changeset 6800:8f228a7d5076

[gaim-migrate @ 7340] Added what I have of MSNSLP in my tree. It's broken, and therefore disabled, but I need to get this out so I can do other stuff too, and have something to revert back to if I break something :) committer: Tailor Script <tailor@pidgin.im>
author Christian Hammond <chipx86@chipx86.com>
date Wed, 10 Sep 2003 00:24:48 +0000
parents fac483a95584
children b4fe4c1023c6
files src/protocols/msn/msg.c src/protocols/msn/msg.h src/protocols/msn/msnslp.c src/protocols/msn/msnslp.h src/protocols/msn/notification.c src/protocols/msn/servconn.c src/protocols/msn/switchboard.c src/protocols/msn/user.c src/protocols/msn/user.h
diffstat 9 files changed, 143 insertions(+), 43 deletions(-) [+]
line wrap: on
line diff
--- a/src/protocols/msn/msg.c	Tue Sep 09 16:55:10 2003 +0000
+++ b/src/protocols/msn/msg.c	Wed Sep 10 00:24:48 2003 +0000
@@ -69,6 +69,21 @@
 }
 
 MsnMessage *
+msn_message_new_msnslp(void)
+{
+	MsnMessage *msg;
+
+	msg = msn_message_new();
+
+	msn_message_set_attr(msg, "User-Agent", NULL);
+
+	msg->msnslp_message = TRUE;
+	msg->size += 52;
+
+	return msg;
+}
+
+MsnMessage *
 msn_message_new_from_str(MsnSession *session, const char *str)
 {
 	MsnMessage *msg;
@@ -357,7 +372,9 @@
 		long session_id, id, offset, total_size, length, flags;
 		long ack_session_id, ack_unique_id, ack_length;
 
-		memcpy(blank, 0, 4);
+		blank[0] = blank[1] = blank[2] = blank[3] = 0;
+
+		g_strlcat(str, "\r\n", 3);
 
 		c = str + strlen(str);
 
@@ -388,20 +405,33 @@
 
 		c += strlen(msn_message_get_body(msg));
 
-		memcpy(c, blank,                      1); c++;
+		if (strlen(msn_message_get_body(msg)) > 0)
+			*c++ = '\0';
+
 		memcpy(c, &msg->msnslp_footer.app_id, 4); c += 4;
+		*c = '\0';
+
+		gaim_debug_misc("msn", "cur size = %d\n", (c - str));
+		gaim_debug_misc("msn", "msg->size = %d\n", msg->size);
+
+		if (msg->size != (c - str))
+		{
+			gaim_debug(GAIM_DEBUG_ERROR, "msn",
+					   "Outgoing message size (%d) and string length (%d) "
+					   "do not match!\n", msg->size, (c - str));
+		}
 	}
 	else
 	{
 		g_snprintf(buf, sizeof(buf), "\r\n%s", msn_message_get_body(msg));
 
 		g_strlcat(str, buf, len);
-	}
 
-	if (msg->size != strlen(msg_start)) {
-		gaim_debug(GAIM_DEBUG_ERROR, "msn",
-				   "Outgoing message size (%d) and string length (%d) "
-				   "do not match!\n", msg->size, strlen(msg_start));
+		if (msg->size != strlen(msg_start)) {
+			gaim_debug(GAIM_DEBUG_ERROR, "msn",
+					   "Outgoing message size (%d) and string length (%d) "
+					   "do not match!\n", msg->size, strlen(msg_start));
+		}
 	}
 
 	return str;
@@ -430,7 +460,7 @@
 	g_return_if_fail(user != NULL);
 
 	msg->sender = user;
-	
+
 	msn_user_ref(msg->sender);
 }
 
@@ -449,7 +479,7 @@
 	g_return_if_fail(user != NULL);
 
 	msg->receiver = user;
-	
+
 	msn_user_ref(msg->receiver);
 }
 
@@ -509,6 +539,9 @@
 	if (msg->body != NULL) {
 		msg->size -= strlen(msg->body);
 		g_free(msg->body);
+
+		if (msg->msnslp_message)
+			msg->size--;
 	}
 
 	for (c = body; *c != '\0'; c++) {
@@ -532,6 +565,9 @@
 	msg->body = buf;
 
 	msg->size += new_len;
+
+	if (msg->msnslp_message)
+		msg->size++;
 }
 
 const char *
--- a/src/protocols/msn/msg.h	Tue Sep 09 16:55:10 2003 +0000
+++ b/src/protocols/msn/msg.h	Wed Sep 10 00:24:48 2003 +0000
@@ -87,6 +87,13 @@
 MsnMessage *msn_message_new(void);
 
 /**
+ * Creates a new, empty MSNSLP message.
+ *
+ * @return A new MSNSLP message.
+ */
+MsnMessage *msn_message_new_msnslp(void);
+
+/**
  * Creates a new message based off a string.
  *
  * @param session The MSN session.
--- a/src/protocols/msn/msnslp.c	Tue Sep 09 16:55:10 2003 +0000
+++ b/src/protocols/msn/msnslp.c	Wed Sep 10 00:24:48 2003 +0000
@@ -27,9 +27,7 @@
 {
 	MsnMessage *msg;
 
-	msg = msn_message_new();
-
-	msg->msnslp_message = TRUE;
+	msg = msn_message_new_msnslp();
 
 	msg->msnslp_header.length = acked_msg->msnslp_header.length;
 	msg->msnslp_header.flags = 0x02;
@@ -110,7 +108,9 @@
 
 	msg->msnslp_header.id = slpsession->prev_msg_id;
 	msg->msnslp_header.ack_session_id = rand() % 0xFFFFFF00;
-	msg->msnslp_header.total_size = strlen(msn_message_get_body(msg));
+
+	if (msn_message_get_body(msg) != NULL)
+		msg->msnslp_header.total_size = strlen(msn_message_get_body(msg));
 
 	msn_message_set_charset(msg, NULL);
 
@@ -124,25 +124,29 @@
 
 void
 msn_slp_session_request_user_display(MsnSlpSession *slpsession,
-									 const MsnUser *localUser,
-									 const MsnUser *remoteUser,
+									 MsnUser *local_user,
+									 MsnUser *remote_user,
 									 const MsnObject *obj)
 {
 	MsnMessage *invite_msg;
 	char *msnobj_data;
 	char *msnobj_base64;
 	char *content;
-	char *header;
+	char *body;
+	char *c;
 
-	g_return_if_fail(slpsession != NULL);
-	g_return_if_fail(localUser  != NULL);
-	g_return_if_fail(remoteUser != NULL);
-	g_return_if_fail(obj        != NULL);
+	g_return_if_fail(slpsession  != NULL);
+	g_return_if_fail(local_user  != NULL);
+	g_return_if_fail(remote_user != NULL);
+	g_return_if_fail(obj         != NULL);
 
 	msnobj_data = msn_object_to_string(obj);
 	msnobj_base64 = tobase64(msnobj_data, strlen(msnobj_data));
 	g_free(msnobj_data);
 
+	if ((c = strchr(msnobj_base64, '=')) != NULL)
+		*c = '\0';
+
 	if (slpsession->session_id == 0)
 		slpsession->session_id = rand() % 0xFFFFFF00;
 
@@ -156,7 +160,7 @@
 
 	g_free(msnobj_base64);
 
-	header = g_strdup_printf(
+	body = g_strdup_printf(
 		"INVITE MSNMSGR:%s MSNSLP/1.0\r\n"
 		"To: <msnmsgr:%s>\r\n"
 		"From: <msnmsgr:%s>\r\n"
@@ -169,13 +173,24 @@
 		"\r\n"
 		"%s"
 		"\r\n\r\n",
-		msn_user_get_passport(remoteUser),
-		msn_user_get_passport(localUser),
-		msn_user_get_passport(remoteUser),
+		msn_user_get_passport(remote_user),
+		msn_user_get_passport(remote_user),
+		msn_user_get_passport(local_user),
 		strlen(content) + 5,
 		content);
 
-	invite_msg = msn_message_new();
+	g_free(content);
+
+	gaim_debug_misc("msn", "Message = {%s}\n", body);
+
+	invite_msg = msn_message_new_msnslp();
+
+	msn_message_set_sender(invite_msg, local_user);
+	msn_message_set_receiver(invite_msg, remote_user);
+
+	msn_message_set_body(invite_msg, body);
+
+	g_free(body);
 
 	msn_slp_session_send_msg(slpsession, invite_msg);
 
@@ -189,7 +204,7 @@
 	gboolean session_ended = FALSE;
 
 	if (swboard->slp_session == NULL)
-		swboard->slp_session = msn_slp_session_new(swboard, TRUE);
+		swboard->slp_session = msn_slp_session_new(swboard, FALSE);
 
 	session_ended = msn_slp_session_msg_received(swboard->slp_session, msg);
 
--- a/src/protocols/msn/msnslp.h	Tue Sep 09 16:55:10 2003 +0000
+++ b/src/protocols/msn/msnslp.h	Wed Sep 10 00:24:48 2003 +0000
@@ -88,8 +88,8 @@
  * @param obj        The MSNObject representing the user display info.
  */
 void msn_slp_session_request_user_display(MsnSlpSession *session,
-										  const MsnUser *localUser,
-										  const MsnUser *remoteUser,
+										  MsnUser *localUser,
+										  MsnUser *remoteUser,
 										  const MsnObject *obj);
 
 /**
--- a/src/protocols/msn/notification.c	Tue Sep 09 16:55:10 2003 +0000
+++ b/src/protocols/msn/notification.c	Wed Sep 10 00:24:48 2003 +0000
@@ -1033,7 +1033,10 @@
 iln_cmd(MsnServConn *servconn, const char *command, const char **params,
 		size_t param_count)
 {
-	GaimConnection *gc = servconn->session->account->gc;
+	MsnSession *session = servconn->session;
+	GaimConnection *gc = session->account->gc;
+	MsnUser *user;
+	MsnObject *msnobj;
 	int status = 0;
 	const char *state, *passport, *friend;
 	GaimBuddy *b;
@@ -1042,6 +1045,14 @@
 	passport = params[2];
 	friend   = msn_url_decode(params[3]);
 
+	if (session->protocol_ver >= 9 && param_count == 6)
+	{
+		user = msn_users_find_with_passport(session->users, passport);
+
+		msnobj = msn_object_new_from_string(msn_url_decode(params[5]));
+		msn_user_set_object(user, msnobj);
+	}
+
 	serv_got_alias(gc, (char *)passport, (char *)friend);
 
 	if ((b = gaim_find_buddy(gc->account, passport)) != NULL)
--- a/src/protocols/msn/servconn.c	Tue Sep 09 16:55:10 2003 +0000
+++ b/src/protocols/msn/servconn.c	Wed Sep 10 00:24:48 2003 +0000
@@ -336,8 +336,10 @@
 {
 	g_return_val_if_fail(servconn != NULL, 0);
 
+#if 0
 	gaim_debug(GAIM_DEBUG_MISC, "msn", "C: %s%s", buf,
 			   (*(buf + size - 1) == '\n' ? "" : "\n"));
+#endif
 
 	return write(servconn->fd, buf, size);
 }
--- a/src/protocols/msn/switchboard.c	Tue Sep 09 16:55:10 2003 +0000
+++ b/src/protocols/msn/switchboard.c	Wed Sep 10 00:24:48 2003 +0000
@@ -86,8 +86,31 @@
 		 size_t param_count)
 {
 	MsnSwitchBoard *swboard = servconn->data;
+	MsnSession *session = servconn->session;
 
-	return send_clientcaps(swboard);
+	send_clientcaps(swboard);
+
+#if 0
+	if (session->protocol_ver >= 9)
+	{
+		MsnUser *local_user, *remote_user;
+
+		remote_user = msn_user_new(session,
+				msn_user_get_passport(msn_switchboard_get_user(swboard)),
+				NULL);
+		local_user = msn_user_new(session,
+								  gaim_account_get_username(session->account),
+								  NULL);
+
+		swboard->slp_session = msn_slp_session_new(swboard, TRUE);
+
+		msn_slp_session_request_user_display(swboard->slp_session,
+											 local_user, remote_user,
+											 msn_user_get_object(remote_user));
+	}
+#endif
+
+	return FALSE;
 }
 
 static gboolean
@@ -614,11 +637,13 @@
 	int ret;
 
 	g_return_val_if_fail(swboard != NULL, FALSE);
-	g_return_val_if_fail(msg != NULL, FALSE);
+	g_return_val_if_fail(msg     != NULL, FALSE);
 
 	msn_message_set_transaction_id(msg, ++swboard->trId);
 	buf = msn_message_build_string(msg);
 
+	g_return_val_if_fail(buf != NULL, FALSE);
+
 	if (swboard->servconn->txqueue != NULL || !swboard->in_use) {
 		gaim_debug(GAIM_DEBUG_INFO, "msn", "Appending message to queue.\n");
 
@@ -628,7 +653,7 @@
 		return TRUE;
 	}
 
-	ret = msn_servconn_write(swboard->servconn, buf, strlen(buf));
+	ret = msn_servconn_write(swboard->servconn, buf, msg->size);
 
 	g_free(buf);
 
--- a/src/protocols/msn/user.c	Tue Sep 09 16:55:10 2003 +0000
+++ b/src/protocols/msn/user.c	Wed Sep 10 00:24:48 2003 +0000
@@ -67,6 +67,9 @@
 	if (user->group_ids != NULL)
 		g_list_free(user->group_ids);
 
+	if (user->msnobj != NULL)
+		msn_object_destroy(user->msnobj);
+
 	if (user->passport != NULL) g_free(user->passport);
 	if (user->name     != NULL) g_free(user->name);
 
--- a/src/protocols/msn/user.h	Tue Sep 09 16:55:10 2003 +0000
+++ b/src/protocols/msn/user.h	Wed Sep 10 00:24:48 2003 +0000
@@ -33,28 +33,29 @@
  */
 struct _MsnUser
 {
-	MsnSession *session;    /**< The MSN session.           */
+	MsnSession *session;    /**< The MSN session.             */
 
-	char *passport;         /**< The passport account.      */
-	char *name;             /**< The friendly name.         */
+	char *passport;         /**< The passport account.        */
+	char *name;             /**< The friendly name.           */
 
 	struct
 	{
-		char *home;         /**< Home phone number.         */
-		char *work;         /**< Work phone number.         */
-		char *mobile;       /**< Mobile phone number.       */
+		char *home;         /**< Home phone number.           */
+		char *work;         /**< Work phone number.           */
+		char *mobile;       /**< Mobile phone number.         */
 
 	} phone;
 
-	gboolean mobile;        /**< Signed up with MSN Mobile. */
+	gboolean authorized;    /**< Authorized to add this user. */
+	gboolean mobile;        /**< Signed up with MSN Mobile.   */
 
-	GList *group_ids;       /**< The group IDs.             */
+	GList *group_ids;       /**< The group IDs.               */
 
-	size_t ref_count;       /**< The reference count.       */
+	size_t ref_count;       /**< The reference count.         */
 
-	MsnObject *msnobj;      /**< The user's MSN Object.     */
+	MsnObject *msnobj;      /**< The user's MSN Object.       */
 
-	GHashTable *clientcaps; /**< The client's capabilities. */
+	GHashTable *clientcaps; /**< The client's capabilities.   */
 };
 
 /**