Mercurial > pidgin.yaz
annotate src/protocols/napster/napster.c @ 11157:f068eaabe332
[gaim-migrate @ 13242]
Patch submitted to gaim-devel...
"Marcin Owsiany sent you a draft advisory regarding multiple libgadu
vulnerabilities. "Fortunately" gaim contains an extremely old version of
libgadu and is affected only by memory alignment bug, which cannot be
exploited on x86. No other critical vulnerabilities are known in gaim's
version of libgadu.
You'll find the patch in attachment.
Regards,
Wojtek Kaniewski
ekg/libgadu maintainer"
committer: Tailor Script <tailor@pidgin.im>
author | Richard Laager <rlaager@wiktel.com> |
---|---|
date | Mon, 25 Jul 2005 21:20:14 +0000 |
parents | 50224ac8184d |
children | bb0d7b719af2 |
rev | line source |
---|---|
2086 | 1 /* |
2 * gaim - Napster Protocol Plugin | |
3 * | |
3322 | 4 * Copyright (C) 2000-2001, Rob Flynn <rob@marko.net> |
7084
0909ebf6fb28
[gaim-migrate @ 7649]
Christian Hammond <chipx86@chipx86.com>
parents:
7062
diff
changeset
|
5 * |
2086 | 6 * This program is free software; you can redistribute it and/or modify |
7 * it under the terms of the GNU General Public License as published by | |
8 * the Free Software Foundation; either version 2 of the License, or | |
9 * (at your option) any later version. | |
10 * | |
11 * This program is distributed in the hope that it will be useful, | |
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
14 * GNU General Public License for more details. | |
15 * | |
16 * You should have received a copy of the GNU General Public License | |
17 * along with this program; if not, write to the Free Software | |
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
19 */ | |
5872
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5681
diff
changeset
|
20 #include "internal.h" |
2086 | 21 |
5872
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5681
diff
changeset
|
22 #include "account.h" |
5638
0bdfa28c678e
[gaim-migrate @ 6047]
Christian Hammond <chipx86@chipx86.com>
parents:
5605
diff
changeset
|
23 #include "accountopt.h" |
9030 | 24 #include "blist.h" |
5872
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5681
diff
changeset
|
25 #include "conversation.h" |
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5681
diff
changeset
|
26 #include "debug.h" |
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5681
diff
changeset
|
27 #include "notify.h" |
2086 | 28 #include "prpl.h" |
29 #include "proxy.h" | |
5872
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5681
diff
changeset
|
30 #include "util.h" |
9943 | 31 #include "version.h" |
3630 | 32 |
3322 | 33 #define NAP_SERVER "64.124.41.187" |
34 #define NAP_PORT 8888 | |
35 | |
5604 | 36 #define NAPSTER_CONNECT_STEPS 2 |
37 | |
2086 | 38 GSList *nap_connections = NULL; |
39 | |
40 struct nap_data { | |
41 int fd; | |
42 gchar *email; | |
43 }; | |
44 | |
5679 | 45 static GaimConversation *nap_find_chat(GaimConnection *gc, const char *name) |
2086 | 46 { |
5402 | 47 GSList *bcs = gc->buddy_chats; |
2086 | 48 |
5402 | 49 while (bcs) { |
5679 | 50 GaimConversation *b = bcs->data; |
5402 | 51 if (!gaim_utf8_strcasecmp(b->name, name)) |
5388 | 52 return b; |
5402 | 53 bcs = bcs->next; |
5388 | 54 } |
55 | |
56 return NULL; | |
57 } | |
58 | |
5604 | 59 static void nap_write_packet(GaimConnection *gc, unsigned short command, const char *format, ...) |
5388 | 60 { |
61 struct nap_data *ndata = (struct nap_data *)gc->proto_data; | |
62 va_list ap; | |
63 gchar *message; | |
64 unsigned short size; | |
65 | |
66 va_start(ap, format); | |
67 message = g_strdup_vprintf(format, ap); | |
68 va_end(ap); | |
69 | |
70 size = strlen(message); | |
71 gaim_debug(GAIM_DEBUG_MISC, "napster", "S %3hd: %s\n", command, message); | |
72 | |
73 write(ndata->fd, &size, 2); | |
74 write(ndata->fd, &command, 2); | |
75 write(ndata->fd, message, size); | |
76 | |
77 g_free(message); | |
78 } | |
79 | |
5604 | 80 static int nap_do_irc_style(GaimConnection *gc, const char *message, const char *name) |
5388 | 81 { |
82 gchar **res; | |
83 | |
84 gaim_debug(GAIM_DEBUG_MISC, "napster", "C %s\n", message); | |
85 | |
86 res = g_strsplit(message, " ", 2); | |
87 | |
8386 | 88 if (!g_ascii_strcasecmp(res[0], "/ME")) { /* MSG_CLIENT_PUBLIC */ |
5402 | 89 nap_write_packet(gc, 824, "%s \"%s\"", name, res[1]); |
5388 | 90 |
8386 | 91 } else if (!g_ascii_strcasecmp(res[0], "/MSG")) { /* MSG_CLIENT_PUBLIC */ |
5388 | 92 nap_write_packet(gc, 205, "%s", res[1]); |
4359
5fb47ec9bfe4
[gaim-migrate @ 4625]
Christian Hammond <chipx86@chipx86.com>
parents:
4349
diff
changeset
|
93 |
8386 | 94 } else if (!g_ascii_strcasecmp(res[0], "/JOIN")) { /* join chatroom MSG_CLIENT_JOIN */ |
5388 | 95 if (!res[1]) { |
96 g_strfreev(res); | |
97 return 1; | |
98 } | |
99 if (res[1][0] != '#') | |
100 nap_write_packet(gc, 400, "#%s", res[1]); | |
101 else | |
102 nap_write_packet(gc, 400, "%s", res[1]); | |
103 | |
8386 | 104 } else if (!g_ascii_strcasecmp(res[0], "/PART")) { /* partchatroom MSG_CLIENT_PART */ |
5402 | 105 nap_write_packet(gc, 401, "%s", res[1] ? res[1] : name); |
5388 | 106 |
8386 | 107 } else if (!g_ascii_strcasecmp(res[0], "/TOPIC")) { /* set topic MSG_SERVER_TOPIC */ |
5402 | 108 nap_write_packet(gc, 410, "%s", res[1] ? res[1] : name); |
5388 | 109 |
8386 | 110 } else if (!g_ascii_strcasecmp(res[0], "/WHOIS")) { /* whois request MSG_CLIENT_WHOIS */ |
5388 | 111 nap_write_packet(gc, 603, "%s", res[1]); |
112 | |
8386 | 113 } else if (!g_ascii_strcasecmp(res[0], "/PING")) { /* send ping MSG_CLIENT_PING */ |
5388 | 114 nap_write_packet(gc, 751, "%s", res[1]); |
115 | |
8386 | 116 } else if (!g_ascii_strcasecmp(res[0], "/KICK")) { /* kick asswipe MSG_CLIENT_KICK */ |
5388 | 117 nap_write_packet(gc, 829, "%s", res[1]); |
118 | |
119 } else { | |
120 g_strfreev(res); | |
121 return 1; | |
122 } | |
123 | |
124 g_strfreev(res); | |
125 return 0; | |
126 } | |
127 | |
128 /* 205 - MSG_CLIENT_PRIVMSG */ | |
7118
bf630f7dfdcd
[gaim-migrate @ 7685]
Christian Hammond <chipx86@chipx86.com>
parents:
7084
diff
changeset
|
129 static int nap_send_im(GaimConnection *gc, const char *who, const char *message, GaimConvImFlags flags) |
5388 | 130 { |
131 | |
132 if ((strlen(message) < 2) || (message[0] != '/' ) || (message[1] == '/')) { | |
133 /* Actually send a chat message */ | |
134 nap_write_packet(gc, 205, "%s %s", who, message); | |
135 } else { | |
136 /* user typed an IRC-style command */ | |
137 nap_do_irc_style(gc, message, who); | |
2086 | 138 } |
139 | |
5388 | 140 return 1; |
141 } | |
142 | |
143 /* 207 - MSG_CLIENT_ADD_HOTLIST */ | |
9285 | 144 static void nap_add_buddy(GaimConnection *gc, GaimBuddy *buddy, GaimGroup *group) |
5388 | 145 { |
9285 | 146 nap_write_packet(gc, 207, "%s", buddy->name); |
5388 | 147 } |
148 | |
149 /* 208 - MSG_CLIENT_ADD_HOTLIST_SEQ */ | |
10869 | 150 static void nap_send_buddylist(GaimConnection *gc) |
5388 | 151 { |
10869 | 152 GaimBuddyList *blist; |
153 GaimBlistNode *gnode, *cnode, *bnode; | |
154 GaimBuddy *buddy; | |
155 | |
156 if ((blist = gaim_get_blist()) != NULL) | |
157 { | |
158 for (gnode = blist->root; gnode != NULL; gnode = gnode->next) | |
159 { | |
160 if (!GAIM_BLIST_NODE_IS_GROUP(gnode)) | |
161 continue; | |
162 for (cnode = gnode->child; cnode != NULL; cnode = cnode->next) | |
163 { | |
164 if (!GAIM_BLIST_NODE_IS_CONTACT(cnode)) | |
165 continue; | |
166 for (bnode = cnode->child; bnode != NULL; bnode = bnode->next) | |
167 { | |
168 if (!GAIM_BLIST_NODE_IS_BUDDY(bnode)) | |
169 continue; | |
170 buddy = (GaimBuddy *)bnode; | |
171 nap_write_packet(gc, 208, "%s", buddy->name); | |
172 } | |
173 } | |
174 } | |
5388 | 175 } |
176 } | |
177 | |
178 /* 303 - MSG_CLIENT_REMOVE_HOTLIST */ | |
9285 | 179 static void nap_remove_buddy(GaimConnection *gc, GaimBuddy *buddy, GaimGroup *group) |
5388 | 180 { |
9285 | 181 nap_write_packet(gc, 303, "%s", buddy->name); |
5388 | 182 } |
183 | |
9917 | 184 static char *nap_get_chat_name(GHashTable *data) { |
185 char *name = g_hash_table_lookup(data, "group"); | |
10200 | 186 |
9917 | 187 /* Make sure the name has a # preceding it */ |
188 if (name[0] != '#') { | |
189 return g_strdup_printf("#%s", name); | |
190 } | |
191 | |
192 return g_strdup(name); | |
193 } | |
194 | |
5388 | 195 /* 400 - MSG_CLIENT_JOIN */ |
5604 | 196 static void nap_join_chat(GaimConnection *gc, GHashTable *data) |
5388 | 197 { |
198 char *name; | |
199 | |
200 if (!data) | |
201 return; | |
202 | |
9917 | 203 name = nap_get_chat_name(data); |
5388 | 204 |
9917 | 205 if (name) { |
5388 | 206 nap_write_packet(gc, 400, "%s", name); |
9917 | 207 g_free(name); |
208 } | |
5388 | 209 } |
210 | |
211 /* 401 - MSG_CLIENT_PART */ | |
5604 | 212 static void nap_chat_leave(GaimConnection *gc, int id) |
5388 | 213 { |
5679 | 214 GaimConversation *c = gaim_find_chat(gc, id); |
5388 | 215 |
5402 | 216 if (!c) |
5388 | 217 return; |
218 | |
5402 | 219 nap_write_packet(gc, 401, "%s", c->name); |
5388 | 220 } |
221 | |
222 /* 402 - MSG_CLIENT_PUBLIC */ | |
6059 | 223 static int nap_chat_send(GaimConnection *gc, int id, const char *message) |
5388 | 224 { |
5679 | 225 GaimConversation *c = gaim_find_chat(gc, id); |
5388 | 226 |
5402 | 227 if (!c) |
5388 | 228 return -EINVAL; |
229 | |
230 if ((strlen(message) < 2) || (message[0] != '/' ) || (message[1] == '/')) { | |
231 /* Actually send a chat message */ | |
5402 | 232 nap_write_packet(gc, 402, "%s %s", c->name, message); |
5388 | 233 } else { |
234 /* user typed an IRC-style command */ | |
5402 | 235 nap_do_irc_style(gc, message, c->name); |
5388 | 236 } |
237 | |
238 return 0; | |
239 } | |
240 | |
241 /* 603 - MSG_CLIENT_WHOIS */ | |
5604 | 242 static void nap_get_info(GaimConnection *gc, const char *who) |
5388 | 243 { |
244 nap_write_packet(gc, 603, "%s", who); | |
2086 | 245 } |
246 | |
2090
b66aca8e8dce
[gaim-migrate @ 2100]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
247 static void nap_callback(gpointer data, gint source, GaimInputCondition condition) |
2086 | 248 { |
5604 | 249 GaimConnection *gc = data; |
2086 | 250 struct nap_data *ndata = gc->proto_data; |
10010 | 251 GaimAccount *account = gaim_connection_get_account(gc); |
5679 | 252 GaimConversation *c; |
5402 | 253 gchar *buf, *buf2, *buf3, **res; |
2086 | 254 unsigned short header[2]; |
255 int len; | |
256 int command; | |
2220
8b7ba25a7ece
[gaim-migrate @ 2230]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2205
diff
changeset
|
257 int i; |
2086 | 258 |
5388 | 259 if (read(source, (void*)header, 4) != 4) { |
5604 | 260 gaim_connection_error(gc, _("Unable to read header from server")); |
2220
8b7ba25a7ece
[gaim-migrate @ 2230]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2205
diff
changeset
|
261 return; |
8b7ba25a7ece
[gaim-migrate @ 2230]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2205
diff
changeset
|
262 } |
8b7ba25a7ece
[gaim-migrate @ 2230]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2205
diff
changeset
|
263 |
2086 | 264 len = header[0]; |
10740 | 265 command = header[1]; |
5388 | 266 buf = (gchar *)g_malloc((len + 1) * sizeof(gchar)); |
267 buf[len] = '\0'; | |
2086 | 268 |
2220
8b7ba25a7ece
[gaim-migrate @ 2230]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2205
diff
changeset
|
269 i = 0; |
8b7ba25a7ece
[gaim-migrate @ 2230]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2205
diff
changeset
|
270 do { |
5388 | 271 int tmp = read(source, buf + i, len - i); |
2220
8b7ba25a7ece
[gaim-migrate @ 2230]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2205
diff
changeset
|
272 if (tmp <= 0) { |
8b7ba25a7ece
[gaim-migrate @ 2230]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2205
diff
changeset
|
273 g_free(buf); |
10816
c94f40ffcafb
[gaim-migrate @ 12471]
Luke Schierer <lschiere@pidgin.im>
parents:
10812
diff
changeset
|
274 buf = g_strdup_printf(_("Unable to read message from server: %s. Command is %hd, length is %hd."), strerror(errno), len, command); |
5604 | 275 gaim_connection_error(gc, buf); |
5388 | 276 g_free(buf); |
2220
8b7ba25a7ece
[gaim-migrate @ 2230]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2205
diff
changeset
|
277 return; |
8b7ba25a7ece
[gaim-migrate @ 2230]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2205
diff
changeset
|
278 } |
8b7ba25a7ece
[gaim-migrate @ 2230]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2205
diff
changeset
|
279 i += tmp; |
8b7ba25a7ece
[gaim-migrate @ 2230]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2205
diff
changeset
|
280 } while (i != len); |
2086 | 281 |
5388 | 282 gaim_debug(GAIM_DEBUG_MISC, "napster", "R %3hd: %s\n", command, buf); |
2086 | 283 |
5388 | 284 switch (command) { |
285 case 000: /* MSG_SERVER_ERROR */ | |
5436
ad445074d239
[gaim-migrate @ 5818]
Christian Hammond <chipx86@chipx86.com>
parents:
5402
diff
changeset
|
286 gaim_notify_error(gc, NULL, buf, NULL); |
5388 | 287 gaim_input_remove(gc->inpa); |
288 gc->inpa = 0; | |
2086 | 289 close(source); |
10740 | 290 gaim_connection_error(gc, _("Unknown server error.")); |
5388 | 291 break; |
2086 | 292 |
5388 | 293 case 003: /* MSG_SERVER_EMAIL */ |
294 gaim_debug(GAIM_DEBUG_MISC, "napster", "Registered with e-mail address: %s\n", buf); | |
2086 | 295 ndata->email = g_strdup(buf); |
296 | |
297 /* Our signon is complete */ | |
5604 | 298 gaim_connection_set_state(gc, GAIM_CONNECTED); |
2086 | 299 |
10869 | 300 /* Send the server our buddy list */ |
301 nap_send_buddylist(gc); | |
302 | |
5388 | 303 break; |
304 | |
305 case 201: /* MSG_SERVER_SEARCH_RESULT */ | |
306 res = g_strsplit(buf, " ", 0); | |
10010 | 307 gaim_prpl_got_user_status(account, res[0], "online", NULL); |
5388 | 308 g_strfreev(res); |
309 break; | |
310 | |
311 case 202: /* MSG_SERVER_SEARCH_END */ | |
10123 | 312 gaim_prpl_got_user_status(account, buf, "offline", NULL); |
5388 | 313 break; |
314 | |
315 case 205: /* MSG_CLIENT_PRIVMSG */ | |
316 res = g_strsplit(buf, " ", 2); | |
10732
c4cb90065e1d
[gaim-migrate @ 12334]
Luke Schierer <lschiere@pidgin.im>
parents:
10723
diff
changeset
|
317 buf2 = g_markup_escape_text(res[1], -1); |
8495 | 318 serv_got_im(gc, res[0], buf2, 0, time(NULL)); |
319 g_free(buf2); | |
5388 | 320 g_strfreev(res); |
321 break; | |
322 | |
323 case 209: /* MSG_SERVER_USER_SIGNON */ | |
324 /* USERNAME SPEED */ | |
325 res = g_strsplit(buf, " ", 2); | |
10010 | 326 gaim_prpl_got_user_status(account, res[0], "online", NULL); |
5388 | 327 g_strfreev(res); |
328 break; | |
329 | |
330 case 210: /* MSG_SERVER_USER_SIGNOFF */ | |
331 /* USERNAME SPEED */ | |
332 res = g_strsplit(buf, " ", 2); | |
10010 | 333 gaim_prpl_got_user_status(account, res[0], "offline", NULL); |
5388 | 334 g_strfreev(res); |
335 break; | |
336 | |
337 case 214: /* MSG_SERVER_STATS */ | |
338 res = g_strsplit(buf, " ", 3); | |
339 buf2 = g_strdup_printf(_("users: %s, files: %s, size: %sGB"), res[0], res[1], res[2]); | |
6982 | 340 serv_got_im(gc, "server", buf2, 0, time(NULL)); |
5388 | 341 g_free(buf2); |
342 g_strfreev(res); | |
343 break; | |
344 | |
345 case 301: /* MSG_SERVER_HOTLIST_ACK */ | |
346 /* Our buddy was added successfully */ | |
347 break; | |
348 | |
349 case 302: /* MSG_SERVER_HOTLIST_ERROR */ | |
350 buf2 = g_strdup_printf(_("Unable to add \"%s\" to your Napster hotlist"), buf); | |
5436
ad445074d239
[gaim-migrate @ 5818]
Christian Hammond <chipx86@chipx86.com>
parents:
5402
diff
changeset
|
351 gaim_notify_error(gc, NULL, buf2, NULL); |
5388 | 352 g_free(buf2); |
353 break; | |
354 | |
355 case 316: /* MSG_SERVER_DISCONNECTING */ | |
356 /* we have been kicked off =^( */ | |
10740 | 357 gaim_connection_error(gc, _("You were disconnected from the server.")); |
5388 | 358 break; |
359 | |
360 case 401: /* MSG_CLIENT_PART */ | |
5402 | 361 c = nap_find_chat(gc, buf); |
362 if (c) | |
7118
bf630f7dfdcd
[gaim-migrate @ 7685]
Christian Hammond <chipx86@chipx86.com>
parents:
7084
diff
changeset
|
363 serv_got_chat_left(gc, gaim_conv_chat_get_id(GAIM_CONV_CHAT(c))); |
5388 | 364 break; |
365 | |
366 case 403: /* MSG_SERVER_PUBLIC */ | |
367 res = g_strsplit(buf, " ", 3); | |
5402 | 368 c = nap_find_chat(gc, res[0]); |
369 if (c) | |
7118
bf630f7dfdcd
[gaim-migrate @ 7685]
Christian Hammond <chipx86@chipx86.com>
parents:
7084
diff
changeset
|
370 serv_got_chat_in(gc, gaim_conv_chat_get_id(GAIM_CONV_CHAT(c)), res[1], 0, res[2], time((time_t)NULL)); |
5388 | 371 g_strfreev(res); |
372 break; | |
373 | |
374 case 404: /* MSG_SERVER_NOSUCH */ | |
375 /* abused by opennap servers to broadcast stuff */ | |
10732
c4cb90065e1d
[gaim-migrate @ 12334]
Luke Schierer <lschiere@pidgin.im>
parents:
10723
diff
changeset
|
376 buf2 = g_markup_escape_text(buf, -1); |
8495 | 377 serv_got_im(gc, "server", buf2, 0, time(NULL)); |
378 g_free(buf2); | |
5388 | 379 break; |
380 | |
381 case 405: /* MSG_SERVER_JOIN_ACK */ | |
5402 | 382 c = nap_find_chat(gc, buf); |
383 if (!c) | |
7118
bf630f7dfdcd
[gaim-migrate @ 7685]
Christian Hammond <chipx86@chipx86.com>
parents:
7084
diff
changeset
|
384 serv_got_joined_chat(gc, gaim_conv_chat_get_id(GAIM_CONV_CHAT(c)), buf); |
5388 | 385 break; |
386 | |
387 case 407: /* MSG_SERVER_PART */ | |
388 res = g_strsplit(buf, " ", 0); | |
5402 | 389 c = nap_find_chat(gc, res[0]); |
7118
bf630f7dfdcd
[gaim-migrate @ 7685]
Christian Hammond <chipx86@chipx86.com>
parents:
7084
diff
changeset
|
390 gaim_conv_chat_remove_user(GAIM_CONV_CHAT(c), res[1], NULL); |
5388 | 391 g_strfreev(res); |
392 break; | |
393 | |
394 case 406: /* MSG_SERVER_JOIN */ | |
395 case 408: /* MSG_SERVER_CHANNEL_USER_LIST */ | |
396 res = g_strsplit(buf, " ", 4); | |
5402 | 397 c = nap_find_chat(gc, res[0]); |
9846 | 398 gaim_conv_chat_add_user(GAIM_CONV_CHAT(c), res[1], NULL, GAIM_CBFLAGS_NONE, TRUE); |
5388 | 399 g_strfreev(res); |
400 break; | |
401 | |
402 case 409: /* MSG_SERVER_CHANNEL_USER_LIST_END */ | |
403 break; | |
404 | |
405 case 410: /* MSG_SERVER_TOPIC */ | |
406 /* display the topic in the channel */ | |
407 res = g_strsplit(buf, " ", 2); | |
5402 | 408 c = nap_find_chat(gc, res[0]); |
7118
bf630f7dfdcd
[gaim-migrate @ 7685]
Christian Hammond <chipx86@chipx86.com>
parents:
7084
diff
changeset
|
409 gaim_conv_chat_set_topic(GAIM_CONV_CHAT(c), res[0], res[1]); |
5388 | 410 g_strfreev(res); |
411 break; | |
412 | |
413 case 603: /* MSG_CLIENT_WHOIS */ | |
414 buf2 = g_strdup_printf(_("%s requested your information"), buf); | |
6982 | 415 serv_got_im(gc, "server", buf2, 0, time(NULL)); |
5388 | 416 g_free(buf2); |
417 break; | |
418 | |
419 case 604: /* MSG_SERVER_WHOIS_RESPONSE */ | |
420 /* XXX - Format is: "Elite" 37 " " "Active" 0 0 0 0 "gaim 0.63cvs" 0 0 192.168.1.41 32798 0 unknown flounder */ | |
421 res = g_strsplit(buf, " ", 2); | |
7062
86ed8b2aa665
[gaim-migrate @ 7626]
Christian Hammond <chipx86@chipx86.com>
parents:
6982
diff
changeset
|
422 /* res[0] == username */ |
9797 | 423 gaim_notify_userinfo(gc, res[0], NULL, _("Buddy Information"), NULL, |
7062
86ed8b2aa665
[gaim-migrate @ 7626]
Christian Hammond <chipx86@chipx86.com>
parents:
6982
diff
changeset
|
424 res[1], NULL, NULL); |
5388 | 425 g_strfreev(res); |
426 break; | |
427 | |
428 case 621: | |
429 case 622: /* MSG_CLIENT_MOTD */ | |
430 /* also replaces MSG_SERVER_MOTD, so we should display it */ | |
10732
c4cb90065e1d
[gaim-migrate @ 12334]
Luke Schierer <lschiere@pidgin.im>
parents:
10723
diff
changeset
|
431 buf2 = g_markup_escape_text(buf, -1); |
8495 | 432 serv_got_im(gc, "motd", buf2, 0, time(NULL)); |
433 g_free(buf2); | |
5388 | 434 break; |
435 | |
436 case 627: /* MSG_CLIENT_WALLOP */ | |
437 /* abused by opennap server maintainers to broadcast stuff */ | |
10732
c4cb90065e1d
[gaim-migrate @ 12334]
Luke Schierer <lschiere@pidgin.im>
parents:
10723
diff
changeset
|
438 buf2 = g_markup_escape_text(buf, -1); |
8495 | 439 serv_got_im(gc, "wallop", buf2, 0, time(NULL)); |
440 g_free(buf2); | |
5388 | 441 break; |
442 | |
443 case 628: /* MSG_CLIENT_ANNOUNCE */ | |
10732
c4cb90065e1d
[gaim-migrate @ 12334]
Luke Schierer <lschiere@pidgin.im>
parents:
10723
diff
changeset
|
444 buf2 = g_markup_escape_text(buf, -1); |
8495 | 445 serv_got_im(gc, "announce", buf2, 0, time(NULL)); |
446 g_free(buf); | |
5388 | 447 break; |
448 | |
449 case 748: /* MSG_SERVER_GHOST */ | |
450 /* Looks like someone logged in as us! =-O */ | |
10740 | 451 gaim_connection_error(gc, _("You have signed on from another location.")); |
5388 | 452 break; |
453 | |
454 case 751: /* MSG_CLIENT_PING */ | |
455 buf2 = g_strdup_printf(_("%s requested a PING"), buf); | |
6982 | 456 serv_got_im(gc, "server", buf2, 0, time(NULL)); |
5388 | 457 g_free(buf2); |
458 /* send back a pong */ | |
459 /* MSG_CLIENT_PONG */ | |
460 nap_write_packet(gc, 752, "%s", buf); | |
461 break; | |
462 | |
463 case 752: /* MSG_CLIENT_PONG */ | |
464 buf2 = g_strdup_printf("Received pong from %s", buf); | |
5436
ad445074d239
[gaim-migrate @ 5818]
Christian Hammond <chipx86@chipx86.com>
parents:
5402
diff
changeset
|
465 gaim_notify_info(gc, NULL, buf2, NULL); |
5388 | 466 g_free(buf2); |
467 break; | |
468 | |
469 case 824: /* MSG_CLIENT_EMOTE */ | |
470 res = g_strsplit(buf, " ", 3); | |
471 buf2 = g_strndup(res[2]+1, strlen(res[2]) - 2); /* chomp off the surround quotes */ | |
472 buf3 = g_strdup_printf("/me %s", buf2); | |
473 g_free(buf2); | |
5402 | 474 if ((c = nap_find_chat(gc, res[0]))) { |
7118
bf630f7dfdcd
[gaim-migrate @ 7685]
Christian Hammond <chipx86@chipx86.com>
parents:
7084
diff
changeset
|
475 gaim_conv_chat_write(GAIM_CONV_CHAT(c), res[1], buf3, GAIM_MESSAGE_NICK, time(NULL)); |
5388 | 476 } |
477 g_free(buf3); | |
478 g_strfreev(res); | |
479 break; | |
480 | |
481 default: | |
482 gaim_debug(GAIM_DEBUG_MISC, "napster", "Unknown packet %hd: %s\n", command, buf); | |
483 break; | |
2086 | 484 } |
5388 | 485 |
486 g_free(buf); | |
2086 | 487 } |
488 | |
5388 | 489 /* 002 - MSG_CLIENT_LOGIN */ |
2090
b66aca8e8dce
[gaim-migrate @ 2100]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
490 static void nap_login_connect(gpointer data, gint source, GaimInputCondition cond) |
2086 | 491 { |
5604 | 492 GaimConnection *gc = data; |
5388 | 493 struct nap_data *ndata = (struct nap_data *)gc->proto_data; |
494 gchar *buf; | |
2086 | 495 |
5605 | 496 if (!g_list_find(gaim_connections_get_all(), gc)) { |
2701
8a84f2bb1716
[gaim-migrate @ 2714]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
497 close(source); |
8a84f2bb1716
[gaim-migrate @ 2714]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
498 return; |
8a84f2bb1716
[gaim-migrate @ 2714]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
499 } |
8a84f2bb1716
[gaim-migrate @ 2714]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
500 |
2086 | 501 if (source < 0) { |
7981 | 502 gaim_connection_error(gc, _("Unable to connect.")); |
2086 | 503 return; |
504 } | |
505 | |
4452 | 506 ndata->fd = source; |
2086 | 507 |
5388 | 508 /* Update the login progress status display */ |
5604 | 509 buf = g_strdup_printf("Logging in: %s", gaim_account_get_username(gc->account)); |
7884 | 510 gaim_connection_update_progress(gc, buf, 1, NAPSTER_CONNECT_STEPS); |
5388 | 511 g_free(buf); |
512 | |
513 /* Write our signon data */ | |
5604 | 514 nap_write_packet(gc, 2, "%s %s 0 \"gaim %s\" 0", |
515 gaim_account_get_username(gc->account), | |
10740 | 516 gaim_connection_get_password(gc), VERSION); |
5388 | 517 |
2086 | 518 /* And set up the input watcher */ |
5388 | 519 gc->inpa = gaim_input_add(ndata->fd, GAIM_INPUT_READ, nap_callback, gc); |
2086 | 520 } |
521 | |
10401 | 522 static void nap_login(GaimAccount *account, GaimStatus *status) |
2086 | 523 { |
5604 | 524 GaimConnection *gc = gaim_account_get_connection(account); |
5388 | 525 |
7884 | 526 gaim_connection_update_progress(gc, _("Connecting"), 0, NAPSTER_CONNECT_STEPS); |
5388 | 527 |
4460 | 528 gc->proto_data = g_new0(struct nap_data, 1); |
5681
46d7ad0dfa26
[gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents:
5679
diff
changeset
|
529 if (gaim_proxy_connect(account, |
5604 | 530 gaim_account_get_string(account, "server", NAP_SERVER), |
531 gaim_account_get_int(account, "port", NAP_PORT), | |
4491 | 532 nap_login_connect, gc) != 0) { |
7981 | 533 gaim_connection_error(gc, _("Unable to connect.")); |
2086 | 534 } |
535 } | |
536 | |
5604 | 537 static void nap_close(GaimConnection *gc) |
2086 | 538 { |
539 struct nap_data *ndata = (struct nap_data *)gc->proto_data; | |
5388 | 540 |
2086 | 541 if (gc->inpa) |
2090
b66aca8e8dce
[gaim-migrate @ 2100]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
542 gaim_input_remove(gc->inpa); |
2086 | 543 |
5388 | 544 if (!ndata) |
545 return; | |
546 | |
10882
83e119608cb5
[gaim-migrate @ 12580]
Gary Kramlich <grim@reaperworld.com>
parents:
10869
diff
changeset
|
547 close(ndata->fd); |
83e119608cb5
[gaim-migrate @ 12580]
Gary Kramlich <grim@reaperworld.com>
parents:
10869
diff
changeset
|
548 |
5388 | 549 g_free(ndata->email); |
550 g_free(ndata); | |
2086 | 551 } |
552 | |
6695 | 553 static const char* nap_list_icon(GaimAccount *a, GaimBuddy *b) |
2086 | 554 { |
4687 | 555 return "napster"; |
2086 | 556 } |
557 | |
9953 | 558 static void nap_list_emblems(GaimBuddy *b, const char **se, const char **sw, |
559 const char **nw, const char **ne) | |
4916 | 560 { |
10723
a9c77f7b8ced
[gaim-migrate @ 12323]
Luke Schierer <lschiere@pidgin.im>
parents:
10649
diff
changeset
|
561 if(!GAIM_BUDDY_IS_ONLINE(b)) |
4916 | 562 *se = "offline"; |
563 } | |
564 | |
10200 | 565 static GList *nap_status_types(GaimAccount *account) |
566 { | |
567 GList *types = NULL; | |
568 GaimStatusType *type; | |
569 | |
570 g_return_val_if_fail(account != NULL, NULL); | |
571 | |
572 type = gaim_status_type_new_full(GAIM_STATUS_OFFLINE, | |
573 "offline", | |
10723
a9c77f7b8ced
[gaim-migrate @ 12323]
Luke Schierer <lschiere@pidgin.im>
parents:
10649
diff
changeset
|
574 _("Offline"), TRUE, TRUE, FALSE); |
10200 | 575 types = g_list_append(types, type); |
576 | |
577 type = gaim_status_type_new_full(GAIM_STATUS_ONLINE, | |
578 "online", | |
10723
a9c77f7b8ced
[gaim-migrate @ 12323]
Luke Schierer <lschiere@pidgin.im>
parents:
10649
diff
changeset
|
579 _("Online"), TRUE, TRUE, FALSE); |
10200 | 580 types = g_list_append(types, type); |
581 | |
582 return types; | |
583 } | |
584 | |
5604 | 585 static GList *nap_chat_info(GaimConnection *gc) |
2086 | 586 { |
5388 | 587 GList *m = NULL; |
588 struct proto_chat_entry *pce; | |
589 | |
590 pce = g_new0(struct proto_chat_entry, 1); | |
7844 | 591 pce->label = _("_Group:"); |
5388 | 592 pce->identifier = "group"; |
593 m = g_list_append(m, pce); | |
594 | |
595 return m; | |
2086 | 596 } |
5388 | 597 |
9754 | 598 GHashTable *nap_chat_info_defaults(GaimConnection *gc, const char *chat_name) |
599 { | |
600 GHashTable *defaults; | |
601 | |
602 defaults = g_hash_table_new_full(g_str_hash, g_str_equal, NULL, g_free); | |
603 | |
604 if (chat_name != NULL) | |
605 g_hash_table_insert(defaults, "group", g_strdup(chat_name)); | |
606 | |
607 return defaults; | |
608 } | |
609 | |
5388 | 610 static GaimPlugin *my_protocol = NULL; |
5205
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5136
diff
changeset
|
611 |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5136
diff
changeset
|
612 static GaimPluginProtocolInfo prpl_info = |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5136
diff
changeset
|
613 { |
5388 | 614 OPT_PROTO_CHAT_TOPIC, |
9475 | 615 NULL, /* user_splits */ |
616 NULL, /* protocol_options */ | |
617 NO_BUDDY_ICONS, /* icon_spec */ | |
618 nap_list_icon, /* list_icon */ | |
619 nap_list_emblems, /* list_emblems */ | |
620 NULL, /* status_text */ | |
621 NULL, /* tooltip_text */ | |
10200 | 622 nap_status_types, /* status_types */ |
9475 | 623 NULL, /* blist_node_menu */ |
624 nap_chat_info, /* chat_info */ | |
9754 | 625 nap_chat_info_defaults, /* chat_info_defaults */ |
9475 | 626 nap_login, /* login */ |
627 nap_close, /* close */ | |
628 nap_send_im, /* send_im */ | |
629 NULL, /* set_info */ | |
630 NULL, /* send_typing */ | |
631 nap_get_info, /* get_info */ | |
632 NULL, /* set_away */ | |
633 NULL, /* set_idle */ | |
634 NULL, /* change_passwd */ | |
635 nap_add_buddy, /* add_buddy */ | |
10869 | 636 NULL, /* add_buddies */ |
9475 | 637 nap_remove_buddy, /* remove_buddy */ |
638 NULL, /* remove_buddies */ | |
639 NULL, /* add_permit */ | |
640 NULL, /* add_deny */ | |
641 NULL, /* rem_permit */ | |
642 NULL, /* rem_deny */ | |
643 NULL, /* set_permit_deny */ | |
644 NULL, /* warn */ | |
645 nap_join_chat, /* join_chat */ | |
646 NULL, /* reject chat invite */ | |
9917 | 647 nap_get_chat_name, /* get_chat_name */ |
9475 | 648 NULL, /* chat_invite */ |
649 nap_chat_leave, /* chat_leave */ | |
650 NULL, /* chat_whisper */ | |
651 nap_chat_send, /* chat_send */ | |
652 NULL, /* keepalive */ | |
653 NULL, /* register_user */ | |
654 NULL, /* get_cb_info */ | |
655 NULL, /* get_cb_away */ | |
656 NULL, /* alias_buddy */ | |
657 NULL, /* group_buddy */ | |
658 NULL, /* rename_group */ | |
659 NULL, /* buddy_free */ | |
660 NULL, /* convo_closed */ | |
661 NULL, /* normalize */ | |
662 NULL, /* set_buddy_icon */ | |
663 NULL, /* remove_group */ | |
664 NULL, /* get_cb_real_name */ | |
665 NULL, /* set_chat_topic */ | |
666 NULL, /* find_blist_chat */ | |
667 NULL, /* roomlist_get_list */ | |
668 NULL, /* roomlist_cancel */ | |
669 NULL, /* roomlist_expand_category */ | |
670 NULL, /* can_receive_file */ | |
671 NULL /* send_file */ | |
5205
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5136
diff
changeset
|
672 }; |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5136
diff
changeset
|
673 |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5136
diff
changeset
|
674 static GaimPluginInfo info = |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5136
diff
changeset
|
675 { |
9943 | 676 GAIM_PLUGIN_MAGIC, |
10649 | 677 0, |
9943 | 678 GAIM_MINOR_VERSION, |
5205
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5136
diff
changeset
|
679 GAIM_PLUGIN_PROTOCOL, /**< type */ |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5136
diff
changeset
|
680 NULL, /**< ui_requirement */ |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5136
diff
changeset
|
681 0, /**< flags */ |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5136
diff
changeset
|
682 NULL, /**< dependencies */ |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5136
diff
changeset
|
683 GAIM_PRIORITY_DEFAULT, /**< priority */ |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5136
diff
changeset
|
684 |
5388 | 685 "prpl-napster", /**< id */ |
686 "Napster", /**< name */ | |
5205
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5136
diff
changeset
|
687 VERSION, /**< version */ |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5136
diff
changeset
|
688 /** summary */ |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5136
diff
changeset
|
689 N_("NAPSTER Protocol Plugin"), |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5136
diff
changeset
|
690 /** description */ |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5136
diff
changeset
|
691 N_("NAPSTER Protocol Plugin"), |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5136
diff
changeset
|
692 NULL, /**< author */ |
6371
8f94cce8faa5
[gaim-migrate @ 6876]
Christian Hammond <chipx86@chipx86.com>
parents:
6321
diff
changeset
|
693 GAIM_WEBSITE, /**< homepage */ |
5205
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5136
diff
changeset
|
694 |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5136
diff
changeset
|
695 NULL, /**< load */ |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5136
diff
changeset
|
696 NULL, /**< unload */ |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5136
diff
changeset
|
697 NULL, /**< destroy */ |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5136
diff
changeset
|
698 |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5136
diff
changeset
|
699 NULL, /**< ui_info */ |
8993 | 700 &prpl_info, /**< extra_info */ |
701 NULL, | |
702 NULL | |
5205
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5136
diff
changeset
|
703 }; |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5136
diff
changeset
|
704 |
5920
7d385de2f9cd
[gaim-migrate @ 6360]
Christian Hammond <chipx86@chipx86.com>
parents:
5872
diff
changeset
|
705 static void init_plugin(GaimPlugin *plugin) |
5205
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5136
diff
changeset
|
706 { |
5638
0bdfa28c678e
[gaim-migrate @ 6047]
Christian Hammond <chipx86@chipx86.com>
parents:
5605
diff
changeset
|
707 GaimAccountOption *option; |
5205
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5136
diff
changeset
|
708 |
11033
50224ac8184d
[gaim-migrate @ 12919]
Etan Reisner <pidgin@unreliablesource.net>
parents:
10882
diff
changeset
|
709 gaim_debug_register_category("napster"); |
50224ac8184d
[gaim-migrate @ 12919]
Etan Reisner <pidgin@unreliablesource.net>
parents:
10882
diff
changeset
|
710 |
5638
0bdfa28c678e
[gaim-migrate @ 6047]
Christian Hammond <chipx86@chipx86.com>
parents:
5605
diff
changeset
|
711 option = gaim_account_option_string_new(_("Server"), "server", |
0bdfa28c678e
[gaim-migrate @ 6047]
Christian Hammond <chipx86@chipx86.com>
parents:
5605
diff
changeset
|
712 NAP_SERVER); |
0bdfa28c678e
[gaim-migrate @ 6047]
Christian Hammond <chipx86@chipx86.com>
parents:
5605
diff
changeset
|
713 prpl_info.protocol_options = g_list_append(prpl_info.protocol_options, |
0bdfa28c678e
[gaim-migrate @ 6047]
Christian Hammond <chipx86@chipx86.com>
parents:
5605
diff
changeset
|
714 option); |
5205
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5136
diff
changeset
|
715 |
5638
0bdfa28c678e
[gaim-migrate @ 6047]
Christian Hammond <chipx86@chipx86.com>
parents:
5605
diff
changeset
|
716 option = gaim_account_option_int_new(_("Port"), "port", 8888); |
0bdfa28c678e
[gaim-migrate @ 6047]
Christian Hammond <chipx86@chipx86.com>
parents:
5605
diff
changeset
|
717 prpl_info.protocol_options = g_list_append(prpl_info.protocol_options, |
0bdfa28c678e
[gaim-migrate @ 6047]
Christian Hammond <chipx86@chipx86.com>
parents:
5605
diff
changeset
|
718 option); |
5205
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5136
diff
changeset
|
719 |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5136
diff
changeset
|
720 my_protocol = plugin; |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5136
diff
changeset
|
721 } |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5136
diff
changeset
|
722 |
5920
7d385de2f9cd
[gaim-migrate @ 6360]
Christian Hammond <chipx86@chipx86.com>
parents:
5872
diff
changeset
|
723 GAIM_INIT_PLUGIN(napster, init_plugin, info); |