Mercurial > pidgin.yaz
annotate src/protocols/napster/napster.c @ 3593:d145d98d7ed1
[gaim-migrate @ 3695]
I'm a cool guy.
committer: Tailor Script <tailor@pidgin.im>
author | Sean Egan <seanegan@gmail.com> |
---|---|
date | Sun, 06 Oct 2002 02:59:26 +0000 |
parents | 737322cce04b |
children | 9682c0e022c6 |
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 */ | |
21 | |
2090
b66aca8e8dce
[gaim-migrate @ 2100]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
22 #include <config.h> |
2086 | 23 |
24 #include <netdb.h> | |
25 #include <unistd.h> | |
26 #include <errno.h> | |
27 #include <netinet/in.h> | |
28 #include <arpa/inet.h> | |
29 #include <time.h> | |
30 #include <string.h> | |
31 #include <stdlib.h> | |
32 #include <stdio.h> | |
33 #include <time.h> | |
34 #include <sys/socket.h> | |
35 #include <sys/stat.h> | |
36 #include "multi.h" | |
37 #include "prpl.h" | |
38 #include "gaim.h" | |
39 #include "proxy.h" | |
3593 | 40 #include "pixmaps/protocols/napster/napster.xpm" |
2086 | 41 |
42 #define NAP_BUF_LEN 4096 | |
43 | |
3322 | 44 #define USEROPT_NAPSERVER 3 |
45 #define NAP_SERVER "64.124.41.187" | |
46 #define USEROPT_NAPPORT 4 | |
47 #define NAP_PORT 8888 | |
48 | |
2086 | 49 GSList *nap_connections = NULL; |
50 | |
51 static unsigned int chat_id = 0; | |
52 | |
53 struct nap_channel { | |
54 unsigned int id; | |
55 gchar *name; | |
56 }; | |
57 | |
58 struct nap_data { | |
59 int fd; | |
60 int inpa; | |
61 | |
62 gchar *email; | |
63 GSList *channels; | |
64 }; | |
65 | |
66 /* FIXME: Make this use va_arg stuff */ | |
3466 | 67 static void nap_write_packet(struct gaim_connection *gc, unsigned short command, const char *message) |
2086 | 68 { |
69 struct nap_data *ndata = (struct nap_data *)gc->proto_data; | |
70 unsigned short size; | |
71 | |
72 size = strlen(message); | |
2220
8b7ba25a7ece
[gaim-migrate @ 2230]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2205
diff
changeset
|
73 |
2086 | 74 write(ndata->fd, &size, 2); |
75 write(ndata->fd, &command, 2); | |
76 write(ndata->fd, message, size); | |
77 } | |
78 | |
3033 | 79 static int nap_send_im(struct gaim_connection *gc, char *who, char *message, int len, int flags) |
2086 | 80 { |
81 gchar buf[NAP_BUF_LEN]; | |
82 | |
83 g_snprintf(buf, NAP_BUF_LEN, "%s %s", who, message); | |
84 nap_write_packet(gc, 0xCD, buf); | |
2123
56c4382f2909
[gaim-migrate @ 2133]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2090
diff
changeset
|
85 |
2303
f5bf315e6104
[gaim-migrate @ 2313]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2231
diff
changeset
|
86 return 1; |
2086 | 87 } |
88 | |
89 static struct nap_channel *find_channel_by_name(struct gaim_connection *gc, char *name) | |
90 { | |
91 struct nap_channel *channel; | |
92 struct nap_data *ndata = (struct nap_data *)gc->proto_data; | |
93 GSList *channels; | |
94 | |
95 channels = ndata->channels; | |
96 | |
97 while (channels) { | |
98 channel = (struct nap_channel *)channels->data; | |
99 | |
100 if (channel) { | |
101 if (!g_strcasecmp(name, channel->name)) { | |
102 return channel; | |
103 } | |
104 } | |
105 channels = g_slist_next(channels); | |
106 } | |
107 | |
108 return NULL; | |
109 } | |
110 | |
111 static struct nap_channel *find_channel_by_id(struct gaim_connection *gc, int id) | |
112 { | |
113 struct nap_channel *channel; | |
114 struct nap_data *ndata = (struct nap_data *)gc->proto_data; | |
115 GSList *channels; | |
116 | |
117 channels = ndata->channels; | |
118 | |
119 while (channels) { | |
120 channel = (struct nap_channel *)channels->data; | |
121 if (id == channel->id) { | |
122 return channel; | |
123 } | |
124 | |
125 channels = g_slist_next(channels); | |
126 } | |
127 | |
128 return NULL; | |
129 } | |
130 | |
131 static struct conversation *find_conversation_by_id(struct gaim_connection *gc, int id) | |
132 { | |
133 GSList *bc = gc->buddy_chats; | |
134 struct conversation *b = NULL; | |
135 | |
136 while (bc) { | |
137 b = (struct conversation *)bc->data; | |
138 if (id == b->id) { | |
139 break; | |
140 } | |
141 bc = bc->next; | |
142 b = NULL; | |
143 } | |
144 | |
145 return b; | |
146 } | |
147 | |
2090
b66aca8e8dce
[gaim-migrate @ 2100]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
148 static void nap_callback(gpointer data, gint source, GaimInputCondition condition) |
2086 | 149 { |
150 struct gaim_connection *gc = data; | |
151 struct nap_data *ndata = gc->proto_data; | |
152 gchar *buf; | |
153 unsigned short header[2]; | |
154 int len; | |
155 int command; | |
156 gchar **res; | |
2220
8b7ba25a7ece
[gaim-migrate @ 2230]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2205
diff
changeset
|
157 int i; |
2086 | 158 |
2220
8b7ba25a7ece
[gaim-migrate @ 2230]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2205
diff
changeset
|
159 if (recv(source, header, 4, 0) != 4) { |
8b7ba25a7ece
[gaim-migrate @ 2230]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2205
diff
changeset
|
160 hide_login_progress(gc, "Unable to read"); |
8b7ba25a7ece
[gaim-migrate @ 2230]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2205
diff
changeset
|
161 signoff(gc); |
8b7ba25a7ece
[gaim-migrate @ 2230]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2205
diff
changeset
|
162 return; |
8b7ba25a7ece
[gaim-migrate @ 2230]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2205
diff
changeset
|
163 } |
8b7ba25a7ece
[gaim-migrate @ 2230]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2205
diff
changeset
|
164 |
2086 | 165 len = header[0]; |
166 command = header[1]; | |
167 | |
168 buf = (gchar *)g_malloc(sizeof(gchar) * (len + 1)); | |
169 | |
2220
8b7ba25a7ece
[gaim-migrate @ 2230]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2205
diff
changeset
|
170 i = 0; |
8b7ba25a7ece
[gaim-migrate @ 2230]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2205
diff
changeset
|
171 do { |
8b7ba25a7ece
[gaim-migrate @ 2230]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2205
diff
changeset
|
172 int tmp = recv(source, buf + i, len - i, 0); |
8b7ba25a7ece
[gaim-migrate @ 2230]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2205
diff
changeset
|
173 if (tmp <= 0) { |
8b7ba25a7ece
[gaim-migrate @ 2230]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2205
diff
changeset
|
174 g_free(buf); |
8b7ba25a7ece
[gaim-migrate @ 2230]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2205
diff
changeset
|
175 hide_login_progress(gc, "Unable to read"); |
8b7ba25a7ece
[gaim-migrate @ 2230]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2205
diff
changeset
|
176 signoff(gc); |
8b7ba25a7ece
[gaim-migrate @ 2230]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2205
diff
changeset
|
177 return; |
8b7ba25a7ece
[gaim-migrate @ 2230]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2205
diff
changeset
|
178 } |
8b7ba25a7ece
[gaim-migrate @ 2230]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2205
diff
changeset
|
179 i += tmp; |
8b7ba25a7ece
[gaim-migrate @ 2230]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2205
diff
changeset
|
180 } while (i != len); |
2086 | 181 |
182 buf[len] = 0; | |
183 | |
2220
8b7ba25a7ece
[gaim-migrate @ 2230]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2205
diff
changeset
|
184 debug_printf("DEBUG: %s\n", buf); |
2086 | 185 |
186 if (command == 0xd6) { | |
187 res = g_strsplit(buf, " ", 0); | |
188 /* Do we want to report what the users are doing? */ | |
189 printf("users: %s, files: %s, size: %sGB\n", res[0], res[1], res[2]); | |
190 g_strfreev(res); | |
2220
8b7ba25a7ece
[gaim-migrate @ 2230]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2205
diff
changeset
|
191 g_free(buf); |
2086 | 192 return; |
193 } | |
194 | |
195 if (command == 0x26d) { | |
196 /* Do we want to use the MOTD? */ | |
2220
8b7ba25a7ece
[gaim-migrate @ 2230]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2205
diff
changeset
|
197 g_free(buf); |
2086 | 198 return; |
199 } | |
200 | |
201 if (command == 0xCD) { | |
202 res = g_strsplit(buf, " ", 1); | |
2856
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2820
diff
changeset
|
203 serv_got_im(gc, res[0], res[1], 0, time(NULL), -1); |
2086 | 204 g_strfreev(res); |
2220
8b7ba25a7ece
[gaim-migrate @ 2230]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2205
diff
changeset
|
205 g_free(buf); |
2086 | 206 return; |
207 } | |
208 | |
209 if (command == 0x195) { | |
210 struct nap_channel *channel; | |
211 | |
212 channel = find_channel_by_name(gc, buf); | |
213 | |
214 if (!channel) { | |
215 chat_id++; | |
216 | |
217 channel = g_new0(struct nap_channel, 1); | |
218 | |
219 channel->id = chat_id; | |
220 channel->name = g_strdup(buf); | |
221 | |
222 ndata->channels = g_slist_append(ndata->channels, channel); | |
223 | |
224 serv_got_joined_chat(gc, chat_id, buf); | |
225 } | |
226 | |
2220
8b7ba25a7ece
[gaim-migrate @ 2230]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2205
diff
changeset
|
227 g_free(buf); |
2086 | 228 return; |
229 } | |
230 | |
231 if (command == 0x198 || command == 0x196) { | |
232 struct nap_channel *channel; | |
233 struct conversation *convo; | |
234 gchar **res; | |
235 | |
236 res = g_strsplit(buf, " ", 0); | |
237 | |
238 channel = find_channel_by_name(gc, res[0]); | |
239 convo = find_conversation_by_id(gc, channel->id); | |
240 | |
241 add_chat_buddy(convo, res[1]); | |
242 | |
243 g_strfreev(res); | |
244 | |
2220
8b7ba25a7ece
[gaim-migrate @ 2230]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2205
diff
changeset
|
245 g_free(buf); |
2086 | 246 return; |
247 } | |
248 | |
249 if (command == 0x197) { | |
250 struct nap_channel *channel; | |
251 struct conversation *convo; | |
252 gchar **res; | |
253 | |
254 res = g_strsplit(buf, " ", 0); | |
255 | |
256 channel = find_channel_by_name(gc, res[0]); | |
257 convo = find_conversation_by_id(gc, channel->id); | |
258 | |
2820
b917845dad3c
[gaim-migrate @ 2833]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2701
diff
changeset
|
259 remove_chat_buddy(convo, res[1], NULL); |
2086 | 260 |
261 g_strfreev(res); | |
2220
8b7ba25a7ece
[gaim-migrate @ 2230]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2205
diff
changeset
|
262 g_free(buf); |
2086 | 263 return; |
264 } | |
265 | |
266 if (command == 0x193) { | |
267 gchar **res; | |
268 struct nap_channel *channel; | |
269 | |
270 res = g_strsplit(buf, " ", 2); | |
271 | |
272 channel = find_channel_by_name(gc, res[0]); | |
273 | |
274 if (channel) | |
275 serv_got_chat_in(gc, channel->id, res[1], 0, res[2], time((time_t)NULL)); | |
276 | |
277 g_strfreev(res); | |
2220
8b7ba25a7ece
[gaim-migrate @ 2230]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2205
diff
changeset
|
278 g_free(buf); |
2086 | 279 return; |
280 } | |
281 | |
282 if (command == 0x194) { | |
3427 | 283 do_error_dialog(buf, NULL, GAIM_ERROR); |
2220
8b7ba25a7ece
[gaim-migrate @ 2230]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2205
diff
changeset
|
284 g_free(buf); |
2086 | 285 return; |
286 } | |
287 | |
288 if (command == 0x12e) { | |
289 gchar buf2[NAP_BUF_LEN]; | |
290 | |
3427 | 291 g_snprintf(buf2, NAP_BUF_LEN, "Unable to add '%s' to your Napster hotlist", buf); |
292 do_error_dialog(buf2, NULL, GAIM_ERROR); | |
2086 | 293 |
2220
8b7ba25a7ece
[gaim-migrate @ 2230]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2205
diff
changeset
|
294 g_free(buf); |
2086 | 295 return; |
296 | |
297 } | |
298 | |
299 if (command == 0x191) { | |
300 struct nap_channel *channel; | |
301 | |
302 channel = find_channel_by_name(gc, buf); | |
303 | |
304 if (!channel) /* I'm not sure how this would happen =) */ | |
305 return; | |
306 | |
307 serv_got_chat_left(gc, channel->id); | |
308 ndata->channels = g_slist_remove(ndata->channels, channel); | |
309 | |
2220
8b7ba25a7ece
[gaim-migrate @ 2230]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2205
diff
changeset
|
310 g_free(buf); |
2086 | 311 return; |
312 | |
313 } | |
314 | |
315 if (command == 0xd1) { | |
316 gchar **res; | |
317 | |
318 res = g_strsplit(buf, " ", 0); | |
319 | |
320 serv_got_update(gc, res[0], 1, 0, 0, 0, 0, 0); | |
321 | |
322 g_strfreev(res); | |
2220
8b7ba25a7ece
[gaim-migrate @ 2230]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2205
diff
changeset
|
323 g_free(buf); |
2086 | 324 return; |
325 } | |
326 | |
327 if (command == 0xd2) { | |
328 serv_got_update(gc, buf, 0, 0, 0, 0, 0, 0); | |
329 g_free(buf); | |
330 return; | |
331 } | |
332 | |
333 if (command == 0x12d) { | |
334 /* Our buddy was added successfully */ | |
2220
8b7ba25a7ece
[gaim-migrate @ 2230]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2205
diff
changeset
|
335 g_free(buf); |
2086 | 336 return; |
337 } | |
338 | |
339 if (command == 0x2ec) { | |
340 /* Looks like someone logged in as us! =-O */ | |
2220
8b7ba25a7ece
[gaim-migrate @ 2230]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2205
diff
changeset
|
341 g_free(buf); |
2086 | 342 |
343 signoff(gc); | |
344 return; | |
345 } | |
346 | |
2220
8b7ba25a7ece
[gaim-migrate @ 2230]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2205
diff
changeset
|
347 debug_printf("NAP: [COMMAND: 0x%04x] %s\n", command, buf); |
2086 | 348 |
2220
8b7ba25a7ece
[gaim-migrate @ 2230]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2205
diff
changeset
|
349 g_free(buf); |
2086 | 350 } |
351 | |
352 | |
2090
b66aca8e8dce
[gaim-migrate @ 2100]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
353 static void nap_login_callback(gpointer data, gint source, GaimInputCondition condition) |
2086 | 354 { |
355 struct gaim_connection *gc = data; | |
356 struct nap_data *ndata = gc->proto_data; | |
357 gchar buf[NAP_BUF_LEN]; | |
358 unsigned short header[2]; | |
359 int len; | |
360 int command; | |
361 | |
362 read(source, header, 4); | |
363 len = header[0]; | |
364 command = header[1]; | |
365 | |
366 read(source, buf, len); | |
367 buf[len] = 0; | |
368 | |
369 /* If we have some kind of error, get outta here */ | |
370 if (command == 0x00) | |
371 { | |
3427 | 372 do_error_dialog(buf, NULL, GAIM_ERROR); |
2090
b66aca8e8dce
[gaim-migrate @ 2100]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
373 gaim_input_remove(ndata->inpa); |
2086 | 374 ndata->inpa = 0; |
375 close(source); | |
376 signoff(gc); | |
377 return; | |
378 } | |
379 | |
380 if (command == 0x03) { | |
381 printf("Registered with E-Mail address of: %s\n", buf); | |
382 ndata->email = g_strdup(buf); | |
383 | |
384 /* Remove old inpa, add new one */ | |
2090
b66aca8e8dce
[gaim-migrate @ 2100]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
385 gaim_input_remove(ndata->inpa); |
2086 | 386 ndata->inpa = 0; |
2090
b66aca8e8dce
[gaim-migrate @ 2100]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
387 gc->inpa = gaim_input_add(ndata->fd, GAIM_INPUT_READ, nap_callback, gc); |
2086 | 388 |
389 /* Our signon is complete */ | |
390 account_online(gc); | |
391 serv_finish_login(gc); | |
392 | |
393 if (bud_list_cache_exists(gc)) | |
2382
569ae9f2bb89
[gaim-migrate @ 2395]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2309
diff
changeset
|
394 do_import(gc, NULL); |
2086 | 395 |
396 return; | |
397 } | |
398 } | |
399 | |
400 | |
2090
b66aca8e8dce
[gaim-migrate @ 2100]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
401 static void nap_login_connect(gpointer data, gint source, GaimInputCondition cond) |
2086 | 402 { |
403 struct gaim_connection *gc = data; | |
2701
8a84f2bb1716
[gaim-migrate @ 2714]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
404 struct nap_data *ndata; |
2086 | 405 char buf[NAP_BUF_LEN]; |
406 | |
2701
8a84f2bb1716
[gaim-migrate @ 2714]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
407 if (!g_slist_find(connections, gc)) { |
8a84f2bb1716
[gaim-migrate @ 2714]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
408 close(source); |
8a84f2bb1716
[gaim-migrate @ 2714]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
409 return; |
8a84f2bb1716
[gaim-migrate @ 2714]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
410 } |
8a84f2bb1716
[gaim-migrate @ 2714]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
411 |
2086 | 412 if (source < 0) { |
413 hide_login_progress(gc, "Unable to connect"); | |
414 signoff(gc); | |
415 return; | |
416 } | |
417 | |
2701
8a84f2bb1716
[gaim-migrate @ 2714]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
418 ndata = gc->proto_data; |
2086 | 419 if (ndata->fd != source) |
420 ndata->fd = source; | |
421 | |
422 /* And write our signon data */ | |
423 g_snprintf(buf, NAP_BUF_LEN, "%s %s 0 \"gaimster\" 0", gc->username, gc->password); | |
424 nap_write_packet(gc, 0x02, buf); | |
425 | |
426 /* And set up the input watcher */ | |
2090
b66aca8e8dce
[gaim-migrate @ 2100]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
427 ndata->inpa = gaim_input_add(ndata->fd, GAIM_INPUT_READ, nap_login_callback, gc); |
2086 | 428 } |
429 | |
430 | |
431 static void nap_login(struct aim_user *user) | |
432 { | |
433 struct gaim_connection *gc = new_gaim_conn(user); | |
434 struct nap_data *ndata = gc->proto_data = g_new0(struct nap_data, 1); | |
435 | |
3322 | 436 ndata->fd = proxy_connect(user->proto_opt[USEROPT_NAPSERVER][0] ? user->proto_opt[USEROPT_NAPSERVER] : NAP_SERVER, |
437 user->proto_opt[USEROPT_NAPPORT][0] ? atoi(user->proto_opt[USEROPT_NAPPORT]) : NAP_PORT, | |
438 nap_login_connect, gc); | |
2086 | 439 if (ndata->fd < 0) { |
440 hide_login_progress(gc, "Unable to connect"); | |
441 signoff(gc); | |
442 } | |
443 } | |
444 | |
2205
cff4fbe01c7b
[gaim-migrate @ 2215]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2170
diff
changeset
|
445 static GList *nap_chat_info(struct gaim_connection *gc) |
cff4fbe01c7b
[gaim-migrate @ 2215]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2170
diff
changeset
|
446 { |
cff4fbe01c7b
[gaim-migrate @ 2215]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2170
diff
changeset
|
447 GList *m = NULL; |
cff4fbe01c7b
[gaim-migrate @ 2215]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2170
diff
changeset
|
448 struct proto_chat_entry *pce; |
cff4fbe01c7b
[gaim-migrate @ 2215]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2170
diff
changeset
|
449 |
cff4fbe01c7b
[gaim-migrate @ 2215]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2170
diff
changeset
|
450 pce = g_new0(struct proto_chat_entry, 1); |
cff4fbe01c7b
[gaim-migrate @ 2215]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2170
diff
changeset
|
451 pce->label = _("Join what group:"); |
cff4fbe01c7b
[gaim-migrate @ 2215]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2170
diff
changeset
|
452 m = g_list_append(m, pce); |
cff4fbe01c7b
[gaim-migrate @ 2215]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2170
diff
changeset
|
453 |
cff4fbe01c7b
[gaim-migrate @ 2215]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2170
diff
changeset
|
454 return m; |
cff4fbe01c7b
[gaim-migrate @ 2215]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2170
diff
changeset
|
455 } |
cff4fbe01c7b
[gaim-migrate @ 2215]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2170
diff
changeset
|
456 |
cff4fbe01c7b
[gaim-migrate @ 2215]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2170
diff
changeset
|
457 static void nap_join_chat(struct gaim_connection *gc, GList *data) |
2086 | 458 { |
459 gchar buf[NAP_BUF_LEN]; | |
2205
cff4fbe01c7b
[gaim-migrate @ 2215]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2170
diff
changeset
|
460 char *name; |
cff4fbe01c7b
[gaim-migrate @ 2215]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2170
diff
changeset
|
461 |
cff4fbe01c7b
[gaim-migrate @ 2215]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2170
diff
changeset
|
462 if (!data) |
cff4fbe01c7b
[gaim-migrate @ 2215]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2170
diff
changeset
|
463 return; |
cff4fbe01c7b
[gaim-migrate @ 2215]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2170
diff
changeset
|
464 |
cff4fbe01c7b
[gaim-migrate @ 2215]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2170
diff
changeset
|
465 name = data->data; |
2086 | 466 |
467 /* Make sure the name has a # preceeding it */ | |
468 if (name[0] != '#') | |
469 g_snprintf(buf, NAP_BUF_LEN, "#%s", name); | |
470 else | |
471 g_snprintf(buf, NAP_BUF_LEN, "%s", name); | |
472 | |
473 nap_write_packet(gc, 0x190, buf); | |
474 } | |
475 | |
476 static void nap_chat_leave(struct gaim_connection *gc, int id) | |
477 { | |
478 struct nap_data *ndata = (struct nap_data *)gc->proto_data; | |
479 struct nap_channel *channel = NULL; | |
480 | |
481 channel = find_channel_by_id(gc, id); | |
482 | |
483 if (!channel) /* Again, I'm not sure how this would happen */ | |
484 return; | |
485 | |
486 nap_write_packet(gc, 0x191, channel->name); | |
487 | |
488 ndata->channels = g_slist_remove(ndata->channels, channel); | |
489 g_free(channel->name); | |
490 g_free(channel); | |
491 | |
492 } | |
493 | |
2167
edf8c5a70e5b
[gaim-migrate @ 2177]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2162
diff
changeset
|
494 static int nap_chat_send(struct gaim_connection *gc, int id, char *message) |
2086 | 495 { |
496 struct nap_channel *channel = NULL; | |
497 gchar buf[NAP_BUF_LEN]; | |
498 | |
499 channel = find_channel_by_id(gc, id); | |
500 | |
501 if (!channel) { | |
502 /* This shouldn't happen */ | |
2167
edf8c5a70e5b
[gaim-migrate @ 2177]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2162
diff
changeset
|
503 return -EINVAL; |
2086 | 504 } |
505 | |
506 g_snprintf(buf, NAP_BUF_LEN, "%s %s", channel->name, message); | |
507 nap_write_packet(gc, 0x192, buf); | |
2167
edf8c5a70e5b
[gaim-migrate @ 2177]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2162
diff
changeset
|
508 return 0; |
2086 | 509 } |
510 | |
3466 | 511 static void nap_add_buddy(struct gaim_connection *gc, const char *name) |
2086 | 512 { |
513 nap_write_packet(gc, 0xCF, name); | |
514 } | |
515 | |
2681
37d80035e77f
[gaim-migrate @ 2694]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2382
diff
changeset
|
516 static void nap_remove_buddy(struct gaim_connection *gc, char *name, char *group) |
2086 | 517 { |
518 nap_write_packet(gc, 0x12F, name); | |
519 } | |
520 | |
521 static void nap_close(struct gaim_connection *gc) | |
522 { | |
523 struct nap_data *ndata = (struct nap_data *)gc->proto_data; | |
524 struct nap_channel *channel; | |
525 | |
526 if (gc->inpa) | |
2090
b66aca8e8dce
[gaim-migrate @ 2100]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
527 gaim_input_remove(gc->inpa); |
2086 | 528 |
529 while (ndata->channels) { | |
530 channel = (struct nap_channel *)ndata->channels->data; | |
531 g_free(channel->name); | |
532 ndata->channels = g_slist_remove(ndata->channels, channel); | |
533 g_free(channel); | |
534 } | |
535 | |
2220
8b7ba25a7ece
[gaim-migrate @ 2230]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2205
diff
changeset
|
536 g_free(gc->proto_data); |
2086 | 537 } |
538 | |
539 static void nap_add_buddies(struct gaim_connection *gc, GList *buddies) | |
540 { | |
541 while (buddies) { | |
542 nap_write_packet(gc, 0xd0, (char *)buddies->data); | |
543 buddies = buddies -> next; | |
544 } | |
545 } | |
546 | |
547 static char** nap_list_icon(int uc) | |
548 { | |
549 return napster_xpm; | |
550 } | |
551 | |
552 static struct prpl *my_protocol = NULL; | |
553 | |
554 void napster_init(struct prpl *ret) | |
555 { | |
3572 | 556 struct proto_user_opt *puo; |
557 ret->add_buddies = nap_add_buddies; | |
558 ret->remove_buddy = nap_remove_buddy; | |
559 ret->add_permit = NULL; | |
560 ret->rem_permit = NULL; | |
561 ret->add_deny = NULL; | |
562 ret->rem_deny = NULL; | |
563 ret->warn = NULL; | |
564 ret->chat_info = nap_chat_info; | |
565 ret->join_chat = nap_join_chat; | |
566 ret->chat_invite = NULL; | |
567 ret->chat_leave = nap_chat_leave; | |
568 ret->chat_whisper = NULL; | |
569 ret->chat_send = nap_chat_send; | |
570 ret->keepalive = NULL; | |
2086 | 571 ret->protocol = PROTO_NAPSTER; |
3572 | 572 ret->name = g_strdup("Napster"); |
2086 | 573 ret->list_icon = nap_list_icon; |
574 ret->login = nap_login; | |
575 ret->close = nap_close; | |
576 ret->send_im = nap_send_im; | |
577 ret->set_info = NULL; | |
578 ret->get_info = NULL; | |
579 ret->set_away = NULL; | |
580 ret->set_dir = NULL; | |
581 ret->get_dir = NULL; | |
582 ret->dir_search = NULL; | |
583 ret->set_idle = NULL; | |
584 ret->change_passwd = NULL; | |
585 ret->add_buddy = nap_add_buddy; | |
586 ret->add_buddies = nap_add_buddies; | |
587 ret->remove_buddy = nap_remove_buddy; | |
588 ret->add_permit = NULL; | |
589 ret->rem_permit = NULL; | |
590 ret->add_deny = NULL; | |
591 ret->rem_deny = NULL; | |
592 ret->warn = NULL; | |
2205
cff4fbe01c7b
[gaim-migrate @ 2215]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2170
diff
changeset
|
593 ret->chat_info = nap_chat_info; |
2086 | 594 ret->join_chat = nap_join_chat; |
595 ret->chat_invite = NULL; | |
596 ret->chat_leave = nap_chat_leave; | |
597 ret->chat_whisper = NULL; | |
598 ret->chat_send = nap_chat_send; | |
599 ret->keepalive = NULL; | |
600 | |
3572 | 601 puo = g_new0(struct proto_user_opt, 1); |
602 puo->label = g_strdup("Server:"); | |
603 puo->def = g_strdup(NAP_SERVER); | |
604 puo->pos = USEROPT_NAPSERVER; | |
605 ret->user_opts = g_list_append(ret->user_opts, puo); | |
606 | |
607 puo = g_new0(struct proto_user_opt, 1); | |
608 puo->label = g_strdup("Port:"); | |
609 puo->def = g_strdup("8888"); | |
610 puo->pos = USEROPT_NAPPORT; | |
611 ret->user_opts = g_list_append(ret->user_opts, puo); | |
612 | |
2086 | 613 my_protocol = ret; |
614 } | |
615 | |
616 #ifndef STATIC | |
617 | |
3572 | 618 void *gaim_prpl_init(struct prpl *prpl) |
2086 | 619 { |
3572 | 620 napster_init(prpl); |
621 prpl->plug->desc.api_version = PLUGIN_API_VERSION; | |
2086 | 622 } |
623 #endif |