diff options
Diffstat (limited to 'imap')
-rw-r--r-- | imap/src/c-client/http.c | 41 | ||||
-rw-r--r-- | imap/src/c-client/http.h | 7 | ||||
-rw-r--r-- | imap/src/c-client/oauth2_aux.c | 6 |
3 files changed, 14 insertions, 40 deletions
diff --git a/imap/src/c-client/http.c b/imap/src/c-client/http.c index d073dc6c..0162502d 100644 --- a/imap/src/c-client/http.c +++ b/imap/src/c-client/http.c @@ -959,17 +959,14 @@ http_open (unsigned char *url) } unsigned char * -http_post_param(unsigned char *url, HTTP_PARAM_S *param, int *code) +http_post_param(HTTPSTREAM *stream, HTTP_PARAM_S *param) { - HTTPSTREAM *stream; HTTP_PARAM_S enc_param; HTTP_REQUEST_S *http_request; unsigned char *response = NULL; int i; - *code = -1; - if(url == NULL || param == NULL || (stream = http_open(url)) == NULL) - return response; + if(stream == NULL || param == NULL ) return response; http_request = http_request_get(); http_request->request = http_request_line("POST", stream->urltail, HTTP_1_1_VERSION); @@ -991,8 +988,6 @@ http_post_param(unsigned char *url, HTTP_PARAM_S *param, int *code) if(http_send(stream, http_request)){ unsigned char *s = http_response_from_reply(stream); response = cpystr(s ? (char *) s : ""); - *code = stream->status ? stream->status->code : -1; - http_close(stream); } http_request_free(&http_request); @@ -1001,17 +996,14 @@ http_post_param(unsigned char *url, HTTP_PARAM_S *param, int *code) } unsigned char * -http_post_param2(unsigned char *url, HTTP_PARAM_S *param, int *code) +http_post_param2(HTTPSTREAM *stream, HTTP_PARAM_S *param) { - HTTPSTREAM *stream; HTTP_PARAM_S enc_param; HTTP_REQUEST_S *http_request = NULL; unsigned char *response = NULL; int i; - *code = -1; - if(url == NULL || param == NULL || (stream = http_open(url)) == NULL) - return response; + if(stream == NULL || param == NULL) return response; http_request = http_request_get(); http_request->request = http_request_line("POST", stream->urltail, HTTP_1_1_VERSION); @@ -1034,8 +1026,6 @@ http_post_param2(unsigned char *url, HTTP_PARAM_S *param, int *code) if(http_send(stream, http_request)){ unsigned char *s = http_response_from_reply(stream); response = cpystr(s ? (char *) s : ""); - *code = stream->status ? stream->status->code : -1; - http_close(stream); } http_request_free(&http_request); @@ -1044,29 +1034,12 @@ http_post_param2(unsigned char *url, HTTP_PARAM_S *param, int *code) } unsigned char * -http_get_param(unsigned char *base_url, HTTP_PARAM_S *param, int *code) -{ - unsigned char *url, *response = NIL; - - *code = -1; - url = http_get_param_url(base_url, param); - if(url){ - response = http_get(url, code); - fs_give((void **) &url); - } - return response; -} - -unsigned char * -http_get(unsigned char *url, int *code) +http_get(HTTPSTREAM *stream) { HTTP_REQUEST_S *http_request; unsigned char *response = NIL; - HTTPSTREAM *stream; - *code = -1; - if(!url || !(stream = http_open(url))) - return response; + if(!stream) return response; http_request = http_request_get(); http_request->request = http_request_line("GET", stream->urltail, HTTP_1_1_VERSION); @@ -1075,8 +1048,6 @@ http_get(unsigned char *url, int *code) if(http_send(stream, http_request)){ unsigned char *s = http_response_from_reply(stream); response = cpystr(s ? (char *) s : ""); - *code = stream->status ? stream->status->code : -1; - http_close(stream); } http_request_free(&http_request); diff --git a/imap/src/c-client/http.h b/imap/src/c-client/http.h index 9c7464e1..1ddc988b 100644 --- a/imap/src/c-client/http.h +++ b/imap/src/c-client/http.h @@ -107,10 +107,9 @@ typedef struct http_param_s { /* exported prototypes */ HTTPSTREAM *http_open (unsigned char *); -unsigned char *http_post_param(unsigned char *, HTTP_PARAM_S *, int *); -unsigned char *http_post_param2(unsigned char *, HTTP_PARAM_S *, int *); -unsigned char *http_get_param(unsigned char *, HTTP_PARAM_S *, int *); -unsigned char *http_get(unsigned char *, int *); +unsigned char *http_post_param(HTTPSTREAM *, HTTP_PARAM_S *); +unsigned char *http_post_param2(HTTPSTREAM *, HTTP_PARAM_S *); +unsigned char *http_get(HTTPSTREAM *); void http_close (HTTPSTREAM *stream); HTTP_PARAM_S *http_param_get(int); diff --git a/imap/src/c-client/oauth2_aux.c b/imap/src/c-client/oauth2_aux.c index ad1c07de..0ecd0730 100644 --- a/imap/src/c-client/oauth2_aux.c +++ b/imap/src/c-client/oauth2_aux.c @@ -104,6 +104,7 @@ JSON_S *oauth2_json_reply(OAUTH2_SERVER_METHOD_S RefreshMethod, OAUTH2_S *oauth2 { JSON_S *json = NULL; HTTP_PARAM_S params[OAUTH2_PARAM_NUMBER]; + HTTPSTREAM *stream; unsigned char *s; char *server = NULL; @@ -111,11 +112,14 @@ JSON_S *oauth2_json_reply(OAUTH2_SERVER_METHOD_S RefreshMethod, OAUTH2_S *oauth2 *status = 0; server = xoauth2_server(RefreshMethod.urlserver, oauth2->param[OA2_Tenant].value); if(strcmp(RefreshMethod.name, "POST") == 0 - && ((s = http_post_param(server, params, status)) != NULL)){ + && ((stream = http_open(server)) != NULL) + && ((s = http_post_param(stream, params)) != NULL)){ unsigned char *u = s; json = json_parse(&u); fs_give((void **) &s); } + *status = stream->status ? stream->status->code : -1; + if(stream) http_close(stream); if(server) fs_give((void **) &server); |