mcabber/src/jab_iq.c
author Mikael Berthe <mikael@lilotux.net>
Tue, 01 May 2007 18:16:11 +0200
changeset 1213 4a7db2870685
parent 1205 2de8f8ba1f34
child 1215 80c095886fb5
permissions -rw-r--r--
Improve Private Storage detection. MCabber now correctly detects Private Storage support when receiving an item-not-found error (which doesn't mean the server has no support for P.S., but that it's empty). I've added a return value to the callback functions. For now the return value is only used for IQ error handling.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
29
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
     1
/*
577
5c6d364130ee Move IQ Jabber stuff to a separate file
Mikael Berthe <mikael@lilotux.net>
parents: 576
diff changeset
     2
 * jab_iq.c     -- Jabber protocol IQ-related fonctions
393
f8f3c7493457 Whitespace cleanup
Mikael Berthe <mikael@lilotux.net>
parents: 387
diff changeset
     3
 *
1205
2de8f8ba1f34 Update copyrights
Mikael Berthe <mikael@lilotux.net>
parents: 1198
diff changeset
     4
 * Copyright (C) 2005-2007 Mikael Berthe <mikael@lilotux.net>
577
5c6d364130ee Move IQ Jabber stuff to a separate file
Mikael Berthe <mikael@lilotux.net>
parents: 576
diff changeset
     5
 * Some parts initially came from the centericq project:
29
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
     6
 * Copyright (C) 2002-2005 by Konstantin Klyagin <konst@konst.org.ua>
619
44ddf9bec3a5 Answer IQ:version & IQ:time requests
Mikael Berthe <mikael@lilotux.net>
parents: 613
diff changeset
     7
 * Some small parts come from the Gaim project <http://gaim.sourceforge.net/>
29
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
     8
 *
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
     9
 * This program is free software; you can redistribute it and/or modify
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
    10
 * it under the terms of the GNU General Public License as published by
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
    11
 * the Free Software Foundation; either version 2 of the License, or (at
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
    12
 * your option) any later version.
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
    13
 *
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
    14
 * This program is distributed in the hope that it will be useful, but
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
    15
 * WITHOUT ANY WARRANTY; without even the implied warranty of
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
    16
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
    17
 * General Public License for more details.
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
    18
 *
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
    19
 * You should have received a copy of the GNU General Public License
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
    20
 * along with this program; if not, write to the Free Software
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
    21
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
    22
 * USA
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
    23
 */
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
    24
619
44ddf9bec3a5 Answer IQ:version & IQ:time requests
Mikael Berthe <mikael@lilotux.net>
parents: 613
diff changeset
    25
#include <sys/utsname.h>
603
9516db839e08 Store subscription data
Mikael Berthe <mikael@lilotux.net>
parents: 597
diff changeset
    26
#include <glib.h>
9516db839e08 Store subscription data
Mikael Berthe <mikael@lilotux.net>
parents: 597
diff changeset
    27
29
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
    28
#include "jabglue.h"
577
5c6d364130ee Move IQ Jabber stuff to a separate file
Mikael Berthe <mikael@lilotux.net>
parents: 576
diff changeset
    29
#include "jab_priv.h"
81
0bd578421ce9 [/trunk] Changeset 95 by mikael
mikael
parents: 52
diff changeset
    30
#include "roster.h"
29
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
    31
#include "utils.h"
603
9516db839e08 Store subscription data
Mikael Berthe <mikael@lilotux.net>
parents: 597
diff changeset
    32
#include "screen.h"
619
44ddf9bec3a5 Answer IQ:version & IQ:time requests
Mikael Berthe <mikael@lilotux.net>
parents: 613
diff changeset
    33
#include "settings.h"
704
4118a66f2c02 Display IQ results (time, version) in the chat window
Mikael Berthe <mikael@lilotux.net>
parents: 703
diff changeset
    34
#include "hbuf.h"
1158
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
    35
#include "commands.h"
164
faf534be8ff0 [/trunk] Changeset 176 by mikael
mikael
parents: 159
diff changeset
    36
683
c5e0d8c3f00c Introduce new IQ system
Mikael Berthe <mikael@lilotux.net>
parents: 619
diff changeset
    37
1008
bbf53cd43fbb Functions to update room bookmarks
Mikael Berthe <mikael@lilotux.net>
parents: 1006
diff changeset
    38
// Bookmarks for IQ:private storage
bbf53cd43fbb Functions to update room bookmarks
Mikael Berthe <mikael@lilotux.net>
parents: 1006
diff changeset
    39
xmlnode bookmarks;
1016
4d3c48844746 Add /roster note
Mikael Berthe <mikael@lilotux.net>
parents: 1015
diff changeset
    40
// Roster notes for IQ:private storage
4d3c48844746 Add /roster note
Mikael Berthe <mikael@lilotux.net>
parents: 1015
diff changeset
    41
xmlnode rosternotes;
1008
bbf53cd43fbb Functions to update room bookmarks
Mikael Berthe <mikael@lilotux.net>
parents: 1006
diff changeset
    42
683
c5e0d8c3f00c Introduce new IQ system
Mikael Berthe <mikael@lilotux.net>
parents: 619
diff changeset
    43
static GSList *iqs_list;
c5e0d8c3f00c Introduce new IQ system
Mikael Berthe <mikael@lilotux.net>
parents: 619
diff changeset
    44
1006
f61131cd86a0 Clean up vcard code
Mikael Berthe <mikael@lilotux.net>
parents: 1005
diff changeset
    45
// Enum for vCard attributes
f61131cd86a0 Clean up vcard code
Mikael Berthe <mikael@lilotux.net>
parents: 1005
diff changeset
    46
enum vcard_attr {
f61131cd86a0 Clean up vcard code
Mikael Berthe <mikael@lilotux.net>
parents: 1005
diff changeset
    47
  vcard_home    = 1<<0,
f61131cd86a0 Clean up vcard code
Mikael Berthe <mikael@lilotux.net>
parents: 1005
diff changeset
    48
  vcard_work    = 1<<1,
f61131cd86a0 Clean up vcard code
Mikael Berthe <mikael@lilotux.net>
parents: 1005
diff changeset
    49
  vcard_postal  = 1<<2,
f61131cd86a0 Clean up vcard code
Mikael Berthe <mikael@lilotux.net>
parents: 1005
diff changeset
    50
  vcard_voice   = 1<<3,
f61131cd86a0 Clean up vcard code
Mikael Berthe <mikael@lilotux.net>
parents: 1005
diff changeset
    51
  vcard_fax     = 1<<4,
f61131cd86a0 Clean up vcard code
Mikael Berthe <mikael@lilotux.net>
parents: 1005
diff changeset
    52
  vcard_cell    = 1<<5,
f61131cd86a0 Clean up vcard code
Mikael Berthe <mikael@lilotux.net>
parents: 1005
diff changeset
    53
  vcard_inet    = 1<<6,
f61131cd86a0 Clean up vcard code
Mikael Berthe <mikael@lilotux.net>
parents: 1005
diff changeset
    54
  vcard_pref    = 1<<7,
f61131cd86a0 Clean up vcard code
Mikael Berthe <mikael@lilotux.net>
parents: 1005
diff changeset
    55
};
683
c5e0d8c3f00c Introduce new IQ system
Mikael Berthe <mikael@lilotux.net>
parents: 619
diff changeset
    56
1158
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
    57
static void handle_iq_command_set_status(jconn conn, char *from,
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
    58
                                         const char *id, xmlnode xmldata);
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
    59
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
    60
static void handle_iq_command_leave_groupchats(jconn conn, char *from,
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
    61
                                               const char *id, xmlnode xmldata);
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
    62
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
    63
typedef void (*adhoc_command_callback)(jconn, char*, const char*, xmlnode);
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
    64
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
    65
struct adhoc_command {
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
    66
  char *name;
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
    67
  char *description;
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
    68
  bool only_for_self;
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
    69
  adhoc_command_callback callback;
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
    70
};
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
    71
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
    72
const struct adhoc_command adhoc_command_list[] = {
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
    73
  { "http://jabber.org/protocol/rc#set-status",
1159
53c0c5be43fa Small fixes, typos and cleanups
Mikael Berthe <mikael@lilotux.net>
parents: 1158
diff changeset
    74
    "Change client status",
1158
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
    75
    1,
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
    76
    &handle_iq_command_set_status },
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
    77
  { "http://jabber.org/protocol/rc#leave-groupchats",
1159
53c0c5be43fa Small fixes, typos and cleanups
Mikael Berthe <mikael@lilotux.net>
parents: 1158
diff changeset
    78
    "Leave groupchat(s)",
1158
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
    79
    1,
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
    80
    &handle_iq_command_leave_groupchats },
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
    81
  { NULL, NULL, 0, NULL },
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
    82
};
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
    83
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
    84
struct adhoc_status {
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
    85
  char *name;   // the name used by adhoc
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
    86
  char *description;
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
    87
  char *status; // the string, used by setstus
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
    88
};
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
    89
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
    90
const struct adhoc_status adhoc_status_list[] = {
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
    91
  {"online", "Online", "avail"},
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
    92
  {"chat", "Chat", "free"},
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
    93
  {"away", "Away", "away"},
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
    94
  {"xd", "Extended away", "notavail"},
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
    95
  {"dnd", "Do not disturb", "dnd"},
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
    96
  {"invisible", "Invisible", "invisible"},
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
    97
  {"offline", "Offline", "offline"},
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
    98
  {NULL, NULL, NULL},
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
    99
};
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
   100
683
c5e0d8c3f00c Introduce new IQ system
Mikael Berthe <mikael@lilotux.net>
parents: 619
diff changeset
   101
//  iqs_new(type, namespace, prefix, timeout)
c5e0d8c3f00c Introduce new IQ system
Mikael Berthe <mikael@lilotux.net>
parents: 619
diff changeset
   102
// Create a query (GET, SET) IQ structure.  This function should not be used
c5e0d8c3f00c Introduce new IQ system
Mikael Berthe <mikael@lilotux.net>
parents: 619
diff changeset
   103
// for RESULT packets.
1058
c0d44a9a99bc Code cleanup
Mikael Berthe <mikael@lilotux.net>
parents: 1037
diff changeset
   104
eviqs *iqs_new(guint8 type, const char *ns, const char *prefix, time_t tmout)
683
c5e0d8c3f00c Introduce new IQ system
Mikael Berthe <mikael@lilotux.net>
parents: 619
diff changeset
   105
{
c5e0d8c3f00c Introduce new IQ system
Mikael Berthe <mikael@lilotux.net>
parents: 619
diff changeset
   106
  static guint iqs_idn;
745
413e95f3051a Introduce user "events" list
Mikael Berthe <mikael@lilotux.net>
parents: 705
diff changeset
   107
  eviqs *new_iqs;
683
c5e0d8c3f00c Introduce new IQ system
Mikael Berthe <mikael@lilotux.net>
parents: 619
diff changeset
   108
  time_t now_t;
c5e0d8c3f00c Introduce new IQ system
Mikael Berthe <mikael@lilotux.net>
parents: 619
diff changeset
   109
c5e0d8c3f00c Introduce new IQ system
Mikael Berthe <mikael@lilotux.net>
parents: 619
diff changeset
   110
  iqs_idn++;
c5e0d8c3f00c Introduce new IQ system
Mikael Berthe <mikael@lilotux.net>
parents: 619
diff changeset
   111
745
413e95f3051a Introduce user "events" list
Mikael Berthe <mikael@lilotux.net>
parents: 705
diff changeset
   112
  new_iqs = g_new0(eviqs, 1);
683
c5e0d8c3f00c Introduce new IQ system
Mikael Berthe <mikael@lilotux.net>
parents: 619
diff changeset
   113
  time(&now_t);
c5e0d8c3f00c Introduce new IQ system
Mikael Berthe <mikael@lilotux.net>
parents: 619
diff changeset
   114
  new_iqs->ts_create = now_t;
1058
c0d44a9a99bc Code cleanup
Mikael Berthe <mikael@lilotux.net>
parents: 1037
diff changeset
   115
  if (tmout)
c0d44a9a99bc Code cleanup
Mikael Berthe <mikael@lilotux.net>
parents: 1037
diff changeset
   116
    new_iqs->ts_expire = now_t + tmout;
683
c5e0d8c3f00c Introduce new IQ system
Mikael Berthe <mikael@lilotux.net>
parents: 619
diff changeset
   117
  new_iqs->type = type;
c5e0d8c3f00c Introduce new IQ system
Mikael Berthe <mikael@lilotux.net>
parents: 619
diff changeset
   118
  new_iqs->xmldata = jutil_iqnew(type, (char*)ns);
c5e0d8c3f00c Introduce new IQ system
Mikael Berthe <mikael@lilotux.net>
parents: 619
diff changeset
   119
  if (prefix)
687
426145046b93 Minor format change in IQ id string
Mikael Berthe <mikael@lilotux.net>
parents: 686
diff changeset
   120
    new_iqs->id = g_strdup_printf("%s_%d", prefix, iqs_idn);
683
c5e0d8c3f00c Introduce new IQ system
Mikael Berthe <mikael@lilotux.net>
parents: 619
diff changeset
   121
  else
c5e0d8c3f00c Introduce new IQ system
Mikael Berthe <mikael@lilotux.net>
parents: 619
diff changeset
   122
    new_iqs->id = g_strdup_printf("%d", iqs_idn);
c5e0d8c3f00c Introduce new IQ system
Mikael Berthe <mikael@lilotux.net>
parents: 619
diff changeset
   123
  xmlnode_put_attrib(new_iqs->xmldata, "id", new_iqs->id);
c5e0d8c3f00c Introduce new IQ system
Mikael Berthe <mikael@lilotux.net>
parents: 619
diff changeset
   124
c5e0d8c3f00c Introduce new IQ system
Mikael Berthe <mikael@lilotux.net>
parents: 619
diff changeset
   125
  iqs_list = g_slist_append(iqs_list, new_iqs);
c5e0d8c3f00c Introduce new IQ system
Mikael Berthe <mikael@lilotux.net>
parents: 619
diff changeset
   126
  return new_iqs;
c5e0d8c3f00c Introduce new IQ system
Mikael Berthe <mikael@lilotux.net>
parents: 619
diff changeset
   127
}
c5e0d8c3f00c Introduce new IQ system
Mikael Berthe <mikael@lilotux.net>
parents: 619
diff changeset
   128
c5e0d8c3f00c Introduce new IQ system
Mikael Berthe <mikael@lilotux.net>
parents: 619
diff changeset
   129
int iqs_del(const char *iqid)
c5e0d8c3f00c Introduce new IQ system
Mikael Berthe <mikael@lilotux.net>
parents: 619
diff changeset
   130
{
c5e0d8c3f00c Introduce new IQ system
Mikael Berthe <mikael@lilotux.net>
parents: 619
diff changeset
   131
  GSList *p;
745
413e95f3051a Introduce user "events" list
Mikael Berthe <mikael@lilotux.net>
parents: 705
diff changeset
   132
  eviqs *i;
683
c5e0d8c3f00c Introduce new IQ system
Mikael Berthe <mikael@lilotux.net>
parents: 619
diff changeset
   133
c5e0d8c3f00c Introduce new IQ system
Mikael Berthe <mikael@lilotux.net>
parents: 619
diff changeset
   134
  if (!iqid) return 1;
c5e0d8c3f00c Introduce new IQ system
Mikael Berthe <mikael@lilotux.net>
parents: 619
diff changeset
   135
c5e0d8c3f00c Introduce new IQ system
Mikael Berthe <mikael@lilotux.net>
parents: 619
diff changeset
   136
  for (p = iqs_list; p; p = g_slist_next(p)) {
c5e0d8c3f00c Introduce new IQ system
Mikael Berthe <mikael@lilotux.net>
parents: 619
diff changeset
   137
    i = p->data;
c5e0d8c3f00c Introduce new IQ system
Mikael Berthe <mikael@lilotux.net>
parents: 619
diff changeset
   138
    if (!strcmp(iqid, i->id))
c5e0d8c3f00c Introduce new IQ system
Mikael Berthe <mikael@lilotux.net>
parents: 619
diff changeset
   139
      break;
c5e0d8c3f00c Introduce new IQ system
Mikael Berthe <mikael@lilotux.net>
parents: 619
diff changeset
   140
  }
c5e0d8c3f00c Introduce new IQ system
Mikael Berthe <mikael@lilotux.net>
parents: 619
diff changeset
   141
  if (p) {
c5e0d8c3f00c Introduce new IQ system
Mikael Berthe <mikael@lilotux.net>
parents: 619
diff changeset
   142
    g_free(i->id);
774
46304b773a44 Remove useless checks before g_free() calls
Mikael Berthe <mikael@lilotux.net>
parents: 772
diff changeset
   143
    xmlnode_free(i->xmldata);
46304b773a44 Remove useless checks before g_free() calls
Mikael Berthe <mikael@lilotux.net>
parents: 772
diff changeset
   144
    g_free(i->data);
683
c5e0d8c3f00c Introduce new IQ system
Mikael Berthe <mikael@lilotux.net>
parents: 619
diff changeset
   145
    g_free(i);
c5e0d8c3f00c Introduce new IQ system
Mikael Berthe <mikael@lilotux.net>
parents: 619
diff changeset
   146
    iqs_list = g_slist_remove(iqs_list, p->data);
c5e0d8c3f00c Introduce new IQ system
Mikael Berthe <mikael@lilotux.net>
parents: 619
diff changeset
   147
    return 0; // Ok, deleted
c5e0d8c3f00c Introduce new IQ system
Mikael Berthe <mikael@lilotux.net>
parents: 619
diff changeset
   148
  }
c5e0d8c3f00c Introduce new IQ system
Mikael Berthe <mikael@lilotux.net>
parents: 619
diff changeset
   149
  return -1;  // Not found
c5e0d8c3f00c Introduce new IQ system
Mikael Berthe <mikael@lilotux.net>
parents: 619
diff changeset
   150
}
c5e0d8c3f00c Introduce new IQ system
Mikael Berthe <mikael@lilotux.net>
parents: 619
diff changeset
   151
745
413e95f3051a Introduce user "events" list
Mikael Berthe <mikael@lilotux.net>
parents: 705
diff changeset
   152
static eviqs *iqs_find(const char *iqid)
683
c5e0d8c3f00c Introduce new IQ system
Mikael Berthe <mikael@lilotux.net>
parents: 619
diff changeset
   153
{
c5e0d8c3f00c Introduce new IQ system
Mikael Berthe <mikael@lilotux.net>
parents: 619
diff changeset
   154
  GSList *p;
745
413e95f3051a Introduce user "events" list
Mikael Berthe <mikael@lilotux.net>
parents: 705
diff changeset
   155
  eviqs *i;
683
c5e0d8c3f00c Introduce new IQ system
Mikael Berthe <mikael@lilotux.net>
parents: 619
diff changeset
   156
c5e0d8c3f00c Introduce new IQ system
Mikael Berthe <mikael@lilotux.net>
parents: 619
diff changeset
   157
  if (!iqid) return NULL;
c5e0d8c3f00c Introduce new IQ system
Mikael Berthe <mikael@lilotux.net>
parents: 619
diff changeset
   158
c5e0d8c3f00c Introduce new IQ system
Mikael Berthe <mikael@lilotux.net>
parents: 619
diff changeset
   159
  for (p = iqs_list; p; p = g_slist_next(p)) {
c5e0d8c3f00c Introduce new IQ system
Mikael Berthe <mikael@lilotux.net>
parents: 619
diff changeset
   160
    i = p->data;
c5e0d8c3f00c Introduce new IQ system
Mikael Berthe <mikael@lilotux.net>
parents: 619
diff changeset
   161
    if (!strcmp(iqid, i->id))
c5e0d8c3f00c Introduce new IQ system
Mikael Berthe <mikael@lilotux.net>
parents: 619
diff changeset
   162
      return i;
c5e0d8c3f00c Introduce new IQ system
Mikael Berthe <mikael@lilotux.net>
parents: 619
diff changeset
   163
  }
c5e0d8c3f00c Introduce new IQ system
Mikael Berthe <mikael@lilotux.net>
parents: 619
diff changeset
   164
  return NULL;
c5e0d8c3f00c Introduce new IQ system
Mikael Berthe <mikael@lilotux.net>
parents: 619
diff changeset
   165
}
c5e0d8c3f00c Introduce new IQ system
Mikael Berthe <mikael@lilotux.net>
parents: 619
diff changeset
   166
698
60522cf6d325 Propagate context to IQ callback functions
Mikael Berthe <mikael@lilotux.net>
parents: 692
diff changeset
   167
//  iqs_callback(iqid, xml_result, iqcontext)
683
c5e0d8c3f00c Introduce new IQ system
Mikael Berthe <mikael@lilotux.net>
parents: 619
diff changeset
   168
// Callback processing for the iqid message.
c5e0d8c3f00c Introduce new IQ system
Mikael Berthe <mikael@lilotux.net>
parents: 619
diff changeset
   169
// If we've received an answer, xml_result should point to the xmldata packet.
c5e0d8c3f00c Introduce new IQ system
Mikael Berthe <mikael@lilotux.net>
parents: 619
diff changeset
   170
// If this is a timeout, xml_result should be NULL.
c5e0d8c3f00c Introduce new IQ system
Mikael Berthe <mikael@lilotux.net>
parents: 619
diff changeset
   171
// Return 0 in case of success, -1 if the iqid hasn't been found.
698
60522cf6d325 Propagate context to IQ callback functions
Mikael Berthe <mikael@lilotux.net>
parents: 692
diff changeset
   172
int iqs_callback(const char *iqid, xmlnode xml_result, guint iqcontext)
683
c5e0d8c3f00c Introduce new IQ system
Mikael Berthe <mikael@lilotux.net>
parents: 619
diff changeset
   173
{
745
413e95f3051a Introduce user "events" list
Mikael Berthe <mikael@lilotux.net>
parents: 705
diff changeset
   174
  eviqs *i;
1213
4a7db2870685 Improve Private Storage detection.
Mikael Berthe <mikael@lilotux.net>
parents: 1205
diff changeset
   175
  int retval = 0;
683
c5e0d8c3f00c Introduce new IQ system
Mikael Berthe <mikael@lilotux.net>
parents: 619
diff changeset
   176
c5e0d8c3f00c Introduce new IQ system
Mikael Berthe <mikael@lilotux.net>
parents: 619
diff changeset
   177
  i = iqs_find(iqid);
c5e0d8c3f00c Introduce new IQ system
Mikael Berthe <mikael@lilotux.net>
parents: 619
diff changeset
   178
  if (!i) return -1;
c5e0d8c3f00c Introduce new IQ system
Mikael Berthe <mikael@lilotux.net>
parents: 619
diff changeset
   179
c5e0d8c3f00c Introduce new IQ system
Mikael Berthe <mikael@lilotux.net>
parents: 619
diff changeset
   180
  // IQ processing
c5e0d8c3f00c Introduce new IQ system
Mikael Berthe <mikael@lilotux.net>
parents: 619
diff changeset
   181
  // Note: If xml_result is NULL, this is a timeout
c5e0d8c3f00c Introduce new IQ system
Mikael Berthe <mikael@lilotux.net>
parents: 619
diff changeset
   182
  if (i->callback)
1213
4a7db2870685 Improve Private Storage detection.
Mikael Berthe <mikael@lilotux.net>
parents: 1205
diff changeset
   183
    retval = (*i->callback)(i, xml_result, iqcontext);
683
c5e0d8c3f00c Introduce new IQ system
Mikael Berthe <mikael@lilotux.net>
parents: 619
diff changeset
   184
c5e0d8c3f00c Introduce new IQ system
Mikael Berthe <mikael@lilotux.net>
parents: 619
diff changeset
   185
  iqs_del(iqid);
1213
4a7db2870685 Improve Private Storage detection.
Mikael Berthe <mikael@lilotux.net>
parents: 1205
diff changeset
   186
  return retval;
683
c5e0d8c3f00c Introduce new IQ system
Mikael Berthe <mikael@lilotux.net>
parents: 619
diff changeset
   187
}
c5e0d8c3f00c Introduce new IQ system
Mikael Berthe <mikael@lilotux.net>
parents: 619
diff changeset
   188
705
603b43e4f56a Fix a bug in iqs_check_timeout()
Mikael Berthe <mikael@lilotux.net>
parents: 704
diff changeset
   189
void iqs_check_timeout(time_t now_t)
683
c5e0d8c3f00c Introduce new IQ system
Mikael Berthe <mikael@lilotux.net>
parents: 619
diff changeset
   190
{
c5e0d8c3f00c Introduce new IQ system
Mikael Berthe <mikael@lilotux.net>
parents: 619
diff changeset
   191
  GSList *p;
745
413e95f3051a Introduce user "events" list
Mikael Berthe <mikael@lilotux.net>
parents: 705
diff changeset
   192
  eviqs *i;
683
c5e0d8c3f00c Introduce new IQ system
Mikael Berthe <mikael@lilotux.net>
parents: 619
diff changeset
   193
705
603b43e4f56a Fix a bug in iqs_check_timeout()
Mikael Berthe <mikael@lilotux.net>
parents: 704
diff changeset
   194
  p = iqs_list;
603b43e4f56a Fix a bug in iqs_check_timeout()
Mikael Berthe <mikael@lilotux.net>
parents: 704
diff changeset
   195
  while (p) {
603b43e4f56a Fix a bug in iqs_check_timeout()
Mikael Berthe <mikael@lilotux.net>
parents: 704
diff changeset
   196
    i = p->data;
745
413e95f3051a Introduce user "events" list
Mikael Berthe <mikael@lilotux.net>
parents: 705
diff changeset
   197
    // We must get next IQ eviqs element now because the current one
705
603b43e4f56a Fix a bug in iqs_check_timeout()
Mikael Berthe <mikael@lilotux.net>
parents: 704
diff changeset
   198
    // could be freed.
603b43e4f56a Fix a bug in iqs_check_timeout()
Mikael Berthe <mikael@lilotux.net>
parents: 704
diff changeset
   199
    p = g_slist_next(p);
683
c5e0d8c3f00c Introduce new IQ system
Mikael Berthe <mikael@lilotux.net>
parents: 619
diff changeset
   200
965
1bdf0f1b16c0 Use U suffix for unsigned defines
Mikael Berthe <mikael@lilotux.net>
parents: 959
diff changeset
   201
    if ((!i->ts_expire && now_t > i->ts_create + (time_t)IQS_MAX_TIMEOUT) ||
683
c5e0d8c3f00c Introduce new IQ system
Mikael Berthe <mikael@lilotux.net>
parents: 619
diff changeset
   202
        (i->ts_expire && now_t > i->ts_expire)) {
698
60522cf6d325 Propagate context to IQ callback functions
Mikael Berthe <mikael@lilotux.net>
parents: 692
diff changeset
   203
      iqs_callback(i->id, NULL, IQS_CONTEXT_TIMEOUT);
683
c5e0d8c3f00c Introduce new IQ system
Mikael Berthe <mikael@lilotux.net>
parents: 619
diff changeset
   204
    }
c5e0d8c3f00c Introduce new IQ system
Mikael Berthe <mikael@lilotux.net>
parents: 619
diff changeset
   205
  }
c5e0d8c3f00c Introduce new IQ system
Mikael Berthe <mikael@lilotux.net>
parents: 619
diff changeset
   206
}
c5e0d8c3f00c Introduce new IQ system
Mikael Berthe <mikael@lilotux.net>
parents: 619
diff changeset
   207
689
281aab5aef50 Introduce jb_iqs_display_list() helper function for debugging
Mikael Berthe <mikael@lilotux.net>
parents: 688
diff changeset
   208
void jb_iqs_display_list(void)
281aab5aef50 Introduce jb_iqs_display_list() helper function for debugging
Mikael Berthe <mikael@lilotux.net>
parents: 688
diff changeset
   209
{
281aab5aef50 Introduce jb_iqs_display_list() helper function for debugging
Mikael Berthe <mikael@lilotux.net>
parents: 688
diff changeset
   210
  GSList *p;
745
413e95f3051a Introduce user "events" list
Mikael Berthe <mikael@lilotux.net>
parents: 705
diff changeset
   211
  eviqs *i;
689
281aab5aef50 Introduce jb_iqs_display_list() helper function for debugging
Mikael Berthe <mikael@lilotux.net>
parents: 688
diff changeset
   212
281aab5aef50 Introduce jb_iqs_display_list() helper function for debugging
Mikael Berthe <mikael@lilotux.net>
parents: 688
diff changeset
   213
  scr_LogPrint(LPRINT_LOGNORM, "IQ list:");
281aab5aef50 Introduce jb_iqs_display_list() helper function for debugging
Mikael Berthe <mikael@lilotux.net>
parents: 688
diff changeset
   214
  for (p = iqs_list; p; p = g_slist_next(p)) {
281aab5aef50 Introduce jb_iqs_display_list() helper function for debugging
Mikael Berthe <mikael@lilotux.net>
parents: 688
diff changeset
   215
    i = p->data;
281aab5aef50 Introduce jb_iqs_display_list() helper function for debugging
Mikael Berthe <mikael@lilotux.net>
parents: 688
diff changeset
   216
    scr_LogPrint(LPRINT_LOGNORM, "Id [%s]", i->id);
281aab5aef50 Introduce jb_iqs_display_list() helper function for debugging
Mikael Berthe <mikael@lilotux.net>
parents: 688
diff changeset
   217
  }
281aab5aef50 Introduce jb_iqs_display_list() helper function for debugging
Mikael Berthe <mikael@lilotux.net>
parents: 688
diff changeset
   218
  scr_LogPrint(LPRINT_LOGNORM, "End of IQ list.");
281aab5aef50 Introduce jb_iqs_display_list() helper function for debugging
Mikael Berthe <mikael@lilotux.net>
parents: 688
diff changeset
   219
}
281aab5aef50 Introduce jb_iqs_display_list() helper function for debugging
Mikael Berthe <mikael@lilotux.net>
parents: 688
diff changeset
   220
606
0b4ed231ebc2 Code cleanup + remove deprecated Agents list IQ request
Mikael Berthe <mikael@lilotux.net>
parents: 605
diff changeset
   221
static void request_roster(void)
29
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
   222
{
745
413e95f3051a Introduce user "events" list
Mikael Berthe <mikael@lilotux.net>
parents: 705
diff changeset
   223
  eviqs *iqn = iqs_new(JPACKET__GET, NS_ROSTER, "Roster", IQS_DEFAULT_TIMEOUT);
684
3282276e7413 Switch IQ packet creation to the new IQ system
Mikael Berthe <mikael@lilotux.net>
parents: 683
diff changeset
   224
  jab_send(jc, iqn->xmldata);
3282276e7413 Switch IQ packet creation to the new IQ system
Mikael Berthe <mikael@lilotux.net>
parents: 683
diff changeset
   225
  iqs_del(iqn->id); // XXX
29
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
   226
}
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
   227
606
0b4ed231ebc2 Code cleanup + remove deprecated Agents list IQ request
Mikael Berthe <mikael@lilotux.net>
parents: 605
diff changeset
   228
static void handle_iq_roster(xmlnode x)
29
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
   229
{
577
5c6d364130ee Move IQ Jabber stuff to a separate file
Mikael Berthe <mikael@lilotux.net>
parents: 576
diff changeset
   230
  xmlnode y;
1058
c0d44a9a99bc Code cleanup
Mikael Berthe <mikael@lilotux.net>
parents: 1037
diff changeset
   231
  const char *fjid, *name, *group, *sub, *ask;
577
5c6d364130ee Move IQ Jabber stuff to a separate file
Mikael Berthe <mikael@lilotux.net>
parents: 576
diff changeset
   232
  char *cleanalias;
603
9516db839e08 Store subscription data
Mikael Berthe <mikael@lilotux.net>
parents: 597
diff changeset
   233
  enum subscr esub;
9516db839e08 Store subscription data
Mikael Berthe <mikael@lilotux.net>
parents: 597
diff changeset
   234
  int need_refresh = FALSE;
613
a6b8b373e4de Try to guess if a roster item is an agent
Mikael Berthe <mikael@lilotux.net>
parents: 607
diff changeset
   235
  guint roster_type;
29
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
   236
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
   237
  for (y = xmlnode_get_tag(x, "item"); y; y = xmlnode_get_nextsibling(y)) {
577
5c6d364130ee Move IQ Jabber stuff to a separate file
Mikael Berthe <mikael@lilotux.net>
parents: 576
diff changeset
   238
1058
c0d44a9a99bc Code cleanup
Mikael Berthe <mikael@lilotux.net>
parents: 1037
diff changeset
   239
    fjid = xmlnode_get_attrib(y, "jid");
577
5c6d364130ee Move IQ Jabber stuff to a separate file
Mikael Berthe <mikael@lilotux.net>
parents: 576
diff changeset
   240
    name = xmlnode_get_attrib(y, "name");
603
9516db839e08 Store subscription data
Mikael Berthe <mikael@lilotux.net>
parents: 597
diff changeset
   241
    sub = xmlnode_get_attrib(y, "subscription");
605
2a4fefb98511 Set the subscription pending flag
Mikael Berthe <mikael@lilotux.net>
parents: 603
diff changeset
   242
    ask = xmlnode_get_attrib(y, "ask");
577
5c6d364130ee Move IQ Jabber stuff to a separate file
Mikael Berthe <mikael@lilotux.net>
parents: 576
diff changeset
   243
5c6d364130ee Move IQ Jabber stuff to a separate file
Mikael Berthe <mikael@lilotux.net>
parents: 576
diff changeset
   244
    group = xmlnode_get_tag_data(y, "group");
5c6d364130ee Move IQ Jabber stuff to a separate file
Mikael Berthe <mikael@lilotux.net>
parents: 576
diff changeset
   245
1058
c0d44a9a99bc Code cleanup
Mikael Berthe <mikael@lilotux.net>
parents: 1037
diff changeset
   246
    if (!fjid)
577
5c6d364130ee Move IQ Jabber stuff to a separate file
Mikael Berthe <mikael@lilotux.net>
parents: 576
diff changeset
   247
      continue;
5c6d364130ee Move IQ Jabber stuff to a separate file
Mikael Berthe <mikael@lilotux.net>
parents: 576
diff changeset
   248
1058
c0d44a9a99bc Code cleanup
Mikael Berthe <mikael@lilotux.net>
parents: 1037
diff changeset
   249
    cleanalias = jidtodisp(fjid);
29
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
   250
603
9516db839e08 Store subscription data
Mikael Berthe <mikael@lilotux.net>
parents: 597
diff changeset
   251
    esub = sub_none;
9516db839e08 Store subscription data
Mikael Berthe <mikael@lilotux.net>
parents: 597
diff changeset
   252
    if (sub) {
9516db839e08 Store subscription data
Mikael Berthe <mikael@lilotux.net>
parents: 597
diff changeset
   253
      if (!strcmp(sub, "to"))          esub = sub_to;
9516db839e08 Store subscription data
Mikael Berthe <mikael@lilotux.net>
parents: 597
diff changeset
   254
      else if (!strcmp(sub, "from"))   esub = sub_from;
9516db839e08 Store subscription data
Mikael Berthe <mikael@lilotux.net>
parents: 597
diff changeset
   255
      else if (!strcmp(sub, "both"))   esub = sub_both;
9516db839e08 Store subscription data
Mikael Berthe <mikael@lilotux.net>
parents: 597
diff changeset
   256
      else if (!strcmp(sub, "remove")) esub = sub_remove;
9516db839e08 Store subscription data
Mikael Berthe <mikael@lilotux.net>
parents: 597
diff changeset
   257
    }
9516db839e08 Store subscription data
Mikael Berthe <mikael@lilotux.net>
parents: 597
diff changeset
   258
9516db839e08 Store subscription data
Mikael Berthe <mikael@lilotux.net>
parents: 597
diff changeset
   259
    if (esub == sub_remove) {
9516db839e08 Store subscription data
Mikael Berthe <mikael@lilotux.net>
parents: 597
diff changeset
   260
      roster_del_user(cleanalias);
9516db839e08 Store subscription data
Mikael Berthe <mikael@lilotux.net>
parents: 597
diff changeset
   261
      scr_LogPrint(LPRINT_LOGNORM, "Buddy <%s> has been removed "
9516db839e08 Store subscription data
Mikael Berthe <mikael@lilotux.net>
parents: 597
diff changeset
   262
                   "from the roster", cleanalias);
9516db839e08 Store subscription data
Mikael Berthe <mikael@lilotux.net>
parents: 597
diff changeset
   263
      g_free(cleanalias);
9516db839e08 Store subscription data
Mikael Berthe <mikael@lilotux.net>
parents: 597
diff changeset
   264
      need_refresh = TRUE;
9516db839e08 Store subscription data
Mikael Berthe <mikael@lilotux.net>
parents: 597
diff changeset
   265
      continue;
9516db839e08 Store subscription data
Mikael Berthe <mikael@lilotux.net>
parents: 597
diff changeset
   266
    }
9516db839e08 Store subscription data
Mikael Berthe <mikael@lilotux.net>
parents: 597
diff changeset
   267
605
2a4fefb98511 Set the subscription pending flag
Mikael Berthe <mikael@lilotux.net>
parents: 603
diff changeset
   268
    if (ask && !strcmp(ask, "subscribe"))
2a4fefb98511 Set the subscription pending flag
Mikael Berthe <mikael@lilotux.net>
parents: 603
diff changeset
   269
      esub |= sub_pending;
2a4fefb98511 Set the subscription pending flag
Mikael Berthe <mikael@lilotux.net>
parents: 603
diff changeset
   270
772
464be13343a9 Store most data in UTF-8 internally
Mikael Berthe <mikael@lilotux.net>
parents: 746
diff changeset
   271
    if (!name)
464be13343a9 Store most data in UTF-8 internally
Mikael Berthe <mikael@lilotux.net>
parents: 746
diff changeset
   272
      name = cleanalias;
577
5c6d364130ee Move IQ Jabber stuff to a separate file
Mikael Berthe <mikael@lilotux.net>
parents: 576
diff changeset
   273
977
5b01de4ac5e1 Cosmetic changes
Alexis Hildebrandt <afh [at] 2drop [dot] net>
parents: 965
diff changeset
   274
    // Tricky... :-\  My guess is that if there is no JID_DOMAIN_SEPARATOR,
5b01de4ac5e1 Cosmetic changes
Alexis Hildebrandt <afh [at] 2drop [dot] net>
parents: 965
diff changeset
   275
    // this is an agent.
5b01de4ac5e1 Cosmetic changes
Alexis Hildebrandt <afh [at] 2drop [dot] net>
parents: 965
diff changeset
   276
    if (strchr(cleanalias, JID_DOMAIN_SEPARATOR))
613
a6b8b373e4de Try to guess if a roster item is an agent
Mikael Berthe <mikael@lilotux.net>
parents: 607
diff changeset
   277
      roster_type = ROSTER_TYPE_USER;
a6b8b373e4de Try to guess if a roster item is an agent
Mikael Berthe <mikael@lilotux.net>
parents: 607
diff changeset
   278
    else
a6b8b373e4de Try to guess if a roster item is an agent
Mikael Berthe <mikael@lilotux.net>
parents: 607
diff changeset
   279
      roster_type = ROSTER_TYPE_AGENT;
a6b8b373e4de Try to guess if a roster item is an agent
Mikael Berthe <mikael@lilotux.net>
parents: 607
diff changeset
   280
772
464be13343a9 Store most data in UTF-8 internally
Mikael Berthe <mikael@lilotux.net>
parents: 746
diff changeset
   281
    roster_add_user(cleanalias, name, group, roster_type, esub);
603
9516db839e08 Store subscription data
Mikael Berthe <mikael@lilotux.net>
parents: 597
diff changeset
   282
577
5c6d364130ee Move IQ Jabber stuff to a separate file
Mikael Berthe <mikael@lilotux.net>
parents: 576
diff changeset
   283
    g_free(cleanalias);
5c6d364130ee Move IQ Jabber stuff to a separate file
Mikael Berthe <mikael@lilotux.net>
parents: 576
diff changeset
   284
  }
5c6d364130ee Move IQ Jabber stuff to a separate file
Mikael Berthe <mikael@lilotux.net>
parents: 576
diff changeset
   285
5c6d364130ee Move IQ Jabber stuff to a separate file
Mikael Berthe <mikael@lilotux.net>
parents: 576
diff changeset
   286
  buddylist_build();
603
9516db839e08 Store subscription data
Mikael Berthe <mikael@lilotux.net>
parents: 597
diff changeset
   287
  update_roster = TRUE;
9516db839e08 Store subscription data
Mikael Berthe <mikael@lilotux.net>
parents: 597
diff changeset
   288
  if (need_refresh)
959
8bf36cef8aa6 Do not enter chat mode after command "/del"
Mikael Berthe <mikael@lilotux.net>
parents: 871
diff changeset
   289
    scr_UpdateBuddyWindow();
577
5c6d364130ee Move IQ Jabber stuff to a separate file
Mikael Berthe <mikael@lilotux.net>
parents: 576
diff changeset
   290
}
29
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
   291
1213
4a7db2870685 Improve Private Storage detection.
Mikael Berthe <mikael@lilotux.net>
parents: 1205
diff changeset
   292
static int iqscallback_version(eviqs *iqp, xmlnode xml_result, guint iqcontext)
690
3e965a1186c7 Implement IQ:version requests
Mikael Berthe <mikael@lilotux.net>
parents: 689
diff changeset
   293
{
3e965a1186c7 Implement IQ:version requests
Mikael Berthe <mikael@lilotux.net>
parents: 689
diff changeset
   294
  xmlnode ansqry;
1030
923cf5a92b44 [BP-dd9e7eb5f8a8] Remove old UTF-8 conversions
Mikael Berthe <mikael@lilotux.net>
parents: 965
diff changeset
   295
  char *p;
704
4118a66f2c02 Display IQ results (time, version) in the chat window
Mikael Berthe <mikael@lilotux.net>
parents: 703
diff changeset
   296
  char *bjid;
4118a66f2c02 Display IQ results (time, version) in the chat window
Mikael Berthe <mikael@lilotux.net>
parents: 703
diff changeset
   297
  char *buf;
690
3e965a1186c7 Implement IQ:version requests
Mikael Berthe <mikael@lilotux.net>
parents: 689
diff changeset
   298
698
60522cf6d325 Propagate context to IQ callback functions
Mikael Berthe <mikael@lilotux.net>
parents: 692
diff changeset
   299
  // Leave now if we cannot process xml_result
1213
4a7db2870685 Improve Private Storage detection.
Mikael Berthe <mikael@lilotux.net>
parents: 1205
diff changeset
   300
  if (!xml_result || iqcontext) return -1;
690
3e965a1186c7 Implement IQ:version requests
Mikael Berthe <mikael@lilotux.net>
parents: 689
diff changeset
   301
3e965a1186c7 Implement IQ:version requests
Mikael Berthe <mikael@lilotux.net>
parents: 689
diff changeset
   302
  ansqry = xmlnode_get_tag(xml_result, "query");
3e965a1186c7 Implement IQ:version requests
Mikael Berthe <mikael@lilotux.net>
parents: 689
diff changeset
   303
  if (!ansqry) {
3e965a1186c7 Implement IQ:version requests
Mikael Berthe <mikael@lilotux.net>
parents: 689
diff changeset
   304
    scr_LogPrint(LPRINT_LOGNORM, "Invalid IQ:version result!");
1213
4a7db2870685 Improve Private Storage detection.
Mikael Berthe <mikael@lilotux.net>
parents: 1205
diff changeset
   305
    return 0;
690
3e965a1186c7 Implement IQ:version requests
Mikael Berthe <mikael@lilotux.net>
parents: 689
diff changeset
   306
  }
3e965a1186c7 Implement IQ:version requests
Mikael Berthe <mikael@lilotux.net>
parents: 689
diff changeset
   307
  // Display IQ result sender...
3e965a1186c7 Implement IQ:version requests
Mikael Berthe <mikael@lilotux.net>
parents: 689
diff changeset
   308
  p = xmlnode_get_attrib(xml_result, "from");
3e965a1186c7 Implement IQ:version requests
Mikael Berthe <mikael@lilotux.net>
parents: 689
diff changeset
   309
  if (!p) {
3e965a1186c7 Implement IQ:version requests
Mikael Berthe <mikael@lilotux.net>
parents: 689
diff changeset
   310
    scr_LogPrint(LPRINT_LOGNORM, "Invalid IQ:version result (no sender name).");
1213
4a7db2870685 Improve Private Storage detection.
Mikael Berthe <mikael@lilotux.net>
parents: 1205
diff changeset
   311
    return 0;
690
3e965a1186c7 Implement IQ:version requests
Mikael Berthe <mikael@lilotux.net>
parents: 689
diff changeset
   312
  }
772
464be13343a9 Store most data in UTF-8 internally
Mikael Berthe <mikael@lilotux.net>
parents: 746
diff changeset
   313
  bjid = p;
704
4118a66f2c02 Display IQ results (time, version) in the chat window
Mikael Berthe <mikael@lilotux.net>
parents: 703
diff changeset
   314
782
19121d9f4aa2 Nicer message when receiving IQ result packet
Mikael Berthe <mikael@lilotux.net>
parents: 776
diff changeset
   315
  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
   316
  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
   317
4118a66f2c02 Display IQ results (time, version) in the chat window
Mikael Berthe <mikael@lilotux.net>
parents: 703
diff changeset
   318
  // bjid should now really be the "bare JID", let's strip the resource
977
5b01de4ac5e1 Cosmetic changes
Alexis Hildebrandt <afh [at] 2drop [dot] net>
parents: 965
diff changeset
   319
  p = strchr(bjid, JID_RESOURCE_SEPARATOR);
704
4118a66f2c02 Display IQ results (time, version) in the chat window
Mikael Berthe <mikael@lilotux.net>
parents: 703
diff changeset
   320
  if (p) *p = '\0';
4118a66f2c02 Display IQ results (time, version) in the chat window
Mikael Berthe <mikael@lilotux.net>
parents: 703
diff changeset
   321
4118a66f2c02 Display IQ results (time, version) in the chat window
Mikael Berthe <mikael@lilotux.net>
parents: 703
diff changeset
   322
  scr_WriteIncomingMessage(bjid, buf, 0, HBB_PREFIX_INFO);
4118a66f2c02 Display IQ results (time, version) in the chat window
Mikael Berthe <mikael@lilotux.net>
parents: 703
diff changeset
   323
  g_free(buf);
4118a66f2c02 Display IQ results (time, version) in the chat window
Mikael Berthe <mikael@lilotux.net>
parents: 703
diff changeset
   324
690
3e965a1186c7 Implement IQ:version requests
Mikael Berthe <mikael@lilotux.net>
parents: 689
diff changeset
   325
  // Get result data...
3e965a1186c7 Implement IQ:version requests
Mikael Berthe <mikael@lilotux.net>
parents: 689
diff changeset
   326
  p = xmlnode_get_tag_data(ansqry, "name");
3e965a1186c7 Implement IQ:version requests
Mikael Berthe <mikael@lilotux.net>
parents: 689
diff changeset
   327
  if (p) {
1030
923cf5a92b44 [BP-dd9e7eb5f8a8] Remove old UTF-8 conversions
Mikael Berthe <mikael@lilotux.net>
parents: 965
diff changeset
   328
    buf = g_strdup_printf("Name:    %s", p);
923cf5a92b44 [BP-dd9e7eb5f8a8] Remove old UTF-8 conversions
Mikael Berthe <mikael@lilotux.net>
parents: 965
diff changeset
   329
    scr_WriteIncomingMessage(bjid, buf, 0, HBB_PREFIX_NONE);
923cf5a92b44 [BP-dd9e7eb5f8a8] Remove old UTF-8 conversions
Mikael Berthe <mikael@lilotux.net>
parents: 965
diff changeset
   330
    g_free(buf);
690
3e965a1186c7 Implement IQ:version requests
Mikael Berthe <mikael@lilotux.net>
parents: 689
diff changeset
   331
  }
3e965a1186c7 Implement IQ:version requests
Mikael Berthe <mikael@lilotux.net>
parents: 689
diff changeset
   332
  p = xmlnode_get_tag_data(ansqry, "version");
3e965a1186c7 Implement IQ:version requests
Mikael Berthe <mikael@lilotux.net>
parents: 689
diff changeset
   333
  if (p) {
1030
923cf5a92b44 [BP-dd9e7eb5f8a8] Remove old UTF-8 conversions
Mikael Berthe <mikael@lilotux.net>
parents: 965
diff changeset
   334
    buf = g_strdup_printf("Version: %s", p);
923cf5a92b44 [BP-dd9e7eb5f8a8] Remove old UTF-8 conversions
Mikael Berthe <mikael@lilotux.net>
parents: 965
diff changeset
   335
    scr_WriteIncomingMessage(bjid, buf, 0, HBB_PREFIX_NONE);
923cf5a92b44 [BP-dd9e7eb5f8a8] Remove old UTF-8 conversions
Mikael Berthe <mikael@lilotux.net>
parents: 965
diff changeset
   336
    g_free(buf);
690
3e965a1186c7 Implement IQ:version requests
Mikael Berthe <mikael@lilotux.net>
parents: 689
diff changeset
   337
  }
3e965a1186c7 Implement IQ:version requests
Mikael Berthe <mikael@lilotux.net>
parents: 689
diff changeset
   338
  p = xmlnode_get_tag_data(ansqry, "os");
3e965a1186c7 Implement IQ:version requests
Mikael Berthe <mikael@lilotux.net>
parents: 689
diff changeset
   339
  if (p) {
1030
923cf5a92b44 [BP-dd9e7eb5f8a8] Remove old UTF-8 conversions
Mikael Berthe <mikael@lilotux.net>
parents: 965
diff changeset
   340
    buf = g_strdup_printf("OS:      %s", p);
923cf5a92b44 [BP-dd9e7eb5f8a8] Remove old UTF-8 conversions
Mikael Berthe <mikael@lilotux.net>
parents: 965
diff changeset
   341
    scr_WriteIncomingMessage(bjid, buf, 0, HBB_PREFIX_NONE);
923cf5a92b44 [BP-dd9e7eb5f8a8] Remove old UTF-8 conversions
Mikael Berthe <mikael@lilotux.net>
parents: 965
diff changeset
   342
    g_free(buf);
690
3e965a1186c7 Implement IQ:version requests
Mikael Berthe <mikael@lilotux.net>
parents: 689
diff changeset
   343
  }
1213
4a7db2870685 Improve Private Storage detection.
Mikael Berthe <mikael@lilotux.net>
parents: 1205
diff changeset
   344
  return 0;
690
3e965a1186c7 Implement IQ:version requests
Mikael Berthe <mikael@lilotux.net>
parents: 689
diff changeset
   345
}
3e965a1186c7 Implement IQ:version requests
Mikael Berthe <mikael@lilotux.net>
parents: 689
diff changeset
   346
3e965a1186c7 Implement IQ:version requests
Mikael Berthe <mikael@lilotux.net>
parents: 689
diff changeset
   347
void request_version(const char *fulljid)
3e965a1186c7 Implement IQ:version requests
Mikael Berthe <mikael@lilotux.net>
parents: 689
diff changeset
   348
{
745
413e95f3051a Introduce user "events" list
Mikael Berthe <mikael@lilotux.net>
parents: 705
diff changeset
   349
  eviqs *iqn;
690
3e965a1186c7 Implement IQ:version requests
Mikael Berthe <mikael@lilotux.net>
parents: 689
diff changeset
   350
3e965a1186c7 Implement IQ:version requests
Mikael Berthe <mikael@lilotux.net>
parents: 689
diff changeset
   351
  iqn = iqs_new(JPACKET__GET, NS_VERSION, "version", IQS_DEFAULT_TIMEOUT);
772
464be13343a9 Store most data in UTF-8 internally
Mikael Berthe <mikael@lilotux.net>
parents: 746
diff changeset
   352
  xmlnode_put_attrib(iqn->xmldata, "to", fulljid);
690
3e965a1186c7 Implement IQ:version requests
Mikael Berthe <mikael@lilotux.net>
parents: 689
diff changeset
   353
  iqn->callback = &iqscallback_version;
3e965a1186c7 Implement IQ:version requests
Mikael Berthe <mikael@lilotux.net>
parents: 689
diff changeset
   354
  jab_send(jc, iqn->xmldata);
3e965a1186c7 Implement IQ:version requests
Mikael Berthe <mikael@lilotux.net>
parents: 689
diff changeset
   355
}
3e965a1186c7 Implement IQ:version requests
Mikael Berthe <mikael@lilotux.net>
parents: 689
diff changeset
   356
1213
4a7db2870685 Improve Private Storage detection.
Mikael Berthe <mikael@lilotux.net>
parents: 1205
diff changeset
   357
static int iqscallback_time(eviqs *iqp, xmlnode xml_result, guint iqcontext)
691
3c0a0a993de8 Implement IQ:time requests
Mikael Berthe <mikael@lilotux.net>
parents: 690
diff changeset
   358
{
3c0a0a993de8 Implement IQ:time requests
Mikael Berthe <mikael@lilotux.net>
parents: 690
diff changeset
   359
  xmlnode ansqry;
1030
923cf5a92b44 [BP-dd9e7eb5f8a8] Remove old UTF-8 conversions
Mikael Berthe <mikael@lilotux.net>
parents: 965
diff changeset
   360
  char *p;
704
4118a66f2c02 Display IQ results (time, version) in the chat window
Mikael Berthe <mikael@lilotux.net>
parents: 703
diff changeset
   361
  char *bjid;
4118a66f2c02 Display IQ results (time, version) in the chat window
Mikael Berthe <mikael@lilotux.net>
parents: 703
diff changeset
   362
  char *buf;
691
3c0a0a993de8 Implement IQ:time requests
Mikael Berthe <mikael@lilotux.net>
parents: 690
diff changeset
   363
698
60522cf6d325 Propagate context to IQ callback functions
Mikael Berthe <mikael@lilotux.net>
parents: 692
diff changeset
   364
  // Leave now if we cannot process xml_result
1213
4a7db2870685 Improve Private Storage detection.
Mikael Berthe <mikael@lilotux.net>
parents: 1205
diff changeset
   365
  if (!xml_result || iqcontext) return -1;
691
3c0a0a993de8 Implement IQ:time requests
Mikael Berthe <mikael@lilotux.net>
parents: 690
diff changeset
   366
3c0a0a993de8 Implement IQ:time requests
Mikael Berthe <mikael@lilotux.net>
parents: 690
diff changeset
   367
  ansqry = xmlnode_get_tag(xml_result, "query");
3c0a0a993de8 Implement IQ:time requests
Mikael Berthe <mikael@lilotux.net>
parents: 690
diff changeset
   368
  if (!ansqry) {
3c0a0a993de8 Implement IQ:time requests
Mikael Berthe <mikael@lilotux.net>
parents: 690
diff changeset
   369
    scr_LogPrint(LPRINT_LOGNORM, "Invalid IQ:time result!");
1213
4a7db2870685 Improve Private Storage detection.
Mikael Berthe <mikael@lilotux.net>
parents: 1205
diff changeset
   370
    return 0;
691
3c0a0a993de8 Implement IQ:time requests
Mikael Berthe <mikael@lilotux.net>
parents: 690
diff changeset
   371
  }
3c0a0a993de8 Implement IQ:time requests
Mikael Berthe <mikael@lilotux.net>
parents: 690
diff changeset
   372
  // Display IQ result sender...
3c0a0a993de8 Implement IQ:time requests
Mikael Berthe <mikael@lilotux.net>
parents: 690
diff changeset
   373
  p = xmlnode_get_attrib(xml_result, "from");
3c0a0a993de8 Implement IQ:time requests
Mikael Berthe <mikael@lilotux.net>
parents: 690
diff changeset
   374
  if (!p) {
3c0a0a993de8 Implement IQ:time requests
Mikael Berthe <mikael@lilotux.net>
parents: 690
diff changeset
   375
    scr_LogPrint(LPRINT_LOGNORM, "Invalid IQ:time result (no sender name).");
1213
4a7db2870685 Improve Private Storage detection.
Mikael Berthe <mikael@lilotux.net>
parents: 1205
diff changeset
   376
    return 0;
691
3c0a0a993de8 Implement IQ:time requests
Mikael Berthe <mikael@lilotux.net>
parents: 690
diff changeset
   377
  }
772
464be13343a9 Store most data in UTF-8 internally
Mikael Berthe <mikael@lilotux.net>
parents: 746
diff changeset
   378
  bjid = p;
704
4118a66f2c02 Display IQ results (time, version) in the chat window
Mikael Berthe <mikael@lilotux.net>
parents: 703
diff changeset
   379
782
19121d9f4aa2 Nicer message when receiving IQ result packet
Mikael Berthe <mikael@lilotux.net>
parents: 776
diff changeset
   380
  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
   381
  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
   382
4118a66f2c02 Display IQ results (time, version) in the chat window
Mikael Berthe <mikael@lilotux.net>
parents: 703
diff changeset
   383
  // bjid should now really be the "bare JID", let's strip the resource
977
5b01de4ac5e1 Cosmetic changes
Alexis Hildebrandt <afh [at] 2drop [dot] net>
parents: 965
diff changeset
   384
  p = strchr(bjid, JID_RESOURCE_SEPARATOR);
704
4118a66f2c02 Display IQ results (time, version) in the chat window
Mikael Berthe <mikael@lilotux.net>
parents: 703
diff changeset
   385
  if (p) *p = '\0';
4118a66f2c02 Display IQ results (time, version) in the chat window
Mikael Berthe <mikael@lilotux.net>
parents: 703
diff changeset
   386
4118a66f2c02 Display IQ results (time, version) in the chat window
Mikael Berthe <mikael@lilotux.net>
parents: 703
diff changeset
   387
  scr_WriteIncomingMessage(bjid, buf, 0, HBB_PREFIX_INFO);
4118a66f2c02 Display IQ results (time, version) in the chat window
Mikael Berthe <mikael@lilotux.net>
parents: 703
diff changeset
   388
  g_free(buf);
4118a66f2c02 Display IQ results (time, version) in the chat window
Mikael Berthe <mikael@lilotux.net>
parents: 703
diff changeset
   389
691
3c0a0a993de8 Implement IQ:time requests
Mikael Berthe <mikael@lilotux.net>
parents: 690
diff changeset
   390
  // Get result data...
3c0a0a993de8 Implement IQ:time requests
Mikael Berthe <mikael@lilotux.net>
parents: 690
diff changeset
   391
  p = xmlnode_get_tag_data(ansqry, "utc");
3c0a0a993de8 Implement IQ:time requests
Mikael Berthe <mikael@lilotux.net>
parents: 690
diff changeset
   392
  if (p) {
1030
923cf5a92b44 [BP-dd9e7eb5f8a8] Remove old UTF-8 conversions
Mikael Berthe <mikael@lilotux.net>
parents: 965
diff changeset
   393
    buf = g_strdup_printf("UTC:  %s", p);
923cf5a92b44 [BP-dd9e7eb5f8a8] Remove old UTF-8 conversions
Mikael Berthe <mikael@lilotux.net>
parents: 965
diff changeset
   394
    scr_WriteIncomingMessage(bjid, buf, 0, HBB_PREFIX_NONE);
923cf5a92b44 [BP-dd9e7eb5f8a8] Remove old UTF-8 conversions
Mikael Berthe <mikael@lilotux.net>
parents: 965
diff changeset
   395
    g_free(buf);
691
3c0a0a993de8 Implement IQ:time requests
Mikael Berthe <mikael@lilotux.net>
parents: 690
diff changeset
   396
  }
3c0a0a993de8 Implement IQ:time requests
Mikael Berthe <mikael@lilotux.net>
parents: 690
diff changeset
   397
  p = xmlnode_get_tag_data(ansqry, "tz");
3c0a0a993de8 Implement IQ:time requests
Mikael Berthe <mikael@lilotux.net>
parents: 690
diff changeset
   398
  if (p) {
1030
923cf5a92b44 [BP-dd9e7eb5f8a8] Remove old UTF-8 conversions
Mikael Berthe <mikael@lilotux.net>
parents: 965
diff changeset
   399
    buf = g_strdup_printf("TZ:   %s", p);
923cf5a92b44 [BP-dd9e7eb5f8a8] Remove old UTF-8 conversions
Mikael Berthe <mikael@lilotux.net>
parents: 965
diff changeset
   400
    scr_WriteIncomingMessage(bjid, buf, 0, HBB_PREFIX_NONE);
923cf5a92b44 [BP-dd9e7eb5f8a8] Remove old UTF-8 conversions
Mikael Berthe <mikael@lilotux.net>
parents: 965
diff changeset
   401
    g_free(buf);
691
3c0a0a993de8 Implement IQ:time requests
Mikael Berthe <mikael@lilotux.net>
parents: 690
diff changeset
   402
  }
3c0a0a993de8 Implement IQ:time requests
Mikael Berthe <mikael@lilotux.net>
parents: 690
diff changeset
   403
  p = xmlnode_get_tag_data(ansqry, "display");
3c0a0a993de8 Implement IQ:time requests
Mikael Berthe <mikael@lilotux.net>
parents: 690
diff changeset
   404
  if (p) {
1030
923cf5a92b44 [BP-dd9e7eb5f8a8] Remove old UTF-8 conversions
Mikael Berthe <mikael@lilotux.net>
parents: 965
diff changeset
   405
    buf = g_strdup_printf("Time: %s", p);
923cf5a92b44 [BP-dd9e7eb5f8a8] Remove old UTF-8 conversions
Mikael Berthe <mikael@lilotux.net>
parents: 965
diff changeset
   406
    scr_WriteIncomingMessage(bjid, buf, 0, HBB_PREFIX_NONE);
923cf5a92b44 [BP-dd9e7eb5f8a8] Remove old UTF-8 conversions
Mikael Berthe <mikael@lilotux.net>
parents: 965
diff changeset
   407
    g_free(buf);
691
3c0a0a993de8 Implement IQ:time requests
Mikael Berthe <mikael@lilotux.net>
parents: 690
diff changeset
   408
  }
1213
4a7db2870685 Improve Private Storage detection.
Mikael Berthe <mikael@lilotux.net>
parents: 1205
diff changeset
   409
  return 0;
691
3c0a0a993de8 Implement IQ:time requests
Mikael Berthe <mikael@lilotux.net>
parents: 690
diff changeset
   410
}
3c0a0a993de8 Implement IQ:time requests
Mikael Berthe <mikael@lilotux.net>
parents: 690
diff changeset
   411
3c0a0a993de8 Implement IQ:time requests
Mikael Berthe <mikael@lilotux.net>
parents: 690
diff changeset
   412
void request_time(const char *fulljid)
3c0a0a993de8 Implement IQ:time requests
Mikael Berthe <mikael@lilotux.net>
parents: 690
diff changeset
   413
{
745
413e95f3051a Introduce user "events" list
Mikael Berthe <mikael@lilotux.net>
parents: 705
diff changeset
   414
  eviqs *iqn;
691
3c0a0a993de8 Implement IQ:time requests
Mikael Berthe <mikael@lilotux.net>
parents: 690
diff changeset
   415
3c0a0a993de8 Implement IQ:time requests
Mikael Berthe <mikael@lilotux.net>
parents: 690
diff changeset
   416
  iqn = iqs_new(JPACKET__GET, NS_TIME, "time", IQS_DEFAULT_TIMEOUT);
772
464be13343a9 Store most data in UTF-8 internally
Mikael Berthe <mikael@lilotux.net>
parents: 746
diff changeset
   417
  xmlnode_put_attrib(iqn->xmldata, "to", fulljid);
691
3c0a0a993de8 Implement IQ:time requests
Mikael Berthe <mikael@lilotux.net>
parents: 690
diff changeset
   418
  iqn->callback = &iqscallback_time;
3c0a0a993de8 Implement IQ:time requests
Mikael Berthe <mikael@lilotux.net>
parents: 690
diff changeset
   419
  jab_send(jc, iqn->xmldata);
3c0a0a993de8 Implement IQ:time requests
Mikael Berthe <mikael@lilotux.net>
parents: 690
diff changeset
   420
}
3c0a0a993de8 Implement IQ:time requests
Mikael Berthe <mikael@lilotux.net>
parents: 690
diff changeset
   421
1213
4a7db2870685 Improve Private Storage detection.
Mikael Berthe <mikael@lilotux.net>
parents: 1205
diff changeset
   422
static int iqscallback_last(eviqs *iqp, xmlnode xml_result, guint iqcontext)
1015
579299b1c9b2 Add /request last
Mikael Berthe <mikael@lilotux.net>
parents: 1014
diff changeset
   423
{
579299b1c9b2 Add /request last
Mikael Berthe <mikael@lilotux.net>
parents: 1014
diff changeset
   424
  xmlnode ansqry;
579299b1c9b2 Add /request last
Mikael Berthe <mikael@lilotux.net>
parents: 1014
diff changeset
   425
  char *p;
579299b1c9b2 Add /request last
Mikael Berthe <mikael@lilotux.net>
parents: 1014
diff changeset
   426
  char *bjid;
579299b1c9b2 Add /request last
Mikael Berthe <mikael@lilotux.net>
parents: 1014
diff changeset
   427
  char *buf;
579299b1c9b2 Add /request last
Mikael Berthe <mikael@lilotux.net>
parents: 1014
diff changeset
   428
579299b1c9b2 Add /request last
Mikael Berthe <mikael@lilotux.net>
parents: 1014
diff changeset
   429
  // Leave now if we cannot process xml_result
1213
4a7db2870685 Improve Private Storage detection.
Mikael Berthe <mikael@lilotux.net>
parents: 1205
diff changeset
   430
  if (!xml_result || iqcontext) return -1;
1015
579299b1c9b2 Add /request last
Mikael Berthe <mikael@lilotux.net>
parents: 1014
diff changeset
   431
579299b1c9b2 Add /request last
Mikael Berthe <mikael@lilotux.net>
parents: 1014
diff changeset
   432
  ansqry = xmlnode_get_tag(xml_result, "query");
579299b1c9b2 Add /request last
Mikael Berthe <mikael@lilotux.net>
parents: 1014
diff changeset
   433
  if (!ansqry) {
579299b1c9b2 Add /request last
Mikael Berthe <mikael@lilotux.net>
parents: 1014
diff changeset
   434
    scr_LogPrint(LPRINT_LOGNORM, "Invalid IQ:last result!");
1213
4a7db2870685 Improve Private Storage detection.
Mikael Berthe <mikael@lilotux.net>
parents: 1205
diff changeset
   435
    return 0;
1015
579299b1c9b2 Add /request last
Mikael Berthe <mikael@lilotux.net>
parents: 1014
diff changeset
   436
  }
579299b1c9b2 Add /request last
Mikael Berthe <mikael@lilotux.net>
parents: 1014
diff changeset
   437
  // Display IQ result sender...
579299b1c9b2 Add /request last
Mikael Berthe <mikael@lilotux.net>
parents: 1014
diff changeset
   438
  p = xmlnode_get_attrib(xml_result, "from");
579299b1c9b2 Add /request last
Mikael Berthe <mikael@lilotux.net>
parents: 1014
diff changeset
   439
  if (!p) {
579299b1c9b2 Add /request last
Mikael Berthe <mikael@lilotux.net>
parents: 1014
diff changeset
   440
    scr_LogPrint(LPRINT_LOGNORM, "Invalid IQ:last result (no sender name).");
1213
4a7db2870685 Improve Private Storage detection.
Mikael Berthe <mikael@lilotux.net>
parents: 1205
diff changeset
   441
    return 0;
1015
579299b1c9b2 Add /request last
Mikael Berthe <mikael@lilotux.net>
parents: 1014
diff changeset
   442
  }
579299b1c9b2 Add /request last
Mikael Berthe <mikael@lilotux.net>
parents: 1014
diff changeset
   443
  bjid = p;
579299b1c9b2 Add /request last
Mikael Berthe <mikael@lilotux.net>
parents: 1014
diff changeset
   444
579299b1c9b2 Add /request last
Mikael Berthe <mikael@lilotux.net>
parents: 1014
diff changeset
   445
  buf = g_strdup_printf("Received IQ:last result from <%s>", bjid);
579299b1c9b2 Add /request last
Mikael Berthe <mikael@lilotux.net>
parents: 1014
diff changeset
   446
  scr_LogPrint(LPRINT_LOGNORM, "%s", buf);
579299b1c9b2 Add /request last
Mikael Berthe <mikael@lilotux.net>
parents: 1014
diff changeset
   447
579299b1c9b2 Add /request last
Mikael Berthe <mikael@lilotux.net>
parents: 1014
diff changeset
   448
  // bjid should now really be the "bare JID", let's strip the resource
579299b1c9b2 Add /request last
Mikael Berthe <mikael@lilotux.net>
parents: 1014
diff changeset
   449
  p = strchr(bjid, JID_RESOURCE_SEPARATOR);
579299b1c9b2 Add /request last
Mikael Berthe <mikael@lilotux.net>
parents: 1014
diff changeset
   450
  if (p) *p = '\0';
579299b1c9b2 Add /request last
Mikael Berthe <mikael@lilotux.net>
parents: 1014
diff changeset
   451
579299b1c9b2 Add /request last
Mikael Berthe <mikael@lilotux.net>
parents: 1014
diff changeset
   452
  scr_WriteIncomingMessage(bjid, buf, 0, HBB_PREFIX_INFO);
579299b1c9b2 Add /request last
Mikael Berthe <mikael@lilotux.net>
parents: 1014
diff changeset
   453
  g_free(buf);
579299b1c9b2 Add /request last
Mikael Berthe <mikael@lilotux.net>
parents: 1014
diff changeset
   454
579299b1c9b2 Add /request last
Mikael Berthe <mikael@lilotux.net>
parents: 1014
diff changeset
   455
  // Get result data...
579299b1c9b2 Add /request last
Mikael Berthe <mikael@lilotux.net>
parents: 1014
diff changeset
   456
  p = xmlnode_get_attrib(ansqry, "seconds");
579299b1c9b2 Add /request last
Mikael Berthe <mikael@lilotux.net>
parents: 1014
diff changeset
   457
  if (p) {
579299b1c9b2 Add /request last
Mikael Berthe <mikael@lilotux.net>
parents: 1014
diff changeset
   458
    long int s;
579299b1c9b2 Add /request last
Mikael Berthe <mikael@lilotux.net>
parents: 1014
diff changeset
   459
    GString *sbuf;
579299b1c9b2 Add /request last
Mikael Berthe <mikael@lilotux.net>
parents: 1014
diff changeset
   460
    sbuf = g_string_new("Idle time: ");
579299b1c9b2 Add /request last
Mikael Berthe <mikael@lilotux.net>
parents: 1014
diff changeset
   461
    s = atol(p);
579299b1c9b2 Add /request last
Mikael Berthe <mikael@lilotux.net>
parents: 1014
diff changeset
   462
    // Days
579299b1c9b2 Add /request last
Mikael Berthe <mikael@lilotux.net>
parents: 1014
diff changeset
   463
    if (s > 86400L) {
579299b1c9b2 Add /request last
Mikael Berthe <mikael@lilotux.net>
parents: 1014
diff changeset
   464
      g_string_append_printf(sbuf, "%ldd ", s/86400L);
579299b1c9b2 Add /request last
Mikael Berthe <mikael@lilotux.net>
parents: 1014
diff changeset
   465
      s %= 86400L;
579299b1c9b2 Add /request last
Mikael Berthe <mikael@lilotux.net>
parents: 1014
diff changeset
   466
    }
579299b1c9b2 Add /request last
Mikael Berthe <mikael@lilotux.net>
parents: 1014
diff changeset
   467
    // hh:mm:ss
579299b1c9b2 Add /request last
Mikael Berthe <mikael@lilotux.net>
parents: 1014
diff changeset
   468
    g_string_append_printf(sbuf, "%02ld:", s/3600L);
579299b1c9b2 Add /request last
Mikael Berthe <mikael@lilotux.net>
parents: 1014
diff changeset
   469
    s %= 3600L;
579299b1c9b2 Add /request last
Mikael Berthe <mikael@lilotux.net>
parents: 1014
diff changeset
   470
    g_string_append_printf(sbuf, "%02ld:%02ld", s/60L, s%60L);
579299b1c9b2 Add /request last
Mikael Berthe <mikael@lilotux.net>
parents: 1014
diff changeset
   471
    scr_WriteIncomingMessage(bjid, sbuf->str, 0, HBB_PREFIX_NONE);
579299b1c9b2 Add /request last
Mikael Berthe <mikael@lilotux.net>
parents: 1014
diff changeset
   472
    g_string_free(sbuf, TRUE);
579299b1c9b2 Add /request last
Mikael Berthe <mikael@lilotux.net>
parents: 1014
diff changeset
   473
  } else {
579299b1c9b2 Add /request last
Mikael Berthe <mikael@lilotux.net>
parents: 1014
diff changeset
   474
    scr_WriteIncomingMessage(bjid, "No idle time reported.",
579299b1c9b2 Add /request last
Mikael Berthe <mikael@lilotux.net>
parents: 1014
diff changeset
   475
                             0, HBB_PREFIX_NONE);
579299b1c9b2 Add /request last
Mikael Berthe <mikael@lilotux.net>
parents: 1014
diff changeset
   476
  }
579299b1c9b2 Add /request last
Mikael Berthe <mikael@lilotux.net>
parents: 1014
diff changeset
   477
  p = xmlnode_get_data(ansqry);
579299b1c9b2 Add /request last
Mikael Berthe <mikael@lilotux.net>
parents: 1014
diff changeset
   478
  if (p) {
579299b1c9b2 Add /request last
Mikael Berthe <mikael@lilotux.net>
parents: 1014
diff changeset
   479
    buf = g_strdup_printf("Status message: %s", p);
579299b1c9b2 Add /request last
Mikael Berthe <mikael@lilotux.net>
parents: 1014
diff changeset
   480
    scr_WriteIncomingMessage(bjid, buf, 0, HBB_PREFIX_INFO);
579299b1c9b2 Add /request last
Mikael Berthe <mikael@lilotux.net>
parents: 1014
diff changeset
   481
    g_free(buf);
579299b1c9b2 Add /request last
Mikael Berthe <mikael@lilotux.net>
parents: 1014
diff changeset
   482
  }
1213
4a7db2870685 Improve Private Storage detection.
Mikael Berthe <mikael@lilotux.net>
parents: 1205
diff changeset
   483
  return 0;
1015
579299b1c9b2 Add /request last
Mikael Berthe <mikael@lilotux.net>
parents: 1014
diff changeset
   484
}
579299b1c9b2 Add /request last
Mikael Berthe <mikael@lilotux.net>
parents: 1014
diff changeset
   485
579299b1c9b2 Add /request last
Mikael Berthe <mikael@lilotux.net>
parents: 1014
diff changeset
   486
void request_last(const char *fulljid)
579299b1c9b2 Add /request last
Mikael Berthe <mikael@lilotux.net>
parents: 1014
diff changeset
   487
{
579299b1c9b2 Add /request last
Mikael Berthe <mikael@lilotux.net>
parents: 1014
diff changeset
   488
  eviqs *iqn;
579299b1c9b2 Add /request last
Mikael Berthe <mikael@lilotux.net>
parents: 1014
diff changeset
   489
579299b1c9b2 Add /request last
Mikael Berthe <mikael@lilotux.net>
parents: 1014
diff changeset
   490
  iqn = iqs_new(JPACKET__GET, NS_LAST, "last", IQS_DEFAULT_TIMEOUT);
579299b1c9b2 Add /request last
Mikael Berthe <mikael@lilotux.net>
parents: 1014
diff changeset
   491
  xmlnode_put_attrib(iqn->xmldata, "to", fulljid);
579299b1c9b2 Add /request last
Mikael Berthe <mikael@lilotux.net>
parents: 1014
diff changeset
   492
  iqn->callback = &iqscallback_last;
579299b1c9b2 Add /request last
Mikael Berthe <mikael@lilotux.net>
parents: 1014
diff changeset
   493
  jab_send(jc, iqn->xmldata);
579299b1c9b2 Add /request last
Mikael Berthe <mikael@lilotux.net>
parents: 1014
diff changeset
   494
}
579299b1c9b2 Add /request last
Mikael Berthe <mikael@lilotux.net>
parents: 1014
diff changeset
   495
1006
f61131cd86a0 Clean up vcard code
Mikael Berthe <mikael@lilotux.net>
parents: 1005
diff changeset
   496
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
   497
                               enum vcard_attr vcard_attrib, const char *text)
f61131cd86a0 Clean up vcard code
Mikael Berthe <mikael@lilotux.net>
parents: 1005
diff changeset
   498
{
f61131cd86a0 Clean up vcard code
Mikael Berthe <mikael@lilotux.net>
parents: 1005
diff changeset
   499
  char *buf;
f61131cd86a0 Clean up vcard code
Mikael Berthe <mikael@lilotux.net>
parents: 1005
diff changeset
   500
f61131cd86a0 Clean up vcard code
Mikael Berthe <mikael@lilotux.net>
parents: 1005
diff changeset
   501
  if (!text || !bjid || !label)
f61131cd86a0 Clean up vcard code
Mikael Berthe <mikael@lilotux.net>
parents: 1005
diff changeset
   502
    return;
f61131cd86a0 Clean up vcard code
Mikael Berthe <mikael@lilotux.net>
parents: 1005
diff changeset
   503
f61131cd86a0 Clean up vcard code
Mikael Berthe <mikael@lilotux.net>
parents: 1005
diff changeset
   504
  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
   505
                        (vcard_attrib & vcard_home ? "[home]" : ""),
f61131cd86a0 Clean up vcard code
Mikael Berthe <mikael@lilotux.net>
parents: 1005
diff changeset
   506
                        (vcard_attrib & vcard_work ? "[work]" : ""),
f61131cd86a0 Clean up vcard code
Mikael Berthe <mikael@lilotux.net>
parents: 1005
diff changeset
   507
                        (vcard_attrib & vcard_postal ? "[postal]" : ""),
f61131cd86a0 Clean up vcard code
Mikael Berthe <mikael@lilotux.net>
parents: 1005
diff changeset
   508
                        (vcard_attrib & vcard_voice ? "[voice]" : ""),
f61131cd86a0 Clean up vcard code
Mikael Berthe <mikael@lilotux.net>
parents: 1005
diff changeset
   509
                        (vcard_attrib & vcard_fax  ? "[fax]"  : ""),
f61131cd86a0 Clean up vcard code
Mikael Berthe <mikael@lilotux.net>
parents: 1005
diff changeset
   510
                        (vcard_attrib & vcard_cell ? "[cell]" : ""),
f61131cd86a0 Clean up vcard code
Mikael Berthe <mikael@lilotux.net>
parents: 1005
diff changeset
   511
                        (vcard_attrib & vcard_inet ? "[inet]" : ""),
f61131cd86a0 Clean up vcard code
Mikael Berthe <mikael@lilotux.net>
parents: 1005
diff changeset
   512
                        (vcard_attrib & vcard_pref ? "[pref]" : ""),
f61131cd86a0 Clean up vcard code
Mikael Berthe <mikael@lilotux.net>
parents: 1005
diff changeset
   513
                        (vcard_attrib ? " " : ""),
f61131cd86a0 Clean up vcard code
Mikael Berthe <mikael@lilotux.net>
parents: 1005
diff changeset
   514
                        text);
f61131cd86a0 Clean up vcard code
Mikael Berthe <mikael@lilotux.net>
parents: 1005
diff changeset
   515
  scr_WriteIncomingMessage(bjid, buf, 0, HBB_PREFIX_NONE);
f61131cd86a0 Clean up vcard code
Mikael Berthe <mikael@lilotux.net>
parents: 1005
diff changeset
   516
  g_free(buf);
f61131cd86a0 Clean up vcard code
Mikael Berthe <mikael@lilotux.net>
parents: 1005
diff changeset
   517
}
f61131cd86a0 Clean up vcard code
Mikael Berthe <mikael@lilotux.net>
parents: 1005
diff changeset
   518
1003
c8b1a52b2fd6 Initial VCard retrieval support
Mikael Berthe <mikael@lilotux.net>
parents: 1002
diff changeset
   519
static void handle_vcard_node(const char *barejid, xmlnode vcardnode)
c8b1a52b2fd6 Initial VCard retrieval support
Mikael Berthe <mikael@lilotux.net>
parents: 1002
diff changeset
   520
{
c8b1a52b2fd6 Initial VCard retrieval support
Mikael Berthe <mikael@lilotux.net>
parents: 1002
diff changeset
   521
  xmlnode x;
c8b1a52b2fd6 Initial VCard retrieval support
Mikael Berthe <mikael@lilotux.net>
parents: 1002
diff changeset
   522
  const char *p;
c8b1a52b2fd6 Initial VCard retrieval support
Mikael Berthe <mikael@lilotux.net>
parents: 1002
diff changeset
   523
c8b1a52b2fd6 Initial VCard retrieval support
Mikael Berthe <mikael@lilotux.net>
parents: 1002
diff changeset
   524
  x = xmlnode_get_firstchild(vcardnode);
c8b1a52b2fd6 Initial VCard retrieval support
Mikael Berthe <mikael@lilotux.net>
parents: 1002
diff changeset
   525
  for ( ; x; x = xmlnode_get_nextsibling(x)) {
1006
f61131cd86a0 Clean up vcard code
Mikael Berthe <mikael@lilotux.net>
parents: 1005
diff changeset
   526
    const char *data;
f61131cd86a0 Clean up vcard code
Mikael Berthe <mikael@lilotux.net>
parents: 1005
diff changeset
   527
    enum vcard_attr vcard_attrib = 0;
f61131cd86a0 Clean up vcard code
Mikael Berthe <mikael@lilotux.net>
parents: 1005
diff changeset
   528
1003
c8b1a52b2fd6 Initial VCard retrieval support
Mikael Berthe <mikael@lilotux.net>
parents: 1002
diff changeset
   529
    p = xmlnode_get_name(x);
c8b1a52b2fd6 Initial VCard retrieval support
Mikael Berthe <mikael@lilotux.net>
parents: 1002
diff changeset
   530
    data = xmlnode_get_data(x);
1006
f61131cd86a0 Clean up vcard code
Mikael Berthe <mikael@lilotux.net>
parents: 1005
diff changeset
   531
    if (!p || !data)
f61131cd86a0 Clean up vcard code
Mikael Berthe <mikael@lilotux.net>
parents: 1005
diff changeset
   532
      continue;
f61131cd86a0 Clean up vcard code
Mikael Berthe <mikael@lilotux.net>
parents: 1005
diff changeset
   533
f61131cd86a0 Clean up vcard code
Mikael Berthe <mikael@lilotux.net>
parents: 1005
diff changeset
   534
    if (!strcmp(p, "FN"))
f61131cd86a0 Clean up vcard code
Mikael Berthe <mikael@lilotux.net>
parents: 1005
diff changeset
   535
      display_vcard_item(barejid, "Name", vcard_attrib, data);
f61131cd86a0 Clean up vcard code
Mikael Berthe <mikael@lilotux.net>
parents: 1005
diff changeset
   536
    else if (!strcmp(p, "NICKNAME"))
f61131cd86a0 Clean up vcard code
Mikael Berthe <mikael@lilotux.net>
parents: 1005
diff changeset
   537
      display_vcard_item(barejid, "Nickname", vcard_attrib, data);
f61131cd86a0 Clean up vcard code
Mikael Berthe <mikael@lilotux.net>
parents: 1005
diff changeset
   538
    else if (!strcmp(p, "URL"))
f61131cd86a0 Clean up vcard code
Mikael Berthe <mikael@lilotux.net>
parents: 1005
diff changeset
   539
      display_vcard_item(barejid, "URL", vcard_attrib, data);
f61131cd86a0 Clean up vcard code
Mikael Berthe <mikael@lilotux.net>
parents: 1005
diff changeset
   540
    else if (!strcmp(p, "BDAY"))
f61131cd86a0 Clean up vcard code
Mikael Berthe <mikael@lilotux.net>
parents: 1005
diff changeset
   541
      display_vcard_item(barejid, "Birthday", vcard_attrib, data);
f61131cd86a0 Clean up vcard code
Mikael Berthe <mikael@lilotux.net>
parents: 1005
diff changeset
   542
    else if (!strcmp(p, "TZ"))
f61131cd86a0 Clean up vcard code
Mikael Berthe <mikael@lilotux.net>
parents: 1005
diff changeset
   543
      display_vcard_item(barejid, "Timezone", vcard_attrib, data);
f61131cd86a0 Clean up vcard code
Mikael Berthe <mikael@lilotux.net>
parents: 1005
diff changeset
   544
    else if (!strcmp(p, "TITLE"))
f61131cd86a0 Clean up vcard code
Mikael Berthe <mikael@lilotux.net>
parents: 1005
diff changeset
   545
      display_vcard_item(barejid, "Title", vcard_attrib, data);
f61131cd86a0 Clean up vcard code
Mikael Berthe <mikael@lilotux.net>
parents: 1005
diff changeset
   546
    else if (!strcmp(p, "ROLE"))
f61131cd86a0 Clean up vcard code
Mikael Berthe <mikael@lilotux.net>
parents: 1005
diff changeset
   547
      display_vcard_item(barejid, "Role", vcard_attrib, data);
f61131cd86a0 Clean up vcard code
Mikael Berthe <mikael@lilotux.net>
parents: 1005
diff changeset
   548
    else if (!strcmp(p, "DESC"))
f61131cd86a0 Clean up vcard code
Mikael Berthe <mikael@lilotux.net>
parents: 1005
diff changeset
   549
      display_vcard_item(barejid, "Comment", vcard_attrib, data);
f61131cd86a0 Clean up vcard code
Mikael Berthe <mikael@lilotux.net>
parents: 1005
diff changeset
   550
    else if (!strcmp(p, "N")) {
f61131cd86a0 Clean up vcard code
Mikael Berthe <mikael@lilotux.net>
parents: 1005
diff changeset
   551
      data = xmlnode_get_tag_data(x, "FAMILY");
f61131cd86a0 Clean up vcard code
Mikael Berthe <mikael@lilotux.net>
parents: 1005
diff changeset
   552
      display_vcard_item(barejid, "Family Name", vcard_attrib, data);
f61131cd86a0 Clean up vcard code
Mikael Berthe <mikael@lilotux.net>
parents: 1005
diff changeset
   553
      data = xmlnode_get_tag_data(x, "GIVEN");
f61131cd86a0 Clean up vcard code
Mikael Berthe <mikael@lilotux.net>
parents: 1005
diff changeset
   554
      display_vcard_item(barejid, "Given Name", vcard_attrib, data);
f61131cd86a0 Clean up vcard code
Mikael Berthe <mikael@lilotux.net>
parents: 1005
diff changeset
   555
      data = xmlnode_get_tag_data(x, "MIDDLE");
f61131cd86a0 Clean up vcard code
Mikael Berthe <mikael@lilotux.net>
parents: 1005
diff changeset
   556
      display_vcard_item(barejid, "Middle Name", vcard_attrib, data);
f61131cd86a0 Clean up vcard code
Mikael Berthe <mikael@lilotux.net>
parents: 1005
diff changeset
   557
    } else if (!strcmp(p, "ORG")) {
f61131cd86a0 Clean up vcard code
Mikael Berthe <mikael@lilotux.net>
parents: 1005
diff changeset
   558
      data = xmlnode_get_tag_data(x, "ORGNAME");
f61131cd86a0 Clean up vcard code
Mikael Berthe <mikael@lilotux.net>
parents: 1005
diff changeset
   559
      display_vcard_item(barejid, "Organisation name", vcard_attrib, data);
f61131cd86a0 Clean up vcard code
Mikael Berthe <mikael@lilotux.net>
parents: 1005
diff changeset
   560
      data = xmlnode_get_tag_data(x, "ORGUNIT");
f61131cd86a0 Clean up vcard code
Mikael Berthe <mikael@lilotux.net>
parents: 1005
diff changeset
   561
      display_vcard_item(barejid, "Organisation unit", vcard_attrib, data);
f61131cd86a0 Clean up vcard code
Mikael Berthe <mikael@lilotux.net>
parents: 1005
diff changeset
   562
    } else {
f61131cd86a0 Clean up vcard code
Mikael Berthe <mikael@lilotux.net>
parents: 1005
diff changeset
   563
      // 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
   564
      // (ADR, TEL & EMAIL)
f61131cd86a0 Clean up vcard code
Mikael Berthe <mikael@lilotux.net>
parents: 1005
diff changeset
   565
      if (xmlnode_get_tag(x, "HOME"))
f61131cd86a0 Clean up vcard code
Mikael Berthe <mikael@lilotux.net>
parents: 1005
diff changeset
   566
        vcard_attrib |= vcard_home;
f61131cd86a0 Clean up vcard code
Mikael Berthe <mikael@lilotux.net>
parents: 1005
diff changeset
   567
      if (xmlnode_get_tag(x, "WORK"))
f61131cd86a0 Clean up vcard code
Mikael Berthe <mikael@lilotux.net>
parents: 1005
diff changeset
   568
        vcard_attrib |= vcard_work;
f61131cd86a0 Clean up vcard code
Mikael Berthe <mikael@lilotux.net>
parents: 1005
diff changeset
   569
      if (xmlnode_get_tag(x, "PREF"))
f61131cd86a0 Clean up vcard code
Mikael Berthe <mikael@lilotux.net>
parents: 1005
diff changeset
   570
        vcard_attrib |= vcard_pref;
f61131cd86a0 Clean up vcard code
Mikael Berthe <mikael@lilotux.net>
parents: 1005
diff changeset
   571
      if (!strcmp(p, "ADR")) {          // Address
1005
e5c10cc29660 Improve vcard support
Mikael Berthe <mikael@lilotux.net>
parents: 1004
diff changeset
   572
        if (xmlnode_get_tag(x, "POSTAL"))
1006
f61131cd86a0 Clean up vcard code
Mikael Berthe <mikael@lilotux.net>
parents: 1005
diff changeset
   573
          vcard_attrib |= vcard_postal;
f61131cd86a0 Clean up vcard code
Mikael Berthe <mikael@lilotux.net>
parents: 1005
diff changeset
   574
        data = xmlnode_get_tag_data(x, "EXTADD");
f61131cd86a0 Clean up vcard code
Mikael Berthe <mikael@lilotux.net>
parents: 1005
diff changeset
   575
        display_vcard_item(barejid, "Addr (ext)", vcard_attrib, data);
f61131cd86a0 Clean up vcard code
Mikael Berthe <mikael@lilotux.net>
parents: 1005
diff changeset
   576
        data = xmlnode_get_tag_data(x, "STREET");
f61131cd86a0 Clean up vcard code
Mikael Berthe <mikael@lilotux.net>
parents: 1005
diff changeset
   577
        display_vcard_item(barejid, "Street", vcard_attrib, data);
f61131cd86a0 Clean up vcard code
Mikael Berthe <mikael@lilotux.net>
parents: 1005
diff changeset
   578
        data = xmlnode_get_tag_data(x, "LOCALITY");
f61131cd86a0 Clean up vcard code
Mikael Berthe <mikael@lilotux.net>
parents: 1005
diff changeset
   579
        display_vcard_item(barejid, "Locality", vcard_attrib, data);
f61131cd86a0 Clean up vcard code
Mikael Berthe <mikael@lilotux.net>
parents: 1005
diff changeset
   580
        data = xmlnode_get_tag_data(x, "REGION");
f61131cd86a0 Clean up vcard code
Mikael Berthe <mikael@lilotux.net>
parents: 1005
diff changeset
   581
        display_vcard_item(barejid, "Region", vcard_attrib, data);
f61131cd86a0 Clean up vcard code
Mikael Berthe <mikael@lilotux.net>
parents: 1005
diff changeset
   582
        data = xmlnode_get_tag_data(x, "PCODE");
f61131cd86a0 Clean up vcard code
Mikael Berthe <mikael@lilotux.net>
parents: 1005
diff changeset
   583
        display_vcard_item(barejid, "Postal code", vcard_attrib, data);
f61131cd86a0 Clean up vcard code
Mikael Berthe <mikael@lilotux.net>
parents: 1005
diff changeset
   584
        data = xmlnode_get_tag_data(x, "CTRY");
f61131cd86a0 Clean up vcard code
Mikael Berthe <mikael@lilotux.net>
parents: 1005
diff changeset
   585
        display_vcard_item(barejid, "Country", vcard_attrib, data);
f61131cd86a0 Clean up vcard code
Mikael Berthe <mikael@lilotux.net>
parents: 1005
diff changeset
   586
      } else if (!strcmp(p, "TEL")) {   // Telephone
1005
e5c10cc29660 Improve vcard support
Mikael Berthe <mikael@lilotux.net>
parents: 1004
diff changeset
   587
        data = xmlnode_get_tag_data(x, "NUMBER");
e5c10cc29660 Improve vcard support
Mikael Berthe <mikael@lilotux.net>
parents: 1004
diff changeset
   588
        if (data) {
e5c10cc29660 Improve vcard support
Mikael Berthe <mikael@lilotux.net>
parents: 1004
diff changeset
   589
          if (xmlnode_get_tag(x, "VOICE"))
1006
f61131cd86a0 Clean up vcard code
Mikael Berthe <mikael@lilotux.net>
parents: 1005
diff changeset
   590
            vcard_attrib |= vcard_voice;
1005
e5c10cc29660 Improve vcard support
Mikael Berthe <mikael@lilotux.net>
parents: 1004
diff changeset
   591
          if (xmlnode_get_tag(x, "FAX"))
1006
f61131cd86a0 Clean up vcard code
Mikael Berthe <mikael@lilotux.net>
parents: 1005
diff changeset
   592
            vcard_attrib |= vcard_fax;
1005
e5c10cc29660 Improve vcard support
Mikael Berthe <mikael@lilotux.net>
parents: 1004
diff changeset
   593
          if (xmlnode_get_tag(x, "CELL"))
1006
f61131cd86a0 Clean up vcard code
Mikael Berthe <mikael@lilotux.net>
parents: 1005
diff changeset
   594
            vcard_attrib |= vcard_cell;
f61131cd86a0 Clean up vcard code
Mikael Berthe <mikael@lilotux.net>
parents: 1005
diff changeset
   595
          display_vcard_item(barejid, "Phone", vcard_attrib, data);
1005
e5c10cc29660 Improve vcard support
Mikael Berthe <mikael@lilotux.net>
parents: 1004
diff changeset
   596
        }
1006
f61131cd86a0 Clean up vcard code
Mikael Berthe <mikael@lilotux.net>
parents: 1005
diff changeset
   597
      } else if (!strcmp(p, "EMAIL")) { // Email
f61131cd86a0 Clean up vcard code
Mikael Berthe <mikael@lilotux.net>
parents: 1005
diff changeset
   598
        if (xmlnode_get_tag(x, "INTERNET"))
f61131cd86a0 Clean up vcard code
Mikael Berthe <mikael@lilotux.net>
parents: 1005
diff changeset
   599
          vcard_attrib |= vcard_inet;
1003
c8b1a52b2fd6 Initial VCard retrieval support
Mikael Berthe <mikael@lilotux.net>
parents: 1002
diff changeset
   600
        data = xmlnode_get_tag_data(x, "USERID");
1006
f61131cd86a0 Clean up vcard code
Mikael Berthe <mikael@lilotux.net>
parents: 1005
diff changeset
   601
        display_vcard_item(barejid, "Email", vcard_attrib, data);
1003
c8b1a52b2fd6 Initial VCard retrieval support
Mikael Berthe <mikael@lilotux.net>
parents: 1002
diff changeset
   602
      }
c8b1a52b2fd6 Initial VCard retrieval support
Mikael Berthe <mikael@lilotux.net>
parents: 1002
diff changeset
   603
    }
c8b1a52b2fd6 Initial VCard retrieval support
Mikael Berthe <mikael@lilotux.net>
parents: 1002
diff changeset
   604
  }
c8b1a52b2fd6 Initial VCard retrieval support
Mikael Berthe <mikael@lilotux.net>
parents: 1002
diff changeset
   605
}
c8b1a52b2fd6 Initial VCard retrieval support
Mikael Berthe <mikael@lilotux.net>
parents: 1002
diff changeset
   606
1213
4a7db2870685 Improve Private Storage detection.
Mikael Berthe <mikael@lilotux.net>
parents: 1205
diff changeset
   607
static int iqscallback_vcard(eviqs *iqp, xmlnode xml_result, guint iqcontext)
1003
c8b1a52b2fd6 Initial VCard retrieval support
Mikael Berthe <mikael@lilotux.net>
parents: 1002
diff changeset
   608
{
c8b1a52b2fd6 Initial VCard retrieval support
Mikael Berthe <mikael@lilotux.net>
parents: 1002
diff changeset
   609
  xmlnode ansqry;
c8b1a52b2fd6 Initial VCard retrieval support
Mikael Berthe <mikael@lilotux.net>
parents: 1002
diff changeset
   610
  char *p;
c8b1a52b2fd6 Initial VCard retrieval support
Mikael Berthe <mikael@lilotux.net>
parents: 1002
diff changeset
   611
  char *bjid;
c8b1a52b2fd6 Initial VCard retrieval support
Mikael Berthe <mikael@lilotux.net>
parents: 1002
diff changeset
   612
  char *buf;
c8b1a52b2fd6 Initial VCard retrieval support
Mikael Berthe <mikael@lilotux.net>
parents: 1002
diff changeset
   613
c8b1a52b2fd6 Initial VCard retrieval support
Mikael Berthe <mikael@lilotux.net>
parents: 1002
diff changeset
   614
  // Leave now if we cannot process xml_result
1213
4a7db2870685 Improve Private Storage detection.
Mikael Berthe <mikael@lilotux.net>
parents: 1205
diff changeset
   615
  if (!xml_result || iqcontext) return -1;
1003
c8b1a52b2fd6 Initial VCard retrieval support
Mikael Berthe <mikael@lilotux.net>
parents: 1002
diff changeset
   616
c8b1a52b2fd6 Initial VCard retrieval support
Mikael Berthe <mikael@lilotux.net>
parents: 1002
diff changeset
   617
  // Display IQ result sender...
c8b1a52b2fd6 Initial VCard retrieval support
Mikael Berthe <mikael@lilotux.net>
parents: 1002
diff changeset
   618
  p = xmlnode_get_attrib(xml_result, "from");
c8b1a52b2fd6 Initial VCard retrieval support
Mikael Berthe <mikael@lilotux.net>
parents: 1002
diff changeset
   619
  if (!p) {
c8b1a52b2fd6 Initial VCard retrieval support
Mikael Berthe <mikael@lilotux.net>
parents: 1002
diff changeset
   620
    scr_LogPrint(LPRINT_LOGNORM, "Invalid IQ:vCard result (no sender name).");
1213
4a7db2870685 Improve Private Storage detection.
Mikael Berthe <mikael@lilotux.net>
parents: 1205
diff changeset
   621
    return 0;
1003
c8b1a52b2fd6 Initial VCard retrieval support
Mikael Berthe <mikael@lilotux.net>
parents: 1002
diff changeset
   622
  }
c8b1a52b2fd6 Initial VCard retrieval support
Mikael Berthe <mikael@lilotux.net>
parents: 1002
diff changeset
   623
  bjid = p;
c8b1a52b2fd6 Initial VCard retrieval support
Mikael Berthe <mikael@lilotux.net>
parents: 1002
diff changeset
   624
c8b1a52b2fd6 Initial VCard retrieval support
Mikael Berthe <mikael@lilotux.net>
parents: 1002
diff changeset
   625
  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
   626
  scr_LogPrint(LPRINT_LOGNORM, "%s", buf);
c8b1a52b2fd6 Initial VCard retrieval support
Mikael Berthe <mikael@lilotux.net>
parents: 1002
diff changeset
   627
c8b1a52b2fd6 Initial VCard retrieval support
Mikael Berthe <mikael@lilotux.net>
parents: 1002
diff changeset
   628
  // Get the vCard node
c8b1a52b2fd6 Initial VCard retrieval support
Mikael Berthe <mikael@lilotux.net>
parents: 1002
diff changeset
   629
  ansqry = xmlnode_get_tag(xml_result, "vCard");
c8b1a52b2fd6 Initial VCard retrieval support
Mikael Berthe <mikael@lilotux.net>
parents: 1002
diff changeset
   630
  if (!ansqry) {
c8b1a52b2fd6 Initial VCard retrieval support
Mikael Berthe <mikael@lilotux.net>
parents: 1002
diff changeset
   631
    scr_LogPrint(LPRINT_LOGNORM, "Empty IQ:vCard result!");
1213
4a7db2870685 Improve Private Storage detection.
Mikael Berthe <mikael@lilotux.net>
parents: 1205
diff changeset
   632
    return 0;
1003
c8b1a52b2fd6 Initial VCard retrieval support
Mikael Berthe <mikael@lilotux.net>
parents: 1002
diff changeset
   633
  }
c8b1a52b2fd6 Initial VCard retrieval support
Mikael Berthe <mikael@lilotux.net>
parents: 1002
diff changeset
   634
c8b1a52b2fd6 Initial VCard retrieval support
Mikael Berthe <mikael@lilotux.net>
parents: 1002
diff changeset
   635
  // bjid should really be the "bare JID", let's strip the resource
c8b1a52b2fd6 Initial VCard retrieval support
Mikael Berthe <mikael@lilotux.net>
parents: 1002
diff changeset
   636
  p = strchr(bjid, JID_RESOURCE_SEPARATOR);
c8b1a52b2fd6 Initial VCard retrieval support
Mikael Berthe <mikael@lilotux.net>
parents: 1002
diff changeset
   637
  if (p) *p = '\0';
c8b1a52b2fd6 Initial VCard retrieval support
Mikael Berthe <mikael@lilotux.net>
parents: 1002
diff changeset
   638
c8b1a52b2fd6 Initial VCard retrieval support
Mikael Berthe <mikael@lilotux.net>
parents: 1002
diff changeset
   639
  scr_WriteIncomingMessage(bjid, buf, 0, HBB_PREFIX_INFO);
c8b1a52b2fd6 Initial VCard retrieval support
Mikael Berthe <mikael@lilotux.net>
parents: 1002
diff changeset
   640
  g_free(buf);
c8b1a52b2fd6 Initial VCard retrieval support
Mikael Berthe <mikael@lilotux.net>
parents: 1002
diff changeset
   641
c8b1a52b2fd6 Initial VCard retrieval support
Mikael Berthe <mikael@lilotux.net>
parents: 1002
diff changeset
   642
  // Get result data...
c8b1a52b2fd6 Initial VCard retrieval support
Mikael Berthe <mikael@lilotux.net>
parents: 1002
diff changeset
   643
  handle_vcard_node(bjid, ansqry);
1213
4a7db2870685 Improve Private Storage detection.
Mikael Berthe <mikael@lilotux.net>
parents: 1205
diff changeset
   644
  return 0;
1003
c8b1a52b2fd6 Initial VCard retrieval support
Mikael Berthe <mikael@lilotux.net>
parents: 1002
diff changeset
   645
}
c8b1a52b2fd6 Initial VCard retrieval support
Mikael Berthe <mikael@lilotux.net>
parents: 1002
diff changeset
   646
1058
c0d44a9a99bc Code cleanup
Mikael Berthe <mikael@lilotux.net>
parents: 1037
diff changeset
   647
void request_vcard(const char *bjid)
1003
c8b1a52b2fd6 Initial VCard retrieval support
Mikael Berthe <mikael@lilotux.net>
parents: 1002
diff changeset
   648
{
c8b1a52b2fd6 Initial VCard retrieval support
Mikael Berthe <mikael@lilotux.net>
parents: 1002
diff changeset
   649
  eviqs *iqn;
c8b1a52b2fd6 Initial VCard retrieval support
Mikael Berthe <mikael@lilotux.net>
parents: 1002
diff changeset
   650
  char *barejid;
c8b1a52b2fd6 Initial VCard retrieval support
Mikael Berthe <mikael@lilotux.net>
parents: 1002
diff changeset
   651
1058
c0d44a9a99bc Code cleanup
Mikael Berthe <mikael@lilotux.net>
parents: 1037
diff changeset
   652
  barejid = jidtodisp(bjid);
1003
c8b1a52b2fd6 Initial VCard retrieval support
Mikael Berthe <mikael@lilotux.net>
parents: 1002
diff changeset
   653
c8b1a52b2fd6 Initial VCard retrieval support
Mikael Berthe <mikael@lilotux.net>
parents: 1002
diff changeset
   654
  // Create a new IQ structure.  We use NULL for the namespace because
c8b1a52b2fd6 Initial VCard retrieval support
Mikael Berthe <mikael@lilotux.net>
parents: 1002
diff changeset
   655
  // we'll have to use a special tag, not the usual "query" one.
c8b1a52b2fd6 Initial VCard retrieval support
Mikael Berthe <mikael@lilotux.net>
parents: 1002
diff changeset
   656
  iqn = iqs_new(JPACKET__GET, NULL, "vcard", IQS_DEFAULT_TIMEOUT);
c8b1a52b2fd6 Initial VCard retrieval support
Mikael Berthe <mikael@lilotux.net>
parents: 1002
diff changeset
   657
  xmlnode_put_attrib(iqn->xmldata, "to", barejid);
c8b1a52b2fd6 Initial VCard retrieval support
Mikael Berthe <mikael@lilotux.net>
parents: 1002
diff changeset
   658
  // Remove the useless <query/> tag, and insert a vCard one.
c8b1a52b2fd6 Initial VCard retrieval support
Mikael Berthe <mikael@lilotux.net>
parents: 1002
diff changeset
   659
  xmlnode_hide(xmlnode_get_tag(iqn->xmldata, "query"));
c8b1a52b2fd6 Initial VCard retrieval support
Mikael Berthe <mikael@lilotux.net>
parents: 1002
diff changeset
   660
  xmlnode_put_attrib(xmlnode_insert_tag(iqn->xmldata, "vCard"),
c8b1a52b2fd6 Initial VCard retrieval support
Mikael Berthe <mikael@lilotux.net>
parents: 1002
diff changeset
   661
                     "xmlns", NS_VCARD);
c8b1a52b2fd6 Initial VCard retrieval support
Mikael Berthe <mikael@lilotux.net>
parents: 1002
diff changeset
   662
  iqn->callback = &iqscallback_vcard;
c8b1a52b2fd6 Initial VCard retrieval support
Mikael Berthe <mikael@lilotux.net>
parents: 1002
diff changeset
   663
  jab_send(jc, iqn->xmldata);
c8b1a52b2fd6 Initial VCard retrieval support
Mikael Berthe <mikael@lilotux.net>
parents: 1002
diff changeset
   664
c8b1a52b2fd6 Initial VCard retrieval support
Mikael Berthe <mikael@lilotux.net>
parents: 1002
diff changeset
   665
  g_free(barejid);
c8b1a52b2fd6 Initial VCard retrieval support
Mikael Berthe <mikael@lilotux.net>
parents: 1002
diff changeset
   666
}
c8b1a52b2fd6 Initial VCard retrieval support
Mikael Berthe <mikael@lilotux.net>
parents: 1002
diff changeset
   667
1004
b57a01ffeed6 Use existing conference bookmarks
Mikael Berthe <mikael@lilotux.net>
parents: 1003
diff changeset
   668
static void storage_bookmarks_parse_conference(xmlnode xmldata)
b57a01ffeed6 Use existing conference bookmarks
Mikael Berthe <mikael@lilotux.net>
parents: 1003
diff changeset
   669
{
1058
c0d44a9a99bc Code cleanup
Mikael Berthe <mikael@lilotux.net>
parents: 1037
diff changeset
   670
  const char *fjid, *name, *autojoin;
1004
b57a01ffeed6 Use existing conference bookmarks
Mikael Berthe <mikael@lilotux.net>
parents: 1003
diff changeset
   671
  char *bjid;
b57a01ffeed6 Use existing conference bookmarks
Mikael Berthe <mikael@lilotux.net>
parents: 1003
diff changeset
   672
  GSList *room_elt;
b57a01ffeed6 Use existing conference bookmarks
Mikael Berthe <mikael@lilotux.net>
parents: 1003
diff changeset
   673
1058
c0d44a9a99bc Code cleanup
Mikael Berthe <mikael@lilotux.net>
parents: 1037
diff changeset
   674
  fjid = xmlnode_get_attrib(xmldata, "jid");
c0d44a9a99bc Code cleanup
Mikael Berthe <mikael@lilotux.net>
parents: 1037
diff changeset
   675
  if (!fjid)
1004
b57a01ffeed6 Use existing conference bookmarks
Mikael Berthe <mikael@lilotux.net>
parents: 1003
diff changeset
   676
    return;
b57a01ffeed6 Use existing conference bookmarks
Mikael Berthe <mikael@lilotux.net>
parents: 1003
diff changeset
   677
  name = xmlnode_get_attrib(xmldata, "name");
b57a01ffeed6 Use existing conference bookmarks
Mikael Berthe <mikael@lilotux.net>
parents: 1003
diff changeset
   678
  autojoin = xmlnode_get_attrib(xmldata, "autojoin");
b57a01ffeed6 Use existing conference bookmarks
Mikael Berthe <mikael@lilotux.net>
parents: 1003
diff changeset
   679
1058
c0d44a9a99bc Code cleanup
Mikael Berthe <mikael@lilotux.net>
parents: 1037
diff changeset
   680
  bjid = jidtodisp(fjid); // Bare jid
1004
b57a01ffeed6 Use existing conference bookmarks
Mikael Berthe <mikael@lilotux.net>
parents: 1003
diff changeset
   681
b57a01ffeed6 Use existing conference bookmarks
Mikael Berthe <mikael@lilotux.net>
parents: 1003
diff changeset
   682
  // 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
   683
  room_elt = roster_find(bjid, jidsearch, 0);
b57a01ffeed6 Use existing conference bookmarks
Mikael Berthe <mikael@lilotux.net>
parents: 1003
diff changeset
   684
  if (!room_elt) {
b57a01ffeed6 Use existing conference bookmarks
Mikael Berthe <mikael@lilotux.net>
parents: 1003
diff changeset
   685
    room_elt = roster_add_user(bjid, name, NULL, ROSTER_TYPE_ROOM, sub_none);
b57a01ffeed6 Use existing conference bookmarks
Mikael Berthe <mikael@lilotux.net>
parents: 1003
diff changeset
   686
  } else {
b57a01ffeed6 Use existing conference bookmarks
Mikael Berthe <mikael@lilotux.net>
parents: 1003
diff changeset
   687
    buddy_settype(room_elt->data, ROSTER_TYPE_ROOM);
b57a01ffeed6 Use existing conference bookmarks
Mikael Berthe <mikael@lilotux.net>
parents: 1003
diff changeset
   688
    /*
b57a01ffeed6 Use existing conference bookmarks
Mikael Berthe <mikael@lilotux.net>
parents: 1003
diff changeset
   689
    // If the name is available, should we use it?
b57a01ffeed6 Use existing conference bookmarks
Mikael Berthe <mikael@lilotux.net>
parents: 1003
diff changeset
   690
    // 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
   691
    // in the roster.
b57a01ffeed6 Use existing conference bookmarks
Mikael Berthe <mikael@lilotux.net>
parents: 1003
diff changeset
   692
    if (name)
b57a01ffeed6 Use existing conference bookmarks
Mikael Berthe <mikael@lilotux.net>
parents: 1003
diff changeset
   693
      buddy_setname(room_elt->data, name);
b57a01ffeed6 Use existing conference bookmarks
Mikael Berthe <mikael@lilotux.net>
parents: 1003
diff changeset
   694
    */
b57a01ffeed6 Use existing conference bookmarks
Mikael Berthe <mikael@lilotux.net>
parents: 1003
diff changeset
   695
  }
b57a01ffeed6 Use existing conference bookmarks
Mikael Berthe <mikael@lilotux.net>
parents: 1003
diff changeset
   696
b57a01ffeed6 Use existing conference bookmarks
Mikael Berthe <mikael@lilotux.net>
parents: 1003
diff changeset
   697
  // Is autojoin set?
b57a01ffeed6 Use existing conference bookmarks
Mikael Berthe <mikael@lilotux.net>
parents: 1003
diff changeset
   698
  // 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
   699
  // try to join the room.
b57a01ffeed6 Use existing conference bookmarks
Mikael Berthe <mikael@lilotux.net>
parents: 1003
diff changeset
   700
  if (autojoin && !strcmp(autojoin, "1")) {
b57a01ffeed6 Use existing conference bookmarks
Mikael Berthe <mikael@lilotux.net>
parents: 1003
diff changeset
   701
    char *nick, *passwd;
b57a01ffeed6 Use existing conference bookmarks
Mikael Berthe <mikael@lilotux.net>
parents: 1003
diff changeset
   702
    char *tmpnick = NULL;
b57a01ffeed6 Use existing conference bookmarks
Mikael Berthe <mikael@lilotux.net>
parents: 1003
diff changeset
   703
    nick = xmlnode_get_tag_data(xmldata, "nick");
b57a01ffeed6 Use existing conference bookmarks
Mikael Berthe <mikael@lilotux.net>
parents: 1003
diff changeset
   704
    passwd = xmlnode_get_tag_data(xmldata, "password");
b57a01ffeed6 Use existing conference bookmarks
Mikael Berthe <mikael@lilotux.net>
parents: 1003
diff changeset
   705
    if (!nick || !*nick)
b57a01ffeed6 Use existing conference bookmarks
Mikael Berthe <mikael@lilotux.net>
parents: 1003
diff changeset
   706
      nick = tmpnick = default_muc_nickname();
b57a01ffeed6 Use existing conference bookmarks
Mikael Berthe <mikael@lilotux.net>
parents: 1003
diff changeset
   707
    // Let's join now
b57a01ffeed6 Use existing conference bookmarks
Mikael Berthe <mikael@lilotux.net>
parents: 1003
diff changeset
   708
    scr_LogPrint(LPRINT_LOGNORM, "Auto-join bookmark <%s>", bjid);
b57a01ffeed6 Use existing conference bookmarks
Mikael Berthe <mikael@lilotux.net>
parents: 1003
diff changeset
   709
    jb_room_join(bjid, nick, passwd);
b57a01ffeed6 Use existing conference bookmarks
Mikael Berthe <mikael@lilotux.net>
parents: 1003
diff changeset
   710
    g_free(tmpnick);
b57a01ffeed6 Use existing conference bookmarks
Mikael Berthe <mikael@lilotux.net>
parents: 1003
diff changeset
   711
  }
b57a01ffeed6 Use existing conference bookmarks
Mikael Berthe <mikael@lilotux.net>
parents: 1003
diff changeset
   712
  g_free(bjid);
b57a01ffeed6 Use existing conference bookmarks
Mikael Berthe <mikael@lilotux.net>
parents: 1003
diff changeset
   713
}
b57a01ffeed6 Use existing conference bookmarks
Mikael Berthe <mikael@lilotux.net>
parents: 1003
diff changeset
   714
1213
4a7db2870685 Improve Private Storage detection.
Mikael Berthe <mikael@lilotux.net>
parents: 1205
diff changeset
   715
static int iqscallback_storage_bookmarks(eviqs *iqp, xmlnode xml_result,
4a7db2870685 Improve Private Storage detection.
Mikael Berthe <mikael@lilotux.net>
parents: 1205
diff changeset
   716
                                         guint iqcontext)
1004
b57a01ffeed6 Use existing conference bookmarks
Mikael Berthe <mikael@lilotux.net>
parents: 1003
diff changeset
   717
{
b57a01ffeed6 Use existing conference bookmarks
Mikael Berthe <mikael@lilotux.net>
parents: 1003
diff changeset
   718
  xmlnode x, ansqry;
b57a01ffeed6 Use existing conference bookmarks
Mikael Berthe <mikael@lilotux.net>
parents: 1003
diff changeset
   719
  char *p;
b57a01ffeed6 Use existing conference bookmarks
Mikael Berthe <mikael@lilotux.net>
parents: 1003
diff changeset
   720
1213
4a7db2870685 Improve Private Storage detection.
Mikael Berthe <mikael@lilotux.net>
parents: 1205
diff changeset
   721
  if (iqcontext == IQS_CONTEXT_ERROR) {
4a7db2870685 Improve Private Storage detection.
Mikael Berthe <mikael@lilotux.net>
parents: 1205
diff changeset
   722
    // No server support, or no bookmarks?
4a7db2870685 Improve Private Storage detection.
Mikael Berthe <mikael@lilotux.net>
parents: 1205
diff changeset
   723
    p = xmlnode_get_name(xmlnode_get_firstchild(xml_result));
4a7db2870685 Improve Private Storage detection.
Mikael Berthe <mikael@lilotux.net>
parents: 1205
diff changeset
   724
    if (p && !strcmp(p, "item-not-found")) {
4a7db2870685 Improve Private Storage detection.
Mikael Berthe <mikael@lilotux.net>
parents: 1205
diff changeset
   725
      // 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
   726
      // currently empty.
4a7db2870685 Improve Private Storage detection.
Mikael Berthe <mikael@lilotux.net>
parents: 1205
diff changeset
   727
      xmlnode_free(bookmarks);
4a7db2870685 Improve Private Storage detection.
Mikael Berthe <mikael@lilotux.net>
parents: 1205
diff changeset
   728
      bookmarks = xmlnode_new_tag("storage");
4a7db2870685 Improve Private Storage detection.
Mikael Berthe <mikael@lilotux.net>
parents: 1205
diff changeset
   729
      xmlnode_put_attrib(bookmarks, "xmlns", "storage:bookmarks");
4a7db2870685 Improve Private Storage detection.
Mikael Berthe <mikael@lilotux.net>
parents: 1205
diff changeset
   730
      // We return 0 so that the IQ error message be
4a7db2870685 Improve Private Storage detection.
Mikael Berthe <mikael@lilotux.net>
parents: 1205
diff changeset
   731
      // not displayed, as it isn't a real error.
4a7db2870685 Improve Private Storage detection.
Mikael Berthe <mikael@lilotux.net>
parents: 1205
diff changeset
   732
      return 0;
4a7db2870685 Improve Private Storage detection.
Mikael Berthe <mikael@lilotux.net>
parents: 1205
diff changeset
   733
    }
4a7db2870685 Improve Private Storage detection.
Mikael Berthe <mikael@lilotux.net>
parents: 1205
diff changeset
   734
    return -1; // Unhandled error
4a7db2870685 Improve Private Storage detection.
Mikael Berthe <mikael@lilotux.net>
parents: 1205
diff changeset
   735
  }
4a7db2870685 Improve Private Storage detection.
Mikael Berthe <mikael@lilotux.net>
parents: 1205
diff changeset
   736
1004
b57a01ffeed6 Use existing conference bookmarks
Mikael Berthe <mikael@lilotux.net>
parents: 1003
diff changeset
   737
  // Leave now if we cannot process xml_result
1213
4a7db2870685 Improve Private Storage detection.
Mikael Berthe <mikael@lilotux.net>
parents: 1205
diff changeset
   738
  if (!xml_result || iqcontext) return 0;
1004
b57a01ffeed6 Use existing conference bookmarks
Mikael Berthe <mikael@lilotux.net>
parents: 1003
diff changeset
   739
b57a01ffeed6 Use existing conference bookmarks
Mikael Berthe <mikael@lilotux.net>
parents: 1003
diff changeset
   740
  ansqry = xmlnode_get_tag(xml_result, "query");
b57a01ffeed6 Use existing conference bookmarks
Mikael Berthe <mikael@lilotux.net>
parents: 1003
diff changeset
   741
  ansqry = xmlnode_get_tag(ansqry, "storage");
b57a01ffeed6 Use existing conference bookmarks
Mikael Berthe <mikael@lilotux.net>
parents: 1003
diff changeset
   742
  if (!ansqry) {
b57a01ffeed6 Use existing conference bookmarks
Mikael Berthe <mikael@lilotux.net>
parents: 1003
diff changeset
   743
    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
   744
    return 0;
1004
b57a01ffeed6 Use existing conference bookmarks
Mikael Berthe <mikael@lilotux.net>
parents: 1003
diff changeset
   745
  }
b57a01ffeed6 Use existing conference bookmarks
Mikael Berthe <mikael@lilotux.net>
parents: 1003
diff changeset
   746
b57a01ffeed6 Use existing conference bookmarks
Mikael Berthe <mikael@lilotux.net>
parents: 1003
diff changeset
   747
  // Walk through the storage tags
b57a01ffeed6 Use existing conference bookmarks
Mikael Berthe <mikael@lilotux.net>
parents: 1003
diff changeset
   748
  x = xmlnode_get_firstchild(ansqry);
b57a01ffeed6 Use existing conference bookmarks
Mikael Berthe <mikael@lilotux.net>
parents: 1003
diff changeset
   749
  for ( ; x; x = xmlnode_get_nextsibling(x)) {
b57a01ffeed6 Use existing conference bookmarks
Mikael Berthe <mikael@lilotux.net>
parents: 1003
diff changeset
   750
    p = xmlnode_get_name(x);
b57a01ffeed6 Use existing conference bookmarks
Mikael Berthe <mikael@lilotux.net>
parents: 1003
diff changeset
   751
    // If the current node is a conference item, parse it and update the roster
b57a01ffeed6 Use existing conference bookmarks
Mikael Berthe <mikael@lilotux.net>
parents: 1003
diff changeset
   752
    if (p && !strcmp(p, "conference"))
b57a01ffeed6 Use existing conference bookmarks
Mikael Berthe <mikael@lilotux.net>
parents: 1003
diff changeset
   753
      storage_bookmarks_parse_conference(x);
b57a01ffeed6 Use existing conference bookmarks
Mikael Berthe <mikael@lilotux.net>
parents: 1003
diff changeset
   754
  }
1016
4d3c48844746 Add /roster note
Mikael Berthe <mikael@lilotux.net>
parents: 1015
diff changeset
   755
  // Copy the bookmarks node
1008
bbf53cd43fbb Functions to update room bookmarks
Mikael Berthe <mikael@lilotux.net>
parents: 1006
diff changeset
   756
  xmlnode_free(bookmarks);
bbf53cd43fbb Functions to update room bookmarks
Mikael Berthe <mikael@lilotux.net>
parents: 1006
diff changeset
   757
  bookmarks = xmlnode_dup(ansqry);
1213
4a7db2870685 Improve Private Storage detection.
Mikael Berthe <mikael@lilotux.net>
parents: 1205
diff changeset
   758
  return 0;
1004
b57a01ffeed6 Use existing conference bookmarks
Mikael Berthe <mikael@lilotux.net>
parents: 1003
diff changeset
   759
}
b57a01ffeed6 Use existing conference bookmarks
Mikael Berthe <mikael@lilotux.net>
parents: 1003
diff changeset
   760
b57a01ffeed6 Use existing conference bookmarks
Mikael Berthe <mikael@lilotux.net>
parents: 1003
diff changeset
   761
static void request_storage_bookmarks(void)
b57a01ffeed6 Use existing conference bookmarks
Mikael Berthe <mikael@lilotux.net>
parents: 1003
diff changeset
   762
{
b57a01ffeed6 Use existing conference bookmarks
Mikael Berthe <mikael@lilotux.net>
parents: 1003
diff changeset
   763
  eviqs *iqn;
b57a01ffeed6 Use existing conference bookmarks
Mikael Berthe <mikael@lilotux.net>
parents: 1003
diff changeset
   764
  xmlnode x;
b57a01ffeed6 Use existing conference bookmarks
Mikael Berthe <mikael@lilotux.net>
parents: 1003
diff changeset
   765
b57a01ffeed6 Use existing conference bookmarks
Mikael Berthe <mikael@lilotux.net>
parents: 1003
diff changeset
   766
  iqn = iqs_new(JPACKET__GET, NS_PRIVATE, "storage", IQS_DEFAULT_TIMEOUT);
b57a01ffeed6 Use existing conference bookmarks
Mikael Berthe <mikael@lilotux.net>
parents: 1003
diff changeset
   767
b57a01ffeed6 Use existing conference bookmarks
Mikael Berthe <mikael@lilotux.net>
parents: 1003
diff changeset
   768
  x = xmlnode_insert_tag(xmlnode_get_tag(iqn->xmldata, "query"), "storage");
b57a01ffeed6 Use existing conference bookmarks
Mikael Berthe <mikael@lilotux.net>
parents: 1003
diff changeset
   769
  xmlnode_put_attrib(x, "xmlns", "storage:bookmarks");
b57a01ffeed6 Use existing conference bookmarks
Mikael Berthe <mikael@lilotux.net>
parents: 1003
diff changeset
   770
b57a01ffeed6 Use existing conference bookmarks
Mikael Berthe <mikael@lilotux.net>
parents: 1003
diff changeset
   771
  iqn->callback = &iqscallback_storage_bookmarks;
b57a01ffeed6 Use existing conference bookmarks
Mikael Berthe <mikael@lilotux.net>
parents: 1003
diff changeset
   772
  jab_send(jc, iqn->xmldata);
b57a01ffeed6 Use existing conference bookmarks
Mikael Berthe <mikael@lilotux.net>
parents: 1003
diff changeset
   773
}
b57a01ffeed6 Use existing conference bookmarks
Mikael Berthe <mikael@lilotux.net>
parents: 1003
diff changeset
   774
1213
4a7db2870685 Improve Private Storage detection.
Mikael Berthe <mikael@lilotux.net>
parents: 1205
diff changeset
   775
static int iqscallback_storage_rosternotes(eviqs *iqp, xmlnode xml_result,
4a7db2870685 Improve Private Storage detection.
Mikael Berthe <mikael@lilotux.net>
parents: 1205
diff changeset
   776
                                           guint iqcontext)
1016
4d3c48844746 Add /roster note
Mikael Berthe <mikael@lilotux.net>
parents: 1015
diff changeset
   777
{
4d3c48844746 Add /roster note
Mikael Berthe <mikael@lilotux.net>
parents: 1015
diff changeset
   778
  xmlnode ansqry;
4d3c48844746 Add /roster note
Mikael Berthe <mikael@lilotux.net>
parents: 1015
diff changeset
   779
1213
4a7db2870685 Improve Private Storage detection.
Mikael Berthe <mikael@lilotux.net>
parents: 1205
diff changeset
   780
  if (iqcontext == IQS_CONTEXT_ERROR) {
4a7db2870685 Improve Private Storage detection.
Mikael Berthe <mikael@lilotux.net>
parents: 1205
diff changeset
   781
    const char *p;
4a7db2870685 Improve Private Storage detection.
Mikael Berthe <mikael@lilotux.net>
parents: 1205
diff changeset
   782
    // No server support, or no roster notes?
4a7db2870685 Improve Private Storage detection.
Mikael Berthe <mikael@lilotux.net>
parents: 1205
diff changeset
   783
    p = xmlnode_get_name(xmlnode_get_firstchild(xml_result));
4a7db2870685 Improve Private Storage detection.
Mikael Berthe <mikael@lilotux.net>
parents: 1205
diff changeset
   784
    if (p && !strcmp(p, "item-not-found")) {
4a7db2870685 Improve Private Storage detection.
Mikael Berthe <mikael@lilotux.net>
parents: 1205
diff changeset
   785
      // 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
   786
      // currently empty.
4a7db2870685 Improve Private Storage detection.
Mikael Berthe <mikael@lilotux.net>
parents: 1205
diff changeset
   787
      xmlnode_free(rosternotes);
4a7db2870685 Improve Private Storage detection.
Mikael Berthe <mikael@lilotux.net>
parents: 1205
diff changeset
   788
      rosternotes = xmlnode_new_tag("storage");
4a7db2870685 Improve Private Storage detection.
Mikael Berthe <mikael@lilotux.net>
parents: 1205
diff changeset
   789
      xmlnode_put_attrib(rosternotes, "xmlns", "storage:rosternotes");
4a7db2870685 Improve Private Storage detection.
Mikael Berthe <mikael@lilotux.net>
parents: 1205
diff changeset
   790
      // We return 0 so that the IQ error message be
4a7db2870685 Improve Private Storage detection.
Mikael Berthe <mikael@lilotux.net>
parents: 1205
diff changeset
   791
      // not displayed, as it isn't a real error.
4a7db2870685 Improve Private Storage detection.
Mikael Berthe <mikael@lilotux.net>
parents: 1205
diff changeset
   792
      return 0;
4a7db2870685 Improve Private Storage detection.
Mikael Berthe <mikael@lilotux.net>
parents: 1205
diff changeset
   793
    }
4a7db2870685 Improve Private Storage detection.
Mikael Berthe <mikael@lilotux.net>
parents: 1205
diff changeset
   794
    return -1; // Unhandled error
4a7db2870685 Improve Private Storage detection.
Mikael Berthe <mikael@lilotux.net>
parents: 1205
diff changeset
   795
  }
4a7db2870685 Improve Private Storage detection.
Mikael Berthe <mikael@lilotux.net>
parents: 1205
diff changeset
   796
1016
4d3c48844746 Add /roster note
Mikael Berthe <mikael@lilotux.net>
parents: 1015
diff changeset
   797
  // Leave now if we cannot process xml_result
1213
4a7db2870685 Improve Private Storage detection.
Mikael Berthe <mikael@lilotux.net>
parents: 1205
diff changeset
   798
  if (!xml_result || iqcontext) return 0;
1016
4d3c48844746 Add /roster note
Mikael Berthe <mikael@lilotux.net>
parents: 1015
diff changeset
   799
4d3c48844746 Add /roster note
Mikael Berthe <mikael@lilotux.net>
parents: 1015
diff changeset
   800
  ansqry = xmlnode_get_tag(xml_result, "query");
4d3c48844746 Add /roster note
Mikael Berthe <mikael@lilotux.net>
parents: 1015
diff changeset
   801
  ansqry = xmlnode_get_tag(ansqry, "storage");
4d3c48844746 Add /roster note
Mikael Berthe <mikael@lilotux.net>
parents: 1015
diff changeset
   802
  if (!ansqry) {
4d3c48844746 Add /roster note
Mikael Berthe <mikael@lilotux.net>
parents: 1015
diff changeset
   803
    scr_LogPrint(LPRINT_LOG, "Invalid IQ:private result! "
4d3c48844746 Add /roster note
Mikael Berthe <mikael@lilotux.net>
parents: 1015
diff changeset
   804
                 "(storage:rosternotes)");
1213
4a7db2870685 Improve Private Storage detection.
Mikael Berthe <mikael@lilotux.net>
parents: 1205
diff changeset
   805
    return 0;
1016
4d3c48844746 Add /roster note
Mikael Berthe <mikael@lilotux.net>
parents: 1015
diff changeset
   806
  }
4d3c48844746 Add /roster note
Mikael Berthe <mikael@lilotux.net>
parents: 1015
diff changeset
   807
  // Copy the rosternotes node
4d3c48844746 Add /roster note
Mikael Berthe <mikael@lilotux.net>
parents: 1015
diff changeset
   808
  xmlnode_free(rosternotes);
4d3c48844746 Add /roster note
Mikael Berthe <mikael@lilotux.net>
parents: 1015
diff changeset
   809
  rosternotes = xmlnode_dup(ansqry);
1213
4a7db2870685 Improve Private Storage detection.
Mikael Berthe <mikael@lilotux.net>
parents: 1205
diff changeset
   810
  return 0;
1016
4d3c48844746 Add /roster note
Mikael Berthe <mikael@lilotux.net>
parents: 1015
diff changeset
   811
}
4d3c48844746 Add /roster note
Mikael Berthe <mikael@lilotux.net>
parents: 1015
diff changeset
   812
4d3c48844746 Add /roster note
Mikael Berthe <mikael@lilotux.net>
parents: 1015
diff changeset
   813
static void request_storage_rosternotes(void)
4d3c48844746 Add /roster note
Mikael Berthe <mikael@lilotux.net>
parents: 1015
diff changeset
   814
{
4d3c48844746 Add /roster note
Mikael Berthe <mikael@lilotux.net>
parents: 1015
diff changeset
   815
  eviqs *iqn;
4d3c48844746 Add /roster note
Mikael Berthe <mikael@lilotux.net>
parents: 1015
diff changeset
   816
  xmlnode x;
4d3c48844746 Add /roster note
Mikael Berthe <mikael@lilotux.net>
parents: 1015
diff changeset
   817
4d3c48844746 Add /roster note
Mikael Berthe <mikael@lilotux.net>
parents: 1015
diff changeset
   818
  iqn = iqs_new(JPACKET__GET, NS_PRIVATE, "storage", IQS_DEFAULT_TIMEOUT);
4d3c48844746 Add /roster note
Mikael Berthe <mikael@lilotux.net>
parents: 1015
diff changeset
   819
4d3c48844746 Add /roster note
Mikael Berthe <mikael@lilotux.net>
parents: 1015
diff changeset
   820
  x = xmlnode_insert_tag(xmlnode_get_tag(iqn->xmldata, "query"), "storage");
4d3c48844746 Add /roster note
Mikael Berthe <mikael@lilotux.net>
parents: 1015
diff changeset
   821
  xmlnode_put_attrib(x, "xmlns", "storage:rosternotes");
4d3c48844746 Add /roster note
Mikael Berthe <mikael@lilotux.net>
parents: 1015
diff changeset
   822
4d3c48844746 Add /roster note
Mikael Berthe <mikael@lilotux.net>
parents: 1015
diff changeset
   823
  iqn->callback = &iqscallback_storage_rosternotes;
4d3c48844746 Add /roster note
Mikael Berthe <mikael@lilotux.net>
parents: 1015
diff changeset
   824
  jab_send(jc, iqn->xmldata);
4d3c48844746 Add /roster note
Mikael Berthe <mikael@lilotux.net>
parents: 1015
diff changeset
   825
}
4d3c48844746 Add /roster note
Mikael Berthe <mikael@lilotux.net>
parents: 1015
diff changeset
   826
1213
4a7db2870685 Improve Private Storage detection.
Mikael Berthe <mikael@lilotux.net>
parents: 1205
diff changeset
   827
int iqscallback_auth(eviqs *iqp, xmlnode xml_result)
686
98de2d166a11 Use the new IQ system for authentication
Mikael Berthe <mikael@lilotux.net>
parents: 685
diff changeset
   828
{
98de2d166a11 Use the new IQ system for authentication
Mikael Berthe <mikael@lilotux.net>
parents: 685
diff changeset
   829
  if (jstate == STATE_GETAUTH) {
745
413e95f3051a Introduce user "events" list
Mikael Berthe <mikael@lilotux.net>
parents: 705
diff changeset
   830
    eviqs *iqn;
686
98de2d166a11 Use the new IQ system for authentication
Mikael Berthe <mikael@lilotux.net>
parents: 685
diff changeset
   831
98de2d166a11 Use the new IQ system for authentication
Mikael Berthe <mikael@lilotux.net>
parents: 685
diff changeset
   832
    if (xml_result) {
98de2d166a11 Use the new IQ system for authentication
Mikael Berthe <mikael@lilotux.net>
parents: 685
diff changeset
   833
      xmlnode x = xmlnode_get_tag(xml_result, "query");
98de2d166a11 Use the new IQ system for authentication
Mikael Berthe <mikael@lilotux.net>
parents: 685
diff changeset
   834
      if (x && !xmlnode_get_tag(x, "digest"))
98de2d166a11 Use the new IQ system for authentication
Mikael Berthe <mikael@lilotux.net>
parents: 685
diff changeset
   835
        jc->sid = 0;
98de2d166a11 Use the new IQ system for authentication
Mikael Berthe <mikael@lilotux.net>
parents: 685
diff changeset
   836
    }
98de2d166a11 Use the new IQ system for authentication
Mikael Berthe <mikael@lilotux.net>
parents: 685
diff changeset
   837
98de2d166a11 Use the new IQ system for authentication
Mikael Berthe <mikael@lilotux.net>
parents: 685
diff changeset
   838
    iqn = iqs_new(JPACKET__SET, NS_AUTH, "auth", IQS_DEFAULT_TIMEOUT);
98de2d166a11 Use the new IQ system for authentication
Mikael Berthe <mikael@lilotux.net>
parents: 685
diff changeset
   839
    iqn->callback = &iqscallback_auth;
98de2d166a11 Use the new IQ system for authentication
Mikael Berthe <mikael@lilotux.net>
parents: 685
diff changeset
   840
    jab_auth_mcabber(jc, iqn->xmldata);
98de2d166a11 Use the new IQ system for authentication
Mikael Berthe <mikael@lilotux.net>
parents: 685
diff changeset
   841
    jab_send(jc, iqn->xmldata);
98de2d166a11 Use the new IQ system for authentication
Mikael Berthe <mikael@lilotux.net>
parents: 685
diff changeset
   842
    jstate = STATE_SENDAUTH;
98de2d166a11 Use the new IQ system for authentication
Mikael Berthe <mikael@lilotux.net>
parents: 685
diff changeset
   843
  } else if (jstate == STATE_SENDAUTH) {
98de2d166a11 Use the new IQ system for authentication
Mikael Berthe <mikael@lilotux.net>
parents: 685
diff changeset
   844
    request_roster();
1004
b57a01ffeed6 Use existing conference bookmarks
Mikael Berthe <mikael@lilotux.net>
parents: 1003
diff changeset
   845
    request_storage_bookmarks();
1016
4d3c48844746 Add /roster note
Mikael Berthe <mikael@lilotux.net>
parents: 1015
diff changeset
   846
    request_storage_rosternotes();
686
98de2d166a11 Use the new IQ system for authentication
Mikael Berthe <mikael@lilotux.net>
parents: 685
diff changeset
   847
    jstate = STATE_LOGGED;
98de2d166a11 Use the new IQ system for authentication
Mikael Berthe <mikael@lilotux.net>
parents: 685
diff changeset
   848
  }
1213
4a7db2870685 Improve Private Storage detection.
Mikael Berthe <mikael@lilotux.net>
parents: 1205
diff changeset
   849
  return 0;
686
98de2d166a11 Use the new IQ system for authentication
Mikael Berthe <mikael@lilotux.net>
parents: 685
diff changeset
   850
}
98de2d166a11 Use the new IQ system for authentication
Mikael Berthe <mikael@lilotux.net>
parents: 685
diff changeset
   851
577
5c6d364130ee Move IQ Jabber stuff to a separate file
Mikael Berthe <mikael@lilotux.net>
parents: 576
diff changeset
   852
static void handle_iq_result(jconn conn, char *from, xmlnode xmldata)
426
2706ef3e25a7 Better handling of server error codes/messages
Mikael Berthe <mikael@lilotux.net>
parents: 421
diff changeset
   853
{
577
5c6d364130ee Move IQ Jabber stuff to a separate file
Mikael Berthe <mikael@lilotux.net>
parents: 576
diff changeset
   854
  xmlnode x;
685
f033345d1315 Call IQ callback function when receiving a RESULT packet
Mikael Berthe <mikael@lilotux.net>
parents: 684
diff changeset
   855
  char *id;
577
5c6d364130ee Move IQ Jabber stuff to a separate file
Mikael Berthe <mikael@lilotux.net>
parents: 576
diff changeset
   856
  char *ns;
5c6d364130ee Move IQ Jabber stuff to a separate file
Mikael Berthe <mikael@lilotux.net>
parents: 576
diff changeset
   857
685
f033345d1315 Call IQ callback function when receiving a RESULT packet
Mikael Berthe <mikael@lilotux.net>
parents: 684
diff changeset
   858
  id = xmlnode_get_attrib(xmldata, "id");
f033345d1315 Call IQ callback function when receiving a RESULT packet
Mikael Berthe <mikael@lilotux.net>
parents: 684
diff changeset
   859
  if (!id) {
596
6c7fd289648f Clean up handle_iq_result()
Mikael Berthe <mikael@lilotux.net>
parents: 595
diff changeset
   860
    scr_LogPrint(LPRINT_LOG, "IQ result stanza with no ID, ignored.");
6c7fd289648f Clean up handle_iq_result()
Mikael Berthe <mikael@lilotux.net>
parents: 595
diff changeset
   861
    return;
6c7fd289648f Clean up handle_iq_result()
Mikael Berthe <mikael@lilotux.net>
parents: 595
diff changeset
   862
  }
577
5c6d364130ee Move IQ Jabber stuff to a separate file
Mikael Berthe <mikael@lilotux.net>
parents: 576
diff changeset
   863
698
60522cf6d325 Propagate context to IQ callback functions
Mikael Berthe <mikael@lilotux.net>
parents: 692
diff changeset
   864
  if (!iqs_callback(id, xmldata, IQS_CONTEXT_RESULT))
685
f033345d1315 Call IQ callback function when receiving a RESULT packet
Mikael Berthe <mikael@lilotux.net>
parents: 684
diff changeset
   865
    return;
f033345d1315 Call IQ callback function when receiving a RESULT packet
Mikael Berthe <mikael@lilotux.net>
parents: 684
diff changeset
   866
577
5c6d364130ee Move IQ Jabber stuff to a separate file
Mikael Berthe <mikael@lilotux.net>
parents: 576
diff changeset
   867
  x = xmlnode_get_tag(xmldata, "query");
5c6d364130ee Move IQ Jabber stuff to a separate file
Mikael Berthe <mikael@lilotux.net>
parents: 576
diff changeset
   868
  if (!x) return;
5c6d364130ee Move IQ Jabber stuff to a separate file
Mikael Berthe <mikael@lilotux.net>
parents: 576
diff changeset
   869
5c6d364130ee Move IQ Jabber stuff to a separate file
Mikael Berthe <mikael@lilotux.net>
parents: 576
diff changeset
   870
  ns = xmlnode_get_attrib(x, "xmlns");
5c6d364130ee Move IQ Jabber stuff to a separate file
Mikael Berthe <mikael@lilotux.net>
parents: 576
diff changeset
   871
  if (!ns) return;
5c6d364130ee Move IQ Jabber stuff to a separate file
Mikael Berthe <mikael@lilotux.net>
parents: 576
diff changeset
   872
5c6d364130ee Move IQ Jabber stuff to a separate file
Mikael Berthe <mikael@lilotux.net>
parents: 576
diff changeset
   873
  if (!strcmp(ns, NS_ROSTER)) {
606
0b4ed231ebc2 Code cleanup + remove deprecated Agents list IQ request
Mikael Berthe <mikael@lilotux.net>
parents: 605
diff changeset
   874
    handle_iq_roster(x);
603
9516db839e08 Store subscription data
Mikael Berthe <mikael@lilotux.net>
parents: 597
diff changeset
   875
607
cf722bff6579 Improve IQ management
Mikael Berthe <mikael@lilotux.net>
parents: 606
diff changeset
   876
    // Post-login stuff
cf722bff6579 Improve IQ management
Mikael Berthe <mikael@lilotux.net>
parents: 606
diff changeset
   877
    // Usually we request the roster only at connection time
cf722bff6579 Improve IQ management
Mikael Berthe <mikael@lilotux.net>
parents: 606
diff changeset
   878
    // so we should be there only once.  (That's ugly, however)
1014
99c5278bf6b8 Keep the status and status messages when we're disconnected
Mikael Berthe <mikael@lilotux.net>
parents: 1008
diff changeset
   879
    jb_setprevstatus();
577
5c6d364130ee Move IQ Jabber stuff to a separate file
Mikael Berthe <mikael@lilotux.net>
parents: 576
diff changeset
   880
  }
426
2706ef3e25a7 Better handling of server error codes/messages
Mikael Berthe <mikael@lilotux.net>
parents: 421
diff changeset
   881
}
2706ef3e25a7 Better handling of server error codes/messages
Mikael Berthe <mikael@lilotux.net>
parents: 421
diff changeset
   882
1158
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
   883
// FIXME  highly duplicated code
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
   884
static void send_iq_not_implemented(jconn conn, char *from, xmlnode xmldata)
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
   885
{
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
   886
  xmlnode x, y, z;
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
   887
  // Not implemented.
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
   888
  x = xmlnode_dup(xmldata);
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
   889
  xmlnode_put_attrib(x, "to", xmlnode_get_attrib(xmldata, "from"));
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
   890
  xmlnode_hide_attrib(x, "from");
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
   891
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
   892
  xmlnode_put_attrib(x, "type", TMSG_ERROR);
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
   893
  y = xmlnode_insert_tag(x, TMSG_ERROR);
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
   894
  xmlnode_put_attrib(y, "code", "501");
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
   895
  xmlnode_put_attrib(y, "type", "cancel");
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
   896
  z = xmlnode_insert_tag(y, "feature-not-implemented");
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
   897
  xmlnode_put_attrib(z, "xmlns", NS_XMPP_STANZAS);
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
   898
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
   899
  jab_send(conn, x);
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
   900
  xmlnode_free(x);
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
   901
}
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
   902
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
   903
/*
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
   904
static void send_iq_commands_bad_action(jconn conn, char *from, xmlnode xmldata)
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
   905
{
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
   906
  xmlnode x, y, z;
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
   907
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
   908
  x = xmlnode_dup(xmldata);
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
   909
  xmlnode_put_attrib(x, "to", xmlnode_get_attrib(xmldata, "from"));
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
   910
  xmlnode_hide_attrib(x, "from");
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
   911
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
   912
  xmlnode_put_attrib(x, "type", TMSG_ERROR);
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
   913
  y = xmlnode_insert_tag(x, TMSG_ERROR);
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
   914
  xmlnode_put_attrib(y, "code", "400");
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
   915
  xmlnode_put_attrib(y, "type", "modify");
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
   916
  z = xmlnode_insert_tag(y, "bad-request");
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
   917
  xmlnode_put_attrib(z, "xmlns", NS_XMPP_STANZAS);
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
   918
  z = xmlnode_insert_tag(y, "bad-action");
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
   919
  xmlnode_put_attrib(z, "xmlns", NS_COMMANDS);
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
   920
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
   921
  jab_send(conn, x);
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
   922
  xmlnode_free(x);
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
   923
}
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
   924
*/
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
   925
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
   926
static void send_iq_forbidden(jconn conn, char *from, xmlnode xmldata)
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
   927
{
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
   928
  xmlnode x, y, z;
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
   929
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
   930
  x = xmlnode_dup(xmldata);
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
   931
  xmlnode_put_attrib(x, "to", xmlnode_get_attrib(xmldata, "from"));
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
   932
  xmlnode_hide_attrib(x, "from");
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
   933
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
   934
  xmlnode_put_attrib(x, "type", TMSG_ERROR);
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
   935
  y = xmlnode_insert_tag(x, TMSG_ERROR);
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
   936
  xmlnode_put_attrib(y, "code", "403");
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
   937
  xmlnode_put_attrib(y, "type", "cancel");
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
   938
  z = xmlnode_insert_tag(y, "forbidden");
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
   939
  xmlnode_put_attrib(z, "xmlns", NS_XMPP_STANZAS);
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
   940
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
   941
  jab_send(conn, x);
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
   942
  xmlnode_free(x);
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
   943
}
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
   944
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
   945
static void send_iq_commands_malformed_action(jconn conn, char *from,
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
   946
                                              xmlnode xmldata)
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
   947
{
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
   948
  xmlnode x, y, z;
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
   949
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
   950
  x = xmlnode_dup(xmldata);
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
   951
  xmlnode_put_attrib(x, "to", xmlnode_get_attrib(xmldata, "from"));
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
   952
  xmlnode_hide_attrib(x, "from");
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
   953
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
   954
  xmlnode_put_attrib(x, "type", TMSG_ERROR);
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
   955
  y = xmlnode_insert_tag(x, TMSG_ERROR);
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
   956
  xmlnode_put_attrib(y, "code", "400");
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
   957
  xmlnode_put_attrib(y, "type", "modify");
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
   958
  z = xmlnode_insert_tag(y, "bad-request");
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
   959
  xmlnode_put_attrib(z, "xmlns", NS_XMPP_STANZAS);
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
   960
  z = xmlnode_insert_tag(y, "malformed-action");
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
   961
  xmlnode_put_attrib(z, "xmlns", NS_COMMANDS);
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
   962
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
   963
  jab_send(conn, x);
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
   964
  xmlnode_free(x);
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
   965
}
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
   966
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
   967
static void handle_iq_commands_list(jconn conn, char *from, const char *id,
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
   968
                                    xmlnode xmldata)
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
   969
{
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
   970
  xmlnode x;
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
   971
  xmlnode myquery;
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
   972
  jid requester_jid;
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
   973
  const struct adhoc_command *command;
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
   974
  bool from_self;
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
   975
  x = jutil_iqnew(JPACKET__RESULT, NS_DISCO_ITEMS);
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
   976
  xmlnode_put_attrib(x, "id", id);
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
   977
  xmlnode_put_attrib(x, "to", xmlnode_get_attrib(xmldata, "from"));
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
   978
  myquery = xmlnode_get_tag(x, "query");
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
   979
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
   980
  requester_jid = jid_new(conn->p, xmlnode_get_attrib(xmldata, "from"));
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
   981
  from_self = !jid_cmpx(conn->user, requester_jid, JID_USER | JID_SERVER);
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
   982
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
   983
  for (command = adhoc_command_list ; command->name ; command++) {
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
   984
    if (!command->only_for_self || from_self) {
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
   985
      xmlnode item;
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
   986
      item = xmlnode_insert_tag(myquery, "item");
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
   987
      xmlnode_put_attrib(item, "node", command->name);
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
   988
      xmlnode_put_attrib(item, "name", command->description);
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
   989
      xmlnode_put_attrib(item, "jid", jid_full(conn->user));
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
   990
    }
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
   991
  }
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
   992
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
   993
  jab_send(jc, x);
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
   994
  xmlnode_free(x);
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
   995
}
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
   996
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
   997
static void xmlnode_insert_dataform_result_message(xmlnode node, char *message)
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
   998
{
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
   999
  xmlnode x = xmlnode_insert_tag(node, "x");
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
  1000
  xmlnode_put_attrib(x, "type", "result");
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
  1001
  xmlnode_put_attrib(x, "xmlns", "jabber:x:data");
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
  1002
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
  1003
  xmlnode field = xmlnode_insert_tag(x, "field");
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
  1004
  xmlnode_put_attrib(field, "type", "text-single");
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
  1005
  xmlnode_put_attrib(field, "var", "message");
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
  1006
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
  1007
  xmlnode value = xmlnode_insert_tag(field, "value");
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
  1008
  xmlnode_insert_cdata(value, message, -1);
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
  1009
}
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
  1010
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
  1011
static char *generate_session_id(char *prefix)
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
  1012
{
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
  1013
  char *result;
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
  1014
  static int counter = 0;
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
  1015
  counter++;
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
  1016
  // TODO better use timezone ?
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
  1017
  result = g_strdup_printf("%s-%i", prefix, counter);
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
  1018
  return result;
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
  1019
}
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
  1020
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
  1021
static void handle_iq_command_set_status(jconn conn, char *from, const char *id,
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
  1022
                                          xmlnode xmldata)
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
  1023
{
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
  1024
  char *action, *node, *sessionid;
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
  1025
  xmlnode iq, command, x, y;
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
  1026
  const struct adhoc_status *s;
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
  1027
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
  1028
  x = xmlnode_get_tag(xmldata, "command");
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
  1029
  action = xmlnode_get_attrib(x, "action");
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
  1030
  node = xmlnode_get_attrib(x, "node");
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
  1031
  sessionid = xmlnode_get_attrib(x, "sessionid");
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
  1032
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
  1033
  iq = xmlnode_new_tag("iq");
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
  1034
  command = xmlnode_insert_tag(iq, "command");
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
  1035
  xmlnode_put_attrib(command, "node", node);
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
  1036
  xmlnode_put_attrib(command, "xmlns", NS_COMMANDS);
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
  1037
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
  1038
  if (!sessionid) {
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
  1039
    sessionid = generate_session_id("set-status");
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
  1040
    xmlnode_put_attrib(command, "sessionid", sessionid);
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
  1041
    g_free(sessionid);
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
  1042
    xmlnode_put_attrib(command, "status", "executing");
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
  1043
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
  1044
    x = xmlnode_insert_tag(command, "x");
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
  1045
    xmlnode_put_attrib(x, "type", "form");
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
  1046
    xmlnode_put_attrib(x, "xmlns", "jabber:x:data");
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
  1047
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
  1048
    y = xmlnode_insert_tag(x, "title");
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
  1049
    xmlnode_insert_cdata(y, "Change Status", -1);
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
  1050
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
  1051
    y = xmlnode_insert_tag(x, "instructions");
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
  1052
    xmlnode_insert_cdata(y, "Choose the status and status message", -1);
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
  1053
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
  1054
    // TODO see if factorisation is possible
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
  1055
    // (with xmlnode_insert_dataform_result_message)
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
  1056
    y = xmlnode_insert_tag(x, "field");
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
  1057
    xmlnode_put_attrib(y, "type", "hidden");
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
  1058
    xmlnode_put_attrib(y, "var", "FORM_TYPE");
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
  1059
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
  1060
    xmlnode value = xmlnode_insert_tag(y, "value");
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
  1061
    xmlnode_insert_cdata(value, "http://jabber.org/protocol/rc", -1);
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
  1062
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
  1063
    y = xmlnode_insert_tag(x, "field");
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
  1064
    xmlnode_put_attrib(y, "type", "list-single");
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
  1065
    xmlnode_put_attrib(y, "var", "status");
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
  1066
    xmlnode_put_attrib(y, "label", "Status");
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
  1067
    xmlnode_insert_tag(y, "required");
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
  1068
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
  1069
    value = xmlnode_insert_tag(y, "value");
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
  1070
    // TODO current status
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
  1071
    xmlnode_insert_cdata(value, "online", -1);
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
  1072
    for (s = adhoc_status_list; s->name; s++) {
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
  1073
        xmlnode option = xmlnode_insert_tag(y, "option");
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
  1074
        value = xmlnode_insert_tag(option, "value");
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
  1075
        xmlnode_insert_cdata(value, s->name, -1);
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
  1076
        xmlnode_put_attrib(option, "label", s->description);
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
  1077
    }
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
  1078
    // TODO add priority ?
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
  1079
    // I do not think this is useful, user should not have to care of the
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
  1080
    // priority like gossip and gajim do (misc)
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
  1081
    y = xmlnode_insert_tag(x, "field");
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
  1082
    xmlnode_put_attrib(y, "type", "text-multi");
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
  1083
    xmlnode_put_attrib(y, "var", "status-message");
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
  1084
    xmlnode_put_attrib(y, "label", "Message");
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
  1085
  }
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
  1086
  else // (if sessionid)
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
  1087
  {
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
  1088
    y = xmlnode_get_tag(x, "x?xmlns=jabber:x:data");
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
  1089
    if (y) {
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
  1090
      char *value, *message;
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
  1091
      value = xmlnode_get_tag_data(xmlnode_get_tag(y, "field?var=status"),
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
  1092
                                   "value");
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
  1093
      message = xmlnode_get_tag_data(xmlnode_get_tag(y,
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
  1094
                                   "field?var=status-message"), "value");
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
  1095
      for (s = adhoc_status_list; !s->name || strcmp(s->name, value); s++);
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
  1096
      if (s->name) {
1159
53c0c5be43fa Small fixes, typos and cleanups
Mikael Berthe <mikael@lilotux.net>
parents: 1158
diff changeset
  1097
        char *status = g_strdup_printf("%s %s", s->status,
53c0c5be43fa Small fixes, typos and cleanups
Mikael Berthe <mikael@lilotux.net>
parents: 1158
diff changeset
  1098
                                       message ? message : "");
1158
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
  1099
        setstatus(NULL, status);
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
  1100
        g_free(status);
1159
53c0c5be43fa Small fixes, typos and cleanups
Mikael Berthe <mikael@lilotux.net>
parents: 1158
diff changeset
  1101
        xmlnode_put_attrib(command, "status", "completed");
1158
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
  1102
        xmlnode_put_attrib(iq, "type", "result");
1159
53c0c5be43fa Small fixes, typos and cleanups
Mikael Berthe <mikael@lilotux.net>
parents: 1158
diff changeset
  1103
        xmlnode_insert_dataform_result_message(command,
53c0c5be43fa Small fixes, typos and cleanups
Mikael Berthe <mikael@lilotux.net>
parents: 1158
diff changeset
  1104
                                               "Status has been changed");
1158
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
  1105
      }
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
  1106
    }
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
  1107
  }
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
  1108
  xmlnode_put_attrib(iq, "to", xmlnode_get_attrib(xmldata, "from"));
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
  1109
  xmlnode_put_attrib(iq, "id", id);
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
  1110
  jab_send(jc, iq);
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
  1111
  xmlnode_free(iq);
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
  1112
}
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
  1113
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
  1114
static void _callback_foreach_buddy_groupchat(gpointer rosterdata, void *param)
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
  1115
{
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
  1116
  xmlnode value;
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
  1117
  xmlnode *field;
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
  1118
  const char *room_jid, *nickname;
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
  1119
  char *desc;
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
  1120
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
  1121
  room_jid = buddy_getjid(rosterdata);
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
  1122
  if (!room_jid) return;
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
  1123
  nickname = buddy_getnickname(rosterdata);
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
  1124
  if (!nickname) return;
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
  1125
  field = param;
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
  1126
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
  1127
  xmlnode option = xmlnode_insert_tag(*field, "option");
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
  1128
  value = xmlnode_insert_tag(option, "value");
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
  1129
  xmlnode_insert_cdata(value, room_jid, -1);
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
  1130
  desc = g_strdup_printf("%s on %s", nickname, room_jid);
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
  1131
  xmlnode_put_attrib(option, "label", desc);
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
  1132
  g_free(desc);
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
  1133
}
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
  1134
1159
53c0c5be43fa Small fixes, typos and cleanups
Mikael Berthe <mikael@lilotux.net>
parents: 1158
diff changeset
  1135
static void handle_iq_command_leave_groupchats(jconn conn, char *from,
53c0c5be43fa Small fixes, typos and cleanups
Mikael Berthe <mikael@lilotux.net>
parents: 1158
diff changeset
  1136
                                               const char *id, xmlnode xmldata)
1158
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
  1137
{
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
  1138
  char *action, *node, *sessionid;
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
  1139
  xmlnode iq, command, x;
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
  1140
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
  1141
  x = xmlnode_get_tag(xmldata, "command");
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
  1142
  action = xmlnode_get_attrib(x, "action");
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
  1143
  node = xmlnode_get_attrib(x, "node");
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
  1144
  sessionid = xmlnode_get_attrib(x, "sessionid");
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
  1145
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
  1146
  iq = xmlnode_new_tag("iq");
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
  1147
  command = xmlnode_insert_tag(iq, "command");
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
  1148
  xmlnode_put_attrib(command, "node", node);
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
  1149
  xmlnode_put_attrib(command, "xmlns", NS_COMMANDS);
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
  1150
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
  1151
  if (!sessionid) {
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
  1152
    sessionid = generate_session_id("leave-groupchats");
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
  1153
    xmlnode_put_attrib(command, "sessionid", sessionid);
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
  1154
    g_free(sessionid);
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
  1155
    xmlnode_put_attrib(command, "status", "executing");
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
  1156
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
  1157
    x = xmlnode_insert_tag(command, "x");
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
  1158
    xmlnode_put_attrib(x, "type", "form");
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
  1159
    xmlnode_put_attrib(x, "xmlns", "jabber:x:data");
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
  1160
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
  1161
    xmlnode title = xmlnode_insert_tag(x, "title");
1159
53c0c5be43fa Small fixes, typos and cleanups
Mikael Berthe <mikael@lilotux.net>
parents: 1158
diff changeset
  1162
    xmlnode_insert_cdata(title, "Leave groupchat(s)", -1);
1158
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
  1163
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
  1164
    xmlnode instructions = xmlnode_insert_tag(x, "instructions");
1159
53c0c5be43fa Small fixes, typos and cleanups
Mikael Berthe <mikael@lilotux.net>
parents: 1158
diff changeset
  1165
    xmlnode_insert_cdata(instructions, "What groupchats do you want to leave?",
1158
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
  1166
                         -1);
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
  1167
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
  1168
    xmlnode field = xmlnode_insert_tag(x, "field");
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
  1169
    xmlnode_put_attrib(field, "type", "hidden");
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
  1170
    xmlnode_put_attrib(field, "var", "FORM_TYPE");
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
  1171
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
  1172
    xmlnode value = xmlnode_insert_tag(field, "value");
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
  1173
    xmlnode_insert_cdata(value, "http://jabber.org/protocol/rc", -1);
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
  1174
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
  1175
    field = xmlnode_insert_tag(x, "field");
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
  1176
    xmlnode_put_attrib(field, "type", "list-multi");
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
  1177
    xmlnode_put_attrib(field, "var", "groupchats");
1159
53c0c5be43fa Small fixes, typos and cleanups
Mikael Berthe <mikael@lilotux.net>
parents: 1158
diff changeset
  1178
    xmlnode_put_attrib(field, "label", "Groupchats: ");
1158
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
  1179
    xmlnode_insert_tag(field, "required");
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
  1180
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
  1181
    foreach_buddy(ROSTER_TYPE_ROOM, &_callback_foreach_buddy_groupchat, &field);
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
  1182
  }
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
  1183
  else // (if sessionid)
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
  1184
  {
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
  1185
    xmlnode form = xmlnode_get_tag(x, "x?xmlns=jabber:x:data");
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
  1186
    if (form) {
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
  1187
      xmlnode_put_attrib(command, "status", "completed");
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
  1188
      xmlnode gc = xmlnode_get_tag(form, "field?var=groupchats");
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
  1189
      xmlnode x;
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
  1190
1159
53c0c5be43fa Small fixes, typos and cleanups
Mikael Berthe <mikael@lilotux.net>
parents: 1158
diff changeset
  1191
      for (x = xmlnode_get_firstchild(gc) ; x ; x = xmlnode_get_nextsibling(x))
53c0c5be43fa Small fixes, typos and cleanups
Mikael Berthe <mikael@lilotux.net>
parents: 1158
diff changeset
  1192
      {
1158
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
  1193
        char* to_leave = xmlnode_get_tag_data(x, "value");
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
  1194
        if (to_leave) {
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
  1195
          GList* b = buddy_search_jid(to_leave);
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
  1196
          if (b)
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
  1197
            room_leave(b->data, "Asked by remote command");
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
  1198
        }
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
  1199
      }
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
  1200
      xmlnode_put_attrib(iq, "type", "result");
1159
53c0c5be43fa Small fixes, typos and cleanups
Mikael Berthe <mikael@lilotux.net>
parents: 1158
diff changeset
  1201
      xmlnode_insert_dataform_result_message(command,
53c0c5be43fa Small fixes, typos and cleanups
Mikael Berthe <mikael@lilotux.net>
parents: 1158
diff changeset
  1202
                                             "Groupchats have been left");
1158
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
  1203
    }
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
  1204
  }
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
  1205
  xmlnode_put_attrib(iq, "to", xmlnode_get_attrib(xmldata, "from"));
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
  1206
  xmlnode_put_attrib(iq, "id", id);
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
  1207
  jab_send(jc, iq);
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
  1208
  xmlnode_free(iq);
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
  1209
}
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
  1210
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
  1211
static void handle_iq_commands(jconn conn, char *from, const char *id,
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
  1212
                               xmlnode xmldata)
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
  1213
{
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
  1214
  jid requester_jid;
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
  1215
  xmlnode x;
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
  1216
  const struct adhoc_command *command;
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
  1217
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
  1218
  requester_jid = jid_new(conn->p, xmlnode_get_attrib(xmldata, "from"));
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
  1219
  x = xmlnode_get_tag(xmldata, "command");
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
  1220
  if (!jid_cmpx(conn->user, requester_jid, JID_USER | JID_SERVER) ) {
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
  1221
    char *action, *node;
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
  1222
    action = xmlnode_get_attrib(x, "action");
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
  1223
    node = xmlnode_get_attrib(x, "node");
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
  1224
    // action can be NULL, in which case it seems to take the default,
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
  1225
    // ie execute
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
  1226
    if (!action || !strcmp(action, "execute") || !strcmp(action, "cancel")
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
  1227
        || !strcmp(action, "next") || !strcmp(action, "complete")) {
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
  1228
      for (command = adhoc_command_list; command->name; command++) {
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
  1229
        if (!strcmp(node, command->name))
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
  1230
          command->callback(conn, from, id, xmldata);
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
  1231
      }
1159
53c0c5be43fa Small fixes, typos and cleanups
Mikael Berthe <mikael@lilotux.net>
parents: 1158
diff changeset
  1232
      // "prev" action will get there, as we do not implement it,
53c0c5be43fa Small fixes, typos and cleanups
Mikael Berthe <mikael@lilotux.net>
parents: 1158
diff changeset
  1233
      // and do not authorize it
1158
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
  1234
    } else {
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
  1235
      send_iq_commands_malformed_action(conn, from, xmldata);
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
  1236
    }
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
  1237
  } else {
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
  1238
    send_iq_forbidden(conn, from, xmldata);
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
  1239
  }
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
  1240
}
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
  1241
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
  1242
static void handle_iq_disco_items(jconn conn, char *from, const char *id,
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
  1243
                                  xmlnode xmldata)
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
  1244
{
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
  1245
  xmlnode x;
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
  1246
  char *node;
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
  1247
  x = xmlnode_get_tag(xmldata, "query");
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
  1248
  node = xmlnode_get_attrib(x, "node");
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
  1249
  if (node) {
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
  1250
    if (!strcmp(node, NS_COMMANDS)) {
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
  1251
      handle_iq_commands_list(conn, from, id, xmldata);
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
  1252
    } else {
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
  1253
      send_iq_not_implemented(conn, from, xmldata);
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
  1254
    }
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
  1255
  } else {
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
  1256
    // not sure about this one
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
  1257
    send_iq_not_implemented(conn, from, xmldata);
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
  1258
  }
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
  1259
}
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
  1260
995
c89e7993c4d9 Answer IQ disco#info queries
Mikael Berthe <mikael@lilotux.net>
parents: 977
diff changeset
  1261
static void handle_iq_disco_info(jconn conn, char *from, const char *id,
c89e7993c4d9 Answer IQ disco#info queries
Mikael Berthe <mikael@lilotux.net>
parents: 977
diff changeset
  1262
                                 xmlnode xmldata)
c89e7993c4d9 Answer IQ disco#info queries
Mikael Berthe <mikael@lilotux.net>
parents: 977
diff changeset
  1263
{
c89e7993c4d9 Answer IQ disco#info queries
Mikael Berthe <mikael@lilotux.net>
parents: 977
diff changeset
  1264
  xmlnode x, y;
c89e7993c4d9 Answer IQ disco#info queries
Mikael Berthe <mikael@lilotux.net>
parents: 977
diff changeset
  1265
  xmlnode myquery;
c89e7993c4d9 Answer IQ disco#info queries
Mikael Berthe <mikael@lilotux.net>
parents: 977
diff changeset
  1266
c89e7993c4d9 Answer IQ disco#info queries
Mikael Berthe <mikael@lilotux.net>
parents: 977
diff changeset
  1267
  x = jutil_iqnew(JPACKET__RESULT, NS_DISCO_INFO);
c89e7993c4d9 Answer IQ disco#info queries
Mikael Berthe <mikael@lilotux.net>
parents: 977
diff changeset
  1268
  xmlnode_put_attrib(x, "id", id);
c89e7993c4d9 Answer IQ disco#info queries
Mikael Berthe <mikael@lilotux.net>
parents: 977
diff changeset
  1269
  xmlnode_put_attrib(x, "to", xmlnode_get_attrib(xmldata, "from"));
c89e7993c4d9 Answer IQ disco#info queries
Mikael Berthe <mikael@lilotux.net>
parents: 977
diff changeset
  1270
  myquery = xmlnode_get_tag(x, "query");
c89e7993c4d9 Answer IQ disco#info queries
Mikael Berthe <mikael@lilotux.net>
parents: 977
diff changeset
  1271
c89e7993c4d9 Answer IQ disco#info queries
Mikael Berthe <mikael@lilotux.net>
parents: 977
diff changeset
  1272
  y = xmlnode_insert_tag(myquery, "identity");
c89e7993c4d9 Answer IQ disco#info queries
Mikael Berthe <mikael@lilotux.net>
parents: 977
diff changeset
  1273
  xmlnode_put_attrib(y, "category", "client");
c89e7993c4d9 Answer IQ disco#info queries
Mikael Berthe <mikael@lilotux.net>
parents: 977
diff changeset
  1274
  xmlnode_put_attrib(y, "type", "pc");
c89e7993c4d9 Answer IQ disco#info queries
Mikael Berthe <mikael@lilotux.net>
parents: 977
diff changeset
  1275
  xmlnode_put_attrib(y, "name", PACKAGE_NAME);
c89e7993c4d9 Answer IQ disco#info queries
Mikael Berthe <mikael@lilotux.net>
parents: 977
diff changeset
  1276
c89e7993c4d9 Answer IQ disco#info queries
Mikael Berthe <mikael@lilotux.net>
parents: 977
diff changeset
  1277
  xmlnode_put_attrib(xmlnode_insert_tag(myquery, "feature"),
c89e7993c4d9 Answer IQ disco#info queries
Mikael Berthe <mikael@lilotux.net>
parents: 977
diff changeset
  1278
                     "var", NS_DISCO_INFO);
c89e7993c4d9 Answer IQ disco#info queries
Mikael Berthe <mikael@lilotux.net>
parents: 977
diff changeset
  1279
  xmlnode_put_attrib(xmlnode_insert_tag(myquery, "feature"),
c89e7993c4d9 Answer IQ disco#info queries
Mikael Berthe <mikael@lilotux.net>
parents: 977
diff changeset
  1280
                     "var", NS_MUC);
c89e7993c4d9 Answer IQ disco#info queries
Mikael Berthe <mikael@lilotux.net>
parents: 977
diff changeset
  1281
  xmlnode_put_attrib(xmlnode_insert_tag(myquery, "feature"),
c89e7993c4d9 Answer IQ disco#info queries
Mikael Berthe <mikael@lilotux.net>
parents: 977
diff changeset
  1282
                     "var", NS_CHATSTATES);
c89e7993c4d9 Answer IQ disco#info queries
Mikael Berthe <mikael@lilotux.net>
parents: 977
diff changeset
  1283
  xmlnode_put_attrib(xmlnode_insert_tag(myquery, "feature"),
c89e7993c4d9 Answer IQ disco#info queries
Mikael Berthe <mikael@lilotux.net>
parents: 977
diff changeset
  1284
                     "var", NS_TIME);
c89e7993c4d9 Answer IQ disco#info queries
Mikael Berthe <mikael@lilotux.net>
parents: 977
diff changeset
  1285
  xmlnode_put_attrib(xmlnode_insert_tag(myquery, "feature"),
c89e7993c4d9 Answer IQ disco#info queries
Mikael Berthe <mikael@lilotux.net>
parents: 977
diff changeset
  1286
                     "var", NS_VERSION);
1134
995dde656033 Response to XMPP Ping (XEP-0199)
misc@mandriva.org
parents: 1058
diff changeset
  1287
  xmlnode_put_attrib(xmlnode_insert_tag(myquery, "feature"),
995dde656033 Response to XMPP Ping (XEP-0199)
misc@mandriva.org
parents: 1058
diff changeset
  1288
                     "var", NS_PING);
1158
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
  1289
  xmlnode_put_attrib(xmlnode_insert_tag(myquery, "feature"),
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
  1290
                     "var", NS_COMMANDS);
1134
995dde656033 Response to XMPP Ping (XEP-0199)
misc@mandriva.org
parents: 1058
diff changeset
  1291
  jab_send(jc, x);
995dde656033 Response to XMPP Ping (XEP-0199)
misc@mandriva.org
parents: 1058
diff changeset
  1292
  xmlnode_free(x);
995dde656033 Response to XMPP Ping (XEP-0199)
misc@mandriva.org
parents: 1058
diff changeset
  1293
}
995
c89e7993c4d9 Answer IQ disco#info queries
Mikael Berthe <mikael@lilotux.net>
parents: 977
diff changeset
  1294
1134
995dde656033 Response to XMPP Ping (XEP-0199)
misc@mandriva.org
parents: 1058
diff changeset
  1295
static void handle_iq_ping(jconn conn, char *from, const char *id,
995dde656033 Response to XMPP Ping (XEP-0199)
misc@mandriva.org
parents: 1058
diff changeset
  1296
                           xmlnode xmldata)
995dde656033 Response to XMPP Ping (XEP-0199)
misc@mandriva.org
parents: 1058
diff changeset
  1297
{
995dde656033 Response to XMPP Ping (XEP-0199)
misc@mandriva.org
parents: 1058
diff changeset
  1298
  xmlnode x;
995dde656033 Response to XMPP Ping (XEP-0199)
misc@mandriva.org
parents: 1058
diff changeset
  1299
  x = jutil_iqresult(xmldata);
995
c89e7993c4d9 Answer IQ disco#info queries
Mikael Berthe <mikael@lilotux.net>
parents: 977
diff changeset
  1300
  jab_send(jc, x);
c89e7993c4d9 Answer IQ disco#info queries
Mikael Berthe <mikael@lilotux.net>
parents: 977
diff changeset
  1301
}
c89e7993c4d9 Answer IQ disco#info queries
Mikael Berthe <mikael@lilotux.net>
parents: 977
diff changeset
  1302
619
44ddf9bec3a5 Answer IQ:version & IQ:time requests
Mikael Berthe <mikael@lilotux.net>
parents: 613
diff changeset
  1303
static void handle_iq_version(jconn conn, char *from, const char *id,
44ddf9bec3a5 Answer IQ:version & IQ:time requests
Mikael Berthe <mikael@lilotux.net>
parents: 613
diff changeset
  1304
                              xmlnode xmldata)
44ddf9bec3a5 Answer IQ:version & IQ:time requests
Mikael Berthe <mikael@lilotux.net>
parents: 613
diff changeset
  1305
{
995
c89e7993c4d9 Answer IQ disco#info queries
Mikael Berthe <mikael@lilotux.net>
parents: 977
diff changeset
  1306
  xmlnode x;
619
44ddf9bec3a5 Answer IQ:version & IQ:time requests
Mikael Berthe <mikael@lilotux.net>
parents: 613
diff changeset
  1307
  xmlnode myquery;
44ddf9bec3a5 Answer IQ:version & IQ:time requests
Mikael Berthe <mikael@lilotux.net>
parents: 613
diff changeset
  1308
  char *os = NULL;
814
109dcf5fc111 Use hgcset (if available) when answering to IQ:version requests
Mikael Berthe <mikael@lilotux.net>
parents: 782
diff changeset
  1309
  char *ver = mcabber_version();
619
44ddf9bec3a5 Answer IQ:version & IQ:time requests
Mikael Berthe <mikael@lilotux.net>
parents: 613
diff changeset
  1310
692
d3511f846d47 Cosmetics (line wrapping)
Mikael Berthe <mikael@lilotux.net>
parents: 691
diff changeset
  1311
  scr_LogPrint(LPRINT_LOGNORM, "Received an IQ version request from <%s>",
d3511f846d47 Cosmetics (line wrapping)
Mikael Berthe <mikael@lilotux.net>
parents: 691
diff changeset
  1312
               from);
619
44ddf9bec3a5 Answer IQ:version & IQ:time requests
Mikael Berthe <mikael@lilotux.net>
parents: 613
diff changeset
  1313
44ddf9bec3a5 Answer IQ:version & IQ:time requests
Mikael Berthe <mikael@lilotux.net>
parents: 613
diff changeset
  1314
  if (!settings_opt_get_int("iq_version_hide_os")) {
44ddf9bec3a5 Answer IQ:version & IQ:time requests
Mikael Berthe <mikael@lilotux.net>
parents: 613
diff changeset
  1315
    struct utsname osinfo;
44ddf9bec3a5 Answer IQ:version & IQ:time requests
Mikael Berthe <mikael@lilotux.net>
parents: 613
diff changeset
  1316
    uname(&osinfo);
44ddf9bec3a5 Answer IQ:version & IQ:time requests
Mikael Berthe <mikael@lilotux.net>
parents: 613
diff changeset
  1317
    os = g_strdup_printf("%s %s %s", osinfo.sysname, osinfo.release,
44ddf9bec3a5 Answer IQ:version & IQ:time requests
Mikael Berthe <mikael@lilotux.net>
parents: 613
diff changeset
  1318
                         osinfo.machine);
44ddf9bec3a5 Answer IQ:version & IQ:time requests
Mikael Berthe <mikael@lilotux.net>
parents: 613
diff changeset
  1319
  }
44ddf9bec3a5 Answer IQ:version & IQ:time requests
Mikael Berthe <mikael@lilotux.net>
parents: 613
diff changeset
  1320
44ddf9bec3a5 Answer IQ:version & IQ:time requests
Mikael Berthe <mikael@lilotux.net>
parents: 613
diff changeset
  1321
  x = jutil_iqnew(JPACKET__RESULT, NS_VERSION);
44ddf9bec3a5 Answer IQ:version & IQ:time requests
Mikael Berthe <mikael@lilotux.net>
parents: 613
diff changeset
  1322
  xmlnode_put_attrib(x, "id", id);
44ddf9bec3a5 Answer IQ:version & IQ:time requests
Mikael Berthe <mikael@lilotux.net>
parents: 613
diff changeset
  1323
  xmlnode_put_attrib(x, "to", xmlnode_get_attrib(xmldata, "from"));
44ddf9bec3a5 Answer IQ:version & IQ:time requests
Mikael Berthe <mikael@lilotux.net>
parents: 613
diff changeset
  1324
  myquery = xmlnode_get_tag(x, "query");
44ddf9bec3a5 Answer IQ:version & IQ:time requests
Mikael Berthe <mikael@lilotux.net>
parents: 613
diff changeset
  1325
814
109dcf5fc111 Use hgcset (if available) when answering to IQ:version requests
Mikael Berthe <mikael@lilotux.net>
parents: 782
diff changeset
  1326
  xmlnode_insert_cdata(xmlnode_insert_tag(myquery, "name"), PACKAGE_NAME, -1);
109dcf5fc111 Use hgcset (if available) when answering to IQ:version requests
Mikael Berthe <mikael@lilotux.net>
parents: 782
diff changeset
  1327
  xmlnode_insert_cdata(xmlnode_insert_tag(myquery, "version"), ver, -1);
619
44ddf9bec3a5 Answer IQ:version & IQ:time requests
Mikael Berthe <mikael@lilotux.net>
parents: 613
diff changeset
  1328
  if (os) {
44ddf9bec3a5 Answer IQ:version & IQ:time requests
Mikael Berthe <mikael@lilotux.net>
parents: 613
diff changeset
  1329
    xmlnode_insert_cdata(xmlnode_insert_tag(myquery, "os"), os, -1);
44ddf9bec3a5 Answer IQ:version & IQ:time requests
Mikael Berthe <mikael@lilotux.net>
parents: 613
diff changeset
  1330
    g_free(os);
44ddf9bec3a5 Answer IQ:version & IQ:time requests
Mikael Berthe <mikael@lilotux.net>
parents: 613
diff changeset
  1331
  }
44ddf9bec3a5 Answer IQ:version & IQ:time requests
Mikael Berthe <mikael@lilotux.net>
parents: 613
diff changeset
  1332
814
109dcf5fc111 Use hgcset (if available) when answering to IQ:version requests
Mikael Berthe <mikael@lilotux.net>
parents: 782
diff changeset
  1333
  g_free(ver);
619
44ddf9bec3a5 Answer IQ:version & IQ:time requests
Mikael Berthe <mikael@lilotux.net>
parents: 613
diff changeset
  1334
  jab_send(jc, x);
44ddf9bec3a5 Answer IQ:version & IQ:time requests
Mikael Berthe <mikael@lilotux.net>
parents: 613
diff changeset
  1335
  xmlnode_free(x);
44ddf9bec3a5 Answer IQ:version & IQ:time requests
Mikael Berthe <mikael@lilotux.net>
parents: 613
diff changeset
  1336
}
44ddf9bec3a5 Answer IQ:version & IQ:time requests
Mikael Berthe <mikael@lilotux.net>
parents: 613
diff changeset
  1337
44ddf9bec3a5 Answer IQ:version & IQ:time requests
Mikael Berthe <mikael@lilotux.net>
parents: 613
diff changeset
  1338
// This function borrows some code from the Gaim project
44ddf9bec3a5 Answer IQ:version & IQ:time requests
Mikael Berthe <mikael@lilotux.net>
parents: 613
diff changeset
  1339
static void handle_iq_time(jconn conn, char *from, const char *id,
44ddf9bec3a5 Answer IQ:version & IQ:time requests
Mikael Berthe <mikael@lilotux.net>
parents: 613
diff changeset
  1340
                              xmlnode xmldata)
44ddf9bec3a5 Answer IQ:version & IQ:time requests
Mikael Berthe <mikael@lilotux.net>
parents: 613
diff changeset
  1341
{
995
c89e7993c4d9 Answer IQ disco#info queries
Mikael Berthe <mikael@lilotux.net>
parents: 977
diff changeset
  1342
  xmlnode x;
619
44ddf9bec3a5 Answer IQ:version & IQ:time requests
Mikael Berthe <mikael@lilotux.net>
parents: 613
diff changeset
  1343
  xmlnode myquery;
44ddf9bec3a5 Answer IQ:version & IQ:time requests
Mikael Berthe <mikael@lilotux.net>
parents: 613
diff changeset
  1344
  char *buf, *utf8_buf;
44ddf9bec3a5 Answer IQ:version & IQ:time requests
Mikael Berthe <mikael@lilotux.net>
parents: 613
diff changeset
  1345
  time_t now_t;
44ddf9bec3a5 Answer IQ:version & IQ:time requests
Mikael Berthe <mikael@lilotux.net>
parents: 613
diff changeset
  1346
  struct tm *now;
44ddf9bec3a5 Answer IQ:version & IQ:time requests
Mikael Berthe <mikael@lilotux.net>
parents: 613
diff changeset
  1347
44ddf9bec3a5 Answer IQ:version & IQ:time requests
Mikael Berthe <mikael@lilotux.net>
parents: 613
diff changeset
  1348
  time(&now_t);
44ddf9bec3a5 Answer IQ:version & IQ:time requests
Mikael Berthe <mikael@lilotux.net>
parents: 613
diff changeset
  1349
44ddf9bec3a5 Answer IQ:version & IQ:time requests
Mikael Berthe <mikael@lilotux.net>
parents: 613
diff changeset
  1350
  scr_LogPrint(LPRINT_LOGNORM, "Received an IQ time request from <%s>", from);
44ddf9bec3a5 Answer IQ:version & IQ:time requests
Mikael Berthe <mikael@lilotux.net>
parents: 613
diff changeset
  1351
44ddf9bec3a5 Answer IQ:version & IQ:time requests
Mikael Berthe <mikael@lilotux.net>
parents: 613
diff changeset
  1352
  buf = g_new0(char, 512);
44ddf9bec3a5 Answer IQ:version & IQ:time requests
Mikael Berthe <mikael@lilotux.net>
parents: 613
diff changeset
  1353
44ddf9bec3a5 Answer IQ:version & IQ:time requests
Mikael Berthe <mikael@lilotux.net>
parents: 613
diff changeset
  1354
  x = jutil_iqnew(JPACKET__RESULT, NS_TIME);
44ddf9bec3a5 Answer IQ:version & IQ:time requests
Mikael Berthe <mikael@lilotux.net>
parents: 613
diff changeset
  1355
  xmlnode_put_attrib(x, "id", id);
44ddf9bec3a5 Answer IQ:version & IQ:time requests
Mikael Berthe <mikael@lilotux.net>
parents: 613
diff changeset
  1356
  xmlnode_put_attrib(x, "to", xmlnode_get_attrib(xmldata, "from"));
44ddf9bec3a5 Answer IQ:version & IQ:time requests
Mikael Berthe <mikael@lilotux.net>
parents: 613
diff changeset
  1357
  myquery = xmlnode_get_tag(x, "query");
44ddf9bec3a5 Answer IQ:version & IQ:time requests
Mikael Berthe <mikael@lilotux.net>
parents: 613
diff changeset
  1358
703
8cbcbff8de7d Fix UTC time in IQ:version queries
Mikael Berthe <mikael@lilotux.net>
parents: 699
diff changeset
  1359
  now = gmtime(&now_t);
8cbcbff8de7d Fix UTC time in IQ:version queries
Mikael Berthe <mikael@lilotux.net>
parents: 699
diff changeset
  1360
619
44ddf9bec3a5 Answer IQ:version & IQ:time requests
Mikael Berthe <mikael@lilotux.net>
parents: 613
diff changeset
  1361
  strftime(buf, 512, "%Y%m%dT%T", now);
44ddf9bec3a5 Answer IQ:version & IQ:time requests
Mikael Berthe <mikael@lilotux.net>
parents: 613
diff changeset
  1362
  xmlnode_insert_cdata(xmlnode_insert_tag(myquery, "utc"), buf, -1);
44ddf9bec3a5 Answer IQ:version & IQ:time requests
Mikael Berthe <mikael@lilotux.net>
parents: 613
diff changeset
  1363
703
8cbcbff8de7d Fix UTC time in IQ:version queries
Mikael Berthe <mikael@lilotux.net>
parents: 699
diff changeset
  1364
  now = localtime(&now_t);
8cbcbff8de7d Fix UTC time in IQ:version queries
Mikael Berthe <mikael@lilotux.net>
parents: 699
diff changeset
  1365
619
44ddf9bec3a5 Answer IQ:version & IQ:time requests
Mikael Berthe <mikael@lilotux.net>
parents: 613
diff changeset
  1366
  strftime(buf, 512, "%Z", now);
44ddf9bec3a5 Answer IQ:version & IQ:time requests
Mikael Berthe <mikael@lilotux.net>
parents: 613
diff changeset
  1367
  if ((utf8_buf = to_utf8(buf))) {
44ddf9bec3a5 Answer IQ:version & IQ:time requests
Mikael Berthe <mikael@lilotux.net>
parents: 613
diff changeset
  1368
    xmlnode_insert_cdata(xmlnode_insert_tag(myquery, "tz"), utf8_buf, -1);
44ddf9bec3a5 Answer IQ:version & IQ:time requests
Mikael Berthe <mikael@lilotux.net>
parents: 613
diff changeset
  1369
    g_free(utf8_buf);
44ddf9bec3a5 Answer IQ:version & IQ:time requests
Mikael Berthe <mikael@lilotux.net>
parents: 613
diff changeset
  1370
  }
44ddf9bec3a5 Answer IQ:version & IQ:time requests
Mikael Berthe <mikael@lilotux.net>
parents: 613
diff changeset
  1371
44ddf9bec3a5 Answer IQ:version & IQ:time requests
Mikael Berthe <mikael@lilotux.net>
parents: 613
diff changeset
  1372
  strftime(buf, 512, "%d %b %Y %T", now);
44ddf9bec3a5 Answer IQ:version & IQ:time requests
Mikael Berthe <mikael@lilotux.net>
parents: 613
diff changeset
  1373
  if ((utf8_buf = to_utf8(buf))) {
44ddf9bec3a5 Answer IQ:version & IQ:time requests
Mikael Berthe <mikael@lilotux.net>
parents: 613
diff changeset
  1374
    xmlnode_insert_cdata(xmlnode_insert_tag(myquery, "display"), utf8_buf, -1);
44ddf9bec3a5 Answer IQ:version & IQ:time requests
Mikael Berthe <mikael@lilotux.net>
parents: 613
diff changeset
  1375
    g_free(utf8_buf);
44ddf9bec3a5 Answer IQ:version & IQ:time requests
Mikael Berthe <mikael@lilotux.net>
parents: 613
diff changeset
  1376
  }
44ddf9bec3a5 Answer IQ:version & IQ:time requests
Mikael Berthe <mikael@lilotux.net>
parents: 613
diff changeset
  1377
44ddf9bec3a5 Answer IQ:version & IQ:time requests
Mikael Berthe <mikael@lilotux.net>
parents: 613
diff changeset
  1378
  jab_send(jc, x);
44ddf9bec3a5 Answer IQ:version & IQ:time requests
Mikael Berthe <mikael@lilotux.net>
parents: 613
diff changeset
  1379
  xmlnode_free(x);
44ddf9bec3a5 Answer IQ:version & IQ:time requests
Mikael Berthe <mikael@lilotux.net>
parents: 613
diff changeset
  1380
  g_free(buf);
44ddf9bec3a5 Answer IQ:version & IQ:time requests
Mikael Berthe <mikael@lilotux.net>
parents: 613
diff changeset
  1381
}
44ddf9bec3a5 Answer IQ:version & IQ:time requests
Mikael Berthe <mikael@lilotux.net>
parents: 613
diff changeset
  1382
44ddf9bec3a5 Answer IQ:version & IQ:time requests
Mikael Berthe <mikael@lilotux.net>
parents: 613
diff changeset
  1383
// This function borrows some code from the Gaim project
577
5c6d364130ee Move IQ Jabber stuff to a separate file
Mikael Berthe <mikael@lilotux.net>
parents: 576
diff changeset
  1384
static void handle_iq_get(jconn conn, char *from, xmlnode xmldata)
31
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
  1385
{
619
44ddf9bec3a5 Answer IQ:version & IQ:time requests
Mikael Berthe <mikael@lilotux.net>
parents: 613
diff changeset
  1386
  const char *id, *ns;
1158
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
  1387
  xmlnode x;
619
44ddf9bec3a5 Answer IQ:version & IQ:time requests
Mikael Berthe <mikael@lilotux.net>
parents: 613
diff changeset
  1388
  guint iq_not_implemented = FALSE;
31
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
  1389
577
5c6d364130ee Move IQ Jabber stuff to a separate file
Mikael Berthe <mikael@lilotux.net>
parents: 576
diff changeset
  1390
  id = xmlnode_get_attrib(xmldata, "id");
607
cf722bff6579 Improve IQ management
Mikael Berthe <mikael@lilotux.net>
parents: 606
diff changeset
  1391
  if (!id) {
cf722bff6579 Improve IQ management
Mikael Berthe <mikael@lilotux.net>
parents: 606
diff changeset
  1392
    scr_LogPrint(LPRINT_LOG, "IQ get stanza with no ID, ignored.");
cf722bff6579 Improve IQ management
Mikael Berthe <mikael@lilotux.net>
parents: 606
diff changeset
  1393
    return;
cf722bff6579 Improve IQ management
Mikael Berthe <mikael@lilotux.net>
parents: 606
diff changeset
  1394
  }
31
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
  1395
1134
995dde656033 Response to XMPP Ping (XEP-0199)
misc@mandriva.org
parents: 1058
diff changeset
  1396
  x = xmlnode_get_tag(xmldata, "ping");
995dde656033 Response to XMPP Ping (XEP-0199)
misc@mandriva.org
parents: 1058
diff changeset
  1397
  ns = xmlnode_get_attrib(x, "xmlns");
995dde656033 Response to XMPP Ping (XEP-0199)
misc@mandriva.org
parents: 1058
diff changeset
  1398
  if (ns && !strcmp(ns, NS_PING)) {
995dde656033 Response to XMPP Ping (XEP-0199)
misc@mandriva.org
parents: 1058
diff changeset
  1399
    handle_iq_ping(conn, from, id, xmldata);
995dde656033 Response to XMPP Ping (XEP-0199)
misc@mandriva.org
parents: 1058
diff changeset
  1400
    return;
995dde656033 Response to XMPP Ping (XEP-0199)
misc@mandriva.org
parents: 1058
diff changeset
  1401
  }
995dde656033 Response to XMPP Ping (XEP-0199)
misc@mandriva.org
parents: 1058
diff changeset
  1402
619
44ddf9bec3a5 Answer IQ:version & IQ:time requests
Mikael Berthe <mikael@lilotux.net>
parents: 613
diff changeset
  1403
  x = xmlnode_get_tag(xmldata, "query");
44ddf9bec3a5 Answer IQ:version & IQ:time requests
Mikael Berthe <mikael@lilotux.net>
parents: 613
diff changeset
  1404
  ns = xmlnode_get_attrib(x, "xmlns");
995
c89e7993c4d9 Answer IQ disco#info queries
Mikael Berthe <mikael@lilotux.net>
parents: 977
diff changeset
  1405
  if (ns && !strcmp(ns, NS_DISCO_INFO)) {
c89e7993c4d9 Answer IQ disco#info queries
Mikael Berthe <mikael@lilotux.net>
parents: 977
diff changeset
  1406
    handle_iq_disco_info(conn, from, id, xmldata);
1158
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
  1407
  } else if (ns && !strcmp(ns, NS_DISCO_ITEMS)) {
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
  1408
    handle_iq_disco_items(conn, from, id, xmldata);
995
c89e7993c4d9 Answer IQ disco#info queries
Mikael Berthe <mikael@lilotux.net>
parents: 977
diff changeset
  1409
  } else if (ns && !strcmp(ns, NS_VERSION)) {
619
44ddf9bec3a5 Answer IQ:version & IQ:time requests
Mikael Berthe <mikael@lilotux.net>
parents: 613
diff changeset
  1410
    handle_iq_version(conn, from, id, xmldata);
44ddf9bec3a5 Answer IQ:version & IQ:time requests
Mikael Berthe <mikael@lilotux.net>
parents: 613
diff changeset
  1411
  } else if (ns && !strcmp(ns, NS_TIME)) {
44ddf9bec3a5 Answer IQ:version & IQ:time requests
Mikael Berthe <mikael@lilotux.net>
parents: 613
diff changeset
  1412
    handle_iq_time(conn, from, id, xmldata);
44ddf9bec3a5 Answer IQ:version & IQ:time requests
Mikael Berthe <mikael@lilotux.net>
parents: 613
diff changeset
  1413
  } else {
44ddf9bec3a5 Answer IQ:version & IQ:time requests
Mikael Berthe <mikael@lilotux.net>
parents: 613
diff changeset
  1414
    iq_not_implemented = TRUE;
44ddf9bec3a5 Answer IQ:version & IQ:time requests
Mikael Berthe <mikael@lilotux.net>
parents: 613
diff changeset
  1415
  }
44ddf9bec3a5 Answer IQ:version & IQ:time requests
Mikael Berthe <mikael@lilotux.net>
parents: 613
diff changeset
  1416
44ddf9bec3a5 Answer IQ:version & IQ:time requests
Mikael Berthe <mikael@lilotux.net>
parents: 613
diff changeset
  1417
  if (!iq_not_implemented)
44ddf9bec3a5 Answer IQ:version & IQ:time requests
Mikael Berthe <mikael@lilotux.net>
parents: 613
diff changeset
  1418
    return;
44ddf9bec3a5 Answer IQ:version & IQ:time requests
Mikael Berthe <mikael@lilotux.net>
parents: 613
diff changeset
  1419
1158
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
  1420
  send_iq_not_implemented(conn, from, xmldata);
31
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
  1421
}
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
  1422
577
5c6d364130ee Move IQ Jabber stuff to a separate file
Mikael Berthe <mikael@lilotux.net>
parents: 576
diff changeset
  1423
static void handle_iq_set(jconn conn, char *from, xmlnode xmldata)
547
1df26ff0ed8c Break packethandler() out
Mikael Berthe <mikael@lilotux.net>
parents: 539
diff changeset
  1424
{
619
44ddf9bec3a5 Answer IQ:version & IQ:time requests
Mikael Berthe <mikael@lilotux.net>
parents: 613
diff changeset
  1425
  const char *id, *ns;
1158
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
  1426
  xmlnode x;
619
44ddf9bec3a5 Answer IQ:version & IQ:time requests
Mikael Berthe <mikael@lilotux.net>
parents: 613
diff changeset
  1427
  guint iq_not_implemented = FALSE;
595
0c1d37300862 IQ: send feature-not-implemented error stanzas
Mikael Berthe <mikael@lilotux.net>
parents: 582
diff changeset
  1428
0c1d37300862 IQ: send feature-not-implemented error stanzas
Mikael Berthe <mikael@lilotux.net>
parents: 582
diff changeset
  1429
  id = xmlnode_get_attrib(xmldata, "id");
607
cf722bff6579 Improve IQ management
Mikael Berthe <mikael@lilotux.net>
parents: 606
diff changeset
  1430
  if (!id)
cf722bff6579 Improve IQ management
Mikael Berthe <mikael@lilotux.net>
parents: 606
diff changeset
  1431
    scr_LogPrint(LPRINT_LOG, "IQ set stanza with no ID...");
cf722bff6579 Improve IQ management
Mikael Berthe <mikael@lilotux.net>
parents: 606
diff changeset
  1432
cf722bff6579 Improve IQ management
Mikael Berthe <mikael@lilotux.net>
parents: 606
diff changeset
  1433
  x = xmlnode_get_tag(xmldata, "query");
cf722bff6579 Improve IQ management
Mikael Berthe <mikael@lilotux.net>
parents: 606
diff changeset
  1434
  ns = xmlnode_get_attrib(x, "xmlns");
cf722bff6579 Improve IQ management
Mikael Berthe <mikael@lilotux.net>
parents: 606
diff changeset
  1435
  if (ns && !strcmp(ns, NS_ROSTER)) {
cf722bff6579 Improve IQ management
Mikael Berthe <mikael@lilotux.net>
parents: 606
diff changeset
  1436
    handle_iq_roster(x);
cf722bff6579 Improve IQ management
Mikael Berthe <mikael@lilotux.net>
parents: 606
diff changeset
  1437
  } else {
1158
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
  1438
    x = xmlnode_get_tag(xmldata, "command");
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
  1439
    ns = xmlnode_get_attrib(x, "xmlns");
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
  1440
    if (ns && !strcmp(ns, NS_COMMANDS)) {
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
  1441
      handle_iq_commands(conn, from, id, xmldata);
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
  1442
    } else {
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
  1443
      iq_not_implemented = TRUE;
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
  1444
    }
607
cf722bff6579 Improve IQ management
Mikael Berthe <mikael@lilotux.net>
parents: 606
diff changeset
  1445
  }
cf722bff6579 Improve IQ management
Mikael Berthe <mikael@lilotux.net>
parents: 606
diff changeset
  1446
595
0c1d37300862 IQ: send feature-not-implemented error stanzas
Mikael Berthe <mikael@lilotux.net>
parents: 582
diff changeset
  1447
  if (!id) return;
0c1d37300862 IQ: send feature-not-implemented error stanzas
Mikael Berthe <mikael@lilotux.net>
parents: 582
diff changeset
  1448
619
44ddf9bec3a5 Answer IQ:version & IQ:time requests
Mikael Berthe <mikael@lilotux.net>
parents: 613
diff changeset
  1449
  if (!iq_not_implemented) {
607
cf722bff6579 Improve IQ management
Mikael Berthe <mikael@lilotux.net>
parents: 606
diff changeset
  1450
    x = xmlnode_new_tag("iq");
cf722bff6579 Improve IQ management
Mikael Berthe <mikael@lilotux.net>
parents: 606
diff changeset
  1451
    xmlnode_put_attrib(x, "to", xmlnode_get_attrib(xmldata, "from"));
cf722bff6579 Improve IQ management
Mikael Berthe <mikael@lilotux.net>
parents: 606
diff changeset
  1452
    xmlnode_put_attrib(x, "type", "result");
cf722bff6579 Improve IQ management
Mikael Berthe <mikael@lilotux.net>
parents: 606
diff changeset
  1453
    xmlnode_put_attrib(x, "id", id);
1158
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
  1454
    jab_send(conn, x);
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
  1455
    xmlnode_free(x);
607
cf722bff6579 Improve IQ management
Mikael Berthe <mikael@lilotux.net>
parents: 606
diff changeset
  1456
  } else {
1158
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
  1457
    send_iq_not_implemented(conn, from, xmldata);
607
cf722bff6579 Improve IQ management
Mikael Berthe <mikael@lilotux.net>
parents: 606
diff changeset
  1458
  }
577
5c6d364130ee Move IQ Jabber stuff to a separate file
Mikael Berthe <mikael@lilotux.net>
parents: 576
diff changeset
  1459
}
547
1df26ff0ed8c Break packethandler() out
Mikael Berthe <mikael@lilotux.net>
parents: 539
diff changeset
  1460
577
5c6d364130ee Move IQ Jabber stuff to a separate file
Mikael Berthe <mikael@lilotux.net>
parents: 576
diff changeset
  1461
void handle_packet_iq(jconn conn, char *type, char *from, xmlnode xmldata)
5c6d364130ee Move IQ Jabber stuff to a separate file
Mikael Berthe <mikael@lilotux.net>
parents: 576
diff changeset
  1462
{
547
1df26ff0ed8c Break packethandler() out
Mikael Berthe <mikael@lilotux.net>
parents: 539
diff changeset
  1463
  if (!type)
1df26ff0ed8c Break packethandler() out
Mikael Berthe <mikael@lilotux.net>
parents: 539
diff changeset
  1464
    return;
1df26ff0ed8c Break packethandler() out
Mikael Berthe <mikael@lilotux.net>
parents: 539
diff changeset
  1465
1df26ff0ed8c Break packethandler() out
Mikael Berthe <mikael@lilotux.net>
parents: 539
diff changeset
  1466
  if (!strcmp(type, "result")) {
577
5c6d364130ee Move IQ Jabber stuff to a separate file
Mikael Berthe <mikael@lilotux.net>
parents: 576
diff changeset
  1467
    handle_iq_result(conn, from, xmldata);
547
1df26ff0ed8c Break packethandler() out
Mikael Berthe <mikael@lilotux.net>
parents: 539
diff changeset
  1468
  } else if (!strcmp(type, "get")) {
577
5c6d364130ee Move IQ Jabber stuff to a separate file
Mikael Berthe <mikael@lilotux.net>
parents: 576
diff changeset
  1469
    handle_iq_get(conn, from, xmldata);
547
1df26ff0ed8c Break packethandler() out
Mikael Berthe <mikael@lilotux.net>
parents: 539
diff changeset
  1470
  } else if (!strcmp(type, "set")) {
577
5c6d364130ee Move IQ Jabber stuff to a separate file
Mikael Berthe <mikael@lilotux.net>
parents: 576
diff changeset
  1471
    handle_iq_set(conn, from, xmldata);
547
1df26ff0ed8c Break packethandler() out
Mikael Berthe <mikael@lilotux.net>
parents: 539
diff changeset
  1472
  } else if (!strcmp(type, TMSG_ERROR)) {
1213
4a7db2870685 Improve Private Storage detection.
Mikael Berthe <mikael@lilotux.net>
parents: 1205
diff changeset
  1473
    // Display a message only if the error isn't caught by a callback.
577
5c6d364130ee Move IQ Jabber stuff to a separate file
Mikael Berthe <mikael@lilotux.net>
parents: 576
diff changeset
  1474
    xmlnode x = xmlnode_get_tag(xmldata, TMSG_ERROR);
1213
4a7db2870685 Improve Private Storage detection.
Mikael Berthe <mikael@lilotux.net>
parents: 1205
diff changeset
  1475
    if (iqs_callback(xmlnode_get_attrib(xmldata, "id"), x, IQS_CONTEXT_ERROR))
547
1df26ff0ed8c Break packethandler() out
Mikael Berthe <mikael@lilotux.net>
parents: 539
diff changeset
  1476
      display_server_error(x);
1df26ff0ed8c Break packethandler() out
Mikael Berthe <mikael@lilotux.net>
parents: 539
diff changeset
  1477
  }
1df26ff0ed8c Break packethandler() out
Mikael Berthe <mikael@lilotux.net>
parents: 539
diff changeset
  1478
}
1df26ff0ed8c Break packethandler() out
Mikael Berthe <mikael@lilotux.net>
parents: 539
diff changeset
  1479
1008
bbf53cd43fbb Functions to update room bookmarks
Mikael Berthe <mikael@lilotux.net>
parents: 1006
diff changeset
  1480
//  send_storage_bookmarks()
bbf53cd43fbb Functions to update room bookmarks
Mikael Berthe <mikael@lilotux.net>
parents: 1006
diff changeset
  1481
// Send the current bookmarks node to update the server.
bbf53cd43fbb Functions to update room bookmarks
Mikael Berthe <mikael@lilotux.net>
parents: 1006
diff changeset
  1482
// Note: the sender should check we're online.
bbf53cd43fbb Functions to update room bookmarks
Mikael Berthe <mikael@lilotux.net>
parents: 1006
diff changeset
  1483
void send_storage_bookmarks(void)
bbf53cd43fbb Functions to update room bookmarks
Mikael Berthe <mikael@lilotux.net>
parents: 1006
diff changeset
  1484
{
bbf53cd43fbb Functions to update room bookmarks
Mikael Berthe <mikael@lilotux.net>
parents: 1006
diff changeset
  1485
  eviqs *iqn;
bbf53cd43fbb Functions to update room bookmarks
Mikael Berthe <mikael@lilotux.net>
parents: 1006
diff changeset
  1486
bbf53cd43fbb Functions to update room bookmarks
Mikael Berthe <mikael@lilotux.net>
parents: 1006
diff changeset
  1487
  if (!bookmarks) return;
bbf53cd43fbb Functions to update room bookmarks
Mikael Berthe <mikael@lilotux.net>
parents: 1006
diff changeset
  1488
bbf53cd43fbb Functions to update room bookmarks
Mikael Berthe <mikael@lilotux.net>
parents: 1006
diff changeset
  1489
  iqn = iqs_new(JPACKET__SET, NS_PRIVATE, "storage", IQS_DEFAULT_TIMEOUT);
bbf53cd43fbb Functions to update room bookmarks
Mikael Berthe <mikael@lilotux.net>
parents: 1006
diff changeset
  1490
  xmlnode_insert_node(xmlnode_get_tag(iqn->xmldata, "query"), bookmarks);
bbf53cd43fbb Functions to update room bookmarks
Mikael Berthe <mikael@lilotux.net>
parents: 1006
diff changeset
  1491
bbf53cd43fbb Functions to update room bookmarks
Mikael Berthe <mikael@lilotux.net>
parents: 1006
diff changeset
  1492
  jab_send(jc, iqn->xmldata);
bbf53cd43fbb Functions to update room bookmarks
Mikael Berthe <mikael@lilotux.net>
parents: 1006
diff changeset
  1493
  iqs_del(iqn->id); // XXX
bbf53cd43fbb Functions to update room bookmarks
Mikael Berthe <mikael@lilotux.net>
parents: 1006
diff changeset
  1494
}
bbf53cd43fbb Functions to update room bookmarks
Mikael Berthe <mikael@lilotux.net>
parents: 1006
diff changeset
  1495
1016
4d3c48844746 Add /roster note
Mikael Berthe <mikael@lilotux.net>
parents: 1015
diff changeset
  1496
//  send_storage_rosternotes()
4d3c48844746 Add /roster note
Mikael Berthe <mikael@lilotux.net>
parents: 1015
diff changeset
  1497
// Send the current rosternotes node to update the server.
4d3c48844746 Add /roster note
Mikael Berthe <mikael@lilotux.net>
parents: 1015
diff changeset
  1498
// Note: the sender should check we're online.
4d3c48844746 Add /roster note
Mikael Berthe <mikael@lilotux.net>
parents: 1015
diff changeset
  1499
void send_storage_rosternotes(void)
4d3c48844746 Add /roster note
Mikael Berthe <mikael@lilotux.net>
parents: 1015
diff changeset
  1500
{
4d3c48844746 Add /roster note
Mikael Berthe <mikael@lilotux.net>
parents: 1015
diff changeset
  1501
  eviqs *iqn;
4d3c48844746 Add /roster note
Mikael Berthe <mikael@lilotux.net>
parents: 1015
diff changeset
  1502
4d3c48844746 Add /roster note
Mikael Berthe <mikael@lilotux.net>
parents: 1015
diff changeset
  1503
  if (!rosternotes) return;
4d3c48844746 Add /roster note
Mikael Berthe <mikael@lilotux.net>
parents: 1015
diff changeset
  1504
4d3c48844746 Add /roster note
Mikael Berthe <mikael@lilotux.net>
parents: 1015
diff changeset
  1505
  iqn = iqs_new(JPACKET__SET, NS_PRIVATE, "storage", IQS_DEFAULT_TIMEOUT);
4d3c48844746 Add /roster note
Mikael Berthe <mikael@lilotux.net>
parents: 1015
diff changeset
  1506
  xmlnode_insert_node(xmlnode_get_tag(iqn->xmldata, "query"), rosternotes);
4d3c48844746 Add /roster note
Mikael Berthe <mikael@lilotux.net>
parents: 1015
diff changeset
  1507
4d3c48844746 Add /roster note
Mikael Berthe <mikael@lilotux.net>
parents: 1015
diff changeset
  1508
  jab_send(jc, iqn->xmldata);
4d3c48844746 Add /roster note
Mikael Berthe <mikael@lilotux.net>
parents: 1015
diff changeset
  1509
  iqs_del(iqn->id); // XXX
4d3c48844746 Add /roster note
Mikael Berthe <mikael@lilotux.net>
parents: 1015
diff changeset
  1510
}
4d3c48844746 Add /roster note
Mikael Berthe <mikael@lilotux.net>
parents: 1015
diff changeset
  1511
580
fed6d1e4d7a9 Fix modelines
Mikael Berthe <mikael@lilotux.net>
parents: 578
diff changeset
  1512
/* vim: set expandtab cindent cinoptions=>2\:2(0:  For Vim users... */