/********************************************************************\ * BitlBee -- An IRC to other IM-networks gateway * * * * Copyright 2002-2010 Wilmer van der Gaast and others * \********************************************************************/ /* MSN module - Notification server callbacks */ /* This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License with the Debian GNU/Linux distribution in /usr/share/common-licenses/GPL; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include #include "nogaim.h" #include "msn.h" #include "md5.h" #include "soap.h" #include "xmltree.h" static gboolean msn_ns_connected( gpointer data, gint source, b_input_condition cond ); static gboolean msn_ns_callback( gpointer data, gint source, b_input_condition cond ); static int msn_ns_command( struct msn_handler_data *handler, char **cmd, int num_parts ); static int msn_ns_message( struct msn_handler_data *handler, char *msg, int msglen, char **cmd, int num_parts ); static void msn_ns_send_adl_start( struct im_connection *ic ); static void msn_ns_send_adl( struct im_connection *ic ); int msn_ns_write( struct im_connection *ic, int fd, const char *fmt, ... ) { struct msn_data *md = ic->proto_data; va_list params; char *out; size_t len; int st; va_start( params, fmt ); out = g_strdup_vprintf( fmt, params ); va_end( params ); if( fd < 0 ) fd = md->ns->fd; if( getenv( "BITLBEE_DEBUG" ) ) fprintf( stderr, "->NS%d:%s", fd, out ); len = strlen( out ); st = write( fd, out, len ); g_free( out ); if( st != len ) { imcb_error( ic, "Short write() to main server" ); imc_logout( ic, TRUE ); return 0; } return 1; } gboolean msn_ns_connect( struct im_connection *ic, struct msn_handler_data *handler, const char *host, int port ) { if( handler->fd >= 0 ) closesocket( handler->fd ); handler->exec_command = msn_ns_command; handler->exec_message = msn_ns_message; handler->data = ic; handler->fd = proxy_connect( host, port, msn_ns_connected, handler ); if( handler->fd < 0 ) { imcb_error( ic, "Could not connect to server" ); imc_logout( ic, TRUE ); return FALSE; } return TRUE; } static gboolean msn_ns_connected( gpointer data, gint source, b_input_condition cond ) { struct msn_handler_data *handler = data; struct im_connection *ic = handler->data; struct msn_data *md; if( !g_slist_find( msn_connections, ic ) ) return FALSE; md = ic->proto_data; if( source == -1 ) { imcb_error( ic, "Could not connect to server" ); imc_logout( ic, TRUE ); return FALSE; } g_free( handler->rxq ); handler->rxlen = 0; handler->rxq = g_new0( char, 1 ); if( msn_ns_write( ic, source, "VER %d %s CVR0\r\n", ++md->trId, MSNP_VER ) ) { handler->inpa = b_input_add( handler->fd, B_EV_IO_READ, msn_ns_callback, handler ); imcb_log( ic, "Connected to server, waiting for reply" ); } return FALSE; } void msn_ns_close( struct msn_handler_data *handler ) { if( handler->fd >= 0 ) { closesocket( handler->fd ); b_event_remove( handler->inpa ); } handler->fd = handler->inpa = -1; g_free( handler->rxq ); g_free( handler->cmd_text ); handler->rxlen = 0; handler->rxq = NULL; handler->cmd_text = NULL; } static gboolean msn_ns_callback( gpointer data, gint source, b_input_condition cond ) { struct msn_handler_data *handler = data; struct im_connection *ic = handler->data; if( msn_handler( handler ) == -1 ) /* Don't do this on ret == 0, it's already done then. */ { imcb_error( ic, "Error while reading from server" ); imc_logout( ic, TRUE ); return FALSE; } else return TRUE; } static int msn_ns_command( struct msn_handler_data *handler, char **cmd, int num_parts ) { struct im_connection *ic = handler->data; struct msn_data *md = ic->proto_data; if( num_parts == 0 ) { /* Hrrm... Empty command...? Ignore? */ return( 1 ); } if( strcmp( cmd[0], "VER" ) == 0 ) { if( cmd[2] && strncmp( cmd[2], MSNP_VER, 5 ) != 0 ) { imcb_error( ic, "Unsupported protocol" ); imc_logout( ic, FALSE ); return( 0 ); } return( msn_ns_write( ic, handler->fd, "CVR %d 0x0409 mac 10.2.0 ppc macmsgs 3.5.1 macmsgs %s\r\n", ++md->trId, ic->acc->user ) ); } else if( strcmp( cmd[0], "CVR" ) == 0 ) { /* We don't give a damn about the information we just received */ return msn_ns_write( ic, handler->fd, "USR %d SSO I %s\r\n", ++md->trId, ic->acc->user ); } else if( strcmp( cmd[0], "XFR" ) == 0 ) { char *server; int port; if( num_parts >= 6 && strcmp( cmd[2], "NS" ) == 0 ) { b_event_remove( handler->inpa ); handler->inpa = -1; server = strchr( cmd[3], ':' ); if( !server ) { imcb_error( ic, "Syntax error" ); imc_logout( ic, TRUE ); return( 0 ); } *server = 0; port = atoi( server + 1 ); server = cmd[3]; imcb_log( ic, "Transferring to other server" ); return msn_ns_connect( ic, handler, server, port ); } else if( num_parts >= 6 && strcmp( cmd[2], "SB" ) == 0 ) { struct msn_switchboard *sb; server = strchr( cmd[3], ':' ); if( !server ) { imcb_error( ic, "Syntax error" ); imc_logout( ic, TRUE ); return( 0 ); } *server = 0; port = atoi( server + 1 ); server = cmd[3]; if( strcmp( cmd[4], "CKI" ) != 0 ) { imcb_error( ic, "Unknown authentication method for switchboard" ); imc_logout( ic, TRUE ); return( 0 ); } debug( "Connecting to a new switchboard with key %s", cmd[5] ); if( ( sb = msn_sb_create( ic, server, port, cmd[5], MSN_SB_NEW ) ) == NULL ) { /* Although this isn't strictly fatal for the NS connection, it's definitely something serious (we ran out of file descriptors?). */ imcb_error( ic, "Could not create new switchboard" ); imc_logout( ic, TRUE ); return( 0 ); } if( md->msgq ) { struct msn_message *m = md->msgq->data; GSList *l; sb->who = g_strdup( m->who ); /* Move all the messages to the first user in the message queue to the switchboard message queue. */ l = md->msgq; while( l ) { m = l->data; l = l->next; if( strcmp( m->who, sb->who ) == 0 ) { sb->msgq = g_slist_append( sb->msgq, m ); md->msgq = g_slist_remove( md->msgq, m ); } } } } else { imcb_error( ic, "Syntax error" ); imc_logout( ic, TRUE ); return( 0 ); } } else if( strcmp( cmd[0], "USR" ) == 0 ) { if( num_parts >= 6 && strcmp( cmd[2], "SSO" ) == 0 && strcmp( cmd[3], "S" ) == 0 ) { g_free( md->pp_policy ); md->pp_policy = g_strdup( cmd[4] ); msn_soap_passport_sso_request( ic, cmd[5] ); } else if( strcmp( cmd[2], "OK" ) == 0 ) { /* If the number after the handle is 0, the e-mail address is unverified, which means we can't change the display name. */ if( cmd[4][0] == '0' ) md->flags |= MSN_EMAIL_UNVERIFIED; imcb_log( ic, "Authenticated, getting buddy list" ); msn_soap_memlist_request( ic ); } else { imcb_error( ic, "Unknown authentication type" ); imc_logout( ic, FALSE ); return( 0 ); } } else if( strcmp( cmd[0], "MSG" ) == 0 ) { if( num_parts < 4 ) { imcb_error( ic, "Syntax error" ); imc_logout( ic, TRUE ); return( 0 ); } handler->msglen = atoi( cmd[3] ); if( handler->msglen <= 0 ) { imcb_error( ic, "Syntax error" ); imc_logout( ic, TRUE ); return( 0 ); } } else if( strcmp( cmd[0], "BLP" ) == 0 ) { msn_ns_send_adl_start( ic ); return msn_ns_finish_login( ic ); } else if( strcmp( cmd[0], "ADL" ) == 0 ) { if( num_parts >= 3 && strcmp( cmd[2], "OK" ) == 0 ) { msn_ns_send_adl( ic ); return msn_ns_finish_login( ic ); } else if( num_parts >= 3 ) { handler->msglen = atoi( cmd[2] ); } } else if( strcmp( cmd[0], "PRP" ) == 0 ) { imcb_connected( ic ); } else if( strcmp( cmd[0], "CHL" ) == 0 ) { char *resp; int st; if( num_parts < 3 ) { imcb_error( ic, "Syntax error" ); imc_logout( ic, TRUE ); return( 0 ); } resp = msn_p11_ch
<?xml version='1.0'?>
<!--
	Convert DocBook documentation to help.txt file used by bitlbee
	(C) 2004 Jelmer Vernooij
-->
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
	version="1.1">

	<xsl:output method="text" encoding="utf-8" standalone="yes"/>
	<xsl:strip-space elements="*"/>

	<xsl:template match="text()">
		<xsl:if test="starts-with(.,' ') and preceding-sibling::* and
			not(preceding-sibling::*[1]/node()[1][self::text() and contains(concat(.,'^$%'),' ^$%')])">
			<xsl:text> </xsl:text>
		</xsl:if>
	
		<xsl:value-of select="normalize-space(.)"/>
		<xsl:if test="contains(concat(.,'^$%'),' ^$%') and following-sibling::* and
			not(following-sibling::*[1]/node()[1][self::text() and starts-with(.,' ')])">
			<xsl:text> </xsl:text>
		</xsl:if>
	</xsl:template>

	<xsl:template match="para">
		<xsl:apply-templates/><xsl:text>&#10;</xsl:text>
		<xsl:if test="$extraparanewline = '1'">
			<xsl:text>&#10;</xsl:text>
		</xsl:if>
	</xsl:template>

	<xsl:template name="subject">
		<xsl:param name="id"/>
		<xsl:message><xsl:text>Processing: </xsl:text><xsl:value-of select="$id"/></xsl:message>
		<xsl:text>?</xsl:text><xsl:value-of select="$id"/><xsl:text>&#10;</xsl:text>

		<xsl:for-each select="para|variablelist|simplelist|command-list|ircexample">
			<xsl:if test="title != ''">
				<xsl:value-of select="title"/><xsl:text>&#10;</xsl:text>
			</xsl:if>
			<xsl:apply-templates select="."/>
		</xsl:for-each>
		<xsl:text>%&#10;</xsl:text>

		<xsl:for-each select="sect1|sect2">
			<xsl:call-template name="subject">
				<xsl:with-param name="id" select="@id"/>
			</xsl:call-template>
		</xsl:for-each>

		<xsl:for-each select="bitlbee-command">
			<xsl:call-template name="cmd">
				<xsl:with-param