Changeset 601e813 for protocols/nogaim.c
- Timestamp:
- 2006-05-24T23:04:18Z (18 years ago)
- Branches:
- master
- Children:
- 80c1e4d
- Parents:
- 46ad029 (diff), fc630f9 (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
r46ad029 r601e813 14 14 * (except for the function names). 15 15 * 16 * Copyright 2002-200 4 Wilmer van der Gaast <lintux@lintux.cx>16 * Copyright 2002-2006 Wilmer van der Gaast <wilmer@gaast.net> and others 17 17 */ 18 18 … … 37 37 #include "nogaim.h" 38 38 #include <ctype.h> 39 #include <iconv.h>40 41 static char *proto_away_alias[7][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 { NULL }50 };51 static char *proto_away_alias_find( GList *gcm, char *away );52 39 53 40 static int remove_chat_buddy_silent( struct conversation *b, char *handle ); … … 158 145 GSList *get_connections() { return connections; } 159 146 160 int proto_away( struct gaim_connection *gc, char *away )161 {162 GList *m, *ms;163 char *s;164 165 if( !away ) away = "";166 ms = m = gc->prpl->away_states( gc );167 168 while( m )169 {170 if( *away )171 {172 if( g_strncasecmp( m->data, away, strlen( m->data ) ) == 0 )173 break;174 }175 else176 {177 if( g_strcasecmp( m->data, "Available" ) == 0 )178 break;179 if( g_strcasecmp( m->data, "Online" ) == 0 )180 break;181 }182 m = m->next;183 }184 185 if( m )186 {187 gc->prpl->set_away( gc, m->data, *away ? away : NULL );188 }189 else190 {191 s = proto_away_alias_find( ms, away );192 if( s )193 {194 gc->prpl->set_away( gc, s, away );195 if( set_getint( gc->irc, "debug" ) )196 serv_got_crap( gc, "Setting away state to %s", s );197 }198 else199 gc->prpl->set_away( gc, GAIM_AWAY_CUSTOM, away );200 }201 202 g_list_free( ms );203 204 return( 1 );205 }206 207 static char *proto_away_alias_find( GList *gcm, char *away )208 {209 GList *m;210 int i, j;211 212 for( i = 0; *proto_away_alias[i]; i ++ )213 {214 for( j = 0; proto_away_alias[i][j]; j ++ )215 if( g_strncasecmp( away, proto_away_alias[i][j], strlen( proto_away_alias[i][j] ) ) == 0 )216 break;217 218 if( !proto_away_alias[i][j] ) /* If we reach the end, this row */219 continue; /* is not what we want. Next! */220 221 /* Now find an entry in this row which exists in gcm */222 for( j = 0; proto_away_alias[i][j]; j ++ )223 {224 m = gcm;225 while( m )226 {227 if( g_strcasecmp( proto_away_alias[i][j], m->data ) == 0 )228 return( proto_away_alias[i][j] );229 m = m->next;230 }231 }232 }233 234 return( NULL );235 }236 237 147 /* multi.c */ 238 148 … … 305 215 { 306 216 va_list params; 307 char text[1024], buf[1024], acc_id[33]; 308 char *msg; 217 char *text; 309 218 account_t *a; 310 219 311 220 va_start( params, format ); 312 g_vsnprintf( text, sizeof( text ),format, params );221 text = g_strdup_vprintf( format, params ); 313 222 va_end( params ); 314 223 315 if( g_strncasecmp( set_getstr( gc->irc, "charset" ), "none", 4 ) != 0 &&316 do_iconv( "UTF8", set_getstr( gc->irc, "charset" ), text, buf, 0, 1024 ) != -1 )317 msg = buf;318 else319 msg = text;320 321 224 if( ( g_strcasecmp( set_getstr( gc->irc, "strip_html" ), "always" ) == 0 ) || 322 225 ( ( gc->flags & OPT_CONN_HTML ) && set_getint( gc->irc, "strip_html" ) ) ) 323 strip_html( msg);226 strip_html( text ); 324 227 325 228 /* Try to find a different connection on the same protocol. */ … … 328 231 break; 329 232 330 /* If we found one, add the screenname to the acc_id. */233 /* If we found one, include the screenname in the message. */ 331 234 if( a ) 332 g_snprintf( acc_id, 32, "%s(%s)", gc->prpl->name, gc->username);235 irc_usermsg( gc->irc, "%s(%s) - %s", gc->prpl->name, gc->username, text ); 333 236 else 334 g_snprintf( acc_id, 32, "%s", gc->prpl->name);335 336 irc_usermsg( gc->irc, "%s - %s", acc_id, msg);237 irc_usermsg( gc->irc, "%s - %s", gc->prpl->name, text ); 238 239 g_free( text ); 337 240 } 338 241 … … 352 255 353 256 /* MSN servers sometimes redirect you to a different server and do 354 the whole login sequence again, so subsequentcalls to this257 the whole login sequence again, so these "late" calls to this 355 258 function should be handled correctly. (IOW, ignored) */ 356 259 if( gc->flags & OPT_LOGGED_IN ) … … 364 267 gc->flags |= OPT_LOGGED_IN; 365 268 366 if( u && u->away ) proto_away( gc, u->away ); 367 368 if( !strcmp(gc->prpl->name, "icq") ) 369 { 370 for( u = gc->irc->users; u; u = u->next ) 371 if( u->gc == gc ) 372 break; 373 374 if( u == NULL ) 375 serv_got_crap( gc, "\x02""***\x02"" BitlBee now supports ICQ server-side contact lists. " 376 "See \x02""help import_buddies\x02"" for more information." ); 377 } 269 /* Also necessary when we're not away, at least for some of the 270 protocols. */ 271 bim_set_away( gc, u->away ); 378 272 } 379 273 … … 392 286 while( g_source_remove_by_user_data( (gpointer) a ) ); 393 287 a->reconnect = 0; 394 }395 396 void account_offline( struct gaim_connection *gc )397 {398 gc->wants_to_die = TRUE;399 signoff( gc );400 288 } 401 289 … … 470 358 /* list.c */ 471 359 472 int bud_list_cache_exists( struct gaim_connection *gc )473 {474 return( 0 );475 }476 477 void do_import( struct gaim_connection *gc, void *null )478 {479 return;480 }481 482 360 void add_buddy( struct gaim_connection *gc, char *group, char *handle, char *realname ) 483 361 { … … 515 393 else if( gc->user->proto_opt[0] && *gc->user->proto_opt[0] ) 516 394 { 517 u->host = g_strdup( gc->user->proto_opt[0] ); 395 char *colon; 396 397 if( ( colon = strchr( gc->user->proto_opt[0], ':' ) ) ) 398 u->host = g_strndup( gc->user->proto_opt[0], 399 colon - gc->user->proto_opt[0] ); 400 else 401 u->host = g_strdup( gc->user->proto_opt[0] ); 402 518 403 u->user = g_strdup( handle ); 519 404 … … 531 416 u->gc = gc; 532 417 u->handle = g_strdup( handle ); 418 if( group ) u->group = g_strdup( group ); 533 419 u->send_handler = buddy_send_handler; 534 420 u->last_typing_notice = 0; … … 554 440 } 555 441 556 void do_export( struct gaim_connection *gc )557 {558 return;559 }560 561 442 void signoff_blocked( struct gaim_connection *gc ) 562 443 { … … 568 449 { 569 450 user_t *u = user_findhandle( gc, handle ); 570 char *name, buf[1024];571 451 572 452 if( !u ) return; 573 453 574 /* Convert all UTF-8 */ 575 if( g_strncasecmp( set_getstr( gc->irc, "charset" ), "none", 4 ) != 0 && 576 do_iconv( "UTF-8", set_getstr( gc->irc, "charset" ), realname, buf, 0, sizeof( buf ) ) != -1 ) 577 name = buf; 578 else 579 name = realname; 580 581 if( g_strcasecmp( u->realname, name ) != 0 ) 454 if( g_strcasecmp( u->realname, realname ) != 0 ) 582 455 { 583 456 if( u->realname != u->nick ) g_free( u->realname ); 584 457 585 u->realname = g_strdup( name );458 u->realname = g_strdup( realname ); 586 459 587 460 if( ( gc->flags & OPT_LOGGED_IN ) && set_getint( gc->irc, "display_namechanges" ) ) … … 593 466 /* prpl.c */ 594 467 595 void show_got_added( struct gaim_connection *gc, char *id, char *handle, const char *realname, const char *msg ) 596 { 597 return; 468 struct show_got_added_data 469 { 470 struct gaim_connection *gc; 471 char *handle; 472 }; 473 474 void show_got_added_no( gpointer w, struct show_got_added_data *data ) 475 { 476 g_free( data->handle ); 477 g_free( data ); 478 } 479 480 void show_got_added_yes( gpointer w, struct show_got_added_data *data ) 481 { 482 data->gc->prpl->add_buddy( data->gc, data->handle ); 483 add_buddy( data->gc, NULL, data->handle, data->handle ); 484 485 return show_got_added_no( w, data ); 486 } 487 488 void show_got_added( struct gaim_connection *gc, char *handle, const char *realname ) 489 { 490 struct show_got_added_data *data = g_new0( struct show_got_added_data, 1 ); 491 char *s; 492 493 /* TODO: Make a setting for this! */ 494 if( user_findhandle( gc, handle ) != NULL ) 495 return; 496 497 s = g_strdup_printf( "The user %s is not in your buddy list yet. Do you want to add him/her now?", handle ); 498 499 data->gc = gc; 500 data->handle = g_strdup( handle ); 501 query_add( gc->irc, gc, s, show_got_added_yes, show_got_added_no, data ); 598 502 } 599 503 … … 625 529 return; 626 530 } 627 return; 531 /* Why did we have this here.... 532 return; */ 628 533 } 629 534 … … 689 594 irc_t *irc = gc->irc; 690 595 user_t *u; 691 char buf[8192];692 596 693 597 u = user_findhandle( gc, handle ); … … 731 635 strip_html( msg ); 732 636 733 if( g_strncasecmp( set_getstr( irc, "charset" ), "none", 4 ) != 0 &&734 do_iconv( "UTF-8", set_getstr( irc, "charset" ), msg, buf, 0, 8192 ) != -1 )735 msg = buf;736 737 637 while( strlen( msg ) > 425 ) 738 638 { … … 831 731 struct conversation *c; 832 732 user_t *u; 833 char buf[8192];834 733 835 734 /* Gaim sends own messages through this too. IRC doesn't want this, so kill them */ … … 843 742 ( ( gc->flags & OPT_CONN_HTML ) && set_getint( gc->irc, "strip_html" ) ) ) 844 743 strip_html( msg ); 845 846 if( g_strncasecmp( set_getstr( gc->irc, "charset" ), "none", 4 ) != 0 &&847 do_iconv( "UTF-8", set_getstr( gc->irc, "charset" ), msg, buf, 0, 8192 ) != -1 )848 msg = buf;849 744 850 745 if( c && u ) … … 884 779 } 885 780 886 void serv_finish_login( struct gaim_connection *gc )887 {888 return;889 }890 891 781 892 782 /* buddy_chat.c */ … … 970 860 971 861 return( 0 ); 972 }973 974 975 /* prefs.c */976 977 /* Necessary? */978 void build_block_list()979 {980 return;981 }982 983 void build_allow_list()984 {985 return;986 862 } 987 863 … … 1065 941 } 1066 942 1067 int serv_send_im( irc_t *irc, user_t *u, char *msg, int flags ) 1068 { 1069 char buf[8192]; 1070 1071 if( g_strncasecmp( set_getstr( irc, "charset" ), "none", 4 ) != 0 && 1072 do_iconv( set_getstr( irc, "charset" ), "UTF-8", msg, buf, 0, 8192 ) != -1 ) 943 944 945 946 /* The plan is to not allow straight calls to prpl functions anymore, but do 947 them all from some wrappers. We'll start to define some down here: */ 948 949 int bim_buddy_msg( struct gaim_connection *gc, char *handle, char *msg, int flags ) 950 { 951 char *buf = NULL; 952 int st; 953 954 if( ( gc->flags & OPT_CONN_HTML ) && ( g_strncasecmp( msg, "<html>", 6 ) != 0 ) ) 955 { 956 buf = escape_html( msg ); 1073 957 msg = buf; 1074 1075 if( ( u->gc->flags & OPT_CONN_HTML ) && ( g_strncasecmp( msg, "<html>", 6 ) != 0 ) ) 1076 { 1077 char *html; 1078 1079 html = escape_html( msg ); 1080 strncpy( buf, html, 8192 ); 1081 g_free( html ); 1082 958 } 959 960 st = gc->prpl->send_im( gc, handle, msg, strlen( msg ), flags ); 961 g_free( buf ); 962 963 return st; 964 } 965 966 int bim_chat_msg( struct gaim_connection *gc, int id, char *msg ) 967 { 968 char *buf = NULL; 969 int st; 970 971 if( ( gc->flags & OPT_CONN_HTML ) && ( g_strncasecmp( msg, "<html>", 6 ) != 0 ) ) 972 { 973 buf = escape_html( msg ); 1083 974 msg = buf; 1084 975 } 1085 976 1086 return( ((struct gaim_connection *)u->gc)->prpl->send_im( u->gc, u->handle, msg, strlen( msg ), flags ) ); 1087 } 1088 1089 int serv_send_chat( irc_t *irc, struct gaim_connection *gc, int id, char *msg ) 1090 { 1091 char buf[8192]; 1092 1093 if( g_strncasecmp( set_getstr( irc, "charset" ), "none", 4 ) != 0 && 1094 do_iconv( set_getstr( irc, "charset" ), "UTF-8", msg, buf, 0, 8192 ) != -1 ) 1095 msg = buf; 1096 1097 if( gc->flags & OPT_CONN_HTML) { 1098 char * html = escape_html(msg); 1099 strncpy(buf, html, 8192); 1100 g_free(html); 1101 } 1102 1103 return( gc->prpl->chat_send( gc, id, msg ) ); 1104 } 1105 1106 /* Convert from one charset to another. 1107 1108 from_cs, to_cs: Source and destination charsets 1109 src, dst: Source and destination strings 1110 size: Size if src. 0 == use strlen(). strlen() is not reliable for UNICODE/UTF16 strings though. 1111 maxbuf: Maximum number of bytes to write to dst 1112 1113 Returns the number of bytes written to maxbuf or -1 on an error. 1114 */ 1115 signed int do_iconv( char *from_cs, char *to_cs, char *src, char *dst, size_t size, size_t maxbuf ) 1116 { 1117 iconv_t cd; 1118 size_t res; 1119 size_t inbytesleft, outbytesleft; 1120 char *inbuf = src; 1121 char *outbuf = dst; 1122 1123 cd = iconv_open( to_cs, from_cs ); 1124 if( cd == (iconv_t) -1 ) 1125 return( -1 ); 1126 1127 inbytesleft = size ? size : strlen( src ); 1128 outbytesleft = maxbuf - 1; 1129 res = iconv( cd, &inbuf, &inbytesleft, &outbuf, &outbytesleft ); 1130 *outbuf = '\0'; 1131 iconv_close( cd ); 1132 1133 if( res == (size_t) -1 ) 1134 return( -1 ); 977 st = gc->prpl->chat_send( gc, id, msg ); 978 g_free( buf ); 979 980 return st; 981 } 982 983 static char *bim_away_alias_find( GList *gcm, char *away ); 984 985 int bim_set_away( struct gaim_connection *gc, char *away ) 986 { 987 GList *m, *ms; 988 char *s; 989 990 if( !away ) away = ""; 991 ms = m = gc->prpl->away_states( gc ); 992 993 while( m ) 994 { 995 if( *away ) 996 { 997 if( g_strncasecmp( m->data, away, strlen( m->data ) ) == 0 ) 998 break; 999 } 1000 else 1001 { 1002 if( g_strcasecmp( m->data, "Available" ) == 0 ) 1003 break; 1004 if( g_strcasecmp( m->data, "Online" ) == 0 ) 1005 break; 1006 } 1007 m = m->next; 1008 } 1009 1010 if( m ) 1011 { 1012 gc->prpl->set_away( gc, m->data, *away ? away : NULL ); 1013 } 1135 1014 else 1136 return( outbuf - dst ); 1137 } 1138 1139 char *set_eval_charset( irc_t *irc, set_t *set, char *value ) 1140 { 1141 iconv_t cd; 1142 1143 if ( g_strncasecmp( value, "none", 4 ) == 0 ) 1144 return( value ); 1145 1146 cd = iconv_open( "UTF-8", value ); 1147 if( cd == (iconv_t) -1 ) 1148 return( NULL ); 1149 1150 iconv_close( cd ); 1151 return( value ); 1152 } 1015 { 1016 s = bim_away_alias_find( ms, away ); 1017 if( s ) 1018 { 1019 gc->prpl->set_away( gc, s, away ); 1020 if( set_getint( gc->irc, "debug" ) ) 1021 serv_got_crap( gc, "Setting away state to %s", s ); 1022 } 1023 else 1024 gc->prpl->set_away( gc, GAIM_AWAY_CUSTOM, away ); 1025 } 1026 1027 g_list_free( ms ); 1028 1029 return( 1 ); 1030 } 1031 1032 static char *bim_away_alias_list[8][5] = 1033 { 1034 { "Away from computer", "Away", "Extended away", NULL }, 1035 { "NA", "N/A", "Not available", NULL }, 1036 { "Busy", "Do not disturb", "DND", "Occupied", NULL }, 1037 { "Be right back", "BRB", NULL }, 1038 { "On the phone", "Phone", "On phone", NULL }, 1039 { "Out to lunch", "Lunch", "Food", NULL }, 1040 { "Invisible", "Hidden" }, 1041 { NULL } 1042 }; 1043 1044 static char *bim_away_alias_find( GList *gcm, char *away ) 1045 { 1046 GList *m; 1047 int i, j; 1048 1049 for( i = 0; *bim_away_alias_list[i]; i ++ ) 1050 { 1051 for( j = 0; bim_away_alias_list[i][j]; j ++ ) 1052 if( g_strncasecmp( away, bim_away_alias_list[i][j], strlen( bim_away_alias_list[i][j] ) ) == 0 ) 1053 break; 1054 1055 if( !bim_away_alias_list[i][j] ) /* If we reach the end, this row */ 1056 continue; /* is not what we want. Next! */ 1057 1058 /* Now find an entry in this row which exists in gcm */ 1059 for( j = 0; bim_away_alias_list[i][j]; j ++ ) 1060 { 1061 m = gcm; 1062 while( m ) 1063 { 1064 if( g_strcasecmp( bim_away_alias_list[i][j], m->data ) == 0 ) 1065 return( bim_away_alias_list[i][j] ); 1066 m = m->next; 1067 } 1068 } 1069 } 1070 1071 return( NULL ); 1072 } 1073 1074 void bim_add_allow( struct gaim_connection *gc, char *handle ) 1075 { 1076 if( g_slist_find_custom( gc->permit, handle, (GCompareFunc) gc->prpl->cmp_buddynames ) == NULL ) 1077 { 1078 gc->permit = g_slist_prepend( gc->permit, g_strdup( handle ) ); 1079 } 1080 1081 gc->prpl->add_permit( gc, handle ); 1082 } 1083 1084 void bim_rem_allow( struct gaim_connection *gc, char *handle ) 1085 { 1086 GSList *l; 1087 1088 if( ( l = g_slist_find_custom( gc->permit, handle, (GCompareFunc) gc->prpl->cmp_buddynames ) ) ) 1089 { 1090 g_free( l->data ); 1091 gc->permit = g_slist_delete_link( gc->permit, l ); 1092 } 1093 1094 gc->prpl->rem_permit( gc, handle ); 1095 } 1096 1097 void bim_add_block( struct gaim_connection *gc, char *handle ) 1098 { 1099 if( g_slist_find_custom( gc->deny, handle, (GCompareFunc) gc->prpl->cmp_buddynames ) == NULL ) 1100 { 1101 gc->deny = g_slist_prepend( gc->deny, g_strdup( handle ) ); 1102 } 1103 1104 gc->prpl->add_deny( gc, handle ); 1105 } 1106 1107 void bim_rem_block( struct gaim_connection *gc, char *handle ) 1108 { 1109 GSList *l; 1110 1111 if( ( l = g_slist_find_custom( gc->deny, handle, (GCompareFunc) gc->prpl->cmp_buddynames ) ) ) 1112 { 1113 g_free( l->data ); 1114 gc->deny = g_slist_delete_link( gc->deny, l ); 1115 } 1116 1117 gc->prpl->rem_deny( gc, handle ); 1118 }
Note: See TracChangeset
for help on using the changeset viewer.