loudmouth/tsrc/src/tstlmBlocks.cpp
changeset 10 59927b2d3b75
parent 0 d0f3a028347a
equal deleted inserted replaced
0:d0f3a028347a 10:59927b2d3b75
     1 /*
       
     2 * Copyright (c) 2002 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of the License "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:   tstlmblocks.cpp
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 
       
    21 // INCLUDE FILES
       
    22 #include <e32svr.h>
       
    23 #include <StifParser.h>
       
    24 #include <StifTestInterface.h>
       
    25 #include "tstlm.h"
       
    26 
       
    27 #include "loudmouth/loudmouth.h"
       
    28 #include <glib.h>
       
    29 #include <glib/gprintf.h>           // for g_stpcpy
       
    30 #include <string.h>
       
    31 #include <stdlib.h>
       
    32 
       
    33 #include <glowmem.h>
       
    34 
       
    35 // EXTERNAL DATA STRUCTURES
       
    36 //extern  ?external_data;
       
    37 
       
    38 // EXTERNAL FUNCTION PROTOTYPES  
       
    39 //extern ?external_function( ?arg_type,?arg_type );
       
    40 
       
    41 // CONSTANTS
       
    42 //const ?type ?constant_var = ?constant;
       
    43 
       
    44 // MACROS
       
    45 #define UNEXIST_PORT 0
       
    46 #define MYPORT 4321
       
    47 #define HAVE_OPENSSL
       
    48 #define FAKEPORT NULL
       
    49 //You need to use 5223 for ssl+sasl and 5222 for non-ssl+sasl connection
       
    50 
       
    51 #define GTALK_SSL_PORT 443
       
    52 #define SSL_INVALID_PORT 999
       
    53 
       
    54 // LOCAL CONSTANTS AND MACROS
       
    55 //const ?type ?constant_var = ?constant;
       
    56 //#define ?macro_name ?macro_def
       
    57 
       
    58 // MODULE DATA STRUCTURES
       
    59 
       
    60 typedef enum
       
    61 {
       
    62 	RC_OK,
       
    63 	RC_ERROR
       
    64 } RC_Code_t;
       
    65 
       
    66 typedef struct
       
    67 {
       
    68 	gchar *recipient;
       
    69 	gchar *message;
       
    70 } MessageData;
       
    71 
       
    72 typedef struct
       
    73 {
       
    74 	gchar      *proxy_server;
       
    75 	guint       proxy_port;	
       
    76 }ProxyData;
       
    77 
       
    78 typedef struct
       
    79 {
       
    80 	gchar       *server;
       
    81 	gchar       *username;
       
    82 	gchar       *password;		
       
    83 	gchar       *resource;
       
    84 	MessageData *msg_data;	
       
    85 #ifdef __WINSCW__
       
    86     ProxyData   *proxy_data;
       
    87 #endif
       
    88 } ConnectData;
       
    89 
       
    90 typedef struct
       
    91 {
       
    92 	ConnectData *connect_data;
       
    93 	GMainLoop   *main_loop;
       
    94 	RC_Code_t   rCode;	
       
    95 } AuthData;
       
    96 
       
    97 typedef struct
       
    98 {
       
    99     GMainLoop *main_loop;
       
   100     RC_Code_t Test_Success;	
       
   101     int count;
       
   102 } HandleData;
       
   103 
       
   104 typedef struct
       
   105 {
       
   106 	ConnectData *connect_data;
       
   107 	LmMessage* message;
       
   108 	LmMessageHandler* handler;
       
   109 	GMainLoop   *main_loop;
       
   110 	RC_Code_t   rCode;	
       
   111 } SendStreamData;
       
   112 // ======== MODULE DATA STRUCTURES =========
       
   113 typedef enum
       
   114 	{
       
   115 	XMPP_PRESENCE_TYPE_ONLINE,
       
   116 	XMPP_PRESENCE_TYPE_CHAT,
       
   117 	XMPP_PRESENCE_TYPE_AWAY,
       
   118 	XMPP_PRESENCE_TYPE_XA,
       
   119 	XMPP_PRESENCE_TYPE_DND,
       
   120 	XMPP_PRESENCE_TYPE_INVISIBLE,
       
   121 	XMPP_PRESENCE_TYPE_UNAVAILABLE
       
   122 	} JabberPresenceType;
       
   123 
       
   124 // LOCAL FUNCTION PROTOTYPES
       
   125 
       
   126 // Function to read data from the cfg file
       
   127 static RC_Code_t read_data ( ConnectData*& connect_data, 
       
   128                              CStifItemParser& aItem );
       
   129 // Function to free the allocated resources
       
   130 static void free_data ( ConnectData*& connect_data );
       
   131 
       
   132 // Callback function used in lm_connection_open
       
   133 static void connection_open_cb ( LmConnection *connection, 
       
   134                                  gboolean     success, 
       
   135                                  gpointer     data );
       
   136 
       
   137 static void wrong_input_in_open_cb ( LmConnection *connection, 
       
   138                                  gboolean     success, 
       
   139                                  gpointer     data );                                 
       
   140 
       
   141 //Callback function set in lm_connection_authenticate() call
       
   142 //from lm-connection_send
       
   143 static void connection_auth_cb ( LmConnection *connection, 
       
   144                                  gboolean     success, 
       
   145                                  gpointer     data );
       
   146 
       
   147 //Callback from lm_login_test method after auth
       
   148 static void lm_login_cb ( LmConnection * connection, 
       
   149                      gboolean  success, 
       
   150                      gpointer data );
       
   151 // Callback function called by lm_connection_open in Lm_AuthenticateL
       
   152 // Will call authenticate method from inside this callback. 
       
   153 // It uses the correct input data
       
   154 static void auth_in_connection_cb( LmConnection *connection, 
       
   155                               gboolean     success, 
       
   156                               gpointer     *data );
       
   157                                                                
       
   158 // Callback function set in auth_from_open_cb for handling 
       
   159 //wrong input data during authenticate. Written to handle negative test cases.
       
   160 static void wrong_input_auth_cb ( LmConnection *connection, 
       
   161                                  gboolean     success, 
       
   162                                  gpointer     data );
       
   163 // Callback function set by lm_connection_open call.
       
   164 //written to handle the negative test cases for authenticate
       
   165 static void auth_from_open_cb ( LmConnection *connection, 
       
   166                               gboolean     success, 
       
   167                               gpointer     *data );
       
   168 // Callback function to handle messages                              
       
   169 static LmHandlerResult handle_messages ( LmMessageHandler *handler,
       
   170                                          LmConnection     *conneciton,
       
   171                                          LmMessage        *message,
       
   172                                          gpointer         user_data );
       
   173 static LmHandlerResult handle_100_messages ( LmMessageHandler *handler,
       
   174                                          LmConnection     *conneciton,
       
   175                                          LmMessage        *message,
       
   176                                          gpointer         user_data );
       
   177 // Callback function called when connection is closed
       
   178 static void connection_close_cb ( LmConnection       *connection, 
       
   179                                   LmDisconnectReason reason,
       
   180                                   gpointer           user_data );
       
   181                                   
       
   182 // Callback function called when presence is changed
       
   183 static void jabber_presence_handler_cb ( LmConnection       *connection, 
       
   184                                   LmDisconnectReason reason,
       
   185                                   gpointer           user_data );                                  
       
   186 static void message_response_cb ( LmConnection       *connection, 
       
   187                                   LmDisconnectReason reason,
       
   188                                   gpointer           user_data );                                    
       
   189                                   
       
   190 // Get the MessageType in Type
       
   191 static void GetMessageType ( LmMessageType MessageType, gchar *Type );
       
   192 // Get MessageSubType in SubType
       
   193 static void GetMessageSubType ( LmMessageSubType MessageSubType, 
       
   194                                 gchar *SubType );
       
   195 
       
   196 // Callback function called if something goes wrong during the connection phase
       
   197 static LmSSLResponse ssl_cb ( LmSSL       *ssl, 
       
   198                               LmSSLStatus status, 
       
   199                               gpointer    user_data );
       
   200 
       
   201 #ifdef __WINSCW__
       
   202 // Set connection to connect through a proxy
       
   203 static void SetProxy ( LmConnection *connection, ProxyData *connect_data );
       
   204 #endif
       
   205 
       
   206 // Set SSL for connection
       
   207 static void SSLInit ( LmConnection *connection );
       
   208 
       
   209 // Returns the username from the JID ( username@domainname/resource )
       
   210 static gchar *get_user_name ( const gchar *jid );
       
   211 
       
   212 
       
   213 static JabberPresenceType
       
   214 jabber_presence_type_from_string ( const gchar *string );
       
   215 
       
   216 
       
   217 //?type ?function_name( ?arg_type, ?arg_type );
       
   218 
       
   219 // FORWARD DECLARATIONS
       
   220 //class ?FORWARD_CLASSNAME;
       
   221 
       
   222 // ============================= LOCAL FUNCTIONS ==============================
       
   223 
       
   224 //-----------------------------------------------------------------------------
       
   225 // function_name	: read_data
       
   226 // description     	: Reads data from the CFG file
       
   227 // Returns          : None
       
   228 //-----------------------------------------------------------------------------
       
   229 //
       
   230 static RC_Code_t
       
   231 read_data ( ConnectData*& connect_data, CStifItemParser& aItem )
       
   232     {
       
   233 	TPtrC               string;
       
   234 	TBuf8<KMaxFileName> temp;
       
   235 	MessageData         *msg_data   = NULL;
       
   236 	
       
   237 #ifdef __WINSCW__
       
   238 	ProxyData           *proxy_data = NULL;
       
   239 	TInt                proxy_port;
       
   240 #endif
       
   241 
       
   242 	
       
   243 	connect_data = g_new0 ( ConnectData, 1 );
       
   244 	if ( !connect_data )
       
   245 	    {
       
   246 		return RC_ERROR;
       
   247 	    }
       
   248 	    
       
   249 	msg_data = g_new0 ( MessageData, 1 );
       
   250 	if ( !msg_data )
       
   251 	    {
       
   252 		free_data ( connect_data );
       
   253 		return RC_ERROR;
       
   254 	    }
       
   255 	
       
   256 	connect_data->msg_data = msg_data;
       
   257 	
       
   258 #ifdef __WINSCW__
       
   259     proxy_data = g_new0 ( ProxyData, 1 );
       
   260     if ( !proxy_data ) 
       
   261     	{
       
   262     	free_data ( connect_data );
       
   263     	return RC_ERROR;
       
   264     	}
       
   265 	connect_data->proxy_data = proxy_data;
       
   266 #endif
       
   267 
       
   268 	// Read server name
       
   269 	if ( aItem.GetNextString ( string ) == KErrNone )
       
   270 	    {
       
   271 		temp.Copy ( string );
       
   272 		temp.Append ( '\0' );
       
   273 		connect_data->server = g_new0 ( gchar, temp.Length() );
       
   274 		if ( !connect_data->server )
       
   275 		    {			
       
   276 			free_data ( connect_data );
       
   277 			return RC_ERROR;
       
   278 		    }
       
   279 		g_stpcpy ( connect_data->server, ( gchar * ) temp.Ptr() ); 
       
   280 	    }
       
   281 	    
       
   282 	// Read Username
       
   283 	if ( aItem.GetNextString ( string ) == KErrNone )
       
   284 	    {
       
   285 	    temp.Copy ( string );
       
   286 	    temp.Append ( '\0' );
       
   287 	    connect_data->username = g_new0 ( gchar, temp.Length() );
       
   288 	    if ( !connect_data->username )
       
   289 	        {	    	
       
   290 	    	free_data ( connect_data );
       
   291 	    	return RC_ERROR;
       
   292 	        }
       
   293 	    g_stpcpy ( connect_data->username, ( gchar * ) temp.Ptr() );		    
       
   294 	    }
       
   295 	
       
   296 	// Read Password corresponding to Username
       
   297 	if ( aItem.GetNextString ( string ) == KErrNone )
       
   298 	    {
       
   299 	    temp.Copy ( string );
       
   300 	    temp.Append ( '\0' );
       
   301 	    connect_data->password = g_new0 ( gchar, temp.Length () );		    
       
   302 	    if ( !connect_data->password )
       
   303 	        {	    	
       
   304 	    	free_data ( connect_data );
       
   305 	    	return RC_ERROR;
       
   306 	        }
       
   307 	    g_stpcpy ( connect_data->password, ( gchar *) temp.Ptr() );
       
   308 	    }
       
   309 	
       
   310 	// Read recipient
       
   311 	if ( aItem.GetNextString ( string ) == KErrNone )
       
   312 	    {
       
   313 	    temp.Copy ( string );
       
   314 	    temp.Append ( '\0' );
       
   315 	    msg_data->recipient = g_new0 ( gchar, temp.Length() );
       
   316 	    if ( !msg_data->recipient )
       
   317 	        {
       
   318 	    	free_data ( connect_data );
       
   319 	    	return RC_ERROR;
       
   320 	        }
       
   321 	    g_stpcpy ( msg_data->recipient, ( gchar * ) temp.Ptr() );
       
   322 	    }
       
   323 	
       
   324 	// Read Message
       
   325 	if ( aItem.GetNextString ( string ) == KErrNone )
       
   326 	    {
       
   327 	    temp.Copy ( string );
       
   328 	    temp.Append ( '\0' );	    
       
   329 	    msg_data->message = g_new0 ( gchar, temp.Length() );
       
   330 	    if ( !msg_data->message )
       
   331 	        {
       
   332 	    	free_data ( connect_data );
       
   333 	    	return RC_ERROR;
       
   334 	        }
       
   335 	    g_stpcpy ( msg_data->message, ( gchar * ) temp.Ptr() );
       
   336 	    }
       
   337 	
       
   338 	// Read resource identifier
       
   339 	if ( aItem.GetNextString ( string ) == KErrNone )
       
   340 	    {
       
   341 	    temp.Copy ( string );
       
   342 	    temp.Append ( '\0' );
       
   343 	    connect_data->resource = g_new0 ( gchar, temp.Length() );
       
   344 	    if ( !connect_data->resource )
       
   345 	        {
       
   346 	    	free_data ( connect_data );
       
   347 	    	return RC_ERROR;
       
   348 	        }
       
   349 	    g_stpcpy ( connect_data->resource, ( gchar * ) temp.Ptr() );		    
       
   350 	    }
       
   351 	 
       
   352 #ifdef __WINSCW__
       
   353 	// Read proxy server and proxy port
       
   354     if ( aItem.GetNextString ( string ) == KErrNone )
       
   355     	{
       
   356     	temp.Copy ( string );
       
   357     	temp.Append ( '\0' );
       
   358     	proxy_data->proxy_server = g_new0 ( gchar, temp.Length() );
       
   359     	if ( !proxy_data->proxy_server )
       
   360     		{
       
   361     		free_data ( connect_data );
       
   362     		return RC_ERROR;
       
   363     		}
       
   364     	g_stpcpy ( proxy_data->proxy_server, ( gchar * ) temp.Ptr() );
       
   365     	}
       
   366     	
       
   367     	if ( aItem.GetNextInt ( proxy_port ) == KErrNone )
       
   368     		{
       
   369     		proxy_data->proxy_port = proxy_port;
       
   370     		}    	
       
   371 #endif 
       
   372 
       
   373 	return RC_OK;
       
   374     }
       
   375 
       
   376 
       
   377 //-----------------------------------------------------------------------------
       
   378 // function_name	: free_data
       
   379 // description     	: Deallocates all the data
       
   380 // Returns          : None
       
   381 //-----------------------------------------------------------------------------
       
   382 //
       
   383 static void
       
   384 free_data ( ConnectData*& connect_data )
       
   385     {
       
   386 	if ( connect_data )
       
   387 	    {
       
   388 		if ( connect_data->server )
       
   389 		    {
       
   390 			g_free ( connect_data->server );
       
   391 			connect_data->server = NULL;
       
   392 		    }
       
   393 		
       
   394 		if ( connect_data->username )
       
   395 		    {
       
   396 			g_free ( connect_data->username );
       
   397 			connect_data->username = NULL;
       
   398 		    }
       
   399 		
       
   400 		if ( connect_data->password )
       
   401 		    {
       
   402 			g_free ( connect_data->password );
       
   403 			connect_data->password = NULL;
       
   404 		    }
       
   405 		
       
   406 		if ( connect_data->msg_data )
       
   407 		    {
       
   408 			if ( connect_data->msg_data->recipient )
       
   409 			    {
       
   410 				g_free ( connect_data->msg_data->recipient );
       
   411 				connect_data->msg_data->recipient = NULL;
       
   412 			    }
       
   413 			if ( connect_data->msg_data->message )
       
   414 			    {
       
   415 				g_free ( connect_data->msg_data->message );
       
   416 				connect_data->msg_data->message = NULL;
       
   417 			    }
       
   418 			g_free ( connect_data->msg_data );
       
   419 			connect_data->msg_data = NULL;
       
   420 		    }		
       
   421 		
       
   422 		if ( connect_data->resource )
       
   423 		    {
       
   424 			g_free ( connect_data->resource );
       
   425 			connect_data->resource = NULL;
       
   426 		    }
       
   427 		    
       
   428 	#ifdef __WINSCW__
       
   429 	    if ( connect_data->proxy_data )
       
   430 	    	{
       
   431 	    	if ( connect_data->proxy_data->proxy_server )
       
   432 	    		{
       
   433 	    		g_free ( connect_data->proxy_data->proxy_server );
       
   434 	    		connect_data->proxy_data->proxy_server = NULL;
       
   435 	    		}
       
   436 	    	g_free ( connect_data->proxy_data );
       
   437 	    	connect_data->proxy_data = NULL;	
       
   438 	    	}
       
   439 	#endif	     
       
   440 		g_free ( connect_data );
       
   441 		connect_data = NULL;    
       
   442 	    }
       
   443     }
       
   444 
       
   445 
       
   446 //-----------------------------------------------------------------------------
       
   447 // funnction_name	: connection_open_cb
       
   448 // description		: callback function called by lm_connection_open
       
   449 // Returns			: None
       
   450 //-----------------------------------------------------------------------------
       
   451 //
       
   452 static void
       
   453 connection_open_cb ( LmConnection *connection, 
       
   454                      gboolean    success  /*success*/, 
       
   455                      gpointer data )
       
   456     {
       
   457     
       
   458     gboolean result = success ;
       
   459     GMainLoop *main_loop = ( GMainLoop * ) data;
       
   460     
       
   461 	if ( main_loop )
       
   462 	    {
       
   463 		g_main_loop_quit ( main_loop );	
       
   464 	    }		
       
   465     /* send whitespace to the server every 30 seconds */
       
   466     lm_connection_set_keep_alive_rate (connection, 30);			
       
   467     }
       
   468 
       
   469 
       
   470 //-----------------------------------------------------------------------------
       
   471 // funnction_name	: wrong_input_in_open_cb
       
   472 // description		: callback function called by lm_connection_open when the wrong
       
   473 //input like wrong server , user id etc is given
       
   474 // Returns			: None
       
   475 //-----------------------------------------------------------------------------
       
   476 //
       
   477 static void
       
   478 wrong_input_in_open_cb ( LmConnection */*connection*/, 
       
   479                      gboolean    success  /*success*/, 
       
   480                      gpointer data )
       
   481     {
       
   482     
       
   483     gboolean result = success;
       
   484     AuthData *auth_data = ( AuthData * ) data;
       
   485     
       
   486      //Result is false when the wrong input parameters were successfully handled.
       
   487     if (result == FALSE)
       
   488 		{       
       
   489 		auth_data->rCode = RC_OK;
       
   490 		}
       
   491     else 
       
   492     	{
       
   493     	//Result is true, when the wrong input was not handled successfully.
       
   494        	auth_data->rCode = RC_ERROR;	
       
   495     	}
       
   496     g_main_loop_quit ( auth_data->main_loop ); 		
       
   497     }
       
   498 //-----------------------------------------------------------------------------
       
   499 // funnction_name	: wrong_input_auth_cb
       
   500 // description		: callback function called by lm_connection_open
       
   501 // Returns			: None
       
   502 //-----------------------------------------------------------------------------
       
   503 //
       
   504 static void
       
   505 wrong_input_auth_cb ( LmConnection */*connection*/, 
       
   506                      gboolean  success, 
       
   507                      gpointer data )
       
   508     {
       
   509     gboolean result = success;
       
   510     AuthData *auth_data = ( AuthData * ) data;
       
   511     //Result is false when the wrong input parameters were successfully handled.
       
   512     if (result == FALSE)
       
   513 		{       
       
   514 		auth_data->rCode = RC_OK;
       
   515 		}
       
   516     else 
       
   517     	{
       
   518     	//Result is true, when the wrong input was not handled successfully.
       
   519        	auth_data->rCode = RC_ERROR;	
       
   520     	}
       
   521     g_main_loop_quit ( auth_data->main_loop );       		
       
   522     }
       
   523     
       
   524 //-----------------------------------------------------------------------------
       
   525 // funnction_name	: connection_auth_cb
       
   526 // description		: callback function set by lm_connection_authenticate
       
   527 // in lm_connection_sendL()
       
   528 // Returns			: None
       
   529 //-----------------------------------------------------------------------------
       
   530 //
       
   531 static void connection_auth_cb ( LmConnection */*connection*/, 
       
   532                      gboolean  /*success*/, 
       
   533                      gpointer data )
       
   534     {
       
   535     GMainLoop *main_loop = ( GMainLoop * ) data;
       
   536     
       
   537 	if ( main_loop )
       
   538 	    {
       
   539 		g_main_loop_quit ( main_loop );	
       
   540 	    }	   		
       
   541     }
       
   542 
       
   543 //-----------------------------------------------------------------------------
       
   544 // function_name	: auth_in_connection_cb
       
   545 // description		: callback function called for lm_connection_open
       
   546 // Returns			: RC_OK if successfull, RC_ERROR otherwise
       
   547 //-----------------------------------------------------------------------------
       
   548 static void
       
   549 auth_in_connection_cb ( LmConnection *connection, 
       
   550                   gboolean success, 
       
   551                   gpointer *data )
       
   552     {
       
   553     AuthData *auth_data = ( AuthData * ) data;
       
   554          
       
   555     if ( !success )
       
   556         {
       
   557         // Connection failed
       
   558         auth_data->rCode = RC_ERROR;
       
   559         g_main_loop_quit ( auth_data->main_loop );    	    
       
   560         }
       
   561     
       
   562     // Extract the username from the JID
       
   563     gchar *username = get_user_name ( auth_data->connect_data->username );
       
   564     
       
   565     if ( !lm_connection_authenticate ( connection, 
       
   566                                        username,
       
   567                                        auth_data->connect_data->password,
       
   568                                        auth_data->connect_data->resource, 
       
   569                                        NULL, 
       
   570                                        auth_data->connect_data->msg_data, 
       
   571                                        NULL, 
       
   572                                        NULL ) )
       
   573         {
       
   574        	auth_data->rCode = RC_ERROR;
       
   575        	g_free ( username );
       
   576        	g_main_loop_quit ( auth_data->main_loop );    	    
       
   577         }
       
   578     g_free ( username );
       
   579         
       
   580     auth_data->rCode = RC_OK;    
       
   581     g_main_loop_quit ( auth_data->main_loop );    
       
   582     
       
   583     }
       
   584 
       
   585 //-----------------------------------------------------------------------------
       
   586 // function_name	: auth_from_open_cb
       
   587 // description		: callback function called for lm_connection_authenticate
       
   588 // Returns			: RC_OK if successfull, RC_ERROR otherwise
       
   589 //-----------------------------------------------------------------------------
       
   590 static void
       
   591 auth_from_open_cb ( LmConnection *connection, 
       
   592                   gboolean success, 
       
   593                   gpointer *data )
       
   594     {
       
   595     AuthData *auth_data = ( AuthData * ) data;
       
   596          
       
   597     if ( !success )
       
   598         {
       
   599         // Connection failed
       
   600         auth_data->rCode = RC_ERROR;
       
   601         g_main_loop_quit ( auth_data->main_loop );    	    
       
   602         }
       
   603     
       
   604     // Extract the username from the JID
       
   605     gchar *username = get_user_name ( auth_data->connect_data->username );
       
   606     
       
   607     if ( !lm_connection_authenticate ( connection, 
       
   608                                        username,
       
   609                                        auth_data->connect_data->password,
       
   610                                        auth_data->connect_data->resource, 
       
   611                                        ( LmResultFunction ) wrong_input_auth_cb, 
       
   612                                        auth_data ,  
       
   613                                        NULL, 
       
   614                                        NULL ) )
       
   615         {
       
   616        	auth_data->rCode = RC_ERROR;
       
   617        	g_free ( username );
       
   618        	g_main_loop_quit ( auth_data->main_loop );    	    
       
   619         }
       
   620     g_free ( username );
       
   621     
       
   622     }
       
   623 
       
   624 
       
   625 //--------------------------------------------------------------------------------
       
   626 // function_name    : handle_messages
       
   627 // description      : callback function to handle messages
       
   628 // Returns          : LmHandlerResult
       
   629 //--------------------------------------------------------------------------------
       
   630 static LmHandlerResult
       
   631 handle_messages ( LmMessageHandler* /*handler*/,
       
   632                   LmConnection*     /*connection*/,
       
   633                   LmMessage*        /*message*/,
       
   634                   gpointer          user_data )
       
   635     {
       
   636     HandleData *handle_data = ( HandleData * )user_data;	
       
   637 	
       
   638 	if ( handle_data )
       
   639 		{
       
   640 		handle_data->Test_Success = RC_OK;
       
   641 	
       
   642 	    g_main_loop_quit ( handle_data->main_loop );
       
   643 		}	
       
   644 	
       
   645 	return LM_HANDLER_RESULT_REMOVE_MESSAGE;
       
   646     }
       
   647 
       
   648 //--------------------------------------------------------------------------------
       
   649 // function_name    : handle_messages
       
   650 // description      : callback function to handle messages
       
   651 // Returns          : LmHandlerResult
       
   652 //--------------------------------------------------------------------------------
       
   653 static LmHandlerResult
       
   654 handle_100_messages ( LmMessageHandler* /*handler*/,
       
   655                   LmConnection*     /*connection*/,
       
   656                   LmMessage*        /*message*/,
       
   657                   gpointer          user_data )
       
   658     {
       
   659     HandleData *handle_data = ( HandleData * )user_data;    
       
   660     //static int count=0;
       
   661     handle_data->count++;
       
   662     GMainLoop *main_loop = ( GMainLoop * )user_data;
       
   663     //count++;
       
   664     if(handle_data->count==5)
       
   665             {
       
   666         g_main_loop_quit ( handle_data->main_loop );
       
   667         //    g_main_loop_quit ( main_loop );
       
   668             } 
       
   669         //} 
       
   670     
       
   671     return LM_HANDLER_RESULT_REMOVE_MESSAGE;
       
   672     }
       
   673 
       
   674 //--------------------------------------------------------------------------------
       
   675 // function_name    : handle_messages
       
   676 // description      : callback function to handle messages
       
   677 // Returns          : LmHandlerResult
       
   678 //--------------------------------------------------------------------------------
       
   679 static LmHandlerResult
       
   680 handle_100_presence_notification ( LmMessageHandler* /*handler*/,
       
   681                   LmConnection*     /*connection*/,
       
   682                   LmMessage*        /*message*/,
       
   683                   gpointer          user_data )
       
   684     {
       
   685     HandleData *handle_data = ( HandleData * )user_data;    
       
   686     handle_data->count++;
       
   687     GMainLoop *main_loop = ( GMainLoop * )user_data;
       
   688     if(handle_data->count==100)
       
   689             {
       
   690         g_main_loop_quit ( handle_data->main_loop );
       
   691         
       
   692             } 
       
   693       
       
   694     
       
   695     return LM_HANDLER_RESULT_REMOVE_MESSAGE;
       
   696     }
       
   697 
       
   698 //--------------------------------------------------------------------------------
       
   699 // function_name	: connection_close_cb
       
   700 // description		: callback function called when connection is closed
       
   701 // Returns			: RC_OK if called
       
   702 //--------------------------------------------------------------------------------
       
   703 static void
       
   704 connection_close_cb ( LmConnection       */*connection*/,
       
   705                       LmDisconnectReason reason,
       
   706                       gpointer           user_data )
       
   707     {   
       
   708     HandleData *handle_data = ( HandleData * ) user_data;
       
   709     
       
   710     switch ( reason )
       
   711         {
       
   712         case LM_DISCONNECT_REASON_OK:
       
   713     	    handle_data->Test_Success = RC_OK;
       
   714     	    break;
       
   715         case LM_DISCONNECT_REASON_PING_TIME_OUT:
       
   716         /* No break, fall through */
       
   717         case LM_DISCONNECT_REASON_HUP:
       
   718         case LM_DISCONNECT_REASON_ERROR:
       
   719         case LM_DISCONNECT_REASON_UNKNOWN:
       
   720             handle_data->Test_Success = RC_ERROR;
       
   721             break;
       
   722         default:
       
   723             handle_data->Test_Success = RC_ERROR;
       
   724             break;
       
   725         }
       
   726 	
       
   727     }
       
   728 
       
   729 
       
   730 //------------------------------------------------------------------------------
       
   731 // function_name	: GetMessageType
       
   732 // description     	: Gets LmMessageType in Type
       
   733 // Returns          : None
       
   734 //------------------------------------------------------------------------------
       
   735 static void
       
   736 GetMessageType ( LmMessageType MessageType, gchar *Type )
       
   737 {
       
   738 	switch ( MessageType )
       
   739 	    {
       
   740 		case LM_MESSAGE_TYPE_MESSAGE:		
       
   741 		    g_stpcpy ( Type, "LM_MESSAGE_TYPE_MESSAGE" );
       
   742 		    break;
       
   743 	    case LM_MESSAGE_TYPE_PRESENCE:	        
       
   744 	        g_stpcpy ( Type, "LM_MESSAGE_TYPE_MESSAGE" );
       
   745 	        break;	        	    
       
   746 	    case LM_MESSAGE_TYPE_IQ:	        
       
   747 	        g_stpcpy ( Type, "LM_MESSAGE_TYPE_IQ" );
       
   748 	        break;
       
   749 	    case LM_MESSAGE_TYPE_STREAM:	        
       
   750 	        g_stpcpy ( Type, "LM_MESSAGE_TYPE_STREAM" );
       
   751 	        break;
       
   752 	    case LM_MESSAGE_TYPE_STREAM_ERROR:	        
       
   753 	        g_stpcpy ( Type, "LM_MESSAGE_TYPE_STREAM_ERROR" );	        
       
   754 	        break;
       
   755 	    case LM_MESSAGE_TYPE_UNKNOWN:	        
       
   756 	        g_stpcpy ( Type, "LM_MESSAGE_TYPE_UNKNOWN" );
       
   757 	        break;	        
       
   758 	    }
       
   759 }
       
   760 
       
   761 
       
   762 //------------------------------------------------------------------------------
       
   763 // function_name	: GetMessageSubType
       
   764 // description     	: Gets LmMessageSubType in SubType
       
   765 // Returns          : None
       
   766 //------------------------------------------------------------------------------
       
   767 static void
       
   768 GetMessageSubType ( LmMessageSubType MessageSubType, gchar *SubType )
       
   769 {
       
   770 	switch ( MessageSubType )
       
   771 	    {
       
   772 		case LM_MESSAGE_SUB_TYPE_NOT_SET:
       
   773 		    g_stpcpy ( SubType, "LM_MESSAGE_SUB_TYPE_NOT_SET" );
       
   774 		    break;
       
   775 		case LM_MESSAGE_SUB_TYPE_AVAILABLE:
       
   776 		    g_stpcpy ( SubType, "LM_MESSAGE_SUB_TYPE_AVAILABLE" );
       
   777 		    break;
       
   778 		case LM_MESSAGE_SUB_TYPE_NORMAL:
       
   779 		    g_stpcpy ( SubType, "LM_MESSAGE_SUB_TYPE_NORMAL" );
       
   780 		    break;
       
   781 		case LM_MESSAGE_SUB_TYPE_CHAT:
       
   782 		    g_stpcpy ( SubType, "LM_MESSAGE_SUB_TYPE_CHAT" );
       
   783 		    break;
       
   784 		case LM_MESSAGE_SUB_TYPE_GROUPCHAT:
       
   785 		    g_stpcpy ( SubType, "LM_MESSAGE_SUB_TYPE_GROUPCHAT" );
       
   786 		    break;
       
   787 		case LM_MESSAGE_SUB_TYPE_HEADLINE:
       
   788 		    g_stpcpy ( SubType, "LM_MESSAGE_SUB_TYPE_HEADLINE" );
       
   789 		    break;
       
   790 		case LM_MESSAGE_SUB_TYPE_UNAVAILABLE:
       
   791 		    g_stpcpy ( SubType, "LM_MESSAGE_SUB_TYPE_UNAVAILABLE" );
       
   792 		    break;
       
   793 		case LM_MESSAGE_SUB_TYPE_PROBE:
       
   794 		    g_stpcpy ( SubType, "LM_MESSAGE_SUB_TYPE_PROBE" );
       
   795 		    break;
       
   796 		case LM_MESSAGE_SUB_TYPE_SUBSCRIBE:
       
   797 		    g_stpcpy ( SubType, "LM_MESSAGE_SUB_TYPE_SUBSCRIBE" );
       
   798 		    break;
       
   799 		case LM_MESSAGE_SUB_TYPE_UNSUBSCRIBE:
       
   800 		    g_stpcpy ( SubType, "LM_MESSAGE_SUB_TYPE_UNSUBSCRIBE" );
       
   801 		    break;
       
   802 		case LM_MESSAGE_SUB_TYPE_SUBSCRIBED:
       
   803 		    g_stpcpy ( SubType, "LM_MESSAGE_SUB_TYPE_SUBSCRIBED" );
       
   804 		    break;
       
   805 		case LM_MESSAGE_SUB_TYPE_UNSUBSCRIBED:
       
   806 		    g_stpcpy ( SubType, "LM_MESSAGE_SUB_TYPE_UNSUBSCRIBED" );
       
   807 		    break;
       
   808 		case LM_MESSAGE_SUB_TYPE_GET:
       
   809 		    g_stpcpy ( SubType, "LM_MESSAGE_SUB_TYPE_GET" );
       
   810 		    break;
       
   811 		case LM_MESSAGE_SUB_TYPE_SET:
       
   812 		    g_stpcpy ( SubType, "LM_MESSAGE_SUB_TYPE_SET" );
       
   813 		    break;
       
   814 		case LM_MESSAGE_SUB_TYPE_RESULT:
       
   815 		    g_stpcpy ( SubType, "LM_MESSAGE_SUB_TYPE_RESULT" );
       
   816 		    break;
       
   817 		case LM_MESSAGE_SUB_TYPE_ERROR:
       
   818 		    g_stpcpy ( SubType, "LM_MESSAGE_SUB_TYPE_ERROR" );
       
   819 		    break;
       
   820 	    }
       
   821 }
       
   822 
       
   823 
       
   824 // ---------------------------------------------------------------------------
       
   825 // jabber_presence_type_from_string: Returns the presence type
       
   826 // ---------------------------------------------------------------------------
       
   827 //	
       
   828 static JabberPresenceType
       
   829 jabber_presence_type_from_string ( const gchar *string )
       
   830 	{
       
   831 	
       
   832 	if ( string == NULL )
       
   833 		return XMPP_PRESENCE_TYPE_ONLINE;
       
   834 	
       
   835 	if ( !strcmp ( string, "online" ) )
       
   836 		return XMPP_PRESENCE_TYPE_ONLINE;	
       
   837 	else if ( !strcmp ( string, "chat" ) )
       
   838 		return XMPP_PRESENCE_TYPE_CHAT;
       
   839 	else if ( !strcmp ( string, "away" ) )
       
   840 		return XMPP_PRESENCE_TYPE_AWAY;
       
   841 	else if ( !strcmp ( string, "xa" ) )
       
   842 		return XMPP_PRESENCE_TYPE_XA;
       
   843 	else if ( !strcmp ( string, "dnd" ) )
       
   844 		return XMPP_PRESENCE_TYPE_DND;
       
   845 	else if ( !strcmp ( string, "invisible" ) )
       
   846 		return XMPP_PRESENCE_TYPE_INVISIBLE;
       
   847 	else if ( !strcmp ( string, "unavailable" ) )
       
   848 		return XMPP_PRESENCE_TYPE_UNAVAILABLE;	
       
   849 	else
       
   850 		return XMPP_PRESENCE_TYPE_ONLINE;
       
   851 	}
       
   852 
       
   853 
       
   854 // ---------------------------------------------------------------------------
       
   855 // function_name       : ssl_cb
       
   856 // description         : This function is called if something goes wrong
       
   857 //                       during the connecting phase.
       
   858 // Arguements          :
       
   859 //        ssl          : An LmSSL
       
   860 //        status       : The status informing what went wrong
       
   861 //        user_data    : User data provided in the callback
       
   862 //
       
   863 // Returns             : User should return LM_SSL_RESPONSE_CONTINUE if 
       
   864 //                       connection should proceed. otherwise 
       
   865 //                       LM_SSL_RESPONSE_STOP.
       
   866 // ---------------------------------------------------------------------------
       
   867 //
       
   868 static LmSSLResponse
       
   869 ssl_cb ( LmSSL */*ssl*/, LmSSLStatus status, gpointer /*user_data*/ )
       
   870 	{
       
   871 	
       
   872 	g_print ( "SSL status :%d\n", status );
       
   873 	
       
   874 	switch ( status ) 
       
   875 	    {
       
   876 	case LM_SSL_STATUS_NO_CERT_FOUND:
       
   877        	g_printerr ("No certificate found!\n");
       
   878        	break;
       
   879      case LM_SSL_STATUS_UNTRUSTED_CERT:
       
   880        	g_printerr ("Certificate is not trusted!\n");
       
   881        	break;
       
   882  	case LM_SSL_STATUS_CERT_EXPIRED:
       
   883        	g_printerr ("Certificate has expired!\n");
       
   884        	break;
       
   885 	case LM_SSL_STATUS_CERT_NOT_ACTIVATED:
       
   886        	g_printerr ("Certificate has not been activated!\n");
       
   887        	break;
       
   888 	case LM_SSL_STATUS_CERT_HOSTNAME_MISMATCH:
       
   889        	g_printerr ("Certificate hostname does not match expected hostname!\n");
       
   890        	break;
       
   891 	 case LM_SSL_STATUS_CERT_FINGERPRINT_MISMATCH:
       
   892 	 	g_printerr ( "fingerprint error!\n" );
       
   893 	 	break;
       
   894 	 case LM_SSL_STATUS_GENERIC_ERROR:
       
   895         g_printerr ("Generic SSL error!\n");
       
   896         break;
       
   897 	    }
       
   898 		
       
   899 	return LM_SSL_RESPONSE_CONTINUE;
       
   900 	}
       
   901 
       
   902 
       
   903 // ---------------------------------------------------------------------------
       
   904 // function_name       : SetProxy
       
   905 // description         : Sets the connection to use proxy
       
   906 // Arguements          :
       
   907 //        connection   : LmConnection
       
   908 //        connect_data : ConnectData
       
   909 // Returns             : None
       
   910 // ---------------------------------------------------------------------------
       
   911 //
       
   912 #ifdef __WINSCW__
       
   913 static void 
       
   914 SetProxy ( LmConnection *connection, ProxyData *proxy_data )
       
   915 	{
       
   916 	LmProxy *proxy = NULL;
       
   917 	
       
   918 	proxy = lm_proxy_new ( LM_PROXY_TYPE_HTTP );
       
   919 	lm_proxy_set_server ( proxy, proxy_data->proxy_server );
       
   920 	lm_proxy_set_port ( proxy, proxy_data->proxy_port );
       
   921 	lm_connection_set_proxy ( connection, proxy );
       
   922 	lm_proxy_unref ( proxy );
       
   923 	}
       
   924 #endif
       
   925 
       
   926 // ---------------------------------------------------------------------------
       
   927 // function_name       : SSLInit
       
   928 // description         : Sets the connection to use SSL
       
   929 // Arguements          :
       
   930 //        connection   : LmConnection
       
   931 // Returns             : None
       
   932 // ---------------------------------------------------------------------------
       
   933 //
       
   934 static void 
       
   935 SSLInit ( LmConnection *connection )
       
   936 	{
       
   937 	LmSSL *ssl = NULL;
       
   938 	
       
   939 	ssl = lm_ssl_new ( NULL, ( LmSSLFunction ) ssl_cb, NULL, NULL );
       
   940 	lm_connection_set_ssl ( connection, ssl );
       
   941 		lm_ssl_unref ( ssl );
       
   942 	lm_connection_set_keep_alive_rate (connection, 30);
       
   943 	}
       
   944 
       
   945 
       
   946 // ---------------------------------------------------------------------------
       
   947 // function_name       : get_user_name 
       
   948 // description         : Returns the username from the jid
       
   949 // Arguements          :
       
   950 //        jid          : jid
       
   951 // Returns             : username
       
   952 // ---------------------------------------------------------------------------
       
   953 //
       
   954 static gchar *
       
   955 get_user_name ( const gchar *jid )
       
   956 	{
       
   957 	const gchar *ch;
       
   958 	
       
   959 	g_return_val_if_fail ( jid != NULL, NULL );
       
   960 	
       
   961 	ch = strchr ( jid, '@' );
       
   962 	if ( !ch )
       
   963 		return ( gchar *) jid;
       
   964 	
       
   965 	return g_strndup ( jid, ch - jid );
       
   966 	}
       
   967 
       
   968 // ---------------------------------------------------------------------------
       
   969 // jabber_presence_handler_cb: Callback function to handle the presence info
       
   970 // ---------------------------------------------------------------------------
       
   971 //
       
   972 static LmHandlerResult
       
   973 jabber_presence_handler_cb ( LmMessageHandler * /*handler*/,
       
   974                               LmConnection     * /*connection*/,
       
   975                               LmMessage        *message,
       
   976                               gpointer          user_data )
       
   977 	{	
       
   978 	const gchar        *jid;
       
   979 	const gchar        *show;
       
   980 	const gchar        *status;		
       
   981 	
       
   982 	LmMessageNode      *node;
       
   983 	JabberPresenceType type;
       
   984 	
       
   985 	if(message != NULL)
       
   986 		{
       
   987 		// Get the JID attribute
       
   988 		jid = lm_message_node_get_attribute ( message->node, "from" );
       
   989 
       
   990 		// Get the show attribute
       
   991 		
       
   992 		node = lm_message_node_get_child ( message->node, "show" );
       
   993 		show = node ? ( node->value ) : "online";
       
   994 		
       
   995 		// Get the status attribute
       
   996 		node   = lm_message_node_get_child ( message->node, "status" );
       
   997 		status = node ? ( node->value ) : NULL;
       
   998 		
       
   999 		type = jabber_presence_type_from_string ( show );			
       
  1000 		}
       
  1001 	
       
  1002 		
       
  1003 	GMainLoop *main_loop = ( GMainLoop * ) user_data;  
       
  1004 	if ( main_loop )
       
  1005 	    {
       
  1006 	    g_main_loop_quit ( main_loop );	
       
  1007 	    }  		
       
  1008 	return LM_HANDLER_RESULT_REMOVE_MESSAGE;
       
  1009 	}
       
  1010 
       
  1011 
       
  1012 
       
  1013 
       
  1014 
       
  1015 // ============================ MEMBER FUNCTIONS ===============================
       
  1016 
       
  1017 // -----------------------------------------------------------------------------
       
  1018 // Ctstlm::Delete
       
  1019 // Delete here all resources allocated and opened from test methods. 
       
  1020 // Called from destructor. 
       
  1021 // -----------------------------------------------------------------------------
       
  1022 //
       
  1023 void Ctstlm::Delete() 
       
  1024     {
       
  1025 
       
  1026     }
       
  1027 
       
  1028 // -----------------------------------------------------------------------------
       
  1029 // Ctstlm::RunMethodL
       
  1030 // Run specified method. Contains also table of test mothods and their names.
       
  1031 // -----------------------------------------------------------------------------
       
  1032 //
       
  1033 TInt Ctstlm::RunMethodL( 
       
  1034     CStifItemParser& aItem ) 
       
  1035     {
       
  1036 	iLog->Log ( _L ( "In RunMethodL method" ) );
       
  1037 	
       
  1038 
       
  1039     //TestModuleIf().SetBehavior( CTestModuleIf::ETestLeaksRequests ); 
       
  1040     //TestModuleIf().SetBehavior( CTestModuleIf::ETestLeaksHandles );  
       
  1041 
       
  1042     static TStifFunctionInfo const KFunctions[] =
       
  1043         {  
       
  1044         // Copy this line for every implemented function.
       
  1045         // First string is the function name used in TestScripter script file.
       
  1046         // Second is the actual implementation member function.    
       
  1047         
       
  1048         // LmConnection       
       
  1049         ENTRY( "lm_connection_new", Ctstlm::lm_connection_newL ),
       
  1050         ENTRY( "lm_new_with_context", Ctstlm::lm_new_with_contextL ),
       
  1051         ENTRY( "lm_connection_open", Ctstlm::lm_connection_openL ),
       
  1052         ENTRY( "lm_connection_is_open_WhenConnectionIsClosed", Ctstlm::lm_connection_is_open_WhenConnectionIsClosedL), 
       
  1053         ENTRY( "lm_connection_is_authenticated_WhenNot_Authenticated", Ctstlm::lm_is_authenticated_WhenNotAuthenticatedL), 
       
  1054         ENTRY( "lm_connection_set_server_withNULL", Ctstlm::lm_connection_set_server_WithNULL),   
       
  1055         ENTRY( "lm_connection_set_jid_WithNull", Ctstlm::lm_connection_set_jid_WithNULL),   
       
  1056         ENTRY( "lm_connection_set_port_WithNULL", Ctstlm::lm_connection_set_port_WithNULL),   
       
  1057         ENTRY( "lm_connection_set_ssl_WithNULL", Ctstlm::lm_connection_set_ssl_WithNULL),   
       
  1058         ENTRY( "lm_connection_close", Ctstlm::lm_connection_closeL ),
       
  1059         ENTRY( "lm_connection_closeWhenNotOpen", Ctstlm::lm_connection_closeWhenNotOpenedL ),
       
  1060         ENTRY( "lm_authenticate", Ctstlm::lm_authenticateL ),
       
  1061         ENTRY( "lm_connection_is_open", Ctstlm::lm_connection_is_openL ),
       
  1062         ENTRY( "lm_is_authenticated", Ctstlm::lm_is_authenticatedL ),
       
  1063         ENTRY( "lm_connection_set_get_server", Ctstlm::lm_connection_set_get_serverL ),
       
  1064         ENTRY( "lm_connection_set_get_jid", Ctstlm::lm_connection_set_get_jidL ), 
       
  1065         ENTRY( "lm_connection_set_get_port", Ctstlm::lm_connection_set_get_portL ),
       
  1066         ENTRY( "lm_connection_set_get_ssl", Ctstlm::lm_connection_set_get_sslL ),
       
  1067         ENTRY( "lm_connection_set_get_proxy", Ctstlm::lm_connection_set_get_proxyL ),
       
  1068         
       
  1069         ENTRY( "lm_connection_send", Ctstlm::lm_connection_sendL ),
       
  1070         ENTRY( "lm_connection_send400char", Ctstlm::lm_connection_send400charL ),
       
  1071         ENTRY( "lm_connection_send_repeated", Ctstlm::lm_connection_send_repeatedL ),       
       
  1072         
       
  1073         ENTRY( "lm_send_with_reply", Ctstlm::lm_send_with_replyL ),
       
  1074         ENTRY( "register_message_handler", Ctstlm::register_message_handlerL ),
       
  1075         ENTRY( "set_disconnect_function", Ctstlm::set_disconnect_functionL ),
       
  1076         ENTRY( "lm_connection_send_raw",  Ctstlm::lm_connection_send_rawL ),
       
  1077         ENTRY( "lm_connection_get_state", Ctstlm::lm_connection_get_stateL ),
       
  1078         ENTRY( "lm_connection_ref",  Ctstlm::lm_connection_refL ),
       
  1079         ENTRY( "lm_connection_unref", Ctstlm::lm_connection_unrefL ),
       
  1080         
       
  1081         // LmMessage
       
  1082         ENTRY( "lm_message_new", Ctstlm::lm_message_newL ),
       
  1083         ENTRY( "lm_message_new_with_sub_type", Ctstlm::lm_message_new_with_sub_typeL ),
       
  1084         ENTRY( "lm_message_get_type", Ctstlm::lm_message_get_typeL ),
       
  1085         ENTRY( "lm_message_get_sub_type", Ctstlm::lm_message_get_sub_typeL ),
       
  1086         ENTRY( "lm_message_get_node", Ctstlm::lm_message_get_nodeL ),
       
  1087         ENTRY( "lm_message_ref", Ctstlm::lm_message_refL ),
       
  1088         ENTRY( "lm_message_unref", Ctstlm::lm_message_unrefL ),
       
  1089         
       
  1090         // LmMessageHandler
       
  1091         ENTRY( "lm_message_handler_new", Ctstlm::lm_message_handler_newL ),
       
  1092         ENTRY( "lm_message_handler_invalidate", Ctstlm::lm_message_handler_invalidateL ),
       
  1093         ENTRY( "lm_message_handler_is_valid", Ctstlm::lm_message_handler_is_validL ),
       
  1094         ENTRY( "lm_message_handler_ref", Ctstlm::lm_message_handler_refL ),
       
  1095         ENTRY( "lm_message_handler_unref", Ctstlm::lm_message_handler_unrefL ),
       
  1096         
       
  1097         // LmMessageNode
       
  1098         ENTRY( "lm_message_node_set_get_value", Ctstlm::lm_message_node_set_get_valueL ),
       
  1099         ENTRY( "lm_message_node_add_child", Ctstlm::lm_message_node_add_childL ),
       
  1100         ENTRY( "lm_message_node_get_child", Ctstlm::lm_message_node_get_childL ),
       
  1101         ENTRY( "lm_message_node_find_child", Ctstlm::lm_message_node_find_childL ),  
       
  1102         
       
  1103         ENTRY( "lm_message_node_set_get_attributes", Ctstlm::lm_message_node_set_get_attributesL ),
       
  1104               
       
  1105         ENTRY( "lm_message_node_set_get_raw_mode", Ctstlm::lm_message_node_set_get_raw_modeL ),
       
  1106         
       
  1107         ENTRY( "lm_message_node_ref", Ctstlm::lm_message_node_refL ),
       
  1108         ENTRY( "lm_message_node_unref", Ctstlm::lm_message_node_unrefL ),
       
  1109         
       
  1110         ENTRY( "lm_message_node_to_string", Ctstlm::lm_message_node_to_stringL ),
       
  1111         
       
  1112         // LmSSL
       
  1113         ENTRY( "lm_ssl_new", Ctstlm::lm_ssl_newL ),
       
  1114         ENTRY( "lm_ssl_is_supported", Ctstlm::lm_ssl_is_supportedL ),
       
  1115         ENTRY( "lm_ssl_get_fingerprint", Ctstlm::lm_ssl_get_fingerprintL ),
       
  1116         ENTRY( "lm_ssl_ref", Ctstlm::lm_ssl_refL ),
       
  1117         ENTRY( "lm_ssl_unref", Ctstlm::lm_ssl_unrefL ),        
       
  1118         
       
  1119         // LmProxy        
       
  1120         ENTRY( "lm_proxy_new", Ctstlm::lm_proxy_newL ),
       
  1121         ENTRY( "lm_proxy_new_with_server", Ctstlm::lm_proxy_new_with_serverL ),        
       
  1122         ENTRY( "lm_proxy_set_get_type", Ctstlm::lm_proxy_set_get_typeL ),        
       
  1123         ENTRY( "lm_proxy_set_get_server", Ctstlm::lm_proxy_set_get_serverL ),        
       
  1124         ENTRY( "lm_proxy_set_get_port", Ctstlm::lm_proxy_set_get_portL ),        
       
  1125         ENTRY( "lm_proxy_set_get_username", Ctstlm::lm_proxy_set_get_usernameL ),        
       
  1126         ENTRY( "lm_proxy_set_get_password", Ctstlm::lm_proxy_set_get_passwordL ),        
       
  1127         ENTRY( "lm_proxy_ref", Ctstlm::lm_proxy_refL ),
       
  1128         ENTRY( "lm_proxy_unref", Ctstlm::lm_proxy_unrefL ),
       
  1129         
       
  1130         // lm-send-sync example        
       
  1131         ENTRY( "lm_send_sync", Ctstlm::lm_send_syncL ),
       
  1132         
       
  1133         // lm contact list fetching code
       
  1134         
       
  1135         ENTRY( "lm_fetching_contactlist", Ctstlm::lm_fetching_contactlist_L ),
       
  1136         ENTRY( "lm_fetching_presence", Ctstlm::lm_fetching_presenceL ),
       
  1137         ENTRY( "lm_subscribe_contact", Ctstlm::lm_subscribe_contact_L ),
       
  1138         ENTRY( "lm_authenticate_unexistjid", Ctstlm::lm_authenticate_WithUnexistingJID ),
       
  1139         ENTRY( "lm_authenticate_badpassword", Ctstlm::lm_authenticate_WithBadPasswordL ),
       
  1140         ENTRY( "lm_authenticate_connectionisnotcreated", Ctstlm::lm_authenticate_WhenConnectionIsNotOpenedL ),
       
  1141         ENTRY( "lm_connection_open_with_bad_server", Ctstlm::lm_connection_open_with_badserverL ),
       
  1142         ENTRY( "lm_connection_send_receive", Ctstlm::lm_connection_send_receiveL ),
       
  1143         ENTRY( "lm_login_test", Ctstlm::lm_login_testL ),
       
  1144         ENTRY( "lm_add_contact", Ctstlm::lm_add_contactL ),
       
  1145         ENTRY( "lm_remove_contact", Ctstlm::lm_remove_contactL ),
       
  1146         ENTRY( "lm_connection_cancel_open", Ctstlm::lm_connection_cancel_openL ),
       
  1147         ENTRY( "lm_connection_get_privacy_lists", Ctstlm::lm_connection_get_privacy_listsL ),
       
  1148         ENTRY( "lm_connection_set_privacy_lists", Ctstlm::lm_connection_set_privacy_listsL ),
       
  1149         ENTRY( "lm_connection_send_image_bytestream_msg", Ctstlm::lm_connection_send_image_bytestream_msgL ),
       
  1150         ENTRY( "lm_connection_send_image_bytestream_iq", Ctstlm::lm_connection_send_image_bytestream_iqL ),
       
  1151         ENTRY( "lm_connection_send_multiple_conn", Ctstlm::lm_connection_send_multiple_connL ),
       
  1152         ENTRY( "lm_connection_block_contact", Ctstlm::lm_connection_block_contactL ),
       
  1153         ENTRY( "lm_connection_unblock_contact", Ctstlm::lm_connection_unblock_contactL ),
       
  1154         ENTRY( "lm_connection_set_active_list", Ctstlm::lm_connection_set_active_listL ),
       
  1155         ENTRY( "lm_connection_set_unexist_active_list", Ctstlm::lm_connection_set_unexist_active_listL ),
       
  1156         ENTRY( "lm_connection_set_decline_active_list", Ctstlm::lm_connection_set_decline_active_listL ),
       
  1157         ENTRY( "lm_connection_get_one_privacy_list", Ctstlm::lm_connection_get_one_privacy_listL ),
       
  1158         ENTRY( "lm_connection_set_one_privacy_list", Ctstlm::lm_connection_set_one_privacy_listL ),
       
  1159         ENTRY( "lm_connection_get_many_privacy_list_from_listname", Ctstlm::lm_connection_get_many_privacy_list_from_listnameL ),
       
  1160         ENTRY( "lm_connection_set_one_unexist_privacy_list", Ctstlm::lm_connection_set_one_unexist_privacy_listL ),
       
  1161         ENTRY( "lm_connection_get_one_unexist_privacy_list", Ctstlm::lm_connection_get_one_unexist_privacy_listL ),
       
  1162         ENTRY( "lm_connection_create_one_privacy_list", Ctstlm::lm_connection_create_one_privacy_listL ),
       
  1163         ENTRY( "lm_service_discovery", Ctstlm::lm_service_discoveryL ),
       
  1164         ENTRY( "lm_service_discovery_connected_resource", Ctstlm::lm_service_discovery_connected_resourceL ),
       
  1165         ENTRY( "lm_simple_communications_blocking", Ctstlm::lm_simple_communications_blockingL ),
       
  1166         ENTRY( "lm_send_im_with_reply", Ctstlm::lm_send_im_with_replyL ),
       
  1167         ENTRY( "lm_receive_any_message", Ctstlm::lm_receive_any_messageL ),
       
  1168         ENTRY( "lm_login_multiple_sessions", Ctstlm::lm_login_multiple_sessionsL ),
       
  1169         ENTRY( "lm_change_own_presence", Ctstlm::lm_change_own_presenceL ),
       
  1170         ENTRY( "lm_login_test_invalid_server", Ctstlm::lm_login_test_invalid_serverL ),
       
  1171         ENTRY( "lm_login_test_invalid_port", Ctstlm::lm_login_test_invalid_portL ),
       
  1172         ENTRY( "lm_memory_leak_test", Ctstlm::lm_memory_leak_testL ),
       
  1173         ENTRY( "lm_nft_updating_presence", Ctstlm::lm_nft_updating_presenceL ),
       
  1174         ENTRY( "lm_nft_presence_notification", Ctstlm::lm_nft_presence_notificationL ),
       
  1175         ENTRY( "lm_nft_send_text_message", Ctstlm::lm_nft_send_text_messageL ),
       
  1176         ENTRY( "lm_nft_open_conversation_with_multiple",Ctstlm::lm_nft_open_conversation_with_multipleL ),
       
  1177         ENTRY( "lm_nft_fetch300_contact", Ctstlm::lm_nft_fetch300_contactL ),
       
  1178         ENTRY( "lm_nft_loginlogoutmultipletime", Ctstlm::lm_nft_loginlogoutmultipletime ),
       
  1179         ENTRY( "lm_nft_receiving100_message_L", Ctstlm::lm_nft_receiving100_message_L ),
       
  1180         
       
  1181         };
       
  1182 
       
  1183     const TInt count = sizeof( KFunctions ) / 
       
  1184                         sizeof( TStifFunctionInfo );
       
  1185 
       
  1186     return RunInternalL( KFunctions, count, aItem );
       
  1187 
       
  1188     }
       
  1189 
       
  1190 
       
  1191 //----------------------------------------------------------------------------
       
  1192 // Ctstlm::lm_connection_newL
       
  1193 // Description	: Creates a new closed connection. Server can be NULL but must
       
  1194 //				  be set before calling lm_connection_open()
       
  1195 // Arguements	:
       
  1196 //		 server	: The hostname of the server for the connection
       
  1197 // Retrurns		: A newly created LmConnection, should be unreffed with 
       
  1198 //				  lm_connection_unref()
       
  1199 //----------------------------------------------------------------------------
       
  1200 //
       
  1201 TInt Ctstlm::lm_connection_newL ( CStifItemParser& aItem )
       
  1202 	{
       
  1203 	LmConnection *connection   = NULL;
       
  1204 	ConnectData  *connect_data = NULL;	
       
  1205   	
       
  1206   	SET_LOW_MEMORY_TRAP ( NULL );
       
  1207   	
       
  1208   	iLog->Log ( _L("In lm_connection_newL" ) );
       
  1209   	
       
  1210   	
       
  1211   	
       
  1212 __UHEAP_MARK;
       
  1213 __UHEAP_RESET;
       
  1214 
       
  1215   	// Read data from the cfg file
       
  1216   	if ( read_data ( connect_data, aItem ) != RC_OK )
       
  1217   	    {
       
  1218   		iLog->Log ( _L ( "read_data failed" ) );
       
  1219   		free_data ( connect_data );
       
  1220   		return KErrGeneral;
       
  1221   	    }
       
  1222   	
       
  1223 __UHEAP_FAILNEXT(1);
       
  1224 
       
  1225   	//-----------------------
       
  1226   	connection = lm_connection_new ( connect_data->server );  	
       
  1227   	//-----------------------
       
  1228   	
       
  1229   	// Free the allocated resources 
       
  1230   	free_data ( connect_data );
       
  1231   	
       
  1232 	if ( connection == NULL ) 
       
  1233 	    {
       
  1234 		iLog->Log ( _L( "lm_connection_new failed to allocate memory" ) );		
       
  1235 		return KErrGeneral;	
       
  1236 	    }
       
  1237 	
       
  1238 	lm_connection_unref ( connection );
       
  1239 __UHEAP_MARKEND;
       
  1240 	
       
  1241 	REMOVE_LOW_MEMORY_TRAP ();
       
  1242 	
       
  1243 	iLog->Log ( _L( "lm_connection_new test case passed" ) );
       
  1244 	
       
  1245 	return KErrNone;			
       
  1246 	}
       
  1247 	
       
  1248 	
       
  1249 //----------------------------------------------------------------------------
       
  1250 // Ctstlm::lm_connection_new_with_context
       
  1251 // Description	: Creates a new closed connection running in a certain context
       
  1252 // Arguements	:
       
  1253 //		server	: The hostname of the server for the connection
       
  1254 //		context	: The context this connection should be running on
       
  1255 // Retrurns		: A newly created Lmconnection, should be unreffed with
       
  1256 //				  lm_connection_unref()
       
  1257 //----------------------------------------------------------------------------
       
  1258 //
       
  1259 TInt Ctstlm::lm_new_with_contextL ( CStifItemParser& /* aItem */ )
       
  1260     {
       
  1261 	GMainContext *context;
       
  1262 	LmConnection *connection = NULL;
       
  1263 	
       
  1264 	iLog->Log ( _L( "In lm_connection_new_with_contextL" ) );
       
  1265 	
       
  1266 	context = g_main_context_new ();
       
  1267 	connection = lm_connection_new_with_context ( NULL, context );
       
  1268 	if ( connection == NULL ) 
       
  1269 		{
       
  1270 		iLog->Log ( _L ( "lm_connection_new_with_context failed" ) );
       
  1271 		return KErrGeneral;
       
  1272 		}
       
  1273 		
       
  1274 	lm_connection_unref ( connection );
       
  1275 	
       
  1276 	iLog->Log ( _L ( "lm_connection_new_with_context test case passed" ) );
       
  1277 	
       
  1278 	return KErrNone;
       
  1279     }
       
  1280 	
       
  1281 
       
  1282 //-----------------------------------------------------------------------------
       
  1283 // Ctstlm::lm_connection_open
       
  1284 // Description	: An async call to open connection. When the connection is open
       
  1285 //                function 'connection_open_cb' is called
       
  1286 // Arguements	:
       
  1287 //	connection	: LmConnection to open
       
  1288 //	function	: Callback function that will be called when the connection 
       
  1289 //         		  is open
       
  1290 //	user_data	: User data that will be passed to function
       
  1291 //	notify		: Function for freeing that user_data, can be NULL
       
  1292 //	error		: location to store error
       
  1293 // Returns		: TRUE if everything went fine, FALSE otherwise
       
  1294 //
       
  1295 // Requieres	: This test case requires GUI for selecting Access point
       
  1296 //-----------------------------------------------------------------------------
       
  1297 //
       
  1298 TInt Ctstlm::lm_connection_openL ( CStifItemParser& aItem )
       
  1299     {
       
  1300 	LmConnection *connection   = NULL;
       
  1301 	ConnectData  *connect_data = NULL;
       
  1302 	
       
  1303 	GMainLoop    *main_loop    = NULL;	
       
  1304 		
       
  1305 	iLog->Log ( _L ( "In lm_connection_open" ) );
       
  1306 	
       
  1307 	// Read data from the CFG file
       
  1308 	if ( read_data ( connect_data, aItem ) != RC_OK )
       
  1309 		{
       
  1310 		iLog->Log ( _L ( "read_data failed" ) );
       
  1311 		free_data ( connect_data );
       
  1312 		return KErrGeneral;
       
  1313 		}
       
  1314 	
       
  1315 	// Open a new closed connection
       
  1316 	//context = g_main_context_new ();
       
  1317 	//connection = lm_connection_new_with_context ( connect_data->server, context );
       
  1318 	
       
  1319 	connection = lm_connection_new ( connect_data->server );
       
  1320 	if ( !connection )
       
  1321 		{
       
  1322 		iLog->Log ( _L ( "lm_connection_new failed" ) );
       
  1323 		free_data ( connect_data );
       
  1324 		return KErrGeneral;
       
  1325 		}
       
  1326 		
       
  1327 	lm_connection_set_port ( connection, GTALK_SSL_PORT );
       
  1328 	lm_connection_set_jid ( connection, connect_data->username );
       
  1329 	
       
  1330 	// Set proxy for emulator
       
  1331 #ifdef __WINSCW__
       
  1332     SetProxy ( connection, connect_data->proxy_data );
       
  1333 #endif
       
  1334 
       
  1335     // Set connection to use SSL
       
  1336     SSLInit ( connection );
       
  1337 	
       
  1338 	main_loop = g_main_loop_new ( NULL, FALSE );
       
  1339 	
       
  1340 	if ( !lm_connection_open ( connection, ( LmResultFunction ) connection_open_cb,
       
  1341 	                           main_loop, NULL, NULL ) ) 
       
  1342 	    {
       
  1343 		iLog->Log ( _L ( "lm_connection_open failed" ));
       
  1344 		lm_connection_unref ( connection );
       
  1345 		g_main_loop_unref ( main_loop );
       
  1346 		free_data ( connect_data );		
       
  1347 		return KErrGeneral;
       
  1348 	    }
       
  1349 		
       
  1350 	
       
  1351 	g_main_loop_run ( main_loop );
       
  1352 	g_main_loop_unref ( main_loop );
       
  1353 	
       
  1354 	lm_connection_close ( connection, NULL );
       
  1355 	lm_connection_unref ( connection );
       
  1356 	free_data ( connect_data );
       
  1357 	
       
  1358 	iLog->Log ( _L ( "lm_connection_open succeded" ) );
       
  1359 	return  KErrNone;	
       
  1360 
       
  1361     }
       
  1362 
       
  1363 
       
  1364 //-----------------------------------------------------------------------------
       
  1365 // Ctstlm::lm_connection_close
       
  1366 // Description	 : A synchronous call to close the connection
       
  1367 // Arguements    :
       
  1368 //	  connection : LmConnection to close
       
  1369 //			error		: location to store error, or NULL
       
  1370 // Retrurns      :TRUE if no errors were detected, otherwise FALSE
       
  1371 //-----------------------------------------------------------------------------
       
  1372 //
       
  1373 TInt Ctstlm::lm_connection_closeL ( CStifItemParser& aItem )
       
  1374     {
       
  1375 	LmConnection *connection   = NULL;
       
  1376 	ConnectData  *connect_data = NULL;
       
  1377 	
       
  1378 	iLog->Log ( _L ( "In lm_connection_close" ) );
       
  1379 	
       
  1380 	// Read data from the CFG file
       
  1381 	if ( read_data ( connect_data, aItem ) != RC_OK )
       
  1382 		{
       
  1383 		iLog->Log ( _L ( "read_data failed" ) );
       
  1384 		free_data ( connect_data );
       
  1385 		return KErrGeneral;
       
  1386 		}
       
  1387 	
       
  1388 	// Open a new closed connection	
       
  1389 	connection = lm_connection_new ( connect_data->server );
       
  1390 	if ( !connection )
       
  1391 		{
       
  1392 		iLog->Log ( _L ( "lm_connection_new failed" ) );
       
  1393 		free_data ( connect_data );
       
  1394 		return KErrGeneral;
       
  1395 		}
       
  1396 	
       
  1397 	lm_connection_set_port ( connection, GTALK_SSL_PORT );
       
  1398 	lm_connection_set_jid ( connection, connect_data->username );
       
  1399 	// Set proxy settings for Emulator
       
  1400 #ifdef __WINSCW__
       
  1401 	SetProxy ( connection, connect_data->proxy_data );
       
  1402 #endif
       
  1403 	
       
  1404 	// Set connection to use SSL
       
  1405 	SSLInit ( connection );
       
  1406 	GMainLoop *main_loop = g_main_loop_new ( NULL, FALSE );
       
  1407 	
       
  1408 	if ( !lm_connection_open ( connection, ( LmResultFunction ) connection_open_cb,
       
  1409 	                           main_loop, NULL, NULL ) ) 
       
  1410 	    {
       
  1411 		iLog->Log ( _L ( "lm_connection_open failed" ));
       
  1412 		lm_connection_unref ( connection );
       
  1413 		free_data ( connect_data );
       
  1414 		g_main_loop_unref ( main_loop );		
       
  1415 		return KErrGeneral;
       
  1416 	    }
       
  1417 		
       
  1418 	
       
  1419 	g_main_loop_run ( main_loop );
       
  1420 	g_main_loop_unref ( main_loop );
       
  1421 	
       
  1422 		
       
  1423 	if ( lm_connection_close ( connection, NULL ) == FALSE )
       
  1424 	    {
       
  1425 		iLog->Log ( _L ( "lm_connection_close failed" ) );
       
  1426 		lm_connection_unref ( connection );
       
  1427 		return KErrGeneral;
       
  1428 	    }
       
  1429 	
       
  1430 	lm_connection_unref ( connection );
       
  1431 	free_data ( connect_data );
       
  1432 	iLog->Log ( _L ( "lm_connection_close passed" ) );
       
  1433 	
       
  1434 	return KErrNone;
       
  1435     }
       
  1436 
       
  1437 
       
  1438 //-----------------------------------------------------------------------------
       
  1439 // Ctstlm::lm_connection_closeWhenNotOpenedL
       
  1440 // Description	 : A synchronous call to close the connection
       
  1441 // Arguements    :
       
  1442 //	  connection : LmConnection to close
       
  1443 //			error		: location to store error, or NULL
       
  1444 // Retrurns      :TRUE if no errors were detected, otherwise FALSE
       
  1445 //-----------------------------------------------------------------------------
       
  1446 //
       
  1447 TInt Ctstlm::lm_connection_closeWhenNotOpenedL ( CStifItemParser& aItem )
       
  1448     {
       
  1449 	LmConnection *connection   = NULL;
       
  1450 	ConnectData  *connect_data = NULL;
       
  1451 	
       
  1452 	iLog->Log ( _L ( "In lm_connection_close" ) );
       
  1453 	
       
  1454 	// Read data from the CFG file
       
  1455 	if ( read_data ( connect_data, aItem ) != RC_OK )
       
  1456 		{
       
  1457 		iLog->Log ( _L ( "read_data failed" ) );
       
  1458 		free_data ( connect_data );
       
  1459 		return KErrGeneral;
       
  1460 		}
       
  1461 	
       
  1462 	// Open a new closed connection	
       
  1463 	connection = lm_connection_new ( connect_data->server );
       
  1464 	if ( !connection )
       
  1465 		{
       
  1466 		iLog->Log ( _L ( "lm_connection_new failed" ) );
       
  1467 		free_data ( connect_data );
       
  1468 		return KErrGeneral;
       
  1469 		}
       
  1470 	
       
  1471 		
       
  1472 	if ( lm_connection_close ( connection, NULL ) == TRUE )
       
  1473 	    {
       
  1474 		iLog->Log ( _L ( "lm_connection_close failed" ) );
       
  1475 		lm_connection_unref ( connection );
       
  1476 		return KErrGeneral;
       
  1477 	    }
       
  1478 	
       
  1479 	lm_connection_unref ( connection );
       
  1480 	free_data ( connect_data );
       
  1481 	iLog->Log ( _L ( "lm_connection_closeWhenNotOpenedL passed" ) );
       
  1482 	
       
  1483 	return KErrNone;
       
  1484     }
       
  1485 
       
  1486 
       
  1487 
       
  1488 
       
  1489 
       
  1490 //-----------------------------------------------------------------------------
       
  1491 // Ctstlm::lm_authenticateL
       
  1492 // Description	  : Tries to authenticate a user against the server
       
  1493 // Arguements	  :
       
  1494 //	 connnection  : LmConnection to authenticate
       
  1495 //	 username     : Username used to authenticate
       
  1496 //	 password     : Password corresponding to username
       
  1497 //	 resource     : Resource used for this connection
       
  1498 //	 function     : Callback function called when authentication is finished
       
  1499 //   user_data    : Userdata passed to callback function when called
       
  1500 //   notify       : Function for freeing user_data, can be NULL
       
  1501 //   error        : location to store error, or NULL
       
  1502 // Returns        : TRUE if no errors were detected, FALSE otherwise
       
  1503 // Requieres      : This test case requires GUI for selecting Access point
       
  1504 //-----------------------------------------------------------------------------
       
  1505 //
       
  1506 TInt Ctstlm::lm_authenticateL ( CStifItemParser& aItem )
       
  1507     {
       
  1508 	LmConnection *connection   = NULL;	
       
  1509 	AuthData     *auth_data    = NULL;
       
  1510 		
       
  1511 	iLog->Log ( _L ( "In lm_authenticateL" ) );	
       
  1512 
       
  1513 	auth_data = g_new0 ( AuthData, 1 );
       
  1514 	if ( !auth_data )
       
  1515 		{
       
  1516 		iLog->Log ( _L ( "memory allocation failed for auth_data" ) );
       
  1517 		return KErrGeneral;
       
  1518 		}	
       
  1519 		
       
  1520 	if ( read_data ( auth_data->connect_data, aItem ) != RC_OK )
       
  1521 		{
       
  1522 		iLog->Log ( _L ( "read_data failed" ) );		
       
  1523 		free_data ( auth_data->connect_data );		
       
  1524 		g_free ( auth_data );
       
  1525 		return KErrGeneral;
       
  1526 		}
       
  1527 	
       
  1528 	auth_data->main_loop    = g_main_loop_new ( NULL, FALSE );	
       
  1529 	auth_data->rCode        = RC_ERROR;
       
  1530 	connection = lm_connection_new ( auth_data->connect_data->server );
       
  1531 	if ( connection == NULL )
       
  1532 	    {
       
  1533 	    iLog->Log ( _L ( "lm_connection_new failed" ) );
       
  1534 	    free_data ( auth_data->connect_data );
       
  1535 	    g_main_loop_unref ( auth_data->main_loop );
       
  1536 	    g_free ( auth_data );
       
  1537 	    return KErrGeneral;
       
  1538 	    }
       
  1539 	
       
  1540 	lm_connection_set_port ( connection, GTALK_SSL_PORT );
       
  1541 	lm_connection_set_jid ( connection, auth_data->connect_data->username );
       
  1542 
       
  1543 #ifdef __WINSCW__
       
  1544 	SetProxy ( connection, auth_data->connect_data->proxy_data );
       
  1545 #endif
       
  1546 	SSLInit ( connection );
       
  1547 	
       
  1548 	if ( !lm_connection_open ( connection, 
       
  1549 	                           ( LmResultFunction ) auth_in_connection_cb,
       
  1550 	                           auth_data, 
       
  1551 	                           NULL, 
       
  1552 	                           NULL ) )                          
       
  1553 	    {
       
  1554 		iLog->Log ( _L ( "lm_connection_open failed" ) );
       
  1555 		free_data ( auth_data->connect_data );
       
  1556 		g_main_loop_unref ( auth_data->main_loop );
       
  1557 		g_free ( auth_data );
       
  1558 		return KErrGeneral;
       
  1559 	    }	   
       
  1560 	                                    
       
  1561 	
       
  1562 	g_main_loop_run ( auth_data->main_loop );
       
  1563 	g_main_loop_unref ( auth_data->main_loop );
       
  1564 	
       
  1565 	lm_connection_close ( connection, NULL );
       
  1566 	lm_connection_unref ( connection );
       
  1567 	free_data ( auth_data->connect_data );	
       
  1568 	
       
  1569 	if ( auth_data->rCode != RC_OK )
       
  1570 	    {
       
  1571 	    iLog->Log ( _L ( "lm_authenticateL failed" ) );
       
  1572 	    g_free ( auth_data );
       
  1573 	    return KErrGeneral;
       
  1574 	    }
       
  1575 	
       
  1576 	g_free ( auth_data );
       
  1577 
       
  1578 	iLog->Log ( _L ( "lm_authenticateL passed" ) );
       
  1579 	
       
  1580 	return KErrNone;		
       
  1581     }
       
  1582 
       
  1583 //-----------------------------------------------------------------------------
       
  1584 // Ctstlm::lm_connection_is_open
       
  1585 // Description  : Check if connection is currently open or not
       
  1586 // Arguements   :
       
  1587 //   connection	: an LmConnection to check if it is open
       
  1588 // Returns      : TRUE if connection is open and FALSE if it is closed
       
  1589 //-----------------------------------------------------------------------------
       
  1590 //
       
  1591 TInt Ctstlm::lm_connection_is_openL ( CStifItemParser& aItem )
       
  1592     {
       
  1593 	LmConnection *connection   = NULL;
       
  1594 	ConnectData  *connect_data = NULL;
       
  1595 	gboolean NotOpen           = FALSE;	
       
  1596 	
       
  1597 	iLog->Log ( _L ( "In lm_connection_is_open" ) );
       
  1598 	
       
  1599 	// Read data from the CFG file
       
  1600 	if ( read_data ( connect_data, aItem ) != RC_OK )
       
  1601 		{
       
  1602 		iLog->Log ( _L ( "read_data failed" ) );
       
  1603 		free_data ( connect_data );
       
  1604 		return KErrGeneral;
       
  1605 		}
       
  1606 		
       
  1607 	// Open a new closed connection
       
  1608 	connection = lm_connection_new ( connect_data->server );
       
  1609 	if ( !connection )
       
  1610 		{
       
  1611 		iLog->Log ( _L ( "lm_connection_new failed" ) );
       
  1612 		free_data ( connect_data );
       
  1613 		return KErrGeneral;
       
  1614 		}
       
  1615 	
       
  1616 	lm_connection_set_port ( connection, GTALK_SSL_PORT );
       
  1617 	lm_connection_set_jid ( connection, connect_data->username );
       
  1618 #ifdef __WINSCW__
       
  1619 	SetProxy ( connection, connect_data->proxy_data );
       
  1620 #endif
       
  1621 	SSLInit ( connection );
       
  1622 	
       
  1623 	// Check for connection in case of connection not yet opened
       
  1624 	if ( !lm_connection_is_open ( connection ) )
       
  1625 	    {
       
  1626 		iLog->Log ( _L ( "Connection is not open" ) );
       
  1627 		NotOpen = TRUE;
       
  1628 	    }	
       
  1629 	
       
  1630 	// Check for open connection in case of connection opened	
       
  1631 	GMainLoop	*main_loop = g_main_loop_new ( NULL, FALSE );
       
  1632 	iLog->Log ( _L ( "before lm_connection_open" ) );
       
  1633 	
       
  1634 	if ( !lm_connection_open ( connection, ( LmResultFunction ) connection_open_cb,
       
  1635 	                           main_loop, NULL, NULL ) ) 
       
  1636 	    {
       
  1637 		iLog->Log ( _L ( "lm_connection_open failed" ));
       
  1638 		lm_connection_unref ( connection );
       
  1639 		g_main_loop_unref ( main_loop );
       
  1640 		free_data ( connect_data );		
       
  1641 		return KErrGeneral;
       
  1642 	    }
       
  1643 		
       
  1644 	iLog->Log ( _L ( "after lm_connection_open" ) );	
       
  1645 	g_main_loop_run ( main_loop );
       
  1646 	g_main_loop_unref ( main_loop ); 
       
  1647 	
       
  1648 	if ( !lm_connection_is_open ( connection ) && FALSE == NotOpen )
       
  1649 	    {
       
  1650 		iLog->Log ( _L ( "lm_connection_is_open failed" ) );
       
  1651 		free_data ( connect_data );
       
  1652 		return KErrGeneral;
       
  1653 	    }	
       
  1654 	
       
  1655 	lm_connection_close ( connection, NULL );
       
  1656 	lm_connection_unref ( connection );
       
  1657 	free_data ( connect_data );	
       
  1658 	
       
  1659 	iLog->Log ( _L ( "lm_connection_is_open passed" ) );
       
  1660 	
       
  1661 	return KErrNone;
       
  1662 	}
       
  1663 /////////////////////////////////////////////////////////
       
  1664 //-----------------------------------------------------------------------------
       
  1665 // Ctstlm::lm_connection_is_open_WhenConnectionIsClosedL
       
  1666 // Description  : Check if connection is currently open or not
       
  1667 // Arguements   :
       
  1668 //   connection	: an LmConnection to check if it is open
       
  1669 // Returns      : TRUE if connection is open and FALSE if it is closed
       
  1670 //-----------------------------------------------------------------------------
       
  1671 //
       
  1672 TInt Ctstlm::lm_connection_is_open_WhenConnectionIsClosedL ( CStifItemParser& aItem )
       
  1673     {
       
  1674 	LmConnection *connection   = NULL;
       
  1675 	ConnectData  *connect_data = NULL;
       
  1676 	gboolean NotOpen           = FALSE;	
       
  1677 	
       
  1678 	iLog->Log ( _L ( "lm_connection_is_open_WhenConnectionIsClosedL" ) );
       
  1679 	
       
  1680 	// Read data from the CFG file
       
  1681 	if ( read_data ( connect_data, aItem ) != RC_OK )
       
  1682 		{
       
  1683 		iLog->Log ( _L ( "read_data failed" ) );
       
  1684 		free_data ( connect_data );
       
  1685 		return KErrGeneral;
       
  1686 		}
       
  1687 		
       
  1688 	// Open a new closed connection
       
  1689 	connection = lm_connection_new ( connect_data->server );
       
  1690 	if ( !connection )
       
  1691 		{
       
  1692 		iLog->Log ( _L ( " lm_connection_is_open" ) );
       
  1693 		free_data ( connect_data );
       
  1694 		return KErrGeneral;
       
  1695 		}
       
  1696 		
       
  1697 	if ( lm_connection_is_open ( connection )  )
       
  1698 	    {
       
  1699 		iLog->Log ( _L ( "lm_connection_is_open_WhenConnectionIsClosedL failed" ) );
       
  1700 		free_data ( connect_data );
       
  1701 		return KErrGeneral;
       
  1702 	    }	
       
  1703 	
       
  1704 	lm_connection_close ( connection, NULL );
       
  1705 	lm_connection_unref ( connection );
       
  1706 	free_data ( connect_data );	
       
  1707 	
       
  1708 	iLog->Log ( _L ( "lm_connection_is_open_WhenConnectionIsClosedL passed" ) );
       
  1709 	
       
  1710 	return KErrNone;
       
  1711 	}
       
  1712 
       
  1713 
       
  1714 
       
  1715 //-----------------------------------------------------------------------------
       
  1716 // Ctstlm::lm_connection_is_authenticated
       
  1717 // Description  : Check if connection is authenticated or not
       
  1718 // Arguements   :
       
  1719 //   connection	: an LmConnection to check 
       
  1720 // Returns      : TRUE if connection is authenticated, FALSE otherwise
       
  1721 //-----------------------------------------------------------------------------
       
  1722 //
       
  1723 TInt Ctstlm::lm_is_authenticatedL ( CStifItemParser& aItem )
       
  1724     {
       
  1725     LmConnection *connection       = NULL;
       
  1726     ConnectData  *connect_data     = NULL;
       
  1727     gboolean     NotAuthenticated  = FALSE;    
       
  1728     
       
  1729     iLog->Log ( _L ( "In lm_connection_is_authenticated" ) );
       
  1730     
       
  1731     // Read data from the CFG file
       
  1732     if ( read_data ( connect_data, aItem ) != RC_OK )
       
  1733     	{
       
  1734     	iLog->Log ( _L ( "read_data failed" ) );
       
  1735     	free_data ( connect_data );
       
  1736     	return KErrGeneral;
       
  1737     	}    
       
  1738     
       
  1739     // Open a new closed connection
       
  1740     connection = lm_connection_new ( connect_data->server );
       
  1741     if ( !connection )
       
  1742     	{
       
  1743     	iLog->Log ( _L ( "lm_connection_new failed" ) );
       
  1744     	free_data ( connect_data );
       
  1745     	return KErrGeneral;
       
  1746     	}
       
  1747     
       
  1748     // Set the connection to use gtalk's SSL port
       
  1749     lm_connection_set_port ( connection, GTALK_SSL_PORT );
       
  1750     
       
  1751     // Set the JID to be used for connection 
       
  1752     lm_connection_set_jid ( connection, connect_data->username );
       
  1753 	
       
  1754 	// Proxy settings for Emulator
       
  1755 #ifdef __WINSCW__
       
  1756 	SetProxy ( connection, connect_data->proxy_data );
       
  1757 #endif
       
  1758 
       
  1759 	// Set the connection to use SSL
       
  1760 	SSLInit ( connection );
       
  1761 	
       
  1762     // Open a connection
       
  1763     GMainLoop	*main_loop = g_main_loop_new ( NULL, FALSE );
       
  1764 	iLog->Log ( _L ( "before lm_connection_open" ) );
       
  1765 	
       
  1766 	if ( !lm_connection_open ( connection, ( LmResultFunction ) connection_open_cb,
       
  1767 	                           main_loop, NULL, NULL ) ) 
       
  1768 	    {
       
  1769 		iLog->Log ( _L ( "lm_connection_open failed" ));
       
  1770 		lm_connection_unref ( connection );
       
  1771 		g_main_loop_unref ( main_loop );
       
  1772 		free_data ( connect_data );		
       
  1773 		return KErrGeneral;
       
  1774 	    }
       
  1775 		
       
  1776 	iLog->Log ( _L ( "after lm_connection_open" ) );	
       
  1777 	g_main_loop_run ( main_loop );
       
  1778 	g_main_loop_unref ( main_loop ); 
       
  1779 	
       
  1780     
       
  1781     // Check for authentication before the connection is authenticated
       
  1782     if ( !lm_connection_is_authenticated ( connection ) )
       
  1783         {
       
  1784     	iLog->Log ( _L ( "Connection not yet authenticated" ) );
       
  1785     	NotAuthenticated = TRUE;
       
  1786         }
       
  1787     
       
  1788     // Authenticate the connection
       
  1789     main_loop = g_main_loop_new ( NULL, FALSE );
       
  1790 	
       
  1791 	// Get the username from the JID
       
  1792 	gchar *username = get_user_name ( connect_data->username );
       
  1793 	
       
  1794 	// Authenticate with the server
       
  1795 	if ( !lm_connection_authenticate ( connection,
       
  1796                                      username,
       
  1797                                      connect_data->password,
       
  1798                                      connect_data->resource,
       
  1799                                       ( LmResultFunction ) connection_auth_cb,
       
  1800                                      main_loop,NULL,NULL ) )
       
  1801 	    {
       
  1802 		iLog->Log ( _L ( "lm_connection_authenticate failed" ) );
       
  1803 		lm_connection_close ( connection, NULL );
       
  1804 		lm_connection_unref ( connection );
       
  1805 		free_data ( connect_data );
       
  1806 		g_main_loop_unref ( main_loop );
       
  1807 		g_free ( username );
       
  1808 		return KErrGeneral;
       
  1809 	    }
       
  1810 
       
  1811 	g_main_loop_run ( main_loop );
       
  1812 	g_main_loop_unref ( main_loop );
       
  1813     g_free ( username );
       
  1814     
       
  1815     // Check for authentication after the connection is authenticated
       
  1816     if ( !lm_connection_is_authenticated ( connection ) && 
       
  1817           FALSE == NotAuthenticated )
       
  1818         {
       
  1819     	iLog->Log ( _L ( "lm_connection_is_authenticated failed" ) );    	
       
  1820     	lm_connection_close ( connection, NULL );
       
  1821     	lm_connection_unref ( connection );
       
  1822     	free_data ( connect_data );
       
  1823     	return KErrGeneral;
       
  1824         }    
       
  1825     
       
  1826     lm_connection_close ( connection, NULL );
       
  1827     lm_connection_unref ( connection );
       
  1828     free_data ( connect_data );
       
  1829     
       
  1830     iLog->Log ( _L ( "lm_connection_is_authenticated passed" ) );
       
  1831     
       
  1832     return KErrNone;  
       
  1833     }
       
  1834 
       
  1835 
       
  1836 
       
  1837 
       
  1838 //-----------------------------------------------------------------------------
       
  1839 // Ctstlm::lm_connection_set_get_server
       
  1840 // Description  : Sets the server address for connection to server. Notice that
       
  1841 //                connection can't be open while doing this.
       
  1842 // Arguements   :
       
  1843 //   connection	: an LmConnection
       
  1844 //   server     : Address of the server ( name of the server )
       
  1845 // Returns      : None
       
  1846 //-----------------------------------------------------------------------------
       
  1847 //
       
  1848 TInt Ctstlm::lm_connection_set_get_serverL ( CStifItemParser& aItem )
       
  1849     {
       
  1850     LmConnection *connection   = NULL;
       
  1851     gchar        *ServerName   = "ganapati.nokia.com";
       
  1852     ConnectData  *connect_data = NULL;
       
  1853     gchar        *NewServerName;
       
  1854     
       
  1855     iLog->Log ( _L ( "In lm_connection_set_server" ) );
       
  1856     
       
  1857     // Read data from the CFG file
       
  1858     if ( read_data ( connect_data, aItem ) != RC_OK )
       
  1859     	{
       
  1860     	iLog->Log ( _L ( "read_data failed" ) );
       
  1861     	free_data ( connect_data );
       
  1862     	return KErrGeneral;
       
  1863     	}
       
  1864     
       
  1865     // Open a new closed connection
       
  1866     connection = lm_connection_new ( connect_data->server );
       
  1867     if ( !connection )
       
  1868     	{
       
  1869     	iLog->Log ( _L ( " lm_connection_new failed" ) );
       
  1870     	free_data ( connect_data );
       
  1871     	return KErrGeneral;
       
  1872     	}
       
  1873     	
       
  1874     
       
  1875     
       
  1876     // Set the servers name before the connection
       
  1877     lm_connection_set_server ( connection, ServerName );
       
  1878     
       
  1879     // Verify the server name
       
  1880     NewServerName = (gchar *)lm_connection_get_server ( connection );
       
  1881     
       
  1882     if ( strcmp ( NewServerName, ServerName ) != 0 )
       
  1883         {
       
  1884     	iLog->Log ( _L ( "lm_connection_set_server failed" ) );    	
       
  1885     	lm_connection_unref ( connection );    	
       
  1886     	return KErrGeneral;
       
  1887         }
       
  1888          
       
  1889     lm_connection_unref ( connection );            
       
  1890     free_data ( connect_data );
       
  1891     // Server name modified successfully
       
  1892     iLog->Log ( _L ( "lm_connection_set_server passed" ) );        
       
  1893     
       
  1894     return KErrNone;    	
       
  1895     }
       
  1896 
       
  1897 
       
  1898 //-----------------------------------------------------------------------------
       
  1899 // Ctstlm:lm_connection_set_server_WithNULL 
       
  1900 // Description  : Sets the server address for connection to server. Notice that
       
  1901 //                connection can't be open while doing this.
       
  1902 // Arguements   :
       
  1903 //   connection	: an LmConnection
       
  1904 //   server     : Address of the server ( name of the server )
       
  1905 // Returns      : None
       
  1906 //-----------------------------------------------------------------------------
       
  1907 //
       
  1908 TInt Ctstlm::lm_connection_set_server_WithNULL ( CStifItemParser& aItem )
       
  1909     {
       
  1910     LmConnection *connection   = NULL;
       
  1911     gchar        *ServerName   = "\0";
       
  1912     ConnectData  *connect_data = NULL;
       
  1913     gchar        *NewServerName;
       
  1914     
       
  1915     iLog->Log ( _L ( "In lm_connection_set_server" ) );
       
  1916     
       
  1917     // Read data from the CFG file
       
  1918     if ( read_data ( connect_data, aItem ) != RC_OK )
       
  1919     	{
       
  1920     	iLog->Log ( _L ( "read_data failed" ) );
       
  1921     	free_data ( connect_data );
       
  1922     	return KErrGeneral;
       
  1923     	}
       
  1924     
       
  1925     // Open a new closed connection
       
  1926     connection = lm_connection_new ( connect_data->server );
       
  1927     if ( !connection )
       
  1928     	{
       
  1929     	iLog->Log ( _L ( " lm_connection_new failed" ) );
       
  1930     	free_data ( connect_data );
       
  1931     	return KErrGeneral;
       
  1932     	}
       
  1933     	
       
  1934     
       
  1935     
       
  1936     // Set the servers name before the connection
       
  1937     lm_connection_set_server ( connection, ServerName );
       
  1938     
       
  1939     // Verify the server name
       
  1940     NewServerName = (gchar *)lm_connection_get_server ( connection );
       
  1941     
       
  1942     if ( strcmp ( NewServerName, ServerName ) != 0 )
       
  1943         {
       
  1944     	iLog->Log ( _L ( "lm_connection_set_server failed" ) );    	
       
  1945     	lm_connection_unref ( connection );    	
       
  1946     	return KErrGeneral;
       
  1947         }
       
  1948          
       
  1949     lm_connection_unref ( connection );            
       
  1950     free_data ( connect_data );
       
  1951     // Server name modified successfully
       
  1952     iLog->Log ( _L ( "lm_connection_set_server passed" ) );        
       
  1953     
       
  1954     return KErrNone;    	
       
  1955     }
       
  1956 
       
  1957 //-----------------------------------------------------------------------------
       
  1958 // Ctstlm::lm_connection_set_get_jid
       
  1959 // Description  : Sets the JID to be used for connection
       
  1960 // Arguements   :
       
  1961 //   connection	: an LmConnection
       
  1962 //   jid        : JID to be used for connection
       
  1963 // Returns      : None
       
  1964 //-----------------------------------------------------------------------------
       
  1965 //
       
  1966 TInt Ctstlm::lm_connection_set_get_jidL ( CStifItemParser& aItem )
       
  1967     {
       
  1968 	LmConnection *connection   = NULL;
       
  1969 	ConnectData  *connect_data = NULL;
       
  1970 	gchar *Jid                 = "connect.nokia.com";
       
  1971 	const gchar *GetJid        = NULL;
       
  1972 	
       
  1973 	iLog->Log ( _L ( "In lm_connection_set_jid" ) );
       
  1974 	
       
  1975 	// Read data from the CFG file
       
  1976 	if ( read_data ( connect_data, aItem ) != RC_OK )
       
  1977 		{
       
  1978 		iLog->Log ( _L ( "read_data failed" ) );
       
  1979 		free_data ( connect_data );
       
  1980 		return KErrGeneral;
       
  1981 		}
       
  1982 	
       
  1983 	// Open a new close connection
       
  1984 	connection = lm_connection_new ( connect_data->server );
       
  1985 	if ( !connection )
       
  1986 		{
       
  1987 		iLog->Log ( _L ( "lm_connection_new failed" ) );
       
  1988 		free_data ( connect_data );
       
  1989 		return KErrGeneral;
       
  1990 		}
       
  1991 	
       
  1992 	// Set new jid
       
  1993 	Jid = g_strdup_printf ( "%s@%s", connect_data->username, connect_data->server );
       
  1994 	lm_connection_set_jid ( connection, Jid );
       
  1995 	
       
  1996 	
       
  1997 	// Verify the Jid
       
  1998 	GetJid = lm_connection_get_jid ( connection );
       
  1999 	if ( strcmp ( Jid, GetJid ) != 0 )
       
  2000 	    {
       
  2001 		iLog->Log ( _L ( "lm_connection_set_jid failed" ) );
       
  2002 		lm_connection_unref ( connection );
       
  2003 		return KErrGeneral;
       
  2004 	    }
       
  2005 	
       
  2006 	// Remove a referece on connection
       
  2007 	lm_connection_unref ( connection );
       
  2008 	free_data ( connect_data );
       
  2009 	iLog->Log ( _L ( "lm_connection_set_jid passed" ) );
       
  2010 	
       
  2011 	return KErrNone;
       
  2012     }
       
  2013 
       
  2014 
       
  2015 //-----------------------------------------------------------------------------
       
  2016 // Ctstlm::lm_connection_set_jid_WithNULL
       
  2017 // Description  : Sets the JID to be used for connection
       
  2018 // Arguements   :
       
  2019 //   connection	: an LmConnection
       
  2020 //   jid        : JID to be used for connection
       
  2021 // Returns      : None
       
  2022 //-----------------------------------------------------------------------------
       
  2023 //
       
  2024 TInt Ctstlm::lm_connection_set_jid_WithNULL ( CStifItemParser& aItem )
       
  2025     {
       
  2026 	LmConnection *connection   = NULL;
       
  2027 	ConnectData  *connect_data = NULL;
       
  2028 	gchar *Jid                 = "\0";
       
  2029 	const gchar *GetJid        = NULL;
       
  2030 	
       
  2031 	iLog->Log ( _L ( "In lm_connection_set_jid" ) );
       
  2032 	
       
  2033 	// Read data from the CFG file
       
  2034 	if ( read_data ( connect_data, aItem ) != RC_OK )
       
  2035 		{
       
  2036 		iLog->Log ( _L ( "read_data failed" ) );
       
  2037 		free_data ( connect_data );
       
  2038 		return KErrGeneral;
       
  2039 		}
       
  2040 	
       
  2041 	// Open a new close connection
       
  2042 	connection = lm_connection_new ( connect_data->server );
       
  2043 	if ( !connection )
       
  2044 		{
       
  2045 		iLog->Log ( _L ( "lm_connection_new failed" ) );
       
  2046 		free_data ( connect_data );
       
  2047 		return KErrGeneral;
       
  2048 		}
       
  2049 	
       
  2050 	// Set new jid
       
  2051 	Jid = g_strdup_printf ( "%s@%s", connect_data->username, connect_data->server );
       
  2052 	lm_connection_set_jid ( connection, Jid );
       
  2053 	
       
  2054 	
       
  2055 	// Verify the Jid
       
  2056 	GetJid = lm_connection_get_jid ( connection );
       
  2057 	if ( strcmp ( Jid, GetJid ) != 0 )
       
  2058 	    {
       
  2059 		iLog->Log ( _L ( "lm_connection_set_jid failed" ) );
       
  2060 		lm_connection_unref ( connection );
       
  2061 		return KErrGeneral;
       
  2062 	    }
       
  2063 	
       
  2064 	// Remove a referece on connection
       
  2065 	lm_connection_unref ( connection );
       
  2066 	free_data ( connect_data );
       
  2067 	iLog->Log ( _L ( "lm_connection_set_jid passed" ) );
       
  2068 	
       
  2069 	return KErrNone;
       
  2070     }
       
  2071 
       
  2072 
       
  2073 
       
  2074 //-----------------------------------------------------------------------------
       
  2075 // Ctstlm::lm_connection_set_get_port
       
  2076 // Description  : Sets the port that connection will be using
       
  2077 // Arguements   :
       
  2078 //   connection	: an LmConnection
       
  2079 //   port       : server port
       
  2080 // Returns      : None 
       
  2081 //-----------------------------------------------------------------------------
       
  2082 //
       
  2083 TInt Ctstlm::lm_connection_set_get_portL ( CStifItemParser& /*aItem*/ )
       
  2084     {
       
  2085 	LmConnection *connection = NULL;
       
  2086 	guint        LmPort;	
       
  2087 	
       
  2088 	// Open a new closed connection
       
  2089 	connection = lm_connection_new ( NULL );
       
  2090 	if ( !connection )
       
  2091 		{
       
  2092 		iLog->Log ( _L ( "lm_connection_new failed" ) );
       
  2093 		return KErrGeneral;
       
  2094 		}
       
  2095 	
       
  2096 	// Sets the port 
       
  2097 	lm_connection_set_port ( connection, MYPORT );
       
  2098 	
       
  2099 	// Get the port
       
  2100 	LmPort = lm_connection_get_port ( connection );
       
  2101 	
       
  2102 	// Verify the port used by the connection 	
       
  2103 	if ( LmPort != MYPORT )
       
  2104 	    {
       
  2105 		iLog->Log ( _L ( "lm_connection_set_port failed" ) );
       
  2106 		lm_connection_unref ( connection );
       
  2107 		return KErrGeneral;
       
  2108 	    }
       
  2109 	
       
  2110 	// Remove a reference on connection
       
  2111 	lm_connection_unref ( connection );
       
  2112 	
       
  2113 	iLog->Log ( _L ( "lm_connection_set_port passed" ) );
       
  2114 	
       
  2115 	return KErrNone;	
       
  2116     }
       
  2117 
       
  2118 
       
  2119 //-----------------------------------------------------------------------------
       
  2120 // Ctstlm::lm_connection_set_port_WithNULL
       
  2121 // Description  : Sets the port that connection will be using
       
  2122 // Arguements   :
       
  2123 //   connection	: an LmConnection
       
  2124 //   port       : server port
       
  2125 // Returns      : None 
       
  2126 //-----------------------------------------------------------------------------
       
  2127 //
       
  2128 TInt Ctstlm::lm_connection_set_port_WithNULL ( CStifItemParser& /*aItem*/ )
       
  2129     {
       
  2130 	LmConnection *connection = NULL;
       
  2131 	guint        LmPort;	
       
  2132 	
       
  2133 	// Open a new closed connection
       
  2134 	connection = lm_connection_new ( NULL );
       
  2135 	if ( !connection )
       
  2136 		{
       
  2137 		iLog->Log ( _L ( "lm_connection_new failed" ) );
       
  2138 		return KErrGeneral;
       
  2139 		}
       
  2140 	
       
  2141 	// Sets the port 
       
  2142 	lm_connection_set_port ( connection, FAKEPORT );
       
  2143 	
       
  2144 	// Get the port
       
  2145 	LmPort = lm_connection_get_port ( connection );
       
  2146 	
       
  2147 	// Verify the port used by the connection 	
       
  2148 	if ( LmPort != FAKEPORT )
       
  2149 	    {
       
  2150 		iLog->Log ( _L ( "lm_connection_set_port failed" ) );
       
  2151 		lm_connection_unref ( connection );
       
  2152 		return KErrGeneral;
       
  2153 	    }
       
  2154 	
       
  2155 	// Remove a reference on connection
       
  2156 	lm_connection_unref ( connection );
       
  2157 	
       
  2158 	iLog->Log ( _L ( "lm_connection_set_port passed" ) );
       
  2159 	
       
  2160 	return KErrNone;	
       
  2161     }
       
  2162 
       
  2163 //-----------------------------------------------------------------------------
       
  2164 // Ctstlm::lm_connection_set_get_ssl
       
  2165 // Description  : Sets SSL struct or unset if ssl is NULL.
       
  2166 //                If set connection will use SSL for the connection
       
  2167 // Arguements   :
       
  2168 //   connection	: an LmConnection
       
  2169 //   ssl        : an LmSSL
       
  2170 // Returns      : None
       
  2171 //-----------------------------------------------------------------------------
       
  2172 //
       
  2173 TInt Ctstlm::lm_connection_set_get_sslL ( CStifItemParser& /*aItem*/ )
       
  2174     {
       
  2175     LmConnection *connection = NULL;
       
  2176     LmSSL        *ssl        = NULL;
       
  2177     
       
  2178     iLog->Log ( _L ( "In lm_connection_set_ssl" ) );
       
  2179     
       
  2180     if ( lm_ssl_is_supported() )
       
  2181         {       
       
  2182         connection = lm_connection_new ( NULL );
       
  2183     
       
  2184         ssl = lm_ssl_new ( NULL, NULL, NULL, NULL );
       
  2185     
       
  2186         lm_connection_set_ssl ( connection, ssl );
       
  2187         lm_ssl_unref ( ssl );
       
  2188     
       
  2189         if ( !lm_connection_get_ssl ( connection ) )
       
  2190             {
       
  2191     	    iLog->Log ( _L ( "lm_connection_set_ssl failed" ) );
       
  2192     	    lm_connection_unref ( connection );    	    
       
  2193     	    return KErrGeneral;    
       
  2194             }
       
  2195         
       
  2196         lm_connection_unref ( connection );            
       
  2197         
       
  2198         iLog->Log ( _L ( "lm_connection_set_ssl passed" ) );
       
  2199         
       
  2200         return KErrNone;        
       
  2201         }
       
  2202     
       
  2203     iLog->Log ( _L ( "ssl not supported" ) );           
       
  2204     
       
  2205     return KErrNone;    		    
       
  2206     }
       
  2207 
       
  2208 //-----------------------------------------------------------------------------
       
  2209 // Ctstlm::lm_connection_set_ssl_WithNULL
       
  2210 // Description  : Sets SSL struct or unset if ssl is NULL.
       
  2211 //                If set connection will use SSL for the connection
       
  2212 // Arguements   :
       
  2213 //   connection	: an LmConnection
       
  2214 //   ssl        : an LmSSL
       
  2215 // Returns      : None
       
  2216 //-----------------------------------------------------------------------------
       
  2217 //
       
  2218 TInt Ctstlm::lm_connection_set_ssl_WithNULL ( CStifItemParser& /*aItem*/ )
       
  2219     {
       
  2220     LmConnection *connection = NULL;
       
  2221     LmSSL        *ssl        = NULL;
       
  2222     
       
  2223     iLog->Log ( _L ( "In lm_connection_set_ssl" ) );
       
  2224     
       
  2225     if ( lm_ssl_is_supported() )
       
  2226         {       
       
  2227         connection = lm_connection_new ( NULL );
       
  2228     
       
  2229         ssl = lm_ssl_new ( NULL, NULL, NULL, NULL );
       
  2230     
       
  2231         lm_connection_set_ssl ( connection, ssl );
       
  2232         lm_ssl_unref ( ssl );
       
  2233     
       
  2234         if ( !lm_connection_get_ssl ( connection ) )
       
  2235             {
       
  2236     	    iLog->Log ( _L ( "lm_connection_set_ssl failed" ) );
       
  2237     	    lm_connection_unref ( connection );    	    
       
  2238     	    return KErrGeneral;    
       
  2239             }
       
  2240         
       
  2241         lm_connection_unref ( connection );            
       
  2242         
       
  2243         iLog->Log ( _L ( "lm_connection_set_ssl passed" ) );
       
  2244         
       
  2245         return KErrNone;        
       
  2246         }
       
  2247     
       
  2248     iLog->Log ( _L ( "ssl not supported" ) );           
       
  2249     
       
  2250     return KErrNone;    		    
       
  2251     }
       
  2252 
       
  2253 
       
  2254 
       
  2255 //-----------------------------------------------------------------------------
       
  2256 // Ctstlm::lm_connection_set_get_proxy
       
  2257 // Description  : Sets the proxy to use for this connection. To unset pass NULL
       
  2258 // Arguements   :
       
  2259 //   connection	: an LmConnection
       
  2260 //   proxy      : an LmProxy
       
  2261 // Returns      : None
       
  2262 //-----------------------------------------------------------------------------
       
  2263 //
       
  2264 TInt Ctstlm::lm_connection_set_get_proxyL ( CStifItemParser& /*aItem*/ )
       
  2265     {
       
  2266     LmConnection *connection;
       
  2267     LmProxy      *Proxy;    
       
  2268     
       
  2269     iLog->Log ( _L ( "In lm_connection_set_proxy" ) );
       
  2270     
       
  2271     connection = lm_connection_new ( NULL );
       
  2272 
       
  2273     Proxy = lm_proxy_new ( LM_PROXY_TYPE_HTTP );
       
  2274     
       
  2275     // Set proxy 
       
  2276     lm_connection_set_proxy ( connection, Proxy );
       
  2277     lm_proxy_unref ( Proxy );
       
  2278     
       
  2279     // Verify proxy setttings
       
  2280     if ( !lm_connection_get_proxy ( connection ) )
       
  2281         {
       
  2282     	iLog->Log ( _L ( "lm_connection_set_proxy failed" ) );
       
  2283     	lm_connection_unref ( connection );
       
  2284     	return KErrGeneral;
       
  2285         }    
       
  2286     
       
  2287     lm_connection_unref ( connection );
       
  2288     
       
  2289     iLog->Log ( _L ( "lm_connection_set_proxy passed") );
       
  2290     
       
  2291     return KErrNone;    
       
  2292     }
       
  2293 
       
  2294 
       
  2295 //-----------------------------------------------------------------------------
       
  2296 // Ctstlm::lm_connection_sendL
       
  2297 // Description  : Asynchronous call to send a message
       
  2298 // Arguements   :
       
  2299 //   connection	: an LmConnection used to send message
       
  2300 //   message    : LmMessage to send
       
  2301 //   error      : location to store error, or NULL
       
  2302 // Returns      : Returns TRUE if no errors were detected while sending,
       
  2303 //                FALSE otherwise
       
  2304 //-----------------------------------------------------------------------------
       
  2305 // 
       
  2306 TInt Ctstlm::lm_connection_sendL ( CStifItemParser& aItem )
       
  2307     {
       
  2308 	LmConnection *connection   = NULL;
       
  2309 	ConnectData  *connect_data = NULL;
       
  2310 	LmMessage    *message;
       
  2311 	
       
  2312 	iLog->Log ( _L ( "In lm_connection_send" ) );
       
  2313 	
       
  2314 	// Read a data from the CFG file
       
  2315 	if ( read_data ( connect_data, aItem ) != RC_OK )
       
  2316 		{
       
  2317 		iLog->Log ( _L ( "read_data failed" ) );
       
  2318 		free_data ( connect_data );
       
  2319 		return KErrGeneral;
       
  2320 		}
       
  2321 	iLog->Log ( _L ( "after read_data" ) );
       
  2322 	
       
  2323 	// Open a new closed connection
       
  2324 	connection = lm_connection_new ( connect_data->server );
       
  2325 	iLog->Log ( _L ( "after lm_connection_new " ) );
       
  2326 	if ( !connection )
       
  2327 		{
       
  2328 		iLog->Log ( _L ( "lm_connection_new failed" ) );
       
  2329 		free_data ( connect_data );
       
  2330 		return KErrGeneral;
       
  2331 		}
       
  2332 	
       
  2333 	// Set the gtalk's SSL port
       
  2334 	lm_connection_set_port ( connection, GTALK_SSL_PORT );
       
  2335 	
       
  2336 	// Set the JID
       
  2337 	lm_connection_set_jid ( connection, connect_data->username );
       
  2338 	
       
  2339 	// Proxy settings for Emulator
       
  2340 #ifdef __WINSCW__
       
  2341 	SetProxy ( connection, connect_data->proxy_data );
       
  2342 #endif
       
  2343 	
       
  2344 	// Set the connection to use SSL
       
  2345 	SSLInit ( connection );
       
  2346 	
       
  2347 	GMainLoop	*main_loop = g_main_loop_new ( NULL, FALSE );
       
  2348 
       
  2349 	iLog->Log ( _L ( "before lm_connection_open" ) );
       
  2350 	
       
  2351 	if ( !lm_connection_open ( connection, ( LmResultFunction ) connection_open_cb,
       
  2352 	                           main_loop, NULL, NULL ) ) 
       
  2353 	    {
       
  2354 		iLog->Log ( _L ( "lm_connection_open failed" ));
       
  2355 		lm_connection_unref ( connection );
       
  2356 		g_main_loop_unref ( main_loop );
       
  2357 		free_data ( connect_data );		
       
  2358 		return KErrGeneral;
       
  2359 	    }
       
  2360 		
       
  2361 	iLog->Log ( _L ( "after lm_connection_open" ) );
       
  2362 	
       
  2363 	g_main_loop_run ( main_loop );
       
  2364 
       
  2365 	g_main_loop_unref ( main_loop );    
       
  2366 
       
  2367 	
       
  2368 	GMainLoop	*main_loop1 = g_main_loop_new ( NULL, FALSE );
       
  2369 	
       
  2370 	// Get the username from the JID
       
  2371 	gchar *username = get_user_name ( connect_data->username );
       
  2372 	
       
  2373 	// Authenticate with the server
       
  2374 	if ( !lm_connection_authenticate ( connection,
       
  2375                                      username,
       
  2376                                      connect_data->password,
       
  2377                                      connect_data->resource,
       
  2378                                       ( LmResultFunction ) connection_auth_cb,
       
  2379                                      main_loop1,NULL,NULL ) )
       
  2380 	    {
       
  2381 		iLog->Log ( _L ( "lm_connection_authenticate failed" ) );
       
  2382 		lm_connection_close ( connection, NULL );
       
  2383 		lm_connection_unref ( connection );
       
  2384 		free_data ( connect_data );
       
  2385 		g_main_loop_unref ( main_loop1 );
       
  2386 		g_free ( username );
       
  2387 		return KErrGeneral;
       
  2388 	    }
       
  2389 
       
  2390 	g_main_loop_run ( main_loop1 );
       
  2391 
       
  2392 	g_main_loop_unref ( main_loop1 );
       
  2393 	    
       
  2394 
       
  2395 	g_free ( username );
       
  2396 	
       
  2397 	// Construct a message
       
  2398 	message = lm_message_new ( connect_data->msg_data->recipient,               
       
  2399 	                           LM_MESSAGE_TYPE_MESSAGE );
       
  2400 	lm_message_node_add_child ( message->node, "body", 
       
  2401 	                            connect_data->msg_data->message);
       
  2402 	
       
  2403 	// Send message to the server
       
  2404 	if ( !lm_connection_send ( connection, message, NULL ) )
       
  2405 	    {
       
  2406 		iLog->Log ( _L ( "lm_connection_send failed" ) );
       
  2407 		lm_connection_close ( connection, NULL );
       
  2408 		lm_connection_unref ( connection );
       
  2409 		lm_message_unref ( message );
       
  2410 		free_data ( connect_data );		
       
  2411 		return KErrGeneral;
       
  2412 	    }	
       
  2413 	
       
  2414 	// Close the connection
       
  2415 	lm_connection_close ( connection, NULL );
       
  2416 	
       
  2417 	// Remove a reference on connection
       
  2418 	lm_connection_unref ( connection );
       
  2419 	
       
  2420 	// Remove a reference on message
       
  2421 	lm_message_unref ( message );
       
  2422 	
       
  2423 	free_data ( connect_data );
       
  2424 	
       
  2425 	// Message sending passed
       
  2426 	iLog->Log ( _L ( "lm_connection_send passed" ) );
       
  2427 	
       
  2428 	return KErrNone;
       
  2429 }
       
  2430 
       
  2431 
       
  2432 
       
  2433 //-----------------------------------------------------------------------------
       
  2434 // Ctstlm::lm_send_with_replyL
       
  2435 // Description  : Send a LmMessage which will result in a reply
       
  2436 // Arguements   :
       
  2437 //   connection	: an LmConnection used to send message
       
  2438 //   message    : LmMessage to send
       
  2439 //   handler    : LmMessageHandler that will be used when reply to a message
       
  2440 //                arrives
       
  2441 //   error      : location to store error, or NULL
       
  2442 // Returns      : Returns TRUE if no errors were detected while sending,
       
  2443 //                FALSE otherwise
       
  2444 //-----------------------------------------------------------------------------
       
  2445 //
       
  2446 TInt Ctstlm::lm_send_with_replyL ( CStifItemParser& aItem )
       
  2447     {
       
  2448 	LmConnection     *connection;
       
  2449 	ConnectData      *connect_data = NULL;
       
  2450 	LmMessage        *message;
       
  2451 	LmMessageNode    *q_node;
       
  2452 	LmMessageHandler *handler      = NULL;	
       
  2453 	
       
  2454 	iLog->Log ( _L ( "In lm_connection_send_with_reply" ) );
       
  2455 	
       
  2456 	// Read data from the CFG file
       
  2457 	if ( read_data ( connect_data, aItem ) != RC_OK )
       
  2458 		{
       
  2459 		iLog->Log ( _L ( "read_data failed" ) );
       
  2460 		free_data ( connect_data );
       
  2461 		return KErrGeneral;
       
  2462 		}	
       
  2463 	
       
  2464 	// Open a new closed connection
       
  2465 	connection = lm_connection_new ( connect_data->server );
       
  2466 	if ( !connection )
       
  2467 		{
       
  2468 		iLog->Log ( _L ( "lm_connection_new failed" ) );
       
  2469 		free_data ( connect_data );
       
  2470 		return KErrGeneral;
       
  2471 		}
       
  2472 	
       
  2473 	// Set the port to gtalk's SSL port
       
  2474 	lm_connection_set_port ( connection, GTALK_SSL_PORT );
       
  2475 	
       
  2476 	// Set the JID
       
  2477 	lm_connection_set_jid ( connection, connect_data->username );
       
  2478 	
       
  2479 	// Proxy settings for emulator
       
  2480 #ifdef __WINSCW__
       
  2481 	SetProxy ( connection, connect_data->proxy_data );
       
  2482 #endif
       
  2483 
       
  2484 	// Set the connection to use SSL
       
  2485 	SSLInit ( connection );
       
  2486 	
       
  2487 	// Open a connection with the server
       
  2488 	GMainLoop	*main_loop = g_main_loop_new ( NULL, FALSE );
       
  2489 	iLog->Log ( _L ( "before lm_connection_open" ) );
       
  2490 	
       
  2491 	if ( !lm_connection_open ( connection, ( LmResultFunction ) connection_open_cb,
       
  2492 	                           main_loop, NULL, NULL ) ) 
       
  2493 	    {
       
  2494 		iLog->Log ( _L ( "lm_connection_open failed" ));
       
  2495 		lm_connection_unref ( connection );
       
  2496 		g_main_loop_unref ( main_loop );
       
  2497 		free_data ( connect_data );		
       
  2498 		return KErrGeneral;
       
  2499 	    }
       
  2500 		
       
  2501 	iLog->Log ( _L ( "after lm_connection_open" ) );	
       
  2502 	g_main_loop_run ( main_loop );
       
  2503 	g_main_loop_unref ( main_loop ); 
       
  2504 	
       
  2505 	
       
  2506 	main_loop = g_main_loop_new ( NULL, FALSE );
       
  2507 	
       
  2508 	// Get the username from the JID
       
  2509 	gchar *username = get_user_name ( connect_data->username );
       
  2510 	
       
  2511 	// Authenticate with the server
       
  2512 	if ( !lm_connection_authenticate ( connection,
       
  2513                                      username,
       
  2514                                      connect_data->password,
       
  2515                                      connect_data->resource,
       
  2516                                       ( LmResultFunction )connection_auth_cb,
       
  2517                                      main_loop,NULL,NULL ) )
       
  2518 	    {
       
  2519 		iLog->Log ( _L ( "lm_connection_authenticate failed" ) );
       
  2520 		lm_connection_close ( connection, NULL );
       
  2521 		lm_connection_unref ( connection );
       
  2522 		free_data ( connect_data );
       
  2523 		g_main_loop_unref ( main_loop );
       
  2524 		g_free ( username );
       
  2525 		return KErrGeneral;
       
  2526 	    }
       
  2527 	g_main_loop_run ( main_loop );
       
  2528 	g_main_loop_unref ( main_loop );    
       
  2529 	g_free ( username );
       
  2530 	
       
  2531 	// Construct a message
       
  2532 	message = lm_message_new_with_sub_type ( NULL, 
       
  2533 	                                         LM_MESSAGE_TYPE_IQ,
       
  2534 	                                         LM_MESSAGE_SUB_TYPE_GET );	                                         
       
  2535 	q_node = lm_message_node_add_child ( message->node, "query", NULL );
       
  2536 	lm_message_node_set_attributes ( q_node, "xmlns", "jabber:iq:auth", NULL );
       
  2537 	lm_message_node_add_child ( q_node, "username", connect_data->username );
       
  2538 	
       
  2539 	main_loop = g_main_loop_new ( NULL, FALSE );                                         
       
  2540 	// Send message to the server
       
  2541 	handler = lm_message_handler_new ( handle_messages, main_loop, NULL );
       
  2542 	//we are sending a dummy username request to server and the server should reply with error or not supported message
       
  2543 	//we handle this in the handler and quit the mainloop.
       
  2544 	if ( !lm_connection_send_with_reply ( connection, message, handler, NULL ) ) 
       
  2545 	    {
       
  2546 		iLog->Log ( _L ( "lm_connection_send_with_reply failed" ) );
       
  2547 		lm_connection_close ( connection, NULL );
       
  2548 		lm_connection_unref ( connection );
       
  2549 		lm_message_unref ( message );
       
  2550 		lm_message_handler_unref ( handler );
       
  2551 		g_main_loop_unref ( main_loop );
       
  2552 		free_data ( connect_data );
       
  2553 		return KErrGeneral;
       
  2554 	    }	
       
  2555 	
       
  2556 	g_main_loop_run ( main_loop );
       
  2557 	g_main_loop_unref ( main_loop );
       
  2558 	
       
  2559 	lm_connection_close ( connection, NULL );
       
  2560 	lm_connection_unref ( connection );
       
  2561 	lm_message_unref ( message );
       
  2562 	lm_message_handler_unref ( handler );
       
  2563 	free_data ( connect_data );
       
  2564 	
       
  2565 	iLog->Log ( _L ( "lm_connection_send_with_reply passed" ) );
       
  2566 	
       
  2567 	return KErrNone;
       
  2568     }
       
  2569 
       
  2570 
       
  2571 //-----------------------------------------------------------------------------
       
  2572 // Ctstlm::register_message_handlerL
       
  2573 // Description  : Registers a LmMessageHandler to handle incoming messages of
       
  2574 //                certain type. 
       
  2575 // Arguements   :
       
  2576 //   connection	: Connection to register a handle for
       
  2577 //   handler    : Message handler to register
       
  2578 //   type       : Message type that handler will handle
       
  2579 //   priority   : The priority in which to call handler
       
  2580 // Returns      : None
       
  2581 //-----------------------------------------------------------------------------
       
  2582 //
       
  2583 TInt Ctstlm::register_message_handlerL ( CStifItemParser& aItem )
       
  2584     {
       
  2585 	LmConnection     *connection;
       
  2586 	ConnectData      *connect_data;
       
  2587 	LmMessage        *msg;
       
  2588 	LmMessageHandler *handler;
       
  2589 	HandleData       *handle_data;
       
  2590 	GMainLoop        *main_loop   = NULL;		
       
  2591 
       
  2592 	iLog->Log ( _L ( "In register_message_handlerL" ) );
       
  2593 	
       
  2594 	// Read data from the CFG file
       
  2595 	if ( read_data ( connect_data, aItem ) != RC_OK )
       
  2596 		{
       
  2597 		iLog->Log ( _L ( "read_data failed" ) );
       
  2598 		free_data ( connect_data );
       
  2599 		return KErrGeneral;
       
  2600 		}	
       
  2601 	
       
  2602 	// Create a new closed connection
       
  2603 	connection = lm_connection_new ( connect_data->server );
       
  2604 	if ( !connection )
       
  2605 		{
       
  2606 		iLog->Log ( _L ( "lm_connection_new failed" ) );
       
  2607 		free_data ( connect_data );
       
  2608 		return KErrGeneral;
       
  2609 		}
       
  2610 	
       
  2611 	lm_connection_set_port ( connection, GTALK_SSL_PORT );
       
  2612 	lm_connection_set_jid ( connection, connect_data->username );
       
  2613 	
       
  2614 #ifdef __WINSCW__
       
  2615 	SetProxy ( connection, connect_data->proxy_data );
       
  2616 #endif
       
  2617 
       
  2618 	SSLInit ( connection );
       
  2619 		
       
  2620 	// Open a connection with the server
       
  2621 	main_loop = g_main_loop_new ( NULL, FALSE );
       
  2622 	iLog->Log ( _L ( "before lm_connection_open" ) );
       
  2623 	
       
  2624 	if ( !lm_connection_open ( connection, 
       
  2625 								( LmResultFunction ) connection_open_cb,
       
  2626 	                           main_loop, NULL, NULL ) ) 
       
  2627 	    {
       
  2628 		iLog->Log ( _L ( "lm_connection_open failed" ));
       
  2629 		lm_connection_unref ( connection );
       
  2630 		g_main_loop_unref ( main_loop );
       
  2631 		free_data ( connect_data );		
       
  2632 		return KErrGeneral;
       
  2633 	    }
       
  2634 		
       
  2635 	iLog->Log ( _L ( "after lm_connection_open" ) );	
       
  2636 	g_main_loop_run ( main_loop );
       
  2637 	g_main_loop_unref ( main_loop ); 
       
  2638 	
       
  2639 	
       
  2640 	// Get the username from the JID
       
  2641 	gchar *username = get_user_name ( connect_data->username );
       
  2642 	
       
  2643 	main_loop = g_main_loop_new ( NULL, FALSE );
       
  2644 	// Authenticate with the server
       
  2645 	if ( !lm_connection_authenticate ( connection,
       
  2646                                      username,
       
  2647                                      connect_data->password,
       
  2648                                      connect_data->resource,
       
  2649                                       ( LmResultFunction )connection_auth_cb,
       
  2650                                      main_loop,NULL,NULL ) )
       
  2651 	    {
       
  2652 		iLog->Log ( _L ( "lm_connection_authenticate failed" ) );
       
  2653 		lm_connection_close ( connection, NULL );
       
  2654 		lm_connection_unref ( connection );
       
  2655 		free_data ( connect_data );
       
  2656 		g_main_loop_unref ( main_loop );
       
  2657 		g_free ( username );
       
  2658 		return KErrGeneral;
       
  2659 	    }
       
  2660 	g_main_loop_run ( main_loop );
       
  2661 	g_main_loop_unref ( main_loop );    
       
  2662 	g_free ( username );
       
  2663 	
       
  2664 	
       
  2665 	main_loop = g_main_loop_new ( NULL, FALSE );
       
  2666 	handle_data = g_new0 ( HandleData, 1 );
       
  2667 	if ( !handle_data )
       
  2668 		{
       
  2669 		iLog->Log ( _L ( "Memory allocation failed for handle_data" ) );
       
  2670 		lm_connection_close ( connection, NULL );
       
  2671 		lm_connection_unref ( connection );
       
  2672 		free_data ( connect_data );
       
  2673 		return KErrGeneral;
       
  2674 		}
       
  2675 	
       
  2676 	handle_data->main_loop = main_loop;
       
  2677 	handle_data->Test_Success = RC_ERROR;
       
  2678 	
       
  2679 	// Register a message handler
       
  2680 	handler = lm_message_handler_new ( handle_messages, handle_data, NULL );
       
  2681 	if ( !handler )
       
  2682 		{
       
  2683 		iLog->Log ( _L ( "lm_message_handler_new failed" ) );
       
  2684 		lm_connection_close ( connection, NULL );
       
  2685 		lm_connection_unref ( connection );
       
  2686 		free_data ( connect_data );
       
  2687 		return KErrGeneral;
       
  2688 		}
       
  2689 	lm_connection_register_message_handler ( connection,
       
  2690 	                                         handler,
       
  2691 	                                         LM_MESSAGE_TYPE_IQ,
       
  2692 	                                         LM_HANDLER_PRIORITY_NORMAL );
       
  2693 	lm_message_handler_unref ( handler );	
       
  2694 	
       
  2695 	
       
  2696 	// Construct a message
       
  2697 	msg = lm_message_new ( connect_data->msg_data->recipient, 
       
  2698 	                           LM_MESSAGE_TYPE_IQ );
       
  2699 	lm_message_node_add_child ( msg->node, "query", NULL );
       
  2700 
       
  2701 	
       
  2702 	//Send message to the server
       
  2703 	//Since we are sending dummy query to the recipient, we are expecting
       
  2704 	//an error message. This indicates the response was successfully received.
       
  2705 	if ( !lm_connection_send ( connection, msg, NULL ) )
       
  2706 	    {
       
  2707 		iLog->Log ( _L ( "lm_message_send failed" ) );
       
  2708 		lm_connection_close ( connection, NULL );
       
  2709 		lm_connection_unref ( connection );
       
  2710 		lm_message_unref ( msg );
       
  2711 		return KErrGeneral;
       
  2712 	    }	
       
  2713     
       
  2714     // Wait for the reply from the server
       
  2715     g_main_loop_run ( main_loop );
       
  2716     g_main_loop_unref ( main_loop );
       
  2717     
       
  2718     // Free the allocated resources
       
  2719     lm_connection_close ( connection, NULL );
       
  2720     lm_connection_unref ( connection );
       
  2721     lm_message_unref ( msg );
       
  2722     
       
  2723     // Verify wheather the callback function called or not
       
  2724     if ( RC_OK != handle_data->Test_Success )
       
  2725         {
       
  2726     	iLog->Log ( _L ( "register_message_handlerL failed" ) );
       
  2727     	g_free ( handle_data );
       
  2728     	return KErrGeneral;
       
  2729         }
       
  2730     
       
  2731     g_free ( handle_data );
       
  2732 	free_data ( connect_data );
       
  2733     iLog->Log ( _L ( "register_message_handlerL passed" ) );
       
  2734     
       
  2735     return KErrNone;
       
  2736     }
       
  2737 
       
  2738 
       
  2739 //-----------------------------------------------------------------------------
       
  2740 // Ctstlm::set_disconnect_functionL
       
  2741 // Description  : Set the callback that will be called when a connection is 
       
  2742 //                closed
       
  2743 // Arguements   :
       
  2744 //   connection	: Connection to register disconnect callback for
       
  2745 //   function   : Function to be called when connection is closed
       
  2746 //   user_data  : User data passed to a function
       
  2747 //   notify     : Function to free user_data
       
  2748 // Returns      : None
       
  2749 //-----------------------------------------------------------------------------
       
  2750 //
       
  2751 TInt Ctstlm::set_disconnect_functionL ( CStifItemParser& aItem )
       
  2752     {
       
  2753 	LmConnection *connection   = NULL;	
       
  2754 	ConnectData  *connect_data = NULL;
       
  2755 	HandleData   *handle_data  = NULL;
       
  2756 	
       
  2757 	iLog->Log ( _L ( "In set_disconnect_functionL" ) );
       
  2758 	
       
  2759 	if ( read_data ( connect_data, aItem ) != RC_OK )
       
  2760 		{
       
  2761 		iLog->Log ( _L ( "read_data failed" ) );
       
  2762 		free_data ( connect_data );
       
  2763 		return KErrGeneral;
       
  2764 		}		
       
  2765 	
       
  2766 	// Create a new closed connection
       
  2767 	connection = lm_connection_new ( connect_data->server );
       
  2768 	if ( !connection )
       
  2769 		{
       
  2770 		iLog->Log ( _L ( "lm_connection_new failed" ) );
       
  2771 		free_data ( connect_data );
       
  2772 		return KErrGeneral;
       
  2773 		}
       
  2774 	
       
  2775 	lm_connection_set_port ( connection, GTALK_SSL_PORT );
       
  2776 	lm_connection_set_jid ( connection, connect_data->username );
       
  2777 	
       
  2778 #ifdef __WINSCW__
       
  2779 	SetProxy ( connection, connect_data->proxy_data );
       
  2780 #endif
       
  2781 
       
  2782 	SSLInit ( connection );
       
  2783 
       
  2784 	
       
  2785 	// Open a connection with the server
       
  2786 	GMainLoop	*main_loop = g_main_loop_new ( NULL, FALSE );
       
  2787 	iLog->Log ( _L ( "before lm_connection_open" ) );
       
  2788 	
       
  2789 	if ( !lm_connection_open ( connection, ( LmResultFunction ) connection_open_cb,
       
  2790 	                           main_loop, NULL, NULL ) ) 
       
  2791 	    {
       
  2792 		iLog->Log ( _L ( "lm_connection_open failed" ));
       
  2793 		lm_connection_unref ( connection );
       
  2794 		g_main_loop_unref ( main_loop );
       
  2795 		free_data ( connect_data );		
       
  2796 		return KErrGeneral;
       
  2797 	    }
       
  2798 		
       
  2799 	iLog->Log ( _L ( "after lm_connection_open" ) );	
       
  2800 	g_main_loop_run ( main_loop );
       
  2801 	g_main_loop_unref ( main_loop ); 
       
  2802 	
       
  2803 		
       
  2804 	handle_data = g_new0 ( HandleData, 1 );
       
  2805 	if ( !handle_data )
       
  2806 		{
       
  2807 		iLog->Log ( _L ( "Memory allocation failed for handle_data" ) );
       
  2808 		lm_connection_close ( connection, NULL );
       
  2809 		lm_connection_unref ( connection );
       
  2810 		return KErrGeneral;
       
  2811 		}
       
  2812 	handle_data->Test_Success = RC_ERROR;
       
  2813 	
       
  2814 	// Set a Callback function that will be called when connection is closed
       
  2815 	lm_connection_set_disconnect_function ( connection, 
       
  2816 	                                        connection_close_cb, 
       
  2817 	                                        handle_data,
       
  2818 	                                        NULL );
       
  2819 	
       
  2820 	// Close the opened connection
       
  2821 	lm_connection_close ( connection, NULL );
       
  2822 	lm_connection_unref ( connection );
       
  2823 	
       
  2824 	// Check wheather callback function is called or not
       
  2825 	if ( RC_OK != handle_data->Test_Success )
       
  2826 	    {
       
  2827 		iLog->Log ( _L ( "set_disconnect_functionL failed" ) );
       
  2828 		g_free ( handle_data );
       
  2829 		return KErrGeneral;
       
  2830 	    } 
       
  2831 	    
       
  2832 	g_free ( handle_data );	
       
  2833 	
       
  2834 	iLog->Log ( _L ( "set_disconnect_functionL passed" ) );
       
  2835 	free_data ( connect_data );
       
  2836 	
       
  2837 	return KErrNone;	
       
  2838     }
       
  2839 
       
  2840 
       
  2841 //-----------------------------------------------------------------------------
       
  2842 // Ctstlm::lm_connection_send_raw
       
  2843 // Description  : Asynchronus call to send a raw string. 
       
  2844 // Arguements   :
       
  2845 //   connection	: Connection used to send
       
  2846 //   str        : The string to send, the entire string will be sent
       
  2847 //   error      : Set if error was detected during sending
       
  2848 // Returns      : TRUE if no errors were detected during sending, FALSE 
       
  2849 //                otherwise
       
  2850 //-----------------------------------------------------------------------------
       
  2851 //
       
  2852 TInt Ctstlm::lm_connection_send_rawL ( CStifItemParser& aItem )
       
  2853     {
       
  2854 	LmConnection *connection   = NULL;
       
  2855 	ConnectData  *connect_data = NULL;
       
  2856 	GError       *error        = NULL;
       
  2857 	
       
  2858 	iLog->Log ( _L ( "In lm_connection_send_raw" ) );
       
  2859 	
       
  2860 	// Read data from the cfg file
       
  2861 	if ( read_data ( connect_data, aItem ) != RC_OK )
       
  2862 		{
       
  2863 		iLog->Log ( _L ( "read_data failed" ) );
       
  2864 		free_data ( connect_data );
       
  2865 		return KErrGeneral;
       
  2866 		}
       
  2867 	
       
  2868 	// Create a new closed connection
       
  2869 	connection = lm_connection_new ( connect_data->server );
       
  2870 	if ( !connection )
       
  2871 		{
       
  2872 		iLog->Log ( _L ( "lm_connection_new failed" ) );
       
  2873 		free_data ( connect_data );
       
  2874 		return KErrGeneral;
       
  2875 		}
       
  2876 	
       
  2877 	lm_connection_set_port ( connection, GTALK_SSL_PORT );
       
  2878 	lm_connection_set_jid ( connection, connect_data->username );
       
  2879 	
       
  2880 #ifdef __WINSCW__
       
  2881 	SetProxy ( connection, connect_data->proxy_data );
       
  2882 #endif
       
  2883 
       
  2884 	SSLInit ( connection );
       
  2885 		
       
  2886 	// Open a connection with the server
       
  2887 	GMainLoop	*main_loop = g_main_loop_new ( NULL, FALSE );
       
  2888 	iLog->Log ( _L ( "before lm_connection_open" ) );
       
  2889 	
       
  2890 	if ( !lm_connection_open ( connection, ( LmResultFunction ) connection_open_cb,
       
  2891 	                           main_loop, NULL, NULL ) ) 
       
  2892 	    {
       
  2893 		iLog->Log ( _L ( "lm_connection_open failed" ));
       
  2894 		lm_connection_unref ( connection );
       
  2895 		g_main_loop_unref ( main_loop );
       
  2896 		free_data ( connect_data );		
       
  2897 		return KErrGeneral;
       
  2898 	    }
       
  2899 		
       
  2900 	iLog->Log ( _L ( "after lm_connection_open" ) );	
       
  2901 	g_main_loop_run ( main_loop );
       
  2902 	g_main_loop_unref ( main_loop ); 
       
  2903 	
       
  2904 	
       
  2905 	// Send a raw message 
       
  2906 	if ( !lm_connection_send_raw ( connection, 
       
  2907 	                               connect_data->msg_data->message, 
       
  2908 	                               &error ) )
       
  2909 	    {
       
  2910 		iLog->Log ( _L ( "lm_connection_send_raw failed: %s"), error->message );
       
  2911 		lm_connection_close ( connection, NULL );
       
  2912 		lm_connection_unref ( connection );
       
  2913 		free_data ( connect_data );
       
  2914 		return KErrGeneral;
       
  2915 	    }
       
  2916     
       
  2917     lm_connection_close ( connection, NULL );
       
  2918     lm_connection_unref ( connection );
       
  2919     free_data ( connect_data );
       
  2920     
       
  2921     iLog->Log ( _L ( "lm_connection_send_raw passed" ) );
       
  2922     
       
  2923     return KErrNone;	
       
  2924     }
       
  2925 
       
  2926 
       
  2927 
       
  2928 //-----------------------------------------------------------------------------
       
  2929 // Ctstlm::lm_connection_get_state
       
  2930 // Description  : Returns the state of the connection
       
  2931 // Arguements   :
       
  2932 //      connection	: Connection to get state
       
  2933 // Returns      : The state of the connection
       
  2934 //-----------------------------------------------------------------------------
       
  2935 //
       
  2936 TInt Ctstlm::lm_connection_get_stateL ( CStifItemParser& aItem )
       
  2937     {
       
  2938 	LmConnection      *connection   = NULL;
       
  2939 	ConnectData       *connect_data = NULL;
       
  2940 	LmConnectionState state;
       
  2941 	
       
  2942 	iLog->Log ( _L ( "In lm_connection_get_state" ) );
       
  2943 	
       
  2944 	// Read data from the CFG file
       
  2945 	if ( read_data ( connect_data, aItem ) != RC_OK )
       
  2946 		{
       
  2947 		iLog->Log ( _L ( "read_data failed" ) );
       
  2948 		free_data ( connect_data );
       
  2949 		return KErrGeneral;
       
  2950 		}
       
  2951 	
       
  2952 	// Create a new closed connection
       
  2953 	connection = lm_connection_new ( connect_data->server );
       
  2954 	lm_connection_set_port ( connection, GTALK_SSL_PORT );
       
  2955 	lm_connection_set_jid ( connection, connect_data->username );
       
  2956 	
       
  2957 #ifdef __WINSCW__
       
  2958 	SetProxy ( connection, connect_data->proxy_data );
       
  2959 #endif
       
  2960 
       
  2961 	SSLInit ( connection );	
       
  2962 	
       
  2963 	// Verify the state when the connection is closed
       
  2964 	state = lm_connection_get_state ( connection );
       
  2965 	
       
  2966 	if ( LM_CONNECTION_STATE_CLOSED != state )
       
  2967 	    {
       
  2968 		iLog->Log ( _L ( "lm_connection_get_state failed:closed" ) );
       
  2969 		lm_connection_unref ( connection );
       
  2970 		free_data ( connect_data );
       
  2971 		return KErrGeneral;
       
  2972 	    }
       
  2973 	
       
  2974 	// Verify the state after opening the connection
       
  2975 	GMainLoop	*main_loop = g_main_loop_new ( NULL, FALSE );
       
  2976 	iLog->Log ( _L ( "before lm_connection_open" ) );
       
  2977 	
       
  2978 	if ( !lm_connection_open ( connection, ( LmResultFunction ) connection_open_cb,
       
  2979 	                           main_loop, NULL, NULL ) ) 
       
  2980 	    {
       
  2981 		iLog->Log ( _L ( "lm_connection_open failed" ));
       
  2982 		lm_connection_unref ( connection );
       
  2983 		g_main_loop_unref ( main_loop );
       
  2984 		free_data ( connect_data );		
       
  2985 		return KErrGeneral;
       
  2986 	    }
       
  2987 		
       
  2988 	iLog->Log ( _L ( "after lm_connection_open" ) );	
       
  2989 	g_main_loop_run ( main_loop );
       
  2990 	g_main_loop_unref ( main_loop ); 
       
  2991 	
       
  2992 	    
       
  2993 	state = lm_connection_get_state ( connection );
       
  2994 	
       
  2995 	if ( LM_CONNECTION_STATE_OPEN != state )
       
  2996 	    {
       
  2997 		iLog->Log ( _L ( "lm_connection_get_state failed: open" ) );
       
  2998 		lm_connection_close ( connection, NULL );
       
  2999 		lm_connection_unref ( connection );
       
  3000 		free_data ( connect_data );
       
  3001 		return KErrGeneral;
       
  3002 	    }
       
  3003 	    
       
  3004 	// Get the username from the JID
       
  3005 	gchar *username = get_user_name ( connect_data->username );
       
  3006 	
       
  3007 	main_loop = g_main_loop_new ( NULL, FALSE );
       
  3008 	// Authenticate with the server
       
  3009 	if ( !lm_connection_authenticate ( connection,
       
  3010                                      username,
       
  3011                                      connect_data->password,
       
  3012                                      connect_data->resource,
       
  3013                                       ( LmResultFunction )connection_auth_cb,
       
  3014                                      main_loop,NULL,NULL ) )
       
  3015 	    {
       
  3016 		iLog->Log ( _L ( "lm_connection_authenticate failed" ) );
       
  3017 		lm_connection_close ( connection, NULL );
       
  3018 		lm_connection_unref ( connection );
       
  3019 		free_data ( connect_data );
       
  3020 		g_main_loop_unref ( main_loop );
       
  3021 		g_free ( username );
       
  3022 		return KErrGeneral;
       
  3023 	    }
       
  3024 	g_main_loop_run ( main_loop );
       
  3025 	g_main_loop_unref ( main_loop );    
       
  3026 	g_free ( username );    
       
  3027 	
       
  3028 		    
       
  3029 	state = lm_connection_get_state ( connection );
       
  3030 	
       
  3031 	if ( LM_CONNECTION_STATE_AUTHENTICATED != state )
       
  3032 	    {
       
  3033 	    iLog->Log ( _L ( "lm_connection_get_state failed: authenticated" ) );
       
  3034 	    lm_connection_close ( connection, NULL );
       
  3035 	    lm_connection_unref ( connection );
       
  3036 	    free_data ( connect_data );
       
  3037 	    return KErrGeneral;
       
  3038 	    }    
       
  3039 	
       
  3040 	lm_connection_close ( connection, NULL );
       
  3041 	lm_connection_unref ( connection );
       
  3042 	free_data ( connect_data );
       
  3043 	
       
  3044 	iLog->Log ( _L ( "lm_connection_get_state passed" ) );
       
  3045 	
       
  3046 	return KErrNone;
       
  3047     }
       
  3048 
       
  3049 
       
  3050 //-----------------------------------------------------------------------------
       
  3051 // Ctstlm::lm_connection_ref
       
  3052 // Description  : Add a reference on connection
       
  3053 // Arguements   :
       
  3054 //   connection	: Connection to a add a reference to 
       
  3055 // Returns      : Returns the same connection
       
  3056 // ----------------------------------------------------------------------------
       
  3057 //
       
  3058 TInt Ctstlm::lm_connection_refL ( CStifItemParser& /*aItem*/ )
       
  3059     {
       
  3060 	LmConnection *connection = NULL;	
       
  3061 	
       
  3062 	iLog->Log ( _L ("In lm_connection_unref" ) );
       
  3063 	
       
  3064 	// Create a new closed connection
       
  3065 	connection = lm_connection_new ( NULL );
       
  3066 		
       
  3067 	// Add a reference on connection
       
  3068 	connection = lm_connection_ref ( connection );
       
  3069 	
       
  3070     // Loudmouth don't have any API to check the ref count on connection
       
  3071     // Therefore lm_connection_ref is considered as passed.
       
  3072     	
       
  3073     // Decrement the reference count and free the memory
       
  3074 	lm_connection_unref ( connection );
       
  3075 	lm_connection_unref ( connection );
       
  3076 	
       
  3077 	iLog->Log ( _L ( "lm_connection_ref passed" ) );
       
  3078 	
       
  3079 	return KErrNone;
       
  3080     }
       
  3081 
       
  3082 
       
  3083 //-----------------------------------------------------------------------------
       
  3084 // Ctstlm::lm_connection_unref
       
  3085 // Description  : Removes the reference on connection. If there are no
       
  3086 //                references to connection, it will be freed and shouldn't
       
  3087 //                used again
       
  3088 //                Check the total available heap space
       
  3089 //                Create a new closed connection,
       
  3090 //                Check that available heap space is reduced
       
  3091 //                Decrement the reference on connection
       
  3092 //                Check the available heap is equal to what it was before                 
       
  3093 // Arguements   :
       
  3094 //   connection	: Connection to remove reference from
       
  3095 // Returns      : None
       
  3096 // ----------------------------------------------------------------------------
       
  3097 //
       
  3098 TInt Ctstlm::lm_connection_unrefL ( CStifItemParser& /*aItem*/ )
       
  3099     {
       
  3100 	LmConnection *connection = NULL;
       
  3101 	RHeap&       heap_handle = User::Heap();
       
  3102 	TInt         largest_free_block;
       
  3103 	TInt         heap_available_before;
       
  3104 	TInt         heap_available_after;	
       
  3105 	
       
  3106 	iLog->Log ( _L ( "In lm_connection_unref" ) );	
       
  3107 __UHEAP_MARK;
       
  3108     // Get the heap space before creating closed connection
       
  3109 	heap_available_before = heap_handle.Available ( largest_free_block );	
       
  3110 	
       
  3111 	// Create a new closed connection
       
  3112 	connection = lm_connection_new ( NULL );	
       
  3113 	
       
  3114 	// Decrement the reference on connection
       
  3115 	lm_connection_unref ( connection );
       
  3116 
       
  3117 	// Get the heap space after freeing memory
       
  3118 	heap_available_after = heap_handle.Available ( largest_free_block );	
       
  3119 
       
  3120    	if ( heap_available_after != heap_available_before )
       
  3121 	    {
       
  3122 		iLog->Log ( _L ( "{heap_available_before = %d, heap_available_before = %d}" ),
       
  3123 		                   heap_available_before, heap_available_after );
       
  3124 		iLog->Log ( _L ( "Available memeory is not as expected after free!" ) );
       
  3125 		return KErrGeneral;                   
       
  3126 	    }	
       
  3127 __UHEAP_MARKEND;
       
  3128 	iLog->Log ( _L ( "{ Expected:heap_available_before is equal to heap_available_after }" ) );
       
  3129 	iLog->Log ( _L ( "heap_available_before = %d, heap_available_after = %d" ),
       
  3130 	                  heap_available_before, heap_available_after );
       
  3131 	iLog->Log ( _L ( "lm_connection_unref passed" ) );
       
  3132 		
       
  3133 	return KErrNone;
       
  3134 	
       
  3135     }
       
  3136     
       
  3137 
       
  3138 // ----------------------------------------------------------------------------
       
  3139 // Ctstlm::lm_message_new
       
  3140 // Description:Creates a new LmMessage which can be sent with 
       
  3141 //             lm_connection_send() or lm_connection_send_with_reply().
       
  3142 // Arguements :
       
  3143 //    to      : recipient jid
       
  3144 //    type    : message type
       
  3145 // Returns    : a newly created LmMessage       
       
  3146 // ----------------------------------------------------------------------------
       
  3147 //
       
  3148 TInt Ctstlm::lm_message_newL ( CStifItemParser& aItem )
       
  3149     {
       
  3150 	LmMessage     *message;
       
  3151 	ConnectData   *connect_data = NULL;
       
  3152 	LmMessageType MessageType;
       
  3153 	gchar         Type[256];	
       
  3154 	
       
  3155 	iLog->Log ( _L ( "\tIn lm_message_new" ) );	
       
  3156 	
       
  3157 	// Read data from the CFG file	
       
  3158 	if ( read_data ( connect_data, aItem ) != RC_OK )
       
  3159 	{
       
  3160 		iLog->Log ( _L ( "\tread_data failed" ) );
       
  3161 		free_data ( connect_data );
       
  3162 		return KErrGeneral;
       
  3163 	}
       
  3164 	
       
  3165 	// Construct a message with a type=LM_MESSAGE_TYPE_MESSAGE
       
  3166 	iLog->Log ( _L ( "\tConstruct a message" ) );
       
  3167 	
       
  3168 	message = lm_message_new ( connect_data->msg_data->recipient, 
       
  3169 	                           LM_MESSAGE_TYPE_MESSAGE );
       
  3170 	if ( !message )
       
  3171 	{
       
  3172 		iLog->Log ( _L ( "\tlm_message_new failed" ) );
       
  3173 		free_data ( connect_data );
       
  3174 		return KErrGeneral;
       
  3175 	}
       
  3176 	
       
  3177 	
       
  3178 	// Verify the message type
       
  3179 	iLog->Log ( _L ( "\tVerify the message type" ) );
       
  3180 	
       
  3181 	MessageType = lm_message_get_type ( message );
       
  3182 	if ( LM_MESSAGE_TYPE_MESSAGE != MessageType )
       
  3183 	    {
       
  3184 		iLog->Log ( _L( "\tExpected message type: LM_MESSAGE_TYPE_MESSAGE" ) );
       
  3185 		memset ( Type, '\0', sizeof ( Type ) );
       
  3186 		GetMessageType ( MessageType, Type );
       
  3187 		iLog->Log ( _L8 ( "\tActual message type  : %s" ), Type );
       
  3188 		
       
  3189 		iLog->Log ( _L ( "\tlm_message_get_type failed" ) );
       
  3190 		lm_message_unref ( message );
       
  3191 		return KErrGeneral;
       
  3192 	    }	
       
  3193 	
       
  3194 	lm_message_unref ( message );	
       
  3195 	free_data ( connect_data );
       
  3196 	
       
  3197 	iLog->Log ( _L ( "lm_message_new passed" ) );
       
  3198 	
       
  3199 	return KErrNone;
       
  3200 	
       
  3201     }
       
  3202 
       
  3203  
       
  3204  // ---------------------------------------------------------------------------
       
  3205 // Ctstlm::lm_message_new_with_sub_type
       
  3206 // Description:Creates a new LmMessage with subtype set.
       
  3207 // Arguements :
       
  3208 //  to        : recipient jid
       
  3209 //  type      : message type
       
  3210 //  sub_type  : message sub type
       
  3211 // Returns    : a newly created LmMessage       
       
  3212 // ----------------------------------------------------------------------------
       
  3213 //
       
  3214 TInt Ctstlm::lm_message_new_with_sub_typeL ( CStifItemParser& aItem )
       
  3215     {
       
  3216 	LmMessage        *message;
       
  3217 	ConnectData      *connect_data = NULL;
       
  3218 	LmMessageType    MessageType;
       
  3219 	LmMessageSubType MessageSubType;
       
  3220 	gchar            Type[256];
       
  3221 	gchar            SubType[256];
       
  3222 	
       
  3223 	iLog->Log ( _L ( "In lm_message_new_with_sub_type" ) );
       
  3224 		
       
  3225 	// Read data from the CFG file
       
  3226 	if ( read_data ( connect_data, aItem ) != RC_OK )
       
  3227 	    {
       
  3228 		iLog->Log ( _L ( "\tread_data failed" ) );
       
  3229 		free_data ( connect_data );
       
  3230 		return KErrGeneral;
       
  3231 	    }
       
  3232 	
       
  3233 	// Construct a message with type and sub type	
       
  3234 	message = lm_message_new_with_sub_type ( connect_data->msg_data->recipient,
       
  3235 	                                         LM_MESSAGE_TYPE_IQ,
       
  3236 	                                         LM_MESSAGE_SUB_TYPE_SET );
       
  3237 	if ( !message )
       
  3238 	    {
       
  3239 		iLog->Log ( _L ( "\tlm_message_new_with_sub_type failed" ) );
       
  3240 		free_data ( connect_data );		
       
  3241 		return KErrGeneral;
       
  3242 	    }
       
  3243 
       
  3244 	
       
  3245 	// Verify the message type	
       
  3246 	MessageType = lm_message_get_type ( message );
       
  3247 	if ( LM_MESSAGE_TYPE_IQ != MessageType )
       
  3248 	    {
       
  3249 	    iLog->Log ( _L ( "\tExpected message type: LM_MESSAGE_TYPE_IQ" ) );
       
  3250 	    memset ( Type, '\0', sizeof ( Type ) );
       
  3251 	    GetMessageType ( MessageType, Type );
       
  3252 	    iLog->Log ( _L8 ( "\tActual message type  : %s"), Type );		
       
  3253 	    lm_message_unref ( message );
       
  3254 	    return KErrGeneral;
       
  3255 	    }
       
  3256 	
       
  3257 	// Verify the message sub type	
       
  3258 	MessageSubType = lm_message_get_sub_type ( message );
       
  3259 	if ( LM_MESSAGE_SUB_TYPE_SET != MessageSubType )
       
  3260 	    {
       
  3261 		iLog->Log ( _L ( "\tExpected message subtype: LM_MESSAGE_SUB_TYPE_SET" ) );
       
  3262 		memset ( SubType, '\0', sizeof ( SubType ) );
       
  3263 		GetMessageSubType ( MessageSubType, SubType );
       
  3264 		iLog->Log ( _L8 ( "\tActual message subtype  : %s" ), SubType );
       
  3265 		lm_message_unref ( message );
       
  3266 		return KErrGeneral;
       
  3267 	    }	    
       
  3268 	
       
  3269 	lm_message_unref ( message );
       
  3270 		    
       
  3271 	free_data ( connect_data );    
       
  3272 	iLog->Log ( _L ( "lm_message_new_with_sub_type passed" ) );
       
  3273 	
       
  3274 	return KErrNone;
       
  3275     }
       
  3276     
       
  3277 
       
  3278 // ----------------------------------------------------------------------------
       
  3279 // Ctstlm::lm_message_get_type
       
  3280 // Description:Fetches the type of the message
       
  3281 // Arguements :
       
  3282 //    message : an LmMessage
       
  3283 // Returns    : the message type
       
  3284 // ----------------------------------------------------------------------------
       
  3285 //
       
  3286 TInt Ctstlm::lm_message_get_typeL ( CStifItemParser& /*aItem*/ )
       
  3287     {
       
  3288 	LmMessage     *message      = NULL;
       
  3289 	LmMessageType MessageType;
       
  3290 	gchar         Type[256];
       
  3291 	
       
  3292 	iLog->Log ( _L ( "In lm_message_get_type" ) );
       
  3293 	memset ( Type, '\0', sizeof ( Type ) );
       
  3294 	
       
  3295 	// Construct a message with a type	
       
  3296 	message = lm_message_new ( NULL, LM_MESSAGE_TYPE_PRESENCE );
       
  3297 	if ( !message )
       
  3298 	    {
       
  3299 		iLog->Log ( _L ( "\tlm_message_new failed while constructing PRESENCE msg" ) );
       
  3300 		return KErrGeneral;
       
  3301 	    } 
       
  3302 	
       
  3303 	// Verify the message type=LM_MESSAGE_TYPE_PRESENCE
       
  3304 	iLog->Log ( _L ( "\tMessage type verification" ) );
       
  3305 		
       
  3306 	MessageType = lm_message_get_type ( message );
       
  3307 	if ( LM_MESSAGE_TYPE_PRESENCE != MessageType )
       
  3308 	    {
       
  3309 		iLog->Log ( _L ( "\tExpected message type: LM_MESSAGE_TYPE_PRESENCE" ) ) ;
       
  3310 		memset ( Type, '\0', sizeof ( Type ) );
       
  3311 		GetMessageType ( MessageType, Type );
       
  3312 		iLog->Log ( _L8 ( "\tActual message type  :%s" ), Type );
       
  3313 		lm_message_unref ( message );
       
  3314 		return KErrGeneral;
       
  3315 	    }
       
  3316 	    
       
  3317     // Construct another message with type=LM_MESSAGE_TYPE_IQ
       
  3318     iLog->Log ( _L ( "\tConstruct a message with another type" ) );
       
  3319     
       
  3320     lm_message_unref ( message );
       
  3321     message = NULL;    
       
  3322     
       
  3323     message = lm_message_new ( NULL, LM_MESSAGE_TYPE_IQ );
       
  3324     if ( !message )
       
  3325         {
       
  3326     	iLog->Log ( _L ( "\tlm_message_new failed while constructing IQ message " ) );
       
  3327     	lm_message_unref ( message );
       
  3328     	return KErrGeneral;
       
  3329         }
       
  3330     
       
  3331     // Verify the message type
       
  3332     iLog->Log ( _L ( "\tVerify the message type" ) );
       
  3333     
       
  3334     MessageType = lm_message_get_type ( message );
       
  3335     if ( LM_MESSAGE_TYPE_IQ != MessageType )
       
  3336         {
       
  3337     	iLog->Log ( _L ( "\tExpected message type: LM_MESSAGE_TYPE_IQ" ) );
       
  3338     	memset ( Type, '\0', sizeof ( Type ) );
       
  3339     	GetMessageType ( MessageType, Type );
       
  3340     	iLog->Log ( _L8 ( "\tActual message type  : %s" ), Type );
       
  3341     	lm_message_unref ( message );
       
  3342     	return KErrGeneral;
       
  3343         }
       
  3344     
       
  3345     lm_message_unref ( message );
       
  3346      
       
  3347     iLog->Log ( _L ( "\tlm_message_get_type passed" ) );    
       
  3348     
       
  3349     return KErrNone;
       
  3350     }
       
  3351     
       
  3352 
       
  3353 // ----------------------------------------------------------------------------
       
  3354 // Ctstlm::lm_message_get_sub_type
       
  3355 // Description:Fetches the sub type of the message
       
  3356 // Arguements :
       
  3357 //    message : an LmMessage
       
  3358 // Returns    : the message sub type
       
  3359 // ----------------------------------------------------------------------------
       
  3360 //
       
  3361 TInt Ctstlm::lm_message_get_sub_typeL ( CStifItemParser& /*aItem*/ )
       
  3362     {
       
  3363 	LmMessage        *message = NULL;
       
  3364 	LmMessageSubType MessageSubType;
       
  3365 	gchar            SubType[256];
       
  3366 	
       
  3367 	iLog->Log ( _L ( "In lm_message_get_sub_type" ) );
       
  3368 	
       
  3369 	// Construct a message with type and subtype=LM_MESSAGE_SUB_TYPE_SUBSCRIBE
       
  3370 	iLog->Log ( _L ( "\tConstruct a message with type & subtype" ) );
       
  3371 	
       
  3372 	message = lm_message_new_with_sub_type ( NULL, 
       
  3373 	                                         LM_MESSAGE_TYPE_MESSAGE,
       
  3374 	                                         LM_MESSAGE_SUB_TYPE_SUBSCRIBE );
       
  3375 	if ( !message )
       
  3376 	    {
       
  3377 		iLog->Log ( _L ( "lm_message_new_with_sub_type failed for SUBSCRIBE" ) );
       
  3378 		return KErrGeneral;
       
  3379 	    }
       
  3380 	
       
  3381 	// Verify message subtype	
       
  3382 	MessageSubType = lm_message_get_sub_type ( message );
       
  3383 	if ( LM_MESSAGE_SUB_TYPE_SUBSCRIBE != MessageSubType )
       
  3384 	    {
       
  3385 		iLog->Log ( _L ( "\tExpected MessageSubType: LM_MESSAGE_SUB_TYPE_SUBSCRIBE" ) );		
       
  3386 		memset ( SubType, '\0', sizeof ( SubType ) );
       
  3387 		GetMessageSubType ( MessageSubType, SubType );
       
  3388 		iLog->Log ( _L8 ( "\tActual MessageSubType  : %s" ), SubType );
       
  3389 		lm_message_unref ( message );
       
  3390 		return KErrGeneral;
       
  3391 	    }
       
  3392 	
       
  3393 	// Construct another message with subtype=LM_MESSAGE_SUB_TYPE_CHAT	
       
  3394 	lm_message_unref ( message );
       
  3395 	message = NULL;
       
  3396 	
       
  3397 	message = lm_message_new_with_sub_type ( NULL,
       
  3398 	                                         LM_MESSAGE_TYPE_MESSAGE,
       
  3399 	                                         LM_MESSAGE_SUB_TYPE_CHAT );
       
  3400 	if ( !message )
       
  3401 	    {
       
  3402 		iLog->Log ( _L ( "\tlm_message_new_with_sub_type failed for CHAT" ) );
       
  3403 		return KErrGeneral;
       
  3404 	    }
       
  3405 	
       
  3406 	// Verify message subtype	
       
  3407 	MessageSubType = lm_message_get_sub_type ( message );
       
  3408 	if ( LM_MESSAGE_SUB_TYPE_CHAT != MessageSubType )
       
  3409 	    {
       
  3410 		iLog->Log ( _L ( "\tExpected MessageSubType: LM_MESSAGE_SUB_TYPE_CHAT" ) );
       
  3411 		
       
  3412 		memset ( SubType, '\0', sizeof ( SubType ) );
       
  3413 		GetMessageSubType ( MessageSubType, SubType );
       
  3414 		iLog->Log ( _L8 ( "\tActual MessageSubType  : %s" ), SubType );
       
  3415 		lm_message_unref ( message );
       
  3416 		return KErrGeneral;
       
  3417 	    }	
       
  3418 	
       
  3419 	lm_message_unref ( message );
       
  3420 	
       
  3421 	iLog->Log ( _L ( "\tlm_message_get_sub_type passed" ) );	
       
  3422 	
       
  3423 	return KErrNone;
       
  3424     }
       
  3425 
       
  3426 
       
  3427 // ----------------------------------------------------------------------------
       
  3428 // Ctstlm::lm_message_get_node
       
  3429 // Description:Retrives the root node from LmMessage
       
  3430 // Arguements :
       
  3431 //   message  : an LmMessage
       
  3432 // Returns    : an LmMessageNode
       
  3433 // ----------------------------------------------------------------------------
       
  3434 //
       
  3435 TInt Ctstlm::lm_message_get_nodeL ( CStifItemParser& /*aItem*/ )
       
  3436     {
       
  3437 	LmMessage     *message;
       
  3438 	LmMessageNode *Node = NULL;
       
  3439 	
       
  3440 	iLog->Log ( _L ( "In lm_message_get_node" ) );
       
  3441 	
       
  3442 	// Construct a message with type=LM_MESSAGE_TYPE_MESSAGE
       
  3443 	iLog->Log ( _L ( "Construct a message" ) );
       
  3444 	
       
  3445 	message = lm_message_new ( NULL, LM_MESSAGE_TYPE_MESSAGE );
       
  3446 	if ( !message )
       
  3447 	    {
       
  3448 		iLog->Log ( _L ( "lm_message_new failed" ) );
       
  3449 		return KErrGeneral;
       
  3450 	    }
       
  3451 	
       
  3452 	// Retrive root node from the message
       
  3453 	iLog->Log ( _L ( "Retrive root node from message" ) );
       
  3454 	
       
  3455 	Node = lm_message_get_node ( message );
       
  3456 	if ( !Node )
       
  3457 	    {
       
  3458 		iLog->Log ( _L ( "lm_message_get_node failed" ) );
       
  3459 		lm_message_unref ( message );
       
  3460 		return KErrGeneral;
       
  3461 	    }		
       
  3462 	
       
  3463 	lm_message_unref ( message );
       
  3464 	lm_message_node_unref ( Node );
       
  3465 	
       
  3466 	iLog->Log ( _L ( "lm_message_get_node passed" ) );
       
  3467 	
       
  3468 	return KErrNone;
       
  3469     }
       
  3470 
       
  3471 
       
  3472     
       
  3473 // ----------------------------------------------------------------------------
       
  3474 // Ctstlm::lm_message_ref 
       
  3475 // Description:Adds a reference to message
       
  3476 // Arguements :
       
  3477 //       message   : an LmMessage
       
  3478 // Returns    : an message
       
  3479 // ----------------------------------------------------------------------------
       
  3480 //
       
  3481 TInt Ctstlm::lm_message_refL ( CStifItemParser& /*aItem*/ )
       
  3482 {
       
  3483 	LmMessage *message = NULL;
       
  3484 	
       
  3485 	iLog->Log ( _L ( "In lm_message_ref" ) );
       
  3486 	
       
  3487 	// Construct a message	
       
  3488 	message = lm_message_new ( NULL, LM_MESSAGE_TYPE_MESSAGE );
       
  3489 	if ( !message )
       
  3490 	    {
       
  3491 		iLog->Log ( _L ( "lm_message_new failed" ) );
       
  3492 		return KErrGeneral;
       
  3493 	    }
       
  3494 	
       
  3495 	// Add a reference to message 	
       
  3496 	message = lm_message_ref ( message );
       
  3497 	
       
  3498 	// Loudmouth don't have any API to check the ref count on message
       
  3499     // Therefore lm_message_ref is considered as passed.
       
  3500     
       
  3501     // Decrement the reference(2 times) to message and free the memory    
       
  3502     lm_message_unref ( message );
       
  3503     lm_message_unref ( message );
       
  3504     
       
  3505     iLog->Log ( _L ( "lm_message_ref passed" ) );
       
  3506     
       
  3507     return KErrNone;
       
  3508 }
       
  3509 
       
  3510 
       
  3511 // ----------------------------------------------------------------------------
       
  3512 // Ctstlm::lm_message_unref 
       
  3513 // Description:Removes a reference from message. When no more references are 
       
  3514 //             present, the message is freed.
       
  3515 //             Check the total available heap space
       
  3516 //             Construct a new message by using lm_message_new
       
  3517 //             Check that available heap space is reduced
       
  3518 //             Decrement the reference from message
       
  3519 //             Check the available heap is equal to what it was before
       
  3520 // Arguements :
       
  3521 //   message  : an LmMessage
       
  3522 // Returns    : None
       
  3523 // ----------------------------------------------------------------------------
       
  3524 //
       
  3525 TInt Ctstlm::lm_message_unrefL ( CStifItemParser& /*aItem*/ )
       
  3526 {
       
  3527 	LmMessage *message;
       
  3528 	RHeap&    heap_handle = User::Heap();
       
  3529 	TInt 	  largest_free_block;
       
  3530 	TInt      heap_available_before;
       
  3531 	TInt      heap_available_after;
       
  3532 	
       
  3533 	iLog->Log ( _L ( "In lm_message_unref" ) );
       
  3534 	
       
  3535 	// Get the total heap space before constructing a message
       
  3536 	iLog->Log ( _L ( "Getting the heap size before message construction" ) );	
       
  3537 	heap_available_before = heap_handle.Available ( largest_free_block );
       
  3538 		
       
  3539 	// Construct a message 
       
  3540 	iLog->Log ( _L ( "Construct a message" ) );
       
  3541 	
       
  3542 	message = lm_message_new ( NULL, LM_MESSAGE_TYPE_MESSAGE );
       
  3543 	if ( !message )
       
  3544 	{
       
  3545 		iLog->Log ( _L ( "lm_message_new failed" ) );
       
  3546 		return KErrGeneral;
       
  3547 	}
       
  3548 	
       
  3549 	// Decrement the reference from message
       
  3550 	iLog->Log ( _L ( "Remove the reference from the message" ) );
       
  3551 	lm_message_unref ( message );
       
  3552 	
       
  3553 	// Get the heap space after freeing memory
       
  3554 	iLog->Log ( _L ( "Getting the heap size after freeing the memory" ) );
       
  3555 	heap_available_after = heap_handle.Available ( largest_free_block );
       
  3556 	
       
  3557 	// Compare the heap size
       
  3558 	iLog->Log ( _L ( "Comparing heap size before and after freeing memory" ) );
       
  3559 	
       
  3560 	if ( heap_available_after != heap_available_before )
       
  3561 	{
       
  3562 		iLog->Log ( _L ( "heap_available_before = %d, heap_available_after = %d" ),
       
  3563 		                  heap_available_before, heap_available_after );
       
  3564 		iLog->Log ( _L ( "Available memory is not as expected after freeing" ) );
       
  3565 		return KErrGeneral;
       
  3566 	}
       
  3567 	
       
  3568 	iLog->Log ( _L ( "Expected: heap_available_before is equal to heap_available_after" ) );
       
  3569 	iLog->Log ( _L ( "heap_available_before = %d, heap_available_after = %d" ),
       
  3570 	                  heap_available_before, heap_available_after );
       
  3571 	
       
  3572 	return KErrNone;
       
  3573 }
       
  3574 
       
  3575 
       
  3576 // ----------------------------------------------------------------------------
       
  3577 // Ctstlm::lm_message_handler_new
       
  3578 // Description:Creates a new message handler.This can be set to handle incoming
       
  3579 //             messages and when a message of type the handler is registered to 
       
  3580 //             handle is received function will be called and user_data will be
       
  3581 //             passed to it. notify is called when the message handler is freed,
       
  3582 //             that way any memory allocated by user_data can be freed.
       
  3583 // Arguements :
       
  3584 //  function  : a callback
       
  3585 //  user_data : user data passed to function
       
  3586 //  notify    : function called when the message handler is freed
       
  3587 // Returns    : a newly created message handler
       
  3588 //
       
  3589 // Note       : This test case requires UI mode to select Access point
       
  3590 // ----------------------------------------------------------------------------
       
  3591 //
       
  3592 TInt Ctstlm::lm_message_handler_newL ( CStifItemParser& /*aItem*/ )
       
  3593 {
       
  3594 	LmMessageHandler *handler      = NULL;
       
  3595 	
       
  3596 	iLog->Log ( _L ( "In lm_message_handler_new" ) );
       
  3597 	
       
  3598 	// Create a new message handler
       
  3599 	handler = lm_message_handler_new ( handle_messages, NULL, NULL );
       
  3600 	if ( !handler )
       
  3601 		{
       
  3602 		iLog->Log ( _L ( "lm_message_handler_new failed" ) );
       
  3603 		return KErrGeneral;
       
  3604 		}
       
  3605 		
       
  3606 	// Validate the handler
       
  3607 	if ( !lm_message_handler_is_valid ( handler ) )
       
  3608 		{
       
  3609 		iLog->Log ( _L ( "message handler is not valid" ) );
       
  3610 		lm_message_handler_unref ( handler );
       
  3611 		return KErrGeneral;
       
  3612 		}
       
  3613 	
       
  3614 	iLog->Log ( _L ( "lm_message_handler_new passed" ) );
       
  3615 	
       
  3616 	return KErrNone;
       
  3617 }
       
  3618 
       
  3619 
       
  3620 // ----------------------------------------------------------------------------
       
  3621 // Ctstlm::lm_message_handler_invalidate
       
  3622 // Description:Invalidates the handler. Useful if you need to cancel a reply
       
  3623 // Arguements :
       
  3624 //   handler  : an LmMessageHandler
       
  3625 // Returns    : None
       
  3626 // ----------------------------------------------------------------------------
       
  3627 //
       
  3628 TInt Ctstlm::lm_message_handler_invalidateL ( CStifItemParser& /*aItem*/ )
       
  3629 {
       
  3630 	LmMessageHandler *handler      = NULL;	
       
  3631 	gboolean         IsValid;
       
  3632 		
       
  3633 	iLog->Log ( _L ( "In lm_message_handler_invalidate" ) );
       
  3634 	
       
  3635 	// Create a new message handler
       
  3636 	iLog->Log ( _L ( "Creat a new message handler" ) );
       
  3637 	
       
  3638 	handler = lm_message_handler_new ( handle_messages, NULL, NULL );
       
  3639 	if ( !handler )
       
  3640 	    {
       
  3641 		iLog->Log ( _L ( "lm_message_handler_new failed" ) );
       
  3642 		return KErrGeneral;
       
  3643 	    }
       
  3644 	
       
  3645 	// Invalidate the message handler ( handler->valid = FALSE )
       
  3646 	iLog->Log ( _L ( "Invalidate the handler" ) );
       
  3647 	lm_message_handler_invalidate ( handler );
       
  3648 	
       
  3649 	// Check for validity of message handler
       
  3650 	iLog->Log ( _L ( "Checking validity of message handler" ) );
       
  3651 	
       
  3652 	IsValid = lm_message_handler_is_valid ( handler );
       
  3653 	if ( IsValid )
       
  3654 	    {
       
  3655 		iLog->Log ( _L ( "lm_message_handler_invalidate failed" ) );		
       
  3656 		lm_message_handler_unref ( handler );
       
  3657 		return KErrGeneral;
       
  3658 	    }
       
  3659 	
       
  3660 	lm_message_handler_unref ( handler );	
       
  3661 	
       
  3662 	iLog->Log ( _L ( "lm_message_handler_invalidate passed" ) );	
       
  3663 	
       
  3664 	return KErrNone;
       
  3665 }
       
  3666 
       
  3667 
       
  3668 // ----------------------------------------------------------------------------
       
  3669 // Ctstlm::lm_message_handler_is_valid
       
  3670 // Description:Fetches whether the handler is valid or not.
       
  3671 // Arguements :
       
  3672 //   handler  : an LmMessageHandler
       
  3673 // Returns    : TRUE if handler is valid, otherwise FALSE
       
  3674 // ----------------------------------------------------------------------------
       
  3675 //
       
  3676 TInt Ctstlm::lm_message_handler_is_validL ( CStifItemParser& /*aItem*/ )
       
  3677 {
       
  3678 	LmMessageHandler *handler = NULL;
       
  3679 	
       
  3680 	iLog->Log ( _L ( "In lm_message_handler_is_valid" ) );
       
  3681 	
       
  3682 	// Create a new message handler
       
  3683 	iLog->Log ( _L ( "Constructing new message handler" ) );
       
  3684 	handler = lm_message_handler_new ( handle_messages, NULL, NULL );
       
  3685 	if ( !handler )
       
  3686 	    {
       
  3687 		iLog->Log ( _L ( "lm_message_handler_new failed" ) );
       
  3688 		return KErrGeneral;
       
  3689 	    }
       
  3690 	
       
  3691 	// Check the validity of the message handler
       
  3692 	iLog->Log ( _L ( "Check for validity of message handler" ) );
       
  3693 	if ( !lm_message_handler_is_valid ( handler ) )
       
  3694 	    {
       
  3695 		iLog->Log ( _L ( "lm_message_handler_is_valid failed" ) );
       
  3696 		lm_message_handler_unref ( handler );
       
  3697 		return KErrGeneral;
       
  3698 	    }
       
  3699 	
       
  3700 	// Invalidate the handler ( set handler->valid = FALSE )
       
  3701 	iLog->Log ( _L ( "Invalidate the message handler" ) );
       
  3702 	lm_message_handler_invalidate ( handler );
       
  3703 	
       
  3704 	// check for validity of message handler after invalidating
       
  3705 	iLog->Log ( _L ( "Check for validity after invalidating" ) );
       
  3706 	
       
  3707 	if ( lm_message_handler_is_valid ( handler ) )
       
  3708 	    {
       
  3709 		iLog->Log ( _L ( "lm_message_handler_is_valid failed" ) );
       
  3710 		lm_message_handler_unref ( handler );
       
  3711 		return KErrGeneral;
       
  3712 	    }
       
  3713 	
       
  3714 	lm_message_handler_unref ( handler );
       
  3715 	
       
  3716 	iLog->Log ( _L ( "lm_message_handler_is_valid passed" ) );
       
  3717 	
       
  3718 	return KErrNone;
       
  3719 }
       
  3720 
       
  3721 
       
  3722 // ----------------------------------------------------------------------------
       
  3723 // Ctstlm::lm_message_handler_ref
       
  3724 // Description:Adds a reference to handler
       
  3725 // Arguements :
       
  3726 //   handler  : an LmMessageHandler
       
  3727 // Returns    : the message handler
       
  3728 // ----------------------------------------------------------------------------
       
  3729 //
       
  3730 TInt Ctstlm::lm_message_handler_refL ( CStifItemParser& /*aItem*/ )
       
  3731 {
       
  3732 	LmMessageHandler *handler = NULL;	
       
  3733 	
       
  3734 	iLog->Log ( _L ( "In lm_message_handler_ref" ) );
       
  3735 	
       
  3736 	// Create a new message handler
       
  3737 	iLog->Log ( _L ( "Construct a new message handler" ) );
       
  3738 	
       
  3739 	handler = lm_message_handler_new ( handle_messages, NULL, NULL );
       
  3740 	if ( !handler )
       
  3741 	    {
       
  3742 		iLog->Log ( _L ( "lm_message_handler_new failed" ) );
       
  3743 		return KErrGeneral;
       
  3744 	    }	
       
  3745 	
       
  3746 	// Loudmouth don't have any API to check reference to handler
       
  3747 	// Therefore this test is considered as passed without checking
       
  3748 	
       
  3749 	iLog->Log ( _L ( "Remove a reference from the message handler" ) );
       
  3750 	lm_message_handler_unref ( handler );
       
  3751 	
       
  3752 	iLog->Log ( _L ( "lm_message_handler_ref passed" ) );
       
  3753 	
       
  3754 	return KErrNone;
       
  3755 }
       
  3756 
       
  3757 
       
  3758 // ----------------------------------------------------------------------------
       
  3759 // Ctstlm::lm_message_handler_unref
       
  3760 // Description:Removes a reference from handler. When no more references are 
       
  3761 //             present, the handler is freed
       
  3762 //             Check the total available heap space
       
  3763 //             Construct a new message handler
       
  3764 //             Check that available heap space is reduced
       
  3765 //             Remove reference from the message handler
       
  3766 //             Check the available heap is equal to what it was before
       
  3767 // Arguements :
       
  3768 //    handler : an LmMessageHandler
       
  3769 // Returns    : None
       
  3770 // ----------------------------------------------------------------------------
       
  3771 //
       
  3772 TInt Ctstlm::lm_message_handler_unrefL ( CStifItemParser& /*aItem*/ )
       
  3773 {
       
  3774 	LmMessageHandler *handler     = NULL;
       
  3775 	RHeap&            heap_handle = User::Heap();
       
  3776 	TInt              largest_free_block;
       
  3777 	TInt              heap_avail_before;
       
  3778 	TInt              heap_avail_after;
       
  3779 	
       
  3780 	iLog->Log ( _L ( "Inlm_message_handler_unref" ) );
       
  3781 	
       
  3782 	// Get the total heap size before creating new message handler
       
  3783 	iLog->Log ( _L ( "Get the heap size before allocating memory" ) );
       
  3784 	heap_avail_before = heap_handle.Available ( largest_free_block );
       
  3785 	
       
  3786 	// Create a new message handler
       
  3787 	iLog->Log ( _L ( "Construct a new message handler" ) );
       
  3788 	
       
  3789 	handler = lm_message_handler_new ( handle_messages, NULL, NULL );
       
  3790 	if ( !handler )
       
  3791 	    { 
       
  3792 		iLog->Log ( _L ( "lm_message_handler_new failed" ) );
       
  3793 		return KErrGeneral;
       
  3794 	    }
       
  3795 	
       
  3796 	// Remove a reference from the message handler
       
  3797 	iLog->Log ( _L ( "Freeing allocated memory" ) );
       
  3798 	lm_message_handler_unref ( handler );
       
  3799 	
       
  3800 	// Get the heap size after removing reference from message handler
       
  3801 	iLog->Log ( _L ( "Get the heap size after freeing memory" ) );
       
  3802 	heap_avail_after = heap_handle.Available ( largest_free_block );
       
  3803 	
       
  3804 	// Compare the heap size
       
  3805 	iLog->Log ( _L ( "Compare the heap size after freeing memory" ) );
       
  3806 	
       
  3807 	if ( heap_avail_before != heap_avail_after )
       
  3808 	    {
       
  3809 		iLog->Log ( _L ( "heap_avail_before = %d, heap_avail_after = %d" ),
       
  3810 		                  heap_avail_before, heap_avail_after );
       
  3811 		iLog->Log ( _L ( "Available memory is not as expected after freeing" ) );
       
  3812 		return KErrGeneral;		
       
  3813 	    }
       
  3814 	
       
  3815 	iLog->Log ( _L ( "Expected: heap_avail_before is equal to heap_avail_after" ) );
       
  3816 	iLog->Log ( _L ( "heap_avail_before = %d, heap_avail_after = %d" ),
       
  3817 	                 heap_avail_before, heap_avail_after );
       
  3818 	
       
  3819 	return KErrNone;
       
  3820 }
       
  3821 
       
  3822 
       
  3823 
       
  3824 // ----------------------------------------------------------------------------
       
  3825 // Ctstlm::lm_message_node_set_value
       
  3826 // Description:Sets the value of node. If a prev value is set it will be freed
       
  3827 // Arguements :
       
  3828 //   Node     : an LmMessageNode
       
  3829 //   value    : the new value
       
  3830 // Returns    : None
       
  3831 // ----------------------------------------------------------------------------
       
  3832 //
       
  3833 TInt Ctstlm::lm_message_node_set_get_valueL ( CStifItemParser& /*aItem*/ )
       
  3834 {
       
  3835 	LmMessage     *message       = NULL;
       
  3836 	LmMessageNode *Node          = NULL;
       
  3837 	const gchar   *SetUsername   = "Nokia";		
       
  3838 	
       
  3839 	iLog->Log ( _L ( "In lm_message_node_get_value" ) );
       
  3840 	
       
  3841 	// Construct a message with type = LM_MESSAGE_TYPE_MESSAGE
       
  3842 	iLog->Log ( _L ( "Construct a message" ) );
       
  3843 	
       
  3844 	message = lm_message_new ( NULL, LM_MESSAGE_TYPE_MESSAGE );
       
  3845 	if ( !message )
       
  3846 	{
       
  3847 		iLog->Log ( _L ( "lm_message_new failed" ) );
       
  3848 		return KErrGeneral;
       
  3849 	}
       
  3850 	
       
  3851 	// Retrive the root node from message
       
  3852 	iLog->Log ( _L ( "Retriving root node from the message" ) );
       
  3853 	Node = lm_message_get_node ( message );
       
  3854 	if ( !Node )
       
  3855 	    {
       
  3856 		iLog->Log ( _L ( "lm_message_get_node failed" ) );
       
  3857 		lm_message_unref ( message );
       
  3858 		return KErrGeneral;		
       
  3859 	    }
       
  3860 	
       
  3861 	// Set the value of the node
       
  3862 	iLog->Log ( _L ( "Set the value of the node" ) );
       
  3863 	lm_message_node_set_value ( Node, SetUsername );
       
  3864 	
       
  3865 	// Retrive the value of node
       
  3866 	iLog->Log ( _L ( "Retrive the value of the node" ) );
       
  3867 	const gchar *GetUsername = lm_message_node_get_value ( Node );	
       
  3868 	
       
  3869 	// Verify the result
       
  3870 	iLog->Log ( _L ( "Verify value of node" ) );	
       
  3871 	if ( strcmp ( SetUsername, GetUsername ) )
       
  3872 	    {
       
  3873 		iLog->Log ( _L ( "lm_message_set_value failed" ) );		
       
  3874 		lm_message_unref ( message );
       
  3875 	    lm_message_node_unref ( Node );
       
  3876 		return KErrGeneral;
       
  3877 	    }	
       
  3878 	
       
  3879 	lm_message_unref ( message );
       
  3880 	lm_message_node_unref ( Node );
       
  3881 	
       
  3882 	iLog->Log ( _L ( "lm_message_set_value passed" ) );
       
  3883 		
       
  3884 	return KErrNone;
       
  3885 }
       
  3886 
       
  3887 
       
  3888 // ----------------------------------------------------------------------------
       
  3889 // Ctstlm::lm_message_node_add_child
       
  3890 // Description:Add a child node with a name and value
       
  3891 // Arguements :
       
  3892 //   node     : an LmMessageNode
       
  3893 //   name     : name of the new child
       
  3894 //   value    : value of the new child
       
  3895 // Returns    : the newly created child
       
  3896 // ----------------------------------------------------------------------------
       
  3897 //
       
  3898 TInt Ctstlm::lm_message_node_add_childL ( CStifItemParser& /*aItem*/ )
       
  3899 {
       
  3900 	LmMessage     *message   = NULL;
       
  3901 	LmMessageNode *Node      = NULL;	
       
  3902 	const gchar   *Username  = "Nokia";		
       
  3903 	
       
  3904 	iLog->Log ( _L ( "In lm_message_node_add_child" ) );
       
  3905 	
       
  3906 	// Construct a message with type = LM_MESSAGE_TYPE_MESSAGE
       
  3907 	iLog->Log ( _L ( "construct a message" ) );
       
  3908 	
       
  3909 	message = lm_message_new ( NULL, LM_MESSAGE_TYPE_MESSAGE );
       
  3910 	if ( !message )
       
  3911 	    {
       
  3912 		iLog->Log ( _L ( "lm_message_new failed" ) );
       
  3913 		return KErrGeneral;
       
  3914 	    }
       
  3915 	
       
  3916 	// Retrive the root node from message
       
  3917 	iLog->Log ( _L ( "Retrive the root node from message" ) );
       
  3918 	
       
  3919 	Node = lm_message_get_node ( message );
       
  3920 	if ( !Node )
       
  3921 	    {
       
  3922 		iLog->Log ( _L ( "lm_message_get_node failed" ) );
       
  3923 		lm_message_unref ( message );
       
  3924 		return KErrGeneral;		
       
  3925 	    }
       
  3926 	
       
  3927 	// Add a child
       
  3928 	iLog->Log ( _L ( "Add a child 'username' to node" ) );
       
  3929 	lm_message_node_add_child ( Node, "username", Username );
       
  3930 	
       
  3931 	// Verify the child
       
  3932 	iLog->Log ( _L ( "Verify the child" ) );
       
  3933 	if ( !lm_message_node_get_child ( Node, "username" ) ) 
       
  3934 	    {
       
  3935 		iLog->Log ( _L ( "lm_message_add_child failed" ) );
       
  3936 		lm_message_unref ( message );
       
  3937 		lm_message_node_unref ( Node );		
       
  3938 		return KErrGeneral;
       
  3939 	    }
       
  3940 	
       
  3941 	iLog->Log ( _L ( "Freeing allocated resources" ) );
       
  3942 	lm_message_unref ( message );
       
  3943 	lm_message_node_unref ( Node );	
       
  3944 	
       
  3945 	iLog->Log ( _L ( "lm_message_node_add_child passed" ) );
       
  3946 	
       
  3947 	return KErrNone;	    
       
  3948 }
       
  3949 
       
  3950 
       
  3951 
       
  3952 // ----------------------------------------------------------------------------
       
  3953 // Ctstlm::lm_message_node_find_child
       
  3954 // Description:Locates a child among all children of node. The entire tree will
       
  3955 //             be searched until a child with a name child_name is located.
       
  3956 // Arguements :
       
  3957 //    node    : an LmMessageNode
       
  3958 //    name    : name of the child to find
       
  3959 // Returns    : located child or NULL if not found
       
  3960 // ----------------------------------------------------------------------------
       
  3961 //
       
  3962 TInt Ctstlm::lm_message_node_find_childL ( CStifItemParser& /*aItem*/ )
       
  3963 {
       
  3964 	LmMessage     *message   = NULL;
       
  3965 	LmMessageNode *Node      = NULL;	
       
  3966 	const gchar   *Username  = "Nokia";	
       
  3967 	const gchar   *Password  = "Nokia";		
       
  3968 	
       
  3969 	iLog->Log ( _L ( "In lm_message_node_find_child" ) );
       
  3970 	
       
  3971 	// Construct a message with type = LM_MESSAGE_TYPE_MESSAGE
       
  3972 	iLog->Log ( _L ( "Construct a message" ) );	
       
  3973 	message = lm_message_new ( NULL, LM_MESSAGE_TYPE_MESSAGE );
       
  3974 	if ( !message )
       
  3975 	    {
       
  3976 		iLog->Log ( _L ( "lm_message_new failed" ) );
       
  3977 		return KErrGeneral;
       
  3978 	    }
       
  3979 	
       
  3980 	// Retrive the root node from message
       
  3981 	iLog->Log ( _L ( "Retrive the root node from the message" ) );	
       
  3982 	Node = lm_message_get_node ( message );
       
  3983 	if ( !Node )
       
  3984 	    {
       
  3985 		iLog->Log ( _L ( "lm_message_get_node failed" ) );
       
  3986 		lm_message_unref ( message );
       
  3987 		return KErrGeneral;		
       
  3988 	    }
       
  3989 	
       
  3990 	// Add childrens
       
  3991 	iLog->Log ( _L ( "Adding childrens 'username' and 'password'" ) );
       
  3992 	lm_message_node_add_child ( Node, "username", Username );
       
  3993 	lm_message_node_add_child ( Node, "password", Password );
       
  3994 	
       
  3995 	// Locate the child 'username'	
       
  3996 	iLog->Log ( _L ( "Locate the child 'username'" ) );	
       
  3997 	if ( !lm_message_node_find_child ( Node, "username" ) ) 
       
  3998 	    {	    
       
  3999 		iLog->Log ( _L ( "lm_message_node_find_child: child 'username' not found" ) );
       
  4000 		lm_message_unref ( message );
       
  4001 		lm_message_node_unref ( Node );		
       
  4002 		return KErrGeneral;
       
  4003 	    }
       
  4004 	
       
  4005 	// Locate the child 'password'
       
  4006 	if ( !lm_message_node_get_child ( Node, "password" ) )
       
  4007 	    {
       
  4008 	    iLog->Log ( _L ( "lm_message_node_find_child: child 'password' not found" ) );		
       
  4009 		lm_message_unref ( message );
       
  4010 		lm_message_node_unref ( Node );
       
  4011 		return KErrGeneral;
       
  4012 	    }	
       
  4013 		
       
  4014 	lm_message_unref ( message );
       
  4015 	lm_message_node_unref ( Node );	
       
  4016 	
       
  4017 	iLog->Log ( _L ( "lm_message_node_find_child passed" ) );
       
  4018 	
       
  4019 	return KErrNone;	    
       
  4020 }
       
  4021 
       
  4022 
       
  4023 // ----------------------------------------------------------------------------
       
  4024 // Ctstlm::lm_message_node_set_get_attributes
       
  4025 // Description:Sets a list of attributes. The arguements should be names and 
       
  4026 //             correspoinding values and needs to be ended with NULL.
       
  4027 // Arguements :
       
  4028 //    node    : an LmMessageNode
       
  4029 //    name    : first attribute, should be fallowed by string with value
       
  4030 //    ..      : rest of the name/value pairs
       
  4031 // Returns    : None
       
  4032 // ----------------------------------------------------------------------------
       
  4033 //
       
  4034 TInt Ctstlm::lm_message_node_set_get_attributesL ( CStifItemParser& /*aItem*/ )
       
  4035 {
       
  4036 	LmMessage     *message   = NULL;
       
  4037 	LmMessageNode *Node      = NULL;	
       
  4038 	const gchar   *Value     = "Nokia";		
       
  4039 	
       
  4040 	iLog->Log ( _L ( "In lm_message_node_set_attributes" ) );
       
  4041 	
       
  4042 	// Construct a message with type = LM_MESSAGE_TYPE_MESSAGE
       
  4043 	iLog->Log ( _L ( "Construct a message" ) );
       
  4044 	
       
  4045 	message = lm_message_new ( NULL, LM_MESSAGE_TYPE_MESSAGE );
       
  4046 	if ( !message )
       
  4047 	    {
       
  4048 		iLog->Log ( _L ( "lm_message_new failed" ) );
       
  4049 		return KErrGeneral;
       
  4050 	    }
       
  4051 	
       
  4052 	// Retrive the root node from message
       
  4053 	iLog->Log ( _L ( "Retrive the root node from the message" ) );
       
  4054 	
       
  4055 	Node = lm_message_get_node ( message );
       
  4056 	if ( !Node )
       
  4057 	    {
       
  4058 		iLog->Log ( _L ( "lm_message_get_node failed" ) );
       
  4059 		lm_message_unref ( message );
       
  4060 		return KErrGeneral;		
       
  4061 	    }
       
  4062 	
       
  4063 	// Set attributes
       
  4064 	iLog->Log ( _L ("Setting attributes 'username', 'password' and 'xmlns'" ) );
       
  4065 	lm_message_node_set_attributes ( Node, 
       
  4066 	                                 "username", Value,
       
  4067 	                                 "password", Value,
       
  4068 	                                 "xmlns", "jabber:iq:register",
       
  4069 	                                 NULL );
       
  4070 	                                 
       
  4071     // Verify the attributes set
       
  4072     iLog->Log ( _L (" Verify the attributes" ) );
       
  4073     
       
  4074     if ( !lm_message_node_get_attribute ( Node, "username" ) )
       
  4075         {
       
  4076     	iLog->Log ( _L ( "lm_message_set_attributes failed for username" ) );
       
  4077     	lm_message_unref ( message );
       
  4078     	lm_message_node_unref ( Node );
       
  4079     	return KErrGeneral;
       
  4080         }
       
  4081     
       
  4082     if ( !lm_message_node_get_attribute ( Node, "password" ) )
       
  4083         {
       
  4084     	iLog->Log ( _L ( "lm_message_set_attributes failed for password" ) );
       
  4085     	lm_message_unref ( message );
       
  4086     	lm_message_node_unref ( Node );
       
  4087     	return KErrGeneral;
       
  4088         }
       
  4089     
       
  4090     if ( !lm_message_node_get_attribute ( Node, "xmlns" ) )
       
  4091         {
       
  4092     	iLog->Log ( _L ( "lm_message_set_attributes failed for xmlns" ) );
       
  4093     	lm_message_unref ( message );
       
  4094     	lm_message_node_unref ( Node );
       
  4095     	return KErrGeneral;
       
  4096         }
       
  4097     
       
  4098     lm_message_unref ( message );
       
  4099     lm_message_node_unref ( Node );
       
  4100     
       
  4101     iLog->Log ( _L ( "lm_message_node_set_attributes passed" ) );
       
  4102     
       
  4103     return KErrNone;
       
  4104 }
       
  4105 
       
  4106 
       
  4107 
       
  4108 
       
  4109 
       
  4110 // ----------------------------------------------------------------------------
       
  4111 // Ctstlm::lm_message_node_set_get_raw_mode
       
  4112 // Description:Checks if the nodes values should be sent as raw mode
       
  4113 // Arguements :
       
  4114 //    node    : an LmMessageNode
       
  4115 // Returns    : TRUE if nodes value should be sent as is
       
  4116 //              FALSE if the value will be escaped before sending
       
  4117 // ----------------------------------------------------------------------------
       
  4118 //
       
  4119 TInt Ctstlm::lm_message_node_set_get_raw_modeL ( CStifItemParser& /*aItem*/ )
       
  4120 {
       
  4121 	LmMessage     *message   = NULL;
       
  4122 	LmMessageNode *Node      = NULL;		
       
  4123 	
       
  4124 	iLog->Log ( _L ( "In lm_message_node_set_raw_mode" ) );
       
  4125 	
       
  4126 	// Construct a message with type = LM_MESSAGE_TYPE_MESSAGE
       
  4127 	iLog->Log ( _L ( "Construct a message" ) );
       
  4128 		
       
  4129 	message = lm_message_new ( NULL, LM_MESSAGE_TYPE_MESSAGE );
       
  4130 	if ( !message )
       
  4131 	    {
       
  4132 		iLog->Log ( _L ( "lm_message_new failed" ) );
       
  4133 		return KErrGeneral;
       
  4134 	    }
       
  4135 	
       
  4136 	// Retrive the root node from message
       
  4137 	iLog->Log ( _L ( "Retrive the root node from message" ) );	
       
  4138 	Node = lm_message_get_node ( message );
       
  4139 	if ( !Node )
       
  4140 	    {
       
  4141 		iLog->Log ( _L ( "lm_message_get_node failed" ) );
       
  4142 		lm_message_unref ( message );
       
  4143 		return KErrGeneral;		
       
  4144 	    }
       
  4145 	
       
  4146 	// Set the raw mode to TRUE
       
  4147 	iLog->Log ( _L ( "Set the node to raw mode" ) );
       
  4148 	lm_message_node_set_raw_mode ( Node, TRUE );
       
  4149 	
       
  4150 	// Check if the Node is in raw mode or not after setting
       
  4151 	iLog->Log ( _L ( "Check for raw mode after setting" ) );
       
  4152 	if ( !lm_message_node_get_raw_mode ( Node ) )
       
  4153 	    {
       
  4154 		iLog->Log ( _L ( "get_raw_mode returned FALSE after setting raw mode" ) );
       
  4155 		lm_message_unref ( message );
       
  4156 		lm_message_node_unref ( Node );		
       
  4157 		return KErrGeneral;
       
  4158 	    }
       
  4159 	
       
  4160 	// Set the raw mode to FALSE
       
  4161 	iLog->Log ( _L ( "Unset the raw mode" ) );
       
  4162 	lm_message_node_set_raw_mode ( Node, FALSE );
       
  4163 	
       
  4164 	// Check for raw mode
       
  4165 	iLog->Log ( _L ( "Check for raw mode after unsetting" ) );
       
  4166 	if ( lm_message_node_get_raw_mode ( Node ) )
       
  4167 	    {
       
  4168 		iLog->Log ( _L ( "get_raw_mode returned TRUE after unsetting" ) );
       
  4169 		lm_message_unref ( message );
       
  4170 		lm_message_node_unref ( Node );		
       
  4171 		return KErrGeneral;
       
  4172 	    }
       
  4173 		
       
  4174 	lm_message_unref ( message );
       
  4175 	lm_message_node_unref ( Node );	
       
  4176 	
       
  4177 	iLog->Log ( _L ( "lm_message_node_set_raw_mode passed" ) );
       
  4178 	 
       
  4179 	return KErrNone;    
       
  4180 }
       
  4181 
       
  4182 
       
  4183 // ----------------------------------------------------------------------------
       
  4184 // Ctstlm::lm_message_node_ref
       
  4185 // Description:Adds a reference to node
       
  4186 // Arguements :
       
  4187 //    node    : an LmMessageNode
       
  4188 // Returns    : the node
       
  4189 // ----------------------------------------------------------------------------
       
  4190 //
       
  4191 TInt Ctstlm::lm_message_node_refL ( CStifItemParser& /*aItem*/ )
       
  4192 {
       
  4193     LmMessage     *message   = NULL;
       
  4194 	LmMessageNode *Node      = NULL;		
       
  4195 	
       
  4196 	iLog->Log ( _L ( "In lm_message_node_ref" ) );
       
  4197 	
       
  4198 	// Construct a message with type = LM_MESSAGE_TYPE_MESSAGE
       
  4199 	iLog->Log ( _L ( "Construct a message" ) );
       
  4200 		
       
  4201 	message = lm_message_new ( NULL, LM_MESSAGE_TYPE_MESSAGE );
       
  4202 	if ( !message )
       
  4203 	    {
       
  4204 		iLog->Log ( _L ( "lm_message_new failed" ) );
       
  4205 		return KErrGeneral;
       
  4206 	    }
       
  4207 	
       
  4208 	// Retrive the root node from message
       
  4209 	iLog->Log ( _L ( "Retrive the root node from message" ) );	
       
  4210 	Node = lm_message_get_node ( message );
       
  4211 	if ( !Node )
       
  4212 	    {
       
  4213 		iLog->Log ( _L ( "lm_message_get_node failed" ) );
       
  4214 		lm_message_unref ( message );
       
  4215 		return KErrGeneral;		
       
  4216 	    }	
       
  4217 	    
       
  4218 	// Add a reference to  node
       
  4219 	lm_message_node_ref ( Node );
       
  4220 	
       
  4221 	// Loudmouth dont have any API to check reference on message node
       
  4222 	// Therefore lm_message_node_ref is considered as passed without checking	
       
  4223 	lm_message_unref ( message );
       
  4224 	lm_message_node_unref ( Node );	
       
  4225 	
       
  4226 	iLog->Log ( _L ( "lm_message_node_ref passed" ) );
       
  4227 	
       
  4228 	return KErrNone;
       
  4229 }
       
  4230 
       
  4231 
       
  4232 // ----------------------------------------------------------------------------
       
  4233 // Ctstlm::lm_message_node_unref
       
  4234 // Description:  Removes a reference from the the node. When no more 
       
  4235 //             reference are present, the node is freed. When freed 
       
  4236 //             lm_message_node_unref() will be called on all children.
       
  4237 //               Check the size of the heap just to verify whether node 
       
  4238 //             is freed or not when no more references to the node
       
  4239 // Arguements :
       
  4240 //    node    : an LmMessageNode
       
  4241 // Returns    : Node
       
  4242 // ----------------------------------------------------------------------------
       
  4243 //
       
  4244 TInt Ctstlm::lm_message_node_unrefL ( CStifItemParser& /*aItem*/ )
       
  4245 {
       
  4246     LmMessage     *message     = NULL;
       
  4247 	LmMessageNode *Node        = NULL;
       
  4248 	
       
  4249 	RHeap&         heap_handle = User::Heap();
       
  4250 	TInt           largest_free_block;
       
  4251 	TInt           heap_avail_before;
       
  4252 	TInt           heap_avail_after; 		
       
  4253 	
       
  4254 	iLog->Log ( _L ( "In lm_message_node_unref" ) );
       
  4255 	
       
  4256 	// Get the heap size before constructing a message 
       
  4257 	heap_avail_before = heap_handle.Available ( largest_free_block );
       
  4258 	
       
  4259 	// Construct a message with type = LM_MESSAGE_TYPE_MESSAGE
       
  4260 	iLog->Log ( _L ( "Construct a message" ) );
       
  4261 		
       
  4262 	message = lm_message_new ( NULL, LM_MESSAGE_TYPE_MESSAGE );
       
  4263 	if ( !message )
       
  4264 	    {
       
  4265 		iLog->Log ( _L ( "lm_message_new failed" ) );
       
  4266 		return KErrGeneral;
       
  4267 	    }
       
  4268 	
       
  4269 	// Retrive the root node from message
       
  4270 	iLog->Log ( _L ( "Retrive the root node from message" ) );	
       
  4271 	Node = lm_message_get_node ( message );
       
  4272 	if ( !Node )
       
  4273 	    {
       
  4274 		iLog->Log ( _L ( "lm_message_get_node failed" ) );
       
  4275 		lm_message_unref ( message );
       
  4276 		return KErrGeneral;		
       
  4277 	    }	
       
  4278 	    
       
  4279 	// Remove reference from the message
       
  4280 	iLog->Log ( _L ( "Remove reference from the message" ) );
       
  4281 	lm_message_unref ( message );
       
  4282 	
       
  4283 	// Remove reference from the node
       
  4284 	iLog->Log ( _L ( "Remove a reference from the node" ) );
       
  4285 	lm_message_node_unref ( Node );
       
  4286 	
       
  4287 	// Get the heap size after removing references
       
  4288 	heap_avail_after = heap_handle.Available ( largest_free_block );
       
  4289 	
       
  4290 	// Verify the heap size
       
  4291 	if ( heap_avail_after != heap_avail_before )
       
  4292 	    {
       
  4293 		iLog->Log ( _L ( "heap_avail_before = %d, heap_avail_after = %d" ),
       
  4294 		                  heap_avail_before, heap_avail_after );
       
  4295 		iLog->Log ( _L ( "Available memory is not as expected after freeing" ) );
       
  4296 		return KErrGeneral;
       
  4297 	    }
       
  4298 	
       
  4299 	iLog->Log ( _L ( "Expected: heap_available_before is equal to heap_available_after" ) );
       
  4300 	iLog->Log ( _L ( "heap_avail_before = %d, heap_avail_after = %d" ),
       
  4301 	                  heap_avail_before, heap_avail_after );
       
  4302 		
       
  4303 	return KErrNone;
       
  4304 }
       
  4305 
       
  4306 
       
  4307 // ----------------------------------------------------------------------------
       
  4308 // Ctstlm::lm_message_node_to_string
       
  4309 // Description:Returns an XML string representing the node. This is what
       
  4310 //             is sent over the connection. This is used internally by 
       
  4311 //             loudmouth and is external for debugging  purposes
       
  4312 // Arguements :
       
  4313 //    node    : an LmMessageNode
       
  4314 // Returns    : an XML string representation of node
       
  4315 // ----------------------------------------------------------------------------
       
  4316 //
       
  4317 TInt Ctstlm::lm_message_node_to_stringL ( CStifItemParser& /*aItem*/ )
       
  4318 {
       
  4319 	LmMessage     *message     = NULL;	
       
  4320 	gchar         *XmlString      = NULL;
       
  4321 	
       
  4322 	
       
  4323 	iLog->Log ( _L ( "In lm_message_node_to_string" ) );
       
  4324 	
       
  4325 	// Construct a message with type = LM_MESSAGE_TYPE_PRESENCE
       
  4326 	iLog->Log ( _L ( "Construct a message with type=presence" ) );
       
  4327 		
       
  4328 	message = lm_message_new ( NULL, LM_MESSAGE_TYPE_PRESENCE );
       
  4329 	if ( !message )
       
  4330 	    {
       
  4331 		iLog->Log ( _L ( "lm_message_new failed for type = PRESENCE" ) );
       
  4332 		return KErrGeneral;
       
  4333 	    }
       
  4334 	
       
  4335 	// Convert node to XML string
       
  4336 	XmlString = lm_message_node_to_string ( message->node );
       
  4337 	
       
  4338 	// Check in XML string for <presence> stanza
       
  4339 	if ( !g_strrstr ( XmlString, "presence" ) )
       
  4340 	{
       
  4341 		iLog->Log ( _L ( "XML string doesnt contain <presence> stanza" ) );
       
  4342 		lm_message_unref ( message );
       
  4343 		return KErrGeneral;
       
  4344 	}
       
  4345 	
       
  4346 	// Construct a message with type=LM_MESSAGE_TYPE_IQ
       
  4347 	lm_message_unref ( message );
       
  4348 	message = lm_message_new ( NULL, LM_MESSAGE_TYPE_IQ );
       
  4349 	if ( !message )
       
  4350 	{
       
  4351 		iLog->Log ( _L ( "lm_message_new failed for type = IQ" ) );
       
  4352 		return KErrGeneral;
       
  4353 	}
       
  4354 	
       
  4355 	// Convert the message node to XML string
       
  4356 	XmlString = lm_message_node_to_string ( message->node );
       
  4357 	
       
  4358 	// Check in XML string for <iq> stanza
       
  4359 	if ( !g_strrstr ( XmlString, "iq" ) )
       
  4360 	{
       
  4361 		iLog->Log ( _L ( "XML string doesnt contain <iq> stanza" ) );
       
  4362 		lm_message_unref ( message );
       
  4363 		return KErrGeneral;
       
  4364 	}
       
  4365 	
       
  4366 	iLog->Log ( _L ( "lm_message_node_to_string passed" ) );
       
  4367 	lm_message_unref ( message );
       
  4368 	
       
  4369 	return KErrNone;  
       
  4370 }
       
  4371 
       
  4372 
       
  4373 // ---------------------------------------------------------------------------
       
  4374 // Ctstlm::lm_ssl_new
       
  4375 // Description: Creates a new ssl struct
       
  4376 // Arguements :
       
  4377 //      expected_fingerprint : The expected fingerprint. ssl_function will be
       
  4378 //                             called if there is a mismatch. NULL if you 
       
  4379 //                             are not interested in this check.
       
  4380 //      ssl_cb               : Callback called to inform the user of a problem
       
  4381 //                             during setting up the SSL connection and how 
       
  4382 //                             to proceed.
       
  4383 //      user_data            : Data sent with the callback
       
  4384 //      notify               : Function to free user_data when the connection
       
  4385 //                             is finished. 
       
  4386 // Returns    : A new LmSSL struct
       
  4387 // ---------------------------------------------------------------------------
       
  4388 //
       
  4389 TInt Ctstlm::lm_ssl_newL ( CStifItemParser& /*aItem*/ )
       
  4390 {
       
  4391 	LmSSL *ssl = NULL;
       
  4392 	
       
  4393 	iLog->Log ( _L ( "In lm_ssl_new" ) );
       
  4394 	
       
  4395 	ssl = lm_ssl_new ( NULL, ( LmSSLFunction ) ssl_cb, NULL, NULL );
       
  4396 	if ( !ssl )
       
  4397 		{
       
  4398 		iLog->Log ( _L ( "lm_ssl_new failed" ) );
       
  4399 		return KErrGeneral;
       
  4400 		}		
       
  4401 	
       
  4402 	lm_ssl_unref ( ssl );
       
  4403 	
       
  4404 	iLog->Log ( _L ( "lm_ssl_new passed" ) );
       
  4405 	
       
  4406 	return KErrNone;		
       
  4407 }
       
  4408 
       
  4409 // ---------------------------------------------------------------------------
       
  4410 // Ctstlm::lm_ssl_is_supportedL
       
  4411 // Description: Checks wheather the Loudmouth supports SSL or not.
       
  4412 // Arguements : None
       
  4413 // Returns    : TRUE if loudmouth supports SSL, FALSE otherwise
       
  4414 // ---------------------------------------------------------------------------
       
  4415 //
       
  4416 TInt Ctstlm::lm_ssl_is_supportedL ( CStifItemParser& /*aItem*/ )
       
  4417 {	
       
  4418 	iLog->Log ( _L ( "In lm_ssl_is_supported" ) );
       
  4419 	
       
  4420 	if ( !lm_ssl_is_supported() )
       
  4421 		{
       
  4422 		iLog->Log ( _L ( "Loudmouth installation doesn't support SSL" ) );
       
  4423 		}
       
  4424 	else
       
  4425 		{
       
  4426 		iLog->Log ( _L ( "Loudmouth supports SSL" ) );		
       
  4427 		}
       
  4428 		
       
  4429 	iLog->Log ( _L ( "lm_ssl_is_supported passed" ) );
       
  4430 	
       
  4431 	return KErrNone;
       
  4432 }
       
  4433 
       
  4434 
       
  4435 // ---------------------------------------------------------------------------
       
  4436 // Ctstlm::lm_ssl_get_fingerprintL
       
  4437 // Description: Returns the MD5 fingerprint of the remote server's certificate.
       
  4438 // Arguements : 
       
  4439 //      ssl   : An LmSSL
       
  4440 // Returns    : A 16-byte array indicating fingerprint or NULL if unknow
       
  4441 // ---------------------------------------------------------------------------
       
  4442 //
       
  4443 TInt Ctstlm::lm_ssl_get_fingerprintL ( CStifItemParser& /*aItem*/ )
       
  4444 {
       
  4445 	LmSSL *ssl;	
       
  4446 	
       
  4447 	iLog->Log ( _L ( "In lm_ssl_get_fingerprint" ) );
       
  4448 	
       
  4449 	ssl = lm_ssl_new ( "--ssl", ( LmSSLFunction )ssl_cb, NULL, NULL );
       
  4450 	
       
  4451 	const gchar *fingerprint = lm_ssl_get_fingerprint ( ssl );
       
  4452 	if ( !fingerprint )
       
  4453 		{
       
  4454 		iLog->Log ( _L ( "Not able to get the remote server's certificate" ) );
       
  4455 		}
       
  4456 	
       
  4457 	iLog->Log ( _L ( "lm_ssl_get_fingerprint passed" ) );
       
  4458 	lm_ssl_unref ( ssl );
       
  4459 	
       
  4460 	return KErrNone;
       
  4461 }
       
  4462 
       
  4463 
       
  4464 // ---------------------------------------------------------------------------
       
  4465 // Ctstlm::lm_ssl_ref
       
  4466 // Description: Adds a reference to ssl
       
  4467 // Arguements : 
       
  4468 //      ssl   : An LmSSL
       
  4469 // Returns    : LmSSL
       
  4470 // ---------------------------------------------------------------------------
       
  4471 //
       
  4472 TInt Ctstlm::lm_ssl_refL ( CStifItemParser& /*aItem*/ )
       
  4473 {
       
  4474 	LmSSL *ssl;
       
  4475 	
       
  4476 	iLog->Log ( _L ( "In lm_ssl_ref" ) );
       
  4477 	
       
  4478 	ssl = lm_ssl_new ( NULL, NULL, NULL, NULL );
       
  4479 	if ( !ssl )
       
  4480 		{
       
  4481 		iLog->Log ( _L ( "lm_ssl_new failed" ) );
       
  4482 		return KErrGeneral;
       
  4483 		}
       
  4484 	
       
  4485 	// Add a reference to ssl
       
  4486 	lm_ssl_ref ( ssl );
       
  4487 	
       
  4488 	// Loudmouth don't have any API to get the reference to ssl.
       
  4489 	// Therefore this test case is considered as passed without verifying it	
       
  4490 	lm_ssl_unref ( ssl );
       
  4491 	
       
  4492 	iLog->Log ( _L ( "lm_ssl_ref passed" ) );
       
  4493 	return KErrNone;	
       
  4494 }
       
  4495 
       
  4496 
       
  4497 // ---------------------------------------------------------------------------
       
  4498 // Ctstlm::lm_ssl_unref
       
  4499 // Description: Removes a reference from ssl. 
       
  4500 //              When no more references are present, ssl is freed.
       
  4501 //              Check the heap size to ensure that lm_ssl_unref frees the ssl
       
  4502 //              when no more references are present.
       
  4503 // Arguements : 
       
  4504 //      ssl   : An LmSSL
       
  4505 // Returns    : None
       
  4506 // ---------------------------------------------------------------------------
       
  4507 //
       
  4508 TInt Ctstlm::lm_ssl_unrefL ( CStifItemParser& /*aItem*/ )
       
  4509 {	
       
  4510 	RHeap& heap_handle = User::Heap();
       
  4511 	TInt   largest_free_block;
       
  4512 	TInt   heap_avail_before;
       
  4513 	TInt   heap_avail_after;
       
  4514 	
       
  4515 	LmSSL  *ssl = NULL;
       
  4516 	
       
  4517 	iLog->Log ( _L ( "In lm_ssl_unref" ) );
       
  4518 	
       
  4519 	// Get the heap size before creating a new ssl
       
  4520 	heap_avail_before = heap_handle.Available ( largest_free_block );
       
  4521 	
       
  4522 	// Create a new ssl
       
  4523 	ssl = lm_ssl_new ( NULL, NULL, NULL, NULL );
       
  4524 	if ( !ssl )
       
  4525 		{
       
  4526 		iLog->Log ( _L ( "lm_ssl_new failed" ) );
       
  4527 		return KErrGeneral;
       
  4528 		}
       
  4529 	
       
  4530 	// Remove a reference from the ssl
       
  4531 	lm_ssl_unref ( ssl );
       
  4532 	
       
  4533 	// Get the heap size after freeing memory
       
  4534 	heap_avail_after = heap_handle.Available ( largest_free_block );
       
  4535 	
       
  4536 	// Compare the heap size
       
  4537 	if ( heap_avail_after != heap_avail_before )
       
  4538 		{
       
  4539 		iLog->Log ( _L ( "heap_avail_before = %d, heap_avail_after = %d" ),
       
  4540 		                  heap_avail_before, heap_avail_after );
       
  4541 		iLog->Log ( _L ( "Available memory is not as expected after unref" ) );
       
  4542 		return KErrGeneral;
       
  4543 		}
       
  4544 	
       
  4545 	iLog->Log ( _L ( "Expected: heap_avail_before is equal to heap_avail_after" ) );
       
  4546 	iLog->Log ( _L ( "heap_avail_before = %d, heap_avail_after = %d" ),
       
  4547 	                  heap_avail_before, heap_avail_after );	
       
  4548 	
       
  4549 	return KErrNone;	
       
  4550 }
       
  4551     
       
  4552 
       
  4553 // ---------------------------------------------------------------------------
       
  4554 // Ctstlm::lm_proxy_new
       
  4555 // Description:Creates a new proxy
       
  4556 // Arguements :
       
  4557 //    type    : proxy type (LM_PROXY_TYPE_NONE/LM_PROXY_TYPE_HTTP)
       
  4558 // Returns    : a newly created proxy       
       
  4559 // ---------------------------------------------------------------------------
       
  4560 //
       
  4561 TInt Ctstlm::lm_proxy_newL ( CStifItemParser& /*aItem*/ )
       
  4562 {
       
  4563 	LmProxy     *proxy = NULL;
       
  4564 	LmProxyType Type;
       
  4565 	
       
  4566 	iLog->Log ( _L ( "In lm_proxy_new" ) );
       
  4567 	
       
  4568 	iLog->Log ( _L ( "Create a new proxy" ) );	
       
  4569 	proxy = lm_proxy_new ( LM_PROXY_TYPE_HTTP );
       
  4570 	if ( !proxy )
       
  4571 	{
       
  4572 		iLog->Log ( _L ( "lm_proxy_new failed" ) );
       
  4573 		lm_proxy_unref ( proxy );
       
  4574 		return KErrGeneral;
       
  4575 	}
       
  4576 	
       
  4577 	// Verify the proxy type
       
  4578 	iLog->Log ( _L ( "Proxy type verification" ) );
       
  4579 	
       
  4580 	Type = lm_proxy_get_type ( proxy );
       
  4581 	if ( LM_PROXY_TYPE_HTTP != Type )
       
  4582 	{
       
  4583 		iLog->Log ( _L ( "lm_proxy_new failed" ) );
       
  4584 		lm_proxy_unref ( proxy );
       
  4585 		return KErrGeneral;
       
  4586 	}
       
  4587 		
       
  4588 	lm_proxy_unref ( proxy );
       
  4589 	
       
  4590 	iLog->Log ( _L ( "lm_proxy_new passed" ) );
       
  4591 	
       
  4592 	return KErrNone;	
       
  4593 }
       
  4594 
       
  4595 
       
  4596 // ---------------------------------------------------------------------------
       
  4597 // Ctstlm::lm_proxy_new_with_server
       
  4598 // Description:Creates a new proxy
       
  4599 // Arguements :
       
  4600 //   type    : proxy type (LM_PROXY_TYPE_NONE/LM_PROXY_TYPE_HTTP)
       
  4601 //   server  : proxy server
       
  4602 //   port    : proxy server port
       
  4603 // Returns   : a newly created proxy       
       
  4604 // ---------------------------------------------------------------------------
       
  4605 //
       
  4606 TInt Ctstlm::lm_proxy_new_with_serverL ( CStifItemParser& /*aItem*/ )
       
  4607 {
       
  4608 	LmProxy     *proxy  = NULL;	
       
  4609 	guint       port    = 8000;
       
  4610 	const gchar *server = "nokia.com";
       
  4611 	
       
  4612 	
       
  4613 	iLog->Log ( _L ( "In lm_proxy_new_with_server" ) );
       
  4614 	// Create a new proxy with the server
       
  4615 	proxy = lm_proxy_new_with_server ( LM_PROXY_TYPE_HTTP, server, port );
       
  4616 	if ( !proxy )
       
  4617 	    {
       
  4618 		iLog->Log ( _L ( "lm_proxy_new_with_server failed" ) );		
       
  4619 		return KErrGeneral;
       
  4620 	    }
       
  4621 	
       
  4622 	// Verify proxy type, server and port
       
  4623 	iLog->Log ( _L ( "Verify server, type and port in proxy" ) );
       
  4624 	
       
  4625 	if ( LM_PROXY_TYPE_HTTP != lm_proxy_get_type ( proxy ) )
       
  4626 	    {
       
  4627 		iLog->Log ( _L ( "lm_proxy_new_with_server failed for proxy type setting" ) );		
       
  4628 		lm_proxy_unref ( proxy );
       
  4629 		return KErrGeneral;
       
  4630 	    }
       
  4631 	
       
  4632 	if ( strcmp ( server, lm_proxy_get_server ( proxy ) ) )
       
  4633 	    {
       
  4634 		iLog->Log ( _L ( "lm_proxy_new_with_server failed for server setting" ) );		
       
  4635 		lm_proxy_unref ( proxy );
       
  4636 		return KErrGeneral;
       
  4637 	    }
       
  4638 	
       
  4639 	if ( port != lm_proxy_get_port ( proxy ) )
       
  4640 	    {
       
  4641 		iLog->Log ( _L ( "lm_proxy_new_with_server failed for port setting" ) );		
       
  4642 		lm_proxy_unref ( proxy );
       
  4643 		return KErrGeneral;
       
  4644 	    }
       
  4645 	
       
  4646 	lm_proxy_unref ( proxy );	
       
  4647 	
       
  4648 	iLog->Log ( _L ( "lm_proxy_new_with_server passed" ) );	
       
  4649 	
       
  4650 	return KErrNone;
       
  4651 }
       
  4652 
       
  4653 
       
  4654 
       
  4655 // ---------------------------------------------------------------------------
       
  4656 // Ctstlm::lm_proxy_set_get_type
       
  4657 // Description:Sets the proxy type for proxy to type
       
  4658 // Arguements :
       
  4659 //       proxy    : an LmProxy
       
  4660 //       type     : proxy type
       
  4661 // Returns    : None
       
  4662 // ---------------------------------------------------------------------------
       
  4663 //
       
  4664 TInt Ctstlm::lm_proxy_set_get_typeL ( CStifItemParser& /*aItem*/ )
       
  4665 {
       
  4666 	LmProxy     *proxy = NULL;	
       
  4667 	
       
  4668 	iLog->Log ( _L ( "In lm_proxy_set_get_type" ) );
       
  4669 	
       
  4670 	// Create a new proxy with type=LM_PROXY_TYPE_NONE
       
  4671 	proxy = lm_proxy_new ( LM_PROXY_TYPE_NONE );
       
  4672 	if ( !proxy )
       
  4673 	    {
       
  4674 		iLog->Log ( _L ( "lm_proxy_new failed" ) );
       
  4675 		return KErrGeneral;
       
  4676 	    }
       
  4677 	
       
  4678 	// Set the proxy type=LM_PROXY_TYPE_HTTP
       
  4679 	lm_proxy_set_type ( proxy, LM_PROXY_TYPE_HTTP );
       
  4680 	
       
  4681 	// Verify the proxy type for LM_PROXY_TYPE_HTTP		
       
  4682 	if ( LM_PROXY_TYPE_HTTP != lm_proxy_get_type ( proxy ) )
       
  4683 	    {
       
  4684 		iLog->Log ( _L ( "lm_proxy_set_type failed" ) );
       
  4685 		lm_proxy_unref ( proxy );
       
  4686 		return KErrGeneral;
       
  4687 	    }	
       
  4688 		
       
  4689 	lm_proxy_unref ( proxy );
       
  4690 	
       
  4691 	iLog->Log ( _L ( "lm_proxy_set_get_type passed" ) );
       
  4692 	
       
  4693 	return KErrNone;
       
  4694 }
       
  4695 
       
  4696 
       
  4697 
       
  4698 // ---------------------------------------------------------------------------
       
  4699 // Ctstlm::lm_proxy_set_get_server
       
  4700 // Description:Sets the server address for proxy
       
  4701 // Arguements :
       
  4702 //   proxy    : an LmProxy
       
  4703 //   server   : address of the proxy server
       
  4704 // Returns    : None
       
  4705 // ---------------------------------------------------------------------------
       
  4706 //
       
  4707 TInt Ctstlm::lm_proxy_set_get_serverL ( CStifItemParser& /*aItem*/ )
       
  4708 {
       
  4709 	LmProxy     *proxy  = NULL;
       
  4710 	const gchar *server = "nokia.com";	
       
  4711 	
       
  4712 	iLog->Log ( _L ( "In lm_proxy_get_server" ) );
       
  4713 	
       
  4714 	// Create a new proxy with type = LM_PROXY_TYPE_HTTP
       
  4715 	proxy = lm_proxy_new ( LM_PROXY_TYPE_HTTP );
       
  4716 	if ( !proxy )
       
  4717 	    {
       
  4718 		iLog->Log ( _L ( "lm_proxy_new failed" ) );
       
  4719 		return KErrGeneral;
       
  4720 	    }
       
  4721 	
       
  4722 	// Set the proxy server to "nokia.com"
       
  4723 	lm_proxy_set_server ( proxy, server );
       
  4724 	
       
  4725 	// Verify the server address in proxy
       
  4726 	if ( strcmp ( server, lm_proxy_get_server ( proxy ) ) )
       
  4727 	    {
       
  4728 		iLog->Log ( _L ( "lm_proxy_set_server failed" ) );
       
  4729 		lm_proxy_unref ( proxy );
       
  4730 		return KErrGeneral;
       
  4731 	    }
       
  4732 	
       
  4733 	lm_proxy_unref ( proxy );
       
  4734 	
       
  4735 	iLog->Log ( _L ( "lm_proxy_set_server passed" ) );
       
  4736 	
       
  4737 	return KErrNone;	
       
  4738 }
       
  4739 
       
  4740 
       
  4741 // ---------------------------------------------------------------------------
       
  4742 // Ctstlm::lm_proxy_set_port
       
  4743 // Description:Sets the server port that proxy will be using
       
  4744 // Arguements :
       
  4745 //    proxy   : an LmProxy
       
  4746 //    port    : proxy server port
       
  4747 // Returns    : None
       
  4748 // ---------------------------------------------------------------------------
       
  4749 //
       
  4750 TInt Ctstlm::lm_proxy_set_get_portL ( CStifItemParser& /*aItem*/ )
       
  4751 {
       
  4752 	LmProxy *proxy = NULL;
       
  4753 	guint   port1  = 80;
       
  4754 	guint   port2  = 21;
       
  4755 	
       
  4756 	iLog->Log ( _L ( "In lm_proxy_set_get_port" ) );
       
  4757 	
       
  4758 	// Create new proxy
       
  4759 	proxy = lm_proxy_new ( LM_PROXY_TYPE_HTTP );
       
  4760 	if ( !proxy )
       
  4761 	    {
       
  4762 		iLog->Log ( _L ( "lm_proxy_new failed" ) );
       
  4763 		return KErrGeneral;
       
  4764 	    }
       
  4765 	
       
  4766 	// Set the port = port1
       
  4767 	lm_proxy_set_port ( proxy, port1 );
       
  4768 	
       
  4769 	// Verify the port
       
  4770 	if ( port1 != lm_proxy_get_port ( proxy ) )
       
  4771 	    {
       
  4772 		iLog->Log ( _L ( "lm_proxy_set_port failed for port = %d" ), port1 );
       
  4773 		lm_proxy_unref ( proxy );
       
  4774 		return KErrGeneral;
       
  4775 	    }
       
  4776 	
       
  4777 	// Set the port = port2
       
  4778 	lm_proxy_set_port ( proxy, port2 );
       
  4779 	
       
  4780 	// Verify the port
       
  4781 	if ( port2 != lm_proxy_get_port ( proxy ) )
       
  4782 	    {
       
  4783 		iLog->Log ( _L ( "lm_proxy_set_port failed for port = %d" ), port2 );
       
  4784 		lm_proxy_unref ( proxy );
       
  4785 		return KErrGeneral;
       
  4786 	    }
       
  4787 	
       
  4788 	lm_proxy_unref ( proxy );
       
  4789 	
       
  4790 	iLog->Log ( _L ( "lm_proxy_set_get_port passed" ) );
       
  4791 	
       
  4792 	return KErrNone;
       
  4793 }
       
  4794 
       
  4795 
       
  4796 
       
  4797 // ---------------------------------------------------------------------------
       
  4798 // Ctstlm::lm_proxy_set_username
       
  4799 // Description:Sets the username for proxy or NULL to unset
       
  4800 // Arguements :
       
  4801 //   proxy    : an LmProxy
       
  4802 //   username : username
       
  4803 // Returns    : None
       
  4804 // ---------------------------------------------------------------------------
       
  4805 //
       
  4806 TInt Ctstlm::lm_proxy_set_get_usernameL ( CStifItemParser& /*aItem*/ )
       
  4807 {
       
  4808 	LmProxy     *proxy = NULL;
       
  4809 	const gchar *user1 = "nokia";
       
  4810 	const gchar *user2 = "linux";
       
  4811 	
       
  4812 	iLog->Log ( _L ( "In lm_proxy_set_get_username" ) );
       
  4813 	
       
  4814 	// Create a new proxy
       
  4815 	proxy = lm_proxy_new ( LM_PROXY_TYPE_HTTP );
       
  4816 	if ( !proxy )
       
  4817 	    {
       
  4818 		iLog->Log ( _L ( "lm_proxy_new failed" ) );
       
  4819 		return KErrGeneral;
       
  4820 	    }
       
  4821 	
       
  4822 	// Set the proxy username to "nokia"
       
  4823 	lm_proxy_set_username ( proxy, user1 );
       
  4824 	
       
  4825 	// Verify the proxy username
       
  4826 	if ( strcmp ( user1, lm_proxy_get_username ( proxy ) ) )
       
  4827 	    {
       
  4828 		iLog->Log ( _L ( "lm_proxy_set_username failed for user1" ) );
       
  4829 		lm_proxy_unref ( proxy );
       
  4830 		return KErrGeneral;
       
  4831 	    }
       
  4832 	
       
  4833 	// Set the proxy username to "linux"
       
  4834 	lm_proxy_set_username ( proxy, user2);
       
  4835 	
       
  4836 	// Verify the proxy username
       
  4837 	if ( strcmp ( user2, lm_proxy_get_username ( proxy ) ) )
       
  4838 	    {
       
  4839 		iLog->Log ( _L ( "lm_proxy_set_username failed for user2" ) );
       
  4840 		lm_proxy_unref ( proxy );
       
  4841 		return KErrGeneral;
       
  4842 	    }
       
  4843 	
       
  4844 	lm_proxy_unref ( proxy );
       
  4845 	
       
  4846 	iLog->Log ( _L ( "lm_proxy_set_get_username passed" ) );
       
  4847 	
       
  4848 	return KErrNone;
       
  4849 }
       
  4850 
       
  4851 
       
  4852 
       
  4853 // ---------------------------------------------------------------------------
       
  4854 // Ctstlm::lm_proxy_set_password
       
  4855 // Description:Sets the password for proxy
       
  4856 // Arguements :
       
  4857 //   proxy    : an LmProxy
       
  4858 // Returns    : the proxy password
       
  4859 // ---------------------------------------------------------------------------
       
  4860 //
       
  4861 TInt Ctstlm::lm_proxy_set_get_passwordL ( CStifItemParser& /*aItem*/ )
       
  4862 {
       
  4863 	LmProxy     *proxy = NULL;
       
  4864 	const gchar *password = "nokia";
       
  4865 	
       
  4866 	iLog->Log ( _L ( "In lm_proxy_set_get_passrod" ) );
       
  4867 	
       
  4868 	// Create a new proxy
       
  4869 	proxy = lm_proxy_new ( LM_PROXY_TYPE_HTTP );
       
  4870 	if ( !proxy )
       
  4871 	    {
       
  4872 		iLog->Log ( _L ( "lm_proxy_new failed" ) );
       
  4873 		return KErrGeneral;
       
  4874 	    }
       
  4875 	
       
  4876 	// Set the password proxy to "nokia"
       
  4877 	lm_proxy_set_password ( proxy, password );
       
  4878 	
       
  4879 	// Verify the password
       
  4880 	if ( strcmp ( password, lm_proxy_get_password ( proxy ) ) )
       
  4881 	    {
       
  4882 		iLog->Log ( _L ( "lm_proxy_set_password failed" ) );
       
  4883 		lm_proxy_unref ( proxy );
       
  4884 		return KErrGeneral;
       
  4885 	    }
       
  4886 	
       
  4887 	// Unset the password
       
  4888 	lm_proxy_set_password ( proxy, NULL );
       
  4889 	
       
  4890 	// Verify the password
       
  4891 	if ( lm_proxy_get_password ( proxy ) )
       
  4892 	    {
       
  4893 		iLog->Log ( _L ( "lm_proxy_set_password failed" ) );
       
  4894 		lm_proxy_unref ( proxy );
       
  4895 		return KErrGeneral;
       
  4896 	    }
       
  4897 	
       
  4898 	iLog->Log ( _L ( "lm_proxy_set_password passed" ) );
       
  4899 	lm_proxy_unref ( proxy );
       
  4900 	
       
  4901 	return KErrNone; 
       
  4902 }
       
  4903 
       
  4904 
       
  4905 // ---------------------------------------------------------------------------
       
  4906 // Ctstlm::lm_proxy_ref
       
  4907 // Description:Adds a reference to proxy
       
  4908 // Arguements :
       
  4909 //   proxy    : an LmProxy
       
  4910 // Returns    : the proxy
       
  4911 // ---------------------------------------------------------------------------
       
  4912 //
       
  4913 TInt Ctstlm::lm_proxy_refL ( CStifItemParser& /*aItem*/ )
       
  4914 {
       
  4915 	LmProxy *proxy = NULL;
       
  4916 	
       
  4917 	iLog->Log ( _L ( "In lm_proxy_ref" ) );
       
  4918 	
       
  4919 	// Creat a new proxy
       
  4920 	proxy = lm_proxy_new ( LM_PROXY_TYPE_HTTP );
       
  4921 	if ( !proxy )
       
  4922 	{
       
  4923 		iLog->Log ( _L ( "lm_proxy_new failed" ) );
       
  4924 		return KErrGeneral;
       
  4925 	}
       
  4926 	
       
  4927 	// Add a reference to proxy
       
  4928 	proxy = lm_proxy_ref ( proxy );
       
  4929 	
       
  4930 	// Loudmouth don't provide API for getting reference to the proxy
       
  4931 	// Therefore this test case is considered as passed without checking
       
  4932 	iLog->Log ( _L ( "lm_proxy_ref passed" ) );
       
  4933 	lm_proxy_unref ( proxy );
       
  4934 	lm_proxy_unref ( proxy );
       
  4935 	
       
  4936 	return KErrNone;
       
  4937 }
       
  4938 
       
  4939 
       
  4940 // ---------------------------------------------------------------------------
       
  4941 // Ctstlm::lm_proxy_unref
       
  4942 // Description:Removes a reference from the proxy
       
  4943 //             When no more rererences are present proxy is freed
       
  4944 //             Check the heap size to ensure that lm_proxy_unref free 
       
  4945 //             the proxy when no more references are present.
       
  4946 // Arguements :
       
  4947 //   proxy    : an LmProxy
       
  4948 // Returns    : None
       
  4949 // ---------------------------------------------------------------------------
       
  4950 //
       
  4951 TInt Ctstlm::lm_proxy_unrefL ( CStifItemParser& /*aItem*/ )
       
  4952 {
       
  4953 	LmProxy *proxy      = NULL;
       
  4954 	
       
  4955 	RHeap&  heap_handle = User::Heap();
       
  4956 	TInt    largest_free_block;
       
  4957 	TInt    heap_avail_before;
       
  4958 	TInt    heap_avail_after;
       
  4959 	
       
  4960 	iLog->Log ( _L ( "In lm_proxy_unref" ) );
       
  4961 	
       
  4962 	// Get the heap size before creating a new proxy
       
  4963 	heap_avail_before = heap_handle.Available ( largest_free_block );
       
  4964 	
       
  4965 	// Create a new proxy
       
  4966 	proxy = lm_proxy_new ( LM_PROXY_TYPE_HTTP );
       
  4967 	if ( !proxy )
       
  4968 	{
       
  4969 	    iLog->Log ( _L ( "lm_proxy_new failed" ) );
       
  4970 	    return KErrGeneral;
       
  4971 	}
       
  4972 	
       
  4973 	// Remove a reference from the proxy
       
  4974 	lm_proxy_unref ( proxy );
       
  4975 	
       
  4976 	// Get the heap size 
       
  4977 	heap_avail_after = heap_handle.Available ( largest_free_block );
       
  4978 	
       
  4979 	// Compare the heap size
       
  4980 	if ( heap_avail_after != heap_avail_before )
       
  4981 	{
       
  4982 		iLog->Log ( _L ( "heap_available_before = %d, heap_available_after = %d" ),
       
  4983 		                  heap_avail_before, heap_avail_after );
       
  4984 		iLog->Log ( _L ( "Available memory is not as expected after freeing" ) );
       
  4985 		return KErrGeneral;	
       
  4986 	}
       
  4987 	
       
  4988 	iLog->Log ( _L ( "Expected: heap_available_before is equal to heap_available_after" ) );
       
  4989 	iLog->Log ( _L ( "heap_available_before = %d, heap_available_after = %d" ),
       
  4990 	                  heap_avail_before, heap_avail_after );
       
  4991 	iLog->Log ( _L ( "lm_message_unref passed" ) );
       
  4992 	
       
  4993 	return KErrNone;	
       
  4994 }
       
  4995 	
       
  4996 //-----------------------------------------------------------------------------
       
  4997 // Ctstlm::lm_send_sync
       
  4998 // Description	: Opens a connection with the gtalk server and sends a jabber
       
  4999 //                message to the another person  
       
  5000 // Requires		: This test case requires GUI mode for selecting Access point
       
  5001 //-----------------------------------------------------------------------------
       
  5002 //
       
  5003 TInt Ctstlm::lm_send_syncL ( CStifItemParser& aItem )
       
  5004     {
       
  5005 	LmConnection *connection  = NULL;
       
  5006 	LmMessage    *message     = NULL;
       
  5007 	
       
  5008 	ConnectData *connect_data = NULL;
       
  5009 	
       
  5010 	GError      *error        = NULL;
       
  5011 	
       
  5012 	iLog->Log ( _L ( "In lm_send_sync" ) );	
       
  5013 	
       
  5014 	// Read data from the CFG file
       
  5015 	iLog->Log ( _L ( "Reading data from the CFG file" ) );	
       
  5016 	if ( read_data ( connect_data, aItem ) != RC_OK )
       
  5017 	    {
       
  5018 	    iLog->Log ( _L ( "read_data failed" ) );
       
  5019 	    free_data ( connect_data );
       
  5020 		return KErrGeneral;
       
  5021 	    }
       
  5022 	iLog->Log ( _L ( "Read data from the CFG file" ) );
       
  5023 	iLog->Log ( _L8 ( "Server name: %s" ), connect_data->server );
       
  5024 	
       
  5025 	// Open a new closed connection
       
  5026 	iLog->Log ( _L ( "Open a new closed connection" ) );
       
  5027 	connection = lm_connection_new ( connect_data->server );	
       
  5028 	if ( !connection )
       
  5029 		{
       
  5030 		iLog->Log ( _L ( "lm_connection_new failed" ) );
       
  5031 		free_data ( connect_data );
       
  5032 		return KErrGeneral;
       
  5033 		}
       
  5034 	iLog->Log ( _L ( "New closed connection opened" ) );
       
  5035 	
       
  5036 	iLog->Log ( _L ( "Setting jid" ) );	
       
  5037 	lm_connection_set_jid ( connection, connect_data->username );
       
  5038 	
       
  5039 	iLog->Log ( _L ( "Setting gtalks SSL port" ) );
       
  5040 	lm_connection_set_port ( connection, GTALK_SSL_PORT );
       
  5041 	
       
  5042 	// Proxy settings for emulator
       
  5043 #ifdef __WINSCW__
       
  5044     SetProxy ( connection, connect_data->proxy_data );
       
  5045 #endif
       
  5046 
       
  5047 	// Set connection to use SSL
       
  5048 	iLog->Log ( _L ( "Setting SSL for the connection" ) );
       
  5049 	SSLInit ( connection );
       
  5050 	
       
  5051 	iLog->Log ( _L ( "Open a connection with the server" ) );
       
  5052 	//Calling connection open
       
  5053 	GMainLoop	*main_loop = g_main_loop_new ( NULL, FALSE );
       
  5054 	iLog->Log ( _L ( "before lm_connection_open" ) );
       
  5055 	
       
  5056 	if ( !lm_connection_open ( connection, ( LmResultFunction ) connection_open_cb,
       
  5057 	                           main_loop, NULL, NULL ) ) 
       
  5058 	    {
       
  5059 		iLog->Log ( _L ( "lm_connection_open failed" ));
       
  5060 		lm_connection_unref ( connection );
       
  5061 		g_main_loop_unref ( main_loop );
       
  5062 		free_data ( connect_data );		
       
  5063 		return KErrGeneral;
       
  5064 	    }
       
  5065 		
       
  5066 	iLog->Log ( _L ( "after lm_connection_open" ) );	
       
  5067 	g_main_loop_run ( main_loop );
       
  5068 	g_main_loop_unref ( main_loop ); 
       
  5069 	
       
  5070 	iLog->Log ( _L ( "connection with the server successfull" ) );
       
  5071 	
       
  5072 	iLog->Log ( _L ( "Getting the username from the server" ) );
       
  5073 	iLog->Log ( _L8 ( "jid: %s" ), connect_data->username );
       
  5074 	// Get the user from the full JID
       
  5075 	gchar *username = get_user_name ( connect_data->username );
       
  5076 	iLog->Log ( _L ( "after extracting from the jid: %s" ), username );
       
  5077 	
       
  5078 	
       
  5079 	iLog->Log ( _L ( "Authenticating with the server" ) );
       
  5080 	
       
  5081 	main_loop = g_main_loop_new ( NULL, FALSE );
       
  5082 	// Authenticate with the server
       
  5083 	if ( !lm_connection_authenticate ( connection,
       
  5084                                      username,
       
  5085                                      connect_data->password,
       
  5086                                      connect_data->resource,
       
  5087                                       ( LmResultFunction )connection_auth_cb,
       
  5088                                      main_loop,NULL,NULL ) )
       
  5089 	    {
       
  5090 		iLog->Log ( _L ( "lm_connection_authenticate failed" ) );
       
  5091 		lm_connection_close ( connection, NULL );
       
  5092 		lm_connection_unref ( connection );
       
  5093 		free_data ( connect_data );
       
  5094 		g_main_loop_unref ( main_loop );
       
  5095 		g_free ( username );
       
  5096 		return KErrGeneral;
       
  5097 	    }
       
  5098 	g_main_loop_run ( main_loop );
       
  5099 	g_main_loop_unref ( main_loop );    
       
  5100 	g_free ( username );
       
  5101 	iLog->Log ( _L ( "Authentication done" ) );
       
  5102 	
       
  5103 	// Send a message to the server
       
  5104 	iLog->Log ( _L8 ( "Create a new message: %s" ),
       
  5105 	                   connect_data->msg_data->recipient );
       
  5106 	message = lm_message_new ( connect_data->msg_data->recipient, 
       
  5107 	                           LM_MESSAGE_TYPE_MESSAGE );
       
  5108 	if ( !message )
       
  5109 		{
       
  5110 		iLog->Log ( _L ( "lm_message_new failed" ) );
       
  5111 		lm_connection_close ( connection, NULL );
       
  5112 		lm_connection_unref ( connection );
       
  5113 		free_data ( connect_data );
       
  5114 		return KErrGeneral;
       
  5115 		}
       
  5116 	
       
  5117 	iLog->Log ( _L ( "Add a node" ) );	
       
  5118 	lm_message_node_add_child ( message->node, "body", 
       
  5119 	                            connect_data->msg_data->message );
       
  5120 	
       
  5121 	
       
  5122 	iLog->Log ( _L ( "Send message to the server" ) );
       
  5123 	if ( !lm_connection_send ( connection, message, NULL ) )
       
  5124 		{
       
  5125 		iLog->Log ( _L ( "lm_connection_send failed" ) );
       
  5126 		lm_connection_close ( connection, NULL );
       
  5127 		lm_connection_unref ( connection );
       
  5128 		lm_message_unref ( message );
       
  5129 		free_data ( connect_data );
       
  5130 		return KErrGeneral;
       
  5131 		}
       
  5132 	iLog->Log ( _L ( "Message has been sent" ) );
       
  5133 	
       
  5134 	iLog->Log ( _L ( "Free the allocated resources" ) );
       
  5135 	lm_connection_close ( connection, NULL );
       
  5136 	lm_connection_unref ( connection );	
       
  5137 	lm_message_unref ( message );
       
  5138 	free_data ( connect_data );
       
  5139 	iLog->Log ( _L ( "Freed" ) );
       
  5140 
       
  5141 	iLog->Log ( _L ( "lm_send_sync passed" ) );
       
  5142 	
       
  5143 	return KErrNone;	
       
  5144     }
       
  5145 	
       
  5146  //-----------------------------------------------------------------------------
       
  5147 // Ctstlm::lm_is_authenticated_WhenNotAuthenticatedL
       
  5148 // Description  : Check if connection is authenticated or not
       
  5149 // Arguements   :
       
  5150 //   connection	: an LmConnection to check 
       
  5151 // Returns      : TRUE if connection is authenticated, FALSE otherwise
       
  5152 //-----------------------------------------------------------------------------
       
  5153 //
       
  5154 TInt Ctstlm::lm_is_authenticated_WhenNotAuthenticatedL ( CStifItemParser& aItem )
       
  5155     {
       
  5156     LmConnection *connection       = NULL;
       
  5157     ConnectData  *connect_data     = NULL;
       
  5158     gboolean     NotAuthenticated  = FALSE;    
       
  5159     
       
  5160     iLog->Log ( _L ( "In lm_connection_is_authenticated" ) );
       
  5161     
       
  5162     // Read data from the CFG file
       
  5163     if ( read_data ( connect_data, aItem ) != RC_OK )
       
  5164     	{
       
  5165     	iLog->Log ( _L ( "read_data failed" ) );
       
  5166     	free_data ( connect_data );
       
  5167     	return KErrGeneral;
       
  5168     	}    
       
  5169     
       
  5170     // Open a new closed connection
       
  5171     connection = lm_connection_new ( connect_data->server );
       
  5172     if ( !connection )
       
  5173     	{
       
  5174     	iLog->Log ( _L ( "lm_connection_new failed" ) );
       
  5175     	free_data ( connect_data );
       
  5176     	return KErrGeneral;
       
  5177     	}
       
  5178     
       
  5179     // Set the connection to use gtalk's SSL port
       
  5180     lm_connection_set_port ( connection, GTALK_SSL_PORT );
       
  5181     
       
  5182     // Set the JID to be used for connection 
       
  5183     lm_connection_set_jid ( connection, connect_data->username );
       
  5184 	
       
  5185 	// Proxy settings for Emulator
       
  5186 #ifdef __WINSCW__
       
  5187 	SetProxy ( connection, connect_data->proxy_data );
       
  5188 #endif
       
  5189 
       
  5190 	// Set the connection to use SSL
       
  5191 	SSLInit ( connection );
       
  5192 	
       
  5193     // Open a connection
       
  5194     GMainLoop	*main_loop = g_main_loop_new ( NULL, FALSE );
       
  5195 	iLog->Log ( _L ( "before lm_connection_open" ) );
       
  5196 	
       
  5197 	if ( !lm_connection_open ( connection, ( LmResultFunction ) connection_open_cb,
       
  5198 	                           main_loop, NULL, NULL ) ) 
       
  5199 	    {
       
  5200 		iLog->Log ( _L ( "lm_connection_open failed" ));
       
  5201 		lm_connection_unref ( connection );
       
  5202 		g_main_loop_unref ( main_loop );
       
  5203 		free_data ( connect_data );		
       
  5204 		return KErrGeneral;
       
  5205 	    }
       
  5206 		
       
  5207 	iLog->Log ( _L ( "after lm_connection_open" ) );	
       
  5208 	g_main_loop_run ( main_loop );
       
  5209 	g_main_loop_unref ( main_loop ); 
       
  5210 	
       
  5211     // Check for authentication after the connection is authenticated
       
  5212     if ( lm_connection_is_authenticated ( connection ) )
       
  5213         {
       
  5214     	iLog->Log ( _L ( "lm_is_authenticated_WhenNotAuthenticatedL failed" ) );    	
       
  5215     	lm_connection_close ( connection, NULL );
       
  5216     	lm_connection_unref ( connection );
       
  5217     	free_data ( connect_data );
       
  5218     	return KErrGeneral;
       
  5219         }    
       
  5220     
       
  5221     lm_connection_close ( connection, NULL );
       
  5222     lm_connection_unref ( connection );
       
  5223     free_data ( connect_data );
       
  5224     
       
  5225     iLog->Log ( _L ( "lm_is_authenticated_WhenNotAuthenticatedL passed" ) );
       
  5226     
       
  5227     return KErrNone;  
       
  5228     }
       
  5229 
       
  5230 
       
  5231 
       
  5232 //--------------------------------------------------------------------------------
       
  5233 // function_name    : handle_fetch_contactlist_messages
       
  5234 // description      : callback function to handle messages
       
  5235 // Returns          : LmHandlerResult
       
  5236 //--------------------------------------------------------------------------------
       
  5237 static LmHandlerResult
       
  5238 handle_fetch_contactlist_messages ( LmMessageHandler* /*handler*/,
       
  5239                   LmConnection*     /*connection*/,
       
  5240                   LmMessage*        reply,
       
  5241                   gpointer          user_data )
       
  5242     {
       
  5243     GMainLoop *main_loop = ( GMainLoop * )user_data;	
       
  5244 	LmMessageSubType  type;
       
  5245 	LmMessageNode *q_node,*item_node;
       
  5246 	type = lm_message_get_sub_type (reply); 
       
  5247      	
       
  5248        	
       
  5249 	switch (type) 
       
  5250     	{
       
  5251     	case LM_MESSAGE_SUB_TYPE_RESULT:        		        		
       
  5252     		break;
       
  5253     	case LM_MESSAGE_SUB_TYPE_ERROR:          	          		
       
  5254     		//return NULL;
       
  5255     		break;
       
  5256     //	default:
       
  5257     	//	g_assert_not_reached ();
       
  5258     	//	break;
       
  5259     	} 
       
  5260     
       
  5261    	q_node = lm_message_node_get_child (reply->node, "query");
       
  5262 
       
  5263 	if (!q_node) 
       
  5264     	{
       
  5265    		//return NULL;
       
  5266     	}
       
  5267     	
       
  5268     item_node = lm_message_node_get_child (q_node, "item");
       
  5269 
       
  5270 	while (item_node) 
       
  5271     	{          	
       
  5272     	const char* reply_string;
       
  5273         reply_string = lm_message_node_get_attribute(item_node,"jid");  
       
  5274         char* friendname;
       
  5275         const char* atstring = "@";
       
  5276         friendname = strtok((char*)reply_string,atstring );
       
  5277         item_node = item_node->next;  
       
  5278      	}  
       
  5279 	
       
  5280 	
       
  5281 	if ( main_loop )
       
  5282 		{
       
  5283 		g_main_loop_quit ( main_loop );
       
  5284 		}	
       
  5285 	
       
  5286 	return LM_HANDLER_RESULT_REMOVE_MESSAGE;
       
  5287     }
       
  5288     
       
  5289 //-----------------------------------------------------------------------------
       
  5290 // Ctstlm::lm_fetching_contactlistL
       
  5291 // Description  : fetching contact list 
       
  5292 // Arguements   :
       
  5293 //   connection	: 
       
  5294 //   message    : 
       
  5295 //   error      : 
       
  5296 // Returns      : 
       
  5297 //-----------------------------------------------------------------------------
       
  5298 // 
       
  5299 TInt Ctstlm::lm_fetching_contactlist_L ( CStifItemParser& aItem )
       
  5300     {
       
  5301 	LmConnection *connection   = NULL;
       
  5302 	ConnectData  *connect_data = NULL;
       
  5303 	LmMessage    *message;
       
  5304 	LmMessageNode *q_node;
       
  5305     //LmMessageSubType  type;
       
  5306     LmMessageHandler *handler = NULL;
       
  5307 	
       
  5308 	iLog->Log ( _L ( "In lm_fetching_contactlist_L" ) );
       
  5309 	
       
  5310 	// Read a data from the CFG file
       
  5311 	if ( read_data ( connect_data, aItem ) != RC_OK )
       
  5312 		{
       
  5313 		iLog->Log ( _L ( "read_data failed" ) );
       
  5314 		free_data ( connect_data );
       
  5315 		return KErrGeneral;
       
  5316 		}
       
  5317 	
       
  5318 	// Open a new closed connection
       
  5319 	connection = lm_connection_new ( connect_data->server );
       
  5320 	if ( !connection )
       
  5321 		{
       
  5322 		iLog->Log ( _L ( "lm_connection_new failed" ) );
       
  5323 		free_data ( connect_data );
       
  5324 		return KErrGeneral;
       
  5325 		}
       
  5326 	
       
  5327 	// Set the gtalk's SSL port
       
  5328 	lm_connection_set_port ( connection, GTALK_SSL_PORT );
       
  5329 	
       
  5330 	// Set the JID
       
  5331 	lm_connection_set_jid ( connection, connect_data->username );
       
  5332 	
       
  5333 	// Proxy settings for Emulator
       
  5334 #ifdef __WINSCW__
       
  5335 	SetProxy ( connection, connect_data->proxy_data );
       
  5336 #endif
       
  5337 	
       
  5338 	// Set the connection to use SSL
       
  5339 	SSLInit ( connection );
       
  5340 
       
  5341 	//Open call    
       
  5342 	GMainLoop	*main_loop = g_main_loop_new ( NULL, FALSE );
       
  5343 	
       
  5344 	if ( !lm_connection_open ( connection, ( LmResultFunction ) connection_open_cb,
       
  5345 	                           main_loop, NULL, NULL ) ) 
       
  5346 	    {
       
  5347 		iLog->Log ( _L ( "lm_connection_open failed" ));
       
  5348 		lm_connection_unref ( connection );
       
  5349 		free_data ( connect_data );	
       
  5350 		g_main_loop_unref ( main_loop );	
       
  5351 		return KErrGeneral;
       
  5352 	    }
       
  5353 		
       
  5354 	
       
  5355 	g_main_loop_run ( main_loop );
       
  5356 
       
  5357 	g_main_loop_unref ( main_loop );    
       
  5358     
       
  5359 
       
  5360 	main_loop = g_main_loop_new ( NULL, FALSE );
       
  5361 	
       
  5362 	// Get the username from the JID
       
  5363 	gchar *username = get_user_name ( connect_data->username );
       
  5364 	
       
  5365 	// Authenticate with the server
       
  5366 	if ( !lm_connection_authenticate ( connection,
       
  5367                                      username,
       
  5368                                      connect_data->password,
       
  5369                                      connect_data->resource,
       
  5370                                       ( LmResultFunction )connection_auth_cb,
       
  5371                                      main_loop,NULL,NULL ) )
       
  5372 	    {
       
  5373 		iLog->Log ( _L ( "lm_connection_authenticate failed" ) );
       
  5374 		lm_connection_close ( connection, NULL );
       
  5375 		lm_connection_unref ( connection );
       
  5376 		free_data ( connect_data );
       
  5377 		g_main_loop_unref ( main_loop );
       
  5378 		g_free ( username );
       
  5379 		return KErrGeneral;
       
  5380 	    }
       
  5381 	g_main_loop_run ( main_loop );
       
  5382 	g_main_loop_unref ( main_loop );    
       
  5383 	g_free ( username );
       
  5384 	
       
  5385 
       
  5386                 
       
  5387 	// Construct a message
       
  5388 	main_loop = g_main_loop_new ( NULL, FALSE );
       
  5389 	message = lm_message_new_with_sub_type (NULL, LM_MESSAGE_TYPE_IQ,
       
  5390     					  LM_MESSAGE_SUB_TYPE_GET);
       
  5391     q_node = lm_message_node_add_child (message->node, "query", NULL);
       
  5392     lm_message_node_set_attributes (q_node,
       
  5393     					"xmlns", "jabber:iq:roster",
       
  5394     					NULL); 
       
  5395 	// Send message to the server
       
  5396 	handler = lm_message_handler_new ( handle_fetch_contactlist_messages, main_loop, NULL );
       
  5397 	
       
  5398 	if ( !lm_connection_send_with_reply ( connection, message, handler, NULL ) ) 
       
  5399 	    {
       
  5400 		iLog->Log ( _L ( "lm_connection_send_with_reply failed" ) );
       
  5401 		lm_connection_close ( connection, NULL );
       
  5402 		lm_connection_unref ( connection );
       
  5403 		lm_message_unref ( message );
       
  5404 		free_data ( connect_data );
       
  5405 		g_main_loop_unref ( main_loop );
       
  5406 		return KErrGeneral;
       
  5407 	    }	
       
  5408 	g_main_loop_run ( main_loop );
       
  5409 	g_main_loop_unref ( main_loop );                					
       
  5410     					
       
  5411    				
       
  5412 	
       
  5413 	// Close the connection
       
  5414 	lm_connection_close ( connection, NULL );
       
  5415 	
       
  5416 	// Remove a reference on connection
       
  5417 	lm_connection_unref ( connection );
       
  5418 	
       
  5419 	// Remove a reference on message
       
  5420 	lm_message_unref ( message );
       
  5421 	
       
  5422 	free_data ( connect_data );
       
  5423 	
       
  5424 	// Message sending passed
       
  5425 	iLog->Log ( _L ( "lm_fetching_contactlist_L passed" ) );
       
  5426 	
       
  5427 	return KErrNone;
       
  5428     }
       
  5429 
       
  5430 
       
  5431 //-----------------------------------------------------------------------------
       
  5432 // Ctstlm::lm_fetching_presenceL
       
  5433 // Description  : fetching contact list 
       
  5434 // Arguements   :
       
  5435 //   connection	: 
       
  5436 //   message    : 
       
  5437 //   error      : 
       
  5438 // Returns      : 
       
  5439 //-----------------------------------------------------------------------------
       
  5440 // 
       
  5441 TInt Ctstlm::lm_fetching_presenceL ( CStifItemParser& aItem )
       
  5442     {
       
  5443 	LmConnection *connection   = NULL;
       
  5444 	ConnectData  *connect_data = NULL;
       
  5445 	LmMessage    *message;
       
  5446 	//LmMessageNode *q_node;
       
  5447    // LmMessageSubType  type;
       
  5448     LmMessageHandler *handler = NULL;
       
  5449     GMainLoop    *main_loop    = NULL;
       
  5450 	
       
  5451 	iLog->Log ( _L ( "In lm_fetching_presenceL" ) );
       
  5452 	
       
  5453 	// Read a data from the CFG file
       
  5454 	if ( read_data ( connect_data, aItem ) != RC_OK )
       
  5455 		{
       
  5456 		iLog->Log ( _L ( "read_data failed" ) );
       
  5457 		free_data ( connect_data );
       
  5458 		return KErrGeneral;
       
  5459 		}
       
  5460 	
       
  5461 	// Open a new closed connection
       
  5462 	connection = lm_connection_new ( connect_data->server );
       
  5463 	if ( !connection )
       
  5464 		{
       
  5465 		iLog->Log ( _L ( "lm_connection_new failed" ) );
       
  5466 		free_data ( connect_data );
       
  5467 		return KErrGeneral;
       
  5468 		}
       
  5469 	
       
  5470 	// Set the gtalk's SSL port
       
  5471 	lm_connection_set_port ( connection, GTALK_SSL_PORT );
       
  5472 	
       
  5473 	// Set the JID
       
  5474 	lm_connection_set_jid ( connection, connect_data->username );
       
  5475 	
       
  5476 	// Proxy settings for Emulator
       
  5477 #ifdef __WINSCW__
       
  5478 	SetProxy ( connection, connect_data->proxy_data );
       
  5479 #endif
       
  5480 	
       
  5481 	// Set the connection to use SSL
       
  5482 	SSLInit ( connection );
       
  5483 	
       
  5484 	
       
  5485 	main_loop = g_main_loop_new ( NULL, FALSE );
       
  5486 	
       
  5487 	if ( !lm_connection_open ( connection, ( LmResultFunction ) connection_open_cb,
       
  5488 	                           main_loop, NULL, NULL ) ) 
       
  5489 	    {
       
  5490 		iLog->Log ( _L ( "lm_connection_open failed" ));
       
  5491 		lm_connection_unref ( connection );
       
  5492 		g_main_loop_unref ( main_loop );
       
  5493 		free_data ( connect_data );		
       
  5494 		return KErrGeneral;
       
  5495 	    }
       
  5496 		
       
  5497 	
       
  5498 	g_main_loop_run ( main_loop );
       
  5499 
       
  5500 	g_main_loop_unref ( main_loop );    
       
  5501 
       
  5502 	main_loop = g_main_loop_new ( NULL, FALSE );
       
  5503 	
       
  5504 	// Get the username from the JID
       
  5505 	gchar *username = get_user_name ( connect_data->username );
       
  5506 	
       
  5507 	// Authenticate with the server
       
  5508 	if ( !lm_connection_authenticate ( connection,
       
  5509                                      username,
       
  5510                                      connect_data->password,
       
  5511                                      connect_data->resource,
       
  5512                                       ( LmResultFunction ) connection_auth_cb,
       
  5513                                      main_loop,NULL,NULL ) )
       
  5514 	    {
       
  5515 		iLog->Log ( _L ( "lm_connection_authenticate failed" ) );
       
  5516 		lm_connection_close ( connection, NULL );
       
  5517 		lm_connection_unref ( connection );
       
  5518 		free_data ( connect_data );
       
  5519 		g_main_loop_unref ( main_loop );
       
  5520 		g_free ( username );
       
  5521 		return KErrGeneral;
       
  5522 	    }
       
  5523 	g_main_loop_run ( main_loop );
       
  5524 	g_main_loop_unref ( main_loop );    
       
  5525 	g_free ( username );
       
  5526 	
       
  5527 	
       
  5528 	message = lm_message_new_with_sub_type ( NULL,
       
  5529 	                                     LM_MESSAGE_TYPE_PRESENCE,
       
  5530 	                                     LM_MESSAGE_SUB_TYPE_AVAILABLE );
       
  5531 	
       
  5532     gboolean result = lm_connection_send ( connection, message, NULL );	
       
  5533    	// Close the connection
       
  5534 	main_loop = g_main_loop_new ( NULL, FALSE );
       
  5535 	
       
  5536 	//------------------------------------------------------------------------
       
  5537 	//
       
  5538 	// Register a handler to recieve and update presence information
       
  5539 	//
       
  5540 	handler = lm_message_handler_new ( 
       
  5541 	                     (LmHandleMessageFunction)jabber_presence_handler_cb,
       
  5542 	                     main_loop,
       
  5543 	                     NULL );
       
  5544 	
       
  5545 	lm_connection_register_message_handler ( connection,
       
  5546 	                                         handler,
       
  5547 	                                         LM_MESSAGE_TYPE_PRESENCE,
       
  5548 	                                         LM_HANDLER_PRIORITY_NORMAL );
       
  5549 	
       
  5550 	//------------------------------------------------------------------------
       
  5551 	
       
  5552 	g_main_loop_run ( main_loop );	
       
  5553 	g_main_loop_unref ( main_loop );
       
  5554 	
       
  5555 	lm_connection_close ( connection, NULL );	
       
  5556 	// Remove a reference on connection
       
  5557 	lm_connection_unref ( connection );	
       
  5558 	// Remove a reference on message
       
  5559 	lm_message_unref ( message );	
       
  5560 	free_data ( connect_data );
       
  5561 	lm_message_handler_unref(handler);
       
  5562 	
       
  5563 	// Message sending passed
       
  5564 	iLog->Log ( _L ( "lm_fetching_presenceL passed" ) );
       
  5565 	
       
  5566 	return KErrNone;
       
  5567     }
       
  5568 
       
  5569 //-----------------------------------------------------------------------------
       
  5570 // Ctstlm::lm_subscribe_contact_L
       
  5571 // Description  : fetching contact list 
       
  5572 // Arguements   :
       
  5573 //   connection	: 
       
  5574 //   message    : 
       
  5575 //   error      : 
       
  5576 // Returns      : 
       
  5577 //-----------------------------------------------------------------------------
       
  5578 // 
       
  5579 TInt Ctstlm::lm_subscribe_contact_L ( CStifItemParser& aItem )
       
  5580     {
       
  5581 	LmConnection *connection   = NULL;
       
  5582 	ConnectData  *connect_data = NULL;
       
  5583 	LmMessage    *message;
       
  5584 	//LmMessageNode *q_node;
       
  5585     //LmMessageSubType  type;
       
  5586 	
       
  5587 	iLog->Log ( _L ( "In lm_subscribe_contact_L" ) );
       
  5588 	
       
  5589 	// Read a data from the CFG file
       
  5590 	if ( read_data ( connect_data, aItem ) != RC_OK )
       
  5591 		{
       
  5592 		iLog->Log ( _L ( "read_data failed" ) );
       
  5593 		free_data ( connect_data );
       
  5594 		return KErrGeneral;
       
  5595 		}
       
  5596 	
       
  5597 	// Open a new closed connection
       
  5598 	connection = lm_connection_new ( connect_data->server );
       
  5599 	if ( !connection )
       
  5600 		{
       
  5601 		iLog->Log ( _L ( "lm_connection_new failed" ) );
       
  5602 		free_data ( connect_data );
       
  5603 		return KErrGeneral;
       
  5604 		}
       
  5605 	
       
  5606 	// Set the gtalk's SSL port
       
  5607 	lm_connection_set_port ( connection, GTALK_SSL_PORT );
       
  5608 	
       
  5609 	// Set the JID
       
  5610 	lm_connection_set_jid ( connection, connect_data->username );
       
  5611 	
       
  5612 	// Proxy settings for Emulator
       
  5613 #ifdef __WINSCW__
       
  5614 	SetProxy ( connection, connect_data->proxy_data );
       
  5615 #endif
       
  5616 	
       
  5617 	// Set the connection to use SSL
       
  5618 	SSLInit ( connection );
       
  5619 	
       
  5620 	// Open a connection with the server
       
  5621 	GMainLoop	*main_loop1 = g_main_loop_new ( NULL, FALSE );
       
  5622 	
       
  5623 	if ( !lm_connection_open ( connection, 
       
  5624 								( LmResultFunction ) connection_open_cb,
       
  5625 	                           main_loop1, NULL, NULL ) ) 
       
  5626 	    {
       
  5627 		iLog->Log ( _L ( "lm_connection_open failed" ));
       
  5628 		lm_connection_unref ( connection );
       
  5629 		g_main_loop_unref ( main_loop1 );
       
  5630 		free_data ( connect_data );		
       
  5631 		return KErrGeneral;
       
  5632 	    }
       
  5633 		
       
  5634 	
       
  5635 	
       
  5636 	g_main_loop_run ( main_loop1 );
       
  5637 
       
  5638 	g_main_loop_unref ( main_loop1 );   
       
  5639 
       
  5640 	
       
  5641 	GMainLoop	*main_loop2 = g_main_loop_new ( NULL, FALSE );
       
  5642 	
       
  5643 	// Get the username from the JID
       
  5644 	gchar *username = get_user_name ( connect_data->username );	
       
  5645 	// Authenticate with the server
       
  5646 	if ( !lm_connection_authenticate ( connection,
       
  5647                                      username,
       
  5648                                      connect_data->password,
       
  5649                                      connect_data->resource,
       
  5650                                       ( LmResultFunction ) connection_auth_cb,
       
  5651                                      main_loop2,NULL,NULL ) )
       
  5652 	    {
       
  5653 		iLog->Log ( _L ( "lm_connection_authenticate failed" ) );
       
  5654 		lm_connection_close ( connection, NULL );
       
  5655 		lm_connection_unref ( connection );
       
  5656 		free_data ( connect_data );
       
  5657 		g_free ( username );
       
  5658 		return KErrGeneral;
       
  5659 	    }
       
  5660 	g_main_loop_run ( main_loop2 );
       
  5661 	g_main_loop_unref ( main_loop2 );    
       
  5662 	g_free ( username );
       
  5663 	
       
  5664 	
       
  5665 	gchar *jid = "rakesh.harsha@gmail.com";
       
  5666     message = lm_message_new (jid, LM_MESSAGE_TYPE_PRESENCE );
       
  5667     lm_message_node_set_attribute ( message->node, "type", "subscribe" );
       
  5668     //Send the message					
       
  5669    	if ( !lm_connection_send ( connection, message, NULL ) )
       
  5670     	{
       
  5671     	lm_message_unref ( message );
       
  5672     	return KErrGeneral;
       
  5673     	}
       
  5674     
       
  5675     lm_connection_close ( connection, NULL );	
       
  5676 	// Remove a reference on connection
       
  5677 	lm_connection_unref ( connection );	
       
  5678 	// Remove a reference on message
       
  5679 	lm_message_unref ( message );	
       
  5680 	free_data ( connect_data );
       
  5681 	
       
  5682 	// Message sending passed
       
  5683 	iLog->Log ( _L ( "lm_subscribe_contact_L passed" ) );	
       
  5684 	return KErrNone;
       
  5685     }
       
  5686     
       
  5687     
       
  5688     
       
  5689  //-----------------------------------------------------------------------------
       
  5690 // Ctstlm::lm_authenticate_WithUnexistingJID
       
  5691 // Description  : Tries to authenticate a user against the server. 
       
  5692 // Arguements   :
       
  5693 //   connection : an LmConnection 
       
  5694 //   username   : Username used to authenticate
       
  5695 //   password   : Password corresponding to Username
       
  5696 //   resource   : Resource used for this connection
       
  5697 //   error      : location to store error, or NULL
       
  5698 // Returns      : TRUE if no errors were detected & authentication was 
       
  5699 //                successful,
       
  5700 //                FALSE otherwise
       
  5701 //-----------------------------------------------------------------------------
       
  5702 //
       
  5703 TInt Ctstlm::lm_authenticate_WithUnexistingJID ( CStifItemParser& aItem )
       
  5704     {
       
  5705 	LmConnection *connection   = NULL;	
       
  5706 	//ConnectData  *connect_data = NULL;
       
  5707 	AuthData     *auth_data    = NULL;
       
  5708 	//GMainLoop    *main_loop    = NULL;
       
  5709 	//GMainContext *context      = NULL;
       
  5710 		
       
  5711 	iLog->Log ( _L ( "In lm_connection_authenticate" ) );	
       
  5712 
       
  5713 	auth_data = g_new0 ( AuthData, 1 );
       
  5714 	if ( !auth_data )
       
  5715 		{
       
  5716 		iLog->Log ( _L ( "memory allocation failed for auth_data" ) );
       
  5717 		return KErrGeneral;
       
  5718 		}	
       
  5719 		
       
  5720 	if ( read_data ( auth_data->connect_data, aItem ) != RC_OK )
       
  5721 		{
       
  5722 		iLog->Log ( _L ( "read_data failed" ) );		
       
  5723 		free_data ( auth_data->connect_data );		
       
  5724 		g_free ( auth_data );
       
  5725 		return KErrGeneral;
       
  5726 		}
       
  5727 	
       
  5728 	auth_data->main_loop    = g_main_loop_new ( NULL, FALSE );	
       
  5729 	auth_data->rCode        = RC_ERROR;
       
  5730 	
       
  5731 	//connection = lm_connection_new_with_context ( connect_data->server,context );
       
  5732 	connection = lm_connection_new ( auth_data->connect_data->server );
       
  5733 	if ( connection == NULL )
       
  5734 	    {
       
  5735 	    iLog->Log ( _L ( "lm_connection_new_with_context failed" ) );
       
  5736 	    free_data ( auth_data->connect_data );
       
  5737 	    g_main_loop_unref ( auth_data->main_loop );
       
  5738 	    g_free ( auth_data );
       
  5739 	    return KErrGeneral;
       
  5740 	    }
       
  5741 	
       
  5742 	lm_connection_set_port ( connection, GTALK_SSL_PORT );
       
  5743 	lm_connection_set_jid ( connection, auth_data->connect_data->username );
       
  5744 
       
  5745 #ifdef __WINSCW__
       
  5746 	SetProxy ( connection, auth_data->connect_data->proxy_data );
       
  5747 #endif
       
  5748 	SSLInit ( connection );
       
  5749 	
       
  5750 	if ( !lm_connection_open ( connection, 
       
  5751 	                           ( LmResultFunction ) connection_open_cb,
       
  5752 	                           auth_data->main_loop, 
       
  5753 	                           NULL, 
       
  5754 	                           NULL ) )                          
       
  5755 	    {
       
  5756 		iLog->Log ( _L ( "lm_connection_open failed" ) );
       
  5757 		free_data ( auth_data->connect_data );
       
  5758 		g_main_loop_unref ( auth_data->main_loop );
       
  5759 		g_free ( auth_data );
       
  5760 		return KErrGeneral;
       
  5761 	    }	   
       
  5762 	                                    
       
  5763 	
       
  5764 	g_main_loop_run ( auth_data->main_loop );
       
  5765 	g_main_loop_unref ( auth_data->main_loop );
       
  5766 	
       
  5767 	// Extract the username from the JID
       
  5768     gchar *username = get_user_name ( auth_data->connect_data->username );
       
  5769     auth_data->main_loop    = g_main_loop_new ( NULL, FALSE );
       
  5770     if ( !lm_connection_authenticate ( connection, 
       
  5771                                        username,
       
  5772                                        auth_data->connect_data->password,
       
  5773                                        auth_data->connect_data->resource, 
       
  5774                                        ( LmResultFunction ) wrong_input_auth_cb, 
       
  5775                                        auth_data ,  
       
  5776                                        NULL, 
       
  5777                                        NULL ) )
       
  5778         {
       
  5779        	auth_data->rCode = RC_ERROR;
       
  5780        	lm_connection_close ( connection, NULL );
       
  5781 		lm_connection_unref ( connection );
       
  5782        	g_free ( username );
       
  5783        	g_main_loop_unref ( auth_data->main_loop );
       
  5784        	free_data ( auth_data->connect_data );	
       
  5785        	g_free ( auth_data );
       
  5786        	return KErrGeneral;
       
  5787         }
       
  5788             
       
  5789     g_main_loop_run ( auth_data->main_loop );
       
  5790 	g_main_loop_unref ( auth_data->main_loop );
       
  5791 	g_free ( username );
       
  5792 	
       
  5793 	
       
  5794 	
       
  5795 	lm_connection_close ( connection, NULL );
       
  5796 	lm_connection_unref ( connection );
       
  5797 	free_data ( auth_data->connect_data );	
       
  5798 	
       
  5799 	if ( auth_data->rCode == RC_ERROR )
       
  5800 	    {
       
  5801 	    iLog->Log ( _L ( "lm_authenticate_WithUnexistingJID failed" ) );
       
  5802 	    g_free ( auth_data );
       
  5803 	    return KErrGeneral;
       
  5804 	    }
       
  5805 	
       
  5806 	g_free ( auth_data );
       
  5807 
       
  5808 	iLog->Log ( _L ( "lm_authenticate_WithUnexistingJID passed" ) );
       
  5809 	
       
  5810 	return KErrNone;		
       
  5811 }
       
  5812 
       
  5813 
       
  5814 //-----------------------------------------------------------------------------
       
  5815 // Ctstlm::lm_authenticate_WithBadPasswordL
       
  5816 // Description  : Tries to authenticate a user against the server. 
       
  5817 // Arguements   :
       
  5818 //   connection : an LmConnection 
       
  5819 //   username   : Username used to authenticate
       
  5820 //   password   : Password corresponding to Username
       
  5821 //   resource   : Resource used for this connection
       
  5822 //   error      : location to store error, or NULL
       
  5823 // Returns      : TRUE if no errors were detected & authentication was 
       
  5824 //                successful,
       
  5825 //                FALSE otherwise
       
  5826 //-----------------------------------------------------------------------------
       
  5827 //
       
  5828 TInt Ctstlm::lm_authenticate_WithBadPasswordL ( CStifItemParser& aItem )
       
  5829     {
       
  5830 		LmConnection *connection   = NULL;	
       
  5831 	//ConnectData  *connect_data = NULL;
       
  5832 	AuthData     *auth_data    = NULL;
       
  5833 	//GMainLoop    *main_loop    = NULL;
       
  5834 	//GMainContext *context      = NULL;
       
  5835 		
       
  5836 	iLog->Log ( _L ( "In lm_connection_authenticate" ) );	
       
  5837 
       
  5838 	auth_data = g_new0 ( AuthData, 1 );
       
  5839 	if ( !auth_data )
       
  5840 		{
       
  5841 		iLog->Log ( _L ( "memory allocation failed for auth_data" ) );
       
  5842 		return KErrGeneral;
       
  5843 		}	
       
  5844 		
       
  5845 	if ( read_data ( auth_data->connect_data, aItem ) != RC_OK )
       
  5846 		{
       
  5847 		iLog->Log ( _L ( "read_data failed" ) );		
       
  5848 		free_data ( auth_data->connect_data );		
       
  5849 		g_free ( auth_data );
       
  5850 		return KErrGeneral;
       
  5851 		}
       
  5852 	
       
  5853 	//context = g_main_context_new ();
       
  5854 	//main_loop = g_main_loop_new ( context, FALSE );	
       
  5855 	auth_data->main_loop    = g_main_loop_new ( NULL, FALSE );	
       
  5856 	//auth_data->connect_data = connect_data;
       
  5857 	auth_data->rCode        = RC_ERROR;
       
  5858 	//auth_data->main_loop    = main_loop;
       
  5859 	
       
  5860 	//connection = lm_connection_new_with_context ( connect_data->server,context );
       
  5861 	connection = lm_connection_new ( auth_data->connect_data->server );
       
  5862 	if ( connection == NULL )
       
  5863 	    {
       
  5864 	    iLog->Log ( _L ( "lm_connection_new_with_context failed" ) );
       
  5865 	    free_data ( auth_data->connect_data );
       
  5866 	    g_main_loop_unref ( auth_data->main_loop );
       
  5867 	    g_free ( auth_data );
       
  5868 	    return KErrGeneral;
       
  5869 	    }
       
  5870 	
       
  5871 	lm_connection_set_port ( connection, GTALK_SSL_PORT );
       
  5872 	lm_connection_set_jid ( connection, auth_data->connect_data->username );
       
  5873 
       
  5874 #ifdef __WINSCW__
       
  5875 	SetProxy ( connection, auth_data->connect_data->proxy_data );
       
  5876 #endif
       
  5877 	SSLInit ( connection );
       
  5878 	
       
  5879 	if ( !lm_connection_open ( connection, 
       
  5880 	                           ( LmResultFunction ) auth_from_open_cb,
       
  5881 	                           auth_data, 
       
  5882 	                           NULL, 
       
  5883 	                           NULL ) )                          
       
  5884 	    {
       
  5885 		iLog->Log ( _L ( "lm_connection_open failed" ) );
       
  5886 		free_data ( auth_data->connect_data );
       
  5887 		g_main_loop_unref ( auth_data->main_loop );
       
  5888 		g_free ( auth_data );
       
  5889 		return KErrGeneral;
       
  5890 	    }	   
       
  5891 	                                    
       
  5892 	
       
  5893 	g_main_loop_run ( auth_data->main_loop );
       
  5894 	g_main_loop_unref ( auth_data->main_loop );
       
  5895 	
       
  5896 	lm_connection_close ( connection, NULL );
       
  5897 	lm_connection_unref ( connection );
       
  5898 	free_data ( auth_data->connect_data );	
       
  5899 	
       
  5900 	if ( auth_data->rCode == RC_ERROR )
       
  5901 	    {
       
  5902 	    iLog->Log ( _L ( "lm_authenticate_WithBadPasswordL failed" ) );
       
  5903 	    g_free ( auth_data );
       
  5904 	    return KErrGeneral;
       
  5905 	    }
       
  5906 	
       
  5907 	g_free ( auth_data );
       
  5908 
       
  5909 	iLog->Log ( _L ( "lm_authenticate_WithBadPasswordL passed" ) );
       
  5910 	
       
  5911 	return KErrNone;		
       
  5912 }
       
  5913    
       
  5914   //-----------------------------------------------------------------------------
       
  5915 // Ctstlm::lm_authenticate_WhenConnectionIsNotOpenedL
       
  5916 // Description  : Tries to authenticate a user against the server.handles 
       
  5917 // 				  a reply to the authentication in callback method
       
  5918 // Arguments    :
       
  5919 //   connection : an LmConnection 
       
  5920 //   username   : Username used to authenticate
       
  5921 //   password   : Password corresponding to Username
       
  5922 //   resource   : Resource used for this connection
       
  5923 //   error      : location to store error, or NULL
       
  5924 // Returns      : TRUE if no errors were detected & authentication was 
       
  5925 //                successful,
       
  5926 //                FALSE otherwise
       
  5927 //-----------------------------------------------------------------------------
       
  5928 //
       
  5929 TInt Ctstlm::lm_authenticate_WhenConnectionIsNotOpenedL ( CStifItemParser& aItem )
       
  5930     {
       
  5931 	LmConnection *connection   = NULL;	
       
  5932 	ConnectData  *connect_data = NULL;
       
  5933 	
       
  5934 	
       
  5935 	iLog->Log ( _L ( "In lm_authenticate_WhenConnectionIsNotOpenedL" ) );
       
  5936 	
       
  5937 	// Read data from the CFG file
       
  5938 	if ( read_data ( connect_data, aItem ) != RC_OK )
       
  5939 		{
       
  5940 		iLog->Log ( _L ( "read_data failed" ) );
       
  5941 		free_data ( connect_data );
       
  5942 		return KErrGeneral;
       
  5943 		}
       
  5944 	
       
  5945 	// Open a new closed connection	
       
  5946 	connection = lm_connection_new ( connect_data->server );
       
  5947 	if ( connection == NULL)
       
  5948 	    {
       
  5949 		iLog->Log ( _L ( "lm_connection_new failed" ) );
       
  5950 		free_data ( connect_data );
       
  5951 		return KErrGeneral;
       
  5952 	    }
       
  5953 	
       
  5954 	lm_connection_set_port ( connection, GTALK_SSL_PORT );
       
  5955 	lm_connection_set_jid ( connection, connect_data->username );
       
  5956 	
       
  5957 #ifdef __WINSCW__
       
  5958 	SetProxy ( connection, connect_data->proxy_data );
       
  5959 #endif
       
  5960 	
       
  5961 	SSLInit ( connection );
       
  5962 	
       
  5963 		
       
  5964 	
       
  5965 	// Get the username from the JID
       
  5966    GMainLoop	*main_loop = g_main_loop_new ( NULL, FALSE );
       
  5967 	
       
  5968 	// Get the username from the JID
       
  5969 	gchar *username = get_user_name ( connect_data->username );
       
  5970 	
       
  5971 	// Authenticate with the server without doing a connection open
       
  5972 	if (! lm_connection_authenticate ( connection,
       
  5973                                      username,
       
  5974                                      connect_data->password,
       
  5975                                      connect_data->resource,
       
  5976                                       ( LmResultFunction ) connection_open_cb,
       
  5977                                      main_loop,NULL,NULL ) )
       
  5978 	    {
       
  5979 		iLog->Log ( _L ( "lm_authenticate_WhenConnectionIsNotOpened passed" ) );
       
  5980 		lm_connection_close ( connection, NULL );
       
  5981 		lm_connection_unref ( connection );
       
  5982 		free_data ( connect_data );
       
  5983 		g_main_loop_unref ( main_loop );
       
  5984 		g_free ( username );  
       
  5985 		//returning kerrnone since we are testing negative scenario and this call is 
       
  5986 		//expected to return false
       
  5987 		return KErrNone; 
       
  5988 	    }
       
  5989 	g_main_loop_run ( main_loop );
       
  5990 	g_main_loop_unref ( main_loop );    
       
  5991 	g_free ( username );
       
  5992 
       
  5993 	
       
  5994 	lm_connection_close ( connection, NULL );
       
  5995 	lm_connection_unref ( connection );
       
  5996 	free_data ( connect_data );
       
  5997 	
       
  5998 	iLog->Log ( _L ( "lm_authenticate_WhenConnectionIsNotOpened when connection is not opened failed since connection must be already open" ) );
       
  5999 	//Returning KErrNone, since the test case could not be tested as the connection must be open
       
  6000 	//The control will never come here for the test case :)
       
  6001 	return KErrNone;	
       
  6002     }
       
  6003     
       
  6004     
       
  6005  //-----------------------------------------------------------------------------
       
  6006 // Ctstlm::lm_connection_open_with_badserver server name
       
  6007 // Description  : Tries to authenticate a user against the wrong server. 
       
  6008 // Arguements   :
       
  6009 //   connection : an LmConnection 
       
  6010 //   username   : Username used to authenticate
       
  6011 //   password   : Password corresponding to Username
       
  6012 //   resource   : Resource used for this connection
       
  6013 //   error      : location to store error, or NULL
       
  6014 // Returns      : TRUE if no errors were detected & authentication was 
       
  6015 //                successful,
       
  6016 //                FALSE otherwise
       
  6017 //-----------------------------------------------------------------------------
       
  6018 //
       
  6019 TInt Ctstlm::lm_connection_open_with_badserverL ( CStifItemParser& aItem )
       
  6020     {
       
  6021 		LmConnection *connection   = NULL;	
       
  6022 	//ConnectData  *connect_data = NULL;
       
  6023 	AuthData     *auth_data    = NULL;
       
  6024 	//GMainLoop    *main_loop    = NULL;
       
  6025 	//GMainContext *context      = NULL;
       
  6026 		
       
  6027 	iLog->Log ( _L ( "In lm_connection_open_with_badserverL" ) );	
       
  6028 
       
  6029 	auth_data = g_new0 ( AuthData, 1 );
       
  6030 	if ( !auth_data )
       
  6031 		{
       
  6032 		iLog->Log ( _L ( "memory allocation failed for auth_data" ) );
       
  6033 		return KErrGeneral;
       
  6034 		}	
       
  6035 		
       
  6036 	if ( read_data ( auth_data->connect_data, aItem ) != RC_OK )
       
  6037 		{
       
  6038 		iLog->Log ( _L ( "read_data failed" ) );		
       
  6039 		free_data ( auth_data->connect_data );		
       
  6040 		g_free ( auth_data );
       
  6041 		return KErrGeneral;
       
  6042 		}
       
  6043 	
       
  6044 	//context = g_main_context_new ();
       
  6045 	//main_loop = g_main_loop_new ( context, FALSE );	
       
  6046 	auth_data->main_loop    = g_main_loop_new ( NULL, FALSE );	
       
  6047 	//auth_data->connect_data = connect_data;
       
  6048 	auth_data->rCode        = RC_ERROR;
       
  6049 	//auth_data->main_loop    = main_loop;
       
  6050 	
       
  6051 	//connection = lm_connection_new_with_context ( connect_data->server,context );
       
  6052 	connection = lm_connection_new ( auth_data->connect_data->server );
       
  6053 	if ( connection == NULL )
       
  6054 	    {
       
  6055 	    iLog->Log ( _L ( "lm_connection_new failed" ) );
       
  6056 	    free_data ( auth_data->connect_data );
       
  6057 	    g_main_loop_unref ( auth_data->main_loop );
       
  6058 	    g_free ( auth_data );
       
  6059 	    return KErrGeneral;
       
  6060 	    }
       
  6061 	
       
  6062 	lm_connection_set_port ( connection, GTALK_SSL_PORT );
       
  6063 	lm_connection_set_jid ( connection, auth_data->connect_data->username );
       
  6064 
       
  6065 #ifdef __WINSCW__
       
  6066 	SetProxy ( connection, auth_data->connect_data->proxy_data );
       
  6067 #endif
       
  6068 	SSLInit ( connection );
       
  6069 	
       
  6070 	if ( !lm_connection_open ( connection, 
       
  6071 	                           ( LmResultFunction ) wrong_input_in_open_cb,
       
  6072 	                           auth_data, 
       
  6073 	                           NULL, 
       
  6074 	                           NULL ) )                          
       
  6075 	    {
       
  6076 		iLog->Log ( _L ( "lm_connection_open failed" ) );
       
  6077 		free_data ( auth_data->connect_data );
       
  6078 		g_main_loop_unref ( auth_data->main_loop );
       
  6079 		g_free ( auth_data );
       
  6080 		return KErrGeneral;
       
  6081 	    }	   
       
  6082 	                                    
       
  6083 	
       
  6084 	g_main_loop_run ( auth_data->main_loop );
       
  6085 	iLog->Log ( _L ( "main loop exited returned" ) );
       
  6086 	g_main_loop_unref ( auth_data->main_loop );
       
  6087 	lm_connection_close ( connection, NULL );
       
  6088 	lm_connection_unref ( connection );
       
  6089 	free_data ( auth_data->connect_data );	
       
  6090 	
       
  6091 	if ( auth_data->rCode == RC_ERROR )
       
  6092 	    {
       
  6093 	    iLog->Log ( _L ( "lm_connection_open_with_badserver failed" ) );
       
  6094 	    g_free ( auth_data );
       
  6095 	    return KErrGeneral;
       
  6096 	    }
       
  6097 	
       
  6098 	g_free ( auth_data );
       
  6099 	
       
  6100 	iLog->Log ( _L ( "lm_connection_open_with_badserver passed" ) );
       
  6101 	
       
  6102 	return KErrNone;		
       
  6103 }
       
  6104 
       
  6105  
       
  6106 // ----------------------------------------------------------------------------
       
  6107 // Ctstlm::lm_message_node_get_child
       
  6108 // Description:Fetches the child from node. If child is not found as an 
       
  6109 //             immediate child of node, NULL is returned
       
  6110 // Arguements :
       
  6111 //    node    : an LmMessageNode
       
  6112 //    name    : name of the new child
       
  6113 //    value   : value of the new child
       
  6114 // Returns    : the child node or NULL if child not found
       
  6115 // ----------------------------------------------------------------------------
       
  6116 //
       
  6117 TInt Ctstlm::lm_message_node_get_childL ( CStifItemParser& /*aItem*/ )
       
  6118 {
       
  6119 	LmMessage     *message   = NULL;
       
  6120 	LmMessageNode *Node      = NULL;	
       
  6121 	const gchar   *Username  = "Nokia";	
       
  6122 	const gchar   *Password  = "Nokia";		
       
  6123 	
       
  6124 	iLog->Log ( _L ( "In lm_message_node_get_child" ) );
       
  6125 	
       
  6126 	// Construct a message with type = LM_MESSAGE_TYPE_MESSAGE
       
  6127 	iLog->Log ( _L ( "Construct a message" ) );
       
  6128 	
       
  6129 	message = lm_message_new ( NULL, LM_MESSAGE_TYPE_MESSAGE );
       
  6130 	if ( !message )
       
  6131 	    {
       
  6132 		iLog->Log ( _L ( "lm_message_new failed" ) );
       
  6133 		return KErrGeneral;
       
  6134 	    }
       
  6135 	
       
  6136 	// Retrive the root node from message
       
  6137 	iLog->Log ( _L ( "Retrive the root node from the message" ) );
       
  6138 	
       
  6139 	Node = lm_message_get_node ( message );
       
  6140 	if ( !Node )
       
  6141 	    {
       
  6142 		iLog->Log ( _L ( "lm_message_get_node failed" ) );
       
  6143 		lm_message_unref ( message );
       
  6144 		return KErrGeneral;		
       
  6145 	    }
       
  6146 	
       
  6147 	// Add childrens
       
  6148 	iLog->Log ( _L ( "Adding childrens 'username' and 'password'" ) );
       
  6149 	lm_message_node_add_child ( Node, "username", Username );
       
  6150 	lm_message_node_add_child ( Node, "password", Password );
       
  6151 	
       
  6152 	// Verify the childs
       
  6153 	iLog->Log ( _L ( "Verify the childs" ) );
       
  6154 	
       
  6155 	if ( !lm_message_node_get_child ( Node, "username" ) ) 
       
  6156 	    {
       
  6157 		iLog->Log ( _L ( "lm_message_get_child failed" ) );
       
  6158 		lm_message_unref ( message );
       
  6159 		lm_message_node_unref ( Node );		
       
  6160 		return KErrGeneral;
       
  6161 	    }
       
  6162 	
       
  6163 	if ( !lm_message_node_get_child ( Node, "password" ) )
       
  6164 	    {
       
  6165 		iLog->Log ( _L ( "lm_message_get_child failed" ) );
       
  6166 		lm_message_unref ( message );
       
  6167 		lm_message_node_unref ( Node );
       
  6168 		return KErrGeneral;
       
  6169 	    }	
       
  6170 		
       
  6171 	lm_message_unref ( message );
       
  6172 	lm_message_node_unref ( Node );	
       
  6173 	
       
  6174 	iLog->Log ( _L ( "lm_message_node_get_child passed" ) );
       
  6175 	
       
  6176 	return KErrNone;	    
       
  6177 }
       
  6178 
       
  6179 //--------------------------------------------------------------------------------
       
  6180 // function_name    : handle_receive_messages
       
  6181 // description      : callback function to handle messages
       
  6182 // Returns          : LmHandlerResult
       
  6183 //--------------------------------------------------------------------------------
       
  6184 static LmHandlerResult
       
  6185 handle_receive_messages ( LmMessageHandler* /*handler*/,
       
  6186                   LmConnection*     /*connection*/,
       
  6187                   LmMessage*        /*message*/,
       
  6188                   gpointer          user_data )
       
  6189     {
       
  6190     GMainLoop *main_loop = ( GMainLoop * )user_data;	
       
  6191 	
       
  6192 	if ( main_loop )
       
  6193 		{
       
  6194 		g_main_loop_quit ( main_loop );
       
  6195 		}	
       
  6196 	
       
  6197 	return LM_HANDLER_RESULT_REMOVE_MESSAGE;
       
  6198     }
       
  6199 
       
  6200 
       
  6201 
       
  6202 //-----------------------------------------------------------------------------
       
  6203 // function_name	: connection_auth_cb
       
  6204 // description		: callback function set by lm_connection_authenticate
       
  6205 // in lm_connection_sendL()
       
  6206 // Returns			: None
       
  6207 //-----------------------------------------------------------------------------
       
  6208 //
       
  6209 static void lm_login_cb ( LmConnection * /*connection*/, 
       
  6210                      gboolean  success, 
       
  6211                      gpointer data )
       
  6212     {
       
  6213     gboolean result = success;
       
  6214     AuthData *auth_data = ( AuthData * ) data;
       
  6215     //Result is false when the wrong input parameters were successfully handled.
       
  6216     if (result == FALSE)
       
  6217 		{       
       
  6218 		auth_data->rCode = RC_OK;
       
  6219 		}
       
  6220     else 
       
  6221     	{
       
  6222     	//Result is true, when the wrong input was not handled successfully.
       
  6223        	auth_data->rCode = RC_ERROR;	
       
  6224     	}
       
  6225     g_main_loop_quit ( auth_data->main_loop ); 		
       
  6226     }
       
  6227 
       
  6228 //-----------------------------------------------------------------------------
       
  6229 // Ctstlm::lm_connection_login_testL
       
  6230 // Description  : Asynchronous call to send a message
       
  6231 // Arguements   :
       
  6232 //   connection	: an LmConnection used to send message
       
  6233 //   message    : LmMessage to send
       
  6234 //   error      : location to store error, or NULL
       
  6235 // Returns      : Returns TRUE if no errors were detected while sending,
       
  6236 //                FALSE otherwise
       
  6237 //-----------------------------------------------------------------------------
       
  6238 // 
       
  6239 TInt Ctstlm::lm_login_testL ( CStifItemParser& aItem )
       
  6240     {
       
  6241 	LmConnection *connection   = NULL;
       
  6242 	//ConnectData  *connect_data = NULL;
       
  6243 	AuthData     *auth_data    = NULL;
       
  6244 	
       
  6245 	
       
  6246 	iLog->Log ( _L ( "In lm_login_testL" ) );
       
  6247 	
       
  6248 	auth_data = g_new0 ( AuthData, 1 );
       
  6249 	if ( !auth_data )
       
  6250 		{
       
  6251 		iLog->Log ( _L ( "memory allocation failed for auth_data" ) );
       
  6252 		return KErrGeneral;
       
  6253 		}	
       
  6254 	
       
  6255 	// Read a data from the CFG file
       
  6256 	if ( read_data ( auth_data->connect_data, aItem ) != RC_OK )
       
  6257 		{
       
  6258 		iLog->Log ( _L ( "read_data failed" ) );
       
  6259 		free_data ( auth_data->connect_data );
       
  6260 		return KErrGeneral;
       
  6261 		}
       
  6262 	iLog->Log ( _L ( "after read_data" ) );
       
  6263 	
       
  6264 	// Open a new closed connection
       
  6265 	connection = lm_connection_new ( auth_data->connect_data->server );
       
  6266 	iLog->Log ( _L ( "after lm_connection_new " ) );
       
  6267 	if ( !connection )
       
  6268 		{
       
  6269 		iLog->Log ( _L ( "lm_connection_new failed" ) );
       
  6270 		free_data ( auth_data->connect_data );
       
  6271 		return KErrGeneral;
       
  6272 		}
       
  6273 	
       
  6274 	// Set the gtalk's SSL port
       
  6275 	lm_connection_set_port ( connection, GTALK_SSL_PORT );
       
  6276 	
       
  6277 	// Set the JID
       
  6278 	lm_connection_set_jid ( connection, auth_data->connect_data->username );
       
  6279 	
       
  6280 	// Proxy settings for Emulator
       
  6281 #ifdef __WINSCW__
       
  6282 	SetProxy ( connection, auth_data->connect_data->proxy_data );
       
  6283 #endif
       
  6284 	
       
  6285 	// Set the connection to use SSL
       
  6286 	SSLInit ( connection );
       
  6287 	
       
  6288 	auth_data->main_loop = g_main_loop_new ( NULL, FALSE );
       
  6289 
       
  6290 	iLog->Log ( _L ( "before lm_connection_open" ) );
       
  6291 	
       
  6292 	if ( !lm_connection_open ( connection, ( LmResultFunction ) connection_open_cb,
       
  6293 	                           auth_data->main_loop, NULL, NULL ) ) 
       
  6294 	    {
       
  6295 		iLog->Log ( _L ( "lm_connection_open failed" ));
       
  6296 		lm_connection_unref ( connection );
       
  6297 		g_main_loop_unref ( auth_data->main_loop );
       
  6298 		free_data ( auth_data->connect_data );
       
  6299 				
       
  6300 		g_free(auth_data);
       
  6301 		return KErrGeneral;
       
  6302 	    }
       
  6303 		
       
  6304 	iLog->Log ( _L ( "after lm_connection_open" ) );
       
  6305 	
       
  6306 	g_main_loop_run ( auth_data->main_loop );
       
  6307 
       
  6308 	g_main_loop_unref ( auth_data->main_loop );    
       
  6309 
       
  6310 	
       
  6311 	auth_data->main_loop = g_main_loop_new ( NULL, FALSE );
       
  6312 	
       
  6313 	// Get the username from the JID
       
  6314 	gchar *username = get_user_name ( auth_data->connect_data->username );
       
  6315 	
       
  6316 	// Authenticate with the server
       
  6317 	if ( !lm_connection_authenticate ( connection,
       
  6318                                      username,
       
  6319                                      auth_data->connect_data->password,
       
  6320                                      auth_data->connect_data->resource,
       
  6321                                       ( LmResultFunction ) lm_login_cb,
       
  6322                                      auth_data,NULL,NULL ) )
       
  6323 	    {
       
  6324 		iLog->Log ( _L ( "lm_connection_authenticate failed" ) );
       
  6325 		lm_connection_close ( connection, NULL );
       
  6326 		lm_connection_unref ( connection );
       
  6327 		free_data ( auth_data->connect_data );
       
  6328 		g_main_loop_unref ( auth_data->main_loop );
       
  6329 		g_free ( username );
       
  6330 		g_free ( auth_data );
       
  6331 		return KErrGeneral;
       
  6332 	    }
       
  6333 
       
  6334 	g_main_loop_run ( auth_data->main_loop );
       
  6335 	g_main_loop_unref ( auth_data->main_loop ); 
       
  6336 	g_free ( username );
       
  6337 	
       
  6338 	// Close the connection
       
  6339 	lm_connection_close ( connection, NULL );	
       
  6340 	// Remove a reference on connection
       
  6341 	lm_connection_unref ( connection );
       
  6342 	free_data ( auth_data->connect_data );
       
  6343 	
       
  6344 	if ( auth_data->rCode == RC_ERROR )
       
  6345 	    {
       
  6346 	    iLog->Log ( _L ( "lm_login_testL failed" ) );
       
  6347 	    g_free ( auth_data );
       
  6348 	    return KErrGeneral;
       
  6349 	    }	
       
  6350 	g_free ( auth_data );
       
  6351 
       
  6352 	// Message sending passed
       
  6353 	iLog->Log ( _L ( "lm_login_testL passed" ) );
       
  6354 	
       
  6355 	return KErrNone;
       
  6356 }
       
  6357 
       
  6358 
       
  6359 //-----------------------------------------------------------------------------
       
  6360 // Ctstlm::lm_connection_send400charL
       
  6361 // Description  : Asynchronous call to send a message of 400 characters
       
  6362 // Arguements   :
       
  6363 //   connection	: an LmConnection used to send message
       
  6364 //   message    : LmMessage to send
       
  6365 //   error      : location to store error, or NULL
       
  6366 // Returns      : Returns TRUE if no errors were detected while sending,
       
  6367 //                FALSE otherwise
       
  6368 //-----------------------------------------------------------------------------
       
  6369 // 
       
  6370 TInt Ctstlm::lm_connection_send400charL ( CStifItemParser& aItem )
       
  6371     {
       
  6372 	LmConnection *connection   = NULL;
       
  6373 	ConnectData  *connect_data = NULL;
       
  6374 	LmMessage    *message;
       
  6375 	
       
  6376 	iLog->Log ( _L ( "In lm_connection_send" ) );
       
  6377 	
       
  6378 	// Read a data from the CFG file
       
  6379 	if ( read_data ( connect_data, aItem ) != RC_OK )
       
  6380 		{
       
  6381 		iLog->Log ( _L ( "read_data failed" ) );
       
  6382 		free_data ( connect_data );
       
  6383 		return KErrGeneral;
       
  6384 		}
       
  6385 	iLog->Log ( _L ( "after read_data" ) );
       
  6386 	
       
  6387 	// Open a new closed connection
       
  6388 	connection = lm_connection_new ( connect_data->server );
       
  6389 	iLog->Log ( _L ( "after lm_connection_new " ) );
       
  6390 	if ( !connection )
       
  6391 		{
       
  6392 		iLog->Log ( _L ( "lm_connection_new failed" ) );
       
  6393 		free_data ( connect_data );
       
  6394 		return KErrGeneral;
       
  6395 		}
       
  6396 	
       
  6397 	// Set the gtalk's SSL port
       
  6398 	lm_connection_set_port ( connection, GTALK_SSL_PORT );
       
  6399 	
       
  6400 	// Set the JID
       
  6401 	lm_connection_set_jid ( connection, connect_data->username );
       
  6402 	
       
  6403 	// Proxy settings for Emulator
       
  6404 #ifdef __WINSCW__
       
  6405 	SetProxy ( connection, connect_data->proxy_data );
       
  6406 #endif
       
  6407 	
       
  6408 	// Set the connection to use SSL
       
  6409 	SSLInit ( connection );
       
  6410 	
       
  6411 	GMainLoop	*main_loop = g_main_loop_new ( NULL, FALSE );
       
  6412 
       
  6413 	iLog->Log ( _L ( "before lm_connection_open" ) );
       
  6414 	
       
  6415 	if ( !lm_connection_open ( connection, ( LmResultFunction ) connection_open_cb,
       
  6416 	                           main_loop, NULL, NULL ) ) 
       
  6417 	    {
       
  6418 		iLog->Log ( _L ( "lm_connection_open failed" ));
       
  6419 		lm_connection_unref ( connection );
       
  6420 		g_main_loop_unref ( main_loop );
       
  6421 		free_data ( connect_data );		
       
  6422 		return KErrGeneral;
       
  6423 	    }
       
  6424 		
       
  6425 	iLog->Log ( _L ( "after lm_connection_open" ) );	
       
  6426 	g_main_loop_run ( main_loop );
       
  6427 	g_main_loop_unref ( main_loop );
       
  6428 	
       
  6429 	main_loop = g_main_loop_new ( NULL, FALSE );
       
  6430 	
       
  6431 	// Get the username from the JID
       
  6432 	gchar *username = get_user_name ( connect_data->username );
       
  6433 	
       
  6434 	// Authenticate with the server
       
  6435 	if ( !lm_connection_authenticate ( connection,
       
  6436                                      username,
       
  6437                                      connect_data->password,
       
  6438                                      connect_data->resource,
       
  6439                                       ( LmResultFunction ) connection_auth_cb,
       
  6440                                      main_loop,NULL,NULL ) )
       
  6441 	    {
       
  6442 		iLog->Log ( _L ( "lm_connection_authenticate failed" ) );
       
  6443 		lm_connection_close ( connection, NULL );
       
  6444 		lm_connection_unref ( connection );
       
  6445 		free_data ( connect_data );
       
  6446 		g_main_loop_unref ( main_loop );
       
  6447 		g_free ( username );
       
  6448 		return KErrGeneral;
       
  6449 	    }
       
  6450 
       
  6451 	g_main_loop_run ( main_loop );
       
  6452 	g_main_loop_unref ( main_loop );
       
  6453 	g_free ( username );
       
  6454 	
       
  6455 	// Construct a message
       
  6456 	message = lm_message_new ( connect_data->msg_data->recipient,               
       
  6457 	                           LM_MESSAGE_TYPE_MESSAGE );
       
  6458 	
       
  6459 	gchar* msg = {"sdfsadFsdfsadfsdfsdjfksdjfl;jdsf;jsadfl;jsdvdfggdfg:   \
       
  6460 				fjsdljfsldfjsfwerpwerpweripwierweirpiwepriwperiwperipwer  \
       
  6461 				fjsdljfsldfjsfwerpwerpweripwierweirpiwepriwperiwperipwer  \
       
  6462 				fjsdljfsldfjsfwerpwerpweripwierweirpiwepriwperiwperipwer  \
       
  6463 				fjsdljfsldfjsfwerpwerpweripwierweirpiwepriwperiwperipwer  \
       
  6464 				fjsdljfsldfjsfwerpwerpweripwierweirpiwepriwperiwperipwer  \
       
  6465 				fjsdljfsldfjsfwerpwerpweripwierweirpiwepriwperiwperipwer  \
       
  6466 				fjsdljfsldfjsfwerpwerpweripwierweirpiwepriwperiwperipwer  \
       
  6467 				fjsdljfsldfjsfwerpwerpweripwierweirpiwepriwperiwperipwer"};
       
  6468 	
       
  6469 	lm_message_node_add_child ( message->node, "body", 
       
  6470 	                            msg );
       
  6471 	
       
  6472 	// Send message to the server
       
  6473 	if ( !lm_connection_send ( connection, message, NULL ) )
       
  6474 	    {
       
  6475 		iLog->Log ( _L ( "lm_connection_send failed" ) );
       
  6476 		lm_connection_close ( connection, NULL );
       
  6477 		lm_connection_unref ( connection );
       
  6478 		lm_message_unref ( message );
       
  6479 		free_data ( connect_data );		
       
  6480 		return KErrGeneral;
       
  6481 	    }	
       
  6482 	
       
  6483 	// Close the connection
       
  6484 	lm_connection_close ( connection, NULL );
       
  6485 	// Remove a reference on connection
       
  6486 	lm_connection_unref ( connection );
       
  6487 	// Remove a reference on message
       
  6488 	lm_message_unref ( message );
       
  6489 	free_data ( connect_data );
       
  6490 	
       
  6491 	// Message sending passed
       
  6492 	iLog->Log ( _L ( "lm_connection_send passed" ) );
       
  6493 	
       
  6494 	return KErrNone;
       
  6495     
       
  6496     }
       
  6497 
       
  6498 //-----------------------------------------------------------------------------
       
  6499 // Ctstlm::lm_connection_send_repeatedL
       
  6500 // Description  : Asynchronous call to send a message
       
  6501 // Arguements   :
       
  6502 //   connection	: an LmConnection used to send message
       
  6503 //   message    : LmMessage to send
       
  6504 //   error      : location to store error, or NULL
       
  6505 // Returns      : Returns TRUE if no errors were detected while sending,
       
  6506 //                FALSE otherwise
       
  6507 //-----------------------------------------------------------------------------
       
  6508 // 
       
  6509 TInt Ctstlm::lm_connection_send_repeatedL ( CStifItemParser& aItem )
       
  6510     {
       
  6511 	LmConnection *connection   = NULL;
       
  6512 	ConnectData  *connect_data = NULL;
       
  6513 	LmMessage    *message;
       
  6514 	
       
  6515 	iLog->Log ( _L ( "In lm_connection_send_repeatedL" ) );
       
  6516 	
       
  6517 	// Read a data from the CFG file
       
  6518 	if ( read_data ( connect_data, aItem ) != RC_OK )
       
  6519 		{
       
  6520 		iLog->Log ( _L ( "read_data failed" ) );
       
  6521 		free_data ( connect_data );
       
  6522 		return KErrGeneral;
       
  6523 		}
       
  6524 	iLog->Log ( _L ( "after read_data" ) );
       
  6525 	
       
  6526 	// Open a new closed connection
       
  6527 	connection = lm_connection_new ( connect_data->server );
       
  6528 	iLog->Log ( _L ( "after lm_connection_new " ) );
       
  6529 	if ( !connection )
       
  6530 		{
       
  6531 		iLog->Log ( _L ( "lm_connection_new failed" ) );
       
  6532 		free_data ( connect_data );
       
  6533 		return KErrGeneral;
       
  6534 		}
       
  6535 	
       
  6536 	// Set the gtalk's SSL port
       
  6537 	lm_connection_set_port ( connection, GTALK_SSL_PORT );
       
  6538 	
       
  6539 	// Set the JID
       
  6540 	lm_connection_set_jid ( connection, connect_data->username );
       
  6541 	
       
  6542 	// Proxy settings for Emulator
       
  6543 #ifdef __WINSCW__
       
  6544 	SetProxy ( connection, connect_data->proxy_data );
       
  6545 #endif
       
  6546 	
       
  6547 	// Set the connection to use SSL
       
  6548 	SSLInit ( connection );
       
  6549 	
       
  6550 	GMainLoop	*main_loop = g_main_loop_new ( NULL, FALSE );
       
  6551 
       
  6552 	iLog->Log ( _L ( "before lm_connection_open" ) );
       
  6553 	
       
  6554 	if ( !lm_connection_open ( connection, ( LmResultFunction ) connection_open_cb,
       
  6555 	                           main_loop, NULL, NULL ) ) 
       
  6556 	    {
       
  6557 		iLog->Log ( _L ( "lm_connection_open failed" ));
       
  6558 		lm_connection_unref ( connection );
       
  6559 		g_main_loop_unref ( main_loop );
       
  6560 		free_data ( connect_data );		
       
  6561 		return KErrGeneral;
       
  6562 	    }
       
  6563 		
       
  6564 	iLog->Log ( _L ( "after lm_connection_open" ) );
       
  6565 	g_main_loop_run ( main_loop );
       
  6566 	g_main_loop_unref ( main_loop );    
       
  6567 	
       
  6568 	main_loop = g_main_loop_new ( NULL, FALSE );
       
  6569 	
       
  6570 	// Get the username from the JID
       
  6571 	gchar *username = get_user_name ( connect_data->username );
       
  6572 	
       
  6573 	// Authenticate with the server
       
  6574 	if ( !lm_connection_authenticate ( connection,
       
  6575                                      username,
       
  6576                                      connect_data->password,
       
  6577                                      connect_data->resource,
       
  6578                                       ( LmResultFunction ) connection_auth_cb,
       
  6579                                      main_loop,NULL,NULL ) )
       
  6580 	    {
       
  6581 		iLog->Log ( _L ( "lm_connection_authenticate failed" ) );
       
  6582 		lm_connection_close ( connection, NULL );
       
  6583 		lm_connection_unref ( connection );
       
  6584 		free_data ( connect_data );
       
  6585 		g_main_loop_unref ( main_loop );
       
  6586 		g_free ( username );
       
  6587 		return KErrGeneral;
       
  6588 	    }
       
  6589 	g_main_loop_run ( main_loop );
       
  6590 	g_main_loop_unref ( main_loop );
       
  6591 	g_free ( username );
       
  6592 	
       
  6593 	// Construct a message
       
  6594 	message = lm_message_new ( connect_data->msg_data->recipient,               
       
  6595 	                           LM_MESSAGE_TYPE_MESSAGE );
       
  6596 	lm_message_node_add_child ( message->node, "body", 
       
  6597 	                            connect_data->msg_data->message);
       
  6598 	
       
  6599 	// Send message to the server
       
  6600 	if ( !lm_connection_send ( connection, message, NULL ) )
       
  6601 	    {
       
  6602 		iLog->Log ( _L ( "lm_connection_send failed" ) );
       
  6603 		lm_connection_close ( connection, NULL );
       
  6604 		lm_connection_unref ( connection );
       
  6605 		lm_message_unref ( message );
       
  6606 		free_data ( connect_data );		
       
  6607 		return KErrGeneral;
       
  6608 	    }	
       
  6609 	
       
  6610 		// Send message to the server
       
  6611 	if ( !lm_connection_send ( connection, message, NULL ) )
       
  6612 	    {
       
  6613 		iLog->Log ( _L ( "lm_connection_send_repeatedL failed" ) );
       
  6614 		lm_connection_close ( connection, NULL );
       
  6615 		lm_connection_unref ( connection );
       
  6616 		lm_message_unref ( message );
       
  6617 		free_data ( connect_data );		
       
  6618 		return KErrGeneral;
       
  6619 	    }	
       
  6620 	    
       
  6621 	// Send message to the server
       
  6622 	if ( !lm_connection_send ( connection, message, NULL ) )
       
  6623 	    {
       
  6624 		iLog->Log ( _L ( "lm_connection_send_repeatedL failed" ) );
       
  6625 		lm_connection_close ( connection, NULL );
       
  6626 		lm_connection_unref ( connection );
       
  6627 		lm_message_unref ( message );
       
  6628 		free_data ( connect_data );		
       
  6629 		return KErrGeneral;
       
  6630 	    }	
       
  6631 	// Send message to the server
       
  6632 	if ( !lm_connection_send ( connection, message, NULL ) )
       
  6633 	    {
       
  6634 		iLog->Log ( _L ( "lm_connection_send_repeatedL failed" ) );
       
  6635 		lm_connection_close ( connection, NULL );
       
  6636 		lm_connection_unref ( connection );
       
  6637 		lm_message_unref ( message );
       
  6638 		free_data ( connect_data );		
       
  6639 		return KErrGeneral;
       
  6640 	    }	
       
  6641 	// Send message to the server
       
  6642 	if ( !lm_connection_send ( connection, message, NULL ) )
       
  6643 	    {
       
  6644 		iLog->Log ( _L ( "lm_connection_send_repeatedL failed" ) );
       
  6645 		lm_connection_close ( connection, NULL );
       
  6646 		lm_connection_unref ( connection );
       
  6647 		lm_message_unref ( message );
       
  6648 		free_data ( connect_data );		
       
  6649 		return KErrGeneral;
       
  6650 	    }		    	   	    
       
  6651 	// Close the connection
       
  6652 	lm_connection_close ( connection, NULL );
       
  6653 	
       
  6654 	// Remove a reference on connection
       
  6655 	lm_connection_unref ( connection );
       
  6656 	
       
  6657 	// Remove a reference on message
       
  6658 	lm_message_unref ( message );
       
  6659 	
       
  6660 	free_data ( connect_data );
       
  6661 	
       
  6662 	// Message sending passed
       
  6663 	iLog->Log ( _L ( "lm_connection_send passed" ) );
       
  6664 	
       
  6665 	return KErrNone;
       
  6666 }
       
  6667 //--------------------------------------------------------------------------------
       
  6668 // function_name    : handle_add_contact
       
  6669 // description      : callback function to handle messages
       
  6670 // Returns          : LmHandlerResult
       
  6671 //--------------------------------------------------------------------------------
       
  6672 static LmHandlerResult
       
  6673 handle_add_contact ( LmMessageHandler* /*handler*/,
       
  6674                   LmConnection*     /*connection*/,
       
  6675                   LmMessage*        reply,
       
  6676                   gpointer          user_data )
       
  6677     {
       
  6678     GMainLoop *main_loop = ( GMainLoop * )user_data;	
       
  6679 	LmMessageSubType  type;
       
  6680 	LmMessageNode *q_node,*item_node;
       
  6681 	type = lm_message_get_sub_type (reply); 
       
  6682      	
       
  6683     
       
  6684 	switch (type) 
       
  6685     	{
       
  6686     	case LM_MESSAGE_SUB_TYPE_SET:        		        		
       
  6687 	   			{
       
  6688     			/*
       
  6689 			    <iq to='juliet@example.com/balcony' type='set' id='a78b4q6ha463'>
       
  6690 					<query xmlns='jabber:iq:roster'>
       
  6691 					    <item jid='nurse@example.com'
       
  6692 					          name='Nurse'
       
  6693 					          subscription='none'>
       
  6694 					      <group>Servants</group>
       
  6695 					    </item>
       
  6696 			  		</query>
       
  6697 				</iq>
       
  6698 				*/				
       
  6699     			q_node = lm_message_node_get_child (reply->node, "query");   	
       
  6700 				if (q_node) 
       
  6701 			    	{
       
  6702 			   		item_node = lm_message_node_get_child (q_node, "item");
       
  6703 			   		if(item_node)
       
  6704 			   			{
       
  6705 			   			const char* reply_string;
       
  6706 			        	reply_string = lm_message_node_get_attribute(item_node,"jid");  
       
  6707 			        	}
       
  6708 			    
       
  6709         			}	
       
  6710     			
       
  6711     			break;
       
  6712 	   			}
       
  6713     	case LM_MESSAGE_SUB_TYPE_ERROR:          	          		
       
  6714     		{
       
  6715     		/*<iq from='prima@chat.gizmoproject.com/mytest12345rt' 
       
  6716 			to='prima@chat.gizmoproject.com/mytest12345rt' 
       
  6717 			id='164121175000' type='error'>
       
  6718 				<query xmlns='jabber:iq:roster'> 
       
  6719 					<item jid='testlmnokia1111@chat.gizmoproject.com'/>
       
  6720 				</query>
       
  6721 				<error code='404' type='cancel'>
       
  6722 					<item-not-found xmlns='urn:ietf:params:xml:ns:xmpp-stanzas'/>
       
  6723 				</error>
       
  6724 			</iq>
       
  6725 			*/  
       
  6726 			//return NULL;
       
  6727     		LmMessageNode* error_node=NULL;
       
  6728     		LmMessageNode* error_node_child=NULL;
       
  6729 	    	error_node = lm_message_node_get_child (reply->node, "error");
       
  6730 		   	if(error_node)
       
  6731 	   			{
       
  6732 	   			const char* error_code;
       
  6733 	        	error_code = lm_message_node_get_attribute(error_node,"code");  
       
  6734 	        	error_node_child = lm_message_node_get_child (error_node, "item-not-found");
       
  6735 	        	}
       
  6736     		break;
       
  6737     		}
       
  6738     //	default:
       
  6739     	//	g_assert_not_reached ();
       
  6740     	//	break;
       
  6741     	} 
       
  6742     
       
  6743 	if ( main_loop )
       
  6744 		{
       
  6745 		g_main_loop_quit ( main_loop );
       
  6746 		}	
       
  6747 	
       
  6748 	return LM_HANDLER_RESULT_REMOVE_MESSAGE;
       
  6749     }    
       
  6750 
       
  6751 //-----------------------------------------------------------------------------
       
  6752 // Ctstlm::lm_add_contactL
       
  6753 // Description  : Asynchronous call to add a new contact
       
  6754 //   connection	: an LmConnection used to send message
       
  6755 //   message    : LmMessage to send
       
  6756 //   error      : location to store error, or NULL
       
  6757 // Returns      : Returns TRUE if no errors were detected while sending,
       
  6758 //                FALSE otherwise
       
  6759 //-----------------------------------------------------------------------------
       
  6760 // 
       
  6761 TInt Ctstlm::lm_add_contactL ( CStifItemParser& aItem )
       
  6762     {
       
  6763 	LmConnection *connection   = NULL;
       
  6764 	ConnectData  *connect_data = NULL;
       
  6765 	LmMessage    *message;
       
  6766 	LmMessageNode *q_node,*item_node;
       
  6767 	LmMessageHandler* handler = NULL;
       
  6768 	
       
  6769 	iLog->Log ( _L ( "In lm_add_contactL" ) );
       
  6770 	
       
  6771 	// Read a data from the CFG file
       
  6772 	if ( read_data ( connect_data, aItem ) != RC_OK )
       
  6773 		{
       
  6774 		iLog->Log ( _L ( "read_data failed" ) );
       
  6775 		free_data ( connect_data );
       
  6776 		return KErrGeneral;
       
  6777 		}
       
  6778 	iLog->Log ( _L ( "after read_data" ) );
       
  6779 	
       
  6780 	// Open a new closed connection
       
  6781 	connection = lm_connection_new ( connect_data->server );
       
  6782 	iLog->Log ( _L ( "after lm_connection_new " ) );
       
  6783 	if ( !connection )
       
  6784 		{
       
  6785 		iLog->Log ( _L ( "lm_connection_new failed" ) );
       
  6786 		free_data ( connect_data );
       
  6787 		return KErrGeneral;
       
  6788 		}
       
  6789 	
       
  6790 	// Set the gtalk's SSL port
       
  6791 	lm_connection_set_port ( connection, GTALK_SSL_PORT );
       
  6792 	
       
  6793 	// Set the JID
       
  6794 	lm_connection_set_jid ( connection, connect_data->username );
       
  6795 	
       
  6796 	// Proxy settings for Emulator
       
  6797 #ifdef __WINSCW__
       
  6798 	SetProxy ( connection, connect_data->proxy_data );
       
  6799 #endif
       
  6800 	
       
  6801 	// Set the connection to use SSL
       
  6802 	SSLInit ( connection );
       
  6803 	
       
  6804 	GMainLoop	*main_loop = g_main_loop_new ( NULL, FALSE );
       
  6805 
       
  6806 	iLog->Log ( _L ( "before lm_connection_open" ) );
       
  6807 	
       
  6808 	if ( !lm_connection_open ( connection, ( LmResultFunction ) connection_open_cb,
       
  6809 	                           main_loop, NULL, NULL ) ) 
       
  6810 	    {
       
  6811 		iLog->Log ( _L ( "lm_connection_open failed" ));
       
  6812 		lm_connection_unref ( connection );
       
  6813 		g_main_loop_unref ( main_loop );
       
  6814 		free_data ( connect_data );		
       
  6815 		return KErrGeneral;
       
  6816 	    }
       
  6817 		
       
  6818 	iLog->Log ( _L ( "after lm_connection_open" ) );
       
  6819 	
       
  6820 	g_main_loop_run ( main_loop );
       
  6821 
       
  6822 	g_main_loop_unref ( main_loop );    
       
  6823 
       
  6824 	
       
  6825 	main_loop = g_main_loop_new ( NULL, FALSE );
       
  6826 	
       
  6827 	// Get the username from the JID
       
  6828 	gchar *username = get_user_name ( connect_data->username );
       
  6829 	
       
  6830 	// Authenticate with the server
       
  6831 	if ( !lm_connection_authenticate ( connection,
       
  6832                                      username,
       
  6833                                      connect_data->password,
       
  6834                                      connect_data->resource,
       
  6835                                       ( LmResultFunction ) connection_auth_cb,
       
  6836                                      main_loop,NULL,NULL ) )
       
  6837 	    {
       
  6838 		iLog->Log ( _L ( "lm_connection_authenticate failed" ) );
       
  6839 		lm_connection_close ( connection, NULL );
       
  6840 		lm_connection_unref ( connection );
       
  6841 		free_data ( connect_data );
       
  6842 		g_main_loop_unref ( main_loop );
       
  6843 		g_free ( username );
       
  6844 		return KErrGeneral;
       
  6845 	    }
       
  6846 	g_main_loop_run ( main_loop );
       
  6847 	g_main_loop_unref ( main_loop );
       
  6848 	g_free ( username );	
       
  6849 	
       
  6850     /***********fetch contact list********************/
       
  6851   
       
  6852     // Construct a message
       
  6853 	main_loop = g_main_loop_new ( NULL, FALSE );
       
  6854 	message = lm_message_new_with_sub_type (NULL, LM_MESSAGE_TYPE_IQ,
       
  6855     					  LM_MESSAGE_SUB_TYPE_GET);
       
  6856     q_node = lm_message_node_add_child (message->node, "query", NULL);
       
  6857     lm_message_node_set_attributes (q_node,"xmlns", "jabber:iq:roster",NULL); 
       
  6858 	handler = lm_message_handler_new ( handle_fetch_contactlist_messages, main_loop, NULL );
       
  6859 	// Send message to the server
       
  6860 	if ( !lm_connection_send_with_reply ( connection, message, handler, NULL ) ) 
       
  6861 	    {
       
  6862 		iLog->Log ( _L ( "lm_connection_send_with_reply failed" ) );
       
  6863 		lm_connection_close ( connection, NULL );
       
  6864 		lm_connection_unref ( connection );
       
  6865 		lm_message_unref ( message );
       
  6866 		free_data ( connect_data );
       
  6867 		lm_message_handler_unref(handler);
       
  6868 		g_main_loop_unref ( main_loop );
       
  6869 		return KErrGeneral;
       
  6870 	    }	
       
  6871 	g_main_loop_run ( main_loop );
       
  6872 	g_main_loop_unref ( main_loop );                					
       
  6873     lm_message_unref ( message );
       
  6874     lm_message_handler_unref(handler);
       
  6875   
       
  6876     /****send own presence********/
       
  6877 	
       
  6878 	message = lm_message_new_with_sub_type ( NULL,
       
  6879 	                                     LM_MESSAGE_TYPE_PRESENCE,
       
  6880 	                                     LM_MESSAGE_SUB_TYPE_AVAILABLE );
       
  6881 	gboolean result = lm_connection_send ( connection, message, NULL );	
       
  6882     lm_message_unref ( message );
       
  6883     
       
  6884     /*********Send request to add a contact**********************/
       
  6885   
       
  6886 	// Construct a message
       
  6887 	main_loop = g_main_loop_new ( NULL, FALSE );
       
  6888 	message = lm_message_new_with_sub_type ( NULL,
       
  6889                                          LM_MESSAGE_TYPE_IQ,
       
  6890                                          LM_MESSAGE_SUB_TYPE_SET );
       
  6891     q_node = lm_message_node_add_child ( message->node, "query", NULL );
       
  6892     item_node = lm_message_node_add_child ( q_node, "item", NULL );
       
  6893     
       
  6894     lm_message_node_set_attribute ( q_node, "xmlns", "jabber:iq:roster" );
       
  6895     lm_message_node_set_attribute ( item_node, "jid", connect_data->msg_data->recipient );
       
  6896     //If we specify the name we cannot add the contact, maybe the name has to be unique.
       
  6897     /*lm_message_node_set_attribute ( item_node, "name", "harsh_rakesh" );
       
  6898     if ( group )
       
  6899     	{
       
  6900     	lm_message_node_add_child ( item, "group", group );
       
  6901     	}*/
       
  6902 	
       
  6903 	// Send message to the server
       
  6904 	handler = lm_message_handler_new ( handle_add_contact, main_loop, NULL );	
       
  6905 	if ( !lm_connection_send_with_reply ( connection, message, handler, NULL ) ) 
       
  6906 	    {
       
  6907 		iLog->Log ( _L ( "lm_connection_send_with_reply in lm_add_contactL failed" ) );
       
  6908 		lm_connection_close ( connection, NULL );
       
  6909 		lm_connection_unref ( connection );
       
  6910 		lm_message_unref ( message );
       
  6911 		lm_message_handler_unref(handler);
       
  6912 		free_data ( connect_data );
       
  6913 		g_main_loop_unref ( main_loop );
       
  6914 		return KErrGeneral;
       
  6915 	    }
       
  6916 	g_main_loop_run ( main_loop );
       
  6917 	g_main_loop_unref ( main_loop );	
       
  6918 	lm_message_unref ( message );    
       
  6919 	lm_message_handler_unref(handler);
       
  6920 	// Send subscription request to the server
       
  6921     message = lm_message_new_with_sub_type ( connect_data->msg_data->recipient,
       
  6922                                          LM_MESSAGE_TYPE_PRESENCE,
       
  6923                                          LM_MESSAGE_SUB_TYPE_SUBSCRIBE );
       
  6924     result = lm_connection_send ( connection, message, NULL ) ;
       
  6925     // Remove a reference on message
       
  6926 	lm_message_unref ( message );
       
  6927 	    
       
  6928 	// Close the connection
       
  6929 	lm_connection_close ( connection, NULL );
       
  6930 	
       
  6931 	// Remove a reference on connection
       
  6932 	lm_connection_unref ( connection );
       
  6933 		
       
  6934 	free_data ( connect_data );
       
  6935 	
       
  6936 	// Message sending passed
       
  6937 	iLog->Log ( _L ( "lm_add_contactL passed" ) );
       
  6938 	
       
  6939 	return KErrNone;
       
  6940 }
       
  6941 //-----------------------------------------------------------------------------
       
  6942 // Ctstlm::lm_remove_contactL
       
  6943 // Description  : Asynchronous call to add a new contact
       
  6944 //   connection	: an LmConnection used to send message
       
  6945 //   message    : LmMessage to send
       
  6946 //   error      : location to store error, or NULL
       
  6947 // Returns      : Returns TRUE if no errors were detected while sending,
       
  6948 //                FALSE otherwise
       
  6949 //-----------------------------------------------------------------------------
       
  6950 // 
       
  6951 TInt Ctstlm::lm_remove_contactL ( CStifItemParser& aItem )
       
  6952     {
       
  6953 	LmConnection *connection   = NULL;
       
  6954 	ConnectData  *connect_data = NULL;
       
  6955 	LmMessage    *message;
       
  6956 	LmMessageNode *q_node,*item_node;
       
  6957 	LmMessageHandler* handler = NULL;
       
  6958 	TBool result = EFalse;
       
  6959 	
       
  6960 	iLog->Log ( _L ( "In lm_remove_contactL" ) );
       
  6961 	
       
  6962 	// Read a data from the CFG file
       
  6963 	if ( read_data ( connect_data, aItem ) != RC_OK )
       
  6964 		{
       
  6965 		iLog->Log ( _L ( "read_data failed" ) );
       
  6966 		free_data ( connect_data );
       
  6967 		return KErrGeneral;
       
  6968 		}
       
  6969 	iLog->Log ( _L ( "after read_data" ) );
       
  6970 	
       
  6971 	// Open a new closed connection
       
  6972 	connection = lm_connection_new ( connect_data->server );
       
  6973 	iLog->Log ( _L ( "after lm_connection_new " ) );
       
  6974 	if ( !connection )
       
  6975 		{
       
  6976 		iLog->Log ( _L ( "lm_connection_new failed" ) );
       
  6977 		free_data ( connect_data );
       
  6978 		return KErrGeneral;
       
  6979 		}
       
  6980 	
       
  6981 	// Set the gtalk's SSL port
       
  6982 	lm_connection_set_port ( connection, GTALK_SSL_PORT );
       
  6983 	
       
  6984 	// Set the JID
       
  6985 	lm_connection_set_jid ( connection, connect_data->username );
       
  6986 	
       
  6987 	// Proxy settings for Emulator
       
  6988 #ifdef __WINSCW__
       
  6989 	SetProxy ( connection, connect_data->proxy_data );
       
  6990 #endif
       
  6991 	
       
  6992 	// Set the connection to use SSL
       
  6993 	SSLInit ( connection );
       
  6994 	
       
  6995 	GMainLoop	*main_loop = g_main_loop_new ( NULL, FALSE );
       
  6996 
       
  6997 	iLog->Log ( _L ( "before lm_connection_open" ) );
       
  6998 	
       
  6999 	if ( !lm_connection_open ( connection, ( LmResultFunction ) connection_open_cb,
       
  7000 	                           main_loop, NULL, NULL ) ) 
       
  7001 	    {
       
  7002 		iLog->Log ( _L ( "lm_connection_open failed" ));
       
  7003 		lm_connection_unref ( connection );
       
  7004 		g_main_loop_unref ( main_loop );
       
  7005 		free_data ( connect_data );		
       
  7006 		return KErrGeneral;
       
  7007 	    }
       
  7008 		
       
  7009 	iLog->Log ( _L ( "after lm_connection_open" ) );	
       
  7010 	g_main_loop_run ( main_loop );
       
  7011 	g_main_loop_unref ( main_loop );    	
       
  7012 	main_loop = g_main_loop_new ( NULL, FALSE );
       
  7013 	
       
  7014 	// Get the username from the JID
       
  7015 	gchar *username = get_user_name ( connect_data->username );
       
  7016 	
       
  7017 	// Authenticate with the server
       
  7018 	if ( !lm_connection_authenticate ( connection,
       
  7019                                      username,
       
  7020                                      connect_data->password,
       
  7021                                      connect_data->resource,
       
  7022                                       ( LmResultFunction ) connection_auth_cb,
       
  7023                                      main_loop,NULL,NULL ) )
       
  7024 	    {
       
  7025 		iLog->Log ( _L ( "lm_connection_authenticate failed" ) );
       
  7026 		lm_connection_close ( connection, NULL );
       
  7027 		lm_connection_unref ( connection );
       
  7028 		free_data ( connect_data );
       
  7029 		g_main_loop_unref ( main_loop );
       
  7030 		g_free ( username );
       
  7031 		return KErrGeneral;
       
  7032 	    }
       
  7033 	g_main_loop_run ( main_loop );
       
  7034 	g_main_loop_unref ( main_loop );
       
  7035 	g_free ( username );	
       
  7036 	
       
  7037     /***********fetch contact list********************/
       
  7038   
       
  7039     // Construct a message
       
  7040 	main_loop = g_main_loop_new ( NULL, FALSE );
       
  7041 	message = lm_message_new_with_sub_type (NULL, LM_MESSAGE_TYPE_IQ,
       
  7042     					  LM_MESSAGE_SUB_TYPE_GET);
       
  7043     q_node = lm_message_node_add_child (message->node, "query", NULL);
       
  7044     lm_message_node_set_attributes (q_node,"xmlns", "jabber:iq:roster",NULL); 
       
  7045 	handler = lm_message_handler_new ( handle_fetch_contactlist_messages, main_loop, NULL );
       
  7046 	// Send message to the server
       
  7047 	if ( !lm_connection_send_with_reply ( connection, message, handler, NULL ) ) 
       
  7048 	    {
       
  7049 		iLog->Log ( _L ( "lm_connection_send_with_reply failed" ) );
       
  7050 		lm_connection_close ( connection, NULL );
       
  7051 		lm_connection_unref ( connection );
       
  7052 		lm_message_unref ( message );
       
  7053 		free_data ( connect_data );
       
  7054 		lm_message_handler_unref(handler);
       
  7055 		g_main_loop_unref ( main_loop );
       
  7056 		return KErrGeneral;
       
  7057 	    }	
       
  7058 	g_main_loop_run ( main_loop );
       
  7059 	g_main_loop_unref ( main_loop );                					
       
  7060     lm_message_unref ( message );
       
  7061     lm_message_handler_unref(handler);
       
  7062     
       
  7063     /*********Send request to ADD a contact**********************/
       
  7064     //If we specify the name we cannot add the contact, maybe the name has to be unique.
       
  7065     /*lm_message_node_set_attribute ( item_node, "name", "harsh_rakesh" );
       
  7066     	if ( group )
       
  7067 	    	{
       
  7068 	    	lm_message_node_add_child ( item, "group", group );
       
  7069 	    	}
       
  7070 	*/
       
  7071 	main_loop = g_main_loop_new ( NULL, FALSE );
       
  7072 	message = lm_message_new_with_sub_type ( NULL,
       
  7073                                          LM_MESSAGE_TYPE_IQ,
       
  7074                                          LM_MESSAGE_SUB_TYPE_SET );
       
  7075     q_node = lm_message_node_add_child ( message->node, "query", NULL );
       
  7076     item_node = lm_message_node_add_child ( q_node, "item", NULL );
       
  7077     lm_message_node_set_attribute ( q_node, "xmlns", "jabber:iq:roster" );
       
  7078     lm_message_node_set_attribute ( item_node, "jid", connect_data->msg_data->recipient );
       
  7079     // Send message to the server
       
  7080 	handler = lm_message_handler_new ( handle_add_contact, main_loop, NULL );	
       
  7081 	if ( !lm_connection_send_with_reply ( connection, message, handler, NULL ) ) 
       
  7082 	    {
       
  7083 		iLog->Log ( _L ( "lm_connection_send_with_reply in lm_add_contactL failed" ) );
       
  7084 		lm_connection_close ( connection, NULL );
       
  7085 		lm_connection_unref ( connection );
       
  7086 		lm_message_unref ( message );
       
  7087 		lm_message_handler_unref(handler);
       
  7088 		free_data ( connect_data );
       
  7089 		g_main_loop_unref ( main_loop );
       
  7090 		return KErrGeneral;
       
  7091 	    }
       
  7092 	g_main_loop_run ( main_loop );
       
  7093 	g_main_loop_unref ( main_loop );	
       
  7094 	lm_message_unref ( message );    
       
  7095 	lm_message_handler_unref(handler);
       
  7096 	// Send subscription request to the server
       
  7097     message = lm_message_new_with_sub_type ( connect_data->msg_data->recipient,
       
  7098                                          LM_MESSAGE_TYPE_PRESENCE,
       
  7099                                          LM_MESSAGE_SUB_TYPE_SUBSCRIBE );
       
  7100     result = lm_connection_send ( connection, message, NULL ) ;
       
  7101     lm_message_unref ( message );    
       
  7102 	
       
  7103     /*********Send request to REMOVE a contact**********************/
       
  7104     /*
       
  7105       <iq from='juliet@example.com/balcony' type='set' id='roster_4'>
       
  7106   			<query xmlns='jabber:iq:roster'>
       
  7107     			<item jid='nurse@example.com' subscription='remove'/>
       
  7108   			</query>
       
  7109 	  </iq>
       
  7110 	*/
       
  7111 	
       
  7112 	// Construct a message
       
  7113 	main_loop = g_main_loop_new ( NULL, FALSE );
       
  7114 	message = lm_message_new_with_sub_type ( NULL,
       
  7115                                          LM_MESSAGE_TYPE_IQ,
       
  7116                                          LM_MESSAGE_SUB_TYPE_SET );
       
  7117     q_node = lm_message_node_add_child ( message->node, "query", NULL );
       
  7118     item_node = lm_message_node_add_child ( q_node, "item", NULL );
       
  7119     
       
  7120     lm_message_node_set_attribute ( q_node, "xmlns", "jabber:iq:roster" );
       
  7121     lm_message_node_set_attribute ( item_node, "jid", connect_data->msg_data->recipient );
       
  7122     lm_message_node_set_attribute ( item_node, "subscription", "remove" );
       
  7123     // Send message to the server
       
  7124 	handler = lm_message_handler_new ( handle_add_contact, main_loop, NULL );	
       
  7125 	if ( !lm_connection_send_with_reply ( connection, message, handler, NULL ) ) 
       
  7126 	    {
       
  7127 		iLog->Log ( _L ( "lm_connection_send_with_reply in lm_remove_contactL failed" ) );
       
  7128 		lm_connection_close ( connection, NULL );
       
  7129 		lm_connection_unref ( connection );
       
  7130 		lm_message_unref ( message );
       
  7131 		lm_message_handler_unref(handler);
       
  7132 		free_data ( connect_data );
       
  7133 		g_main_loop_unref ( main_loop );
       
  7134 		return KErrGeneral;
       
  7135 	    }
       
  7136 	g_main_loop_run ( main_loop );
       
  7137 	g_main_loop_unref ( main_loop );
       
  7138 	
       
  7139 	lm_message_unref ( message );    
       
  7140 	lm_message_handler_unref(handler);	 
       
  7141 	
       
  7142 	/***********FETCH contact list********************/
       
  7143   
       
  7144     // Construct a message
       
  7145 	main_loop = g_main_loop_new ( NULL, FALSE );
       
  7146 	message = lm_message_new_with_sub_type (NULL, LM_MESSAGE_TYPE_IQ,
       
  7147     					  LM_MESSAGE_SUB_TYPE_GET);
       
  7148     q_node = lm_message_node_add_child (message->node, "query", NULL);
       
  7149     lm_message_node_set_attributes (q_node,"xmlns", "jabber:iq:roster",NULL); 
       
  7150 	handler = lm_message_handler_new ( handle_fetch_contactlist_messages, main_loop, NULL );
       
  7151 	// Send message to the server
       
  7152 	if ( !lm_connection_send_with_reply ( connection, message, handler, NULL ) ) 
       
  7153 	    {
       
  7154 		iLog->Log ( _L ( "lm_connection_send_with_reply failed" ) );
       
  7155 		lm_connection_close ( connection, NULL );
       
  7156 		lm_connection_unref ( connection );
       
  7157 		lm_message_unref ( message );
       
  7158 		free_data ( connect_data );
       
  7159 		lm_message_handler_unref(handler);
       
  7160 		g_main_loop_unref ( main_loop );
       
  7161 		return KErrGeneral;
       
  7162 	    }	
       
  7163 	g_main_loop_run ( main_loop );
       
  7164 	g_main_loop_unref ( main_loop );                					
       
  7165     lm_message_unref ( message );
       
  7166     lm_message_handler_unref(handler);   		
       
  7167 	
       
  7168 	/*********Send request to ADD a contact**********************/
       
  7169   	// Construct a message
       
  7170 	main_loop = g_main_loop_new ( NULL, FALSE );
       
  7171 	message = lm_message_new_with_sub_type ( NULL,
       
  7172                                          LM_MESSAGE_TYPE_IQ,
       
  7173                                          LM_MESSAGE_SUB_TYPE_SET );
       
  7174     q_node = lm_message_node_add_child ( message->node, "query", NULL );
       
  7175     item_node = lm_message_node_add_child ( q_node, "item", NULL );
       
  7176     
       
  7177     lm_message_node_set_attribute ( q_node, "xmlns", "jabber:iq:roster" );
       
  7178     lm_message_node_set_attribute ( item_node, "jid", connect_data->msg_data->recipient);
       
  7179     
       
  7180 	// Send message to the server
       
  7181 	handler = lm_message_handler_new ( handle_add_contact, main_loop, NULL );	
       
  7182 	if ( !lm_connection_send_with_reply ( connection, message, handler, NULL ) ) 
       
  7183 	    {
       
  7184 		iLog->Log ( _L ( "lm_connection_send_with_reply in lm_add_contactL failed" ) );
       
  7185 		lm_connection_close ( connection, NULL );
       
  7186 		lm_connection_unref ( connection );
       
  7187 		lm_message_unref ( message );
       
  7188 		lm_message_handler_unref(handler);
       
  7189 		free_data ( connect_data );
       
  7190 		g_main_loop_unref ( main_loop );
       
  7191 		return KErrGeneral;
       
  7192 	    }
       
  7193 	g_main_loop_run ( main_loop );
       
  7194 	g_main_loop_unref ( main_loop );	
       
  7195 	lm_message_unref ( message );    
       
  7196 	lm_message_handler_unref(handler);
       
  7197 	// Send subscription request to the server
       
  7198     message = lm_message_new_with_sub_type ( connect_data->msg_data->recipient,
       
  7199                                          LM_MESSAGE_TYPE_PRESENCE,
       
  7200                                          LM_MESSAGE_SUB_TYPE_SUBSCRIBE );
       
  7201     result = lm_connection_send ( connection, message, NULL ) ;
       
  7202 	// Remove a reference on message
       
  7203 	lm_message_unref ( message );
       
  7204 	
       
  7205 	/***********FETCH contact list********************/
       
  7206   
       
  7207     // Construct a message
       
  7208 	main_loop = g_main_loop_new ( NULL, FALSE );
       
  7209 	message = lm_message_new_with_sub_type (NULL, LM_MESSAGE_TYPE_IQ,
       
  7210     					  LM_MESSAGE_SUB_TYPE_GET);
       
  7211     q_node = lm_message_node_add_child (message->node, "query", NULL);
       
  7212     lm_message_node_set_attributes (q_node,"xmlns", "jabber:iq:roster",NULL); 
       
  7213 	handler = lm_message_handler_new ( handle_fetch_contactlist_messages, main_loop, NULL );
       
  7214 	// Send message to the server
       
  7215 	if ( !lm_connection_send_with_reply ( connection, message, handler, NULL ) ) 
       
  7216 	    {
       
  7217 		iLog->Log ( _L ( "lm_connection_send_with_reply failed" ) );
       
  7218 		lm_connection_close ( connection, NULL );
       
  7219 		lm_connection_unref ( connection );
       
  7220 		lm_message_unref ( message );
       
  7221 		free_data ( connect_data );
       
  7222 		lm_message_handler_unref(handler);
       
  7223 		g_main_loop_unref ( main_loop );
       
  7224 		return KErrGeneral;
       
  7225 	    }	
       
  7226 	g_main_loop_run ( main_loop );
       
  7227 	g_main_loop_unref ( main_loop );                					
       
  7228     lm_message_unref ( message );
       
  7229     lm_message_handler_unref(handler);
       
  7230 	
       
  7231 	/*********Send request to REMOVE a contact**********************/
       
  7232     /*
       
  7233       <iq from='juliet@example.com/balcony' type='set' id='roster_4'>
       
  7234   			<query xmlns='jabber:iq:roster'>
       
  7235     			<item jid='nurse@example.com' subscription='remove'/>
       
  7236   			</query>
       
  7237 	  </iq>
       
  7238 	*/
       
  7239 	
       
  7240 	// Construct a message
       
  7241 	main_loop = g_main_loop_new ( NULL, FALSE );
       
  7242 	message = lm_message_new_with_sub_type ( NULL,
       
  7243                                          LM_MESSAGE_TYPE_IQ,
       
  7244                                          LM_MESSAGE_SUB_TYPE_SET );
       
  7245     q_node = lm_message_node_add_child ( message->node, "query", NULL );
       
  7246     item_node = lm_message_node_add_child ( q_node, "item", NULL );
       
  7247     
       
  7248     lm_message_node_set_attribute ( q_node, "xmlns", "jabber:iq:roster" );
       
  7249     lm_message_node_set_attribute ( item_node, "jid", connect_data->msg_data->recipient );
       
  7250     lm_message_node_set_attribute ( item_node, "subscription", "remove" );
       
  7251     // Send message to the server
       
  7252 	handler = lm_message_handler_new ( handle_add_contact, main_loop, NULL );	
       
  7253 	if ( !lm_connection_send_with_reply ( connection, message, handler, NULL ) ) 
       
  7254 	    {
       
  7255 		iLog->Log ( _L ( "lm_connection_send_with_reply in lm_remove_contactL failed" ) );
       
  7256 		lm_connection_close ( connection, NULL );
       
  7257 		lm_connection_unref ( connection );
       
  7258 		lm_message_unref ( message );
       
  7259 		lm_message_handler_unref(handler);
       
  7260 		free_data ( connect_data );
       
  7261 		g_main_loop_unref ( main_loop );
       
  7262 		return KErrGeneral;
       
  7263 	    }
       
  7264 	g_main_loop_run ( main_loop );
       
  7265 	g_main_loop_unref ( main_loop );
       
  7266 	
       
  7267 	lm_message_unref ( message );    
       
  7268 	lm_message_handler_unref(handler);	    
       
  7269 	
       
  7270 	/***********FETCH contact list********************/
       
  7271   
       
  7272     // Construct a message
       
  7273 	main_loop = g_main_loop_new ( NULL, FALSE );
       
  7274 	message = lm_message_new_with_sub_type (NULL, LM_MESSAGE_TYPE_IQ,
       
  7275     					  LM_MESSAGE_SUB_TYPE_GET);
       
  7276     q_node = lm_message_node_add_child (message->node, "query", NULL);
       
  7277     lm_message_node_set_attributes (q_node,"xmlns", "jabber:iq:roster",NULL); 
       
  7278 	handler = lm_message_handler_new ( handle_fetch_contactlist_messages, main_loop, NULL );
       
  7279 	// Send message to the server
       
  7280 	if ( !lm_connection_send_with_reply ( connection, message, handler, NULL ) ) 
       
  7281 	    {
       
  7282 		iLog->Log ( _L ( "lm_connection_send_with_reply failed" ) );
       
  7283 		lm_connection_close ( connection, NULL );
       
  7284 		lm_connection_unref ( connection );
       
  7285 		lm_message_unref ( message );
       
  7286 		free_data ( connect_data );
       
  7287 		lm_message_handler_unref(handler);
       
  7288 		g_main_loop_unref ( main_loop );
       
  7289 		return KErrGeneral;
       
  7290 	    }	
       
  7291 	g_main_loop_run ( main_loop );
       
  7292 	g_main_loop_unref ( main_loop );                					
       
  7293     lm_message_unref ( message );
       
  7294     lm_message_handler_unref(handler);		
       
  7295 
       
  7296 
       
  7297 	/*********Send request to ADD a contact**********************/
       
  7298     //If we specify the name we cannot add the contact, maybe the name has to be unique.
       
  7299     /*lm_message_node_set_attribute ( item_node, "name", "harsh_rakesh" );
       
  7300     	if ( group )
       
  7301 	    	{
       
  7302 	    	lm_message_node_add_child ( item, "group", group );
       
  7303 	    	}
       
  7304 	*/
       
  7305 	main_loop = g_main_loop_new ( NULL, FALSE );
       
  7306 	message = lm_message_new_with_sub_type ( NULL,
       
  7307                                          LM_MESSAGE_TYPE_IQ,
       
  7308                                          LM_MESSAGE_SUB_TYPE_SET );
       
  7309     q_node = lm_message_node_add_child ( message->node, "query", NULL );
       
  7310     item_node = lm_message_node_add_child ( q_node, "item", NULL );
       
  7311     lm_message_node_set_attribute ( q_node, "xmlns", "jabber:iq:roster" );
       
  7312     lm_message_node_set_attribute ( item_node, "jid", connect_data->msg_data->recipient );
       
  7313     // Send message to the server
       
  7314 	handler = lm_message_handler_new ( handle_add_contact, main_loop, NULL );	
       
  7315 	if ( !lm_connection_send_with_reply ( connection, message, handler, NULL ) ) 
       
  7316 	    {
       
  7317 		iLog->Log ( _L ( "lm_connection_send_with_reply in lm_add_contactL failed" ) );
       
  7318 		lm_connection_close ( connection, NULL );
       
  7319 		lm_connection_unref ( connection );
       
  7320 		lm_message_unref ( message );
       
  7321 		lm_message_handler_unref(handler);
       
  7322 		free_data ( connect_data );
       
  7323 		g_main_loop_unref ( main_loop );
       
  7324 		return KErrGeneral;
       
  7325 	    }
       
  7326 	g_main_loop_run ( main_loop );
       
  7327 	g_main_loop_unref ( main_loop );	
       
  7328 	lm_message_unref ( message );    
       
  7329 	lm_message_handler_unref(handler);
       
  7330 	// Send subscription request to the server
       
  7331     message = lm_message_new_with_sub_type ( connect_data->msg_data->recipient,
       
  7332                                          LM_MESSAGE_TYPE_PRESENCE,
       
  7333                                          LM_MESSAGE_SUB_TYPE_SUBSCRIBE );
       
  7334     result = lm_connection_send ( connection, message, NULL ) ;
       
  7335     lm_message_unref ( message );  
       
  7336     	    
       
  7337 	/***********cleanup*****************/
       
  7338 	// Close the connection
       
  7339 	lm_connection_close ( connection, NULL );	
       
  7340 	// Remove a reference on connection
       
  7341 	lm_connection_unref ( connection );	
       
  7342 	free_data ( connect_data );
       
  7343 	
       
  7344 	// Message sending passed
       
  7345 	iLog->Log ( _L ( "lm_remove_contactL passed" ) );
       
  7346 	
       
  7347 	return KErrNone;
       
  7348 }
       
  7349 //-----------------------------------------------------------------------------
       
  7350 // Ctstlm::lm_connection_send_receiveL
       
  7351 // Description  : Asynchronous call to send a message
       
  7352 // Arguements   :
       
  7353 //   connection	: an LmConnection used to send message
       
  7354 //   message    : LmMessage to send and receive
       
  7355 //   error      : location to store error, or NULL
       
  7356 // Returns      : Returns TRUE if no errors were detected while sending,
       
  7357 //                FALSE otherwise
       
  7358 //-----------------------------------------------------------------------------
       
  7359 // 
       
  7360 TInt Ctstlm::lm_connection_send_receiveL ( CStifItemParser& aItem )
       
  7361     {
       
  7362 	LmConnection *connection   = NULL;
       
  7363 	ConnectData  *connect_data = NULL;
       
  7364 	LmMessage    *message = NULL;
       
  7365 	LmMessage    *messagetoself = NULL;
       
  7366 	LmMessageHandler *handler = NULL;
       
  7367 	HandleData *handle_data = NULL;
       
  7368 	
       
  7369 	iLog->Log ( _L ( "In lm_connection_send" ) );
       
  7370 	
       
  7371 	// Read a data from the CFG file
       
  7372 	if ( read_data ( connect_data, aItem ) != RC_OK )
       
  7373 		{
       
  7374 		iLog->Log ( _L ( "read_data failed" ) );
       
  7375 		free_data ( connect_data );
       
  7376 		return KErrGeneral;
       
  7377 		}
       
  7378 	iLog->Log ( _L ( "after read_data" ) );
       
  7379 	
       
  7380 	// Open a new closed connection
       
  7381 	connection = lm_connection_new ( connect_data->server );
       
  7382 	iLog->Log ( _L ( "after lm_connection_new " ) );
       
  7383 	if ( !connection )
       
  7384 		{
       
  7385 		iLog->Log ( _L ( "lm_connection_new failed" ) );
       
  7386 		free_data ( connect_data );
       
  7387 		return KErrGeneral;
       
  7388 		}
       
  7389 	
       
  7390 	// Set the gtalk's SSL port
       
  7391 	lm_connection_set_port ( connection, GTALK_SSL_PORT );
       
  7392 	
       
  7393 	// Set the JID
       
  7394 	lm_connection_set_jid ( connection, connect_data->username );
       
  7395 	
       
  7396 	// Proxy settings for Emulator
       
  7397 #ifdef __WINSCW__
       
  7398 	SetProxy ( connection, connect_data->proxy_data );
       
  7399 #endif
       
  7400 	
       
  7401 	// Set the connection to use SSL
       
  7402 	SSLInit ( connection );
       
  7403 	
       
  7404 	GMainLoop	*main_loop = g_main_loop_new ( NULL, FALSE );
       
  7405 
       
  7406 	iLog->Log ( _L ( "before lm_connection_open" ) );
       
  7407 	
       
  7408 	if ( !lm_connection_open ( connection, ( LmResultFunction ) connection_open_cb,
       
  7409 	                           main_loop, NULL, NULL ) ) 
       
  7410 	    {
       
  7411 		iLog->Log ( _L ( "lm_connection_open failed" ));
       
  7412 		lm_connection_unref ( connection );
       
  7413 		g_main_loop_unref ( main_loop );
       
  7414 		free_data ( connect_data );		
       
  7415 		return KErrGeneral;
       
  7416 	    }
       
  7417 		
       
  7418 	iLog->Log ( _L ( "after lm_connection_open" ) );	
       
  7419 	g_main_loop_run ( main_loop );
       
  7420 	g_main_loop_unref ( main_loop );    
       
  7421 	
       
  7422 	main_loop = g_main_loop_new ( NULL, FALSE );	
       
  7423 	// Get the username from the JID
       
  7424 	gchar *username = get_user_name ( connect_data->username );
       
  7425 	
       
  7426 	// Authenticate with the server
       
  7427 	if ( !lm_connection_authenticate ( connection,
       
  7428                                      username,
       
  7429                                      connect_data->password,
       
  7430                                      connect_data->resource,
       
  7431                                       ( LmResultFunction ) connection_auth_cb,
       
  7432                                      main_loop,NULL,NULL ) )
       
  7433 	    {
       
  7434 		iLog->Log ( _L ( "lm_connection_authenticate failed" ) );
       
  7435 		lm_connection_close ( connection, NULL );
       
  7436 		lm_connection_unref ( connection );
       
  7437 		free_data ( connect_data );
       
  7438 		g_main_loop_unref ( main_loop );
       
  7439 		g_free ( username );
       
  7440 		return KErrGeneral;
       
  7441 	    }
       
  7442 
       
  7443 	g_main_loop_run ( main_loop );
       
  7444 	g_main_loop_unref ( main_loop );
       
  7445 	g_free ( username );
       
  7446 
       
  7447 	//------------------------------------------------------------------------
       
  7448 	//Send own presence
       
  7449 	message = lm_message_new_with_sub_type ( NULL,
       
  7450 	                                     LM_MESSAGE_TYPE_PRESENCE,
       
  7451 	                                     LM_MESSAGE_SUB_TYPE_AVAILABLE );
       
  7452 	
       
  7453     gboolean result = lm_connection_send ( connection, message, NULL );	
       
  7454    	
       
  7455 	//------------------------------------------------------------------------
       
  7456 	//
       
  7457 	// Register a handler to recieve msgs
       
  7458 	//
       
  7459 	main_loop = g_main_loop_new ( NULL, FALSE );
       
  7460 	handler = lm_message_handler_new ( 
       
  7461 	                     (LmHandleMessageFunction)handle_messages,
       
  7462 	                     main_loop,
       
  7463 	                     NULL );
       
  7464 	
       
  7465 	lm_connection_register_message_handler ( connection,
       
  7466 	                                         handler,
       
  7467 	                                         LM_MESSAGE_TYPE_MESSAGE,
       
  7468 	                                         LM_HANDLER_PRIORITY_FIRST );
       
  7469 	
       
  7470 	// Construct a message for sending to self
       
  7471 	messagetoself = lm_message_new ( connect_data->username,               
       
  7472 	                           LM_MESSAGE_TYPE_MESSAGE );
       
  7473 	lm_message_node_add_child ( message->node, "body", 
       
  7474 	                            connect_data->msg_data->message);
       
  7475 	
       
  7476 	// Send message to the server
       
  7477 	if ( !lm_connection_send ( connection, messagetoself, NULL ) )
       
  7478 	    {
       
  7479 		iLog->Log ( _L ( "lm_connection_send failed" ) );
       
  7480 		lm_connection_close ( connection, NULL );
       
  7481 		lm_connection_unref ( connection );
       
  7482 		lm_message_unref ( messagetoself );
       
  7483 		lm_message_unref ( message );
       
  7484 		g_main_loop_unref ( main_loop );
       
  7485 		lm_message_handler_unref(handler);
       
  7486 		free_data ( connect_data );		
       
  7487 		return KErrGeneral;
       
  7488 	    }	
       
  7489     // Wait for the message sent to self
       
  7490     g_main_loop_run ( main_loop );
       
  7491     g_main_loop_unref ( main_loop );
       
  7492     lm_message_handler_unref(handler);
       
  7493 	// Remove a reference on message
       
  7494 	lm_message_unref ( message );
       
  7495 	lm_message_unref ( messagetoself );
       
  7496 	
       
  7497 	//------------------------------------------------------------------------
       
  7498 	
       
  7499 	// Close the connection
       
  7500 	lm_connection_close ( connection, NULL );	
       
  7501 	// Remove a reference on connection
       
  7502 	lm_connection_unref ( connection );		
       
  7503 	free_data ( connect_data );
       
  7504 	
       
  7505 	// Message sending passed
       
  7506 	iLog->Log ( _L ( "lm_connection_send passed" ) );
       
  7507 	
       
  7508 	return KErrNone;
       
  7509 }
       
  7510 
       
  7511 
       
  7512 
       
  7513 //-----------------------------------------------------------------------------
       
  7514 // funnction_name	: connection_open_cancel_cb
       
  7515 // description		: callback function called by lm_connection_open
       
  7516 // Returns			: None
       
  7517 //-----------------------------------------------------------------------------
       
  7518 //
       
  7519 static void
       
  7520 connection_open_cancel_cb ( LmConnection * /*connection*/, 
       
  7521                      gboolean    success  /*success*/, 
       
  7522                      gpointer data )
       
  7523     {
       
  7524     
       
  7525     gboolean result = success ;
       
  7526     GMainLoop *main_loop = ( GMainLoop * ) data;
       
  7527 	if ( main_loop )
       
  7528 	    {
       
  7529 		g_main_loop_quit ( main_loop );	
       
  7530 	    }		
       
  7531     }
       
  7532 
       
  7533 //-----------------------------------------------------------------------------
       
  7534 // Ctstlm::lm_connection_cancel_openL
       
  7535 // Description  : Asynchronous call to send a message
       
  7536 // Arguements   :
       
  7537 //   connection	: an LmConnection used to send message
       
  7538 //   message    : LmMessage to send
       
  7539 //   error      : location to store error, or NULL
       
  7540 // Returns      : Returns TRUE if no errors were detected while sending,
       
  7541 //                FALSE otherwise
       
  7542 //-----------------------------------------------------------------------------
       
  7543 // 
       
  7544 TInt Ctstlm::lm_connection_cancel_openL ( CStifItemParser& aItem )
       
  7545  	{
       
  7546 		LmConnection *connection   = NULL;
       
  7547 	ConnectData  *connect_data = NULL;
       
  7548 	LmMessage    *message = NULL;
       
  7549 	
       
  7550 	iLog->Log ( _L ( "In lm_connection_cancel_openL" ) );
       
  7551 	
       
  7552 	// Read a data from the CFG file
       
  7553 	if ( read_data ( connect_data, aItem ) != RC_OK )
       
  7554 		{
       
  7555 		iLog->Log ( _L ( "read_data failed" ) );
       
  7556 		free_data ( connect_data );
       
  7557 		return KErrGeneral;
       
  7558 		}
       
  7559 	iLog->Log ( _L ( "after read_data" ) );
       
  7560 	
       
  7561 	// Open a new closed connection
       
  7562 	connection = lm_connection_new ( connect_data->server );
       
  7563 	iLog->Log ( _L ( "after lm_connection_new " ) );
       
  7564 	if ( !connection )
       
  7565 		{
       
  7566 		iLog->Log ( _L ( "lm_connection_new failed" ) );
       
  7567 		free_data ( connect_data );
       
  7568 		return KErrGeneral;
       
  7569 		}
       
  7570 	
       
  7571 	// Set the gtalk's SSL port
       
  7572 	lm_connection_set_port ( connection, GTALK_SSL_PORT );
       
  7573 	
       
  7574 	// Set the JID
       
  7575 	lm_connection_set_jid ( connection, connect_data->username );
       
  7576 	
       
  7577 	// Proxy settings for Emulator
       
  7578 #ifdef __WINSCW__
       
  7579 	SetProxy ( connection, connect_data->proxy_data );
       
  7580 #endif
       
  7581 	
       
  7582 	// Set the connection to use SSL
       
  7583 	SSLInit ( connection );
       
  7584 	
       
  7585 	GMainLoop	*main_loop = g_main_loop_new ( NULL, FALSE );
       
  7586 
       
  7587 	iLog->Log ( _L ( "before lm_connection_open" ) );
       
  7588 	
       
  7589 	if ( !lm_connection_open ( connection, ( LmResultFunction ) connection_open_cancel_cb,
       
  7590 	                           main_loop, NULL, NULL ) ) 
       
  7591 	    {
       
  7592 		iLog->Log ( _L ( "lm_connection_open failed" ));
       
  7593 		lm_connection_unref ( connection );
       
  7594 		g_main_loop_unref ( main_loop );
       
  7595 		free_data ( connect_data );		
       
  7596 		return KErrGeneral;
       
  7597 	    }
       
  7598 	
       
  7599 	if(!lm_connection_is_open(connection))
       
  7600 		{
       
  7601 		lm_connection_cancel_open(connection);
       
  7602 		//lm_connection_unref(connection);
       
  7603 		}
       
  7604 	
       
  7605 	//g_main_loop_run ( main_loop );
       
  7606 	g_main_loop_unref ( main_loop );    
       
  7607 
       
  7608 	// Close the connection
       
  7609 	lm_connection_close ( connection, NULL );
       
  7610 	
       
  7611 	// Remove a reference on connection
       
  7612 	lm_connection_unref ( connection );
       
  7613 	
       
  7614 	
       
  7615 	free_data ( connect_data );
       
  7616 	
       
  7617 	// Message sending passed
       
  7618 	iLog->Log ( _L ( "lm_connection_cancel_openL passed" ) );
       
  7619 	
       
  7620 	return KErrNone;
       
  7621 	}
       
  7622 
       
  7623 //--------------------------------------------------------------------------------
       
  7624 // function_name    : handle_get_privacy_lists
       
  7625 // description      : callback function to handle messages
       
  7626 // Returns          : LmHandlerResult
       
  7627 //--------------------------------------------------------------------------------
       
  7628 static LmHandlerResult
       
  7629 handle_get_privacy_lists ( LmMessageHandler* /*handler*/,
       
  7630                   LmConnection*     /*connection*/,
       
  7631                   LmMessage*        reply,
       
  7632                   gpointer          user_data )
       
  7633     {
       
  7634     GMainLoop *main_loop = ( GMainLoop * )user_data;	
       
  7635 	LmMessageSubType  type;
       
  7636 	LmMessageNode *q_node,*item_node;
       
  7637 	type = lm_message_get_sub_type (reply); 
       
  7638     /*
       
  7639     <iq type='result' id='getlist1' to='romeo@example.net/orchard'>
       
  7640 		<query xmlns='jabber:iq:privacy'>
       
  7641 		    <active name='private'/>
       
  7642 		    <default name='public'/>
       
  7643 		    <list name='public'/>
       
  7644 		    <list name='private'/>
       
  7645 			<list name='special'/>
       
  7646   		</query>
       
  7647 	</iq>
       
  7648     */ 	
       
  7649        	
       
  7650 	switch (type) 
       
  7651     	{
       
  7652     	case LM_MESSAGE_SUB_TYPE_RESULT:        		        		
       
  7653     			{
       
  7654 				const char* list_name1,*list_name2,*list_name3,*list_name4;
       
  7655     			q_node = lm_message_node_get_child (reply->node, "query");
       
  7656     			item_node = lm_message_node_get_child (q_node, "list");
       
  7657 				list_name1 = lm_message_node_get_attribute(item_node,"name");
       
  7658 				
       
  7659 				item_node = lm_message_node_get_child(q_node, "list");
       
  7660 				list_name2 = lm_message_node_get_attribute(item_node,"name");  
       
  7661 				
       
  7662 				item_node = lm_message_node_get_child (q_node, "active");
       
  7663 				if(item_node!=NULL)
       
  7664 					list_name3 = lm_message_node_get_attribute(item_node,"name");  
       
  7665 				
       
  7666 				item_node = lm_message_node_get_child (q_node, "default");
       
  7667 				if(item_node!=NULL)
       
  7668 					list_name4 = lm_message_node_get_attribute(item_node,"name");  
       
  7669 				
       
  7670     			break;
       
  7671     			}
       
  7672     	case LM_MESSAGE_SUB_TYPE_ERROR:
       
  7673     			{
       
  7674     			/*
       
  7675     			<error type='cancel'>
       
  7676     				<item-not-found	xmlns='urn:ietf:params:xml:ns:xmpp-stanzas'/>
       
  7677     				
       
  7678   				</error>
       
  7679   				OR
       
  7680   				<error type='modify'>
       
  7681 			    	<bad-request xmlns='urn:ietf:params:xml:ns:xmpp-stanzas'/>
       
  7682   				</error>
       
  7683   				*/
       
  7684 				const char* error_type;
       
  7685     			q_node = lm_message_node_get_child (reply->node, "query");
       
  7686     			item_node = lm_message_node_get_child (q_node, "error");
       
  7687 				error_type = lm_message_node_get_attribute(item_node,"type");
       
  7688     			break;
       
  7689     			}
       
  7690     //	default:
       
  7691     	//	g_assert_not_reached ();
       
  7692     	//	break;
       
  7693     	} 
       
  7694     
       
  7695    
       
  7696 
       
  7697 	if (!q_node) 
       
  7698     	{
       
  7699    		//return NULL;
       
  7700     	}
       
  7701     	
       
  7702    
       
  7703 	if ( main_loop )
       
  7704 		{
       
  7705 		g_main_loop_quit ( main_loop );
       
  7706 		}	
       
  7707 	
       
  7708 	return LM_HANDLER_RESULT_REMOVE_MESSAGE;
       
  7709     }   
       
  7710 //-----------------------------------------------------------------------------
       
  7711 // Ctstlm::lm_connection_get_privacy_listsL
       
  7712 // Description  : Asynchronous call to send a message
       
  7713 // Arguements   :
       
  7714 //   connection	: an LmConnection used to send message
       
  7715 //   message    : LmMessage to send
       
  7716 //   error      : location to store error, or NULL
       
  7717 // Returns      : Returns TRUE if no errors were detected while sending,
       
  7718 //                FALSE otherwise
       
  7719 //-----------------------------------------------------------------------------
       
  7720 // 
       
  7721 TInt Ctstlm::lm_connection_get_privacy_listsL ( CStifItemParser& aItem )
       
  7722     {
       
  7723 	LmConnection *connection   = NULL;
       
  7724 	ConnectData  *connect_data = NULL;
       
  7725 	LmMessage    *message = NULL;
       
  7726 	LmMessageNode* q_node = NULL;
       
  7727 	LmMessageHandler *handler = NULL;
       
  7728 	
       
  7729 	iLog->Log ( _L ( "In lm_connection_get_privacy_listsL" ) );
       
  7730 	
       
  7731 	// Read a data from the CFG file
       
  7732 	if ( read_data ( connect_data, aItem ) != RC_OK )
       
  7733 		{
       
  7734 		iLog->Log ( _L ( "read_data failed" ) );
       
  7735 		free_data ( connect_data );
       
  7736 		return KErrGeneral;
       
  7737 		}
       
  7738 	iLog->Log ( _L ( "after read_data" ) );
       
  7739 	
       
  7740 	// Open a new closed connection
       
  7741 	connection = lm_connection_new ( connect_data->server );
       
  7742 	iLog->Log ( _L ( "after lm_connection_new " ) );
       
  7743 	if ( !connection )
       
  7744 		{
       
  7745 		iLog->Log ( _L ( "lm_connection_new failed" ) );
       
  7746 		free_data ( connect_data );
       
  7747 		return KErrGeneral;
       
  7748 		}
       
  7749 	
       
  7750 	// Set the gtalk's SSL port
       
  7751 	lm_connection_set_port ( connection, GTALK_SSL_PORT );
       
  7752 	
       
  7753 	// Set the JID
       
  7754 	lm_connection_set_jid ( connection, connect_data->username );
       
  7755 	
       
  7756 	// Proxy settings for Emulator
       
  7757 #ifdef __WINSCW__
       
  7758 	SetProxy ( connection, connect_data->proxy_data );
       
  7759 #endif
       
  7760 	
       
  7761 	// Set the connection to use SSL
       
  7762 	SSLInit ( connection );
       
  7763 	
       
  7764 	GMainLoop	*main_loop = g_main_loop_new ( NULL, FALSE );
       
  7765 
       
  7766 	iLog->Log ( _L ( "before lm_connection_open" ) );
       
  7767 	
       
  7768 	if ( !lm_connection_open ( connection, ( LmResultFunction ) connection_open_cb,
       
  7769 	                           main_loop, NULL, NULL ) ) 
       
  7770 	    {
       
  7771 		iLog->Log ( _L ( "lm_connection_open failed" ));
       
  7772 		lm_connection_unref ( connection );
       
  7773 		g_main_loop_unref ( main_loop );
       
  7774 		free_data ( connect_data );		
       
  7775 		return KErrGeneral;
       
  7776 	    }
       
  7777 		
       
  7778 	iLog->Log ( _L ( "after lm_connection_open" ) );
       
  7779 	g_main_loop_run ( main_loop );
       
  7780 	g_main_loop_unref ( main_loop );    
       
  7781 
       
  7782 	main_loop = g_main_loop_new ( NULL, FALSE );
       
  7783 	// Get the username from the JID
       
  7784 	gchar *username = get_user_name ( connect_data->username );
       
  7785 	
       
  7786 	// Authenticate with the server
       
  7787 	if ( !lm_connection_authenticate ( connection,
       
  7788                                      username,
       
  7789                                      connect_data->password,
       
  7790                                      connect_data->resource,
       
  7791                                       ( LmResultFunction ) connection_auth_cb,
       
  7792                                      main_loop,NULL,NULL ) )
       
  7793 	    {
       
  7794 		iLog->Log ( _L ( "lm_connection_authenticate failed" ) );
       
  7795 		lm_connection_close ( connection, NULL );
       
  7796 		lm_connection_unref ( connection );
       
  7797 		free_data ( connect_data );
       
  7798 		g_main_loop_unref ( main_loop );
       
  7799 		g_free ( username );
       
  7800 		return KErrGeneral;
       
  7801 	    }	
       
  7802 	g_main_loop_run ( main_loop );
       
  7803 	g_main_loop_unref ( main_loop );
       
  7804 	g_free ( username );
       
  7805 	
       
  7806 	// Construct a message with type=LM_MESSAGE_TYPE_IQ
       
  7807 	main_loop = g_main_loop_new ( NULL, FALSE );
       
  7808 	message = lm_message_new_with_sub_type ( NULL,
       
  7809                                          LM_MESSAGE_TYPE_IQ,
       
  7810                                          LM_MESSAGE_SUB_TYPE_GET );
       
  7811     q_node = lm_message_node_add_child ( message->node, "query", NULL );
       
  7812     lm_message_node_set_attribute ( q_node, "xmlns", "jabber:iq:privacy" );
       
  7813     // Send message to the server
       
  7814 	handler = lm_message_handler_new ( handle_get_privacy_lists, main_loop, NULL );	
       
  7815 	if ( !lm_connection_send_with_reply ( connection, message, handler, NULL ) ) 
       
  7816 	    {
       
  7817 		iLog->Log ( _L ( "lm_connection_send_with_reply in lm_add_contactL failed" ) );
       
  7818 		lm_connection_close ( connection, NULL );
       
  7819 		lm_connection_unref ( connection );
       
  7820 		lm_message_unref ( message );
       
  7821 		lm_message_handler_unref(handler);
       
  7822 		free_data ( connect_data );
       
  7823 		g_main_loop_unref ( main_loop );
       
  7824 		return KErrGeneral;
       
  7825 	    }
       
  7826 	g_main_loop_run ( main_loop );
       
  7827 	g_main_loop_unref ( main_loop );
       
  7828 	lm_message_unref ( message );    
       
  7829 	lm_message_handler_unref(handler);
       
  7830 
       
  7831    
       
  7832 	// Close the connection
       
  7833 	lm_connection_close ( connection, NULL );
       
  7834 	
       
  7835 	// Remove a reference on connection
       
  7836 	lm_connection_unref ( connection );
       
  7837 	free_data ( connect_data );
       
  7838 	
       
  7839 	// Message sending passed
       
  7840 	iLog->Log ( _L ( "lm_connection_get_privacy_listsL passed" ) );
       
  7841 	
       
  7842 	return KErrNone;
       
  7843 }
       
  7844 
       
  7845 
       
  7846 //--------------------------------------------------------------------------------
       
  7847 // function_name    : handle_set_privacy_lists
       
  7848 // description      : callback function to handle messages
       
  7849 // Returns          : LmHandlerResult
       
  7850 //--------------------------------------------------------------------------------
       
  7851 static LmHandlerResult
       
  7852 handle_set_privacy_lists ( LmMessageHandler*/* handler*/,
       
  7853                   LmConnection*     /*connection*/,
       
  7854                   LmMessage*        reply,
       
  7855                   gpointer          user_data )
       
  7856     {
       
  7857     GMainLoop *main_loop = ( GMainLoop * )user_data;	
       
  7858 	LmMessageSubType  type;
       
  7859 	LmMessageNode *q_node = NULL;
       
  7860 	LmMessageNode *item_node = NULL;
       
  7861 	type = lm_message_get_sub_type (reply); 
       
  7862     /*
       
  7863     <iq type='result' id='edit1' to='romeo@example.net/orchard'/>
       
  7864     */ 	
       
  7865        	
       
  7866 	switch (type) 
       
  7867     	{
       
  7868     	case LM_MESSAGE_SUB_TYPE_RESULT:        		        		
       
  7869     		{
       
  7870     		const char* reply_string;
       
  7871     		reply_string = lm_message_node_get_attribute(reply->node,"id");  
       
  7872 			break;
       
  7873     		}
       
  7874     	case LM_MESSAGE_SUB_TYPE_ERROR:          	          		
       
  7875     		{
       
  7876     		/*
       
  7877 		    <iq to='romeo@example.net/orchard' type='error' id='getlist6'>
       
  7878 			    <error type='modify'>
       
  7879 			    	<bad-request xmlns='urn:ietf:params:xml:ns:xmpp-stanzas'/>
       
  7880 			    </error>
       
  7881 		    </iq>
       
  7882 			*/ 	
       
  7883     		if (q_node) 
       
  7884 		    	{
       
  7885 		    	LmMessageNode* error_node = NULL;
       
  7886 		    	error_node = lm_message_node_get_child(reply->node,"error");
       
  7887 	    		const char* error_code;
       
  7888 	    		error_code = lm_message_node_get_attribute(error_node,"code");  
       
  7889 				const char* error_type;
       
  7890 	    		error_type = lm_message_node_get_attribute(error_node,"type");  
       
  7891 				item_node = lm_message_node_get_child (q_node, "feature-not-implemented");
       
  7892 		    	}
       
  7893 			break;
       
  7894 			}
       
  7895     //	default:
       
  7896     	//	g_assert_not_reached ();
       
  7897     	//	break;
       
  7898     	} 
       
  7899     	
       
  7900     
       
  7901 	if ( main_loop )
       
  7902 		{
       
  7903 		g_main_loop_quit ( main_loop );
       
  7904 		}	
       
  7905 	
       
  7906 	return LM_HANDLER_RESULT_REMOVE_MESSAGE;
       
  7907     }   
       
  7908 //-----------------------------------------------------------------------------
       
  7909 // Ctstlm::lm_connection_set_privacy_listsL
       
  7910 // Description  : Asynchronous call to send a message
       
  7911 // Arguements   :
       
  7912 //   connection	: an LmConnection used to send message
       
  7913 //   message    : LmMessage to send
       
  7914 //   error      : location to store error, or NULL
       
  7915 // Returns      : Returns TRUE if no errors were detected while sending,
       
  7916 //                FALSE otherwise
       
  7917 //-----------------------------------------------------------------------------
       
  7918 // 
       
  7919 TInt Ctstlm::lm_connection_set_privacy_listsL ( CStifItemParser& aItem )
       
  7920     {
       
  7921 	LmConnection *connection   = NULL;
       
  7922 	ConnectData  *connect_data = NULL;
       
  7923 	LmMessage    *message = NULL;
       
  7924 	LmMessageNode* q_node, *item_node1, *item_node2 = NULL;
       
  7925 	LmMessageHandler *handler = NULL;
       
  7926 	
       
  7927 	iLog->Log ( _L ( "In lm_connection_set_privacy_listsL" ) );
       
  7928 	
       
  7929 	// Read a data from the CFG file
       
  7930 	if ( read_data ( connect_data, aItem ) != RC_OK )
       
  7931 		{
       
  7932 		iLog->Log ( _L ( "read_data failed" ) );
       
  7933 		free_data ( connect_data );
       
  7934 		return KErrGeneral;
       
  7935 		}
       
  7936 	iLog->Log ( _L ( "after read_data" ) );
       
  7937 	
       
  7938 	// Open a new closed connection
       
  7939 	connection = lm_connection_new ( connect_data->server );
       
  7940 	iLog->Log ( _L ( "after lm_connection_new " ) );
       
  7941 	if ( !connection )
       
  7942 		{
       
  7943 		iLog->Log ( _L ( "lm_connection_new failed" ) );
       
  7944 		free_data ( connect_data );
       
  7945 		return KErrGeneral;
       
  7946 		}
       
  7947 	
       
  7948 	// Set the gtalk's SSL port
       
  7949 	lm_connection_set_port ( connection, GTALK_SSL_PORT );
       
  7950 	
       
  7951 	// Set the JID
       
  7952 	lm_connection_set_jid ( connection, connect_data->username );
       
  7953 	
       
  7954 	// Proxy settings for Emulator
       
  7955 #ifdef __WINSCW__
       
  7956 	SetProxy ( connection, connect_data->proxy_data );
       
  7957 #endif
       
  7958 	
       
  7959 	// Set the connection to use SSL
       
  7960 	SSLInit ( connection );
       
  7961 	
       
  7962 	GMainLoop	*main_loop = g_main_loop_new ( NULL, FALSE );
       
  7963 	iLog->Log ( _L ( "before lm_connection_open" ) );
       
  7964 	
       
  7965 	if ( !lm_connection_open ( connection, ( LmResultFunction ) connection_open_cb,
       
  7966 	                           main_loop, NULL, NULL ) ) 
       
  7967 	    {
       
  7968 		iLog->Log ( _L ( "lm_connection_open failed" ));
       
  7969 		lm_connection_unref ( connection );
       
  7970 		g_main_loop_unref ( main_loop );
       
  7971 		free_data ( connect_data );		
       
  7972 		return KErrGeneral;
       
  7973 	    }
       
  7974 		
       
  7975 	iLog->Log ( _L ( "after lm_connection_open" ) );
       
  7976 	
       
  7977 	g_main_loop_run ( main_loop );
       
  7978 	g_main_loop_unref ( main_loop ); 
       
  7979 	
       
  7980 	main_loop = g_main_loop_new ( NULL, FALSE );	
       
  7981 	// Get the username from the JID
       
  7982 	gchar *username = get_user_name ( connect_data->username );
       
  7983 	
       
  7984 	// Authenticate with the server
       
  7985 	if ( !lm_connection_authenticate ( connection,
       
  7986                                      username,
       
  7987                                      connect_data->password,
       
  7988                                      connect_data->resource,
       
  7989                                       ( LmResultFunction ) connection_auth_cb,
       
  7990                                      main_loop,NULL,NULL ) )
       
  7991 	    {
       
  7992 		iLog->Log ( _L ( "lm_connection_authenticate failed" ) );
       
  7993 		lm_connection_close ( connection, NULL );
       
  7994 		lm_connection_unref ( connection );
       
  7995 		free_data ( connect_data );
       
  7996 		g_main_loop_unref ( main_loop );
       
  7997 		g_free ( username );
       
  7998 		return KErrGeneral;
       
  7999 	    }
       
  8000 
       
  8001 	g_main_loop_run ( main_loop );
       
  8002 	g_main_loop_unref ( main_loop );
       
  8003 	g_free ( username );
       
  8004 	
       
  8005 	// Construct a message with type=LM_MESSAGE_TYPE_IQ
       
  8006 	/*
       
  8007 	<iq from='romeo@example.net/orchard' type='set' id='edit1'>
       
  8008 		<query xmlns='jabber:iq:privacy'>
       
  8009 		    <list name='public'>
       
  8010 		      <item type='jid'
       
  8011 		            value='tybalt@example.com'
       
  8012 		            action='deny'
       
  8013 		            order='3'/>
       
  8014 		      <item type='jid'
       
  8015 		            value='paris@example.org'
       
  8016 		            action='deny'
       
  8017 		            order='5'/>
       
  8018 		      <item action='allow' order='68'/>
       
  8019 		    </list>
       
  8020 		    <list name='active'>
       
  8021 		      <item type='jid'
       
  8022 		            value='tybalt@example.com'
       
  8023 		            action='deny'
       
  8024 		            order='3'/>
       
  8025 		      <item type='jid'
       
  8026 		            value='paris@example.org'
       
  8027 		            action='deny'
       
  8028 		            order='5'/>
       
  8029 		      <item action='allow' order='68'/>
       
  8030 		    </list>
       
  8031   		</query>
       
  8032 	</iq>
       
  8033 	*/
       
  8034 	main_loop = g_main_loop_new ( NULL, FALSE );
       
  8035 	message = lm_message_new_with_sub_type ( NULL,
       
  8036                                          LM_MESSAGE_TYPE_IQ,
       
  8037                                          LM_MESSAGE_SUB_TYPE_SET );
       
  8038     q_node = lm_message_node_add_child ( message->node, "query", NULL );
       
  8039     lm_message_node_set_attribute ( q_node, "xmlns", "jabber:iq:privacy" );
       
  8040     item_node1 = lm_message_node_add_child ( q_node, "list", NULL );
       
  8041     lm_message_node_set_attribute ( item_node1, "name", "public" );
       
  8042     item_node2 = lm_message_node_add_child ( item_node1, "item", NULL );
       
  8043     lm_message_node_set_attribute ( item_node2, "type", "jid" );
       
  8044     lm_message_node_set_attribute ( item_node2, "value", "rakesh_harsh@chat.gizmoproject.com" );
       
  8045     lm_message_node_set_attribute ( item_node2, "action", "deny" );
       
  8046     lm_message_node_set_attribute ( item_node2, "order", "3" );
       
  8047     
       
  8048     item_node1 = lm_message_node_add_child ( q_node, "list", NULL );
       
  8049     lm_message_node_set_attribute ( item_node1, "name", "active" );
       
  8050     item_node2 = lm_message_node_add_child ( item_node1, "item", NULL );
       
  8051     lm_message_node_set_attribute ( item_node2, "type", "jid" );
       
  8052     lm_message_node_set_attribute ( item_node2, "value", "rakesh_harsh@chat.gizmoproject.com" );
       
  8053     lm_message_node_set_attribute ( item_node2, "action", "deny" );
       
  8054     lm_message_node_set_attribute ( item_node2, "order", "4" );
       
  8055     
       
  8056     // Send message to the server
       
  8057 	handler = lm_message_handler_new ( handle_set_privacy_lists, main_loop, NULL );	
       
  8058 	if ( !lm_connection_send_with_reply ( connection, message, handler, NULL ) ) 
       
  8059 	    {
       
  8060 		iLog->Log ( _L ( "lm_connection_send_with_reply in lm_add_contactL failed" ) );
       
  8061 		lm_connection_close ( connection, NULL );
       
  8062 		lm_connection_unref ( connection );
       
  8063 		lm_message_unref ( message );
       
  8064 		lm_message_handler_unref(handler);
       
  8065 		free_data ( connect_data );
       
  8066 		g_main_loop_unref ( main_loop );
       
  8067 		return KErrGeneral;
       
  8068 	    }
       
  8069 	g_main_loop_run ( main_loop );
       
  8070 	g_main_loop_unref ( main_loop );
       
  8071 	lm_message_unref ( message );    
       
  8072 	lm_message_handler_unref(handler);
       
  8073 
       
  8074    
       
  8075 	// Close the connection
       
  8076 	lm_connection_close ( connection, NULL );
       
  8077 	
       
  8078 	// Remove a reference on connection
       
  8079 	lm_connection_unref ( connection );
       
  8080 	
       
  8081 	free_data ( connect_data );
       
  8082 	
       
  8083 	// Message sending passed
       
  8084 	iLog->Log ( _L ( "lm_connection_set_privacy_listsL passed" ) );
       
  8085 	
       
  8086 	return KErrNone;
       
  8087 }
       
  8088 
       
  8089 //--------------------------------------------------------------------------------
       
  8090 // function_name    : handle_send_image_cb
       
  8091 // description      : callback function to handle messages
       
  8092 // Returns          : LmHandlerResult
       
  8093 //--------------------------------------------------------------------------------
       
  8094 static LmHandlerResult
       
  8095 handle_send_image_cb ( LmMessageHandler* /*handler*/,
       
  8096                   LmConnection*     /*connection*/,
       
  8097                   LmMessage*        reply,
       
  8098                   gpointer          user_data )
       
  8099     {
       
  8100     SendStreamData *stream_data = ( SendStreamData * )user_data;	
       
  8101 	LmMessageSubType  type;
       
  8102 	LmMessageNode *q_node,*item_node;
       
  8103 	type = lm_message_get_sub_type (reply); 
       
  8104         	
       
  8105 	switch (type) 
       
  8106     	{
       
  8107     	case LM_MESSAGE_SUB_TYPE_RESULT:        		        		
       
  8108 			{
       
  8109 			const char* reply_string;
       
  8110 			reply_string = lm_message_node_get_attribute(reply->node,"id");  
       
  8111 			break;
       
  8112 			}
       
  8113     	case LM_MESSAGE_SUB_TYPE_ERROR:          	          		
       
  8114     		{
       
  8115     		/*<message from='juliet@capulet.com/balcony' to='romeo@montague.net/orchard' 
       
  8116     						id='msg1' type='error'>
       
  8117     			...
       
  8118 			    <error code='504' type='cancel'>
       
  8119 			         <remote-server-timeout xmlns='urn:ietf:params:xml:ns:xmpp-stanzas'/>
       
  8120 			    </error>
       
  8121 			</message>*/
       
  8122 
       
  8123     		const char* reply_string;
       
  8124     		reply_string = lm_message_node_get_attribute(reply->node,"id");  
       
  8125 			q_node = lm_message_node_get_child (reply->node, "error");
       
  8126 			if (q_node) 
       
  8127 		    	{
       
  8128 		   		const char* error_code;
       
  8129 		   		error_code = lm_message_node_get_attribute(q_node,"code");  
       
  8130 		   		item_node = lm_message_node_get_child (q_node, "feature-not-implemented");
       
  8131 		   		if(item_node==NULL)
       
  8132 		   			{
       
  8133 		   			item_node = lm_message_node_get_child (q_node, "remote-server-timeout");
       
  8134 		   			}
       
  8135 		    	}
       
  8136 		    	
       
  8137 			break;
       
  8138     		}
       
  8139     //	default:
       
  8140     	//	g_assert_not_reached ();
       
  8141     	//	break;
       
  8142     	} 
       
  8143     	
       
  8144     
       
  8145 	if ( stream_data->main_loop )
       
  8146 		{
       
  8147 		g_main_loop_quit ( stream_data->main_loop );
       
  8148 		}	
       
  8149 	lm_message_unref(stream_data->message);
       
  8150 	lm_message_handler_unref(stream_data->handler);
       
  8151 	return LM_HANDLER_RESULT_REMOVE_MESSAGE;
       
  8152     }
       
  8153 //--------------------------------------------------------------------------------
       
  8154 // function_name    : handle_send_image_stream_msg_open_cb
       
  8155 // description      : callback function to handle messages
       
  8156 // Returns          : LmHandlerResult
       
  8157 //--------------------------------------------------------------------------------
       
  8158 static LmHandlerResult
       
  8159 handle_send_image_stream_msg_open_cb ( LmMessageHandler* /*handler*/,
       
  8160                   LmConnection*     connection,
       
  8161                   LmMessage*        reply,
       
  8162                   gpointer          user_data )
       
  8163     {
       
  8164     SendStreamData *stream_data = ( SendStreamData * )user_data;	
       
  8165     LmMessageSubType  type;
       
  8166 	LmMessageNode *q_node = NULL;
       
  8167 	LmMessageNode *item_node1 = NULL;
       
  8168 	LmMessageNode *item_node2 = NULL;
       
  8169 	LmMessageNode* item_node = NULL;
       
  8170 	LmMessage * message = NULL;
       
  8171 	LmMessageHandler* handler = NULL;
       
  8172 	type = lm_message_get_sub_type (reply); 
       
  8173     /*
       
  8174     //success response
       
  8175     <iq type='result' from='juliet@capulet.com/balcony' to='romeo@montague.net/orchard'
       
  8176     	id='inband_1'/>
       
  8177     	
       
  8178     //error response
       
  8179     <iq type='error' from='juliet@capulet.com/balcony' to='romeo@montague.net/orchard'
       
  8180     	id='inband_1'/>
       
  8181   			<error code='501' type='cancel'>
       
  8182     			<feature-not-implemented xmlns='urn:ietf:params:xml:ns:xmpp-stanzas'/>
       
  8183   			</error>
       
  8184 	</iq>
       
  8185 	*/ 	
       
  8186    
       
  8187 	switch (type) 
       
  8188     	{
       
  8189     	case LM_MESSAGE_SUB_TYPE_RESULT:
       
  8190     		{
       
  8191     		const char* reply_string;
       
  8192     		reply_string = lm_message_node_get_attribute(q_node,"id");  
       
  8193     			
       
  8194 			/****************************************************/
       
  8195 			// send bytes in message
       
  8196 			/*
       
  8197 			<message from='romeo@montague.net/orchard' to='juliet@capulet.com/balcony' id='msg1'>
       
  8198 				  <data xmlns='http://jabber.org/protocol/ibb' sid='mySID' seq='0'>
       
  8199 				    qANQR1DBwU4DX7jmYZnncmUQB/9KuKBddzQH+tZ1ZywKK0yHKnq57kWq+RFtQdCJ
       
  8200 				    WpdWpR0uQsuJe7+vh3NWn59/gTc5MDlX8dS9p0ovStmNcyLhxVgmqS8ZKhsblVeu
       
  8201 				    IpQ0JgavABqibJolc3BKrVtVV1igKiX/N7Pi8RtY1K18toaMDhdEfhBRzO/XB0+P
       
  8202 				    AQhYlRjNacGcslkhXqNjK5Va4tuOAPy2n1Q8UUrHbUd0g+xJ9Bm0G0LZXyvCWyKH
       
  8203 				    kuNEHFQiLuCY6Iv0myq6iX6tjuHehZlFSh80b5BVV9tNLwNR5Eqz1klxMhoghJOA
       
  8204 				  </data>
       
  8205 				  <amp xmlns='http://jabber.org/protocol/amp'>
       
  8206 				    <rule condition='deliver' value='stored' action='error'/>
       
  8207 				    <rule condition='match-resource' value='exact' action='error'/>
       
  8208 				  </amp>
       
  8209 			</message>
       
  8210 			*/
       
  8211 			message = lm_message_new ( NULL, LM_MESSAGE_TYPE_MESSAGE );
       
  8212 			lm_message_node_set_attribute ( message->node, "to", "donna.prima@gmail.com" );
       
  8213 		    q_node = lm_message_node_add_child ( message->node, "data", 
       
  8214 		    		"qANQR1DBwU4DX7jmYZnncmUQB/9KuKBddzQH+tZ1ZywKK0yHKnq57kWq+RFtQdCJ \
       
  8215 				    WpdWpR0uQsuJe7+vh3NWn59/gTc5MDlX8dS9p0ovStmNcyLhxVgmqS8ZKhsblVeu \
       
  8216 				    IpQ0JgavABqibJolc3BKrVtVV1igKiX/N7Pi8RtY1K18toaMDhdEfhBRzO/XB0+P \
       
  8217 				    AQhYlRjNacGcslkhXqNjK5Va4tuOAPy2n1Q8UUrHbUd0g+xJ9Bm0G0LZXyvCWyKH \
       
  8218 				    kuNEHFQiLuCY6Iv0myq6iX6tjuHehZlFSh80b5BVV9tNLwNR5Eqz1klxMhoghJOA" );
       
  8219 		    lm_message_node_set_attribute ( q_node, "xmlns", "http://jabber.org/protocol/ibb" );
       
  8220 		    lm_message_node_set_attribute ( q_node, "sid", "mySID" );
       
  8221 		    lm_message_node_set_attribute ( q_node, "seq", "0" );
       
  8222 		    
       
  8223 		    q_node = lm_message_node_add_child ( message->node, "amp", NULL );
       
  8224 		    lm_message_node_set_attribute ( q_node, "xmlns", "http://jabber.org/protocol/amp" );
       
  8225 		    item_node1 = lm_message_node_add_child ( q_node, "rule", NULL );
       
  8226 		    lm_message_node_set_attribute ( item_node1, "condition", "deliver" );
       
  8227 		    lm_message_node_set_attribute ( item_node1, "value", "stored" );
       
  8228 		    lm_message_node_set_attribute ( item_node1, "action", "error" );
       
  8229 		    item_node2 = lm_message_node_add_child ( q_node, "rule", NULL );
       
  8230 		    lm_message_node_set_attribute ( item_node1, "condition", "match-resource" );
       
  8231 		    lm_message_node_set_attribute ( item_node1, "value", "exact" );
       
  8232 		    lm_message_node_set_attribute ( item_node1, "action", "error" );
       
  8233 		    
       
  8234 		    stream_data->message = message;
       
  8235 		    
       
  8236 		    // Send message to the server
       
  8237 			handler = lm_message_handler_new ( handle_send_image_cb, stream_data, NULL );	
       
  8238 			
       
  8239 			stream_data->handler = handler;
       
  8240 			if ( !lm_connection_send_with_reply ( connection, message, handler, NULL ) ) 
       
  8241 			    {
       
  8242 				//lm_connection_close ( connection, NULL );
       
  8243 				//lm_connection_unref ( connection );
       
  8244 				lm_message_unref ( stream_data->message );
       
  8245 				lm_message_handler_unref(stream_data->handler);
       
  8246 				if ( stream_data->main_loop)
       
  8247 					{
       
  8248 					g_main_loop_quit ( stream_data->main_loop );
       
  8249 					}
       
  8250 				return LM_HANDLER_RESULT_REMOVE_MESSAGE;
       
  8251 			    }
       
  8252 			/****************************************************/
       
  8253 			break;
       
  8254     		}        		        		
       
  8255     		
       
  8256     	case LM_MESSAGE_SUB_TYPE_ERROR:          	          		
       
  8257     		{
       
  8258     		const char* reply_string;
       
  8259     		reply_string = lm_message_node_get_attribute(reply->node,"id");  
       
  8260 			q_node = lm_message_node_get_child (reply->node, "error");
       
  8261 			if (q_node) 
       
  8262 		    	{
       
  8263 		   		const char* error_code;
       
  8264 		   		error_code = lm_message_node_get_attribute(q_node,"code");  
       
  8265 		   		item_node = lm_message_node_get_child (q_node, "feature-not-implemented");
       
  8266 		    	}
       
  8267 		    if ( stream_data->main_loop)
       
  8268 				{
       
  8269 				g_main_loop_quit ( stream_data->main_loop );
       
  8270 				}
       
  8271 			break;
       
  8272     		}
       
  8273     //	default:
       
  8274     	//	g_assert_not_reached ();
       
  8275     	//	break;
       
  8276     	} 
       
  8277     	
       
  8278   
       
  8279 		
       
  8280 	
       
  8281 	return LM_HANDLER_RESULT_REMOVE_MESSAGE;
       
  8282     }  
       
  8283    
       
  8284 //-----------------------------------------------------------------------------
       
  8285 // Ctstlm::lm_connection_send_image_bytestream_msgL
       
  8286 // Description  : Asynchronous call to send a message
       
  8287 // Arguements   :
       
  8288 //   connection	: an LmConnection used to send message
       
  8289 //   message    : LmMessage to send
       
  8290 //   error      : location to store error, or NULL
       
  8291 // Returns      : Returns TRUE if no errors were detected while sending,
       
  8292 //                FALSE otherwise
       
  8293 //-----------------------------------------------------------------------------
       
  8294 // 
       
  8295 TInt Ctstlm::lm_connection_send_image_bytestream_msgL ( CStifItemParser& aItem )
       
  8296     {
       
  8297 	LmConnection *connection   = NULL;
       
  8298 	ConnectData  *connect_data = NULL;
       
  8299 	LmMessage    *message = NULL;
       
  8300 	LmMessageNode* q_node, *item_node1, *item_node2 = NULL;
       
  8301 	LmMessageHandler *handler = NULL;
       
  8302 	SendStreamData* stream_data = NULL;
       
  8303 	iLog->Log ( _L ( "In lm_connection_send_imageL" ) );
       
  8304 	
       
  8305 	stream_data = g_new0 ( SendStreamData, 1 );
       
  8306 	if (! stream_data )
       
  8307 		{
       
  8308 		return KErrGeneral;
       
  8309 		}			
       
  8310 	if ( read_data ( stream_data->connect_data, aItem ) != RC_OK )
       
  8311 		{
       
  8312 		iLog->Log ( _L ( "read_data failed" ) );		
       
  8313 		free_data ( stream_data->connect_data );		
       
  8314 		g_free ( stream_data );
       
  8315 		return KErrGeneral;
       
  8316 		}
       
  8317 	stream_data->main_loop    = g_main_loop_new ( NULL, FALSE );	
       
  8318 	stream_data->rCode        = RC_ERROR;
       
  8319 	
       
  8320 	iLog->Log ( _L ( "after read_data" ) );
       
  8321 	
       
  8322 	// Open a new closed connection
       
  8323 	connection = lm_connection_new ( stream_data->connect_data->server );
       
  8324 	iLog->Log ( _L ( "after lm_connection_new " ) );
       
  8325 	if ( !connection )
       
  8326 		{
       
  8327 		iLog->Log ( _L ( "lm_connection_new failed" ) );
       
  8328 		free_data ( stream_data->connect_data );
       
  8329 		g_free(stream_data);
       
  8330 		return KErrGeneral;
       
  8331 		}
       
  8332 	
       
  8333 	// Set the gtalk's SSL port
       
  8334 	lm_connection_set_port ( connection, GTALK_SSL_PORT );
       
  8335 	
       
  8336 	// Set the JID
       
  8337 	lm_connection_set_jid ( connection, stream_data->connect_data->username );
       
  8338 	
       
  8339 	// Proxy settings for Emulator
       
  8340 #ifdef __WINSCW__
       
  8341 	SetProxy ( connection, stream_data->connect_data->proxy_data );
       
  8342 #endif
       
  8343 	
       
  8344 	// Set the connection to use SSL
       
  8345 	SSLInit ( connection );
       
  8346 	
       
  8347 	stream_data->main_loop = g_main_loop_new ( NULL, FALSE );
       
  8348 
       
  8349 	iLog->Log ( _L ( "before lm_connection_open" ) );
       
  8350 	
       
  8351 	if ( !lm_connection_open ( connection, ( LmResultFunction ) connection_open_cb,
       
  8352 	                           stream_data->main_loop, NULL, NULL ) ) 
       
  8353 	    {
       
  8354 		iLog->Log ( _L ( "lm_connection_open failed" ));
       
  8355 		lm_connection_unref ( connection );
       
  8356 		g_main_loop_unref ( stream_data->main_loop );
       
  8357 		free_data ( stream_data->connect_data );
       
  8358 		g_free(stream_data);		
       
  8359 		return KErrGeneral;
       
  8360 	    }
       
  8361 		
       
  8362 	iLog->Log ( _L ( "after lm_connection_open" ) );	
       
  8363 	g_main_loop_run ( stream_data->main_loop );
       
  8364 	g_main_loop_unref ( stream_data->main_loop );    
       
  8365 
       
  8366 	
       
  8367 	stream_data->main_loop = g_main_loop_new ( NULL, FALSE );
       
  8368 	
       
  8369 	// Get the username from the JID
       
  8370 	gchar *username = get_user_name ( stream_data->connect_data->username );
       
  8371 	
       
  8372 	// Authenticate with the server
       
  8373 	if ( !lm_connection_authenticate ( connection,
       
  8374                                      username,
       
  8375                                      stream_data->connect_data->password,
       
  8376                                      stream_data->connect_data->resource,
       
  8377                                       ( LmResultFunction ) connection_auth_cb,
       
  8378                                      stream_data->main_loop,NULL,NULL ) )
       
  8379 	    {
       
  8380 		iLog->Log ( _L ( "lm_connection_authenticate failed" ) );
       
  8381 		lm_connection_close ( connection, NULL );
       
  8382 		lm_connection_unref ( connection );
       
  8383 		free_data ( stream_data->connect_data );
       
  8384 		g_main_loop_unref ( stream_data->main_loop );
       
  8385 		g_free(stream_data);
       
  8386 		g_free ( username );
       
  8387 		return KErrGeneral;
       
  8388 	    }
       
  8389 
       
  8390 	g_main_loop_run ( stream_data->main_loop );
       
  8391 	g_main_loop_unref ( stream_data->main_loop );
       
  8392 	g_free ( username );
       
  8393 	
       
  8394 	/**************************************/
       
  8395 	//Opening a byte stream
       
  8396 	/*
       
  8397 	<iq type='set' from='romeo@montague.net/orchard'
       
  8398 	    			to='juliet@capulet.com/balcony'	id='inband_1'>
       
  8399 	  	<open sid='mySID' block-size='4096' xmlns='http://jabber.org/protocol/ibb'/>
       
  8400 	</iq>
       
  8401 	*/
       
  8402 	stream_data->main_loop = g_main_loop_new ( NULL, FALSE );
       
  8403 	message = lm_message_new_with_sub_type ( NULL,
       
  8404                                          LM_MESSAGE_TYPE_IQ,
       
  8405                                          LM_MESSAGE_SUB_TYPE_SET );
       
  8406 	lm_message_node_set_attribute ( message->node, "to", "donna.prima@gmail.com" );
       
  8407     q_node = lm_message_node_add_child ( message->node, "open", NULL );
       
  8408     lm_message_node_set_attribute ( q_node, "xmlns", "http://jabber.org/protocol/ibb" );
       
  8409     lm_message_node_set_attribute ( q_node, "sid", "mySID" );
       
  8410     lm_message_node_set_attribute ( q_node, "block-size", "4096" );
       
  8411     
       
  8412     // Send message to the server
       
  8413 	handler = lm_message_handler_new ( handle_send_image_stream_msg_open_cb, stream_data, NULL );	
       
  8414 	if ( !lm_connection_send_with_reply ( connection, message, handler, NULL ) ) 
       
  8415 	    {
       
  8416 		iLog->Log ( _L ( "lm_connection_send_with_reply in lm_add_contactL failed" ) );
       
  8417 		lm_connection_close ( connection, NULL );
       
  8418 		lm_connection_unref ( connection );
       
  8419 		lm_message_unref ( message );
       
  8420 		lm_message_handler_unref(handler);
       
  8421 		free_data ( stream_data->connect_data );
       
  8422 		g_main_loop_unref ( stream_data->main_loop );
       
  8423 		g_free(stream_data);
       
  8424 		return KErrGeneral;
       
  8425 	    }
       
  8426 	g_main_loop_run ( stream_data->main_loop );
       
  8427 	g_main_loop_unref ( stream_data->main_loop );
       
  8428 	lm_message_unref ( message );    
       
  8429 	lm_message_handler_unref(handler);
       
  8430 	/***************************************/
       
  8431    
       
  8432 	// Close the connection
       
  8433 	lm_connection_close ( connection, NULL );
       
  8434 	
       
  8435 	// Remove a reference on connection
       
  8436 	lm_connection_unref ( connection );
       
  8437 	
       
  8438 	free_data ( connect_data );
       
  8439 	
       
  8440 	// Message sending passed
       
  8441 	iLog->Log ( _L ( "lm_connection_send_imageL passed" ) );
       
  8442 	
       
  8443 	return KErrNone;
       
  8444 }
       
  8445 
       
  8446 //--------------------------------------------------------------------------------
       
  8447 // function_name    : handle_send_image_iq_cb
       
  8448 // description      : callback function to handle messages
       
  8449 // Returns          : LmHandlerResult
       
  8450 //--------------------------------------------------------------------------------
       
  8451 static LmHandlerResult
       
  8452 handle_send_image_iq_cb ( LmMessageHandler* /*handler*/,
       
  8453                   LmConnection*     /*connection*/,
       
  8454                   LmMessage*        reply,
       
  8455                   gpointer          user_data )
       
  8456     {
       
  8457     SendStreamData* stream_data = ( SendStreamData * )user_data;	
       
  8458 	LmMessageSubType  type;
       
  8459 	LmMessageNode *q_node,*item_node;
       
  8460 	type = lm_message_get_sub_type (reply); 
       
  8461         	
       
  8462 	switch (type) 
       
  8463     	{
       
  8464     	case LM_MESSAGE_SUB_TYPE_RESULT:        		        		
       
  8465 			{
       
  8466 			const char* reply_string;
       
  8467 			reply_string = lm_message_node_get_attribute(reply->node,"id");  
       
  8468 			break;
       
  8469 			}
       
  8470     	case LM_MESSAGE_SUB_TYPE_ERROR:          	          		
       
  8471     		{
       
  8472     		/*<iq from='juliet@capulet.com/balcony' to='romeo@montague.net/orchard' id='ibb1' type='error'>
       
  8473 				  ...
       
  8474 				  <error code='504' type='cancel'>
       
  8475 				    <remote-server-timeout xmlns='urn:ietf:params:xml:ns:xmpp-stanzas'/>
       
  8476 				  </error>
       
  8477 			  </iq>
       
  8478 			*/
       
  8479 
       
  8480     		const char* reply_string;
       
  8481     		reply_string = lm_message_node_get_attribute(reply->node,"id");  
       
  8482 			q_node = lm_message_node_get_child (reply->node, "error");
       
  8483 			if (q_node) 
       
  8484 		    	{
       
  8485 		   		const char* error_code;
       
  8486 		   		error_code = lm_message_node_get_attribute(q_node,"code");  
       
  8487 		   		item_node = lm_message_node_get_child (q_node, "feature-not-implemented");
       
  8488 		   		if(item_node==NULL)
       
  8489 		   			{
       
  8490 		   			item_node = lm_message_node_get_child (q_node, "remote-server-timeout");
       
  8491 		   			}
       
  8492 		    	}
       
  8493 		    	
       
  8494 			break;
       
  8495     		}
       
  8496     //	default:
       
  8497     	//	g_assert_not_reached ();
       
  8498     	//	break;
       
  8499     	} 
       
  8500     	
       
  8501     
       
  8502 	if ( stream_data->main_loop )
       
  8503 		{
       
  8504 		g_main_loop_quit ( stream_data->main_loop );
       
  8505 		}	
       
  8506 	lm_message_unref(stream_data->message);
       
  8507 	lm_message_handler_unref(stream_data->handler);
       
  8508 	return LM_HANDLER_RESULT_REMOVE_MESSAGE;
       
  8509     } 
       
  8510     
       
  8511 //--------------------------------------------------------------------------------
       
  8512 // function_name    : handle_send_image_stream_iq_open_cb
       
  8513 // description      : callback function to handle messages
       
  8514 // Returns          : LmHandlerResult
       
  8515 //--------------------------------------------------------------------------------
       
  8516 static LmHandlerResult
       
  8517 handle_send_image_stream_iq_open_cb ( LmMessageHandler* /*handler*/,
       
  8518                   LmConnection*     connection,
       
  8519                   LmMessage*        reply,
       
  8520                   gpointer          user_data )
       
  8521     {
       
  8522     SendStreamData *stream_data = ( SendStreamData * )user_data;	
       
  8523     LmMessageSubType  type;
       
  8524 	LmMessageNode *q_node = NULL;
       
  8525 	LmMessageNode* item_node = NULL;
       
  8526 	LmMessage * message = NULL;
       
  8527 	LmMessageHandler* handler = NULL;
       
  8528 	type = lm_message_get_sub_type (reply); 
       
  8529     /*
       
  8530     //success response
       
  8531     <iq type='result' from='juliet@capulet.com/balcony' to='romeo@montague.net/orchard'
       
  8532     	id='inband_1'/>
       
  8533     	
       
  8534     //error response
       
  8535     <iq type='error' from='juliet@capulet.com/balcony' to='romeo@montague.net/orchard'
       
  8536     	id='inband_1'/>
       
  8537   			<error code='501' type='cancel'>
       
  8538     			<feature-not-implemented xmlns='urn:ietf:params:xml:ns:xmpp-stanzas'/>
       
  8539   			</error>
       
  8540 	</iq>
       
  8541 	*/ 	
       
  8542  
       
  8543 	switch (type) 
       
  8544     	{
       
  8545     	case LM_MESSAGE_SUB_TYPE_RESULT:
       
  8546     		{
       
  8547     		const char* reply_string;
       
  8548     		reply_string = lm_message_node_get_attribute(q_node,"id");  
       
  8549     			
       
  8550 			/****************************************************/
       
  8551 			// send bytes in message
       
  8552 			/*
       
  8553 			<iq from='romeo@montague.net/orchard' to='juliet@capulet.com/balcony' type='set' id='ibb1'>
       
  8554 			  <data xmlns='http://jabber.org/protocol/ibb' sid='mySID' seq='0'>
       
  8555 			    qANQR1DBwU4DX7jmYZnncmUQB/9KuKBddzQH+tZ1ZywKK0yHKnq57kWq+RFtQdCJ
       
  8556 			    WpdWpR0uQsuJe7+vh3NWn59/gTc5MDlX8dS9p0ovStmNcyLhxVgmqS8ZKhsblVeu
       
  8557 			    IpQ0JgavABqibJolc3BKrVtVV1igKiX/N7Pi8RtY1K18toaMDhdEfhBRzO/XB0+P
       
  8558 			    AQhYlRjNacGcslkhXqNjK5Va4tuOAPy2n1Q8UUrHbUd0g+xJ9Bm0G0LZXyvCWyKH
       
  8559 			    kuNEHFQiLuCY6Iv0myq6iX6tjuHehZlFSh80b5BVV9tNLwNR5Eqz1klxMhoghJOA
       
  8560 			  </data>
       
  8561 			</iq>
       
  8562 			*/
       
  8563 			message = lm_message_new_with_sub_type( NULL, LM_MESSAGE_TYPE_IQ, 
       
  8564 													LM_MESSAGE_SUB_TYPE_SET);
       
  8565 			lm_message_node_set_attribute ( message->node, "to", "donna.prima@gmail.com" );
       
  8566 		    q_node = lm_message_node_add_child ( message->node, "data", 
       
  8567 		    		"qANQR1DBwU4DX7jmYZnncmUQB/9KuKBddzQH+tZ1ZywKK0yHKnq57kWq+RFtQdCJ \
       
  8568 				    WpdWpR0uQsuJe7+vh3NWn59/gTc5MDlX8dS9p0ovStmNcyLhxVgmqS8ZKhsblVeu \
       
  8569 				    IpQ0JgavABqibJolc3BKrVtVV1igKiX/N7Pi8RtY1K18toaMDhdEfhBRzO/XB0+P \
       
  8570 				    AQhYlRjNacGcslkhXqNjK5Va4tuOAPy2n1Q8UUrHbUd0g+xJ9Bm0G0LZXyvCWyKH \
       
  8571 				    kuNEHFQiLuCY6Iv0myq6iX6tjuHehZlFSh80b5BVV9tNLwNR5Eqz1klxMhoghJOA" );
       
  8572 		    lm_message_node_set_attribute ( q_node, "xmlns", "http://jabber.org/protocol/ibb" );
       
  8573 		    lm_message_node_set_attribute ( q_node, "sid", "mySID" );
       
  8574 		    lm_message_node_set_attribute ( q_node, "seq", "0" );
       
  8575 		    stream_data->message = message;
       
  8576 		   
       
  8577 		    // Send message to the server
       
  8578 			handler = lm_message_handler_new ( handle_send_image_iq_cb, stream_data, NULL );	
       
  8579 			stream_data->handler = handler;
       
  8580 			if ( !lm_connection_send_with_reply ( connection, message, handler, NULL ) ) 
       
  8581 			    {
       
  8582 				lm_message_unref ( stream_data->message );
       
  8583 				lm_message_handler_unref(stream_data->handler);
       
  8584 				if ( stream_data->main_loop)
       
  8585 				{
       
  8586 				g_main_loop_quit ( stream_data->main_loop );
       
  8587 				}				
       
  8588 				return LM_HANDLER_RESULT_REMOVE_MESSAGE;
       
  8589 			    }
       
  8590 			/****************************************************/
       
  8591 			break;
       
  8592     		}        		        		
       
  8593     		
       
  8594     	case LM_MESSAGE_SUB_TYPE_ERROR:          	          		
       
  8595     		{
       
  8596     		const char* reply_string;
       
  8597     		reply_string = lm_message_node_get_attribute(reply->node,"id");  
       
  8598 			q_node = lm_message_node_get_child (reply->node, "error");
       
  8599 			if (q_node) 
       
  8600 		    	{
       
  8601 		   		const char* error_code;
       
  8602 		   		error_code = lm_message_node_get_attribute(q_node,"code");  
       
  8603 		   		item_node = lm_message_node_get_child (q_node, "feature-not-implemented");
       
  8604 		    	}
       
  8605 		    if ( stream_data->main_loop)
       
  8606 				{
       
  8607 				g_main_loop_quit ( stream_data->main_loop );
       
  8608 				}
       
  8609 			break;
       
  8610     		}
       
  8611     //	default:
       
  8612     	//	g_assert_not_reached ();
       
  8613     	//	break;
       
  8614     	} 
       
  8615     	
       
  8616 	
       
  8617 	return LM_HANDLER_RESULT_REMOVE_MESSAGE;
       
  8618     }        
       
  8619 //-----------------------------------------------------------------------------
       
  8620 // Ctstlm::lm_connection_send_image_bytestream_iqL
       
  8621 // Description  : Asynchronous call to send a message
       
  8622 // Arguements   :
       
  8623 //   connection	: an LmConnection used to send message
       
  8624 //   message    : LmMessage to send
       
  8625 //   error      : location to store error, or NULL
       
  8626 // Returns      : Returns TRUE if no errors were detected while sending,
       
  8627 //                FALSE otherwise
       
  8628 //-----------------------------------------------------------------------------
       
  8629 // 
       
  8630 TInt Ctstlm::lm_connection_send_image_bytestream_iqL ( CStifItemParser& aItem )
       
  8631     {
       
  8632 	LmConnection *connection   = NULL;
       
  8633 	ConnectData  *connect_data = NULL;
       
  8634 	LmMessage    *message = NULL;
       
  8635 	LmMessageNode* q_node= NULL;
       
  8636 	LmMessageHandler *handler = NULL;
       
  8637 	SendStreamData* stream_data = NULL;
       
  8638 	iLog->Log ( _L ( "In lm_connection_send_imageL" ) );
       
  8639 	
       
  8640 	stream_data = g_new0 ( SendStreamData, 1 );
       
  8641 	if (! stream_data )
       
  8642 		{
       
  8643 		return KErrGeneral;
       
  8644 		}			
       
  8645 	if ( read_data ( stream_data->connect_data, aItem ) != RC_OK )
       
  8646 		{
       
  8647 		iLog->Log ( _L ( "read_data failed" ) );		
       
  8648 		free_data ( stream_data->connect_data );		
       
  8649 		g_free ( stream_data );
       
  8650 		return KErrGeneral;
       
  8651 		}
       
  8652 	stream_data->main_loop    = g_main_loop_new ( NULL, FALSE );	
       
  8653 	stream_data->rCode        = RC_ERROR;
       
  8654 	
       
  8655 	iLog->Log ( _L ( "after read_data" ) );
       
  8656 	
       
  8657 	// Open a new closed connection
       
  8658 	connection = lm_connection_new ( stream_data->connect_data->server );
       
  8659 	iLog->Log ( _L ( "after lm_connection_new " ) );
       
  8660 	if ( !connection )
       
  8661 		{
       
  8662 		iLog->Log ( _L ( "lm_connection_new failed" ) );
       
  8663 		free_data ( stream_data->connect_data );
       
  8664 		return KErrGeneral;
       
  8665 		}
       
  8666 	
       
  8667 	// Set the gtalk's SSL port
       
  8668 	lm_connection_set_port ( connection, GTALK_SSL_PORT );
       
  8669 	
       
  8670 	// Set the JID
       
  8671 	lm_connection_set_jid ( connection, stream_data->connect_data->username );
       
  8672 	
       
  8673 	// Proxy settings for Emulator
       
  8674 #ifdef __WINSCW__
       
  8675 	SetProxy ( connection, stream_data->connect_data->proxy_data );
       
  8676 #endif
       
  8677 	
       
  8678 	// Set the connection to use SSL
       
  8679 	SSLInit ( connection );
       
  8680 	
       
  8681 	stream_data->main_loop = g_main_loop_new ( NULL, FALSE );
       
  8682 	iLog->Log ( _L ( "before lm_connection_open" ) );
       
  8683 	
       
  8684 	if ( !lm_connection_open ( connection, ( LmResultFunction ) connection_open_cb,
       
  8685 	                           stream_data->main_loop, NULL, NULL ) ) 
       
  8686 	    {
       
  8687 		iLog->Log ( _L ( "lm_connection_open failed" ));
       
  8688 		lm_connection_unref ( connection );
       
  8689 		g_main_loop_unref ( stream_data->main_loop );
       
  8690 		free_data ( stream_data->connect_data );
       
  8691 		g_free(stream_data);		
       
  8692 		return KErrGeneral;
       
  8693 	    }
       
  8694 		
       
  8695 	iLog->Log ( _L ( "after lm_connection_open" ) );	
       
  8696 	g_main_loop_run ( stream_data->main_loop );
       
  8697 	g_main_loop_unref ( stream_data->main_loop );   
       
  8698 	
       
  8699 	stream_data->main_loop = g_main_loop_new ( NULL, FALSE );
       
  8700 	
       
  8701 	// Get the username from the JID
       
  8702 	gchar *username = get_user_name ( stream_data->connect_data->username );
       
  8703 	
       
  8704 	// Authenticate with the server
       
  8705 	if ( !lm_connection_authenticate ( connection,
       
  8706                                      username,
       
  8707                                      stream_data->connect_data->password,
       
  8708                                      stream_data->connect_data->resource,
       
  8709                                       ( LmResultFunction ) connection_auth_cb,
       
  8710                                      stream_data->main_loop,NULL,NULL ) )
       
  8711 	    {
       
  8712 		iLog->Log ( _L ( "lm_connection_authenticate failed" ) );
       
  8713 		lm_connection_close ( connection, NULL );
       
  8714 		lm_connection_unref ( connection );
       
  8715 		free_data ( stream_data->connect_data );
       
  8716 		g_main_loop_unref ( stream_data->main_loop );
       
  8717 		g_free(stream_data);
       
  8718 		g_free ( username );
       
  8719 		return KErrGeneral;
       
  8720 	    }
       
  8721 
       
  8722 	g_main_loop_run ( stream_data->main_loop );
       
  8723 	g_main_loop_unref ( stream_data->main_loop );
       
  8724 	g_free ( username );
       
  8725 	/**************************************/
       
  8726 	//Opening a byte stream
       
  8727 	/*
       
  8728 	<iq type='set' from='romeo@montague.net/orchard'
       
  8729 	    			to='juliet@capulet.com/balcony'	id='inband_1'>
       
  8730 	  	<open sid='mySID' block-size='4096' xmlns='http://jabber.org/protocol/ibb'/>
       
  8731 	</iq>
       
  8732 	*/
       
  8733 	stream_data->main_loop = g_main_loop_new ( NULL, FALSE );
       
  8734 	message = lm_message_new_with_sub_type ( NULL,
       
  8735                                          LM_MESSAGE_TYPE_IQ,
       
  8736                                          LM_MESSAGE_SUB_TYPE_SET );
       
  8737 	lm_message_node_set_attribute ( message->node, "to", "donna.prima@gmail.com" );
       
  8738     q_node = lm_message_node_add_child ( message->node, "open", NULL );
       
  8739     lm_message_node_set_attribute ( q_node, "xmlns", "http://jabber.org/protocol/ibb" );
       
  8740     lm_message_node_set_attribute ( q_node, "sid", "mySID" );
       
  8741     lm_message_node_set_attribute ( q_node, "block-size", "4096" );
       
  8742     
       
  8743     // Send message to the server
       
  8744 	handler = lm_message_handler_new ( handle_send_image_stream_iq_open_cb, stream_data, NULL );	
       
  8745 	if ( !lm_connection_send_with_reply ( connection, message, handler, NULL ) ) 
       
  8746 	    {
       
  8747 		iLog->Log ( _L ( "lm_connection_send_with_reply in lm_add_contactL failed" ) );
       
  8748 		lm_connection_close ( connection, NULL );
       
  8749 		lm_connection_unref ( connection );
       
  8750 		lm_message_unref ( message );
       
  8751 		lm_message_handler_unref(handler);
       
  8752 		free_data ( stream_data->connect_data );
       
  8753 		g_free(stream_data);
       
  8754 		g_main_loop_unref ( stream_data->main_loop );
       
  8755 		return KErrGeneral;
       
  8756 	    }
       
  8757 	g_main_loop_run ( stream_data->main_loop );
       
  8758 	g_main_loop_unref ( stream_data->main_loop );
       
  8759 	lm_message_unref ( message );    
       
  8760 	lm_message_handler_unref(handler);
       
  8761 	/****************************************************/
       
  8762    
       
  8763 	// Close the connection
       
  8764 	lm_connection_close ( connection, NULL );	
       
  8765 	// Remove a reference on connection
       
  8766 	lm_connection_unref ( connection );
       
  8767 	free_data ( stream_data->connect_data );
       
  8768 	g_free(stream_data);
       
  8769 	// Message sending passed
       
  8770 	iLog->Log ( _L ( "lm_connection_send_imageL passed" ) );
       
  8771 	
       
  8772 	return KErrNone;
       
  8773 }
       
  8774 
       
  8775 //-----------------------------------------------------------------------------
       
  8776 // Ctstlm::lm_connection_send_multiple_connL
       
  8777 // Description  : Asynchronous call to send a message
       
  8778 // Arguements   :
       
  8779 //   connection	: an LmConnection used to send message
       
  8780 //   message    : LmMessage to send
       
  8781 //   error      : location to store error, or NULL
       
  8782 // Returns      : Returns TRUE if no errors were detected while sending,
       
  8783 //                FALSE otherwise
       
  8784 //-----------------------------------------------------------------------------
       
  8785 // 
       
  8786 TInt Ctstlm::lm_connection_send_multiple_connL ( CStifItemParser& aItem )
       
  8787     {
       
  8788 	LmConnection *connection1   = NULL;
       
  8789 	LmConnection *connection2   = NULL;
       
  8790 	ConnectData  *connect_data1 = NULL;
       
  8791 	LmMessage    *message;
       
  8792 	iLog->Log ( _L ( "In lm_connection_send_multiple_connL" ) );
       
  8793 	
       
  8794 	// Read a data from the CFG file
       
  8795 	if ( read_data ( connect_data1, aItem ) != RC_OK )
       
  8796 		{
       
  8797 		iLog->Log ( _L ( "read_data failed" ) );
       
  8798 		free_data ( connect_data1 );
       
  8799 		return KErrGeneral;
       
  8800 		}
       
  8801 	iLog->Log ( _L ( "after read_data" ) );
       
  8802 	
       
  8803 	// Open a new closed connection
       
  8804 	connection1 = lm_connection_new ( connect_data1->server );	
       
  8805 	connection2 = lm_connection_new ( connect_data1->server );
       
  8806 	
       
  8807 	
       
  8808 	iLog->Log ( _L ( "after lm_connection_new " ) );
       
  8809 	if ( !connection1 || !connection2 )
       
  8810 		{
       
  8811 		iLog->Log ( _L ( "lm_connection_new failed" ) );
       
  8812 		free_data ( connect_data1 );
       
  8813 		//free_data ( connect_data2 );
       
  8814 		return KErrGeneral;
       
  8815 		}
       
  8816 	
       
  8817 	// Set the gtalk's SSL port and Set the JID
       
  8818 	lm_connection_set_port ( connection1, GTALK_SSL_PORT );
       
  8819 	lm_connection_set_jid ( connection1, connect_data1->username );
       
  8820 	
       
  8821 	// Set the gtalk's SSL port and Set the JID
       
  8822 	lm_connection_set_port ( connection2, GTALK_SSL_PORT );
       
  8823 	lm_connection_set_jid ( connection2, connect_data1->username );
       
  8824 
       
  8825 	// Proxy settings for Emulator
       
  8826 #ifdef __WINSCW__
       
  8827 	SetProxy ( connection1, connect_data1->proxy_data );
       
  8828 	SetProxy ( connection2, connect_data1->proxy_data );
       
  8829 #endif
       
  8830 	
       
  8831 	// Set the connection to use SSL
       
  8832 	SSLInit ( connection1 );
       
  8833 	SSLInit ( connection2 );
       
  8834 	/********************************************************/
       
  8835 	//CONNECTION1
       
  8836 	GMainLoop	*main_loop = g_main_loop_new ( NULL, FALSE );
       
  8837 	iLog->Log ( _L ( "before lm_connection_open" ) );
       
  8838 	if ( !lm_connection_open ( connection1, ( LmResultFunction ) connection_open_cb,
       
  8839 	                           main_loop, NULL, NULL ) ) 
       
  8840 	    {
       
  8841 		iLog->Log ( _L ( "lm_connection_open failed" ));
       
  8842 		lm_connection_unref ( connection1 );
       
  8843 		g_main_loop_unref ( main_loop );
       
  8844 		free_data ( connect_data1 );		
       
  8845 		return KErrGeneral;
       
  8846 	    }
       
  8847 	iLog->Log ( _L ( "after lm_connection_open" ) );
       
  8848 	g_main_loop_run ( main_loop );
       
  8849 	g_main_loop_unref ( main_loop );    
       
  8850     main_loop = g_main_loop_new ( NULL, FALSE );
       
  8851 	// Get the username from the JID
       
  8852 	gchar *username = get_user_name ( connect_data1->username );	
       
  8853 	// Authenticate with the server
       
  8854 	if ( !lm_connection_authenticate ( connection1,
       
  8855                                      username,
       
  8856                                      connect_data1->password,
       
  8857                                      connect_data1->resource,
       
  8858                                       ( LmResultFunction ) connection_auth_cb,
       
  8859                                      main_loop,NULL,NULL ) )
       
  8860 	    {
       
  8861 		iLog->Log ( _L ( "lm_connection_authenticate failed" ) );
       
  8862 		lm_connection_close ( connection1, NULL );
       
  8863 		lm_connection_unref ( connection1 );
       
  8864 		free_data ( connect_data1 );
       
  8865 		g_main_loop_unref ( main_loop );
       
  8866 		g_free ( username );
       
  8867 		return KErrGeneral;
       
  8868 	    }
       
  8869 	g_main_loop_run ( main_loop );
       
  8870 	g_main_loop_unref ( main_loop );
       
  8871 	g_free ( username );
       
  8872 	
       
  8873 	/****************************************************/
       
  8874 	//CONNECTION1 MSG
       
  8875 	// Construct a message
       
  8876 	message = lm_message_new ( connect_data1->msg_data->recipient,               
       
  8877 	                           LM_MESSAGE_TYPE_MESSAGE );
       
  8878 	lm_message_node_add_child ( message->node, "body", 
       
  8879 	                            connect_data1->msg_data->message);
       
  8880 	// Send message to the server
       
  8881 	if ( !lm_connection_send ( connection1, message, NULL ) )
       
  8882 	    {
       
  8883 		iLog->Log ( _L ( "lm_connection_send failed" ) );
       
  8884 		lm_connection_close ( connection1, NULL );
       
  8885 		lm_connection_unref ( connection1 );
       
  8886 		lm_connection_unref ( connection2 );
       
  8887 		lm_message_unref ( message );
       
  8888 		free_data ( connect_data1 );		
       
  8889 		return KErrGeneral;
       
  8890 	    }	
       
  8891 	// Remove a reference on message
       
  8892 	lm_message_unref ( message );	
       
  8893 	
       
  8894 	/***********************************************/
       
  8895 	//CONNECTION2
       
  8896 	main_loop = g_main_loop_new ( NULL, FALSE );
       
  8897 	iLog->Log ( _L ( "before lm_connection_open" ) );
       
  8898 	if ( !lm_connection_open ( connection2, ( LmResultFunction ) connection_open_cb,
       
  8899 	                           main_loop, NULL, NULL ) ) 
       
  8900 	    {
       
  8901 		iLog->Log ( _L ( "lm_connection_open failed" ));
       
  8902 		lm_connection_close ( connection1, NULL );
       
  8903 		lm_connection_unref ( connection1 );
       
  8904 		lm_connection_unref ( connection2 );
       
  8905 		g_main_loop_unref ( main_loop );
       
  8906 		free_data ( connect_data1 );		
       
  8907 		return KErrGeneral;
       
  8908 	    }
       
  8909 	iLog->Log ( _L ( "after lm_connection_open" ) );
       
  8910 	g_main_loop_run ( main_loop );
       
  8911 	g_main_loop_unref ( main_loop );    
       
  8912     main_loop = g_main_loop_new ( NULL, FALSE );
       
  8913 	// Get the username from the JID
       
  8914 	username = get_user_name ( connect_data1->username );	
       
  8915 	// Authenticate with the server
       
  8916 	if ( !lm_connection_authenticate ( connection2,
       
  8917                                      username,
       
  8918                                      connect_data1->password,
       
  8919                                      /*connect_data2->resource*/
       
  8920                                      "RSC1234",
       
  8921                                       ( LmResultFunction ) connection_auth_cb,
       
  8922                                      main_loop,NULL,NULL ) )
       
  8923 	    {
       
  8924 		iLog->Log ( _L ( "lm_connection_authenticate failed" ) );
       
  8925 		lm_connection_close ( connection1, NULL );
       
  8926 		lm_connection_unref ( connection1 );
       
  8927 		lm_connection_close ( connection2, NULL );
       
  8928 		lm_connection_unref ( connection2 );
       
  8929 		free_data ( connect_data1 );
       
  8930 		g_main_loop_unref ( main_loop );
       
  8931 		g_free ( username );
       
  8932 		return KErrGeneral;
       
  8933 	    }
       
  8934 	g_main_loop_run ( main_loop );
       
  8935 	g_main_loop_unref ( main_loop );
       
  8936 	g_free ( username );
       
  8937 	/***********************************************/
       
  8938 	// CONNECTION2 MSG
       
  8939 	// Construct a message
       
  8940 	message = lm_message_new ( connect_data1->msg_data->recipient,               
       
  8941 	                           LM_MESSAGE_TYPE_MESSAGE );
       
  8942 	lm_message_node_add_child ( message->node, "body", 
       
  8943 	                            connect_data1->msg_data->message);
       
  8944 	// Send message to the server
       
  8945 	if ( !lm_connection_send ( connection2, message, NULL ) )
       
  8946 	    {
       
  8947 		iLog->Log ( _L ( "lm_connection_send failed" ) );
       
  8948 		lm_connection_close ( connection2, NULL );
       
  8949 		lm_connection_unref ( connection2 );
       
  8950 		lm_message_unref ( message );
       
  8951 		free_data ( connect_data1);		
       
  8952 		return KErrGeneral;
       
  8953 	    }	
       
  8954 	// Remove a reference on message
       
  8955 	lm_message_unref ( message );
       
  8956 	
       
  8957 	/**********************************************/
       
  8958 	// Close the connection
       
  8959 	lm_connection_close ( connection1, NULL );
       
  8960 	// Remove a reference on connection
       
  8961 	lm_connection_unref ( connection1 );
       
  8962 	free_data ( connect_data1 );
       
  8963 	
       
  8964 	// Close the connection
       
  8965 	lm_connection_close ( connection2, NULL );
       
  8966 	// Remove a reference on connection
       
  8967 	lm_connection_unref ( connection2 );
       
  8968 	
       
  8969 	
       
  8970 	// Message sending passed
       
  8971 	iLog->Log ( _L ( "lm_connection_send_multiple_connL passed" ) );
       
  8972 	
       
  8973 	return KErrNone;
       
  8974 }
       
  8975 //--------------------------------------------------------------------------------
       
  8976 // function_name    : handle_block_contact
       
  8977 // description      : callback function to handle messages
       
  8978 // Returns          : LmHandlerResult
       
  8979 //--------------------------------------------------------------------------------
       
  8980 static LmHandlerResult
       
  8981 handle_block_contact ( LmMessageHandler* /*handler*/,
       
  8982                   LmConnection*     /*connection*/,
       
  8983                   LmMessage*        reply,
       
  8984                   gpointer          user_data )
       
  8985     {
       
  8986     GMainLoop *main_loop = ( GMainLoop * )user_data;	
       
  8987 	LmMessageSubType  type;
       
  8988 	LmMessageNode *q_node,*item_node;
       
  8989 	type = lm_message_get_sub_type (reply); 
       
  8990     /*
       
  8991     <iq type='result' id='edit1' to='romeo@example.net/orchard'/>
       
  8992     */ 	
       
  8993     /*
       
  8994     <iq to='romeo@example.net/orchard' type='set' id='push1'>
       
  8995 		  <query xmlns='jabber:iq:privacy'>
       
  8996 		    <list name='public'/>
       
  8997 		  </query>
       
  8998 	</iq>
       
  8999 
       
  9000 	<iq to='romeo@example.net/home' type='set' id='push2'>
       
  9001 		  <query xmlns='jabber:iq:privacy'>
       
  9002 		    <list name='public'/>
       
  9003 		  </query>
       
  9004 	</iq>
       
  9005 	*/
       
  9006        	
       
  9007 	switch (type) 
       
  9008     	{
       
  9009     	case LM_MESSAGE_SUB_TYPE_RESULT:        		        		
       
  9010     		break;
       
  9011     	case LM_MESSAGE_SUB_TYPE_ERROR:          	          		
       
  9012     		//return NULL;
       
  9013     		break;
       
  9014     //	default:
       
  9015     	//	g_assert_not_reached ();
       
  9016     	//	break;
       
  9017     	} 
       
  9018     
       
  9019    //	q_node = lm_message_node_get_child (reply->node, "query");
       
  9020 
       
  9021 	if (!q_node) 
       
  9022     	{
       
  9023    		//return NULL;
       
  9024     	}
       
  9025     	
       
  9026     //item_node = lm_message_node_get_child (q_node, "id");
       
  9027 	const char* reply_string;
       
  9028     reply_string = lm_message_node_get_attribute(reply->node,"id");  
       
  9029 	
       
  9030 	if ( main_loop )
       
  9031 		{
       
  9032 		g_main_loop_quit ( main_loop );
       
  9033 		}	
       
  9034 	
       
  9035 	return LM_HANDLER_RESULT_REMOVE_MESSAGE;
       
  9036     }  
       
  9037 //-----------------------------------------------------------------------------
       
  9038 // Ctstlm::lm_connection_block_contactL
       
  9039 // Description  : Asynchronous call to send a message
       
  9040 // Arguements   :
       
  9041 //   connection	: an LmConnection used to send message
       
  9042 //   message    : LmMessage to send
       
  9043 //   error      : location to store error, or NULL
       
  9044 // Returns      : Returns TRUE if no errors were detected while sending,
       
  9045 //                FALSE otherwise
       
  9046 //-----------------------------------------------------------------------------
       
  9047 // 
       
  9048 TInt Ctstlm::lm_connection_block_contactL ( CStifItemParser& aItem )
       
  9049     {
       
  9050 	LmConnection *connection   = NULL;
       
  9051 	ConnectData  *connect_data = NULL;
       
  9052 	LmMessage    *message = NULL;
       
  9053 	LmMessageNode* q_node = NULL;
       
  9054 	LmMessageNode* item_node1 = NULL;
       
  9055 	LmMessageNode* item_node2 = NULL;
       
  9056 	LmMessageNode* item_node3 = NULL;
       
  9057 	
       
  9058 	LmMessageHandler *handler = NULL;
       
  9059 	
       
  9060 	iLog->Log ( _L ( "In lm_connection_block_contactL" ) );
       
  9061 	
       
  9062 	// Read a data from the CFG file
       
  9063 	if ( read_data ( connect_data, aItem ) != RC_OK )
       
  9064 		{
       
  9065 		iLog->Log ( _L ( "read_data failed" ) );
       
  9066 		free_data ( connect_data );
       
  9067 		return KErrGeneral;
       
  9068 		}
       
  9069 	iLog->Log ( _L ( "after read_data" ) );
       
  9070 	
       
  9071 	// Open a new closed connection
       
  9072 	connection = lm_connection_new ( connect_data->server );
       
  9073 	iLog->Log ( _L ( "after lm_connection_new " ) );
       
  9074 	if ( !connection )
       
  9075 		{
       
  9076 		iLog->Log ( _L ( "lm_connection_new failed" ) );
       
  9077 		free_data ( connect_data );
       
  9078 		return KErrGeneral;
       
  9079 		}
       
  9080 	
       
  9081 	// Set the gtalk's SSL port
       
  9082 	lm_connection_set_port ( connection, GTALK_SSL_PORT );
       
  9083 	
       
  9084 	// Set the JID
       
  9085 	lm_connection_set_jid ( connection, connect_data->username );
       
  9086 	
       
  9087 	// Proxy settings for Emulator
       
  9088 #ifdef __WINSCW__
       
  9089 	SetProxy ( connection, connect_data->proxy_data );
       
  9090 #endif
       
  9091 	
       
  9092 	// Set the connection to use SSL
       
  9093 	SSLInit ( connection );
       
  9094 	
       
  9095 	GMainLoop	*main_loop = g_main_loop_new ( NULL, FALSE );
       
  9096 
       
  9097 	iLog->Log ( _L ( "before lm_connection_open" ) );
       
  9098 	
       
  9099 	if ( !lm_connection_open ( connection, ( LmResultFunction ) connection_open_cb,
       
  9100 	                           main_loop, NULL, NULL ) ) 
       
  9101 	    {
       
  9102 		iLog->Log ( _L ( "lm_connection_open failed" ));
       
  9103 		lm_connection_unref ( connection );
       
  9104 		g_main_loop_unref ( main_loop );
       
  9105 		free_data ( connect_data );		
       
  9106 		return KErrGeneral;
       
  9107 	    }
       
  9108 	iLog->Log ( _L ( "after lm_connection_open" ) );
       
  9109 	g_main_loop_run ( main_loop );
       
  9110 	g_main_loop_unref ( main_loop );    
       
  9111 
       
  9112 	main_loop = g_main_loop_new ( NULL, FALSE );
       
  9113 	
       
  9114 	// Get the username from the JID
       
  9115 	gchar *username = get_user_name ( connect_data->username );
       
  9116 	
       
  9117 	// Authenticate with the server
       
  9118 	if ( !lm_connection_authenticate ( connection,
       
  9119                                      username,
       
  9120                                      connect_data->password,
       
  9121                                      connect_data->resource,
       
  9122                                       ( LmResultFunction ) connection_auth_cb,
       
  9123                                      main_loop,NULL,NULL ) )
       
  9124 	    {
       
  9125 		iLog->Log ( _L ( "lm_connection_authenticate failed" ) );
       
  9126 		lm_connection_close ( connection, NULL );
       
  9127 		lm_connection_unref ( connection );
       
  9128 		free_data ( connect_data );
       
  9129 		g_main_loop_unref ( main_loop );
       
  9130 		g_free ( username );
       
  9131 		return KErrGeneral;
       
  9132 	    }
       
  9133 
       
  9134 	g_main_loop_run ( main_loop );
       
  9135 	g_main_loop_unref ( main_loop );
       
  9136 	g_free ( username );
       
  9137 	/**********************************/	
       
  9138   	/*<iq>
       
  9139   		<query xmlns='jabber:iq:privacy'>
       
  9140     		<list name='foo'>
       
  9141 			    <item
       
  9142 			          type='[jid|group|subscription]'
       
  9143 			          value='bar'
       
  9144 			          action='[allow|deny]'
       
  9145 			          order='unsignedInt'>
       
  9146 			        [<message/>]
       
  9147 			        [<presence-in/>]
       
  9148 			        [<presence-out/>]
       
  9149 			        [<iq/>]
       
  9150       			</item>
       
  9151     		</list>
       
  9152   		</query>
       
  9153 	</iq>*/
       
  9154 
       
  9155 	// Construct a message with type=LM_MESSAGE_TYPE_IQ
       
  9156 	main_loop = g_main_loop_new ( NULL, FALSE );
       
  9157 	message = lm_message_new_with_sub_type ( NULL,
       
  9158                                          LM_MESSAGE_TYPE_IQ,
       
  9159                                          LM_MESSAGE_SUB_TYPE_SET );
       
  9160     q_node = lm_message_node_add_child ( message->node, "query", NULL );
       
  9161     lm_message_node_set_attribute ( q_node, "xmlns", "jabber:iq:privacy" );
       
  9162     item_node1 = lm_message_node_add_child ( q_node, "list", NULL );
       
  9163     lm_message_node_set_attribute ( item_node1, "name", "public" );
       
  9164     item_node2 = lm_message_node_add_child ( item_node1, "item", NULL );
       
  9165     lm_message_node_set_attribute ( item_node2, "type", "jid" );
       
  9166     lm_message_node_set_attribute ( item_node2, "value", "rakesh_harsh@chat.gizmoproject.com" );
       
  9167     lm_message_node_set_attribute ( item_node2, "action", "deny" );
       
  9168     lm_message_node_set_attribute ( item_node2, "order", "1" );
       
  9169     item_node3 = lm_message_node_add_child ( item_node2, "presence-in", NULL );
       
  9170     item_node3 = lm_message_node_add_child ( item_node2, "message", NULL );
       
  9171     
       
  9172     
       
  9173     // Send message to the server
       
  9174 	handler = lm_message_handler_new ( handle_block_contact, main_loop, NULL );	
       
  9175 	if ( !lm_connection_send_with_reply ( connection, message, handler, NULL ) ) 
       
  9176 	    {
       
  9177 		iLog->Log ( _L ( "lm_connection_send_with_reply in lm_add_contactL failed" ) );
       
  9178 		lm_connection_close ( connection, NULL );
       
  9179 		lm_connection_unref ( connection );
       
  9180 		lm_message_unref ( message );
       
  9181 		lm_message_handler_unref(handler);
       
  9182 		free_data ( connect_data );
       
  9183 		g_main_loop_unref ( main_loop );
       
  9184 		return KErrGeneral;
       
  9185 	    }
       
  9186 	g_main_loop_run ( main_loop );
       
  9187 	lm_message_unref ( message );    
       
  9188 	lm_message_handler_unref(handler);
       
  9189 
       
  9190 	/**********************************/	
       
  9191    // Construct a message with type=LM_MESSAGE_TYPE_IQ
       
  9192 	/*
       
  9193 	<iq from='romeo@example.net/orchard' type='get' id='getlist2'>
       
  9194 		  <query xmlns='jabber:iq:privacy'>
       
  9195 		    <list name='public'/>
       
  9196 		  </query>
       
  9197 	</iq>
       
  9198 	*/
       
  9199 	main_loop = g_main_loop_new ( NULL, FALSE );
       
  9200 	message = lm_message_new_with_sub_type ( NULL,
       
  9201                                          LM_MESSAGE_TYPE_IQ,
       
  9202                                          LM_MESSAGE_SUB_TYPE_GET );
       
  9203     q_node = lm_message_node_add_child ( message->node, "query", NULL );
       
  9204     lm_message_node_set_attribute ( q_node, "xmlns", "jabber:iq:privacy" );
       
  9205     item_node1 = lm_message_node_add_child ( q_node, "list", NULL );
       
  9206     lm_message_node_set_attribute ( item_node1, "name", "public" );
       
  9207     
       
  9208     // Send message to the server
       
  9209 	handler = lm_message_handler_new ( handle_get_privacy_lists, main_loop, NULL );	
       
  9210 	if ( !lm_connection_send_with_reply ( connection, message, handler, NULL ) ) 
       
  9211 	    {
       
  9212 		iLog->Log ( _L ( "lm_connection_get_one_privacy_listL failed" ) );
       
  9213 		lm_connection_close ( connection, NULL );
       
  9214 		lm_connection_unref ( connection );
       
  9215 		lm_message_unref ( message );
       
  9216 		lm_message_handler_unref(handler);
       
  9217 		free_data ( connect_data );
       
  9218 		g_main_loop_unref ( main_loop );
       
  9219 		return KErrGeneral;
       
  9220 	    }
       
  9221 	g_main_loop_run ( main_loop );
       
  9222 	g_main_loop_unref ( main_loop );
       
  9223 	lm_message_unref ( message );    
       
  9224 	lm_message_handler_unref(handler);
       
  9225 	/************************************/
       
  9226    
       
  9227 	// Close the connection
       
  9228 	lm_connection_close ( connection, NULL );
       
  9229 	
       
  9230 	// Remove a reference on connection
       
  9231 	lm_connection_unref ( connection );
       
  9232 	
       
  9233 	
       
  9234 	free_data ( connect_data );
       
  9235 	
       
  9236 	// Message sending passed
       
  9237 	iLog->Log ( _L ( "lm_connection_block_contactL passed" ) );
       
  9238 	
       
  9239 	return KErrNone;
       
  9240 }
       
  9241 //--------------------------------------------------------------------------------
       
  9242 // function_name    : handle_unblock_contact
       
  9243 // description      : callback function to handle messages
       
  9244 // Returns          : LmHandlerResult
       
  9245 //--------------------------------------------------------------------------------
       
  9246 static LmHandlerResult
       
  9247 handle_unblock_contact ( LmMessageHandler* /*handler*/,
       
  9248                   LmConnection*     /*connection*/,
       
  9249                   LmMessage*        reply,
       
  9250                   gpointer          user_data )
       
  9251     {
       
  9252     GMainLoop *main_loop = ( GMainLoop * )user_data;	
       
  9253 	LmMessageSubType  type;
       
  9254 	LmMessageNode *q_node,*item_node;
       
  9255 	type = lm_message_get_sub_type (reply); 
       
  9256     /*
       
  9257     <iq type='result' id='edit1' to='romeo@example.net/orchard'/>
       
  9258     */ 	
       
  9259     /*
       
  9260     <iq to='romeo@example.net/orchard' type='set' id='push1'>
       
  9261 		  <query xmlns='jabber:iq:privacy'>
       
  9262 		    <list name='public'/>
       
  9263 		  </query>
       
  9264 	</iq>
       
  9265 
       
  9266 	<iq to='romeo@example.net/home' type='set' id='push2'>
       
  9267 		  <query xmlns='jabber:iq:privacy'>
       
  9268 		    <list name='public'/>
       
  9269 		  </query>
       
  9270 	</iq>
       
  9271 	*/
       
  9272        	
       
  9273 	switch (type) 
       
  9274     	{
       
  9275     	case LM_MESSAGE_SUB_TYPE_RESULT:        		        		
       
  9276     		break;
       
  9277     	case LM_MESSAGE_SUB_TYPE_ERROR:          	          		
       
  9278     		//return NULL;
       
  9279     		break;
       
  9280     //	default:
       
  9281     	//	g_assert_not_reached ();
       
  9282     	//	break;
       
  9283     	} 
       
  9284     
       
  9285    //	q_node = lm_message_node_get_child (reply->node, "query");
       
  9286 
       
  9287 	if (!q_node) 
       
  9288     	{
       
  9289    		//return NULL;
       
  9290     	}
       
  9291     	
       
  9292     //item_node = lm_message_node_get_child (q_node, "id");
       
  9293 	const char* reply_string;
       
  9294     reply_string = lm_message_node_get_attribute(reply->node,"id");  
       
  9295 	
       
  9296 	if ( main_loop )
       
  9297 		{
       
  9298 		g_main_loop_quit ( main_loop );
       
  9299 		}	
       
  9300 	
       
  9301 	return LM_HANDLER_RESULT_REMOVE_MESSAGE;
       
  9302     } 
       
  9303 //-----------------------------------------------------------------------------
       
  9304 // Ctstlm::lm_connection_unblock_contactL
       
  9305 // Description  : Asynchronous call to send a message
       
  9306 // Arguements   :
       
  9307 //   connection	: an LmConnection used to send message
       
  9308 //   message    : LmMessage to send
       
  9309 //   error      : location to store error, or NULL
       
  9310 // Returns      : Returns TRUE if no errors were detected while sending,
       
  9311 //                FALSE otherwise
       
  9312 //-----------------------------------------------------------------------------
       
  9313 // 
       
  9314 TInt Ctstlm::lm_connection_unblock_contactL ( CStifItemParser& aItem )
       
  9315     {
       
  9316 	LmConnection *connection   = NULL;
       
  9317 	ConnectData  *connect_data = NULL;
       
  9318 	LmMessage    *message = NULL;
       
  9319 	LmMessageNode* q_node = NULL;
       
  9320 	LmMessageNode* item_node1 = NULL;
       
  9321 	LmMessageNode* item_node2 = NULL;
       
  9322 	LmMessageNode* item_node3 = NULL;	
       
  9323 	LmMessageHandler *handler = NULL;
       
  9324 	
       
  9325 	iLog->Log ( _L ( "In lm_connection_unblock_contactL" ) );
       
  9326 	
       
  9327 	// Read a data from the CFG file
       
  9328 	if ( read_data ( connect_data, aItem ) != RC_OK )
       
  9329 		{
       
  9330 		iLog->Log ( _L ( "read_data failed" ) );
       
  9331 		free_data ( connect_data );
       
  9332 		return KErrGeneral;
       
  9333 		}
       
  9334 	iLog->Log ( _L ( "after read_data" ) );
       
  9335 	
       
  9336 	// Open a new closed connection
       
  9337 	connection = lm_connection_new ( connect_data->server );
       
  9338 	iLog->Log ( _L ( "after lm_connection_new " ) );
       
  9339 	if ( !connection )
       
  9340 		{
       
  9341 		iLog->Log ( _L ( "lm_connection_new failed" ) );
       
  9342 		free_data ( connect_data );
       
  9343 		return KErrGeneral;
       
  9344 		}
       
  9345 	
       
  9346 	// Set the gtalk's SSL port
       
  9347 	lm_connection_set_port ( connection, GTALK_SSL_PORT );	
       
  9348 	// Set the JID
       
  9349 	lm_connection_set_jid ( connection, connect_data->username );
       
  9350 	// Proxy settings for Emulator
       
  9351 #ifdef __WINSCW__
       
  9352 	SetProxy ( connection, connect_data->proxy_data );
       
  9353 #endif
       
  9354 	// Set the connection to use SSL
       
  9355 	SSLInit ( connection );
       
  9356 	
       
  9357 	GMainLoop	*main_loop = g_main_loop_new ( NULL, FALSE );
       
  9358 	iLog->Log ( _L ( "before lm_connection_open" ) );
       
  9359 	if ( !lm_connection_open ( connection, ( LmResultFunction ) connection_open_cb,
       
  9360 	                           main_loop, NULL, NULL ) ) 
       
  9361 	    {
       
  9362 		iLog->Log ( _L ( "lm_connection_open failed" ));
       
  9363 		lm_connection_unref ( connection );
       
  9364 		g_main_loop_unref ( main_loop );
       
  9365 		free_data ( connect_data );		
       
  9366 		return KErrGeneral;
       
  9367 	    }
       
  9368 		
       
  9369 	iLog->Log ( _L ( "after lm_connection_open" ) );	
       
  9370 	g_main_loop_run ( main_loop );
       
  9371 	g_main_loop_unref ( main_loop );    
       
  9372 
       
  9373 	
       
  9374 	main_loop = g_main_loop_new ( NULL, FALSE );	
       
  9375 	// Get the username from the JID
       
  9376 	gchar *username = get_user_name ( connect_data->username );	
       
  9377 	// Authenticate with the server
       
  9378 	if ( !lm_connection_authenticate ( connection,
       
  9379                                      username,
       
  9380                                      connect_data->password,
       
  9381                                      connect_data->resource,
       
  9382                                       ( LmResultFunction ) connection_auth_cb,
       
  9383                                      main_loop,NULL,NULL ) )
       
  9384 	    {
       
  9385 		iLog->Log ( _L ( "lm_connection_authenticate failed" ) );
       
  9386 		lm_connection_close ( connection, NULL );
       
  9387 		lm_connection_unref ( connection );
       
  9388 		free_data ( connect_data );
       
  9389 		g_main_loop_unref ( main_loop );
       
  9390 		g_free ( username );
       
  9391 		return KErrGeneral;
       
  9392 	    }
       
  9393 	
       
  9394 	g_main_loop_run ( main_loop );
       
  9395 	g_main_loop_unref ( main_loop ); 
       
  9396 	g_free ( username );
       
  9397 	
       
  9398 	/**********************************/	
       
  9399     // Construct a message with type=LM_MESSAGE_TYPE_IQ
       
  9400 	main_loop = g_main_loop_new ( NULL, FALSE );
       
  9401 	
       
  9402 	/*<iq>
       
  9403   		<query xmlns='jabber:iq:privacy'>
       
  9404     		<list name='foo'>
       
  9405 			    <item
       
  9406 			          type='[jid|group|subscription]'
       
  9407 			          value='bar'
       
  9408 			          action='[allow|deny]'
       
  9409 			          order='unsignedInt'>
       
  9410 			        [<message/>]
       
  9411 			        [<presence-in/>]
       
  9412 			        [<presence-out/>]
       
  9413 			        [<iq/>]
       
  9414       			</item>
       
  9415     		</list>
       
  9416   		</query>
       
  9417 	</iq>*/
       
  9418 
       
  9419 	message = lm_message_new_with_sub_type ( NULL,
       
  9420                                          LM_MESSAGE_TYPE_IQ,
       
  9421                                          LM_MESSAGE_SUB_TYPE_SET );
       
  9422     q_node = lm_message_node_add_child ( message->node, "query", NULL );
       
  9423     lm_message_node_set_attribute ( q_node, "xmlns", "jabber:iq:privacy" );
       
  9424     item_node1 = lm_message_node_add_child ( q_node, "list", NULL );
       
  9425     lm_message_node_set_attribute ( item_node1, "name", "public" );
       
  9426     item_node2 = lm_message_node_add_child ( item_node1, "item", NULL );
       
  9427     lm_message_node_set_attribute ( item_node2, "type", "jid" );
       
  9428     lm_message_node_set_attribute ( item_node2, "value", "rakesh_harsh@chat.gizmoproject.com" );
       
  9429     lm_message_node_set_attribute ( item_node2, "action", "allow" );
       
  9430     lm_message_node_set_attribute ( item_node2, "order", "1" );
       
  9431     item_node3 = lm_message_node_add_child ( item_node2, "presence-in", NULL );
       
  9432     item_node3 = lm_message_node_add_child ( item_node2, "message", NULL );
       
  9433     
       
  9434     // Send message to the server
       
  9435 	handler = lm_message_handler_new ( handle_unblock_contact, main_loop, NULL );	
       
  9436 	if ( !lm_connection_send_with_reply ( connection, message, handler, NULL ) ) 
       
  9437 	    {
       
  9438 		iLog->Log ( _L ( "lm_connection_send_with_reply in lm_connection_unblock_contactL failed" ) );
       
  9439 		lm_connection_close ( connection, NULL );
       
  9440 		lm_connection_unref ( connection );
       
  9441 		lm_message_unref ( message );
       
  9442 		lm_message_handler_unref(handler);
       
  9443 		free_data ( connect_data );
       
  9444 		g_main_loop_unref ( main_loop );
       
  9445 		return KErrGeneral;
       
  9446 	    }
       
  9447 	g_main_loop_run ( main_loop );
       
  9448 	g_main_loop_unref ( main_loop );
       
  9449 	lm_message_unref ( message );    
       
  9450 	lm_message_handler_unref(handler);
       
  9451 	/**********************************/	
       
  9452    // Construct a message with type=LM_MESSAGE_TYPE_IQ
       
  9453 	/*
       
  9454 	<iq from='romeo@example.net/orchard' type='get' id='getlist2'>
       
  9455 		  <query xmlns='jabber:iq:privacy'>
       
  9456 		    <list name='public'/>
       
  9457 		  </query>
       
  9458 	</iq>
       
  9459 	*/
       
  9460 	main_loop = g_main_loop_new ( NULL, FALSE );
       
  9461 	message = lm_message_new_with_sub_type ( NULL,
       
  9462                                          LM_MESSAGE_TYPE_IQ,
       
  9463                                          LM_MESSAGE_SUB_TYPE_GET );
       
  9464     q_node = lm_message_node_add_child ( message->node, "query", NULL );
       
  9465     lm_message_node_set_attribute ( q_node, "xmlns", "jabber:iq:privacy" );
       
  9466     item_node1 = lm_message_node_add_child ( q_node, "list", NULL );
       
  9467     lm_message_node_set_attribute ( item_node1, "name", "public" );
       
  9468     
       
  9469     // Send message to the server
       
  9470 	handler = lm_message_handler_new ( handle_get_privacy_lists, main_loop, NULL );	
       
  9471 	if ( !lm_connection_send_with_reply ( connection, message, handler, NULL ) ) 
       
  9472 	    {
       
  9473 		iLog->Log ( _L ( "lm_connection_get_one_privacy_listL failed" ) );
       
  9474 		lm_connection_close ( connection, NULL );
       
  9475 		lm_connection_unref ( connection );
       
  9476 		lm_message_unref ( message );
       
  9477 		lm_message_handler_unref(handler);
       
  9478 		free_data ( connect_data );
       
  9479 		g_main_loop_unref ( main_loop );
       
  9480 		return KErrGeneral;
       
  9481 	    }
       
  9482 	g_main_loop_run ( main_loop );
       
  9483 	g_main_loop_unref ( main_loop );
       
  9484 	lm_message_unref ( message );    
       
  9485 	lm_message_handler_unref(handler);
       
  9486 	/************************************/
       
  9487    
       
  9488 	// Close the connection
       
  9489 	lm_connection_close ( connection, NULL );
       
  9490 	
       
  9491 	// Remove a reference on connection
       
  9492 	lm_connection_unref ( connection );
       
  9493 	free_data ( connect_data );
       
  9494 	
       
  9495 	// Message sending passed
       
  9496 	iLog->Log ( _L ( "lm_connection_unblock_contactL passed" ) );
       
  9497 	
       
  9498 	return KErrNone;
       
  9499 }
       
  9500 
       
  9501 //--------------------------------------------------------------------------------
       
  9502 // function_name    : handle_set_active_list
       
  9503 // description      : callback function to handle messages
       
  9504 // Returns          : LmHandlerResult
       
  9505 //--------------------------------------------------------------------------------
       
  9506 static LmHandlerResult
       
  9507 handle_set_active_list ( LmMessageHandler*/* handler*/,
       
  9508                   LmConnection*     /*connection*/,
       
  9509                   LmMessage*        reply,
       
  9510                   gpointer          user_data )
       
  9511     {
       
  9512     GMainLoop *main_loop = ( GMainLoop * )user_data;	
       
  9513 	LmMessageSubType  type;
       
  9514 	LmMessageNode *error_node = NULL;
       
  9515 	LmMessageNode *item_node = NULL;
       
  9516 	type = lm_message_get_sub_type (reply); 
       
  9517     /*
       
  9518     <iq type='result' id='edit1' to='romeo@example.net/orchard'/>
       
  9519     */ 	
       
  9520        	
       
  9521 	switch (type) 
       
  9522     	{
       
  9523     	case LM_MESSAGE_SUB_TYPE_RESULT:        		        		
       
  9524     		{
       
  9525     		const char* id;
       
  9526     		id = lm_message_node_get_attribute(reply->node,"id");  
       
  9527     		break;
       
  9528     		}
       
  9529     	case LM_MESSAGE_SUB_TYPE_ERROR:
       
  9530     		{
       
  9531     		/*<iq to='romeo@example.net/orchard' type='error' id='active2'>
       
  9532 			  <query xmlns='jabber:iq:privacy'>
       
  9533 			    <active name='The Empty Set'/>
       
  9534 			  </query>
       
  9535 			  <error code='404' type='cancel'>
       
  9536 			    <item-not-found
       
  9537 			        xmlns='urn:ietf:params:xml:ns:xmpp-stanzas'/>
       
  9538 			  </error>
       
  9539 			</iq>*/
       
  9540     		error_node = lm_message_node_get_child(reply->node,"error");
       
  9541     		const char* error_code;
       
  9542     		error_code = lm_message_node_get_attribute(error_node,"code");  
       
  9543 			break;
       
  9544     		}
       
  9545     //	default:
       
  9546     	//	g_assert_not_reached ();
       
  9547     	//	break;
       
  9548     	} 
       
  9549 	if ( main_loop )
       
  9550 		{
       
  9551 		g_main_loop_quit ( main_loop );
       
  9552 		}	
       
  9553 	
       
  9554 	return LM_HANDLER_RESULT_REMOVE_MESSAGE;
       
  9555     } 
       
  9556     
       
  9557 //-----------------------------------------------------------------------------
       
  9558 // Ctstlm::lm_connection_set_active_listL
       
  9559 // Description  : Asynchronous call to send a message
       
  9560 // Arguements   :
       
  9561 //   connection	: an LmConnection used to send message
       
  9562 //   message    : LmMessage to send
       
  9563 //   error      : location to store error, or NULL
       
  9564 // Returns      : Returns TRUE if no errors were detected while sending,
       
  9565 //                FALSE otherwise
       
  9566 //-----------------------------------------------------------------------------
       
  9567 // 
       
  9568 TInt Ctstlm::lm_connection_set_active_listL ( CStifItemParser& aItem )
       
  9569     {
       
  9570 	LmConnection *connection   = NULL;
       
  9571 	ConnectData  *connect_data = NULL;
       
  9572 	LmMessage    *message = NULL;
       
  9573 	LmMessageNode* q_node, *item_node1, *item_node2 = NULL;
       
  9574 	LmMessageHandler *handler = NULL;
       
  9575 	
       
  9576 	iLog->Log ( _L ( "In lm_connection_set_active_listL" ) );
       
  9577 	
       
  9578 	// Read a data from the CFG file
       
  9579 	if ( read_data ( connect_data, aItem ) != RC_OK )
       
  9580 		{
       
  9581 		iLog->Log ( _L ( "read_data failed" ) );
       
  9582 		free_data ( connect_data );
       
  9583 		return KErrGeneral;
       
  9584 		}
       
  9585 	iLog->Log ( _L ( "after read_data" ) );
       
  9586 	
       
  9587 	// Open a new closed connection
       
  9588 	connection = lm_connection_new ( connect_data->server );
       
  9589 	iLog->Log ( _L ( "after lm_connection_new " ) );
       
  9590 	if ( !connection )
       
  9591 		{
       
  9592 		iLog->Log ( _L ( "lm_connection_new failed" ) );
       
  9593 		free_data ( connect_data );
       
  9594 		return KErrGeneral;
       
  9595 		}
       
  9596 	
       
  9597 	// Set the gtalk's SSL port
       
  9598 	lm_connection_set_port ( connection, GTALK_SSL_PORT );	
       
  9599 	// Set the JID
       
  9600 	lm_connection_set_jid ( connection, connect_data->username );
       
  9601 	
       
  9602 	// Proxy settings for Emulator
       
  9603 #ifdef __WINSCW__
       
  9604 	SetProxy ( connection, connect_data->proxy_data );
       
  9605 #endif
       
  9606 	
       
  9607 	// Set the connection to use SSL
       
  9608 	SSLInit ( connection );	
       
  9609 	GMainLoop	*main_loop = g_main_loop_new ( NULL, FALSE );
       
  9610 	iLog->Log ( _L ( "before lm_connection_open" ) );	
       
  9611 	if ( !lm_connection_open ( connection, ( LmResultFunction ) connection_open_cb,
       
  9612 	                           main_loop, NULL, NULL ) ) 
       
  9613 	    {
       
  9614 		iLog->Log ( _L ( "lm_connection_open failed" ));
       
  9615 		lm_connection_unref ( connection );
       
  9616 		g_main_loop_unref ( main_loop );
       
  9617 		free_data ( connect_data );		
       
  9618 		return KErrGeneral;
       
  9619 	    }		
       
  9620 	iLog->Log ( _L ( "after lm_connection_open" ) );	
       
  9621 	g_main_loop_run ( main_loop );
       
  9622 	g_main_loop_unref ( main_loop );    
       
  9623 	
       
  9624 	main_loop = g_main_loop_new ( NULL, FALSE );	
       
  9625 	// Get the username from the JID
       
  9626 	gchar *username = get_user_name ( connect_data->username );	
       
  9627 	// Authenticate with the server
       
  9628 	if ( !lm_connection_authenticate ( connection,
       
  9629                                      username,
       
  9630                                      connect_data->password,
       
  9631                                      connect_data->resource,
       
  9632                                       ( LmResultFunction ) connection_auth_cb,
       
  9633                                      main_loop,NULL,NULL ) )
       
  9634 	    {
       
  9635 		iLog->Log ( _L ( "lm_connection_authenticate failed" ) );
       
  9636 		lm_connection_close ( connection, NULL );
       
  9637 		lm_connection_unref ( connection );
       
  9638 		free_data ( connect_data );
       
  9639 		g_main_loop_unref ( main_loop );
       
  9640 		g_free ( username );
       
  9641 		return KErrGeneral;
       
  9642 	    }
       
  9643 	g_main_loop_run ( main_loop );
       
  9644 	g_main_loop_unref ( main_loop );
       
  9645 	g_free ( username );
       
  9646 	
       
  9647 	// Construct a message with type=LM_MESSAGE_TYPE_IQ
       
  9648 	/*
       
  9649 	<iq from='romeo@example.net/orchard' type='set' id='active1'>
       
  9650 		  <query xmlns='jabber:iq:privacy'>
       
  9651 		    <active name='special'/>
       
  9652 		  </query>
       
  9653 	</iq>
       
  9654 	*/
       
  9655 	main_loop = g_main_loop_new ( NULL, FALSE );
       
  9656 	message = lm_message_new_with_sub_type ( NULL,
       
  9657                                          LM_MESSAGE_TYPE_IQ,
       
  9658                                          LM_MESSAGE_SUB_TYPE_SET );
       
  9659     q_node = lm_message_node_add_child ( message->node, "query", NULL );
       
  9660     lm_message_node_set_attribute ( q_node, "xmlns", "jabber:iq:privacy" );
       
  9661     item_node1 = lm_message_node_add_child ( q_node, "active", NULL );
       
  9662     lm_message_node_set_attribute ( item_node1, "name", "public" );
       
  9663     
       
  9664     // Send message to the server
       
  9665 	handler = lm_message_handler_new ( handle_set_active_list, main_loop, NULL );	
       
  9666 	if ( !lm_connection_send_with_reply ( connection, message, handler, NULL ) ) 
       
  9667 	    {
       
  9668 		iLog->Log ( _L ( "lm_connection_send_with_reply in lm_add_contactL failed" ) );
       
  9669 		lm_connection_close ( connection, NULL );
       
  9670 		lm_connection_unref ( connection );
       
  9671 		lm_message_unref ( message );
       
  9672 		lm_message_handler_unref(handler);
       
  9673 		free_data ( connect_data );
       
  9674 		g_main_loop_unref ( main_loop );
       
  9675 		return KErrGeneral;
       
  9676 	    }
       
  9677 	g_main_loop_run ( main_loop );
       
  9678 	g_main_loop_unref ( main_loop );
       
  9679 	lm_message_unref ( message );    
       
  9680 	lm_message_handler_unref(handler);
       
  9681 
       
  9682    
       
  9683 	// Close the connection
       
  9684 	lm_connection_close ( connection, NULL );	
       
  9685 	// Remove a reference on connection
       
  9686 	lm_connection_unref ( connection );	
       
  9687 	free_data ( connect_data );	
       
  9688 	// Message sending passed
       
  9689 	iLog->Log ( _L ( "lm_connection_set_active_listL passed" ) );	
       
  9690 	return KErrNone;
       
  9691 }
       
  9692 
       
  9693 //-----------------------------------------------------------------------------
       
  9694 // Ctstlm::lm_connection_set_unexist_active_listL
       
  9695 // Description  : Asynchronous call to send a message
       
  9696 // Arguements   :
       
  9697 //   connection	: an LmConnection used to send message
       
  9698 //   message    : LmMessage to send
       
  9699 //   error      : location to store error, or NULL
       
  9700 // Returns      : Returns TRUE if no errors were detected while sending,
       
  9701 //                FALSE otherwise
       
  9702 //-----------------------------------------------------------------------------
       
  9703 // 
       
  9704 TInt Ctstlm::lm_connection_set_unexist_active_listL ( CStifItemParser& aItem )
       
  9705     {
       
  9706 	LmConnection *connection   = NULL;
       
  9707 	ConnectData  *connect_data = NULL;
       
  9708 	LmMessage    *message = NULL;
       
  9709 	LmMessageNode* q_node, *item_node1, *item_node2 = NULL;
       
  9710 	LmMessageHandler *handler = NULL;
       
  9711 	
       
  9712 	iLog->Log ( _L ( "In lm_connection_set_unexist_active_listL" ) );
       
  9713 	
       
  9714 	// Read a data from the CFG file
       
  9715 	if ( read_data ( connect_data, aItem ) != RC_OK )
       
  9716 		{
       
  9717 		iLog->Log ( _L ( "read_data failed" ) );
       
  9718 		free_data ( connect_data );
       
  9719 		return KErrGeneral;
       
  9720 		}
       
  9721 	iLog->Log ( _L ( "after read_data" ) );
       
  9722 	
       
  9723 	// Open a new closed connection
       
  9724 	connection = lm_connection_new ( connect_data->server );
       
  9725 	iLog->Log ( _L ( "after lm_connection_new " ) );
       
  9726 	if ( !connection )
       
  9727 		{
       
  9728 		iLog->Log ( _L ( "lm_connection_new failed" ) );
       
  9729 		free_data ( connect_data );
       
  9730 		return KErrGeneral;
       
  9731 		}
       
  9732 	
       
  9733 	// Set the gtalk's SSL port
       
  9734 	lm_connection_set_port ( connection, GTALK_SSL_PORT );	
       
  9735 	// Set the JID
       
  9736 	lm_connection_set_jid ( connection, connect_data->username );
       
  9737 	
       
  9738 	// Proxy settings for Emulator
       
  9739 #ifdef __WINSCW__
       
  9740 	SetProxy ( connection, connect_data->proxy_data );
       
  9741 #endif
       
  9742 	
       
  9743 	// Set the connection to use SSL
       
  9744 	SSLInit ( connection );	
       
  9745 	GMainLoop	*main_loop = g_main_loop_new ( NULL, FALSE );
       
  9746 	iLog->Log ( _L ( "before lm_connection_open" ) );	
       
  9747 	if ( !lm_connection_open ( connection, ( LmResultFunction ) connection_open_cb,
       
  9748 	                           main_loop, NULL, NULL ) ) 
       
  9749 	    {
       
  9750 		iLog->Log ( _L ( "lm_connection_open failed" ));
       
  9751 		lm_connection_unref ( connection );
       
  9752 		g_main_loop_unref ( main_loop );
       
  9753 		free_data ( connect_data );		
       
  9754 		return KErrGeneral;
       
  9755 	    }		
       
  9756 	iLog->Log ( _L ( "after lm_connection_open" ) );	
       
  9757 	g_main_loop_run ( main_loop );
       
  9758 	g_main_loop_unref ( main_loop );    
       
  9759 	
       
  9760 	main_loop = g_main_loop_new ( NULL, FALSE );	
       
  9761 	// Get the username from the JID
       
  9762 	gchar *username = get_user_name ( connect_data->username );	
       
  9763 	// Authenticate with the server
       
  9764 	if ( !lm_connection_authenticate ( connection,
       
  9765                                      username,
       
  9766                                      connect_data->password,
       
  9767                                      connect_data->resource,
       
  9768                                       ( LmResultFunction ) connection_auth_cb,
       
  9769                                      main_loop,NULL,NULL ) )
       
  9770 	    {
       
  9771 		iLog->Log ( _L ( "lm_connection_authenticate failed" ) );
       
  9772 		lm_connection_close ( connection, NULL );
       
  9773 		lm_connection_unref ( connection );
       
  9774 		free_data ( connect_data );
       
  9775 		g_main_loop_unref ( main_loop );
       
  9776 		g_free ( username );
       
  9777 		return KErrGeneral;
       
  9778 	    }
       
  9779 	g_main_loop_run ( main_loop );
       
  9780 	g_main_loop_unref ( main_loop );
       
  9781 	g_free ( username );
       
  9782 	
       
  9783 	// Construct a message with type=LM_MESSAGE_TYPE_IQ
       
  9784 	/*
       
  9785 	<iq from='romeo@example.net/orchard' type='set' id='active1'>
       
  9786 		  <query xmlns='jabber:iq:privacy'>
       
  9787 		    <active name='special'/>
       
  9788 		  </query>
       
  9789 	</iq>
       
  9790 	*/
       
  9791 	main_loop = g_main_loop_new ( NULL, FALSE );
       
  9792 	message = lm_message_new_with_sub_type ( NULL,
       
  9793                                          LM_MESSAGE_TYPE_IQ,
       
  9794                                          LM_MESSAGE_SUB_TYPE_SET );
       
  9795     q_node = lm_message_node_add_child ( message->node, "query", NULL );
       
  9796     lm_message_node_set_attribute ( q_node, "xmlns", "jabber:iq:privacy" );
       
  9797     item_node1 = lm_message_node_add_child ( q_node, "active", NULL );
       
  9798     lm_message_node_set_attribute ( item_node1, "name", "publicunexist" );
       
  9799     
       
  9800     // Send message to the server
       
  9801 	handler = lm_message_handler_new ( handle_set_active_list, main_loop, NULL );	
       
  9802 	if ( !lm_connection_send_with_reply ( connection, message, handler, NULL ) ) 
       
  9803 	    {
       
  9804 		iLog->Log ( _L ( "lm_connection_send_with_reply in lm_add_contactL failed" ) );
       
  9805 		lm_connection_close ( connection, NULL );
       
  9806 		lm_connection_unref ( connection );
       
  9807 		lm_message_unref ( message );
       
  9808 		lm_message_handler_unref(handler);
       
  9809 		free_data ( connect_data );
       
  9810 		g_main_loop_unref ( main_loop );
       
  9811 		return KErrGeneral;
       
  9812 	    }
       
  9813 	g_main_loop_run ( main_loop );
       
  9814 	g_main_loop_unref ( main_loop );
       
  9815 	lm_message_unref ( message );    
       
  9816 	lm_message_handler_unref(handler);
       
  9817 
       
  9818    
       
  9819 	// Close the connection
       
  9820 	lm_connection_close ( connection, NULL );	
       
  9821 	// Remove a reference on connection
       
  9822 	lm_connection_unref ( connection );	
       
  9823 	free_data ( connect_data );	
       
  9824 	// Message sending passed
       
  9825 	iLog->Log ( _L ( "lm_connection_set_unexist_active_listL passed" ) );	
       
  9826 	return KErrNone;
       
  9827 }
       
  9828 
       
  9829 //-----------------------------------------------------------------------------
       
  9830 // Ctstlm::lm_connection_set_decline_active_listL
       
  9831 // Description  : Asynchronous call to send a message
       
  9832 // Arguements   :
       
  9833 //   connection	: an LmConnection used to send message
       
  9834 //   message    : LmMessage to send
       
  9835 //   error      : location to store error, or NULL
       
  9836 // Returns      : Returns TRUE if no errors were detected while sending,
       
  9837 //                FALSE otherwise
       
  9838 //-----------------------------------------------------------------------------
       
  9839 // 
       
  9840 TInt Ctstlm::lm_connection_set_decline_active_listL ( CStifItemParser& aItem )
       
  9841     {
       
  9842 	LmConnection *connection   = NULL;
       
  9843 	ConnectData  *connect_data = NULL;
       
  9844 	LmMessage    *message = NULL;
       
  9845 	LmMessageNode* q_node, *item_node1, *item_node2 = NULL;
       
  9846 	LmMessageHandler *handler = NULL;
       
  9847 	
       
  9848 	iLog->Log ( _L ( "In lm_connection_set_decline_active_listL" ) );
       
  9849 	
       
  9850 	// Read a data from the CFG file
       
  9851 	if ( read_data ( connect_data, aItem ) != RC_OK )
       
  9852 		{
       
  9853 		iLog->Log ( _L ( "read_data failed" ) );
       
  9854 		free_data ( connect_data );
       
  9855 		return KErrGeneral;
       
  9856 		}
       
  9857 	iLog->Log ( _L ( "after read_data" ) );
       
  9858 	
       
  9859 	// Open a new closed connection
       
  9860 	connection = lm_connection_new ( connect_data->server );
       
  9861 	iLog->Log ( _L ( "after lm_connection_new " ) );
       
  9862 	if ( !connection )
       
  9863 		{
       
  9864 		iLog->Log ( _L ( "lm_connection_new failed" ) );
       
  9865 		free_data ( connect_data );
       
  9866 		return KErrGeneral;
       
  9867 		}
       
  9868 	
       
  9869 	// Set the gtalk's SSL port
       
  9870 	lm_connection_set_port ( connection, GTALK_SSL_PORT );	
       
  9871 	// Set the JID
       
  9872 	lm_connection_set_jid ( connection, connect_data->username );
       
  9873 	
       
  9874 	// Proxy settings for Emulator
       
  9875 #ifdef __WINSCW__
       
  9876 	SetProxy ( connection, connect_data->proxy_data );
       
  9877 #endif
       
  9878 	
       
  9879 	// Set the connection to use SSL
       
  9880 	SSLInit ( connection );	
       
  9881 	GMainLoop	*main_loop = g_main_loop_new ( NULL, FALSE );
       
  9882 	iLog->Log ( _L ( "before lm_connection_open" ) );	
       
  9883 	if ( !lm_connection_open ( connection, ( LmResultFunction ) connection_open_cb,
       
  9884 	                           main_loop, NULL, NULL ) ) 
       
  9885 	    {
       
  9886 		iLog->Log ( _L ( "lm_connection_open failed" ));
       
  9887 		lm_connection_unref ( connection );
       
  9888 		g_main_loop_unref ( main_loop );
       
  9889 		free_data ( connect_data );		
       
  9890 		return KErrGeneral;
       
  9891 	    }		
       
  9892 	iLog->Log ( _L ( "after lm_connection_open" ) );	
       
  9893 	g_main_loop_run ( main_loop );
       
  9894 	g_main_loop_unref ( main_loop );    
       
  9895 	
       
  9896 	main_loop = g_main_loop_new ( NULL, FALSE );	
       
  9897 	// Get the username from the JID
       
  9898 	gchar *username = get_user_name ( connect_data->username );	
       
  9899 	// Authenticate with the server
       
  9900 	if ( !lm_connection_authenticate ( connection,
       
  9901                                      username,
       
  9902                                      connect_data->password,
       
  9903                                      connect_data->resource,
       
  9904                                       ( LmResultFunction ) connection_auth_cb,
       
  9905                                      main_loop,NULL,NULL ) )
       
  9906 	    {
       
  9907 		iLog->Log ( _L ( "lm_connection_authenticate failed" ) );
       
  9908 		lm_connection_close ( connection, NULL );
       
  9909 		lm_connection_unref ( connection );
       
  9910 		free_data ( connect_data );
       
  9911 		g_main_loop_unref ( main_loop );
       
  9912 		g_free ( username );
       
  9913 		return KErrGeneral;
       
  9914 	    }
       
  9915 	g_main_loop_run ( main_loop);
       
  9916 	g_main_loop_unref ( main_loop );
       
  9917 	g_free ( username );
       
  9918 	
       
  9919 	// Construct a message with type=LM_MESSAGE_TYPE_IQ
       
  9920 	/*
       
  9921 	<iq from='romeo@example.net/orchard' type='set' id='active3'>
       
  9922 		  <query xmlns='jabber:iq:privacy'>
       
  9923 		    <active/>
       
  9924 		  </query>
       
  9925 	</iq>
       
  9926 
       
  9927 	*/
       
  9928 	main_loop = g_main_loop_new ( NULL, FALSE );
       
  9929 	message = lm_message_new_with_sub_type ( NULL,
       
  9930                                          LM_MESSAGE_TYPE_IQ,
       
  9931                                          LM_MESSAGE_SUB_TYPE_SET );
       
  9932     q_node = lm_message_node_add_child ( message->node, "query", NULL );
       
  9933     lm_message_node_set_attribute ( q_node, "xmlns", "jabber:iq:privacy" );
       
  9934     item_node1 = lm_message_node_add_child ( q_node, "active", NULL );
       
  9935     
       
  9936     // Send message to the server
       
  9937 	handler = lm_message_handler_new ( handle_set_active_list, main_loop, NULL );	
       
  9938 	if ( !lm_connection_send_with_reply ( connection, message, handler, NULL ) ) 
       
  9939 	    {
       
  9940 		iLog->Log ( _L ( "lm_connection_send_with_reply in lm_connection_set_decline_active_listL failed" ) );
       
  9941 		lm_connection_close ( connection, NULL );
       
  9942 		lm_connection_unref ( connection );
       
  9943 		lm_message_unref ( message );
       
  9944 		lm_message_handler_unref(handler);
       
  9945 		free_data ( connect_data );
       
  9946 		g_main_loop_unref ( main_loop );
       
  9947 		return KErrGeneral;
       
  9948 	    }
       
  9949 	g_main_loop_run ( main_loop );
       
  9950 	g_main_loop_unref ( main_loop );
       
  9951 	lm_message_unref ( message );    
       
  9952 	lm_message_handler_unref(handler);
       
  9953 
       
  9954    
       
  9955 	// Close the connection
       
  9956 	lm_connection_close ( connection, NULL );	
       
  9957 	// Remove a reference on connection
       
  9958 	lm_connection_unref ( connection );	
       
  9959 	free_data ( connect_data );	
       
  9960 	// Message sending passed
       
  9961 	iLog->Log ( _L ( "lm_connection_set_decline_active_listL passed" ) );	
       
  9962 	return KErrNone;
       
  9963 }
       
  9964 
       
  9965 //-----------------------------------------------------------------------------
       
  9966 // Ctstlm::lm_connection_get_one_privacy_listL
       
  9967 // Description  : Asynchronous call to send a message
       
  9968 // Arguements   :
       
  9969 //   connection	: an LmConnection used to send message
       
  9970 //   message    : LmMessage to send
       
  9971 //   error      : location to store error, or NULL
       
  9972 // Returns      : Returns TRUE if no errors were detected while sending,
       
  9973 //                FALSE otherwise
       
  9974 //-----------------------------------------------------------------------------
       
  9975 // 
       
  9976 TInt Ctstlm::lm_connection_get_one_privacy_listL ( CStifItemParser& aItem )
       
  9977     {
       
  9978 	LmConnection *connection   = NULL;
       
  9979 	ConnectData  *connect_data = NULL;
       
  9980 	LmMessage    *message = NULL;
       
  9981 	LmMessageNode* q_node, *item_node1 = NULL;
       
  9982 	LmMessageHandler *handler = NULL;
       
  9983 	
       
  9984 	iLog->Log ( _L ( "In lm_connection_get_one_privacy_listL" ) );
       
  9985 	
       
  9986 	// Read a data from the CFG file
       
  9987 	if ( read_data ( connect_data, aItem ) != RC_OK )
       
  9988 		{
       
  9989 		iLog->Log ( _L ( "read_data failed" ) );
       
  9990 		free_data ( connect_data );
       
  9991 		return KErrGeneral;
       
  9992 		}
       
  9993 	iLog->Log ( _L ( "after read_data" ) );
       
  9994 	
       
  9995 	// Open a new closed connection
       
  9996 	connection = lm_connection_new ( connect_data->server );
       
  9997 	iLog->Log ( _L ( "after lm_connection_new " ) );
       
  9998 	if ( !connection )
       
  9999 		{
       
 10000 		iLog->Log ( _L ( "lm_connection_new failed" ) );
       
 10001 		free_data ( connect_data );
       
 10002 		return KErrGeneral;
       
 10003 		}
       
 10004 	
       
 10005 	// Set the gtalk's SSL port
       
 10006 	lm_connection_set_port ( connection, GTALK_SSL_PORT );	
       
 10007 	// Set the JID
       
 10008 	lm_connection_set_jid ( connection, connect_data->username );
       
 10009 	
       
 10010 	// Proxy settings for Emulator
       
 10011 #ifdef __WINSCW__
       
 10012 	SetProxy ( connection, connect_data->proxy_data );
       
 10013 #endif
       
 10014 	
       
 10015 	// Set the connection to use SSL
       
 10016 	SSLInit ( connection );	
       
 10017 	GMainLoop	*main_loop = g_main_loop_new ( NULL, FALSE );
       
 10018 	iLog->Log ( _L ( "before lm_connection_open" ) );	
       
 10019 	if ( !lm_connection_open ( connection, ( LmResultFunction ) connection_open_cb,
       
 10020 	                           main_loop, NULL, NULL ) ) 
       
 10021 	    {
       
 10022 		iLog->Log ( _L ( "lm_connection_open failed" ));
       
 10023 		lm_connection_unref ( connection );
       
 10024 		g_main_loop_unref ( main_loop );
       
 10025 		free_data ( connect_data );		
       
 10026 		return KErrGeneral;
       
 10027 	    }		
       
 10028 	iLog->Log ( _L ( "after lm_connection_open" ) );	
       
 10029 	g_main_loop_run ( main_loop );
       
 10030 	g_main_loop_unref ( main_loop );    
       
 10031 	
       
 10032 	main_loop = g_main_loop_new ( NULL, FALSE );	
       
 10033 	// Get the username from the JID
       
 10034 	gchar *username = get_user_name ( connect_data->username );	
       
 10035 	// Authenticate with the server
       
 10036 	if ( !lm_connection_authenticate ( connection,
       
 10037                                      username,
       
 10038                                      connect_data->password,
       
 10039                                      connect_data->resource,
       
 10040                                       ( LmResultFunction ) connection_auth_cb,
       
 10041                                      main_loop,NULL,NULL ) )
       
 10042 	    {
       
 10043 		iLog->Log ( _L ( "lm_connection_authenticate failed" ) );
       
 10044 		lm_connection_close ( connection, NULL );
       
 10045 		lm_connection_unref ( connection );
       
 10046 		free_data ( connect_data );
       
 10047 		g_main_loop_unref ( main_loop );
       
 10048 		g_free ( username );
       
 10049 		return KErrGeneral;
       
 10050 	    }
       
 10051 	g_main_loop_run ( main_loop );
       
 10052 	g_main_loop_unref ( main_loop );
       
 10053 	g_free ( username );
       
 10054 	
       
 10055 	// Construct a message with type=LM_MESSAGE_TYPE_IQ
       
 10056 	/*
       
 10057 	<iq from='romeo@example.net/orchard' type='get' id='getlist2'>
       
 10058 		  <query xmlns='jabber:iq:privacy'>
       
 10059 		    <list name='public'/>
       
 10060 		  </query>
       
 10061 	</iq>
       
 10062 	*/
       
 10063 	main_loop = g_main_loop_new ( NULL, FALSE );
       
 10064 	message = lm_message_new_with_sub_type ( NULL,
       
 10065                                          LM_MESSAGE_TYPE_IQ,
       
 10066                                          LM_MESSAGE_SUB_TYPE_GET );
       
 10067     q_node = lm_message_node_add_child ( message->node, "query", NULL );
       
 10068     lm_message_node_set_attribute ( q_node, "xmlns", "jabber:iq:privacy" );
       
 10069     item_node1 = lm_message_node_add_child ( q_node, "list", NULL );
       
 10070     lm_message_node_set_attribute ( item_node1, "name", "public" );
       
 10071     
       
 10072     // Send message to the server
       
 10073 	handler = lm_message_handler_new ( handle_get_privacy_lists, main_loop, NULL );	
       
 10074 	if ( !lm_connection_send_with_reply ( connection, message, handler, NULL ) ) 
       
 10075 	    {
       
 10076 		iLog->Log ( _L ( "lm_connection_get_one_privacy_listL failed" ) );
       
 10077 		lm_connection_close ( connection, NULL );
       
 10078 		lm_connection_unref ( connection );
       
 10079 		lm_message_unref ( message );
       
 10080 		lm_message_handler_unref(handler);
       
 10081 		free_data ( connect_data );
       
 10082 		g_main_loop_unref ( main_loop );
       
 10083 		return KErrGeneral;
       
 10084 	    }
       
 10085 	g_main_loop_run ( main_loop );
       
 10086 	g_main_loop_unref ( main_loop );
       
 10087 	lm_message_unref ( message );    
       
 10088 	lm_message_handler_unref(handler);
       
 10089 
       
 10090    
       
 10091 	// Close the connection
       
 10092 	lm_connection_close ( connection, NULL );	
       
 10093 	// Remove a reference on connection
       
 10094 	lm_connection_unref ( connection );	
       
 10095 	free_data ( connect_data );	
       
 10096 	// Message sending passed
       
 10097 	iLog->Log ( _L ( "lm_connection_get_one_privacy_listL passed" ) );	
       
 10098 	return KErrNone;
       
 10099 }
       
 10100 
       
 10101 //-----------------------------------------------------------------------------
       
 10102 // Ctstlm::lm_connection_set_one_privacy_listL
       
 10103 // Description  : Asynchronous call to send a message
       
 10104 // Arguements   :
       
 10105 //   connection	: an LmConnection used to send message
       
 10106 //   message    : LmMessage to send
       
 10107 //   error      : location to store error, or NULL
       
 10108 // Returns      : Returns TRUE if no errors were detected while sending,
       
 10109 //                FALSE otherwise
       
 10110 //-----------------------------------------------------------------------------
       
 10111 // 
       
 10112 TInt Ctstlm::lm_connection_set_one_privacy_listL ( CStifItemParser& aItem )
       
 10113     {
       
 10114 	LmConnection *connection   = NULL;
       
 10115 	ConnectData  *connect_data = NULL;
       
 10116 	LmMessage    *message = NULL;
       
 10117 	LmMessageNode* q_node, *item_node1, *item_node2 = NULL;
       
 10118 	LmMessageHandler *handler = NULL;
       
 10119 	
       
 10120 	iLog->Log ( _L ( "In lm_connection_set_one_privacy_listL" ) );
       
 10121 	
       
 10122 	// Read a data from the CFG file
       
 10123 	if ( read_data ( connect_data, aItem ) != RC_OK )
       
 10124 		{
       
 10125 		iLog->Log ( _L ( "read_data failed" ) );
       
 10126 		free_data ( connect_data );
       
 10127 		return KErrGeneral;
       
 10128 		}
       
 10129 	iLog->Log ( _L ( "after read_data" ) );
       
 10130 	
       
 10131 	// Open a new closed connection
       
 10132 	connection = lm_connection_new ( connect_data->server );
       
 10133 	iLog->Log ( _L ( "after lm_connection_new " ) );
       
 10134 	if ( !connection )
       
 10135 		{
       
 10136 		iLog->Log ( _L ( "lm_connection_new failed" ) );
       
 10137 		free_data ( connect_data );
       
 10138 		return KErrGeneral;
       
 10139 		}
       
 10140 	
       
 10141 	// Set the gtalk's SSL port
       
 10142 	lm_connection_set_port ( connection, GTALK_SSL_PORT );
       
 10143 	
       
 10144 	// Set the JID
       
 10145 	lm_connection_set_jid ( connection, connect_data->username );
       
 10146 	
       
 10147 	// Proxy settings for Emulator
       
 10148 #ifdef __WINSCW__
       
 10149 	SetProxy ( connection, connect_data->proxy_data );
       
 10150 #endif
       
 10151 	
       
 10152 	// Set the connection to use SSL
       
 10153 	SSLInit ( connection );
       
 10154 	
       
 10155 	GMainLoop	*main_loop = g_main_loop_new ( NULL, FALSE );
       
 10156 
       
 10157 	iLog->Log ( _L ( "before lm_connection_open" ) );
       
 10158 	
       
 10159 	if ( !lm_connection_open ( connection, ( LmResultFunction ) connection_open_cb,
       
 10160 	                           main_loop, NULL, NULL ) ) 
       
 10161 	    {
       
 10162 		iLog->Log ( _L ( "lm_connection_open failed" ));
       
 10163 		lm_connection_unref ( connection );
       
 10164 		g_main_loop_unref ( main_loop );
       
 10165 		free_data ( connect_data );		
       
 10166 		return KErrGeneral;
       
 10167 	    }
       
 10168 		
       
 10169 	iLog->Log ( _L ( "after lm_connection_open" ) );	
       
 10170 	g_main_loop_run ( main_loop );
       
 10171 	g_main_loop_unref ( main_loop );    
       
 10172 	
       
 10173 	main_loop = g_main_loop_new ( NULL, FALSE );
       
 10174 	
       
 10175 	// Get the username from the JID
       
 10176 	gchar *username = get_user_name ( connect_data->username );
       
 10177 	
       
 10178 	// Authenticate with the server
       
 10179 	if ( !lm_connection_authenticate ( connection,
       
 10180                                      username,
       
 10181                                      connect_data->password,
       
 10182                                      connect_data->resource,
       
 10183                                       ( LmResultFunction ) connection_auth_cb,
       
 10184                                      main_loop,NULL,NULL ) )
       
 10185 	    {
       
 10186 		iLog->Log ( _L ( "lm_connection_authenticate failed" ) );
       
 10187 		lm_connection_close ( connection, NULL );
       
 10188 		lm_connection_unref ( connection );
       
 10189 		free_data ( connect_data );
       
 10190 		g_main_loop_unref ( main_loop );
       
 10191 		g_free ( username );
       
 10192 		return KErrGeneral;
       
 10193 	    }
       
 10194 
       
 10195 	g_main_loop_run ( main_loop );
       
 10196 	g_main_loop_unref ( main_loop );
       
 10197 	g_free ( username );
       
 10198 	
       
 10199 	// Construct a message with type=LM_MESSAGE_TYPE_IQ
       
 10200 	/*
       
 10201 	<iq from='romeo@example.net/orchard' type='set' id='edit1'>
       
 10202 		<query xmlns='jabber:iq:privacy'>
       
 10203 		    <list name='public'>
       
 10204 		      <item type='jid'
       
 10205 		            value='tybalt@example.com'
       
 10206 		            action='deny'
       
 10207 		            order='3'/>
       
 10208 		      <item type='jid'
       
 10209 		            value='paris@example.org'
       
 10210 		            action='deny'
       
 10211 		            order='5'/>
       
 10212 		      <item action='allow' order='68'/>
       
 10213 		    </list>		    
       
 10214   		</query>
       
 10215 	</iq>
       
 10216 	*/
       
 10217 	main_loop = g_main_loop_new ( NULL, FALSE );
       
 10218 	message = lm_message_new_with_sub_type ( NULL,
       
 10219                                          LM_MESSAGE_TYPE_IQ,
       
 10220                                          LM_MESSAGE_SUB_TYPE_SET );
       
 10221     q_node = lm_message_node_add_child ( message->node, "query", NULL );
       
 10222     lm_message_node_set_attribute ( q_node, "xmlns", "jabber:iq:privacy" );
       
 10223     item_node1 = lm_message_node_add_child ( q_node, "list", NULL );
       
 10224     lm_message_node_set_attribute ( item_node1, "name", "public" );
       
 10225     item_node2 = lm_message_node_add_child ( item_node1, "item", NULL );
       
 10226     lm_message_node_set_attribute ( item_node2, "type", "jid" );
       
 10227     lm_message_node_set_attribute ( item_node2, "value", "rakesh_harsh@chat.gizmoproject.com" );
       
 10228     lm_message_node_set_attribute ( item_node2, "action", "deny" );
       
 10229     lm_message_node_set_attribute ( item_node2, "order", "3" );
       
 10230     
       
 10231     // Send message to the server
       
 10232 	handler = lm_message_handler_new ( handle_set_privacy_lists, main_loop, NULL );	
       
 10233 	if ( !lm_connection_send_with_reply ( connection, message, handler, NULL ) ) 
       
 10234 	    {
       
 10235 		iLog->Log ( _L ( "lm_connection_send_with_reply in lm_connection_set_one_privacy_listL failed" ) );
       
 10236 		lm_connection_close ( connection, NULL );
       
 10237 		lm_connection_unref ( connection );
       
 10238 		lm_message_unref ( message );
       
 10239 		lm_message_handler_unref(handler);
       
 10240 		free_data ( connect_data );
       
 10241 		g_main_loop_unref ( main_loop );
       
 10242 		return KErrGeneral;
       
 10243 	    }
       
 10244 	g_main_loop_run ( main_loop );
       
 10245 	g_main_loop_unref ( main_loop );
       
 10246 	lm_message_unref ( message );    
       
 10247 	lm_message_handler_unref(handler);
       
 10248 
       
 10249    
       
 10250 	// Close the connection
       
 10251 	lm_connection_close ( connection, NULL );
       
 10252 	
       
 10253 	// Remove a reference on connection
       
 10254 	lm_connection_unref ( connection );
       
 10255 	
       
 10256 	free_data ( connect_data );
       
 10257 	
       
 10258 	// Message sending passed
       
 10259 	iLog->Log ( _L ( "lm_connection_set_one_privacy_listL passed" ) );
       
 10260 	
       
 10261 	return KErrNone;
       
 10262 }
       
 10263 
       
 10264 //-----------------------------------------------------------------------------
       
 10265 // Ctstlm::lm_connection_create_one_privacy_listL
       
 10266 // Description  : Asynchronous call to send a message
       
 10267 // Arguements   :
       
 10268 //   connection	: an LmConnection used to send message
       
 10269 //   message    : LmMessage to send
       
 10270 //   error      : location to store error, or NULL
       
 10271 // Returns      : Returns TRUE if no errors were detected while sending,
       
 10272 //                FALSE otherwise
       
 10273 //-----------------------------------------------------------------------------
       
 10274 // 
       
 10275 TInt Ctstlm::lm_connection_create_one_privacy_listL ( CStifItemParser& aItem )
       
 10276     {
       
 10277 	LmConnection *connection   = NULL;
       
 10278 	ConnectData  *connect_data = NULL;
       
 10279 	LmMessage    *message = NULL;
       
 10280 	LmMessageNode* q_node, *item_node1, *item_node2 = NULL;
       
 10281 	LmMessageHandler *handler = NULL;
       
 10282 	
       
 10283 	iLog->Log ( _L ( "In lm_connection_create_one_privacy_listL" ) );
       
 10284 	
       
 10285 	// Read a data from the CFG file
       
 10286 	if ( read_data ( connect_data, aItem ) != RC_OK )
       
 10287 		{
       
 10288 		iLog->Log ( _L ( "read_data failed" ) );
       
 10289 		free_data ( connect_data );
       
 10290 		return KErrGeneral;
       
 10291 		}
       
 10292 	iLog->Log ( _L ( "after read_data" ) );
       
 10293 	
       
 10294 	// Open a new closed connection
       
 10295 	connection = lm_connection_new ( connect_data->server );
       
 10296 	iLog->Log ( _L ( "after lm_connection_new " ) );
       
 10297 	if ( !connection )
       
 10298 		{
       
 10299 		iLog->Log ( _L ( "lm_connection_new failed" ) );
       
 10300 		free_data ( connect_data );
       
 10301 		return KErrGeneral;
       
 10302 		}
       
 10303 	
       
 10304 	// Set the gtalk's SSL port
       
 10305 	lm_connection_set_port ( connection, GTALK_SSL_PORT );
       
 10306 	
       
 10307 	// Set the JID
       
 10308 	lm_connection_set_jid ( connection, connect_data->username );
       
 10309 	
       
 10310 	// Proxy settings for Emulator
       
 10311 #ifdef __WINSCW__
       
 10312 	SetProxy ( connection, connect_data->proxy_data );
       
 10313 #endif
       
 10314 	
       
 10315 	// Set the connection to use SSL
       
 10316 	SSLInit ( connection );
       
 10317 	
       
 10318 	GMainLoop	*main_loop = g_main_loop_new ( NULL, FALSE );
       
 10319 
       
 10320 	iLog->Log ( _L ( "before lm_connection_open" ) );
       
 10321 	
       
 10322 	if ( !lm_connection_open ( connection, ( LmResultFunction ) connection_open_cb,
       
 10323 	                           main_loop, NULL, NULL ) ) 
       
 10324 	    {
       
 10325 		iLog->Log ( _L ( "lm_connection_open failed" ));
       
 10326 		lm_connection_unref ( connection );
       
 10327 		g_main_loop_unref ( main_loop );
       
 10328 		free_data ( connect_data );		
       
 10329 		return KErrGeneral;
       
 10330 	    }
       
 10331 		
       
 10332 	iLog->Log ( _L ( "after lm_connection_open" ) );	
       
 10333 	g_main_loop_run ( main_loop );
       
 10334 	g_main_loop_unref ( main_loop );    
       
 10335 
       
 10336 	
       
 10337 	main_loop = g_main_loop_new ( NULL, FALSE );	
       
 10338 	// Get the username from the JID
       
 10339 	gchar *username = get_user_name ( connect_data->username );
       
 10340 	
       
 10341 	// Authenticate with the server
       
 10342 	if ( !lm_connection_authenticate ( connection,
       
 10343                                      username,
       
 10344                                      connect_data->password,
       
 10345                                      connect_data->resource,
       
 10346                                       ( LmResultFunction ) connection_auth_cb,
       
 10347                                      main_loop,NULL,NULL ) )
       
 10348 	    {
       
 10349 		iLog->Log ( _L ( "lm_connection_authenticate failed" ) );
       
 10350 		lm_connection_close ( connection, NULL );
       
 10351 		lm_connection_unref ( connection );
       
 10352 		free_data ( connect_data );
       
 10353 		g_main_loop_unref ( main_loop );
       
 10354 		g_free ( username );
       
 10355 		return KErrGeneral;
       
 10356 	    }
       
 10357 
       
 10358 	g_main_loop_run ( main_loop );
       
 10359 	g_main_loop_unref ( main_loop );	    
       
 10360 	g_free ( username );
       
 10361 	
       
 10362 	// Construct a message with type=LM_MESSAGE_TYPE_IQ
       
 10363 	/*
       
 10364 	<iq from='romeo@example.net/orchard' type='set' id='edit1'>
       
 10365 		<query xmlns='jabber:iq:privacy'>
       
 10366 		    <list name='public'>
       
 10367 		      <item type='jid'
       
 10368 		            value='tybalt@example.com'
       
 10369 		            action='deny'
       
 10370 		            order='3'/>
       
 10371 		      <item type='jid'
       
 10372 		            value='paris@example.org'
       
 10373 		            action='deny'
       
 10374 		            order='5'/>
       
 10375 		      <item action='allow' order='68'/>
       
 10376 		    </list>		    
       
 10377   		</query>
       
 10378 	</iq>
       
 10379 	*/
       
 10380 	main_loop = g_main_loop_new ( NULL, FALSE );
       
 10381 	message = lm_message_new_with_sub_type ( NULL,
       
 10382                                          LM_MESSAGE_TYPE_IQ,
       
 10383                                          LM_MESSAGE_SUB_TYPE_SET );
       
 10384     q_node = lm_message_node_add_child ( message->node, "query", NULL );
       
 10385     lm_message_node_set_attribute ( q_node, "xmlns", "jabber:iq:privacy" );
       
 10386     item_node1 = lm_message_node_add_child ( q_node, "list", NULL );
       
 10387     lm_message_node_set_attribute ( item_node1, "name", "publicnewlist" );
       
 10388     item_node2 = lm_message_node_add_child ( item_node1, "item", NULL );
       
 10389     lm_message_node_set_attribute ( item_node2, "type", "jid" );
       
 10390     lm_message_node_set_attribute ( item_node2, "value", "rakesh_harsh@chat.gizmoproject.com" );
       
 10391     lm_message_node_set_attribute ( item_node2, "action", "allow" );
       
 10392     lm_message_node_set_attribute ( item_node2, "order", "10" );
       
 10393     
       
 10394     // Send message to the server
       
 10395 	handler = lm_message_handler_new ( handle_set_privacy_lists, main_loop, NULL );	
       
 10396 	if ( !lm_connection_send_with_reply ( connection, message, handler, NULL ) ) 
       
 10397 	    {
       
 10398 		iLog->Log ( _L ( "lm_connection_send_with_reply in lm_connection_create_one_privacy_listL failed" ) );
       
 10399 		lm_connection_close ( connection, NULL );
       
 10400 		lm_connection_unref ( connection );
       
 10401 		lm_message_unref ( message );
       
 10402 		lm_message_handler_unref(handler);
       
 10403 		free_data ( connect_data );
       
 10404 		g_main_loop_unref ( main_loop );
       
 10405 		return KErrGeneral;
       
 10406 	    }
       
 10407 	g_main_loop_run ( main_loop );
       
 10408 	lm_message_unref ( message );    
       
 10409 	lm_message_handler_unref(handler);
       
 10410 	g_main_loop_unref ( main_loop );
       
 10411 	/*****************************/
       
 10412 	//Now retrieve all the privacy lists and see if it is created
       
 10413 	// Construct a message with type=LM_MESSAGE_TYPE_IQ
       
 10414 	main_loop = g_main_loop_new ( NULL, FALSE );
       
 10415 	message = lm_message_new_with_sub_type ( NULL,
       
 10416                                          LM_MESSAGE_TYPE_IQ,
       
 10417                                          LM_MESSAGE_SUB_TYPE_GET );
       
 10418     q_node = lm_message_node_add_child ( message->node, "query", NULL );
       
 10419     lm_message_node_set_attribute ( q_node, "xmlns", "jabber:iq:privacy" );
       
 10420     // Send message to the server
       
 10421 	handler = lm_message_handler_new ( handle_get_privacy_lists, main_loop, NULL );	
       
 10422 	if ( !lm_connection_send_with_reply ( connection, message, handler, NULL ) ) 
       
 10423 	    {
       
 10424 		iLog->Log ( _L ( "lm_connection_send_with_reply in lm_add_contactL failed" ) );
       
 10425 		lm_connection_close ( connection, NULL );
       
 10426 		lm_connection_unref ( connection );
       
 10427 		lm_message_unref ( message );
       
 10428 		lm_message_handler_unref(handler);
       
 10429 		free_data ( connect_data );
       
 10430 		g_main_loop_unref ( main_loop );
       
 10431 		return KErrGeneral;
       
 10432 	    }
       
 10433 	g_main_loop_run ( main_loop );
       
 10434 	lm_message_unref ( message );    
       
 10435 	lm_message_handler_unref(handler);
       
 10436 	g_main_loop_unref ( main_loop );
       
 10437 	/*******************************/
       
 10438    
       
 10439 	// Close the connection
       
 10440 	lm_connection_close ( connection, NULL );	
       
 10441 	// Remove a reference on connection
       
 10442 	lm_connection_unref ( connection );	
       
 10443 	free_data ( connect_data );	
       
 10444 	// Message sending passed
       
 10445 	iLog->Log ( _L ( "lm_connection_create_one_privacy_listL passed" ) );
       
 10446 	
       
 10447 	return KErrNone;
       
 10448 }
       
 10449 
       
 10450 //--------------------------------------------------------------------------------
       
 10451 // function_name    : handle_get_many_privacy_lists
       
 10452 // description      : callback function to handle messages
       
 10453 // Returns          : LmHandlerResult
       
 10454 //--------------------------------------------------------------------------------
       
 10455 static LmHandlerResult
       
 10456 handle_get_many_privacy_lists ( LmMessageHandler*/* handler*/,
       
 10457                   LmConnection*     /*connection*/,
       
 10458                   LmMessage*        reply,
       
 10459                   gpointer          user_data )
       
 10460     {
       
 10461     GMainLoop *main_loop = ( GMainLoop * )user_data;	
       
 10462 	LmMessageSubType  type;
       
 10463 	LmMessageNode *error_node = NULL;
       
 10464 	LmMessageNode *item_node = NULL;
       
 10465 	type = lm_message_get_sub_type (reply); 
       
 10466     
       
 10467     /*<iq to='romeo@example.net/orchard' type='error/result' id='getlist6'>   	*/
       
 10468 	switch (type) 
       
 10469     	{
       
 10470     	case LM_MESSAGE_SUB_TYPE_RESULT:        		        		
       
 10471     		{
       
 10472     		const char* id;
       
 10473     		id = lm_message_node_get_attribute(reply->node,"id");  
       
 10474     		break;
       
 10475     		}
       
 10476     	case LM_MESSAGE_SUB_TYPE_ERROR:
       
 10477     		{
       
 10478     		/*
       
 10479 		    <iq to='romeo@example.net/orchard' type='error' id='getlist6'>
       
 10480 			    <error type='modify'>
       
 10481 			    	<bad-request xmlns='urn:ietf:params:xml:ns:xmpp-stanzas'/>
       
 10482 			    </error>
       
 10483 		    </iq>
       
 10484 			*/ 	
       
 10485     		error_node = lm_message_node_get_child(reply->node,"error");
       
 10486     		const char* error_code;
       
 10487     		error_code = lm_message_node_get_attribute(error_node,"code");  
       
 10488 			const char* error_type;
       
 10489     		error_type = lm_message_node_get_attribute(error_node,"type");  
       
 10490 			break;
       
 10491     		}
       
 10492     //	default:
       
 10493     	//	g_assert_not_reached ();
       
 10494     	//	break;
       
 10495     	} 
       
 10496 	if ( main_loop )
       
 10497 		{
       
 10498 		g_main_loop_quit ( main_loop );
       
 10499 		}	
       
 10500 	
       
 10501 	return LM_HANDLER_RESULT_REMOVE_MESSAGE;
       
 10502     } 
       
 10503 //-----------------------------------------------------------------------------
       
 10504 // Ctstlm::lm_connection_get_many_privacy_list_from_listnameL
       
 10505 // Description  : Asynchronous call to get more than one privacy list details by 
       
 10506 //				  specifying the name. The server should return error, since we 
       
 10507 //  			  can only retrieve info of one list at a time
       
 10508 // Arguements   :
       
 10509 //   connection	: an LmConnection used to send message
       
 10510 //   message    : LmMessage to send
       
 10511 //   error      : location to store error, or NULL
       
 10512 // Returns      : Returns TRUE if no errors were detected while sending,
       
 10513 //                FALSE otherwise
       
 10514 //-----------------------------------------------------------------------------
       
 10515 // 
       
 10516 TInt Ctstlm::lm_connection_get_many_privacy_list_from_listnameL ( CStifItemParser& aItem )
       
 10517     {
       
 10518 	LmConnection *connection   = NULL;
       
 10519 	ConnectData  *connect_data = NULL;
       
 10520 	LmMessage    *message = NULL;
       
 10521 	LmMessageNode* q_node, *item_node1, *item_node2, *item_node3 = NULL;
       
 10522 	LmMessageHandler *handler = NULL;
       
 10523 	
       
 10524 	iLog->Log ( _L ( "In lm_connection_get_many_privacy_list_from_listname" ) );
       
 10525 	
       
 10526 	// Read a data from the CFG file
       
 10527 	if ( read_data ( connect_data, aItem ) != RC_OK )
       
 10528 		{
       
 10529 		iLog->Log ( _L ( "read_data failed" ) );
       
 10530 		free_data ( connect_data );
       
 10531 		return KErrGeneral;
       
 10532 		}
       
 10533 	iLog->Log ( _L ( "after read_data" ) );
       
 10534 	
       
 10535 	// Open a new closed connection
       
 10536 	connection = lm_connection_new ( connect_data->server );
       
 10537 	iLog->Log ( _L ( "after lm_connection_new " ) );
       
 10538 	if ( !connection )
       
 10539 		{
       
 10540 		iLog->Log ( _L ( "lm_connection_new failed" ) );
       
 10541 		free_data ( connect_data );
       
 10542 		return KErrGeneral;
       
 10543 		}
       
 10544 	
       
 10545 	// Set the gtalk's SSL port
       
 10546 	lm_connection_set_port ( connection, GTALK_SSL_PORT );	
       
 10547 	// Set the JID
       
 10548 	lm_connection_set_jid ( connection, connect_data->username );
       
 10549 	
       
 10550 	// Proxy settings for Emulator
       
 10551 #ifdef __WINSCW__
       
 10552 	SetProxy ( connection, connect_data->proxy_data );
       
 10553 #endif
       
 10554 	
       
 10555 	// Set the connection to use SSL
       
 10556 	SSLInit ( connection );	
       
 10557 	GMainLoop	*main_loop = g_main_loop_new ( NULL, FALSE );
       
 10558 	iLog->Log ( _L ( "before lm_connection_open" ) );	
       
 10559 	if ( !lm_connection_open ( connection, ( LmResultFunction ) connection_open_cb,
       
 10560 	                           main_loop, NULL, NULL ) ) 
       
 10561 	    {
       
 10562 		iLog->Log ( _L ( "lm_connection_open failed" ));
       
 10563 		lm_connection_unref ( connection );
       
 10564 		g_main_loop_unref ( main_loop );
       
 10565 		free_data ( connect_data );		
       
 10566 		return KErrGeneral;
       
 10567 	    }		
       
 10568 	iLog->Log ( _L ( "after lm_connection_open" ) );	
       
 10569 	g_main_loop_run ( main_loop );
       
 10570 	g_main_loop_unref ( main_loop );    
       
 10571 	
       
 10572 	main_loop = g_main_loop_new ( NULL, FALSE );	
       
 10573 	// Get the username from the JID
       
 10574 	gchar *username = get_user_name ( connect_data->username );	
       
 10575 	// Authenticate with the server
       
 10576 	if ( !lm_connection_authenticate ( connection,
       
 10577                                      username,
       
 10578                                      connect_data->password,
       
 10579                                      connect_data->resource,
       
 10580                                       ( LmResultFunction ) connection_auth_cb,
       
 10581                                      main_loop,NULL,NULL ) )
       
 10582 	    {
       
 10583 		iLog->Log ( _L ( "lm_connection_authenticate failed" ) );
       
 10584 		lm_connection_close ( connection, NULL );
       
 10585 		lm_connection_unref ( connection );
       
 10586 		free_data ( connect_data );
       
 10587 		g_main_loop_unref ( main_loop );
       
 10588 		g_free ( username );
       
 10589 		return KErrGeneral;
       
 10590 	    }
       
 10591 	g_main_loop_run ( main_loop );
       
 10592 	g_main_loop_unref ( main_loop );
       
 10593 	g_free ( username );
       
 10594 	
       
 10595 	// Construct a message with type=LM_MESSAGE_TYPE_IQ
       
 10596 	/*
       
 10597 	<iq from='romeo@example.net/orchard' type='get' id='getlist2'>
       
 10598 		  <query xmlns='jabber:iq:privacy'>
       
 10599 		    <list name='public'/>
       
 10600 		    <list name='active'/>
       
 10601 		    <list name='default'/>		    
       
 10602 		  </query>
       
 10603 	</iq>
       
 10604 	*/
       
 10605 	main_loop = g_main_loop_new ( NULL, FALSE );
       
 10606 	message = lm_message_new_with_sub_type ( NULL,
       
 10607                                          LM_MESSAGE_TYPE_IQ,
       
 10608                                          LM_MESSAGE_SUB_TYPE_GET );
       
 10609     q_node = lm_message_node_add_child ( message->node, "query", NULL );
       
 10610     lm_message_node_set_attribute ( q_node, "xmlns", "jabber:iq:privacy" );
       
 10611     item_node1 = lm_message_node_add_child ( q_node, "list", NULL );
       
 10612     lm_message_node_set_attribute ( item_node1, "name", "public" );
       
 10613     item_node2 = lm_message_node_add_child ( q_node, "list", NULL );
       
 10614     lm_message_node_set_attribute ( item_node2, "name", "private" );
       
 10615     item_node3 = lm_message_node_add_child ( q_node, "list", NULL );
       
 10616     lm_message_node_set_attribute ( item_node3, "name", "default" );
       
 10617     
       
 10618     
       
 10619     // Send message to the server
       
 10620 	handler = lm_message_handler_new ( handle_get_many_privacy_lists, main_loop, NULL );	
       
 10621 	if ( !lm_connection_send_with_reply ( connection, message, handler, NULL ) ) 
       
 10622 	    {
       
 10623 		iLog->Log ( _L ( "lm_connection_get_many_privacy_list_from_listname failed" ) );
       
 10624 		lm_connection_close ( connection, NULL );
       
 10625 		lm_connection_unref ( connection );
       
 10626 		lm_message_unref ( message );
       
 10627 		lm_message_handler_unref(handler);
       
 10628 		free_data ( connect_data );
       
 10629 		g_main_loop_unref ( main_loop );
       
 10630 		return KErrGeneral;
       
 10631 	    }
       
 10632 	g_main_loop_run ( main_loop );
       
 10633 	g_main_loop_unref ( main_loop );
       
 10634 	lm_message_unref ( message );    
       
 10635 	lm_message_handler_unref(handler);
       
 10636 
       
 10637    
       
 10638 	// Close the connection
       
 10639 	lm_connection_close ( connection, NULL );	
       
 10640 	// Remove a reference on connection
       
 10641 	lm_connection_unref ( connection );	
       
 10642 	free_data ( connect_data );	
       
 10643 	// Message sending passed
       
 10644 	iLog->Log ( _L ( "lm_connection_get_many_privacy_list_from_listname passed" ) );	
       
 10645 	return KErrNone;
       
 10646 }
       
 10647 
       
 10648 //-----------------------------------------------------------------------------
       
 10649 // Ctstlm::lm_connection_get_one_unexist_privacy_listL
       
 10650 // Description  : Asynchronous call to send a message
       
 10651 // Arguements   :
       
 10652 //   connection	: an LmConnection used to send message
       
 10653 //   message    : LmMessage to send
       
 10654 //   error      : location to store error, or NULL
       
 10655 // Returns      : Returns TRUE if no errors were detected while sending,
       
 10656 //                FALSE otherwise
       
 10657 //-----------------------------------------------------------------------------
       
 10658 // 
       
 10659 TInt Ctstlm::lm_connection_get_one_unexist_privacy_listL ( CStifItemParser& aItem )
       
 10660     {
       
 10661 	LmConnection *connection   = NULL;
       
 10662 	ConnectData  *connect_data = NULL;
       
 10663 	LmMessage    *message = NULL;
       
 10664 	LmMessageNode* q_node, *item_node = NULL;
       
 10665 	LmMessageHandler *handler = NULL;
       
 10666 	
       
 10667 	iLog->Log ( _L ( "In lm_connection_get_one_unexist_privacy_list" ) );
       
 10668 	
       
 10669 	// Read a data from the CFG file
       
 10670 	if ( read_data ( connect_data, aItem ) != RC_OK )
       
 10671 		{
       
 10672 		iLog->Log ( _L ( "read_data failed" ) );
       
 10673 		free_data ( connect_data );
       
 10674 		return KErrGeneral;
       
 10675 		}
       
 10676 	iLog->Log ( _L ( "after read_data" ) );
       
 10677 	
       
 10678 	// Open a new closed connection
       
 10679 	connection = lm_connection_new ( connect_data->server );
       
 10680 	iLog->Log ( _L ( "after lm_connection_new " ) );
       
 10681 	if ( !connection )
       
 10682 		{
       
 10683 		iLog->Log ( _L ( "lm_connection_new failed" ) );
       
 10684 		free_data ( connect_data );
       
 10685 		return KErrGeneral;
       
 10686 		}
       
 10687 	
       
 10688 	// Set the gtalk's SSL port
       
 10689 	lm_connection_set_port ( connection, GTALK_SSL_PORT );	
       
 10690 	// Set the JID
       
 10691 	lm_connection_set_jid ( connection, connect_data->username );
       
 10692 	
       
 10693 	// Proxy settings for Emulator
       
 10694 #ifdef __WINSCW__
       
 10695 	SetProxy ( connection, connect_data->proxy_data );
       
 10696 #endif
       
 10697 	
       
 10698 	// Set the connection to use SSL
       
 10699 	SSLInit ( connection );	
       
 10700 	GMainLoop	*main_loop = g_main_loop_new ( NULL, FALSE );
       
 10701 	iLog->Log ( _L ( "before lm_connection_open" ) );	
       
 10702 	if ( !lm_connection_open ( connection, ( LmResultFunction ) connection_open_cb,
       
 10703 	                           main_loop, NULL, NULL ) ) 
       
 10704 	    {
       
 10705 		iLog->Log ( _L ( "lm_connection_open failed" ));
       
 10706 		lm_connection_unref ( connection );
       
 10707 		g_main_loop_unref ( main_loop );
       
 10708 		free_data ( connect_data );		
       
 10709 		return KErrGeneral;
       
 10710 	    }		
       
 10711 	iLog->Log ( _L ( "after lm_connection_open" ) );	
       
 10712 	g_main_loop_run ( main_loop );
       
 10713 	g_main_loop_unref ( main_loop );    
       
 10714 	
       
 10715 	main_loop = g_main_loop_new ( NULL, FALSE );	
       
 10716 	// Get the username from the JID
       
 10717 	gchar *username = get_user_name ( connect_data->username );	
       
 10718 	// Authenticate with the server
       
 10719 	if ( !lm_connection_authenticate ( connection,
       
 10720                                      username,
       
 10721                                      connect_data->password,
       
 10722                                      connect_data->resource,
       
 10723                                       ( LmResultFunction ) connection_auth_cb,
       
 10724                                      main_loop,NULL,NULL ) )
       
 10725 	    {
       
 10726 		iLog->Log ( _L ( "lm_connection_authenticate failed" ) );
       
 10727 		lm_connection_close ( connection, NULL );
       
 10728 		lm_connection_unref ( connection );
       
 10729 		free_data ( connect_data );
       
 10730 		g_main_loop_unref ( main_loop );
       
 10731 		g_free ( username );
       
 10732 		return KErrGeneral;
       
 10733 	    }
       
 10734 	g_main_loop_run ( main_loop );
       
 10735 	g_main_loop_unref ( main_loop );
       
 10736 	g_free ( username );
       
 10737 	
       
 10738 	// Construct a message with type=LM_MESSAGE_TYPE_IQ
       
 10739 	/*
       
 10740 	<iq from='romeo@example.net/orchard' type='get' id='getlist2'>
       
 10741 		  <query xmlns='jabber:iq:privacy'>
       
 10742 		    <list name='publicunexist'/>
       
 10743 		  </query>
       
 10744 	</iq>
       
 10745 	*/
       
 10746 	main_loop = g_main_loop_new ( NULL, FALSE );
       
 10747 	message = lm_message_new_with_sub_type ( NULL,
       
 10748                                          LM_MESSAGE_TYPE_IQ,
       
 10749                                          LM_MESSAGE_SUB_TYPE_GET );
       
 10750     q_node = lm_message_node_add_child ( message->node, "query", NULL );
       
 10751     lm_message_node_set_attribute ( q_node, "xmlns", "jabber:iq:privacy" );
       
 10752     item_node = lm_message_node_add_child ( q_node, "list", NULL );
       
 10753     lm_message_node_set_attribute ( item_node, "name", "publicunexist" );
       
 10754     
       
 10755     // Send message to the server
       
 10756 	handler = lm_message_handler_new ( handle_get_privacy_lists, main_loop, NULL );	
       
 10757 	if ( !lm_connection_send_with_reply ( connection, message, handler, NULL ) ) 
       
 10758 	    {
       
 10759 		iLog->Log ( _L ( "lm_connection_get_one_unexist_privacy_list failed" ) );
       
 10760 		lm_connection_close ( connection, NULL );
       
 10761 		lm_connection_unref ( connection );
       
 10762 		lm_message_unref ( message );
       
 10763 		lm_message_handler_unref(handler);
       
 10764 		free_data ( connect_data );
       
 10765 		g_main_loop_unref ( main_loop );
       
 10766 		return KErrGeneral;
       
 10767 	    }
       
 10768 	g_main_loop_run ( main_loop );
       
 10769 	g_main_loop_unref ( main_loop );
       
 10770 	lm_message_unref ( message );    
       
 10771 	lm_message_handler_unref(handler);
       
 10772 
       
 10773    
       
 10774 	// Close the connection
       
 10775 	lm_connection_close ( connection, NULL );	
       
 10776 	// Remove a reference on connection
       
 10777 	lm_connection_unref ( connection );	
       
 10778 	free_data ( connect_data );	
       
 10779 	// Message sending passed
       
 10780 	iLog->Log ( _L ( "lm_connection_get_one_unexist_privacy_list passed" ) );	
       
 10781 	return KErrNone;
       
 10782 }
       
 10783 
       
 10784 
       
 10785 //-----------------------------------------------------------------------------
       
 10786 // Ctstlm::lm_connection_set_one_unexist_privacy_listL
       
 10787 // Description  : Asynchronous call to send a message
       
 10788 // Arguements   :
       
 10789 //   connection	: an LmConnection used to send message
       
 10790 //   message    : LmMessage to send
       
 10791 //   error      : location to store error, or NULL
       
 10792 // Returns      : Returns TRUE if no errors were detected while sending,
       
 10793 //                FALSE otherwise
       
 10794 //-----------------------------------------------------------------------------
       
 10795 // 
       
 10796 TInt Ctstlm::lm_connection_set_one_unexist_privacy_listL ( CStifItemParser& aItem )
       
 10797     {
       
 10798 	LmConnection *connection   = NULL;
       
 10799 	ConnectData  *connect_data = NULL;
       
 10800 	LmMessage    *message = NULL;
       
 10801 	LmMessageNode* q_node, *item_node1, *item_node2 = NULL;
       
 10802 	LmMessageHandler *handler = NULL;
       
 10803 	
       
 10804 	iLog->Log ( _L ( "In lm_connection_set_one_unexist_privacy_list" ) );
       
 10805 	
       
 10806 	// Read a data from the CFG file
       
 10807 	if ( read_data ( connect_data, aItem ) != RC_OK )
       
 10808 		{
       
 10809 		iLog->Log ( _L ( "read_data failed" ) );
       
 10810 		free_data ( connect_data );
       
 10811 		return KErrGeneral;
       
 10812 		}
       
 10813 	iLog->Log ( _L ( "after read_data" ) );
       
 10814 	
       
 10815 	// Open a new closed connection
       
 10816 	connection = lm_connection_new ( connect_data->server );
       
 10817 	iLog->Log ( _L ( "after lm_connection_new " ) );
       
 10818 	if ( !connection )
       
 10819 		{
       
 10820 		iLog->Log ( _L ( "lm_connection_new failed" ) );
       
 10821 		free_data ( connect_data );
       
 10822 		return KErrGeneral;
       
 10823 		}
       
 10824 	
       
 10825 	// Set the gtalk's SSL port
       
 10826 	lm_connection_set_port ( connection, GTALK_SSL_PORT );	
       
 10827 	// Set the JID
       
 10828 	lm_connection_set_jid ( connection, connect_data->username );
       
 10829 	
       
 10830 	// Proxy settings for Emulator
       
 10831 #ifdef __WINSCW__
       
 10832 	SetProxy ( connection, connect_data->proxy_data );
       
 10833 #endif
       
 10834 	
       
 10835 	// Set the connection to use SSL
       
 10836 	SSLInit ( connection );	
       
 10837 	GMainLoop	*main_loop = g_main_loop_new ( NULL, FALSE );
       
 10838 	iLog->Log ( _L ( "before lm_connection_open" ) );	
       
 10839 	if ( !lm_connection_open ( connection, ( LmResultFunction ) connection_open_cb,
       
 10840 	                           main_loop, NULL, NULL ) ) 
       
 10841 	    {
       
 10842 		iLog->Log ( _L ( "lm_connection_open failed" ));
       
 10843 		lm_connection_unref ( connection );
       
 10844 		g_main_loop_unref ( main_loop );
       
 10845 		free_data ( connect_data );		
       
 10846 		return KErrGeneral;
       
 10847 	    }		
       
 10848 	iLog->Log ( _L ( "after lm_connection_open" ) );	
       
 10849 	g_main_loop_run ( main_loop );
       
 10850 	g_main_loop_unref ( main_loop );    
       
 10851 	
       
 10852 	main_loop = g_main_loop_new ( NULL, FALSE );	
       
 10853 	// Get the username from the JID
       
 10854 	gchar *username = get_user_name ( connect_data->username );	
       
 10855 	// Authenticate with the server
       
 10856 	if ( !lm_connection_authenticate ( connection,
       
 10857                                      username,
       
 10858                                      connect_data->password,
       
 10859                                      connect_data->resource,
       
 10860                                       ( LmResultFunction ) connection_auth_cb,
       
 10861                                      main_loop,NULL,NULL ) )
       
 10862 	    {
       
 10863 		iLog->Log ( _L ( "lm_connection_authenticate failed" ) );
       
 10864 		lm_connection_close ( connection, NULL );
       
 10865 		lm_connection_unref ( connection );
       
 10866 		free_data ( connect_data );
       
 10867 		g_main_loop_unref ( main_loop );
       
 10868 		g_free ( username );
       
 10869 		return KErrGeneral;
       
 10870 	    }
       
 10871 	g_main_loop_run ( main_loop );
       
 10872 	g_main_loop_unref ( main_loop );
       
 10873 	g_free ( username );
       
 10874 	
       
 10875 // Construct a message with type=LM_MESSAGE_TYPE_IQ
       
 10876 	/*
       
 10877 	<iq from='romeo@example.net/orchard' type='set' id='edit1'>
       
 10878 		<query xmlns='jabber:iq:privacy'>
       
 10879 		    <list name='publicunexist'>
       
 10880 		      <item type='jid'
       
 10881 		            value='tybalt@example.com'
       
 10882 		            action='deny'
       
 10883 		            order='3'/>
       
 10884 		      <item type='jid'
       
 10885 		            value='paris@example.org'
       
 10886 		            action='deny'
       
 10887 		            order='5'/>
       
 10888 		      <item action='allow' order='68'/>
       
 10889 		    </list>
       
 10890   		</query>
       
 10891 	</iq>
       
 10892 	*/
       
 10893 	main_loop = g_main_loop_new ( NULL, FALSE );
       
 10894 	message = lm_message_new_with_sub_type ( NULL,
       
 10895                                          LM_MESSAGE_TYPE_IQ,
       
 10896                                          LM_MESSAGE_SUB_TYPE_SET );
       
 10897     q_node = lm_message_node_add_child ( message->node, "query", NULL );
       
 10898     lm_message_node_set_attribute ( q_node, "xmlns", "jabber:iq:privacy" );
       
 10899     item_node1 = lm_message_node_add_child ( q_node, "list", NULL );
       
 10900     lm_message_node_set_attribute ( item_node1, "name", "publicunexist" );
       
 10901     item_node2 = lm_message_node_add_child ( item_node1, "item", NULL );
       
 10902     lm_message_node_set_attribute ( item_node2, "type", "jid" );
       
 10903     lm_message_node_set_attribute ( item_node2, "value", "rakesh_harsh@chat.gizmoproject.com" );
       
 10904     lm_message_node_set_attribute ( item_node2, "action", "deny" );
       
 10905     lm_message_node_set_attribute ( item_node2, "order", "3" );
       
 10906     
       
 10907     // Send message to the server
       
 10908 	handler = lm_message_handler_new ( handle_set_privacy_lists, main_loop, NULL );	
       
 10909 	if ( !lm_connection_send_with_reply ( connection, message, handler, NULL ) ) 
       
 10910 	    {
       
 10911 		iLog->Log ( _L ( "lm_connection_send_with_reply in lm_add_contactL failed" ) );
       
 10912 		lm_connection_close ( connection, NULL );
       
 10913 		lm_connection_unref ( connection );
       
 10914 		lm_message_unref ( message );
       
 10915 		lm_message_handler_unref(handler);
       
 10916 		free_data ( connect_data );
       
 10917 		g_main_loop_unref ( main_loop );
       
 10918 		return KErrGeneral;
       
 10919 	    }
       
 10920 	g_main_loop_run ( main_loop );
       
 10921 	g_main_loop_unref ( main_loop );
       
 10922 	lm_message_unref ( message );    
       
 10923 	lm_message_handler_unref(handler);
       
 10924 
       
 10925    
       
 10926 	// Close the connection
       
 10927 	lm_connection_close ( connection, NULL );	
       
 10928 	// Remove a reference on connection
       
 10929 	lm_connection_unref ( connection );	
       
 10930 	free_data ( connect_data );	
       
 10931 	// Message sending passed
       
 10932 	iLog->Log ( _L ( "lm_connection_set_one_unexist_privacy_list passed" ) );	
       
 10933 	return KErrNone;
       
 10934 }
       
 10935 
       
 10936 //--------------------------------------------------------------------------------
       
 10937 // function_name    : handle_service_discovery
       
 10938 // description      : callback function to handle messages
       
 10939 // Returns          : LmHandlerResult
       
 10940 //--------------------------------------------------------------------------------
       
 10941 static LmHandlerResult
       
 10942 handle_service_discovery ( LmMessageHandler*/* handler*/,
       
 10943                   LmConnection*     /*connection*/,
       
 10944                   LmMessage*        reply,
       
 10945                   gpointer          user_data )
       
 10946     {
       
 10947     GMainLoop *main_loop = ( GMainLoop * )user_data;	
       
 10948 	LmMessageSubType  type;
       
 10949 	LmMessageNode *q_node = NULL;
       
 10950 	LmMessageNode *item_node = NULL;
       
 10951 	type = lm_message_get_sub_type (reply); 
       
 10952     /*
       
 10953     <iq from='capulet.com' to='juliet@capulet.com/chamber' 
       
 10954 		    type='result' id='disco1'>
       
 10955 		<query xmlns='http://jabber.org/protocol/disco#info'>
       
 10956 		    ...
       
 10957 		    <feature var='urn:xmpp:blocking'/>
       
 10958 		    ...
       
 10959   		</query>
       
 10960 	</iq>
       
 10961     */ 	
       
 10962        	
       
 10963 	switch (type) 
       
 10964     	{
       
 10965     	case LM_MESSAGE_SUB_TYPE_RESULT:        		        		
       
 10966     		{
       
 10967     		const char* reply_string;
       
 10968     		reply_string = lm_message_node_get_attribute(reply->node,"id");  
       
 10969 			break;
       
 10970     		}
       
 10971     	case LM_MESSAGE_SUB_TYPE_ERROR:          	          		
       
 10972     		{
       
 10973     		/*
       
 10974 		    <iq to='romeo@example.net/orchard' type='error' id='getlist6'>
       
 10975 			    <error type='modify'>
       
 10976 			    	<bad-request xmlns='urn:ietf:params:xml:ns:xmpp-stanzas'/>
       
 10977 			    </error>
       
 10978 		    </iq>
       
 10979 			*/ 	
       
 10980     		if (reply->node) 
       
 10981 		    	{
       
 10982 		    	LmMessageNode* error_node = NULL;
       
 10983 		    	error_node = lm_message_node_get_child(reply->node,"error");
       
 10984 	    		const char* error_code;
       
 10985 	    		error_code = lm_message_node_get_attribute(error_node,"code");  
       
 10986 				const char* error_type;
       
 10987 	    		error_type = lm_message_node_get_attribute(error_node,"type");  
       
 10988 				item_node = lm_message_node_get_child (reply->node, "feature-not-implemented");
       
 10989 		    	}
       
 10990 			break;
       
 10991 			}
       
 10992     //	default:
       
 10993     	//	g_assert_not_reached ();
       
 10994     	//	break;
       
 10995     	} 
       
 10996     	
       
 10997     
       
 10998 	if ( main_loop )
       
 10999 		{
       
 11000 		g_main_loop_quit ( main_loop );
       
 11001 		}	
       
 11002 	
       
 11003 	return LM_HANDLER_RESULT_REMOVE_MESSAGE;
       
 11004     }   
       
 11005 //-----------------------------------------------------------------------------
       
 11006 // Ctstlm::lm_service_discoveryL
       
 11007 // Description  : Asynchronous call to send a message
       
 11008 // Arguements   :
       
 11009 //   connection	: an LmConnection used to send message
       
 11010 //   message    : LmMessage to send
       
 11011 //   error      : location to store error, or NULL
       
 11012 // Returns      : Returns TRUE if no errors were detected while sending,
       
 11013 //                FALSE otherwise
       
 11014 //-----------------------------------------------------------------------------
       
 11015 // 
       
 11016 TInt Ctstlm::lm_service_discoveryL ( CStifItemParser& aItem )
       
 11017     {
       
 11018 	LmConnection *connection   = NULL;
       
 11019 	ConnectData  *connect_data = NULL;
       
 11020 	LmMessage    *message;
       
 11021 	LmMessageNode * q_node = NULL;
       
 11022 	LmMessageHandler *handler = NULL;
       
 11023 	iLog->Log ( _L ( "In lm_service_discoveryL" ) );
       
 11024 	
       
 11025 	// Read a data from the CFG file
       
 11026 	if ( read_data ( connect_data, aItem ) != RC_OK )
       
 11027 		{
       
 11028 		iLog->Log ( _L ( "read_data failed" ) );
       
 11029 		free_data ( connect_data );
       
 11030 		return KErrGeneral;
       
 11031 		}
       
 11032 	iLog->Log ( _L ( "after read_data" ) );
       
 11033 	
       
 11034 	// Open a new closed connection
       
 11035 	connection = lm_connection_new ( connect_data->server );
       
 11036 	iLog->Log ( _L ( "after lm_connection_new " ) );
       
 11037 	if ( !connection )
       
 11038 		{
       
 11039 		iLog->Log ( _L ( "lm_connection_new failed" ) );
       
 11040 		free_data ( connect_data );
       
 11041 		return KErrGeneral;
       
 11042 		}
       
 11043 	
       
 11044 	// Set the gtalk's SSL port
       
 11045 	lm_connection_set_port ( connection, GTALK_SSL_PORT );
       
 11046 	
       
 11047 	// Set the JID
       
 11048 	lm_connection_set_jid ( connection, connect_data->username );
       
 11049 	
       
 11050 	// Proxy settings for Emulator
       
 11051 #ifdef __WINSCW__
       
 11052 	SetProxy ( connection, connect_data->proxy_data );
       
 11053 #endif
       
 11054 	
       
 11055 	// Set the connection to use SSL
       
 11056 	SSLInit ( connection );
       
 11057 	
       
 11058 	GMainLoop	*main_loop = g_main_loop_new ( NULL, FALSE );
       
 11059 
       
 11060 	iLog->Log ( _L ( "before lm_connection_open" ) );
       
 11061 	
       
 11062 	if ( !lm_connection_open ( connection, ( LmResultFunction ) connection_open_cb,
       
 11063 	                           main_loop, NULL, NULL ) ) 
       
 11064 	    {
       
 11065 		iLog->Log ( _L ( "lm_connection_open failed" ));
       
 11066 		lm_connection_unref ( connection );
       
 11067 		g_main_loop_unref ( main_loop );
       
 11068 		free_data ( connect_data );		
       
 11069 		return KErrGeneral;
       
 11070 	    }
       
 11071 		
       
 11072 	iLog->Log ( _L ( "after lm_connection_open" ) );
       
 11073 	
       
 11074 	g_main_loop_run ( main_loop );
       
 11075 	g_main_loop_unref ( main_loop );    
       
 11076 	
       
 11077 	main_loop = g_main_loop_new ( NULL, FALSE );
       
 11078 	
       
 11079 	// Get the username from the JID
       
 11080 	gchar *username = get_user_name ( connect_data->username );
       
 11081 	
       
 11082 	// Authenticate with the server
       
 11083 	if ( !lm_connection_authenticate ( connection,
       
 11084                                      username,
       
 11085                                      connect_data->password,
       
 11086                                      connect_data->resource,
       
 11087                                       ( LmResultFunction ) connection_auth_cb,
       
 11088                                      main_loop,NULL,NULL ) )
       
 11089 	    {
       
 11090 		iLog->Log ( _L ( "lm_connection_authenticate failed" ) );
       
 11091 		lm_connection_close ( connection, NULL );
       
 11092 		lm_connection_unref ( connection );
       
 11093 		free_data ( connect_data );
       
 11094 		g_main_loop_unref ( main_loop );
       
 11095 		g_free ( username );
       
 11096 		return KErrGeneral;
       
 11097 	    }
       
 11098 
       
 11099 	g_main_loop_run ( main_loop );
       
 11100 	g_main_loop_unref ( main_loop );	    
       
 11101 	g_free ( username );
       
 11102 	
       
 11103 	// Construct a message
       
 11104 	/*
       
 11105 	<iq from='juliet@capulet.com/chamber' to='capulet.com' type='get' id='disco1'>
       
 11106   		<query xmlns='http://jabber.org/protocol/disco#info'/>
       
 11107 	</iq>
       
 11108 	*/
       
 11109 	main_loop = g_main_loop_new ( NULL, FALSE );
       
 11110 	message = lm_message_new_with_sub_type (connect_data->server,
       
 11111                                          LM_MESSAGE_TYPE_IQ,
       
 11112                                          LM_MESSAGE_SUB_TYPE_GET );
       
 11113     q_node = lm_message_node_add_child ( message->node, "query", NULL );
       
 11114     lm_message_node_set_attribute ( q_node, "xmlns", "http://jabber.org/protocol/disco#info" );
       
 11115     
       
 11116 	// Send message to the server
       
 11117 	handler = lm_message_handler_new ( handle_service_discovery, main_loop, NULL );	
       
 11118 	if ( !lm_connection_send_with_reply ( connection, message, handler, NULL ) ) 
       
 11119 	    {
       
 11120 		iLog->Log ( _L ( "lm_connection_send_with_reply in lm_service_discoveryL failed" ) );
       
 11121 		lm_connection_close ( connection, NULL );
       
 11122 		lm_connection_unref ( connection );
       
 11123 		lm_message_unref ( message );
       
 11124 		lm_message_handler_unref(handler);
       
 11125 		free_data ( connect_data );
       
 11126 		g_main_loop_unref ( main_loop );
       
 11127 		return KErrGeneral;
       
 11128 	    }
       
 11129 	g_main_loop_run ( main_loop );
       
 11130 	g_main_loop_unref ( main_loop );
       
 11131 	lm_message_unref ( message );    
       
 11132 	lm_message_handler_unref(handler);
       
 11133 	
       
 11134 	
       
 11135 	// Close the connection
       
 11136 	lm_connection_close ( connection, NULL );
       
 11137 	// Remove a reference on connection
       
 11138 	lm_connection_unref ( connection );
       
 11139 	free_data ( connect_data );
       
 11140 	
       
 11141 	// Message sending passed
       
 11142 	iLog->Log ( _L ( "lm_service_discoveryL passed" ) );
       
 11143 	
       
 11144 	return KErrNone;
       
 11145 }
       
 11146 
       
 11147 //-----------------------------------------------------------------------------
       
 11148 // Ctstlm::lm_service_discovery_connected_resourceL
       
 11149 // Description  : Asynchronous call to send a message
       
 11150 // Arguements   :
       
 11151 //   connection	: an LmConnection used to send message
       
 11152 //   message    : LmMessage to send
       
 11153 //   error      : location to store error, or NULL
       
 11154 // Returns      : Returns TRUE if no errors were detected while sending,
       
 11155 //                FALSE otherwise
       
 11156 //-----------------------------------------------------------------------------
       
 11157 // 
       
 11158 TInt Ctstlm::lm_service_discovery_connected_resourceL ( CStifItemParser& aItem )
       
 11159     {
       
 11160 	LmConnection *connection   = NULL;
       
 11161 	ConnectData  *connect_data = NULL;
       
 11162 	LmMessage    *message;
       
 11163 	LmMessageNode * q_node = NULL;
       
 11164 	LmMessageHandler *handler = NULL;
       
 11165 	iLog->Log ( _L ( "In lm_service_discovery_connected_resourceL" ) );
       
 11166 	
       
 11167 	// Read a data from the CFG file
       
 11168 	if ( read_data ( connect_data, aItem ) != RC_OK )
       
 11169 		{
       
 11170 		iLog->Log ( _L ( "read_data failed" ) );
       
 11171 		free_data ( connect_data );
       
 11172 		return KErrGeneral;
       
 11173 		}
       
 11174 	iLog->Log ( _L ( "after read_data" ) );
       
 11175 	
       
 11176 	// Open a new closed connection
       
 11177 	connection = lm_connection_new ( connect_data->server );
       
 11178 	iLog->Log ( _L ( "after lm_connection_new " ) );
       
 11179 	if ( !connection )
       
 11180 		{
       
 11181 		iLog->Log ( _L ( "lm_connection_new failed" ) );
       
 11182 		free_data ( connect_data );
       
 11183 		return KErrGeneral;
       
 11184 		}
       
 11185 	
       
 11186 	// Set the gtalk's SSL port
       
 11187 	lm_connection_set_port ( connection, GTALK_SSL_PORT );
       
 11188 	
       
 11189 	// Set the JID
       
 11190 	lm_connection_set_jid ( connection, connect_data->username );
       
 11191 	
       
 11192 	// Proxy settings for Emulator
       
 11193 #ifdef __WINSCW__
       
 11194 	SetProxy ( connection, connect_data->proxy_data );
       
 11195 #endif
       
 11196 	
       
 11197 	// Set the connection to use SSL
       
 11198 	SSLInit ( connection );
       
 11199 	
       
 11200 	GMainLoop	*main_loop = g_main_loop_new ( NULL, FALSE );
       
 11201 
       
 11202 	iLog->Log ( _L ( "before lm_connection_open" ) );
       
 11203 	
       
 11204 	if ( !lm_connection_open ( connection, ( LmResultFunction ) connection_open_cb,
       
 11205 	                           main_loop, NULL, NULL ) ) 
       
 11206 	    {
       
 11207 		iLog->Log ( _L ( "lm_connection_open failed" ));
       
 11208 		lm_connection_unref ( connection );
       
 11209 		g_main_loop_unref ( main_loop );
       
 11210 		free_data ( connect_data );		
       
 11211 		return KErrGeneral;
       
 11212 	    }
       
 11213 		
       
 11214 	iLog->Log ( _L ( "after lm_connection_open" ) );
       
 11215 	
       
 11216 	g_main_loop_run ( main_loop );
       
 11217 
       
 11218 	g_main_loop_unref ( main_loop );    
       
 11219 
       
 11220 	
       
 11221 	main_loop = g_main_loop_new ( NULL, FALSE );
       
 11222 	
       
 11223 	// Get the username from the JID
       
 11224 	gchar *username = get_user_name ( connect_data->username );
       
 11225 	
       
 11226 	// Authenticate with the server
       
 11227 	if ( !lm_connection_authenticate ( connection,
       
 11228                                      username,
       
 11229                                      connect_data->password,
       
 11230                                      connect_data->resource,
       
 11231                                       ( LmResultFunction ) connection_auth_cb,
       
 11232                                      main_loop,NULL,NULL ) )
       
 11233 	    {
       
 11234 		iLog->Log ( _L ( "lm_connection_authenticate failed" ) );
       
 11235 		lm_connection_close ( connection, NULL );
       
 11236 		lm_connection_unref ( connection );
       
 11237 		free_data ( connect_data );
       
 11238 		g_main_loop_unref ( main_loop );
       
 11239 		g_free ( username );
       
 11240 		return KErrGeneral;
       
 11241 	    }
       
 11242 
       
 11243 	g_main_loop_run ( main_loop );
       
 11244 	g_main_loop_unref ( main_loop );	    
       
 11245 	g_free ( username );
       
 11246 	
       
 11247 	// Construct a message
       
 11248 	/*
       
 11249 	<iq from='juliet@capulet.com/chamber' to='capulet.com' type='get' id='disco1'>
       
 11250   		<query xmlns='http://jabber.org/protocol/disco#info'/>
       
 11251 	</iq>
       
 11252 	*/
       
 11253 	main_loop = g_main_loop_new ( NULL, FALSE );
       
 11254 	message = lm_message_new_with_sub_type ("testlmnokia@chat.gizmoproject.com/mytest12345rt17",
       
 11255                                          LM_MESSAGE_TYPE_IQ,
       
 11256                                          LM_MESSAGE_SUB_TYPE_GET );
       
 11257     q_node = lm_message_node_add_child ( message->node, "query", NULL );
       
 11258     lm_message_node_set_attribute ( q_node, "xmlns", "http://jabber.org/protocol/disco#info" );
       
 11259     
       
 11260 	// Send message to the server
       
 11261 	handler = lm_message_handler_new ( handle_service_discovery, main_loop, NULL );	
       
 11262 	if ( !lm_connection_send_with_reply ( connection, message, handler, NULL ) ) 
       
 11263 	    {
       
 11264 		iLog->Log ( _L ( "lm_connection_send_with_reply in lm_add_contactL failed" ) );
       
 11265 		lm_connection_close ( connection, NULL );
       
 11266 		lm_connection_unref ( connection );
       
 11267 		lm_message_unref ( message );
       
 11268 		lm_message_handler_unref(handler);
       
 11269 		free_data ( connect_data );
       
 11270 		g_main_loop_unref ( main_loop );
       
 11271 		return KErrGeneral;
       
 11272 	    }
       
 11273 	g_main_loop_run ( main_loop );
       
 11274 	g_main_loop_unref ( main_loop );
       
 11275 	lm_message_unref ( message );    
       
 11276 	lm_message_handler_unref(handler);
       
 11277 	
       
 11278 	
       
 11279 	// Close the connection
       
 11280 	lm_connection_close ( connection, NULL );
       
 11281 	// Remove a reference on connection
       
 11282 	lm_connection_unref ( connection );	
       
 11283 	free_data ( connect_data );
       
 11284 	
       
 11285 	// Message sending passed
       
 11286 	iLog->Log ( _L ( "lm_service_discovery_connected_resourceL passed" ) );
       
 11287 	
       
 11288 	return KErrNone;
       
 11289 }
       
 11290 
       
 11291 
       
 11292 //--------------------------------------------------------------------------------
       
 11293 // function_name    : handle_simple_communications_blocking
       
 11294 // description      : callback function to handle messages
       
 11295 //					  XEP-0191: Simple Communications Blocking
       
 11296 // Returns          : LmHandlerResult
       
 11297 //--------------------------------------------------------------------------------
       
 11298 static LmHandlerResult
       
 11299 handle_simple_communications_blocking ( LmMessageHandler*/* handler*/,
       
 11300                   LmConnection*     /*connection*/,
       
 11301                   LmMessage*        reply,
       
 11302                   gpointer          user_data )
       
 11303     {
       
 11304     GMainLoop *main_loop = ( GMainLoop * )user_data;	
       
 11305 	LmMessageSubType  type;
       
 11306 	LmMessageNode *q_node = NULL;
       
 11307 	LmMessageNode *item_node = NULL;
       
 11308 	type = lm_message_get_sub_type (reply); 
       
 11309     /*
       
 11310     <iq from='capulet.com' to='juliet@capulet.com/chamber' 
       
 11311 		    type='result' id='disco1'>
       
 11312 		<query xmlns='http://jabber.org/protocol/disco#info'>
       
 11313 		    ...
       
 11314 		    <feature var='urn:xmpp:blocking'/>
       
 11315 		    ...
       
 11316   		</query>
       
 11317 	</iq>
       
 11318     */ 	
       
 11319        	
       
 11320 	switch (type) 
       
 11321     	{
       
 11322     	case LM_MESSAGE_SUB_TYPE_RESULT:        		        		
       
 11323     		{
       
 11324     		const char* reply_string;
       
 11325     		reply_string = lm_message_node_get_attribute(reply->node,"id");  
       
 11326 			break;
       
 11327     		}
       
 11328     	case LM_MESSAGE_SUB_TYPE_ERROR:          	          		
       
 11329     		{
       
 11330     		/*
       
 11331 		    <iq to='romeo@example.net/orchard' type='error' id='getlist6'>
       
 11332 			    <error type='modify'>
       
 11333 			    	<bad-request xmlns='urn:ietf:params:xml:ns:xmpp-stanzas'/>
       
 11334 			    </error>
       
 11335 		    </iq>
       
 11336 			*/ 	
       
 11337     		if (reply->node) 
       
 11338 		    	{
       
 11339 		    	LmMessageNode* error_node = NULL;
       
 11340 		    	error_node = lm_message_node_get_child(reply->node,"error");
       
 11341 	    		const char* error_code;
       
 11342 	    		error_code = lm_message_node_get_attribute(error_node,"code");  
       
 11343 				const char* error_type;
       
 11344 	    		error_type = lm_message_node_get_attribute(error_node,"type");  
       
 11345 				item_node = lm_message_node_get_child (error_node, "feature-not-implemented");
       
 11346 		    	}
       
 11347 			break;
       
 11348 			}
       
 11349     //	default:
       
 11350     	//	g_assert_not_reached ();
       
 11351     	//	break;
       
 11352     	} 
       
 11353     	
       
 11354     
       
 11355 	if ( main_loop )
       
 11356 		{
       
 11357 		g_main_loop_quit ( main_loop );
       
 11358 		}	
       
 11359 	
       
 11360 	return LM_HANDLER_RESULT_REMOVE_MESSAGE;
       
 11361     }   
       
 11362 //-----------------------------------------------------------------------------
       
 11363 // Ctstlm::lm_simple_communications_blockingL
       
 11364 // Description  : Asynchronous call to send a message
       
 11365 //				  XEP-0191: Simple Communications Blocking
       
 11366 //				  Not implemented by Gizmo
       
 11367 // Arguements   :
       
 11368 //   connection	: an LmConnection used to send message
       
 11369 //   message    : LmMessage to send
       
 11370 //   error      : location to store error, or NULL
       
 11371 // Returns      : Returns TRUE if no errors were detected while sending,
       
 11372 //                FALSE otherwise
       
 11373 //-----------------------------------------------------------------------------
       
 11374 // 
       
 11375 TInt Ctstlm::lm_simple_communications_blockingL ( CStifItemParser& aItem )
       
 11376     {
       
 11377 	LmConnection *connection   = NULL;
       
 11378 	ConnectData  *connect_data = NULL;
       
 11379 	LmMessage    *message;
       
 11380 	LmMessageNode * q_node = NULL;
       
 11381 	LmMessageHandler *handler = NULL;
       
 11382 	iLog->Log ( _L ( "In lm_simple_communications_blockingL" ) );
       
 11383 	
       
 11384 	// Read a data from the CFG file
       
 11385 	if ( read_data ( connect_data, aItem ) != RC_OK )
       
 11386 		{
       
 11387 		iLog->Log ( _L ( "read_data failed" ) );
       
 11388 		free_data ( connect_data );
       
 11389 		return KErrGeneral;
       
 11390 		}
       
 11391 	iLog->Log ( _L ( "after read_data" ) );
       
 11392 	
       
 11393 	// Open a new closed connection
       
 11394 	connection = lm_connection_new ( connect_data->server );
       
 11395 	iLog->Log ( _L ( "after lm_connection_new " ) );
       
 11396 	if ( !connection )
       
 11397 		{
       
 11398 		iLog->Log ( _L ( "lm_connection_new failed" ) );
       
 11399 		free_data ( connect_data );
       
 11400 		return KErrGeneral;
       
 11401 		}
       
 11402 	
       
 11403 	// Set the gtalk's SSL port
       
 11404 	lm_connection_set_port ( connection, GTALK_SSL_PORT );
       
 11405 	
       
 11406 	// Set the JID
       
 11407 	lm_connection_set_jid ( connection, connect_data->username );
       
 11408 	
       
 11409 	// Proxy settings for Emulator
       
 11410 #ifdef __WINSCW__
       
 11411 	SetProxy ( connection, connect_data->proxy_data );
       
 11412 #endif
       
 11413 	
       
 11414 	// Set the connection to use SSL
       
 11415 	SSLInit ( connection );
       
 11416 	
       
 11417 	GMainLoop	*main_loop = g_main_loop_new ( NULL, FALSE );
       
 11418 	iLog->Log ( _L ( "before lm_connection_open" ) );
       
 11419 	
       
 11420 	if ( !lm_connection_open ( connection, ( LmResultFunction ) connection_open_cb,
       
 11421 	                           main_loop, NULL, NULL ) ) 
       
 11422 	    {
       
 11423 		iLog->Log ( _L ( "lm_connection_open failed" ));
       
 11424 		lm_connection_unref ( connection );
       
 11425 		g_main_loop_unref ( main_loop );
       
 11426 		free_data ( connect_data );		
       
 11427 		return KErrGeneral;
       
 11428 	    }
       
 11429 		
       
 11430 	iLog->Log ( _L ( "after lm_connection_open" ) );	
       
 11431 	g_main_loop_run ( main_loop );
       
 11432 	g_main_loop_unref ( main_loop );    
       
 11433 	
       
 11434 	main_loop = g_main_loop_new ( NULL, FALSE );	
       
 11435 	// Get the username from the JID
       
 11436 	gchar *username = get_user_name ( connect_data->username );
       
 11437 	
       
 11438 	// Authenticate with the server
       
 11439 	if ( !lm_connection_authenticate ( connection,
       
 11440                                      username,
       
 11441                                      connect_data->password,
       
 11442                                      connect_data->resource,
       
 11443                                       ( LmResultFunction ) connection_auth_cb,
       
 11444                                      main_loop,NULL,NULL ) )
       
 11445 	    {
       
 11446 		iLog->Log ( _L ( "lm_connection_authenticate failed" ) );
       
 11447 		lm_connection_close ( connection, NULL );
       
 11448 		lm_connection_unref ( connection );
       
 11449 		free_data ( connect_data );
       
 11450 		g_main_loop_unref ( main_loop );
       
 11451 		g_free ( username );
       
 11452 		return KErrGeneral;
       
 11453 	    }
       
 11454 
       
 11455 	g_main_loop_run ( main_loop );
       
 11456 	g_main_loop_unref ( main_loop );	    
       
 11457 	g_free ( username );
       
 11458 	
       
 11459 	// Construct a message
       
 11460 	/*
       
 11461 	<iq type='get' id='blocklist1'>
       
 11462   		<blocklist xmlns='urn:xmpp:blocking'/>
       
 11463 	</iq>
       
 11464 	*/
       
 11465 	main_loop = g_main_loop_new ( NULL, FALSE );
       
 11466 	message = lm_message_new_with_sub_type (NULL,
       
 11467                                          LM_MESSAGE_TYPE_IQ,
       
 11468                                          LM_MESSAGE_SUB_TYPE_GET );
       
 11469     q_node = lm_message_node_add_child ( message->node, "blocklist", NULL );
       
 11470     lm_message_node_set_attribute ( q_node, "xmlns", "urn:xmpp:blocking" );
       
 11471     
       
 11472 	// Send message to the server
       
 11473 	handler = lm_message_handler_new ( handle_simple_communications_blocking, main_loop, NULL );	
       
 11474 	if ( !lm_connection_send_with_reply ( connection, message, handler, NULL ) ) 
       
 11475 	    {
       
 11476 		iLog->Log ( _L ( "lm_connection_send_with_reply in lm_simple_communications_blockingL failed" ) );
       
 11477 		lm_connection_close ( connection, NULL );
       
 11478 		lm_connection_unref ( connection );
       
 11479 		lm_message_unref ( message );
       
 11480 		lm_message_handler_unref(handler);
       
 11481 		free_data ( connect_data );
       
 11482 		g_main_loop_unref ( main_loop );
       
 11483 		return KErrGeneral;
       
 11484 	    }
       
 11485 	g_main_loop_run ( main_loop );
       
 11486 	g_main_loop_unref ( main_loop );
       
 11487 	lm_message_unref ( message );    
       
 11488 	lm_message_handler_unref(handler);
       
 11489 	
       
 11490 	
       
 11491 	// Close the connection
       
 11492 	lm_connection_close ( connection, NULL );
       
 11493 	// Remove a reference on connection
       
 11494 	lm_connection_unref ( connection );	
       
 11495 	free_data ( connect_data );	
       
 11496 	// Message sending passed
       
 11497 	iLog->Log ( _L ( "lm_simple_communications_blockingL passed" ) );
       
 11498 	
       
 11499 	return KErrNone;
       
 11500 }
       
 11501 //--------------------------------------------------------------------------------
       
 11502 // function_name    : handle_send_im
       
 11503 // description      : callback function to handle messages
       
 11504 //					  XEP-0191: Simple Communications Blocking
       
 11505 // Returns          : LmHandlerResult
       
 11506 //--------------------------------------------------------------------------------
       
 11507 static LmHandlerResult
       
 11508 handle_send_im ( LmMessageHandler*/* handler*/,
       
 11509                   LmConnection*     /*connection*/,
       
 11510                   LmMessage*        reply,
       
 11511                   gpointer          user_data )
       
 11512     {
       
 11513     GMainLoop *main_loop = ( GMainLoop * )user_data;	
       
 11514 	LmMessageSubType  type;
       
 11515 	LmMessageNode *item_node = NULL;
       
 11516 	type = lm_message_get_sub_type (reply); 
       
 11517    
       
 11518     switch (type) 
       
 11519     	{
       
 11520     	case LM_MESSAGE_SUB_TYPE_RESULT:        		        		
       
 11521     		{
       
 11522     		const char* reply_string;
       
 11523     		reply_string = lm_message_node_get_attribute(reply->node,"id");  
       
 11524 			break;
       
 11525     		}
       
 11526     	case LM_MESSAGE_SUB_TYPE_ERROR:          	          		
       
 11527     		{
       
 11528     		/* //with gizmo
       
 11529 		    <message from='testlmnokia1111@chat.gizmoproject.com' 
       
 11530 		    	to='prima@chat.gizmoproject.com/mytest12345rt' 
       
 11531 				type='error' id='98332763125'>
       
 11532 				 <body>Hello</body>
       
 11533 				<error code='503' type='cancel'>
       
 11534 				<service-unavailable xmlns='urn:ietf:params:xml:ns:xmpp-stanzas'/>
       
 11535 				</error>
       
 11536 			</message>
       
 11537 			*/ 	
       
 11538     		if (reply->node) 
       
 11539 		    	{
       
 11540 		    	LmMessageNode* error_node = NULL;
       
 11541 		    	const char* msg_error_type;
       
 11542 	    		msg_error_type = lm_message_node_get_attribute(reply->node,"type");  
       
 11543 				error_node = lm_message_node_get_child(reply->node,"error");
       
 11544 	    		const char* error_code;
       
 11545 	    		error_code = lm_message_node_get_attribute(error_node,"code");  
       
 11546 				const char* error_type;
       
 11547 	    		error_type = lm_message_node_get_attribute(error_node,"type");  
       
 11548 				item_node = lm_message_node_get_child (error_node, "feature-not-implemented");
       
 11549 				if(item_node == NULL)
       
 11550 					{
       
 11551 					item_node = lm_message_node_get_child (error_node, "service-unavailable");
       
 11552 					}
       
 11553 		    	}
       
 11554 			break;
       
 11555 			}
       
 11556     //	default:
       
 11557     	//	g_assert_not_reached ();
       
 11558     	//	break;
       
 11559     	} 
       
 11560     	
       
 11561     
       
 11562 	if ( main_loop )
       
 11563 		{
       
 11564 		g_main_loop_quit ( main_loop );
       
 11565 		}	
       
 11566 	
       
 11567 	return LM_HANDLER_RESULT_REMOVE_MESSAGE;
       
 11568     } 
       
 11569 //-----------------------------------------------------------------------------
       
 11570 // Ctstlm::lm_send_im_with_replyL
       
 11571 // Description  : Asynchronous call to send a message. Needs a response
       
 11572 // Arguements   :
       
 11573 //   connection	: an LmConnection used to send message
       
 11574 //   message    : LmMessage to send
       
 11575 //   error      : location to store error, or NULL
       
 11576 // Returns      : Returns TRUE if no errors were detected while sending,
       
 11577 //                FALSE otherwise
       
 11578 //-----------------------------------------------------------------------------
       
 11579 // 
       
 11580 TInt Ctstlm::lm_send_im_with_replyL ( CStifItemParser& aItem )
       
 11581     {
       
 11582 	LmConnection *connection   = NULL;
       
 11583 	ConnectData  *connect_data = NULL;
       
 11584 	LmMessage    *message;
       
 11585 	LmMessageHandler *handler = NULL;
       
 11586 	iLog->Log ( _L ( "In lm_send_im_with_replyL" ) );
       
 11587 	
       
 11588 	// Read a data from the CFG file
       
 11589 	if ( read_data ( connect_data, aItem ) != RC_OK )
       
 11590 		{
       
 11591 		iLog->Log ( _L ( "read_data failed" ) );
       
 11592 		free_data ( connect_data );
       
 11593 		return KErrGeneral;
       
 11594 		}
       
 11595 	iLog->Log ( _L ( "after read_data" ) );
       
 11596 	
       
 11597 	// Open a new closed connection
       
 11598 	connection = lm_connection_new ( connect_data->server );
       
 11599 	iLog->Log ( _L ( "after lm_connection_new " ) );
       
 11600 	if ( !connection )
       
 11601 		{
       
 11602 		iLog->Log ( _L ( "lm_connection_new failed" ) );
       
 11603 		free_data ( connect_data );
       
 11604 		return KErrGeneral;
       
 11605 		}
       
 11606 	
       
 11607 	// Set the gtalk's SSL port
       
 11608 	lm_connection_set_port ( connection, GTALK_SSL_PORT );
       
 11609 	
       
 11610 	// Set the JID
       
 11611 	lm_connection_set_jid ( connection, connect_data->username );
       
 11612 	
       
 11613 	// Proxy settings for Emulator
       
 11614 #ifdef __WINSCW__
       
 11615 	SetProxy ( connection, connect_data->proxy_data );
       
 11616 #endif
       
 11617 	
       
 11618 	// Set the connection to use SSL
       
 11619 	SSLInit ( connection );
       
 11620 	
       
 11621 	GMainLoop	*main_loop = g_main_loop_new ( NULL, FALSE );
       
 11622 
       
 11623 	iLog->Log ( _L ( "before lm_connection_open" ) );
       
 11624 	
       
 11625 	if ( !lm_connection_open ( connection, ( LmResultFunction ) connection_open_cb,
       
 11626 	                           main_loop, NULL, NULL ) ) 
       
 11627 	    {
       
 11628 		iLog->Log ( _L ( "lm_connection_open failed" ));
       
 11629 		lm_connection_unref ( connection );
       
 11630 		g_main_loop_unref ( main_loop );
       
 11631 		free_data ( connect_data );		
       
 11632 		return KErrGeneral;
       
 11633 	    }
       
 11634 		
       
 11635 	iLog->Log ( _L ( "after lm_connection_open" ) );	
       
 11636 	g_main_loop_run ( main_loop );
       
 11637 	g_main_loop_unref ( main_loop );    
       
 11638 
       
 11639 	
       
 11640 	main_loop = g_main_loop_new ( NULL, FALSE );	
       
 11641 	// Get the username from the JID
       
 11642 	gchar *username = get_user_name ( connect_data->username );
       
 11643 	
       
 11644 	// Authenticate with the server
       
 11645 	if ( !lm_connection_authenticate ( connection,
       
 11646                                      username,
       
 11647                                      connect_data->password,
       
 11648                                      connect_data->resource,
       
 11649                                       ( LmResultFunction ) connection_auth_cb,
       
 11650                                      main_loop,NULL,NULL ) )
       
 11651 	    {
       
 11652 		iLog->Log ( _L ( "lm_connection_authenticate failed" ) );
       
 11653 		lm_connection_close ( connection, NULL );
       
 11654 		lm_connection_unref ( connection );
       
 11655 		free_data ( connect_data );
       
 11656 		g_main_loop_unref ( main_loop );
       
 11657 		g_free ( username );
       
 11658 		return KErrGeneral;
       
 11659 	    }
       
 11660 	g_main_loop_run ( main_loop );
       
 11661 	g_main_loop_unref ( main_loop );
       
 11662 	g_free ( username );
       
 11663 	
       
 11664 	//------------------------------------------------------------------------
       
 11665 	//Send own presence
       
 11666 //	message = lm_message_new_with_sub_type ( NULL,
       
 11667 //	                                     LM_MESSAGE_TYPE_PRESENCE,
       
 11668 //	                                     LM_MESSAGE_SUB_TYPE_AVAILABLE );
       
 11669 	
       
 11670    // gboolean result = lm_connection_send ( connection, message, NULL );	
       
 11671    	//	lm_message_unref ( message );
       
 11672 	//------------------------------------------------------------------------
       
 11673 	//
       
 11674 	// Register a handler to recieve msgs
       
 11675 	//
       
 11676 	main_loop = g_main_loop_new ( NULL, FALSE );
       
 11677 	
       
 11678 	
       
 11679 	// Construct a message
       
 11680 	message = lm_message_new ( connect_data->msg_data->recipient,               
       
 11681 	                           LM_MESSAGE_TYPE_MESSAGE );
       
 11682 	lm_message_node_add_child ( message->node, "body", 
       
 11683 	                            connect_data->msg_data->message);	
       
 11684 	// Send message to the server
       
 11685 	if ( !lm_connection_send ( connection, message, NULL ) ) 
       
 11686 	    {
       
 11687 		iLog->Log ( _L ( "lm_send_im_with_replyL failed" ) );
       
 11688 		lm_connection_close ( connection, NULL );
       
 11689 		lm_connection_unref ( connection );
       
 11690 		lm_message_unref ( message );
       
 11691 		lm_message_handler_unref(handler);
       
 11692 		g_main_loop_unref ( main_loop );
       
 11693 		free_data ( connect_data );		
       
 11694 		return KErrGeneral;
       
 11695 	    }	
       
 11696 	
       
 11697 	handler = lm_message_handler_new ( 
       
 11698 	                     (LmHandleMessageFunction)handle_send_im,
       
 11699 	                     main_loop,
       
 11700 	                     NULL );
       
 11701 	
       
 11702 	lm_connection_register_message_handler ( connection,
       
 11703 	                                         handler,
       
 11704 	                                         LM_MESSAGE_TYPE_IQ,
       
 11705 	                                         LM_HANDLER_PRIORITY_FIRST );
       
 11706 	g_main_loop_run ( main_loop );
       
 11707 	g_main_loop_unref ( main_loop );
       
 11708 	
       
 11709 	
       
 11710 	
       
 11711 	// Remove a reference on message
       
 11712 	lm_message_unref ( message );
       
 11713 	lm_message_handler_unref(handler);
       
 11714 	// Close the connection
       
 11715 	lm_connection_close ( connection, NULL );
       
 11716 	// Remove a reference on connection
       
 11717 	lm_connection_unref ( connection );
       
 11718 	free_data ( connect_data );
       
 11719 	
       
 11720 	// Message sending passed
       
 11721 	iLog->Log ( _L ( "lm_send_im_with_replyL passed" ) );
       
 11722 	
       
 11723 	return KErrNone;
       
 11724 }
       
 11725 
       
 11726 //-----------------------------------------------------------------------------
       
 11727 // Ctstlm::lm_receive_any_messageL
       
 11728 // Description  : Asynchronous call to send a message
       
 11729 // Arguements   :
       
 11730 //   connection	: an LmConnection used to send message
       
 11731 //   message    : LmMessage to send and receive
       
 11732 //   error      : location to store error, or NULL
       
 11733 // Returns      : Returns TRUE if no errors were detected while sending,
       
 11734 //                FALSE otherwise
       
 11735 //-----------------------------------------------------------------------------
       
 11736 // 
       
 11737 TInt Ctstlm::lm_receive_any_messageL ( CStifItemParser& aItem )
       
 11738     {
       
 11739 	LmConnection *connection   = NULL;
       
 11740 	ConnectData  *connect_data = NULL;
       
 11741 	LmMessage    *message = NULL;
       
 11742 	LmMessageHandler *handler = NULL;
       
 11743 	HandleData *handle_data = NULL;
       
 11744 	
       
 11745 	iLog->Log ( _L ( "In lm_receive_any_message" ) );
       
 11746 	
       
 11747 	// Read a data from the CFG file
       
 11748 	if ( read_data ( connect_data, aItem ) != RC_OK )
       
 11749 		{
       
 11750 		iLog->Log ( _L ( "read_data failed" ) );
       
 11751 		free_data ( connect_data );
       
 11752 		return KErrGeneral;
       
 11753 		}
       
 11754 	iLog->Log ( _L ( "after read_data" ) );
       
 11755 	
       
 11756 	// Open a new closed connection
       
 11757 	connection = lm_connection_new ( connect_data->server );
       
 11758 	iLog->Log ( _L ( "after lm_connection_new " ) );
       
 11759 	if ( !connection )
       
 11760 		{
       
 11761 		iLog->Log ( _L ( "lm_connection_new failed" ) );
       
 11762 		free_data ( connect_data );
       
 11763 		return KErrGeneral;
       
 11764 		}
       
 11765 	
       
 11766 	// Set the gtalk's SSL port
       
 11767 	lm_connection_set_port ( connection, GTALK_SSL_PORT );
       
 11768 	
       
 11769 	// Set the JID
       
 11770 	lm_connection_set_jid ( connection, connect_data->username );
       
 11771 	
       
 11772 	// Proxy settings for Emulator
       
 11773 #ifdef __WINSCW__
       
 11774 	SetProxy ( connection, connect_data->proxy_data );
       
 11775 #endif
       
 11776 	
       
 11777 	// Set the connection to use SSL
       
 11778 	SSLInit ( connection );
       
 11779 	
       
 11780 	GMainLoop	*main_loop = g_main_loop_new ( NULL, FALSE );
       
 11781 	iLog->Log ( _L ( "before lm_connection_open" ) );	
       
 11782 	if ( !lm_connection_open ( connection, ( LmResultFunction ) connection_open_cb,
       
 11783 	                           main_loop, NULL, NULL ) ) 
       
 11784 	    {
       
 11785 		iLog->Log ( _L ( "lm_connection_open failed" ));
       
 11786 		lm_connection_unref ( connection );
       
 11787 		g_main_loop_unref ( main_loop );
       
 11788 		free_data ( connect_data );		
       
 11789 		return KErrGeneral;
       
 11790 	    }
       
 11791 		
       
 11792 	iLog->Log ( _L ( "after lm_connection_open" ) );	
       
 11793 	g_main_loop_run ( main_loop );
       
 11794 	g_main_loop_unref ( main_loop );    
       
 11795 	
       
 11796 	main_loop = g_main_loop_new ( NULL, FALSE );	
       
 11797 	// Get the username from the JID
       
 11798 	gchar *username = get_user_name ( connect_data->username );
       
 11799 	
       
 11800 	// Authenticate with the server
       
 11801 	if ( !lm_connection_authenticate ( connection,
       
 11802                                      username,
       
 11803                                      connect_data->password,
       
 11804                                      connect_data->resource,
       
 11805                                       ( LmResultFunction ) connection_auth_cb,
       
 11806                                      main_loop,NULL,NULL ) )
       
 11807 	    {
       
 11808 		iLog->Log ( _L ( "lm_connection_authenticate failed" ) );
       
 11809 		lm_connection_close ( connection, NULL );
       
 11810 		lm_connection_unref ( connection );
       
 11811 		free_data ( connect_data );
       
 11812 		g_main_loop_unref ( main_loop );
       
 11813 		g_free ( username );
       
 11814 		return KErrGeneral;
       
 11815 	    }
       
 11816 
       
 11817 	g_main_loop_run ( main_loop );
       
 11818 	g_main_loop_unref ( main_loop );
       
 11819 	g_free ( username );
       
 11820 
       
 11821 	//------------------------------------------------------------------------
       
 11822 	//Send own presence
       
 11823 	message = lm_message_new_with_sub_type ( NULL,
       
 11824 	                                     LM_MESSAGE_TYPE_PRESENCE,
       
 11825 	                                     LM_MESSAGE_SUB_TYPE_AVAILABLE );
       
 11826 	
       
 11827     gboolean result = lm_connection_send ( connection, message, NULL );	
       
 11828    	
       
 11829 	//------------------------------------------------------------------------
       
 11830 	//
       
 11831 	// Register a handler to recieve msgs
       
 11832 	//
       
 11833 	main_loop = g_main_loop_new ( NULL, FALSE );
       
 11834 	handler = lm_message_handler_new ( 
       
 11835 	                     (LmHandleMessageFunction)handle_messages,
       
 11836 	                     main_loop,
       
 11837 	                     NULL );
       
 11838 	
       
 11839 	lm_connection_register_message_handler ( connection,
       
 11840 	                                         handler,
       
 11841 	                                         LM_MESSAGE_TYPE_MESSAGE,
       
 11842 	                                         LM_HANDLER_PRIORITY_FIRST );
       
 11843 	
       
 11844 	g_main_loop_run ( main_loop );
       
 11845 	g_main_loop_unref ( main_loop );
       
 11846 	//------------------------------------------------------------------------
       
 11847 	lm_message_unref(message);
       
 11848 	lm_message_handler_unref(handler);
       
 11849 	// Close the connection
       
 11850 	lm_connection_close ( connection, NULL );	
       
 11851 	// Remove a reference on connection
       
 11852 	lm_connection_unref ( connection );		
       
 11853 	free_data ( connect_data );
       
 11854 	
       
 11855 	// Message sending passed
       
 11856 	iLog->Log ( _L ( "lm_connection_send passed" ) );
       
 11857 	
       
 11858 	return KErrNone;
       
 11859 }
       
 11860 
       
 11861 //--------------------------------------------------------------------------------
       
 11862 // function_name    : handle_multiple_session_messages
       
 11863 // description      : callback function to handle messages
       
 11864 // Returns          : LmHandlerResult
       
 11865 //--------------------------------------------------------------------------------
       
 11866 static LmHandlerResult
       
 11867 handle_multiple_session_messages ( LmMessageHandler* /*handler*/,
       
 11868                   LmConnection*     /*connection*/,
       
 11869                   LmMessage*        reply,
       
 11870                   gpointer          user_data )
       
 11871     {
       
 11872     HandleData *handle_data = ( HandleData * )user_data;	
       
 11873 	
       
 11874 	if ( handle_data )
       
 11875 		{
       
 11876 		handle_data->Test_Success = RC_OK;
       
 11877 		LmMessageSubType  type;
       
 11878 		LmMessageNode *q_node = NULL;
       
 11879 		LmMessageNode *item_node = NULL;
       
 11880 		type = lm_message_get_sub_type (reply); 
       
 11881 	       	
       
 11882 		switch (type) 
       
 11883 	    	{
       
 11884 	    	case LM_MESSAGE_SUB_TYPE_RESULT:        		        		
       
 11885 	    		{
       
 11886 	    		const char* reply_string;
       
 11887 	    		reply_string = lm_message_node_get_attribute(reply->node,"id");  
       
 11888 				break;
       
 11889 	    		}
       
 11890 	    	case LM_MESSAGE_SUB_TYPE_ERROR:          	          		
       
 11891 	    		{
       
 11892 	    		if (q_node) 
       
 11893 			    	{
       
 11894 			    	LmMessageNode* error_node = NULL;
       
 11895 			    	error_node = lm_message_node_get_child(reply->node,"error");
       
 11896 		    		const char* error_code;
       
 11897 		    		error_code = lm_message_node_get_attribute(error_node,"code");  
       
 11898 					const char* error_type;
       
 11899 		    		error_type = lm_message_node_get_attribute(error_node,"type");  
       
 11900 					item_node = lm_message_node_get_child (q_node, "feature-not-implemented");
       
 11901 			    	}
       
 11902 				break;
       
 11903 				}
       
 11904 	    //	default:
       
 11905 	    	//	g_assert_not_reached ();
       
 11906 	    	//	break;
       
 11907 	    	} 
       
 11908     	
       
 11909 	
       
 11910 	    g_main_loop_quit ( handle_data->main_loop );
       
 11911 		}	
       
 11912 	
       
 11913 	return LM_HANDLER_RESULT_REMOVE_MESSAGE;
       
 11914     }
       
 11915 
       
 11916 //-----------------------------------------------------------------------------
       
 11917 // Ctstlm::lm_login_multiple_sessionsL
       
 11918 // Description  : Asynchronous call to send a message
       
 11919 // Arguements   :
       
 11920 //   connection	: an LmConnection used to send message
       
 11921 //   message    : LmMessage to send and receive
       
 11922 //   error      : location to store error, or NULL
       
 11923 // Returns      : Returns TRUE if no errors were detected while sending,
       
 11924 //                FALSE otherwise
       
 11925 //-----------------------------------------------------------------------------
       
 11926 // 
       
 11927 TInt Ctstlm::lm_login_multiple_sessionsL ( CStifItemParser& aItem )
       
 11928     {
       
 11929 	LmConnection *connection1  = NULL;
       
 11930 	LmConnection *connection2  = NULL;
       
 11931 	ConnectData  *connect_data = NULL;
       
 11932 	LmMessage    *message = NULL;
       
 11933 	LmMessageHandler *handler1 = NULL;
       
 11934 	LmMessageHandler *handler2 = NULL;
       
 11935 	HandleData *handle_data = NULL;
       
 11936 	
       
 11937 	iLog->Log ( _L ( "In lm_receive_any_message" ) );
       
 11938 	
       
 11939 	// Read a data from the CFG file
       
 11940 	if ( read_data ( connect_data, aItem ) != RC_OK )
       
 11941 		{
       
 11942 		iLog->Log ( _L ( "read_data failed" ) );
       
 11943 		free_data ( connect_data );
       
 11944 		return KErrGeneral;
       
 11945 		}
       
 11946 	iLog->Log ( _L ( "after read_data" ) );
       
 11947 	
       
 11948 	// Open a new closed connection
       
 11949 	connection1 = lm_connection_new ( connect_data->server );
       
 11950 	connection2 = lm_connection_new ( connect_data->server );
       
 11951 	iLog->Log ( _L ( "after lm_connection_new " ) );
       
 11952 	if ( !connection1 || !connection2 )
       
 11953 		{
       
 11954 		iLog->Log ( _L ( "lm_connection_new failed" ) );
       
 11955 		free_data ( connect_data );
       
 11956 		return KErrGeneral;
       
 11957 		}
       
 11958 	
       
 11959 	// Set the gtalk's SSL port and Set the JID
       
 11960 	lm_connection_set_port ( connection1, GTALK_SSL_PORT );
       
 11961 	lm_connection_set_jid ( connection1, connect_data->username );
       
 11962 	lm_connection_set_port ( connection2, GTALK_SSL_PORT );
       
 11963 	lm_connection_set_jid ( connection2, connect_data->username );
       
 11964 	
       
 11965 	// Proxy settings for Emulator
       
 11966 #ifdef __WINSCW__
       
 11967 	SetProxy ( connection1, connect_data->proxy_data );
       
 11968 	SetProxy ( connection2, connect_data->proxy_data );
       
 11969 #endif
       
 11970 	
       
 11971 	// Set the connection to use SSL
       
 11972 	SSLInit ( connection1 );
       
 11973 	SSLInit ( connection2 );
       
 11974 	/*********************************************************/
       
 11975 	//Login with connection1	
       
 11976 	GMainLoop	*main_loop = g_main_loop_new ( NULL, FALSE );
       
 11977 	iLog->Log ( _L ( "before lm_connection_open" ) );	
       
 11978 	if ( !lm_connection_open ( connection1, ( LmResultFunction ) connection_open_cb,
       
 11979 	                           main_loop, NULL, NULL ) ) 
       
 11980 	    {
       
 11981 		iLog->Log ( _L ( "lm_connection_open failed" ));
       
 11982 		lm_connection_unref ( connection1 );
       
 11983 		g_main_loop_unref ( main_loop );
       
 11984 		free_data ( connect_data );		
       
 11985 		return KErrGeneral;
       
 11986 	    }
       
 11987 	iLog->Log ( _L ( "after lm_connection_open" ) );	
       
 11988 	g_main_loop_run ( main_loop );
       
 11989 	g_main_loop_unref ( main_loop );    	
       
 11990 	main_loop = g_main_loop_new ( NULL, FALSE );	
       
 11991 	// Get the username from the JID
       
 11992 	gchar *username = get_user_name ( connect_data->username );	
       
 11993 	// Authenticate with the server
       
 11994 	if ( !lm_connection_authenticate ( connection1,
       
 11995                                      username,
       
 11996                                      connect_data->password,
       
 11997                                      connect_data->resource,
       
 11998                                       ( LmResultFunction ) connection_auth_cb,
       
 11999                                      main_loop,NULL,NULL ) )
       
 12000 	    {
       
 12001 		iLog->Log ( _L ( "lm_connection_authenticate failed" ) );
       
 12002 		lm_connection_close ( connection1, NULL );
       
 12003 		lm_connection_unref ( connection1 );
       
 12004 		free_data ( connect_data );
       
 12005 		g_main_loop_unref ( main_loop );
       
 12006 		g_free ( username );
       
 12007 		return KErrGeneral;
       
 12008 	    }
       
 12009 	g_main_loop_run ( main_loop );
       
 12010 	g_main_loop_unref ( main_loop );
       
 12011 	//Send own presence
       
 12012 	message = lm_message_new_with_sub_type ( NULL,
       
 12013 	                                     LM_MESSAGE_TYPE_PRESENCE,
       
 12014 	                                     LM_MESSAGE_SUB_TYPE_AVAILABLE );
       
 12015     gboolean result = lm_connection_send ( connection1, message, NULL );	
       
 12016 	
       
 12017 	//Dont unref message here. It will be used to send agn .
       
 12018 	//lm_message_unref(message);
       
 12019 
       
 12020 
       
 12021 	// Register a handler to recieve msgs
       
 12022 	main_loop = g_main_loop_new ( NULL, FALSE );
       
 12023 	handler1 = lm_message_handler_new ( 
       
 12024 	                     (LmHandleMessageFunction)handle_multiple_session_messages,
       
 12025 	                     main_loop,
       
 12026 	                     NULL );
       
 12027 	lm_connection_register_message_handler ( connection1,
       
 12028 	                                         handler1,
       
 12029 	                                         LM_MESSAGE_TYPE_MESSAGE,
       
 12030 	                                         LM_HANDLER_PRIORITY_FIRST );	
       
 12031 	/*********************************************************/
       
 12032 	//Login with CONNECTION2
       
 12033 	GMainLoop* main_loop1 = g_main_loop_new ( NULL, FALSE );
       
 12034 	iLog->Log ( _L ( "before lm_connection_open" ) );	
       
 12035 	if ( !lm_connection_open ( connection2, ( LmResultFunction ) connection_open_cb,
       
 12036 	                           main_loop1, NULL, NULL ) ) 
       
 12037 	    {
       
 12038 		iLog->Log ( _L ( "lm_connection_open failed" ));
       
 12039 		lm_connection_unref ( connection2 );
       
 12040 		g_main_loop_unref ( main_loop1 );
       
 12041 		free_data ( connect_data );		
       
 12042 		return KErrGeneral;
       
 12043 	    }
       
 12044 	iLog->Log ( _L ( "after lm_connection_open" ) );	
       
 12045 	g_main_loop_run ( main_loop1 );
       
 12046 	g_main_loop_unref ( main_loop1 );    	
       
 12047 	main_loop1 = g_main_loop_new ( NULL, FALSE );	
       
 12048 	// Authenticate with the server
       
 12049 	if ( !lm_connection_authenticate ( connection2,
       
 12050                                      username,
       
 12051                                      connect_data->password,
       
 12052                                      connect_data->resource,
       
 12053                                       ( LmResultFunction ) connection_auth_cb,
       
 12054                                      main_loop1,NULL,NULL ) )
       
 12055 	    {
       
 12056 		iLog->Log ( _L ( "lm_connection_authenticate failed" ) );
       
 12057 		lm_connection_close ( connection2, NULL );
       
 12058 		lm_connection_unref ( connection2 );
       
 12059 		free_data ( connect_data );
       
 12060 		g_main_loop_unref ( main_loop1 );
       
 12061 		g_free ( username );
       
 12062 		return KErrGeneral;
       
 12063 	    }
       
 12064 	g_main_loop_run ( main_loop1 );
       
 12065 	g_main_loop_unref ( main_loop1 );
       
 12066 	g_free ( username );
       
 12067 	//Send own presence
       
 12068 	result = lm_connection_send ( connection2, message, NULL );	
       
 12069 	lm_message_unref(message);
       
 12070 	/*********************************************************/
       
 12071 	// Conn2 should have logged out. Send message should not work.	
       
 12072 	// Construct a message
       
 12073 //	main_loop1 = g_main_loop_new ( NULL, FALSE );
       
 12074 	message = lm_message_new ( connect_data->msg_data->recipient,               
       
 12075 	                           LM_MESSAGE_TYPE_MESSAGE );
       
 12076 	lm_message_node_add_child ( message->node, "body", 
       
 12077 	                            connect_data->msg_data->message);	
       
 12078 	// Send message to the server
       
 12079 	handler2 = lm_message_handler_new ( handle_send_im, main_loop, NULL );	
       
 12080 	if ( !lm_connection_send_with_reply ( connection1, message, handler2, NULL ) ) 
       
 12081 	    {
       
 12082 		iLog->Log ( _L ( "lm_send_im_with_replyL failed" ) );
       
 12083 		lm_connection_close ( connection1, NULL );
       
 12084 		lm_connection_unref ( connection1 );
       
 12085 		g_main_loop_unref ( main_loop );
       
 12086 		lm_message_unref ( message );
       
 12087 		free_data ( connect_data );		
       
 12088 		return KErrGeneral;
       
 12089 	    }	
       
 12090 	
       
 12091 	g_main_loop_run ( main_loop );
       
 12092 	g_main_loop_unref ( main_loop );
       
 12093 	lm_message_unref(message);
       
 12094 	lm_message_handler_unref(handler2);
       
 12095 
       
 12096 	/***********************************************************/
       
 12097 	//Run the registered main loop for logout callbacks
       
 12098 	g_main_loop_run ( main_loop );
       
 12099 	g_main_loop_unref ( main_loop );
       
 12100 	
       
 12101 
       
 12102 	// Close the connection
       
 12103 	lm_connection_close ( connection1, NULL );
       
 12104 	// Remove a reference on connection
       
 12105 	lm_connection_unref ( connection1 );
       
 12106 	
       
 12107 	// Close the connection
       
 12108 	lm_connection_close ( connection2, NULL );
       
 12109 	// Remove a reference on connection
       
 12110 	lm_connection_unref ( connection2 );
       
 12111 		
       
 12112 	free_data ( connect_data );
       
 12113 	
       
 12114 	// Message sending passed
       
 12115 	iLog->Log ( _L ( "lm_connection_send passed" ) );
       
 12116 	
       
 12117 	return KErrNone;
       
 12118 }
       
 12119 
       
 12120 //-----------------------------------------------------------------------------
       
 12121 // Ctstlm::lm_change_own_presenceL
       
 12122 // Description  : Changing own presence information
       
 12123 // Arguements   :
       
 12124 //   connection	: 
       
 12125 //   message    : 
       
 12126 //   error      : 
       
 12127 // Returns      : 
       
 12128 //-----------------------------------------------------------------------------
       
 12129 // 
       
 12130 TInt Ctstlm::lm_change_own_presenceL ( CStifItemParser& aItem )
       
 12131     {
       
 12132 	LmConnection *connection   = NULL;
       
 12133 	ConnectData  *connect_data = NULL;
       
 12134 	LmMessage    *message = NULL;
       
 12135 	LmMessageNode *show_node = NULL;
       
 12136     LmMessageNode *status_node = NULL;
       
 12137     LmMessageHandler *handler = NULL;
       
 12138     GMainLoop    *main_loop    = NULL;
       
 12139 	
       
 12140 	iLog->Log ( _L ( "In lm_change_own_presenceL" ) );
       
 12141 	
       
 12142 	// Read a data from the CFG file
       
 12143 	if ( read_data ( connect_data, aItem ) != RC_OK )
       
 12144 		{
       
 12145 		iLog->Log ( _L ( "read_data failed" ) );
       
 12146 		free_data ( connect_data );
       
 12147 		return KErrGeneral;
       
 12148 		}
       
 12149 	
       
 12150 	// Open a new closed connection
       
 12151 	connection = lm_connection_new ( connect_data->server );
       
 12152 	if ( !connection )
       
 12153 		{
       
 12154 		iLog->Log ( _L ( "lm_connection_new failed" ) );
       
 12155 		free_data ( connect_data );
       
 12156 		return KErrGeneral;
       
 12157 		}
       
 12158 	
       
 12159 	// Set the gtalk's SSL port
       
 12160 	lm_connection_set_port ( connection, GTALK_SSL_PORT );
       
 12161 	
       
 12162 	// Set the JID
       
 12163 	lm_connection_set_jid ( connection, connect_data->username );
       
 12164 	
       
 12165 	// Proxy settings for Emulator
       
 12166 #ifdef __WINSCW__
       
 12167 	SetProxy ( connection, connect_data->proxy_data );
       
 12168 #endif
       
 12169 	
       
 12170 	// Set the connection to use SSL
       
 12171 	SSLInit ( connection );
       
 12172 	
       
 12173 	
       
 12174 	main_loop = g_main_loop_new ( NULL, FALSE );
       
 12175 	
       
 12176 	if ( !lm_connection_open ( connection, ( LmResultFunction ) connection_open_cb,
       
 12177 	                           main_loop, NULL, NULL ) ) 
       
 12178 	    {
       
 12179 		iLog->Log ( _L ( "lm_connection_open failed" ));
       
 12180 		lm_connection_unref ( connection );
       
 12181 		g_main_loop_unref ( main_loop );
       
 12182 		free_data ( connect_data );		
       
 12183 		return KErrGeneral;
       
 12184 	    }
       
 12185 		
       
 12186 	
       
 12187 	g_main_loop_run ( main_loop );
       
 12188 
       
 12189 	g_main_loop_unref ( main_loop );    
       
 12190 
       
 12191 	main_loop = g_main_loop_new ( NULL, FALSE );
       
 12192 	
       
 12193 	// Get the username from the JID
       
 12194 	gchar *username = get_user_name ( connect_data->username );
       
 12195 	
       
 12196 	// Authenticate with the server
       
 12197 	if ( !lm_connection_authenticate ( connection,
       
 12198                                      username,
       
 12199                                      connect_data->password,
       
 12200                                      connect_data->resource,
       
 12201                                       ( LmResultFunction ) connection_auth_cb,
       
 12202                                      main_loop,NULL,NULL ) )
       
 12203 	    {
       
 12204 		iLog->Log ( _L ( "lm_connection_authenticate failed" ) );
       
 12205 		lm_connection_close ( connection, NULL );
       
 12206 		lm_connection_unref ( connection );
       
 12207 		free_data ( connect_data );
       
 12208 		g_main_loop_unref ( main_loop );
       
 12209 		g_free ( username );
       
 12210 		return KErrGeneral;
       
 12211 	    }
       
 12212 	g_main_loop_run ( main_loop );
       
 12213 	g_main_loop_unref ( main_loop );    
       
 12214 	g_free ( username );
       
 12215 	
       
 12216 	/*
       
 12217 	<presence xml:lang='en'>
       
 12218   		<show>dnd</show>
       
 12219   		<status>Wooing Juliet</status>
       
 12220   		<status xml:lang='cz'>Ja dvo&#x0159;&#x00ED;m Juliet</status>
       
 12221 	</presence>
       
 12222 	*/
       
 12223 
       
 12224 	//publish own presence
       
 12225 	message = lm_message_new_with_sub_type ( NULL,
       
 12226 	                                     LM_MESSAGE_TYPE_PRESENCE,
       
 12227 	                                     LM_MESSAGE_SUB_TYPE_AVAILABLE );
       
 12228 	gboolean result = lm_connection_send ( connection, message, NULL );	
       
 12229 	//lm_connection_send_with_reply(
       
 12230 	// Remove a reference on message
       
 12231 	lm_message_unref ( message );	
       
 12232 
       
 12233 	//------------------------------------------------------------------------
       
 12234 	//
       
 12235 	// Register a handler to recieve and update presence information
       
 12236 	//
       
 12237 	main_loop = g_main_loop_new ( NULL, FALSE );
       
 12238 		
       
 12239 	handler = lm_message_handler_new ( 
       
 12240 	                     (LmHandleMessageFunction)jabber_presence_handler_cb,
       
 12241 	                     main_loop,
       
 12242 	                     NULL );
       
 12243 	
       
 12244 	lm_connection_register_message_handler ( connection,
       
 12245 	                                         handler,
       
 12246 	                                         LM_MESSAGE_TYPE_PRESENCE,
       
 12247 	                                         LM_HANDLER_PRIORITY_NORMAL );
       
 12248 	
       
 12249 	g_main_loop_run ( main_loop );	
       
 12250 	g_main_loop_unref ( main_loop );
       
 12251 	lm_message_handler_unref(handler);
       
 12252 	//------------------------------------------------------------------------
       
 12253 	
       
 12254 	
       
 12255  	
       
 12256    	//Change presence again
       
 12257    	message = lm_message_new_with_sub_type ( NULL,
       
 12258 	                                     LM_MESSAGE_TYPE_PRESENCE,
       
 12259 	                                     LM_MESSAGE_SUB_TYPE_AVAILABLE );
       
 12260 	lm_message_node_set_attributes ( message->node, "xml:lang", "en", NULL ); 
       
 12261 	show_node = lm_message_node_add_child ( message->node, "show", "busy" );
       
 12262 	status_node = lm_message_node_add_child ( message->node, "status", "goal goal goal" );
       
 12263 	result = lm_connection_send ( connection, message, NULL );	
       
 12264 	// Remove a reference on message
       
 12265 	lm_message_unref ( message );	
       
 12266    	
       
 12267    	//Change presence again
       
 12268    	message = lm_message_new_with_sub_type ( NULL,
       
 12269 	                                     LM_MESSAGE_TYPE_PRESENCE,
       
 12270 	                                     LM_MESSAGE_SUB_TYPE_AVAILABLE );
       
 12271 	lm_message_node_set_attributes ( message->node, "xml:lang", "en", NULL ); 
       
 12272 	show_node = lm_message_node_add_child ( message->node, "show", "away" );
       
 12273 	status_node = lm_message_node_add_child ( message->node, "status", "imagine a world without nokia!" );
       
 12274 	result = lm_connection_send ( connection, message, NULL );	
       
 12275 	// Remove a reference on message
       
 12276 	lm_message_unref ( message );	
       
 12277    	
       
 12278    	//Change presence again
       
 12279    	message = lm_message_new_with_sub_type ( NULL,
       
 12280 	                                     LM_MESSAGE_TYPE_PRESENCE,
       
 12281 	                                     LM_MESSAGE_SUB_TYPE_AVAILABLE );
       
 12282 	lm_message_node_set_attributes ( message->node, "xml:lang", "en", NULL ); 
       
 12283 	show_node = lm_message_node_add_child ( message->node, "show", "available" );
       
 12284 	status_node = lm_message_node_add_child ( message->node, "status", "there comes a time..." );
       
 12285 	result = lm_connection_send ( connection, message, NULL );	
       
 12286 	// Remove a reference on message
       
 12287 	lm_message_unref ( message );
       
 12288 	
       
 12289 	
       
 12290 	lm_connection_close ( connection, NULL );	
       
 12291 	// Remove a reference on connection
       
 12292 	lm_connection_unref ( connection );	
       
 12293 	free_data ( connect_data );
       
 12294 	// Message sending passed
       
 12295 	iLog->Log ( _L ( "lm_fetching_presenceL passed" ) );
       
 12296 	
       
 12297 	return KErrNone;
       
 12298     }
       
 12299     
       
 12300 //-----------------------------------------------------------------------------
       
 12301 // Ctstlm::lm_login_test_invalid_settingsL
       
 12302 // Description  : Asynchronous call to send a message
       
 12303 // Arguements   :
       
 12304 //   connection	: an LmConnection used to send message
       
 12305 //   message    : LmMessage to send
       
 12306 //   error      : location to store error, or NULL
       
 12307 // Returns      : Returns TRUE if no errors were detected while sending,
       
 12308 //                FALSE otherwise
       
 12309 //-----------------------------------------------------------------------------
       
 12310 // 
       
 12311 TInt Ctstlm::lm_login_test_invalid_portL ( CStifItemParser& aItem )
       
 12312     {
       
 12313 	LmConnection *connection   = NULL;
       
 12314 	ConnectData  *connect_data = NULL;
       
 12315 	
       
 12316 	
       
 12317 	iLog->Log ( _L ( "In lm_login_test_invalid_portL" ) );
       
 12318 	// Read a data from the CFG file
       
 12319 	if ( read_data ( connect_data, aItem ) != RC_OK )
       
 12320 		{
       
 12321 		iLog->Log ( _L ( "read_data failed" ) );
       
 12322 		free_data ( connect_data );
       
 12323 		return KErrGeneral;
       
 12324 		}
       
 12325 	iLog->Log ( _L ( "after read_data" ) );
       
 12326 	
       
 12327 	// Open a new closed connection
       
 12328 	connection = lm_connection_new ( connect_data->server );
       
 12329 	iLog->Log ( _L ( "after lm_connection_new " ) );
       
 12330 	if ( !connection )
       
 12331 		{
       
 12332 		iLog->Log ( _L ( "lm_connection_new failed" ) );
       
 12333 		free_data ( connect_data );
       
 12334 		return KErrGeneral;
       
 12335 		}
       
 12336 	
       
 12337 	// Set the gtalk's SSL port
       
 12338 	lm_connection_set_port ( connection, SSL_INVALID_PORT );
       
 12339 	
       
 12340 	// Set the JID
       
 12341 	lm_connection_set_jid ( connection, connect_data->username );
       
 12342 	
       
 12343 	// Proxy settings for Emulator
       
 12344 #ifdef __WINSCW__
       
 12345 	SetProxy ( connection, connect_data->proxy_data );
       
 12346 #endif
       
 12347 	
       
 12348 	// Set the connection to use SSL
       
 12349 	SSLInit ( connection );
       
 12350 	
       
 12351 	GMainLoop* main_loop = g_main_loop_new ( NULL, FALSE );
       
 12352 
       
 12353 	iLog->Log ( _L ( "before lm_connection_open" ) );
       
 12354 	
       
 12355 	if ( !lm_connection_open ( connection, ( LmResultFunction ) connection_open_cb,
       
 12356 	                           main_loop, NULL, NULL ) ) 
       
 12357 	    {
       
 12358 		iLog->Log ( _L ( "lm_connection_open failed" ));
       
 12359 		lm_connection_unref ( connection );
       
 12360 		g_main_loop_unref ( main_loop );
       
 12361 		free_data ( connect_data );		
       
 12362 		return KErrGeneral;
       
 12363 	    }
       
 12364 		
       
 12365 	iLog->Log ( _L ( "after lm_connection_open" ) );
       
 12366 	
       
 12367 	g_main_loop_run ( main_loop );
       
 12368 
       
 12369 	g_main_loop_unref ( main_loop );    
       
 12370 
       
 12371 	// Close the connection
       
 12372 	lm_connection_close ( connection, NULL );	
       
 12373 	// Remove a reference on connection
       
 12374 	lm_connection_unref ( connection );
       
 12375 	free_data ( connect_data );
       
 12376 	iLog->Log ( _L ( "lm_login_test_invalid_port: Invalid settings is handled correctly" ) );
       
 12377 	return KErrNone;
       
 12378 }   
       
 12379   
       
 12380 //-----------------------------------------------------------------------------
       
 12381 // Ctstlm:: lm_login_test_invalid_serverL
       
 12382 // Description  : Asynchronous call to send a message
       
 12383 // Arguements   :
       
 12384 //   connection	: an LmConnection used to send message
       
 12385 //   message    : LmMessage to send
       
 12386 //   error      : location to store error, or NULL
       
 12387 // Returns      : Returns TRUE if no errors were detected while sending,
       
 12388 //                FALSE otherwise
       
 12389 //-----------------------------------------------------------------------------
       
 12390 // 
       
 12391 TInt Ctstlm:: lm_login_test_invalid_serverL ( CStifItemParser& aItem )
       
 12392     {
       
 12393 	LmConnection *connection   = NULL;
       
 12394 	ConnectData  *connect_data = NULL;
       
 12395 	
       
 12396 	
       
 12397 	iLog->Log ( _L ( "In  lm_login_test_invalid_serverL" ) );
       
 12398 	// Read a data from the CFG file
       
 12399 	if ( read_data ( connect_data, aItem ) != RC_OK )
       
 12400 		{
       
 12401 		iLog->Log ( _L ( "read_data failed" ) );
       
 12402 		free_data ( connect_data );
       
 12403 		return KErrGeneral;
       
 12404 		}
       
 12405 	iLog->Log ( _L ( "after read_data" ) );
       
 12406 	
       
 12407 	// Open a new closed connection
       
 12408 	connection = lm_connection_new ( connect_data->server );
       
 12409 	iLog->Log ( _L ( "after lm_connection_new " ) );
       
 12410 	if ( !connection )
       
 12411 		{
       
 12412 		iLog->Log ( _L ( "lm_connection_new failed" ) );
       
 12413 		free_data ( connect_data );
       
 12414 		return KErrGeneral;
       
 12415 		}
       
 12416 	
       
 12417 	// Set the gtalk's SSL port
       
 12418 	lm_connection_set_port ( connection, SSL_INVALID_PORT );
       
 12419 	
       
 12420 	// Set the JID
       
 12421 	lm_connection_set_jid ( connection, connect_data->username );
       
 12422 	
       
 12423 	// Proxy settings for Emulator
       
 12424 #ifdef __WINSCW__
       
 12425 	SetProxy ( connection, connect_data->proxy_data );
       
 12426 #endif
       
 12427 	
       
 12428 	// Set the connection to use SSL
       
 12429 	SSLInit ( connection );
       
 12430 	
       
 12431 	GMainLoop* main_loop = g_main_loop_new ( NULL, FALSE );
       
 12432 
       
 12433 	iLog->Log ( _L ( "before lm_connection_open" ) );
       
 12434 	
       
 12435 	if ( !lm_connection_open ( connection, ( LmResultFunction ) connection_open_cb,
       
 12436 	                           main_loop, NULL, NULL ) ) 
       
 12437 	    {
       
 12438 		iLog->Log ( _L ( "lm_connection_open failed" ));
       
 12439 		lm_connection_unref ( connection );
       
 12440 		g_main_loop_unref ( main_loop );
       
 12441 		free_data ( connect_data );		
       
 12442 		return KErrGeneral;
       
 12443 	    }
       
 12444 		
       
 12445 	iLog->Log ( _L ( "after lm_connection_open" ) );
       
 12446 	
       
 12447 	g_main_loop_run ( main_loop );
       
 12448 
       
 12449 	g_main_loop_unref ( main_loop );    
       
 12450 
       
 12451 	// Close the connection
       
 12452 	lm_connection_close ( connection, NULL );	
       
 12453 	// Remove a reference on connection
       
 12454 	lm_connection_unref ( connection );
       
 12455 	free_data ( connect_data );
       
 12456 	iLog->Log ( _L ( " lm_login_test_invalid_server: Invalid settings is handled correctly" ) );
       
 12457 	return KErrNone;
       
 12458 }    
       
 12459    
       
 12460     
       
 12461 //-----------------------------------------------------------------------------
       
 12462 // Ctstlm::lm_memory_leak_testL
       
 12463 // Description  : Asynchronous call to send a message
       
 12464 // Arguements   :
       
 12465 //   connection	: an LmConnection used to send message
       
 12466 //   message    : LmMessage to send
       
 12467 //   error      : location to store error, or NULL
       
 12468 // Returns      : Returns TRUE if no errors were detected while sending,
       
 12469 //                FALSE otherwise
       
 12470 //-----------------------------------------------------------------------------
       
 12471 // 
       
 12472 TInt Ctstlm::lm_memory_leak_testL ( CStifItemParser& aItem )
       
 12473     {
       
 12474 	LmConnection *connection   = NULL;
       
 12475 	//ConnectData  *connect_data = NULL;
       
 12476 	AuthData     *auth_data    = NULL;
       
 12477 	
       
 12478 	
       
 12479 	iLog->Log ( _L ( "In lm_memory_leak_testL" ) );
       
 12480 	
       
 12481 	auth_data = g_new0 ( AuthData, 1 );
       
 12482 	if ( !auth_data )
       
 12483 		{
       
 12484 		iLog->Log ( _L ( "memory allocation failed for auth_data" ) );
       
 12485 		return KErrGeneral;
       
 12486 		}	
       
 12487 	
       
 12488 	// Read a data from the CFG file
       
 12489 	if ( read_data ( auth_data->connect_data, aItem ) != RC_OK )
       
 12490 		{
       
 12491 		iLog->Log ( _L ( "read_data failed" ) );
       
 12492 		free_data ( auth_data->connect_data );
       
 12493 		return KErrGeneral;
       
 12494 		}
       
 12495 	iLog->Log ( _L ( "after read_data" ) );
       
 12496 	
       
 12497 	// Open a new closed connection
       
 12498 	connection = lm_connection_new ( auth_data->connect_data->server );
       
 12499 	iLog->Log ( _L ( "after lm_connection_new " ) );
       
 12500 	if ( !connection )
       
 12501 		{
       
 12502 		iLog->Log ( _L ( "lm_connection_new failed" ) );
       
 12503 		free_data ( auth_data->connect_data );
       
 12504 		return KErrGeneral;
       
 12505 		}
       
 12506 	
       
 12507 	// Set the gtalk's SSL port
       
 12508 	lm_connection_set_port ( connection, GTALK_SSL_PORT );
       
 12509 	
       
 12510 	// Set the JID
       
 12511 	lm_connection_set_jid ( connection, auth_data->connect_data->username );
       
 12512 	
       
 12513 	// Proxy settings for Emulator
       
 12514 #ifdef __WINSCW__
       
 12515 	SetProxy ( connection, auth_data->connect_data->proxy_data );
       
 12516 #endif
       
 12517 	
       
 12518 	// Set the connection to use SSL
       
 12519 	SSLInit ( connection );
       
 12520 	
       
 12521 	auth_data->main_loop = g_main_loop_new ( NULL, FALSE );
       
 12522 
       
 12523 	iLog->Log ( _L ( "before lm_connection_open" ) );
       
 12524 	
       
 12525 	if ( !lm_connection_open ( connection, ( LmResultFunction ) connection_open_cb,
       
 12526 	                           auth_data->main_loop, NULL, NULL ) ) 
       
 12527 	    {
       
 12528 		iLog->Log ( _L ( "lm_connection_open failed" ));
       
 12529 		lm_connection_unref ( connection );
       
 12530 		g_main_loop_unref ( auth_data->main_loop );
       
 12531 		free_data ( auth_data->connect_data );		
       
 12532 		g_free(auth_data);
       
 12533 		return KErrGeneral;
       
 12534 	    }
       
 12535 		
       
 12536 	iLog->Log ( _L ( "after lm_connection_open" ) );
       
 12537 	
       
 12538 	g_main_loop_run ( auth_data->main_loop );
       
 12539 
       
 12540 	g_main_loop_unref ( auth_data->main_loop );    
       
 12541 
       
 12542 	
       
 12543 	auth_data->main_loop = g_main_loop_new ( NULL, FALSE );
       
 12544 	
       
 12545 	// Get the username from the JID
       
 12546 	gchar *username = get_user_name ( auth_data->connect_data->username );
       
 12547 	
       
 12548 	// Authenticate with the server
       
 12549 	if ( !lm_connection_authenticate ( connection,
       
 12550                                      username,
       
 12551                                      auth_data->connect_data->password,
       
 12552                                      auth_data->connect_data->resource,
       
 12553                                       ( LmResultFunction ) lm_login_cb,
       
 12554                                      auth_data,NULL,NULL ) )
       
 12555 	    {
       
 12556 		iLog->Log ( _L ( "lm_connection_authenticate failed" ) );
       
 12557 		lm_connection_close ( connection, NULL );
       
 12558 		lm_connection_unref ( connection );
       
 12559 		free_data ( auth_data->connect_data );
       
 12560 		g_main_loop_unref ( auth_data->main_loop );
       
 12561 		g_free ( username );
       
 12562 		g_free ( auth_data );
       
 12563 		return KErrGeneral;
       
 12564 	    }
       
 12565 
       
 12566 	g_main_loop_run ( auth_data->main_loop );
       
 12567 	g_main_loop_unref ( auth_data->main_loop ); 
       
 12568 	g_free ( username );
       
 12569 	
       
 12570 	// Close the connection
       
 12571 	lm_connection_close ( connection, NULL );	
       
 12572 	// Remove a reference on connection
       
 12573 	lm_connection_unref ( connection );
       
 12574 	free_data ( auth_data->connect_data );
       
 12575 	
       
 12576 	if ( auth_data->rCode == RC_ERROR )
       
 12577 	    {
       
 12578 	    iLog->Log ( _L ( "lm_memory_leak_testL failed" ) );
       
 12579 	    g_free ( auth_data );
       
 12580 	    return KErrGeneral;
       
 12581 	    }	
       
 12582 	g_free ( auth_data );
       
 12583     
       
 12584 
       
 12585 	
       
 12586 	return KErrNone;
       
 12587 }
       
 12588 // NFT test cases
       
 12589 
       
 12590 TInt Ctstlm::lm_nft_updating_presenceL(CStifItemParser& aItem)	    
       
 12591     {
       
 12592 
       
 12593     LmConnection *connection   = NULL;
       
 12594     ConnectData  *connect_data = NULL;
       
 12595     LmMessage    *message = NULL;
       
 12596     LmMessageNode *show_node = NULL;
       
 12597     LmMessageNode *status_node = NULL;
       
 12598     LmMessageHandler *handler = NULL;
       
 12599     GMainLoop    *main_loop    = NULL;
       
 12600     
       
 12601     iLog->Log ( _L ( "In lm_nft_updating_presenceL" ) );
       
 12602     
       
 12603     // Read a data from the CFG file
       
 12604     if ( read_data ( connect_data, aItem ) != RC_OK )
       
 12605         {
       
 12606         iLog->Log ( _L ( "read_data failed" ) );
       
 12607         free_data ( connect_data );
       
 12608         return KErrGeneral;
       
 12609         }
       
 12610     
       
 12611     // Open a new closed connection
       
 12612     connection = lm_connection_new ( connect_data->server );
       
 12613     if ( !connection )
       
 12614         {
       
 12615         iLog->Log ( _L ( "lm_connection_new failed" ) );
       
 12616         free_data ( connect_data );
       
 12617         return KErrGeneral;
       
 12618         }
       
 12619     
       
 12620     // Set the gtalk's SSL port
       
 12621     lm_connection_set_port ( connection, GTALK_SSL_PORT );
       
 12622     
       
 12623     // Set the JID
       
 12624     lm_connection_set_jid ( connection, connect_data->username );
       
 12625     
       
 12626     // Proxy settings for Emulator
       
 12627 #ifdef __WINSCW__
       
 12628     SetProxy ( connection, connect_data->proxy_data );
       
 12629 #endif
       
 12630     
       
 12631     // Set the connection to use SSL
       
 12632     SSLInit ( connection );
       
 12633     
       
 12634     
       
 12635     main_loop = g_main_loop_new ( NULL, FALSE );
       
 12636     
       
 12637     if ( !lm_connection_open ( connection, ( LmResultFunction ) connection_open_cb,
       
 12638                                main_loop, NULL, NULL ) ) 
       
 12639         {
       
 12640         iLog->Log ( _L ( "lm_connection_open failed" ));
       
 12641         lm_connection_unref ( connection );
       
 12642         g_main_loop_unref ( main_loop );
       
 12643         free_data ( connect_data );     
       
 12644         return KErrGeneral;
       
 12645         }
       
 12646         
       
 12647     
       
 12648     g_main_loop_run ( main_loop );
       
 12649 
       
 12650     g_main_loop_unref ( main_loop );    
       
 12651 
       
 12652     main_loop = g_main_loop_new ( NULL, FALSE );
       
 12653     
       
 12654     // Get the username from the JID
       
 12655     gchar *username = get_user_name ( connect_data->username );
       
 12656     
       
 12657     // Authenticate with the server
       
 12658     if ( !lm_connection_authenticate ( connection,
       
 12659                                      username,
       
 12660                                      connect_data->password,
       
 12661                                      connect_data->resource,
       
 12662                                       ( LmResultFunction ) connection_auth_cb,
       
 12663                                      main_loop,NULL,NULL ) )
       
 12664         {
       
 12665         iLog->Log ( _L ( "lm_connection_authenticate failed" ) );
       
 12666         lm_connection_close ( connection, NULL );
       
 12667         lm_connection_unref ( connection );
       
 12668         free_data ( connect_data );
       
 12669         g_main_loop_unref ( main_loop );
       
 12670         g_free ( username );
       
 12671         return KErrGeneral;
       
 12672         }
       
 12673     g_main_loop_run ( main_loop );
       
 12674     g_main_loop_unref ( main_loop );    
       
 12675     g_free ( username );
       
 12676     
       
 12677     /*
       
 12678     <presence xml:lang='en'>
       
 12679         <show>dnd</show>
       
 12680         <status>Wooing Juliet</status>
       
 12681         <status xml:lang='cz'>Ja dvo&#x0159;&#x00ED;m Juliet</status>
       
 12682     </presence>
       
 12683     */
       
 12684 
       
 12685     //publish own presence
       
 12686     //updating presence multiple time
       
 12687     for (TInt i =1 ;i<100 ;i++)
       
 12688         {
       
 12689     message = lm_message_new_with_sub_type ( NULL,
       
 12690                                          LM_MESSAGE_TYPE_PRESENCE,
       
 12691                                          LM_MESSAGE_SUB_TYPE_AVAILABLE );
       
 12692     gboolean result = lm_connection_send ( connection, message, NULL ); 
       
 12693     //lm_connection_send_with_reply(
       
 12694     // Remove a reference on message
       
 12695     lm_message_unref ( message );   
       
 12696     
       
 12697     //Change presence again
       
 12698         message = lm_message_new_with_sub_type ( NULL,
       
 12699                                              LM_MESSAGE_TYPE_PRESENCE,
       
 12700                                              LM_MESSAGE_SUB_TYPE_AVAILABLE );
       
 12701         lm_message_node_set_attributes ( message->node, "xml:lang", "en", NULL ); 
       
 12702         show_node = lm_message_node_add_child ( message->node, "show", "busy" );
       
 12703         status_node = lm_message_node_add_child ( message->node, "status", "goal goal goal" );
       
 12704         result = lm_connection_send ( connection, message, NULL );  
       
 12705         // Remove a reference on message
       
 12706         lm_message_unref ( message );   
       
 12707     
       
 12708         }
       
 12709     
       
 12710     
       
 12711     lm_connection_close ( connection, NULL );   
       
 12712     // Remove a reference on connection
       
 12713     lm_connection_unref ( connection ); 
       
 12714     free_data ( connect_data );
       
 12715     // Message sending passed
       
 12716     iLog->Log ( _L ( "lm_nft_updating_presenceL" ) );
       
 12717     
       
 12718     return KErrNone;
       
 12719     
       
 12720     }
       
 12721 
       
 12722 TInt Ctstlm ::lm_nft_presence_notificationL(CStifItemParser& aItem)
       
 12723     {
       
 12724 
       
 12725     LmConnection *connection   = NULL;
       
 12726     ConnectData  *connect_data = NULL;
       
 12727     LmMessage    *message = NULL;
       
 12728     LmMessageNode *show_node = NULL;
       
 12729     LmMessageNode *status_node = NULL;
       
 12730     LmMessageHandler *handler = NULL;
       
 12731     GMainLoop    *main_loop    = NULL;
       
 12732     HandleData *handle_data = NULL;
       
 12733     
       
 12734     iLog->Log ( _L ( "lm_nft_presence_notificationL" ) );
       
 12735     
       
 12736     // Read a data from the CFG file
       
 12737     if ( read_data ( connect_data, aItem ) != RC_OK )
       
 12738         {
       
 12739         iLog->Log ( _L ( "read_data failed" ) );
       
 12740         free_data ( connect_data );
       
 12741         return KErrGeneral;
       
 12742         }
       
 12743     
       
 12744     // Open a new closed connection
       
 12745     connection = lm_connection_new ( connect_data->server );
       
 12746     if ( !connection )
       
 12747         {
       
 12748         iLog->Log ( _L ( "lm_connection_new failed" ) );
       
 12749         free_data ( connect_data );
       
 12750         return KErrGeneral;
       
 12751         }
       
 12752     
       
 12753     // Set the gtalk's SSL port
       
 12754     lm_connection_set_port ( connection, GTALK_SSL_PORT );
       
 12755     
       
 12756     // Set the JID
       
 12757     lm_connection_set_jid ( connection, connect_data->username );
       
 12758     
       
 12759     // Proxy settings for Emulator
       
 12760 #ifdef __WINSCW__
       
 12761     SetProxy ( connection, connect_data->proxy_data );
       
 12762 #endif
       
 12763     
       
 12764     // Set the connection to use SSL
       
 12765     SSLInit ( connection );
       
 12766     
       
 12767     
       
 12768     main_loop = g_main_loop_new ( NULL, FALSE );
       
 12769     
       
 12770     if ( !lm_connection_open ( connection, ( LmResultFunction ) connection_open_cb,
       
 12771                                main_loop, NULL, NULL ) ) 
       
 12772         {
       
 12773         iLog->Log ( _L ( "lm_connection_open failed" ));
       
 12774         lm_connection_unref ( connection );
       
 12775         g_main_loop_unref ( main_loop );
       
 12776         free_data ( connect_data );     
       
 12777         return KErrGeneral;
       
 12778         }
       
 12779         
       
 12780     
       
 12781     g_main_loop_run ( main_loop );
       
 12782 
       
 12783     g_main_loop_unref ( main_loop );    
       
 12784 
       
 12785     main_loop = g_main_loop_new ( NULL, FALSE );
       
 12786     
       
 12787     // Get the username from the JID
       
 12788     gchar *username = get_user_name ( connect_data->username );
       
 12789     
       
 12790     // Authenticate with the server
       
 12791     if ( !lm_connection_authenticate ( connection,
       
 12792                                      username,
       
 12793                                      connect_data->password,
       
 12794                                      connect_data->resource,
       
 12795                                       ( LmResultFunction ) connection_auth_cb,
       
 12796                                      main_loop,NULL,NULL ) )
       
 12797         {
       
 12798         iLog->Log ( _L ( "lm_connection_authenticate failed" ) );
       
 12799         lm_connection_close ( connection, NULL );
       
 12800         lm_connection_unref ( connection );
       
 12801         free_data ( connect_data );
       
 12802         g_main_loop_unref ( main_loop );
       
 12803         g_free ( username );
       
 12804         return KErrGeneral;
       
 12805         }
       
 12806     g_main_loop_run ( main_loop );
       
 12807     g_main_loop_unref ( main_loop );    
       
 12808     g_free ( username );
       
 12809     
       
 12810     /*
       
 12811     <presence xml:lang='en'>
       
 12812         <show>dnd</show>
       
 12813         <status>Wooing Juliet</status>
       
 12814         <status xml:lang='cz'>Ja dvo&#x0159;&#x00ED;m Juliet</status>
       
 12815     </presence>
       
 12816     */
       
 12817 
       
 12818     //publish own presence
       
 12819     message = lm_message_new_with_sub_type ( NULL,
       
 12820                                          LM_MESSAGE_TYPE_PRESENCE,
       
 12821                                          LM_MESSAGE_SUB_TYPE_AVAILABLE );
       
 12822     gboolean result = lm_connection_send ( connection, message, NULL ); 
       
 12823     //lm_connection_send_with_reply(
       
 12824     // Remove a reference on message
       
 12825     lm_message_unref ( message );   
       
 12826 
       
 12827     //------------------------------------------------------------------------
       
 12828     //
       
 12829     // Register a handler to recieve and update presence information
       
 12830     //
       
 12831    
       
 12832         main_loop = g_main_loop_new ( NULL, FALSE );
       
 12833         handle_data = g_new0 ( HandleData, 1 );
       
 12834         handle_data->main_loop=main_loop;
       
 12835         handle_data->count=0;
       
 12836         handler = lm_message_handler_new ( 
       
 12837                              (LmHandleMessageFunction)handle_100_presence_notification,
       
 12838                              handle_data,
       
 12839                              NULL );
       
 12840         lm_connection_register_message_handler ( connection,
       
 12841                                                  handler,
       
 12842                                                  LM_MESSAGE_TYPE_PRESENCE,
       
 12843                                                  LM_HANDLER_PRIORITY_NORMAL );
       
 12844         g_main_loop_run ( main_loop );  
       
 12845         g_main_loop_unref ( main_loop );
       
 12846         lm_message_handler_unref(handler);
       
 12847     
       
 12848     
       
 12849     
       
 12850     lm_connection_close ( connection, NULL );   
       
 12851     // Remove a reference on connection
       
 12852     lm_connection_unref ( connection ); 
       
 12853     free_data ( connect_data );
       
 12854     // Message sending passed
       
 12855     iLog->Log ( _L ( "lm_nft_presence_notificationL" ) );
       
 12856     
       
 12857     return KErrNone;
       
 12858     
       
 12859     
       
 12860     }
       
 12861 
       
 12862  TInt Ctstlm::lm_nft_send_text_messageL(CStifItemParser& aItem)
       
 12863      {
       
 12864 
       
 12865      LmConnection *connection   = NULL;
       
 12866      ConnectData  *connect_data = NULL;
       
 12867      LmMessage    *message;
       
 12868      
       
 12869      iLog->Log ( _L ( "In lm_nft_send_text_messageL" ) );
       
 12870      
       
 12871      // Read a data from the CFG file
       
 12872      if ( read_data ( connect_data, aItem ) != RC_OK )
       
 12873          {
       
 12874          iLog->Log ( _L ( "read_data failed" ) );
       
 12875          free_data ( connect_data );
       
 12876          return KErrGeneral;
       
 12877          }
       
 12878      iLog->Log ( _L ( "after read_data" ) );
       
 12879      
       
 12880      // Open a new closed connection
       
 12881      connection = lm_connection_new ( connect_data->server );
       
 12882      iLog->Log ( _L ( "after lm_connection_new " ) );
       
 12883      if ( !connection )
       
 12884          {
       
 12885          iLog->Log ( _L ( "lm_connection_new failed" ) );
       
 12886          free_data ( connect_data );
       
 12887          return KErrGeneral;
       
 12888          }
       
 12889      
       
 12890      // Set the gtalk's SSL port
       
 12891      lm_connection_set_port ( connection, GTALK_SSL_PORT );
       
 12892      
       
 12893      // Set the JID
       
 12894      lm_connection_set_jid ( connection, connect_data->username );
       
 12895      
       
 12896      // Proxy settings for Emulator
       
 12897  #ifdef __WINSCW__
       
 12898      SetProxy ( connection, connect_data->proxy_data );
       
 12899  #endif
       
 12900      
       
 12901      // Set the connection to use SSL
       
 12902      SSLInit ( connection );
       
 12903      
       
 12904      GMainLoop   *main_loop = g_main_loop_new ( NULL, FALSE );
       
 12905 
       
 12906      iLog->Log ( _L ( "before lm_connection_open" ) );
       
 12907      
       
 12908      if ( !lm_connection_open ( connection, ( LmResultFunction ) connection_open_cb,
       
 12909                                 main_loop, NULL, NULL ) ) 
       
 12910          {
       
 12911          iLog->Log ( _L ( "lm_connection_open failed" ));
       
 12912          lm_connection_unref ( connection );
       
 12913          g_main_loop_unref ( main_loop );
       
 12914          free_data ( connect_data );     
       
 12915          return KErrGeneral;
       
 12916          }
       
 12917          
       
 12918      iLog->Log ( _L ( "after lm_connection_open" ) );
       
 12919      g_main_loop_run ( main_loop );
       
 12920      g_main_loop_unref ( main_loop );    
       
 12921      
       
 12922      main_loop = g_main_loop_new ( NULL, FALSE );
       
 12923      
       
 12924      // Get the username from the JID
       
 12925      gchar *username = get_user_name ( connect_data->username );
       
 12926      
       
 12927      // Authenticate with the server
       
 12928      if ( !lm_connection_authenticate ( connection,
       
 12929                                       username,
       
 12930                                       connect_data->password,
       
 12931                                       connect_data->resource,
       
 12932                                        ( LmResultFunction ) connection_auth_cb,
       
 12933                                       main_loop,NULL,NULL ) )
       
 12934          {
       
 12935          iLog->Log ( _L ( "lm_connection_authenticate failed" ) );
       
 12936          lm_connection_close ( connection, NULL );
       
 12937          lm_connection_unref ( connection );
       
 12938          free_data ( connect_data );
       
 12939          g_main_loop_unref ( main_loop );
       
 12940          g_free ( username );
       
 12941          return KErrGeneral;
       
 12942          }
       
 12943      g_main_loop_run ( main_loop );
       
 12944      g_main_loop_unref ( main_loop );
       
 12945      g_free ( username );
       
 12946      
       
 12947      // Construct a message
       
 12948      message = lm_message_new ( connect_data->msg_data->recipient,               
       
 12949                                 LM_MESSAGE_TYPE_MESSAGE );
       
 12950      lm_message_node_add_child ( message->node, "body", 
       
 12951                                  connect_data->msg_data->message);
       
 12952      for(TInt i =0 ; i<100 ;i++)
       
 12953          {
       
 12954      // Send message to the server
       
 12955      if ( !lm_connection_send ( connection, message, NULL ) )
       
 12956          {
       
 12957          iLog->Log ( _L ( "lm_connection_send failed" ) );
       
 12958          lm_connection_close ( connection, NULL );
       
 12959          lm_connection_unref ( connection );
       
 12960          lm_message_unref ( message );
       
 12961          free_data ( connect_data );     
       
 12962          return KErrGeneral;
       
 12963          }  
       
 12964          }
       
 12965      // Close the connection
       
 12966      lm_connection_close ( connection, NULL );
       
 12967      
       
 12968      // Remove a reference on connection
       
 12969      lm_connection_unref ( connection );
       
 12970      
       
 12971      // Remove a reference on message
       
 12972      lm_message_unref ( message );
       
 12973      
       
 12974      //free_data ( connect_data );
       
 12975      
       
 12976      // Message sending passed
       
 12977      iLog->Log ( _L ( "lm_nft_send_text_messageL" ) );
       
 12978      
       
 12979      return KErrNone;
       
 12980 
       
 12981      }
       
 12982  TInt Ctstlm::lm_nft_open_conversation_with_multipleL(CStifItemParser& aItem)
       
 12983      {
       
 12984 
       
 12985 
       
 12986      LmConnection *connection   = NULL;
       
 12987      ConnectData  *connect_data = NULL;
       
 12988      LmMessage    *message;
       
 12989      
       
 12990      iLog->Log ( _L ( "lm_nft_open_conversation_with_multipleL" ) );
       
 12991      
       
 12992      // Read a data from the CFG file
       
 12993      if ( read_data ( connect_data, aItem ) != RC_OK )
       
 12994          {
       
 12995          iLog->Log ( _L ( "read_data failed" ) );
       
 12996          free_data ( connect_data );
       
 12997          return KErrGeneral;
       
 12998          }
       
 12999      iLog->Log ( _L ( "after read_data" ) );
       
 13000      
       
 13001      // Open a new closed connection
       
 13002      connection = lm_connection_new ( connect_data->server );
       
 13003      iLog->Log ( _L ( "after lm_connection_new " ) );
       
 13004      if ( !connection )
       
 13005          {
       
 13006          iLog->Log ( _L ( "lm_connection_new failed" ) );
       
 13007          free_data ( connect_data );
       
 13008          return KErrGeneral;
       
 13009          }
       
 13010      
       
 13011      // Set the gtalk's SSL port
       
 13012      lm_connection_set_port ( connection, GTALK_SSL_PORT );
       
 13013      
       
 13014      // Set the JID
       
 13015      lm_connection_set_jid ( connection, connect_data->username );
       
 13016      
       
 13017      // Proxy settings for Emulator
       
 13018  #ifdef __WINSCW__
       
 13019      SetProxy ( connection, connect_data->proxy_data );
       
 13020  #endif
       
 13021      
       
 13022      // Set the connection to use SSL
       
 13023      SSLInit ( connection );
       
 13024      
       
 13025      GMainLoop   *main_loop = g_main_loop_new ( NULL, FALSE );
       
 13026 
       
 13027      iLog->Log ( _L ( "before lm_connection_open" ) );
       
 13028      
       
 13029      if ( !lm_connection_open ( connection, ( LmResultFunction ) connection_open_cb,
       
 13030                                 main_loop, NULL, NULL ) ) 
       
 13031          {
       
 13032          iLog->Log ( _L ( "lm_connection_open failed" ));
       
 13033          lm_connection_unref ( connection );
       
 13034          g_main_loop_unref ( main_loop );
       
 13035          free_data ( connect_data );     
       
 13036          return KErrGeneral;
       
 13037          }
       
 13038          
       
 13039      iLog->Log ( _L ( "after lm_connection_open" ) );
       
 13040      g_main_loop_run ( main_loop );
       
 13041      g_main_loop_unref ( main_loop );    
       
 13042      
       
 13043      main_loop = g_main_loop_new ( NULL, FALSE );
       
 13044      
       
 13045      // Get the username from the JID
       
 13046      gchar *username = get_user_name ( connect_data->username );
       
 13047      
       
 13048      // Authenticate with the server
       
 13049      if ( !lm_connection_authenticate ( connection,
       
 13050                                       username,
       
 13051                                       connect_data->password,
       
 13052                                       connect_data->resource,
       
 13053                                        ( LmResultFunction ) connection_auth_cb,
       
 13054                                       main_loop,NULL,NULL ) )
       
 13055          {
       
 13056          iLog->Log ( _L ( "lm_connection_authenticate failed" ) );
       
 13057          lm_connection_close ( connection, NULL );
       
 13058          lm_connection_unref ( connection );
       
 13059          free_data ( connect_data );
       
 13060          g_main_loop_unref ( main_loop );
       
 13061          g_free ( username );
       
 13062          return KErrGeneral;
       
 13063          }
       
 13064      g_main_loop_run ( main_loop );
       
 13065      g_main_loop_unref ( main_loop );
       
 13066      g_free ( username );
       
 13067      
       
 13068      // Construct a message
       
 13069      //receipient1
       
 13070      const char *receipient = "rakesh.harsh@gmail.com";
       
 13071      message = lm_message_new ( receipient,               
       
 13072                                 LM_MESSAGE_TYPE_MESSAGE );
       
 13073      lm_message_node_add_child ( message->node, "body", 
       
 13074                                  connect_data->msg_data->message);
       
 13075      for(TInt i =0 ; i<20 ;i++)
       
 13076          {
       
 13077      // Send message to the server
       
 13078      if ( !lm_connection_send ( connection, message, NULL ) )
       
 13079          {
       
 13080          iLog->Log ( _L ( "lm_connection_send failed" ) );
       
 13081          lm_connection_close ( connection, NULL );
       
 13082          lm_connection_unref ( connection );
       
 13083          lm_message_unref ( message );
       
 13084          free_data ( connect_data );     
       
 13085          return KErrGeneral;
       
 13086          }  
       
 13087          }
       
 13088              const char *receipient1 = "rakesh.harsha@gmail.com";
       
 13089               message = lm_message_new ( receipient1,               
       
 13090                                          LM_MESSAGE_TYPE_MESSAGE );
       
 13091               lm_message_node_add_child ( message->node, "body", 
       
 13092                                           connect_data->msg_data->message);
       
 13093               for(TInt i =0 ; i<20 ;i++)
       
 13094                   {
       
 13095               // Send message to the server
       
 13096               if ( !lm_connection_send ( connection, message, NULL ) )
       
 13097                   {
       
 13098                   iLog->Log ( _L ( "lm_connection_send failed" ) );
       
 13099                   lm_connection_close ( connection, NULL );
       
 13100                   lm_connection_unref ( connection );
       
 13101                   lm_message_unref ( message );
       
 13102                   free_data ( connect_data );     
       
 13103                   return KErrGeneral;
       
 13104                   }  
       
 13105                   }
       
 13106                const char *receipient2 = "testlm123@gmail.com";
       
 13107                message = lm_message_new ( receipient2,               
       
 13108                                           LM_MESSAGE_TYPE_MESSAGE );
       
 13109                lm_message_node_add_child ( message->node, "body", 
       
 13110                                            connect_data->msg_data->message);
       
 13111                for(TInt i =0 ; i<20 ;i++)
       
 13112                    {
       
 13113                // Send message to the server
       
 13114                if ( !lm_connection_send ( connection, message, NULL ) )
       
 13115                    {
       
 13116                    iLog->Log ( _L ( "lm_connection_send failed" ) );
       
 13117                    lm_connection_close ( connection, NULL );
       
 13118                    lm_connection_unref ( connection );
       
 13119                    lm_message_unref ( message );
       
 13120                    free_data ( connect_data );     
       
 13121                    return KErrGeneral;
       
 13122                    }  
       
 13123                    }
       
 13124                
       
 13125                    const char *receipient3 = "nokiatestlm@gmail.com";
       
 13126                     message = lm_message_new ( receipient3,               
       
 13127                                                LM_MESSAGE_TYPE_MESSAGE );
       
 13128                     lm_message_node_add_child ( message->node, "body", 
       
 13129                                                 connect_data->msg_data->message);
       
 13130                     for(TInt i =0 ; i<20 ;i++)
       
 13131                         {
       
 13132                     // Send message to the server
       
 13133                     if ( !lm_connection_send ( connection, message, NULL ) )
       
 13134                         {
       
 13135                         iLog->Log ( _L ( "lm_connection_send failed" ) );
       
 13136                         lm_connection_close ( connection, NULL );
       
 13137                         lm_connection_unref ( connection );
       
 13138                         lm_message_unref ( message );
       
 13139                         free_data ( connect_data );     
       
 13140                         return KErrGeneral;
       
 13141                         }  
       
 13142                         } 
       
 13143                                  const char *receipient4 = "testui123@gmail.com";
       
 13144                                   message = lm_message_new ( receipient4,               
       
 13145                                                              LM_MESSAGE_TYPE_MESSAGE );
       
 13146                                   lm_message_node_add_child ( message->node, "body", 
       
 13147                                                               connect_data->msg_data->message);
       
 13148                                   for(TInt i =0 ; i<20 ;i++)
       
 13149                                       {
       
 13150                                   // Send message to the server
       
 13151                                   if ( !lm_connection_send ( connection, message, NULL ) )
       
 13152                                       {
       
 13153                                       iLog->Log ( _L ( "lm_connection_send failed" ) );
       
 13154                                       lm_connection_close ( connection, NULL );
       
 13155                                       lm_connection_unref ( connection );
       
 13156                                       lm_message_unref ( message );
       
 13157                                       free_data ( connect_data );     
       
 13158                                       return KErrGeneral;
       
 13159                                       }  
       
 13160                                       } 
       
 13161                                   const char *receipient5 = "immeco10@gmail.com";
       
 13162                                   message = lm_message_new ( receipient5,               
       
 13163                                   LM_MESSAGE_TYPE_MESSAGE );
       
 13164                                   lm_message_node_add_child ( message->node, "body", 
       
 13165                                   connect_data->msg_data->message);
       
 13166                                   for(TInt i =0 ; i<20 ;i++)
       
 13167                                   {
       
 13168                                   // Send message to the server
       
 13169                                   if ( !lm_connection_send ( connection, message, NULL ) )
       
 13170                                   {
       
 13171                                   iLog->Log ( _L ( "lm_connection_send failed" ) );
       
 13172                                   lm_connection_close ( connection, NULL );
       
 13173                                   lm_connection_unref ( connection );
       
 13174                                   lm_message_unref ( message );
       
 13175                                   free_data ( connect_data );     
       
 13176                                   return KErrGeneral;
       
 13177                                   }  
       
 13178                                   } 
       
 13179                                   const char *receipient6 = "immeco11@gmail.com";
       
 13180                                   message = lm_message_new ( receipient6,               
       
 13181                                   LM_MESSAGE_TYPE_MESSAGE );
       
 13182                                   lm_message_node_add_child ( message->node, "body", 
       
 13183                                   connect_data->msg_data->message);
       
 13184                                   for(TInt i =0 ; i<20 ;i++)
       
 13185                                   {
       
 13186                                   // Send message to the server
       
 13187                                   if ( !lm_connection_send ( connection, message, NULL ) )
       
 13188                                   {
       
 13189                                   iLog->Log ( _L ( "lm_connection_send failed" ) );
       
 13190                                   lm_connection_close ( connection, NULL );
       
 13191                                   lm_connection_unref ( connection );
       
 13192                                   lm_message_unref ( message );
       
 13193                                   free_data ( connect_data );     
       
 13194                                   return KErrGeneral;
       
 13195                                   }  
       
 13196                                   } 
       
 13197                                   const char *receipient7 = "immeco11@gmail.com";
       
 13198                                   message = lm_message_new ( receipient7,               
       
 13199                                   LM_MESSAGE_TYPE_MESSAGE );
       
 13200                                   lm_message_node_add_child ( message->node, "body", 
       
 13201                                   connect_data->msg_data->message);
       
 13202                                   for(TInt i =0 ; i<20 ;i++) 
       
 13203                                   {
       
 13204                                   // Send message to the server
       
 13205                                   if ( !lm_connection_send ( connection, message, NULL ) )
       
 13206                                   {
       
 13207                                   iLog->Log ( _L ( "lm_connection_send failed" ) );
       
 13208                                   lm_connection_close ( connection, NULL );
       
 13209                                   lm_connection_unref ( connection );
       
 13210                                   lm_message_unref ( message );
       
 13211                                   free_data ( connect_data );     
       
 13212                                   return KErrGeneral;
       
 13213                                   }  
       
 13214                                   } 
       
 13215                                   const char *receipient8 = "test.isoserver@gmail.com";
       
 13216                                   message = lm_message_new ( receipient8,               
       
 13217                                   LM_MESSAGE_TYPE_MESSAGE );
       
 13218                                   lm_message_node_add_child ( message->node, "body", 
       
 13219                                   connect_data->msg_data->message);
       
 13220                                   for(TInt i =0 ; i<20 ;i++)
       
 13221                                   {
       
 13222                                   // Send message to the server
       
 13223                                   if ( !lm_connection_send ( connection, message, NULL ) )
       
 13224                                   {
       
 13225                                   iLog->Log ( _L ( "lm_connection_send failed" ) );
       
 13226                                   lm_connection_close ( connection, NULL );
       
 13227                                   lm_connection_unref ( connection );
       
 13228                                   lm_message_unref ( message );
       
 13229                                   free_data ( connect_data );     
       
 13230                                   return KErrGeneral;
       
 13231                                   }  
       
 13232                                   }   
       
 13233                                   const char *receipient9 = "tele1236@gmail.com";
       
 13234                                   message = lm_message_new ( receipient9,               
       
 13235                                   LM_MESSAGE_TYPE_MESSAGE );
       
 13236                                   lm_message_node_add_child ( message->node, "body", 
       
 13237                                   connect_data->msg_data->message);
       
 13238                                   for(TInt i =0 ; i<20 ;i++)
       
 13239                                   {
       
 13240                                   // Send message to the server
       
 13241                                   if ( !lm_connection_send ( connection, message, NULL ) )
       
 13242                                   {
       
 13243                                   iLog->Log ( _L ( "lm_connection_send failed" ) );
       
 13244                                   lm_connection_close ( connection, NULL );
       
 13245                                   lm_connection_unref ( connection );
       
 13246                                   lm_message_unref ( message );
       
 13247                                   free_data ( connect_data );     
       
 13248                                   return KErrGeneral;
       
 13249                                   }  
       
 13250                                   }                                   
       
 13251                                   const char *receipient10 = "meco5555@gmail.com";
       
 13252                                   message = lm_message_new ( receipient10,               
       
 13253                                   LM_MESSAGE_TYPE_MESSAGE );
       
 13254                                   lm_message_node_add_child ( message->node, "body", 
       
 13255                                   connect_data->msg_data->message);
       
 13256                                   for(TInt i =0 ; i<20 ;i++)
       
 13257                                   {
       
 13258                                   // Send message to the server
       
 13259                                   if ( !lm_connection_send ( connection, message, NULL ) )
       
 13260                                   {
       
 13261                                   iLog->Log ( _L ( "lm_connection_send failed" ) );
       
 13262                                   lm_connection_close ( connection, NULL );
       
 13263                                   lm_connection_unref ( connection );
       
 13264                                   lm_message_unref ( message );
       
 13265                                   free_data ( connect_data );     
       
 13266                                   return KErrGeneral;
       
 13267                                   }  
       
 13268                                   }                               
       
 13269      // Close the connection
       
 13270      lm_connection_close ( connection, NULL );
       
 13271      
       
 13272      // Remove a reference on connection
       
 13273      lm_connection_unref ( connection );
       
 13274      
       
 13275      // Remove a reference on message
       
 13276      lm_message_unref ( message );
       
 13277      
       
 13278      free_data ( connect_data );
       
 13279      
       
 13280      // Message sending passed
       
 13281      iLog->Log ( _L ( "lm_nft_open_conversation_with_multipleL" ) );
       
 13282      
       
 13283      return KErrNone;
       
 13284      
       
 13285      }
       
 13286  TInt Ctstlm::lm_nft_fetch300_contactL(CStifItemParser& aItem)
       
 13287       {
       
 13288 
       
 13289       LmConnection *connection   = NULL;
       
 13290       ConnectData  *connect_data = NULL;
       
 13291       LmMessage    *message;
       
 13292       LmMessageNode *q_node;
       
 13293       //LmMessageSubType  type;
       
 13294       LmMessageHandler *handler = NULL;
       
 13295       
       
 13296       iLog->Log ( _L ( "lm_nft_fetch300_contactL" ) );
       
 13297       
       
 13298       // Read a data from the CFG file
       
 13299       if ( read_data ( connect_data, aItem ) != RC_OK )
       
 13300           {
       
 13301           iLog->Log ( _L ( "read_data failed" ) );
       
 13302           free_data ( connect_data );
       
 13303           return KErrGeneral;
       
 13304           }
       
 13305       
       
 13306       // Open a new closed connection
       
 13307       connection = lm_connection_new ( connect_data->server );
       
 13308       if ( !connection )
       
 13309           {
       
 13310           iLog->Log ( _L ( "lm_connection_new failed" ) );
       
 13311           free_data ( connect_data );
       
 13312           return KErrGeneral;
       
 13313           }
       
 13314       
       
 13315       // Set the gtalk's SSL port
       
 13316       lm_connection_set_port ( connection, GTALK_SSL_PORT );
       
 13317       
       
 13318       // Set the JID
       
 13319       lm_connection_set_jid ( connection, connect_data->username );
       
 13320       
       
 13321       // Proxy settings for Emulator
       
 13322   #ifdef __WINSCW__
       
 13323       SetProxy ( connection, connect_data->proxy_data );
       
 13324   #endif
       
 13325       
       
 13326       // Set the connection to use SSL
       
 13327       SSLInit ( connection );
       
 13328 
       
 13329       //Open call    
       
 13330       GMainLoop   *main_loop = g_main_loop_new ( NULL, FALSE );
       
 13331       
       
 13332       if ( !lm_connection_open ( connection, ( LmResultFunction ) connection_open_cb,
       
 13333                                  main_loop, NULL, NULL ) ) 
       
 13334           {
       
 13335           iLog->Log ( _L ( "lm_connection_open failed" ));
       
 13336           lm_connection_unref ( connection );
       
 13337           free_data ( connect_data ); 
       
 13338           g_main_loop_unref ( main_loop );    
       
 13339           return KErrGeneral;
       
 13340           }
       
 13341           
       
 13342       
       
 13343       g_main_loop_run ( main_loop );
       
 13344 
       
 13345       g_main_loop_unref ( main_loop );    
       
 13346       
       
 13347 
       
 13348       main_loop = g_main_loop_new ( NULL, FALSE );
       
 13349       
       
 13350       // Get the username from the JID
       
 13351       gchar *username = get_user_name ( connect_data->username );
       
 13352       
       
 13353       // Authenticate with the server
       
 13354       if ( !lm_connection_authenticate ( connection,
       
 13355                                        username,
       
 13356                                        connect_data->password,
       
 13357                                        connect_data->resource,
       
 13358                                         ( LmResultFunction )connection_auth_cb,
       
 13359                                        main_loop,NULL,NULL ) )
       
 13360           {
       
 13361           iLog->Log ( _L ( "lm_connection_authenticate failed" ) );
       
 13362           lm_connection_close ( connection, NULL );
       
 13363           lm_connection_unref ( connection );
       
 13364           free_data ( connect_data );
       
 13365           g_main_loop_unref ( main_loop );
       
 13366           g_free ( username );
       
 13367           return KErrGeneral;
       
 13368           }
       
 13369       g_main_loop_run ( main_loop );
       
 13370       g_main_loop_unref ( main_loop );    
       
 13371       g_free ( username );
       
 13372       
       
 13373 
       
 13374                   
       
 13375       // Construct a message
       
 13376       main_loop = g_main_loop_new ( NULL, FALSE );
       
 13377       message = lm_message_new_with_sub_type (NULL, LM_MESSAGE_TYPE_IQ,
       
 13378                             LM_MESSAGE_SUB_TYPE_GET);
       
 13379       q_node = lm_message_node_add_child (message->node, "query", NULL);
       
 13380       lm_message_node_set_attributes (q_node,
       
 13381                           "xmlns", "jabber:iq:roster",
       
 13382                           NULL); 
       
 13383       // Send message to the server
       
 13384       handler = lm_message_handler_new ( handle_fetch_contactlist_messages, main_loop, NULL );
       
 13385       
       
 13386       if ( !lm_connection_send_with_reply ( connection, message, handler, NULL ) ) 
       
 13387           {
       
 13388           iLog->Log ( _L ( "lm_connection_send_with_reply failed" ) );
       
 13389           lm_connection_close ( connection, NULL );
       
 13390           lm_connection_unref ( connection );
       
 13391           lm_message_unref ( message );
       
 13392           free_data ( connect_data );
       
 13393           g_main_loop_unref ( main_loop );
       
 13394           return KErrGeneral;
       
 13395           }   
       
 13396       g_main_loop_run ( main_loop );
       
 13397       g_main_loop_unref ( main_loop );                                    
       
 13398                           
       
 13399                   
       
 13400       
       
 13401       // Close the connection
       
 13402       lm_connection_close ( connection, NULL );
       
 13403       
       
 13404       // Remove a reference on connection
       
 13405       lm_connection_unref ( connection );
       
 13406       
       
 13407       // Remove a reference on message
       
 13408       lm_message_unref ( message );
       
 13409       
       
 13410       free_data ( connect_data );
       
 13411       
       
 13412       // Message sending passed
       
 13413       iLog->Log ( _L ( "lm_nft_fetch300_contactL" ) );
       
 13414       
       
 13415       return KErrNone;
       
 13416       
       
 13417       }
       
 13418      
       
 13419  TInt Ctstlm::lm_nft_loginlogoutmultipletime(CStifItemParser& aItem)
       
 13420      {
       
 13421      LmConnection *connection   = NULL;
       
 13422      ConnectData  *connect_data = NULL;
       
 13423      LmMessage    *message;
       
 13424      
       
 13425      iLog->Log ( _L ( "lm_nft_loginlogoutmultipletime" ) );
       
 13426      
       
 13427      // Read a data from the CFG file
       
 13428      if ( read_data ( connect_data, aItem ) != RC_OK )
       
 13429          {
       
 13430          iLog->Log ( _L ( "read_data failed" ) );
       
 13431          free_data ( connect_data );
       
 13432          return KErrGeneral;
       
 13433          }
       
 13434      iLog->Log ( _L ( "after read_data" ) );
       
 13435      
       
 13436      // Open a new closed connection
       
 13437      connection = lm_connection_new ( connect_data->server );
       
 13438      iLog->Log ( _L ( "after lm_connection_new " ) );
       
 13439      if ( !connection )
       
 13440          {
       
 13441          iLog->Log ( _L ( "lm_connection_new failed" ) );
       
 13442          free_data ( connect_data );
       
 13443          return KErrGeneral;
       
 13444          }
       
 13445      
       
 13446      // Set the gtalk's SSL port
       
 13447      lm_connection_set_port ( connection, GTALK_SSL_PORT );
       
 13448      
       
 13449      // Set the JID
       
 13450      lm_connection_set_jid ( connection, connect_data->username );
       
 13451      
       
 13452      // Proxy settings for Emulator
       
 13453  #ifdef __WINSCW__
       
 13454      SetProxy ( connection, connect_data->proxy_data );
       
 13455  #endif
       
 13456      
       
 13457      // Set the connection to use SSL
       
 13458      SSLInit ( connection );
       
 13459      
       
 13460      GMainLoop   *main_loop = g_main_loop_new ( NULL, FALSE );
       
 13461 
       
 13462      iLog->Log ( _L ( "before lm_connection_open" ) );
       
 13463      
       
 13464      if ( !lm_connection_open ( connection, ( LmResultFunction ) connection_open_cb,
       
 13465                                 main_loop, NULL, NULL ) ) 
       
 13466          {
       
 13467          iLog->Log ( _L ( "lm_connection_open failed" ));
       
 13468          lm_connection_unref ( connection );
       
 13469          g_main_loop_unref ( main_loop );
       
 13470          free_data ( connect_data );     
       
 13471          return KErrGeneral;
       
 13472          }
       
 13473          
       
 13474      iLog->Log ( _L ( "after lm_connection_open" ) );
       
 13475      
       
 13476      g_main_loop_run ( main_loop );
       
 13477 
       
 13478      g_main_loop_unref ( main_loop );    
       
 13479 
       
 13480      
       
 13481      GMainLoop   *main_loop1 = g_main_loop_new ( NULL, FALSE );
       
 13482      
       
 13483      // Get the username from the JID
       
 13484      gchar *username = get_user_name ( connect_data->username );
       
 13485      
       
 13486      // Authenticate with the server
       
 13487      if ( !lm_connection_authenticate ( connection,
       
 13488                                       username,
       
 13489                                       connect_data->password,
       
 13490                                       connect_data->resource,
       
 13491                                        ( LmResultFunction ) connection_auth_cb,
       
 13492                                       main_loop1,NULL,NULL ) )
       
 13493          {
       
 13494          iLog->Log ( _L ( "lm_connection_authenticate failed" ) );
       
 13495          lm_connection_close ( connection, NULL );
       
 13496          lm_connection_unref ( connection );
       
 13497          free_data ( connect_data );
       
 13498          g_main_loop_unref ( main_loop1 );
       
 13499          g_free ( username );
       
 13500          return KErrGeneral;
       
 13501          }
       
 13502 
       
 13503      g_main_loop_run ( main_loop1 );
       
 13504 
       
 13505      g_main_loop_unref ( main_loop1 );
       
 13506          
       
 13507 
       
 13508      g_free ( username );
       
 13509      
       
 13510      // Construct a message
       
 13511      message = lm_message_new ( connect_data->msg_data->recipient,               
       
 13512                                 LM_MESSAGE_TYPE_MESSAGE );
       
 13513      lm_message_node_add_child ( message->node, "body", 
       
 13514                                  connect_data->msg_data->message);
       
 13515      
       
 13516      // Send message to the server
       
 13517      if ( !lm_connection_send ( connection, message, NULL ) )
       
 13518          {
       
 13519          iLog->Log ( _L ( "lm_connection_send failed" ) );
       
 13520          lm_connection_close ( connection, NULL );
       
 13521          lm_connection_unref ( connection );
       
 13522          lm_message_unref ( message );
       
 13523          free_data ( connect_data );     
       
 13524          return KErrGeneral;
       
 13525          }   
       
 13526      
       
 13527      // Close the connection
       
 13528      lm_connection_close ( connection, NULL );
       
 13529      
       
 13530      // Remove a reference on connection
       
 13531      lm_connection_unref ( connection );
       
 13532      
       
 13533      // Remove a reference on message
       
 13534      lm_message_unref ( message );
       
 13535      
       
 13536      free_data ( connect_data );
       
 13537      
       
 13538      // Message sending passed
       
 13539      iLog->Log ( _L ( "lm_connection_send passed" ) );
       
 13540      //second time
       
 13541      // Read a data from the CFG file
       
 13542           if ( read_data ( connect_data, aItem ) != RC_OK )
       
 13543               {
       
 13544               iLog->Log ( _L ( "read_data failed" ) );
       
 13545               free_data ( connect_data );
       
 13546               return KErrGeneral;
       
 13547               }
       
 13548           iLog->Log ( _L ( "after read_data" ) );
       
 13549           
       
 13550           // Open a new closed connection
       
 13551           connection = lm_connection_new ( connect_data->server );
       
 13552           iLog->Log ( _L ( "after lm_connection_new " ) );
       
 13553           if ( !connection )
       
 13554               {
       
 13555               iLog->Log ( _L ( "lm_connection_new failed" ) );
       
 13556               free_data ( connect_data );
       
 13557               return KErrGeneral;
       
 13558               }
       
 13559           
       
 13560           // Set the gtalk's SSL port
       
 13561           lm_connection_set_port ( connection, GTALK_SSL_PORT );
       
 13562           
       
 13563           // Set the JID
       
 13564           lm_connection_set_jid ( connection, connect_data->username );
       
 13565           
       
 13566           // Proxy settings for Emulator
       
 13567       #ifdef __WINSCW__
       
 13568           SetProxy ( connection, connect_data->proxy_data );
       
 13569       #endif
       
 13570           
       
 13571           // Set the connection to use SSL
       
 13572           SSLInit ( connection );
       
 13573           
       
 13574           //*main_loop = g_main_loop_new ( NULL, FALSE );
       
 13575 
       
 13576           iLog->Log ( _L ( "before lm_connection_open" ) );
       
 13577           
       
 13578           if ( !lm_connection_open ( connection, ( LmResultFunction ) connection_open_cb,
       
 13579                                      main_loop, NULL, NULL ) ) 
       
 13580               {
       
 13581               iLog->Log ( _L ( "lm_connection_open failed" ));
       
 13582               lm_connection_unref ( connection );
       
 13583               g_main_loop_unref ( main_loop );
       
 13584               free_data ( connect_data );     
       
 13585               return KErrGeneral;
       
 13586               }
       
 13587               
       
 13588           iLog->Log ( _L ( "after lm_connection_open" ) );
       
 13589           
       
 13590           g_main_loop_run ( main_loop );
       
 13591 
       
 13592           g_main_loop_unref ( main_loop );    
       
 13593 
       
 13594           
       
 13595             // *main_loop1 = g_main_loop_new ( NULL, FALSE );
       
 13596           
       
 13597           // Get the username from the JID
       
 13598           //*username = get_user_name ( connect_data->username );
       
 13599           
       
 13600           // Authenticate with the server
       
 13601           if ( !lm_connection_authenticate ( connection,
       
 13602                                            username,
       
 13603                                            connect_data->password,
       
 13604                                            connect_data->resource,
       
 13605                                             ( LmResultFunction ) connection_auth_cb,
       
 13606                                            main_loop1,NULL,NULL ) )
       
 13607               {
       
 13608               iLog->Log ( _L ( "lm_connection_authenticate failed" ) );
       
 13609               lm_connection_close ( connection, NULL );
       
 13610               lm_connection_unref ( connection );
       
 13611               free_data ( connect_data );
       
 13612               g_main_loop_unref ( main_loop1 );
       
 13613               g_free ( username );
       
 13614               return KErrGeneral;
       
 13615               }
       
 13616 
       
 13617           g_main_loop_run ( main_loop1 );
       
 13618 
       
 13619           g_main_loop_unref ( main_loop1 );
       
 13620               
       
 13621 
       
 13622           g_free ( username );
       
 13623           
       
 13624           // Construct a message
       
 13625           message = lm_message_new ( connect_data->msg_data->recipient,               
       
 13626                                      LM_MESSAGE_TYPE_MESSAGE );
       
 13627           lm_message_node_add_child ( message->node, "body", 
       
 13628                                       connect_data->msg_data->message);
       
 13629           
       
 13630           // Send message to the server
       
 13631           if ( !lm_connection_send ( connection, message, NULL ) )
       
 13632               {
       
 13633               iLog->Log ( _L ( "lm_connection_send failed" ) );
       
 13634               lm_connection_close ( connection, NULL );
       
 13635               lm_connection_unref ( connection );
       
 13636               lm_message_unref ( message );
       
 13637               free_data ( connect_data );     
       
 13638               return KErrGeneral;
       
 13639               }   
       
 13640           
       
 13641           // Close the connection
       
 13642           lm_connection_close ( connection, NULL );
       
 13643           
       
 13644           // Remove a reference on connection
       
 13645           lm_connection_unref ( connection );
       
 13646           
       
 13647           // Remove a reference on message
       
 13648           lm_message_unref ( message );
       
 13649           
       
 13650           free_data ( connect_data );
       
 13651           
       
 13652           // Message sending passed
       
 13653           iLog->Log ( _L ( "lm_connection_send passed" ) );
       
 13654           
       
 13655 //third time
       
 13656           // Read a data from the CFG file
       
 13657                if ( read_data ( connect_data, aItem ) != RC_OK )
       
 13658                    {
       
 13659                    iLog->Log ( _L ( "read_data failed" ) );
       
 13660                    free_data ( connect_data );
       
 13661                    return KErrGeneral;
       
 13662                    }
       
 13663                iLog->Log ( _L ( "after read_data" ) );
       
 13664                
       
 13665                // Open a new closed connection
       
 13666                connection = lm_connection_new ( connect_data->server );
       
 13667                iLog->Log ( _L ( "after lm_connection_new " ) );
       
 13668                if ( !connection )
       
 13669                    {
       
 13670                    iLog->Log ( _L ( "lm_connection_new failed" ) );
       
 13671                    free_data ( connect_data );
       
 13672                    return KErrGeneral;
       
 13673                    }
       
 13674                
       
 13675                // Set the gtalk's SSL port
       
 13676                lm_connection_set_port ( connection, GTALK_SSL_PORT );
       
 13677                
       
 13678                // Set the JID
       
 13679                lm_connection_set_jid ( connection, connect_data->username );
       
 13680                
       
 13681                // Proxy settings for Emulator
       
 13682            #ifdef __WINSCW__
       
 13683                SetProxy ( connection, connect_data->proxy_data );
       
 13684            #endif
       
 13685                
       
 13686                // Set the connection to use SSL
       
 13687                SSLInit ( connection );
       
 13688                
       
 13689               // *main_loop = g_main_loop_new ( NULL, FALSE );
       
 13690 
       
 13691                iLog->Log ( _L ( "before lm_connection_open" ) );
       
 13692                
       
 13693                if ( !lm_connection_open ( connection, ( LmResultFunction ) connection_open_cb,
       
 13694                                           main_loop, NULL, NULL ) ) 
       
 13695                    {
       
 13696                    iLog->Log ( _L ( "lm_connection_open failed" ));
       
 13697                    lm_connection_unref ( connection );
       
 13698                    g_main_loop_unref ( main_loop );
       
 13699                    free_data ( connect_data );     
       
 13700                    return KErrGeneral;
       
 13701                    }
       
 13702                    
       
 13703                iLog->Log ( _L ( "after lm_connection_open" ) );
       
 13704                
       
 13705                g_main_loop_run ( main_loop );
       
 13706 
       
 13707                g_main_loop_unref ( main_loop );    
       
 13708 
       
 13709                
       
 13710              // *main_loop1 = g_main_loop_new ( NULL, FALSE );
       
 13711                
       
 13712                // Get the username from the JID
       
 13713               // gchar *username = get_user_name ( connect_data->username );
       
 13714                
       
 13715                // Authenticate with the server
       
 13716                if ( !lm_connection_authenticate ( connection,
       
 13717                                                 username,
       
 13718                                                 connect_data->password,
       
 13719                                                 connect_data->resource,
       
 13720                                                  ( LmResultFunction ) connection_auth_cb,
       
 13721                                                 main_loop1,NULL,NULL ) )
       
 13722                    {
       
 13723                    iLog->Log ( _L ( "lm_connection_authenticate failed" ) );
       
 13724                    lm_connection_close ( connection, NULL );
       
 13725                    lm_connection_unref ( connection );
       
 13726                    free_data ( connect_data );
       
 13727                    g_main_loop_unref ( main_loop1 );
       
 13728                    g_free ( username );
       
 13729                    return KErrGeneral;
       
 13730                    }
       
 13731 
       
 13732                g_main_loop_run ( main_loop1 );
       
 13733 
       
 13734                g_main_loop_unref ( main_loop1 );
       
 13735                    
       
 13736 
       
 13737                g_free ( username );
       
 13738                
       
 13739                // Construct a message
       
 13740                message = lm_message_new ( connect_data->msg_data->recipient,               
       
 13741                                           LM_MESSAGE_TYPE_MESSAGE );
       
 13742                lm_message_node_add_child ( message->node, "body", 
       
 13743                                            connect_data->msg_data->message);
       
 13744                
       
 13745                // Send message to the server
       
 13746                if ( !lm_connection_send ( connection, message, NULL ) )
       
 13747                    {
       
 13748                    iLog->Log ( _L ( "lm_connection_send failed" ) );
       
 13749                    lm_connection_close ( connection, NULL );
       
 13750                    lm_connection_unref ( connection );
       
 13751                    lm_message_unref ( message );
       
 13752                    free_data ( connect_data );     
       
 13753                    return KErrGeneral;
       
 13754                    }   
       
 13755                
       
 13756                // Close the connection
       
 13757                lm_connection_close ( connection, NULL );
       
 13758                
       
 13759                // Remove a reference on connection
       
 13760                lm_connection_unref ( connection );
       
 13761                
       
 13762                // Remove a reference on message
       
 13763                lm_message_unref ( message );
       
 13764                
       
 13765                free_data ( connect_data );
       
 13766                
       
 13767                // Message sending passed
       
 13768                iLog->Log ( _L ( "lm_connection_send passed" ) );
       
 13769                
       
 13770 //fourth time
       
 13771                // Read a data from the CFG file
       
 13772                     if ( read_data ( connect_data, aItem ) != RC_OK )
       
 13773                         {
       
 13774                         iLog->Log ( _L ( "read_data failed" ) );
       
 13775                         free_data ( connect_data );
       
 13776                         return KErrGeneral;
       
 13777                         }
       
 13778                     iLog->Log ( _L ( "after read_data" ) );
       
 13779                     
       
 13780                     // Open a new closed connection
       
 13781                     connection = lm_connection_new ( connect_data->server );
       
 13782                     iLog->Log ( _L ( "after lm_connection_new " ) );
       
 13783                     if ( !connection )
       
 13784                         {
       
 13785                         iLog->Log ( _L ( "lm_connection_new failed" ) );
       
 13786                         free_data ( connect_data );
       
 13787                         return KErrGeneral;
       
 13788                         }
       
 13789                     
       
 13790                     // Set the gtalk's SSL port
       
 13791                     lm_connection_set_port ( connection, GTALK_SSL_PORT );
       
 13792                     
       
 13793                     // Set the JID
       
 13794                     lm_connection_set_jid ( connection, connect_data->username );
       
 13795                     
       
 13796                     // Proxy settings for Emulator
       
 13797                 #ifdef __WINSCW__
       
 13798                     SetProxy ( connection, connect_data->proxy_data );
       
 13799                 #endif
       
 13800                     
       
 13801                     // Set the connection to use SSL
       
 13802                     SSLInit ( connection );
       
 13803                     
       
 13804                    // *main_loop = g_main_loop_new ( NULL, FALSE );
       
 13805 
       
 13806                     iLog->Log ( _L ( "before lm_connection_open" ) );
       
 13807                     
       
 13808                     if ( !lm_connection_open ( connection, ( LmResultFunction ) connection_open_cb,
       
 13809                                                main_loop, NULL, NULL ) ) 
       
 13810                         {
       
 13811                         iLog->Log ( _L ( "lm_connection_open failed" ));
       
 13812                         lm_connection_unref ( connection );
       
 13813                         g_main_loop_unref ( main_loop );
       
 13814                         free_data ( connect_data );     
       
 13815                         return KErrGeneral;
       
 13816                         }
       
 13817                         
       
 13818                     iLog->Log ( _L ( "after lm_connection_open" ) );
       
 13819                     
       
 13820                     g_main_loop_run ( main_loop );
       
 13821 
       
 13822                     g_main_loop_unref ( main_loop );    
       
 13823 
       
 13824                     
       
 13825                    // *main_loop1 = g_main_loop_new ( NULL, FALSE );
       
 13826                     
       
 13827                     // Get the username from the JID
       
 13828                    // gchar *username = get_user_name ( connect_data->username );
       
 13829                     
       
 13830                     // Authenticate with the server
       
 13831                     if ( !lm_connection_authenticate ( connection,
       
 13832                                                      username,
       
 13833                                                      connect_data->password,
       
 13834                                                      connect_data->resource,
       
 13835                                                       ( LmResultFunction ) connection_auth_cb,
       
 13836                                                      main_loop1,NULL,NULL ) )
       
 13837                         {
       
 13838                         iLog->Log ( _L ( "lm_connection_authenticate failed" ) );
       
 13839                         lm_connection_close ( connection, NULL );
       
 13840                         lm_connection_unref ( connection );
       
 13841                         free_data ( connect_data );
       
 13842                         g_main_loop_unref ( main_loop1 );
       
 13843                         g_free ( username );
       
 13844                         return KErrGeneral;
       
 13845                         }
       
 13846 
       
 13847                     g_main_loop_run ( main_loop1 );
       
 13848 
       
 13849                     g_main_loop_unref ( main_loop1 );
       
 13850                         
       
 13851 
       
 13852                     g_free ( username );
       
 13853                     
       
 13854                     // Construct a message
       
 13855                     message = lm_message_new ( connect_data->msg_data->recipient,               
       
 13856                                                LM_MESSAGE_TYPE_MESSAGE );
       
 13857                     lm_message_node_add_child ( message->node, "body", 
       
 13858                                                 connect_data->msg_data->message);
       
 13859                     
       
 13860                     // Send message to the server
       
 13861                     if ( !lm_connection_send ( connection, message, NULL ) )
       
 13862                         {
       
 13863                         iLog->Log ( _L ( "lm_connection_send failed" ) );
       
 13864                         lm_connection_close ( connection, NULL );
       
 13865                         lm_connection_unref ( connection );
       
 13866                         lm_message_unref ( message );
       
 13867                         free_data ( connect_data );     
       
 13868                         return KErrGeneral;
       
 13869                         }   
       
 13870                     
       
 13871                     // Close the connection
       
 13872                     lm_connection_close ( connection, NULL );
       
 13873                     
       
 13874                     // Remove a reference on connection
       
 13875                     lm_connection_unref ( connection );
       
 13876                     
       
 13877                     // Remove a reference on message
       
 13878                     lm_message_unref ( message );
       
 13879                     
       
 13880                     free_data ( connect_data );
       
 13881                     
       
 13882                     // Message sending passed
       
 13883                     iLog->Log ( _L ( "lm_connection_send passed" ) );
       
 13884                     
       
 13885 //five time
       
 13886                     // Read a data from the CFG file
       
 13887                          if ( read_data ( connect_data, aItem ) != RC_OK )
       
 13888                              {
       
 13889                              iLog->Log ( _L ( "read_data failed" ) );
       
 13890                              free_data ( connect_data );
       
 13891                              return KErrGeneral;
       
 13892                              }
       
 13893                          iLog->Log ( _L ( "after read_data" ) );
       
 13894                          
       
 13895                          // Open a new closed connection
       
 13896                          connection = lm_connection_new ( connect_data->server );
       
 13897                          iLog->Log ( _L ( "after lm_connection_new " ) );
       
 13898                          if ( !connection )
       
 13899                              {
       
 13900                              iLog->Log ( _L ( "lm_connection_new failed" ) );
       
 13901                              free_data ( connect_data );
       
 13902                              return KErrGeneral;
       
 13903                              }
       
 13904                          
       
 13905                          // Set the gtalk's SSL port
       
 13906                          lm_connection_set_port ( connection, GTALK_SSL_PORT );
       
 13907                          
       
 13908                          // Set the JID
       
 13909                          lm_connection_set_jid ( connection, connect_data->username );
       
 13910                          
       
 13911                          // Proxy settings for Emulator
       
 13912                      #ifdef __WINSCW__
       
 13913                          SetProxy ( connection, connect_data->proxy_data );
       
 13914                      #endif
       
 13915                          
       
 13916                          // Set the connection to use SSL
       
 13917                          SSLInit ( connection );
       
 13918                          
       
 13919                      // *main_loop = g_main_loop_new ( NULL, FALSE );
       
 13920 
       
 13921                           iLog->Log ( _L ( "before lm_connection_open" ) );
       
 13922                          
       
 13923                          if ( !lm_connection_open ( connection, ( LmResultFunction ) connection_open_cb,
       
 13924                                                     main_loop, NULL, NULL ) ) 
       
 13925                              {
       
 13926                              iLog->Log ( _L ( "lm_connection_open failed" ));
       
 13927                              lm_connection_unref ( connection );
       
 13928                              g_main_loop_unref ( main_loop );
       
 13929                              free_data ( connect_data );     
       
 13930                              return KErrGeneral;
       
 13931                              }
       
 13932                              
       
 13933                          iLog->Log ( _L ( "after lm_connection_open" ) );
       
 13934                          
       
 13935                          g_main_loop_run ( main_loop );
       
 13936 
       
 13937                          g_main_loop_unref ( main_loop );    
       
 13938 
       
 13939                          
       
 13940                        //    *main_loop1 = g_main_loop_new ( NULL, FALSE );
       
 13941                          
       
 13942                          // Get the username from the JID
       
 13943                          //gchar *username = get_user_name ( connect_data->username );
       
 13944                          
       
 13945                          // Authenticate with the server
       
 13946                          if ( !lm_connection_authenticate ( connection,
       
 13947                                                           username,
       
 13948                                                           connect_data->password,
       
 13949                                                           connect_data->resource,
       
 13950                                                            ( LmResultFunction ) connection_auth_cb,
       
 13951                                                           main_loop1,NULL,NULL ) )
       
 13952                              {
       
 13953                              iLog->Log ( _L ( "lm_connection_authenticate failed" ) );
       
 13954                              lm_connection_close ( connection, NULL );
       
 13955                              lm_connection_unref ( connection );
       
 13956                              free_data ( connect_data );
       
 13957                              g_main_loop_unref ( main_loop1 );
       
 13958                              g_free ( username );
       
 13959                              return KErrGeneral;
       
 13960                              }
       
 13961 
       
 13962                          g_main_loop_run ( main_loop1 );
       
 13963 
       
 13964                          g_main_loop_unref ( main_loop1 );
       
 13965                              
       
 13966 
       
 13967                          g_free ( username );
       
 13968                          
       
 13969                          // Construct a message
       
 13970                          message = lm_message_new ( connect_data->msg_data->recipient,               
       
 13971                                                     LM_MESSAGE_TYPE_MESSAGE );
       
 13972                          lm_message_node_add_child ( message->node, "body", 
       
 13973                                                      connect_data->msg_data->message);
       
 13974                          
       
 13975                          // Send message to the server
       
 13976                          if ( !lm_connection_send ( connection, message, NULL ) )
       
 13977                              {
       
 13978                              iLog->Log ( _L ( "lm_connection_send failed" ) );
       
 13979                              lm_connection_close ( connection, NULL );
       
 13980                              lm_connection_unref ( connection );
       
 13981                              lm_message_unref ( message );
       
 13982                              free_data ( connect_data );     
       
 13983                              return KErrGeneral;
       
 13984                              }   
       
 13985                          
       
 13986                          // Close the connection
       
 13987                          lm_connection_close ( connection, NULL );
       
 13988                          
       
 13989                          // Remove a reference on connection
       
 13990                          lm_connection_unref ( connection );
       
 13991                          
       
 13992                          // Remove a reference on message
       
 13993                          lm_message_unref ( message );
       
 13994                          
       
 13995                          free_data ( connect_data );
       
 13996                          
       
 13997                          // Message sending passed
       
 13998                          iLog->Log ( _L ( "lm_connection_send passed" ) );
       
 13999                          
       
 14000 //fifth time
       
 14001                          // Read a data from the CFG file
       
 14002                               if ( read_data ( connect_data, aItem ) != RC_OK )
       
 14003                                   {
       
 14004                                   iLog->Log ( _L ( "read_data failed" ) );
       
 14005                                   free_data ( connect_data );
       
 14006                                   return KErrGeneral;
       
 14007                                   }
       
 14008                               iLog->Log ( _L ( "after read_data" ) );
       
 14009                               
       
 14010                               // Open a new closed connection
       
 14011                               connection = lm_connection_new ( connect_data->server );
       
 14012                               iLog->Log ( _L ( "after lm_connection_new " ) );
       
 14013                               if ( !connection )
       
 14014                                   {
       
 14015                                   iLog->Log ( _L ( "lm_connection_new failed" ) );
       
 14016                                   free_data ( connect_data );
       
 14017                                   return KErrGeneral;
       
 14018                                   }
       
 14019                               
       
 14020                               // Set the gtalk's SSL port
       
 14021                               lm_connection_set_port ( connection, GTALK_SSL_PORT );
       
 14022                               
       
 14023                               // Set the JID
       
 14024                               lm_connection_set_jid ( connection, connect_data->username );
       
 14025                               
       
 14026                               // Proxy settings for Emulator
       
 14027                           #ifdef __WINSCW__
       
 14028                               SetProxy ( connection, connect_data->proxy_data );
       
 14029                           #endif
       
 14030                               
       
 14031                               // Set the connection to use SSL
       
 14032                               SSLInit ( connection );
       
 14033                               
       
 14034                           //    *main_loop = g_main_loop_new ( NULL, FALSE );
       
 14035 
       
 14036                               iLog->Log ( _L ( "before lm_connection_open" ) );
       
 14037                               
       
 14038                               if ( !lm_connection_open ( connection, ( LmResultFunction ) connection_open_cb,
       
 14039                                                          main_loop, NULL, NULL ) ) 
       
 14040                                   {
       
 14041                                   iLog->Log ( _L ( "lm_connection_open failed" ));
       
 14042                                   lm_connection_unref ( connection );
       
 14043                                   g_main_loop_unref ( main_loop );
       
 14044                                   free_data ( connect_data );     
       
 14045                                   return KErrGeneral;
       
 14046                                   }
       
 14047                                   
       
 14048                               iLog->Log ( _L ( "after lm_connection_open" ) );
       
 14049                               
       
 14050                               g_main_loop_run ( main_loop );
       
 14051 
       
 14052                               g_main_loop_unref ( main_loop );    
       
 14053 
       
 14054                               
       
 14055                        //        *main_loop1 = g_main_loop_new ( NULL, FALSE );
       
 14056                               
       
 14057                               // Get the username from the JID
       
 14058                               //gchar *username = get_user_name ( connect_data->username );
       
 14059                               
       
 14060                               // Authenticate with the server
       
 14061                               if ( !lm_connection_authenticate ( connection,
       
 14062                                                                username,
       
 14063                                                                connect_data->password,
       
 14064                                                                connect_data->resource,
       
 14065                                                                 ( LmResultFunction ) connection_auth_cb,
       
 14066                                                                main_loop1,NULL,NULL ) )
       
 14067                                   {
       
 14068                                   iLog->Log ( _L ( "lm_connection_authenticate failed" ) );
       
 14069                                   lm_connection_close ( connection, NULL );
       
 14070                                   lm_connection_unref ( connection );
       
 14071                                   free_data ( connect_data );
       
 14072                                   g_main_loop_unref ( main_loop1 );
       
 14073                                   g_free ( username );
       
 14074                                   return KErrGeneral;
       
 14075                                   }
       
 14076 
       
 14077                               g_main_loop_run ( main_loop1 );
       
 14078 
       
 14079                               g_main_loop_unref ( main_loop1 );
       
 14080                                   
       
 14081 
       
 14082                               g_free ( username );
       
 14083                               
       
 14084                               // Construct a message
       
 14085                               message = lm_message_new ( connect_data->msg_data->recipient,               
       
 14086                                                          LM_MESSAGE_TYPE_MESSAGE );
       
 14087                               lm_message_node_add_child ( message->node, "body", 
       
 14088                                                           connect_data->msg_data->message);
       
 14089                               
       
 14090                               // Send message to the server
       
 14091                               if ( !lm_connection_send ( connection, message, NULL ) )
       
 14092                                   {
       
 14093                                   iLog->Log ( _L ( "lm_connection_send failed" ) );
       
 14094                                   lm_connection_close ( connection, NULL );
       
 14095                                   lm_connection_unref ( connection );
       
 14096                                   lm_message_unref ( message );
       
 14097                                   free_data ( connect_data );     
       
 14098                                   return KErrGeneral;
       
 14099                                   }   
       
 14100                               
       
 14101                               // Close the connection
       
 14102                               lm_connection_close ( connection, NULL );
       
 14103                               
       
 14104                               // Remove a reference on connection
       
 14105                               lm_connection_unref ( connection );
       
 14106                               
       
 14107                               // Remove a reference on message
       
 14108                               lm_message_unref ( message );
       
 14109                               
       
 14110                               free_data ( connect_data );
       
 14111                               
       
 14112                               // Message sending passed
       
 14113                               iLog->Log ( _L ( "lm_connection_send passed" ) );
       
 14114                               
       
 14115 //sixth time
       
 14116                               // Read a data from the CFG file
       
 14117                                    if ( read_data ( connect_data, aItem ) != RC_OK )
       
 14118                                        {
       
 14119                                        iLog->Log ( _L ( "read_data failed" ) );
       
 14120                                        free_data ( connect_data );
       
 14121                                        return KErrGeneral;
       
 14122                                        }
       
 14123                                    iLog->Log ( _L ( "after read_data" ) );
       
 14124                                    
       
 14125                                    // Open a new closed connection
       
 14126                                    connection = lm_connection_new ( connect_data->server );
       
 14127                                    iLog->Log ( _L ( "after lm_connection_new " ) );
       
 14128                                    if ( !connection )
       
 14129                                        {
       
 14130                                        iLog->Log ( _L ( "lm_connection_new failed" ) );
       
 14131                                        free_data ( connect_data );
       
 14132                                        return KErrGeneral;
       
 14133                                        }
       
 14134                                    
       
 14135                                    // Set the gtalk's SSL port
       
 14136                                    lm_connection_set_port ( connection, GTALK_SSL_PORT );
       
 14137                                    
       
 14138                                    // Set the JID
       
 14139                                    lm_connection_set_jid ( connection, connect_data->username );
       
 14140                                    
       
 14141                                    // Proxy settings for Emulator
       
 14142                                #ifdef __WINSCW__
       
 14143                                    SetProxy ( connection, connect_data->proxy_data );
       
 14144                                #endif
       
 14145                                    
       
 14146                                    // Set the connection to use SSL
       
 14147                                    SSLInit ( connection );
       
 14148                                    
       
 14149                         //        *main_loop = g_main_loop_new ( NULL, FALSE );
       
 14150 
       
 14151                                    iLog->Log ( _L ( "before lm_connection_open" ) );
       
 14152                                    
       
 14153                                    if ( !lm_connection_open ( connection, ( LmResultFunction ) connection_open_cb,
       
 14154                                                               main_loop, NULL, NULL ) ) 
       
 14155                                        {
       
 14156                                        iLog->Log ( _L ( "lm_connection_open failed" ));
       
 14157                                        lm_connection_unref ( connection );
       
 14158                                        g_main_loop_unref ( main_loop );
       
 14159                                        free_data ( connect_data );     
       
 14160                                        return KErrGeneral;
       
 14161                                        }
       
 14162                                        
       
 14163                                    iLog->Log ( _L ( "after lm_connection_open" ) );
       
 14164                                    
       
 14165                                    g_main_loop_run ( main_loop );
       
 14166 
       
 14167                                    g_main_loop_unref ( main_loop );    
       
 14168 
       
 14169                                    
       
 14170                                   // GMainLoop   *main_loop1 = g_main_loop_new ( NULL, FALSE );
       
 14171                                    
       
 14172                                    // Get the username from the JID
       
 14173                                    //gchar *username = get_user_name ( connect_data->username );
       
 14174                                    
       
 14175                                    // Authenticate with the server
       
 14176                                    if ( !lm_connection_authenticate ( connection,
       
 14177                                                                     username,
       
 14178                                                                     connect_data->password,
       
 14179                                                                     connect_data->resource,
       
 14180                                                                      ( LmResultFunction ) connection_auth_cb,
       
 14181                                                                     main_loop1,NULL,NULL ) )
       
 14182                                        {
       
 14183                                        iLog->Log ( _L ( "lm_connection_authenticate failed" ) );
       
 14184                                        lm_connection_close ( connection, NULL );
       
 14185                                        lm_connection_unref ( connection );
       
 14186                                        free_data ( connect_data );
       
 14187                                        g_main_loop_unref ( main_loop1 );
       
 14188                                        g_free ( username );
       
 14189                                        return KErrGeneral;
       
 14190                                        }
       
 14191 
       
 14192                                    g_main_loop_run ( main_loop1 );
       
 14193 
       
 14194                                    g_main_loop_unref ( main_loop1 );
       
 14195                                        
       
 14196 
       
 14197                                    g_free ( username );
       
 14198                                    
       
 14199                                    // Construct a message
       
 14200                                    message = lm_message_new ( connect_data->msg_data->recipient,               
       
 14201                                                               LM_MESSAGE_TYPE_MESSAGE );
       
 14202                                    lm_message_node_add_child ( message->node, "body", 
       
 14203                                                                connect_data->msg_data->message);
       
 14204                                    
       
 14205                                    // Send message to the server
       
 14206                                    if ( !lm_connection_send ( connection, message, NULL ) )
       
 14207                                        {
       
 14208                                        iLog->Log ( _L ( "lm_connection_send failed" ) );
       
 14209                                        lm_connection_close ( connection, NULL );
       
 14210                                        lm_connection_unref ( connection );
       
 14211                                        lm_message_unref ( message );
       
 14212                                        free_data ( connect_data );     
       
 14213                                        return KErrGeneral;
       
 14214                                        }   
       
 14215                                    
       
 14216                                    // Close the connection
       
 14217                                    lm_connection_close ( connection, NULL );
       
 14218                                    
       
 14219                                    // Remove a reference on connection
       
 14220                                    lm_connection_unref ( connection );
       
 14221                                    
       
 14222                                    // Remove a reference on message
       
 14223                                    lm_message_unref ( message );
       
 14224                                    
       
 14225                                    free_data ( connect_data );
       
 14226                                    
       
 14227                                    // Message sending passed
       
 14228                                    iLog->Log ( _L ( "lm_connection_send passed" ) );
       
 14229                                    
       
 14230 //seventh time
       
 14231                                    // Read a data from the CFG file
       
 14232                                         if ( read_data ( connect_data, aItem ) != RC_OK )
       
 14233                                             {
       
 14234                                             iLog->Log ( _L ( "read_data failed" ) );
       
 14235                                             free_data ( connect_data );
       
 14236                                             return KErrGeneral;
       
 14237                                             }
       
 14238                                         iLog->Log ( _L ( "after read_data" ) );
       
 14239                                         
       
 14240                                         // Open a new closed connection
       
 14241                                         connection = lm_connection_new ( connect_data->server );
       
 14242                                         iLog->Log ( _L ( "after lm_connection_new " ) );
       
 14243                                         if ( !connection )
       
 14244                                             {
       
 14245                                             iLog->Log ( _L ( "lm_connection_new failed" ) );
       
 14246                                             free_data ( connect_data );
       
 14247                                             return KErrGeneral;
       
 14248                                             }
       
 14249                                         
       
 14250                                         // Set the gtalk's SSL port
       
 14251                                         lm_connection_set_port ( connection, GTALK_SSL_PORT );
       
 14252                                         
       
 14253                                         // Set the JID
       
 14254                                         lm_connection_set_jid ( connection, connect_data->username );
       
 14255                                         
       
 14256                                         // Proxy settings for Emulator
       
 14257                                     #ifdef __WINSCW__
       
 14258                                         SetProxy ( connection, connect_data->proxy_data );
       
 14259                                     #endif
       
 14260                                         
       
 14261                                         // Set the connection to use SSL
       
 14262                                         SSLInit ( connection );
       
 14263                                         
       
 14264                                //          *main_loop = g_main_loop_new ( NULL, FALSE );
       
 14265 
       
 14266                                         iLog->Log ( _L ( "before lm_connection_open" ) );
       
 14267                                         
       
 14268                                         if ( !lm_connection_open ( connection, ( LmResultFunction ) connection_open_cb,
       
 14269                                                                    main_loop, NULL, NULL ) ) 
       
 14270                                             {
       
 14271                                             iLog->Log ( _L ( "lm_connection_open failed" ));
       
 14272                                             lm_connection_unref ( connection );
       
 14273                                             g_main_loop_unref ( main_loop );
       
 14274                                             free_data ( connect_data );     
       
 14275                                             return KErrGeneral;
       
 14276                                             }
       
 14277                                             
       
 14278                                         iLog->Log ( _L ( "after lm_connection_open" ) );
       
 14279                                         
       
 14280                                         g_main_loop_run ( main_loop );
       
 14281 
       
 14282                                         g_main_loop_unref ( main_loop );    
       
 14283 
       
 14284                                         
       
 14285                                   //      GMainLoop   *main_loop1 = g_main_loop_new ( NULL, FALSE );
       
 14286                                         
       
 14287                                         // Get the username from the JID
       
 14288                                         //gchar *username = get_user_name ( connect_data->username );
       
 14289                                         
       
 14290                                         // Authenticate with the server
       
 14291                                         if ( !lm_connection_authenticate ( connection,
       
 14292                                                                          username,
       
 14293                                                                          connect_data->password,
       
 14294                                                                          connect_data->resource,
       
 14295                                                                           ( LmResultFunction ) connection_auth_cb,
       
 14296                                                                          main_loop1,NULL,NULL ) )
       
 14297                                             {
       
 14298                                             iLog->Log ( _L ( "lm_connection_authenticate failed" ) );
       
 14299                                             lm_connection_close ( connection, NULL );
       
 14300                                             lm_connection_unref ( connection );
       
 14301                                             free_data ( connect_data );
       
 14302                                             g_main_loop_unref ( main_loop1 );
       
 14303                                             g_free ( username );
       
 14304                                             return KErrGeneral;
       
 14305                                             }
       
 14306 
       
 14307                                         g_main_loop_run ( main_loop1 );
       
 14308 
       
 14309                                         g_main_loop_unref ( main_loop1 );
       
 14310                                             
       
 14311 
       
 14312                                         g_free ( username );
       
 14313                                         
       
 14314                                         // Construct a message
       
 14315                                         message = lm_message_new ( connect_data->msg_data->recipient,               
       
 14316                                                                    LM_MESSAGE_TYPE_MESSAGE );
       
 14317                                         lm_message_node_add_child ( message->node, "body", 
       
 14318                                                                     connect_data->msg_data->message);
       
 14319                                         
       
 14320                                         // Send message to the server
       
 14321                                         if ( !lm_connection_send ( connection, message, NULL ) )
       
 14322                                             {
       
 14323                                             iLog->Log ( _L ( "lm_connection_send failed" ) );
       
 14324                                             lm_connection_close ( connection, NULL );
       
 14325                                             lm_connection_unref ( connection );
       
 14326                                             lm_message_unref ( message );
       
 14327                                             free_data ( connect_data );     
       
 14328                                             return KErrGeneral;
       
 14329                                             }   
       
 14330                                         
       
 14331                                         // Close the connection
       
 14332                                         lm_connection_close ( connection, NULL );
       
 14333                                         
       
 14334                                         // Remove a reference on connection
       
 14335                                         lm_connection_unref ( connection );
       
 14336                                         
       
 14337                                         // Remove a reference on message
       
 14338                                         lm_message_unref ( message );
       
 14339                                         
       
 14340                                         free_data ( connect_data );
       
 14341                                         
       
 14342                                         // Message sending passed
       
 14343                                         iLog->Log ( _L ( "lm_connection_send passed" ) );
       
 14344                                         
       
 14345 //eight time
       
 14346                                         // Read a data from the CFG file
       
 14347                                              if ( read_data ( connect_data, aItem ) != RC_OK )
       
 14348                                                  {
       
 14349                                                  iLog->Log ( _L ( "read_data failed" ) );
       
 14350                                                  free_data ( connect_data );
       
 14351                                                  return KErrGeneral;
       
 14352                                                  }
       
 14353                                              iLog->Log ( _L ( "after read_data" ) );
       
 14354                                              
       
 14355                                              // Open a new closed connection
       
 14356                                              connection = lm_connection_new ( connect_data->server );
       
 14357                                              iLog->Log ( _L ( "after lm_connection_new " ) );
       
 14358                                              if ( !connection )
       
 14359                                                  {
       
 14360                                                  iLog->Log ( _L ( "lm_connection_new failed" ) );
       
 14361                                                  free_data ( connect_data );
       
 14362                                                  return KErrGeneral;
       
 14363                                                  }
       
 14364                                              
       
 14365                                              // Set the gtalk's SSL port
       
 14366                                              lm_connection_set_port ( connection, GTALK_SSL_PORT );
       
 14367                                              
       
 14368                                              // Set the JID
       
 14369                                              lm_connection_set_jid ( connection, connect_data->username );
       
 14370                                              
       
 14371                                              // Proxy settings for Emulator
       
 14372                                          #ifdef __WINSCW__
       
 14373                                              SetProxy ( connection, connect_data->proxy_data );
       
 14374                                          #endif
       
 14375                                              
       
 14376                                              // Set the connection to use SSL
       
 14377                                              SSLInit ( connection );
       
 14378                                              
       
 14379                               //                *main_loop = g_main_loop_new ( NULL, FALSE );
       
 14380 
       
 14381                                              iLog->Log ( _L ( "before lm_connection_open" ) );
       
 14382                                              
       
 14383                                              if ( !lm_connection_open ( connection, ( LmResultFunction ) connection_open_cb,
       
 14384                                                                         main_loop, NULL, NULL ) ) 
       
 14385                                                  {
       
 14386                                                  iLog->Log ( _L ( "lm_connection_open failed" ));
       
 14387                                                  lm_connection_unref ( connection );
       
 14388                                                  g_main_loop_unref ( main_loop );
       
 14389                                                  free_data ( connect_data );     
       
 14390                                                  return KErrGeneral;
       
 14391                                                  }
       
 14392                                                  
       
 14393                                              iLog->Log ( _L ( "after lm_connection_open" ) );
       
 14394                                              
       
 14395                                              g_main_loop_run ( main_loop );
       
 14396 
       
 14397                                              g_main_loop_unref ( main_loop );    
       
 14398 
       
 14399                                              
       
 14400                                     //         GMainLoop   *main_loop1 = g_main_loop_new ( NULL, FALSE );
       
 14401                                              
       
 14402                                              // Get the username from the JID
       
 14403                                              //gchar *username = get_user_name ( connect_data->username );
       
 14404                                              
       
 14405                                              // Authenticate with the server
       
 14406                                              if ( !lm_connection_authenticate ( connection,
       
 14407                                                                               username,
       
 14408                                                                               connect_data->password,
       
 14409                                                                               connect_data->resource,
       
 14410                                                                                ( LmResultFunction ) connection_auth_cb,
       
 14411                                                                               main_loop1,NULL,NULL ) )
       
 14412                                                  {
       
 14413                                                  iLog->Log ( _L ( "lm_connection_authenticate failed" ) );
       
 14414                                                  lm_connection_close ( connection, NULL );
       
 14415                                                  lm_connection_unref ( connection );
       
 14416                                                  free_data ( connect_data );
       
 14417                                                  g_main_loop_unref ( main_loop1 );
       
 14418                                                  g_free ( username );
       
 14419                                                  return KErrGeneral;
       
 14420                                                  }
       
 14421 
       
 14422                                              g_main_loop_run ( main_loop1 );
       
 14423 
       
 14424                                              g_main_loop_unref ( main_loop1 );
       
 14425                                                  
       
 14426 
       
 14427                                              g_free ( username );
       
 14428                                              
       
 14429                                              // Construct a message
       
 14430                                              message = lm_message_new ( connect_data->msg_data->recipient,               
       
 14431                                                                         LM_MESSAGE_TYPE_MESSAGE );
       
 14432                                              lm_message_node_add_child ( message->node, "body", 
       
 14433                                                                          connect_data->msg_data->message);
       
 14434                                              
       
 14435                                              // Send message to the server
       
 14436                                              if ( !lm_connection_send ( connection, message, NULL ) )
       
 14437                                                  {
       
 14438                                                  iLog->Log ( _L ( "lm_connection_send failed" ) );
       
 14439                                                  lm_connection_close ( connection, NULL );
       
 14440                                                  lm_connection_unref ( connection );
       
 14441                                                  lm_message_unref ( message );
       
 14442                                                  free_data ( connect_data );     
       
 14443                                                  return KErrGeneral;
       
 14444                                                  }   
       
 14445                                              
       
 14446                                              // Close the connection
       
 14447                                              lm_connection_close ( connection, NULL );
       
 14448                                              
       
 14449                                              // Remove a reference on connection
       
 14450                                              lm_connection_unref ( connection );
       
 14451                                              
       
 14452                                              // Remove a reference on message
       
 14453                                              lm_message_unref ( message );
       
 14454                                              
       
 14455                                              free_data ( connect_data );
       
 14456                                              
       
 14457                                              // Message sending passed
       
 14458                                              iLog->Log ( _L ( "lm_connection_send passed" ) );
       
 14459                                              
       
 14460 //ninth time
       
 14461                                              // Read a data from the CFG file
       
 14462                                                   if ( read_data ( connect_data, aItem ) != RC_OK )
       
 14463                                                       {
       
 14464                                                       iLog->Log ( _L ( "read_data failed" ) );
       
 14465                                                       free_data ( connect_data );
       
 14466                                                       return KErrGeneral;
       
 14467                                                       }
       
 14468                                                   iLog->Log ( _L ( "after read_data" ) );
       
 14469                                                   
       
 14470                                                   // Open a new closed connection
       
 14471                                                   connection = lm_connection_new ( connect_data->server );
       
 14472                                                   iLog->Log ( _L ( "after lm_connection_new " ) );
       
 14473                                                   if ( !connection )
       
 14474                                                       {
       
 14475                                                       iLog->Log ( _L ( "lm_connection_new failed" ) );
       
 14476                                                       free_data ( connect_data );
       
 14477                                                       return KErrGeneral;
       
 14478                                                       }
       
 14479                                                   
       
 14480                                                   // Set the gtalk's SSL port
       
 14481                                                   lm_connection_set_port ( connection, GTALK_SSL_PORT );
       
 14482                                                   
       
 14483                                                   // Set the JID
       
 14484                                                   lm_connection_set_jid ( connection, connect_data->username );
       
 14485                                                   
       
 14486                                                   // Proxy settings for Emulator
       
 14487                                               #ifdef __WINSCW__
       
 14488                                                   SetProxy ( connection, connect_data->proxy_data );
       
 14489                                               #endif
       
 14490                                                   
       
 14491                                                   // Set the connection to use SSL
       
 14492                                                   SSLInit ( connection );
       
 14493                                                   
       
 14494                                        //            *main_loop = g_main_loop_new ( NULL, FALSE );
       
 14495 
       
 14496                                                   iLog->Log ( _L ( "before lm_connection_open" ) );
       
 14497                                                   
       
 14498                                                   if ( !lm_connection_open ( connection, ( LmResultFunction ) connection_open_cb,
       
 14499                                                                              main_loop, NULL, NULL ) ) 
       
 14500                                                       {
       
 14501                                                       iLog->Log ( _L ( "lm_connection_open failed" ));
       
 14502                                                       lm_connection_unref ( connection );
       
 14503                                                       g_main_loop_unref ( main_loop );
       
 14504                                                       free_data ( connect_data );     
       
 14505                                                       return KErrGeneral;
       
 14506                                                       }
       
 14507                                                       
       
 14508                                                   iLog->Log ( _L ( "after lm_connection_open" ) );
       
 14509                                                   
       
 14510                                                   g_main_loop_run ( main_loop );
       
 14511 
       
 14512                                                   g_main_loop_unref ( main_loop );    
       
 14513 
       
 14514                                                   
       
 14515                                           //        GMainLoop   *main_loop1 = g_main_loop_new ( NULL, FALSE );
       
 14516                                                   
       
 14517                                                   // Get the username from the JID
       
 14518                                                   //gchar *username = get_user_name ( connect_data->username );
       
 14519                                                   
       
 14520                                                   // Authenticate with the server
       
 14521                                                   if ( !lm_connection_authenticate ( connection,
       
 14522                                                                                    username,
       
 14523                                                                                    connect_data->password,
       
 14524                                                                                    connect_data->resource,
       
 14525                                                                                     ( LmResultFunction ) connection_auth_cb,
       
 14526                                                                                    main_loop1,NULL,NULL ) )
       
 14527                                                       {
       
 14528                                                       iLog->Log ( _L ( "lm_connection_authenticate failed" ) );
       
 14529                                                       lm_connection_close ( connection, NULL );
       
 14530                                                       lm_connection_unref ( connection );
       
 14531                                                       free_data ( connect_data );
       
 14532                                                       g_main_loop_unref ( main_loop1 );
       
 14533                                                       g_free ( username );
       
 14534                                                       return KErrGeneral;
       
 14535                                                       }
       
 14536 
       
 14537                                                   g_main_loop_run ( main_loop1 );
       
 14538 
       
 14539                                                   g_main_loop_unref ( main_loop1 );
       
 14540                                                       
       
 14541 
       
 14542                                                   g_free ( username );
       
 14543                                                   
       
 14544                                                   // Construct a message
       
 14545                                                   message = lm_message_new ( connect_data->msg_data->recipient,               
       
 14546                                                                              LM_MESSAGE_TYPE_MESSAGE );
       
 14547                                                   lm_message_node_add_child ( message->node, "body", 
       
 14548                                                                               connect_data->msg_data->message);
       
 14549                                                   
       
 14550                                                   // Send message to the server
       
 14551                                                   if ( !lm_connection_send ( connection, message, NULL ) )
       
 14552                                                       {
       
 14553                                                       iLog->Log ( _L ( "lm_connection_send failed" ) );
       
 14554                                                       lm_connection_close ( connection, NULL );
       
 14555                                                       lm_connection_unref ( connection );
       
 14556                                                       lm_message_unref ( message );
       
 14557                                                       free_data ( connect_data );     
       
 14558                                                       return KErrGeneral;
       
 14559                                                       }   
       
 14560                                                   
       
 14561                                                   // Close the connection
       
 14562                                                   lm_connection_close ( connection, NULL );
       
 14563                                                   
       
 14564                                                   // Remove a reference on connection
       
 14565                                                   lm_connection_unref ( connection );
       
 14566                                                   
       
 14567                                                   // Remove a reference on message
       
 14568                                                   lm_message_unref ( message );
       
 14569                                                   
       
 14570                                                   free_data ( connect_data );
       
 14571                                                   
       
 14572                                                   // Message sending passed
       
 14573                                                   iLog->Log ( _L ( "lm_connection_send passed" ) );
       
 14574                                                   
       
 14575 //tenth time
       
 14576                                                   // Read a data from the CFG file
       
 14577                                                        if ( read_data ( connect_data, aItem ) != RC_OK )
       
 14578                                                            {
       
 14579                                                            iLog->Log ( _L ( "read_data failed" ) );
       
 14580                                                            free_data ( connect_data );
       
 14581                                                            return KErrGeneral;
       
 14582                                                            }
       
 14583                                                        iLog->Log ( _L ( "after read_data" ) );
       
 14584                                                        
       
 14585                                                        // Open a new closed connection
       
 14586                                                        connection = lm_connection_new ( connect_data->server );
       
 14587                                                        iLog->Log ( _L ( "after lm_connection_new " ) );
       
 14588                                                        if ( !connection )
       
 14589                                                            {
       
 14590                                                            iLog->Log ( _L ( "lm_connection_new failed" ) );
       
 14591                                                            free_data ( connect_data );
       
 14592                                                            return KErrGeneral;
       
 14593                                                            }
       
 14594                                                        
       
 14595                                                        // Set the gtalk's SSL port
       
 14596                                                        lm_connection_set_port ( connection, GTALK_SSL_PORT );
       
 14597                                                        
       
 14598                                                        // Set the JID
       
 14599                                                        lm_connection_set_jid ( connection, connect_data->username );
       
 14600                                                        
       
 14601                                                        // Proxy settings for Emulator
       
 14602                                                    #ifdef __WINSCW__
       
 14603                                                        SetProxy ( connection, connect_data->proxy_data );
       
 14604                                                    #endif
       
 14605                                                        
       
 14606                                                        // Set the connection to use SSL
       
 14607                                                        SSLInit ( connection );
       
 14608                                                        
       
 14609                                              //           *main_loop = g_main_loop_new ( NULL, FALSE );
       
 14610 
       
 14611                                                        iLog->Log ( _L ( "before lm_connection_open" ) );
       
 14612                                                        
       
 14613                                                        if ( !lm_connection_open ( connection, ( LmResultFunction ) connection_open_cb,
       
 14614                                                                                   main_loop, NULL, NULL ) ) 
       
 14615                                                            {
       
 14616                                                            iLog->Log ( _L ( "lm_connection_open failed" ));
       
 14617                                                            lm_connection_unref ( connection );
       
 14618                                                            g_main_loop_unref ( main_loop );
       
 14619                                                            free_data ( connect_data );     
       
 14620                                                            return KErrGeneral;
       
 14621                                                            }
       
 14622                                                            
       
 14623                                                        iLog->Log ( _L ( "after lm_connection_open" ) );
       
 14624                                                        
       
 14625                                                        g_main_loop_run ( main_loop );
       
 14626 
       
 14627                                                        g_main_loop_unref ( main_loop );    
       
 14628 
       
 14629                                                        
       
 14630                                             //           GMainLoop   *main_loop1 = g_main_loop_new ( NULL, FALSE );
       
 14631                                                        
       
 14632                                                        // Get the username from the JID
       
 14633                                                        //gchar *username = get_user_name ( connect_data->username );
       
 14634                                                        
       
 14635                                                        // Authenticate with the server
       
 14636                                                        if ( !lm_connection_authenticate ( connection,
       
 14637                                                                                         username,
       
 14638                                                                                         connect_data->password,
       
 14639                                                                                         connect_data->resource,
       
 14640                                                                                          ( LmResultFunction ) connection_auth_cb,
       
 14641                                                                                         main_loop1,NULL,NULL ) )
       
 14642                                                            {
       
 14643                                                            iLog->Log ( _L ( "lm_connection_authenticate failed" ) );
       
 14644                                                            lm_connection_close ( connection, NULL );
       
 14645                                                            lm_connection_unref ( connection );
       
 14646                                                            free_data ( connect_data );
       
 14647                                                            g_main_loop_unref ( main_loop1 );
       
 14648                                                            g_free ( username );
       
 14649                                                            return KErrGeneral;
       
 14650                                                            }
       
 14651 
       
 14652                                                        g_main_loop_run ( main_loop1 );
       
 14653 
       
 14654                                                        g_main_loop_unref ( main_loop1 );
       
 14655                                                            
       
 14656 
       
 14657                                                        g_free ( username );
       
 14658                                                        
       
 14659                                                        // Construct a message
       
 14660                                                        message = lm_message_new ( connect_data->msg_data->recipient,               
       
 14661                                                                                   LM_MESSAGE_TYPE_MESSAGE );
       
 14662                                                        lm_message_node_add_child ( message->node, "body", 
       
 14663                                                                                    connect_data->msg_data->message);
       
 14664                                                        
       
 14665                                                        // Send message to the server
       
 14666                                                        if ( !lm_connection_send ( connection, message, NULL ) )
       
 14667                                                            {
       
 14668                                                            iLog->Log ( _L ( "lm_connection_send failed" ) );
       
 14669                                                            lm_connection_close ( connection, NULL );
       
 14670                                                            lm_connection_unref ( connection );
       
 14671                                                            lm_message_unref ( message );
       
 14672                                                            free_data ( connect_data );     
       
 14673                                                            return KErrGeneral;
       
 14674                                                            }   
       
 14675                                                        
       
 14676                                                        // Close the connection
       
 14677                                                        lm_connection_close ( connection, NULL );
       
 14678                                                        
       
 14679                                                        // Remove a reference on connection
       
 14680                                                        lm_connection_unref ( connection );
       
 14681                                                        
       
 14682                                                        // Remove a reference on message
       
 14683                                                        lm_message_unref ( message );
       
 14684                                                        
       
 14685                                                        free_data ( connect_data );
       
 14686                                                        
       
 14687                                                        // Message sending passed
       
 14688                                                        iLog->Log ( _L ( "lm_nft_loginlogoutmultipletime" ) );
       
 14689                                                        
       
 14690                                                   
       
 14691      return KErrNone;
       
 14692 }
       
 14693  
       
 14694  TInt Ctstlm::lm_nft_receiving100_message_L(CStifItemParser& aItem)
       
 14695      {
       
 14696      LmConnection *connection   = NULL;
       
 14697      ConnectData  *connect_data = NULL;
       
 14698      LmMessage    *message = NULL;
       
 14699      LmMessageHandler *handler = NULL;
       
 14700      HandleData *handle_data = NULL;
       
 14701      
       
 14702      iLog->Log ( _L ( "lm_nft_receiving100_message_L" ) );
       
 14703      
       
 14704      // Read a data from the CFG file
       
 14705      if ( read_data ( connect_data, aItem ) != RC_OK )
       
 14706          {
       
 14707          iLog->Log ( _L ( "read_data failed" ) );
       
 14708          free_data ( connect_data );
       
 14709          return KErrGeneral;
       
 14710          }
       
 14711      iLog->Log ( _L ( "after read_data" ) );
       
 14712      
       
 14713      // Open a new closed connection
       
 14714      connection = lm_connection_new ( connect_data->server );
       
 14715      iLog->Log ( _L ( "after lm_connection_new " ) );
       
 14716      if ( !connection )
       
 14717          {
       
 14718          iLog->Log ( _L ( "lm_connection_new failed" ) );
       
 14719          free_data ( connect_data );
       
 14720          return KErrGeneral;
       
 14721          }
       
 14722      
       
 14723      // Set the gtalk's SSL port
       
 14724      lm_connection_set_port ( connection, GTALK_SSL_PORT );
       
 14725      
       
 14726      // Set the JID
       
 14727      lm_connection_set_jid ( connection, connect_data->username );
       
 14728      
       
 14729      // Proxy settings for Emulator
       
 14730  #ifdef __WINSCW__
       
 14731      SetProxy ( connection, connect_data->proxy_data );
       
 14732  #endif
       
 14733      
       
 14734      // Set the connection to use SSL
       
 14735      SSLInit ( connection );
       
 14736      
       
 14737      GMainLoop   *main_loop = g_main_loop_new ( NULL, FALSE );
       
 14738      iLog->Log ( _L ( "before lm_connection_open" ) );   
       
 14739      if ( !lm_connection_open ( connection, ( LmResultFunction ) connection_open_cb,
       
 14740                                 main_loop, NULL, NULL ) ) 
       
 14741          {
       
 14742          iLog->Log ( _L ( "lm_connection_open failed" ));
       
 14743          lm_connection_unref ( connection );
       
 14744          g_main_loop_unref ( main_loop );
       
 14745          free_data ( connect_data );     
       
 14746          return KErrGeneral;
       
 14747          }
       
 14748          
       
 14749      iLog->Log ( _L ( "after lm_connection_open" ) );    
       
 14750      g_main_loop_run ( main_loop );
       
 14751      g_main_loop_unref ( main_loop );    
       
 14752      
       
 14753      main_loop = g_main_loop_new ( NULL, FALSE );    
       
 14754      // Get the username from the JID
       
 14755      gchar *username = get_user_name ( connect_data->username );
       
 14756      
       
 14757      // Authenticate with the server
       
 14758      if ( !lm_connection_authenticate ( connection,
       
 14759                                       username,
       
 14760                                       connect_data->password,
       
 14761                                       connect_data->resource,
       
 14762                                        ( LmResultFunction ) connection_auth_cb,
       
 14763                                       main_loop,NULL,NULL ) )
       
 14764          {
       
 14765          iLog->Log ( _L ( "lm_connection_authenticate failed" ) );
       
 14766          lm_connection_close ( connection, NULL );
       
 14767          lm_connection_unref ( connection );
       
 14768          free_data ( connect_data );
       
 14769          g_main_loop_unref ( main_loop );
       
 14770          g_free ( username );
       
 14771          return KErrGeneral;
       
 14772          }
       
 14773 
       
 14774      g_main_loop_run ( main_loop );
       
 14775      g_main_loop_unref ( main_loop );
       
 14776      g_free ( username );
       
 14777 
       
 14778      //------------------------------------------------------------------------
       
 14779      //Send own presence
       
 14780      message = lm_message_new_with_sub_type ( NULL,
       
 14781                                           LM_MESSAGE_TYPE_PRESENCE,
       
 14782                                           LM_MESSAGE_SUB_TYPE_AVAILABLE );
       
 14783      
       
 14784      gboolean result = lm_connection_send ( connection, message, NULL ); 
       
 14785     // GMainLoop  *main_loop1;
       
 14786         
       
 14787      //------------------------------------------------------------------------
       
 14788      //
       
 14789      // Register a handler to recieve msgs
       
 14790      //
       
 14791      handle_data = g_new0 ( HandleData, 1 );
       
 14792      GMainLoop *main_loop1 = g_main_loop_new ( NULL, FALSE );
       
 14793      handle_data->main_loop=main_loop1;
       
 14794      handle_data->count=0;
       
 14795      handler = lm_message_handler_new ( 
       
 14796                           (LmHandleMessageFunction)handle_100_messages,
       
 14797                           handle_data,
       
 14798                           NULL );
       
 14799      
       
 14800      lm_connection_register_message_handler ( connection,
       
 14801                                               handler,
       
 14802                                               LM_MESSAGE_TYPE_MESSAGE,
       
 14803                                               LM_HANDLER_PRIORITY_FIRST );
       
 14804      
       
 14805      g_main_loop_run ( main_loop1 );
       
 14806      g_main_loop_unref ( main_loop1 );
       
 14807      //------------------------------------------------------------------------
       
 14808         
       
 14809      lm_message_unref(message);
       
 14810      lm_message_handler_unref(handler);
       
 14811      // Close the connection
       
 14812      lm_connection_close ( connection, NULL );   
       
 14813      // Remove a reference on connection
       
 14814      lm_connection_unref ( connection );     
       
 14815      free_data ( connect_data );
       
 14816      
       
 14817      // Message sending passed
       
 14818      iLog->Log ( _L ( "lm_nft_receiving100_message_L" ) );
       
 14819      
       
 14820      return KErrNone;
       
 14821 }	    
       
 14822 //  End of File