Tue, 10 Sep 2013 21:47:37 +0200
Request API refactoring: switch purple_request_action to PurpleRequestCommonParameters
| 8849 | 1 | /* |
| 2 | ||
| 15884 | 3 | silcpurple_util.c |
| 8849 | 4 | |
| 5 | Author: Pekka Riikonen <priikone@silcnet.org> | |
| 6 | ||
|
17675
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
17156
diff
changeset
|
7 | Copyright (C) 2004 - 2007 Pekka Riikonen |
| 8849 | 8 | |
| 9 | This program is free software; you can redistribute it and/or modify | |
| 10 | it under the terms of the GNU General Public License as published by | |
| 11 | the Free Software Foundation; version 2 of the License. | |
| 12 | ||
| 13 | This program is distributed in the hope that it will be useful, | |
| 14 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
| 16 | GNU General Public License for more details. | |
| 17 | ||
| 18 | */ | |
| 19 | ||
|
28981
4e3922ab4844
Include 'internal.h' before all other headers to make some non-gcc compilers happy.
Paul Aurich <darkrain42@pidgin.im>
parents:
27635
diff
changeset
|
20 | #include "internal.h" |
|
17675
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
17156
diff
changeset
|
21 | #include "silc.h" |
| 8849 | 22 | #include "silcclient.h" |
| 15884 | 23 | #include "silcpurple.h" |
|
12217
ea610d8ab584
[gaim-migrate @ 14519]
Pekka Riikonen <priikone@silcnet.org>
parents:
11488
diff
changeset
|
24 | #include "imgstore.h" |
| 8849 | 25 | |
| 26 | /**************************** Utility Routines *******************************/ | |
| 27 | ||
| 28 | static char str[256], str2[256]; | |
| 29 | ||
| 15884 | 30 | const char *silcpurple_silcdir(void) |
| 8849 | 31 | { |
| 15884 | 32 | const char *hd = purple_home_dir(); |
| 8849 | 33 | memset(str, 0, sizeof(str)); |
| 34 | g_snprintf(str, sizeof(str) - 1, "%s" G_DIR_SEPARATOR_S ".silc", hd ? hd : "/tmp"); | |
| 35 | return (const char *)str; | |
| 36 | } | |
| 37 | ||
| 15884 | 38 | const char *silcpurple_session_file(const char *account) |
| 8849 | 39 | { |
| 40 | memset(str2, 0, sizeof(str2)); | |
| 41 | g_snprintf(str2, sizeof(str2) - 1, "%s" G_DIR_SEPARATOR_S "%s_session", | |
| 15884 | 42 | silcpurple_silcdir(), account); |
| 8849 | 43 | return (const char *)str2; |
| 44 | } | |
| 45 | ||
| 15884 | 46 | gboolean silcpurple_ip_is_private(const char *ip) |
| 8849 | 47 | { |
| 48 | if (silc_net_is_ip4(ip)) { | |
| 49 | if (!strncmp(ip, "10.", 3)) { | |
| 50 | return TRUE; | |
| 51 | } else if (!strncmp(ip, "172.", 4) && strlen(ip) > 6) { | |
| 52 | char tmp[3]; | |
| 8910 | 53 | int s; |
| 8849 | 54 | memset(tmp, 0, sizeof(tmp)); |
| 55 | strncpy(tmp, ip + 4, 2); | |
| 8910 | 56 | s = atoi(tmp); |
| 8849 | 57 | if (s >= 16 && s <= 31) |
| 58 | return TRUE; | |
| 59 | } else if (!strncmp(ip, "192.168.", 8)) { | |
| 60 | return TRUE; | |
| 61 | } | |
| 62 | } | |
| 63 | ||
| 64 | return FALSE; | |
| 65 | } | |
| 66 | ||
|
33940
b44d15793c83
Use GStatBuf instead of struct stat
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33811
diff
changeset
|
67 | /* there is no fstat alternative for GStatBuf */ |
|
b44d15793c83
Use GStatBuf instead of struct stat
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33811
diff
changeset
|
68 | static int g_fstat(int fd, GStatBuf *st) |
|
b44d15793c83
Use GStatBuf instead of struct stat
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33811
diff
changeset
|
69 | { |
|
b44d15793c83
Use GStatBuf instead of struct stat
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33811
diff
changeset
|
70 | struct stat sst; |
|
b44d15793c83
Use GStatBuf instead of struct stat
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33811
diff
changeset
|
71 | int ret; |
|
b44d15793c83
Use GStatBuf instead of struct stat
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33811
diff
changeset
|
72 | |
|
b44d15793c83
Use GStatBuf instead of struct stat
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33811
diff
changeset
|
73 | g_return_val_if_fail(st != NULL, -1); |
|
b44d15793c83
Use GStatBuf instead of struct stat
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33811
diff
changeset
|
74 | |
|
b44d15793c83
Use GStatBuf instead of struct stat
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33811
diff
changeset
|
75 | ret = fstat(fd, &sst); |
|
b44d15793c83
Use GStatBuf instead of struct stat
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33811
diff
changeset
|
76 | if (ret != 0) |
|
b44d15793c83
Use GStatBuf instead of struct stat
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33811
diff
changeset
|
77 | return ret; |
|
b44d15793c83
Use GStatBuf instead of struct stat
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33811
diff
changeset
|
78 | |
|
b44d15793c83
Use GStatBuf instead of struct stat
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33811
diff
changeset
|
79 | memset(st, 0, sizeof(GStatBuf)); |
|
b44d15793c83
Use GStatBuf instead of struct stat
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33811
diff
changeset
|
80 | /* only these two are used here */ |
|
b44d15793c83
Use GStatBuf instead of struct stat
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33811
diff
changeset
|
81 | st->st_uid = sst.st_uid; |
|
b44d15793c83
Use GStatBuf instead of struct stat
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33811
diff
changeset
|
82 | st->st_mode = sst.st_mode; |
|
b44d15793c83
Use GStatBuf instead of struct stat
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33811
diff
changeset
|
83 | |
|
b44d15793c83
Use GStatBuf instead of struct stat
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33811
diff
changeset
|
84 | return 0; |
|
b44d15793c83
Use GStatBuf instead of struct stat
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33811
diff
changeset
|
85 | } |
|
b44d15793c83
Use GStatBuf instead of struct stat
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33811
diff
changeset
|
86 | |
| 8849 | 87 | /* This checks stats for various SILC files and directories. First it |
| 88 | checks if ~/.silc directory exist and is owned by the correct user. If | |
| 89 | it doesn't exist, it will create the directory. After that it checks if | |
| 90 | user's Public and Private key files exists and creates them if needed. */ | |
| 91 | ||
| 15884 | 92 | gboolean silcpurple_check_silc_dir(PurpleConnection *gc) |
| 8849 | 93 | { |
| 94 | char filename[256], file_public_key[256], file_private_key[256]; | |
| 95 | char servfilename[256], clientfilename[256], friendsfilename[256]; | |
|
10825
986d260851e8
[gaim-migrate @ 12490]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
10751
diff
changeset
|
96 | char pkd[256], prd[256]; |
|
33940
b44d15793c83
Use GStatBuf instead of struct stat
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33811
diff
changeset
|
97 | GStatBuf st; |
| 8849 | 98 | struct passwd *pw; |
|
13660
3ade3ab0b2ae
[gaim-migrate @ 16061]
Mark Doliner <markdoliner@pidgin.im>
parents:
13546
diff
changeset
|
99 | int fd; |
| 8849 | 100 | |
| 101 | pw = getpwuid(getuid()); | |
| 102 | if (!pw) { | |
|
21389
e1dd8142bb87
replace most calls to strerror with calls to g_strerror. strerror will return
Nathan Walp <nwalp@pidgin.im>
parents:
20289
diff
changeset
|
103 | purple_debug_error("silc", "silc: %s\n", g_strerror(errno)); |
| 8849 | 104 | return FALSE; |
| 105 | } | |
| 106 | ||
| 15884 | 107 | g_snprintf(filename, sizeof(filename) - 1, "%s", silcpurple_silcdir()); |
| 8849 | 108 | g_snprintf(servfilename, sizeof(servfilename) - 1, "%s" G_DIR_SEPARATOR_S "serverkeys", |
| 15884 | 109 | silcpurple_silcdir()); |
| 8849 | 110 | g_snprintf(clientfilename, sizeof(clientfilename) - 1, "%s" G_DIR_SEPARATOR_S "clientkeys", |
| 15884 | 111 | silcpurple_silcdir()); |
| 8849 | 112 | g_snprintf(friendsfilename, sizeof(friendsfilename) - 1, "%s" G_DIR_SEPARATOR_S "friends", |
| 15884 | 113 | silcpurple_silcdir()); |
| 8849 | 114 | |
| 115 | /* | |
| 116 | * Check ~/.silc directory | |
| 117 | */ | |
|
10589
4e10236e06d4
[gaim-migrate @ 11994]
Daniel Atallah <datallah@pidgin.im>
parents:
9488
diff
changeset
|
118 | if ((g_stat(filename, &st)) == -1) { |
| 8849 | 119 | /* If dir doesn't exist */ |
| 120 | if (errno == ENOENT) { | |
| 121 | if (pw->pw_uid == geteuid()) { | |
|
10589
4e10236e06d4
[gaim-migrate @ 11994]
Daniel Atallah <datallah@pidgin.im>
parents:
9488
diff
changeset
|
122 | if ((g_mkdir(filename, 0755)) == -1) { |
| 15884 | 123 | purple_debug_error("silc", "Couldn't create '%s' directory\n", filename); |
| 8849 | 124 | return FALSE; |
| 125 | } | |
| 126 | } else { | |
| 15884 | 127 | purple_debug_error("silc", "Couldn't create '%s' directory due to a wrong uid!\n", |
| 8849 | 128 | filename); |
| 129 | return FALSE; | |
| 130 | } | |
| 131 | } else { | |
|
21389
e1dd8142bb87
replace most calls to strerror with calls to g_strerror. strerror will return
Nathan Walp <nwalp@pidgin.im>
parents:
20289
diff
changeset
|
132 | purple_debug_error("silc", "Couldn't stat '%s' directory, error: %s\n", filename, g_strerror(errno)); |
| 8849 | 133 | return FALSE; |
| 134 | } | |
| 135 | } else { | |
|
9353
ff6546387358
[gaim-migrate @ 10161]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
9274
diff
changeset
|
136 | #ifndef _WIN32 |
| 8849 | 137 | /* Check the owner of the dir */ |
| 138 | if (st.st_uid != 0 && st.st_uid != pw->pw_uid) { | |
| 15884 | 139 | purple_debug_error("silc", "You don't seem to own '%s' directory\n", |
| 8849 | 140 | filename); |
| 141 | return FALSE; | |
| 142 | } | |
|
9353
ff6546387358
[gaim-migrate @ 10161]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
9274
diff
changeset
|
143 | #endif |
| 8849 | 144 | } |
| 145 | ||
| 146 | /* | |
| 147 | * Check ~./silc/serverkeys directory | |
| 148 | */ | |
|
10589
4e10236e06d4
[gaim-migrate @ 11994]
Daniel Atallah <datallah@pidgin.im>
parents:
9488
diff
changeset
|
149 | if ((g_stat(servfilename, &st)) == -1) { |
| 8849 | 150 | /* If dir doesn't exist */ |
| 151 | if (errno == ENOENT) { | |
| 152 | if (pw->pw_uid == geteuid()) { | |
|
10589
4e10236e06d4
[gaim-migrate @ 11994]
Daniel Atallah <datallah@pidgin.im>
parents:
9488
diff
changeset
|
153 | if ((g_mkdir(servfilename, 0755)) == -1) { |
| 15884 | 154 | purple_debug_error("silc", "Couldn't create '%s' directory\n", servfilename); |
| 8849 | 155 | return FALSE; |
| 156 | } | |
| 157 | } else { | |
| 15884 | 158 | purple_debug_error("silc", "Couldn't create '%s' directory due to a wrong uid!\n", |
| 8849 | 159 | servfilename); |
| 160 | return FALSE; | |
| 161 | } | |
| 162 | } else { | |
| 15884 | 163 | purple_debug_error("silc", "Couldn't stat '%s' directory, error: %s\n", |
|
21389
e1dd8142bb87
replace most calls to strerror with calls to g_strerror. strerror will return
Nathan Walp <nwalp@pidgin.im>
parents:
20289
diff
changeset
|
164 | servfilename, g_strerror(errno)); |
| 8849 | 165 | return FALSE; |
| 166 | } | |
| 167 | } | |
| 168 | ||
| 169 | /* | |
| 170 | * Check ~./silc/clientkeys directory | |
| 171 | */ | |
|
10589
4e10236e06d4
[gaim-migrate @ 11994]
Daniel Atallah <datallah@pidgin.im>
parents:
9488
diff
changeset
|
172 | if ((g_stat(clientfilename, &st)) == -1) { |
| 8849 | 173 | /* If dir doesn't exist */ |
| 174 | if (errno == ENOENT) { | |
| 175 | if (pw->pw_uid == geteuid()) { | |
|
10589
4e10236e06d4
[gaim-migrate @ 11994]
Daniel Atallah <datallah@pidgin.im>
parents:
9488
diff
changeset
|
176 | if ((g_mkdir(clientfilename, 0755)) == -1) { |
| 15884 | 177 | purple_debug_error("silc", "Couldn't create '%s' directory\n", clientfilename); |
| 8849 | 178 | return FALSE; |
| 179 | } | |
| 180 | } else { | |
| 15884 | 181 | purple_debug_error("silc", "Couldn't create '%s' directory due to a wrong uid!\n", |
| 8849 | 182 | clientfilename); |
| 183 | return FALSE; | |
| 184 | } | |
| 185 | } else { | |
| 15884 | 186 | purple_debug_error("silc", "Couldn't stat '%s' directory, error: %s\n", |
|
21389
e1dd8142bb87
replace most calls to strerror with calls to g_strerror. strerror will return
Nathan Walp <nwalp@pidgin.im>
parents:
20289
diff
changeset
|
187 | clientfilename, g_strerror(errno)); |
| 8849 | 188 | return FALSE; |
| 189 | } | |
| 190 | } | |
| 191 | ||
| 192 | /* | |
| 193 | * Check ~./silc/friends directory | |
| 194 | */ | |
|
10589
4e10236e06d4
[gaim-migrate @ 11994]
Daniel Atallah <datallah@pidgin.im>
parents:
9488
diff
changeset
|
195 | if ((g_stat(friendsfilename, &st)) == -1) { |
| 8849 | 196 | /* If dir doesn't exist */ |
| 197 | if (errno == ENOENT) { | |
| 198 | if (pw->pw_uid == geteuid()) { | |
|
10589
4e10236e06d4
[gaim-migrate @ 11994]
Daniel Atallah <datallah@pidgin.im>
parents:
9488
diff
changeset
|
199 | if ((g_mkdir(friendsfilename, 0755)) == -1) { |
| 15884 | 200 | purple_debug_error("silc", "Couldn't create '%s' directory\n", friendsfilename); |
| 8849 | 201 | return FALSE; |
| 202 | } | |
| 203 | } else { | |
| 15884 | 204 | purple_debug_error("silc", "Couldn't create '%s' directory due to a wrong uid!\n", |
| 8849 | 205 | friendsfilename); |
| 206 | return FALSE; | |
| 207 | } | |
| 208 | } else { | |
| 15884 | 209 | purple_debug_error("silc", "Couldn't stat '%s' directory, error: %s\n", |
|
21389
e1dd8142bb87
replace most calls to strerror with calls to g_strerror. strerror will return
Nathan Walp <nwalp@pidgin.im>
parents:
20289
diff
changeset
|
210 | friendsfilename, g_strerror(errno)); |
| 8849 | 211 | return FALSE; |
| 212 | } | |
| 213 | } | |
| 214 | ||
| 215 | /* | |
| 216 | * Check Public and Private keys | |
| 217 | */ | |
| 15884 | 218 | g_snprintf(pkd, sizeof(pkd), "%s" G_DIR_SEPARATOR_S "public_key.pub", silcpurple_silcdir()); |
| 219 | g_snprintf(prd, sizeof(prd), "%s" G_DIR_SEPARATOR_S "private_key.prv", silcpurple_silcdir()); | |
| 8849 | 220 | g_snprintf(file_public_key, sizeof(file_public_key) - 1, "%s", |
|
32678
01f6312a4a7b
On the way to hiding the PurpleConnection struct.
Andrew Victor <andrew.victor@mxit.com>
parents:
32157
diff
changeset
|
221 | purple_account_get_string(purple_connection_get_account(gc), "public-key", pkd)); |
| 8849 | 222 | g_snprintf(file_private_key, sizeof(file_public_key) - 1, "%s", |
|
32678
01f6312a4a7b
On the way to hiding the PurpleConnection struct.
Andrew Victor <andrew.victor@mxit.com>
parents:
32157
diff
changeset
|
223 | purple_account_get_string(purple_connection_get_account(gc), "private-key", prd)); |
| 8849 | 224 | |
|
10589
4e10236e06d4
[gaim-migrate @ 11994]
Daniel Atallah <datallah@pidgin.im>
parents:
9488
diff
changeset
|
225 | if ((g_stat(file_public_key, &st)) == -1) { |
| 8849 | 226 | /* If file doesn't exist */ |
| 227 | if (errno == ENOENT) { | |
| 15884 | 228 | purple_connection_update_progress(gc, _("Creating SILC key pair..."), 1, 5); |
| 229 | if (!silc_create_key_pair(SILCPURPLE_DEF_PKCS, | |
|
17675
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
17156
diff
changeset
|
230 | SILCPURPLE_DEF_PKCS_LEN, |
|
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
17156
diff
changeset
|
231 | file_public_key, |
|
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
17156
diff
changeset
|
232 | file_private_key, NULL, |
|
32683
5376a35d461a
Samtime: Move the "inpa" input watcher into protocol_data.
Andrew Victor <andrew.victor@mxit.com>
parents:
32678
diff
changeset
|
233 | (purple_connection_get_password(gc) == NULL) ? "" : purple_connection_get_password(gc), |
|
17675
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
17156
diff
changeset
|
234 | NULL, NULL, FALSE)) { |
|
32157
39ba2e2492ee
Rename purple_connection_error_reason to purple_connection_error
Mark Doliner <markdoliner@pidgin.im>
parents:
28981
diff
changeset
|
235 | purple_connection_error(gc, PURPLE_CONNECTION_ERROR_OTHER_ERROR, |
|
27635
0cd19038c417
More uniformity among disconnect error messages
Mark Doliner <markdoliner@pidgin.im>
parents:
23325
diff
changeset
|
236 | _("Unable to create SILC key pair")); |
|
14148
2f0c6fcb0db5
[gaim-migrate @ 16709]
Daniel Atallah <datallah@pidgin.im>
parents:
13660
diff
changeset
|
237 | return FALSE; |
|
2f0c6fcb0db5
[gaim-migrate @ 16709]
Daniel Atallah <datallah@pidgin.im>
parents:
13660
diff
changeset
|
238 | } |
|
2f0c6fcb0db5
[gaim-migrate @ 16709]
Daniel Atallah <datallah@pidgin.im>
parents:
13660
diff
changeset
|
239 | |
|
2f0c6fcb0db5
[gaim-migrate @ 16709]
Daniel Atallah <datallah@pidgin.im>
parents:
13660
diff
changeset
|
240 | if ((g_stat(file_public_key, &st)) == -1) { |
| 15884 | 241 | purple_debug_error("silc", "Couldn't stat '%s' public key, error: %s\n", |
|
21389
e1dd8142bb87
replace most calls to strerror with calls to g_strerror. strerror will return
Nathan Walp <nwalp@pidgin.im>
parents:
20289
diff
changeset
|
242 | file_public_key, g_strerror(errno)); |
|
14148
2f0c6fcb0db5
[gaim-migrate @ 16709]
Daniel Atallah <datallah@pidgin.im>
parents:
13660
diff
changeset
|
243 | return FALSE; |
|
2f0c6fcb0db5
[gaim-migrate @ 16709]
Daniel Atallah <datallah@pidgin.im>
parents:
13660
diff
changeset
|
244 | } |
| 8849 | 245 | } else { |
| 15884 | 246 | purple_debug_error("silc", "Couldn't stat '%s' public key, error: %s\n", |
|
21389
e1dd8142bb87
replace most calls to strerror with calls to g_strerror. strerror will return
Nathan Walp <nwalp@pidgin.im>
parents:
20289
diff
changeset
|
247 | file_public_key, g_strerror(errno)); |
| 8849 | 248 | return FALSE; |
| 249 | } | |
| 250 | } | |
| 251 | ||
|
9353
ff6546387358
[gaim-migrate @ 10161]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
9274
diff
changeset
|
252 | #ifndef _WIN32 |
| 8849 | 253 | /* Check the owner of the public key */ |
| 254 | if (st.st_uid != 0 && st.st_uid != pw->pw_uid) { | |
| 15884 | 255 | purple_debug_error("silc", "You don't seem to own your public key!?\n"); |
| 8849 | 256 | return FALSE; |
| 257 | } | |
|
9353
ff6546387358
[gaim-migrate @ 10161]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
9274
diff
changeset
|
258 | #endif |
| 8849 | 259 | |
|
14227
e760c7dd2e7a
[gaim-migrate @ 16815]
Daniel Atallah <datallah@pidgin.im>
parents:
14218
diff
changeset
|
260 | if ((fd = g_open(file_private_key, O_RDONLY, 0)) != -1) { |
|
33940
b44d15793c83
Use GStatBuf instead of struct stat
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33811
diff
changeset
|
261 | if ((g_fstat(fd, &st)) == -1) { |
| 15884 | 262 | purple_debug_error("silc", "Couldn't stat '%s' private key, error: %s\n", |
|
21389
e1dd8142bb87
replace most calls to strerror with calls to g_strerror. strerror will return
Nathan Walp <nwalp@pidgin.im>
parents:
20289
diff
changeset
|
263 | file_private_key, g_strerror(errno)); |
|
14218
c498aba6235f
[gaim-migrate @ 16801]
Daniel Atallah <datallah@pidgin.im>
parents:
14148
diff
changeset
|
264 | close(fd); |
|
c498aba6235f
[gaim-migrate @ 16801]
Daniel Atallah <datallah@pidgin.im>
parents:
14148
diff
changeset
|
265 | return FALSE; |
|
c498aba6235f
[gaim-migrate @ 16801]
Daniel Atallah <datallah@pidgin.im>
parents:
14148
diff
changeset
|
266 | } |
|
c498aba6235f
[gaim-migrate @ 16801]
Daniel Atallah <datallah@pidgin.im>
parents:
14148
diff
changeset
|
267 | } else if ((g_stat(file_private_key, &st)) == -1) { |
| 8849 | 268 | /* If file doesn't exist */ |
| 269 | if (errno == ENOENT) { | |
| 15884 | 270 | purple_connection_update_progress(gc, _("Creating SILC key pair..."), 1, 5); |
| 271 | if (!silc_create_key_pair(SILCPURPLE_DEF_PKCS, | |
|
17675
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
17156
diff
changeset
|
272 | SILCPURPLE_DEF_PKCS_LEN, |
|
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
17156
diff
changeset
|
273 | file_public_key, |
|
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
17156
diff
changeset
|
274 | file_private_key, NULL, |
|
32683
5376a35d461a
Samtime: Move the "inpa" input watcher into protocol_data.
Andrew Victor <andrew.victor@mxit.com>
parents:
32678
diff
changeset
|
275 | (purple_connection_get_password(gc) == NULL) ? "" : purple_connection_get_password(gc), |
|
17675
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
17156
diff
changeset
|
276 | NULL, NULL, FALSE)) { |
|
32157
39ba2e2492ee
Rename purple_connection_error_reason to purple_connection_error
Mark Doliner <markdoliner@pidgin.im>
parents:
28981
diff
changeset
|
277 | purple_connection_error(gc, PURPLE_CONNECTION_ERROR_OTHER_ERROR, |
|
27635
0cd19038c417
More uniformity among disconnect error messages
Mark Doliner <markdoliner@pidgin.im>
parents:
23325
diff
changeset
|
278 | _("Unable to create SILC key pair")); |
|
14218
c498aba6235f
[gaim-migrate @ 16801]
Daniel Atallah <datallah@pidgin.im>
parents:
14148
diff
changeset
|
279 | return FALSE; |
|
c498aba6235f
[gaim-migrate @ 16801]
Daniel Atallah <datallah@pidgin.im>
parents:
14148
diff
changeset
|
280 | } |
|
c498aba6235f
[gaim-migrate @ 16801]
Daniel Atallah <datallah@pidgin.im>
parents:
14148
diff
changeset
|
281 | |
|
14227
e760c7dd2e7a
[gaim-migrate @ 16815]
Daniel Atallah <datallah@pidgin.im>
parents:
14218
diff
changeset
|
282 | if ((fd = g_open(file_private_key, O_RDONLY, 0)) != -1) { |
|
33940
b44d15793c83
Use GStatBuf instead of struct stat
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33811
diff
changeset
|
283 | if ((g_fstat(fd, &st)) == -1) { |
| 15884 | 284 | purple_debug_error("silc", "Couldn't stat '%s' private key, error: %s\n", |
|
21389
e1dd8142bb87
replace most calls to strerror with calls to g_strerror. strerror will return
Nathan Walp <nwalp@pidgin.im>
parents:
20289
diff
changeset
|
285 | file_private_key, g_strerror(errno)); |
|
14218
c498aba6235f
[gaim-migrate @ 16801]
Daniel Atallah <datallah@pidgin.im>
parents:
14148
diff
changeset
|
286 | close(fd); |
|
c498aba6235f
[gaim-migrate @ 16801]
Daniel Atallah <datallah@pidgin.im>
parents:
14148
diff
changeset
|
287 | return FALSE; |
|
c498aba6235f
[gaim-migrate @ 16801]
Daniel Atallah <datallah@pidgin.im>
parents:
14148
diff
changeset
|
288 | } |
|
c498aba6235f
[gaim-migrate @ 16801]
Daniel Atallah <datallah@pidgin.im>
parents:
14148
diff
changeset
|
289 | } |
|
c498aba6235f
[gaim-migrate @ 16801]
Daniel Atallah <datallah@pidgin.im>
parents:
14148
diff
changeset
|
290 | /* This shouldn't really happen because silc_create_key_pair() |
|
c498aba6235f
[gaim-migrate @ 16801]
Daniel Atallah <datallah@pidgin.im>
parents:
14148
diff
changeset
|
291 | * will set the permissions */ |
|
c498aba6235f
[gaim-migrate @ 16801]
Daniel Atallah <datallah@pidgin.im>
parents:
14148
diff
changeset
|
292 | else if ((g_stat(file_private_key, &st)) == -1) { |
| 15884 | 293 | purple_debug_error("silc", "Couldn't stat '%s' private key, error: %s\n", |
|
21389
e1dd8142bb87
replace most calls to strerror with calls to g_strerror. strerror will return
Nathan Walp <nwalp@pidgin.im>
parents:
20289
diff
changeset
|
294 | file_private_key, g_strerror(errno)); |
|
14218
c498aba6235f
[gaim-migrate @ 16801]
Daniel Atallah <datallah@pidgin.im>
parents:
14148
diff
changeset
|
295 | return FALSE; |
|
c498aba6235f
[gaim-migrate @ 16801]
Daniel Atallah <datallah@pidgin.im>
parents:
14148
diff
changeset
|
296 | } |
| 8849 | 297 | } else { |
| 15884 | 298 | purple_debug_error("silc", "Couldn't stat '%s' private key, error: %s\n", |
|
21389
e1dd8142bb87
replace most calls to strerror with calls to g_strerror. strerror will return
Nathan Walp <nwalp@pidgin.im>
parents:
20289
diff
changeset
|
299 | file_private_key, g_strerror(errno)); |
| 8849 | 300 | return FALSE; |
| 301 | } | |
| 302 | } | |
| 303 | ||
|
9353
ff6546387358
[gaim-migrate @ 10161]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
9274
diff
changeset
|
304 | #ifndef _WIN32 |
| 8849 | 305 | /* Check the owner of the private key */ |
| 306 | if (st.st_uid != 0 && st.st_uid != pw->pw_uid) { | |
| 15884 | 307 | purple_debug_error("silc", "You don't seem to own your private key!?\n"); |
|
13660
3ade3ab0b2ae
[gaim-migrate @ 16061]
Mark Doliner <markdoliner@pidgin.im>
parents:
13546
diff
changeset
|
308 | if (fd != -1) |
|
3ade3ab0b2ae
[gaim-migrate @ 16061]
Mark Doliner <markdoliner@pidgin.im>
parents:
13546
diff
changeset
|
309 | close(fd); |
| 8849 | 310 | return FALSE; |
| 311 | } | |
| 312 | ||
| 313 | /* Check the permissions for the private key */ | |
| 314 | if ((st.st_mode & 0777) != 0600) { | |
| 15884 | 315 | purple_debug_warning("silc", "Wrong permissions in your private key file `%s'!\n" |
|
13660
3ade3ab0b2ae
[gaim-migrate @ 16061]
Mark Doliner <markdoliner@pidgin.im>
parents:
13546
diff
changeset
|
316 | "Trying to change them ...\n", file_private_key); |
|
14218
c498aba6235f
[gaim-migrate @ 16801]
Daniel Atallah <datallah@pidgin.im>
parents:
14148
diff
changeset
|
317 | if ((fd == -1) || (fchmod(fd, S_IRUSR | S_IWUSR)) == -1) { |
| 15884 | 318 | purple_debug_error("silc", |
| 8849 | 319 | "Failed to change permissions for private key file!\n" |
| 320 | "Permissions for your private key file must be 0600.\n"); | |
|
13660
3ade3ab0b2ae
[gaim-migrate @ 16061]
Mark Doliner <markdoliner@pidgin.im>
parents:
13546
diff
changeset
|
321 | if (fd != -1) |
|
3ade3ab0b2ae
[gaim-migrate @ 16061]
Mark Doliner <markdoliner@pidgin.im>
parents:
13546
diff
changeset
|
322 | close(fd); |
| 8849 | 323 | return FALSE; |
| 324 | } | |
| 15884 | 325 | purple_debug_warning("silc", "Done.\n\n"); |
| 8849 | 326 | } |
|
9353
ff6546387358
[gaim-migrate @ 10161]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
9274
diff
changeset
|
327 | #endif |
| 8849 | 328 | |
|
13660
3ade3ab0b2ae
[gaim-migrate @ 16061]
Mark Doliner <markdoliner@pidgin.im>
parents:
13546
diff
changeset
|
329 | if (fd != -1) |
|
3ade3ab0b2ae
[gaim-migrate @ 16061]
Mark Doliner <markdoliner@pidgin.im>
parents:
13546
diff
changeset
|
330 | close(fd); |
|
3ade3ab0b2ae
[gaim-migrate @ 16061]
Mark Doliner <markdoliner@pidgin.im>
parents:
13546
diff
changeset
|
331 | |
|
33692
4f72b9501fb2
util.c: Fix win32-only leak in silcpurple_check_silc_dir
Niels Thykier <niels@thykier.net>
parents:
32683
diff
changeset
|
332 | #ifdef _WIN32 |
|
4f72b9501fb2
util.c: Fix win32-only leak in silcpurple_check_silc_dir
Niels Thykier <niels@thykier.net>
parents:
32683
diff
changeset
|
333 | /* on win32, we calloc pw so pass it to free |
|
4f72b9501fb2
util.c: Fix win32-only leak in silcpurple_check_silc_dir
Niels Thykier <niels@thykier.net>
parents:
32683
diff
changeset
|
334 | * (see the getpwuid code below) |
|
4f72b9501fb2
util.c: Fix win32-only leak in silcpurple_check_silc_dir
Niels Thykier <niels@thykier.net>
parents:
32683
diff
changeset
|
335 | */ |
|
4f72b9501fb2
util.c: Fix win32-only leak in silcpurple_check_silc_dir
Niels Thykier <niels@thykier.net>
parents:
32683
diff
changeset
|
336 | free(pw); |
|
4f72b9501fb2
util.c: Fix win32-only leak in silcpurple_check_silc_dir
Niels Thykier <niels@thykier.net>
parents:
32683
diff
changeset
|
337 | #endif |
|
4f72b9501fb2
util.c: Fix win32-only leak in silcpurple_check_silc_dir
Niels Thykier <niels@thykier.net>
parents:
32683
diff
changeset
|
338 | |
| 8849 | 339 | return TRUE; |
| 340 | } | |
| 341 | ||
|
9353
ff6546387358
[gaim-migrate @ 10161]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
9274
diff
changeset
|
342 | #ifdef _WIN32 |
|
ff6546387358
[gaim-migrate @ 10161]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
9274
diff
changeset
|
343 | struct passwd *getpwuid(uid_t uid) { |
|
ff6546387358
[gaim-migrate @ 10161]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
9274
diff
changeset
|
344 | struct passwd *pwd = calloc(1, sizeof(struct passwd)); |
|
ff6546387358
[gaim-migrate @ 10161]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
9274
diff
changeset
|
345 | return pwd; |
|
ff6546387358
[gaim-migrate @ 10161]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
9274
diff
changeset
|
346 | } |
|
ff6546387358
[gaim-migrate @ 10161]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
9274
diff
changeset
|
347 | |
|
ff6546387358
[gaim-migrate @ 10161]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
9274
diff
changeset
|
348 | uid_t getuid() { |
|
ff6546387358
[gaim-migrate @ 10161]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
9274
diff
changeset
|
349 | return 0; |
|
ff6546387358
[gaim-migrate @ 10161]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
9274
diff
changeset
|
350 | } |
|
ff6546387358
[gaim-migrate @ 10161]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
9274
diff
changeset
|
351 | |
|
ff6546387358
[gaim-migrate @ 10161]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
9274
diff
changeset
|
352 | uid_t geteuid() { |
|
ff6546387358
[gaim-migrate @ 10161]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
9274
diff
changeset
|
353 | return 0; |
|
ff6546387358
[gaim-migrate @ 10161]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
9274
diff
changeset
|
354 | } |
|
ff6546387358
[gaim-migrate @ 10161]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
9274
diff
changeset
|
355 | #endif |
|
ff6546387358
[gaim-migrate @ 10161]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
9274
diff
changeset
|
356 | |
| 15884 | 357 | void silcpurple_show_public_key(SilcPurple sg, |
|
17675
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
17156
diff
changeset
|
358 | const char *name, SilcPublicKey public_key, |
|
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
17156
diff
changeset
|
359 | GCallback callback, void *context) |
| 8849 | 360 | { |
| 361 | SilcPublicKeyIdentifier ident; | |
|
17675
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
17156
diff
changeset
|
362 | SilcSILCPublicKey silc_pubkey; |
| 8849 | 363 | char *fingerprint, *babbleprint; |
| 364 | unsigned char *pk; | |
| 365 | SilcUInt32 pk_len, key_len = 0; | |
| 366 | GString *s; | |
| 367 | ||
|
17675
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
17156
diff
changeset
|
368 | /* We support showing only SILC public keys for now */ |
|
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
17156
diff
changeset
|
369 | if (silc_pkcs_get_type(public_key) != SILC_PKCS_SILC) |
|
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
17156
diff
changeset
|
370 | return; |
|
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
17156
diff
changeset
|
371 | |
|
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
17156
diff
changeset
|
372 | silc_pubkey = silc_pkcs_get_context(SILC_PKCS_SILC, public_key); |
|
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
17156
diff
changeset
|
373 | ident = &silc_pubkey->identifier; |
|
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
17156
diff
changeset
|
374 | key_len = silc_pkcs_public_key_get_len(public_key); |
| 8849 | 375 | |
| 376 | pk = silc_pkcs_public_key_encode(public_key, &pk_len); | |
|
20289
5c844288fbec
applied changes from 32f31e981f0618a4167aa98bcc22c2dab13d1550
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
18552
diff
changeset
|
377 | if (!pk) |
|
5c844288fbec
applied changes from 32f31e981f0618a4167aa98bcc22c2dab13d1550
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
18552
diff
changeset
|
378 | return; |
| 8849 | 379 | fingerprint = silc_hash_fingerprint(NULL, pk, pk_len); |
| 380 | babbleprint = silc_hash_babbleprint(NULL, pk, pk_len); | |
|
20289
5c844288fbec
applied changes from 32f31e981f0618a4167aa98bcc22c2dab13d1550
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
18552
diff
changeset
|
381 | if (!fingerprint || !babbleprint) |
|
5c844288fbec
applied changes from 32f31e981f0618a4167aa98bcc22c2dab13d1550
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
18552
diff
changeset
|
382 | return; |
| 8849 | 383 | |
| 384 | s = g_string_new(""); | |
| 385 | if (ident->realname) | |
|
10825
986d260851e8
[gaim-migrate @ 12490]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
10751
diff
changeset
|
386 | /* Hint for translators: Please check the tabulator width here and in |
|
986d260851e8
[gaim-migrate @ 12490]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
10751
diff
changeset
|
387 | the next strings (short strings: 2 tabs, longer strings 1 tab, |
| 9274 | 388 | sum: 3 tabs or 24 characters) */ |
| 389 | g_string_append_printf(s, _("Real Name: \t%s\n"), ident->realname); | |
| 8849 | 390 | if (ident->username) |
| 9274 | 391 | g_string_append_printf(s, _("User Name: \t%s\n"), ident->username); |
| 8849 | 392 | if (ident->email) |
|
23325
a374a26fe217
Use "email" and "Email" consistently. This is potentially controversial,
Richard Laager <rlaager@pidgin.im>
parents:
22972
diff
changeset
|
393 | g_string_append_printf(s, _("Email: \t\t%s\n"), ident->email); |
| 8849 | 394 | if (ident->host) |
| 9274 | 395 | g_string_append_printf(s, _("Host Name: \t%s\n"), ident->host); |
| 8849 | 396 | if (ident->org) |
| 9274 | 397 | g_string_append_printf(s, _("Organization: \t%s\n"), ident->org); |
| 8849 | 398 | if (ident->country) |
| 9274 | 399 | g_string_append_printf(s, _("Country: \t%s\n"), ident->country); |
|
17675
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
17156
diff
changeset
|
400 | g_string_append_printf(s, _("Algorithm: \t%s\n"), silc_pubkey->pkcs->name); |
| 9274 | 401 | g_string_append_printf(s, _("Key Length: \t%d bits\n"), (int)key_len); |
|
17675
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
17156
diff
changeset
|
402 | if (ident->version) |
|
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
17156
diff
changeset
|
403 | g_string_append_printf(s, _("Version: \t%s\n"), ident->version); |
| 9274 | 404 | g_string_append_printf(s, "\n"); |
| 405 | g_string_append_printf(s, _("Public Key Fingerprint:\n%s\n\n"), fingerprint); | |
| 406 | g_string_append_printf(s, _("Public Key Babbleprint:\n%s"), babbleprint); | |
| 8849 | 407 | |
|
21175
c6d76b49c206
disapproval of revision '8ba833993a115415727bb1b70362e0bd1603c169'
Richard Laager <rlaager@pidgin.im>
parents:
21174
diff
changeset
|
408 | purple_request_action(sg->gc, _("Public Key Information"), |
|
17675
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
17156
diff
changeset
|
409 | _("Public Key Information"), |
|
34331
c8486462bb63
Request API refactoring: switch purple_request_action to PurpleRequestCommonParameters
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
33940
diff
changeset
|
410 | s->str, 0, purple_request_cpar_from_connection(sg->gc), |
|
c8486462bb63
Request API refactoring: switch purple_request_action to PurpleRequestCommonParameters
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
33940
diff
changeset
|
411 | context, 1, _("Close"), callback); |
| 8849 | 412 | |
|
22972
2942c1995c22
Cleanup allocations/frees to match and plug some leaks.
Daniel Atallah <datallah@pidgin.im>
parents:
22470
diff
changeset
|
413 | g_string_free(s, TRUE); |
| 8849 | 414 | silc_free(fingerprint); |
| 415 | silc_free(babbleprint); | |
| 416 | silc_free(pk); | |
| 417 | } | |
| 418 | ||
| 419 | SilcAttributePayload | |
| 15884 | 420 | silcpurple_get_attr(SilcDList attrs, SilcAttribute attribute) |
| 8849 | 421 | { |
| 422 | SilcAttributePayload attr = NULL; | |
| 423 | ||
| 424 | if (!attrs) | |
| 425 | return NULL; | |
| 426 | ||
| 427 | silc_dlist_start(attrs); | |
| 428 | while ((attr = silc_dlist_get(attrs)) != SILC_LIST_END) | |
| 429 | if (attribute == silc_attribute_get_attribute(attr)) | |
| 430 | break; | |
| 431 | ||
| 432 | return attr; | |
| 433 | } | |
| 434 | ||
| 15884 | 435 | void silcpurple_get_umode_string(SilcUInt32 mode, char *buf, |
|
17675
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
17156
diff
changeset
|
436 | SilcUInt32 buf_size) |
| 8849 | 437 | { |
| 438 | memset(buf, 0, buf_size); | |
| 439 | if ((mode & SILC_UMODE_SERVER_OPERATOR) || | |
| 440 | (mode & SILC_UMODE_ROUTER_OPERATOR)) { | |
| 441 | strcat(buf, (mode & SILC_UMODE_SERVER_OPERATOR) ? | |
| 442 | "[server operator] " : | |
| 443 | (mode & SILC_UMODE_ROUTER_OPERATOR) ? | |
| 444 | "[SILC operator] " : "[unknown mode] "); | |
| 445 | } | |
| 446 | if (mode & SILC_UMODE_GONE) | |
| 447 | strcat(buf, "[away] "); | |
| 448 | if (mode & SILC_UMODE_INDISPOSED) | |
| 449 | strcat(buf, "[indisposed] "); | |
| 450 | if (mode & SILC_UMODE_BUSY) | |
| 451 | strcat(buf, "[busy] "); | |
| 452 | if (mode & SILC_UMODE_PAGE) | |
| 453 | strcat(buf, "[wake me up] "); | |
| 454 | if (mode & SILC_UMODE_HYPER) | |
| 455 | strcat(buf, "[hyperactive] "); | |
| 456 | if (mode & SILC_UMODE_ROBOT) | |
| 457 | strcat(buf, "[robot] "); | |
| 458 | if (mode & SILC_UMODE_ANONYMOUS) | |
| 459 | strcat(buf, "[anonymous] "); | |
| 460 | if (mode & SILC_UMODE_BLOCK_PRIVMSG) | |
| 461 | strcat(buf, "[blocks private messages] "); | |
| 462 | if (mode & SILC_UMODE_DETACHED) | |
| 463 | strcat(buf, "[detached] "); | |
| 464 | if (mode & SILC_UMODE_REJECT_WATCHING) | |
| 465 | strcat(buf, "[rejects watching] "); | |
| 466 | if (mode & SILC_UMODE_BLOCK_INVITE) | |
| 467 | strcat(buf, "[blocks invites] "); | |
|
22470
6fb4ab976585
chomp chomp chomp chomp chomp chomp chomp chomp chomp chomp
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
21630
diff
changeset
|
468 | g_strchomp(buf); |
| 8849 | 469 | } |
| 470 | ||
| 15884 | 471 | void silcpurple_get_chmode_string(SilcUInt32 mode, char *buf, |
|
17675
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
17156
diff
changeset
|
472 | SilcUInt32 buf_size) |
| 8849 | 473 | { |
| 474 | memset(buf, 0, buf_size); | |
| 475 | if (mode & SILC_CHANNEL_MODE_FOUNDER_AUTH) | |
| 476 | strcat(buf, "[permanent] "); | |
| 477 | if (mode & SILC_CHANNEL_MODE_PRIVATE) | |
| 478 | strcat(buf, "[private] "); | |
| 479 | if (mode & SILC_CHANNEL_MODE_SECRET) | |
| 480 | strcat(buf, "[secret] "); | |
| 481 | if (mode & SILC_CHANNEL_MODE_PRIVKEY) | |
| 482 | strcat(buf, "[private key] "); | |
| 483 | if (mode & SILC_CHANNEL_MODE_INVITE) | |
| 484 | strcat(buf, "[invite only] "); | |
| 485 | if (mode & SILC_CHANNEL_MODE_TOPIC) | |
| 486 | strcat(buf, "[topic restricted] "); | |
| 487 | if (mode & SILC_CHANNEL_MODE_ULIMIT) | |
| 488 | strcat(buf, "[user count limit] "); | |
| 489 | if (mode & SILC_CHANNEL_MODE_PASSPHRASE) | |
| 490 | strcat(buf, "[passphrase auth] "); | |
| 491 | if (mode & SILC_CHANNEL_MODE_CHANNEL_AUTH) | |
| 492 | strcat(buf, "[public key auth] "); | |
| 493 | if (mode & SILC_CHANNEL_MODE_SILENCE_USERS) | |
| 494 | strcat(buf, "[users silenced] "); | |
| 495 | if (mode & SILC_CHANNEL_MODE_SILENCE_OPERS) | |
| 496 | strcat(buf, "[operators silenced] "); | |
|
22470
6fb4ab976585
chomp chomp chomp chomp chomp chomp chomp chomp chomp chomp
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
21630
diff
changeset
|
497 | g_strchomp(buf); |
| 8849 | 498 | } |
| 499 | ||
| 15884 | 500 | void silcpurple_get_chumode_string(SilcUInt32 mode, char *buf, |
| 8849 | 501 | SilcUInt32 buf_size) |
| 502 | { | |
| 503 | memset(buf, 0, buf_size); | |
| 504 | if (mode & SILC_CHANNEL_UMODE_CHANFO) | |
| 505 | strcat(buf, "[founder] "); | |
| 506 | if (mode & SILC_CHANNEL_UMODE_CHANOP) | |
| 507 | strcat(buf, "[operator] "); | |
| 508 | if (mode & SILC_CHANNEL_UMODE_BLOCK_MESSAGES) | |
| 509 | strcat(buf, "[blocks messages] "); | |
| 510 | if (mode & SILC_CHANNEL_UMODE_BLOCK_MESSAGES_USERS) | |
| 511 | strcat(buf, "[blocks user messages] "); | |
| 512 | if (mode & SILC_CHANNEL_UMODE_BLOCK_MESSAGES_ROBOTS) | |
| 513 | strcat(buf, "[blocks robot messages] "); | |
| 514 | if (mode & SILC_CHANNEL_UMODE_QUIET) | |
| 515 | strcat(buf, "[quieted] "); | |
|
22470
6fb4ab976585
chomp chomp chomp chomp chomp chomp chomp chomp chomp chomp
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
21630
diff
changeset
|
516 | g_strchomp(buf); |
| 8849 | 517 | } |
|
9488
9d6520fa53fd
[gaim-migrate @ 10313]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
9353
diff
changeset
|
518 | |
|
9d6520fa53fd
[gaim-migrate @ 10313]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
9353
diff
changeset
|
519 | void |
| 15884 | 520 | silcpurple_parse_attrs(SilcDList attrs, char **moodstr, char **statusstr, |
|
17675
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
17156
diff
changeset
|
521 | char **contactstr, char **langstr, char **devicestr, |
|
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
17156
diff
changeset
|
522 | char **tzstr, char **geostr) |
|
9488
9d6520fa53fd
[gaim-migrate @ 10313]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
9353
diff
changeset
|
523 | { |
|
9d6520fa53fd
[gaim-migrate @ 10313]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
9353
diff
changeset
|
524 | SilcAttributePayload attr; |
|
9d6520fa53fd
[gaim-migrate @ 10313]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
9353
diff
changeset
|
525 | SilcAttributeMood mood = 0; |
|
9d6520fa53fd
[gaim-migrate @ 10313]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
9353
diff
changeset
|
526 | SilcAttributeContact contact; |
|
9d6520fa53fd
[gaim-migrate @ 10313]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
9353
diff
changeset
|
527 | SilcAttributeObjDevice device; |
|
9d6520fa53fd
[gaim-migrate @ 10313]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
9353
diff
changeset
|
528 | SilcAttributeObjGeo geo; |
|
9d6520fa53fd
[gaim-migrate @ 10313]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
9353
diff
changeset
|
529 | |
|
9d6520fa53fd
[gaim-migrate @ 10313]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
9353
diff
changeset
|
530 | char tmp[1024]; |
|
9d6520fa53fd
[gaim-migrate @ 10313]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
9353
diff
changeset
|
531 | GString *s; |
|
9d6520fa53fd
[gaim-migrate @ 10313]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
9353
diff
changeset
|
532 | |
|
9d6520fa53fd
[gaim-migrate @ 10313]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
9353
diff
changeset
|
533 | *moodstr = NULL; |
|
9d6520fa53fd
[gaim-migrate @ 10313]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
9353
diff
changeset
|
534 | *statusstr = NULL; |
|
9d6520fa53fd
[gaim-migrate @ 10313]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
9353
diff
changeset
|
535 | *contactstr = NULL; |
|
9d6520fa53fd
[gaim-migrate @ 10313]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
9353
diff
changeset
|
536 | *langstr = NULL; |
|
9d6520fa53fd
[gaim-migrate @ 10313]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
9353
diff
changeset
|
537 | *devicestr = NULL; |
|
9d6520fa53fd
[gaim-migrate @ 10313]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
9353
diff
changeset
|
538 | *tzstr = NULL; |
|
9d6520fa53fd
[gaim-migrate @ 10313]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
9353
diff
changeset
|
539 | *geostr = NULL; |
|
9d6520fa53fd
[gaim-migrate @ 10313]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
9353
diff
changeset
|
540 | |
|
9d6520fa53fd
[gaim-migrate @ 10313]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
9353
diff
changeset
|
541 | if (!attrs) |
|
9d6520fa53fd
[gaim-migrate @ 10313]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
9353
diff
changeset
|
542 | return; |
|
9d6520fa53fd
[gaim-migrate @ 10313]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
9353
diff
changeset
|
543 | |
|
9d6520fa53fd
[gaim-migrate @ 10313]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
9353
diff
changeset
|
544 | s = g_string_new(""); |
| 15884 | 545 | attr = silcpurple_get_attr(attrs, SILC_ATTRIBUTE_STATUS_MOOD); |
|
9488
9d6520fa53fd
[gaim-migrate @ 10313]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
9353
diff
changeset
|
546 | if (attr && silc_attribute_get_object(attr, &mood, sizeof(mood))) { |
|
9d6520fa53fd
[gaim-migrate @ 10313]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
9353
diff
changeset
|
547 | if (mood & SILC_ATTRIBUTE_MOOD_HAPPY) |
|
9d6520fa53fd
[gaim-migrate @ 10313]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
9353
diff
changeset
|
548 | g_string_append_printf(s, "[%s] ", _("Happy")); |
|
9d6520fa53fd
[gaim-migrate @ 10313]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
9353
diff
changeset
|
549 | if (mood & SILC_ATTRIBUTE_MOOD_SAD) |
|
9d6520fa53fd
[gaim-migrate @ 10313]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
9353
diff
changeset
|
550 | g_string_append_printf(s, "[%s] ", _("Sad")); |
|
9d6520fa53fd
[gaim-migrate @ 10313]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
9353
diff
changeset
|
551 | if (mood & SILC_ATTRIBUTE_MOOD_ANGRY) |
|
9d6520fa53fd
[gaim-migrate @ 10313]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
9353
diff
changeset
|
552 | g_string_append_printf(s, "[%s] ", _("Angry")); |
|
9d6520fa53fd
[gaim-migrate @ 10313]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
9353
diff
changeset
|
553 | if (mood & SILC_ATTRIBUTE_MOOD_JEALOUS) |
|
9d6520fa53fd
[gaim-migrate @ 10313]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
9353
diff
changeset
|
554 | g_string_append_printf(s, "[%s] ", _("Jealous")); |
|
9d6520fa53fd
[gaim-migrate @ 10313]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
9353
diff
changeset
|
555 | if (mood & SILC_ATTRIBUTE_MOOD_ASHAMED) |
|
9d6520fa53fd
[gaim-migrate @ 10313]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
9353
diff
changeset
|
556 | g_string_append_printf(s, "[%s] ", _("Ashamed")); |
|
9d6520fa53fd
[gaim-migrate @ 10313]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
9353
diff
changeset
|
557 | if (mood & SILC_ATTRIBUTE_MOOD_INVINCIBLE) |
|
9d6520fa53fd
[gaim-migrate @ 10313]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
9353
diff
changeset
|
558 | g_string_append_printf(s, "[%s] ", _("Invincible")); |
|
9d6520fa53fd
[gaim-migrate @ 10313]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
9353
diff
changeset
|
559 | if (mood & SILC_ATTRIBUTE_MOOD_INLOVE) |
|
9d6520fa53fd
[gaim-migrate @ 10313]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
9353
diff
changeset
|
560 | g_string_append_printf(s, "[%s] ", _("In Love")); |
|
9d6520fa53fd
[gaim-migrate @ 10313]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
9353
diff
changeset
|
561 | if (mood & SILC_ATTRIBUTE_MOOD_SLEEPY) |
|
9d6520fa53fd
[gaim-migrate @ 10313]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
9353
diff
changeset
|
562 | g_string_append_printf(s, "[%s] ", _("Sleepy")); |
|
9d6520fa53fd
[gaim-migrate @ 10313]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
9353
diff
changeset
|
563 | if (mood & SILC_ATTRIBUTE_MOOD_BORED) |
|
9d6520fa53fd
[gaim-migrate @ 10313]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
9353
diff
changeset
|
564 | g_string_append_printf(s, "[%s] ", _("Bored")); |
|
9d6520fa53fd
[gaim-migrate @ 10313]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
9353
diff
changeset
|
565 | if (mood & SILC_ATTRIBUTE_MOOD_EXCITED) |
|
9d6520fa53fd
[gaim-migrate @ 10313]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
9353
diff
changeset
|
566 | g_string_append_printf(s, "[%s] ", _("Excited")); |
|
9d6520fa53fd
[gaim-migrate @ 10313]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
9353
diff
changeset
|
567 | if (mood & SILC_ATTRIBUTE_MOOD_ANXIOUS) |
|
9d6520fa53fd
[gaim-migrate @ 10313]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
9353
diff
changeset
|
568 | g_string_append_printf(s, "[%s] ", _("Anxious")); |
|
9d6520fa53fd
[gaim-migrate @ 10313]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
9353
diff
changeset
|
569 | } |
|
9d6520fa53fd
[gaim-migrate @ 10313]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
9353
diff
changeset
|
570 | if (strlen(s->str)) { |
|
22972
2942c1995c22
Cleanup allocations/frees to match and plug some leaks.
Daniel Atallah <datallah@pidgin.im>
parents:
22470
diff
changeset
|
571 | *moodstr = g_string_free(s, FALSE); |
|
22470
6fb4ab976585
chomp chomp chomp chomp chomp chomp chomp chomp chomp chomp
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
21630
diff
changeset
|
572 | g_strchomp(*moodstr); |
|
9488
9d6520fa53fd
[gaim-migrate @ 10313]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
9353
diff
changeset
|
573 | } else |
|
9d6520fa53fd
[gaim-migrate @ 10313]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
9353
diff
changeset
|
574 | g_string_free(s, TRUE); |
|
9d6520fa53fd
[gaim-migrate @ 10313]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
9353
diff
changeset
|
575 | |
| 15884 | 576 | attr = silcpurple_get_attr(attrs, SILC_ATTRIBUTE_STATUS_FREETEXT); |
|
9488
9d6520fa53fd
[gaim-migrate @ 10313]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
9353
diff
changeset
|
577 | memset(tmp, 0, sizeof(tmp)); |
|
9d6520fa53fd
[gaim-migrate @ 10313]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
9353
diff
changeset
|
578 | if (attr && silc_attribute_get_object(attr, tmp, sizeof(tmp))) |
|
9d6520fa53fd
[gaim-migrate @ 10313]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
9353
diff
changeset
|
579 | *statusstr = g_strdup(tmp); |
|
9d6520fa53fd
[gaim-migrate @ 10313]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
9353
diff
changeset
|
580 | |
|
9d6520fa53fd
[gaim-migrate @ 10313]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
9353
diff
changeset
|
581 | s = g_string_new(""); |
| 15884 | 582 | attr = silcpurple_get_attr(attrs, SILC_ATTRIBUTE_PREFERRED_CONTACT); |
|
9488
9d6520fa53fd
[gaim-migrate @ 10313]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
9353
diff
changeset
|
583 | if (attr && silc_attribute_get_object(attr, &contact, sizeof(contact))) { |
|
9d6520fa53fd
[gaim-migrate @ 10313]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
9353
diff
changeset
|
584 | if (contact & SILC_ATTRIBUTE_CONTACT_CHAT) |
|
9d6520fa53fd
[gaim-migrate @ 10313]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
9353
diff
changeset
|
585 | g_string_append_printf(s, "[%s] ", _("Chat")); |
|
9d6520fa53fd
[gaim-migrate @ 10313]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
9353
diff
changeset
|
586 | if (contact & SILC_ATTRIBUTE_CONTACT_EMAIL) |
|
23325
a374a26fe217
Use "email" and "Email" consistently. This is potentially controversial,
Richard Laager <rlaager@pidgin.im>
parents:
22972
diff
changeset
|
587 | g_string_append_printf(s, "[%s] ", _("Email")); |
|
9488
9d6520fa53fd
[gaim-migrate @ 10313]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
9353
diff
changeset
|
588 | if (contact & SILC_ATTRIBUTE_CONTACT_CALL) |
|
9d6520fa53fd
[gaim-migrate @ 10313]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
9353
diff
changeset
|
589 | g_string_append_printf(s, "[%s] ", _("Phone")); |
|
9d6520fa53fd
[gaim-migrate @ 10313]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
9353
diff
changeset
|
590 | if (contact & SILC_ATTRIBUTE_CONTACT_PAGE) |
|
9d6520fa53fd
[gaim-migrate @ 10313]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
9353
diff
changeset
|
591 | g_string_append_printf(s, "[%s] ", _("Paging")); |
|
9d6520fa53fd
[gaim-migrate @ 10313]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
9353
diff
changeset
|
592 | if (contact & SILC_ATTRIBUTE_CONTACT_SMS) |
|
9d6520fa53fd
[gaim-migrate @ 10313]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
9353
diff
changeset
|
593 | g_string_append_printf(s, "[%s] ", _("SMS")); |
|
9d6520fa53fd
[gaim-migrate @ 10313]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
9353
diff
changeset
|
594 | if (contact & SILC_ATTRIBUTE_CONTACT_MMS) |
|
9d6520fa53fd
[gaim-migrate @ 10313]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
9353
diff
changeset
|
595 | g_string_append_printf(s, "[%s] ", _("MMS")); |
|
9d6520fa53fd
[gaim-migrate @ 10313]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
9353
diff
changeset
|
596 | if (contact & SILC_ATTRIBUTE_CONTACT_VIDEO) |
|
9d6520fa53fd
[gaim-migrate @ 10313]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
9353
diff
changeset
|
597 | g_string_append_printf(s, "[%s] ", _("Video Conferencing")); |
|
9d6520fa53fd
[gaim-migrate @ 10313]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
9353
diff
changeset
|
598 | } |
|
9d6520fa53fd
[gaim-migrate @ 10313]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
9353
diff
changeset
|
599 | if (strlen(s->str)) { |
|
22972
2942c1995c22
Cleanup allocations/frees to match and plug some leaks.
Daniel Atallah <datallah@pidgin.im>
parents:
22470
diff
changeset
|
600 | *contactstr = g_string_free(s, FALSE); |
|
22470
6fb4ab976585
chomp chomp chomp chomp chomp chomp chomp chomp chomp chomp
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
21630
diff
changeset
|
601 | g_strchomp(*contactstr); |
|
9488
9d6520fa53fd
[gaim-migrate @ 10313]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
9353
diff
changeset
|
602 | } else |
|
9d6520fa53fd
[gaim-migrate @ 10313]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
9353
diff
changeset
|
603 | g_string_free(s, TRUE); |
|
9d6520fa53fd
[gaim-migrate @ 10313]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
9353
diff
changeset
|
604 | |
| 15884 | 605 | attr = silcpurple_get_attr(attrs, SILC_ATTRIBUTE_PREFERRED_LANGUAGE); |
|
9488
9d6520fa53fd
[gaim-migrate @ 10313]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
9353
diff
changeset
|
606 | memset(tmp, 0, sizeof(tmp)); |
|
9d6520fa53fd
[gaim-migrate @ 10313]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
9353
diff
changeset
|
607 | if (attr && silc_attribute_get_object(attr, tmp, sizeof(tmp))) |
|
9d6520fa53fd
[gaim-migrate @ 10313]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
9353
diff
changeset
|
608 | *langstr = g_strdup(tmp); |
|
9d6520fa53fd
[gaim-migrate @ 10313]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
9353
diff
changeset
|
609 | |
|
9d6520fa53fd
[gaim-migrate @ 10313]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
9353
diff
changeset
|
610 | s = g_string_new(""); |
| 15884 | 611 | attr = silcpurple_get_attr(attrs, SILC_ATTRIBUTE_DEVICE_INFO); |
|
9488
9d6520fa53fd
[gaim-migrate @ 10313]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
9353
diff
changeset
|
612 | memset(&device, 0, sizeof(device)); |
|
9d6520fa53fd
[gaim-migrate @ 10313]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
9353
diff
changeset
|
613 | if (attr && silc_attribute_get_object(attr, &device, sizeof(device))) { |
|
9d6520fa53fd
[gaim-migrate @ 10313]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
9353
diff
changeset
|
614 | if (device.type == SILC_ATTRIBUTE_DEVICE_COMPUTER) |
|
9d6520fa53fd
[gaim-migrate @ 10313]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
9353
diff
changeset
|
615 | g_string_append_printf(s, "%s: ", _("Computer")); |
|
9d6520fa53fd
[gaim-migrate @ 10313]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
9353
diff
changeset
|
616 | if (device.type == SILC_ATTRIBUTE_DEVICE_MOBILE_PHONE) |
|
9d6520fa53fd
[gaim-migrate @ 10313]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
9353
diff
changeset
|
617 | g_string_append_printf(s, "%s: ", _("Mobile Phone")); |
|
9d6520fa53fd
[gaim-migrate @ 10313]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
9353
diff
changeset
|
618 | if (device.type == SILC_ATTRIBUTE_DEVICE_PDA) |
|
9d6520fa53fd
[gaim-migrate @ 10313]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
9353
diff
changeset
|
619 | g_string_append_printf(s, "%s: ", _("PDA")); |
|
9d6520fa53fd
[gaim-migrate @ 10313]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
9353
diff
changeset
|
620 | if (device.type == SILC_ATTRIBUTE_DEVICE_TERMINAL) |
|
9d6520fa53fd
[gaim-migrate @ 10313]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
9353
diff
changeset
|
621 | g_string_append_printf(s, "%s: ", _("Terminal")); |
|
9d6520fa53fd
[gaim-migrate @ 10313]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
9353
diff
changeset
|
622 | g_string_append_printf(s, "%s %s %s %s", |
|
9d6520fa53fd
[gaim-migrate @ 10313]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
9353
diff
changeset
|
623 | device.manufacturer ? device.manufacturer : "", |
|
9d6520fa53fd
[gaim-migrate @ 10313]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
9353
diff
changeset
|
624 | device.version ? device.version : "", |
|
9d6520fa53fd
[gaim-migrate @ 10313]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
9353
diff
changeset
|
625 | device.model ? device.model : "", |
|
9d6520fa53fd
[gaim-migrate @ 10313]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
9353
diff
changeset
|
626 | device.language ? device.language : ""); |
|
9d6520fa53fd
[gaim-migrate @ 10313]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
9353
diff
changeset
|
627 | } |
|
22972
2942c1995c22
Cleanup allocations/frees to match and plug some leaks.
Daniel Atallah <datallah@pidgin.im>
parents:
22470
diff
changeset
|
628 | if (strlen(s->str)) |
|
2942c1995c22
Cleanup allocations/frees to match and plug some leaks.
Daniel Atallah <datallah@pidgin.im>
parents:
22470
diff
changeset
|
629 | *devicestr = g_string_free(s, FALSE); |
|
2942c1995c22
Cleanup allocations/frees to match and plug some leaks.
Daniel Atallah <datallah@pidgin.im>
parents:
22470
diff
changeset
|
630 | else |
|
9488
9d6520fa53fd
[gaim-migrate @ 10313]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
9353
diff
changeset
|
631 | g_string_free(s, TRUE); |
|
9d6520fa53fd
[gaim-migrate @ 10313]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
9353
diff
changeset
|
632 | |
| 15884 | 633 | attr = silcpurple_get_attr(attrs, SILC_ATTRIBUTE_TIMEZONE); |
|
9488
9d6520fa53fd
[gaim-migrate @ 10313]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
9353
diff
changeset
|
634 | memset(tmp, 0, sizeof(tmp)); |
|
9d6520fa53fd
[gaim-migrate @ 10313]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
9353
diff
changeset
|
635 | if (attr && silc_attribute_get_object(attr, tmp, sizeof(tmp))) |
|
9d6520fa53fd
[gaim-migrate @ 10313]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
9353
diff
changeset
|
636 | *tzstr = g_strdup(tmp); |
|
9d6520fa53fd
[gaim-migrate @ 10313]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
9353
diff
changeset
|
637 | |
| 15884 | 638 | attr = silcpurple_get_attr(attrs, SILC_ATTRIBUTE_GEOLOCATION); |
|
9488
9d6520fa53fd
[gaim-migrate @ 10313]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
9353
diff
changeset
|
639 | memset(&geo, 0, sizeof(geo)); |
|
9d6520fa53fd
[gaim-migrate @ 10313]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
9353
diff
changeset
|
640 | if (attr && silc_attribute_get_object(attr, &geo, sizeof(geo))) |
|
9d6520fa53fd
[gaim-migrate @ 10313]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
9353
diff
changeset
|
641 | *geostr = g_strdup_printf("%s %s %s (%s)", |
|
9d6520fa53fd
[gaim-migrate @ 10313]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
9353
diff
changeset
|
642 | geo.longitude ? geo.longitude : "", |
|
9d6520fa53fd
[gaim-migrate @ 10313]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
9353
diff
changeset
|
643 | geo.latitude ? geo.latitude : "", |
|
9d6520fa53fd
[gaim-migrate @ 10313]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
9353
diff
changeset
|
644 | geo.altitude ? geo.altitude : "", |
|
9d6520fa53fd
[gaim-migrate @ 10313]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
9353
diff
changeset
|
645 | geo.accuracy ? geo.accuracy : ""); |
|
9d6520fa53fd
[gaim-migrate @ 10313]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
9353
diff
changeset
|
646 | } |
|
12217
ea610d8ab584
[gaim-migrate @ 14519]
Pekka Riikonen <priikone@silcnet.org>
parents:
11488
diff
changeset
|
647 | |
|
ea610d8ab584
[gaim-migrate @ 14519]
Pekka Riikonen <priikone@silcnet.org>
parents:
11488
diff
changeset
|
648 | /* Returns MIME type of filetype */ |
|
ea610d8ab584
[gaim-migrate @ 14519]
Pekka Riikonen <priikone@silcnet.org>
parents:
11488
diff
changeset
|
649 | |
| 15884 | 650 | char *silcpurple_file2mime(const char *filename) |
|
12217
ea610d8ab584
[gaim-migrate @ 14519]
Pekka Riikonen <priikone@silcnet.org>
parents:
11488
diff
changeset
|
651 | { |
|
ea610d8ab584
[gaim-migrate @ 14519]
Pekka Riikonen <priikone@silcnet.org>
parents:
11488
diff
changeset
|
652 | const char *ct; |
|
ea610d8ab584
[gaim-migrate @ 14519]
Pekka Riikonen <priikone@silcnet.org>
parents:
11488
diff
changeset
|
653 | |
|
ea610d8ab584
[gaim-migrate @ 14519]
Pekka Riikonen <priikone@silcnet.org>
parents:
11488
diff
changeset
|
654 | ct = strrchr(filename, '.'); |
|
ea610d8ab584
[gaim-migrate @ 14519]
Pekka Riikonen <priikone@silcnet.org>
parents:
11488
diff
changeset
|
655 | if (!ct) |
|
ea610d8ab584
[gaim-migrate @ 14519]
Pekka Riikonen <priikone@silcnet.org>
parents:
11488
diff
changeset
|
656 | return NULL; |
|
18552
810a338ef085
Use the glib strcasecmp functions everywhere, as we've had reports of
Richard Laager <rlaager@pidgin.im>
parents:
17680
diff
changeset
|
657 | else if (!g_ascii_strcasecmp(".png", ct)) |
|
22972
2942c1995c22
Cleanup allocations/frees to match and plug some leaks.
Daniel Atallah <datallah@pidgin.im>
parents:
22470
diff
changeset
|
658 | return g_strdup("image/png"); |
|
18552
810a338ef085
Use the glib strcasecmp functions everywhere, as we've had reports of
Richard Laager <rlaager@pidgin.im>
parents:
17680
diff
changeset
|
659 | else if (!g_ascii_strcasecmp(".jpg", ct)) |
|
22972
2942c1995c22
Cleanup allocations/frees to match and plug some leaks.
Daniel Atallah <datallah@pidgin.im>
parents:
22470
diff
changeset
|
660 | return g_strdup("image/jpeg"); |
|
18552
810a338ef085
Use the glib strcasecmp functions everywhere, as we've had reports of
Richard Laager <rlaager@pidgin.im>
parents:
17680
diff
changeset
|
661 | else if (!g_ascii_strcasecmp(".jpeg", ct)) |
|
22972
2942c1995c22
Cleanup allocations/frees to match and plug some leaks.
Daniel Atallah <datallah@pidgin.im>
parents:
22470
diff
changeset
|
662 | return g_strdup("image/jpeg"); |
|
18552
810a338ef085
Use the glib strcasecmp functions everywhere, as we've had reports of
Richard Laager <rlaager@pidgin.im>
parents:
17680
diff
changeset
|
663 | else if (!g_ascii_strcasecmp(".gif", ct)) |
|
22972
2942c1995c22
Cleanup allocations/frees to match and plug some leaks.
Daniel Atallah <datallah@pidgin.im>
parents:
22470
diff
changeset
|
664 | return g_strdup("image/gif"); |
|
18552
810a338ef085
Use the glib strcasecmp functions everywhere, as we've had reports of
Richard Laager <rlaager@pidgin.im>
parents:
17680
diff
changeset
|
665 | else if (!g_ascii_strcasecmp(".tiff", ct)) |
|
22972
2942c1995c22
Cleanup allocations/frees to match and plug some leaks.
Daniel Atallah <datallah@pidgin.im>
parents:
22470
diff
changeset
|
666 | return g_strdup("image/tiff"); |
|
17675
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
17156
diff
changeset
|
667 | |
|
12217
ea610d8ab584
[gaim-migrate @ 14519]
Pekka Riikonen <priikone@silcnet.org>
parents:
11488
diff
changeset
|
668 | return NULL; |
|
ea610d8ab584
[gaim-migrate @ 14519]
Pekka Riikonen <priikone@silcnet.org>
parents:
11488
diff
changeset
|
669 | } |
|
ea610d8ab584
[gaim-migrate @ 14519]
Pekka Riikonen <priikone@silcnet.org>
parents:
11488
diff
changeset
|
670 | |
|
17675
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
17156
diff
changeset
|
671 | /* Checks if message has images, and assembles MIME message if it has. |
|
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
17156
diff
changeset
|
672 | If only one image is present, creates simple MIME image message. If |
|
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
17156
diff
changeset
|
673 | there are multiple images and/or text with images multipart MIME |
|
12217
ea610d8ab584
[gaim-migrate @ 14519]
Pekka Riikonen <priikone@silcnet.org>
parents:
11488
diff
changeset
|
674 | message is created. */ |
|
ea610d8ab584
[gaim-migrate @ 14519]
Pekka Riikonen <priikone@silcnet.org>
parents:
11488
diff
changeset
|
675 | |
|
33798
ab26d8e3da97
silc: Use appropriate datatype for SilcMessageFlags
Daniel Atallah <datallah@pidgin.im>
parents:
28981
diff
changeset
|
676 | SilcDList silcpurple_image_message(const char *msg, SilcMessageFlags *mflags) |
|
12217
ea610d8ab584
[gaim-migrate @ 14519]
Pekka Riikonen <priikone@silcnet.org>
parents:
11488
diff
changeset
|
677 | { |
|
ea610d8ab584
[gaim-migrate @ 14519]
Pekka Riikonen <priikone@silcnet.org>
parents:
11488
diff
changeset
|
678 | SilcMime mime = NULL, p; |
|
ea610d8ab584
[gaim-migrate @ 14519]
Pekka Riikonen <priikone@silcnet.org>
parents:
11488
diff
changeset
|
679 | SilcDList list, parts = NULL; |
|
ea610d8ab584
[gaim-migrate @ 14519]
Pekka Riikonen <priikone@silcnet.org>
parents:
11488
diff
changeset
|
680 | const char *start, *end, *last; |
|
ea610d8ab584
[gaim-migrate @ 14519]
Pekka Riikonen <priikone@silcnet.org>
parents:
11488
diff
changeset
|
681 | GData *attribs; |
|
ea610d8ab584
[gaim-migrate @ 14519]
Pekka Riikonen <priikone@silcnet.org>
parents:
11488
diff
changeset
|
682 | char *type; |
|
ea610d8ab584
[gaim-migrate @ 14519]
Pekka Riikonen <priikone@silcnet.org>
parents:
11488
diff
changeset
|
683 | gboolean images = FALSE; |
|
ea610d8ab584
[gaim-migrate @ 14519]
Pekka Riikonen <priikone@silcnet.org>
parents:
11488
diff
changeset
|
684 | |
|
ea610d8ab584
[gaim-migrate @ 14519]
Pekka Riikonen <priikone@silcnet.org>
parents:
11488
diff
changeset
|
685 | last = msg; |
| 15884 | 686 | while (last && *last && purple_markup_find_tag("img", last, &start, |
|
12217
ea610d8ab584
[gaim-migrate @ 14519]
Pekka Riikonen <priikone@silcnet.org>
parents:
11488
diff
changeset
|
687 | &end, &attribs)) { |
| 15884 | 688 | PurpleStoredImage *image = NULL; |
|
12217
ea610d8ab584
[gaim-migrate @ 14519]
Pekka Riikonen <priikone@silcnet.org>
parents:
11488
diff
changeset
|
689 | const char *id; |
|
ea610d8ab584
[gaim-migrate @ 14519]
Pekka Riikonen <priikone@silcnet.org>
parents:
11488
diff
changeset
|
690 | |
|
ea610d8ab584
[gaim-migrate @ 14519]
Pekka Riikonen <priikone@silcnet.org>
parents:
11488
diff
changeset
|
691 | /* Check if there is text before image */ |
|
ea610d8ab584
[gaim-migrate @ 14519]
Pekka Riikonen <priikone@silcnet.org>
parents:
11488
diff
changeset
|
692 | if (start - last) { |
|
ea610d8ab584
[gaim-migrate @ 14519]
Pekka Riikonen <priikone@silcnet.org>
parents:
11488
diff
changeset
|
693 | char *text, *tmp; |
|
ea610d8ab584
[gaim-migrate @ 14519]
Pekka Riikonen <priikone@silcnet.org>
parents:
11488
diff
changeset
|
694 | p = silc_mime_alloc(); |
|
ea610d8ab584
[gaim-migrate @ 14519]
Pekka Riikonen <priikone@silcnet.org>
parents:
11488
diff
changeset
|
695 | |
|
ea610d8ab584
[gaim-migrate @ 14519]
Pekka Riikonen <priikone@silcnet.org>
parents:
11488
diff
changeset
|
696 | /* Add content type */ |
|
ea610d8ab584
[gaim-migrate @ 14519]
Pekka Riikonen <priikone@silcnet.org>
parents:
11488
diff
changeset
|
697 | silc_mime_add_field(p, "Content-Type", |
|
ea610d8ab584
[gaim-migrate @ 14519]
Pekka Riikonen <priikone@silcnet.org>
parents:
11488
diff
changeset
|
698 | "text/plain; charset=utf-8"); |
|
ea610d8ab584
[gaim-migrate @ 14519]
Pekka Riikonen <priikone@silcnet.org>
parents:
11488
diff
changeset
|
699 | |
|
ea610d8ab584
[gaim-migrate @ 14519]
Pekka Riikonen <priikone@silcnet.org>
parents:
11488
diff
changeset
|
700 | tmp = g_strndup(last, start - last); |
| 15884 | 701 | text = purple_unescape_html(tmp); |
|
12217
ea610d8ab584
[gaim-migrate @ 14519]
Pekka Riikonen <priikone@silcnet.org>
parents:
11488
diff
changeset
|
702 | g_free(tmp); |
|
17675
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
17156
diff
changeset
|
703 | |
|
12217
ea610d8ab584
[gaim-migrate @ 14519]
Pekka Riikonen <priikone@silcnet.org>
parents:
11488
diff
changeset
|
704 | /* Add text */ |
|
17675
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
17156
diff
changeset
|
705 | silc_mime_add_data(p, (const unsigned char *)text, strlen(text)); |
|
12217
ea610d8ab584
[gaim-migrate @ 14519]
Pekka Riikonen <priikone@silcnet.org>
parents:
11488
diff
changeset
|
706 | g_free(text); |
|
ea610d8ab584
[gaim-migrate @ 14519]
Pekka Riikonen <priikone@silcnet.org>
parents:
11488
diff
changeset
|
707 | |
|
ea610d8ab584
[gaim-migrate @ 14519]
Pekka Riikonen <priikone@silcnet.org>
parents:
11488
diff
changeset
|
708 | if (!parts) |
|
ea610d8ab584
[gaim-migrate @ 14519]
Pekka Riikonen <priikone@silcnet.org>
parents:
11488
diff
changeset
|
709 | parts = silc_dlist_init(); |
|
ea610d8ab584
[gaim-migrate @ 14519]
Pekka Riikonen <priikone@silcnet.org>
parents:
11488
diff
changeset
|
710 | silc_dlist_add(parts, p); |
|
ea610d8ab584
[gaim-migrate @ 14519]
Pekka Riikonen <priikone@silcnet.org>
parents:
11488
diff
changeset
|
711 | } |
|
ea610d8ab584
[gaim-migrate @ 14519]
Pekka Riikonen <priikone@silcnet.org>
parents:
11488
diff
changeset
|
712 | |
|
ea610d8ab584
[gaim-migrate @ 14519]
Pekka Riikonen <priikone@silcnet.org>
parents:
11488
diff
changeset
|
713 | id = g_datalist_get_data(&attribs, "id"); |
|
16560
6d1c2bb6ee4c
Finally fix SILC fully, now that i have HAVE_SILCMIME_H defined.
Daniel Atallah <datallah@pidgin.im>
parents:
16492
diff
changeset
|
714 | if (id && (image = purple_imgstore_find_by_id(atoi(id)))) { |
| 15884 | 715 | unsigned long imglen = purple_imgstore_get_size(image); |
|
16560
6d1c2bb6ee4c
Finally fix SILC fully, now that i have HAVE_SILCMIME_H defined.
Daniel Atallah <datallah@pidgin.im>
parents:
16492
diff
changeset
|
716 | gconstpointer img = purple_imgstore_get_data(image); |
|
12217
ea610d8ab584
[gaim-migrate @ 14519]
Pekka Riikonen <priikone@silcnet.org>
parents:
11488
diff
changeset
|
717 | |
|
ea610d8ab584
[gaim-migrate @ 14519]
Pekka Riikonen <priikone@silcnet.org>
parents:
11488
diff
changeset
|
718 | p = silc_mime_alloc(); |
|
ea610d8ab584
[gaim-migrate @ 14519]
Pekka Riikonen <priikone@silcnet.org>
parents:
11488
diff
changeset
|
719 | |
|
ea610d8ab584
[gaim-migrate @ 14519]
Pekka Riikonen <priikone@silcnet.org>
parents:
11488
diff
changeset
|
720 | /* Add content type */ |
| 15884 | 721 | type = silcpurple_file2mime(purple_imgstore_get_filename(image)); |
|
12217
ea610d8ab584
[gaim-migrate @ 14519]
Pekka Riikonen <priikone@silcnet.org>
parents:
11488
diff
changeset
|
722 | if (!type) { |
|
ea610d8ab584
[gaim-migrate @ 14519]
Pekka Riikonen <priikone@silcnet.org>
parents:
11488
diff
changeset
|
723 | g_datalist_clear(&attribs); |
|
ea610d8ab584
[gaim-migrate @ 14519]
Pekka Riikonen <priikone@silcnet.org>
parents:
11488
diff
changeset
|
724 | last = end + 1; |
|
ea610d8ab584
[gaim-migrate @ 14519]
Pekka Riikonen <priikone@silcnet.org>
parents:
11488
diff
changeset
|
725 | continue; |
|
ea610d8ab584
[gaim-migrate @ 14519]
Pekka Riikonen <priikone@silcnet.org>
parents:
11488
diff
changeset
|
726 | } |
|
ea610d8ab584
[gaim-migrate @ 14519]
Pekka Riikonen <priikone@silcnet.org>
parents:
11488
diff
changeset
|
727 | silc_mime_add_field(p, "Content-Type", type); |
|
22972
2942c1995c22
Cleanup allocations/frees to match and plug some leaks.
Daniel Atallah <datallah@pidgin.im>
parents:
22470
diff
changeset
|
728 | g_free(type); |
|
12217
ea610d8ab584
[gaim-migrate @ 14519]
Pekka Riikonen <priikone@silcnet.org>
parents:
11488
diff
changeset
|
729 | |
|
ea610d8ab584
[gaim-migrate @ 14519]
Pekka Riikonen <priikone@silcnet.org>
parents:
11488
diff
changeset
|
730 | /* Add content transfer encoding */ |
|
ea610d8ab584
[gaim-migrate @ 14519]
Pekka Riikonen <priikone@silcnet.org>
parents:
11488
diff
changeset
|
731 | silc_mime_add_field(p, "Content-Transfer-Encoding", "binary"); |
|
ea610d8ab584
[gaim-migrate @ 14519]
Pekka Riikonen <priikone@silcnet.org>
parents:
11488
diff
changeset
|
732 | |
|
ea610d8ab584
[gaim-migrate @ 14519]
Pekka Riikonen <priikone@silcnet.org>
parents:
11488
diff
changeset
|
733 | /* Add image data */ |
|
ea610d8ab584
[gaim-migrate @ 14519]
Pekka Riikonen <priikone@silcnet.org>
parents:
11488
diff
changeset
|
734 | silc_mime_add_data(p, img, imglen); |
|
ea610d8ab584
[gaim-migrate @ 14519]
Pekka Riikonen <priikone@silcnet.org>
parents:
11488
diff
changeset
|
735 | |
|
ea610d8ab584
[gaim-migrate @ 14519]
Pekka Riikonen <priikone@silcnet.org>
parents:
11488
diff
changeset
|
736 | if (!parts) |
|
ea610d8ab584
[gaim-migrate @ 14519]
Pekka Riikonen <priikone@silcnet.org>
parents:
11488
diff
changeset
|
737 | parts = silc_dlist_init(); |
|
ea610d8ab584
[gaim-migrate @ 14519]
Pekka Riikonen <priikone@silcnet.org>
parents:
11488
diff
changeset
|
738 | silc_dlist_add(parts, p); |
|
ea610d8ab584
[gaim-migrate @ 14519]
Pekka Riikonen <priikone@silcnet.org>
parents:
11488
diff
changeset
|
739 | images = TRUE; |
|
ea610d8ab584
[gaim-migrate @ 14519]
Pekka Riikonen <priikone@silcnet.org>
parents:
11488
diff
changeset
|
740 | } |
|
ea610d8ab584
[gaim-migrate @ 14519]
Pekka Riikonen <priikone@silcnet.org>
parents:
11488
diff
changeset
|
741 | |
|
ea610d8ab584
[gaim-migrate @ 14519]
Pekka Riikonen <priikone@silcnet.org>
parents:
11488
diff
changeset
|
742 | g_datalist_clear(&attribs); |
|
ea610d8ab584
[gaim-migrate @ 14519]
Pekka Riikonen <priikone@silcnet.org>
parents:
11488
diff
changeset
|
743 | |
|
ea610d8ab584
[gaim-migrate @ 14519]
Pekka Riikonen <priikone@silcnet.org>
parents:
11488
diff
changeset
|
744 | /* Continue after tag */ |
|
ea610d8ab584
[gaim-migrate @ 14519]
Pekka Riikonen <priikone@silcnet.org>
parents:
11488
diff
changeset
|
745 | last = end + 1; |
|
ea610d8ab584
[gaim-migrate @ 14519]
Pekka Riikonen <priikone@silcnet.org>
parents:
11488
diff
changeset
|
746 | } |
|
ea610d8ab584
[gaim-migrate @ 14519]
Pekka Riikonen <priikone@silcnet.org>
parents:
11488
diff
changeset
|
747 | |
|
ea610d8ab584
[gaim-migrate @ 14519]
Pekka Riikonen <priikone@silcnet.org>
parents:
11488
diff
changeset
|
748 | /* Check for text after the image(s) */ |
|
ea610d8ab584
[gaim-migrate @ 14519]
Pekka Riikonen <priikone@silcnet.org>
parents:
11488
diff
changeset
|
749 | if (images && last && *last) { |
| 15884 | 750 | char *tmp = purple_unescape_html(last); |
|
12217
ea610d8ab584
[gaim-migrate @ 14519]
Pekka Riikonen <priikone@silcnet.org>
parents:
11488
diff
changeset
|
751 | p = silc_mime_alloc(); |
|
ea610d8ab584
[gaim-migrate @ 14519]
Pekka Riikonen <priikone@silcnet.org>
parents:
11488
diff
changeset
|
752 | |
|
ea610d8ab584
[gaim-migrate @ 14519]
Pekka Riikonen <priikone@silcnet.org>
parents:
11488
diff
changeset
|
753 | /* Add content type */ |
|
ea610d8ab584
[gaim-migrate @ 14519]
Pekka Riikonen <priikone@silcnet.org>
parents:
11488
diff
changeset
|
754 | silc_mime_add_field(p, "Content-Type", |
|
ea610d8ab584
[gaim-migrate @ 14519]
Pekka Riikonen <priikone@silcnet.org>
parents:
11488
diff
changeset
|
755 | "text/plain; charset=utf-8"); |
|
ea610d8ab584
[gaim-migrate @ 14519]
Pekka Riikonen <priikone@silcnet.org>
parents:
11488
diff
changeset
|
756 | |
|
ea610d8ab584
[gaim-migrate @ 14519]
Pekka Riikonen <priikone@silcnet.org>
parents:
11488
diff
changeset
|
757 | /* Add text */ |
|
17675
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
17156
diff
changeset
|
758 | silc_mime_add_data(p, (const unsigned char *)tmp, strlen(tmp)); |
|
12217
ea610d8ab584
[gaim-migrate @ 14519]
Pekka Riikonen <priikone@silcnet.org>
parents:
11488
diff
changeset
|
759 | g_free(tmp); |
|
ea610d8ab584
[gaim-migrate @ 14519]
Pekka Riikonen <priikone@silcnet.org>
parents:
11488
diff
changeset
|
760 | |
|
ea610d8ab584
[gaim-migrate @ 14519]
Pekka Riikonen <priikone@silcnet.org>
parents:
11488
diff
changeset
|
761 | if (!parts) |
|
ea610d8ab584
[gaim-migrate @ 14519]
Pekka Riikonen <priikone@silcnet.org>
parents:
11488
diff
changeset
|
762 | parts = silc_dlist_init(); |
|
ea610d8ab584
[gaim-migrate @ 14519]
Pekka Riikonen <priikone@silcnet.org>
parents:
11488
diff
changeset
|
763 | silc_dlist_add(parts, p); |
|
ea610d8ab584
[gaim-migrate @ 14519]
Pekka Riikonen <priikone@silcnet.org>
parents:
11488
diff
changeset
|
764 | } |
|
ea610d8ab584
[gaim-migrate @ 14519]
Pekka Riikonen <priikone@silcnet.org>
parents:
11488
diff
changeset
|
765 | |
|
ea610d8ab584
[gaim-migrate @ 14519]
Pekka Riikonen <priikone@silcnet.org>
parents:
11488
diff
changeset
|
766 | /* If there weren't any images, don't return anything. */ |
|
ea610d8ab584
[gaim-migrate @ 14519]
Pekka Riikonen <priikone@silcnet.org>
parents:
11488
diff
changeset
|
767 | if (!images) { |
|
ea610d8ab584
[gaim-migrate @ 14519]
Pekka Riikonen <priikone@silcnet.org>
parents:
11488
diff
changeset
|
768 | if (parts) |
|
ea610d8ab584
[gaim-migrate @ 14519]
Pekka Riikonen <priikone@silcnet.org>
parents:
11488
diff
changeset
|
769 | silc_dlist_uninit(parts); |
|
ea610d8ab584
[gaim-migrate @ 14519]
Pekka Riikonen <priikone@silcnet.org>
parents:
11488
diff
changeset
|
770 | return NULL; |
|
ea610d8ab584
[gaim-migrate @ 14519]
Pekka Riikonen <priikone@silcnet.org>
parents:
11488
diff
changeset
|
771 | } |
|
ea610d8ab584
[gaim-migrate @ 14519]
Pekka Riikonen <priikone@silcnet.org>
parents:
11488
diff
changeset
|
772 | |
|
ea610d8ab584
[gaim-migrate @ 14519]
Pekka Riikonen <priikone@silcnet.org>
parents:
11488
diff
changeset
|
773 | if (silc_dlist_count(parts) > 1) { |
|
ea610d8ab584
[gaim-migrate @ 14519]
Pekka Riikonen <priikone@silcnet.org>
parents:
11488
diff
changeset
|
774 | /* Multipart MIME message */ |
|
ea610d8ab584
[gaim-migrate @ 14519]
Pekka Riikonen <priikone@silcnet.org>
parents:
11488
diff
changeset
|
775 | char b[32]; |
|
ea610d8ab584
[gaim-migrate @ 14519]
Pekka Riikonen <priikone@silcnet.org>
parents:
11488
diff
changeset
|
776 | mime = silc_mime_alloc(); |
|
ea610d8ab584
[gaim-migrate @ 14519]
Pekka Riikonen <priikone@silcnet.org>
parents:
11488
diff
changeset
|
777 | silc_mime_add_field(mime, "MIME-Version", "1.0"); |
|
ea610d8ab584
[gaim-migrate @ 14519]
Pekka Riikonen <priikone@silcnet.org>
parents:
11488
diff
changeset
|
778 | g_snprintf(b, sizeof(b), "b%4X%4X", |
|
ea610d8ab584
[gaim-migrate @ 14519]
Pekka Riikonen <priikone@silcnet.org>
parents:
11488
diff
changeset
|
779 | (unsigned int)time(NULL), |
|
17675
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
17156
diff
changeset
|
780 | silc_dlist_count(parts)); |
|
12217
ea610d8ab584
[gaim-migrate @ 14519]
Pekka Riikonen <priikone@silcnet.org>
parents:
11488
diff
changeset
|
781 | silc_mime_set_multipart(mime, "mixed", b); |
|
ea610d8ab584
[gaim-migrate @ 14519]
Pekka Riikonen <priikone@silcnet.org>
parents:
11488
diff
changeset
|
782 | silc_dlist_start(parts); |
|
ea610d8ab584
[gaim-migrate @ 14519]
Pekka Riikonen <priikone@silcnet.org>
parents:
11488
diff
changeset
|
783 | while ((p = silc_dlist_get(parts)) != SILC_LIST_END) |
|
ea610d8ab584
[gaim-migrate @ 14519]
Pekka Riikonen <priikone@silcnet.org>
parents:
11488
diff
changeset
|
784 | silc_mime_add_multipart(mime, p); |
|
ea610d8ab584
[gaim-migrate @ 14519]
Pekka Riikonen <priikone@silcnet.org>
parents:
11488
diff
changeset
|
785 | } else { |
|
ea610d8ab584
[gaim-migrate @ 14519]
Pekka Riikonen <priikone@silcnet.org>
parents:
11488
diff
changeset
|
786 | /* Simple MIME message */ |
|
ea610d8ab584
[gaim-migrate @ 14519]
Pekka Riikonen <priikone@silcnet.org>
parents:
11488
diff
changeset
|
787 | silc_dlist_start(parts); |
|
ea610d8ab584
[gaim-migrate @ 14519]
Pekka Riikonen <priikone@silcnet.org>
parents:
11488
diff
changeset
|
788 | mime = silc_dlist_get(parts); |
|
ea610d8ab584
[gaim-migrate @ 14519]
Pekka Riikonen <priikone@silcnet.org>
parents:
11488
diff
changeset
|
789 | silc_mime_add_field(mime, "MIME-Version", "1.0"); |
|
ea610d8ab584
[gaim-migrate @ 14519]
Pekka Riikonen <priikone@silcnet.org>
parents:
11488
diff
changeset
|
790 | } |
|
ea610d8ab584
[gaim-migrate @ 14519]
Pekka Riikonen <priikone@silcnet.org>
parents:
11488
diff
changeset
|
791 | |
|
ea610d8ab584
[gaim-migrate @ 14519]
Pekka Riikonen <priikone@silcnet.org>
parents:
11488
diff
changeset
|
792 | *mflags &= ~SILC_MESSAGE_FLAG_UTF8; |
|
ea610d8ab584
[gaim-migrate @ 14519]
Pekka Riikonen <priikone@silcnet.org>
parents:
11488
diff
changeset
|
793 | *mflags |= SILC_MESSAGE_FLAG_DATA; |
|
ea610d8ab584
[gaim-migrate @ 14519]
Pekka Riikonen <priikone@silcnet.org>
parents:
11488
diff
changeset
|
794 | |
|
ea610d8ab584
[gaim-migrate @ 14519]
Pekka Riikonen <priikone@silcnet.org>
parents:
11488
diff
changeset
|
795 | /* Encode message. Fragment if it is too large */ |
|
ea610d8ab584
[gaim-migrate @ 14519]
Pekka Riikonen <priikone@silcnet.org>
parents:
11488
diff
changeset
|
796 | list = silc_mime_encode_partial(mime, 0xfc00); |
|
ea610d8ab584
[gaim-migrate @ 14519]
Pekka Riikonen <priikone@silcnet.org>
parents:
11488
diff
changeset
|
797 | |
|
ea610d8ab584
[gaim-migrate @ 14519]
Pekka Riikonen <priikone@silcnet.org>
parents:
11488
diff
changeset
|
798 | silc_dlist_uninit(parts); |
|
ea610d8ab584
[gaim-migrate @ 14519]
Pekka Riikonen <priikone@silcnet.org>
parents:
11488
diff
changeset
|
799 | |
|
ea610d8ab584
[gaim-migrate @ 14519]
Pekka Riikonen <priikone@silcnet.org>
parents:
11488
diff
changeset
|
800 | /* Added multiparts gets freed here */ |
|
ea610d8ab584
[gaim-migrate @ 14519]
Pekka Riikonen <priikone@silcnet.org>
parents:
11488
diff
changeset
|
801 | silc_mime_free(mime); |
|
ea610d8ab584
[gaim-migrate @ 14519]
Pekka Riikonen <priikone@silcnet.org>
parents:
11488
diff
changeset
|
802 | |
|
ea610d8ab584
[gaim-migrate @ 14519]
Pekka Riikonen <priikone@silcnet.org>
parents:
11488
diff
changeset
|
803 | return list; |
|
ea610d8ab584
[gaim-migrate @ 14519]
Pekka Riikonen <priikone@silcnet.org>
parents:
11488
diff
changeset
|
804 | } |