main.c 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740
  1. /* snac - A simple, minimalistic ActivityPub instance */
  2. /* copyright (c) 2022 - 2025 grunfink et al. / MIT license */
  3. #include "xs.h"
  4. #include "xs_io.h"
  5. #include "xs_json.h"
  6. #include "xs_time.h"
  7. #include "xs_openssl.h"
  8. #include "xs_match.h"
  9. #include "snac.h"
  10. #include <sys/stat.h>
  11. #include <sys/wait.h>
  12. int usage(void)
  13. {
  14. printf("snac " VERSION " - A simple, minimalistic ActivityPub instance\n");
  15. printf("Copyright (c) 2022 - 2025 grunfink et al. / MIT license\n");
  16. printf("\n");
  17. printf("Commands:\n");
  18. printf("\n");
  19. printf("init [{basedir}] Initializes the data storage\n");
  20. printf("upgrade {basedir} Upgrade to a new version\n");
  21. printf("adduser {basedir} [{uid}] Adds a new user\n");
  22. printf("deluser {basedir} {uid} Deletes a user\n");
  23. printf("httpd {basedir} Starts the HTTPD daemon\n");
  24. printf("purge {basedir} Purges old data\n");
  25. printf("state {basedir} Prints server state\n");
  26. printf("webfinger {basedir} {account} Queries about an account (@user@host or actor url)\n");
  27. printf("queue {basedir} {uid} Processes a user queue\n");
  28. printf("follow {basedir} {uid} {actor} Follows an actor\n");
  29. printf("unfollow {basedir} {uid} {actor} Unfollows an actor\n");
  30. printf("request {basedir} {uid} {url} Requests an object\n");
  31. printf("insert {basedir} {uid} {url} Requests an object and inserts it into the timeline\n");
  32. printf("actor {basedir} [{uid}] {url} Requests an actor\n");
  33. printf("note {basedir} {uid} {text} [files...] Sends a note with optional attachments\n");
  34. printf("note_unlisted {basedir} {uid} {text} [files...] Sends an unlisted note with optional attachments\n");
  35. printf("note_mention {basedir} {uid} {text} [files...] Sends a note only to mentioned accounts\n");
  36. printf("boost|announce {basedir} {uid} {url} Boosts (announces) a post\n");
  37. printf("unboost {basedir} {uid} {url} Unboosts a post\n");
  38. printf("resetpwd {basedir} {uid} Resets the password of a user\n");
  39. printf("ping {basedir} {uid} {actor} Pings an actor\n");
  40. printf("webfinger_s {basedir} {uid} {account} Queries about an account (@user@host or actor url)\n");
  41. printf("pin {basedir} {uid} {msg_url} Pins a message\n");
  42. printf("unpin {basedir} {uid} {msg_url} Unpins a message\n");
  43. printf("bookmark {basedir} {uid} {msg_url} Bookmarks a message\n");
  44. printf("unbookmark {basedir} {uid} {msg_url} Unbookmarks a message\n");
  45. printf("block {basedir} {instance_url} Blocks a full instance\n");
  46. printf("unblock {basedir} {instance_url} Unblocks a full instance\n");
  47. printf("limit {basedir} {uid} {actor} Limits an actor (drops their announces)\n");
  48. printf("unlimit {basedir} {uid} {actor} Unlimits an actor\n");
  49. printf("unmute {basedir} {uid} {actor} Unmutes a previously muted actor\n");
  50. printf("verify_links {basedir} {uid} Verifies a user's links (in the metadata)\n");
  51. printf("search {basedir} {uid} {regex} Searches posts by content\n");
  52. printf("export_csv {basedir} {uid} Exports data as CSV files\n");
  53. printf("alias {basedir} {uid} {account} Sets account (@user@host or actor url) as an alias\n");
  54. printf("migrate {basedir} {uid} Migrates to the account defined as the alias\n");
  55. printf("import_csv {basedir} {uid} Imports data from CSV files\n");
  56. printf("import_list {basedir} {uid} {file} Imports a Mastodon CSV list file\n");
  57. printf("import_block_list {basedir} {uid} {file} Imports a Mastodon CSV block list file\n");
  58. return 1;
  59. }
  60. char *get_argv(int *argi, int argc, char *argv[])
  61. {
  62. if (*argi < argc)
  63. return argv[(*argi)++];
  64. else
  65. return NULL;
  66. }
  67. #define GET_ARGV() get_argv(&argi, argc, argv)
  68. int main(int argc, char *argv[])
  69. {
  70. char *cmd;
  71. char *basedir;
  72. char *user;
  73. char *url;
  74. int argi = 1;
  75. snac snac;
  76. /* ensure group has write access */
  77. umask(0007);
  78. if ((cmd = GET_ARGV()) == NULL)
  79. return usage();
  80. if (strcmp(cmd, "init") == 0) { /** **/
  81. /* initialize the data storage */
  82. /* ... */
  83. basedir = GET_ARGV();
  84. return snac_init(basedir);
  85. }
  86. if (strcmp(cmd, "markdown") == 0) { /** **/
  87. /* undocumented, for testing only */
  88. xs *c = xs_readall(stdin);
  89. xs *fc = not_really_markdown(c, NULL, NULL);
  90. printf("<html>\n%s\n</html>\n", fc);
  91. return 0;
  92. }
  93. if ((basedir = getenv("SNAC_BASEDIR")) == NULL) {
  94. if ((basedir = GET_ARGV()) == NULL)
  95. return usage();
  96. }
  97. if (strcmp(cmd, "upgrade") == 0) { /** **/
  98. int ret;
  99. /* upgrade */
  100. if ((ret = srv_open(basedir, 1)) == 1)
  101. srv_log(xs_dup("OK"));
  102. return ret;
  103. }
  104. if (!srv_open(basedir, 0)) {
  105. srv_log(xs_fmt("error opening data storage at %s", basedir));
  106. return 1;
  107. }
  108. if (strcmp(cmd, "adduser") == 0) { /** **/
  109. user = GET_ARGV();
  110. return adduser(user);
  111. return 0;
  112. }
  113. if (strcmp(cmd, "httpd") == 0) { /** **/
  114. httpd();
  115. srv_free();
  116. return 0;
  117. }
  118. if (strcmp(cmd, "purge") == 0) { /** **/
  119. purge_all();
  120. return 0;
  121. }
  122. if (strcmp(cmd, "state") == 0) { /** **/
  123. xs *shm_name = NULL;
  124. srv_state *p_state = srv_state_op(&shm_name, 1);
  125. if (p_state == NULL)
  126. return 1;
  127. srv_state ss = *p_state;
  128. int n;
  129. printf("server: %s (%s)\n", xs_dict_get(srv_config, "host"), USER_AGENT);
  130. xs *uptime = xs_str_time_diff(time(NULL) - ss.srv_start_time);
  131. printf("uptime: %s\n", uptime);
  132. printf("job fifo size (cur): %d\n", ss.job_fifo_size);
  133. printf("job fifo size (peak): %d\n", ss.peak_job_fifo_size);
  134. char *th_states[] = { "stopped", "waiting", "input", "output" };
  135. for (n = 0; n < ss.n_threads; n++)
  136. printf("thread #%d state: %s\n", n, th_states[ss.th_state[n]]);
  137. return 0;
  138. }
  139. if ((user = GET_ARGV()) == NULL)
  140. return usage();
  141. if (strcmp(cmd, "block") == 0) { /** **/
  142. int ret = instance_block(user);
  143. if (ret < 0) {
  144. fprintf(stderr, "Error blocking instance %s: %d\n", user, ret);
  145. return 1;
  146. }
  147. return 0;
  148. }
  149. if (strcmp(cmd, "unblock") == 0) { /** **/
  150. int ret = instance_unblock(user);
  151. if (ret < 0) {
  152. fprintf(stderr, "Error unblocking instance %s: %d\n", user, ret);
  153. return 1;
  154. }
  155. return 0;
  156. }
  157. if (strcmp(cmd, "webfinger") == 0) { /** **/
  158. xs *actor = NULL;
  159. xs *uid = NULL;
  160. int status;
  161. status = webfinger_request(user, &actor, &uid);
  162. printf("status: %d\n", status);
  163. if (actor != NULL)
  164. printf("actor: %s\n", actor);
  165. if (uid != NULL)
  166. printf("uid: %s\n", uid);
  167. return 0;
  168. }
  169. if (argi == argc && strcmp(cmd, "actor") == 0) { /** **/
  170. /* query an actor without user (non-signed) */
  171. xs *actor = NULL;
  172. int status;
  173. status = actor_request(NULL, user, &actor);
  174. printf("status: %d\n", status);
  175. if (valid_status(status)) {
  176. xs_json_dump(actor, 4, stdout);
  177. printf("\n");
  178. }
  179. return 0;
  180. }
  181. if (!user_open(&snac, user)) {
  182. printf("invalid user '%s'\n", user);
  183. return 1;
  184. }
  185. lastlog_write(&snac, "cmdline");
  186. if (strcmp(cmd, "resetpwd") == 0) { /** **/
  187. return resetpwd(&snac);
  188. }
  189. if (strcmp(cmd, "deluser") == 0) { /** **/
  190. return deluser(&snac);
  191. }
  192. if (strcmp(cmd, "update") == 0) { /** **/
  193. xs *a_msg = msg_actor(&snac);
  194. xs *u_msg = msg_update(&snac, a_msg);
  195. enqueue_message(&snac, u_msg);
  196. return 0;
  197. }
  198. if (strcmp(cmd, "queue") == 0) { /** **/
  199. process_user_queue(&snac);
  200. return 0;
  201. }
  202. if (strcmp(cmd, "verify_links") == 0) { /** **/
  203. verify_links(&snac);
  204. return 0;
  205. }
  206. if (strcmp(cmd, "timeline") == 0) { /** **/
  207. #if 0
  208. xs *list = local_list(&snac, XS_ALL);
  209. xs *body = html_timeline(&snac, list, 1);
  210. printf("%s\n", body);
  211. user_free(&snac);
  212. srv_free();
  213. #endif
  214. xs *idx = xs_fmt("%s/private.idx", snac.basedir);
  215. xs *list = index_list_desc(idx, 0, 256);
  216. xs *tl = timeline_top_level(&snac, list);
  217. xs_json_dump(tl, 4, stdout);
  218. return 0;
  219. }
  220. if (strcmp(cmd, "export_csv") == 0) { /** **/
  221. export_csv(&snac);
  222. return 0;
  223. }
  224. if (strcmp(cmd, "import_csv") == 0) { /** **/
  225. import_csv(&snac);
  226. return 0;
  227. }
  228. if (strcmp(cmd, "migrate") == 0) { /** **/
  229. return migrate_account(&snac);
  230. }
  231. if ((url = GET_ARGV()) == NULL)
  232. return usage();
  233. if (strcmp(cmd, "alias") == 0) { /** **/
  234. xs *actor = NULL;
  235. xs *uid = NULL;
  236. int status = HTTP_STATUS_OK;
  237. if (*url == '\0')
  238. actor = xs_dup("");
  239. else
  240. status = webfinger_request(url, &actor, &uid);
  241. if (valid_status(status)) {
  242. if (strcmp(actor, snac.actor) == 0) {
  243. snac_log(&snac, xs_fmt("You can't be your own alias"));
  244. return 1;
  245. }
  246. else {
  247. snac.config = xs_dict_set(snac.config, "alias", actor);
  248. snac.config = xs_dict_set(snac.config, "alias_raw", url);
  249. user_persist(&snac, 1);
  250. }
  251. }
  252. else {
  253. snac_log(&snac, xs_fmt("Webfinger error for %s %d", url, status));
  254. return 1;
  255. }
  256. return 0;
  257. }
  258. if (strcmp(cmd, "webfinger_s") == 0) { /** **/
  259. xs *actor = NULL;
  260. xs *uid = NULL;
  261. int status;
  262. status = webfinger_request_signed(&snac, url, &actor, &uid);
  263. printf("status: %d\n", status);
  264. if (actor != NULL)
  265. printf("actor: %s\n", actor);
  266. if (uid != NULL)
  267. printf("uid: %s\n", uid);
  268. return 0;
  269. }
  270. if (strcmp(cmd, "boost") == 0 || strcmp(cmd, "announce") == 0) { /** **/
  271. xs *msg = msg_admiration(&snac, url, "Announce");
  272. if (msg != NULL) {
  273. enqueue_message(&snac, msg);
  274. if (dbglevel) {
  275. xs_json_dump(msg, 4, stdout);
  276. }
  277. }
  278. return 0;
  279. }
  280. if (strcmp(cmd, "assist") == 0) { /** **/
  281. /* undocumented: experimental (do not use) */
  282. xs *msg = msg_admiration(&snac, url, "Accept");
  283. if (msg != NULL) {
  284. enqueue_message(&snac, msg);
  285. if (dbglevel) {
  286. xs_json_dump(msg, 4, stdout);
  287. }
  288. }
  289. return 0;
  290. }
  291. if (strcmp(cmd, "unboost") == 0) { /** **/
  292. xs *msg = msg_repulsion(&snac, url, "Announce");
  293. if (msg != NULL) {
  294. enqueue_message(&snac, msg);
  295. if (dbglevel) {
  296. xs_json_dump(msg, 4, stdout);
  297. }
  298. }
  299. return 0;
  300. }
  301. if (strcmp(cmd, "follow") == 0) { /** **/
  302. xs *msg = msg_follow(&snac, url);
  303. if (msg != NULL) {
  304. const char *actor = xs_dict_get(msg, "object");
  305. following_add(&snac, actor, msg);
  306. enqueue_output_by_actor(&snac, msg, actor, 0);
  307. if (dbglevel) {
  308. xs_json_dump(msg, 4, stdout);
  309. }
  310. }
  311. return 0;
  312. }
  313. if (strcmp(cmd, "unfollow") == 0) { /** **/
  314. xs *object = NULL;
  315. if (valid_status(following_get(&snac, url, &object))) {
  316. xs *msg = msg_undo(&snac, xs_dict_get(object, "object"));
  317. following_del(&snac, url);
  318. enqueue_output_by_actor(&snac, msg, url, 0);
  319. snac_log(&snac, xs_fmt("unfollowed actor %s", url));
  320. }
  321. else
  322. snac_log(&snac, xs_fmt("actor is not being followed %s", url));
  323. return 0;
  324. }
  325. if (strcmp(cmd, "limit") == 0) { /** **/
  326. int ret;
  327. if (!following_check(&snac, url))
  328. snac_log(&snac, xs_fmt("actor %s is not being followed", url));
  329. else
  330. if ((ret = limit(&snac, url)) == 0)
  331. snac_log(&snac, xs_fmt("actor %s is now limited", url));
  332. else
  333. snac_log(&snac, xs_fmt("error limiting actor %s (%d)", url, ret));
  334. return 0;
  335. }
  336. if (strcmp(cmd, "unlimit") == 0) { /** **/
  337. int ret;
  338. if (!following_check(&snac, url))
  339. snac_log(&snac, xs_fmt("actor %s is not being followed", url));
  340. else
  341. if ((ret = unlimit(&snac, url)) == 0)
  342. snac_log(&snac, xs_fmt("actor %s is no longer limited", url));
  343. else
  344. snac_log(&snac, xs_fmt("error unlimiting actor %s (%d)", url, ret));
  345. return 0;
  346. }
  347. if (strcmp(cmd, "unmute") == 0) { /** **/
  348. if (is_muted(&snac, url)) {
  349. unmute(&snac, url);
  350. printf("%s unmuted\n", url);
  351. }
  352. else
  353. printf("%s actor is not muted\n", url);
  354. return 0;
  355. }
  356. if (strcmp(cmd, "search") == 0) { /** **/
  357. int to;
  358. /* 'url' contains the regex */
  359. xs *r = content_search(&snac, url, 1, 0, XS_ALL, 10, &to);
  360. int c = 0;
  361. const char *v;
  362. /* print results as standalone links */
  363. while (xs_list_next(r, &v, &c)) {
  364. printf("%s/admin/p/%s\n", snac.actor, v);
  365. }
  366. return 0;
  367. }
  368. if (strcmp(cmd, "ping") == 0) { /** **/
  369. xs *actor_o = NULL;
  370. if (!xs_startswith(url, "https:/")) {
  371. /* try to resolve via webfinger */
  372. if (!valid_status(webfinger_request(url, &url, NULL))) {
  373. srv_log(xs_fmt("cannot resolve %s via webfinger", url));
  374. return 1;
  375. }
  376. }
  377. if (valid_status(actor_request(&snac, url, &actor_o))) {
  378. xs *msg = msg_ping(&snac, url);
  379. enqueue_output_by_actor(&snac, msg, url, 0);
  380. if (dbglevel) {
  381. xs_json_dump(msg, 4, stdout);
  382. }
  383. srv_log(xs_fmt("Ping sent to %s -- see log for Pong reply", url));
  384. }
  385. else {
  386. srv_log(xs_fmt("Error getting actor %s", url));
  387. return 1;
  388. }
  389. return 0;
  390. }
  391. if (strcmp(cmd, "pin") == 0) { /** **/
  392. int ret = pin(&snac, url);
  393. if (ret < 0) {
  394. fprintf(stderr, "error pinning %s %d\n", url, ret);
  395. return 1;
  396. }
  397. return 0;
  398. }
  399. if (strcmp(cmd, "unpin") == 0) { /** **/
  400. int ret = unpin(&snac, url);
  401. if (ret < 0) {
  402. fprintf(stderr, "error unpinning %s %d\n", url, ret);
  403. return 1;
  404. }
  405. return 0;
  406. }
  407. if (strcmp(cmd, "bookmark") == 0) { /** **/
  408. int ret = bookmark(&snac, url);
  409. if (ret < 0) {
  410. fprintf(stderr, "error bookmarking %s %d\n", url, ret);
  411. return 1;
  412. }
  413. return 0;
  414. }
  415. if (strcmp(cmd, "unbookmark") == 0) { /** **/
  416. int ret = unbookmark(&snac, url);
  417. if (ret < 0) {
  418. fprintf(stderr, "error unbookmarking %s %d\n", url, ret);
  419. return 1;
  420. }
  421. return 0;
  422. }
  423. if (strcmp(cmd, "question") == 0) { /** **/
  424. int end_secs = 5 * 60;
  425. xs *opts = xs_split(url, ";");
  426. xs *msg = msg_question(&snac, "Poll", NULL, opts, 0, end_secs);
  427. xs *c_msg = msg_create(&snac, msg);
  428. if (dbglevel) {
  429. xs_json_dump(c_msg, 4, stdout);
  430. }
  431. enqueue_message(&snac, c_msg);
  432. enqueue_close_question(&snac, xs_dict_get(msg, "id"), end_secs);
  433. timeline_add(&snac, xs_dict_get(msg, "id"), msg);
  434. return 0;
  435. }
  436. if (strcmp(cmd, "request") == 0) { /** **/
  437. int status;
  438. xs *data = NULL;
  439. status = activitypub_request(&snac, url, &data);
  440. printf("status: %d\n", status);
  441. if (data != NULL) {
  442. xs_json_dump(data, 4, stdout);
  443. }
  444. return 0;
  445. }
  446. if (strcmp(cmd, "insert") == 0) { /** **/
  447. int status;
  448. xs *data = NULL;
  449. status = activitypub_request(&snac, url, &data);
  450. printf("status: %d\n", status);
  451. if (data != NULL) {
  452. xs_json_dump(data, 4, stdout);
  453. enqueue_actor_refresh(&snac, xs_dict_get(data, "attributedTo"), 0);
  454. if (!timeline_here(&snac, url))
  455. timeline_add(&snac, url, data);
  456. else
  457. printf("Post %s already here\n", url);
  458. }
  459. return 0;
  460. }
  461. if (strcmp(cmd, "request2") == 0) { /** **/
  462. enqueue_object_request(&snac, url, 2);
  463. return 0;
  464. }
  465. if (strcmp(cmd, "actor") == 0) { /** **/
  466. int status;
  467. xs *data = NULL;
  468. status = actor_request(&snac, url, &data);
  469. printf("status: %d\n", status);
  470. if (valid_status(status)) {
  471. xs_json_dump(data, 4, stdout);
  472. }
  473. return 0;
  474. }
  475. if (strcmp(cmd, "import_list") == 0) { /** **/
  476. import_list_csv(&snac, url);
  477. return 0;
  478. }
  479. if (strcmp(cmd, "import_block_list") == 0) { /** **/
  480. import_blocked_accounts_csv(&snac, url);
  481. return 0;
  482. }
  483. if (strcmp(cmd, "note") == 0 || /** **/
  484. strcmp(cmd, "note_unlisted") == 0 || /** **/
  485. strcmp(cmd, "note_mention") == 0) { /** **/
  486. xs *content = NULL;
  487. xs *msg = NULL;
  488. xs *c_msg = NULL;
  489. xs *attl = xs_list_new();
  490. char *fn = NULL;
  491. /* iterate possible attachments */
  492. while ((fn = GET_ARGV())) {
  493. FILE *f;
  494. if ((f = fopen(fn, "rb")) != NULL) {
  495. /* get the file size and content */
  496. fseek(f, 0, SEEK_END);
  497. int sz = ftell(f);
  498. fseek(f, 0, SEEK_SET);
  499. xs *atc = xs_readall(f);
  500. fclose(f);
  501. char *ext = strrchr(fn, '.');
  502. xs *hash = xs_md5_hex(fn, strlen(fn));
  503. xs *id = xs_fmt("%s%s", hash, ext);
  504. xs *url = xs_fmt("%s/s/%s", snac.actor, id);
  505. /* store */
  506. static_put(&snac, id, atc, sz);
  507. xs *l = xs_list_new();
  508. l = xs_list_append(l, url);
  509. l = xs_list_append(l, ""); /* alt text */
  510. attl = xs_list_append(attl, l);
  511. }
  512. else
  513. fprintf(stderr, "Error opening '%s' as attachment\n", fn);
  514. }
  515. if (strcmp(url, "-e") == 0) {
  516. /* get the content from an editor */
  517. #define EDITOR "$EDITOR "
  518. char cmd[] = EDITOR "/tmp/snac-XXXXXX";
  519. FILE *f;
  520. int fd = mkstemp(cmd + strlen(EDITOR));
  521. if (fd >= 0) {
  522. int status = system(cmd);
  523. if (WIFEXITED(status) && WEXITSTATUS(status) == 0 && (f = fdopen(fd, "r")) != NULL) {
  524. content = xs_readall(f);
  525. fclose(f);
  526. unlink(cmd + strlen(EDITOR));
  527. } else {
  528. printf("Nothing to send\n");
  529. close(fd);
  530. return 1;
  531. }
  532. } else {
  533. fprintf(stderr, "Temp file creation failed\n");
  534. return 1;
  535. }
  536. }
  537. else
  538. if (strcmp(url, "-") == 0) {
  539. /* get the content from stdin */
  540. content = xs_readall(stdin);
  541. }
  542. else
  543. content = xs_dup(url);
  544. if (!content || !*content) {
  545. printf("Nothing to send\n");
  546. return 1;
  547. }
  548. int scope = 0;
  549. if (strcmp(cmd, "note_mention") == 0)
  550. scope = 1;
  551. else
  552. if (strcmp(cmd, "note_unlisted") == 0)
  553. scope = 2;
  554. msg = msg_note(&snac, content, NULL, NULL, attl, scope, getenv("LANG"));
  555. c_msg = msg_create(&snac, msg);
  556. if (dbglevel) {
  557. xs_json_dump(c_msg, 4, stdout);
  558. }
  559. enqueue_message(&snac, c_msg);
  560. timeline_add(&snac, xs_dict_get(msg, "id"), msg);
  561. return 0;
  562. }
  563. fprintf(stderr, "ERROR: bad command '%s'\n", cmd);
  564. return 1;
  565. }