Mercurial > pidgin.yaz
annotate plugins/irc.c @ 1499:de0b946e86a4
[gaim-migrate @ 1509]
woohoo, i'm back.
committer: Tailor Script <tailor@pidgin.im>
author | Eric Warmenhoven <eric@warmenhoven.org> |
---|---|
date | Fri, 23 Feb 2001 23:58:35 +0000 |
parents | 336fc98b7f90 |
children | cac3efeb4d9c |
rev | line source |
---|---|
987 | 1 /* |
2 * gaim - IRC Protocol Plugin | |
3 * | |
4 * Copyright (C) 2000, Rob Flynn <rob@tgflinux.com> | |
5 * Copyright (C) 1998-1999, Mark Spencer <markster@marko.net> | |
6 * | |
7 * This program is free software; you can redistribute it and/or modify | |
8 * it under the terms of the GNU General Public License as published by | |
9 * the Free Software Foundation; either version 2 of the License, or | |
10 * (at your option) any later version. | |
11 * | |
12 * This program is distributed in the hope that it will be useful, | |
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
15 * GNU General Public License for more details. | |
16 * | |
17 * You should have received a copy of the GNU General Public License | |
18 * along with this program; if not, write to the Free Software | |
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
20 * | |
21 */ | |
22 | |
23 #include "../config.h" | |
24 | |
25 | |
26 #include <netdb.h> | |
27 #include <gtk/gtk.h> | |
28 #include <unistd.h> | |
29 #include <errno.h> | |
30 #include <netinet/in.h> | |
31 #include <arpa/inet.h> | |
1266
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
32 #include <fcntl.h> |
987 | 33 #include <string.h> |
34 #include <stdlib.h> | |
35 #include <stdio.h> | |
36 #include <time.h> | |
37 #include <sys/socket.h> | |
38 #include <sys/stat.h> | |
39 #include "multi.h" | |
40 #include "prpl.h" | |
41 #include "gaim.h" | |
42 | |
1178 | 43 #include "pixmaps/free_icon.xpm" |
44 | |
1011 | 45 #define IRC_BUF_LEN 4096 |
46 | |
1022 | 47 |
1011 | 48 static int chat_id = 0; |
49 | |
1266
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
50 struct irc_channel { |
1011 | 51 int id; |
52 gchar *name; | |
53 }; | |
54 | |
55 struct irc_data { | |
56 int fd; | |
1266
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
57 int inpa; /* used for non-block logins */ |
1011 | 58 |
1022 | 59 int timer; |
60 | |
61 int totalblocks; | |
62 int recblocks; | |
63 | |
64 GSList *templist; | |
1011 | 65 GList *channels; |
66 }; | |
67 | |
1266
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
68 static char *irc_name() |
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
69 { |
1008 | 70 return "IRC"; |
71 } | |
72 | |
1266
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
73 char *name() |
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
74 { |
1008 | 75 return "IRC"; |
76 } | |
77 | |
1266
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
78 char *description() |
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
79 { |
1008 | 80 return "Allows gaim to use the IRC protocol"; |
81 } | |
82 | |
1266
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
83 static void irc_join_chat(struct gaim_connection *gc, int id, char *name) |
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
84 { |
1011 | 85 struct irc_data *idata = (struct irc_data *)gc->proto_data; |
1266
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
86 gchar *buf = (gchar *) g_malloc(IRC_BUF_LEN + 1); |
1011 | 87 |
88 g_snprintf(buf, IRC_BUF_LEN, "JOIN %s\n", name); | |
89 write(idata->fd, buf, strlen(buf)); | |
1266
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
90 |
1011 | 91 g_free(buf); |
92 } | |
93 | |
1266
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
94 static void irc_update_user(struct gaim_connection *gc, char *name, int status) |
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
95 { |
1022 | 96 struct irc_data *idata = (struct irc_data *)gc->proto_data; |
97 struct irc_channel *u; | |
98 GSList *temp = idata->templist; | |
99 | |
100 /* Loop through our list */ | |
1266
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
101 |
1022 | 102 while (temp) { |
103 u = (struct irc_channel *)temp->data; | |
104 if (g_strcasecmp(u->name, name) == 0) { | |
105 u->id = status; | |
106 return; | |
107 } | |
1266
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
108 |
1022 | 109 temp = g_slist_next(temp); |
110 } | |
111 return; | |
112 } | |
113 | |
1266
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
114 static void irc_request_buddy_update(struct gaim_connection *gc) |
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
115 { |
1022 | 116 struct irc_data *idata = (struct irc_data *)gc->proto_data; |
1046
4593605da0e2
[gaim-migrate @ 1056]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1022
diff
changeset
|
117 GSList *grp = gc->groups; |
4593605da0e2
[gaim-migrate @ 1056]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1022
diff
changeset
|
118 GSList *person; |
1022 | 119 struct group *g; |
120 struct buddy *b; | |
121 struct irc_channel *u; | |
1266
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
122 gchar buf[IRC_BUF_LEN + 1]; |
1022 | 123 |
124 if (idata->templist != NULL) | |
125 return; | |
126 | |
127 idata->recblocks = 0; | |
128 idata->totalblocks = 1; | |
129 | |
1105 | 130 /* First, let's check to see if we have anyone on our buddylist */ |
131 if (!grp) { | |
132 return; | |
133 } | |
134 | |
1266
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
135 /* Send the first part of our request */ |
1022 | 136 write(idata->fd, "ISON", 4); |
137 | |
138 /* Step through our list of groups */ | |
139 while (grp) { | |
1266
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
140 |
1022 | 141 g = (struct group *)grp->data; |
142 person = g->members; | |
143 | |
144 while (person) { | |
145 b = (struct buddy *)person->data; | |
146 | |
147 /* We will store our buddy info here. I know, this is cheap | |
148 * but hey, its the exact same data structure. Why should we | |
149 * bother with making another one */ | |
1266
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
150 |
1022 | 151 u = g_new0(struct irc_channel, 1); |
1266
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
152 u->id = 0; /* Assume by default that they're offline */ |
1022 | 153 u->name = strdup(b->name); |
154 | |
155 write(idata->fd, " ", 1); | |
156 write(idata->fd, u->name, strlen(u->name)); | |
157 idata->templist = g_slist_append(idata->templist, u); | |
158 | |
159 person = person->next; | |
160 } | |
1266
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
161 |
1022 | 162 grp = g_slist_next(grp); |
163 } | |
164 write(idata->fd, "\n", 1); | |
165 } | |
166 | |
167 | |
1266
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
168 static void irc_send_im(struct gaim_connection *gc, char *who, char *message, int away) |
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
169 { |
1011 | 170 |
171 struct irc_data *idata = (struct irc_data *)gc->proto_data; | |
1266
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
172 gchar *buf = (gchar *) g_malloc(IRC_BUF_LEN + 1); |
1011 | 173 |
174 /* Before we actually send this, we should check to see if they're trying | |
175 * To issue a /me command and handle it properly. */ | |
176 | |
1266
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
177 if ((g_strncasecmp(message, "/me ", 4) == 0) && (strlen(message) > 4)) { |
1011 | 178 /* We have /me!! We have /me!! :-) */ |
179 | |
1266
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
180 gchar *temp = (gchar *) g_malloc(IRC_BUF_LEN + 1); |
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
181 strcpy(temp, message + 4); |
1011 | 182 g_snprintf(buf, IRC_BUF_LEN, "PRIVMSG %s :%cACTION %s%c\n", who, '\001', temp, '\001'); |
183 g_free(temp); | |
1266
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
184 } else { |
1011 | 185 g_snprintf(buf, IRC_BUF_LEN, "PRIVMSG %s :%s\n", who, message); |
186 } | |
187 | |
1266
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
188 write(idata->fd, buf, strlen(buf)); |
1011 | 189 |
1266
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
190 g_free(buf); |
1011 | 191 } |
192 | |
1266
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
193 static int find_id_by_name(struct gaim_connection *gc, char *name) |
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
194 { |
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
195 gchar *temp = (gchar *) g_malloc(IRC_BUF_LEN + 1); |
1011 | 196 GList *templist; |
197 struct irc_channel *channel; | |
198 | |
199 templist = ((struct irc_data *)gc->proto_data)->channels; | |
200 | |
201 while (templist) { | |
202 channel = (struct irc_channel *)templist->data; | |
203 | |
204 g_snprintf(temp, IRC_BUF_LEN, "#%s", channel->name); | |
205 | |
206 if (g_strcasecmp(temp, name) == 0) { | |
207 g_free(temp); | |
208 return channel->id; | |
209 } | |
210 | |
1266
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
211 templist = templist->next; |
1011 | 212 } |
213 | |
214 g_free(temp); | |
215 | |
216 /* Return -1 if we have no ID */ | |
217 return -1; | |
218 } | |
219 | |
1266
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
220 static struct irc_channel *find_channel_by_name(struct gaim_connection *gc, char *name) |
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
221 { |
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
222 gchar *temp = (gchar *) g_malloc(IRC_BUF_LEN + 1); |
1011 | 223 GList *templist; |
224 struct irc_channel *channel; | |
225 | |
226 templist = ((struct irc_data *)gc->proto_data)->channels; | |
227 | |
228 while (templist) { | |
229 channel = (struct irc_channel *)templist->data; | |
230 | |
231 g_snprintf(temp, IRC_BUF_LEN, "%s", channel->name); | |
232 | |
233 if (g_strcasecmp(temp, name) == 0) { | |
234 g_free(temp); | |
235 return channel; | |
236 } | |
237 | |
1266
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
238 templist = templist->next; |
1011 | 239 } |
240 | |
241 g_free(temp); | |
242 | |
243 /* If we found nothing, return nothing :-) */ | |
244 return NULL; | |
245 } | |
246 | |
1266
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
247 static struct irc_channel *find_channel_by_id(struct gaim_connection *gc, int id) |
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
248 { |
1011 | 249 struct irc_data *idata = (struct irc_data *)gc->proto_data; |
250 struct irc_channel *channel; | |
1266
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
251 |
1011 | 252 GList *temp; |
253 | |
254 temp = idata->channels; | |
255 | |
256 while (temp) { | |
257 channel = (struct irc_channel *)temp->data; | |
258 | |
259 if (channel->id == id) { | |
260 /* We've found our man */ | |
261 return channel; | |
262 } | |
1266
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
263 |
1011 | 264 temp = temp->next; |
265 } | |
266 | |
267 | |
268 /* If we didnt find one, return NULL */ | |
269 return NULL; | |
270 } | |
271 | |
1266
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
272 static void irc_chat_send(struct gaim_connection *gc, int id, char *message) |
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
273 { |
1011 | 274 |
275 struct irc_data *idata = (struct irc_data *)gc->proto_data; | |
1021 | 276 struct irc_channel *channel = NULL; |
1266
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
277 gchar *buf = (gchar *) g_malloc(IRC_BUF_LEN + 1); |
1011 | 278 |
279 /* First lets get our current channel */ | |
280 channel = find_channel_by_id(gc, id); | |
1266
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
281 |
1011 | 282 |
283 if (!channel) { | |
284 /* If for some reason we've lost our channel, let's bolt */ | |
1021 | 285 g_free(buf); |
1011 | 286 return; |
287 } | |
1266
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
288 |
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
289 |
1011 | 290 /* Before we actually send this, we should check to see if they're trying |
291 * To issue a /me command and handle it properly. */ | |
292 | |
1266
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
293 if ((g_strncasecmp(message, "/me ", 4) == 0) && (strlen(message) > 4)) { |
1011 | 294 /* We have /me!! We have /me!! :-) */ |
295 | |
1266
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
296 gchar *temp = (gchar *) g_malloc(IRC_BUF_LEN + 1); |
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
297 strcpy(temp, message + 4); |
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
298 g_snprintf(buf, IRC_BUF_LEN, "PRIVMSG #%s :%cACTION %s%c\n", channel->name, '\001', temp, |
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
299 '\001'); |
1011 | 300 g_free(temp); |
1266
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
301 } else { |
1011 | 302 g_snprintf(buf, IRC_BUF_LEN, "PRIVMSG #%s :%s\n", channel->name, message); |
303 } | |
304 | |
1266
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
305 write(idata->fd, buf, strlen(buf)); |
1011 | 306 |
307 /* Since AIM expects us to receive the message we send, we gotta fake it */ | |
308 serv_got_chat_in(gc, id, gc->username, 0, message); | |
309 | |
1266
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
310 g_free(buf); |
1008 | 311 } |
312 | |
1266
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
313 static struct conversation *find_conversation_by_id(struct gaim_connection *gc, int id) |
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
314 { |
1014 | 315 struct irc_data *idata = (struct irc_data *)gc->proto_data; |
316 GSList *bc = gc->buddy_chats; | |
317 struct conversation *b = NULL; | |
318 | |
319 while (bc) { | |
320 b = (struct conversation *)bc->data; | |
321 if (id == b->id) { | |
322 break; | |
323 } | |
324 bc = bc->next; | |
325 b = NULL; | |
326 } | |
327 | |
328 if (!b) { | |
329 return NULL; | |
330 } | |
331 | |
332 return b; | |
333 } | |
334 | |
1266
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
335 static struct conversation *find_conversation_by_name(struct gaim_connection *gc, char *name) |
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
336 { |
1014 | 337 struct irc_data *idata = (struct irc_data *)gc->proto_data; |
338 GSList *bc = gc->buddy_chats; | |
339 struct conversation *b = NULL; | |
340 | |
341 while (bc) { | |
1301 | 342 int x; |
1014 | 343 b = (struct conversation *)bc->data; |
344 | |
345 if (g_strcasecmp(name, b->name) == 0) { | |
346 break; | |
347 } | |
348 bc = bc->next; | |
349 b = NULL; | |
350 } | |
351 | |
352 if (!b) { | |
353 return NULL; | |
354 } | |
355 | |
356 return b; | |
357 } | |
358 | |
359 | |
360 | |
1266
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
361 static void irc_callback(gpointer data, gint source, GdkInputCondition condition) |
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
362 { |
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
363 struct gaim_connection *gc = data; |
1011 | 364 int i = 0; |
365 gchar buf[4096]; | |
366 gchar **buf2; | |
367 struct irc_data *idata; | |
368 | |
369 idata = (struct irc_data *)gc->proto_data; | |
1266
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
370 |
1011 | 371 do { |
1266
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
372 if (read(idata->fd, buf + i, 1) < 0) { |
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
373 hide_login_progress(gc, "Read error"); |
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
374 signoff(gc); |
1105 | 375 return; |
1011 | 376 } |
1266
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
377 } while (buf[i++] != '\n'); |
1011 | 378 |
1266
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
379 buf[--i] = '\0'; |
1301 | 380 g_strchomp(buf); |
1269
677e2c9e8baf
[gaim-migrate @ 1279]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1266
diff
changeset
|
381 g_print("%s\n", buf); |
1105 | 382 |
383 /* Check for errors */ | |
384 | |
385 if (((strstr(buf, "ERROR :") && (!strstr(buf, "PRIVMSG ")) && | |
1266
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
386 (!strstr(buf, "NOTICE ")) && (strlen(buf) > 7)))) { |
1105 | 387 |
388 gchar *u_errormsg; | |
389 | |
390 /* Let's get our error message */ | |
1269
677e2c9e8baf
[gaim-migrate @ 1279]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1266
diff
changeset
|
391 u_errormsg = g_strdup(buf + 7); |
1105 | 392 |
393 /* We got our error message. Now, let's reaise an | |
394 * error dialog */ | |
395 | |
396 do_error_dialog(u_errormsg, "Gaim: IRC Error"); | |
397 | |
398 /* And our necessary garbage collection */ | |
1269
677e2c9e8baf
[gaim-migrate @ 1279]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1266
diff
changeset
|
399 g_free(u_errormsg); |
1105 | 400 } |
1266
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
401 |
1014 | 402 /* Parse the list of names that we receive when we first sign on to |
403 * a channel */ | |
404 | |
1266
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
405 if (((strstr(buf, " 353 ")) && (!strstr(buf, "PRIVMSG")) && (!strstr(buf, "NOTICE")))) { |
1014 | 406 gchar u_host[255]; |
407 gchar u_command[32]; | |
408 gchar u_channel[128]; | |
409 gchar u_names[IRC_BUF_LEN + 1]; | |
410 struct conversation *convo = NULL; | |
411 int j; | |
412 | |
413 for (j = 0, i = 0; buf[i] != ' '; j++, i++) { | |
414 u_host[j] = buf[i]; | |
415 } | |
416 | |
1266
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
417 u_host[j] = '\0'; |
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
418 i++; |
1014 | 419 |
420 for (j = 0; buf[i] != ' '; j++, i++) { | |
421 u_command[j] = buf[i]; | |
422 } | |
423 | |
1266
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
424 u_command[j] = '\0'; |
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
425 i++; |
1014 | 426 |
427 for (j = 0; buf[i] != '#'; j++, i++) { | |
428 } | |
429 i++; | |
1266
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
430 |
1014 | 431 for (j = 0; buf[i] != ':'; j++, i++) { |
432 u_channel[j] = buf[i]; | |
433 } | |
434 | |
1266
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
435 u_channel[j - 1] = '\0'; |
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
436 i++; |
1014 | 437 |
438 while ((buf[i] == ' ') || (buf[i] == ':')) { | |
439 i++; | |
440 } | |
441 | |
442 strcpy(u_names, buf + i); | |
1266
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
443 |
1014 | 444 buf2 = g_strsplit(u_names, " ", 0); |
1266
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
445 |
1014 | 446 /* Let's get our conversation window */ |
447 convo = find_conversation_by_name(gc, u_channel); | |
448 | |
449 if (!convo) { | |
450 return; | |
451 } | |
1266
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
452 |
1014 | 453 /* Now that we've parsed the hell out of this big |
454 * mess, let's try to split up the names properly */ | |
455 | |
1269
677e2c9e8baf
[gaim-migrate @ 1279]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1266
diff
changeset
|
456 for (i = 0; buf2[i] != NULL; i++) |
677e2c9e8baf
[gaim-migrate @ 1279]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1266
diff
changeset
|
457 add_chat_buddy(convo, buf2[i]); |
1021 | 458 |
459 /* And free our pointers */ | |
1266
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
460 g_strfreev(buf2); |
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
461 |
1014 | 462 return; |
1266
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
463 |
1014 | 464 } |
465 | |
1022 | 466 /* Receive a list of users that are currently online */ |
1266
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
467 |
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
468 if (((strstr(buf, " 303 ")) && (!strstr(buf, "PRIVMSG")) && (!strstr(buf, "NOTICE")))) { |
1022 | 469 gchar u_host[255]; |
470 gchar u_command[32]; | |
471 gchar u_names[IRC_BUF_LEN + 1]; | |
472 int j; | |
473 | |
474 for (j = 0, i = 0; buf[i] != ' '; j++, i++) { | |
475 u_host[j] = buf[i]; | |
476 } | |
477 | |
1266
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
478 u_host[j] = '\0'; |
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
479 i++; |
1022 | 480 |
481 for (j = 0; buf[i] != ' '; j++, i++) { | |
482 u_command[j] = buf[i]; | |
483 } | |
484 | |
1266
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
485 u_command[j] = '\0'; |
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
486 i++; |
1022 | 487 |
488 for (j = 0; buf[i] != ':'; j++, i++) { | |
489 /* My Nick */ | |
490 } | |
491 i++; | |
1266
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
492 |
1022 | 493 strcpy(u_names, buf + i); |
1266
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
494 |
1022 | 495 buf2 = g_strsplit(u_names, " ", 0); |
1266
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
496 |
1022 | 497 /* Now that we've parsed the hell out of this big |
498 * mess, let's try to split up the names properly */ | |
499 | |
500 for (i = 0; buf2[i] != NULL; i++) { | |
501 /* If we have a name here then our buddy is online. We should | |
502 * update our temporary gslist accordingly. When we achieve our maximum | |
503 * list of names then we should force an update */ | |
504 | |
505 irc_update_user(gc, buf2[i], 1); | |
506 } | |
1266
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
507 |
1022 | 508 /* Increase our received blocks counter */ |
509 idata->recblocks++; | |
510 | |
511 /* If we have our total number of blocks */ | |
512 if (idata->recblocks == idata->totalblocks) { | |
513 GSList *temp; | |
514 struct irc_channel *u; | |
1266
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
515 |
1022 | 516 /* Let's grab our list of people and bring them all on or off line */ |
517 temp = idata->templist; | |
1266
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
518 |
1022 | 519 /* Loop */ |
520 while (temp) { | |
1266
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
521 |
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
522 u = temp->data; |
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
523 |
1022 | 524 /* Tell Gaim to bring the person on or off line */ |
1266
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
525 serv_got_update(gc, u->name, u->id, 0, 0, 0, 0, 0); |
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
526 |
1022 | 527 /* Grab the next entry */ |
528 temp = g_slist_next(temp); | |
529 } | |
1266
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
530 |
1022 | 531 /* And now, let's delete all of our entries */ |
532 temp = idata->templist; | |
533 while (temp) { | |
534 u = temp->data; | |
535 g_free(u->name); | |
536 temp = g_slist_remove(temp, u); | |
537 } | |
1266
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
538 |
1022 | 539 /* Reset our list */ |
540 idata->totalblocks = 0; | |
541 idata->recblocks = 0; | |
1266
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
542 |
1022 | 543 idata->templist = NULL; |
1266
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
544 |
1022 | 545 return; |
546 } | |
547 | |
548 /* And free our pointers */ | |
1266
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
549 g_strfreev(buf2); |
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
550 |
1022 | 551 return; |
1266
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
552 |
1022 | 553 } |
554 | |
1266
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
555 |
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
556 if ((strstr(buf, " JOIN ")) && (buf[0] == ':') && (!strstr(buf, " NOTICE "))) { |
1011 | 557 |
558 gchar u_channel[128]; | |
1012 | 559 gchar u_nick[128]; |
1266
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
560 |
1011 | 561 struct irc_channel *channel; |
562 int id; | |
563 int j; | |
564 | |
1012 | 565 for (j = 0, i = 1; buf[i] != '!'; j++, i++) { |
566 u_nick[j] = buf[i]; | |
567 } | |
568 | |
1266
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
569 u_nick[j] = '\0'; |
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
570 i++; |
1012 | 571 |
572 for (j = 0; buf[i] != '#'; j++, i++) { | |
1011 | 573 } |
1266
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
574 |
1011 | 575 i++; |
1266
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
576 |
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
577 strcpy(u_channel, buf + i); |
1011 | 578 |
1301 | 579 g_strchomp(u_channel); |
580 | |
1014 | 581 /* Looks like we're going to join the channel for real |
582 * now. Let's create a valid channel structure and add | |
583 * it to our list. Let's make sure that | |
1011 | 584 * we are not already in a channel first */ |
585 | |
586 channel = find_channel_by_name(gc, u_channel); | |
587 | |
588 if (!channel) { | |
1301 | 589 |
1011 | 590 chat_id++; |
591 | |
592 channel = g_new0(struct irc_channel, 1); | |
1266
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
593 |
1011 | 594 channel->id = chat_id; |
595 channel->name = strdup(u_channel); | |
1266
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
596 |
1011 | 597 idata->channels = g_list_append(idata->channels, channel); |
598 | |
1266
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
599 serv_got_joined_chat(gc, chat_id, u_channel); |
1011 | 600 } else { |
1014 | 601 struct conversation *convo = NULL; |
1266
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
602 |
1014 | 603 /* Someone else joined. Find their conversation |
604 * window */ | |
605 convo = find_conversation_by_id(gc, channel->id); | |
606 | |
607 /* And add their name to it */ | |
608 add_chat_buddy(convo, u_nick); | |
1266
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
609 |
1011 | 610 } |
611 | |
612 return; | |
613 } | |
1266
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
614 |
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
615 if ((strstr(buf, " PART ")) && (buf[0] == ':') && (!strstr(buf, " NOTICE "))) { |
1011 | 616 |
617 gchar u_channel[128]; | |
618 gchar u_nick[128]; | |
619 | |
1021 | 620 struct irc_channel *channel; |
1011 | 621 int id; |
622 int j; | |
623 GList *test = NULL; | |
624 | |
625 for (j = 0, i = 1; buf[i] != '!'; j++, i++) { | |
626 u_nick[j] = buf[i]; | |
627 } | |
628 u_nick[j] = '\0'; | |
629 | |
630 i++; | |
1266
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
631 |
1011 | 632 for (j = 0; buf[i] != '#'; j++, i++) { |
633 } | |
1266
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
634 |
1011 | 635 i++; |
1266
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
636 |
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
637 strcpy(u_channel, buf + i); |
1011 | 638 |
639 | |
1014 | 640 /* Now, lets check to see if it was US that was leaving. |
641 * If so, do the correct thing by closing up all of our | |
642 * old channel stuff. Otherwise, | |
1011 | 643 * we should just print that someone left */ |
644 | |
1014 | 645 channel = find_channel_by_name(gc, u_channel); |
646 | |
647 if (!channel) { | |
648 return; | |
649 } | |
650 | |
1011 | 651 if (g_strcasecmp(u_nick, gc->username) == 0) { |
1266
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
652 |
1014 | 653 /* Looks like we're going to leave the channel for |
654 * real now. Let's create a valid channel structure | |
655 * and add it to our list */ | |
1011 | 656 |
657 serv_got_chat_left(gc, channel->id); | |
658 | |
659 idata->channels = g_list_remove(idata->channels, channel); | |
1014 | 660 } else { |
661 struct conversation *convo = NULL; | |
1266
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
662 |
1014 | 663 /* Find their conversation window */ |
664 convo = find_conversation_by_id(gc, channel->id); | |
665 | |
666 if (!convo) { | |
667 /* Some how the window doesn't exist. | |
668 * Let's get out of here */ | |
1266
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
669 return; |
1014 | 670 } |
1266
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
671 |
1014 | 672 /* And remove their name */ |
673 remove_chat_buddy(convo, u_nick); | |
674 | |
1011 | 675 } |
676 | |
1014 | 677 /* Go Home! */ |
1011 | 678 return; |
679 } | |
1266
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
680 |
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
681 if ((strstr(buf, " NOTICE ")) && (buf[0] == ':')) { |
1178 | 682 gchar u_nick[128]; |
683 gchar u_host[255]; | |
684 gchar u_command[32]; | |
685 gchar u_channel[128]; | |
686 gchar u_message[IRC_BUF_LEN]; | |
687 int j; | |
688 int msgcode = 0; | |
689 | |
690 for (j = 0, i = 1; buf[i] != '!'; j++, i++) { | |
691 u_nick[j] = buf[i]; | |
692 } | |
693 | |
1266
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
694 u_nick[j] = '\0'; |
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
695 i++; |
1178 | 696 |
697 for (j = 0; buf[i] != ' '; j++, i++) { | |
698 u_host[j] = buf[i]; | |
699 } | |
700 | |
1266
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
701 u_host[j] = '\0'; |
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
702 i++; |
1178 | 703 |
704 for (j = 0; buf[i] != ' '; j++, i++) { | |
705 u_command[j] = buf[i]; | |
706 } | |
707 | |
1266
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
708 u_command[j] = '\0'; |
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
709 i++; |
1178 | 710 |
711 for (j = 0; buf[i] != ':'; j++, i++) { | |
712 u_channel[j] = buf[i]; | |
713 } | |
714 | |
1266
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
715 u_channel[j - 1] = '\0'; |
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
716 i++; |
1178 | 717 |
718 | |
719 /* Now that everything is parsed, the rest of this baby must be our message */ | |
720 strncpy(u_message, buf + i, IRC_BUF_LEN); | |
721 | |
722 /* Now, lets check the message to see if there's anything special in it */ | |
723 if (u_message[0] == '\001') { | |
724 if ((g_strncasecmp(u_message, "\001PING ", 6) == 0) && (strlen(u_message) > 6)) { | |
725 /* Someone's triyng to ping us. Let's respond */ | |
726 gchar u_arg[24]; | |
727 gchar u_buf[200]; | |
1393 | 728 unsigned long tend= time((time_t *)NULL); |
729 unsigned long tstart; | |
730 | |
731 printf("LA: %s\n", buf); | |
1178 | 732 |
733 strcpy(u_arg, u_message + 6); | |
1266
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
734 u_arg[strlen(u_arg) - 1] = '\0'; |
1178 | 735 |
1393 | 736 tstart = atol(u_arg); |
737 | |
738 g_snprintf(u_buf, sizeof(u_buf), "Ping Reply From %s: [%ld seconds]", u_nick, tend-tstart); | |
1266
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
739 |
1178 | 740 do_error_dialog(u_buf, "Gaim IRC - Ping Reply"); |
1266
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
741 |
1178 | 742 return; |
743 } | |
744 } | |
745 | |
746 } | |
1266
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
747 |
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
748 |
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
749 if ((strstr(buf, " PRIVMSG ")) && (buf[0] == ':')) { |
1011 | 750 gchar u_nick[128]; |
751 gchar u_host[255]; | |
752 gchar u_command[32]; | |
753 gchar u_channel[128]; | |
754 gchar u_message[IRC_BUF_LEN]; | |
755 int j; | |
756 int msgcode = 0; | |
757 | |
758 for (j = 0, i = 1; buf[i] != '!'; j++, i++) { | |
759 u_nick[j] = buf[i]; | |
760 } | |
761 | |
1266
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
762 u_nick[j] = '\0'; |
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
763 i++; |
1011 | 764 |
765 for (j = 0; buf[i] != ' '; j++, i++) { | |
766 u_host[j] = buf[i]; | |
767 } | |
768 | |
1266
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
769 u_host[j] = '\0'; |
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
770 i++; |
1011 | 771 |
772 for (j = 0; buf[i] != ' '; j++, i++) { | |
773 u_command[j] = buf[i]; | |
774 } | |
775 | |
1266
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
776 u_command[j] = '\0'; |
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
777 i++; |
1011 | 778 |
779 for (j = 0; buf[i] != ':'; j++, i++) { | |
780 u_channel[j] = buf[i]; | |
781 } | |
782 | |
1266
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
783 u_channel[j - 1] = '\0'; |
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
784 i++; |
1011 | 785 |
786 | |
787 /* Now that everything is parsed, the rest of this baby must be our message */ | |
788 strncpy(u_message, buf + i, IRC_BUF_LEN); | |
1266
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
789 |
1011 | 790 /* Now, lets check the message to see if there's anything special in it */ |
791 if (u_message[0] == '\001') { | |
1017 | 792 if (g_strncasecmp(u_message, "\001VERSION", 8) == 0) { |
793 /* Looks like we have a version request. Let | |
794 * us handle it thusly */ | |
1266
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
795 |
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
796 g_snprintf(buf, IRC_BUF_LEN, |
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
797 "NOTICE %s :%cVERSION GAIM %s:The Pimpin Penguin AIM Clone:www.marko.net/gaim%c\n", |
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
798 u_nick, '\001', VERSION, '\001'); |
1017 | 799 |
800 write(idata->fd, buf, strlen(buf)); | |
801 | |
802 /* And get the heck out of dodge */ | |
803 return; | |
804 } | |
1266
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
805 |
1017 | 806 if ((g_strncasecmp(u_message, "\001PING ", 6) == 0) && (strlen(u_message) > 6)) { |
807 /* Someone's triyng to ping us. Let's respond */ | |
808 gchar u_arg[24]; | |
809 | |
810 strcpy(u_arg, u_message + 6); | |
1266
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
811 u_arg[strlen(u_arg) - 1] = '\0'; |
1017 | 812 |
1266
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
813 g_snprintf(buf, IRC_BUF_LEN, "NOTICE %s :%cPING %s%c\n", u_nick, '\001', |
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
814 u_arg, '\001'); |
1017 | 815 |
816 write(idata->fd, buf, strlen(buf)); | |
817 | |
818 /* And get the heck out of dodge */ | |
819 return; | |
820 } | |
821 | |
1011 | 822 if (g_strncasecmp(u_message, "\001ACTION ", 8) == 0) { |
823 /* Looks like we have an action. Let's parse it a little */ | |
824 strcpy(buf, u_message); | |
825 | |
826 strcpy(u_message, "/me "); | |
827 for (j = 4, i = 8; buf[i] != '\001'; i++, j++) { | |
828 u_message[j] = buf[i]; | |
829 } | |
830 u_message[j] = '\0'; | |
831 } | |
832 } | |
833 | |
834 | |
835 /* Let's check to see if we have a channel on our hands */ | |
836 if (u_channel[0] == '#') { | |
837 /* Yup. We have a channel */ | |
838 int id; | |
839 | |
840 id = find_id_by_name(gc, u_channel); | |
841 if (id != -1) { | |
842 serv_got_chat_in(gc, id, u_nick, 0, u_message); | |
843 } | |
1266
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
844 } else { |
1011 | 845 /* Nope. Let's treat it as a private message */ |
846 serv_got_im(gc, u_nick, u_message, 0); | |
847 } | |
848 | |
849 return; | |
850 } | |
851 | |
852 /* Let's parse PING requests so that we wont get booted for inactivity */ | |
853 | |
854 if (strncmp(buf, "PING :", 6) == 0) { | |
855 buf2 = g_strsplit(buf, ":", 1); | |
1266
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
856 |
1011 | 857 /* Let's build a new response */ |
858 g_snprintf(buf, IRC_BUF_LEN, "PONG :%s\n", buf2[1]); | |
859 write(idata->fd, buf, strlen(buf)); | |
860 | |
861 /* And clean up after ourselves */ | |
862 g_strfreev(buf2); | |
863 | |
864 return; | |
865 } | |
866 | |
867 } | |
868 | |
1266
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
869 static void irc_close(struct gaim_connection *gc) |
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
870 { |
1011 | 871 struct irc_data *idata = (struct irc_data *)gc->proto_data; |
1021 | 872 GList *chats = idata->channels; |
873 struct irc_channel *cc; | |
874 | |
1266
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
875 gchar *buf = (gchar *) g_malloc(IRC_BUF_LEN); |
1011 | 876 |
1021 | 877 g_snprintf(buf, IRC_BUF_LEN, "QUIT :Download GAIM [www.marko.net/gaim]\n"); |
1011 | 878 write(idata->fd, buf, strlen(buf)); |
879 | |
880 g_free(buf); | |
1021 | 881 |
1266
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
882 if (idata->timer) |
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
883 gtk_timeout_remove(idata->timer); |
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
884 |
1021 | 885 while (chats) { |
886 cc = (struct irc_channel *)chats->data; | |
887 g_free(cc->name); | |
888 chats = g_list_remove(chats, cc); | |
889 g_free(cc); | |
890 } | |
1266
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
891 |
1021 | 892 if (gc->inpa) |
893 gdk_input_remove(gc->inpa); | |
894 | |
1266
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
895 if (idata->inpa) |
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
896 gdk_input_remove(idata->inpa); |
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
897 |
1011 | 898 close(idata->fd); |
899 g_free(gc->proto_data); | |
900 } | |
901 | |
1266
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
902 static void irc_chat_leave(struct gaim_connection *gc, int id) |
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
903 { |
1011 | 904 struct irc_data *idata = (struct irc_data *)gc->proto_data; |
905 struct irc_channel *channel; | |
1266
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
906 gchar *buf = (gchar *) g_malloc(IRC_BUF_LEN + 1); |
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
907 |
1011 | 908 channel = find_channel_by_id(gc, id); |
1266
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
909 |
1011 | 910 if (!channel) { |
911 return; | |
912 } | |
913 | |
914 g_snprintf(buf, IRC_BUF_LEN, "PART #%s\n", channel->name); | |
915 write(idata->fd, buf, strlen(buf)); | |
916 | |
917 g_free(buf); | |
918 } | |
919 | |
1266
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
920 static void irc_login_callback(gpointer data, gint source, GdkInputCondition condition) |
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
921 { |
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
922 struct gaim_connection *gc = data; |
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
923 struct irc_data *idata = gc->proto_data; |
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
924 char buf[4096]; |
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
925 int len, error = ETIMEDOUT; |
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
926 |
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
927 len = sizeof(error); |
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
928 if (getsockopt(idata->fd, SOL_SOCKET, SO_ERROR, &error, &len) < 0) |
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
929 error = errno; |
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
930 if (error) { |
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
931 hide_login_progress(gc, "Couldn't connect"); |
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
932 signoff(gc); |
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
933 return; |
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
934 } |
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
935 |
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
936 fcntl(idata->fd, F_SETFL, 0); |
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
937 |
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
938 g_snprintf(buf, 4096, "NICK %s\n USER %s localhost %s :GAIM (www.marko.net/gaim)\n", |
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
939 gc->username, g_get_user_name(), gc->user->proto_opt[0]); |
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
940 |
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
941 if (write(idata->fd, buf, strlen(buf)) < 0) { |
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
942 hide_login_progress(gc, "Write error"); |
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
943 signoff(gc); |
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
944 return; |
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
945 } |
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
946 |
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
947 gdk_input_remove(idata->inpa); |
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
948 idata->inpa = 0; |
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
949 |
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
950 /* Now lets sign ourselves on */ |
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
951 account_online(gc); |
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
952 serv_finish_login(gc); |
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
953 |
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
954 if (bud_list_cache_exists(gc)) |
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
955 do_import(NULL, gc); |
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
956 |
1269
677e2c9e8baf
[gaim-migrate @ 1279]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1266
diff
changeset
|
957 /* we don't call this now because otherwise some IRC servers might not like us */ |
1266
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
958 idata->timer = gtk_timeout_add(20000, (GtkFunction)irc_request_buddy_update, gc); |
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
959 } |
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
960 |
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
961 static void irc_login(struct aim_user *user) |
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
962 { |
1011 | 963 int fd; |
964 struct hostent *host; | |
965 struct sockaddr_in site; | |
966 char buf[4096]; | |
1266
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
967 |
1089
f0f5c10cce63
[gaim-migrate @ 1099]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1075
diff
changeset
|
968 struct gaim_connection *gc = new_gaim_conn(user); |
1011 | 969 struct irc_data *idata = gc->proto_data = g_new0(struct irc_data, 1); |
970 char c; | |
971 int i; | |
972 int status; | |
973 | |
1075
2fe18b2d6105
[gaim-migrate @ 1085]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1056
diff
changeset
|
974 host = gethostbyname(user->proto_opt[0]); |
1011 | 975 if (!host) { |
976 hide_login_progress(gc, "Unable to resolve hostname"); | |
1115
114cd406b022
[gaim-migrate @ 1125]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1105
diff
changeset
|
977 signoff(gc); |
1011 | 978 return; |
979 } | |
980 | |
981 site.sin_family = AF_INET; | |
982 site.sin_addr.s_addr = *(long *)(host->h_addr); | |
1304 | 983 |
984 if (user->proto_opt[1][0]) | |
985 site.sin_port = htons(atoi(user->proto_opt[1])); | |
986 else { | |
987 site.sin_port = htons(6667); | |
988 g_snprintf(user->proto_opt[1], 5, "6667"); | |
989 } | |
1011 | 990 |
991 fd = socket(AF_INET, SOCK_STREAM, 0); | |
992 if (fd < 0) { | |
993 hide_login_progress(gc, "Unable to create socket"); | |
1115
114cd406b022
[gaim-migrate @ 1125]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1105
diff
changeset
|
994 signoff(gc); |
1011 | 995 return; |
996 } | |
997 | |
1266
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
998 fcntl(fd, F_SETFL, O_NONBLOCK); |
1011 | 999 if (connect(fd, (struct sockaddr *)&site, sizeof(site)) < 0) { |
1266
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
1000 if ((errno == EINPROGRESS) || (errno == EINTR)) { |
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
1001 idata->inpa = gdk_input_add(idata->fd, GDK_INPUT_WRITE, irc_login_callback, gc); |
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
1002 } else { |
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
1003 hide_login_progress(gc, "Unable to connect."); |
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
1004 signoff(gc); |
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
1005 return; |
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
1006 } |
1011 | 1007 } |
1008 | |
1009 idata->fd = fd; | |
1266
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
1010 |
1011 | 1011 g_snprintf(buf, sizeof(buf), "Signon: %s", gc->username); |
1012 set_login_progress(gc, 2, buf); | |
1013 | |
1014 /* This is where we will attempt to sign on */ | |
1015 | |
1266
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
1016 if (!idata->inpa) |
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
1017 irc_login_callback(gc, idata->fd, GDK_INPUT_READ); |
1022 | 1018 |
1266
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
1019 gc->inpa = gdk_input_add(idata->fd, GDK_INPUT_READ, irc_callback, gc); |
1011 | 1020 } |
1008 | 1021 |
1266
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
1022 static void irc_print_option(GtkEntry * entry, struct aim_user *user) |
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
1023 { |
1075
2fe18b2d6105
[gaim-migrate @ 1085]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1056
diff
changeset
|
1024 if (gtk_object_get_user_data(GTK_OBJECT(entry))) { |
2fe18b2d6105
[gaim-migrate @ 1085]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1056
diff
changeset
|
1025 g_snprintf(user->proto_opt[1], sizeof(user->proto_opt[1]), "%s", |
1266
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
1026 gtk_entry_get_text(entry)); |
1075
2fe18b2d6105
[gaim-migrate @ 1085]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1056
diff
changeset
|
1027 } else { |
2fe18b2d6105
[gaim-migrate @ 1085]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1056
diff
changeset
|
1028 g_snprintf(user->proto_opt[0], sizeof(user->proto_opt[0]), "%s", |
1266
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
1029 gtk_entry_get_text(entry)); |
1075
2fe18b2d6105
[gaim-migrate @ 1085]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1056
diff
changeset
|
1030 } |
2fe18b2d6105
[gaim-migrate @ 1085]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1056
diff
changeset
|
1031 } |
2fe18b2d6105
[gaim-migrate @ 1085]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1056
diff
changeset
|
1032 |
1266
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
1033 static void irc_user_opts(GtkWidget * book, struct aim_user *user) |
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
1034 { |
1075
2fe18b2d6105
[gaim-migrate @ 1085]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1056
diff
changeset
|
1035 /* so here, we create the new notebook page */ |
2fe18b2d6105
[gaim-migrate @ 1085]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1056
diff
changeset
|
1036 GtkWidget *vbox; |
2fe18b2d6105
[gaim-migrate @ 1085]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1056
diff
changeset
|
1037 GtkWidget *hbox; |
2fe18b2d6105
[gaim-migrate @ 1085]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1056
diff
changeset
|
1038 GtkWidget *label; |
2fe18b2d6105
[gaim-migrate @ 1085]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1056
diff
changeset
|
1039 GtkWidget *entry; |
2fe18b2d6105
[gaim-migrate @ 1085]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1056
diff
changeset
|
1040 |
2fe18b2d6105
[gaim-migrate @ 1085]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1056
diff
changeset
|
1041 vbox = gtk_vbox_new(FALSE, 0); |
1266
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
1042 gtk_notebook_append_page(GTK_NOTEBOOK(book), vbox, gtk_label_new("IRC Options")); |
1075
2fe18b2d6105
[gaim-migrate @ 1085]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1056
diff
changeset
|
1043 gtk_widget_show(vbox); |
2fe18b2d6105
[gaim-migrate @ 1085]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1056
diff
changeset
|
1044 |
2fe18b2d6105
[gaim-migrate @ 1085]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1056
diff
changeset
|
1045 hbox = gtk_hbox_new(FALSE, 0); |
2fe18b2d6105
[gaim-migrate @ 1085]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1056
diff
changeset
|
1046 gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, 5); |
2fe18b2d6105
[gaim-migrate @ 1085]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1056
diff
changeset
|
1047 gtk_widget_show(hbox); |
2fe18b2d6105
[gaim-migrate @ 1085]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1056
diff
changeset
|
1048 |
2fe18b2d6105
[gaim-migrate @ 1085]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1056
diff
changeset
|
1049 label = gtk_label_new("Server:"); |
2fe18b2d6105
[gaim-migrate @ 1085]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1056
diff
changeset
|
1050 gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 5); |
2fe18b2d6105
[gaim-migrate @ 1085]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1056
diff
changeset
|
1051 gtk_widget_show(label); |
2fe18b2d6105
[gaim-migrate @ 1085]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1056
diff
changeset
|
1052 |
2fe18b2d6105
[gaim-migrate @ 1085]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1056
diff
changeset
|
1053 entry = gtk_entry_new(); |
2fe18b2d6105
[gaim-migrate @ 1085]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1056
diff
changeset
|
1054 gtk_box_pack_end(GTK_BOX(hbox), entry, FALSE, FALSE, 5); |
1266
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
1055 gtk_signal_connect(GTK_OBJECT(entry), "changed", GTK_SIGNAL_FUNC(irc_print_option), user); |
1075
2fe18b2d6105
[gaim-migrate @ 1085]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1056
diff
changeset
|
1056 if (user->proto_opt[0][0]) { |
2fe18b2d6105
[gaim-migrate @ 1085]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1056
diff
changeset
|
1057 debug_printf("setting text %s\n", user->proto_opt[0]); |
2fe18b2d6105
[gaim-migrate @ 1085]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1056
diff
changeset
|
1058 gtk_entry_set_text(GTK_ENTRY(entry), user->proto_opt[0]); |
2fe18b2d6105
[gaim-migrate @ 1085]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1056
diff
changeset
|
1059 } |
2fe18b2d6105
[gaim-migrate @ 1085]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1056
diff
changeset
|
1060 gtk_widget_show(entry); |
2fe18b2d6105
[gaim-migrate @ 1085]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1056
diff
changeset
|
1061 |
2fe18b2d6105
[gaim-migrate @ 1085]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1056
diff
changeset
|
1062 hbox = gtk_hbox_new(FALSE, 0); |
2fe18b2d6105
[gaim-migrate @ 1085]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1056
diff
changeset
|
1063 gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, 5); |
2fe18b2d6105
[gaim-migrate @ 1085]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1056
diff
changeset
|
1064 gtk_widget_show(hbox); |
2fe18b2d6105
[gaim-migrate @ 1085]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1056
diff
changeset
|
1065 |
2fe18b2d6105
[gaim-migrate @ 1085]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1056
diff
changeset
|
1066 label = gtk_label_new("Port:"); |
2fe18b2d6105
[gaim-migrate @ 1085]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1056
diff
changeset
|
1067 gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 5); |
2fe18b2d6105
[gaim-migrate @ 1085]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1056
diff
changeset
|
1068 gtk_widget_show(label); |
2fe18b2d6105
[gaim-migrate @ 1085]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1056
diff
changeset
|
1069 |
2fe18b2d6105
[gaim-migrate @ 1085]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1056
diff
changeset
|
1070 entry = gtk_entry_new(); |
2fe18b2d6105
[gaim-migrate @ 1085]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1056
diff
changeset
|
1071 gtk_box_pack_end(GTK_BOX(hbox), entry, FALSE, FALSE, 5); |
2fe18b2d6105
[gaim-migrate @ 1085]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1056
diff
changeset
|
1072 if (user->proto_opt[1][0]) { |
2fe18b2d6105
[gaim-migrate @ 1085]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1056
diff
changeset
|
1073 debug_printf("setting text %s\n", user->proto_opt[1]); |
2fe18b2d6105
[gaim-migrate @ 1085]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1056
diff
changeset
|
1074 gtk_entry_set_text(GTK_ENTRY(entry), user->proto_opt[1]); |
1304 | 1075 } else { |
1076 gtk_entry_set_text(GTK_ENTRY(entry), "6667"); | |
1075
2fe18b2d6105
[gaim-migrate @ 1085]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1056
diff
changeset
|
1077 } |
2fe18b2d6105
[gaim-migrate @ 1085]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1056
diff
changeset
|
1078 gtk_object_set_user_data(GTK_OBJECT(entry), user); |
1266
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
1079 gtk_signal_connect(GTK_OBJECT(entry), "changed", GTK_SIGNAL_FUNC(irc_print_option), user); |
1075
2fe18b2d6105
[gaim-migrate @ 1085]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1056
diff
changeset
|
1080 gtk_widget_show(entry); |
2fe18b2d6105
[gaim-migrate @ 1085]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1056
diff
changeset
|
1081 } |
2fe18b2d6105
[gaim-migrate @ 1085]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1056
diff
changeset
|
1082 |
1266
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
1083 static char **irc_list_icon(int uc) |
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
1084 { |
1178 | 1085 return free_icon_xpm; |
1086 } | |
1087 | |
1088 /* Send out a ping request to the specified user */ | |
1266
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
1089 static void irc_send_ping(GtkObject * w, char *who) |
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
1090 { |
1178 | 1091 struct gaim_connection *gc = (struct gaim_connection *)gtk_object_get_user_data(w); |
1092 struct irc_data *idata = (struct irc_data *)gc->proto_data; | |
1093 char buf[BUF_LEN]; | |
1094 | |
1393 | 1095 g_snprintf(buf, BUF_LEN, "PRIVMSG %s :%cPING %ld%c\n", who, '\001', time((time_t *)NULL), '\001'); |
1178 | 1096 |
1266
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
1097 write(idata->fd, buf, strlen(buf)); |
1178 | 1098 } |
1099 | |
1100 | |
1499
de0b946e86a4
[gaim-migrate @ 1509]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1443
diff
changeset
|
1101 static void irc_buddy_menu(GtkWidget * menu, struct gaim_connection *gc, char *who) |
1266
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
1102 { |
1178 | 1103 GtkWidget *button; |
1266
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
1104 |
1178 | 1105 button = gtk_menu_item_new_with_label("Ping"); |
1266
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
1106 gtk_signal_connect(GTK_OBJECT(button), "activate", GTK_SIGNAL_FUNC(irc_send_ping), who); |
1178 | 1107 gtk_object_set_user_data(GTK_OBJECT(button), gc); |
1108 gtk_menu_append(GTK_MENU(menu), button); | |
1109 gtk_widget_show(button); | |
1110 } | |
1111 | |
1112 | |
1047
ece2d1543b20
[gaim-migrate @ 1057]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1046
diff
changeset
|
1113 static struct prpl *my_protocol = NULL; |
987 | 1114 |
1266
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
1115 static void irc_init(struct prpl *ret) |
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
1116 { |
1008 | 1117 ret->protocol = PROTO_IRC; |
1118 ret->name = irc_name; | |
1178 | 1119 ret->list_icon = irc_list_icon; |
1499
de0b946e86a4
[gaim-migrate @ 1509]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1443
diff
changeset
|
1120 ret->buddy_menu = irc_buddy_menu; |
1075
2fe18b2d6105
[gaim-migrate @ 1085]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1056
diff
changeset
|
1121 ret->user_opts = irc_user_opts; |
1008 | 1122 ret->login = irc_login; |
1011 | 1123 ret->close = irc_close; |
1124 ret->send_im = irc_send_im; | |
1125 ret->join_chat = irc_join_chat; | |
1126 ret->chat_leave = irc_chat_leave; | |
1127 ret->chat_send = irc_chat_send; | |
1047
ece2d1543b20
[gaim-migrate @ 1057]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1046
diff
changeset
|
1128 |
ece2d1543b20
[gaim-migrate @ 1057]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1046
diff
changeset
|
1129 my_protocol = ret; |
987 | 1130 } |
1131 | |
1266
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
1132 char *gaim_plugin_init(GModule * handle) |
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
1133 { |
1443
336fc98b7f90
[gaim-migrate @ 1453]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1394
diff
changeset
|
1134 load_protocol(irc_init, sizeof(struct prpl)); |
1047
ece2d1543b20
[gaim-migrate @ 1057]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1046
diff
changeset
|
1135 return NULL; |
987 | 1136 } |
1047
ece2d1543b20
[gaim-migrate @ 1057]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1046
diff
changeset
|
1137 |
1266
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
1138 void gaim_plugin_remove() |
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
1139 { |
1047
ece2d1543b20
[gaim-migrate @ 1057]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1046
diff
changeset
|
1140 struct prpl *p = find_prpl(PROTO_IRC); |
ece2d1543b20
[gaim-migrate @ 1057]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1046
diff
changeset
|
1141 if (p == my_protocol) |
ece2d1543b20
[gaim-migrate @ 1057]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1046
diff
changeset
|
1142 unload_protocol(p); |
ece2d1543b20
[gaim-migrate @ 1057]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1046
diff
changeset
|
1143 } |