mcabber/mcabber/xmpp_iqrequest.c
author Mikael Berthe <mikael@lilotux.net>
Sat, 28 Jul 2012 14:40:50 +0200
changeset 2017 87049d55e34f
parent 2004 aa7e03c35488
child 2103 1210a22726d3
permissions -rw-r--r--
Fix /request time /request time was still using Legacy Entity Time (XEP-90). This patch makes mcabber use XEP-202 for queries; mcabber still answers to both current and legacy queries.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1599
dcd5d4c75199 Update/Add headers
Mikael Berthe <mikael@lilotux.net>
parents: 1598
diff changeset
     1
/*
dcd5d4c75199 Update/Add headers
Mikael Berthe <mikael@lilotux.net>
parents: 1598
diff changeset
     2
 * xmpp_iqrequest.c -- Jabber IQ request handling
dcd5d4c75199 Update/Add headers
Mikael Berthe <mikael@lilotux.net>
parents: 1598
diff changeset
     3
 *
1729
e6e89b1d7831 Minor style and header updates
Mikael Berthe <mikael@lilotux.net>
parents: 1719
diff changeset
     4
 * Copyright (C) 2008-2010 Frank Zschockelt <mcabber@freakysoft.de>
e6e89b1d7831 Minor style and header updates
Mikael Berthe <mikael@lilotux.net>
parents: 1719
diff changeset
     5
 * Copyright (C) 2005-2010 Mikael Berthe <mikael@lilotux.net>
1599
dcd5d4c75199 Update/Add headers
Mikael Berthe <mikael@lilotux.net>
parents: 1598
diff changeset
     6
 *
dcd5d4c75199 Update/Add headers
Mikael Berthe <mikael@lilotux.net>
parents: 1598
diff changeset
     7
 * This program is free software; you can redistribute it and/or modify
dcd5d4c75199 Update/Add headers
Mikael Berthe <mikael@lilotux.net>
parents: 1598
diff changeset
     8
 * it under the terms of the GNU General Public License as published by
dcd5d4c75199 Update/Add headers
Mikael Berthe <mikael@lilotux.net>
parents: 1598
diff changeset
     9
 * the Free Software Foundation; either version 2 of the License, or (at
dcd5d4c75199 Update/Add headers
Mikael Berthe <mikael@lilotux.net>
parents: 1598
diff changeset
    10
 * your option) any later version.
dcd5d4c75199 Update/Add headers
Mikael Berthe <mikael@lilotux.net>
parents: 1598
diff changeset
    11
 *
dcd5d4c75199 Update/Add headers
Mikael Berthe <mikael@lilotux.net>
parents: 1598
diff changeset
    12
 * This program is distributed in the hope that it will be useful, but
dcd5d4c75199 Update/Add headers
Mikael Berthe <mikael@lilotux.net>
parents: 1598
diff changeset
    13
 * WITHOUT ANY WARRANTY; without even the implied warranty of
dcd5d4c75199 Update/Add headers
Mikael Berthe <mikael@lilotux.net>
parents: 1598
diff changeset
    14
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
dcd5d4c75199 Update/Add headers
Mikael Berthe <mikael@lilotux.net>
parents: 1598
diff changeset
    15
 * General Public License for more details.
dcd5d4c75199 Update/Add headers
Mikael Berthe <mikael@lilotux.net>
parents: 1598
diff changeset
    16
 *
dcd5d4c75199 Update/Add headers
Mikael Berthe <mikael@lilotux.net>
parents: 1598
diff changeset
    17
 * You should have received a copy of the GNU General Public License
dcd5d4c75199 Update/Add headers
Mikael Berthe <mikael@lilotux.net>
parents: 1598
diff changeset
    18
 * along with this program; if not, write to the Free Software
dcd5d4c75199 Update/Add headers
Mikael Berthe <mikael@lilotux.net>
parents: 1598
diff changeset
    19
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
dcd5d4c75199 Update/Add headers
Mikael Berthe <mikael@lilotux.net>
parents: 1598
diff changeset
    20
 * USA
dcd5d4c75199 Update/Add headers
Mikael Berthe <mikael@lilotux.net>
parents: 1598
diff changeset
    21
 */
1598
a087125d8fc8 Replace libjabber with loudmouth
franky
parents: 1575
diff changeset
    22
1604
351427ef0b4b Remove #include's of C files
Mikael Berthe <mikael@lilotux.net>
parents: 1599
diff changeset
    23
#include <string.h>
351427ef0b4b Remove #include's of C files
Mikael Berthe <mikael@lilotux.net>
parents: 1599
diff changeset
    24
#include <stdlib.h>
1705
ac881b5f9248 Add /request ping (XEP-0199), by merging isbear's module
Mikael Berthe <mikael@lilotux.net>
parents: 1703
diff changeset
    25
#include <sys/time.h>
1604
351427ef0b4b Remove #include's of C files
Mikael Berthe <mikael@lilotux.net>
parents: 1599
diff changeset
    26
351427ef0b4b Remove #include's of C files
Mikael Berthe <mikael@lilotux.net>
parents: 1599
diff changeset
    27
#include "xmpp_helper.h"
351427ef0b4b Remove #include's of C files
Mikael Berthe <mikael@lilotux.net>
parents: 1599
diff changeset
    28
#include "xmpp_iq.h"
351427ef0b4b Remove #include's of C files
Mikael Berthe <mikael@lilotux.net>
parents: 1599
diff changeset
    29
#include "screen.h"
351427ef0b4b Remove #include's of C files
Mikael Berthe <mikael@lilotux.net>
parents: 1599
diff changeset
    30
#include "utils.h"
351427ef0b4b Remove #include's of C files
Mikael Berthe <mikael@lilotux.net>
parents: 1599
diff changeset
    31
#include "settings.h"
351427ef0b4b Remove #include's of C files
Mikael Berthe <mikael@lilotux.net>
parents: 1599
diff changeset
    32
#include "hooks.h"
351427ef0b4b Remove #include's of C files
Mikael Berthe <mikael@lilotux.net>
parents: 1599
diff changeset
    33
#include "hbuf.h"
351427ef0b4b Remove #include's of C files
Mikael Berthe <mikael@lilotux.net>
parents: 1599
diff changeset
    34
351427ef0b4b Remove #include's of C files
Mikael Berthe <mikael@lilotux.net>
parents: 1599
diff changeset
    35
extern LmMessageNode *bookmarks;
351427ef0b4b Remove #include's of C files
Mikael Berthe <mikael@lilotux.net>
parents: 1599
diff changeset
    36
extern LmMessageNode *rosternotes;
351427ef0b4b Remove #include's of C files
Mikael Berthe <mikael@lilotux.net>
parents: 1599
diff changeset
    37
1598
a087125d8fc8 Replace libjabber with loudmouth
franky
parents: 1575
diff changeset
    38
static LmHandlerResult cb_roster(LmMessageHandler *h, LmConnection *c,
a087125d8fc8 Replace libjabber with loudmouth
franky
parents: 1575
diff changeset
    39
                                 LmMessage *m, gpointer user_data);
a087125d8fc8 Replace libjabber with loudmouth
franky
parents: 1575
diff changeset
    40
static LmHandlerResult cb_version(LmMessageHandler *h, LmConnection *c,
a087125d8fc8 Replace libjabber with loudmouth
franky
parents: 1575
diff changeset
    41
                                  LmMessage *m, gpointer user_data);
a087125d8fc8 Replace libjabber with loudmouth
franky
parents: 1575
diff changeset
    42
static LmHandlerResult cb_time(LmMessageHandler *h, LmConnection *c,
a087125d8fc8 Replace libjabber with loudmouth
franky
parents: 1575
diff changeset
    43
                               LmMessage *m, gpointer user_data);
a087125d8fc8 Replace libjabber with loudmouth
franky
parents: 1575
diff changeset
    44
static LmHandlerResult cb_last(LmMessageHandler *h, LmConnection *c,
a087125d8fc8 Replace libjabber with loudmouth
franky
parents: 1575
diff changeset
    45
                               LmMessage *m, gpointer user_data);
1705
ac881b5f9248 Add /request ping (XEP-0199), by merging isbear's module
Mikael Berthe <mikael@lilotux.net>
parents: 1703
diff changeset
    46
static LmHandlerResult cb_ping(LmMessageHandler *h, LmConnection *c,
ac881b5f9248 Add /request ping (XEP-0199), by merging isbear's module
Mikael Berthe <mikael@lilotux.net>
parents: 1703
diff changeset
    47
                               LmMessage *m, gpointer user_data);
1598
a087125d8fc8 Replace libjabber with loudmouth
franky
parents: 1575
diff changeset
    48
static LmHandlerResult cb_vcard(LmMessageHandler *h, LmConnection *c,
a087125d8fc8 Replace libjabber with loudmouth
franky
parents: 1575
diff changeset
    49
                               LmMessage *m, gpointer user_data);
29
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
    50
1598
a087125d8fc8 Replace libjabber with loudmouth
franky
parents: 1575
diff changeset
    51
static struct IqRequestHandlers
a087125d8fc8 Replace libjabber with loudmouth
franky
parents: 1575
diff changeset
    52
{
a087125d8fc8 Replace libjabber with loudmouth
franky
parents: 1575
diff changeset
    53
  const gchar *xmlns;
a087125d8fc8 Replace libjabber with loudmouth
franky
parents: 1575
diff changeset
    54
  const gchar *querytag;
a087125d8fc8 Replace libjabber with loudmouth
franky
parents: 1575
diff changeset
    55
  LmHandleMessageFunction handler;
a087125d8fc8 Replace libjabber with loudmouth
franky
parents: 1575
diff changeset
    56
} iq_request_handlers[] = {
2017
87049d55e34f Fix /request time
Mikael Berthe <mikael@lilotux.net>
parents: 2004
diff changeset
    57
  {NS_ROSTER,   "query", &cb_roster},
87049d55e34f Fix /request time
Mikael Berthe <mikael@lilotux.net>
parents: 2004
diff changeset
    58
  {NS_VERSION,  "query", &cb_version},
87049d55e34f Fix /request time
Mikael Berthe <mikael@lilotux.net>
parents: 2004
diff changeset
    59
  {NS_XMPP_TIME,"time",  &cb_time},
87049d55e34f Fix /request time
Mikael Berthe <mikael@lilotux.net>
parents: 2004
diff changeset
    60
  {NS_LAST,     "query", &cb_last},
87049d55e34f Fix /request time
Mikael Berthe <mikael@lilotux.net>
parents: 2004
diff changeset
    61
  {NS_PING,     "ping",  &cb_ping},
87049d55e34f Fix /request time
Mikael Berthe <mikael@lilotux.net>
parents: 2004
diff changeset
    62
  {NS_VCARD,    "vCard", &cb_vcard},
1598
a087125d8fc8 Replace libjabber with loudmouth
franky
parents: 1575
diff changeset
    63
  {NULL, NULL, NULL}
a087125d8fc8 Replace libjabber with loudmouth
franky
parents: 1575
diff changeset
    64
};
1254
401639413340 More jabber:iq:last support... (misc)
Mikael Berthe <mikael@lilotux.net>
parents: 1224
diff changeset
    65
1006
f61131cd86a0 Clean up vcard code
Mikael Berthe <mikael@lilotux.net>
parents: 1005
diff changeset
    66
// Enum for vCard attributes
f61131cd86a0 Clean up vcard code
Mikael Berthe <mikael@lilotux.net>
parents: 1005
diff changeset
    67
enum vcard_attr {
f61131cd86a0 Clean up vcard code
Mikael Berthe <mikael@lilotux.net>
parents: 1005
diff changeset
    68
  vcard_home    = 1<<0,
f61131cd86a0 Clean up vcard code
Mikael Berthe <mikael@lilotux.net>
parents: 1005
diff changeset
    69
  vcard_work    = 1<<1,
f61131cd86a0 Clean up vcard code
Mikael Berthe <mikael@lilotux.net>
parents: 1005
diff changeset
    70
  vcard_postal  = 1<<2,
f61131cd86a0 Clean up vcard code
Mikael Berthe <mikael@lilotux.net>
parents: 1005
diff changeset
    71
  vcard_voice   = 1<<3,
f61131cd86a0 Clean up vcard code
Mikael Berthe <mikael@lilotux.net>
parents: 1005
diff changeset
    72
  vcard_fax     = 1<<4,
f61131cd86a0 Clean up vcard code
Mikael Berthe <mikael@lilotux.net>
parents: 1005
diff changeset
    73
  vcard_cell    = 1<<5,
f61131cd86a0 Clean up vcard code
Mikael Berthe <mikael@lilotux.net>
parents: 1005
diff changeset
    74
  vcard_inet    = 1<<6,
f61131cd86a0 Clean up vcard code
Mikael Berthe <mikael@lilotux.net>
parents: 1005
diff changeset
    75
  vcard_pref    = 1<<7,
f61131cd86a0 Clean up vcard code
Mikael Berthe <mikael@lilotux.net>
parents: 1005
diff changeset
    76
};
683
c5e0d8c3f00c Introduce new IQ system
Mikael Berthe <mikael@lilotux.net>
parents: 619
diff changeset
    77
1705
ac881b5f9248 Add /request ping (XEP-0199), by merging isbear's module
Mikael Berthe <mikael@lilotux.net>
parents: 1703
diff changeset
    78
static LmHandlerResult cb_ping(LmMessageHandler *h, LmConnection *c,
1706
a5263e93c5d7 Fix pinging oneself
Mikael Berthe <mikael@lilotux.net>
parents: 1705
diff changeset
    79
                               LmMessage *m, gpointer user_data)
1705
ac881b5f9248 Add /request ping (XEP-0199), by merging isbear's module
Mikael Berthe <mikael@lilotux.net>
parents: 1703
diff changeset
    80
{
1706
a5263e93c5d7 Fix pinging oneself
Mikael Berthe <mikael@lilotux.net>
parents: 1705
diff changeset
    81
  struct timeval *timestamp = (struct timeval *)user_data;
1705
ac881b5f9248 Add /request ping (XEP-0199), by merging isbear's module
Mikael Berthe <mikael@lilotux.net>
parents: 1703
diff changeset
    82
  struct timeval now;
ac881b5f9248 Add /request ping (XEP-0199), by merging isbear's module
Mikael Berthe <mikael@lilotux.net>
parents: 1703
diff changeset
    83
  time_t         dsec;
ac881b5f9248 Add /request ping (XEP-0199), by merging isbear's module
Mikael Berthe <mikael@lilotux.net>
parents: 1703
diff changeset
    84
  suseconds_t    dusec;
1706
a5263e93c5d7 Fix pinging oneself
Mikael Berthe <mikael@lilotux.net>
parents: 1705
diff changeset
    85
  const gchar    *fjid;
1707
184de76b5b18 Refactor some code
Mikael Berthe <mikael@lilotux.net>
parents: 1706
diff changeset
    86
  gchar          *bjid, *mesg = NULL;
1705
ac881b5f9248 Add /request ping (XEP-0199), by merging isbear's module
Mikael Berthe <mikael@lilotux.net>
parents: 1703
diff changeset
    87
ac881b5f9248 Add /request ping (XEP-0199), by merging isbear's module
Mikael Berthe <mikael@lilotux.net>
parents: 1703
diff changeset
    88
  gettimeofday(&now, NULL);
ac881b5f9248 Add /request ping (XEP-0199), by merging isbear's module
Mikael Berthe <mikael@lilotux.net>
parents: 1703
diff changeset
    89
  dsec = now.tv_sec - timestamp->tv_sec;
ac881b5f9248 Add /request ping (XEP-0199), by merging isbear's module
Mikael Berthe <mikael@lilotux.net>
parents: 1703
diff changeset
    90
  if (now.tv_usec < timestamp->tv_usec) {
ac881b5f9248 Add /request ping (XEP-0199), by merging isbear's module
Mikael Berthe <mikael@lilotux.net>
parents: 1703
diff changeset
    91
    dusec = now.tv_usec + 1000000 - timestamp->tv_usec;
ac881b5f9248 Add /request ping (XEP-0199), by merging isbear's module
Mikael Berthe <mikael@lilotux.net>
parents: 1703
diff changeset
    92
    --dsec;
ac881b5f9248 Add /request ping (XEP-0199), by merging isbear's module
Mikael Berthe <mikael@lilotux.net>
parents: 1703
diff changeset
    93
  } else
ac881b5f9248 Add /request ping (XEP-0199), by merging isbear's module
Mikael Berthe <mikael@lilotux.net>
parents: 1703
diff changeset
    94
    dusec = now.tv_usec - timestamp->tv_usec;
ac881b5f9248 Add /request ping (XEP-0199), by merging isbear's module
Mikael Berthe <mikael@lilotux.net>
parents: 1703
diff changeset
    95
1706
a5263e93c5d7 Fix pinging oneself
Mikael Berthe <mikael@lilotux.net>
parents: 1705
diff changeset
    96
  // Check IQ result sender
a5263e93c5d7 Fix pinging oneself
Mikael Berthe <mikael@lilotux.net>
parents: 1705
diff changeset
    97
  fjid = lm_message_get_from(m);
a5263e93c5d7 Fix pinging oneself
Mikael Berthe <mikael@lilotux.net>
parents: 1705
diff changeset
    98
  if (!fjid)
a5263e93c5d7 Fix pinging oneself
Mikael Berthe <mikael@lilotux.net>
parents: 1705
diff changeset
    99
    fjid = lm_connection_get_jid(lconnection); // No from means our JID...
a5263e93c5d7 Fix pinging oneself
Mikael Berthe <mikael@lilotux.net>
parents: 1705
diff changeset
   100
  if (!fjid) {
a5263e93c5d7 Fix pinging oneself
Mikael Berthe <mikael@lilotux.net>
parents: 1705
diff changeset
   101
    scr_LogPrint(LPRINT_LOGNORM, "Invalid IQ:version result (no sender name).");
a5263e93c5d7 Fix pinging oneself
Mikael Berthe <mikael@lilotux.net>
parents: 1705
diff changeset
   102
    return LM_HANDLER_RESULT_REMOVE_MESSAGE;
a5263e93c5d7 Fix pinging oneself
Mikael Berthe <mikael@lilotux.net>
parents: 1705
diff changeset
   103
  }
a5263e93c5d7 Fix pinging oneself
Mikael Berthe <mikael@lilotux.net>
parents: 1705
diff changeset
   104
a5263e93c5d7 Fix pinging oneself
Mikael Berthe <mikael@lilotux.net>
parents: 1705
diff changeset
   105
  bjid  = jidtodisp(fjid);
a5263e93c5d7 Fix pinging oneself
Mikael Berthe <mikael@lilotux.net>
parents: 1705
diff changeset
   106
a5263e93c5d7 Fix pinging oneself
Mikael Berthe <mikael@lilotux.net>
parents: 1705
diff changeset
   107
  switch (lm_message_get_sub_type(m)) {
1705
ac881b5f9248 Add /request ping (XEP-0199), by merging isbear's module
Mikael Berthe <mikael@lilotux.net>
parents: 1703
diff changeset
   108
    case LM_MESSAGE_SUB_TYPE_RESULT:
1707
184de76b5b18 Refactor some code
Mikael Berthe <mikael@lilotux.net>
parents: 1706
diff changeset
   109
        mesg = g_strdup_printf("Pong from <%s>: %d second%s %d ms.", fjid,
184de76b5b18 Refactor some code
Mikael Berthe <mikael@lilotux.net>
parents: 1706
diff changeset
   110
                               (int)dsec, dsec > 1 ? "s" : "",
184de76b5b18 Refactor some code
Mikael Berthe <mikael@lilotux.net>
parents: 1706
diff changeset
   111
                               (int)(dusec/1000L));
1705
ac881b5f9248 Add /request ping (XEP-0199), by merging isbear's module
Mikael Berthe <mikael@lilotux.net>
parents: 1703
diff changeset
   112
        break;
ac881b5f9248 Add /request ping (XEP-0199), by merging isbear's module
Mikael Berthe <mikael@lilotux.net>
parents: 1703
diff changeset
   113
ac881b5f9248 Add /request ping (XEP-0199), by merging isbear's module
Mikael Berthe <mikael@lilotux.net>
parents: 1703
diff changeset
   114
    case LM_MESSAGE_SUB_TYPE_ERROR:
1800
d2747442918a When displaying a server error, show the sender JID
Mikael Berthe <mikael@lilotux.net>
parents: 1729
diff changeset
   115
        display_server_error(lm_message_node_get_child(m->node, "error"),
d2747442918a When displaying a server error, show the sender JID
Mikael Berthe <mikael@lilotux.net>
parents: 1729
diff changeset
   116
                             fjid);
1707
184de76b5b18 Refactor some code
Mikael Berthe <mikael@lilotux.net>
parents: 1706
diff changeset
   117
        mesg = g_strdup_printf("Ping to <%s> failed.  "
184de76b5b18 Refactor some code
Mikael Berthe <mikael@lilotux.net>
parents: 1706
diff changeset
   118
                               "Response time: %d second%s %d ms.",
184de76b5b18 Refactor some code
Mikael Berthe <mikael@lilotux.net>
parents: 1706
diff changeset
   119
                               fjid, (int)dsec, dsec > 1 ? "s" : "",
184de76b5b18 Refactor some code
Mikael Berthe <mikael@lilotux.net>
parents: 1706
diff changeset
   120
                               (int)(dusec/1000L));
1705
ac881b5f9248 Add /request ping (XEP-0199), by merging isbear's module
Mikael Berthe <mikael@lilotux.net>
parents: 1703
diff changeset
   121
        break;
ac881b5f9248 Add /request ping (XEP-0199), by merging isbear's module
Mikael Berthe <mikael@lilotux.net>
parents: 1703
diff changeset
   122
ac881b5f9248 Add /request ping (XEP-0199), by merging isbear's module
Mikael Berthe <mikael@lilotux.net>
parents: 1703
diff changeset
   123
    default:
1706
a5263e93c5d7 Fix pinging oneself
Mikael Berthe <mikael@lilotux.net>
parents: 1705
diff changeset
   124
        g_free(bjid);
1705
ac881b5f9248 Add /request ping (XEP-0199), by merging isbear's module
Mikael Berthe <mikael@lilotux.net>
parents: 1703
diff changeset
   125
        return LM_HANDLER_RESULT_ALLOW_MORE_HANDLERS;
ac881b5f9248 Add /request ping (XEP-0199), by merging isbear's module
Mikael Berthe <mikael@lilotux.net>
parents: 1703
diff changeset
   126
        break;
ac881b5f9248 Add /request ping (XEP-0199), by merging isbear's module
Mikael Berthe <mikael@lilotux.net>
parents: 1703
diff changeset
   127
  }
ac881b5f9248 Add /request ping (XEP-0199), by merging isbear's module
Mikael Berthe <mikael@lilotux.net>
parents: 1703
diff changeset
   128
1707
184de76b5b18 Refactor some code
Mikael Berthe <mikael@lilotux.net>
parents: 1706
diff changeset
   129
  if (mesg)
184de76b5b18 Refactor some code
Mikael Berthe <mikael@lilotux.net>
parents: 1706
diff changeset
   130
    scr_WriteIncomingMessage(bjid, mesg, 0, HBB_PREFIX_INFO, 0);
184de76b5b18 Refactor some code
Mikael Berthe <mikael@lilotux.net>
parents: 1706
diff changeset
   131
  g_free(mesg);
1706
a5263e93c5d7 Fix pinging oneself
Mikael Berthe <mikael@lilotux.net>
parents: 1705
diff changeset
   132
  g_free(bjid);
1705
ac881b5f9248 Add /request ping (XEP-0199), by merging isbear's module
Mikael Berthe <mikael@lilotux.net>
parents: 1703
diff changeset
   133
  return LM_HANDLER_RESULT_REMOVE_MESSAGE;
ac881b5f9248 Add /request ping (XEP-0199), by merging isbear's module
Mikael Berthe <mikael@lilotux.net>
parents: 1703
diff changeset
   134
}
ac881b5f9248 Add /request ping (XEP-0199), by merging isbear's module
Mikael Berthe <mikael@lilotux.net>
parents: 1703
diff changeset
   135
ac881b5f9248 Add /request ping (XEP-0199), by merging isbear's module
Mikael Berthe <mikael@lilotux.net>
parents: 1703
diff changeset
   136
// Warning!! xmlns has to be a namespace from iq_request_handlers[].xmlns
1598
a087125d8fc8 Replace libjabber with loudmouth
franky
parents: 1575
diff changeset
   137
void xmpp_iq_request(const char *fulljid, const char *xmlns)
1215
80c095886fb5 Entity Capabilities support (XEP-0115)
Mikael Berthe <mikael@lilotux.net>
parents: 1213
diff changeset
   138
{
1598
a087125d8fc8 Replace libjabber with loudmouth
franky
parents: 1575
diff changeset
   139
  LmMessage *iq;
a087125d8fc8 Replace libjabber with loudmouth
franky
parents: 1575
diff changeset
   140
  LmMessageNode *query;
a087125d8fc8 Replace libjabber with loudmouth
franky
parents: 1575
diff changeset
   141
  LmMessageHandler *handler;
1705
ac881b5f9248 Add /request ping (XEP-0199), by merging isbear's module
Mikael Berthe <mikael@lilotux.net>
parents: 1703
diff changeset
   142
  gpointer data = NULL;
ac881b5f9248 Add /request ping (XEP-0199), by merging isbear's module
Mikael Berthe <mikael@lilotux.net>
parents: 1703
diff changeset
   143
  GDestroyNotify notifier = NULL;
ac881b5f9248 Add /request ping (XEP-0199), by merging isbear's module
Mikael Berthe <mikael@lilotux.net>
parents: 1703
diff changeset
   144
  GError *error = NULL;
1598
a087125d8fc8 Replace libjabber with loudmouth
franky
parents: 1575
diff changeset
   145
  int i;
683
c5e0d8c3f00c Introduce new IQ system
Mikael Berthe <mikael@lilotux.net>
parents: 619
diff changeset
   146
1598
a087125d8fc8 Replace libjabber with loudmouth
franky
parents: 1575
diff changeset
   147
  iq = lm_message_new_with_sub_type(fulljid, LM_MESSAGE_TYPE_IQ,
a087125d8fc8 Replace libjabber with loudmouth
franky
parents: 1575
diff changeset
   148
                                    LM_MESSAGE_SUB_TYPE_GET);
2017
87049d55e34f Fix /request time
Mikael Berthe <mikael@lilotux.net>
parents: 2004
diff changeset
   149
  for (i = 0; iq_request_handlers[i].xmlns &&
87049d55e34f Fix /request time
Mikael Berthe <mikael@lilotux.net>
parents: 2004
diff changeset
   150
              strcmp(iq_request_handlers[i].xmlns, xmlns) != 0 ; ++i)
1598
a087125d8fc8 Replace libjabber with loudmouth
franky
parents: 1575
diff changeset
   151
       ;
a087125d8fc8 Replace libjabber with loudmouth
franky
parents: 1575
diff changeset
   152
  query = lm_message_node_add_child(iq->node,
a087125d8fc8 Replace libjabber with loudmouth
franky
parents: 1575
diff changeset
   153
                                    iq_request_handlers[i].querytag,
a087125d8fc8 Replace libjabber with loudmouth
franky
parents: 1575
diff changeset
   154
                                    NULL);
a087125d8fc8 Replace libjabber with loudmouth
franky
parents: 1575
diff changeset
   155
  lm_message_node_set_attribute(query, "xmlns", xmlns);
1705
ac881b5f9248 Add /request ping (XEP-0199), by merging isbear's module
Mikael Berthe <mikael@lilotux.net>
parents: 1703
diff changeset
   156
ac881b5f9248 Add /request ping (XEP-0199), by merging isbear's module
Mikael Berthe <mikael@lilotux.net>
parents: 1703
diff changeset
   157
  if (!g_strcmp0(xmlns, NS_PING)) {     // Create handler for ping queries
ac881b5f9248 Add /request ping (XEP-0199), by merging isbear's module
Mikael Berthe <mikael@lilotux.net>
parents: 1703
diff changeset
   158
    struct timeval *now = g_new(struct timeval, 1);
ac881b5f9248 Add /request ping (XEP-0199), by merging isbear's module
Mikael Berthe <mikael@lilotux.net>
parents: 1703
diff changeset
   159
    gettimeofday(now, NULL);
ac881b5f9248 Add /request ping (XEP-0199), by merging isbear's module
Mikael Berthe <mikael@lilotux.net>
parents: 1703
diff changeset
   160
    data = (gpointer)now;
ac881b5f9248 Add /request ping (XEP-0199), by merging isbear's module
Mikael Berthe <mikael@lilotux.net>
parents: 1703
diff changeset
   161
    notifier = g_free;
ac881b5f9248 Add /request ping (XEP-0199), by merging isbear's module
Mikael Berthe <mikael@lilotux.net>
parents: 1703
diff changeset
   162
  }
ac881b5f9248 Add /request ping (XEP-0199), by merging isbear's module
Mikael Berthe <mikael@lilotux.net>
parents: 1703
diff changeset
   163
1598
a087125d8fc8 Replace libjabber with loudmouth
franky
parents: 1575
diff changeset
   164
  handler = lm_message_handler_new(iq_request_handlers[i].handler,
1705
ac881b5f9248 Add /request ping (XEP-0199), by merging isbear's module
Mikael Berthe <mikael@lilotux.net>
parents: 1703
diff changeset
   165
                                   data, notifier);
ac881b5f9248 Add /request ping (XEP-0199), by merging isbear's module
Mikael Berthe <mikael@lilotux.net>
parents: 1703
diff changeset
   166
ac881b5f9248 Add /request ping (XEP-0199), by merging isbear's module
Mikael Berthe <mikael@lilotux.net>
parents: 1703
diff changeset
   167
  lm_connection_send_with_reply(lconnection, iq, handler, &error);
1598
a087125d8fc8 Replace libjabber with loudmouth
franky
parents: 1575
diff changeset
   168
  lm_message_handler_unref(handler);
a087125d8fc8 Replace libjabber with loudmouth
franky
parents: 1575
diff changeset
   169
  lm_message_unref(iq);
1705
ac881b5f9248 Add /request ping (XEP-0199), by merging isbear's module
Mikael Berthe <mikael@lilotux.net>
parents: 1703
diff changeset
   170
ac881b5f9248 Add /request ping (XEP-0199), by merging isbear's module
Mikael Berthe <mikael@lilotux.net>
parents: 1703
diff changeset
   171
  if (error) {
ac881b5f9248 Add /request ping (XEP-0199), by merging isbear's module
Mikael Berthe <mikael@lilotux.net>
parents: 1703
diff changeset
   172
    scr_LogPrint(LPRINT_LOGNORM, "Error sending IQ request: %s.", error->message);
ac881b5f9248 Add /request ping (XEP-0199), by merging isbear's module
Mikael Berthe <mikael@lilotux.net>
parents: 1703
diff changeset
   173
    g_error_free(error);
ac881b5f9248 Add /request ping (XEP-0199), by merging isbear's module
Mikael Berthe <mikael@lilotux.net>
parents: 1703
diff changeset
   174
  }
577
5c6d364130ee Move IQ Jabber stuff to a separate file
Mikael Berthe <mikael@lilotux.net>
parents: 576
diff changeset
   175
}
29
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
   176
1353
7caedca15e50 Add post-connect internal hook
Mikael Berthe <mikael@lilotux.net>
parents: 1348
diff changeset
   177
//  This callback is reached when mcabber receives the first roster update
7caedca15e50 Add post-connect internal hook
Mikael Berthe <mikael@lilotux.net>
parents: 1348
diff changeset
   178
// after the connection.
1598
a087125d8fc8 Replace libjabber with loudmouth
franky
parents: 1575
diff changeset
   179
static LmHandlerResult cb_roster(LmMessageHandler *h, LmConnection *c,
a087125d8fc8 Replace libjabber with loudmouth
franky
parents: 1575
diff changeset
   180
                                 LmMessage *m, gpointer user_data)
1353
7caedca15e50 Add post-connect internal hook
Mikael Berthe <mikael@lilotux.net>
parents: 1348
diff changeset
   181
{
1598
a087125d8fc8 Replace libjabber with loudmouth
franky
parents: 1575
diff changeset
   182
  LmMessageNode *x;
a087125d8fc8 Replace libjabber with loudmouth
franky
parents: 1575
diff changeset
   183
  const char *ns;
1353
7caedca15e50 Add post-connect internal hook
Mikael Berthe <mikael@lilotux.net>
parents: 1348
diff changeset
   184
7caedca15e50 Add post-connect internal hook
Mikael Berthe <mikael@lilotux.net>
parents: 1348
diff changeset
   185
  // Only execute the hook if the roster has been successfully retrieved
1598
a087125d8fc8 Replace libjabber with loudmouth
franky
parents: 1575
diff changeset
   186
  if (lm_message_get_sub_type(m) != LM_MESSAGE_SUB_TYPE_RESULT)
a087125d8fc8 Replace libjabber with loudmouth
franky
parents: 1575
diff changeset
   187
    return LM_HANDLER_RESULT_ALLOW_MORE_HANDLERS;
1353
7caedca15e50 Add post-connect internal hook
Mikael Berthe <mikael@lilotux.net>
parents: 1348
diff changeset
   188
1598
a087125d8fc8 Replace libjabber with loudmouth
franky
parents: 1575
diff changeset
   189
  x = lm_message_node_find_child(m->node, "query");
1353
7caedca15e50 Add post-connect internal hook
Mikael Berthe <mikael@lilotux.net>
parents: 1348
diff changeset
   190
  if (!x)
1598
a087125d8fc8 Replace libjabber with loudmouth
franky
parents: 1575
diff changeset
   191
    return LM_HANDLER_RESULT_ALLOW_MORE_HANDLERS;
1365
c7e709719c43 Small code cleanup
Mikael Berthe <mikael@lilotux.net>
parents: 1361
diff changeset
   192
1598
a087125d8fc8 Replace libjabber with loudmouth
franky
parents: 1575
diff changeset
   193
  ns = lm_message_node_get_attribute(x, "xmlns");
1365
c7e709719c43 Small code cleanup
Mikael Berthe <mikael@lilotux.net>
parents: 1361
diff changeset
   194
  if (ns && !strcmp(ns, NS_ROSTER))
1598
a087125d8fc8 Replace libjabber with loudmouth
franky
parents: 1575
diff changeset
   195
    handle_iq_roster(NULL, c, m, user_data);
1353
7caedca15e50 Add post-connect internal hook
Mikael Berthe <mikael@lilotux.net>
parents: 1348
diff changeset
   196
7caedca15e50 Add post-connect internal hook
Mikael Berthe <mikael@lilotux.net>
parents: 1348
diff changeset
   197
  // Post-login stuff
1683
b09f82f61745 Split HOOK_INTERNAL
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1668
diff changeset
   198
  hk_postconnect();
1353
7caedca15e50 Add post-connect internal hook
Mikael Berthe <mikael@lilotux.net>
parents: 1348
diff changeset
   199
1598
a087125d8fc8 Replace libjabber with loudmouth
franky
parents: 1575
diff changeset
   200
  return LM_HANDLER_RESULT_REMOVE_MESSAGE;
1353
7caedca15e50 Add post-connect internal hook
Mikael Berthe <mikael@lilotux.net>
parents: 1348
diff changeset
   201
}
7caedca15e50 Add post-connect internal hook
Mikael Berthe <mikael@lilotux.net>
parents: 1348
diff changeset
   202
1598
a087125d8fc8 Replace libjabber with loudmouth
franky
parents: 1575
diff changeset
   203
static LmHandlerResult cb_version(LmMessageHandler *h, LmConnection *c,
a087125d8fc8 Replace libjabber with loudmouth
franky
parents: 1575
diff changeset
   204
                                  LmMessage *m, gpointer user_data)
1353
7caedca15e50 Add post-connect internal hook
Mikael Berthe <mikael@lilotux.net>
parents: 1348
diff changeset
   205
{
1598
a087125d8fc8 Replace libjabber with loudmouth
franky
parents: 1575
diff changeset
   206
  LmMessageNode *ansqry;
a087125d8fc8 Replace libjabber with loudmouth
franky
parents: 1575
diff changeset
   207
  const char *p, *bjid;
1703
65ba89949252 Improve error checks in received IQ responses
Mikael Berthe <mikael@lilotux.net>
parents: 1699
diff changeset
   208
  char *buf, *tmp;
690
3e965a1186c7 Implement IQ:version requests
Mikael Berthe <mikael@lilotux.net>
parents: 689
diff changeset
   209
1703
65ba89949252 Improve error checks in received IQ responses
Mikael Berthe <mikael@lilotux.net>
parents: 1699
diff changeset
   210
  // Check IQ result sender
1698
e67bdd863638 Handle IQ responses with no "from"
Mikael Berthe <mikael@lilotux.net>
parents: 1683
diff changeset
   211
  bjid = lm_message_get_from(m);
e67bdd863638 Handle IQ responses with no "from"
Mikael Berthe <mikael@lilotux.net>
parents: 1683
diff changeset
   212
  if (!bjid)
1699
527c965b45c5 Add small comment in previous change
Mikael Berthe <mikael@lilotux.net>
parents: 1698
diff changeset
   213
    bjid = lm_connection_get_jid(lconnection); // No from means our JID...
1698
e67bdd863638 Handle IQ responses with no "from"
Mikael Berthe <mikael@lilotux.net>
parents: 1683
diff changeset
   214
  if (!bjid) {
690
3e965a1186c7 Implement IQ:version requests
Mikael Berthe <mikael@lilotux.net>
parents: 689
diff changeset
   215
    scr_LogPrint(LPRINT_LOGNORM, "Invalid IQ:version result (no sender name).");
1698
e67bdd863638 Handle IQ responses with no "from"
Mikael Berthe <mikael@lilotux.net>
parents: 1683
diff changeset
   216
    return LM_HANDLER_RESULT_REMOVE_MESSAGE;
690
3e965a1186c7 Implement IQ:version requests
Mikael Berthe <mikael@lilotux.net>
parents: 689
diff changeset
   217
  }
704
4118a66f2c02 Display IQ results (time, version) in the chat window
Mikael Berthe <mikael@lilotux.net>
parents: 703
diff changeset
   218
1703
65ba89949252 Improve error checks in received IQ responses
Mikael Berthe <mikael@lilotux.net>
parents: 1699
diff changeset
   219
  // Check for error message
65ba89949252 Improve error checks in received IQ responses
Mikael Berthe <mikael@lilotux.net>
parents: 1699
diff changeset
   220
  if (lm_message_get_sub_type(m) == LM_MESSAGE_SUB_TYPE_ERROR) {
65ba89949252 Improve error checks in received IQ responses
Mikael Berthe <mikael@lilotux.net>
parents: 1699
diff changeset
   221
    scr_LogPrint(LPRINT_LOGNORM, "Received error IQ message (%s)", bjid);
1800
d2747442918a When displaying a server error, show the sender JID
Mikael Berthe <mikael@lilotux.net>
parents: 1729
diff changeset
   222
    display_server_error(lm_message_node_get_child(m->node, "error"), NULL);
1703
65ba89949252 Improve error checks in received IQ responses
Mikael Berthe <mikael@lilotux.net>
parents: 1699
diff changeset
   223
    return LM_HANDLER_RESULT_REMOVE_MESSAGE;
65ba89949252 Improve error checks in received IQ responses
Mikael Berthe <mikael@lilotux.net>
parents: 1699
diff changeset
   224
  }
65ba89949252 Improve error checks in received IQ responses
Mikael Berthe <mikael@lilotux.net>
parents: 1699
diff changeset
   225
65ba89949252 Improve error checks in received IQ responses
Mikael Berthe <mikael@lilotux.net>
parents: 1699
diff changeset
   226
  // Check message contents
65ba89949252 Improve error checks in received IQ responses
Mikael Berthe <mikael@lilotux.net>
parents: 1699
diff changeset
   227
  ansqry = lm_message_node_get_child(m->node, "query");
65ba89949252 Improve error checks in received IQ responses
Mikael Berthe <mikael@lilotux.net>
parents: 1699
diff changeset
   228
  if (!ansqry) {
65ba89949252 Improve error checks in received IQ responses
Mikael Berthe <mikael@lilotux.net>
parents: 1699
diff changeset
   229
    scr_LogPrint(LPRINT_LOGNORM, "Invalid IQ:version result from <%s>!", bjid);
65ba89949252 Improve error checks in received IQ responses
Mikael Berthe <mikael@lilotux.net>
parents: 1699
diff changeset
   230
    return LM_HANDLER_RESULT_REMOVE_MESSAGE;
65ba89949252 Improve error checks in received IQ responses
Mikael Berthe <mikael@lilotux.net>
parents: 1699
diff changeset
   231
  }
65ba89949252 Improve error checks in received IQ responses
Mikael Berthe <mikael@lilotux.net>
parents: 1699
diff changeset
   232
782
19121d9f4aa2 Nicer message when receiving IQ result packet
Mikael Berthe <mikael@lilotux.net>
parents: 776
diff changeset
   233
  buf = g_strdup_printf("Received IQ:version result from <%s>", bjid);
704
4118a66f2c02 Display IQ results (time, version) in the chat window
Mikael Berthe <mikael@lilotux.net>
parents: 703
diff changeset
   234
  scr_LogPrint(LPRINT_LOGNORM, "%s", buf);
4118a66f2c02 Display IQ results (time, version) in the chat window
Mikael Berthe <mikael@lilotux.net>
parents: 703
diff changeset
   235
4118a66f2c02 Display IQ results (time, version) in the chat window
Mikael Berthe <mikael@lilotux.net>
parents: 703
diff changeset
   236
  // bjid should now really be the "bare JID", let's strip the resource
1598
a087125d8fc8 Replace libjabber with loudmouth
franky
parents: 1575
diff changeset
   237
  tmp = strchr(bjid, JID_RESOURCE_SEPARATOR);
a087125d8fc8 Replace libjabber with loudmouth
franky
parents: 1575
diff changeset
   238
  if (tmp) *tmp = '\0';
704
4118a66f2c02 Display IQ results (time, version) in the chat window
Mikael Berthe <mikael@lilotux.net>
parents: 703
diff changeset
   239
1290
e42f48103609 Drawing the MUC nicks by a different color
Michal 'vorner' Vaner <vorner@ucw.cz>
parents: 1283
diff changeset
   240
  scr_WriteIncomingMessage(bjid, buf, 0, HBB_PREFIX_INFO, 0);
704
4118a66f2c02 Display IQ results (time, version) in the chat window
Mikael Berthe <mikael@lilotux.net>
parents: 703
diff changeset
   241
  g_free(buf);
4118a66f2c02 Display IQ results (time, version) in the chat window
Mikael Berthe <mikael@lilotux.net>
parents: 703
diff changeset
   242
690
3e965a1186c7 Implement IQ:version requests
Mikael Berthe <mikael@lilotux.net>
parents: 689
diff changeset
   243
  // Get result data...
1598
a087125d8fc8 Replace libjabber with loudmouth
franky
parents: 1575
diff changeset
   244
  p = lm_message_node_get_child_value(ansqry, "name");
1899
decf94827efe More lm_message_node_get_child_value() return value checks
Mikael Berthe <mikael@lilotux.net>
parents: 1811
diff changeset
   245
  if (p && *p) {
1030
923cf5a92b44 [BP-dd9e7eb5f8a8] Remove old UTF-8 conversions
Mikael Berthe <mikael@lilotux.net>
parents: 965
diff changeset
   246
    buf = g_strdup_printf("Name:    %s", p);
1333
e30a9d907105 Minor coding style adjustments
Mikael Berthe <mikael@lilotux.net>
parents: 1310
diff changeset
   247
    scr_WriteIncomingMessage(bjid, buf,
e30a9d907105 Minor coding style adjustments
Mikael Berthe <mikael@lilotux.net>
parents: 1310
diff changeset
   248
                             0, HBB_PREFIX_INFO | HBB_PREFIX_CONT, 0);
1030
923cf5a92b44 [BP-dd9e7eb5f8a8] Remove old UTF-8 conversions
Mikael Berthe <mikael@lilotux.net>
parents: 965
diff changeset
   249
    g_free(buf);
690
3e965a1186c7 Implement IQ:version requests
Mikael Berthe <mikael@lilotux.net>
parents: 689
diff changeset
   250
  }
1598
a087125d8fc8 Replace libjabber with loudmouth
franky
parents: 1575
diff changeset
   251
  p = lm_message_node_get_child_value(ansqry, "version");
1899
decf94827efe More lm_message_node_get_child_value() return value checks
Mikael Berthe <mikael@lilotux.net>
parents: 1811
diff changeset
   252
  if (p && *p) {
1030
923cf5a92b44 [BP-dd9e7eb5f8a8] Remove old UTF-8 conversions
Mikael Berthe <mikael@lilotux.net>
parents: 965
diff changeset
   253
    buf = g_strdup_printf("Version: %s", p);
1333
e30a9d907105 Minor coding style adjustments
Mikael Berthe <mikael@lilotux.net>
parents: 1310
diff changeset
   254
    scr_WriteIncomingMessage(bjid, buf,
e30a9d907105 Minor coding style adjustments
Mikael Berthe <mikael@lilotux.net>
parents: 1310
diff changeset
   255
                             0, HBB_PREFIX_INFO | HBB_PREFIX_CONT, 0);
1030
923cf5a92b44 [BP-dd9e7eb5f8a8] Remove old UTF-8 conversions
Mikael Berthe <mikael@lilotux.net>
parents: 965
diff changeset
   256
    g_free(buf);
690
3e965a1186c7 Implement IQ:version requests
Mikael Berthe <mikael@lilotux.net>
parents: 689
diff changeset
   257
  }
1598
a087125d8fc8 Replace libjabber with loudmouth
franky
parents: 1575
diff changeset
   258
  p = lm_message_node_get_child_value(ansqry, "os");
1899
decf94827efe More lm_message_node_get_child_value() return value checks
Mikael Berthe <mikael@lilotux.net>
parents: 1811
diff changeset
   259
  if (p && *p) {
1030
923cf5a92b44 [BP-dd9e7eb5f8a8] Remove old UTF-8 conversions
Mikael Berthe <mikael@lilotux.net>
parents: 965
diff changeset
   260
    buf = g_strdup_printf("OS:      %s", p);
1333
e30a9d907105 Minor coding style adjustments
Mikael Berthe <mikael@lilotux.net>
parents: 1310
diff changeset
   261
    scr_WriteIncomingMessage(bjid, buf,
e30a9d907105 Minor coding style adjustments
Mikael Berthe <mikael@lilotux.net>
parents: 1310
diff changeset
   262
                             0, HBB_PREFIX_INFO | HBB_PREFIX_CONT, 0);
1030
923cf5a92b44 [BP-dd9e7eb5f8a8] Remove old UTF-8 conversions
Mikael Berthe <mikael@lilotux.net>
parents: 965
diff changeset
   263
    g_free(buf);
690
3e965a1186c7 Implement IQ:version requests
Mikael Berthe <mikael@lilotux.net>
parents: 689
diff changeset
   264
  }
1598
a087125d8fc8 Replace libjabber with loudmouth
franky
parents: 1575
diff changeset
   265
  return LM_HANDLER_RESULT_REMOVE_MESSAGE;
690
3e965a1186c7 Implement IQ:version requests
Mikael Berthe <mikael@lilotux.net>
parents: 689
diff changeset
   266
}
3e965a1186c7 Implement IQ:version requests
Mikael Berthe <mikael@lilotux.net>
parents: 689
diff changeset
   267
1598
a087125d8fc8 Replace libjabber with loudmouth
franky
parents: 1575
diff changeset
   268
static LmHandlerResult cb_time(LmMessageHandler *h, LmConnection *c,
a087125d8fc8 Replace libjabber with loudmouth
franky
parents: 1575
diff changeset
   269
                               LmMessage *m, gpointer user_data)
691
3c0a0a993de8 Implement IQ:time requests
Mikael Berthe <mikael@lilotux.net>
parents: 690
diff changeset
   270
{
1598
a087125d8fc8 Replace libjabber with loudmouth
franky
parents: 1575
diff changeset
   271
  LmMessageNode *ansqry;
a087125d8fc8 Replace libjabber with loudmouth
franky
parents: 1575
diff changeset
   272
  const char *p, *bjid;
1703
65ba89949252 Improve error checks in received IQ responses
Mikael Berthe <mikael@lilotux.net>
parents: 1699
diff changeset
   273
  char *buf, *tmp;
691
3c0a0a993de8 Implement IQ:time requests
Mikael Berthe <mikael@lilotux.net>
parents: 690
diff changeset
   274
1703
65ba89949252 Improve error checks in received IQ responses
Mikael Berthe <mikael@lilotux.net>
parents: 1699
diff changeset
   275
  // Check IQ result sender
1698
e67bdd863638 Handle IQ responses with no "from"
Mikael Berthe <mikael@lilotux.net>
parents: 1683
diff changeset
   276
  bjid = lm_message_get_from(m);
e67bdd863638 Handle IQ responses with no "from"
Mikael Berthe <mikael@lilotux.net>
parents: 1683
diff changeset
   277
  if (!bjid)
1699
527c965b45c5 Add small comment in previous change
Mikael Berthe <mikael@lilotux.net>
parents: 1698
diff changeset
   278
    bjid = lm_connection_get_jid(lconnection); // No from means our JID...
1698
e67bdd863638 Handle IQ responses with no "from"
Mikael Berthe <mikael@lilotux.net>
parents: 1683
diff changeset
   279
  if (!bjid) {
1703
65ba89949252 Improve error checks in received IQ responses
Mikael Berthe <mikael@lilotux.net>
parents: 1699
diff changeset
   280
    scr_LogPrint(LPRINT_LOGNORM, "Invalid IQ:time result (no sender name).");
65ba89949252 Improve error checks in received IQ responses
Mikael Berthe <mikael@lilotux.net>
parents: 1699
diff changeset
   281
    return LM_HANDLER_RESULT_REMOVE_MESSAGE;
65ba89949252 Improve error checks in received IQ responses
Mikael Berthe <mikael@lilotux.net>
parents: 1699
diff changeset
   282
  }
65ba89949252 Improve error checks in received IQ responses
Mikael Berthe <mikael@lilotux.net>
parents: 1699
diff changeset
   283
65ba89949252 Improve error checks in received IQ responses
Mikael Berthe <mikael@lilotux.net>
parents: 1699
diff changeset
   284
  // Check for error message
65ba89949252 Improve error checks in received IQ responses
Mikael Berthe <mikael@lilotux.net>
parents: 1699
diff changeset
   285
  if (lm_message_get_sub_type(m) == LM_MESSAGE_SUB_TYPE_ERROR) {
65ba89949252 Improve error checks in received IQ responses
Mikael Berthe <mikael@lilotux.net>
parents: 1699
diff changeset
   286
    scr_LogPrint(LPRINT_LOGNORM, "Received error IQ message (%s)", bjid);
1800
d2747442918a When displaying a server error, show the sender JID
Mikael Berthe <mikael@lilotux.net>
parents: 1729
diff changeset
   287
    display_server_error(lm_message_node_get_child(m->node, "error"), NULL);
1703
65ba89949252 Improve error checks in received IQ responses
Mikael Berthe <mikael@lilotux.net>
parents: 1699
diff changeset
   288
    return LM_HANDLER_RESULT_REMOVE_MESSAGE;
65ba89949252 Improve error checks in received IQ responses
Mikael Berthe <mikael@lilotux.net>
parents: 1699
diff changeset
   289
  }
65ba89949252 Improve error checks in received IQ responses
Mikael Berthe <mikael@lilotux.net>
parents: 1699
diff changeset
   290
65ba89949252 Improve error checks in received IQ responses
Mikael Berthe <mikael@lilotux.net>
parents: 1699
diff changeset
   291
  // Check message contents
2017
87049d55e34f Fix /request time
Mikael Berthe <mikael@lilotux.net>
parents: 2004
diff changeset
   292
  ansqry = lm_message_node_get_child(m->node, "time");
1703
65ba89949252 Improve error checks in received IQ responses
Mikael Berthe <mikael@lilotux.net>
parents: 1699
diff changeset
   293
  if (!ansqry) {
65ba89949252 Improve error checks in received IQ responses
Mikael Berthe <mikael@lilotux.net>
parents: 1699
diff changeset
   294
    scr_LogPrint(LPRINT_LOGNORM, "Invalid IQ:time result from <%s>!", bjid);
1698
e67bdd863638 Handle IQ responses with no "from"
Mikael Berthe <mikael@lilotux.net>
parents: 1683
diff changeset
   295
    return LM_HANDLER_RESULT_REMOVE_MESSAGE;
691
3c0a0a993de8 Implement IQ:time requests
Mikael Berthe <mikael@lilotux.net>
parents: 690
diff changeset
   296
  }
704
4118a66f2c02 Display IQ results (time, version) in the chat window
Mikael Berthe <mikael@lilotux.net>
parents: 703
diff changeset
   297
782
19121d9f4aa2 Nicer message when receiving IQ result packet
Mikael Berthe <mikael@lilotux.net>
parents: 776
diff changeset
   298
  buf = g_strdup_printf("Received IQ:time result from <%s>", bjid);
704
4118a66f2c02 Display IQ results (time, version) in the chat window
Mikael Berthe <mikael@lilotux.net>
parents: 703
diff changeset
   299
  scr_LogPrint(LPRINT_LOGNORM, "%s", buf);
4118a66f2c02 Display IQ results (time, version) in the chat window
Mikael Berthe <mikael@lilotux.net>
parents: 703
diff changeset
   300
4118a66f2c02 Display IQ results (time, version) in the chat window
Mikael Berthe <mikael@lilotux.net>
parents: 703
diff changeset
   301
  // bjid should now really be the "bare JID", let's strip the resource
1598
a087125d8fc8 Replace libjabber with loudmouth
franky
parents: 1575
diff changeset
   302
  tmp = strchr(bjid, JID_RESOURCE_SEPARATOR);
a087125d8fc8 Replace libjabber with loudmouth
franky
parents: 1575
diff changeset
   303
  if (tmp) *tmp = '\0';
704
4118a66f2c02 Display IQ results (time, version) in the chat window
Mikael Berthe <mikael@lilotux.net>
parents: 703
diff changeset
   304
1290
e42f48103609 Drawing the MUC nicks by a different color
Michal 'vorner' Vaner <vorner@ucw.cz>
parents: 1283
diff changeset
   305
  scr_WriteIncomingMessage(bjid, buf, 0, HBB_PREFIX_INFO, 0);
704
4118a66f2c02 Display IQ results (time, version) in the chat window
Mikael Berthe <mikael@lilotux.net>
parents: 703
diff changeset
   306
  g_free(buf);
4118a66f2c02 Display IQ results (time, version) in the chat window
Mikael Berthe <mikael@lilotux.net>
parents: 703
diff changeset
   307
691
3c0a0a993de8 Implement IQ:time requests
Mikael Berthe <mikael@lilotux.net>
parents: 690
diff changeset
   308
  // Get result data...
1598
a087125d8fc8 Replace libjabber with loudmouth
franky
parents: 1575
diff changeset
   309
  p = lm_message_node_get_child_value(ansqry, "utc");
1899
decf94827efe More lm_message_node_get_child_value() return value checks
Mikael Berthe <mikael@lilotux.net>
parents: 1811
diff changeset
   310
  if (p && *p) {
1030
923cf5a92b44 [BP-dd9e7eb5f8a8] Remove old UTF-8 conversions
Mikael Berthe <mikael@lilotux.net>
parents: 965
diff changeset
   311
    buf = g_strdup_printf("UTC:  %s", p);
1333
e30a9d907105 Minor coding style adjustments
Mikael Berthe <mikael@lilotux.net>
parents: 1310
diff changeset
   312
    scr_WriteIncomingMessage(bjid, buf,
e30a9d907105 Minor coding style adjustments
Mikael Berthe <mikael@lilotux.net>
parents: 1310
diff changeset
   313
                             0, HBB_PREFIX_INFO | HBB_PREFIX_CONT, 0);
1030
923cf5a92b44 [BP-dd9e7eb5f8a8] Remove old UTF-8 conversions
Mikael Berthe <mikael@lilotux.net>
parents: 965
diff changeset
   314
    g_free(buf);
691
3c0a0a993de8 Implement IQ:time requests
Mikael Berthe <mikael@lilotux.net>
parents: 690
diff changeset
   315
  }
2017
87049d55e34f Fix /request time
Mikael Berthe <mikael@lilotux.net>
parents: 2004
diff changeset
   316
  p = lm_message_node_get_child_value(ansqry, "tzo");
1899
decf94827efe More lm_message_node_get_child_value() return value checks
Mikael Berthe <mikael@lilotux.net>
parents: 1811
diff changeset
   317
  if (p && *p) {
1030
923cf5a92b44 [BP-dd9e7eb5f8a8] Remove old UTF-8 conversions
Mikael Berthe <mikael@lilotux.net>
parents: 965
diff changeset
   318
    buf = g_strdup_printf("TZ:   %s", p);
1333
e30a9d907105 Minor coding style adjustments
Mikael Berthe <mikael@lilotux.net>
parents: 1310
diff changeset
   319
    scr_WriteIncomingMessage(bjid, buf,
e30a9d907105 Minor coding style adjustments
Mikael Berthe <mikael@lilotux.net>
parents: 1310
diff changeset
   320
                             0, HBB_PREFIX_INFO | HBB_PREFIX_CONT, 0);
1030
923cf5a92b44 [BP-dd9e7eb5f8a8] Remove old UTF-8 conversions
Mikael Berthe <mikael@lilotux.net>
parents: 965
diff changeset
   321
    g_free(buf);
691
3c0a0a993de8 Implement IQ:time requests
Mikael Berthe <mikael@lilotux.net>
parents: 690
diff changeset
   322
  }
1598
a087125d8fc8 Replace libjabber with loudmouth
franky
parents: 1575
diff changeset
   323
  p = lm_message_node_get_child_value(ansqry, "display");
1899
decf94827efe More lm_message_node_get_child_value() return value checks
Mikael Berthe <mikael@lilotux.net>
parents: 1811
diff changeset
   324
  if (p && *p) {
1030
923cf5a92b44 [BP-dd9e7eb5f8a8] Remove old UTF-8 conversions
Mikael Berthe <mikael@lilotux.net>
parents: 965
diff changeset
   325
    buf = g_strdup_printf("Time: %s", p);
1333
e30a9d907105 Minor coding style adjustments
Mikael Berthe <mikael@lilotux.net>
parents: 1310
diff changeset
   326
    scr_WriteIncomingMessage(bjid, buf,
e30a9d907105 Minor coding style adjustments
Mikael Berthe <mikael@lilotux.net>
parents: 1310
diff changeset
   327
                             0, HBB_PREFIX_INFO | HBB_PREFIX_CONT, 0);
1030
923cf5a92b44 [BP-dd9e7eb5f8a8] Remove old UTF-8 conversions
Mikael Berthe <mikael@lilotux.net>
parents: 965
diff changeset
   328
    g_free(buf);
691
3c0a0a993de8 Implement IQ:time requests
Mikael Berthe <mikael@lilotux.net>
parents: 690
diff changeset
   329
  }
1598
a087125d8fc8 Replace libjabber with loudmouth
franky
parents: 1575
diff changeset
   330
  return LM_HANDLER_RESULT_REMOVE_MESSAGE;
691
3c0a0a993de8 Implement IQ:time requests
Mikael Berthe <mikael@lilotux.net>
parents: 690
diff changeset
   331
}
3c0a0a993de8 Implement IQ:time requests
Mikael Berthe <mikael@lilotux.net>
parents: 690
diff changeset
   332
1598
a087125d8fc8 Replace libjabber with loudmouth
franky
parents: 1575
diff changeset
   333
static LmHandlerResult cb_last(LmMessageHandler *h, LmConnection *c,
a087125d8fc8 Replace libjabber with loudmouth
franky
parents: 1575
diff changeset
   334
                               LmMessage *m, gpointer user_data)
1015
579299b1c9b2 Add /request last
Mikael Berthe <mikael@lilotux.net>
parents: 1014
diff changeset
   335
{
1598
a087125d8fc8 Replace libjabber with loudmouth
franky
parents: 1575
diff changeset
   336
  LmMessageNode *ansqry;
a087125d8fc8 Replace libjabber with loudmouth
franky
parents: 1575
diff changeset
   337
  const char *p, *bjid;
a087125d8fc8 Replace libjabber with loudmouth
franky
parents: 1575
diff changeset
   338
  char *buf, *tmp;
1015
579299b1c9b2 Add /request last
Mikael Berthe <mikael@lilotux.net>
parents: 1014
diff changeset
   339
1703
65ba89949252 Improve error checks in received IQ responses
Mikael Berthe <mikael@lilotux.net>
parents: 1699
diff changeset
   340
  // Check IQ result sender
1698
e67bdd863638 Handle IQ responses with no "from"
Mikael Berthe <mikael@lilotux.net>
parents: 1683
diff changeset
   341
  bjid = lm_message_get_from(m);
e67bdd863638 Handle IQ responses with no "from"
Mikael Berthe <mikael@lilotux.net>
parents: 1683
diff changeset
   342
  if (!bjid)
1699
527c965b45c5 Add small comment in previous change
Mikael Berthe <mikael@lilotux.net>
parents: 1698
diff changeset
   343
    bjid = lm_connection_get_jid(lconnection); // No from means our JID...
1698
e67bdd863638 Handle IQ responses with no "from"
Mikael Berthe <mikael@lilotux.net>
parents: 1683
diff changeset
   344
  if (!bjid) {
1703
65ba89949252 Improve error checks in received IQ responses
Mikael Berthe <mikael@lilotux.net>
parents: 1699
diff changeset
   345
    scr_LogPrint(LPRINT_LOGNORM, "Invalid IQ:last result (no sender name).");
65ba89949252 Improve error checks in received IQ responses
Mikael Berthe <mikael@lilotux.net>
parents: 1699
diff changeset
   346
    return LM_HANDLER_RESULT_REMOVE_MESSAGE;
65ba89949252 Improve error checks in received IQ responses
Mikael Berthe <mikael@lilotux.net>
parents: 1699
diff changeset
   347
  }
65ba89949252 Improve error checks in received IQ responses
Mikael Berthe <mikael@lilotux.net>
parents: 1699
diff changeset
   348
65ba89949252 Improve error checks in received IQ responses
Mikael Berthe <mikael@lilotux.net>
parents: 1699
diff changeset
   349
  // Check for error message
65ba89949252 Improve error checks in received IQ responses
Mikael Berthe <mikael@lilotux.net>
parents: 1699
diff changeset
   350
  if (lm_message_get_sub_type(m) == LM_MESSAGE_SUB_TYPE_ERROR) {
65ba89949252 Improve error checks in received IQ responses
Mikael Berthe <mikael@lilotux.net>
parents: 1699
diff changeset
   351
    scr_LogPrint(LPRINT_LOGNORM, "Received error IQ message (%s)", bjid);
1800
d2747442918a When displaying a server error, show the sender JID
Mikael Berthe <mikael@lilotux.net>
parents: 1729
diff changeset
   352
    display_server_error(lm_message_node_get_child(m->node, "error"), NULL);
1703
65ba89949252 Improve error checks in received IQ responses
Mikael Berthe <mikael@lilotux.net>
parents: 1699
diff changeset
   353
    return LM_HANDLER_RESULT_REMOVE_MESSAGE;
65ba89949252 Improve error checks in received IQ responses
Mikael Berthe <mikael@lilotux.net>
parents: 1699
diff changeset
   354
  }
65ba89949252 Improve error checks in received IQ responses
Mikael Berthe <mikael@lilotux.net>
parents: 1699
diff changeset
   355
65ba89949252 Improve error checks in received IQ responses
Mikael Berthe <mikael@lilotux.net>
parents: 1699
diff changeset
   356
  // Check message contents
65ba89949252 Improve error checks in received IQ responses
Mikael Berthe <mikael@lilotux.net>
parents: 1699
diff changeset
   357
  ansqry = lm_message_node_get_child(m->node, "query");
65ba89949252 Improve error checks in received IQ responses
Mikael Berthe <mikael@lilotux.net>
parents: 1699
diff changeset
   358
  if (!ansqry) {
65ba89949252 Improve error checks in received IQ responses
Mikael Berthe <mikael@lilotux.net>
parents: 1699
diff changeset
   359
    scr_LogPrint(LPRINT_LOGNORM, "Invalid IQ:version result from <%s>!", bjid);
1698
e67bdd863638 Handle IQ responses with no "from"
Mikael Berthe <mikael@lilotux.net>
parents: 1683
diff changeset
   360
    return LM_HANDLER_RESULT_REMOVE_MESSAGE;
1015
579299b1c9b2 Add /request last
Mikael Berthe <mikael@lilotux.net>
parents: 1014
diff changeset
   361
  }
579299b1c9b2 Add /request last
Mikael Berthe <mikael@lilotux.net>
parents: 1014
diff changeset
   362
579299b1c9b2 Add /request last
Mikael Berthe <mikael@lilotux.net>
parents: 1014
diff changeset
   363
  buf = g_strdup_printf("Received IQ:last result from <%s>", bjid);
579299b1c9b2 Add /request last
Mikael Berthe <mikael@lilotux.net>
parents: 1014
diff changeset
   364
  scr_LogPrint(LPRINT_LOGNORM, "%s", buf);
579299b1c9b2 Add /request last
Mikael Berthe <mikael@lilotux.net>
parents: 1014
diff changeset
   365
579299b1c9b2 Add /request last
Mikael Berthe <mikael@lilotux.net>
parents: 1014
diff changeset
   366
  // bjid should now really be the "bare JID", let's strip the resource
1598
a087125d8fc8 Replace libjabber with loudmouth
franky
parents: 1575
diff changeset
   367
  tmp = strchr(bjid, JID_RESOURCE_SEPARATOR);
a087125d8fc8 Replace libjabber with loudmouth
franky
parents: 1575
diff changeset
   368
  if (tmp) *tmp = '\0';
1015
579299b1c9b2 Add /request last
Mikael Berthe <mikael@lilotux.net>
parents: 1014
diff changeset
   369
1290
e42f48103609 Drawing the MUC nicks by a different color
Michal 'vorner' Vaner <vorner@ucw.cz>
parents: 1283
diff changeset
   370
  scr_WriteIncomingMessage(bjid, buf, 0, HBB_PREFIX_INFO, 0);
1015
579299b1c9b2 Add /request last
Mikael Berthe <mikael@lilotux.net>
parents: 1014
diff changeset
   371
  g_free(buf);
579299b1c9b2 Add /request last
Mikael Berthe <mikael@lilotux.net>
parents: 1014
diff changeset
   372
579299b1c9b2 Add /request last
Mikael Berthe <mikael@lilotux.net>
parents: 1014
diff changeset
   373
  // Get result data...
1598
a087125d8fc8 Replace libjabber with loudmouth
franky
parents: 1575
diff changeset
   374
  p = lm_message_node_get_attribute(ansqry, "seconds");
1015
579299b1c9b2 Add /request last
Mikael Berthe <mikael@lilotux.net>
parents: 1014
diff changeset
   375
  if (p) {
579299b1c9b2 Add /request last
Mikael Berthe <mikael@lilotux.net>
parents: 1014
diff changeset
   376
    long int s;
579299b1c9b2 Add /request last
Mikael Berthe <mikael@lilotux.net>
parents: 1014
diff changeset
   377
    GString *sbuf;
579299b1c9b2 Add /request last
Mikael Berthe <mikael@lilotux.net>
parents: 1014
diff changeset
   378
    sbuf = g_string_new("Idle time: ");
579299b1c9b2 Add /request last
Mikael Berthe <mikael@lilotux.net>
parents: 1014
diff changeset
   379
    s = atol(p);
579299b1c9b2 Add /request last
Mikael Berthe <mikael@lilotux.net>
parents: 1014
diff changeset
   380
    // Days
579299b1c9b2 Add /request last
Mikael Berthe <mikael@lilotux.net>
parents: 1014
diff changeset
   381
    if (s > 86400L) {
579299b1c9b2 Add /request last
Mikael Berthe <mikael@lilotux.net>
parents: 1014
diff changeset
   382
      g_string_append_printf(sbuf, "%ldd ", s/86400L);
579299b1c9b2 Add /request last
Mikael Berthe <mikael@lilotux.net>
parents: 1014
diff changeset
   383
      s %= 86400L;
579299b1c9b2 Add /request last
Mikael Berthe <mikael@lilotux.net>
parents: 1014
diff changeset
   384
    }
579299b1c9b2 Add /request last
Mikael Berthe <mikael@lilotux.net>
parents: 1014
diff changeset
   385
    // hh:mm:ss
579299b1c9b2 Add /request last
Mikael Berthe <mikael@lilotux.net>
parents: 1014
diff changeset
   386
    g_string_append_printf(sbuf, "%02ld:", s/3600L);
579299b1c9b2 Add /request last
Mikael Berthe <mikael@lilotux.net>
parents: 1014
diff changeset
   387
    s %= 3600L;
579299b1c9b2 Add /request last
Mikael Berthe <mikael@lilotux.net>
parents: 1014
diff changeset
   388
    g_string_append_printf(sbuf, "%02ld:%02ld", s/60L, s%60L);
1268
dbc907b2d92f Add configurable colors for info and incoming messages (Michal 'vorner' Vaner)
Mikael Berthe <mikael@lilotux.net>
parents: 1261
diff changeset
   389
    scr_WriteIncomingMessage(bjid, sbuf->str,
1290
e42f48103609 Drawing the MUC nicks by a different color
Michal 'vorner' Vaner <vorner@ucw.cz>
parents: 1283
diff changeset
   390
                             0, HBB_PREFIX_INFO | HBB_PREFIX_CONT, 0);
1015
579299b1c9b2 Add /request last
Mikael Berthe <mikael@lilotux.net>
parents: 1014
diff changeset
   391
    g_string_free(sbuf, TRUE);
579299b1c9b2 Add /request last
Mikael Berthe <mikael@lilotux.net>
parents: 1014
diff changeset
   392
  } else {
579299b1c9b2 Add /request last
Mikael Berthe <mikael@lilotux.net>
parents: 1014
diff changeset
   393
    scr_WriteIncomingMessage(bjid, "No idle time reported.",
1290
e42f48103609 Drawing the MUC nicks by a different color
Michal 'vorner' Vaner <vorner@ucw.cz>
parents: 1283
diff changeset
   394
                             0, HBB_PREFIX_INFO | HBB_PREFIX_CONT, 0);
1015
579299b1c9b2 Add /request last
Mikael Berthe <mikael@lilotux.net>
parents: 1014
diff changeset
   395
  }
1598
a087125d8fc8 Replace libjabber with loudmouth
franky
parents: 1575
diff changeset
   396
  p = lm_message_node_get_value(ansqry);
1015
579299b1c9b2 Add /request last
Mikael Berthe <mikael@lilotux.net>
parents: 1014
diff changeset
   397
  if (p) {
579299b1c9b2 Add /request last
Mikael Berthe <mikael@lilotux.net>
parents: 1014
diff changeset
   398
    buf = g_strdup_printf("Status message: %s", p);
1290
e42f48103609 Drawing the MUC nicks by a different color
Michal 'vorner' Vaner <vorner@ucw.cz>
parents: 1283
diff changeset
   399
    scr_WriteIncomingMessage(bjid, buf, 0, HBB_PREFIX_INFO, 0);
1015
579299b1c9b2 Add /request last
Mikael Berthe <mikael@lilotux.net>
parents: 1014
diff changeset
   400
    g_free(buf);
579299b1c9b2 Add /request last
Mikael Berthe <mikael@lilotux.net>
parents: 1014
diff changeset
   401
  }
1598
a087125d8fc8 Replace libjabber with loudmouth
franky
parents: 1575
diff changeset
   402
  return LM_HANDLER_RESULT_REMOVE_MESSAGE;
1015
579299b1c9b2 Add /request last
Mikael Berthe <mikael@lilotux.net>
parents: 1014
diff changeset
   403
}
579299b1c9b2 Add /request last
Mikael Berthe <mikael@lilotux.net>
parents: 1014
diff changeset
   404
1006
f61131cd86a0 Clean up vcard code
Mikael Berthe <mikael@lilotux.net>
parents: 1005
diff changeset
   405
static void display_vcard_item(const char *bjid, const char *label,
f61131cd86a0 Clean up vcard code
Mikael Berthe <mikael@lilotux.net>
parents: 1005
diff changeset
   406
                               enum vcard_attr vcard_attrib, const char *text)
f61131cd86a0 Clean up vcard code
Mikael Berthe <mikael@lilotux.net>
parents: 1005
diff changeset
   407
{
f61131cd86a0 Clean up vcard code
Mikael Berthe <mikael@lilotux.net>
parents: 1005
diff changeset
   408
  char *buf;
f61131cd86a0 Clean up vcard code
Mikael Berthe <mikael@lilotux.net>
parents: 1005
diff changeset
   409
1899
decf94827efe More lm_message_node_get_child_value() return value checks
Mikael Berthe <mikael@lilotux.net>
parents: 1811
diff changeset
   410
  if (!text || !*text || !bjid || !label)
1006
f61131cd86a0 Clean up vcard code
Mikael Berthe <mikael@lilotux.net>
parents: 1005
diff changeset
   411
    return;
f61131cd86a0 Clean up vcard code
Mikael Berthe <mikael@lilotux.net>
parents: 1005
diff changeset
   412
f61131cd86a0 Clean up vcard code
Mikael Berthe <mikael@lilotux.net>
parents: 1005
diff changeset
   413
  buf = g_strdup_printf("%s: %s%s%s%s%s%s%s%s%s%s", label,
f61131cd86a0 Clean up vcard code
Mikael Berthe <mikael@lilotux.net>
parents: 1005
diff changeset
   414
                        (vcard_attrib & vcard_home ? "[home]" : ""),
f61131cd86a0 Clean up vcard code
Mikael Berthe <mikael@lilotux.net>
parents: 1005
diff changeset
   415
                        (vcard_attrib & vcard_work ? "[work]" : ""),
f61131cd86a0 Clean up vcard code
Mikael Berthe <mikael@lilotux.net>
parents: 1005
diff changeset
   416
                        (vcard_attrib & vcard_postal ? "[postal]" : ""),
f61131cd86a0 Clean up vcard code
Mikael Berthe <mikael@lilotux.net>
parents: 1005
diff changeset
   417
                        (vcard_attrib & vcard_voice ? "[voice]" : ""),
f61131cd86a0 Clean up vcard code
Mikael Berthe <mikael@lilotux.net>
parents: 1005
diff changeset
   418
                        (vcard_attrib & vcard_fax  ? "[fax]"  : ""),
f61131cd86a0 Clean up vcard code
Mikael Berthe <mikael@lilotux.net>
parents: 1005
diff changeset
   419
                        (vcard_attrib & vcard_cell ? "[cell]" : ""),
f61131cd86a0 Clean up vcard code
Mikael Berthe <mikael@lilotux.net>
parents: 1005
diff changeset
   420
                        (vcard_attrib & vcard_inet ? "[inet]" : ""),
f61131cd86a0 Clean up vcard code
Mikael Berthe <mikael@lilotux.net>
parents: 1005
diff changeset
   421
                        (vcard_attrib & vcard_pref ? "[pref]" : ""),
f61131cd86a0 Clean up vcard code
Mikael Berthe <mikael@lilotux.net>
parents: 1005
diff changeset
   422
                        (vcard_attrib ? " " : ""),
f61131cd86a0 Clean up vcard code
Mikael Berthe <mikael@lilotux.net>
parents: 1005
diff changeset
   423
                        text);
1290
e42f48103609 Drawing the MUC nicks by a different color
Michal 'vorner' Vaner <vorner@ucw.cz>
parents: 1283
diff changeset
   424
  scr_WriteIncomingMessage(bjid, buf, 0, HBB_PREFIX_INFO | HBB_PREFIX_CONT, 0);
1006
f61131cd86a0 Clean up vcard code
Mikael Berthe <mikael@lilotux.net>
parents: 1005
diff changeset
   425
  g_free(buf);
f61131cd86a0 Clean up vcard code
Mikael Berthe <mikael@lilotux.net>
parents: 1005
diff changeset
   426
}
f61131cd86a0 Clean up vcard code
Mikael Berthe <mikael@lilotux.net>
parents: 1005
diff changeset
   427
1598
a087125d8fc8 Replace libjabber with loudmouth
franky
parents: 1575
diff changeset
   428
static void handle_vcard_node(const char *barejid, LmMessageNode *vcardnode)
1003
c8b1a52b2fd6 Initial VCard retrieval support
Mikael Berthe <mikael@lilotux.net>
parents: 1002
diff changeset
   429
{
1598
a087125d8fc8 Replace libjabber with loudmouth
franky
parents: 1575
diff changeset
   430
  LmMessageNode *x;
1003
c8b1a52b2fd6 Initial VCard retrieval support
Mikael Berthe <mikael@lilotux.net>
parents: 1002
diff changeset
   431
  const char *p;
c8b1a52b2fd6 Initial VCard retrieval support
Mikael Berthe <mikael@lilotux.net>
parents: 1002
diff changeset
   432
1598
a087125d8fc8 Replace libjabber with loudmouth
franky
parents: 1575
diff changeset
   433
  for (x = vcardnode->children ; x; x = x->next) {
1006
f61131cd86a0 Clean up vcard code
Mikael Berthe <mikael@lilotux.net>
parents: 1005
diff changeset
   434
    const char *data;
f61131cd86a0 Clean up vcard code
Mikael Berthe <mikael@lilotux.net>
parents: 1005
diff changeset
   435
    enum vcard_attr vcard_attrib = 0;
f61131cd86a0 Clean up vcard code
Mikael Berthe <mikael@lilotux.net>
parents: 1005
diff changeset
   436
1598
a087125d8fc8 Replace libjabber with loudmouth
franky
parents: 1575
diff changeset
   437
    p = x->name;
1719
f3c5e1175b22 Remove buggy check in handle_vcard_node() (Reported by Hermitifier)
Mikael Berthe <mikael@lilotux.net>
parents: 1707
diff changeset
   438
    if (!p)
f3c5e1175b22 Remove buggy check in handle_vcard_node() (Reported by Hermitifier)
Mikael Berthe <mikael@lilotux.net>
parents: 1707
diff changeset
   439
      continue;
f3c5e1175b22 Remove buggy check in handle_vcard_node() (Reported by Hermitifier)
Mikael Berthe <mikael@lilotux.net>
parents: 1707
diff changeset
   440
1598
a087125d8fc8 Replace libjabber with loudmouth
franky
parents: 1575
diff changeset
   441
    data = lm_message_node_get_value(x);
1006
f61131cd86a0 Clean up vcard code
Mikael Berthe <mikael@lilotux.net>
parents: 1005
diff changeset
   442
f61131cd86a0 Clean up vcard code
Mikael Berthe <mikael@lilotux.net>
parents: 1005
diff changeset
   443
    if (!strcmp(p, "FN"))
f61131cd86a0 Clean up vcard code
Mikael Berthe <mikael@lilotux.net>
parents: 1005
diff changeset
   444
      display_vcard_item(barejid, "Name", vcard_attrib, data);
f61131cd86a0 Clean up vcard code
Mikael Berthe <mikael@lilotux.net>
parents: 1005
diff changeset
   445
    else if (!strcmp(p, "NICKNAME"))
f61131cd86a0 Clean up vcard code
Mikael Berthe <mikael@lilotux.net>
parents: 1005
diff changeset
   446
      display_vcard_item(barejid, "Nickname", vcard_attrib, data);
f61131cd86a0 Clean up vcard code
Mikael Berthe <mikael@lilotux.net>
parents: 1005
diff changeset
   447
    else if (!strcmp(p, "URL"))
f61131cd86a0 Clean up vcard code
Mikael Berthe <mikael@lilotux.net>
parents: 1005
diff changeset
   448
      display_vcard_item(barejid, "URL", vcard_attrib, data);
f61131cd86a0 Clean up vcard code
Mikael Berthe <mikael@lilotux.net>
parents: 1005
diff changeset
   449
    else if (!strcmp(p, "BDAY"))
f61131cd86a0 Clean up vcard code
Mikael Berthe <mikael@lilotux.net>
parents: 1005
diff changeset
   450
      display_vcard_item(barejid, "Birthday", vcard_attrib, data);
f61131cd86a0 Clean up vcard code
Mikael Berthe <mikael@lilotux.net>
parents: 1005
diff changeset
   451
    else if (!strcmp(p, "TZ"))
f61131cd86a0 Clean up vcard code
Mikael Berthe <mikael@lilotux.net>
parents: 1005
diff changeset
   452
      display_vcard_item(barejid, "Timezone", vcard_attrib, data);
f61131cd86a0 Clean up vcard code
Mikael Berthe <mikael@lilotux.net>
parents: 1005
diff changeset
   453
    else if (!strcmp(p, "TITLE"))
f61131cd86a0 Clean up vcard code
Mikael Berthe <mikael@lilotux.net>
parents: 1005
diff changeset
   454
      display_vcard_item(barejid, "Title", vcard_attrib, data);
f61131cd86a0 Clean up vcard code
Mikael Berthe <mikael@lilotux.net>
parents: 1005
diff changeset
   455
    else if (!strcmp(p, "ROLE"))
f61131cd86a0 Clean up vcard code
Mikael Berthe <mikael@lilotux.net>
parents: 1005
diff changeset
   456
      display_vcard_item(barejid, "Role", vcard_attrib, data);
f61131cd86a0 Clean up vcard code
Mikael Berthe <mikael@lilotux.net>
parents: 1005
diff changeset
   457
    else if (!strcmp(p, "DESC"))
f61131cd86a0 Clean up vcard code
Mikael Berthe <mikael@lilotux.net>
parents: 1005
diff changeset
   458
      display_vcard_item(barejid, "Comment", vcard_attrib, data);
f61131cd86a0 Clean up vcard code
Mikael Berthe <mikael@lilotux.net>
parents: 1005
diff changeset
   459
    else if (!strcmp(p, "N")) {
1598
a087125d8fc8 Replace libjabber with loudmouth
franky
parents: 1575
diff changeset
   460
      data = lm_message_node_get_child_value(x, "FAMILY");
1006
f61131cd86a0 Clean up vcard code
Mikael Berthe <mikael@lilotux.net>
parents: 1005
diff changeset
   461
      display_vcard_item(barejid, "Family Name", vcard_attrib, data);
1598
a087125d8fc8 Replace libjabber with loudmouth
franky
parents: 1575
diff changeset
   462
      data = lm_message_node_get_child_value(x, "GIVEN");
1006
f61131cd86a0 Clean up vcard code
Mikael Berthe <mikael@lilotux.net>
parents: 1005
diff changeset
   463
      display_vcard_item(barejid, "Given Name", vcard_attrib, data);
1598
a087125d8fc8 Replace libjabber with loudmouth
franky
parents: 1575
diff changeset
   464
      data = lm_message_node_get_child_value(x, "MIDDLE");
1006
f61131cd86a0 Clean up vcard code
Mikael Berthe <mikael@lilotux.net>
parents: 1005
diff changeset
   465
      display_vcard_item(barejid, "Middle Name", vcard_attrib, data);
f61131cd86a0 Clean up vcard code
Mikael Berthe <mikael@lilotux.net>
parents: 1005
diff changeset
   466
    } else if (!strcmp(p, "ORG")) {
1598
a087125d8fc8 Replace libjabber with loudmouth
franky
parents: 1575
diff changeset
   467
      data = lm_message_node_get_child_value(x, "ORGNAME");
1006
f61131cd86a0 Clean up vcard code
Mikael Berthe <mikael@lilotux.net>
parents: 1005
diff changeset
   468
      display_vcard_item(barejid, "Organisation name", vcard_attrib, data);
1598
a087125d8fc8 Replace libjabber with loudmouth
franky
parents: 1575
diff changeset
   469
      data = lm_message_node_get_child_value(x, "ORGUNIT");
1006
f61131cd86a0 Clean up vcard code
Mikael Berthe <mikael@lilotux.net>
parents: 1005
diff changeset
   470
      display_vcard_item(barejid, "Organisation unit", vcard_attrib, data);
f61131cd86a0 Clean up vcard code
Mikael Berthe <mikael@lilotux.net>
parents: 1005
diff changeset
   471
    } else {
f61131cd86a0 Clean up vcard code
Mikael Berthe <mikael@lilotux.net>
parents: 1005
diff changeset
   472
      // The HOME, WORK and PREF attributes are common to the remaining fields
f61131cd86a0 Clean up vcard code
Mikael Berthe <mikael@lilotux.net>
parents: 1005
diff changeset
   473
      // (ADR, TEL & EMAIL)
1598
a087125d8fc8 Replace libjabber with loudmouth
franky
parents: 1575
diff changeset
   474
      if (lm_message_node_get_child(x, "HOME"))
1006
f61131cd86a0 Clean up vcard code
Mikael Berthe <mikael@lilotux.net>
parents: 1005
diff changeset
   475
        vcard_attrib |= vcard_home;
1598
a087125d8fc8 Replace libjabber with loudmouth
franky
parents: 1575
diff changeset
   476
      if (lm_message_node_get_child(x, "WORK"))
1006
f61131cd86a0 Clean up vcard code
Mikael Berthe <mikael@lilotux.net>
parents: 1005
diff changeset
   477
        vcard_attrib |= vcard_work;
1598
a087125d8fc8 Replace libjabber with loudmouth
franky
parents: 1575
diff changeset
   478
      if (lm_message_node_get_child(x, "PREF"))
1006
f61131cd86a0 Clean up vcard code
Mikael Berthe <mikael@lilotux.net>
parents: 1005
diff changeset
   479
        vcard_attrib |= vcard_pref;
f61131cd86a0 Clean up vcard code
Mikael Berthe <mikael@lilotux.net>
parents: 1005
diff changeset
   480
      if (!strcmp(p, "ADR")) {          // Address
1598
a087125d8fc8 Replace libjabber with loudmouth
franky
parents: 1575
diff changeset
   481
        if (lm_message_node_get_child(x, "POSTAL"))
1006
f61131cd86a0 Clean up vcard code
Mikael Berthe <mikael@lilotux.net>
parents: 1005
diff changeset
   482
          vcard_attrib |= vcard_postal;
1598
a087125d8fc8 Replace libjabber with loudmouth
franky
parents: 1575
diff changeset
   483
        data = lm_message_node_get_child_value(x, "EXTADD");
1006
f61131cd86a0 Clean up vcard code
Mikael Berthe <mikael@lilotux.net>
parents: 1005
diff changeset
   484
        display_vcard_item(barejid, "Addr (ext)", vcard_attrib, data);
1598
a087125d8fc8 Replace libjabber with loudmouth
franky
parents: 1575
diff changeset
   485
        data = lm_message_node_get_child_value(x, "STREET");
1006
f61131cd86a0 Clean up vcard code
Mikael Berthe <mikael@lilotux.net>
parents: 1005
diff changeset
   486
        display_vcard_item(barejid, "Street", vcard_attrib, data);
1598
a087125d8fc8 Replace libjabber with loudmouth
franky
parents: 1575
diff changeset
   487
        data = lm_message_node_get_child_value(x, "LOCALITY");
1006
f61131cd86a0 Clean up vcard code
Mikael Berthe <mikael@lilotux.net>
parents: 1005
diff changeset
   488
        display_vcard_item(barejid, "Locality", vcard_attrib, data);
1598
a087125d8fc8 Replace libjabber with loudmouth
franky
parents: 1575
diff changeset
   489
        data = lm_message_node_get_child_value(x, "REGION");
1006
f61131cd86a0 Clean up vcard code
Mikael Berthe <mikael@lilotux.net>
parents: 1005
diff changeset
   490
        display_vcard_item(barejid, "Region", vcard_attrib, data);
1598
a087125d8fc8 Replace libjabber with loudmouth
franky
parents: 1575
diff changeset
   491
        data = lm_message_node_get_child_value(x, "PCODE");
1006
f61131cd86a0 Clean up vcard code
Mikael Berthe <mikael@lilotux.net>
parents: 1005
diff changeset
   492
        display_vcard_item(barejid, "Postal code", vcard_attrib, data);
1598
a087125d8fc8 Replace libjabber with loudmouth
franky
parents: 1575
diff changeset
   493
        data = lm_message_node_get_child_value(x, "CTRY");
1006
f61131cd86a0 Clean up vcard code
Mikael Berthe <mikael@lilotux.net>
parents: 1005
diff changeset
   494
        display_vcard_item(barejid, "Country", vcard_attrib, data);
f61131cd86a0 Clean up vcard code
Mikael Berthe <mikael@lilotux.net>
parents: 1005
diff changeset
   495
      } else if (!strcmp(p, "TEL")) {   // Telephone
1598
a087125d8fc8 Replace libjabber with loudmouth
franky
parents: 1575
diff changeset
   496
        data = lm_message_node_get_child_value(x, "NUMBER");
1005
e5c10cc29660 Improve vcard support
Mikael Berthe <mikael@lilotux.net>
parents: 1004
diff changeset
   497
        if (data) {
1598
a087125d8fc8 Replace libjabber with loudmouth
franky
parents: 1575
diff changeset
   498
          if (lm_message_node_get_child(x, "VOICE"))
1006
f61131cd86a0 Clean up vcard code
Mikael Berthe <mikael@lilotux.net>
parents: 1005
diff changeset
   499
            vcard_attrib |= vcard_voice;
1598
a087125d8fc8 Replace libjabber with loudmouth
franky
parents: 1575
diff changeset
   500
          if (lm_message_node_get_child(x, "FAX"))
1006
f61131cd86a0 Clean up vcard code
Mikael Berthe <mikael@lilotux.net>
parents: 1005
diff changeset
   501
            vcard_attrib |= vcard_fax;
1598
a087125d8fc8 Replace libjabber with loudmouth
franky
parents: 1575
diff changeset
   502
          if (lm_message_node_get_child(x, "CELL"))
1006
f61131cd86a0 Clean up vcard code
Mikael Berthe <mikael@lilotux.net>
parents: 1005
diff changeset
   503
            vcard_attrib |= vcard_cell;
f61131cd86a0 Clean up vcard code
Mikael Berthe <mikael@lilotux.net>
parents: 1005
diff changeset
   504
          display_vcard_item(barejid, "Phone", vcard_attrib, data);
1005
e5c10cc29660 Improve vcard support
Mikael Berthe <mikael@lilotux.net>
parents: 1004
diff changeset
   505
        }
1006
f61131cd86a0 Clean up vcard code
Mikael Berthe <mikael@lilotux.net>
parents: 1005
diff changeset
   506
      } else if (!strcmp(p, "EMAIL")) { // Email
1598
a087125d8fc8 Replace libjabber with loudmouth
franky
parents: 1575
diff changeset
   507
        if (lm_message_node_get_child(x, "INTERNET"))
1006
f61131cd86a0 Clean up vcard code
Mikael Berthe <mikael@lilotux.net>
parents: 1005
diff changeset
   508
          vcard_attrib |= vcard_inet;
1598
a087125d8fc8 Replace libjabber with loudmouth
franky
parents: 1575
diff changeset
   509
        data = lm_message_node_get_child_value(x, "USERID");
1006
f61131cd86a0 Clean up vcard code
Mikael Berthe <mikael@lilotux.net>
parents: 1005
diff changeset
   510
        display_vcard_item(barejid, "Email", vcard_attrib, data);
1003
c8b1a52b2fd6 Initial VCard retrieval support
Mikael Berthe <mikael@lilotux.net>
parents: 1002
diff changeset
   511
      }
c8b1a52b2fd6 Initial VCard retrieval support
Mikael Berthe <mikael@lilotux.net>
parents: 1002
diff changeset
   512
    }
c8b1a52b2fd6 Initial VCard retrieval support
Mikael Berthe <mikael@lilotux.net>
parents: 1002
diff changeset
   513
  }
c8b1a52b2fd6 Initial VCard retrieval support
Mikael Berthe <mikael@lilotux.net>
parents: 1002
diff changeset
   514
}
c8b1a52b2fd6 Initial VCard retrieval support
Mikael Berthe <mikael@lilotux.net>
parents: 1002
diff changeset
   515
1598
a087125d8fc8 Replace libjabber with loudmouth
franky
parents: 1575
diff changeset
   516
static LmHandlerResult cb_vcard(LmMessageHandler *h, LmConnection *c,
a087125d8fc8 Replace libjabber with loudmouth
franky
parents: 1575
diff changeset
   517
                               LmMessage *m, gpointer user_data)
1003
c8b1a52b2fd6 Initial VCard retrieval support
Mikael Berthe <mikael@lilotux.net>
parents: 1002
diff changeset
   518
{
1598
a087125d8fc8 Replace libjabber with loudmouth
franky
parents: 1575
diff changeset
   519
  LmMessageNode *ansqry;
1698
e67bdd863638 Handle IQ responses with no "from"
Mikael Berthe <mikael@lilotux.net>
parents: 1683
diff changeset
   520
  const char *bjid;
1598
a087125d8fc8 Replace libjabber with loudmouth
franky
parents: 1575
diff changeset
   521
  char *buf, *tmp;
1003
c8b1a52b2fd6 Initial VCard retrieval support
Mikael Berthe <mikael@lilotux.net>
parents: 1002
diff changeset
   522
1703
65ba89949252 Improve error checks in received IQ responses
Mikael Berthe <mikael@lilotux.net>
parents: 1699
diff changeset
   523
  // Check IQ result sender
1698
e67bdd863638 Handle IQ responses with no "from"
Mikael Berthe <mikael@lilotux.net>
parents: 1683
diff changeset
   524
  bjid = lm_message_get_from(m);
e67bdd863638 Handle IQ responses with no "from"
Mikael Berthe <mikael@lilotux.net>
parents: 1683
diff changeset
   525
  if (!bjid)
1699
527c965b45c5 Add small comment in previous change
Mikael Berthe <mikael@lilotux.net>
parents: 1698
diff changeset
   526
    bjid = lm_connection_get_jid(lconnection); // No from means our JID...
1698
e67bdd863638 Handle IQ responses with no "from"
Mikael Berthe <mikael@lilotux.net>
parents: 1683
diff changeset
   527
  if (!bjid) {
1703
65ba89949252 Improve error checks in received IQ responses
Mikael Berthe <mikael@lilotux.net>
parents: 1699
diff changeset
   528
    scr_LogPrint(LPRINT_LOGNORM, "Invalid IQ:vCard result (no sender name).");
65ba89949252 Improve error checks in received IQ responses
Mikael Berthe <mikael@lilotux.net>
parents: 1699
diff changeset
   529
    return LM_HANDLER_RESULT_REMOVE_MESSAGE;
65ba89949252 Improve error checks in received IQ responses
Mikael Berthe <mikael@lilotux.net>
parents: 1699
diff changeset
   530
  }
65ba89949252 Improve error checks in received IQ responses
Mikael Berthe <mikael@lilotux.net>
parents: 1699
diff changeset
   531
65ba89949252 Improve error checks in received IQ responses
Mikael Berthe <mikael@lilotux.net>
parents: 1699
diff changeset
   532
  // Check for error message
65ba89949252 Improve error checks in received IQ responses
Mikael Berthe <mikael@lilotux.net>
parents: 1699
diff changeset
   533
  if (lm_message_get_sub_type(m) == LM_MESSAGE_SUB_TYPE_ERROR) {
65ba89949252 Improve error checks in received IQ responses
Mikael Berthe <mikael@lilotux.net>
parents: 1699
diff changeset
   534
    scr_LogPrint(LPRINT_LOGNORM, "Received error IQ message (%s)", bjid);
1800
d2747442918a When displaying a server error, show the sender JID
Mikael Berthe <mikael@lilotux.net>
parents: 1729
diff changeset
   535
    display_server_error(lm_message_node_get_child(m->node, "error"), NULL);
1698
e67bdd863638 Handle IQ responses with no "from"
Mikael Berthe <mikael@lilotux.net>
parents: 1683
diff changeset
   536
    return LM_HANDLER_RESULT_REMOVE_MESSAGE;
1003
c8b1a52b2fd6 Initial VCard retrieval support
Mikael Berthe <mikael@lilotux.net>
parents: 1002
diff changeset
   537
  }
c8b1a52b2fd6 Initial VCard retrieval support
Mikael Berthe <mikael@lilotux.net>
parents: 1002
diff changeset
   538
c8b1a52b2fd6 Initial VCard retrieval support
Mikael Berthe <mikael@lilotux.net>
parents: 1002
diff changeset
   539
  buf = g_strdup_printf("Received IQ:vCard result from <%s>", bjid);
c8b1a52b2fd6 Initial VCard retrieval support
Mikael Berthe <mikael@lilotux.net>
parents: 1002
diff changeset
   540
  scr_LogPrint(LPRINT_LOGNORM, "%s", buf);
c8b1a52b2fd6 Initial VCard retrieval support
Mikael Berthe <mikael@lilotux.net>
parents: 1002
diff changeset
   541
c8b1a52b2fd6 Initial VCard retrieval support
Mikael Berthe <mikael@lilotux.net>
parents: 1002
diff changeset
   542
  // Get the vCard node
1598
a087125d8fc8 Replace libjabber with loudmouth
franky
parents: 1575
diff changeset
   543
  ansqry = lm_message_node_get_child(m->node, "vCard");
1003
c8b1a52b2fd6 Initial VCard retrieval support
Mikael Berthe <mikael@lilotux.net>
parents: 1002
diff changeset
   544
  if (!ansqry) {
c8b1a52b2fd6 Initial VCard retrieval support
Mikael Berthe <mikael@lilotux.net>
parents: 1002
diff changeset
   545
    scr_LogPrint(LPRINT_LOGNORM, "Empty IQ:vCard result!");
1340
2031f4b2cced Fix a small memory leak
Mikael Berthe <mikael@lilotux.net>
parents: 1334
diff changeset
   546
    g_free(buf);
1598
a087125d8fc8 Replace libjabber with loudmouth
franky
parents: 1575
diff changeset
   547
    return LM_HANDLER_RESULT_REMOVE_MESSAGE;
1003
c8b1a52b2fd6 Initial VCard retrieval support
Mikael Berthe <mikael@lilotux.net>
parents: 1002
diff changeset
   548
  }
c8b1a52b2fd6 Initial VCard retrieval support
Mikael Berthe <mikael@lilotux.net>
parents: 1002
diff changeset
   549
c8b1a52b2fd6 Initial VCard retrieval support
Mikael Berthe <mikael@lilotux.net>
parents: 1002
diff changeset
   550
  // bjid should really be the "bare JID", let's strip the resource
1598
a087125d8fc8 Replace libjabber with loudmouth
franky
parents: 1575
diff changeset
   551
  tmp = strchr(bjid, JID_RESOURCE_SEPARATOR);
a087125d8fc8 Replace libjabber with loudmouth
franky
parents: 1575
diff changeset
   552
  if (tmp) *tmp = '\0';
1003
c8b1a52b2fd6 Initial VCard retrieval support
Mikael Berthe <mikael@lilotux.net>
parents: 1002
diff changeset
   553
1290
e42f48103609 Drawing the MUC nicks by a different color
Michal 'vorner' Vaner <vorner@ucw.cz>
parents: 1283
diff changeset
   554
  scr_WriteIncomingMessage(bjid, buf, 0, HBB_PREFIX_INFO, 0);
1003
c8b1a52b2fd6 Initial VCard retrieval support
Mikael Berthe <mikael@lilotux.net>
parents: 1002
diff changeset
   555
  g_free(buf);
c8b1a52b2fd6 Initial VCard retrieval support
Mikael Berthe <mikael@lilotux.net>
parents: 1002
diff changeset
   556
c8b1a52b2fd6 Initial VCard retrieval support
Mikael Berthe <mikael@lilotux.net>
parents: 1002
diff changeset
   557
  // Get result data...
c8b1a52b2fd6 Initial VCard retrieval support
Mikael Berthe <mikael@lilotux.net>
parents: 1002
diff changeset
   558
  handle_vcard_node(bjid, ansqry);
1598
a087125d8fc8 Replace libjabber with loudmouth
franky
parents: 1575
diff changeset
   559
  return LM_HANDLER_RESULT_REMOVE_MESSAGE;
1003
c8b1a52b2fd6 Initial VCard retrieval support
Mikael Berthe <mikael@lilotux.net>
parents: 1002
diff changeset
   560
}
c8b1a52b2fd6 Initial VCard retrieval support
Mikael Berthe <mikael@lilotux.net>
parents: 1002
diff changeset
   561
1598
a087125d8fc8 Replace libjabber with loudmouth
franky
parents: 1575
diff changeset
   562
static void storage_bookmarks_parse_conference(LmMessageNode *node)
1004
b57a01ffeed6 Use existing conference bookmarks
Mikael Berthe <mikael@lilotux.net>
parents: 1003
diff changeset
   563
{
1058
c0d44a9a99bc Code cleanup
Mikael Berthe <mikael@lilotux.net>
parents: 1037
diff changeset
   564
  const char *fjid, *name, *autojoin;
1979
6febc7d1f760 Add /room setopt flag_joins (Hermitifier)
Mikael Berthe <mikael@lilotux.net>
parents: 1976
diff changeset
   565
  const char *pstatus, *awhois, *fjoins, *group;
1004
b57a01ffeed6 Use existing conference bookmarks
Mikael Berthe <mikael@lilotux.net>
parents: 1003
diff changeset
   566
  char *bjid;
b57a01ffeed6 Use existing conference bookmarks
Mikael Berthe <mikael@lilotux.net>
parents: 1003
diff changeset
   567
  GSList *room_elt;
b57a01ffeed6 Use existing conference bookmarks
Mikael Berthe <mikael@lilotux.net>
parents: 1003
diff changeset
   568
1598
a087125d8fc8 Replace libjabber with loudmouth
franky
parents: 1575
diff changeset
   569
  fjid = lm_message_node_get_attribute(node, "jid");
1058
c0d44a9a99bc Code cleanup
Mikael Berthe <mikael@lilotux.net>
parents: 1037
diff changeset
   570
  if (!fjid)
1004
b57a01ffeed6 Use existing conference bookmarks
Mikael Berthe <mikael@lilotux.net>
parents: 1003
diff changeset
   571
    return;
1598
a087125d8fc8 Replace libjabber with loudmouth
franky
parents: 1575
diff changeset
   572
  name = lm_message_node_get_attribute(node, "name");
a087125d8fc8 Replace libjabber with loudmouth
franky
parents: 1575
diff changeset
   573
  autojoin = lm_message_node_get_attribute(node, "autojoin");
a087125d8fc8 Replace libjabber with loudmouth
franky
parents: 1575
diff changeset
   574
  awhois = lm_message_node_get_attribute(node, "autowhois");
a087125d8fc8 Replace libjabber with loudmouth
franky
parents: 1575
diff changeset
   575
  pstatus = lm_message_node_get_child_value(node, "print_status");
1979
6febc7d1f760 Add /room setopt flag_joins (Hermitifier)
Mikael Berthe <mikael@lilotux.net>
parents: 1976
diff changeset
   576
  fjoins = lm_message_node_get_child_value(node, "flag_joins");
1976
e6beab22099b Do not add items to roster with commands /move and /rename (Hermitifier)
Mikael Berthe <mikael@lilotux.net>
parents: 1899
diff changeset
   577
  group = lm_message_node_get_child_value(node, "group");
1004
b57a01ffeed6 Use existing conference bookmarks
Mikael Berthe <mikael@lilotux.net>
parents: 1003
diff changeset
   578
1058
c0d44a9a99bc Code cleanup
Mikael Berthe <mikael@lilotux.net>
parents: 1037
diff changeset
   579
  bjid = jidtodisp(fjid); // Bare jid
1004
b57a01ffeed6 Use existing conference bookmarks
Mikael Berthe <mikael@lilotux.net>
parents: 1003
diff changeset
   580
b57a01ffeed6 Use existing conference bookmarks
Mikael Berthe <mikael@lilotux.net>
parents: 1003
diff changeset
   581
  // Make sure this is a room (it can be a conversion user->room)
b57a01ffeed6 Use existing conference bookmarks
Mikael Berthe <mikael@lilotux.net>
parents: 1003
diff changeset
   582
  room_elt = roster_find(bjid, jidsearch, 0);
b57a01ffeed6 Use existing conference bookmarks
Mikael Berthe <mikael@lilotux.net>
parents: 1003
diff changeset
   583
  if (!room_elt) {
1976
e6beab22099b Do not add items to roster with commands /move and /rename (Hermitifier)
Mikael Berthe <mikael@lilotux.net>
parents: 1899
diff changeset
   584
    room_elt = roster_add_user(bjid, name, group, ROSTER_TYPE_ROOM,
1355
9716cf8a0726 Add on_server flag
Mikael Berthe <mikael@lilotux.net>
parents: 1353
diff changeset
   585
                               sub_none, -1);
1004
b57a01ffeed6 Use existing conference bookmarks
Mikael Berthe <mikael@lilotux.net>
parents: 1003
diff changeset
   586
  } else {
b57a01ffeed6 Use existing conference bookmarks
Mikael Berthe <mikael@lilotux.net>
parents: 1003
diff changeset
   587
    buddy_settype(room_elt->data, ROSTER_TYPE_ROOM);
b57a01ffeed6 Use existing conference bookmarks
Mikael Berthe <mikael@lilotux.net>
parents: 1003
diff changeset
   588
    /*
b57a01ffeed6 Use existing conference bookmarks
Mikael Berthe <mikael@lilotux.net>
parents: 1003
diff changeset
   589
    // If the name is available, should we use it?
b57a01ffeed6 Use existing conference bookmarks
Mikael Berthe <mikael@lilotux.net>
parents: 1003
diff changeset
   590
    // I don't think so, it would be confusing because this item is already
b57a01ffeed6 Use existing conference bookmarks
Mikael Berthe <mikael@lilotux.net>
parents: 1003
diff changeset
   591
    // in the roster.
b57a01ffeed6 Use existing conference bookmarks
Mikael Berthe <mikael@lilotux.net>
parents: 1003
diff changeset
   592
    if (name)
b57a01ffeed6 Use existing conference bookmarks
Mikael Berthe <mikael@lilotux.net>
parents: 1003
diff changeset
   593
      buddy_setname(room_elt->data, name);
1976
e6beab22099b Do not add items to roster with commands /move and /rename (Hermitifier)
Mikael Berthe <mikael@lilotux.net>
parents: 1899
diff changeset
   594
e6beab22099b Do not add items to roster with commands /move and /rename (Hermitifier)
Mikael Berthe <mikael@lilotux.net>
parents: 1899
diff changeset
   595
    // The same question for roster group.
e6beab22099b Do not add items to roster with commands /move and /rename (Hermitifier)
Mikael Berthe <mikael@lilotux.net>
parents: 1899
diff changeset
   596
    if (group)
e6beab22099b Do not add items to roster with commands /move and /rename (Hermitifier)
Mikael Berthe <mikael@lilotux.net>
parents: 1899
diff changeset
   597
      buddy_setgroup(room_elt->data, group);
1004
b57a01ffeed6 Use existing conference bookmarks
Mikael Berthe <mikael@lilotux.net>
parents: 1003
diff changeset
   598
    */
b57a01ffeed6 Use existing conference bookmarks
Mikael Berthe <mikael@lilotux.net>
parents: 1003
diff changeset
   599
  }
b57a01ffeed6 Use existing conference bookmarks
Mikael Berthe <mikael@lilotux.net>
parents: 1003
diff changeset
   600
1379
74b7621537d7 MUC: Store room settings (print_status, auto_whois) in private storage
Mikael Berthe <mikael@lilotux.net>
parents: 1365
diff changeset
   601
  // Set the print_status and auto_whois values
74b7621537d7 MUC: Store room settings (print_status, auto_whois) in private storage
Mikael Berthe <mikael@lilotux.net>
parents: 1365
diff changeset
   602
  if (pstatus) {
74b7621537d7 MUC: Store room settings (print_status, auto_whois) in private storage
Mikael Berthe <mikael@lilotux.net>
parents: 1365
diff changeset
   603
    enum room_printstatus i;
74b7621537d7 MUC: Store room settings (print_status, auto_whois) in private storage
Mikael Berthe <mikael@lilotux.net>
parents: 1365
diff changeset
   604
    for (i = status_none; i <= status_all; i++)
74b7621537d7 MUC: Store room settings (print_status, auto_whois) in private storage
Mikael Berthe <mikael@lilotux.net>
parents: 1365
diff changeset
   605
      if (!strcasecmp(pstatus, strprintstatus[i]))
74b7621537d7 MUC: Store room settings (print_status, auto_whois) in private storage
Mikael Berthe <mikael@lilotux.net>
parents: 1365
diff changeset
   606
        break;
74b7621537d7 MUC: Store room settings (print_status, auto_whois) in private storage
Mikael Berthe <mikael@lilotux.net>
parents: 1365
diff changeset
   607
    if (i <= status_all)
74b7621537d7 MUC: Store room settings (print_status, auto_whois) in private storage
Mikael Berthe <mikael@lilotux.net>
parents: 1365
diff changeset
   608
      buddy_setprintstatus(room_elt->data, i);
74b7621537d7 MUC: Store room settings (print_status, auto_whois) in private storage
Mikael Berthe <mikael@lilotux.net>
parents: 1365
diff changeset
   609
  }
74b7621537d7 MUC: Store room settings (print_status, auto_whois) in private storage
Mikael Berthe <mikael@lilotux.net>
parents: 1365
diff changeset
   610
  if (awhois) {
74b7621537d7 MUC: Store room settings (print_status, auto_whois) in private storage
Mikael Berthe <mikael@lilotux.net>
parents: 1365
diff changeset
   611
    enum room_autowhois i = autowhois_default;
1976
e6beab22099b Do not add items to roster with commands /move and /rename (Hermitifier)
Mikael Berthe <mikael@lilotux.net>
parents: 1899
diff changeset
   612
    if (!strcmp(awhois, "1") || !(strcmp(awhois, "true")))
1379
74b7621537d7 MUC: Store room settings (print_status, auto_whois) in private storage
Mikael Berthe <mikael@lilotux.net>
parents: 1365
diff changeset
   613
      i = autowhois_on;
1976
e6beab22099b Do not add items to roster with commands /move and /rename (Hermitifier)
Mikael Berthe <mikael@lilotux.net>
parents: 1899
diff changeset
   614
    else if (!strcmp(awhois, "0") || !(strcmp(awhois, "false")))
1379
74b7621537d7 MUC: Store room settings (print_status, auto_whois) in private storage
Mikael Berthe <mikael@lilotux.net>
parents: 1365
diff changeset
   615
      i = autowhois_off;
74b7621537d7 MUC: Store room settings (print_status, auto_whois) in private storage
Mikael Berthe <mikael@lilotux.net>
parents: 1365
diff changeset
   616
    if (i != autowhois_default)
74b7621537d7 MUC: Store room settings (print_status, auto_whois) in private storage
Mikael Berthe <mikael@lilotux.net>
parents: 1365
diff changeset
   617
      buddy_setautowhois(room_elt->data, i);
74b7621537d7 MUC: Store room settings (print_status, auto_whois) in private storage
Mikael Berthe <mikael@lilotux.net>
parents: 1365
diff changeset
   618
  }
1979
6febc7d1f760 Add /room setopt flag_joins (Hermitifier)
Mikael Berthe <mikael@lilotux.net>
parents: 1976
diff changeset
   619
  if (fjoins) {
6febc7d1f760 Add /room setopt flag_joins (Hermitifier)
Mikael Berthe <mikael@lilotux.net>
parents: 1976
diff changeset
   620
    enum room_flagjoins i;
6febc7d1f760 Add /room setopt flag_joins (Hermitifier)
Mikael Berthe <mikael@lilotux.net>
parents: 1976
diff changeset
   621
    for (i = flagjoins_none; i <= flagjoins_all; i++)
6febc7d1f760 Add /room setopt flag_joins (Hermitifier)
Mikael Berthe <mikael@lilotux.net>
parents: 1976
diff changeset
   622
      if (!strcasecmp(fjoins, strflagjoins[i]))
6febc7d1f760 Add /room setopt flag_joins (Hermitifier)
Mikael Berthe <mikael@lilotux.net>
parents: 1976
diff changeset
   623
        break;
6febc7d1f760 Add /room setopt flag_joins (Hermitifier)
Mikael Berthe <mikael@lilotux.net>
parents: 1976
diff changeset
   624
    if (i <= flagjoins_all)
6febc7d1f760 Add /room setopt flag_joins (Hermitifier)
Mikael Berthe <mikael@lilotux.net>
parents: 1976
diff changeset
   625
      buddy_setflagjoins(room_elt->data, i);
6febc7d1f760 Add /room setopt flag_joins (Hermitifier)
Mikael Berthe <mikael@lilotux.net>
parents: 1976
diff changeset
   626
  }
1379
74b7621537d7 MUC: Store room settings (print_status, auto_whois) in private storage
Mikael Berthe <mikael@lilotux.net>
parents: 1365
diff changeset
   627
1004
b57a01ffeed6 Use existing conference bookmarks
Mikael Berthe <mikael@lilotux.net>
parents: 1003
diff changeset
   628
  // Is autojoin set?
b57a01ffeed6 Use existing conference bookmarks
Mikael Berthe <mikael@lilotux.net>
parents: 1003
diff changeset
   629
  // If it is, we'll look up for more information (nick? password?) and
b57a01ffeed6 Use existing conference bookmarks
Mikael Berthe <mikael@lilotux.net>
parents: 1003
diff changeset
   630
  // try to join the room.
2004
aa7e03c35488 Accept "true" as well as "1" for autojoin in bookmarked rooms
Hermitifier
parents: 2003
diff changeset
   631
  if (autojoin && (!strcmp(autojoin, "1") || !strcmp(autojoin, "true"))) {
1598
a087125d8fc8 Replace libjabber with loudmouth
franky
parents: 1575
diff changeset
   632
    const char *nick, *passwd;
1004
b57a01ffeed6 Use existing conference bookmarks
Mikael Berthe <mikael@lilotux.net>
parents: 1003
diff changeset
   633
    char *tmpnick = NULL;
1598
a087125d8fc8 Replace libjabber with loudmouth
franky
parents: 1575
diff changeset
   634
    nick = lm_message_node_get_child_value(node, "nick");
a087125d8fc8 Replace libjabber with loudmouth
franky
parents: 1575
diff changeset
   635
    passwd = lm_message_node_get_child_value(node, "password");
1004
b57a01ffeed6 Use existing conference bookmarks
Mikael Berthe <mikael@lilotux.net>
parents: 1003
diff changeset
   636
    if (!nick || !*nick)
1395
d431cd75eb53 Use bookmarked nickname when manually joining a room
Mikael Berthe <mikael@lilotux.net>
parents: 1393
diff changeset
   637
      nick = tmpnick = default_muc_nickname(NULL);
1004
b57a01ffeed6 Use existing conference bookmarks
Mikael Berthe <mikael@lilotux.net>
parents: 1003
diff changeset
   638
    // Let's join now
b57a01ffeed6 Use existing conference bookmarks
Mikael Berthe <mikael@lilotux.net>
parents: 1003
diff changeset
   639
    scr_LogPrint(LPRINT_LOGNORM, "Auto-join bookmark <%s>", bjid);
1598
a087125d8fc8 Replace libjabber with loudmouth
franky
parents: 1575
diff changeset
   640
    xmpp_room_join(bjid, nick, passwd);
1004
b57a01ffeed6 Use existing conference bookmarks
Mikael Berthe <mikael@lilotux.net>
parents: 1003
diff changeset
   641
    g_free(tmpnick);
b57a01ffeed6 Use existing conference bookmarks
Mikael Berthe <mikael@lilotux.net>
parents: 1003
diff changeset
   642
  }
b57a01ffeed6 Use existing conference bookmarks
Mikael Berthe <mikael@lilotux.net>
parents: 1003
diff changeset
   643
  g_free(bjid);
1983
45e0b13a39e2 Refresh the roster when MUC bookmarks are received
Jan Zachorowski <quantifier666@gmail.com>
parents: 1979
diff changeset
   644
45e0b13a39e2 Refresh the roster when MUC bookmarks are received
Jan Zachorowski <quantifier666@gmail.com>
parents: 1979
diff changeset
   645
  buddylist_build();
45e0b13a39e2 Refresh the roster when MUC bookmarks are received
Jan Zachorowski <quantifier666@gmail.com>
parents: 1979
diff changeset
   646
  update_roster = TRUE;
1004
b57a01ffeed6 Use existing conference bookmarks
Mikael Berthe <mikael@lilotux.net>
parents: 1003
diff changeset
   647
}
b57a01ffeed6 Use existing conference bookmarks
Mikael Berthe <mikael@lilotux.net>
parents: 1003
diff changeset
   648
1598
a087125d8fc8 Replace libjabber with loudmouth
franky
parents: 1575
diff changeset
   649
static LmHandlerResult cb_storage_bookmarks(LmMessageHandler *h,
a087125d8fc8 Replace libjabber with loudmouth
franky
parents: 1575
diff changeset
   650
                                            LmConnection *c,
a087125d8fc8 Replace libjabber with loudmouth
franky
parents: 1575
diff changeset
   651
                                            LmMessage *m, gpointer user_data)
1004
b57a01ffeed6 Use existing conference bookmarks
Mikael Berthe <mikael@lilotux.net>
parents: 1003
diff changeset
   652
{
1598
a087125d8fc8 Replace libjabber with loudmouth
franky
parents: 1575
diff changeset
   653
  LmMessageNode *x, *ansqry;
2003
10cec229b41a Handle errors of private storage
Hermitifier
parents: 1983
diff changeset
   654
  char *p = NULL;
1004
b57a01ffeed6 Use existing conference bookmarks
Mikael Berthe <mikael@lilotux.net>
parents: 1003
diff changeset
   655
1598
a087125d8fc8 Replace libjabber with loudmouth
franky
parents: 1575
diff changeset
   656
  if (lm_message_get_sub_type(m) == LM_MESSAGE_SUB_TYPE_ERROR) {
2003
10cec229b41a Handle errors of private storage
Hermitifier
parents: 1983
diff changeset
   657
    LmMessageNode *error = lm_message_node_get_child(m->node, "error");
1213
4a7db2870685 Improve Private Storage detection.
Mikael Berthe <mikael@lilotux.net>
parents: 1205
diff changeset
   658
    // No server support, or no bookmarks?
2003
10cec229b41a Handle errors of private storage
Hermitifier
parents: 1983
diff changeset
   659
    if (error && error->children)
10cec229b41a Handle errors of private storage
Hermitifier
parents: 1983
diff changeset
   660
      p = error->children->name;
1213
4a7db2870685 Improve Private Storage detection.
Mikael Berthe <mikael@lilotux.net>
parents: 1205
diff changeset
   661
    if (p && !strcmp(p, "item-not-found")) {
4a7db2870685 Improve Private Storage detection.
Mikael Berthe <mikael@lilotux.net>
parents: 1205
diff changeset
   662
      // item-no-found means the server has Private Storage, but it's
4a7db2870685 Improve Private Storage detection.
Mikael Berthe <mikael@lilotux.net>
parents: 1205
diff changeset
   663
      // currently empty.
1598
a087125d8fc8 Replace libjabber with loudmouth
franky
parents: 1575
diff changeset
   664
      if (bookmarks)
a087125d8fc8 Replace libjabber with loudmouth
franky
parents: 1575
diff changeset
   665
        lm_message_node_unref(bookmarks);
a087125d8fc8 Replace libjabber with loudmouth
franky
parents: 1575
diff changeset
   666
      bookmarks = lm_message_node_new("storage", "storage:bookmarks");
1213
4a7db2870685 Improve Private Storage detection.
Mikael Berthe <mikael@lilotux.net>
parents: 1205
diff changeset
   667
      // We return 0 so that the IQ error message be
4a7db2870685 Improve Private Storage detection.
Mikael Berthe <mikael@lilotux.net>
parents: 1205
diff changeset
   668
      // not displayed, as it isn't a real error.
2003
10cec229b41a Handle errors of private storage
Hermitifier
parents: 1983
diff changeset
   669
    } else
10cec229b41a Handle errors of private storage
Hermitifier
parents: 1983
diff changeset
   670
      scr_LogPrint(LPRINT_LOGNORM, "Server does not support bookmarks storage.");
10cec229b41a Handle errors of private storage
Hermitifier
parents: 1983
diff changeset
   671
    return LM_HANDLER_RESULT_REMOVE_MESSAGE;
1213
4a7db2870685 Improve Private Storage detection.
Mikael Berthe <mikael@lilotux.net>
parents: 1205
diff changeset
   672
  }
4a7db2870685 Improve Private Storage detection.
Mikael Berthe <mikael@lilotux.net>
parents: 1205
diff changeset
   673
1598
a087125d8fc8 Replace libjabber with loudmouth
franky
parents: 1575
diff changeset
   674
  ansqry = lm_message_node_get_child(m->node, "query");
a087125d8fc8 Replace libjabber with loudmouth
franky
parents: 1575
diff changeset
   675
  ansqry = lm_message_node_get_child(ansqry, "storage");
1004
b57a01ffeed6 Use existing conference bookmarks
Mikael Berthe <mikael@lilotux.net>
parents: 1003
diff changeset
   676
  if (!ansqry) {
b57a01ffeed6 Use existing conference bookmarks
Mikael Berthe <mikael@lilotux.net>
parents: 1003
diff changeset
   677
    scr_LogPrint(LPRINT_LOG, "Invalid IQ:private result! (storage:bookmarks)");
1213
4a7db2870685 Improve Private Storage detection.
Mikael Berthe <mikael@lilotux.net>
parents: 1205
diff changeset
   678
    return 0;
1004
b57a01ffeed6 Use existing conference bookmarks
Mikael Berthe <mikael@lilotux.net>
parents: 1003
diff changeset
   679
  }
b57a01ffeed6 Use existing conference bookmarks
Mikael Berthe <mikael@lilotux.net>
parents: 1003
diff changeset
   680
b57a01ffeed6 Use existing conference bookmarks
Mikael Berthe <mikael@lilotux.net>
parents: 1003
diff changeset
   681
  // Walk through the storage tags
1598
a087125d8fc8 Replace libjabber with loudmouth
franky
parents: 1575
diff changeset
   682
  for (x = ansqry->children ; x; x = x->next) {
1004
b57a01ffeed6 Use existing conference bookmarks
Mikael Berthe <mikael@lilotux.net>
parents: 1003
diff changeset
   683
    // If the current node is a conference item, parse it and update the roster
1598
a087125d8fc8 Replace libjabber with loudmouth
franky
parents: 1575
diff changeset
   684
    if (x->name && !strcmp(x->name, "conference"))
1004
b57a01ffeed6 Use existing conference bookmarks
Mikael Berthe <mikael@lilotux.net>
parents: 1003
diff changeset
   685
      storage_bookmarks_parse_conference(x);
b57a01ffeed6 Use existing conference bookmarks
Mikael Berthe <mikael@lilotux.net>
parents: 1003
diff changeset
   686
  }
1598
a087125d8fc8 Replace libjabber with loudmouth
franky
parents: 1575
diff changeset
   687
  // "Copy" the bookmarks node
a087125d8fc8 Replace libjabber with loudmouth
franky
parents: 1575
diff changeset
   688
  if (bookmarks)
a087125d8fc8 Replace libjabber with loudmouth
franky
parents: 1575
diff changeset
   689
    lm_message_node_unref(bookmarks);
a087125d8fc8 Replace libjabber with loudmouth
franky
parents: 1575
diff changeset
   690
  lm_message_node_deep_ref(ansqry);
a087125d8fc8 Replace libjabber with loudmouth
franky
parents: 1575
diff changeset
   691
  bookmarks = ansqry;
1213
4a7db2870685 Improve Private Storage detection.
Mikael Berthe <mikael@lilotux.net>
parents: 1205
diff changeset
   692
  return 0;
686
98de2d166a11 Use the new IQ system for authentication
Mikael Berthe <mikael@lilotux.net>
parents: 685
diff changeset
   693
}
98de2d166a11 Use the new IQ system for authentication
Mikael Berthe <mikael@lilotux.net>
parents: 685
diff changeset
   694
577
5c6d364130ee Move IQ Jabber stuff to a separate file
Mikael Berthe <mikael@lilotux.net>
parents: 576
diff changeset
   695
1598
a087125d8fc8 Replace libjabber with loudmouth
franky
parents: 1575
diff changeset
   696
static LmHandlerResult cb_storage_rosternotes(LmMessageHandler *h,
a087125d8fc8 Replace libjabber with loudmouth
franky
parents: 1575
diff changeset
   697
                                              LmConnection *c,
a087125d8fc8 Replace libjabber with loudmouth
franky
parents: 1575
diff changeset
   698
                                              LmMessage *m, gpointer user_data)
1261
704adf4df2d0 Send service-unavailable when Last Activity is disabled
Mikael Berthe <mikael@lilotux.net>
parents: 1255
diff changeset
   699
{
1598
a087125d8fc8 Replace libjabber with loudmouth
franky
parents: 1575
diff changeset
   700
  LmMessageNode *ansqry;
1158
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
   701
1598
a087125d8fc8 Replace libjabber with loudmouth
franky
parents: 1575
diff changeset
   702
  if (lm_message_get_sub_type(m) == LM_MESSAGE_SUB_TYPE_ERROR) {
2003
10cec229b41a Handle errors of private storage
Hermitifier
parents: 1983
diff changeset
   703
    const char *p = NULL;
10cec229b41a Handle errors of private storage
Hermitifier
parents: 1983
diff changeset
   704
    LmMessageNode *error = lm_message_node_get_child(m->node, "error");
1598
a087125d8fc8 Replace libjabber with loudmouth
franky
parents: 1575
diff changeset
   705
    // No server support, or no roster notes?
2003
10cec229b41a Handle errors of private storage
Hermitifier
parents: 1983
diff changeset
   706
    if (error && error->children)
10cec229b41a Handle errors of private storage
Hermitifier
parents: 1983
diff changeset
   707
      p = error->children->name;
1598
a087125d8fc8 Replace libjabber with loudmouth
franky
parents: 1575
diff changeset
   708
    if (p && !strcmp(p, "item-not-found")) {
a087125d8fc8 Replace libjabber with loudmouth
franky
parents: 1575
diff changeset
   709
      // item-no-found means the server has Private Storage, but it's
a087125d8fc8 Replace libjabber with loudmouth
franky
parents: 1575
diff changeset
   710
      // currently empty.
a087125d8fc8 Replace libjabber with loudmouth
franky
parents: 1575
diff changeset
   711
      if (rosternotes)
a087125d8fc8 Replace libjabber with loudmouth
franky
parents: 1575
diff changeset
   712
        lm_message_node_unref(rosternotes);
a087125d8fc8 Replace libjabber with loudmouth
franky
parents: 1575
diff changeset
   713
      rosternotes = lm_message_node_new("storage", "storage:rosternotes");
a087125d8fc8 Replace libjabber with loudmouth
franky
parents: 1575
diff changeset
   714
      // We return 0 so that the IQ error message be
a087125d8fc8 Replace libjabber with loudmouth
franky
parents: 1575
diff changeset
   715
      // not displayed, as it isn't a real error.
2003
10cec229b41a Handle errors of private storage
Hermitifier
parents: 1983
diff changeset
   716
    } else
10cec229b41a Handle errors of private storage
Hermitifier
parents: 1983
diff changeset
   717
      scr_LogPrint(LPRINT_LOGNORM, "Server does not support roster notes storage.");
10cec229b41a Handle errors of private storage
Hermitifier
parents: 1983
diff changeset
   718
    return LM_HANDLER_RESULT_REMOVE_MESSAGE;
1158
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
   719
  }
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
   720
1598
a087125d8fc8 Replace libjabber with loudmouth
franky
parents: 1575
diff changeset
   721
  ansqry = lm_message_node_get_child(m->node, "query");
a087125d8fc8 Replace libjabber with loudmouth
franky
parents: 1575
diff changeset
   722
  ansqry = lm_message_node_get_child(ansqry, "storage");
a087125d8fc8 Replace libjabber with loudmouth
franky
parents: 1575
diff changeset
   723
  if (!ansqry) {
a087125d8fc8 Replace libjabber with loudmouth
franky
parents: 1575
diff changeset
   724
    scr_LogPrint(LPRINT_LOG, "Invalid IQ:private result! "
a087125d8fc8 Replace libjabber with loudmouth
franky
parents: 1575
diff changeset
   725
                 "(storage:rosternotes)");
a087125d8fc8 Replace libjabber with loudmouth
franky
parents: 1575
diff changeset
   726
    return LM_HANDLER_RESULT_REMOVE_MESSAGE;
1158
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
   727
  }
1598
a087125d8fc8 Replace libjabber with loudmouth
franky
parents: 1575
diff changeset
   728
  // Copy the rosternotes node
a087125d8fc8 Replace libjabber with loudmouth
franky
parents: 1575
diff changeset
   729
  if (rosternotes)
a087125d8fc8 Replace libjabber with loudmouth
franky
parents: 1575
diff changeset
   730
    lm_message_node_unref(rosternotes);
a087125d8fc8 Replace libjabber with loudmouth
franky
parents: 1575
diff changeset
   731
  lm_message_node_deep_ref(ansqry);
a087125d8fc8 Replace libjabber with loudmouth
franky
parents: 1575
diff changeset
   732
  rosternotes = ansqry;
a087125d8fc8 Replace libjabber with loudmouth
franky
parents: 1575
diff changeset
   733
  return 0;
1158
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
   734
}
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
   735
995
c89e7993c4d9 Answer IQ disco#info queries
Mikael Berthe <mikael@lilotux.net>
parents: 977
diff changeset
   736
1598
a087125d8fc8 Replace libjabber with loudmouth
franky
parents: 1575
diff changeset
   737
static struct IqRequestStorageHandlers
1254
401639413340 More jabber:iq:last support... (misc)
Mikael Berthe <mikael@lilotux.net>
parents: 1224
diff changeset
   738
{
1598
a087125d8fc8 Replace libjabber with loudmouth
franky
parents: 1575
diff changeset
   739
  const gchar *storagens;
a087125d8fc8 Replace libjabber with loudmouth
franky
parents: 1575
diff changeset
   740
  LmHandleMessageFunction handler;
a087125d8fc8 Replace libjabber with loudmouth
franky
parents: 1575
diff changeset
   741
} iq_request_storage_handlers[] = {
a087125d8fc8 Replace libjabber with loudmouth
franky
parents: 1575
diff changeset
   742
  {"storage:rosternotes", &cb_storage_rosternotes},
a087125d8fc8 Replace libjabber with loudmouth
franky
parents: 1575
diff changeset
   743
  {"storage:bookmarks", &cb_storage_bookmarks},
a087125d8fc8 Replace libjabber with loudmouth
franky
parents: 1575
diff changeset
   744
  {NULL, NULL}
a087125d8fc8 Replace libjabber with loudmouth
franky
parents: 1575
diff changeset
   745
};
619
44ddf9bec3a5 Answer IQ:version & IQ:time requests
Mikael Berthe <mikael@lilotux.net>
parents: 613
diff changeset
   746
1598
a087125d8fc8 Replace libjabber with loudmouth
franky
parents: 1575
diff changeset
   747
void xmpp_request_storage(const gchar *storage)
619
44ddf9bec3a5 Answer IQ:version & IQ:time requests
Mikael Berthe <mikael@lilotux.net>
parents: 613
diff changeset
   748
{
1598
a087125d8fc8 Replace libjabber with loudmouth
franky
parents: 1575
diff changeset
   749
  LmMessage *iq;
a087125d8fc8 Replace libjabber with loudmouth
franky
parents: 1575
diff changeset
   750
  LmMessageNode *query;
a087125d8fc8 Replace libjabber with loudmouth
franky
parents: 1575
diff changeset
   751
  LmMessageHandler *handler;
a087125d8fc8 Replace libjabber with loudmouth
franky
parents: 1575
diff changeset
   752
  int i;
703
8cbcbff8de7d Fix UTC time in IQ:version queries
Mikael Berthe <mikael@lilotux.net>
parents: 699
diff changeset
   753
1598
a087125d8fc8 Replace libjabber with loudmouth
franky
parents: 1575
diff changeset
   754
  iq = lm_message_new_with_sub_type(NULL, LM_MESSAGE_TYPE_IQ,
a087125d8fc8 Replace libjabber with loudmouth
franky
parents: 1575
diff changeset
   755
                                    LM_MESSAGE_SUB_TYPE_GET);
a087125d8fc8 Replace libjabber with loudmouth
franky
parents: 1575
diff changeset
   756
  query = lm_message_node_add_child(iq->node, "query", NULL);
a087125d8fc8 Replace libjabber with loudmouth
franky
parents: 1575
diff changeset
   757
  lm_message_node_set_attribute(query, "xmlns", NS_PRIVATE);
a087125d8fc8 Replace libjabber with loudmouth
franky
parents: 1575
diff changeset
   758
  lm_message_node_set_attribute(lm_message_node_add_child
a087125d8fc8 Replace libjabber with loudmouth
franky
parents: 1575
diff changeset
   759
                                (query, "storage", NULL),
a087125d8fc8 Replace libjabber with loudmouth
franky
parents: 1575
diff changeset
   760
                                "xmlns", storage);
1283
2faf179166f3 Implement XEP-0202 (Entity Time)
Mikael Berthe <mikael@lilotux.net>
parents: 1268
diff changeset
   761
1598
a087125d8fc8 Replace libjabber with loudmouth
franky
parents: 1575
diff changeset
   762
  for (i = 0;
a087125d8fc8 Replace libjabber with loudmouth
franky
parents: 1575
diff changeset
   763
       strcmp(iq_request_storage_handlers[i].storagens, storage) != 0;
a087125d8fc8 Replace libjabber with loudmouth
franky
parents: 1575
diff changeset
   764
       ++i) ;
595
0c1d37300862 IQ: send feature-not-implemented error stanzas
Mikael Berthe <mikael@lilotux.net>
parents: 582
diff changeset
   765
1598
a087125d8fc8 Replace libjabber with loudmouth
franky
parents: 1575
diff changeset
   766
  handler = lm_message_handler_new(iq_request_storage_handlers[i].handler,
a087125d8fc8 Replace libjabber with loudmouth
franky
parents: 1575
diff changeset
   767
                                   NULL, FALSE);
a087125d8fc8 Replace libjabber with loudmouth
franky
parents: 1575
diff changeset
   768
  lm_connection_send_with_reply(lconnection, iq, handler, NULL);
a087125d8fc8 Replace libjabber with loudmouth
franky
parents: 1575
diff changeset
   769
  lm_message_handler_unref(handler);
a087125d8fc8 Replace libjabber with loudmouth
franky
parents: 1575
diff changeset
   770
  lm_message_unref(iq);
547
1df26ff0ed8c Break packethandler() out
Mikael Berthe <mikael@lilotux.net>
parents: 539
diff changeset
   771
}
1599
dcd5d4c75199 Update/Add headers
Mikael Berthe <mikael@lilotux.net>
parents: 1598
diff changeset
   772
1811
e6d355e50d7a Update Vim modelines
Mikael Berthe <mikael@lilotux.net>
parents: 1800
diff changeset
   773
/* vim: set et cindent cinoptions=>2\:2(0 ts=2 sw=2:  For Vim users... */