Mercurial > pidgin
comparison src/server.c @ 1775:9ca22174da76
[gaim-migrate @ 1785]
cleaning up some stuff of rob's
committer: Tailor Script <tailor@pidgin.im>
| author | Eric Warmenhoven <eric@warmenhoven.org> |
|---|---|
| date | Mon, 30 Apr 2001 08:33:25 +0000 |
| parents | 9d0c91c705b7 |
| children | f4ae086c746b |
comparison
equal
deleted
inserted
replaced
| 1774:9d0c91c705b7 | 1775:9ca22174da76 |
|---|---|
| 333 GSList *templist; | 333 GSList *templist; |
| 334 int i = 0; | 334 int i = 0; |
| 335 | 335 |
| 336 templist = message_queue; | 336 templist = message_queue; |
| 337 | 337 |
| 338 while (templist) | 338 while (templist) { |
| 339 { | |
| 340 struct queued_message *qm = (struct queued_message *)templist->data; | 339 struct queued_message *qm = (struct queued_message *)templist->data; |
| 341 if (!strcmp(name, qm->name)) | 340 if ((qm->flags & WFLAG_RECV) && !strcmp(name, qm->name)) |
| 342 i++; | 341 i++; |
| 343 | 342 |
| 344 templist = templist->next; | 343 templist = templist->next; |
| 345 } | 344 } |
| 346 | 345 |
| 352 GSList *templist; | 351 GSList *templist; |
| 353 struct queued_away_response *qar; | 352 struct queued_away_response *qar; |
| 354 | 353 |
| 355 templist = away_time_queue; | 354 templist = away_time_queue; |
| 356 | 355 |
| 357 while (templist) | 356 while (templist) { |
| 358 { | |
| 359 qar = (struct queued_away_response *)templist->data; | 357 qar = (struct queued_away_response *)templist->data; |
| 360 | 358 |
| 361 if (!strcmp(name, qar->name)) | 359 if (!strcmp(name, qar->name)) |
| 362 return qar; | 360 return qar; |
| 363 | 361 |
| 365 } | 363 } |
| 366 | 364 |
| 367 return NULL; | 365 return NULL; |
| 368 } | 366 } |
| 369 | 367 |
| 368 /* woo. i'm actually going to comment this function. isn't that fun. make sure to follow along, kids */ | |
| 370 void serv_got_im(struct gaim_connection *gc, char *name, char *message, int away, time_t mtime) | 369 void serv_got_im(struct gaim_connection *gc, char *name, char *message, int away, time_t mtime) |
| 371 { | 370 { |
| 372 struct conversation *cnv; | 371 struct conversation *cnv; |
| 373 int new_conv = 0; | 372 int new_conv = 0; |
| 374 int hehe = away; | 373 int hehe = away; |
| 375 | 374 |
| 375 /* plugin stuff. we pass a char ** but we don't want to pass what's been given us | |
| 376 * by the prpls. so we create temp holders and pass those instead. it's basically | |
| 377 * just to avoid segfaults. */ | |
| 376 char *buffy = g_strdup(message); | 378 char *buffy = g_strdup(message); |
| 377 char *angel = g_strdup(name); | 379 char *angel = g_strdup(name); |
| 378 int plugin_return = plugin_event(event_im_recv, gc, &angel, &buffy, 0); | 380 int plugin_return = plugin_event(event_im_recv, gc, &angel, &buffy, 0); |
| 379 | 381 |
| 380 if (!buffy || !angel || plugin_return) { | 382 if (!buffy || !angel || plugin_return) { |
| 387 g_snprintf(message, strlen(message) + 1, "%s", buffy); | 389 g_snprintf(message, strlen(message) + 1, "%s", buffy); |
| 388 g_free(buffy); | 390 g_free(buffy); |
| 389 g_snprintf(name, strlen(name) + 1, "%s", angel); | 391 g_snprintf(name, strlen(name) + 1, "%s", angel); |
| 390 g_free(angel); | 392 g_free(angel); |
| 391 | 393 |
| 392 if ((general_options & OPT_GEN_TIK_HACK) && awaymessage && | 394 /* TiK, using TOC, sends an automated message in order to get your away message. Now, |
| 395 * this is one of the biggest hacks I think I've seen. But, in order to be nice to | |
| 396 * TiK, we're going to give users the option to ignore it. */ | |
| 397 if ((general_options & OPT_GEN_TIK_HACK) && gc->away && strlen(gc->away) && | |
| 393 !strcmp(message, ">>>Automated Message: Getting Away Message<<<")) { | 398 !strcmp(message, ">>>Automated Message: Getting Away Message<<<")) { |
| 394 char *tmpmsg = stylize(awaymessage->message, MSG_LEN); | 399 char *tmpmsg = stylize(awaymessage->message, MSG_LEN); |
| 395 serv_send_im(gc, name, tmpmsg, 1); | 400 serv_send_im(gc, name, tmpmsg, 1); |
| 396 g_free(tmpmsg); | 401 g_free(tmpmsg); |
| 397 return; | 402 return; |
| 398 } | 403 } |
| 399 | 404 |
| 405 /* we should update the conversation window buttons and menu, if it exists. */ | |
| 400 cnv = find_conversation(name); | 406 cnv = find_conversation(name); |
| 401 if (cnv) { | 407 if (cnv) { |
| 402 cnv->gc = gc; | 408 cnv->gc = gc; |
| 403 gtk_option_menu_set_history(GTK_OPTION_MENU(cnv->menu), g_slist_index(connections, gc)); | 409 gtk_option_menu_set_history(GTK_OPTION_MENU(cnv->menu), g_slist_index(connections, gc)); |
| 404 update_buttons_by_protocol(cnv); | 410 update_buttons_by_protocol(cnv); |
| 405 } | 411 } |
| 406 | 412 |
| 407 if (general_options & OPT_GEN_SEND_LINKS) { | 413 /* if you can't figure this out, stop reading right now. |
| 414 * "we're not worthy! we're not worthy!" */ | |
| 415 if (general_options & OPT_GEN_SEND_LINKS) | |
| 408 linkify_text(message); | 416 linkify_text(message); |
| 409 } | 417 |
| 410 | 418 /* um. when we call write_to_conv with the message we received, it's nice to pass whether |
| 419 * or not it was an auto-response. so if it was an auto-response, we set the appropriate | |
| 420 * flag. this is just so prpls don't have to know about WFLAG_* (though some do anyway) */ | |
| 411 if (away) | 421 if (away) |
| 412 away = WFLAG_AUTO; | 422 away = WFLAG_AUTO; |
| 413 | 423 |
| 424 /* alright. two cases for how to handle this. either we're away or we're not. if we're not, | |
| 425 * then it's easy. if we are, then there are three or four different ways of handling it | |
| 426 * and different things we have to do for each. */ | |
| 414 if (gc->away) { | 427 if (gc->away) { |
| 415 if (general_options & OPT_GEN_QUEUE_WHEN_AWAY) | 428 time_t t; |
| 416 { | 429 char *tmpmsg; |
| 430 struct buddy *b = find_buddy(gc, name); | |
| 431 char *alias = b ? b->show : name; | |
| 432 int row; | |
| 433 struct queued_away_response *qar; | |
| 434 | |
| 435 time(&t); | |
| 436 | |
| 437 /* either we're going to queue it or not. Because of the way awayness currently | |
| 438 * works, this is fucked up. it's possible for an account to be away without the | |
| 439 * imaway dialog being shown. in fact, it's possible for *all* the accounts to be | |
| 440 * away without the imaway dialog being shown. so in order for this to be queued | |
| 441 * properly, we have to make sure that the imaway dialog actually exists, first. */ | |
| 442 if (!cnv && clistqueue && (general_options & OPT_GEN_QUEUE_WHEN_AWAY)) { | |
| 443 /* alright, so we're going to queue it. neat, eh? :) so first we create | |
| 444 * something to store the message, and add it to our queue. Then we update | |
| 445 * the away dialog to indicate that we've queued something. */ | |
| 417 struct queued_message *qm; | 446 struct queued_message *qm; |
| 418 struct queued_away_response *qar; | 447 |
| 419 int row; | 448 qm = g_new0(struct queued_message, 1); |
| 420 | |
| 421 qm = (struct queued_message *)g_new0(struct queued_message, 1); | |
| 422 g_snprintf(qm->name, sizeof(qm->name), "%s", name); | 449 g_snprintf(qm->name, sizeof(qm->name), "%s", name); |
| 423 qm->message = strdup(message); | 450 qm->message = g_strdup(message); |
| 424 qm->gc = gc; | 451 qm->gc = gc; |
| 425 qm->tm = mtime; | 452 qm->tm = mtime; |
| 453 qm->flags = WFLAG_RECV | away; | |
| 454 message_queue = g_slist_append(message_queue, qm); | |
| 426 | 455 |
| 427 row = find_queue_row_by_name(qm->name); | 456 row = find_queue_row_by_name(qm->name); |
| 428 | 457 |
| 429 if (row >= 0) | 458 if (row >= 0) { |
| 430 { | |
| 431 char number[32]; | 459 char number[32]; |
| 432 int qtotal; | 460 int qtotal; |
| 433 | 461 |
| 434 qtotal = find_queue_total_by_name(qm->name); | 462 qtotal = find_queue_total_by_name(qm->name); |
| 435 | 463 g_snprintf(number, 32, _("(%d messages)"), qtotal); |
| 436 g_snprintf(number, 32, _("(%d messages)"), ++qtotal); | |
| 437 | |
| 438 gtk_clist_set_text(GTK_CLIST(clistqueue), row, 1, number); | 464 gtk_clist_set_text(GTK_CLIST(clistqueue), row, 1, number); |
| 465 } else { | |
| 466 gchar *heh[2]; | |
| 467 | |
| 468 heh[0] = qm->name; | |
| 469 heh[1] = _("(1 message)"); | |
| 470 gtk_clist_append(GTK_CLIST(clistqueue), heh); | |
| 439 } | 471 } |
| 440 else | 472 } else { |
| 441 { | 473 /* ok, so we're not queuing it. well then, we'll try to handle it normally. |
| 442 | 474 * Some people think that ignoring it is a perfectly acceptible way to handle |
| 443 gchar *heh[2]; | 475 * it. i think they're on crack, but hey, that's why it's optional. */ |
| 444 int tmp = 0; | 476 if (general_options & OPT_GEN_DISCARD_WHEN_AWAY) |
| 445 | 477 return; |
| 446 heh[0] = g_strdup(qm->name); | 478 |
| 447 heh[1] = g_strdup(_("(1 message)")); | 479 /* ok, so we're not ignoring it. make sure the conversation exists and is |
| 448 gtk_clist_append(GTK_CLIST(clistqueue), heh); | 480 * updated (partly handled above already), play the receive sound (sound.c |
| 449 | 481 * will take care of not playing while away), and then write it to the |
| 450 row = find_queue_row_by_name(qm->name); | 482 * convo window. */ |
| 451 | 483 if (cnv == NULL) { |
| 452 g_free(heh[0]); | 484 new_conv = 1; |
| 453 g_free(heh[1]); | 485 cnv = new_conversation(name); |
| 486 cnv->gc = gc; | |
| 487 gtk_option_menu_set_history(GTK_OPTION_MENU(cnv->menu), | |
| 488 g_slist_index(connections, gc)); | |
| 489 update_buttons_by_protocol(cnv); | |
| 454 } | 490 } |
| 455 | 491 if (new_conv && (sound_options & OPT_SOUND_FIRST_RCV)) |
| 492 play_sound(FIRST_RECEIVE); | |
| 493 else if (cnv->makesound && (sound_options & OPT_SOUND_RECV)) | |
| 494 play_sound(RECEIVE); | |
| 495 | |
| 496 write_to_conv(cnv, message, away | WFLAG_RECV, NULL, mtime); | |
| 497 } | |
| 498 | |
| 499 /* regardless of whether we queue it or not, we should send an auto-response. That is, | |
| 500 * of course, unless the horse.... no wait. */ | |
| 501 if ((general_options & OPT_GEN_NO_AUTO_RESP) || !strlen(gc->away)) | |
| 502 return; | |
| 503 | |
| 504 /* this used to be based on the conversation window. but um, if you went away, and | |
| 505 * someone sent you a message and got your auto-response, and then you closed the | |
| 506 * window, and then the sent you another one, they'd get the auto-response back | |
| 507 * too soon. besides that, we need to keep track of this even if we've got a queue. | |
| 508 * so the rest of this block is just the auto-response, if necessary */ | |
| 509 qar = find_queued_away_response_by_name(name); | |
| 510 if (!qar) { | |
| 511 qar = (struct queued_away_response *)g_new0(struct queued_away_response, 1); | |
| 512 g_snprintf(qar->name, sizeof(qar->name), "%s", name); | |
| 513 qar->sent_away = 0; | |
| 514 away_time_queue = g_slist_append(away_time_queue, qar); | |
| 515 } | |
| 516 if ((t - qar->sent_away) < 120) | |
| 517 return; | |
| 518 qar->sent_away = t; | |
| 519 | |
| 520 /* apply default fonts and colors */ | |
| 521 tmpmsg = stylize(gc->away, MSG_LEN); | |
| 522 serv_send_im(gc, name, away_subs(tmpmsg, alias), 1); | |
| 523 if (!cnv && clistqueue && (general_options & OPT_GEN_QUEUE_WHEN_AWAY)) { | |
| 524 struct queued_message *qm; | |
| 525 qm = g_new0(struct queued_message, 1); | |
| 526 g_snprintf(qm->name, sizeof(qm->name), "%s", name); | |
| 527 qm->message = g_strdup(message); | |
| 528 qm->gc = gc; | |
| 529 qm->tm = mtime; | |
| 530 qm->flags = WFLAG_SEND | WFLAG_AUTO; | |
| 456 message_queue = g_slist_append(message_queue, qm); | 531 message_queue = g_slist_append(message_queue, qm); |
| 457 } | 532 } else if (cnv != NULL) |
| 458 else | 533 write_to_conv(cnv, away_subs(tmpmsg, alias), WFLAG_SEND | WFLAG_AUTO, NULL, mtime); |
| 459 { | 534 g_free(tmpmsg); |
| 460 if (!(general_options & OPT_GEN_DISCARD_WHEN_AWAY)) { | |
| 461 if (cnv == NULL) { | |
| 462 new_conv = 1; | |
| 463 cnv = new_conversation(name); | |
| 464 cnv->gc = gc; | |
| 465 gtk_option_menu_set_history(GTK_OPTION_MENU(cnv->menu), | |
| 466 g_slist_index(connections, gc)); | |
| 467 update_buttons_by_protocol(cnv); | |
| 468 } | |
| 469 } else { | |
| 470 return; | |
| 471 } | |
| 472 if (cnv != NULL) { | |
| 473 if (cnv->makesound && (sound_options & OPT_SOUND_RECV)) | |
| 474 play_sound(RECEIVE); | |
| 475 | |
| 476 write_to_conv(cnv, message, away | WFLAG_RECV, NULL, mtime); | |
| 477 } | |
| 478 } | |
| 479 | |
| 480 } else { | 535 } else { |
| 536 /* we're not away. this is easy. if the convo window doesn't exist, create and update | |
| 537 * it (if it does exist it was updated earlier), then play a sound indicating we've | |
| 538 * received it and then display it. easy. */ | |
| 481 if (cnv == NULL) { | 539 if (cnv == NULL) { |
| 482 new_conv = 1; | 540 new_conv = 1; |
| 483 cnv = new_conversation(name); | 541 cnv = new_conversation(name); |
| 484 cnv->gc = gc; | 542 cnv->gc = gc; |
| 485 gtk_option_menu_set_history(GTK_OPTION_MENU(cnv->menu), | 543 gtk_option_menu_set_history(GTK_OPTION_MENU(cnv->menu), |
| 486 g_slist_index(connections, gc)); | 544 g_slist_index(connections, gc)); |
| 487 update_buttons_by_protocol(cnv); | 545 update_buttons_by_protocol(cnv); |
| 488 } | 546 } |
| 489 if (new_conv && (sound_options & OPT_SOUND_FIRST_RCV)) { | 547 if (new_conv && (sound_options & OPT_SOUND_FIRST_RCV)) |
| 490 play_sound(FIRST_RECEIVE); | 548 play_sound(FIRST_RECEIVE); |
| 491 } else | 549 else if (cnv->makesound && (sound_options & OPT_SOUND_RECV)) |
| 492 { | 550 play_sound(RECEIVE); |
| 493 if (cnv->makesound && (sound_options & OPT_SOUND_RECV)) | |
| 494 play_sound(RECEIVE); | |
| 495 } | |
| 496 | 551 |
| 497 write_to_conv(cnv, message, away | WFLAG_RECV, NULL, mtime); | 552 write_to_conv(cnv, message, away | WFLAG_RECV, NULL, mtime); |
| 498 } | |
| 499 | |
| 500 | |
| 501 | |
| 502 | |
| 503 if (!(general_options & OPT_GEN_NO_AUTO_RESP) && gc->away && strlen(gc->away)) { | |
| 504 time_t t; | |
| 505 char *tmpmsg; | |
| 506 struct buddy *b = find_buddy(gc, name); | |
| 507 char *alias = b ? b->show : name; | |
| 508 int sawy; | |
| 509 int row; | |
| 510 struct queued_away_response *qar = NULL; | |
| 511 | |
| 512 time(&t); | |
| 513 | |
| 514 if (cnv) | |
| 515 sawy = cnv->sent_away; | |
| 516 else | |
| 517 { | |
| 518 qar = find_queued_away_response_by_name(name); | |
| 519 | |
| 520 if (!qar) | |
| 521 { | |
| 522 qar = (struct queued_away_response *)g_new0(struct queued_away_response, 1); | |
| 523 | |
| 524 g_snprintf(qar->name, sizeof(qar->name), "%s", name); | |
| 525 qar->sent_away = 0; | |
| 526 | |
| 527 away_time_queue = g_slist_append(away_time_queue, qar); | |
| 528 } | |
| 529 | |
| 530 sawy = qar->sent_away; | |
| 531 } | |
| 532 | |
| 533 if ((t - sawy) < 120) | |
| 534 return; | |
| 535 | |
| 536 /* apply default fonts and colors */ | |
| 537 tmpmsg = stylize(gc->away, MSG_LEN); | |
| 538 serv_send_im(gc, name, away_subs(tmpmsg, alias), 1); | |
| 539 | |
| 540 if (cnv) | |
| 541 cnv->sent_away = t; | |
| 542 else if (qar) | |
| 543 qar->sent_away = t; | |
| 544 | |
| 545 if (cnv != NULL) | |
| 546 write_to_conv(cnv, away_subs(tmpmsg, alias), WFLAG_SEND | WFLAG_AUTO, NULL, mtime); | |
| 547 | |
| 548 g_free(tmpmsg); | |
| 549 } | 553 } |
| 550 } | 554 } |
| 551 | 555 |
| 552 | 556 |
| 553 | 557 |
