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