Changes in protocols/nogaim.c [c6ca3ee:286b28e]
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
protocols/nogaim.c
rc6ca3ee r286b28e 2 2 * BitlBee -- An IRC to other IM-networks gateway * 3 3 * * 4 * Copyright 2002-20 06Wilmer van der Gaast and others *4 * Copyright 2002-2010 Wilmer van der Gaast and others * 5 5 \********************************************************************/ 6 6 … … 33 33 34 34 #define BITLBEE_CORE 35 #include <ctype.h> 36 35 37 #include "nogaim.h" 36 #include <ctype.h>38 #include "chat.h" 37 39 38 40 static int remove_chat_buddy_silent( struct groupchat *b, const char *handle ); … … 249 251 void imcb_connected( struct im_connection *ic ) 250 252 { 253 irc_t *irc = ic->irc; 254 struct chat *c; 251 255 user_t *u; 252 256 … … 264 268 ic->flags |= OPT_LOGGED_IN; 265 269 266 /* Also necessary when we're not away, at least for some of the 267 protocols. */ 268 imc_set_away( ic, u->away ); 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 } 269 285 } 270 286 … … 290 306 user_t *t, *u; 291 307 account_t *a; 308 int delay; 292 309 293 310 /* Nested calls might happen sometimes, this is probably the best … … 305 322 b_event_remove( ic->inpa ); 306 323 324 g_free( ic->away ); 325 ic->away = NULL; 326 307 327 u = irc->users; 308 328 while( u ) … … 329 349 } 330 350 else if( allow_reconnect && set_getbool( &irc->set, "auto_reconnect" ) && 331 set_getbool( &a->set, "auto_reconnect" ) ) 332 { 333 int delay = set_getint( &irc->set, "auto_reconnect_delay" ); 334 351 set_getbool( &a->set, "auto_reconnect" ) && 352 ( delay = account_reconnect_delay( a ) ) > 0 ) 353 { 335 354 imcb_log( ic, "Reconnecting in %d seconds..", delay ); 336 355 a->reconnect = b_timeout_add( delay * 1000, auto_reconnect, a ); … … 352 371 /* list.c */ 353 372 354 void imcb_add_buddy( struct im_connection *ic, c onst char *handle, constchar *group )373 void imcb_add_buddy( struct im_connection *ic, char *handle, char *group ) 355 374 { 356 375 user_t *u; … … 426 445 } 427 446 428 void imcb_rename_buddy( struct im_connection *ic, c onst char *handle, constchar *realname )447 void imcb_rename_buddy( struct im_connection *ic, char *handle, char *realname ) 429 448 { 430 449 user_t *u = user_findhandle( ic, handle ); 450 char *set; 431 451 432 452 if( !u || !realname ) return; … … 441 461 imcb_log( ic, "User `%s' changed name to `%s'", u->nick, u->realname ); 442 462 } 443 } 444 445 void imcb_remove_buddy( struct im_connection *ic, const char *handle, char *group ) 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 ) 446 483 { 447 484 user_t *u; … … 488 525 } 489 526 490 /* prpl.c */ 491 492 struct show_got_added_data 527 528 struct imcb_ask_cb_data 493 529 { 494 530 struct im_connection *ic; … … 496 532 }; 497 533 498 void show_got_added_no( void *data ) 499 { 500 g_free( ((struct show_got_added_data*)data)->handle ); 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 ); 501 576 g_free( data ); 502 577 } 503 578 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 ); 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 ); 517 591 char *s; 518 592 … … 525 599 data->ic = ic; 526 600 data->handle = g_strdup( handle ); 527 query_add( ic->irc, ic, s, show_got_added_yes, show_got_added_no, data );601 query_add( ic->irc, ic, s, imcb_ask_add_cb_yes, imcb_ask_add_cb_no, data ); 528 602 } 529 603 … … 628 702 } 629 703 630 void imcb_buddy_msg( struct im_connection *ic, c onst char *handle, char *msg, uint32_t flags, time_t sent_at )704 void imcb_buddy_msg( struct im_connection *ic, char *handle, char *msg, uint32_t flags, time_t sent_at ) 631 705 { 632 706 irc_t *irc = ic->irc; … … 761 835 } 762 836 763 void imcb_chat_msg( struct groupchat *c, c onst char *who, char *msg, uint32_t flags, time_t sent_at )837 void imcb_chat_msg( struct groupchat *c, char *who, char *msg, uint32_t flags, time_t sent_at ) 764 838 { 765 839 struct im_connection *ic = c->ic; … … 833 907 /* buddy_chat.c */ 834 908 835 void imcb_chat_add_buddy( struct groupchat *b, c onst char *handle )909 void imcb_chat_add_buddy( struct groupchat *b, char *handle ) 836 910 { 837 911 user_t *u = user_findhandle( b->ic, handle ); … … 868 942 869 943 /* This function is one BIG hack... :-( EREWRITE */ 870 void imcb_chat_remove_buddy( struct groupchat *b, c onst char *handle, constchar *reason )944 void imcb_chat_remove_buddy( struct groupchat *b, char *handle, char *reason ) 871 945 { 872 946 user_t *u; … … 924 998 int st; 925 999 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; 1000 if( !is_bool( value ) ) 1001 return SET_INVALID; 1002 1003 st = bool2int( value ); 934 1004 935 1005 /* Horror.... */ … … 975 1045 } 976 1046 977 return ( set_eval_bool( set, value ) );1047 return value; 978 1048 } 979 1049 … … 1017 1087 } 1018 1088 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 ); 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; 1064 1113 } 1065 1114 … … 1076 1125 }; 1077 1126 1078 static char *imc_away_ alias_find( GList *gcm, char *away)1127 static char *imc_away_state_find( GList *gcm, char *away, char **message ) 1079 1128 { 1080 1129 GList *m; 1081 1130 int i, j; 1082 1131 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 message 1136 contains no data unless it adds something to what 1137 we have in state already. */ 1138 if( strlen( m->data ) == strlen( away ) ) 1139 *message = NULL; 1140 1141 return m->data; 1142 } 1143 1083 1144 for( i = 0; *imc_away_alias_list[i]; i ++ ) 1084 1145 { 1146 int keep_message; 1147 1085 1148 for( j = 0; imc_away_alias_list[i][j]; j ++ ) 1086 1149 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] ); 1087 1152 break; 1153 } 1088 1154 1089 1155 if( !imc_away_alias_list[i][j] ) /* If we reach the end, this row */ … … 1093 1159 for( j = 0; imc_away_alias_list[i][j]; j ++ ) 1094 1160 { 1095 m = gcm; 1096 while( m ) 1097 { 1161 for( m = gcm; m; m = m->next ) 1098 1162 if( g_strcasecmp( imc_away_alias_list[i][j], m->data ) == 0 ) 1099 return( imc_away_alias_list[i][j] ); 1100 m = m->next; 1101 } 1102 } 1103 } 1104 1105 return( NULL ); 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; 1106 1177 } 1107 1178
Note: See TracChangeset
for help on using the changeset viewer.