예제 #1
0
/*
 * Initialize.
 */
PJ_DEF(pj_status_t) pj_turn_sock_alloc(pj_turn_sock *turn_sock,
				       const pj_str_t *domain,
				       int default_port,
				       pj_dns_resolver *resolver,
				       const pj_stun_auth_cred *cred,
				       const pj_turn_alloc_param *param)
{
    pj_status_t status;

    PJ_ASSERT_RETURN(turn_sock && domain, PJ_EINVAL);
    PJ_ASSERT_RETURN(turn_sock->sess, PJ_EINVALIDOP);

    pj_grp_lock_acquire(turn_sock->grp_lock);

    /* Copy alloc param. We will call session_alloc() only after the 
     * server address has been resolved.
     */
    if (param) {
	pj_turn_alloc_param_copy(turn_sock->pool, &turn_sock->alloc_param, param);
    } else {
	pj_turn_alloc_param_default(&turn_sock->alloc_param);
    }

    /* Set credental */
    if (cred) {
	status = pj_turn_session_set_credential(turn_sock->sess, cred);
	if (status != PJ_SUCCESS) {
	    sess_fail(turn_sock, "Error setting credential", status);
	    pj_grp_lock_release(turn_sock->grp_lock);
	    return status;
	}
    }

    /* Resolve server */
    status = pj_turn_session_set_server(turn_sock->sess, domain, default_port,
					resolver);
    if (status != PJ_SUCCESS) {
	sess_fail(turn_sock, "Error setting TURN server", status);
	pj_grp_lock_release(turn_sock->grp_lock);
	return status;
    }

    /* Done for now. The next work will be done when session state moved
     * to RESOLVED state.
     */
    pj_grp_lock_release(turn_sock->grp_lock);
    return PJ_SUCCESS;
}
예제 #2
0
/*
 * 2013-05-08 DEAN modifedf by adding parameters.
 * Initialize.
 */
PJ_DEF(pj_status_t) pj_turn_sock_alloc2(pj_turn_sock *turn_sock,
				       const pj_str_t *domain,
				       int default_port,
				       pj_dns_resolver *resolver,
				       const pj_stun_auth_cred *cred,
					   const pj_turn_alloc_param *param,
					   int curr_turn,
					   int turn_cnt,
					   pj_turn_server turn_list[])
{
    pj_status_t status;

    PJ_ASSERT_RETURN(turn_sock && domain && turn_cnt <= MAX_TURN_SERVER_COUNT, PJ_EINVAL);
    PJ_ASSERT_RETURN(turn_sock->sess, PJ_EINVALIDOP);

    /* Copy alloc param. We will call session_alloc() only after the 
     * server address has been resolved.
     */
    if (param) {
	pj_turn_alloc_param_copy(turn_sock->pool, &turn_sock->alloc_param, param);
    } else {
	pj_turn_alloc_param_default(&turn_sock->alloc_param);
    }

    /* Set credential */
	if (cred) {
		PJ_LOG(4, (THIS_FILE, "pj_turn_sock_alloc2() turn tp type=%d", turn_sock->conn_type));
		PJ_LOG(4, (THIS_FILE, "pj_turn_sock_alloc2() turn server=%.*s:%d", domain->slen, domain->ptr, default_port));
		PJ_LOG(4, (THIS_FILE, "pj_turn_sock_alloc2() turn realm=%.*s", cred->data.static_cred.realm.slen, cred->data.static_cred.realm.ptr));
		PJ_LOG(4, (THIS_FILE, "pj_turn_sock_alloc2() turn username=%.*s", cred->data.static_cred.username.slen, cred->data.static_cred.username.ptr));
		PJ_LOG(4, (THIS_FILE, "pj_turn_sock_alloc2() turn password=%.*s", cred->data.static_cred.data.slen, cred->data.static_cred.data.ptr));
		status = pj_turn_session_set_credential(turn_sock->sess, cred);
		if (status != PJ_SUCCESS) {
			PJ_LOG(1, ("turn_sock.c", "!!! TURN DEALLOCATE !!! in pj_turn_sock_alloc2() pj_turn_session_set_credential failed=%d", status));
			sess_fail(turn_sock, "Error setting credential", status);
			return status;
		}
    }

	// 2014-04-19 DEAN, for retry another turn use
	turn_sock->turn.domain = domain;
	turn_sock->turn.default_port = default_port;
	turn_sock->turn.resolver = resolver;
	turn_sock->curr_turn = curr_turn;
	turn_sock->turn_cnt = turn_cnt;
	memcpy(turn_sock->turn_list, turn_list, sizeof(pj_turn_server)*turn_cnt);	

    /* Resolve server */
    status = pj_turn_session_set_server(turn_sock->sess, domain, default_port,
					resolver);
	if (status != PJ_SUCCESS) {
		PJ_LOG(1, ("turn_sock.c", "!!! TURN DEALLOCATE !!! in pj_turn_sock_alloc2() pj_turn_session_set_server failed=%d", status));
		sess_fail(turn_sock, "Error setting TURN server", status);
		return status;
    }

    /* Done for now. The next work will be done when session state moved
     * to RESOLVED state.
     */

    return PJ_SUCCESS;
}