Mercurial > pidgin
diff libpurple/protocols/msn/slpmsg_part.c @ 31558:ce968e115c95
propagate from branch 'im.pidgin.cpw.masca.p2p' (head 33ca865dacb9e5bcf763d06f6a42cbaca337cc64)
to branch 'im.pidgin.pidgin' (head 92f47f4e8b0cbb107fd97e1ab814d1cedbf109ad)
author | Elliott Sales de Andrade <qulogic@pidgin.im> |
---|---|
date | Fri, 06 May 2011 06:25:14 +0000 |
parents | 8cf9270acf4c |
children | eb1bbaae3427 |
line wrap: on
line diff
--- a/libpurple/protocols/msn/slpmsg_part.c Tue Jan 04 05:05:06 2011 +0000 +++ b/libpurple/protocols/msn/slpmsg_part.c Fri May 06 06:25:14 2011 +0000 @@ -28,16 +28,13 @@ #include "slpmsg.h" #include "slpmsg_part.h" -MsnSlpMessagePart *msn_slpmsgpart_new(MsnP2PHeader *header, MsnP2PFooter *footer) +MsnSlpMessagePart *msn_slpmsgpart_new(MsnP2PInfo *info) { 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->info = info; part->ack_cb = msn_slpmsgpart_ack; part->nak_cb = msn_slpmsgpart_nak; @@ -48,20 +45,23 @@ MsnSlpMessagePart *msn_slpmsgpart_new_from_data(const char *data, size_t data_len) { MsnSlpMessagePart *part; + MsnP2PInfo *info; + size_t len; int body_len; - if (data_len < P2P_PACKET_HEADER_SIZE) { + info = msn_p2p_info_new(MSN_P2P_VERSION_ONE); + + /* Extract the binary SLP header */ + len = msn_p2p_header_from_wire(info, data, data_len); + if (len == 0) { + msn_p2p_info_free(info); return NULL; } - - part = msn_slpmsgpart_new(NULL, NULL); - - /* Extract the binary SLP header */ - part->header = msn_p2p_header_from_wire(data); - data += P2P_PACKET_HEADER_SIZE; + data += len; + part = msn_slpmsgpart_new(info); /* Extract the body */ - body_len = data_len - P2P_PACKET_HEADER_SIZE - P2P_PACKET_FOOTER_SIZE; + body_len = data_len - len - P2P_PACKET_FOOTER_SIZE; /* msg->body_len = msg->msnslp_header.length; */ if (body_len > 0) { @@ -72,16 +72,16 @@ } /* Extract the footer */ - if (body_len >= 0) - part->footer = msn_p2p_footer_from_wire(data); + if (body_len >= 0) + msn_p2p_footer_from_wire(part->info, data); return part; } static void msn_slpmsgpart_destroy(MsnSlpMessagePart *part) { - g_free(part->header); - g_free(part->footer); + g_free(part->info); + g_free(part->buffer); g_free(part); @@ -137,27 +137,25 @@ char *footer; char *base; char *tmp; - size_t siz; + size_t header_size, footer_size; - base = g_malloc(P2P_PACKET_HEADER_SIZE + part->size + P2P_PACKET_FOOTER_SIZE); + header = msn_p2p_header_to_wire(part->info, &header_size); + footer = msn_p2p_footer_to_wire(part->info, &footer_size); + + base = g_malloc(header_size + part->size + footer_size); tmp = base; - header = msn_p2p_header_to_wire(part->header); - footer = msn_p2p_footer_to_wire(part->footer); - - siz = P2P_PACKET_HEADER_SIZE; /* Copy header */ - memcpy(tmp, header, siz); - tmp += siz; + memcpy(tmp, header, header_size); + tmp += header_size; /* Copy body */ memcpy(tmp, part->buffer, part->size); tmp += part->size; /* Copy footer */ - siz = P2P_PACKET_FOOTER_SIZE; - memcpy(tmp, footer, siz); - tmp += siz; + memcpy(tmp, footer, footer_size); + tmp += footer_size; *ret_size = tmp - base; @@ -166,23 +164,27 @@ return base; } + /* We have received the message ack */ void msn_slpmsgpart_ack(MsnSlpMessagePart *part, void *data) { MsnSlpMessage *slpmsg; + guint64 offset; long long real_size; slpmsg = data; - real_size = (slpmsg->header->flags == P2P_ACK) ? 0 : slpmsg->size; + real_size = (msn_p2p_info_get_flags(slpmsg->p2p_info) == P2P_ACK) ? 0 : slpmsg->size; - slpmsg->header->offset += part->header->length; + offset = msn_p2p_info_get_offset(slpmsg->p2p_info); + offset += msn_p2p_info_get_length(part->info); + msn_p2p_info_set_offset(slpmsg->p2p_info, offset); slpmsg->parts = g_list_remove(slpmsg->parts, part); msn_slpmsgpart_unref(part); - if (slpmsg->header->offset < real_size) + if (offset < real_size) { if (slpmsg->slpcall->xfer && purple_xfer_get_status(slpmsg->slpcall->xfer) == PURPLE_XFER_STATUS_STARTED) { @@ -195,7 +197,7 @@ else { /* The whole message has been sent */ - if (msn_p2p_msg_is_data(slpmsg->header->flags)) + if (msn_p2p_msg_is_data(msn_p2p_info_get_flags(slpmsg->p2p_info))) { if (slpmsg->slpcall != NULL) { @@ -221,3 +223,9 @@ msn_slpmsgpart_unref(part); } +void +msn_slpmsgpart_to_string(MsnSlpMessagePart *part, GString *str) +{ + msn_p2p_info_to_string(part->info, str); +} +