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