1/*!
2 * @file message.c
3 *
4 * vim: expandtab:ts=2:sts=2:sw=2
5 *
6 * @authors
7 * Copyright (C) 2020 Anoxinon e.V.
8 *
9 * @copyright
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 "message.h"
44#include "stdlib.h"
45#include "string.h"
46
47static void _message_send_text(xmppc_t *xmppc, char* to, char* message);
48
49void message_execute_command(xmppc_t *xmppc, int argc, char *argv[]) {
50 if( argc == 3 && ( strcmp("chat", argv[0] ) == 0)) {
51 _message_send_text(xmppc, argv[1],argv[2]);
52 } else {
53 logError(xmppc, "Befehl unbekannt");
54 }
55 sleep(10);
56 xmpp_disconnect(xmppc->conn);
57}
58
59void _message_send_text(xmppc_t *xmppc, char* to, char* text) {
60 xmpp_conn_t *conn = xmppc->conn;
61 xmpp_stanza_t *message;
62 char* id = xmpp_uuid_gen(xmppc->ctx);
63 message = xmpp_message_new(xmpp_conn_get_context(conn), "chat", to, id);
64 int res = xmpp_message_set_body(message, text);
65 if(res == 0) {
66 xmpp_send(conn, message);
67 printf("%s\n", id);
68 fflush(stdout);
69 }
70 xmpp_stanza_release(message);
71 free(id);
72}
73