Mercurial > hg
annotate mcabber/src/main.c @ 1500:0803c0bd8b76
Previous fix was incomplete
author | Mikael Berthe <mikael@lilotux.net> |
---|---|
date | Tue, 22 Jul 2008 23:07:58 +0200 |
parents | 35020a2ed115 |
children | 29c505d43b3e |
rev | line source |
---|---|
307 | 1 /* |
2 * main.c | |
393 | 3 * |
1414 | 4 * Copyright (C) 2005-2008 Mikael Berthe <mikael@lilotux.net> |
307 | 5 * Parts of this file come from Cabber <cabber@ajmacias.com> |
6 * | |
7 * This program is free software; you can redistribute it and/or modify | |
8 * it under the terms of the GNU General Public License as published by | |
9 * the Free Software Foundation; either version 2 of the License, or (at | |
10 * your option) any later version. | |
11 * | |
12 * This program is distributed in the hope that it will be useful, but | |
13 * WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
15 * General Public License for more details. | |
16 * | |
17 * You should have received a copy of the GNU General Public License | |
18 * along with this program; if not, write to the Free Software | |
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 | |
20 * USA | |
21 */ | |
22 | |
24 | 23 #include <stdio.h> |
24 #include <stdlib.h> | |
25 #include <unistd.h> | |
26 #include <string.h> | |
27 #include <signal.h> | |
28 #include <termios.h> | |
163 | 29 #include <sys/types.h> |
30 #include <sys/wait.h> | |
169 | 31 #include <glib.h> |
404 | 32 #include <config.h> |
24 | 33 |
81 | 34 #include "jabglue.h" |
24 | 35 #include "screen.h" |
279
f5dd437c057b
Rewrite the settings system
Mikael Berthe <mikael@lilotux.net>
parents:
272
diff
changeset
|
36 #include "settings.h" |
102 | 37 #include "roster.h" |
96 | 38 #include "commands.h" |
113 | 39 #include "histolog.h" |
163 | 40 #include "hooks.h" |
81 | 41 #include "utils.h" |
1042
8a395c2cafc4
Initial PGP support (decrypt)
Mikael Berthe <mikael@lilotux.net>
parents:
993
diff
changeset
|
42 #include "pgp.h" |
1299
3b338a5c01fc
OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
1259
diff
changeset
|
43 #include "otr.h" |
1448
844410b9b4cc
Remove configure option --enable-fifo
Mikael Berthe <mikael@lilotux.net>
parents:
1445
diff
changeset
|
44 #include "fifo.h" |
1426
a64778f5f26b
Implement FIFO named command pipe
Mikael Berthe <mikael@lilotux.net>
parents:
1425
diff
changeset
|
45 |
781
d3af6877a7df
Add --enable-hgcset to configure script
Mikael Berthe <mikael@lilotux.net>
parents:
779
diff
changeset
|
46 #ifdef ENABLE_HGCSET |
d3af6877a7df
Add --enable-hgcset to configure script
Mikael Berthe <mikael@lilotux.net>
parents:
779
diff
changeset
|
47 # include "hgcset.h" |
d3af6877a7df
Add --enable-hgcset to configure script
Mikael Berthe <mikael@lilotux.net>
parents:
779
diff
changeset
|
48 #endif |
24 | 49 |
801
d8e0a1ce3e8a
Define WAIT_ANY if needed.
Soren Andersen <somian@pobox.com>
parents:
789
diff
changeset
|
50 #ifndef WAIT_ANY |
1053 | 51 # define WAIT_ANY -1 |
801
d8e0a1ce3e8a
Define WAIT_ANY if needed.
Soren Andersen <somian@pobox.com>
parents:
789
diff
changeset
|
52 #endif |
24 | 53 |
1359
7daf906fbcdc
The command /quit can be used in bindings, hooks and sourced files
Mikael Berthe <mikael@lilotux.net>
parents:
1313
diff
changeset
|
54 static unsigned int terminate_ui; |
7daf906fbcdc
The command /quit can be used in bindings, hooks and sourced files
Mikael Berthe <mikael@lilotux.net>
parents:
1313
diff
changeset
|
55 |
789
1fa93cc6f5e3
Correctly restore term settings when interrupting the password query
Mikael Berthe <mikael@lilotux.net>
parents:
784
diff
changeset
|
56 static struct termios *backup_termios; |
1fa93cc6f5e3
Correctly restore term settings when interrupting the password query
Mikael Berthe <mikael@lilotux.net>
parents:
784
diff
changeset
|
57 |
777
e6d42f239541
"/version" shows Mercurial changeset (if there's one)
Mikael Berthe <mikael@lilotux.net>
parents:
774
diff
changeset
|
58 char *mcabber_version(void) |
e6d42f239541
"/version" shows Mercurial changeset (if there's one)
Mikael Berthe <mikael@lilotux.net>
parents:
774
diff
changeset
|
59 { |
e6d42f239541
"/version" shows Mercurial changeset (if there's one)
Mikael Berthe <mikael@lilotux.net>
parents:
774
diff
changeset
|
60 char *ver; |
e6d42f239541
"/version" shows Mercurial changeset (if there's one)
Mikael Berthe <mikael@lilotux.net>
parents:
774
diff
changeset
|
61 #ifdef HGCSET |
e6d42f239541
"/version" shows Mercurial changeset (if there's one)
Mikael Berthe <mikael@lilotux.net>
parents:
774
diff
changeset
|
62 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
|
63 #else |
e6d42f239541
"/version" shows Mercurial changeset (if there's one)
Mikael Berthe <mikael@lilotux.net>
parents:
774
diff
changeset
|
64 ver = g_strdup(PACKAGE_VERSION); |
e6d42f239541
"/version" shows Mercurial changeset (if there's one)
Mikael Berthe <mikael@lilotux.net>
parents:
774
diff
changeset
|
65 #endif |
e6d42f239541
"/version" shows Mercurial changeset (if there's one)
Mikael Berthe <mikael@lilotux.net>
parents:
774
diff
changeset
|
66 return ver; |
e6d42f239541
"/version" shows Mercurial changeset (if there's one)
Mikael Berthe <mikael@lilotux.net>
parents:
774
diff
changeset
|
67 } |
e6d42f239541
"/version" shows Mercurial changeset (if there's one)
Mikael Berthe <mikael@lilotux.net>
parents:
774
diff
changeset
|
68 |
298
35cda94e570d
Add /connect and /disconnect commands
Mikael Berthe <mikael@lilotux.net>
parents:
281
diff
changeset
|
69 void mcabber_connect(void) |
35 | 70 { |
298
35cda94e570d
Add /connect and /disconnect commands
Mikael Berthe <mikael@lilotux.net>
parents:
281
diff
changeset
|
71 const char *username, *password, *resource, *servername; |
429 | 72 const char *proxy_host; |
1421
0b8701386bde
Randomize the default resource
Mikael Berthe <mikael@lilotux.net>
parents:
1414
diff
changeset
|
73 char *dynresource = NULL; |
0b8701386bde
Randomize the default resource
Mikael Berthe <mikael@lilotux.net>
parents:
1414
diff
changeset
|
74 char *fjid; |
298
35cda94e570d
Add /connect and /disconnect commands
Mikael Berthe <mikael@lilotux.net>
parents:
281
diff
changeset
|
75 int ssl; |
938
40175f3dcef7
SSL server certificate verification
Jefferson Ogata <ogata@antibozo.net>
parents:
895
diff
changeset
|
76 int sslverify = -1; |
40175f3dcef7
SSL server certificate verification
Jefferson Ogata <ogata@antibozo.net>
parents:
895
diff
changeset
|
77 const char *sslvopt = NULL, *cafile = NULL, *capath = NULL, *ciphers = NULL; |
1222
75aee46d3aee
Fix a problem with the ssl_ca{file,path} variables expansion
Mikael Berthe <mikael@lilotux.net>
parents:
1205
diff
changeset
|
78 static char *cafile_xp, *capath_xp; |
298
35cda94e570d
Add /connect and /disconnect commands
Mikael Berthe <mikael@lilotux.net>
parents:
281
diff
changeset
|
79 unsigned int port; |
35cda94e570d
Add /connect and /disconnect commands
Mikael Berthe <mikael@lilotux.net>
parents:
281
diff
changeset
|
80 |
35cda94e570d
Add /connect and /disconnect commands
Mikael Berthe <mikael@lilotux.net>
parents:
281
diff
changeset
|
81 servername = settings_opt_get("server"); |
35cda94e570d
Add /connect and /disconnect commands
Mikael Berthe <mikael@lilotux.net>
parents:
281
diff
changeset
|
82 username = settings_opt_get("username"); |
35cda94e570d
Add /connect and /disconnect commands
Mikael Berthe <mikael@lilotux.net>
parents:
281
diff
changeset
|
83 password = settings_opt_get("password"); |
35cda94e570d
Add /connect and /disconnect commands
Mikael Berthe <mikael@lilotux.net>
parents:
281
diff
changeset
|
84 resource = settings_opt_get("resource"); |
429 | 85 proxy_host = settings_opt_get("proxy_host"); |
298
35cda94e570d
Add /connect and /disconnect commands
Mikael Berthe <mikael@lilotux.net>
parents:
281
diff
changeset
|
86 |
1222
75aee46d3aee
Fix a problem with the ssl_ca{file,path} variables expansion
Mikael Berthe <mikael@lilotux.net>
parents:
1205
diff
changeset
|
87 // Free the ca*_xp strings if they've already been set. |
75aee46d3aee
Fix a problem with the ssl_ca{file,path} variables expansion
Mikael Berthe <mikael@lilotux.net>
parents:
1205
diff
changeset
|
88 g_free(cafile_xp); |
75aee46d3aee
Fix a problem with the ssl_ca{file,path} variables expansion
Mikael Berthe <mikael@lilotux.net>
parents:
1205
diff
changeset
|
89 g_free(capath_xp); |
75aee46d3aee
Fix a problem with the ssl_ca{file,path} variables expansion
Mikael Berthe <mikael@lilotux.net>
parents:
1205
diff
changeset
|
90 cafile_xp = capath_xp = NULL; |
75aee46d3aee
Fix a problem with the ssl_ca{file,path} variables expansion
Mikael Berthe <mikael@lilotux.net>
parents:
1205
diff
changeset
|
91 |
298
35cda94e570d
Add /connect and /disconnect commands
Mikael Berthe <mikael@lilotux.net>
parents:
281
diff
changeset
|
92 if (!servername) { |
374
bd5638c21834
Improve logging system (traces)
Mikael Berthe <mikael@lilotux.net>
parents:
364
diff
changeset
|
93 scr_LogPrint(LPRINT_NORMAL, "Server name has not been specified!"); |
298
35cda94e570d
Add /connect and /disconnect commands
Mikael Berthe <mikael@lilotux.net>
parents:
281
diff
changeset
|
94 return; |
35cda94e570d
Add /connect and /disconnect commands
Mikael Berthe <mikael@lilotux.net>
parents:
281
diff
changeset
|
95 } |
35cda94e570d
Add /connect and /disconnect commands
Mikael Berthe <mikael@lilotux.net>
parents:
281
diff
changeset
|
96 if (!username) { |
374
bd5638c21834
Improve logging system (traces)
Mikael Berthe <mikael@lilotux.net>
parents:
364
diff
changeset
|
97 scr_LogPrint(LPRINT_NORMAL, "User name has not been specified!"); |
298
35cda94e570d
Add /connect and /disconnect commands
Mikael Berthe <mikael@lilotux.net>
parents:
281
diff
changeset
|
98 return; |
35cda94e570d
Add /connect and /disconnect commands
Mikael Berthe <mikael@lilotux.net>
parents:
281
diff
changeset
|
99 } |
35cda94e570d
Add /connect and /disconnect commands
Mikael Berthe <mikael@lilotux.net>
parents:
281
diff
changeset
|
100 if (!password) { |
374
bd5638c21834
Improve logging system (traces)
Mikael Berthe <mikael@lilotux.net>
parents:
364
diff
changeset
|
101 scr_LogPrint(LPRINT_NORMAL, "Password has not been specified!"); |
298
35cda94e570d
Add /connect and /disconnect commands
Mikael Berthe <mikael@lilotux.net>
parents:
281
diff
changeset
|
102 return; |
35cda94e570d
Add /connect and /disconnect commands
Mikael Berthe <mikael@lilotux.net>
parents:
281
diff
changeset
|
103 } |
35cda94e570d
Add /connect and /disconnect commands
Mikael Berthe <mikael@lilotux.net>
parents:
281
diff
changeset
|
104 |
938
40175f3dcef7
SSL server certificate verification
Jefferson Ogata <ogata@antibozo.net>
parents:
895
diff
changeset
|
105 port = (unsigned int) settings_opt_get_int("port"); |
40175f3dcef7
SSL server certificate verification
Jefferson Ogata <ogata@antibozo.net>
parents:
895
diff
changeset
|
106 |
40175f3dcef7
SSL server certificate verification
Jefferson Ogata <ogata@antibozo.net>
parents:
895
diff
changeset
|
107 ssl = settings_opt_get_int("ssl"); |
40175f3dcef7
SSL server certificate verification
Jefferson Ogata <ogata@antibozo.net>
parents:
895
diff
changeset
|
108 sslvopt = settings_opt_get("ssl_verify"); |
40175f3dcef7
SSL server certificate verification
Jefferson Ogata <ogata@antibozo.net>
parents:
895
diff
changeset
|
109 if (sslvopt) |
40175f3dcef7
SSL server certificate verification
Jefferson Ogata <ogata@antibozo.net>
parents:
895
diff
changeset
|
110 sslverify = settings_opt_get_int("ssl_verify"); |
40175f3dcef7
SSL server certificate verification
Jefferson Ogata <ogata@antibozo.net>
parents:
895
diff
changeset
|
111 cafile = settings_opt_get("ssl_cafile"); |
40175f3dcef7
SSL server certificate verification
Jefferson Ogata <ogata@antibozo.net>
parents:
895
diff
changeset
|
112 capath = settings_opt_get("ssl_capath"); |
40175f3dcef7
SSL server certificate verification
Jefferson Ogata <ogata@antibozo.net>
parents:
895
diff
changeset
|
113 ciphers = settings_opt_get("ssl_ciphers"); |
298
35cda94e570d
Add /connect and /disconnect commands
Mikael Berthe <mikael@lilotux.net>
parents:
281
diff
changeset
|
114 |
815
04edcb6d7ee3
Warn when ssl is request but not compiled in
Mikael Berthe <mikael@lilotux.net>
parents:
801
diff
changeset
|
115 #if !defined(HAVE_OPENSSL) && !defined(HAVE_GNUTLS) |
1370
6d4770f35ddd
Do not connect when the SSL settings can't be used (suggested by Till Maas)
Mikael Berthe <mikael@lilotux.net>
parents:
1359
diff
changeset
|
116 if (ssl) { |
6d4770f35ddd
Do not connect when the SSL settings can't be used (suggested by Till Maas)
Mikael Berthe <mikael@lilotux.net>
parents:
1359
diff
changeset
|
117 scr_LogPrint(LPRINT_LOGNORM, "** Error: SSL is NOT available, " |
6d4770f35ddd
Do not connect when the SSL settings can't be used (suggested by Till Maas)
Mikael Berthe <mikael@lilotux.net>
parents:
1359
diff
changeset
|
118 "do not set the option 'ssl'."); |
6d4770f35ddd
Do not connect when the SSL settings can't be used (suggested by Till Maas)
Mikael Berthe <mikael@lilotux.net>
parents:
1359
diff
changeset
|
119 return; |
6d4770f35ddd
Do not connect when the SSL settings can't be used (suggested by Till Maas)
Mikael Berthe <mikael@lilotux.net>
parents:
1359
diff
changeset
|
120 } else if (sslvopt || cafile || capath || ciphers) { |
6d4770f35ddd
Do not connect when the SSL settings can't be used (suggested by Till Maas)
Mikael Berthe <mikael@lilotux.net>
parents:
1359
diff
changeset
|
121 scr_LogPrint(LPRINT_LOGNORM, "** Warning: SSL is NOT available, " |
6d4770f35ddd
Do not connect when the SSL settings can't be used (suggested by Till Maas)
Mikael Berthe <mikael@lilotux.net>
parents:
1359
diff
changeset
|
122 "ignoring ssl-related settings"); |
938
40175f3dcef7
SSL server certificate verification
Jefferson Ogata <ogata@antibozo.net>
parents:
895
diff
changeset
|
123 ssl = sslverify = 0; |
40175f3dcef7
SSL server certificate verification
Jefferson Ogata <ogata@antibozo.net>
parents:
895
diff
changeset
|
124 cafile = capath = ciphers = NULL; |
815
04edcb6d7ee3
Warn when ssl is request but not compiled in
Mikael Berthe <mikael@lilotux.net>
parents:
801
diff
changeset
|
125 } |
1253 | 126 #elif defined HAVE_GNUTLS |
1445
00503a68f431
Fix false error with GnuTLS
Mikael Berthe <mikael@lilotux.net>
parents:
1437
diff
changeset
|
127 if (ssl && sslverify != 0) { |
1370
6d4770f35ddd
Do not connect when the SSL settings can't be used (suggested by Till Maas)
Mikael Berthe <mikael@lilotux.net>
parents:
1359
diff
changeset
|
128 scr_LogPrint(LPRINT_LOGNORM, "** Error: SSL certificate checking " |
6d4770f35ddd
Do not connect when the SSL settings can't be used (suggested by Till Maas)
Mikael Berthe <mikael@lilotux.net>
parents:
1359
diff
changeset
|
129 "is not supported yet with GnuTLS."); |
6d4770f35ddd
Do not connect when the SSL settings can't be used (suggested by Till Maas)
Mikael Berthe <mikael@lilotux.net>
parents:
1359
diff
changeset
|
130 scr_LogPrint(LPRINT_LOGNORM, |
6d4770f35ddd
Do not connect when the SSL settings can't be used (suggested by Till Maas)
Mikael Berthe <mikael@lilotux.net>
parents:
1359
diff
changeset
|
131 " * Please set 'ssl_verify' to 0 explicitly!"); |
6d4770f35ddd
Do not connect when the SSL settings can't be used (suggested by Till Maas)
Mikael Berthe <mikael@lilotux.net>
parents:
1359
diff
changeset
|
132 return; |
1253 | 133 } |
815
04edcb6d7ee3
Warn when ssl is request but not compiled in
Mikael Berthe <mikael@lilotux.net>
parents:
801
diff
changeset
|
134 #endif |
1222
75aee46d3aee
Fix a problem with the ssl_ca{file,path} variables expansion
Mikael Berthe <mikael@lilotux.net>
parents:
1205
diff
changeset
|
135 cafile_xp = expand_filename(cafile); |
75aee46d3aee
Fix a problem with the ssl_ca{file,path} variables expansion
Mikael Berthe <mikael@lilotux.net>
parents:
1205
diff
changeset
|
136 capath_xp = expand_filename(capath); |
1167
9726c78a91f3
Allow '~' (HOME directory) in config options
Mikael Berthe <mikael@lilotux.net>
parents:
1123
diff
changeset
|
137 cw_set_ssl_options(sslverify, cafile_xp, capath_xp, ciphers, servername); |
1222
75aee46d3aee
Fix a problem with the ssl_ca{file,path} variables expansion
Mikael Berthe <mikael@lilotux.net>
parents:
1205
diff
changeset
|
138 // We can't free the ca*_xp variables now, because they're not duplicated |
75aee46d3aee
Fix a problem with the ssl_ca{file,path} variables expansion
Mikael Berthe <mikael@lilotux.net>
parents:
1205
diff
changeset
|
139 // in cw_set_ssl_options(). |
815
04edcb6d7ee3
Warn when ssl is request but not compiled in
Mikael Berthe <mikael@lilotux.net>
parents:
801
diff
changeset
|
140 |
1421
0b8701386bde
Randomize the default resource
Mikael Berthe <mikael@lilotux.net>
parents:
1414
diff
changeset
|
141 if (!resource) { |
1497
35020a2ed115
Do not use srand()/rand() if better alternatives exist (mirabilos)
Mikael Berthe <mikael@lilotux.net>
parents:
1454
diff
changeset
|
142 #if HAVE_ARC4RANDOM |
35020a2ed115
Do not use srand()/rand() if better alternatives exist (mirabilos)
Mikael Berthe <mikael@lilotux.net>
parents:
1454
diff
changeset
|
143 dynresource = g_strdup_printf("%s.%08x", PACKAGE_NAME, arc4random()); |
35020a2ed115
Do not use srand()/rand() if better alternatives exist (mirabilos)
Mikael Berthe <mikael@lilotux.net>
parents:
1454
diff
changeset
|
144 #else |
1421
0b8701386bde
Randomize the default resource
Mikael Berthe <mikael@lilotux.net>
parents:
1414
diff
changeset
|
145 unsigned int tab[2]; |
0b8701386bde
Randomize the default resource
Mikael Berthe <mikael@lilotux.net>
parents:
1414
diff
changeset
|
146 srand(time(NULL)); |
0b8701386bde
Randomize the default resource
Mikael Berthe <mikael@lilotux.net>
parents:
1414
diff
changeset
|
147 tab[0] = (unsigned int) (0xffff * (rand() / (RAND_MAX + 1.0))); |
0b8701386bde
Randomize the default resource
Mikael Berthe <mikael@lilotux.net>
parents:
1414
diff
changeset
|
148 tab[1] = (unsigned int) (0xffff * (rand() / (RAND_MAX + 1.0))); |
0b8701386bde
Randomize the default resource
Mikael Berthe <mikael@lilotux.net>
parents:
1414
diff
changeset
|
149 dynresource = g_strdup_printf("%s.%04x%04x", PACKAGE_NAME, |
0b8701386bde
Randomize the default resource
Mikael Berthe <mikael@lilotux.net>
parents:
1414
diff
changeset
|
150 tab[0], tab[1]); |
1497
35020a2ed115
Do not use srand()/rand() if better alternatives exist (mirabilos)
Mikael Berthe <mikael@lilotux.net>
parents:
1454
diff
changeset
|
151 #endif |
1421
0b8701386bde
Randomize the default resource
Mikael Berthe <mikael@lilotux.net>
parents:
1414
diff
changeset
|
152 resource = dynresource; |
0b8701386bde
Randomize the default resource
Mikael Berthe <mikael@lilotux.net>
parents:
1414
diff
changeset
|
153 } |
0b8701386bde
Randomize the default resource
Mikael Berthe <mikael@lilotux.net>
parents:
1414
diff
changeset
|
154 |
298
35cda94e570d
Add /connect and /disconnect commands
Mikael Berthe <mikael@lilotux.net>
parents:
281
diff
changeset
|
155 /* Connect to server */ |
374
bd5638c21834
Improve logging system (traces)
Mikael Berthe <mikael@lilotux.net>
parents:
364
diff
changeset
|
156 scr_LogPrint(LPRINT_NORMAL|LPRINT_DEBUG, "Connecting to server: %s", |
bd5638c21834
Improve logging system (traces)
Mikael Berthe <mikael@lilotux.net>
parents:
364
diff
changeset
|
157 servername); |
bd5638c21834
Improve logging system (traces)
Mikael Berthe <mikael@lilotux.net>
parents:
364
diff
changeset
|
158 if (port) |
bd5638c21834
Improve logging system (traces)
Mikael Berthe <mikael@lilotux.net>
parents:
364
diff
changeset
|
159 scr_LogPrint(LPRINT_NORMAL|LPRINT_DEBUG, " using port %d", port); |
1421
0b8701386bde
Randomize the default resource
Mikael Berthe <mikael@lilotux.net>
parents:
1414
diff
changeset
|
160 scr_LogPrint(LPRINT_NORMAL|LPRINT_DEBUG, " resource %s", resource); |
298
35cda94e570d
Add /connect and /disconnect commands
Mikael Berthe <mikael@lilotux.net>
parents:
281
diff
changeset
|
161 |
429 | 162 if (proxy_host) { |
163 int proxy_port = settings_opt_get_int("proxy_port"); | |
164 if (proxy_port <= 0 || proxy_port > 65535) { | |
165 scr_LogPrint(LPRINT_LOGNORM, "Invalid proxy port: %d", proxy_port); | |
166 } else { | |
167 const char *proxy_user, *proxy_pass; | |
168 proxy_user = settings_opt_get("proxy_user"); | |
169 proxy_pass = settings_opt_get("proxy_pass"); | |
170 // Proxy initialization | |
171 cw_setproxy(proxy_host, proxy_port, proxy_user, proxy_pass); | |
172 scr_LogPrint(LPRINT_NORMAL|LPRINT_DEBUG, " using proxy %s:%d", | |
173 proxy_host, proxy_port); | |
174 } | |
175 } | |
176 | |
1421
0b8701386bde
Randomize the default resource
Mikael Berthe <mikael@lilotux.net>
parents:
1414
diff
changeset
|
177 fjid = compose_jid(username, servername, resource); |
1299
3b338a5c01fc
OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
1259
diff
changeset
|
178 #if defined(HAVE_LIBOTR) |
1421
0b8701386bde
Randomize the default resource
Mikael Berthe <mikael@lilotux.net>
parents:
1414
diff
changeset
|
179 otr_init(fjid); |
1299
3b338a5c01fc
OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
1259
diff
changeset
|
180 #endif |
1421
0b8701386bde
Randomize the default resource
Mikael Berthe <mikael@lilotux.net>
parents:
1414
diff
changeset
|
181 jc = jb_connect(fjid, servername, port, ssl, password); |
0b8701386bde
Randomize the default resource
Mikael Berthe <mikael@lilotux.net>
parents:
1414
diff
changeset
|
182 g_free(fjid); |
0b8701386bde
Randomize the default resource
Mikael Berthe <mikael@lilotux.net>
parents:
1414
diff
changeset
|
183 g_free(dynresource); |
298
35cda94e570d
Add /connect and /disconnect commands
Mikael Berthe <mikael@lilotux.net>
parents:
281
diff
changeset
|
184 |
374
bd5638c21834
Improve logging system (traces)
Mikael Berthe <mikael@lilotux.net>
parents:
364
diff
changeset
|
185 if (!jc) |
bd5638c21834
Improve logging system (traces)
Mikael Berthe <mikael@lilotux.net>
parents:
364
diff
changeset
|
186 scr_LogPrint(LPRINT_LOGNORM, "Error connecting to (%s)", servername); |
298
35cda94e570d
Add /connect and /disconnect commands
Mikael Berthe <mikael@lilotux.net>
parents:
281
diff
changeset
|
187 |
35cda94e570d
Add /connect and /disconnect commands
Mikael Berthe <mikael@lilotux.net>
parents:
281
diff
changeset
|
188 jb_reset_keepalive(); |
35 | 189 } |
190 | |
962
e79af58cd0be
mcabber_disconnect() -> static mcabber_terminate()
Mikael Berthe <mikael@lilotux.net>
parents:
961
diff
changeset
|
191 static void mcabber_terminate(const char *msg) |
312
f0b7ff2df7e8
Ctrl-C does not terminate mcabber
Mikael Berthe <mikael@lilotux.net>
parents:
307
diff
changeset
|
192 { |
f0b7ff2df7e8
Ctrl-C does not terminate mcabber
Mikael Berthe <mikael@lilotux.net>
parents:
307
diff
changeset
|
193 jb_disconnect(); |
f0b7ff2df7e8
Ctrl-C does not terminate mcabber
Mikael Berthe <mikael@lilotux.net>
parents:
307
diff
changeset
|
194 scr_TerminateCurses(); |
789
1fa93cc6f5e3
Correctly restore term settings when interrupting the password query
Mikael Berthe <mikael@lilotux.net>
parents:
784
diff
changeset
|
195 |
1fa93cc6f5e3
Correctly restore term settings when interrupting the password query
Mikael Berthe <mikael@lilotux.net>
parents:
784
diff
changeset
|
196 // Restore term settings, if needed. |
1fa93cc6f5e3
Correctly restore term settings when interrupting the password query
Mikael Berthe <mikael@lilotux.net>
parents:
784
diff
changeset
|
197 if (backup_termios) |
1fa93cc6f5e3
Correctly restore term settings when interrupting the password query
Mikael Berthe <mikael@lilotux.net>
parents:
784
diff
changeset
|
198 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
|
199 |
312
f0b7ff2df7e8
Ctrl-C does not terminate mcabber
Mikael Berthe <mikael@lilotux.net>
parents:
307
diff
changeset
|
200 if (msg) |
f0b7ff2df7e8
Ctrl-C does not terminate mcabber
Mikael Berthe <mikael@lilotux.net>
parents:
307
diff
changeset
|
201 fprintf(stderr, "%s\n", msg); |
f0b7ff2df7e8
Ctrl-C does not terminate mcabber
Mikael Berthe <mikael@lilotux.net>
parents:
307
diff
changeset
|
202 printf("Bye!\n"); |
f0b7ff2df7e8
Ctrl-C does not terminate mcabber
Mikael Berthe <mikael@lilotux.net>
parents:
307
diff
changeset
|
203 exit(EXIT_SUCCESS); |
f0b7ff2df7e8
Ctrl-C does not terminate mcabber
Mikael Berthe <mikael@lilotux.net>
parents:
307
diff
changeset
|
204 } |
f0b7ff2df7e8
Ctrl-C does not terminate mcabber
Mikael Berthe <mikael@lilotux.net>
parents:
307
diff
changeset
|
205 |
f0b7ff2df7e8
Ctrl-C does not terminate mcabber
Mikael Berthe <mikael@lilotux.net>
parents:
307
diff
changeset
|
206 void sig_handler(int signum) |
f0b7ff2df7e8
Ctrl-C does not terminate mcabber
Mikael Berthe <mikael@lilotux.net>
parents:
307
diff
changeset
|
207 { |
f0b7ff2df7e8
Ctrl-C does not terminate mcabber
Mikael Berthe <mikael@lilotux.net>
parents:
307
diff
changeset
|
208 if (signum == SIGCHLD) { |
f0b7ff2df7e8
Ctrl-C does not terminate mcabber
Mikael Berthe <mikael@lilotux.net>
parents:
307
diff
changeset
|
209 int status; |
f0b7ff2df7e8
Ctrl-C does not terminate mcabber
Mikael Berthe <mikael@lilotux.net>
parents:
307
diff
changeset
|
210 pid_t pid; |
f0b7ff2df7e8
Ctrl-C does not terminate mcabber
Mikael Berthe <mikael@lilotux.net>
parents:
307
diff
changeset
|
211 do { |
f0b7ff2df7e8
Ctrl-C does not terminate mcabber
Mikael Berthe <mikael@lilotux.net>
parents:
307
diff
changeset
|
212 pid = waitpid (WAIT_ANY, &status, WNOHANG); |
676
80d4959422ca
New "eventcmd_checkstatus" option
Mikael Berthe <mikael@lilotux.net>
parents:
580
diff
changeset
|
213 // Check the exit status value if 'eventcmd_checkstatus' is set |
80d4959422ca
New "eventcmd_checkstatus" option
Mikael Berthe <mikael@lilotux.net>
parents:
580
diff
changeset
|
214 if (settings_opt_get_int("eventcmd_checkstatus")) { |
80d4959422ca
New "eventcmd_checkstatus" option
Mikael Berthe <mikael@lilotux.net>
parents:
580
diff
changeset
|
215 if (pid > 0) { |
80d4959422ca
New "eventcmd_checkstatus" option
Mikael Berthe <mikael@lilotux.net>
parents:
580
diff
changeset
|
216 // exit status 2 -> beep |
80d4959422ca
New "eventcmd_checkstatus" option
Mikael Berthe <mikael@lilotux.net>
parents:
580
diff
changeset
|
217 if (WIFEXITED(status) && WEXITSTATUS(status) == 2) { |
80d4959422ca
New "eventcmd_checkstatus" option
Mikael Berthe <mikael@lilotux.net>
parents:
580
diff
changeset
|
218 scr_Beep(); |
80d4959422ca
New "eventcmd_checkstatus" option
Mikael Berthe <mikael@lilotux.net>
parents:
580
diff
changeset
|
219 } |
80d4959422ca
New "eventcmd_checkstatus" option
Mikael Berthe <mikael@lilotux.net>
parents:
580
diff
changeset
|
220 } |
80d4959422ca
New "eventcmd_checkstatus" option
Mikael Berthe <mikael@lilotux.net>
parents:
580
diff
changeset
|
221 } |
312
f0b7ff2df7e8
Ctrl-C does not terminate mcabber
Mikael Berthe <mikael@lilotux.net>
parents:
307
diff
changeset
|
222 } while (pid > 0); |
f0b7ff2df7e8
Ctrl-C does not terminate mcabber
Mikael Berthe <mikael@lilotux.net>
parents:
307
diff
changeset
|
223 signal(SIGCHLD, sig_handler); |
f0b7ff2df7e8
Ctrl-C does not terminate mcabber
Mikael Berthe <mikael@lilotux.net>
parents:
307
diff
changeset
|
224 } else if (signum == SIGTERM) { |
962
e79af58cd0be
mcabber_disconnect() -> static mcabber_terminate()
Mikael Berthe <mikael@lilotux.net>
parents:
961
diff
changeset
|
225 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
|
226 } else if (signum == SIGINT) { |
962
e79af58cd0be
mcabber_disconnect() -> static mcabber_terminate()
Mikael Berthe <mikael@lilotux.net>
parents:
961
diff
changeset
|
227 mcabber_terminate("Killed by SIGINT"); |
1454
6b98dc22946d
Add optional SIGWINCH handler (Markus Hennecke)
Mikael Berthe <mikael@lilotux.net>
parents:
1448
diff
changeset
|
228 #ifdef USE_SIGWINCH |
6b98dc22946d
Add optional SIGWINCH handler (Markus Hennecke)
Mikael Berthe <mikael@lilotux.net>
parents:
1448
diff
changeset
|
229 } else if (signum == SIGWINCH) { |
6b98dc22946d
Add optional SIGWINCH handler (Markus Hennecke)
Mikael Berthe <mikael@lilotux.net>
parents:
1448
diff
changeset
|
230 ungetch(KEY_RESIZE); |
6b98dc22946d
Add optional SIGWINCH handler (Markus Hennecke)
Mikael Berthe <mikael@lilotux.net>
parents:
1448
diff
changeset
|
231 #endif |
312
f0b7ff2df7e8
Ctrl-C does not terminate mcabber
Mikael Berthe <mikael@lilotux.net>
parents:
307
diff
changeset
|
232 } else { |
374
bd5638c21834
Improve logging system (traces)
Mikael Berthe <mikael@lilotux.net>
parents:
364
diff
changeset
|
233 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
|
234 } |
f0b7ff2df7e8
Ctrl-C does not terminate mcabber
Mikael Berthe <mikael@lilotux.net>
parents:
307
diff
changeset
|
235 } |
f0b7ff2df7e8
Ctrl-C does not terminate mcabber
Mikael Berthe <mikael@lilotux.net>
parents:
307
diff
changeset
|
236 |
1042
8a395c2cafc4
Initial PGP support (decrypt)
Mikael Berthe <mikael@lilotux.net>
parents:
993
diff
changeset
|
237 // ask_password(what) |
8a395c2cafc4
Initial PGP support (decrypt)
Mikael Berthe <mikael@lilotux.net>
parents:
993
diff
changeset
|
238 // Return the password, or NULL. |
8a395c2cafc4
Initial PGP support (decrypt)
Mikael Berthe <mikael@lilotux.net>
parents:
993
diff
changeset
|
239 // The string must be freed after use. |
8a395c2cafc4
Initial PGP support (decrypt)
Mikael Berthe <mikael@lilotux.net>
parents:
993
diff
changeset
|
240 static char *ask_password(const char *what) |
312
f0b7ff2df7e8
Ctrl-C does not terminate mcabber
Mikael Berthe <mikael@lilotux.net>
parents:
307
diff
changeset
|
241 { |
f0b7ff2df7e8
Ctrl-C does not terminate mcabber
Mikael Berthe <mikael@lilotux.net>
parents:
307
diff
changeset
|
242 char *password, *p; |
f0b7ff2df7e8
Ctrl-C does not terminate mcabber
Mikael Berthe <mikael@lilotux.net>
parents:
307
diff
changeset
|
243 size_t passsize = 128; |
f0b7ff2df7e8
Ctrl-C does not terminate mcabber
Mikael Berthe <mikael@lilotux.net>
parents:
307
diff
changeset
|
244 struct termios orig, new; |
482
2ea7591584ab
Use fgets() instead of getline()
Mikael Berthe <mikael@lilotux.net>
parents:
429
diff
changeset
|
245 |
2ea7591584ab
Use fgets() instead of getline()
Mikael Berthe <mikael@lilotux.net>
parents:
429
diff
changeset
|
246 password = g_new0(char, passsize); |
312
f0b7ff2df7e8
Ctrl-C does not terminate mcabber
Mikael Berthe <mikael@lilotux.net>
parents:
307
diff
changeset
|
247 |
f0b7ff2df7e8
Ctrl-C does not terminate mcabber
Mikael Berthe <mikael@lilotux.net>
parents:
307
diff
changeset
|
248 /* Turn echoing off and fail if we can't. */ |
1042
8a395c2cafc4
Initial PGP support (decrypt)
Mikael Berthe <mikael@lilotux.net>
parents:
993
diff
changeset
|
249 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
|
250 backup_termios = &orig; |
1fa93cc6f5e3
Correctly restore term settings when interrupting the password query
Mikael Berthe <mikael@lilotux.net>
parents:
784
diff
changeset
|
251 |
312
f0b7ff2df7e8
Ctrl-C does not terminate mcabber
Mikael Berthe <mikael@lilotux.net>
parents:
307
diff
changeset
|
252 new = orig; |
f0b7ff2df7e8
Ctrl-C does not terminate mcabber
Mikael Berthe <mikael@lilotux.net>
parents:
307
diff
changeset
|
253 new.c_lflag &= ~ECHO; |
1042
8a395c2cafc4
Initial PGP support (decrypt)
Mikael Berthe <mikael@lilotux.net>
parents:
993
diff
changeset
|
254 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
|
255 |
f0b7ff2df7e8
Ctrl-C does not terminate mcabber
Mikael Berthe <mikael@lilotux.net>
parents:
307
diff
changeset
|
256 /* Read the password. */ |
1042
8a395c2cafc4
Initial PGP support (decrypt)
Mikael Berthe <mikael@lilotux.net>
parents:
993
diff
changeset
|
257 printf("Please enter %s: ", what); |
482
2ea7591584ab
Use fgets() instead of getline()
Mikael Berthe <mikael@lilotux.net>
parents:
429
diff
changeset
|
258 fgets(password, passsize, stdin); |
312
f0b7ff2df7e8
Ctrl-C does not terminate mcabber
Mikael Berthe <mikael@lilotux.net>
parents:
307
diff
changeset
|
259 |
f0b7ff2df7e8
Ctrl-C does not terminate mcabber
Mikael Berthe <mikael@lilotux.net>
parents:
307
diff
changeset
|
260 /* Restore terminal. */ |
f0b7ff2df7e8
Ctrl-C does not terminate mcabber
Mikael Berthe <mikael@lilotux.net>
parents:
307
diff
changeset
|
261 tcsetattr(fileno(stdin), TCSAFLUSH, &orig); |
f0b7ff2df7e8
Ctrl-C does not terminate mcabber
Mikael Berthe <mikael@lilotux.net>
parents:
307
diff
changeset
|
262 printf("\n"); |
789
1fa93cc6f5e3
Correctly restore term settings when interrupting the password query
Mikael Berthe <mikael@lilotux.net>
parents:
784
diff
changeset
|
263 backup_termios = NULL; |
312
f0b7ff2df7e8
Ctrl-C does not terminate mcabber
Mikael Berthe <mikael@lilotux.net>
parents:
307
diff
changeset
|
264 |
f0b7ff2df7e8
Ctrl-C does not terminate mcabber
Mikael Berthe <mikael@lilotux.net>
parents:
307
diff
changeset
|
265 for (p = (char*)password; *p; p++) |
f0b7ff2df7e8
Ctrl-C does not terminate mcabber
Mikael Berthe <mikael@lilotux.net>
parents:
307
diff
changeset
|
266 ; |
f0b7ff2df7e8
Ctrl-C does not terminate mcabber
Mikael Berthe <mikael@lilotux.net>
parents:
307
diff
changeset
|
267 for ( ; p > (char*)password ; p--) |
f0b7ff2df7e8
Ctrl-C does not terminate mcabber
Mikael Berthe <mikael@lilotux.net>
parents:
307
diff
changeset
|
268 if (*p == '\n' || *p == '\r') *p = 0; |
f0b7ff2df7e8
Ctrl-C does not terminate mcabber
Mikael Berthe <mikael@lilotux.net>
parents:
307
diff
changeset
|
269 |
1042
8a395c2cafc4
Initial PGP support (decrypt)
Mikael Berthe <mikael@lilotux.net>
parents:
993
diff
changeset
|
270 return password; |
312
f0b7ff2df7e8
Ctrl-C does not terminate mcabber
Mikael Berthe <mikael@lilotux.net>
parents:
307
diff
changeset
|
271 } |
f0b7ff2df7e8
Ctrl-C does not terminate mcabber
Mikael Berthe <mikael@lilotux.net>
parents:
307
diff
changeset
|
272 |
784
d7f3b58db522
Display hgcset (if defined) at startup
Mikael Berthe <mikael@lilotux.net>
parents:
781
diff
changeset
|
273 static void credits(void) |
24 | 274 { |
895 | 275 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
|
276 char *v = mcabber_version(); |
851
da03534e46c7
Add startup log messages to the status buffer
Mikael Berthe <mikael@lilotux.net>
parents:
848
diff
changeset
|
277 printf(v_fmt, v); |
da03534e46c7
Add startup log messages to the status buffer
Mikael Berthe <mikael@lilotux.net>
parents:
848
diff
changeset
|
278 scr_LogPrint(LPRINT_LOGNORM|LPRINT_NOTUTF8, v_fmt, v); |
784
d7f3b58db522
Display hgcset (if defined) at startup
Mikael Berthe <mikael@lilotux.net>
parents:
781
diff
changeset
|
279 g_free(v); |
24 | 280 } |
281 | |
1257
05dc45e7c7bb
Add command line option -v
Mikael Berthe <mikael@lilotux.net>
parents:
1256
diff
changeset
|
282 static void compile_options(void) |
05dc45e7c7bb
Add command line option -v
Mikael Berthe <mikael@lilotux.net>
parents:
1256
diff
changeset
|
283 { |
05dc45e7c7bb
Add command line option -v
Mikael Berthe <mikael@lilotux.net>
parents:
1256
diff
changeset
|
284 puts("Installation data directory: " DATA_DIR "\n"); |
05dc45e7c7bb
Add command line option -v
Mikael Berthe <mikael@lilotux.net>
parents:
1256
diff
changeset
|
285 #ifdef HAVE_UNICODE |
05dc45e7c7bb
Add command line option -v
Mikael Berthe <mikael@lilotux.net>
parents:
1256
diff
changeset
|
286 puts("Compiled with unicode support."); |
05dc45e7c7bb
Add command line option -v
Mikael Berthe <mikael@lilotux.net>
parents:
1256
diff
changeset
|
287 #endif |
05dc45e7c7bb
Add command line option -v
Mikael Berthe <mikael@lilotux.net>
parents:
1256
diff
changeset
|
288 #ifdef HAVE_OPENSSL |
05dc45e7c7bb
Add command line option -v
Mikael Berthe <mikael@lilotux.net>
parents:
1256
diff
changeset
|
289 puts("Compiled with OpenSSL support."); |
05dc45e7c7bb
Add command line option -v
Mikael Berthe <mikael@lilotux.net>
parents:
1256
diff
changeset
|
290 #elif defined HAVE_GNUTLS |
05dc45e7c7bb
Add command line option -v
Mikael Berthe <mikael@lilotux.net>
parents:
1256
diff
changeset
|
291 puts("Compiled with GnuTLS support."); |
05dc45e7c7bb
Add command line option -v
Mikael Berthe <mikael@lilotux.net>
parents:
1256
diff
changeset
|
292 #endif |
05dc45e7c7bb
Add command line option -v
Mikael Berthe <mikael@lilotux.net>
parents:
1256
diff
changeset
|
293 #ifdef HAVE_GPGME |
05dc45e7c7bb
Add command line option -v
Mikael Berthe <mikael@lilotux.net>
parents:
1256
diff
changeset
|
294 puts("Compiled with GPG support."); |
05dc45e7c7bb
Add command line option -v
Mikael Berthe <mikael@lilotux.net>
parents:
1256
diff
changeset
|
295 #endif |
1299
3b338a5c01fc
OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
1259
diff
changeset
|
296 #ifdef HAVE_LIBOTR |
3b338a5c01fc
OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
1259
diff
changeset
|
297 puts("Compiled with OTR support."); |
3b338a5c01fc
OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
1259
diff
changeset
|
298 #endif |
1257
05dc45e7c7bb
Add command line option -v
Mikael Berthe <mikael@lilotux.net>
parents:
1256
diff
changeset
|
299 #ifdef WITH_ASPELL |
05dc45e7c7bb
Add command line option -v
Mikael Berthe <mikael@lilotux.net>
parents:
1256
diff
changeset
|
300 puts("Compiled with Aspell support."); |
05dc45e7c7bb
Add command line option -v
Mikael Berthe <mikael@lilotux.net>
parents:
1256
diff
changeset
|
301 #endif |
1423
757ebe4df0b9
Replace DEBUG_ENABLE with ENABLE_DEBUG
Mikael Berthe <mikael@lilotux.net>
parents:
1421
diff
changeset
|
302 #ifdef ENABLE_DEBUG |
1257
05dc45e7c7bb
Add command line option -v
Mikael Berthe <mikael@lilotux.net>
parents:
1256
diff
changeset
|
303 puts("Compiled with debugging support."); |
05dc45e7c7bb
Add command line option -v
Mikael Berthe <mikael@lilotux.net>
parents:
1256
diff
changeset
|
304 #endif |
05dc45e7c7bb
Add command line option -v
Mikael Berthe <mikael@lilotux.net>
parents:
1256
diff
changeset
|
305 } |
05dc45e7c7bb
Add command line option -v
Mikael Berthe <mikael@lilotux.net>
parents:
1256
diff
changeset
|
306 |
05dc45e7c7bb
Add command line option -v
Mikael Berthe <mikael@lilotux.net>
parents:
1256
diff
changeset
|
307 static void main_init_pgp(void) |
1042
8a395c2cafc4
Initial PGP support (decrypt)
Mikael Berthe <mikael@lilotux.net>
parents:
993
diff
changeset
|
308 { |
8a395c2cafc4
Initial PGP support (decrypt)
Mikael Berthe <mikael@lilotux.net>
parents:
993
diff
changeset
|
309 #ifdef HAVE_GPGME |
8a395c2cafc4
Initial PGP support (decrypt)
Mikael Berthe <mikael@lilotux.net>
parents:
993
diff
changeset
|
310 const char *pk, *pp; |
8a395c2cafc4
Initial PGP support (decrypt)
Mikael Berthe <mikael@lilotux.net>
parents:
993
diff
changeset
|
311 char *typed_passwd = NULL; |
1238
80008fe2a4f2
Re-enable gpg-agent (revert 591d8b35c881)
Mikael Berthe <mikael@lilotux.net>
parents:
1223
diff
changeset
|
312 char *p; |
1042
8a395c2cafc4
Initial PGP support (decrypt)
Mikael Berthe <mikael@lilotux.net>
parents:
993
diff
changeset
|
313 bool pgp_invalid = FALSE; |
8a395c2cafc4
Initial PGP support (decrypt)
Mikael Berthe <mikael@lilotux.net>
parents:
993
diff
changeset
|
314 bool pgp_agent; |
1313
d1d12a09b04a
Make passphrase entry retries customizable (suggested by Till Maas)
Mikael Berthe <mikael@lilotux.net>
parents:
1311
diff
changeset
|
315 int retries; |
1042
8a395c2cafc4
Initial PGP support (decrypt)
Mikael Berthe <mikael@lilotux.net>
parents:
993
diff
changeset
|
316 |
1238
80008fe2a4f2
Re-enable gpg-agent (revert 591d8b35c881)
Mikael Berthe <mikael@lilotux.net>
parents:
1223
diff
changeset
|
317 p = getenv("GPG_AGENT_INFO"); |
80008fe2a4f2
Re-enable gpg-agent (revert 591d8b35c881)
Mikael Berthe <mikael@lilotux.net>
parents:
1223
diff
changeset
|
318 pgp_agent = (p && strchr(p, ':')); |
1042
8a395c2cafc4
Initial PGP support (decrypt)
Mikael Berthe <mikael@lilotux.net>
parents:
993
diff
changeset
|
319 |
8a395c2cafc4
Initial PGP support (decrypt)
Mikael Berthe <mikael@lilotux.net>
parents:
993
diff
changeset
|
320 pk = settings_opt_get("pgp_private_key"); |
8a395c2cafc4
Initial PGP support (decrypt)
Mikael Berthe <mikael@lilotux.net>
parents:
993
diff
changeset
|
321 pp = settings_opt_get("pgp_passphrase"); |
1313
d1d12a09b04a
Make passphrase entry retries customizable (suggested by Till Maas)
Mikael Berthe <mikael@lilotux.net>
parents:
1311
diff
changeset
|
322 |
d1d12a09b04a
Make passphrase entry retries customizable (suggested by Till Maas)
Mikael Berthe <mikael@lilotux.net>
parents:
1311
diff
changeset
|
323 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
|
324 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
|
325 else |
d1d12a09b04a
Make passphrase entry retries customizable (suggested by Till Maas)
Mikael Berthe <mikael@lilotux.net>
parents:
1311
diff
changeset
|
326 retries = 2; |
d1d12a09b04a
Make passphrase entry retries customizable (suggested by Till Maas)
Mikael Berthe <mikael@lilotux.net>
parents:
1311
diff
changeset
|
327 |
1042
8a395c2cafc4
Initial PGP support (decrypt)
Mikael Berthe <mikael@lilotux.net>
parents:
993
diff
changeset
|
328 if (!pk) { |
8a395c2cafc4
Initial PGP support (decrypt)
Mikael Berthe <mikael@lilotux.net>
parents:
993
diff
changeset
|
329 scr_LogPrint(LPRINT_LOGNORM, "WARNING: unkown PGP private key"); |
8a395c2cafc4
Initial PGP support (decrypt)
Mikael Berthe <mikael@lilotux.net>
parents:
993
diff
changeset
|
330 pgp_invalid = TRUE; |
8a395c2cafc4
Initial PGP support (decrypt)
Mikael Berthe <mikael@lilotux.net>
parents:
993
diff
changeset
|
331 } else if (!(pp || pgp_agent)) { |
8a395c2cafc4
Initial PGP support (decrypt)
Mikael Berthe <mikael@lilotux.net>
parents:
993
diff
changeset
|
332 // Request PGP passphrase |
8a395c2cafc4
Initial PGP support (decrypt)
Mikael Berthe <mikael@lilotux.net>
parents:
993
diff
changeset
|
333 pp = typed_passwd = ask_password("PGP passphrase"); |
8a395c2cafc4
Initial PGP support (decrypt)
Mikael Berthe <mikael@lilotux.net>
parents:
993
diff
changeset
|
334 } |
8a395c2cafc4
Initial PGP support (decrypt)
Mikael Berthe <mikael@lilotux.net>
parents:
993
diff
changeset
|
335 gpg_init(pk, pp); |
8a395c2cafc4
Initial PGP support (decrypt)
Mikael Berthe <mikael@lilotux.net>
parents:
993
diff
changeset
|
336 // Erase password from the settings array |
8a395c2cafc4
Initial PGP support (decrypt)
Mikael Berthe <mikael@lilotux.net>
parents:
993
diff
changeset
|
337 if (pp) { |
8a395c2cafc4
Initial PGP support (decrypt)
Mikael Berthe <mikael@lilotux.net>
parents:
993
diff
changeset
|
338 memset((char*)pp, 0, strlen(pp)); |
8a395c2cafc4
Initial PGP support (decrypt)
Mikael Berthe <mikael@lilotux.net>
parents:
993
diff
changeset
|
339 if (typed_passwd) |
8a395c2cafc4
Initial PGP support (decrypt)
Mikael Berthe <mikael@lilotux.net>
parents:
993
diff
changeset
|
340 g_free(typed_passwd); |
8a395c2cafc4
Initial PGP support (decrypt)
Mikael Berthe <mikael@lilotux.net>
parents:
993
diff
changeset
|
341 else |
8a395c2cafc4
Initial PGP support (decrypt)
Mikael Berthe <mikael@lilotux.net>
parents:
993
diff
changeset
|
342 settings_set(SETTINGS_TYPE_OPTION, "pgp_passphrase", NULL); |
8a395c2cafc4
Initial PGP support (decrypt)
Mikael Berthe <mikael@lilotux.net>
parents:
993
diff
changeset
|
343 } |
8a395c2cafc4
Initial PGP support (decrypt)
Mikael Berthe <mikael@lilotux.net>
parents:
993
diff
changeset
|
344 if (!pgp_agent && pk && pp && gpg_test_passphrase()) { |
8a395c2cafc4
Initial PGP support (decrypt)
Mikael Berthe <mikael@lilotux.net>
parents:
993
diff
changeset
|
345 // Let's check the pasphrase |
8a395c2cafc4
Initial PGP support (decrypt)
Mikael Berthe <mikael@lilotux.net>
parents:
993
diff
changeset
|
346 int i; |
1313
d1d12a09b04a
Make passphrase entry retries customizable (suggested by Till Maas)
Mikael Berthe <mikael@lilotux.net>
parents:
1311
diff
changeset
|
347 for (i = 1; retries < 0 || i <= retries; i++) { |
1042
8a395c2cafc4
Initial PGP support (decrypt)
Mikael Berthe <mikael@lilotux.net>
parents:
993
diff
changeset
|
348 typed_passwd = ask_password("PGP passphrase"); // Ask again... |
8a395c2cafc4
Initial PGP support (decrypt)
Mikael Berthe <mikael@lilotux.net>
parents:
993
diff
changeset
|
349 if (typed_passwd) { |
8a395c2cafc4
Initial PGP support (decrypt)
Mikael Berthe <mikael@lilotux.net>
parents:
993
diff
changeset
|
350 gpg_set_passphrase(typed_passwd); |
8a395c2cafc4
Initial PGP support (decrypt)
Mikael Berthe <mikael@lilotux.net>
parents:
993
diff
changeset
|
351 memset(typed_passwd, 0, strlen(typed_passwd)); |
8a395c2cafc4
Initial PGP support (decrypt)
Mikael Berthe <mikael@lilotux.net>
parents:
993
diff
changeset
|
352 g_free(typed_passwd); |
8a395c2cafc4
Initial PGP support (decrypt)
Mikael Berthe <mikael@lilotux.net>
parents:
993
diff
changeset
|
353 } |
8a395c2cafc4
Initial PGP support (decrypt)
Mikael Berthe <mikael@lilotux.net>
parents:
993
diff
changeset
|
354 if (!gpg_test_passphrase()) |
8a395c2cafc4
Initial PGP support (decrypt)
Mikael Berthe <mikael@lilotux.net>
parents:
993
diff
changeset
|
355 break; // Ok |
8a395c2cafc4
Initial PGP support (decrypt)
Mikael Berthe <mikael@lilotux.net>
parents:
993
diff
changeset
|
356 } |
1313
d1d12a09b04a
Make passphrase entry retries customizable (suggested by Till Maas)
Mikael Berthe <mikael@lilotux.net>
parents:
1311
diff
changeset
|
357 if (i > retries) |
1042
8a395c2cafc4
Initial PGP support (decrypt)
Mikael Berthe <mikael@lilotux.net>
parents:
993
diff
changeset
|
358 pgp_invalid = TRUE; |
8a395c2cafc4
Initial PGP support (decrypt)
Mikael Berthe <mikael@lilotux.net>
parents:
993
diff
changeset
|
359 } |
8a395c2cafc4
Initial PGP support (decrypt)
Mikael Berthe <mikael@lilotux.net>
parents:
993
diff
changeset
|
360 if (pgp_invalid) |
8a395c2cafc4
Initial PGP support (decrypt)
Mikael Berthe <mikael@lilotux.net>
parents:
993
diff
changeset
|
361 scr_LogPrint(LPRINT_LOGNORM, "WARNING: PGP key/pass invalid"); |
8a395c2cafc4
Initial PGP support (decrypt)
Mikael Berthe <mikael@lilotux.net>
parents:
993
diff
changeset
|
362 #else /* not HAVE_GPGME */ |
8a395c2cafc4
Initial PGP support (decrypt)
Mikael Berthe <mikael@lilotux.net>
parents:
993
diff
changeset
|
363 scr_LogPrint(LPRINT_LOGNORM, "WARNING: not compiled with PGP support"); |
8a395c2cafc4
Initial PGP support (decrypt)
Mikael Berthe <mikael@lilotux.net>
parents:
993
diff
changeset
|
364 #endif /* HAVE_GPGME */ |
8a395c2cafc4
Initial PGP support (decrypt)
Mikael Berthe <mikael@lilotux.net>
parents:
993
diff
changeset
|
365 } |
8a395c2cafc4
Initial PGP support (decrypt)
Mikael Berthe <mikael@lilotux.net>
parents:
993
diff
changeset
|
366 |
1359
7daf906fbcdc
The command /quit can be used in bindings, hooks and sourced files
Mikael Berthe <mikael@lilotux.net>
parents:
1313
diff
changeset
|
367 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
|
368 { |
7daf906fbcdc
The command /quit can be used in bindings, hooks and sourced files
Mikael Berthe <mikael@lilotux.net>
parents:
1313
diff
changeset
|
369 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
|
370 } |
7daf906fbcdc
The command /quit can be used in bindings, hooks and sourced files
Mikael Berthe <mikael@lilotux.net>
parents:
1313
diff
changeset
|
371 |
24 | 372 int main(int argc, char **argv) |
373 { | |
169 | 374 char *configFile = NULL; |
281
f562b9af2de7
Add "const" specifier in prototypes
Mikael Berthe <mikael@lilotux.net>
parents:
279
diff
changeset
|
375 const char *optstring; |
177 | 376 int optval, optval2; |
24 | 377 unsigned int ping; |
333
db5bebe96c89
New config. file parsing
Mikael Berthe <mikael@lilotux.net>
parents:
322
diff
changeset
|
378 int ret; |
761
4532a9fe0e8c
Handle some keyboard escape sequences
Mikael Berthe <mikael@lilotux.net>
parents:
699
diff
changeset
|
379 keycode kcode; |
24 | 380 |
381 credits(); | |
382 | |
383 signal(SIGTERM, sig_handler); | |
312
f0b7ff2df7e8
Ctrl-C does not terminate mcabber
Mikael Berthe <mikael@lilotux.net>
parents:
307
diff
changeset
|
384 signal(SIGINT, sig_handler); |
163 | 385 signal(SIGCHLD, sig_handler); |
1454
6b98dc22946d
Add optional SIGWINCH handler (Markus Hennecke)
Mikael Berthe <mikael@lilotux.net>
parents:
1448
diff
changeset
|
386 #ifdef USE_SIGWINCH |
6b98dc22946d
Add optional SIGWINCH handler (Markus Hennecke)
Mikael Berthe <mikael@lilotux.net>
parents:
1448
diff
changeset
|
387 signal(SIGWINCH, sig_handler); |
6b98dc22946d
Add optional SIGWINCH handler (Markus Hennecke)
Mikael Berthe <mikael@lilotux.net>
parents:
1448
diff
changeset
|
388 #endif |
413 | 389 signal(SIGPIPE, SIG_IGN); |
24 | 390 |
77 | 391 /* Parse command line options */ |
24 | 392 while (1) { |
1259
c5c09f8f60b0
Change command line option -v to -V
Mikael Berthe <mikael@lilotux.net>
parents:
1257
diff
changeset
|
393 int c = getopt(argc, argv, "hVf:"); |
24 | 394 if (c == -1) { |
395 break; | |
396 } else | |
397 switch (c) { | |
398 case 'h': | |
1256
ea679e3598a9
Don't start when command line options are wrong
Mikael Berthe <mikael@lilotux.net>
parents:
1253
diff
changeset
|
399 case '?': |
1259
c5c09f8f60b0
Change command line option -v to -V
Mikael Berthe <mikael@lilotux.net>
parents:
1257
diff
changeset
|
400 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
|
401 return (c == 'h' ? 0 : -1); |
1259
c5c09f8f60b0
Change command line option -v to -V
Mikael Berthe <mikael@lilotux.net>
parents:
1257
diff
changeset
|
402 case 'V': |
1257
05dc45e7c7bb
Add command line option -v
Mikael Berthe <mikael@lilotux.net>
parents:
1256
diff
changeset
|
403 compile_options(); |
05dc45e7c7bb
Add command line option -v
Mikael Berthe <mikael@lilotux.net>
parents:
1256
diff
changeset
|
404 return 0; |
24 | 405 case 'f': |
1241 | 406 configFile = g_strdup(optarg); |
407 break; | |
24 | 408 } |
409 } | |
410 | |
1256
ea679e3598a9
Don't start when command line options are wrong
Mikael Berthe <mikael@lilotux.net>
parents:
1253
diff
changeset
|
411 if (optind < argc) { |
1259
c5c09f8f60b0
Change command line option -v to -V
Mikael Berthe <mikael@lilotux.net>
parents:
1257
diff
changeset
|
412 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
|
413 return -1; |
ea679e3598a9
Don't start when command line options are wrong
Mikael Berthe <mikael@lilotux.net>
parents:
1253
diff
changeset
|
414 } |
ea679e3598a9
Don't start when command line options are wrong
Mikael Berthe <mikael@lilotux.net>
parents:
1253
diff
changeset
|
415 |
1176
547a8ca7c1a8
Move init_bindings() to screen.c, with a few updates
Mikael Berthe <mikael@lilotux.net>
parents:
1173
diff
changeset
|
416 /* Initialize command system, roster and default key bindings */ |
333
db5bebe96c89
New config. file parsing
Mikael Berthe <mikael@lilotux.net>
parents:
322
diff
changeset
|
417 cmd_init(); |
848
a9161d2dc414
Introduce special buffer stuff
Mikael Berthe <mikael@lilotux.net>
parents:
815
diff
changeset
|
418 roster_init(); |
1065
230dca34dbea
Extand pgp_data structure
Mikael Berthe <mikael@lilotux.net>
parents:
1058
diff
changeset
|
419 settings_init(); |
1176
547a8ca7c1a8
Move init_bindings() to screen.c, with a few updates
Mikael Berthe <mikael@lilotux.net>
parents:
1173
diff
changeset
|
420 scr_init_bindings(); |
779
057ffe7c43dc
Initialize locale charset earlier
Mikael Berthe <mikael@lilotux.net>
parents:
777
diff
changeset
|
421 /* Initialize charset */ |
057ffe7c43dc
Initialize locale charset earlier
Mikael Berthe <mikael@lilotux.net>
parents:
777
diff
changeset
|
422 scr_InitLocaleCharSet(); |
333
db5bebe96c89
New config. file parsing
Mikael Berthe <mikael@lilotux.net>
parents:
322
diff
changeset
|
423 |
24 | 424 /* Parsing config file... */ |
1192 | 425 ret = cfg_read_file(configFile, TRUE); |
374
bd5638c21834
Improve logging system (traces)
Mikael Berthe <mikael@lilotux.net>
parents:
364
diff
changeset
|
426 /* 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
|
427 g_free(configFile); |
333
db5bebe96c89
New config. file parsing
Mikael Berthe <mikael@lilotux.net>
parents:
322
diff
changeset
|
428 /* 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
|
429 if (ret == -2) |
333
db5bebe96c89
New config. file parsing
Mikael Berthe <mikael@lilotux.net>
parents:
322
diff
changeset
|
430 exit(EXIT_FAILURE); |
24 | 431 |
374
bd5638c21834
Improve logging system (traces)
Mikael Berthe <mikael@lilotux.net>
parents:
364
diff
changeset
|
432 optstring = settings_opt_get("tracelog_file"); |
bd5638c21834
Improve logging system (traces)
Mikael Berthe <mikael@lilotux.net>
parents:
364
diff
changeset
|
433 if (optstring) |
bd5638c21834
Improve logging system (traces)
Mikael Berthe <mikael@lilotux.net>
parents:
364
diff
changeset
|
434 ut_InitDebug(settings_opt_get_int("tracelog_level"), optstring); |
138 | 435 |
306
b2d11b11675f
Fix interactive password prompt
Mikael Berthe <mikael@lilotux.net>
parents:
300
diff
changeset
|
436 /* 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
|
437 ncurses mode -- unless the username is unknown. */ |
a0ddc43b421e
Don't stop when there is no configuration file
Mikael Berthe <mikael@lilotux.net>
parents:
855
diff
changeset
|
438 if (settings_opt_get("username") && !settings_opt_get("password")) { |
855
cbeedd730b1b
Display username before asking for password
Mikael Berthe <mikael@lilotux.net>
parents:
851
diff
changeset
|
439 const char *p; |
1123 | 440 char *pwd; |
855
cbeedd730b1b
Display username before asking for password
Mikael Berthe <mikael@lilotux.net>
parents:
851
diff
changeset
|
441 p = settings_opt_get("server"); |
cbeedd730b1b
Display username before asking for password
Mikael Berthe <mikael@lilotux.net>
parents:
851
diff
changeset
|
442 if (p) |
cbeedd730b1b
Display username before asking for password
Mikael Berthe <mikael@lilotux.net>
parents:
851
diff
changeset
|
443 printf("Server: %s\n", p); |
cbeedd730b1b
Display username before asking for password
Mikael Berthe <mikael@lilotux.net>
parents:
851
diff
changeset
|
444 p = settings_opt_get("username"); |
cbeedd730b1b
Display username before asking for password
Mikael Berthe <mikael@lilotux.net>
parents:
851
diff
changeset
|
445 if (p) |
cbeedd730b1b
Display username before asking for password
Mikael Berthe <mikael@lilotux.net>
parents:
851
diff
changeset
|
446 printf("Username: %s\n", p); |
1123 | 447 |
448 pwd = ask_password("Jabber password"); | |
449 settings_set(SETTINGS_TYPE_OPTION, "password", pwd); | |
450 g_free(pwd); | |
415
5692c3a13202
Display the server name/IP before asking for password
Mikael Berthe <mikael@lilotux.net>
parents:
413
diff
changeset
|
451 } |
24 | 452 |
1042
8a395c2cafc4
Initial PGP support (decrypt)
Mikael Berthe <mikael@lilotux.net>
parents:
993
diff
changeset
|
453 /* Initialize PGP system |
8a395c2cafc4
Initial PGP support (decrypt)
Mikael Berthe <mikael@lilotux.net>
parents:
993
diff
changeset
|
454 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
|
455 a passphrase. */ |
8a395c2cafc4
Initial PGP support (decrypt)
Mikael Berthe <mikael@lilotux.net>
parents:
993
diff
changeset
|
456 if (settings_opt_get_int("pgp")) |
8a395c2cafc4
Initial PGP support (decrypt)
Mikael Berthe <mikael@lilotux.net>
parents:
993
diff
changeset
|
457 main_init_pgp(); |
8a395c2cafc4
Initial PGP support (decrypt)
Mikael Berthe <mikael@lilotux.net>
parents:
993
diff
changeset
|
458 |
24 | 459 /* Initialize N-Curses */ |
374
bd5638c21834
Improve logging system (traces)
Mikael Berthe <mikael@lilotux.net>
parents:
364
diff
changeset
|
460 scr_LogPrint(LPRINT_DEBUG, "Initializing N-Curses..."); |
24 | 461 scr_InitCurses(); |
151 | 462 scr_DrawMainWindow(TRUE); |
29 | 463 |
279
f5dd437c057b
Rewrite the settings system
Mikael Berthe <mikael@lilotux.net>
parents:
272
diff
changeset
|
464 optval = (settings_opt_get_int("logging") > 0); |
f5dd437c057b
Rewrite the settings system
Mikael Berthe <mikael@lilotux.net>
parents:
272
diff
changeset
|
465 optval2 = (settings_opt_get_int("load_logs") > 0); |
177 | 466 if (optval || optval2) |
298
35cda94e570d
Add /connect and /disconnect commands
Mikael Berthe <mikael@lilotux.net>
parents:
281
diff
changeset
|
467 hlog_enable(optval, settings_opt_get("logging_dir"), optval2); |
113 | 468 |
1179 | 469 #ifdef HAVE_ASPELL_H |
470 /* Initialize aspell */ | |
471 if (settings_opt_get_int("aspell_enable")) { | |
472 spellcheck_init(); | |
473 } | |
474 #endif | |
475 | |
279
f5dd437c057b
Rewrite the settings system
Mikael Berthe <mikael@lilotux.net>
parents:
272
diff
changeset
|
476 optstring = settings_opt_get("events_command"); |
f5dd437c057b
Rewrite the settings system
Mikael Berthe <mikael@lilotux.net>
parents:
272
diff
changeset
|
477 if (optstring) |
160 | 478 hk_ext_cmd_init(optstring); |
479 | |
112 | 480 ping = 40; |
279
f5dd437c057b
Rewrite the settings system
Mikael Berthe <mikael@lilotux.net>
parents:
272
diff
changeset
|
481 if (settings_opt_get("pinginterval")) |
f5dd437c057b
Rewrite the settings system
Mikael Berthe <mikael@lilotux.net>
parents:
272
diff
changeset
|
482 ping = (unsigned int) settings_opt_get_int("pinginterval"); |
112 | 483 jb_set_keepalive_delay(ping); |
374
bd5638c21834
Improve logging system (traces)
Mikael Berthe <mikael@lilotux.net>
parents:
364
diff
changeset
|
484 scr_LogPrint(LPRINT_DEBUG, "Ping interval established: %d secs", ping); |
24 | 485 |
1311
0dda8238af21
Implement "/roster display"
Mikael Berthe <mikael@lilotux.net>
parents:
1307
diff
changeset
|
486 if (settings_opt_get_int("hide_offline_buddies") > 0) { // XXX Deprecated |
0dda8238af21
Implement "/roster display"
Mikael Berthe <mikael@lilotux.net>
parents:
1307
diff
changeset
|
487 scr_RosterDisplay("ofdna"); |
0dda8238af21
Implement "/roster display"
Mikael Berthe <mikael@lilotux.net>
parents:
1307
diff
changeset
|
488 scr_LogPrint(LPRINT_LOGNORM, |
0dda8238af21
Implement "/roster display"
Mikael Berthe <mikael@lilotux.net>
parents:
1307
diff
changeset
|
489 "* Warning: 'hide_offline_buddies' is deprecated."); |
0dda8238af21
Implement "/roster display"
Mikael Berthe <mikael@lilotux.net>
parents:
1307
diff
changeset
|
490 } else { |
0dda8238af21
Implement "/roster display"
Mikael Berthe <mikael@lilotux.net>
parents:
1307
diff
changeset
|
491 optstring = settings_opt_get("roster_display_filter"); |
0dda8238af21
Implement "/roster display"
Mikael Berthe <mikael@lilotux.net>
parents:
1307
diff
changeset
|
492 if (optstring) |
0dda8238af21
Implement "/roster display"
Mikael Berthe <mikael@lilotux.net>
parents:
1307
diff
changeset
|
493 scr_RosterDisplay(optstring); |
0dda8238af21
Implement "/roster display"
Mikael Berthe <mikael@lilotux.net>
parents:
1307
diff
changeset
|
494 // Empty filter isn't allowed... |
0dda8238af21
Implement "/roster display"
Mikael Berthe <mikael@lilotux.net>
parents:
1307
diff
changeset
|
495 if (!buddylist_get_filter()) |
0dda8238af21
Implement "/roster display"
Mikael Berthe <mikael@lilotux.net>
parents:
1307
diff
changeset
|
496 scr_RosterDisplay("*"); |
0dda8238af21
Implement "/roster display"
Mikael Berthe <mikael@lilotux.net>
parents:
1307
diff
changeset
|
497 } |
87 | 498 |
993
0759f4c7da68
Add option 'disable_chatstates'
Mikael Berthe <mikael@lilotux.net>
parents:
962
diff
changeset
|
499 chatstates_disabled = settings_opt_get_int("disable_chatstates"); |
0759f4c7da68
Add option 'disable_chatstates'
Mikael Berthe <mikael@lilotux.net>
parents:
962
diff
changeset
|
500 |
1426
a64778f5f26b
Implement FIFO named command pipe
Mikael Berthe <mikael@lilotux.net>
parents:
1425
diff
changeset
|
501 /* Initialize FIFO named pipe */ |
a64778f5f26b
Implement FIFO named command pipe
Mikael Berthe <mikael@lilotux.net>
parents:
1425
diff
changeset
|
502 fifo_init(settings_opt_get("fifo_name")); |
a64778f5f26b
Implement FIFO named command pipe
Mikael Berthe <mikael@lilotux.net>
parents:
1425
diff
changeset
|
503 |
1437
071c8170b7de
Add option 'statefile' to keep track of unread messages across restarts
Mikael Berthe <mikael@lilotux.net>
parents:
1426
diff
changeset
|
504 /* 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
|
505 hlog_load_state(); |
071c8170b7de
Add option 'statefile' to keep track of unread messages across restarts
Mikael Berthe <mikael@lilotux.net>
parents:
1426
diff
changeset
|
506 |
872
a0ddc43b421e
Don't stop when there is no configuration file
Mikael Berthe <mikael@lilotux.net>
parents:
855
diff
changeset
|
507 if (ret < 0) { |
a0ddc43b421e
Don't stop when there is no configuration file
Mikael Berthe <mikael@lilotux.net>
parents:
855
diff
changeset
|
508 scr_LogPrint(LPRINT_NORMAL, "No configuration file has been found."); |
a0ddc43b421e
Don't stop when there is no configuration file
Mikael Berthe <mikael@lilotux.net>
parents:
855
diff
changeset
|
509 scr_ShowBuddyWindow(); |
a0ddc43b421e
Don't stop when there is no configuration file
Mikael Berthe <mikael@lilotux.net>
parents:
855
diff
changeset
|
510 } else { |
a0ddc43b421e
Don't stop when there is no configuration file
Mikael Berthe <mikael@lilotux.net>
parents:
855
diff
changeset
|
511 /* Connection */ |
306
b2d11b11675f
Fix interactive password prompt
Mikael Berthe <mikael@lilotux.net>
parents:
300
diff
changeset
|
512 mcabber_connect(); |
872
a0ddc43b421e
Don't stop when there is no configuration file
Mikael Berthe <mikael@lilotux.net>
parents:
855
diff
changeset
|
513 } |
298
35cda94e570d
Add /connect and /disconnect commands
Mikael Berthe <mikael@lilotux.net>
parents:
281
diff
changeset
|
514 |
374
bd5638c21834
Improve logging system (traces)
Mikael Berthe <mikael@lilotux.net>
parents:
364
diff
changeset
|
515 scr_LogPrint(LPRINT_DEBUG, "Entering into main loop..."); |
112 | 516 |
1359
7daf906fbcdc
The command /quit can be used in bindings, hooks and sourced files
Mikael Berthe <mikael@lilotux.net>
parents:
1313
diff
changeset
|
517 while (!terminate_ui) { |
939
12fa2ae6445d
Get rid of "busy-waiting" (Christof Meerwald)
Mikael Berthe <mikael@lilotux.net>
parents:
938
diff
changeset
|
518 scr_DoUpdate(); |
761
4532a9fe0e8c
Handle some keyboard escape sequences
Mikael Berthe <mikael@lilotux.net>
parents:
699
diff
changeset
|
519 scr_Getch(&kcode); |
151 | 520 |
939
12fa2ae6445d
Get rid of "busy-waiting" (Christof Meerwald)
Mikael Berthe <mikael@lilotux.net>
parents:
938
diff
changeset
|
521 if (kcode.value != ERR) { |
1359
7daf906fbcdc
The command /quit can be used in bindings, hooks and sourced files
Mikael Berthe <mikael@lilotux.net>
parents:
1313
diff
changeset
|
522 process_key(kcode); |
939
12fa2ae6445d
Get rid of "busy-waiting" (Christof Meerwald)
Mikael Berthe <mikael@lilotux.net>
parents:
938
diff
changeset
|
523 } else { |
322
da138cdebf04
Implement auto-away mode
Mikael Berthe <mikael@lilotux.net>
parents:
314
diff
changeset
|
524 scr_CheckAutoAway(FALSE); |
939
12fa2ae6445d
Get rid of "busy-waiting" (Christof Meerwald)
Mikael Berthe <mikael@lilotux.net>
parents:
938
diff
changeset
|
525 |
12fa2ae6445d
Get rid of "busy-waiting" (Christof Meerwald)
Mikael Berthe <mikael@lilotux.net>
parents:
938
diff
changeset
|
526 if (update_roster) |
1241 | 527 scr_DrawRoster(); |
939
12fa2ae6445d
Get rid of "busy-waiting" (Christof Meerwald)
Mikael Berthe <mikael@lilotux.net>
parents:
938
diff
changeset
|
528 |
12fa2ae6445d
Get rid of "busy-waiting" (Christof Meerwald)
Mikael Berthe <mikael@lilotux.net>
parents:
938
diff
changeset
|
529 jb_main(); |
1425 | 530 hk_mainloop(); |
152 | 531 } |
24 | 532 } |
533 | |
1307
6c116207ab2e
Work around segfault in otrl_userstate_free()
Mikael Berthe <mikael@lilotux.net>
parents:
1299
diff
changeset
|
534 scr_TerminateCurses(); |
1426
a64778f5f26b
Implement FIFO named command pipe
Mikael Berthe <mikael@lilotux.net>
parents:
1425
diff
changeset
|
535 fifo_deinit(); |
1299
3b338a5c01fc
OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
1259
diff
changeset
|
536 #ifdef HAVE_LIBOTR |
3b338a5c01fc
OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
1259
diff
changeset
|
537 otr_terminate(); |
3b338a5c01fc
OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
1259
diff
changeset
|
538 #endif |
35 | 539 jb_disconnect(); |
1042
8a395c2cafc4
Initial PGP support (decrypt)
Mikael Berthe <mikael@lilotux.net>
parents:
993
diff
changeset
|
540 #ifdef HAVE_GPGME |
8a395c2cafc4
Initial PGP support (decrypt)
Mikael Berthe <mikael@lilotux.net>
parents:
993
diff
changeset
|
541 gpg_terminate(); |
8a395c2cafc4
Initial PGP support (decrypt)
Mikael Berthe <mikael@lilotux.net>
parents:
993
diff
changeset
|
542 #endif |
1179 | 543 #ifdef HAVE_ASPELL_H |
544 /* Deinitialize aspell */ | |
1437
071c8170b7de
Add option 'statefile' to keep track of unread messages across restarts
Mikael Berthe <mikael@lilotux.net>
parents:
1426
diff
changeset
|
545 if (settings_opt_get_int("aspell_enable")) |
1179 | 546 spellcheck_deinit(); |
547 #endif | |
1437
071c8170b7de
Add option 'statefile' to keep track of unread messages across restarts
Mikael Berthe <mikael@lilotux.net>
parents:
1426
diff
changeset
|
548 /* 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
|
549 hlog_save_state(); |
24 | 550 |
961
95659cf9ea1a
Display mcabber version in the status window
Mikael Berthe <mikael@lilotux.net>
parents:
955
diff
changeset
|
551 printf("\n\nThanks for using mcabber!\n"); |
24 | 552 |
553 return 0; | |
554 } | |
576 | 555 |
580 | 556 /* vim: set expandtab cindent cinoptions=>2\:2(0: For Vim users... */ |