soc.2010.msn-tlc: 2b033301: Introduce SlpMessagePart, It will replac...
masca at cpw.pidgin.im
masca at cpw.pidgin.im
Wed Jun 16 19:15:57 EDT 2010
-----------------------------------------------------------------
Revision: 2b033301427d91a22a7846282b10e24ac754694b
Ancestor: 9833702ef48cab7ac01356e052d78c9f0f01ae83
Author: masca at cpw.pidgin.im
Date: 2010-06-16T21:25:11
Branch: im.pidgin.soc.2010.msn-tlc
URL: http://d.pidgin.im/viewmtn/revision/info/2b033301427d91a22a7846282b10e24ac754694b
Added files:
libpurple/protocols/msn/slpmsg_part.c
libpurple/protocols/msn/slpmsg_part.h
Modified files:
libpurple/protocols/msn/Makefile.am
libpurple/protocols/msn/Makefile.mingw
ChangeLog:
Introduce SlpMessagePart, It will replace MsnMessage in every Slp related code so MsnMessage just get used where it makes sense, in the Switchboard.
-------------- next part --------------
============================================================
--- libpurple/protocols/msn/slpmsg_part.c 3f42c5411427812a44062de598c5b7f8cfd3d599
+++ libpurple/protocols/msn/slpmsg_part.c 3f42c5411427812a44062de598c5b7f8cfd3d599
@@ -0,0 +1,171 @@
+#include "internal.h"
+
+#include "slpmsg.h"
+#include "slpmsg_part.h"
+
+MsnSlpMessagePart *msn_slpmsgpart_new(MsnP2PHeader *header, MsnP2PFooter *footer)
+{
+ MsnSlpMessagePart *part;
+
+ part = g_new0(MsnSlpMessagePart, 1);
+
+ if (header)
+ part->header = g_memdup(header, P2P_PACKET_HEADER_SIZE);
+ if (footer)
+ part->footer = g_memdup(footer, P2P_PACKET_FOOTER_SIZE);
+
+ part->ack_cb = msn_slpmsgpart_ack;
+ part->nack_cb = msn_slpmsgpart_nak;
+
+ return part;
+}
+
+MsnSlpMessagePart *msn_slpmsgpart_new_from_data(const char *data, size_t data_len)
+{
+ MsnSlpMessagePart *part;
+ MsnP2PHeader *header;
+ const char *tmp;
+ int body_len;
+
+ tmp = data;
+ part = msn_slpmsgpart_new(NULL, NULL);
+
+ if (data_len < sizeof(*header)) {
+ return NULL;
+ }
+
+ /* Extract the binary SLP header */
+ part->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) {
+ part->size = body_len;
+ part->buffer = g_malloc(body_len);
+ memcpy(part->buffer, tmp, body_len);
+ tmp += body_len;
+ }
+
+ /* Extract the footer */
+ if (body_len >= 0)
+ part->footer = msn_p2p_footer_from_wire((MsnP2PFooter*)tmp);
+
+ return part;
+}
+
+void msn_slpmsgpart_destroy(MsnSlpMessagePart *part)
+{
+ g_free(part->header);
+ g_free(part->footer);
+
+ g_free(part);
+
+}
+
+void msn_slpmsgpart_set_bin_data(MsnSlpMessagePart *part, const void *data, size_t len)
+{
+ g_return_if_fail(part != NULL);
+
+ if (part->buffer != NULL)
+ g_free(part->buffer);
+
+ if (data != NULL && len > 0) {
+ part->buffer = g_malloc(len + 1);
+ memcpy(part->buffer, data, len);
+ part->buffer[len] = '\0';
+ part->size = len;
+ } else {
+ part->buffer = NULL;
+ part->size = 0;
+ }
+
+}
+
+char *msn_slpmsgpart_serialize(MsnSlpMessagePart *part, size_t *ret_size)
+{
+ MsnP2PHeader *header;
+ MsnP2PFooter *footer;
+ char *base;
+ char *tmp;
+ size_t siz;
+
+ base = g_malloc(P2P_PACKET_HEADER_SIZE + part->size + sizeof(MsnP2PFooter));
+ tmp = base;
+
+ header = msn_p2p_header_to_wire(part->header);
+ footer = msn_p2p_footer_to_wire(part->footer);
+
+ siz = sizeof(MsnP2PHeader);
+ /* Copy header */
+ memcpy(tmp, (char*)header, siz);
+ tmp += siz;
+
+ /* Copy body */
+ memcpy(tmp, part->buffer, part->size);
+ tmp += part->size;
+
+ /* Copy footer */
+ siz = sizeof(MsnP2PFooter);
+ memcpy(tmp, (char*)footer, siz);
+ tmp += siz;
+
+ *ret_size = tmp - base;
+
+ return base;
+}
+/* We have received the message ack */
+void
+msn_slpmsgpart_ack(MsnSlpMessagePart *part, void *data)
+{
+ MsnSlpMessage *slpmsg;
+ long long real_size;
+
+ slpmsg = data;
+
+ real_size = (slpmsg->flags == P2P_ACK) ? 0 : slpmsg->size;
+
+ slpmsg->offset += part->header->length;
+
+ slpmsg->parts = g_list_remove(slpmsg->parts, part);
+
+ if (slpmsg->offset < real_size)
+ {
+ if (slpmsg->slpcall->xfer && purple_xfer_get_status(slpmsg->slpcall->xfer) == PURPLE_XFER_STATUS_STARTED)
+ {
+ slpmsg->slpcall->xfer_msg = slpmsg;
+ purple_xfer_prpl_ready(slpmsg->slpcall->xfer);
+ }
+ else
+ msn_slplink_send_msgpart(slpmsg->slplink, slpmsg);
+ }
+ else
+ {
+ /* The whole message has been sent */
+ if (slpmsg->flags == P2P_MSN_OBJ_DATA ||
+ slpmsg->flags == (P2P_WML2009_COMP | P2P_MSN_OBJ_DATA) ||
+ slpmsg->flags == P2P_FILE_DATA)
+ {
+ if (slpmsg->slpcall != NULL)
+ {
+ if (slpmsg->slpcall->cb)
+ slpmsg->slpcall->cb(slpmsg->slpcall,
+ NULL, 0);
+ }
+ }
+ }
+}
+
+/* We have received the message nak. */
+void
+msn_slpmsgpart_nak(MsnSlpMessagePart *part, void *data)
+{
+ MsnSlpMessage *slpmsg;
+
+ slpmsg = data;
+
+ msn_slplink_send_msgpart(slpmsg->slplink, slpmsg);
+
+ slpmsg->parts = g_list_remove(slpmsg->parts, part);
+}
============================================================
--- libpurple/protocols/msn/slpmsg_part.h caed71263d5b10963b84e99598d45e8bf64bba13
+++ libpurple/protocols/msn/slpmsg_part.h caed71263d5b10963b84e99598d45e8bf64bba13
@@ -0,0 +1,34 @@
+#ifndef MSN_SLPMSG_PART_H
+#define MSN_SLPMSG_PART_H
+
+#include "p2p.h"
+
+typedef struct _MsnSlpMessagePart MsnSlpMessagePart;
+typedef void (*MsnSlpPartCb)(MsnSlpMessagePart *part, void *data);
+
+struct _MsnSlpMessagePart
+{
+ MsnP2PHeader *header;
+ MsnP2PFooter *footer;
+
+ MsnSlpPartCb ack_cb;
+ MsnSlpPartCb nack_cb;
+
+ guchar *buffer;
+ size_t size;
+};
+
+MsnSlpMessagePart *msn_slpmsgpart_new(MsnP2PHeader *header, MsnP2PFooter *footer);
+
+MsnSlpMessagePart *msn_slpmsgpart_new_from_data(const char *data, size_t data_len);
+
+void msn_slpmsgpart_destroy(MsnSlpMessagePart *part);
+
+void msn_slpmsgpart_set_bin_data(MsnSlpMessagePart *part, const void *data, size_t len);
+
+char *msn_slpmsgpart_serialize(MsnSlpMessagePart *part, size_t *ret_size);
+
+void msn_slpmsgpart_ack(MsnSlpMessagePart *part, void *data);
+
+void msn_slpmsgpart_nak(MsnSlpMessagePart *part, void *data);
+#endif /* MSN_SLPMSG_PART_H */
============================================================
--- libpurple/protocols/msn/Makefile.am 92e18590a57f724e046601ca95ef41d92bcf7735
+++ libpurple/protocols/msn/Makefile.am 5caeb94245d48d0c31803caf6487013d52ae088c
@@ -50,6 +50,8 @@ MSNSOURCES = \
slplink.h \
slpmsg.c \
slpmsg.h \
+ slpmsg_part.c \
+ slpmsg_part.h \
soap.c \
soap.h \
state.c \
============================================================
--- libpurple/protocols/msn/Makefile.mingw e3371113dc93110638043690e78c2f7af03a0d74
+++ libpurple/protocols/msn/Makefile.mingw df1732a022290a420ce30a5e4091742221dbfa55
@@ -60,6 +60,7 @@ C_SRC = cmdproc.c \
slpcall.c \
slplink.c \
slpmsg.c \
+ slpmsg_part.c \
soap.c\
state.c \
sbconn.c \
More information about the Commits
mailing list