56 // Make sure the request come from an user in our roster |
56 // Make sure the request come from an user in our roster |
57 disp = jidtodisp(lm_message_get_from(jn->message)); |
57 disp = jidtodisp(lm_message_get_from(jn->message)); |
58 if (!roster_find(disp, jidsearch, 0)) { |
58 if (!roster_find(disp, jidsearch, 0)) { |
59 // We say that we doesn't support jingle. |
59 // We say that we doesn't support jingle. |
60 jingle_send_iq_error(jn->message, "cancel", "service-unavailable", NULL); |
60 jingle_send_iq_error(jn->message, "cancel", "service-unavailable", NULL); |
61 jingle_free_jinglenode(jn); |
|
62 g_free(disp); |
61 g_free(disp); |
63 return; |
62 return; |
64 } |
63 } |
65 |
64 |
66 if (!check_contents(jn, &err)) { |
65 if (!check_contents(jn, &err)) { |
67 scr_log_print(LPRINT_DEBUG, "jingle: One of the content element was invalid (%s)", |
66 scr_log_print(LPRINT_DEBUG, "jingle: One of the content element was invalid (%s)", |
68 err->message); |
67 err->message); |
69 jingle_send_iq_error(jn->message, "cancel", "bad-request", NULL); |
68 jingle_send_iq_error(jn->message, "cancel", "bad-request", NULL); |
70 jingle_free_jinglenode(jn); |
|
71 g_free(disp); |
69 g_free(disp); |
72 return; |
70 return; |
73 } |
71 } |
74 |
72 |
75 // a session-initiate message must contains at least one <content> element |
73 // a session-initiate message must contains at least one <content> element |
76 if (g_slist_length(jn->content) < 1) { |
74 if (g_slist_length(jn->content) < 1) { |
77 jingle_send_iq_error(jn->message, "cancel", "bad-request", NULL); |
75 jingle_send_iq_error(jn->message, "cancel", "bad-request", NULL); |
78 jingle_free_jinglenode(jn); |
|
79 g_free(disp); |
76 g_free(disp); |
80 return; |
77 return; |
81 } |
78 } |
82 |
79 |
83 /* When sending a session-initiate at least one <content/> element MUST have |
80 /* When sending a session-initiate at least one <content/> element MUST have |
90 valid_disposition = TRUE; |
87 valid_disposition = TRUE; |
91 } |
88 } |
92 if (!valid_disposition) { |
89 if (!valid_disposition) { |
93 jingle_send_iq_error(jn->message, "cancel", "bad-request", NULL); |
90 jingle_send_iq_error(jn->message, "cancel", "bad-request", NULL); |
94 g_free(disp); |
91 g_free(disp); |
95 jingle_free_jinglenode(jn); |
|
96 return; |
92 return; |
97 } |
93 } |
98 |
94 |
99 // if a session with the same sid already exists |
95 // if a session with the same sid already exists |
100 if (session_find(jn) != NULL) { |
96 if (session_find(jn) != NULL) { |
101 jingle_send_iq_error(jn->message, "cancel", "unexpected-request", "out-of-order"); |
97 jingle_send_iq_error(jn->message, "cancel", "unexpected-request", "out-of-order"); |
102 g_free(disp); |
98 g_free(disp); |
103 jingle_free_jinglenode(jn); |
|
104 return; |
99 return; |
105 } |
100 } |
106 |
101 |
107 jingle_ack_iq(jn->message); |
102 jingle_ack_iq(jn->message); |
108 |
103 |
199 * does not understand the payload, it MUST return a |
193 * does not understand the payload, it MUST return a |
200 * <feature-not-implemented/> error with a Jingle-specific |
194 * <feature-not-implemented/> error with a Jingle-specific |
201 * error condition of <unsupported-info/>." */ |
195 * error condition of <unsupported-info/>." */ |
202 jingle_send_iq_error(jn->message, "modify", "feature-not-implemented", |
196 jingle_send_iq_error(jn->message, "modify", "feature-not-implemented", |
203 "unsupported-info"); |
197 "unsupported-info"); |
204 jingle_free_jinglenode(jn); |
|
205 } |
198 } |
206 |
199 |
207 void handle_session_accept(JingleNode *jn) |
200 void handle_session_accept(JingleNode *jn) |
208 { |
201 { |
209 JingleSession *sess; |
202 JingleSession *sess; |
210 JingleContent *jc; |
203 JingleContent *jc; |
211 SessionContent *sc; |
204 SessionContent *sc; |
212 session_content *sc2 = g_new0(session_content, 1); |
205 session_content *sc2 = g_new0(session_content, 1); |
213 |
206 GError *err; |
214 GSList *el; |
207 GSList *el; |
215 const gchar *from = lm_message_get_from(jn->message); |
208 const gchar *from = lm_message_get_from(jn->message); |
216 |
209 |
217 // We're looking if the session exist |
210 // We're looking if the session exist |
218 sess = session_find_by_sid(jn->sid, from); |
211 sess = session_find_by_sid(jn->sid, from); |
219 if (sess == NULL) { |
212 if (sess == NULL) { |
220 jingle_send_iq_error(jn->message, "cancel", "item-not-found", "unknown-session"); |
213 jingle_send_iq_error(jn->message, "cancel", "item-not-found", "unknown-session"); |
221 return; |
214 return; |
222 } |
215 } |
|
216 |
|
217 if (!check_contents(jn, &err)) { |
|
218 scr_log_print(LPRINT_DEBUG, "jingle: One of the content element was invalid (%s)", |
|
219 err->message); |
|
220 jingle_send_iq_error(jn->message, "cancel", "bad-request", NULL); |
|
221 return; |
|
222 } |
223 |
223 |
224 jingle_ack_iq(jn->message); |
224 jingle_ack_iq(jn->message); |
225 |
225 |
|
226 sc2->sid = sess->sid; |
|
227 sc2->from = (sess->origin == JINGLE_SESSION_INCOMING) ? sess->from : sess->to; |
|
228 |
|
229 // TODO: it's really bad done! |
226 for (el = jn->content; el; el = el->next) { |
230 for (el = jn->content; el; el = el->next) { |
227 jc = (JingleContent*)el->data; |
231 jc = (JingleContent*)el->data; |
|
232 sc2->name = jc->name; |
|
233 sc = session_find_sessioncontent(sess, jc->name); |
228 session_changestate_sessioncontent(sess, jc->name, |
234 session_changestate_sessioncontent(sess, jc->name, |
229 JINGLE_SESSION_STATE_ACTIVE); |
235 JINGLE_SESSION_STATE_ACTIVE); |
230 } |
236 sc->transfuncs->init(sc2, sc->transfuncs->check(jc, NULL)); |
231 |
237 } |
232 // We delete content who have been refuse |
238 |
233 /*for (el = sess->content; el; el = el->next) { |
239 // We delete content who haven't been accepted |
|
240 for (el = sess->content; el; el = el->next) { |
234 sc = (SessionContent*) el->data; |
241 sc = (SessionContent*) el->data; |
235 if (sc->state == JINGLE_SESSION_STATE_PENDING) { |
242 if (sc->state == JINGLE_SESSION_STATE_PENDING) { |
236 scr_log_print(LPRINT_DEBUG, "Delete %s!", sc->name); |
243 scr_log_print(LPRINT_DEBUG, "Delete %s!", sc->name); |
237 session_remove_sessioncontent(sess, sc->name); |
244 session_remove_sessioncontent(sess, sc->name); |
238 } |
245 } |
239 }*/ |
246 } |
240 |
247 |
241 // Go go go! We start jobs! |
248 // Go go go! We start jobs! |
242 for (el = sess->content; el; el = el->next) { |
249 for (el = sess->content; el; el = el->next) { |
243 sc = (SessionContent*)el->data; |
250 sc = (SessionContent*)el->data; |
244 sc2->sid = sess->sid; |
|
245 sc2->from = (sess->origin == JINGLE_SESSION_INCOMING) ? sess->from : sess->to; |
|
246 sc2->name = sc->name; |
251 sc2->name = sc->name; |
247 sc->appfuncs->start(sc2); |
252 sc->appfuncs->start(sc2); |
248 } |
253 } |
249 jingle_free_jinglenode(jn); |
|
250 } |
254 } |
251 |
255 |
252 void handle_session_terminate(JingleNode *jn) |
256 void handle_session_terminate(JingleNode *jn) |
253 { |
257 { |
254 JingleSession *sess; |
258 JingleSession *sess; |