Changeset e27661d
- Timestamp:
- 2006-03-31T17:55:47Z (19 years ago)
- Branches:
- master
- Children:
- 7d31002
- Parents:
- d783e48
- Files:
-
- 1 added
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
bitlbee.h
rd783e48 re27661d 111 111 #include "query.h" 112 112 #include "sock.h" 113 #include "util.h" 113 114 114 115 typedef struct global { … … 133 134 void root_command( irc_t *irc, char *command[] ); 134 135 void bitlbee_shutdown( gpointer data ); 135 double gettime( void );136 G_MODULE_EXPORT void http_encode( char *s );137 G_MODULE_EXPORT void http_decode( char *s );138 G_MODULE_EXPORT char *strip_newlines(char *source);139 136 140 137 extern global_t global; -
irc.c
rd783e48 re27661d 346 346 void irc_process( irc_t *irc ) 347 347 { 348 char **lines, *temp, **cmd ;348 char **lines, *temp, **cmd, *cs; 349 349 int i; 350 350 … … 355 355 for( i = 0; *lines[i] != '\0'; i ++ ) 356 356 { 357 /* [WvG] Because irc_tokenize splits at every newline, the lines[] list 358 should end with an empty string. This is why this actually works. 359 Took me a while to figure out, Maurits. :-P */ 357 360 if( lines[i+1] == NULL ) 358 361 { … … 362 365 i ++; 363 366 break; 364 } 367 } 368 369 if( ( cs = set_getstr( irc, "charset" ) ) ) 370 { 371 char conv[IRC_MAX_LINE+1]; 372 373 conv[IRC_MAX_LINE] = 0; 374 if( do_iconv( cs, "UTF-8", lines[i], conv, 0, IRC_MAX_LINE - 2 ) != -1 ) 375 strcpy( lines[i], conv ); 376 } 365 377 366 378 if( ( cmd = irc_parse_line( lines[i] ) ) == NULL ) … … 388 400 } 389 401 402 /* Splits a long string into separate lines. The array is NULL-terminated and, unless the string 403 contains an incomplete line at the end, ends with an empty string. */ 390 404 char **irc_tokenize( char *buffer ) 391 405 { … … 428 442 } 429 443 444 /* Split an IRC-style line into little parts/arguments. */ 430 445 char **irc_parse_line( char *line ) 431 446 { … … 487 502 } 488 503 504 /* Converts such an array back into a command string. Mainly used for the IPC code right now. */ 489 505 char *irc_build_line( char **cmd ) 490 506 { -
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(); -
util.c
rd783e48 re27661d 39 39 #include <glib.h> 40 40 #include <time.h> 41 #include <iconv.h> 41 42 42 43 void strip_linefeed(gchar *text) … … 445 446 } 446 447 #endif 448 449 /* Convert from one charset to another. 450 451 from_cs, to_cs: Source and destination charsets 452 src, dst: Source and destination strings 453 size: Size if src. 0 == use strlen(). strlen() is not reliable for UNICODE/UTF16 strings though. 454 maxbuf: Maximum number of bytes to write to dst 455 456 Returns the number of bytes written to maxbuf or -1 on an error. 457 */ 458 signed int do_iconv( char *from_cs, char *to_cs, char *src, char *dst, size_t size, size_t maxbuf ) 459 { 460 iconv_t cd; 461 size_t res; 462 size_t inbytesleft, outbytesleft; 463 char *inbuf = src; 464 char *outbuf = dst; 465 466 cd = iconv_open( to_cs, from_cs ); 467 if( cd == (iconv_t) -1 ) 468 return( -1 ); 469 470 inbytesleft = size ? size : strlen( src ); 471 outbytesleft = maxbuf - 1; 472 res = iconv( cd, &inbuf, &inbytesleft, &outbuf, &outbytesleft ); 473 *outbuf = '\0'; 474 iconv_close( cd ); 475 476 if( res == (size_t) -1 ) 477 return( -1 ); 478 else 479 return( outbuf - dst ); 480 } 481 482 char *set_eval_charset( irc_t *irc, set_t *set, char *value ) 483 { 484 iconv_t cd; 485 486 if ( g_strncasecmp( value, "none", 4 ) == 0 ) 487 return( value ); 488 489 cd = iconv_open( "UTF-8", value ); 490 if( cd == (iconv_t) -1 ) 491 return( NULL ); 492 493 iconv_close( cd ); 494 return( value ); 495 }
Note: See TracChangeset
for help on using the changeset viewer.