author | Mikael Berthe <mikael@lilotux.net> |
Fri, 20 Apr 2007 17:14:38 +0200 | |
changeset 1187 | 16abe7ec3056 |
parent 1141 | 5be2408a6534 |
child 1192 | 7b8765c10abb |
permissions | -rw-r--r-- |
279 | 1 |
/* |
2 |
* settings.c -- Configuration stuff |
|
393 | 3 |
* |
699 | 4 |
* Copyright (C) 2005, 2006 Mikael Berthe <bmikael@lists.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" |
279 | 30 |
|
1070
9eaacc0ad3a2
Use a hash for settings
Mikael Berthe <mikael@lilotux.net>
parents:
1068
diff
changeset
|
31 |
static GHashTable *option; |
9eaacc0ad3a2
Use a hash for settings
Mikael Berthe <mikael@lilotux.net>
parents:
1068
diff
changeset
|
32 |
static GHashTable *alias; |
9eaacc0ad3a2
Use a hash for settings
Mikael Berthe <mikael@lilotux.net>
parents:
1068
diff
changeset
|
33 |
static GHashTable *binding; |
279 | 34 |
|
1065
230dca34dbea
Extand pgp_data structure
Mikael Berthe <mikael@lilotux.net>
parents:
1004
diff
changeset
|
35 |
#ifdef HAVE_GPGME /* PGP settings */ |
230dca34dbea
Extand pgp_data structure
Mikael Berthe <mikael@lilotux.net>
parents:
1004
diff
changeset
|
36 |
static GHashTable *pgpopt; |
230dca34dbea
Extand pgp_data structure
Mikael Berthe <mikael@lilotux.net>
parents:
1004
diff
changeset
|
37 |
|
230dca34dbea
Extand pgp_data structure
Mikael Berthe <mikael@lilotux.net>
parents:
1004
diff
changeset
|
38 |
typedef struct { |
230dca34dbea
Extand pgp_data structure
Mikael Berthe <mikael@lilotux.net>
parents:
1004
diff
changeset
|
39 |
gchar *pgp_keyid; /* KeyId the contact is supposed to use */ |
230dca34dbea
Extand pgp_data structure
Mikael Berthe <mikael@lilotux.net>
parents:
1004
diff
changeset
|
40 |
guint pgp_disabled; /* If TRUE, PGP is disabled for outgoing messages */ |
230dca34dbea
Extand pgp_data structure
Mikael Berthe <mikael@lilotux.net>
parents:
1004
diff
changeset
|
41 |
} T_pgpopt; |
230dca34dbea
Extand pgp_data structure
Mikael Berthe <mikael@lilotux.net>
parents:
1004
diff
changeset
|
42 |
#endif |
230dca34dbea
Extand pgp_data structure
Mikael Berthe <mikael@lilotux.net>
parents:
1004
diff
changeset
|
43 |
|
1070
9eaacc0ad3a2
Use a hash for settings
Mikael Berthe <mikael@lilotux.net>
parents:
1068
diff
changeset
|
44 |
static inline GHashTable *get_hash(guint type) |
279 | 45 |
{ |
1070
9eaacc0ad3a2
Use a hash for settings
Mikael Berthe <mikael@lilotux.net>
parents:
1068
diff
changeset
|
46 |
if (type == SETTINGS_TYPE_OPTION) return option; |
9eaacc0ad3a2
Use a hash for settings
Mikael Berthe <mikael@lilotux.net>
parents:
1068
diff
changeset
|
47 |
else if (type == SETTINGS_TYPE_ALIAS) return alias; |
9eaacc0ad3a2
Use a hash for settings
Mikael Berthe <mikael@lilotux.net>
parents:
1068
diff
changeset
|
48 |
else if (type == SETTINGS_TYPE_BINDING) return binding; |
279 | 49 |
return NULL; |
50 |
} |
|
51 |
||
52 |
/* -- */ |
|
53 |
||
1065
230dca34dbea
Extand pgp_data structure
Mikael Berthe <mikael@lilotux.net>
parents:
1004
diff
changeset
|
54 |
void settings_init(void) |
230dca34dbea
Extand pgp_data structure
Mikael Berthe <mikael@lilotux.net>
parents:
1004
diff
changeset
|
55 |
{ |
1070
9eaacc0ad3a2
Use a hash for settings
Mikael Berthe <mikael@lilotux.net>
parents:
1068
diff
changeset
|
56 |
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
|
57 |
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
|
58 |
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
|
59 |
#ifdef HAVE_GPGME |
230dca34dbea
Extand pgp_data structure
Mikael Berthe <mikael@lilotux.net>
parents:
1004
diff
changeset
|
60 |
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
|
61 |
#endif |
230dca34dbea
Extand pgp_data structure
Mikael Berthe <mikael@lilotux.net>
parents:
1004
diff
changeset
|
62 |
} |
230dca34dbea
Extand pgp_data structure
Mikael Berthe <mikael@lilotux.net>
parents:
1004
diff
changeset
|
63 |
|
341
dea407d53fe6
Improve configuration file reading
Mikael Berthe <mikael@lilotux.net>
parents:
337
diff
changeset
|
64 |
// cfg_read_file(filename) |
dea407d53fe6
Improve configuration file reading
Mikael Berthe <mikael@lilotux.net>
parents:
337
diff
changeset
|
65 |
// Read and parse config file "filename". If filename is NULL, |
dea407d53fe6
Improve configuration file reading
Mikael Berthe <mikael@lilotux.net>
parents:
337
diff
changeset
|
66 |
// try to open the configuration file at the default locations. |
dea407d53fe6
Improve configuration file reading
Mikael Berthe <mikael@lilotux.net>
parents:
337
diff
changeset
|
67 |
// |
dea407d53fe6
Improve configuration file reading
Mikael Berthe <mikael@lilotux.net>
parents:
337
diff
changeset
|
68 |
int cfg_read_file(char *filename) |
dea407d53fe6
Improve configuration file reading
Mikael Berthe <mikael@lilotux.net>
parents:
337
diff
changeset
|
69 |
{ |
dea407d53fe6
Improve configuration file reading
Mikael Berthe <mikael@lilotux.net>
parents:
337
diff
changeset
|
70 |
FILE *fp; |
dea407d53fe6
Improve configuration file reading
Mikael Berthe <mikael@lilotux.net>
parents:
337
diff
changeset
|
71 |
char *buf; |
dea407d53fe6
Improve configuration file reading
Mikael Berthe <mikael@lilotux.net>
parents:
337
diff
changeset
|
72 |
char *line, *eol; |
dea407d53fe6
Improve configuration file reading
Mikael Berthe <mikael@lilotux.net>
parents:
337
diff
changeset
|
73 |
unsigned int ln = 0; |
dea407d53fe6
Improve configuration file reading
Mikael Berthe <mikael@lilotux.net>
parents:
337
diff
changeset
|
74 |
int err = 0; |
dea407d53fe6
Improve configuration file reading
Mikael Berthe <mikael@lilotux.net>
parents:
337
diff
changeset
|
75 |
|
dea407d53fe6
Improve configuration file reading
Mikael Berthe <mikael@lilotux.net>
parents:
337
diff
changeset
|
76 |
if (!filename) { |
dea407d53fe6
Improve configuration file reading
Mikael Berthe <mikael@lilotux.net>
parents:
337
diff
changeset
|
77 |
// Use default config file locations |
dea407d53fe6
Improve configuration file reading
Mikael Berthe <mikael@lilotux.net>
parents:
337
diff
changeset
|
78 |
char *home = getenv("HOME"); |
dea407d53fe6
Improve configuration file reading
Mikael Berthe <mikael@lilotux.net>
parents:
337
diff
changeset
|
79 |
if (!home) { |
374
bd5638c21834
Improve logging system (traces)
Mikael Berthe <mikael@lilotux.net>
parents:
364
diff
changeset
|
80 |
scr_LogPrint(LPRINT_LOG, "Can't find home dir!"); |
341
dea407d53fe6
Improve configuration file reading
Mikael Berthe <mikael@lilotux.net>
parents:
337
diff
changeset
|
81 |
fprintf(stderr, "Can't find home dir!\n"); |
dea407d53fe6
Improve configuration file reading
Mikael Berthe <mikael@lilotux.net>
parents:
337
diff
changeset
|
82 |
return -1; |
dea407d53fe6
Improve configuration file reading
Mikael Berthe <mikael@lilotux.net>
parents:
337
diff
changeset
|
83 |
} |
dea407d53fe6
Improve configuration file reading
Mikael Berthe <mikael@lilotux.net>
parents:
337
diff
changeset
|
84 |
filename = g_new(char, strlen(home)+24); |
dea407d53fe6
Improve configuration file reading
Mikael Berthe <mikael@lilotux.net>
parents:
337
diff
changeset
|
85 |
sprintf(filename, "%s/.mcabber/mcabberrc", home); |
dea407d53fe6
Improve configuration file reading
Mikael Berthe <mikael@lilotux.net>
parents:
337
diff
changeset
|
86 |
if ((fp = fopen(filename, "r")) == NULL) { |
dea407d53fe6
Improve configuration file reading
Mikael Berthe <mikael@lilotux.net>
parents:
337
diff
changeset
|
87 |
// 2nd try... |
dea407d53fe6
Improve configuration file reading
Mikael Berthe <mikael@lilotux.net>
parents:
337
diff
changeset
|
88 |
sprintf(filename, "%s/.mcabberrc", home); |
dea407d53fe6
Improve configuration file reading
Mikael Berthe <mikael@lilotux.net>
parents:
337
diff
changeset
|
89 |
if ((fp = fopen(filename, "r")) == NULL) { |
dea407d53fe6
Improve configuration file reading
Mikael Berthe <mikael@lilotux.net>
parents:
337
diff
changeset
|
90 |
fprintf(stderr, "Cannot open config file!\n"); |
895 | 91 |
g_free(filename); |
341
dea407d53fe6
Improve configuration file reading
Mikael Berthe <mikael@lilotux.net>
parents:
337
diff
changeset
|
92 |
return -1; |
dea407d53fe6
Improve configuration file reading
Mikael Berthe <mikael@lilotux.net>
parents:
337
diff
changeset
|
93 |
} |
dea407d53fe6
Improve configuration file reading
Mikael Berthe <mikael@lilotux.net>
parents:
337
diff
changeset
|
94 |
} |
362
d8f147d6e872
Check directory and config file permissions
Mikael Berthe <mikael@lilotux.net>
parents:
341
diff
changeset
|
95 |
// Check configuration file permissions |
d8f147d6e872
Check directory and config file permissions
Mikael Berthe <mikael@lilotux.net>
parents:
341
diff
changeset
|
96 |
// As it could contain sensitive data, we make it user-readable only |
d8f147d6e872
Check directory and config file permissions
Mikael Berthe <mikael@lilotux.net>
parents:
341
diff
changeset
|
97 |
checkset_perm(filename, TRUE); |
d8f147d6e872
Check directory and config file permissions
Mikael Berthe <mikael@lilotux.net>
parents:
341
diff
changeset
|
98 |
// Check mcabber dir. There we just warn, we don't change the modes |
d8f147d6e872
Check directory and config file permissions
Mikael Berthe <mikael@lilotux.net>
parents:
341
diff
changeset
|
99 |
sprintf(filename, "%s/.mcabber/", home); |
d8f147d6e872
Check directory and config file permissions
Mikael Berthe <mikael@lilotux.net>
parents:
341
diff
changeset
|
100 |
checkset_perm(filename, FALSE); |
341
dea407d53fe6
Improve configuration file reading
Mikael Berthe <mikael@lilotux.net>
parents:
337
diff
changeset
|
101 |
g_free(filename); |
362
d8f147d6e872
Check directory and config file permissions
Mikael Berthe <mikael@lilotux.net>
parents:
341
diff
changeset
|
102 |
} else { |
d8f147d6e872
Check directory and config file permissions
Mikael Berthe <mikael@lilotux.net>
parents:
341
diff
changeset
|
103 |
if ((fp = fopen(filename, "r")) == NULL) { |
780
1dd19363c73e
cfg_read_file(): Clarify error message
Mikael Berthe <mikael@lilotux.net>
parents:
774
diff
changeset
|
104 |
perror("Cannot open configuration file"); |
872
a0ddc43b421e
Don't stop when there is no configuration file
Mikael Berthe <mikael@lilotux.net>
parents:
867
diff
changeset
|
105 |
return -2; |
362
d8f147d6e872
Check directory and config file permissions
Mikael Berthe <mikael@lilotux.net>
parents:
341
diff
changeset
|
106 |
} |
d8f147d6e872
Check directory and config file permissions
Mikael Berthe <mikael@lilotux.net>
parents:
341
diff
changeset
|
107 |
// Check configuration file permissions (see above) |
d8f147d6e872
Check directory and config file permissions
Mikael Berthe <mikael@lilotux.net>
parents:
341
diff
changeset
|
108 |
checkset_perm(filename, TRUE); |
341
dea407d53fe6
Improve configuration file reading
Mikael Berthe <mikael@lilotux.net>
parents:
337
diff
changeset
|
109 |
} |
dea407d53fe6
Improve configuration file reading
Mikael Berthe <mikael@lilotux.net>
parents:
337
diff
changeset
|
110 |
|
dea407d53fe6
Improve configuration file reading
Mikael Berthe <mikael@lilotux.net>
parents:
337
diff
changeset
|
111 |
buf = g_new(char, 512); |
dea407d53fe6
Improve configuration file reading
Mikael Berthe <mikael@lilotux.net>
parents:
337
diff
changeset
|
112 |
|
dea407d53fe6
Improve configuration file reading
Mikael Berthe <mikael@lilotux.net>
parents:
337
diff
changeset
|
113 |
while (fgets(buf+1, 511, fp) != NULL) { |
dea407d53fe6
Improve configuration file reading
Mikael Berthe <mikael@lilotux.net>
parents:
337
diff
changeset
|
114 |
// 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
|
115 |
line = buf+1; |
dea407d53fe6
Improve configuration file reading
Mikael Berthe <mikael@lilotux.net>
parents:
337
diff
changeset
|
116 |
ln++; |
dea407d53fe6
Improve configuration file reading
Mikael Berthe <mikael@lilotux.net>
parents:
337
diff
changeset
|
117 |
|
dea407d53fe6
Improve configuration file reading
Mikael Berthe <mikael@lilotux.net>
parents:
337
diff
changeset
|
118 |
// Strip leading spaces |
dea407d53fe6
Improve configuration file reading
Mikael Berthe <mikael@lilotux.net>
parents:
337
diff
changeset
|
119 |
while (isspace(*line)) |
dea407d53fe6
Improve configuration file reading
Mikael Berthe <mikael@lilotux.net>
parents:
337
diff
changeset
|
120 |
line++; |
dea407d53fe6
Improve configuration file reading
Mikael Berthe <mikael@lilotux.net>
parents:
337
diff
changeset
|
121 |
|
dea407d53fe6
Improve configuration file reading
Mikael Berthe <mikael@lilotux.net>
parents:
337
diff
changeset
|
122 |
// Make eol point to the last char of the line |
dea407d53fe6
Improve configuration file reading
Mikael Berthe <mikael@lilotux.net>
parents:
337
diff
changeset
|
123 |
for (eol = line ; *eol ; eol++) |
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 |
if (eol > line) |
dea407d53fe6
Improve configuration file reading
Mikael Berthe <mikael@lilotux.net>
parents:
337
diff
changeset
|
126 |
eol--; |
dea407d53fe6
Improve configuration file reading
Mikael Berthe <mikael@lilotux.net>
parents:
337
diff
changeset
|
127 |
|
dea407d53fe6
Improve configuration file reading
Mikael Berthe <mikael@lilotux.net>
parents:
337
diff
changeset
|
128 |
// Strip trailing spaces |
dea407d53fe6
Improve configuration file reading
Mikael Berthe <mikael@lilotux.net>
parents:
337
diff
changeset
|
129 |
while (eol > line && isspace(*eol)) |
dea407d53fe6
Improve configuration file reading
Mikael Berthe <mikael@lilotux.net>
parents:
337
diff
changeset
|
130 |
*eol-- = 0; |
dea407d53fe6
Improve configuration file reading
Mikael Berthe <mikael@lilotux.net>
parents:
337
diff
changeset
|
131 |
|
dea407d53fe6
Improve configuration file reading
Mikael Berthe <mikael@lilotux.net>
parents:
337
diff
changeset
|
132 |
// Ignore empty lines and comments |
dea407d53fe6
Improve configuration file reading
Mikael Berthe <mikael@lilotux.net>
parents:
337
diff
changeset
|
133 |
if ((*line == '\n') || (*line == '\0') || (*line == '#')) |
dea407d53fe6
Improve configuration file reading
Mikael Berthe <mikael@lilotux.net>
parents:
337
diff
changeset
|
134 |
continue; |
dea407d53fe6
Improve configuration file reading
Mikael Berthe <mikael@lilotux.net>
parents:
337
diff
changeset
|
135 |
|
1068
6646d2ed7f74
Allow pgp commands in config file, update sample configuration file
Mikael Berthe <mikael@lilotux.net>
parents:
1065
diff
changeset
|
136 |
if ((strchr(line, '=') != NULL) || !strncmp(line, "pgp ", strlen("pgp "))) { |
6646d2ed7f74
Allow pgp commands in config file, update sample configuration file
Mikael Berthe <mikael@lilotux.net>
parents:
1065
diff
changeset
|
137 |
// Only accept the set, alias, bind and pgp commands |
967 | 138 |
if (strncmp(line, "set ", strlen("set ")) && |
1068
6646d2ed7f74
Allow pgp commands in config file, update sample configuration file
Mikael Berthe <mikael@lilotux.net>
parents:
1065
diff
changeset
|
139 |
strncmp(line, "pgp ", strlen("pgp ")) && |
967 | 140 |
strncmp(line, "bind ", strlen("bind ")) && |
141 |
strncmp(line, "alias ", strlen("alias "))) { |
|
374
bd5638c21834
Improve logging system (traces)
Mikael Berthe <mikael@lilotux.net>
parents:
364
diff
changeset
|
142 |
scr_LogPrint(LPRINT_LOGNORM, |
bd5638c21834
Improve logging system (traces)
Mikael Berthe <mikael@lilotux.net>
parents:
364
diff
changeset
|
143 |
"Error in configuration file (l. %d): bad command", ln); |
341
dea407d53fe6
Improve configuration file reading
Mikael Berthe <mikael@lilotux.net>
parents:
337
diff
changeset
|
144 |
err++; |
dea407d53fe6
Improve configuration file reading
Mikael Berthe <mikael@lilotux.net>
parents:
337
diff
changeset
|
145 |
continue; |
dea407d53fe6
Improve configuration file reading
Mikael Berthe <mikael@lilotux.net>
parents:
337
diff
changeset
|
146 |
} |
967 | 147 |
// Set the leading COMMAND_CHAR to build a command line |
148 |
// and process the command |
|
149 |
*(--line) = COMMAND_CHAR; |
|
1187
16abe7ec3056
Fix a conflict between verbatim multiline mode and the key binding system
Mikael Berthe <mikael@lilotux.net>
parents:
1141
diff
changeset
|
150 |
process_command(line, TRUE); |
341
dea407d53fe6
Improve configuration file reading
Mikael Berthe <mikael@lilotux.net>
parents:
337
diff
changeset
|
151 |
} else { |
374
bd5638c21834
Improve logging system (traces)
Mikael Berthe <mikael@lilotux.net>
parents:
364
diff
changeset
|
152 |
scr_LogPrint(LPRINT_LOGNORM, |
bd5638c21834
Improve logging system (traces)
Mikael Berthe <mikael@lilotux.net>
parents:
364
diff
changeset
|
153 |
"Error in configuration file (l. %d): no assignment", ln); |
341
dea407d53fe6
Improve configuration file reading
Mikael Berthe <mikael@lilotux.net>
parents:
337
diff
changeset
|
154 |
err++; |
dea407d53fe6
Improve configuration file reading
Mikael Berthe <mikael@lilotux.net>
parents:
337
diff
changeset
|
155 |
} |
dea407d53fe6
Improve configuration file reading
Mikael Berthe <mikael@lilotux.net>
parents:
337
diff
changeset
|
156 |
} |
dea407d53fe6
Improve configuration file reading
Mikael Berthe <mikael@lilotux.net>
parents:
337
diff
changeset
|
157 |
g_free(buf); |
dea407d53fe6
Improve configuration file reading
Mikael Berthe <mikael@lilotux.net>
parents:
337
diff
changeset
|
158 |
fclose(fp); |
dea407d53fe6
Improve configuration file reading
Mikael Berthe <mikael@lilotux.net>
parents:
337
diff
changeset
|
159 |
return err; |
dea407d53fe6
Improve configuration file reading
Mikael Berthe <mikael@lilotux.net>
parents:
337
diff
changeset
|
160 |
} |
dea407d53fe6
Improve configuration file reading
Mikael Berthe <mikael@lilotux.net>
parents:
337
diff
changeset
|
161 |
|
280
68ce34b4243b
Add parse_assigment() function
Mikael Berthe <mikael@lilotux.net>
parents:
279
diff
changeset
|
162 |
// parse_assigment(assignment, pkey, pval) |
68ce34b4243b
Add parse_assigment() function
Mikael Berthe <mikael@lilotux.net>
parents:
279
diff
changeset
|
163 |
// Read assignment and split it to key, value |
68ce34b4243b
Add parse_assigment() function
Mikael Berthe <mikael@lilotux.net>
parents:
279
diff
changeset
|
164 |
// |
68ce34b4243b
Add parse_assigment() function
Mikael Berthe <mikael@lilotux.net>
parents:
279
diff
changeset
|
165 |
// 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
|
166 |
// 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
|
167 |
// |
68ce34b4243b
Add parse_assigment() function
Mikael Berthe <mikael@lilotux.net>
parents:
279
diff
changeset
|
168 |
// 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
|
169 |
// to NULL and return FALSE. |
68ce34b4243b
Add parse_assigment() function
Mikael Berthe <mikael@lilotux.net>
parents:
279
diff
changeset
|
170 |
// |
774
46304b773a44
Remove useless checks before g_free() calls
Mikael Berthe <mikael@lilotux.net>
parents:
764
diff
changeset
|
171 |
// 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
|
172 |
guint parse_assigment(gchar *assignment, gchar **pkey, gchar **pval) |
280
68ce34b4243b
Add parse_assigment() function
Mikael Berthe <mikael@lilotux.net>
parents:
279
diff
changeset
|
173 |
{ |
293
d0295e735768
Assignment lvalue (key, option name, alias...) cannnot contain spaces
Mikael Berthe <mikael@lilotux.net>
parents:
288
diff
changeset
|
174 |
char *key, *val, *t, *p; |
280
68ce34b4243b
Add parse_assigment() function
Mikael Berthe <mikael@lilotux.net>
parents:
279
diff
changeset
|
175 |
|
68ce34b4243b
Add parse_assigment() function
Mikael Berthe <mikael@lilotux.net>
parents:
279
diff
changeset
|
176 |
*pkey = *pval = NULL; |
68ce34b4243b
Add parse_assigment() function
Mikael Berthe <mikael@lilotux.net>
parents:
279
diff
changeset
|
177 |
|
68ce34b4243b
Add parse_assigment() function
Mikael Berthe <mikael@lilotux.net>
parents:
279
diff
changeset
|
178 |
key = assignment; |
68ce34b4243b
Add parse_assigment() function
Mikael Berthe <mikael@lilotux.net>
parents:
279
diff
changeset
|
179 |
// Remove leading spaces in option name |
68ce34b4243b
Add parse_assigment() function
Mikael Berthe <mikael@lilotux.net>
parents:
279
diff
changeset
|
180 |
while ((!isalnum(*key)) && (*key != '=') && *key) { |
68ce34b4243b
Add parse_assigment() function
Mikael Berthe <mikael@lilotux.net>
parents:
279
diff
changeset
|
181 |
//if (!isblank(*key)) |
293
d0295e735768
Assignment lvalue (key, option name, alias...) cannnot contain spaces
Mikael Berthe <mikael@lilotux.net>
parents:
288
diff
changeset
|
182 |
// scr_LogPrint("Error in assignment parsing!"); |
280
68ce34b4243b
Add parse_assigment() function
Mikael Berthe <mikael@lilotux.net>
parents:
279
diff
changeset
|
183 |
key++; |
68ce34b4243b
Add parse_assigment() function
Mikael Berthe <mikael@lilotux.net>
parents:
279
diff
changeset
|
184 |
} |
68ce34b4243b
Add parse_assigment() function
Mikael Berthe <mikael@lilotux.net>
parents:
279
diff
changeset
|
185 |
if (!*key) return FALSE; // Empty assignment |
68ce34b4243b
Add parse_assigment() function
Mikael Berthe <mikael@lilotux.net>
parents:
279
diff
changeset
|
186 |
|
68ce34b4243b
Add parse_assigment() function
Mikael Berthe <mikael@lilotux.net>
parents:
279
diff
changeset
|
187 |
if (*key == '=') { |
293
d0295e735768
Assignment lvalue (key, option name, alias...) cannnot contain spaces
Mikael Berthe <mikael@lilotux.net>
parents:
288
diff
changeset
|
188 |
//scr_LogPrint("Cannot parse assignment!"); |
280
68ce34b4243b
Add parse_assigment() function
Mikael Berthe <mikael@lilotux.net>
parents:
279
diff
changeset
|
189 |
return FALSE; |
68ce34b4243b
Add parse_assigment() function
Mikael Berthe <mikael@lilotux.net>
parents:
279
diff
changeset
|
190 |
} |
68ce34b4243b
Add parse_assigment() function
Mikael Berthe <mikael@lilotux.net>
parents:
279
diff
changeset
|
191 |
// Ok, key points to the option name |
68ce34b4243b
Add parse_assigment() function
Mikael Berthe <mikael@lilotux.net>
parents:
279
diff
changeset
|
192 |
|
68ce34b4243b
Add parse_assigment() function
Mikael Berthe <mikael@lilotux.net>
parents:
279
diff
changeset
|
193 |
for (val = key+1 ; *val && (*val != '=') ; val++) |
68ce34b4243b
Add parse_assigment() function
Mikael Berthe <mikael@lilotux.net>
parents:
279
diff
changeset
|
194 |
if (!isalnum(*val) && !isblank(*val) && (*val != '_') && (*val != '-')) { |
68ce34b4243b
Add parse_assigment() function
Mikael Berthe <mikael@lilotux.net>
parents:
279
diff
changeset
|
195 |
// 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
|
196 |
//scr_LogPrint("Error in assignment parsing!"); |
280
68ce34b4243b
Add parse_assigment() function
Mikael Berthe <mikael@lilotux.net>
parents:
279
diff
changeset
|
197 |
return FALSE; |
68ce34b4243b
Add parse_assigment() function
Mikael Berthe <mikael@lilotux.net>
parents:
279
diff
changeset
|
198 |
} |
68ce34b4243b
Add parse_assigment() function
Mikael Berthe <mikael@lilotux.net>
parents:
279
diff
changeset
|
199 |
// Remove trailing spaces in option name: |
68ce34b4243b
Add parse_assigment() function
Mikael Berthe <mikael@lilotux.net>
parents:
279
diff
changeset
|
200 |
for (t = val-1 ; t > key && isblank(*t) ; t--) |
68ce34b4243b
Add parse_assigment() function
Mikael Berthe <mikael@lilotux.net>
parents:
279
diff
changeset
|
201 |
; |
293
d0295e735768
Assignment lvalue (key, option name, alias...) cannnot contain spaces
Mikael Berthe <mikael@lilotux.net>
parents:
288
diff
changeset
|
202 |
// Check for embedded whitespace characters |
d0295e735768
Assignment lvalue (key, option name, alias...) cannnot contain spaces
Mikael Berthe <mikael@lilotux.net>
parents:
288
diff
changeset
|
203 |
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
|
204 |
if (isblank(*p)) { |
d0295e735768
Assignment lvalue (key, option name, alias...) cannnot contain spaces
Mikael Berthe <mikael@lilotux.net>
parents:
288
diff
changeset
|
205 |
//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
|
206 |
// " (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
|
207 |
return FALSE; |
d0295e735768
Assignment lvalue (key, option name, alias...) cannnot contain spaces
Mikael Berthe <mikael@lilotux.net>
parents:
288
diff
changeset
|
208 |
} |
d0295e735768
Assignment lvalue (key, option name, alias...) cannnot contain spaces
Mikael Berthe <mikael@lilotux.net>
parents:
288
diff
changeset
|
209 |
} |
d0295e735768
Assignment lvalue (key, option name, alias...) cannnot contain spaces
Mikael Berthe <mikael@lilotux.net>
parents:
288
diff
changeset
|
210 |
|
280
68ce34b4243b
Add parse_assigment() function
Mikael Berthe <mikael@lilotux.net>
parents:
279
diff
changeset
|
211 |
*pkey = g_strndup(key, t+1-key); |
68ce34b4243b
Add parse_assigment() function
Mikael Berthe <mikael@lilotux.net>
parents:
279
diff
changeset
|
212 |
|
68ce34b4243b
Add parse_assigment() function
Mikael Berthe <mikael@lilotux.net>
parents:
279
diff
changeset
|
213 |
if (!*val) return FALSE; // Not an assignment |
68ce34b4243b
Add parse_assigment() function
Mikael Berthe <mikael@lilotux.net>
parents:
279
diff
changeset
|
214 |
|
68ce34b4243b
Add parse_assigment() function
Mikael Berthe <mikael@lilotux.net>
parents:
279
diff
changeset
|
215 |
// Remove leading and trailing spaces in option value: |
68ce34b4243b
Add parse_assigment() function
Mikael Berthe <mikael@lilotux.net>
parents:
279
diff
changeset
|
216 |
for (val++; *val && isblank(*val) ; val++) ; |
68ce34b4243b
Add parse_assigment() function
Mikael Berthe <mikael@lilotux.net>
parents:
279
diff
changeset
|
217 |
for (t = val ; *t ; t++) ; |
68ce34b4243b
Add parse_assigment() function
Mikael Berthe <mikael@lilotux.net>
parents:
279
diff
changeset
|
218 |
for (t-- ; t >= val && isblank(*t) ; t--) ; |
68ce34b4243b
Add parse_assigment() function
Mikael Berthe <mikael@lilotux.net>
parents:
279
diff
changeset
|
219 |
|
282
87d6ac21cd1b
Fix "Cannot unset option" bug
Mikael Berthe <mikael@lilotux.net>
parents:
281
diff
changeset
|
220 |
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
|
221 |
|
337
3a25be278864
Values can be enclosed by quotes in assignments
Mikael Berthe <mikael@lilotux.net>
parents:
336
diff
changeset
|
222 |
// 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
|
223 |
// removed and whitespace is not stripped |
3a25be278864
Values can be enclosed by quotes in assignments
Mikael Berthe <mikael@lilotux.net>
parents:
336
diff
changeset
|
224 |
if ((t>val) && (*val == '"' && *t == '"')) { |
3a25be278864
Values can be enclosed by quotes in assignments
Mikael Berthe <mikael@lilotux.net>
parents:
336
diff
changeset
|
225 |
val++; |
3a25be278864
Values can be enclosed by quotes in assignments
Mikael Berthe <mikael@lilotux.net>
parents:
336
diff
changeset
|
226 |
t--; |
3a25be278864
Values can be enclosed by quotes in assignments
Mikael Berthe <mikael@lilotux.net>
parents:
336
diff
changeset
|
227 |
} |
280
68ce34b4243b
Add parse_assigment() function
Mikael Berthe <mikael@lilotux.net>
parents:
279
diff
changeset
|
228 |
*pval = g_strndup(val, t+1-val); |
68ce34b4243b
Add parse_assigment() function
Mikael Berthe <mikael@lilotux.net>
parents:
279
diff
changeset
|
229 |
return TRUE; |
68ce34b4243b
Add parse_assigment() function
Mikael Berthe <mikael@lilotux.net>
parents:
279
diff
changeset
|
230 |
} |
68ce34b4243b
Add parse_assigment() function
Mikael Berthe <mikael@lilotux.net>
parents:
279
diff
changeset
|
231 |
|
281
f562b9af2de7
Add "const" specifier in prototypes
Mikael Berthe <mikael@lilotux.net>
parents:
280
diff
changeset
|
232 |
void settings_set(guint type, const gchar *key, const gchar *value) |
279 | 233 |
{ |
1070
9eaacc0ad3a2
Use a hash for settings
Mikael Berthe <mikael@lilotux.net>
parents:
1068
diff
changeset
|
234 |
GHashTable *hash; |
279 | 235 |
|
1070
9eaacc0ad3a2
Use a hash for settings
Mikael Berthe <mikael@lilotux.net>
parents:
1068
diff
changeset
|
236 |
hash = get_hash(type); |
9eaacc0ad3a2
Use a hash for settings
Mikael Berthe <mikael@lilotux.net>
parents:
1068
diff
changeset
|
237 |
if (!hash) |
9eaacc0ad3a2
Use a hash for settings
Mikael Berthe <mikael@lilotux.net>
parents:
1068
diff
changeset
|
238 |
return; |
9eaacc0ad3a2
Use a hash for settings
Mikael Berthe <mikael@lilotux.net>
parents:
1068
diff
changeset
|
239 |
|
9eaacc0ad3a2
Use a hash for settings
Mikael Berthe <mikael@lilotux.net>
parents:
1068
diff
changeset
|
240 |
if (!value) { |
9eaacc0ad3a2
Use a hash for settings
Mikael Berthe <mikael@lilotux.net>
parents:
1068
diff
changeset
|
241 |
g_hash_table_remove(hash, key); |
9eaacc0ad3a2
Use a hash for settings
Mikael Berthe <mikael@lilotux.net>
parents:
1068
diff
changeset
|
242 |
} else { |
9eaacc0ad3a2
Use a hash for settings
Mikael Berthe <mikael@lilotux.net>
parents:
1068
diff
changeset
|
243 |
g_hash_table_insert(hash, g_strdup(key), g_strdup(value)); |
279 | 244 |
} |
245 |
} |
|
246 |
||
281
f562b9af2de7
Add "const" specifier in prototypes
Mikael Berthe <mikael@lilotux.net>
parents:
280
diff
changeset
|
247 |
void settings_del(guint type, const gchar *key) |
279 | 248 |
{ |
249 |
settings_set(type, key, NULL); |
|
250 |
} |
|
251 |
||
281
f562b9af2de7
Add "const" specifier in prototypes
Mikael Berthe <mikael@lilotux.net>
parents:
280
diff
changeset
|
252 |
const gchar *settings_get(guint type, const gchar *key) |
279 | 253 |
{ |
1070
9eaacc0ad3a2
Use a hash for settings
Mikael Berthe <mikael@lilotux.net>
parents:
1068
diff
changeset
|
254 |
GHashTable *hash; |
279 | 255 |
|
1070
9eaacc0ad3a2
Use a hash for settings
Mikael Berthe <mikael@lilotux.net>
parents:
1068
diff
changeset
|
256 |
hash = get_hash(type); |
9eaacc0ad3a2
Use a hash for settings
Mikael Berthe <mikael@lilotux.net>
parents:
1068
diff
changeset
|
257 |
if (!hash) |
9eaacc0ad3a2
Use a hash for settings
Mikael Berthe <mikael@lilotux.net>
parents:
1068
diff
changeset
|
258 |
return NULL; |
279 | 259 |
|
1070
9eaacc0ad3a2
Use a hash for settings
Mikael Berthe <mikael@lilotux.net>
parents:
1068
diff
changeset
|
260 |
return g_hash_table_lookup(hash, key); |
279 | 261 |
} |
262 |
||
281
f562b9af2de7
Add "const" specifier in prototypes
Mikael Berthe <mikael@lilotux.net>
parents:
280
diff
changeset
|
263 |
int settings_get_int(guint type, const gchar *key) |
279 | 264 |
{ |
281
f562b9af2de7
Add "const" specifier in prototypes
Mikael Berthe <mikael@lilotux.net>
parents:
280
diff
changeset
|
265 |
const gchar *setval = settings_get(type, key); |
279 | 266 |
|
267 |
if (setval) return atoi(setval); |
|
268 |
return 0; |
|
269 |
} |
|
270 |
||
294
871e53769084
Allow one status message per Jabber status
Mikael Berthe <mikael@lilotux.net>
parents:
293
diff
changeset
|
271 |
// settings_get_status_msg(status) |
871e53769084
Allow one status message per Jabber status
Mikael Berthe <mikael@lilotux.net>
parents:
293
diff
changeset
|
272 |
// 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
|
273 |
// - 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
|
274 |
// return this message |
871e53769084
Allow one status message per Jabber status
Mikael Berthe <mikael@lilotux.net>
parents:
293
diff
changeset
|
275 |
// - 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
|
276 |
// generic user message), it is returned |
521 | 277 |
// - 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
|
278 |
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
|
279 |
{ |
871e53769084
Allow one status message per Jabber status
Mikael Berthe <mikael@lilotux.net>
parents:
293
diff
changeset
|
280 |
const gchar *rstatus = settings_opt_get("message"); |
871e53769084
Allow one status message per Jabber status
Mikael Berthe <mikael@lilotux.net>
parents:
293
diff
changeset
|
281 |
|
871e53769084
Allow one status message per Jabber status
Mikael Berthe <mikael@lilotux.net>
parents:
293
diff
changeset
|
282 |
if (rstatus) return rstatus; |
871e53769084
Allow one status message per Jabber status
Mikael Berthe <mikael@lilotux.net>
parents:
293
diff
changeset
|
283 |
|
871e53769084
Allow one status message per Jabber status
Mikael Berthe <mikael@lilotux.net>
parents:
293
diff
changeset
|
284 |
switch(status) { |
871e53769084
Allow one status message per Jabber status
Mikael Berthe <mikael@lilotux.net>
parents:
293
diff
changeset
|
285 |
case available: |
521 | 286 |
rstatus = settings_opt_get("message_avail"); |
294
871e53769084
Allow one status message per Jabber status
Mikael Berthe <mikael@lilotux.net>
parents:
293
diff
changeset
|
287 |
break; |
871e53769084
Allow one status message per Jabber status
Mikael Berthe <mikael@lilotux.net>
parents:
293
diff
changeset
|
288 |
|
871e53769084
Allow one status message per Jabber status
Mikael Berthe <mikael@lilotux.net>
parents:
293
diff
changeset
|
289 |
case freeforchat: |
521 | 290 |
rstatus = settings_opt_get("message_free"); |
294
871e53769084
Allow one status message per Jabber status
Mikael Berthe <mikael@lilotux.net>
parents:
293
diff
changeset
|
291 |
break; |
871e53769084
Allow one status message per Jabber status
Mikael Berthe <mikael@lilotux.net>
parents:
293
diff
changeset
|
292 |
|
871e53769084
Allow one status message per Jabber status
Mikael Berthe <mikael@lilotux.net>
parents:
293
diff
changeset
|
293 |
case dontdisturb: |
521 | 294 |
rstatus = settings_opt_get("message_dnd"); |
294
871e53769084
Allow one status message per Jabber status
Mikael Berthe <mikael@lilotux.net>
parents:
293
diff
changeset
|
295 |
break; |
871e53769084
Allow one status message per Jabber status
Mikael Berthe <mikael@lilotux.net>
parents:
293
diff
changeset
|
296 |
|
871e53769084
Allow one status message per Jabber status
Mikael Berthe <mikael@lilotux.net>
parents:
293
diff
changeset
|
297 |
case notavail: |
521 | 298 |
rstatus = settings_opt_get("message_notavail"); |
294
871e53769084
Allow one status message per Jabber status
Mikael Berthe <mikael@lilotux.net>
parents:
293
diff
changeset
|
299 |
break; |
871e53769084
Allow one status message per Jabber status
Mikael Berthe <mikael@lilotux.net>
parents:
293
diff
changeset
|
300 |
|
871e53769084
Allow one status message per Jabber status
Mikael Berthe <mikael@lilotux.net>
parents:
293
diff
changeset
|
301 |
case away: |
521 | 302 |
rstatus = settings_opt_get("message_away"); |
294
871e53769084
Allow one status message per Jabber status
Mikael Berthe <mikael@lilotux.net>
parents:
293
diff
changeset
|
303 |
break; |
871e53769084
Allow one status message per Jabber status
Mikael Berthe <mikael@lilotux.net>
parents:
293
diff
changeset
|
304 |
|
521 | 305 |
default: // offline, invisible |
306 |
break; |
|
294
871e53769084
Allow one status message per Jabber status
Mikael Berthe <mikael@lilotux.net>
parents:
293
diff
changeset
|
307 |
} |
871e53769084
Allow one status message per Jabber status
Mikael Berthe <mikael@lilotux.net>
parents:
293
diff
changeset
|
308 |
return rstatus; |
871e53769084
Allow one status message per Jabber status
Mikael Berthe <mikael@lilotux.net>
parents:
293
diff
changeset
|
309 |
} |
576 | 310 |
|
867
7f056c566569
Commands /alias & /bind list the key bindings and aliases
Mikael Berthe <mikael@lilotux.net>
parents:
780
diff
changeset
|
311 |
// settings_foreach(type, pfunction, param) |
7f056c566569
Commands /alias & /bind list the key bindings and aliases
Mikael Berthe <mikael@lilotux.net>
parents:
780
diff
changeset
|
312 |
// 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
|
313 |
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
|
314 |
void *param) |
7f056c566569
Commands /alias & /bind list the key bindings and aliases
Mikael Berthe <mikael@lilotux.net>
parents:
780
diff
changeset
|
315 |
{ |
1070
9eaacc0ad3a2
Use a hash for settings
Mikael Berthe <mikael@lilotux.net>
parents:
1068
diff
changeset
|
316 |
GHashTable *hash; |
867
7f056c566569
Commands /alias & /bind list the key bindings and aliases
Mikael Berthe <mikael@lilotux.net>
parents:
780
diff
changeset
|
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; |
867
7f056c566569
Commands /alias & /bind list the key bindings and aliases
Mikael Berthe <mikael@lilotux.net>
parents:
780
diff
changeset
|
321 |
|
1070
9eaacc0ad3a2
Use a hash for settings
Mikael Berthe <mikael@lilotux.net>
parents:
1068
diff
changeset
|
322 |
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
|
323 |
} |
7f056c566569
Commands /alias & /bind list the key bindings and aliases
Mikael Berthe <mikael@lilotux.net>
parents:
780
diff
changeset
|
324 |
|
1004
b57a01ffeed6
Use existing conference bookmarks
Mikael Berthe <mikael@lilotux.net>
parents:
967
diff
changeset
|
325 |
|
b57a01ffeed6
Use existing conference bookmarks
Mikael Berthe <mikael@lilotux.net>
parents:
967
diff
changeset
|
326 |
// default_muc_nickname() |
b57a01ffeed6
Use existing conference bookmarks
Mikael Berthe <mikael@lilotux.net>
parents:
967
diff
changeset
|
327 |
// Return the user's default nickname |
b57a01ffeed6
Use existing conference bookmarks
Mikael Berthe <mikael@lilotux.net>
parents:
967
diff
changeset
|
328 |
// The caller should free the string after use |
b57a01ffeed6
Use existing conference bookmarks
Mikael Berthe <mikael@lilotux.net>
parents:
967
diff
changeset
|
329 |
char *default_muc_nickname(void) |
b57a01ffeed6
Use existing conference bookmarks
Mikael Berthe <mikael@lilotux.net>
parents:
967
diff
changeset
|
330 |
{ |
b57a01ffeed6
Use existing conference bookmarks
Mikael Berthe <mikael@lilotux.net>
parents:
967
diff
changeset
|
331 |
char *nick; |
b57a01ffeed6
Use existing conference bookmarks
Mikael Berthe <mikael@lilotux.net>
parents:
967
diff
changeset
|
332 |
|
b57a01ffeed6
Use existing conference bookmarks
Mikael Berthe <mikael@lilotux.net>
parents:
967
diff
changeset
|
333 |
// 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
|
334 |
nick = (char*)settings_opt_get("nickname"); |
b57a01ffeed6
Use existing conference bookmarks
Mikael Berthe <mikael@lilotux.net>
parents:
967
diff
changeset
|
335 |
if (nick) |
b57a01ffeed6
Use existing conference bookmarks
Mikael Berthe <mikael@lilotux.net>
parents:
967
diff
changeset
|
336 |
return g_strdup(nick); |
b57a01ffeed6
Use existing conference bookmarks
Mikael Berthe <mikael@lilotux.net>
parents:
967
diff
changeset
|
337 |
|
b57a01ffeed6
Use existing conference bookmarks
Mikael Berthe <mikael@lilotux.net>
parents:
967
diff
changeset
|
338 |
nick = g_strdup(settings_opt_get("username")); |
b57a01ffeed6
Use existing conference bookmarks
Mikael Berthe <mikael@lilotux.net>
parents:
967
diff
changeset
|
339 |
if (nick) { |
b57a01ffeed6
Use existing conference bookmarks
Mikael Berthe <mikael@lilotux.net>
parents:
967
diff
changeset
|
340 |
char *p = strchr(nick, JID_DOMAIN_SEPARATOR); |
b57a01ffeed6
Use existing conference bookmarks
Mikael Berthe <mikael@lilotux.net>
parents:
967
diff
changeset
|
341 |
if (p > nick) |
b57a01ffeed6
Use existing conference bookmarks
Mikael Berthe <mikael@lilotux.net>
parents:
967
diff
changeset
|
342 |
*p = 0; |
b57a01ffeed6
Use existing conference bookmarks
Mikael Berthe <mikael@lilotux.net>
parents:
967
diff
changeset
|
343 |
} |
b57a01ffeed6
Use existing conference bookmarks
Mikael Berthe <mikael@lilotux.net>
parents:
967
diff
changeset
|
344 |
return nick; |
b57a01ffeed6
Use existing conference bookmarks
Mikael Berthe <mikael@lilotux.net>
parents:
967
diff
changeset
|
345 |
} |
b57a01ffeed6
Use existing conference bookmarks
Mikael Berthe <mikael@lilotux.net>
parents:
967
diff
changeset
|
346 |
|
1065
230dca34dbea
Extand pgp_data structure
Mikael Berthe <mikael@lilotux.net>
parents:
1004
diff
changeset
|
347 |
|
230dca34dbea
Extand pgp_data structure
Mikael Berthe <mikael@lilotux.net>
parents:
1004
diff
changeset
|
348 |
/* PGP settings */ |
230dca34dbea
Extand pgp_data structure
Mikael Berthe <mikael@lilotux.net>
parents:
1004
diff
changeset
|
349 |
|
230dca34dbea
Extand pgp_data structure
Mikael Berthe <mikael@lilotux.net>
parents:
1004
diff
changeset
|
350 |
// settings_pgp_setdisabled(jid, value) |
230dca34dbea
Extand pgp_data structure
Mikael Berthe <mikael@lilotux.net>
parents:
1004
diff
changeset
|
351 |
// Enable/disable PGP encryption for jid. |
230dca34dbea
Extand pgp_data structure
Mikael Berthe <mikael@lilotux.net>
parents:
1004
diff
changeset
|
352 |
// (Set value to TRUE to disable encryption) |
230dca34dbea
Extand pgp_data structure
Mikael Berthe <mikael@lilotux.net>
parents:
1004
diff
changeset
|
353 |
void settings_pgp_setdisabled(const char *bjid, guint value) |
230dca34dbea
Extand pgp_data structure
Mikael Berthe <mikael@lilotux.net>
parents:
1004
diff
changeset
|
354 |
{ |
230dca34dbea
Extand pgp_data structure
Mikael Berthe <mikael@lilotux.net>
parents:
1004
diff
changeset
|
355 |
#ifdef HAVE_GPGME |
230dca34dbea
Extand pgp_data structure
Mikael Berthe <mikael@lilotux.net>
parents:
1004
diff
changeset
|
356 |
T_pgpopt *pgpdata; |
230dca34dbea
Extand pgp_data structure
Mikael Berthe <mikael@lilotux.net>
parents:
1004
diff
changeset
|
357 |
pgpdata = g_hash_table_lookup(pgpopt, bjid); |
230dca34dbea
Extand pgp_data structure
Mikael Berthe <mikael@lilotux.net>
parents:
1004
diff
changeset
|
358 |
if (!pgpdata) { |
230dca34dbea
Extand pgp_data structure
Mikael Berthe <mikael@lilotux.net>
parents:
1004
diff
changeset
|
359 |
// 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
|
360 |
// the default value). |
230dca34dbea
Extand pgp_data structure
Mikael Berthe <mikael@lilotux.net>
parents:
1004
diff
changeset
|
361 |
if (value) { |
230dca34dbea
Extand pgp_data structure
Mikael Berthe <mikael@lilotux.net>
parents:
1004
diff
changeset
|
362 |
pgpdata = g_new0(T_pgpopt, 1); |
230dca34dbea
Extand pgp_data structure
Mikael Berthe <mikael@lilotux.net>
parents:
1004
diff
changeset
|
363 |
pgpdata->pgp_disabled = value; |
230dca34dbea
Extand pgp_data structure
Mikael Berthe <mikael@lilotux.net>
parents:
1004
diff
changeset
|
364 |
g_hash_table_insert(pgpopt, g_strdup(bjid), pgpdata); |
230dca34dbea
Extand pgp_data structure
Mikael Berthe <mikael@lilotux.net>
parents:
1004
diff
changeset
|
365 |
} |
230dca34dbea
Extand pgp_data structure
Mikael Berthe <mikael@lilotux.net>
parents:
1004
diff
changeset
|
366 |
} else { |
230dca34dbea
Extand pgp_data structure
Mikael Berthe <mikael@lilotux.net>
parents:
1004
diff
changeset
|
367 |
pgpdata->pgp_disabled = value; |
230dca34dbea
Extand pgp_data structure
Mikael Berthe <mikael@lilotux.net>
parents:
1004
diff
changeset
|
368 |
// 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
|
369 |
// pgp_keyid is NULL, actually. |
230dca34dbea
Extand pgp_data structure
Mikael Berthe <mikael@lilotux.net>
parents:
1004
diff
changeset
|
370 |
} |
230dca34dbea
Extand pgp_data structure
Mikael Berthe <mikael@lilotux.net>
parents:
1004
diff
changeset
|
371 |
#endif |
230dca34dbea
Extand pgp_data structure
Mikael Berthe <mikael@lilotux.net>
parents:
1004
diff
changeset
|
372 |
} |
230dca34dbea
Extand pgp_data structure
Mikael Berthe <mikael@lilotux.net>
parents:
1004
diff
changeset
|
373 |
|
230dca34dbea
Extand pgp_data structure
Mikael Berthe <mikael@lilotux.net>
parents:
1004
diff
changeset
|
374 |
// settings_pgp_getdisabled(jid) |
230dca34dbea
Extand pgp_data structure
Mikael Berthe <mikael@lilotux.net>
parents:
1004
diff
changeset
|
375 |
// Return TRUE if PGP encryption should be disabled for jid. |
230dca34dbea
Extand pgp_data structure
Mikael Berthe <mikael@lilotux.net>
parents:
1004
diff
changeset
|
376 |
guint settings_pgp_getdisabled(const char *bjid) |
230dca34dbea
Extand pgp_data structure
Mikael Berthe <mikael@lilotux.net>
parents:
1004
diff
changeset
|
377 |
{ |
230dca34dbea
Extand pgp_data structure
Mikael Berthe <mikael@lilotux.net>
parents:
1004
diff
changeset
|
378 |
#ifdef HAVE_GPGME |
230dca34dbea
Extand pgp_data structure
Mikael Berthe <mikael@lilotux.net>
parents:
1004
diff
changeset
|
379 |
T_pgpopt *pgpdata; |
230dca34dbea
Extand pgp_data structure
Mikael Berthe <mikael@lilotux.net>
parents:
1004
diff
changeset
|
380 |
pgpdata = g_hash_table_lookup(pgpopt, bjid); |
230dca34dbea
Extand pgp_data structure
Mikael Berthe <mikael@lilotux.net>
parents:
1004
diff
changeset
|
381 |
if (pgpdata) |
230dca34dbea
Extand pgp_data structure
Mikael Berthe <mikael@lilotux.net>
parents:
1004
diff
changeset
|
382 |
return pgpdata->pgp_disabled; |
230dca34dbea
Extand pgp_data structure
Mikael Berthe <mikael@lilotux.net>
parents:
1004
diff
changeset
|
383 |
else |
230dca34dbea
Extand pgp_data structure
Mikael Berthe <mikael@lilotux.net>
parents:
1004
diff
changeset
|
384 |
return FALSE; // default: not disabled |
230dca34dbea
Extand pgp_data structure
Mikael Berthe <mikael@lilotux.net>
parents:
1004
diff
changeset
|
385 |
#else |
230dca34dbea
Extand pgp_data structure
Mikael Berthe <mikael@lilotux.net>
parents:
1004
diff
changeset
|
386 |
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
|
387 |
#endif |
230dca34dbea
Extand pgp_data structure
Mikael Berthe <mikael@lilotux.net>
parents:
1004
diff
changeset
|
388 |
} |
230dca34dbea
Extand pgp_data structure
Mikael Berthe <mikael@lilotux.net>
parents:
1004
diff
changeset
|
389 |
|
230dca34dbea
Extand pgp_data structure
Mikael Berthe <mikael@lilotux.net>
parents:
1004
diff
changeset
|
390 |
// settings_pgp_setkeyid(jid, keyid) |
230dca34dbea
Extand pgp_data structure
Mikael Berthe <mikael@lilotux.net>
parents:
1004
diff
changeset
|
391 |
// Set the PGP KeyId for user jid. |
230dca34dbea
Extand pgp_data structure
Mikael Berthe <mikael@lilotux.net>
parents:
1004
diff
changeset
|
392 |
// Use keyid = NULL to erase the previous KeyId. |
230dca34dbea
Extand pgp_data structure
Mikael Berthe <mikael@lilotux.net>
parents:
1004
diff
changeset
|
393 |
void settings_pgp_setkeyid(const char *bjid, const char *keyid) |
230dca34dbea
Extand pgp_data structure
Mikael Berthe <mikael@lilotux.net>
parents:
1004
diff
changeset
|
394 |
{ |
230dca34dbea
Extand pgp_data structure
Mikael Berthe <mikael@lilotux.net>
parents:
1004
diff
changeset
|
395 |
#ifdef HAVE_GPGME |
230dca34dbea
Extand pgp_data structure
Mikael Berthe <mikael@lilotux.net>
parents:
1004
diff
changeset
|
396 |
T_pgpopt *pgpdata; |
230dca34dbea
Extand pgp_data structure
Mikael Berthe <mikael@lilotux.net>
parents:
1004
diff
changeset
|
397 |
pgpdata = g_hash_table_lookup(pgpopt, bjid); |
230dca34dbea
Extand pgp_data structure
Mikael Berthe <mikael@lilotux.net>
parents:
1004
diff
changeset
|
398 |
if (!pgpdata) { |
230dca34dbea
Extand pgp_data structure
Mikael Berthe <mikael@lilotux.net>
parents:
1004
diff
changeset
|
399 |
// 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
|
400 |
// the default value). |
230dca34dbea
Extand pgp_data structure
Mikael Berthe <mikael@lilotux.net>
parents:
1004
diff
changeset
|
401 |
if (keyid) { |
230dca34dbea
Extand pgp_data structure
Mikael Berthe <mikael@lilotux.net>
parents:
1004
diff
changeset
|
402 |
pgpdata = g_new0(T_pgpopt, 1); |
230dca34dbea
Extand pgp_data structure
Mikael Berthe <mikael@lilotux.net>
parents:
1004
diff
changeset
|
403 |
pgpdata->pgp_keyid = g_strdup(keyid); |
230dca34dbea
Extand pgp_data structure
Mikael Berthe <mikael@lilotux.net>
parents:
1004
diff
changeset
|
404 |
g_hash_table_insert(pgpopt, g_strdup(bjid), pgpdata); |
230dca34dbea
Extand pgp_data structure
Mikael Berthe <mikael@lilotux.net>
parents:
1004
diff
changeset
|
405 |
} |
230dca34dbea
Extand pgp_data structure
Mikael Berthe <mikael@lilotux.net>
parents:
1004
diff
changeset
|
406 |
} else { |
230dca34dbea
Extand pgp_data structure
Mikael Berthe <mikael@lilotux.net>
parents:
1004
diff
changeset
|
407 |
g_free(pgpdata->pgp_keyid); |
230dca34dbea
Extand pgp_data structure
Mikael Berthe <mikael@lilotux.net>
parents:
1004
diff
changeset
|
408 |
if (keyid) |
230dca34dbea
Extand pgp_data structure
Mikael Berthe <mikael@lilotux.net>
parents:
1004
diff
changeset
|
409 |
pgpdata->pgp_keyid = g_strdup(keyid); |
230dca34dbea
Extand pgp_data structure
Mikael Berthe <mikael@lilotux.net>
parents:
1004
diff
changeset
|
410 |
else |
230dca34dbea
Extand pgp_data structure
Mikael Berthe <mikael@lilotux.net>
parents:
1004
diff
changeset
|
411 |
pgpdata->pgp_keyid = NULL; |
230dca34dbea
Extand pgp_data structure
Mikael Berthe <mikael@lilotux.net>
parents:
1004
diff
changeset
|
412 |
// 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
|
413 |
// pgp_keyid is NULL, actually. |
230dca34dbea
Extand pgp_data structure
Mikael Berthe <mikael@lilotux.net>
parents:
1004
diff
changeset
|
414 |
} |
230dca34dbea
Extand pgp_data structure
Mikael Berthe <mikael@lilotux.net>
parents:
1004
diff
changeset
|
415 |
#endif |
230dca34dbea
Extand pgp_data structure
Mikael Berthe <mikael@lilotux.net>
parents:
1004
diff
changeset
|
416 |
} |
230dca34dbea
Extand pgp_data structure
Mikael Berthe <mikael@lilotux.net>
parents:
1004
diff
changeset
|
417 |
|
230dca34dbea
Extand pgp_data structure
Mikael Berthe <mikael@lilotux.net>
parents:
1004
diff
changeset
|
418 |
// settings_pgp_getkeyid(jid) |
230dca34dbea
Extand pgp_data structure
Mikael Berthe <mikael@lilotux.net>
parents:
1004
diff
changeset
|
419 |
// Get the PGP KeyId for user jid. |
230dca34dbea
Extand pgp_data structure
Mikael Berthe <mikael@lilotux.net>
parents:
1004
diff
changeset
|
420 |
const char *settings_pgp_getkeyid(const char *bjid) |
230dca34dbea
Extand pgp_data structure
Mikael Berthe <mikael@lilotux.net>
parents:
1004
diff
changeset
|
421 |
{ |
230dca34dbea
Extand pgp_data structure
Mikael Berthe <mikael@lilotux.net>
parents:
1004
diff
changeset
|
422 |
#ifdef HAVE_GPGME |
230dca34dbea
Extand pgp_data structure
Mikael Berthe <mikael@lilotux.net>
parents:
1004
diff
changeset
|
423 |
T_pgpopt *pgpdata; |
230dca34dbea
Extand pgp_data structure
Mikael Berthe <mikael@lilotux.net>
parents:
1004
diff
changeset
|
424 |
pgpdata = g_hash_table_lookup(pgpopt, bjid); |
230dca34dbea
Extand pgp_data structure
Mikael Berthe <mikael@lilotux.net>
parents:
1004
diff
changeset
|
425 |
if (pgpdata) |
230dca34dbea
Extand pgp_data structure
Mikael Berthe <mikael@lilotux.net>
parents:
1004
diff
changeset
|
426 |
return pgpdata->pgp_keyid; |
230dca34dbea
Extand pgp_data structure
Mikael Berthe <mikael@lilotux.net>
parents:
1004
diff
changeset
|
427 |
#endif |
230dca34dbea
Extand pgp_data structure
Mikael Berthe <mikael@lilotux.net>
parents:
1004
diff
changeset
|
428 |
return NULL; |
230dca34dbea
Extand pgp_data structure
Mikael Berthe <mikael@lilotux.net>
parents:
1004
diff
changeset
|
429 |
} |
230dca34dbea
Extand pgp_data structure
Mikael Berthe <mikael@lilotux.net>
parents:
1004
diff
changeset
|
430 |
|
1141
5be2408a6534
Add option "max_history_blocks"
Mikael Berthe <mikael@lilotux.net>
parents:
1074
diff
changeset
|
431 |
guint get_max_history_blocks(void) |
5be2408a6534
Add option "max_history_blocks"
Mikael Berthe <mikael@lilotux.net>
parents:
1074
diff
changeset
|
432 |
{ |
5be2408a6534
Add option "max_history_blocks"
Mikael Berthe <mikael@lilotux.net>
parents:
1074
diff
changeset
|
433 |
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
|
434 |
if (max_num_of_blocks < 0) |
5be2408a6534
Add option "max_history_blocks"
Mikael Berthe <mikael@lilotux.net>
parents:
1074
diff
changeset
|
435 |
max_num_of_blocks = 0; |
5be2408a6534
Add option "max_history_blocks"
Mikael Berthe <mikael@lilotux.net>
parents:
1074
diff
changeset
|
436 |
else if (max_num_of_blocks == 1) |
5be2408a6534
Add option "max_history_blocks"
Mikael Berthe <mikael@lilotux.net>
parents:
1074
diff
changeset
|
437 |
max_num_of_blocks = 2; |
5be2408a6534
Add option "max_history_blocks"
Mikael Berthe <mikael@lilotux.net>
parents:
1074
diff
changeset
|
438 |
return (guint)max_num_of_blocks; |
5be2408a6534
Add option "max_history_blocks"
Mikael Berthe <mikael@lilotux.net>
parents:
1074
diff
changeset
|
439 |
} |
5be2408a6534
Add option "max_history_blocks"
Mikael Berthe <mikael@lilotux.net>
parents:
1074
diff
changeset
|
440 |
|
580 | 441 |
/* vim: set expandtab cindent cinoptions=>2\:2(0: For Vim users... */ |