From b0e376b6ba1891fcf749d22095c4f79a843a5d0f Mon Sep 17 00:00:00 2001 From: Iru Cai Date: Wed, 27 Jun 2018 23:34:21 +0800 Subject: util.c: string builder and rename util.{c,h} to curl_util --- util.h | 45 ++++++++++++--------------------------------- 1 file changed, 12 insertions(+), 33 deletions(-) (limited to 'util.h') diff --git a/util.h b/util.h index 509bcb9..ab0b158 100644 --- a/util.h +++ b/util.h @@ -1,39 +1,18 @@ -#ifndef MATRIX_CURL_UTIL_H -#define MATRIX_CURL_UTIL_H +#ifndef LIBMC_UTIL_H +#define LIBMC_UTIL_H -#include -#include -#include +#ifdef __cplusplus +extern "C" { +#endif /* } */ -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); +/* build a new C string by concatenate strings in ss + * @ss: C strings, the last element is NULL + * @note callers should call free() to free the returned C string + */ +char * alloc_build_string(const char *ss[]); -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; +#ifdef __cplusplus } +#endif #endif -- cgit v1.2.3