Mercurial > pidgin.yaz
annotate plugins/napster.c @ 1999:591ebfe8ec00
[gaim-migrate @ 2009]
can be in two rooms of the same name
committer: Tailor Script <tailor@pidgin.im>
| author | Eric Warmenhoven <eric@warmenhoven.org> |
|---|---|
| date | Tue, 12 Jun 2001 07:57:27 +0000 |
| parents | c9c20663e05b |
| children |
| rev | line source |
|---|---|
| 1323 | 1 /* |
| 2 * gaim - Napster Protocol Plugin | |
| 3 * | |
| 1672 | 4 * Copyright (C) 2000-2001, Rob Flynn <rob@tgflinux.com> |
| 1323 | 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 | |
| 22 #include "../config.h" | |
| 23 | |
| 24 #include <netdb.h> | |
| 25 #include <gtk/gtk.h> | |
| 26 #include <unistd.h> | |
| 27 #include <errno.h> | |
| 28 #include <netinet/in.h> | |
| 29 #include <arpa/inet.h> | |
| 30 #include <time.h> | |
| 31 #include <string.h> | |
| 32 #include <stdlib.h> | |
| 33 #include <stdio.h> | |
| 34 #include <time.h> | |
| 35 #include <sys/socket.h> | |
| 36 #include <sys/stat.h> | |
| 1422 | 37 #include <sys/types.h> |
| 38 #include <fcntl.h> | |
| 39 #include <ctype.h> | |
| 1323 | 40 #include "multi.h" |
| 41 #include "prpl.h" | |
| 42 #include "gaim.h" | |
|
1873
08ac51210d09
[gaim-migrate @ 1883]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1764
diff
changeset
|
43 #include "proxy.h" |
| 1327 | 44 #include "pixmaps/napster.xpm" |
| 1323 | 45 |
| 46 #define NAP_BUF_LEN 4096 | |
| 47 | |
| 48 GSList *nap_connections = NULL; | |
| 49 | |
| 50 static unsigned int chat_id = 0; | |
| 51 | |
| 1427 | 52 struct search_window { |
| 53 GtkWidget *window; | |
| 54 GtkWidget *list; | |
| 55 }; | |
| 56 | |
| 1422 | 57 struct browse_window { |
| 58 GtkWidget *window; | |
| 59 GtkWidget *list; | |
| 60 struct gaim_connection *gc; | |
| 61 char *name; | |
| 62 }; | |
| 63 | |
| 64 struct nap_download_box { | |
| 65 GtkWidget *window; | |
| 66 GtkWidget *ok; | |
| 67 GtkWidget *entry; | |
| 68 gchar *who; | |
| 69 }; | |
| 70 | |
| 1323 | 71 struct nap_channel { |
| 72 unsigned int id; | |
| 73 gchar *name; | |
| 74 }; | |
| 75 | |
| 1422 | 76 struct nap_file_request { |
| 77 gchar *name; | |
| 78 gchar *file; | |
| 79 int fd; | |
| 80 long size; | |
| 81 long total; | |
| 82 int status; | |
| 83 int inpa; | |
| 84 FILE *mp3; | |
| 1444 | 85 GtkWidget *window; |
| 86 GtkWidget *progress; | |
| 87 GtkWidget *ok; | |
| 88 GtkWidget *cancel; | |
|
1873
08ac51210d09
[gaim-migrate @ 1883]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1764
diff
changeset
|
89 struct gaim_connection *gc; |
| 1422 | 90 }; |
| 91 | |
| 1323 | 92 struct nap_data { |
| 93 int fd; | |
| 94 int inpa; | |
| 95 | |
| 96 gchar *email; | |
| 97 GSList *channels; | |
| 1422 | 98 GSList *requests; |
| 99 GSList *browses; | |
| 1323 | 100 }; |
| 101 | |
| 1427 | 102 static struct search_window *search_dialog = NULL; |
| 103 | |
| 1323 | 104 static char *nap_name() |
| 105 { | |
| 106 return "Napster"; | |
| 107 } | |
| 108 | |
| 109 char *name() | |
| 110 { | |
| 111 return "Napster"; | |
| 112 } | |
| 113 | |
| 114 char *description() | |
| 115 { | |
| 116 return "Allows gaim to use the Napster protocol. Yes, kids, drugs are bad."; | |
| 117 } | |
| 118 | |
| 119 | |
| 120 /* FIXME: Make this use va_arg stuff */ | |
|
1873
08ac51210d09
[gaim-migrate @ 1883]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1764
diff
changeset
|
121 static void nap_write_packet(struct gaim_connection *gc, unsigned short command, char *message) |
| 1323 | 122 { |
| 123 struct nap_data *ndata = (struct nap_data *)gc->proto_data; | |
| 124 unsigned short size; | |
| 125 | |
| 126 size = strlen(message); | |
| 127 write(ndata->fd, &size, 2); | |
| 128 write(ndata->fd, &command, 2); | |
| 129 write(ndata->fd, message, size); | |
| 1444 | 130 |
| 1323 | 131 } |
| 132 | |
|
1873
08ac51210d09
[gaim-migrate @ 1883]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1764
diff
changeset
|
133 static void nap_send_download_req(struct gaim_connection *gc, char *who, char *file) |
| 1422 | 134 { |
| 135 struct nap_data *ndata = (struct nap_data *)gc->proto_data; | |
| 136 gchar buf[NAP_BUF_LEN]; | |
| 137 | |
| 138 g_snprintf(buf, NAP_BUF_LEN, "%s \"%s\"", who, file); | |
| 139 | |
| 1427 | 140 printf("%s\n", buf); |
| 141 printf("%d\n", ndata->fd); | |
| 1422 | 142 nap_write_packet(gc, 0xCB, buf); |
| 143 } | |
| 144 | |
| 1427 | 145 // FIXME: These next two windows should really be together |
| 146 // and should use the same clist style look too. | |
| 147 | |
|
1873
08ac51210d09
[gaim-migrate @ 1883]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1764
diff
changeset
|
148 static void nap_handle_download(GtkCList *clist, gint row, gint col, GdkEventButton *event, gpointer user_data) |
| 1422 | 149 { |
|
1873
08ac51210d09
[gaim-migrate @ 1883]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1764
diff
changeset
|
150 gchar *results; |
| 1422 | 151 struct browse_window *bw = (struct browse_window *)user_data; |
| 152 | |
|
1873
08ac51210d09
[gaim-migrate @ 1883]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1764
diff
changeset
|
153 gtk_clist_get_text(GTK_CLIST(clist), row, 0, &results); |
| 1422 | 154 |
|
1873
08ac51210d09
[gaim-migrate @ 1883]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1764
diff
changeset
|
155 nap_send_download_req(bw->gc, bw->name, results); |
| 1422 | 156 |
| 157 } | |
| 158 | |
|
1873
08ac51210d09
[gaim-migrate @ 1883]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1764
diff
changeset
|
159 static void nap_handle_download_search(GtkCList *clist, gint row, gint col, GdkEventButton *event, gpointer user_data) |
| 1427 | 160 { |
| 161 gchar *filename; | |
| 162 gchar *nick; | |
| 163 | |
| 164 struct gaim_connection *gc = (struct gaim_connection *)user_data; | |
| 165 | |
| 166 filename = (gchar *)gtk_clist_get_row_data(GTK_CLIST(clist), row); | |
| 167 | |
| 168 gtk_clist_get_text(GTK_CLIST(clist), row, 1, &nick); | |
| 169 | |
| 170 printf("Trying to download: %s from %s\n", filename, nick); | |
| 171 nap_send_download_req(gc, nick, filename); | |
| 172 } | |
| 173 | |
|
1873
08ac51210d09
[gaim-migrate @ 1883]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1764
diff
changeset
|
174 static struct browse_window *browse_window_new(struct gaim_connection *gc, char *name) |
| 1422 | 175 { |
| 176 struct browse_window *browse = g_new0(struct browse_window, 1); | |
| 177 struct nap_data *ndata = (struct nap_data *)gc->proto_data; | |
| 178 | |
|
1956
c9c20663e05b
[gaim-migrate @ 1966]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1943
diff
changeset
|
179 browse->window = gtk_window_new(GTK_WINDOW_DIALOG); |
| 1422 | 180 browse->name = g_strdup(name); |
| 181 browse->list = gtk_clist_new(1); | |
| 182 browse->gc = gc; | |
| 183 | |
| 184 gtk_widget_show(browse->list); | |
| 185 gtk_container_add(GTK_CONTAINER(browse->window), browse->list); | |
| 186 | |
| 187 gtk_widget_set_usize(GTK_WIDGET(browse->window), 300, 250); | |
| 188 gtk_widget_show(browse->window); | |
| 189 | |
| 190 /*FIXME: I dont like using select-row. Im lazy. Ill fix it later */ | |
| 191 gtk_signal_connect(GTK_OBJECT(browse->list), "select-row", GTK_SIGNAL_FUNC(nap_handle_download), browse); | |
| 192 | |
| 193 ndata->browses = g_slist_append(ndata->browses, browse); | |
|
1873
08ac51210d09
[gaim-migrate @ 1883]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1764
diff
changeset
|
194 |
|
08ac51210d09
[gaim-migrate @ 1883]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1764
diff
changeset
|
195 return browse; |
| 1422 | 196 } |
| 197 | |
|
1873
08ac51210d09
[gaim-migrate @ 1883]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1764
diff
changeset
|
198 static void browse_window_add_file(struct browse_window *bw, char *name) |
| 1422 | 199 { |
| 200 char *fn[1]; | |
| 201 fn[0] = strdup(name); | |
| 202 printf("User '%s' has file '%s'\n", bw->name, name); | |
| 203 gtk_clist_append(GTK_CLIST(bw->list), fn); | |
| 204 | |
| 205 free(fn[0]); | |
| 206 } | |
| 207 | |
| 208 static struct browse_window *find_browse_window_by_name(struct gaim_connection *gc, char *name) | |
| 209 { | |
| 210 struct browse_window *browse; | |
| 211 struct nap_data *ndata = (struct nap_data *)gc->proto_data; | |
| 212 GSList *browses; | |
| 213 | |
| 214 browses = ndata->browses; | |
| 215 | |
| 216 while (browses) { | |
| 217 browse = (struct browse_window *)browses->data; | |
| 218 | |
| 219 if (browse) { | |
| 220 if (!g_strcasecmp(name, browse->name)) { | |
| 221 return browse; | |
| 222 } | |
| 223 } | |
| 224 browses = g_slist_next(browses); | |
| 225 } | |
| 226 | |
| 227 return NULL; | |
| 228 } | |
| 229 | |
| 1323 | 230 static void nap_send_im(struct gaim_connection *gc, char *who, char *message, int away) |
| 231 { | |
| 232 gchar buf[NAP_BUF_LEN]; | |
| 233 | |
| 234 g_snprintf(buf, NAP_BUF_LEN, "%s %s", who, message); | |
| 235 nap_write_packet(gc, 0xCD, buf); | |
| 236 } | |
| 237 | |
| 238 static struct nap_channel *find_channel_by_name(struct gaim_connection *gc, char *name) | |
| 239 { | |
| 240 struct nap_channel *channel; | |
| 241 struct nap_data *ndata = (struct nap_data *)gc->proto_data; | |
| 242 GSList *channels; | |
| 243 | |
| 244 channels = ndata->channels; | |
| 245 | |
| 246 while (channels) { | |
| 247 channel = (struct nap_channel *)channels->data; | |
| 1325 | 248 |
| 249 if (channel) { | |
| 250 if (!g_strcasecmp(name, channel->name)) { | |
| 251 return channel; | |
| 252 } | |
| 1323 | 253 } |
| 254 channels = g_slist_next(channels); | |
| 255 } | |
| 256 | |
| 257 return NULL; | |
| 258 } | |
| 259 | |
| 260 static struct nap_channel *find_channel_by_id(struct gaim_connection *gc, int id) | |
| 261 { | |
| 262 struct nap_channel *channel; | |
| 263 struct nap_data *ndata = (struct nap_data *)gc->proto_data; | |
| 264 GSList *channels; | |
| 265 | |
| 266 channels = ndata->channels; | |
| 267 | |
| 268 while (channels) { | |
| 269 channel = (struct nap_channel *)channels->data; | |
| 270 if (id == channel->id) { | |
| 271 return channel; | |
| 272 } | |
| 273 | |
| 274 channels = g_slist_next(channels); | |
| 275 } | |
| 276 | |
| 277 return NULL; | |
| 278 } | |
| 279 | |
| 280 static struct conversation *find_conversation_by_id(struct gaim_connection *gc, int id) | |
| 281 { | |
| 282 GSList *bc = gc->buddy_chats; | |
| 283 struct conversation *b = NULL; | |
| 284 | |
| 285 while (bc) { | |
| 286 b = (struct conversation *)bc->data; | |
| 287 if (id == b->id) { | |
| 288 break; | |
| 289 } | |
| 290 bc = bc->next; | |
| 291 b = NULL; | |
| 292 } | |
| 293 | |
| 294 return b; | |
| 295 } | |
| 296 | |
| 1422 | 297 /* This is a strange function. I smoke too many bad bad things :-) */ |
|
1873
08ac51210d09
[gaim-migrate @ 1883]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1764
diff
changeset
|
298 static struct nap_file_request * find_request_by_fd(struct gaim_connection *gc, int fd) |
| 1422 | 299 { |
| 300 struct nap_file_request *req; | |
| 301 struct nap_data *ndata = (struct nap_data *)gc->proto_data; | |
| 302 GSList *requests; | |
| 303 | |
| 304 requests = ndata->requests; | |
| 305 | |
| 306 while (requests) { | |
| 307 req = (struct nap_file_request *)requests->data; | |
| 308 | |
| 309 if (req) { | |
| 310 if (req->fd == fd) | |
| 311 return req; | |
| 312 } | |
| 313 requests = g_slist_next(requests); | |
| 314 } | |
| 315 | |
| 316 return NULL; | |
| 317 } | |
| 318 | |
| 319 static void nap_ctc_callback(gpointer data, gint source, GdkInputCondition condition) | |
| 320 { | |
| 321 struct gaim_connection *gc = (struct gaim_connection *)data; | |
| 322 struct nap_data *ndata = (struct nap_data *)gc->proto_data; | |
| 323 struct nap_file_request *req; | |
| 324 unsigned char *buf; | |
| 325 int i = 0; | |
| 326 | |
| 327 req = find_request_by_fd(gc, source); | |
| 328 if (!req) /* Something bad happened */ | |
| 329 return; | |
| 330 | |
| 331 buf = (char *)malloc(sizeof(char) * (NAP_BUF_LEN + 1)); | |
| 332 | |
| 333 if (req->status == 0) | |
| 334 { | |
| 335 int j; | |
| 336 gchar tmp[32]; | |
| 337 long filesize; | |
| 338 gchar **parse_name; | |
| 339 gchar path[2048]; | |
| 1444 | 340 GtkWidget *hbox; |
| 341 GtkWidget *vbox; | |
| 342 GtkWidget *label; | |
| 343 gchar *buf2; | |
| 1422 | 344 |
| 345 recv(source, buf, 1, 0); | |
| 346 | |
| 347 /* We should receive a '1' upon connection */ | |
| 348 if (buf[0] != '1') | |
| 349 { | |
| 350 do_error_dialog("Uh Oh", "Uh Oh"); | |
| 351 gdk_input_remove(req->inpa); | |
| 352 ndata->requests = g_slist_remove(ndata->requests, req); | |
| 353 g_free(req->name); | |
| 354 g_free(req->file); | |
| 355 close(source); | |
| 356 g_free(req); | |
| 357 free(buf); | |
| 358 return; | |
| 359 } | |
| 360 | |
| 361 /* Lets take a peek at the awaiting data */ | |
| 362 i = recv(source, buf, NAP_BUF_LEN, MSG_PEEK); | |
| 363 buf[i] = 0; /* Make sure that we terminate our string */ | |
| 364 | |
| 365 /* Looks like the uploader sent the proper data. Let's see how big the | |
| 366 * file is */ | |
| 367 | |
| 368 for (j = 0, i = 0; isdigit(buf[i]); i++, j++) | |
| 369 { | |
| 370 tmp[j] = buf[i]; | |
| 371 } | |
| 372 tmp[j] = 0; | |
| 373 filesize = atol(tmp); | |
| 374 | |
| 375 /* Save the size of the file */ | |
| 376 req->total = filesize; | |
| 377 | |
| 378 /* If we have a zero file size then something bad happened */ | |
| 379 if (filesize == 0) { | |
| 380 gdk_input_remove(req->inpa); | |
| 381 ndata->requests = g_slist_remove(ndata->requests, req); | |
| 382 g_free(req->name); | |
| 383 g_free(req->file); | |
| 384 g_free(req); | |
| 385 free(buf); | |
| 386 close(source); | |
| 387 return; | |
| 388 } | |
| 389 | |
| 390 /* Now that we've done that, let's go ahead and read that | |
| 391 * data to get it out of the way */ | |
| 392 recv(source, buf, strlen(tmp), 0); | |
| 393 | |
| 394 /* Now, we should tell the server that we're download something */ | |
| 395 nap_write_packet(gc, 0xda, "\n"); | |
| 396 | |
| 397 req->status = 1; | |
| 398 | |
| 399 /* FIXME: We dont want to force the file name. I'll parse this | |
| 400 * later */ | |
| 401 | |
| 402 parse_name = g_strsplit(req->file, "\\", 0); | |
| 403 g_snprintf(path, sizeof(path), "%s/%s", getenv("HOME"), parse_name[sizeof(parse_name)]); | |
| 404 printf("Gonna try to save to: %s\n", path); | |
| 405 g_strfreev(parse_name); | |
| 406 | |
| 407 req->mp3 = fopen(path, "w"); | |
| 1444 | 408 |
| 409 req->window = gtk_window_new(GTK_WINDOW_TOPLEVEL); | |
| 410 | |
| 411 vbox = gtk_vbox_new(FALSE, 5); | |
| 412 | |
| 413 buf2 = (gchar *)g_malloc(sizeof(gchar) * (strlen(req->file) + 33)); | |
| 414 g_snprintf(buf2, strlen(req->file) + 32, "Downloading File: %s", req->file); | |
| 415 label = gtk_label_new(buf2); | |
| 416 gtk_box_pack_start(GTK_BOX(vbox), label, FALSE, FALSE, 5); | |
| 417 | |
| 418 req->progress = gtk_progress_bar_new(); | |
| 419 gtk_progress_bar_update(GTK_PROGRESS_BAR(req->progress), 0); | |
| 1494 | 420 gtk_progress_configure(GTK_PROGRESS(req->progress), 0, 0, (float)req->total/(float)1024); |
| 421 gtk_progress_set_format_string(GTK_PROGRESS(req->progress), "%P%% (%VKB / %UKB)"); | |
| 1444 | 422 gtk_progress_set_show_text(GTK_PROGRESS(req->progress), TRUE); |
| 423 gtk_box_pack_start(GTK_BOX(vbox), req->progress, FALSE, FALSE, 5); | |
| 424 | |
| 425 hbox = gtk_hbox_new(TRUE, 5); | |
| 426 | |
| 427 req->ok = gtk_button_new_with_label("Ok"); | |
| 428 req->cancel = gtk_button_new_with_label("Cancel"); | |
| 429 | |
| 430 gtk_box_pack_end(GTK_BOX(hbox), req->cancel, FALSE, FALSE, 5); | |
| 431 gtk_box_pack_end(GTK_BOX(hbox), req->ok, FALSE, FALSE, 5); | |
| 432 | |
| 433 gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, 5); | |
| 434 | |
| 435 gtk_container_add(GTK_CONTAINER(req->window), vbox); | |
| 436 | |
| 437 gtk_widget_show_all(req->window); | |
| 438 | |
| 1422 | 439 free(buf); |
| 440 return; | |
| 441 } | |
| 442 | |
| 443 /* Looks like our status isn't 1. It's safe to assume we're downloadin' */ | |
| 444 i = recv(source, buf, NAP_BUF_LEN, 0); | |
| 445 | |
| 446 req->size += i; /* Lets add up the total */ | |
| 447 | |
| 1444 | 448 // printf("Downloaded %ld of %ld (%f)\n", req->size, req->total, (float)req->size/(float)req->total); |
| 449 | |
| 450 gtk_progress_bar_update(GTK_PROGRESS_BAR(req->progress), (float)req->size/(float)req->total); | |
| 451 | |
| 452 while (gtk_events_pending()) | |
| 453 gtk_main_iteration(); | |
| 1422 | 454 |
| 455 fwrite(buf, i, sizeof(char), req->mp3); | |
| 456 | |
| 457 free(buf); | |
| 458 | |
| 459 if (req->size >= req->total) { | |
| 460 printf("Download complete.\n"); | |
| 461 nap_write_packet(gc, 0xdb, "\n"); /* Tell the server we're finished */ | |
| 462 gdk_input_remove(req->inpa); | |
| 1444 | 463 |
| 1422 | 464 ndata->requests = g_slist_remove(ndata->requests, req); |
| 1444 | 465 |
| 466 if (req->name != NULL) | |
| 467 g_free(req->name); | |
| 468 | |
| 469 if (req->file != NULL) | |
| 470 g_free(req->file); | |
| 471 | |
| 1422 | 472 g_free(req); |
| 473 fclose(req->mp3); | |
| 474 close(source); | |
| 475 } | |
| 476 } | |
| 477 | |
|
1873
08ac51210d09
[gaim-migrate @ 1883]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1764
diff
changeset
|
478 static void nap_get_file_connect(gpointer data, gint source, GdkInputCondition cond) |
| 1422 | 479 { |
| 480 char buf[NAP_BUF_LEN]; | |
|
1873
08ac51210d09
[gaim-migrate @ 1883]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1764
diff
changeset
|
481 struct nap_file_request *req = data; |
|
08ac51210d09
[gaim-migrate @ 1883]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1764
diff
changeset
|
482 struct gaim_connection *gc = req->gc; |
| 1422 | 483 struct nap_data *ndata = (struct nap_data *)gc->proto_data; |
| 484 | |
|
1873
08ac51210d09
[gaim-migrate @ 1883]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1764
diff
changeset
|
485 if (source < 0) { |
| 1422 | 486 do_error_dialog("Error connecting to user", "Gaim: Napster error"); |
|
1873
08ac51210d09
[gaim-migrate @ 1883]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1764
diff
changeset
|
487 g_free(req->name); |
|
08ac51210d09
[gaim-migrate @ 1883]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1764
diff
changeset
|
488 g_free(req->file); |
|
08ac51210d09
[gaim-migrate @ 1883]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1764
diff
changeset
|
489 g_free(req); |
| 1422 | 490 return; |
| 491 } | |
| 492 | |
|
1873
08ac51210d09
[gaim-migrate @ 1883]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1764
diff
changeset
|
493 if (req->fd != source) |
|
08ac51210d09
[gaim-migrate @ 1883]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1764
diff
changeset
|
494 req->fd = source; |
|
08ac51210d09
[gaim-migrate @ 1883]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1764
diff
changeset
|
495 |
|
08ac51210d09
[gaim-migrate @ 1883]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1764
diff
changeset
|
496 send(req->fd, "GET", 3, 0); |
|
08ac51210d09
[gaim-migrate @ 1883]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1764
diff
changeset
|
497 |
|
08ac51210d09
[gaim-migrate @ 1883]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1764
diff
changeset
|
498 /* Send our request to the user */ |
|
08ac51210d09
[gaim-migrate @ 1883]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1764
diff
changeset
|
499 g_snprintf(buf, sizeof(buf), "%s \"%s\" 0", gc->username, req->file); |
|
08ac51210d09
[gaim-migrate @ 1883]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1764
diff
changeset
|
500 |
|
08ac51210d09
[gaim-migrate @ 1883]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1764
diff
changeset
|
501 send(req->fd, buf, strlen(buf), 0); |
|
08ac51210d09
[gaim-migrate @ 1883]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1764
diff
changeset
|
502 |
|
08ac51210d09
[gaim-migrate @ 1883]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1764
diff
changeset
|
503 /* Add our request */ |
|
08ac51210d09
[gaim-migrate @ 1883]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1764
diff
changeset
|
504 ndata->requests = g_slist_append(ndata->requests, req); |
|
08ac51210d09
[gaim-migrate @ 1883]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1764
diff
changeset
|
505 |
|
08ac51210d09
[gaim-migrate @ 1883]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1764
diff
changeset
|
506 /* And start monitoring */ |
|
08ac51210d09
[gaim-migrate @ 1883]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1764
diff
changeset
|
507 req->inpa = gdk_input_add(req->fd, GDK_INPUT_READ, nap_ctc_callback, gc); |
|
08ac51210d09
[gaim-migrate @ 1883]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1764
diff
changeset
|
508 } |
|
08ac51210d09
[gaim-migrate @ 1883]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1764
diff
changeset
|
509 |
|
08ac51210d09
[gaim-migrate @ 1883]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1764
diff
changeset
|
510 static void nap_get_file(struct gaim_connection *gc, gchar *user, gchar *file, gchar *host, unsigned int port) |
|
08ac51210d09
[gaim-migrate @ 1883]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1764
diff
changeset
|
511 { |
|
08ac51210d09
[gaim-migrate @ 1883]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1764
diff
changeset
|
512 struct nap_file_request *req = g_new0(struct nap_file_request, 1); |
|
08ac51210d09
[gaim-migrate @ 1883]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1764
diff
changeset
|
513 |
| 1422 | 514 req->name = g_strdup(user); |
| 515 req->file = g_strdup(file); | |
| 516 req->size = 0; | |
| 517 req->status = 0; | |
| 518 req->total = 0; | |
|
1873
08ac51210d09
[gaim-migrate @ 1883]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1764
diff
changeset
|
519 req->gc = gc; |
| 1444 | 520 |
|
1873
08ac51210d09
[gaim-migrate @ 1883]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1764
diff
changeset
|
521 /* Make a connection with the server */ |
|
1881
a02584b98823
[gaim-migrate @ 1891]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1873
diff
changeset
|
522 req->fd = proxy_connect(host, port, nap_get_file_connect, req); |
|
1873
08ac51210d09
[gaim-migrate @ 1883]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1764
diff
changeset
|
523 if (req->fd < 0) { |
|
08ac51210d09
[gaim-migrate @ 1883]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1764
diff
changeset
|
524 do_error_dialog("Error connecting to user", "Gaim: Napster error"); |
|
08ac51210d09
[gaim-migrate @ 1883]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1764
diff
changeset
|
525 g_free(req->name); |
|
08ac51210d09
[gaim-migrate @ 1883]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1764
diff
changeset
|
526 g_free(req->file); |
|
08ac51210d09
[gaim-migrate @ 1883]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1764
diff
changeset
|
527 g_free(req); |
|
08ac51210d09
[gaim-migrate @ 1883]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1764
diff
changeset
|
528 } |
| 1422 | 529 } |
| 530 | |
| 1323 | 531 static void nap_callback(gpointer data, gint source, GdkInputCondition condition) |
| 532 { | |
| 533 struct gaim_connection *gc = data; | |
| 534 struct nap_data *ndata = gc->proto_data; | |
| 535 gchar *buf; | |
| 536 unsigned short header[2]; | |
| 537 int len; | |
| 538 int command; | |
| 539 gchar **res; | |
| 540 | |
| 1494 | 541 recv(source, header, 4, 0); |
| 542 // read(source, header, 4); | |
| 1323 | 543 len = header[0]; |
| 544 command = header[1]; | |
| 545 | |
| 546 buf = (gchar *)g_malloc(sizeof(gchar) * (len + 1)); | |
| 1494 | 547 |
| 548 // read(source, buf, len); | |
| 549 recv(source, buf, len, 0); | |
| 1323 | 550 |
| 551 buf[len] = 0; | |
| 1427 | 552 |
| 553 printf("DEBUG: %s\n", buf); | |
| 1323 | 554 |
| 555 if (command == 0xd6) { | |
| 556 res = g_strsplit(buf, " ", 0); | |
| 557 /* Do we want to report what the users are doing? */ | |
| 558 printf("users: %s, files: %s, size: %sGB\n", res[0], res[1], res[2]); | |
| 559 g_strfreev(res); | |
| 560 free(buf); | |
| 561 return; | |
| 562 } | |
| 563 | |
| 564 if (command == 0x26d) { | |
| 565 /* Do we want to use the MOTD? */ | |
| 566 free(buf); | |
| 567 return; | |
| 568 } | |
| 569 | |
| 570 if (command == 0xCD) { | |
| 571 res = g_strsplit(buf, " ", 1); | |
| 1764 | 572 serv_got_im(gc, res[0], res[1], 0, time((time_t)NULL)); |
| 1323 | 573 g_strfreev(res); |
| 574 free(buf); | |
| 575 return; | |
| 576 } | |
| 577 | |
| 578 if (command == 0x195) { | |
| 579 struct nap_channel *channel; | |
| 580 | |
| 581 channel = find_channel_by_name(gc, buf); | |
| 582 | |
| 583 if (!channel) { | |
| 584 chat_id++; | |
| 585 | |
| 586 channel = g_new0(struct nap_channel, 1); | |
| 587 | |
| 588 channel->id = chat_id; | |
| 589 channel->name = g_strdup(buf); | |
| 590 | |
| 591 ndata->channels = g_slist_append(ndata->channels, channel); | |
| 592 | |
| 593 serv_got_joined_chat(gc, chat_id, buf); | |
| 594 } | |
| 595 | |
| 596 free(buf); | |
| 597 return; | |
| 598 } | |
| 599 | |
| 600 if (command == 0x198 || command == 0x196) { | |
| 601 struct nap_channel *channel; | |
| 602 struct conversation *convo; | |
| 603 gchar **res; | |
| 604 | |
| 605 res = g_strsplit(buf, " ", 0); | |
| 606 | |
| 607 channel = find_channel_by_name(gc, res[0]); | |
| 608 convo = find_conversation_by_id(gc, channel->id); | |
| 609 | |
| 610 add_chat_buddy(convo, res[1]); | |
| 611 | |
| 612 g_strfreev(res); | |
| 613 | |
| 614 free(buf); | |
| 615 return; | |
| 616 } | |
| 617 | |
| 1325 | 618 if (command == 0x197) { |
| 619 struct nap_channel *channel; | |
| 620 struct conversation *convo; | |
| 621 gchar **res; | |
| 622 | |
| 623 res = g_strsplit(buf, " ", 0); | |
| 624 | |
| 625 channel = find_channel_by_name(gc, res[0]); | |
| 626 convo = find_conversation_by_id(gc, channel->id); | |
| 627 | |
| 628 remove_chat_buddy(convo, res[1]); | |
| 629 | |
| 630 g_strfreev(res); | |
| 631 free(buf); | |
| 632 return; | |
| 633 } | |
| 634 | |
| 1323 | 635 if (command == 0x193) { |
| 636 gchar **res; | |
| 637 struct nap_channel *channel; | |
| 638 | |
| 639 res = g_strsplit(buf, " ", 2); | |
| 640 | |
| 641 channel = find_channel_by_name(gc, res[0]); | |
| 642 | |
| 643 if (channel) | |
| 1764 | 644 serv_got_chat_in(gc, channel->id, res[1], 0, res[2], time((time_t)NULL)); |
| 1323 | 645 |
| 646 g_strfreev(res); | |
| 647 free(buf); | |
| 648 return; | |
| 649 } | |
| 650 | |
| 651 if (command == 0x194) { | |
| 652 do_error_dialog(buf, "Gaim: Napster Error"); | |
| 653 free(buf); | |
| 654 return; | |
| 655 } | |
| 656 | |
| 657 if (command == 0x12e) { | |
| 658 gchar buf2[NAP_BUF_LEN]; | |
| 659 | |
| 660 g_snprintf(buf2, NAP_BUF_LEN, "Unable to add '%s' to your hotlist", buf); | |
| 661 do_error_dialog(buf2, "Gaim: Napster Error"); | |
| 662 | |
| 663 free(buf); | |
| 664 return; | |
| 665 | |
| 666 } | |
| 667 | |
| 668 if (command == 0x191) { | |
| 669 struct nap_channel *channel; | |
| 670 | |
| 671 channel = find_channel_by_name(gc, buf); | |
| 672 | |
| 673 if (!channel) /* I'm not sure how this would happen =) */ | |
| 674 return; | |
| 675 | |
| 676 serv_got_chat_left(gc, channel->id); | |
| 677 ndata->channels = g_slist_remove(ndata->channels, channel); | |
| 678 | |
| 679 free(buf); | |
| 680 return; | |
| 681 | |
| 682 } | |
| 683 | |
| 684 if (command == 0xd1) { | |
| 685 gchar **res; | |
| 686 | |
| 687 res = g_strsplit(buf, " ", 0); | |
| 688 | |
|
1496
d33bf6548543
[gaim-migrate @ 1506]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1494
diff
changeset
|
689 serv_got_update(gc, res[0], 1, 0, 0, 0, 0, 0); |
| 1323 | 690 |
| 691 g_strfreev(res); | |
| 692 free(buf); | |
| 693 return; | |
| 694 } | |
| 695 | |
| 696 if (command == 0xd2) { | |
| 697 serv_got_update(gc, buf, 0, 0, 0, 0, 0, 0); | |
| 698 free(buf); | |
| 699 return; | |
| 700 } | |
| 701 | |
| 1422 | 702 if (command == 0xd4) { |
| 703 /* Looks like we're getting a browse response */ | |
| 704 gchar user[64]; | |
| 705 gchar file[2048]; | |
| 706 struct browse_window *bw = NULL; | |
| 707 | |
| 708 int i,j; | |
| 709 | |
| 710 for (i = 0, j = 0; buf[i] != ' '; i++, j++) | |
| 711 { | |
| 712 user[j] = buf[i]; | |
| 713 } | |
| 714 user[j] = 0; i++; i++; | |
| 715 | |
| 716 for (j = 0; buf[i] != '\"'; i++, j++) | |
| 717 { | |
| 718 file[j] = buf[i]; | |
| 719 } | |
| 720 file[j] = 0; | |
| 721 | |
| 722 bw = find_browse_window_by_name(gc, user); | |
| 723 if (!bw) | |
| 724 { | |
| 725 /* If a browse window isn't found, let's create one */ | |
| 726 bw = browse_window_new(gc, user); | |
| 727 } | |
| 728 | |
| 729 browse_window_add_file(bw, file); | |
| 730 | |
| 731 free(buf); | |
| 732 return; | |
| 733 | |
| 734 } | |
| 735 | |
| 1427 | 736 if (command == 0xc9) { |
| 737 /* We've received a search response */ | |
| 738 gchar *file = (gchar *)g_malloc(sizeof(gchar) * (NAP_BUF_LEN+1)); | |
| 739 gchar *tmp; | |
| 740 gchar rest[NAP_BUF_LEN]; | |
| 741 gchar *data[5]; | |
| 742 gchar **parse_name; | |
| 743 | |
| 744 int i, j; | |
| 745 | |
| 1494 | 746 for (i = 1, j = 0; ((buf[i] != '\"') && (buf[i] != 0)); i++, j++) |
| 1427 | 747 { |
| 748 file[j] = buf[i]; | |
| 749 } | |
| 750 | |
| 751 file[j] = 0; i++; | |
| 752 | |
| 753 tmp = (gchar *)g_malloc(sizeof(gchar) * (strlen(file) + 1)); | |
| 754 strcpy(tmp, rindex(file, '\\')+1); | |
| 755 | |
| 756 strcpy(rest, buf+i); | |
| 757 | |
| 758 parse_name = g_strsplit(rest, " ", 0); | |
| 759 | |
| 760 data[0] = g_strdup(tmp); | |
| 761 data[1] = g_strdup(parse_name[6]); | |
| 762 data[2] = g_strdup(parse_name[2]); | |
| 763 data[3] = g_strdup(parse_name[3]); | |
| 764 data[4] = g_strdup(parse_name[8]); | |
| 765 | |
| 766 // printf("File: %s, 1: %s, 2: %s, 3: %s\n", data[0], data[1], data[2], data[3]); | |
| 767 i = gtk_clist_append(GTK_CLIST(search_dialog->list), data); | |
| 768 | |
| 769 gtk_clist_set_row_data(GTK_CLIST(search_dialog->list), i, file); | |
| 770 g_strfreev(parse_name); | |
| 771 // g_free(file); | |
| 772 g_free(tmp); | |
| 773 g_free(buf); | |
| 774 return; | |
| 775 } | |
| 776 | |
| 777 if (command == 0xca) | |
| 778 { | |
| 779 /* End of search */ | |
| 780 g_free(buf); | |
| 781 return; | |
| 782 } | |
| 783 | |
| 1323 | 784 if (command == 0x12d) { |
| 785 /* Our buddy was added successfully */ | |
| 786 free(buf); | |
| 787 return; | |
| 788 } | |
| 789 | |
| 1329 | 790 if (command == 0x2ec) { |
| 791 /* Looks like someone logged in as us! =-O */ | |
| 792 free(buf); | |
| 793 | |
| 794 signoff(gc); | |
| 795 return; | |
| 796 } | |
| 797 | |
| 1422 | 798 if (command == 0xcc) { |
| 799 /* We received a Download ACK from a user. The way this is printed is kind of | |
| 800 * strange so we'll need to parse this one ourselves. */ | |
| 801 | |
| 802 gchar user[64]; | |
| 803 gchar file[2048]; | |
| 804 gchar hoststr[16]; | |
| 805 gchar portstr[16]; | |
| 806 int i,j; | |
| 807 | |
| 808 for (i = 0, j = 0; buf[i] != ' '; i++, j++) | |
| 809 { | |
| 810 user[j] = buf[i]; | |
| 811 } | |
| 812 user[j] = 0; i++; | |
| 813 | |
| 814 for (j = 0; buf[i] != ' '; i++, j++) | |
| 815 { | |
| 816 hoststr[j] = buf[i]; | |
| 817 } | |
| 818 hoststr[j] = 0; i++; | |
| 819 | |
| 820 for (j = 0; buf[i] != ' '; i++, j++) | |
| 821 { | |
| 822 portstr[j] = buf[i]; | |
| 823 } | |
| 824 portstr[j] = 0; i++; | |
| 825 | |
| 826 i++; /* We do this to ignore the first quotation mark */ | |
| 827 | |
| 828 for (j = 0; buf[i] != '\"'; i++, j++) | |
| 829 { | |
| 830 file[j] = buf[i]; | |
| 831 } | |
| 832 file[j] = 0; | |
| 833 | |
| 834 /* Aaight. We dont need nuttin' else. Let's download the file */ | |
|
1873
08ac51210d09
[gaim-migrate @ 1883]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1764
diff
changeset
|
835 nap_get_file(gc, user, file, hoststr, atoi(portstr)); |
| 1422 | 836 |
| 837 free(buf); | |
| 838 | |
| 839 return; | |
| 840 } | |
| 841 | |
| 1323 | 842 printf("NAP: [COMMAND: 0x%04x] %s\n", command, buf); |
| 1422 | 843 |
| 844 free(buf); | |
| 1323 | 845 } |
| 846 | |
| 847 | |
| 848 static void nap_login_callback(gpointer data, gint source, GdkInputCondition condition) | |
| 849 { | |
| 850 struct gaim_connection *gc = data; | |
| 851 struct nap_data *ndata = gc->proto_data; | |
| 852 gchar buf[NAP_BUF_LEN]; | |
| 853 unsigned short header[2]; | |
| 854 int len; | |
| 855 int command; | |
| 856 | |
| 857 read(source, header, 4); | |
| 858 len = header[0]; | |
| 859 command = header[1]; | |
| 1935 | 860 |
| 1323 | 861 read(source, buf, len); |
| 862 buf[len] = 0; | |
| 863 | |
| 1935 | 864 /* If we have some kind of error, get outta here */ |
| 865 if (command == 0x00) | |
| 866 { | |
| 867 do_error_dialog(buf, "Gaim: Napster Error"); | |
| 868 gdk_input_remove(ndata->inpa); | |
| 869 ndata->inpa = 0; | |
| 870 close(source); | |
| 871 signoff(gc); | |
| 872 return; | |
| 873 } | |
| 874 | |
| 1323 | 875 if (command == 0x03) { |
| 876 printf("Registered with E-Mail address of: %s\n", buf); | |
| 877 ndata->email = g_strdup(buf); | |
| 878 | |
| 879 /* Remove old inpa, add new one */ | |
| 880 gdk_input_remove(ndata->inpa); | |
| 881 ndata->inpa = 0; | |
| 882 gc->inpa = gdk_input_add(ndata->fd, GDK_INPUT_READ, nap_callback, gc); | |
| 883 | |
| 884 /* Our signon is complete */ | |
| 885 account_online(gc); | |
| 886 serv_finish_login(gc); | |
| 887 | |
| 888 if (bud_list_cache_exists(gc)) | |
| 889 do_import(NULL, gc); | |
| 890 | |
| 891 return; | |
| 892 } | |
| 893 } | |
| 894 | |
| 895 | |
|
1873
08ac51210d09
[gaim-migrate @ 1883]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1764
diff
changeset
|
896 static void nap_login_connect(gpointer data, gint source, GdkInputCondition cond) |
| 1323 | 897 { |
|
1873
08ac51210d09
[gaim-migrate @ 1883]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1764
diff
changeset
|
898 struct gaim_connection *gc = data; |
|
08ac51210d09
[gaim-migrate @ 1883]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1764
diff
changeset
|
899 struct nap_data *ndata = gc->proto_data; |
| 1323 | 900 char buf[NAP_BUF_LEN]; |
| 901 | |
|
1873
08ac51210d09
[gaim-migrate @ 1883]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1764
diff
changeset
|
902 if (source < 0) { |
|
08ac51210d09
[gaim-migrate @ 1883]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1764
diff
changeset
|
903 hide_login_progress(gc, "Unable to connect"); |
| 1422 | 904 signoff(gc); |
| 905 return; | |
| 906 } | |
| 1323 | 907 |
|
1873
08ac51210d09
[gaim-migrate @ 1883]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1764
diff
changeset
|
908 if (ndata->fd != source) |
|
08ac51210d09
[gaim-migrate @ 1883]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1764
diff
changeset
|
909 ndata->fd = source; |
| 1323 | 910 |
| 911 /* And write our signon data */ | |
| 1427 | 912 g_snprintf(buf, NAP_BUF_LEN, "%s %s 0 \"gaimster\" 0", gc->username, gc->password); |
| 1323 | 913 nap_write_packet(gc, 0x02, buf); |
| 914 | |
| 915 /* And set up the input watcher */ | |
| 916 ndata->inpa = gdk_input_add(ndata->fd, GDK_INPUT_READ, nap_login_callback, gc); | |
|
1873
08ac51210d09
[gaim-migrate @ 1883]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1764
diff
changeset
|
917 } |
| 1323 | 918 |
| 1424 | 919 |
|
1873
08ac51210d09
[gaim-migrate @ 1883]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1764
diff
changeset
|
920 static void nap_login(struct aim_user *user) |
|
08ac51210d09
[gaim-migrate @ 1883]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1764
diff
changeset
|
921 { |
|
08ac51210d09
[gaim-migrate @ 1883]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1764
diff
changeset
|
922 struct gaim_connection *gc = new_gaim_conn(user); |
|
08ac51210d09
[gaim-migrate @ 1883]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1764
diff
changeset
|
923 struct nap_data *ndata = gc->proto_data = g_new0(struct nap_data, 1); |
|
08ac51210d09
[gaim-migrate @ 1883]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1764
diff
changeset
|
924 |
|
1881
a02584b98823
[gaim-migrate @ 1891]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1873
diff
changeset
|
925 ndata->fd = proxy_connect("64.124.41.187", 8888, nap_login_connect, gc); |
|
1873
08ac51210d09
[gaim-migrate @ 1883]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1764
diff
changeset
|
926 if (ndata->fd < 0) { |
|
08ac51210d09
[gaim-migrate @ 1883]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1764
diff
changeset
|
927 hide_login_progress(gc, "Unable to connect"); |
|
08ac51210d09
[gaim-migrate @ 1883]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1764
diff
changeset
|
928 signoff(gc); |
|
08ac51210d09
[gaim-migrate @ 1883]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1764
diff
changeset
|
929 } |
| 1323 | 930 } |
| 931 | |
| 932 static void nap_join_chat(struct gaim_connection *gc, int id, char *name) | |
| 933 { | |
| 934 gchar buf[NAP_BUF_LEN]; | |
| 935 | |
| 936 /* Make sure the name has a # preceeding it */ | |
| 937 if (name[0] != '#') | |
| 938 g_snprintf(buf, NAP_BUF_LEN, "#%s", name); | |
| 939 else | |
| 940 g_snprintf(buf, NAP_BUF_LEN, "%s", name); | |
| 941 | |
| 942 nap_write_packet(gc, 0x190, buf); | |
| 943 } | |
| 944 | |
| 945 static void nap_chat_leave(struct gaim_connection *gc, int id) | |
| 946 { | |
| 947 struct nap_data *ndata = (struct nap_data *)gc->proto_data; | |
| 948 struct nap_channel *channel = NULL; | |
| 949 | |
| 950 channel = find_channel_by_id(gc, id); | |
| 951 | |
| 952 if (!channel) /* Again, I'm not sure how this would happen */ | |
| 953 return; | |
| 954 | |
| 955 nap_write_packet(gc, 0x191, channel->name); | |
| 956 | |
| 1325 | 957 ndata->channels = g_slist_remove(ndata->channels, channel); |
| 1323 | 958 g_free(channel->name); |
| 959 g_free(channel); | |
| 960 | |
| 961 } | |
| 962 | |
| 963 static void nap_chat_send(struct gaim_connection *gc, int id, char *message) | |
| 964 { | |
| 965 struct nap_channel *channel = NULL; | |
| 966 gchar buf[NAP_BUF_LEN]; | |
| 967 | |
| 968 channel = find_channel_by_id(gc, id); | |
| 969 | |
| 970 if (!channel) { | |
| 971 /* This shouldn't happen */ | |
| 972 return; | |
| 973 } | |
| 974 | |
| 975 g_snprintf(buf, NAP_BUF_LEN, "%s %s", channel->name, message); | |
| 976 nap_write_packet(gc, 0x192, buf); | |
| 977 | |
| 978 } | |
| 979 | |
| 980 static void nap_add_buddy(struct gaim_connection *gc, char *name) | |
| 981 { | |
| 982 nap_write_packet(gc, 0xCF, name); | |
| 983 } | |
| 984 | |
| 985 static void nap_remove_buddy(struct gaim_connection *gc, char *name) | |
| 986 { | |
| 987 nap_write_packet(gc, 0x12F, name); | |
| 988 } | |
| 989 | |
| 990 static void nap_close(struct gaim_connection *gc) | |
| 991 { | |
| 992 struct nap_data *ndata = (struct nap_data *)gc->proto_data; | |
| 993 struct nap_channel *channel; | |
| 1422 | 994 struct browse_window *browse; |
| 995 struct nap_file_request *req; | |
| 996 | |
| 1323 | 997 if (gc->inpa) |
| 998 gdk_input_remove(gc->inpa); | |
| 999 | |
| 1325 | 1000 while (ndata->channels) { |
| 1001 channel = (struct nap_channel *)ndata->channels->data; | |
| 1323 | 1002 g_free(channel->name); |
| 1325 | 1003 ndata->channels = g_slist_remove(ndata->channels, channel); |
| 1323 | 1004 g_free(channel); |
| 1005 } | |
| 1325 | 1006 |
| 1422 | 1007 while (ndata->browses) { |
| 1008 browse = (struct browse_window *)ndata->browses->data; | |
| 1009 g_free(browse->name); | |
| 1010 gtk_widget_destroy(browse->window); | |
| 1011 ndata->browses = g_slist_remove(ndata->browses, browse); | |
| 1012 g_free(browse); | |
| 1013 } | |
| 1014 | |
| 1015 while (ndata->requests) { | |
| 1016 req = (struct nap_file_request *)ndata->requests->data; | |
| 1017 g_free(req->name); | |
| 1018 g_free(req->file); | |
| 1019 if (req->inpa) { | |
| 1020 gdk_input_remove(req->inpa); | |
| 1021 } | |
| 1022 ndata->requests = g_slist_remove(ndata->requests, req); | |
| 1023 g_free(req); | |
| 1024 | |
| 1025 } | |
| 1026 | |
| 1325 | 1027 free(gc->proto_data); |
| 1323 | 1028 } |
| 1029 | |
| 1030 static void nap_add_buddies(struct gaim_connection *gc, GList *buddies) | |
| 1031 { | |
| 1032 while (buddies) { | |
| 1033 nap_write_packet(gc, 0xd0, (char *)buddies->data); | |
| 1034 buddies = buddies -> next; | |
| 1035 } | |
| 1036 } | |
| 1037 | |
| 1338 | 1038 static void nap_draw_new_user(GtkWidget *box) |
| 1039 { | |
| 1040 GtkWidget *label; | |
| 1041 | |
| 1042 label = gtk_label_new(_("Napster registration is currently under development")); | |
| 1043 | |
| 1044 gtk_label_set_line_wrap(GTK_LABEL(label), TRUE); | |
| 1045 gtk_box_pack_start(GTK_BOX(box), label, FALSE, FALSE, 5); | |
| 1046 gtk_widget_show(label); | |
| 1047 } | |
| 1048 | |
| 1422 | 1049 |
|
1873
08ac51210d09
[gaim-migrate @ 1883]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1764
diff
changeset
|
1050 static void nap_send_browse(GtkObject *w, char *who) |
| 1422 | 1051 { |
| 1052 struct gaim_connection *gc = (struct gaim_connection *)gtk_object_get_user_data(w); | |
| 1053 gchar buf[NAP_BUF_LEN]; | |
| 1054 | |
| 1055 g_snprintf(buf, NAP_BUF_LEN, "%s", who); | |
| 1056 nap_write_packet(gc, 0xd3, buf); | |
| 1057 } | |
| 1058 | |
|
1873
08ac51210d09
[gaim-migrate @ 1883]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1764
diff
changeset
|
1059 static void nap_find_callback(GtkObject *w, GtkWidget *entry) |
| 1427 | 1060 { |
| 1061 struct gaim_connection *gc = (struct gaim_connection *)gtk_object_get_user_data(w); | |
|
1940
8de58cd2892f
[gaim-migrate @ 1950]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1935
diff
changeset
|
1062 const gchar *search; |
| 1427 | 1063 gchar buf[NAP_BUF_LEN]; |
| 1064 | |
| 1065 search = gtk_entry_get_text(GTK_ENTRY(entry)); | |
| 1066 g_snprintf(buf, NAP_BUF_LEN, "FILENAME CONTAINS \"%s\" MAX_RESULTS 50", search); | |
| 1067 | |
| 1068 nap_write_packet(gc, 0xc8, buf); | |
| 1069 } | |
| 1070 | |
|
1873
08ac51210d09
[gaim-migrate @ 1883]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1764
diff
changeset
|
1071 static void destroy_window(GtkObject *w, GtkWidget *win) |
| 1427 | 1072 { |
| 1073 gtk_widget_destroy(win); | |
| 1074 } | |
| 1075 | |
|
1873
08ac51210d09
[gaim-migrate @ 1883]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1764
diff
changeset
|
1076 static void nap_show_search(GtkObject *w, void *omit) |
| 1427 | 1077 { |
| 1078 struct gaim_connection *gc = (struct gaim_connection *)gtk_object_get_user_data(w); | |
| 1079 | |
| 1080 if (!search_dialog) | |
| 1081 { | |
| 1082 GtkWidget *window; | |
| 1083 GtkWidget *sw; | |
| 1084 GtkWidget *vbox; | |
| 1085 GtkWidget *hbox; | |
| 1086 GtkWidget *label; | |
| 1087 GtkWidget *button; | |
| 1088 GtkWidget *entry; | |
| 1089 GtkWidget *list; | |
| 1090 gchar *titles[5] = {"Mp3 Name", "Nick", "Size", "Bitrate", "Connection"}; | |
| 1091 search_dialog = g_new0(struct search_window, 1); | |
| 1092 | |
|
1956
c9c20663e05b
[gaim-migrate @ 1966]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1943
diff
changeset
|
1093 window = gtk_window_new(GTK_WINDOW_DIALOG); |
| 1427 | 1094 |
| 1095 vbox = gtk_vbox_new(FALSE, 0); | |
| 1096 | |
| 1097 /* First Line */ | |
| 1098 hbox = gtk_hbox_new(FALSE, 5); | |
| 1099 label = gtk_label_new("Search for:"); | |
| 1100 gtk_widget_show(label); | |
| 1101 gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 5); | |
| 1102 | |
| 1103 entry = gtk_entry_new(); | |
| 1104 gtk_widget_show(entry); | |
| 1105 gtk_box_pack_start(GTK_BOX(hbox), entry, FALSE, FALSE, 5); | |
| 1106 | |
| 1107 button = gtk_button_new_with_label("Find"); | |
| 1108 gtk_widget_show(button); | |
| 1109 gtk_object_set_user_data(GTK_OBJECT(button), gc); | |
| 1110 gtk_signal_connect(GTK_OBJECT(button), "clicked", GTK_SIGNAL_FUNC(nap_find_callback), entry); | |
| 1111 | |
| 1112 gtk_box_pack_start(GTK_BOX(hbox), button, FALSE, FALSE, 5); | |
| 1113 | |
| 1114 button = gtk_button_new_with_label("Cancel"); | |
| 1115 gtk_widget_show(button); | |
| 1116 gtk_box_pack_start(GTK_BOX(hbox), button, FALSE, FALSE, 5); | |
| 1117 | |
| 1118 | |
| 1119 gtk_widget_show(hbox); | |
| 1120 gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, 5); | |
| 1121 /* End First List */ | |
| 1122 | |
| 1123 /* Second Line */ | |
| 1124 | |
| 1125 sw = gtk_scrolled_window_new(NULL, NULL); | |
| 1126 | |
| 1127 list = gtk_clist_new_with_titles(5, titles); | |
| 1128 | |
| 1129 gtk_clist_column_titles_show(GTK_CLIST(list)); | |
| 1130 | |
| 1131 gtk_signal_connect(GTK_OBJECT(list), "select-row", GTK_SIGNAL_FUNC(nap_handle_download_search), gc); | |
| 1132 | |
| 1133 gtk_container_add(GTK_CONTAINER(sw), list); | |
| 1134 gtk_widget_show(list); | |
| 1135 | |
| 1136 gtk_box_pack_start(GTK_BOX(vbox), sw, FALSE, FALSE, 5); | |
| 1137 | |
| 1138 gtk_widget_show(sw); | |
| 1139 | |
| 1140 /* End Second Line */ | |
| 1141 | |
| 1142 gtk_widget_show(vbox); | |
| 1143 | |
| 1144 gtk_container_add(GTK_CONTAINER(window), vbox); | |
| 1145 gtk_container_set_border_width(GTK_CONTAINER(window), 10); | |
| 1146 | |
| 1147 gtk_widget_set_usize(GTK_WIDGET(list), 500, 350); | |
| 1148 gtk_widget_set_usize(GTK_WIDGET(window), 500, 400); | |
| 1149 | |
| 1150 gtk_signal_connect(GTK_OBJECT(window), "destroy", GTK_SIGNAL_FUNC(destroy_window), window); | |
| 1151 gtk_widget_show(window); | |
| 1152 | |
| 1153 search_dialog->window = window; | |
| 1154 search_dialog->list = list; | |
| 1155 } | |
| 1156 | |
| 1157 gtk_widget_show(search_dialog->window); | |
| 1158 } | |
| 1159 | |
|
1499
de0b946e86a4
[gaim-migrate @ 1509]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1496
diff
changeset
|
1160 static void nap_buddy_menu(GtkWidget *menu, struct gaim_connection *gc, char *who) |
| 1422 | 1161 { |
| 1162 GtkWidget *button; | |
| 1163 | |
| 1427 | 1164 button = gtk_menu_item_new_with_label("Browse Files"); |
| 1422 | 1165 gtk_signal_connect(GTK_OBJECT(button), "activate", GTK_SIGNAL_FUNC(nap_send_browse), who); |
| 1166 gtk_object_set_user_data(GTK_OBJECT(button), gc); | |
| 1167 gtk_menu_append(GTK_MENU(menu), button); | |
| 1168 gtk_widget_show(button); | |
| 1427 | 1169 |
| 1170 button = gtk_menu_item_new_with_label("Search Napster"); | |
| 1171 gtk_signal_connect(GTK_OBJECT(button), "activate", GTK_SIGNAL_FUNC(nap_show_search), NULL); | |
| 1172 gtk_object_set_user_data(GTK_OBJECT(button), gc); | |
| 1173 gtk_menu_append(GTK_MENU(menu), button); | |
| 1174 gtk_widget_show(button); | |
| 1422 | 1175 } |
| 1176 | |
| 1327 | 1177 static char** nap_list_icon(int uc) |
| 1178 { | |
| 1179 return napster_xpm; | |
| 1180 } | |
| 1181 | |
| 1323 | 1182 static struct prpl *my_protocol = NULL; |
| 1183 | |
|
1873
08ac51210d09
[gaim-migrate @ 1883]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1764
diff
changeset
|
1184 static void nap_init(struct prpl *ret) |
| 1323 | 1185 { |
| 1186 ret->protocol = PROTO_NAPSTER; | |
| 1187 ret->name = nap_name; | |
| 1327 | 1188 ret->list_icon = nap_list_icon; |
|
1499
de0b946e86a4
[gaim-migrate @ 1509]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1496
diff
changeset
|
1189 ret->buddy_menu = nap_buddy_menu; |
|
1881
a02584b98823
[gaim-migrate @ 1891]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1873
diff
changeset
|
1190 ret->user_opts = NULL; |
| 1323 | 1191 ret->login = nap_login; |
| 1192 ret->close = nap_close; | |
| 1193 ret->send_im = nap_send_im; | |
| 1194 ret->set_info = NULL; | |
| 1195 ret->get_info = NULL; | |
| 1196 ret->set_away = NULL; | |
| 1197 ret->get_away_msg = NULL; | |
| 1198 ret->set_dir = NULL; | |
| 1199 ret->get_dir = NULL; | |
| 1200 ret->dir_search = NULL; | |
| 1201 ret->set_idle = NULL; | |
| 1202 ret->change_passwd = NULL; | |
| 1203 ret->add_buddy = nap_add_buddy; | |
| 1204 ret->add_buddies = nap_add_buddies; | |
| 1205 ret->remove_buddy = nap_remove_buddy; | |
| 1206 ret->add_permit = NULL; | |
| 1207 ret->rem_permit = NULL; | |
| 1208 ret->add_deny = NULL; | |
| 1209 ret->rem_deny = NULL; | |
| 1210 ret->warn = NULL; | |
| 1211 ret->accept_chat = NULL; | |
| 1212 ret->join_chat = nap_join_chat; | |
| 1213 ret->chat_invite = NULL; | |
| 1214 ret->chat_leave = nap_chat_leave; | |
| 1215 ret->chat_whisper = NULL; | |
| 1216 ret->chat_send = nap_chat_send; | |
| 1217 ret->keepalive = NULL; | |
| 1338 | 1218 ret->draw_new_user = nap_draw_new_user; |
| 1323 | 1219 |
| 1220 my_protocol = ret; | |
| 1221 } | |
| 1222 | |
| 1223 char *gaim_plugin_init(GModule * handle) | |
| 1224 { | |
|
1443
336fc98b7f90
[gaim-migrate @ 1453]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1427
diff
changeset
|
1225 load_protocol(nap_init, sizeof(struct prpl)); |
| 1323 | 1226 return NULL; |
| 1227 } | |
| 1228 | |
| 1229 void gaim_plugin_remove() | |
| 1230 { | |
| 1231 struct prpl *p = find_prpl(PROTO_NAPSTER); | |
| 1232 if (p == my_protocol) | |
| 1233 unload_protocol(p); | |
| 1234 } |
