Mercurial > pidgin
annotate src/protocols/napster/napster.c @ 6825:936133f7c755
[gaim-migrate @ 7369]
Shush, CVS.
committer: Tailor Script <tailor@pidgin.im>
author | Christian Hammond <chipx86@chipx86.com> |
---|---|
date | Sat, 13 Sep 2003 21:01:26 +0000 |
parents | faa491042c66 |
children | bdd046deec7e |
rev | line source |
---|---|
2086 | 1 /* |
2 * gaim - Napster Protocol Plugin | |
3 * | |
3322 | 4 * Copyright (C) 2000-2001, Rob Flynn <rob@marko.net> |
2086 | 5 * |
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 * | |
20 */ | |
5872
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5681
diff
changeset
|
21 #include "internal.h" |
2086 | 22 |
5872
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5681
diff
changeset
|
23 #include "account.h" |
5638
0bdfa28c678e
[gaim-migrate @ 6047]
Christian Hammond <chipx86@chipx86.com>
parents:
5605
diff
changeset
|
24 #include "accountopt.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" |
2086 | 27 #include "multi.h" |
5872
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5681
diff
changeset
|
28 #include "notify.h" |
2086 | 29 #include "prpl.h" |
30 #include "proxy.h" | |
5872
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5681
diff
changeset
|
31 #include "util.h" |
3630 | 32 |
5872
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5681
diff
changeset
|
33 /* XXX */ |
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5681
diff
changeset
|
34 #include "gaim.h" |
3630 | 35 |
3322 | 36 #define NAP_SERVER "64.124.41.187" |
37 #define NAP_PORT 8888 | |
38 | |
5604 | 39 #define NAPSTER_CONNECT_STEPS 2 |
40 | |
2086 | 41 GSList *nap_connections = NULL; |
42 | |
43 struct nap_data { | |
44 int fd; | |
45 gchar *email; | |
46 }; | |
47 | |
5679 | 48 static GaimConversation *nap_find_chat(GaimConnection *gc, const char *name) |
2086 | 49 { |
5402 | 50 GSList *bcs = gc->buddy_chats; |
2086 | 51 |
5402 | 52 while (bcs) { |
5679 | 53 GaimConversation *b = bcs->data; |
5402 | 54 if (!gaim_utf8_strcasecmp(b->name, name)) |
5388 | 55 return b; |
5402 | 56 bcs = bcs->next; |
5388 | 57 } |
58 | |
59 return NULL; | |
60 } | |
61 | |
5604 | 62 static void nap_write_packet(GaimConnection *gc, unsigned short command, const char *format, ...) |
5388 | 63 { |
64 struct nap_data *ndata = (struct nap_data *)gc->proto_data; | |
65 va_list ap; | |
66 gchar *message; | |
67 unsigned short size; | |
68 | |
69 va_start(ap, format); | |
70 message = g_strdup_vprintf(format, ap); | |
71 va_end(ap); | |
72 | |
73 size = strlen(message); | |
74 gaim_debug(GAIM_DEBUG_MISC, "napster", "S %3hd: %s\n", command, message); | |
75 | |
76 write(ndata->fd, &size, 2); | |
77 write(ndata->fd, &command, 2); | |
78 write(ndata->fd, message, size); | |
79 | |
80 g_free(message); | |
81 } | |
82 | |
5604 | 83 static int nap_do_irc_style(GaimConnection *gc, const char *message, const char *name) |
5388 | 84 { |
85 gchar **res; | |
86 | |
87 gaim_debug(GAIM_DEBUG_MISC, "napster", "C %s\n", message); | |
88 | |
89 res = g_strsplit(message, " ", 2); | |
90 | |
91 if (!strcasecmp(res[0], "/ME")) { /* MSG_CLIENT_PUBLIC */ | |
5402 | 92 nap_write_packet(gc, 824, "%s \"%s\"", name, res[1]); |
5388 | 93 |
94 } else if (!strcasecmp(res[0], "/MSG")) { /* MSG_CLIENT_PUBLIC */ | |
95 nap_write_packet(gc, 205, "%s", res[1]); | |
4359
5fb47ec9bfe4
[gaim-migrate @ 4625]
Christian Hammond <chipx86@chipx86.com>
parents:
4349
diff
changeset
|
96 |
5388 | 97 } else if (!strcasecmp(res[0], "/JOIN")) { /* join chatroom MSG_CLIENT_JOIN */ |
98 if (!res[1]) { | |
99 g_strfreev(res); | |
100 return 1; | |
101 } | |
102 if (res[1][0] != '#') | |
103 nap_write_packet(gc, 400, "#%s", res[1]); | |
104 else | |
105 nap_write_packet(gc, 400, "%s", res[1]); | |
106 | |
107 } else if (!strcasecmp(res[0], "/PART")) { /* partchatroom MSG_CLIENT_PART */ | |
5402 | 108 nap_write_packet(gc, 401, "%s", res[1] ? res[1] : name); |
5388 | 109 |
110 } else if (!strcasecmp(res[0], "/TOPIC")) { /* set topic MSG_SERVER_TOPIC */ | |
5402 | 111 nap_write_packet(gc, 410, "%s", res[1] ? res[1] : name); |
5388 | 112 |
113 } else if (!strcasecmp(res[0], "/WHOIS")) { /* whois request MSG_CLIENT_WHOIS */ | |
114 nap_write_packet(gc, 603, "%s", res[1]); | |
115 | |
116 } else if (!strcasecmp(res[0], "/PING")) { /* send ping MSG_CLIENT_PING */ | |
117 nap_write_packet(gc, 751, "%s", res[1]); | |
118 | |
119 } else if (!strcasecmp(res[0], "/KICK")) { /* kick asswipe MSG_CLIENT_KICK */ | |
120 nap_write_packet(gc, 829, "%s", res[1]); | |
121 | |
122 } else { | |
123 g_strfreev(res); | |
124 return 1; | |
125 } | |
126 | |
127 g_strfreev(res); | |
128 return 0; | |
129 } | |
130 | |
131 /* 205 - MSG_CLIENT_PRIVMSG */ | |
6622 | 132 static int nap_send_im(GaimConnection *gc, const char *who, const char *message, int len, GaimImFlags flags) |
5388 | 133 { |
134 | |
135 if ((strlen(message) < 2) || (message[0] != '/' ) || (message[1] == '/')) { | |
136 /* Actually send a chat message */ | |
137 nap_write_packet(gc, 205, "%s %s", who, message); | |
138 } else { | |
139 /* user typed an IRC-style command */ | |
140 nap_do_irc_style(gc, message, who); | |
2086 | 141 } |
142 | |
5388 | 143 return 1; |
144 } | |
145 | |
146 /* 207 - MSG_CLIENT_ADD_HOTLIST */ | |
6787
faa491042c66
[gaim-migrate @ 7326]
Christian Hammond <chipx86@chipx86.com>
parents:
6695
diff
changeset
|
147 static void nap_add_buddy(GaimConnection *gc, const char *name, GaimGroup *group) |
5388 | 148 { |
149 nap_write_packet(gc, 207, "%s", name); | |
150 } | |
151 | |
152 /* 208 - MSG_CLIENT_ADD_HOTLIST_SEQ */ | |
5604 | 153 static void nap_add_buddies(GaimConnection *gc, GList *buddies) |
5388 | 154 { |
155 while (buddies) { | |
156 nap_write_packet(gc, 208, "%s", (char *)buddies->data); | |
157 buddies = buddies -> next; | |
158 } | |
159 } | |
160 | |
161 /* 303 - MSG_CLIENT_REMOVE_HOTLIST */ | |
6059 | 162 static void nap_remove_buddy(GaimConnection *gc, const char *name, const char *group) |
5388 | 163 { |
164 nap_write_packet(gc, 303, "%s", name); | |
165 } | |
166 | |
167 /* 400 - MSG_CLIENT_JOIN */ | |
5604 | 168 static void nap_join_chat(GaimConnection *gc, GHashTable *data) |
5388 | 169 { |
170 char *name; | |
171 | |
172 if (!data) | |
173 return; | |
174 | |
175 name = g_hash_table_lookup(data, "group"); | |
176 | |
177 /* Make sure the name has a # preceeding it */ | |
178 if (name[0] != '#') | |
179 nap_write_packet(gc, 400, "#%s", name); | |
180 else | |
181 nap_write_packet(gc, 400, "%s", name); | |
182 } | |
183 | |
184 /* 401 - MSG_CLIENT_PART */ | |
5604 | 185 static void nap_chat_leave(GaimConnection *gc, int id) |
5388 | 186 { |
5679 | 187 GaimConversation *c = gaim_find_chat(gc, id); |
5388 | 188 |
5402 | 189 if (!c) |
5388 | 190 return; |
191 | |
5402 | 192 nap_write_packet(gc, 401, "%s", c->name); |
5388 | 193 } |
194 | |
195 /* 402 - MSG_CLIENT_PUBLIC */ | |
6059 | 196 static int nap_chat_send(GaimConnection *gc, int id, const char *message) |
5388 | 197 { |
5679 | 198 GaimConversation *c = gaim_find_chat(gc, id); |
5388 | 199 |
5402 | 200 if (!c) |
5388 | 201 return -EINVAL; |
202 | |
203 if ((strlen(message) < 2) || (message[0] != '/' ) || (message[1] == '/')) { | |
204 /* Actually send a chat message */ | |
5402 | 205 nap_write_packet(gc, 402, "%s %s", c->name, message); |
5388 | 206 } else { |
207 /* user typed an IRC-style command */ | |
5402 | 208 nap_do_irc_style(gc, message, c->name); |
5388 | 209 } |
210 | |
211 return 0; | |
212 } | |
213 | |
214 /* 603 - MSG_CLIENT_WHOIS */ | |
5604 | 215 static void nap_get_info(GaimConnection *gc, const char *who) |
5388 | 216 { |
217 nap_write_packet(gc, 603, "%s", who); | |
2086 | 218 } |
219 | |
2090
b66aca8e8dce
[gaim-migrate @ 2100]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
220 static void nap_callback(gpointer data, gint source, GaimInputCondition condition) |
2086 | 221 { |
5604 | 222 GaimConnection *gc = data; |
2086 | 223 struct nap_data *ndata = gc->proto_data; |
5679 | 224 GaimConversation *c; |
5402 | 225 gchar *buf, *buf2, *buf3, **res; |
2086 | 226 unsigned short header[2]; |
227 int len; | |
228 int command; | |
2220
8b7ba25a7ece
[gaim-migrate @ 2230]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2205
diff
changeset
|
229 int i; |
2086 | 230 |
5388 | 231 if (read(source, (void*)header, 4) != 4) { |
5604 | 232 gaim_connection_error(gc, _("Unable to read header from server")); |
2220
8b7ba25a7ece
[gaim-migrate @ 2230]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2205
diff
changeset
|
233 return; |
8b7ba25a7ece
[gaim-migrate @ 2230]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2205
diff
changeset
|
234 } |
8b7ba25a7ece
[gaim-migrate @ 2230]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2205
diff
changeset
|
235 |
2086 | 236 len = header[0]; |
237 command = header[1]; | |
5388 | 238 buf = (gchar *)g_malloc((len + 1) * sizeof(gchar)); |
239 buf[len] = '\0'; | |
2086 | 240 |
2220
8b7ba25a7ece
[gaim-migrate @ 2230]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2205
diff
changeset
|
241 i = 0; |
8b7ba25a7ece
[gaim-migrate @ 2230]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2205
diff
changeset
|
242 do { |
5388 | 243 int tmp = read(source, buf + i, len - i); |
2220
8b7ba25a7ece
[gaim-migrate @ 2230]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2205
diff
changeset
|
244 if (tmp <= 0) { |
8b7ba25a7ece
[gaim-migrate @ 2230]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2205
diff
changeset
|
245 g_free(buf); |
6321 | 246 buf = g_strdup_printf(_("Unable to read mesage from server. Command is %hd, length is %hd."), len, command); |
5604 | 247 gaim_connection_error(gc, buf); |
5388 | 248 g_free(buf); |
2220
8b7ba25a7ece
[gaim-migrate @ 2230]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2205
diff
changeset
|
249 return; |
8b7ba25a7ece
[gaim-migrate @ 2230]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2205
diff
changeset
|
250 } |
8b7ba25a7ece
[gaim-migrate @ 2230]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2205
diff
changeset
|
251 i += tmp; |
8b7ba25a7ece
[gaim-migrate @ 2230]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2205
diff
changeset
|
252 } while (i != len); |
2086 | 253 |
5388 | 254 gaim_debug(GAIM_DEBUG_MISC, "napster", "R %3hd: %s\n", command, buf); |
2086 | 255 |
5388 | 256 switch (command) { |
257 case 000: /* MSG_SERVER_ERROR */ | |
5436
ad445074d239
[gaim-migrate @ 5818]
Christian Hammond <chipx86@chipx86.com>
parents:
5402
diff
changeset
|
258 gaim_notify_error(gc, NULL, buf, NULL); |
5388 | 259 gaim_input_remove(gc->inpa); |
260 gc->inpa = 0; | |
2086 | 261 close(source); |
5604 | 262 gaim_connection_destroy(gc); |
5388 | 263 break; |
2086 | 264 |
5388 | 265 case 003: /* MSG_SERVER_EMAIL */ |
266 gaim_debug(GAIM_DEBUG_MISC, "napster", "Registered with e-mail address: %s\n", buf); | |
2086 | 267 ndata->email = g_strdup(buf); |
268 | |
269 /* Our signon is complete */ | |
5604 | 270 gaim_connection_set_state(gc, GAIM_CONNECTED); |
2086 | 271 serv_finish_login(gc); |
272 | |
5388 | 273 break; |
274 | |
275 case 201: /* MSG_SERVER_SEARCH_RESULT */ | |
276 res = g_strsplit(buf, " ", 0); | |
277 serv_got_update(gc, res[0], 1, 0, 0, 0, 0); | |
278 g_strfreev(res); | |
279 break; | |
280 | |
281 case 202: /* MSG_SERVER_SEARCH_END */ | |
282 serv_got_update(gc, buf, 0, 0, 0, 0, 0); | |
283 break; | |
284 | |
285 case 205: /* MSG_CLIENT_PRIVMSG */ | |
286 res = g_strsplit(buf, " ", 2); | |
287 serv_got_im(gc, res[0], res[1], 0, time(NULL), -1); | |
288 g_strfreev(res); | |
289 break; | |
290 | |
291 case 209: /* MSG_SERVER_USER_SIGNON */ | |
292 /* USERNAME SPEED */ | |
293 res = g_strsplit(buf, " ", 2); | |
294 serv_got_update(gc, res[0], 1, 0, 0, 0, 0); | |
295 g_strfreev(res); | |
296 break; | |
297 | |
298 case 210: /* MSG_SERVER_USER_SIGNOFF */ | |
299 /* USERNAME SPEED */ | |
300 res = g_strsplit(buf, " ", 2); | |
301 serv_got_update(gc, res[0], 0, 0, 0, 0, 0); | |
302 g_strfreev(res); | |
303 break; | |
304 | |
305 case 214: /* MSG_SERVER_STATS */ | |
306 res = g_strsplit(buf, " ", 3); | |
307 buf2 = g_strdup_printf(_("users: %s, files: %s, size: %sGB"), res[0], res[1], res[2]); | |
308 serv_got_im(gc, "server", buf2, 0, time(NULL), -1); | |
309 g_free(buf2); | |
310 g_strfreev(res); | |
311 break; | |
312 | |
313 case 301: /* MSG_SERVER_HOTLIST_ACK */ | |
314 /* Our buddy was added successfully */ | |
315 break; | |
316 | |
317 case 302: /* MSG_SERVER_HOTLIST_ERROR */ | |
318 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
|
319 gaim_notify_error(gc, NULL, buf2, NULL); |
5388 | 320 g_free(buf2); |
321 break; | |
322 | |
323 case 316: /* MSG_SERVER_DISCONNECTING */ | |
324 /* we have been kicked off =^( */ | |
5436
ad445074d239
[gaim-migrate @ 5818]
Christian Hammond <chipx86@chipx86.com>
parents:
5402
diff
changeset
|
325 gaim_notify_error(gc, NULL, |
ad445074d239
[gaim-migrate @ 5818]
Christian Hammond <chipx86@chipx86.com>
parents:
5402
diff
changeset
|
326 _("You were disconnected from the server."), NULL); |
5604 | 327 gaim_connection_destroy(gc); |
5388 | 328 break; |
329 | |
330 case 401: /* MSG_CLIENT_PART */ | |
5402 | 331 c = nap_find_chat(gc, buf); |
332 if (c) | |
333 serv_got_chat_left(gc, gaim_chat_get_id(GAIM_CHAT(c))); | |
5388 | 334 break; |
335 | |
336 case 403: /* MSG_SERVER_PUBLIC */ | |
337 res = g_strsplit(buf, " ", 3); | |
5402 | 338 c = nap_find_chat(gc, res[0]); |
339 if (c) | |
340 serv_got_chat_in(gc, gaim_chat_get_id(GAIM_CHAT(c)), res[1], 0, res[2], time((time_t)NULL)); | |
5388 | 341 g_strfreev(res); |
342 break; | |
343 | |
344 case 404: /* MSG_SERVER_NOSUCH */ | |
345 /* abused by opennap servers to broadcast stuff */ | |
346 serv_got_im(gc, "server", buf, 0, time(NULL), -1); | |
347 break; | |
348 | |
349 case 405: /* MSG_SERVER_JOIN_ACK */ | |
5402 | 350 c = nap_find_chat(gc, buf); |
351 if (!c) | |
352 serv_got_joined_chat(gc, gaim_chat_get_id(GAIM_CHAT(c)), buf); | |
5388 | 353 break; |
354 | |
355 case 407: /* MSG_SERVER_PART */ | |
356 res = g_strsplit(buf, " ", 0); | |
5402 | 357 c = nap_find_chat(gc, res[0]); |
358 gaim_chat_remove_user(GAIM_CHAT(c), res[1], NULL); | |
5388 | 359 g_strfreev(res); |
360 break; | |
361 | |
362 case 406: /* MSG_SERVER_JOIN */ | |
363 case 408: /* MSG_SERVER_CHANNEL_USER_LIST */ | |
364 res = g_strsplit(buf, " ", 4); | |
5402 | 365 c = nap_find_chat(gc, res[0]); |
366 gaim_chat_add_user(GAIM_CHAT(c), res[1], NULL); | |
5388 | 367 g_strfreev(res); |
368 break; | |
369 | |
370 case 409: /* MSG_SERVER_CHANNEL_USER_LIST_END */ | |
371 break; | |
372 | |
373 case 410: /* MSG_SERVER_TOPIC */ | |
374 /* display the topic in the channel */ | |
375 res = g_strsplit(buf, " ", 2); | |
5402 | 376 c = nap_find_chat(gc, res[0]); |
377 gaim_chat_set_topic(GAIM_CHAT(c), res[0], res[1]); | |
5388 | 378 g_strfreev(res); |
379 break; | |
380 | |
381 case 603: /* MSG_CLIENT_WHOIS */ | |
382 buf2 = g_strdup_printf(_("%s requested your information"), buf); | |
383 serv_got_im(gc, "server", buf2, 0, time(NULL), -1); | |
384 g_free(buf2); | |
385 break; | |
386 | |
387 case 604: /* MSG_SERVER_WHOIS_RESPONSE */ | |
388 /* XXX - Format is: "Elite" 37 " " "Active" 0 0 0 0 "gaim 0.63cvs" 0 0 192.168.1.41 32798 0 unknown flounder */ | |
389 res = g_strsplit(buf, " ", 2); | |
390 g_show_info_text(gc, res[0], 2, res[1], NULL); | |
391 g_strfreev(res); | |
392 break; | |
393 | |
394 case 621: | |
395 case 622: /* MSG_CLIENT_MOTD */ | |
396 /* also replaces MSG_SERVER_MOTD, so we should display it */ | |
397 serv_got_im(gc, "motd", buf, 0, time(NULL), -1); | |
398 break; | |
399 | |
400 case 627: /* MSG_CLIENT_WALLOP */ | |
401 /* abused by opennap server maintainers to broadcast stuff */ | |
402 serv_got_im(gc, "wallop", buf, 0, time(NULL), -1); | |
403 break; | |
404 | |
405 case 628: /* MSG_CLIENT_ANNOUNCE */ | |
406 serv_got_im(gc, "announce", buf, 0, time(NULL), -1); | |
407 break; | |
408 | |
409 case 748: /* MSG_SERVER_GHOST */ | |
410 /* Looks like someone logged in as us! =-O */ | |
5436
ad445074d239
[gaim-migrate @ 5818]
Christian Hammond <chipx86@chipx86.com>
parents:
5402
diff
changeset
|
411 gaim_notify_error(gc, NULL, |
ad445074d239
[gaim-migrate @ 5818]
Christian Hammond <chipx86@chipx86.com>
parents:
5402
diff
changeset
|
412 _("You were disconnected from the server, because " |
ad445074d239
[gaim-migrate @ 5818]
Christian Hammond <chipx86@chipx86.com>
parents:
5402
diff
changeset
|
413 "you logged on from a different location"), NULL); |
5604 | 414 gaim_connection_destroy(gc); |
5388 | 415 break; |
416 | |
417 case 751: /* MSG_CLIENT_PING */ | |
418 buf2 = g_strdup_printf(_("%s requested a PING"), buf); | |
419 serv_got_im(gc, "server", buf2, 0, time(NULL), -1); | |
420 g_free(buf2); | |
421 /* send back a pong */ | |
422 /* MSG_CLIENT_PONG */ | |
423 nap_write_packet(gc, 752, "%s", buf); | |
424 break; | |
425 | |
426 case 752: /* MSG_CLIENT_PONG */ | |
427 buf2 = g_strdup_printf("Received pong from %s", buf); | |
5436
ad445074d239
[gaim-migrate @ 5818]
Christian Hammond <chipx86@chipx86.com>
parents:
5402
diff
changeset
|
428 gaim_notify_info(gc, NULL, buf2, NULL); |
5388 | 429 g_free(buf2); |
430 break; | |
431 | |
432 case 824: /* MSG_CLIENT_EMOTE */ | |
433 res = g_strsplit(buf, " ", 3); | |
434 buf2 = g_strndup(res[2]+1, strlen(res[2]) - 2); /* chomp off the surround quotes */ | |
435 buf3 = g_strdup_printf("/me %s", buf2); | |
436 g_free(buf2); | |
5402 | 437 if ((c = nap_find_chat(gc, res[0]))) { |
6621 | 438 gaim_chat_write(GAIM_CHAT(c), res[1], buf3, GAIM_MESSAGE_NICK, time(NULL)); |
5388 | 439 } |
440 g_free(buf3); | |
441 g_strfreev(res); | |
442 break; | |
443 | |
444 default: | |
445 gaim_debug(GAIM_DEBUG_MISC, "napster", "Unknown packet %hd: %s\n", command, buf); | |
446 break; | |
2086 | 447 } |
5388 | 448 |
449 g_free(buf); | |
2086 | 450 } |
451 | |
5388 | 452 /* 002 - MSG_CLIENT_LOGIN */ |
2090
b66aca8e8dce
[gaim-migrate @ 2100]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
453 static void nap_login_connect(gpointer data, gint source, GaimInputCondition cond) |
2086 | 454 { |
5604 | 455 GaimConnection *gc = data; |
5388 | 456 struct nap_data *ndata = (struct nap_data *)gc->proto_data; |
457 gchar *buf; | |
2086 | 458 |
5605 | 459 if (!g_list_find(gaim_connections_get_all(), gc)) { |
2701
8a84f2bb1716
[gaim-migrate @ 2714]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
460 close(source); |
8a84f2bb1716
[gaim-migrate @ 2714]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
461 return; |
8a84f2bb1716
[gaim-migrate @ 2714]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
462 } |
8a84f2bb1716
[gaim-migrate @ 2714]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
463 |
2086 | 464 if (source < 0) { |
6321 | 465 gaim_connection_error(gc, _("Unable to connect")); |
2086 | 466 return; |
467 } | |
468 | |
4452 | 469 ndata->fd = source; |
2086 | 470 |
5388 | 471 /* Update the login progress status display */ |
5604 | 472 buf = g_strdup_printf("Logging in: %s", gaim_account_get_username(gc->account)); |
473 gaim_connection_update_progress(gc, buf, 2, NAPSTER_CONNECT_STEPS); | |
5388 | 474 g_free(buf); |
475 | |
476 /* Write our signon data */ | |
5604 | 477 nap_write_packet(gc, 2, "%s %s 0 \"gaim %s\" 0", |
478 gaim_account_get_username(gc->account), | |
479 gaim_account_get_password(gc->account), VERSION); | |
5388 | 480 |
2086 | 481 /* And set up the input watcher */ |
5388 | 482 gc->inpa = gaim_input_add(ndata->fd, GAIM_INPUT_READ, nap_callback, gc); |
2086 | 483 } |
484 | |
5604 | 485 static void nap_login(GaimAccount *account) |
2086 | 486 { |
5604 | 487 GaimConnection *gc = gaim_account_get_connection(account); |
5388 | 488 |
5604 | 489 gaim_connection_update_progress(gc, _("Connecting"), 1, NAPSTER_CONNECT_STEPS); |
5388 | 490 |
4460 | 491 gc->proto_data = g_new0(struct nap_data, 1); |
5681
46d7ad0dfa26
[gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents:
5679
diff
changeset
|
492 if (gaim_proxy_connect(account, |
5604 | 493 gaim_account_get_string(account, "server", NAP_SERVER), |
494 gaim_account_get_int(account, "port", NAP_PORT), | |
4491 | 495 nap_login_connect, gc) != 0) { |
5604 | 496 gaim_connection_error(gc, _("Unable to connect")); |
2086 | 497 } |
498 } | |
499 | |
5604 | 500 static void nap_close(GaimConnection *gc) |
2086 | 501 { |
502 struct nap_data *ndata = (struct nap_data *)gc->proto_data; | |
5388 | 503 |
2086 | 504 if (gc->inpa) |
2090
b66aca8e8dce
[gaim-migrate @ 2100]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
505 gaim_input_remove(gc->inpa); |
2086 | 506 |
5388 | 507 if (!ndata) |
508 return; | |
509 | |
510 g_free(ndata->email); | |
511 g_free(ndata); | |
2086 | 512 } |
513 | |
6695 | 514 static const char* nap_list_icon(GaimAccount *a, GaimBuddy *b) |
2086 | 515 { |
4687 | 516 return "napster"; |
2086 | 517 } |
518 | |
6695 | 519 static void nap_list_emblems(GaimBuddy *b, char **se, char **sw, char **nw, char **ne) |
4916 | 520 { |
5068 | 521 if (b->present == GAIM_BUDDY_OFFLINE) |
4916 | 522 *se = "offline"; |
523 } | |
524 | |
5604 | 525 static GList *nap_buddy_menu(GaimConnection *gc, const char *who) |
2086 | 526 { |
5388 | 527 GList *m = NULL; |
528 struct proto_buddy_menu *pbm; | |
2086 | 529 |
5388 | 530 pbm = g_new0(struct proto_buddy_menu, 1); |
531 pbm->label = _("Get Info"); | |
532 pbm->callback = nap_get_info; | |
533 pbm->gc = gc; | |
534 m = g_list_append(m, pbm); | |
3572 | 535 |
5388 | 536 return m; |
2086 | 537 } |
538 | |
5604 | 539 static GList *nap_chat_info(GaimConnection *gc) |
2086 | 540 { |
5388 | 541 GList *m = NULL; |
542 struct proto_chat_entry *pce; | |
543 | |
544 pce = g_new0(struct proto_chat_entry, 1); | |
545 pce->label = _("Join what group:"); | |
546 pce->identifier = "group"; | |
547 m = g_list_append(m, pce); | |
548 | |
549 return m; | |
2086 | 550 } |
5388 | 551 |
552 static GaimPlugin *my_protocol = NULL; | |
5205
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5136
diff
changeset
|
553 |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5136
diff
changeset
|
554 static GaimPluginProtocolInfo prpl_info = |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5136
diff
changeset
|
555 { |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5136
diff
changeset
|
556 GAIM_PROTO_NAPSTER, |
5388 | 557 OPT_PROTO_CHAT_TOPIC, |
5205
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5136
diff
changeset
|
558 NULL, |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5136
diff
changeset
|
559 NULL, |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5136
diff
changeset
|
560 nap_list_icon, |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5136
diff
changeset
|
561 nap_list_emblems, |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5136
diff
changeset
|
562 NULL, |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5136
diff
changeset
|
563 NULL, |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5136
diff
changeset
|
564 NULL, |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5136
diff
changeset
|
565 NULL, |
5388 | 566 nap_buddy_menu, |
5205
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5136
diff
changeset
|
567 nap_chat_info, |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5136
diff
changeset
|
568 nap_login, |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5136
diff
changeset
|
569 nap_close, |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5136
diff
changeset
|
570 nap_send_im, |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5136
diff
changeset
|
571 NULL, |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5136
diff
changeset
|
572 NULL, |
5388 | 573 nap_get_info, |
5205
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5136
diff
changeset
|
574 NULL, |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5136
diff
changeset
|
575 NULL, |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5136
diff
changeset
|
576 NULL, |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5136
diff
changeset
|
577 NULL, |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5136
diff
changeset
|
578 NULL, |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5136
diff
changeset
|
579 NULL, |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5136
diff
changeset
|
580 NULL, |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5136
diff
changeset
|
581 nap_add_buddy, |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5136
diff
changeset
|
582 nap_add_buddies, |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5136
diff
changeset
|
583 nap_remove_buddy, |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5136
diff
changeset
|
584 NULL, |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5136
diff
changeset
|
585 NULL, |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5136
diff
changeset
|
586 NULL, |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5136
diff
changeset
|
587 NULL, |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5136
diff
changeset
|
588 NULL, |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5136
diff
changeset
|
589 NULL, |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5136
diff
changeset
|
590 NULL, |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5136
diff
changeset
|
591 nap_join_chat, |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5136
diff
changeset
|
592 NULL, |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5136
diff
changeset
|
593 nap_chat_leave, |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5136
diff
changeset
|
594 NULL, |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5136
diff
changeset
|
595 nap_chat_send, |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5136
diff
changeset
|
596 NULL, |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5136
diff
changeset
|
597 NULL, |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5136
diff
changeset
|
598 NULL, |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5136
diff
changeset
|
599 NULL, |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5136
diff
changeset
|
600 NULL, |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5136
diff
changeset
|
601 NULL, |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5136
diff
changeset
|
602 NULL, |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5136
diff
changeset
|
603 NULL, |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5136
diff
changeset
|
604 NULL, |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5136
diff
changeset
|
605 NULL |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5136
diff
changeset
|
606 }; |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5136
diff
changeset
|
607 |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5136
diff
changeset
|
608 static GaimPluginInfo info = |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5136
diff
changeset
|
609 { |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5136
diff
changeset
|
610 2, /**< api_version */ |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5136
diff
changeset
|
611 GAIM_PLUGIN_PROTOCOL, /**< type */ |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5136
diff
changeset
|
612 NULL, /**< ui_requirement */ |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5136
diff
changeset
|
613 0, /**< flags */ |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5136
diff
changeset
|
614 NULL, /**< dependencies */ |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5136
diff
changeset
|
615 GAIM_PRIORITY_DEFAULT, /**< priority */ |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5136
diff
changeset
|
616 |
5388 | 617 "prpl-napster", /**< id */ |
618 "Napster", /**< name */ | |
5205
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5136
diff
changeset
|
619 VERSION, /**< version */ |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5136
diff
changeset
|
620 /** summary */ |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5136
diff
changeset
|
621 N_("NAPSTER Protocol Plugin"), |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5136
diff
changeset
|
622 /** description */ |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5136
diff
changeset
|
623 N_("NAPSTER Protocol Plugin"), |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5136
diff
changeset
|
624 NULL, /**< author */ |
6371
8f94cce8faa5
[gaim-migrate @ 6876]
Christian Hammond <chipx86@chipx86.com>
parents:
6321
diff
changeset
|
625 GAIM_WEBSITE, /**< homepage */ |
5205
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5136
diff
changeset
|
626 |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5136
diff
changeset
|
627 NULL, /**< load */ |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5136
diff
changeset
|
628 NULL, /**< unload */ |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5136
diff
changeset
|
629 NULL, /**< destroy */ |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5136
diff
changeset
|
630 |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5136
diff
changeset
|
631 NULL, /**< ui_info */ |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5136
diff
changeset
|
632 &prpl_info /**< extra_info */ |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5136
diff
changeset
|
633 }; |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5136
diff
changeset
|
634 |
5920
7d385de2f9cd
[gaim-migrate @ 6360]
Christian Hammond <chipx86@chipx86.com>
parents:
5872
diff
changeset
|
635 static void init_plugin(GaimPlugin *plugin) |
5205
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5136
diff
changeset
|
636 { |
5638
0bdfa28c678e
[gaim-migrate @ 6047]
Christian Hammond <chipx86@chipx86.com>
parents:
5605
diff
changeset
|
637 GaimAccountOption *option; |
5205
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5136
diff
changeset
|
638 |
5638
0bdfa28c678e
[gaim-migrate @ 6047]
Christian Hammond <chipx86@chipx86.com>
parents:
5605
diff
changeset
|
639 option = gaim_account_option_string_new(_("Server"), "server", |
0bdfa28c678e
[gaim-migrate @ 6047]
Christian Hammond <chipx86@chipx86.com>
parents:
5605
diff
changeset
|
640 NAP_SERVER); |
0bdfa28c678e
[gaim-migrate @ 6047]
Christian Hammond <chipx86@chipx86.com>
parents:
5605
diff
changeset
|
641 prpl_info.protocol_options = g_list_append(prpl_info.protocol_options, |
0bdfa28c678e
[gaim-migrate @ 6047]
Christian Hammond <chipx86@chipx86.com>
parents:
5605
diff
changeset
|
642 option); |
5205
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5136
diff
changeset
|
643 |
5638
0bdfa28c678e
[gaim-migrate @ 6047]
Christian Hammond <chipx86@chipx86.com>
parents:
5605
diff
changeset
|
644 option = gaim_account_option_int_new(_("Port"), "port", 8888); |
0bdfa28c678e
[gaim-migrate @ 6047]
Christian Hammond <chipx86@chipx86.com>
parents:
5605
diff
changeset
|
645 prpl_info.protocol_options = g_list_append(prpl_info.protocol_options, |
0bdfa28c678e
[gaim-migrate @ 6047]
Christian Hammond <chipx86@chipx86.com>
parents:
5605
diff
changeset
|
646 option); |
5205
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5136
diff
changeset
|
647 |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5136
diff
changeset
|
648 my_protocol = plugin; |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5136
diff
changeset
|
649 } |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5136
diff
changeset
|
650 |
5920
7d385de2f9cd
[gaim-migrate @ 6360]
Christian Hammond <chipx86@chipx86.com>
parents:
5872
diff
changeset
|
651 GAIM_INIT_PLUGIN(napster, init_plugin, info); |