Mercurial > pidgin
comparison libpurple/protocols/qq/utils.c @ 24145:ec3f7d3e0445
2008.10.04 - lonicerae <lonicerae(at)gmail.com>
* fixed a bug in qq_base.c
author | SHiNE CsyFeK <csyfek@gmail.com> |
---|---|
date | Wed, 22 Oct 2008 14:49:38 +0000 |
parents | a95c7e71064c |
children | ce94189f15ad |
comparison
equal
deleted
inserted
replaced
24144:a95c7e71064c | 24145:ec3f7d3e0445 |
---|---|
102 * return gchar* array (needs to be freed by g_strfreev later), or NULL */ | 102 * return gchar* array (needs to be freed by g_strfreev later), or NULL */ |
103 gchar **split_data(guint8 *data, gint len, const gchar *delimit, gint expected_fields) | 103 gchar **split_data(guint8 *data, gint len, const gchar *delimit, gint expected_fields) |
104 { | 104 { |
105 guint8 *input; | 105 guint8 *input; |
106 gchar **segments; | 106 gchar **segments; |
107 gint count, j; | 107 gint i, j; |
108 | 108 |
109 g_return_val_if_fail(data != NULL && len != 0 && delimit != 0, NULL); | 109 g_return_val_if_fail(data != NULL && len != 0 && delimit != 0, NULL); |
110 | 110 |
111 /* as the last field would be string, but data is not ended with 0x00 | 111 /* as the last field would be string, but data is not ended with 0x00 |
112 * we have to duplicate the data and append a 0x00 at the end */ | 112 * we have to duplicate the data and append a 0x00 at the end */ |
116 | 116 |
117 segments = g_strsplit_set((gchar *) input, delimit, 0); | 117 segments = g_strsplit_set((gchar *) input, delimit, 0); |
118 if (expected_fields <= 0) | 118 if (expected_fields <= 0) |
119 return segments; | 119 return segments; |
120 | 120 |
121 for (count = 0; segments[count] != NULL; count++) {; | 121 for (i = 0; segments[i] != NULL; i++) {; |
122 } | 122 } |
123 if (count < expected_fields) { /* not enough fields */ | 123 if (i < expected_fields) { /* not enough fields */ |
124 purple_debug_error("QQ", "Less fields %d then %d\n", count, expected_fields); | 124 purple_debug_error("QQ", "Invalid data, expect %d fields, found only %d, discard\n", |
125 expected_fields, i); | |
126 g_strfreev(segments); | |
125 return NULL; | 127 return NULL; |
126 } else if (count > expected_fields) { /* more fields, OK */ | 128 } else if (i > expected_fields) { /* more fields, OK */ |
127 purple_debug_warning("QQ", "More fields %d than %d\n", count, expected_fields); | 129 purple_debug_warning("QQ", "Dangerous data, expect %d fields, found %d, return all\n", |
130 expected_fields, i); | |
128 /* free up those not used */ | 131 /* free up those not used */ |
129 for (j = expected_fields; j < count; j++) { | 132 for (j = expected_fields; j < i; j++) { |
130 purple_debug_warning("QQ", "field[%d] is %s\n", j, segments[j]); | 133 purple_debug_warning("QQ", "field[%d] is %s\n", j, segments[j]); |
131 g_free(segments[j]); | 134 g_free(segments[j]); |
132 } | 135 } |
136 | |
133 segments[expected_fields] = NULL; | 137 segments[expected_fields] = NULL; |
134 } | 138 } |
135 | 139 |
136 return segments; | 140 return segments; |
137 } | 141 } |
191 /* Sample: (1234567)*/ | 195 /* Sample: (1234567)*/ |
192 start = strchr(name, '('); | 196 start = strchr(name, '('); |
193 g_return_val_if_fail(start != NULL, NULL); | 197 g_return_val_if_fail(start != NULL, NULL); |
194 end = strchr(start, ')'); | 198 end = strchr(start, ')'); |
195 g_return_val_if_fail(end != NULL && (end - start) > 1, NULL); | 199 g_return_val_if_fail(end != NULL && (end - start) > 1, NULL); |
196 | 200 |
197 ret = g_strndup(start + 1, end - start - 1); | 201 ret = g_strndup(start + 1, end - start - 1); |
198 | 202 |
199 return ret; | 203 return ret; |
200 } | 204 } |
201 | 205 |