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

Annotation of /imapfilter/response.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.52 - (hide annotations)
Sat Feb 14 23:08:31 2004 UTC (20 years, 1 month ago) by lefcha
Branch: MAIN
Changes since 1.51: +13 -9 lines
File MIME type: text/plain
Undocumented variable to force protocol version.

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

webmaster@linux.gr
ViewVC Help
Powered by ViewVC 1.1.26