1/*!
2 * @file File: bookmark.c
3 *
4 * vim: expandtab:ts=2:sts=2:sw=2
5 *
6 * @copyright
7 *
8 * Copyright (C) 2020 Anoxinon e.V.
9 *
10 * This file is part of xmppc.
11 *
12 * xmppc is free software: you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation, either version 3 of the License, or
15 * (at your option) any later version.
16 *
17 * xmppc is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
21 *
22 * You should have received a copy of the GNU General Public License
23 * along with Foobar. If not, see <http://www.gnu.org/licenses/>.
24 *
25 * German
26 *
27 * Diese Datei ist Teil von xmppc.
28 *
29 * xmppc ist Freie Software: Sie können es unter den Bedingungen
30 * der GNU General Public License, wie von der Free Software Foundation,
31 * Version 3 der Lizenz oder (nach Ihrer Wahl) jeder neueren
32 * veröffentlichten Version, weiter verteilen und/oder modifizieren.
33 *
34 * xmppc wird in der Hoffnung, dass es nützlich sein wird, aber
35 * OHNE JEDE GEWÄHRLEISTUNG, bereitgestellt; sogar ohne die implizite
36 * Gewährleistung der MARKTFÄHIGKEIT oder EIGNUNG FÜR EINEN BESTIMMTEN ZWECK.
37 * Siehe die GNU General Public License für weitere Details.
38 *
39 * Sie sollten eine Kopie der GNU General Public License zusammen mit diesem
40 * Programm erhalten haben. Wenn nicht, siehe <https://www.gnu.org/licenses/>.
41 */
42
43#include "bookmark.h"
44#include "stdio.h"
45#include "string.h"
46
47static void _bookmark_request(xmppc_t *xmppc);
48static int _bookmark_show(xmpp_conn_t *const conn, xmpp_stanza_t *const stanza, void *const userdata);
49
50void bookmark_execute_command (xmppc_t *xmppc, int argc, char *argv[]) {
51 if(argc == 1 && strcmp("list", argv[0]) == 0) {
52 _bookmark_request(xmppc);
53 } else {
54 printf("Command unbekannt!");
55 xmpp_disconnect(xmppc->conn);
56 }
57}
58
59static void _bookmark_request(xmppc_t *xmppc) {
60 char* id = xmpp_uuid_gen(xmppc->ctx);
61 xmpp_stanza_t *iq = xmpp_iq_new(xmppc->ctx, "get", id);
62 // pubsub
63 xmpp_stanza_t* pubsub = xmpp_stanza_new(xmppc->ctx);
64 xmpp_stanza_set_name(pubsub, "pubsub");
65 xmpp_stanza_set_ns(pubsub, "http://jabber.org/protocol/pubsub");
66 // items
67 xmpp_stanza_t* items = xmpp_stanza_new(xmppc->ctx);
68 xmpp_stanza_set_name(items, "items");
69 xmpp_stanza_set_attribute(items, "node", "storage:bookmarks");
70
71 xmpp_stanza_add_child(iq,pubsub);
72 xmpp_stanza_add_child(pubsub,items);
73 xmpp_id_handler_add(xmppc->conn, _bookmark_show, id, xmppc);
74 xmpp_send(xmppc->conn,iq);
75
76}
77
78int _bookmark_show(xmpp_conn_t *const conn, xmpp_stanza_t *const stanza, void *const userdata){
79 xmpp_stanza_t* pubsub = xmpp_stanza_get_child_by_name(stanza,"pubsub");
80 xmpp_stanza_t* items = xmpp_stanza_get_child_by_name(pubsub,"items");
81 xmpp_stanza_t* item = xmpp_stanza_get_child_by_name(items,"item");
82 xmpp_stanza_t* storage = xmpp_stanza_get_child_by_name(item,"storage");
83 if(storage != NULL) {
84 xmpp_stanza_t* c = xmpp_stanza_get_children(storage);
85 while (c) {
86 printf("%s%-50s - %-5s - %-40s\x1b[m\n", ANSI_COLOR_RED,
87 xmpp_stanza_get_attribute(c,"jid"),
88 xmpp_stanza_get_attribute(c,"autojoin"),
89 xmpp_stanza_get_attribute(c,"name")
90 );
91 c = xmpp_stanza_get_next(c);
92 }
93 }
94
95 xmpp_disconnect(conn);
96 return 1;
97}
98
99