Mercurial > hg
annotate mcabber/src/main.c @ 1617:9ca672ee884f
Fix previous commit :)
author | Mikael Berthe <mikael@lilotux.net> |
---|---|
date | Sun, 11 Oct 2009 22:47:12 +0200 |
parents | 6db9f403f707 |
children | 9296987856d9 |
rev | line source |
---|---|
307 | 1 /* |
2 * main.c | |
393 | 3 * |
1599 | 4 * Copyright (C) 2005-2009 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 |
1600 | 34 #include "caps.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" |
1598 | 45 #include "xmpp.h" |
1426
a64778f5f26b
Implement FIFO named command pipe
Mikael Berthe <mikael@lilotux.net>
parents:
1425
diff
changeset
|
46 |
781
d3af6877a7df
Add --enable-hgcset to configure script
Mikael Berthe <mikael@lilotux.net>
parents:
779
diff
changeset
|
47 #ifdef ENABLE_HGCSET |
d3af6877a7df
Add --enable-hgcset to configure script
Mikael Berthe <mikael@lilotux.net>
parents:
779
diff
changeset
|
48 # include "hgcset.h" |
d3af6877a7df
Add --enable-hgcset to configure script
Mikael Berthe <mikael@lilotux.net>
parents:
779
diff
changeset
|
49 #endif |
24 | 50 |
801
d8e0a1ce3e8a
Define WAIT_ANY if needed.
Soren Andersen <somian@pobox.com>
parents:
789
diff
changeset
|
51 #ifndef WAIT_ANY |
1053 | 52 # define WAIT_ANY -1 |
801
d8e0a1ce3e8a
Define WAIT_ANY if needed.
Soren Andersen <somian@pobox.com>
parents:
789
diff
changeset
|
53 #endif |
24 | 54 |
1359
7daf906fbcdc
The command /quit can be used in bindings, hooks and sourced files
Mikael Berthe <mikael@lilotux.net>
parents:
1313
diff
changeset
|
55 static unsigned int terminate_ui; |
1598 | 56 GMainLoop *main_loop = NULL; |
1359
7daf906fbcdc
The command /quit can be used in bindings, hooks and sourced files
Mikael Berthe <mikael@lilotux.net>
parents:
1313
diff
changeset
|
57 |
789
1fa93cc6f5e3
Correctly restore term settings when interrupting the password query
Mikael Berthe <mikael@lilotux.net>
parents:
784
diff
changeset
|
58 static struct termios *backup_termios; |
1fa93cc6f5e3
Correctly restore term settings when interrupting the password query
Mikael Berthe <mikael@lilotux.net>
parents:
784
diff
changeset
|
59 |
777
e6d42f239541
"/version" shows Mercurial changeset (if there's one)
Mikael Berthe <mikael@lilotux.net>
parents:
774
diff
changeset
|
60 char *mcabber_version(void) |
e6d42f239541
"/version" shows Mercurial changeset (if there's one)
Mikael Berthe <mikael@lilotux.net>
parents:
774
diff
changeset
|
61 { |
e6d42f239541
"/version" shows Mercurial changeset (if there's one)
Mikael Berthe <mikael@lilotux.net>
parents:
774
diff
changeset
|
62 char *ver; |
e6d42f239541
"/version" shows Mercurial changeset (if there's one)
Mikael Berthe <mikael@lilotux.net>
parents:
774
diff
changeset
|
63 #ifdef HGCSET |
e6d42f239541
"/version" shows Mercurial changeset (if there's one)
Mikael Berthe <mikael@lilotux.net>
parents:
774
diff
changeset
|
64 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
|
65 #else |
e6d42f239541
"/version" shows Mercurial changeset (if there's one)
Mikael Berthe <mikael@lilotux.net>
parents:
774
diff
changeset
|
66 ver = g_strdup(PACKAGE_VERSION); |
e6d42f239541
"/version" shows Mercurial changeset (if there's one)
Mikael Berthe <mikael@lilotux.net>
parents:
774
diff
changeset
|
67 #endif |
e6d42f239541
"/version" shows Mercurial changeset (if there's one)
Mikael Berthe <mikael@lilotux.net>
parents:
774
diff
changeset
|
68 return ver; |
e6d42f239541
"/version" shows Mercurial changeset (if there's one)
Mikael Berthe <mikael@lilotux.net>
parents:
774
diff
changeset
|
69 } |
e6d42f239541
"/version" shows Mercurial changeset (if there's one)
Mikael Berthe <mikael@lilotux.net>
parents:
774
diff
changeset
|
70 |
962
e79af58cd0be
mcabber_disconnect() -> static mcabber_terminate()
Mikael Berthe <mikael@lilotux.net>
parents:
961
diff
changeset
|
71 static void mcabber_terminate(const char *msg) |
312
f0b7ff2df7e8
Ctrl-C does not terminate mcabber
Mikael Berthe <mikael@lilotux.net>
parents:
307
diff
changeset
|
72 { |
1545
31472d421267
Clean up FIFO on SIGTERM (T. Glaser)
Mikael Berthe <mikael@lilotux.net>
parents:
1530
diff
changeset
|
73 fifo_deinit(); |
1598 | 74 xmpp_disconnect(); |
312
f0b7ff2df7e8
Ctrl-C does not terminate mcabber
Mikael Berthe <mikael@lilotux.net>
parents:
307
diff
changeset
|
75 scr_TerminateCurses(); |
789
1fa93cc6f5e3
Correctly restore term settings when interrupting the password query
Mikael Berthe <mikael@lilotux.net>
parents:
784
diff
changeset
|
76 |
1fa93cc6f5e3
Correctly restore term settings when interrupting the password query
Mikael Berthe <mikael@lilotux.net>
parents:
784
diff
changeset
|
77 // Restore term settings, if needed. |
1fa93cc6f5e3
Correctly restore term settings when interrupting the password query
Mikael Berthe <mikael@lilotux.net>
parents:
784
diff
changeset
|
78 if (backup_termios) |
1fa93cc6f5e3
Correctly restore term settings when interrupting the password query
Mikael Berthe <mikael@lilotux.net>
parents:
784
diff
changeset
|
79 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
|
80 |
312
f0b7ff2df7e8
Ctrl-C does not terminate mcabber
Mikael Berthe <mikael@lilotux.net>
parents:
307
diff
changeset
|
81 if (msg) |
f0b7ff2df7e8
Ctrl-C does not terminate mcabber
Mikael Berthe <mikael@lilotux.net>
parents:
307
diff
changeset
|
82 fprintf(stderr, "%s\n", msg); |
f0b7ff2df7e8
Ctrl-C does not terminate mcabber
Mikael Berthe <mikael@lilotux.net>
parents:
307
diff
changeset
|
83 printf("Bye!\n"); |
f0b7ff2df7e8
Ctrl-C does not terminate mcabber
Mikael Berthe <mikael@lilotux.net>
parents:
307
diff
changeset
|
84 exit(EXIT_SUCCESS); |
f0b7ff2df7e8
Ctrl-C does not terminate mcabber
Mikael Berthe <mikael@lilotux.net>
parents:
307
diff
changeset
|
85 } |
f0b7ff2df7e8
Ctrl-C does not terminate mcabber
Mikael Berthe <mikael@lilotux.net>
parents:
307
diff
changeset
|
86 |
f0b7ff2df7e8
Ctrl-C does not terminate mcabber
Mikael Berthe <mikael@lilotux.net>
parents:
307
diff
changeset
|
87 void sig_handler(int signum) |
f0b7ff2df7e8
Ctrl-C does not terminate mcabber
Mikael Berthe <mikael@lilotux.net>
parents:
307
diff
changeset
|
88 { |
f0b7ff2df7e8
Ctrl-C does not terminate mcabber
Mikael Berthe <mikael@lilotux.net>
parents:
307
diff
changeset
|
89 if (signum == SIGCHLD) { |
f0b7ff2df7e8
Ctrl-C does not terminate mcabber
Mikael Berthe <mikael@lilotux.net>
parents:
307
diff
changeset
|
90 int status; |
f0b7ff2df7e8
Ctrl-C does not terminate mcabber
Mikael Berthe <mikael@lilotux.net>
parents:
307
diff
changeset
|
91 pid_t pid; |
f0b7ff2df7e8
Ctrl-C does not terminate mcabber
Mikael Berthe <mikael@lilotux.net>
parents:
307
diff
changeset
|
92 do { |
f0b7ff2df7e8
Ctrl-C does not terminate mcabber
Mikael Berthe <mikael@lilotux.net>
parents:
307
diff
changeset
|
93 pid = waitpid (WAIT_ANY, &status, WNOHANG); |
676
80d4959422ca
New "eventcmd_checkstatus" option
Mikael Berthe <mikael@lilotux.net>
parents:
580
diff
changeset
|
94 // Check the exit status value if 'eventcmd_checkstatus' is set |
80d4959422ca
New "eventcmd_checkstatus" option
Mikael Berthe <mikael@lilotux.net>
parents:
580
diff
changeset
|
95 if (settings_opt_get_int("eventcmd_checkstatus")) { |
80d4959422ca
New "eventcmd_checkstatus" option
Mikael Berthe <mikael@lilotux.net>
parents:
580
diff
changeset
|
96 if (pid > 0) { |
80d4959422ca
New "eventcmd_checkstatus" option
Mikael Berthe <mikael@lilotux.net>
parents:
580
diff
changeset
|
97 // exit status 2 -> beep |
80d4959422ca
New "eventcmd_checkstatus" option
Mikael Berthe <mikael@lilotux.net>
parents:
580
diff
changeset
|
98 if (WIFEXITED(status) && WEXITSTATUS(status) == 2) { |
80d4959422ca
New "eventcmd_checkstatus" option
Mikael Berthe <mikael@lilotux.net>
parents:
580
diff
changeset
|
99 scr_Beep(); |
80d4959422ca
New "eventcmd_checkstatus" option
Mikael Berthe <mikael@lilotux.net>
parents:
580
diff
changeset
|
100 } |
80d4959422ca
New "eventcmd_checkstatus" option
Mikael Berthe <mikael@lilotux.net>
parents:
580
diff
changeset
|
101 } |
80d4959422ca
New "eventcmd_checkstatus" option
Mikael Berthe <mikael@lilotux.net>
parents:
580
diff
changeset
|
102 } |
312
f0b7ff2df7e8
Ctrl-C does not terminate mcabber
Mikael Berthe <mikael@lilotux.net>
parents:
307
diff
changeset
|
103 } while (pid > 0); |
f0b7ff2df7e8
Ctrl-C does not terminate mcabber
Mikael Berthe <mikael@lilotux.net>
parents:
307
diff
changeset
|
104 signal(SIGCHLD, sig_handler); |
f0b7ff2df7e8
Ctrl-C does not terminate mcabber
Mikael Berthe <mikael@lilotux.net>
parents:
307
diff
changeset
|
105 } else if (signum == SIGTERM) { |
962
e79af58cd0be
mcabber_disconnect() -> static mcabber_terminate()
Mikael Berthe <mikael@lilotux.net>
parents:
961
diff
changeset
|
106 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
|
107 } else if (signum == SIGINT) { |
962
e79af58cd0be
mcabber_disconnect() -> static mcabber_terminate()
Mikael Berthe <mikael@lilotux.net>
parents:
961
diff
changeset
|
108 mcabber_terminate("Killed by SIGINT"); |
1454
6b98dc22946d
Add optional SIGWINCH handler (Markus Hennecke)
Mikael Berthe <mikael@lilotux.net>
parents:
1448
diff
changeset
|
109 #ifdef USE_SIGWINCH |
6b98dc22946d
Add optional SIGWINCH handler (Markus Hennecke)
Mikael Berthe <mikael@lilotux.net>
parents:
1448
diff
changeset
|
110 } else if (signum == SIGWINCH) { |
6b98dc22946d
Add optional SIGWINCH handler (Markus Hennecke)
Mikael Berthe <mikael@lilotux.net>
parents:
1448
diff
changeset
|
111 ungetch(KEY_RESIZE); |
6b98dc22946d
Add optional SIGWINCH handler (Markus Hennecke)
Mikael Berthe <mikael@lilotux.net>
parents:
1448
diff
changeset
|
112 #endif |
312
f0b7ff2df7e8
Ctrl-C does not terminate mcabber
Mikael Berthe <mikael@lilotux.net>
parents:
307
diff
changeset
|
113 } else { |
374
bd5638c21834
Improve logging system (traces)
Mikael Berthe <mikael@lilotux.net>
parents:
364
diff
changeset
|
114 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
|
115 } |
f0b7ff2df7e8
Ctrl-C does not terminate mcabber
Mikael Berthe <mikael@lilotux.net>
parents:
307
diff
changeset
|
116 } |
f0b7ff2df7e8
Ctrl-C does not terminate mcabber
Mikael Berthe <mikael@lilotux.net>
parents:
307
diff
changeset
|
117 |
1042
8a395c2cafc4
Initial PGP support (decrypt)
Mikael Berthe <mikael@lilotux.net>
parents:
993
diff
changeset
|
118 // ask_password(what) |
8a395c2cafc4
Initial PGP support (decrypt)
Mikael Berthe <mikael@lilotux.net>
parents:
993
diff
changeset
|
119 // Return the password, or NULL. |
8a395c2cafc4
Initial PGP support (decrypt)
Mikael Berthe <mikael@lilotux.net>
parents:
993
diff
changeset
|
120 // The string must be freed after use. |
8a395c2cafc4
Initial PGP support (decrypt)
Mikael Berthe <mikael@lilotux.net>
parents:
993
diff
changeset
|
121 static char *ask_password(const char *what) |
312
f0b7ff2df7e8
Ctrl-C does not terminate mcabber
Mikael Berthe <mikael@lilotux.net>
parents:
307
diff
changeset
|
122 { |
f0b7ff2df7e8
Ctrl-C does not terminate mcabber
Mikael Berthe <mikael@lilotux.net>
parents:
307
diff
changeset
|
123 char *password, *p; |
f0b7ff2df7e8
Ctrl-C does not terminate mcabber
Mikael Berthe <mikael@lilotux.net>
parents:
307
diff
changeset
|
124 size_t passsize = 128; |
f0b7ff2df7e8
Ctrl-C does not terminate mcabber
Mikael Berthe <mikael@lilotux.net>
parents:
307
diff
changeset
|
125 struct termios orig, new; |
482
2ea7591584ab
Use fgets() instead of getline()
Mikael Berthe <mikael@lilotux.net>
parents:
429
diff
changeset
|
126 |
2ea7591584ab
Use fgets() instead of getline()
Mikael Berthe <mikael@lilotux.net>
parents:
429
diff
changeset
|
127 password = g_new0(char, passsize); |
312
f0b7ff2df7e8
Ctrl-C does not terminate mcabber
Mikael Berthe <mikael@lilotux.net>
parents:
307
diff
changeset
|
128 |
f0b7ff2df7e8
Ctrl-C does not terminate mcabber
Mikael Berthe <mikael@lilotux.net>
parents:
307
diff
changeset
|
129 /* Turn echoing off and fail if we can't. */ |
1042
8a395c2cafc4
Initial PGP support (decrypt)
Mikael Berthe <mikael@lilotux.net>
parents:
993
diff
changeset
|
130 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
|
131 backup_termios = &orig; |
1fa93cc6f5e3
Correctly restore term settings when interrupting the password query
Mikael Berthe <mikael@lilotux.net>
parents:
784
diff
changeset
|
132 |
312
f0b7ff2df7e8
Ctrl-C does not terminate mcabber
Mikael Berthe <mikael@lilotux.net>
parents:
307
diff
changeset
|
133 new = orig; |
f0b7ff2df7e8
Ctrl-C does not terminate mcabber
Mikael Berthe <mikael@lilotux.net>
parents:
307
diff
changeset
|
134 new.c_lflag &= ~ECHO; |
1042
8a395c2cafc4
Initial PGP support (decrypt)
Mikael Berthe <mikael@lilotux.net>
parents:
993
diff
changeset
|
135 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
|
136 |
f0b7ff2df7e8
Ctrl-C does not terminate mcabber
Mikael Berthe <mikael@lilotux.net>
parents:
307
diff
changeset
|
137 /* Read the password. */ |
1042
8a395c2cafc4
Initial PGP support (decrypt)
Mikael Berthe <mikael@lilotux.net>
parents:
993
diff
changeset
|
138 printf("Please enter %s: ", what); |
1598 | 139 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
|
140 |
f0b7ff2df7e8
Ctrl-C does not terminate mcabber
Mikael Berthe <mikael@lilotux.net>
parents:
307
diff
changeset
|
141 /* Restore terminal. */ |
f0b7ff2df7e8
Ctrl-C does not terminate mcabber
Mikael Berthe <mikael@lilotux.net>
parents:
307
diff
changeset
|
142 tcsetattr(fileno(stdin), TCSAFLUSH, &orig); |
f0b7ff2df7e8
Ctrl-C does not terminate mcabber
Mikael Berthe <mikael@lilotux.net>
parents:
307
diff
changeset
|
143 printf("\n"); |
789
1fa93cc6f5e3
Correctly restore term settings when interrupting the password query
Mikael Berthe <mikael@lilotux.net>
parents:
784
diff
changeset
|
144 backup_termios = NULL; |
312
f0b7ff2df7e8
Ctrl-C does not terminate mcabber
Mikael Berthe <mikael@lilotux.net>
parents:
307
diff
changeset
|
145 |
f0b7ff2df7e8
Ctrl-C does not terminate mcabber
Mikael Berthe <mikael@lilotux.net>
parents:
307
diff
changeset
|
146 for (p = (char*)password; *p; p++) |
f0b7ff2df7e8
Ctrl-C does not terminate mcabber
Mikael Berthe <mikael@lilotux.net>
parents:
307
diff
changeset
|
147 ; |
f0b7ff2df7e8
Ctrl-C does not terminate mcabber
Mikael Berthe <mikael@lilotux.net>
parents:
307
diff
changeset
|
148 for ( ; p > (char*)password ; p--) |
f0b7ff2df7e8
Ctrl-C does not terminate mcabber
Mikael Berthe <mikael@lilotux.net>
parents:
307
diff
changeset
|
149 if (*p == '\n' || *p == '\r') *p = 0; |
f0b7ff2df7e8
Ctrl-C does not terminate mcabber
Mikael Berthe <mikael@lilotux.net>
parents:
307
diff
changeset
|
150 |
1042
8a395c2cafc4
Initial PGP support (decrypt)
Mikael Berthe <mikael@lilotux.net>
parents:
993
diff
changeset
|
151 return password; |
312
f0b7ff2df7e8
Ctrl-C does not terminate mcabber
Mikael Berthe <mikael@lilotux.net>
parents:
307
diff
changeset
|
152 } |
f0b7ff2df7e8
Ctrl-C does not terminate mcabber
Mikael Berthe <mikael@lilotux.net>
parents:
307
diff
changeset
|
153 |
784
d7f3b58db522
Display hgcset (if defined) at startup
Mikael Berthe <mikael@lilotux.net>
parents:
781
diff
changeset
|
154 static void credits(void) |
24 | 155 { |
895 | 156 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
|
157 char *v = mcabber_version(); |
851
da03534e46c7
Add startup log messages to the status buffer
Mikael Berthe <mikael@lilotux.net>
parents:
848
diff
changeset
|
158 printf(v_fmt, v); |
da03534e46c7
Add startup log messages to the status buffer
Mikael Berthe <mikael@lilotux.net>
parents:
848
diff
changeset
|
159 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
|
160 g_free(v); |
24 | 161 } |
162 | |
1257
05dc45e7c7bb
Add command line option -v
Mikael Berthe <mikael@lilotux.net>
parents:
1256
diff
changeset
|
163 static void compile_options(void) |
05dc45e7c7bb
Add command line option -v
Mikael Berthe <mikael@lilotux.net>
parents:
1256
diff
changeset
|
164 { |
05dc45e7c7bb
Add command line option -v
Mikael Berthe <mikael@lilotux.net>
parents:
1256
diff
changeset
|
165 puts("Installation data directory: " DATA_DIR "\n"); |
05dc45e7c7bb
Add command line option -v
Mikael Berthe <mikael@lilotux.net>
parents:
1256
diff
changeset
|
166 #ifdef HAVE_UNICODE |
05dc45e7c7bb
Add command line option -v
Mikael Berthe <mikael@lilotux.net>
parents:
1256
diff
changeset
|
167 puts("Compiled with unicode support."); |
05dc45e7c7bb
Add command line option -v
Mikael Berthe <mikael@lilotux.net>
parents:
1256
diff
changeset
|
168 #endif |
05dc45e7c7bb
Add command line option -v
Mikael Berthe <mikael@lilotux.net>
parents:
1256
diff
changeset
|
169 #ifdef HAVE_GPGME |
05dc45e7c7bb
Add command line option -v
Mikael Berthe <mikael@lilotux.net>
parents:
1256
diff
changeset
|
170 puts("Compiled with GPG support."); |
05dc45e7c7bb
Add command line option -v
Mikael Berthe <mikael@lilotux.net>
parents:
1256
diff
changeset
|
171 #endif |
1607 | 172 #ifdef MODULES_ENABLE |
173 puts ("Compiled with modules support"); | |
174 #endif | |
1299
3b338a5c01fc
OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
1259
diff
changeset
|
175 #ifdef HAVE_LIBOTR |
3b338a5c01fc
OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
1259
diff
changeset
|
176 puts("Compiled with OTR support."); |
3b338a5c01fc
OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
1259
diff
changeset
|
177 #endif |
1590
8d1bcc83ae32
Add support for spellchecking with Enchant (caolan)
Mikael Berthe <mikael@lilotux.net>
parents:
1545
diff
changeset
|
178 #ifdef WITH_ENCHANT |
8d1bcc83ae32
Add support for spellchecking with Enchant (caolan)
Mikael Berthe <mikael@lilotux.net>
parents:
1545
diff
changeset
|
179 puts("Compiled with Enchant support."); |
8d1bcc83ae32
Add support for spellchecking with Enchant (caolan)
Mikael Berthe <mikael@lilotux.net>
parents:
1545
diff
changeset
|
180 #endif |
1257
05dc45e7c7bb
Add command line option -v
Mikael Berthe <mikael@lilotux.net>
parents:
1256
diff
changeset
|
181 #ifdef WITH_ASPELL |
05dc45e7c7bb
Add command line option -v
Mikael Berthe <mikael@lilotux.net>
parents:
1256
diff
changeset
|
182 puts("Compiled with Aspell support."); |
05dc45e7c7bb
Add command line option -v
Mikael Berthe <mikael@lilotux.net>
parents:
1256
diff
changeset
|
183 #endif |
1423
757ebe4df0b9
Replace DEBUG_ENABLE with ENABLE_DEBUG
Mikael Berthe <mikael@lilotux.net>
parents:
1421
diff
changeset
|
184 #ifdef ENABLE_DEBUG |
1257
05dc45e7c7bb
Add command line option -v
Mikael Berthe <mikael@lilotux.net>
parents:
1256
diff
changeset
|
185 puts("Compiled with debugging support."); |
05dc45e7c7bb
Add command line option -v
Mikael Berthe <mikael@lilotux.net>
parents:
1256
diff
changeset
|
186 #endif |
05dc45e7c7bb
Add command line option -v
Mikael Berthe <mikael@lilotux.net>
parents:
1256
diff
changeset
|
187 } |
05dc45e7c7bb
Add command line option -v
Mikael Berthe <mikael@lilotux.net>
parents:
1256
diff
changeset
|
188 |
05dc45e7c7bb
Add command line option -v
Mikael Berthe <mikael@lilotux.net>
parents:
1256
diff
changeset
|
189 static void main_init_pgp(void) |
1042
8a395c2cafc4
Initial PGP support (decrypt)
Mikael Berthe <mikael@lilotux.net>
parents:
993
diff
changeset
|
190 { |
8a395c2cafc4
Initial PGP support (decrypt)
Mikael Berthe <mikael@lilotux.net>
parents:
993
diff
changeset
|
191 #ifdef HAVE_GPGME |
8a395c2cafc4
Initial PGP support (decrypt)
Mikael Berthe <mikael@lilotux.net>
parents:
993
diff
changeset
|
192 const char *pk, *pp; |
8a395c2cafc4
Initial PGP support (decrypt)
Mikael Berthe <mikael@lilotux.net>
parents:
993
diff
changeset
|
193 char *typed_passwd = NULL; |
1238
80008fe2a4f2
Re-enable gpg-agent (revert 591d8b35c881)
Mikael Berthe <mikael@lilotux.net>
parents:
1223
diff
changeset
|
194 char *p; |
1042
8a395c2cafc4
Initial PGP support (decrypt)
Mikael Berthe <mikael@lilotux.net>
parents:
993
diff
changeset
|
195 bool pgp_invalid = FALSE; |
8a395c2cafc4
Initial PGP support (decrypt)
Mikael Berthe <mikael@lilotux.net>
parents:
993
diff
changeset
|
196 bool pgp_agent; |
1313
d1d12a09b04a
Make passphrase entry retries customizable (suggested by Till Maas)
Mikael Berthe <mikael@lilotux.net>
parents:
1311
diff
changeset
|
197 int retries; |
1042
8a395c2cafc4
Initial PGP support (decrypt)
Mikael Berthe <mikael@lilotux.net>
parents:
993
diff
changeset
|
198 |
1238
80008fe2a4f2
Re-enable gpg-agent (revert 591d8b35c881)
Mikael Berthe <mikael@lilotux.net>
parents:
1223
diff
changeset
|
199 p = getenv("GPG_AGENT_INFO"); |
80008fe2a4f2
Re-enable gpg-agent (revert 591d8b35c881)
Mikael Berthe <mikael@lilotux.net>
parents:
1223
diff
changeset
|
200 pgp_agent = (p && strchr(p, ':')); |
1042
8a395c2cafc4
Initial PGP support (decrypt)
Mikael Berthe <mikael@lilotux.net>
parents:
993
diff
changeset
|
201 |
8a395c2cafc4
Initial PGP support (decrypt)
Mikael Berthe <mikael@lilotux.net>
parents:
993
diff
changeset
|
202 pk = settings_opt_get("pgp_private_key"); |
8a395c2cafc4
Initial PGP support (decrypt)
Mikael Berthe <mikael@lilotux.net>
parents:
993
diff
changeset
|
203 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
|
204 |
d1d12a09b04a
Make passphrase entry retries customizable (suggested by Till Maas)
Mikael Berthe <mikael@lilotux.net>
parents:
1311
diff
changeset
|
205 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
|
206 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
|
207 else |
d1d12a09b04a
Make passphrase entry retries customizable (suggested by Till Maas)
Mikael Berthe <mikael@lilotux.net>
parents:
1311
diff
changeset
|
208 retries = 2; |
d1d12a09b04a
Make passphrase entry retries customizable (suggested by Till Maas)
Mikael Berthe <mikael@lilotux.net>
parents:
1311
diff
changeset
|
209 |
1042
8a395c2cafc4
Initial PGP support (decrypt)
Mikael Berthe <mikael@lilotux.net>
parents:
993
diff
changeset
|
210 if (!pk) { |
1597
4f59a414217e
Fix typo reported by rhonda
Mikael Berthe <mikael@lilotux.net>
parents:
1590
diff
changeset
|
211 scr_LogPrint(LPRINT_LOGNORM, "WARNING: unknown PGP private key"); |
1042
8a395c2cafc4
Initial PGP support (decrypt)
Mikael Berthe <mikael@lilotux.net>
parents:
993
diff
changeset
|
212 pgp_invalid = TRUE; |
8a395c2cafc4
Initial PGP support (decrypt)
Mikael Berthe <mikael@lilotux.net>
parents:
993
diff
changeset
|
213 } else if (!(pp || pgp_agent)) { |
8a395c2cafc4
Initial PGP support (decrypt)
Mikael Berthe <mikael@lilotux.net>
parents:
993
diff
changeset
|
214 // Request PGP passphrase |
8a395c2cafc4
Initial PGP support (decrypt)
Mikael Berthe <mikael@lilotux.net>
parents:
993
diff
changeset
|
215 pp = typed_passwd = ask_password("PGP passphrase"); |
8a395c2cafc4
Initial PGP support (decrypt)
Mikael Berthe <mikael@lilotux.net>
parents:
993
diff
changeset
|
216 } |
8a395c2cafc4
Initial PGP support (decrypt)
Mikael Berthe <mikael@lilotux.net>
parents:
993
diff
changeset
|
217 gpg_init(pk, pp); |
8a395c2cafc4
Initial PGP support (decrypt)
Mikael Berthe <mikael@lilotux.net>
parents:
993
diff
changeset
|
218 // Erase password from the settings array |
8a395c2cafc4
Initial PGP support (decrypt)
Mikael Berthe <mikael@lilotux.net>
parents:
993
diff
changeset
|
219 if (pp) { |
8a395c2cafc4
Initial PGP support (decrypt)
Mikael Berthe <mikael@lilotux.net>
parents:
993
diff
changeset
|
220 memset((char*)pp, 0, strlen(pp)); |
8a395c2cafc4
Initial PGP support (decrypt)
Mikael Berthe <mikael@lilotux.net>
parents:
993
diff
changeset
|
221 if (typed_passwd) |
8a395c2cafc4
Initial PGP support (decrypt)
Mikael Berthe <mikael@lilotux.net>
parents:
993
diff
changeset
|
222 g_free(typed_passwd); |
8a395c2cafc4
Initial PGP support (decrypt)
Mikael Berthe <mikael@lilotux.net>
parents:
993
diff
changeset
|
223 else |
8a395c2cafc4
Initial PGP support (decrypt)
Mikael Berthe <mikael@lilotux.net>
parents:
993
diff
changeset
|
224 settings_set(SETTINGS_TYPE_OPTION, "pgp_passphrase", NULL); |
8a395c2cafc4
Initial PGP support (decrypt)
Mikael Berthe <mikael@lilotux.net>
parents:
993
diff
changeset
|
225 } |
8a395c2cafc4
Initial PGP support (decrypt)
Mikael Berthe <mikael@lilotux.net>
parents:
993
diff
changeset
|
226 if (!pgp_agent && pk && pp && gpg_test_passphrase()) { |
8a395c2cafc4
Initial PGP support (decrypt)
Mikael Berthe <mikael@lilotux.net>
parents:
993
diff
changeset
|
227 // Let's check the pasphrase |
8a395c2cafc4
Initial PGP support (decrypt)
Mikael Berthe <mikael@lilotux.net>
parents:
993
diff
changeset
|
228 int i; |
1313
d1d12a09b04a
Make passphrase entry retries customizable (suggested by Till Maas)
Mikael Berthe <mikael@lilotux.net>
parents:
1311
diff
changeset
|
229 for (i = 1; retries < 0 || i <= retries; i++) { |
1042
8a395c2cafc4
Initial PGP support (decrypt)
Mikael Berthe <mikael@lilotux.net>
parents:
993
diff
changeset
|
230 typed_passwd = ask_password("PGP passphrase"); // Ask again... |
8a395c2cafc4
Initial PGP support (decrypt)
Mikael Berthe <mikael@lilotux.net>
parents:
993
diff
changeset
|
231 if (typed_passwd) { |
8a395c2cafc4
Initial PGP support (decrypt)
Mikael Berthe <mikael@lilotux.net>
parents:
993
diff
changeset
|
232 gpg_set_passphrase(typed_passwd); |
8a395c2cafc4
Initial PGP support (decrypt)
Mikael Berthe <mikael@lilotux.net>
parents:
993
diff
changeset
|
233 memset(typed_passwd, 0, strlen(typed_passwd)); |
8a395c2cafc4
Initial PGP support (decrypt)
Mikael Berthe <mikael@lilotux.net>
parents:
993
diff
changeset
|
234 g_free(typed_passwd); |
8a395c2cafc4
Initial PGP support (decrypt)
Mikael Berthe <mikael@lilotux.net>
parents:
993
diff
changeset
|
235 } |
8a395c2cafc4
Initial PGP support (decrypt)
Mikael Berthe <mikael@lilotux.net>
parents:
993
diff
changeset
|
236 if (!gpg_test_passphrase()) |
8a395c2cafc4
Initial PGP support (decrypt)
Mikael Berthe <mikael@lilotux.net>
parents:
993
diff
changeset
|
237 break; // Ok |
8a395c2cafc4
Initial PGP support (decrypt)
Mikael Berthe <mikael@lilotux.net>
parents:
993
diff
changeset
|
238 } |
1313
d1d12a09b04a
Make passphrase entry retries customizable (suggested by Till Maas)
Mikael Berthe <mikael@lilotux.net>
parents:
1311
diff
changeset
|
239 if (i > retries) |
1042
8a395c2cafc4
Initial PGP support (decrypt)
Mikael Berthe <mikael@lilotux.net>
parents:
993
diff
changeset
|
240 pgp_invalid = TRUE; |
8a395c2cafc4
Initial PGP support (decrypt)
Mikael Berthe <mikael@lilotux.net>
parents:
993
diff
changeset
|
241 } |
8a395c2cafc4
Initial PGP support (decrypt)
Mikael Berthe <mikael@lilotux.net>
parents:
993
diff
changeset
|
242 if (pgp_invalid) |
8a395c2cafc4
Initial PGP support (decrypt)
Mikael Berthe <mikael@lilotux.net>
parents:
993
diff
changeset
|
243 scr_LogPrint(LPRINT_LOGNORM, "WARNING: PGP key/pass invalid"); |
8a395c2cafc4
Initial PGP support (decrypt)
Mikael Berthe <mikael@lilotux.net>
parents:
993
diff
changeset
|
244 #else /* not HAVE_GPGME */ |
8a395c2cafc4
Initial PGP support (decrypt)
Mikael Berthe <mikael@lilotux.net>
parents:
993
diff
changeset
|
245 scr_LogPrint(LPRINT_LOGNORM, "WARNING: not compiled with PGP support"); |
8a395c2cafc4
Initial PGP support (decrypt)
Mikael Berthe <mikael@lilotux.net>
parents:
993
diff
changeset
|
246 #endif /* HAVE_GPGME */ |
8a395c2cafc4
Initial PGP support (decrypt)
Mikael Berthe <mikael@lilotux.net>
parents:
993
diff
changeset
|
247 } |
8a395c2cafc4
Initial PGP support (decrypt)
Mikael Berthe <mikael@lilotux.net>
parents:
993
diff
changeset
|
248 |
1359
7daf906fbcdc
The command /quit can be used in bindings, hooks and sourced files
Mikael Berthe <mikael@lilotux.net>
parents:
1313
diff
changeset
|
249 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
|
250 { |
7daf906fbcdc
The command /quit can be used in bindings, hooks and sourced files
Mikael Berthe <mikael@lilotux.net>
parents:
1313
diff
changeset
|
251 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
|
252 } |
7daf906fbcdc
The command /quit can be used in bindings, hooks and sourced files
Mikael Berthe <mikael@lilotux.net>
parents:
1313
diff
changeset
|
253 |
1598 | 254 gboolean mcabber_loop() |
255 { | |
256 keycode kcode; | |
257 | |
258 if (terminate_ui) { | |
259 g_main_loop_quit(main_loop); | |
260 return FALSE; | |
261 } | |
262 scr_DoUpdate(); | |
263 scr_Getch(&kcode); | |
264 | |
265 if (kcode.value != ERR) { | |
266 process_key(kcode); | |
267 } else { | |
268 scr_CheckAutoAway(FALSE); | |
269 | |
270 if (update_roster) | |
271 scr_DrawRoster(); | |
272 | |
273 hk_mainloop(); | |
274 } | |
275 return TRUE; | |
276 } | |
277 | |
24 | 278 int main(int argc, char **argv) |
279 { | |
169 | 280 char *configFile = NULL; |
281
f562b9af2de7
Add "const" specifier in prototypes
Mikael Berthe <mikael@lilotux.net>
parents:
279
diff
changeset
|
281 const char *optstring; |
177 | 282 int optval, optval2; |
333
db5bebe96c89
New config. file parsing
Mikael Berthe <mikael@lilotux.net>
parents:
322
diff
changeset
|
283 int ret; |
24 | 284 |
285 credits(); | |
286 | |
287 signal(SIGTERM, sig_handler); | |
312
f0b7ff2df7e8
Ctrl-C does not terminate mcabber
Mikael Berthe <mikael@lilotux.net>
parents:
307
diff
changeset
|
288 signal(SIGINT, sig_handler); |
163 | 289 signal(SIGCHLD, sig_handler); |
1454
6b98dc22946d
Add optional SIGWINCH handler (Markus Hennecke)
Mikael Berthe <mikael@lilotux.net>
parents:
1448
diff
changeset
|
290 #ifdef USE_SIGWINCH |
6b98dc22946d
Add optional SIGWINCH handler (Markus Hennecke)
Mikael Berthe <mikael@lilotux.net>
parents:
1448
diff
changeset
|
291 signal(SIGWINCH, sig_handler); |
6b98dc22946d
Add optional SIGWINCH handler (Markus Hennecke)
Mikael Berthe <mikael@lilotux.net>
parents:
1448
diff
changeset
|
292 #endif |
413 | 293 signal(SIGPIPE, SIG_IGN); |
24 | 294 |
77 | 295 /* Parse command line options */ |
24 | 296 while (1) { |
1259
c5c09f8f60b0
Change command line option -v to -V
Mikael Berthe <mikael@lilotux.net>
parents:
1257
diff
changeset
|
297 int c = getopt(argc, argv, "hVf:"); |
24 | 298 if (c == -1) { |
299 break; | |
300 } else | |
301 switch (c) { | |
302 case 'h': | |
1256
ea679e3598a9
Don't start when command line options are wrong
Mikael Berthe <mikael@lilotux.net>
parents:
1253
diff
changeset
|
303 case '?': |
1259
c5c09f8f60b0
Change command line option -v to -V
Mikael Berthe <mikael@lilotux.net>
parents:
1257
diff
changeset
|
304 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
|
305 return (c == 'h' ? 0 : -1); |
1259
c5c09f8f60b0
Change command line option -v to -V
Mikael Berthe <mikael@lilotux.net>
parents:
1257
diff
changeset
|
306 case 'V': |
1257
05dc45e7c7bb
Add command line option -v
Mikael Berthe <mikael@lilotux.net>
parents:
1256
diff
changeset
|
307 compile_options(); |
05dc45e7c7bb
Add command line option -v
Mikael Berthe <mikael@lilotux.net>
parents:
1256
diff
changeset
|
308 return 0; |
24 | 309 case 'f': |
1241 | 310 configFile = g_strdup(optarg); |
311 break; | |
24 | 312 } |
313 } | |
314 | |
1256
ea679e3598a9
Don't start when command line options are wrong
Mikael Berthe <mikael@lilotux.net>
parents:
1253
diff
changeset
|
315 if (optind < argc) { |
1259
c5c09f8f60b0
Change command line option -v to -V
Mikael Berthe <mikael@lilotux.net>
parents:
1257
diff
changeset
|
316 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
|
317 return -1; |
ea679e3598a9
Don't start when command line options are wrong
Mikael Berthe <mikael@lilotux.net>
parents:
1253
diff
changeset
|
318 } |
ea679e3598a9
Don't start when command line options are wrong
Mikael Berthe <mikael@lilotux.net>
parents:
1253
diff
changeset
|
319 |
1176
547a8ca7c1a8
Move init_bindings() to screen.c, with a few updates
Mikael Berthe <mikael@lilotux.net>
parents:
1173
diff
changeset
|
320 /* Initialize command system, roster and default key bindings */ |
333
db5bebe96c89
New config. file parsing
Mikael Berthe <mikael@lilotux.net>
parents:
322
diff
changeset
|
321 cmd_init(); |
848
a9161d2dc414
Introduce special buffer stuff
Mikael Berthe <mikael@lilotux.net>
parents:
815
diff
changeset
|
322 roster_init(); |
1065
230dca34dbea
Extand pgp_data structure
Mikael Berthe <mikael@lilotux.net>
parents:
1058
diff
changeset
|
323 settings_init(); |
1176
547a8ca7c1a8
Move init_bindings() to screen.c, with a few updates
Mikael Berthe <mikael@lilotux.net>
parents:
1173
diff
changeset
|
324 scr_init_bindings(); |
1600 | 325 caps_init(); |
779
057ffe7c43dc
Initialize locale charset earlier
Mikael Berthe <mikael@lilotux.net>
parents:
777
diff
changeset
|
326 /* Initialize charset */ |
057ffe7c43dc
Initialize locale charset earlier
Mikael Berthe <mikael@lilotux.net>
parents:
777
diff
changeset
|
327 scr_InitLocaleCharSet(); |
333
db5bebe96c89
New config. file parsing
Mikael Berthe <mikael@lilotux.net>
parents:
322
diff
changeset
|
328 |
24 | 329 /* Parsing config file... */ |
1192 | 330 ret = cfg_read_file(configFile, TRUE); |
374
bd5638c21834
Improve logging system (traces)
Mikael Berthe <mikael@lilotux.net>
parents:
364
diff
changeset
|
331 /* 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
|
332 g_free(configFile); |
333
db5bebe96c89
New config. file parsing
Mikael Berthe <mikael@lilotux.net>
parents:
322
diff
changeset
|
333 /* 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
|
334 if (ret == -2) |
333
db5bebe96c89
New config. file parsing
Mikael Berthe <mikael@lilotux.net>
parents:
322
diff
changeset
|
335 exit(EXIT_FAILURE); |
24 | 336 |
374
bd5638c21834
Improve logging system (traces)
Mikael Berthe <mikael@lilotux.net>
parents:
364
diff
changeset
|
337 optstring = settings_opt_get("tracelog_file"); |
bd5638c21834
Improve logging system (traces)
Mikael Berthe <mikael@lilotux.net>
parents:
364
diff
changeset
|
338 if (optstring) |
bd5638c21834
Improve logging system (traces)
Mikael Berthe <mikael@lilotux.net>
parents:
364
diff
changeset
|
339 ut_InitDebug(settings_opt_get_int("tracelog_level"), optstring); |
138 | 340 |
306
b2d11b11675f
Fix interactive password prompt
Mikael Berthe <mikael@lilotux.net>
parents:
300
diff
changeset
|
341 /* 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
|
342 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
|
343 if (settings_opt_get("jid") && !settings_opt_get("password")) { |
855
cbeedd730b1b
Display username before asking for password
Mikael Berthe <mikael@lilotux.net>
parents:
851
diff
changeset
|
344 const char *p; |
1123 | 345 char *pwd; |
855
cbeedd730b1b
Display username before asking for password
Mikael Berthe <mikael@lilotux.net>
parents:
851
diff
changeset
|
346 p = settings_opt_get("server"); |
cbeedd730b1b
Display username before asking for password
Mikael Berthe <mikael@lilotux.net>
parents:
851
diff
changeset
|
347 if (p) |
cbeedd730b1b
Display username before asking for password
Mikael Berthe <mikael@lilotux.net>
parents:
851
diff
changeset
|
348 printf("Server: %s\n", p); |
1610
6db9f403f707
Replace 'username' with 'jid' in the configuration file
Mikael Berthe <mikael@lilotux.net>
parents:
1607
diff
changeset
|
349 p = settings_opt_get("jid"); |
855
cbeedd730b1b
Display username before asking for password
Mikael Berthe <mikael@lilotux.net>
parents:
851
diff
changeset
|
350 if (p) |
1610
6db9f403f707
Replace 'username' with 'jid' in the configuration file
Mikael Berthe <mikael@lilotux.net>
parents:
1607
diff
changeset
|
351 printf("User JID: %s\n", p); |
1123 | 352 |
353 pwd = ask_password("Jabber password"); | |
354 settings_set(SETTINGS_TYPE_OPTION, "password", pwd); | |
355 g_free(pwd); | |
415
5692c3a13202
Display the server name/IP before asking for password
Mikael Berthe <mikael@lilotux.net>
parents:
413
diff
changeset
|
356 } |
24 | 357 |
1042
8a395c2cafc4
Initial PGP support (decrypt)
Mikael Berthe <mikael@lilotux.net>
parents:
993
diff
changeset
|
358 /* Initialize PGP system |
8a395c2cafc4
Initial PGP support (decrypt)
Mikael Berthe <mikael@lilotux.net>
parents:
993
diff
changeset
|
359 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
|
360 a passphrase. */ |
8a395c2cafc4
Initial PGP support (decrypt)
Mikael Berthe <mikael@lilotux.net>
parents:
993
diff
changeset
|
361 if (settings_opt_get_int("pgp")) |
8a395c2cafc4
Initial PGP support (decrypt)
Mikael Berthe <mikael@lilotux.net>
parents:
993
diff
changeset
|
362 main_init_pgp(); |
8a395c2cafc4
Initial PGP support (decrypt)
Mikael Berthe <mikael@lilotux.net>
parents:
993
diff
changeset
|
363 |
24 | 364 /* Initialize N-Curses */ |
374
bd5638c21834
Improve logging system (traces)
Mikael Berthe <mikael@lilotux.net>
parents:
364
diff
changeset
|
365 scr_LogPrint(LPRINT_DEBUG, "Initializing N-Curses..."); |
24 | 366 scr_InitCurses(); |
151 | 367 scr_DrawMainWindow(TRUE); |
29 | 368 |
279
f5dd437c057b
Rewrite the settings system
Mikael Berthe <mikael@lilotux.net>
parents:
272
diff
changeset
|
369 optval = (settings_opt_get_int("logging") > 0); |
f5dd437c057b
Rewrite the settings system
Mikael Berthe <mikael@lilotux.net>
parents:
272
diff
changeset
|
370 optval2 = (settings_opt_get_int("load_logs") > 0); |
177 | 371 if (optval || optval2) |
298
35cda94e570d
Add /connect and /disconnect commands
Mikael Berthe <mikael@lilotux.net>
parents:
281
diff
changeset
|
372 hlog_enable(optval, settings_opt_get("logging_dir"), optval2); |
113 | 373 |
1590
8d1bcc83ae32
Add support for spellchecking with Enchant (caolan)
Mikael Berthe <mikael@lilotux.net>
parents:
1545
diff
changeset
|
374 #if defined(WITH_ENCHANT) || defined(WITH_ASPELL) |
8d1bcc83ae32
Add support for spellchecking with Enchant (caolan)
Mikael Berthe <mikael@lilotux.net>
parents:
1545
diff
changeset
|
375 /* Initialize spelling */ |
8d1bcc83ae32
Add support for spellchecking with Enchant (caolan)
Mikael Berthe <mikael@lilotux.net>
parents:
1545
diff
changeset
|
376 if (settings_opt_get_int("spell_enable")) { |
1179 | 377 spellcheck_init(); |
378 } | |
379 #endif | |
380 | |
279
f5dd437c057b
Rewrite the settings system
Mikael Berthe <mikael@lilotux.net>
parents:
272
diff
changeset
|
381 optstring = settings_opt_get("events_command"); |
f5dd437c057b
Rewrite the settings system
Mikael Berthe <mikael@lilotux.net>
parents:
272
diff
changeset
|
382 if (optstring) |
160 | 383 hk_ext_cmd_init(optstring); |
384 | |
1311
0dda8238af21
Implement "/roster display"
Mikael Berthe <mikael@lilotux.net>
parents:
1307
diff
changeset
|
385 if (settings_opt_get_int("hide_offline_buddies") > 0) { // XXX Deprecated |
0dda8238af21
Implement "/roster display"
Mikael Berthe <mikael@lilotux.net>
parents:
1307
diff
changeset
|
386 scr_RosterDisplay("ofdna"); |
0dda8238af21
Implement "/roster display"
Mikael Berthe <mikael@lilotux.net>
parents:
1307
diff
changeset
|
387 scr_LogPrint(LPRINT_LOGNORM, |
0dda8238af21
Implement "/roster display"
Mikael Berthe <mikael@lilotux.net>
parents:
1307
diff
changeset
|
388 "* Warning: 'hide_offline_buddies' is deprecated."); |
0dda8238af21
Implement "/roster display"
Mikael Berthe <mikael@lilotux.net>
parents:
1307
diff
changeset
|
389 } else { |
0dda8238af21
Implement "/roster display"
Mikael Berthe <mikael@lilotux.net>
parents:
1307
diff
changeset
|
390 optstring = settings_opt_get("roster_display_filter"); |
0dda8238af21
Implement "/roster display"
Mikael Berthe <mikael@lilotux.net>
parents:
1307
diff
changeset
|
391 if (optstring) |
0dda8238af21
Implement "/roster display"
Mikael Berthe <mikael@lilotux.net>
parents:
1307
diff
changeset
|
392 scr_RosterDisplay(optstring); |
0dda8238af21
Implement "/roster display"
Mikael Berthe <mikael@lilotux.net>
parents:
1307
diff
changeset
|
393 // Empty filter isn't allowed... |
0dda8238af21
Implement "/roster display"
Mikael Berthe <mikael@lilotux.net>
parents:
1307
diff
changeset
|
394 if (!buddylist_get_filter()) |
0dda8238af21
Implement "/roster display"
Mikael Berthe <mikael@lilotux.net>
parents:
1307
diff
changeset
|
395 scr_RosterDisplay("*"); |
0dda8238af21
Implement "/roster display"
Mikael Berthe <mikael@lilotux.net>
parents:
1307
diff
changeset
|
396 } |
87 | 397 |
993
0759f4c7da68
Add option 'disable_chatstates'
Mikael Berthe <mikael@lilotux.net>
parents:
962
diff
changeset
|
398 chatstates_disabled = settings_opt_get_int("disable_chatstates"); |
0759f4c7da68
Add option 'disable_chatstates'
Mikael Berthe <mikael@lilotux.net>
parents:
962
diff
changeset
|
399 |
1426
a64778f5f26b
Implement FIFO named command pipe
Mikael Berthe <mikael@lilotux.net>
parents:
1425
diff
changeset
|
400 /* Initialize FIFO named pipe */ |
a64778f5f26b
Implement FIFO named command pipe
Mikael Berthe <mikael@lilotux.net>
parents:
1425
diff
changeset
|
401 fifo_init(settings_opt_get("fifo_name")); |
a64778f5f26b
Implement FIFO named command pipe
Mikael Berthe <mikael@lilotux.net>
parents:
1425
diff
changeset
|
402 |
1437
071c8170b7de
Add option 'statefile' to keep track of unread messages across restarts
Mikael Berthe <mikael@lilotux.net>
parents:
1426
diff
changeset
|
403 /* 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
|
404 hlog_load_state(); |
071c8170b7de
Add option 'statefile' to keep track of unread messages across restarts
Mikael Berthe <mikael@lilotux.net>
parents:
1426
diff
changeset
|
405 |
1598 | 406 main_loop = g_main_loop_new(NULL, TRUE); |
407 | |
872
a0ddc43b421e
Don't stop when there is no configuration file
Mikael Berthe <mikael@lilotux.net>
parents:
855
diff
changeset
|
408 if (ret < 0) { |
a0ddc43b421e
Don't stop when there is no configuration file
Mikael Berthe <mikael@lilotux.net>
parents:
855
diff
changeset
|
409 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
|
410 scr_ShowBuddyWindow(); |
a0ddc43b421e
Don't stop when there is no configuration file
Mikael Berthe <mikael@lilotux.net>
parents:
855
diff
changeset
|
411 } else { |
a0ddc43b421e
Don't stop when there is no configuration file
Mikael Berthe <mikael@lilotux.net>
parents:
855
diff
changeset
|
412 /* Connection */ |
1598 | 413 xmpp_connect(); |
872
a0ddc43b421e
Don't stop when there is no configuration file
Mikael Berthe <mikael@lilotux.net>
parents:
855
diff
changeset
|
414 } |
298
35cda94e570d
Add /connect and /disconnect commands
Mikael Berthe <mikael@lilotux.net>
parents:
281
diff
changeset
|
415 |
374
bd5638c21834
Improve logging system (traces)
Mikael Berthe <mikael@lilotux.net>
parents:
364
diff
changeset
|
416 scr_LogPrint(LPRINT_DEBUG, "Entering into main loop..."); |
112 | 417 |
1598 | 418 g_timeout_add(10, mcabber_loop, NULL); |
419 g_main_loop_run(main_loop); | |
24 | 420 |
1307
6c116207ab2e
Work around segfault in otrl_userstate_free()
Mikael Berthe <mikael@lilotux.net>
parents:
1299
diff
changeset
|
421 scr_TerminateCurses(); |
1607 | 422 #ifdef MODULES_ENABLE |
423 cmd_deinit(); | |
424 #endif | |
1426
a64778f5f26b
Implement FIFO named command pipe
Mikael Berthe <mikael@lilotux.net>
parents:
1425
diff
changeset
|
425 fifo_deinit(); |
1299
3b338a5c01fc
OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
1259
diff
changeset
|
426 #ifdef HAVE_LIBOTR |
3b338a5c01fc
OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
1259
diff
changeset
|
427 otr_terminate(); |
3b338a5c01fc
OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
1259
diff
changeset
|
428 #endif |
1598 | 429 xmpp_disconnect(); |
1042
8a395c2cafc4
Initial PGP support (decrypt)
Mikael Berthe <mikael@lilotux.net>
parents:
993
diff
changeset
|
430 #ifdef HAVE_GPGME |
8a395c2cafc4
Initial PGP support (decrypt)
Mikael Berthe <mikael@lilotux.net>
parents:
993
diff
changeset
|
431 gpg_terminate(); |
8a395c2cafc4
Initial PGP support (decrypt)
Mikael Berthe <mikael@lilotux.net>
parents:
993
diff
changeset
|
432 #endif |
1590
8d1bcc83ae32
Add support for spellchecking with Enchant (caolan)
Mikael Berthe <mikael@lilotux.net>
parents:
1545
diff
changeset
|
433 #if defined(WITH_ENCHANT) || defined(WITH_ASPELL) |
8d1bcc83ae32
Add support for spellchecking with Enchant (caolan)
Mikael Berthe <mikael@lilotux.net>
parents:
1545
diff
changeset
|
434 /* Deinitialize spelling */ |
8d1bcc83ae32
Add support for spellchecking with Enchant (caolan)
Mikael Berthe <mikael@lilotux.net>
parents:
1545
diff
changeset
|
435 if (settings_opt_get_int("spell_enable")) |
1179 | 436 spellcheck_deinit(); |
437 #endif | |
1437
071c8170b7de
Add option 'statefile' to keep track of unread messages across restarts
Mikael Berthe <mikael@lilotux.net>
parents:
1426
diff
changeset
|
438 /* 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
|
439 hlog_save_state(); |
1600 | 440 caps_free(); |
24 | 441 |
961
95659cf9ea1a
Display mcabber version in the status window
Mikael Berthe <mikael@lilotux.net>
parents:
955
diff
changeset
|
442 printf("\n\nThanks for using mcabber!\n"); |
24 | 443 |
444 return 0; | |
445 } | |
576 | 446 |
580 | 447 /* vim: set expandtab cindent cinoptions=>2\:2(0: For Vim users... */ |