Commit 687c3197 authored by Pekka Pessi's avatar Pekka Pessi

soa: fixed restoring state after failed offer

darcs-hash:20090116192739-db55f-b6e4ec723e700deb455da1edc95b6ed2b8a93e60.gz
parent 3f9a1e6f
......@@ -938,7 +938,7 @@ soa_base_set_capability_sdp(soa_session_t *ss,
*
* <i>User SDP</i> is used as basis for SDP Offer/Answer negotiation. It can
* be very minimal template, consisting just m= line containing media name,
* transport protocol port number and list of supported codecs.
* transport protocol, port number and list of supported codecs.
*
* The SDP used as an offer or answer (generated by soa_generate_answer() or
* soa_generate_offer()) is known as <i>local SDP</i> and it is available
......@@ -1703,13 +1703,10 @@ int soa_base_process_reject(soa_session_t *ss,
(void)completed;
if (!l_sdp)
return -1;
soa_set_activity(ss, l_sdp->sdp_media, soa_activity_session);
ss->ss_offer_sent = 0;
soa_set_activity(ss, l_sdp ? l_sdp->sdp_media : NULL, soa_activity_session);
return 0;
}
......
......@@ -84,6 +84,11 @@ typedef struct soa_static_session
/** Mapping from session SDP m= lines to user SDP m= lines */
int *sss_s2u;
/** State kept from SDP before current offer */
struct {
int *u2s, *s2u;
} sss_previous;
/** Our latest offer or answer */
sdp_session_t *sss_latest;
}
......@@ -886,6 +891,7 @@ int soa_sdp_upgrade(soa_session_t *ss,
return 0;
}
static
int *u2s_alloc(su_home_t *home, int const *u2s)
{
if (u2s) {
......@@ -1318,6 +1324,8 @@ static int offer_answer_step(soa_session_t *ss,
}
soa_description_free(ss, ss->ss_previous);
su_free(ss->ss_home, sss->sss_previous.u2s), sss->sss_previous.u2s = NULL;
su_free(ss->ss_home, sss->sss_previous.s2u), sss->sss_previous.s2u = NULL;
if (u2s) {
u2s = u2s_alloc(ss->ss_home, u2s);
......@@ -1358,10 +1366,18 @@ static int offer_answer_step(soa_session_t *ss,
if (action == generate_offer) {
/* Keep a copy of previous session state */
int *previous_u2s = u2s_alloc(ss->ss_home, sss->sss_u2s);
int *previous_s2u = u2s_alloc(ss->ss_home, sss->sss_s2u);
if ((sss->sss_u2s && !previous_u2s) || (sss->sss_s2u && !previous_s2u))
goto internal_error;
*ss->ss_previous = *ss->ss_local;
memset(ss->ss_local, 0, (sizeof *ss->ss_local));
ss->ss_previous_user_version = ss->ss_local_user_version;
ss->ss_previous_remote_version = ss->ss_local_remote_version;
sss->sss_previous.u2s = previous_u2s;
sss->sss_previous.s2u = previous_s2u;
}
SU_DEBUG_7(("soa_static(%p, %s): %s\n", (void *)ss, by,
......@@ -1374,6 +1390,8 @@ static int offer_answer_step(soa_session_t *ss,
memset(ss->ss_previous, 0, (sizeof *ss->ss_previous));
ss->ss_previous_user_version = 0;
ss->ss_previous_remote_version = 0;
su_free(ss->ss_home, sss->sss_previous.u2s), sss->sss_previous.u2s = NULL;
su_free(ss->ss_home, sss->sss_previous.s2u), sss->sss_previous.s2u = NULL;
}
su_free(ss->ss_home, u2s), su_free(ss->ss_home, s2u);
......@@ -1467,21 +1485,26 @@ static int soa_static_process_answer(soa_session_t *ss,
static int soa_static_process_reject(soa_session_t *ss,
soa_callback_f *completed)
{
soa_static_session_t *sss = (soa_static_session_t *)ss;
struct soa_description d[1];
if (ss->ss_previous_user_version) {
*d = *ss->ss_local;
*ss->ss_local = *ss->ss_previous;
ss->ss_local_user_version = ss->ss_previous_user_version;
ss->ss_local_remote_version = ss->ss_previous_remote_version;
soa_base_process_reject(ss, NULL);
memset(ss->ss_previous, 0, (sizeof *ss->ss_previous));
soa_description_free(ss, d);
ss->ss_previous_user_version = 0;
ss->ss_previous_remote_version = 0;
}
*d = *ss->ss_local;
*ss->ss_local = *ss->ss_previous;
ss->ss_local_user_version = ss->ss_previous_user_version;
ss->ss_local_remote_version = ss->ss_previous_remote_version;
memset(ss->ss_previous, 0, (sizeof *ss->ss_previous));
soa_description_free(ss, d);
su_free(ss->ss_home, sss->sss_previous.u2s), sss->sss_previous.u2s = NULL;
su_free(ss->ss_home, sss->sss_previous.s2u), sss->sss_previous.s2u = NULL;
ss->ss_previous_user_version = 0;
ss->ss_previous_remote_version = 0;
return soa_base_process_reject(ss, NULL);
su_free(ss->ss_home, sss->sss_latest), sss->sss_latest = NULL;
return 0;
}
static int soa_static_activate(soa_session_t *ss, char const *option)
......@@ -1496,6 +1519,19 @@ static int soa_static_deactivate(soa_session_t *ss, char const *option)
static void soa_static_terminate(soa_session_t *ss, char const *option)
{
soa_description_free(ss, ss->ss_user);
soa_static_session_t *sss = (soa_static_session_t *)ss;
soa_description_free(ss, ss->ss_local);
su_free(ss->ss_home, sss->sss_u2s), sss->sss_u2s = NULL;
su_free(ss->ss_home, sss->sss_s2u), sss->sss_s2u = NULL;
soa_description_free(ss, ss->ss_previous);
ss->ss_previous_user_version = 0;
ss->ss_previous_remote_version = 0;
su_free(ss->ss_home, sss->sss_previous.u2s), sss->sss_previous.u2s = NULL;
su_free(ss->ss_home, sss->sss_previous.s2u), sss->sss_previous.s2u = NULL;
su_free(ss->ss_home, sss->sss_latest), sss->sss_latest = NULL;
soa_base_terminate(ss, option);
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment