comparison libpurple/protocols/qq/char_conv.c @ 24075:a95c7e71064c

2008.10.05 - ccpaging <ccpagint(at)gmail.com> * Add my uid into buddy list * Fixed a minor bug in qq_create_buddy. Not get new buddy's info. * There are 38 fields in protocol 2008, one more than 2005/2007. * The packet of Modifing buddy info is changed. Need sample to fix it.
author SHiNE CsyFeK <csyfek@gmail.com>
date Wed, 22 Oct 2008 14:48:46 +0000
parents df699d739b8f
children ec3f7d3e0445
comparison
equal deleted inserted replaced
24074:c2253c485728 24075:a95c7e71064c
96 { 96 {
97 return (font_attr & 0x80) ? TRUE : FALSE; 97 return (font_attr & 0x80) ? TRUE : FALSE;
98 } 98 }
99 99
100 /* convert a string from from_charset to to_charset, using g_convert */ 100 /* convert a string from from_charset to to_charset, using g_convert */
101 static gchar *_my_convert(const gchar *str, gssize len, const gchar *to_charset, const gchar *from_charset) 101 static gchar *do_convert(const gchar *str, gssize len, const gchar *to_charset, const gchar *from_charset)
102 { 102 {
103 GError *error = NULL; 103 GError *error = NULL;
104 gchar *ret; 104 gchar *ret;
105 gsize byte_read, byte_write; 105 gsize byte_read, byte_write;
106 106
126 /* 126 /*
127 * take the input as a pascal string and return a converted c-string in UTF-8 127 * take the input as a pascal string and return a converted c-string in UTF-8
128 * returns the number of bytes read, return -1 if fatal error 128 * returns the number of bytes read, return -1 if fatal error
129 * the converted UTF-8 will be saved in ret 129 * the converted UTF-8 will be saved in ret
130 */ 130 */
131 gint convert_as_pascal_string(guint8 *data, gchar **ret, const gchar *from_charset) 131 gint qq_get_vstr(gchar **ret, const gchar *from_charset, guint8 *data)
132 { 132 {
133 guint8 len; 133 guint8 len;
134 134
135 g_return_val_if_fail(data != NULL && from_charset != NULL, -1); 135 g_return_val_if_fail(data != NULL && from_charset != NULL, -1);
136 136
137 len = data[0]; 137 len = data[0];
138 *ret = _my_convert((gchar *) (data + 1), (gssize) len, UTF8, from_charset); 138 if (len == 0) {
139 *ret = g_strdup("");
140 return 1;
141 }
142 *ret = do_convert((gchar *) (data + 1), (gssize) len, UTF8, from_charset);
139 143
140 return len + 1; 144 return len + 1;
141 } 145 }
142 146
143 /* convert QQ formatted msg to Purple formatted msg (and UTF-8) */ 147 /* convert QQ formatted msg to Purple formatted msg (and UTF-8) */
212 g_string_free(encoded, FALSE); 216 g_string_free(encoded, FALSE);
213 217
214 return ret; 218 return ret;
215 } 219 }
216 220
217 /* two convenience methods, using _my_convert */ 221 /* two convenience methods, using do_convert */
218 gchar *utf8_to_qq(const gchar *str, const gchar *to_charset) 222 gchar *utf8_to_qq(const gchar *str, const gchar *to_charset)
219 { 223 {
220 return _my_convert(str, -1, to_charset, UTF8); 224 return do_convert(str, -1, to_charset, UTF8);
221 } 225 }
222 226
223 gchar *qq_to_utf8(const gchar *str, const gchar *from_charset) 227 gchar *qq_to_utf8(const gchar *str, const gchar *from_charset)
224 { 228 {
225 return _my_convert(str, -1, UTF8, from_charset); 229 return do_convert(str, -1, UTF8, from_charset);
226 } 230 }
227 231
228 /* QQ uses binary code for smiley, while purple uses strings. 232 /* QQ uses binary code for smiley, while purple uses strings.
229 * There is a mapping relation between these two. */ 233 * There is a mapping relation between these two. */
230 gchar *qq_smiley_to_purple(gchar *text) 234 gchar *qq_smiley_to_purple(gchar *text)