comparison libgaim/protocols/qq/utils.c @ 14236:b7f17fdded6f

[gaim-migrate @ 16918] Const-correctness to eliminate some warnings. committer: Tailor Script <tailor@pidgin.im>
author Mark Huetsch <markhuetsch>
date Sun, 20 Aug 2006 21:37:45 +0000
parents 60b1bc8dbf37
children 7cf90e0b6180
comparison
equal deleted inserted replaced
14235:a54ff7cafc2a 14236:b7f17fdded6f
123 } 123 }
124 } 124 }
125 125
126 guint8 *str_ip_gen(gchar *str) { 126 guint8 *str_ip_gen(gchar *str) {
127 guint8 *ip = g_new(guint8, 4); 127 guint8 *ip = g_new(guint8, 4);
128 int a, b, c, d; 128 gint a, b, c, d;
129
129 sscanf(str, "%d.%d.%d.%d", &a, &b, &c, &d); 130 sscanf(str, "%d.%d.%d.%d", &a, &b, &c, &d);
130 ip[0] = a; 131 ip[0] = a;
131 ip[1] = b; 132 ip[1] = b;
132 ip[2] = c; 133 ip[2] = c;
133 ip[3] = d; 134 ip[3] = d;
147 { 148 {
148 return g_strdup_printf(QQ_NAME_FORMAT, uid); 149 return g_strdup_printf(QQ_NAME_FORMAT, uid);
149 } 150 }
150 151
151 /* convert GAIM name to original QQ UID */ 152 /* convert GAIM name to original QQ UID */
152 guint32 gaim_name_to_uid(const gchar *name) 153 guint32 gaim_name_to_uid(const gchar *const name)
153 { 154 {
154 gchar *p; 155 gchar *p;
155 156
156 g_return_val_if_fail(gaim_str_has_prefix(name, QQ_NAME_PREFIX), 0); 157 g_return_val_if_fail(gaim_str_has_prefix(name, QQ_NAME_PREFIX), 0);
157 158
158 p = g_strrstr(name, QQ_NAME_PREFIX); 159 p = g_strrstr(name, QQ_NAME_PREFIX);
159 return (p == NULL) ? 0 : strtol(p + strlen(QQ_NAME_PREFIX), NULL, 10); 160 return (p == NULL) ? 0 : strtol(p + strlen(QQ_NAME_PREFIX), NULL, 10);
160 } 161 }
161 162
162 /* try to dump the data as GBK */ 163 /* try to dump the data as GBK */
163 void try_dump_as_gbk(guint8 *data, gint len) 164 void try_dump_as_gbk(const guint8 *const data, gint len)
164 { 165 {
165 gint i; 166 gint i;
166 guint8 *incoming; 167 guint8 *incoming;
167 gchar *msg_utf8; 168 gchar *msg_utf8;
168 169
184 g_free(msg_utf8); 185 g_free(msg_utf8);
185 } 186 }
186 } 187 }
187 188
188 /* strips whitespace */ 189 /* strips whitespace */
189 static gchar *strstrip(const gchar *buffer) 190 static gchar *strstrip(const gchar *const buffer)
190 { 191 {
191 GString *stripped; 192 GString *stripped;
192 gchar *ret; 193 gchar *ret;
193 int i; 194 int i;
194 195
204 g_string_free(stripped, FALSE); 205 g_string_free(stripped, FALSE);
205 206
206 return ret; 207 return ret;
207 } 208 }
208 209
209 /* Dumps an ASCII hex string to a string of bytes. The return should be freed later. 210 /* Attempts to dump an ASCII hex string to a string of bytes.
210 * Returns NULL if a string with an odd number of nibbles is passed in or if buffer 211 * The return should be freed later. */
211 * isn't a valid hex string */ 212 guint8 *hex_str_to_bytes(const gchar *const buffer, gint *out_len)
212 guint8 *hex_str_to_bytes(const gchar *buffer, gint *out_len)
213 { 213 {
214 gchar *hex_str, *hex_buffer, *cursor, tmp; 214 gchar *hex_str, *hex_buffer, *cursor, tmp;
215 guint8 *bytes, nibble1, nibble2; 215 guint8 *bytes, nibble1, nibble2;
216 gint index; 216 gint index;
217 217
257 *out_len = strlen(hex_str) / 2; 257 *out_len = strlen(hex_str) / 2;
258 g_free(hex_str); 258 g_free(hex_str);
259 return g_memdup(bytes, *out_len); 259 return g_memdup(bytes, *out_len);
260 } 260 }
261 261
262 /* Dumps a chunk of raw data into an ASCII hex string. The return should be freed later. */ 262 /* Dumps a chunk of raw data into an ASCII hex string.
263 gchar *hex_dump_to_str(const guint8 *buffer, gint bytes) 263 * The return should be freed later. */
264 gchar *hex_dump_to_str(const guint8 *const buffer, gint bytes)
264 { 265 {
265 GString *str; 266 GString *str;
266 gchar *ret; 267 gchar *ret;
267 gint i, j, ch; 268 gint i, j, ch;
268 269