jingle/action-handlers.c
changeset 119 0b9a7b505079
parent 114 813867884159
child 121 3a3c0e16ea00
equal deleted inserted replaced
118:f3408f4fe61a 119:0b9a7b505079
    73 
    73 
    74   for (child = jn->content; child; child = child->next) {
    74   for (child = jn->content; child; child = child->next) {
    75     cn = (JingleContent *)(child->data);
    75     cn = (JingleContent *)(child->data);
    76     session_changestate_sessioncontent(sess, cn->name, JINGLE_SESSION_STATE_ACTIVE);
    76     session_changestate_sessioncontent(sess, cn->name, JINGLE_SESSION_STATE_ACTIVE);
    77   }
    77   }
       
    78   jingle_free_jinglenode(jn);
    78 }
    79 }
    79 
    80 
    80 void handle_content_add(JingleNode *jn)
    81 void handle_content_add(JingleNode *jn)
    81 {
    82 {
    82   GError *err = NULL;
    83   GError *err = NULL;
   170       if (err != NULL) {
   171       if (err != NULL) {
   171         // TODO
   172         // TODO
   172       }
   173       }
   173     }
   174     }
   174   }
   175   }
       
   176   jingle_free_jinglenode(jn);
   175 }
   177 }
   176 
   178 
   177 void handle_content_reject(JingleNode *jn)
   179 void handle_content_reject(JingleNode *jn)
   178 {
   180 {
   179   GError *err = NULL;
   181   GError *err = NULL;
   213   if (g_slist_length(sess->content) == 0) {
   215   if (g_slist_length(sess->content) == 0) {
   214     jingle_send_session_terminate(sess, "success");
   216     jingle_send_session_terminate(sess, "success");
   215     session_delete(sess);
   217     session_delete(sess);
   216     return;
   218     return;
   217   }
   219   }
       
   220   jingle_free_jinglenode(jn);
   218 }
   221 }
   219 
   222 
   220 void handle_content_remove(JingleNode *jn)
   223 void handle_content_remove(JingleNode *jn)
   221 {
   224 {
   222   GError *err = NULL;
   225   GError *err = NULL;
   230 
   233 
   231   if (!check_contents(jn, &err)) {
   234   if (!check_contents(jn, &err)) {
   232     scr_log_print(LPRINT_DEBUG, "jingle: One of the content element was invalid (%s)",
   235     scr_log_print(LPRINT_DEBUG, "jingle: One of the content element was invalid (%s)",
   233                   err->message);
   236                   err->message);
   234     jingle_send_iq_error(jn->message, "cancel", "bad-request", NULL);
   237     jingle_send_iq_error(jn->message, "cancel", "bad-request", NULL);
       
   238     jingle_free_jinglenode(jn);
   235     return;
   239     return;
   236   }
   240   }
   237 
   241 
   238   /* it's better if there is at least one content elem */
   242   /* it's better if there is at least one content elem */
   239   if (g_slist_length(jn->content) < 1) {
   243   if (g_slist_length(jn->content) < 1) {
   240     jingle_send_iq_error(jn->message, "cancel", "bad-request", NULL);
   244     jingle_send_iq_error(jn->message, "cancel", "bad-request", NULL);
       
   245     jingle_free_jinglenode(jn);
   241     return;
   246     return;
   242   }
   247   }
   243   
   248   
   244   // if a session with the same sid doesn't already exists
   249   // if a session with the same sid doesn't already exists
   245   if ((sess = session_find(jn)) == NULL) {
   250   if ((sess = session_find(jn)) == NULL) {
   246     jingle_send_iq_error(jn->message, "cancel", "item-not-found", "unknown-session");
   251     // TODO: look if it's really that
       
   252     jingle_send_iq_error(jn->message, "cancel", "item-not-found", "unknown-session");
       
   253     jingle_free_jinglenode(jn);
   247     return;
   254     return;
   248   }
   255   }
   249 
   256 
   250   jingle_ack_iq(jn->message);
   257   jingle_ack_iq(jn->message);
   251 
   258 
   252   for (child = jn->content; child; child = child->next) {
   259   for (child = jn->content; child; child = child->next) {
   253     cn = (JingleContent *)(child->data);
   260     cn = (JingleContent *)(child->data);
   254     session_remove_sessioncontent(sess, cn->name);
   261     session_remove_sessioncontent(sess, cn->name);
   255   }
   262   }
       
   263   jingle_free_jinglenode(jn);
   256 }
   264 }
   257 
   265 
   258 void handle_session_initiate(JingleNode *jn)
   266 void handle_session_initiate(JingleNode *jn)
   259 {
   267 {
   260   GError *err = NULL;
   268   GError *err = NULL;
   262   JingleContent *cn;
   270   JingleContent *cn;
   263   GString *sbuf;
   271   GString *sbuf;
   264   GSList *child = NULL;
   272   GSList *child = NULL;
   265   LmMessage *r;
   273   LmMessage *r;
   266   gchar *disp;
   274   gchar *disp;
       
   275   JingleSession *sess;
       
   276   const gchar *xmlns;
       
   277   JingleAppFuncs *appfuncs;
       
   278   JingleTransportFuncs *transfuncs;
       
   279   gconstpointer description, transport;
   267   
   280   
   268   // Make sure the request come from an user in our roster
   281   // Make sure the request come from an user in our roster
   269   disp = jidtodisp(lm_message_get_from(jn->message));
   282   disp = jidtodisp(lm_message_get_from(jn->message));
   270   if (!roster_find(disp, jidsearch, 0)) {
   283   if (!roster_find(disp, jidsearch, 0)) {
   271     // jingle_send_session_terminate(jn, "decline");
   284     // We say that we doesn't support jingle.
       
   285     jingle_send_iq_error(jn->message, "cancel", "service-unavailable", NULL);
   272     jingle_free_jinglenode(jn);
   286     jingle_free_jinglenode(jn);
   273     g_free(disp);
   287     g_free(disp);
   274     return;
   288     return;
   275   }
   289   }
   276   
   290   
   277   if (!check_contents(jn, &err)) {
   291   if (!check_contents(jn, &err)) {
   278     scr_log_print(LPRINT_DEBUG, "jingle: One of the content element was invalid (%s)",
   292     scr_log_print(LPRINT_DEBUG, "jingle: One of the content element was invalid (%s)",
   279                   err->message);
   293                   err->message);
   280     jingle_send_iq_error(jn->message, "cancel", "bad-request", NULL);
   294     jingle_send_iq_error(jn->message, "cancel", "bad-request", NULL);
       
   295     jingle_free_jinglenode(jn);
   281     g_free(disp);
   296     g_free(disp);
   282     return;
   297     return;
   283   }
   298   }
   284 
   299 
   285   // a session-initiate message must contains at least one <content> element
   300   // a session-initiate message must contains at least one <content> element
   286   if (g_slist_length(jn->content) < 1) {
   301   if (g_slist_length(jn->content) < 1) {
   287     jingle_send_iq_error(jn->message, "cancel", "bad-request", NULL);
   302     jingle_send_iq_error(jn->message, "cancel", "bad-request", NULL);
       
   303     jingle_free_jinglenode(jn);
   288     g_free(disp);
   304     g_free(disp);
   289     return;
   305     return;
   290   }
   306   }
   291   
   307   
   292   /* When sending a session-initiate at least one <content/> element MUST have
   308   /* When sending a session-initiate at least one <content/> element MUST have
   299       valid_disposition = TRUE;
   315       valid_disposition = TRUE;
   300   }
   316   }
   301   if (!valid_disposition) {
   317   if (!valid_disposition) {
   302     jingle_send_iq_error(jn->message, "cancel", "bad-request", NULL);
   318     jingle_send_iq_error(jn->message, "cancel", "bad-request", NULL);
   303     g_free(disp);
   319     g_free(disp);
       
   320     jingle_free_jinglenode(jn);
   304     return;  
   321     return;  
   305   }
   322   }
   306   
   323   
   307   // if a session with the same sid already exists
   324   // if a session with the same sid already exists
   308   if (session_find(jn) != NULL) {
   325   if (session_find(jn) != NULL) {
   309     jingle_send_iq_error(jn->message, "cancel", "unexpected-request", "out-of-order");
   326     jingle_send_iq_error(jn->message, "cancel", "unexpected-request", "out-of-order");
   310     g_free(disp);
   327     g_free(disp);
   311     return;
   328     jingle_free_jinglenode(jn);
   312   }
   329     return;
   313 
   330   }
   314   jingle_ack_iq(jn->message);
   331 
   315 
   332   jingle_ack_iq(jn->message);
       
   333 
       
   334   // We create a session
       
   335   sess = session_new_from_jinglenode(jn);
       
   336   
       
   337   for (child = jn->content; child; child = child->next) {
       
   338     cn = (JingleContent *)(child->data);
       
   339     
       
   340     xmlns = lm_message_node_get_attribute(cn->description, "xmlns");
       
   341     appfuncs = jingle_get_appfuncs(xmlns);
       
   342     if (appfuncs == NULL) continue;
       
   343     
       
   344     xmlns = lm_message_node_get_attribute(cn->transport, "xmlns");
       
   345     transfuncs = jingle_get_transportfuncs(xmlns);
       
   346     if (transfuncs == NULL) continue;
       
   347     
       
   348     description = appfuncs->check(cn, &err);
       
   349     if (description == NULL || err != NULL) continue;
       
   350     transport = transfuncs->check(cn, &err);
       
   351     if (transport == NULL || err != NULL) continue;
       
   352     
       
   353     session_add_content_from_jinglecontent(sess, cn,
       
   354                                            JINGLE_SESSION_STATE_PENDING);
       
   355   }
       
   356   
       
   357   if(g_slist_length(sess->content) == 0) {
       
   358     jingle_send_session_terminate(sess, "unsupported-applications");
       
   359     session_delete(sess);
       
   360     return;
       
   361   }
       
   362   
   316   // Wait that user accept the jingle
   363   // Wait that user accept the jingle
   317   sbuf = g_string_new("");
   364   sbuf = g_string_new("");
   318   g_string_printf(sbuf, "Received an invitation for a jingle session from <%s>", lm_message_get_from(jn->message));
   365   g_string_printf(sbuf, "Received an invitation for a jingle session from <%s>",
       
   366                   lm_message_get_from(jn->message));
   319 
   367 
   320   scr_WriteIncomingMessage(disp, sbuf->str, 0, HBB_PREFIX_INFO, 0);
   368   scr_WriteIncomingMessage(disp, sbuf->str, 0, HBB_PREFIX_INFO, 0);
   321   scr_LogPrint(LPRINT_LOGNORM, "%s", sbuf->str);
   369   scr_LogPrint(LPRINT_LOGNORM, "%s", sbuf->str);
   322 
   370 
   323   {
   371   {
   324     const char *id;
   372     const char *id;
   325     char *desc = g_strdup_printf("<%s> invites you to do a jingle session", lm_message_get_from(jn->message));
   373     char *desc = g_strdup_printf("<%s> invites you to do a jingle session",
   326 
   374                                  lm_message_get_from(jn->message));
   327     id = evs_new(desc, NULL, 0, evscallback_jingle, jn, NULL);
   375 
       
   376     id = evs_new(desc, NULL, 0, evscallback_jingle, sess, NULL);
   328     g_free(desc);
   377     g_free(desc);
   329     if (id)
   378     if (id)
   330       g_string_printf(sbuf, "Please use /event %s accept|reject", id);
   379       g_string_printf(sbuf, "Please use /event %s accept|reject", id);
   331     else
   380     else
   332       g_string_printf(sbuf, "Unable to create a new event!");
   381       g_string_printf(sbuf, "Unable to create a new event!");
   333     scr_WriteIncomingMessage(disp, sbuf->str, 0, HBB_PREFIX_INFO, 0);
   382     scr_WriteIncomingMessage(disp, sbuf->str, 0, HBB_PREFIX_INFO, 0);
   334     scr_LogPrint(LPRINT_LOGNORM, "%s", sbuf->str);
   383     scr_LogPrint(LPRINT_LOGNORM, "%s", sbuf->str);
   335   }
   384   }
   336   g_free(disp);
   385   g_free(disp);
       
   386   jingle_free_jinglenode(jn);
   337 }
   387 }
   338 
   388 
   339 void handle_session_info(JingleNode *jn)
   389 void handle_session_info(JingleNode *jn)
   340 {
   390 {
   341   JingleSession *sess;
   391   JingleSession *sess;
   374    * does not understand the payload, it MUST return a
   424    * does not understand the payload, it MUST return a
   375    * <feature-not-implemented/> error with a Jingle-specific
   425    * <feature-not-implemented/> error with a Jingle-specific
   376    * error condition of <unsupported-info/>." */
   426    * error condition of <unsupported-info/>." */
   377   jingle_send_iq_error(jn->message, "modify", "feature-not-implemented",
   427   jingle_send_iq_error(jn->message, "modify", "feature-not-implemented",
   378                        "unsupported-info");
   428                        "unsupported-info");
       
   429   jingle_free_jinglenode(jn);
   379 }
   430 }
   380 
   431 
   381 void handle_session_accept(JingleNode *jn)
   432 void handle_session_accept(JingleNode *jn)
   382 {
   433 {
   383   JingleSession *sess;
   434   JingleSession *sess;
   419     sc2->sid = sess->sid;
   470     sc2->sid = sess->sid;
   420     sc2->from = (sess->origin == JINGLE_SESSION_INCOMING) ? sess->from : sess->to;
   471     sc2->from = (sess->origin == JINGLE_SESSION_INCOMING) ? sess->from : sess->to;
   421     sc2->name = sc->name;
   472     sc2->name = sc->name;
   422     sc->appfuncs->start(sc2, 2048);
   473     sc->appfuncs->start(sc2, 2048);
   423   }
   474   }
   424 
   475   jingle_free_jinglenode(jn);
   425 }
   476 }
   426 
   477 
   427 void handle_session_terminate(JingleNode *jn)
   478 void handle_session_terminate(JingleNode *jn)
   428 {
   479 {
   429   JingleSession *sess;
   480   JingleSession *sess;
   442       sc->appfuncs->stop(sc->description);
   493       sc->appfuncs->stop(sc->description);
   443     session_remove_sessioncontent(sess, sc->name);
   494     session_remove_sessioncontent(sess, sc->name);
   444   }
   495   }
   445   session_delete(sess);
   496   session_delete(sess);
   446   jingle_ack_iq(jn->message);
   497   jingle_ack_iq(jn->message);
   447 }
   498   jingle_free_jinglenode(jn);
       
   499 }