Mercurial > pidgin.yaz
diff libpurple/protocols/msn/slpmsg.c @ 31599:34da321b60f1
Try to hide all P2P fields away behind accessor functions.
author | Elliott Sales de Andrade <qulogic@pidgin.im> |
---|---|
date | Thu, 20 Jan 2011 06:43:45 +0000 |
parents | dcd407e6c004 |
children | 9562a7baa9e4 |
line wrap: on
line diff
--- a/libpurple/protocols/msn/slpmsg.c Thu Jan 20 06:41:34 2011 +0000 +++ b/libpurple/protocols/msn/slpmsg.c Thu Jan 20 06:43:45 2011 +0000 @@ -48,8 +48,7 @@ else slpmsg->slplink = NULL; - slpmsg->header = g_new0(MsnP2PHeader, 1); - slpmsg->footer = NULL; + slpmsg->p2p_info = msn_p2p_info_new(); return slpmsg; } @@ -90,8 +89,7 @@ slplink->slp_msgs = g_list_remove(slplink->slp_msgs, slpmsg); - g_free(slpmsg->header); - g_free(slpmsg->footer); + msn_p2p_info_free(slpmsg->p2p_info); g_free(slpmsg); } @@ -200,18 +198,20 @@ return slpmsg; } -MsnSlpMessage *msn_slpmsg_ack_new(MsnP2PHeader *header) +MsnSlpMessage *msn_slpmsg_ack_new(MsnP2PInfo *ack_info) { MsnSlpMessage *slpmsg; + MsnP2PInfo *new_info; slpmsg = msn_slpmsg_new(NULL); - slpmsg->header->session_id = header->session_id; - slpmsg->size = header->total_size; - slpmsg->header->flags = P2P_ACK; - slpmsg->header->ack_id = header->id; - slpmsg->header->ack_sub_id = header->ack_id; - slpmsg->header->ack_size = header->total_size; + new_info = slpmsg->p2p_info; + msn_p2p_info_set_session_id(new_info, msn_p2p_info_get_session_id(ack_info)); + slpmsg->size = msn_p2p_info_get_total_size(ack_info); + msn_p2p_info_set_flags(new_info, P2P_ACK); + msn_p2p_info_set_ack_id(new_info, msn_p2p_info_get_id(ack_info)); + msn_p2p_info_set_ack_sub_id(new_info, msn_p2p_info_get_ack_id(ack_info)); + msn_p2p_info_set_ack_size(new_info, msn_p2p_info_get_total_size(ack_info)); slpmsg->info = "SLP ACK"; return slpmsg; @@ -223,7 +223,7 @@ slpmsg = msn_slpmsg_new(NULL); slpmsg->slpcall = slpcall; - slpmsg->header->flags = P2P_MSN_OBJ_DATA; + msn_p2p_info_set_flags(slpmsg->p2p_info, P2P_MSN_OBJ_DATA); slpmsg->info = "SLP DATA"; msn_slpmsg_set_image(slpmsg, img); @@ -238,7 +238,7 @@ slpmsg = msn_slpmsg_new(NULL); slpmsg->slpcall = slpcall; - slpmsg->header->session_id = slpcall->session_id; + msn_p2p_info_set_session_id(slpmsg->p2p_info, slpcall->session_id); msn_slpmsg_set_body(slpmsg, NULL, 4); slpmsg->info = "SLP DATA PREP"; @@ -253,7 +253,7 @@ slpmsg = msn_slpmsg_new(NULL); slpmsg->slpcall = slpcall; - slpmsg->header->flags = P2P_FILE_DATA; + msn_p2p_info_set_flags(slpmsg->p2p_info, P2P_FILE_DATA); slpmsg->info = "SLP FILE"; slpmsg->size = size; @@ -266,27 +266,25 @@ char *footer; char *base; char *tmp; - size_t siz; + size_t header_size, footer_size; - base = g_malloc(P2P_PACKET_HEADER_SIZE + slpmsg->size + P2P_PACKET_FOOTER_SIZE); + header = msn_p2p_header_to_wire(slpmsg->p2p_info, &header_size); + footer = msn_p2p_footer_to_wire(slpmsg->p2p_info, &footer_size); + + base = g_malloc(header_size + slpmsg->size + footer_size); tmp = base; - header = msn_p2p_header_to_wire(slpmsg->header); - footer = msn_p2p_footer_to_wire(slpmsg->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, slpmsg->buffer, slpmsg->size); tmp += slpmsg->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; @@ -302,15 +300,7 @@ str = g_string_new(NULL); - g_string_append_printf(str, "Session ID: %u\r\n", slpmsg->header->session_id); - g_string_append_printf(str, "ID: %u\r\n", slpmsg->header->id); - g_string_append_printf(str, "Offset: %" G_GUINT64_FORMAT "\r\n", slpmsg->header->offset); - g_string_append_printf(str, "Total size: %" G_GUINT64_FORMAT "\r\n", slpmsg->header->total_size); - g_string_append_printf(str, "Length: %u\r\n", slpmsg->header->length); - g_string_append_printf(str, "Flags: 0x%x\r\n", slpmsg->header->flags); - g_string_append_printf(str, "ACK ID: %u\r\n", slpmsg->header->ack_id); - g_string_append_printf(str, "SUB ID: %u\r\n", slpmsg->header->ack_sub_id); - g_string_append_printf(str, "ACK Size: %" G_GUINT64_FORMAT "\r\n", slpmsg->header->ack_size); + msn_p2p_info_to_string(slpmsg->p2p_info, str); if (purple_debug_is_verbose() && slpmsg->buffer != NULL) { g_string_append_len(str, (gchar*)slpmsg->buffer, slpmsg->size); @@ -323,7 +313,5 @@ } - g_string_append_printf(str, "Footer: %u\r\n", slpmsg->footer->value); - purple_debug_info("msn", "SlpMessage %s:\n{%s}\n", slpmsg->info, str->str); }