comparison mcabber/src/jab_iq.c @ 772:464be13343a9

Store most data in UTF-8 internally Only chat buffer data is still using 1 byte for char size. User input still doesn't handle UTF-8 locales.
author Mikael Berthe <mikael@lilotux.net>
date Sat, 25 Mar 2006 18:10:36 +0100
parents 3a76c2d73606
children 46304b773a44
comparison
equal deleted inserted replaced
771:ce4f8a2129a4 772:464be13343a9
165 165
166 static void handle_iq_roster(xmlnode x) 166 static void handle_iq_roster(xmlnode x)
167 { 167 {
168 xmlnode y; 168 xmlnode y;
169 const char *jid, *name, *group, *sub, *ask; 169 const char *jid, *name, *group, *sub, *ask;
170 char *buddyname;
171 char *cleanalias; 170 char *cleanalias;
172 enum subscr esub; 171 enum subscr esub;
173 int need_refresh = FALSE; 172 int need_refresh = FALSE;
174 guint roster_type; 173 guint roster_type;
175 174
176 for (y = xmlnode_get_tag(x, "item"); y; y = xmlnode_get_nextsibling(y)) { 175 for (y = xmlnode_get_tag(x, "item"); y; y = xmlnode_get_nextsibling(y)) {
177 gchar *name_noutf8 = NULL;
178 gchar *group_noutf8 = NULL;
179 176
180 jid = xmlnode_get_attrib(y, "jid"); 177 jid = xmlnode_get_attrib(y, "jid");
181 name = xmlnode_get_attrib(y, "name"); 178 name = xmlnode_get_attrib(y, "name");
182 sub = xmlnode_get_attrib(y, "subscription"); 179 sub = xmlnode_get_attrib(y, "subscription");
183 ask = xmlnode_get_attrib(y, "ask"); 180 ask = xmlnode_get_attrib(y, "ask");
185 group = xmlnode_get_tag_data(y, "group"); 182 group = xmlnode_get_tag_data(y, "group");
186 183
187 if (!jid) 184 if (!jid)
188 continue; 185 continue;
189 186
190 buddyname = cleanalias = jidtodisp(jid); 187 cleanalias = jidtodisp(jid);
191 188
192 esub = sub_none; 189 esub = sub_none;
193 if (sub) { 190 if (sub) {
194 if (!strcmp(sub, "to")) esub = sub_to; 191 if (!strcmp(sub, "to")) esub = sub_to;
195 else if (!strcmp(sub, "from")) esub = sub_from; 192 else if (!strcmp(sub, "from")) esub = sub_from;
207 } 204 }
208 205
209 if (ask && !strcmp(ask, "subscribe")) 206 if (ask && !strcmp(ask, "subscribe"))
210 esub |= sub_pending; 207 esub |= sub_pending;
211 208
212 if (name) { 209 if (!name)
213 name_noutf8 = from_utf8(name); 210 name = cleanalias;
214 if (name_noutf8)
215 buddyname = name_noutf8;
216 else
217 scr_LogPrint(LPRINT_LOG, "Decoding of buddy alias has failed: %s",
218 name);
219 }
220
221 if (group) {
222 group_noutf8 = from_utf8(group);
223 if (!group_noutf8)
224 scr_LogPrint(LPRINT_LOG, "Decoding of buddy group has failed: %s",
225 group);
226 }
227 211
228 // Tricky... :-\ My guess is that if there is no '@', this is an agent 212 // Tricky... :-\ My guess is that if there is no '@', this is an agent
229 if (strchr(cleanalias, '@')) 213 if (strchr(cleanalias, '@'))
230 roster_type = ROSTER_TYPE_USER; 214 roster_type = ROSTER_TYPE_USER;
231 else 215 else
232 roster_type = ROSTER_TYPE_AGENT; 216 roster_type = ROSTER_TYPE_AGENT;
233 217
234 roster_add_user(cleanalias, buddyname, group_noutf8, roster_type, esub); 218 roster_add_user(cleanalias, name, group, roster_type, esub);
235 219
236 if (name_noutf8) g_free(name_noutf8);
237 if (group_noutf8) g_free(group_noutf8);
238 g_free(cleanalias); 220 g_free(cleanalias);
239 } 221 }
240 222
241 buddylist_build(); 223 buddylist_build();
242 update_roster = TRUE; 224 update_roster = TRUE;
243 if (need_refresh) 225 if (need_refresh)
244 scr_ShowBuddyWindow(); 226 scr_ShowBuddyWindow();
245 } 227 }
246 228
247 void iqscallback_version(eviqs *iqp, xmlnode xml_result, guint iqcontext) 229 static void iqscallback_version(eviqs *iqp, xmlnode xml_result, guint iqcontext)
248 { 230 {
249 xmlnode ansqry; 231 xmlnode ansqry;
250 char *p, *p_noutf8; 232 char *p, *p_noutf8;
251 char *bjid; 233 char *bjid;
252 char *buf; 234 char *buf;
263 p = xmlnode_get_attrib(xml_result, "from"); 245 p = xmlnode_get_attrib(xml_result, "from");
264 if (!p) { 246 if (!p) {
265 scr_LogPrint(LPRINT_LOGNORM, "Invalid IQ:version result (no sender name)."); 247 scr_LogPrint(LPRINT_LOGNORM, "Invalid IQ:version result (no sender name).");
266 return; 248 return;
267 } 249 }
268 bjid = from_utf8(p); 250 bjid = p;
269 if (!bjid) {
270 scr_LogPrint(LPRINT_LOGNORM, "UTF-8 decoding error in IQ:version result "
271 "(sender name).");
272 return;
273 }
274 251
275 buf = g_strdup_printf("IQ:version result from <%s>", bjid); 252 buf = g_strdup_printf("IQ:version result from <%s>", bjid);
276 scr_LogPrint(LPRINT_LOGNORM, "%s", buf); 253 scr_LogPrint(LPRINT_LOGNORM, "%s", buf);
277 254
278 // bjid should now really be the "bare JID", let's strip the resource 255 // bjid should now really be the "bare JID", let's strip the resource
311 scr_WriteIncomingMessage(bjid, buf, 0, HBB_PREFIX_INFO); 288 scr_WriteIncomingMessage(bjid, buf, 0, HBB_PREFIX_INFO);
312 g_free(p_noutf8); 289 g_free(p_noutf8);
313 g_free(buf); 290 g_free(buf);
314 } 291 }
315 } 292 }
316 g_free(bjid);
317 } 293 }
318 294
319 void request_version(const char *fulljid) 295 void request_version(const char *fulljid)
320 { 296 {
321 eviqs *iqn; 297 eviqs *iqn;
322 gchar *utf8_jid = to_utf8(fulljid);
323 298
324 iqn = iqs_new(JPACKET__GET, NS_VERSION, "version", IQS_DEFAULT_TIMEOUT); 299 iqn = iqs_new(JPACKET__GET, NS_VERSION, "version", IQS_DEFAULT_TIMEOUT);
325 xmlnode_put_attrib(iqn->xmldata, "to", utf8_jid); 300 xmlnode_put_attrib(iqn->xmldata, "to", fulljid);
326 if (utf8_jid) g_free(utf8_jid);
327 iqn->callback = &iqscallback_version; 301 iqn->callback = &iqscallback_version;
328 jab_send(jc, iqn->xmldata); 302 jab_send(jc, iqn->xmldata);
329 } 303 }
330 304
331 void iqscallback_time(eviqs *iqp, xmlnode xml_result, guint iqcontext) 305 static void iqscallback_time(eviqs *iqp, xmlnode xml_result, guint iqcontext)
332 { 306 {
333 xmlnode ansqry; 307 xmlnode ansqry;
334 char *p, *p_noutf8; 308 char *p, *p_noutf8;
335 char *bjid; 309 char *bjid;
336 char *buf; 310 char *buf;
347 p = xmlnode_get_attrib(xml_result, "from"); 321 p = xmlnode_get_attrib(xml_result, "from");
348 if (!p) { 322 if (!p) {
349 scr_LogPrint(LPRINT_LOGNORM, "Invalid IQ:time result (no sender name)."); 323 scr_LogPrint(LPRINT_LOGNORM, "Invalid IQ:time result (no sender name).");
350 return; 324 return;
351 } 325 }
352 bjid = from_utf8(p); 326 bjid = p;
353 if (!bjid) {
354 scr_LogPrint(LPRINT_LOGNORM, "UTF-8 decoding error in IQ:time result "
355 "(sender name).");
356 return;
357 }
358 327
359 buf = g_strdup_printf("IQ:time result from <%s>", bjid); 328 buf = g_strdup_printf("IQ:time result from <%s>", bjid);
360 scr_LogPrint(LPRINT_LOGNORM, "%s", buf); 329 scr_LogPrint(LPRINT_LOGNORM, "%s", buf);
361 330
362 // bjid should now really be the "bare JID", let's strip the resource 331 // bjid should now really be the "bare JID", let's strip the resource
395 scr_WriteIncomingMessage(bjid, buf, 0, HBB_PREFIX_INFO); 364 scr_WriteIncomingMessage(bjid, buf, 0, HBB_PREFIX_INFO);
396 g_free(p_noutf8); 365 g_free(p_noutf8);
397 g_free(buf); 366 g_free(buf);
398 } 367 }
399 } 368 }
400 g_free(bjid);
401 } 369 }
402 370
403 void request_time(const char *fulljid) 371 void request_time(const char *fulljid)
404 { 372 {
405 eviqs *iqn; 373 eviqs *iqn;
406 gchar *utf8_jid = to_utf8(fulljid);
407 374
408 iqn = iqs_new(JPACKET__GET, NS_TIME, "time", IQS_DEFAULT_TIMEOUT); 375 iqn = iqs_new(JPACKET__GET, NS_TIME, "time", IQS_DEFAULT_TIMEOUT);
409 xmlnode_put_attrib(iqn->xmldata, "to", utf8_jid); 376 xmlnode_put_attrib(iqn->xmldata, "to", fulljid);
410 if (utf8_jid) g_free(utf8_jid);
411 iqn->callback = &iqscallback_time; 377 iqn->callback = &iqscallback_time;
412 jab_send(jc, iqn->xmldata); 378 jab_send(jc, iqn->xmldata);
413 } 379 }
414 380
415 void iqscallback_auth(eviqs *iqp, xmlnode xml_result) 381 void iqscallback_auth(eviqs *iqp, xmlnode xml_result)