Mercurial > pidgin
annotate src/protocols/napster/napster.c @ 10860:d01d81de94d8
[gaim-migrate @ 12543]
sf patch #1188728, from Enix
"this patch fixes the sort by status option in HEAD so
that it actually sorts by status. Also, changes the
documenation in status.h for the
gaim_presence_compare() function so that it makes sense."
committer: Tailor Script <tailor@pidgin.im>
author | Mark Doliner <mark@kingant.net> |
---|---|
date | Sun, 24 Apr 2005 18:13:16 +0000 |
parents | c94f40ffcafb |
children | 3e43c132f151 |
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 */ | |
9285 | 150 static void nap_add_buddies(GaimConnection *gc, GList *buddies, GList *groups) |
5388 | 151 { |
152 while (buddies) { | |
9285 | 153 GaimBuddy *buddy = buddies->data; |
154 nap_write_packet(gc, 208, "%s", buddy->name); | |
155 buddies = buddies->next; | |
5388 | 156 } |
157 } | |
158 | |
159 /* 303 - MSG_CLIENT_REMOVE_HOTLIST */ | |
9285 | 160 static void nap_remove_buddy(GaimConnection *gc, GaimBuddy *buddy, GaimGroup *group) |
5388 | 161 { |
9285 | 162 nap_write_packet(gc, 303, "%s", buddy->name); |
5388 | 163 } |
164 | |
9917 | 165 static char *nap_get_chat_name(GHashTable *data) { |
166 char *name = g_hash_table_lookup(data, "group"); | |
10200 | 167 |
9917 | 168 /* Make sure the name has a # preceding it */ |
169 if (name[0] != '#') { | |
170 return g_strdup_printf("#%s", name); | |
171 } | |
172 | |
173 return g_strdup(name); | |
174 } | |
175 | |
5388 | 176 /* 400 - MSG_CLIENT_JOIN */ |
5604 | 177 static void nap_join_chat(GaimConnection *gc, GHashTable *data) |
5388 | 178 { |
179 char *name; | |
180 | |
181 if (!data) | |
182 return; | |
183 | |
9917 | 184 name = nap_get_chat_name(data); |
5388 | 185 |
9917 | 186 if (name) { |
5388 | 187 nap_write_packet(gc, 400, "%s", name); |
9917 | 188 g_free(name); |
189 } | |
5388 | 190 } |
191 | |
192 /* 401 - MSG_CLIENT_PART */ | |
5604 | 193 static void nap_chat_leave(GaimConnection *gc, int id) |
5388 | 194 { |
5679 | 195 GaimConversation *c = gaim_find_chat(gc, id); |
5388 | 196 |
5402 | 197 if (!c) |
5388 | 198 return; |
199 | |
5402 | 200 nap_write_packet(gc, 401, "%s", c->name); |
5388 | 201 } |
202 | |
203 /* 402 - MSG_CLIENT_PUBLIC */ | |
6059 | 204 static int nap_chat_send(GaimConnection *gc, int id, const char *message) |
5388 | 205 { |
5679 | 206 GaimConversation *c = gaim_find_chat(gc, id); |
5388 | 207 |
5402 | 208 if (!c) |
5388 | 209 return -EINVAL; |
210 | |
211 if ((strlen(message) < 2) || (message[0] != '/' ) || (message[1] == '/')) { | |
212 /* Actually send a chat message */ | |
5402 | 213 nap_write_packet(gc, 402, "%s %s", c->name, message); |
5388 | 214 } else { |
215 /* user typed an IRC-style command */ | |
5402 | 216 nap_do_irc_style(gc, message, c->name); |
5388 | 217 } |
218 | |
219 return 0; | |
220 } | |
221 | |
222 /* 603 - MSG_CLIENT_WHOIS */ | |
5604 | 223 static void nap_get_info(GaimConnection *gc, const char *who) |
5388 | 224 { |
225 nap_write_packet(gc, 603, "%s", who); | |
2086 | 226 } |
227 | |
2090
b66aca8e8dce
[gaim-migrate @ 2100]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
228 static void nap_callback(gpointer data, gint source, GaimInputCondition condition) |
2086 | 229 { |
5604 | 230 GaimConnection *gc = data; |
2086 | 231 struct nap_data *ndata = gc->proto_data; |
10010 | 232 GaimAccount *account = gaim_connection_get_account(gc); |
5679 | 233 GaimConversation *c; |
5402 | 234 gchar *buf, *buf2, *buf3, **res; |
2086 | 235 unsigned short header[2]; |
236 int len; | |
237 int command; | |
2220
8b7ba25a7ece
[gaim-migrate @ 2230]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2205
diff
changeset
|
238 int i; |
2086 | 239 |
5388 | 240 if (read(source, (void*)header, 4) != 4) { |
5604 | 241 gaim_connection_error(gc, _("Unable to read header from server")); |
2220
8b7ba25a7ece
[gaim-migrate @ 2230]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2205
diff
changeset
|
242 return; |
8b7ba25a7ece
[gaim-migrate @ 2230]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2205
diff
changeset
|
243 } |
8b7ba25a7ece
[gaim-migrate @ 2230]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2205
diff
changeset
|
244 |
2086 | 245 len = header[0]; |
10740 | 246 command = header[1]; |
5388 | 247 buf = (gchar *)g_malloc((len + 1) * sizeof(gchar)); |
248 buf[len] = '\0'; | |
2086 | 249 |
2220
8b7ba25a7ece
[gaim-migrate @ 2230]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2205
diff
changeset
|
250 i = 0; |
8b7ba25a7ece
[gaim-migrate @ 2230]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2205
diff
changeset
|
251 do { |
5388 | 252 int tmp = read(source, buf + i, len - i); |
2220
8b7ba25a7ece
[gaim-migrate @ 2230]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2205
diff
changeset
|
253 if (tmp <= 0) { |
8b7ba25a7ece
[gaim-migrate @ 2230]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2205
diff
changeset
|
254 g_free(buf); |
10816
c94f40ffcafb
[gaim-migrate @ 12471]
Luke Schierer <lschiere@pidgin.im>
parents:
10812
diff
changeset
|
255 buf = g_strdup_printf(_("Unable to read message from server: %s. Command is %hd, length is %hd."), strerror(errno), len, command); |
5604 | 256 gaim_connection_error(gc, buf); |
5388 | 257 g_free(buf); |
2220
8b7ba25a7ece
[gaim-migrate @ 2230]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2205
diff
changeset
|
258 return; |
8b7ba25a7ece
[gaim-migrate @ 2230]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2205
diff
changeset
|
259 } |
8b7ba25a7ece
[gaim-migrate @ 2230]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2205
diff
changeset
|
260 i += tmp; |
8b7ba25a7ece
[gaim-migrate @ 2230]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2205
diff
changeset
|
261 } while (i != len); |
2086 | 262 |
5388 | 263 gaim_debug(GAIM_DEBUG_MISC, "napster", "R %3hd: %s\n", command, buf); |
2086 | 264 |
5388 | 265 switch (command) { |
266 case 000: /* MSG_SERVER_ERROR */ | |
5436
ad445074d239
[gaim-migrate @ 5818]
Christian Hammond <chipx86@chipx86.com>
parents:
5402
diff
changeset
|
267 gaim_notify_error(gc, NULL, buf, NULL); |
5388 | 268 gaim_input_remove(gc->inpa); |
269 gc->inpa = 0; | |
2086 | 270 close(source); |
10740 | 271 gaim_connection_error(gc, _("Unknown server error.")); |
5388 | 272 break; |
2086 | 273 |
5388 | 274 case 003: /* MSG_SERVER_EMAIL */ |
275 gaim_debug(GAIM_DEBUG_MISC, "napster", "Registered with e-mail address: %s\n", buf); | |
2086 | 276 ndata->email = g_strdup(buf); |
277 | |
278 /* Our signon is complete */ | |
5604 | 279 gaim_connection_set_state(gc, GAIM_CONNECTED); |
2086 | 280 |
5388 | 281 break; |
282 | |
283 case 201: /* MSG_SERVER_SEARCH_RESULT */ | |
284 res = g_strsplit(buf, " ", 0); | |
10010 | 285 gaim_prpl_got_user_status(account, res[0], "online", NULL); |
5388 | 286 g_strfreev(res); |
287 break; | |
288 | |
289 case 202: /* MSG_SERVER_SEARCH_END */ | |
10123 | 290 gaim_prpl_got_user_status(account, buf, "offline", NULL); |
5388 | 291 break; |
292 | |
293 case 205: /* MSG_CLIENT_PRIVMSG */ | |
294 res = g_strsplit(buf, " ", 2); | |
10732
c4cb90065e1d
[gaim-migrate @ 12334]
Luke Schierer <lschiere@pidgin.im>
parents:
10723
diff
changeset
|
295 buf2 = g_markup_escape_text(res[1], -1); |
8495 | 296 serv_got_im(gc, res[0], buf2, 0, time(NULL)); |
297 g_free(buf2); | |
5388 | 298 g_strfreev(res); |
299 break; | |
300 | |
301 case 209: /* MSG_SERVER_USER_SIGNON */ | |
302 /* USERNAME SPEED */ | |
303 res = g_strsplit(buf, " ", 2); | |
10010 | 304 gaim_prpl_got_user_status(account, res[0], "online", NULL); |
5388 | 305 g_strfreev(res); |
306 break; | |
307 | |
308 case 210: /* MSG_SERVER_USER_SIGNOFF */ | |
309 /* USERNAME SPEED */ | |
310 res = g_strsplit(buf, " ", 2); | |
10010 | 311 gaim_prpl_got_user_status(account, res[0], "offline", NULL); |
5388 | 312 g_strfreev(res); |
313 break; | |
314 | |
315 case 214: /* MSG_SERVER_STATS */ | |
316 res = g_strsplit(buf, " ", 3); | |
317 buf2 = g_strdup_printf(_("users: %s, files: %s, size: %sGB"), res[0], res[1], res[2]); | |
6982 | 318 serv_got_im(gc, "server", buf2, 0, time(NULL)); |
5388 | 319 g_free(buf2); |
320 g_strfreev(res); | |
321 break; | |
322 | |
323 case 301: /* MSG_SERVER_HOTLIST_ACK */ | |
324 /* Our buddy was added successfully */ | |
325 break; | |
326 | |
327 case 302: /* MSG_SERVER_HOTLIST_ERROR */ | |
328 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
|
329 gaim_notify_error(gc, NULL, buf2, NULL); |
5388 | 330 g_free(buf2); |
331 break; | |
332 | |
333 case 316: /* MSG_SERVER_DISCONNECTING */ | |
334 /* we have been kicked off =^( */ | |
10740 | 335 gaim_connection_error(gc, _("You were disconnected from the server.")); |
5388 | 336 break; |
337 | |
338 case 401: /* MSG_CLIENT_PART */ | |
5402 | 339 c = nap_find_chat(gc, buf); |
340 if (c) | |
7118
bf630f7dfdcd
[gaim-migrate @ 7685]
Christian Hammond <chipx86@chipx86.com>
parents:
7084
diff
changeset
|
341 serv_got_chat_left(gc, gaim_conv_chat_get_id(GAIM_CONV_CHAT(c))); |
5388 | 342 break; |
343 | |
344 case 403: /* MSG_SERVER_PUBLIC */ | |
345 res = g_strsplit(buf, " ", 3); | |
5402 | 346 c = nap_find_chat(gc, res[0]); |
347 if (c) | |
7118
bf630f7dfdcd
[gaim-migrate @ 7685]
Christian Hammond <chipx86@chipx86.com>
parents:
7084
diff
changeset
|
348 serv_got_chat_in(gc, gaim_conv_chat_get_id(GAIM_CONV_CHAT(c)), res[1], 0, res[2], time((time_t)NULL)); |
5388 | 349 g_strfreev(res); |
350 break; | |
351 | |
352 case 404: /* MSG_SERVER_NOSUCH */ | |
353 /* abused by opennap servers to broadcast stuff */ | |
10732
c4cb90065e1d
[gaim-migrate @ 12334]
Luke Schierer <lschiere@pidgin.im>
parents:
10723
diff
changeset
|
354 buf2 = g_markup_escape_text(buf, -1); |
8495 | 355 serv_got_im(gc, "server", buf2, 0, time(NULL)); |
356 g_free(buf2); | |
5388 | 357 break; |
358 | |
359 case 405: /* MSG_SERVER_JOIN_ACK */ | |
5402 | 360 c = nap_find_chat(gc, buf); |
361 if (!c) | |
7118
bf630f7dfdcd
[gaim-migrate @ 7685]
Christian Hammond <chipx86@chipx86.com>
parents:
7084
diff
changeset
|
362 serv_got_joined_chat(gc, gaim_conv_chat_get_id(GAIM_CONV_CHAT(c)), buf); |
5388 | 363 break; |
364 | |
365 case 407: /* MSG_SERVER_PART */ | |
366 res = g_strsplit(buf, " ", 0); | |
5402 | 367 c = nap_find_chat(gc, res[0]); |
7118
bf630f7dfdcd
[gaim-migrate @ 7685]
Christian Hammond <chipx86@chipx86.com>
parents:
7084
diff
changeset
|
368 gaim_conv_chat_remove_user(GAIM_CONV_CHAT(c), res[1], NULL); |
5388 | 369 g_strfreev(res); |
370 break; | |
371 | |
372 case 406: /* MSG_SERVER_JOIN */ | |
373 case 408: /* MSG_SERVER_CHANNEL_USER_LIST */ | |
374 res = g_strsplit(buf, " ", 4); | |
5402 | 375 c = nap_find_chat(gc, res[0]); |
9846 | 376 gaim_conv_chat_add_user(GAIM_CONV_CHAT(c), res[1], NULL, GAIM_CBFLAGS_NONE, TRUE); |
5388 | 377 g_strfreev(res); |
378 break; | |
379 | |
380 case 409: /* MSG_SERVER_CHANNEL_USER_LIST_END */ | |
381 break; | |
382 | |
383 case 410: /* MSG_SERVER_TOPIC */ | |
384 /* display the topic in the channel */ | |
385 res = g_strsplit(buf, " ", 2); | |
5402 | 386 c = nap_find_chat(gc, res[0]); |
7118
bf630f7dfdcd
[gaim-migrate @ 7685]
Christian Hammond <chipx86@chipx86.com>
parents:
7084
diff
changeset
|
387 gaim_conv_chat_set_topic(GAIM_CONV_CHAT(c), res[0], res[1]); |
5388 | 388 g_strfreev(res); |
389 break; | |
390 | |
391 case 603: /* MSG_CLIENT_WHOIS */ | |
392 buf2 = g_strdup_printf(_("%s requested your information"), buf); | |
6982 | 393 serv_got_im(gc, "server", buf2, 0, time(NULL)); |
5388 | 394 g_free(buf2); |
395 break; | |
396 | |
397 case 604: /* MSG_SERVER_WHOIS_RESPONSE */ | |
398 /* XXX - Format is: "Elite" 37 " " "Active" 0 0 0 0 "gaim 0.63cvs" 0 0 192.168.1.41 32798 0 unknown flounder */ | |
399 res = g_strsplit(buf, " ", 2); | |
7062
86ed8b2aa665
[gaim-migrate @ 7626]
Christian Hammond <chipx86@chipx86.com>
parents:
6982
diff
changeset
|
400 /* res[0] == username */ |
9797 | 401 gaim_notify_userinfo(gc, res[0], NULL, _("Buddy Information"), NULL, |
7062
86ed8b2aa665
[gaim-migrate @ 7626]
Christian Hammond <chipx86@chipx86.com>
parents:
6982
diff
changeset
|
402 res[1], NULL, NULL); |
5388 | 403 g_strfreev(res); |
404 break; | |
405 | |
406 case 621: | |
407 case 622: /* MSG_CLIENT_MOTD */ | |
408 /* also replaces MSG_SERVER_MOTD, so we should display it */ | |
10732
c4cb90065e1d
[gaim-migrate @ 12334]
Luke Schierer <lschiere@pidgin.im>
parents:
10723
diff
changeset
|
409 buf2 = g_markup_escape_text(buf, -1); |
8495 | 410 serv_got_im(gc, "motd", buf2, 0, time(NULL)); |
411 g_free(buf2); | |
5388 | 412 break; |
413 | |
414 case 627: /* MSG_CLIENT_WALLOP */ | |
415 /* abused by opennap server maintainers to broadcast stuff */ | |
10732
c4cb90065e1d
[gaim-migrate @ 12334]
Luke Schierer <lschiere@pidgin.im>
parents:
10723
diff
changeset
|
416 buf2 = g_markup_escape_text(buf, -1); |
8495 | 417 serv_got_im(gc, "wallop", buf2, 0, time(NULL)); |
418 g_free(buf2); | |
5388 | 419 break; |
420 | |
421 case 628: /* MSG_CLIENT_ANNOUNCE */ | |
10732
c4cb90065e1d
[gaim-migrate @ 12334]
Luke Schierer <lschiere@pidgin.im>
parents:
10723
diff
changeset
|
422 buf2 = g_markup_escape_text(buf, -1); |
8495 | 423 serv_got_im(gc, "announce", buf2, 0, time(NULL)); |
424 g_free(buf); | |
5388 | 425 break; |
426 | |
427 case 748: /* MSG_SERVER_GHOST */ | |
428 /* Looks like someone logged in as us! =-O */ | |
10740 | 429 gaim_connection_error(gc, _("You have signed on from another location.")); |
5388 | 430 break; |
431 | |
432 case 751: /* MSG_CLIENT_PING */ | |
433 buf2 = g_strdup_printf(_("%s requested a PING"), buf); | |
6982 | 434 serv_got_im(gc, "server", buf2, 0, time(NULL)); |
5388 | 435 g_free(buf2); |
436 /* send back a pong */ | |
437 /* MSG_CLIENT_PONG */ | |
438 nap_write_packet(gc, 752, "%s", buf); | |
439 break; | |
440 | |
441 case 752: /* MSG_CLIENT_PONG */ | |
442 buf2 = g_strdup_printf("Received pong from %s", buf); | |
5436
ad445074d239
[gaim-migrate @ 5818]
Christian Hammond <chipx86@chipx86.com>
parents:
5402
diff
changeset
|
443 gaim_notify_info(gc, NULL, buf2, NULL); |
5388 | 444 g_free(buf2); |
445 break; | |
446 | |
447 case 824: /* MSG_CLIENT_EMOTE */ | |
448 res = g_strsplit(buf, " ", 3); | |
449 buf2 = g_strndup(res[2]+1, strlen(res[2]) - 2); /* chomp off the surround quotes */ | |
450 buf3 = g_strdup_printf("/me %s", buf2); | |
451 g_free(buf2); | |
5402 | 452 if ((c = nap_find_chat(gc, res[0]))) { |
7118
bf630f7dfdcd
[gaim-migrate @ 7685]
Christian Hammond <chipx86@chipx86.com>
parents:
7084
diff
changeset
|
453 gaim_conv_chat_write(GAIM_CONV_CHAT(c), res[1], buf3, GAIM_MESSAGE_NICK, time(NULL)); |
5388 | 454 } |
455 g_free(buf3); | |
456 g_strfreev(res); | |
457 break; | |
458 | |
459 default: | |
460 gaim_debug(GAIM_DEBUG_MISC, "napster", "Unknown packet %hd: %s\n", command, buf); | |
461 break; | |
2086 | 462 } |
5388 | 463 |
464 g_free(buf); | |
2086 | 465 } |
466 | |
5388 | 467 /* 002 - MSG_CLIENT_LOGIN */ |
2090
b66aca8e8dce
[gaim-migrate @ 2100]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
468 static void nap_login_connect(gpointer data, gint source, GaimInputCondition cond) |
2086 | 469 { |
5604 | 470 GaimConnection *gc = data; |
5388 | 471 struct nap_data *ndata = (struct nap_data *)gc->proto_data; |
472 gchar *buf; | |
2086 | 473 |
5605 | 474 if (!g_list_find(gaim_connections_get_all(), gc)) { |
2701
8a84f2bb1716
[gaim-migrate @ 2714]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
475 close(source); |
8a84f2bb1716
[gaim-migrate @ 2714]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
476 return; |
8a84f2bb1716
[gaim-migrate @ 2714]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
477 } |
8a84f2bb1716
[gaim-migrate @ 2714]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
478 |
2086 | 479 if (source < 0) { |
7981 | 480 gaim_connection_error(gc, _("Unable to connect.")); |
2086 | 481 return; |
482 } | |
483 | |
4452 | 484 ndata->fd = source; |
2086 | 485 |
5388 | 486 /* Update the login progress status display */ |
5604 | 487 buf = g_strdup_printf("Logging in: %s", gaim_account_get_username(gc->account)); |
7884 | 488 gaim_connection_update_progress(gc, buf, 1, NAPSTER_CONNECT_STEPS); |
5388 | 489 g_free(buf); |
490 | |
491 /* Write our signon data */ | |
5604 | 492 nap_write_packet(gc, 2, "%s %s 0 \"gaim %s\" 0", |
493 gaim_account_get_username(gc->account), | |
10740 | 494 gaim_connection_get_password(gc), VERSION); |
5388 | 495 |
2086 | 496 /* And set up the input watcher */ |
5388 | 497 gc->inpa = gaim_input_add(ndata->fd, GAIM_INPUT_READ, nap_callback, gc); |
2086 | 498 } |
499 | |
10401 | 500 static void nap_login(GaimAccount *account, GaimStatus *status) |
2086 | 501 { |
5604 | 502 GaimConnection *gc = gaim_account_get_connection(account); |
5388 | 503 |
7884 | 504 gaim_connection_update_progress(gc, _("Connecting"), 0, NAPSTER_CONNECT_STEPS); |
5388 | 505 |
4460 | 506 gc->proto_data = g_new0(struct nap_data, 1); |
5681
46d7ad0dfa26
[gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents:
5679
diff
changeset
|
507 if (gaim_proxy_connect(account, |
5604 | 508 gaim_account_get_string(account, "server", NAP_SERVER), |
509 gaim_account_get_int(account, "port", NAP_PORT), | |
4491 | 510 nap_login_connect, gc) != 0) { |
7981 | 511 gaim_connection_error(gc, _("Unable to connect.")); |
2086 | 512 } |
513 } | |
514 | |
5604 | 515 static void nap_close(GaimConnection *gc) |
2086 | 516 { |
517 struct nap_data *ndata = (struct nap_data *)gc->proto_data; | |
5388 | 518 |
2086 | 519 if (gc->inpa) |
2090
b66aca8e8dce
[gaim-migrate @ 2100]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
520 gaim_input_remove(gc->inpa); |
2086 | 521 |
5388 | 522 if (!ndata) |
523 return; | |
524 | |
525 g_free(ndata->email); | |
526 g_free(ndata); | |
2086 | 527 } |
528 | |
6695 | 529 static const char* nap_list_icon(GaimAccount *a, GaimBuddy *b) |
2086 | 530 { |
4687 | 531 return "napster"; |
2086 | 532 } |
533 | |
9953 | 534 static void nap_list_emblems(GaimBuddy *b, const char **se, const char **sw, |
535 const char **nw, const char **ne) | |
4916 | 536 { |
10723
a9c77f7b8ced
[gaim-migrate @ 12323]
Luke Schierer <lschiere@pidgin.im>
parents:
10649
diff
changeset
|
537 if(!GAIM_BUDDY_IS_ONLINE(b)) |
4916 | 538 *se = "offline"; |
539 } | |
540 | |
10200 | 541 static GList *nap_status_types(GaimAccount *account) |
542 { | |
543 GList *types = NULL; | |
544 GaimStatusType *type; | |
545 | |
546 g_return_val_if_fail(account != NULL, NULL); | |
547 | |
548 type = gaim_status_type_new_full(GAIM_STATUS_OFFLINE, | |
549 "offline", | |
10723
a9c77f7b8ced
[gaim-migrate @ 12323]
Luke Schierer <lschiere@pidgin.im>
parents:
10649
diff
changeset
|
550 _("Offline"), TRUE, TRUE, FALSE); |
10200 | 551 types = g_list_append(types, type); |
552 | |
553 type = gaim_status_type_new_full(GAIM_STATUS_ONLINE, | |
554 "online", | |
10723
a9c77f7b8ced
[gaim-migrate @ 12323]
Luke Schierer <lschiere@pidgin.im>
parents:
10649
diff
changeset
|
555 _("Online"), TRUE, TRUE, FALSE); |
10200 | 556 types = g_list_append(types, type); |
557 | |
558 return types; | |
559 } | |
560 | |
5604 | 561 static GList *nap_chat_info(GaimConnection *gc) |
2086 | 562 { |
5388 | 563 GList *m = NULL; |
564 struct proto_chat_entry *pce; | |
565 | |
566 pce = g_new0(struct proto_chat_entry, 1); | |
7844 | 567 pce->label = _("_Group:"); |
5388 | 568 pce->identifier = "group"; |
569 m = g_list_append(m, pce); | |
570 | |
571 return m; | |
2086 | 572 } |
5388 | 573 |
9754 | 574 GHashTable *nap_chat_info_defaults(GaimConnection *gc, const char *chat_name) |
575 { | |
576 GHashTable *defaults; | |
577 | |
578 defaults = g_hash_table_new_full(g_str_hash, g_str_equal, NULL, g_free); | |
579 | |
580 if (chat_name != NULL) | |
581 g_hash_table_insert(defaults, "group", g_strdup(chat_name)); | |
582 | |
583 return defaults; | |
584 } | |
585 | |
5388 | 586 static GaimPlugin *my_protocol = NULL; |
5205
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5136
diff
changeset
|
587 |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5136
diff
changeset
|
588 static GaimPluginProtocolInfo prpl_info = |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5136
diff
changeset
|
589 { |
5388 | 590 OPT_PROTO_CHAT_TOPIC, |
9475 | 591 NULL, /* user_splits */ |
592 NULL, /* protocol_options */ | |
593 NO_BUDDY_ICONS, /* icon_spec */ | |
594 nap_list_icon, /* list_icon */ | |
595 nap_list_emblems, /* list_emblems */ | |
596 NULL, /* status_text */ | |
597 NULL, /* tooltip_text */ | |
10200 | 598 nap_status_types, /* status_types */ |
9475 | 599 NULL, /* blist_node_menu */ |
600 nap_chat_info, /* chat_info */ | |
9754 | 601 nap_chat_info_defaults, /* chat_info_defaults */ |
9475 | 602 nap_login, /* login */ |
603 nap_close, /* close */ | |
604 nap_send_im, /* send_im */ | |
605 NULL, /* set_info */ | |
606 NULL, /* send_typing */ | |
607 nap_get_info, /* get_info */ | |
608 NULL, /* set_away */ | |
609 NULL, /* set_idle */ | |
610 NULL, /* change_passwd */ | |
611 nap_add_buddy, /* add_buddy */ | |
612 nap_add_buddies, /* add_buddies */ | |
613 nap_remove_buddy, /* remove_buddy */ | |
614 NULL, /* remove_buddies */ | |
615 NULL, /* add_permit */ | |
616 NULL, /* add_deny */ | |
617 NULL, /* rem_permit */ | |
618 NULL, /* rem_deny */ | |
619 NULL, /* set_permit_deny */ | |
620 NULL, /* warn */ | |
621 nap_join_chat, /* join_chat */ | |
622 NULL, /* reject chat invite */ | |
9917 | 623 nap_get_chat_name, /* get_chat_name */ |
9475 | 624 NULL, /* chat_invite */ |
625 nap_chat_leave, /* chat_leave */ | |
626 NULL, /* chat_whisper */ | |
627 nap_chat_send, /* chat_send */ | |
628 NULL, /* keepalive */ | |
629 NULL, /* register_user */ | |
630 NULL, /* get_cb_info */ | |
631 NULL, /* get_cb_away */ | |
632 NULL, /* alias_buddy */ | |
633 NULL, /* group_buddy */ | |
634 NULL, /* rename_group */ | |
635 NULL, /* buddy_free */ | |
636 NULL, /* convo_closed */ | |
637 NULL, /* normalize */ | |
638 NULL, /* set_buddy_icon */ | |
639 NULL, /* remove_group */ | |
640 NULL, /* get_cb_real_name */ | |
641 NULL, /* set_chat_topic */ | |
642 NULL, /* find_blist_chat */ | |
643 NULL, /* roomlist_get_list */ | |
644 NULL, /* roomlist_cancel */ | |
645 NULL, /* roomlist_expand_category */ | |
646 NULL, /* can_receive_file */ | |
647 NULL /* send_file */ | |
5205
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5136
diff
changeset
|
648 }; |
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 static GaimPluginInfo info = |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5136
diff
changeset
|
651 { |
9943 | 652 GAIM_PLUGIN_MAGIC, |
10649 | 653 0, |
9943 | 654 GAIM_MINOR_VERSION, |
5205
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5136
diff
changeset
|
655 GAIM_PLUGIN_PROTOCOL, /**< type */ |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5136
diff
changeset
|
656 NULL, /**< ui_requirement */ |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5136
diff
changeset
|
657 0, /**< flags */ |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5136
diff
changeset
|
658 NULL, /**< dependencies */ |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5136
diff
changeset
|
659 GAIM_PRIORITY_DEFAULT, /**< priority */ |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5136
diff
changeset
|
660 |
5388 | 661 "prpl-napster", /**< id */ |
662 "Napster", /**< name */ | |
5205
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5136
diff
changeset
|
663 VERSION, /**< version */ |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5136
diff
changeset
|
664 /** summary */ |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5136
diff
changeset
|
665 N_("NAPSTER Protocol Plugin"), |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5136
diff
changeset
|
666 /** description */ |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5136
diff
changeset
|
667 N_("NAPSTER Protocol Plugin"), |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5136
diff
changeset
|
668 NULL, /**< author */ |
6371
8f94cce8faa5
[gaim-migrate @ 6876]
Christian Hammond <chipx86@chipx86.com>
parents:
6321
diff
changeset
|
669 GAIM_WEBSITE, /**< homepage */ |
5205
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5136
diff
changeset
|
670 |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5136
diff
changeset
|
671 NULL, /**< load */ |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5136
diff
changeset
|
672 NULL, /**< unload */ |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5136
diff
changeset
|
673 NULL, /**< destroy */ |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5136
diff
changeset
|
674 |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5136
diff
changeset
|
675 NULL, /**< ui_info */ |
8993 | 676 &prpl_info, /**< extra_info */ |
677 NULL, | |
678 NULL | |
5205
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5136
diff
changeset
|
679 }; |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5136
diff
changeset
|
680 |
5920
7d385de2f9cd
[gaim-migrate @ 6360]
Christian Hammond <chipx86@chipx86.com>
parents:
5872
diff
changeset
|
681 static void init_plugin(GaimPlugin *plugin) |
5205
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5136
diff
changeset
|
682 { |
5638
0bdfa28c678e
[gaim-migrate @ 6047]
Christian Hammond <chipx86@chipx86.com>
parents:
5605
diff
changeset
|
683 GaimAccountOption *option; |
5205
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5136
diff
changeset
|
684 |
5638
0bdfa28c678e
[gaim-migrate @ 6047]
Christian Hammond <chipx86@chipx86.com>
parents:
5605
diff
changeset
|
685 option = gaim_account_option_string_new(_("Server"), "server", |
0bdfa28c678e
[gaim-migrate @ 6047]
Christian Hammond <chipx86@chipx86.com>
parents:
5605
diff
changeset
|
686 NAP_SERVER); |
0bdfa28c678e
[gaim-migrate @ 6047]
Christian Hammond <chipx86@chipx86.com>
parents:
5605
diff
changeset
|
687 prpl_info.protocol_options = g_list_append(prpl_info.protocol_options, |
0bdfa28c678e
[gaim-migrate @ 6047]
Christian Hammond <chipx86@chipx86.com>
parents:
5605
diff
changeset
|
688 option); |
5205
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5136
diff
changeset
|
689 |
5638
0bdfa28c678e
[gaim-migrate @ 6047]
Christian Hammond <chipx86@chipx86.com>
parents:
5605
diff
changeset
|
690 option = gaim_account_option_int_new(_("Port"), "port", 8888); |
0bdfa28c678e
[gaim-migrate @ 6047]
Christian Hammond <chipx86@chipx86.com>
parents:
5605
diff
changeset
|
691 prpl_info.protocol_options = g_list_append(prpl_info.protocol_options, |
0bdfa28c678e
[gaim-migrate @ 6047]
Christian Hammond <chipx86@chipx86.com>
parents:
5605
diff
changeset
|
692 option); |
5205
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5136
diff
changeset
|
693 |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5136
diff
changeset
|
694 my_protocol = plugin; |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5136
diff
changeset
|
695 } |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5136
diff
changeset
|
696 |
5920
7d385de2f9cd
[gaim-migrate @ 6360]
Christian Hammond <chipx86@chipx86.com>
parents:
5872
diff
changeset
|
697 GAIM_INIT_PLUGIN(napster, init_plugin, info); |