Mercurial > hg
annotate mcabber/mcabber/settings.c @ 2339:7f11a567d236
Implemented settings_free()
This removes many leaked memory messages from valgrind and thus makes
it easier to read its output.
author | franky |
---|---|
date | Sat, 18 May 2019 20:44:01 +0200 |
parents | ffd0e57e9563 |
children | 6eeef7be58f3 |
rev | line source |
---|---|
279 | 1 /* |
2 * settings.c -- Configuration stuff | |
393 | 3 * |
2204
ccd4ffa41a1b
Use XDG configuration directory if a config file exists
Mikael Berthe <mikael@lilotux.net>
parents:
2164
diff
changeset
|
4 * Copyright (C) 2005-2015 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 | |
2268
f5402d705f67
Fix FSF addresses in all files
Mikael Berthe <mikael@lilotux.net>
parents:
2253
diff
changeset
|
17 * along with this program; if not, see <http://www.gnu.org/licenses/>. |
279 | 18 */ |
19 | |
1598 | 20 #include <stdio.h> |
279 | 21 #include <stdlib.h> |
1598 | 22 #include <string.h> |
2204
ccd4ffa41a1b
Use XDG configuration directory if a config file exists
Mikael Berthe <mikael@lilotux.net>
parents:
2164
diff
changeset
|
23 #include <sys/stat.h> |
279 | 24 |
1607 | 25 #include "config.h" |
279 | 26 #include "settings.h" |
341
dea407d53fe6
Improve configuration file reading
Mikael Berthe <mikael@lilotux.net>
parents:
337
diff
changeset
|
27 #include "commands.h" |
378
2e6c7b1440d1
Improve debugging/logging
Mikael Berthe <mikael@lilotux.net>
parents:
374
diff
changeset
|
28 #include "logprint.h" |
1299
3b338a5c01fc
OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
1278
diff
changeset
|
29 #include "otr.h" |
1598 | 30 #include "utils.h" |
31 #include "xmpp.h" | |
1653
fca9a4c17432
Improve UI latency and CPU usage
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1611
diff
changeset
|
32 #include "main.h" |
279 | 33 |
1299
3b338a5c01fc
OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
1278
diff
changeset
|
34 // Maximum line length |
1278
c3107650d165
Allow longer lines in config file
Mikael Berthe <mikael@lilotux.net>
parents:
1272
diff
changeset
|
35 // (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
|
36 #define CONFLINE_LENGTH 1024 |
c3107650d165
Allow longer lines in config file
Mikael Berthe <mikael@lilotux.net>
parents:
1272
diff
changeset
|
37 |
1070
9eaacc0ad3a2
Use a hash for settings
Mikael Berthe <mikael@lilotux.net>
parents:
1068
diff
changeset
|
38 static GHashTable *option; |
9eaacc0ad3a2
Use a hash for settings
Mikael Berthe <mikael@lilotux.net>
parents:
1068
diff
changeset
|
39 static GHashTable *alias; |
9eaacc0ad3a2
Use a hash for settings
Mikael Berthe <mikael@lilotux.net>
parents:
1068
diff
changeset
|
40 static GHashTable *binding; |
1673 | 41 static GHashTable *guards; |
279 | 42 |
1065
230dca34dbea
Extand pgp_data structure
Mikael Berthe <mikael@lilotux.net>
parents:
1004
diff
changeset
|
43 #ifdef HAVE_GPGME /* PGP settings */ |
230dca34dbea
Extand pgp_data structure
Mikael Berthe <mikael@lilotux.net>
parents:
1004
diff
changeset
|
44 static GHashTable *pgpopt; |
230dca34dbea
Extand pgp_data structure
Mikael Berthe <mikael@lilotux.net>
parents:
1004
diff
changeset
|
45 |
230dca34dbea
Extand pgp_data structure
Mikael Berthe <mikael@lilotux.net>
parents:
1004
diff
changeset
|
46 typedef struct { |
230dca34dbea
Extand pgp_data structure
Mikael Berthe <mikael@lilotux.net>
parents:
1004
diff
changeset
|
47 gchar *pgp_keyid; /* KeyId the contact is supposed to use */ |
230dca34dbea
Extand pgp_data structure
Mikael Berthe <mikael@lilotux.net>
parents:
1004
diff
changeset
|
48 guint pgp_disabled; /* If TRUE, PGP is disabled for outgoing messages */ |
1197 | 49 guint pgp_force; /* If TRUE, PGP is used w/o negotiation */ |
2337 | 50 } pgpopt_t; |
1065
230dca34dbea
Extand pgp_data structure
Mikael Berthe <mikael@lilotux.net>
parents:
1004
diff
changeset
|
51 #endif |
230dca34dbea
Extand pgp_data structure
Mikael Berthe <mikael@lilotux.net>
parents:
1004
diff
changeset
|
52 |
1768
d80a9e32ab1a
Refuse to replace existing guards
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1736
diff
changeset
|
53 typedef struct { |
d80a9e32ab1a
Refuse to replace existing guards
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1736
diff
changeset
|
54 settings_guard_t guard; |
d80a9e32ab1a
Refuse to replace existing guards
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1736
diff
changeset
|
55 } installed_guard_t; |
d80a9e32ab1a
Refuse to replace existing guards
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1736
diff
changeset
|
56 |
1299
3b338a5c01fc
OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
1278
diff
changeset
|
57 #ifdef HAVE_LIBOTR |
3b338a5c01fc
OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
1278
diff
changeset
|
58 static GHashTable *otrpolicy; |
3b338a5c01fc
OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
1278
diff
changeset
|
59 static enum otr_policy default_policy; |
3b338a5c01fc
OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
1278
diff
changeset
|
60 #endif |
3b338a5c01fc
OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
1278
diff
changeset
|
61 |
1070
9eaacc0ad3a2
Use a hash for settings
Mikael Berthe <mikael@lilotux.net>
parents:
1068
diff
changeset
|
62 static inline GHashTable *get_hash(guint type) |
279 | 63 { |
1070
9eaacc0ad3a2
Use a hash for settings
Mikael Berthe <mikael@lilotux.net>
parents:
1068
diff
changeset
|
64 if (type == SETTINGS_TYPE_OPTION) return option; |
9eaacc0ad3a2
Use a hash for settings
Mikael Berthe <mikael@lilotux.net>
parents:
1068
diff
changeset
|
65 else if (type == SETTINGS_TYPE_ALIAS) return alias; |
9eaacc0ad3a2
Use a hash for settings
Mikael Berthe <mikael@lilotux.net>
parents:
1068
diff
changeset
|
66 else if (type == SETTINGS_TYPE_BINDING) return binding; |
1299
3b338a5c01fc
OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
1278
diff
changeset
|
67 #ifdef HAVE_LIBOTR |
3b338a5c01fc
OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
1278
diff
changeset
|
68 else if (type == SETTINGS_TYPE_OTR) return otrpolicy; |
3b338a5c01fc
OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
1278
diff
changeset
|
69 #endif |
279 | 70 return NULL; |
71 } | |
72 | |
73 /* -- */ | |
74 | |
1065
230dca34dbea
Extand pgp_data structure
Mikael Berthe <mikael@lilotux.net>
parents:
1004
diff
changeset
|
75 void settings_init(void) |
230dca34dbea
Extand pgp_data structure
Mikael Berthe <mikael@lilotux.net>
parents:
1004
diff
changeset
|
76 { |
1070
9eaacc0ad3a2
Use a hash for settings
Mikael Berthe <mikael@lilotux.net>
parents:
1068
diff
changeset
|
77 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
|
78 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
|
79 binding = g_hash_table_new_full(&g_str_hash, &g_str_equal, &g_free, &g_free); |
1768
d80a9e32ab1a
Refuse to replace existing guards
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1736
diff
changeset
|
80 guards = 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
|
81 #ifdef HAVE_GPGME |
230dca34dbea
Extand pgp_data structure
Mikael Berthe <mikael@lilotux.net>
parents:
1004
diff
changeset
|
82 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
|
83 #endif |
1299
3b338a5c01fc
OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
1278
diff
changeset
|
84 #ifdef HAVE_LIBOTR |
3b338a5c01fc
OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
1278
diff
changeset
|
85 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
|
86 #endif |
1065
230dca34dbea
Extand pgp_data structure
Mikael Berthe <mikael@lilotux.net>
parents:
1004
diff
changeset
|
87 } |
230dca34dbea
Extand pgp_data structure
Mikael Berthe <mikael@lilotux.net>
parents:
1004
diff
changeset
|
88 |
2339 | 89 void settings_free(void) |
90 { | |
91 g_hash_table_destroy(option); | |
92 g_hash_table_destroy(alias); | |
93 g_hash_table_destroy(binding); | |
94 g_hash_table_destroy(guards); | |
95 #ifdef HAVE_GPGME | |
96 g_hash_table_destroy(pgpopt); | |
97 #endif | |
98 #ifdef HAVE_LIBOTR | |
99 g_hash_table_destroy(otrpolicy); | |
100 #endif | |
101 } | |
102 | |
2204
ccd4ffa41a1b
Use XDG configuration directory if a config file exists
Mikael Berthe <mikael@lilotux.net>
parents:
2164
diff
changeset
|
103 // settings_get_mcabber_config_dir() |
ccd4ffa41a1b
Use XDG configuration directory if a config file exists
Mikael Berthe <mikael@lilotux.net>
parents:
2164
diff
changeset
|
104 // Returns the mcabber configuration directory. |
ccd4ffa41a1b
Use XDG configuration directory if a config file exists
Mikael Berthe <mikael@lilotux.net>
parents:
2164
diff
changeset
|
105 // The directory is looked up for only once (and the string is never freed, |
ccd4ffa41a1b
Use XDG configuration directory if a config file exists
Mikael Berthe <mikael@lilotux.net>
parents:
2164
diff
changeset
|
106 // but we might change this later). |
ccd4ffa41a1b
Use XDG configuration directory if a config file exists
Mikael Berthe <mikael@lilotux.net>
parents:
2164
diff
changeset
|
107 const gchar *settings_get_mcabber_config_dir(void) |
ccd4ffa41a1b
Use XDG configuration directory if a config file exists
Mikael Berthe <mikael@lilotux.net>
parents:
2164
diff
changeset
|
108 { |
ccd4ffa41a1b
Use XDG configuration directory if a config file exists
Mikael Berthe <mikael@lilotux.net>
parents:
2164
diff
changeset
|
109 static char *config_dir; |
2253
5a107c907e71
Read $HOME/.mcabberrc if there is no mcabber configuration directory
Mikael Berthe <mikael@lilotux.net>
parents:
2204
diff
changeset
|
110 const char *home_dir; |
2204
ccd4ffa41a1b
Use XDG configuration directory if a config file exists
Mikael Berthe <mikael@lilotux.net>
parents:
2164
diff
changeset
|
111 GString *sfilename; |
ccd4ffa41a1b
Use XDG configuration directory if a config file exists
Mikael Berthe <mikael@lilotux.net>
parents:
2164
diff
changeset
|
112 FILE *fp; |
ccd4ffa41a1b
Use XDG configuration directory if a config file exists
Mikael Berthe <mikael@lilotux.net>
parents:
2164
diff
changeset
|
113 |
ccd4ffa41a1b
Use XDG configuration directory if a config file exists
Mikael Berthe <mikael@lilotux.net>
parents:
2164
diff
changeset
|
114 if (config_dir) |
ccd4ffa41a1b
Use XDG configuration directory if a config file exists
Mikael Berthe <mikael@lilotux.net>
parents:
2164
diff
changeset
|
115 return config_dir; |
ccd4ffa41a1b
Use XDG configuration directory if a config file exists
Mikael Berthe <mikael@lilotux.net>
parents:
2164
diff
changeset
|
116 |
ccd4ffa41a1b
Use XDG configuration directory if a config file exists
Mikael Berthe <mikael@lilotux.net>
parents:
2164
diff
changeset
|
117 home_dir = getenv("HOME"); |
ccd4ffa41a1b
Use XDG configuration directory if a config file exists
Mikael Berthe <mikael@lilotux.net>
parents:
2164
diff
changeset
|
118 if (!home_dir) { |
ccd4ffa41a1b
Use XDG configuration directory if a config file exists
Mikael Berthe <mikael@lilotux.net>
parents:
2164
diff
changeset
|
119 scr_log_print(LPRINT_LOG, "Can't find home dir!"); |
ccd4ffa41a1b
Use XDG configuration directory if a config file exists
Mikael Berthe <mikael@lilotux.net>
parents:
2164
diff
changeset
|
120 fprintf(stderr, "Can't find home dir!\n"); |
ccd4ffa41a1b
Use XDG configuration directory if a config file exists
Mikael Berthe <mikael@lilotux.net>
parents:
2164
diff
changeset
|
121 return NULL; |
ccd4ffa41a1b
Use XDG configuration directory if a config file exists
Mikael Berthe <mikael@lilotux.net>
parents:
2164
diff
changeset
|
122 } |
ccd4ffa41a1b
Use XDG configuration directory if a config file exists
Mikael Berthe <mikael@lilotux.net>
parents:
2164
diff
changeset
|
123 |
ccd4ffa41a1b
Use XDG configuration directory if a config file exists
Mikael Berthe <mikael@lilotux.net>
parents:
2164
diff
changeset
|
124 sfilename = g_string_new(""); |
ccd4ffa41a1b
Use XDG configuration directory if a config file exists
Mikael Berthe <mikael@lilotux.net>
parents:
2164
diff
changeset
|
125 |
ccd4ffa41a1b
Use XDG configuration directory if a config file exists
Mikael Berthe <mikael@lilotux.net>
parents:
2164
diff
changeset
|
126 // First try: $HOME/.mcabber/mcabberrc |
ccd4ffa41a1b
Use XDG configuration directory if a config file exists
Mikael Berthe <mikael@lilotux.net>
parents:
2164
diff
changeset
|
127 g_string_printf(sfilename, "%s/.mcabber/mcabberrc", home_dir); |
ccd4ffa41a1b
Use XDG configuration directory if a config file exists
Mikael Berthe <mikael@lilotux.net>
parents:
2164
diff
changeset
|
128 if ((fp = fopen(sfilename->str, "r")) != NULL) { |
ccd4ffa41a1b
Use XDG configuration directory if a config file exists
Mikael Berthe <mikael@lilotux.net>
parents:
2164
diff
changeset
|
129 fclose(fp); |
ccd4ffa41a1b
Use XDG configuration directory if a config file exists
Mikael Berthe <mikael@lilotux.net>
parents:
2164
diff
changeset
|
130 config_dir = g_strdup_printf("%s/.mcabber", home_dir); |
ccd4ffa41a1b
Use XDG configuration directory if a config file exists
Mikael Berthe <mikael@lilotux.net>
parents:
2164
diff
changeset
|
131 } |
ccd4ffa41a1b
Use XDG configuration directory if a config file exists
Mikael Berthe <mikael@lilotux.net>
parents:
2164
diff
changeset
|
132 |
ccd4ffa41a1b
Use XDG configuration directory if a config file exists
Mikael Berthe <mikael@lilotux.net>
parents:
2164
diff
changeset
|
133 // Second guess: Try to use the XDG standard configuration directory |
ccd4ffa41a1b
Use XDG configuration directory if a config file exists
Mikael Berthe <mikael@lilotux.net>
parents:
2164
diff
changeset
|
134 if (!config_dir) { |
ccd4ffa41a1b
Use XDG configuration directory if a config file exists
Mikael Berthe <mikael@lilotux.net>
parents:
2164
diff
changeset
|
135 char *xdg_config_dir = g_strdup(getenv("XDG_CONFIG_HOME")); |
ccd4ffa41a1b
Use XDG configuration directory if a config file exists
Mikael Berthe <mikael@lilotux.net>
parents:
2164
diff
changeset
|
136 if (!xdg_config_dir || !*xdg_config_dir) { |
ccd4ffa41a1b
Use XDG configuration directory if a config file exists
Mikael Berthe <mikael@lilotux.net>
parents:
2164
diff
changeset
|
137 // Free the string if it is non-null but empty |
ccd4ffa41a1b
Use XDG configuration directory if a config file exists
Mikael Berthe <mikael@lilotux.net>
parents:
2164
diff
changeset
|
138 if (xdg_config_dir) g_free(xdg_config_dir); |
ccd4ffa41a1b
Use XDG configuration directory if a config file exists
Mikael Berthe <mikael@lilotux.net>
parents:
2164
diff
changeset
|
139 xdg_config_dir = g_strdup_printf("%s/.config", home_dir); |
ccd4ffa41a1b
Use XDG configuration directory if a config file exists
Mikael Berthe <mikael@lilotux.net>
parents:
2164
diff
changeset
|
140 } |
ccd4ffa41a1b
Use XDG configuration directory if a config file exists
Mikael Berthe <mikael@lilotux.net>
parents:
2164
diff
changeset
|
141 |
ccd4ffa41a1b
Use XDG configuration directory if a config file exists
Mikael Berthe <mikael@lilotux.net>
parents:
2164
diff
changeset
|
142 if (xdg_config_dir) { |
ccd4ffa41a1b
Use XDG configuration directory if a config file exists
Mikael Berthe <mikael@lilotux.net>
parents:
2164
diff
changeset
|
143 int fd = -1; |
ccd4ffa41a1b
Use XDG configuration directory if a config file exists
Mikael Berthe <mikael@lilotux.net>
parents:
2164
diff
changeset
|
144 struct stat statbuf; |
ccd4ffa41a1b
Use XDG configuration directory if a config file exists
Mikael Berthe <mikael@lilotux.net>
parents:
2164
diff
changeset
|
145 |
ccd4ffa41a1b
Use XDG configuration directory if a config file exists
Mikael Berthe <mikael@lilotux.net>
parents:
2164
diff
changeset
|
146 if (*xdg_config_dir) |
ccd4ffa41a1b
Use XDG configuration directory if a config file exists
Mikael Berthe <mikael@lilotux.net>
parents:
2164
diff
changeset
|
147 fd = stat(xdg_config_dir, &statbuf); |
ccd4ffa41a1b
Use XDG configuration directory if a config file exists
Mikael Berthe <mikael@lilotux.net>
parents:
2164
diff
changeset
|
148 |
ccd4ffa41a1b
Use XDG configuration directory if a config file exists
Mikael Berthe <mikael@lilotux.net>
parents:
2164
diff
changeset
|
149 // If the XDG configuration directory exists, see if we can find a |
ccd4ffa41a1b
Use XDG configuration directory if a config file exists
Mikael Berthe <mikael@lilotux.net>
parents:
2164
diff
changeset
|
150 // configuration file for mcabber inside. |
ccd4ffa41a1b
Use XDG configuration directory if a config file exists
Mikael Berthe <mikael@lilotux.net>
parents:
2164
diff
changeset
|
151 if (fd != -1) { |
ccd4ffa41a1b
Use XDG configuration directory if a config file exists
Mikael Berthe <mikael@lilotux.net>
parents:
2164
diff
changeset
|
152 char *xdg_mcabber_dir = g_strdup_printf("%s/mcabber", xdg_config_dir); |
ccd4ffa41a1b
Use XDG configuration directory if a config file exists
Mikael Berthe <mikael@lilotux.net>
parents:
2164
diff
changeset
|
153 g_string_printf(sfilename, "%s/mcabberrc", xdg_mcabber_dir); |
ccd4ffa41a1b
Use XDG configuration directory if a config file exists
Mikael Berthe <mikael@lilotux.net>
parents:
2164
diff
changeset
|
154 if ((fp = fopen(sfilename->str, "r")) != NULL) { |
ccd4ffa41a1b
Use XDG configuration directory if a config file exists
Mikael Berthe <mikael@lilotux.net>
parents:
2164
diff
changeset
|
155 fclose(fp); |
ccd4ffa41a1b
Use XDG configuration directory if a config file exists
Mikael Berthe <mikael@lilotux.net>
parents:
2164
diff
changeset
|
156 config_dir = xdg_mcabber_dir; |
ccd4ffa41a1b
Use XDG configuration directory if a config file exists
Mikael Berthe <mikael@lilotux.net>
parents:
2164
diff
changeset
|
157 } else { |
ccd4ffa41a1b
Use XDG configuration directory if a config file exists
Mikael Berthe <mikael@lilotux.net>
parents:
2164
diff
changeset
|
158 g_free(xdg_mcabber_dir); |
ccd4ffa41a1b
Use XDG configuration directory if a config file exists
Mikael Berthe <mikael@lilotux.net>
parents:
2164
diff
changeset
|
159 } |
ccd4ffa41a1b
Use XDG configuration directory if a config file exists
Mikael Berthe <mikael@lilotux.net>
parents:
2164
diff
changeset
|
160 } |
ccd4ffa41a1b
Use XDG configuration directory if a config file exists
Mikael Berthe <mikael@lilotux.net>
parents:
2164
diff
changeset
|
161 g_free(xdg_config_dir); |
ccd4ffa41a1b
Use XDG configuration directory if a config file exists
Mikael Berthe <mikael@lilotux.net>
parents:
2164
diff
changeset
|
162 } |
ccd4ffa41a1b
Use XDG configuration directory if a config file exists
Mikael Berthe <mikael@lilotux.net>
parents:
2164
diff
changeset
|
163 } |
ccd4ffa41a1b
Use XDG configuration directory if a config file exists
Mikael Berthe <mikael@lilotux.net>
parents:
2164
diff
changeset
|
164 |
2253
5a107c907e71
Read $HOME/.mcabberrc if there is no mcabber configuration directory
Mikael Berthe <mikael@lilotux.net>
parents:
2204
diff
changeset
|
165 if (!config_dir) |
5a107c907e71
Read $HOME/.mcabberrc if there is no mcabber configuration directory
Mikael Berthe <mikael@lilotux.net>
parents:
2204
diff
changeset
|
166 scr_log_print(LPRINT_NORMAL, "Cannot find configuration directory!\n"); |
2204
ccd4ffa41a1b
Use XDG configuration directory if a config file exists
Mikael Berthe <mikael@lilotux.net>
parents:
2164
diff
changeset
|
167 |
ccd4ffa41a1b
Use XDG configuration directory if a config file exists
Mikael Berthe <mikael@lilotux.net>
parents:
2164
diff
changeset
|
168 g_string_free(sfilename, TRUE); |
ccd4ffa41a1b
Use XDG configuration directory if a config file exists
Mikael Berthe <mikael@lilotux.net>
parents:
2164
diff
changeset
|
169 return config_dir; |
ccd4ffa41a1b
Use XDG configuration directory if a config file exists
Mikael Berthe <mikael@lilotux.net>
parents:
2164
diff
changeset
|
170 } |
ccd4ffa41a1b
Use XDG configuration directory if a config file exists
Mikael Berthe <mikael@lilotux.net>
parents:
2164
diff
changeset
|
171 |
1192 | 172 // cfg_read_file(filename, mainfile) |
341
dea407d53fe6
Improve configuration file reading
Mikael Berthe <mikael@lilotux.net>
parents:
337
diff
changeset
|
173 // Read and parse config file "filename". If filename is NULL, |
dea407d53fe6
Improve configuration file reading
Mikael Berthe <mikael@lilotux.net>
parents:
337
diff
changeset
|
174 // try to open the configuration file at the default locations. |
1192 | 175 // mainfile must be set to TRUE for the startup config file. |
176 // If mainfile is TRUE, the permissions of the configuration file will | |
177 // be fixed if they're insecure. | |
341
dea407d53fe6
Improve configuration file reading
Mikael Berthe <mikael@lilotux.net>
parents:
337
diff
changeset
|
178 // |
1192 | 179 int cfg_read_file(char *filename, guint mainfile) |
341
dea407d53fe6
Improve configuration file reading
Mikael Berthe <mikael@lilotux.net>
parents:
337
diff
changeset
|
180 { |
1358 | 181 static unsigned int runtime; |
341
dea407d53fe6
Improve configuration file reading
Mikael Berthe <mikael@lilotux.net>
parents:
337
diff
changeset
|
182 FILE *fp; |
dea407d53fe6
Improve configuration file reading
Mikael Berthe <mikael@lilotux.net>
parents:
337
diff
changeset
|
183 char *buf; |
dea407d53fe6
Improve configuration file reading
Mikael Berthe <mikael@lilotux.net>
parents:
337
diff
changeset
|
184 char *line, *eol; |
dea407d53fe6
Improve configuration file reading
Mikael Berthe <mikael@lilotux.net>
parents:
337
diff
changeset
|
185 unsigned int ln = 0; |
dea407d53fe6
Improve configuration file reading
Mikael Berthe <mikael@lilotux.net>
parents:
337
diff
changeset
|
186 int err = 0; |
dea407d53fe6
Improve configuration file reading
Mikael Berthe <mikael@lilotux.net>
parents:
337
diff
changeset
|
187 |
dea407d53fe6
Improve configuration file reading
Mikael Berthe <mikael@lilotux.net>
parents:
337
diff
changeset
|
188 if (!filename) { |
2204
ccd4ffa41a1b
Use XDG configuration directory if a config file exists
Mikael Berthe <mikael@lilotux.net>
parents:
2164
diff
changeset
|
189 const gchar *mcabber_conf_dir; |
ccd4ffa41a1b
Use XDG configuration directory if a config file exists
Mikael Berthe <mikael@lilotux.net>
parents:
2164
diff
changeset
|
190 gchar *def_filename; |
1192 | 191 |
192 if (!mainfile) { | |
193 scr_LogPrint(LPRINT_LOGNORM, "No file name provided"); | |
194 return -1; | |
195 } | |
196 | |
2204
ccd4ffa41a1b
Use XDG configuration directory if a config file exists
Mikael Berthe <mikael@lilotux.net>
parents:
2164
diff
changeset
|
197 mcabber_conf_dir = settings_get_mcabber_config_dir(); |
2253
5a107c907e71
Read $HOME/.mcabberrc if there is no mcabber configuration directory
Mikael Berthe <mikael@lilotux.net>
parents:
2204
diff
changeset
|
198 if (!mcabber_conf_dir) { |
5a107c907e71
Read $HOME/.mcabberrc if there is no mcabber configuration directory
Mikael Berthe <mikael@lilotux.net>
parents:
2204
diff
changeset
|
199 // Try home directory |
5a107c907e71
Read $HOME/.mcabberrc if there is no mcabber configuration directory
Mikael Berthe <mikael@lilotux.net>
parents:
2204
diff
changeset
|
200 const char *home_dir = getenv("HOME"); |
5a107c907e71
Read $HOME/.mcabberrc if there is no mcabber configuration directory
Mikael Berthe <mikael@lilotux.net>
parents:
2204
diff
changeset
|
201 if (!home_dir) { |
5a107c907e71
Read $HOME/.mcabberrc if there is no mcabber configuration directory
Mikael Berthe <mikael@lilotux.net>
parents:
2204
diff
changeset
|
202 scr_log_print(LPRINT_NORMAL, "Cannot find any configuration file!\n"); |
5a107c907e71
Read $HOME/.mcabberrc if there is no mcabber configuration directory
Mikael Berthe <mikael@lilotux.net>
parents:
2204
diff
changeset
|
203 err = -1; |
5a107c907e71
Read $HOME/.mcabberrc if there is no mcabber configuration directory
Mikael Berthe <mikael@lilotux.net>
parents:
2204
diff
changeset
|
204 goto cfg_read_file_return; |
5a107c907e71
Read $HOME/.mcabberrc if there is no mcabber configuration directory
Mikael Berthe <mikael@lilotux.net>
parents:
2204
diff
changeset
|
205 } |
5a107c907e71
Read $HOME/.mcabberrc if there is no mcabber configuration directory
Mikael Berthe <mikael@lilotux.net>
parents:
2204
diff
changeset
|
206 def_filename = g_strdup_printf("%s/.mcabberrc", home_dir); |
5a107c907e71
Read $HOME/.mcabberrc if there is no mcabber configuration directory
Mikael Berthe <mikael@lilotux.net>
parents:
2204
diff
changeset
|
207 } else { |
5a107c907e71
Read $HOME/.mcabberrc if there is no mcabber configuration directory
Mikael Berthe <mikael@lilotux.net>
parents:
2204
diff
changeset
|
208 def_filename = g_strdup_printf("%s/mcabberrc", mcabber_conf_dir); |
5a107c907e71
Read $HOME/.mcabberrc if there is no mcabber configuration directory
Mikael Berthe <mikael@lilotux.net>
parents:
2204
diff
changeset
|
209 } |
2204
ccd4ffa41a1b
Use XDG configuration directory if a config file exists
Mikael Berthe <mikael@lilotux.net>
parents:
2164
diff
changeset
|
210 |
ccd4ffa41a1b
Use XDG configuration directory if a config file exists
Mikael Berthe <mikael@lilotux.net>
parents:
2164
diff
changeset
|
211 if ((fp = fopen(def_filename, "r")) == NULL) { |
ccd4ffa41a1b
Use XDG configuration directory if a config file exists
Mikael Berthe <mikael@lilotux.net>
parents:
2164
diff
changeset
|
212 fprintf(stderr, "Cannot open config file!\n"); |
ccd4ffa41a1b
Use XDG configuration directory if a config file exists
Mikael Berthe <mikael@lilotux.net>
parents:
2164
diff
changeset
|
213 g_free(def_filename); |
1358 | 214 err = -1; |
215 goto cfg_read_file_return; | |
341
dea407d53fe6
Improve configuration file reading
Mikael Berthe <mikael@lilotux.net>
parents:
337
diff
changeset
|
216 } |
362
d8f147d6e872
Check directory and config file permissions
Mikael Berthe <mikael@lilotux.net>
parents:
341
diff
changeset
|
217 // Check configuration file permissions |
1358 | 218 // As it could contain sensitive data, we make it user-readable only. |
2204
ccd4ffa41a1b
Use XDG configuration directory if a config file exists
Mikael Berthe <mikael@lilotux.net>
parents:
2164
diff
changeset
|
219 checkset_perm(def_filename, TRUE); |
ccd4ffa41a1b
Use XDG configuration directory if a config file exists
Mikael Berthe <mikael@lilotux.net>
parents:
2164
diff
changeset
|
220 scr_log_print(LPRINT_LOGNORM, "Reading %s", def_filename); |
2253
5a107c907e71
Read $HOME/.mcabberrc if there is no mcabber configuration directory
Mikael Berthe <mikael@lilotux.net>
parents:
2204
diff
changeset
|
221 |
5a107c907e71
Read $HOME/.mcabberrc if there is no mcabber configuration directory
Mikael Berthe <mikael@lilotux.net>
parents:
2204
diff
changeset
|
222 // Check mcabber directory permissions. |
5a107c907e71
Read $HOME/.mcabberrc if there is no mcabber configuration directory
Mikael Berthe <mikael@lilotux.net>
parents:
2204
diff
changeset
|
223 // Here we just warn, we don't change the mode. |
5a107c907e71
Read $HOME/.mcabberrc if there is no mcabber configuration directory
Mikael Berthe <mikael@lilotux.net>
parents:
2204
diff
changeset
|
224 if (mcabber_conf_dir) |
5a107c907e71
Read $HOME/.mcabberrc if there is no mcabber configuration directory
Mikael Berthe <mikael@lilotux.net>
parents:
2204
diff
changeset
|
225 checkset_perm(mcabber_conf_dir, FALSE); |
5a107c907e71
Read $HOME/.mcabberrc if there is no mcabber configuration directory
Mikael Berthe <mikael@lilotux.net>
parents:
2204
diff
changeset
|
226 |
2204
ccd4ffa41a1b
Use XDG configuration directory if a config file exists
Mikael Berthe <mikael@lilotux.net>
parents:
2164
diff
changeset
|
227 g_free(def_filename); |
362
d8f147d6e872
Check directory and config file permissions
Mikael Berthe <mikael@lilotux.net>
parents:
341
diff
changeset
|
228 } else { |
1383 | 229 // filename was specified |
362
d8f147d6e872
Check directory and config file permissions
Mikael Berthe <mikael@lilotux.net>
parents:
341
diff
changeset
|
230 if ((fp = fopen(filename, "r")) == NULL) { |
1192 | 231 const char *msg = "Cannot open configuration file"; |
232 if (mainfile) | |
233 perror(msg); | |
234 else | |
235 scr_LogPrint(LPRINT_LOGNORM, "%s (%s).", msg, filename); | |
1358 | 236 err = -2; |
237 goto cfg_read_file_return; | |
362
d8f147d6e872
Check directory and config file permissions
Mikael Berthe <mikael@lilotux.net>
parents:
341
diff
changeset
|
238 } |
d8f147d6e872
Check directory and config file permissions
Mikael Berthe <mikael@lilotux.net>
parents:
341
diff
changeset
|
239 // Check configuration file permissions (see above) |
1192 | 240 // 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
|
241 if (mainfile) |
9f5c5f176953
Do not check file permissions when using /source
Mikael Berthe <mikael@lilotux.net>
parents:
1205
diff
changeset
|
242 checkset_perm(filename, TRUE); |
1192 | 243 scr_LogPrint(LPRINT_LOGNORM, "Reading %s", filename); |
341
dea407d53fe6
Improve configuration file reading
Mikael Berthe <mikael@lilotux.net>
parents:
337
diff
changeset
|
244 } |
dea407d53fe6
Improve configuration file reading
Mikael Berthe <mikael@lilotux.net>
parents:
337
diff
changeset
|
245 |
1278
c3107650d165
Allow longer lines in config file
Mikael Berthe <mikael@lilotux.net>
parents:
1272
diff
changeset
|
246 buf = g_new(char, CONFLINE_LENGTH+1); |
341
dea407d53fe6
Improve configuration file reading
Mikael Berthe <mikael@lilotux.net>
parents:
337
diff
changeset
|
247 |
1278
c3107650d165
Allow longer lines in config file
Mikael Berthe <mikael@lilotux.net>
parents:
1272
diff
changeset
|
248 while (fgets(buf+1, CONFLINE_LENGTH, fp) != NULL) { |
341
dea407d53fe6
Improve configuration file reading
Mikael Berthe <mikael@lilotux.net>
parents:
337
diff
changeset
|
249 // 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
|
250 line = buf+1; |
dea407d53fe6
Improve configuration file reading
Mikael Berthe <mikael@lilotux.net>
parents:
337
diff
changeset
|
251 ln++; |
dea407d53fe6
Improve configuration file reading
Mikael Berthe <mikael@lilotux.net>
parents:
337
diff
changeset
|
252 |
dea407d53fe6
Improve configuration file reading
Mikael Berthe <mikael@lilotux.net>
parents:
337
diff
changeset
|
253 // Strip leading spaces |
dea407d53fe6
Improve configuration file reading
Mikael Berthe <mikael@lilotux.net>
parents:
337
diff
changeset
|
254 while (isspace(*line)) |
dea407d53fe6
Improve configuration file reading
Mikael Berthe <mikael@lilotux.net>
parents:
337
diff
changeset
|
255 line++; |
dea407d53fe6
Improve configuration file reading
Mikael Berthe <mikael@lilotux.net>
parents:
337
diff
changeset
|
256 |
dea407d53fe6
Improve configuration file reading
Mikael Berthe <mikael@lilotux.net>
parents:
337
diff
changeset
|
257 // Make eol point to the last char of the line |
dea407d53fe6
Improve configuration file reading
Mikael Berthe <mikael@lilotux.net>
parents:
337
diff
changeset
|
258 for (eol = line ; *eol ; eol++) |
dea407d53fe6
Improve configuration file reading
Mikael Berthe <mikael@lilotux.net>
parents:
337
diff
changeset
|
259 ; |
dea407d53fe6
Improve configuration file reading
Mikael Berthe <mikael@lilotux.net>
parents:
337
diff
changeset
|
260 if (eol > line) |
dea407d53fe6
Improve configuration file reading
Mikael Berthe <mikael@lilotux.net>
parents:
337
diff
changeset
|
261 eol--; |
dea407d53fe6
Improve configuration file reading
Mikael Berthe <mikael@lilotux.net>
parents:
337
diff
changeset
|
262 |
dea407d53fe6
Improve configuration file reading
Mikael Berthe <mikael@lilotux.net>
parents:
337
diff
changeset
|
263 // Strip trailing spaces |
dea407d53fe6
Improve configuration file reading
Mikael Berthe <mikael@lilotux.net>
parents:
337
diff
changeset
|
264 while (eol > line && isspace(*eol)) |
dea407d53fe6
Improve configuration file reading
Mikael Berthe <mikael@lilotux.net>
parents:
337
diff
changeset
|
265 *eol-- = 0; |
dea407d53fe6
Improve configuration file reading
Mikael Berthe <mikael@lilotux.net>
parents:
337
diff
changeset
|
266 |
dea407d53fe6
Improve configuration file reading
Mikael Berthe <mikael@lilotux.net>
parents:
337
diff
changeset
|
267 // Ignore empty lines and comments |
dea407d53fe6
Improve configuration file reading
Mikael Berthe <mikael@lilotux.net>
parents:
337
diff
changeset
|
268 if ((*line == '\n') || (*line == '\0') || (*line == '#')) |
dea407d53fe6
Improve configuration file reading
Mikael Berthe <mikael@lilotux.net>
parents:
337
diff
changeset
|
269 continue; |
dea407d53fe6
Improve configuration file reading
Mikael Berthe <mikael@lilotux.net>
parents:
337
diff
changeset
|
270 |
1988
dd65a18dc480
Add cmd_set_safe() / cmd_is_safe() (Myhailo Danylenko)
Mikael Berthe <mikael@lilotux.net>
parents:
1811
diff
changeset
|
271 // If we aren't in runtime (i.e. startup) we'll only accept "safe" commands |
dd65a18dc480
Add cmd_set_safe() / cmd_is_safe() (Myhailo Danylenko)
Mikael Berthe <mikael@lilotux.net>
parents:
1811
diff
changeset
|
272 if (!runtime) { |
dd65a18dc480
Add cmd_set_safe() / cmd_is_safe() (Myhailo Danylenko)
Mikael Berthe <mikael@lilotux.net>
parents:
1811
diff
changeset
|
273 const gchar *cmdend = strchr(line, ' '); |
dd65a18dc480
Add cmd_set_safe() / cmd_is_safe() (Myhailo Danylenko)
Mikael Berthe <mikael@lilotux.net>
parents:
1811
diff
changeset
|
274 gchar *cmdname = NULL; |
dd65a18dc480
Add cmd_set_safe() / cmd_is_safe() (Myhailo Danylenko)
Mikael Berthe <mikael@lilotux.net>
parents:
1811
diff
changeset
|
275 gboolean safe; |
dd65a18dc480
Add cmd_set_safe() / cmd_is_safe() (Myhailo Danylenko)
Mikael Berthe <mikael@lilotux.net>
parents:
1811
diff
changeset
|
276 if (cmdend) |
dd65a18dc480
Add cmd_set_safe() / cmd_is_safe() (Myhailo Danylenko)
Mikael Berthe <mikael@lilotux.net>
parents:
1811
diff
changeset
|
277 cmdname = g_strndup(line, cmdend - line); |
dd65a18dc480
Add cmd_set_safe() / cmd_is_safe() (Myhailo Danylenko)
Mikael Berthe <mikael@lilotux.net>
parents:
1811
diff
changeset
|
278 safe = cmd_is_safe(cmdname ? cmdname : line); |
dd65a18dc480
Add cmd_set_safe() / cmd_is_safe() (Myhailo Danylenko)
Mikael Berthe <mikael@lilotux.net>
parents:
1811
diff
changeset
|
279 g_free(cmdname); |
dd65a18dc480
Add cmd_set_safe() / cmd_is_safe() (Myhailo Danylenko)
Mikael Berthe <mikael@lilotux.net>
parents:
1811
diff
changeset
|
280 if (!safe) { |
dd65a18dc480
Add cmd_set_safe() / cmd_is_safe() (Myhailo Danylenko)
Mikael Berthe <mikael@lilotux.net>
parents:
1811
diff
changeset
|
281 scr_log_print(LPRINT_LOGNORM, "Error in configuration file (l. %d): " |
dd65a18dc480
Add cmd_set_safe() / cmd_is_safe() (Myhailo Danylenko)
Mikael Berthe <mikael@lilotux.net>
parents:
1811
diff
changeset
|
282 "this command can't be used here", ln); |
341
dea407d53fe6
Improve configuration file reading
Mikael Berthe <mikael@lilotux.net>
parents:
337
diff
changeset
|
283 err++; |
dea407d53fe6
Improve configuration file reading
Mikael Berthe <mikael@lilotux.net>
parents:
337
diff
changeset
|
284 continue; |
dea407d53fe6
Improve configuration file reading
Mikael Berthe <mikael@lilotux.net>
parents:
337
diff
changeset
|
285 } |
dea407d53fe6
Improve configuration file reading
Mikael Berthe <mikael@lilotux.net>
parents:
337
diff
changeset
|
286 } |
1988
dd65a18dc480
Add cmd_set_safe() / cmd_is_safe() (Myhailo Danylenko)
Mikael Berthe <mikael@lilotux.net>
parents:
1811
diff
changeset
|
287 |
dd65a18dc480
Add cmd_set_safe() / cmd_is_safe() (Myhailo Danylenko)
Mikael Berthe <mikael@lilotux.net>
parents:
1811
diff
changeset
|
288 // Set the leading COMMAND_CHAR to build a command line |
dd65a18dc480
Add cmd_set_safe() / cmd_is_safe() (Myhailo Danylenko)
Mikael Berthe <mikael@lilotux.net>
parents:
1811
diff
changeset
|
289 // and process the command |
dd65a18dc480
Add cmd_set_safe() / cmd_is_safe() (Myhailo Danylenko)
Mikael Berthe <mikael@lilotux.net>
parents:
1811
diff
changeset
|
290 *(--line) = COMMAND_CHAR; |
2164 | 291 process_command(line, TRUE); |
341
dea407d53fe6
Improve configuration file reading
Mikael Berthe <mikael@lilotux.net>
parents:
337
diff
changeset
|
292 } |
dea407d53fe6
Improve configuration file reading
Mikael Berthe <mikael@lilotux.net>
parents:
337
diff
changeset
|
293 g_free(buf); |
dea407d53fe6
Improve configuration file reading
Mikael Berthe <mikael@lilotux.net>
parents:
337
diff
changeset
|
294 fclose(fp); |
1192 | 295 |
296 if (filename) | |
297 scr_LogPrint(LPRINT_LOGNORM, "Loaded %s.", filename); | |
1358 | 298 |
299 cfg_read_file_return: | |
300 // If we're done with the main file parsing, we can assume that | |
301 // the next time this function is called will be at run time. | |
302 if (mainfile) | |
303 runtime = TRUE; | |
341
dea407d53fe6
Improve configuration file reading
Mikael Berthe <mikael@lilotux.net>
parents:
337
diff
changeset
|
304 return err; |
dea407d53fe6
Improve configuration file reading
Mikael Berthe <mikael@lilotux.net>
parents:
337
diff
changeset
|
305 } |
dea407d53fe6
Improve configuration file reading
Mikael Berthe <mikael@lilotux.net>
parents:
337
diff
changeset
|
306 |
280
68ce34b4243b
Add parse_assigment() function
Mikael Berthe <mikael@lilotux.net>
parents:
279
diff
changeset
|
307 // parse_assigment(assignment, pkey, pval) |
68ce34b4243b
Add parse_assigment() function
Mikael Berthe <mikael@lilotux.net>
parents:
279
diff
changeset
|
308 // Read assignment and split it to key, value |
68ce34b4243b
Add parse_assigment() function
Mikael Berthe <mikael@lilotux.net>
parents:
279
diff
changeset
|
309 // |
68ce34b4243b
Add parse_assigment() function
Mikael Berthe <mikael@lilotux.net>
parents:
279
diff
changeset
|
310 // 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
|
311 // 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
|
312 // |
68ce34b4243b
Add parse_assigment() function
Mikael Berthe <mikael@lilotux.net>
parents:
279
diff
changeset
|
313 // 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
|
314 // to NULL and return FALSE. |
68ce34b4243b
Add parse_assigment() function
Mikael Berthe <mikael@lilotux.net>
parents:
279
diff
changeset
|
315 // |
774
46304b773a44
Remove useless checks before g_free() calls
Mikael Berthe <mikael@lilotux.net>
parents:
764
diff
changeset
|
316 // 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
|
317 guint parse_assigment(gchar *assignment, gchar **pkey, gchar **pval) |
280
68ce34b4243b
Add parse_assigment() function
Mikael Berthe <mikael@lilotux.net>
parents:
279
diff
changeset
|
318 { |
293
d0295e735768
Assignment lvalue (key, option name, alias...) cannnot contain spaces
Mikael Berthe <mikael@lilotux.net>
parents:
288
diff
changeset
|
319 char *key, *val, *t, *p; |
280
68ce34b4243b
Add parse_assigment() function
Mikael Berthe <mikael@lilotux.net>
parents:
279
diff
changeset
|
320 |
68ce34b4243b
Add parse_assigment() function
Mikael Berthe <mikael@lilotux.net>
parents:
279
diff
changeset
|
321 *pkey = *pval = NULL; |
68ce34b4243b
Add parse_assigment() function
Mikael Berthe <mikael@lilotux.net>
parents:
279
diff
changeset
|
322 |
68ce34b4243b
Add parse_assigment() function
Mikael Berthe <mikael@lilotux.net>
parents:
279
diff
changeset
|
323 key = assignment; |
68ce34b4243b
Add parse_assigment() function
Mikael Berthe <mikael@lilotux.net>
parents:
279
diff
changeset
|
324 // Remove leading spaces in option name |
68ce34b4243b
Add parse_assigment() function
Mikael Berthe <mikael@lilotux.net>
parents:
279
diff
changeset
|
325 while ((!isalnum(*key)) && (*key != '=') && *key) { |
68ce34b4243b
Add parse_assigment() function
Mikael Berthe <mikael@lilotux.net>
parents:
279
diff
changeset
|
326 key++; |
68ce34b4243b
Add parse_assigment() function
Mikael Berthe <mikael@lilotux.net>
parents:
279
diff
changeset
|
327 } |
68ce34b4243b
Add parse_assigment() function
Mikael Berthe <mikael@lilotux.net>
parents:
279
diff
changeset
|
328 if (!*key) return FALSE; // Empty assignment |
68ce34b4243b
Add parse_assigment() function
Mikael Berthe <mikael@lilotux.net>
parents:
279
diff
changeset
|
329 |
68ce34b4243b
Add parse_assigment() function
Mikael Berthe <mikael@lilotux.net>
parents:
279
diff
changeset
|
330 if (*key == '=') { |
68ce34b4243b
Add parse_assigment() function
Mikael Berthe <mikael@lilotux.net>
parents:
279
diff
changeset
|
331 return FALSE; |
68ce34b4243b
Add parse_assigment() function
Mikael Berthe <mikael@lilotux.net>
parents:
279
diff
changeset
|
332 } |
68ce34b4243b
Add parse_assigment() function
Mikael Berthe <mikael@lilotux.net>
parents:
279
diff
changeset
|
333 // Ok, key points to the option name |
68ce34b4243b
Add parse_assigment() function
Mikael Berthe <mikael@lilotux.net>
parents:
279
diff
changeset
|
334 |
68ce34b4243b
Add parse_assigment() function
Mikael Berthe <mikael@lilotux.net>
parents:
279
diff
changeset
|
335 for (val = key+1 ; *val && (*val != '=') ; val++) |
68ce34b4243b
Add parse_assigment() function
Mikael Berthe <mikael@lilotux.net>
parents:
279
diff
changeset
|
336 if (!isalnum(*val) && !isblank(*val) && (*val != '_') && (*val != '-')) { |
68ce34b4243b
Add parse_assigment() function
Mikael Berthe <mikael@lilotux.net>
parents:
279
diff
changeset
|
337 // Key should only have alnum chars... |
68ce34b4243b
Add parse_assigment() function
Mikael Berthe <mikael@lilotux.net>
parents:
279
diff
changeset
|
338 return FALSE; |
68ce34b4243b
Add parse_assigment() function
Mikael Berthe <mikael@lilotux.net>
parents:
279
diff
changeset
|
339 } |
68ce34b4243b
Add parse_assigment() function
Mikael Berthe <mikael@lilotux.net>
parents:
279
diff
changeset
|
340 // Remove trailing spaces in option name: |
68ce34b4243b
Add parse_assigment() function
Mikael Berthe <mikael@lilotux.net>
parents:
279
diff
changeset
|
341 for (t = val-1 ; t > key && isblank(*t) ; t--) |
68ce34b4243b
Add parse_assigment() function
Mikael Berthe <mikael@lilotux.net>
parents:
279
diff
changeset
|
342 ; |
293
d0295e735768
Assignment lvalue (key, option name, alias...) cannnot contain spaces
Mikael Berthe <mikael@lilotux.net>
parents:
288
diff
changeset
|
343 // Check for embedded whitespace characters |
d0295e735768
Assignment lvalue (key, option name, alias...) cannnot contain spaces
Mikael Berthe <mikael@lilotux.net>
parents:
288
diff
changeset
|
344 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
|
345 if (isblank(*p)) { |
1729
e6e89b1d7831
Minor style and header updates
Mikael Berthe <mikael@lilotux.net>
parents:
1673
diff
changeset
|
346 // Name should not contain space chars... |
293
d0295e735768
Assignment lvalue (key, option name, alias...) cannnot contain spaces
Mikael Berthe <mikael@lilotux.net>
parents:
288
diff
changeset
|
347 return FALSE; |
d0295e735768
Assignment lvalue (key, option name, alias...) cannnot contain spaces
Mikael Berthe <mikael@lilotux.net>
parents:
288
diff
changeset
|
348 } |
d0295e735768
Assignment lvalue (key, option name, alias...) cannnot contain spaces
Mikael Berthe <mikael@lilotux.net>
parents:
288
diff
changeset
|
349 } |
d0295e735768
Assignment lvalue (key, option name, alias...) cannnot contain spaces
Mikael Berthe <mikael@lilotux.net>
parents:
288
diff
changeset
|
350 |
280
68ce34b4243b
Add parse_assigment() function
Mikael Berthe <mikael@lilotux.net>
parents:
279
diff
changeset
|
351 *pkey = g_strndup(key, t+1-key); |
68ce34b4243b
Add parse_assigment() function
Mikael Berthe <mikael@lilotux.net>
parents:
279
diff
changeset
|
352 |
68ce34b4243b
Add parse_assigment() function
Mikael Berthe <mikael@lilotux.net>
parents:
279
diff
changeset
|
353 if (!*val) return FALSE; // Not an assignment |
68ce34b4243b
Add parse_assigment() function
Mikael Berthe <mikael@lilotux.net>
parents:
279
diff
changeset
|
354 |
68ce34b4243b
Add parse_assigment() function
Mikael Berthe <mikael@lilotux.net>
parents:
279
diff
changeset
|
355 // Remove leading and trailing spaces in option value: |
68ce34b4243b
Add parse_assigment() function
Mikael Berthe <mikael@lilotux.net>
parents:
279
diff
changeset
|
356 for (val++; *val && isblank(*val) ; val++) ; |
68ce34b4243b
Add parse_assigment() function
Mikael Berthe <mikael@lilotux.net>
parents:
279
diff
changeset
|
357 for (t = val ; *t ; t++) ; |
68ce34b4243b
Add parse_assigment() function
Mikael Berthe <mikael@lilotux.net>
parents:
279
diff
changeset
|
358 for (t-- ; t >= val && isblank(*t) ; t--) ; |
68ce34b4243b
Add parse_assigment() function
Mikael Berthe <mikael@lilotux.net>
parents:
279
diff
changeset
|
359 |
282
87d6ac21cd1b
Fix "Cannot unset option" bug
Mikael Berthe <mikael@lilotux.net>
parents:
281
diff
changeset
|
360 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
|
361 |
337
3a25be278864
Values can be enclosed by quotes in assignments
Mikael Berthe <mikael@lilotux.net>
parents:
336
diff
changeset
|
362 // 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
|
363 // removed and whitespace is not stripped |
3a25be278864
Values can be enclosed by quotes in assignments
Mikael Berthe <mikael@lilotux.net>
parents:
336
diff
changeset
|
364 if ((t>val) && (*val == '"' && *t == '"')) { |
3a25be278864
Values can be enclosed by quotes in assignments
Mikael Berthe <mikael@lilotux.net>
parents:
336
diff
changeset
|
365 val++; |
3a25be278864
Values can be enclosed by quotes in assignments
Mikael Berthe <mikael@lilotux.net>
parents:
336
diff
changeset
|
366 t--; |
3a25be278864
Values can be enclosed by quotes in assignments
Mikael Berthe <mikael@lilotux.net>
parents:
336
diff
changeset
|
367 } |
280
68ce34b4243b
Add parse_assigment() function
Mikael Berthe <mikael@lilotux.net>
parents:
279
diff
changeset
|
368 *pval = g_strndup(val, t+1-val); |
68ce34b4243b
Add parse_assigment() function
Mikael Berthe <mikael@lilotux.net>
parents:
279
diff
changeset
|
369 return TRUE; |
68ce34b4243b
Add parse_assigment() function
Mikael Berthe <mikael@lilotux.net>
parents:
279
diff
changeset
|
370 } |
68ce34b4243b
Add parse_assigment() function
Mikael Berthe <mikael@lilotux.net>
parents:
279
diff
changeset
|
371 |
1768
d80a9e32ab1a
Refuse to replace existing guards
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1736
diff
changeset
|
372 gboolean settings_set_guard(const gchar *key, settings_guard_t guard) |
1673 | 373 { |
374 if (!guard) | |
375 g_hash_table_remove(guards, key); | |
1768
d80a9e32ab1a
Refuse to replace existing guards
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1736
diff
changeset
|
376 else { |
d80a9e32ab1a
Refuse to replace existing guards
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1736
diff
changeset
|
377 installed_guard_t *iguard = g_hash_table_lookup(guards, key); |
d80a9e32ab1a
Refuse to replace existing guards
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1736
diff
changeset
|
378 if (iguard) |
d80a9e32ab1a
Refuse to replace existing guards
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1736
diff
changeset
|
379 return FALSE; |
d80a9e32ab1a
Refuse to replace existing guards
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1736
diff
changeset
|
380 iguard = g_new(installed_guard_t, 1); |
d80a9e32ab1a
Refuse to replace existing guards
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1736
diff
changeset
|
381 iguard->guard = guard; |
d80a9e32ab1a
Refuse to replace existing guards
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1736
diff
changeset
|
382 g_hash_table_insert(guards, g_strdup(key), iguard); |
d80a9e32ab1a
Refuse to replace existing guards
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1736
diff
changeset
|
383 } |
d80a9e32ab1a
Refuse to replace existing guards
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1736
diff
changeset
|
384 return TRUE; |
1673 | 385 } |
386 | |
387 void settings_del_guard(const gchar *key) | |
388 { | |
389 settings_set_guard(key, NULL); | |
390 } | |
391 | |
392 void settings_opt_set_raw(const gchar *key, const gchar *value) | |
393 { | |
394 if (!value) | |
395 g_hash_table_remove(option, key); | |
396 else | |
397 g_hash_table_insert(option, g_strdup(key), g_strdup(value)); | |
398 } | |
399 | |
281
f562b9af2de7
Add "const" specifier in prototypes
Mikael Berthe <mikael@lilotux.net>
parents:
280
diff
changeset
|
400 void settings_set(guint type, const gchar *key, const gchar *value) |
279 | 401 { |
1070
9eaacc0ad3a2
Use a hash for settings
Mikael Berthe <mikael@lilotux.net>
parents:
1068
diff
changeset
|
402 GHashTable *hash; |
1673 | 403 gchar *dup_value = NULL; |
1794
58d1390f28ca
Fix ignore of NULL guard retval (introduced in d80a9e32ab1a)
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1768
diff
changeset
|
404 installed_guard_t *guard = NULL; |
1673 | 405 |
406 if (type == SETTINGS_TYPE_OPTION) { | |
1794
58d1390f28ca
Fix ignore of NULL guard retval (introduced in d80a9e32ab1a)
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1768
diff
changeset
|
407 guard = g_hash_table_lookup(guards, key); |
1673 | 408 if (guard) |
1768
d80a9e32ab1a
Refuse to replace existing guards
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1736
diff
changeset
|
409 dup_value = guard->guard(key, value); |
1673 | 410 } |
279 | 411 |
1070
9eaacc0ad3a2
Use a hash for settings
Mikael Berthe <mikael@lilotux.net>
parents:
1068
diff
changeset
|
412 hash = get_hash(type); |
9eaacc0ad3a2
Use a hash for settings
Mikael Berthe <mikael@lilotux.net>
parents:
1068
diff
changeset
|
413 if (!hash) |
9eaacc0ad3a2
Use a hash for settings
Mikael Berthe <mikael@lilotux.net>
parents:
1068
diff
changeset
|
414 return; |
9eaacc0ad3a2
Use a hash for settings
Mikael Berthe <mikael@lilotux.net>
parents:
1068
diff
changeset
|
415 |
1673 | 416 if (!value && !dup_value) |
1070
9eaacc0ad3a2
Use a hash for settings
Mikael Berthe <mikael@lilotux.net>
parents:
1068
diff
changeset
|
417 g_hash_table_remove(hash, key); |
1673 | 418 else if (!guard) |
1070
9eaacc0ad3a2
Use a hash for settings
Mikael Berthe <mikael@lilotux.net>
parents:
1068
diff
changeset
|
419 g_hash_table_insert(hash, g_strdup(key), g_strdup(value)); |
1673 | 420 else if (dup_value) |
421 g_hash_table_insert(hash, g_strdup(key), dup_value); | |
422 else | |
423 g_hash_table_remove(option, key); | |
279 | 424 } |
425 | |
281
f562b9af2de7
Add "const" specifier in prototypes
Mikael Berthe <mikael@lilotux.net>
parents:
280
diff
changeset
|
426 void settings_del(guint type, const gchar *key) |
279 | 427 { |
428 settings_set(type, key, NULL); | |
429 } | |
430 | |
281
f562b9af2de7
Add "const" specifier in prototypes
Mikael Berthe <mikael@lilotux.net>
parents:
280
diff
changeset
|
431 const gchar *settings_get(guint type, const gchar *key) |
279 | 432 { |
1070
9eaacc0ad3a2
Use a hash for settings
Mikael Berthe <mikael@lilotux.net>
parents:
1068
diff
changeset
|
433 GHashTable *hash; |
279 | 434 |
1070
9eaacc0ad3a2
Use a hash for settings
Mikael Berthe <mikael@lilotux.net>
parents:
1068
diff
changeset
|
435 hash = get_hash(type); |
9eaacc0ad3a2
Use a hash for settings
Mikael Berthe <mikael@lilotux.net>
parents:
1068
diff
changeset
|
436 if (!hash) |
9eaacc0ad3a2
Use a hash for settings
Mikael Berthe <mikael@lilotux.net>
parents:
1068
diff
changeset
|
437 return NULL; |
279 | 438 |
1070
9eaacc0ad3a2
Use a hash for settings
Mikael Berthe <mikael@lilotux.net>
parents:
1068
diff
changeset
|
439 return g_hash_table_lookup(hash, key); |
279 | 440 } |
441 | |
281
f562b9af2de7
Add "const" specifier in prototypes
Mikael Berthe <mikael@lilotux.net>
parents:
280
diff
changeset
|
442 int settings_get_int(guint type, const gchar *key) |
279 | 443 { |
281
f562b9af2de7
Add "const" specifier in prototypes
Mikael Berthe <mikael@lilotux.net>
parents:
280
diff
changeset
|
444 const gchar *setval = settings_get(type, key); |
279 | 445 |
446 if (setval) return atoi(setval); | |
447 return 0; | |
448 } | |
449 | |
294
871e53769084
Allow one status message per Jabber status
Mikael Berthe <mikael@lilotux.net>
parents:
293
diff
changeset
|
450 // settings_get_status_msg(status) |
871e53769084
Allow one status message per Jabber status
Mikael Berthe <mikael@lilotux.net>
parents:
293
diff
changeset
|
451 // 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
|
452 // - 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
|
453 // return this message |
871e53769084
Allow one status message per Jabber status
Mikael Berthe <mikael@lilotux.net>
parents:
293
diff
changeset
|
454 // - 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
|
455 // generic user message), it is returned |
521 | 456 // - 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
|
457 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
|
458 { |
871e53769084
Allow one status message per Jabber status
Mikael Berthe <mikael@lilotux.net>
parents:
293
diff
changeset
|
459 const gchar *rstatus = settings_opt_get("message"); |
871e53769084
Allow one status message per Jabber status
Mikael Berthe <mikael@lilotux.net>
parents:
293
diff
changeset
|
460 |
871e53769084
Allow one status message per Jabber status
Mikael Berthe <mikael@lilotux.net>
parents:
293
diff
changeset
|
461 if (rstatus) return rstatus; |
871e53769084
Allow one status message per Jabber status
Mikael Berthe <mikael@lilotux.net>
parents:
293
diff
changeset
|
462 |
871e53769084
Allow one status message per Jabber status
Mikael Berthe <mikael@lilotux.net>
parents:
293
diff
changeset
|
463 switch(status) { |
871e53769084
Allow one status message per Jabber status
Mikael Berthe <mikael@lilotux.net>
parents:
293
diff
changeset
|
464 case available: |
521 | 465 rstatus = settings_opt_get("message_avail"); |
294
871e53769084
Allow one status message per Jabber status
Mikael Berthe <mikael@lilotux.net>
parents:
293
diff
changeset
|
466 break; |
871e53769084
Allow one status message per Jabber status
Mikael Berthe <mikael@lilotux.net>
parents:
293
diff
changeset
|
467 |
871e53769084
Allow one status message per Jabber status
Mikael Berthe <mikael@lilotux.net>
parents:
293
diff
changeset
|
468 case freeforchat: |
521 | 469 rstatus = settings_opt_get("message_free"); |
294
871e53769084
Allow one status message per Jabber status
Mikael Berthe <mikael@lilotux.net>
parents:
293
diff
changeset
|
470 break; |
871e53769084
Allow one status message per Jabber status
Mikael Berthe <mikael@lilotux.net>
parents:
293
diff
changeset
|
471 |
871e53769084
Allow one status message per Jabber status
Mikael Berthe <mikael@lilotux.net>
parents:
293
diff
changeset
|
472 case dontdisturb: |
521 | 473 rstatus = settings_opt_get("message_dnd"); |
294
871e53769084
Allow one status message per Jabber status
Mikael Berthe <mikael@lilotux.net>
parents:
293
diff
changeset
|
474 break; |
871e53769084
Allow one status message per Jabber status
Mikael Berthe <mikael@lilotux.net>
parents:
293
diff
changeset
|
475 |
871e53769084
Allow one status message per Jabber status
Mikael Berthe <mikael@lilotux.net>
parents:
293
diff
changeset
|
476 case notavail: |
521 | 477 rstatus = settings_opt_get("message_notavail"); |
294
871e53769084
Allow one status message per Jabber status
Mikael Berthe <mikael@lilotux.net>
parents:
293
diff
changeset
|
478 break; |
871e53769084
Allow one status message per Jabber status
Mikael Berthe <mikael@lilotux.net>
parents:
293
diff
changeset
|
479 |
871e53769084
Allow one status message per Jabber status
Mikael Berthe <mikael@lilotux.net>
parents:
293
diff
changeset
|
480 case away: |
521 | 481 rstatus = settings_opt_get("message_away"); |
294
871e53769084
Allow one status message per Jabber status
Mikael Berthe <mikael@lilotux.net>
parents:
293
diff
changeset
|
482 break; |
871e53769084
Allow one status message per Jabber status
Mikael Berthe <mikael@lilotux.net>
parents:
293
diff
changeset
|
483 |
521 | 484 default: // offline, invisible |
485 break; | |
294
871e53769084
Allow one status message per Jabber status
Mikael Berthe <mikael@lilotux.net>
parents:
293
diff
changeset
|
486 } |
871e53769084
Allow one status message per Jabber status
Mikael Berthe <mikael@lilotux.net>
parents:
293
diff
changeset
|
487 return rstatus; |
871e53769084
Allow one status message per Jabber status
Mikael Berthe <mikael@lilotux.net>
parents:
293
diff
changeset
|
488 } |
576 | 489 |
867
7f056c566569
Commands /alias & /bind list the key bindings and aliases
Mikael Berthe <mikael@lilotux.net>
parents:
780
diff
changeset
|
490 // settings_foreach(type, pfunction, param) |
1661
64a7428afcb3
Print list of options with '/set'
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1653
diff
changeset
|
491 // Call pfunction(key, value, param) for each setting with requested type. |
1070
9eaacc0ad3a2
Use a hash for settings
Mikael Berthe <mikael@lilotux.net>
parents:
1068
diff
changeset
|
492 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
|
493 void *param) |
7f056c566569
Commands /alias & /bind list the key bindings and aliases
Mikael Berthe <mikael@lilotux.net>
parents:
780
diff
changeset
|
494 { |
1070
9eaacc0ad3a2
Use a hash for settings
Mikael Berthe <mikael@lilotux.net>
parents:
1068
diff
changeset
|
495 GHashTable *hash; |
867
7f056c566569
Commands /alias & /bind list the key bindings and aliases
Mikael Berthe <mikael@lilotux.net>
parents:
780
diff
changeset
|
496 |
1070
9eaacc0ad3a2
Use a hash for settings
Mikael Berthe <mikael@lilotux.net>
parents:
1068
diff
changeset
|
497 hash = get_hash(type); |
9eaacc0ad3a2
Use a hash for settings
Mikael Berthe <mikael@lilotux.net>
parents:
1068
diff
changeset
|
498 if (!hash) |
9eaacc0ad3a2
Use a hash for settings
Mikael Berthe <mikael@lilotux.net>
parents:
1068
diff
changeset
|
499 return; |
867
7f056c566569
Commands /alias & /bind list the key bindings and aliases
Mikael Berthe <mikael@lilotux.net>
parents:
780
diff
changeset
|
500 |
1070
9eaacc0ad3a2
Use a hash for settings
Mikael Berthe <mikael@lilotux.net>
parents:
1068
diff
changeset
|
501 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
|
502 } |
7f056c566569
Commands /alias & /bind list the key bindings and aliases
Mikael Berthe <mikael@lilotux.net>
parents:
780
diff
changeset
|
503 |
1004
b57a01ffeed6
Use existing conference bookmarks
Mikael Berthe <mikael@lilotux.net>
parents:
967
diff
changeset
|
504 |
b57a01ffeed6
Use existing conference bookmarks
Mikael Berthe <mikael@lilotux.net>
parents:
967
diff
changeset
|
505 // default_muc_nickname() |
b57a01ffeed6
Use existing conference bookmarks
Mikael Berthe <mikael@lilotux.net>
parents:
967
diff
changeset
|
506 // Return the user's default nickname |
b57a01ffeed6
Use existing conference bookmarks
Mikael Berthe <mikael@lilotux.net>
parents:
967
diff
changeset
|
507 // 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
|
508 char *default_muc_nickname(const char *roomid) |
1004
b57a01ffeed6
Use existing conference bookmarks
Mikael Berthe <mikael@lilotux.net>
parents:
967
diff
changeset
|
509 { |
b57a01ffeed6
Use existing conference bookmarks
Mikael Berthe <mikael@lilotux.net>
parents:
967
diff
changeset
|
510 char *nick; |
b57a01ffeed6
Use existing conference bookmarks
Mikael Berthe <mikael@lilotux.net>
parents:
967
diff
changeset
|
511 |
1598 | 512 nick = (char*)xmpp_get_bookmark_nick(roomid); |
1395
d431cd75eb53
Use bookmarked nickname when manually joining a room
Mikael Berthe <mikael@lilotux.net>
parents:
1383
diff
changeset
|
513 if (nick) |
d431cd75eb53
Use bookmarked nickname when manually joining a room
Mikael Berthe <mikael@lilotux.net>
parents:
1383
diff
changeset
|
514 return g_strdup(nick); |
d431cd75eb53
Use bookmarked nickname when manually joining a room
Mikael Berthe <mikael@lilotux.net>
parents:
1383
diff
changeset
|
515 |
1004
b57a01ffeed6
Use existing conference bookmarks
Mikael Berthe <mikael@lilotux.net>
parents:
967
diff
changeset
|
516 // 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
|
517 nick = (char*)settings_opt_get("nickname"); |
b57a01ffeed6
Use existing conference bookmarks
Mikael Berthe <mikael@lilotux.net>
parents:
967
diff
changeset
|
518 if (nick) |
b57a01ffeed6
Use existing conference bookmarks
Mikael Berthe <mikael@lilotux.net>
parents:
967
diff
changeset
|
519 return g_strdup(nick); |
b57a01ffeed6
Use existing conference bookmarks
Mikael Berthe <mikael@lilotux.net>
parents:
967
diff
changeset
|
520 |
1611
f9bf561e54d0
Use the username for authentication, added jid_get_username() to utils.c
franky
parents:
1607
diff
changeset
|
521 nick = jid_get_username(settings_opt_get("jid")); |
1004
b57a01ffeed6
Use existing conference bookmarks
Mikael Berthe <mikael@lilotux.net>
parents:
967
diff
changeset
|
522 return nick; |
b57a01ffeed6
Use existing conference bookmarks
Mikael Berthe <mikael@lilotux.net>
parents:
967
diff
changeset
|
523 } |
b57a01ffeed6
Use existing conference bookmarks
Mikael Berthe <mikael@lilotux.net>
parents:
967
diff
changeset
|
524 |
1065
230dca34dbea
Extand pgp_data structure
Mikael Berthe <mikael@lilotux.net>
parents:
1004
diff
changeset
|
525 |
230dca34dbea
Extand pgp_data structure
Mikael Berthe <mikael@lilotux.net>
parents:
1004
diff
changeset
|
526 /* PGP settings */ |
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 // settings_pgp_setdisabled(jid, value) |
230dca34dbea
Extand pgp_data structure
Mikael Berthe <mikael@lilotux.net>
parents:
1004
diff
changeset
|
529 // Enable/disable PGP encryption for jid. |
230dca34dbea
Extand pgp_data structure
Mikael Berthe <mikael@lilotux.net>
parents:
1004
diff
changeset
|
530 // (Set value to TRUE to disable encryption) |
230dca34dbea
Extand pgp_data structure
Mikael Berthe <mikael@lilotux.net>
parents:
1004
diff
changeset
|
531 void settings_pgp_setdisabled(const char *bjid, guint value) |
230dca34dbea
Extand pgp_data structure
Mikael Berthe <mikael@lilotux.net>
parents:
1004
diff
changeset
|
532 { |
230dca34dbea
Extand pgp_data structure
Mikael Berthe <mikael@lilotux.net>
parents:
1004
diff
changeset
|
533 #ifdef HAVE_GPGME |
2337 | 534 pgpopt_t *pgpdata; |
1065
230dca34dbea
Extand pgp_data structure
Mikael Berthe <mikael@lilotux.net>
parents:
1004
diff
changeset
|
535 pgpdata = g_hash_table_lookup(pgpopt, bjid); |
230dca34dbea
Extand pgp_data structure
Mikael Berthe <mikael@lilotux.net>
parents:
1004
diff
changeset
|
536 if (!pgpdata) { |
230dca34dbea
Extand pgp_data structure
Mikael Berthe <mikael@lilotux.net>
parents:
1004
diff
changeset
|
537 // 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
|
538 // the default value). |
230dca34dbea
Extand pgp_data structure
Mikael Berthe <mikael@lilotux.net>
parents:
1004
diff
changeset
|
539 if (value) { |
2337 | 540 pgpdata = g_new0(pgpopt_t, 1); |
1065
230dca34dbea
Extand pgp_data structure
Mikael Berthe <mikael@lilotux.net>
parents:
1004
diff
changeset
|
541 pgpdata->pgp_disabled = value; |
230dca34dbea
Extand pgp_data structure
Mikael Berthe <mikael@lilotux.net>
parents:
1004
diff
changeset
|
542 g_hash_table_insert(pgpopt, g_strdup(bjid), pgpdata); |
230dca34dbea
Extand pgp_data structure
Mikael Berthe <mikael@lilotux.net>
parents:
1004
diff
changeset
|
543 } |
230dca34dbea
Extand pgp_data structure
Mikael Berthe <mikael@lilotux.net>
parents:
1004
diff
changeset
|
544 } else { |
230dca34dbea
Extand pgp_data structure
Mikael Berthe <mikael@lilotux.net>
parents:
1004
diff
changeset
|
545 pgpdata->pgp_disabled = value; |
230dca34dbea
Extand pgp_data structure
Mikael Berthe <mikael@lilotux.net>
parents:
1004
diff
changeset
|
546 // 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
|
547 // pgp_keyid is NULL, actually. |
230dca34dbea
Extand pgp_data structure
Mikael Berthe <mikael@lilotux.net>
parents:
1004
diff
changeset
|
548 } |
230dca34dbea
Extand pgp_data structure
Mikael Berthe <mikael@lilotux.net>
parents:
1004
diff
changeset
|
549 #endif |
230dca34dbea
Extand pgp_data structure
Mikael Berthe <mikael@lilotux.net>
parents:
1004
diff
changeset
|
550 } |
230dca34dbea
Extand pgp_data structure
Mikael Berthe <mikael@lilotux.net>
parents:
1004
diff
changeset
|
551 |
230dca34dbea
Extand pgp_data structure
Mikael Berthe <mikael@lilotux.net>
parents:
1004
diff
changeset
|
552 // settings_pgp_getdisabled(jid) |
230dca34dbea
Extand pgp_data structure
Mikael Berthe <mikael@lilotux.net>
parents:
1004
diff
changeset
|
553 // Return TRUE if PGP encryption should be disabled for jid. |
230dca34dbea
Extand pgp_data structure
Mikael Berthe <mikael@lilotux.net>
parents:
1004
diff
changeset
|
554 guint settings_pgp_getdisabled(const char *bjid) |
230dca34dbea
Extand pgp_data structure
Mikael Berthe <mikael@lilotux.net>
parents:
1004
diff
changeset
|
555 { |
230dca34dbea
Extand pgp_data structure
Mikael Berthe <mikael@lilotux.net>
parents:
1004
diff
changeset
|
556 #ifdef HAVE_GPGME |
2337 | 557 pgpopt_t *pgpdata; |
1065
230dca34dbea
Extand pgp_data structure
Mikael Berthe <mikael@lilotux.net>
parents:
1004
diff
changeset
|
558 pgpdata = g_hash_table_lookup(pgpopt, bjid); |
230dca34dbea
Extand pgp_data structure
Mikael Berthe <mikael@lilotux.net>
parents:
1004
diff
changeset
|
559 if (pgpdata) |
230dca34dbea
Extand pgp_data structure
Mikael Berthe <mikael@lilotux.net>
parents:
1004
diff
changeset
|
560 return pgpdata->pgp_disabled; |
230dca34dbea
Extand pgp_data structure
Mikael Berthe <mikael@lilotux.net>
parents:
1004
diff
changeset
|
561 else |
1197 | 562 return FALSE; // Default: not disabled |
1065
230dca34dbea
Extand pgp_data structure
Mikael Berthe <mikael@lilotux.net>
parents:
1004
diff
changeset
|
563 #else |
230dca34dbea
Extand pgp_data structure
Mikael Berthe <mikael@lilotux.net>
parents:
1004
diff
changeset
|
564 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
|
565 #endif |
230dca34dbea
Extand pgp_data structure
Mikael Berthe <mikael@lilotux.net>
parents:
1004
diff
changeset
|
566 } |
230dca34dbea
Extand pgp_data structure
Mikael Berthe <mikael@lilotux.net>
parents:
1004
diff
changeset
|
567 |
1197 | 568 // settings_pgp_setforce(jid, value) |
569 // Force (or not) PGP encryption for jid. | |
570 // When value is TRUE, PGP support will be assumed for the remote client. | |
571 void settings_pgp_setforce(const char *bjid, guint value) | |
572 { | |
573 #ifdef HAVE_GPGME | |
2337 | 574 pgpopt_t *pgpdata; |
1197 | 575 pgpdata = g_hash_table_lookup(pgpopt, bjid); |
576 if (!pgpdata) { | |
577 // If value is 0, we do not need to create a structure (that's | |
578 // the default value). | |
579 if (value) { | |
2337 | 580 pgpdata = g_new0(pgpopt_t, 1); |
1197 | 581 pgpdata->pgp_force = value; |
582 g_hash_table_insert(pgpopt, g_strdup(bjid), pgpdata); | |
583 } | |
584 } else { | |
585 pgpdata->pgp_force = value; | |
586 } | |
1565
bff9633e38ee
Fix segfault in command /pgp (reported by Maxim Vuets)
Mikael Berthe <mikael@lilotux.net>
parents:
1519
diff
changeset
|
587 if (value && pgpdata && !pgpdata->pgp_keyid) |
1197 | 588 scr_LogPrint(LPRINT_NORMAL, "Warning: the Key Id is not set!"); |
589 #endif | |
590 } | |
591 | |
592 // settings_pgp_getforce(jid) | |
593 // Return TRUE if PGP enforcement is set for jid. | |
594 guint settings_pgp_getforce(const char *bjid) | |
595 { | |
596 #ifdef HAVE_GPGME | |
2337 | 597 pgpopt_t *pgpdata; |
1197 | 598 pgpdata = g_hash_table_lookup(pgpopt, bjid); |
599 if (pgpdata) | |
600 return pgpdata->pgp_force; | |
601 else | |
602 return FALSE; // Default | |
603 #else | |
604 return FALSE; // No PGP support | |
605 #endif | |
606 } | |
607 | |
1065
230dca34dbea
Extand pgp_data structure
Mikael Berthe <mikael@lilotux.net>
parents:
1004
diff
changeset
|
608 // settings_pgp_setkeyid(jid, keyid) |
230dca34dbea
Extand pgp_data structure
Mikael Berthe <mikael@lilotux.net>
parents:
1004
diff
changeset
|
609 // Set the PGP KeyId for user jid. |
230dca34dbea
Extand pgp_data structure
Mikael Berthe <mikael@lilotux.net>
parents:
1004
diff
changeset
|
610 // Use keyid = NULL to erase the previous KeyId. |
230dca34dbea
Extand pgp_data structure
Mikael Berthe <mikael@lilotux.net>
parents:
1004
diff
changeset
|
611 void settings_pgp_setkeyid(const char *bjid, const char *keyid) |
230dca34dbea
Extand pgp_data structure
Mikael Berthe <mikael@lilotux.net>
parents:
1004
diff
changeset
|
612 { |
230dca34dbea
Extand pgp_data structure
Mikael Berthe <mikael@lilotux.net>
parents:
1004
diff
changeset
|
613 #ifdef HAVE_GPGME |
2337 | 614 pgpopt_t *pgpdata; |
1065
230dca34dbea
Extand pgp_data structure
Mikael Berthe <mikael@lilotux.net>
parents:
1004
diff
changeset
|
615 pgpdata = g_hash_table_lookup(pgpopt, bjid); |
230dca34dbea
Extand pgp_data structure
Mikael Berthe <mikael@lilotux.net>
parents:
1004
diff
changeset
|
616 if (!pgpdata) { |
230dca34dbea
Extand pgp_data structure
Mikael Berthe <mikael@lilotux.net>
parents:
1004
diff
changeset
|
617 // 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
|
618 // the default value). |
230dca34dbea
Extand pgp_data structure
Mikael Berthe <mikael@lilotux.net>
parents:
1004
diff
changeset
|
619 if (keyid) { |
2337 | 620 pgpdata = g_new0(pgpopt_t, 1); |
1065
230dca34dbea
Extand pgp_data structure
Mikael Berthe <mikael@lilotux.net>
parents:
1004
diff
changeset
|
621 pgpdata->pgp_keyid = g_strdup(keyid); |
230dca34dbea
Extand pgp_data structure
Mikael Berthe <mikael@lilotux.net>
parents:
1004
diff
changeset
|
622 g_hash_table_insert(pgpopt, g_strdup(bjid), pgpdata); |
230dca34dbea
Extand pgp_data structure
Mikael Berthe <mikael@lilotux.net>
parents:
1004
diff
changeset
|
623 } |
230dca34dbea
Extand pgp_data structure
Mikael Berthe <mikael@lilotux.net>
parents:
1004
diff
changeset
|
624 } else { |
230dca34dbea
Extand pgp_data structure
Mikael Berthe <mikael@lilotux.net>
parents:
1004
diff
changeset
|
625 g_free(pgpdata->pgp_keyid); |
230dca34dbea
Extand pgp_data structure
Mikael Berthe <mikael@lilotux.net>
parents:
1004
diff
changeset
|
626 if (keyid) |
230dca34dbea
Extand pgp_data structure
Mikael Berthe <mikael@lilotux.net>
parents:
1004
diff
changeset
|
627 pgpdata->pgp_keyid = g_strdup(keyid); |
230dca34dbea
Extand pgp_data structure
Mikael Berthe <mikael@lilotux.net>
parents:
1004
diff
changeset
|
628 else |
230dca34dbea
Extand pgp_data structure
Mikael Berthe <mikael@lilotux.net>
parents:
1004
diff
changeset
|
629 pgpdata->pgp_keyid = NULL; |
230dca34dbea
Extand pgp_data structure
Mikael Berthe <mikael@lilotux.net>
parents:
1004
diff
changeset
|
630 // 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
|
631 // pgp_keyid is NULL, actually. |
230dca34dbea
Extand pgp_data structure
Mikael Berthe <mikael@lilotux.net>
parents:
1004
diff
changeset
|
632 } |
230dca34dbea
Extand pgp_data structure
Mikael Berthe <mikael@lilotux.net>
parents:
1004
diff
changeset
|
633 #endif |
230dca34dbea
Extand pgp_data structure
Mikael Berthe <mikael@lilotux.net>
parents:
1004
diff
changeset
|
634 } |
230dca34dbea
Extand pgp_data structure
Mikael Berthe <mikael@lilotux.net>
parents:
1004
diff
changeset
|
635 |
230dca34dbea
Extand pgp_data structure
Mikael Berthe <mikael@lilotux.net>
parents:
1004
diff
changeset
|
636 // settings_pgp_getkeyid(jid) |
230dca34dbea
Extand pgp_data structure
Mikael Berthe <mikael@lilotux.net>
parents:
1004
diff
changeset
|
637 // Get the PGP KeyId for user jid. |
230dca34dbea
Extand pgp_data structure
Mikael Berthe <mikael@lilotux.net>
parents:
1004
diff
changeset
|
638 const char *settings_pgp_getkeyid(const char *bjid) |
230dca34dbea
Extand pgp_data structure
Mikael Berthe <mikael@lilotux.net>
parents:
1004
diff
changeset
|
639 { |
230dca34dbea
Extand pgp_data structure
Mikael Berthe <mikael@lilotux.net>
parents:
1004
diff
changeset
|
640 #ifdef HAVE_GPGME |
2337 | 641 pgpopt_t *pgpdata; |
1065
230dca34dbea
Extand pgp_data structure
Mikael Berthe <mikael@lilotux.net>
parents:
1004
diff
changeset
|
642 pgpdata = g_hash_table_lookup(pgpopt, bjid); |
230dca34dbea
Extand pgp_data structure
Mikael Berthe <mikael@lilotux.net>
parents:
1004
diff
changeset
|
643 if (pgpdata) |
230dca34dbea
Extand pgp_data structure
Mikael Berthe <mikael@lilotux.net>
parents:
1004
diff
changeset
|
644 return pgpdata->pgp_keyid; |
230dca34dbea
Extand pgp_data structure
Mikael Berthe <mikael@lilotux.net>
parents:
1004
diff
changeset
|
645 #endif |
230dca34dbea
Extand pgp_data structure
Mikael Berthe <mikael@lilotux.net>
parents:
1004
diff
changeset
|
646 return NULL; |
230dca34dbea
Extand pgp_data structure
Mikael Berthe <mikael@lilotux.net>
parents:
1004
diff
changeset
|
647 } |
230dca34dbea
Extand pgp_data structure
Mikael Berthe <mikael@lilotux.net>
parents:
1004
diff
changeset
|
648 |
1299
3b338a5c01fc
OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
1278
diff
changeset
|
649 /* otr settings */ |
3b338a5c01fc
OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
1278
diff
changeset
|
650 |
3b338a5c01fc
OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
1278
diff
changeset
|
651 #ifdef HAVE_LIBOTR |
1598 | 652 static void remove_default_policies(char *k, char *policy, void *defaultp) |
1299
3b338a5c01fc
OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
1278
diff
changeset
|
653 { |
3b338a5c01fc
OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
1278
diff
changeset
|
654 if (*(enum otr_policy *)policy == *(enum otr_policy *)defaultp) { |
3b338a5c01fc
OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
1278
diff
changeset
|
655 g_free((enum otr_policy *) policy); |
3b338a5c01fc
OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
1278
diff
changeset
|
656 g_hash_table_remove(otrpolicy, k); |
3b338a5c01fc
OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
1278
diff
changeset
|
657 } |
3b338a5c01fc
OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
1278
diff
changeset
|
658 } |
3b338a5c01fc
OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
1278
diff
changeset
|
659 #endif |
3b338a5c01fc
OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
1278
diff
changeset
|
660 |
3b338a5c01fc
OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
1278
diff
changeset
|
661 void settings_otr_setpolicy(const char *bjid, guint value) |
3b338a5c01fc
OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
1278
diff
changeset
|
662 { |
3b338a5c01fc
OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
1278
diff
changeset
|
663 #ifdef HAVE_LIBOTR |
3b338a5c01fc
OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
1278
diff
changeset
|
664 enum otr_policy *otrdata; |
3b338a5c01fc
OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
1278
diff
changeset
|
665 |
3b338a5c01fc
OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
1278
diff
changeset
|
666 if (!bjid) { |
3b338a5c01fc
OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
1278
diff
changeset
|
667 default_policy = value; |
3b338a5c01fc
OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
1278
diff
changeset
|
668 /* refresh hash */ |
3b338a5c01fc
OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
1278
diff
changeset
|
669 settings_foreach(SETTINGS_TYPE_OTR, &remove_default_policies, &value); |
3b338a5c01fc
OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
1278
diff
changeset
|
670 return; |
3b338a5c01fc
OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
1278
diff
changeset
|
671 } |
3b338a5c01fc
OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
1278
diff
changeset
|
672 |
3b338a5c01fc
OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
1278
diff
changeset
|
673 otrdata = g_hash_table_lookup(otrpolicy, bjid); |
3b338a5c01fc
OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
1278
diff
changeset
|
674 |
3b338a5c01fc
OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
1278
diff
changeset
|
675 if (value == default_policy) { |
3b338a5c01fc
OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
1278
diff
changeset
|
676 if (otrdata) { |
3b338a5c01fc
OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
1278
diff
changeset
|
677 g_free(otrdata); |
3b338a5c01fc
OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
1278
diff
changeset
|
678 g_hash_table_remove(otrpolicy, bjid); |
3b338a5c01fc
OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
1278
diff
changeset
|
679 } |
3b338a5c01fc
OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
1278
diff
changeset
|
680 } else if (otrdata) { |
3b338a5c01fc
OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
1278
diff
changeset
|
681 *otrdata = value; |
3b338a5c01fc
OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
1278
diff
changeset
|
682 } else { |
3b338a5c01fc
OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
1278
diff
changeset
|
683 otrdata = g_new(enum otr_policy, 1); |
3b338a5c01fc
OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
1278
diff
changeset
|
684 *otrdata = value; |
3b338a5c01fc
OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
1278
diff
changeset
|
685 g_hash_table_insert(otrpolicy, g_strdup(bjid), otrdata); |
3b338a5c01fc
OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
1278
diff
changeset
|
686 } |
3b338a5c01fc
OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
1278
diff
changeset
|
687 #endif |
3b338a5c01fc
OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
1278
diff
changeset
|
688 } |
3b338a5c01fc
OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
1278
diff
changeset
|
689 |
3b338a5c01fc
OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
1278
diff
changeset
|
690 guint settings_otr_getpolicy(const char *bjid) |
3b338a5c01fc
OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
1278
diff
changeset
|
691 { |
3b338a5c01fc
OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
1278
diff
changeset
|
692 #ifdef HAVE_LIBOTR |
1598 | 693 enum otr_policy *otrdata; |
1299
3b338a5c01fc
OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
1278
diff
changeset
|
694 if (!bjid) |
3b338a5c01fc
OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
1278
diff
changeset
|
695 return default_policy; |
3b338a5c01fc
OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
1278
diff
changeset
|
696 |
3b338a5c01fc
OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
1278
diff
changeset
|
697 otrdata = g_hash_table_lookup(otrpolicy, bjid); |
3b338a5c01fc
OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
1278
diff
changeset
|
698 if (otrdata) |
3b338a5c01fc
OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
1278
diff
changeset
|
699 return *otrdata; |
3b338a5c01fc
OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
1278
diff
changeset
|
700 else |
3b338a5c01fc
OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
1278
diff
changeset
|
701 return default_policy; |
3b338a5c01fc
OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
1278
diff
changeset
|
702 #else |
3b338a5c01fc
OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
1278
diff
changeset
|
703 return 0; |
3b338a5c01fc
OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
1278
diff
changeset
|
704 #endif |
3b338a5c01fc
OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
1278
diff
changeset
|
705 } |
3b338a5c01fc
OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
1278
diff
changeset
|
706 |
1141
5be2408a6534
Add option "max_history_blocks"
Mikael Berthe <mikael@lilotux.net>
parents:
1074
diff
changeset
|
707 guint get_max_history_blocks(void) |
5be2408a6534
Add option "max_history_blocks"
Mikael Berthe <mikael@lilotux.net>
parents:
1074
diff
changeset
|
708 { |
5be2408a6534
Add option "max_history_blocks"
Mikael Berthe <mikael@lilotux.net>
parents:
1074
diff
changeset
|
709 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
|
710 if (max_num_of_blocks < 0) |
5be2408a6534
Add option "max_history_blocks"
Mikael Berthe <mikael@lilotux.net>
parents:
1074
diff
changeset
|
711 max_num_of_blocks = 0; |
5be2408a6534
Add option "max_history_blocks"
Mikael Berthe <mikael@lilotux.net>
parents:
1074
diff
changeset
|
712 else if (max_num_of_blocks == 1) |
5be2408a6534
Add option "max_history_blocks"
Mikael Berthe <mikael@lilotux.net>
parents:
1074
diff
changeset
|
713 max_num_of_blocks = 2; |
5be2408a6534
Add option "max_history_blocks"
Mikael Berthe <mikael@lilotux.net>
parents:
1074
diff
changeset
|
714 return (guint)max_num_of_blocks; |
5be2408a6534
Add option "max_history_blocks"
Mikael Berthe <mikael@lilotux.net>
parents:
1074
diff
changeset
|
715 } |
5be2408a6534
Add option "max_history_blocks"
Mikael Berthe <mikael@lilotux.net>
parents:
1074
diff
changeset
|
716 |
1811 | 717 /* vim: set et cindent cinoptions=>2\:2(0 ts=2 sw=2: For Vim users... */ |