--- a/jingle/action-handlers.c Thu Jul 08 00:08:34 2010 +0200
+++ b/jingle/action-handlers.c Thu Jul 08 00:35:37 2010 +0200
@@ -47,6 +47,7 @@
JingleTransportFuncs *transfuncs;
gconstpointer description, transport;
const gchar *xmlns;
+ JingleSession *sess;
if (!check_contents(jn, &err)) {
scr_log_print(LPRINT_DEBUG, "jingle: One of the content element was invalid (%s)",
@@ -55,14 +56,14 @@
return;
}
- // it's better if there is at least one content elem */
+ /* it's better if there is at least one content elem */
if (g_slist_length(jn->content) < 1) {
jingle_send_iq_error(m, "cancel", "bad-request", NULL);
return;
}
// if a session with the same sid doesn't already exists
- if (session_find(jn) == NULL) {
+ if ((sess = session_find(jn)) == NULL) {
jingle_send_iq_error(m, "cancel", "unexpected-request", "out-of-order");
return;
}
@@ -84,9 +85,60 @@
if (description == NULL || err != NULL) continue;
transport = transfuncs->check(cn, &err);
if (transport == NULL || err != NULL) continue;
+ session_add_content(sess, cn);
}
}
+void handle_content_remove(LmMessage *m, JingleNode *jn)
+{
+ GError *err = NULL;
+ GSList *child = NULL;
+ JingleContent *cn;
+ JingleAppFuncs *appfuncs;
+ JingleTransportFuncs *transfuncs;
+ gconstpointer description, transport;
+ const gchar *xmlns;
+ JingleSession *sess;
+
+ if (!check_contents(jn, &err)) {
+ scr_log_print(LPRINT_DEBUG, "jingle: One of the content element was invalid (%s)",
+ err->message);
+ jingle_send_iq_error(m, "cancel", "bad-request", NULL);
+ return;
+ }
+
+ /* it's better if there is at least one content elem */
+ if (g_slist_length(jn->content) < 1) {
+ jingle_send_iq_error(m, "cancel", "bad-request", NULL);
+ return;
+ }
+
+ // if a session with the same sid doesn't already exists
+ if ((sess = session_find(jn)) == NULL) {
+ jingle_send_iq_error(m, "cancel", "unexpected-request", "out-of-order");
+ return;
+ }
+
+ jingle_ack_iq(m);
+
+ for (child = jn->content; child; child = child->next) {
+ cn = (JingleContent *)(child->data);
+
+ xmlns = lm_message_node_get_attribute(cn->description, "xmlns");
+ appfuncs = jingle_get_appfuncs(xmlns);
+ if (appfuncs == NULL) continue;
+
+ xmlns = lm_message_node_get_attribute(cn->transport, "xmlns");
+ transfuncs = jingle_get_transportfuncs(xmlns);
+ if (appfuncs == NULL) continue;
+
+ description = appfuncs->check(cn, &err);
+ if (description == NULL || err != NULL) continue;
+ transport = transfuncs->check(cn, &err);
+ if (transport == NULL || err != NULL) continue;
+ session_add_content(sess, cn);
+ }
+}
void handle_session_initiate(LmMessage *m, JingleNode *jn)
{
@@ -98,6 +150,7 @@
JingleTransportFuncs *transfuncs;
gconstpointer description, transport;
const gchar *xmlns;
+ JingleSession* sess;
if (!check_contents(jn, &err)) {
scr_log_print(LPRINT_DEBUG, "jingle: One of the content element was invalid (%s)",
@@ -134,6 +187,8 @@
jingle_ack_iq(m);
+ sess = session_new(jn);
+
for (child = jn->content; child; child = child->next) {
cn = (JingleContent *)(child->data);
@@ -149,7 +204,15 @@
if (description == NULL || err != NULL) continue;
transport = transfuncs->check(cn, &err);
if (transport == NULL || err != NULL) continue;
+
+ session_add_content(sess, cn);
}
+
+ if(g_slist_length(sess->content) == 0) {
+ jingle_send_session_terminate(jn, "unsupported-applications");
+ }
+
+
}
void handle_session_terminate(LmMessage *m, JingleNode *jn)
--- a/jingle/register.h Thu Jul 08 00:08:34 2010 +0200
+++ b/jingle/register.h Thu Jul 08 00:35:37 2010 +0200
@@ -11,12 +11,10 @@
typedef gconstpointer (*JingleAppCheck) (JingleContent *cn, GError **err);
typedef void (*JingleAppHandle) (JingleNode *jn, JingleContent *cn);
typedef LmMessageNode* (*JingleAppGetLM) (gconstpointer data);
-typedef gboolean (*JingleAppCmp) (gconstpointer data, gconstpointer data2);
typedef gconstpointer (*JingleTransportCheck) (JingleContent *cn, GError **err);
typedef void (*JingleTransportHandle) (JingleNode *jn, JingleContent *cn);
typedef LmMessageNode* (*JingleTransportGetLM) (gconstpointer data);
-typedef gboolean (*JingleTransportCmp) (gconstpointer data, gconstpointer data2);
typedef struct {
/* check if the description of a JingleContent is correct */
@@ -27,8 +25,6 @@
/* If we got a LM with the good xmlns */
JingleAppHandle handle;
-
- JingleAppCmp cmp;
} JingleAppFuncs;
@@ -41,8 +37,6 @@
/* */
JingleAppHandle handle;
- JingleTransportCmp cmp;
-
} JingleTransportFuncs;
--- a/jingle/send.c Thu Jul 08 00:08:34 2010 +0200
+++ b/jingle/send.c Thu Jul 08 00:35:37 2010 +0200
@@ -32,6 +32,7 @@
void jingle_send_session_terminate(JingleNode *jn, const gchar *reason)
{
LmMessage *r;
+ LmMessageNode *err;
JingleNode *reply = g_new0(JingleNode, 1);
reply->action = JINGLE_SESSION_TERMINATE;
--- a/jingle/sessions.c Thu Jul 08 00:08:34 2010 +0200
+++ b/jingle/sessions.c Thu Jul 08 00:35:37 2010 +0200
@@ -73,6 +73,9 @@
void session_add_content(JingleSession *sess, JingleContent *cn)
{
SessionContent *sc = g_new0(SessionContent, 1);
+
+ sc->name = cn->name;
+
const gchar *tmpchar = lm_message_node_get_attribute(cn->description,
"xmlns");
sc->appfuncs = jingle_get_appfuncs(tmpchar);
@@ -86,19 +89,26 @@
}
SessionContent *session_find_sessioncontent(JingleSession *sess,
- gconstpointer desc, gconstpointer trans)
+ const gchar *name)
{
GSList *el;
SessionContent *sc;
for (el = sess->content; el; el = el->next) {
sc = (SessionContent*) el->data;
- if (sc->appfuncs->cmp(sc->description, desc) == TRUE &&
- sc->transfuncs->cmp(sc->transport, trans) == TRUE)
+ if (g_strcmp0(sc->name, name))
return sc;
}
return NULL;
}
+void session_remove_sessioncontent(JingleSession *sess, const gchar *name)
+{
+ SessionContent *sc;
+ sc = session_find_sessioncontent(sess, name);
+ if(sc != NULL)
+ sess->content = g_slist_remove(sess->content, sc);
+}
+
/**
* Remove a session from the linked list and free it.
*/
--- a/jingle/sessions.h Thu Jul 08 00:08:34 2010 +0200
+++ b/jingle/sessions.h Thu Jul 08 00:35:37 2010 +0200
@@ -19,6 +19,7 @@
} JingleSession;
typedef struct {
+ const gchar *name;
gconstpointer description;
JingleAppFuncs *appfuncs;
gconstpointer transport;
@@ -30,7 +31,8 @@
JingleSession *session_find_by_sid(const gchar *sid, const gchar *from);
JingleSession *session_find(const JingleNode *jn);
void session_add_content(JingleSession *sess, JingleContent *cn);
-SessionContent *session_find_sessioncontent(JingleSession *sess, gconstpointer desc, gconstpointer trans);
+SessionContent *session_find_sessioncontent(JingleSession *sess, const gchar *name);
+void session_remove_sessioncontent(JingleSession *sess, const gchar *name);
void session_delete(JingleSession *sess);
void session_remove(JingleSession *sess);
void session_free(JingleSession *sess);