diff options
Diffstat (limited to 'imap')
-rw-r--r-- | imap/src/c-client/c-client.h | 1 | ||||
-rw-r--r-- | imap/src/c-client/http.c | 35 | ||||
-rw-r--r-- | imap/src/c-client/http.h | 3 | ||||
-rw-r--r-- | imap/src/c-client/mail.c | 1 | ||||
-rw-r--r-- | imap/src/c-client/mail.h | 3 | ||||
-rw-r--r-- | imap/src/c-client/oauth2_aux.c | 2 |
6 files changed, 38 insertions, 7 deletions
diff --git a/imap/src/c-client/c-client.h b/imap/src/c-client/c-client.h index b279bff9..b190db86 100644 --- a/imap/src/c-client/c-client.h +++ b/imap/src/c-client/c-client.h @@ -43,6 +43,7 @@ extern "C" { #include "rfc822.h" /* RFC822 and MIME routines */ #include "smtp.h" /* SMTP sending routines */ #include "nntp.h" /* NNTP sending routines */ +#include "http.h" /* HTTP management routines */ #include "utf8.h" /* Unicode and charset routines */ #include "utf8aux.h" /* Unicode auxiliary routines */ #include "misc.h" /* miscellaneous utility routines */ diff --git a/imap/src/c-client/http.c b/imap/src/c-client/http.c index fef3c7fc..cb34f896 100644 --- a/imap/src/c-client/http.c +++ b/imap/src/c-client/http.c @@ -1,5 +1,5 @@ /* - * Copyright 2018-2020 Eduardo Chappa + * Copyright 2018-2021 Eduardo Chappa * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -11,10 +11,11 @@ #include <ctype.h> #include <stdio.h> #include <time.h> -#include "c-client.h" +#include "c-client.h" /* this includes http.h */ #include "flstring.h" #include "netmsg.h" -#include "http.h" + +unsigned long http_debug; //char t[] = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!#$%&'*+-.^_`|~"; static char http_notok[] = "\1\2\3\4\5\6\7\10\11\12\13\14\15\16\17\20\21\22\23\24\25\26\27\30\31\32\33\34\35\36\37\40\42\50\51\54\57\72\73\74\75\76\77\100\133\134\135\173\175\177\200\201\202\203\204\205\206\207\210\211\212\213\214\215\216\217\220\221\222\223\224\225\226\227\230\231\232\233\234\235\236\237\240\241\242\243\244\245\246\247\250\251\252\253\254\255\256\257\260\261\262\263\264\265\266\267\270\271\272\273\274\275\276\277\300\301\302\303\304\305\306\307\310\311\312\313\314\315\316\317\320\321\322\323\324\325\326\327\330\331\332\333\334\335\336\337\340\341\342\343\344\345\346\347\350\351\352\353\354\355\356\357\360\361\362\363\364\365\366\367\370\371\372\373\374\375\376\377"; @@ -107,7 +108,6 @@ unsigned char *http_response_from_reply(HTTPSTREAM *); /* HTTP function prototypes */ int http_valid_net_parse (unsigned char *, NETMBX *); -void *http_parameters (long function,void *value); long http_send (HTTPSTREAM *, HTTP_REQUEST_S *); long http_reply (HTTPSTREAM *); @@ -131,6 +131,19 @@ PARAMETER *http_parse_parameter(unsigned char *, int); void http_parse_headers(HTTPSTREAM *); +void * +http_parameters (long function,void *value) +{ + void *ret = NIL; + switch((int) function){ + case SET_HTTPDEBUG: http_debug = (long) value; + case GET_HTTPDEBUG: ret = (void *) http_debug; + break; + } + return ret; +} + + unsigned char * http_response_from_reply(HTTPSTREAM *stream) { @@ -941,6 +954,7 @@ http_open (unsigned char *url) http_close(stream); stream = NIL; } + stream->debug = http_debug; return stream; } @@ -1104,7 +1118,9 @@ http_send (HTTPSTREAM *stream, HTTP_REQUEST_S *req) buffer_add(&s, req->request); buffer_add(&s, "\015\012"); buffer_add(&s, req->header); buffer_add(&s, "\015\012"); buffer_add(&s, req->body); buffer_add(&s, "\015\012"); - mm_log(s, TCPDEBUG); + + if(stream->debug) mm_log(s, HTTPDEBUG); + ret = net_soutr (stream->netstream,s) ? http_reply (stream) : http_fake (stream,"http connection broken in command"); @@ -1159,6 +1175,8 @@ http_reply (HTTPSTREAM *stream) if (stream->response) fs_give ((void **) &stream->response); stream->response = (unsigned char *) net_getline(stream->netstream); + if(stream->debug) mm_log(stream->response, HTTPDEBUG); + if(stream->response){ buffer_add(&stream->reply, stream->response); buffer_add(&stream->reply, "\015\012"); @@ -1178,6 +1196,7 @@ http_reply (HTTPSTREAM *stream) if(stream->response){ buffer_add(&stream->reply, stream->response); http_add_header_data(stream, stream->response); + if(stream->debug) mm_log(stream->response, HTTPDEBUG); } buffer_add(&stream->reply, "\015\012"); // save_header(stream->headers, stream->response); @@ -1190,7 +1209,10 @@ http_reply (HTTPSTREAM *stream) size = atol(stream->header->content_length->p->vp->value); if (stream->response) fs_give ((void **) &stream->response); stream->response = (unsigned char *) net_getsize (stream->netstream, size); - if(stream->response) buffer_add(&stream->reply, stream->response); + if(stream->response){ + buffer_add(&stream->reply, stream->response); + if(stream->debug) mm_log(stream->response, HTTPDEBUG); + } } else if (stream->header->transfer_encoding){ HTTP_PARAM_LIST_S *p = stream->header->transfer_encoding->p; @@ -1211,6 +1233,7 @@ http_reply (HTTPSTREAM *stream) fs_give ((void **) &stream->response); stream->response = (unsigned char *) net_getsize (stream->netstream, size); buffer_add(&stream->reply, stream->response); + if(stream->debug) mm_log(stream->response, HTTPDEBUG); } if(size == 0L) done++; } diff --git a/imap/src/c-client/http.h b/imap/src/c-client/http.h index 41b16842..9c7464e1 100644 --- a/imap/src/c-client/http.h +++ b/imap/src/c-client/http.h @@ -90,6 +90,7 @@ typedef struct http_status_s { typedef struct http_stream { NETSTREAM *netstream; HTTP_HEADER_DATA_S *header; /* headers sent by the server */ + unsigned int debug : 1; /* send debug information */ char *url; /* original url */ char *urlhost; /* get original host */ char *urltail; /* the part of the URL after the original host */ @@ -115,5 +116,7 @@ void http_close (HTTPSTREAM *stream); HTTP_PARAM_S *http_param_get(int); void http_param_free(HTTP_PARAM_S **); +void *http_parameters (long,void *); + /* Ugghh.... just construct the URL for a get request */ unsigned char *http_get_param_url(unsigned char *, HTTP_PARAM_S *); diff --git a/imap/src/c-client/mail.c b/imap/src/c-client/mail.c index 981025c1..f3e14fe3 100644 --- a/imap/src/c-client/mail.c +++ b/imap/src/c-client/mail.c @@ -701,6 +701,7 @@ void *mail_parameters (MAILSTREAM *stream,long function,void *value) if ((r = smtp_parameters (function,value)) != NULL) ret = r; if ((r = env_parameters (function,value)) != NULL) ret = r; if ((r = tcp_parameters (function,value)) != NULL) ret = r; + if ((r = http_parameters (function,value)) != NULL) ret = r; if ((r = utf8_parameters (function,value)) != NULL) ret = r; if (stream && stream->dtb) {/* if have stream, do for its driver only */ if ((r = (*stream->dtb->parameters) (function,value)) != NULL) ret = r; diff --git a/imap/src/c-client/mail.h b/imap/src/c-client/mail.h index 79f0b3f3..ce5e2847 100644 --- a/imap/src/c-client/mail.h +++ b/imap/src/c-client/mail.h @@ -160,6 +160,8 @@ #define SET_OA2CLIENTINFO (long) 172 #define GET_OA2DEVICEINFO (long) 173 #define SET_OA2DEVICEINFO (long) 174 +#define GET_HTTPDEBUG (long) 175 +#define SET_HTTPDEBUG (long) 176 /* 2xx: environment */ #define GET_USERNAME (long) 201 @@ -573,6 +575,7 @@ #define PARSE (long) 3 /* mm_log parse error type */ #define BYE (long) 4 /* mm_notify stream dying */ #define TCPDEBUG (long) 5 /* mm_log TCP debug babble */ +#define HTTPDEBUG (long) 6 /* mm_log HTTP debug babble */ /* Bits from mail_parse_flags(). Don't change these, since the header format diff --git a/imap/src/c-client/oauth2_aux.c b/imap/src/c-client/oauth2_aux.c index 420f3be1..b1af30b1 100644 --- a/imap/src/c-client/oauth2_aux.c +++ b/imap/src/c-client/oauth2_aux.c @@ -20,7 +20,7 @@ * the deviceinfo method. */ -#include "http.h" +/* http.h is supposed to be included, typically by including c-client.h */ #include "json.h" #include "oauth2_aux.h" |