- Timestamp:
- 2006-03-31T17:55:47Z (19 years ago)
- Branches:
- master
- Children:
- 7d31002
- Parents:
- d783e48
- Location:
- protocols
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
protocols/nogaim.c
rd783e48 re27661d 37 37 #include "nogaim.h" 38 38 #include <ctype.h> 39 #include <iconv.h>40 39 41 40 static char *proto_away_alias[8][5] = … … 306 305 { 307 306 va_list params; 308 char text[1024], buf[1024], *acc_id; 309 char *msg; 307 char *text; 310 308 account_t *a; 311 309 312 310 va_start( params, format ); 313 g_vsnprintf( text, sizeof( text ),format, params );311 text = g_strdup_vprintf( format, params ); 314 312 va_end( params ); 315 313 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 314 if( ( g_strcasecmp( set_getstr( gc->irc, "strip_html" ), "always" ) == 0 ) || 323 315 ( ( gc->flags & OPT_CONN_HTML ) && set_getint( gc->irc, "strip_html" ) ) ) 324 strip_html( msg);316 strip_html( text ); 325 317 326 318 /* Try to find a different connection on the same protocol. */ … … 329 321 break; 330 322 331 /* If we found one, add the screenname to the acc_id. */323 /* If we found one, include the screenname in the message. */ 332 324 if( a ) 333 acc_id = g_strdup_printf( "%s(%s)", gc->prpl->name, gc->username);325 irc_usermsg( gc->irc, "%s(%s) - %s", gc->prpl->name, gc->username, text ); 334 326 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 ); 327 irc_usermsg( gc->irc, "%s - %s", gc->prpl->name, text ); 328 329 g_free( text ); 340 330 } 341 331 … … 559 549 { 560 550 user_t *u = user_findhandle( gc, handle ); 561 char *name, buf[1024];562 551 563 552 if( !u ) return; 564 553 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 ) 554 if( g_strcasecmp( u->realname, realname ) != 0 ) 573 555 { 574 556 if( u->realname != u->nick ) g_free( u->realname ); 575 557 576 u->realname = g_strdup( name );558 u->realname = g_strdup( realname ); 577 559 578 560 if( ( gc->flags & OPT_LOGGED_IN ) && set_getint( gc->irc, "display_namechanges" ) ) … … 680 662 irc_t *irc = gc->irc; 681 663 user_t *u; 682 char buf[8192];683 664 684 665 u = user_findhandle( gc, handle ); … … 722 703 strip_html( msg ); 723 704 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 705 while( strlen( msg ) > 425 ) 729 706 { … … 822 799 struct conversation *c; 823 800 user_t *u; 824 char buf[8192];825 801 826 802 /* Gaim sends own messages through this too. IRC doesn't want this, so kill them */ … … 834 810 ( ( gc->flags & OPT_CONN_HTML ) && set_getint( gc->irc, "strip_html" ) ) ) 835 811 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 812 841 813 if( c && u ) … … 1053 1025 int serv_send_im( irc_t *irc, user_t *u, char *msg, int flags ) 1054 1026 { 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 ) 1027 char *buf = NULL; 1028 int st; 1029 1030 if( ( u->gc->flags & OPT_CONN_HTML ) && ( g_strncasecmp( msg, "<html>", 6 ) != 0 ) ) 1031 { 1032 buf = escape_html( msg ); 1059 1033 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 1034 } 1035 1036 st = ((struct gaim_connection *)u->gc)->prpl->send_im( u->gc, u->handle, msg, strlen( msg ), flags ); 1037 g_free( buf ); 1038 1039 return st; 1040 } 1041 1042 int serv_send_chat( irc_t *irc, struct gaim_connection *gc, int id, char *msg ) 1043 { 1044 char *buf = NULL; 1045 int st; 1046 1047 if( ( gc->flags & OPT_CONN_HTML ) && ( g_strncasecmp( msg, "<html>", 6 ) != 0 ) ) 1048 { 1049 buf = escape_html( msg ); 1069 1050 msg = buf; 1070 1051 } 1071 1052 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 ); 1121 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 } 1053 st = gc->prpl->chat_send( gc, id, msg ); 1054 g_free( buf ); 1055 1056 return st; 1057 } -
protocols/nogaim.h
rd783e48 re27661d 207 207 int serv_send_chat(irc_t *irc, struct gaim_connection *gc, int id, char *msg ); 208 208 209 G_MODULE_EXPORT signed int do_iconv( char *from_cs, char *to_cs, char *src, char *dst, size_t size, size_t maxbuf );210 char *set_eval_charset( irc_t *irc, set_t *set, char *value );211 212 209 void nogaim_init(); 213 210 int proto_away( struct gaim_connection *gc, char *away ); … … 258 255 G_MODULE_EXPORT void serv_got_chat_left( struct gaim_connection *gc, int id ); 259 256 260 /* util.c */261 G_MODULE_EXPORT void strip_linefeed( gchar *text );262 G_MODULE_EXPORT char *add_cr( char *text );263 G_MODULE_EXPORT char *tobase64( const char *text );264 G_MODULE_EXPORT char *normalize( const char *s );265 G_MODULE_EXPORT time_t get_time( int year, int month, int day, int hour, int min, int sec );266 G_MODULE_EXPORT void strip_html( char *msg );267 G_MODULE_EXPORT char *escape_html( const char *html );268 G_MODULE_EXPORT void info_string_append(GString *str, char *newline, char *name, char *value);269 G_MODULE_EXPORT char *ipv6_wrap( char *src );270 G_MODULE_EXPORT char *ipv6_unwrap( char *src );271 272 257 /* prefs.c */ 273 258 G_MODULE_EXPORT void build_block_list();
Note: See TracChangeset
for help on using the changeset viewer.