libtelepathy/tsrc/src/telepathygabblelogintest.cpp
changeset 0 d0f3a028347a
equal deleted inserted replaced
-1:000000000000 0:d0f3a028347a
       
     1 /*
       
     2 * Copyright (c) 2008 - 2009 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:    Used for Login-Logout related Test Cases
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20  
       
    21 //Include files
       
    22 #include <e32err.h>
       
    23 #include <e32const.h>
       
    24 #include <e32base.h>
       
    25 
       
    26 #include <glib.h>
       
    27 #include <StifLogger.h>
       
    28 
       
    29 #include "telepathygabbleutils.h"
       
    30 #include "telepathygabblelogintest.h"
       
    31 #include "telepathygabbletestdata.h"
       
    32 #include "telepathygabbleadddeletecontact.h"
       
    33 
       
    34 static void  test_log_handler1 (
       
    35 		    const gchar    *message
       
    36 		   )
       
    37 {
       
    38    FILE* fp;
       
    39 		
       
    40 	fp = fopen("c:\\tplogs.txt","a");
       
    41 	if(fp)
       
    42 	{
       
    43 		fprintf(fp,message);
       
    44 		fprintf(fp,"\n");
       
    45 		fclose(fp);
       
    46 	}
       
    47 
       
    48 	
       
    49 }
       
    50 
       
    51 
       
    52 //-----------------------------------------------------------------------------
       
    53 // function_name	: CTelepathyGabbleLoginTest
       
    54 // description     	: Constructor
       
    55 // Returns          : None
       
    56 //-----------------------------------------------------------------------------
       
    57 
       
    58 CTelepathyGabbleLoginTest::CTelepathyGabbleLoginTest()
       
    59     {
       
    60     }
       
    61     
       
    62 //-----------------------------------------------------------------------------
       
    63 // function_name	: ConstructL
       
    64 // description     	: Constructor
       
    65 // Returns          : None
       
    66 //-----------------------------------------------------------------------------
       
    67 
       
    68 void CTelepathyGabbleLoginTest::ConstructL()
       
    69 	{
       
    70 
       
    71 	}
       
    72 
       
    73 //-----------------------------------------------------------------------------
       
    74 // function_name	: NewL
       
    75 // description     	: Constructor
       
    76 // Returns          : None
       
    77 //-----------------------------------------------------------------------------
       
    78 CTelepathyGabbleLoginTest* CTelepathyGabbleLoginTest::NewL()
       
    79     {
       
    80     
       
    81 	CTelepathyGabbleLoginTest* self = new(ELeave) CTelepathyGabbleLoginTest;
       
    82     CleanupStack::PushL( self );
       
    83     self->ConstructL();    
       
    84     CleanupStack::Pop();
       
    85     return self;
       
    86     }
       
    87 
       
    88 //-----------------------------------------------------------------------------
       
    89 // function_name	: ~CTelepathyGabbleLoginTest
       
    90 // description     	: destructor
       
    91 // Returns          : None
       
    92 //-----------------------------------------------------------------------------
       
    93 CTelepathyGabbleLoginTest::~CTelepathyGabbleLoginTest()
       
    94     {
       
    95     
       
    96     //class variables
       
    97     //delete conn;
       
    98     //conn = NULL;
       
    99 
       
   100     }
       
   101 
       
   102 //-----------------------------------------------------------------------------
       
   103 // function_name	: action_login
       
   104 // description     	: login
       
   105 // Returns          : gboolean
       
   106 //----------------------------------------------------------------------------- 
       
   107 TInt CTelepathyGabbleLoginTest::action_login(char* username,char* password,
       
   108 												char* server, char* resource, char* ssl_flag,
       
   109 												char *port, char *proxy_server, char *proxy_port,
       
   110 												CTestData* aTestData)
       
   111 {
       
   112    
       
   113    
       
   114     TpConnMgr *connmgr = NULL;
       
   115     GError *error = NULL;
       
   116     
       
   117     test_log_handler1(username);
       
   118     test_log_handler1(password);
       
   119     test_log_handler1(server);
       
   120     test_log_handler1(resource);
       
   121     test_log_handler1(ssl_flag);
       
   122     test_log_handler1(port);
       
   123     
       
   124    	
       
   125 	GHashTable *connection_parameters = g_hash_table_new(g_str_hash, g_str_equal);
       
   126 
       
   127 	DBusGConnection *dbus_connection;
       
   128 	TpConn *tp_conn;
       
   129 	
       
   130 	//Use the values passed from the cfg file.
       
   131 	gchar* def1 = g_strdup(username);
       
   132 	gchar* def2 = g_strdup(password);
       
   133 	
       
   134 	gchar* def3 = g_strdup(server);	
       
   135 	gchar* def4 = g_strdup(resource);
       
   136 	
       
   137 	guint def5 = atoi(port);				//443;
       
   138 
       
   139 	#ifdef __WINSCW__	
       
   140 	gchar* def6 = g_strdup(proxy_server); 		//g_strdup("172.16.42.135"); //for emulater
       
   141 	guint def7 = atoi(proxy_port);												//8080; //for emulater
       
   142 	#endif
       
   143 
       
   144 	GValue *value1 = g_new0(GValue, 1);
       
   145 	GValue *value2 = g_new0(GValue, 1);
       
   146 	GValue *value3 = g_new0(GValue, 1);
       
   147 	GValue *value4 = g_new0(GValue, 1);
       
   148 	GValue *value5 = g_new0(GValue, 1);
       
   149 		
       
   150 	#ifdef __WINSCW__	
       
   151 	GValue *value6 = g_new0(GValue, 1);
       
   152 	GValue *value7 = g_new0(GValue, 1);
       
   153 	#endif
       
   154 
       
   155   GValue *value8 = g_new0(GValue, 1);	
       
   156 	g_type_init();
       
   157 
       
   158 
       
   159   	// just use system bus and do not bother about others
       
   160   	 dbus_connection = dbus_g_bus_get( DBUS_BUS_SESSION , &error); 
       
   161   
       
   162   	aTestData->GetStifLogger()->Log( _L("after dbus_g_bus_get") );
       
   163     /* bsr 4 sep: this was null as host parsing failed -> transport was zero -> connectionw as 0 */
       
   164   	if (dbus_connection == NULL)
       
   165    	{
       
   166 	    // if we get error as part of above step, connection variable is NULL, so we are here
       
   167 	    //_dbus_verboseerr("Failed to open connection to bus: %s\n", error->message);
       
   168 	    //test_log_handler("Found Error in dbus_g_bus_get exiting.\n");
       
   169 	    aTestData->GetStifLogger()->Log( _L("dbus_connection == NULL") );
       
   170 	    g_error_free(error);
       
   171 	 	return (aTestData->GetConnectionState());	
       
   172    	}
       
   173    	else
       
   174    	{
       
   175    	aTestData->SetDBusConnection(dbus_connection);
       
   176    	}
       
   177    
       
   178   	aTestData->GetStifLogger()->Log( _L("b4 tp_connmgr_new") );
       
   179   	/* Create a connection manager object */
       
   180   	connmgr = tp_connmgr_new(dbus_connection, CONNMGR_BUS, CONNMGR_PATH,
       
   181 			   /*CONNMGR_BUS*/ TP_IFACE_CONN_MGR_INTERFACE);
       
   182   	aTestData->GetStifLogger()->Log( _L("after tp_connmgr_new") );
       
   183 	if (connmgr == NULL)
       
   184 	{
       
   185 	 aTestData->GetStifLogger()->Log( _L("connmgr == NULL") );
       
   186 	 g_error("Failed to create a connection manager, skipping manager startup.");
       
   187 	 return (aTestData->GetConnectionState());	
       
   188 	}
       
   189 	else
       
   190 	{
       
   191 		aTestData->SetTpConnMgr(connmgr);	
       
   192 	}
       
   193 		
       
   194 	g_value_init(value1, G_TYPE_STRING);
       
   195 	g_value_set_string (value1, def1);
       
   196 	g_hash_table_insert(connection_parameters, (gpointer)"account", (gpointer)value1); 
       
   197 
       
   198 	g_value_init(value2, G_TYPE_STRING); 
       
   199 	g_value_set_string (value2, def2);
       
   200 	g_hash_table_insert(connection_parameters,(gpointer) "password",(gpointer) value2); 
       
   201 
       
   202 	g_value_init(value3, G_TYPE_STRING); 
       
   203 	g_value_set_string (value3, def3);
       
   204 	g_hash_table_insert(connection_parameters,(gpointer) "server",(gpointer)value3 ); 
       
   205 
       
   206 	g_value_init(value4, G_TYPE_STRING); 
       
   207 	g_value_set_string (value4, def4);
       
   208 	g_hash_table_insert(connection_parameters, (gpointer)"resource", (gpointer)value4); 
       
   209 
       
   210 
       
   211 	g_value_init(value5, G_TYPE_UINT); 
       
   212 	g_value_set_uint (value5, def5);
       
   213 	g_hash_table_insert(connection_parameters, (gpointer)"port", (gpointer)value5); 
       
   214 
       
   215 	//convert the ssl_flag to ascii
       
   216 	TInt ssl_bool = atoi(ssl_flag);
       
   217 	
       
   218 	//if (ssl_flag == "1") //def8 ==1 
       
   219 	if (ssl_bool == 1) //i.e. only for gtalk, not for gizmo
       
   220 	{
       
   221 		gboolean def8 = TRUE; //for gtalk
       
   222 		g_value_init(value8, G_TYPE_BOOLEAN);
       
   223 		g_value_set_boolean (value8, def8);
       
   224   	g_hash_table_insert(connection_parameters, (gpointer)"old-ssl", (gpointer)value8); 
       
   225 	}  
       
   226 	
       
   227 #ifdef __WINSCW__    
       
   228 	g_value_init(value6, G_TYPE_STRING); 
       
   229 	g_value_set_string (value6, def6);
       
   230 	g_hash_table_insert(connection_parameters, (gpointer)"https-proxy-server", (gpointer)value6);
       
   231 
       
   232 
       
   233 	g_value_init(value7, G_TYPE_UINT); 
       
   234 	g_value_set_uint (value7, def7);
       
   235 	g_hash_table_insert(connection_parameters, (gpointer)"https-proxy-port",(gpointer) value7); 
       
   236 #endif
       
   237 	
       
   238 		
       
   239 	// Create a new actual connection with the connection manager 
       
   240 	//Ensure that conn is global. 
       
   241 	// The same conn object is used for logout.
       
   242 	aTestData->GetStifLogger()->Log( _L("b4 tp_connmgr_new_connection") );
       
   243 	tp_conn = tp_connmgr_new_connection(connmgr,connection_parameters, PROTOCOL);
       
   244 	aTestData->GetStifLogger()->Log( _L("after tp_connmgr_new_connection") );
       
   245 	if( tp_conn == NULL )
       
   246   	{
       
   247   		aTestData->GetStifLogger()->Log( _L("tp_conn is null") );
       
   248   		return (aTestData->GetConnectionState());	
       
   249   	}
       
   250   	else
       
   251   	{
       
   252   	aTestData->SetTpConn(tp_conn);	
       
   253   	}
       
   254   
       
   255 		
       
   256    	
       
   257 	// add a callback for StatusChange signal 
       
   258 	dbus_g_proxy_connect_signal(DBUS_G_PROXY(tp_conn), "StatusChanged",
       
   259 	(G_CALLBACK(status_changed_cb)),
       
   260 	aTestData,NULL );
       
   261 
       
   262 	g_hash_table_destroy(connection_parameters);
       
   263 
       
   264 	//Run the mainloop
       
   265 	g_main_loop_run (aTestData->GetMainLoop());
       
   266 
       
   267 	//Quit of main loop happened in thecallback.
       
   268 	//unref this mainloop
       
   269 	// same main loop can be used for all classes,
       
   270 	// unref after logout in each test case when logintest object gets destroyed
       
   271 	//g_main_loop_unref ( mainloop ); 
       
   272 	
       
   273 	//After the status_changed_cb , the control back here
       
   274 	//Check the value of global variable that was updated
       
   275 	//in the callback and return the same.
       
   276 
       
   277 	
       
   278 	//Get the connected state for login and return the same.
       
   279 	return (aTestData->GetConnectionState());
       
   280 }
       
   281 
       
   282 //-----------------------------------------------------------------------------
       
   283 // function_name	: action_logout
       
   284 // description     	: Does logout
       
   285 // Returns          : None
       
   286 //-----------------------------------------------------------------------------
       
   287 
       
   288 TInt CTelepathyGabbleLoginTest::action_logout(CTestData* aTestData)
       
   289 {
       
   290 	GError *error = NULL;
       
   291 	
       
   292 	//Do the disconnect
       
   293 	tp_conn_disconnect (DBUS_G_PROXY( aTestData->GetTpConn()), &error);
       
   294 	
       
   295 	//g_hash_table_destroy(global_data_ptr->Getptrhashtable_textchan());
       
   296 	
       
   297 	//Start the main loop
       
   298 	g_main_loop_run (aTestData->GetMainLoop());
       
   299 	
       
   300 
       
   301 	//After this see that the callback status_changed_cb
       
   302 	//is hit with TP_CONN_STATUS_DISCONNECTED as the status.
       
   303 	
       
   304 	//After the status_changed_cb , the control back here
       
   305 	//Check the value of global variable that was updated in the 
       
   306 	//callback and return the same.
       
   307 	
       
   308 	if (error)
       
   309 	{
       
   310 		// There is some error
       
   311 		g_error_free (error);	
       
   312 		// Update the global to connected 
       
   313 		//global_connected = TRUE;
       
   314 	}
       
   315 	//else global_connected is made FALSE in the status_changed_cb
       
   316       
       
   317 	
       
   318 	//return global_connected; 
       
   319 	//Get the connected state for login and return the same.
       
   320 	return (aTestData->GetConnectionState());
       
   321 }
       
   322 
       
   323 //-----------------------------------------------------------------------------
       
   324 // function_name	: action_cancel
       
   325 // description     	: cancel login
       
   326 // Returns          : None
       
   327 //-----------------------------------------------------------------------------
       
   328 
       
   329 TInt CTelepathyGabbleLoginTest::action_cancel(char* username,
       
   330 													char* password, char* server,char* resource, char* ssl_flag,
       
   331 													char *port,char *proxy_server, char *proxy_port,
       
   332 												    CTestData* aTestData)
       
   333 {
       
   334 	aTestData->SetTestType(CTestData::ECancel) ;
       
   335 	aTestData->GetStifLogger()->Log( _L("inside action_cancel\n") );
       
   336 	action_login(username,password,server,resource,ssl_flag,
       
   337 								port, proxy_server, proxy_port, aTestData);
       
   338 	
       
   339 	action_logout(aTestData);//Do tp_disconnected.
       
   340 	
       
   341 	return (aTestData->GetConnectionState());
       
   342 }
       
   343 
       
   344 //-----------------------------------------------------------------------------
       
   345 // function_name	: status_changed_cb
       
   346 //-----------------------------------------------------------------------------
       
   347 gboolean CTelepathyGabbleLoginTest::status_changed_cb(DBusGProxy* /*proxy*/,
       
   348 				  guint status, guint reason,
       
   349 				  gpointer user_data)
       
   350 {
       
   351   GHashTable*  textChannelsHT = NULL;
       
   352   CTestData* testData = static_cast<CTestData*> (user_data);
       
   353   CStifLogger* logger = testData->GetStifLogger();
       
   354   logger->Log( _L("status_changed_cb\n") );
       
   355 
       
   356   if (status == TP_CONN_STATUS_CONNECTED ) 
       
   357   {
       
   358   	
       
   359  
       
   360     logger->Log( _L("status_changed_cb::connected\n") );
       
   361     
       
   362     
       
   363     if( testData->GetTestType() != CTestData::ELogin )
       
   364     {
       
   365     
       
   366     
       
   367  	textChannelsHT =
       
   368 		g_hash_table_new_full(g_str_hash,
       
   369 				      g_str_equal,
       
   370 				      (GDestroyNotify) g_free,
       
   371 				      (GDestroyNotify) g_object_unref);
       
   372 	
       
   373 	testData->SetTextChannelsHT(textChannelsHT);
       
   374 	//Register the callback for new channel
       
   375 	//Commented for now has been put in the SendMessage function,
       
   376 	dbus_g_proxy_connect_signal(DBUS_G_PROXY(testData->GetTpConn()), "NewChannel",
       
   377 			      (G_CALLBACK(new_channel_handler)),			      
       
   378 			      user_data,NULL);
       
   379 	}
       
   380 	else
       
   381 	{
       
   382 		// if the test case is login related test case, new channel callback not required
       
   383 		//so dont register for NewChannel
       
   384 	g_main_loop_quit(testData->GetMainLoop());
       
   385 	testData->ResetLoginCompleteFlag();		      
       
   386 	}
       
   387     //update the state_of_conenction enum
       
   388   testData->SetConnectionState(CTestData::ECONNECTED );
       
   389    
       
   390   }
       
   391   else if (status == TP_CONN_STATUS_CONNECTING)
       
   392   {
       
   393     //if the test case is for cancel disconnect here, meaning cancel the login here.
       
   394   	//if cancel test case, do disconnect in connecting state
       
   395   	testData->SetConnectionState(CTestData::ECONNECTING);
       
   396   	if ( testData->GetTestType() == CTestData::ECancel)
       
   397   	{
       
   398   		//quit from this callback so that we return to point from where
       
   399   		//action_login was called.
       
   400   		g_main_loop_quit(testData->GetMainLoop());	
       
   401   	}
       
   402   	
       
   403   }
       
   404   else if ( status == TP_CONN_STATUS_DISCONNECTED )
       
   405   {
       
   406   	
       
   407   	
       
   408   	if ( testData->GetTestType() == CTestData::ECancel) 
       
   409   	{
       
   410   		//this disconnect was initiated from the cancel test case
       
   411   		logger->Log( _L("status_changed_cb :cancelled \n") );
       
   412   		testData->SetConnectionState(CTestData::EDISCONNECTED);
       
   413   		//quit the main loop.
       
   414   		g_main_loop_quit(testData->GetMainLoop());
       
   415   	}
       
   416   	else
       
   417   	{
       
   418   	
       
   419   		if(reason == TP_CONN_STATUS_REASON_AUTHENTICATION_FAILED)
       
   420   		{
       
   421   			// Here disconnect is received as the authentication has failed.
       
   422 	  		//it could be because of invalid user_id or invalid passwd issued 
       
   423 	  		//while passing the login parameters.
       
   424 	  		//Here we are checking for TP_CONN_STATUS_REASON_AUTHENTICATION_FAILED since
       
   425 	  		// the gabblelogs show the reason value as 3 if invalid user_id and passwd are given.
       
   426 	  	
       
   427 	  		testData->SetConnectionState(CTestData::EDISCONNECTED);
       
   428 	  		
       
   429 	  		//Quit the main loop started in action_login.
       
   430 			g_main_loop_quit(testData->GetMainLoop());
       
   431 			
       
   432   		}
       
   433   		else
       
   434   		{
       
   435   			//this was initiated in the logout testcase,
       
   436 	  		//update the state_of_connection
       
   437 	  		//LOGOUT AFTER SUCCESSFUL LOGIN
       
   438   			
       
   439   			if( testData->GetConnectionState() != CTestData::EDISCONNECTED )
       
   440   			{
       
   441   		
       
   442   			logger->Log( _L("status_changed_cb::not disconnected\n") );
       
   443   			
       
   444   			testData->IncLoginCompleteFlag();
       
   445   		
       
   446 			//currently for all the reasons except TP_CONN_STATUS_REASON_AUTHENTICATION_FAILED
       
   447 			//disconencted will come here.
       
   448 			//This code can be updated for variuos "reason" values
       
   449 			//based on the scenarios and the need for the test cases for those scenarios. 	
       
   450   			}
       
   451   			
       
   452   			if( testData->GetLoginCompleteFlag() && testData->GetConnectionState() == CTestData::EDISCONNECTED  )
       
   453   			{
       
   454   			logger->Log( _L("status_changed_cb::disconnected\n") );
       
   455   			testData->ResetLoginCompleteFlag();
       
   456   			//Quit the main loop started in action_login.
       
   457 			g_main_loop_quit(testData->GetMainLoop());	
       
   458 				
       
   459   			}
       
   460   			logger->Log( _L("status_changed_cb::before SetConnectionState\n") );
       
   461   			testData->SetConnectionState(CTestData::EDISCONNECTED);
       
   462 	 	
       
   463   		}
       
   464   	}
       
   465   	
       
   466   }
       
   467   logger->Log( _L("status_changed_cb out\n") ); 
       
   468   return TRUE;
       
   469 }
       
   470 
       
   471 //-----------------------------------------------------------------------------
       
   472 // function_name	: new_channel_handler
       
   473 // description     	: callback function for NewChannel signal
       
   474 //-----------------------------------------------------------------------------
       
   475 void CTelepathyGabbleLoginTest::new_channel_handler(DBusGProxy* /*proxy*/, const char *object_path,
       
   476 				const char *channel_type, guint handle_type,
       
   477 				guint channel_handle, gboolean /*suppress_handler*/,
       
   478 				gpointer user_data)
       
   479 {
       
   480 CTestData* testData = static_cast<CTestData*> (user_data);
       
   481 CStifLogger* logger = testData->GetStifLogger();
       
   482 logger->Log( _L("new_channel_handler\n") );
       
   483 
       
   484 //Use the class data member new_text_channel.
       
   485 TpChan *new_chan;
       
   486 
       
   487 //Get the new_chan 
       
   488 new_chan = tp_chan_new(testData->GetDBusConnection(),
       
   489 	       CONNMGR_BUS, object_path,
       
   490 		       channel_type, handle_type, channel_handle);
       
   491 
       
   492 
       
   493 //channel_type == TP_IFACE_CHANNEL_TYPE_TEXT
       
   494 if ((strcmp(channel_type, TP_IFACE_CHANNEL_TYPE_TEXT) == 0)  )
       
   495 	{
       
   496 	g_hash_table_insert(testData->GetTextChannelsHT(), g_strdup(object_path), new_chan);		       
       
   497 	//test_log_handler( "b4 text_channel_init" );
       
   498 	//check for  new_chan objects for text channel should be loaclly stored/freed
       
   499 	text_channel_init( new_chan );
       
   500 	}
       
   501 	
       
   502 	
       
   503 //channel_type == TP_IFACE_CHANNEL_TYPE_CONTACT_LIST
       
   504 if( strcmp( channel_type, TP_IFACE_CHANNEL_TYPE_CONTACT_LIST  ) == 0 
       
   505  		&& (g_strrstr(object_path, "RosterChannel/subscribe") ) )
       
   506  		  
       
   507 	{
       
   508 	DBusGProxy* groupInterface = NULL;
       
   509 	//Get the group_iface
       
   510 	groupInterface =
       
   511      	tp_chan_get_interface(new_chan,
       
   512 				      TELEPATHY_CHAN_IFACE_GROUP_QUARK);
       
   513 
       
   514 	
       
   515 	testData->SetGroupSubscribeInterface(groupInterface);
       
   516 	
       
   517 	//register the callback, commented for now.
       
   518 	dbus_g_proxy_connect_signal (groupInterface, "MembersChanged",
       
   519 					     G_CALLBACK (CTelepathyGabbleAddDeleteContact::roster_members_changed_cb ),
       
   520 					     NULL, NULL); 
       
   521 					     
       
   522 	//add_contact("testcm6666@gmail.com",NULL);		
       
   523     
       
   524     testData->IncLoginCompleteFlag();
       
   525 				       
       
   526 	}
       
   527 
       
   528 if( strcmp( channel_type, TP_IFACE_CHANNEL_TYPE_CONTACT_LIST  ) == 0 
       
   529  		&& (g_strrstr(object_path, "RosterChannel/publish") ) )
       
   530  		  
       
   531 	{
       
   532 	
       
   533 	DBusGProxy* groupInterface = NULL;
       
   534 	//Get the group_iface
       
   535 	groupInterface ==
       
   536      	tp_chan_get_interface(new_chan,
       
   537 				      TELEPATHY_CHAN_IFACE_GROUP_QUARK);
       
   538 				      
       
   539 	testData->SetGroupPublishInterface(groupInterface);
       
   540 		
       
   541 	dbus_g_proxy_connect_signal (groupInterface, "MembersChanged",
       
   542 					     G_CALLBACK (CTelepathyGabbleAddDeleteContact::roster_members_changed_cb ),
       
   543 					     NULL, NULL); 
       
   544 					     
       
   545 					     
       
   546 				     
       
   547 	//Increment the flag.
       
   548 	testData->IncLoginCompleteFlag();
       
   549 					     
       
   550  	}      
       
   551 	
       
   552 if( strcmp( channel_type, TP_IFACE_CHANNEL_TYPE_CONTACT_LIST  ) == 0 
       
   553  		&& (g_strrstr(object_path, "RosterChannel/known") ) )
       
   554  		  
       
   555 	{
       
   556  	DBusGProxy* groupInterface = NULL;
       
   557 	//Get the group_iface
       
   558 	groupInterface = 	tp_chan_get_interface(new_chan,
       
   559 				      TELEPATHY_CHAN_IFACE_GROUP_QUARK);				      
       
   560 
       
   561 	
       
   562 	//remove_contact( "testcm6666@gmail.com", NULL  );	
       
   563 	testData->SetGroupKnownInterface(groupInterface);
       
   564 				      
       
   565 	dbus_g_proxy_connect_signal (groupInterface, "MembersChanged",
       
   566 					     G_CALLBACK (CTelepathyGabbleAddDeleteContact::roster_members_changed_cb ),
       
   567 					     NULL, NULL);
       
   568 
       
   569 	
       
   570 	//increment the flag
       
   571 	testData->IncLoginCompleteFlag();
       
   572 	
       
   573 	}
       
   574 	
       
   575 if( strcmp( channel_type, TP_IFACE_CHANNEL_TYPE_CONTACT_LIST  ) == 0 
       
   576  		&& (g_strrstr(object_path, "RosterChannel/deny") ) )
       
   577  		  
       
   578 	{
       
   579  	DBusGProxy* groupInterface = NULL;
       
   580 	//Get the group_iface
       
   581 	groupInterface =   	tp_chan_get_interface(new_chan,
       
   582 				      TELEPATHY_CHAN_IFACE_GROUP_QUARK);				      
       
   583 				      
       
   584 	testData->SetGroupDenyInterface(groupInterface);
       
   585 				      
       
   586 	dbus_g_proxy_connect_signal (groupInterface, "MembersChanged",
       
   587 					     G_CALLBACK (CTelepathyGabbleAddDeleteContact::roster_members_changed_cb ),
       
   588 					     NULL, NULL);
       
   589 
       
   590 	//remove_contact( "testcm6666@gmail.com", NULL  );	
       
   591 
       
   592 	//increment the flag
       
   593 	testData->IncLoginCompleteFlag();
       
   594 	
       
   595 	}
       
   596 	//Quit the mainloop started once all the channel-types are recieved.
       
   597 	//check the flag.
       
   598 	
       
   599 	if (testData->GetLoginCompleteFlag() == 3) 
       
   600 	//In case of gizmo, the number of channels is 3.gtalk for deny also we get the callback
       
   601 	//we must also store the server name in the login class and check  the server name here
       
   602 	{
       
   603 		//Quit the main loop.
       
   604 		testData->ResetLoginCompleteFlag();
       
   605 		testData->GetStifLogger()->Log( _L("new_channel_handler::after ResetLoginCompleteFlag\n") );
       
   606 		g_main_loop_quit(testData->GetMainLoop());
       
   607 	
       
   608 	}
       
   609 		
       
   610 
       
   611 }
       
   612 
       
   613 //-----------------------------------------------------------------------------
       
   614 // function_name	: text_channel_init
       
   615 // description     	: To get pending messages after login
       
   616 //-----------------------------------------------------------------------------
       
   617 
       
   618 void CTelepathyGabbleLoginTest::text_channel_init  ( TpChan *text_chan )
       
   619 	{
       
   620 	GPtrArray  *messages_list ;
       
   621 	guint       i;
       
   622 	GArray     *message_ids;
       
   623 	DBusGProxy *text_iface;
       
   624 
       
   625 		
       
   626     text_iface = tp_chan_get_interface(text_chan ,
       
   627 					   TELEPATHY_CHAN_IFACE_TEXT_QUARK);
       
   628 
       
   629 		
       
   630 	//check if need to fetch the pending message or simply register for receive only
       
   631 	tp_chan_type_text_list_pending_messages(text_iface,
       
   632 						FALSE,
       
   633 						&messages_list,
       
   634 						NULL);
       
   635 
       
   636 
       
   637 	message_ids = g_array_new (FALSE, TRUE, sizeof (guint));
       
   638 
       
   639 		
       
   640 	for (i = 0; i < messages_list->len ; i++)
       
   641 	 {
       
   642 		guint          message_id;
       
   643 		guint          timestamp;
       
   644 		guint          from_handle;
       
   645 		guint          message_type;
       
   646 		guint          message_flags;
       
   647 		const gchar   *message_body;
       
   648 		GValueArray   *message_struct;
       
   649 	
       
   650 		
       
   651 		
       
   652 		message_struct = (GValueArray *) g_ptr_array_index (messages_list, i);
       
   653 		
       
   654 		message_id = g_value_get_uint(g_value_array_get_nth(message_struct, 0));
       
   655 
       
   656 		timestamp = g_value_get_uint(g_value_array_get_nth(message_struct, 1));
       
   657 
       
   658 		from_handle = g_value_get_uint(g_value_array_get_nth(message_struct, 2));
       
   659 
       
   660 		message_type = g_value_get_uint(g_value_array_get_nth(message_struct, 3));
       
   661 
       
   662 		message_flags = g_value_get_uint(g_value_array_get_nth(message_struct, 4));
       
   663 
       
   664 		message_body = g_value_get_string(g_value_array_get_nth(message_struct, 5));
       
   665 
       
   666 		g_array_append_val (message_ids, message_id);
       
   667 
       
   668 	}
       
   669 
       
   670 
       
   671 	tp_chan_type_text_acknowledge_pending_messages(text_iface, message_ids,
       
   672 						       NULL);
       
   673 
       
   674 					
       
   675 
       
   676 }
       
   677 
       
   678 				
       
   679 						
       
   680 //End of file