diff options
author | Iru Cai <mytbk920423@gmail.com> | 2018-06-27 23:34:21 +0800 |
---|---|---|
committer | Iru Cai <mytbk920423@gmail.com> | 2018-06-28 00:16:51 +0800 |
commit | b0e376b6ba1891fcf749d22095c4f79a843a5d0f (patch) | |
tree | 5008f76cf09bbda7b979180997a8cb3e142f0899 /api.c | |
parent | e6d9edc048efb5b19d79bbe7871b2ff779d72311 (diff) | |
download | matrix-curl-b0e376b6ba1891fcf749d22095c4f79a843a5d0f.tar.xz |
util.c: string builder
and rename util.{c,h} to curl_util
Diffstat (limited to 'api.c')
-rw-r--r-- | api.c | 14 |
1 files changed, 10 insertions, 4 deletions
@@ -4,14 +4,20 @@ #include <curl/curl.h> #include <json-c/json.h> #include "session.h" +#include "curl_util.h" #include "util.h" /* logout: return 1 if success, 0 if failed */ int matrix_logout(matrix_session *sess) { - char requrl[1000]; /* FIXME */ - sprintf(requrl, "%s/_matrix/client/r0/logout?access_token=%s", sess->url, sess->token); + char * requrl = alloc_build_string((const char *[]){ + sess->url, + "/_matrix/client/r0/logout?access_token=", + sess->token, + NULL + }); CURLcode res = _curl_post(sess->curl, requrl, "", NULL); + free(requrl); if (res == CURLE_OK) return 1; else @@ -110,7 +116,7 @@ int main() if (roomid == NULL) puts("fail to resolv #hello:my.domain.name"); - free(roomid); + if (roomid) free(roomid); /* create a room */ roomid = matrix_create_room(sess); @@ -119,7 +125,7 @@ int main() else printf("create room %s\n", roomid); - free(roomid); + if (roomid) free(roomid); if (matrix_logout(sess)) puts("logout!"); |