annotate libpurple/protocols/msn/slpmsg_part.c @ 30935:2de522fa534a

Fix a lot more leaks, some old, some new.
author Elliott Sales de Andrade <qulogic@pidgin.im>
date Sun, 21 Nov 2010 09:56:48 +0000
parents 4e097dfb7784
children 0c60da8eb88c
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
30796
e545b2b6f66a Introduce SlpMessagePart, It will replace MsnMessage in every Slp related code so MsnMessage just get used where it makes sense, in the Switchboard.
masca@cpw.pidgin.im
parents:
diff changeset
1 #include "internal.h"
30849
e358e16e527f Add a ref to the part at sbconn and add some debug output.
masca@cpw.pidgin.im
parents: 30847
diff changeset
2 #include "debug.h"
30796
e545b2b6f66a Introduce SlpMessagePart, It will replace MsnMessage in every Slp related code so MsnMessage just get used where it makes sense, in the Switchboard.
masca@cpw.pidgin.im
parents:
diff changeset
3
e545b2b6f66a Introduce SlpMessagePart, It will replace MsnMessage in every Slp related code so MsnMessage just get used where it makes sense, in the Switchboard.
masca@cpw.pidgin.im
parents:
diff changeset
4 #include "slpmsg.h"
e545b2b6f66a Introduce SlpMessagePart, It will replace MsnMessage in every Slp related code so MsnMessage just get used where it makes sense, in the Switchboard.
masca@cpw.pidgin.im
parents:
diff changeset
5 #include "slpmsg_part.h"
e545b2b6f66a Introduce SlpMessagePart, It will replace MsnMessage in every Slp related code so MsnMessage just get used where it makes sense, in the Switchboard.
masca@cpw.pidgin.im
parents:
diff changeset
6
e545b2b6f66a Introduce SlpMessagePart, It will replace MsnMessage in every Slp related code so MsnMessage just get used where it makes sense, in the Switchboard.
masca@cpw.pidgin.im
parents:
diff changeset
7 MsnSlpMessagePart *msn_slpmsgpart_new(MsnP2PHeader *header, MsnP2PFooter *footer)
e545b2b6f66a Introduce SlpMessagePart, It will replace MsnMessage in every Slp related code so MsnMessage just get used where it makes sense, in the Switchboard.
masca@cpw.pidgin.im
parents:
diff changeset
8 {
e545b2b6f66a Introduce SlpMessagePart, It will replace MsnMessage in every Slp related code so MsnMessage just get used where it makes sense, in the Switchboard.
masca@cpw.pidgin.im
parents:
diff changeset
9 MsnSlpMessagePart *part;
e545b2b6f66a Introduce SlpMessagePart, It will replace MsnMessage in every Slp related code so MsnMessage just get used where it makes sense, in the Switchboard.
masca@cpw.pidgin.im
parents:
diff changeset
10
e545b2b6f66a Introduce SlpMessagePart, It will replace MsnMessage in every Slp related code so MsnMessage just get used where it makes sense, in the Switchboard.
masca@cpw.pidgin.im
parents:
diff changeset
11 part = g_new0(MsnSlpMessagePart, 1);
e545b2b6f66a Introduce SlpMessagePart, It will replace MsnMessage in every Slp related code so MsnMessage just get used where it makes sense, in the Switchboard.
masca@cpw.pidgin.im
parents:
diff changeset
12
e545b2b6f66a Introduce SlpMessagePart, It will replace MsnMessage in every Slp related code so MsnMessage just get used where it makes sense, in the Switchboard.
masca@cpw.pidgin.im
parents:
diff changeset
13 if (header)
e545b2b6f66a Introduce SlpMessagePart, It will replace MsnMessage in every Slp related code so MsnMessage just get used where it makes sense, in the Switchboard.
masca@cpw.pidgin.im
parents:
diff changeset
14 part->header = g_memdup(header, P2P_PACKET_HEADER_SIZE);
e545b2b6f66a Introduce SlpMessagePart, It will replace MsnMessage in every Slp related code so MsnMessage just get used where it makes sense, in the Switchboard.
masca@cpw.pidgin.im
parents:
diff changeset
15 if (footer)
e545b2b6f66a Introduce SlpMessagePart, It will replace MsnMessage in every Slp related code so MsnMessage just get used where it makes sense, in the Switchboard.
masca@cpw.pidgin.im
parents:
diff changeset
16 part->footer = g_memdup(footer, P2P_PACKET_FOOTER_SIZE);
e545b2b6f66a Introduce SlpMessagePart, It will replace MsnMessage in every Slp related code so MsnMessage just get used where it makes sense, in the Switchboard.
masca@cpw.pidgin.im
parents:
diff changeset
17
e545b2b6f66a Introduce SlpMessagePart, It will replace MsnMessage in every Slp related code so MsnMessage just get used where it makes sense, in the Switchboard.
masca@cpw.pidgin.im
parents:
diff changeset
18 part->ack_cb = msn_slpmsgpart_ack;
30822
e0dd17804079 Fix typo.
masca@cpw.pidgin.im
parents: 30796
diff changeset
19 part->nak_cb = msn_slpmsgpart_nak;
30796
e545b2b6f66a Introduce SlpMessagePart, It will replace MsnMessage in every Slp related code so MsnMessage just get used where it makes sense, in the Switchboard.
masca@cpw.pidgin.im
parents:
diff changeset
20
30847
74c4aa38adfc Add support to ref/unref SlpMessageParts.
masca@cpw.pidgin.im
parents: 30843
diff changeset
21 return msn_slpmsgpart_ref(part);
30796
e545b2b6f66a Introduce SlpMessagePart, It will replace MsnMessage in every Slp related code so MsnMessage just get used where it makes sense, in the Switchboard.
masca@cpw.pidgin.im
parents:
diff changeset
22 }
e545b2b6f66a Introduce SlpMessagePart, It will replace MsnMessage in every Slp related code so MsnMessage just get used where it makes sense, in the Switchboard.
masca@cpw.pidgin.im
parents:
diff changeset
23
e545b2b6f66a Introduce SlpMessagePart, It will replace MsnMessage in every Slp related code so MsnMessage just get used where it makes sense, in the Switchboard.
masca@cpw.pidgin.im
parents:
diff changeset
24 MsnSlpMessagePart *msn_slpmsgpart_new_from_data(const char *data, size_t data_len)
e545b2b6f66a Introduce SlpMessagePart, It will replace MsnMessage in every Slp related code so MsnMessage just get used where it makes sense, in the Switchboard.
masca@cpw.pidgin.im
parents:
diff changeset
25 {
e545b2b6f66a Introduce SlpMessagePart, It will replace MsnMessage in every Slp related code so MsnMessage just get used where it makes sense, in the Switchboard.
masca@cpw.pidgin.im
parents:
diff changeset
26 MsnSlpMessagePart *part;
e545b2b6f66a Introduce SlpMessagePart, It will replace MsnMessage in every Slp related code so MsnMessage just get used where it makes sense, in the Switchboard.
masca@cpw.pidgin.im
parents:
diff changeset
27 MsnP2PHeader *header;
e545b2b6f66a Introduce SlpMessagePart, It will replace MsnMessage in every Slp related code so MsnMessage just get used where it makes sense, in the Switchboard.
masca@cpw.pidgin.im
parents:
diff changeset
28 const char *tmp;
e545b2b6f66a Introduce SlpMessagePart, It will replace MsnMessage in every Slp related code so MsnMessage just get used where it makes sense, in the Switchboard.
masca@cpw.pidgin.im
parents:
diff changeset
29 int body_len;
e545b2b6f66a Introduce SlpMessagePart, It will replace MsnMessage in every Slp related code so MsnMessage just get used where it makes sense, in the Switchboard.
masca@cpw.pidgin.im
parents:
diff changeset
30
e545b2b6f66a Introduce SlpMessagePart, It will replace MsnMessage in every Slp related code so MsnMessage just get used where it makes sense, in the Switchboard.
masca@cpw.pidgin.im
parents:
diff changeset
31 tmp = data;
e545b2b6f66a Introduce SlpMessagePart, It will replace MsnMessage in every Slp related code so MsnMessage just get used where it makes sense, in the Switchboard.
masca@cpw.pidgin.im
parents:
diff changeset
32 part = msn_slpmsgpart_new(NULL, NULL);
e545b2b6f66a Introduce SlpMessagePart, It will replace MsnMessage in every Slp related code so MsnMessage just get used where it makes sense, in the Switchboard.
masca@cpw.pidgin.im
parents:
diff changeset
33
e545b2b6f66a Introduce SlpMessagePart, It will replace MsnMessage in every Slp related code so MsnMessage just get used where it makes sense, in the Switchboard.
masca@cpw.pidgin.im
parents:
diff changeset
34 if (data_len < sizeof(*header)) {
e545b2b6f66a Introduce SlpMessagePart, It will replace MsnMessage in every Slp related code so MsnMessage just get used where it makes sense, in the Switchboard.
masca@cpw.pidgin.im
parents:
diff changeset
35 return NULL;
e545b2b6f66a Introduce SlpMessagePart, It will replace MsnMessage in every Slp related code so MsnMessage just get used where it makes sense, in the Switchboard.
masca@cpw.pidgin.im
parents:
diff changeset
36 }
e545b2b6f66a Introduce SlpMessagePart, It will replace MsnMessage in every Slp related code so MsnMessage just get used where it makes sense, in the Switchboard.
masca@cpw.pidgin.im
parents:
diff changeset
37
e545b2b6f66a Introduce SlpMessagePart, It will replace MsnMessage in every Slp related code so MsnMessage just get used where it makes sense, in the Switchboard.
masca@cpw.pidgin.im
parents:
diff changeset
38 /* Extract the binary SLP header */
e545b2b6f66a Introduce SlpMessagePart, It will replace MsnMessage in every Slp related code so MsnMessage just get used where it makes sense, in the Switchboard.
masca@cpw.pidgin.im
parents:
diff changeset
39 part->header = msn_p2p_header_from_wire((MsnP2PHeader*)tmp);
30840
df3e9c686b02 Update tmp pointer after reading the header.
masca@cpw.pidgin.im
parents: 30824
diff changeset
40 tmp += P2P_PACKET_HEADER_SIZE;
30796
e545b2b6f66a Introduce SlpMessagePart, It will replace MsnMessage in every Slp related code so MsnMessage just get used where it makes sense, in the Switchboard.
masca@cpw.pidgin.im
parents:
diff changeset
41
e545b2b6f66a Introduce SlpMessagePart, It will replace MsnMessage in every Slp related code so MsnMessage just get used where it makes sense, in the Switchboard.
masca@cpw.pidgin.im
parents:
diff changeset
42 /* Extract the body */
30843
98cd0ea847ec Properly set the body_len of the SlpMessagePart, this set correctly the footer value.
masca@cpw.pidgin.im
parents: 30840
diff changeset
43 body_len = data_len - P2P_PACKET_HEADER_SIZE - P2P_PACKET_FOOTER_SIZE;
30796
e545b2b6f66a Introduce SlpMessagePart, It will replace MsnMessage in every Slp related code so MsnMessage just get used where it makes sense, in the Switchboard.
masca@cpw.pidgin.im
parents:
diff changeset
44 /* msg->body_len = msg->msnslp_header.length; */
e545b2b6f66a Introduce SlpMessagePart, It will replace MsnMessage in every Slp related code so MsnMessage just get used where it makes sense, in the Switchboard.
masca@cpw.pidgin.im
parents:
diff changeset
45
e545b2b6f66a Introduce SlpMessagePart, It will replace MsnMessage in every Slp related code so MsnMessage just get used where it makes sense, in the Switchboard.
masca@cpw.pidgin.im
parents:
diff changeset
46 if (body_len > 0) {
e545b2b6f66a Introduce SlpMessagePart, It will replace MsnMessage in every Slp related code so MsnMessage just get used where it makes sense, in the Switchboard.
masca@cpw.pidgin.im
parents:
diff changeset
47 part->size = body_len;
e545b2b6f66a Introduce SlpMessagePart, It will replace MsnMessage in every Slp related code so MsnMessage just get used where it makes sense, in the Switchboard.
masca@cpw.pidgin.im
parents:
diff changeset
48 part->buffer = g_malloc(body_len);
e545b2b6f66a Introduce SlpMessagePart, It will replace MsnMessage in every Slp related code so MsnMessage just get used where it makes sense, in the Switchboard.
masca@cpw.pidgin.im
parents:
diff changeset
49 memcpy(part->buffer, tmp, body_len);
e545b2b6f66a Introduce SlpMessagePart, It will replace MsnMessage in every Slp related code so MsnMessage just get used where it makes sense, in the Switchboard.
masca@cpw.pidgin.im
parents:
diff changeset
50 tmp += body_len;
e545b2b6f66a Introduce SlpMessagePart, It will replace MsnMessage in every Slp related code so MsnMessage just get used where it makes sense, in the Switchboard.
masca@cpw.pidgin.im
parents:
diff changeset
51 }
e545b2b6f66a Introduce SlpMessagePart, It will replace MsnMessage in every Slp related code so MsnMessage just get used where it makes sense, in the Switchboard.
masca@cpw.pidgin.im
parents:
diff changeset
52
e545b2b6f66a Introduce SlpMessagePart, It will replace MsnMessage in every Slp related code so MsnMessage just get used where it makes sense, in the Switchboard.
masca@cpw.pidgin.im
parents:
diff changeset
53 /* Extract the footer */
e545b2b6f66a Introduce SlpMessagePart, It will replace MsnMessage in every Slp related code so MsnMessage just get used where it makes sense, in the Switchboard.
masca@cpw.pidgin.im
parents:
diff changeset
54 if (body_len >= 0)
e545b2b6f66a Introduce SlpMessagePart, It will replace MsnMessage in every Slp related code so MsnMessage just get used where it makes sense, in the Switchboard.
masca@cpw.pidgin.im
parents:
diff changeset
55 part->footer = msn_p2p_footer_from_wire((MsnP2PFooter*)tmp);
e545b2b6f66a Introduce SlpMessagePart, It will replace MsnMessage in every Slp related code so MsnMessage just get used where it makes sense, in the Switchboard.
masca@cpw.pidgin.im
parents:
diff changeset
56
e545b2b6f66a Introduce SlpMessagePart, It will replace MsnMessage in every Slp related code so MsnMessage just get used where it makes sense, in the Switchboard.
masca@cpw.pidgin.im
parents:
diff changeset
57 return part;
e545b2b6f66a Introduce SlpMessagePart, It will replace MsnMessage in every Slp related code so MsnMessage just get used where it makes sense, in the Switchboard.
masca@cpw.pidgin.im
parents:
diff changeset
58 }
e545b2b6f66a Introduce SlpMessagePart, It will replace MsnMessage in every Slp related code so MsnMessage just get used where it makes sense, in the Switchboard.
masca@cpw.pidgin.im
parents:
diff changeset
59
e545b2b6f66a Introduce SlpMessagePart, It will replace MsnMessage in every Slp related code so MsnMessage just get used where it makes sense, in the Switchboard.
masca@cpw.pidgin.im
parents:
diff changeset
60 void msn_slpmsgpart_destroy(MsnSlpMessagePart *part)
e545b2b6f66a Introduce SlpMessagePart, It will replace MsnMessage in every Slp related code so MsnMessage just get used where it makes sense, in the Switchboard.
masca@cpw.pidgin.im
parents:
diff changeset
61 {
30824
a743c25b27a8 Destroying Parts return silently when it's passed a NULL pointer.
masca@cpw.pidgin.im
parents: 30822
diff changeset
62 if (!part)
a743c25b27a8 Destroying Parts return silently when it's passed a NULL pointer.
masca@cpw.pidgin.im
parents: 30822
diff changeset
63 return;
a743c25b27a8 Destroying Parts return silently when it's passed a NULL pointer.
masca@cpw.pidgin.im
parents: 30822
diff changeset
64
30847
74c4aa38adfc Add support to ref/unref SlpMessageParts.
masca@cpw.pidgin.im
parents: 30843
diff changeset
65 if (part->ref_count > 0) {
74c4aa38adfc Add support to ref/unref SlpMessageParts.
masca@cpw.pidgin.im
parents: 30843
diff changeset
66 msn_slpmsgpart_unref(part);
74c4aa38adfc Add support to ref/unref SlpMessageParts.
masca@cpw.pidgin.im
parents: 30843
diff changeset
67
74c4aa38adfc Add support to ref/unref SlpMessageParts.
masca@cpw.pidgin.im
parents: 30843
diff changeset
68 return;
74c4aa38adfc Add support to ref/unref SlpMessageParts.
masca@cpw.pidgin.im
parents: 30843
diff changeset
69 }
74c4aa38adfc Add support to ref/unref SlpMessageParts.
masca@cpw.pidgin.im
parents: 30843
diff changeset
70
30796
e545b2b6f66a Introduce SlpMessagePart, It will replace MsnMessage in every Slp related code so MsnMessage just get used where it makes sense, in the Switchboard.
masca@cpw.pidgin.im
parents:
diff changeset
71 g_free(part->header);
e545b2b6f66a Introduce SlpMessagePart, It will replace MsnMessage in every Slp related code so MsnMessage just get used where it makes sense, in the Switchboard.
masca@cpw.pidgin.im
parents:
diff changeset
72 g_free(part->footer);
e545b2b6f66a Introduce SlpMessagePart, It will replace MsnMessage in every Slp related code so MsnMessage just get used where it makes sense, in the Switchboard.
masca@cpw.pidgin.im
parents:
diff changeset
73
e545b2b6f66a Introduce SlpMessagePart, It will replace MsnMessage in every Slp related code so MsnMessage just get used where it makes sense, in the Switchboard.
masca@cpw.pidgin.im
parents:
diff changeset
74 g_free(part);
e545b2b6f66a Introduce SlpMessagePart, It will replace MsnMessage in every Slp related code so MsnMessage just get used where it makes sense, in the Switchboard.
masca@cpw.pidgin.im
parents:
diff changeset
75
e545b2b6f66a Introduce SlpMessagePart, It will replace MsnMessage in every Slp related code so MsnMessage just get used where it makes sense, in the Switchboard.
masca@cpw.pidgin.im
parents:
diff changeset
76 }
e545b2b6f66a Introduce SlpMessagePart, It will replace MsnMessage in every Slp related code so MsnMessage just get used where it makes sense, in the Switchboard.
masca@cpw.pidgin.im
parents:
diff changeset
77
30847
74c4aa38adfc Add support to ref/unref SlpMessageParts.
masca@cpw.pidgin.im
parents: 30843
diff changeset
78 MsnSlpMessagePart *msn_slpmsgpart_ref(MsnSlpMessagePart *part)
74c4aa38adfc Add support to ref/unref SlpMessageParts.
masca@cpw.pidgin.im
parents: 30843
diff changeset
79 {
74c4aa38adfc Add support to ref/unref SlpMessageParts.
masca@cpw.pidgin.im
parents: 30843
diff changeset
80 g_return_val_if_fail(part != NULL, NULL);
74c4aa38adfc Add support to ref/unref SlpMessageParts.
masca@cpw.pidgin.im
parents: 30843
diff changeset
81 part->ref_count ++;
74c4aa38adfc Add support to ref/unref SlpMessageParts.
masca@cpw.pidgin.im
parents: 30843
diff changeset
82
30849
e358e16e527f Add a ref to the part at sbconn and add some debug output.
masca@cpw.pidgin.im
parents: 30847
diff changeset
83 if (purple_debug_is_verbose())
30873
4b1eecab50e8 ref_count is an int
Mark Doliner <mark@kingant.net>
parents: 30870
diff changeset
84 purple_debug_info("msn", "part ref (%p)[%d]\n", part, part->ref_count);
30849
e358e16e527f Add a ref to the part at sbconn and add some debug output.
masca@cpw.pidgin.im
parents: 30847
diff changeset
85
30847
74c4aa38adfc Add support to ref/unref SlpMessageParts.
masca@cpw.pidgin.im
parents: 30843
diff changeset
86 return part;
74c4aa38adfc Add support to ref/unref SlpMessageParts.
masca@cpw.pidgin.im
parents: 30843
diff changeset
87 }
74c4aa38adfc Add support to ref/unref SlpMessageParts.
masca@cpw.pidgin.im
parents: 30843
diff changeset
88
74c4aa38adfc Add support to ref/unref SlpMessageParts.
masca@cpw.pidgin.im
parents: 30843
diff changeset
89 MsnSlpMessagePart *msn_slpmsgpart_unref(MsnSlpMessagePart *part)
74c4aa38adfc Add support to ref/unref SlpMessageParts.
masca@cpw.pidgin.im
parents: 30843
diff changeset
90 {
74c4aa38adfc Add support to ref/unref SlpMessageParts.
masca@cpw.pidgin.im
parents: 30843
diff changeset
91 g_return_val_if_fail(part != NULL, NULL);
74c4aa38adfc Add support to ref/unref SlpMessageParts.
masca@cpw.pidgin.im
parents: 30843
diff changeset
92 g_return_val_if_fail(part->ref_count > 0, NULL);
74c4aa38adfc Add support to ref/unref SlpMessageParts.
masca@cpw.pidgin.im
parents: 30843
diff changeset
93
74c4aa38adfc Add support to ref/unref SlpMessageParts.
masca@cpw.pidgin.im
parents: 30843
diff changeset
94 part->ref_count--;
74c4aa38adfc Add support to ref/unref SlpMessageParts.
masca@cpw.pidgin.im
parents: 30843
diff changeset
95
30849
e358e16e527f Add a ref to the part at sbconn and add some debug output.
masca@cpw.pidgin.im
parents: 30847
diff changeset
96 if (purple_debug_is_verbose())
30873
4b1eecab50e8 ref_count is an int
Mark Doliner <mark@kingant.net>
parents: 30870
diff changeset
97 purple_debug_info("msn", "part unref (%p)[%d]\n", part, part->ref_count);
30849
e358e16e527f Add a ref to the part at sbconn and add some debug output.
masca@cpw.pidgin.im
parents: 30847
diff changeset
98
30847
74c4aa38adfc Add support to ref/unref SlpMessageParts.
masca@cpw.pidgin.im
parents: 30843
diff changeset
99 if (part->ref_count == 0) {
74c4aa38adfc Add support to ref/unref SlpMessageParts.
masca@cpw.pidgin.im
parents: 30843
diff changeset
100 msn_slpmsgpart_destroy(part);
74c4aa38adfc Add support to ref/unref SlpMessageParts.
masca@cpw.pidgin.im
parents: 30843
diff changeset
101
74c4aa38adfc Add support to ref/unref SlpMessageParts.
masca@cpw.pidgin.im
parents: 30843
diff changeset
102 return NULL;
74c4aa38adfc Add support to ref/unref SlpMessageParts.
masca@cpw.pidgin.im
parents: 30843
diff changeset
103 }
74c4aa38adfc Add support to ref/unref SlpMessageParts.
masca@cpw.pidgin.im
parents: 30843
diff changeset
104
74c4aa38adfc Add support to ref/unref SlpMessageParts.
masca@cpw.pidgin.im
parents: 30843
diff changeset
105 return part;
74c4aa38adfc Add support to ref/unref SlpMessageParts.
masca@cpw.pidgin.im
parents: 30843
diff changeset
106 }
74c4aa38adfc Add support to ref/unref SlpMessageParts.
masca@cpw.pidgin.im
parents: 30843
diff changeset
107
30796
e545b2b6f66a Introduce SlpMessagePart, It will replace MsnMessage in every Slp related code so MsnMessage just get used where it makes sense, in the Switchboard.
masca@cpw.pidgin.im
parents:
diff changeset
108 void msn_slpmsgpart_set_bin_data(MsnSlpMessagePart *part, const void *data, size_t len)
e545b2b6f66a Introduce SlpMessagePart, It will replace MsnMessage in every Slp related code so MsnMessage just get used where it makes sense, in the Switchboard.
masca@cpw.pidgin.im
parents:
diff changeset
109 {
e545b2b6f66a Introduce SlpMessagePart, It will replace MsnMessage in every Slp related code so MsnMessage just get used where it makes sense, in the Switchboard.
masca@cpw.pidgin.im
parents:
diff changeset
110 g_return_if_fail(part != NULL);
e545b2b6f66a Introduce SlpMessagePart, It will replace MsnMessage in every Slp related code so MsnMessage just get used where it makes sense, in the Switchboard.
masca@cpw.pidgin.im
parents:
diff changeset
111
30935
2de522fa534a Fix a lot more leaks, some old, some new.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 30934
diff changeset
112 g_free(part->buffer);
30796
e545b2b6f66a Introduce SlpMessagePart, It will replace MsnMessage in every Slp related code so MsnMessage just get used where it makes sense, in the Switchboard.
masca@cpw.pidgin.im
parents:
diff changeset
113
e545b2b6f66a Introduce SlpMessagePart, It will replace MsnMessage in every Slp related code so MsnMessage just get used where it makes sense, in the Switchboard.
masca@cpw.pidgin.im
parents:
diff changeset
114 if (data != NULL && len > 0) {
e545b2b6f66a Introduce SlpMessagePart, It will replace MsnMessage in every Slp related code so MsnMessage just get used where it makes sense, in the Switchboard.
masca@cpw.pidgin.im
parents:
diff changeset
115 part->buffer = g_malloc(len + 1);
e545b2b6f66a Introduce SlpMessagePart, It will replace MsnMessage in every Slp related code so MsnMessage just get used where it makes sense, in the Switchboard.
masca@cpw.pidgin.im
parents:
diff changeset
116 memcpy(part->buffer, data, len);
e545b2b6f66a Introduce SlpMessagePart, It will replace MsnMessage in every Slp related code so MsnMessage just get used where it makes sense, in the Switchboard.
masca@cpw.pidgin.im
parents:
diff changeset
117 part->buffer[len] = '\0';
e545b2b6f66a Introduce SlpMessagePart, It will replace MsnMessage in every Slp related code so MsnMessage just get used where it makes sense, in the Switchboard.
masca@cpw.pidgin.im
parents:
diff changeset
118 part->size = len;
e545b2b6f66a Introduce SlpMessagePart, It will replace MsnMessage in every Slp related code so MsnMessage just get used where it makes sense, in the Switchboard.
masca@cpw.pidgin.im
parents:
diff changeset
119 } else {
e545b2b6f66a Introduce SlpMessagePart, It will replace MsnMessage in every Slp related code so MsnMessage just get used where it makes sense, in the Switchboard.
masca@cpw.pidgin.im
parents:
diff changeset
120 part->buffer = NULL;
e545b2b6f66a Introduce SlpMessagePart, It will replace MsnMessage in every Slp related code so MsnMessage just get used where it makes sense, in the Switchboard.
masca@cpw.pidgin.im
parents:
diff changeset
121 part->size = 0;
e545b2b6f66a Introduce SlpMessagePart, It will replace MsnMessage in every Slp related code so MsnMessage just get used where it makes sense, in the Switchboard.
masca@cpw.pidgin.im
parents:
diff changeset
122 }
e545b2b6f66a Introduce SlpMessagePart, It will replace MsnMessage in every Slp related code so MsnMessage just get used where it makes sense, in the Switchboard.
masca@cpw.pidgin.im
parents:
diff changeset
123
e545b2b6f66a Introduce SlpMessagePart, It will replace MsnMessage in every Slp related code so MsnMessage just get used where it makes sense, in the Switchboard.
masca@cpw.pidgin.im
parents:
diff changeset
124 }
e545b2b6f66a Introduce SlpMessagePart, It will replace MsnMessage in every Slp related code so MsnMessage just get used where it makes sense, in the Switchboard.
masca@cpw.pidgin.im
parents:
diff changeset
125
e545b2b6f66a Introduce SlpMessagePart, It will replace MsnMessage in every Slp related code so MsnMessage just get used where it makes sense, in the Switchboard.
masca@cpw.pidgin.im
parents:
diff changeset
126 char *msn_slpmsgpart_serialize(MsnSlpMessagePart *part, size_t *ret_size)
e545b2b6f66a Introduce SlpMessagePart, It will replace MsnMessage in every Slp related code so MsnMessage just get used where it makes sense, in the Switchboard.
masca@cpw.pidgin.im
parents:
diff changeset
127 {
e545b2b6f66a Introduce SlpMessagePart, It will replace MsnMessage in every Slp related code so MsnMessage just get used where it makes sense, in the Switchboard.
masca@cpw.pidgin.im
parents:
diff changeset
128 MsnP2PHeader *header;
e545b2b6f66a Introduce SlpMessagePart, It will replace MsnMessage in every Slp related code so MsnMessage just get used where it makes sense, in the Switchboard.
masca@cpw.pidgin.im
parents:
diff changeset
129 MsnP2PFooter *footer;
e545b2b6f66a Introduce SlpMessagePart, It will replace MsnMessage in every Slp related code so MsnMessage just get used where it makes sense, in the Switchboard.
masca@cpw.pidgin.im
parents:
diff changeset
130 char *base;
e545b2b6f66a Introduce SlpMessagePart, It will replace MsnMessage in every Slp related code so MsnMessage just get used where it makes sense, in the Switchboard.
masca@cpw.pidgin.im
parents:
diff changeset
131 char *tmp;
e545b2b6f66a Introduce SlpMessagePart, It will replace MsnMessage in every Slp related code so MsnMessage just get used where it makes sense, in the Switchboard.
masca@cpw.pidgin.im
parents:
diff changeset
132 size_t siz;
e545b2b6f66a Introduce SlpMessagePart, It will replace MsnMessage in every Slp related code so MsnMessage just get used where it makes sense, in the Switchboard.
masca@cpw.pidgin.im
parents:
diff changeset
133
e545b2b6f66a Introduce SlpMessagePart, It will replace MsnMessage in every Slp related code so MsnMessage just get used where it makes sense, in the Switchboard.
masca@cpw.pidgin.im
parents:
diff changeset
134 base = g_malloc(P2P_PACKET_HEADER_SIZE + part->size + sizeof(MsnP2PFooter));
e545b2b6f66a Introduce SlpMessagePart, It will replace MsnMessage in every Slp related code so MsnMessage just get used where it makes sense, in the Switchboard.
masca@cpw.pidgin.im
parents:
diff changeset
135 tmp = base;
e545b2b6f66a Introduce SlpMessagePart, It will replace MsnMessage in every Slp related code so MsnMessage just get used where it makes sense, in the Switchboard.
masca@cpw.pidgin.im
parents:
diff changeset
136
e545b2b6f66a Introduce SlpMessagePart, It will replace MsnMessage in every Slp related code so MsnMessage just get used where it makes sense, in the Switchboard.
masca@cpw.pidgin.im
parents:
diff changeset
137 header = msn_p2p_header_to_wire(part->header);
e545b2b6f66a Introduce SlpMessagePart, It will replace MsnMessage in every Slp related code so MsnMessage just get used where it makes sense, in the Switchboard.
masca@cpw.pidgin.im
parents:
diff changeset
138 footer = msn_p2p_footer_to_wire(part->footer);
e545b2b6f66a Introduce SlpMessagePart, It will replace MsnMessage in every Slp related code so MsnMessage just get used where it makes sense, in the Switchboard.
masca@cpw.pidgin.im
parents:
diff changeset
139
e545b2b6f66a Introduce SlpMessagePart, It will replace MsnMessage in every Slp related code so MsnMessage just get used where it makes sense, in the Switchboard.
masca@cpw.pidgin.im
parents:
diff changeset
140 siz = sizeof(MsnP2PHeader);
e545b2b6f66a Introduce SlpMessagePart, It will replace MsnMessage in every Slp related code so MsnMessage just get used where it makes sense, in the Switchboard.
masca@cpw.pidgin.im
parents:
diff changeset
141 /* Copy header */
e545b2b6f66a Introduce SlpMessagePart, It will replace MsnMessage in every Slp related code so MsnMessage just get used where it makes sense, in the Switchboard.
masca@cpw.pidgin.im
parents:
diff changeset
142 memcpy(tmp, (char*)header, siz);
e545b2b6f66a Introduce SlpMessagePart, It will replace MsnMessage in every Slp related code so MsnMessage just get used where it makes sense, in the Switchboard.
masca@cpw.pidgin.im
parents:
diff changeset
143 tmp += siz;
e545b2b6f66a Introduce SlpMessagePart, It will replace MsnMessage in every Slp related code so MsnMessage just get used where it makes sense, in the Switchboard.
masca@cpw.pidgin.im
parents:
diff changeset
144
e545b2b6f66a Introduce SlpMessagePart, It will replace MsnMessage in every Slp related code so MsnMessage just get used where it makes sense, in the Switchboard.
masca@cpw.pidgin.im
parents:
diff changeset
145 /* Copy body */
e545b2b6f66a Introduce SlpMessagePart, It will replace MsnMessage in every Slp related code so MsnMessage just get used where it makes sense, in the Switchboard.
masca@cpw.pidgin.im
parents:
diff changeset
146 memcpy(tmp, part->buffer, part->size);
e545b2b6f66a Introduce SlpMessagePart, It will replace MsnMessage in every Slp related code so MsnMessage just get used where it makes sense, in the Switchboard.
masca@cpw.pidgin.im
parents:
diff changeset
147 tmp += part->size;
e545b2b6f66a Introduce SlpMessagePart, It will replace MsnMessage in every Slp related code so MsnMessage just get used where it makes sense, in the Switchboard.
masca@cpw.pidgin.im
parents:
diff changeset
148
e545b2b6f66a Introduce SlpMessagePart, It will replace MsnMessage in every Slp related code so MsnMessage just get used where it makes sense, in the Switchboard.
masca@cpw.pidgin.im
parents:
diff changeset
149 /* Copy footer */
e545b2b6f66a Introduce SlpMessagePart, It will replace MsnMessage in every Slp related code so MsnMessage just get used where it makes sense, in the Switchboard.
masca@cpw.pidgin.im
parents:
diff changeset
150 siz = sizeof(MsnP2PFooter);
e545b2b6f66a Introduce SlpMessagePart, It will replace MsnMessage in every Slp related code so MsnMessage just get used where it makes sense, in the Switchboard.
masca@cpw.pidgin.im
parents:
diff changeset
151 memcpy(tmp, (char*)footer, siz);
e545b2b6f66a Introduce SlpMessagePart, It will replace MsnMessage in every Slp related code so MsnMessage just get used where it makes sense, in the Switchboard.
masca@cpw.pidgin.im
parents:
diff changeset
152 tmp += siz;
e545b2b6f66a Introduce SlpMessagePart, It will replace MsnMessage in every Slp related code so MsnMessage just get used where it makes sense, in the Switchboard.
masca@cpw.pidgin.im
parents:
diff changeset
153
e545b2b6f66a Introduce SlpMessagePart, It will replace MsnMessage in every Slp related code so MsnMessage just get used where it makes sense, in the Switchboard.
masca@cpw.pidgin.im
parents:
diff changeset
154 *ret_size = tmp - base;
e545b2b6f66a Introduce SlpMessagePart, It will replace MsnMessage in every Slp related code so MsnMessage just get used where it makes sense, in the Switchboard.
masca@cpw.pidgin.im
parents:
diff changeset
155
30934
4e097dfb7784 Fix some leaks. Header and footer are allocated, copied and not freed.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 30873
diff changeset
156 g_free(header);
4e097dfb7784 Fix some leaks. Header and footer are allocated, copied and not freed.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 30873
diff changeset
157 g_free(footer);
4e097dfb7784 Fix some leaks. Header and footer are allocated, copied and not freed.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 30873
diff changeset
158
30796
e545b2b6f66a Introduce SlpMessagePart, It will replace MsnMessage in every Slp related code so MsnMessage just get used where it makes sense, in the Switchboard.
masca@cpw.pidgin.im
parents:
diff changeset
159 return base;
e545b2b6f66a Introduce SlpMessagePart, It will replace MsnMessage in every Slp related code so MsnMessage just get used where it makes sense, in the Switchboard.
masca@cpw.pidgin.im
parents:
diff changeset
160 }
e545b2b6f66a Introduce SlpMessagePart, It will replace MsnMessage in every Slp related code so MsnMessage just get used where it makes sense, in the Switchboard.
masca@cpw.pidgin.im
parents:
diff changeset
161 /* We have received the message ack */
e545b2b6f66a Introduce SlpMessagePart, It will replace MsnMessage in every Slp related code so MsnMessage just get used where it makes sense, in the Switchboard.
masca@cpw.pidgin.im
parents:
diff changeset
162 void
e545b2b6f66a Introduce SlpMessagePart, It will replace MsnMessage in every Slp related code so MsnMessage just get used where it makes sense, in the Switchboard.
masca@cpw.pidgin.im
parents:
diff changeset
163 msn_slpmsgpart_ack(MsnSlpMessagePart *part, void *data)
e545b2b6f66a Introduce SlpMessagePart, It will replace MsnMessage in every Slp related code so MsnMessage just get used where it makes sense, in the Switchboard.
masca@cpw.pidgin.im
parents:
diff changeset
164 {
e545b2b6f66a Introduce SlpMessagePart, It will replace MsnMessage in every Slp related code so MsnMessage just get used where it makes sense, in the Switchboard.
masca@cpw.pidgin.im
parents:
diff changeset
165 MsnSlpMessage *slpmsg;
e545b2b6f66a Introduce SlpMessagePart, It will replace MsnMessage in every Slp related code so MsnMessage just get used where it makes sense, in the Switchboard.
masca@cpw.pidgin.im
parents:
diff changeset
166 long long real_size;
e545b2b6f66a Introduce SlpMessagePart, It will replace MsnMessage in every Slp related code so MsnMessage just get used where it makes sense, in the Switchboard.
masca@cpw.pidgin.im
parents:
diff changeset
167
e545b2b6f66a Introduce SlpMessagePart, It will replace MsnMessage in every Slp related code so MsnMessage just get used where it makes sense, in the Switchboard.
masca@cpw.pidgin.im
parents:
diff changeset
168 slpmsg = data;
e545b2b6f66a Introduce SlpMessagePart, It will replace MsnMessage in every Slp related code so MsnMessage just get used where it makes sense, in the Switchboard.
masca@cpw.pidgin.im
parents:
diff changeset
169
30870
d9ca3798faa5 Get rid of the Flags field in the SlpMessage in favor of the one in the Header.
masca@cpw.pidgin.im
parents: 30869
diff changeset
170 real_size = (slpmsg->header->flags == P2P_ACK) ? 0 : slpmsg->size;
30796
e545b2b6f66a Introduce SlpMessagePart, It will replace MsnMessage in every Slp related code so MsnMessage just get used where it makes sense, in the Switchboard.
masca@cpw.pidgin.im
parents:
diff changeset
171
30862
5ad928319db0 Use the SlpMessage header offset only instead of it and the one on the SlpMessage when sending it. This fixes sending big data which needs to be split in multiple messages.
masca@cpw.pidgin.im
parents: 30849
diff changeset
172 slpmsg->header->offset += part->header->length;
30796
e545b2b6f66a Introduce SlpMessagePart, It will replace MsnMessage in every Slp related code so MsnMessage just get used where it makes sense, in the Switchboard.
masca@cpw.pidgin.im
parents:
diff changeset
173
e545b2b6f66a Introduce SlpMessagePart, It will replace MsnMessage in every Slp related code so MsnMessage just get used where it makes sense, in the Switchboard.
masca@cpw.pidgin.im
parents:
diff changeset
174 slpmsg->parts = g_list_remove(slpmsg->parts, part);
e545b2b6f66a Introduce SlpMessagePart, It will replace MsnMessage in every Slp related code so MsnMessage just get used where it makes sense, in the Switchboard.
masca@cpw.pidgin.im
parents:
diff changeset
175
30862
5ad928319db0 Use the SlpMessage header offset only instead of it and the one on the SlpMessage when sending it. This fixes sending big data which needs to be split in multiple messages.
masca@cpw.pidgin.im
parents: 30849
diff changeset
176 if (slpmsg->header->offset < real_size)
30796
e545b2b6f66a Introduce SlpMessagePart, It will replace MsnMessage in every Slp related code so MsnMessage just get used where it makes sense, in the Switchboard.
masca@cpw.pidgin.im
parents:
diff changeset
177 {
e545b2b6f66a Introduce SlpMessagePart, It will replace MsnMessage in every Slp related code so MsnMessage just get used where it makes sense, in the Switchboard.
masca@cpw.pidgin.im
parents:
diff changeset
178 if (slpmsg->slpcall->xfer && purple_xfer_get_status(slpmsg->slpcall->xfer) == PURPLE_XFER_STATUS_STARTED)
e545b2b6f66a Introduce SlpMessagePart, It will replace MsnMessage in every Slp related code so MsnMessage just get used where it makes sense, in the Switchboard.
masca@cpw.pidgin.im
parents:
diff changeset
179 {
e545b2b6f66a Introduce SlpMessagePart, It will replace MsnMessage in every Slp related code so MsnMessage just get used where it makes sense, in the Switchboard.
masca@cpw.pidgin.im
parents:
diff changeset
180 slpmsg->slpcall->xfer_msg = slpmsg;
e545b2b6f66a Introduce SlpMessagePart, It will replace MsnMessage in every Slp related code so MsnMessage just get used where it makes sense, in the Switchboard.
masca@cpw.pidgin.im
parents:
diff changeset
181 purple_xfer_prpl_ready(slpmsg->slpcall->xfer);
e545b2b6f66a Introduce SlpMessagePart, It will replace MsnMessage in every Slp related code so MsnMessage just get used where it makes sense, in the Switchboard.
masca@cpw.pidgin.im
parents:
diff changeset
182 }
e545b2b6f66a Introduce SlpMessagePart, It will replace MsnMessage in every Slp related code so MsnMessage just get used where it makes sense, in the Switchboard.
masca@cpw.pidgin.im
parents:
diff changeset
183 else
e545b2b6f66a Introduce SlpMessagePart, It will replace MsnMessage in every Slp related code so MsnMessage just get used where it makes sense, in the Switchboard.
masca@cpw.pidgin.im
parents:
diff changeset
184 msn_slplink_send_msgpart(slpmsg->slplink, slpmsg);
e545b2b6f66a Introduce SlpMessagePart, It will replace MsnMessage in every Slp related code so MsnMessage just get used where it makes sense, in the Switchboard.
masca@cpw.pidgin.im
parents:
diff changeset
185 }
e545b2b6f66a Introduce SlpMessagePart, It will replace MsnMessage in every Slp related code so MsnMessage just get used where it makes sense, in the Switchboard.
masca@cpw.pidgin.im
parents:
diff changeset
186 else
e545b2b6f66a Introduce SlpMessagePart, It will replace MsnMessage in every Slp related code so MsnMessage just get used where it makes sense, in the Switchboard.
masca@cpw.pidgin.im
parents:
diff changeset
187 {
e545b2b6f66a Introduce SlpMessagePart, It will replace MsnMessage in every Slp related code so MsnMessage just get used where it makes sense, in the Switchboard.
masca@cpw.pidgin.im
parents:
diff changeset
188 /* The whole message has been sent */
30870
d9ca3798faa5 Get rid of the Flags field in the SlpMessage in favor of the one in the Header.
masca@cpw.pidgin.im
parents: 30869
diff changeset
189 if (msn_p2p_msg_is_data(slpmsg->header->flags))
30796
e545b2b6f66a Introduce SlpMessagePart, It will replace MsnMessage in every Slp related code so MsnMessage just get used where it makes sense, in the Switchboard.
masca@cpw.pidgin.im
parents:
diff changeset
190 {
e545b2b6f66a Introduce SlpMessagePart, It will replace MsnMessage in every Slp related code so MsnMessage just get used where it makes sense, in the Switchboard.
masca@cpw.pidgin.im
parents:
diff changeset
191 if (slpmsg->slpcall != NULL)
e545b2b6f66a Introduce SlpMessagePart, It will replace MsnMessage in every Slp related code so MsnMessage just get used where it makes sense, in the Switchboard.
masca@cpw.pidgin.im
parents:
diff changeset
192 {
e545b2b6f66a Introduce SlpMessagePart, It will replace MsnMessage in every Slp related code so MsnMessage just get used where it makes sense, in the Switchboard.
masca@cpw.pidgin.im
parents:
diff changeset
193 if (slpmsg->slpcall->cb)
e545b2b6f66a Introduce SlpMessagePart, It will replace MsnMessage in every Slp related code so MsnMessage just get used where it makes sense, in the Switchboard.
masca@cpw.pidgin.im
parents:
diff changeset
194 slpmsg->slpcall->cb(slpmsg->slpcall,
e545b2b6f66a Introduce SlpMessagePart, It will replace MsnMessage in every Slp related code so MsnMessage just get used where it makes sense, in the Switchboard.
masca@cpw.pidgin.im
parents:
diff changeset
195 NULL, 0);
e545b2b6f66a Introduce SlpMessagePart, It will replace MsnMessage in every Slp related code so MsnMessage just get used where it makes sense, in the Switchboard.
masca@cpw.pidgin.im
parents:
diff changeset
196 }
e545b2b6f66a Introduce SlpMessagePart, It will replace MsnMessage in every Slp related code so MsnMessage just get used where it makes sense, in the Switchboard.
masca@cpw.pidgin.im
parents:
diff changeset
197 }
e545b2b6f66a Introduce SlpMessagePart, It will replace MsnMessage in every Slp related code so MsnMessage just get used where it makes sense, in the Switchboard.
masca@cpw.pidgin.im
parents:
diff changeset
198 }
e545b2b6f66a Introduce SlpMessagePart, It will replace MsnMessage in every Slp related code so MsnMessage just get used where it makes sense, in the Switchboard.
masca@cpw.pidgin.im
parents:
diff changeset
199 }
e545b2b6f66a Introduce SlpMessagePart, It will replace MsnMessage in every Slp related code so MsnMessage just get used where it makes sense, in the Switchboard.
masca@cpw.pidgin.im
parents:
diff changeset
200
e545b2b6f66a Introduce SlpMessagePart, It will replace MsnMessage in every Slp related code so MsnMessage just get used where it makes sense, in the Switchboard.
masca@cpw.pidgin.im
parents:
diff changeset
201 /* We have received the message nak. */
e545b2b6f66a Introduce SlpMessagePart, It will replace MsnMessage in every Slp related code so MsnMessage just get used where it makes sense, in the Switchboard.
masca@cpw.pidgin.im
parents:
diff changeset
202 void
e545b2b6f66a Introduce SlpMessagePart, It will replace MsnMessage in every Slp related code so MsnMessage just get used where it makes sense, in the Switchboard.
masca@cpw.pidgin.im
parents:
diff changeset
203 msn_slpmsgpart_nak(MsnSlpMessagePart *part, void *data)
e545b2b6f66a Introduce SlpMessagePart, It will replace MsnMessage in every Slp related code so MsnMessage just get used where it makes sense, in the Switchboard.
masca@cpw.pidgin.im
parents:
diff changeset
204 {
e545b2b6f66a Introduce SlpMessagePart, It will replace MsnMessage in every Slp related code so MsnMessage just get used where it makes sense, in the Switchboard.
masca@cpw.pidgin.im
parents:
diff changeset
205 MsnSlpMessage *slpmsg;
e545b2b6f66a Introduce SlpMessagePart, It will replace MsnMessage in every Slp related code so MsnMessage just get used where it makes sense, in the Switchboard.
masca@cpw.pidgin.im
parents:
diff changeset
206
e545b2b6f66a Introduce SlpMessagePart, It will replace MsnMessage in every Slp related code so MsnMessage just get used where it makes sense, in the Switchboard.
masca@cpw.pidgin.im
parents:
diff changeset
207 slpmsg = data;
e545b2b6f66a Introduce SlpMessagePart, It will replace MsnMessage in every Slp related code so MsnMessage just get used where it makes sense, in the Switchboard.
masca@cpw.pidgin.im
parents:
diff changeset
208
e545b2b6f66a Introduce SlpMessagePart, It will replace MsnMessage in every Slp related code so MsnMessage just get used where it makes sense, in the Switchboard.
masca@cpw.pidgin.im
parents:
diff changeset
209 msn_slplink_send_msgpart(slpmsg->slplink, slpmsg);
e545b2b6f66a Introduce SlpMessagePart, It will replace MsnMessage in every Slp related code so MsnMessage just get used where it makes sense, in the Switchboard.
masca@cpw.pidgin.im
parents:
diff changeset
210
e545b2b6f66a Introduce SlpMessagePart, It will replace MsnMessage in every Slp related code so MsnMessage just get used where it makes sense, in the Switchboard.
masca@cpw.pidgin.im
parents:
diff changeset
211 slpmsg->parts = g_list_remove(slpmsg->parts, part);
e545b2b6f66a Introduce SlpMessagePart, It will replace MsnMessage in every Slp related code so MsnMessage just get used where it makes sense, in the Switchboard.
masca@cpw.pidgin.im
parents:
diff changeset
212 }