summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEduardo Chappa <chappa@washington.edu>2021-06-10 20:15:14 -0600
committerEduardo Chappa <chappa@washington.edu>2021-06-10 20:15:14 -0600
commitc7aed72b5ec34501f488b96591bbc018f76d351f (patch)
treebcc6b488e2aeae537c92f3b2aee5770843cfadca
parentaffb946709254a8c6f68409e2ffb6d36f7d38edd (diff)
downloadalpine-c7aed72b5ec34501f488b96591bbc018f76d351f.tar.xz
* Rewrite of http code to keep connections alive after GET and POST
commands.
-rw-r--r--alpine/help.c5
-rw-r--r--imap/src/c-client/http.c41
-rw-r--r--imap/src/c-client/http.h7
-rw-r--r--imap/src/c-client/oauth2_aux.c6
-rw-r--r--pith/pine.hlp2
5 files changed, 19 insertions, 42 deletions
diff --git a/alpine/help.c b/alpine/help.c
index aa55848a..e9937cb2 100644
--- a/alpine/help.c
+++ b/alpine/help.c
@@ -136,7 +136,10 @@ helper_internal(HelpType text, char *frag, char *title, int flags)
if(shown_text && *shown_text && !struncmp(*shown_text, "x-alpine-http:", 14)){
int status;
- help_text = http_get(*shown_text + 14, &status);
+ HTTPSTREAM *stream = http_open(*shown_text + 14);
+ if(stream) help_text = http_get(stream);
+ status = stream->status ? stream->status->code : -1;
+ if(stream) http_close(stream);
if(status != HTTP_OK){
shown_text = NO_HELP;
if(help_text) fs_give((void **) &help_text);
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);
diff --git a/pith/pine.hlp b/pith/pine.hlp
index 59812c93..d8d4075d 100644
--- a/pith/pine.hlp
+++ b/pith/pine.hlp
@@ -140,7 +140,7 @@ with help text for the config screen and the composer that didn't have any
reasonable place to be called from.
Dummy change to get revision in pine.hlp
============= h_revision =================
-Alpine Commit 564 2021-06-10 16:26:14
+Alpine Commit 565 2021-06-10 20:14:46
============= h_news =================
<HTML>
<HEAD>