Detailed changes
@@ -9,6 +9,9 @@ core_sources = \
src/mode/pgp.h src/mode/pgp.c \
src/mode/account.h src/mode/account.c \
src/mode/monitor.h src/mode/monitor.c \
+ src/mode/discovery.h src/mode/discovery.c \
+ src/mode/bookmark.h src/mode/bookmark.c \
+ src/mode/mam.h src/mode/mam.c \
src/mode/openpgp.h src/mode/openpgp.c
AM_CFLAGS = @AM_CFLAGS@ -I$(srcdir)/src
@@ -1,4 +1,4 @@
-AC_INIT([xmppc], [0.0.4], [stefan@debxwoody.de])
+AC_INIT([xmppc], [0.0.5], [stefan@debxwoody.de])
AC_CONFIG_AUX_DIR([build-aux])
AC_CONFIG_MACRO_DIR([m4])
AC_CONFIG_SRCDIR([src/main.c])
@@ -24,7 +24,7 @@ PACKAGE_STATUS="release"
AM_CFLAGS="-Wall -Wno-deprecated-declarations -pedantic -std=c11"
AS_IF([test "x$PACKAGE_STATUS" = xdevelopment],
- [AM_CFLAGS="$AM_CFLAGS -Wunused -Werror -g"])
+ [AM_CFLAGS="$AM_CFLAGS -Wunused -Werror -g -O0"])
AS_IF([test "x$PACKAGE_STATUS" = xdevelopment],
[AC_DEFINE([XMPPC_DEVELOPMENT], [1], [XMPPC Development])])
@@ -135,6 +135,7 @@
#include <string.h>
#include <glib.h>
#include <strophe.h>
+#include <errno.h>
#include "xmppc.h"
#include "mode/account.h"
@@ -145,6 +146,9 @@
#include "mode/pgp.h"
#include "mode/openpgp.h"
#include "mode/monitor.h"
+#include "mode/mam.h"
+#include "mode/discovery.h"
+#include "mode/bookmark.h"
/*!
* @brief The callback structure.
@@ -244,6 +248,12 @@ static struct mode_mapping map[] = {
* Monitor
*/
{"monitor", MONITOR, monitor_execute_command},
+ //
+ {"discovery", DISCOVERY, discovery_execute_command},
+ //
+ {"bookmark", BOOKMARK, bookmark_execute_command},
+ //
+ {"mam", MAM, mam_execute_command},
// End of Map
{NULL, 0}
};
@@ -271,11 +281,34 @@ void conn_handler(xmpp_conn_t *const conn, const xmpp_conn_event_t status,
void *const userdata) {
callback_t *callback = (callback_t *)userdata;
- if (status == XMPP_CONN_CONNECT) {
- logInfo(callback->xmppc, "Connected\n");
- callback->callback(callback->xmppc, callback->argc, callback->argv);
- } else {
+ if( error != 0 ) {
+ logError(callback->xmppc,"Connection failed. %s\n", strerror(error));
+ xmpp_stop(xmpp_conn_get_context(conn));
+ return;
+ }
+
+ if( stream_error != NULL ) {
+ logError(callback->xmppc,"Connection failed. %s\n", stream_error->text);
xmpp_stop(xmpp_conn_get_context(conn));
+ return;
+ }
+
+ if( xmpp_conn_is_secured(conn) ) {
+ logInfo(callback->xmppc, "Secure connection!\n");
+ } else {
+ logWarn(callback->xmppc, "Connection not secure!\n");
+ }
+
+ switch (status) {
+ case XMPP_CONN_CONNECT:
+ logInfo(callback->xmppc, "Connected\n");
+ callback->callback(callback->xmppc, callback->argc, callback->argv);
+ break;
+ case XMPP_CONN_RAW_CONNECT:
+ case XMPP_CONN_DISCONNECT:
+ case XMPP_CONN_FAIL:
+ logInfo(callback->xmppc, "Stopping XMPP!\n");
+ xmpp_stop(xmpp_conn_get_context(conn));
}
}
@@ -415,7 +448,7 @@ int main(int argc, char *argv[]) {
}
xmppc_context(&xmppc, verbose_flag);
- logInfo(&xmppc, "Connecting... \n");
+ logInfo(&xmppc, "Connecting %s ... ", jid);
xmppc_connect(&xmppc, jid, pwd);
ExecuteHandler handler = NULL;
@@ -426,9 +459,19 @@ int main(int argc, char *argv[]) {
}
}
+ if( handler == NULL ) {
+ logError(&xmppc, "Unbekannter mode\n");
+ return -1;
+ }
+
callback_t callback = {paramc, paramv, handler, &xmppc};
- xmpp_connect_client(xmppc.conn, NULL, 0, conn_handler, &callback);
+ xmpp_conn_set_flags(xmppc.conn, XMPP_CONN_FLAG_MANDATORY_TLS);
+
+ int e = xmpp_connect_client(xmppc.conn, NULL, 0, conn_handler, &callback);
+ if(XMPP_EOK != e ) {
+ printf("xmpp_connect_client failed");
+ }
xmpp_run(xmppc.ctx);
xmpp_conn_release(xmppc.conn);
@@ -0,0 +1,99 @@
+/*!
+ * @file File: bookmark.c
+ *
+ * vim: expandtab:ts=2:sts=2:sw=2
+ *
+ * @copyright
+ *
+ * Copyright (C) 2020 Anoxinon e.V.
+ *
+ * This file is part of xmppc.
+ *
+ * xmppc is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * xmppc is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Foobar. If not, see <http://www.gnu.org/licenses/>.
+ *
+ * German
+ *
+ * Diese Datei ist Teil von xmppc.
+ *
+ * xmppc ist Freie Software: Sie können es unter den Bedingungen
+ * der GNU General Public License, wie von der Free Software Foundation,
+ * Version 3 der Lizenz oder (nach Ihrer Wahl) jeder neueren
+ * veröffentlichten Version, weiter verteilen und/oder modifizieren.
+ *
+ * xmppc wird in der Hoffnung, dass es nützlich sein wird, aber
+ * OHNE JEDE GEWÄHRLEISTUNG, bereitgestellt; sogar ohne die implizite
+ * Gewährleistung der MARKTFÄHIGKEIT oder EIGNUNG FÜR EINEN BESTIMMTEN ZWECK.
+ * Siehe die GNU General Public License für weitere Details.
+ *
+ * Sie sollten eine Kopie der GNU General Public License zusammen mit diesem
+ * Programm erhalten haben. Wenn nicht, siehe <https://www.gnu.org/licenses/>.
+ */
+
+#include "bookmark.h"
+#include "stdio.h"
+#include "string.h"
+
+static void _bookmark_request(xmppc_t *xmppc);
+static int _bookmark_show(xmpp_conn_t *const conn, xmpp_stanza_t *const stanza, void *const userdata);
+
+void bookmark_execute_command (xmppc_t *xmppc, int argc, char *argv[]) {
+ if(argc == 1 && strcmp("list", argv[0]) == 0) {
+ _bookmark_request(xmppc);
+ } else {
+ printf("Command unbekannt!");
+ xmpp_disconnect(xmppc->conn);
+ }
+}
+
+static void _bookmark_request(xmppc_t *xmppc) {
+ char* id = xmpp_uuid_gen(xmppc->ctx);
+ xmpp_stanza_t *iq = xmpp_iq_new(xmppc->ctx, "get", id);
+ // pubsub
+ xmpp_stanza_t* pubsub = xmpp_stanza_new(xmppc->ctx);
+ xmpp_stanza_set_name(pubsub, "pubsub");
+ xmpp_stanza_set_ns(pubsub, "http://jabber.org/protocol/pubsub");
+ // items
+ xmpp_stanza_t* items = xmpp_stanza_new(xmppc->ctx);
+ xmpp_stanza_set_name(items, "items");
+ xmpp_stanza_set_attribute(items, "node", "storage:bookmarks");
+
+ xmpp_stanza_add_child(iq,pubsub);
+ xmpp_stanza_add_child(pubsub,items);
+ xmpp_id_handler_add(xmppc->conn, _bookmark_show, id, xmppc);
+ xmpp_send(xmppc->conn,iq);
+
+}
+
+int _bookmark_show(xmpp_conn_t *const conn, xmpp_stanza_t *const stanza, void *const userdata){
+ xmpp_stanza_t* pubsub = xmpp_stanza_get_child_by_name(stanza,"pubsub");
+ xmpp_stanza_t* items = xmpp_stanza_get_child_by_name(pubsub,"items");
+ xmpp_stanza_t* item = xmpp_stanza_get_child_by_name(items,"item");
+ xmpp_stanza_t* storage = xmpp_stanza_get_child_by_name(item,"storage");
+ if(storage != NULL) {
+ xmpp_stanza_t* c = xmpp_stanza_get_children(storage);
+ while (c) {
+ printf("%s%-50s - %-5s - %-40s\x1b[m\n", ANSI_COLOR_RED,
+ xmpp_stanza_get_attribute(c,"jid"),
+ xmpp_stanza_get_attribute(c,"autojoin"),
+ xmpp_stanza_get_attribute(c,"name")
+ );
+ c = xmpp_stanza_get_next(c);
+ }
+ }
+
+ xmpp_disconnect(conn);
+ return 1;
+}
+
+
@@ -0,0 +1,50 @@
+/*!
+ * @file bookmark.h
+ *
+ * vim: expandtab:ts=2:sts=2:sw=2
+ *
+ * @ copyright
+ *
+ * Copyright (C) 2020 Anoxinon e.V.
+ *
+ * This file is part of xmppc.
+ *
+ * xmppc is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * xmppc is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Foobar. If not, see <http://www.gnu.org/licenses/>.
+ *
+ * German
+ *
+ * Diese Datei ist Teil von xmppc.
+ *
+ * xmppc ist Freie Software: Sie können es unter den Bedingungen
+ * der GNU General Public License, wie von der Free Software Foundation,
+ * Version 3 der Lizenz oder (nach Ihrer Wahl) jeder neueren
+ * veröffentlichten Version, weiter verteilen und/oder modifizieren.
+ *
+ * xmppc wird in der Hoffnung, dass es nützlich sein wird, aber
+ * OHNE JEDE GEWÄHRLEISTUNG, bereitgestellt; sogar ohne die implizite
+ * Gewährleistung der MARKTFÄHIGKEIT oder EIGNUNG FÜR EINEN BESTIMMTEN ZWECK.
+ * Siehe die GNU General Public License für weitere Details.
+ *
+ * Sie sollten eine Kopie der GNU General Public License zusammen mit diesem
+ * Programm erhalten haben. Wenn nicht, siehe <https://www.gnu.org/licenses/>.
+ */
+
+#ifndef XMPPC_BOOKMARK_H__
+#define XMPPC_BOOKMARK_H__
+
+#include "xmppc.h"
+
+void bookmark_execute_command(xmppc_t *xmppc, int agrc, char *argv[]);
+
+#endif // XMPPC_BOOKMARK_H__
@@ -0,0 +1,158 @@
+/*!
+ * @file File: discovery.c
+ *
+ * vim: expandtab:ts=2:sts=2:sw=2
+ *
+ * @copyright
+ *
+ * Copyright (C) 2020 Anoxinon e.V.
+ *
+ * This file is part of xmppc.
+ *
+ * xmppc is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * xmppc is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Foobar. If not, see <http://www.gnu.org/licenses/>.
+ *
+ * German
+ *
+ * Diese Datei ist Teil von xmppc.
+ *
+ * xmppc ist Freie Software: Sie können es unter den Bedingungen
+ * der GNU General Public License, wie von der Free Software Foundation,
+ * Version 3 der Lizenz oder (nach Ihrer Wahl) jeder neueren
+ * veröffentlichten Version, weiter verteilen und/oder modifizieren.
+ *
+ * xmppc wird in der Hoffnung, dass es nützlich sein wird, aber
+ * OHNE JEDE GEWÄHRLEISTUNG, bereitgestellt; sogar ohne die implizite
+ * Gewährleistung der MARKTFÄHIGKEIT oder EIGNUNG FÜR EINEN BESTIMMTEN ZWECK.
+ * Siehe die GNU General Public License für weitere Details.
+ *
+ * Sie sollten eine Kopie der GNU General Public License zusammen mit diesem
+ * Programm erhalten haben. Wenn nicht, siehe <https://www.gnu.org/licenses/>.
+ */
+
+#include "discovery.h"
+#include "stdio.h"
+#include "string.h"
+
+static void _discovery_get_info(xmppc_t *xmppc, char* to);
+
+static void _discovery_get_item(xmppc_t *xmppc, char* to);
+
+static int _discovery_info_result_handle(xmpp_conn_t *const conn, xmpp_stanza_t *const stanza,
+ void *const userdata);
+
+static int _discovery_item_result_handle(xmpp_conn_t *const conn, xmpp_stanza_t *const stanza,
+ void *const userdata);
+
+void discovery_execute_command(xmppc_t *xmppc, int argc, char *argv[]) {
+ if( argc == 2 && ( strcmp("info", argv[0] ) == 0)) {
+ _discovery_get_info(xmppc, argv[1]);
+ } else if( argc == 2 && ( strcmp("item", argv[0] ) == 0)) {
+ _discovery_get_item(xmppc, argv[1]);
+ } else {
+ logError(xmppc, "Befehl unbekannt");
+ }
+}
+
+static void _discovery_get_info(xmppc_t *xmppc, char* to) {
+ char* id = xmpp_uuid_gen(xmppc->ctx);
+ xmpp_stanza_t *iq = xmpp_iq_new(xmppc->ctx, "get", id);
+ xmpp_stanza_set_to(iq,to);
+ xmpp_stanza_set_from(iq, xmpp_conn_get_jid(xmppc->conn));
+ xmpp_stanza_t *query = xmpp_stanza_new(xmppc->ctx);
+ xmpp_stanza_set_name(query,"query");
+ xmpp_stanza_set_ns(query,"http://jabber.org/protocol/disco#info");
+ xmpp_stanza_add_child(iq, query);
+ xmpp_id_handler_add(xmppc->conn, _discovery_info_result_handle, id, xmppc);
+ xmpp_send(xmppc->conn, iq);
+}
+
+static void _discovery_get_item(xmppc_t *xmppc, char* to) {
+ char* id = xmpp_uuid_gen(xmppc->ctx);
+ xmpp_stanza_t *iq = xmpp_iq_new(xmppc->ctx, "get", id);
+ xmpp_stanza_set_to(iq,to);
+ xmpp_stanza_set_from(iq, xmpp_conn_get_jid(xmppc->conn));
+ xmpp_stanza_t *query = xmpp_stanza_new(xmppc->ctx);
+ xmpp_stanza_set_name(query,"query");
+ xmpp_stanza_set_ns(query,"http://jabber.org/protocol/disco#items");
+ xmpp_stanza_add_child(iq, query);
+ xmpp_id_handler_add(xmppc->conn, _discovery_item_result_handle, id, xmppc);
+ xmpp_send(xmppc->conn, iq);
+}
+
+static int _discovery_item_result_handle(xmpp_conn_t *const conn, xmpp_stanza_t *const stanza,
+ void *const userdata) {
+ xmppc_t *xmppc = (xmppc_t *)userdata;
+
+ logInfo(xmppc,"Discover Item for: %s\n", xmpp_stanza_get_from(stanza));
+
+ if (strcmp(xmpp_stanza_get_type(stanza), "error") == 0) {
+ char* text;
+ size_t textlen;
+ xmpp_stanza_to_text(stanza,&text, &textlen);
+ logError(xmppc, "%s%s%s\n", ANSI_COLOR_RED, text, ANSI_COLOR_RESET);
+ }
+
+ xmpp_stanza_t* query = xmpp_stanza_get_child_by_name(stanza, "query");
+ if(query != NULL ) {
+ xmpp_stanza_t* c = xmpp_stanza_get_children(query);
+ while (c) {
+ if( strcmp( xmpp_stanza_get_name(c), "item" ) == 0) {
+ printf("%-40s - %-40s\n", xmpp_stanza_get_attribute(c, "jid"), xmpp_stanza_get_attribute(c, "name"));
+ }
+ c = xmpp_stanza_get_next(c);
+ }
+ }
+ xmpp_disconnect(xmppc->conn);
+ return 0;
+}
+
+static int _discovery_info_result_handle(xmpp_conn_t *const conn, xmpp_stanza_t *const stanza, void *const userdata){
+ xmppc_t *xmppc = (xmppc_t *)userdata;
+
+ if (strcmp(xmpp_stanza_get_type(stanza), "error") == 0) {
+ char* text;
+ size_t textlen;
+ xmpp_stanza_to_text(stanza,&text, &textlen);
+ logError(xmppc, "%s%s%s\n", ANSI_COLOR_RED, text, ANSI_COLOR_RESET);
+ return 0;
+ }
+
+ logInfo(xmppc,"Discover Info for:\t%s\n", xmpp_stanza_get_from(stanza) );
+
+ xmpp_stanza_t* query = xmpp_stanza_get_child_by_name(stanza, "query");
+ if(query != NULL ) {
+ xmpp_stanza_t* c = xmpp_stanza_get_children(query);
+
+ while (c) {
+ if( strcmp( xmpp_stanza_get_name(c), "identity" ) == 0) {
+ printf("%-10s - %-20s - %-40s\n", xmpp_stanza_get_attribute(c, "type"),xmpp_stanza_get_attribute(c, "category"), xmpp_stanza_get_attribute(c, "name") );
+ } else if( strcmp( xmpp_stanza_get_name(c), "feature" ) == 0) {
+ if ( strcmp( xmpp_stanza_get_attribute(c, "var"), "muc_passwordprotected") == 0 ) printf("\tpassword protected\n");
+ else if ( strcmp( xmpp_stanza_get_attribute(c, "var"), "muc_hidden") == 0 ) printf("\tmuc_hidden\n");
+ else if ( strcmp( xmpp_stanza_get_attribute(c, "var"), "muc_temporary") == 0 ) printf("\ttemporary\n");
+ else if ( strcmp( xmpp_stanza_get_attribute(c, "var"), "muc_open") == 0 ) printf("\topen\n");
+ else if ( strcmp( xmpp_stanza_get_attribute(c, "var"), "muc_unmoderated") == 0 ) printf("\tunmoderated\n");
+ else if ( strcmp( xmpp_stanza_get_attribute(c, "var"), "muc_nonanonymous") == 0 ) printf("\tnonanonymous\n");
+ else printf("\t%-10s\n", xmpp_stanza_get_attribute(c, "var"));
+ }
+ c = xmpp_stanza_get_next(c);
+ }
+
+ }
+
+ xmpp_disconnect(xmppc->conn);
+
+ return 0;
+}
+
@@ -0,0 +1,50 @@
+/*!
+ * @file discovery.h
+ *
+ * vim: expandtab:ts=2:sts=2:sw=2
+ *
+ * @ copyright
+ *
+ * Copyright (C) 2020 Anoxinon e.V.
+ *
+ * This file is part of xmppc.
+ *
+ * xmppc is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * xmppc is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Foobar. If not, see <http://www.gnu.org/licenses/>.
+ *
+ * German
+ *
+ * Diese Datei ist Teil von xmppc.
+ *
+ * xmppc ist Freie Software: Sie können es unter den Bedingungen
+ * der GNU General Public License, wie von der Free Software Foundation,
+ * Version 3 der Lizenz oder (nach Ihrer Wahl) jeder neueren
+ * veröffentlichten Version, weiter verteilen und/oder modifizieren.
+ *
+ * xmppc wird in der Hoffnung, dass es nützlich sein wird, aber
+ * OHNE JEDE GEWÄHRLEISTUNG, bereitgestellt; sogar ohne die implizite
+ * Gewährleistung der MARKTFÄHIGKEIT oder EIGNUNG FÜR EINEN BESTIMMTEN ZWECK.
+ * Siehe die GNU General Public License für weitere Details.
+ *
+ * Sie sollten eine Kopie der GNU General Public License zusammen mit diesem
+ * Programm erhalten haben. Wenn nicht, siehe <https://www.gnu.org/licenses/>.
+ */
+
+#ifndef XMPPC_DISCOVERY_H__
+#define XMPPC_DISCOVERY_H__
+
+#include "xmppc.h"
+
+void discovery_execute_command(xmppc_t *xmppc, int agrc, char *argv[]);
+
+#endif // XMPPC_DISCOVERY_H__
@@ -0,0 +1,129 @@
+/*!
+ * @file File: mam.c
+ *
+ * vim: expandtab:ts=2:sts=2:sw=2
+ *
+ * @copyright
+ *
+ * Copyright (C) 2020 Anoxinon e.V.
+ *
+ * This file is part of xmppc.
+ *
+ * xmppc is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * xmppc is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Foobar. If not, see <http://www.gnu.org/licenses/>.
+ *
+ * German
+ *
+ * Diese Datei ist Teil von xmppc.
+ *
+ * xmppc ist Freie Software: Sie können es unter den Bedingungen
+ * der GNU General Public License, wie von der Free Software Foundation,
+ * Version 3 der Lizenz oder (nach Ihrer Wahl) jeder neueren
+ * veröffentlichten Version, weiter verteilen und/oder modifizieren.
+ *
+ * xmppc wird in der Hoffnung, dass es nützlich sein wird, aber
+ * OHNE JEDE GEWÄHRLEISTUNG, bereitgestellt; sogar ohne die implizite
+ * Gewährleistung der MARKTFÄHIGKEIT oder EIGNUNG FÜR EINEN BESTIMMTEN ZWECK.
+ * Siehe die GNU General Public License für weitere Details.
+ *
+ * Sie sollten eine Kopie der GNU General Public License zusammen mit diesem
+ * Programm erhalten haben. Wenn nicht, siehe <https://www.gnu.org/licenses/>.
+ */
+
+#include "mam.h"
+#include "stdio.h"
+#include "string.h"
+
+static void _mam_request(xmppc_t *xmppc, char* to);
+static int _mam_show(xmpp_conn_t *const conn, xmpp_stanza_t *const stanza, void *const userdata);
+static int _mam_display_message(xmpp_conn_t *const conn, xmpp_stanza_t *const stanza, void *const userdata);
+
+void mam_execute_command (xmppc_t *xmppc, int argc, char *argv[]) {
+ if(argc == 2 && strcmp("list", argv[0]) == 0) {
+ _mam_request(xmppc, argv[1]);
+ } else {
+ printf("Command unbekannt!");
+ xmpp_disconnect(xmppc->conn);
+ }
+}
+
+static void _mam_request(xmppc_t *xmppc, char* to) {
+
+ xmpp_handler_add (xmppc->conn, _mam_display_message, NULL,"message",NULL, xmppc);
+
+ char* id = xmpp_uuid_gen(xmppc->ctx);
+ xmpp_stanza_t *iq = xmpp_iq_new(xmppc->ctx, "set", id);
+ // query
+ xmpp_stanza_t* query = xmpp_stanza_new(xmppc->ctx);
+ xmpp_stanza_set_name(query, "query");
+ xmpp_stanza_set_ns(query, "urn:xmpp:mam:2");
+
+
+ xmpp_stanza_t* x = xmpp_stanza_new(xmppc->ctx);
+ xmpp_stanza_set_name(x,"x");
+ xmpp_stanza_set_ns(x, "jabber:x:data"),
+ xmpp_stanza_set_type(x,"submit");
+
+ xmpp_stanza_add_child(query,x);
+
+ xmpp_stanza_t* f = xmpp_stanza_new(xmppc->ctx);
+ xmpp_stanza_set_name(f,"field");
+ xmpp_stanza_set_type(f,"hidden");
+ xmpp_stanza_set_attribute(f, "var", "FORM_TYPE");
+ xmpp_stanza_t* v = xmpp_stanza_new(xmppc->ctx);
+ xmpp_stanza_set_name(v,"value");
+ xmpp_stanza_t* b = xmpp_stanza_new(xmppc->ctx);
+ xmpp_stanza_set_text(b, "urn:xmpp:mam:2");
+
+ xmpp_stanza_add_child(x,f);
+ xmpp_stanza_add_child(f,v);
+ xmpp_stanza_add_child(v,b);
+
+ f = xmpp_stanza_new(xmppc->ctx);
+ xmpp_stanza_set_name(f,"field");
+ xmpp_stanza_set_attribute(f, "var", "with");
+ v = xmpp_stanza_new(xmppc->ctx);
+ xmpp_stanza_set_name(v,"value");
+ b = xmpp_stanza_new(xmppc->ctx);
+ xmpp_stanza_set_text(b, to);
+ //xmpp_stanza_set_text(b, xmpp_conn_get_jid (xmppc->conn));
+
+ xmpp_stanza_add_child(x,f);
+ xmpp_stanza_add_child(f,v);
+ xmpp_stanza_add_child(v,b);
+
+ xmpp_stanza_add_child(iq,query);
+ xmpp_id_handler_add(xmppc->conn, _mam_show, id, xmppc);
+ xmpp_send(xmppc->conn,iq);
+
+}
+
+int _mam_show(xmpp_conn_t *const conn, xmpp_stanza_t *const stanza, void *const userdata){
+ xmpp_stanza_t *fin = xmpp_stanza_get_child_by_name(stanza,"fin");
+ if(fin) {
+ xmpp_disconnect(conn);
+ }
+ return 1;
+}
+
+
+static int _mam_display_message(xmpp_conn_t *const conn, xmpp_stanza_t *const stanza, void *const userdata) {
+ xmpp_stanza_t* result = xmpp_stanza_get_child_by_name(stanza,"result");
+ if( result && strcmp("urn:xmpp:mam:2", xmpp_stanza_get_ns(result)) == 0 ) {
+ char* s;
+ size_t len;
+ xmpp_stanza_to_text(xmpp_stanza_get_children(result) ,&s,&len);
+ printf("%s%s\x1b[m\n", ANSI_COLOR_YELLOW, s);
+ }
+ return 1;
+}
@@ -0,0 +1,50 @@
+/*!
+ * @file mam.h
+ *
+ * vim: expandtab:ts=2:sts=2:sw=2
+ *
+ * @ copyright
+ *
+ * Copyright (C) 2020 Anoxinon e.V.
+ *
+ * This file is part of xmppc.
+ *
+ * xmppc is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * xmppc is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Foobar. If not, see <http://www.gnu.org/licenses/>.
+ *
+ * German
+ *
+ * Diese Datei ist Teil von xmppc.
+ *
+ * xmppc ist Freie Software: Sie können es unter den Bedingungen
+ * der GNU General Public License, wie von der Free Software Foundation,
+ * Version 3 der Lizenz oder (nach Ihrer Wahl) jeder neueren
+ * veröffentlichten Version, weiter verteilen und/oder modifizieren.
+ *
+ * xmppc wird in der Hoffnung, dass es nützlich sein wird, aber
+ * OHNE JEDE GEWÄHRLEISTUNG, bereitgestellt; sogar ohne die implizite
+ * Gewährleistung der MARKTFÄHIGKEIT oder EIGNUNG FÜR EINEN BESTIMMTEN ZWECK.
+ * Siehe die GNU General Public License für weitere Details.
+ *
+ * Sie sollten eine Kopie der GNU General Public License zusammen mit diesem
+ * Programm erhalten haben. Wenn nicht, siehe <https://www.gnu.org/licenses/>.
+ */
+
+#ifndef XMPPC_MAM_H__
+#define XMPPC_MAM_H__
+
+#include "xmppc.h"
+
+void mam_execute_command(xmppc_t *xmppc, int agrc, char *argv[]);
+
+#endif // XMPPC_MAM_H__
@@ -3,7 +3,7 @@
*
* vim: expandtab:ts=2:sts=2:sw=2
*
- * @copyright
+ * @copyright
*
* Copyright (C) 2020 Anoxinon e.V.
*
@@ -49,29 +49,43 @@
#include <stdio.h>
#include <strophe.h>
-#define ANSI_COLOR_RED "\x1b[31m"
-#define ANSI_COLOR_GREEN "\x1b[32m"
-#define ANSI_COLOR_YELLOW "\x1b[33m"
-#define ANSI_COLOR_BLUE "\x1b[34m"
-#define ANSI_COLOR_MAGENTA "\x1b[35m"
-#define ANSI_COLOR_CYAN "\x1b[36m"
+#define ANSI_COLOR_RED "\x1b[31m"
+#define ANSI_COLOR_GREEN "\x1b[32m"
+#define ANSI_COLOR_YELLOW "\x1b[33m"
+#define ANSI_COLOR_BLUE "\x1b[34m"
+#define ANSI_COLOR_MAGENTA "\x1b[35m"
+#define ANSI_COLOR_CYAN "\x1b[36m"
-#define ANSI_COLOR_B_RED "\x1b[91m"
+#define ANSI_COLOR_B_RED "\x1b[91m"
+#define ANSI_COLOR_RESET "\x1b[m"
/**
* XMPPC Level of Logging
*
*/
-typedef enum loglevel {
+typedef enum loglevel {
ERROR = 0,
- WARN = 1,
- INFO = 2,
+ WARN = 1,
+ INFO = 2,
DEBUG = 3,
TRACE = 4
} loglevel_t;
-typedef enum mode { UNKOWN, ACCOUNT, ROSTER, MESSAGE, MUC, OMEMO, PGP, OPENPGP, MONITOR } xmppc_mode_t;
+typedef enum mode {
+ UNKOWN,
+ ACCOUNT,
+ ROSTER,
+ MESSAGE,
+ MUC,
+ OMEMO,
+ PGP,
+ OPENPGP,
+ MONITOR,
+ MAM,
+ DISCOVERY,
+ BOOKMARK
+} xmppc_mode_t;
typedef struct {
/** log level **/