diff options
| author | ꦌ ꦫꦶ ꦏ꧀ꦦꦿ ꦧ ꦮ ꦑ ꦩ ꦭ꧀ <erik@darapsa.co.id> | 2019-09-19 16:43:18 +0800 |
|---|---|---|
| committer | ꦌ ꦫꦶ ꦏ꧀ꦦꦿ ꦧ ꦮ ꦑ ꦩ ꦭ꧀ <erik@darapsa.co.id> | 2019-09-19 16:43:18 +0800 |
| commit | 4898094229ecee8061896280afffbe74bae717e8 (patch) | |
| tree | 55e8afe517123877846e8e9ff8edfa21e99be307 /post.h | |
| parent | a88e6d47c5e51d09415e450ece221fb7665f34f6 (diff) | |
Post content builder inline function
Diffstat (limited to 'post.h')
| -rw-r--r-- | post.h | 30 |
1 files changed, 30 insertions, 0 deletions
@@ -0,0 +1,30 @@ +#include "request.h" + +inline void post(const char *path, const char *pairs[], size_t n) +{ + size_t length = 0; + for (size_t i = 0; i < n; i += 2) { + const char *pair = pairs[i]; + if (pair && strcmp(pair, "")) + length += strlen(pair) + strlen(++pair) + 3; + } + + char content[length + 1]; + memset(content, 0, strlen(content)); + for (size_t i = 0; i < n; i += 2) { + const char *pair = pairs[i]; + if (pair && strcmp(pair, "")) + sprintf(content, "%s%s: %s\n", content, pairs[i + 1] + , pair); + } + + struct curl_httppost *post, *last = NULL; + curl_formadd(&post, &last + , CURLFORM_COPYNAME, "content" + , CURLFORM_PTRCONTENTS, content + , CURLFORM_END); + last = NULL; + request(path, "", NULL, NULL, post); + curl_formfree(post); + post = NULL; +} |