# HG changeset patch # User Mark Huetsch # Date 1156109865 0 # Node ID b7f17fdded6fc6b42ae02669d151760107044fc8 # Parent a54ff7cafc2a5b6b1aaec461682e26187e01c111 [gaim-migrate @ 16918] Const-correctness to eliminate some warnings. committer: Tailor Script diff -r a54ff7cafc2a -r b7f17fdded6f libgaim/protocols/qq/crypt.c --- a/libgaim/protocols/qq/crypt.c Sun Aug 20 20:14:12 2006 +0000 +++ b/libgaim/protocols/qq/crypt.c Sun Aug 20 21:37:45 2006 +0000 @@ -49,10 +49,9 @@ * encryption *******************************************************************/ -/* TODO: convert these data types to proper glib ones */ -static void qq_encipher(unsigned long *const v, const unsigned long *const k, unsigned long *const w) +static void qq_encipher(guint32 *const v, const guint32 *const k, guint32 *const w) { - register unsigned long y = ntohl(v[0]), + register guint32 y = ntohl(v[0]), z = ntohl(v[1]), a = ntohl(k[0]), b = ntohl(k[1]), @@ -72,13 +71,14 @@ w[1] = htonl(z); } -static int rand(void) { /* it can be the real random seed function */ +static gint rand(void) { /* it can be the real random seed function */ return 0xdead; } /* override with number, convenient for debug */ -/* we encrypt every eight byte block */ -static void encrypt_every_8_byte(unsigned char *plain, unsigned char *plain_pre_8, unsigned char **crypted, - unsigned char **crypted_pre_8, unsigned char *key, int *count, int *pos_in_byte, int *is_header) +/* we encrypt every eight byte chunk */ +static void encrypt_every_8_byte(guint8 *plain, guint8 *plain_pre_8, guint8 **crypted, + guint8 **crypted_pre_8, const guint8 *const key, gint *count, + gint *pos_in_byte, gint *is_header) { /* prepare plain text */ for (*pos_in_byte = 0; *pos_in_byte < 8; (*pos_in_byte)++) { @@ -89,7 +89,7 @@ } } /* encrypt it */ - qq_encipher((unsigned long *) plain, (unsigned long *) key, (unsigned long *) *crypted); + qq_encipher((guint32 *) plain, (guint32 *) key, (guint32 *) *crypted); for (*pos_in_byte = 0; *pos_in_byte < 8; (*pos_in_byte)++) { (*crypted)[*pos_in_byte] ^= plain_pre_8[*pos_in_byte]; @@ -104,15 +104,16 @@ } /* encrypt_every_8_byte */ -static void qq_encrypt(unsigned char *instr, int instrlen, unsigned char *key, - unsigned char *outstr, int *outstrlen_prt) +static void qq_encrypt(const guint8 *const instr, gint instrlen, + const guint8 *const key, + guint8 *outstr, gint *outstrlen_prt) { - unsigned char plain[8], /* plain text buffer */ + guint8 plain[8], /* plain text buffer */ plain_pre_8[8], /* plain text buffer, previous 8 bytes */ *crypted, /* crypted text */ - *crypted_pre_8, /* crypted test, previous 8 bytes */ - *inp; /* current position in instr */ - int pos_in_byte = 1, /* loop in the byte */ + *crypted_pre_8; /* crypted test, previous 8 bytes */ + const guint8 *inp; /* current position in instr */ + gint pos_in_byte = 1, /* loop in the byte */ is_header = 1, /* header is one byte */ count = 0, /* number of bytes being crypted */ padding = 0; /* number of padding stuff */ @@ -135,7 +136,8 @@ padding++; } if (pos_in_byte == 8) { - encrypt_every_8_byte(plain, plain_pre_8, &crypted, &crypted_pre_8, key, &count, &pos_in_byte, &is_header); + encrypt_every_8_byte(plain, plain_pre_8, &crypted, &crypted_pre_8, + key, &count, &pos_in_byte, &is_header); } } @@ -146,7 +148,8 @@ instrlen--; } if (pos_in_byte == 8) { - encrypt_every_8_byte(plain, plain_pre_8, &crypted, &crypted_pre_8, key, &count, &pos_in_byte, &is_header); + encrypt_every_8_byte(plain, plain_pre_8, &crypted, &crypted_pre_8, + key, &count, &pos_in_byte, &is_header); } } @@ -157,7 +160,8 @@ padding++; } if (pos_in_byte == 8) { - encrypt_every_8_byte(plain, plain_pre_8, &crypted, &crypted_pre_8, key, &count, &pos_in_byte, &is_header); + encrypt_every_8_byte(plain, plain_pre_8, &crypted, &crypted_pre_8, + key, &count, &pos_in_byte, &is_header); } } @@ -169,9 +173,9 @@ * decryption ********************************************************************/ -static void qq_decipher(unsigned long *const v, const unsigned long *const k, unsigned long *const w) +static void qq_decipher(guint32 *const v, const guint32 *const k, guint32 *const w) { - register unsigned long y = ntohl(v[0]), + register guint32 y = ntohl(v[0]), z = ntohl(v[1]), a = ntohl(k[0]), b = ntohl(k[1]), @@ -192,15 +196,16 @@ w[1] = htonl(z); } -static int decrypt_every_8_byte(unsigned char **crypt_buff, const int instrlen, const unsigned char * const key, - int *context_start, unsigned char *decrypted, int *pos_in_byte) +static gint decrypt_every_8_byte(const guint8 **crypt_buff, const gint instrlen, + const guint8 *const key, gint *context_start, + guint8 *decrypted, gint *pos_in_byte) { for (*pos_in_byte = 0; *pos_in_byte < 8; (*pos_in_byte)++) { if (*context_start + *pos_in_byte >= instrlen) return 1; decrypted[*pos_in_byte] ^= (*crypt_buff)[*pos_in_byte]; } - qq_decipher((unsigned long *) decrypted, (unsigned long *) key, (unsigned long *) decrypted); + qq_decipher((guint32 *) decrypted, (guint32 *) key, (guint32 *) decrypted); *context_start += 8; *crypt_buff += 8; @@ -210,25 +215,29 @@ } /* return 0 if failed, 1 otherwise */ -static int qq_decrypt(unsigned char *instr, int instrlen, unsigned char *key, - unsigned char *outstr, int *outstrlen_ptr) +static gint qq_decrypt(const guint8 *const instr, gint instrlen, + const guint8 *const key, + guint8 *outstr, gint *outstrlen_ptr) { - unsigned char decrypted[8], m[8], *crypt_buff, *crypt_buff_pre_8, *outp; - int count, context_start, pos_in_byte, padding; + guint8 decrypted[8], m[8], *outp; + const guint8 *crypt_buff, *crypt_buff_pre_8; + gint count, context_start, pos_in_byte, padding; /* at least 16 bytes and %8 == 0 */ if ((instrlen % 8) || (instrlen < 16)) { gaim_debug(GAIM_DEBUG_ERROR, "QQ", - "Packet len is either too short or not a multiple of 8 bytes, read %d bytes\n", instrlen); + "Packet len is either too short or not a multiple of 8 bytes, read %d bytes\n", + instrlen); return 0; } /* get information from header */ - qq_decipher((unsigned long *) instr, (unsigned long *) key, (unsigned long *) decrypted); + qq_decipher((guint32 *) instr, (guint32 *) key, (guint32 *) decrypted); pos_in_byte = decrypted[0] & 0x7; count = instrlen - pos_in_byte - 10; /* this is the plaintext length */ /* return if outstr buffer is not large enough or error plaintext length */ if (*outstrlen_ptr < count || count < 0) { - gaim_debug(GAIM_DEBUG_ERROR, "QQ", "Buffer len %d is less than real len %d", *outstrlen_ptr, count); + gaim_debug(GAIM_DEBUG_ERROR, "QQ", "Buffer len %d is less than real len %d", + *outstrlen_ptr, count); return 0; } @@ -248,7 +257,8 @@ } if (pos_in_byte == 8) { crypt_buff_pre_8 = instr; - if (!decrypt_every_8_byte(&crypt_buff, instrlen, key, &context_start, decrypted, &pos_in_byte)) { + if (!decrypt_every_8_byte(&crypt_buff, instrlen, key, + &context_start, decrypted, &pos_in_byte)) { gaim_debug(GAIM_DEBUG_ERROR, "QQ", "decrypt every 8 bytes error A"); return 0; } @@ -265,7 +275,8 @@ } if (pos_in_byte == 8) { crypt_buff_pre_8 = crypt_buff - 8; - if (!decrypt_every_8_byte(&crypt_buff, instrlen, key, &context_start, decrypted, &pos_in_byte)) { + if (!decrypt_every_8_byte(&crypt_buff, instrlen, key, + &context_start, decrypted, &pos_in_byte)) { gaim_debug(GAIM_DEBUG_ERROR, "QQ", "decrypt every 8 bytes error B"); return 0; } @@ -280,7 +291,8 @@ } if (pos_in_byte == 8) { crypt_buff_pre_8 = crypt_buff; - if (!decrypt_every_8_byte(&crypt_buff, instrlen, key, &context_start, decrypted, &pos_in_byte)) { + if (!decrypt_every_8_byte(&crypt_buff, instrlen, key, + &context_start, decrypted, &pos_in_byte)) { gaim_debug(GAIM_DEBUG_ERROR, "QQ", "decrypt every 8 bytes error C"); return 0; } @@ -289,10 +301,11 @@ return 1; } -/* This is the Public Function */ /* return 1 is succeed, otherwise return 0 */ -int qq_crypt(unsigned char flag, - unsigned char *instr, int instrlen, unsigned char *key, unsigned char *outstr, int *outstrlen_ptr) +gint qq_crypt(gint flag, + const guint8 *const instr, gint instrlen, + const guint8 *const key, + guint8 *outstr, gint *outstrlen_ptr) { if (flag == DECRYPT) return qq_decrypt(instr, instrlen, key, outstr, outstrlen_ptr); diff -r a54ff7cafc2a -r b7f17fdded6f libgaim/protocols/qq/crypt.h --- a/libgaim/protocols/qq/crypt.h Sun Aug 20 20:14:12 2006 +0000 +++ b/libgaim/protocols/qq/crypt.h Sun Aug 20 21:37:45 2006 +0000 @@ -23,10 +23,14 @@ #ifndef _QQ_CRYPT_H_ #define _QQ_CRYPT_H_ +#include + #define DECRYPT 0x00 #define ENCRYPT 0x01 -int qq_crypt(unsigned char flag, - unsigned char *instr, int instrlen, unsigned char *key, unsigned char *outstr, int *outstrlen_ptr); +gint qq_crypt(gint flag, + const guint8 *const instr, gint instrlen, + const guint8 *const key, + guint8 *outstr, gint *outstrlen_ptr); #endif diff -r a54ff7cafc2a -r b7f17fdded6f libgaim/protocols/qq/utils.c --- a/libgaim/protocols/qq/utils.c Sun Aug 20 20:14:12 2006 +0000 +++ b/libgaim/protocols/qq/utils.c Sun Aug 20 21:37:45 2006 +0000 @@ -125,7 +125,8 @@ guint8 *str_ip_gen(gchar *str) { guint8 *ip = g_new(guint8, 4); - int a, b, c, d; + gint a, b, c, d; + sscanf(str, "%d.%d.%d.%d", &a, &b, &c, &d); ip[0] = a; ip[1] = b; @@ -149,7 +150,7 @@ } /* convert GAIM name to original QQ UID */ -guint32 gaim_name_to_uid(const gchar *name) +guint32 gaim_name_to_uid(const gchar *const name) { gchar *p; @@ -160,7 +161,7 @@ } /* try to dump the data as GBK */ -void try_dump_as_gbk(guint8 *data, gint len) +void try_dump_as_gbk(const guint8 *const data, gint len) { gint i; guint8 *incoming; @@ -186,7 +187,7 @@ } /* strips whitespace */ -static gchar *strstrip(const gchar *buffer) +static gchar *strstrip(const gchar *const buffer) { GString *stripped; gchar *ret; @@ -206,10 +207,9 @@ return ret; } -/* Dumps an ASCII hex string to a string of bytes. The return should be freed later. - * Returns NULL if a string with an odd number of nibbles is passed in or if buffer - * isn't a valid hex string */ -guint8 *hex_str_to_bytes(const gchar *buffer, gint *out_len) +/* Attempts to dump an ASCII hex string to a string of bytes. + * The return should be freed later. */ +guint8 *hex_str_to_bytes(const gchar *const buffer, gint *out_len) { gchar *hex_str, *hex_buffer, *cursor, tmp; guint8 *bytes, nibble1, nibble2; @@ -259,8 +259,9 @@ return g_memdup(bytes, *out_len); } -/* Dumps a chunk of raw data into an ASCII hex string. The return should be freed later. */ -gchar *hex_dump_to_str(const guint8 *buffer, gint bytes) +/* Dumps a chunk of raw data into an ASCII hex string. + * The return should be freed later. */ +gchar *hex_dump_to_str(const guint8 *const buffer, gint bytes) { GString *str; gchar *ret; diff -r a54ff7cafc2a -r b7f17fdded6f libgaim/protocols/qq/utils.h --- a/libgaim/protocols/qq/utils.h Sun Aug 20 20:14:12 2006 +0000 +++ b/libgaim/protocols/qq/utils.h Sun Aug 20 21:37:45 2006 +0000 @@ -41,7 +41,7 @@ gchar *get_icon_name(gint set, gint suffix); -void try_dump_as_gbk(guint8 *data, gint len); +void try_dump_as_gbk(const guint8 *const data, gint len); guint8 *hex_str_to_bytes(const gchar *buf, gint *out_len); gchar *hex_dump_to_str(const guint8 *buf, gint buf_len);