aboutsummaryrefslogtreecommitdiffstats
path: root/protocols/msn
diff options
context:
space:
mode:
Diffstat (limited to 'protocols/msn')
-rw-r--r--protocols/msn/msn.c79
-rw-r--r--protocols/msn/msn.h7
-rw-r--r--protocols/msn/msn_util.c8
-rw-r--r--protocols/msn/ns.c49
-rw-r--r--protocols/msn/sb.c42
-rw-r--r--protocols/msn/tables.c37
6 files changed, 104 insertions, 118 deletions
diff --git a/protocols/msn/msn.c b/protocols/msn/msn.c
index 09670dfa..8930847d 100644
--- a/protocols/msn/msn.c
+++ b/protocols/msn/msn.c
@@ -116,7 +116,6 @@ static void msn_logout( struct im_connection *ic )
static int msn_buddy_msg( struct im_connection *ic, char *who, char *message, int away )
{
struct msn_switchboard *sb;
- struct msn_data *md = ic->proto_data;
if( ( sb = msn_sb_by_handle( ic, who ) ) )
{
@@ -125,47 +124,13 @@ static int msn_buddy_msg( struct im_connection *ic, char *who, char *message, in
else
{
struct msn_message *m;
- char buf[1024];
/* Create a message. We have to arrange a usable switchboard, and send the message later. */
m = g_new0( struct msn_message, 1 );
m->who = g_strdup( who );
m->text = g_strdup( message );
- /* FIXME: *CHECK* the reliability of using spare sb's! */
- if( ( sb = msn_sb_spare( ic ) ) )
- {
- debug( "Trying to use a spare switchboard to message %s", who );
-
- sb->who = g_strdup( who );
- g_snprintf( buf, sizeof( buf ), "CAL %d %s\r\n", ++sb->trId, who );
- if( msn_sb_write( sb, buf, strlen( buf ) ) )
- {
- /* He/She should join the switchboard soon, let's queue the message. */
- sb->msgq = g_slist_append( sb->msgq, m );
- return( 1 );
- }
- }
-
- debug( "Creating a new switchboard to message %s", who );
-
- /* If we reach this line, there was no spare switchboard, so let's make one. */
- g_snprintf( buf, sizeof( buf ), "XFR %d SB\r\n", ++md->trId );
- if( !msn_write( ic, buf, strlen( buf ) ) )
- {
- g_free( m->who );
- g_free( m->text );
- g_free( m );
-
- return( 0 );
- }
-
- /* And queue the message to md. We'll pick it up when the switchboard comes up. */
- md->msgq = g_slist_append( md->msgq, m );
-
- /* FIXME: If the switchboard creation fails, the message will not be sent. */
-
- return( 1 );
+ return msn_sb_write_msg( ic, m );
}
return( 0 );
@@ -177,8 +142,9 @@ static GList *msn_away_states( struct im_connection *ic )
int i;
if( l == NULL )
- for( i = 0; msn_away_state_list[i].number > -1; i ++ )
- l = g_list_append( l, (void*) msn_away_state_list[i].name );
+ for( i = 0; *msn_away_state_list[i].code; i ++ )
+ if( *msn_away_state_list[i].name )
+ l = g_list_append( l, (void*) msn_away_state_list[i].name );
return l;
}
@@ -187,17 +153,14 @@ static void msn_set_away( struct im_connection *ic, char *state, char *message )
{
char buf[1024];
struct msn_data *md = ic->proto_data;
- const struct msn_away_state *st;
- if( strcmp( state, GAIM_AWAY_CUSTOM ) == 0 )
- st = msn_away_state_by_name( "Away" );
+ if( state )
+ md->away_state = msn_away_state_by_name( state ) ? :
+ msn_away_state_list + 1;
else
- st = msn_away_state_by_name( state );
+ md->away_state = msn_away_state_list;
- if( !st ) st = msn_away_state_list;
- md->away_state = st;
-
- g_snprintf( buf, sizeof( buf ), "CHG %d %s\r\n", ++md->trId, st->code );
+ g_snprintf( buf, sizeof( buf ), "CHG %d %s\r\n", ++md->trId, md->away_state->code );
msn_write( ic, buf, strlen( buf ) );
}
@@ -255,8 +218,6 @@ static void msn_chat_leave( struct groupchat *c )
static struct groupchat *msn_chat_with( struct im_connection *ic, char *who )
{
struct msn_switchboard *sb;
- struct msn_data *md = ic->proto_data;
- char buf[1024];
if( ( sb = msn_sb_by_handle( ic, who ) ) )
{
@@ -267,31 +228,13 @@ static struct groupchat *msn_chat_with( struct im_connection *ic, char *who )
{
struct msn_message *m;
- if( ( sb = msn_sb_spare( ic ) ) )
- {
- debug( "Trying to reuse an existing switchboard as a groupchat with %s", who );
- g_snprintf( buf, sizeof( buf ), "CAL %d %s\r\n", ++sb->trId, who );
- if( msn_sb_write( sb, buf, strlen( buf ) ) )
- return msn_sb_to_chat( sb );
- }
-
- /* If the stuff above failed for some reason: */
- debug( "Creating a new switchboard to groupchat with %s", who );
-
- /* Request a new switchboard. */
- g_snprintf( buf, sizeof( buf ), "XFR %d SB\r\n", ++md->trId );
- if( !msn_write( ic, buf, strlen( buf ) ) )
- return( 0 );
-
/* Create a magic message. This is quite hackish, but who cares? :-P */
m = g_new0( struct msn_message, 1 );
m->who = g_strdup( who );
m->text = g_strdup( GROUPCHAT_SWITCHBOARD_MESSAGE );
- /* Queue the magic message and cross your fingers. */
- md->msgq = g_slist_append( md->msgq, m );
-
- /* FIXME: Can I try to return something here already? */
+ msn_sb_write_msg( ic, m );
+
return NULL;
}
diff --git a/protocols/msn/msn.h b/protocols/msn/msn.h
index 16e5ab52..84914bc3 100644
--- a/protocols/msn/msn.h
+++ b/protocols/msn/msn.h
@@ -23,6 +23,9 @@
Suite 330, Boston, MA 02111-1307 USA
*/
+#ifndef _MSN_H
+#define _MSN_H
+
/* Some hackish magicstrings to make special-purpose messages/switchboards.
*/
#define TYPING_NOTIFICATION_MESSAGE "\r\r\rBEWARE, ME R TYPINK MESSAGE!!!!\r\r\r"
@@ -93,7 +96,6 @@ struct msn_switchboard
struct msn_away_state
{
- int number;
char code[4];
char name[16];
};
@@ -175,3 +177,6 @@ int msn_sb_sendmessage( struct msn_switchboard *sb, char *text );
struct groupchat *msn_sb_to_chat( struct msn_switchboard *sb );
void msn_sb_destroy( struct msn_switchboard *sb );
gboolean msn_sb_connected( gpointer data, gint source, b_input_condition cond );
+int msn_sb_write_msg( struct im_connection *ic, struct msn_message *m );
+
+#endif //_MSN_H
diff --git a/protocols/msn/msn_util.c b/protocols/msn/msn_util.c
index 58ad22f8..668a8b8a 100644
--- a/protocols/msn/msn_util.c
+++ b/protocols/msn/msn_util.c
@@ -170,9 +170,9 @@ char *msn_findheader( char *text, char *header, int len )
while( i < len && ( text[i] == '\r' || text[i] == '\n' ) ) i ++;
/* End of headers? */
- if( strncmp( text + i - 2, "\n\n", 2 ) == 0 ||
- strncmp( text + i - 4, "\r\n\r\n", 4 ) == 0 ||
- strncmp( text + i - 2, "\r\r", 2 ) == 0 )
+ if( ( i >= 4 && strncmp( text + i - 4, "\r\n\r\n", 4 ) == 0 ) ||
+ ( i >= 2 && ( strncmp( text + i - 2, "\n\n", 2 ) == 0 ||
+ strncmp( text + i - 2, "\r\r", 2 ) == 0 ) ) )
{
break;
}
@@ -373,6 +373,6 @@ void msn_msgq_purge( struct im_connection *ic, GSList **list )
g_slist_free( *list );
*list = NULL;
- imcb_log( ic, ret->str );
+ imcb_log( ic, "%s", ret->str );
g_string_free( ret, TRUE );
}
diff --git a/protocols/msn/ns.c b/protocols/msn/ns.c
index fe48f96d..d05d8e0d 100644
--- a/protocols/msn/ns.c
+++ b/protocols/msn/ns.c
@@ -419,11 +419,12 @@ static int msn_ns_command( gpointer data, char **cmd, int num_parts )
if( !st )
{
/* FIXME: Warn/Bomb about unknown away state? */
- st = msn_away_state_list;
+ st = msn_away_state_list + 1;
}
- imcb_buddy_status( ic, cmd[3], OPT_LOGGED_IN |
- ( st->number ? OPT_AWAY : 0 ), st->name, NULL );
+ imcb_buddy_status( ic, cmd[3], OPT_LOGGED_IN |
+ ( st != msn_away_state_list ? OPT_AWAY : 0 ),
+ st->name, NULL );
}
else if( strcmp( cmd[0], "FLN" ) == 0 )
{
@@ -448,11 +449,12 @@ static int msn_ns_command( gpointer data, char **cmd, int num_parts )
if( !st )
{
/* FIXME: Warn/Bomb about unknown away state? */
- st = msn_away_state_list;
+ st = msn_away_state_list + 1;
}
- imcb_buddy_status( ic, cmd[2], OPT_LOGGED_IN |
- ( st->number ? OPT_AWAY : 0 ), st->name, NULL );
+ imcb_buddy_status( ic, cmd[2], OPT_LOGGED_IN |
+ ( st != msn_away_state_list ? OPT_AWAY : 0 ),
+ st->name, NULL );
}
else if( strcmp( cmd[0], "RNG" ) == 0 )
{
@@ -662,8 +664,8 @@ static int msn_ns_message( gpointer data, char *msg, int msglen, char **cmd, int
imcb_log( ic, "The server is going down for maintenance in %s minutes.", arg1 );
}
- if( arg1 ) g_free( arg1 );
- if( mtype ) g_free( mtype );
+ g_free( arg1 );
+ g_free( mtype );
}
else if( g_strncasecmp( ct, "text/x-msmsgsprofile", 20 ) == 0 )
{
@@ -671,25 +673,30 @@ static int msn_ns_message( gpointer data, char *msg, int msglen, char **cmd, int
}
else if( g_strncasecmp( ct, "text/x-msmsgsinitialemailnotification", 37 ) == 0 )
{
- char *inbox = msn_findheader( body, "Inbox-Unread:", blen );
- char *folders = msn_findheader( body, "Folders-Unread:", blen );
-
- if( inbox && folders && set_getbool( &ic->acc->set, "mail_notifications" ) )
+ if( set_getbool( &ic->acc->set, "mail_notifications" ) )
{
- imcb_log( ic, "INBOX contains %s new messages, plus %s messages in other folders.", inbox, folders );
+ char *inbox = msn_findheader( body, "Inbox-Unread:", blen );
+ char *folders = msn_findheader( body, "Folders-Unread:", blen );
+
+ if( inbox && folders )
+ imcb_log( ic, "INBOX contains %s new messages, plus %s messages in other folders.", inbox, folders );
+
+ g_free( inbox );
+ g_free( folders );
}
-
- g_free( inbox );
- g_free( folders );
}
else if( g_strncasecmp( ct, "text/x-msmsgsemailnotification", 30 ) == 0 )
{
- char *from = msn_findheader( body, "From-Addr:", blen );
- char *fromname = msn_findheader( body, "From:", blen );
-
- if( from && fromname && set_getbool( &ic->acc->set, "mail_notifications" ) )
+ if( set_getbool( &ic->acc->set, "mail_notifications" ) )
{
- imcb_log( ic, "Received an e-mail message from %s <%s>.", fromname, from );
+ char *from = msn_findheader( body, "From-Addr:", blen );
+ char *fromname = msn_findheader( body, "From:", blen );
+
+ if( from && fromname )
+ imcb_log( ic, "Received an e-mail message from %s <%s>.", fromname, from );
+
+ g_free( from );
+ g_free( fromname );
}
}
else if( g_strncasecmp( ct, "text/x-msmsgsactivemailnotification", 35 ) == 0 )
diff --git a/protocols/msn/sb.c b/protocols/msn/sb.c
index 18c41ef5..e9526234 100644
--- a/protocols/msn/sb.c
+++ b/protocols/msn/sb.c
@@ -47,6 +47,48 @@ int msn_sb_write( struct msn_switchboard *sb, char *s, int len )
return( 1 );
}
+int msn_sb_write_msg( struct im_connection *ic, struct msn_message *m )
+{
+ struct msn_data *md = ic->proto_data;
+ struct msn_switchboard *sb;
+ char buf[1024];
+
+ /* FIXME: *CHECK* the reliability of using spare sb's! */
+ if( ( sb = msn_sb_spare( ic ) ) )
+ {
+ debug( "Trying to use a spare switchboard to message %s", m->who );
+
+ sb->who = g_strdup( m->who );
+ g_snprintf( buf, sizeof( buf ), "CAL %d %s\r\n", ++sb->trId, m->who );
+ if( msn_sb_write( sb, buf, strlen( buf ) ) )
+ {
+ /* He/She should join the switchboard soon, let's queue the message. */
+ sb->msgq = g_slist_append( sb->msgq, m );
+ return( 1 );
+ }
+ }
+
+ debug( "Creating a new switchboard to message %s", m->who );
+
+ /* If we reach this line, there was no spare switchboard, so let's make one. */
+ g_snprintf( buf, sizeof( buf ), "XFR %d SB\r\n", ++md->trId );
+ if( !msn_write( ic, buf, strlen( buf ) ) )
+ {
+ g_free( m->who );
+ g_free( m->text );
+ g_free( m );
+
+ return( 0 );
+ }
+
+ /* And queue the message to md. We'll pick it up when the switchboard comes up. */
+ md->msgq = g_slist_append( md->msgq, m );
+
+ /* FIXME: If the switchboard creation fails, the message will not be sent. */
+
+ return( 1 );
+}
+
struct msn_switchboard *msn_sb_create( struct im_connection *ic, char *host, int port, char *key, int session )
{
struct msn_data *md = ic->proto_data;
diff --git a/protocols/msn/tables.c b/protocols/msn/tables.c
index 5ba9ea73..42b12aa9 100644
--- a/protocols/msn/tables.c
+++ b/protocols/msn/tables.c
@@ -28,48 +28,37 @@
const struct msn_away_state msn_away_state_list[] =
{
- { 0, "NLN", "Available" },
- { 1, "BSY", "Busy" },
- { 3, "IDL", "Idle" },
- { 5, "BRB", "Be Right Back" },
- { 7, "AWY", "Away" },
- { 9, "PHN", "On the Phone" },
- { 11, "LUN", "Out to Lunch" },
- { 13, "HDN", "Hidden" },
- { -1, "", "" }
+ { "NLN", "" },
+ { "AWY", "Away" },
+ { "BSY", "Busy" },
+ { "IDL", "Idle" },
+ { "BRB", "Be Right Back" },
+ { "PHN", "On the Phone" },
+ { "LUN", "Out to Lunch" },
+ { "HDN", "Hidden" },
+ { "", "" }
};
-const struct msn_away_state *msn_away_state_by_number( int number )
-{
- int i;
-
- for( i = 0; msn_away_state_list[i].number > -1; i ++ )
- if( msn_away_state_list[i].number == number )
- return( msn_away_state_list + i );
-
- return( NULL );
-}
-
const struct msn_away_state *msn_away_state_by_code( char *code )
{
int i;
- for( i = 0; msn_away_state_list[i].number > -1; i ++ )
+ for( i = 0; *msn_away_state_list[i].code; i ++ )
if( g_strcasecmp( msn_away_state_list[i].code, code ) == 0 )
return( msn_away_state_list + i );
- return( NULL );
+ return NULL;
}
const struct msn_away_state *msn_away_state_by_name( char *name )
{
int i;
- for( i = 0; msn_away_state_list[i].number > -1; i ++ )
+ for( i = 0; *msn_away_state_list[i].code; i ++ )
if( g_strcasecmp( msn_away_state_list[i].name, name ) == 0 )
return( msn_away_state_list + i );
- return( NULL );
+ return NULL;
}
const struct msn_status_code msn_status_code_list[] =