annotate plugins/napster.c @ 1337:198b0e53d7c3

[gaim-migrate @ 1347] hehe committer: Tailor Script <tailor@pidgin.im>
author Rob Flynn <gaim@robflynn.com>
date Wed, 20 Dec 2000 23:56:03 +0000
parents e2d8b713d928
children 2e046be5e44a
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1323
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
1 /*
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
2 * gaim - Napster Protocol Plugin
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
3 *
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
4 * Copyright (C) 2000, Rob Flynn <rob@tgflinux.com>
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
5 *
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
6 * This program is free software; you can redistribute it and/or modify
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
7 * it under the terms of the GNU General Public License as published by
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
8 * the Free Software Foundation; either version 2 of the License, or
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
9 * (at your option) any later version.
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
10 *
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
11 * This program is distributed in the hope that it will be useful,
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
14 * GNU General Public License for more details.
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
15 *
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
16 * You should have received a copy of the GNU General Public License
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
17 * along with this program; if not, write to the Free Software
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
19 *
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
20 */
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
21
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
22 #include "../config.h"
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
23
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
24 #include <netdb.h>
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
25 #include <gtk/gtk.h>
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
26 #include <unistd.h>
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
27 #include <errno.h>
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
28 #include <netinet/in.h>
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
29 #include <arpa/inet.h>
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
30 #include <time.h>
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
31 #include <string.h>
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
32 #include <stdlib.h>
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
33 #include <stdio.h>
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
34 #include <time.h>
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
35 #include <sys/socket.h>
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
36 #include <sys/stat.h>
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
37 #include "multi.h"
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
38 #include "prpl.h"
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
39 #include "gaim.h"
1327
113a3d16f1ce [gaim-migrate @ 1337]
Rob Flynn <gaim@robflynn.com>
parents: 1325
diff changeset
40 #include "pixmaps/napster.xpm"
1323
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
41
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
42 #define NAP_BUF_LEN 4096
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
43
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
44 GSList *nap_connections = NULL;
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
45
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
46 static unsigned int chat_id = 0;
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
47
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
48 struct nap_channel {
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
49 unsigned int id;
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
50 gchar *name;
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
51 };
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
52
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
53 struct nap_data {
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
54 int fd;
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
55 int inpa;
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
56
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
57 gchar *email;
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
58 GSList *channels;
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
59 };
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
60
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
61 static char *nap_name()
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
62 {
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
63 return "Napster";
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
64 }
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
65
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
66 char *name()
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
67 {
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
68 return "Napster";
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
69 }
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
70
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
71 char *description()
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
72 {
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
73 return "Allows gaim to use the Napster protocol. Yes, kids, drugs are bad.";
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
74 }
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
75
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
76
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
77 /* FIXME: Make this use va_arg stuff */
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
78 void nap_write_packet(struct gaim_connection *gc, unsigned short command, char *message)
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
79 {
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
80 struct nap_data *ndata = (struct nap_data *)gc->proto_data;
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
81 unsigned short size;
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
82
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
83 size = strlen(message);
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
84
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
85 write(ndata->fd, &size, 2);
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
86 write(ndata->fd, &command, 2);
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
87 write(ndata->fd, message, size);
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
88 }
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
89
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
90 static void nap_send_im(struct gaim_connection *gc, char *who, char *message, int away)
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
91 {
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
92 struct nap_data *ndata = (struct nap_data *)gc->proto_data;
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
93 gchar buf[NAP_BUF_LEN];
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
94
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
95 g_snprintf(buf, NAP_BUF_LEN, "%s %s", who, message);
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
96 nap_write_packet(gc, 0xCD, buf);
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
97 }
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
98
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
99 static struct nap_channel *find_channel_by_name(struct gaim_connection *gc, char *name)
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
100 {
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
101 struct nap_channel *channel;
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
102 struct nap_data *ndata = (struct nap_data *)gc->proto_data;
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
103 GSList *channels;
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
104
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
105 channels = ndata->channels;
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
106
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
107 while (channels) {
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
108 channel = (struct nap_channel *)channels->data;
1325
08aa745310f6 [gaim-migrate @ 1335]
Rob Flynn <gaim@robflynn.com>
parents: 1323
diff changeset
109
08aa745310f6 [gaim-migrate @ 1335]
Rob Flynn <gaim@robflynn.com>
parents: 1323
diff changeset
110 if (channel) {
08aa745310f6 [gaim-migrate @ 1335]
Rob Flynn <gaim@robflynn.com>
parents: 1323
diff changeset
111 if (!g_strcasecmp(name, channel->name)) {
08aa745310f6 [gaim-migrate @ 1335]
Rob Flynn <gaim@robflynn.com>
parents: 1323
diff changeset
112 return channel;
08aa745310f6 [gaim-migrate @ 1335]
Rob Flynn <gaim@robflynn.com>
parents: 1323
diff changeset
113 }
1323
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
114 }
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
115 channels = g_slist_next(channels);
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
116 }
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
117
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
118 return NULL;
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
119 }
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
120
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
121 static struct nap_channel *find_channel_by_id(struct gaim_connection *gc, int id)
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
122 {
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
123 struct nap_channel *channel;
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
124 struct nap_data *ndata = (struct nap_data *)gc->proto_data;
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
125 GSList *channels;
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
126
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
127 channels = ndata->channels;
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
128
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
129 while (channels) {
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
130 channel = (struct nap_channel *)channels->data;
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
131 if (id == channel->id) {
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
132 return channel;
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
133 }
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
134
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
135 channels = g_slist_next(channels);
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
136 }
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
137
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
138 return NULL;
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
139 }
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
140
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
141 static struct conversation *find_conversation_by_id(struct gaim_connection *gc, int id)
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
142 {
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
143 struct nap_data *ndata = (struct nap_data *)gc->proto_data;
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
144 GSList *bc = gc->buddy_chats;
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
145 struct conversation *b = NULL;
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
146
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
147 while (bc) {
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
148 b = (struct conversation *)bc->data;
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
149 if (id == b->id) {
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
150 break;
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
151 }
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
152 bc = bc->next;
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
153 b = NULL;
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
154 }
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
155
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
156 if (!b) {
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
157 return NULL;
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
158 }
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
159
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
160 return b;
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
161 }
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
162
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
163 static void nap_callback(gpointer data, gint source, GdkInputCondition condition)
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
164 {
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
165 struct gaim_connection *gc = data;
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
166 struct nap_data *ndata = gc->proto_data;
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
167 gchar *buf;
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
168 unsigned short header[2];
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
169 int i = 0;
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
170 int len;
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
171 int command;
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
172 gchar **res;
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
173
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
174 read(source, header, 4);
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
175 len = header[0];
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
176 command = header[1];
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
177
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
178 buf = (gchar *)g_malloc(sizeof(gchar) * (len + 1));
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
179
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
180 read(source, buf, len);
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
181
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
182 buf[len] = 0;
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
183
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
184 if (command == 0xd6) {
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
185 res = g_strsplit(buf, " ", 0);
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
186 /* Do we want to report what the users are doing? */
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
187 printf("users: %s, files: %s, size: %sGB\n", res[0], res[1], res[2]);
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
188 g_strfreev(res);
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
189 free(buf);
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
190 return;
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
191 }
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
192
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
193 if (command == 0x26d) {
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
194 /* Do we want to use the MOTD? */
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
195 free(buf);
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
196 return;
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
197 }
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
198
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
199 if (command == 0xCD) {
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
200 res = g_strsplit(buf, " ", 1);
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
201 serv_got_im(gc, res[0], res[1], 0);
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
202 g_strfreev(res);
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
203 free(buf);
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
204 return;
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
205 }
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
206
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
207 if (command == 0x195) {
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
208 struct nap_channel *channel;
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
209 int id;
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
210
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
211 channel = find_channel_by_name(gc, buf);
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
212
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
213 if (!channel) {
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
214 chat_id++;
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
215
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
216 channel = g_new0(struct nap_channel, 1);
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
217
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
218 channel->id = chat_id;
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
219 channel->name = g_strdup(buf);
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
220
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
221 ndata->channels = g_slist_append(ndata->channels, channel);
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
222
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
223 serv_got_joined_chat(gc, chat_id, buf);
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
224 }
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
225
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
226 free(buf);
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
227 return;
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
228 }
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
229
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
230 if (command == 0x198 || command == 0x196) {
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
231 struct nap_channel *channel;
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
232 struct conversation *convo;
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
233 gchar **res;
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
234
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
235 res = g_strsplit(buf, " ", 0);
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
236
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
237 channel = find_channel_by_name(gc, res[0]);
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
238 convo = find_conversation_by_id(gc, channel->id);
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
239
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
240 add_chat_buddy(convo, res[1]);
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
241
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
242 g_strfreev(res);
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
243
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
244 free(buf);
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
245 return;
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
246 }
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
247
1325
08aa745310f6 [gaim-migrate @ 1335]
Rob Flynn <gaim@robflynn.com>
parents: 1323
diff changeset
248 if (command == 0x197) {
08aa745310f6 [gaim-migrate @ 1335]
Rob Flynn <gaim@robflynn.com>
parents: 1323
diff changeset
249 struct nap_channel *channel;
08aa745310f6 [gaim-migrate @ 1335]
Rob Flynn <gaim@robflynn.com>
parents: 1323
diff changeset
250 struct conversation *convo;
08aa745310f6 [gaim-migrate @ 1335]
Rob Flynn <gaim@robflynn.com>
parents: 1323
diff changeset
251 gchar **res;
08aa745310f6 [gaim-migrate @ 1335]
Rob Flynn <gaim@robflynn.com>
parents: 1323
diff changeset
252
08aa745310f6 [gaim-migrate @ 1335]
Rob Flynn <gaim@robflynn.com>
parents: 1323
diff changeset
253 res = g_strsplit(buf, " ", 0);
08aa745310f6 [gaim-migrate @ 1335]
Rob Flynn <gaim@robflynn.com>
parents: 1323
diff changeset
254
08aa745310f6 [gaim-migrate @ 1335]
Rob Flynn <gaim@robflynn.com>
parents: 1323
diff changeset
255 channel = find_channel_by_name(gc, res[0]);
08aa745310f6 [gaim-migrate @ 1335]
Rob Flynn <gaim@robflynn.com>
parents: 1323
diff changeset
256 convo = find_conversation_by_id(gc, channel->id);
08aa745310f6 [gaim-migrate @ 1335]
Rob Flynn <gaim@robflynn.com>
parents: 1323
diff changeset
257
08aa745310f6 [gaim-migrate @ 1335]
Rob Flynn <gaim@robflynn.com>
parents: 1323
diff changeset
258 remove_chat_buddy(convo, res[1]);
08aa745310f6 [gaim-migrate @ 1335]
Rob Flynn <gaim@robflynn.com>
parents: 1323
diff changeset
259
08aa745310f6 [gaim-migrate @ 1335]
Rob Flynn <gaim@robflynn.com>
parents: 1323
diff changeset
260 g_strfreev(res);
08aa745310f6 [gaim-migrate @ 1335]
Rob Flynn <gaim@robflynn.com>
parents: 1323
diff changeset
261 free(buf);
08aa745310f6 [gaim-migrate @ 1335]
Rob Flynn <gaim@robflynn.com>
parents: 1323
diff changeset
262 return;
08aa745310f6 [gaim-migrate @ 1335]
Rob Flynn <gaim@robflynn.com>
parents: 1323
diff changeset
263 }
08aa745310f6 [gaim-migrate @ 1335]
Rob Flynn <gaim@robflynn.com>
parents: 1323
diff changeset
264
1323
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
265 if (command == 0x193) {
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
266 gchar **res;
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
267 struct nap_channel *channel;
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
268
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
269 res = g_strsplit(buf, " ", 2);
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
270
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
271 channel = find_channel_by_name(gc, res[0]);
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
272
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
273 if (channel)
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
274 serv_got_chat_in(gc, channel->id, res[1], 0, res[2]);
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
275
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
276 g_strfreev(res);
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
277 free(buf);
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
278 return;
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
279 }
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
280
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
281 if (command == 0x194) {
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
282 do_error_dialog(buf, "Gaim: Napster Error");
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
283 free(buf);
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
284 return;
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
285 }
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
286
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
287 if (command == 0x12e) {
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
288 gchar buf2[NAP_BUF_LEN];
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
289
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
290 g_snprintf(buf2, NAP_BUF_LEN, "Unable to add '%s' to your hotlist", buf);
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
291 do_error_dialog(buf2, "Gaim: Napster Error");
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
292
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
293 free(buf);
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
294 return;
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
295
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
296 }
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
297
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
298 if (command == 0x191) {
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
299 struct nap_channel *channel;
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
300
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
301 channel = find_channel_by_name(gc, buf);
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
302
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
303 if (!channel) /* I'm not sure how this would happen =) */
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
304 return;
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
305
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
306 serv_got_chat_left(gc, channel->id);
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
307 ndata->channels = g_slist_remove(ndata->channels, channel);
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
308
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
309 free(buf);
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
310 return;
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
311
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
312 }
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
313
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
314 if (command == 0xd1) {
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
315 gchar **res;
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
316
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
317 res = g_strsplit(buf, " ", 0);
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
318
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
319 serv_got_update(gc, res[0], 1, 0, time((time_t *)NULL), 0, 0, 0);
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
320
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
321 g_strfreev(res);
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
322 free(buf);
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
323 return;
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
324 }
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
325
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
326 if (command == 0xd2) {
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
327 serv_got_update(gc, buf, 0, 0, 0, 0, 0, 0);
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
328 free(buf);
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
329 return;
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
330 }
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
331
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
332 if (command == 0x12d) {
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
333 /* Our buddy was added successfully */
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
334 free(buf);
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
335 return;
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
336 }
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
337
1329
e2d8b713d928 [gaim-migrate @ 1339]
Rob Flynn <gaim@robflynn.com>
parents: 1327
diff changeset
338 if (command == 0x2ec) {
e2d8b713d928 [gaim-migrate @ 1339]
Rob Flynn <gaim@robflynn.com>
parents: 1327
diff changeset
339 /* Looks like someone logged in as us! =-O */
e2d8b713d928 [gaim-migrate @ 1339]
Rob Flynn <gaim@robflynn.com>
parents: 1327
diff changeset
340 free(buf);
e2d8b713d928 [gaim-migrate @ 1339]
Rob Flynn <gaim@robflynn.com>
parents: 1327
diff changeset
341
e2d8b713d928 [gaim-migrate @ 1339]
Rob Flynn <gaim@robflynn.com>
parents: 1327
diff changeset
342 signoff(gc);
e2d8b713d928 [gaim-migrate @ 1339]
Rob Flynn <gaim@robflynn.com>
parents: 1327
diff changeset
343 return;
e2d8b713d928 [gaim-migrate @ 1339]
Rob Flynn <gaim@robflynn.com>
parents: 1327
diff changeset
344 }
e2d8b713d928 [gaim-migrate @ 1339]
Rob Flynn <gaim@robflynn.com>
parents: 1327
diff changeset
345
1323
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
346 printf("NAP: [COMMAND: 0x%04x] %s\n", command, buf);
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
347 }
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
348
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
349
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
350 static void nap_login_callback(gpointer data, gint source, GdkInputCondition condition)
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
351 {
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
352 struct gaim_connection *gc = data;
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
353 struct nap_data *ndata = gc->proto_data;
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
354 gchar buf[NAP_BUF_LEN];
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
355 unsigned short header[2];
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
356 int i = 0;
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
357 int len;
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
358 int command;
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
359
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
360 read(source, header, 4);
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
361 len = header[0];
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
362 command = header[1];
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
363
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
364 read(source, buf, len);
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
365 buf[len] = 0;
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
366
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
367 if (command == 0x03) {
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
368 printf("Registered with E-Mail address of: %s\n", buf);
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
369 ndata->email = g_strdup(buf);
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
370
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
371 /* Remove old inpa, add new one */
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
372 gdk_input_remove(ndata->inpa);
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
373 ndata->inpa = 0;
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
374 gc->inpa = gdk_input_add(ndata->fd, GDK_INPUT_READ, nap_callback, gc);
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
375
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
376 /* Our signon is complete */
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
377 account_online(gc);
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
378 serv_finish_login(gc);
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
379
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
380 if (bud_list_cache_exists(gc))
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
381 do_import(NULL, gc);
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
382
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
383 return;
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
384 }
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
385 }
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
386
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
387
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
388
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
389 static void nap_login(struct aim_user *user)
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
390 {
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
391 int fd;
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
392 struct hostent *host;
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
393 struct sockaddr_in site;
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
394 struct gaim_connection *gc = new_gaim_conn(user);
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
395 struct nap_data *ndata = gc->proto_data = g_new0(struct nap_data, 1);
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
396 char buf[NAP_BUF_LEN];
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
397 char c;
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
398 char z[4];
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
399 int i;
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
400 int status;
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
401
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
402 host = gethostbyname("64.124.41.184");
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
403
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
404 if (!host) {
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
405 hide_login_progress(gc, "Unable to resolve hostname");
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
406 signoff(gc);
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
407 return;
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
408 }
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
409
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
410 site.sin_family = AF_INET;
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
411 site.sin_addr.s_addr = *(long *)(host->h_addr);
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
412
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
413 site.sin_port = htons(8888);
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
414
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
415 fd = socket(AF_INET, SOCK_STREAM, 0);
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
416 if (fd < 0) {
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
417 hide_login_progress(gc, "Unable to create socket");
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
418 signoff(gc);
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
419 return;
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
420 }
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
421
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
422 /* Make a connection with the server */
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
423 if (connect(fd, (struct sockaddr *)&site, sizeof(site)) < 0) {
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
424 hide_login_progress(gc, "Unable to connect.");
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
425 signoff(gc);
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
426 return;
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
427 }
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
428
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
429 ndata->fd = fd;
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
430
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
431 /* And write our signon data */
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
432 g_snprintf(buf, NAP_BUF_LEN, "%s %s 0 \"Gnapster 1.4.1a\" 0", gc->username, gc->password);
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
433 nap_write_packet(gc, 0x02, buf);
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
434
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
435 /* And set up the input watcher */
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
436 ndata->inpa = gdk_input_add(ndata->fd, GDK_INPUT_READ, nap_login_callback, gc);
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
437
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
438 }
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
439
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
440 static void nap_join_chat(struct gaim_connection *gc, int id, char *name)
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
441 {
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
442 struct nap_data *ndata = (struct nap_data *)gc->proto_data;
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
443 gchar buf[NAP_BUF_LEN];
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
444
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
445 /* Make sure the name has a # preceeding it */
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
446 if (name[0] != '#')
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
447 g_snprintf(buf, NAP_BUF_LEN, "#%s", name);
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
448 else
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
449 g_snprintf(buf, NAP_BUF_LEN, "%s", name);
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
450
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
451 nap_write_packet(gc, 0x190, buf);
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
452 }
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
453
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
454 static void nap_chat_leave(struct gaim_connection *gc, int id)
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
455 {
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
456 struct nap_data *ndata = (struct nap_data *)gc->proto_data;
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
457 struct nap_channel *channel = NULL;
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
458 GSList *channels = ndata->channels;
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
459
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
460 channel = find_channel_by_id(gc, id);
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
461
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
462 if (!channel) /* Again, I'm not sure how this would happen */
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
463 return;
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
464
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
465 nap_write_packet(gc, 0x191, channel->name);
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
466
1325
08aa745310f6 [gaim-migrate @ 1335]
Rob Flynn <gaim@robflynn.com>
parents: 1323
diff changeset
467 ndata->channels = g_slist_remove(ndata->channels, channel);
1323
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
468 g_free(channel->name);
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
469 g_free(channel);
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
470
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
471 }
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
472
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
473 static void nap_chat_send(struct gaim_connection *gc, int id, char *message)
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
474 {
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
475 struct nap_data *ndata = (struct nap_data *)gc->proto_data;
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
476 struct nap_channel *channel = NULL;
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
477 gchar buf[NAP_BUF_LEN];
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
478
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
479 channel = find_channel_by_id(gc, id);
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
480
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
481 if (!channel) {
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
482 /* This shouldn't happen */
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
483 return;
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
484 }
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
485
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
486 g_snprintf(buf, NAP_BUF_LEN, "%s %s", channel->name, message);
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
487 nap_write_packet(gc, 0x192, buf);
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
488
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
489 }
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
490
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
491 static void nap_add_buddy(struct gaim_connection *gc, char *name)
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
492 {
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
493 nap_write_packet(gc, 0xCF, name);
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
494 }
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
495
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
496 static void nap_remove_buddy(struct gaim_connection *gc, char *name)
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
497 {
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
498 nap_write_packet(gc, 0x12F, name);
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
499 }
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
500
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
501 static void nap_close(struct gaim_connection *gc)
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
502 {
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
503 struct nap_data *ndata = (struct nap_data *)gc->proto_data;
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
504 gchar buf[NAP_BUF_LEN];
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
505 struct nap_channel *channel;
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
506 GSList *channels = ndata->channels;
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
507
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
508 if (gc->inpa)
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
509 gdk_input_remove(gc->inpa);
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
510
1325
08aa745310f6 [gaim-migrate @ 1335]
Rob Flynn <gaim@robflynn.com>
parents: 1323
diff changeset
511 while (ndata->channels) {
08aa745310f6 [gaim-migrate @ 1335]
Rob Flynn <gaim@robflynn.com>
parents: 1323
diff changeset
512 channel = (struct nap_channel *)ndata->channels->data;
1323
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
513 g_free(channel->name);
1325
08aa745310f6 [gaim-migrate @ 1335]
Rob Flynn <gaim@robflynn.com>
parents: 1323
diff changeset
514 ndata->channels = g_slist_remove(ndata->channels, channel);
1323
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
515 g_free(channel);
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
516 }
1325
08aa745310f6 [gaim-migrate @ 1335]
Rob Flynn <gaim@robflynn.com>
parents: 1323
diff changeset
517
08aa745310f6 [gaim-migrate @ 1335]
Rob Flynn <gaim@robflynn.com>
parents: 1323
diff changeset
518 free(gc->proto_data);
1323
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
519 }
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
520
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
521 static void nap_add_buddies(struct gaim_connection *gc, GList *buddies)
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
522 {
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
523 struct nap_data *ndata = (struct nap_data *)gc->proto_data;
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
524 gchar buf[NAP_BUF_LEN];
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
525 int n = 0;
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
526
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
527 while (buddies) {
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
528 nap_write_packet(gc, 0xd0, (char *)buddies->data);
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
529 buddies = buddies -> next;
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
530 }
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
531 }
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
532
1327
113a3d16f1ce [gaim-migrate @ 1337]
Rob Flynn <gaim@robflynn.com>
parents: 1325
diff changeset
533 static char** nap_list_icon(int uc)
113a3d16f1ce [gaim-migrate @ 1337]
Rob Flynn <gaim@robflynn.com>
parents: 1325
diff changeset
534 {
113a3d16f1ce [gaim-migrate @ 1337]
Rob Flynn <gaim@robflynn.com>
parents: 1325
diff changeset
535 return napster_xpm;
113a3d16f1ce [gaim-migrate @ 1337]
Rob Flynn <gaim@robflynn.com>
parents: 1325
diff changeset
536 }
113a3d16f1ce [gaim-migrate @ 1337]
Rob Flynn <gaim@robflynn.com>
parents: 1325
diff changeset
537
1323
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
538 static struct prpl *my_protocol = NULL;
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
539
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
540 void nap_init(struct prpl *ret)
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
541 {
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
542 ret->protocol = PROTO_NAPSTER;
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
543 ret->name = nap_name;
1327
113a3d16f1ce [gaim-migrate @ 1337]
Rob Flynn <gaim@robflynn.com>
parents: 1325
diff changeset
544 ret->list_icon = nap_list_icon;
1323
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
545 ret->action_menu = NULL;
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
546 ret->user_opts = NULL;
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
547 ret->login = nap_login;
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
548 ret->close = nap_close;
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
549 ret->send_im = nap_send_im;
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
550 ret->set_info = NULL;
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
551 ret->get_info = NULL;
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
552 ret->set_away = NULL;
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
553 ret->get_away_msg = NULL;
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
554 ret->set_dir = NULL;
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
555 ret->get_dir = NULL;
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
556 ret->dir_search = NULL;
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
557 ret->set_idle = NULL;
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
558 ret->change_passwd = NULL;
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
559 ret->add_buddy = nap_add_buddy;
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
560 ret->add_buddies = nap_add_buddies;
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
561 ret->remove_buddy = nap_remove_buddy;
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
562 ret->add_permit = NULL;
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
563 ret->rem_permit = NULL;
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
564 ret->add_deny = NULL;
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
565 ret->rem_deny = NULL;
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
566 ret->warn = NULL;
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
567 ret->accept_chat = NULL;
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
568 ret->join_chat = nap_join_chat;
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
569 ret->chat_invite = NULL;
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
570 ret->chat_leave = nap_chat_leave;
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
571 ret->chat_whisper = NULL;
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
572 ret->chat_send = nap_chat_send;
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
573 ret->keepalive = NULL;
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
574
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
575 my_protocol = ret;
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
576 }
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
577
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
578 char *gaim_plugin_init(GModule * handle)
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
579 {
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
580 load_protocol(nap_init);
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
581 return NULL;
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
582 }
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
583
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
584 void gaim_plugin_remove()
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
585 {
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
586 struct prpl *p = find_prpl(PROTO_NAPSTER);
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
587 if (p == my_protocol)
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
588 unload_protocol(p);
4cbb78f05e4b [gaim-migrate @ 1333]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
589 }