1
0
Fork 0
mirror of https://github.com/deltachat/deltachat-core.git synced 2025-10-06 03:50:08 +02:00

add DC_EVENT_HTTP_POST, needed to regenerate OAuth2 tokens

This commit is contained in:
B. Petersen 2019-02-15 18:32:45 +01:00
parent fee032b513
commit 1c5ab7444d
No known key found for this signature in database
GPG key ID: 3B88E92DEA8E9AFC
3 changed files with 43 additions and 3 deletions

View file

@ -67,17 +67,33 @@ static uintptr_t receive_event(dc_context_t* context, int event, uintptr_t data1
break;
case DC_EVENT_HTTP_GET:
case DC_EVENT_HTTP_POST:
{
char* url = dc_strdup((char*)data1);
char* param = strchr(url, '?');
if (param) {
*param = 0;
param++;
}
else {
param = "";
}
char* ret = NULL;
char* tempFile = dc_get_fine_pathNfilename(context, context->blobdir, "curl.result");
char* cmd = dc_mprintf("curl --silent --location --fail --insecure %s > %s", (char*)data1, tempFile); /* --location = follow redirects */
char* cmd = event==DC_EVENT_HTTP_GET?
dc_mprintf("curl --silent --location --fail --insecure %s%s%s > %s", url, param[0]? "?" : "", param, tempFile) :
dc_mprintf("curl --silent -d \"%s\" %s > %s", param, url, tempFile);
int error = system(cmd);
if (error == 0) { /* -1=system() error, !0=curl errors forced by -f, 0=curl success */
size_t bytes = 0;
dc_read_file(context, tempFile, (void**)&ret, &bytes);
}
free(cmd);
free(tempFile);
free(url);
return (uintptr_t)ret;
}