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