Changes in protocols/nogaim.c [286b28e:c6ca3ee]
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
protocols/nogaim.c
r286b28e rc6ca3ee 2 2 * BitlBee -- An IRC to other IM-networks gateway * 3 3 * * 4 * Copyright 2002-20 10Wilmer van der Gaast and others *4 * Copyright 2002-2006 Wilmer van der Gaast and others * 5 5 \********************************************************************/ 6 6 … … 33 33 34 34 #define BITLBEE_CORE 35 #include "nogaim.h" 35 36 #include <ctype.h> 36 37 #include "nogaim.h"38 #include "chat.h"39 37 40 38 static int remove_chat_buddy_silent( struct groupchat *b, const char *handle ); … … 251 249 void imcb_connected( struct im_connection *ic ) 252 250 { 253 irc_t *irc = ic->irc;254 struct chat *c;255 251 user_t *u; 256 252 … … 268 264 ic->flags |= OPT_LOGGED_IN; 269 265 270 /* Necessary to send initial presence status, even if we're not away. */ 271 imc_away_send_update( ic ); 272 273 /* Apparently we're connected successfully, so reset the 274 exponential backoff timer. */ 275 ic->acc->auto_reconnect_delay = 0; 276 277 for( c = irc->chatrooms; c; c = c->next ) 278 { 279 if( c->acc != ic->acc ) 280 continue; 281 282 if( set_getbool( &c->set, "auto_join" ) ) 283 chat_join( irc, c, NULL ); 284 } 266 /* Also necessary when we're not away, at least for some of the 267 protocols. */ 268 imc_set_away( ic, u->away ); 285 269 } 286 270 … … 306 290 user_t *t, *u; 307 291 account_t *a; 308 int delay;309 292 310 293 /* Nested calls might happen sometimes, this is probably the best … … 322 305 b_event_remove( ic->inpa ); 323 306 324 g_free( ic->away );325 ic->away = NULL;326 327 307 u = irc->users; 328 308 while( u ) … … 349 329 } 350 330 else if( allow_reconnect && set_getbool( &irc->set, "auto_reconnect" ) && 351 set_getbool( &a->set, "auto_reconnect" ) && 352 ( delay = account_reconnect_delay( a ) ) > 0 ) 353 { 331 set_getbool( &a->set, "auto_reconnect" ) ) 332 { 333 int delay = set_getint( &irc->set, "auto_reconnect_delay" ); 334 354 335 imcb_log( ic, "Reconnecting in %d seconds..", delay ); 355 336 a->reconnect = b_timeout_add( delay * 1000, auto_reconnect, a ); … … 371 352 /* list.c */ 372 353 373 void imcb_add_buddy( struct im_connection *ic, c har *handle,char *group )354 void imcb_add_buddy( struct im_connection *ic, const char *handle, const char *group ) 374 355 { 375 356 user_t *u; … … 445 426 } 446 427 447 void imcb_rename_buddy( struct im_connection *ic, c har *handle,char *realname )428 void imcb_rename_buddy( struct im_connection *ic, const char *handle, const char *realname ) 448 429 { 449 430 user_t *u = user_findhandle( ic, handle ); 450 char *set;451 431 452 432 if( !u || !realname ) return; … … 461 441 imcb_log( ic, "User `%s' changed name to `%s'", u->nick, u->realname ); 462 442 } 463 464 set = set_getstr( &ic->acc->set, "nick_source" ); 465 if( strcmp( set, "handle" ) != 0 ) 466 { 467 char *name = g_strdup( realname ); 468 469 if( strcmp( set, "first_name" ) == 0 ) 470 { 471 int i; 472 for( i = 0; name[i] && !isspace( name[i] ); i ++ ) {} 473 name[i] = '\0'; 474 } 475 476 imcb_buddy_nick_hint( ic, handle, name ); 477 478 g_free( name ); 479 } 480 } 481 482 void imcb_remove_buddy( struct im_connection *ic, char *handle, char *group ) 443 } 444 445 void imcb_remove_buddy( struct im_connection *ic, const char *handle, char *group ) 483 446 { 484 447 user_t *u; … … 525 488 } 526 489 527 528 struct imcb_ask_cb_data 490 /* prpl.c */ 491 492 struct show_got_added_data 529 493 { 530 494 struct im_connection *ic; … … 532 496 }; 533 497 534 static void imcb_ask_auth_cb_no( void *data ) 535 { 536 struct imcb_ask_cb_data *cbd = data; 537 538 cbd->ic->acc->prpl->auth_deny( cbd->ic, cbd->handle ); 539 540 g_free( cbd->handle ); 541 g_free( cbd ); 542 } 543 544 static void imcb_ask_auth_cb_yes( void *data ) 545 { 546 struct imcb_ask_cb_data *cbd = data; 547 548 cbd->ic->acc->prpl->auth_allow( cbd->ic, cbd->handle ); 549 550 g_free( cbd->handle ); 551 g_free( cbd ); 552 } 553 554 void imcb_ask_auth( struct im_connection *ic, const char *handle, const char *realname ) 555 { 556 struct imcb_ask_cb_data *data = g_new0( struct imcb_ask_cb_data, 1 ); 557 char *s, *realname_ = NULL; 558 559 if( realname != NULL ) 560 realname_ = g_strdup_printf( " (%s)", realname ); 561 562 s = g_strdup_printf( "The user %s%s wants to add you to his/her buddy list.", 563 handle, realname_ ?: "" ); 564 565 g_free( realname_ ); 566 567 data->ic = ic; 568 data->handle = g_strdup( handle ); 569 query_add( ic->irc, ic, s, imcb_ask_auth_cb_yes, imcb_ask_auth_cb_no, data ); 570 } 571 572 573 static void imcb_ask_add_cb_no( void *data ) 574 { 575 g_free( ((struct imcb_ask_cb_data*)data)->handle ); 498 void show_got_added_no( void *data ) 499 { 500 g_free( ((struct show_got_added_data*)data)->handle ); 576 501 g_free( data ); 577 502 } 578 503 579 static void imcb_ask_add_cb_yes( void *data ) 580 { 581 struct imcb_ask_cb_data *cbd = data; 582 583 cbd->ic->acc->prpl->add_buddy( cbd->ic, cbd->handle, NULL ); 584 585 return imcb_ask_add_cb_no( data ); 586 } 587 588 void imcb_ask_add( struct im_connection *ic, const char *handle, const char *realname ) 589 { 590 struct imcb_ask_cb_data *data = g_new0( struct imcb_ask_cb_data, 1 ); 504 void show_got_added_yes( void *data ) 505 { 506 struct show_got_added_data *sga = data; 507 508 sga->ic->acc->prpl->add_buddy( sga->ic, sga->handle, NULL ); 509 /* imcb_add_buddy( sga->ic, NULL, sga->handle, sga->handle ); */ 510 511 return show_got_added_no( data ); 512 } 513 514 void imcb_ask_add( struct im_connection *ic, char *handle, const char *realname ) 515 { 516 struct show_got_added_data *data = g_new0( struct show_got_added_data, 1 ); 591 517 char *s; 592 518 … … 599 525 data->ic = ic; 600 526 data->handle = g_strdup( handle ); 601 query_add( ic->irc, ic, s, imcb_ask_add_cb_yes, imcb_ask_add_cb_no, data );527 query_add( ic->irc, ic, s, show_got_added_yes, show_got_added_no, data ); 602 528 } 603 529 … … 702 628 } 703 629 704 void imcb_buddy_msg( struct im_connection *ic, c har *handle, char *msg, uint32_t flags, time_t sent_at )630 void imcb_buddy_msg( struct im_connection *ic, const char *handle, char *msg, uint32_t flags, time_t sent_at ) 705 631 { 706 632 irc_t *irc = ic->irc; … … 835 761 } 836 762 837 void imcb_chat_msg( struct groupchat *c, c har *who, char *msg, uint32_t flags, time_t sent_at )763 void imcb_chat_msg( struct groupchat *c, const char *who, char *msg, uint32_t flags, time_t sent_at ) 838 764 { 839 765 struct im_connection *ic = c->ic; … … 907 833 /* buddy_chat.c */ 908 834 909 void imcb_chat_add_buddy( struct groupchat *b, c har *handle )835 void imcb_chat_add_buddy( struct groupchat *b, const char *handle ) 910 836 { 911 837 user_t *u = user_findhandle( b->ic, handle ); … … 942 868 943 869 /* This function is one BIG hack... :-( EREWRITE */ 944 void imcb_chat_remove_buddy( struct groupchat *b, c har *handle,char *reason )870 void imcb_chat_remove_buddy( struct groupchat *b, const char *handle, const char *reason ) 945 871 { 946 872 user_t *u; … … 998 924 int st; 999 925 1000 if( !is_bool( value ) ) 1001 return SET_INVALID; 1002 1003 st = bool2int( value ); 926 if( ( g_strcasecmp( value, "true" ) == 0 ) || ( g_strcasecmp( value, "yes" ) == 0 ) || ( g_strcasecmp( value, "on" ) == 0 ) ) 927 st = 1; 928 else if( ( g_strcasecmp( value, "false" ) == 0 ) || ( g_strcasecmp( value, "no" ) == 0 ) || ( g_strcasecmp( value, "off" ) == 0 ) ) 929 st = 0; 930 else if( sscanf( value, "%d", &st ) != 1 ) 931 return( NULL ); 932 933 st = st != 0; 1004 934 1005 935 /* Horror.... */ … … 1045 975 } 1046 976 1047 return value;977 return( set_eval_bool( set, value ) ); 1048 978 } 1049 979 … … 1087 1017 } 1088 1018 1089 static char *imc_away_state_find( GList *gcm, char *away, char **message ); 1090 1091 int imc_away_send_update( struct im_connection *ic ) 1092 { 1093 char *away, *msg = NULL; 1094 1095 away = set_getstr( &ic->acc->set, "away" ) ? 1096 : set_getstr( &ic->irc->set, "away" ); 1097 if( away && *away ) 1098 { 1099 GList *m = ic->acc->prpl->away_states( ic ); 1100 msg = ic->acc->flags & ACC_FLAG_AWAY_MESSAGE ? away : NULL; 1101 away = imc_away_state_find( m, away, &msg ) ? : m->data; 1102 } 1103 else if( ic->acc->flags & ACC_FLAG_STATUS_MESSAGE ) 1104 { 1105 away = NULL; 1106 msg = set_getstr( &ic->acc->set, "status" ) ? 1107 : set_getstr( &ic->irc->set, "status" ); 1108 } 1109 1110 ic->acc->prpl->set_away( ic, away, msg ); 1111 1112 return 1; 1019 static char *imc_away_alias_find( GList *gcm, char *away ); 1020 1021 int imc_set_away( struct im_connection *ic, char *away ) 1022 { 1023 GList *m, *ms; 1024 char *s; 1025 1026 if( !away ) away = ""; 1027 ms = m = ic->acc->prpl->away_states( ic ); 1028 1029 while( m ) 1030 { 1031 if( *away ) 1032 { 1033 if( g_strncasecmp( m->data, away, strlen( m->data ) ) == 0 ) 1034 break; 1035 } 1036 else 1037 { 1038 if( g_strcasecmp( m->data, "Available" ) == 0 ) 1039 break; 1040 if( g_strcasecmp( m->data, "Online" ) == 0 ) 1041 break; 1042 } 1043 m = m->next; 1044 } 1045 1046 if( m ) 1047 { 1048 ic->acc->prpl->set_away( ic, m->data, *away ? away : NULL ); 1049 } 1050 else 1051 { 1052 s = imc_away_alias_find( ms, away ); 1053 if( s ) 1054 { 1055 ic->acc->prpl->set_away( ic, s, away ); 1056 if( set_getbool( &ic->irc->set, "debug" ) ) 1057 imcb_log( ic, "Setting away state to %s", s ); 1058 } 1059 else 1060 ic->acc->prpl->set_away( ic, GAIM_AWAY_CUSTOM, away ); 1061 } 1062 1063 return( 1 ); 1113 1064 } 1114 1065 … … 1125 1076 }; 1126 1077 1127 static char *imc_away_ state_find( GList *gcm, char *away, char **message)1078 static char *imc_away_alias_find( GList *gcm, char *away ) 1128 1079 { 1129 1080 GList *m; 1130 1081 int i, j; 1131 1082 1132 for( m = gcm; m; m = m->next )1133 if( g_strncasecmp( m->data, away, strlen( m->data ) ) == 0 )1134 {1135 /* At least the Yahoo! module works better if message1136 contains no data unless it adds something to what1137 we have in state already. */1138 if( strlen( m->data ) == strlen( away ) )1139 *message = NULL;1140 1141 return m->data;1142 }1143 1144 1083 for( i = 0; *imc_away_alias_list[i]; i ++ ) 1145 1084 { 1146 int keep_message;1147 1148 1085 for( j = 0; imc_away_alias_list[i][j]; j ++ ) 1149 1086 if( g_strncasecmp( away, imc_away_alias_list[i][j], strlen( imc_away_alias_list[i][j] ) ) == 0 ) 1150 {1151 keep_message = strlen( away ) != strlen( imc_away_alias_list[i][j] );1152 1087 break; 1153 }1154 1088 1155 1089 if( !imc_away_alias_list[i][j] ) /* If we reach the end, this row */ … … 1159 1093 for( j = 0; imc_away_alias_list[i][j]; j ++ ) 1160 1094 { 1161 for( m = gcm; m; m = m->next ) 1095 m = gcm; 1096 while( m ) 1097 { 1162 1098 if( g_strcasecmp( imc_away_alias_list[i][j], m->data ) == 0 ) 1163 { 1164 if( !keep_message ) 1165 *message = NULL; 1166 1167 return imc_away_alias_list[i][j]; 1168 } 1169 } 1170 1171 /* No need to look further, apparently this state doesn't 1172 have any good alias for this protocol. */ 1173 break; 1174 } 1175 1176 return NULL; 1099 return( imc_away_alias_list[i][j] ); 1100 m = m->next; 1101 } 1102 } 1103 } 1104 1105 return( NULL ); 1177 1106 } 1178 1107
Note: See TracChangeset
for help on using the changeset viewer.