diff options
Diffstat (limited to 'rtclient')
-rw-r--r-- | rtclient/common.h | 13 | ||||
-rw-r--r-- | rtclient/request.h | 50 |
2 files changed, 50 insertions, 13 deletions
diff --git a/rtclient/common.h b/rtclient/common.h deleted file mode 100644 index a63a10c..0000000 --- a/rtclient/common.h +++ /dev/null @@ -1,13 +0,0 @@ -#ifndef RTCLIENT_COMMON_H -#define RTCLIENT_COMMON_H - -#include <curl/curl.h> - -extern CURL *curl; -extern char *server_url; - -void request(const char *path, const char *suffix - , size_t (*writefunction)(void *, size_t, size_t, void *) - , void *writedata, struct curl_httppost *post); - -#endif // RTCLIENT_COMMON_H diff --git a/rtclient/request.h b/rtclient/request.h new file mode 100644 index 0000000..a523610 --- /dev/null +++ b/rtclient/request.h @@ -0,0 +1,50 @@ +#ifndef RTCLIENT_REQUEST_H +#define RTCLIENT_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, const char *suffix + , size_t (*writefunction)(void *, size_t, size_t, void *) + , void *writedata, struct curl_httppost *post) +{ + char url[strlen(server_url) + strlen(path) + strlen(suffix) + 1]; + sprintf(url, "%s%s%s", server_url, path, suffix); + 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, "librtclient", "%s: %s" + , __func__, error); +#else + fprintf(stderr, "%s: %s\n", __func__, error); +#endif // ANDROID + } +#endif // DEBUG +} +#endif // RTCLIENT_REQUEST_H |