| 1 /** |
|
| 2 * @file im.c |
|
| 3 * |
|
| 4 * purple |
|
| 5 * |
|
| 6 * Purple is the legal property of its developers, whose names are too numerous |
|
| 7 * to list here. Please refer to the COPYRIGHT file distributed with this |
|
| 8 * source distribution. |
|
| 9 * |
|
| 10 * This program is free software; you can redistribute it and/or modify |
|
| 11 * it under the terms of the GNU General Public License as published by |
|
| 12 * the Free Software Foundation; either version 2 of the License, or |
|
| 13 * (at your option) any later version. |
|
| 14 * |
|
| 15 * This program is distributed in the hope that it will be useful, |
|
| 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
| 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
| 18 * GNU General Public License for more details. |
|
| 19 * |
|
| 20 * You should have received a copy of the GNU General Public License |
|
| 21 * along with this program; if not, write to the Free Software |
|
| 22 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA |
|
| 23 */ |
|
| 24 |
|
| 25 #include "internal.h" |
|
| 26 |
|
| 27 #include "conversation.h" |
|
| 28 #include "debug.h" |
|
| 29 #include "internal.h" |
|
| 30 #include "notify.h" |
|
| 31 #include "server.h" |
|
| 32 #include "util.h" |
|
| 33 |
|
| 34 #include "buddy_info.h" |
|
| 35 #include "buddy_list.h" |
|
| 36 #include "buddy_opt.h" |
|
| 37 #include "char_conv.h" |
|
| 38 #include "qq_define.h" |
|
| 39 #include "im.h" |
|
| 40 #include "packet_parse.h" |
|
| 41 #include "qq_network.h" |
|
| 42 #include "send_file.h" |
|
| 43 #include "utils.h" |
|
| 44 |
|
| 45 #define QQ_MSG_IM_MAX 700 /* max length of IM */ |
|
| 46 |
|
| 47 enum { |
|
| 48 QQ_IM_TEXT = 0x01, |
|
| 49 QQ_IM_AUTO_REPLY = 0x02 |
|
| 50 }; |
|
| 51 |
|
| 52 enum |
|
| 53 { |
|
| 54 QQ_NORMAL_IM_TEXT = 0x000b, |
|
| 55 QQ_NORMAL_IM_FILE_REQUEST_TCP = 0x0001, |
|
| 56 QQ_NORMAL_IM_FILE_APPROVE_TCP = 0x0003, |
|
| 57 QQ_NORMAL_IM_FILE_REJECT_TCP = 0x0005, |
|
| 58 QQ_NORMAL_IM_FILE_REQUEST_UDP = 0x0035, |
|
| 59 QQ_NORMAL_IM_FILE_APPROVE_UDP = 0x0037, |
|
| 60 QQ_NORMAL_IM_FILE_REJECT_UDP = 0x0039, |
|
| 61 QQ_NORMAL_IM_FILE_NOTIFY = 0x003b, |
|
| 62 QQ_NORMAL_IM_FILE_PASV = 0x003f, /* are you behind a firewall? */ |
|
| 63 QQ_NORMAL_IM_FILE_CANCEL = 0x0049, |
|
| 64 QQ_NORMAL_IM_FILE_EX_REQUEST_UDP = 0x81, |
|
| 65 QQ_NORMAL_IM_FILE_EX_REQUEST_ACCEPT = 0x83, |
|
| 66 QQ_NORMAL_IM_FILE_EX_REQUEST_CANCEL = 0x85, |
|
| 67 QQ_NORMAL_IM_FILE_EX_NOTIFY_IP = 0x87 |
|
| 68 }; |
|
| 69 |
|
| 70 typedef struct _qq_im_header qq_im_header; |
|
| 71 struct _qq_im_header { |
|
| 72 /* this is the common part of normal_text */ |
|
| 73 guint16 version_from; |
|
| 74 guint32 uid_from; |
|
| 75 guint32 uid_to; |
|
| 76 guint8 session_md5[QQ_KEY_LENGTH]; |
|
| 77 guint16 im_type; |
|
| 78 }; |
|
| 79 |
|
| 80 /* read the common parts of the normal_im, |
|
| 81 * returns the bytes read if succeed, or -1 if there is any error */ |
|
| 82 static gint get_im_header(qq_im_header *im_header, guint8 *data, gint len) |
|
| 83 { |
|
| 84 gint bytes; |
|
| 85 g_return_val_if_fail(data != NULL && len > 0, -1); |
|
| 86 |
|
| 87 bytes = 0; |
|
| 88 bytes += qq_get16(&(im_header->version_from), data + bytes); |
|
| 89 bytes += qq_get32(&(im_header->uid_from), data + bytes); |
|
| 90 bytes += qq_get32(&(im_header->uid_to), data + bytes); |
|
| 91 bytes += qq_getdata(im_header->session_md5, QQ_KEY_LENGTH, data + bytes); |
|
| 92 bytes += qq_get16(&(im_header->im_type), data + bytes); |
|
| 93 return bytes; |
|
| 94 } |
|
| 95 |
|
| 96 typedef struct _qq_emoticon qq_emoticon; |
|
| 97 struct _qq_emoticon { |
|
| 98 guint8 symbol; |
|
| 99 gchar *name; |
|
| 100 }; |
|
| 101 |
|
| 102 static gboolean emoticons_is_sorted = FALSE; |
|
| 103 /* Map for purple smiley convert to qq, need qsort */ |
|
| 104 static qq_emoticon emoticons_std[] = { |
|
| 105 {0x4f, "/:)"}, {0x4f, "/wx"}, {0x4f, "/small_smile"}, |
|
| 106 {0x42, "/:~"}, {0x42, "/pz"}, {0x42, "/curl_lip"}, |
|
| 107 {0x43, "/:*"}, {0x43, "/se"}, {0x43, "/desire"}, |
|
| 108 {0x44, "/:|"}, {0x44, "/fd"}, {0x44, "/dazed"}, |
|
| 109 {0x45, "/8-)"}, {0x45, "/dy"}, {0x45, "/revel"}, |
|
| 110 {0x46, "/:<"}, {0x46, "/ll"}, {0x46, "/cry"}, |
|
| 111 {0x47, "/:$"}, {0x47, "/hx"}, {0x47, "/bashful"}, |
|
| 112 {0x48, "/:x"}, {0x48, "/bz"}, {0x48, "/shut_mouth"}, |
|
| 113 {0x8f, "/|-)"}, {0x8f, "/kun"}, {0x8f, "/sleepy"}, |
|
| 114 {0x49, "/:z"}, {0x49, "/shui"}, {0x49, "/sleep"}, /* after sleepy */ |
|
| 115 {0x4a, "/:'"}, {0x4a, "/dk"}, {0x4a, "/weep"}, |
|
| 116 {0x4b, "/:-|"}, {0x4b, "/gg"}, {0x4b, "/embarassed"}, |
|
| 117 {0x4c, "/:@"}, {0x4c, "/fn"}, {0x4c, "/pissed_off"}, |
|
| 118 {0x4d, "/:P"}, {0x4d, "/tp"}, {0x4d, "/act_up"}, |
|
| 119 {0x4e, "/:D"}, {0x4e, "/cy"}, {0x4e, "/toothy_smile"}, |
|
| 120 {0x41, "/:O"}, {0x41, "/jy"}, {0x41, "/surprised"}, |
|
| 121 {0x73, "/:("}, {0x73, "/ng"}, {0x73, "/sad"}, |
|
| 122 {0x74, "/:+"}, {0x74, "/kuk"}, {0x74, "/cool"}, |
|
| 123 {0xa1, "/--b"}, {0xa1, "/lengh"}, |
|
| 124 {0x76, "/:Q"}, {0x76, "/zk"}, {0x76, "/crazy"}, |
|
| 125 {0x8a, "/;P"}, {0x8a, "/tx"}, {0x8a, "/titter"}, |
|
| 126 {0x8b, "/;-D"}, {0x8b, "/ka"}, {0x8b, "/cute"}, |
|
| 127 {0x8c, "/;d"}, {0x8c, "/by"}, {0x8c, "/disdain"}, |
|
| 128 {0x8d, "/;o"}, {0x8d, "/am"}, {0x8d, "/arrogant"}, |
|
| 129 {0x8e, "/:g"}, {0x8e, "/jie"}, {0x8e, "/starving"}, |
|
| 130 {0x78, "/:!"}, {0x78, "/jk"}, {0x78, "/terror"}, |
|
| 131 {0x79, "/:L"}, {0x79, "/lh"}, {0x79, "/sweat"}, |
|
| 132 {0x7a, "/:>"}, {0x7a, "/hanx"}, {0x7a, "/smirk"}, |
|
| 133 {0x7b, "/:;"}, {0x7b, "/db"}, {0x7b, "/soldier"}, |
|
| 134 {0x90, "/;f"}, {0x90, "/fendou"}, {0x90, "/struggle"}, |
|
| 135 {0x91, "/:-S"}, {0x91, "/zhm"}, {0x91, "/curse"}, |
|
| 136 {0x92, "/?"}, {0x92, "/yiw"}, {0x92, "/question"}, |
|
| 137 {0x93, "/;x"}, {0x93, "/xu"}, {0x93, "/shh"}, |
|
| 138 {0x94, "/;@"}, {0x94, "/yun"}, {0x94, "/dizzy"}, |
|
| 139 {0x95, "/:8"}, {0x95, "/zhem"}, {0x95, "/excrutiating"}, |
|
| 140 {0x96, "/;!"}, {0x96, "/shuai"}, {0x96, "/freaked_out"}, |
|
| 141 {0x97, "/!!!"}, {0x97, "/kl"}, {0x97, "/skeleton"}, |
|
| 142 {0x98, "/xx"}, {0x98, "/qiao"}, {0x98, "/hammer"}, |
|
| 143 {0x99, "/bye"}, {0x99, "/zj"}, {0x99, "/bye"}, |
|
| 144 {0xa2, "/wipe"}, {0xa2, "/ch"}, |
|
| 145 {0xa3, "/dig"}, {0xa3, "/kb"}, |
|
| 146 {0xa4, "/handclap"},{0xa4, "/gz"}, |
|
| 147 {0xa5, "/&-("}, {0xa5, "/qd"}, |
|
| 148 {0xa6, "/B-)"}, {0xa6, "/huaix"}, |
|
| 149 {0xa7, "/<@"}, {0xa7, "/zhh"}, |
|
| 150 {0xa8, "/@>"}, {0xa8, "/yhh"}, |
|
| 151 {0xa9, "/:-O"}, {0xa9, "/hq"}, |
|
| 152 {0xaa, "/>-|"}, {0xaa, "/bs"}, |
|
| 153 {0xab, "/P-("}, {0xab, "/wq"}, |
|
| 154 {0xac, "/:'|"}, {0xac, "/kk"}, |
|
| 155 {0xad, "/X-)"}, {0xad, "/yx"}, |
|
| 156 {0xae, "/:*"}, {0xae, "/qq"}, |
|
| 157 {0xaf, "/@x"}, {0xaf, "/xia"}, |
|
| 158 {0xb0, "/8*"}, {0xb0, "/kel"}, |
|
| 159 {0xb1, "/pd"}, {0xb1, "/cd"}, |
|
| 160 {0x61, "/<W>"}, {0x61, "/xig"}, {0x61, "/watermelon"}, |
|
| 161 {0xb2, "/beer"}, {0xb2, "/pj"}, |
|
| 162 {0xb3, "/basketb"}, {0xb3, "/lq"}, |
|
| 163 {0xb4, "/oo"}, {0xb4, "/pp"}, |
|
| 164 {0x80, "/coffee"}, {0x80, "/kf"}, |
|
| 165 {0x81, "/eat"}, {0x81, "/fan"}, |
|
| 166 {0x62, "/rose"}, {0x62, "/mg"}, |
|
| 167 {0x63, "/fade"}, {0x63, "/dx"}, {0x63, "/wilt"}, |
|
| 168 {0xb5, "/showlove"},{0xb5, "/sa"}, /* after sad */ |
|
| 169 {0x65, "/heart"}, {0x65, "/xin"}, |
|
| 170 {0x66, "/break"}, {0x66, "/xs"}, {0x66, "/broken_heart"}, |
|
| 171 {0x67, "/cake"}, {0x67, "/dg"}, |
|
| 172 {0x9c, "/li"}, {0x9c, "/shd"}, {0x9c, "/lightning"}, |
|
| 173 {0x9d, "/bome"}, {0x9d, "/zhd"}, {0x9d, "/bomb"}, |
|
| 174 {0x9e, "/kn"}, {0x9e, "/dao"}, {0x9e, "/knife"}, |
|
| 175 {0x5e, "/footb"}, {0x5e, "/zq"}, {0x5e, "/soccer"}, |
|
| 176 {0xb6, "/ladybug"}, {0xb6, "/pc"}, |
|
| 177 {0x89, "/shit"}, {0x89, "/bb"}, |
|
| 178 {0x6e, "/moon"}, {0x6e, "/yl"}, |
|
| 179 {0x6b, "/sun"}, {0x6b, "/ty"}, |
|
| 180 {0x68, "/gift"}, {0x68, "/lw"}, |
|
| 181 {0x7f, "/hug"}, {0x7f, "/yb"}, |
|
| 182 {0x6f, "/strong"}, {0x6f, "/qiang"}, {0x6f, "/thumbs_up"}, |
|
| 183 {0x70, "/weak"}, {0x70, "/ruo"}, {0x70, "/thumbs_down"}, |
|
| 184 {0x88, "/share"}, {0x88, "/ws"}, {0x88, "/handshake"}, |
|
| 185 {0xb7, "/@)"}, {0xb7, "/bq"}, |
|
| 186 {0xb8, "/jj"}, {0xb8, "/gy"}, |
|
| 187 {0xb9, "/@@"}, {0xb9, "/qt"}, |
|
| 188 {0xba, "/bad"}, {0xba, "/cj"}, |
|
| 189 {0xbb, "/loveu"}, {0xbb, "/aini"}, |
|
| 190 {0xbc, "/no"}, {0xbc, "/bu"}, |
|
| 191 {0xbd, "/ok"}, {0xbd, "/hd"}, |
|
| 192 {0x5c, "/love"}, {0x5c, "/aiq"}, /* after loveu */ |
|
| 193 {0x56, "/<L>"}, {0x56, "/fw"}, {0x56, "/blow_kiss"}, |
|
| 194 {0x58, "/jump"}, {0x58, "/tiao"}, |
|
| 195 {0x5a, "/shake"}, {0x5a, "/fad"}, /* after fade */ |
|
| 196 {0x5b, "/<O>"}, {0x5b, "/oh"}, {0x5b, "/angry"}, |
|
| 197 {0xbe, "/circle"}, {0xbe, "/zhq"}, |
|
| 198 {0xbf, "/kotow"}, {0xbf, "/kt"}, |
|
| 199 {0xc0, "/turn"}, {0xc0, "/ht"}, |
|
| 200 {0x77, "/:t"}, {0x77, "/tu"}, {0x77, "/vomit"}, /* after turn */ |
|
| 201 {0xa0, "/victory"}, {0xa0, "/shl"}, {0xa0, "/v"}, /* end of v */ |
|
| 202 {0xc1, "/skip"}, {0xc1, "/tsh"}, |
|
| 203 {0xc2, "/oY"}, {0xc2, "/hsh"}, |
|
| 204 {0xc3, "/#-O"}, {0xc3, "/jd"}, |
|
| 205 {0xc4, "/hiphop"}, {0xc4, "/jw"}, |
|
| 206 {0xc5, "/kiss"}, {0xc5, "/xw"}, |
|
| 207 {0xc6, "/<&"}, {0xc6, "/ztj"}, |
|
| 208 {0x7c, "/pig"}, {0x7c, "/zt"}, /* after ztj */ |
|
| 209 {0xc7, "/&>"}, {0xc7, "/ytj"}, /* must be end of "&" */ |
|
| 210 {0x75, "/:#"}, {0x75, "/feid"}, {0x75, "/SARS"}, |
|
| 211 {0x59, "/go"}, {0x59, "/shan"}, |
|
| 212 {0x57, "/find"}, {0x57, "/zhao"}, {0x57, "/search"}, |
|
| 213 {0x55, "/&"}, {0x55, "/mm"}, {0x55, "/beautiful_eyebrows"}, |
|
| 214 {0x7d, "/cat"}, {0x7d, "/maom"}, |
|
| 215 {0x7e, "/dog"}, {0x7e, "/xg"}, |
|
| 216 {0x9a, "/$"}, {0x9a, "/qianc"}, {0x9a, "/money"}, |
|
| 217 {0x9b, "/(!)"}, {0x9b, "/dp"}, {0x9b, "/lightbulb"}, |
|
| 218 {0x60, "/cup"}, {0x60, "/bei"}, |
|
| 219 {0x9f, "/music"}, {0x9f, "/yy"}, |
|
| 220 {0x82, "/pill"}, {0x82, "/yw"}, |
|
| 221 {0x64, "/kiss"}, {0x64, "/wen"}, |
|
| 222 {0x83, "/meeting"}, {0x83, "/hy"}, |
|
| 223 {0x84, "/phone"}, {0x84, "/dh"}, |
|
| 224 {0x85, "/time"}, {0x85, "/sj"}, |
|
| 225 {0x86, "/email"}, {0x86, "/yj"}, |
|
| 226 {0x87, "/tv"}, {0x87, "/ds"}, |
|
| 227 {0x50, "/<D>"}, {0x50, "/dd"}, |
|
| 228 {0x51, "/<J>"}, {0x51, "/mn"}, {0x51, "/beauty"}, |
|
| 229 {0x52, "/<H>"}, {0x52, "/hl"}, |
|
| 230 {0x53, "/<M>"}, {0x53, "/mamao"}, |
|
| 231 {0x54, "/<QQ>"}, {0x54, "/qz"}, {0x54, "/qq"}, |
|
| 232 {0x5d, "/<B>"}, {0x5d, "/bj"}, {0x5d, "/baijiu"}, |
|
| 233 {0x5f, "/<U>"}, {0x5f, "/qsh"}, {0x5f, "/soda"}, |
|
| 234 {0x69, "/<!!>"}, {0x69, "/xy"}, {0x69, "/rain"}, |
|
| 235 {0x6a, "/<~>"}, {0x6a, "/duoy"}, {0x6a, "/cloudy"}, |
|
| 236 {0x6c, "/<Z>"}, {0x6c, "/xr"}, {0x6c, "/snowman"}, |
|
| 237 {0x6d, "/<*>"}, {0x6d, "/xixing"}, {0x6d, "/star"}, /* after starving */ |
|
| 238 {0x71, "/<00>"}, {0x71, "/nv"}, {0x71, "/woman"}, |
|
| 239 {0x72, "/<11>"}, {0x72, "/nan"}, {0x72, "/man"}, |
|
| 240 {0, NULL} |
|
| 241 }; |
|
| 242 gint emoticons_std_num = sizeof(emoticons_std) / sizeof(qq_emoticon) - 1; |
|
| 243 |
|
| 244 /* Map for purple smiley convert to qq, need qsort */ |
|
| 245 static qq_emoticon emoticons_ext[] = { |
|
| 246 {0xc7, "/&>"}, {0xa5, "/&-("}, |
|
| 247 {0xbb, "/loveu"}, |
|
| 248 {0x63, "/fade"}, |
|
| 249 {0x8f, "/sleepy"}, {0x73, "/sad"}, {0x8e, "/starving"}, |
|
| 250 {0xc0, "/turn"}, |
|
| 251 {0xa0, "/victory"}, {0x77, "/vomit"}, |
|
| 252 {0xc6, "/ztj"}, |
|
| 253 {0, NULL} |
|
| 254 }; |
|
| 255 gint emoticons_ext_num = sizeof(emoticons_ext) / sizeof(qq_emoticon) - 1; |
|
| 256 |
|
| 257 /* Map for qq smiley convert to purple */ |
|
| 258 static qq_emoticon emoticons_sym[] = { |
|
| 259 {0x41, "/jy"}, |
|
| 260 {0x42, "/pz"}, |
|
| 261 {0x43, "/se"}, |
|
| 262 {0x44, "/fd"}, |
|
| 263 {0x45, "/dy"}, |
|
| 264 {0x46, "/ll"}, |
|
| 265 {0x47, "/hx"}, |
|
| 266 {0x48, "/bz"}, |
|
| 267 {0x49, "/shui"}, |
|
| 268 {0x4a, "/dk"}, |
|
| 269 {0x4b, "/gg"}, |
|
| 270 {0x4c, "/fn"}, |
|
| 271 {0x4d, "/tp"}, |
|
| 272 {0x4e, "/cy"}, |
|
| 273 {0x4f, "/wx"}, |
|
| 274 {0x50, "/dd"}, |
|
| 275 {0x51, "/mn"}, |
|
| 276 {0x52, "/hl"}, |
|
| 277 {0x53, "/mamao"}, |
|
| 278 {0x54, "/qz"}, |
|
| 279 {0x55, "/mm"}, |
|
| 280 {0x56, "/fw"}, |
|
| 281 {0x57, "/zhao"}, |
|
| 282 {0x58, "/tiao"}, |
|
| 283 {0x59, "/shan"}, |
|
| 284 {0x5a, "/fad"}, |
|
| 285 {0x5b, "/oh"}, |
|
| 286 {0x5c, "/aiq"}, |
|
| 287 {0x5d, "/bj"}, |
|
| 288 {0x5e, "/zq"}, |
|
| 289 {0x5f, "/qsh"}, |
|
| 290 {0x60, "/bei"}, |
|
| 291 {0x61, "/xig"}, |
|
| 292 {0x62, "/mg"}, |
|
| 293 {0x63, "/dx"}, |
|
| 294 {0x64, "/wen"}, |
|
| 295 {0x65, "/xin"}, |
|
| 296 {0x66, "/xs"}, |
|
| 297 {0x67, "/dg"}, |
|
| 298 {0x68, "/lw"}, |
|
| 299 {0x69, "/xy"}, |
|
| 300 {0x6a, "/duoy"}, |
|
| 301 {0x6b, "/ty"}, |
|
| 302 {0x6c, "/xr"}, |
|
| 303 {0x6d, "/xixing"}, |
|
| 304 {0x6e, "/yl"}, |
|
| 305 {0x6f, "/qiang"}, |
|
| 306 {0x70, "/ruo"}, |
|
| 307 {0x71, "/nv"}, |
|
| 308 {0x72, "/nan"}, |
|
| 309 {0x73, "/ng"}, |
|
| 310 {0x74, "/kuk"}, |
|
| 311 {0x75, "/feid"}, |
|
| 312 {0x76, "/zk"}, |
|
| 313 {0x77, "/tu"}, |
|
| 314 {0x78, "/jk"}, |
|
| 315 {0x79, "/sweat"}, |
|
| 316 {0x7a, "/hanx"}, |
|
| 317 {0x7b, "/db"}, |
|
| 318 {0x7c, "/zt"}, |
|
| 319 {0x7d, "/maom"}, |
|
| 320 {0x7e, "/xg"}, |
|
| 321 {0x7f, "/yb"}, |
|
| 322 {0x80, "/coffee"}, |
|
| 323 {0x81, "/fan"}, |
|
| 324 {0x82, "/yw"}, |
|
| 325 {0x83, "/hy"}, |
|
| 326 {0x84, "/dh"}, |
|
| 327 {0x85, "/sj"}, |
|
| 328 {0x86, "/yj"}, |
|
| 329 {0x87, "/ds"}, |
|
| 330 {0x88, "/ws"}, |
|
| 331 {0x89, "/bb"}, |
|
| 332 {0x8a, "/tx"}, |
|
| 333 {0x8b, "/ka"}, |
|
| 334 {0x8c, "/by"}, |
|
| 335 {0x8d, "/am"}, |
|
| 336 {0x8e, "/jie"}, |
|
| 337 {0x8f, "/kun"}, |
|
| 338 {0x90, "/fendou"}, |
|
| 339 {0x91, "/zhm"}, |
|
| 340 {0x92, "/yiw"}, |
|
| 341 {0x93, "/xu"}, |
|
| 342 {0x94, "/yun"}, |
|
| 343 {0x95, "/zhem"}, |
|
| 344 {0x96, "/shuai"}, |
|
| 345 {0x97, "/kl"}, |
|
| 346 {0x98, "/qiao"}, |
|
| 347 {0x99, "/zj"}, |
|
| 348 {0x9a, "/qianc"}, |
|
| 349 {0x9b, "/dp"}, |
|
| 350 {0x9c, "/shd"}, |
|
| 351 {0x9d, "/zhd"}, |
|
| 352 {0x9e, "/dao"}, |
|
| 353 {0x9f, "/yy"}, |
|
| 354 {0xa0, "/shl"}, |
|
| 355 {0xa1, "/lengh"}, |
|
| 356 {0xa2, "/wipe"}, |
|
| 357 {0xa3, "/kb"}, |
|
| 358 {0xa4, "/gz"}, |
|
| 359 {0xa5, "/qd"}, |
|
| 360 {0xa6, "/huaix"}, |
|
| 361 {0xa7, "/zhh"}, |
|
| 362 {0xa8, "/yhh"}, |
|
| 363 {0xa9, "/hq"}, |
|
| 364 {0xaa, "/bs"}, |
|
| 365 {0xab, "/wq"}, |
|
| 366 {0xac, "/kk"}, |
|
| 367 {0xad, "/yx"}, |
|
| 368 {0xae, "/qq"}, |
|
| 369 {0xaf, "/xia"}, |
|
| 370 {0xb0, "/kel"}, |
|
| 371 {0xb1, "/cd"}, |
|
| 372 {0xb2, "/pj"}, |
|
| 373 {0xb3, "/lq"}, |
|
| 374 {0xb4, "/pp"}, |
|
| 375 {0xb5, "/sa"}, |
|
| 376 {0xb6, "/pc"}, |
|
| 377 {0xb7, "/bq"}, |
|
| 378 {0xb8, "/gy"}, |
|
| 379 {0xb9, "/qt"}, |
|
| 380 {0xba, "/cj"}, |
|
| 381 {0xbb, "/aini"}, |
|
| 382 {0xbc, "/bu"}, |
|
| 383 {0xbd, "/hd"}, |
|
| 384 {0xbe, "/zhq"}, |
|
| 385 {0xbf, "/kt"}, |
|
| 386 {0xc0, "/ht"}, |
|
| 387 {0xc1, "/tsh"}, |
|
| 388 {0xc2, "/hsh"}, |
|
| 389 {0xc3, "/jd"}, |
|
| 390 {0xc4, "/jw"}, |
|
| 391 {0xc5, "/xw"}, |
|
| 392 {0xc6, "/ztj"}, |
|
| 393 {0xc7, "/ytj"}, |
|
| 394 {0, NULL} |
|
| 395 }; |
|
| 396 gint emoticons_sym_num = sizeof(emoticons_sym) / sizeof(qq_emoticon) - 1;; |
|
| 397 |
|
| 398 static int emoticon_cmp(const void *k1, const void *k2) |
|
| 399 { |
|
| 400 const qq_emoticon *e1 = (const qq_emoticon *) k1; |
|
| 401 const qq_emoticon *e2 = (const qq_emoticon *) k2; |
|
| 402 if (e1->symbol == 0) { |
|
| 403 /* purple_debug_info("QQ", "emoticon_cmp len %d\n", strlen(e2->name)); */ |
|
| 404 return strncmp(e1->name, e2->name, strlen(e2->name)); |
|
| 405 } |
|
| 406 if (e2->symbol == 0) { |
|
| 407 /* purple_debug_info("QQ", "emoticon_cmp len %d\n", strlen(e1->name)); */ |
|
| 408 return strncmp(e1->name, e2->name, strlen(e1->name)); |
|
| 409 } |
|
| 410 return strcmp(e1->name, e2->name); |
|
| 411 } |
|
| 412 |
|
| 413 static void emoticon_try_sort() |
|
| 414 { |
|
| 415 if (emoticons_is_sorted) |
|
| 416 return; |
|
| 417 |
|
| 418 purple_debug_info("QQ", "qsort stand emoticons\n"); |
|
| 419 qsort(emoticons_std, emoticons_std_num, sizeof(qq_emoticon), emoticon_cmp); |
|
| 420 purple_debug_info("QQ", "qsort extend emoticons\n"); |
|
| 421 qsort(emoticons_ext, emoticons_ext_num, sizeof(qq_emoticon), emoticon_cmp); |
|
| 422 emoticons_is_sorted = TRUE; |
|
| 423 } |
|
| 424 |
|
| 425 static qq_emoticon *emoticon_find(gchar *name) |
|
| 426 { |
|
| 427 qq_emoticon *ret = NULL; |
|
| 428 qq_emoticon key; |
|
| 429 |
|
| 430 g_return_val_if_fail(name != NULL, NULL); |
|
| 431 emoticon_try_sort(); |
|
| 432 |
|
| 433 key.name = name; |
|
| 434 key.symbol = 0; |
|
| 435 |
|
| 436 /* purple_debug_info("QQ", "bsearch emoticon %.20s\n", name); */ |
|
| 437 ret = (qq_emoticon *)bsearch(&key, emoticons_ext, emoticons_ext_num, |
|
| 438 sizeof(qq_emoticon), emoticon_cmp); |
|
| 439 if (ret != NULL) { |
|
| 440 return ret; |
|
| 441 } |
|
| 442 ret = (qq_emoticon *)bsearch(&key, emoticons_std, emoticons_std_num, |
|
| 443 sizeof(qq_emoticon), emoticon_cmp); |
|
| 444 return ret; |
|
| 445 } |
|
| 446 |
|
| 447 static gchar *emoticon_get(guint8 symbol) |
|
| 448 { |
|
| 449 g_return_val_if_fail(symbol >= emoticons_sym[0].symbol, NULL); |
|
| 450 g_return_val_if_fail(symbol <= emoticons_sym[emoticons_sym_num - 2].symbol, NULL); |
|
| 451 |
|
| 452 return emoticons_sym[symbol - emoticons_sym[0].symbol].name; |
|
| 453 } |
|
| 454 |
|
| 455 /* convert qq emote icon to purple sytle |
|
| 456 Notice: text is in qq charset, GB18030 or utf8 */ |
|
| 457 gchar *qq_emoticon_to_purple(gchar *text) |
|
| 458 { |
|
| 459 gchar *ret; |
|
| 460 GString *converted; |
|
| 461 gchar **segments; |
|
| 462 gboolean have_smiley; |
|
| 463 gchar *purple_smiley; |
|
| 464 gchar *cur; |
|
| 465 guint8 symbol; |
|
| 466 |
|
| 467 /* qq_show_packet("text", (guint8 *)text, strlen(text)); */ |
|
| 468 g_return_val_if_fail(text != NULL && strlen(text) != 0, g_strdup("")); |
|
| 469 |
|
| 470 while ((cur = strchr(text, '\x14')) != NULL) |
|
| 471 *cur = '\x15'; |
|
| 472 |
|
| 473 segments = g_strsplit(text, "\x15", 0); |
|
| 474 if(segments == NULL) { |
|
| 475 return g_strdup(""); |
|
| 476 } |
|
| 477 |
|
| 478 converted = g_string_new(""); |
|
| 479 have_smiley = FALSE; |
|
| 480 if (segments[0] != NULL) { |
|
| 481 g_string_append(converted, segments[0]); |
|
| 482 } else { |
|
| 483 purple_debug_info("QQ", "segments[0] is NULL\n"); |
|
| 484 } |
|
| 485 while ((*(++segments)) != NULL) { |
|
| 486 have_smiley = TRUE; |
|
| 487 |
|
| 488 cur = *segments; |
|
| 489 if (cur == NULL) { |
|
| 490 purple_debug_info("QQ", "current segment is NULL\n"); |
|
| 491 break; |
|
| 492 } |
|
| 493 if (strlen(cur) == 0) { |
|
| 494 purple_debug_info("QQ", "current segment length is 0\n"); |
|
| 495 break; |
|
| 496 } |
|
| 497 symbol = (guint8)cur[0]; |
|
| 498 |
|
| 499 purple_smiley = emoticon_get(symbol); |
|
| 500 if (purple_smiley == NULL) { |
|
| 501 purple_debug_info("QQ", "Not found smiley of 0x%02X\n", symbol); |
|
| 502 g_string_append(converted, "<IMG ID=\"0\">"); |
|
| 503 } else { |
|
| 504 purple_debug_info("QQ", "Found 0x%02X smiley is %s\n", symbol, purple_smiley); |
|
| 505 g_string_append(converted, purple_smiley); |
|
| 506 g_string_append(converted, cur + 1); |
|
| 507 } |
|
| 508 /* purple_debug_info("QQ", "next segment\n"); */ |
|
| 509 } |
|
| 510 |
|
| 511 /* purple_debug_info("QQ", "end of convert\n"); */ |
|
| 512 if (!have_smiley) { |
|
| 513 g_string_prepend(converted, "<font sml=\"none\">"); |
|
| 514 g_string_append(converted, "</font>"); |
|
| 515 } |
|
| 516 ret = converted->str; |
|
| 517 g_string_free(converted, FALSE); |
|
| 518 return ret; |
|
| 519 } |
|
| 520 |
|
| 521 void qq_im_fmt_free(qq_im_format *fmt) |
|
| 522 { |
|
| 523 g_return_if_fail(fmt != NULL); |
|
| 524 if (fmt->font) g_free(fmt->font); |
|
| 525 g_free(fmt); |
|
| 526 } |
|
| 527 |
|
| 528 qq_im_format *qq_im_fmt_new(void) |
|
| 529 { |
|
| 530 qq_im_format *fmt; |
|
| 531 const gchar simsun[] = { 0xcb, 0xce, 0xcc, 0xe5, 0}; /* simsun in Chinese */ |
|
| 532 |
|
| 533 fmt = g_new0(qq_im_format, 1); |
|
| 534 memset(fmt, 0, sizeof(qq_im_format)); |
|
| 535 fmt->font_len = strlen(simsun); |
|
| 536 fmt->font = g_strdup(simsun); |
|
| 537 fmt->attr = 10; |
|
| 538 /* encoding, 0x8602=GB, 0x0000=EN, define BIG5 support here */ |
|
| 539 fmt->charset = 0x8602; |
|
| 540 |
|
| 541 return fmt; |
|
| 542 } |
|
| 543 |
|
| 544 qq_im_format *qq_im_fmt_new_by_purple(const gchar *msg) |
|
| 545 { |
|
| 546 qq_im_format *fmt; |
|
| 547 const gchar *start, *end, *last; |
|
| 548 GData *attribs; |
|
| 549 gchar *tmp; |
|
| 550 unsigned char *rgb; |
|
| 551 |
|
| 552 g_return_val_if_fail(msg != NULL, NULL); |
|
| 553 |
|
| 554 fmt = qq_im_fmt_new(); |
|
| 555 |
|
| 556 last = msg; |
|
| 557 while (purple_markup_find_tag("font", last, &start, &end, &attribs)) { |
|
| 558 tmp = g_datalist_get_data(&attribs, "face"); |
|
| 559 if (tmp && strlen(tmp) > 0) { |
|
| 560 if (fmt->font) g_free(fmt->font); |
|
| 561 fmt->font_len = strlen(tmp); |
|
| 562 fmt->font = g_strdup(tmp); |
|
| 563 } |
|
| 564 |
|
| 565 tmp = g_datalist_get_data(&attribs, "size"); |
|
| 566 if (tmp) { |
|
| 567 fmt->attr = atoi(tmp) * 3 + 1; |
|
| 568 fmt->attr &= 0x0f; |
|
| 569 } |
|
| 570 |
|
| 571 tmp = g_datalist_get_data(&attribs, "color"); |
|
| 572 if (tmp && strlen(tmp) > 1) { |
|
| 573 rgb = purple_base16_decode(tmp + 1, NULL); |
|
| 574 g_memmove(fmt->rgb, rgb, 3); |
|
| 575 g_free(rgb); |
|
| 576 } |
|
| 577 |
|
| 578 g_datalist_clear(&attribs); |
|
| 579 last = end + 1; |
|
| 580 } |
|
| 581 |
|
| 582 if (purple_markup_find_tag("b", msg, &start, &end, &attribs)) { |
|
| 583 fmt->attr |= 0x20; |
|
| 584 g_datalist_clear(&attribs); |
|
| 585 } |
|
| 586 |
|
| 587 if (purple_markup_find_tag("i", msg, &start, &end, &attribs)) { |
|
| 588 fmt->attr |= 0x40; |
|
| 589 g_datalist_clear(&attribs); |
|
| 590 } |
|
| 591 |
|
| 592 if (purple_markup_find_tag("u", msg, &start, &end, &attribs)) { |
|
| 593 fmt->attr |= 0x80; |
|
| 594 g_datalist_clear(&attribs); |
|
| 595 } |
|
| 596 |
|
| 597 return fmt; |
|
| 598 } |
|
| 599 |
|
| 600 /* convert qq format to purple |
|
| 601 Notice: text is in qq charset, GB18030 or utf8 */ |
|
| 602 gchar *qq_im_fmt_to_purple(qq_im_format *fmt, gchar *text) |
|
| 603 { |
|
| 604 GString *converted, *tmp; |
|
| 605 gchar *ret; |
|
| 606 gint size; |
|
| 607 |
|
| 608 converted = g_string_new(text); |
|
| 609 tmp = g_string_new(""); |
|
| 610 g_string_append_printf(tmp, "<font color=\"#%02x%02x%02x\">", |
|
| 611 fmt->rgb[0], fmt->rgb[1], fmt->rgb[2]); |
|
| 612 g_string_prepend(converted, tmp->str); |
|
| 613 g_string_set_size(tmp, 0); |
|
| 614 g_string_append(converted, "</font>"); |
|
| 615 |
|
| 616 /* Fixme: |
|
| 617 * check font face can be convert to utf8 or not? |
|
| 618 * If failed, prepending font face cause msg display as "(NULL)" */ |
|
| 619 if (fmt->font != NULL) { |
|
| 620 g_string_append_printf(tmp, "<font face=\"%s\">", fmt->font); |
|
| 621 g_string_prepend(converted, tmp->str); |
|
| 622 g_string_set_size(tmp, 0); |
|
| 623 g_string_append(converted, "</font>"); |
|
| 624 } |
|
| 625 size = (fmt->attr & 0x1f) / 3; |
|
| 626 if (size >= 0) { |
|
| 627 g_string_append_printf(tmp, "<font size=\"%d\">", size); |
|
| 628 g_string_prepend(converted, tmp->str); |
|
| 629 g_string_set_size(tmp, 0); |
|
| 630 g_string_append(converted, "</font>"); |
|
| 631 } |
|
| 632 if (fmt->attr & 0x20) { |
|
| 633 /* bold */ |
|
| 634 g_string_prepend(converted, "<b>"); |
|
| 635 g_string_append(converted, "</b>"); |
|
| 636 } |
|
| 637 if (fmt->attr & 0x40) { |
|
| 638 /* italic */ |
|
| 639 g_string_prepend(converted, "<i>"); |
|
| 640 g_string_append(converted, "</i>"); |
|
| 641 } |
|
| 642 if (fmt->attr & 0x80) { |
|
| 643 /* underline */ |
|
| 644 g_string_prepend(converted, "<u>"); |
|
| 645 g_string_append(converted, "</u>"); |
|
| 646 } |
|
| 647 |
|
| 648 g_string_free(tmp, TRUE); |
|
| 649 ret = converted->str; |
|
| 650 g_string_free(converted, FALSE); |
|
| 651 return ret; |
|
| 652 } |
|
| 653 |
|
| 654 gint qq_put_im_tail(guint8 *buf, qq_im_format *fmt) |
|
| 655 { |
|
| 656 gint bytes; |
|
| 657 |
|
| 658 g_return_val_if_fail(buf != NULL && fmt != NULL, 0); |
|
| 659 |
|
| 660 bytes = 0; |
|
| 661 bytes += qq_put8(buf + bytes, 0); |
|
| 662 bytes += qq_put8(buf + bytes, fmt->attr); |
|
| 663 bytes += qq_putdata(buf + bytes, fmt->rgb, sizeof(fmt->rgb)); |
|
| 664 bytes += qq_put8(buf + bytes, 0); |
|
| 665 bytes += qq_put16(buf + bytes, fmt->charset); |
|
| 666 if (fmt->font != NULL && fmt->font_len > 0) { |
|
| 667 bytes += qq_putdata(buf + bytes, (guint8 *)fmt->font, fmt->font_len); |
|
| 668 } else { |
|
| 669 purple_debug_warning("QQ", "Font name is empty\n"); |
|
| 670 } |
|
| 671 bytes += qq_put8(buf + bytes, bytes + 1); |
|
| 672 /* qq_show_packet("IM tail", buf, bytes); */ |
|
| 673 return bytes; |
|
| 674 } |
|
| 675 |
|
| 676 /* data includes text msg and font attr*/ |
|
| 677 gint qq_get_im_tail(qq_im_format *fmt, guint8 *data, gint data_len) |
|
| 678 { |
|
| 679 gint bytes, text_len; |
|
| 680 guint8 tail_len; |
|
| 681 guint8 font_len; |
|
| 682 |
|
| 683 g_return_val_if_fail(fmt != NULL && data != NULL, 0); |
|
| 684 g_return_val_if_fail(data_len > 1, 0); |
|
| 685 tail_len = data[data_len - 1]; |
|
| 686 g_return_val_if_fail(tail_len > 2, 0); |
|
| 687 text_len = data_len - tail_len; |
|
| 688 g_return_val_if_fail(text_len >= 0, 0); |
|
| 689 |
|
| 690 bytes = text_len; |
|
| 691 /* qq_show_packet("IM tail", data + bytes, tail_len); */ |
|
| 692 bytes += 1; /* skip 0x00 */ |
|
| 693 bytes += qq_get8(&fmt->attr, data + bytes); |
|
| 694 bytes += qq_getdata(fmt->rgb, sizeof(fmt->rgb), data + bytes); /* red,green,blue */ |
|
| 695 bytes += 1; /* skip 0x00 */ |
|
| 696 bytes += qq_get16(&fmt->charset, data + bytes); |
|
| 697 |
|
| 698 font_len = data_len - bytes - 1; |
|
| 699 g_return_val_if_fail(font_len > 0, bytes + 1); |
|
| 700 |
|
| 701 fmt->font_len = font_len; |
|
| 702 if (fmt->font != NULL) g_free(fmt->font); |
|
| 703 fmt->font = g_strndup((gchar *)data + bytes, fmt->font_len); |
|
| 704 return tail_len; |
|
| 705 } |
|
| 706 |
|
| 707 void qq_got_message(PurpleConnection *gc, const gchar *msg) |
|
| 708 { |
|
| 709 qq_data *qd; |
|
| 710 gchar *from; |
|
| 711 time_t now = time(NULL); |
|
| 712 |
|
| 713 g_return_if_fail(gc != NULL && gc->proto_data != NULL); |
|
| 714 qd = gc->proto_data; |
|
| 715 |
|
| 716 g_return_if_fail(qd->uid > 0); |
|
| 717 |
|
| 718 qq_buddy_find_or_new(gc, qd->uid); |
|
| 719 |
|
| 720 from = uid_to_purple_name(qd->uid); |
|
| 721 serv_got_im(gc, from, msg, PURPLE_MESSAGE_SYSTEM, now); |
|
| 722 g_free(from); |
|
| 723 } |
|
| 724 |
|
| 725 /* process received normal text IM */ |
|
| 726 static void process_im_text(PurpleConnection *gc, guint8 *data, gint len, qq_im_header *im_header) |
|
| 727 { |
|
| 728 qq_data *qd; |
|
| 729 guint16 purple_msg_type; |
|
| 730 gchar *who; |
|
| 731 gchar *msg_smiley, *msg_fmt, *msg_utf8; |
|
| 732 PurpleBuddy *buddy; |
|
| 733 qq_buddy_data *bd; |
|
| 734 gint bytes, tail_len; |
|
| 735 qq_im_format *fmt = NULL; |
|
| 736 |
|
| 737 struct { |
|
| 738 /* now comes the part for text only */ |
|
| 739 guint16 msg_seq; |
|
| 740 guint32 send_time; |
|
| 741 guint16 sender_icon; |
|
| 742 guint8 unknown1[3]; |
|
| 743 guint8 has_font_attr; |
|
| 744 guint8 fragment_count; |
|
| 745 guint8 fragment_index; |
|
| 746 guint8 msg_id; |
|
| 747 guint8 unknown2; |
|
| 748 guint8 msg_type; |
|
| 749 gchar *msg; /* no fixed length, ends with 0x00 */ |
|
| 750 } im_text; |
|
| 751 |
|
| 752 g_return_if_fail (data != NULL && len > 0); |
|
| 753 g_return_if_fail(im_header != NULL); |
|
| 754 |
|
| 755 qd = (qq_data *) gc->proto_data; |
|
| 756 memset(&im_text, 0, sizeof(im_text)); |
|
| 757 |
|
| 758 /* qq_show_packet("IM text", data, len); */ |
|
| 759 bytes = 0; |
|
| 760 bytes += qq_get16(&(im_text.msg_seq), data + bytes); |
|
| 761 bytes += qq_get32(&(im_text.send_time), data + bytes); |
|
| 762 bytes += qq_get16(&(im_text.sender_icon), data + bytes); |
|
| 763 bytes += qq_getdata(im_text.unknown1, sizeof(im_text.unknown1), data + bytes); /* 0x(00 00 00)*/ |
|
| 764 bytes += qq_get8(&(im_text.has_font_attr), data + bytes); |
|
| 765 bytes += qq_get8(&(im_text.fragment_count), data + bytes); |
|
| 766 bytes += qq_get8(&(im_text.fragment_index), data + bytes); |
|
| 767 bytes += qq_get8(&(im_text.msg_id), data + bytes); |
|
| 768 bytes += 1; /* skip 0x00 */ |
|
| 769 bytes += qq_get8(&(im_text.msg_type), data + bytes); |
|
| 770 purple_debug_info("QQ", "IM Seq %u, id %04X, fragment %d-%d, type %d, %s\n", |
|
| 771 im_text.msg_seq, im_text.msg_id, |
|
| 772 im_text.fragment_count, im_text.fragment_index, |
|
| 773 im_text.msg_type, |
|
| 774 im_text.has_font_attr ? "exist font atrr" : ""); |
|
| 775 |
|
| 776 if (im_text.has_font_attr) { |
|
| 777 fmt = qq_im_fmt_new(); |
|
| 778 tail_len = qq_get_im_tail(fmt, data + bytes, len - bytes); |
|
| 779 im_text.msg = g_strndup((gchar *)(data + bytes), len - tail_len); |
|
| 780 } else { |
|
| 781 im_text.msg = g_strndup((gchar *)(data + bytes), len - bytes); |
|
| 782 } |
|
| 783 /* qq_show_packet("IM text", (guint8 *)im_text.msg , strlen(im_text.msg) ); */ |
|
| 784 |
|
| 785 who = uid_to_purple_name(im_header->uid_from); |
|
| 786 buddy = purple_find_buddy(gc->account, who); |
|
| 787 if (buddy == NULL) { |
|
| 788 /* create no-auth buddy */ |
|
| 789 buddy = qq_buddy_new(gc, im_header->uid_from); |
|
| 790 } |
|
| 791 bd = (buddy == NULL) ? NULL : purple_buddy_get_protocol_data(buddy); |
|
| 792 if (bd != NULL) { |
|
| 793 bd->client_tag = im_header->version_from; |
|
| 794 bd->face = im_text.sender_icon; |
|
| 795 qq_update_buddy_icon(gc->account, who, bd->face); |
|
| 796 } |
|
| 797 |
|
| 798 purple_msg_type = (im_text.msg_type == QQ_IM_AUTO_REPLY) |
|
| 799 ? PURPLE_MESSAGE_AUTO_RESP : 0; |
|
| 800 |
|
| 801 msg_smiley = qq_emoticon_to_purple(im_text.msg); |
|
| 802 if (fmt != NULL) { |
|
| 803 msg_fmt = qq_im_fmt_to_purple(fmt, msg_smiley); |
|
| 804 msg_utf8 = qq_to_utf8(msg_fmt, QQ_CHARSET_DEFAULT); |
|
| 805 g_free(msg_fmt); |
|
| 806 qq_im_fmt_free(fmt); |
|
| 807 } else { |
|
| 808 msg_utf8 = qq_to_utf8(msg_smiley, QQ_CHARSET_DEFAULT); |
|
| 809 } |
|
| 810 g_free(msg_smiley); |
|
| 811 |
|
| 812 /* send encoded to purple, note that we use im_text.send_time, |
|
| 813 * not the time we receive the message |
|
| 814 * as it may have been delayed when I am not online. */ |
|
| 815 purple_debug_info("QQ", "IM from %u: %s\n", im_header->uid_from,msg_utf8); |
|
| 816 serv_got_im(gc, who, msg_utf8, purple_msg_type, (time_t) im_text.send_time); |
|
| 817 |
|
| 818 g_free(msg_utf8); |
|
| 819 g_free(who); |
|
| 820 g_free(im_text.msg); |
|
| 821 } |
|
| 822 |
|
| 823 /* process received extended (2007) text IM */ |
|
| 824 static void process_extend_im_text(PurpleConnection *gc, guint8 *data, gint len, qq_im_header *im_header) |
|
| 825 { |
|
| 826 qq_data *qd; |
|
| 827 guint16 purple_msg_type; |
|
| 828 gchar *who; |
|
| 829 gchar *msg_smiley, *msg_fmt, *msg_utf8; |
|
| 830 PurpleBuddy *buddy; |
|
| 831 qq_buddy_data *bd; |
|
| 832 gint bytes, tail_len; |
|
| 833 qq_im_format *fmt = NULL; |
|
| 834 |
|
| 835 struct { |
|
| 836 /* now comes the part for text only */ |
|
| 837 guint16 msg_seq; |
|
| 838 guint32 send_time; |
|
| 839 guint16 sender_icon; |
|
| 840 guint32 has_font_attr; |
|
| 841 guint8 unknown1[8]; |
|
| 842 guint8 fragment_count; |
|
| 843 guint8 fragment_index; |
|
| 844 guint8 msg_id; |
|
| 845 guint8 unknown2; |
|
| 846 guint8 msg_type; |
|
| 847 gchar *msg; /* no fixed length, ends with 0x00 */ |
|
| 848 guint8 fromMobileQQ; |
|
| 849 } im_text; |
|
| 850 |
|
| 851 g_return_if_fail (data != NULL && len > 0); |
|
| 852 g_return_if_fail(im_header != NULL); |
|
| 853 |
|
| 854 qd = (qq_data *) gc->proto_data; |
|
| 855 memset(&im_text, 0, sizeof(im_text)); |
|
| 856 |
|
| 857 /* qq_show_packet("Extend IM text", data, len); */ |
|
| 858 bytes = 0; |
|
| 859 bytes += qq_get16(&(im_text.msg_seq), data + bytes); |
|
| 860 bytes += qq_get32(&(im_text.send_time), data + bytes); |
|
| 861 bytes += qq_get16(&(im_text.sender_icon), data + bytes); |
|
| 862 bytes += qq_get32(&(im_text.has_font_attr), data + bytes); |
|
| 863 bytes += qq_getdata(im_text.unknown1, sizeof(im_text.unknown1), data + bytes); |
|
| 864 bytes += qq_get8(&(im_text.fragment_count), data + bytes); |
|
| 865 bytes += qq_get8(&(im_text.fragment_index), data + bytes); |
|
| 866 bytes += qq_get8(&(im_text.msg_id), data + bytes); |
|
| 867 bytes += 1; /* skip 0x00 */ |
|
| 868 bytes += qq_get8(&(im_text.msg_type), data + bytes); |
|
| 869 purple_debug_info("QQ", "IM Seq %u, id %04X, fragment %d-%d, type %d, %s\n", |
|
| 870 im_text.msg_seq, im_text.msg_id, |
|
| 871 im_text.fragment_count, im_text.fragment_index, |
|
| 872 im_text.msg_type, |
|
| 873 im_text.has_font_attr ? "exist font atrr" : ""); |
|
| 874 |
|
| 875 if (im_text.has_font_attr) { |
|
| 876 fmt = qq_im_fmt_new(); |
|
| 877 tail_len = qq_get_im_tail(fmt, data + bytes, len - bytes); |
|
| 878 im_text.msg = g_strndup((gchar *)(data + bytes), len - tail_len); |
|
| 879 } else { |
|
| 880 im_text.msg = g_strndup((gchar *)(data + bytes), len - bytes); |
|
| 881 } |
|
| 882 /* qq_show_packet("IM text", (guint8 *)im_text.msg , strlen(im_text.msg)); */ |
|
| 883 |
|
| 884 if(im_text.fragment_count == 0) im_text.fragment_count = 1; |
|
| 885 |
|
| 886 who = uid_to_purple_name(im_header->uid_from); |
|
| 887 buddy = purple_find_buddy(gc->account, who); |
|
| 888 if (buddy == NULL) { |
|
| 889 /* create no-auth buddy */ |
|
| 890 buddy = qq_buddy_new(gc, im_header->uid_from); |
|
| 891 } |
|
| 892 bd = (buddy == NULL) ? NULL : purple_buddy_get_protocol_data(buddy); |
|
| 893 if (bd != NULL) { |
|
| 894 bd->client_tag = im_header->version_from; |
|
| 895 bd->face = im_text.sender_icon; |
|
| 896 qq_update_buddy_icon(gc->account, who, bd->face); |
|
| 897 } |
|
| 898 |
|
| 899 purple_msg_type = 0; |
|
| 900 |
|
| 901 msg_smiley = qq_emoticon_to_purple(im_text.msg); |
|
| 902 if (fmt != NULL) { |
|
| 903 msg_fmt = qq_im_fmt_to_purple(fmt, msg_smiley); |
|
| 904 msg_utf8 = qq_to_utf8(msg_fmt, QQ_CHARSET_DEFAULT); |
|
| 905 g_free(msg_fmt); |
|
| 906 qq_im_fmt_free(fmt); |
|
| 907 } else { |
|
| 908 msg_utf8 = qq_to_utf8(msg_smiley, QQ_CHARSET_DEFAULT); |
|
| 909 } |
|
| 910 g_free(msg_smiley); |
|
| 911 |
|
| 912 /* send encoded to purple, note that we use im_text.send_time, |
|
| 913 * not the time we receive the message |
|
| 914 * as it may have been delayed when I am not online. */ |
|
| 915 serv_got_im(gc, who, msg_utf8, purple_msg_type, (time_t) im_text.send_time); |
|
| 916 |
|
| 917 g_free(msg_utf8); |
|
| 918 g_free(who); |
|
| 919 g_free(im_text.msg); |
|
| 920 } |
|
| 921 |
|
| 922 /* it is a normal IM, maybe text or video request */ |
|
| 923 void qq_process_im(PurpleConnection *gc, guint8 *data, gint len) |
|
| 924 { |
|
| 925 gint bytes = 0; |
|
| 926 qq_im_header im_header; |
|
| 927 |
|
| 928 g_return_if_fail (data != NULL && len > 0); |
|
| 929 |
|
| 930 bytes = get_im_header(&im_header, data, len); |
|
| 931 if (bytes < 0) { |
|
| 932 purple_debug_error("QQ", "Fail read im header, len %d\n", len); |
|
| 933 qq_show_packet ("IM Header", data, len); |
|
| 934 return; |
|
| 935 } |
|
| 936 purple_debug_info("QQ", |
|
| 937 "Got IM to %u, type: %02X from: %u ver: %s (%04X)\n", |
|
| 938 im_header.uid_to, im_header.im_type, im_header.uid_from, |
|
| 939 qq_get_ver_desc(im_header.version_from), im_header.version_from); |
|
| 940 |
|
| 941 switch (im_header.im_type) { |
|
| 942 case QQ_NORMAL_IM_TEXT: |
|
| 943 if (bytes >= len - 1) { |
|
| 944 purple_debug_warning("QQ", "Received normal IM text is empty\n"); |
|
| 945 return; |
|
| 946 } |
|
| 947 process_im_text(gc, data + bytes, len - bytes, &im_header); |
|
| 948 break; |
|
| 949 case QQ_NORMAL_IM_FILE_REJECT_UDP: |
|
| 950 qq_process_recv_file_reject(data + bytes, len - bytes, im_header.uid_from, gc); |
|
| 951 break; |
|
| 952 case QQ_NORMAL_IM_FILE_APPROVE_UDP: |
|
| 953 qq_process_recv_file_accept(data + bytes, len - bytes, im_header.uid_from, gc); |
|
| 954 break; |
|
| 955 case QQ_NORMAL_IM_FILE_REQUEST_UDP: |
|
| 956 qq_process_recv_file_request(data + bytes, len - bytes, im_header.uid_from, gc); |
|
| 957 break; |
|
| 958 case QQ_NORMAL_IM_FILE_CANCEL: |
|
| 959 qq_process_recv_file_cancel(data + bytes, len - bytes, im_header.uid_from, gc); |
|
| 960 break; |
|
| 961 case QQ_NORMAL_IM_FILE_NOTIFY: |
|
| 962 qq_process_recv_file_notify(data + bytes, len - bytes, im_header.uid_from, gc); |
|
| 963 break; |
|
| 964 case QQ_NORMAL_IM_FILE_REQUEST_TCP: |
|
| 965 /* Check ReceivedFileIM::parseContents in eva*/ |
|
| 966 /* some client use this function for detect invisable buddy*/ |
|
| 967 case QQ_NORMAL_IM_FILE_APPROVE_TCP: |
|
| 968 case QQ_NORMAL_IM_FILE_REJECT_TCP: |
|
| 969 case QQ_NORMAL_IM_FILE_PASV: |
|
| 970 case QQ_NORMAL_IM_FILE_EX_REQUEST_UDP: |
|
| 971 case QQ_NORMAL_IM_FILE_EX_REQUEST_ACCEPT: |
|
| 972 case QQ_NORMAL_IM_FILE_EX_REQUEST_CANCEL: |
|
| 973 case QQ_NORMAL_IM_FILE_EX_NOTIFY_IP: |
|
| 974 qq_show_packet ("Not support", data, len); |
|
| 975 break; |
|
| 976 default: |
|
| 977 /* a simple process here, maybe more later */ |
|
| 978 qq_show_packet ("Unknow", data + bytes, len - bytes); |
|
| 979 return; |
|
| 980 } |
|
| 981 } |
|
| 982 |
|
| 983 /* it is a extended IM, maybe text or video request */ |
|
| 984 void qq_process_extend_im(PurpleConnection *gc, guint8 *data, gint len) |
|
| 985 { |
|
| 986 gint bytes; |
|
| 987 qq_im_header im_header; |
|
| 988 |
|
| 989 g_return_if_fail (data != NULL && len > 0); |
|
| 990 |
|
| 991 bytes = get_im_header(&im_header, data, len); |
|
| 992 if (bytes < 0) { |
|
| 993 purple_debug_error("QQ", "Fail read im header, len %d\n", len); |
|
| 994 qq_show_packet ("IM Header", data, len); |
|
| 995 return; |
|
| 996 } |
|
| 997 purple_debug_info("QQ", |
|
| 998 "Got Extend IM to %u, type: %02X from: %u ver: %s (%04X)\n", |
|
| 999 im_header.uid_to, im_header.im_type, im_header.uid_from, |
|
| 1000 qq_get_ver_desc(im_header.version_from), im_header.version_from); |
|
| 1001 |
|
| 1002 switch (im_header.im_type) { |
|
| 1003 case QQ_NORMAL_IM_TEXT: |
|
| 1004 process_extend_im_text(gc, data + bytes, len - bytes, &im_header); |
|
| 1005 break; |
|
| 1006 case QQ_NORMAL_IM_FILE_REJECT_UDP: |
|
| 1007 qq_process_recv_file_reject (data + bytes, len - bytes, im_header.uid_from, gc); |
|
| 1008 break; |
|
| 1009 case QQ_NORMAL_IM_FILE_APPROVE_UDP: |
|
| 1010 qq_process_recv_file_accept (data + bytes, len - bytes, im_header.uid_from, gc); |
|
| 1011 break; |
|
| 1012 case QQ_NORMAL_IM_FILE_REQUEST_UDP: |
|
| 1013 qq_process_recv_file_request (data + bytes, len - bytes, im_header.uid_from, gc); |
|
| 1014 break; |
|
| 1015 case QQ_NORMAL_IM_FILE_CANCEL: |
|
| 1016 qq_process_recv_file_cancel (data + bytes, len - bytes, im_header.uid_from, gc); |
|
| 1017 break; |
|
| 1018 case QQ_NORMAL_IM_FILE_NOTIFY: |
|
| 1019 qq_process_recv_file_notify (data + bytes, len - bytes, im_header.uid_from, gc); |
|
| 1020 break; |
|
| 1021 case QQ_NORMAL_IM_FILE_REQUEST_TCP: |
|
| 1022 /* Check ReceivedFileIM::parseContents in eva*/ |
|
| 1023 /* some client use this function for detect invisable buddy*/ |
|
| 1024 case QQ_NORMAL_IM_FILE_APPROVE_TCP: |
|
| 1025 case QQ_NORMAL_IM_FILE_REJECT_TCP: |
|
| 1026 case QQ_NORMAL_IM_FILE_PASV: |
|
| 1027 case QQ_NORMAL_IM_FILE_EX_REQUEST_UDP: |
|
| 1028 case QQ_NORMAL_IM_FILE_EX_REQUEST_ACCEPT: |
|
| 1029 case QQ_NORMAL_IM_FILE_EX_REQUEST_CANCEL: |
|
| 1030 case QQ_NORMAL_IM_FILE_EX_NOTIFY_IP: |
|
| 1031 qq_show_packet ("Not support", data, len); |
|
| 1032 break; |
|
| 1033 default: |
|
| 1034 /* a simple process here, maybe more later */ |
|
| 1035 qq_show_packet ("Unknow", data + bytes, len - bytes); |
|
| 1036 break; |
|
| 1037 } |
|
| 1038 } |
|
| 1039 |
|
| 1040 /* send an IM to uid_to */ |
|
| 1041 static void request_send_im(PurpleConnection *gc, guint32 uid_to, gint type, |
|
| 1042 qq_im_format *fmt, gchar *msg, guint8 id, guint8 frag_count, guint8 frag_index) |
|
| 1043 { |
|
| 1044 qq_data *qd; |
|
| 1045 guint8 raw_data[MAX_PACKET_SIZE - 16]; |
|
| 1046 guint16 im_type; |
|
| 1047 gint bytes; |
|
| 1048 time_t now; |
|
| 1049 |
|
| 1050 qd = (qq_data *) gc->proto_data; |
|
| 1051 im_type = QQ_NORMAL_IM_TEXT; |
|
| 1052 |
|
| 1053 /* purple_debug_info("QQ", "Send IM %d-%d\n", frag_count, frag_index); */ |
|
| 1054 bytes = 0; |
|
| 1055 /* 000-003: receiver uid */ |
|
| 1056 bytes += qq_put32(raw_data + bytes, qd->uid); |
|
| 1057 /* 004-007: sender uid */ |
|
| 1058 bytes += qq_put32(raw_data + bytes, uid_to); |
|
| 1059 /* 008-009: sender client version */ |
|
| 1060 bytes += qq_put16(raw_data + bytes, qd->client_tag); |
|
| 1061 /* 010-013: receiver uid */ |
|
| 1062 bytes += qq_put32(raw_data + bytes, qd->uid); |
|
| 1063 /* 014-017: sender uid */ |
|
| 1064 bytes += qq_put32(raw_data + bytes, uid_to); |
|
| 1065 /* 018-033: md5 of (uid+session_key) */ |
|
| 1066 bytes += qq_putdata(raw_data + bytes, qd->session_md5, 16); |
|
| 1067 /* 034-035: message type */ |
|
| 1068 bytes += qq_put16(raw_data + bytes, QQ_NORMAL_IM_TEXT); |
|
| 1069 /* 036-037: sequence number */ |
|
| 1070 bytes += qq_put16(raw_data + bytes, qd->send_seq); |
|
| 1071 /* 038-041: send time */ |
|
| 1072 now = time(NULL); |
|
| 1073 bytes += qq_put32(raw_data + bytes, (guint32) now); |
|
| 1074 /* 042-043: sender icon */ |
|
| 1075 bytes += qq_put16(raw_data + bytes, qd->my_icon); |
|
| 1076 /* 044-046: always 0x00 */ |
|
| 1077 bytes += qq_put16(raw_data + bytes, 0x0000); |
|
| 1078 bytes += qq_put8(raw_data + bytes, 0x00); |
|
| 1079 /* 047-047: always use font attr */ |
|
| 1080 bytes += qq_put8(raw_data + bytes, 0x01); |
|
| 1081 /* 048-051: always 0x00 */ |
|
| 1082 /* Fixme: frag_count, frag_index not working now */ |
|
| 1083 bytes += qq_put8(raw_data + bytes, frag_count); |
|
| 1084 bytes += qq_put8(raw_data + bytes, frag_index); |
|
| 1085 bytes += qq_put8(raw_data + bytes, id); |
|
| 1086 bytes += qq_put8(raw_data + bytes, 0); |
|
| 1087 /* 052-052: text message type (normal/auto-reply) */ |
|
| 1088 bytes += qq_put8(raw_data + bytes, type); |
|
| 1089 /* 053- : msg ends with 0x00 */ |
|
| 1090 bytes += qq_putdata(raw_data + bytes, (guint8 *)msg, strlen(msg)); |
|
| 1091 if (frag_count == frag_index + 1) { |
|
| 1092 bytes += qq_put8(raw_data + bytes, 0x20); /* add extra SPACE */ |
|
| 1093 } |
|
| 1094 bytes += qq_put_im_tail(raw_data + bytes, fmt); |
|
| 1095 |
|
| 1096 /* qq_show_packet("QQ_CMD_SEND_IM", raw_data, bytes); */ |
|
| 1097 qq_send_cmd(gc, QQ_CMD_SEND_IM, raw_data, bytes); |
|
| 1098 } |
|
| 1099 |
|
| 1100 static void im_convert_and_merge(GString *dest, GString *append) |
|
| 1101 { |
|
| 1102 gchar *converted; |
|
| 1103 g_return_if_fail(dest != NULL && append != NULL); |
|
| 1104 |
|
| 1105 if (append->str == NULL || append->len <= 0) { |
|
| 1106 return; |
|
| 1107 } |
|
| 1108 /* purple_debug_info("QQ", "Append:\n%s\n", append->str); */ |
|
| 1109 converted = utf8_to_qq(append->str, QQ_CHARSET_DEFAULT); |
|
| 1110 g_string_append(dest, converted); |
|
| 1111 g_string_set_size(append, 0); |
|
| 1112 g_free(converted); |
|
| 1113 } |
|
| 1114 |
|
| 1115 GSList *qq_im_get_segments(gchar *msg_stripped, gboolean is_smiley_none) |
|
| 1116 { |
|
| 1117 GSList *string_list = NULL; |
|
| 1118 GString *new_string; |
|
| 1119 GString *append_utf8; |
|
| 1120 gchar *start, *p; |
|
| 1121 gint count, len; |
|
| 1122 qq_emoticon *emoticon; |
|
| 1123 |
|
| 1124 g_return_val_if_fail(msg_stripped != NULL, NULL); |
|
| 1125 |
|
| 1126 start = msg_stripped; |
|
| 1127 count = 0; |
|
| 1128 new_string = g_string_new(""); |
|
| 1129 append_utf8 = g_string_new(""); |
|
| 1130 while (*start) { |
|
| 1131 p = start; |
|
| 1132 |
|
| 1133 /* Convert emoticon */ |
|
| 1134 if (!is_smiley_none && *p == '/') { |
|
| 1135 if (new_string->len + append_utf8->len + 2 > QQ_MSG_IM_MAX) { |
|
| 1136 /* enough chars to send */ |
|
| 1137 im_convert_and_merge(new_string, append_utf8); |
|
| 1138 string_list = g_slist_append(string_list, strdup(new_string->str)); |
|
| 1139 g_string_set_size(new_string, 0); |
|
| 1140 continue; |
|
| 1141 } |
|
| 1142 emoticon = emoticon_find(p); |
|
| 1143 if (emoticon != NULL) { |
|
| 1144 purple_debug_info("QQ", "found emoticon %s as 0x%02X\n", |
|
| 1145 emoticon->name, emoticon->symbol); |
|
| 1146 /* QQ emoticon code prevent converting from utf8 to QQ charset |
|
| 1147 * convert append_utf8 to QQ charset |
|
| 1148 * merge the result to dest |
|
| 1149 * append qq QQ emoticon code to dest */ |
|
| 1150 im_convert_and_merge(new_string, append_utf8); |
|
| 1151 g_string_append_c(new_string, 0x14); |
|
| 1152 g_string_append_c(new_string, emoticon->symbol); |
|
| 1153 start += strlen(emoticon->name); |
|
| 1154 continue; |
|
| 1155 } else { |
|
| 1156 purple_debug_info("QQ", "Not found emoticon %.20s\n", p); |
|
| 1157 } |
|
| 1158 } |
|
| 1159 |
|
| 1160 /* Get next char */ |
|
| 1161 start = g_utf8_next_char(p); |
|
| 1162 len = start - p; |
|
| 1163 if (new_string->len + append_utf8->len + len > QQ_MSG_IM_MAX) { |
|
| 1164 /* enough chars to send */ |
|
| 1165 im_convert_and_merge(new_string, append_utf8); |
|
| 1166 string_list = g_slist_append(string_list, strdup(new_string->str)); |
|
| 1167 g_string_set_size(new_string, 0); |
|
| 1168 } |
|
| 1169 g_string_append_len(append_utf8, p, len); |
|
| 1170 } |
|
| 1171 |
|
| 1172 if (new_string->len + append_utf8->len > 0) { |
|
| 1173 im_convert_and_merge(new_string, append_utf8); |
|
| 1174 string_list = g_slist_append(string_list, strdup(new_string->str)); |
|
| 1175 } |
|
| 1176 g_string_free(new_string, TRUE); |
|
| 1177 g_string_free(append_utf8, TRUE); |
|
| 1178 return string_list; |
|
| 1179 } |
|
| 1180 |
|
| 1181 gboolean qq_im_smiley_none(const gchar *msg) |
|
| 1182 { |
|
| 1183 const gchar *start, *end, *last; |
|
| 1184 GData *attribs; |
|
| 1185 gchar *tmp; |
|
| 1186 gboolean ret = FALSE; |
|
| 1187 |
|
| 1188 g_return_val_if_fail(msg != NULL, TRUE); |
|
| 1189 |
|
| 1190 last = msg; |
|
| 1191 while (purple_markup_find_tag("font", last, &start, &end, &attribs)) { |
|
| 1192 tmp = g_datalist_get_data(&attribs, "sml"); |
|
| 1193 if (tmp && strlen(tmp) > 0) { |
|
| 1194 if (strcmp(tmp, "none") == 0) { |
|
| 1195 ret = TRUE; |
|
| 1196 break; |
|
| 1197 } |
|
| 1198 } |
|
| 1199 g_datalist_clear(&attribs); |
|
| 1200 last = end + 1; |
|
| 1201 } |
|
| 1202 return ret; |
|
| 1203 } |
|
| 1204 |
|
| 1205 /* Grab custom emote icons |
|
| 1206 static GSList* qq_grab_emoticons(const char *msg, const char*username) |
|
| 1207 { |
|
| 1208 GSList *list; |
|
| 1209 GList *smileys; |
|
| 1210 PurpleSmiley *smiley; |
|
| 1211 const char *smiley_shortcut; |
|
| 1212 char *ptr; |
|
| 1213 int length; |
|
| 1214 PurpleStoredImage *img; |
|
| 1215 |
|
| 1216 smileys = purple_smileys_get_all(); |
|
| 1217 length = strlen(msg); |
|
| 1218 |
|
| 1219 for (; smileys; smileys = g_list_delete_link(smileys, smileys)) { |
|
| 1220 smiley = smileys->data; |
|
| 1221 smiley_shortcut = purple_smiley_get_shortcut(smiley); |
|
| 1222 purple_debug_info("QQ", "Smiley shortcut [%s]\n", smiley_shortcut); |
|
| 1223 |
|
| 1224 ptr = g_strstr_len(msg, length, smiley_shortcut); |
|
| 1225 |
|
| 1226 if (!ptr) |
|
| 1227 continue; |
|
| 1228 |
|
| 1229 purple_debug_info("QQ", "Found Smiley shortcut [%s]\n", smiley_shortcut); |
|
| 1230 |
|
| 1231 img = purple_smiley_get_stored_image(smiley); |
|
| 1232 |
|
| 1233 emoticon = g_new0(MsnEmoticon, 1); |
|
| 1234 emoticon->smile = g_strdup(purple_smiley_get_shortcut(smiley)); |
|
| 1235 emoticon->obj = msn_object_new_from_image(img, |
|
| 1236 purple_imgstore_get_filename(img), |
|
| 1237 username, MSN_OBJECT_EMOTICON); |
|
| 1238 |
|
| 1239 purple_imgstore_unref(img); |
|
| 1240 list = g_slist_prepend(list, emoticon); |
|
| 1241 } |
|
| 1242 return list; |
|
| 1243 } |
|
| 1244 */ |
|
| 1245 |
|
| 1246 gint qq_send_im(PurpleConnection *gc, const gchar *who, const gchar *what, PurpleMessageFlags flags) |
|
| 1247 { |
|
| 1248 qq_data *qd; |
|
| 1249 guint32 uid_to; |
|
| 1250 gint type; |
|
| 1251 qq_im_format *fmt; |
|
| 1252 gchar *msg_stripped, *tmp; |
|
| 1253 GSList *segments, *it; |
|
| 1254 gint msg_len; |
|
| 1255 const gchar *start_invalid; |
|
| 1256 gboolean is_smiley_none; |
|
| 1257 guint8 frag_count, frag_index; |
|
| 1258 guint8 msg_id; |
|
| 1259 |
|
| 1260 g_return_val_if_fail(NULL != gc && NULL != gc->proto_data, -1); |
|
| 1261 g_return_val_if_fail(who != NULL && what != NULL, -1); |
|
| 1262 |
|
| 1263 qd = (qq_data *) gc->proto_data; |
|
| 1264 purple_debug_info("QQ", "Send IM to %s, len %" G_GSIZE_FORMAT ":\n%s\n", who, strlen(what), what); |
|
| 1265 |
|
| 1266 uid_to = purple_name_to_uid(who); |
|
| 1267 if (uid_to == qd->uid) { |
|
| 1268 /* if msg is to myself, bypass the network */ |
|
| 1269 serv_got_im(gc, who, what, flags, time(NULL)); |
|
| 1270 return 1; |
|
| 1271 } |
|
| 1272 |
|
| 1273 type = (flags == PURPLE_MESSAGE_AUTO_RESP ? QQ_IM_AUTO_REPLY : QQ_IM_TEXT); |
|
| 1274 /* qq_show_packet("IM UTF8", (guint8 *)what, strlen(what)); */ |
|
| 1275 |
|
| 1276 msg_stripped = purple_markup_strip_html(what); |
|
| 1277 g_return_val_if_fail(msg_stripped != NULL, -1); |
|
| 1278 /* qq_show_packet("IM Stripped", (guint8 *)what, strlen(what)); */ |
|
| 1279 |
|
| 1280 /* Check and valid utf8 string */ |
|
| 1281 msg_len = strlen(msg_stripped); |
|
| 1282 g_return_val_if_fail(msg_len > 0, -1); |
|
| 1283 if (!g_utf8_validate(msg_stripped, msg_len, &start_invalid)) { |
|
| 1284 if (start_invalid > msg_stripped) { |
|
| 1285 tmp = g_strndup(msg_stripped, start_invalid - msg_stripped); |
|
| 1286 g_free(msg_stripped); |
|
| 1287 msg_stripped = g_strconcat(tmp, _("(Invalid UTF-8 string)"), NULL); |
|
| 1288 g_free(tmp); |
|
| 1289 } else { |
|
| 1290 g_free(msg_stripped); |
|
| 1291 msg_stripped = g_strdup(_("(Invalid UTF-8 string)")); |
|
| 1292 } |
|
| 1293 } |
|
| 1294 |
|
| 1295 is_smiley_none = qq_im_smiley_none(what); |
|
| 1296 segments = qq_im_get_segments(msg_stripped, is_smiley_none); |
|
| 1297 g_free(msg_stripped); |
|
| 1298 |
|
| 1299 if (segments == NULL) { |
|
| 1300 return -1; |
|
| 1301 } |
|
| 1302 |
|
| 1303 qd->send_im_id++; |
|
| 1304 msg_id = (guint8)(qd->send_im_id && 0xFF); |
|
| 1305 fmt = qq_im_fmt_new_by_purple(what); |
|
| 1306 frag_count = g_slist_length(segments); |
|
| 1307 frag_index = 0; |
|
| 1308 for (it = segments; it; it = it->next) { |
|
| 1309 /* |
|
| 1310 request_send_im(gc, uid_to, type, fmt, (gchar *)it->data, |
|
| 1311 msg_id, frag_count, frag_index); |
|
| 1312 */ |
|
| 1313 request_send_im(gc, uid_to, type, fmt, (gchar *)it->data, 0, 0, 0); |
|
| 1314 g_free(it->data); |
|
| 1315 frag_index++; |
|
| 1316 } |
|
| 1317 g_slist_free(segments); |
|
| 1318 qq_im_fmt_free(fmt); |
|
| 1319 return 1; |
|
| 1320 } |
|