| 1104 g_free(who); |
1105 g_free(who); |
| 1105 if(!jri) { |
1106 if(!jri) { |
| 1106 jri = g_new0(struct jabber_resource_info, 1); |
1107 jri = g_new0(struct jabber_resource_info, 1); |
| 1107 jri->name = g_strdup(res); |
1108 jri->name = g_strdup(res); |
| 1108 jri->away_msg = NULL; |
1109 jri->away_msg = NULL; |
| |
1110 jri->has_xhtml = TRUE; |
| 1109 jbd->resources = g_slist_append(jbd->resources, jri); |
1111 jbd->resources = g_slist_append(jbd->resources, jri); |
| 1110 } |
1112 } |
| 1111 jri->priority = priority; |
1113 jri->priority = priority; |
| 1112 jri->state = state; |
1114 jri->state = state; |
| 1113 } |
1115 } |
| 1254 static void jabber_handlemessage(gjconn gjc, jpacket p) |
1256 static void jabber_handlemessage(gjconn gjc, jpacket p) |
| 1255 { |
1257 { |
| 1256 xmlnode y, subj; |
1258 xmlnode y, subj; |
| 1257 time_t time_sent = time(NULL); |
1259 time_t time_sent = time(NULL); |
| 1258 gboolean typing = FALSE; |
1260 gboolean typing = FALSE; |
| |
1261 gboolean has_xhtml = TRUE; |
| 1259 |
1262 |
| 1260 char *from = NULL, *msg = NULL, *type = NULL, *topic = NULL; |
1263 char *from = NULL, *msg = NULL, *type = NULL, *topic = NULL; |
| 1261 char *thread_id = NULL; |
1264 char *thread_id = NULL; |
| 1262 char *conference_room = NULL; |
1265 char *conference_room = NULL; |
| 1263 char m[BUF_LONG * 2]; |
1266 char m[BUF_LONG * 2]; |
| 1285 } |
1288 } |
| 1286 |
1289 |
| 1287 if (!type || !strcasecmp(type, "normal") || !strcasecmp(type, "chat")) { |
1290 if (!type || !strcasecmp(type, "normal") || !strcasecmp(type, "chat")) { |
| 1288 |
1291 |
| 1289 from = jid_full(p->from); |
1292 from = jid_full(p->from); |
| 1290 /* |
|
| 1291 if ((y = xmlnode_get_tag(p->x, "html"))) { |
1293 if ((y = xmlnode_get_tag(p->x, "html"))) { |
| |
1294 msg = xmlnode2str(y); |
| |
1295 } else if ((y = xmlnode_get_tag(p->x, "body"))) { |
| 1292 msg = xmlnode_get_data(y); |
1296 msg = xmlnode_get_data(y); |
| 1293 } else |
1297 has_xhtml = FALSE; |
| 1294 */ |
|
| 1295 if ((y = xmlnode_get_tag(p->x, "body"))) { |
|
| 1296 msg = xmlnode_get_data(y); |
|
| 1297 } |
1298 } |
| 1298 |
1299 |
| 1299 if (!from) |
1300 if (!from) |
| 1300 return; |
1301 return; |
| 1301 |
1302 |
| 1318 gaim_chat_get_id(GAIM_CHAT(jc->b)), |
1319 gaim_chat_get_id(GAIM_CHAT(jc->b)), |
| 1319 p->from->resource, 1, m, time_sent); |
1320 p->from->resource, 1, m, time_sent); |
| 1320 else { |
1321 else { |
| 1321 int flags = 0; |
1322 int flags = 0; |
| 1322 jab_res_info jri = jabber_find_resource(GJ_GC(gjc), from); |
1323 jab_res_info jri = jabber_find_resource(GJ_GC(gjc), from); |
| 1323 if(jri && typing) |
1324 if(jri) { |
| 1324 jri->has_composing = TRUE; |
1325 if(typing) |
| |
1326 jri->has_composing = TRUE; |
| |
1327 jri->has_xhtml = has_xhtml; |
| |
1328 } |
| 1325 if (xmlnode_get_tag(p->x, "gaim")) |
1329 if (xmlnode_get_tag(p->x, "gaim")) |
| 1326 flags = IM_FLAG_GAIMUSER; |
1330 flags = IM_FLAG_GAIMUSER; |
| 1327 jabber_track_convo_thread(gjc, from, thread_id); |
1331 jabber_track_convo_thread(gjc, from, thread_id); |
| 1328 if (gaim_find_conversation(from)) |
1332 if (gaim_find_conversation(from)) |
| 1329 serv_got_im(GJ_GC(gjc), from, m, flags, |
1333 serv_got_im(GJ_GC(gjc), from, m, flags, |
| 1363 } |
1367 } |
| 1364 } else if (!strcasecmp(type, "groupchat")) { |
1368 } else if (!strcasecmp(type, "groupchat")) { |
| 1365 struct jabber_chat *jc; |
1369 struct jabber_chat *jc; |
| 1366 static int i = 0; |
1370 static int i = 0; |
| 1367 |
1371 |
| 1368 /* |
|
| 1369 if ((y = xmlnode_get_tag(p->x, "html"))) { |
1372 if ((y = xmlnode_get_tag(p->x, "html"))) { |
| 1370 msg = xmlnode_get_data(y); |
1373 msg = xmlnode2str(y); |
| 1371 } else |
1374 } else if ((y = xmlnode_get_tag(p->x, "body"))) { |
| 1372 */ |
|
| 1373 if ((y = xmlnode_get_tag(p->x, "body"))) { |
|
| 1374 msg = xmlnode_get_data(y); |
1375 msg = xmlnode_get_data(y); |
| 1375 } |
1376 } |
| 1376 |
1377 |
| 1377 if ((subj = xmlnode_get_tag(p->x, "subject"))) { |
1378 if ((subj = xmlnode_get_tag(p->x, "subject"))) { |
| 1378 topic = xmlnode_get_data(subj); |
1379 topic = xmlnode_get_data(subj); |
| 2419 xmlnode_free(x); |
2420 xmlnode_free(x); |
| 2420 g_free(realwho); |
2421 g_free(realwho); |
| 2421 return JABBER_TYPING_NOTIFY_INT; |
2422 return JABBER_TYPING_NOTIFY_INT; |
| 2422 } |
2423 } |
| 2423 |
2424 |
| |
2425 static void insert_message(xmlnode x, const char *message, gboolean use_xhtml) { |
| |
2426 xmlnode y; |
| |
2427 char *buf = strip_html(message); |
| |
2428 y = xmlnode_insert_tag(x, "body"); |
| |
2429 xmlnode_insert_cdata(y, buf, -1); |
| |
2430 g_free(buf); |
| |
2431 |
| |
2432 if(use_xhtml) { |
| |
2433 char *buf2 = g_strdup_printf("<html xmlns='http://jabber.org/protocol/xhtml-im'><body>%s</body></html>", message); |
| |
2434 buf = html_to_xhtml(buf2); |
| |
2435 g_free(buf2); |
| |
2436 |
| |
2437 y = xmlnode_str(buf, strlen(buf)); |
| |
2438 if(y) { |
| |
2439 xmlnode_insert_tag_node(x, y); |
| |
2440 xmlnode_free(y); |
| |
2441 } else { |
| |
2442 debug_printf("holy cow, html_to_xhtml didn't work right!\n"); |
| |
2443 debug_printf("the invalid XML: %s\n", buf); |
| |
2444 } |
| |
2445 g_free(buf); |
| |
2446 } |
| |
2447 } |
| |
2448 |
| 2424 static int jabber_send_im(struct gaim_connection *gc, char *who, char *message, int len, int flags) |
2449 static int jabber_send_im(struct gaim_connection *gc, char *who, char *message, int len, int flags) |
| 2425 { |
2450 { |
| 2426 xmlnode x, y; |
2451 xmlnode x, y; |
| 2427 char *thread_id = NULL; |
2452 char *thread_id = NULL; |
| 2428 gjconn gjc = ((struct jabber_data *)gc->proto_data)->gjc; |
2453 gjconn gjc = ((struct jabber_data *)gc->proto_data)->gjc; |
| |
2454 jab_res_info jri = jabber_find_resource(gc, who); |
| 2429 |
2455 |
| 2430 if (!who || !message) |
2456 if (!who || !message) |
| 2431 return 0; |
2457 return 0; |
| 2432 |
2458 |
| 2433 x = xmlnode_new_tag("message"); |
2459 x = xmlnode_new_tag("message"); |
| 2450 y = xmlnode_insert_tag(x, "x"); |
2476 y = xmlnode_insert_tag(x, "x"); |
| 2451 xmlnode_put_attrib(y, "xmlns", "jabber:x:event"); |
2477 xmlnode_put_attrib(y, "xmlns", "jabber:x:event"); |
| 2452 xmlnode_insert_tag(y, "composing"); |
2478 xmlnode_insert_tag(y, "composing"); |
| 2453 |
2479 |
| 2454 if (message && strlen(message)) { |
2480 if (message && strlen(message)) { |
| 2455 y = xmlnode_insert_tag(x, "body"); |
2481 insert_message(x, message, jri ? jri->has_xhtml : TRUE); |
| 2456 xmlnode_insert_cdata(y, message, -1); |
|
| 2457 } |
2482 } |
| 2458 |
2483 |
| 2459 gjab_send(((struct jabber_data *)gc->proto_data)->gjc, x); |
2484 gjab_send(((struct jabber_data *)gc->proto_data)->gjc, x); |
| 2460 xmlnode_free(x); |
2485 xmlnode_free(x); |
| 2461 return 1; |
2486 return 1; |
| 2966 subject = g_strdup_printf("%s@%s", jc->gjid->user, jc->gjid->server); |
2991 subject = g_strdup_printf("%s@%s", jc->gjid->user, jc->gjid->server); |
| 2967 xmlnode_put_attrib(y, "jid", subject); |
2992 xmlnode_put_attrib(y, "jid", subject); |
| 2968 g_free(subject); |
2993 g_free(subject); |
| 2969 |
2994 |
| 2970 if (message && strlen(message)) { |
2995 if (message && strlen(message)) { |
| 2971 y = xmlnode_insert_tag(x, "body"); |
2996 insert_message(x, message, FALSE); |
| 2972 xmlnode_insert_cdata(y, message, -1); |
|
| 2973 } |
2997 } |
| 2974 |
2998 |
| 2975 gjab_send(((struct jabber_data *)gc->proto_data)->gjc, x); |
2999 gjab_send(((struct jabber_data *)gc->proto_data)->gjc, x); |
| 2976 xmlnode_free(x); |
3000 xmlnode_free(x); |
| 2977 } |
3001 } |
| 3022 xmlnode_insert_cdata(y, message + strlen("/topic "), -1); |
3046 xmlnode_insert_cdata(y, message + strlen("/topic "), -1); |
| 3023 y = xmlnode_insert_tag(x, "body"); |
3047 y = xmlnode_insert_tag(x, "body"); |
| 3024 g_snprintf(buf, sizeof(buf), "/me has changed the subject to: %s", message + strlen("/topic")); |
3048 g_snprintf(buf, sizeof(buf), "/me has changed the subject to: %s", message + strlen("/topic")); |
| 3025 xmlnode_insert_cdata(y, buf, -1); |
3049 xmlnode_insert_cdata(y, buf, -1); |
| 3026 } else if (message && strlen(message)) { |
3050 } else if (message && strlen(message)) { |
| 3027 y = xmlnode_insert_tag(x, "body"); |
3051 insert_message(x, message, FALSE); |
| 3028 xmlnode_insert_cdata(y, message, -1); |
|
| 3029 } |
3052 } |
| 3030 |
3053 |
| 3031 gjab_send(((struct jabber_data *)gc->proto_data)->gjc, x); |
3054 gjab_send(((struct jabber_data *)gc->proto_data)->gjc, x); |
| 3032 xmlnode_free(x); |
3055 xmlnode_free(x); |
| 3033 return 0; |
3056 return 0; |
| 3034 } |
3057 } |
| 3035 |
3058 |
| 3036 static void jabber_chat_whisper(struct gaim_connection *gc, int id, char *who, char *message) |
3059 static void jabber_chat_whisper(struct gaim_connection *gc, int id, char *who, char *message) |
| 3037 { |
3060 { |
| 3038 xmlnode x, y; |
3061 xmlnode x; |
| 3039 struct jabber_chat *jc = NULL; |
3062 struct jabber_chat *jc = NULL; |
| 3040 char *chatname; |
3063 char *chatname; |
| 3041 |
3064 |
| 3042 /* Find out which chat we're whispering to */ |
3065 /* Find out which chat we're whispering to */ |
| 3043 if(jabber_find_chat_by_convo_id(gc, id, &jc) != 0) |
3066 if(jabber_find_chat_by_convo_id(gc, id, &jc) != 0) |
| 3049 xmlnode_put_attrib(x, "to", chatname); |
3072 xmlnode_put_attrib(x, "to", chatname); |
| 3050 g_free(chatname); |
3073 g_free(chatname); |
| 3051 xmlnode_put_attrib(x, "type", "normal"); |
3074 xmlnode_put_attrib(x, "type", "normal"); |
| 3052 |
3075 |
| 3053 if (message && strlen(message)) { |
3076 if (message && strlen(message)) { |
| 3054 y = xmlnode_insert_tag(x, "body"); |
3077 insert_message(x, message, FALSE); |
| 3055 xmlnode_insert_cdata(y, message, -1); |
|
| 3056 } |
3078 } |
| 3057 |
3079 |
| 3058 gjab_send(((struct jabber_data *)gc->proto_data)->gjc, x); |
3080 gjab_send(((struct jabber_data *)gc->proto_data)->gjc, x); |
| 3059 xmlnode_free(x); |
3081 xmlnode_free(x); |
| 3060 } |
3082 } |