/[imapfilter]/imapfilter/response.c
ViewVC logotype

Annotation of /imapfilter/response.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.51 - (hide annotations)
Sat Feb 14 22:48:04 2004 UTC (20 years, 2 months ago) by lefcha
Branch: MAIN
Changes since 1.50: +69 -11 lines
File MIME type: text/plain
Added IMAP4 protocol support.

1 lefcha 1.1 #include <stdio.h>
2 lefcha 1.41 #include <stdlib.h>
3 lefcha 1.40 #include <string.h>
4 lefcha 1.42 #include <strings.h>
5 lefcha 1.9 #include <ctype.h>
6 lefcha 1.50 #include <sys/types.h> /* For POSIX.1-2001 non-conformant systems. */
7 lefcha 1.1 #include <regex.h>
8 lefcha 1.26 #include <setjmp.h>
9 lefcha 1.1
10     #include "config.h"
11     #include "imapfilter.h"
12 lefcha 1.40 #include "buffer.h"
13 lefcha 1.1
14    
15 lefcha 1.48 extern connection_t connpri, connaux;
16 lefcha 1.26 extern jmp_buf acctloop;
17 lefcha 1.1
18 lefcha 1.38 buffer_t ibuf; /* Input buffer. */
19 lefcha 1.20
20 lefcha 1.1
21 lefcha 1.48 void receive_response(connection_t * conn, char *buf);
22     void response_bye(char *buf);
23     int analyze_response(connection_t * conn, char *buf);
24 lefcha 1.40
25    
26 lefcha 1.1 /*
27 lefcha 1.14 * Read one packet of data that the server sent.
28 lefcha 1.1 */
29 lefcha 1.33 void
30 lefcha 1.48 receive_response(connection_t * conn, char *buf)
31 lefcha 1.1 {
32 lefcha 1.49
33 lefcha 1.39 if (socket_read(conn, buf) == ERROR_NETWORK)
34 lefcha 1.33 longjmp(acctloop, -1);
35 lefcha 1.1
36 lefcha 1.47 debug("getting response (%s):\n\n%s\n",
37 lefcha 1.39 (conn == &connpri ? "primary" : "auxiliary"), buf);
38 lefcha 1.1 }
39    
40    
41     /*
42     * Get server response to client's request.
43     */
44 lefcha 1.33 int
45 lefcha 1.48 response_generic(connection_t * conn, unsigned int tag)
46 lefcha 1.1 {
47 lefcha 1.49
48 lefcha 1.48 buffer_reset(&ibuf);
49 lefcha 1.21
50 lefcha 1.33 do {
51 lefcha 1.48 buffer_check(&ibuf, strlen(ibuf.data) + RESPONSE_BUF);
52 lefcha 1.39 receive_response(conn, ibuf.data + strlen(ibuf.data));
53 lefcha 1.48 response_bye(ibuf.data);
54 lefcha 1.38 } while (!strcasestr(ibuf.data, ultostr(tag, 16)));
55 lefcha 1.6
56 lefcha 1.39 return analyze_response(conn, ibuf.data);
57 lefcha 1.1 }
58    
59    
60     /*
61 lefcha 1.26 * Check if server sent a BYE response (connection is closed immediately).
62     */
63 lefcha 1.33 void
64 lefcha 1.48 response_bye(char *buf)
65 lefcha 1.26 {
66 lefcha 1.49
67 lefcha 1.33 if (strcasestr(buf, "* BYE"))
68     longjmp(acctloop, -1);
69 lefcha 1.26 }
70    
71    
72     /*
73 lefcha 1.9 * Process the greeting that server sends during connection.
74     */
75 lefcha 1.33 int
76 lefcha 1.48 response_greeting(connection_t * conn)
77 lefcha 1.9 {
78 lefcha 1.49
79 lefcha 1.48 buffer_reset(&ibuf);
80 lefcha 1.9
81 lefcha 1.39 receive_response(conn, ibuf.data);
82 lefcha 1.35
83 lefcha 1.39 verbose("%s: %s", (conn == &connpri ? "S" : "s"), ibuf);
84 lefcha 1.35
85 lefcha 1.48 response_bye(ibuf.data);
86 lefcha 1.9
87 lefcha 1.38 if (strcasestr(ibuf.data, "* PREAUTH"))
88 lefcha 1.33 return RESPONSE_PREAUTH;
89 lefcha 1.9
90 lefcha 1.33 return RESPONSE_OK;
91 lefcha 1.9 }
92    
93 lefcha 1.13
94 lefcha 1.9 /*
95 lefcha 1.25 * Process the data that server sent due to IMAP LOGOUT client request.
96     */
97 lefcha 1.33 int
98 lefcha 1.48 response_logout(connection_t * conn, unsigned int tag)
99 lefcha 1.25 {
100 lefcha 1.49
101 lefcha 1.48 buffer_reset(&ibuf);
102 lefcha 1.25
103 lefcha 1.33 do {
104 lefcha 1.48 buffer_check(&ibuf, strlen(ibuf.data) + RESPONSE_BUF);
105 lefcha 1.39 receive_response(conn, ibuf.data + strlen(ibuf.data));
106 lefcha 1.38 } while (!strcasestr(ibuf.data, ultostr(tag, 16)));
107 lefcha 1.25
108 lefcha 1.39 return analyze_response(conn, ibuf.data);
109 lefcha 1.25 }
110    
111    
112     /*
113 lefcha 1.9 * Process the data that server sent due to IMAP CAPABILITY client request.
114     */
115 lefcha 1.33 int
116 lefcha 1.48 response_capability(connection_t * conn, unsigned int tag)
117 lefcha 1.9 {
118 lefcha 1.49
119 lefcha 1.48 buffer_reset(&ibuf);
120 lefcha 1.9
121 lefcha 1.33 do {
122 lefcha 1.48 buffer_check(&ibuf, strlen(ibuf.data) + RESPONSE_BUF);
123 lefcha 1.39 receive_response(conn, ibuf.data + strlen(ibuf.data));
124 lefcha 1.48 response_bye(ibuf.data);
125 lefcha 1.38 } while (!strcasestr(ibuf.data, ultostr(tag, 16)));
126 lefcha 1.33
127 lefcha 1.51 if (strcasestr(ibuf.data, "IMAP4rev1"))
128     conn->prot |= PROTOCOL_IMAP4REV1;
129     else if (strcasestr(ibuf.data, "IMAP4"))
130     conn->caps |= PROTOCOL_IMAP4;
131     else {
132     error("server supports neither the IMAP4rev1 nor the "
133     "IMAP4 protocol\n");
134 lefcha 1.33 return -2;
135     }
136 lefcha 1.51
137 lefcha 1.38 if (strcasestr(ibuf.data, "NAMESPACE"))
138 lefcha 1.51 conn->caps |= CAPABILITY_NAMESPACE;
139 lefcha 1.37 #ifdef CRAM_MD5
140 lefcha 1.38 if (strcasestr(ibuf.data, "AUTH=CRAM-MD5"))
141 lefcha 1.51 conn->caps |= CAPABILITY_CRAMMD5;
142 lefcha 1.37 #endif
143     #ifdef SSL_TLS
144 lefcha 1.38 if (strcasestr(ibuf.data, "STARTTLS"))
145 lefcha 1.51 conn->caps |= CAPABILITY_STARTTLS;
146 lefcha 1.37 #endif
147 lefcha 1.39 return analyze_response(conn, ibuf.data);
148 lefcha 1.18 }
149    
150    
151 lefcha 1.36 #ifdef CRAM_MD5
152 lefcha 1.18 /*
153 lefcha 1.36 * Process the data that server sent due to IMAP AUTHENTICATE client request.
154 lefcha 1.31 */
155 lefcha 1.36 int
156 lefcha 1.48 response_authenticate(connection_t * conn, unsigned int tag, unsigned char **cont)
157 lefcha 1.31 {
158 lefcha 1.36 int i;
159     char *c;
160 lefcha 1.33
161 lefcha 1.48 buffer_reset(&ibuf);
162 lefcha 1.36
163     do {
164 lefcha 1.48 buffer_check(&ibuf, strlen(ibuf.data) + RESPONSE_BUF);
165 lefcha 1.39 receive_response(conn, ibuf.data + strlen(ibuf.data));
166 lefcha 1.48 response_bye(ibuf.data);
167 lefcha 1.38 } while (strlen(ibuf.data) == RESPONSE_BUF &&
168     !strcasestr(ibuf.data, ultostr(tag, 16)));
169 lefcha 1.31
170 lefcha 1.38 if (cont != NULL && ibuf.data[0] == '+' && ibuf.data[1] == ' ') {
171     c = *cont = (unsigned char *)xmalloc(strlen(ibuf.data) + 1);
172 lefcha 1.33
173 lefcha 1.38 for (i = 2; ibuf.data[i] != '\r'; i++)
174     *c++ = ibuf.data[i];
175 lefcha 1.36
176     *c = '\0';
177 lefcha 1.33 }
178 lefcha 1.39 return analyze_response(conn, ibuf.data);
179 lefcha 1.36 }
180 lefcha 1.31 #endif
181 lefcha 1.33
182 lefcha 1.31
183     /*
184 lefcha 1.18 * Process the data that server sent due to IMAP NAMESPACE client request.
185     */
186 lefcha 1.33 int
187 lefcha 1.48 response_namespace(connection_t * conn, unsigned int tag)
188 lefcha 1.18 {
189 lefcha 1.33 char *c, *d;
190 lefcha 1.18
191 lefcha 1.48 buffer_reset(&ibuf);
192 lefcha 1.21
193 lefcha 1.33 do {
194 lefcha 1.48 buffer_check(&ibuf, strlen(ibuf.data) + RESPONSE_BUF);
195 lefcha 1.39 receive_response(conn, ibuf.data + strlen(ibuf.data));
196 lefcha 1.48 response_bye(ibuf.data);
197 lefcha 1.38 } while (!strcasestr(ibuf.data, ultostr(tag, 16)));
198 lefcha 1.33
199 lefcha 1.38 if ((c = strcasestr(ibuf.data, "* NAMESPACE"))) {
200 lefcha 1.33 c += 12;
201     if (strncasecmp(c, "NIL", 3)) {
202     c = strchr(c, '"') + 1;
203     d = strchr(c, '"') + 1;
204    
205 lefcha 1.48 strncat(conn->ns.prefix, c, d - c - 1);
206     conn->ns.delim = *(strchr(d, '"') + 1);
207 lefcha 1.33 }
208 lefcha 1.18 }
209 lefcha 1.47 debug("namespace (%s): '%s' '%c'\n",
210 lefcha 1.48 (conn == &connpri ? "primary" : "auxiliary"), conn->ns.prefix,
211     conn->ns.delim);
212 lefcha 1.39 return analyze_response(conn, ibuf.data);
213 lefcha 1.9 }
214    
215    
216     /*
217 lefcha 1.3 * Process the data that server sent due to IMAP STATUS client request.
218 lefcha 1.1 */
219 lefcha 1.33 int
220 lefcha 1.48 response_status(connection_t * conn, unsigned int tag, char *mbox)
221 lefcha 1.1 {
222 lefcha 1.33 int r;
223 lefcha 1.51 unsigned int exists, recent, unseen;
224 lefcha 1.33 char *c;
225    
226 lefcha 1.51 exists = recent = unseen = 0;
227 lefcha 1.33
228 lefcha 1.48 buffer_reset(&ibuf);
229 lefcha 1.33
230     do {
231 lefcha 1.48 buffer_check(&ibuf, strlen(ibuf.data) + RESPONSE_BUF);
232 lefcha 1.39 receive_response(conn, ibuf.data + strlen(ibuf.data));
233 lefcha 1.48 response_bye(ibuf.data);
234 lefcha 1.38 } while (!strcasestr(ibuf.data, ultostr(tag, 16)));
235 lefcha 1.1
236 lefcha 1.39 r = analyze_response(conn, ibuf.data);
237 lefcha 1.21
238 lefcha 1.33 if (r == RESPONSE_NO)
239     return -2;
240 lefcha 1.1
241 lefcha 1.38 if ((c = strcasestr(ibuf.data, "MESSAGES"))) {
242 lefcha 1.33 c += 9;
243 lefcha 1.51 exists = strtoul(c, NULL, 10);
244     }
245     if (exists == 0) {
246     info("No messages in mailbox \"%s\".\n", mbox);
247     return -2;
248 lefcha 1.33 }
249 lefcha 1.38 if ((c = strcasestr(ibuf.data, "RECENT"))) {
250 lefcha 1.33 c += 7;
251     recent = strtoul(c, NULL, 10);
252     }
253 lefcha 1.38 if ((c = strcasestr(ibuf.data, "UNSEEN"))) {
254 lefcha 1.33 c += 7;
255     unseen = strtoul(c, NULL, 10);
256     }
257 lefcha 1.51 info("%d message%s, %d recent, %d unseen, in mailbox \"%s\".\n",
258     exists, plural(exists), recent, unseen, mbox);
259    
260     return r;
261     }
262    
263    
264     /*
265     * Process the data that server sent due to IMAP EXAMINE client request.
266     */
267     int
268     response_examine(connection_t * conn, unsigned int tag, char *mbox)
269     {
270     int r;
271     unsigned int exists, recent, unseen;
272     char *c;
273    
274     exists = recent = unseen = 0;
275    
276     buffer_reset(&ibuf);
277    
278     do {
279     buffer_check(&ibuf, strlen(ibuf.data) + RESPONSE_BUF);
280     receive_response(conn, ibuf.data + strlen(ibuf.data));
281     response_bye(ibuf.data);
282     } while (!strcasestr(ibuf.data, ultostr(tag, 16)));
283    
284     r = analyze_response(conn, ibuf.data);
285    
286     if (r == RESPONSE_NO)
287     return -2;
288    
289     if ((c = strcasestr(ibuf.data, "EXISTS"))) {
290     while (--c >= ibuf.data && *c != '*');
291     c++;
292     exists = strtoul(c, NULL, 10);
293     }
294     if (exists == 0) {
295 lefcha 1.33 info("No messages in mailbox \"%s\".\n", mbox);
296     return -2;
297     }
298 lefcha 1.51 if ((c = strcasestr(ibuf.data, "RECENT"))) {
299     while (--c >= ibuf.data && *c != '*');
300     c++;
301     recent = strtoul(c, NULL, 10);
302     }
303     if ((c = strcasestr(ibuf.data, "UNSEEN"))) {
304     c += 7;
305     unseen = strtoul(c, NULL, 10);
306     info("%d message%s, %d recent, %d unseen, in mailbox \"%s\".\n",
307     exists, plural(exists), recent, unseen, mbox);
308     } else
309     info("%d message%s, %d recent, in mailbox \"%s\".\n", exists,
310     plural(exists), recent, mbox);
311 lefcha 1.9
312 lefcha 1.33 return r;
313 lefcha 1.9 }
314    
315    
316     /*
317     * Process the data that server sent due to IMAP SELECT client request.
318     */
319 lefcha 1.33 int
320 lefcha 1.48 response_select(connection_t * conn, unsigned int tag)
321 lefcha 1.9 {
322 lefcha 1.49
323 lefcha 1.48 buffer_reset(&ibuf);
324 lefcha 1.21
325 lefcha 1.33 do {
326 lefcha 1.48 buffer_check(&ibuf, strlen(ibuf.data) + RESPONSE_BUF);
327 lefcha 1.39 receive_response(conn, ibuf.data + strlen(ibuf.data));
328 lefcha 1.48 response_bye(ibuf.data);
329 lefcha 1.38 } while (!strcasestr(ibuf.data, ultostr(tag, 16)));
330 lefcha 1.9
331 lefcha 1.38 if (strcasestr(ibuf.data, "[READ-ONLY]"))
332 lefcha 1.33 return RESPONSE_READONLY;
333 lefcha 1.1
334 lefcha 1.39 return analyze_response(conn, ibuf.data);
335 lefcha 1.1 }
336    
337    
338     /*
339 lefcha 1.3 * Process the data that server sent due to IMAP SEARCH client request.
340 lefcha 1.1 */
341 lefcha 1.33 int
342 lefcha 1.48 response_search(connection_t * conn, unsigned int tag, char **mesgs)
343 lefcha 1.1 {
344 lefcha 1.33 char *c, *m;
345     unsigned int blen;
346 lefcha 1.13
347 lefcha 1.48 buffer_reset(&ibuf);
348 lefcha 1.21
349 lefcha 1.33 do {
350 lefcha 1.48 buffer_check(&ibuf, strlen(ibuf.data) + RESPONSE_BUF);
351 lefcha 1.39 receive_response(conn, ibuf.data + strlen(ibuf.data));
352 lefcha 1.48 response_bye(ibuf.data);
353 lefcha 1.38 } while (!strcasestr(ibuf.data, ultostr(tag, 16)));
354 lefcha 1.1
355 lefcha 1.38 if ((c = strcasestr(ibuf.data, "* SEARCH "))) {
356     blen = strlen(ibuf.data);
357 lefcha 1.21
358 lefcha 1.33 m = *mesgs = (char *)xmalloc(blen + 1);
359 lefcha 1.21
360 lefcha 1.33 c += 9;
361 lefcha 1.21
362 lefcha 1.33 while (*c != '\0' && (isdigit(*c) || *c == ' '))
363     *(m++) = *(c++);
364 lefcha 1.14
365 lefcha 1.33 *m = 0;
366     }
367 lefcha 1.39 return analyze_response(conn, ibuf.data);
368 lefcha 1.1 }
369    
370    
371     /*
372 lefcha 1.3 * Process the data that server sent due to IMAP FETCH client request.
373 lefcha 1.1 */
374 lefcha 1.33 int
375 lefcha 1.48 response_fetch(connection_t * conn, unsigned int tag, int reset, char *fetch)
376 lefcha 1.1 {
377 lefcha 1.33 unsigned int i;
378     static unsigned int s;
379     char *b;
380    
381     if (reset) {
382     s = 0;
383     return 0;
384     }
385     i = 0;
386 lefcha 1.20
387 lefcha 1.48 buffer_reset(&ibuf);
388 lefcha 1.20
389 lefcha 1.33 do {
390 lefcha 1.48 buffer_check(&ibuf, strlen(ibuf.data) + RESPONSE_BUF);
391 lefcha 1.39 receive_response(conn, ibuf.data + strlen(ibuf.data));
392 lefcha 1.48 response_bye(ibuf.data);
393 lefcha 1.38 } while (strlen(ibuf.data) < RESPONSE_BUF &&
394     !strcasestr(ibuf.data, ultostr(tag, 16)));
395 lefcha 1.33
396 lefcha 1.38 b = ibuf.data;
397 lefcha 1.33
398     if (s == 0) {
399     if ((b = strstr(b, "}\r\n"))) {
400 lefcha 1.38 while (b - ibuf.data > 0)
401 lefcha 1.33 if (*--b == '{')
402     break;
403     s = atoi(++b) - 2;
404     b = strchr(b, '}');
405     b += 3;
406     } else {
407     return RESPONSE_NULLBODY; /* Null body. */
408     }
409     }
410     while (*b != '\0' && s-- != 0)
411     fetch[i++] = *(b++);
412 lefcha 1.20
413 lefcha 1.33 fetch[i] = '\0';
414 lefcha 1.21
415 lefcha 1.39 return analyze_response(conn, ibuf.data);
416 lefcha 1.20 }
417    
418 lefcha 1.6
419 lefcha 1.20 /*
420 lefcha 1.45 * Process the data that server sent due to IMAP FETCH FAST client request.
421 lefcha 1.20 */
422 lefcha 1.33 int
423 lefcha 1.48 response_fetchfast(connection_t * conn, char **flags, char **date,
424 lefcha 1.45 unsigned int *size, unsigned int tag)
425 lefcha 1.20 {
426 lefcha 1.45 char *c, *m;
427     unsigned int blen;
428 lefcha 1.21
429 lefcha 1.33 *size = 0;
430 lefcha 1.21
431 lefcha 1.48 buffer_reset(&ibuf);
432 lefcha 1.33
433     do {
434 lefcha 1.48 buffer_check(&ibuf, strlen(ibuf.data) + RESPONSE_BUF);
435 lefcha 1.39 receive_response(conn, ibuf.data + strlen(ibuf.data));
436 lefcha 1.48 response_bye(ibuf.data);
437 lefcha 1.38 } while (!strcasestr(ibuf.data, ultostr(tag, 16)));
438 lefcha 1.33
439 lefcha 1.45 if ((c = strcasestr(ibuf.data, "FETCH (FLAGS ("))) {
440     blen = strlen(ibuf.data);
441    
442     m = *flags = (char *)xmalloc(blen + 1);
443    
444     c += 14;
445 lefcha 1.46
446 lefcha 1.45 while (*c != '\0' && *c != ')') {
447     /* The \Recent flag can not be altered by the client. */
448     if (*c == '\\') {
449     if (strcasestr(c - 1, "(\\Recent)") ||
450     strcasestr(c - 1, " \\Recent)"))
451     break;
452     else if (strcasestr(c, "\\Recent "))
453     c += 8;
454     }
455     *(m++) = *(c++);
456     }
457    
458     *m = 0;
459     }
460     if ((c = strcasestr(ibuf.data, " INTERNALDATE \""))) {
461     blen = strlen(ibuf.data);
462    
463     m = *date = (char *)xmalloc(blen + 1);
464    
465     c += 15;
466 lefcha 1.46
467 lefcha 1.45 while (*c != '\0' && *c != '"')
468     *(m++) = *(c++);
469    
470     *m = 0;
471     }
472     if ((c = strcasestr(ibuf.data, " RFC822.SIZE "))) {
473     c += 13;
474 lefcha 1.33 *size = strtoul(c, NULL, 10);
475     }
476 lefcha 1.39 return analyze_response(conn, ibuf.data);
477 lefcha 1.20 }
478 lefcha 1.13
479 lefcha 1.6
480 lefcha 1.20 /*
481     * Process the data that server sent due to IMAP APPEND client request.
482     */
483 lefcha 1.33 int
484 lefcha 1.48 response_append(connection_t * conn, unsigned int tag)
485 lefcha 1.20 {
486 lefcha 1.33 int r;
487    
488     r = RESPONSE_OK;
489 lefcha 1.21
490 lefcha 1.48 buffer_reset(&ibuf);
491 lefcha 1.21
492 lefcha 1.33 do {
493 lefcha 1.48 buffer_check(&ibuf, strlen(ibuf.data) + RESPONSE_BUF);
494 lefcha 1.39 receive_response(conn, ibuf.data + strlen(ibuf.data));
495 lefcha 1.48 response_bye(ibuf.data);
496 lefcha 1.38 } while (!strcasestr(ibuf.data, ultostr(tag, 16)));
497 lefcha 1.33
498 lefcha 1.39 if ((r = analyze_response(conn, ibuf.data)) == RESPONSE_NO &&
499 lefcha 1.38 strcasestr(ibuf.data, "[TRYCREATE]"))
500 lefcha 1.33 return RESPONSE_TRYCREATE;
501 lefcha 1.6
502 lefcha 1.33 return r;
503 lefcha 1.1 }
504    
505    
506     /*
507 lefcha 1.3 * Process the data that server sent due to IMAP COPY client request.
508 lefcha 1.1 */
509 lefcha 1.33 int
510 lefcha 1.48 response_copy(connection_t * conn, unsigned int tag)
511 lefcha 1.1 {
512 lefcha 1.33 int r;
513 lefcha 1.21
514 lefcha 1.33 r = RESPONSE_OK;
515 lefcha 1.1
516 lefcha 1.48 buffer_reset(&ibuf);
517 lefcha 1.33
518     do {
519 lefcha 1.48 buffer_check(&ibuf, strlen(ibuf.data) + RESPONSE_BUF);
520 lefcha 1.39 receive_response(conn, ibuf.data + strlen(ibuf.data));
521 lefcha 1.48 response_bye(ibuf.data);
522 lefcha 1.38 } while (!strcasestr(ibuf.data, ultostr(tag, 16)));
523 lefcha 1.33
524 lefcha 1.39 if ((r = analyze_response(conn, ibuf.data)) == RESPONSE_NO &&
525 lefcha 1.38 strcasestr(ibuf.data, "[TRYCREATE]"))
526 lefcha 1.33 return RESPONSE_TRYCREATE;
527 lefcha 1.1
528 lefcha 1.33 return r;
529 lefcha 1.1 }
530    
531    
532     /*
533 lefcha 1.3 * Check if response of server to client's request was succesfully
534 lefcha 1.1 * delivered or there was some kind of error.
535     */
536 lefcha 1.33 int
537 lefcha 1.48 analyze_response(connection_t * conn, char *buf)
538 lefcha 1.1 {
539 lefcha 1.33 int r;
540     regex_t creg;
541     regmatch_t match[3];
542     const char *reg;
543     char result[RESULT_BUF];
544 lefcha 1.1
545 lefcha 1.33 r = RESPONSE_OK;
546 lefcha 1.44 reg = "[[:xdigit:]]{4,4} ((OK|NO|BAD)[[:print:]]*)\r\n";
547 lefcha 1.33 result[0] = '\0';
548 lefcha 1.4
549 lefcha 1.33 regcomp(&creg, reg, REG_EXTENDED | REG_ICASE);
550 lefcha 1.6
551 lefcha 1.33 if (!regexec(&creg, buf, 3, match, 0)) {
552     strncat(result, buf + match[1].rm_so,
553     min(match[1].rm_eo - match[1].rm_so, RESULT_BUF - 1));
554 lefcha 1.1
555 lefcha 1.33 if (!strncasecmp(buf + match[2].rm_so, "NO", 2))
556     r = RESPONSE_NO;
557     else if (!strncasecmp(buf + match[2].rm_so, "BAD", 3))
558     r = RESPONSE_BAD;
559 lefcha 1.6
560 lefcha 1.39 verbose("%s: %s", (conn == &connpri ? "S" : "s"),
561 lefcha 1.35 buf + match[0].rm_so);
562 lefcha 1.33 } else
563     r = RESPONSE_NONE;
564 lefcha 1.21
565 lefcha 1.33 regfree(&creg);
566 lefcha 1.1
567 lefcha 1.33 return r;
568 lefcha 1.1 }

webmaster@linux.gr
ViewVC Help
Powered by ViewVC 1.1.26