mcabber/mcabber/main.c
author franky
Sat, 18 May 2019 20:44:01 +0200
changeset 2339 7f11a567d236
parent 2337 ffd0e57e9563
permissions -rw-r--r--
Implemented settings_free() This removes many leaked memory messages from valgrind and thus makes it easier to read its output.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
307
566818afee1c Add headers to C files
Mikael Berthe <mikael@lilotux.net>
parents: 306
diff changeset
     1
/*
566818afee1c Add headers to C files
Mikael Berthe <mikael@lilotux.net>
parents: 306
diff changeset
     2
 * main.c
393
f8f3c7493457 Whitespace cleanup
Mikael Berthe <mikael@lilotux.net>
parents: 389
diff changeset
     3
 *
2134
fc7a758ebbde Remove deprecated options comments, update headers
Mikael Berthe <mikael@lilotux.net>
parents: 2110
diff changeset
     4
 * Copyright (C) 2005-2014 Mikael Berthe <mikael@lilotux.net>
307
566818afee1c Add headers to C files
Mikael Berthe <mikael@lilotux.net>
parents: 306
diff changeset
     5
 *
566818afee1c Add headers to C files
Mikael Berthe <mikael@lilotux.net>
parents: 306
diff changeset
     6
 * This program is free software; you can redistribute it and/or modify
566818afee1c Add headers to C files
Mikael Berthe <mikael@lilotux.net>
parents: 306
diff changeset
     7
 * it under the terms of the GNU General Public License as published by
566818afee1c Add headers to C files
Mikael Berthe <mikael@lilotux.net>
parents: 306
diff changeset
     8
 * the Free Software Foundation; either version 2 of the License, or (at
566818afee1c Add headers to C files
Mikael Berthe <mikael@lilotux.net>
parents: 306
diff changeset
     9
 * your option) any later version.
566818afee1c Add headers to C files
Mikael Berthe <mikael@lilotux.net>
parents: 306
diff changeset
    10
 *
566818afee1c Add headers to C files
Mikael Berthe <mikael@lilotux.net>
parents: 306
diff changeset
    11
 * This program is distributed in the hope that it will be useful, but
566818afee1c Add headers to C files
Mikael Berthe <mikael@lilotux.net>
parents: 306
diff changeset
    12
 * WITHOUT ANY WARRANTY; without even the implied warranty of
566818afee1c Add headers to C files
Mikael Berthe <mikael@lilotux.net>
parents: 306
diff changeset
    13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
566818afee1c Add headers to C files
Mikael Berthe <mikael@lilotux.net>
parents: 306
diff changeset
    14
 * General Public License for more details.
566818afee1c Add headers to C files
Mikael Berthe <mikael@lilotux.net>
parents: 306
diff changeset
    15
 *
566818afee1c Add headers to C files
Mikael Berthe <mikael@lilotux.net>
parents: 306
diff changeset
    16
 * You should have received a copy of the GNU General Public License
2268
f5402d705f67 Fix FSF addresses in all files
Mikael Berthe <mikael@lilotux.net>
parents: 2231
diff changeset
    17
 * along with this program; if not, see <http://www.gnu.org/licenses/>.
307
566818afee1c Add headers to C files
Mikael Berthe <mikael@lilotux.net>
parents: 306
diff changeset
    18
 */
566818afee1c Add headers to C files
Mikael Berthe <mikael@lilotux.net>
parents: 306
diff changeset
    19
24
e88b15cbf2de [/trunk] Changeset 40 by mikael
mikael
parents:
diff changeset
    20
#include <stdio.h>
e88b15cbf2de [/trunk] Changeset 40 by mikael
mikael
parents:
diff changeset
    21
#include <stdlib.h>
e88b15cbf2de [/trunk] Changeset 40 by mikael
mikael
parents:
diff changeset
    22
#include <unistd.h>
e88b15cbf2de [/trunk] Changeset 40 by mikael
mikael
parents:
diff changeset
    23
#include <string.h>
e88b15cbf2de [/trunk] Changeset 40 by mikael
mikael
parents:
diff changeset
    24
#include <signal.h>
e88b15cbf2de [/trunk] Changeset 40 by mikael
mikael
parents:
diff changeset
    25
#include <termios.h>
163
a8f7dc0a56cb [/trunk] Changeset 175 by mikael
mikael
parents: 160
diff changeset
    26
#include <sys/types.h>
a8f7dc0a56cb [/trunk] Changeset 175 by mikael
mikael
parents: 160
diff changeset
    27
#include <sys/wait.h>
169
0ed6099b5a54 [/trunk] Changeset 181 by mikael
mikael
parents: 165
diff changeset
    28
#include <glib.h>
404
fb2325d24d13 Drop harddefines.h
Mikael Berthe <mikael@lilotux.net>
parents: 403
diff changeset
    29
#include <config.h>
1653
fca9a4c17432 Improve UI latency and CPU usage
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1643
diff changeset
    30
#include <poll.h>
2183
e62319868844 Fix external password support (esp. on OS X)
Mikael Berthe <mikael@lilotux.net>
parents: 2173
diff changeset
    31
#include <errno.h>
24
e88b15cbf2de [/trunk] Changeset 40 by mikael
mikael
parents:
diff changeset
    32
1600
c5ee395fbc8c Updated Entity Capabilities support (XEP-0115)
franky
parents: 1599
diff changeset
    33
#include "caps.h"
24
e88b15cbf2de [/trunk] Changeset 40 by mikael
mikael
parents:
diff changeset
    34
#include "screen.h"
279
f5dd437c057b Rewrite the settings system
Mikael Berthe <mikael@lilotux.net>
parents: 272
diff changeset
    35
#include "settings.h"
102
2b4cc6bc5bf2 [/trunk] Changeset 116 by mikael
mikael
parents: 96
diff changeset
    36
#include "roster.h"
96
8b2703ccc4be [/trunk] Changeset 110 by mikael
mikael
parents: 88
diff changeset
    37
#include "commands.h"
113
8ac67e951eab [/trunk] Changeset 127 by mikael
mikael
parents: 112
diff changeset
    38
#include "histolog.h"
163
a8f7dc0a56cb [/trunk] Changeset 175 by mikael
mikael
parents: 160
diff changeset
    39
#include "hooks.h"
81
0bd578421ce9 [/trunk] Changeset 95 by mikael
mikael
parents: 77
diff changeset
    40
#include "utils.h"
1042
8a395c2cafc4 Initial PGP support (decrypt)
Mikael Berthe <mikael@lilotux.net>
parents: 993
diff changeset
    41
#include "pgp.h"
1299
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents: 1259
diff changeset
    42
#include "otr.h"
1598
a087125d8fc8 Replace libjabber with loudmouth
franky
parents: 1597
diff changeset
    43
#include "xmpp.h"
1678
e489ead6574a New help system
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1674
diff changeset
    44
#include "help.h"
1685
1342df44c814 Improved events interface
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1678
diff changeset
    45
#include "events.h"
2228
1afa40f1d80d Fix compilation warning, when building without modules support
Myhailo Danylenko <isbear@ukrpost.net>
parents: 2196
diff changeset
    46
#include "compl.h"
1426
a64778f5f26b Implement FIFO named command pipe
Mikael Berthe <mikael@lilotux.net>
parents: 1425
diff changeset
    47
1941
2256d0626730 Modularize fifo system (Myhailo Danylenko)
Mikael Berthe <mikael@lilotux.net>
parents: 1940
diff changeset
    48
#ifndef MODULES_ENABLE
2256d0626730 Modularize fifo system (Myhailo Danylenko)
Mikael Berthe <mikael@lilotux.net>
parents: 1940
diff changeset
    49
# include "fifo.h"
2256d0626730 Modularize fifo system (Myhailo Danylenko)
Mikael Berthe <mikael@lilotux.net>
parents: 1940
diff changeset
    50
#endif
2256d0626730 Modularize fifo system (Myhailo Danylenko)
Mikael Berthe <mikael@lilotux.net>
parents: 1940
diff changeset
    51
1735
5093b5ca1572 New modules loading scheme
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1729
diff changeset
    52
#ifdef MODULES_ENABLE
5093b5ca1572 New modules loading scheme
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1729
diff changeset
    53
# include "modules.h"
5093b5ca1572 New modules loading scheme
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1729
diff changeset
    54
#endif
5093b5ca1572 New modules loading scheme
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1729
diff changeset
    55
781
d3af6877a7df Add --enable-hgcset to configure script
Mikael Berthe <mikael@lilotux.net>
parents: 779
diff changeset
    56
#ifdef ENABLE_HGCSET
d3af6877a7df Add --enable-hgcset to configure script
Mikael Berthe <mikael@lilotux.net>
parents: 779
diff changeset
    57
# include "hgcset.h"
d3af6877a7df Add --enable-hgcset to configure script
Mikael Berthe <mikael@lilotux.net>
parents: 779
diff changeset
    58
#endif
24
e88b15cbf2de [/trunk] Changeset 40 by mikael
mikael
parents:
diff changeset
    59
801
d8e0a1ce3e8a Define WAIT_ANY if needed.
Soren Andersen <somian@pobox.com>
parents: 789
diff changeset
    60
#ifndef WAIT_ANY
1053
1ec7ec9bda60 Cleanup/cosmetics
Mikael Berthe <mikael@lilotux.net>
parents: 1042
diff changeset
    61
# define WAIT_ANY -1
801
d8e0a1ce3e8a Define WAIT_ANY if needed.
Soren Andersen <somian@pobox.com>
parents: 789
diff changeset
    62
#endif
24
e88b15cbf2de [/trunk] Changeset 40 by mikael
mikael
parents:
diff changeset
    63
2231
387cea2a1a81 Fix resizing with --enable-sigwinch
Mikael Berthe <mikael@lilotux.net>
parents: 2228
diff changeset
    64
#ifdef USE_SIGWINCH
387cea2a1a81 Fix resizing with --enable-sigwinch
Mikael Berthe <mikael@lilotux.net>
parents: 2228
diff changeset
    65
void sigwinch_resize(void);
387cea2a1a81 Fix resizing with --enable-sigwinch
Mikael Berthe <mikael@lilotux.net>
parents: 2228
diff changeset
    66
static bool sigwinch;
387cea2a1a81 Fix resizing with --enable-sigwinch
Mikael Berthe <mikael@lilotux.net>
parents: 2228
diff changeset
    67
#endif
387cea2a1a81 Fix resizing with --enable-sigwinch
Mikael Berthe <mikael@lilotux.net>
parents: 2228
diff changeset
    68
387cea2a1a81 Fix resizing with --enable-sigwinch
Mikael Berthe <mikael@lilotux.net>
parents: 2228
diff changeset
    69
static bool terminate_ui;
1653
fca9a4c17432 Improve UI latency and CPU usage
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1643
diff changeset
    70
GMainContext *main_context;
fca9a4c17432 Improve UI latency and CPU usage
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1643
diff changeset
    71
789
1fa93cc6f5e3 Correctly restore term settings when interrupting the password query
Mikael Berthe <mikael@lilotux.net>
parents: 784
diff changeset
    72
static struct termios *backup_termios;
1fa93cc6f5e3 Correctly restore term settings when interrupting the password query
Mikael Berthe <mikael@lilotux.net>
parents: 784
diff changeset
    73
777
e6d42f239541 "/version" shows Mercurial changeset (if there's one)
Mikael Berthe <mikael@lilotux.net>
parents: 774
diff changeset
    74
char *mcabber_version(void)
e6d42f239541 "/version" shows Mercurial changeset (if there's one)
Mikael Berthe <mikael@lilotux.net>
parents: 774
diff changeset
    75
{
e6d42f239541 "/version" shows Mercurial changeset (if there's one)
Mikael Berthe <mikael@lilotux.net>
parents: 774
diff changeset
    76
  char *ver;
e6d42f239541 "/version" shows Mercurial changeset (if there's one)
Mikael Berthe <mikael@lilotux.net>
parents: 774
diff changeset
    77
#ifdef HGCSET
e6d42f239541 "/version" shows Mercurial changeset (if there's one)
Mikael Berthe <mikael@lilotux.net>
parents: 774
diff changeset
    78
  ver = g_strdup_printf("%s (%s)", PACKAGE_VERSION, HGCSET);
e6d42f239541 "/version" shows Mercurial changeset (if there's one)
Mikael Berthe <mikael@lilotux.net>
parents: 774
diff changeset
    79
#else
e6d42f239541 "/version" shows Mercurial changeset (if there's one)
Mikael Berthe <mikael@lilotux.net>
parents: 774
diff changeset
    80
  ver = g_strdup(PACKAGE_VERSION);
e6d42f239541 "/version" shows Mercurial changeset (if there's one)
Mikael Berthe <mikael@lilotux.net>
parents: 774
diff changeset
    81
#endif
e6d42f239541 "/version" shows Mercurial changeset (if there's one)
Mikael Berthe <mikael@lilotux.net>
parents: 774
diff changeset
    82
  return ver;
e6d42f239541 "/version" shows Mercurial changeset (if there's one)
Mikael Berthe <mikael@lilotux.net>
parents: 774
diff changeset
    83
}
e6d42f239541 "/version" shows Mercurial changeset (if there's one)
Mikael Berthe <mikael@lilotux.net>
parents: 774
diff changeset
    84
962
e79af58cd0be mcabber_disconnect() -> static mcabber_terminate()
Mikael Berthe <mikael@lilotux.net>
parents: 961
diff changeset
    85
static void mcabber_terminate(const char *msg)
312
f0b7ff2df7e8 Ctrl-C does not terminate mcabber
Mikael Berthe <mikael@lilotux.net>
parents: 307
diff changeset
    86
{
1941
2256d0626730 Modularize fifo system (Myhailo Danylenko)
Mikael Berthe <mikael@lilotux.net>
parents: 1940
diff changeset
    87
#ifndef MODULES_ENABLE
1659
2536a4b5e370 Re-add fifo_deinit() in mcabber_terminate() (isbear)
Mikael Berthe <mikael@lilotux.net>
parents: 1658
diff changeset
    88
  fifo_deinit();
1941
2256d0626730 Modularize fifo system (Myhailo Danylenko)
Mikael Berthe <mikael@lilotux.net>
parents: 1940
diff changeset
    89
#endif
1598
a087125d8fc8 Replace libjabber with loudmouth
franky
parents: 1597
diff changeset
    90
  xmpp_disconnect();
1780
e4378fbab5d7 Major API cleanup - bump API to 4
Mikael Berthe <mikael@lilotux.net>
parents: 1764
diff changeset
    91
  scr_terminate_curses();
789
1fa93cc6f5e3 Correctly restore term settings when interrupting the password query
Mikael Berthe <mikael@lilotux.net>
parents: 784
diff changeset
    92
1fa93cc6f5e3 Correctly restore term settings when interrupting the password query
Mikael Berthe <mikael@lilotux.net>
parents: 784
diff changeset
    93
  // Restore term settings, if needed.
1fa93cc6f5e3 Correctly restore term settings when interrupting the password query
Mikael Berthe <mikael@lilotux.net>
parents: 784
diff changeset
    94
  if (backup_termios)
1fa93cc6f5e3 Correctly restore term settings when interrupting the password query
Mikael Berthe <mikael@lilotux.net>
parents: 784
diff changeset
    95
    tcsetattr(fileno(stdin), TCSAFLUSH, backup_termios);
1fa93cc6f5e3 Correctly restore term settings when interrupting the password query
Mikael Berthe <mikael@lilotux.net>
parents: 784
diff changeset
    96
312
f0b7ff2df7e8 Ctrl-C does not terminate mcabber
Mikael Berthe <mikael@lilotux.net>
parents: 307
diff changeset
    97
  if (msg)
f0b7ff2df7e8 Ctrl-C does not terminate mcabber
Mikael Berthe <mikael@lilotux.net>
parents: 307
diff changeset
    98
    fprintf(stderr, "%s\n", msg);
f0b7ff2df7e8 Ctrl-C does not terminate mcabber
Mikael Berthe <mikael@lilotux.net>
parents: 307
diff changeset
    99
  printf("Bye!\n");
f0b7ff2df7e8 Ctrl-C does not terminate mcabber
Mikael Berthe <mikael@lilotux.net>
parents: 307
diff changeset
   100
  exit(EXIT_SUCCESS);
f0b7ff2df7e8 Ctrl-C does not terminate mcabber
Mikael Berthe <mikael@lilotux.net>
parents: 307
diff changeset
   101
}
f0b7ff2df7e8 Ctrl-C does not terminate mcabber
Mikael Berthe <mikael@lilotux.net>
parents: 307
diff changeset
   102
f0b7ff2df7e8 Ctrl-C does not terminate mcabber
Mikael Berthe <mikael@lilotux.net>
parents: 307
diff changeset
   103
void sig_handler(int signum)
f0b7ff2df7e8 Ctrl-C does not terminate mcabber
Mikael Berthe <mikael@lilotux.net>
parents: 307
diff changeset
   104
{
f0b7ff2df7e8 Ctrl-C does not terminate mcabber
Mikael Berthe <mikael@lilotux.net>
parents: 307
diff changeset
   105
  if (signum == SIGCHLD) {
f0b7ff2df7e8 Ctrl-C does not terminate mcabber
Mikael Berthe <mikael@lilotux.net>
parents: 307
diff changeset
   106
    int status;
f0b7ff2df7e8 Ctrl-C does not terminate mcabber
Mikael Berthe <mikael@lilotux.net>
parents: 307
diff changeset
   107
    pid_t pid;
f0b7ff2df7e8 Ctrl-C does not terminate mcabber
Mikael Berthe <mikael@lilotux.net>
parents: 307
diff changeset
   108
    do {
f0b7ff2df7e8 Ctrl-C does not terminate mcabber
Mikael Berthe <mikael@lilotux.net>
parents: 307
diff changeset
   109
      pid = waitpid (WAIT_ANY, &status, WNOHANG);
676
80d4959422ca New "eventcmd_checkstatus" option
Mikael Berthe <mikael@lilotux.net>
parents: 580
diff changeset
   110
      // Check the exit status value if 'eventcmd_checkstatus' is set
80d4959422ca New "eventcmd_checkstatus" option
Mikael Berthe <mikael@lilotux.net>
parents: 580
diff changeset
   111
      if (settings_opt_get_int("eventcmd_checkstatus")) {
80d4959422ca New "eventcmd_checkstatus" option
Mikael Berthe <mikael@lilotux.net>
parents: 580
diff changeset
   112
        if (pid > 0) {
80d4959422ca New "eventcmd_checkstatus" option
Mikael Berthe <mikael@lilotux.net>
parents: 580
diff changeset
   113
          // exit status 2 -> beep
80d4959422ca New "eventcmd_checkstatus" option
Mikael Berthe <mikael@lilotux.net>
parents: 580
diff changeset
   114
          if (WIFEXITED(status) && WEXITSTATUS(status) == 2) {
1780
e4378fbab5d7 Major API cleanup - bump API to 4
Mikael Berthe <mikael@lilotux.net>
parents: 1764
diff changeset
   115
            scr_beep();
676
80d4959422ca New "eventcmd_checkstatus" option
Mikael Berthe <mikael@lilotux.net>
parents: 580
diff changeset
   116
          }
80d4959422ca New "eventcmd_checkstatus" option
Mikael Berthe <mikael@lilotux.net>
parents: 580
diff changeset
   117
        }
80d4959422ca New "eventcmd_checkstatus" option
Mikael Berthe <mikael@lilotux.net>
parents: 580
diff changeset
   118
      }
312
f0b7ff2df7e8 Ctrl-C does not terminate mcabber
Mikael Berthe <mikael@lilotux.net>
parents: 307
diff changeset
   119
    } while (pid > 0);
f0b7ff2df7e8 Ctrl-C does not terminate mcabber
Mikael Berthe <mikael@lilotux.net>
parents: 307
diff changeset
   120
    signal(SIGCHLD, sig_handler);
f0b7ff2df7e8 Ctrl-C does not terminate mcabber
Mikael Berthe <mikael@lilotux.net>
parents: 307
diff changeset
   121
  } else if (signum == SIGTERM) {
962
e79af58cd0be mcabber_disconnect() -> static mcabber_terminate()
Mikael Berthe <mikael@lilotux.net>
parents: 961
diff changeset
   122
    mcabber_terminate("Killed by SIGTERM");
389
6e895f397474 Ncurses changes + Ctrl-C does not send a signal anylore
Mikael Berthe <mikael@lilotux.net>
parents: 374
diff changeset
   123
  } else if (signum == SIGINT) {
962
e79af58cd0be mcabber_disconnect() -> static mcabber_terminate()
Mikael Berthe <mikael@lilotux.net>
parents: 961
diff changeset
   124
    mcabber_terminate("Killed by SIGINT");
2071
a5acc2a1af53 Adds SIGHUP to signal handling.
Dominik George <nik@naturalnet.de>
parents: 2042
diff changeset
   125
  } else if (signum == SIGHUP) {
a5acc2a1af53 Adds SIGHUP to signal handling.
Dominik George <nik@naturalnet.de>
parents: 2042
diff changeset
   126
    mcabber_terminate("Killed by SIGHUP");
1454
6b98dc22946d Add optional SIGWINCH handler (Markus Hennecke)
Mikael Berthe <mikael@lilotux.net>
parents: 1448
diff changeset
   127
#ifdef USE_SIGWINCH
6b98dc22946d Add optional SIGWINCH handler (Markus Hennecke)
Mikael Berthe <mikael@lilotux.net>
parents: 1448
diff changeset
   128
  } else if (signum == SIGWINCH) {
2231
387cea2a1a81 Fix resizing with --enable-sigwinch
Mikael Berthe <mikael@lilotux.net>
parents: 2228
diff changeset
   129
    sigwinch = TRUE;
1454
6b98dc22946d Add optional SIGWINCH handler (Markus Hennecke)
Mikael Berthe <mikael@lilotux.net>
parents: 1448
diff changeset
   130
#endif
312
f0b7ff2df7e8 Ctrl-C does not terminate mcabber
Mikael Berthe <mikael@lilotux.net>
parents: 307
diff changeset
   131
  } else {
374
bd5638c21834 Improve logging system (traces)
Mikael Berthe <mikael@lilotux.net>
parents: 364
diff changeset
   132
    scr_LogPrint(LPRINT_LOGNORM, "Caught signal: %d", signum);
312
f0b7ff2df7e8 Ctrl-C does not terminate mcabber
Mikael Berthe <mikael@lilotux.net>
parents: 307
diff changeset
   133
  }
f0b7ff2df7e8 Ctrl-C does not terminate mcabber
Mikael Berthe <mikael@lilotux.net>
parents: 307
diff changeset
   134
}
f0b7ff2df7e8 Ctrl-C does not terminate mcabber
Mikael Berthe <mikael@lilotux.net>
parents: 307
diff changeset
   135
1042
8a395c2cafc4 Initial PGP support (decrypt)
Mikael Berthe <mikael@lilotux.net>
parents: 993
diff changeset
   136
//  ask_password(what)
8a395c2cafc4 Initial PGP support (decrypt)
Mikael Berthe <mikael@lilotux.net>
parents: 993
diff changeset
   137
// Return the password, or NULL.
8a395c2cafc4 Initial PGP support (decrypt)
Mikael Berthe <mikael@lilotux.net>
parents: 993
diff changeset
   138
// The string must be freed after use.
8a395c2cafc4 Initial PGP support (decrypt)
Mikael Berthe <mikael@lilotux.net>
parents: 993
diff changeset
   139
static char *ask_password(const char *what)
312
f0b7ff2df7e8 Ctrl-C does not terminate mcabber
Mikael Berthe <mikael@lilotux.net>
parents: 307
diff changeset
   140
{
f0b7ff2df7e8 Ctrl-C does not terminate mcabber
Mikael Berthe <mikael@lilotux.net>
parents: 307
diff changeset
   141
  char *password, *p;
f0b7ff2df7e8 Ctrl-C does not terminate mcabber
Mikael Berthe <mikael@lilotux.net>
parents: 307
diff changeset
   142
  size_t passsize = 128;
f0b7ff2df7e8 Ctrl-C does not terminate mcabber
Mikael Berthe <mikael@lilotux.net>
parents: 307
diff changeset
   143
  struct termios orig, new;
482
2ea7591584ab Use fgets() instead of getline()
Mikael Berthe <mikael@lilotux.net>
parents: 429
diff changeset
   144
2ea7591584ab Use fgets() instead of getline()
Mikael Berthe <mikael@lilotux.net>
parents: 429
diff changeset
   145
  password = g_new0(char, passsize);
312
f0b7ff2df7e8 Ctrl-C does not terminate mcabber
Mikael Berthe <mikael@lilotux.net>
parents: 307
diff changeset
   146
f0b7ff2df7e8 Ctrl-C does not terminate mcabber
Mikael Berthe <mikael@lilotux.net>
parents: 307
diff changeset
   147
  /* Turn echoing off and fail if we can't. */
1042
8a395c2cafc4 Initial PGP support (decrypt)
Mikael Berthe <mikael@lilotux.net>
parents: 993
diff changeset
   148
  if (tcgetattr(fileno(stdin), &orig) != 0) return NULL;
789
1fa93cc6f5e3 Correctly restore term settings when interrupting the password query
Mikael Berthe <mikael@lilotux.net>
parents: 784
diff changeset
   149
  backup_termios = &orig;
1fa93cc6f5e3 Correctly restore term settings when interrupting the password query
Mikael Berthe <mikael@lilotux.net>
parents: 784
diff changeset
   150
312
f0b7ff2df7e8 Ctrl-C does not terminate mcabber
Mikael Berthe <mikael@lilotux.net>
parents: 307
diff changeset
   151
  new = orig;
f0b7ff2df7e8 Ctrl-C does not terminate mcabber
Mikael Berthe <mikael@lilotux.net>
parents: 307
diff changeset
   152
  new.c_lflag &= ~ECHO;
1042
8a395c2cafc4 Initial PGP support (decrypt)
Mikael Berthe <mikael@lilotux.net>
parents: 993
diff changeset
   153
  if (tcsetattr(fileno(stdin), TCSAFLUSH, &new) != 0) return NULL;
312
f0b7ff2df7e8 Ctrl-C does not terminate mcabber
Mikael Berthe <mikael@lilotux.net>
parents: 307
diff changeset
   154
f0b7ff2df7e8 Ctrl-C does not terminate mcabber
Mikael Berthe <mikael@lilotux.net>
parents: 307
diff changeset
   155
  /* Read the password. */
1042
8a395c2cafc4 Initial PGP support (decrypt)
Mikael Berthe <mikael@lilotux.net>
parents: 993
diff changeset
   156
  printf("Please enter %s: ", what);
1598
a087125d8fc8 Replace libjabber with loudmouth
franky
parents: 1597
diff changeset
   157
  if (fgets(password, passsize, stdin) == NULL) return NULL;
312
f0b7ff2df7e8 Ctrl-C does not terminate mcabber
Mikael Berthe <mikael@lilotux.net>
parents: 307
diff changeset
   158
f0b7ff2df7e8 Ctrl-C does not terminate mcabber
Mikael Berthe <mikael@lilotux.net>
parents: 307
diff changeset
   159
  /* Restore terminal. */
f0b7ff2df7e8 Ctrl-C does not terminate mcabber
Mikael Berthe <mikael@lilotux.net>
parents: 307
diff changeset
   160
  tcsetattr(fileno(stdin), TCSAFLUSH, &orig);
f0b7ff2df7e8 Ctrl-C does not terminate mcabber
Mikael Berthe <mikael@lilotux.net>
parents: 307
diff changeset
   161
  printf("\n");
789
1fa93cc6f5e3 Correctly restore term settings when interrupting the password query
Mikael Berthe <mikael@lilotux.net>
parents: 784
diff changeset
   162
  backup_termios = NULL;
312
f0b7ff2df7e8 Ctrl-C does not terminate mcabber
Mikael Berthe <mikael@lilotux.net>
parents: 307
diff changeset
   163
f0b7ff2df7e8 Ctrl-C does not terminate mcabber
Mikael Berthe <mikael@lilotux.net>
parents: 307
diff changeset
   164
  for (p = (char*)password; *p; p++)
f0b7ff2df7e8 Ctrl-C does not terminate mcabber
Mikael Berthe <mikael@lilotux.net>
parents: 307
diff changeset
   165
    ;
f0b7ff2df7e8 Ctrl-C does not terminate mcabber
Mikael Berthe <mikael@lilotux.net>
parents: 307
diff changeset
   166
  for ( ; p > (char*)password ; p--)
f0b7ff2df7e8 Ctrl-C does not terminate mcabber
Mikael Berthe <mikael@lilotux.net>
parents: 307
diff changeset
   167
    if (*p == '\n' || *p == '\r') *p = 0;
f0b7ff2df7e8 Ctrl-C does not terminate mcabber
Mikael Berthe <mikael@lilotux.net>
parents: 307
diff changeset
   168
1042
8a395c2cafc4 Initial PGP support (decrypt)
Mikael Berthe <mikael@lilotux.net>
parents: 993
diff changeset
   169
  return password;
312
f0b7ff2df7e8 Ctrl-C does not terminate mcabber
Mikael Berthe <mikael@lilotux.net>
parents: 307
diff changeset
   170
}
f0b7ff2df7e8 Ctrl-C does not terminate mcabber
Mikael Berthe <mikael@lilotux.net>
parents: 307
diff changeset
   171
2173
cf08c3b630af Tweak the previous change...
Mikael Berthe <mikael@lilotux.net>
parents: 2172
diff changeset
   172
//  password_eval(command, *status)
cf08c3b630af Tweak the previous change...
Mikael Berthe <mikael@lilotux.net>
parents: 2172
diff changeset
   173
// Get password from a system command.
cf08c3b630af Tweak the previous change...
Mikael Berthe <mikael@lilotux.net>
parents: 2172
diff changeset
   174
// The string must be freed after use.
cf08c3b630af Tweak the previous change...
Mikael Berthe <mikael@lilotux.net>
parents: 2172
diff changeset
   175
static char *password_eval(const char *command, int *status)
cf08c3b630af Tweak the previous change...
Mikael Berthe <mikael@lilotux.net>
parents: 2172
diff changeset
   176
{
cf08c3b630af Tweak the previous change...
Mikael Berthe <mikael@lilotux.net>
parents: 2172
diff changeset
   177
#define MAX_PWD 100
cf08c3b630af Tweak the previous change...
Mikael Berthe <mikael@lilotux.net>
parents: 2172
diff changeset
   178
  char *pwd;
cf08c3b630af Tweak the previous change...
Mikael Berthe <mikael@lilotux.net>
parents: 2172
diff changeset
   179
  FILE *outfp = popen(command, "r");
cf08c3b630af Tweak the previous change...
Mikael Berthe <mikael@lilotux.net>
parents: 2172
diff changeset
   180
  if (outfp == NULL) {
2183
e62319868844 Fix external password support (esp. on OS X)
Mikael Berthe <mikael@lilotux.net>
parents: 2173
diff changeset
   181
    scr_log_print(LPRINT_NORMAL,
e62319868844 Fix external password support (esp. on OS X)
Mikael Berthe <mikael@lilotux.net>
parents: 2173
diff changeset
   182
                  "** ERROR: Failed to execute password_eval command.");
2173
cf08c3b630af Tweak the previous change...
Mikael Berthe <mikael@lilotux.net>
parents: 2172
diff changeset
   183
    *status = -1;
cf08c3b630af Tweak the previous change...
Mikael Berthe <mikael@lilotux.net>
parents: 2172
diff changeset
   184
    return NULL;
cf08c3b630af Tweak the previous change...
Mikael Berthe <mikael@lilotux.net>
parents: 2172
diff changeset
   185
  }
cf08c3b630af Tweak the previous change...
Mikael Berthe <mikael@lilotux.net>
parents: 2172
diff changeset
   186
cf08c3b630af Tweak the previous change...
Mikael Berthe <mikael@lilotux.net>
parents: 2172
diff changeset
   187
  pwd = g_new0(char, MAX_PWD);
cf08c3b630af Tweak the previous change...
Mikael Berthe <mikael@lilotux.net>
parents: 2172
diff changeset
   188
  if (fgets(pwd, MAX_PWD, outfp) == NULL) {
2183
e62319868844 Fix external password support (esp. on OS X)
Mikael Berthe <mikael@lilotux.net>
parents: 2173
diff changeset
   189
    scr_log_print(LPRINT_NORMAL,
e62319868844 Fix external password support (esp. on OS X)
Mikael Berthe <mikael@lilotux.net>
parents: 2173
diff changeset
   190
                  "** ERROR: Failed to read from password_eval command.");
2173
cf08c3b630af Tweak the previous change...
Mikael Berthe <mikael@lilotux.net>
parents: 2172
diff changeset
   191
    g_free(pwd);
cf08c3b630af Tweak the previous change...
Mikael Berthe <mikael@lilotux.net>
parents: 2172
diff changeset
   192
    *status = -1;
cf08c3b630af Tweak the previous change...
Mikael Berthe <mikael@lilotux.net>
parents: 2172
diff changeset
   193
    return NULL;
cf08c3b630af Tweak the previous change...
Mikael Berthe <mikael@lilotux.net>
parents: 2172
diff changeset
   194
  }
cf08c3b630af Tweak the previous change...
Mikael Berthe <mikael@lilotux.net>
parents: 2172
diff changeset
   195
cf08c3b630af Tweak the previous change...
Mikael Berthe <mikael@lilotux.net>
parents: 2172
diff changeset
   196
  int res = pclose(outfp);
2183
e62319868844 Fix external password support (esp. on OS X)
Mikael Berthe <mikael@lilotux.net>
parents: 2173
diff changeset
   197
  if (res != 0 && errno != ECHILD) {
e62319868844 Fix external password support (esp. on OS X)
Mikael Berthe <mikael@lilotux.net>
parents: 2173
diff changeset
   198
    scr_log_print(LPRINT_NORMAL,
e62319868844 Fix external password support (esp. on OS X)
Mikael Berthe <mikael@lilotux.net>
parents: 2173
diff changeset
   199
                  "** ERROR: Password evaluation command exited with error %d.",
e62319868844 Fix external password support (esp. on OS X)
Mikael Berthe <mikael@lilotux.net>
parents: 2173
diff changeset
   200
                  res);
e62319868844 Fix external password support (esp. on OS X)
Mikael Berthe <mikael@lilotux.net>
parents: 2173
diff changeset
   201
    if (res == -1) {
2184
f30459c47092 Fix indent in previous patch
Mikael Berthe <mikael@lilotux.net>
parents: 2183
diff changeset
   202
      scr_log_print(LPRINT_NORMAL, "   errno=%d", errno);
2183
e62319868844 Fix external password support (esp. on OS X)
Mikael Berthe <mikael@lilotux.net>
parents: 2173
diff changeset
   203
    }
2173
cf08c3b630af Tweak the previous change...
Mikael Berthe <mikael@lilotux.net>
parents: 2172
diff changeset
   204
    g_free(pwd);
cf08c3b630af Tweak the previous change...
Mikael Berthe <mikael@lilotux.net>
parents: 2172
diff changeset
   205
    *status = res;
cf08c3b630af Tweak the previous change...
Mikael Berthe <mikael@lilotux.net>
parents: 2172
diff changeset
   206
    return NULL;
cf08c3b630af Tweak the previous change...
Mikael Berthe <mikael@lilotux.net>
parents: 2172
diff changeset
   207
  }
cf08c3b630af Tweak the previous change...
Mikael Berthe <mikael@lilotux.net>
parents: 2172
diff changeset
   208
cf08c3b630af Tweak the previous change...
Mikael Berthe <mikael@lilotux.net>
parents: 2172
diff changeset
   209
  // Strip trailing whitespaces and newlines
cf08c3b630af Tweak the previous change...
Mikael Berthe <mikael@lilotux.net>
parents: 2172
diff changeset
   210
  size_t i = strlen(pwd);
cf08c3b630af Tweak the previous change...
Mikael Berthe <mikael@lilotux.net>
parents: 2172
diff changeset
   211
  while (i && isspace(pwd[i-1])) {
cf08c3b630af Tweak the previous change...
Mikael Berthe <mikael@lilotux.net>
parents: 2172
diff changeset
   212
    i--;
cf08c3b630af Tweak the previous change...
Mikael Berthe <mikael@lilotux.net>
parents: 2172
diff changeset
   213
  }
cf08c3b630af Tweak the previous change...
Mikael Berthe <mikael@lilotux.net>
parents: 2172
diff changeset
   214
  pwd[i] = '\0';
cf08c3b630af Tweak the previous change...
Mikael Berthe <mikael@lilotux.net>
parents: 2172
diff changeset
   215
  return pwd;
cf08c3b630af Tweak the previous change...
Mikael Berthe <mikael@lilotux.net>
parents: 2172
diff changeset
   216
}
cf08c3b630af Tweak the previous change...
Mikael Berthe <mikael@lilotux.net>
parents: 2172
diff changeset
   217
784
d7f3b58db522 Display hgcset (if defined) at startup
Mikael Berthe <mikael@lilotux.net>
parents: 781
diff changeset
   218
static void credits(void)
24
e88b15cbf2de [/trunk] Changeset 40 by mikael
mikael
parents:
diff changeset
   219
{
895
b461d7ee6d96 Minor changes
Mikael Berthe <mikael@lilotux.net>
parents: 872
diff changeset
   220
  const char *v_fmt = "MCabber %s -- Email: mcabber [at] lilotux [dot] net\n";
784
d7f3b58db522 Display hgcset (if defined) at startup
Mikael Berthe <mikael@lilotux.net>
parents: 781
diff changeset
   221
  char *v = mcabber_version();
851
da03534e46c7 Add startup log messages to the status buffer
Mikael Berthe <mikael@lilotux.net>
parents: 848
diff changeset
   222
  printf(v_fmt, v);
1897
efd7c4c34ff2 Display mcabber version when starting a trace log
Mikael Berthe <mikael@lilotux.net>
parents: 1894
diff changeset
   223
  scr_LogPrint(LPRINT_NORMAL|LPRINT_NOTUTF8, v_fmt, v);
784
d7f3b58db522 Display hgcset (if defined) at startup
Mikael Berthe <mikael@lilotux.net>
parents: 781
diff changeset
   224
  g_free(v);
24
e88b15cbf2de [/trunk] Changeset 40 by mikael
mikael
parents:
diff changeset
   225
}
e88b15cbf2de [/trunk] Changeset 40 by mikael
mikael
parents:
diff changeset
   226
1257
05dc45e7c7bb Add command line option -v
Mikael Berthe <mikael@lilotux.net>
parents: 1256
diff changeset
   227
static void compile_options(void)
05dc45e7c7bb Add command line option -v
Mikael Berthe <mikael@lilotux.net>
parents: 1256
diff changeset
   228
{
05dc45e7c7bb Add command line option -v
Mikael Berthe <mikael@lilotux.net>
parents: 1256
diff changeset
   229
  puts("Installation data directory: " DATA_DIR "\n");
05dc45e7c7bb Add command line option -v
Mikael Berthe <mikael@lilotux.net>
parents: 1256
diff changeset
   230
#ifdef HAVE_UNICODE
05dc45e7c7bb Add command line option -v
Mikael Berthe <mikael@lilotux.net>
parents: 1256
diff changeset
   231
  puts("Compiled with unicode support.");
05dc45e7c7bb Add command line option -v
Mikael Berthe <mikael@lilotux.net>
parents: 1256
diff changeset
   232
#endif
1630
141ae278e769 Reorder feature list in mcabber -V
Mikael Berthe <mikael@lilotux.net>
parents: 1628
diff changeset
   233
#ifdef MODULES_ENABLE
1764
6e856c5858c3 Display module API version with mcabber -V
Mikael Berthe <mikael@lilotux.net>
parents: 1744
diff changeset
   234
  printf("Compiled with modules support. (API %s:%d-%d)\n",
6e856c5858c3 Display module API version with mcabber -V
Mikael Berthe <mikael@lilotux.net>
parents: 1744
diff changeset
   235
         MCABBER_BRANCH, MCABBER_API_MIN, MCABBER_API_VERSION);
1702
02039190532d Display modules directory with mcabber -V
Mikael Berthe <mikael@lilotux.net>
parents: 1685
diff changeset
   236
# ifdef PKGLIB_DIR
1764
6e856c5858c3 Display module API version with mcabber -V
Mikael Berthe <mikael@lilotux.net>
parents: 1744
diff changeset
   237
  puts("Modules directory: " PKGLIB_DIR);
1702
02039190532d Display modules directory with mcabber -V
Mikael Berthe <mikael@lilotux.net>
parents: 1685
diff changeset
   238
# endif
1630
141ae278e769 Reorder feature list in mcabber -V
Mikael Berthe <mikael@lilotux.net>
parents: 1628
diff changeset
   239
#endif
1257
05dc45e7c7bb Add command line option -v
Mikael Berthe <mikael@lilotux.net>
parents: 1256
diff changeset
   240
#ifdef HAVE_GPGME
05dc45e7c7bb Add command line option -v
Mikael Berthe <mikael@lilotux.net>
parents: 1256
diff changeset
   241
  puts("Compiled with GPG support.");
05dc45e7c7bb Add command line option -v
Mikael Berthe <mikael@lilotux.net>
parents: 1256
diff changeset
   242
#endif
1299
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents: 1259
diff changeset
   243
#ifdef HAVE_LIBOTR
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents: 1259
diff changeset
   244
  puts("Compiled with OTR support.");
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents: 1259
diff changeset
   245
#endif
1590
8d1bcc83ae32 Add support for spellchecking with Enchant (caolan)
Mikael Berthe <mikael@lilotux.net>
parents: 1545
diff changeset
   246
#ifdef WITH_ENCHANT
8d1bcc83ae32 Add support for spellchecking with Enchant (caolan)
Mikael Berthe <mikael@lilotux.net>
parents: 1545
diff changeset
   247
  puts("Compiled with Enchant support.");
8d1bcc83ae32 Add support for spellchecking with Enchant (caolan)
Mikael Berthe <mikael@lilotux.net>
parents: 1545
diff changeset
   248
#endif
1257
05dc45e7c7bb Add command line option -v
Mikael Berthe <mikael@lilotux.net>
parents: 1256
diff changeset
   249
#ifdef WITH_ASPELL
05dc45e7c7bb Add command line option -v
Mikael Berthe <mikael@lilotux.net>
parents: 1256
diff changeset
   250
  puts("Compiled with Aspell support.");
05dc45e7c7bb Add command line option -v
Mikael Berthe <mikael@lilotux.net>
parents: 1256
diff changeset
   251
#endif
1423
757ebe4df0b9 Replace DEBUG_ENABLE with ENABLE_DEBUG
Mikael Berthe <mikael@lilotux.net>
parents: 1421
diff changeset
   252
#ifdef ENABLE_DEBUG
1257
05dc45e7c7bb Add command line option -v
Mikael Berthe <mikael@lilotux.net>
parents: 1256
diff changeset
   253
  puts("Compiled with debugging support.");
05dc45e7c7bb Add command line option -v
Mikael Berthe <mikael@lilotux.net>
parents: 1256
diff changeset
   254
#endif
05dc45e7c7bb Add command line option -v
Mikael Berthe <mikael@lilotux.net>
parents: 1256
diff changeset
   255
}
05dc45e7c7bb Add command line option -v
Mikael Berthe <mikael@lilotux.net>
parents: 1256
diff changeset
   256
05dc45e7c7bb Add command line option -v
Mikael Berthe <mikael@lilotux.net>
parents: 1256
diff changeset
   257
static void main_init_pgp(void)
1042
8a395c2cafc4 Initial PGP support (decrypt)
Mikael Berthe <mikael@lilotux.net>
parents: 993
diff changeset
   258
{
8a395c2cafc4 Initial PGP support (decrypt)
Mikael Berthe <mikael@lilotux.net>
parents: 993
diff changeset
   259
#ifdef HAVE_GPGME
8a395c2cafc4 Initial PGP support (decrypt)
Mikael Berthe <mikael@lilotux.net>
parents: 993
diff changeset
   260
  const char *pk, *pp;
8a395c2cafc4 Initial PGP support (decrypt)
Mikael Berthe <mikael@lilotux.net>
parents: 993
diff changeset
   261
  char *typed_passwd = NULL;
1238
80008fe2a4f2 Re-enable gpg-agent (revert 591d8b35c881)
Mikael Berthe <mikael@lilotux.net>
parents: 1223
diff changeset
   262
  char *p;
1042
8a395c2cafc4 Initial PGP support (decrypt)
Mikael Berthe <mikael@lilotux.net>
parents: 993
diff changeset
   263
  bool pgp_invalid = FALSE;
8a395c2cafc4 Initial PGP support (decrypt)
Mikael Berthe <mikael@lilotux.net>
parents: 993
diff changeset
   264
  bool pgp_agent;
1313
d1d12a09b04a Make passphrase entry retries customizable (suggested by Till Maas)
Mikael Berthe <mikael@lilotux.net>
parents: 1311
diff changeset
   265
  int retries;
1042
8a395c2cafc4 Initial PGP support (decrypt)
Mikael Berthe <mikael@lilotux.net>
parents: 993
diff changeset
   266
2196
8811fe9d6ef0 Improve support for GnuPG v2+
Mikael Berthe <mikael@lilotux.net>
parents: 2184
diff changeset
   267
  pk = settings_opt_get("pgp_private_key");
8811fe9d6ef0 Improve support for GnuPG v2+
Mikael Berthe <mikael@lilotux.net>
parents: 2184
diff changeset
   268
8811fe9d6ef0 Improve support for GnuPG v2+
Mikael Berthe <mikael@lilotux.net>
parents: 2184
diff changeset
   269
  if (!pk)
8811fe9d6ef0 Improve support for GnuPG v2+
Mikael Berthe <mikael@lilotux.net>
parents: 2184
diff changeset
   270
    scr_LogPrint(LPRINT_LOGNORM, "WARNING: unknown PGP private key");
8811fe9d6ef0 Improve support for GnuPG v2+
Mikael Berthe <mikael@lilotux.net>
parents: 2184
diff changeset
   271
8811fe9d6ef0 Improve support for GnuPG v2+
Mikael Berthe <mikael@lilotux.net>
parents: 2184
diff changeset
   272
  if (gpg_init(pk, NULL)) {
8811fe9d6ef0 Improve support for GnuPG v2+
Mikael Berthe <mikael@lilotux.net>
parents: 2184
diff changeset
   273
    scr_LogPrint(LPRINT_LOGNORM, "WARNING: Could not initialize PGP.");
8811fe9d6ef0 Improve support for GnuPG v2+
Mikael Berthe <mikael@lilotux.net>
parents: 2184
diff changeset
   274
    return;
8811fe9d6ef0 Improve support for GnuPG v2+
Mikael Berthe <mikael@lilotux.net>
parents: 2184
diff changeset
   275
  }
8811fe9d6ef0 Improve support for GnuPG v2+
Mikael Berthe <mikael@lilotux.net>
parents: 2184
diff changeset
   276
8811fe9d6ef0 Improve support for GnuPG v2+
Mikael Berthe <mikael@lilotux.net>
parents: 2184
diff changeset
   277
  // We're done if the PGP engine version is > 1
8811fe9d6ef0 Improve support for GnuPG v2+
Mikael Berthe <mikael@lilotux.net>
parents: 2184
diff changeset
   278
  // since the agent is mandatory and password mechanism is external.
8811fe9d6ef0 Improve support for GnuPG v2+
Mikael Berthe <mikael@lilotux.net>
parents: 2184
diff changeset
   279
  if (!gpg_is_version1())
8811fe9d6ef0 Improve support for GnuPG v2+
Mikael Berthe <mikael@lilotux.net>
parents: 2184
diff changeset
   280
    return;
8811fe9d6ef0 Improve support for GnuPG v2+
Mikael Berthe <mikael@lilotux.net>
parents: 2184
diff changeset
   281
8811fe9d6ef0 Improve support for GnuPG v2+
Mikael Berthe <mikael@lilotux.net>
parents: 2184
diff changeset
   282
1238
80008fe2a4f2 Re-enable gpg-agent (revert 591d8b35c881)
Mikael Berthe <mikael@lilotux.net>
parents: 1223
diff changeset
   283
  p = getenv("GPG_AGENT_INFO");
80008fe2a4f2 Re-enable gpg-agent (revert 591d8b35c881)
Mikael Berthe <mikael@lilotux.net>
parents: 1223
diff changeset
   284
  pgp_agent = (p && strchr(p, ':'));
1042
8a395c2cafc4 Initial PGP support (decrypt)
Mikael Berthe <mikael@lilotux.net>
parents: 993
diff changeset
   285
1313
d1d12a09b04a Make passphrase entry retries customizable (suggested by Till Maas)
Mikael Berthe <mikael@lilotux.net>
parents: 1311
diff changeset
   286
  if (settings_opt_get("pgp_passphrase_retries"))
d1d12a09b04a Make passphrase entry retries customizable (suggested by Till Maas)
Mikael Berthe <mikael@lilotux.net>
parents: 1311
diff changeset
   287
    retries = settings_opt_get_int("pgp_passphrase_retries");
d1d12a09b04a Make passphrase entry retries customizable (suggested by Till Maas)
Mikael Berthe <mikael@lilotux.net>
parents: 1311
diff changeset
   288
  else
d1d12a09b04a Make passphrase entry retries customizable (suggested by Till Maas)
Mikael Berthe <mikael@lilotux.net>
parents: 1311
diff changeset
   289
    retries = 2;
d1d12a09b04a Make passphrase entry retries customizable (suggested by Till Maas)
Mikael Berthe <mikael@lilotux.net>
parents: 1311
diff changeset
   290
2196
8811fe9d6ef0 Improve support for GnuPG v2+
Mikael Berthe <mikael@lilotux.net>
parents: 2184
diff changeset
   291
  pp = settings_opt_get("pgp_passphrase");
8811fe9d6ef0 Improve support for GnuPG v2+
Mikael Berthe <mikael@lilotux.net>
parents: 2184
diff changeset
   292
1042
8a395c2cafc4 Initial PGP support (decrypt)
Mikael Berthe <mikael@lilotux.net>
parents: 993
diff changeset
   293
  if (!pk) {
8a395c2cafc4 Initial PGP support (decrypt)
Mikael Berthe <mikael@lilotux.net>
parents: 993
diff changeset
   294
    pgp_invalid = TRUE;
8a395c2cafc4 Initial PGP support (decrypt)
Mikael Berthe <mikael@lilotux.net>
parents: 993
diff changeset
   295
  } else if (!(pp || pgp_agent)) {
8a395c2cafc4 Initial PGP support (decrypt)
Mikael Berthe <mikael@lilotux.net>
parents: 993
diff changeset
   296
    // Request PGP passphrase
1799
e73cd9377a4e Better UI message for password prompt
Mikael Berthe <mikael@lilotux.net>
parents: 1780
diff changeset
   297
    pp = typed_passwd = ask_password("your PGP passphrase");
1042
8a395c2cafc4 Initial PGP support (decrypt)
Mikael Berthe <mikael@lilotux.net>
parents: 993
diff changeset
   298
  }
2196
8811fe9d6ef0 Improve support for GnuPG v2+
Mikael Berthe <mikael@lilotux.net>
parents: 2184
diff changeset
   299
  gpg_set_passphrase(pp);
1042
8a395c2cafc4 Initial PGP support (decrypt)
Mikael Berthe <mikael@lilotux.net>
parents: 993
diff changeset
   300
  // Erase password from the settings array
8a395c2cafc4 Initial PGP support (decrypt)
Mikael Berthe <mikael@lilotux.net>
parents: 993
diff changeset
   301
  if (pp) {
8a395c2cafc4 Initial PGP support (decrypt)
Mikael Berthe <mikael@lilotux.net>
parents: 993
diff changeset
   302
    memset((char*)pp, 0, strlen(pp));
8a395c2cafc4 Initial PGP support (decrypt)
Mikael Berthe <mikael@lilotux.net>
parents: 993
diff changeset
   303
    if (typed_passwd)
8a395c2cafc4 Initial PGP support (decrypt)
Mikael Berthe <mikael@lilotux.net>
parents: 993
diff changeset
   304
      g_free(typed_passwd);
8a395c2cafc4 Initial PGP support (decrypt)
Mikael Berthe <mikael@lilotux.net>
parents: 993
diff changeset
   305
    else
8a395c2cafc4 Initial PGP support (decrypt)
Mikael Berthe <mikael@lilotux.net>
parents: 993
diff changeset
   306
      settings_set(SETTINGS_TYPE_OPTION, "pgp_passphrase", NULL);
8a395c2cafc4 Initial PGP support (decrypt)
Mikael Berthe <mikael@lilotux.net>
parents: 993
diff changeset
   307
  }
8a395c2cafc4 Initial PGP support (decrypt)
Mikael Berthe <mikael@lilotux.net>
parents: 993
diff changeset
   308
  if (!pgp_agent && pk && pp && gpg_test_passphrase()) {
8a395c2cafc4 Initial PGP support (decrypt)
Mikael Berthe <mikael@lilotux.net>
parents: 993
diff changeset
   309
    // Let's check the pasphrase
8a395c2cafc4 Initial PGP support (decrypt)
Mikael Berthe <mikael@lilotux.net>
parents: 993
diff changeset
   310
    int i;
1313
d1d12a09b04a Make passphrase entry retries customizable (suggested by Till Maas)
Mikael Berthe <mikael@lilotux.net>
parents: 1311
diff changeset
   311
    for (i = 1; retries < 0 || i <= retries; i++) {
1799
e73cd9377a4e Better UI message for password prompt
Mikael Berthe <mikael@lilotux.net>
parents: 1780
diff changeset
   312
      typed_passwd = ask_password("your PGP passphrase"); // Ask again...
1042
8a395c2cafc4 Initial PGP support (decrypt)
Mikael Berthe <mikael@lilotux.net>
parents: 993
diff changeset
   313
      if (typed_passwd) {
8a395c2cafc4 Initial PGP support (decrypt)
Mikael Berthe <mikael@lilotux.net>
parents: 993
diff changeset
   314
        gpg_set_passphrase(typed_passwd);
8a395c2cafc4 Initial PGP support (decrypt)
Mikael Berthe <mikael@lilotux.net>
parents: 993
diff changeset
   315
        memset(typed_passwd, 0, strlen(typed_passwd));
8a395c2cafc4 Initial PGP support (decrypt)
Mikael Berthe <mikael@lilotux.net>
parents: 993
diff changeset
   316
        g_free(typed_passwd);
8a395c2cafc4 Initial PGP support (decrypt)
Mikael Berthe <mikael@lilotux.net>
parents: 993
diff changeset
   317
      }
8a395c2cafc4 Initial PGP support (decrypt)
Mikael Berthe <mikael@lilotux.net>
parents: 993
diff changeset
   318
      if (!gpg_test_passphrase())
8a395c2cafc4 Initial PGP support (decrypt)
Mikael Berthe <mikael@lilotux.net>
parents: 993
diff changeset
   319
        break; // Ok
8a395c2cafc4 Initial PGP support (decrypt)
Mikael Berthe <mikael@lilotux.net>
parents: 993
diff changeset
   320
    }
1313
d1d12a09b04a Make passphrase entry retries customizable (suggested by Till Maas)
Mikael Berthe <mikael@lilotux.net>
parents: 1311
diff changeset
   321
    if (i > retries)
1042
8a395c2cafc4 Initial PGP support (decrypt)
Mikael Berthe <mikael@lilotux.net>
parents: 993
diff changeset
   322
      pgp_invalid = TRUE;
8a395c2cafc4 Initial PGP support (decrypt)
Mikael Berthe <mikael@lilotux.net>
parents: 993
diff changeset
   323
  }
8a395c2cafc4 Initial PGP support (decrypt)
Mikael Berthe <mikael@lilotux.net>
parents: 993
diff changeset
   324
  if (pgp_invalid)
8a395c2cafc4 Initial PGP support (decrypt)
Mikael Berthe <mikael@lilotux.net>
parents: 993
diff changeset
   325
    scr_LogPrint(LPRINT_LOGNORM, "WARNING: PGP key/pass invalid");
8a395c2cafc4 Initial PGP support (decrypt)
Mikael Berthe <mikael@lilotux.net>
parents: 993
diff changeset
   326
#else /* not HAVE_GPGME */
8a395c2cafc4 Initial PGP support (decrypt)
Mikael Berthe <mikael@lilotux.net>
parents: 993
diff changeset
   327
  scr_LogPrint(LPRINT_LOGNORM, "WARNING: not compiled with PGP support");
8a395c2cafc4 Initial PGP support (decrypt)
Mikael Berthe <mikael@lilotux.net>
parents: 993
diff changeset
   328
#endif /* HAVE_GPGME */
8a395c2cafc4 Initial PGP support (decrypt)
Mikael Berthe <mikael@lilotux.net>
parents: 993
diff changeset
   329
}
8a395c2cafc4 Initial PGP support (decrypt)
Mikael Berthe <mikael@lilotux.net>
parents: 993
diff changeset
   330
1359
7daf906fbcdc The command /quit can be used in bindings, hooks and sourced files
Mikael Berthe <mikael@lilotux.net>
parents: 1313
diff changeset
   331
void mcabber_set_terminate_ui(void)
7daf906fbcdc The command /quit can be used in bindings, hooks and sourced files
Mikael Berthe <mikael@lilotux.net>
parents: 1313
diff changeset
   332
{
7daf906fbcdc The command /quit can be used in bindings, hooks and sourced files
Mikael Berthe <mikael@lilotux.net>
parents: 1313
diff changeset
   333
  terminate_ui = TRUE;
7daf906fbcdc The command /quit can be used in bindings, hooks and sourced files
Mikael Berthe <mikael@lilotux.net>
parents: 1313
diff changeset
   334
}
7daf906fbcdc The command /quit can be used in bindings, hooks and sourced files
Mikael Berthe <mikael@lilotux.net>
parents: 1313
diff changeset
   335
1653
fca9a4c17432 Improve UI latency and CPU usage
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1643
diff changeset
   336
typedef struct {
fca9a4c17432 Improve UI latency and CPU usage
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1643
diff changeset
   337
  GSource source;
fca9a4c17432 Improve UI latency and CPU usage
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1643
diff changeset
   338
  GPollFD pollfd;
fca9a4c17432 Improve UI latency and CPU usage
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1643
diff changeset
   339
} mcabber_source_t;
fca9a4c17432 Improve UI latency and CPU usage
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1643
diff changeset
   340
fca9a4c17432 Improve UI latency and CPU usage
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1643
diff changeset
   341
static gboolean mcabber_source_prepare(GSource *source, gint *timeout)
fca9a4c17432 Improve UI latency and CPU usage
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1643
diff changeset
   342
{
fca9a4c17432 Improve UI latency and CPU usage
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1643
diff changeset
   343
  *timeout = -1;
fca9a4c17432 Improve UI latency and CPU usage
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1643
diff changeset
   344
  return FALSE;
fca9a4c17432 Improve UI latency and CPU usage
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1643
diff changeset
   345
}
fca9a4c17432 Improve UI latency and CPU usage
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1643
diff changeset
   346
fca9a4c17432 Improve UI latency and CPU usage
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1643
diff changeset
   347
static gboolean mcabber_source_check(GSource *source)
fca9a4c17432 Improve UI latency and CPU usage
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1643
diff changeset
   348
{
fca9a4c17432 Improve UI latency and CPU usage
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1643
diff changeset
   349
  mcabber_source_t *mc_source = (mcabber_source_t *) source;
fca9a4c17432 Improve UI latency and CPU usage
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1643
diff changeset
   350
  gushort revents = mc_source->pollfd.revents;
fca9a4c17432 Improve UI latency and CPU usage
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1643
diff changeset
   351
  if (revents)
fca9a4c17432 Improve UI latency and CPU usage
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1643
diff changeset
   352
    return TRUE;
fca9a4c17432 Improve UI latency and CPU usage
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1643
diff changeset
   353
  return FALSE;
fca9a4c17432 Improve UI latency and CPU usage
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1643
diff changeset
   354
}
fca9a4c17432 Improve UI latency and CPU usage
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1643
diff changeset
   355
1657
c4ee6d99f75b Fix resize event handling issue (reported by mvuets)
Mikael Berthe <mikael@lilotux.net>
parents: 1653
diff changeset
   356
static gboolean keyboard_activity(void)
1598
a087125d8fc8 Replace libjabber with loudmouth
franky
parents: 1597
diff changeset
   357
{
2337
ffd0e57e9563 Defined types shall end with "_t"
franky
parents: 2292
diff changeset
   358
  keycode_t kcode;
1598
a087125d8fc8 Replace libjabber with loudmouth
franky
parents: 1597
diff changeset
   359
a087125d8fc8 Replace libjabber with loudmouth
franky
parents: 1597
diff changeset
   360
  if (terminate_ui) {
a087125d8fc8 Replace libjabber with loudmouth
franky
parents: 1597
diff changeset
   361
    return FALSE;
a087125d8fc8 Replace libjabber with loudmouth
franky
parents: 1597
diff changeset
   362
  }
1780
e4378fbab5d7 Major API cleanup - bump API to 4
Mikael Berthe <mikael@lilotux.net>
parents: 1764
diff changeset
   363
  scr_do_update();
e4378fbab5d7 Major API cleanup - bump API to 4
Mikael Berthe <mikael@lilotux.net>
parents: 1764
diff changeset
   364
  scr_getch(&kcode);
1598
a087125d8fc8 Replace libjabber with loudmouth
franky
parents: 1597
diff changeset
   365
1618
9296987856d9 Process keycodes faster
franky
parents: 1610
diff changeset
   366
  while (kcode.value != ERR) {
1780
e4378fbab5d7 Major API cleanup - bump API to 4
Mikael Berthe <mikael@lilotux.net>
parents: 1764
diff changeset
   367
    scr_process_key(kcode);
e4378fbab5d7 Major API cleanup - bump API to 4
Mikael Berthe <mikael@lilotux.net>
parents: 1764
diff changeset
   368
    scr_getch(&kcode);
1618
9296987856d9 Process keycodes faster
franky
parents: 1610
diff changeset
   369
  }
1780
e4378fbab5d7 Major API cleanup - bump API to 4
Mikael Berthe <mikael@lilotux.net>
parents: 1764
diff changeset
   370
  scr_check_auto_away(FALSE);
1598
a087125d8fc8 Replace libjabber with loudmouth
franky
parents: 1597
diff changeset
   371
a087125d8fc8 Replace libjabber with loudmouth
franky
parents: 1597
diff changeset
   372
  return TRUE;
a087125d8fc8 Replace libjabber with loudmouth
franky
parents: 1597
diff changeset
   373
}
a087125d8fc8 Replace libjabber with loudmouth
franky
parents: 1597
diff changeset
   374
1657
c4ee6d99f75b Fix resize event handling issue (reported by mvuets)
Mikael Berthe <mikael@lilotux.net>
parents: 1653
diff changeset
   375
static gboolean mcabber_source_dispatch(GSource *source, GSourceFunc callback,
c4ee6d99f75b Fix resize event handling issue (reported by mvuets)
Mikael Berthe <mikael@lilotux.net>
parents: 1653
diff changeset
   376
                                        gpointer udata) {
c4ee6d99f75b Fix resize event handling issue (reported by mvuets)
Mikael Berthe <mikael@lilotux.net>
parents: 1653
diff changeset
   377
  return keyboard_activity();
c4ee6d99f75b Fix resize event handling issue (reported by mvuets)
Mikael Berthe <mikael@lilotux.net>
parents: 1653
diff changeset
   378
}
c4ee6d99f75b Fix resize event handling issue (reported by mvuets)
Mikael Berthe <mikael@lilotux.net>
parents: 1653
diff changeset
   379
1653
fca9a4c17432 Improve UI latency and CPU usage
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1643
diff changeset
   380
static GSourceFuncs mcabber_source_funcs = {
fca9a4c17432 Improve UI latency and CPU usage
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1643
diff changeset
   381
  mcabber_source_prepare,
fca9a4c17432 Improve UI latency and CPU usage
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1643
diff changeset
   382
  mcabber_source_check,
fca9a4c17432 Improve UI latency and CPU usage
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1643
diff changeset
   383
  mcabber_source_dispatch,
fca9a4c17432 Improve UI latency and CPU usage
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1643
diff changeset
   384
  NULL,
fca9a4c17432 Improve UI latency and CPU usage
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1643
diff changeset
   385
  NULL,
fca9a4c17432 Improve UI latency and CPU usage
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1643
diff changeset
   386
  NULL
fca9a4c17432 Improve UI latency and CPU usage
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1643
diff changeset
   387
};
fca9a4c17432 Improve UI latency and CPU usage
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1643
diff changeset
   388
24
e88b15cbf2de [/trunk] Changeset 40 by mikael
mikael
parents:
diff changeset
   389
int main(int argc, char **argv)
e88b15cbf2de [/trunk] Changeset 40 by mikael
mikael
parents:
diff changeset
   390
{
169
0ed6099b5a54 [/trunk] Changeset 181 by mikael
mikael
parents: 165
diff changeset
   391
  char *configFile = NULL;
281
f562b9af2de7 Add "const" specifier in prototypes
Mikael Berthe <mikael@lilotux.net>
parents: 279
diff changeset
   392
  const char *optstring;
177
a51ce78a0e2a [/trunk] Changeset 189 by mikael
mikael
parents: 170
diff changeset
   393
  int optval, optval2;
333
db5bebe96c89 New config. file parsing
Mikael Berthe <mikael@lilotux.net>
parents: 322
diff changeset
   394
  int ret;
24
e88b15cbf2de [/trunk] Changeset 40 by mikael
mikael
parents:
diff changeset
   395
e88b15cbf2de [/trunk] Changeset 40 by mikael
mikael
parents:
diff changeset
   396
  credits();
e88b15cbf2de [/trunk] Changeset 40 by mikael
mikael
parents:
diff changeset
   397
e88b15cbf2de [/trunk] Changeset 40 by mikael
mikael
parents:
diff changeset
   398
  signal(SIGTERM, sig_handler);
312
f0b7ff2df7e8 Ctrl-C does not terminate mcabber
Mikael Berthe <mikael@lilotux.net>
parents: 307
diff changeset
   399
  signal(SIGINT,  sig_handler);
2071
a5acc2a1af53 Adds SIGHUP to signal handling.
Dominik George <nik@naturalnet.de>
parents: 2042
diff changeset
   400
  signal(SIGHUP,  sig_handler);
163
a8f7dc0a56cb [/trunk] Changeset 175 by mikael
mikael
parents: 160
diff changeset
   401
  signal(SIGCHLD, sig_handler);
1454
6b98dc22946d Add optional SIGWINCH handler (Markus Hennecke)
Mikael Berthe <mikael@lilotux.net>
parents: 1448
diff changeset
   402
#ifdef USE_SIGWINCH
6b98dc22946d Add optional SIGWINCH handler (Markus Hennecke)
Mikael Berthe <mikael@lilotux.net>
parents: 1448
diff changeset
   403
  signal(SIGWINCH, sig_handler);
6b98dc22946d Add optional SIGWINCH handler (Markus Hennecke)
Mikael Berthe <mikael@lilotux.net>
parents: 1448
diff changeset
   404
#endif
413
f7e4b0424081 Ignore SIGPIPE
Mikael Berthe <mikael@lilotux.net>
parents: 404
diff changeset
   405
  signal(SIGPIPE, SIG_IGN);
24
e88b15cbf2de [/trunk] Changeset 40 by mikael
mikael
parents:
diff changeset
   406
77
32f54ad6d729 [/trunk] Changeset 91 by mikael
mikael
parents: 70
diff changeset
   407
  /* Parse command line options */
24
e88b15cbf2de [/trunk] Changeset 40 by mikael
mikael
parents:
diff changeset
   408
  while (1) {
1259
c5c09f8f60b0 Change command line option -v to -V
Mikael Berthe <mikael@lilotux.net>
parents: 1257
diff changeset
   409
    int c = getopt(argc, argv, "hVf:");
24
e88b15cbf2de [/trunk] Changeset 40 by mikael
mikael
parents:
diff changeset
   410
    if (c == -1) {
e88b15cbf2de [/trunk] Changeset 40 by mikael
mikael
parents:
diff changeset
   411
      break;
e88b15cbf2de [/trunk] Changeset 40 by mikael
mikael
parents:
diff changeset
   412
    } else
e88b15cbf2de [/trunk] Changeset 40 by mikael
mikael
parents:
diff changeset
   413
      switch (c) {
e88b15cbf2de [/trunk] Changeset 40 by mikael
mikael
parents:
diff changeset
   414
      case 'h':
1256
ea679e3598a9 Don't start when command line options are wrong
Mikael Berthe <mikael@lilotux.net>
parents: 1253
diff changeset
   415
      case '?':
1259
c5c09f8f60b0 Change command line option -v to -V
Mikael Berthe <mikael@lilotux.net>
parents: 1257
diff changeset
   416
        printf("Usage: %s [-h|-V|-f mcabberrc_file]\n\n", argv[0]);
1256
ea679e3598a9 Don't start when command line options are wrong
Mikael Berthe <mikael@lilotux.net>
parents: 1253
diff changeset
   417
        return (c == 'h' ? 0 : -1);
1259
c5c09f8f60b0 Change command line option -v to -V
Mikael Berthe <mikael@lilotux.net>
parents: 1257
diff changeset
   418
      case 'V':
1257
05dc45e7c7bb Add command line option -v
Mikael Berthe <mikael@lilotux.net>
parents: 1256
diff changeset
   419
        compile_options();
05dc45e7c7bb Add command line option -v
Mikael Berthe <mikael@lilotux.net>
parents: 1256
diff changeset
   420
        return 0;
24
e88b15cbf2de [/trunk] Changeset 40 by mikael
mikael
parents:
diff changeset
   421
      case 'f':
1241
3a4018f18bdf Cosmetics
Mikael Berthe <mikael@lilotux.net>
parents: 1238
diff changeset
   422
        configFile = g_strdup(optarg);
3a4018f18bdf Cosmetics
Mikael Berthe <mikael@lilotux.net>
parents: 1238
diff changeset
   423
        break;
24
e88b15cbf2de [/trunk] Changeset 40 by mikael
mikael
parents:
diff changeset
   424
      }
e88b15cbf2de [/trunk] Changeset 40 by mikael
mikael
parents:
diff changeset
   425
  }
e88b15cbf2de [/trunk] Changeset 40 by mikael
mikael
parents:
diff changeset
   426
1256
ea679e3598a9 Don't start when command line options are wrong
Mikael Berthe <mikael@lilotux.net>
parents: 1253
diff changeset
   427
  if (optind < argc) {
1259
c5c09f8f60b0 Change command line option -v to -V
Mikael Berthe <mikael@lilotux.net>
parents: 1257
diff changeset
   428
    fprintf(stderr, "Usage: %s [-h|-V|-f mcabberrc_file]\n\n", argv[0]);
1256
ea679e3598a9 Don't start when command line options are wrong
Mikael Berthe <mikael@lilotux.net>
parents: 1253
diff changeset
   429
    return -1;
ea679e3598a9 Don't start when command line options are wrong
Mikael Berthe <mikael@lilotux.net>
parents: 1253
diff changeset
   430
  }
ea679e3598a9 Don't start when command line options are wrong
Mikael Berthe <mikael@lilotux.net>
parents: 1253
diff changeset
   431
1176
547a8ca7c1a8 Move init_bindings() to screen.c, with a few updates
Mikael Berthe <mikael@lilotux.net>
parents: 1173
diff changeset
   432
  /* Initialize command system, roster and default key bindings */
2042
0cb8ea02e472 Make completion sorting order configurable
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1995
diff changeset
   433
  compl_init_system();
333
db5bebe96c89 New config. file parsing
Mikael Berthe <mikael@lilotux.net>
parents: 322
diff changeset
   434
  cmd_init();
848
a9161d2dc414 Introduce special buffer stuff
Mikael Berthe <mikael@lilotux.net>
parents: 815
diff changeset
   435
  roster_init();
1065
230dca34dbea Extand pgp_data structure
Mikael Berthe <mikael@lilotux.net>
parents: 1058
diff changeset
   436
  settings_init();
1176
547a8ca7c1a8 Move init_bindings() to screen.c, with a few updates
Mikael Berthe <mikael@lilotux.net>
parents: 1173
diff changeset
   437
  scr_init_bindings();
2101
f56c214a19dc Add a guard for 'attention_char'
Mikael Berthe <mikael@lilotux.net>
parents: 2071
diff changeset
   438
  scr_init_settings();
1600
c5ee395fbc8c Updated Entity Capabilities support (XEP-0115)
franky
parents: 1599
diff changeset
   439
  caps_init();
1735
5093b5ca1572 New modules loading scheme
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1729
diff changeset
   440
#ifdef MODULES_ENABLE
5093b5ca1572 New modules loading scheme
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1729
diff changeset
   441
  modules_init();
5093b5ca1572 New modules loading scheme
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1729
diff changeset
   442
#endif
779
057ffe7c43dc Initialize locale charset earlier
Mikael Berthe <mikael@lilotux.net>
parents: 777
diff changeset
   443
  /* Initialize charset */
1780
e4378fbab5d7 Major API cleanup - bump API to 4
Mikael Berthe <mikael@lilotux.net>
parents: 1764
diff changeset
   444
  scr_init_locale_charset();
e4378fbab5d7 Major API cleanup - bump API to 4
Mikael Berthe <mikael@lilotux.net>
parents: 1764
diff changeset
   445
  ut_init_debug();
1678
e489ead6574a New help system
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1674
diff changeset
   446
  help_init();
333
db5bebe96c89 New config. file parsing
Mikael Berthe <mikael@lilotux.net>
parents: 322
diff changeset
   447
24
e88b15cbf2de [/trunk] Changeset 40 by mikael
mikael
parents:
diff changeset
   448
  /* Parsing config file... */
1192
7b8765c10abb New command: /source
Mikael Berthe <mikael@lilotux.net>
parents: 1179
diff changeset
   449
  ret = cfg_read_file(configFile, TRUE);
374
bd5638c21834 Improve logging system (traces)
Mikael Berthe <mikael@lilotux.net>
parents: 364
diff changeset
   450
  /* free() configFile if it has been allocated during options parsing */
774
46304b773a44 Remove useless checks before g_free() calls
Mikael Berthe <mikael@lilotux.net>
parents: 772
diff changeset
   451
  g_free(configFile);
333
db5bebe96c89 New config. file parsing
Mikael Berthe <mikael@lilotux.net>
parents: 322
diff changeset
   452
  /* Leave if there was an error in the config. file */
872
a0ddc43b421e Don't stop when there is no configuration file
Mikael Berthe <mikael@lilotux.net>
parents: 855
diff changeset
   453
  if (ret == -2)
333
db5bebe96c89 New config. file parsing
Mikael Berthe <mikael@lilotux.net>
parents: 322
diff changeset
   454
    exit(EXIT_FAILURE);
24
e88b15cbf2de [/trunk] Changeset 40 by mikael
mikael
parents:
diff changeset
   455
1894
c3271ac96173 Display the JID before attempting to connect
Mikael Berthe <mikael@lilotux.net>
parents: 1811
diff changeset
   456
  /* Display configuration settings */
c3271ac96173 Display the JID before attempting to connect
Mikael Berthe <mikael@lilotux.net>
parents: 1811
diff changeset
   457
  {
c3271ac96173 Display the JID before attempting to connect
Mikael Berthe <mikael@lilotux.net>
parents: 1811
diff changeset
   458
    const char *p;
c3271ac96173 Display the JID before attempting to connect
Mikael Berthe <mikael@lilotux.net>
parents: 1811
diff changeset
   459
    if ((p = settings_opt_get("server")) != NULL)
c3271ac96173 Display the JID before attempting to connect
Mikael Berthe <mikael@lilotux.net>
parents: 1811
diff changeset
   460
      scr_log_print(LPRINT_NORMAL, "Server: %s", p);
1900
5dc0fd8225e3 Display a warning when the configuration file hasn't been updated
Mikael Berthe <mikael@lilotux.net>
parents: 1897
diff changeset
   461
    if ((p = settings_opt_get("jid")) != NULL) {
1894
c3271ac96173 Display the JID before attempting to connect
Mikael Berthe <mikael@lilotux.net>
parents: 1811
diff changeset
   462
      scr_log_print(LPRINT_NORMAL, "User JID: %s", p);
1916
a87ac75872fe Display a warning when the option ssl_verify is still used
Mikael Berthe <mikael@lilotux.net>
parents: 1901
diff changeset
   463
    }
1894
c3271ac96173 Display the JID before attempting to connect
Mikael Berthe <mikael@lilotux.net>
parents: 1811
diff changeset
   464
  }
c3271ac96173 Display the JID before attempting to connect
Mikael Berthe <mikael@lilotux.net>
parents: 1811
diff changeset
   465
306
b2d11b11675f Fix interactive password prompt
Mikael Berthe <mikael@lilotux.net>
parents: 300
diff changeset
   466
  /* If no password is stored, we ask for it before entering
872
a0ddc43b421e Don't stop when there is no configuration file
Mikael Berthe <mikael@lilotux.net>
parents: 855
diff changeset
   467
     ncurses mode -- unless the username is unknown. */
1610
6db9f403f707 Replace 'username' with 'jid' in the configuration file
Mikael Berthe <mikael@lilotux.net>
parents: 1607
diff changeset
   468
  if (settings_opt_get("jid") && !settings_opt_get("password")) {
2173
cf08c3b630af Tweak the previous change...
Mikael Berthe <mikael@lilotux.net>
parents: 2172
diff changeset
   469
    const char *pass_eval = settings_opt_get("password_eval");
cf08c3b630af Tweak the previous change...
Mikael Berthe <mikael@lilotux.net>
parents: 2172
diff changeset
   470
    if (pass_eval) {
cf08c3b630af Tweak the previous change...
Mikael Berthe <mikael@lilotux.net>
parents: 2172
diff changeset
   471
      int status = 0;
cf08c3b630af Tweak the previous change...
Mikael Berthe <mikael@lilotux.net>
parents: 2172
diff changeset
   472
      char *pwd = password_eval(pass_eval, &status);
cf08c3b630af Tweak the previous change...
Mikael Berthe <mikael@lilotux.net>
parents: 2172
diff changeset
   473
      if (status == 0 && pwd) {
cf08c3b630af Tweak the previous change...
Mikael Berthe <mikael@lilotux.net>
parents: 2172
diff changeset
   474
        settings_set(SETTINGS_TYPE_OPTION, "password", pwd);
2172
06669fc1810c Add support for using external password managers
Christian Burkert <post@cburkert.de>
parents: 2134
diff changeset
   475
      }
2173
cf08c3b630af Tweak the previous change...
Mikael Berthe <mikael@lilotux.net>
parents: 2172
diff changeset
   476
      g_free(pwd);
cf08c3b630af Tweak the previous change...
Mikael Berthe <mikael@lilotux.net>
parents: 2172
diff changeset
   477
    }
cf08c3b630af Tweak the previous change...
Mikael Berthe <mikael@lilotux.net>
parents: 2172
diff changeset
   478
    // If the password is still unset, ask the user...
cf08c3b630af Tweak the previous change...
Mikael Berthe <mikael@lilotux.net>
parents: 2172
diff changeset
   479
    if (!settings_opt_get("password")) {
2172
06669fc1810c Add support for using external password managers
Christian Burkert <post@cburkert.de>
parents: 2134
diff changeset
   480
      char *pwd = ask_password("your Jabber password");
06669fc1810c Add support for using external password managers
Christian Burkert <post@cburkert.de>
parents: 2134
diff changeset
   481
      settings_set(SETTINGS_TYPE_OPTION, "password", pwd);
06669fc1810c Add support for using external password managers
Christian Burkert <post@cburkert.de>
parents: 2134
diff changeset
   482
      g_free(pwd);
06669fc1810c Add support for using external password managers
Christian Burkert <post@cburkert.de>
parents: 2134
diff changeset
   483
    }
415
5692c3a13202 Display the server name/IP before asking for password
Mikael Berthe <mikael@lilotux.net>
parents: 413
diff changeset
   484
  }
24
e88b15cbf2de [/trunk] Changeset 40 by mikael
mikael
parents:
diff changeset
   485
1042
8a395c2cafc4 Initial PGP support (decrypt)
Mikael Berthe <mikael@lilotux.net>
parents: 993
diff changeset
   486
  /* Initialize PGP system
8a395c2cafc4 Initial PGP support (decrypt)
Mikael Berthe <mikael@lilotux.net>
parents: 993
diff changeset
   487
     We do it before ncurses initialization because we may need to request
8a395c2cafc4 Initial PGP support (decrypt)
Mikael Berthe <mikael@lilotux.net>
parents: 993
diff changeset
   488
     a passphrase. */
8a395c2cafc4 Initial PGP support (decrypt)
Mikael Berthe <mikael@lilotux.net>
parents: 993
diff changeset
   489
  if (settings_opt_get_int("pgp"))
8a395c2cafc4 Initial PGP support (decrypt)
Mikael Berthe <mikael@lilotux.net>
parents: 993
diff changeset
   490
    main_init_pgp();
8a395c2cafc4 Initial PGP support (decrypt)
Mikael Berthe <mikael@lilotux.net>
parents: 993
diff changeset
   491
24
e88b15cbf2de [/trunk] Changeset 40 by mikael
mikael
parents:
diff changeset
   492
  /* Initialize N-Curses */
374
bd5638c21834 Improve logging system (traces)
Mikael Berthe <mikael@lilotux.net>
parents: 364
diff changeset
   493
  scr_LogPrint(LPRINT_DEBUG, "Initializing N-Curses...");
1780
e4378fbab5d7 Major API cleanup - bump API to 4
Mikael Berthe <mikael@lilotux.net>
parents: 1764
diff changeset
   494
  scr_init_curses();
e4378fbab5d7 Major API cleanup - bump API to 4
Mikael Berthe <mikael@lilotux.net>
parents: 1764
diff changeset
   495
  scr_draw_main_window(TRUE);
29
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents: 28
diff changeset
   496
279
f5dd437c057b Rewrite the settings system
Mikael Berthe <mikael@lilotux.net>
parents: 272
diff changeset
   497
  optval   = (settings_opt_get_int("logging") > 0);
f5dd437c057b Rewrite the settings system
Mikael Berthe <mikael@lilotux.net>
parents: 272
diff changeset
   498
  optval2  = (settings_opt_get_int("load_logs") > 0);
177
a51ce78a0e2a [/trunk] Changeset 189 by mikael
mikael
parents: 170
diff changeset
   499
  if (optval || optval2)
298
35cda94e570d Add /connect and /disconnect commands
Mikael Berthe <mikael@lilotux.net>
parents: 281
diff changeset
   500
    hlog_enable(optval, settings_opt_get("logging_dir"), optval2);
113
8ac67e951eab [/trunk] Changeset 127 by mikael
mikael
parents: 112
diff changeset
   501
1590
8d1bcc83ae32 Add support for spellchecking with Enchant (caolan)
Mikael Berthe <mikael@lilotux.net>
parents: 1545
diff changeset
   502
#if defined(WITH_ENCHANT) || defined(WITH_ASPELL)
8d1bcc83ae32 Add support for spellchecking with Enchant (caolan)
Mikael Berthe <mikael@lilotux.net>
parents: 1545
diff changeset
   503
  /* Initialize spelling */
8d1bcc83ae32 Add support for spellchecking with Enchant (caolan)
Mikael Berthe <mikael@lilotux.net>
parents: 1545
diff changeset
   504
  if (settings_opt_get_int("spell_enable")) {
1179
0f7e0346d9cb Add aspell support
entragian <entragian@o2.pl>
parents: 1176
diff changeset
   505
    spellcheck_init();
0f7e0346d9cb Add aspell support
entragian <entragian@o2.pl>
parents: 1176
diff changeset
   506
  }
0f7e0346d9cb Add aspell support
entragian <entragian@o2.pl>
parents: 1176
diff changeset
   507
#endif
0f7e0346d9cb Add aspell support
entragian <entragian@o2.pl>
parents: 1176
diff changeset
   508
279
f5dd437c057b Rewrite the settings system
Mikael Berthe <mikael@lilotux.net>
parents: 272
diff changeset
   509
  optstring = settings_opt_get("events_command");
f5dd437c057b Rewrite the settings system
Mikael Berthe <mikael@lilotux.net>
parents: 272
diff changeset
   510
  if (optstring)
160
44c6410b4845 [/trunk] Changeset 172 by mikael
mikael
parents: 156
diff changeset
   511
    hk_ext_cmd_init(optstring);
44c6410b4845 [/trunk] Changeset 172 by mikael
mikael
parents: 156
diff changeset
   512
1632
d29376ef424d Remove deprecated option ('hide_offline_buddies')
Mikael Berthe <mikael@lilotux.net>
parents: 1630
diff changeset
   513
  optstring = settings_opt_get("roster_display_filter");
d29376ef424d Remove deprecated option ('hide_offline_buddies')
Mikael Berthe <mikael@lilotux.net>
parents: 1630
diff changeset
   514
  if (optstring)
1780
e4378fbab5d7 Major API cleanup - bump API to 4
Mikael Berthe <mikael@lilotux.net>
parents: 1764
diff changeset
   515
    scr_roster_display(optstring);
1632
d29376ef424d Remove deprecated option ('hide_offline_buddies')
Mikael Berthe <mikael@lilotux.net>
parents: 1630
diff changeset
   516
  // Empty filter isn't allowed...
d29376ef424d Remove deprecated option ('hide_offline_buddies')
Mikael Berthe <mikael@lilotux.net>
parents: 1630
diff changeset
   517
  if (!buddylist_get_filter())
1780
e4378fbab5d7 Major API cleanup - bump API to 4
Mikael Berthe <mikael@lilotux.net>
parents: 1764
diff changeset
   518
    scr_roster_display("*");
87
f600615c490d [/trunk] Changeset 101 by mikael
mikael
parents: 81
diff changeset
   519
993
0759f4c7da68 Add option 'disable_chatstates'
Mikael Berthe <mikael@lilotux.net>
parents: 962
diff changeset
   520
  chatstates_disabled = settings_opt_get_int("disable_chatstates");
0759f4c7da68 Add option 'disable_chatstates'
Mikael Berthe <mikael@lilotux.net>
parents: 962
diff changeset
   521
1941
2256d0626730 Modularize fifo system (Myhailo Danylenko)
Mikael Berthe <mikael@lilotux.net>
parents: 1940
diff changeset
   522
#ifndef MODULES_ENABLE
1426
a64778f5f26b Implement FIFO named command pipe
Mikael Berthe <mikael@lilotux.net>
parents: 1425
diff changeset
   523
  /* Initialize FIFO named pipe */
1940
7eadf86039e6 Use guard for the fifo system (Myhailo Danylenko)
Mikael Berthe <mikael@lilotux.net>
parents: 1936
diff changeset
   524
  fifo_init();
1941
2256d0626730 Modularize fifo system (Myhailo Danylenko)
Mikael Berthe <mikael@lilotux.net>
parents: 1940
diff changeset
   525
#endif
1426
a64778f5f26b Implement FIFO named command pipe
Mikael Berthe <mikael@lilotux.net>
parents: 1425
diff changeset
   526
1437
071c8170b7de Add option 'statefile' to keep track of unread messages across restarts
Mikael Berthe <mikael@lilotux.net>
parents: 1426
diff changeset
   527
  /* Load previous roster state */
071c8170b7de Add option 'statefile' to keep track of unread messages across restarts
Mikael Berthe <mikael@lilotux.net>
parents: 1426
diff changeset
   528
  hlog_load_state();
071c8170b7de Add option 'statefile' to keep track of unread messages across restarts
Mikael Berthe <mikael@lilotux.net>
parents: 1426
diff changeset
   529
1653
fca9a4c17432 Improve UI latency and CPU usage
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1643
diff changeset
   530
  main_context = g_main_context_default();
1598
a087125d8fc8 Replace libjabber with loudmouth
franky
parents: 1597
diff changeset
   531
872
a0ddc43b421e Don't stop when there is no configuration file
Mikael Berthe <mikael@lilotux.net>
parents: 855
diff changeset
   532
  if (ret < 0) {
a0ddc43b421e Don't stop when there is no configuration file
Mikael Berthe <mikael@lilotux.net>
parents: 855
diff changeset
   533
    scr_LogPrint(LPRINT_NORMAL, "No configuration file has been found.");
1780
e4378fbab5d7 Major API cleanup - bump API to 4
Mikael Berthe <mikael@lilotux.net>
parents: 1764
diff changeset
   534
    scr_show_buddy_window();
872
a0ddc43b421e Don't stop when there is no configuration file
Mikael Berthe <mikael@lilotux.net>
parents: 855
diff changeset
   535
  } else {
a0ddc43b421e Don't stop when there is no configuration file
Mikael Berthe <mikael@lilotux.net>
parents: 855
diff changeset
   536
    /* Connection */
1810
8c2651fc217a Improve initial display when there is an error message
Mikael Berthe <mikael@lilotux.net>
parents: 1799
diff changeset
   537
    if (xmpp_connect())
8c2651fc217a Improve initial display when there is an error message
Mikael Berthe <mikael@lilotux.net>
parents: 1799
diff changeset
   538
      scr_show_buddy_window();
872
a0ddc43b421e Don't stop when there is no configuration file
Mikael Berthe <mikael@lilotux.net>
parents: 855
diff changeset
   539
  }
298
35cda94e570d Add /connect and /disconnect commands
Mikael Berthe <mikael@lilotux.net>
parents: 281
diff changeset
   540
1810
8c2651fc217a Improve initial display when there is an error message
Mikael Berthe <mikael@lilotux.net>
parents: 1799
diff changeset
   541
  // Initial drawing
8c2651fc217a Improve initial display when there is an error message
Mikael Berthe <mikael@lilotux.net>
parents: 1799
diff changeset
   542
  scr_draw_roster();
8c2651fc217a Improve initial display when there is an error message
Mikael Berthe <mikael@lilotux.net>
parents: 1799
diff changeset
   543
  scr_do_update();
8c2651fc217a Improve initial display when there is an error message
Mikael Berthe <mikael@lilotux.net>
parents: 1799
diff changeset
   544
1653
fca9a4c17432 Improve UI latency and CPU usage
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1643
diff changeset
   545
  { // add keypress processing source
fca9a4c17432 Improve UI latency and CPU usage
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1643
diff changeset
   546
    GSource *mc_source = g_source_new(&mcabber_source_funcs,
fca9a4c17432 Improve UI latency and CPU usage
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1643
diff changeset
   547
                                      sizeof(mcabber_source_t));
fca9a4c17432 Improve UI latency and CPU usage
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1643
diff changeset
   548
    GPollFD *mc_pollfd = &(((mcabber_source_t *)mc_source)->pollfd);
fca9a4c17432 Improve UI latency and CPU usage
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1643
diff changeset
   549
    mc_pollfd->fd = STDIN_FILENO;
fca9a4c17432 Improve UI latency and CPU usage
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1643
diff changeset
   550
    mc_pollfd->events = POLLIN|POLLERR|POLLPRI;
fca9a4c17432 Improve UI latency and CPU usage
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1643
diff changeset
   551
    mc_pollfd->revents = 0;
fca9a4c17432 Improve UI latency and CPU usage
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1643
diff changeset
   552
    g_source_add_poll(mc_source, mc_pollfd);
fca9a4c17432 Improve UI latency and CPU usage
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1643
diff changeset
   553
    g_source_attach(mc_source, main_context);
fca9a4c17432 Improve UI latency and CPU usage
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1643
diff changeset
   554
fca9a4c17432 Improve UI latency and CPU usage
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1643
diff changeset
   555
    scr_LogPrint(LPRINT_DEBUG, "Entering into main loop...");
112
edb5591e2e64 [/trunk] Changeset 126 by mikael
mikael
parents: 102
diff changeset
   556
1653
fca9a4c17432 Improve UI latency and CPU usage
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1643
diff changeset
   557
    while(!terminate_ui) {
1657
c4ee6d99f75b Fix resize event handling issue (reported by mvuets)
Mikael Berthe <mikael@lilotux.net>
parents: 1653
diff changeset
   558
      if (g_main_context_iteration(main_context, TRUE) == FALSE)
c4ee6d99f75b Fix resize event handling issue (reported by mvuets)
Mikael Berthe <mikael@lilotux.net>
parents: 1653
diff changeset
   559
        keyboard_activity();
2231
387cea2a1a81 Fix resizing with --enable-sigwinch
Mikael Berthe <mikael@lilotux.net>
parents: 2228
diff changeset
   560
#ifdef USE_SIGWINCH
387cea2a1a81 Fix resizing with --enable-sigwinch
Mikael Berthe <mikael@lilotux.net>
parents: 2228
diff changeset
   561
      if (sigwinch) {
387cea2a1a81 Fix resizing with --enable-sigwinch
Mikael Berthe <mikael@lilotux.net>
parents: 2228
diff changeset
   562
        sigwinch_resize();
387cea2a1a81 Fix resizing with --enable-sigwinch
Mikael Berthe <mikael@lilotux.net>
parents: 2228
diff changeset
   563
        sigwinch = FALSE;
387cea2a1a81 Fix resizing with --enable-sigwinch
Mikael Berthe <mikael@lilotux.net>
parents: 2228
diff changeset
   564
      }
387cea2a1a81 Fix resizing with --enable-sigwinch
Mikael Berthe <mikael@lilotux.net>
parents: 2228
diff changeset
   565
#endif
2292
f181418db215 Replace global variable update_roster with scr_update_roster()
franky
parents: 2288
diff changeset
   566
      scr_draw_roster();
2288
ece02eb9c81d Backed out changeset 1bb9002801e5
Mikael Berthe <mikael@lilotux.net>
parents: 2281
diff changeset
   567
      scr_do_update();
1653
fca9a4c17432 Improve UI latency and CPU usage
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1643
diff changeset
   568
    }
fca9a4c17432 Improve UI latency and CPU usage
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1643
diff changeset
   569
fca9a4c17432 Improve UI latency and CPU usage
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1643
diff changeset
   570
    g_source_destroy(mc_source);
fca9a4c17432 Improve UI latency and CPU usage
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1643
diff changeset
   571
    g_source_unref(mc_source);
fca9a4c17432 Improve UI latency and CPU usage
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1643
diff changeset
   572
  }
24
e88b15cbf2de [/trunk] Changeset 40 by mikael
mikael
parents:
diff changeset
   573
1685
1342df44c814 Improved events interface
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1678
diff changeset
   574
  evs_deinit();
1607
14690e624e9d Add modules
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1600
diff changeset
   575
#ifdef MODULES_ENABLE
1735
5093b5ca1572 New modules loading scheme
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1729
diff changeset
   576
  modules_deinit();
1607
14690e624e9d Add modules
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1600
diff changeset
   577
#endif
1941
2256d0626730 Modularize fifo system (Myhailo Danylenko)
Mikael Berthe <mikael@lilotux.net>
parents: 1940
diff changeset
   578
#ifndef MODULES_ENABLE
1426
a64778f5f26b Implement FIFO named command pipe
Mikael Berthe <mikael@lilotux.net>
parents: 1425
diff changeset
   579
  fifo_deinit();
1941
2256d0626730 Modularize fifo system (Myhailo Danylenko)
Mikael Berthe <mikael@lilotux.net>
parents: 1940
diff changeset
   580
#endif
1299
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents: 1259
diff changeset
   581
#ifdef HAVE_LIBOTR
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents: 1259
diff changeset
   582
  otr_terminate();
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents: 1259
diff changeset
   583
#endif
1598
a087125d8fc8 Replace libjabber with loudmouth
franky
parents: 1597
diff changeset
   584
  xmpp_disconnect();
1042
8a395c2cafc4 Initial PGP support (decrypt)
Mikael Berthe <mikael@lilotux.net>
parents: 993
diff changeset
   585
#ifdef HAVE_GPGME
8a395c2cafc4 Initial PGP support (decrypt)
Mikael Berthe <mikael@lilotux.net>
parents: 993
diff changeset
   586
  gpg_terminate();
8a395c2cafc4 Initial PGP support (decrypt)
Mikael Berthe <mikael@lilotux.net>
parents: 993
diff changeset
   587
#endif
1590
8d1bcc83ae32 Add support for spellchecking with Enchant (caolan)
Mikael Berthe <mikael@lilotux.net>
parents: 1545
diff changeset
   588
#if defined(WITH_ENCHANT) || defined(WITH_ASPELL)
8d1bcc83ae32 Add support for spellchecking with Enchant (caolan)
Mikael Berthe <mikael@lilotux.net>
parents: 1545
diff changeset
   589
  /* Deinitialize spelling */
8d1bcc83ae32 Add support for spellchecking with Enchant (caolan)
Mikael Berthe <mikael@lilotux.net>
parents: 1545
diff changeset
   590
  if (settings_opt_get_int("spell_enable"))
1179
0f7e0346d9cb Add aspell support
entragian <entragian@o2.pl>
parents: 1176
diff changeset
   591
    spellcheck_deinit();
0f7e0346d9cb Add aspell support
entragian <entragian@o2.pl>
parents: 1176
diff changeset
   592
#endif
1936
9e6e53821fb3 Do not terminate ncurses too early
Mikael Berthe <mikael@lilotux.net>
parents: 1922
diff changeset
   593
9e6e53821fb3 Do not terminate ncurses too early
Mikael Berthe <mikael@lilotux.net>
parents: 1922
diff changeset
   594
  scr_terminate_curses();
1437
071c8170b7de Add option 'statefile' to keep track of unread messages across restarts
Mikael Berthe <mikael@lilotux.net>
parents: 1426
diff changeset
   595
  /* Save pending message state */
071c8170b7de Add option 'statefile' to keep track of unread messages across restarts
Mikael Berthe <mikael@lilotux.net>
parents: 1426
diff changeset
   596
  hlog_save_state();
1600
c5ee395fbc8c Updated Entity Capabilities support (XEP-0115)
franky
parents: 1599
diff changeset
   597
  caps_free();
2339
7f11a567d236 Implemented settings_free()
franky
parents: 2337
diff changeset
   598
  settings_free();
24
e88b15cbf2de [/trunk] Changeset 40 by mikael
mikael
parents:
diff changeset
   599
961
95659cf9ea1a Display mcabber version in the status window
Mikael Berthe <mikael@lilotux.net>
parents: 955
diff changeset
   600
  printf("\n\nThanks for using mcabber!\n");
24
e88b15cbf2de [/trunk] Changeset 40 by mikael
mikael
parents:
diff changeset
   601
e88b15cbf2de [/trunk] Changeset 40 by mikael
mikael
parents:
diff changeset
   602
  return 0;
e88b15cbf2de [/trunk] Changeset 40 by mikael
mikael
parents:
diff changeset
   603
}
576
8b3db0b555a1 Add Vim modelines
Mikael Berthe <mikael@lilotux.net>
parents: 542
diff changeset
   604
1811
e6d355e50d7a Update Vim modelines
Mikael Berthe <mikael@lilotux.net>
parents: 1810
diff changeset
   605
/* vim: set expandtab cindent cinoptions=>2\:2(0 sw=2 ts=2:  For Vim users... */