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