Mercurial > pidgin
comparison src/protocols/qq/packet_parse.c @ 14021:ef8490f9e823
[gaim-migrate @ 16618]
Replaced all C++-style comments with C-style ones.
Cleaned up some comments and implemented a more consistent formatting scheme.
committer: Tailor Script <tailor@pidgin.im>
| author | Mark Huetsch <markhuetsch> |
|---|---|
| date | Wed, 02 Aug 2006 15:35:36 +0000 |
| parents | 983fd420e86b |
| children |
comparison
equal
deleted
inserted
replaced
| 14020:13e7ba964993 | 14021:ef8490f9e823 |
|---|---|
| 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 | 22 |
| 23 // START OF FILE | |
| 24 /*****************************************************************************/ | |
| 25 #ifndef _WIN32 | 23 #ifndef _WIN32 |
| 26 #include <arpa/inet.h> | 24 #include <arpa/inet.h> |
| 27 #else | 25 #else |
| 28 #include "win32dep.h" | 26 #include "win32dep.h" |
| 29 #endif | 27 #endif |
| 30 | 28 |
| 31 #include <string.h> | 29 #include <string.h> |
| 32 | 30 |
| 33 #include "packet_parse.h" | 31 #include "packet_parse.h" |
| 34 | 32 |
| 35 /*****************************************************************************/ | 33 /* read one byte from buf, |
| 36 // read one byte from buf, | 34 * return the number of bytes read if succeeds, otherwise return -1 */ |
| 37 // return the number of bytes read if succeeds, otherwise return -1 | 35 gint read_packet_b(guint8 *buf, guint8 **cursor, gint buflen, guint8 *b) |
| 38 gint read_packet_b(guint8 * buf, guint8 ** cursor, gint buflen, guint8 * b) | |
| 39 { | 36 { |
| 40 if (*cursor <= buf + buflen - sizeof(*b)) { | 37 if (*cursor <= buf + buflen - sizeof(*b)) { |
| 41 *b = **(guint8 **) cursor; | 38 *b = **(guint8 **) cursor; |
| 42 *cursor += sizeof(*b); | 39 *cursor += sizeof(*b); |
| 43 return sizeof(*b); | 40 return sizeof(*b); |
| 44 } else | 41 } else { |
| 45 return -1; | 42 return -1; |
| 46 } // read_packet_b | 43 } |
| 44 } | |
| 47 | 45 |
| 48 /*****************************************************************************/ | 46 /* read two bytes as "guint16" from buf, |
| 49 // read two bytes as "guint16" from buf, | 47 * return the number of bytes read if succeeds, otherwise return -1 */ |
| 50 // return the number of bytes read if succeeds, otherwise return -1 | 48 gint read_packet_w(guint8 *buf, guint8 **cursor, gint buflen, guint16 *w) |
| 51 gint read_packet_w(guint8 * buf, guint8 ** cursor, gint buflen, guint16 * w) | |
| 52 { | 49 { |
| 53 if (*cursor <= buf + buflen - sizeof(*w)) { | 50 if (*cursor <= buf + buflen - sizeof(*w)) { |
| 54 *w = ntohs(**(guint16 **) cursor); | 51 *w = ntohs(**(guint16 **) cursor); |
| 55 *cursor += sizeof(*w); | 52 *cursor += sizeof(*w); |
| 56 return sizeof(*w); | 53 return sizeof(*w); |
| 57 } else | 54 } else { |
| 58 return -1; | 55 return -1; |
| 59 } // read_packet_w | 56 } |
| 57 } | |
| 60 | 58 |
| 61 /*****************************************************************************/ | 59 /* read four bytes as "guint32" from buf, |
| 62 // read four bytes as "guint32" from buf, | 60 * return the number of bytes read if succeeds, otherwise return -1 */ |
| 63 // return the number of bytes read if succeeds, otherwise return -1 | 61 gint read_packet_dw(guint8 *buf, guint8 **cursor, gint buflen, guint32 *dw) |
| 64 gint read_packet_dw(guint8 * buf, guint8 ** cursor, gint buflen, guint32 * dw) | |
| 65 { | 62 { |
| 66 if (*cursor <= buf + buflen - sizeof(*dw)) { | 63 if (*cursor <= buf + buflen - sizeof(*dw)) { |
| 67 *dw = ntohl(**(guint32 **) cursor); | 64 *dw = ntohl(**(guint32 **) cursor); |
| 68 *cursor += sizeof(*dw); | 65 *cursor += sizeof(*dw); |
| 69 return sizeof(*dw); | 66 return sizeof(*dw); |
| 70 } else | 67 } else { |
| 71 return -1; | 68 return -1; |
| 72 } // read_packet_dw | 69 } |
| 70 } | |
| 73 | 71 |
| 74 /*****************************************************************************/ | 72 /* read datalen bytes from buf, |
| 75 // read datalen bytes from buf, | 73 * return the number of bytes read if succeeds, otherwise return -1 */ |
| 76 // return the number of bytes read if succeeds, otherwise return -1 | 74 gint read_packet_data(guint8 *buf, guint8 **cursor, gint buflen, guint8 *data, gint datalen) { |
| 77 gint read_packet_data(guint8 * buf, guint8 ** cursor, gint buflen, guint8 * data, gint datalen) { | |
| 78 if (*cursor <= buf + buflen - datalen) { | 75 if (*cursor <= buf + buflen - datalen) { |
| 79 g_memmove(data, *cursor, datalen); | 76 g_memmove(data, *cursor, datalen); |
| 80 *cursor += datalen; | 77 *cursor += datalen; |
| 81 return datalen; | 78 return datalen; |
| 82 } else | 79 } else { |
| 83 return -1; | 80 return -1; |
| 84 } // read_packet_data | 81 } |
| 82 } | |
| 85 | 83 |
| 86 /*****************************************************************************/ | 84 /* pack one byte into buf |
| 87 // pack one byte into buf | 85 * return the number of bytes packed, otherwise return -1 */ |
| 88 // return the number of bytes packed, otherwise return -1 | 86 gint create_packet_b(guint8 *buf, guint8 **cursor, guint8 b) |
| 89 gint create_packet_b(guint8 * buf, guint8 ** cursor, guint8 b) | |
| 90 { | 87 { |
| 91 if (*cursor <= buf + MAX_PACKET_SIZE - sizeof(guint8)) { | 88 if (*cursor <= buf + MAX_PACKET_SIZE - sizeof(guint8)) { |
| 92 **(guint8 **) cursor = b; | 89 **(guint8 **) cursor = b; |
| 93 *cursor += sizeof(guint8); | 90 *cursor += sizeof(guint8); |
| 94 return sizeof(guint8); | 91 return sizeof(guint8); |
| 95 } else | 92 } else { |
| 96 return -1; | 93 return -1; |
| 97 } // create_packet_b | 94 } |
| 95 } | |
| 98 | 96 |
| 99 /*****************************************************************************/ | 97 /* pack two bytes as "guint16" into buf |
| 100 // pack two bytes as "guint16" into buf | 98 * return the number of bytes packed, otherwise return -1 */ |
| 101 // return the number of bytes packed, otherwise return -1 | 99 gint create_packet_w(guint8 *buf, guint8 **cursor, guint16 w) |
| 102 gint create_packet_w(guint8 * buf, guint8 ** cursor, guint16 w) | |
| 103 { | 100 { |
| 104 if (*cursor <= buf + MAX_PACKET_SIZE - sizeof(guint16)) { | 101 if (*cursor <= buf + MAX_PACKET_SIZE - sizeof(guint16)) { |
| 105 **(guint16 **) cursor = htons(w); | 102 **(guint16 **) cursor = htons(w); |
| 106 *cursor += sizeof(guint16); | 103 *cursor += sizeof(guint16); |
| 107 return sizeof(guint16); | 104 return sizeof(guint16); |
| 108 } else | 105 } else { |
| 109 return -1; | 106 return -1; |
| 110 } // create_packet_w | 107 } |
| 108 } | |
| 111 | 109 |
| 112 /*****************************************************************************/ | 110 /* pack four bytes as "guint32" into buf |
| 113 // pack four bytes as "guint32" into buf | 111 * return the number of bytes packed, otherwise return -1 */ |
| 114 // return the number of bytes packed, otherwise return -1 | 112 gint create_packet_dw(guint8 *buf, guint8 **cursor, guint32 dw) |
| 115 gint create_packet_dw(guint8 * buf, guint8 ** cursor, guint32 dw) | |
| 116 { | 113 { |
| 117 if (*cursor <= buf + MAX_PACKET_SIZE - sizeof(guint32)) { | 114 if (*cursor <= buf + MAX_PACKET_SIZE - sizeof(guint32)) { |
| 118 **(guint32 **) cursor = htonl(dw); | 115 **(guint32 **) cursor = htonl(dw); |
| 119 *cursor += sizeof(guint32); | 116 *cursor += sizeof(guint32); |
| 120 return sizeof(guint32); | 117 return sizeof(guint32); |
| 121 } else | 118 } else { |
| 122 return -1; | 119 return -1; |
| 123 } // create_packet_dw | 120 } |
| 121 } | |
| 124 | 122 |
| 125 /*****************************************************************************/ | 123 /* pack datalen bytes into buf |
| 126 // pack datalen bytes into buf | 124 * return the number of bytes packed, otherwise return -1 */ |
| 127 // return the number of bytes packed, otherwise return -1 | 125 gint create_packet_data(guint8 *buf, guint8 **cursor, guint8 *data, gint datalen) |
| 128 gint create_packet_data(guint8 * buf, guint8 ** cursor, guint8 * data, gint datalen) { | 126 { |
| 129 if (*cursor <= buf + MAX_PACKET_SIZE - datalen) { | 127 if (*cursor <= buf + MAX_PACKET_SIZE - datalen) { |
| 130 g_memmove(*cursor, data, datalen); | 128 g_memmove(*cursor, data, datalen); |
| 131 *cursor += datalen; | 129 *cursor += datalen; |
| 132 return datalen; | 130 return datalen; |
| 133 } else | 131 } else { |
| 134 return -1; | 132 return -1; |
| 135 } // create_packet_data | 133 } |
| 136 | 134 } |
| 137 /*****************************************************************************/ | |
| 138 // END OF FILE |
