annotate src/protocols/silc/util.c @ 14086:545dbc931e8c

[gaim-migrate @ 16709] Deal with inability to create key pair. (CID 139) committer: Tailor Script <tailor@pidgin.im>
author Daniel Atallah <daniel.atallah@gmail.com>
date Fri, 11 Aug 2006 19:02:47 +0000
parents a92263b13380
children 0154168c414a
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
8849
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
1 /*
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
2
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
3 silcgaim_util.c
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
4
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
5 Author: Pekka Riikonen <priikone@silcnet.org>
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
6
10825
cb625efd1071 [gaim-migrate @ 12490]
Stu Tomlinson <stu@nosnilmot.com>
parents: 10751
diff changeset
7 Copyright (C) 2004 - 2005 Pekka Riikonen
8849
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
8
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
9 This program is free software; you can redistribute it and/or modify
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
10 it under the terms of the GNU General Public License as published by
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
11 the Free Software Foundation; version 2 of the License.
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
12
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
13 This program is distributed in the hope that it will be useful,
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
16 GNU General Public License for more details.
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
17
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
18 */
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
19
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
20 #include "silcincludes.h"
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
21 #include "silcclient.h"
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
22 #include "silcgaim.h"
12217
029802981b81 [gaim-migrate @ 14519]
Stu Tomlinson <stu@nosnilmot.com>
parents: 11488
diff changeset
23 #include "imgstore.h"
8849
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
24
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
25 /**************************** Utility Routines *******************************/
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
26
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
27 static char str[256], str2[256];
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
28
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
29 const char *silcgaim_silcdir(void)
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
30 {
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
31 const char *hd = gaim_home_dir();
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
32 memset(str, 0, sizeof(str));
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
33 g_snprintf(str, sizeof(str) - 1, "%s" G_DIR_SEPARATOR_S ".silc", hd ? hd : "/tmp");
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
34 return (const char *)str;
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
35 }
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
36
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
37 const char *silcgaim_session_file(const char *account)
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
38 {
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
39 memset(str2, 0, sizeof(str2));
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
40 g_snprintf(str2, sizeof(str2) - 1, "%s" G_DIR_SEPARATOR_S "%s_session",
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
41 silcgaim_silcdir(), account);
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
42 return (const char *)str2;
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
43 }
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
44
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
45 gboolean silcgaim_ip_is_private(const char *ip)
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
46 {
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
47 if (silc_net_is_ip4(ip)) {
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
48 if (!strncmp(ip, "10.", 3)) {
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
49 return TRUE;
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
50 } else if (!strncmp(ip, "172.", 4) && strlen(ip) > 6) {
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
51 char tmp[3];
8910
26c9b8761707 [gaim-migrate @ 9680]
Luke Schierer <lschiere@pidgin.im>
parents: 8849
diff changeset
52 int s;
8849
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
53 memset(tmp, 0, sizeof(tmp));
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
54 strncpy(tmp, ip + 4, 2);
8910
26c9b8761707 [gaim-migrate @ 9680]
Luke Schierer <lschiere@pidgin.im>
parents: 8849
diff changeset
55 s = atoi(tmp);
8849
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
56 if (s >= 16 && s <= 31)
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
57 return TRUE;
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
58 } else if (!strncmp(ip, "192.168.", 8)) {
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
59 return TRUE;
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
60 }
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
61 }
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
62
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
63 return FALSE;
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
64 }
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
65
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
66 /* This checks stats for various SILC files and directories. First it
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
67 checks if ~/.silc directory exist and is owned by the correct user. If
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
68 it doesn't exist, it will create the directory. After that it checks if
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
69 user's Public and Private key files exists and creates them if needed. */
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
70
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
71 gboolean silcgaim_check_silc_dir(GaimConnection *gc)
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
72 {
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
73 char filename[256], file_public_key[256], file_private_key[256];
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
74 char servfilename[256], clientfilename[256], friendsfilename[256];
10825
cb625efd1071 [gaim-migrate @ 12490]
Stu Tomlinson <stu@nosnilmot.com>
parents: 10751
diff changeset
75 char pkd[256], prd[256];
8849
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
76 struct stat st;
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
77 struct passwd *pw;
13659
a92263b13380 [gaim-migrate @ 16061]
Mark Doliner <mark@kingant.net>
parents: 13545
diff changeset
78 int fd;
8849
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
79
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
80 pw = getpwuid(getuid());
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
81 if (!pw) {
9272
ac4480944fc3 [gaim-migrate @ 10075]
Ethan Blanton <elb@pidgin.im>
parents: 9183
diff changeset
82 gaim_debug_error("silc", "silc: %s\n", strerror(errno));
8849
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
83 return FALSE;
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
84 }
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
85
9353
b8138f3959dc [gaim-migrate @ 10161]
Ethan Blanton <elb@pidgin.im>
parents: 9274
diff changeset
86 g_snprintf(filename, sizeof(filename) - 1, "%s", silcgaim_silcdir());
8849
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
87 g_snprintf(servfilename, sizeof(servfilename) - 1, "%s" G_DIR_SEPARATOR_S "serverkeys",
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
88 silcgaim_silcdir());
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
89 g_snprintf(clientfilename, sizeof(clientfilename) - 1, "%s" G_DIR_SEPARATOR_S "clientkeys",
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
90 silcgaim_silcdir());
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
91 g_snprintf(friendsfilename, sizeof(friendsfilename) - 1, "%s" G_DIR_SEPARATOR_S "friends",
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
92 silcgaim_silcdir());
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
93
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
94 /*
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
95 * Check ~/.silc directory
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
96 */
10589
0f7452b1f777 [gaim-migrate @ 11994]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 9488
diff changeset
97 if ((g_stat(filename, &st)) == -1) {
8849
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
98 /* If dir doesn't exist */
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
99 if (errno == ENOENT) {
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
100 if (pw->pw_uid == geteuid()) {
10589
0f7452b1f777 [gaim-migrate @ 11994]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 9488
diff changeset
101 if ((g_mkdir(filename, 0755)) == -1) {
9272
ac4480944fc3 [gaim-migrate @ 10075]
Ethan Blanton <elb@pidgin.im>
parents: 9183
diff changeset
102 gaim_debug_error("silc", "Couldn't create '%s' directory\n", filename);
8849
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
103 return FALSE;
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
104 }
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
105 } else {
9272
ac4480944fc3 [gaim-migrate @ 10075]
Ethan Blanton <elb@pidgin.im>
parents: 9183
diff changeset
106 gaim_debug_error("silc", "Couldn't create '%s' directory due to a wrong uid!\n",
8849
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
107 filename);
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
108 return FALSE;
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
109 }
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
110 } else {
9272
ac4480944fc3 [gaim-migrate @ 10075]
Ethan Blanton <elb@pidgin.im>
parents: 9183
diff changeset
111 gaim_debug_error("silc", "Couldn't stat '%s' directory, error: %s\n", filename, strerror(errno));
8849
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
112 return FALSE;
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
113 }
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
114 } else {
9353
b8138f3959dc [gaim-migrate @ 10161]
Ethan Blanton <elb@pidgin.im>
parents: 9274
diff changeset
115 #ifndef _WIN32
8849
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
116 /* Check the owner of the dir */
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
117 if (st.st_uid != 0 && st.st_uid != pw->pw_uid) {
9272
ac4480944fc3 [gaim-migrate @ 10075]
Ethan Blanton <elb@pidgin.im>
parents: 9183
diff changeset
118 gaim_debug_error("silc", "You don't seem to own '%s' directory\n",
8849
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
119 filename);
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
120 return FALSE;
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
121 }
9353
b8138f3959dc [gaim-migrate @ 10161]
Ethan Blanton <elb@pidgin.im>
parents: 9274
diff changeset
122 #endif
8849
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
123 }
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
124
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
125 /*
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
126 * Check ~./silc/serverkeys directory
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
127 */
10589
0f7452b1f777 [gaim-migrate @ 11994]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 9488
diff changeset
128 if ((g_stat(servfilename, &st)) == -1) {
8849
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
129 /* If dir doesn't exist */
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
130 if (errno == ENOENT) {
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
131 if (pw->pw_uid == geteuid()) {
10589
0f7452b1f777 [gaim-migrate @ 11994]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 9488
diff changeset
132 if ((g_mkdir(servfilename, 0755)) == -1) {
9272
ac4480944fc3 [gaim-migrate @ 10075]
Ethan Blanton <elb@pidgin.im>
parents: 9183
diff changeset
133 gaim_debug_error("silc", "Couldn't create '%s' directory\n", servfilename);
8849
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
134 return FALSE;
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
135 }
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
136 } else {
9272
ac4480944fc3 [gaim-migrate @ 10075]
Ethan Blanton <elb@pidgin.im>
parents: 9183
diff changeset
137 gaim_debug_error("silc", "Couldn't create '%s' directory due to a wrong uid!\n",
8849
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
138 servfilename);
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
139 return FALSE;
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
140 }
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
141 } else {
9272
ac4480944fc3 [gaim-migrate @ 10075]
Ethan Blanton <elb@pidgin.im>
parents: 9183
diff changeset
142 gaim_debug_error("silc", "Couldn't stat '%s' directory, error: %s\n",
ac4480944fc3 [gaim-migrate @ 10075]
Ethan Blanton <elb@pidgin.im>
parents: 9183
diff changeset
143 servfilename, strerror(errno));
8849
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
144 return FALSE;
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
145 }
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
146 }
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
147
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
148 /*
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
149 * Check ~./silc/clientkeys directory
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
150 */
10589
0f7452b1f777 [gaim-migrate @ 11994]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 9488
diff changeset
151 if ((g_stat(clientfilename, &st)) == -1) {
8849
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
152 /* If dir doesn't exist */
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
153 if (errno == ENOENT) {
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
154 if (pw->pw_uid == geteuid()) {
10589
0f7452b1f777 [gaim-migrate @ 11994]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 9488
diff changeset
155 if ((g_mkdir(clientfilename, 0755)) == -1) {
9272
ac4480944fc3 [gaim-migrate @ 10075]
Ethan Blanton <elb@pidgin.im>
parents: 9183
diff changeset
156 gaim_debug_error("silc", "Couldn't create '%s' directory\n", clientfilename);
8849
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
157 return FALSE;
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
158 }
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
159 } else {
9272
ac4480944fc3 [gaim-migrate @ 10075]
Ethan Blanton <elb@pidgin.im>
parents: 9183
diff changeset
160 gaim_debug_error("silc", "Couldn't create '%s' directory due to a wrong uid!\n",
8849
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
161 clientfilename);
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
162 return FALSE;
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
163 }
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
164 } else {
9272
ac4480944fc3 [gaim-migrate @ 10075]
Ethan Blanton <elb@pidgin.im>
parents: 9183
diff changeset
165 gaim_debug_error("silc", "Couldn't stat '%s' directory, error: %s\n",
ac4480944fc3 [gaim-migrate @ 10075]
Ethan Blanton <elb@pidgin.im>
parents: 9183
diff changeset
166 clientfilename, strerror(errno));
8849
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
167 return FALSE;
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
168 }
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
169 }
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
170
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
171 /*
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
172 * Check ~./silc/friends directory
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
173 */
10589
0f7452b1f777 [gaim-migrate @ 11994]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 9488
diff changeset
174 if ((g_stat(friendsfilename, &st)) == -1) {
8849
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
175 /* If dir doesn't exist */
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
176 if (errno == ENOENT) {
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
177 if (pw->pw_uid == geteuid()) {
10589
0f7452b1f777 [gaim-migrate @ 11994]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 9488
diff changeset
178 if ((g_mkdir(friendsfilename, 0755)) == -1) {
9272
ac4480944fc3 [gaim-migrate @ 10075]
Ethan Blanton <elb@pidgin.im>
parents: 9183
diff changeset
179 gaim_debug_error("silc", "Couldn't create '%s' directory\n", friendsfilename);
8849
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
180 return FALSE;
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
181 }
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
182 } else {
9272
ac4480944fc3 [gaim-migrate @ 10075]
Ethan Blanton <elb@pidgin.im>
parents: 9183
diff changeset
183 gaim_debug_error("silc", "Couldn't create '%s' directory due to a wrong uid!\n",
8849
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
184 friendsfilename);
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
185 return FALSE;
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
186 }
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
187 } else {
9272
ac4480944fc3 [gaim-migrate @ 10075]
Ethan Blanton <elb@pidgin.im>
parents: 9183
diff changeset
188 gaim_debug_error("silc", "Couldn't stat '%s' directory, error: %s\n",
ac4480944fc3 [gaim-migrate @ 10075]
Ethan Blanton <elb@pidgin.im>
parents: 9183
diff changeset
189 friendsfilename, strerror(errno));
8849
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
190 return FALSE;
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
191 }
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
192 }
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
193
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
194 /*
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
195 * Check Public and Private keys
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
196 */
10825
cb625efd1071 [gaim-migrate @ 12490]
Stu Tomlinson <stu@nosnilmot.com>
parents: 10751
diff changeset
197 g_snprintf(pkd, sizeof(pkd), "%s" G_DIR_SEPARATOR_S "public_key.pub", silcgaim_silcdir());
cb625efd1071 [gaim-migrate @ 12490]
Stu Tomlinson <stu@nosnilmot.com>
parents: 10751
diff changeset
198 g_snprintf(prd, sizeof(prd), "%s" G_DIR_SEPARATOR_S "private_key.prv", silcgaim_silcdir());
8849
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
199 g_snprintf(file_public_key, sizeof(file_public_key) - 1, "%s",
10825
cb625efd1071 [gaim-migrate @ 12490]
Stu Tomlinson <stu@nosnilmot.com>
parents: 10751
diff changeset
200 gaim_account_get_string(gc->account, "public-key", pkd));
8849
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
201 g_snprintf(file_private_key, sizeof(file_public_key) - 1, "%s",
10825
cb625efd1071 [gaim-migrate @ 12490]
Stu Tomlinson <stu@nosnilmot.com>
parents: 10751
diff changeset
202 gaim_account_get_string(gc->account, "private-key", prd));
8849
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
203
10589
0f7452b1f777 [gaim-migrate @ 11994]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 9488
diff changeset
204 if ((g_stat(file_public_key, &st)) == -1) {
8849
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
205 /* If file doesn't exist */
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
206 if (errno == ENOENT) {
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
207 gaim_connection_update_progress(gc, _("Creating SILC key pair..."), 1, 5);
14086
545dbc931e8c [gaim-migrate @ 16709]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 13659
diff changeset
208 if (!silc_create_key_pair(SILCGAIM_DEF_PKCS,
8849
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
209 SILCGAIM_DEF_PKCS_LEN,
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
210 file_public_key, file_private_key, NULL,
10751
bf5e48215158 [gaim-migrate @ 12354]
Mark Doliner <mark@kingant.net>
parents: 10589
diff changeset
211 (gc->password == NULL) ? "" : gc->password,
14086
545dbc931e8c [gaim-migrate @ 16709]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 13659
diff changeset
212 NULL, NULL, NULL, FALSE)) {
545dbc931e8c [gaim-migrate @ 16709]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 13659
diff changeset
213 gaim_debug_error("silc", "Couldn't create key pair\n");
545dbc931e8c [gaim-migrate @ 16709]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 13659
diff changeset
214 return FALSE;
545dbc931e8c [gaim-migrate @ 16709]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 13659
diff changeset
215 }
545dbc931e8c [gaim-migrate @ 16709]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 13659
diff changeset
216
545dbc931e8c [gaim-migrate @ 16709]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 13659
diff changeset
217 if ((g_stat(file_public_key, &st)) == -1) {
545dbc931e8c [gaim-migrate @ 16709]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 13659
diff changeset
218 gaim_debug_error("silc", "Couldn't stat '%s' public key, error: %s\n",
545dbc931e8c [gaim-migrate @ 16709]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 13659
diff changeset
219 file_public_key, strerror(errno));
545dbc931e8c [gaim-migrate @ 16709]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 13659
diff changeset
220 return FALSE;
545dbc931e8c [gaim-migrate @ 16709]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 13659
diff changeset
221 }
8849
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
222 } else {
9272
ac4480944fc3 [gaim-migrate @ 10075]
Ethan Blanton <elb@pidgin.im>
parents: 9183
diff changeset
223 gaim_debug_error("silc", "Couldn't stat '%s' public key, error: %s\n",
ac4480944fc3 [gaim-migrate @ 10075]
Ethan Blanton <elb@pidgin.im>
parents: 9183
diff changeset
224 file_public_key, strerror(errno));
8849
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
225 return FALSE;
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
226 }
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
227 }
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
228
9353
b8138f3959dc [gaim-migrate @ 10161]
Ethan Blanton <elb@pidgin.im>
parents: 9274
diff changeset
229 #ifndef _WIN32
8849
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
230 /* Check the owner of the public key */
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
231 if (st.st_uid != 0 && st.st_uid != pw->pw_uid) {
9272
ac4480944fc3 [gaim-migrate @ 10075]
Ethan Blanton <elb@pidgin.im>
parents: 9183
diff changeset
232 gaim_debug_error("silc", "You don't seem to own your public key!?\n");
8849
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
233 return FALSE;
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
234 }
9353
b8138f3959dc [gaim-migrate @ 10161]
Ethan Blanton <elb@pidgin.im>
parents: 9274
diff changeset
235 #endif
8849
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
236
13659
a92263b13380 [gaim-migrate @ 16061]
Mark Doliner <mark@kingant.net>
parents: 13545
diff changeset
237 fd = open(file_private_key, O_RDONLY);
10589
0f7452b1f777 [gaim-migrate @ 11994]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 9488
diff changeset
238 if ((g_stat(file_private_key, &st)) == -1) {
8849
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
239 /* If file doesn't exist */
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
240 if (errno == ENOENT) {
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
241 gaim_connection_update_progress(gc, _("Creating SILC key pair..."), 1, 5);
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
242 silc_create_key_pair(SILCGAIM_DEF_PKCS,
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
243 SILCGAIM_DEF_PKCS_LEN,
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
244 file_public_key, file_private_key, NULL,
10751
bf5e48215158 [gaim-migrate @ 12354]
Mark Doliner <mark@kingant.net>
parents: 10589
diff changeset
245 (gc->password == NULL) ? "" : gc->password,
9272
ac4480944fc3 [gaim-migrate @ 10075]
Ethan Blanton <elb@pidgin.im>
parents: 9183
diff changeset
246 NULL, NULL, NULL, FALSE);
13659
a92263b13380 [gaim-migrate @ 16061]
Mark Doliner <mark@kingant.net>
parents: 13545
diff changeset
247 if (fd != -1)
a92263b13380 [gaim-migrate @ 16061]
Mark Doliner <mark@kingant.net>
parents: 13545
diff changeset
248 close(fd);
a92263b13380 [gaim-migrate @ 16061]
Mark Doliner <mark@kingant.net>
parents: 13545
diff changeset
249 fd = open(file_private_key, O_RDONLY);
10589
0f7452b1f777 [gaim-migrate @ 11994]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 9488
diff changeset
250 g_stat(file_private_key, &st);
8849
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
251 } else {
9272
ac4480944fc3 [gaim-migrate @ 10075]
Ethan Blanton <elb@pidgin.im>
parents: 9183
diff changeset
252 gaim_debug_error("silc", "Couldn't stat '%s' private key, error: %s\n",
ac4480944fc3 [gaim-migrate @ 10075]
Ethan Blanton <elb@pidgin.im>
parents: 9183
diff changeset
253 file_private_key, strerror(errno));
13659
a92263b13380 [gaim-migrate @ 16061]
Mark Doliner <mark@kingant.net>
parents: 13545
diff changeset
254 if (fd != -1)
a92263b13380 [gaim-migrate @ 16061]
Mark Doliner <mark@kingant.net>
parents: 13545
diff changeset
255 close(fd);
8849
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
256 return FALSE;
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
257 }
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
258 }
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
259
9353
b8138f3959dc [gaim-migrate @ 10161]
Ethan Blanton <elb@pidgin.im>
parents: 9274
diff changeset
260 #ifndef _WIN32
8849
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
261 /* Check the owner of the private key */
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
262 if (st.st_uid != 0 && st.st_uid != pw->pw_uid) {
9272
ac4480944fc3 [gaim-migrate @ 10075]
Ethan Blanton <elb@pidgin.im>
parents: 9183
diff changeset
263 gaim_debug_error("silc", "You don't seem to own your private key!?\n");
13659
a92263b13380 [gaim-migrate @ 16061]
Mark Doliner <mark@kingant.net>
parents: 13545
diff changeset
264 if (fd != -1)
a92263b13380 [gaim-migrate @ 16061]
Mark Doliner <mark@kingant.net>
parents: 13545
diff changeset
265 close(fd);
8849
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
266 return FALSE;
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
267 }
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
268
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
269 /* Check the permissions for the private key */
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
270 if ((st.st_mode & 0777) != 0600) {
9272
ac4480944fc3 [gaim-migrate @ 10075]
Ethan Blanton <elb@pidgin.im>
parents: 9183
diff changeset
271 gaim_debug_warning("silc", "Wrong permissions in your private key file `%s'!\n"
13659
a92263b13380 [gaim-migrate @ 16061]
Mark Doliner <mark@kingant.net>
parents: 13545
diff changeset
272 "Trying to change them ...\n", file_private_key);
a92263b13380 [gaim-migrate @ 16061]
Mark Doliner <mark@kingant.net>
parents: 13545
diff changeset
273 if ((fd != -1) && (fchmod(fd, S_IRUSR | S_IWUSR)) == -1) {
9272
ac4480944fc3 [gaim-migrate @ 10075]
Ethan Blanton <elb@pidgin.im>
parents: 9183
diff changeset
274 gaim_debug_error("silc",
8849
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
275 "Failed to change permissions for private key file!\n"
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
276 "Permissions for your private key file must be 0600.\n");
13659
a92263b13380 [gaim-migrate @ 16061]
Mark Doliner <mark@kingant.net>
parents: 13545
diff changeset
277 if (fd != -1)
a92263b13380 [gaim-migrate @ 16061]
Mark Doliner <mark@kingant.net>
parents: 13545
diff changeset
278 close(fd);
8849
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
279 return FALSE;
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
280 }
9272
ac4480944fc3 [gaim-migrate @ 10075]
Ethan Blanton <elb@pidgin.im>
parents: 9183
diff changeset
281 gaim_debug_warning("silc", "Done.\n\n");
8849
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
282 }
9353
b8138f3959dc [gaim-migrate @ 10161]
Ethan Blanton <elb@pidgin.im>
parents: 9274
diff changeset
283 #endif
8849
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
284
13659
a92263b13380 [gaim-migrate @ 16061]
Mark Doliner <mark@kingant.net>
parents: 13545
diff changeset
285 if (fd != -1)
a92263b13380 [gaim-migrate @ 16061]
Mark Doliner <mark@kingant.net>
parents: 13545
diff changeset
286 close(fd);
a92263b13380 [gaim-migrate @ 16061]
Mark Doliner <mark@kingant.net>
parents: 13545
diff changeset
287
8849
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
288 return TRUE;
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
289 }
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
290
9353
b8138f3959dc [gaim-migrate @ 10161]
Ethan Blanton <elb@pidgin.im>
parents: 9274
diff changeset
291 #ifdef _WIN32
b8138f3959dc [gaim-migrate @ 10161]
Ethan Blanton <elb@pidgin.im>
parents: 9274
diff changeset
292 struct passwd *getpwuid(uid_t uid) {
b8138f3959dc [gaim-migrate @ 10161]
Ethan Blanton <elb@pidgin.im>
parents: 9274
diff changeset
293 struct passwd *pwd = calloc(1, sizeof(struct passwd));
b8138f3959dc [gaim-migrate @ 10161]
Ethan Blanton <elb@pidgin.im>
parents: 9274
diff changeset
294 return pwd;
b8138f3959dc [gaim-migrate @ 10161]
Ethan Blanton <elb@pidgin.im>
parents: 9274
diff changeset
295 }
b8138f3959dc [gaim-migrate @ 10161]
Ethan Blanton <elb@pidgin.im>
parents: 9274
diff changeset
296
b8138f3959dc [gaim-migrate @ 10161]
Ethan Blanton <elb@pidgin.im>
parents: 9274
diff changeset
297 uid_t getuid() {
b8138f3959dc [gaim-migrate @ 10161]
Ethan Blanton <elb@pidgin.im>
parents: 9274
diff changeset
298 return 0;
b8138f3959dc [gaim-migrate @ 10161]
Ethan Blanton <elb@pidgin.im>
parents: 9274
diff changeset
299 }
b8138f3959dc [gaim-migrate @ 10161]
Ethan Blanton <elb@pidgin.im>
parents: 9274
diff changeset
300
b8138f3959dc [gaim-migrate @ 10161]
Ethan Blanton <elb@pidgin.im>
parents: 9274
diff changeset
301 uid_t geteuid() {
b8138f3959dc [gaim-migrate @ 10161]
Ethan Blanton <elb@pidgin.im>
parents: 9274
diff changeset
302 return 0;
b8138f3959dc [gaim-migrate @ 10161]
Ethan Blanton <elb@pidgin.im>
parents: 9274
diff changeset
303 }
b8138f3959dc [gaim-migrate @ 10161]
Ethan Blanton <elb@pidgin.im>
parents: 9274
diff changeset
304 #endif
b8138f3959dc [gaim-migrate @ 10161]
Ethan Blanton <elb@pidgin.im>
parents: 9274
diff changeset
305
8849
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
306 void silcgaim_show_public_key(SilcGaim sg,
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
307 const char *name, SilcPublicKey public_key,
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
308 GCallback callback, void *context)
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
309 {
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
310 SilcPublicKeyIdentifier ident;
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
311 SilcPKCS pkcs;
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
312 char *fingerprint, *babbleprint;
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
313 unsigned char *pk;
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
314 SilcUInt32 pk_len, key_len = 0;
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
315 GString *s;
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
316 char *buf;
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
317
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
318 ident = silc_pkcs_decode_identifier(public_key->identifier);
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
319 if (!ident)
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
320 return;
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
321
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
322 pk = silc_pkcs_public_key_encode(public_key, &pk_len);
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
323 fingerprint = silc_hash_fingerprint(NULL, pk, pk_len);
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
324 babbleprint = silc_hash_babbleprint(NULL, pk, pk_len);
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
325
11488
9c7ca8a8c4b8 [gaim-migrate @ 13730]
Stu Tomlinson <stu@nosnilmot.com>
parents: 11201
diff changeset
326 if (silc_pkcs_alloc((unsigned char *)public_key->name, &pkcs)) {
8849
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
327 key_len = silc_pkcs_public_key_set(pkcs, public_key);
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
328 silc_pkcs_free(pkcs);
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
329 }
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
330
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
331 s = g_string_new("");
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
332 if (ident->realname)
10825
cb625efd1071 [gaim-migrate @ 12490]
Stu Tomlinson <stu@nosnilmot.com>
parents: 10751
diff changeset
333 /* Hint for translators: Please check the tabulator width here and in
cb625efd1071 [gaim-migrate @ 12490]
Stu Tomlinson <stu@nosnilmot.com>
parents: 10751
diff changeset
334 the next strings (short strings: 2 tabs, longer strings 1 tab,
9274
f5c08be60098 [gaim-migrate @ 10077]
Luke Schierer <lschiere@pidgin.im>
parents: 9272
diff changeset
335 sum: 3 tabs or 24 characters) */
f5c08be60098 [gaim-migrate @ 10077]
Luke Schierer <lschiere@pidgin.im>
parents: 9272
diff changeset
336 g_string_append_printf(s, _("Real Name: \t%s\n"), ident->realname);
8849
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
337 if (ident->username)
9274
f5c08be60098 [gaim-migrate @ 10077]
Luke Schierer <lschiere@pidgin.im>
parents: 9272
diff changeset
338 g_string_append_printf(s, _("User Name: \t%s\n"), ident->username);
8849
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
339 if (ident->email)
13545
cfc2f7fcb3dd [gaim-migrate @ 15922]
Richard Laager <rlaager@wiktel.com>
parents: 12217
diff changeset
340 g_string_append_printf(s, _("E-Mail: \t\t%s\n"), ident->email);
8849
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
341 if (ident->host)
9274
f5c08be60098 [gaim-migrate @ 10077]
Luke Schierer <lschiere@pidgin.im>
parents: 9272
diff changeset
342 g_string_append_printf(s, _("Host Name: \t%s\n"), ident->host);
8849
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
343 if (ident->org)
9274
f5c08be60098 [gaim-migrate @ 10077]
Luke Schierer <lschiere@pidgin.im>
parents: 9272
diff changeset
344 g_string_append_printf(s, _("Organization: \t%s\n"), ident->org);
8849
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
345 if (ident->country)
9274
f5c08be60098 [gaim-migrate @ 10077]
Luke Schierer <lschiere@pidgin.im>
parents: 9272
diff changeset
346 g_string_append_printf(s, _("Country: \t%s\n"), ident->country);
9488
2770a0e659ca [gaim-migrate @ 10313]
Ethan Blanton <elb@pidgin.im>
parents: 9353
diff changeset
347 g_string_append_printf(s, _("Algorithm: \t%s\n"), public_key->name);
9274
f5c08be60098 [gaim-migrate @ 10077]
Luke Schierer <lschiere@pidgin.im>
parents: 9272
diff changeset
348 g_string_append_printf(s, _("Key Length: \t%d bits\n"), (int)key_len);
f5c08be60098 [gaim-migrate @ 10077]
Luke Schierer <lschiere@pidgin.im>
parents: 9272
diff changeset
349 g_string_append_printf(s, "\n");
f5c08be60098 [gaim-migrate @ 10077]
Luke Schierer <lschiere@pidgin.im>
parents: 9272
diff changeset
350 g_string_append_printf(s, _("Public Key Fingerprint:\n%s\n\n"), fingerprint);
f5c08be60098 [gaim-migrate @ 10077]
Luke Schierer <lschiere@pidgin.im>
parents: 9272
diff changeset
351 g_string_append_printf(s, _("Public Key Babbleprint:\n%s"), babbleprint);
8849
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
352
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
353 buf = g_string_free(s, FALSE);
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
354
11201
07dc8c6a359f [gaim-migrate @ 13329]
Mark Doliner <mark@kingant.net>
parents: 10825
diff changeset
355 gaim_request_action(sg->gc, _("Public Key Information"),
8849
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
356 _("Public Key Information"),
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
357 buf, 0, context, 1,
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
358 _("Close"), callback);
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
359
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
360 g_free(buf);
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
361 silc_free(fingerprint);
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
362 silc_free(babbleprint);
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
363 silc_free(pk);
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
364 silc_pkcs_free_identifier(ident);
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
365 }
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
366
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
367 SilcAttributePayload
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
368 silcgaim_get_attr(SilcDList attrs, SilcAttribute attribute)
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
369 {
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
370 SilcAttributePayload attr = NULL;
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
371
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
372 if (!attrs)
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
373 return NULL;
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
374
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
375 silc_dlist_start(attrs);
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
376 while ((attr = silc_dlist_get(attrs)) != SILC_LIST_END)
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
377 if (attribute == silc_attribute_get_attribute(attr))
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
378 break;
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
379
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
380 return attr;
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
381 }
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
382
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
383 void silcgaim_get_umode_string(SilcUInt32 mode, char *buf,
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
384 SilcUInt32 buf_size)
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
385 {
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
386 memset(buf, 0, buf_size);
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
387 if ((mode & SILC_UMODE_SERVER_OPERATOR) ||
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
388 (mode & SILC_UMODE_ROUTER_OPERATOR)) {
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
389 strcat(buf, (mode & SILC_UMODE_SERVER_OPERATOR) ?
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
390 "[server operator] " :
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
391 (mode & SILC_UMODE_ROUTER_OPERATOR) ?
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
392 "[SILC operator] " : "[unknown mode] ");
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
393 }
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
394 if (mode & SILC_UMODE_GONE)
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
395 strcat(buf, "[away] ");
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
396 if (mode & SILC_UMODE_INDISPOSED)
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
397 strcat(buf, "[indisposed] ");
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
398 if (mode & SILC_UMODE_BUSY)
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
399 strcat(buf, "[busy] ");
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
400 if (mode & SILC_UMODE_PAGE)
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
401 strcat(buf, "[wake me up] ");
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
402 if (mode & SILC_UMODE_HYPER)
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
403 strcat(buf, "[hyperactive] ");
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
404 if (mode & SILC_UMODE_ROBOT)
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
405 strcat(buf, "[robot] ");
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
406 if (mode & SILC_UMODE_ANONYMOUS)
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
407 strcat(buf, "[anonymous] ");
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
408 if (mode & SILC_UMODE_BLOCK_PRIVMSG)
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
409 strcat(buf, "[blocks private messages] ");
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
410 if (mode & SILC_UMODE_DETACHED)
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
411 strcat(buf, "[detached] ");
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
412 if (mode & SILC_UMODE_REJECT_WATCHING)
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
413 strcat(buf, "[rejects watching] ");
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
414 if (mode & SILC_UMODE_BLOCK_INVITE)
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
415 strcat(buf, "[blocks invites] ");
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
416 }
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
417
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
418 void silcgaim_get_chmode_string(SilcUInt32 mode, char *buf,
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
419 SilcUInt32 buf_size)
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
420 {
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
421 memset(buf, 0, buf_size);
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
422 if (mode & SILC_CHANNEL_MODE_FOUNDER_AUTH)
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
423 strcat(buf, "[permanent] ");
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
424 if (mode & SILC_CHANNEL_MODE_PRIVATE)
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
425 strcat(buf, "[private] ");
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
426 if (mode & SILC_CHANNEL_MODE_SECRET)
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
427 strcat(buf, "[secret] ");
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
428 if (mode & SILC_CHANNEL_MODE_SECRET)
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
429 strcat(buf, "[secret] ");
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
430 if (mode & SILC_CHANNEL_MODE_PRIVKEY)
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
431 strcat(buf, "[private key] ");
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
432 if (mode & SILC_CHANNEL_MODE_INVITE)
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
433 strcat(buf, "[invite only] ");
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
434 if (mode & SILC_CHANNEL_MODE_TOPIC)
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
435 strcat(buf, "[topic restricted] ");
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
436 if (mode & SILC_CHANNEL_MODE_ULIMIT)
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
437 strcat(buf, "[user count limit] ");
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
438 if (mode & SILC_CHANNEL_MODE_PASSPHRASE)
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
439 strcat(buf, "[passphrase auth] ");
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
440 if (mode & SILC_CHANNEL_MODE_CHANNEL_AUTH)
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
441 strcat(buf, "[public key auth] ");
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
442 if (mode & SILC_CHANNEL_MODE_SILENCE_USERS)
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
443 strcat(buf, "[users silenced] ");
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
444 if (mode & SILC_CHANNEL_MODE_SILENCE_OPERS)
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
445 strcat(buf, "[operators silenced] ");
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
446 }
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
447
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
448 void silcgaim_get_chumode_string(SilcUInt32 mode, char *buf,
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
449 SilcUInt32 buf_size)
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
450 {
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
451 memset(buf, 0, buf_size);
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
452 if (mode & SILC_CHANNEL_UMODE_CHANFO)
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
453 strcat(buf, "[founder] ");
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
454 if (mode & SILC_CHANNEL_UMODE_CHANOP)
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
455 strcat(buf, "[operator] ");
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
456 if (mode & SILC_CHANNEL_UMODE_BLOCK_MESSAGES)
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
457 strcat(buf, "[blocks messages] ");
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
458 if (mode & SILC_CHANNEL_UMODE_BLOCK_MESSAGES_USERS)
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
459 strcat(buf, "[blocks user messages] ");
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
460 if (mode & SILC_CHANNEL_UMODE_BLOCK_MESSAGES_ROBOTS)
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
461 strcat(buf, "[blocks robot messages] ");
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
462 if (mode & SILC_CHANNEL_UMODE_QUIET)
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
463 strcat(buf, "[quieted] ");
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
464 }
9488
2770a0e659ca [gaim-migrate @ 10313]
Ethan Blanton <elb@pidgin.im>
parents: 9353
diff changeset
465
2770a0e659ca [gaim-migrate @ 10313]
Ethan Blanton <elb@pidgin.im>
parents: 9353
diff changeset
466 void
2770a0e659ca [gaim-migrate @ 10313]
Ethan Blanton <elb@pidgin.im>
parents: 9353
diff changeset
467 silcgaim_parse_attrs(SilcDList attrs, char **moodstr, char **statusstr,
2770a0e659ca [gaim-migrate @ 10313]
Ethan Blanton <elb@pidgin.im>
parents: 9353
diff changeset
468 char **contactstr, char **langstr, char **devicestr,
2770a0e659ca [gaim-migrate @ 10313]
Ethan Blanton <elb@pidgin.im>
parents: 9353
diff changeset
469 char **tzstr, char **geostr)
2770a0e659ca [gaim-migrate @ 10313]
Ethan Blanton <elb@pidgin.im>
parents: 9353
diff changeset
470 {
2770a0e659ca [gaim-migrate @ 10313]
Ethan Blanton <elb@pidgin.im>
parents: 9353
diff changeset
471 SilcAttributePayload attr;
2770a0e659ca [gaim-migrate @ 10313]
Ethan Blanton <elb@pidgin.im>
parents: 9353
diff changeset
472 SilcAttributeMood mood = 0;
2770a0e659ca [gaim-migrate @ 10313]
Ethan Blanton <elb@pidgin.im>
parents: 9353
diff changeset
473 SilcAttributeContact contact;
2770a0e659ca [gaim-migrate @ 10313]
Ethan Blanton <elb@pidgin.im>
parents: 9353
diff changeset
474 SilcAttributeObjDevice device;
2770a0e659ca [gaim-migrate @ 10313]
Ethan Blanton <elb@pidgin.im>
parents: 9353
diff changeset
475 SilcAttributeObjGeo geo;
2770a0e659ca [gaim-migrate @ 10313]
Ethan Blanton <elb@pidgin.im>
parents: 9353
diff changeset
476
2770a0e659ca [gaim-migrate @ 10313]
Ethan Blanton <elb@pidgin.im>
parents: 9353
diff changeset
477 char tmp[1024];
2770a0e659ca [gaim-migrate @ 10313]
Ethan Blanton <elb@pidgin.im>
parents: 9353
diff changeset
478 GString *s;
2770a0e659ca [gaim-migrate @ 10313]
Ethan Blanton <elb@pidgin.im>
parents: 9353
diff changeset
479
2770a0e659ca [gaim-migrate @ 10313]
Ethan Blanton <elb@pidgin.im>
parents: 9353
diff changeset
480 *moodstr = NULL;
2770a0e659ca [gaim-migrate @ 10313]
Ethan Blanton <elb@pidgin.im>
parents: 9353
diff changeset
481 *statusstr = NULL;
2770a0e659ca [gaim-migrate @ 10313]
Ethan Blanton <elb@pidgin.im>
parents: 9353
diff changeset
482 *contactstr = NULL;
2770a0e659ca [gaim-migrate @ 10313]
Ethan Blanton <elb@pidgin.im>
parents: 9353
diff changeset
483 *langstr = NULL;
2770a0e659ca [gaim-migrate @ 10313]
Ethan Blanton <elb@pidgin.im>
parents: 9353
diff changeset
484 *devicestr = NULL;
2770a0e659ca [gaim-migrate @ 10313]
Ethan Blanton <elb@pidgin.im>
parents: 9353
diff changeset
485 *tzstr = NULL;
2770a0e659ca [gaim-migrate @ 10313]
Ethan Blanton <elb@pidgin.im>
parents: 9353
diff changeset
486 *geostr = NULL;
2770a0e659ca [gaim-migrate @ 10313]
Ethan Blanton <elb@pidgin.im>
parents: 9353
diff changeset
487
2770a0e659ca [gaim-migrate @ 10313]
Ethan Blanton <elb@pidgin.im>
parents: 9353
diff changeset
488 if (!attrs)
2770a0e659ca [gaim-migrate @ 10313]
Ethan Blanton <elb@pidgin.im>
parents: 9353
diff changeset
489 return;
2770a0e659ca [gaim-migrate @ 10313]
Ethan Blanton <elb@pidgin.im>
parents: 9353
diff changeset
490
2770a0e659ca [gaim-migrate @ 10313]
Ethan Blanton <elb@pidgin.im>
parents: 9353
diff changeset
491 s = g_string_new("");
2770a0e659ca [gaim-migrate @ 10313]
Ethan Blanton <elb@pidgin.im>
parents: 9353
diff changeset
492 attr = silcgaim_get_attr(attrs, SILC_ATTRIBUTE_STATUS_MOOD);
2770a0e659ca [gaim-migrate @ 10313]
Ethan Blanton <elb@pidgin.im>
parents: 9353
diff changeset
493 if (attr && silc_attribute_get_object(attr, &mood, sizeof(mood))) {
2770a0e659ca [gaim-migrate @ 10313]
Ethan Blanton <elb@pidgin.im>
parents: 9353
diff changeset
494 if (mood & SILC_ATTRIBUTE_MOOD_HAPPY)
2770a0e659ca [gaim-migrate @ 10313]
Ethan Blanton <elb@pidgin.im>
parents: 9353
diff changeset
495 g_string_append_printf(s, "[%s] ", _("Happy"));
2770a0e659ca [gaim-migrate @ 10313]
Ethan Blanton <elb@pidgin.im>
parents: 9353
diff changeset
496 if (mood & SILC_ATTRIBUTE_MOOD_SAD)
2770a0e659ca [gaim-migrate @ 10313]
Ethan Blanton <elb@pidgin.im>
parents: 9353
diff changeset
497 g_string_append_printf(s, "[%s] ", _("Sad"));
2770a0e659ca [gaim-migrate @ 10313]
Ethan Blanton <elb@pidgin.im>
parents: 9353
diff changeset
498 if (mood & SILC_ATTRIBUTE_MOOD_ANGRY)
2770a0e659ca [gaim-migrate @ 10313]
Ethan Blanton <elb@pidgin.im>
parents: 9353
diff changeset
499 g_string_append_printf(s, "[%s] ", _("Angry"));
2770a0e659ca [gaim-migrate @ 10313]
Ethan Blanton <elb@pidgin.im>
parents: 9353
diff changeset
500 if (mood & SILC_ATTRIBUTE_MOOD_JEALOUS)
2770a0e659ca [gaim-migrate @ 10313]
Ethan Blanton <elb@pidgin.im>
parents: 9353
diff changeset
501 g_string_append_printf(s, "[%s] ", _("Jealous"));
2770a0e659ca [gaim-migrate @ 10313]
Ethan Blanton <elb@pidgin.im>
parents: 9353
diff changeset
502 if (mood & SILC_ATTRIBUTE_MOOD_ASHAMED)
2770a0e659ca [gaim-migrate @ 10313]
Ethan Blanton <elb@pidgin.im>
parents: 9353
diff changeset
503 g_string_append_printf(s, "[%s] ", _("Ashamed"));
2770a0e659ca [gaim-migrate @ 10313]
Ethan Blanton <elb@pidgin.im>
parents: 9353
diff changeset
504 if (mood & SILC_ATTRIBUTE_MOOD_INVINCIBLE)
2770a0e659ca [gaim-migrate @ 10313]
Ethan Blanton <elb@pidgin.im>
parents: 9353
diff changeset
505 g_string_append_printf(s, "[%s] ", _("Invincible"));
2770a0e659ca [gaim-migrate @ 10313]
Ethan Blanton <elb@pidgin.im>
parents: 9353
diff changeset
506 if (mood & SILC_ATTRIBUTE_MOOD_INLOVE)
2770a0e659ca [gaim-migrate @ 10313]
Ethan Blanton <elb@pidgin.im>
parents: 9353
diff changeset
507 g_string_append_printf(s, "[%s] ", _("In Love"));
2770a0e659ca [gaim-migrate @ 10313]
Ethan Blanton <elb@pidgin.im>
parents: 9353
diff changeset
508 if (mood & SILC_ATTRIBUTE_MOOD_SLEEPY)
2770a0e659ca [gaim-migrate @ 10313]
Ethan Blanton <elb@pidgin.im>
parents: 9353
diff changeset
509 g_string_append_printf(s, "[%s] ", _("Sleepy"));
2770a0e659ca [gaim-migrate @ 10313]
Ethan Blanton <elb@pidgin.im>
parents: 9353
diff changeset
510 if (mood & SILC_ATTRIBUTE_MOOD_BORED)
2770a0e659ca [gaim-migrate @ 10313]
Ethan Blanton <elb@pidgin.im>
parents: 9353
diff changeset
511 g_string_append_printf(s, "[%s] ", _("Bored"));
2770a0e659ca [gaim-migrate @ 10313]
Ethan Blanton <elb@pidgin.im>
parents: 9353
diff changeset
512 if (mood & SILC_ATTRIBUTE_MOOD_EXCITED)
2770a0e659ca [gaim-migrate @ 10313]
Ethan Blanton <elb@pidgin.im>
parents: 9353
diff changeset
513 g_string_append_printf(s, "[%s] ", _("Excited"));
2770a0e659ca [gaim-migrate @ 10313]
Ethan Blanton <elb@pidgin.im>
parents: 9353
diff changeset
514 if (mood & SILC_ATTRIBUTE_MOOD_ANXIOUS)
2770a0e659ca [gaim-migrate @ 10313]
Ethan Blanton <elb@pidgin.im>
parents: 9353
diff changeset
515 g_string_append_printf(s, "[%s] ", _("Anxious"));
2770a0e659ca [gaim-migrate @ 10313]
Ethan Blanton <elb@pidgin.im>
parents: 9353
diff changeset
516 }
2770a0e659ca [gaim-migrate @ 10313]
Ethan Blanton <elb@pidgin.im>
parents: 9353
diff changeset
517 if (strlen(s->str)) {
2770a0e659ca [gaim-migrate @ 10313]
Ethan Blanton <elb@pidgin.im>
parents: 9353
diff changeset
518 *moodstr = s->str;
2770a0e659ca [gaim-migrate @ 10313]
Ethan Blanton <elb@pidgin.im>
parents: 9353
diff changeset
519 g_string_free(s, FALSE);
2770a0e659ca [gaim-migrate @ 10313]
Ethan Blanton <elb@pidgin.im>
parents: 9353
diff changeset
520 } else
2770a0e659ca [gaim-migrate @ 10313]
Ethan Blanton <elb@pidgin.im>
parents: 9353
diff changeset
521 g_string_free(s, TRUE);
2770a0e659ca [gaim-migrate @ 10313]
Ethan Blanton <elb@pidgin.im>
parents: 9353
diff changeset
522
2770a0e659ca [gaim-migrate @ 10313]
Ethan Blanton <elb@pidgin.im>
parents: 9353
diff changeset
523 attr = silcgaim_get_attr(attrs, SILC_ATTRIBUTE_STATUS_FREETEXT);
2770a0e659ca [gaim-migrate @ 10313]
Ethan Blanton <elb@pidgin.im>
parents: 9353
diff changeset
524 memset(tmp, 0, sizeof(tmp));
2770a0e659ca [gaim-migrate @ 10313]
Ethan Blanton <elb@pidgin.im>
parents: 9353
diff changeset
525 if (attr && silc_attribute_get_object(attr, tmp, sizeof(tmp)))
2770a0e659ca [gaim-migrate @ 10313]
Ethan Blanton <elb@pidgin.im>
parents: 9353
diff changeset
526 *statusstr = g_strdup(tmp);
2770a0e659ca [gaim-migrate @ 10313]
Ethan Blanton <elb@pidgin.im>
parents: 9353
diff changeset
527
2770a0e659ca [gaim-migrate @ 10313]
Ethan Blanton <elb@pidgin.im>
parents: 9353
diff changeset
528 s = g_string_new("");
2770a0e659ca [gaim-migrate @ 10313]
Ethan Blanton <elb@pidgin.im>
parents: 9353
diff changeset
529 attr = silcgaim_get_attr(attrs, SILC_ATTRIBUTE_PREFERRED_CONTACT);
2770a0e659ca [gaim-migrate @ 10313]
Ethan Blanton <elb@pidgin.im>
parents: 9353
diff changeset
530 if (attr && silc_attribute_get_object(attr, &contact, sizeof(contact))) {
2770a0e659ca [gaim-migrate @ 10313]
Ethan Blanton <elb@pidgin.im>
parents: 9353
diff changeset
531 if (contact & SILC_ATTRIBUTE_CONTACT_CHAT)
2770a0e659ca [gaim-migrate @ 10313]
Ethan Blanton <elb@pidgin.im>
parents: 9353
diff changeset
532 g_string_append_printf(s, "[%s] ", _("Chat"));
2770a0e659ca [gaim-migrate @ 10313]
Ethan Blanton <elb@pidgin.im>
parents: 9353
diff changeset
533 if (contact & SILC_ATTRIBUTE_CONTACT_EMAIL)
13545
cfc2f7fcb3dd [gaim-migrate @ 15922]
Richard Laager <rlaager@wiktel.com>
parents: 12217
diff changeset
534 g_string_append_printf(s, "[%s] ", _("E-Mail"));
9488
2770a0e659ca [gaim-migrate @ 10313]
Ethan Blanton <elb@pidgin.im>
parents: 9353
diff changeset
535 if (contact & SILC_ATTRIBUTE_CONTACT_CALL)
2770a0e659ca [gaim-migrate @ 10313]
Ethan Blanton <elb@pidgin.im>
parents: 9353
diff changeset
536 g_string_append_printf(s, "[%s] ", _("Phone"));
2770a0e659ca [gaim-migrate @ 10313]
Ethan Blanton <elb@pidgin.im>
parents: 9353
diff changeset
537 if (contact & SILC_ATTRIBUTE_CONTACT_PAGE)
2770a0e659ca [gaim-migrate @ 10313]
Ethan Blanton <elb@pidgin.im>
parents: 9353
diff changeset
538 g_string_append_printf(s, "[%s] ", _("Paging"));
2770a0e659ca [gaim-migrate @ 10313]
Ethan Blanton <elb@pidgin.im>
parents: 9353
diff changeset
539 if (contact & SILC_ATTRIBUTE_CONTACT_SMS)
2770a0e659ca [gaim-migrate @ 10313]
Ethan Blanton <elb@pidgin.im>
parents: 9353
diff changeset
540 g_string_append_printf(s, "[%s] ", _("SMS"));
2770a0e659ca [gaim-migrate @ 10313]
Ethan Blanton <elb@pidgin.im>
parents: 9353
diff changeset
541 if (contact & SILC_ATTRIBUTE_CONTACT_MMS)
2770a0e659ca [gaim-migrate @ 10313]
Ethan Blanton <elb@pidgin.im>
parents: 9353
diff changeset
542 g_string_append_printf(s, "[%s] ", _("MMS"));
2770a0e659ca [gaim-migrate @ 10313]
Ethan Blanton <elb@pidgin.im>
parents: 9353
diff changeset
543 if (contact & SILC_ATTRIBUTE_CONTACT_VIDEO)
2770a0e659ca [gaim-migrate @ 10313]
Ethan Blanton <elb@pidgin.im>
parents: 9353
diff changeset
544 g_string_append_printf(s, "[%s] ", _("Video Conferencing"));
2770a0e659ca [gaim-migrate @ 10313]
Ethan Blanton <elb@pidgin.im>
parents: 9353
diff changeset
545 }
2770a0e659ca [gaim-migrate @ 10313]
Ethan Blanton <elb@pidgin.im>
parents: 9353
diff changeset
546 if (strlen(s->str)) {
2770a0e659ca [gaim-migrate @ 10313]
Ethan Blanton <elb@pidgin.im>
parents: 9353
diff changeset
547 *contactstr = s->str;
2770a0e659ca [gaim-migrate @ 10313]
Ethan Blanton <elb@pidgin.im>
parents: 9353
diff changeset
548 g_string_free(s, FALSE);
2770a0e659ca [gaim-migrate @ 10313]
Ethan Blanton <elb@pidgin.im>
parents: 9353
diff changeset
549 } else
2770a0e659ca [gaim-migrate @ 10313]
Ethan Blanton <elb@pidgin.im>
parents: 9353
diff changeset
550 g_string_free(s, TRUE);
2770a0e659ca [gaim-migrate @ 10313]
Ethan Blanton <elb@pidgin.im>
parents: 9353
diff changeset
551
2770a0e659ca [gaim-migrate @ 10313]
Ethan Blanton <elb@pidgin.im>
parents: 9353
diff changeset
552 attr = silcgaim_get_attr(attrs, SILC_ATTRIBUTE_PREFERRED_LANGUAGE);
2770a0e659ca [gaim-migrate @ 10313]
Ethan Blanton <elb@pidgin.im>
parents: 9353
diff changeset
553 memset(tmp, 0, sizeof(tmp));
2770a0e659ca [gaim-migrate @ 10313]
Ethan Blanton <elb@pidgin.im>
parents: 9353
diff changeset
554 if (attr && silc_attribute_get_object(attr, tmp, sizeof(tmp)))
2770a0e659ca [gaim-migrate @ 10313]
Ethan Blanton <elb@pidgin.im>
parents: 9353
diff changeset
555 *langstr = g_strdup(tmp);
2770a0e659ca [gaim-migrate @ 10313]
Ethan Blanton <elb@pidgin.im>
parents: 9353
diff changeset
556
2770a0e659ca [gaim-migrate @ 10313]
Ethan Blanton <elb@pidgin.im>
parents: 9353
diff changeset
557 s = g_string_new("");
2770a0e659ca [gaim-migrate @ 10313]
Ethan Blanton <elb@pidgin.im>
parents: 9353
diff changeset
558 attr = silcgaim_get_attr(attrs, SILC_ATTRIBUTE_DEVICE_INFO);
2770a0e659ca [gaim-migrate @ 10313]
Ethan Blanton <elb@pidgin.im>
parents: 9353
diff changeset
559 memset(&device, 0, sizeof(device));
2770a0e659ca [gaim-migrate @ 10313]
Ethan Blanton <elb@pidgin.im>
parents: 9353
diff changeset
560 if (attr && silc_attribute_get_object(attr, &device, sizeof(device))) {
2770a0e659ca [gaim-migrate @ 10313]
Ethan Blanton <elb@pidgin.im>
parents: 9353
diff changeset
561 if (device.type == SILC_ATTRIBUTE_DEVICE_COMPUTER)
2770a0e659ca [gaim-migrate @ 10313]
Ethan Blanton <elb@pidgin.im>
parents: 9353
diff changeset
562 g_string_append_printf(s, "%s: ", _("Computer"));
2770a0e659ca [gaim-migrate @ 10313]
Ethan Blanton <elb@pidgin.im>
parents: 9353
diff changeset
563 if (device.type == SILC_ATTRIBUTE_DEVICE_MOBILE_PHONE)
2770a0e659ca [gaim-migrate @ 10313]
Ethan Blanton <elb@pidgin.im>
parents: 9353
diff changeset
564 g_string_append_printf(s, "%s: ", _("Mobile Phone"));
2770a0e659ca [gaim-migrate @ 10313]
Ethan Blanton <elb@pidgin.im>
parents: 9353
diff changeset
565 if (device.type == SILC_ATTRIBUTE_DEVICE_PDA)
2770a0e659ca [gaim-migrate @ 10313]
Ethan Blanton <elb@pidgin.im>
parents: 9353
diff changeset
566 g_string_append_printf(s, "%s: ", _("PDA"));
2770a0e659ca [gaim-migrate @ 10313]
Ethan Blanton <elb@pidgin.im>
parents: 9353
diff changeset
567 if (device.type == SILC_ATTRIBUTE_DEVICE_TERMINAL)
2770a0e659ca [gaim-migrate @ 10313]
Ethan Blanton <elb@pidgin.im>
parents: 9353
diff changeset
568 g_string_append_printf(s, "%s: ", _("Terminal"));
2770a0e659ca [gaim-migrate @ 10313]
Ethan Blanton <elb@pidgin.im>
parents: 9353
diff changeset
569 g_string_append_printf(s, "%s %s %s %s",
2770a0e659ca [gaim-migrate @ 10313]
Ethan Blanton <elb@pidgin.im>
parents: 9353
diff changeset
570 device.manufacturer ? device.manufacturer : "",
2770a0e659ca [gaim-migrate @ 10313]
Ethan Blanton <elb@pidgin.im>
parents: 9353
diff changeset
571 device.version ? device.version : "",
2770a0e659ca [gaim-migrate @ 10313]
Ethan Blanton <elb@pidgin.im>
parents: 9353
diff changeset
572 device.model ? device.model : "",
2770a0e659ca [gaim-migrate @ 10313]
Ethan Blanton <elb@pidgin.im>
parents: 9353
diff changeset
573 device.language ? device.language : "");
2770a0e659ca [gaim-migrate @ 10313]
Ethan Blanton <elb@pidgin.im>
parents: 9353
diff changeset
574 }
2770a0e659ca [gaim-migrate @ 10313]
Ethan Blanton <elb@pidgin.im>
parents: 9353
diff changeset
575 if (strlen(s->str)) {
2770a0e659ca [gaim-migrate @ 10313]
Ethan Blanton <elb@pidgin.im>
parents: 9353
diff changeset
576 *devicestr = s->str;
2770a0e659ca [gaim-migrate @ 10313]
Ethan Blanton <elb@pidgin.im>
parents: 9353
diff changeset
577 g_string_free(s, FALSE);
2770a0e659ca [gaim-migrate @ 10313]
Ethan Blanton <elb@pidgin.im>
parents: 9353
diff changeset
578 } else
2770a0e659ca [gaim-migrate @ 10313]
Ethan Blanton <elb@pidgin.im>
parents: 9353
diff changeset
579 g_string_free(s, TRUE);
2770a0e659ca [gaim-migrate @ 10313]
Ethan Blanton <elb@pidgin.im>
parents: 9353
diff changeset
580
2770a0e659ca [gaim-migrate @ 10313]
Ethan Blanton <elb@pidgin.im>
parents: 9353
diff changeset
581 attr = silcgaim_get_attr(attrs, SILC_ATTRIBUTE_TIMEZONE);
2770a0e659ca [gaim-migrate @ 10313]
Ethan Blanton <elb@pidgin.im>
parents: 9353
diff changeset
582 memset(tmp, 0, sizeof(tmp));
2770a0e659ca [gaim-migrate @ 10313]
Ethan Blanton <elb@pidgin.im>
parents: 9353
diff changeset
583 if (attr && silc_attribute_get_object(attr, tmp, sizeof(tmp)))
2770a0e659ca [gaim-migrate @ 10313]
Ethan Blanton <elb@pidgin.im>
parents: 9353
diff changeset
584 *tzstr = g_strdup(tmp);
2770a0e659ca [gaim-migrate @ 10313]
Ethan Blanton <elb@pidgin.im>
parents: 9353
diff changeset
585
2770a0e659ca [gaim-migrate @ 10313]
Ethan Blanton <elb@pidgin.im>
parents: 9353
diff changeset
586 attr = silcgaim_get_attr(attrs, SILC_ATTRIBUTE_GEOLOCATION);
2770a0e659ca [gaim-migrate @ 10313]
Ethan Blanton <elb@pidgin.im>
parents: 9353
diff changeset
587 memset(&geo, 0, sizeof(geo));
2770a0e659ca [gaim-migrate @ 10313]
Ethan Blanton <elb@pidgin.im>
parents: 9353
diff changeset
588 if (attr && silc_attribute_get_object(attr, &geo, sizeof(geo)))
2770a0e659ca [gaim-migrate @ 10313]
Ethan Blanton <elb@pidgin.im>
parents: 9353
diff changeset
589 *geostr = g_strdup_printf("%s %s %s (%s)",
2770a0e659ca [gaim-migrate @ 10313]
Ethan Blanton <elb@pidgin.im>
parents: 9353
diff changeset
590 geo.longitude ? geo.longitude : "",
2770a0e659ca [gaim-migrate @ 10313]
Ethan Blanton <elb@pidgin.im>
parents: 9353
diff changeset
591 geo.latitude ? geo.latitude : "",
2770a0e659ca [gaim-migrate @ 10313]
Ethan Blanton <elb@pidgin.im>
parents: 9353
diff changeset
592 geo.altitude ? geo.altitude : "",
2770a0e659ca [gaim-migrate @ 10313]
Ethan Blanton <elb@pidgin.im>
parents: 9353
diff changeset
593 geo.accuracy ? geo.accuracy : "");
2770a0e659ca [gaim-migrate @ 10313]
Ethan Blanton <elb@pidgin.im>
parents: 9353
diff changeset
594 }
12217
029802981b81 [gaim-migrate @ 14519]
Stu Tomlinson <stu@nosnilmot.com>
parents: 11488
diff changeset
595
029802981b81 [gaim-migrate @ 14519]
Stu Tomlinson <stu@nosnilmot.com>
parents: 11488
diff changeset
596 #ifdef HAVE_SILCMIME_H
029802981b81 [gaim-migrate @ 14519]
Stu Tomlinson <stu@nosnilmot.com>
parents: 11488
diff changeset
597 /* Returns MIME type of filetype */
029802981b81 [gaim-migrate @ 14519]
Stu Tomlinson <stu@nosnilmot.com>
parents: 11488
diff changeset
598
029802981b81 [gaim-migrate @ 14519]
Stu Tomlinson <stu@nosnilmot.com>
parents: 11488
diff changeset
599 char *silcgaim_file2mime(const char *filename)
029802981b81 [gaim-migrate @ 14519]
Stu Tomlinson <stu@nosnilmot.com>
parents: 11488
diff changeset
600 {
029802981b81 [gaim-migrate @ 14519]
Stu Tomlinson <stu@nosnilmot.com>
parents: 11488
diff changeset
601 const char *ct;
029802981b81 [gaim-migrate @ 14519]
Stu Tomlinson <stu@nosnilmot.com>
parents: 11488
diff changeset
602
029802981b81 [gaim-migrate @ 14519]
Stu Tomlinson <stu@nosnilmot.com>
parents: 11488
diff changeset
603 ct = strrchr(filename, '.');
029802981b81 [gaim-migrate @ 14519]
Stu Tomlinson <stu@nosnilmot.com>
parents: 11488
diff changeset
604 if (!ct)
029802981b81 [gaim-migrate @ 14519]
Stu Tomlinson <stu@nosnilmot.com>
parents: 11488
diff changeset
605 return NULL;
029802981b81 [gaim-migrate @ 14519]
Stu Tomlinson <stu@nosnilmot.com>
parents: 11488
diff changeset
606 else if (!strcasecmp(".png", ct))
029802981b81 [gaim-migrate @ 14519]
Stu Tomlinson <stu@nosnilmot.com>
parents: 11488
diff changeset
607 return strdup("image/png");
029802981b81 [gaim-migrate @ 14519]
Stu Tomlinson <stu@nosnilmot.com>
parents: 11488
diff changeset
608 else if (!strcasecmp(".jpg", ct))
029802981b81 [gaim-migrate @ 14519]
Stu Tomlinson <stu@nosnilmot.com>
parents: 11488
diff changeset
609 return strdup("image/jpeg");
029802981b81 [gaim-migrate @ 14519]
Stu Tomlinson <stu@nosnilmot.com>
parents: 11488
diff changeset
610 else if (!strcasecmp(".jpeg", ct))
029802981b81 [gaim-migrate @ 14519]
Stu Tomlinson <stu@nosnilmot.com>
parents: 11488
diff changeset
611 return strdup("image/jpeg");
029802981b81 [gaim-migrate @ 14519]
Stu Tomlinson <stu@nosnilmot.com>
parents: 11488
diff changeset
612 else if (!strcasecmp(".gif", ct))
029802981b81 [gaim-migrate @ 14519]
Stu Tomlinson <stu@nosnilmot.com>
parents: 11488
diff changeset
613 return strdup("image/gif");
029802981b81 [gaim-migrate @ 14519]
Stu Tomlinson <stu@nosnilmot.com>
parents: 11488
diff changeset
614 else if (!strcasecmp(".tiff", ct))
029802981b81 [gaim-migrate @ 14519]
Stu Tomlinson <stu@nosnilmot.com>
parents: 11488
diff changeset
615 return strdup("image/tiff");
029802981b81 [gaim-migrate @ 14519]
Stu Tomlinson <stu@nosnilmot.com>
parents: 11488
diff changeset
616
029802981b81 [gaim-migrate @ 14519]
Stu Tomlinson <stu@nosnilmot.com>
parents: 11488
diff changeset
617 return NULL;
029802981b81 [gaim-migrate @ 14519]
Stu Tomlinson <stu@nosnilmot.com>
parents: 11488
diff changeset
618 }
029802981b81 [gaim-migrate @ 14519]
Stu Tomlinson <stu@nosnilmot.com>
parents: 11488
diff changeset
619
029802981b81 [gaim-migrate @ 14519]
Stu Tomlinson <stu@nosnilmot.com>
parents: 11488
diff changeset
620 /* Checks if message has images, and assembles MIME message if it has.
029802981b81 [gaim-migrate @ 14519]
Stu Tomlinson <stu@nosnilmot.com>
parents: 11488
diff changeset
621 If only one image is present, creates simple MIME image message. If
029802981b81 [gaim-migrate @ 14519]
Stu Tomlinson <stu@nosnilmot.com>
parents: 11488
diff changeset
622 there are multiple images and/or text with images multipart MIME
029802981b81 [gaim-migrate @ 14519]
Stu Tomlinson <stu@nosnilmot.com>
parents: 11488
diff changeset
623 message is created. */
029802981b81 [gaim-migrate @ 14519]
Stu Tomlinson <stu@nosnilmot.com>
parents: 11488
diff changeset
624
029802981b81 [gaim-migrate @ 14519]
Stu Tomlinson <stu@nosnilmot.com>
parents: 11488
diff changeset
625 SilcDList silcgaim_image_message(const char *msg, SilcUInt32 *mflags)
029802981b81 [gaim-migrate @ 14519]
Stu Tomlinson <stu@nosnilmot.com>
parents: 11488
diff changeset
626 {
029802981b81 [gaim-migrate @ 14519]
Stu Tomlinson <stu@nosnilmot.com>
parents: 11488
diff changeset
627 SilcMime mime = NULL, p;
029802981b81 [gaim-migrate @ 14519]
Stu Tomlinson <stu@nosnilmot.com>
parents: 11488
diff changeset
628 SilcDList list, parts = NULL;
029802981b81 [gaim-migrate @ 14519]
Stu Tomlinson <stu@nosnilmot.com>
parents: 11488
diff changeset
629 const char *start, *end, *last;
029802981b81 [gaim-migrate @ 14519]
Stu Tomlinson <stu@nosnilmot.com>
parents: 11488
diff changeset
630 GData *attribs;
029802981b81 [gaim-migrate @ 14519]
Stu Tomlinson <stu@nosnilmot.com>
parents: 11488
diff changeset
631 char *type;
029802981b81 [gaim-migrate @ 14519]
Stu Tomlinson <stu@nosnilmot.com>
parents: 11488
diff changeset
632 gboolean images = FALSE;
029802981b81 [gaim-migrate @ 14519]
Stu Tomlinson <stu@nosnilmot.com>
parents: 11488
diff changeset
633
029802981b81 [gaim-migrate @ 14519]
Stu Tomlinson <stu@nosnilmot.com>
parents: 11488
diff changeset
634 last = msg;
029802981b81 [gaim-migrate @ 14519]
Stu Tomlinson <stu@nosnilmot.com>
parents: 11488
diff changeset
635 while (last && *last && gaim_markup_find_tag("img", last, &start,
029802981b81 [gaim-migrate @ 14519]
Stu Tomlinson <stu@nosnilmot.com>
parents: 11488
diff changeset
636 &end, &attribs)) {
029802981b81 [gaim-migrate @ 14519]
Stu Tomlinson <stu@nosnilmot.com>
parents: 11488
diff changeset
637 GaimStoredImage *image = NULL;
029802981b81 [gaim-migrate @ 14519]
Stu Tomlinson <stu@nosnilmot.com>
parents: 11488
diff changeset
638 const char *id;
029802981b81 [gaim-migrate @ 14519]
Stu Tomlinson <stu@nosnilmot.com>
parents: 11488
diff changeset
639
029802981b81 [gaim-migrate @ 14519]
Stu Tomlinson <stu@nosnilmot.com>
parents: 11488
diff changeset
640 /* Check if there is text before image */
029802981b81 [gaim-migrate @ 14519]
Stu Tomlinson <stu@nosnilmot.com>
parents: 11488
diff changeset
641 if (start - last) {
029802981b81 [gaim-migrate @ 14519]
Stu Tomlinson <stu@nosnilmot.com>
parents: 11488
diff changeset
642 char *text, *tmp;
029802981b81 [gaim-migrate @ 14519]
Stu Tomlinson <stu@nosnilmot.com>
parents: 11488
diff changeset
643 p = silc_mime_alloc();
029802981b81 [gaim-migrate @ 14519]
Stu Tomlinson <stu@nosnilmot.com>
parents: 11488
diff changeset
644
029802981b81 [gaim-migrate @ 14519]
Stu Tomlinson <stu@nosnilmot.com>
parents: 11488
diff changeset
645 /* Add content type */
029802981b81 [gaim-migrate @ 14519]
Stu Tomlinson <stu@nosnilmot.com>
parents: 11488
diff changeset
646 silc_mime_add_field(p, "Content-Type",
029802981b81 [gaim-migrate @ 14519]
Stu Tomlinson <stu@nosnilmot.com>
parents: 11488
diff changeset
647 "text/plain; charset=utf-8");
029802981b81 [gaim-migrate @ 14519]
Stu Tomlinson <stu@nosnilmot.com>
parents: 11488
diff changeset
648
029802981b81 [gaim-migrate @ 14519]
Stu Tomlinson <stu@nosnilmot.com>
parents: 11488
diff changeset
649 tmp = g_strndup(last, start - last);
029802981b81 [gaim-migrate @ 14519]
Stu Tomlinson <stu@nosnilmot.com>
parents: 11488
diff changeset
650 text = gaim_unescape_html(tmp);
029802981b81 [gaim-migrate @ 14519]
Stu Tomlinson <stu@nosnilmot.com>
parents: 11488
diff changeset
651 g_free(tmp);
029802981b81 [gaim-migrate @ 14519]
Stu Tomlinson <stu@nosnilmot.com>
parents: 11488
diff changeset
652 /* Add text */
029802981b81 [gaim-migrate @ 14519]
Stu Tomlinson <stu@nosnilmot.com>
parents: 11488
diff changeset
653 silc_mime_add_data(p, text, strlen(text));
029802981b81 [gaim-migrate @ 14519]
Stu Tomlinson <stu@nosnilmot.com>
parents: 11488
diff changeset
654 g_free(text);
029802981b81 [gaim-migrate @ 14519]
Stu Tomlinson <stu@nosnilmot.com>
parents: 11488
diff changeset
655
029802981b81 [gaim-migrate @ 14519]
Stu Tomlinson <stu@nosnilmot.com>
parents: 11488
diff changeset
656 if (!parts)
029802981b81 [gaim-migrate @ 14519]
Stu Tomlinson <stu@nosnilmot.com>
parents: 11488
diff changeset
657 parts = silc_dlist_init();
029802981b81 [gaim-migrate @ 14519]
Stu Tomlinson <stu@nosnilmot.com>
parents: 11488
diff changeset
658 silc_dlist_add(parts, p);
029802981b81 [gaim-migrate @ 14519]
Stu Tomlinson <stu@nosnilmot.com>
parents: 11488
diff changeset
659 }
029802981b81 [gaim-migrate @ 14519]
Stu Tomlinson <stu@nosnilmot.com>
parents: 11488
diff changeset
660
029802981b81 [gaim-migrate @ 14519]
Stu Tomlinson <stu@nosnilmot.com>
parents: 11488
diff changeset
661 id = g_datalist_get_data(&attribs, "id");
029802981b81 [gaim-migrate @ 14519]
Stu Tomlinson <stu@nosnilmot.com>
parents: 11488
diff changeset
662 if (id && (image = gaim_imgstore_get(atoi(id)))) {
029802981b81 [gaim-migrate @ 14519]
Stu Tomlinson <stu@nosnilmot.com>
parents: 11488
diff changeset
663 unsigned long imglen = gaim_imgstore_get_size(image);
029802981b81 [gaim-migrate @ 14519]
Stu Tomlinson <stu@nosnilmot.com>
parents: 11488
diff changeset
664 gpointer img = gaim_imgstore_get_data(image);
029802981b81 [gaim-migrate @ 14519]
Stu Tomlinson <stu@nosnilmot.com>
parents: 11488
diff changeset
665
029802981b81 [gaim-migrate @ 14519]
Stu Tomlinson <stu@nosnilmot.com>
parents: 11488
diff changeset
666 p = silc_mime_alloc();
029802981b81 [gaim-migrate @ 14519]
Stu Tomlinson <stu@nosnilmot.com>
parents: 11488
diff changeset
667
029802981b81 [gaim-migrate @ 14519]
Stu Tomlinson <stu@nosnilmot.com>
parents: 11488
diff changeset
668 /* Add content type */
029802981b81 [gaim-migrate @ 14519]
Stu Tomlinson <stu@nosnilmot.com>
parents: 11488
diff changeset
669 type = silcgaim_file2mime(gaim_imgstore_get_filename(image));
029802981b81 [gaim-migrate @ 14519]
Stu Tomlinson <stu@nosnilmot.com>
parents: 11488
diff changeset
670 if (!type) {
029802981b81 [gaim-migrate @ 14519]
Stu Tomlinson <stu@nosnilmot.com>
parents: 11488
diff changeset
671 g_datalist_clear(&attribs);
029802981b81 [gaim-migrate @ 14519]
Stu Tomlinson <stu@nosnilmot.com>
parents: 11488
diff changeset
672 last = end + 1;
029802981b81 [gaim-migrate @ 14519]
Stu Tomlinson <stu@nosnilmot.com>
parents: 11488
diff changeset
673 continue;
029802981b81 [gaim-migrate @ 14519]
Stu Tomlinson <stu@nosnilmot.com>
parents: 11488
diff changeset
674 }
029802981b81 [gaim-migrate @ 14519]
Stu Tomlinson <stu@nosnilmot.com>
parents: 11488
diff changeset
675 silc_mime_add_field(p, "Content-Type", type);
029802981b81 [gaim-migrate @ 14519]
Stu Tomlinson <stu@nosnilmot.com>
parents: 11488
diff changeset
676 silc_free(type);
029802981b81 [gaim-migrate @ 14519]
Stu Tomlinson <stu@nosnilmot.com>
parents: 11488
diff changeset
677
029802981b81 [gaim-migrate @ 14519]
Stu Tomlinson <stu@nosnilmot.com>
parents: 11488
diff changeset
678 /* Add content transfer encoding */
029802981b81 [gaim-migrate @ 14519]
Stu Tomlinson <stu@nosnilmot.com>
parents: 11488
diff changeset
679 silc_mime_add_field(p, "Content-Transfer-Encoding", "binary");
029802981b81 [gaim-migrate @ 14519]
Stu Tomlinson <stu@nosnilmot.com>
parents: 11488
diff changeset
680
029802981b81 [gaim-migrate @ 14519]
Stu Tomlinson <stu@nosnilmot.com>
parents: 11488
diff changeset
681 /* Add image data */
029802981b81 [gaim-migrate @ 14519]
Stu Tomlinson <stu@nosnilmot.com>
parents: 11488
diff changeset
682 silc_mime_add_data(p, img, imglen);
029802981b81 [gaim-migrate @ 14519]
Stu Tomlinson <stu@nosnilmot.com>
parents: 11488
diff changeset
683
029802981b81 [gaim-migrate @ 14519]
Stu Tomlinson <stu@nosnilmot.com>
parents: 11488
diff changeset
684 if (!parts)
029802981b81 [gaim-migrate @ 14519]
Stu Tomlinson <stu@nosnilmot.com>
parents: 11488
diff changeset
685 parts = silc_dlist_init();
029802981b81 [gaim-migrate @ 14519]
Stu Tomlinson <stu@nosnilmot.com>
parents: 11488
diff changeset
686 silc_dlist_add(parts, p);
029802981b81 [gaim-migrate @ 14519]
Stu Tomlinson <stu@nosnilmot.com>
parents: 11488
diff changeset
687 images = TRUE;
029802981b81 [gaim-migrate @ 14519]
Stu Tomlinson <stu@nosnilmot.com>
parents: 11488
diff changeset
688 }
029802981b81 [gaim-migrate @ 14519]
Stu Tomlinson <stu@nosnilmot.com>
parents: 11488
diff changeset
689
029802981b81 [gaim-migrate @ 14519]
Stu Tomlinson <stu@nosnilmot.com>
parents: 11488
diff changeset
690 g_datalist_clear(&attribs);
029802981b81 [gaim-migrate @ 14519]
Stu Tomlinson <stu@nosnilmot.com>
parents: 11488
diff changeset
691
029802981b81 [gaim-migrate @ 14519]
Stu Tomlinson <stu@nosnilmot.com>
parents: 11488
diff changeset
692 /* Continue after tag */
029802981b81 [gaim-migrate @ 14519]
Stu Tomlinson <stu@nosnilmot.com>
parents: 11488
diff changeset
693 last = end + 1;
029802981b81 [gaim-migrate @ 14519]
Stu Tomlinson <stu@nosnilmot.com>
parents: 11488
diff changeset
694 }
029802981b81 [gaim-migrate @ 14519]
Stu Tomlinson <stu@nosnilmot.com>
parents: 11488
diff changeset
695
029802981b81 [gaim-migrate @ 14519]
Stu Tomlinson <stu@nosnilmot.com>
parents: 11488
diff changeset
696 /* Check for text after the image(s) */
029802981b81 [gaim-migrate @ 14519]
Stu Tomlinson <stu@nosnilmot.com>
parents: 11488
diff changeset
697 if (images && last && *last) {
029802981b81 [gaim-migrate @ 14519]
Stu Tomlinson <stu@nosnilmot.com>
parents: 11488
diff changeset
698 char *tmp = gaim_unescape_html(last);
029802981b81 [gaim-migrate @ 14519]
Stu Tomlinson <stu@nosnilmot.com>
parents: 11488
diff changeset
699 p = silc_mime_alloc();
029802981b81 [gaim-migrate @ 14519]
Stu Tomlinson <stu@nosnilmot.com>
parents: 11488
diff changeset
700
029802981b81 [gaim-migrate @ 14519]
Stu Tomlinson <stu@nosnilmot.com>
parents: 11488
diff changeset
701 /* Add content type */
029802981b81 [gaim-migrate @ 14519]
Stu Tomlinson <stu@nosnilmot.com>
parents: 11488
diff changeset
702 silc_mime_add_field(p, "Content-Type",
029802981b81 [gaim-migrate @ 14519]
Stu Tomlinson <stu@nosnilmot.com>
parents: 11488
diff changeset
703 "text/plain; charset=utf-8");
029802981b81 [gaim-migrate @ 14519]
Stu Tomlinson <stu@nosnilmot.com>
parents: 11488
diff changeset
704
029802981b81 [gaim-migrate @ 14519]
Stu Tomlinson <stu@nosnilmot.com>
parents: 11488
diff changeset
705 /* Add text */
029802981b81 [gaim-migrate @ 14519]
Stu Tomlinson <stu@nosnilmot.com>
parents: 11488
diff changeset
706 silc_mime_add_data(p, tmp, strlen(tmp));
029802981b81 [gaim-migrate @ 14519]
Stu Tomlinson <stu@nosnilmot.com>
parents: 11488
diff changeset
707 g_free(tmp);
029802981b81 [gaim-migrate @ 14519]
Stu Tomlinson <stu@nosnilmot.com>
parents: 11488
diff changeset
708
029802981b81 [gaim-migrate @ 14519]
Stu Tomlinson <stu@nosnilmot.com>
parents: 11488
diff changeset
709 if (!parts)
029802981b81 [gaim-migrate @ 14519]
Stu Tomlinson <stu@nosnilmot.com>
parents: 11488
diff changeset
710 parts = silc_dlist_init();
029802981b81 [gaim-migrate @ 14519]
Stu Tomlinson <stu@nosnilmot.com>
parents: 11488
diff changeset
711 silc_dlist_add(parts, p);
029802981b81 [gaim-migrate @ 14519]
Stu Tomlinson <stu@nosnilmot.com>
parents: 11488
diff changeset
712 }
029802981b81 [gaim-migrate @ 14519]
Stu Tomlinson <stu@nosnilmot.com>
parents: 11488
diff changeset
713
029802981b81 [gaim-migrate @ 14519]
Stu Tomlinson <stu@nosnilmot.com>
parents: 11488
diff changeset
714 /* If there weren't any images, don't return anything. */
029802981b81 [gaim-migrate @ 14519]
Stu Tomlinson <stu@nosnilmot.com>
parents: 11488
diff changeset
715 if (!images) {
029802981b81 [gaim-migrate @ 14519]
Stu Tomlinson <stu@nosnilmot.com>
parents: 11488
diff changeset
716 if (parts)
029802981b81 [gaim-migrate @ 14519]
Stu Tomlinson <stu@nosnilmot.com>
parents: 11488
diff changeset
717 silc_dlist_uninit(parts);
029802981b81 [gaim-migrate @ 14519]
Stu Tomlinson <stu@nosnilmot.com>
parents: 11488
diff changeset
718 return NULL;
029802981b81 [gaim-migrate @ 14519]
Stu Tomlinson <stu@nosnilmot.com>
parents: 11488
diff changeset
719 }
029802981b81 [gaim-migrate @ 14519]
Stu Tomlinson <stu@nosnilmot.com>
parents: 11488
diff changeset
720
029802981b81 [gaim-migrate @ 14519]
Stu Tomlinson <stu@nosnilmot.com>
parents: 11488
diff changeset
721 if (silc_dlist_count(parts) > 1) {
029802981b81 [gaim-migrate @ 14519]
Stu Tomlinson <stu@nosnilmot.com>
parents: 11488
diff changeset
722 /* Multipart MIME message */
029802981b81 [gaim-migrate @ 14519]
Stu Tomlinson <stu@nosnilmot.com>
parents: 11488
diff changeset
723 char b[32];
029802981b81 [gaim-migrate @ 14519]
Stu Tomlinson <stu@nosnilmot.com>
parents: 11488
diff changeset
724 mime = silc_mime_alloc();
029802981b81 [gaim-migrate @ 14519]
Stu Tomlinson <stu@nosnilmot.com>
parents: 11488
diff changeset
725 silc_mime_add_field(mime, "MIME-Version", "1.0");
029802981b81 [gaim-migrate @ 14519]
Stu Tomlinson <stu@nosnilmot.com>
parents: 11488
diff changeset
726 g_snprintf(b, sizeof(b), "b%4X%4X",
029802981b81 [gaim-migrate @ 14519]
Stu Tomlinson <stu@nosnilmot.com>
parents: 11488
diff changeset
727 (unsigned int)time(NULL),
029802981b81 [gaim-migrate @ 14519]
Stu Tomlinson <stu@nosnilmot.com>
parents: 11488
diff changeset
728 silc_dlist_count(parts));
029802981b81 [gaim-migrate @ 14519]
Stu Tomlinson <stu@nosnilmot.com>
parents: 11488
diff changeset
729 silc_mime_set_multipart(mime, "mixed", b);
029802981b81 [gaim-migrate @ 14519]
Stu Tomlinson <stu@nosnilmot.com>
parents: 11488
diff changeset
730 silc_dlist_start(parts);
029802981b81 [gaim-migrate @ 14519]
Stu Tomlinson <stu@nosnilmot.com>
parents: 11488
diff changeset
731 while ((p = silc_dlist_get(parts)) != SILC_LIST_END)
029802981b81 [gaim-migrate @ 14519]
Stu Tomlinson <stu@nosnilmot.com>
parents: 11488
diff changeset
732 silc_mime_add_multipart(mime, p);
029802981b81 [gaim-migrate @ 14519]
Stu Tomlinson <stu@nosnilmot.com>
parents: 11488
diff changeset
733 } else {
029802981b81 [gaim-migrate @ 14519]
Stu Tomlinson <stu@nosnilmot.com>
parents: 11488
diff changeset
734 /* Simple MIME message */
029802981b81 [gaim-migrate @ 14519]
Stu Tomlinson <stu@nosnilmot.com>
parents: 11488
diff changeset
735 silc_dlist_start(parts);
029802981b81 [gaim-migrate @ 14519]
Stu Tomlinson <stu@nosnilmot.com>
parents: 11488
diff changeset
736 mime = silc_dlist_get(parts);
029802981b81 [gaim-migrate @ 14519]
Stu Tomlinson <stu@nosnilmot.com>
parents: 11488
diff changeset
737 silc_mime_add_field(mime, "MIME-Version", "1.0");
029802981b81 [gaim-migrate @ 14519]
Stu Tomlinson <stu@nosnilmot.com>
parents: 11488
diff changeset
738 }
029802981b81 [gaim-migrate @ 14519]
Stu Tomlinson <stu@nosnilmot.com>
parents: 11488
diff changeset
739
029802981b81 [gaim-migrate @ 14519]
Stu Tomlinson <stu@nosnilmot.com>
parents: 11488
diff changeset
740 *mflags &= ~SILC_MESSAGE_FLAG_UTF8;
029802981b81 [gaim-migrate @ 14519]
Stu Tomlinson <stu@nosnilmot.com>
parents: 11488
diff changeset
741 *mflags |= SILC_MESSAGE_FLAG_DATA;
029802981b81 [gaim-migrate @ 14519]
Stu Tomlinson <stu@nosnilmot.com>
parents: 11488
diff changeset
742
029802981b81 [gaim-migrate @ 14519]
Stu Tomlinson <stu@nosnilmot.com>
parents: 11488
diff changeset
743 /* Encode message. Fragment if it is too large */
029802981b81 [gaim-migrate @ 14519]
Stu Tomlinson <stu@nosnilmot.com>
parents: 11488
diff changeset
744 list = silc_mime_encode_partial(mime, 0xfc00);
029802981b81 [gaim-migrate @ 14519]
Stu Tomlinson <stu@nosnilmot.com>
parents: 11488
diff changeset
745
029802981b81 [gaim-migrate @ 14519]
Stu Tomlinson <stu@nosnilmot.com>
parents: 11488
diff changeset
746 silc_dlist_uninit(parts);
029802981b81 [gaim-migrate @ 14519]
Stu Tomlinson <stu@nosnilmot.com>
parents: 11488
diff changeset
747
029802981b81 [gaim-migrate @ 14519]
Stu Tomlinson <stu@nosnilmot.com>
parents: 11488
diff changeset
748 /* Added multiparts gets freed here */
029802981b81 [gaim-migrate @ 14519]
Stu Tomlinson <stu@nosnilmot.com>
parents: 11488
diff changeset
749 silc_mime_free(mime);
029802981b81 [gaim-migrate @ 14519]
Stu Tomlinson <stu@nosnilmot.com>
parents: 11488
diff changeset
750
029802981b81 [gaim-migrate @ 14519]
Stu Tomlinson <stu@nosnilmot.com>
parents: 11488
diff changeset
751 return list;
029802981b81 [gaim-migrate @ 14519]
Stu Tomlinson <stu@nosnilmot.com>
parents: 11488
diff changeset
752 }
029802981b81 [gaim-migrate @ 14519]
Stu Tomlinson <stu@nosnilmot.com>
parents: 11488
diff changeset
753
029802981b81 [gaim-migrate @ 14519]
Stu Tomlinson <stu@nosnilmot.com>
parents: 11488
diff changeset
754 #endif /* HAVE_SILCMIME_H */