Wed, 23 May 2001 07:59:05 +0000
[gaim-migrate @ 1891]
C:)
| 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
66c5f8b3f7fe
[gaim-migrate @ 1883]
Eric Warmenhoven <warmenhoven@yahoo.com>
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
66c5f8b3f7fe
[gaim-migrate @ 1883]
Eric Warmenhoven <warmenhoven@yahoo.com>
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
66c5f8b3f7fe
[gaim-migrate @ 1883]
Eric Warmenhoven <warmenhoven@yahoo.com>
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
66c5f8b3f7fe
[gaim-migrate @ 1883]
Eric Warmenhoven <warmenhoven@yahoo.com>
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
66c5f8b3f7fe
[gaim-migrate @ 1883]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
1764
diff
changeset
|
148 | static void nap_handle_download(GtkCList *clist, gint row, gint col, GdkEventButton *event, gpointer user_data) |
| 1422 | 149 | { |
|
1873
66c5f8b3f7fe
[gaim-migrate @ 1883]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
1764
diff
changeset
|
150 | gchar *results; |
| 1422 | 151 | struct browse_window *bw = (struct browse_window *)user_data; |
| 152 | ||
|
1873
66c5f8b3f7fe
[gaim-migrate @ 1883]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
1764
diff
changeset
|
153 | gtk_clist_get_text(GTK_CLIST(clist), row, 0, &results); |
| 1422 | 154 | |
|
1873
66c5f8b3f7fe
[gaim-migrate @ 1883]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
1764
diff
changeset
|
155 | nap_send_download_req(bw->gc, bw->name, results); |
| 1422 | 156 | |
| 157 | } | |
| 158 | ||
|
1873
66c5f8b3f7fe
[gaim-migrate @ 1883]
Eric Warmenhoven <warmenhoven@yahoo.com>
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
66c5f8b3f7fe
[gaim-migrate @ 1883]
Eric Warmenhoven <warmenhoven@yahoo.com>
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 | ||
| 179 | browse->window = gtk_window_new(GTK_WINDOW_DIALOG); | |
| 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
66c5f8b3f7fe
[gaim-migrate @ 1883]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
1764
diff
changeset
|
194 | |
|
66c5f8b3f7fe
[gaim-migrate @ 1883]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
1764
diff
changeset
|
195 | return browse; |
| 1422 | 196 | } |
| 197 | ||
|
1873
66c5f8b3f7fe
[gaim-migrate @ 1883]
Eric Warmenhoven <warmenhoven@yahoo.com>
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
66c5f8b3f7fe
[gaim-migrate @ 1883]
Eric Warmenhoven <warmenhoven@yahoo.com>
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
66c5f8b3f7fe
[gaim-migrate @ 1883]
Eric Warmenhoven <warmenhoven@yahoo.com>
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
66c5f8b3f7fe
[gaim-migrate @ 1883]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
1764
diff
changeset
|
481 | struct nap_file_request *req = data; |
|
66c5f8b3f7fe
[gaim-migrate @ 1883]
Eric Warmenhoven <warmenhoven@yahoo.com>
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
66c5f8b3f7fe
[gaim-migrate @ 1883]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
1764
diff
changeset
|
485 | if (source < 0) { |
| 1422 | 486 | do_error_dialog("Error connecting to user", "Gaim: Napster error"); |
|
1873
66c5f8b3f7fe
[gaim-migrate @ 1883]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
1764
diff
changeset
|
487 | g_free(req->name); |
|
66c5f8b3f7fe
[gaim-migrate @ 1883]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
1764
diff
changeset
|
488 | g_free(req->file); |
|
66c5f8b3f7fe
[gaim-migrate @ 1883]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
1764
diff
changeset
|
489 | g_free(req); |
| 1422 | 490 | return; |
| 491 | } | |
| 492 | ||
|
1873
66c5f8b3f7fe
[gaim-migrate @ 1883]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
1764
diff
changeset
|
493 | if (req->fd != source) |
|
66c5f8b3f7fe
[gaim-migrate @ 1883]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
1764
diff
changeset
|
494 | req->fd = source; |
|
66c5f8b3f7fe
[gaim-migrate @ 1883]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
1764
diff
changeset
|
495 | |
|
66c5f8b3f7fe
[gaim-migrate @ 1883]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
1764
diff
changeset
|
496 | send(req->fd, "GET", 3, 0); |
|
66c5f8b3f7fe
[gaim-migrate @ 1883]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
1764
diff
changeset
|
497 | |
|
66c5f8b3f7fe
[gaim-migrate @ 1883]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
1764
diff
changeset
|
498 | /* Send our request to the user */ |
|
66c5f8b3f7fe
[gaim-migrate @ 1883]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
1764
diff
changeset
|
499 | g_snprintf(buf, sizeof(buf), "%s \"%s\" 0", gc->username, req->file); |
|
66c5f8b3f7fe
[gaim-migrate @ 1883]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
1764
diff
changeset
|
500 | |
|
66c5f8b3f7fe
[gaim-migrate @ 1883]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
1764
diff
changeset
|
501 | send(req->fd, buf, strlen(buf), 0); |
|
66c5f8b3f7fe
[gaim-migrate @ 1883]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
1764
diff
changeset
|
502 | |
|
66c5f8b3f7fe
[gaim-migrate @ 1883]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
1764
diff
changeset
|
503 | /* Add our request */ |
|
66c5f8b3f7fe
[gaim-migrate @ 1883]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
1764
diff
changeset
|
504 | ndata->requests = g_slist_append(ndata->requests, req); |
|
66c5f8b3f7fe
[gaim-migrate @ 1883]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
1764
diff
changeset
|
505 | |
|
66c5f8b3f7fe
[gaim-migrate @ 1883]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
1764
diff
changeset
|
506 | /* And start monitoring */ |
|
66c5f8b3f7fe
[gaim-migrate @ 1883]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
1764
diff
changeset
|
507 | req->inpa = gdk_input_add(req->fd, GDK_INPUT_READ, nap_ctc_callback, gc); |
|
66c5f8b3f7fe
[gaim-migrate @ 1883]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
1764
diff
changeset
|
508 | } |
|
66c5f8b3f7fe
[gaim-migrate @ 1883]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
1764
diff
changeset
|
509 | |
|
66c5f8b3f7fe
[gaim-migrate @ 1883]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
1764
diff
changeset
|
510 | static void nap_get_file(struct gaim_connection *gc, gchar *user, gchar *file, gchar *host, unsigned int port) |
|
66c5f8b3f7fe
[gaim-migrate @ 1883]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
1764
diff
changeset
|
511 | { |
|
66c5f8b3f7fe
[gaim-migrate @ 1883]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
1764
diff
changeset
|
512 | struct nap_file_request *req = g_new0(struct nap_file_request, 1); |
|
66c5f8b3f7fe
[gaim-migrate @ 1883]
Eric Warmenhoven <warmenhoven@yahoo.com>
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
66c5f8b3f7fe
[gaim-migrate @ 1883]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
1764
diff
changeset
|
519 | req->gc = gc; |
| 1444 | 520 | |
|
1873
66c5f8b3f7fe
[gaim-migrate @ 1883]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
1764
diff
changeset
|
521 | /* Make a connection with the server */ |
|
1881
bcd5d457cdbb
[gaim-migrate @ 1891]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
1873
diff
changeset
|
522 | req->fd = proxy_connect(host, port, nap_get_file_connect, req); |
|
1873
66c5f8b3f7fe
[gaim-migrate @ 1883]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
1764
diff
changeset
|
523 | if (req->fd < 0) { |
|
66c5f8b3f7fe
[gaim-migrate @ 1883]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
1764
diff
changeset
|
524 | do_error_dialog("Error connecting to user", "Gaim: Napster error"); |
|
66c5f8b3f7fe
[gaim-migrate @ 1883]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
1764
diff
changeset
|
525 | g_free(req->name); |
|
66c5f8b3f7fe
[gaim-migrate @ 1883]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
1764
diff
changeset
|
526 | g_free(req->file); |
|
66c5f8b3f7fe
[gaim-migrate @ 1883]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
1764
diff
changeset
|
527 | g_free(req); |
|
66c5f8b3f7fe
[gaim-migrate @ 1883]
Eric Warmenhoven <warmenhoven@yahoo.com>
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
d8bc156b68fc
[gaim-migrate @ 1506]
Eric Warmenhoven <warmenhoven@yahoo.com>
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
66c5f8b3f7fe
[gaim-migrate @ 1883]
Eric Warmenhoven <warmenhoven@yahoo.com>
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]; | |
| 860 | ||
| 861 | read(source, buf, len); | |
| 862 | buf[len] = 0; | |
| 863 | ||
| 864 | if (command == 0x03) { | |
| 865 | printf("Registered with E-Mail address of: %s\n", buf); | |
| 866 | ndata->email = g_strdup(buf); | |
| 867 | ||
| 868 | /* Remove old inpa, add new one */ | |
| 869 | gdk_input_remove(ndata->inpa); | |
| 870 | ndata->inpa = 0; | |
| 871 | gc->inpa = gdk_input_add(ndata->fd, GDK_INPUT_READ, nap_callback, gc); | |
| 872 | ||
| 873 | /* Our signon is complete */ | |
| 874 | account_online(gc); | |
| 875 | serv_finish_login(gc); | |
| 876 | ||
| 877 | if (bud_list_cache_exists(gc)) | |
| 878 | do_import(NULL, gc); | |
| 879 | ||
| 880 | return; | |
| 881 | } | |
| 882 | } | |
| 883 | ||
| 884 | ||
|
1873
66c5f8b3f7fe
[gaim-migrate @ 1883]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
1764
diff
changeset
|
885 | static void nap_login_connect(gpointer data, gint source, GdkInputCondition cond) |
| 1323 | 886 | { |
|
1873
66c5f8b3f7fe
[gaim-migrate @ 1883]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
1764
diff
changeset
|
887 | struct gaim_connection *gc = data; |
|
66c5f8b3f7fe
[gaim-migrate @ 1883]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
1764
diff
changeset
|
888 | struct nap_data *ndata = gc->proto_data; |
| 1323 | 889 | char buf[NAP_BUF_LEN]; |
| 890 | ||
|
1873
66c5f8b3f7fe
[gaim-migrate @ 1883]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
1764
diff
changeset
|
891 | if (source < 0) { |
|
66c5f8b3f7fe
[gaim-migrate @ 1883]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
1764
diff
changeset
|
892 | hide_login_progress(gc, "Unable to connect"); |
| 1422 | 893 | signoff(gc); |
| 894 | return; | |
| 895 | } | |
| 1323 | 896 | |
|
1873
66c5f8b3f7fe
[gaim-migrate @ 1883]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
1764
diff
changeset
|
897 | if (ndata->fd != source) |
|
66c5f8b3f7fe
[gaim-migrate @ 1883]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
1764
diff
changeset
|
898 | ndata->fd = source; |
| 1323 | 899 | |
| 900 | /* And write our signon data */ | |
| 1427 | 901 | g_snprintf(buf, NAP_BUF_LEN, "%s %s 0 \"gaimster\" 0", gc->username, gc->password); |
| 1323 | 902 | nap_write_packet(gc, 0x02, buf); |
| 903 | ||
| 904 | /* And set up the input watcher */ | |
| 905 | ndata->inpa = gdk_input_add(ndata->fd, GDK_INPUT_READ, nap_login_callback, gc); | |
|
1873
66c5f8b3f7fe
[gaim-migrate @ 1883]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
1764
diff
changeset
|
906 | } |
| 1323 | 907 | |
| 1424 | 908 | |
|
1873
66c5f8b3f7fe
[gaim-migrate @ 1883]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
1764
diff
changeset
|
909 | static void nap_login(struct aim_user *user) |
|
66c5f8b3f7fe
[gaim-migrate @ 1883]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
1764
diff
changeset
|
910 | { |
|
66c5f8b3f7fe
[gaim-migrate @ 1883]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
1764
diff
changeset
|
911 | struct gaim_connection *gc = new_gaim_conn(user); |
|
66c5f8b3f7fe
[gaim-migrate @ 1883]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
1764
diff
changeset
|
912 | struct nap_data *ndata = gc->proto_data = g_new0(struct nap_data, 1); |
|
66c5f8b3f7fe
[gaim-migrate @ 1883]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
1764
diff
changeset
|
913 | |
|
1881
bcd5d457cdbb
[gaim-migrate @ 1891]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
1873
diff
changeset
|
914 | ndata->fd = proxy_connect("64.124.41.187", 8888, nap_login_connect, gc); |
|
1873
66c5f8b3f7fe
[gaim-migrate @ 1883]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
1764
diff
changeset
|
915 | if (ndata->fd < 0) { |
|
66c5f8b3f7fe
[gaim-migrate @ 1883]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
1764
diff
changeset
|
916 | hide_login_progress(gc, "Unable to connect"); |
|
66c5f8b3f7fe
[gaim-migrate @ 1883]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
1764
diff
changeset
|
917 | signoff(gc); |
|
66c5f8b3f7fe
[gaim-migrate @ 1883]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
1764
diff
changeset
|
918 | } |
| 1323 | 919 | } |
| 920 | ||
| 921 | static void nap_join_chat(struct gaim_connection *gc, int id, char *name) | |
| 922 | { | |
| 923 | gchar buf[NAP_BUF_LEN]; | |
| 924 | ||
| 925 | /* Make sure the name has a # preceeding it */ | |
| 926 | if (name[0] != '#') | |
| 927 | g_snprintf(buf, NAP_BUF_LEN, "#%s", name); | |
| 928 | else | |
| 929 | g_snprintf(buf, NAP_BUF_LEN, "%s", name); | |
| 930 | ||
| 931 | nap_write_packet(gc, 0x190, buf); | |
| 932 | } | |
| 933 | ||
| 934 | static void nap_chat_leave(struct gaim_connection *gc, int id) | |
| 935 | { | |
| 936 | struct nap_data *ndata = (struct nap_data *)gc->proto_data; | |
| 937 | struct nap_channel *channel = NULL; | |
| 938 | ||
| 939 | channel = find_channel_by_id(gc, id); | |
| 940 | ||
| 941 | if (!channel) /* Again, I'm not sure how this would happen */ | |
| 942 | return; | |
| 943 | ||
| 944 | nap_write_packet(gc, 0x191, channel->name); | |
| 945 | ||
| 1325 | 946 | ndata->channels = g_slist_remove(ndata->channels, channel); |
| 1323 | 947 | g_free(channel->name); |
| 948 | g_free(channel); | |
| 949 | ||
| 950 | } | |
| 951 | ||
| 952 | static void nap_chat_send(struct gaim_connection *gc, int id, char *message) | |
| 953 | { | |
| 954 | struct nap_channel *channel = NULL; | |
| 955 | gchar buf[NAP_BUF_LEN]; | |
| 956 | ||
| 957 | channel = find_channel_by_id(gc, id); | |
| 958 | ||
| 959 | if (!channel) { | |
| 960 | /* This shouldn't happen */ | |
| 961 | return; | |
| 962 | } | |
| 963 | ||
| 964 | g_snprintf(buf, NAP_BUF_LEN, "%s %s", channel->name, message); | |
| 965 | nap_write_packet(gc, 0x192, buf); | |
| 966 | ||
| 967 | } | |
| 968 | ||
| 969 | static void nap_add_buddy(struct gaim_connection *gc, char *name) | |
| 970 | { | |
| 971 | nap_write_packet(gc, 0xCF, name); | |
| 972 | } | |
| 973 | ||
| 974 | static void nap_remove_buddy(struct gaim_connection *gc, char *name) | |
| 975 | { | |
| 976 | nap_write_packet(gc, 0x12F, name); | |
| 977 | } | |
| 978 | ||
| 979 | static void nap_close(struct gaim_connection *gc) | |
| 980 | { | |
| 981 | struct nap_data *ndata = (struct nap_data *)gc->proto_data; | |
| 982 | struct nap_channel *channel; | |
| 1422 | 983 | struct browse_window *browse; |
| 984 | struct nap_file_request *req; | |
| 985 | ||
| 1323 | 986 | if (gc->inpa) |
| 987 | gdk_input_remove(gc->inpa); | |
| 988 | ||
| 1325 | 989 | while (ndata->channels) { |
| 990 | channel = (struct nap_channel *)ndata->channels->data; | |
| 1323 | 991 | g_free(channel->name); |
| 1325 | 992 | ndata->channels = g_slist_remove(ndata->channels, channel); |
| 1323 | 993 | g_free(channel); |
| 994 | } | |
| 1325 | 995 | |
| 1422 | 996 | while (ndata->browses) { |
| 997 | browse = (struct browse_window *)ndata->browses->data; | |
| 998 | g_free(browse->name); | |
| 999 | gtk_widget_destroy(browse->window); | |
| 1000 | ndata->browses = g_slist_remove(ndata->browses, browse); | |
| 1001 | g_free(browse); | |
| 1002 | } | |
| 1003 | ||
| 1004 | while (ndata->requests) { | |
| 1005 | req = (struct nap_file_request *)ndata->requests->data; | |
| 1006 | g_free(req->name); | |
| 1007 | g_free(req->file); | |
| 1008 | if (req->inpa) { | |
| 1009 | gdk_input_remove(req->inpa); | |
| 1010 | } | |
| 1011 | ndata->requests = g_slist_remove(ndata->requests, req); | |
| 1012 | g_free(req); | |
| 1013 | ||
| 1014 | } | |
| 1015 | ||
| 1325 | 1016 | free(gc->proto_data); |
| 1323 | 1017 | } |
| 1018 | ||
| 1019 | static void nap_add_buddies(struct gaim_connection *gc, GList *buddies) | |
| 1020 | { | |
| 1021 | while (buddies) { | |
| 1022 | nap_write_packet(gc, 0xd0, (char *)buddies->data); | |
| 1023 | buddies = buddies -> next; | |
| 1024 | } | |
| 1025 | } | |
| 1026 | ||
| 1338 | 1027 | static void nap_draw_new_user(GtkWidget *box) |
| 1028 | { | |
| 1029 | GtkWidget *label; | |
| 1030 | ||
| 1031 | label = gtk_label_new(_("Napster registration is currently under development")); | |
| 1032 | ||
| 1033 | gtk_label_set_line_wrap(GTK_LABEL(label), TRUE); | |
| 1034 | gtk_box_pack_start(GTK_BOX(box), label, FALSE, FALSE, 5); | |
| 1035 | gtk_widget_show(label); | |
| 1036 | } | |
| 1037 | ||
| 1422 | 1038 | |
|
1873
66c5f8b3f7fe
[gaim-migrate @ 1883]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
1764
diff
changeset
|
1039 | static void nap_send_browse(GtkObject *w, char *who) |
| 1422 | 1040 | { |
| 1041 | struct gaim_connection *gc = (struct gaim_connection *)gtk_object_get_user_data(w); | |
| 1042 | gchar buf[NAP_BUF_LEN]; | |
| 1043 | ||
| 1044 | g_snprintf(buf, NAP_BUF_LEN, "%s", who); | |
| 1045 | nap_write_packet(gc, 0xd3, buf); | |
| 1046 | } | |
| 1047 | ||
|
1873
66c5f8b3f7fe
[gaim-migrate @ 1883]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
1764
diff
changeset
|
1048 | static void nap_find_callback(GtkObject *w, GtkWidget *entry) |
| 1427 | 1049 | { |
| 1050 | struct gaim_connection *gc = (struct gaim_connection *)gtk_object_get_user_data(w); | |
| 1051 | gchar *search; | |
| 1052 | gchar buf[NAP_BUF_LEN]; | |
| 1053 | ||
| 1054 | search = gtk_entry_get_text(GTK_ENTRY(entry)); | |
| 1055 | g_snprintf(buf, NAP_BUF_LEN, "FILENAME CONTAINS \"%s\" MAX_RESULTS 50", search); | |
| 1056 | ||
| 1057 | nap_write_packet(gc, 0xc8, buf); | |
| 1058 | } | |
| 1059 | ||
|
1873
66c5f8b3f7fe
[gaim-migrate @ 1883]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
1764
diff
changeset
|
1060 | static void destroy_window(GtkObject *w, GtkWidget *win) |
| 1427 | 1061 | { |
| 1062 | gtk_widget_destroy(win); | |
| 1063 | } | |
| 1064 | ||
|
1873
66c5f8b3f7fe
[gaim-migrate @ 1883]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
1764
diff
changeset
|
1065 | static void nap_show_search(GtkObject *w, void *omit) |
| 1427 | 1066 | { |
| 1067 | struct gaim_connection *gc = (struct gaim_connection *)gtk_object_get_user_data(w); | |
| 1068 | ||
| 1069 | if (!search_dialog) | |
| 1070 | { | |
| 1071 | GtkWidget *window; | |
| 1072 | GtkWidget *sw; | |
| 1073 | GtkWidget *vbox; | |
| 1074 | GtkWidget *hbox; | |
| 1075 | GtkWidget *label; | |
| 1076 | GtkWidget *button; | |
| 1077 | GtkWidget *entry; | |
| 1078 | GtkWidget *list; | |
| 1079 | gchar *titles[5] = {"Mp3 Name", "Nick", "Size", "Bitrate", "Connection"}; | |
| 1080 | search_dialog = g_new0(struct search_window, 1); | |
| 1081 | ||
| 1082 | window = gtk_window_new(GTK_WINDOW_DIALOG); | |
| 1083 | ||
| 1084 | vbox = gtk_vbox_new(FALSE, 0); | |
| 1085 | ||
| 1086 | /* First Line */ | |
| 1087 | hbox = gtk_hbox_new(FALSE, 5); | |
| 1088 | label = gtk_label_new("Search for:"); | |
| 1089 | gtk_widget_show(label); | |
| 1090 | gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 5); | |
| 1091 | ||
| 1092 | entry = gtk_entry_new(); | |
| 1093 | gtk_widget_show(entry); | |
| 1094 | gtk_box_pack_start(GTK_BOX(hbox), entry, FALSE, FALSE, 5); | |
| 1095 | ||
| 1096 | button = gtk_button_new_with_label("Find"); | |
| 1097 | gtk_widget_show(button); | |
| 1098 | gtk_object_set_user_data(GTK_OBJECT(button), gc); | |
| 1099 | gtk_signal_connect(GTK_OBJECT(button), "clicked", GTK_SIGNAL_FUNC(nap_find_callback), entry); | |
| 1100 | ||
| 1101 | gtk_box_pack_start(GTK_BOX(hbox), button, FALSE, FALSE, 5); | |
| 1102 | ||
| 1103 | button = gtk_button_new_with_label("Cancel"); | |
| 1104 | gtk_widget_show(button); | |
| 1105 | gtk_box_pack_start(GTK_BOX(hbox), button, FALSE, FALSE, 5); | |
| 1106 | ||
| 1107 | ||
| 1108 | gtk_widget_show(hbox); | |
| 1109 | gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, 5); | |
| 1110 | /* End First List */ | |
| 1111 | ||
| 1112 | /* Second Line */ | |
| 1113 | ||
| 1114 | sw = gtk_scrolled_window_new(NULL, NULL); | |
| 1115 | ||
| 1116 | list = gtk_clist_new_with_titles(5, titles); | |
| 1117 | ||
| 1118 | gtk_clist_column_titles_show(GTK_CLIST(list)); | |
| 1119 | ||
| 1120 | gtk_signal_connect(GTK_OBJECT(list), "select-row", GTK_SIGNAL_FUNC(nap_handle_download_search), gc); | |
| 1121 | ||
| 1122 | gtk_container_add(GTK_CONTAINER(sw), list); | |
| 1123 | gtk_widget_show(list); | |
| 1124 | ||
| 1125 | gtk_box_pack_start(GTK_BOX(vbox), sw, FALSE, FALSE, 5); | |
| 1126 | ||
| 1127 | gtk_widget_show(sw); | |
| 1128 | ||
| 1129 | /* End Second Line */ | |
| 1130 | ||
| 1131 | gtk_widget_show(vbox); | |
| 1132 | ||
| 1133 | gtk_container_add(GTK_CONTAINER(window), vbox); | |
| 1134 | gtk_container_set_border_width(GTK_CONTAINER(window), 10); | |
| 1135 | ||
| 1136 | gtk_widget_set_usize(GTK_WIDGET(list), 500, 350); | |
| 1137 | gtk_widget_set_usize(GTK_WIDGET(window), 500, 400); | |
| 1138 | ||
| 1139 | gtk_signal_connect(GTK_OBJECT(window), "destroy", GTK_SIGNAL_FUNC(destroy_window), window); | |
| 1140 | gtk_widget_show(window); | |
| 1141 | ||
| 1142 | search_dialog->window = window; | |
| 1143 | search_dialog->list = list; | |
| 1144 | } | |
| 1145 | ||
| 1146 | gtk_widget_show(search_dialog->window); | |
| 1147 | } | |
| 1148 | ||
|
1499
0c3286729687
[gaim-migrate @ 1509]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
1496
diff
changeset
|
1149 | static void nap_buddy_menu(GtkWidget *menu, struct gaim_connection *gc, char *who) |
| 1422 | 1150 | { |
| 1151 | GtkWidget *button; | |
| 1152 | ||
| 1427 | 1153 | button = gtk_menu_item_new_with_label("Browse Files"); |
| 1422 | 1154 | gtk_signal_connect(GTK_OBJECT(button), "activate", GTK_SIGNAL_FUNC(nap_send_browse), who); |
| 1155 | gtk_object_set_user_data(GTK_OBJECT(button), gc); | |
| 1156 | gtk_menu_append(GTK_MENU(menu), button); | |
| 1157 | gtk_widget_show(button); | |
| 1427 | 1158 | |
| 1159 | button = gtk_menu_item_new_with_label("Search Napster"); | |
| 1160 | gtk_signal_connect(GTK_OBJECT(button), "activate", GTK_SIGNAL_FUNC(nap_show_search), NULL); | |
| 1161 | gtk_object_set_user_data(GTK_OBJECT(button), gc); | |
| 1162 | gtk_menu_append(GTK_MENU(menu), button); | |
| 1163 | gtk_widget_show(button); | |
| 1422 | 1164 | } |
| 1165 | ||
| 1327 | 1166 | static char** nap_list_icon(int uc) |
| 1167 | { | |
| 1168 | return napster_xpm; | |
| 1169 | } | |
| 1170 | ||
| 1323 | 1171 | static struct prpl *my_protocol = NULL; |
| 1172 | ||
|
1873
66c5f8b3f7fe
[gaim-migrate @ 1883]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
1764
diff
changeset
|
1173 | static void nap_init(struct prpl *ret) |
| 1323 | 1174 | { |
| 1175 | ret->protocol = PROTO_NAPSTER; | |
| 1176 | ret->name = nap_name; | |
| 1327 | 1177 | ret->list_icon = nap_list_icon; |
|
1499
0c3286729687
[gaim-migrate @ 1509]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
1496
diff
changeset
|
1178 | ret->buddy_menu = nap_buddy_menu; |
|
1881
bcd5d457cdbb
[gaim-migrate @ 1891]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
1873
diff
changeset
|
1179 | ret->user_opts = NULL; |
| 1323 | 1180 | ret->login = nap_login; |
| 1181 | ret->close = nap_close; | |
| 1182 | ret->send_im = nap_send_im; | |
| 1183 | ret->set_info = NULL; | |
| 1184 | ret->get_info = NULL; | |
| 1185 | ret->set_away = NULL; | |
| 1186 | ret->get_away_msg = NULL; | |
| 1187 | ret->set_dir = NULL; | |
| 1188 | ret->get_dir = NULL; | |
| 1189 | ret->dir_search = NULL; | |
| 1190 | ret->set_idle = NULL; | |
| 1191 | ret->change_passwd = NULL; | |
| 1192 | ret->add_buddy = nap_add_buddy; | |
| 1193 | ret->add_buddies = nap_add_buddies; | |
| 1194 | ret->remove_buddy = nap_remove_buddy; | |
| 1195 | ret->add_permit = NULL; | |
| 1196 | ret->rem_permit = NULL; | |
| 1197 | ret->add_deny = NULL; | |
| 1198 | ret->rem_deny = NULL; | |
| 1199 | ret->warn = NULL; | |
| 1200 | ret->accept_chat = NULL; | |
| 1201 | ret->join_chat = nap_join_chat; | |
| 1202 | ret->chat_invite = NULL; | |
| 1203 | ret->chat_leave = nap_chat_leave; | |
| 1204 | ret->chat_whisper = NULL; | |
| 1205 | ret->chat_send = nap_chat_send; | |
| 1206 | ret->keepalive = NULL; | |
| 1338 | 1207 | ret->draw_new_user = nap_draw_new_user; |
| 1323 | 1208 | |
| 1209 | my_protocol = ret; | |
| 1210 | } | |
| 1211 | ||
| 1212 | char *gaim_plugin_init(GModule * handle) | |
| 1213 | { | |
|
1443
0629a6c59f6b
[gaim-migrate @ 1453]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
1427
diff
changeset
|
1214 | load_protocol(nap_init, sizeof(struct prpl)); |
| 1323 | 1215 | return NULL; |
| 1216 | } | |
| 1217 | ||
| 1218 | void gaim_plugin_remove() | |
| 1219 | { | |
| 1220 | struct prpl *p = find_prpl(PROTO_NAPSTER); | |
| 1221 | if (p == my_protocol) | |
| 1222 | unload_protocol(p); | |
| 1223 | } |