Mercurial > pidgin.yaz
comparison libpurple/protocols/qq/char_conv.c @ 23052:51dbe83ebbd3
patch-04-tcp-pending
author | SHiNE CsyFeK <csyfek@gmail.com> |
---|---|
date | Tue, 24 Jun 2008 12:22:40 +0000 |
parents | 190bc4ecf6c3 |
children | ebad75b719f5 |
comparison
equal
deleted
inserted
replaced
23051:190bc4ecf6c3 | 23052:51dbe83ebbd3 |
---|---|
36 #define QQ_CHARSET_ZH_CN "GB18030" | 36 #define QQ_CHARSET_ZH_CN "GB18030" |
37 #define QQ_CHARSET_ENG "ISO-8859-1" | 37 #define QQ_CHARSET_ENG "ISO-8859-1" |
38 | 38 |
39 #define QQ_NULL_MSG "(NULL)" /* return this if conversion fails */ | 39 #define QQ_NULL_MSG "(NULL)" /* return this if conversion fails */ |
40 #define QQ_NULL_SMILEY "(SM)" /* return this if smiley conversion fails */ | 40 #define QQ_NULL_SMILEY "(SM)" /* return this if smiley conversion fails */ |
41 | |
42 /* a debug function */ | |
43 void _qq_show_packet(const gchar *desc, const guint8 *buf, gint len); | |
44 | 41 |
45 const gchar qq_smiley_map[QQ_SMILEY_AMOUNT] = { | 42 const gchar qq_smiley_map[QQ_SMILEY_AMOUNT] = { |
46 0x41, 0x43, 0x42, 0x44, 0x45, 0x46, 0x47, 0x48, | 43 0x41, 0x43, 0x42, 0x44, 0x45, 0x46, 0x47, 0x48, |
47 0x49, 0x4a, 0x4b, 0x4c, 0x4d, 0x4e, 0x4f, 0x73, | 44 0x49, 0x4a, 0x4b, 0x4c, 0x4d, 0x4e, 0x4f, 0x73, |
48 0x74, 0x75, 0x76, 0x77, 0x8a, 0x8b, 0x8c, 0x8d, | 45 0x74, 0x75, 0x76, 0x77, 0x8a, 0x8b, 0x8c, 0x8d, |
109 | 106 |
110 g_return_val_if_fail(str != NULL && to_charset != NULL && from_charset != NULL, g_strdup(QQ_NULL_MSG)); | 107 g_return_val_if_fail(str != NULL && to_charset != NULL && from_charset != NULL, g_strdup(QQ_NULL_MSG)); |
111 | 108 |
112 ret = g_convert(str, len, to_charset, from_charset, &byte_read, &byte_write, &error); | 109 ret = g_convert(str, len, to_charset, from_charset, &byte_read, &byte_write, &error); |
113 | 110 |
114 if (error == NULL) | 111 if (error == NULL) { |
115 return ret; /* conversion is OK */ | 112 return ret; /* conversion is OK */ |
116 else { /* conversion error */ | 113 } |
117 purple_debug(PURPLE_DEBUG_ERROR, "QQ", "%s\n", error->message); | 114 |
118 | 115 /* conversion error */ |
119 qq_hex_dump(PURPLE_DEBUG_WARNING, "QQ", | 116 purple_debug(PURPLE_DEBUG_ERROR, "QQ", "%s\n", error->message); |
120 (guint8 *) str, (len == -1) ? strlen(str) : len, | 117 |
121 "Dump failed text"); | 118 qq_hex_dump(PURPLE_DEBUG_WARNING, "QQ", |
122 | 119 (guint8 *) str, (len == -1) ? strlen(str) : len, |
123 g_error_free(error); | 120 "Dump failed text"); |
124 return g_strdup(QQ_NULL_MSG); | 121 |
125 } | 122 g_error_free(error); |
123 return g_strdup(QQ_NULL_MSG); | |
126 } | 124 } |
127 | 125 |
128 /* take the input as a pascal string and return a converted c-string in UTF-8 | 126 /* take the input as a pascal string and return a converted c-string in UTF-8 |
129 * returns the number of bytes read, return -1 if fatal error | 127 * returns the number of bytes read, return -1 if fatal error |
130 * the converted UTF-8 will be saved in ret */ | 128 * the converted UTF-8 will be saved in ret */ |
148 gboolean is_bold, is_italic, is_underline; | 146 gboolean is_bold, is_italic, is_underline; |
149 guint16 charset_code; | 147 guint16 charset_code; |
150 gchar *font_name, *color_code, *msg_utf8, *tmp, *ret; | 148 gchar *font_name, *color_code, *msg_utf8, *tmp, *ret; |
151 gint bytes = 0; | 149 gint bytes = 0; |
152 | 150 |
153 /* checked _qq_show_packet OK */ | 151 /* checked qq_show_packet OK */ |
154 _qq_show_packet("QQ_MESG recv for font style", data, len); | 152 qq_show_packet("QQ_MESG recv for font style", data, len); |
155 | 153 |
156 bytes += qq_get8(&font_attr, data + bytes); | 154 bytes += qq_get8(&font_attr, data + bytes); |
157 bytes += qq_getdata(color, 3, data + bytes); /* red,green,blue */ | 155 bytes += qq_getdata(color, 3, data + bytes); /* red,green,blue */ |
158 color_code = g_strdup_printf("#%02x%02x%02x", color[0], color[1], color[2]); | 156 color_code = g_strdup_printf("#%02x%02x%02x", color[0], color[1], color[2]); |
159 | 157 |