masqmail-0.2
diff src/libident/id_parse.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 |
line diff
1.1 --- a/src/libident/id_parse.c Mon Oct 27 16:21:27 2008 +0100 1.2 +++ b/src/libident/id_parse.c Mon Oct 27 16:23:10 2008 +0100 1.3 @@ -32,198 +32,184 @@ 1.4 # include <sys/select.h> 1.5 #endif 1.6 #ifdef VMS 1.7 -# include <sys/socket.h> /* for fd_set */ 1.8 +# include <sys/socket.h> /* for fd_set */ 1.9 #endif 1.10 #define IN_LIBIDENT_SRC 1.11 #include "ident.h" 1.12 1.13 1.14 /* 1.15 -int id_parse __P7(ident_t *, id, 1.16 - struct timeval *, timeout, 1.17 - int *, lport, 1.18 - int *, fport, 1.19 - char **, identifier, 1.20 - char **, opsys, 1.21 - char **, charset) 1.22 +int 1.23 +id_parse __P7(ident_t *, id, 1.24 + struct timeval *, timeout, 1.25 + int *, lport, 1.26 + int *, fport, 1.27 + char **, identifier, 1.28 + char **, opsys, 1.29 + char **, charset) 1.30 */ 1.31 1.32 -int id_parse __P(( ident_t *id, 1.33 - __STRUCT_TIMEVAL_P timeout, 1.34 - int *lport, 1.35 - int *fport, 1.36 - char **identifier, 1.37 - char **opsys, 1.38 - char **charset)) 1.39 +int 1.40 +id_parse __P((ident_t * id, 1.41 + __STRUCT_TIMEVAL_P timeout, 1.42 + int *lport, 1.43 + int *fport, 1.44 + char **identifier, 1.45 + char **opsys, 1.46 + char **charset)) 1.47 { 1.48 - char c, *cp, *tmp_charset; 1.49 - fd_set rs; 1.50 - int pos, res=0, lp, fp; 1.51 - 1.52 - errno = 0; 1.53 - 1.54 - tmp_charset = 0; 1.55 - 1.56 - if (!id) 1.57 - return -1; 1.58 - if (lport) 1.59 - *lport = 0; 1.60 - if (fport) 1.61 - *fport = 0; 1.62 - if (identifier) 1.63 - *identifier = 0; 1.64 - if (opsys) 1.65 - *opsys = 0; 1.66 - if (charset) 1.67 - *charset = 0; 1.68 - 1.69 - pos = strlen(id->buf); 1.70 - 1.71 - if (timeout) 1.72 - { 1.73 - FD_ZERO(&rs); 1.74 - FD_SET(id->fd, &rs); 1.75 + char c, *cp, *tmp_charset; 1.76 + fd_set rs; 1.77 + int pos, res = 0, lp, fp; 1.78 + 1.79 + errno = 0; 1.80 + 1.81 + tmp_charset = 0; 1.82 + 1.83 + if (!id) 1.84 + return -1; 1.85 + if (lport) 1.86 + *lport = 0; 1.87 + if (fport) 1.88 + *fport = 0; 1.89 + if (identifier) 1.90 + *identifier = 0; 1.91 + if (opsys) 1.92 + *opsys = 0; 1.93 + if (charset) 1.94 + *charset = 0; 1.95 + 1.96 + pos = strlen(id->buf); 1.97 + 1.98 + if (timeout) { 1.99 + FD_ZERO(&rs); 1.100 + FD_SET(id->fd, &rs); 1.101 1.102 #ifdef __hpux 1.103 - if ((res = select(FD_SETSIZE, (int *) &rs, (int *)0, (int *)0, timeout)) < 0) 1.104 + if ((res = select(FD_SETSIZE, (int *) &rs, (int *) 0, (int *) 0, timeout)) < 0) 1.105 #else 1.106 - if ((res = select(FD_SETSIZE, &rs, (fd_set *)0, (fd_set *)0, timeout)) < 0) 1.107 + if ((res = select(FD_SETSIZE, &rs, (fd_set *) 0, (fd_set *) 0, timeout)) < 0) 1.108 #endif 1.109 - return -1; 1.110 - 1.111 - if (res == 0) 1.112 - { 1.113 - errno = ETIMEDOUT; 1.114 - return -1; 1.115 + return -1; 1.116 + 1.117 + if (res == 0) { 1.118 + errno = ETIMEDOUT; 1.119 + return -1; 1.120 + } 1.121 } 1.122 - } 1.123 - 1.124 - /* Every octal value is allowed except 0, \n and \r */ 1.125 - while (pos < sizeof(id->buf) && 1.126 - (res = read(id->fd, id->buf + pos, 1)) == 1 && 1.127 - id->buf[pos] != '\n' && id->buf[pos] != '\r') 1.128 - pos++; 1.129 - 1.130 - if (res < 0) 1.131 - return -1; 1.132 - 1.133 - if (res == 0) 1.134 - { 1.135 - errno = ENOTCONN; 1.136 - return -1; 1.137 - } 1.138 - 1.139 - if (id->buf[pos] != '\n' && id->buf[pos] != '\r') 1.140 - return 0; /* Not properly terminated string */ 1.141 - 1.142 - id->buf[pos++] = '\0'; 1.143 - 1.144 - /* 1.145 - ** Get first field (<lport> , <fport>) 1.146 - */ 1.147 - cp = id_strtok(id->buf, ":", &c); 1.148 - if (!cp) 1.149 - return -2; 1.150 - 1.151 - if (sscanf(cp, " %d , %d", &lp, &fp) != 2) 1.152 - { 1.153 - if (identifier) 1.154 - { 1.155 - *identifier = id_strdup(cp); 1.156 - if (*identifier == NULL) 1.157 - return -4; 1.158 + 1.159 + /* Every octal value is allowed except 0, \n and \r */ 1.160 + while (pos < sizeof(id->buf) 1.161 + && (res = read(id->fd, id->buf + pos, 1)) == 1 1.162 + && id->buf[pos] != '\n' && id->buf[pos] != '\r') 1.163 + pos++; 1.164 + 1.165 + if (res < 0) 1.166 + return -1; 1.167 + 1.168 + if (res == 0) { 1.169 + errno = ENOTCONN; 1.170 + return -1; 1.171 } 1.172 - return -2; 1.173 - } 1.174 - 1.175 - if (lport) 1.176 - *lport = lp; 1.177 - if (fport) 1.178 - *fport = fp; 1.179 - 1.180 - /* 1.181 - ** Get second field (USERID or ERROR) 1.182 - */ 1.183 - cp = id_strtok((char *)0, ":", &c); 1.184 - if (!cp) 1.185 - return -2; 1.186 - 1.187 - if (strcmp(cp, "ERROR") == 0) 1.188 - { 1.189 - cp = id_strtok((char *)0, "\n\r", &c); 1.190 + 1.191 + if (id->buf[pos] != '\n' && id->buf[pos] != '\r') 1.192 + return 0; /* Not properly terminated string */ 1.193 + 1.194 + id->buf[pos++] = '\0'; 1.195 + 1.196 + /* 1.197 + ** Get first field (<lport> , <fport>) 1.198 + */ 1.199 + cp = id_strtok(id->buf, ":", &c); 1.200 if (!cp) 1.201 - return -2; 1.202 - 1.203 - if (identifier) 1.204 - { 1.205 - *identifier = id_strdup(cp); 1.206 - if (*identifier == NULL) 1.207 - return -4; 1.208 + return -2; 1.209 + 1.210 + if (sscanf(cp, " %d , %d", &lp, &fp) != 2) { 1.211 + if (identifier) { 1.212 + *identifier = id_strdup(cp); 1.213 + if (*identifier == NULL) 1.214 + return -4; 1.215 + } 1.216 + return -2; 1.217 } 1.218 - 1.219 - return 2; 1.220 - } 1.221 - else if (strcmp(cp, "USERID") == 0) 1.222 - { 1.223 + 1.224 + if (lport) 1.225 + *lport = lp; 1.226 + if (fport) 1.227 + *fport = fp; 1.228 + 1.229 /* 1.230 - ** Get first subfield of third field <opsys> 1.231 - */ 1.232 - cp = id_strtok((char *) 0, ",:", &c); 1.233 + ** Get second field (USERID or ERROR) 1.234 + */ 1.235 + cp = id_strtok((char *) 0, ":", &c); 1.236 if (!cp) 1.237 - return -2; 1.238 - 1.239 - if (opsys) 1.240 - { 1.241 - *opsys = id_strdup(cp); 1.242 - if (*opsys == NULL) 1.243 - return -4; 1.244 + return -2; 1.245 + 1.246 + if (strcmp(cp, "ERROR") == 0) { 1.247 + cp = id_strtok((char *) 0, "\n\r", &c); 1.248 + if (!cp) 1.249 + return -2; 1.250 + 1.251 + if (identifier) { 1.252 + *identifier = id_strdup(cp); 1.253 + if (*identifier == NULL) 1.254 + return -4; 1.255 + } 1.256 + 1.257 + return 2; 1.258 + } else if (strcmp(cp, "USERID") == 0) { 1.259 + /* 1.260 + ** Get first subfield of third field <opsys> 1.261 + */ 1.262 + cp = id_strtok((char *) 0, ",:", &c); 1.263 + if (!cp) 1.264 + return -2; 1.265 + 1.266 + if (opsys) { 1.267 + *opsys = id_strdup(cp); 1.268 + if (*opsys == NULL) 1.269 + return -4; 1.270 + } 1.271 + 1.272 + /* 1.273 + ** We have a second subfield (<charset>) 1.274 + */ 1.275 + if (c == ',') { 1.276 + cp = id_strtok((char *) 0, ":", &c); 1.277 + if (!cp) 1.278 + return -2; 1.279 + 1.280 + tmp_charset = cp; 1.281 + if (charset) { 1.282 + *charset = id_strdup(cp); 1.283 + if (*charset == NULL) 1.284 + return -4; 1.285 + } 1.286 + 1.287 + /* 1.288 + ** We have even more subfields - ignore them 1.289 + */ 1.290 + if (c == ',') 1.291 + id_strtok((char *) 0, ":", &c); 1.292 + } 1.293 + 1.294 + if (tmp_charset && strcmp(tmp_charset, "OCTET") == 0) 1.295 + cp = id_strtok((char *) 0, (char *) 0, &c); 1.296 + else 1.297 + cp = id_strtok((char *) 0, "\n\r", &c); 1.298 + 1.299 + if (identifier) { 1.300 + *identifier = id_strdup(cp); 1.301 + if (*identifier == NULL) 1.302 + return -4; 1.303 + } 1.304 + return 1; 1.305 + } else { 1.306 + if (identifier) { 1.307 + *identifier = id_strdup(cp); 1.308 + if (*identifier == NULL) 1.309 + return -4; 1.310 + } 1.311 + return -3; 1.312 } 1.313 - 1.314 - /* 1.315 - ** We have a second subfield (<charset>) 1.316 - */ 1.317 - if (c == ',') 1.318 - { 1.319 - cp = id_strtok((char *)0, ":", &c); 1.320 - if (!cp) 1.321 - return -2; 1.322 - 1.323 - tmp_charset = cp; 1.324 - if (charset) 1.325 - { 1.326 - *charset = id_strdup(cp); 1.327 - if (*charset == NULL) 1.328 - return -4; 1.329 - } 1.330 - 1.331 - /* 1.332 - ** We have even more subfields - ignore them 1.333 - */ 1.334 - if (c == ',') 1.335 - id_strtok((char *)0, ":", &c); 1.336 - } 1.337 - 1.338 - if (tmp_charset && strcmp(tmp_charset, "OCTET") == 0) 1.339 - cp = id_strtok((char *)0, (char *)0, &c); 1.340 - else 1.341 - cp = id_strtok((char *)0, "\n\r", &c); 1.342 - 1.343 - if (identifier) 1.344 - { 1.345 - *identifier = id_strdup(cp); 1.346 - if (*identifier == NULL) 1.347 - return -4; 1.348 - } 1.349 - return 1; 1.350 - } 1.351 - else 1.352 - { 1.353 - if (identifier) 1.354 - { 1.355 - *identifier = id_strdup(cp); 1.356 - if (*identifier == NULL) 1.357 - return -4; 1.358 - } 1.359 - return -3; 1.360 - } 1.361 }