comparison plugins/napster.c @ 1873:08ac51210d09

[gaim-migrate @ 1883] la la la la la la. cleanups. and proxy for napster. committer: Tailor Script <tailor@pidgin.im>
author Eric Warmenhoven <eric@warmenhoven.org>
date Mon, 21 May 2001 23:14:41 +0000
parents 1e0613d9526b
children a02584b98823
comparison
equal deleted inserted replaced
1872:efc899af4912 1873:08ac51210d09
38 #include <fcntl.h> 38 #include <fcntl.h>
39 #include <ctype.h> 39 #include <ctype.h>
40 #include "multi.h" 40 #include "multi.h"
41 #include "prpl.h" 41 #include "prpl.h"
42 #include "gaim.h" 42 #include "gaim.h"
43 #include "proxy.h"
43 #include "pixmaps/napster.xpm" 44 #include "pixmaps/napster.xpm"
44 45
45 #define NAP_BUF_LEN 4096 46 #define NAP_BUF_LEN 4096
47
48 #define USEROPT_PROXYHOST 2
49 #define USEROPT_PROXYPORT 3
50 #define USEROPT_PROXYTYPE 4
51 #define USEROPT_USER 5
52 #define USEROPT_PASS 6
46 53
47 GSList *nap_connections = NULL; 54 GSList *nap_connections = NULL;
48 55
49 static unsigned int chat_id = 0; 56 static unsigned int chat_id = 0;
50 57
83 FILE *mp3; 90 FILE *mp3;
84 GtkWidget *window; 91 GtkWidget *window;
85 GtkWidget *progress; 92 GtkWidget *progress;
86 GtkWidget *ok; 93 GtkWidget *ok;
87 GtkWidget *cancel; 94 GtkWidget *cancel;
95 struct gaim_connection *gc;
88 }; 96 };
89 97
90 struct nap_data { 98 struct nap_data {
91 int fd; 99 int fd;
92 int inpa; 100 int inpa;
114 return "Allows gaim to use the Napster protocol. Yes, kids, drugs are bad."; 122 return "Allows gaim to use the Napster protocol. Yes, kids, drugs are bad.";
115 } 123 }
116 124
117 125
118 /* FIXME: Make this use va_arg stuff */ 126 /* FIXME: Make this use va_arg stuff */
119 void nap_write_packet(struct gaim_connection *gc, unsigned short command, char *message) 127 static void nap_write_packet(struct gaim_connection *gc, unsigned short command, char *message)
120 { 128 {
121 struct nap_data *ndata = (struct nap_data *)gc->proto_data; 129 struct nap_data *ndata = (struct nap_data *)gc->proto_data;
122 unsigned short size; 130 unsigned short size;
123 131
124 size = strlen(message); 132 size = strlen(message);
126 write(ndata->fd, &command, 2); 134 write(ndata->fd, &command, 2);
127 write(ndata->fd, message, size); 135 write(ndata->fd, message, size);
128 136
129 } 137 }
130 138
131 void nap_send_download_req(struct gaim_connection *gc, char *who, char *file) 139 static void nap_send_download_req(struct gaim_connection *gc, char *who, char *file)
132 { 140 {
133 struct nap_data *ndata = (struct nap_data *)gc->proto_data; 141 struct nap_data *ndata = (struct nap_data *)gc->proto_data;
134 gchar buf[NAP_BUF_LEN]; 142 gchar buf[NAP_BUF_LEN];
135 143
136 g_snprintf(buf, NAP_BUF_LEN, "%s \"%s\"", who, file); 144 g_snprintf(buf, NAP_BUF_LEN, "%s \"%s\"", who, file);
141 } 149 }
142 150
143 // FIXME: These next two windows should really be together 151 // FIXME: These next two windows should really be together
144 // and should use the same clist style look too. 152 // and should use the same clist style look too.
145 153
146 void nap_handle_download(GtkCList *clist, gint row, gint col, GdkEventButton *event, gpointer user_data) 154 static void nap_handle_download(GtkCList *clist, gint row, gint col, GdkEventButton *event, gpointer user_data)
147 { 155 {
148 gchar **results; 156 gchar *results;
149 struct browse_window *bw = (struct browse_window *)user_data; 157 struct browse_window *bw = (struct browse_window *)user_data;
150 158
151 gtk_clist_get_text(GTK_CLIST(clist), row, 0, results); 159 gtk_clist_get_text(GTK_CLIST(clist), row, 0, &results);
152 160
153 nap_send_download_req(bw->gc, bw->name, results[0]); 161 nap_send_download_req(bw->gc, bw->name, results);
154 162
155 } 163 }
156 164
157 void nap_handle_download_search(GtkCList *clist, gint row, gint col, GdkEventButton *event, gpointer user_data) 165 static void nap_handle_download_search(GtkCList *clist, gint row, gint col, GdkEventButton *event, gpointer user_data)
158 { 166 {
159 gchar *filename; 167 gchar *filename;
160 gchar *nick; 168 gchar *nick;
161 169
162 int i = 0;
163 struct gaim_connection *gc = (struct gaim_connection *)user_data; 170 struct gaim_connection *gc = (struct gaim_connection *)user_data;
164 171
165 filename = (gchar *)gtk_clist_get_row_data(GTK_CLIST(clist), row); 172 filename = (gchar *)gtk_clist_get_row_data(GTK_CLIST(clist), row);
166 173
167 gtk_clist_get_text(GTK_CLIST(clist), row, 1, &nick); 174 gtk_clist_get_text(GTK_CLIST(clist), row, 1, &nick);
168 175
169 printf("Trying to download: %s from %s\n", filename, nick); 176 printf("Trying to download: %s from %s\n", filename, nick);
170 nap_send_download_req(gc, nick, filename); 177 nap_send_download_req(gc, nick, filename);
171 } 178 }
172 179
173 struct browse_window *browse_window_new(struct gaim_connection *gc, char *name) 180 static struct browse_window *browse_window_new(struct gaim_connection *gc, char *name)
174 { 181 {
175 struct browse_window *browse = g_new0(struct browse_window, 1); 182 struct browse_window *browse = g_new0(struct browse_window, 1);
176 struct nap_data *ndata = (struct nap_data *)gc->proto_data; 183 struct nap_data *ndata = (struct nap_data *)gc->proto_data;
177 184
178 browse->window = gtk_window_new(GTK_WINDOW_DIALOG); 185 browse->window = gtk_window_new(GTK_WINDOW_DIALOG);
188 195
189 /*FIXME: I dont like using select-row. Im lazy. Ill fix it later */ 196 /*FIXME: I dont like using select-row. Im lazy. Ill fix it later */
190 gtk_signal_connect(GTK_OBJECT(browse->list), "select-row", GTK_SIGNAL_FUNC(nap_handle_download), browse); 197 gtk_signal_connect(GTK_OBJECT(browse->list), "select-row", GTK_SIGNAL_FUNC(nap_handle_download), browse);
191 198
192 ndata->browses = g_slist_append(ndata->browses, browse); 199 ndata->browses = g_slist_append(ndata->browses, browse);
193 } 200
194 201 return browse;
195 void browse_window_add_file(struct browse_window *bw, char *name) 202 }
203
204 static void browse_window_add_file(struct browse_window *bw, char *name)
196 { 205 {
197 char *fn[1]; 206 char *fn[1];
198 fn[0] = strdup(name); 207 fn[0] = strdup(name);
199 printf("User '%s' has file '%s'\n", bw->name, name); 208 printf("User '%s' has file '%s'\n", bw->name, name);
200 gtk_clist_append(GTK_CLIST(bw->list), fn); 209 gtk_clist_append(GTK_CLIST(bw->list), fn);
224 return NULL; 233 return NULL;
225 } 234 }
226 235
227 static void nap_send_im(struct gaim_connection *gc, char *who, char *message, int away) 236 static void nap_send_im(struct gaim_connection *gc, char *who, char *message, int away)
228 { 237 {
229 struct nap_data *ndata = (struct nap_data *)gc->proto_data;
230 gchar buf[NAP_BUF_LEN]; 238 gchar buf[NAP_BUF_LEN];
231 239
232 g_snprintf(buf, NAP_BUF_LEN, "%s %s", who, message); 240 g_snprintf(buf, NAP_BUF_LEN, "%s %s", who, message);
233 nap_write_packet(gc, 0xCD, buf); 241 nap_write_packet(gc, 0xCD, buf);
234 } 242 }
275 return NULL; 283 return NULL;
276 } 284 }
277 285
278 static struct conversation *find_conversation_by_id(struct gaim_connection *gc, int id) 286 static struct conversation *find_conversation_by_id(struct gaim_connection *gc, int id)
279 { 287 {
280 struct nap_data *ndata = (struct nap_data *)gc->proto_data;
281 GSList *bc = gc->buddy_chats; 288 GSList *bc = gc->buddy_chats;
282 struct conversation *b = NULL; 289 struct conversation *b = NULL;
283 290
284 while (bc) { 291 while (bc) {
285 b = (struct conversation *)bc->data; 292 b = (struct conversation *)bc->data;
288 } 295 }
289 bc = bc->next; 296 bc = bc->next;
290 b = NULL; 297 b = NULL;
291 } 298 }
292 299
293 if (!b) {
294 return NULL;
295 }
296
297 return b; 300 return b;
298 } 301 }
299 302
300 /* This is a strange function. I smoke too many bad bad things :-) */ 303 /* This is a strange function. I smoke too many bad bad things :-) */
301 struct nap_file_request * find_request_by_fd(struct gaim_connection *gc, int fd) 304 static struct nap_file_request * find_request_by_fd(struct gaim_connection *gc, int fd)
302 { 305 {
303 struct nap_file_request *req; 306 struct nap_file_request *req;
304 struct nap_data *ndata = (struct nap_data *)gc->proto_data; 307 struct nap_data *ndata = (struct nap_data *)gc->proto_data;
305 GSList *requests; 308 GSList *requests;
306 309
324 struct gaim_connection *gc = (struct gaim_connection *)data; 327 struct gaim_connection *gc = (struct gaim_connection *)data;
325 struct nap_data *ndata = (struct nap_data *)gc->proto_data; 328 struct nap_data *ndata = (struct nap_data *)gc->proto_data;
326 struct nap_file_request *req; 329 struct nap_file_request *req;
327 unsigned char *buf; 330 unsigned char *buf;
328 int i = 0; 331 int i = 0;
329 gchar *c;
330 int len;
331 332
332 req = find_request_by_fd(gc, source); 333 req = find_request_by_fd(gc, source);
333 if (!req) /* Something bad happened */ 334 if (!req) /* Something bad happened */
334 return; 335 return;
335 336
478 fclose(req->mp3); 479 fclose(req->mp3);
479 close(source); 480 close(source);
480 } 481 }
481 } 482 }
482 483
483 void nap_get_file(struct gaim_connection *gc, gchar *user, gchar *file, unsigned long host, unsigned int port) 484 static void nap_get_file_connect(gpointer data, gint source, GdkInputCondition cond)
484 { 485 {
485 int fd;
486 struct sockaddr_in site;
487 char buf[NAP_BUF_LEN]; 486 char buf[NAP_BUF_LEN];
488 int inpa; 487 struct nap_file_request *req = data;
488 struct gaim_connection *gc = req->gc;
489 struct nap_data *ndata = (struct nap_data *)gc->proto_data;
490
491 if (source < 0) {
492 do_error_dialog("Error connecting to user", "Gaim: Napster error");
493 g_free(req->name);
494 g_free(req->file);
495 g_free(req);
496 return;
497 }
498
499 if (req->fd != source)
500 req->fd = source;
501
502 send(req->fd, "GET", 3, 0);
503
504 /* Send our request to the user */
505 g_snprintf(buf, sizeof(buf), "%s \"%s\" 0", gc->username, req->file);
506
507 send(req->fd, buf, strlen(buf), 0);
508
509 /* Add our request */
510 ndata->requests = g_slist_append(ndata->requests, req);
511
512 /* And start monitoring */
513 req->inpa = gdk_input_add(req->fd, GDK_INPUT_READ, nap_ctc_callback, gc);
514 }
515
516 static void nap_get_file(struct gaim_connection *gc, gchar *user, gchar *file, gchar *host, unsigned int port)
517 {
489 struct nap_file_request *req = g_new0(struct nap_file_request, 1); 518 struct nap_file_request *req = g_new0(struct nap_file_request, 1);
490 struct nap_data *ndata = (struct nap_data *)gc->proto_data; 519
491
492
493 site.sin_family = AF_INET;
494 site.sin_addr.s_addr = host;
495 site.sin_port = htons(port);
496
497 fd = socket(AF_INET, SOCK_STREAM, 0);
498
499 if (fd < 0) {
500 do_error_dialog("Error connecting to user", "Gaim: Napster error");
501 return;
502 }
503
504 /* Make a connection with the server */
505 if (connect(fd, (struct sockaddr *)&site, sizeof(site)) < 0) {
506 do_error_dialog("Error connecting to user", "Gaim: Napster error");
507 return;
508 }
509
510 req->fd = fd;
511 req->name = g_strdup(user); 520 req->name = g_strdup(user);
512 req->file = g_strdup(file); 521 req->file = g_strdup(file);
513 req->size = 0; 522 req->size = 0;
514 req->status = 0; 523 req->status = 0;
515 req->total = 0; 524 req->total = 0;
516 525 req->gc = gc;
517 send(fd, "GET", 3, 0); 526
518 527 /* Make a connection with the server */
519 /* Send our request to the user */ 528 req->fd = proxy_connect(host, port,
520 g_snprintf(buf, sizeof(buf), "%s \"%s\" 0",gc->username, file); 529 gc->user->proto_opt[USEROPT_PROXYHOST],
521 530 atoi(gc->user->proto_opt[USEROPT_PROXYPORT]),
522 send(fd, buf, strlen(buf), 0); 531 atoi(gc->user->proto_opt[USEROPT_PROXYTYPE]),
523 532 gc->user->proto_opt[USEROPT_USER],
524 /* Add our request */ 533 gc->user->proto_opt[USEROPT_PASS],
525 ndata->requests = g_slist_append(ndata->requests, req); 534 nap_get_file_connect, req);
526 535 if (req->fd < 0) {
527 /* And start monitoring */ 536 do_error_dialog("Error connecting to user", "Gaim: Napster error");
528 req->inpa = gdk_input_add(fd, GDK_INPUT_READ, nap_ctc_callback, gc); 537 g_free(req->name);
538 g_free(req->file);
539 g_free(req);
540 }
529 } 541 }
530 542
531 static void nap_callback(gpointer data, gint source, GdkInputCondition condition) 543 static void nap_callback(gpointer data, gint source, GdkInputCondition condition)
532 { 544 {
533 struct gaim_connection *gc = data; 545 struct gaim_connection *gc = data;
534 struct nap_data *ndata = gc->proto_data; 546 struct nap_data *ndata = gc->proto_data;
535 gchar *buf; 547 gchar *buf;
536 unsigned short header[2]; 548 unsigned short header[2];
537 int i = 0;
538 int len; 549 int len;
539 int command; 550 int command;
540 gchar **res; 551 gchar **res;
541 552
542 recv(source, header, 4, 0); 553 recv(source, header, 4, 0);
576 return; 587 return;
577 } 588 }
578 589
579 if (command == 0x195) { 590 if (command == 0x195) {
580 struct nap_channel *channel; 591 struct nap_channel *channel;
581 int id;
582 592
583 channel = find_channel_by_name(gc, buf); 593 channel = find_channel_by_name(gc, buf);
584 594
585 if (!channel) { 595 if (!channel) {
586 chat_id++; 596 chat_id++;
832 file[j] = buf[i]; 842 file[j] = buf[i];
833 } 843 }
834 file[j] = 0; 844 file[j] = 0;
835 845
836 /* Aaight. We dont need nuttin' else. Let's download the file */ 846 /* Aaight. We dont need nuttin' else. Let's download the file */
837 nap_get_file(gc, user, file, atol(hoststr), atoi(portstr)); 847 nap_get_file(gc, user, file, hoststr, atoi(portstr));
838 848
839 free(buf); 849 free(buf);
840 850
841 return; 851 return;
842 } 852 }
851 { 861 {
852 struct gaim_connection *gc = data; 862 struct gaim_connection *gc = data;
853 struct nap_data *ndata = gc->proto_data; 863 struct nap_data *ndata = gc->proto_data;
854 gchar buf[NAP_BUF_LEN]; 864 gchar buf[NAP_BUF_LEN];
855 unsigned short header[2]; 865 unsigned short header[2];
856 int i = 0;
857 int len; 866 int len;
858 int command; 867 int command;
859 868
860 read(source, header, 4); 869 read(source, header, 4);
861 len = header[0]; 870 len = header[0];
883 return; 892 return;
884 } 893 }
885 } 894 }
886 895
887 896
888 897 static void nap_login_connect(gpointer data, gint source, GdkInputCondition cond)
889 static void nap_login(struct aim_user *user) 898 {
890 { 899 struct gaim_connection *gc = data;
891 int fd; 900 struct nap_data *ndata = gc->proto_data;
892 struct hostent *host;
893 struct sockaddr_in site;
894 struct gaim_connection *gc = new_gaim_conn(user);
895 struct nap_data *ndata = gc->proto_data = g_new0(struct nap_data, 1);
896 char buf[NAP_BUF_LEN]; 901 char buf[NAP_BUF_LEN];
897 char c; 902
898 char z[4]; 903 if (source < 0) {
899 int i; 904 hide_login_progress(gc, "Unable to connect");
900 int status;
901
902 host = gethostbyname("64.124.41.187");
903
904 if (!host) {
905 hide_login_progress(gc, "Unable to resolve hostname");
906 signoff(gc); 905 signoff(gc);
907 return; 906 return;
908 } 907 }
909 908
910 site.sin_family = AF_INET; 909 if (ndata->fd != source)
911 site.sin_addr.s_addr = *(long *)(host->h_addr); 910 ndata->fd = source;
912 site.sin_port = htons(8888); 911
913
914 fd = socket(AF_INET, SOCK_STREAM, 0);
915 if (fd < 0) {
916 hide_login_progress(gc, "Unable to create socket");
917 signoff(gc);
918 return;
919 }
920
921 /* Make a connection with the server */
922 if (connect(fd, (struct sockaddr *)&site, sizeof(site)) < 0) {
923 hide_login_progress(gc, "Unable to connect.");
924 signoff(gc);
925 return;
926 }
927
928 ndata->fd = fd;
929
930 /* And write our signon data */ 912 /* And write our signon data */
931 g_snprintf(buf, NAP_BUF_LEN, "%s %s 0 \"gaimster\" 0", gc->username, gc->password); 913 g_snprintf(buf, NAP_BUF_LEN, "%s %s 0 \"gaimster\" 0", gc->username, gc->password);
932 nap_write_packet(gc, 0x02, buf); 914 nap_write_packet(gc, 0x02, buf);
933 915
934 /* And set up the input watcher */ 916 /* And set up the input watcher */
935 ndata->inpa = gdk_input_add(ndata->fd, GDK_INPUT_READ, nap_login_callback, gc); 917 ndata->inpa = gdk_input_add(ndata->fd, GDK_INPUT_READ, nap_login_callback, gc);
936 918 }
937 919
920
921 static void nap_login(struct aim_user *user)
922 {
923 struct gaim_connection *gc = new_gaim_conn(user);
924 struct nap_data *ndata = gc->proto_data = g_new0(struct nap_data, 1);
925
926 ndata->fd = proxy_connect("64.124.41.187", 8888,
927 user->proto_opt[USEROPT_PROXYHOST],
928 atoi(user->proto_opt[USEROPT_PROXYPORT]),
929 atoi(user->proto_opt[USEROPT_PROXYTYPE]),
930 user->proto_opt[USEROPT_USER], user->proto_opt[USEROPT_PASS],
931 nap_login_connect, gc);
932 if (ndata->fd < 0) {
933 hide_login_progress(gc, "Unable to connect");
934 signoff(gc);
935 }
938 } 936 }
939 937
940 static void nap_join_chat(struct gaim_connection *gc, int id, char *name) 938 static void nap_join_chat(struct gaim_connection *gc, int id, char *name)
941 { 939 {
942 struct nap_data *ndata = (struct nap_data *)gc->proto_data;
943 gchar buf[NAP_BUF_LEN]; 940 gchar buf[NAP_BUF_LEN];
944 941
945 /* Make sure the name has a # preceeding it */ 942 /* Make sure the name has a # preceeding it */
946 if (name[0] != '#') 943 if (name[0] != '#')
947 g_snprintf(buf, NAP_BUF_LEN, "#%s", name); 944 g_snprintf(buf, NAP_BUF_LEN, "#%s", name);
953 950
954 static void nap_chat_leave(struct gaim_connection *gc, int id) 951 static void nap_chat_leave(struct gaim_connection *gc, int id)
955 { 952 {
956 struct nap_data *ndata = (struct nap_data *)gc->proto_data; 953 struct nap_data *ndata = (struct nap_data *)gc->proto_data;
957 struct nap_channel *channel = NULL; 954 struct nap_channel *channel = NULL;
958 GSList *channels = ndata->channels;
959 955
960 channel = find_channel_by_id(gc, id); 956 channel = find_channel_by_id(gc, id);
961 957
962 if (!channel) /* Again, I'm not sure how this would happen */ 958 if (!channel) /* Again, I'm not sure how this would happen */
963 return; 959 return;
970 966
971 } 967 }
972 968
973 static void nap_chat_send(struct gaim_connection *gc, int id, char *message) 969 static void nap_chat_send(struct gaim_connection *gc, int id, char *message)
974 { 970 {
975 struct nap_data *ndata = (struct nap_data *)gc->proto_data;
976 struct nap_channel *channel = NULL; 971 struct nap_channel *channel = NULL;
977 gchar buf[NAP_BUF_LEN]; 972 gchar buf[NAP_BUF_LEN];
978 973
979 channel = find_channel_by_id(gc, id); 974 channel = find_channel_by_id(gc, id);
980 975
999 } 994 }
1000 995
1001 static void nap_close(struct gaim_connection *gc) 996 static void nap_close(struct gaim_connection *gc)
1002 { 997 {
1003 struct nap_data *ndata = (struct nap_data *)gc->proto_data; 998 struct nap_data *ndata = (struct nap_data *)gc->proto_data;
1004 gchar buf[NAP_BUF_LEN];
1005 struct nap_channel *channel; 999 struct nap_channel *channel;
1006 struct browse_window *browse; 1000 struct browse_window *browse;
1007 struct nap_file_request *req; 1001 struct nap_file_request *req;
1008 GSList *channels = ndata->channels;
1009 GSList *requests = ndata->requests;
1010 1002
1011 if (gc->inpa) 1003 if (gc->inpa)
1012 gdk_input_remove(gc->inpa); 1004 gdk_input_remove(gc->inpa);
1013 1005
1014 while (ndata->channels) { 1006 while (ndata->channels) {
1041 free(gc->proto_data); 1033 free(gc->proto_data);
1042 } 1034 }
1043 1035
1044 static void nap_add_buddies(struct gaim_connection *gc, GList *buddies) 1036 static void nap_add_buddies(struct gaim_connection *gc, GList *buddies)
1045 { 1037 {
1046 struct nap_data *ndata = (struct nap_data *)gc->proto_data;
1047 gchar buf[NAP_BUF_LEN];
1048 int n = 0;
1049
1050 while (buddies) { 1038 while (buddies) {
1051 nap_write_packet(gc, 0xd0, (char *)buddies->data); 1039 nap_write_packet(gc, 0xd0, (char *)buddies->data);
1052 buddies = buddies -> next; 1040 buddies = buddies -> next;
1053 } 1041 }
1054 } 1042 }
1063 gtk_box_pack_start(GTK_BOX(box), label, FALSE, FALSE, 5); 1051 gtk_box_pack_start(GTK_BOX(box), label, FALSE, FALSE, 5);
1064 gtk_widget_show(label); 1052 gtk_widget_show(label);
1065 } 1053 }
1066 1054
1067 1055
1068 void nap_send_browse(GtkObject *w, char *who) 1056 static void nap_send_browse(GtkObject *w, char *who)
1069 { 1057 {
1070 struct gaim_connection *gc = (struct gaim_connection *)gtk_object_get_user_data(w); 1058 struct gaim_connection *gc = (struct gaim_connection *)gtk_object_get_user_data(w);
1071 struct nap_data *ndata = (struct nap_data *)gc->proto_data;
1072 gchar buf[NAP_BUF_LEN]; 1059 gchar buf[NAP_BUF_LEN];
1073 1060
1074 g_snprintf(buf, NAP_BUF_LEN, "%s", who); 1061 g_snprintf(buf, NAP_BUF_LEN, "%s", who);
1075 nap_write_packet(gc, 0xd3, buf); 1062 nap_write_packet(gc, 0xd3, buf);
1076 } 1063 }
1077 1064
1078 void nap_find_callback(GtkObject *w, GtkWidget *entry) 1065 static void nap_find_callback(GtkObject *w, GtkWidget *entry)
1079 { 1066 {
1080 struct gaim_connection *gc = (struct gaim_connection *)gtk_object_get_user_data(w); 1067 struct gaim_connection *gc = (struct gaim_connection *)gtk_object_get_user_data(w);
1081 gchar *search; 1068 gchar *search;
1082 gchar buf[NAP_BUF_LEN]; 1069 gchar buf[NAP_BUF_LEN];
1083 1070
1085 g_snprintf(buf, NAP_BUF_LEN, "FILENAME CONTAINS \"%s\" MAX_RESULTS 50", search); 1072 g_snprintf(buf, NAP_BUF_LEN, "FILENAME CONTAINS \"%s\" MAX_RESULTS 50", search);
1086 1073
1087 nap_write_packet(gc, 0xc8, buf); 1074 nap_write_packet(gc, 0xc8, buf);
1088 } 1075 }
1089 1076
1090 void destroy_window(GtkObject *w, GtkWidget *win) 1077 static void destroy_window(GtkObject *w, GtkWidget *win)
1091 { 1078 {
1092 gtk_widget_destroy(win); 1079 gtk_widget_destroy(win);
1093 } 1080 }
1094 1081
1095 void nap_show_search(GtkObject *w, void *omit) 1082 static void nap_show_search(GtkObject *w, void *omit)
1096 { 1083 {
1097 struct gaim_connection *gc = (struct gaim_connection *)gtk_object_get_user_data(w); 1084 struct gaim_connection *gc = (struct gaim_connection *)gtk_object_get_user_data(w);
1098 1085
1099 if (!search_dialog) 1086 if (!search_dialog)
1100 { 1087 {
1196 static char** nap_list_icon(int uc) 1183 static char** nap_list_icon(int uc)
1197 { 1184 {
1198 return napster_xpm; 1185 return napster_xpm;
1199 } 1186 }
1200 1187
1188 static void nap_print_option(GtkEntry *entry, struct aim_user *user)
1189 {
1190 int entrynum;
1191
1192 entrynum = (int)gtk_object_get_user_data(GTK_OBJECT(entry));
1193
1194 if (entrynum == USEROPT_PROXYHOST) {
1195 g_snprintf(user->proto_opt[USEROPT_PROXYHOST],
1196 sizeof(user->proto_opt[USEROPT_PROXYHOST]), "%s", gtk_entry_get_text(entry));
1197 } else if (entrynum == USEROPT_PROXYPORT) {
1198 g_snprintf(user->proto_opt[USEROPT_PROXYPORT],
1199 sizeof(user->proto_opt[USEROPT_PROXYPORT]), "%s", gtk_entry_get_text(entry));
1200 } else if (entrynum == USEROPT_USER) {
1201 g_snprintf(user->proto_opt[USEROPT_USER],
1202 sizeof(user->proto_opt[USEROPT_USER]), "%s", gtk_entry_get_text(entry));
1203 } else if (entrynum == USEROPT_PASS) {
1204 g_snprintf(user->proto_opt[USEROPT_PASS],
1205 sizeof(user->proto_opt[USEROPT_PASS]), "%s", gtk_entry_get_text(entry));
1206 }
1207 }
1208
1209 static void nap_print_optionrad(GtkRadioButton * entry, struct aim_user *user)
1210 {
1211 int entrynum;
1212
1213 entrynum = (int)gtk_object_get_user_data(GTK_OBJECT(entry));
1214
1215 g_snprintf(user->proto_opt[USEROPT_PROXYTYPE],
1216 sizeof(user->proto_opt[USEROPT_PROXYTYPE]), "%d", entrynum);
1217 }
1218
1219 static void nap_user_opts(GtkWidget * book, struct aim_user *user)
1220 {
1221 /* so here, we create the new notebook page */
1222 GtkWidget *vbox;
1223 GtkWidget *hbox;
1224 GtkWidget *label;
1225 GtkWidget *entry;
1226 GtkWidget *first, *opt;
1227
1228 vbox = gtk_vbox_new(FALSE, 5);
1229 gtk_container_set_border_width(GTK_CONTAINER(vbox), 5);
1230 gtk_notebook_append_page(GTK_NOTEBOOK(book), vbox, gtk_label_new("Napster Options"));
1231 gtk_widget_show(vbox);
1232
1233 hbox = gtk_hbox_new(TRUE, 0);
1234 gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, 0);
1235 gtk_widget_show(hbox);
1236
1237 first = gtk_radio_button_new_with_label(NULL, "No proxy");
1238 gtk_box_pack_start(GTK_BOX(hbox), first, FALSE, FALSE, 0);
1239 gtk_object_set_user_data(GTK_OBJECT(first), (void *)PROXY_NONE);
1240 gtk_signal_connect(GTK_OBJECT(first), "clicked", GTK_SIGNAL_FUNC(nap_print_optionrad), user);
1241 gtk_widget_show(first);
1242 if (atoi(user->proto_opt[USEROPT_PROXYTYPE]) == PROXY_NONE)
1243 gtk_toggle_button_set_state(GTK_TOGGLE_BUTTON(first), TRUE);
1244
1245 opt =
1246 gtk_radio_button_new_with_label(gtk_radio_button_group(GTK_RADIO_BUTTON(first)), "SOCKS 4");
1247 gtk_box_pack_start(GTK_BOX(hbox), opt, FALSE, FALSE, 0);
1248 gtk_object_set_user_data(GTK_OBJECT(opt), (void *)PROXY_SOCKS4);
1249 gtk_signal_connect(GTK_OBJECT(opt), "clicked", GTK_SIGNAL_FUNC(nap_print_optionrad), user);
1250 gtk_widget_show(opt);
1251 if (atoi(user->proto_opt[USEROPT_PROXYTYPE]) == PROXY_SOCKS4)
1252 gtk_toggle_button_set_state(GTK_TOGGLE_BUTTON(opt), TRUE);
1253
1254 hbox = gtk_hbox_new(TRUE, 0);
1255 gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, 0);
1256 gtk_widget_show(hbox);
1257
1258 opt =
1259 gtk_radio_button_new_with_label(gtk_radio_button_group(GTK_RADIO_BUTTON(first)), "SOCKS 5");
1260 gtk_box_pack_start(GTK_BOX(hbox), opt, FALSE, FALSE, 0);
1261 gtk_object_set_user_data(GTK_OBJECT(opt), (void *)PROXY_SOCKS5);
1262 gtk_signal_connect(GTK_OBJECT(opt), "clicked", GTK_SIGNAL_FUNC(nap_print_optionrad), user);
1263 gtk_widget_show(opt);
1264 if (atoi(user->proto_opt[USEROPT_PROXYTYPE]) == PROXY_SOCKS5)
1265 gtk_toggle_button_set_state(GTK_TOGGLE_BUTTON(opt), TRUE);
1266
1267 opt = gtk_radio_button_new_with_label(gtk_radio_button_group(GTK_RADIO_BUTTON(first)), "HTTP");
1268 gtk_box_pack_start(GTK_BOX(hbox), opt, FALSE, FALSE, 0);
1269 gtk_object_set_user_data(GTK_OBJECT(opt), (void *)PROXY_HTTP);
1270 gtk_signal_connect(GTK_OBJECT(opt), "clicked", GTK_SIGNAL_FUNC(nap_print_optionrad), user);
1271 gtk_widget_show(opt);
1272 if (atoi(user->proto_opt[USEROPT_PROXYTYPE]) == PROXY_HTTP)
1273 gtk_toggle_button_set_state(GTK_TOGGLE_BUTTON(opt), TRUE);
1274
1275 hbox = gtk_hbox_new(FALSE, 0);
1276 gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, 0);
1277 gtk_widget_show(hbox);
1278
1279 label = gtk_label_new("Proxy Host:");
1280 gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 0);
1281 gtk_widget_show(label);
1282
1283 entry = gtk_entry_new();
1284 gtk_box_pack_end(GTK_BOX(hbox), entry, FALSE, FALSE, 0);
1285 gtk_object_set_user_data(GTK_OBJECT(entry), (void *)USEROPT_PROXYHOST);
1286 gtk_signal_connect(GTK_OBJECT(entry), "changed", GTK_SIGNAL_FUNC(nap_print_option), user);
1287 if (user->proto_opt[USEROPT_PROXYHOST][0]) {
1288 debug_printf("setting text %s\n", user->proto_opt[USEROPT_PROXYHOST]);
1289 gtk_entry_set_text(GTK_ENTRY(entry), user->proto_opt[USEROPT_PROXYHOST]);
1290 }
1291 gtk_widget_show(entry);
1292
1293 hbox = gtk_hbox_new(FALSE, 0);
1294 gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, 0);
1295 gtk_widget_show(hbox);
1296
1297 label = gtk_label_new("Proxy Port:");
1298 gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 0);
1299 gtk_widget_show(label);
1300
1301 entry = gtk_entry_new();
1302 gtk_box_pack_end(GTK_BOX(hbox), entry, FALSE, FALSE, 0);
1303 gtk_object_set_user_data(GTK_OBJECT(entry), (void *)USEROPT_PROXYPORT);
1304 gtk_signal_connect(GTK_OBJECT(entry), "changed", GTK_SIGNAL_FUNC(nap_print_option), user);
1305 if (user->proto_opt[USEROPT_PROXYPORT][0]) {
1306 debug_printf("setting text %s\n", user->proto_opt[USEROPT_PROXYPORT]);
1307 gtk_entry_set_text(GTK_ENTRY(entry), user->proto_opt[USEROPT_PROXYPORT]);
1308 }
1309 gtk_widget_show(entry);
1310
1311 hbox = gtk_hbox_new(FALSE, 0);
1312 gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, 0);
1313 gtk_widget_show(hbox);
1314
1315 label = gtk_label_new("Proxy User:");
1316 gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 0);
1317 gtk_widget_show(label);
1318
1319 entry = gtk_entry_new();
1320 gtk_box_pack_end(GTK_BOX(hbox), entry, FALSE, FALSE, 0);
1321 gtk_object_set_user_data(GTK_OBJECT(entry), (void *)USEROPT_USER);
1322 gtk_signal_connect(GTK_OBJECT(entry), "changed", GTK_SIGNAL_FUNC(nap_print_option), user);
1323 if (user->proto_opt[USEROPT_USER][0]) {
1324 debug_printf("setting text %s\n", user->proto_opt[USEROPT_USER]);
1325 gtk_entry_set_text(GTK_ENTRY(entry), user->proto_opt[USEROPT_USER]);
1326 }
1327 gtk_widget_show(entry);
1328
1329 hbox = gtk_hbox_new(FALSE, 5);
1330 gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, 0);
1331 gtk_widget_show(hbox);
1332
1333 label = gtk_label_new("Proxy Password:");
1334 gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 0);
1335 gtk_widget_show(label);
1336
1337 entry = gtk_entry_new();
1338 gtk_box_pack_end(GTK_BOX(hbox), entry, FALSE, FALSE, 0);
1339 gtk_entry_set_visibility(GTK_ENTRY(entry), FALSE);
1340 gtk_object_set_user_data(GTK_OBJECT(entry), (void *)USEROPT_PASS);
1341 gtk_signal_connect(GTK_OBJECT(entry), "changed", GTK_SIGNAL_FUNC(nap_print_option), user);
1342 if (user->proto_opt[USEROPT_PASS][0]) {
1343 debug_printf("setting text %s\n", user->proto_opt[USEROPT_PASS]);
1344 gtk_entry_set_text(GTK_ENTRY(entry), user->proto_opt[USEROPT_PASS]);
1345 }
1346 gtk_widget_show(entry);
1347 }
1348
1201 static struct prpl *my_protocol = NULL; 1349 static struct prpl *my_protocol = NULL;
1202 1350
1203 void nap_init(struct prpl *ret) 1351 static void nap_init(struct prpl *ret)
1204 { 1352 {
1205 ret->protocol = PROTO_NAPSTER; 1353 ret->protocol = PROTO_NAPSTER;
1206 ret->name = nap_name; 1354 ret->name = nap_name;
1207 ret->list_icon = nap_list_icon; 1355 ret->list_icon = nap_list_icon;
1208 ret->buddy_menu = nap_buddy_menu; 1356 ret->buddy_menu = nap_buddy_menu;
1209 ret->user_opts = NULL; 1357 ret->user_opts = nap_user_opts;
1210 ret->login = nap_login; 1358 ret->login = nap_login;
1211 ret->close = nap_close; 1359 ret->close = nap_close;
1212 ret->send_im = nap_send_im; 1360 ret->send_im = nap_send_im;
1213 ret->set_info = NULL; 1361 ret->set_info = NULL;
1214 ret->get_info = NULL; 1362 ret->get_info = NULL;