pidgin: 4a92dc84: Add some buffer reading/writing function..

qulogic at pidgin.im qulogic at pidgin.im
Fri Dec 17 04:11:22 EST 2010


----------------------------------------------------------------------
Revision: 4a92dc84a2b6298d5faac46328cd78b951e804a5
Parent:   1d56b2faf6ebecee50facc22953238915a8b6230
Author:   qulogic at pidgin.im
Date:     12/17/10 02:12:21
Branch:   im.pidgin.pidgin
URL: http://d.pidgin.im/viewmtn/revision/info/4a92dc84a2b6298d5faac46328cd78b951e804a5

Changelog: 

Add some buffer reading/writing functions. I don't know if these are
really the best implementations, but we'll see how they work out with
each use.

Changes against parent 1d56b2faf6ebecee50facc22953238915a8b6230

  patched  libpurple/protocols/msn/msnutils.c
  patched  libpurple/protocols/msn/msnutils.h

-------------- next part --------------
============================================================
--- libpurple/protocols/msn/msnutils.c	51389fecf7a89471581f579bf9b8fa9b6fc1b9c3
+++ libpurple/protocols/msn/msnutils.c	d930db8b663626b67201f669623431b6756f0c42
@@ -617,3 +617,87 @@ msn_handle_chl(char *input, char *output
 	output[32] = '\0';
 }
 
+guint8
+msn_read8(const char *buf)
+{
+	return (guint8)buf[0];
+}
+
+guint16
+msn_read16le(const char *buf)
+{
+	return GUINT16_FROM_LE(*(guint16 *)buf);
+}
+
+guint16
+msn_read16be(const char *buf)
+{
+	return GUINT16_FROM_BE(*(guint16 *)buf);
+}
+
+guint32
+msn_read32le(const char *buf)
+{
+	return GUINT32_FROM_LE(*(guint32 *)buf);
+}
+
+guint32
+msn_read32be(const char *buf)
+{
+	return GUINT32_FROM_BE(*(guint32 *)buf);
+}
+
+guint64
+msn_read64le(const char *buf)
+{
+	return GUINT64_FROM_LE(*(guint64 *)buf);
+}
+
+guint64
+msn_read64be(const char *buf)
+{
+	return GUINT64_FROM_BE(*(guint64 *)buf);
+}
+
+void
+msn_write8(char *buf, guint8 data)
+{
+	*(guint8 *)buf = data;
+}
+
+void
+msn_write16le(char *buf, guint16 data)
+{
+	*(guint16 *)buf = GUINT16_TO_LE(data);
+}
+
+void
+msn_write16be(char *buf, guint16 data)
+{
+	*(guint16 *)buf = GUINT16_TO_BE(data);
+}
+
+void
+msn_write32le(char *buf, guint32 data)
+{
+	*(guint32 *)buf = GUINT32_TO_LE(data);
+}
+
+void
+msn_write32be(char *buf, guint32 data)
+{
+	*(guint32 *)buf = GUINT32_TO_BE(data);
+}
+
+void
+msn_write64le(char *buf, guint64 data)
+{
+	*(guint64 *)buf = GUINT64_TO_LE(data);
+}
+
+void
+msn_write64be(char *buf, guint64 data)
+{
+	*(guint64 *)buf = GUINT64_TO_BE(data);
+}
+
============================================================
--- libpurple/protocols/msn/msnutils.h	d540e1fff6ce209faaff8ede79fb611c0a91f141
+++ libpurple/protocols/msn/msnutils.h	9722d3b7268666bc496e626d06cf10faa29f1548
@@ -94,4 +94,142 @@ void msn_handle_chl(char *input, char *o
  */
 void msn_handle_chl(char *input, char *output);
 
+/**
+ * Read a byte from a buffer
+ *
+ * @param buf Pointer to buffer.
+ *
+ * @return 8-bit byte
+ */
+guint8 msn_read8(const char *buf);
+
+/**
+ * Read a little-endian short from a buffer
+ *
+ * @param buf Pointer to buffer.
+ *
+ * @return 16-bit short
+ */
+guint16 msn_read16le(const char *buf);
+
+/**
+ * Read a big-endian short from a buffer
+ *
+ * @param buf Pointer to buffer.
+ *
+ * @return 16-bit short
+ */
+guint16 msn_read16be(const char *buf);
+
+/**
+ * Read a little-endian int from a buffer
+ *
+ * @param buf Pointer to buffer.
+ *
+ * @return 32-bit int
+ */
+guint32 msn_read32le(const char *buf);
+
+/**
+ * Read a big-endian int from a buffer
+ *
+ * @param buf Pointer to buffer.
+ *
+ * @return 32-bit int
+ */
+guint32 msn_read32be(const char *buf);
+
+/**
+ * Read a little-endian long from a buffer
+ *
+ * @param buf Pointer to buffer.
+ *
+ * @return 64-bit long
+ */
+guint64 msn_read64le(const char *buf);
+
+/**
+ * Read a big-endian long from a buffer
+ *
+ * @param buf Pointer to buffer.
+ *
+ * @return 64-bit long
+ */
+guint64 msn_read64be(const char *buf);
+
+/**
+ * Write a byte to a buffer
+ *
+ * @param buf  Pointer to buffer.
+ * @param data 8-bit byte.
+ */
+void msn_write8(char *buf, guint8 data);
+
+/**
+ * Write a little-endian short to a buffer
+ *
+ * @param buf  Pointer to buffer.
+ * @param data short.
+ */
+void msn_write16le(char *buf, guint16 data);
+
+/**
+ * Write a big-endian short to a buffer
+ *
+ * @param buf  Pointer to buffer.
+ * @param data short.
+ */
+void msn_write16be(char *buf, guint16 data);
+
+/**
+ * Write a little-endian int to a buffer
+ *
+ * @param buf  Pointer to buffer.
+ * @param data int.
+ */
+void msn_write32le(char *buf, guint32 data);
+
+/**
+ * Write a big-endian int to a buffer
+ *
+ * @param buf  Pointer to buffer.
+ * @param data int.
+ */
+void msn_write32be(char *buf, guint32 data);
+
+/**
+ * Write a little-endian long to a buffer
+ *
+ * @param buf  Pointer to buffer.
+ * @param data long.
+ */
+void msn_write64le(char *buf, guint64 data);
+
+/**
+ * Write a big-endian long to a buffer
+ *
+ * @param buf  Pointer to buffer.
+ * @param data short
+ */
+void msn_write64be(char *buf, guint64 data);
+
+/**
+ * Same as above, but these increment the buf pointer.
+ */
+#define msn_pop8(buf)    msn_read8((buf+=1)-1)
+#define msn_pop16le(buf) msn_read16le((buf+=2)-2)
+#define msn_pop16be(buf) msn_read16be((buf+=2)-2)
+#define msn_pop32le(buf) msn_read32le((buf+=4)-4)
+#define msn_pop32be(buf) msn_read32be((buf+=4)-4)
+#define msn_pop64le(buf) msn_read64le((buf+=8)-8)
+#define msn_pop64be(buf) msn_read64be((buf+=8)-8)
+#define msn_push8(buf, data)    msn_write8(buf, data),    buf+=1
+#define msn_push16le(buf, data) msn_write16le(buf, data), buf+=2
+#define msn_push16be(buf, data) msn_write16be(buf, data), buf+=2
+#define msn_push32le(buf, data) msn_write32le(buf, data), buf+=4
+#define msn_push32be(buf, data) msn_write32be(buf, data), buf+=4
+#define msn_push64le(buf, data) msn_write64le(buf, data), buf+=8
+#define msn_push64be(buf, data) msn_write64be(buf, data), buf+=8
+
 #endif /* MSN_UTILS_H */
+


More information about the Commits mailing list