jingle/general-handlers.c
author Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
Sun, 11 Jul 2010 18:23:28 +0200
changeset 47 964b3ebeba8d
child 48 3c08b78be871
permissions -rw-r--r--
Handle ack iq

/*
 * general-handlers.c
 *
 * Copyrigth (C) 2010 Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or (at
 * your option) any later version.
 *
 * This program is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
 * USA
 */

#include <glib.h>

#include <mcabber/events.h>
#include <mcabber/logprint.h>

#include <jingle/jingle.h>
#include <jingle/general-handlers.h>

extern LmMessageHandler* jingle_ack_iq_handler;
gboolean evscallback_jingle(guint evcontext, const gchar *arg,
                            gpointer userdata)
{
  JingleNode *jn = userdata;

  // Demande à mcKael l'utilité de ce truc
  /*
  if (G_UNLIKELY(!jn)) {
    scr_LogPrint(LPRINT_LOGNORM, "Error in evs callback.");
    return FALSE;
  }
  */

  if (evcontext == EVS_CONTEXT_TIMEOUT) {
    scr_LogPrint(LPRINT_LOGNORM, "Jingle event from %s timed out, cancelled.",
                 jn->initiator);
    jingle_free_jinglenode(jn);
    return FALSE;
  }
  if (evcontext = EVS_CONTEXT_CANCEL) {
    scr_LogPrint(LPRINT_LOGNORM, "Jingle event from %s cancelled.",
                 jn->initiator);
    jingle_free_jinglenode(jn);
    return FALSE;
  }
  if (!(evcontext == EVS_CONTEXT_ACCEPT || evcontext == EVS_CONTEXT_REJECT)) {
    jingle_free_jinglenode(jn);
    return FALSE;
  }
  
  if (evcontext == EVS_CONTEXT_ACCEPT) {
    jingle_send_session_accept(jn);
  } else {
    jingle_send_session_terminate(jn, "decline");
    jingle_free_jinglenode(jn);
  }

  return FALSE;
}

LmHandlerResult jingle_handle_ack_iq (LmMessageHandler *handler,
                                      LmConnection *connection, 
                                      LmMessage *message, gpointer user_data)
{
  static GSList *ack_wait;
  GSList *child;
  LmMessageNode *node = lm_message_get_node(message);
  const gchar *id = lm_message_node_get_attribute(node, "id");
  ack_iq *ai;
  for (child = ack_wait; child; child = child->next) {
    ai = (ack_iq*)child->data;
    if(!g_strcmp0(ai->id, id)) {
      ai->callback(ai->udata);
      ack_wait = g_slist_remove(ack_wait, child);
      return LM_HANDLER_RESULT_REMOVE_MESSAGE;
    }
  }
  return LM_HANDLER_RESULT_ALLOW_MORE_HANDLERS;
}