Changeset 9779c18 for protocols/nogaim.c
- Timestamp:
- 2006-06-03T20:20:43Z (18 years ago)
- Branches:
- master
- Children:
- 5973412
- Parents:
- a15c097 (diff), fb62f81f (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the(diff)
links above to see all the changes relative to each parent. - File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
protocols/nogaim.c
ra15c097 r9779c18 37 37 #include "nogaim.h" 38 38 #include <ctype.h> 39 #include <iconv.h>40 41 static char *proto_away_alias[8][5] =42 {43 { "Away from computer", "Away", "Extended away", NULL },44 { "NA", "N/A", "Not available", NULL },45 { "Busy", "Do not disturb", "DND", "Occupied", NULL },46 { "Be right back", "BRB", NULL },47 { "On the phone", "Phone", "On phone", NULL },48 { "Out to lunch", "Lunch", "Food", NULL },49 { "Invisible", "Hidden" },50 { NULL }51 };52 static char *proto_away_alias_find( GList *gcm, char *away );53 39 54 40 static int remove_chat_buddy_silent( struct conversation *b, char *handle ); … … 159 145 GSList *get_connections() { return connections; } 160 146 161 int proto_away( struct gaim_connection *gc, char *away )162 {163 GList *m, *ms;164 char *s;165 166 if( !away ) away = "";167 ms = m = gc->prpl->away_states( gc );168 169 while( m )170 {171 if( *away )172 {173 if( g_strncasecmp( m->data, away, strlen( m->data ) ) == 0 )174 break;175 }176 else177 {178 if( g_strcasecmp( m->data, "Available" ) == 0 )179 break;180 if( g_strcasecmp( m->data, "Online" ) == 0 )181 break;182 }183 m = m->next;184 }185 186 if( m )187 {188 gc->prpl->set_away( gc, m->data, *away ? away : NULL );189 }190 else191 {192 s = proto_away_alias_find( ms, away );193 if( s )194 {195 gc->prpl->set_away( gc, s, away );196 if( set_getint( gc->irc, "debug" ) )197 serv_got_crap( gc, "Setting away state to %s", s );198 }199 else200 gc->prpl->set_away( gc, GAIM_AWAY_CUSTOM, away );201 }202 203 g_list_free( ms );204 205 return( 1 );206 }207 208 static char *proto_away_alias_find( GList *gcm, char *away )209 {210 GList *m;211 int i, j;212 213 for( i = 0; *proto_away_alias[i]; i ++ )214 {215 for( j = 0; proto_away_alias[i][j]; j ++ )216 if( g_strncasecmp( away, proto_away_alias[i][j], strlen( proto_away_alias[i][j] ) ) == 0 )217 break;218 219 if( !proto_away_alias[i][j] ) /* If we reach the end, this row */220 continue; /* is not what we want. Next! */221 222 /* Now find an entry in this row which exists in gcm */223 for( j = 0; proto_away_alias[i][j]; j ++ )224 {225 m = gcm;226 while( m )227 {228 if( g_strcasecmp( proto_away_alias[i][j], m->data ) == 0 )229 return( proto_away_alias[i][j] );230 m = m->next;231 }232 }233 }234 235 return( NULL );236 }237 238 147 /* multi.c */ 239 148 … … 306 215 { 307 216 va_list params; 308 char text[1024], buf[1024], *acc_id; 309 char *msg; 217 char *text; 310 218 account_t *a; 311 219 312 220 va_start( params, format ); 313 g_vsnprintf( text, sizeof( text ),format, params );221 text = g_strdup_vprintf( format, params ); 314 222 va_end( params ); 315 223 316 if( g_strncasecmp( set_getstr( gc->irc, "charset" ), "none", 4 ) != 0 &&317 do_iconv( "UTF8", set_getstr( gc->irc, "charset" ), text, buf, 0, 1024 ) != -1 )318 msg = buf;319 else320 msg = text;321 322 224 if( ( g_strcasecmp( set_getstr( gc->irc, "strip_html" ), "always" ) == 0 ) || 323 225 ( ( gc->flags & OPT_CONN_HTML ) && set_getint( gc->irc, "strip_html" ) ) ) 324 strip_html( msg);226 strip_html( text ); 325 227 326 228 /* Try to find a different connection on the same protocol. */ … … 329 231 break; 330 232 331 /* If we found one, add the screenname to the acc_id. */233 /* If we found one, include the screenname in the message. */ 332 234 if( a ) 333 acc_id = g_strdup_printf( "%s(%s)", gc->prpl->name, gc->username);235 irc_usermsg( gc->irc, "%s(%s) - %s", gc->prpl->name, gc->username, text ); 334 236 else 335 acc_id = g_strdup( gc->prpl->name ); 336 337 irc_usermsg( gc->irc, "%s - %s", acc_id, msg ); 338 339 g_free( acc_id ); 237 irc_usermsg( gc->irc, "%s - %s", gc->prpl->name, text ); 238 239 g_free( text ); 340 240 } 341 241 … … 369 269 /* Also necessary when we're not away, at least for some of the 370 270 protocols. */ 371 proto_away( gc, u->away ); 372 373 if( strcmp( gc->prpl->name, "ICQ" ) == 0 ) 374 { 375 for( u = gc->irc->users; u; u = u->next ) 376 if( u->gc == gc ) 377 break; 378 379 if( u == NULL ) 380 serv_got_crap( gc, "\x02""***\x02"" BitlBee now supports ICQ server-side contact lists. " 381 "See \x02""help import_buddies\x02"" for more information." ); 382 } 271 bim_set_away( gc, u->away ); 383 272 } 384 273 … … 397 286 while( g_source_remove_by_user_data( (gpointer) a ) ); 398 287 a->reconnect = 0; 399 }400 401 void account_offline( struct gaim_connection *gc )402 {403 gc->wants_to_die = TRUE;404 signoff( gc );405 288 } 406 289 … … 412 295 413 296 serv_got_crap( gc, "Signing off.." ); 414 297 gc->flags |= OPT_LOGGING_OUT; 298 415 299 gaim_input_remove( gc->keepalive ); 416 300 gc->keepalive = 0; … … 510 394 else if( gc->user->proto_opt[0] && *gc->user->proto_opt[0] ) 511 395 { 512 u->host = g_strdup( gc->user->proto_opt[0] ); 396 char *colon; 397 398 if( ( colon = strchr( gc->user->proto_opt[0], ':' ) ) ) 399 u->host = g_strndup( gc->user->proto_opt[0], 400 colon - gc->user->proto_opt[0] ); 401 else 402 u->host = g_strdup( gc->user->proto_opt[0] ); 403 513 404 u->user = g_strdup( handle ); 514 405 … … 559 450 { 560 451 user_t *u = user_findhandle( gc, handle ); 561 char *name, buf[1024];562 452 563 453 if( !u ) return; 564 454 565 /* Convert all UTF-8 */ 566 if( g_strncasecmp( set_getstr( gc->irc, "charset" ), "none", 4 ) != 0 && 567 do_iconv( "UTF-8", set_getstr( gc->irc, "charset" ), realname, buf, 0, sizeof( buf ) ) != -1 ) 568 name = buf; 569 else 570 name = realname; 571 572 if( g_strcasecmp( u->realname, name ) != 0 ) 455 if( g_strcasecmp( u->realname, realname ) != 0 ) 573 456 { 574 457 if( u->realname != u->nick ) g_free( u->realname ); 575 458 576 u->realname = g_strdup( name );459 u->realname = g_strdup( realname ); 577 460 578 461 if( ( gc->flags & OPT_LOGGED_IN ) && set_getint( gc->irc, "display_namechanges" ) ) … … 584 467 /* prpl.c */ 585 468 586 void show_got_added( struct gaim_connection *gc, char *id, char *handle, const char *realname, const char *msg ) 587 { 588 return; 469 struct show_got_added_data 470 { 471 struct gaim_connection *gc; 472 char *handle; 473 }; 474 475 void show_got_added_no( gpointer w, struct show_got_added_data *data ) 476 { 477 g_free( data->handle ); 478 g_free( data ); 479 } 480 481 void show_got_added_yes( gpointer w, struct show_got_added_data *data ) 482 { 483 data->gc->prpl->add_buddy( data->gc, data->handle ); 484 add_buddy( data->gc, NULL, data->handle, data->handle ); 485 486 return show_got_added_no( w, data ); 487 } 488 489 void show_got_added( struct gaim_connection *gc, char *handle, const char *realname ) 490 { 491 struct show_got_added_data *data = g_new0( struct show_got_added_data, 1 ); 492 char *s; 493 494 /* TODO: Make a setting for this! */ 495 if( user_findhandle( gc, handle ) != NULL ) 496 return; 497 498 s = g_strdup_printf( "The user %s is not in your buddy list yet. Do you want to add him/her now?", handle ); 499 500 data->gc = gc; 501 data->handle = g_strdup( handle ); 502 query_add( gc->irc, gc, s, show_got_added_yes, show_got_added_no, data ); 589 503 } 590 504 … … 616 530 return; 617 531 } 618 return; 532 /* Why did we have this here.... 533 return; */ 619 534 } 620 535 … … 680 595 irc_t *irc = gc->irc; 681 596 user_t *u; 682 char buf[8192];683 597 684 598 u = user_findhandle( gc, handle ); … … 722 636 strip_html( msg ); 723 637 724 if( g_strncasecmp( set_getstr( irc, "charset" ), "none", 4 ) != 0 &&725 do_iconv( "UTF-8", set_getstr( irc, "charset" ), msg, buf, 0, 8192 ) != -1 )726 msg = buf;727 728 638 while( strlen( msg ) > 425 ) 729 639 { … … 822 732 struct conversation *c; 823 733 user_t *u; 824 char buf[8192];825 734 826 735 /* Gaim sends own messages through this too. IRC doesn't want this, so kill them */ … … 834 743 ( ( gc->flags & OPT_CONN_HTML ) && set_getint( gc->irc, "strip_html" ) ) ) 835 744 strip_html( msg ); 836 837 if( g_strncasecmp( set_getstr( gc->irc, "charset" ), "none", 4 ) != 0 &&838 do_iconv( "UTF-8", set_getstr( gc->irc, "charset" ), msg, buf, 0, 8192 ) != -1 )839 msg = buf;840 745 841 746 if( c && u ) … … 956 861 957 862 return( 0 ); 958 }959 960 961 /* prefs.c */962 963 /* Necessary? */964 void build_block_list()965 {966 return;967 }968 969 void build_allow_list()970 {971 return;972 863 } 973 864 … … 1051 942 } 1052 943 1053 int serv_send_im( irc_t *irc, user_t *u, char *msg, int flags ) 1054 { 1055 char buf[8192]; 1056 1057 if( g_strncasecmp( set_getstr( irc, "charset" ), "none", 4 ) != 0 && 1058 do_iconv( set_getstr( irc, "charset" ), "UTF-8", msg, buf, 0, 8192 ) != -1 ) 944 945 946 947 /* The plan is to not allow straight calls to prpl functions anymore, but do 948 them all from some wrappers. We'll start to define some down here: */ 949 950 int bim_buddy_msg( struct gaim_connection *gc, char *handle, char *msg, int flags ) 951 { 952 char *buf = NULL; 953 int st; 954 955 if( ( gc->flags & OPT_CONN_HTML ) && ( g_strncasecmp( msg, "<html>", 6 ) != 0 ) ) 956 { 957 buf = escape_html( msg ); 1059 958 msg = buf; 1060 1061 if( ( u->gc->flags & OPT_CONN_HTML ) && ( g_strncasecmp( msg, "<html>", 6 ) != 0 ) ) 1062 { 1063 char *html; 1064 1065 html = escape_html( msg ); 1066 strncpy( buf, html, 8192 ); 1067 g_free( html ); 1068 959 } 960 961 st = gc->prpl->send_im( gc, handle, msg, strlen( msg ), flags ); 962 g_free( buf ); 963 964 return st; 965 } 966 967 int bim_chat_msg( struct gaim_connection *gc, int id, char *msg ) 968 { 969 char *buf = NULL; 970 int st; 971 972 if( ( gc->flags & OPT_CONN_HTML ) && ( g_strncasecmp( msg, "<html>", 6 ) != 0 ) ) 973 { 974 buf = escape_html( msg ); 1069 975 msg = buf; 1070 976 } 1071 977 1072 return( ((struct gaim_connection *)u->gc)->prpl->send_im( u->gc, u->handle, msg, strlen( msg ), flags ) ); 1073 } 1074 1075 int serv_send_chat( irc_t *irc, struct gaim_connection *gc, int id, char *msg ) 1076 { 1077 char buf[8192]; 1078 1079 if( g_strncasecmp( set_getstr( irc, "charset" ), "none", 4 ) != 0 && 1080 do_iconv( set_getstr( irc, "charset" ), "UTF-8", msg, buf, 0, 8192 ) != -1 ) 1081 msg = buf; 1082 1083 if( gc->flags & OPT_CONN_HTML) { 1084 char * html = escape_html(msg); 1085 strncpy(buf, html, 8192); 1086 g_free(html); 1087 } 1088 1089 return( gc->prpl->chat_send( gc, id, msg ) ); 1090 } 1091 1092 /* Convert from one charset to another. 1093 1094 from_cs, to_cs: Source and destination charsets 1095 src, dst: Source and destination strings 1096 size: Size if src. 0 == use strlen(). strlen() is not reliable for UNICODE/UTF16 strings though. 1097 maxbuf: Maximum number of bytes to write to dst 1098 1099 Returns the number of bytes written to maxbuf or -1 on an error. 1100 */ 1101 signed int do_iconv( char *from_cs, char *to_cs, char *src, char *dst, size_t size, size_t maxbuf ) 1102 { 1103 iconv_t cd; 1104 size_t res; 1105 size_t inbytesleft, outbytesleft; 1106 char *inbuf = src; 1107 char *outbuf = dst; 1108 1109 cd = iconv_open( to_cs, from_cs ); 1110 if( cd == (iconv_t) -1 ) 1111 return( -1 ); 1112 1113 inbytesleft = size ? size : strlen( src ); 1114 outbytesleft = maxbuf - 1; 1115 res = iconv( cd, &inbuf, &inbytesleft, &outbuf, &outbytesleft ); 1116 *outbuf = '\0'; 1117 iconv_close( cd ); 1118 1119 if( res == (size_t) -1 ) 1120 return( -1 ); 978 st = gc->prpl->chat_send( gc, id, msg ); 979 g_free( buf ); 980 981 return st; 982 } 983 984 static char *bim_away_alias_find( GList *gcm, char *away ); 985 986 int bim_set_away( struct gaim_connection *gc, char *away ) 987 { 988 GList *m, *ms; 989 char *s; 990 991 if( !away ) away = ""; 992 ms = m = gc->prpl->away_states( gc ); 993 994 while( m ) 995 { 996 if( *away ) 997 { 998 if( g_strncasecmp( m->data, away, strlen( m->data ) ) == 0 ) 999 break; 1000 } 1001 else 1002 { 1003 if( g_strcasecmp( m->data, "Available" ) == 0 ) 1004 break; 1005 if( g_strcasecmp( m->data, "Online" ) == 0 ) 1006 break; 1007 } 1008 m = m->next; 1009 } 1010 1011 if( m ) 1012 { 1013 gc->prpl->set_away( gc, m->data, *away ? away : NULL ); 1014 } 1121 1015 else 1122 return( outbuf - dst ); 1123 } 1124 1125 char *set_eval_charset( irc_t *irc, set_t *set, char *value ) 1126 { 1127 iconv_t cd; 1128 1129 if ( g_strncasecmp( value, "none", 4 ) == 0 ) 1130 return( value ); 1131 1132 cd = iconv_open( "UTF-8", value ); 1133 if( cd == (iconv_t) -1 ) 1134 return( NULL ); 1135 1136 iconv_close( cd ); 1137 return( value ); 1138 } 1016 { 1017 s = bim_away_alias_find( ms, away ); 1018 if( s ) 1019 { 1020 gc->prpl->set_away( gc, s, away ); 1021 if( set_getint( gc->irc, "debug" ) ) 1022 serv_got_crap( gc, "Setting away state to %s", s ); 1023 } 1024 else 1025 gc->prpl->set_away( gc, GAIM_AWAY_CUSTOM, away ); 1026 } 1027 1028 g_list_free( ms ); 1029 1030 return( 1 ); 1031 } 1032 1033 static char *bim_away_alias_list[8][5] = 1034 { 1035 { "Away from computer", "Away", "Extended away", NULL }, 1036 { "NA", "N/A", "Not available", NULL }, 1037 { "Busy", "Do not disturb", "DND", "Occupied", NULL }, 1038 { "Be right back", "BRB", NULL }, 1039 { "On the phone", "Phone", "On phone", NULL }, 1040 { "Out to lunch", "Lunch", "Food", NULL }, 1041 { "Invisible", "Hidden" }, 1042 { NULL } 1043 }; 1044 1045 static char *bim_away_alias_find( GList *gcm, char *away ) 1046 { 1047 GList *m; 1048 int i, j; 1049 1050 for( i = 0; *bim_away_alias_list[i]; i ++ ) 1051 { 1052 for( j = 0; bim_away_alias_list[i][j]; j ++ ) 1053 if( g_strncasecmp( away, bim_away_alias_list[i][j], strlen( bim_away_alias_list[i][j] ) ) == 0 ) 1054 break; 1055 1056 if( !bim_away_alias_list[i][j] ) /* If we reach the end, this row */ 1057 continue; /* is not what we want. Next! */ 1058 1059 /* Now find an entry in this row which exists in gcm */ 1060 for( j = 0; bim_away_alias_list[i][j]; j ++ ) 1061 { 1062 m = gcm; 1063 while( m ) 1064 { 1065 if( g_strcasecmp( bim_away_alias_list[i][j], m->data ) == 0 ) 1066 return( bim_away_alias_list[i][j] ); 1067 m = m->next; 1068 } 1069 } 1070 } 1071 1072 return( NULL ); 1073 } 1074 1075 void bim_add_allow( struct gaim_connection *gc, char *handle ) 1076 { 1077 if( g_slist_find_custom( gc->permit, handle, (GCompareFunc) gc->prpl->cmp_buddynames ) == NULL ) 1078 { 1079 gc->permit = g_slist_prepend( gc->permit, g_strdup( handle ) ); 1080 } 1081 1082 gc->prpl->add_permit( gc, handle ); 1083 } 1084 1085 void bim_rem_allow( struct gaim_connection *gc, char *handle ) 1086 { 1087 GSList *l; 1088 1089 if( ( l = g_slist_find_custom( gc->permit, handle, (GCompareFunc) gc->prpl->cmp_buddynames ) ) ) 1090 { 1091 g_free( l->data ); 1092 gc->permit = g_slist_delete_link( gc->permit, l ); 1093 } 1094 1095 gc->prpl->rem_permit( gc, handle ); 1096 } 1097 1098 void bim_add_block( struct gaim_connection *gc, char *handle ) 1099 { 1100 if( g_slist_find_custom( gc->deny, handle, (GCompareFunc) gc->prpl->cmp_buddynames ) == NULL ) 1101 { 1102 gc->deny = g_slist_prepend( gc->deny, g_strdup( handle ) ); 1103 } 1104 1105 gc->prpl->add_deny( gc, handle ); 1106 } 1107 1108 void bim_rem_block( struct gaim_connection *gc, char *handle ) 1109 { 1110 GSList *l; 1111 1112 if( ( l = g_slist_find_custom( gc->deny, handle, (GCompareFunc) gc->prpl->cmp_buddynames ) ) ) 1113 { 1114 g_free( l->data ); 1115 gc->deny = g_slist_delete_link( gc->deny, l ); 1116 } 1117 1118 gc->prpl->rem_deny( gc, handle ); 1119 }
Note: See TracChangeset
for help on using the changeset viewer.