libpurple/protocols/msn/slp.c

branch
cpw.qulogic.msnp16
changeset 30932
f7b1a60f7466
parent 30930
bea746046da3
parent 30375
1efe4c9de187
child 30933
e8fb33bb8635
child 30965
e9c41f842693
--- a/libpurple/protocols/msn/slp.c	Wed May 26 19:47:56 2010 +0000
+++ b/libpurple/protocols/msn/slp.c	Wed Jun 02 20:08:53 2010 +0000
@@ -288,11 +288,11 @@
 	if (nonce) {
 		*ntype = DC_NONCE_SHA1;
 	} else {
-		guint32 n1, n5;
-		guint16 n2, n3, n4, n6;
+		guint32 n1, n6;
+		guint16 n2, n3, n4, n5;
 		nonce = get_token(content, "Nonce: {", "}\r\n");
 		if (nonce
-		 && sscanf(nonce, "%08x-%04hx-%04hx-%04hx-%08x%04hx",
+		 && sscanf(nonce, "%08x-%04hx-%04hx-%04hx-%04hx%08x",
 		           &n1, &n2, &n3, &n4, &n5, &n6) == 6) {
 			*ntype = DC_NONCE_PLAIN;
 			g_free(nonce);
@@ -301,8 +301,8 @@
 			*(guint16 *)(nonce +  4) = GUINT16_TO_LE(n2);
 			*(guint16 *)(nonce +  6) = GUINT16_TO_LE(n3);
 			*(guint16 *)(nonce +  8) = GUINT16_TO_BE(n4);
-			*(guint32 *)(nonce + 10) = GUINT32_TO_BE(n5);
-			*(guint16 *)(nonce + 14) = GUINT16_TO_BE(n6);
+			*(guint16 *)(nonce + 10) = GUINT16_TO_BE(n5);
+			*(guint32 *)(nonce + 12) = GUINT32_TO_BE(n6);
 		} else {
 			/* Invalid nonce, so ignore request */
 			g_free(nonce);
@@ -360,7 +360,7 @@
 
 			} else {
 				/* We weren't able to create a listener either. Use SB. */
-				msn_dc_fallback_to_p2p(dc);
+				msn_dc_fallback_to_sb(dc);
 			}
 
 		} else {
@@ -928,6 +928,25 @@
 	}
 }
 
+static void
+got_error(MsnSlpCall *slpcall,
+          const char *error, const char *type, const char *content)
+{
+	/* It's not valid. Kill this off. */
+	purple_debug_error("msn", "Received non-OK result: %s\n",
+	                   error ? error : "Unknown");
+
+	if (type && !strcmp(type, "application/x-msnmsgr-transreqbody")) {
+		MsnDirectConn *dc = slpcall->slplink->dc;
+		if (dc) {
+			msn_dc_fallback_to_sb(dc);
+			return;
+		}
+	}
+
+	slpcall->wasted = TRUE;
+}
+
 MsnSlpCall *
 msn_slp_sip_recv(MsnSlpLink *slplink, const char *body)
 {
@@ -1006,38 +1025,31 @@
 
 		g_return_val_if_fail(slpcall != NULL, NULL);
 
+		content_type = get_token(body, "Content-Type: ", "\r\n");
+
+		content = get_token(body, "\r\n\r\n", NULL);
+
 		if (strncmp(status, "200 OK", 6))
 		{
-			/* It's not valid. Kill this off. */
-			char temp[32];
+			char *error = NULL;
 			const char *c;
 
 			/* Eww */
 			if ((c = strchr(status, '\r')) || (c = strchr(status, '\n')) ||
 				(c = strchr(status, '\0')))
 			{
-				size_t offset =  c - status;
-				if (offset >= sizeof(temp))
-					offset = sizeof(temp) - 1;
-
-				strncpy(temp, status, offset);
-				temp[offset] = '\0';
+				size_t len = c - status;
+				error = g_strndup(status, len);
 			}
 
-			purple_debug_error("msn", "Received non-OK result: %s\n", temp);
+			got_error(slpcall, error, content_type, content);
+			g_free(error);
 
-			slpcall->wasted = TRUE;
-
-			/* msn_slpcall_destroy(slpcall); */
-			return slpcall;
+		} else {
+			/* Everything's just dandy */
+			got_ok(slpcall, content_type, content);
 		}
 
-		content_type = get_token(body, "Content-Type: ", "\r\n");
-
-		content = get_token(body, "\r\n\r\n", NULL);
-
-		got_ok(slpcall, content_type, content);
-
 		g_free(content_type);
 		g_free(content);
 	}

mercurial