comparison libgaim/protocols/qq/packet_parse.c @ 14610:473b225e7352

[gaim-migrate @ 17338] Eliminate a dependency in crypt.c by replacing ntohl() (etc) with g_ntohl() (etc). Also replace those calls in the rest of the QQ prpl, to be consistent. committer: Tailor Script <tailor@pidgin.im>
author Mark Huetsch <markhuetsch>
date Fri, 22 Sep 2006 16:05:09 +0000
parents 60b1bc8dbf37
children c039c920e11c
comparison
equal deleted inserted replaced
14609:36ededd6e064 14610:473b225e7352
17 * 17 *
18 * You should have received a copy of the GNU General Public License 18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software 19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 */ 21 */
22
23 #ifndef _WIN32
24 #include <arpa/inet.h>
25 #else
26 #include "win32dep.h"
27 #endif
28 22
29 #include <string.h> 23 #include <string.h>
30 24
31 #include "packet_parse.h" 25 #include "packet_parse.h"
32 26
46 /* read two bytes as "guint16" from buf, 40 /* read two bytes as "guint16" from buf,
47 * return the number of bytes read if succeeds, otherwise return -1 */ 41 * return the number of bytes read if succeeds, otherwise return -1 */
48 gint read_packet_w(guint8 *buf, guint8 **cursor, gint buflen, guint16 *w) 42 gint read_packet_w(guint8 *buf, guint8 **cursor, gint buflen, guint16 *w)
49 { 43 {
50 if (*cursor <= buf + buflen - sizeof(*w)) { 44 if (*cursor <= buf + buflen - sizeof(*w)) {
51 *w = ntohs(**(guint16 **) cursor); 45 *w = g_ntohs(**(guint16 **) cursor);
52 *cursor += sizeof(*w); 46 *cursor += sizeof(*w);
53 return sizeof(*w); 47 return sizeof(*w);
54 } else { 48 } else {
55 return -1; 49 return -1;
56 } 50 }
59 /* read four bytes as "guint32" from buf, 53 /* read four bytes as "guint32" from buf,
60 * return the number of bytes read if succeeds, otherwise return -1 */ 54 * return the number of bytes read if succeeds, otherwise return -1 */
61 gint read_packet_dw(guint8 *buf, guint8 **cursor, gint buflen, guint32 *dw) 55 gint read_packet_dw(guint8 *buf, guint8 **cursor, gint buflen, guint32 *dw)
62 { 56 {
63 if (*cursor <= buf + buflen - sizeof(*dw)) { 57 if (*cursor <= buf + buflen - sizeof(*dw)) {
64 *dw = ntohl(**(guint32 **) cursor); 58 *dw = g_ntohl(**(guint32 **) cursor);
65 *cursor += sizeof(*dw); 59 *cursor += sizeof(*dw);
66 return sizeof(*dw); 60 return sizeof(*dw);
67 } else { 61 } else {
68 return -1; 62 return -1;
69 } 63 }
97 /* pack two bytes as "guint16" into buf 91 /* pack two bytes as "guint16" into buf
98 * return the number of bytes packed, otherwise return -1 */ 92 * return the number of bytes packed, otherwise return -1 */
99 gint create_packet_w(guint8 *buf, guint8 **cursor, guint16 w) 93 gint create_packet_w(guint8 *buf, guint8 **cursor, guint16 w)
100 { 94 {
101 if (*cursor <= buf + MAX_PACKET_SIZE - sizeof(guint16)) { 95 if (*cursor <= buf + MAX_PACKET_SIZE - sizeof(guint16)) {
102 **(guint16 **) cursor = htons(w); 96 **(guint16 **) cursor = g_htons(w);
103 *cursor += sizeof(guint16); 97 *cursor += sizeof(guint16);
104 return sizeof(guint16); 98 return sizeof(guint16);
105 } else { 99 } else {
106 return -1; 100 return -1;
107 } 101 }
110 /* pack four bytes as "guint32" into buf 104 /* pack four bytes as "guint32" into buf
111 * return the number of bytes packed, otherwise return -1 */ 105 * return the number of bytes packed, otherwise return -1 */
112 gint create_packet_dw(guint8 *buf, guint8 **cursor, guint32 dw) 106 gint create_packet_dw(guint8 *buf, guint8 **cursor, guint32 dw)
113 { 107 {
114 if (*cursor <= buf + MAX_PACKET_SIZE - sizeof(guint32)) { 108 if (*cursor <= buf + MAX_PACKET_SIZE - sizeof(guint32)) {
115 **(guint32 **) cursor = htonl(dw); 109 **(guint32 **) cursor = g_htonl(dw);
116 *cursor += sizeof(guint32); 110 *cursor += sizeof(guint32);
117 return sizeof(guint32); 111 return sizeof(guint32);
118 } else { 112 } else {
119 return -1; 113 return -1;
120 } 114 }