ref: 454fd94f7db58e8bef6fb5123a9ed260271d3c06
parent: 6c7016b5b7119d833af543fe5ad707b1b0db5c7e
author: Julien Blanchard <[email protected]>
date: Fri Mar 31 14:36:16 EDT 2023
strdup -> estrdup
--- a/masto9.c
+++ b/masto9.c
@@ -49,25 +49,25 @@
media_attachments = getjsonkey(toot_json, "media_attachments");
Toot toot = emalloc(sizeof(Toot));
- toot.id = strdup((char *)id->s);
+ toot.id = estrdup((char *)id->s);
if(reblog->s == nil) {
toot.reblogged = 0;
- toot.content = strdup((char *)content->s);
+ toot.content = estrdup((char *)content->s);
} else {
reblog_content = getjsonkey(reblog, "content");
reblog_account = getjsonkey(reblog, "account");
reblog_handle = getjsonkey(reblog_account, "acct");
- toot.content = strdup((char *)reblog_content->s);
- toot.reblogged_handle = strdup((char *)reblog_handle->s);
+ toot.content = estrdup((char *)reblog_content->s);
+ toot.reblogged_handle = estrdup((char *)reblog_handle->s);
toot.reblogged = 1;
media_attachments = getjsonkey(reblog, "media_attachments");
};
- toot.handle = strdup((char *)handle->s);
- toot.display_name = strdup((char *)display_name->s);
- toot.avatar_url = strdup((char *)avatar->s);
+ toot.handle = estrdup((char *)handle->s);
+ toot.display_name = estrdup((char *)display_name->s);
+ toot.avatar_url = estrdup((char *)avatar->s);
toot.attachments_count = 0;
if(media_attachments->s != nil) {
@@ -78,12 +78,12 @@
type = getjsonkey(attachment_json, "type");
preview_url = getjsonkey(attachment_json, "preview_url");
remote_url = getjsonkey(attachment_json, "remote_url");
- attachment.type = strdup((char *)type->s);
+ attachment.type = estrdup((char *)type->s);
if(strcmp(type->s, "image") == 0){
- attachment.url = strdup((char *)preview_url->s);
+ attachment.url = estrdup((char *)preview_url->s);
} else {
- attachment.url = strdup((char *)remote_url->s);
+ attachment.url = estrdup((char *)remote_url->s);
}
toot.media_attachments[j] = attachment;
@@ -124,14 +124,14 @@
handle = getjsonkey(account, "acct");
Notification notif = emalloc(sizeof(Notification));
- notif.id = strdup((char *)id->s);
+ notif.id = estrdup((char *)id->s);
- notif.type = strdup((char *)type->s);
+ notif.type = estrdup((char *)type->s);
if(strcmp(type->s, "follow") != 0) {
- notif.content = strdup((char *)content->s);
+ notif.content = estrdup((char *)content->s);
}
- notif.display_name = strdup((char *)display_name->s);
- notif.handle = strdup((char *)handle->s);
+ notif.display_name = estrdup((char *)display_name->s);
+ notif.handle = estrdup((char *)handle->s);
notifs[i] = notif;
i++;
@@ -153,19 +153,25 @@
tootauthor(char *token, char *host, char *id)
{
JSON *obj, *account, *reblog;
- char *endpoint;
+ char *endpoint, *response;
endpoint = concat("statuses/", id);
obj = mastodonget(token, host, endpoint);
reblog = getjsonkey(obj, "reblog");
- if(reblog != nil) {
+ if(reblog->s != nil) {
account = getjsonkey(reblog, "account");
} else {
account = getjsonkey(obj, "account");
}
- return getjsonkey(account, "acct")->s;
+ response = estrdup((char *)getjsonkey(account, "acct")->s);
+
+ free(account);
+ free(reblog);
+ free(obj);
+
+ return response;
}
void
@@ -368,6 +374,19 @@
Bflush(&out);
}
+void
+debug(char *token, char *host, char *id)
+{
+ JSON *obj;
+ char *endpoint;
+
+ endpoint = esmprint("statuses/%s", id);
+ obj = mastodonget(token, host, endpoint);
+ print("%J\n", obj);
+ jsonfree(obj);
+}
+
+
//echo 'proto=pass service=mastodon server=instanceHostName pass=yourToken user=yourUsername' > /mnt/factotum/ctl
void
main(int argc, char**argv)
@@ -408,6 +427,9 @@
} else if(strcmp(command, "reply") == 0) {
id = argv[3];
reply(token, host, id);
+ } else if(strcmp(command, "debug") == 0) {
+ id = argv[3];
+ debug(token, host, id);
} else if(strcmp(command, "more") == 0) {
id = argv[3];
Toot toots[TOOTSCOUNT];
--- a/util.c
+++ b/util.c
@@ -97,17 +97,6 @@
return nil;
}
-u32int
-strhash(char *s)
-{
- u32int h, c;
-
- h = 5381;
- while(c = *s++ & 0xff)
- h = ((h << 5) + h) + c;
- return h;
-}
-
void
removesubstring(char *str, char *sub)
{