From e6d9edc048efb5b19d79bbe7871b2ff779d72311 Mon Sep 17 00:00:00 2001 From: Iru Cai Date: Wed, 27 Jun 2018 22:56:25 +0800 Subject: initial code --- util.h | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 util.h (limited to 'util.h') diff --git a/util.h b/util.h new file mode 100644 index 0000000..509bcb9 --- /dev/null +++ b/util.h @@ -0,0 +1,39 @@ +#ifndef MATRIX_CURL_UTIL_H +#define MATRIX_CURL_UTIL_H + +#include +#include +#include + +CURLcode _curl_get(CURL *curl, const char *url, json_object **resp); +CURLcode _curl_post(CURL *curl, const char *url, const char *postdata, + json_object **resp); + +static inline int +json_add_string(json_object *j, const char *k, const char *v) +{ + return json_object_object_add(j, k, json_object_new_string(v)); +} + +static inline +const char *json_gets(json_object *j, const char *key) +{ + json_object *val; + + if (json_object_object_get_ex(j, key, &val)) { + if (json_object_is_type(val, json_type_string)) + return json_object_get_string(val); + } + return NULL; +} + +static inline +char* copy_str(const char *s) +{ + size_t l = strlen(s)+1; + char *ss = (char*)malloc(l); + memcpy(ss, s, l); + return ss; +} + +#endif -- cgit v1.2.3