soc.2010.msn-tlc: dfe571b8: Add SlpMessage parser and serializer fun...

masca at cpw.pidgin.im masca at cpw.pidgin.im
Tue Jun 8 18:25:47 EDT 2010


-----------------------------------------------------------------
Revision: dfe571b8a1cbc768ce058e22ca86265cee393189
Ancestor: 1914b79c4fd991f47bd28881bf51f40fa3885727
Author: masca at cpw.pidgin.im
Date: 2010-06-08T21:21:49
Branch: im.pidgin.soc.2010.msn-tlc
URL: http://d.pidgin.im/viewmtn/revision/info/dfe571b8a1cbc768ce058e22ca86265cee393189

Modified files:
        libpurple/protocols/msn/slpmsg.c
        libpurple/protocols/msn/slpmsg.h

ChangeLog: 

Add SlpMessage parser and serializer functions to SlpMessage module.

-------------- next part --------------
============================================================
--- libpurple/protocols/msn/slpmsg.c	04c5f7eb550f0eb0e564ed29aa64f00849048a4e
+++ libpurple/protocols/msn/slpmsg.c	205952ffc365e6441162a4e94f69c224fa73ea95
@@ -56,6 +56,41 @@ msn_slpmsg_new(MsnSlpLink *slplink)
 	return slpmsg;
 }
 
+MsnSlpMessage *msn_slpmsg_new_from_data(const char *data, size_t data_len)
+{
+	MsnSlpMessage *slpmsg;
+	MsnP2PHeader *header;
+	const char *tmp;
+	int body_len;
+
+	tmp = data;
+	slpmsg = msn_slpmsg_new(NULL);
+
+	if (data_len < sizeof(*header)) {
+		return NULL;
+	}
+
+	/* Extract the binary SLP header */
+	slpmsg->header = msn_p2p_header_from_wire((MsnP2PHeader*)tmp);
+
+	/* Extract the body */
+	body_len = data_len - (tmp - data);
+	/* msg->body_len = msg->msnslp_header.length; */
+
+	if (body_len > 0) {
+		slpmsg->size = body_len;
+		slpmsg->buffer = g_malloc(body_len);
+		memcpy(slpmsg->buffer, tmp, body_len);
+		tmp += body_len;
+	}
+
+	/* Extract the footer */
+	if (body_len >= 0) 
+		slpmsg->footer = msn_p2p_footer_from_wire((MsnP2PFooter*)tmp);
+
+	return slpmsg;
+}
+
 void
 msn_slpmsg_destroy(MsnSlpMessage *slpmsg)
 {
@@ -218,3 +253,36 @@ msn_slpmsg_sip_new(MsnSlpCall *slpcall, 
 
 	return slpmsg;
 }
+
+char *msn_slpmsg_serialize(MsnSlpMessage *slpmsg, size_t *ret_size)
+{
+	MsnP2PHeader *header;
+	MsnP2PFooter *footer;
+	char *base;
+	char *tmp;
+	size_t siz;
+
+	base = g_malloc(P2P_PACKET_HEADER_SIZE + slpmsg->size + sizeof(MsnP2PFooter));
+	tmp = base;
+
+	header = msn_p2p_header_to_wire(slpmsg->header);
+	footer = msn_p2p_footer_to_wire(slpmsg->footer);
+
+	siz = sizeof(MsnP2PHeader);
+	/* Copy header */
+	memcpy(tmp, (char*)header, siz);
+	tmp += siz;
+
+	/* Copy body */
+	memcpy(tmp, slpmsg->buffer, slpmsg->size);
+	tmp += slpmsg->size;
+
+	/* Copy footer */
+	siz = sizeof(MsnP2PFooter);
+	memcpy(tmp, (char*)footer, siz);
+	tmp += siz;
+
+	*ret_size = tmp - base;
+
+	return base;
+}
============================================================
--- libpurple/protocols/msn/slpmsg.h	85589294b2abbca2e5d5f311b0571772b91398b9
+++ libpurple/protocols/msn/slpmsg.h	d908e8ec199df6b6d8ca6103e8c065b1eb3586dc
@@ -94,6 +94,16 @@ MsnSlpMessage *msn_slpmsg_new(MsnSlpLink
 MsnSlpMessage *msn_slpmsg_new(MsnSlpLink *slplink);
 
 /**
+ * Creates a MsnSlpMessage without a MsnSlpLink by parsing the raw data.
+ *
+ * @param data 		The raw data with the slp message.
+ * @param data_len 	The len of the data
+ *
+ * @return The createed slp message.
+ */
+MsnSlpMessage *msn_slpmsg_new_from_data(const char *data, size_t data_len);
+
+/**
  * Destroys a slp message
  *
  * @param slpmsg The slp message to destory.
@@ -113,4 +123,14 @@ void msn_slpmsg_show(MsnMessage *msg);
 
 void msn_slpmsg_show(MsnMessage *msg);
 
+/**
+ * Serialize the MsnSlpMessage in a way it can be used to be transmited
+ *
+ * @param slpmsg 	The MsnSlpMessage.
+ * @param ret_size 	The size of the buffer cointaining the message.
+ *
+ * @return a buffer with the serialized data.
+ */
+char *msn_slpmsg_serialize(MsnSlpMessage *slpmsg, size_t *ret_size);
+
 #endif /* _MSN_SLPMSG_H_ */


More information about the Commits mailing list