Mercurial > pidgin
comparison src/protocols/trepia/trepia.c @ 5849:97d1ad7a50cc
[gaim-migrate @ 6280]
Users can now set their Trepia buddy icon.
committer: Tailor Script <tailor@pidgin.im>
author | Christian Hammond <chipx86@chipx86.com> |
---|---|
date | Fri, 13 Jun 2003 09:11:24 +0000 |
parents | 8331918af110 |
children | 082982a4acbd |
comparison
equal
deleted
inserted
replaced
5848:8331918af110 | 5849:97d1ad7a50cc |
---|---|
22 #include "gaim.h" | 22 #include "gaim.h" |
23 #include "account.h" | 23 #include "account.h" |
24 #include "accountopt.h" | 24 #include "accountopt.h" |
25 #include "md5.h" | 25 #include "md5.h" |
26 #include "profile.h" | 26 #include "profile.h" |
27 #include <sys/stat.h> | |
27 #include <string.h> | 28 #include <string.h> |
28 #include <stdlib.h> | 29 #include <stdlib.h> |
29 #include <unistd.h> | 30 #include <unistd.h> |
30 | 31 |
31 /* XXX */ | 32 /* XXX */ |
81 } TrepiaParserData; | 82 } TrepiaParserData; |
82 | 83 |
83 #define TREPIA_SERVER "trepia.com" | 84 #define TREPIA_SERVER "trepia.com" |
84 #define TREPIA_PORT 8201 | 85 #define TREPIA_PORT 8201 |
85 #define TREPIA_REG_PORT 8209 | 86 #define TREPIA_REG_PORT 8209 |
87 | |
88 static const char alphabet[] = | |
89 "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz" | |
90 "0123456789+/"; | |
91 | |
92 static char * | |
93 base64_enc(const char *data, int len) | |
94 { | |
95 char *dest; | |
96 char *buf; | |
97 | |
98 buf = dest = g_malloc(4 * len / 3 + 4); | |
99 | |
100 /* Encode 3 bytes at a time */ | |
101 while (len >= 3) { | |
102 buf[0] = alphabet[(data[0] >> 2) & 0x3F]; | |
103 buf[1] = alphabet[((data[0] << 4) & 0x30) | ((data[1] >> 4) & 0x0F)]; | |
104 buf[2] = alphabet[((data[1] << 2) & 0x3C) | ((data[2] >> 6) & 0x03)]; | |
105 buf[3] = alphabet[data[2] & 0x3F]; | |
106 data += 3; | |
107 buf += 4; | |
108 len -= 3; | |
109 } | |
110 | |
111 if (len > 0) { | |
112 buf[0] = alphabet[(data[0] >> 2) & 0x3F]; | |
113 buf[1] = alphabet[(data[0] << 4) & 0x30]; | |
114 | |
115 if (len > 1) { | |
116 buf[1] += (data[1] >> 4) & 0x0F; | |
117 buf[2] = alphabet[(data[1] << 2) & 0x3C]; | |
118 } | |
119 | |
120 else | |
121 buf[2] = '='; | |
122 | |
123 buf[3] = '='; | |
124 buf += 4; | |
125 } | |
126 | |
127 *buf = '\0'; | |
128 | |
129 return dest; | |
130 } | |
131 | |
86 | 132 |
87 static int | 133 static int |
88 trepia_write(int fd, const char *data, size_t len) | 134 trepia_write(int fd, const char *data, size_t len) |
89 { | 135 { |
90 gaim_debug(GAIM_DEBUG_MISC, "trepia", "C: %s%c", data, | 136 gaim_debug(GAIM_DEBUG_MISC, "trepia", "C: %s%c", data, |
1098 b->proto_data = NULL; | 1144 b->proto_data = NULL; |
1099 } | 1145 } |
1100 } | 1146 } |
1101 | 1147 |
1102 static void | 1148 static void |
1149 trepia_set_buddy_icon(GaimConnection *gc, const char *filename) | |
1150 { | |
1151 TrepiaSession *session = gc->proto_data; | |
1152 struct stat sb; | |
1153 | |
1154 if (!stat(filename, &sb)) { | |
1155 FILE *fp; | |
1156 | |
1157 if ((fp = fopen(filename, "rb")) != NULL) { | |
1158 char *buf = g_malloc(sb.st_size + 1); | |
1159 char *temp; | |
1160 char *out_buf; | |
1161 | |
1162 fread(buf, 1, sb.st_size, fp); | |
1163 | |
1164 buf[sb.st_size] = '\0'; | |
1165 | |
1166 temp = base64_enc(buf, sb.st_size); | |
1167 | |
1168 out_buf = g_strdup_printf("<K><m>%s</m></K>", temp); | |
1169 | |
1170 g_free(temp); | |
1171 g_free(buf); | |
1172 | |
1173 fclose(fp); | |
1174 | |
1175 if (trepia_write(session->fd, out_buf, strlen(out_buf)) < 0) { | |
1176 gaim_connection_error(session->gc, _("Write error")); | |
1177 return; | |
1178 } | |
1179 } | |
1180 } | |
1181 } | |
1182 | |
1183 static void | |
1103 trepia_register_user(GaimAccount *account) | 1184 trepia_register_user(GaimAccount *account) |
1104 { | 1185 { |
1105 #if 0 | 1186 #if 0 |
1106 char *buffer; | 1187 char *buffer; |
1107 | 1188 |
1162 NULL, | 1243 NULL, |
1163 NULL, | 1244 NULL, |
1164 NULL, | 1245 NULL, |
1165 trepia_buddy_free, | 1246 trepia_buddy_free, |
1166 NULL, | 1247 NULL, |
1167 NULL | 1248 NULL, |
1249 trepia_set_buddy_icon | |
1168 }; | 1250 }; |
1169 | 1251 |
1170 static GaimPluginInfo info = | 1252 static GaimPluginInfo info = |
1171 { | 1253 { |
1172 2, /**< api_version */ | 1254 2, /**< api_version */ |