From 26fdfc5c39ebc2ca75ec3fa6e8d697a98d217edc Mon Sep 17 00:00:00 2001 From: Wilmer van der Gaast Date: Sun, 5 Mar 2006 23:34:06 +0100 Subject: Fixed ssl_openssl... :-/ --- protocols/ssl_openssl.c | 86 +++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 76 insertions(+), 10 deletions(-) (limited to 'protocols') diff --git a/protocols/ssl_openssl.c b/protocols/ssl_openssl.c index e62f95b9..b79088cc 100644 --- a/protocols/ssl_openssl.c +++ b/protocols/ssl_openssl.c @@ -4,7 +4,7 @@ * Copyright 2002-2004 Wilmer van der Gaast and others * \********************************************************************/ -/* SSL module - OpenTLS version */ +/* SSL module - OpenSSL version */ /* This program is free software; you can redistribute it and/or modify @@ -40,11 +40,13 @@ static gboolean initialized = FALSE; struct scd { - SslInputFunction func; + ssl_input_function func; gpointer data; int fd; gboolean established; + int inpa; + int lasterr; /* Necessary for SSL_get_error */ SSL *ssl; SSL_CTX *ssl_ctx; }; @@ -53,7 +55,7 @@ static void ssl_connected( gpointer data, gint source, GaimInputCondition cond ) -void *ssl_connect( char *host, int port, SslInputFunction func, gpointer data ) +void *ssl_connect( char *host, int port, ssl_input_function func, gpointer data ) { struct scd *conn = g_new0( struct scd, 1 ); SSL_METHOD *meth; @@ -92,19 +94,45 @@ void *ssl_connect( char *host, int port, SslInputFunction func, gpointer data ) return( conn ); } +static void ssl_handshake( gpointer data, gint source, GaimInputCondition cond ); + static void ssl_connected( gpointer data, gint source, GaimInputCondition cond ) { struct scd *conn = data; if( source == -1 ) - goto ssl_connected_failure; + return ssl_handshake( data, -1, cond ); + /* Make it non-blocking at least during the handshake... */ + sock_make_nonblocking( conn->fd ); SSL_set_fd( conn->ssl, conn->fd ); - if( SSL_connect( conn->ssl ) < 0 ) - goto ssl_connected_failure; + return ssl_handshake( data, source, cond ); +} + +static void ssl_handshake( gpointer data, gint source, GaimInputCondition cond ) +{ + struct scd *conn = data; + int st; + + if( conn->inpa != -1 ) + { + gaim_input_remove( conn->inpa ); + conn->inpa = -1; + } + + if( ( st = SSL_connect( conn->ssl ) ) < 0 ) + { + conn->lasterr = SSL_get_error( conn->ssl, st ); + if( conn->lasterr != SSL_ERROR_WANT_READ && conn->lasterr != SSL_ERROR_WANT_WRITE ) + goto ssl_connected_failure; + + conn->inpa = gaim_input_add( conn->fd, ssl_getdirection( conn ), ssl_handshake, data ); + return; + } conn->established = TRUE; + sock_make_blocking( conn->fd ); /* For now... */ conn->func( conn->data, conn, cond ); return; @@ -126,24 +154,57 @@ ssl_connected_failure: int ssl_read( void *conn, char *buf, int len ) { + int st; + if( !((struct scd*)conn)->established ) - return( 0 ); + { + ssl_errno = SSL_NOHANDSHAKE; + return -1; + } + + st = SSL_read( ((struct scd*)conn)->ssl, buf, len ); - return( SSL_read( ((struct scd*)conn)->ssl, buf, len ) ); + ssl_errno = SSL_OK; + if( st <= 0 ) + { + ((struct scd*)conn)->lasterr = SSL_get_error( ((struct scd*)conn)->ssl, st ); + if( ((struct scd*)conn)->lasterr == SSL_ERROR_WANT_READ || ((struct scd*)conn)->lasterr == SSL_ERROR_WANT_WRITE ) + ssl_errno = SSL_AGAIN; + } + + return st; } int ssl_write( void *conn, const char *buf, int len ) { + int st; + if( !((struct scd*)conn)->established ) - return( 0 ); + { + ssl_errno = SSL_NOHANDSHAKE; + return -1; + } + + st = SSL_write( ((struct scd*)conn)->ssl, buf, len ); - return( SSL_write( ((struct scd*)conn)->ssl, buf, len ) ); + ssl_errno = SSL_OK; + if( st <= 0 ) + { + ((struct scd*)conn)->lasterr = SSL_get_error( ((struct scd*)conn)->ssl, st ); + if( ((struct scd*)conn)->lasterr == SSL_ERROR_WANT_READ || ((struct scd*)conn)->lasterr == SSL_ERROR_WANT_WRITE ) + ssl_errno = SSL_AGAIN; + } + + return st; } void ssl_disconnect( void *conn_ ) { struct scd *conn = conn_; + if( conn->inpa != -1 ) + gaim_input_remove( conn->inpa ); + if( conn->established ) SSL_shutdown( conn->ssl ); @@ -158,3 +219,8 @@ int ssl_getfd( void *conn ) { return( ((struct scd*)conn)->fd ); } + +GaimInputCondition ssl_getdirection( void *conn ) +{ + return( ((struct scd*)conn)->lasterr == SSL_ERROR_WANT_WRITE ? GAIM_INPUT_WRITE : GAIM_INPUT_READ ); +} -- cgit v1.2.3 From 84c1a0ac4530a04113a349dbc3dd15f0e0a4e683 Mon Sep 17 00:00:00 2001 From: Wilmer van der Gaast Date: Wed, 15 Mar 2006 20:19:16 +0100 Subject: Small code cleanup, got rid of some functions in nogaim.c that we never needed. --- protocols/nogaim.c | 26 +++----------------------- protocols/oscar/oscar.c | 11 +++-------- 2 files changed, 6 insertions(+), 31 deletions(-) (limited to 'protocols') diff --git a/protocols/nogaim.c b/protocols/nogaim.c index 29ae860a..b0c357db 100644 --- a/protocols/nogaim.c +++ b/protocols/nogaim.c @@ -13,7 +13,7 @@ * from scratch for BitlBee and doesn't contain any code from Gaim anymore * (except for the function names). * - * Copyright 2002-2004 Wilmer van der Gaast + * Copyright 2002-2006 Wilmer van der Gaast and others */ /* @@ -351,7 +351,7 @@ void account_online( struct gaim_connection *gc ) user_t *u; /* MSN servers sometimes redirect you to a different server and do - the whole login sequence again, so subsequent calls to this + the whole login sequence again, so these "late" calls to this function should be handled correctly. (IOW, ignored) */ if( gc->flags & OPT_LOGGED_IN ) return; @@ -365,7 +365,7 @@ void account_online( struct gaim_connection *gc ) if( u && u->away ) proto_away( gc, u->away ); - if( !strcmp(gc->prpl->name, "icq") ) + if( strcmp( gc->prpl->name, "ICQ" ) == 0 ) { for( u = gc->irc->users; u; u = u->next ) if( u->gc == gc ) @@ -469,16 +469,6 @@ void do_ask_dialog( struct gaim_connection *gc, char *msg, void *data, void *doi /* list.c */ -int bud_list_cache_exists( struct gaim_connection *gc ) -{ - return( 0 ); -} - -void do_import( struct gaim_connection *gc, void *null ) -{ - return; -} - void add_buddy( struct gaim_connection *gc, char *group, char *handle, char *realname ) { user_t *u; @@ -553,11 +543,6 @@ struct buddy *find_buddy( struct gaim_connection *gc, char *handle ) return( b ); } -void do_export( struct gaim_connection *gc ) -{ - return; -} - void signoff_blocked( struct gaim_connection *gc ) { return; /* Make all blocked users look invisible (TODO?) */ @@ -883,11 +868,6 @@ struct conversation *serv_got_joined_chat( struct gaim_connection *gc, int id, c return( c ); } -void serv_finish_login( struct gaim_connection *gc ) -{ - return; -} - /* buddy_chat.c */ diff --git a/protocols/oscar/oscar.c b/protocols/oscar/oscar.c index 4e552bce..7f5c0fc3 100644 --- a/protocols/oscar/oscar.c +++ b/protocols/oscar/oscar.c @@ -355,7 +355,9 @@ static void oscar_login(struct aim_user *user) { if (isdigit(*user->username)) { odata->icq = TRUE; - /* this is odd but it's necessary for a proper do_import and do_export */ + /* This is odd but it's necessary for a proper do_import and do_export. + We don't do those anymore, but let's stick with it, just in case + it accidentally fixes something else too... */ gc->password[8] = 0; } else { gc->flags |= OPT_CONN_HTML; @@ -1736,11 +1738,6 @@ static int gaim_bosrights(aim_session_t *sess, aim_frame_t *fr, ...) { odata->rights.maxpermits = (guint)maxpermits; odata->rights.maxdenies = (guint)maxdenies; -// serv_finish_login(gc); - - if (bud_list_cache_exists(gc)) - do_import(gc, NULL); - aim_clientready(sess, fr->conn); aim_reqservice(sess, fr->conn, AIM_CONN_TYPE_CHATNAV); @@ -2095,8 +2092,6 @@ static int gaim_ssi_parselist(aim_session_t *sess, aim_frame_t *fr, ...) { } /* End of switch on curitem->type */ } /* End of for loop */ - if (tmp) - do_export(gc); aim_ssi_enable(sess, fr->conn); /* Request offline messages, now that the buddy list is complete. */ -- cgit v1.2.3 From 8ba511db7b32975df97247474782f82d6a3906f9 Mon Sep 17 00:00:00 2001 From: Wilmer van der Gaast Date: Fri, 17 Mar 2006 16:39:16 +0100 Subject: Fixed a very stupid bug in the "Closing switchboard with unsent messages" warning message. There's still another problem with switchboar management somewhere.. :-( --- protocols/msn/sb.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'protocols') diff --git a/protocols/msn/sb.c b/protocols/msn/sb.c index deaceba1..234be1d6 100644 --- a/protocols/msn/sb.c +++ b/protocols/msn/sb.c @@ -201,9 +201,6 @@ void msn_sb_destroy( struct msn_switchboard *sb ) debug( "Destroying switchboard: %s", sb->who ? sb->who : sb->key ? sb->key : "" ); - if( sb->key ) g_free( sb->key ); - if( sb->who ) g_free( sb->who ); - if( sb->msgq ) { struct msn_message *m; @@ -221,9 +218,12 @@ void msn_sb_destroy( struct msn_switchboard *sb ) serv_got_crap( gc, "Warning: Closing down MSN switchboard connection with " "unsent message to %s, you'll have to resend it.", - m->who ? m->who : "(unknown)" ); + sb->who ? sb->who : "(unknown)" ); } + if( sb->key ) g_free( sb->key ); + if( sb->who ) g_free( sb->who ); + if( sb->chat ) { serv_got_chat_left( gc, sb->chat->id ); -- cgit v1.2.3 From 61dddd0442c0e3c792cf90368c00681051b381a5 Mon Sep 17 00:00:00 2001 From: Wilmer van der Gaast Date: Sat, 18 Mar 2006 09:33:33 +0100 Subject: Fixed #111, Jabber away states get set correctly at connect-time now. --- protocols/jabber/jabber.c | 5 +---- protocols/msn/msn_util.c | 8 -------- protocols/nogaim.c | 4 +++- 3 files changed, 4 insertions(+), 13 deletions(-) (limited to 'protocols') diff --git a/protocols/jabber/jabber.c b/protocols/jabber/jabber.c index ba652b8a..224762ce 100644 --- a/protocols/jabber/jabber.c +++ b/protocols/jabber/jabber.c @@ -1231,9 +1231,7 @@ static void jabber_handleroster(gjconn gjc, xmlnode querynode) x = xmlnode_get_nextsibling(x); } - x = jutil_presnew(0, NULL, "Online"); - gjab_send(gjc, x); - xmlnode_free(x); + account_online(GJ_GC(gjc)); } static void jabber_handleauthresp(gjconn gjc, jpacket p) @@ -1249,7 +1247,6 @@ static void jabber_handleauthresp(gjconn gjc, jpacket p) gjab_auth(gjc); } else { gjab_reqroster(gjc); - account_online(GJ_GC(gjc)); ((struct jabber_data *)GJ_GC(gjc)->proto_data)->did_import = TRUE; } diff --git a/protocols/msn/msn_util.c b/protocols/msn/msn_util.c index e5f0b2c9..c2d840b1 100644 --- a/protocols/msn/msn_util.c +++ b/protocols/msn/msn_util.c @@ -50,14 +50,6 @@ int msn_logged_in( struct gaim_connection *gc ) account_online( gc ); - /* account_online() sets an away state if there is any, so only - execute this code if we're not away. */ - if( md->away_state == msn_away_state_list ) - { - g_snprintf( buf, sizeof( buf ), "CHG %d %s %d\r\n", ++md->trId, md->away_state->code, 0 ); - return( msn_write( gc, buf, strlen( buf ) ) ); - } - return( 0 ); } diff --git a/protocols/nogaim.c b/protocols/nogaim.c index b0c357db..24b74dc9 100644 --- a/protocols/nogaim.c +++ b/protocols/nogaim.c @@ -363,7 +363,9 @@ void account_online( struct gaim_connection *gc ) gc->keepalive = g_timeout_add( 60000, send_keepalive, gc ); gc->flags |= OPT_LOGGED_IN; - if( u && u->away ) proto_away( gc, u->away ); + /* Also necessary when we're not away, at least for some of the + protocols. */ + proto_away( gc, u->away ); if( strcmp( gc->prpl->name, "ICQ" ) == 0 ) { -- cgit v1.2.3 From 42d957194cdf8a3437d7d12e50b2c9d33f98b4d3 Mon Sep 17 00:00:00 2001 From: Wilmer van der Gaast Date: Sat, 18 Mar 2006 10:10:44 +0100 Subject: Stupid warnings. :-P --- protocols/msn/msn_util.c | 3 --- 1 file changed, 3 deletions(-) (limited to 'protocols') diff --git a/protocols/msn/msn_util.c b/protocols/msn/msn_util.c index c2d840b1..5cda9f1c 100644 --- a/protocols/msn/msn_util.c +++ b/protocols/msn/msn_util.c @@ -45,9 +45,6 @@ int msn_write( struct gaim_connection *gc, char *s, int len ) int msn_logged_in( struct gaim_connection *gc ) { - struct msn_data *md = gc->proto_data; - char buf[1024]; - account_online( gc ); return( 0 ); -- cgit v1.2.3 From bc736cfadae460de29553ec0f9bb6e452dfe407d Mon Sep 17 00:00:00 2001 From: Wilmer van der Gaast Date: Tue, 21 Mar 2006 09:00:12 +0100 Subject: Basic handling of LSG responses. --- protocols/msn/msn.h | 5 ++++- protocols/msn/ns.c | 43 ++++++++++++++++++------------------------- 2 files changed, 22 insertions(+), 26 deletions(-) (limited to 'protocols') diff --git a/protocols/msn/msn.h b/protocols/msn/msn.h index 9727c537..0cd174f2 100644 --- a/protocols/msn/msn.h +++ b/protocols/msn/msn.h @@ -65,8 +65,11 @@ struct msn_data GSList *msgq; GSList *switchboards; - int buddycount; const struct msn_away_state *away_state; + + int buddycount; + int groupcount; + char **grouplist; }; struct msn_switchboard diff --git a/protocols/msn/ns.c b/protocols/msn/ns.c index 4ced58a0..57212910 100644 --- a/protocols/msn/ns.c +++ b/protocols/msn/ns.c @@ -256,6 +256,9 @@ static int msn_ns_command( gpointer data, char **cmd, int num_parts ) if( num_parts == 5 ) { md->buddycount = atoi( cmd[3] ); + md->groupcount = atoi( cmd[4] ); + if( md->groupcount > 0 ) + md->grouplist = g_new0( char *, md->groupcount ); if( !*cmd[3] || md->buddycount == 0 ) msn_logged_in( gc ); @@ -268,18 +271,6 @@ static int msn_ns_command( gpointer data, char **cmd, int num_parts ) msn_logged_in( gc ); } } - else if( strcmp( cmd[0], "GTC" ) == 0 ) - { - } - else if( strcmp( cmd[0], "BLP" ) == 0 ) - { - } - else if( strcmp( cmd[0], "PRP" ) == 0 ) - { - } - else if( strcmp( cmd[0], "LSG" ) == 0 ) - { - } else if( strcmp( cmd[0], "LST" ) == 0 ) { int list; @@ -326,11 +317,22 @@ static int msn_ns_command( gpointer data, char **cmd, int num_parts ) } } } - else if( strcmp( cmd[0], "BPR" ) == 0 ) - { - } - else if( strcmp( cmd[0], "CHG" ) == 0 ) + else if( strcmp( cmd[0], "LSG" ) == 0 ) { + int num; + + if( num_parts != 4 ) + { + hide_login_progress_error( gc, "Syntax error" ); + signoff( gc ); + return( 0 ); + } + + http_decode( cmd[2] ); + num = atoi( cmd[1] ); + + if( num < md->groupcount ) + md->grouplist[num] = g_strdup( cmd[2] ); } else if( strcmp( cmd[0], "CHL" ) == 0 ) { @@ -356,12 +358,6 @@ static int msn_ns_command( gpointer data, char **cmd, int num_parts ) return( msn_write( gc, buf, strlen( buf ) ) ); } - else if( strcmp( cmd[0], "QRY" ) == 0 ) - { - } - else if( strcmp( cmd[0], "QNG" ) == 0 ) - { - } else if( strcmp( cmd[0], "ILN" ) == 0 ) { const struct msn_away_state *st; @@ -478,9 +474,6 @@ static int msn_ns_command( gpointer data, char **cmd, int num_parts ) msn_buddy_ask( gc, cmd[4], cmd[5] ); } } - else if( strcmp( cmd[0], "REM" ) == 0 ) - { - } else if( strcmp( cmd[0], "OUT" ) == 0 ) { if( cmd[1] && strcmp( cmd[1], "OTH" ) == 0 ) -- cgit v1.2.3 From 1ad104ab06fe3f7db1b55cc178e92e43cbda9d95 Mon Sep 17 00:00:00 2001 From: Wilmer van der Gaast Date: Tue, 21 Mar 2006 09:11:10 +0100 Subject: ns.c now passess the first group a buddy is in. --- protocols/msn/ns.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'protocols') diff --git a/protocols/msn/ns.c b/protocols/msn/ns.c index 57212910..90d525ef 100644 --- a/protocols/msn/ns.c +++ b/protocols/msn/ns.c @@ -287,7 +287,13 @@ static int msn_ns_command( gpointer data, char **cmd, int num_parts ) if( list & 1 ) /* FL */ { - add_buddy( gc, NULL, cmd[1], cmd[2] ); + char *group = NULL; + int num; + + if( cmd[4] != NULL && sscanf( cmd[4], "%d", &num ) == 1 ) + group = md->grouplist[num]; + + add_buddy( gc, group, cmd[1], cmd[2] ); } if( list & 2 ) /* AL */ { -- cgit v1.2.3 From aefa533eb48587d9f509a8dcab358061b72c7b3b Mon Sep 17 00:00:00 2001 From: Wilmer van der Gaast Date: Tue, 21 Mar 2006 09:12:22 +0100 Subject: Added a special +b usermode for easier parseability of some things. (For now blist and qlist, but more should come) --- protocols/oscar/oscar.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'protocols') diff --git a/protocols/oscar/oscar.c b/protocols/oscar/oscar.c index 7f5c0fc3..97384afb 100644 --- a/protocols/oscar/oscar.c +++ b/protocols/oscar/oscar.c @@ -1149,7 +1149,7 @@ static void gaim_icq_authask(struct gaim_connection *gc, guint32 uin, char *msg) if (strlen(msg) > 6) reason = msg + 6; - dialog_msg = g_strdup_printf("The user %u wants to add you to their buddy list for the following reason:\n\n%s", uin, reason ? reason : "No reason given."); + dialog_msg = g_strdup_printf("The user %u wants to add you to their buddy list for the following reason: %s", uin, reason ? reason : "No reason given."); data->gc = gc; data->uin = uin; do_ask_dialog(gc, dialog_msg, data, gaim_icq_authgrant, gaim_icq_authdeny); -- cgit v1.2.3 From 19a6c756bd064e8955f1a733c4e71f9c41bba36c Mon Sep 17 00:00:00 2001 From: Wilmer van der Gaast Date: Tue, 21 Mar 2006 09:19:01 +0100 Subject: Added Hidden and Invisible to the away state aliases list. --- protocols/nogaim.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'protocols') diff --git a/protocols/nogaim.c b/protocols/nogaim.c index 24b74dc9..1ea68358 100644 --- a/protocols/nogaim.c +++ b/protocols/nogaim.c @@ -38,7 +38,7 @@ #include #include -static char *proto_away_alias[7][5] = +static char *proto_away_alias[8][5] = { { "Away from computer", "Away", "Extended away", NULL }, { "NA", "N/A", "Not available", NULL }, @@ -46,6 +46,7 @@ static char *proto_away_alias[7][5] = { "Be right back", "BRB", NULL }, { "On the phone", "Phone", "On phone", NULL }, { "Out to lunch", "Lunch", "Food", NULL }, + { "Invisible", "Hidden" }, { NULL } }; static char *proto_away_alias_find( GList *gcm, char *away ); -- cgit v1.2.3 From 7b07dc6cae23180e8a06b8663ced71fb4ace7775 Mon Sep 17 00:00:00 2001 From: Wilmer van der Gaast Date: Tue, 21 Mar 2006 09:36:10 +0100 Subject: Fixed ugliness in serv_got_crap(). --- protocols/nogaim.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'protocols') diff --git a/protocols/nogaim.c b/protocols/nogaim.c index 1ea68358..f9ee8a55 100644 --- a/protocols/nogaim.c +++ b/protocols/nogaim.c @@ -305,7 +305,7 @@ void hide_login_progress_error( struct gaim_connection *gc, char *msg ) void serv_got_crap( struct gaim_connection *gc, char *format, ... ) { va_list params; - char text[1024], buf[1024], acc_id[33]; + char text[1024], buf[1024], *acc_id; char *msg; account_t *a; @@ -330,11 +330,13 @@ void serv_got_crap( struct gaim_connection *gc, char *format, ... ) /* If we found one, add the screenname to the acc_id. */ if( a ) - g_snprintf( acc_id, 32, "%s(%s)", gc->prpl->name, gc->username ); + acc_id = g_strdup_printf( "%s(%s)", gc->prpl->name, gc->username ); else - g_snprintf( acc_id, 32, "%s", gc->prpl->name ); + acc_id = g_strdup( gc->prpl->name ); irc_usermsg( gc->irc, "%s - %s", acc_id, msg ); + + g_free( acc_id ); } static gboolean send_keepalive( gpointer d ) -- cgit v1.2.3 From 9b8a38bfa9a89e9741521ac522927c80b68976cf Mon Sep 17 00:00:00 2001 From: Wilmer van der Gaast Date: Wed, 22 Mar 2006 19:22:41 +0100 Subject: Buddy group data is now stored in the user_t structure. --- protocols/nogaim.c | 1 + 1 file changed, 1 insertion(+) (limited to 'protocols') diff --git a/protocols/nogaim.c b/protocols/nogaim.c index f9ee8a55..28f76fff 100644 --- a/protocols/nogaim.c +++ b/protocols/nogaim.c @@ -525,6 +525,7 @@ void add_buddy( struct gaim_connection *gc, char *group, char *handle, char *rea u->gc = gc; u->handle = g_strdup( handle ); + if( group ) u->group = g_strdup( group ); u->send_handler = buddy_send_handler; u->last_typing_notice = 0; } -- cgit v1.2.3