Changeset e27661d for protocols


Ignore:
Timestamp:
2006-03-31T17:55:47Z (18 years ago)
Author:
Wilmer van der Gaast <wilmer@…>
Branches:
master
Children:
7d31002
Parents:
d783e48
Message:

Finished the iconv() fix. Instead of doing it every time something goes from
or to the IM-modules, it's now just done with everything that goes between
BitlBee and the user. Incomparably more efficient/reliable. Plus some more
cleanups. It compiles, can't test it for real yet. ;-)

Location:
protocols
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • protocols/nogaim.c

    rd783e48 re27661d  
    3737#include "nogaim.h"
    3838#include <ctype.h>
    39 #include <iconv.h>
    4039
    4140static char *proto_away_alias[8][5] =
     
    306305{
    307306        va_list params;
    308         char text[1024], buf[1024], *acc_id;
    309         char *msg;
     307        char *text;
    310308        account_t *a;
    311309       
    312310        va_start( params, format );
    313         g_vsnprintf( text, sizeof( text ), format, params );
     311        text = g_strdup_vprintf( format, params );
    314312        va_end( params );
    315313
    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         else
    320                 msg = text;
    321        
    322314        if( ( g_strcasecmp( set_getstr( gc->irc, "strip_html" ), "always" ) == 0 ) ||
    323315            ( ( gc->flags & OPT_CONN_HTML ) && set_getint( gc->irc, "strip_html" ) ) )
    324                 strip_html( msg );
     316                strip_html( text );
    325317       
    326318        /* Try to find a different connection on the same protocol. */
     
    329321                        break;
    330322       
    331         /* If we found one, add the screenname to the acc_id. */
     323        /* If we found one, include the screenname in the message. */
    332324        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 );
    334326        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 );
    340330}
    341331
     
    559549{
    560550        user_t *u = user_findhandle( gc, handle );
    561         char *name, buf[1024];
    562551       
    563552        if( !u ) return;
    564553       
    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 )
    573555        {
    574556                if( u->realname != u->nick ) g_free( u->realname );
    575557               
    576                 u->realname = g_strdup( name );
     558                u->realname = g_strdup( realname );
    577559               
    578560                if( ( gc->flags & OPT_LOGGED_IN ) && set_getint( gc->irc, "display_namechanges" ) )
     
    680662        irc_t *irc = gc->irc;
    681663        user_t *u;
    682         char buf[8192];
    683664       
    684665        u = user_findhandle( gc, handle );
     
    722703                strip_html( msg );
    723704
    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        
    728705        while( strlen( msg ) > 425 )
    729706        {
     
    822799        struct conversation *c;
    823800        user_t *u;
    824         char buf[8192];
    825801       
    826802        /* Gaim sends own messages through this too. IRC doesn't want this, so kill them */
     
    834810            ( ( gc->flags & OPT_CONN_HTML ) && set_getint( gc->irc, "strip_html" ) ) )
    835811                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;
    840812       
    841813        if( c && u )
     
    10531025int serv_send_im( irc_t *irc, user_t *u, char *msg, int flags )
    10541026{
    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 );
    10591033                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
     1042int 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 );
    10691050                msg = buf;
    10701051        }
    10711052       
    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  
    207207int serv_send_chat(irc_t *irc, struct gaim_connection *gc, int id, char *msg );
    208208
    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 
    212209void nogaim_init();
    213210int proto_away( struct gaim_connection *gc, char *away );
     
    258255G_MODULE_EXPORT void serv_got_chat_left( struct gaim_connection *gc, int id );
    259256
    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 
    272257/* prefs.c */
    273258G_MODULE_EXPORT void build_block_list();
Note: See TracChangeset for help on using the changeset viewer.