main.c

  1/*!
  2 * @file main.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/*!
 44 * @mainpage xmppc - XMPP command line
 45 *
 46 * @section whatIsXmppc What is xmppc
 47 *
 48 * xmppc is a command line program for XMPP (https://xmpp.org/).
 49 * The program has been written for the Debian GNU/Linux system (https://www.debian.org/).
 50 *
 51 * @section build Build
 52 *
 53 * @subsection dependencies Dependencies
 54 *
 55 * - The GNU C Library (glibc) - 2.28-10
 56 * - GLib - 2.58.3
 57 * - XMPP library libstrophe - 0.9.2-2
 58 * - GPGME (GnuPG Made Easy) - 1.12.0-6
 59 *
 60 * @subsection compile Compile
 61 *
 62 * @code{.bash}
 63 * ./bootstrap.sh
 64 * ./configure
 65 * make
 66 * @endcode
 67 *
 68 * @subsection documentation Documentation
 69 * @code{.bash}
 70 * cd doc
 71 * make
 72 * @endcode
 73 * @section usage Usage
 74 *
 75 * @code{.bash}
 76 * xmppc --jid <jabberid> --pwd <secret> --mode <mode> <command> <command args>
 77 * @endcode
 78 *
 79 * @code{.bash}
 80 * xmppc --jid user@domain.tld --pwd "my secret" --mode pgp chat friend@domain.tld "Hello!"
 81 * xmppc --jid user@domain.tld --pwd $(pass XMPP/domain/user) --mode omemo list
 82 * @endcode
 83 *
 84 *
 85 * @section development Development
 86 *
 87 * - \subpage module
 88 *
 89 */
 90
 91/*!
 92 * \page module Modules
 93 *
 94 * \section account Account
 95 * \section roster Roster
 96 * \section message Message
 97 * \section muc Multi-User-Chat
 98 * \section omemo OMEMO
 99 * XEP-0384: OMEMO Encryption (Version 0.3.0 (2018-07-31)). xmppc can use used
100 * to request the users OMEMO Device ID List and displays the Fingerprints of
101 * the keys.
102 *
103 * @code{.bash}
104 * xmppc --jid user@domain.tld --pwd $(pass domain.tld/user) --mode omemo
105 * @endcode
106 *
107 * @code{.bash}
108 * xmppc --jid user@domain.tld --pwd $(pass domain.tld/user) --mode omemo| gpg --clear-sign --sign-with 123ABC_MY_OPENPGP_KEY_1234 > omemo.asc
109 * @endcode
110 *
111 *
112 * \section pgp PGP
113 * XEP-0027: Current Jabber OpenPGP Usage
114 * (https://xmpp.org/extensions/xep-0027.html) is obsolete, but there are still
115 * clients which supports XEP-0027 instead of XEP-0373 / XEP-0374. This module
116 * supports sending of OpenPGP encrypted messages via XMPP's XEP-0027.
117 *
118 * @code{.bash}
119 * xmppc --jid user@domain.tld --pwd "my secret" --mode pgp friend@domain.tld "Hello!"
120 * @endcode
121 *
122 * xmppc use GnuPG's GPGME API use lookup the own key and the key of the
123 * recipient. Those two keys will be used to encrypt the message.
124 *
125 * Details \subpage module-pgp
126 *
127 */
128
129#include "config.h"
130#include <assert.h>
131#include <getopt.h>
132#include <stdarg.h>
133#include <stdio.h>
134#include <stdlib.h>
135#include <string.h>
136#include <glib.h>
137#include <glib/gstdio.h>
138#include <strophe.h>
139#include <errno.h>
140#include <termios.h>
141#include <unistd.h>
142
143#include "xmppc.h"
144#include "mode/account.h"
145#include "mode/message.h"
146#include "mode/muc.h"
147#include "mode/omemo.h"
148#include "mode/roster.h"
149#include "mode/pgp.h"
150#include "mode/openpgp.h"
151#include "mode/monitor.h"
152#include "mode/mam.h"
153#include "mode/discovery.h"
154#include "mode/bookmark.h"
155
156/*!
157 * @brief The callback structure.
158 *
159 * This struct is used to call the "execution"-function of the mode module (e.g
160 * account_execute_command, roster_execute_command, ...).
161 *
162 * @authors DebxWoody
163 * @since 0.0.2
164 * @version 1
165 *
166 */
167
168typedef struct {
169  /*! Size of arguments */
170  int argc;
171  /*! Array of C-Strings (arguments) with size of argc */
172  char **argv;
173  /*! Pointer to Execute-Handler */
174  ExecuteHandler callback;
175  /*! XMPPC context object */
176  xmppc_t *xmppc;
177} callback_t;
178
179/*!
180 * @brief Mode Mapping.
181 *
182 * This struct is used to provider the mapping of the mode name (name via
183 * command line interface of the user (e.g. -m account). The technical ID of the
184 * mode which is defined via enum xmppc_mode_t and the pointer of function which
185 * should be used to handle those mode.
186 *
187 * @authors DebxWoody
188 * @since 0.0.2
189 * @version 1
190 */
191
192struct mode_mapping {
193  const char *name;
194  xmppc_mode_t mode;
195  ExecuteHandler callback;
196};
197
198/*!
199 * @brief Mode mapping table.
200 *
201 * Mapping of mode's string, enum and function.
202 *
203 * @authors DebxWoody
204 * @since 0.0.2
205 * @version 1
206 *
207 */
208
209static struct mode_mapping map[] = {
210  /*!
211  * Account Mode Mapping
212  * @since 0.0.2
213  * @version 1
214  */
215  {"account", ACCOUNT, account_execute_command},
216  /*!
217  * roster Mode Mapping
218  * @since 0.0.2
219  * @version 1
220  */
221  {"roster", ROSTER, roster_execute_command},
222  /*!
223  * Message Mode Mapping
224  * @since 0.0.2
225  * @version 1
226  */
227  {"message", MESSAGE, message_execute_command},
228  /*!
229  * MUC Mode Mapping
230  * @since 0.0.2
231  * @version 1
232  */
233  {"muc", MUC, muc_execute_command},
234  /*!
235  * OMEMO Mode Mapping
236  * @since 0.0.2
237  * @version 1
238  */
239  {"omemo", OMEMO, omemo_execute_command},
240  /*!
241  * PGP Mode Mapping
242  * @since 0.0.2
243  * @version 1
244  */
245  {"pgp", PGP, pgp_execute_command},
246  /*!
247  * XEP-0373: OpenPGP for XMPP
248  */
249  {"openpgp", OPENPGP, openpgp_execute_command},
250  /*!
251  * Monitor
252  */
253  {"monitor", MONITOR, monitor_execute_command},
254  //
255  {"discovery", DISCOVERY, discovery_execute_command},
256  //
257  {"bookmark", BOOKMARK, bookmark_execute_command},
258  // 
259  {"mam", MAM, mam_execute_command},
260  // End of Map
261  {NULL, 0}
262};
263
264/*!
265 * \brief Connection Handler Callback of libstrophe.
266 *
267 * This function will be called by libstrophe.
268 *
269 * \param conn See libstrophe documentation
270 * \param status See libstrophe documentation
271 * \param error See libstrophe documentation
272 * \param stream_error See libstrophe documentation
273 *
274 * \param userdata callback_t object for the mode request by user.
275 *
276 * @authors DebxWoody
277 * @since 0.0.2
278 * @version 1
279 *
280 */
281
282void conn_handler(xmpp_conn_t *const conn, const xmpp_conn_event_t status,
283                  const int error, xmpp_stream_error_t *const stream_error,
284                  void *const userdata) {
285  callback_t *callback = (callback_t *)userdata;
286
287  if( error != 0 ) {
288    logError(callback->xmppc,"Connection failed. %s\n", strerror(error));
289    xmpp_stop(xmpp_conn_get_context(conn));
290    return;
291  }
292
293  if( stream_error != NULL ) {
294    logError(callback->xmppc,"Connection failed. %s\n", stream_error->text);
295    xmpp_stop(xmpp_conn_get_context(conn));
296    return;
297  }
298
299
300  switch (status) {
301    case XMPP_CONN_CONNECT:
302      logInfo(callback->xmppc, "Connected\n");
303      if( xmpp_conn_is_secured(conn) ) {
304        logInfo(callback->xmppc, "Secure connection!\n");
305      } else {
306       logWarn(callback->xmppc, "Connection not secure!\n");
307      }
308      callback->callback(callback->xmppc, callback->argc, callback->argv);
309      break;
310    case XMPP_CONN_RAW_CONNECT:
311    case XMPP_CONN_DISCONNECT:
312    case XMPP_CONN_FAIL:
313      logInfo(callback->xmppc, "Stopping XMPP!\n");
314      xmpp_stop(xmpp_conn_get_context(conn));
315  }
316}
317
318static void _show_help();
319static int _agent_skill_command(int argc, char *argv[]);
320static char *_read_password_from_stdin(void);
321static char *_read_password_command(xmppc_t *xmppc, const char *command);
322
323/*!
324 * \brief C-Main function
325 *
326 * - Parse argv arguments of the command line.
327 * - Checks jid and password for xmpp logging
328 * - Checks mode requested by user
329 * - All other arguments will be used as mode parameters
330 *
331 * \param argc Arguments counter
332 * \param argv Arguments vector
333 * \returns Exit Code
334 *
335 * @authors DebxWoody
336 * @since 0.0.2
337 * @version 2
338 */
339
340int main(int argc, char *argv[]) {
341  if(argc < 2) {
342    _show_help();
343    return EXIT_FAILURE;
344  }
345
346  if (strcmp(argv[1], "agent-skill") == 0) {
347    return _agent_skill_command(argc, argv);
348  }
349
350  INIT_XMPPC(xmppc);
351
352  static int verbose_flag = 0;
353  int c = 0;
354  xmppc_mode_t mode = UNKOWN;
355  char *jid = NULL;
356  char *pwd = NULL;
357  char *account = NULL;
358
359  static struct option long_options[] = {
360      /* These options set a flag. */
361      {"verbose", no_argument, &verbose_flag, 1},
362      {"help", no_argument, 0, 'h'},
363      {"config", required_argument, 0, 'c'},
364      {"account", required_argument, 0, 'a'},
365      {"jid", required_argument, 0, 'j'},
366      {"pwd", required_argument, 0, 'p'},
367      {"mode", required_argument, 0, 'm'},
368      {"file", required_argument, 0, 'f'},
369      {0, 0, 0, 0}};
370
371  // No arguments provided
372  if (argc == 1) {
373        _show_help();
374        return EXIT_SUCCESS;
375  }
376
377  while (c > -1) {
378    int option_index = 0;
379
380    c = getopt_long(argc, argv, "hva:j:p:m:", long_options, &option_index);
381    if (c > -1) {
382      switch (c) {
383      case 'h':
384        _show_help();
385        return EXIT_SUCCESS;
386
387      case 'c':
388        printf("option -c with value `%s'\n", optarg);
389        break;
390
391      case 'f':
392        printf("option -f with value `%s'\n", optarg);
393        break;
394
395      case 'a':
396        account = malloc(strlen(optarg) + 1);
397        strcpy(account, optarg);
398        break;
399
400      case 'j':
401        jid = malloc(strlen(optarg) + 1);
402        strcpy(jid, optarg);
403        break;
404
405      case 'p':
406        if (strcmp(optarg, "-") == 0) {
407          pwd = _read_password_from_stdin();
408        } else {
409          pwd = g_strdup(optarg);
410        }
411        break;
412
413      case 'm':
414        for(int i = 0; map[i].name;i++ ) {
415          if (strcmp(optarg, map[i].name) == 0) {
416            mode = map[i].mode;
417            break;
418          }
419        }
420        break;
421
422      case 'v':
423        verbose_flag++;
424        break;
425
426      case '?':
427        break;
428
429      default:
430        abort();
431      }
432    }
433  }
434
435  // Loading config file
436  GKeyFile *config_file = g_key_file_new();
437  GError *error = NULL;
438  GString* configfile = g_string_new( g_get_home_dir());
439  g_string_append(configfile,"/.config/xmppc.conf");
440  gboolean configfilefound = g_key_file_load_from_file(
441    config_file,
442    configfile->str,
443    G_KEY_FILE_NONE,
444    &error);
445
446  if (!configfilefound) {
447   if(error && !g_error_matches(error, G_FILE_ERROR, G_FILE_ERROR_NOENT)) {
448      logError(&xmppc, "Error loading key file: %s\n", error->message);
449      return EXIT_FAILURE;
450    }
451    if(jid == NULL && account == NULL) {
452      printf("You need either --jid or --account parameter or a default account\n");
453      _show_help();
454      return EXIT_FAILURE;
455    }
456  }
457  g_clear_error(&error);
458
459  if(account != NULL || (jid == NULL && pwd == NULL)) {
460    logInfo(&xmppc,"Loading default account\n");
461    if( account == NULL ) {
462      account = "default";
463    }
464    if (jid == NULL) {
465      jid = g_key_file_get_value (config_file, account, "jid" ,&error);
466      if( error ) {
467        logError(&xmppc, "No jid found in configuration file. %s\n", error->message);
468        return EXIT_FAILURE;
469      }
470      g_clear_error(&error);
471    }
472
473    if (pwd == NULL) {
474      pwd = g_key_file_get_value (config_file, account, "pwd", &error);
475      if (!pwd) {
476        g_clear_error(&error);
477        char *pwd_cmd = g_key_file_get_value(config_file, account, "pwd-cmd", &error);
478        if (pwd_cmd) {
479          pwd = _read_password_command(&xmppc, pwd_cmd);
480          g_free(pwd_cmd);
481        }
482        g_clear_error(&error);
483      }
484      g_clear_error(&error);
485    }
486  }
487
488  if ( !pwd ) {
489    static struct termios current_terminal;
490    static struct termios pwd_terminal;
491
492    tcgetattr(STDIN_FILENO, &current_terminal);
493
494    pwd_terminal = current_terminal;
495    pwd_terminal.c_lflag &= ~(ECHO);
496    tcsetattr(STDIN_FILENO, TCSANOW, &pwd_terminal);
497    printf("Password for %s:", jid);
498    pwd = malloc(sizeof(char) * BUFSIZ);
499    if (fgets(pwd, BUFSIZ, stdin) == NULL) {
500        pwd[0] = '\0';
501    } else {
502        size_t pwd_len = strlen(pwd);
503        if (pwd_len > 0 && pwd[pwd_len - 1] == '\n') {
504          pwd[pwd_len - 1] = '\0';
505        }
506    }
507    tcsetattr(STDIN_FILENO, TCSANOW, &current_terminal);
508    printf("\n");
509  }
510
511  int paramc = argc- optind;
512  char* paramv[paramc];
513
514  for (int i = optind; i < argc; i++) {
515    char* x= malloc(strlen(argv[i])+1 *sizeof(char)  );
516    strcpy(x,argv[i]);
517    paramv[i-optind] = x;
518  }
519  xmppc_context(&xmppc, verbose_flag);
520
521  logInfo(&xmppc, "Connecting %s ... ", jid);
522  xmppc_connect(&xmppc, jid, pwd);
523
524  ExecuteHandler handler = NULL;
525        for(int i = 0; map[i].name;i++ ) {
526          if (mode ==  map[i].mode) {
527            handler = map[i].callback;
528            break;
529          }
530        }
531
532  if( handler == NULL ) {
533    logError(&xmppc, "Unknown mode\n");
534    return -1;
535  } 
536
537  callback_t callback = {paramc, paramv, handler, &xmppc};
538
539#if XMPPC_DEVELOPMENT
540  xmpp_conn_set_flags(xmppc.conn, XMPP_CONN_FLAG_TRUST_TLS);
541#else
542  xmpp_conn_set_flags(xmppc.conn, XMPP_CONN_FLAG_MANDATORY_TLS);
543#endif
544
545  int e =  xmpp_connect_client(xmppc.conn, NULL, 0, conn_handler, &callback);
546  if(XMPP_EOK != e ) {
547    printf("xmpp_connect_client failed");
548  }
549
550  xmpp_run(xmppc.ctx);
551  xmpp_conn_release(xmppc.conn);
552  xmpp_ctx_free(xmppc.ctx);
553  xmpp_shutdown();
554
555  g_free(jid);
556  g_free(pwd);
557
558  return EXIT_SUCCESS;
559}
560
561static int _agent_skill_command(int argc, char *argv[]) {
562  const char *skill_text =
563    "xmppc agent-skill\n"
564    "\n"
565    "Use this when the user asks you to communicate over XMPP/Jabber with xmppc.\n"
566    "Before sending or receiving, read ~/.config/xmppc/AGENTS.md if it exists; it\n"
567    "contains the user's allowed accounts, preferred contacts, and local policy.\n"
568    "Never read, print, summarize, or expose ~/.config/xmppc.conf, passwords,\n"
569    "password commands, environment variables, or other secrets.\n"
570    "\n"
571    "Commands:\n"
572    "  xmppc -a <account> -m message chat <jid> <body>\n"
573    "  xmppc -a <account> -m mam list <jid> [MAM_FIELD=VALUE ...]\n"
574    "  xmppc -a <account> -m mam receive <jid> after-id=<mam-id> [timeout=300s] [max=5]\n"
575    "\n"
576    "Sending prints one compact XML record after the sent stanza appears in MAM:\n"
577    "  <sent archive-id=\"mam-id\" message-id=\"stanza-id\" to=\"jid\"/>\n"
578    "Use archive-id as the receive after-id cursor when waiting for a reply. If\n"
579    "archive-id is empty, the message was sent but the archive cursor was not\n"
580    "resolved before timeout.\n"
581    "\n"
582    "MAM fields for list/receive are unordered key=value terms: with=, start=,\n"
583    "end=, after-id=, before-id=, ids=, max=. A bare JID is shorthand for with=.\n"
584    "A second bare argument is an error. start= accepts XMPP timestamps or relative\n"
585    "values like -5m; max defaults to 5 and is capped at 50.\n"
586    "\n"
587    "Message archive output is one compact XML record per line:\n"
588    "  <message id=\"mam-id\" message-id=\"stanza-id\" stamp=\"...\" from=\"...\" to=\"...\"><body>escaped body</body></message>\n"
589    "The id attribute is the MAM archive cursor. message-id is the stanza id.\n"
590    "Use the MAM id, not the stanza id, as receive after-id=.\n"
591    "\n"
592    "Receive behavior:\n"
593    "  xmppc -a <account> -m mam receive <jid> after-id=<mam-id>\n"
594    "blocks until at least one newer archived message is available or timeout is\n"
595    "reached. It polls with real MAM/RSM after-id queries and prints at most max\n"
596    "messages. If no message arrives before timeout, it exits without output.\n";
597
598  const char *pointer_skill =
599    "---\n"
600    "name: communicating-through-xmppc\n"
601    "description: \"Communicates with the user and other contacts over XMPP/Jabber using xmppc. Use when asked to send, list, or receive Jabber/XMPP messages.\"\n"
602    "---\n"
603    "\n"
604    "Run `xmppc agent-skill` and follow the instructions it prints.\n";
605
606  if (argc == 2) {
607    printf("%s", skill_text);
608    return EXIT_SUCCESS;
609  }
610
611  if (argc == 3 && strcmp(argv[2], "install") == 0) {
612    const char *home = g_get_home_dir();
613    if (!home) {
614      fprintf(stderr, "Could not determine home directory\n");
615      return EXIT_FAILURE;
616    }
617
618    char *skill_dir = g_build_filename(home, ".config", "agents", "skills", "communicating-through-xmppc", NULL);
619    char *skill_file = g_build_filename(skill_dir, "SKILL.md", NULL);
620
621    if (g_mkdir_with_parents(skill_dir, 0700) != 0) {
622      fprintf(stderr, "Could not create skill directory: %s\n", skill_dir);
623      g_free(skill_file);
624      g_free(skill_dir);
625      return EXIT_FAILURE;
626    }
627
628    GError *error = NULL;
629    if (!g_file_set_contents(skill_file, pointer_skill, -1, &error)) {
630      fprintf(stderr, "Could not write skill file: %s\n", error ? error->message : "unknown error");
631      g_clear_error(&error);
632      g_free(skill_file);
633      g_free(skill_dir);
634      return EXIT_FAILURE;
635    }
636
637    printf("Installed communicating-through-xmppc skill at %s\n", skill_file);
638    g_free(skill_file);
639    g_free(skill_dir);
640    return EXIT_SUCCESS;
641  }
642
643  fprintf(stderr, "Usage: xmppc agent-skill [install]\n");
644  return EXIT_FAILURE;
645}
646
647static char *_read_password_from_stdin(void) {
648  char buffer[BUFSIZ];
649  if (fgets(buffer, sizeof(buffer), stdin) == NULL) {
650    return g_strdup("");
651  }
652  g_strchomp(buffer);
653  return g_strdup(buffer);
654}
655
656static char *_read_password_command(xmppc_t *xmppc, const char *command) {
657  char *stdout_buf = NULL;
658  char *stderr_buf = NULL;
659  int exit_status = 0;
660  GError *error = NULL;
661
662  gboolean ok = g_spawn_command_line_sync(command, &stdout_buf, &stderr_buf, &exit_status, &error);
663  g_free(stderr_buf);
664
665  if (!ok) {
666    logError(xmppc, "pwd-cmd failed: %s\n", error ? error->message : "unknown error");
667    g_clear_error(&error);
668    g_free(stdout_buf);
669    return NULL;
670  }
671
672  if (exit_status != 0) {
673    logError(xmppc, "pwd-cmd failed\n");
674    g_free(stdout_buf);
675    return NULL;
676  }
677
678  if (!stdout_buf) {
679    return g_strdup("");
680  }
681
682  g_strchomp(stdout_buf);
683  return stdout_buf;
684}
685
686static void _show_help() {
687#ifdef XMPPC_DEVELOPMENT
688  printf("%s - Development\n", PACKAGE_STRING);
689#else
690  printf("%s\n", PACKAGE_STRING);
691#endif
692  printf("Usage: xmppc [--account <account>] [ --jid <jid> --pwd <pwd>] --mode <mode> <command> [<parameters> ...]\n");
693  printf("Options:\n");
694  printf("  -h / --help                 Display this information.\n");
695  printf("  -j / --jid <jid>            Jabber ID\n");
696  printf("  -p / --pwd <password>       Passwort\n");
697  printf("                               Use '-' to read password from stdin\n");
698  printf("  -a / --account <account>    Account\n");
699  printf("  -m / --mode <mode>          xmppc mode\n");
700  printf("  agent-skill [install]       Print or install the agent-facing xmppc skill\n");
701  printf("\n");
702  printf("Modes:\n");
703  printf("  -m --mode roster            xmppc roster mode\n");
704  printf("    list                      List all contacts\n");
705  printf("    export                    Exports all contacts\n");
706  printf("\n");
707  printf("  -m --mode message           xmppc message mode\n");
708  printf("    chat <jid> <message>      Sending unencrypted message to jid\n");
709  printf("\n");
710  printf("  -m --mode pgp               xmppc pgp mode (XEP-0027) \n");
711  printf("    chat <jid> <message>      Sending pgp encrypted message to jid\n");
712  printf("\n");
713  printf("  -m --mode omemo             xmppc omemo mode (XEP-0384)\n");
714  printf("    list                      List the device IDs and fingerprints\n");
715  printf("    delete-device-list        Delete OMEMO device list\n");
716  printf("\n");
717  printf("  -m --mode openpgp           xmppc openpgp mode (XEP-0373)\n");
718  printf("    signcrypt <jid> <message> Sending pgp signed and encrypted message to jid\n");
719  printf("\n");
720  printf("  -m --mode monitor           Monitot mode\n");
721  printf("    stanza                    Stanza Monitor\n");
722  printf("    monitor                   microblog Monitor microblog (XEP-0277)\n");
723  printf("\n");
724  printf("  -m --mode bookmark          Bookmark mode (XEP-0048)\n");
725  printf("    list                      List bookmarks\n");
726  printf("\n");
727  printf("  -m --mode mam               Message Archive Management (XEP-0313)\n");
728  printf("    list <jid> [field=value]  List archived messages from <jid>\n");
729  printf("    receive <jid> after-id=<id> [timeout=300s] [max=5]\n");
730  printf("\n");
731  printf("  -m --mode discovery         Service Discovery (XEP-0030)\n");
732  printf("    info <jid>                info request for <jid>\n");
733  printf("    item <jid>                item request for <jid>\n");
734  printf("\n");
735  printf("\n");
736  printf("Examples:\n");
737  printf("  Usage: xmppc --jid user@domain.tld --pwd \"secret\" --mode roster list\n");
738  printf("  Usage: xmppc --jid user@domain.tld --pwd \"secret\" --mode pgp chat friend@domain.tld \"Hello\"\n");
739  printf("  Usage: xmppc -a account1 --mode discovery item conference@domain.tld\n");
740  printf("  Usage: xmppc --mode bookmark list\n");
741}