Mon, 22 Aug 2016 03:38:13 -0400
Add facebook to meson build.
| 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" |
|
35190
5986ee34c476
libpurple: Fix build and warnings with glib 2.24
Ankit Vani <a@nevitus.org>
parents:
34331
diff
changeset
|
21 | #include "glibcompat.h" |
|
35833
a7bfc2479cbd
imgstore: unref silc; fix inline images in silc
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35681
diff
changeset
|
22 | #include "image-store.h" |
|
a7bfc2479cbd
imgstore: unref silc; fix inline images in silc
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35681
diff
changeset
|
23 | |
|
35681
54694ef14d46
Silc: ignore Wcast-align in silc.h
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35190
diff
changeset
|
24 | PURPLE_BEGIN_IGNORE_CAST_ALIGN |
|
17675
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
17156
diff
changeset
|
25 | #include "silc.h" |
|
35681
54694ef14d46
Silc: ignore Wcast-align in silc.h
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35190
diff
changeset
|
26 | PURPLE_END_IGNORE_CAST_ALIGN |
| 8849 | 27 | #include "silcclient.h" |
| 15884 | 28 | #include "silcpurple.h" |
| 8849 | 29 | |
| 30 | /**************************** Utility Routines *******************************/ | |
| 31 | ||
| 32 | static char str[256], str2[256]; | |
| 33 | ||
| 15884 | 34 | const char *silcpurple_silcdir(void) |
| 8849 | 35 | { |
| 15884 | 36 | const char *hd = purple_home_dir(); |
| 8849 | 37 | memset(str, 0, sizeof(str)); |
| 38 | g_snprintf(str, sizeof(str) - 1, "%s" G_DIR_SEPARATOR_S ".silc", hd ? hd : "/tmp"); | |
| 39 | return (const char *)str; | |
| 40 | } | |
| 41 | ||
| 15884 | 42 | const char *silcpurple_session_file(const char *account) |
| 8849 | 43 | { |
| 44 | memset(str2, 0, sizeof(str2)); | |
| 45 | g_snprintf(str2, sizeof(str2) - 1, "%s" G_DIR_SEPARATOR_S "%s_session", | |
| 15884 | 46 | silcpurple_silcdir(), account); |
| 8849 | 47 | return (const char *)str2; |
| 48 | } | |
| 49 | ||
| 15884 | 50 | gboolean silcpurple_ip_is_private(const char *ip) |
| 8849 | 51 | { |
| 52 | if (silc_net_is_ip4(ip)) { | |
| 53 | if (!strncmp(ip, "10.", 3)) { | |
| 54 | return TRUE; | |
| 55 | } else if (!strncmp(ip, "172.", 4) && strlen(ip) > 6) { | |
| 56 | char tmp[3]; | |
| 8910 | 57 | int s; |
| 8849 | 58 | memset(tmp, 0, sizeof(tmp)); |
| 59 | strncpy(tmp, ip + 4, 2); | |
| 8910 | 60 | s = atoi(tmp); |
| 8849 | 61 | if (s >= 16 && s <= 31) |
| 62 | return TRUE; | |
| 63 | } else if (!strncmp(ip, "192.168.", 8)) { | |
| 64 | return TRUE; | |
| 65 | } | |
| 66 | } | |
| 67 | ||
| 68 | return FALSE; | |
| 69 | } | |
| 70 | ||
| 71 | /* This checks stats for various SILC files and directories. First it | |
| 72 | checks if ~/.silc directory exist and is owned by the correct user. If | |
| 73 | it doesn't exist, it will create the directory. After that it checks if | |
| 74 | user's Public and Private key files exists and creates them if needed. */ | |
| 75 | ||
| 15884 | 76 | gboolean silcpurple_check_silc_dir(PurpleConnection *gc) |
| 8849 | 77 | { |
| 78 | char filename[256], file_public_key[256], file_private_key[256]; | |
| 79 | char servfilename[256], clientfilename[256], friendsfilename[256]; | |
|
10825
986d260851e8
[gaim-migrate @ 12490]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
10751
diff
changeset
|
80 | char pkd[256], prd[256]; |
|
33940
b44d15793c83
Use GStatBuf instead of struct stat
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33811
diff
changeset
|
81 | GStatBuf st; |
| 8849 | 82 | struct passwd *pw; |
|
13660
3ade3ab0b2ae
[gaim-migrate @ 16061]
Mark Doliner <markdoliner@pidgin.im>
parents:
13546
diff
changeset
|
83 | int fd; |
| 8849 | 84 | |
| 85 | pw = getpwuid(getuid()); | |
| 86 | 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
|
87 | purple_debug_error("silc", "silc: %s\n", g_strerror(errno)); |
| 8849 | 88 | return FALSE; |
| 89 | } | |
| 90 | ||
| 15884 | 91 | g_snprintf(filename, sizeof(filename) - 1, "%s", silcpurple_silcdir()); |
| 8849 | 92 | g_snprintf(servfilename, sizeof(servfilename) - 1, "%s" G_DIR_SEPARATOR_S "serverkeys", |
| 15884 | 93 | silcpurple_silcdir()); |
| 8849 | 94 | g_snprintf(clientfilename, sizeof(clientfilename) - 1, "%s" G_DIR_SEPARATOR_S "clientkeys", |
| 15884 | 95 | silcpurple_silcdir()); |
| 8849 | 96 | g_snprintf(friendsfilename, sizeof(friendsfilename) - 1, "%s" G_DIR_SEPARATOR_S "friends", |
| 15884 | 97 | silcpurple_silcdir()); |
| 8849 | 98 | |
|
36030
9a2250c4e9d1
Fix Coverity TOCTOU warnings
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
36027
diff
changeset
|
99 | if (pw->pw_uid != geteuid()) { |
|
9a2250c4e9d1
Fix Coverity TOCTOU warnings
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
36027
diff
changeset
|
100 | purple_debug_error("silc", "Couldn't create directories due to wrong uid!\n"); |
|
9a2250c4e9d1
Fix Coverity TOCTOU warnings
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
36027
diff
changeset
|
101 | return FALSE; |
|
9a2250c4e9d1
Fix Coverity TOCTOU warnings
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
36027
diff
changeset
|
102 | } |
|
9a2250c4e9d1
Fix Coverity TOCTOU warnings
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
36027
diff
changeset
|
103 | |
| 8849 | 104 | /* |
| 105 | * Check ~/.silc directory | |
| 106 | */ | |
|
36030
9a2250c4e9d1
Fix Coverity TOCTOU warnings
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
36027
diff
changeset
|
107 | if (g_mkdir(filename, 0755) != 0 && errno != EEXIST) { |
|
9a2250c4e9d1
Fix Coverity TOCTOU warnings
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
36027
diff
changeset
|
108 | purple_debug_error("silc", "Couldn't create '%s' directory\n", filename); |
|
9a2250c4e9d1
Fix Coverity TOCTOU warnings
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
36027
diff
changeset
|
109 | return FALSE; |
|
9a2250c4e9d1
Fix Coverity TOCTOU warnings
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
36027
diff
changeset
|
110 | } |
|
9a2250c4e9d1
Fix Coverity TOCTOU warnings
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
36027
diff
changeset
|
111 | |
|
9a2250c4e9d1
Fix Coverity TOCTOU warnings
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
36027
diff
changeset
|
112 | #ifndef _WIN32 |
|
10589
4e10236e06d4
[gaim-migrate @ 11994]
Daniel Atallah <datallah@pidgin.im>
parents:
9488
diff
changeset
|
113 | if ((g_stat(filename, &st)) == -1) { |
|
36030
9a2250c4e9d1
Fix Coverity TOCTOU warnings
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
36027
diff
changeset
|
114 | purple_debug_error("silc", "Couldn't stat '%s' directory, error: %s\n", filename, g_strerror(errno)); |
|
9a2250c4e9d1
Fix Coverity TOCTOU warnings
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
36027
diff
changeset
|
115 | return FALSE; |
| 8849 | 116 | } else { |
| 117 | /* Check the owner of the dir */ | |
| 118 | if (st.st_uid != 0 && st.st_uid != pw->pw_uid) { | |
| 15884 | 119 | purple_debug_error("silc", "You don't seem to own '%s' directory\n", |
| 8849 | 120 | filename); |
| 121 | return FALSE; | |
| 122 | } | |
|
36030
9a2250c4e9d1
Fix Coverity TOCTOU warnings
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
36027
diff
changeset
|
123 | } |
|
9353
ff6546387358
[gaim-migrate @ 10161]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
9274
diff
changeset
|
124 | #endif |
| 8849 | 125 | |
| 126 | /* | |
| 127 | * Check ~./silc/serverkeys directory | |
| 128 | */ | |
|
36030
9a2250c4e9d1
Fix Coverity TOCTOU warnings
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
36027
diff
changeset
|
129 | if (g_mkdir(servfilename, 0755) != 0 && errno != EEXIST) { |
|
9a2250c4e9d1
Fix Coverity TOCTOU warnings
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
36027
diff
changeset
|
130 | purple_debug_error("silc", "Couldn't create '%s' directory\n", servfilename); |
|
9a2250c4e9d1
Fix Coverity TOCTOU warnings
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
36027
diff
changeset
|
131 | return FALSE; |
| 8849 | 132 | } |
| 133 | ||
| 134 | /* | |
| 135 | * Check ~./silc/clientkeys directory | |
| 136 | */ | |
|
36030
9a2250c4e9d1
Fix Coverity TOCTOU warnings
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
36027
diff
changeset
|
137 | if (g_mkdir(clientfilename, 0755) != 0 && errno != EEXIST) { |
|
9a2250c4e9d1
Fix Coverity TOCTOU warnings
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
36027
diff
changeset
|
138 | purple_debug_error("silc", "Couldn't create '%s' directory\n", clientfilename); |
|
9a2250c4e9d1
Fix Coverity TOCTOU warnings
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
36027
diff
changeset
|
139 | return FALSE; |
| 8849 | 140 | } |
| 141 | ||
| 142 | /* | |
| 143 | * Check ~./silc/friends directory | |
| 144 | */ | |
|
36030
9a2250c4e9d1
Fix Coverity TOCTOU warnings
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
36027
diff
changeset
|
145 | if (g_mkdir(friendsfilename, 0755) != 0 && errno != EEXIST) { |
|
9a2250c4e9d1
Fix Coverity TOCTOU warnings
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
36027
diff
changeset
|
146 | purple_debug_error("silc", "Couldn't create '%s' directory\n", friendsfilename); |
|
9a2250c4e9d1
Fix Coverity TOCTOU warnings
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
36027
diff
changeset
|
147 | return FALSE; |
| 8849 | 148 | } |
| 149 | ||
| 150 | /* | |
| 151 | * Check Public and Private keys | |
| 152 | */ | |
| 15884 | 153 | g_snprintf(pkd, sizeof(pkd), "%s" G_DIR_SEPARATOR_S "public_key.pub", silcpurple_silcdir()); |
| 154 | g_snprintf(prd, sizeof(prd), "%s" G_DIR_SEPARATOR_S "private_key.prv", silcpurple_silcdir()); | |
| 8849 | 155 | 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
|
156 | purple_account_get_string(purple_connection_get_account(gc), "public-key", pkd)); |
| 8849 | 157 | 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
|
158 | purple_account_get_string(purple_connection_get_account(gc), "private-key", prd)); |
| 8849 | 159 | |
|
10589
4e10236e06d4
[gaim-migrate @ 11994]
Daniel Atallah <datallah@pidgin.im>
parents:
9488
diff
changeset
|
160 | if ((g_stat(file_public_key, &st)) == -1) { |
| 8849 | 161 | /* If file doesn't exist */ |
| 162 | if (errno == ENOENT) { | |
| 15884 | 163 | purple_connection_update_progress(gc, _("Creating SILC key pair..."), 1, 5); |
| 164 | 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
|
165 | 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
|
166 | 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
|
167 | 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
|
168 | (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
|
169 | NULL, NULL, FALSE)) { |
|
32157
39ba2e2492ee
Rename purple_connection_error_reason to purple_connection_error
Mark Doliner <markdoliner@pidgin.im>
parents:
28981
diff
changeset
|
170 | 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
|
171 | _("Unable to create SILC key pair")); |
|
14148
2f0c6fcb0db5
[gaim-migrate @ 16709]
Daniel Atallah <datallah@pidgin.im>
parents:
13660
diff
changeset
|
172 | return FALSE; |
|
2f0c6fcb0db5
[gaim-migrate @ 16709]
Daniel Atallah <datallah@pidgin.im>
parents:
13660
diff
changeset
|
173 | } |
|
2f0c6fcb0db5
[gaim-migrate @ 16709]
Daniel Atallah <datallah@pidgin.im>
parents:
13660
diff
changeset
|
174 | |
|
2f0c6fcb0db5
[gaim-migrate @ 16709]
Daniel Atallah <datallah@pidgin.im>
parents:
13660
diff
changeset
|
175 | if ((g_stat(file_public_key, &st)) == -1) { |
| 15884 | 176 | 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
|
177 | file_public_key, g_strerror(errno)); |
|
14148
2f0c6fcb0db5
[gaim-migrate @ 16709]
Daniel Atallah <datallah@pidgin.im>
parents:
13660
diff
changeset
|
178 | return FALSE; |
|
2f0c6fcb0db5
[gaim-migrate @ 16709]
Daniel Atallah <datallah@pidgin.im>
parents:
13660
diff
changeset
|
179 | } |
| 8849 | 180 | } else { |
| 15884 | 181 | 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
|
182 | file_public_key, g_strerror(errno)); |
| 8849 | 183 | return FALSE; |
| 184 | } | |
| 185 | } | |
| 186 | ||
|
9353
ff6546387358
[gaim-migrate @ 10161]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
9274
diff
changeset
|
187 | #ifndef _WIN32 |
| 8849 | 188 | /* Check the owner of the public key */ |
| 189 | if (st.st_uid != 0 && st.st_uid != pw->pw_uid) { | |
| 15884 | 190 | purple_debug_error("silc", "You don't seem to own your public key!?\n"); |
| 8849 | 191 | return FALSE; |
| 192 | } | |
|
9353
ff6546387358
[gaim-migrate @ 10161]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
9274
diff
changeset
|
193 | #endif |
| 8849 | 194 | |
|
14227
e760c7dd2e7a
[gaim-migrate @ 16815]
Daniel Atallah <datallah@pidgin.im>
parents:
14218
diff
changeset
|
195 | if ((fd = g_open(file_private_key, O_RDONLY, 0)) != -1) { |
|
36034
4bba5ea5d08a
Provide a portable alternative for fstat
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
36031
diff
changeset
|
196 | if (_purple_fstat(fd, &st) == -1) { |
| 15884 | 197 | 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
|
198 | file_private_key, g_strerror(errno)); |
|
14218
c498aba6235f
[gaim-migrate @ 16801]
Daniel Atallah <datallah@pidgin.im>
parents:
14148
diff
changeset
|
199 | close(fd); |
|
c498aba6235f
[gaim-migrate @ 16801]
Daniel Atallah <datallah@pidgin.im>
parents:
14148
diff
changeset
|
200 | return FALSE; |
|
c498aba6235f
[gaim-migrate @ 16801]
Daniel Atallah <datallah@pidgin.im>
parents:
14148
diff
changeset
|
201 | } |
|
35995
d0bbb2dad7f3
Fix some CWE-367 coverity warnings
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
33798
diff
changeset
|
202 | } else { |
| 8849 | 203 | /* If file doesn't exist */ |
| 204 | if (errno == ENOENT) { | |
| 15884 | 205 | purple_connection_update_progress(gc, _("Creating SILC key pair..."), 1, 5); |
| 206 | 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
|
207 | 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
|
208 | 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
|
209 | 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
|
210 | (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
|
211 | NULL, NULL, FALSE)) { |
|
32157
39ba2e2492ee
Rename purple_connection_error_reason to purple_connection_error
Mark Doliner <markdoliner@pidgin.im>
parents:
28981
diff
changeset
|
212 | 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
|
213 | _("Unable to create SILC key pair")); |
|
14218
c498aba6235f
[gaim-migrate @ 16801]
Daniel Atallah <datallah@pidgin.im>
parents:
14148
diff
changeset
|
214 | return FALSE; |
|
c498aba6235f
[gaim-migrate @ 16801]
Daniel Atallah <datallah@pidgin.im>
parents:
14148
diff
changeset
|
215 | } |
|
c498aba6235f
[gaim-migrate @ 16801]
Daniel Atallah <datallah@pidgin.im>
parents:
14148
diff
changeset
|
216 | |
|
14227
e760c7dd2e7a
[gaim-migrate @ 16815]
Daniel Atallah <datallah@pidgin.im>
parents:
14218
diff
changeset
|
217 | if ((fd = g_open(file_private_key, O_RDONLY, 0)) != -1) { |
|
36034
4bba5ea5d08a
Provide a portable alternative for fstat
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
36031
diff
changeset
|
218 | if (_purple_fstat(fd, &st) == -1) { |
| 15884 | 219 | 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
|
220 | file_private_key, g_strerror(errno)); |
|
14218
c498aba6235f
[gaim-migrate @ 16801]
Daniel Atallah <datallah@pidgin.im>
parents:
14148
diff
changeset
|
221 | close(fd); |
|
c498aba6235f
[gaim-migrate @ 16801]
Daniel Atallah <datallah@pidgin.im>
parents:
14148
diff
changeset
|
222 | return FALSE; |
|
c498aba6235f
[gaim-migrate @ 16801]
Daniel Atallah <datallah@pidgin.im>
parents:
14148
diff
changeset
|
223 | } |
|
36027
175e769076e1
Fix newly generated coverity warnings
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35995
diff
changeset
|
224 | } else { |
|
175e769076e1
Fix newly generated coverity warnings
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35995
diff
changeset
|
225 | purple_debug_error("silc", "Couldn't open '%s' " |
|
175e769076e1
Fix newly generated coverity warnings
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35995
diff
changeset
|
226 | "private key, error: %s\n", |
|
175e769076e1
Fix newly generated coverity warnings
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35995
diff
changeset
|
227 | file_private_key, g_strerror(errno)); |
|
14218
c498aba6235f
[gaim-migrate @ 16801]
Daniel Atallah <datallah@pidgin.im>
parents:
14148
diff
changeset
|
228 | return FALSE; |
|
c498aba6235f
[gaim-migrate @ 16801]
Daniel Atallah <datallah@pidgin.im>
parents:
14148
diff
changeset
|
229 | } |
| 8849 | 230 | } else { |
|
35995
d0bbb2dad7f3
Fix some CWE-367 coverity warnings
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
33798
diff
changeset
|
231 | purple_debug_error("silc", "Couldn't open '%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
|
232 | file_private_key, g_strerror(errno)); |
| 8849 | 233 | return FALSE; |
| 234 | } | |
| 235 | } | |
| 236 | ||
|
9353
ff6546387358
[gaim-migrate @ 10161]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
9274
diff
changeset
|
237 | #ifndef _WIN32 |
| 8849 | 238 | /* Check the owner of the private key */ |
| 239 | if (st.st_uid != 0 && st.st_uid != pw->pw_uid) { | |
| 15884 | 240 | 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
|
241 | if (fd != -1) |
|
3ade3ab0b2ae
[gaim-migrate @ 16061]
Mark Doliner <markdoliner@pidgin.im>
parents:
13546
diff
changeset
|
242 | close(fd); |
| 8849 | 243 | return FALSE; |
| 244 | } | |
| 245 | ||
| 246 | /* Check the permissions for the private key */ | |
| 247 | if ((st.st_mode & 0777) != 0600) { | |
| 15884 | 248 | 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
|
249 | "Trying to change them ...\n", file_private_key); |
|
14218
c498aba6235f
[gaim-migrate @ 16801]
Daniel Atallah <datallah@pidgin.im>
parents:
14148
diff
changeset
|
250 | if ((fd == -1) || (fchmod(fd, S_IRUSR | S_IWUSR)) == -1) { |
| 15884 | 251 | purple_debug_error("silc", |
| 8849 | 252 | "Failed to change permissions for private key file!\n" |
| 253 | "Permissions for your private key file must be 0600.\n"); | |
|
13660
3ade3ab0b2ae
[gaim-migrate @ 16061]
Mark Doliner <markdoliner@pidgin.im>
parents:
13546
diff
changeset
|
254 | if (fd != -1) |
|
3ade3ab0b2ae
[gaim-migrate @ 16061]
Mark Doliner <markdoliner@pidgin.im>
parents:
13546
diff
changeset
|
255 | close(fd); |
| 8849 | 256 | return FALSE; |
| 257 | } | |
| 15884 | 258 | purple_debug_warning("silc", "Done.\n\n"); |
| 8849 | 259 | } |
|
9353
ff6546387358
[gaim-migrate @ 10161]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
9274
diff
changeset
|
260 | #endif |
| 8849 | 261 | |
|
13660
3ade3ab0b2ae
[gaim-migrate @ 16061]
Mark Doliner <markdoliner@pidgin.im>
parents:
13546
diff
changeset
|
262 | if (fd != -1) |
|
3ade3ab0b2ae
[gaim-migrate @ 16061]
Mark Doliner <markdoliner@pidgin.im>
parents:
13546
diff
changeset
|
263 | close(fd); |
|
3ade3ab0b2ae
[gaim-migrate @ 16061]
Mark Doliner <markdoliner@pidgin.im>
parents:
13546
diff
changeset
|
264 | |
|
33692
4f72b9501fb2
util.c: Fix win32-only leak in silcpurple_check_silc_dir
Niels Thykier <niels@thykier.net>
parents:
32683
diff
changeset
|
265 | #ifdef _WIN32 |
|
4f72b9501fb2
util.c: Fix win32-only leak in silcpurple_check_silc_dir
Niels Thykier <niels@thykier.net>
parents:
32683
diff
changeset
|
266 | /* 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
|
267 | * (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
|
268 | */ |
|
4f72b9501fb2
util.c: Fix win32-only leak in silcpurple_check_silc_dir
Niels Thykier <niels@thykier.net>
parents:
32683
diff
changeset
|
269 | free(pw); |
|
4f72b9501fb2
util.c: Fix win32-only leak in silcpurple_check_silc_dir
Niels Thykier <niels@thykier.net>
parents:
32683
diff
changeset
|
270 | #endif |
|
4f72b9501fb2
util.c: Fix win32-only leak in silcpurple_check_silc_dir
Niels Thykier <niels@thykier.net>
parents:
32683
diff
changeset
|
271 | |
| 8849 | 272 | return TRUE; |
| 273 | } | |
| 274 | ||
|
9353
ff6546387358
[gaim-migrate @ 10161]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
9274
diff
changeset
|
275 | #ifdef _WIN32 |
|
ff6546387358
[gaim-migrate @ 10161]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
9274
diff
changeset
|
276 | struct passwd *getpwuid(uid_t uid) { |
|
ff6546387358
[gaim-migrate @ 10161]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
9274
diff
changeset
|
277 | struct passwd *pwd = calloc(1, sizeof(struct passwd)); |
|
ff6546387358
[gaim-migrate @ 10161]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
9274
diff
changeset
|
278 | return pwd; |
|
ff6546387358
[gaim-migrate @ 10161]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
9274
diff
changeset
|
279 | } |
|
ff6546387358
[gaim-migrate @ 10161]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
9274
diff
changeset
|
280 | |
|
ff6546387358
[gaim-migrate @ 10161]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
9274
diff
changeset
|
281 | uid_t getuid() { |
|
ff6546387358
[gaim-migrate @ 10161]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
9274
diff
changeset
|
282 | return 0; |
|
ff6546387358
[gaim-migrate @ 10161]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
9274
diff
changeset
|
283 | } |
|
ff6546387358
[gaim-migrate @ 10161]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
9274
diff
changeset
|
284 | |
|
ff6546387358
[gaim-migrate @ 10161]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
9274
diff
changeset
|
285 | uid_t geteuid() { |
|
ff6546387358
[gaim-migrate @ 10161]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
9274
diff
changeset
|
286 | return 0; |
|
ff6546387358
[gaim-migrate @ 10161]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
9274
diff
changeset
|
287 | } |
|
ff6546387358
[gaim-migrate @ 10161]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
9274
diff
changeset
|
288 | #endif |
|
ff6546387358
[gaim-migrate @ 10161]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
9274
diff
changeset
|
289 | |
| 15884 | 290 | 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
|
291 | 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
|
292 | GCallback callback, void *context) |
| 8849 | 293 | { |
| 294 | 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
|
295 | SilcSILCPublicKey silc_pubkey; |
| 8849 | 296 | char *fingerprint, *babbleprint; |
| 297 | unsigned char *pk; | |
| 298 | SilcUInt32 pk_len, key_len = 0; | |
| 299 | GString *s; | |
| 300 | ||
|
17675
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
17156
diff
changeset
|
301 | /* 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
|
302 | 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
|
303 | return; |
|
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
17156
diff
changeset
|
304 | |
|
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
17156
diff
changeset
|
305 | 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
|
306 | 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
|
307 | key_len = silc_pkcs_public_key_get_len(public_key); |
| 8849 | 308 | |
| 309 | 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
|
310 | if (!pk) |
|
5c844288fbec
applied changes from 32f31e981f0618a4167aa98bcc22c2dab13d1550
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
18552
diff
changeset
|
311 | return; |
| 8849 | 312 | fingerprint = silc_hash_fingerprint(NULL, pk, pk_len); |
| 313 | babbleprint = silc_hash_babbleprint(NULL, pk, pk_len); | |
|
20289
5c844288fbec
applied changes from 32f31e981f0618a4167aa98bcc22c2dab13d1550
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
18552
diff
changeset
|
314 | if (!fingerprint || !babbleprint) |
|
5c844288fbec
applied changes from 32f31e981f0618a4167aa98bcc22c2dab13d1550
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
18552
diff
changeset
|
315 | return; |
| 8849 | 316 | |
| 317 | s = g_string_new(""); | |
| 318 | if (ident->realname) | |
|
10825
986d260851e8
[gaim-migrate @ 12490]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
10751
diff
changeset
|
319 | /* Hint for translators: Please check the tabulator width here and in |
|
986d260851e8
[gaim-migrate @ 12490]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
10751
diff
changeset
|
320 | the next strings (short strings: 2 tabs, longer strings 1 tab, |
| 9274 | 321 | sum: 3 tabs or 24 characters) */ |
| 322 | g_string_append_printf(s, _("Real Name: \t%s\n"), ident->realname); | |
| 8849 | 323 | if (ident->username) |
| 9274 | 324 | g_string_append_printf(s, _("User Name: \t%s\n"), ident->username); |
| 8849 | 325 | if (ident->email) |
|
23325
a374a26fe217
Use "email" and "Email" consistently. This is potentially controversial,
Richard Laager <rlaager@pidgin.im>
parents:
22972
diff
changeset
|
326 | g_string_append_printf(s, _("Email: \t\t%s\n"), ident->email); |
| 8849 | 327 | if (ident->host) |
| 9274 | 328 | g_string_append_printf(s, _("Host Name: \t%s\n"), ident->host); |
| 8849 | 329 | if (ident->org) |
| 9274 | 330 | g_string_append_printf(s, _("Organization: \t%s\n"), ident->org); |
| 8849 | 331 | if (ident->country) |
| 9274 | 332 | 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
|
333 | g_string_append_printf(s, _("Algorithm: \t%s\n"), silc_pubkey->pkcs->name); |
| 9274 | 334 | 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
|
335 | 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
|
336 | g_string_append_printf(s, _("Version: \t%s\n"), ident->version); |
| 9274 | 337 | g_string_append_printf(s, "\n"); |
| 338 | g_string_append_printf(s, _("Public Key Fingerprint:\n%s\n\n"), fingerprint); | |
| 339 | g_string_append_printf(s, _("Public Key Babbleprint:\n%s"), babbleprint); | |
| 8849 | 340 | |
|
21175
c6d76b49c206
disapproval of revision '8ba833993a115415727bb1b70362e0bd1603c169'
Richard Laager <rlaager@pidgin.im>
parents:
21174
diff
changeset
|
341 | 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
|
342 | _("Public Key Information"), |
|
34331
c8486462bb63
Request API refactoring: switch purple_request_action to PurpleRequestCommonParameters
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
33940
diff
changeset
|
343 | 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
|
344 | context, 1, _("Close"), callback); |
| 8849 | 345 | |
|
22972
2942c1995c22
Cleanup allocations/frees to match and plug some leaks.
Daniel Atallah <datallah@pidgin.im>
parents:
22470
diff
changeset
|
346 | g_string_free(s, TRUE); |
| 8849 | 347 | silc_free(fingerprint); |
| 348 | silc_free(babbleprint); | |
| 349 | silc_free(pk); | |
| 350 | } | |
| 351 | ||
| 352 | SilcAttributePayload | |
| 15884 | 353 | silcpurple_get_attr(SilcDList attrs, SilcAttribute attribute) |
| 8849 | 354 | { |
| 355 | SilcAttributePayload attr = NULL; | |
| 356 | ||
| 357 | if (!attrs) | |
| 358 | return NULL; | |
| 359 | ||
| 360 | silc_dlist_start(attrs); | |
| 361 | while ((attr = silc_dlist_get(attrs)) != SILC_LIST_END) | |
| 362 | if (attribute == silc_attribute_get_attribute(attr)) | |
| 363 | break; | |
| 364 | ||
| 365 | return attr; | |
| 366 | } | |
| 367 | ||
| 15884 | 368 | 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
|
369 | SilcUInt32 buf_size) |
| 8849 | 370 | { |
| 371 | memset(buf, 0, buf_size); | |
| 372 | if ((mode & SILC_UMODE_SERVER_OPERATOR) || | |
| 373 | (mode & SILC_UMODE_ROUTER_OPERATOR)) { | |
| 374 | strcat(buf, (mode & SILC_UMODE_SERVER_OPERATOR) ? | |
| 375 | "[server operator] " : | |
| 376 | (mode & SILC_UMODE_ROUTER_OPERATOR) ? | |
| 377 | "[SILC operator] " : "[unknown mode] "); | |
| 378 | } | |
| 379 | if (mode & SILC_UMODE_GONE) | |
| 380 | strcat(buf, "[away] "); | |
| 381 | if (mode & SILC_UMODE_INDISPOSED) | |
| 382 | strcat(buf, "[indisposed] "); | |
| 383 | if (mode & SILC_UMODE_BUSY) | |
| 384 | strcat(buf, "[busy] "); | |
| 385 | if (mode & SILC_UMODE_PAGE) | |
| 386 | strcat(buf, "[wake me up] "); | |
| 387 | if (mode & SILC_UMODE_HYPER) | |
| 388 | strcat(buf, "[hyperactive] "); | |
| 389 | if (mode & SILC_UMODE_ROBOT) | |
| 390 | strcat(buf, "[robot] "); | |
| 391 | if (mode & SILC_UMODE_ANONYMOUS) | |
| 392 | strcat(buf, "[anonymous] "); | |
| 393 | if (mode & SILC_UMODE_BLOCK_PRIVMSG) | |
| 394 | strcat(buf, "[blocks private messages] "); | |
| 395 | if (mode & SILC_UMODE_DETACHED) | |
| 396 | strcat(buf, "[detached] "); | |
| 397 | if (mode & SILC_UMODE_REJECT_WATCHING) | |
| 398 | strcat(buf, "[rejects watching] "); | |
| 399 | if (mode & SILC_UMODE_BLOCK_INVITE) | |
| 400 | 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
|
401 | g_strchomp(buf); |
| 8849 | 402 | } |
| 403 | ||
| 15884 | 404 | 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
|
405 | SilcUInt32 buf_size) |
| 8849 | 406 | { |
| 407 | memset(buf, 0, buf_size); | |
| 408 | if (mode & SILC_CHANNEL_MODE_FOUNDER_AUTH) | |
| 409 | strcat(buf, "[permanent] "); | |
| 410 | if (mode & SILC_CHANNEL_MODE_PRIVATE) | |
| 411 | strcat(buf, "[private] "); | |
| 412 | if (mode & SILC_CHANNEL_MODE_SECRET) | |
| 413 | strcat(buf, "[secret] "); | |
| 414 | if (mode & SILC_CHANNEL_MODE_PRIVKEY) | |
| 415 | strcat(buf, "[private key] "); | |
| 416 | if (mode & SILC_CHANNEL_MODE_INVITE) | |
| 417 | strcat(buf, "[invite only] "); | |
| 418 | if (mode & SILC_CHANNEL_MODE_TOPIC) | |
| 419 | strcat(buf, "[topic restricted] "); | |
| 420 | if (mode & SILC_CHANNEL_MODE_ULIMIT) | |
| 421 | strcat(buf, "[user count limit] "); | |
| 422 | if (mode & SILC_CHANNEL_MODE_PASSPHRASE) | |
| 423 | strcat(buf, "[passphrase auth] "); | |
| 424 | if (mode & SILC_CHANNEL_MODE_CHANNEL_AUTH) | |
| 425 | strcat(buf, "[public key auth] "); | |
| 426 | if (mode & SILC_CHANNEL_MODE_SILENCE_USERS) | |
| 427 | strcat(buf, "[users silenced] "); | |
| 428 | if (mode & SILC_CHANNEL_MODE_SILENCE_OPERS) | |
| 429 | 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
|
430 | g_strchomp(buf); |
| 8849 | 431 | } |
| 432 | ||
| 15884 | 433 | void silcpurple_get_chumode_string(SilcUInt32 mode, char *buf, |
| 8849 | 434 | SilcUInt32 buf_size) |
| 435 | { | |
| 436 | memset(buf, 0, buf_size); | |
| 437 | if (mode & SILC_CHANNEL_UMODE_CHANFO) | |
| 438 | strcat(buf, "[founder] "); | |
| 439 | if (mode & SILC_CHANNEL_UMODE_CHANOP) | |
| 440 | strcat(buf, "[operator] "); | |
| 441 | if (mode & SILC_CHANNEL_UMODE_BLOCK_MESSAGES) | |
| 442 | strcat(buf, "[blocks messages] "); | |
| 443 | if (mode & SILC_CHANNEL_UMODE_BLOCK_MESSAGES_USERS) | |
| 444 | strcat(buf, "[blocks user messages] "); | |
| 445 | if (mode & SILC_CHANNEL_UMODE_BLOCK_MESSAGES_ROBOTS) | |
| 446 | strcat(buf, "[blocks robot messages] "); | |
| 447 | if (mode & SILC_CHANNEL_UMODE_QUIET) | |
| 448 | strcat(buf, "[quieted] "); | |
|
22470
6fb4ab976585
chomp chomp chomp chomp chomp chomp chomp chomp chomp chomp
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
21630
diff
changeset
|
449 | g_strchomp(buf); |
| 8849 | 450 | } |
|
9488
9d6520fa53fd
[gaim-migrate @ 10313]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
9353
diff
changeset
|
451 | |
|
9d6520fa53fd
[gaim-migrate @ 10313]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
9353
diff
changeset
|
452 | void |
| 15884 | 453 | 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
|
454 | 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
|
455 | char **tzstr, char **geostr) |
|
9488
9d6520fa53fd
[gaim-migrate @ 10313]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
9353
diff
changeset
|
456 | { |
|
9d6520fa53fd
[gaim-migrate @ 10313]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
9353
diff
changeset
|
457 | SilcAttributePayload attr; |
|
9d6520fa53fd
[gaim-migrate @ 10313]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
9353
diff
changeset
|
458 | SilcAttributeMood mood = 0; |
|
9d6520fa53fd
[gaim-migrate @ 10313]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
9353
diff
changeset
|
459 | SilcAttributeContact contact; |
|
9d6520fa53fd
[gaim-migrate @ 10313]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
9353
diff
changeset
|
460 | SilcAttributeObjDevice device; |
|
9d6520fa53fd
[gaim-migrate @ 10313]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
9353
diff
changeset
|
461 | SilcAttributeObjGeo geo; |
|
9d6520fa53fd
[gaim-migrate @ 10313]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
9353
diff
changeset
|
462 | |
|
9d6520fa53fd
[gaim-migrate @ 10313]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
9353
diff
changeset
|
463 | char tmp[1024]; |
|
9d6520fa53fd
[gaim-migrate @ 10313]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
9353
diff
changeset
|
464 | GString *s; |
|
9d6520fa53fd
[gaim-migrate @ 10313]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
9353
diff
changeset
|
465 | |
|
9d6520fa53fd
[gaim-migrate @ 10313]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
9353
diff
changeset
|
466 | *moodstr = NULL; |
|
9d6520fa53fd
[gaim-migrate @ 10313]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
9353
diff
changeset
|
467 | *statusstr = NULL; |
|
9d6520fa53fd
[gaim-migrate @ 10313]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
9353
diff
changeset
|
468 | *contactstr = NULL; |
|
9d6520fa53fd
[gaim-migrate @ 10313]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
9353
diff
changeset
|
469 | *langstr = NULL; |
|
9d6520fa53fd
[gaim-migrate @ 10313]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
9353
diff
changeset
|
470 | *devicestr = NULL; |
|
9d6520fa53fd
[gaim-migrate @ 10313]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
9353
diff
changeset
|
471 | *tzstr = NULL; |
|
9d6520fa53fd
[gaim-migrate @ 10313]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
9353
diff
changeset
|
472 | *geostr = NULL; |
|
9d6520fa53fd
[gaim-migrate @ 10313]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
9353
diff
changeset
|
473 | |
|
9d6520fa53fd
[gaim-migrate @ 10313]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
9353
diff
changeset
|
474 | if (!attrs) |
|
9d6520fa53fd
[gaim-migrate @ 10313]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
9353
diff
changeset
|
475 | return; |
|
9d6520fa53fd
[gaim-migrate @ 10313]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
9353
diff
changeset
|
476 | |
|
9d6520fa53fd
[gaim-migrate @ 10313]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
9353
diff
changeset
|
477 | s = g_string_new(""); |
| 15884 | 478 | attr = silcpurple_get_attr(attrs, SILC_ATTRIBUTE_STATUS_MOOD); |
|
9488
9d6520fa53fd
[gaim-migrate @ 10313]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
9353
diff
changeset
|
479 | if (attr && silc_attribute_get_object(attr, &mood, sizeof(mood))) { |
|
9d6520fa53fd
[gaim-migrate @ 10313]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
9353
diff
changeset
|
480 | if (mood & SILC_ATTRIBUTE_MOOD_HAPPY) |
|
9d6520fa53fd
[gaim-migrate @ 10313]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
9353
diff
changeset
|
481 | g_string_append_printf(s, "[%s] ", _("Happy")); |
|
9d6520fa53fd
[gaim-migrate @ 10313]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
9353
diff
changeset
|
482 | if (mood & SILC_ATTRIBUTE_MOOD_SAD) |
|
9d6520fa53fd
[gaim-migrate @ 10313]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
9353
diff
changeset
|
483 | g_string_append_printf(s, "[%s] ", _("Sad")); |
|
9d6520fa53fd
[gaim-migrate @ 10313]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
9353
diff
changeset
|
484 | if (mood & SILC_ATTRIBUTE_MOOD_ANGRY) |
|
9d6520fa53fd
[gaim-migrate @ 10313]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
9353
diff
changeset
|
485 | g_string_append_printf(s, "[%s] ", _("Angry")); |
|
9d6520fa53fd
[gaim-migrate @ 10313]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
9353
diff
changeset
|
486 | if (mood & SILC_ATTRIBUTE_MOOD_JEALOUS) |
|
9d6520fa53fd
[gaim-migrate @ 10313]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
9353
diff
changeset
|
487 | g_string_append_printf(s, "[%s] ", _("Jealous")); |
|
9d6520fa53fd
[gaim-migrate @ 10313]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
9353
diff
changeset
|
488 | if (mood & SILC_ATTRIBUTE_MOOD_ASHAMED) |
|
9d6520fa53fd
[gaim-migrate @ 10313]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
9353
diff
changeset
|
489 | g_string_append_printf(s, "[%s] ", _("Ashamed")); |
|
9d6520fa53fd
[gaim-migrate @ 10313]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
9353
diff
changeset
|
490 | if (mood & SILC_ATTRIBUTE_MOOD_INVINCIBLE) |
|
9d6520fa53fd
[gaim-migrate @ 10313]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
9353
diff
changeset
|
491 | g_string_append_printf(s, "[%s] ", _("Invincible")); |
|
9d6520fa53fd
[gaim-migrate @ 10313]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
9353
diff
changeset
|
492 | if (mood & SILC_ATTRIBUTE_MOOD_INLOVE) |
|
9d6520fa53fd
[gaim-migrate @ 10313]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
9353
diff
changeset
|
493 | g_string_append_printf(s, "[%s] ", _("In Love")); |
|
9d6520fa53fd
[gaim-migrate @ 10313]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
9353
diff
changeset
|
494 | if (mood & SILC_ATTRIBUTE_MOOD_SLEEPY) |
|
9d6520fa53fd
[gaim-migrate @ 10313]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
9353
diff
changeset
|
495 | g_string_append_printf(s, "[%s] ", _("Sleepy")); |
|
9d6520fa53fd
[gaim-migrate @ 10313]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
9353
diff
changeset
|
496 | if (mood & SILC_ATTRIBUTE_MOOD_BORED) |
|
9d6520fa53fd
[gaim-migrate @ 10313]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
9353
diff
changeset
|
497 | g_string_append_printf(s, "[%s] ", _("Bored")); |
|
9d6520fa53fd
[gaim-migrate @ 10313]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
9353
diff
changeset
|
498 | if (mood & SILC_ATTRIBUTE_MOOD_EXCITED) |
|
9d6520fa53fd
[gaim-migrate @ 10313]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
9353
diff
changeset
|
499 | g_string_append_printf(s, "[%s] ", _("Excited")); |
|
9d6520fa53fd
[gaim-migrate @ 10313]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
9353
diff
changeset
|
500 | if (mood & SILC_ATTRIBUTE_MOOD_ANXIOUS) |
|
9d6520fa53fd
[gaim-migrate @ 10313]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
9353
diff
changeset
|
501 | g_string_append_printf(s, "[%s] ", _("Anxious")); |
|
9d6520fa53fd
[gaim-migrate @ 10313]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
9353
diff
changeset
|
502 | } |
|
37523
02346b6472b3
Simplify checks for empty strings
Michael McConville <mmcconville@mykolab.com>
parents:
36034
diff
changeset
|
503 | if (*s->str != '\0') { |
|
22972
2942c1995c22
Cleanup allocations/frees to match and plug some leaks.
Daniel Atallah <datallah@pidgin.im>
parents:
22470
diff
changeset
|
504 | *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
|
505 | g_strchomp(*moodstr); |
|
9488
9d6520fa53fd
[gaim-migrate @ 10313]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
9353
diff
changeset
|
506 | } else |
|
9d6520fa53fd
[gaim-migrate @ 10313]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
9353
diff
changeset
|
507 | g_string_free(s, TRUE); |
|
9d6520fa53fd
[gaim-migrate @ 10313]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
9353
diff
changeset
|
508 | |
| 15884 | 509 | attr = silcpurple_get_attr(attrs, SILC_ATTRIBUTE_STATUS_FREETEXT); |
|
9488
9d6520fa53fd
[gaim-migrate @ 10313]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
9353
diff
changeset
|
510 | memset(tmp, 0, sizeof(tmp)); |
|
9d6520fa53fd
[gaim-migrate @ 10313]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
9353
diff
changeset
|
511 | if (attr && silc_attribute_get_object(attr, tmp, sizeof(tmp))) |
|
9d6520fa53fd
[gaim-migrate @ 10313]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
9353
diff
changeset
|
512 | *statusstr = g_strdup(tmp); |
|
9d6520fa53fd
[gaim-migrate @ 10313]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
9353
diff
changeset
|
513 | |
|
9d6520fa53fd
[gaim-migrate @ 10313]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
9353
diff
changeset
|
514 | s = g_string_new(""); |
| 15884 | 515 | attr = silcpurple_get_attr(attrs, SILC_ATTRIBUTE_PREFERRED_CONTACT); |
|
9488
9d6520fa53fd
[gaim-migrate @ 10313]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
9353
diff
changeset
|
516 | if (attr && silc_attribute_get_object(attr, &contact, sizeof(contact))) { |
|
9d6520fa53fd
[gaim-migrate @ 10313]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
9353
diff
changeset
|
517 | if (contact & SILC_ATTRIBUTE_CONTACT_CHAT) |
|
9d6520fa53fd
[gaim-migrate @ 10313]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
9353
diff
changeset
|
518 | g_string_append_printf(s, "[%s] ", _("Chat")); |
|
9d6520fa53fd
[gaim-migrate @ 10313]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
9353
diff
changeset
|
519 | 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
|
520 | g_string_append_printf(s, "[%s] ", _("Email")); |
|
9488
9d6520fa53fd
[gaim-migrate @ 10313]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
9353
diff
changeset
|
521 | if (contact & SILC_ATTRIBUTE_CONTACT_CALL) |
|
9d6520fa53fd
[gaim-migrate @ 10313]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
9353
diff
changeset
|
522 | g_string_append_printf(s, "[%s] ", _("Phone")); |
|
9d6520fa53fd
[gaim-migrate @ 10313]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
9353
diff
changeset
|
523 | if (contact & SILC_ATTRIBUTE_CONTACT_PAGE) |
|
9d6520fa53fd
[gaim-migrate @ 10313]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
9353
diff
changeset
|
524 | g_string_append_printf(s, "[%s] ", _("Paging")); |
|
9d6520fa53fd
[gaim-migrate @ 10313]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
9353
diff
changeset
|
525 | if (contact & SILC_ATTRIBUTE_CONTACT_SMS) |
|
9d6520fa53fd
[gaim-migrate @ 10313]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
9353
diff
changeset
|
526 | g_string_append_printf(s, "[%s] ", _("SMS")); |
|
9d6520fa53fd
[gaim-migrate @ 10313]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
9353
diff
changeset
|
527 | if (contact & SILC_ATTRIBUTE_CONTACT_MMS) |
|
9d6520fa53fd
[gaim-migrate @ 10313]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
9353
diff
changeset
|
528 | g_string_append_printf(s, "[%s] ", _("MMS")); |
|
9d6520fa53fd
[gaim-migrate @ 10313]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
9353
diff
changeset
|
529 | if (contact & SILC_ATTRIBUTE_CONTACT_VIDEO) |
|
9d6520fa53fd
[gaim-migrate @ 10313]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
9353
diff
changeset
|
530 | g_string_append_printf(s, "[%s] ", _("Video Conferencing")); |
|
9d6520fa53fd
[gaim-migrate @ 10313]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
9353
diff
changeset
|
531 | } |
|
37523
02346b6472b3
Simplify checks for empty strings
Michael McConville <mmcconville@mykolab.com>
parents:
36034
diff
changeset
|
532 | if (*s->str != '\0') { |
|
22972
2942c1995c22
Cleanup allocations/frees to match and plug some leaks.
Daniel Atallah <datallah@pidgin.im>
parents:
22470
diff
changeset
|
533 | *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
|
534 | g_strchomp(*contactstr); |
|
9488
9d6520fa53fd
[gaim-migrate @ 10313]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
9353
diff
changeset
|
535 | } else |
|
9d6520fa53fd
[gaim-migrate @ 10313]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
9353
diff
changeset
|
536 | g_string_free(s, TRUE); |
|
9d6520fa53fd
[gaim-migrate @ 10313]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
9353
diff
changeset
|
537 | |
| 15884 | 538 | attr = silcpurple_get_attr(attrs, SILC_ATTRIBUTE_PREFERRED_LANGUAGE); |
|
9488
9d6520fa53fd
[gaim-migrate @ 10313]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
9353
diff
changeset
|
539 | memset(tmp, 0, sizeof(tmp)); |
|
9d6520fa53fd
[gaim-migrate @ 10313]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
9353
diff
changeset
|
540 | if (attr && silc_attribute_get_object(attr, tmp, sizeof(tmp))) |
|
9d6520fa53fd
[gaim-migrate @ 10313]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
9353
diff
changeset
|
541 | *langstr = g_strdup(tmp); |
|
9d6520fa53fd
[gaim-migrate @ 10313]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
9353
diff
changeset
|
542 | |
|
9d6520fa53fd
[gaim-migrate @ 10313]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
9353
diff
changeset
|
543 | s = g_string_new(""); |
| 15884 | 544 | attr = silcpurple_get_attr(attrs, SILC_ATTRIBUTE_DEVICE_INFO); |
|
9488
9d6520fa53fd
[gaim-migrate @ 10313]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
9353
diff
changeset
|
545 | memset(&device, 0, sizeof(device)); |
|
9d6520fa53fd
[gaim-migrate @ 10313]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
9353
diff
changeset
|
546 | if (attr && silc_attribute_get_object(attr, &device, sizeof(device))) { |
|
9d6520fa53fd
[gaim-migrate @ 10313]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
9353
diff
changeset
|
547 | if (device.type == SILC_ATTRIBUTE_DEVICE_COMPUTER) |
|
9d6520fa53fd
[gaim-migrate @ 10313]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
9353
diff
changeset
|
548 | g_string_append_printf(s, "%s: ", _("Computer")); |
|
9d6520fa53fd
[gaim-migrate @ 10313]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
9353
diff
changeset
|
549 | if (device.type == SILC_ATTRIBUTE_DEVICE_MOBILE_PHONE) |
|
9d6520fa53fd
[gaim-migrate @ 10313]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
9353
diff
changeset
|
550 | g_string_append_printf(s, "%s: ", _("Mobile Phone")); |
|
9d6520fa53fd
[gaim-migrate @ 10313]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
9353
diff
changeset
|
551 | if (device.type == SILC_ATTRIBUTE_DEVICE_PDA) |
|
9d6520fa53fd
[gaim-migrate @ 10313]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
9353
diff
changeset
|
552 | g_string_append_printf(s, "%s: ", _("PDA")); |
|
9d6520fa53fd
[gaim-migrate @ 10313]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
9353
diff
changeset
|
553 | if (device.type == SILC_ATTRIBUTE_DEVICE_TERMINAL) |
|
9d6520fa53fd
[gaim-migrate @ 10313]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
9353
diff
changeset
|
554 | g_string_append_printf(s, "%s: ", _("Terminal")); |
|
9d6520fa53fd
[gaim-migrate @ 10313]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
9353
diff
changeset
|
555 | g_string_append_printf(s, "%s %s %s %s", |
|
9d6520fa53fd
[gaim-migrate @ 10313]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
9353
diff
changeset
|
556 | device.manufacturer ? device.manufacturer : "", |
|
9d6520fa53fd
[gaim-migrate @ 10313]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
9353
diff
changeset
|
557 | device.version ? device.version : "", |
|
9d6520fa53fd
[gaim-migrate @ 10313]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
9353
diff
changeset
|
558 | device.model ? device.model : "", |
|
9d6520fa53fd
[gaim-migrate @ 10313]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
9353
diff
changeset
|
559 | device.language ? device.language : ""); |
|
9d6520fa53fd
[gaim-migrate @ 10313]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
9353
diff
changeset
|
560 | } |
|
37523
02346b6472b3
Simplify checks for empty strings
Michael McConville <mmcconville@mykolab.com>
parents:
36034
diff
changeset
|
561 | if (*s->str != '\0') |
|
22972
2942c1995c22
Cleanup allocations/frees to match and plug some leaks.
Daniel Atallah <datallah@pidgin.im>
parents:
22470
diff
changeset
|
562 | *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
|
563 | else |
|
9488
9d6520fa53fd
[gaim-migrate @ 10313]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
9353
diff
changeset
|
564 | g_string_free(s, TRUE); |
|
9d6520fa53fd
[gaim-migrate @ 10313]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
9353
diff
changeset
|
565 | |
| 15884 | 566 | attr = silcpurple_get_attr(attrs, SILC_ATTRIBUTE_TIMEZONE); |
|
9488
9d6520fa53fd
[gaim-migrate @ 10313]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
9353
diff
changeset
|
567 | memset(tmp, 0, sizeof(tmp)); |
|
9d6520fa53fd
[gaim-migrate @ 10313]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
9353
diff
changeset
|
568 | if (attr && silc_attribute_get_object(attr, tmp, sizeof(tmp))) |
|
9d6520fa53fd
[gaim-migrate @ 10313]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
9353
diff
changeset
|
569 | *tzstr = g_strdup(tmp); |
|
9d6520fa53fd
[gaim-migrate @ 10313]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
9353
diff
changeset
|
570 | |
| 15884 | 571 | attr = silcpurple_get_attr(attrs, SILC_ATTRIBUTE_GEOLOCATION); |
|
9488
9d6520fa53fd
[gaim-migrate @ 10313]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
9353
diff
changeset
|
572 | memset(&geo, 0, sizeof(geo)); |
|
9d6520fa53fd
[gaim-migrate @ 10313]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
9353
diff
changeset
|
573 | if (attr && silc_attribute_get_object(attr, &geo, sizeof(geo))) |
|
9d6520fa53fd
[gaim-migrate @ 10313]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
9353
diff
changeset
|
574 | *geostr = g_strdup_printf("%s %s %s (%s)", |
|
9d6520fa53fd
[gaim-migrate @ 10313]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
9353
diff
changeset
|
575 | geo.longitude ? geo.longitude : "", |
|
9d6520fa53fd
[gaim-migrate @ 10313]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
9353
diff
changeset
|
576 | geo.latitude ? geo.latitude : "", |
|
9d6520fa53fd
[gaim-migrate @ 10313]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
9353
diff
changeset
|
577 | geo.altitude ? geo.altitude : "", |
|
9d6520fa53fd
[gaim-migrate @ 10313]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
9353
diff
changeset
|
578 | geo.accuracy ? geo.accuracy : ""); |
|
9d6520fa53fd
[gaim-migrate @ 10313]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
9353
diff
changeset
|
579 | } |
|
12217
ea610d8ab584
[gaim-migrate @ 14519]
Pekka Riikonen <priikone@silcnet.org>
parents:
11488
diff
changeset
|
580 | |
|
17675
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
17156
diff
changeset
|
581 | /* 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
|
582 | 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
|
583 | 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
|
584 | message is created. */ |
|
ea610d8ab584
[gaim-migrate @ 14519]
Pekka Riikonen <priikone@silcnet.org>
parents:
11488
diff
changeset
|
585 | |
|
33798
ab26d8e3da97
silc: Use appropriate datatype for SilcMessageFlags
Daniel Atallah <datallah@pidgin.im>
parents:
28981
diff
changeset
|
586 | SilcDList silcpurple_image_message(const char *msg, SilcMessageFlags *mflags) |
|
12217
ea610d8ab584
[gaim-migrate @ 14519]
Pekka Riikonen <priikone@silcnet.org>
parents:
11488
diff
changeset
|
587 | { |
|
ea610d8ab584
[gaim-migrate @ 14519]
Pekka Riikonen <priikone@silcnet.org>
parents:
11488
diff
changeset
|
588 | SilcMime mime = NULL, p; |
|
ea610d8ab584
[gaim-migrate @ 14519]
Pekka Riikonen <priikone@silcnet.org>
parents:
11488
diff
changeset
|
589 | SilcDList list, parts = NULL; |
|
ea610d8ab584
[gaim-migrate @ 14519]
Pekka Riikonen <priikone@silcnet.org>
parents:
11488
diff
changeset
|
590 | const char *start, *end, *last; |
|
ea610d8ab584
[gaim-migrate @ 14519]
Pekka Riikonen <priikone@silcnet.org>
parents:
11488
diff
changeset
|
591 | GData *attribs; |
|
ea610d8ab584
[gaim-migrate @ 14519]
Pekka Riikonen <priikone@silcnet.org>
parents:
11488
diff
changeset
|
592 | gboolean images = FALSE; |
|
ea610d8ab584
[gaim-migrate @ 14519]
Pekka Riikonen <priikone@silcnet.org>
parents:
11488
diff
changeset
|
593 | |
|
ea610d8ab584
[gaim-migrate @ 14519]
Pekka Riikonen <priikone@silcnet.org>
parents:
11488
diff
changeset
|
594 | last = msg; |
| 15884 | 595 | while (last && *last && purple_markup_find_tag("img", last, &start, |
|
12217
ea610d8ab584
[gaim-migrate @ 14519]
Pekka Riikonen <priikone@silcnet.org>
parents:
11488
diff
changeset
|
596 | &end, &attribs)) { |
|
35833
a7bfc2479cbd
imgstore: unref silc; fix inline images in silc
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35681
diff
changeset
|
597 | PurpleImage *image = NULL; |
|
a7bfc2479cbd
imgstore: unref silc; fix inline images in silc
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35681
diff
changeset
|
598 | const gchar *uri; |
|
12217
ea610d8ab584
[gaim-migrate @ 14519]
Pekka Riikonen <priikone@silcnet.org>
parents:
11488
diff
changeset
|
599 | |
|
ea610d8ab584
[gaim-migrate @ 14519]
Pekka Riikonen <priikone@silcnet.org>
parents:
11488
diff
changeset
|
600 | /* Check if there is text before image */ |
|
ea610d8ab584
[gaim-migrate @ 14519]
Pekka Riikonen <priikone@silcnet.org>
parents:
11488
diff
changeset
|
601 | if (start - last) { |
|
ea610d8ab584
[gaim-migrate @ 14519]
Pekka Riikonen <priikone@silcnet.org>
parents:
11488
diff
changeset
|
602 | char *text, *tmp; |
|
ea610d8ab584
[gaim-migrate @ 14519]
Pekka Riikonen <priikone@silcnet.org>
parents:
11488
diff
changeset
|
603 | p = silc_mime_alloc(); |
|
ea610d8ab584
[gaim-migrate @ 14519]
Pekka Riikonen <priikone@silcnet.org>
parents:
11488
diff
changeset
|
604 | |
|
ea610d8ab584
[gaim-migrate @ 14519]
Pekka Riikonen <priikone@silcnet.org>
parents:
11488
diff
changeset
|
605 | /* Add content type */ |
|
ea610d8ab584
[gaim-migrate @ 14519]
Pekka Riikonen <priikone@silcnet.org>
parents:
11488
diff
changeset
|
606 | silc_mime_add_field(p, "Content-Type", |
|
ea610d8ab584
[gaim-migrate @ 14519]
Pekka Riikonen <priikone@silcnet.org>
parents:
11488
diff
changeset
|
607 | "text/plain; charset=utf-8"); |
|
ea610d8ab584
[gaim-migrate @ 14519]
Pekka Riikonen <priikone@silcnet.org>
parents:
11488
diff
changeset
|
608 | |
|
ea610d8ab584
[gaim-migrate @ 14519]
Pekka Riikonen <priikone@silcnet.org>
parents:
11488
diff
changeset
|
609 | tmp = g_strndup(last, start - last); |
| 15884 | 610 | text = purple_unescape_html(tmp); |
|
12217
ea610d8ab584
[gaim-migrate @ 14519]
Pekka Riikonen <priikone@silcnet.org>
parents:
11488
diff
changeset
|
611 | 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
|
612 | |
|
12217
ea610d8ab584
[gaim-migrate @ 14519]
Pekka Riikonen <priikone@silcnet.org>
parents:
11488
diff
changeset
|
613 | /* 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
|
614 | 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
|
615 | g_free(text); |
|
ea610d8ab584
[gaim-migrate @ 14519]
Pekka Riikonen <priikone@silcnet.org>
parents:
11488
diff
changeset
|
616 | |
|
ea610d8ab584
[gaim-migrate @ 14519]
Pekka Riikonen <priikone@silcnet.org>
parents:
11488
diff
changeset
|
617 | if (!parts) |
|
ea610d8ab584
[gaim-migrate @ 14519]
Pekka Riikonen <priikone@silcnet.org>
parents:
11488
diff
changeset
|
618 | parts = silc_dlist_init(); |
|
ea610d8ab584
[gaim-migrate @ 14519]
Pekka Riikonen <priikone@silcnet.org>
parents:
11488
diff
changeset
|
619 | silc_dlist_add(parts, p); |
|
ea610d8ab584
[gaim-migrate @ 14519]
Pekka Riikonen <priikone@silcnet.org>
parents:
11488
diff
changeset
|
620 | } |
|
ea610d8ab584
[gaim-migrate @ 14519]
Pekka Riikonen <priikone@silcnet.org>
parents:
11488
diff
changeset
|
621 | |
|
35833
a7bfc2479cbd
imgstore: unref silc; fix inline images in silc
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35681
diff
changeset
|
622 | uri = g_datalist_get_data(&attribs, "src"); |
|
a7bfc2479cbd
imgstore: unref silc; fix inline images in silc
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35681
diff
changeset
|
623 | if (uri) |
|
a7bfc2479cbd
imgstore: unref silc; fix inline images in silc
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35681
diff
changeset
|
624 | image = purple_image_store_get_from_uri(uri); |
|
a7bfc2479cbd
imgstore: unref silc; fix inline images in silc
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35681
diff
changeset
|
625 | if (uri) { |
|
a7bfc2479cbd
imgstore: unref silc; fix inline images in silc
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35681
diff
changeset
|
626 | unsigned long imglen = purple_image_get_size(image); |
|
a7bfc2479cbd
imgstore: unref silc; fix inline images in silc
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35681
diff
changeset
|
627 | gconstpointer img = purple_image_get_data(image); |
|
a7bfc2479cbd
imgstore: unref silc; fix inline images in silc
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35681
diff
changeset
|
628 | const gchar *type; |
|
12217
ea610d8ab584
[gaim-migrate @ 14519]
Pekka Riikonen <priikone@silcnet.org>
parents:
11488
diff
changeset
|
629 | |
|
ea610d8ab584
[gaim-migrate @ 14519]
Pekka Riikonen <priikone@silcnet.org>
parents:
11488
diff
changeset
|
630 | p = silc_mime_alloc(); |
|
ea610d8ab584
[gaim-migrate @ 14519]
Pekka Riikonen <priikone@silcnet.org>
parents:
11488
diff
changeset
|
631 | |
|
ea610d8ab584
[gaim-migrate @ 14519]
Pekka Riikonen <priikone@silcnet.org>
parents:
11488
diff
changeset
|
632 | /* Add content type */ |
|
35833
a7bfc2479cbd
imgstore: unref silc; fix inline images in silc
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35681
diff
changeset
|
633 | type = purple_image_get_mimetype(image); |
|
12217
ea610d8ab584
[gaim-migrate @ 14519]
Pekka Riikonen <priikone@silcnet.org>
parents:
11488
diff
changeset
|
634 | if (!type) { |
|
ea610d8ab584
[gaim-migrate @ 14519]
Pekka Riikonen <priikone@silcnet.org>
parents:
11488
diff
changeset
|
635 | g_datalist_clear(&attribs); |
|
ea610d8ab584
[gaim-migrate @ 14519]
Pekka Riikonen <priikone@silcnet.org>
parents:
11488
diff
changeset
|
636 | last = end + 1; |
|
ea610d8ab584
[gaim-migrate @ 14519]
Pekka Riikonen <priikone@silcnet.org>
parents:
11488
diff
changeset
|
637 | continue; |
|
ea610d8ab584
[gaim-migrate @ 14519]
Pekka Riikonen <priikone@silcnet.org>
parents:
11488
diff
changeset
|
638 | } |
|
ea610d8ab584
[gaim-migrate @ 14519]
Pekka Riikonen <priikone@silcnet.org>
parents:
11488
diff
changeset
|
639 | silc_mime_add_field(p, "Content-Type", type); |
|
ea610d8ab584
[gaim-migrate @ 14519]
Pekka Riikonen <priikone@silcnet.org>
parents:
11488
diff
changeset
|
640 | |
|
ea610d8ab584
[gaim-migrate @ 14519]
Pekka Riikonen <priikone@silcnet.org>
parents:
11488
diff
changeset
|
641 | /* Add content transfer encoding */ |
|
ea610d8ab584
[gaim-migrate @ 14519]
Pekka Riikonen <priikone@silcnet.org>
parents:
11488
diff
changeset
|
642 | silc_mime_add_field(p, "Content-Transfer-Encoding", "binary"); |
|
ea610d8ab584
[gaim-migrate @ 14519]
Pekka Riikonen <priikone@silcnet.org>
parents:
11488
diff
changeset
|
643 | |
|
ea610d8ab584
[gaim-migrate @ 14519]
Pekka Riikonen <priikone@silcnet.org>
parents:
11488
diff
changeset
|
644 | /* Add image data */ |
|
ea610d8ab584
[gaim-migrate @ 14519]
Pekka Riikonen <priikone@silcnet.org>
parents:
11488
diff
changeset
|
645 | silc_mime_add_data(p, img, imglen); |
|
ea610d8ab584
[gaim-migrate @ 14519]
Pekka Riikonen <priikone@silcnet.org>
parents:
11488
diff
changeset
|
646 | |
|
ea610d8ab584
[gaim-migrate @ 14519]
Pekka Riikonen <priikone@silcnet.org>
parents:
11488
diff
changeset
|
647 | if (!parts) |
|
ea610d8ab584
[gaim-migrate @ 14519]
Pekka Riikonen <priikone@silcnet.org>
parents:
11488
diff
changeset
|
648 | parts = silc_dlist_init(); |
|
ea610d8ab584
[gaim-migrate @ 14519]
Pekka Riikonen <priikone@silcnet.org>
parents:
11488
diff
changeset
|
649 | silc_dlist_add(parts, p); |
|
ea610d8ab584
[gaim-migrate @ 14519]
Pekka Riikonen <priikone@silcnet.org>
parents:
11488
diff
changeset
|
650 | images = TRUE; |
|
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 | |
|
ea610d8ab584
[gaim-migrate @ 14519]
Pekka Riikonen <priikone@silcnet.org>
parents:
11488
diff
changeset
|
653 | g_datalist_clear(&attribs); |
|
ea610d8ab584
[gaim-migrate @ 14519]
Pekka Riikonen <priikone@silcnet.org>
parents:
11488
diff
changeset
|
654 | |
|
ea610d8ab584
[gaim-migrate @ 14519]
Pekka Riikonen <priikone@silcnet.org>
parents:
11488
diff
changeset
|
655 | /* Continue after tag */ |
|
ea610d8ab584
[gaim-migrate @ 14519]
Pekka Riikonen <priikone@silcnet.org>
parents:
11488
diff
changeset
|
656 | last = end + 1; |
|
ea610d8ab584
[gaim-migrate @ 14519]
Pekka Riikonen <priikone@silcnet.org>
parents:
11488
diff
changeset
|
657 | } |
|
ea610d8ab584
[gaim-migrate @ 14519]
Pekka Riikonen <priikone@silcnet.org>
parents:
11488
diff
changeset
|
658 | |
|
ea610d8ab584
[gaim-migrate @ 14519]
Pekka Riikonen <priikone@silcnet.org>
parents:
11488
diff
changeset
|
659 | /* Check for text after the image(s) */ |
|
ea610d8ab584
[gaim-migrate @ 14519]
Pekka Riikonen <priikone@silcnet.org>
parents:
11488
diff
changeset
|
660 | if (images && last && *last) { |
| 15884 | 661 | char *tmp = purple_unescape_html(last); |
|
12217
ea610d8ab584
[gaim-migrate @ 14519]
Pekka Riikonen <priikone@silcnet.org>
parents:
11488
diff
changeset
|
662 | p = silc_mime_alloc(); |
|
ea610d8ab584
[gaim-migrate @ 14519]
Pekka Riikonen <priikone@silcnet.org>
parents:
11488
diff
changeset
|
663 | |
|
ea610d8ab584
[gaim-migrate @ 14519]
Pekka Riikonen <priikone@silcnet.org>
parents:
11488
diff
changeset
|
664 | /* Add content type */ |
|
ea610d8ab584
[gaim-migrate @ 14519]
Pekka Riikonen <priikone@silcnet.org>
parents:
11488
diff
changeset
|
665 | silc_mime_add_field(p, "Content-Type", |
|
ea610d8ab584
[gaim-migrate @ 14519]
Pekka Riikonen <priikone@silcnet.org>
parents:
11488
diff
changeset
|
666 | "text/plain; charset=utf-8"); |
|
ea610d8ab584
[gaim-migrate @ 14519]
Pekka Riikonen <priikone@silcnet.org>
parents:
11488
diff
changeset
|
667 | |
|
ea610d8ab584
[gaim-migrate @ 14519]
Pekka Riikonen <priikone@silcnet.org>
parents:
11488
diff
changeset
|
668 | /* 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
|
669 | 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
|
670 | g_free(tmp); |
|
ea610d8ab584
[gaim-migrate @ 14519]
Pekka Riikonen <priikone@silcnet.org>
parents:
11488
diff
changeset
|
671 | |
|
ea610d8ab584
[gaim-migrate @ 14519]
Pekka Riikonen <priikone@silcnet.org>
parents:
11488
diff
changeset
|
672 | if (!parts) |
|
ea610d8ab584
[gaim-migrate @ 14519]
Pekka Riikonen <priikone@silcnet.org>
parents:
11488
diff
changeset
|
673 | parts = silc_dlist_init(); |
|
ea610d8ab584
[gaim-migrate @ 14519]
Pekka Riikonen <priikone@silcnet.org>
parents:
11488
diff
changeset
|
674 | silc_dlist_add(parts, p); |
|
ea610d8ab584
[gaim-migrate @ 14519]
Pekka Riikonen <priikone@silcnet.org>
parents:
11488
diff
changeset
|
675 | } |
|
ea610d8ab584
[gaim-migrate @ 14519]
Pekka Riikonen <priikone@silcnet.org>
parents:
11488
diff
changeset
|
676 | |
|
ea610d8ab584
[gaim-migrate @ 14519]
Pekka Riikonen <priikone@silcnet.org>
parents:
11488
diff
changeset
|
677 | /* If there weren't any images, don't return anything. */ |
|
ea610d8ab584
[gaim-migrate @ 14519]
Pekka Riikonen <priikone@silcnet.org>
parents:
11488
diff
changeset
|
678 | if (!images) { |
|
ea610d8ab584
[gaim-migrate @ 14519]
Pekka Riikonen <priikone@silcnet.org>
parents:
11488
diff
changeset
|
679 | if (parts) |
|
ea610d8ab584
[gaim-migrate @ 14519]
Pekka Riikonen <priikone@silcnet.org>
parents:
11488
diff
changeset
|
680 | silc_dlist_uninit(parts); |
|
ea610d8ab584
[gaim-migrate @ 14519]
Pekka Riikonen <priikone@silcnet.org>
parents:
11488
diff
changeset
|
681 | return NULL; |
|
ea610d8ab584
[gaim-migrate @ 14519]
Pekka Riikonen <priikone@silcnet.org>
parents:
11488
diff
changeset
|
682 | } |
|
ea610d8ab584
[gaim-migrate @ 14519]
Pekka Riikonen <priikone@silcnet.org>
parents:
11488
diff
changeset
|
683 | |
|
ea610d8ab584
[gaim-migrate @ 14519]
Pekka Riikonen <priikone@silcnet.org>
parents:
11488
diff
changeset
|
684 | if (silc_dlist_count(parts) > 1) { |
|
ea610d8ab584
[gaim-migrate @ 14519]
Pekka Riikonen <priikone@silcnet.org>
parents:
11488
diff
changeset
|
685 | /* Multipart MIME message */ |
|
ea610d8ab584
[gaim-migrate @ 14519]
Pekka Riikonen <priikone@silcnet.org>
parents:
11488
diff
changeset
|
686 | char b[32]; |
|
ea610d8ab584
[gaim-migrate @ 14519]
Pekka Riikonen <priikone@silcnet.org>
parents:
11488
diff
changeset
|
687 | mime = silc_mime_alloc(); |
|
ea610d8ab584
[gaim-migrate @ 14519]
Pekka Riikonen <priikone@silcnet.org>
parents:
11488
diff
changeset
|
688 | silc_mime_add_field(mime, "MIME-Version", "1.0"); |
|
ea610d8ab584
[gaim-migrate @ 14519]
Pekka Riikonen <priikone@silcnet.org>
parents:
11488
diff
changeset
|
689 | g_snprintf(b, sizeof(b), "b%4X%4X", |
|
ea610d8ab584
[gaim-migrate @ 14519]
Pekka Riikonen <priikone@silcnet.org>
parents:
11488
diff
changeset
|
690 | (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
|
691 | silc_dlist_count(parts)); |
|
12217
ea610d8ab584
[gaim-migrate @ 14519]
Pekka Riikonen <priikone@silcnet.org>
parents:
11488
diff
changeset
|
692 | silc_mime_set_multipart(mime, "mixed", b); |
|
ea610d8ab584
[gaim-migrate @ 14519]
Pekka Riikonen <priikone@silcnet.org>
parents:
11488
diff
changeset
|
693 | silc_dlist_start(parts); |
|
ea610d8ab584
[gaim-migrate @ 14519]
Pekka Riikonen <priikone@silcnet.org>
parents:
11488
diff
changeset
|
694 | while ((p = silc_dlist_get(parts)) != SILC_LIST_END) |
|
ea610d8ab584
[gaim-migrate @ 14519]
Pekka Riikonen <priikone@silcnet.org>
parents:
11488
diff
changeset
|
695 | silc_mime_add_multipart(mime, p); |
|
ea610d8ab584
[gaim-migrate @ 14519]
Pekka Riikonen <priikone@silcnet.org>
parents:
11488
diff
changeset
|
696 | } else { |
|
ea610d8ab584
[gaim-migrate @ 14519]
Pekka Riikonen <priikone@silcnet.org>
parents:
11488
diff
changeset
|
697 | /* Simple MIME message */ |
|
ea610d8ab584
[gaim-migrate @ 14519]
Pekka Riikonen <priikone@silcnet.org>
parents:
11488
diff
changeset
|
698 | silc_dlist_start(parts); |
|
ea610d8ab584
[gaim-migrate @ 14519]
Pekka Riikonen <priikone@silcnet.org>
parents:
11488
diff
changeset
|
699 | mime = silc_dlist_get(parts); |
|
ea610d8ab584
[gaim-migrate @ 14519]
Pekka Riikonen <priikone@silcnet.org>
parents:
11488
diff
changeset
|
700 | silc_mime_add_field(mime, "MIME-Version", "1.0"); |
|
ea610d8ab584
[gaim-migrate @ 14519]
Pekka Riikonen <priikone@silcnet.org>
parents:
11488
diff
changeset
|
701 | } |
|
ea610d8ab584
[gaim-migrate @ 14519]
Pekka Riikonen <priikone@silcnet.org>
parents:
11488
diff
changeset
|
702 | |
|
ea610d8ab584
[gaim-migrate @ 14519]
Pekka Riikonen <priikone@silcnet.org>
parents:
11488
diff
changeset
|
703 | *mflags &= ~SILC_MESSAGE_FLAG_UTF8; |
|
ea610d8ab584
[gaim-migrate @ 14519]
Pekka Riikonen <priikone@silcnet.org>
parents:
11488
diff
changeset
|
704 | *mflags |= SILC_MESSAGE_FLAG_DATA; |
|
ea610d8ab584
[gaim-migrate @ 14519]
Pekka Riikonen <priikone@silcnet.org>
parents:
11488
diff
changeset
|
705 | |
|
ea610d8ab584
[gaim-migrate @ 14519]
Pekka Riikonen <priikone@silcnet.org>
parents:
11488
diff
changeset
|
706 | /* Encode message. Fragment if it is too large */ |
|
ea610d8ab584
[gaim-migrate @ 14519]
Pekka Riikonen <priikone@silcnet.org>
parents:
11488
diff
changeset
|
707 | list = silc_mime_encode_partial(mime, 0xfc00); |
|
ea610d8ab584
[gaim-migrate @ 14519]
Pekka Riikonen <priikone@silcnet.org>
parents:
11488
diff
changeset
|
708 | |
|
ea610d8ab584
[gaim-migrate @ 14519]
Pekka Riikonen <priikone@silcnet.org>
parents:
11488
diff
changeset
|
709 | silc_dlist_uninit(parts); |
|
ea610d8ab584
[gaim-migrate @ 14519]
Pekka Riikonen <priikone@silcnet.org>
parents:
11488
diff
changeset
|
710 | |
|
ea610d8ab584
[gaim-migrate @ 14519]
Pekka Riikonen <priikone@silcnet.org>
parents:
11488
diff
changeset
|
711 | /* Added multiparts gets freed here */ |
|
ea610d8ab584
[gaim-migrate @ 14519]
Pekka Riikonen <priikone@silcnet.org>
parents:
11488
diff
changeset
|
712 | silc_mime_free(mime); |
|
ea610d8ab584
[gaim-migrate @ 14519]
Pekka Riikonen <priikone@silcnet.org>
parents:
11488
diff
changeset
|
713 | |
|
ea610d8ab584
[gaim-migrate @ 14519]
Pekka Riikonen <priikone@silcnet.org>
parents:
11488
diff
changeset
|
714 | return list; |
|
ea610d8ab584
[gaim-migrate @ 14519]
Pekka Riikonen <priikone@silcnet.org>
parents:
11488
diff
changeset
|
715 | } |