summaryrefslogtreecommitdiff
path: root/post.h
blob: acfa3f3437e6f675890506da796b6d037d08d227 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#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(pairs[i + 1]) + 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);
	}
#ifdef DEBUG
#ifdef ANDROID
	__android_log_print(ANDROID_LOG_DEBUG, "librtclient", "%s\nContent:\n%s"
			, __func__, content);
#else
	fprintf(stderr, "%s\nContent:\n%s", __func__, content);
#endif // ANDROID
#endif // DEBUG

	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;
}