summaryrefslogtreecommitdiff
path: root/imap/src
diff options
context:
space:
mode:
Diffstat (limited to 'imap/src')
-rw-r--r--imap/src/c-client/auth_bea.c15
-rw-r--r--imap/src/c-client/auth_oa2.c15
-rw-r--r--imap/src/c-client/http.c25
-rw-r--r--imap/src/c-client/http.h10
4 files changed, 43 insertions, 22 deletions
diff --git a/imap/src/c-client/auth_bea.c b/imap/src/c-client/auth_bea.c
index 94305132..6b78fe64 100644
--- a/imap/src/c-client/auth_bea.c
+++ b/imap/src/c-client/auth_bea.c
@@ -219,6 +219,7 @@ mm_login_oauth2_c_client_method (NETMBX *mb, char *user, char *method,
OAUTH2_SERVER_METHOD_S RefreshMethod;
unsigned char *s = NULL;
JSON_S *json = NULL;
+ int status = 0;
if(oauth2->param[OA2_Id].value == NULL || oauth2->param[OA2_Secret].value == NULL){
oauth2clientinfo_t ogci =
@@ -243,9 +244,12 @@ mm_login_oauth2_c_client_method (NETMBX *mb, char *user, char *method,
params[i].name = params[i].value = NULL;
if(strcmp(RefreshMethod.name, "POST") == 0)
- s = http_post_param(RefreshMethod.urlserver, params);
+ s = http_post_param(RefreshMethod.urlserver, params, &status);
else if(strcmp(RefreshMethod.name, "POST2") == 0)
- s = http_post_param2(RefreshMethod.urlserver, params);
+ s = http_post_param2(RefreshMethod.urlserver, params, &status);
+
+ if(status != 200 && s)
+ fs_give((void **) &s); /* at this moment ignore the reply text */
if(s){
unsigned char *u = s;
@@ -301,9 +305,12 @@ mm_login_oauth2_c_client_method (NETMBX *mb, char *user, char *method,
params[i].name = params[i].value = NULL;
if(strcmp(RefreshMethod.name, "POST") == 0)
- s = http_post_param(RefreshMethod.urlserver, params);
+ s = http_post_param(RefreshMethod.urlserver, params, &status);
else if(strcmp(RefreshMethod.name, "POST2") == 0)
- s = http_post_param2(RefreshMethod.urlserver, params);
+ s = http_post_param2(RefreshMethod.urlserver, params, &status);
+
+ if(status != 200 && s)
+ fs_give((void **) &s); /* at this moment ignore the error */
if(s){
unsigned char *u = s;
diff --git a/imap/src/c-client/auth_oa2.c b/imap/src/c-client/auth_oa2.c
index b003a653..6de4395e 100644
--- a/imap/src/c-client/auth_oa2.c
+++ b/imap/src/c-client/auth_oa2.c
@@ -236,6 +236,7 @@ mm_login_oauth2_c_client_method (NETMBX *mb, char *user, char *method,
OAUTH2_SERVER_METHOD_S RefreshMethod;
char *s = NULL;
JSON_S *json = NULL;
+ int status = 0;
if(oauth2->param[OA2_Id].value == NULL || oauth2->param[OA2_Secret].value == NULL){
oauth2clientinfo_t ogci =
@@ -260,9 +261,12 @@ mm_login_oauth2_c_client_method (NETMBX *mb, char *user, char *method,
params[i].name = params[i].value = NULL;
if(strcmp(RefreshMethod.name, "POST") == 0)
- s = http_post_param(RefreshMethod.urlserver, params);
+ s = http_post_param(RefreshMethod.urlserver, params, &status);
else if(strcmp(RefreshMethod.name, "POST2") == 0)
- s = http_post_param2(RefreshMethod.urlserver, params);
+ s = http_post_param2(RefreshMethod.urlserver, params, &status);
+
+ if(status != 200 && s)
+ fs_give((void **) &s); /* at this moment, ignore the error */
if(s){
unsigned char *u = s;
@@ -318,9 +322,12 @@ mm_login_oauth2_c_client_method (NETMBX *mb, char *user, char *method,
params[i].name = params[i].value = NULL;
if(strcmp(RefreshMethod.name, "POST") == 0)
- s = http_post_param(RefreshMethod.urlserver, params);
+ s = http_post_param(RefreshMethod.urlserver, params, &status);
else if(strcmp(RefreshMethod.name, "POST2") == 0)
- s = http_post_param2(RefreshMethod.urlserver, params);
+ s = http_post_param2(RefreshMethod.urlserver, paramsm &status);
+
+ if(status != 200 && s)
+ fs_give((void **) &s); /* at this moment, ignore the error */
if(s){
unsigned char *u = s;
diff --git a/imap/src/c-client/http.c b/imap/src/c-client/http.c
index f287e4fc..23d9f4b0 100644
--- a/imap/src/c-client/http.c
+++ b/imap/src/c-client/http.c
@@ -942,7 +942,7 @@ http_open (unsigned char *url)
}
unsigned char *
-http_post_param(unsigned char *url, HTTP_PARAM_S *param)
+http_post_param(unsigned char *url, HTTP_PARAM_S *param, int *code)
{
HTTPSTREAM *stream;
HTTP_PARAM_S enc_param;
@@ -950,6 +950,7 @@ http_post_param(unsigned char *url, HTTP_PARAM_S *param)
unsigned char *response = NULL;
int i;
+ *code = -1;
if(url == NULL || param == NULL || (stream = http_open(url)) == NULL)
return response;
@@ -973,6 +974,7 @@ http_post_param(unsigned char *url, HTTP_PARAM_S *param)
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);
}
@@ -982,7 +984,7 @@ http_post_param(unsigned char *url, HTTP_PARAM_S *param)
}
unsigned char *
-http_post_param2(unsigned char *url, HTTP_PARAM_S *param)
+http_post_param2(unsigned char *url, HTTP_PARAM_S *param, int *code)
{
HTTPSTREAM *stream;
HTTP_PARAM_S enc_param;
@@ -990,6 +992,7 @@ http_post_param2(unsigned char *url, HTTP_PARAM_S *param)
unsigned char *response = NULL;
int i;
+ *code = -1;
if(url == NULL || param == NULL || (stream = http_open(url)) == NULL)
return response;
@@ -1014,6 +1017,7 @@ http_post_param2(unsigned char *url, HTTP_PARAM_S *param)
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);
}
@@ -1023,25 +1027,27 @@ http_post_param2(unsigned char *url, HTTP_PARAM_S *param)
}
unsigned char *
-http_get_param(unsigned char *base_url, HTTP_PARAM_S *param)
+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);
+ response = http_get(url, code);
fs_give((void **) &url);
}
return response;
}
unsigned char *
-http_get(unsigned char *url)
+http_get(unsigned char *url, int *code)
{
HTTP_REQUEST_S *http_request;
unsigned char *response = NIL;
HTTPSTREAM *stream;
+ *code = -1;
if(!url) return response;
stream = http_open(url);
if(!stream){
@@ -1056,6 +1062,7 @@ http_get(unsigned char *url)
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);
}
@@ -1112,7 +1119,7 @@ http_status_line_get(unsigned char *status_line)
{
HTTP_STATUS_S *rv = NULL;
char *version, *s;
- int status;
+ int code;
if(!status_line) return NIL;
@@ -1120,11 +1127,11 @@ http_status_line_get(unsigned char *status_line)
*s = '\0';
version = cpystr(status_line);
*s++ = ' ';
- status = strtoul(s, &s, 10);
- if(s && *s == ' ' && status >= 100 && status < 600){
+ code = strtoul(s, &s, 10);
+ if(s && *s == ' ' && code >= 100 && code < 600){
rv = fs_get(sizeof(HTTP_STATUS_S));
rv->version = version;
- rv->status = status;
+ rv->code = code;
rv->text = cpystr(++s);
}
else
diff --git a/imap/src/c-client/http.h b/imap/src/c-client/http.h
index c7c0147d..84607707 100644
--- a/imap/src/c-client/http.h
+++ b/imap/src/c-client/http.h
@@ -79,7 +79,7 @@ typedef struct http_header_data_s {
typedef struct http_status_s {
char *version;
- int status;
+ int code;
char *text;
} HTTP_STATUS_S;
@@ -103,10 +103,10 @@ typedef struct http_param_s {
/* exported prototypes */
HTTPSTREAM *http_open (unsigned char *);
-unsigned char *http_post_param(unsigned char *, HTTP_PARAM_S *);
-unsigned char *http_post_param2(unsigned char *, HTTP_PARAM_S *);
-unsigned char *http_get_param(unsigned char *, HTTP_PARAM_S *);
-unsigned char *http_get(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 *);
void http_close (HTTPSTREAM *stream);
HTTP_PARAM_S *http_param_get(int);