aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorqorg11 <qorg@vxempire.xyz>2021-06-17 00:23:28 +0200
committerqorg11 <qorg@vxempire.xyz>2021-06-17 00:23:28 +0200
commit47495d0f7be8a4b3b4e5f7a98a4d75f5c8b05804 (patch)
tree5ce4c87bbd7288f079f99ddb73046056c546b00b
parentf041fa67d007190cab6876ba1b391f388fb6ed2b (diff)
downloaddemiurge-47495d0f7be8a4b3b4e5f7a98a4d75f5c8b05804.tar.gz
demiurge-47495d0f7be8a4b3b4e5f7a98a4d75f5c8b05804.zip
Print status url instead of JSON output
-rw-r--r--src/post.c21
-rw-r--r--src/util.c25
-rw-r--r--src/util.h7
3 files changed, 51 insertions, 2 deletions
diff --git a/src/post.c b/src/post.c
index 60a7f49..e70578e 100644
--- a/src/post.c
+++ b/src/post.c
@@ -2,6 +2,7 @@
#include <curl/curl.h>
#include <string.h>
#include <stdlib.h>
+#include <json-c/json.h>
#include "util.h"
#include "asprintf.h"
@@ -37,6 +38,13 @@ post_status(const char *status, const char *scope, const char *media_id)
curl_easy_setopt(curl, CURLOPT_HTTPHEADER, header_list);
+ /* Write the thing */
+
+ struct memory chunk = {0};
+
+ curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, cb);
+ curl_easy_setopt(curl, CURLOPT_WRITEDATA, (void *)&chunk);
+
curl_mime *mime;
mime = curl_mime_init(curl);
curl_mimepart *status_part, *scope_part, *media_part;
@@ -64,14 +72,23 @@ post_status(const char *status, const char *scope, const char *media_id)
}
/* post */
- puts(url);
+
curl_easy_setopt(curl,CURLOPT_URL,url);
curl_easy_setopt(curl,CURLOPT_MIMEPOST,mime);
curl_easy_perform(curl);
+ /* The the url */
+
+ struct json_object *parsed_json;
+ struct json_object *json_url;
+
+ parsed_json = json_tokener_parse(chunk.response);
+ json_object_object_get_ex(parsed_json, "url", &json_url);
+ puts(json_object_get_string(json_url));
+
free(url);
free(authorization_header);
-
+ free(chunk.response);
return 0;
}
diff --git a/src/util.c b/src/util.c
index abce04a..a791688 100644
--- a/src/util.c
+++ b/src/util.c
@@ -1,5 +1,12 @@
#include <stdio.h>
#include <string.h>
+#include <stdlib.h>
+
+struct memory {
+ char *response;
+ size_t size;
+};
+
/* This function fucking sucks and should use something else. I'll
* have to rewrite this shit function some day. But for now, it will
@@ -24,6 +31,24 @@ get_tokens_from_file(char *filename, char *instance, char *client_id,
return 0;
}
+
+size_t cb(void *data, size_t size, size_t nmemb, void *userp)
+{
+ size_t realsize = size * nmemb;
+ struct memory *mem = (struct memory *)userp;
+
+ char *ptr = realloc(mem->response, mem->size + realsize + 1);
+ if(ptr == NULL)
+ return 0; /* out of memory! */
+
+ mem->response = ptr;
+ memcpy(&(mem->response[mem->size]), data, realsize);
+ mem->size += realsize;
+ mem->response[mem->size] = 0;
+
+ return realsize;
+}
+
size_t
write_data(void *buffer, size_t size, size_t nmemb, void *userp)
diff --git a/src/util.h b/src/util.h
index e952043..6d0dc7f 100644
--- a/src/util.h
+++ b/src/util.h
@@ -8,3 +8,10 @@ write_data(void *buffer, size_t size, size_t nmemb, void *userp);
void
eputs(const char *s);
+
+struct memory {
+ char *response;
+ size_t size;
+};
+
+static size_t cb(void *data, size_t size, size_t nmemb, void *userp);