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

Diff of /imapfilter/response.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.23 by lefcha, Fri Jul 26 18:21:11 2002 UTC revision 1.23.2.5 by lefcha, Sat Nov 9 14:18:23 2002 UTC
# Line 7  Line 7 
7  #include <sys/time.h>  #include <sys/time.h>
8  #include <sys/types.h>  #include <sys/types.h>
9  #include <regex.h>  #include <regex.h>
10    #include <setjmp.h>
11    
12  #include "config.h"  #include "config.h"
13  #include "imapfilter.h"  #include "imapfilter.h"
# Line 14  Line 15 
15    
16  extern int sockpri;  extern int sockpri;
17  extern unsigned int capabilities;  extern unsigned int capabilities;
18    extern jmp_buf acctloop;
19    
20  static char *vbuf = NULL;       /* Virtual buffer. */  static char *vbuf = NULL;       /* Virtual buffer. */
21  static size_t vbufs = 0;        /* Virtual buffer size. */  static size_t vbufs = 0;        /* Virtual buffer size. */
# Line 44  int server_response(int *sock, unsigned Line 46  int server_response(int *sock, unsigned
46    
47      do {      do {
48          receive_response(sock, buf);          receive_response(sock, buf);
49            bye_response(buf);
50          check_vbuf(strlen(buf));          check_vbuf(strlen(buf));
51          strncat(vbuf, buf, vbufs - strlen(vbuf));          strncat(vbuf, buf, vbufs - strlen(vbuf));
52      } while (tag && !strcasestr(buf, ultostr(tag, 16)));      } while (tag && !strcasestr(buf, ultostr(tag, 16)));
# Line 53  int server_response(int *sock, unsigned Line 56  int server_response(int *sock, unsigned
56    
57    
58  /*  /*
59     * Check if server sent a BYE response (connection is closed immediately).
60     */
61    void bye_response(char *buf)
62    {
63        if (strcasestr(buf, "* BYE"))
64            longjmp(acctloop, -1);
65    }
66    
67    
68    /*
69   * Process the greeting that server sends during connection.   * Process the greeting that server sends during connection.
70   */   */
71  int greeting_response(int *sock)  int greeting_response(int *sock)
# Line 60  int greeting_response(int *sock) Line 73  int greeting_response(int *sock)
73      char buf[RESPONSE_BUF];      char buf[RESPONSE_BUF];
74    
75      receive_response(sock, buf);      receive_response(sock, buf);
76        bye_response(buf);
77    
78      if (strcasestr(buf, "BYE"))      if (strcasestr(buf, "* PREAUTH"))
         return RESPONSE_BYE;  
     else if (strcasestr(buf, "PREAUTH"))  
79          return RESPONSE_PREAUTH;          return RESPONSE_PREAUTH;
80    
81      return RESPONSE_OK;      return RESPONSE_OK;
# Line 71  int greeting_response(int *sock) Line 83  int greeting_response(int *sock)
83    
84    
85  /*  /*
86     * Process the data that server sent due to IMAP LOGOUT client request.
87     */
88    int logout_response(int *sock, unsigned int tag)
89    {
90        char buf[RESPONSE_BUF];
91    
92        reset_vbuf();
93    
94        do {
95            receive_response(sock, buf);
96            check_vbuf(strlen(buf));
97            strncat(vbuf, buf, vbufs - strlen(vbuf));
98        } while (!strcasestr(buf, ultostr(tag, 16)));
99    
100        return analyze_response(buf);
101    }
102    
103    
104    /*
105   * Process the data that server sent due to IMAP CAPABILITY client request.   * Process the data that server sent due to IMAP CAPABILITY client request.
106   */   */
107  int capability_response(int *sock, unsigned int tag)  int capability_response(int *sock, unsigned int tag)
# Line 81  int capability_response(int *sock, unsig Line 112  int capability_response(int *sock, unsig
112    
113      do {      do {
114          receive_response(sock, buf);          receive_response(sock, buf);
115            bye_response(buf);
116          check_vbuf(strlen(buf));          check_vbuf(strlen(buf));
117          strncat(vbuf, buf, vbufs - strlen(vbuf));          strncat(vbuf, buf, vbufs - strlen(vbuf));
118      } while (!strcasestr(buf, ultostr(tag, 16)));      } while (!strcasestr(buf, ultostr(tag, 16)));
# Line 107  int namespace_response(int *sock, unsign Line 139  int namespace_response(int *sock, unsign
139      reset_vbuf();      reset_vbuf();
140    
141      do {      do {
142            receive_response(sock, buf);
143            bye_response(buf);
144          check_vbuf(strlen(buf));          check_vbuf(strlen(buf));
145          strncat(vbuf, buf, vbufs - strlen(vbuf));          strncat(vbuf, buf, vbufs - strlen(vbuf));
         receive_response(sock, buf);  
146      } while (!strcasestr(buf, ultostr(tag, 16)));      } while (!strcasestr(buf, ultostr(tag, 16)));
147    
148      if ((c = strcasestr(vbuf, "* NAMESPACE"))) {      if ((c = strcasestr(vbuf, "* NAMESPACE"))) {
# Line 145  int status_response(int *sock, unsigned Line 178  int status_response(int *sock, unsigned
178    
179      do {      do {
180          receive_response(sock, buf);          receive_response(sock, buf);
181            bye_response(buf);
182          check_vbuf(strlen(buf));          check_vbuf(strlen(buf));
183          strncat(vbuf, buf, vbufs - strlen(vbuf));          strncat(vbuf, buf, vbufs - strlen(vbuf));
184      } while (!strcasestr(buf, ultostr(tag, 16)));      } while (!strcasestr(buf, ultostr(tag, 16)));
# Line 188  int select_response(int *sock, unsigned Line 222  int select_response(int *sock, unsigned
222    
223      do {      do {
224          receive_response(sock, buf);          receive_response(sock, buf);
225            bye_response(buf);
226          check_vbuf(strlen(buf));          check_vbuf(strlen(buf));
227          strncat(vbuf, buf, vbufs - strlen(vbuf));          strncat(vbuf, buf, vbufs - strlen(vbuf));
228      } while (!strcasestr(buf, ultostr(tag, 16)));      } while (!strcasestr(buf, ultostr(tag, 16)));
# Line 212  int search_response(int *sock, unsigned Line 247  int search_response(int *sock, unsigned
247    
248      do {      do {
249          receive_response(sock, buf);          receive_response(sock, buf);
250            bye_response(buf);
251          check_vbuf(strlen(buf));          check_vbuf(strlen(buf));
252          strncat(vbuf, buf, vbufs - strlen(vbuf));          strncat(vbuf, buf, vbufs - strlen(vbuf));
253      } while (!strcasestr(buf, ultostr(tag, 16)));      } while (!strcasestr(buf, ultostr(tag, 16)));
# Line 223  int search_response(int *sock, unsigned Line 259  int search_response(int *sock, unsigned
259    
260          c += 9;          c += 9;
261    
262          while (*c && (isdigit(*c) || *c == ' '))          while (*c && (isdigit((unsigned char)(*c)) || *c == ' '))
263              *(m++) = *(c++);              *(m++) = *(c++);
264    
265          *m = 0;          *m = 0;
# Line 235  int search_response(int *sock, unsigned Line 271  int search_response(int *sock, unsigned
271  /*  /*
272   * Process the data that server sent due to IMAP FETCH client request.   * Process the data that server sent due to IMAP FETCH client request.
273   */   */
274  int fetch_response(int *sock, int reset, char *fetch, unsigned int tag)  int fetch_response(int *sock, unsigned int tag, int reset, char *fetch)
275  {  {
276      char buf[RESPONSE_BUF];      char buf[RESPONSE_BUF];
277      unsigned int i;      unsigned int i;
# Line 248  int fetch_response(int *sock, int reset, Line 284  int fetch_response(int *sock, int reset,
284      }      }
285      i = 0;      i = 0;
286    
287      receive_response(sock, buf);      reset_vbuf();
288    
289        do {
290            receive_response(sock, buf);
291            bye_response(buf);
292            check_vbuf(strlen(buf));
293            strncat(vbuf, buf, vbufs - strlen(vbuf));
294        } while (strlen(vbuf) < RESPONSE_BUF &&
295                 !strcasestr(buf, ultostr(tag, 16)));
296    
297      b = buf;      b = vbuf;
298    
299      if (!s) {      if (!s && (b = strstr(b, "}\r\n"))) {
300          b = strchr(b, '{');          while (b - vbuf > 0)
301          b++;              if (*--b == '{')
302          s = atoi(b) - 2;                  break;
303            s = atoi(++b) - 2;
304          b = strchr(b, '}');          b = strchr(b, '}');
305          b += 3;          b += 3;
306      }      }
# Line 283  int fetchsize_response(int *sock, unsign Line 328  int fetchsize_response(int *sock, unsign
328    
329      do {      do {
330          receive_response(sock, buf);          receive_response(sock, buf);
331            bye_response(buf);
332          check_vbuf(strlen(buf));          check_vbuf(strlen(buf));
333          strncat(vbuf, buf, vbufs - strlen(vbuf));          strncat(vbuf, buf, vbufs - strlen(vbuf));
334      } while (!strcasestr(buf, ultostr(tag, 16)));      } while (!strcasestr(buf, ultostr(tag, 16)));
# Line 307  int append_response(int *sock, unsigned Line 353  int append_response(int *sock, unsigned
353    
354      do {      do {
355          receive_response(sock, buf);          receive_response(sock, buf);
356            bye_response(buf);
357          check_vbuf(strlen(buf));          check_vbuf(strlen(buf));
358          strncat(vbuf, buf, vbufs - strlen(vbuf));          strncat(vbuf, buf, vbufs - strlen(vbuf));
359      } while (!strcasestr(buf, ultostr(tag, 16)));      } while (!strcasestr(buf, ultostr(tag, 16)));
# Line 331  int copy_response(int *sock, unsigned in Line 378  int copy_response(int *sock, unsigned in
378    
379      do {      do {
380          receive_response(sock, buf);          receive_response(sock, buf);
381            bye_response(buf);
382          check_vbuf(strlen(buf));          check_vbuf(strlen(buf));
383          strncat(vbuf, buf, vbufs - strlen(vbuf));          strncat(vbuf, buf, vbufs - strlen(vbuf));
384      } while (!strcasestr(buf, ultostr(tag, 16)));      } while (!strcasestr(buf, ultostr(tag, 16)));
# Line 383  int analyze_response(char *buf) Line 431  int analyze_response(char *buf)
431   */   */
432  void init_vbuf(void)  void init_vbuf(void)
433  {  {
434      vbuf = xmalloc(4096);      vbuf = xmalloc(VIRTUAL_BUF);
435      *vbuf = 0;      *vbuf = 0;
436      vbufs = 4096;      vbufs = VIRTUAL_BUF;
437  }  }
438    
439    
# Line 404  void reset_vbuf(void) Line 452  void reset_vbuf(void)
452  void check_vbuf(size_t n)  void check_vbuf(size_t n)
453  {  {
454      if (n + strlen(vbuf) >= vbufs) {      if (n + strlen(vbuf) >= vbufs) {
455          vbufs += 4096;          vbufs += VIRTUAL_BUF;
456          vbuf = xrealloc(vbuf, vbufs);          vbuf = xrealloc(vbuf, vbufs);
457      }      }
458  }  }

Legend:
Removed from v.1.23  
changed lines
  Added in v.1.23.2.5

webmaster@linux.gr
ViewVC Help
Powered by ViewVC 1.1.26