masqmail
diff src/readsock.c @ 10:26e34ae9a3e3
changed indention and line wrapping to a more consistent style
author | meillo@marmaro.de |
---|---|
date | Mon, 27 Oct 2008 16:23:10 +0100 |
parents | 08114f7dcc23 |
children | f671821d8222 |
line diff
1.1 --- a/src/readsock.c Mon Oct 27 16:21:27 2008 +0100 1.2 +++ b/src/readsock.c Mon Oct 27 16:23:10 2008 +0100 1.3 @@ -27,156 +27,160 @@ 1.4 1.5 jmp_buf jmp_timeout; 1.6 1.7 -static 1.8 -void sig_timeout_handler(int sig) 1.9 +static void 1.10 +sig_timeout_handler(int sig) 1.11 { 1.12 - longjmp(jmp_timeout, 1); 1.13 + longjmp(jmp_timeout, 1); 1.14 } 1.15 1.16 static struct sigaction old_sa_alrm; 1.17 1.18 -static 1.19 -void alarm_on(int timeout) 1.20 +static void 1.21 +alarm_on(int timeout) 1.22 { 1.23 - struct sigaction sa; 1.24 + struct sigaction sa; 1.25 1.26 - sa.sa_handler = sig_timeout_handler; 1.27 - sigemptyset(&(sa.sa_mask)); 1.28 - sa.sa_flags = 0; 1.29 - sigaction(SIGALRM, &sa, &old_sa_alrm); 1.30 + sa.sa_handler = sig_timeout_handler; 1.31 + sigemptyset(&(sa.sa_mask)); 1.32 + sa.sa_flags = 0; 1.33 + sigaction(SIGALRM, &sa, &old_sa_alrm); 1.34 1.35 - if(timeout > 0) 1.36 - alarm(timeout); 1.37 + if (timeout > 0) 1.38 + alarm(timeout); 1.39 } 1.40 1.41 -static 1.42 -void alarm_off() 1.43 +static void 1.44 +alarm_off() 1.45 { 1.46 - alarm(0); 1.47 + alarm(0); 1.48 1.49 - sigaction(SIGALRM, &old_sa_alrm, NULL); 1.50 + sigaction(SIGALRM, &old_sa_alrm, NULL); 1.51 } 1.52 1.53 -static 1.54 -void _read_chug(FILE *in) 1.55 +static void 1.56 +_read_chug(FILE * in) 1.57 { 1.58 - int c = 0; 1.59 + int c = 0; 1.60 1.61 - c = fgetc(in); 1.62 - while(isspace(c) && (c != EOF)) c = fgetc(in); 1.63 - ungetc(c, in); 1.64 + c = fgetc(in); 1.65 + while (isspace(c) && (c != EOF)) 1.66 + c = fgetc(in); 1.67 + ungetc(c, in); 1.68 } 1.69 1.70 -static 1.71 -int _read_line(FILE *in, char *buf, int buf_len, int timeout) 1.72 +static int 1.73 +_read_line(FILE * in, char *buf, int buf_len, int timeout) 1.74 { 1.75 - int p = 0; 1.76 - int c = 0; 1.77 + int p = 0; 1.78 + int c = 0; 1.79 1.80 - c = fgetc(in); 1.81 - while((c != '\n') && (c != EOF) && (p < buf_len-1)){ 1.82 - buf[p++] = c; 1.83 - c = fgetc(in); 1.84 - } 1.85 + c = fgetc(in); 1.86 + while ((c != '\n') && (c != EOF) && (p < buf_len - 1)) { 1.87 + buf[p++] = c; 1.88 + c = fgetc(in); 1.89 + } 1.90 1.91 - buf[p] = 0; 1.92 + buf[p] = 0; 1.93 1.94 - if(c == EOF) 1.95 - return -1; 1.96 - else if(p >= buf_len){ 1.97 - ungetc(c, in); 1.98 - return -2; 1.99 - } 1.100 + if (c == EOF) 1.101 + return -1; 1.102 + else if (p >= buf_len) { 1.103 + ungetc(c, in); 1.104 + return -2; 1.105 + } 1.106 1.107 - buf[p++] = c; /* \n */ 1.108 - buf[p] = 0; 1.109 + buf[p++] = c; /* \n */ 1.110 + buf[p] = 0; 1.111 1.112 - return p; 1.113 + return p; 1.114 } 1.115 1.116 -int read_sockline(FILE *in, char *buf, int buf_len, int timeout, unsigned int flags) 1.117 +int 1.118 +read_sockline(FILE * in, char *buf, int buf_len, int timeout, unsigned int flags) 1.119 { 1.120 - int p = 0; 1.121 + int p = 0; 1.122 1.123 - if(setjmp(jmp_timeout) != 0){ 1.124 - alarm_off(); 1.125 - return -3; 1.126 - } 1.127 + if (setjmp(jmp_timeout) != 0) { 1.128 + alarm_off(); 1.129 + return -3; 1.130 + } 1.131 1.132 - alarm_on(timeout); 1.133 + alarm_on(timeout); 1.134 1.135 - /* strip leading spaces */ 1.136 - if(flags & READSOCKL_CHUG){ 1.137 - _read_chug(in); 1.138 - } 1.139 + /* strip leading spaces */ 1.140 + if (flags & READSOCKL_CHUG) { 1.141 + _read_chug(in); 1.142 + } 1.143 1.144 - p = _read_line(in, buf, buf_len, timeout); 1.145 + p = _read_line(in, buf, buf_len, timeout); 1.146 1.147 - alarm_off(); 1.148 + alarm_off(); 1.149 1.150 - if(p > 1){ 1.151 - /* here we are sure that buf[p-1] == '\n' */ 1.152 - if(flags & READSOCKL_CVT_CRLF){ 1.153 - if((buf[p-2] == '\r') && (buf[p-1] == '\n')){ 1.154 - buf[p-2] = '\n'; 1.155 - buf[p-1] = 0; 1.156 - p--; 1.157 - } 1.158 - } 1.159 - } 1.160 - return p; 1.161 + if (p > 1) { 1.162 + /* here we are sure that buf[p-1] == '\n' */ 1.163 + if (flags & READSOCKL_CVT_CRLF) { 1.164 + if ((buf[p - 2] == '\r') && (buf[p - 1] == '\n')) { 1.165 + buf[p - 2] = '\n'; 1.166 + buf[p - 1] = 0; 1.167 + p--; 1.168 + } 1.169 + } 1.170 + } 1.171 + return p; 1.172 } 1.173 1.174 -int read_sockline1(FILE *in, char **pbuf, int *buf_len, int timeout, unsigned int flags) 1.175 +int 1.176 +read_sockline1(FILE * in, char **pbuf, int *buf_len, int timeout, unsigned int flags) 1.177 { 1.178 - int p = 0, size = *buf_len; 1.179 - char *buf; 1.180 + int p = 0, size = *buf_len; 1.181 + char *buf; 1.182 1.183 - if(setjmp(jmp_timeout) != 0){ 1.184 - alarm_off(); 1.185 - return -3; 1.186 - } 1.187 + if (setjmp(jmp_timeout) != 0) { 1.188 + alarm_off(); 1.189 + return -3; 1.190 + } 1.191 1.192 - alarm_on(timeout); 1.193 + alarm_on(timeout); 1.194 1.195 - /* strip leading spaces */ 1.196 - if(flags & READSOCKL_CHUG){ 1.197 - _read_chug(in); 1.198 - } 1.199 + /* strip leading spaces */ 1.200 + if (flags & READSOCKL_CHUG) { 1.201 + _read_chug(in); 1.202 + } 1.203 1.204 - if(!*pbuf) *pbuf = malloc(size); 1.205 - buf = *pbuf; 1.206 - 1.207 - while(1){ 1.208 - int pp; 1.209 + if (!*pbuf) 1.210 + *pbuf = malloc(size); 1.211 + buf = *pbuf; 1.212 1.213 - pp = _read_line(in, buf, size, timeout); 1.214 - if(pp == -2){ 1.215 - *pbuf = realloc(*pbuf, *buf_len + size); 1.216 - buf = *pbuf + *buf_len; 1.217 - *buf_len += size; 1.218 - p += size; 1.219 - } 1.220 - else{ 1.221 - if(pp > 0) p += pp; 1.222 - else p = pp; 1.223 - break; 1.224 - } 1.225 - } 1.226 + while (1) { 1.227 + int pp; 1.228 1.229 - alarm_off(); 1.230 + pp = _read_line(in, buf, size, timeout); 1.231 + if (pp == -2) { 1.232 + *pbuf = realloc(*pbuf, *buf_len + size); 1.233 + buf = *pbuf + *buf_len; 1.234 + *buf_len += size; 1.235 + p += size; 1.236 + } else { 1.237 + if (pp > 0) 1.238 + p += pp; 1.239 + else 1.240 + p = pp; 1.241 + break; 1.242 + } 1.243 + } 1.244 1.245 - if(p > 1){ 1.246 - buf = *pbuf; 1.247 - /* here we are sure that buf[p-1] == '\n' */ 1.248 - if(flags & READSOCKL_CVT_CRLF){ 1.249 - if((buf[p-2] == '\r') && (buf[p-1] == '\n')){ 1.250 - buf[p-2] = '\n'; 1.251 - buf[p-1] = 0; 1.252 - p--; 1.253 - } 1.254 - } 1.255 - } 1.256 - return p; 1.257 + alarm_off(); 1.258 + 1.259 + if (p > 1) { 1.260 + buf = *pbuf; 1.261 + /* here we are sure that buf[p-1] == '\n' */ 1.262 + if (flags & READSOCKL_CVT_CRLF) { 1.263 + if ((buf[p - 2] == '\r') && (buf[p - 1] == '\n')) { 1.264 + buf[p - 2] = '\n'; 1.265 + buf[p - 1] = 0; 1.266 + p--; 1.267 + } 1.268 + } 1.269 + } 1.270 + return p; 1.271 } 1.272 -