jingle/sessions.c
changeset 67 c12618793df0
parent 63 b56853071a09
child 75 bd48c89b0a3d
equal deleted inserted replaced
66:cd16ab43a285 67:c12618793df0
    32 
    32 
    33 
    33 
    34 /**
    34 /**
    35  * Create a new session and insert it in the linked list.
    35  * Create a new session and insert it in the linked list.
    36  */
    36  */
    37 JingleSession *session_new(JingleNode *jn)
    37 JingleSession *session_new(const gchar *sid, const gchar *initiator,
       
    38                            const gchar *from)
    38 {
    39 {
    39   JingleSession *js = g_new0(JingleSession, 1);
    40   JingleSession *js = g_new0(JingleSession, 1);
       
    41   
       
    42   js->sid = g_strdup(sid);
       
    43   js->initiator = g_strdup(initiator);
       
    44   js->from = g_strdup(from);
       
    45   
       
    46   sessions = g_slist_append(sessions, js);
       
    47   return js;
       
    48 }
       
    49 
       
    50 JingleSession *session_new_from_jinglenode(JingleNode *jn)
       
    51 {
    40   const gchar *from;
    52   const gchar *from;
    41   
    53   
    42   js->sid = g_strdup(jn->sid);
       
    43   js->initiator = g_strdup(jn->initiator);
       
    44   from = lm_message_get_from(jn->message);
    54   from = lm_message_get_from(jn->message);
    45   if (!from) {
    55   if (!from) {
    46     return NULL;
    56     return NULL;
    47   }
    57   }
    48   js->from = g_strdup(from);
    58  
    49 
    59   return session_new(jn->sid, jn->initiator, from);
    50   sessions = g_slist_append(sessions, js);
       
    51   return js;
       
    52 }
    60 }
    53 
    61 
    54 JingleSession *session_find_by_sid(const gchar *sid, const gchar *from)
    62 JingleSession *session_find_by_sid(const gchar *sid, const gchar *from)
    55 {
    63 {
    56   GSList *el;
    64   GSList *el;
    68 {
    76 {
    69   const gchar *from = lm_message_get_from(jn->message);
    77   const gchar *from = lm_message_get_from(jn->message);
    70   return session_find_by_sid(jn->sid, from);
    78   return session_find_by_sid(jn->sid, from);
    71 }
    79 }
    72 
    80 
    73 void session_add_content(JingleSession *sess, JingleContent *cn,
    81 void session_add_content(JingleSession *sess, const gchar *name,
    74                          SessionState state)
    82                          SessionState state)
    75 {
    83 {
    76   SessionContent *sc = g_new0(SessionContent, 1);
    84   SessionContent *sc = g_new0(SessionContent, 1);
    77   
    85   
    78   sc->name = cn->name;
    86   sc->name = name;
    79   sc->state = state;
    87   sc->state = state;
       
    88 
       
    89   sess->content = g_slist_append(sess->content, sc);
       
    90 }
       
    91 
       
    92 void session_add_app(JingleSession *sess, const gchar *name,
       
    93                            const gchar *xmlns, gconstpointer data)
       
    94 {
       
    95   SessionContent *sc = session_find_sessioncontent(sess, name);
    80   
    96   
    81   sc->xmlns_desc = lm_message_node_get_attribute(cn->description, "xmlns");
    97   sc->xmlns_desc = xmlns;
    82   sc->appfuncs = jingle_get_appfuncs(sc->xmlns_desc);
    98   sc->appfuncs = jingle_get_appfuncs(xmlns);
    83   sc->xmlns_trans = lm_message_node_get_attribute(cn->transport, "xmlns");
    99   sc->description = data;
    84   sc->transfuncs = jingle_get_transportfuncs(sc->xmlns_trans);
   100 }
    85   sc->description = sc->appfuncs->check(cn, NULL);
   101 
    86   sc->transport = sc->transfuncs->check(cn, NULL);
   102 void session_add_trans(JingleSession *sess, const gchar *name,
       
   103                            const gchar *xmlns, gconstpointer data)
       
   104 {
       
   105   SessionContent *sc = session_find_sessioncontent(sess, name);
    87   
   106   
    88   sess->content = g_slist_append(sess->content, sc);
   107   sc->xmlns_trans = xmlns;
       
   108   sc->transfuncs = jingle_get_transportfuncs(xmlns);
       
   109   sc->transport = data;
       
   110 }
       
   111 
       
   112 void session_add_content_from_jinglecontent(JingleSession *sess, JingleContent *cn,
       
   113                          SessionState state)
       
   114 {
       
   115   SessionContent *sc = g_new0(SessionContent, 1);
       
   116   session_add_content(sess, cn->name, state);
       
   117   session_add_app(sess, cn->name,
       
   118                   lm_message_node_get_attribute(cn->description, "xmlns"),
       
   119                   sc->appfuncs->check(cn, NULL));
       
   120   session_add_trans(sess, cn->name,
       
   121                   lm_message_node_get_attribute(cn->transport, "xmlns"),
       
   122                   sc->transfuncs->check(cn, NULL));
    89 }
   123 }
    90 
   124 
    91 SessionContent *session_find_sessioncontent(JingleSession *sess,
   125 SessionContent *session_find_sessioncontent(JingleSession *sess,
    92                                             const gchar *name)
   126                                             const gchar *name)
    93 {
   127 {