changeset 19789:7e36832172a9

[gaim-migrate @ 16601] change Windows Live ID authentication code style to simplify the code. add some comments committed by Ma Yuan<mayuan2006@gmail.com> committer: Ethan Blanton <elb@pidgin.im>
author Ma Yuan <mayuan2006@gmail.com>
date Sun, 30 Jul 2006 15:55:30 +0000
parents 8b4653986e8e
children 4f21c73a0c48
files src/protocols/msn/contact.c src/protocols/msn/nexus.c src/protocols/msn/notification.c src/protocols/msn/oim.c src/protocols/msn/oim.h
diffstat 5 files changed, 109 insertions(+), 117 deletions(-) [+]
line wrap: on
line diff
--- a/src/protocols/msn/contact.c	Sun Jul 30 13:44:34 2006 +0000
+++ b/src/protocols/msn/contact.c	Sun Jul 30 15:55:30 2006 +0000
@@ -415,30 +415,35 @@
 	msn_soap_post(contact->soapconn,MSN_GET_ADDRESS_TEMPLATE,msn_address_written_cb);
 }
 
+/*add a Contact */
 void
 msn_add_contact(MsnContact *contact)
 {
 
 }
 
+/*delete a Contact*/
 void
 msn_delete_contact(MsnContact *contact)
 {	
 
 }
 
+/*block a Contact*/
 void
 msn_block_contact(MsnContact *contact)
 {	
 
 }
 
+/*unblock a contact*/
 void
 msn_unblock_contact(MsnContact *contact)
 {	
 
 }
 
+/*get the gleams info*/
 void
 msn_get_gleams(MsnContact *contact)
 {
--- a/src/protocols/msn/nexus.c	Sun Jul 30 13:44:34 2006 +0000
+++ b/src/protocols/msn/nexus.c	Sun Jul 30 15:55:30 2006 +0000
@@ -26,6 +26,9 @@
 #include "nexus.h"
 #include "notification.h"
 
+/*Local Function Prototype*/
+static void nexus_login_connect_cb(gpointer data, GaimSslConnection *gsc,GaimInputCondition cond);
+
 /**************************************************************************
  * Main
  **************************************************************************/
@@ -59,13 +62,8 @@
 /**************************************************************************
  * Login
  **************************************************************************/
-
 static void
-login_connect_cb(gpointer data, GaimSslConnection *gsc,
-				 GaimInputCondition cond);
-
-static void
-login_error_cb(GaimSslConnection *gsc, GaimSslErrorType error, void *data)
+nexus_login_error_cb(GaimSslConnection *gsc, GaimSslErrorType error, void *data)
 {
 	MsnSoapConn * soapconn = data;
 	MsnSession *session;
@@ -78,6 +76,7 @@
 	 * to destroy it here, or we'd crash */
 }
 
+/*process the SOAP reply, get the Authentication Info*/
 static void
 nexus_login_read_cb(gpointer data, gint source, GaimInputCondition cond)
 {
@@ -85,6 +84,12 @@
 	MsnNexus *nexus;
 	MsnSession *session;
 
+	char *base, *c;
+	char *msn_twn_t,*msn_twn_p;
+	char *login_params;
+	char **elems, **cur, **tokens;
+	char * cert_str;
+
 	nexus = soapconn->parent;
 	g_return_if_fail(nexus != NULL);
 	session = nexus->session;
@@ -92,107 +97,52 @@
 
 //	gaim_debug_misc("msn", "TWN Server Reply: {%s}\n", soapconn->read_buf);
 
-	if (strstr(soapconn->read_buf, "HTTP/1.1 302") != NULL){
-		/* Redirect. */
-		char *location, *c;
+	/*reply OK, we should process the SOAP body*/
+	gaim_debug_info("MaYuan","Windows Live ID Reply OK!\n");
 
-		location = strstr(soapconn->read_buf, "Location: ");
-		if (location == NULL){
-			msn_soap_free_read_buf(soapconn);
-			return;
-		}
-		location = strchr(location, ' ') + 1;
+	//TODO: we should parse it using XML
+	base  = g_strstr_len(soapconn->read_buf, soapconn->read_len, TWN_START_TOKEN);
+	base += strlen(TWN_START_TOKEN);
+	c     = g_strstr_len(soapconn->read_buf, soapconn->read_len, TWN_END_TOKEN);
+	login_params = g_strndup(base, c - base);
 
-		if ((c = strchr(location, '\r')) != NULL)
-			*c = '\0';
-
-		/* Skip the http:// */
-		if ((c = strchr(location, '/')) != NULL)
-			location = c + 2;
+	//		gaim_debug_info("msn", "TWN Cert: {%s}\n", login_params);
 
-		if ((c = strchr(location, '/')) != NULL){
-			g_free(soapconn->login_path);
-			soapconn->login_path = g_strdup(c);
-
-			*c = '\0';
-		}
-		g_free(soapconn->login_host);
+	/* Parse the challenge data. */
+	elems = g_strsplit(login_params, "&amp;", 0);
 
-		msn_soap_init(soapconn,location,1,login_connect_cb,login_error_cb);
-	}else if (strstr(soapconn->read_buf, "HTTP/1.1 401 Unauthorized") != NULL){
-		const char *error;
+	for (cur = elems; *cur != NULL; cur++){
+			tokens = g_strsplit(*cur, "=", 2);
+			g_hash_table_insert(nexus->challenge_data, tokens[0], tokens[1]);
+			/* Don't free each of the tokens, only the array. */
+			g_free(tokens);
+	}
 
-		if ((error = strstr(soapconn->read_buf, "WWW-Authenticate")) != NULL)	{
-			if ((error = strstr(error, "cbtxt=")) != NULL){
-				const char *c;
-				char *temp;
-
-				error += strlen("cbtxt=");
-
-				if ((c = strchr(error, '\n')) == NULL)
-					c = error + strlen(error);
+	g_strfreev(elems);
 
-				temp = g_strndup(error, c - error);
-				error = gaim_url_decode(temp);
-				g_free(temp);
-			}
-		}
-		msn_session_set_error(session, MSN_ERROR_AUTH, error);
-	}else if (strstr(soapconn->read_buf, "HTTP/1.1 200 OK")){
-		/*reply OK, we should process the SOAP body*/
-		char *base, *c;
-		char *msn_twn_t,*msn_twn_p;
-		char *login_params;
+	msn_twn_t = (char *)g_hash_table_lookup(nexus->challenge_data, "t");
+	msn_twn_p = (char *)g_hash_table_lookup(nexus->challenge_data, "p");
 
-		char **elems, **cur, **tokens;
-		char * cert_str;
-
-		gaim_debug_info("MaYuan","Windows Live ID Reply OK!\n");
-
-		//TODO: we should parse it using XML
-		base  = g_strstr_len(soapconn->read_buf, soapconn->read_len, TWN_START_TOKEN);
-		base += strlen(TWN_START_TOKEN);
-		c     = g_strstr_len(soapconn->read_buf, soapconn->read_len, TWN_END_TOKEN);
-		login_params = g_strndup(base, c - base);
-
-//		gaim_debug_info("msn", "TWN Cert: {%s}\n", login_params);
-
-		/* Parse the challenge data. */
-		elems = g_strsplit(login_params, "&amp;", 0);
+	/*setup the t and p parameter for session*/
+	if (session->passport_info.t != NULL){
+			g_free(session->passport_info.t);
+	}
+	session->passport_info.t = g_strdup(msn_twn_t);
 
-		for (cur = elems; *cur != NULL; cur++){
-				tokens = g_strsplit(*cur, "=", 2);
-				g_hash_table_insert(nexus->challenge_data, tokens[0], tokens[1]);
-				/* Don't free each of the tokens, only the array. */
-				g_free(tokens);
-		}
+	if (session->passport_info.p != NULL)
+			g_free(session->passport_info.p);
+	session->passport_info.p = g_strdup(msn_twn_p);
 
-		g_strfreev(elems);
-
-		msn_twn_t = (char *)g_hash_table_lookup(nexus->challenge_data, "t");
-		msn_twn_p = (char *)g_hash_table_lookup(nexus->challenge_data, "p");
+	cert_str = g_strdup_printf("t=%s&p=%s",msn_twn_t,msn_twn_p);
+	msn_got_login_params(session, cert_str);
 
-		/*setup the t and p parameter for session*/
-		if (session->passport_info.t != NULL){
-			g_free(session->passport_info.t);
-		}
-		session->passport_info.t = g_strdup(msn_twn_t);
-
-		if (session->passport_info.p != NULL)
-			g_free(session->passport_info.p);
-		session->passport_info.p = g_strdup(msn_twn_p);
+	gaim_debug_info("MaYuan","close nexus connection! \n");
+	g_free(cert_str);
+	g_free(login_params);
+	msn_nexus_destroy(nexus);
+	session->nexus = NULL;
 
-		cert_str = g_strdup_printf("t=%s&p=%s",msn_twn_t,msn_twn_p);
-		msn_got_login_params(session, cert_str);
-
-		gaim_debug_info("MaYuan","close nexus connection! \n");
-		g_free(cert_str);
-		g_free(login_params);
-		msn_nexus_destroy(nexus);
-		session->nexus = NULL;
-		return;
-	}
-	msn_soap_free_read_buf(soapconn);
+	return;
 }
 
 static void
@@ -205,8 +155,9 @@
 }
 
 
+/*when connect, do the SOAP Style windows Live ID authentication */
 void
-login_connect_cb(gpointer data, GaimSslConnection *gsc,
+nexus_login_connect_cb(gpointer data, GaimSslConnection *gsc,
 				 GaimInputCondition cond)
 {
 	MsnSoapConn *soapconn;
@@ -285,6 +236,6 @@
 	/*  Authenticate via Windows Live ID. */
 	gaim_debug_info("MaYuan","msn_nexus_connect...\n");
 
-	msn_soap_init(nexus->soapconn,MSN_TWN_SERVER,1,login_connect_cb,login_error_cb);
+	msn_soap_init(nexus->soapconn,MSN_TWN_SERVER,1,nexus_login_connect_cb,nexus_login_error_cb);
 }
 
--- a/src/protocols/msn/notification.c	Sun Jul 30 13:44:34 2006 +0000
+++ b/src/protocols/msn/notification.c	Sun Jul 30 15:55:30 2006 +0000
@@ -1370,6 +1370,7 @@
 	/*new a oim session*/
 	session = cmdproc->session;
 	session->oim = msn_oim_new(session);
+//	msn_oim_connect(session->oim);
 
 	/*parse offline message data*/
 	elems = g_strsplit(msg->body, "\r\n", 0);
--- a/src/protocols/msn/oim.c	Sun Jul 30 13:44:34 2006 +0000
+++ b/src/protocols/msn/oim.c	Sun Jul 30 15:55:30 2006 +0000
@@ -50,9 +50,12 @@
 	g_free(oim);
 }
 
+/****************************************
+ * OIM send SOAP request
+ * **************************************/
 /*oim SOAP server login error*/
 static void
-msn_oim_login_error_cb(GaimSslConnection *gsc, GaimSslErrorType error, void *data)
+msn_oim_send_error_cb(GaimSslConnection *gsc, GaimSslErrorType error, void *data)
 {
 	MsnSoapConn *soapconn = data;
 	MsnSession *session;
@@ -65,7 +68,7 @@
 
 /*msn oim SOAP server connect process*/
 static void
-msn_oim_login_connect_cb(gpointer data, GaimSslConnection *gsc,
+msn_oim_send_connect_cb(gpointer data, GaimSslConnection *gsc,
 				 GaimInputCondition cond)
 {
 	MsnSoapConn *soapconn = data;
@@ -83,12 +86,44 @@
 {
 	if(msn_soap_connected(oim->sendconn) == -1){
 		msn_soap_init(oim->sendconn,MSN_OIM_SEND_HOST,1,
-					msn_oim_login_connect_cb,
-					msn_oim_login_error_cb);
+					msn_oim_send_connect_cb,
+					msn_oim_send_error_cb);
 	}
 	
 }
 
+/****************************************
+ * OIM get SOAP request
+ * **************************************/
+/*oim SOAP server login error*/
+static void
+msn_oim_get_error_cb(GaimSslConnection *gsc, GaimSslErrorType error, void *data)
+{
+	MsnSoapConn *soapconn = data;
+	MsnSession *session;
+
+	session = soapconn->session;
+	g_return_if_fail(session != NULL);
+
+	msn_session_set_error(session, MSN_ERROR_SERV_DOWN, _("Unable to connect to OIM server"));
+}
+
+/*msn oim SOAP server connect process*/
+static void
+msn_oim_get_connect_cb(gpointer data, GaimSslConnection *gsc,
+				 GaimInputCondition cond)
+{
+	MsnSoapConn *soapconn = data;
+	MsnSession * session;
+	MsnOim *oim;
+
+	oim = soapconn->parent;
+	g_return_if_fail(oim != NULL);
+
+	session = oim->session;
+	g_return_if_fail(session != NULL);
+}
+
 static void
 msn_oim_get_read_cb(gpointer data, GaimSslConnection *gsc,
 				 GaimInputCondition cond)
@@ -107,14 +142,8 @@
 	soapconn->read_cb = msn_oim_get_read_cb;
 	msn_soap_read_cb(data,source,cond);
 }
-/*
-static void
-msn_oim_login_connect_cb(gpointer data, GaimSslConnection *gsc,
-				 GaimInputCondition cond)
-{
-	
-}*/
 
+/*get the conversation*/
 static GaimConversation *
 msn_oim_get_conv(MsnOim *oim,char *passport)
 {
@@ -132,6 +161,7 @@
 	return conv;
 }
 
+/*put the OIM Message to User Conversation*/
 void
 msn_oim_report_user(MsnOim *oim,const char *passport,char *msg)
 {
@@ -143,6 +173,7 @@
 
 }
 
+/*parse the oim XML data*/
 void
 msn_parse_oim_msg(MsnOim *oim,char *xmlmsg)
 {
@@ -161,25 +192,24 @@
 		nNode = xmlnode_get_child(mNode,"N");
 		nickname = xmlnode_get_data(nNode);
 		gaim_debug_info("MaYuan","E:{%s},I:{%s},rTime:{%s}\n",passport,msgid,rTime);
-		msn_oim_report_user(oim,passport,"hello");
-//		msn_oim_get_msg(oim,msgid);
+//		msn_oim_report_user(oim,passport,"hello");
+		msn_oim_get_msg(oim,msgid);
 	}
 }
 
+/*MSN OIM get SOAP request*/
 void msn_oim_get_msg(MsnOim *oim,char *msgid)
 {
 	const char *oimid ,*oimsoapbody,*t,*p;
 
 	if(msn_soap_connected(oim->retrieveconn) == -1){
 		gaim_debug_info("MaYuan","retreive OIM server not connected!\n");
-		msn_soap_init(oim->retrieveconn,MSN_OIM_RETRIEVE_HOST,1,
-					msn_oim_login_connect_cb,
-					msn_oim_login_error_cb);
 		return;
 	}
 
+	gaim_debug_info("MaYuan","Get OIM with SOAP \n");
 	oim->retrieveconn->login_path = g_strdup(MSN_OIM_RETRIEVE__URL);
-	oim->retrieveconn->soap_action = g_strdup(MSN_OIM_DEL_SOAP_ACTION);
+	oim->retrieveconn->soap_action = g_strdup(MSN_OIM_GET_SOAP_ACTION);
 	t = oim->session->passport_info.t;
 	p = oim->session->passport_info.p;
 
@@ -198,8 +228,11 @@
 	gaim_debug_info("MaYuan","msn_oim_connect...\n");
 
 	msn_soap_init(oim->retrieveconn,MSN_OIM_RETRIEVE_HOST,1,
-					msn_oim_login_connect_cb,
-					msn_oim_login_error_cb);
+					msn_oim_get_connect_cb,
+					msn_oim_get_error_cb);
+	msn_soap_init(oim->sendconn,MSN_OIM_SEND_HOST,1,
+					msn_oim_send_connect_cb,
+					msn_oim_send_error_cb);
 }
 
 /*endof oim.c*/
--- a/src/protocols/msn/oim.h	Sun Jul 30 13:44:34 2006 +0000
+++ b/src/protocols/msn/oim.h	Sun Jul 30 15:55:30 2006 +0000
@@ -98,6 +98,8 @@
 /*function prototype*/
 MsnOim * msn_oim_new(MsnSession *session);
 void msn_oim_destroy(MsnOim *oim);
+void msn_oim_connect(MsnOim *oim);
+
 void msn_parse_oim_msg(MsnOim *oim,char *xmlmsg);
 
 void msn_oim_get_msg(MsnOim *oim,char *msgid);