Changes in protocols/nogaim.c [573dab0:cca0692]
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
protocols/nogaim.c
r573dab0 rcca0692 38 38 #include "chat.h" 39 39 40 static int remove_chat_buddy_silent( struct groupchat *b, const char *handle ); 41 static char *format_timestamp( irc_t *irc, time_t msg_ts ); 42 40 43 GSList *connections; 41 44 … … 89 92 } 90 93 #endif 94 95 /* nogaim.c */ 91 96 92 97 GList *protocols = NULL; … … 121 126 } 122 127 128 /* nogaim.c */ 123 129 void nogaim_init() 124 130 { … … 127 133 extern void byahoo_initmodule(); 128 134 extern void jabber_initmodule(); 135 extern void twitter_initmodule(); 129 136 130 137 #ifdef WITH_MSN … … 144 151 #endif 145 152 153 #ifdef WITH_TWITTER 154 twitter_initmodule(); 155 #endif 156 146 157 #ifdef WITH_PLUGINS 147 158 load_plugins(); … … 151 162 GSList *get_connections() { return connections; } 152 163 164 /* multi.c */ 165 153 166 struct im_connection *imcb_new( account_t *acc ) 154 167 { … … 157 170 ic = g_new0( struct im_connection, 1 ); 158 171 159 ic-> bee = acc->bee;172 ic->irc = acc->irc; 160 173 ic->acc = acc; 161 174 acc->ic = ic; … … 171 184 172 185 /* Destroy the pointer to this connection from the account list */ 173 for( a = ic-> bee->accounts; a; a = a->next )186 for( a = ic->irc->accounts; a; a = a->next ) 174 187 if( a->ic == ic ) 175 188 { … … 192 205 va_end( params ); 193 206 194 if( ( g_strcasecmp( set_getstr( &ic-> bee->set, "strip_html" ), "always" ) == 0 ) ||195 ( ( ic->flags & OPT_DOES_HTML ) && set_getbool( &ic-> bee->set, "strip_html" ) ) )207 if( ( g_strcasecmp( set_getstr( &ic->irc->set, "strip_html" ), "always" ) == 0 ) || 208 ( ( ic->flags & OPT_DOES_HTML ) && set_getbool( &ic->irc->set, "strip_html" ) ) ) 196 209 strip_html( text ); 197 210 198 211 /* Try to find a different connection on the same protocol. */ 199 for( a = ic-> bee->accounts; a; a = a->next )212 for( a = ic->irc->accounts; a; a = a->next ) 200 213 if( a->prpl == ic->acc->prpl && a->ic != ic ) 201 214 break; … … 203 216 /* If we found one, include the screenname in the message. */ 204 217 if( a ) 205 /* FIXME(wilmer): ui_log callback or so */ 206 irc_usermsg( ic->bee->ui_data, "%s(%s) - %s", ic->acc->prpl->name, ic->acc->user, text ); 218 irc_usermsg( ic->irc, "%s(%s) - %s", ic->acc->prpl->name, ic->acc->user, text ); 207 219 else 208 irc_usermsg( ic-> bee->ui_data, "%s - %s", ic->acc->prpl->name, text );220 irc_usermsg( ic->irc, "%s - %s", ic->acc->prpl->name, text ); 209 221 210 222 g_free( text ); … … 257 269 void imcb_connected( struct im_connection *ic ) 258 270 { 271 irc_t *irc = ic->irc; 272 struct chat *c; 273 user_t *u; 274 259 275 /* MSN servers sometimes redirect you to a different server and do 260 276 the whole login sequence again, so these "late" calls to this … … 263 279 return; 264 280 281 u = user_find( ic->irc, ic->irc->nick ); 282 265 283 imcb_log( ic, "Logged in" ); 266 284 … … 275 293 ic->acc->auto_reconnect_delay = 0; 276 294 277 /*278 295 for( c = irc->chatrooms; c; c = c->next ) 279 296 { … … 284 301 chat_join( irc, c, NULL ); 285 302 } 286 */287 303 } 288 304 … … 292 308 293 309 a->reconnect = 0; 294 account_on( a-> bee, a );310 account_on( a->irc, a ); 295 311 296 312 return( FALSE ); /* Only have to run the timeout once */ … … 305 321 void imc_logout( struct im_connection *ic, int allow_reconnect ) 306 322 { 307 bee_t *bee = ic->bee; 323 irc_t *irc = ic->irc; 324 user_t *t, *u; 308 325 account_t *a; 309 GSList *l;310 326 int delay; 311 327 … … 327 343 ic->away = NULL; 328 344 329 for( l = bee->users; l; ) 330 { 331 bee_user_t *bu = l->data; 332 GSList *next = l->next; 333 334 if( bu->ic == ic ) 335 bee_user_free( bee, bu ); 336 337 l = next; 338 } 339 340 //query_del_by_conn( ic->irc, ic ); 341 342 for( a = bee->accounts; a; a = a->next ) 345 u = irc->users; 346 while( u ) 347 { 348 if( u->ic == ic ) 349 { 350 t = u->next; 351 user_del( irc, u->nick ); 352 u = t; 353 } 354 else 355 u = u->next; 356 } 357 358 query_del_by_conn( ic->irc, ic ); 359 360 for( a = irc->accounts; a; a = a->next ) 343 361 if( a->ic == ic ) 344 362 break; … … 348 366 /* Uhm... This is very sick. */ 349 367 } 350 else if( allow_reconnect && set_getbool( & bee->set, "auto_reconnect" ) &&368 else if( allow_reconnect && set_getbool( &irc->set, "auto_reconnect" ) && 351 369 set_getbool( &a->set, "auto_reconnect" ) && 352 370 ( delay = account_reconnect_delay( a ) ) > 0 ) … … 359 377 } 360 378 379 380 /* dialogs.c */ 381 361 382 void imcb_ask( struct im_connection *ic, char *msg, void *data, 362 383 query_callback doit, query_callback dont ) 363 384 { 364 query_add( (irc_t *) ic->bee->ui_data, ic, msg, doit, dont, data ); 365 } 385 query_add( ic->irc, ic, msg, doit, dont, data ); 386 } 387 388 389 /* list.c */ 366 390 367 391 void imcb_add_buddy( struct im_connection *ic, const char *handle, const char *group ) 368 392 { 369 bee_user_t *bu; 370 bee_t *bee = ic->bee; 371 372 if( bee_user_by_handle( bee, ic, handle ) ) 373 { 374 if( set_getbool( &bee->set, "debug" ) ) 393 user_t *u; 394 char nick[MAX_NICK_LENGTH+1], *s; 395 irc_t *irc = ic->irc; 396 397 if( user_findhandle( ic, handle ) ) 398 { 399 if( set_getbool( &irc->set, "debug" ) ) 375 400 imcb_log( ic, "User already exists, ignoring add request: %s", handle ); 376 401 … … 383 408 } 384 409 385 bu = bee_user_new( bee, ic, handle ); 386 bu->group = g_strdup( group ); 387 } 388 389 void imcb_rename_buddy( struct im_connection *ic, const char *handle, const char *fullname ) 390 { 391 bee_t *bee = ic->bee; 392 bee_user_t *bu = bee_user_by_handle( bee, ic, handle ); 393 394 if( !bu || !fullname ) return; 395 396 if( !bu->fullname || strcmp( bu->fullname, fullname ) != 0 ) 397 { 398 g_free( bu->fullname ); 399 bu->fullname = g_strdup( fullname ); 400 401 if( bee->ui->user_fullname ) 402 bee->ui->user_fullname( bee, bu ); 410 memset( nick, 0, MAX_NICK_LENGTH + 1 ); 411 strcpy( nick, nick_get( ic->acc, handle ) ); 412 413 u = user_add( ic->irc, nick ); 414 415 // if( !realname || !*realname ) realname = nick; 416 // u->realname = g_strdup( realname ); 417 418 if( ( s = strchr( handle, '@' ) ) ) 419 { 420 u->host = g_strdup( s + 1 ); 421 u->user = g_strndup( handle, s - handle ); 422 } 423 else if( ic->acc->server ) 424 { 425 u->host = g_strdup( ic->acc->server ); 426 u->user = g_strdup( handle ); 427 428 /* s/ /_/ ... important for AOL screennames */ 429 for( s = u->user; *s; s ++ ) 430 if( *s == ' ' ) 431 *s = '_'; 432 } 433 else 434 { 435 u->host = g_strdup( ic->acc->prpl->name ); 436 u->user = g_strdup( handle ); 437 } 438 439 u->ic = ic; 440 u->handle = g_strdup( handle ); 441 if( group ) u->group = g_strdup( group ); 442 u->send_handler = buddy_send_handler; 443 u->last_typing_notice = 0; 444 } 445 446 struct buddy *imcb_find_buddy( struct im_connection *ic, char *handle ) 447 { 448 static struct buddy b[1]; 449 user_t *u; 450 451 u = user_findhandle( ic, handle ); 452 453 if( !u ) 454 return( NULL ); 455 456 memset( b, 0, sizeof( b ) ); 457 strncpy( b->name, handle, 80 ); 458 strncpy( b->show, u->realname, BUDDY_ALIAS_MAXLEN ); 459 b->present = u->online; 460 b->ic = u->ic; 461 462 return( b ); 463 } 464 465 void imcb_rename_buddy( struct im_connection *ic, const char *handle, const char *realname ) 466 { 467 user_t *u = user_findhandle( ic, handle ); 468 char *set; 469 470 if( !u || !realname ) return; 471 472 if( g_strcasecmp( u->realname, realname ) != 0 ) 473 { 474 if( u->realname != u->nick ) g_free( u->realname ); 475 476 u->realname = g_strdup( realname ); 477 478 if( ( ic->flags & OPT_LOGGED_IN ) && set_getbool( &ic->irc->set, "display_namechanges" ) ) 479 imcb_log( ic, "User `%s' changed name to `%s'", u->nick, u->realname ); 480 } 481 482 set = set_getstr( &ic->acc->set, "nick_source" ); 483 if( strcmp( set, "handle" ) != 0 ) 484 { 485 char *name = g_strdup( realname ); 486 487 if( strcmp( set, "first_name" ) == 0 ) 488 { 489 int i; 490 for( i = 0; name[i] && !isspace( name[i] ); i ++ ) {} 491 name[i] = '\0'; 492 } 493 494 imcb_buddy_nick_hint( ic, handle, name ); 495 496 g_free( name ); 403 497 } 404 498 } … … 406 500 void imcb_remove_buddy( struct im_connection *ic, const char *handle, char *group ) 407 501 { 408 bee_user_free( ic->bee, bee_user_by_handle( ic->bee, ic, handle ) ); 502 user_t *u; 503 504 if( ( u = user_findhandle( ic, handle ) ) ) 505 user_del( ic->irc, u->nick ); 409 506 } 410 507 … … 413 510 void imcb_buddy_nick_hint( struct im_connection *ic, const char *handle, const char *nick ) 414 511 { 415 #if 0416 512 user_t *u = user_findhandle( ic, handle ); 417 513 char newnick[MAX_NICK_LENGTH+1], *orig_nick; … … 428 524 /* Some processing to make sure this string is a valid IRC nickname. */ 429 525 nick_strip( newnick ); 430 if( set_getbool( &ic-> bee->set, "lcnicks" ) )526 if( set_getbool( &ic->irc->set, "lcnicks" ) ) 431 527 nick_lc( newnick ); 432 528 … … 445 541 } 446 542 } 447 #endif448 543 } 449 544 … … 490 585 data->ic = ic; 491 586 data->handle = g_strdup( handle ); 492 query_add( (irc_t *) ic->bee->ui_data, ic, s, 493 imcb_ask_auth_cb_yes, imcb_ask_auth_cb_no, data ); 587 query_add( ic->irc, ic, s, imcb_ask_auth_cb_yes, imcb_ask_auth_cb_no, data ); 494 588 } 495 589 … … 516 610 517 611 /* TODO: Make a setting for this! */ 518 if( bee_user_by_handle( ic->bee,ic, handle ) != NULL )612 if( user_findhandle( ic, handle ) != NULL ) 519 613 return; 520 614 … … 523 617 data->ic = ic; 524 618 data->handle = g_strdup( handle ); 525 query_add( (irc_t *) ic->bee->ui_data, ic, s, 526 imcb_ask_add_cb_yes, imcb_ask_add_cb_no, data ); 527 } 528 529 struct bee_user *imcb_buddy_by_handle( struct im_connection *ic, const char *handle ) 530 { 531 return bee_user_by_handle( ic->bee, ic, handle ); 619 query_add( ic->irc, ic, s, imcb_ask_add_cb_yes, imcb_ask_add_cb_no, data ); 620 } 621 622 623 /* server.c */ 624 625 void imcb_buddy_status( struct im_connection *ic, const char *handle, int flags, const char *state, const char *message ) 626 { 627 user_t *u; 628 int oa, oo; 629 630 u = user_findhandle( ic, (char*) handle ); 631 632 if( !u ) 633 { 634 if( g_strcasecmp( set_getstr( &ic->irc->set, "handle_unknown" ), "add" ) == 0 ) 635 { 636 imcb_add_buddy( ic, (char*) handle, NULL ); 637 u = user_findhandle( ic, (char*) handle ); 638 } 639 else 640 { 641 if( set_getbool( &ic->irc->set, "debug" ) || g_strcasecmp( set_getstr( &ic->irc->set, "handle_unknown" ), "ignore" ) != 0 ) 642 { 643 imcb_log( ic, "imcb_buddy_status() for unknown handle %s:", handle ); 644 imcb_log( ic, "flags = %d, state = %s, message = %s", flags, 645 state ? state : "NULL", message ? message : "NULL" ); 646 } 647 648 return; 649 } 650 } 651 652 oa = u->away != NULL; 653 oo = u->online; 654 655 g_free( u->away ); 656 g_free( u->status_msg ); 657 u->away = u->status_msg = NULL; 658 659 if( ( flags & OPT_LOGGED_IN ) && !u->online ) 660 { 661 irc_spawn( ic->irc, u ); 662 u->online = 1; 663 } 664 else if( !( flags & OPT_LOGGED_IN ) && u->online ) 665 { 666 struct groupchat *c; 667 668 irc_kill( ic->irc, u ); 669 u->online = 0; 670 671 /* Remove him/her from the groupchats to prevent PART messages after he/she QUIT already */ 672 for( c = ic->groupchats; c; c = c->next ) 673 remove_chat_buddy_silent( c, handle ); 674 } 675 676 if( flags & OPT_AWAY ) 677 { 678 if( state && message ) 679 { 680 u->away = g_strdup_printf( "%s (%s)", state, message ); 681 } 682 else if( state ) 683 { 684 u->away = g_strdup( state ); 685 } 686 else if( message ) 687 { 688 u->away = g_strdup( message ); 689 } 690 else 691 { 692 u->away = g_strdup( "Away" ); 693 } 694 } 695 else 696 { 697 u->status_msg = g_strdup( message ); 698 } 699 700 /* LISPy... */ 701 if( ( set_getbool( &ic->irc->set, "away_devoice" ) ) && /* Don't do a thing when user doesn't want it */ 702 ( u->online ) && /* Don't touch offline people */ 703 ( ( ( u->online != oo ) && !u->away ) || /* Voice joining people */ 704 ( ( u->online == oo ) && ( oa == !u->away ) ) ) ) /* (De)voice people changing state */ 705 { 706 char *from; 707 708 if( set_getbool( &ic->irc->set, "simulate_netsplit" ) ) 709 { 710 from = g_strdup( ic->irc->myhost ); 711 } 712 else 713 { 714 from = g_strdup_printf( "%s!%s@%s", ic->irc->mynick, ic->irc->mynick, 715 ic->irc->myhost ); 716 } 717 irc_write( ic->irc, ":%s MODE %s %cv %s", from, ic->irc->channel, 718 u->away?'-':'+', u->nick ); 719 g_free( from ); 720 } 721 } 722 723 void imcb_buddy_msg( struct im_connection *ic, const char *handle, char *msg, uint32_t flags, time_t sent_at ) 724 { 725 irc_t *irc = ic->irc; 726 char *wrapped, *ts = NULL; 727 user_t *u; 728 729 u = user_findhandle( ic, handle ); 730 731 if( !u ) 732 { 733 char *h = set_getstr( &irc->set, "handle_unknown" ); 734 735 if( g_strcasecmp( h, "ignore" ) == 0 ) 736 { 737 if( set_getbool( &irc->set, "debug" ) ) 738 imcb_log( ic, "Ignoring message from unknown handle %s", handle ); 739 740 return; 741 } 742 else if( g_strncasecmp( h, "add", 3 ) == 0 ) 743 { 744 int private = set_getbool( &irc->set, "private" ); 745 746 if( h[3] ) 747 { 748 if( g_strcasecmp( h + 3, "_private" ) == 0 ) 749 private = 1; 750 else if( g_strcasecmp( h + 3, "_channel" ) == 0 ) 751 private = 0; 752 } 753 754 imcb_add_buddy( ic, handle, NULL ); 755 u = user_findhandle( ic, handle ); 756 u->is_private = private; 757 } 758 else 759 { 760 imcb_log( ic, "Message from unknown handle %s:", handle ); 761 u = user_find( irc, irc->mynick ); 762 } 763 } 764 765 if( ( g_strcasecmp( set_getstr( &ic->irc->set, "strip_html" ), "always" ) == 0 ) || 766 ( ( ic->flags & OPT_DOES_HTML ) && set_getbool( &ic->irc->set, "strip_html" ) ) ) 767 strip_html( msg ); 768 769 if( set_getbool( &ic->irc->set, "display_timestamps" ) && 770 ( ts = format_timestamp( irc, sent_at ) ) ) 771 { 772 char *new = g_strconcat( ts, msg, NULL ); 773 g_free( ts ); 774 ts = msg = new; 775 } 776 777 wrapped = word_wrap( msg, 425 ); 778 irc_msgfrom( irc, u->nick, wrapped ); 779 g_free( wrapped ); 780 g_free( ts ); 781 } 782 783 void imcb_buddy_typing( struct im_connection *ic, char *handle, uint32_t flags ) 784 { 785 user_t *u; 786 787 if( !set_getbool( &ic->irc->set, "typing_notice" ) ) 788 return; 789 790 if( ( u = user_findhandle( ic, handle ) ) ) 791 { 792 char buf[256]; 793 794 g_snprintf( buf, 256, "\1TYPING %d\1", ( flags >> 8 ) & 3 ); 795 irc_privmsg( ic->irc, u, "PRIVMSG", ic->irc->nick, NULL, buf ); 796 } 532 797 } 533 798 534 799 struct groupchat *imcb_chat_new( struct im_connection *ic, const char *handle ) 535 800 { 536 #if 0537 801 struct groupchat *c; 538 802 … … 552 816 c->topic = g_strdup_printf( "BitlBee groupchat: \"%s\". Please keep in mind that root-commands won't work here. Have fun!", c->title ); 553 817 554 if( set_getbool( &ic-> bee->set, "debug" ) )818 if( set_getbool( &ic->irc->set, "debug" ) ) 555 819 imcb_log( ic, "Creating new conversation: (id=%p,handle=%s)", c, handle ); 556 820 557 821 return c; 558 #endif 559 return NULL; 822 } 823 824 void imcb_chat_name_hint( struct groupchat *c, const char *name ) 825 { 826 if( !c->joined ) 827 { 828 struct im_connection *ic = c->ic; 829 char stripped[MAX_NICK_LENGTH+1], *full_name; 830 831 strncpy( stripped, name, MAX_NICK_LENGTH ); 832 stripped[MAX_NICK_LENGTH] = '\0'; 833 nick_strip( stripped ); 834 if( set_getbool( &ic->irc->set, "lcnicks" ) ) 835 nick_lc( stripped ); 836 837 full_name = g_strdup_printf( "&%s", stripped ); 838 839 if( stripped[0] && 840 nick_cmp( stripped, ic->irc->channel + 1 ) != 0 && 841 irc_chat_by_channel( ic->irc, full_name ) == NULL ) 842 { 843 g_free( c->channel ); 844 c->channel = full_name; 845 } 846 else 847 { 848 g_free( full_name ); 849 } 850 } 560 851 } 561 852 562 853 void imcb_chat_free( struct groupchat *c ) 563 854 { 564 #if 0565 855 struct im_connection *ic = c->ic; 566 856 struct groupchat *l; 567 857 GList *ir; 568 858 569 if( set_getbool( &ic-> bee->set, "debug" ) )859 if( set_getbool( &ic->irc->set, "debug" ) ) 570 860 imcb_log( ic, "You were removed from conversation %p", c ); 571 861 … … 600 890 g_free( c ); 601 891 } 602 #endif603 892 } 604 893 605 894 void imcb_chat_msg( struct groupchat *c, const char *who, char *msg, uint32_t flags, time_t sent_at ) 606 895 { 607 #if 0608 896 struct im_connection *ic = c->ic; 609 897 char *wrapped; … … 616 904 u = user_findhandle( ic, who ); 617 905 618 if( ( g_strcasecmp( set_getstr( &ic-> bee->set, "strip_html" ), "always" ) == 0 ) ||619 ( ( ic->flags & OPT_DOES_HTML ) && set_getbool( &ic-> bee->set, "strip_html" ) ) )906 if( ( g_strcasecmp( set_getstr( &ic->irc->set, "strip_html" ), "always" ) == 0 ) || 907 ( ( ic->flags & OPT_DOES_HTML ) && set_getbool( &ic->irc->set, "strip_html" ) ) ) 620 908 strip_html( msg ); 621 909 … … 623 911 if( c && u ) 624 912 { 625 irc_privmsg( ic->irc, u, "PRIVMSG", c->channel, "", wrapped ); 913 char *ts = NULL; 914 if( set_getbool( &ic->irc->set, "display_timestamps" ) ) 915 ts = format_timestamp( ic->irc, sent_at ); 916 irc_privmsg( ic->irc, u, "PRIVMSG", c->channel, ts ? : "", wrapped ); 917 g_free( ts ); 626 918 } 627 919 else … … 630 922 } 631 923 g_free( wrapped ); 632 #endif633 924 } 634 925 635 926 void imcb_chat_log( struct groupchat *c, char *format, ... ) 636 927 { 637 #if 0638 928 irc_t *irc = c->ic->irc; 639 929 va_list params; … … 650 940 651 941 g_free( text ); 652 #endif653 942 } 654 943 655 944 void imcb_chat_topic( struct groupchat *c, char *who, char *topic, time_t set_at ) 656 945 { 657 #if 0658 946 struct im_connection *ic = c->ic; 659 947 user_t *u = NULL; … … 666 954 u = user_findhandle( ic, who ); 667 955 668 if( ( g_strcasecmp( set_getstr( &ic-> bee->set, "strip_html" ), "always" ) == 0 ) ||669 ( ( ic->flags & OPT_DOES_HTML ) && set_getbool( &ic-> bee->set, "strip_html" ) ) )956 if( ( g_strcasecmp( set_getstr( &ic->irc->set, "strip_html" ), "always" ) == 0 ) || 957 ( ( ic->flags & OPT_DOES_HTML ) && set_getbool( &ic->irc->set, "strip_html" ) ) ) 670 958 strip_html( topic ); 671 959 … … 675 963 if( c->joined && u ) 676 964 irc_write( ic->irc, ":%s!%s@%s TOPIC %s :%s", u->nick, u->user, u->host, c->channel, topic ); 677 #endif 678 } 965 } 966 967 968 /* buddy_chat.c */ 679 969 680 970 void imcb_chat_add_buddy( struct groupchat *b, const char *handle ) 681 971 { 682 #if 0683 972 user_t *u = user_findhandle( b->ic, handle ); 684 973 int me = 0; 685 974 686 if( set_getbool( &b->ic-> bee->set, "debug" ) )975 if( set_getbool( &b->ic->irc->set, "debug" ) ) 687 976 imcb_log( b->ic, "User %s added to conversation %p", handle, b ); 688 977 … … 711 1000 b->in_room = g_list_append( b->in_room, g_strdup( handle ) ); 712 1001 } 713 #endif714 1002 } 715 1003 … … 717 1005 void imcb_chat_remove_buddy( struct groupchat *b, const char *handle, const char *reason ) 718 1006 { 719 #if 0720 1007 user_t *u; 721 1008 int me = 0; 722 1009 723 if( set_getbool( &b->ic-> bee->set, "debug" ) )1010 if( set_getbool( &b->ic->irc->set, "debug" ) ) 724 1011 imcb_log( b->ic, "User %s removed from conversation %p (%s)", handle, b, reason ? reason : "" ); 725 1012 … … 741 1028 if( me || ( remove_chat_buddy_silent( b, handle ) && b->joined && u ) ) 742 1029 irc_part( b->ic->irc, u, b->channel ); 743 #endif 744 } 745 746 #if 0 1030 } 1031 747 1032 static int remove_chat_buddy_silent( struct groupchat *b, const char *handle ) 748 1033 { … … 763 1048 } 764 1049 765 return 0; 766 } 767 #endif 1050 return( 0 ); 1051 } 768 1052 769 1053 770 1054 /* Misc. BitlBee stuff which shouldn't really be here */ 771 #if 0 1055 772 1056 char *set_eval_away_devoice( set_t *set, char *value ) 773 1057 { … … 782 1066 /* Horror.... */ 783 1067 784 if( st != set_getbool( &irc-> b->set, "away_devoice" ) )1068 if( st != set_getbool( &irc->set, "away_devoice" ) ) 785 1069 { 786 1070 char list[80] = ""; … … 824 1108 return value; 825 1109 } 826 #endif 827 828 1110 1111 char *set_eval_timezone( set_t *set, char *value ) 1112 { 1113 char *s; 1114 1115 if( strcmp( value, "local" ) == 0 || 1116 strcmp( value, "gmt" ) == 0 || strcmp( value, "utc" ) == 0 ) 1117 return value; 1118 1119 /* Otherwise: +/- at the beginning optional, then one or more numbers, 1120 possibly followed by a colon and more numbers. Don't bother bound- 1121 checking them since users are free to shoot themselves in the foot. */ 1122 s = value; 1123 if( *s == '+' || *s == '-' ) 1124 s ++; 1125 1126 /* \d+ */ 1127 if( !isdigit( *s ) ) 1128 return SET_INVALID; 1129 while( *s && isdigit( *s ) ) s ++; 1130 1131 /* EOS? */ 1132 if( *s == '\0' ) 1133 return value; 1134 1135 /* Otherwise, colon */ 1136 if( *s != ':' ) 1137 return SET_INVALID; 1138 s ++; 1139 1140 /* \d+ */ 1141 if( !isdigit( *s ) ) 1142 return SET_INVALID; 1143 while( *s && isdigit( *s ) ) s ++; 1144 1145 /* EOS */ 1146 return *s == '\0' ? value : SET_INVALID; 1147 } 1148 1149 static char *format_timestamp( irc_t *irc, time_t msg_ts ) 1150 { 1151 time_t now_ts = time( NULL ); 1152 struct tm now, msg; 1153 char *set; 1154 1155 /* If the timestamp is <= 0 or less than a minute ago, discard it as 1156 it doesn't seem to add to much useful info and/or might be noise. */ 1157 if( msg_ts <= 0 || msg_ts > now_ts - 60 ) 1158 return NULL; 1159 1160 set = set_getstr( &irc->set, "timezone" ); 1161 if( strcmp( set, "local" ) == 0 ) 1162 { 1163 localtime_r( &now_ts, &now ); 1164 localtime_r( &msg_ts, &msg ); 1165 } 1166 else 1167 { 1168 int hr, min = 0, sign = 60; 1169 1170 if( set[0] == '-' ) 1171 { 1172 sign *= -1; 1173 set ++; 1174 } 1175 else if( set[0] == '+' ) 1176 { 1177 set ++; 1178 } 1179 1180 if( sscanf( set, "%d:%d", &hr, &min ) >= 1 ) 1181 { 1182 msg_ts += sign * ( hr * 60 + min ); 1183 now_ts += sign * ( hr * 60 + min ); 1184 } 1185 1186 gmtime_r( &now_ts, &now ); 1187 gmtime_r( &msg_ts, &msg ); 1188 } 1189 1190 if( msg.tm_year == now.tm_year && msg.tm_yday == now.tm_yday ) 1191 return g_strdup_printf( "\x02[\x02\x02\x02%02d:%02d:%02d\x02]\x02 ", 1192 msg.tm_hour, msg.tm_min, msg.tm_sec ); 1193 else 1194 return g_strdup_printf( "\x02[\x02\x02\x02%04d-%02d-%02d " 1195 "%02d:%02d:%02d\x02]\x02 ", 1196 msg.tm_year + 1900, msg.tm_mon, msg.tm_mday, 1197 msg.tm_hour, msg.tm_min, msg.tm_sec ); 1198 } 829 1199 830 1200 /* The plan is to not allow straight calls to prpl functions anymore, but do 831 1201 them all from some wrappers. We'll start to define some down here: */ 832 1202 833 int imc_ chat_msg( struct groupchat *c, char *msg, int flags )1203 int imc_buddy_msg( struct im_connection *ic, char *handle, char *msg, int flags ) 834 1204 { 835 1205 char *buf = NULL; 836 837 if( ( c->ic->flags & OPT_DOES_HTML ) && ( g_strncasecmp( msg, "<html>", 6 ) != 0 ) ) 1206 int st; 1207 1208 if( ( ic->flags & OPT_DOES_HTML ) && ( g_strncasecmp( msg, "<html>", 6 ) != 0 ) ) 838 1209 { 839 1210 buf = escape_html( msg ); … … 841 1212 } 842 1213 1214 st = ic->acc->prpl->buddy_msg( ic, handle, msg, flags ); 1215 g_free( buf ); 1216 1217 return st; 1218 } 1219 1220 int imc_chat_msg( struct groupchat *c, char *msg, int flags ) 1221 { 1222 char *buf = NULL; 1223 1224 if( ( c->ic->flags & OPT_DOES_HTML ) && ( g_strncasecmp( msg, "<html>", 6 ) != 0 ) ) 1225 { 1226 buf = escape_html( msg ); 1227 msg = buf; 1228 } 1229 843 1230 c->ic->acc->prpl->chat_msg( c, msg, flags ); 844 1231 g_free( buf ); … … 853 1240 char *away, *msg = NULL; 854 1241 1242 if( ic->acc->prpl->away_states == NULL || 1243 ic->acc->prpl->set_away == NULL ) 1244 return 0; 1245 855 1246 away = set_getstr( &ic->acc->set, "away" ) ? 856 : set_getstr( &ic-> bee->set, "away" );1247 : set_getstr( &ic->irc->set, "away" ); 857 1248 if( away && *away ) 858 1249 { … … 865 1256 away = NULL; 866 1257 msg = set_getstr( &ic->acc->set, "status" ) ? 867 : set_getstr( &ic-> bee->set, "status" );1258 : set_getstr( &ic->irc->set, "status" ); 868 1259 } 869 1260
Note: See TracChangeset
for help on using the changeset viewer.