Mercurial > hg
annotate mcabber/src/settings.c @ 1518:63dc211a4c1a
New command: /echo (display a message in the log window)
author | Mikael Berthe <mikael@lilotux.net> |
---|---|
date | Sat, 27 Sep 2008 22:41:29 +0200 |
parents | 366ef500c522 |
children | ac5a2c262098 |
rev | line source |
---|---|
279 | 1 /* |
2 * settings.c -- Configuration stuff | |
393 | 3 * |
1414 | 4 * Copyright (C) 2005-2008 Mikael Berthe <mikael@lilotux.net> |
279 | 5 * |
6 * This program is free software; you can redistribute it and/or modify | |
7 * it under the terms of the GNU General Public License as published by | |
8 * the Free Software Foundation; either version 2 of the License, or (at | |
9 * your option) any later version. | |
10 * | |
11 * This program is distributed in the hope that it will be useful, but | |
12 * WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
14 * General Public License for more details. | |
15 * | |
16 * You should have received a copy of the GNU General Public License | |
17 * along with this program; if not, write to the Free Software | |
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 | |
19 * USA | |
20 */ | |
21 | |
22 #include <strings.h> | |
23 #include <stdlib.h> | |
280
68ce34b4243b
Add parse_assigment() function
Mikael Berthe <mikael@lilotux.net>
parents:
279
diff
changeset
|
24 #include <ctype.h> |
279 | 25 |
26 #include "settings.h" | |
341
dea407d53fe6
Improve configuration file reading
Mikael Berthe <mikael@lilotux.net>
parents:
337
diff
changeset
|
27 #include "commands.h" |
dea407d53fe6
Improve configuration file reading
Mikael Berthe <mikael@lilotux.net>
parents:
337
diff
changeset
|
28 #include "utils.h" |
378
2e6c7b1440d1
Improve debugging/logging
Mikael Berthe <mikael@lilotux.net>
parents:
374
diff
changeset
|
29 #include "logprint.h" |
1299
3b338a5c01fc
OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
1278
diff
changeset
|
30 #include "otr.h" |
279 | 31 |
1299
3b338a5c01fc
OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
1278
diff
changeset
|
32 // Maximum line length |
1278
c3107650d165
Allow longer lines in config file
Mikael Berthe <mikael@lilotux.net>
parents:
1272
diff
changeset
|
33 // (probably best to use the same value as INPUTLINE_LENGTH) |
c3107650d165
Allow longer lines in config file
Mikael Berthe <mikael@lilotux.net>
parents:
1272
diff
changeset
|
34 #define CONFLINE_LENGTH 1024 |
c3107650d165
Allow longer lines in config file
Mikael Berthe <mikael@lilotux.net>
parents:
1272
diff
changeset
|
35 |
1070
9eaacc0ad3a2
Use a hash for settings
Mikael Berthe <mikael@lilotux.net>
parents:
1068
diff
changeset
|
36 static GHashTable *option; |
9eaacc0ad3a2
Use a hash for settings
Mikael Berthe <mikael@lilotux.net>
parents:
1068
diff
changeset
|
37 static GHashTable *alias; |
9eaacc0ad3a2
Use a hash for settings
Mikael Berthe <mikael@lilotux.net>
parents:
1068
diff
changeset
|
38 static GHashTable *binding; |
279 | 39 |
1065
230dca34dbea
Extand pgp_data structure
Mikael Berthe <mikael@lilotux.net>
parents:
1004
diff
changeset
|
40 #ifdef HAVE_GPGME /* PGP settings */ |
230dca34dbea
Extand pgp_data structure
Mikael Berthe <mikael@lilotux.net>
parents:
1004
diff
changeset
|
41 static GHashTable *pgpopt; |
230dca34dbea
Extand pgp_data structure
Mikael Berthe <mikael@lilotux.net>
parents:
1004
diff
changeset
|
42 |
230dca34dbea
Extand pgp_data structure
Mikael Berthe <mikael@lilotux.net>
parents:
1004
diff
changeset
|
43 typedef struct { |
230dca34dbea
Extand pgp_data structure
Mikael Berthe <mikael@lilotux.net>
parents:
1004
diff
changeset
|
44 gchar *pgp_keyid; /* KeyId the contact is supposed to use */ |
230dca34dbea
Extand pgp_data structure
Mikael Berthe <mikael@lilotux.net>
parents:
1004
diff
changeset
|
45 guint pgp_disabled; /* If TRUE, PGP is disabled for outgoing messages */ |
1197 | 46 guint pgp_force; /* If TRUE, PGP is used w/o negotiation */ |
1065
230dca34dbea
Extand pgp_data structure
Mikael Berthe <mikael@lilotux.net>
parents:
1004
diff
changeset
|
47 } T_pgpopt; |
230dca34dbea
Extand pgp_data structure
Mikael Berthe <mikael@lilotux.net>
parents:
1004
diff
changeset
|
48 #endif |
230dca34dbea
Extand pgp_data structure
Mikael Berthe <mikael@lilotux.net>
parents:
1004
diff
changeset
|
49 |
1299
3b338a5c01fc
OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
1278
diff
changeset
|
50 #ifdef HAVE_LIBOTR |
3b338a5c01fc
OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
1278
diff
changeset
|
51 static GHashTable *otrpolicy; |
3b338a5c01fc
OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
1278
diff
changeset
|
52 static enum otr_policy default_policy; |
3b338a5c01fc
OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
1278
diff
changeset
|
53 #endif |
3b338a5c01fc
OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
1278
diff
changeset
|
54 |
1070
9eaacc0ad3a2
Use a hash for settings
Mikael Berthe <mikael@lilotux.net>
parents:
1068
diff
changeset
|
55 static inline GHashTable *get_hash(guint type) |
279 | 56 { |
1070
9eaacc0ad3a2
Use a hash for settings
Mikael Berthe <mikael@lilotux.net>
parents:
1068
diff
changeset
|
57 if (type == SETTINGS_TYPE_OPTION) return option; |
9eaacc0ad3a2
Use a hash for settings
Mikael Berthe <mikael@lilotux.net>
parents:
1068
diff
changeset
|
58 else if (type == SETTINGS_TYPE_ALIAS) return alias; |
9eaacc0ad3a2
Use a hash for settings
Mikael Berthe <mikael@lilotux.net>
parents:
1068
diff
changeset
|
59 else if (type == SETTINGS_TYPE_BINDING) return binding; |
1299
3b338a5c01fc
OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
1278
diff
changeset
|
60 #ifdef HAVE_LIBOTR |
3b338a5c01fc
OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
1278
diff
changeset
|
61 else if (type == SETTINGS_TYPE_OTR) return otrpolicy; |
3b338a5c01fc
OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
1278
diff
changeset
|
62 #endif |
279 | 63 return NULL; |
64 } | |
65 | |
66 /* -- */ | |
67 | |
1065
230dca34dbea
Extand pgp_data structure
Mikael Berthe <mikael@lilotux.net>
parents:
1004
diff
changeset
|
68 void settings_init(void) |
230dca34dbea
Extand pgp_data structure
Mikael Berthe <mikael@lilotux.net>
parents:
1004
diff
changeset
|
69 { |
1070
9eaacc0ad3a2
Use a hash for settings
Mikael Berthe <mikael@lilotux.net>
parents:
1068
diff
changeset
|
70 option = g_hash_table_new_full(&g_str_hash, &g_str_equal, &g_free, &g_free); |
9eaacc0ad3a2
Use a hash for settings
Mikael Berthe <mikael@lilotux.net>
parents:
1068
diff
changeset
|
71 alias = g_hash_table_new_full(&g_str_hash, &g_str_equal, &g_free, &g_free); |
9eaacc0ad3a2
Use a hash for settings
Mikael Berthe <mikael@lilotux.net>
parents:
1068
diff
changeset
|
72 binding = g_hash_table_new_full(&g_str_hash, &g_str_equal, &g_free, &g_free); |
1065
230dca34dbea
Extand pgp_data structure
Mikael Berthe <mikael@lilotux.net>
parents:
1004
diff
changeset
|
73 #ifdef HAVE_GPGME |
230dca34dbea
Extand pgp_data structure
Mikael Berthe <mikael@lilotux.net>
parents:
1004
diff
changeset
|
74 pgpopt = g_hash_table_new(&g_str_hash, &g_str_equal); |
230dca34dbea
Extand pgp_data structure
Mikael Berthe <mikael@lilotux.net>
parents:
1004
diff
changeset
|
75 #endif |
1299
3b338a5c01fc
OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
1278
diff
changeset
|
76 #ifdef HAVE_LIBOTR |
3b338a5c01fc
OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
1278
diff
changeset
|
77 otrpolicy = g_hash_table_new(&g_str_hash, &g_str_equal); |
3b338a5c01fc
OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
1278
diff
changeset
|
78 #endif |
1065
230dca34dbea
Extand pgp_data structure
Mikael Berthe <mikael@lilotux.net>
parents:
1004
diff
changeset
|
79 } |
230dca34dbea
Extand pgp_data structure
Mikael Berthe <mikael@lilotux.net>
parents:
1004
diff
changeset
|
80 |
1192 | 81 // cfg_read_file(filename, mainfile) |
341
dea407d53fe6
Improve configuration file reading
Mikael Berthe <mikael@lilotux.net>
parents:
337
diff
changeset
|
82 // Read and parse config file "filename". If filename is NULL, |
dea407d53fe6
Improve configuration file reading
Mikael Berthe <mikael@lilotux.net>
parents:
337
diff
changeset
|
83 // try to open the configuration file at the default locations. |
1192 | 84 // mainfile must be set to TRUE for the startup config file. |
85 // If mainfile is TRUE, the permissions of the configuration file will | |
86 // be fixed if they're insecure. | |
341
dea407d53fe6
Improve configuration file reading
Mikael Berthe <mikael@lilotux.net>
parents:
337
diff
changeset
|
87 // |
1192 | 88 int cfg_read_file(char *filename, guint mainfile) |
341
dea407d53fe6
Improve configuration file reading
Mikael Berthe <mikael@lilotux.net>
parents:
337
diff
changeset
|
89 { |
1358 | 90 static unsigned int runtime; |
341
dea407d53fe6
Improve configuration file reading
Mikael Berthe <mikael@lilotux.net>
parents:
337
diff
changeset
|
91 FILE *fp; |
dea407d53fe6
Improve configuration file reading
Mikael Berthe <mikael@lilotux.net>
parents:
337
diff
changeset
|
92 char *buf; |
dea407d53fe6
Improve configuration file reading
Mikael Berthe <mikael@lilotux.net>
parents:
337
diff
changeset
|
93 char *line, *eol; |
dea407d53fe6
Improve configuration file reading
Mikael Berthe <mikael@lilotux.net>
parents:
337
diff
changeset
|
94 unsigned int ln = 0; |
dea407d53fe6
Improve configuration file reading
Mikael Berthe <mikael@lilotux.net>
parents:
337
diff
changeset
|
95 int err = 0; |
dea407d53fe6
Improve configuration file reading
Mikael Berthe <mikael@lilotux.net>
parents:
337
diff
changeset
|
96 |
dea407d53fe6
Improve configuration file reading
Mikael Berthe <mikael@lilotux.net>
parents:
337
diff
changeset
|
97 if (!filename) { |
dea407d53fe6
Improve configuration file reading
Mikael Berthe <mikael@lilotux.net>
parents:
337
diff
changeset
|
98 // Use default config file locations |
1192 | 99 char *home; |
1383 | 100 GString *sfilename; |
1192 | 101 |
102 if (!mainfile) { | |
103 scr_LogPrint(LPRINT_LOGNORM, "No file name provided"); | |
104 return -1; | |
105 } | |
106 | |
107 home = getenv("HOME"); | |
341
dea407d53fe6
Improve configuration file reading
Mikael Berthe <mikael@lilotux.net>
parents:
337
diff
changeset
|
108 if (!home) { |
374
bd5638c21834
Improve logging system (traces)
Mikael Berthe <mikael@lilotux.net>
parents:
364
diff
changeset
|
109 scr_LogPrint(LPRINT_LOG, "Can't find home dir!"); |
341
dea407d53fe6
Improve configuration file reading
Mikael Berthe <mikael@lilotux.net>
parents:
337
diff
changeset
|
110 fprintf(stderr, "Can't find home dir!\n"); |
1358 | 111 err = -1; |
112 goto cfg_read_file_return; | |
341
dea407d53fe6
Improve configuration file reading
Mikael Berthe <mikael@lilotux.net>
parents:
337
diff
changeset
|
113 } |
1383 | 114 sfilename = g_string_new(""); |
115 g_string_printf(sfilename, "%s/.mcabber/mcabberrc", home); | |
116 if ((fp = fopen(sfilename->str, "r")) == NULL) { | |
341
dea407d53fe6
Improve configuration file reading
Mikael Berthe <mikael@lilotux.net>
parents:
337
diff
changeset
|
117 // 2nd try... |
1383 | 118 g_string_printf(sfilename, "%s/.mcabberrc", home); |
119 if ((fp = fopen(sfilename->str, "r")) == NULL) { | |
341
dea407d53fe6
Improve configuration file reading
Mikael Berthe <mikael@lilotux.net>
parents:
337
diff
changeset
|
120 fprintf(stderr, "Cannot open config file!\n"); |
1383 | 121 g_string_free(sfilename, TRUE); |
1358 | 122 err = -1; |
123 goto cfg_read_file_return; | |
341
dea407d53fe6
Improve configuration file reading
Mikael Berthe <mikael@lilotux.net>
parents:
337
diff
changeset
|
124 } |
dea407d53fe6
Improve configuration file reading
Mikael Berthe <mikael@lilotux.net>
parents:
337
diff
changeset
|
125 } |
362
d8f147d6e872
Check directory and config file permissions
Mikael Berthe <mikael@lilotux.net>
parents:
341
diff
changeset
|
126 // Check configuration file permissions |
1358 | 127 // As it could contain sensitive data, we make it user-readable only. |
1383 | 128 checkset_perm(sfilename->str, TRUE); |
129 scr_LogPrint(LPRINT_LOGNORM, "Reading %s", sfilename->str); | |
1358 | 130 // Check mcabber dir. Here we just warn, we don't change the modes. |
1383 | 131 g_string_printf(sfilename, "%s/.mcabber/", home); |
132 checkset_perm(sfilename->str, FALSE); | |
133 g_string_free(sfilename, TRUE); | |
362
d8f147d6e872
Check directory and config file permissions
Mikael Berthe <mikael@lilotux.net>
parents:
341
diff
changeset
|
134 } else { |
1383 | 135 // filename was specified |
362
d8f147d6e872
Check directory and config file permissions
Mikael Berthe <mikael@lilotux.net>
parents:
341
diff
changeset
|
136 if ((fp = fopen(filename, "r")) == NULL) { |
1192 | 137 const char *msg = "Cannot open configuration file"; |
138 if (mainfile) | |
139 perror(msg); | |
140 else | |
141 scr_LogPrint(LPRINT_LOGNORM, "%s (%s).", msg, filename); | |
1358 | 142 err = -2; |
143 goto cfg_read_file_return; | |
362
d8f147d6e872
Check directory and config file permissions
Mikael Berthe <mikael@lilotux.net>
parents:
341
diff
changeset
|
144 } |
d8f147d6e872
Check directory and config file permissions
Mikael Berthe <mikael@lilotux.net>
parents:
341
diff
changeset
|
145 // Check configuration file permissions (see above) |
1192 | 146 // We don't change the permissions if that's not the main file. |
1214
9f5c5f176953
Do not check file permissions when using /source
Mikael Berthe <mikael@lilotux.net>
parents:
1205
diff
changeset
|
147 if (mainfile) |
9f5c5f176953
Do not check file permissions when using /source
Mikael Berthe <mikael@lilotux.net>
parents:
1205
diff
changeset
|
148 checkset_perm(filename, TRUE); |
1192 | 149 scr_LogPrint(LPRINT_LOGNORM, "Reading %s", filename); |
341
dea407d53fe6
Improve configuration file reading
Mikael Berthe <mikael@lilotux.net>
parents:
337
diff
changeset
|
150 } |
dea407d53fe6
Improve configuration file reading
Mikael Berthe <mikael@lilotux.net>
parents:
337
diff
changeset
|
151 |
1278
c3107650d165
Allow longer lines in config file
Mikael Berthe <mikael@lilotux.net>
parents:
1272
diff
changeset
|
152 buf = g_new(char, CONFLINE_LENGTH+1); |
341
dea407d53fe6
Improve configuration file reading
Mikael Berthe <mikael@lilotux.net>
parents:
337
diff
changeset
|
153 |
1278
c3107650d165
Allow longer lines in config file
Mikael Berthe <mikael@lilotux.net>
parents:
1272
diff
changeset
|
154 while (fgets(buf+1, CONFLINE_LENGTH, fp) != NULL) { |
341
dea407d53fe6
Improve configuration file reading
Mikael Berthe <mikael@lilotux.net>
parents:
337
diff
changeset
|
155 // The first char is reserved to add a '/', to make a command line |
dea407d53fe6
Improve configuration file reading
Mikael Berthe <mikael@lilotux.net>
parents:
337
diff
changeset
|
156 line = buf+1; |
dea407d53fe6
Improve configuration file reading
Mikael Berthe <mikael@lilotux.net>
parents:
337
diff
changeset
|
157 ln++; |
dea407d53fe6
Improve configuration file reading
Mikael Berthe <mikael@lilotux.net>
parents:
337
diff
changeset
|
158 |
dea407d53fe6
Improve configuration file reading
Mikael Berthe <mikael@lilotux.net>
parents:
337
diff
changeset
|
159 // Strip leading spaces |
dea407d53fe6
Improve configuration file reading
Mikael Berthe <mikael@lilotux.net>
parents:
337
diff
changeset
|
160 while (isspace(*line)) |
dea407d53fe6
Improve configuration file reading
Mikael Berthe <mikael@lilotux.net>
parents:
337
diff
changeset
|
161 line++; |
dea407d53fe6
Improve configuration file reading
Mikael Berthe <mikael@lilotux.net>
parents:
337
diff
changeset
|
162 |
dea407d53fe6
Improve configuration file reading
Mikael Berthe <mikael@lilotux.net>
parents:
337
diff
changeset
|
163 // Make eol point to the last char of the line |
dea407d53fe6
Improve configuration file reading
Mikael Berthe <mikael@lilotux.net>
parents:
337
diff
changeset
|
164 for (eol = line ; *eol ; eol++) |
dea407d53fe6
Improve configuration file reading
Mikael Berthe <mikael@lilotux.net>
parents:
337
diff
changeset
|
165 ; |
dea407d53fe6
Improve configuration file reading
Mikael Berthe <mikael@lilotux.net>
parents:
337
diff
changeset
|
166 if (eol > line) |
dea407d53fe6
Improve configuration file reading
Mikael Berthe <mikael@lilotux.net>
parents:
337
diff
changeset
|
167 eol--; |
dea407d53fe6
Improve configuration file reading
Mikael Berthe <mikael@lilotux.net>
parents:
337
diff
changeset
|
168 |
dea407d53fe6
Improve configuration file reading
Mikael Berthe <mikael@lilotux.net>
parents:
337
diff
changeset
|
169 // Strip trailing spaces |
dea407d53fe6
Improve configuration file reading
Mikael Berthe <mikael@lilotux.net>
parents:
337
diff
changeset
|
170 while (eol > line && isspace(*eol)) |
dea407d53fe6
Improve configuration file reading
Mikael Berthe <mikael@lilotux.net>
parents:
337
diff
changeset
|
171 *eol-- = 0; |
dea407d53fe6
Improve configuration file reading
Mikael Berthe <mikael@lilotux.net>
parents:
337
diff
changeset
|
172 |
dea407d53fe6
Improve configuration file reading
Mikael Berthe <mikael@lilotux.net>
parents:
337
diff
changeset
|
173 // Ignore empty lines and comments |
dea407d53fe6
Improve configuration file reading
Mikael Berthe <mikael@lilotux.net>
parents:
337
diff
changeset
|
174 if ((*line == '\n') || (*line == '\0') || (*line == '#')) |
dea407d53fe6
Improve configuration file reading
Mikael Berthe <mikael@lilotux.net>
parents:
337
diff
changeset
|
175 continue; |
dea407d53fe6
Improve configuration file reading
Mikael Berthe <mikael@lilotux.net>
parents:
337
diff
changeset
|
176 |
1299
3b338a5c01fc
OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
1278
diff
changeset
|
177 // We only allow assignments line, except for commands "pgp", "source", |
1358 | 178 // "color" and "otrpolicy", unless we're in runtime (i.e. not startup). |
179 if (runtime || | |
180 (strchr(line, '=') != NULL) || | |
181 startswith(line, "pgp ", FALSE) || | |
182 startswith(line, "source ", FALSE) || | |
183 startswith(line, "color ", FALSE) || | |
1299
3b338a5c01fc
OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
1278
diff
changeset
|
184 startswith(line, "otrpolicy", FALSE)) { |
1192 | 185 // Only accept the set, alias, bind, pgp and source commands |
1358 | 186 if (!runtime && |
187 !startswith(line, "set ", FALSE) && | |
188 !startswith(line, "bind ", FALSE) && | |
189 !startswith(line, "alias ", FALSE) && | |
190 !startswith(line, "pgp ", FALSE) && | |
1272
033576acac4c
Add configurable roster colors (Michal 'vorner' Vaner)
Mikael Berthe <mikael@lilotux.net>
parents:
1214
diff
changeset
|
191 !startswith(line, "source ", FALSE) && |
1358 | 192 !startswith(line, "color ", FALSE) && |
193 !startswith(line, "otrpolicy ", FALSE)) { | |
194 scr_LogPrint(LPRINT_LOGNORM, "Error in configuration file (l. %d): " | |
195 "this command can't be used here", ln); | |
341
dea407d53fe6
Improve configuration file reading
Mikael Berthe <mikael@lilotux.net>
parents:
337
diff
changeset
|
196 err++; |
dea407d53fe6
Improve configuration file reading
Mikael Berthe <mikael@lilotux.net>
parents:
337
diff
changeset
|
197 continue; |
dea407d53fe6
Improve configuration file reading
Mikael Berthe <mikael@lilotux.net>
parents:
337
diff
changeset
|
198 } |
967 | 199 // Set the leading COMMAND_CHAR to build a command line |
200 // and process the command | |
201 *(--line) = COMMAND_CHAR; | |
1359
7daf906fbcdc
The command /quit can be used in bindings, hooks and sourced files
Mikael Berthe <mikael@lilotux.net>
parents:
1358
diff
changeset
|
202 if (process_command(line, TRUE) == 255) |
7daf906fbcdc
The command /quit can be used in bindings, hooks and sourced files
Mikael Berthe <mikael@lilotux.net>
parents:
1358
diff
changeset
|
203 mcabber_set_terminate_ui(); |
341
dea407d53fe6
Improve configuration file reading
Mikael Berthe <mikael@lilotux.net>
parents:
337
diff
changeset
|
204 } else { |
1358 | 205 scr_LogPrint(LPRINT_LOGNORM, "Error in configuration file (l. %d): " |
206 "this is not an assignment", ln); | |
341
dea407d53fe6
Improve configuration file reading
Mikael Berthe <mikael@lilotux.net>
parents:
337
diff
changeset
|
207 err++; |
dea407d53fe6
Improve configuration file reading
Mikael Berthe <mikael@lilotux.net>
parents:
337
diff
changeset
|
208 } |
dea407d53fe6
Improve configuration file reading
Mikael Berthe <mikael@lilotux.net>
parents:
337
diff
changeset
|
209 } |
dea407d53fe6
Improve configuration file reading
Mikael Berthe <mikael@lilotux.net>
parents:
337
diff
changeset
|
210 g_free(buf); |
dea407d53fe6
Improve configuration file reading
Mikael Berthe <mikael@lilotux.net>
parents:
337
diff
changeset
|
211 fclose(fp); |
1192 | 212 |
213 if (filename) | |
214 scr_LogPrint(LPRINT_LOGNORM, "Loaded %s.", filename); | |
1358 | 215 |
216 cfg_read_file_return: | |
217 // If we're done with the main file parsing, we can assume that | |
218 // the next time this function is called will be at run time. | |
219 if (mainfile) | |
220 runtime = TRUE; | |
341
dea407d53fe6
Improve configuration file reading
Mikael Berthe <mikael@lilotux.net>
parents:
337
diff
changeset
|
221 return err; |
dea407d53fe6
Improve configuration file reading
Mikael Berthe <mikael@lilotux.net>
parents:
337
diff
changeset
|
222 } |
dea407d53fe6
Improve configuration file reading
Mikael Berthe <mikael@lilotux.net>
parents:
337
diff
changeset
|
223 |
280
68ce34b4243b
Add parse_assigment() function
Mikael Berthe <mikael@lilotux.net>
parents:
279
diff
changeset
|
224 // parse_assigment(assignment, pkey, pval) |
68ce34b4243b
Add parse_assigment() function
Mikael Berthe <mikael@lilotux.net>
parents:
279
diff
changeset
|
225 // Read assignment and split it to key, value |
68ce34b4243b
Add parse_assigment() function
Mikael Berthe <mikael@lilotux.net>
parents:
279
diff
changeset
|
226 // |
68ce34b4243b
Add parse_assigment() function
Mikael Berthe <mikael@lilotux.net>
parents:
279
diff
changeset
|
227 // If this is an assignment, the function will return TRUE and |
68ce34b4243b
Add parse_assigment() function
Mikael Berthe <mikael@lilotux.net>
parents:
279
diff
changeset
|
228 // set *pkey and *pval (*pval is set to NULL if value field is empty). |
68ce34b4243b
Add parse_assigment() function
Mikael Berthe <mikael@lilotux.net>
parents:
279
diff
changeset
|
229 // |
68ce34b4243b
Add parse_assigment() function
Mikael Berthe <mikael@lilotux.net>
parents:
279
diff
changeset
|
230 // If this isn't a assignment (no = char), the function will set *pval |
68ce34b4243b
Add parse_assigment() function
Mikael Berthe <mikael@lilotux.net>
parents:
279
diff
changeset
|
231 // to NULL and return FALSE. |
68ce34b4243b
Add parse_assigment() function
Mikael Berthe <mikael@lilotux.net>
parents:
279
diff
changeset
|
232 // |
774
46304b773a44
Remove useless checks before g_free() calls
Mikael Berthe <mikael@lilotux.net>
parents:
764
diff
changeset
|
233 // The caller should g_free() *pkey and *pval (if not NULL) after use. |
1074
b2fc694a8228
Fix a few memory leaks after calls to parse_assigment()
Mikael Berthe <mikael@lilotux.net>
parents:
1070
diff
changeset
|
234 guint parse_assigment(gchar *assignment, gchar **pkey, gchar **pval) |
280
68ce34b4243b
Add parse_assigment() function
Mikael Berthe <mikael@lilotux.net>
parents:
279
diff
changeset
|
235 { |
293
d0295e735768
Assignment lvalue (key, option name, alias...) cannnot contain spaces
Mikael Berthe <mikael@lilotux.net>
parents:
288
diff
changeset
|
236 char *key, *val, *t, *p; |
280
68ce34b4243b
Add parse_assigment() function
Mikael Berthe <mikael@lilotux.net>
parents:
279
diff
changeset
|
237 |
68ce34b4243b
Add parse_assigment() function
Mikael Berthe <mikael@lilotux.net>
parents:
279
diff
changeset
|
238 *pkey = *pval = NULL; |
68ce34b4243b
Add parse_assigment() function
Mikael Berthe <mikael@lilotux.net>
parents:
279
diff
changeset
|
239 |
68ce34b4243b
Add parse_assigment() function
Mikael Berthe <mikael@lilotux.net>
parents:
279
diff
changeset
|
240 key = assignment; |
68ce34b4243b
Add parse_assigment() function
Mikael Berthe <mikael@lilotux.net>
parents:
279
diff
changeset
|
241 // Remove leading spaces in option name |
68ce34b4243b
Add parse_assigment() function
Mikael Berthe <mikael@lilotux.net>
parents:
279
diff
changeset
|
242 while ((!isalnum(*key)) && (*key != '=') && *key) { |
68ce34b4243b
Add parse_assigment() function
Mikael Berthe <mikael@lilotux.net>
parents:
279
diff
changeset
|
243 //if (!isblank(*key)) |
293
d0295e735768
Assignment lvalue (key, option name, alias...) cannnot contain spaces
Mikael Berthe <mikael@lilotux.net>
parents:
288
diff
changeset
|
244 // scr_LogPrint("Error in assignment parsing!"); |
280
68ce34b4243b
Add parse_assigment() function
Mikael Berthe <mikael@lilotux.net>
parents:
279
diff
changeset
|
245 key++; |
68ce34b4243b
Add parse_assigment() function
Mikael Berthe <mikael@lilotux.net>
parents:
279
diff
changeset
|
246 } |
68ce34b4243b
Add parse_assigment() function
Mikael Berthe <mikael@lilotux.net>
parents:
279
diff
changeset
|
247 if (!*key) return FALSE; // Empty assignment |
68ce34b4243b
Add parse_assigment() function
Mikael Berthe <mikael@lilotux.net>
parents:
279
diff
changeset
|
248 |
68ce34b4243b
Add parse_assigment() function
Mikael Berthe <mikael@lilotux.net>
parents:
279
diff
changeset
|
249 if (*key == '=') { |
293
d0295e735768
Assignment lvalue (key, option name, alias...) cannnot contain spaces
Mikael Berthe <mikael@lilotux.net>
parents:
288
diff
changeset
|
250 //scr_LogPrint("Cannot parse assignment!"); |
280
68ce34b4243b
Add parse_assigment() function
Mikael Berthe <mikael@lilotux.net>
parents:
279
diff
changeset
|
251 return FALSE; |
68ce34b4243b
Add parse_assigment() function
Mikael Berthe <mikael@lilotux.net>
parents:
279
diff
changeset
|
252 } |
68ce34b4243b
Add parse_assigment() function
Mikael Berthe <mikael@lilotux.net>
parents:
279
diff
changeset
|
253 // Ok, key points to the option name |
68ce34b4243b
Add parse_assigment() function
Mikael Berthe <mikael@lilotux.net>
parents:
279
diff
changeset
|
254 |
68ce34b4243b
Add parse_assigment() function
Mikael Berthe <mikael@lilotux.net>
parents:
279
diff
changeset
|
255 for (val = key+1 ; *val && (*val != '=') ; val++) |
68ce34b4243b
Add parse_assigment() function
Mikael Berthe <mikael@lilotux.net>
parents:
279
diff
changeset
|
256 if (!isalnum(*val) && !isblank(*val) && (*val != '_') && (*val != '-')) { |
68ce34b4243b
Add parse_assigment() function
Mikael Berthe <mikael@lilotux.net>
parents:
279
diff
changeset
|
257 // Key should only have alnum chars... |
293
d0295e735768
Assignment lvalue (key, option name, alias...) cannnot contain spaces
Mikael Berthe <mikael@lilotux.net>
parents:
288
diff
changeset
|
258 //scr_LogPrint("Error in assignment parsing!"); |
280
68ce34b4243b
Add parse_assigment() function
Mikael Berthe <mikael@lilotux.net>
parents:
279
diff
changeset
|
259 return FALSE; |
68ce34b4243b
Add parse_assigment() function
Mikael Berthe <mikael@lilotux.net>
parents:
279
diff
changeset
|
260 } |
68ce34b4243b
Add parse_assigment() function
Mikael Berthe <mikael@lilotux.net>
parents:
279
diff
changeset
|
261 // Remove trailing spaces in option name: |
68ce34b4243b
Add parse_assigment() function
Mikael Berthe <mikael@lilotux.net>
parents:
279
diff
changeset
|
262 for (t = val-1 ; t > key && isblank(*t) ; t--) |
68ce34b4243b
Add parse_assigment() function
Mikael Berthe <mikael@lilotux.net>
parents:
279
diff
changeset
|
263 ; |
293
d0295e735768
Assignment lvalue (key, option name, alias...) cannnot contain spaces
Mikael Berthe <mikael@lilotux.net>
parents:
288
diff
changeset
|
264 // Check for embedded whitespace characters |
d0295e735768
Assignment lvalue (key, option name, alias...) cannnot contain spaces
Mikael Berthe <mikael@lilotux.net>
parents:
288
diff
changeset
|
265 for (p = key; p < t; p++) { |
d0295e735768
Assignment lvalue (key, option name, alias...) cannnot contain spaces
Mikael Berthe <mikael@lilotux.net>
parents:
288
diff
changeset
|
266 if (isblank(*p)) { |
d0295e735768
Assignment lvalue (key, option name, alias...) cannnot contain spaces
Mikael Berthe <mikael@lilotux.net>
parents:
288
diff
changeset
|
267 //scr_LogPrint("Error in assignment parsing!" |
d0295e735768
Assignment lvalue (key, option name, alias...) cannnot contain spaces
Mikael Berthe <mikael@lilotux.net>
parents:
288
diff
changeset
|
268 // " (Name should not contain space chars)"); |
d0295e735768
Assignment lvalue (key, option name, alias...) cannnot contain spaces
Mikael Berthe <mikael@lilotux.net>
parents:
288
diff
changeset
|
269 return FALSE; |
d0295e735768
Assignment lvalue (key, option name, alias...) cannnot contain spaces
Mikael Berthe <mikael@lilotux.net>
parents:
288
diff
changeset
|
270 } |
d0295e735768
Assignment lvalue (key, option name, alias...) cannnot contain spaces
Mikael Berthe <mikael@lilotux.net>
parents:
288
diff
changeset
|
271 } |
d0295e735768
Assignment lvalue (key, option name, alias...) cannnot contain spaces
Mikael Berthe <mikael@lilotux.net>
parents:
288
diff
changeset
|
272 |
280
68ce34b4243b
Add parse_assigment() function
Mikael Berthe <mikael@lilotux.net>
parents:
279
diff
changeset
|
273 *pkey = g_strndup(key, t+1-key); |
68ce34b4243b
Add parse_assigment() function
Mikael Berthe <mikael@lilotux.net>
parents:
279
diff
changeset
|
274 |
68ce34b4243b
Add parse_assigment() function
Mikael Berthe <mikael@lilotux.net>
parents:
279
diff
changeset
|
275 if (!*val) return FALSE; // Not an assignment |
68ce34b4243b
Add parse_assigment() function
Mikael Berthe <mikael@lilotux.net>
parents:
279
diff
changeset
|
276 |
68ce34b4243b
Add parse_assigment() function
Mikael Berthe <mikael@lilotux.net>
parents:
279
diff
changeset
|
277 // Remove leading and trailing spaces in option value: |
68ce34b4243b
Add parse_assigment() function
Mikael Berthe <mikael@lilotux.net>
parents:
279
diff
changeset
|
278 for (val++; *val && isblank(*val) ; val++) ; |
68ce34b4243b
Add parse_assigment() function
Mikael Berthe <mikael@lilotux.net>
parents:
279
diff
changeset
|
279 for (t = val ; *t ; t++) ; |
68ce34b4243b
Add parse_assigment() function
Mikael Berthe <mikael@lilotux.net>
parents:
279
diff
changeset
|
280 for (t-- ; t >= val && isblank(*t) ; t--) ; |
68ce34b4243b
Add parse_assigment() function
Mikael Berthe <mikael@lilotux.net>
parents:
279
diff
changeset
|
281 |
282
87d6ac21cd1b
Fix "Cannot unset option" bug
Mikael Berthe <mikael@lilotux.net>
parents:
281
diff
changeset
|
282 if (t < val) return TRUE; // no value (variable reset for example) |
280
68ce34b4243b
Add parse_assigment() function
Mikael Berthe <mikael@lilotux.net>
parents:
279
diff
changeset
|
283 |
337
3a25be278864
Values can be enclosed by quotes in assignments
Mikael Berthe <mikael@lilotux.net>
parents:
336
diff
changeset
|
284 // If the value begins and ends with quotes ("), these quotes are |
3a25be278864
Values can be enclosed by quotes in assignments
Mikael Berthe <mikael@lilotux.net>
parents:
336
diff
changeset
|
285 // removed and whitespace is not stripped |
3a25be278864
Values can be enclosed by quotes in assignments
Mikael Berthe <mikael@lilotux.net>
parents:
336
diff
changeset
|
286 if ((t>val) && (*val == '"' && *t == '"')) { |
3a25be278864
Values can be enclosed by quotes in assignments
Mikael Berthe <mikael@lilotux.net>
parents:
336
diff
changeset
|
287 val++; |
3a25be278864
Values can be enclosed by quotes in assignments
Mikael Berthe <mikael@lilotux.net>
parents:
336
diff
changeset
|
288 t--; |
3a25be278864
Values can be enclosed by quotes in assignments
Mikael Berthe <mikael@lilotux.net>
parents:
336
diff
changeset
|
289 } |
280
68ce34b4243b
Add parse_assigment() function
Mikael Berthe <mikael@lilotux.net>
parents:
279
diff
changeset
|
290 *pval = g_strndup(val, t+1-val); |
68ce34b4243b
Add parse_assigment() function
Mikael Berthe <mikael@lilotux.net>
parents:
279
diff
changeset
|
291 return TRUE; |
68ce34b4243b
Add parse_assigment() function
Mikael Berthe <mikael@lilotux.net>
parents:
279
diff
changeset
|
292 } |
68ce34b4243b
Add parse_assigment() function
Mikael Berthe <mikael@lilotux.net>
parents:
279
diff
changeset
|
293 |
281
f562b9af2de7
Add "const" specifier in prototypes
Mikael Berthe <mikael@lilotux.net>
parents:
280
diff
changeset
|
294 void settings_set(guint type, const gchar *key, const gchar *value) |
279 | 295 { |
1070
9eaacc0ad3a2
Use a hash for settings
Mikael Berthe <mikael@lilotux.net>
parents:
1068
diff
changeset
|
296 GHashTable *hash; |
279 | 297 |
1070
9eaacc0ad3a2
Use a hash for settings
Mikael Berthe <mikael@lilotux.net>
parents:
1068
diff
changeset
|
298 hash = get_hash(type); |
9eaacc0ad3a2
Use a hash for settings
Mikael Berthe <mikael@lilotux.net>
parents:
1068
diff
changeset
|
299 if (!hash) |
9eaacc0ad3a2
Use a hash for settings
Mikael Berthe <mikael@lilotux.net>
parents:
1068
diff
changeset
|
300 return; |
9eaacc0ad3a2
Use a hash for settings
Mikael Berthe <mikael@lilotux.net>
parents:
1068
diff
changeset
|
301 |
9eaacc0ad3a2
Use a hash for settings
Mikael Berthe <mikael@lilotux.net>
parents:
1068
diff
changeset
|
302 if (!value) { |
9eaacc0ad3a2
Use a hash for settings
Mikael Berthe <mikael@lilotux.net>
parents:
1068
diff
changeset
|
303 g_hash_table_remove(hash, key); |
9eaacc0ad3a2
Use a hash for settings
Mikael Berthe <mikael@lilotux.net>
parents:
1068
diff
changeset
|
304 } else { |
9eaacc0ad3a2
Use a hash for settings
Mikael Berthe <mikael@lilotux.net>
parents:
1068
diff
changeset
|
305 g_hash_table_insert(hash, g_strdup(key), g_strdup(value)); |
279 | 306 } |
307 } | |
308 | |
281
f562b9af2de7
Add "const" specifier in prototypes
Mikael Berthe <mikael@lilotux.net>
parents:
280
diff
changeset
|
309 void settings_del(guint type, const gchar *key) |
279 | 310 { |
311 settings_set(type, key, NULL); | |
312 } | |
313 | |
281
f562b9af2de7
Add "const" specifier in prototypes
Mikael Berthe <mikael@lilotux.net>
parents:
280
diff
changeset
|
314 const gchar *settings_get(guint type, const gchar *key) |
279 | 315 { |
1070
9eaacc0ad3a2
Use a hash for settings
Mikael Berthe <mikael@lilotux.net>
parents:
1068
diff
changeset
|
316 GHashTable *hash; |
279 | 317 |
1070
9eaacc0ad3a2
Use a hash for settings
Mikael Berthe <mikael@lilotux.net>
parents:
1068
diff
changeset
|
318 hash = get_hash(type); |
9eaacc0ad3a2
Use a hash for settings
Mikael Berthe <mikael@lilotux.net>
parents:
1068
diff
changeset
|
319 if (!hash) |
9eaacc0ad3a2
Use a hash for settings
Mikael Berthe <mikael@lilotux.net>
parents:
1068
diff
changeset
|
320 return NULL; |
279 | 321 |
1070
9eaacc0ad3a2
Use a hash for settings
Mikael Berthe <mikael@lilotux.net>
parents:
1068
diff
changeset
|
322 return g_hash_table_lookup(hash, key); |
279 | 323 } |
324 | |
281
f562b9af2de7
Add "const" specifier in prototypes
Mikael Berthe <mikael@lilotux.net>
parents:
280
diff
changeset
|
325 int settings_get_int(guint type, const gchar *key) |
279 | 326 { |
281
f562b9af2de7
Add "const" specifier in prototypes
Mikael Berthe <mikael@lilotux.net>
parents:
280
diff
changeset
|
327 const gchar *setval = settings_get(type, key); |
279 | 328 |
329 if (setval) return atoi(setval); | |
330 return 0; | |
331 } | |
332 | |
294
871e53769084
Allow one status message per Jabber status
Mikael Berthe <mikael@lilotux.net>
parents:
293
diff
changeset
|
333 // settings_get_status_msg(status) |
871e53769084
Allow one status message per Jabber status
Mikael Berthe <mikael@lilotux.net>
parents:
293
diff
changeset
|
334 // Return a string with the current status message: |
871e53769084
Allow one status message per Jabber status
Mikael Berthe <mikael@lilotux.net>
parents:
293
diff
changeset
|
335 // - if there is a user-defined message ("message" option), |
871e53769084
Allow one status message per Jabber status
Mikael Berthe <mikael@lilotux.net>
parents:
293
diff
changeset
|
336 // return this message |
871e53769084
Allow one status message per Jabber status
Mikael Berthe <mikael@lilotux.net>
parents:
293
diff
changeset
|
337 // - if there is a user-defined message for the given status (and no |
871e53769084
Allow one status message per Jabber status
Mikael Berthe <mikael@lilotux.net>
parents:
293
diff
changeset
|
338 // generic user message), it is returned |
521 | 339 // - if no message is found, return NULL |
294
871e53769084
Allow one status message per Jabber status
Mikael Berthe <mikael@lilotux.net>
parents:
293
diff
changeset
|
340 const gchar *settings_get_status_msg(enum imstatus status) |
871e53769084
Allow one status message per Jabber status
Mikael Berthe <mikael@lilotux.net>
parents:
293
diff
changeset
|
341 { |
871e53769084
Allow one status message per Jabber status
Mikael Berthe <mikael@lilotux.net>
parents:
293
diff
changeset
|
342 const gchar *rstatus = settings_opt_get("message"); |
871e53769084
Allow one status message per Jabber status
Mikael Berthe <mikael@lilotux.net>
parents:
293
diff
changeset
|
343 |
871e53769084
Allow one status message per Jabber status
Mikael Berthe <mikael@lilotux.net>
parents:
293
diff
changeset
|
344 if (rstatus) return rstatus; |
871e53769084
Allow one status message per Jabber status
Mikael Berthe <mikael@lilotux.net>
parents:
293
diff
changeset
|
345 |
871e53769084
Allow one status message per Jabber status
Mikael Berthe <mikael@lilotux.net>
parents:
293
diff
changeset
|
346 switch(status) { |
871e53769084
Allow one status message per Jabber status
Mikael Berthe <mikael@lilotux.net>
parents:
293
diff
changeset
|
347 case available: |
521 | 348 rstatus = settings_opt_get("message_avail"); |
294
871e53769084
Allow one status message per Jabber status
Mikael Berthe <mikael@lilotux.net>
parents:
293
diff
changeset
|
349 break; |
871e53769084
Allow one status message per Jabber status
Mikael Berthe <mikael@lilotux.net>
parents:
293
diff
changeset
|
350 |
871e53769084
Allow one status message per Jabber status
Mikael Berthe <mikael@lilotux.net>
parents:
293
diff
changeset
|
351 case freeforchat: |
521 | 352 rstatus = settings_opt_get("message_free"); |
294
871e53769084
Allow one status message per Jabber status
Mikael Berthe <mikael@lilotux.net>
parents:
293
diff
changeset
|
353 break; |
871e53769084
Allow one status message per Jabber status
Mikael Berthe <mikael@lilotux.net>
parents:
293
diff
changeset
|
354 |
871e53769084
Allow one status message per Jabber status
Mikael Berthe <mikael@lilotux.net>
parents:
293
diff
changeset
|
355 case dontdisturb: |
521 | 356 rstatus = settings_opt_get("message_dnd"); |
294
871e53769084
Allow one status message per Jabber status
Mikael Berthe <mikael@lilotux.net>
parents:
293
diff
changeset
|
357 break; |
871e53769084
Allow one status message per Jabber status
Mikael Berthe <mikael@lilotux.net>
parents:
293
diff
changeset
|
358 |
871e53769084
Allow one status message per Jabber status
Mikael Berthe <mikael@lilotux.net>
parents:
293
diff
changeset
|
359 case notavail: |
521 | 360 rstatus = settings_opt_get("message_notavail"); |
294
871e53769084
Allow one status message per Jabber status
Mikael Berthe <mikael@lilotux.net>
parents:
293
diff
changeset
|
361 break; |
871e53769084
Allow one status message per Jabber status
Mikael Berthe <mikael@lilotux.net>
parents:
293
diff
changeset
|
362 |
871e53769084
Allow one status message per Jabber status
Mikael Berthe <mikael@lilotux.net>
parents:
293
diff
changeset
|
363 case away: |
521 | 364 rstatus = settings_opt_get("message_away"); |
294
871e53769084
Allow one status message per Jabber status
Mikael Berthe <mikael@lilotux.net>
parents:
293
diff
changeset
|
365 break; |
871e53769084
Allow one status message per Jabber status
Mikael Berthe <mikael@lilotux.net>
parents:
293
diff
changeset
|
366 |
521 | 367 default: // offline, invisible |
368 break; | |
294
871e53769084
Allow one status message per Jabber status
Mikael Berthe <mikael@lilotux.net>
parents:
293
diff
changeset
|
369 } |
871e53769084
Allow one status message per Jabber status
Mikael Berthe <mikael@lilotux.net>
parents:
293
diff
changeset
|
370 return rstatus; |
871e53769084
Allow one status message per Jabber status
Mikael Berthe <mikael@lilotux.net>
parents:
293
diff
changeset
|
371 } |
576 | 372 |
867
7f056c566569
Commands /alias & /bind list the key bindings and aliases
Mikael Berthe <mikael@lilotux.net>
parents:
780
diff
changeset
|
373 // settings_foreach(type, pfunction, param) |
7f056c566569
Commands /alias & /bind list the key bindings and aliases
Mikael Berthe <mikael@lilotux.net>
parents:
780
diff
changeset
|
374 // Call pfunction(param, key, value) for each setting with requested type. |
1070
9eaacc0ad3a2
Use a hash for settings
Mikael Berthe <mikael@lilotux.net>
parents:
1068
diff
changeset
|
375 void settings_foreach(guint type, void (*pfunc)(char *k, char *v, void *param), |
867
7f056c566569
Commands /alias & /bind list the key bindings and aliases
Mikael Berthe <mikael@lilotux.net>
parents:
780
diff
changeset
|
376 void *param) |
7f056c566569
Commands /alias & /bind list the key bindings and aliases
Mikael Berthe <mikael@lilotux.net>
parents:
780
diff
changeset
|
377 { |
1070
9eaacc0ad3a2
Use a hash for settings
Mikael Berthe <mikael@lilotux.net>
parents:
1068
diff
changeset
|
378 GHashTable *hash; |
867
7f056c566569
Commands /alias & /bind list the key bindings and aliases
Mikael Berthe <mikael@lilotux.net>
parents:
780
diff
changeset
|
379 |
1070
9eaacc0ad3a2
Use a hash for settings
Mikael Berthe <mikael@lilotux.net>
parents:
1068
diff
changeset
|
380 hash = get_hash(type); |
9eaacc0ad3a2
Use a hash for settings
Mikael Berthe <mikael@lilotux.net>
parents:
1068
diff
changeset
|
381 if (!hash) |
9eaacc0ad3a2
Use a hash for settings
Mikael Berthe <mikael@lilotux.net>
parents:
1068
diff
changeset
|
382 return; |
867
7f056c566569
Commands /alias & /bind list the key bindings and aliases
Mikael Berthe <mikael@lilotux.net>
parents:
780
diff
changeset
|
383 |
1070
9eaacc0ad3a2
Use a hash for settings
Mikael Berthe <mikael@lilotux.net>
parents:
1068
diff
changeset
|
384 g_hash_table_foreach(hash, (GHFunc)pfunc, param); |
867
7f056c566569
Commands /alias & /bind list the key bindings and aliases
Mikael Berthe <mikael@lilotux.net>
parents:
780
diff
changeset
|
385 } |
7f056c566569
Commands /alias & /bind list the key bindings and aliases
Mikael Berthe <mikael@lilotux.net>
parents:
780
diff
changeset
|
386 |
1004
b57a01ffeed6
Use existing conference bookmarks
Mikael Berthe <mikael@lilotux.net>
parents:
967
diff
changeset
|
387 |
b57a01ffeed6
Use existing conference bookmarks
Mikael Berthe <mikael@lilotux.net>
parents:
967
diff
changeset
|
388 // default_muc_nickname() |
b57a01ffeed6
Use existing conference bookmarks
Mikael Berthe <mikael@lilotux.net>
parents:
967
diff
changeset
|
389 // Return the user's default nickname |
b57a01ffeed6
Use existing conference bookmarks
Mikael Berthe <mikael@lilotux.net>
parents:
967
diff
changeset
|
390 // The caller should free the string after use |
1395
d431cd75eb53
Use bookmarked nickname when manually joining a room
Mikael Berthe <mikael@lilotux.net>
parents:
1383
diff
changeset
|
391 char *default_muc_nickname(const char *roomid) |
1004
b57a01ffeed6
Use existing conference bookmarks
Mikael Berthe <mikael@lilotux.net>
parents:
967
diff
changeset
|
392 { |
b57a01ffeed6
Use existing conference bookmarks
Mikael Berthe <mikael@lilotux.net>
parents:
967
diff
changeset
|
393 char *nick; |
b57a01ffeed6
Use existing conference bookmarks
Mikael Berthe <mikael@lilotux.net>
parents:
967
diff
changeset
|
394 |
1395
d431cd75eb53
Use bookmarked nickname when manually joining a room
Mikael Berthe <mikael@lilotux.net>
parents:
1383
diff
changeset
|
395 nick = (char*)jb_get_bookmark_nick(roomid); |
d431cd75eb53
Use bookmarked nickname when manually joining a room
Mikael Berthe <mikael@lilotux.net>
parents:
1383
diff
changeset
|
396 if (nick) |
d431cd75eb53
Use bookmarked nickname when manually joining a room
Mikael Berthe <mikael@lilotux.net>
parents:
1383
diff
changeset
|
397 return g_strdup(nick); |
d431cd75eb53
Use bookmarked nickname when manually joining a room
Mikael Berthe <mikael@lilotux.net>
parents:
1383
diff
changeset
|
398 |
1004
b57a01ffeed6
Use existing conference bookmarks
Mikael Berthe <mikael@lilotux.net>
parents:
967
diff
changeset
|
399 // We try the "nickname" option, then the username part of the jid. |
b57a01ffeed6
Use existing conference bookmarks
Mikael Berthe <mikael@lilotux.net>
parents:
967
diff
changeset
|
400 nick = (char*)settings_opt_get("nickname"); |
b57a01ffeed6
Use existing conference bookmarks
Mikael Berthe <mikael@lilotux.net>
parents:
967
diff
changeset
|
401 if (nick) |
b57a01ffeed6
Use existing conference bookmarks
Mikael Berthe <mikael@lilotux.net>
parents:
967
diff
changeset
|
402 return g_strdup(nick); |
b57a01ffeed6
Use existing conference bookmarks
Mikael Berthe <mikael@lilotux.net>
parents:
967
diff
changeset
|
403 |
b57a01ffeed6
Use existing conference bookmarks
Mikael Berthe <mikael@lilotux.net>
parents:
967
diff
changeset
|
404 nick = g_strdup(settings_opt_get("username")); |
b57a01ffeed6
Use existing conference bookmarks
Mikael Berthe <mikael@lilotux.net>
parents:
967
diff
changeset
|
405 if (nick) { |
b57a01ffeed6
Use existing conference bookmarks
Mikael Berthe <mikael@lilotux.net>
parents:
967
diff
changeset
|
406 char *p = strchr(nick, JID_DOMAIN_SEPARATOR); |
b57a01ffeed6
Use existing conference bookmarks
Mikael Berthe <mikael@lilotux.net>
parents:
967
diff
changeset
|
407 if (p > nick) |
b57a01ffeed6
Use existing conference bookmarks
Mikael Berthe <mikael@lilotux.net>
parents:
967
diff
changeset
|
408 *p = 0; |
b57a01ffeed6
Use existing conference bookmarks
Mikael Berthe <mikael@lilotux.net>
parents:
967
diff
changeset
|
409 } |
b57a01ffeed6
Use existing conference bookmarks
Mikael Berthe <mikael@lilotux.net>
parents:
967
diff
changeset
|
410 return nick; |
b57a01ffeed6
Use existing conference bookmarks
Mikael Berthe <mikael@lilotux.net>
parents:
967
diff
changeset
|
411 } |
b57a01ffeed6
Use existing conference bookmarks
Mikael Berthe <mikael@lilotux.net>
parents:
967
diff
changeset
|
412 |
1065
230dca34dbea
Extand pgp_data structure
Mikael Berthe <mikael@lilotux.net>
parents:
1004
diff
changeset
|
413 |
230dca34dbea
Extand pgp_data structure
Mikael Berthe <mikael@lilotux.net>
parents:
1004
diff
changeset
|
414 /* PGP settings */ |
230dca34dbea
Extand pgp_data structure
Mikael Berthe <mikael@lilotux.net>
parents:
1004
diff
changeset
|
415 |
230dca34dbea
Extand pgp_data structure
Mikael Berthe <mikael@lilotux.net>
parents:
1004
diff
changeset
|
416 // settings_pgp_setdisabled(jid, value) |
230dca34dbea
Extand pgp_data structure
Mikael Berthe <mikael@lilotux.net>
parents:
1004
diff
changeset
|
417 // Enable/disable PGP encryption for jid. |
230dca34dbea
Extand pgp_data structure
Mikael Berthe <mikael@lilotux.net>
parents:
1004
diff
changeset
|
418 // (Set value to TRUE to disable encryption) |
230dca34dbea
Extand pgp_data structure
Mikael Berthe <mikael@lilotux.net>
parents:
1004
diff
changeset
|
419 void settings_pgp_setdisabled(const char *bjid, guint value) |
230dca34dbea
Extand pgp_data structure
Mikael Berthe <mikael@lilotux.net>
parents:
1004
diff
changeset
|
420 { |
230dca34dbea
Extand pgp_data structure
Mikael Berthe <mikael@lilotux.net>
parents:
1004
diff
changeset
|
421 #ifdef HAVE_GPGME |
230dca34dbea
Extand pgp_data structure
Mikael Berthe <mikael@lilotux.net>
parents:
1004
diff
changeset
|
422 T_pgpopt *pgpdata; |
230dca34dbea
Extand pgp_data structure
Mikael Berthe <mikael@lilotux.net>
parents:
1004
diff
changeset
|
423 pgpdata = g_hash_table_lookup(pgpopt, bjid); |
230dca34dbea
Extand pgp_data structure
Mikael Berthe <mikael@lilotux.net>
parents:
1004
diff
changeset
|
424 if (!pgpdata) { |
230dca34dbea
Extand pgp_data structure
Mikael Berthe <mikael@lilotux.net>
parents:
1004
diff
changeset
|
425 // If value is 0, we do not need to create a structure (that's |
230dca34dbea
Extand pgp_data structure
Mikael Berthe <mikael@lilotux.net>
parents:
1004
diff
changeset
|
426 // the default value). |
230dca34dbea
Extand pgp_data structure
Mikael Berthe <mikael@lilotux.net>
parents:
1004
diff
changeset
|
427 if (value) { |
230dca34dbea
Extand pgp_data structure
Mikael Berthe <mikael@lilotux.net>
parents:
1004
diff
changeset
|
428 pgpdata = g_new0(T_pgpopt, 1); |
230dca34dbea
Extand pgp_data structure
Mikael Berthe <mikael@lilotux.net>
parents:
1004
diff
changeset
|
429 pgpdata->pgp_disabled = value; |
230dca34dbea
Extand pgp_data structure
Mikael Berthe <mikael@lilotux.net>
parents:
1004
diff
changeset
|
430 g_hash_table_insert(pgpopt, g_strdup(bjid), pgpdata); |
230dca34dbea
Extand pgp_data structure
Mikael Berthe <mikael@lilotux.net>
parents:
1004
diff
changeset
|
431 } |
230dca34dbea
Extand pgp_data structure
Mikael Berthe <mikael@lilotux.net>
parents:
1004
diff
changeset
|
432 } else { |
230dca34dbea
Extand pgp_data structure
Mikael Berthe <mikael@lilotux.net>
parents:
1004
diff
changeset
|
433 pgpdata->pgp_disabled = value; |
230dca34dbea
Extand pgp_data structure
Mikael Berthe <mikael@lilotux.net>
parents:
1004
diff
changeset
|
434 // We could remove the key/value if pgp_disabled is 0 and |
230dca34dbea
Extand pgp_data structure
Mikael Berthe <mikael@lilotux.net>
parents:
1004
diff
changeset
|
435 // pgp_keyid is NULL, actually. |
230dca34dbea
Extand pgp_data structure
Mikael Berthe <mikael@lilotux.net>
parents:
1004
diff
changeset
|
436 } |
230dca34dbea
Extand pgp_data structure
Mikael Berthe <mikael@lilotux.net>
parents:
1004
diff
changeset
|
437 #endif |
230dca34dbea
Extand pgp_data structure
Mikael Berthe <mikael@lilotux.net>
parents:
1004
diff
changeset
|
438 } |
230dca34dbea
Extand pgp_data structure
Mikael Berthe <mikael@lilotux.net>
parents:
1004
diff
changeset
|
439 |
230dca34dbea
Extand pgp_data structure
Mikael Berthe <mikael@lilotux.net>
parents:
1004
diff
changeset
|
440 // settings_pgp_getdisabled(jid) |
230dca34dbea
Extand pgp_data structure
Mikael Berthe <mikael@lilotux.net>
parents:
1004
diff
changeset
|
441 // Return TRUE if PGP encryption should be disabled for jid. |
230dca34dbea
Extand pgp_data structure
Mikael Berthe <mikael@lilotux.net>
parents:
1004
diff
changeset
|
442 guint settings_pgp_getdisabled(const char *bjid) |
230dca34dbea
Extand pgp_data structure
Mikael Berthe <mikael@lilotux.net>
parents:
1004
diff
changeset
|
443 { |
230dca34dbea
Extand pgp_data structure
Mikael Berthe <mikael@lilotux.net>
parents:
1004
diff
changeset
|
444 #ifdef HAVE_GPGME |
230dca34dbea
Extand pgp_data structure
Mikael Berthe <mikael@lilotux.net>
parents:
1004
diff
changeset
|
445 T_pgpopt *pgpdata; |
230dca34dbea
Extand pgp_data structure
Mikael Berthe <mikael@lilotux.net>
parents:
1004
diff
changeset
|
446 pgpdata = g_hash_table_lookup(pgpopt, bjid); |
230dca34dbea
Extand pgp_data structure
Mikael Berthe <mikael@lilotux.net>
parents:
1004
diff
changeset
|
447 if (pgpdata) |
230dca34dbea
Extand pgp_data structure
Mikael Berthe <mikael@lilotux.net>
parents:
1004
diff
changeset
|
448 return pgpdata->pgp_disabled; |
230dca34dbea
Extand pgp_data structure
Mikael Berthe <mikael@lilotux.net>
parents:
1004
diff
changeset
|
449 else |
1197 | 450 return FALSE; // Default: not disabled |
1065
230dca34dbea
Extand pgp_data structure
Mikael Berthe <mikael@lilotux.net>
parents:
1004
diff
changeset
|
451 #else |
230dca34dbea
Extand pgp_data structure
Mikael Berthe <mikael@lilotux.net>
parents:
1004
diff
changeset
|
452 return TRUE; // No PGP support, let's say it's disabled. |
230dca34dbea
Extand pgp_data structure
Mikael Berthe <mikael@lilotux.net>
parents:
1004
diff
changeset
|
453 #endif |
230dca34dbea
Extand pgp_data structure
Mikael Berthe <mikael@lilotux.net>
parents:
1004
diff
changeset
|
454 } |
230dca34dbea
Extand pgp_data structure
Mikael Berthe <mikael@lilotux.net>
parents:
1004
diff
changeset
|
455 |
1197 | 456 // settings_pgp_setforce(jid, value) |
457 // Force (or not) PGP encryption for jid. | |
458 // When value is TRUE, PGP support will be assumed for the remote client. | |
459 void settings_pgp_setforce(const char *bjid, guint value) | |
460 { | |
461 #ifdef HAVE_GPGME | |
462 T_pgpopt *pgpdata; | |
463 pgpdata = g_hash_table_lookup(pgpopt, bjid); | |
464 if (!pgpdata) { | |
465 // If value is 0, we do not need to create a structure (that's | |
466 // the default value). | |
467 if (value) { | |
468 pgpdata = g_new0(T_pgpopt, 1); | |
469 pgpdata->pgp_force = value; | |
470 g_hash_table_insert(pgpopt, g_strdup(bjid), pgpdata); | |
471 } | |
472 } else { | |
473 pgpdata->pgp_force = value; | |
474 } | |
475 if (!pgpdata->pgp_keyid) | |
476 scr_LogPrint(LPRINT_NORMAL, "Warning: the Key Id is not set!"); | |
477 #endif | |
478 } | |
479 | |
480 // settings_pgp_getforce(jid) | |
481 // Return TRUE if PGP enforcement is set for jid. | |
482 guint settings_pgp_getforce(const char *bjid) | |
483 { | |
484 #ifdef HAVE_GPGME | |
485 T_pgpopt *pgpdata; | |
486 pgpdata = g_hash_table_lookup(pgpopt, bjid); | |
487 if (pgpdata) | |
488 return pgpdata->pgp_force; | |
489 else | |
490 return FALSE; // Default | |
491 #else | |
492 return FALSE; // No PGP support | |
493 #endif | |
494 } | |
495 | |
1065
230dca34dbea
Extand pgp_data structure
Mikael Berthe <mikael@lilotux.net>
parents:
1004
diff
changeset
|
496 // settings_pgp_setkeyid(jid, keyid) |
230dca34dbea
Extand pgp_data structure
Mikael Berthe <mikael@lilotux.net>
parents:
1004
diff
changeset
|
497 // Set the PGP KeyId for user jid. |
230dca34dbea
Extand pgp_data structure
Mikael Berthe <mikael@lilotux.net>
parents:
1004
diff
changeset
|
498 // Use keyid = NULL to erase the previous KeyId. |
230dca34dbea
Extand pgp_data structure
Mikael Berthe <mikael@lilotux.net>
parents:
1004
diff
changeset
|
499 void settings_pgp_setkeyid(const char *bjid, const char *keyid) |
230dca34dbea
Extand pgp_data structure
Mikael Berthe <mikael@lilotux.net>
parents:
1004
diff
changeset
|
500 { |
230dca34dbea
Extand pgp_data structure
Mikael Berthe <mikael@lilotux.net>
parents:
1004
diff
changeset
|
501 #ifdef HAVE_GPGME |
230dca34dbea
Extand pgp_data structure
Mikael Berthe <mikael@lilotux.net>
parents:
1004
diff
changeset
|
502 T_pgpopt *pgpdata; |
230dca34dbea
Extand pgp_data structure
Mikael Berthe <mikael@lilotux.net>
parents:
1004
diff
changeset
|
503 pgpdata = g_hash_table_lookup(pgpopt, bjid); |
230dca34dbea
Extand pgp_data structure
Mikael Berthe <mikael@lilotux.net>
parents:
1004
diff
changeset
|
504 if (!pgpdata) { |
230dca34dbea
Extand pgp_data structure
Mikael Berthe <mikael@lilotux.net>
parents:
1004
diff
changeset
|
505 // If keyid is NULL, we do not need to create a structure (that's |
230dca34dbea
Extand pgp_data structure
Mikael Berthe <mikael@lilotux.net>
parents:
1004
diff
changeset
|
506 // the default value). |
230dca34dbea
Extand pgp_data structure
Mikael Berthe <mikael@lilotux.net>
parents:
1004
diff
changeset
|
507 if (keyid) { |
230dca34dbea
Extand pgp_data structure
Mikael Berthe <mikael@lilotux.net>
parents:
1004
diff
changeset
|
508 pgpdata = g_new0(T_pgpopt, 1); |
230dca34dbea
Extand pgp_data structure
Mikael Berthe <mikael@lilotux.net>
parents:
1004
diff
changeset
|
509 pgpdata->pgp_keyid = g_strdup(keyid); |
230dca34dbea
Extand pgp_data structure
Mikael Berthe <mikael@lilotux.net>
parents:
1004
diff
changeset
|
510 g_hash_table_insert(pgpopt, g_strdup(bjid), pgpdata); |
230dca34dbea
Extand pgp_data structure
Mikael Berthe <mikael@lilotux.net>
parents:
1004
diff
changeset
|
511 } |
230dca34dbea
Extand pgp_data structure
Mikael Berthe <mikael@lilotux.net>
parents:
1004
diff
changeset
|
512 } else { |
230dca34dbea
Extand pgp_data structure
Mikael Berthe <mikael@lilotux.net>
parents:
1004
diff
changeset
|
513 g_free(pgpdata->pgp_keyid); |
230dca34dbea
Extand pgp_data structure
Mikael Berthe <mikael@lilotux.net>
parents:
1004
diff
changeset
|
514 if (keyid) |
230dca34dbea
Extand pgp_data structure
Mikael Berthe <mikael@lilotux.net>
parents:
1004
diff
changeset
|
515 pgpdata->pgp_keyid = g_strdup(keyid); |
230dca34dbea
Extand pgp_data structure
Mikael Berthe <mikael@lilotux.net>
parents:
1004
diff
changeset
|
516 else |
230dca34dbea
Extand pgp_data structure
Mikael Berthe <mikael@lilotux.net>
parents:
1004
diff
changeset
|
517 pgpdata->pgp_keyid = NULL; |
230dca34dbea
Extand pgp_data structure
Mikael Berthe <mikael@lilotux.net>
parents:
1004
diff
changeset
|
518 // We could remove the key/value if pgp_disabled is 0 and |
230dca34dbea
Extand pgp_data structure
Mikael Berthe <mikael@lilotux.net>
parents:
1004
diff
changeset
|
519 // pgp_keyid is NULL, actually. |
230dca34dbea
Extand pgp_data structure
Mikael Berthe <mikael@lilotux.net>
parents:
1004
diff
changeset
|
520 } |
230dca34dbea
Extand pgp_data structure
Mikael Berthe <mikael@lilotux.net>
parents:
1004
diff
changeset
|
521 #endif |
230dca34dbea
Extand pgp_data structure
Mikael Berthe <mikael@lilotux.net>
parents:
1004
diff
changeset
|
522 } |
230dca34dbea
Extand pgp_data structure
Mikael Berthe <mikael@lilotux.net>
parents:
1004
diff
changeset
|
523 |
230dca34dbea
Extand pgp_data structure
Mikael Berthe <mikael@lilotux.net>
parents:
1004
diff
changeset
|
524 // settings_pgp_getkeyid(jid) |
230dca34dbea
Extand pgp_data structure
Mikael Berthe <mikael@lilotux.net>
parents:
1004
diff
changeset
|
525 // Get the PGP KeyId for user jid. |
230dca34dbea
Extand pgp_data structure
Mikael Berthe <mikael@lilotux.net>
parents:
1004
diff
changeset
|
526 const char *settings_pgp_getkeyid(const char *bjid) |
230dca34dbea
Extand pgp_data structure
Mikael Berthe <mikael@lilotux.net>
parents:
1004
diff
changeset
|
527 { |
230dca34dbea
Extand pgp_data structure
Mikael Berthe <mikael@lilotux.net>
parents:
1004
diff
changeset
|
528 #ifdef HAVE_GPGME |
230dca34dbea
Extand pgp_data structure
Mikael Berthe <mikael@lilotux.net>
parents:
1004
diff
changeset
|
529 T_pgpopt *pgpdata; |
230dca34dbea
Extand pgp_data structure
Mikael Berthe <mikael@lilotux.net>
parents:
1004
diff
changeset
|
530 pgpdata = g_hash_table_lookup(pgpopt, bjid); |
230dca34dbea
Extand pgp_data structure
Mikael Berthe <mikael@lilotux.net>
parents:
1004
diff
changeset
|
531 if (pgpdata) |
230dca34dbea
Extand pgp_data structure
Mikael Berthe <mikael@lilotux.net>
parents:
1004
diff
changeset
|
532 return pgpdata->pgp_keyid; |
230dca34dbea
Extand pgp_data structure
Mikael Berthe <mikael@lilotux.net>
parents:
1004
diff
changeset
|
533 #endif |
230dca34dbea
Extand pgp_data structure
Mikael Berthe <mikael@lilotux.net>
parents:
1004
diff
changeset
|
534 return NULL; |
230dca34dbea
Extand pgp_data structure
Mikael Berthe <mikael@lilotux.net>
parents:
1004
diff
changeset
|
535 } |
230dca34dbea
Extand pgp_data structure
Mikael Berthe <mikael@lilotux.net>
parents:
1004
diff
changeset
|
536 |
1299
3b338a5c01fc
OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
1278
diff
changeset
|
537 /* otr settings */ |
3b338a5c01fc
OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
1278
diff
changeset
|
538 |
3b338a5c01fc
OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
1278
diff
changeset
|
539 #ifdef HAVE_LIBOTR |
3b338a5c01fc
OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
1278
diff
changeset
|
540 static void remove_default_policies(char * k, char * policy, void * defaultp) |
3b338a5c01fc
OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
1278
diff
changeset
|
541 { |
3b338a5c01fc
OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
1278
diff
changeset
|
542 if (*(enum otr_policy *)policy == *(enum otr_policy *)defaultp) { |
3b338a5c01fc
OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
1278
diff
changeset
|
543 g_free((enum otr_policy *) policy); |
3b338a5c01fc
OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
1278
diff
changeset
|
544 g_hash_table_remove(otrpolicy, k); |
3b338a5c01fc
OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
1278
diff
changeset
|
545 } |
3b338a5c01fc
OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
1278
diff
changeset
|
546 } |
3b338a5c01fc
OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
1278
diff
changeset
|
547 #endif |
3b338a5c01fc
OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
1278
diff
changeset
|
548 |
3b338a5c01fc
OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
1278
diff
changeset
|
549 void settings_otr_setpolicy(const char *bjid, guint value) |
3b338a5c01fc
OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
1278
diff
changeset
|
550 { |
3b338a5c01fc
OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
1278
diff
changeset
|
551 #ifdef HAVE_LIBOTR |
3b338a5c01fc
OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
1278
diff
changeset
|
552 enum otr_policy *otrdata; |
3b338a5c01fc
OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
1278
diff
changeset
|
553 |
3b338a5c01fc
OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
1278
diff
changeset
|
554 if (!bjid) { |
3b338a5c01fc
OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
1278
diff
changeset
|
555 default_policy = value; |
3b338a5c01fc
OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
1278
diff
changeset
|
556 /* refresh hash */ |
3b338a5c01fc
OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
1278
diff
changeset
|
557 settings_foreach(SETTINGS_TYPE_OTR, &remove_default_policies, &value); |
3b338a5c01fc
OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
1278
diff
changeset
|
558 return; |
3b338a5c01fc
OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
1278
diff
changeset
|
559 } |
3b338a5c01fc
OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
1278
diff
changeset
|
560 |
3b338a5c01fc
OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
1278
diff
changeset
|
561 otrdata = g_hash_table_lookup(otrpolicy, bjid); |
3b338a5c01fc
OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
1278
diff
changeset
|
562 |
3b338a5c01fc
OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
1278
diff
changeset
|
563 if (value == default_policy) { |
3b338a5c01fc
OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
1278
diff
changeset
|
564 if (otrdata) { |
3b338a5c01fc
OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
1278
diff
changeset
|
565 g_free(otrdata); |
3b338a5c01fc
OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
1278
diff
changeset
|
566 g_hash_table_remove(otrpolicy, bjid); |
3b338a5c01fc
OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
1278
diff
changeset
|
567 } |
3b338a5c01fc
OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
1278
diff
changeset
|
568 } else if (otrdata) { |
3b338a5c01fc
OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
1278
diff
changeset
|
569 *otrdata = value; |
3b338a5c01fc
OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
1278
diff
changeset
|
570 } else { |
3b338a5c01fc
OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
1278
diff
changeset
|
571 otrdata = g_new(enum otr_policy, 1); |
3b338a5c01fc
OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
1278
diff
changeset
|
572 *otrdata = value; |
3b338a5c01fc
OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
1278
diff
changeset
|
573 g_hash_table_insert(otrpolicy, g_strdup(bjid), otrdata); |
3b338a5c01fc
OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
1278
diff
changeset
|
574 } |
3b338a5c01fc
OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
1278
diff
changeset
|
575 #endif |
3b338a5c01fc
OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
1278
diff
changeset
|
576 } |
3b338a5c01fc
OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
1278
diff
changeset
|
577 |
3b338a5c01fc
OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
1278
diff
changeset
|
578 guint settings_otr_getpolicy(const char *bjid) |
3b338a5c01fc
OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
1278
diff
changeset
|
579 { |
3b338a5c01fc
OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
1278
diff
changeset
|
580 #ifdef HAVE_LIBOTR |
3b338a5c01fc
OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
1278
diff
changeset
|
581 enum otr_policy * otrdata; |
3b338a5c01fc
OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
1278
diff
changeset
|
582 if (!bjid) |
3b338a5c01fc
OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
1278
diff
changeset
|
583 return default_policy; |
3b338a5c01fc
OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
1278
diff
changeset
|
584 |
3b338a5c01fc
OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
1278
diff
changeset
|
585 otrdata = g_hash_table_lookup(otrpolicy, bjid); |
3b338a5c01fc
OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
1278
diff
changeset
|
586 if (otrdata) |
3b338a5c01fc
OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
1278
diff
changeset
|
587 return *otrdata; |
3b338a5c01fc
OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
1278
diff
changeset
|
588 else |
3b338a5c01fc
OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
1278
diff
changeset
|
589 return default_policy; |
3b338a5c01fc
OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
1278
diff
changeset
|
590 #else |
3b338a5c01fc
OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
1278
diff
changeset
|
591 return 0; |
3b338a5c01fc
OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
1278
diff
changeset
|
592 #endif |
3b338a5c01fc
OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
1278
diff
changeset
|
593 } |
3b338a5c01fc
OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
1278
diff
changeset
|
594 |
1141
5be2408a6534
Add option "max_history_blocks"
Mikael Berthe <mikael@lilotux.net>
parents:
1074
diff
changeset
|
595 guint get_max_history_blocks(void) |
5be2408a6534
Add option "max_history_blocks"
Mikael Berthe <mikael@lilotux.net>
parents:
1074
diff
changeset
|
596 { |
5be2408a6534
Add option "max_history_blocks"
Mikael Berthe <mikael@lilotux.net>
parents:
1074
diff
changeset
|
597 int max_num_of_blocks = settings_opt_get_int("max_history_blocks"); |
5be2408a6534
Add option "max_history_blocks"
Mikael Berthe <mikael@lilotux.net>
parents:
1074
diff
changeset
|
598 if (max_num_of_blocks < 0) |
5be2408a6534
Add option "max_history_blocks"
Mikael Berthe <mikael@lilotux.net>
parents:
1074
diff
changeset
|
599 max_num_of_blocks = 0; |
5be2408a6534
Add option "max_history_blocks"
Mikael Berthe <mikael@lilotux.net>
parents:
1074
diff
changeset
|
600 else if (max_num_of_blocks == 1) |
5be2408a6534
Add option "max_history_blocks"
Mikael Berthe <mikael@lilotux.net>
parents:
1074
diff
changeset
|
601 max_num_of_blocks = 2; |
5be2408a6534
Add option "max_history_blocks"
Mikael Berthe <mikael@lilotux.net>
parents:
1074
diff
changeset
|
602 return (guint)max_num_of_blocks; |
5be2408a6534
Add option "max_history_blocks"
Mikael Berthe <mikael@lilotux.net>
parents:
1074
diff
changeset
|
603 } |
5be2408a6534
Add option "max_history_blocks"
Mikael Berthe <mikael@lilotux.net>
parents:
1074
diff
changeset
|
604 |
580 | 605 /* vim: set expandtab cindent cinoptions=>2\:2(0: For Vim users... */ |