Mercurial > pidgin
annotate libpurple/protocols/msn/p2p.c @ 30934:4e097dfb7784
Fix some leaks. Header and footer are allocated, copied and not freed.
author | Elliott Sales de Andrade <qulogic@pidgin.im> |
---|---|
date | Sun, 21 Nov 2010 08:47:08 +0000 |
parents | 5964f65c17ed |
children | 72e6fa6caecc |
rev | line source |
---|---|
30771
198d5bf82e09
Oops, forgot to save before commiting.
masca@cpw.pidgin.im
parents:
30768
diff
changeset
|
1 #include "internal.h" |
198d5bf82e09
Oops, forgot to save before commiting.
masca@cpw.pidgin.im
parents:
30768
diff
changeset
|
2 |
198d5bf82e09
Oops, forgot to save before commiting.
masca@cpw.pidgin.im
parents:
30768
diff
changeset
|
3 #include "p2p.h" |
30768
f66e289bebc6
Move parsing of the p2p header to p2p to avoid duplicated code.
masca@cpw.pidgin.im
parents:
diff
changeset
|
4 |
f66e289bebc6
Move parsing of the p2p header to p2p to avoid duplicated code.
masca@cpw.pidgin.im
parents:
diff
changeset
|
5 MsnP2PHeader * |
f66e289bebc6
Move parsing of the p2p header to p2p to avoid duplicated code.
masca@cpw.pidgin.im
parents:
diff
changeset
|
6 msn_p2p_header_from_wire(MsnP2PHeader *wire) |
f66e289bebc6
Move parsing of the p2p header to p2p to avoid duplicated code.
masca@cpw.pidgin.im
parents:
diff
changeset
|
7 { |
f66e289bebc6
Move parsing of the p2p header to p2p to avoid duplicated code.
masca@cpw.pidgin.im
parents:
diff
changeset
|
8 MsnP2PHeader *header; |
f66e289bebc6
Move parsing of the p2p header to p2p to avoid duplicated code.
masca@cpw.pidgin.im
parents:
diff
changeset
|
9 |
f66e289bebc6
Move parsing of the p2p header to p2p to avoid duplicated code.
masca@cpw.pidgin.im
parents:
diff
changeset
|
10 header = g_new(MsnP2PHeader, 1); |
f66e289bebc6
Move parsing of the p2p header to p2p to avoid duplicated code.
masca@cpw.pidgin.im
parents:
diff
changeset
|
11 |
f66e289bebc6
Move parsing of the p2p header to p2p to avoid duplicated code.
masca@cpw.pidgin.im
parents:
diff
changeset
|
12 header->session_id = GUINT32_FROM_LE(wire->session_id); |
f66e289bebc6
Move parsing of the p2p header to p2p to avoid duplicated code.
masca@cpw.pidgin.im
parents:
diff
changeset
|
13 header->id = GUINT32_FROM_LE(wire->id); |
f66e289bebc6
Move parsing of the p2p header to p2p to avoid duplicated code.
masca@cpw.pidgin.im
parents:
diff
changeset
|
14 header->offset = GUINT64_FROM_LE(wire->offset); |
f66e289bebc6
Move parsing of the p2p header to p2p to avoid duplicated code.
masca@cpw.pidgin.im
parents:
diff
changeset
|
15 header->total_size = GUINT64_FROM_LE(wire->total_size); |
f66e289bebc6
Move parsing of the p2p header to p2p to avoid duplicated code.
masca@cpw.pidgin.im
parents:
diff
changeset
|
16 header->length = GUINT32_FROM_LE(wire->length); |
f66e289bebc6
Move parsing of the p2p header to p2p to avoid duplicated code.
masca@cpw.pidgin.im
parents:
diff
changeset
|
17 header->flags = GUINT32_FROM_LE(wire->flags); |
f66e289bebc6
Move parsing of the p2p header to p2p to avoid duplicated code.
masca@cpw.pidgin.im
parents:
diff
changeset
|
18 header->ack_id = GUINT32_FROM_LE(wire->ack_id); |
f66e289bebc6
Move parsing of the p2p header to p2p to avoid duplicated code.
masca@cpw.pidgin.im
parents:
diff
changeset
|
19 header->ack_sub_id = GUINT32_FROM_LE(wire->ack_sub_id); |
f66e289bebc6
Move parsing of the p2p header to p2p to avoid duplicated code.
masca@cpw.pidgin.im
parents:
diff
changeset
|
20 header->ack_size = GUINT64_FROM_LE(wire->ack_size); |
f66e289bebc6
Move parsing of the p2p header to p2p to avoid duplicated code.
masca@cpw.pidgin.im
parents:
diff
changeset
|
21 |
f66e289bebc6
Move parsing of the p2p header to p2p to avoid duplicated code.
masca@cpw.pidgin.im
parents:
diff
changeset
|
22 return header; |
f66e289bebc6
Move parsing of the p2p header to p2p to avoid duplicated code.
masca@cpw.pidgin.im
parents:
diff
changeset
|
23 } |
f66e289bebc6
Move parsing of the p2p header to p2p to avoid duplicated code.
masca@cpw.pidgin.im
parents:
diff
changeset
|
24 |
f66e289bebc6
Move parsing of the p2p header to p2p to avoid duplicated code.
masca@cpw.pidgin.im
parents:
diff
changeset
|
25 MsnP2PHeader * |
f66e289bebc6
Move parsing of the p2p header to p2p to avoid duplicated code.
masca@cpw.pidgin.im
parents:
diff
changeset
|
26 msn_p2p_header_to_wire(MsnP2PHeader *header) |
f66e289bebc6
Move parsing of the p2p header to p2p to avoid duplicated code.
masca@cpw.pidgin.im
parents:
diff
changeset
|
27 { |
f66e289bebc6
Move parsing of the p2p header to p2p to avoid duplicated code.
masca@cpw.pidgin.im
parents:
diff
changeset
|
28 MsnP2PHeader *wire; |
f66e289bebc6
Move parsing of the p2p header to p2p to avoid duplicated code.
masca@cpw.pidgin.im
parents:
diff
changeset
|
29 |
30771
198d5bf82e09
Oops, forgot to save before commiting.
masca@cpw.pidgin.im
parents:
30768
diff
changeset
|
30 wire = g_new(MsnP2PHeader, 1); |
30768
f66e289bebc6
Move parsing of the p2p header to p2p to avoid duplicated code.
masca@cpw.pidgin.im
parents:
diff
changeset
|
31 |
f66e289bebc6
Move parsing of the p2p header to p2p to avoid duplicated code.
masca@cpw.pidgin.im
parents:
diff
changeset
|
32 wire->session_id = GUINT32_TO_LE(header->session_id); |
f66e289bebc6
Move parsing of the p2p header to p2p to avoid duplicated code.
masca@cpw.pidgin.im
parents:
diff
changeset
|
33 wire->id = GUINT32_TO_LE(header->id); |
f66e289bebc6
Move parsing of the p2p header to p2p to avoid duplicated code.
masca@cpw.pidgin.im
parents:
diff
changeset
|
34 wire->offset = GUINT64_TO_LE(header->offset); |
f66e289bebc6
Move parsing of the p2p header to p2p to avoid duplicated code.
masca@cpw.pidgin.im
parents:
diff
changeset
|
35 wire->total_size = GUINT64_TO_LE(header->total_size); |
f66e289bebc6
Move parsing of the p2p header to p2p to avoid duplicated code.
masca@cpw.pidgin.im
parents:
diff
changeset
|
36 wire->length = GUINT32_TO_LE(header->length); |
f66e289bebc6
Move parsing of the p2p header to p2p to avoid duplicated code.
masca@cpw.pidgin.im
parents:
diff
changeset
|
37 wire->flags = GUINT32_TO_LE(header->flags); |
f66e289bebc6
Move parsing of the p2p header to p2p to avoid duplicated code.
masca@cpw.pidgin.im
parents:
diff
changeset
|
38 wire->ack_id = GUINT32_TO_LE(header->ack_id); |
f66e289bebc6
Move parsing of the p2p header to p2p to avoid duplicated code.
masca@cpw.pidgin.im
parents:
diff
changeset
|
39 wire->ack_sub_id = GUINT32_TO_LE(header->ack_sub_id); |
f66e289bebc6
Move parsing of the p2p header to p2p to avoid duplicated code.
masca@cpw.pidgin.im
parents:
diff
changeset
|
40 wire->ack_size = GUINT64_TO_LE(header->ack_size); |
f66e289bebc6
Move parsing of the p2p header to p2p to avoid duplicated code.
masca@cpw.pidgin.im
parents:
diff
changeset
|
41 |
30771
198d5bf82e09
Oops, forgot to save before commiting.
masca@cpw.pidgin.im
parents:
30768
diff
changeset
|
42 return wire; |
198d5bf82e09
Oops, forgot to save before commiting.
masca@cpw.pidgin.im
parents:
30768
diff
changeset
|
43 |
30768
f66e289bebc6
Move parsing of the p2p header to p2p to avoid duplicated code.
masca@cpw.pidgin.im
parents:
diff
changeset
|
44 } |
f66e289bebc6
Move parsing of the p2p header to p2p to avoid duplicated code.
masca@cpw.pidgin.im
parents:
diff
changeset
|
45 |
30782 | 46 MsnP2PFooter * |
47 msn_p2p_footer_from_wire(MsnP2PFooter *wire) | |
48 { | |
49 MsnP2PFooter *footer; | |
50 | |
51 footer = g_new(MsnP2PFooter, 1); | |
52 | |
53 footer->value = GUINT32_FROM_BE(wire->value); | |
54 | |
55 return footer; | |
56 } | |
57 | |
58 MsnP2PFooter * | |
59 msn_p2p_footer_to_wire(MsnP2PFooter *footer) | |
60 { | |
61 MsnP2PFooter *wire; | |
62 | |
63 wire = g_new(MsnP2PFooter, 1); | |
64 | |
65 wire->value = GUINT32_TO_BE(footer->value); | |
66 | |
67 return wire; | |
68 } | |
69 | |
30868
5964f65c17ed
Avoid duplicated code using a util function to check the flags.
masca@cpw.pidgin.im
parents:
30782
diff
changeset
|
70 gboolean |
5964f65c17ed
Avoid duplicated code using a util function to check the flags.
masca@cpw.pidgin.im
parents:
30782
diff
changeset
|
71 msn_p2p_msg_is_data(const MsnP2PHeaderFlag flags) |
5964f65c17ed
Avoid duplicated code using a util function to check the flags.
masca@cpw.pidgin.im
parents:
30782
diff
changeset
|
72 { |
5964f65c17ed
Avoid duplicated code using a util function to check the flags.
masca@cpw.pidgin.im
parents:
30782
diff
changeset
|
73 return (flags == P2P_MSN_OBJ_DATA || |
5964f65c17ed
Avoid duplicated code using a util function to check the flags.
masca@cpw.pidgin.im
parents:
30782
diff
changeset
|
74 flags == (P2P_WML2009_COMP | P2P_MSN_OBJ_DATA) || |
5964f65c17ed
Avoid duplicated code using a util function to check the flags.
masca@cpw.pidgin.im
parents:
30782
diff
changeset
|
75 flags == P2P_FILE_DATA); |
5964f65c17ed
Avoid duplicated code using a util function to check the flags.
masca@cpw.pidgin.im
parents:
30782
diff
changeset
|
76 } |