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