diff options
author | ꦌ ꦫꦶ ꦏ꧀ꦦꦿ ꦧ ꦮ ꦑ ꦩ ꦭ꧀ <erik@darapsa.co.id> | 2019-09-16 20:43:28 +0800 |
---|---|---|
committer | ꦌ ꦫꦶ ꦏ꧀ꦦꦿ ꦧ ꦮ ꦑ ꦩ ꦭ꧀ <erik@darapsa.co.id> | 2019-09-16 20:43:28 +0800 |
commit | e405b28efceb0865910c3821d92f6f3cb9a6f0be (patch) | |
tree | b0d44ce408d8f22052e3450bc8fc066c55f2b20c /icclient/request.h | |
parent | 47be7ba91f07acb7bf88b66fc706ee6b4add69bd (diff) |
Product related structures and functions
Diffstat (limited to 'icclient/request.h')
-rw-r--r-- | icclient/request.h | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/icclient/request.h b/icclient/request.h new file mode 100644 index 0000000..192a154 --- /dev/null +++ b/icclient/request.h @@ -0,0 +1,50 @@ +#ifndef ICCLIENT_REQUEST_H +#define ICCLIENT_REQUEST_H + +#ifdef DEBUG +#ifdef ANDROID +#include <android/log.h> +#else +#include <stdio.h> +#endif // ANDROID +#endif // DEBUG +#include <string.h> +#include <curl/curl.h> + +extern CURL *curl; +extern char *server_url; + +inline void request(const char *path + , size_t (*writefunction)(void *, size_t, size_t, void *) + , void *writedata, struct curl_httppost *post) +{ + char url[strlen(server_url) + strlen(path) + 1]; + sprintf(url, "%s%s", server_url, path); + curl_easy_setopt(curl, CURLOPT_URL, url); + curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, writefunction); + if (writedata) + curl_easy_setopt(curl, CURLOPT_WRITEDATA, writedata); + else + curl_easy_setopt(curl, CURLOPT_WRITEDATA, stdout); + if (post) + curl_easy_setopt(curl, CURLOPT_HTTPPOST, post); + else + curl_easy_setopt(curl, CURLOPT_HTTPGET, 1L); + +#ifdef DEBUG + CURLcode res = +#endif // DEBUG + curl_easy_perform(curl); +#ifdef DEBUG + if (res != CURLE_OK) { + const char *error = curl_easy_strerror(res); +#ifdef ANDROID + __android_log_print(ANDROID_LOG_ERROR, "libicclient", "%s: %s" + , __func__, error); +#else + fprintf(stderr, "%s: %s\n", __func__, error); +#endif // ANDROID + } +#endif // DEBUG +} +#endif // ICCLIENT_REQUEST_H |