2
* $Id: xmpp-protocol.c,v 1.46 2008/01/07 07:29:13 errtu Exp $
2
* $Id: xmpp-protocol.c,v 1.55 2008/04/26 11:01:11 errtu Exp $
4
4
* Copyright (C) 2007 Colin DIDIER
6
6
* This program is free software; you can redistribute it and/or modify
7
* it under the terms of the GNU General Public License as published by
8
* the Free Software Foundation; either version 2 of the License, or
9
* (at your option) any later version.
7
* it under the terms of the GNU General Public License version 2 as
8
* published by the Free Software Foundation.
11
10
* This program is distributed in the hope that it will be useful,
12
11
* but WITHOUT ANY WARRANTY; without even the implied warranty of
44
43
LmMessageNode *child;
45
XMPP_ROSTER_USER_REC *user;
46
44
XMPP_ROSTER_RESOURCE_REC *resource;
47
char *jid, *res, *jid_recoded, *message_recoded;
45
char *jid, *jid_recoded, *message_recoded;
49
47
g_return_if_fail(IS_XMPP_SERVER(server));
50
48
g_return_if_fail(dest != NULL);
61
59
lm_message_node_add_child(msg->node, "body", message_recoded);
62
60
g_free(message_recoded);
64
if (jid == NULL || !xmpp_have_resource(jid))
67
user = xmpp_rosters_find_user(server->roster, jid, NULL);
71
res = xmpp_strip_resource(jid);
72
resource = xmpp_rosters_find_resource(user, res);
78
if (resource->composing_id != NULL) {
62
xmpp_rosters_find_user(server->roster, jid, NULL, &resource);
63
if (resource != NULL && resource->composing_id != NULL) {
79
64
child = lm_message_node_add_child(msg->node, "x", NULL);
80
65
lm_message_node_set_attribute(child, XMLNS, XMLNS_EVENT);
81
66
lm_message_node_add_child(child, "id", resource->composing_id);
82
67
g_free_and_null(resource->composing_id);
86
70
lm_send(server, msg, NULL);
87
71
lm_message_unref(msg);
317
case LM_MESSAGE_SUB_TYPE_NOT_SET:
318
if ((child = lm_tools_message_node_find(msg->node,
319
"x", XMLNS, XMLNS_MUC)) != NULL) {
322
if ((child = lm_message_node_get_child(child,
323
"invite")) != NULL) {
324
char *room, *by, *password, *reason;
329
subchild = lm_message_node_get_child(
330
child->parent, "password");
331
password = subchild == NULL ? NULL :
332
xmpp_recode_in(subchild->value);
334
subchild = lm_message_node_get_child(
336
reason = subchild == NULL ? NULL :
337
xmpp_recode_in(subchild->value);
339
to = lm_message_node_get_attribute(child,
342
room = xmpp_recode_in(to);
343
signal_emit("xmpp invite", 5, server,
344
room, jid, password, reason);
333
353
case LM_MESSAGE_SUB_TYPE_HEADLINE:
334
354
case LM_MESSAGE_SUB_TYPE_NORMAL:
335
355
case LM_MESSAGE_SUB_TYPE_CHAT:
356
/* rfc3921.txt states in 2.1.1. Types of Message:
357
* if an application receives a message with no 'type' attribute or the
358
* application does not understand the value of the 'type' attribute
359
* provided, it MUST consider the message to be of type "normal"
360
* Thus default belongs here, whre LM_MESSAGE_SUB_TYPE_NORMAL is
336
363
/* XEP-0022: Message Events */
337
364
child = lm_message_node_get_child(msg->node, "x");
338
365
if (child != NULL) {
388
415
GINT_TO_POINTER(SEND_TARGET_NICK));
390
417
if (g_ascii_strncasecmp(text, "/me ", 4) == 0)
391
signal_emit("message xmpp action", 5, server,
418
signal_emit("message xmpp action", 5,
419
server, text+4, jid, jid,
393
420
GINT_TO_POINTER(SEND_TARGET_NICK));
395
422
signal_emit("message private", 4, server,
433
460
if (child != NULL && child->value != NULL) {
434
461
XMPP_CHANNEL_REC *channel;
435
462
char *channel_name, *nick;
463
gboolean own, action;
437
465
channel_name = xmpp_extract_channel(jid);
438
466
nick = xmpp_extract_resource(jid);
468
g_free(channel_name);
472
channel = xmpp_channel_find(server, channel_name);
473
own = channel != NULL
474
&& strcmp(nick, channel->nick) == 0 ? TRUE : FALSE;
476
text = xmpp_recode_in(child->value);
477
action = g_ascii_strncasecmp(text, "/me ", 4) == 0 ?
439
479
stamp = get_timestamp(msg->node);
441
/* it's my own message, so ignore it */
442
channel = xmpp_channel_find(server, channel_name);
443
if (stamp == NULL && (channel == NULL
444
|| nick == NULL || (channel != NULL
445
&& strcmp(nick, channel->nick) == 0))) {
446
g_free(channel_name);
451
text = xmpp_recode_in(child->value);
453
481
if (stamp != NULL) {
454
if (g_ascii_strncasecmp(text, "/me ", 4) == 0)
456
484
"message xmpp history action", 6,
457
485
server, text+4, nick, channel_name,
462
490
server, text, nick, channel_name,
464
492
GINT_TO_POINTER(SEND_TARGET_CHANNEL));
495
signal_emit("message xmpp own_action", 4,
496
server, text+4, channel_name,
497
GINT_TO_POINTER(SEND_TARGET_CHANNEL));
499
signal_emit("message xmpp own_public", 3,
500
server, text, channel_name);
466
if (g_ascii_strncasecmp(text, "/me ", 4) == 0)
467
503
signal_emit("message xmpp action", 5,
468
504
server, text+4, nick, channel_name,
469
505
GINT_TO_POINTER(SEND_TARGET_CHANNEL));