jingle/jingle.c
author Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
Mon, 16 Aug 2010 23:37:31 +0200
changeset 139 459b2503c1a3
parent 135 06b7c6f1c05c
child 144 efc92c939fef
permissions -rw-r--r--
Rename some stuff, create a README file, enable warnings in ./jingle
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
14
77966ed56e14 Create two subdirectories.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff changeset
     1
/*
77966ed56e14 Create two subdirectories.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff changeset
     2
 * jingle.c
77966ed56e14 Create two subdirectories.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff changeset
     3
 *
77966ed56e14 Create two subdirectories.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff changeset
     4
 * Copyrigth (C) 2010 Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
77966ed56e14 Create two subdirectories.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff changeset
     5
 *
77966ed56e14 Create two subdirectories.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff changeset
     6
 * This program is free software; you can redistribute it and/or modify
77966ed56e14 Create two subdirectories.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff changeset
     7
 * it under the terms of the GNU General Public License as published by
77966ed56e14 Create two subdirectories.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff changeset
     8
 * the Free Software Foundation; either version 2 of the License, or (at
77966ed56e14 Create two subdirectories.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff changeset
     9
 * your option) any later version.
77966ed56e14 Create two subdirectories.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff changeset
    10
 *
77966ed56e14 Create two subdirectories.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff changeset
    11
 * This program is distributed in the hope that it will be useful, but
77966ed56e14 Create two subdirectories.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff changeset
    12
 * WITHOUT ANY WARRANTY; without even the implied warranty of
77966ed56e14 Create two subdirectories.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff changeset
    13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
77966ed56e14 Create two subdirectories.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff changeset
    14
 * General Public License for more details.
77966ed56e14 Create two subdirectories.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff changeset
    15
 *
77966ed56e14 Create two subdirectories.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff changeset
    16
 * You should have received a copy of the GNU General Public License
77966ed56e14 Create two subdirectories.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff changeset
    17
 * along with this program; if not, write to the Free Software
77966ed56e14 Create two subdirectories.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff changeset
    18
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
77966ed56e14 Create two subdirectories.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff changeset
    19
 * USA
77966ed56e14 Create two subdirectories.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff changeset
    20
 */
77966ed56e14 Create two subdirectories.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff changeset
    21
23
9367e144e626 Some errors in code
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents: 22
diff changeset
    22
#include <config.h>
15
61ffa66f8288 Include config.h. The file transfert module now add the corresponding
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents: 14
diff changeset
    23
14
77966ed56e14 Create two subdirectories.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff changeset
    24
#include <glib.h>
77966ed56e14 Create two subdirectories.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff changeset
    25
#include <loudmouth/loudmouth.h>
77966ed56e14 Create two subdirectories.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff changeset
    26
77966ed56e14 Create two subdirectories.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff changeset
    27
#include <mcabber/xmpp.h>
77966ed56e14 Create two subdirectories.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff changeset
    28
#include <mcabber/hooks.h>
77966ed56e14 Create two subdirectories.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff changeset
    29
#include <mcabber/modules.h>
77966ed56e14 Create two subdirectories.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff changeset
    30
#include <mcabber/logprint.h>
77966ed56e14 Create two subdirectories.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff changeset
    31
#include <mcabber/xmpp_helper.h>
52
d803c882a182 Fix the ack handlers.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents: 48
diff changeset
    32
#include <mcabber/events.h>
14
77966ed56e14 Create two subdirectories.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff changeset
    33
18
d0ddcfd31eb8 Change the way the header files are included.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents: 17
diff changeset
    34
#include <jingle/jingle.h>
d0ddcfd31eb8 Change the way the header files are included.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents: 17
diff changeset
    35
#include <jingle/check.h>
d0ddcfd31eb8 Change the way the header files are included.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents: 17
diff changeset
    36
#include <jingle/action-handlers.h>
d0ddcfd31eb8 Change the way the header files are included.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents: 17
diff changeset
    37
#include <jingle/register.h>
46
f33c814d5b3a Look if the initiator is in roster (ddos)
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents: 45
diff changeset
    38
#include <jingle/send.h>
54
1c1153f9f945 Handle for jingle
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents: 52
diff changeset
    39
#include <jingle/sessions.h>
14
77966ed56e14 Create two subdirectories.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff changeset
    40
77966ed56e14 Create two subdirectories.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff changeset
    41
static void  jingle_register_lm_handlers(void);
77966ed56e14 Create two subdirectories.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff changeset
    42
static void  jingle_unregister_lm_handlers(void);
46
f33c814d5b3a Look if the initiator is in roster (ddos)
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents: 45
diff changeset
    43
static guint jingle_connect_hh(const gchar *hname, hk_arg_t *args,
f33c814d5b3a Look if the initiator is in roster (ddos)
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents: 45
diff changeset
    44
                               gpointer ignore);
f33c814d5b3a Look if the initiator is in roster (ddos)
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents: 45
diff changeset
    45
static guint jingle_disconn_hh(const gchar *hname, hk_arg_t *args,
f33c814d5b3a Look if the initiator is in roster (ddos)
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents: 45
diff changeset
    46
                               gpointer ignore);
14
77966ed56e14 Create two subdirectories.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff changeset
    47
static void  jingle_init(void);
77966ed56e14 Create two subdirectories.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff changeset
    48
static void  jingle_uninit(void);
77966ed56e14 Create two subdirectories.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff changeset
    49
77966ed56e14 Create two subdirectories.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff changeset
    50
static LmMessageHandler* jingle_iq_handler = NULL;
52
d803c882a182 Fix the ack handlers.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents: 48
diff changeset
    51
static GSList *ack_handlers = NULL;
129
2d5c3efda92a Add a timeout to the AckHandlers.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents: 126
diff changeset
    52
static guint ack_timeout_checker = 0;
14
77966ed56e14 Create two subdirectories.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff changeset
    53
static guint connect_hid = 0;
77966ed56e14 Create two subdirectories.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff changeset
    54
static guint disconn_hid = 0;
77966ed56e14 Create two subdirectories.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff changeset
    55
72
277778138b4b Handle for the app
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents: 70
diff changeset
    56
14
77966ed56e14 Create two subdirectories.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff changeset
    57
/**
77966ed56e14 Create two subdirectories.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff changeset
    58
 * Must be aligned with the values in JingleAction
77966ed56e14 Create two subdirectories.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff changeset
    59
 * for easy acces.
77966ed56e14 Create two subdirectories.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff changeset
    60
 */
77966ed56e14 Create two subdirectories.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff changeset
    61
struct JingleActionList jingle_action_list[] = {
77966ed56e14 Create two subdirectories.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff changeset
    62
  { NULL,                NULL }, // for JINGLE_UNKNOWN_ACTION
121
3a3c0e16ea00 Delete some part which wasn't use
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents: 119
diff changeset
    63
  { "content-accept",    NULL },
3a3c0e16ea00 Delete some part which wasn't use
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents: 119
diff changeset
    64
  { "content-add",       NULL },
14
77966ed56e14 Create two subdirectories.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff changeset
    65
  { "content-modify",    NULL },
121
3a3c0e16ea00 Delete some part which wasn't use
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents: 119
diff changeset
    66
  { "content-reject",    NULL },
3a3c0e16ea00 Delete some part which wasn't use
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents: 119
diff changeset
    67
  { "content-remove",    NULL },
14
77966ed56e14 Create two subdirectories.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff changeset
    68
  { "description-info",  NULL },
77966ed56e14 Create two subdirectories.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff changeset
    69
  { "security-info",     NULL },
99
3463ce93975a Minor bugs
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents: 96
diff changeset
    70
  { "session-accept",    handle_session_accept },
111
76ce876f7935 Handle incoming session-info
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents: 107
diff changeset
    71
  { "session-info",      handle_session_info },
15
61ffa66f8288 Include config.h. The file transfert module now add the corresponding
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents: 14
diff changeset
    72
  { "session-initiate",  handle_session_initiate },
17
24aa7414bafd Start the transport/app registering code. Fix various things.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents: 16
diff changeset
    73
  { "session-terminate", handle_session_terminate },
99
3463ce93975a Minor bugs
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents: 96
diff changeset
    74
  { "transport-accept",  NULL },
14
77966ed56e14 Create two subdirectories.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff changeset
    75
  { "transport-info",    NULL },
77966ed56e14 Create two subdirectories.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff changeset
    76
  { "transport-reject",  NULL },
77966ed56e14 Create two subdirectories.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff changeset
    77
  { "transport-replace", NULL },
77966ed56e14 Create two subdirectories.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff changeset
    78
};
77966ed56e14 Create two subdirectories.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff changeset
    79
77966ed56e14 Create two subdirectories.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff changeset
    80
module_info_t info_jingle = {
77966ed56e14 Create two subdirectories.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff changeset
    81
  .branch          = MCABBER_BRANCH,
77966ed56e14 Create two subdirectories.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff changeset
    82
  .api             = MCABBER_API_VERSION,
15
61ffa66f8288 Include config.h. The file transfert module now add the corresponding
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents: 14
diff changeset
    83
  .version         = PROJECT_VERSION,
14
77966ed56e14 Create two subdirectories.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff changeset
    84
  .description     = "Main Jingle module,"
77966ed56e14 Create two subdirectories.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff changeset
    85
                     " required for file transport, voip...\n",
77966ed56e14 Create two subdirectories.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff changeset
    86
  .requires        = NULL,
77966ed56e14 Create two subdirectories.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff changeset
    87
  .init            = jingle_init,
77966ed56e14 Create two subdirectories.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff changeset
    88
  .uninit          = jingle_uninit,
77966ed56e14 Create two subdirectories.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff changeset
    89
  .next            = NULL,
77966ed56e14 Create two subdirectories.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff changeset
    90
};
77966ed56e14 Create two subdirectories.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff changeset
    91
77966ed56e14 Create two subdirectories.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff changeset
    92
77966ed56e14 Create two subdirectories.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff changeset
    93
LmHandlerResult jingle_handle_iq(LmMessageHandler *handler,
26
af14f8f5a2b6 send session terminated
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents: 25
diff changeset
    94
                                 LmConnection *connection, LmMessage *message,
14
77966ed56e14 Create two subdirectories.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff changeset
    95
                                 gpointer user_data)
77966ed56e14 Create two subdirectories.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff changeset
    96
{
77966ed56e14 Create two subdirectories.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff changeset
    97
  LmMessageSubType iqtype = lm_message_get_sub_type(message);
77966ed56e14 Create two subdirectories.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff changeset
    98
  if (iqtype != LM_MESSAGE_SUB_TYPE_SET)
77966ed56e14 Create two subdirectories.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff changeset
    99
    return LM_HANDLER_RESULT_ALLOW_MORE_HANDLERS;
77966ed56e14 Create two subdirectories.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff changeset
   100
77966ed56e14 Create two subdirectories.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff changeset
   101
  JingleNode *jn = g_new0(JingleNode, 1);
15
61ffa66f8288 Include config.h. The file transfert module now add the corresponding
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents: 14
diff changeset
   102
  GError *error = NULL;
16
cb085682970f Fix a few errors in the code.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents: 15
diff changeset
   103
  LmMessageNode *root = lm_message_get_node(message);
cb085682970f Fix a few errors in the code.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents: 15
diff changeset
   104
  LmMessageNode *jnode = lm_message_node_get_child(root, "jingle");
14
77966ed56e14 Create two subdirectories.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff changeset
   105
16
cb085682970f Fix a few errors in the code.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents: 15
diff changeset
   106
  if (!jnode) // no <jingle> element found
14
77966ed56e14 Create two subdirectories.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff changeset
   107
    return LM_HANDLER_RESULT_ALLOW_MORE_HANDLERS;
77966ed56e14 Create two subdirectories.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff changeset
   108
16
cb085682970f Fix a few errors in the code.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents: 15
diff changeset
   109
  if (g_strcmp0(lm_message_node_get_attribute(jnode, "xmlns"), NS_JINGLE)) {
46
f33c814d5b3a Look if the initiator is in roster (ddos)
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents: 45
diff changeset
   110
    scr_log_print(LPRINT_DEBUG,
f33c814d5b3a Look if the initiator is in roster (ddos)
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents: 45
diff changeset
   111
                  "jingle: Received a jingle IQ with an invalid namespace");
14
77966ed56e14 Create two subdirectories.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff changeset
   112
    return LM_HANDLER_RESULT_REMOVE_MESSAGE;
77966ed56e14 Create two subdirectories.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff changeset
   113
  }
77966ed56e14 Create two subdirectories.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff changeset
   114
18
d0ddcfd31eb8 Change the way the header files are included.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents: 17
diff changeset
   115
  check_jingle(message, jnode, jn, &error);
14
77966ed56e14 Create two subdirectories.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff changeset
   116
  if (error != NULL) {
15
61ffa66f8288 Include config.h. The file transfert module now add the corresponding
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents: 14
diff changeset
   117
    if (error->domain == JINGLE_CHECK_ERROR) {
14
77966ed56e14 Create two subdirectories.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff changeset
   118
      // request malformed, we reply with a bad-request
77966ed56e14 Create two subdirectories.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff changeset
   119
      jingle_send_iq_error(message, "cancel", "bad-request", NULL);
57
23df37238a3a Print more debug output
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents: 54
diff changeset
   120
      scr_log_print(LPRINT_DEBUG,
91
7d3e75eec29e handle error for session-initiate
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents: 89
diff changeset
   121
                    "jingle: %s", error->message);
14
77966ed56e14 Create two subdirectories.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff changeset
   122
    }
126
059a6737f6a4 Error are better handle
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents: 123
diff changeset
   123
    g_error_free(error);
059a6737f6a4 Error are better handle
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents: 123
diff changeset
   124
    jingle_free_jinglenode(jn);
14
77966ed56e14 Create two subdirectories.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff changeset
   125
    return LM_HANDLER_RESULT_REMOVE_MESSAGE;
77966ed56e14 Create two subdirectories.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff changeset
   126
  }
15
61ffa66f8288 Include config.h. The file transfert module now add the corresponding
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents: 14
diff changeset
   127
14
77966ed56e14 Create two subdirectories.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff changeset
   128
  scr_log_print(LPRINT_DEBUG, "jingle: Received a valid jingle IQ");
15
61ffa66f8288 Include config.h. The file transfert module now add the corresponding
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents: 14
diff changeset
   129
61ffa66f8288 Include config.h. The file transfert module now add the corresponding
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents: 14
diff changeset
   130
  if (jingle_action_list[jn->action].handler == NULL) {
17
24aa7414bafd Start the transport/app registering code. Fix various things.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents: 16
diff changeset
   131
    jingle_send_iq_error(message, "cancel", "feature-not-implemented", NULL);
126
059a6737f6a4 Error are better handle
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents: 123
diff changeset
   132
    jingle_free_jinglenode(jn);
15
61ffa66f8288 Include config.h. The file transfert module now add the corresponding
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents: 14
diff changeset
   133
    return LM_HANDLER_RESULT_REMOVE_MESSAGE;
61ffa66f8288 Include config.h. The file transfert module now add the corresponding
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents: 14
diff changeset
   134
  }
61ffa66f8288 Include config.h. The file transfert module now add the corresponding
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents: 14
diff changeset
   135
45
c007e112dd54 Delete LmMessage * in handlers
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents: 44
diff changeset
   136
  jingle_action_list[jn->action].handler(jn);
126
059a6737f6a4 Error are better handle
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents: 123
diff changeset
   137
  jingle_free_jinglenode(jn);
14
77966ed56e14 Create two subdirectories.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff changeset
   138
  return LM_HANDLER_RESULT_REMOVE_MESSAGE;
77966ed56e14 Create two subdirectories.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff changeset
   139
}
77966ed56e14 Create two subdirectories.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff changeset
   140
77966ed56e14 Create two subdirectories.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff changeset
   141
/**
52
d803c882a182 Fix the ack handlers.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents: 48
diff changeset
   142
 * Handle incoming ack iq (type result or error).
d803c882a182 Fix the ack handlers.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents: 48
diff changeset
   143
 */
d803c882a182 Fix the ack handlers.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents: 48
diff changeset
   144
LmHandlerResult jingle_handle_ack_iq(LmMessageHandler *handler,
d803c882a182 Fix the ack handlers.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents: 48
diff changeset
   145
                                     LmConnection *connection, 
d803c882a182 Fix the ack handlers.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents: 48
diff changeset
   146
                                     LmMessage *message, gpointer user_data)
d803c882a182 Fix the ack handlers.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents: 48
diff changeset
   147
{
d803c882a182 Fix the ack handlers.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents: 48
diff changeset
   148
  // TODO: check subtype
d803c882a182 Fix the ack handlers.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents: 48
diff changeset
   149
  if (user_data != NULL) {
d803c882a182 Fix the ack handlers.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents: 48
diff changeset
   150
    JingleAckHandle *ah = user_data;
d803c882a182 Fix the ack handlers.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents: 48
diff changeset
   151
    if(ah->callback != NULL)
129
2d5c3efda92a Add a timeout to the AckHandlers.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents: 126
diff changeset
   152
      ah->callback(JINGLE_ACK_RESPONSE, message, ah->user_data);
52
d803c882a182 Fix the ack handlers.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents: 48
diff changeset
   153
129
2d5c3efda92a Add a timeout to the AckHandlers.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents: 126
diff changeset
   154
    jingle_ack_handler_free(ah);
52
d803c882a182 Fix the ack handlers.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents: 48
diff changeset
   155
  }
d803c882a182 Fix the ack handlers.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents: 48
diff changeset
   156
d803c882a182 Fix the ack handlers.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents: 48
diff changeset
   157
  return LM_HANDLER_RESULT_REMOVE_MESSAGE;
d803c882a182 Fix the ack handlers.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents: 48
diff changeset
   158
}
d803c882a182 Fix the ack handlers.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents: 48
diff changeset
   159
129
2d5c3efda92a Add a timeout to the AckHandlers.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents: 126
diff changeset
   160
gboolean jingle_ack_timeout_checker(gpointer user_data)
2d5c3efda92a Add a timeout to the AckHandlers.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents: 126
diff changeset
   161
{
135
06b7c6f1c05c Fix jingle_ack_timeout_checker.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents: 133
diff changeset
   162
  GSList *el, *prev;
129
2d5c3efda92a Add a timeout to the AckHandlers.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents: 126
diff changeset
   163
  time_t now = time(NULL);
2d5c3efda92a Add a timeout to the AckHandlers.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents: 126
diff changeset
   164
139
459b2503c1a3 Rename some stuff, create a README file, enable warnings in ./jingle
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents: 135
diff changeset
   165
  el = prev = ack_handlers;
135
06b7c6f1c05c Fix jingle_ack_timeout_checker.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents: 133
diff changeset
   166
  while(el) {
06b7c6f1c05c Fix jingle_ack_timeout_checker.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents: 133
diff changeset
   167
    JingleAckHandle *ah = el->data;
129
2d5c3efda92a Add a timeout to the AckHandlers.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents: 126
diff changeset
   168
135
06b7c6f1c05c Fix jingle_ack_timeout_checker.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents: 133
diff changeset
   169
    if (ah->timeout != 0 && ah->_inserted + ah->timeout <= now) {
06b7c6f1c05c Fix jingle_ack_timeout_checker.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents: 133
diff changeset
   170
      if (ah->callback != NULL) {
06b7c6f1c05c Fix jingle_ack_timeout_checker.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents: 133
diff changeset
   171
        ah->callback(JINGLE_ACK_TIMEOUT, NULL, ah->user_data);
06b7c6f1c05c Fix jingle_ack_timeout_checker.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents: 133
diff changeset
   172
      }
129
2d5c3efda92a Add a timeout to the AckHandlers.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents: 126
diff changeset
   173
135
06b7c6f1c05c Fix jingle_ack_timeout_checker.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents: 133
diff changeset
   174
      jingle_ack_handler_free(ah);
06b7c6f1c05c Fix jingle_ack_timeout_checker.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents: 133
diff changeset
   175
      if (ack_handlers == NULL)
06b7c6f1c05c Fix jingle_ack_timeout_checker.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents: 133
diff changeset
   176
        break;
129
2d5c3efda92a Add a timeout to the AckHandlers.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents: 126
diff changeset
   177
135
06b7c6f1c05c Fix jingle_ack_timeout_checker.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents: 133
diff changeset
   178
      el = prev;
06b7c6f1c05c Fix jingle_ack_timeout_checker.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents: 133
diff changeset
   179
    }
06b7c6f1c05c Fix jingle_ack_timeout_checker.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents: 133
diff changeset
   180
    prev = el;
06b7c6f1c05c Fix jingle_ack_timeout_checker.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents: 133
diff changeset
   181
    el = el->next;
129
2d5c3efda92a Add a timeout to the AckHandlers.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents: 126
diff changeset
   182
  }
2d5c3efda92a Add a timeout to the AckHandlers.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents: 126
diff changeset
   183
  return TRUE;
2d5c3efda92a Add a timeout to the AckHandlers.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents: 126
diff changeset
   184
}
2d5c3efda92a Add a timeout to the AckHandlers.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents: 126
diff changeset
   185
52
d803c882a182 Fix the ack handlers.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents: 48
diff changeset
   186
LmMessageHandler *jingle_new_ack_handler(JingleAckHandle *ah)
d803c882a182 Fix the ack handlers.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents: 48
diff changeset
   187
{
129
2d5c3efda92a Add a timeout to the AckHandlers.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents: 126
diff changeset
   188
  if(ack_timeout_checker == 0)
2d5c3efda92a Add a timeout to the AckHandlers.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents: 126
diff changeset
   189
	  ack_timeout_checker = g_timeout_add_seconds(3, jingle_ack_timeout_checker, NULL);
2d5c3efda92a Add a timeout to the AckHandlers.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents: 126
diff changeset
   190
  
2d5c3efda92a Add a timeout to the AckHandlers.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents: 126
diff changeset
   191
  ah->_inserted = time(NULL);
2d5c3efda92a Add a timeout to the AckHandlers.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents: 126
diff changeset
   192
  ah->_handler = lm_message_handler_new(jingle_handle_ack_iq,
2d5c3efda92a Add a timeout to the AckHandlers.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents: 126
diff changeset
   193
                                        (gpointer) ah, NULL);
2d5c3efda92a Add a timeout to the AckHandlers.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents: 126
diff changeset
   194
  ack_handlers = g_slist_append(ack_handlers, ah);
2d5c3efda92a Add a timeout to the AckHandlers.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents: 126
diff changeset
   195
  return ah->_handler;
2d5c3efda92a Add a timeout to the AckHandlers.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents: 126
diff changeset
   196
}
2d5c3efda92a Add a timeout to the AckHandlers.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents: 126
diff changeset
   197
2d5c3efda92a Add a timeout to the AckHandlers.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents: 126
diff changeset
   198
void jingle_ack_handler_free(JingleAckHandle *ah)
2d5c3efda92a Add a timeout to the AckHandlers.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents: 126
diff changeset
   199
{
2d5c3efda92a Add a timeout to the AckHandlers.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents: 126
diff changeset
   200
  lm_message_handler_unref(ah->_handler);
2d5c3efda92a Add a timeout to the AckHandlers.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents: 126
diff changeset
   201
  ack_handlers = g_slist_remove(ack_handlers, ah);
2d5c3efda92a Add a timeout to the AckHandlers.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents: 126
diff changeset
   202
  g_free(ah);
52
d803c882a182 Fix the ack handlers.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents: 48
diff changeset
   203
}
d803c882a182 Fix the ack handlers.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents: 48
diff changeset
   204
d803c882a182 Fix the ack handlers.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents: 48
diff changeset
   205
/**
d803c882a182 Fix the ack handlers.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents: 48
diff changeset
   206
 * mcabber /event callback.
d803c882a182 Fix the ack handlers.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents: 48
diff changeset
   207
 */
d803c882a182 Fix the ack handlers.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents: 48
diff changeset
   208
gboolean evscallback_jingle(guint evcontext, const gchar *arg,
d803c882a182 Fix the ack handlers.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents: 48
diff changeset
   209
                            gpointer userdata)
d803c882a182 Fix the ack handlers.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents: 48
diff changeset
   210
{
119
0b9a7b505079 create the session when receiving a session-initiate
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents: 111
diff changeset
   211
  JingleSession *js = (JingleSession*)userdata;
52
d803c882a182 Fix the ack handlers.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents: 48
diff changeset
   212
d803c882a182 Fix the ack handlers.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents: 48
diff changeset
   213
  /*
d803c882a182 Fix the ack handlers.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents: 48
diff changeset
   214
  if (G_UNLIKELY(!jn)) {
d803c882a182 Fix the ack handlers.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents: 48
diff changeset
   215
    scr_LogPrint(LPRINT_LOGNORM, "Error in evs callback.");
d803c882a182 Fix the ack handlers.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents: 48
diff changeset
   216
    return FALSE;
d803c882a182 Fix the ack handlers.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents: 48
diff changeset
   217
  }
d803c882a182 Fix the ack handlers.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents: 48
diff changeset
   218
  */
d803c882a182 Fix the ack handlers.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents: 48
diff changeset
   219
d803c882a182 Fix the ack handlers.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents: 48
diff changeset
   220
  if (evcontext == EVS_CONTEXT_TIMEOUT) {
d803c882a182 Fix the ack handlers.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents: 48
diff changeset
   221
    scr_LogPrint(LPRINT_LOGNORM, "Jingle event from %s timed out, cancelled.",
119
0b9a7b505079 create the session when receiving a session-initiate
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents: 111
diff changeset
   222
                 js->from);
52
d803c882a182 Fix the ack handlers.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents: 48
diff changeset
   223
    return FALSE;
d803c882a182 Fix the ack handlers.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents: 48
diff changeset
   224
  }
58
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents: 57
diff changeset
   225
  if (evcontext == EVS_CONTEXT_CANCEL) {
52
d803c882a182 Fix the ack handlers.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents: 48
diff changeset
   226
    scr_LogPrint(LPRINT_LOGNORM, "Jingle event from %s cancelled.",
119
0b9a7b505079 create the session when receiving a session-initiate
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents: 111
diff changeset
   227
                 js->from);
52
d803c882a182 Fix the ack handlers.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents: 48
diff changeset
   228
    return FALSE;
d803c882a182 Fix the ack handlers.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents: 48
diff changeset
   229
  }
d803c882a182 Fix the ack handlers.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents: 48
diff changeset
   230
  if (!(evcontext == EVS_CONTEXT_ACCEPT || evcontext == EVS_CONTEXT_REJECT)) {
58
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents: 57
diff changeset
   231
    scr_LogPrint(LPRINT_LOGNORM, "Jingle event from %s cancelled.",
119
0b9a7b505079 create the session when receiving a session-initiate
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents: 111
diff changeset
   232
                 js->from);
52
d803c882a182 Fix the ack handlers.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents: 48
diff changeset
   233
    return FALSE;
d803c882a182 Fix the ack handlers.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents: 48
diff changeset
   234
  }
d803c882a182 Fix the ack handlers.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents: 48
diff changeset
   235
  
d803c882a182 Fix the ack handlers.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents: 48
diff changeset
   236
  if (evcontext == EVS_CONTEXT_ACCEPT) {
58
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents: 57
diff changeset
   237
    scr_LogPrint(LPRINT_LOGNORM, "Jingle event from %s accepted.",
119
0b9a7b505079 create the session when receiving a session-initiate
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents: 111
diff changeset
   238
                 js->from);
0b9a7b505079 create the session when receiving a session-initiate
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents: 111
diff changeset
   239
    jingle_send_session_accept(js);
52
d803c882a182 Fix the ack handlers.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents: 48
diff changeset
   240
  } else {
58
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents: 57
diff changeset
   241
    scr_LogPrint(LPRINT_LOGNORM, "Jingle event from %s cancelled.",
119
0b9a7b505079 create the session when receiving a session-initiate
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents: 111
diff changeset
   242
                 js->from);
0b9a7b505079 create the session when receiving a session-initiate
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents: 111
diff changeset
   243
    jingle_send_session_terminate(js, "decline");
133
361d8577ebd1 Change the way IBB work
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents: 129
diff changeset
   244
    
52
d803c882a182 Fix the ack handlers.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents: 48
diff changeset
   245
  }
d803c882a182 Fix the ack handlers.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents: 48
diff changeset
   246
d803c882a182 Fix the ack handlers.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents: 48
diff changeset
   247
  return FALSE;
d803c882a182 Fix the ack handlers.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents: 48
diff changeset
   248
}
d803c882a182 Fix the ack handlers.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents: 48
diff changeset
   249
d803c882a182 Fix the ack handlers.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents: 48
diff changeset
   250
/**
14
77966ed56e14 Create two subdirectories.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff changeset
   251
 * According to the specifications:
77966ed56e14 Create two subdirectories.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff changeset
   252
 * "An entity that receives an IQ request of type "get" or "set" MUST
77966ed56e14 Create two subdirectories.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff changeset
   253
 * reply with an IQ response of type "result" or "error"."
77966ed56e14 Create two subdirectories.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff changeset
   254
 * For Jingle's IQ, we have to reply with an empty "result" IQ to acknowledge
77966ed56e14 Create two subdirectories.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff changeset
   255
 * receipt.
77966ed56e14 Create two subdirectories.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff changeset
   256
 */
77966ed56e14 Create two subdirectories.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff changeset
   257
void jingle_ack_iq(LmMessage *m)
77966ed56e14 Create two subdirectories.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff changeset
   258
{
77966ed56e14 Create two subdirectories.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff changeset
   259
  LmMessage *r;
77966ed56e14 Create two subdirectories.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff changeset
   260
77966ed56e14 Create two subdirectories.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff changeset
   261
  r = lm_message_new_iq_from_query(m, LM_MESSAGE_SUB_TYPE_RESULT);
77966ed56e14 Create two subdirectories.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff changeset
   262
  lm_connection_send(lconnection, r, NULL);
77966ed56e14 Create two subdirectories.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff changeset
   263
  lm_message_unref(r);
77966ed56e14 Create two subdirectories.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff changeset
   264
}
77966ed56e14 Create two subdirectories.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff changeset
   265
77966ed56e14 Create two subdirectories.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff changeset
   266
/**
18
d0ddcfd31eb8 Change the way the header files are included.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents: 17
diff changeset
   267
 * Create an error IQ.
14
77966ed56e14 Create two subdirectories.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff changeset
   268
 */
77966ed56e14 Create two subdirectories.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff changeset
   269
LmMessage *jingle_new_iq_error(LmMessage *m, const gchar *errtype,
77966ed56e14 Create two subdirectories.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff changeset
   270
                               const gchar *cond, const gchar *jinglecond)
77966ed56e14 Create two subdirectories.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff changeset
   271
{
77966ed56e14 Create two subdirectories.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff changeset
   272
  LmMessage *r;
77966ed56e14 Create two subdirectories.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff changeset
   273
  LmMessageNode *err, *tmpnode;
77966ed56e14 Create two subdirectories.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff changeset
   274
77966ed56e14 Create two subdirectories.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff changeset
   275
  r = lm_message_new_iq_from_query(m, LM_MESSAGE_SUB_TYPE_ERROR);
77966ed56e14 Create two subdirectories.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff changeset
   276
  err = lm_message_node_add_child(r->node, "error", NULL);
77966ed56e14 Create two subdirectories.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff changeset
   277
  lm_message_node_set_attribute(err, "type", errtype);
77966ed56e14 Create two subdirectories.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff changeset
   278
77966ed56e14 Create two subdirectories.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff changeset
   279
  // error condition as defined by RFC 3920bis section 8.3.3
77966ed56e14 Create two subdirectories.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff changeset
   280
  if (cond != NULL) {
77966ed56e14 Create two subdirectories.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff changeset
   281
    tmpnode = lm_message_node_add_child(err, cond, NULL);
77966ed56e14 Create two subdirectories.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff changeset
   282
    lm_message_node_set_attribute(tmpnode, "xmlns", NS_XMPP_STANZAS);
77966ed56e14 Create two subdirectories.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff changeset
   283
  }
77966ed56e14 Create two subdirectories.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff changeset
   284
77966ed56e14 Create two subdirectories.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff changeset
   285
  // jingle error condition as defined by XEP-0166 section 10
77966ed56e14 Create two subdirectories.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff changeset
   286
  if (jinglecond != NULL) {
77966ed56e14 Create two subdirectories.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff changeset
   287
    tmpnode = lm_message_node_add_child(err, jinglecond, NULL);
77966ed56e14 Create two subdirectories.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff changeset
   288
    lm_message_node_set_attribute(tmpnode, "xmlns", NS_JINGLE_ERRORS);
77966ed56e14 Create two subdirectories.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff changeset
   289
  }
77966ed56e14 Create two subdirectories.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff changeset
   290
77966ed56e14 Create two subdirectories.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff changeset
   291
  return r;
77966ed56e14 Create two subdirectories.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff changeset
   292
}
77966ed56e14 Create two subdirectories.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff changeset
   293
18
d0ddcfd31eb8 Change the way the header files are included.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents: 17
diff changeset
   294
/**
d0ddcfd31eb8 Change the way the header files are included.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents: 17
diff changeset
   295
 * Reply to a Jingle IQ with an error.
d0ddcfd31eb8 Change the way the header files are included.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents: 17
diff changeset
   296
 */
14
77966ed56e14 Create two subdirectories.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff changeset
   297
void jingle_send_iq_error(LmMessage *m, const gchar *errtype,
77966ed56e14 Create two subdirectories.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff changeset
   298
                          const gchar *cond, const gchar *jinglecond)
77966ed56e14 Create two subdirectories.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff changeset
   299
{
77966ed56e14 Create two subdirectories.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff changeset
   300
  LmMessage *r = jingle_new_iq_error(m, errtype, cond, jinglecond);
77966ed56e14 Create two subdirectories.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff changeset
   301
  if (r) {
52
d803c882a182 Fix the ack handlers.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents: 48
diff changeset
   302
    lm_connection_send(lconnection, r, NULL);
14
77966ed56e14 Create two subdirectories.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff changeset
   303
  }
77966ed56e14 Create two subdirectories.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff changeset
   304
}
77966ed56e14 Create two subdirectories.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff changeset
   305
77966ed56e14 Create two subdirectories.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff changeset
   306
/**
79
a654afc4a74a Function to detect which jid resource support jingle.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents: 77
diff changeset
   307
 * Find the best resource to initiate a jingle session.
a654afc4a74a Function to detect which jid resource support jingle.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents: 77
diff changeset
   308
 * Test every ressource for a given jid and return the one
a654afc4a74a Function to detect which jid resource support jingle.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents: 77
diff changeset
   309
 * who support all namespaces in ns.
a654afc4a74a Function to detect which jid resource support jingle.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents: 77
diff changeset
   310
 */
a654afc4a74a Function to detect which jid resource support jingle.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents: 77
diff changeset
   311
gchar *jingle_find_compatible_res(const gchar *jid, const gchar *ns[])
a654afc4a74a Function to detect which jid resource support jingle.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents: 77
diff changeset
   312
{
a654afc4a74a Function to detect which jid resource support jingle.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents: 77
diff changeset
   313
  gchar *choosenres;
a654afc4a74a Function to detect which jid resource support jingle.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents: 77
diff changeset
   314
  guint indexns;
a654afc4a74a Function to detect which jid resource support jingle.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents: 77
diff changeset
   315
  gboolean found;
a654afc4a74a Function to detect which jid resource support jingle.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents: 77
diff changeset
   316
  GList *roster_usr;
a654afc4a74a Function to detect which jid resource support jingle.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents: 77
diff changeset
   317
  GSList *reslist, *thisres;
a654afc4a74a Function to detect which jid resource support jingle.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents: 77
diff changeset
   318
a654afc4a74a Function to detect which jid resource support jingle.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents: 77
diff changeset
   319
  roster_usr = buddy_search_jid(jid);
a654afc4a74a Function to detect which jid resource support jingle.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents: 77
diff changeset
   320
  reslist = buddy_getresources(roster_usr->data);
a654afc4a74a Function to detect which jid resource support jingle.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents: 77
diff changeset
   321
  for (thisres = reslist; thisres; thisres = g_slist_next(thisres)) {
a654afc4a74a Function to detect which jid resource support jingle.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents: 77
diff changeset
   322
    found = TRUE;
a654afc4a74a Function to detect which jid resource support jingle.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents: 77
diff changeset
   323
    for (indexns = 0; ns[indexns]; indexns++) {
91
7d3e75eec29e handle error for session-initiate
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents: 89
diff changeset
   324
	  // if (!caps_has_feature(buddy_resource_getcaps(roster_usr->data, thisres->data), ns[indexns]))
7d3e75eec29e handle error for session-initiate
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents: 89
diff changeset
   325
	   //  found = FALSE;
86
a994dc89a1fc nothing
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents: 83
diff changeset
   326
	 }
a994dc89a1fc nothing
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents: 83
diff changeset
   327
	 if (!found) continue;
79
a654afc4a74a Function to detect which jid resource support jingle.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents: 77
diff changeset
   328
a654afc4a74a Function to detect which jid resource support jingle.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents: 77
diff changeset
   329
    choosenres = g_strdup(thisres->data);
a654afc4a74a Function to detect which jid resource support jingle.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents: 77
diff changeset
   330
    g_slist_foreach(reslist, (GFunc)g_free, NULL);
a654afc4a74a Function to detect which jid resource support jingle.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents: 77
diff changeset
   331
    g_slist_free(reslist);
a654afc4a74a Function to detect which jid resource support jingle.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents: 77
diff changeset
   332
    return choosenres;
a654afc4a74a Function to detect which jid resource support jingle.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents: 77
diff changeset
   333
  }
89
88bb2d0f9ff8 add an namespace to a jingle node
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents: 86
diff changeset
   334
86
a994dc89a1fc nothing
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents: 83
diff changeset
   335
  return NULL;
79
a654afc4a74a Function to detect which jid resource support jingle.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents: 77
diff changeset
   336
}
a654afc4a74a Function to detect which jid resource support jingle.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents: 77
diff changeset
   337
a654afc4a74a Function to detect which jid resource support jingle.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents: 77
diff changeset
   338
/**
14
77966ed56e14 Create two subdirectories.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff changeset
   339
 * Find the jingle_action corresponding to a string
77966ed56e14 Create two subdirectories.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff changeset
   340
 */
35
a0fd92a93af7 Fix the function converting a JingleNode to a LmMessage.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents: 34
diff changeset
   341
JingleAction jingle_action_from_str(const gchar *string)
14
77966ed56e14 Create two subdirectories.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff changeset
   342
{
77966ed56e14 Create two subdirectories.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff changeset
   343
  guint i, actstrlen = sizeof(jingle_action_list)/sizeof(jingle_action_list[0]);
77966ed56e14 Create two subdirectories.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff changeset
   344
  for (i = 0; i < actstrlen; i++)
77966ed56e14 Create two subdirectories.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff changeset
   345
    if (!g_strcmp0(jingle_action_list[i].name, string))
77966ed56e14 Create two subdirectories.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff changeset
   346
      return (JingleAction) i;
77966ed56e14 Create two subdirectories.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff changeset
   347
77966ed56e14 Create two subdirectories.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff changeset
   348
  return JINGLE_UNKNOWN_ACTION;
77966ed56e14 Create two subdirectories.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff changeset
   349
}
77966ed56e14 Create two subdirectories.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff changeset
   350
81
8b6320ad470b Add comments, change some function names...
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents: 80
diff changeset
   351
/**
8b6320ad470b Add comments, change some function names...
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents: 80
diff changeset
   352
 * This function should not be called if jn->message was created
8b6320ad470b Add comments, change some function names...
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents: 80
diff changeset
   353
 * using lm_message_from_jinglenode because loudmouth strdup
8b6320ad470b Add comments, change some function names...
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents: 80
diff changeset
   354
 * strings we insert as attributes. the pointers in the LmMessage
8b6320ad470b Add comments, change some function names...
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents: 80
diff changeset
   355
 * and the JingleNode would not refer to the same addresses and
8b6320ad470b Add comments, change some function names...
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents: 80
diff changeset
   356
 * a call to lm_message_unref would not free the data from the
8b6320ad470b Add comments, change some function names...
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents: 80
diff changeset
   357
 * JingleNode.
8b6320ad470b Add comments, change some function names...
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents: 80
diff changeset
   358
 */
18
d0ddcfd31eb8 Change the way the header files are included.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents: 17
diff changeset
   359
void jingle_free_jinglenode(JingleNode *jn)
d0ddcfd31eb8 Change the way the header files are included.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents: 17
diff changeset
   360
{
19
60a10ab26723 Modify the "registering" code.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents: 18
diff changeset
   361
  g_slist_foreach(jn->content, (GFunc)g_free, NULL);
18
d0ddcfd31eb8 Change the way the header files are included.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents: 17
diff changeset
   362
  g_slist_free(jn->content);
d0ddcfd31eb8 Change the way the header files are included.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents: 17
diff changeset
   363
  lm_message_unref(jn->message);
d0ddcfd31eb8 Change the way the header files are included.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents: 17
diff changeset
   364
  g_free(jn);
d0ddcfd31eb8 Change the way the header files are included.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents: 17
diff changeset
   365
}
d0ddcfd31eb8 Change the way the header files are included.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents: 17
diff changeset
   366
14
77966ed56e14 Create two subdirectories.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff changeset
   367
static void jingle_unregister_lm_handlers(void)
77966ed56e14 Create two subdirectories.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff changeset
   368
{
77966ed56e14 Create two subdirectories.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff changeset
   369
  if (lconnection) {
77966ed56e14 Create two subdirectories.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff changeset
   370
    lm_connection_unregister_message_handler(lconnection, jingle_iq_handler,
77966ed56e14 Create two subdirectories.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff changeset
   371
        LM_MESSAGE_TYPE_IQ);
77966ed56e14 Create two subdirectories.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff changeset
   372
  }
77966ed56e14 Create two subdirectories.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff changeset
   373
}
77966ed56e14 Create two subdirectories.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff changeset
   374
77966ed56e14 Create two subdirectories.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff changeset
   375
static void jingle_register_lm_handlers(void)
77966ed56e14 Create two subdirectories.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff changeset
   376
{
77966ed56e14 Create two subdirectories.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff changeset
   377
  jingle_unregister_lm_handlers();
77966ed56e14 Create two subdirectories.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff changeset
   378
  if (lconnection) {
77966ed56e14 Create two subdirectories.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff changeset
   379
    lm_connection_register_message_handler(lconnection, jingle_iq_handler,
77966ed56e14 Create two subdirectories.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff changeset
   380
        LM_MESSAGE_TYPE_IQ,
77966ed56e14 Create two subdirectories.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff changeset
   381
        LM_HANDLER_PRIORITY_FIRST);
77966ed56e14 Create two subdirectories.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff changeset
   382
  }
77966ed56e14 Create two subdirectories.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff changeset
   383
}
77966ed56e14 Create two subdirectories.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff changeset
   384
46
f33c814d5b3a Look if the initiator is in roster (ddos)
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents: 45
diff changeset
   385
static guint jingle_connect_hh(const gchar *hname, hk_arg_t *args,
f33c814d5b3a Look if the initiator is in roster (ddos)
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents: 45
diff changeset
   386
                               gpointer ignore)
14
77966ed56e14 Create two subdirectories.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff changeset
   387
{
77966ed56e14 Create two subdirectories.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff changeset
   388
  jingle_register_lm_handlers();
77966ed56e14 Create two subdirectories.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff changeset
   389
  return HOOK_HANDLER_RESULT_ALLOW_MORE_HANDLERS;
77966ed56e14 Create two subdirectories.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff changeset
   390
}
77966ed56e14 Create two subdirectories.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff changeset
   391
46
f33c814d5b3a Look if the initiator is in roster (ddos)
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents: 45
diff changeset
   392
static guint jingle_disconn_hh(const gchar *hname, hk_arg_t *args,
f33c814d5b3a Look if the initiator is in roster (ddos)
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents: 45
diff changeset
   393
                               gpointer ignore)
14
77966ed56e14 Create two subdirectories.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff changeset
   394
{
77966ed56e14 Create two subdirectories.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff changeset
   395
  jingle_unregister_lm_handlers();
77966ed56e14 Create two subdirectories.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff changeset
   396
  return HOOK_HANDLER_RESULT_ALLOW_MORE_HANDLERS;
77966ed56e14 Create two subdirectories.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff changeset
   397
}
77966ed56e14 Create two subdirectories.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff changeset
   398
77966ed56e14 Create two subdirectories.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff changeset
   399
static void jingle_init(void)
77966ed56e14 Create two subdirectories.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff changeset
   400
{
77966ed56e14 Create two subdirectories.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff changeset
   401
  jingle_iq_handler = lm_message_handler_new(jingle_handle_iq, NULL, NULL);
77966ed56e14 Create two subdirectories.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff changeset
   402
  xmpp_add_feature(NS_JINGLE);
77966ed56e14 Create two subdirectories.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff changeset
   403
77966ed56e14 Create two subdirectories.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff changeset
   404
  connect_hid = hk_add_handler(jingle_connect_hh, HOOK_POST_CONNECT,
77966ed56e14 Create two subdirectories.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff changeset
   405
      G_PRIORITY_DEFAULT_IDLE, NULL);
77966ed56e14 Create two subdirectories.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff changeset
   406
  disconn_hid = hk_add_handler(jingle_disconn_hh, HOOK_PRE_DISCONNECT,
77966ed56e14 Create two subdirectories.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff changeset
   407
      G_PRIORITY_DEFAULT_IDLE, NULL);
77966ed56e14 Create two subdirectories.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff changeset
   408
  jingle_register_lm_handlers();
77966ed56e14 Create two subdirectories.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff changeset
   409
}
77966ed56e14 Create two subdirectories.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff changeset
   410
77966ed56e14 Create two subdirectories.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff changeset
   411
static void jingle_uninit(void)
77966ed56e14 Create two subdirectories.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff changeset
   412
{
77966ed56e14 Create two subdirectories.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff changeset
   413
  xmpp_del_feature(NS_JINGLE);
77966ed56e14 Create two subdirectories.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff changeset
   414
77966ed56e14 Create two subdirectories.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff changeset
   415
  hk_del_handler(HOOK_POST_CONNECT, connect_hid);
77966ed56e14 Create two subdirectories.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff changeset
   416
  hk_del_handler(HOOK_PRE_DISCONNECT, disconn_hid);
77966ed56e14 Create two subdirectories.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff changeset
   417
  jingle_unregister_lm_handlers();
77966ed56e14 Create two subdirectories.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff changeset
   418
77966ed56e14 Create two subdirectories.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff changeset
   419
  lm_message_handler_invalidate(jingle_iq_handler);
77966ed56e14 Create two subdirectories.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff changeset
   420
  lm_message_handler_unref(jingle_iq_handler);
129
2d5c3efda92a Add a timeout to the AckHandlers.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents: 126
diff changeset
   421
2d5c3efda92a Add a timeout to the AckHandlers.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents: 126
diff changeset
   422
  if (ack_timeout_checker != 0) {
2d5c3efda92a Add a timeout to the AckHandlers.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents: 126
diff changeset
   423
    GSource *s = g_main_context_find_source_by_id(NULL, ack_timeout_checker);
2d5c3efda92a Add a timeout to the AckHandlers.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents: 126
diff changeset
   424
    g_source_destroy(s);
2d5c3efda92a Add a timeout to the AckHandlers.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents: 126
diff changeset
   425
  }
14
77966ed56e14 Create two subdirectories.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff changeset
   426
}
22
a089f2f49e9f Produce new LmMessageNode with a struct Jingle
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents: 19
diff changeset
   427
133
361d8577ebd1 Change the way IBB work
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents: 129
diff changeset
   428
void handle_trans_data(gconstpointer data, const gchar *data2, guint len)
54
1c1153f9f945 Handle for jingle
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents: 52
diff changeset
   429
{
133
361d8577ebd1 Change the way IBB work
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents: 129
diff changeset
   430
  SessionContent *sc = session_find_transport(data);
54
1c1153f9f945 Handle for jingle
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents: 52
diff changeset
   431
  if (sc == NULL) {
1c1153f9f945 Handle for jingle
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents: 52
diff changeset
   432
    return;  
1c1153f9f945 Handle for jingle
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents: 52
diff changeset
   433
  }
1c1153f9f945 Handle for jingle
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents: 52
diff changeset
   434
  sc->appfuncs->handle_data(sc->description, data2, len);
1c1153f9f945 Handle for jingle
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents: 52
diff changeset
   435
}
67
c12618793df0 New functions in sessions
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents: 61
diff changeset
   436
107
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents: 99
diff changeset
   437
void handle_trans_next(session_content *sc2) {
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents: 99
diff changeset
   438
  JingleSession *sess = session_find_by_sid(sc2->sid, sc2->from);
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents: 99
diff changeset
   439
  if (sess == NULL) {
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents: 99
diff changeset
   440
    // TODO: err
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents: 99
diff changeset
   441
    return;
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents: 99
diff changeset
   442
  }
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents: 99
diff changeset
   443
  
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents: 99
diff changeset
   444
  SessionContent *sc = session_find_sessioncontent(sess, sc2->name);
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents: 99
diff changeset
   445
  
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents: 99
diff changeset
   446
  // TODO: size!
123
58bd57666ef9 Add a end function to transport
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents: 121
diff changeset
   447
  sc->appfuncs->send(sc2);
107
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents: 99
diff changeset
   448
  g_free(sc2);
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents: 99
diff changeset
   449
}
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents: 99
diff changeset
   450
79
a654afc4a74a Function to detect which jid resource support jingle.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents: 77
diff changeset
   451
gchar *jingle_generate_sid(void)
67
c12618793df0 New functions in sessions
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents: 61
diff changeset
   452
{
c12618793df0 New functions in sessions
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents: 61
diff changeset
   453
  gchar *sid;
c12618793df0 New functions in sessions
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents: 61
diff changeset
   454
  gchar car[] = "azertyuiopqsdfghjklmwxcvbn1234567890AZERTYUIOPQSDFGHJKLMWXCVBN";
c12618793df0 New functions in sessions
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents: 61
diff changeset
   455
  int i;
c12618793df0 New functions in sessions
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents: 61
diff changeset
   456
  sid = g_new0(gchar, 11);
c12618793df0 New functions in sessions
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents: 61
diff changeset
   457
  for (i = 0; i < 10; i++)
c12618793df0 New functions in sessions
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents: 61
diff changeset
   458
    sid[i] = car[g_random_int_range(0, sizeof(car)/sizeof(car[0]))];
c12618793df0 New functions in sessions
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents: 61
diff changeset
   459
c12618793df0 New functions in sessions
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents: 61
diff changeset
   460
  sid[10] = '\0';
c12618793df0 New functions in sessions
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents: 61
diff changeset
   461
  
c12618793df0 New functions in sessions
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents: 61
diff changeset
   462
  return sid;
c12618793df0 New functions in sessions
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents: 61
diff changeset
   463
}