annotate libpurple/protocols/msn/p2p.c @ 31491:7b771e6f1142

Change SLP P2P functions to use the new buffer access functions instead of mapping to a struct. I don't mind this since it's limited to just one pair of functions. This means that we don't need to use any packing there. Refs #12856.
author Elliott Sales de Andrade <qulogic@pidgin.im>
date Fri, 17 Dec 2010 07:49:47 +0000
parents f26e961e1274
children a8cc50c2279f
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
31412
72e6fa6caecc These new files are missing GPL headers. And fix a couple incorrect
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 31306
diff changeset
1 /**
72e6fa6caecc These new files are missing GPL headers. And fix a couple incorrect
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 31306
diff changeset
2 * @file p2p.c MSN P2P functions
72e6fa6caecc These new files are missing GPL headers. And fix a couple incorrect
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 31306
diff changeset
3 *
72e6fa6caecc These new files are missing GPL headers. And fix a couple incorrect
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 31306
diff changeset
4 * purple
72e6fa6caecc These new files are missing GPL headers. And fix a couple incorrect
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 31306
diff changeset
5 *
72e6fa6caecc These new files are missing GPL headers. And fix a couple incorrect
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 31306
diff changeset
6 * Purple is the legal property of its developers, whose names are too numerous
72e6fa6caecc These new files are missing GPL headers. And fix a couple incorrect
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 31306
diff changeset
7 * to list here. Please refer to the COPYRIGHT file distributed with this
72e6fa6caecc These new files are missing GPL headers. And fix a couple incorrect
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 31306
diff changeset
8 * source distribution.
72e6fa6caecc These new files are missing GPL headers. And fix a couple incorrect
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 31306
diff changeset
9 *
72e6fa6caecc These new files are missing GPL headers. And fix a couple incorrect
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 31306
diff changeset
10 * This program is free software; you can redistribute it and/or modify
72e6fa6caecc These new files are missing GPL headers. And fix a couple incorrect
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 31306
diff changeset
11 * it under the terms of the GNU General Public License as published by
72e6fa6caecc These new files are missing GPL headers. And fix a couple incorrect
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 31306
diff changeset
12 * the Free Software Foundation; either version 2 of the License, or
72e6fa6caecc These new files are missing GPL headers. And fix a couple incorrect
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 31306
diff changeset
13 * (at your option) any later version.
72e6fa6caecc These new files are missing GPL headers. And fix a couple incorrect
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 31306
diff changeset
14 *
72e6fa6caecc These new files are missing GPL headers. And fix a couple incorrect
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 31306
diff changeset
15 * This program is distributed in the hope that it will be useful,
72e6fa6caecc These new files are missing GPL headers. And fix a couple incorrect
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 31306
diff changeset
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
72e6fa6caecc These new files are missing GPL headers. And fix a couple incorrect
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 31306
diff changeset
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
72e6fa6caecc These new files are missing GPL headers. And fix a couple incorrect
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 31306
diff changeset
18 * GNU General Public License for more details.
72e6fa6caecc These new files are missing GPL headers. And fix a couple incorrect
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 31306
diff changeset
19 *
72e6fa6caecc These new files are missing GPL headers. And fix a couple incorrect
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 31306
diff changeset
20 * You should have received a copy of the GNU General Public License
72e6fa6caecc These new files are missing GPL headers. And fix a couple incorrect
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 31306
diff changeset
21 * along with this program; if not, write to the Free Software
72e6fa6caecc These new files are missing GPL headers. And fix a couple incorrect
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 31306
diff changeset
22 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA
72e6fa6caecc These new files are missing GPL headers. And fix a couple incorrect
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 31306
diff changeset
23 */
72e6fa6caecc These new files are missing GPL headers. And fix a couple incorrect
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 31306
diff changeset
24
31209
198d5bf82e09 Oops, forgot to save before commiting.
masca@cpw.pidgin.im
parents: 31206
diff changeset
25 #include "internal.h"
198d5bf82e09 Oops, forgot to save before commiting.
masca@cpw.pidgin.im
parents: 31206
diff changeset
26
198d5bf82e09 Oops, forgot to save before commiting.
masca@cpw.pidgin.im
parents: 31206
diff changeset
27 #include "p2p.h"
31491
7b771e6f1142 Change SLP P2P functions to use the new buffer access functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 31417
diff changeset
28 #include "msnutils.h"
31206
f66e289bebc6 Move parsing of the p2p header to p2p to avoid duplicated code.
masca@cpw.pidgin.im
parents:
diff changeset
29
f66e289bebc6 Move parsing of the p2p header to p2p to avoid duplicated code.
masca@cpw.pidgin.im
parents:
diff changeset
30 MsnP2PHeader *
31491
7b771e6f1142 Change SLP P2P functions to use the new buffer access functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 31417
diff changeset
31 msn_p2p_header_from_wire(const char *wire)
31206
f66e289bebc6 Move parsing of the p2p header to p2p to avoid duplicated code.
masca@cpw.pidgin.im
parents:
diff changeset
32 {
f66e289bebc6 Move parsing of the p2p header to p2p to avoid duplicated code.
masca@cpw.pidgin.im
parents:
diff changeset
33 MsnP2PHeader *header;
f66e289bebc6 Move parsing of the p2p header to p2p to avoid duplicated code.
masca@cpw.pidgin.im
parents:
diff changeset
34
f66e289bebc6 Move parsing of the p2p header to p2p to avoid duplicated code.
masca@cpw.pidgin.im
parents:
diff changeset
35 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
36
31491
7b771e6f1142 Change SLP P2P functions to use the new buffer access functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 31417
diff changeset
37 header->session_id = msn_pop32le(wire);
7b771e6f1142 Change SLP P2P functions to use the new buffer access functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 31417
diff changeset
38 header->id = msn_pop32le(wire);
7b771e6f1142 Change SLP P2P functions to use the new buffer access functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 31417
diff changeset
39 header->offset = msn_pop64le(wire);
7b771e6f1142 Change SLP P2P functions to use the new buffer access functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 31417
diff changeset
40 header->total_size = msn_pop64le(wire);
7b771e6f1142 Change SLP P2P functions to use the new buffer access functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 31417
diff changeset
41 header->length = msn_pop32le(wire);
7b771e6f1142 Change SLP P2P functions to use the new buffer access functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 31417
diff changeset
42 header->flags = msn_pop32le(wire);
7b771e6f1142 Change SLP P2P functions to use the new buffer access functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 31417
diff changeset
43 header->ack_id = msn_pop32le(wire);
7b771e6f1142 Change SLP P2P functions to use the new buffer access functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 31417
diff changeset
44 header->ack_sub_id = msn_pop32le(wire);
7b771e6f1142 Change SLP P2P functions to use the new buffer access functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 31417
diff changeset
45 header->ack_size = msn_pop64le(wire);
31206
f66e289bebc6 Move parsing of the p2p header to p2p to avoid duplicated code.
masca@cpw.pidgin.im
parents:
diff changeset
46
f66e289bebc6 Move parsing of the p2p header to p2p to avoid duplicated code.
masca@cpw.pidgin.im
parents:
diff changeset
47 return header;
f66e289bebc6 Move parsing of the p2p header to p2p to avoid duplicated code.
masca@cpw.pidgin.im
parents:
diff changeset
48 }
f66e289bebc6 Move parsing of the p2p header to p2p to avoid duplicated code.
masca@cpw.pidgin.im
parents:
diff changeset
49
31491
7b771e6f1142 Change SLP P2P functions to use the new buffer access functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 31417
diff changeset
50 char *
31206
f66e289bebc6 Move parsing of the p2p header to p2p to avoid duplicated code.
masca@cpw.pidgin.im
parents:
diff changeset
51 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
52 {
31491
7b771e6f1142 Change SLP P2P functions to use the new buffer access functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 31417
diff changeset
53 char *wire;
7b771e6f1142 Change SLP P2P functions to use the new buffer access functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 31417
diff changeset
54 char *tmp;
31206
f66e289bebc6 Move parsing of the p2p header to p2p to avoid duplicated code.
masca@cpw.pidgin.im
parents:
diff changeset
55
31491
7b771e6f1142 Change SLP P2P functions to use the new buffer access functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 31417
diff changeset
56 tmp = wire = g_new(char, P2P_PACKET_HEADER_SIZE);
31206
f66e289bebc6 Move parsing of the p2p header to p2p to avoid duplicated code.
masca@cpw.pidgin.im
parents:
diff changeset
57
31491
7b771e6f1142 Change SLP P2P functions to use the new buffer access functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 31417
diff changeset
58 msn_push32le(tmp, header->session_id);
7b771e6f1142 Change SLP P2P functions to use the new buffer access functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 31417
diff changeset
59 msn_push32le(tmp, header->id);
7b771e6f1142 Change SLP P2P functions to use the new buffer access functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 31417
diff changeset
60 msn_push64le(tmp, header->offset);
7b771e6f1142 Change SLP P2P functions to use the new buffer access functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 31417
diff changeset
61 msn_push64le(tmp, header->total_size);
7b771e6f1142 Change SLP P2P functions to use the new buffer access functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 31417
diff changeset
62 msn_push32le(tmp, header->length);
7b771e6f1142 Change SLP P2P functions to use the new buffer access functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 31417
diff changeset
63 msn_push32le(tmp, header->flags);
7b771e6f1142 Change SLP P2P functions to use the new buffer access functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 31417
diff changeset
64 msn_push32le(tmp, header->ack_id);
7b771e6f1142 Change SLP P2P functions to use the new buffer access functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 31417
diff changeset
65 msn_push32le(tmp, header->ack_sub_id);
7b771e6f1142 Change SLP P2P functions to use the new buffer access functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 31417
diff changeset
66 msn_push64le(tmp, header->ack_size);
31206
f66e289bebc6 Move parsing of the p2p header to p2p to avoid duplicated code.
masca@cpw.pidgin.im
parents:
diff changeset
67
31209
198d5bf82e09 Oops, forgot to save before commiting.
masca@cpw.pidgin.im
parents: 31206
diff changeset
68 return wire;
198d5bf82e09 Oops, forgot to save before commiting.
masca@cpw.pidgin.im
parents: 31206
diff changeset
69
31206
f66e289bebc6 Move parsing of the p2p header to p2p to avoid duplicated code.
masca@cpw.pidgin.im
parents:
diff changeset
70 }
f66e289bebc6 Move parsing of the p2p header to p2p to avoid duplicated code.
masca@cpw.pidgin.im
parents:
diff changeset
71
31220
3ccddae82532 Add P2PFooter helper functions.
masca@cpw.pidgin.im
parents: 31209
diff changeset
72 MsnP2PFooter *
31491
7b771e6f1142 Change SLP P2P functions to use the new buffer access functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 31417
diff changeset
73 msn_p2p_footer_from_wire(const char *wire)
31220
3ccddae82532 Add P2PFooter helper functions.
masca@cpw.pidgin.im
parents: 31209
diff changeset
74 {
3ccddae82532 Add P2PFooter helper functions.
masca@cpw.pidgin.im
parents: 31209
diff changeset
75 MsnP2PFooter *footer;
3ccddae82532 Add P2PFooter helper functions.
masca@cpw.pidgin.im
parents: 31209
diff changeset
76
3ccddae82532 Add P2PFooter helper functions.
masca@cpw.pidgin.im
parents: 31209
diff changeset
77 footer = g_new(MsnP2PFooter, 1);
3ccddae82532 Add P2PFooter helper functions.
masca@cpw.pidgin.im
parents: 31209
diff changeset
78
31491
7b771e6f1142 Change SLP P2P functions to use the new buffer access functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 31417
diff changeset
79 footer->value = msn_pop32be(wire);
31220
3ccddae82532 Add P2PFooter helper functions.
masca@cpw.pidgin.im
parents: 31209
diff changeset
80
3ccddae82532 Add P2PFooter helper functions.
masca@cpw.pidgin.im
parents: 31209
diff changeset
81 return footer;
3ccddae82532 Add P2PFooter helper functions.
masca@cpw.pidgin.im
parents: 31209
diff changeset
82 }
3ccddae82532 Add P2PFooter helper functions.
masca@cpw.pidgin.im
parents: 31209
diff changeset
83
31491
7b771e6f1142 Change SLP P2P functions to use the new buffer access functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 31417
diff changeset
84 char *
31220
3ccddae82532 Add P2PFooter helper functions.
masca@cpw.pidgin.im
parents: 31209
diff changeset
85 msn_p2p_footer_to_wire(MsnP2PFooter *footer)
3ccddae82532 Add P2PFooter helper functions.
masca@cpw.pidgin.im
parents: 31209
diff changeset
86 {
31491
7b771e6f1142 Change SLP P2P functions to use the new buffer access functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 31417
diff changeset
87 char *wire;
7b771e6f1142 Change SLP P2P functions to use the new buffer access functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 31417
diff changeset
88 char *tmp;
31220
3ccddae82532 Add P2PFooter helper functions.
masca@cpw.pidgin.im
parents: 31209
diff changeset
89
31491
7b771e6f1142 Change SLP P2P functions to use the new buffer access functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 31417
diff changeset
90 tmp = wire = g_new(char, P2P_PACKET_FOOTER_SIZE);
31220
3ccddae82532 Add P2PFooter helper functions.
masca@cpw.pidgin.im
parents: 31209
diff changeset
91
31491
7b771e6f1142 Change SLP P2P functions to use the new buffer access functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 31417
diff changeset
92 msn_push32be(tmp, footer->value);
31220
3ccddae82532 Add P2PFooter helper functions.
masca@cpw.pidgin.im
parents: 31209
diff changeset
93
3ccddae82532 Add P2PFooter helper functions.
masca@cpw.pidgin.im
parents: 31209
diff changeset
94 return wire;
3ccddae82532 Add P2PFooter helper functions.
masca@cpw.pidgin.im
parents: 31209
diff changeset
95 }
3ccddae82532 Add P2PFooter helper functions.
masca@cpw.pidgin.im
parents: 31209
diff changeset
96
31306
5964f65c17ed Avoid duplicated code using a util function to check the flags.
masca@cpw.pidgin.im
parents: 31220
diff changeset
97 gboolean
5964f65c17ed Avoid duplicated code using a util function to check the flags.
masca@cpw.pidgin.im
parents: 31220
diff changeset
98 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: 31220
diff changeset
99 {
5964f65c17ed Avoid duplicated code using a util function to check the flags.
masca@cpw.pidgin.im
parents: 31220
diff changeset
100 return (flags == P2P_MSN_OBJ_DATA ||
31417
f26e961e1274 Fix the name of this flag.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 31412
diff changeset
101 flags == (P2P_WLM2009_COMP | P2P_MSN_OBJ_DATA) ||
31306
5964f65c17ed Avoid duplicated code using a util function to check the flags.
masca@cpw.pidgin.im
parents: 31220
diff changeset
102 flags == P2P_FILE_DATA);
5964f65c17ed Avoid duplicated code using a util function to check the flags.
masca@cpw.pidgin.im
parents: 31220
diff changeset
103 }
31491
7b771e6f1142 Change SLP P2P functions to use the new buffer access functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 31417
diff changeset
104