annotate libpurple/protocols/msn/slpmsg_part.c @ 31292:47b6eda87723

propagate from branch 'im.pidgin.pidgin' (head 07d0765c444a097af45c2650f54323afb900a07b) to branch 'im.pidgin.soc.2010.msn-tlc' (head f3998422a4724ab424e4e2328f58fc0504856557)
author masca@cpw.pidgin.im
date Mon, 19 Jul 2010 21:11:32 +0000
parents e358e16e527f
children 5ad928319db0
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
31234
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"
31287
e358e16e527f Add a ref to the part at sbconn and add some debug output.
masca@cpw.pidgin.im
parents: 31285
diff changeset
2 #include "debug.h"
31234
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;
31260
e0dd17804079 Fix typo.
masca@cpw.pidgin.im
parents: 31234
diff changeset
19 part->nak_cb = msn_slpmsgpart_nak;
31234
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
31285
74c4aa38adfc Add support to ref/unref SlpMessageParts.
masca@cpw.pidgin.im
parents: 31281
diff changeset
21 return msn_slpmsgpart_ref(part);
31234
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);
31278
df3e9c686b02 Update tmp pointer after reading the header.
masca@cpw.pidgin.im
parents: 31262
diff changeset
40 tmp += P2P_PACKET_HEADER_SIZE;
31234
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 */
31281
98cd0ea847ec Properly set the body_len of the SlpMessagePart, this set correctly the footer value.
masca@cpw.pidgin.im
parents: 31278
diff changeset
43 body_len = data_len - P2P_PACKET_HEADER_SIZE - P2P_PACKET_FOOTER_SIZE;
31234
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 {
31262
a743c25b27a8 Destroying Parts return silently when it's passed a NULL pointer.
masca@cpw.pidgin.im
parents: 31260
diff changeset
62 if (!part)
a743c25b27a8 Destroying Parts return silently when it's passed a NULL pointer.
masca@cpw.pidgin.im
parents: 31260
diff changeset
63 return;
a743c25b27a8 Destroying Parts return silently when it's passed a NULL pointer.
masca@cpw.pidgin.im
parents: 31260
diff changeset
64
31285
74c4aa38adfc Add support to ref/unref SlpMessageParts.
masca@cpw.pidgin.im
parents: 31281
diff changeset
65 if (part->ref_count > 0) {
74c4aa38adfc Add support to ref/unref SlpMessageParts.
masca@cpw.pidgin.im
parents: 31281
diff changeset
66 msn_slpmsgpart_unref(part);
74c4aa38adfc Add support to ref/unref SlpMessageParts.
masca@cpw.pidgin.im
parents: 31281
diff changeset
67
74c4aa38adfc Add support to ref/unref SlpMessageParts.
masca@cpw.pidgin.im
parents: 31281
diff changeset
68 return;
74c4aa38adfc Add support to ref/unref SlpMessageParts.
masca@cpw.pidgin.im
parents: 31281
diff changeset
69 }
74c4aa38adfc Add support to ref/unref SlpMessageParts.
masca@cpw.pidgin.im
parents: 31281
diff changeset
70
31234
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
31285
74c4aa38adfc Add support to ref/unref SlpMessageParts.
masca@cpw.pidgin.im
parents: 31281
diff changeset
78 MsnSlpMessagePart *msn_slpmsgpart_ref(MsnSlpMessagePart *part)
74c4aa38adfc Add support to ref/unref SlpMessageParts.
masca@cpw.pidgin.im
parents: 31281
diff changeset
79 {
74c4aa38adfc Add support to ref/unref SlpMessageParts.
masca@cpw.pidgin.im
parents: 31281
diff changeset
80 g_return_val_if_fail(part != NULL, NULL);
74c4aa38adfc Add support to ref/unref SlpMessageParts.
masca@cpw.pidgin.im
parents: 31281
diff changeset
81 part->ref_count ++;
74c4aa38adfc Add support to ref/unref SlpMessageParts.
masca@cpw.pidgin.im
parents: 31281
diff changeset
82
31287
e358e16e527f Add a ref to the part at sbconn and add some debug output.
masca@cpw.pidgin.im
parents: 31285
diff changeset
83 if (purple_debug_is_verbose())
e358e16e527f Add a ref to the part at sbconn and add some debug output.
masca@cpw.pidgin.im
parents: 31285
diff changeset
84 purple_debug_info("msn", "part ref (%p)[%" G_GSIZE_FORMAT "]\n", part, part->ref_count);
e358e16e527f Add a ref to the part at sbconn and add some debug output.
masca@cpw.pidgin.im
parents: 31285
diff changeset
85
31285
74c4aa38adfc Add support to ref/unref SlpMessageParts.
masca@cpw.pidgin.im
parents: 31281
diff changeset
86 return part;
74c4aa38adfc Add support to ref/unref SlpMessageParts.
masca@cpw.pidgin.im
parents: 31281
diff changeset
87 }
74c4aa38adfc Add support to ref/unref SlpMessageParts.
masca@cpw.pidgin.im
parents: 31281
diff changeset
88
74c4aa38adfc Add support to ref/unref SlpMessageParts.
masca@cpw.pidgin.im
parents: 31281
diff changeset
89 MsnSlpMessagePart *msn_slpmsgpart_unref(MsnSlpMessagePart *part)
74c4aa38adfc Add support to ref/unref SlpMessageParts.
masca@cpw.pidgin.im
parents: 31281
diff changeset
90 {
74c4aa38adfc Add support to ref/unref SlpMessageParts.
masca@cpw.pidgin.im
parents: 31281
diff changeset
91 g_return_val_if_fail(part != NULL, NULL);
74c4aa38adfc Add support to ref/unref SlpMessageParts.
masca@cpw.pidgin.im
parents: 31281
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: 31281
diff changeset
93
74c4aa38adfc Add support to ref/unref SlpMessageParts.
masca@cpw.pidgin.im
parents: 31281
diff changeset
94 part->ref_count--;
74c4aa38adfc Add support to ref/unref SlpMessageParts.
masca@cpw.pidgin.im
parents: 31281
diff changeset
95
31287
e358e16e527f Add a ref to the part at sbconn and add some debug output.
masca@cpw.pidgin.im
parents: 31285
diff changeset
96 if (purple_debug_is_verbose())
e358e16e527f Add a ref to the part at sbconn and add some debug output.
masca@cpw.pidgin.im
parents: 31285
diff changeset
97 purple_debug_info("msn", "part unref (%p)[%" G_GSIZE_FORMAT "]\n", part, part->ref_count);
e358e16e527f Add a ref to the part at sbconn and add some debug output.
masca@cpw.pidgin.im
parents: 31285
diff changeset
98
31285
74c4aa38adfc Add support to ref/unref SlpMessageParts.
masca@cpw.pidgin.im
parents: 31281
diff changeset
99 if (part->ref_count == 0) {
74c4aa38adfc Add support to ref/unref SlpMessageParts.
masca@cpw.pidgin.im
parents: 31281
diff changeset
100 msn_slpmsgpart_destroy(part);
74c4aa38adfc Add support to ref/unref SlpMessageParts.
masca@cpw.pidgin.im
parents: 31281
diff changeset
101
74c4aa38adfc Add support to ref/unref SlpMessageParts.
masca@cpw.pidgin.im
parents: 31281
diff changeset
102 return NULL;
74c4aa38adfc Add support to ref/unref SlpMessageParts.
masca@cpw.pidgin.im
parents: 31281
diff changeset
103 }
74c4aa38adfc Add support to ref/unref SlpMessageParts.
masca@cpw.pidgin.im
parents: 31281
diff changeset
104
74c4aa38adfc Add support to ref/unref SlpMessageParts.
masca@cpw.pidgin.im
parents: 31281
diff changeset
105 return part;
74c4aa38adfc Add support to ref/unref SlpMessageParts.
masca@cpw.pidgin.im
parents: 31281
diff changeset
106 }
74c4aa38adfc Add support to ref/unref SlpMessageParts.
masca@cpw.pidgin.im
parents: 31281
diff changeset
107
31234
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
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
112 if (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
113 g_free(part->buffer);
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
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 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
116 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
117 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
118 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
119 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
120 } 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
121 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
122 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
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
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 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
128 {
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 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
130 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
131 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
132 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
133 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
134
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 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
136 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
137
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 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
139 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
140
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 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
142 /* 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
143 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
144 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
145
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 /* 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
147 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
148 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
149
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 /* 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
151 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
152 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
153 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
154
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 *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
156
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
157 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
158 }
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 /* 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
160 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
161 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
162 {
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 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
164 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
165
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 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
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 real_size = (slpmsg->flags == P2P_ACK) ? 0 : slpmsg->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
169
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
170 slpmsg->offset += part->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
171
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
172 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
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 if (slpmsg->offset < 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
175 {
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
176 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
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 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
179 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
180 }
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 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
182 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
183 }
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 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
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 /* The whole message has been sent */
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 if (slpmsg->flags == P2P_MSN_OBJ_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
188 slpmsg->flags == (P2P_WML2009_COMP | P2P_MSN_OBJ_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
189 slpmsg->flags == P2P_FILE_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
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 }