示例#1
0
/**
 * Creates an operation handle and binds it to
 * an existing handle 'nh' (does not create a new nua
 * handle with nua_handle()).
 */
ssc_oper_t *ssc_oper_create_with_handle(ssc_t *ssc,
                                        sip_method_t method,
                                        char const *name,
                                        nua_handle_t *nh,
                                        sip_from_t const *from)
{
    ssc_oper_t *op;

    enter;

    if ((op = su_zalloc(ssc->ssc_home, sizeof(*op)))) {
        op->op_next = ssc->ssc_operations;
        ssc->ssc_operations = op;

        ssc_oper_assign(op, method, name);
        nua_handle_bind(op->op_handle = nh, op);
        op->op_ident = sip_header_as_string(ssc->ssc_home, (sip_header_t*)from);
        op->op_ssc = ssc;
    }
    else {
        printf("%s: cannot create operation object for %s\n",
               ssc->ssc_name, name);
    }

    return op;
}
static apt_bool_t mrcp_sofia_session_unref(mrcp_sofia_session_t *sofia_session)
{
	if(sofia_session->nh) {
		nua_handle_bind(sofia_session->nh, NULL);
		nua_handle_destroy(sofia_session->nh);
		sofia_session->nh = NULL;
	}
	sofia_session->session = NULL;
	return TRUE;
}
static void mrcp_sofia_on_session_redirect(
						int                   status,
						mrcp_sofia_agent_t   *sofia_agent,
						nua_handle_t         *nh,
						mrcp_sofia_session_t *sofia_session,
						sip_t const          *sip,
						tagi_t                tags[])
{
	mrcp_session_t *session = sofia_session->session;
	sip_contact_t *sip_contact;
	if(!sip) {
		return;
	}
	sip_contact = sip->sip_contact;
	if(!sip_contact || !sip_contact->m_url) {
		return;
	}
	
	if(sip_contact->m_url->url_user && sip_contact->m_url->url_user != '\0') {
		sofia_session->sip_to_str = apr_psprintf(session->pool,"sip:%s@%s:%s",
										sip_contact->m_url->url_user,
										sip_contact->m_url->url_host,
										sip_contact->m_url->url_port);
	}
	else {
		sofia_session->sip_to_str = apr_psprintf(session->pool,"sip:%s:%s",
										sip_contact->m_url->url_host,
										sip_contact->m_url->url_port);
	}

	apr_thread_mutex_lock(sofia_session->mutex);

	apt_obj_log(APT_LOG_MARK,APT_PRIO_INFO,session->log_obj,"Redirect "APT_NAMESID_FMT" to %s",
		session->name,
		MRCP_SESSION_SID(session), 
		sofia_session->sip_to_str);

	if(sofia_session->nh) {
		nua_handle_bind(sofia_session->nh, NULL);
		nua_handle_destroy(sofia_session->nh);
		sofia_session->nh = NULL;
	}

	sofia_session->nh = nua_handle(
				sofia_agent->nua,
				sofia_session,
				SIPTAG_TO_STR(sofia_session->sip_to_str),
				SIPTAG_FROM_STR(sofia_agent->sip_from_str),
				SIPTAG_CONTACT_STR(sofia_agent->sip_contact_str),
				TAG_END());

	apr_thread_mutex_unlock(sofia_session->mutex);

	mrcp_sofia_session_offer(sofia_session->session,sofia_session->descriptor);
}
static apt_bool_t mrcp_sofia_session_destroy(mrcp_sofia_session_t *sofia_session)
{
	if(sofia_session->nh) {
		nua_handle_bind(sofia_session->nh, NULL);
		nua_handle_destroy(sofia_session->nh);
	}
	if(sofia_session->home) {
		sofia_session->session->obj = NULL;
		su_home_unref(sofia_session->home);
		sofia_session->home = NULL;
	}
	return TRUE;
}
static apt_bool_t mrcp_sofia_on_session_terminate(mrcp_session_t *session)
{
	mrcp_sofia_session_t *sofia_session = session->obj;
	if(sofia_session) {
		if(sofia_session->nh) {
			nua_handle_bind(sofia_session->nh, NULL);
			nua_handle_destroy(sofia_session->nh);
		}
		if(sofia_session->home) {
			su_home_unref(sofia_session->home);
			sofia_session->home = NULL;
		}
		sofia_session->session = NULL;
	}
	
	apt_log(APT_LOG_MARK,APT_PRIO_NOTICE,"Destroy Session "APT_SID_FMT, MRCP_SESSION_SID(session));
	mrcp_session_destroy(session);
	return TRUE;
}
static mrcp_sofia_session_t* mrcp_sofia_session_create(mrcp_sofia_agent_t *sofia_agent, nua_handle_t *nh)
{
	mrcp_sofia_session_t *sofia_session;
	mrcp_session_t* session = sofia_agent->sig_agent->create_server_session(sofia_agent->sig_agent);
	if(!session) {
		return NULL;
	}
	session->response_vtable = &session_response_vtable;
	session->event_vtable = NULL;

	sofia_session = apr_palloc(session->pool,sizeof(mrcp_sofia_session_t));
	sofia_session->home = su_home_new(sizeof(*sofia_session->home));
	sofia_session->session = session;
	session->obj = sofia_session;
	
	nua_handle_bind(nh, sofia_session);
	sofia_session->nh = nh;
	return sofia_session;
}
static apt_bool_t mrcp_sofia_on_session_terminate(mrcp_session_t *session)
{
    mrcp_sofia_session_t *sofia_session = session->obj;
    if(sofia_session) {
        if(sofia_session->session) {
            apt_log(APT_PRIO_NOTICE,"Destroy Session");
            mrcp_session_destroy(sofia_session->session);
            sofia_session->session = NULL;
        }
        if(sofia_session->nh) {
            nua_handle_bind(sofia_session->nh, NULL);
            nua_handle_destroy(sofia_session->nh);
        }
        if(sofia_session->home) {
            su_home_unref(sofia_session->home);
            sofia_session->home = NULL;
        }
    }
    return TRUE;
}