Mercurial > pidgin
comparison libpurple/protocols/silc/util.c @ 15822:32c366eeeb99
sed -ie 's/gaim/purple/g'
author | Sean Egan <seanegan@gmail.com> |
---|---|
date | Mon, 19 Mar 2007 07:01:17 +0000 |
parents | 5fe8042783c1 |
children | b9dce5f463fb |
comparison
equal
deleted
inserted
replaced
15821:84b0f9b23ede | 15822:32c366eeeb99 |
---|---|
1 /* | 1 /* |
2 | 2 |
3 silcgaim_util.c | 3 silcpurple_util.c |
4 | 4 |
5 Author: Pekka Riikonen <priikone@silcnet.org> | 5 Author: Pekka Riikonen <priikone@silcnet.org> |
6 | 6 |
7 Copyright (C) 2004 - 2005 Pekka Riikonen | 7 Copyright (C) 2004 - 2005 Pekka Riikonen |
8 | 8 |
17 | 17 |
18 */ | 18 */ |
19 | 19 |
20 #include "silcincludes.h" | 20 #include "silcincludes.h" |
21 #include "silcclient.h" | 21 #include "silcclient.h" |
22 #include "silcgaim.h" | 22 #include "silcpurple.h" |
23 #include "imgstore.h" | 23 #include "imgstore.h" |
24 | 24 |
25 /**************************** Utility Routines *******************************/ | 25 /**************************** Utility Routines *******************************/ |
26 | 26 |
27 static char str[256], str2[256]; | 27 static char str[256], str2[256]; |
28 | 28 |
29 const char *silcgaim_silcdir(void) | 29 const char *silcpurple_silcdir(void) |
30 { | 30 { |
31 const char *hd = gaim_home_dir(); | 31 const char *hd = purple_home_dir(); |
32 memset(str, 0, sizeof(str)); | 32 memset(str, 0, sizeof(str)); |
33 g_snprintf(str, sizeof(str) - 1, "%s" G_DIR_SEPARATOR_S ".silc", hd ? hd : "/tmp"); | 33 g_snprintf(str, sizeof(str) - 1, "%s" G_DIR_SEPARATOR_S ".silc", hd ? hd : "/tmp"); |
34 return (const char *)str; | 34 return (const char *)str; |
35 } | 35 } |
36 | 36 |
37 const char *silcgaim_session_file(const char *account) | 37 const char *silcpurple_session_file(const char *account) |
38 { | 38 { |
39 memset(str2, 0, sizeof(str2)); | 39 memset(str2, 0, sizeof(str2)); |
40 g_snprintf(str2, sizeof(str2) - 1, "%s" G_DIR_SEPARATOR_S "%s_session", | 40 g_snprintf(str2, sizeof(str2) - 1, "%s" G_DIR_SEPARATOR_S "%s_session", |
41 silcgaim_silcdir(), account); | 41 silcpurple_silcdir(), account); |
42 return (const char *)str2; | 42 return (const char *)str2; |
43 } | 43 } |
44 | 44 |
45 gboolean silcgaim_ip_is_private(const char *ip) | 45 gboolean silcpurple_ip_is_private(const char *ip) |
46 { | 46 { |
47 if (silc_net_is_ip4(ip)) { | 47 if (silc_net_is_ip4(ip)) { |
48 if (!strncmp(ip, "10.", 3)) { | 48 if (!strncmp(ip, "10.", 3)) { |
49 return TRUE; | 49 return TRUE; |
50 } else if (!strncmp(ip, "172.", 4) && strlen(ip) > 6) { | 50 } else if (!strncmp(ip, "172.", 4) && strlen(ip) > 6) { |
66 /* This checks stats for various SILC files and directories. First it | 66 /* This checks stats for various SILC files and directories. First it |
67 checks if ~/.silc directory exist and is owned by the correct user. If | 67 checks if ~/.silc directory exist and is owned by the correct user. If |
68 it doesn't exist, it will create the directory. After that it checks if | 68 it doesn't exist, it will create the directory. After that it checks if |
69 user's Public and Private key files exists and creates them if needed. */ | 69 user's Public and Private key files exists and creates them if needed. */ |
70 | 70 |
71 gboolean silcgaim_check_silc_dir(GaimConnection *gc) | 71 gboolean silcpurple_check_silc_dir(PurpleConnection *gc) |
72 { | 72 { |
73 char filename[256], file_public_key[256], file_private_key[256]; | 73 char filename[256], file_public_key[256], file_private_key[256]; |
74 char servfilename[256], clientfilename[256], friendsfilename[256]; | 74 char servfilename[256], clientfilename[256], friendsfilename[256]; |
75 char pkd[256], prd[256]; | 75 char pkd[256], prd[256]; |
76 struct stat st; | 76 struct stat st; |
77 struct passwd *pw; | 77 struct passwd *pw; |
78 int fd; | 78 int fd; |
79 | 79 |
80 pw = getpwuid(getuid()); | 80 pw = getpwuid(getuid()); |
81 if (!pw) { | 81 if (!pw) { |
82 gaim_debug_error("silc", "silc: %s\n", strerror(errno)); | 82 purple_debug_error("silc", "silc: %s\n", strerror(errno)); |
83 return FALSE; | 83 return FALSE; |
84 } | 84 } |
85 | 85 |
86 g_snprintf(filename, sizeof(filename) - 1, "%s", silcgaim_silcdir()); | 86 g_snprintf(filename, sizeof(filename) - 1, "%s", silcpurple_silcdir()); |
87 g_snprintf(servfilename, sizeof(servfilename) - 1, "%s" G_DIR_SEPARATOR_S "serverkeys", | 87 g_snprintf(servfilename, sizeof(servfilename) - 1, "%s" G_DIR_SEPARATOR_S "serverkeys", |
88 silcgaim_silcdir()); | 88 silcpurple_silcdir()); |
89 g_snprintf(clientfilename, sizeof(clientfilename) - 1, "%s" G_DIR_SEPARATOR_S "clientkeys", | 89 g_snprintf(clientfilename, sizeof(clientfilename) - 1, "%s" G_DIR_SEPARATOR_S "clientkeys", |
90 silcgaim_silcdir()); | 90 silcpurple_silcdir()); |
91 g_snprintf(friendsfilename, sizeof(friendsfilename) - 1, "%s" G_DIR_SEPARATOR_S "friends", | 91 g_snprintf(friendsfilename, sizeof(friendsfilename) - 1, "%s" G_DIR_SEPARATOR_S "friends", |
92 silcgaim_silcdir()); | 92 silcpurple_silcdir()); |
93 | 93 |
94 /* | 94 /* |
95 * Check ~/.silc directory | 95 * Check ~/.silc directory |
96 */ | 96 */ |
97 if ((g_stat(filename, &st)) == -1) { | 97 if ((g_stat(filename, &st)) == -1) { |
98 /* If dir doesn't exist */ | 98 /* If dir doesn't exist */ |
99 if (errno == ENOENT) { | 99 if (errno == ENOENT) { |
100 if (pw->pw_uid == geteuid()) { | 100 if (pw->pw_uid == geteuid()) { |
101 if ((g_mkdir(filename, 0755)) == -1) { | 101 if ((g_mkdir(filename, 0755)) == -1) { |
102 gaim_debug_error("silc", "Couldn't create '%s' directory\n", filename); | 102 purple_debug_error("silc", "Couldn't create '%s' directory\n", filename); |
103 return FALSE; | 103 return FALSE; |
104 } | 104 } |
105 } else { | 105 } else { |
106 gaim_debug_error("silc", "Couldn't create '%s' directory due to a wrong uid!\n", | 106 purple_debug_error("silc", "Couldn't create '%s' directory due to a wrong uid!\n", |
107 filename); | 107 filename); |
108 return FALSE; | 108 return FALSE; |
109 } | 109 } |
110 } else { | 110 } else { |
111 gaim_debug_error("silc", "Couldn't stat '%s' directory, error: %s\n", filename, strerror(errno)); | 111 purple_debug_error("silc", "Couldn't stat '%s' directory, error: %s\n", filename, strerror(errno)); |
112 return FALSE; | 112 return FALSE; |
113 } | 113 } |
114 } else { | 114 } else { |
115 #ifndef _WIN32 | 115 #ifndef _WIN32 |
116 /* Check the owner of the dir */ | 116 /* Check the owner of the dir */ |
117 if (st.st_uid != 0 && st.st_uid != pw->pw_uid) { | 117 if (st.st_uid != 0 && st.st_uid != pw->pw_uid) { |
118 gaim_debug_error("silc", "You don't seem to own '%s' directory\n", | 118 purple_debug_error("silc", "You don't seem to own '%s' directory\n", |
119 filename); | 119 filename); |
120 return FALSE; | 120 return FALSE; |
121 } | 121 } |
122 #endif | 122 #endif |
123 } | 123 } |
128 if ((g_stat(servfilename, &st)) == -1) { | 128 if ((g_stat(servfilename, &st)) == -1) { |
129 /* If dir doesn't exist */ | 129 /* If dir doesn't exist */ |
130 if (errno == ENOENT) { | 130 if (errno == ENOENT) { |
131 if (pw->pw_uid == geteuid()) { | 131 if (pw->pw_uid == geteuid()) { |
132 if ((g_mkdir(servfilename, 0755)) == -1) { | 132 if ((g_mkdir(servfilename, 0755)) == -1) { |
133 gaim_debug_error("silc", "Couldn't create '%s' directory\n", servfilename); | 133 purple_debug_error("silc", "Couldn't create '%s' directory\n", servfilename); |
134 return FALSE; | 134 return FALSE; |
135 } | 135 } |
136 } else { | 136 } else { |
137 gaim_debug_error("silc", "Couldn't create '%s' directory due to a wrong uid!\n", | 137 purple_debug_error("silc", "Couldn't create '%s' directory due to a wrong uid!\n", |
138 servfilename); | 138 servfilename); |
139 return FALSE; | 139 return FALSE; |
140 } | 140 } |
141 } else { | 141 } else { |
142 gaim_debug_error("silc", "Couldn't stat '%s' directory, error: %s\n", | 142 purple_debug_error("silc", "Couldn't stat '%s' directory, error: %s\n", |
143 servfilename, strerror(errno)); | 143 servfilename, strerror(errno)); |
144 return FALSE; | 144 return FALSE; |
145 } | 145 } |
146 } | 146 } |
147 | 147 |
151 if ((g_stat(clientfilename, &st)) == -1) { | 151 if ((g_stat(clientfilename, &st)) == -1) { |
152 /* If dir doesn't exist */ | 152 /* If dir doesn't exist */ |
153 if (errno == ENOENT) { | 153 if (errno == ENOENT) { |
154 if (pw->pw_uid == geteuid()) { | 154 if (pw->pw_uid == geteuid()) { |
155 if ((g_mkdir(clientfilename, 0755)) == -1) { | 155 if ((g_mkdir(clientfilename, 0755)) == -1) { |
156 gaim_debug_error("silc", "Couldn't create '%s' directory\n", clientfilename); | 156 purple_debug_error("silc", "Couldn't create '%s' directory\n", clientfilename); |
157 return FALSE; | 157 return FALSE; |
158 } | 158 } |
159 } else { | 159 } else { |
160 gaim_debug_error("silc", "Couldn't create '%s' directory due to a wrong uid!\n", | 160 purple_debug_error("silc", "Couldn't create '%s' directory due to a wrong uid!\n", |
161 clientfilename); | 161 clientfilename); |
162 return FALSE; | 162 return FALSE; |
163 } | 163 } |
164 } else { | 164 } else { |
165 gaim_debug_error("silc", "Couldn't stat '%s' directory, error: %s\n", | 165 purple_debug_error("silc", "Couldn't stat '%s' directory, error: %s\n", |
166 clientfilename, strerror(errno)); | 166 clientfilename, strerror(errno)); |
167 return FALSE; | 167 return FALSE; |
168 } | 168 } |
169 } | 169 } |
170 | 170 |
174 if ((g_stat(friendsfilename, &st)) == -1) { | 174 if ((g_stat(friendsfilename, &st)) == -1) { |
175 /* If dir doesn't exist */ | 175 /* If dir doesn't exist */ |
176 if (errno == ENOENT) { | 176 if (errno == ENOENT) { |
177 if (pw->pw_uid == geteuid()) { | 177 if (pw->pw_uid == geteuid()) { |
178 if ((g_mkdir(friendsfilename, 0755)) == -1) { | 178 if ((g_mkdir(friendsfilename, 0755)) == -1) { |
179 gaim_debug_error("silc", "Couldn't create '%s' directory\n", friendsfilename); | 179 purple_debug_error("silc", "Couldn't create '%s' directory\n", friendsfilename); |
180 return FALSE; | 180 return FALSE; |
181 } | 181 } |
182 } else { | 182 } else { |
183 gaim_debug_error("silc", "Couldn't create '%s' directory due to a wrong uid!\n", | 183 purple_debug_error("silc", "Couldn't create '%s' directory due to a wrong uid!\n", |
184 friendsfilename); | 184 friendsfilename); |
185 return FALSE; | 185 return FALSE; |
186 } | 186 } |
187 } else { | 187 } else { |
188 gaim_debug_error("silc", "Couldn't stat '%s' directory, error: %s\n", | 188 purple_debug_error("silc", "Couldn't stat '%s' directory, error: %s\n", |
189 friendsfilename, strerror(errno)); | 189 friendsfilename, strerror(errno)); |
190 return FALSE; | 190 return FALSE; |
191 } | 191 } |
192 } | 192 } |
193 | 193 |
194 /* | 194 /* |
195 * Check Public and Private keys | 195 * Check Public and Private keys |
196 */ | 196 */ |
197 g_snprintf(pkd, sizeof(pkd), "%s" G_DIR_SEPARATOR_S "public_key.pub", silcgaim_silcdir()); | 197 g_snprintf(pkd, sizeof(pkd), "%s" G_DIR_SEPARATOR_S "public_key.pub", silcpurple_silcdir()); |
198 g_snprintf(prd, sizeof(prd), "%s" G_DIR_SEPARATOR_S "private_key.prv", silcgaim_silcdir()); | 198 g_snprintf(prd, sizeof(prd), "%s" G_DIR_SEPARATOR_S "private_key.prv", silcpurple_silcdir()); |
199 g_snprintf(file_public_key, sizeof(file_public_key) - 1, "%s", | 199 g_snprintf(file_public_key, sizeof(file_public_key) - 1, "%s", |
200 gaim_account_get_string(gc->account, "public-key", pkd)); | 200 purple_account_get_string(gc->account, "public-key", pkd)); |
201 g_snprintf(file_private_key, sizeof(file_public_key) - 1, "%s", | 201 g_snprintf(file_private_key, sizeof(file_public_key) - 1, "%s", |
202 gaim_account_get_string(gc->account, "private-key", prd)); | 202 purple_account_get_string(gc->account, "private-key", prd)); |
203 | 203 |
204 if ((g_stat(file_public_key, &st)) == -1) { | 204 if ((g_stat(file_public_key, &st)) == -1) { |
205 /* If file doesn't exist */ | 205 /* If file doesn't exist */ |
206 if (errno == ENOENT) { | 206 if (errno == ENOENT) { |
207 gaim_connection_update_progress(gc, _("Creating SILC key pair..."), 1, 5); | 207 purple_connection_update_progress(gc, _("Creating SILC key pair..."), 1, 5); |
208 if (!silc_create_key_pair(SILCGAIM_DEF_PKCS, | 208 if (!silc_create_key_pair(SILCPURPLE_DEF_PKCS, |
209 SILCGAIM_DEF_PKCS_LEN, | 209 SILCPURPLE_DEF_PKCS_LEN, |
210 file_public_key, file_private_key, NULL, | 210 file_public_key, file_private_key, NULL, |
211 (gc->password == NULL) ? "" : gc->password, | 211 (gc->password == NULL) ? "" : gc->password, |
212 NULL, NULL, NULL, FALSE)) { | 212 NULL, NULL, NULL, FALSE)) { |
213 gaim_debug_error("silc", "Couldn't create key pair\n"); | 213 purple_debug_error("silc", "Couldn't create key pair\n"); |
214 return FALSE; | 214 return FALSE; |
215 } | 215 } |
216 | 216 |
217 if ((g_stat(file_public_key, &st)) == -1) { | 217 if ((g_stat(file_public_key, &st)) == -1) { |
218 gaim_debug_error("silc", "Couldn't stat '%s' public key, error: %s\n", | 218 purple_debug_error("silc", "Couldn't stat '%s' public key, error: %s\n", |
219 file_public_key, strerror(errno)); | 219 file_public_key, strerror(errno)); |
220 return FALSE; | 220 return FALSE; |
221 } | 221 } |
222 } else { | 222 } else { |
223 gaim_debug_error("silc", "Couldn't stat '%s' public key, error: %s\n", | 223 purple_debug_error("silc", "Couldn't stat '%s' public key, error: %s\n", |
224 file_public_key, strerror(errno)); | 224 file_public_key, strerror(errno)); |
225 return FALSE; | 225 return FALSE; |
226 } | 226 } |
227 } | 227 } |
228 | 228 |
229 #ifndef _WIN32 | 229 #ifndef _WIN32 |
230 /* Check the owner of the public key */ | 230 /* Check the owner of the public key */ |
231 if (st.st_uid != 0 && st.st_uid != pw->pw_uid) { | 231 if (st.st_uid != 0 && st.st_uid != pw->pw_uid) { |
232 gaim_debug_error("silc", "You don't seem to own your public key!?\n"); | 232 purple_debug_error("silc", "You don't seem to own your public key!?\n"); |
233 return FALSE; | 233 return FALSE; |
234 } | 234 } |
235 #endif | 235 #endif |
236 | 236 |
237 if ((fd = g_open(file_private_key, O_RDONLY, 0)) != -1) { | 237 if ((fd = g_open(file_private_key, O_RDONLY, 0)) != -1) { |
238 if ((fstat(fd, &st)) == -1) { | 238 if ((fstat(fd, &st)) == -1) { |
239 gaim_debug_error("silc", "Couldn't stat '%s' private key, error: %s\n", | 239 purple_debug_error("silc", "Couldn't stat '%s' private key, error: %s\n", |
240 file_private_key, strerror(errno)); | 240 file_private_key, strerror(errno)); |
241 close(fd); | 241 close(fd); |
242 return FALSE; | 242 return FALSE; |
243 } | 243 } |
244 } else if ((g_stat(file_private_key, &st)) == -1) { | 244 } else if ((g_stat(file_private_key, &st)) == -1) { |
245 /* If file doesn't exist */ | 245 /* If file doesn't exist */ |
246 if (errno == ENOENT) { | 246 if (errno == ENOENT) { |
247 gaim_connection_update_progress(gc, _("Creating SILC key pair..."), 1, 5); | 247 purple_connection_update_progress(gc, _("Creating SILC key pair..."), 1, 5); |
248 if (!silc_create_key_pair(SILCGAIM_DEF_PKCS, | 248 if (!silc_create_key_pair(SILCPURPLE_DEF_PKCS, |
249 SILCGAIM_DEF_PKCS_LEN, | 249 SILCPURPLE_DEF_PKCS_LEN, |
250 file_public_key, file_private_key, NULL, | 250 file_public_key, file_private_key, NULL, |
251 (gc->password == NULL) ? "" : gc->password, | 251 (gc->password == NULL) ? "" : gc->password, |
252 NULL, NULL, NULL, FALSE)) { | 252 NULL, NULL, NULL, FALSE)) { |
253 gaim_debug_error("silc", "Couldn't create key pair\n"); | 253 purple_debug_error("silc", "Couldn't create key pair\n"); |
254 return FALSE; | 254 return FALSE; |
255 } | 255 } |
256 | 256 |
257 if ((fd = g_open(file_private_key, O_RDONLY, 0)) != -1) { | 257 if ((fd = g_open(file_private_key, O_RDONLY, 0)) != -1) { |
258 if ((fstat(fd, &st)) == -1) { | 258 if ((fstat(fd, &st)) == -1) { |
259 gaim_debug_error("silc", "Couldn't stat '%s' private key, error: %s\n", | 259 purple_debug_error("silc", "Couldn't stat '%s' private key, error: %s\n", |
260 file_private_key, strerror(errno)); | 260 file_private_key, strerror(errno)); |
261 close(fd); | 261 close(fd); |
262 return FALSE; | 262 return FALSE; |
263 } | 263 } |
264 } | 264 } |
265 /* This shouldn't really happen because silc_create_key_pair() | 265 /* This shouldn't really happen because silc_create_key_pair() |
266 * will set the permissions */ | 266 * will set the permissions */ |
267 else if ((g_stat(file_private_key, &st)) == -1) { | 267 else if ((g_stat(file_private_key, &st)) == -1) { |
268 gaim_debug_error("silc", "Couldn't stat '%s' private key, error: %s\n", | 268 purple_debug_error("silc", "Couldn't stat '%s' private key, error: %s\n", |
269 file_private_key, strerror(errno)); | 269 file_private_key, strerror(errno)); |
270 return FALSE; | 270 return FALSE; |
271 } | 271 } |
272 } else { | 272 } else { |
273 gaim_debug_error("silc", "Couldn't stat '%s' private key, error: %s\n", | 273 purple_debug_error("silc", "Couldn't stat '%s' private key, error: %s\n", |
274 file_private_key, strerror(errno)); | 274 file_private_key, strerror(errno)); |
275 return FALSE; | 275 return FALSE; |
276 } | 276 } |
277 } | 277 } |
278 | 278 |
279 #ifndef _WIN32 | 279 #ifndef _WIN32 |
280 /* Check the owner of the private key */ | 280 /* Check the owner of the private key */ |
281 if (st.st_uid != 0 && st.st_uid != pw->pw_uid) { | 281 if (st.st_uid != 0 && st.st_uid != pw->pw_uid) { |
282 gaim_debug_error("silc", "You don't seem to own your private key!?\n"); | 282 purple_debug_error("silc", "You don't seem to own your private key!?\n"); |
283 if (fd != -1) | 283 if (fd != -1) |
284 close(fd); | 284 close(fd); |
285 return FALSE; | 285 return FALSE; |
286 } | 286 } |
287 | 287 |
288 /* Check the permissions for the private key */ | 288 /* Check the permissions for the private key */ |
289 if ((st.st_mode & 0777) != 0600) { | 289 if ((st.st_mode & 0777) != 0600) { |
290 gaim_debug_warning("silc", "Wrong permissions in your private key file `%s'!\n" | 290 purple_debug_warning("silc", "Wrong permissions in your private key file `%s'!\n" |
291 "Trying to change them ...\n", file_private_key); | 291 "Trying to change them ...\n", file_private_key); |
292 if ((fd == -1) || (fchmod(fd, S_IRUSR | S_IWUSR)) == -1) { | 292 if ((fd == -1) || (fchmod(fd, S_IRUSR | S_IWUSR)) == -1) { |
293 gaim_debug_error("silc", | 293 purple_debug_error("silc", |
294 "Failed to change permissions for private key file!\n" | 294 "Failed to change permissions for private key file!\n" |
295 "Permissions for your private key file must be 0600.\n"); | 295 "Permissions for your private key file must be 0600.\n"); |
296 if (fd != -1) | 296 if (fd != -1) |
297 close(fd); | 297 close(fd); |
298 return FALSE; | 298 return FALSE; |
299 } | 299 } |
300 gaim_debug_warning("silc", "Done.\n\n"); | 300 purple_debug_warning("silc", "Done.\n\n"); |
301 } | 301 } |
302 #endif | 302 #endif |
303 | 303 |
304 if (fd != -1) | 304 if (fd != -1) |
305 close(fd); | 305 close(fd); |
320 uid_t geteuid() { | 320 uid_t geteuid() { |
321 return 0; | 321 return 0; |
322 } | 322 } |
323 #endif | 323 #endif |
324 | 324 |
325 void silcgaim_show_public_key(SilcGaim sg, | 325 void silcpurple_show_public_key(SilcPurple sg, |
326 const char *name, SilcPublicKey public_key, | 326 const char *name, SilcPublicKey public_key, |
327 GCallback callback, void *context) | 327 GCallback callback, void *context) |
328 { | 328 { |
329 SilcPublicKeyIdentifier ident; | 329 SilcPublicKeyIdentifier ident; |
330 SilcPKCS pkcs; | 330 SilcPKCS pkcs; |
369 g_string_append_printf(s, _("Public Key Fingerprint:\n%s\n\n"), fingerprint); | 369 g_string_append_printf(s, _("Public Key Fingerprint:\n%s\n\n"), fingerprint); |
370 g_string_append_printf(s, _("Public Key Babbleprint:\n%s"), babbleprint); | 370 g_string_append_printf(s, _("Public Key Babbleprint:\n%s"), babbleprint); |
371 | 371 |
372 buf = g_string_free(s, FALSE); | 372 buf = g_string_free(s, FALSE); |
373 | 373 |
374 gaim_request_action(sg->gc, _("Public Key Information"), | 374 purple_request_action(sg->gc, _("Public Key Information"), |
375 _("Public Key Information"), | 375 _("Public Key Information"), |
376 buf, 0, context, 1, | 376 buf, 0, context, 1, |
377 _("Close"), callback); | 377 _("Close"), callback); |
378 | 378 |
379 g_free(buf); | 379 g_free(buf); |
382 silc_free(pk); | 382 silc_free(pk); |
383 silc_pkcs_free_identifier(ident); | 383 silc_pkcs_free_identifier(ident); |
384 } | 384 } |
385 | 385 |
386 SilcAttributePayload | 386 SilcAttributePayload |
387 silcgaim_get_attr(SilcDList attrs, SilcAttribute attribute) | 387 silcpurple_get_attr(SilcDList attrs, SilcAttribute attribute) |
388 { | 388 { |
389 SilcAttributePayload attr = NULL; | 389 SilcAttributePayload attr = NULL; |
390 | 390 |
391 if (!attrs) | 391 if (!attrs) |
392 return NULL; | 392 return NULL; |
397 break; | 397 break; |
398 | 398 |
399 return attr; | 399 return attr; |
400 } | 400 } |
401 | 401 |
402 void silcgaim_get_umode_string(SilcUInt32 mode, char *buf, | 402 void silcpurple_get_umode_string(SilcUInt32 mode, char *buf, |
403 SilcUInt32 buf_size) | 403 SilcUInt32 buf_size) |
404 { | 404 { |
405 memset(buf, 0, buf_size); | 405 memset(buf, 0, buf_size); |
406 if ((mode & SILC_UMODE_SERVER_OPERATOR) || | 406 if ((mode & SILC_UMODE_SERVER_OPERATOR) || |
407 (mode & SILC_UMODE_ROUTER_OPERATOR)) { | 407 (mode & SILC_UMODE_ROUTER_OPERATOR)) { |
432 strcat(buf, "[rejects watching] "); | 432 strcat(buf, "[rejects watching] "); |
433 if (mode & SILC_UMODE_BLOCK_INVITE) | 433 if (mode & SILC_UMODE_BLOCK_INVITE) |
434 strcat(buf, "[blocks invites] "); | 434 strcat(buf, "[blocks invites] "); |
435 } | 435 } |
436 | 436 |
437 void silcgaim_get_chmode_string(SilcUInt32 mode, char *buf, | 437 void silcpurple_get_chmode_string(SilcUInt32 mode, char *buf, |
438 SilcUInt32 buf_size) | 438 SilcUInt32 buf_size) |
439 { | 439 { |
440 memset(buf, 0, buf_size); | 440 memset(buf, 0, buf_size); |
441 if (mode & SILC_CHANNEL_MODE_FOUNDER_AUTH) | 441 if (mode & SILC_CHANNEL_MODE_FOUNDER_AUTH) |
442 strcat(buf, "[permanent] "); | 442 strcat(buf, "[permanent] "); |
462 strcat(buf, "[users silenced] "); | 462 strcat(buf, "[users silenced] "); |
463 if (mode & SILC_CHANNEL_MODE_SILENCE_OPERS) | 463 if (mode & SILC_CHANNEL_MODE_SILENCE_OPERS) |
464 strcat(buf, "[operators silenced] "); | 464 strcat(buf, "[operators silenced] "); |
465 } | 465 } |
466 | 466 |
467 void silcgaim_get_chumode_string(SilcUInt32 mode, char *buf, | 467 void silcpurple_get_chumode_string(SilcUInt32 mode, char *buf, |
468 SilcUInt32 buf_size) | 468 SilcUInt32 buf_size) |
469 { | 469 { |
470 memset(buf, 0, buf_size); | 470 memset(buf, 0, buf_size); |
471 if (mode & SILC_CHANNEL_UMODE_CHANFO) | 471 if (mode & SILC_CHANNEL_UMODE_CHANFO) |
472 strcat(buf, "[founder] "); | 472 strcat(buf, "[founder] "); |
481 if (mode & SILC_CHANNEL_UMODE_QUIET) | 481 if (mode & SILC_CHANNEL_UMODE_QUIET) |
482 strcat(buf, "[quieted] "); | 482 strcat(buf, "[quieted] "); |
483 } | 483 } |
484 | 484 |
485 void | 485 void |
486 silcgaim_parse_attrs(SilcDList attrs, char **moodstr, char **statusstr, | 486 silcpurple_parse_attrs(SilcDList attrs, char **moodstr, char **statusstr, |
487 char **contactstr, char **langstr, char **devicestr, | 487 char **contactstr, char **langstr, char **devicestr, |
488 char **tzstr, char **geostr) | 488 char **tzstr, char **geostr) |
489 { | 489 { |
490 SilcAttributePayload attr; | 490 SilcAttributePayload attr; |
491 SilcAttributeMood mood = 0; | 491 SilcAttributeMood mood = 0; |
506 | 506 |
507 if (!attrs) | 507 if (!attrs) |
508 return; | 508 return; |
509 | 509 |
510 s = g_string_new(""); | 510 s = g_string_new(""); |
511 attr = silcgaim_get_attr(attrs, SILC_ATTRIBUTE_STATUS_MOOD); | 511 attr = silcpurple_get_attr(attrs, SILC_ATTRIBUTE_STATUS_MOOD); |
512 if (attr && silc_attribute_get_object(attr, &mood, sizeof(mood))) { | 512 if (attr && silc_attribute_get_object(attr, &mood, sizeof(mood))) { |
513 if (mood & SILC_ATTRIBUTE_MOOD_HAPPY) | 513 if (mood & SILC_ATTRIBUTE_MOOD_HAPPY) |
514 g_string_append_printf(s, "[%s] ", _("Happy")); | 514 g_string_append_printf(s, "[%s] ", _("Happy")); |
515 if (mood & SILC_ATTRIBUTE_MOOD_SAD) | 515 if (mood & SILC_ATTRIBUTE_MOOD_SAD) |
516 g_string_append_printf(s, "[%s] ", _("Sad")); | 516 g_string_append_printf(s, "[%s] ", _("Sad")); |
537 *moodstr = s->str; | 537 *moodstr = s->str; |
538 g_string_free(s, FALSE); | 538 g_string_free(s, FALSE); |
539 } else | 539 } else |
540 g_string_free(s, TRUE); | 540 g_string_free(s, TRUE); |
541 | 541 |
542 attr = silcgaim_get_attr(attrs, SILC_ATTRIBUTE_STATUS_FREETEXT); | 542 attr = silcpurple_get_attr(attrs, SILC_ATTRIBUTE_STATUS_FREETEXT); |
543 memset(tmp, 0, sizeof(tmp)); | 543 memset(tmp, 0, sizeof(tmp)); |
544 if (attr && silc_attribute_get_object(attr, tmp, sizeof(tmp))) | 544 if (attr && silc_attribute_get_object(attr, tmp, sizeof(tmp))) |
545 *statusstr = g_strdup(tmp); | 545 *statusstr = g_strdup(tmp); |
546 | 546 |
547 s = g_string_new(""); | 547 s = g_string_new(""); |
548 attr = silcgaim_get_attr(attrs, SILC_ATTRIBUTE_PREFERRED_CONTACT); | 548 attr = silcpurple_get_attr(attrs, SILC_ATTRIBUTE_PREFERRED_CONTACT); |
549 if (attr && silc_attribute_get_object(attr, &contact, sizeof(contact))) { | 549 if (attr && silc_attribute_get_object(attr, &contact, sizeof(contact))) { |
550 if (contact & SILC_ATTRIBUTE_CONTACT_CHAT) | 550 if (contact & SILC_ATTRIBUTE_CONTACT_CHAT) |
551 g_string_append_printf(s, "[%s] ", _("Chat")); | 551 g_string_append_printf(s, "[%s] ", _("Chat")); |
552 if (contact & SILC_ATTRIBUTE_CONTACT_EMAIL) | 552 if (contact & SILC_ATTRIBUTE_CONTACT_EMAIL) |
553 g_string_append_printf(s, "[%s] ", _("E-Mail")); | 553 g_string_append_printf(s, "[%s] ", _("E-Mail")); |
566 *contactstr = s->str; | 566 *contactstr = s->str; |
567 g_string_free(s, FALSE); | 567 g_string_free(s, FALSE); |
568 } else | 568 } else |
569 g_string_free(s, TRUE); | 569 g_string_free(s, TRUE); |
570 | 570 |
571 attr = silcgaim_get_attr(attrs, SILC_ATTRIBUTE_PREFERRED_LANGUAGE); | 571 attr = silcpurple_get_attr(attrs, SILC_ATTRIBUTE_PREFERRED_LANGUAGE); |
572 memset(tmp, 0, sizeof(tmp)); | 572 memset(tmp, 0, sizeof(tmp)); |
573 if (attr && silc_attribute_get_object(attr, tmp, sizeof(tmp))) | 573 if (attr && silc_attribute_get_object(attr, tmp, sizeof(tmp))) |
574 *langstr = g_strdup(tmp); | 574 *langstr = g_strdup(tmp); |
575 | 575 |
576 s = g_string_new(""); | 576 s = g_string_new(""); |
577 attr = silcgaim_get_attr(attrs, SILC_ATTRIBUTE_DEVICE_INFO); | 577 attr = silcpurple_get_attr(attrs, SILC_ATTRIBUTE_DEVICE_INFO); |
578 memset(&device, 0, sizeof(device)); | 578 memset(&device, 0, sizeof(device)); |
579 if (attr && silc_attribute_get_object(attr, &device, sizeof(device))) { | 579 if (attr && silc_attribute_get_object(attr, &device, sizeof(device))) { |
580 if (device.type == SILC_ATTRIBUTE_DEVICE_COMPUTER) | 580 if (device.type == SILC_ATTRIBUTE_DEVICE_COMPUTER) |
581 g_string_append_printf(s, "%s: ", _("Computer")); | 581 g_string_append_printf(s, "%s: ", _("Computer")); |
582 if (device.type == SILC_ATTRIBUTE_DEVICE_MOBILE_PHONE) | 582 if (device.type == SILC_ATTRIBUTE_DEVICE_MOBILE_PHONE) |
595 *devicestr = s->str; | 595 *devicestr = s->str; |
596 g_string_free(s, FALSE); | 596 g_string_free(s, FALSE); |
597 } else | 597 } else |
598 g_string_free(s, TRUE); | 598 g_string_free(s, TRUE); |
599 | 599 |
600 attr = silcgaim_get_attr(attrs, SILC_ATTRIBUTE_TIMEZONE); | 600 attr = silcpurple_get_attr(attrs, SILC_ATTRIBUTE_TIMEZONE); |
601 memset(tmp, 0, sizeof(tmp)); | 601 memset(tmp, 0, sizeof(tmp)); |
602 if (attr && silc_attribute_get_object(attr, tmp, sizeof(tmp))) | 602 if (attr && silc_attribute_get_object(attr, tmp, sizeof(tmp))) |
603 *tzstr = g_strdup(tmp); | 603 *tzstr = g_strdup(tmp); |
604 | 604 |
605 attr = silcgaim_get_attr(attrs, SILC_ATTRIBUTE_GEOLOCATION); | 605 attr = silcpurple_get_attr(attrs, SILC_ATTRIBUTE_GEOLOCATION); |
606 memset(&geo, 0, sizeof(geo)); | 606 memset(&geo, 0, sizeof(geo)); |
607 if (attr && silc_attribute_get_object(attr, &geo, sizeof(geo))) | 607 if (attr && silc_attribute_get_object(attr, &geo, sizeof(geo))) |
608 *geostr = g_strdup_printf("%s %s %s (%s)", | 608 *geostr = g_strdup_printf("%s %s %s (%s)", |
609 geo.longitude ? geo.longitude : "", | 609 geo.longitude ? geo.longitude : "", |
610 geo.latitude ? geo.latitude : "", | 610 geo.latitude ? geo.latitude : "", |
613 } | 613 } |
614 | 614 |
615 #ifdef HAVE_SILCMIME_H | 615 #ifdef HAVE_SILCMIME_H |
616 /* Returns MIME type of filetype */ | 616 /* Returns MIME type of filetype */ |
617 | 617 |
618 char *silcgaim_file2mime(const char *filename) | 618 char *silcpurple_file2mime(const char *filename) |
619 { | 619 { |
620 const char *ct; | 620 const char *ct; |
621 | 621 |
622 ct = strrchr(filename, '.'); | 622 ct = strrchr(filename, '.'); |
623 if (!ct) | 623 if (!ct) |
639 /* Checks if message has images, and assembles MIME message if it has. | 639 /* Checks if message has images, and assembles MIME message if it has. |
640 If only one image is present, creates simple MIME image message. If | 640 If only one image is present, creates simple MIME image message. If |
641 there are multiple images and/or text with images multipart MIME | 641 there are multiple images and/or text with images multipart MIME |
642 message is created. */ | 642 message is created. */ |
643 | 643 |
644 SilcDList silcgaim_image_message(const char *msg, SilcUInt32 *mflags) | 644 SilcDList silcpurple_image_message(const char *msg, SilcUInt32 *mflags) |
645 { | 645 { |
646 SilcMime mime = NULL, p; | 646 SilcMime mime = NULL, p; |
647 SilcDList list, parts = NULL; | 647 SilcDList list, parts = NULL; |
648 const char *start, *end, *last; | 648 const char *start, *end, *last; |
649 GData *attribs; | 649 GData *attribs; |
650 char *type; | 650 char *type; |
651 gboolean images = FALSE; | 651 gboolean images = FALSE; |
652 | 652 |
653 last = msg; | 653 last = msg; |
654 while (last && *last && gaim_markup_find_tag("img", last, &start, | 654 while (last && *last && purple_markup_find_tag("img", last, &start, |
655 &end, &attribs)) { | 655 &end, &attribs)) { |
656 GaimStoredImage *image = NULL; | 656 PurpleStoredImage *image = NULL; |
657 const char *id; | 657 const char *id; |
658 | 658 |
659 /* Check if there is text before image */ | 659 /* Check if there is text before image */ |
660 if (start - last) { | 660 if (start - last) { |
661 char *text, *tmp; | 661 char *text, *tmp; |
664 /* Add content type */ | 664 /* Add content type */ |
665 silc_mime_add_field(p, "Content-Type", | 665 silc_mime_add_field(p, "Content-Type", |
666 "text/plain; charset=utf-8"); | 666 "text/plain; charset=utf-8"); |
667 | 667 |
668 tmp = g_strndup(last, start - last); | 668 tmp = g_strndup(last, start - last); |
669 text = gaim_unescape_html(tmp); | 669 text = purple_unescape_html(tmp); |
670 g_free(tmp); | 670 g_free(tmp); |
671 /* Add text */ | 671 /* Add text */ |
672 silc_mime_add_data(p, text, strlen(text)); | 672 silc_mime_add_data(p, text, strlen(text)); |
673 g_free(text); | 673 g_free(text); |
674 | 674 |
676 parts = silc_dlist_init(); | 676 parts = silc_dlist_init(); |
677 silc_dlist_add(parts, p); | 677 silc_dlist_add(parts, p); |
678 } | 678 } |
679 | 679 |
680 id = g_datalist_get_data(&attribs, "id"); | 680 id = g_datalist_get_data(&attribs, "id"); |
681 if (id && (image = gaim_imgstore_get(atoi(id)))) { | 681 if (id && (image = purple_imgstore_get(atoi(id)))) { |
682 unsigned long imglen = gaim_imgstore_get_size(image); | 682 unsigned long imglen = purple_imgstore_get_size(image); |
683 gpointer img = gaim_imgstore_get_data(image); | 683 gpointer img = purple_imgstore_get_data(image); |
684 | 684 |
685 p = silc_mime_alloc(); | 685 p = silc_mime_alloc(); |
686 | 686 |
687 /* Add content type */ | 687 /* Add content type */ |
688 type = silcgaim_file2mime(gaim_imgstore_get_filename(image)); | 688 type = silcpurple_file2mime(purple_imgstore_get_filename(image)); |
689 if (!type) { | 689 if (!type) { |
690 g_datalist_clear(&attribs); | 690 g_datalist_clear(&attribs); |
691 last = end + 1; | 691 last = end + 1; |
692 continue; | 692 continue; |
693 } | 693 } |
712 last = end + 1; | 712 last = end + 1; |
713 } | 713 } |
714 | 714 |
715 /* Check for text after the image(s) */ | 715 /* Check for text after the image(s) */ |
716 if (images && last && *last) { | 716 if (images && last && *last) { |
717 char *tmp = gaim_unescape_html(last); | 717 char *tmp = purple_unescape_html(last); |
718 p = silc_mime_alloc(); | 718 p = silc_mime_alloc(); |
719 | 719 |
720 /* Add content type */ | 720 /* Add content type */ |
721 silc_mime_add_field(p, "Content-Type", | 721 silc_mime_add_field(p, "Content-Type", |
722 "text/plain; charset=utf-8"); | 722 "text/plain; charset=utf-8"); |