예제 #1
0
tnet_transport_t* tnet_transport_create(const char* host, tnet_port_t port, tnet_socket_type_t type, const char* description)
{		
	tnet_transport_t* transport;

	if((transport = tsk_object_new(tnet_transport_def_t))){
		transport->description = tsk_strdup(description);
		transport->local_host = tsk_strdup(host);
		transport->req_local_port = port;
		transport->type = type;
		transport->context = tnet_transport_context_create();
		
		if((transport->master = tnet_socket_create(transport->local_host, transport->req_local_port, transport->type))){
			transport->local_ip = tsk_strdup(transport->master->ip);
			transport->bind_local_port = transport->master->port;
		}
		else{
			TSK_DEBUG_ERROR("Failed to create master socket");
			TSK_OBJECT_SAFE_FREE(transport);
		}

		if(_tnet_transport_ssl_init(transport) != 0){
			TSK_DEBUG_ERROR("Failed to initialize TLS and/or DTLS caps");
			TSK_OBJECT_SAFE_FREE(transport);
		}
		// set priority
		tsk_runnable_set_priority(TSK_RUNNABLE(transport), TSK_THREAD_PRIORITY_TIME_CRITICAL);
	}

	return transport;
}
예제 #2
0
tnet_transport_t* tnet_transport_create_2(tnet_socket_t *master, const char* description)
{
	tnet_transport_t* transport;
	if(!master){
		TSK_DEBUG_ERROR("Invalid parameter");
		return tsk_null;
	}

	if((transport = tsk_object_new(tnet_transport_def_t))){
		transport->description = tsk_strdup(description);
		transport->local_host = tsk_strdup(master->ip);
		transport->req_local_port = master->port;
		transport->type = master->type;
		
		transport->master = tsk_object_ref(master);
		transport->local_ip = tsk_strdup(transport->master->ip);
		transport->bind_local_port = transport->master->port;

		transport->context = tnet_transport_context_create();

		if(_tnet_transport_ssl_init(transport) != 0){
			TSK_DEBUG_ERROR("Failed to initialize TLS and/or DTLS caps");
			TSK_OBJECT_SAFE_FREE(transport);
		}

		// set priority
		tsk_runnable_set_priority(TSK_RUNNABLE(transport), TSK_THREAD_PRIORITY_TIME_CRITICAL);
	}

	return transport;
}
예제 #3
0
/**@ingroup tnet_nat_group
* Creates new NAT context.
*/
struct tnet_nat_ctx_s* tnet_nat_context_create(tnet_socket_type_t socket_type, const char* pc_username, const char* pc_password)
{
    extern const tsk_object_def_t *tnet_nat_context_def_t;
    struct tnet_nat_ctx_s* p_ctx;

    if (!(p_ctx = tsk_object_new(tnet_nat_context_def_t)) || !(p_ctx->stun_bindings = tsk_list_create())) {
        TSK_OBJECT_SAFE_FREE(p_ctx);
        TSK_DEBUG_ERROR("Failed to create NAT context");
        return tsk_null;
    }

    p_ctx->socket_type = socket_type;
    p_ctx->username = tsk_strdup(pc_username);
    p_ctx->password = tsk_strdup(pc_password);
    p_ctx->server_port = kStunPortDefaultTcpUdp;
    /*	7.2.1.  Sending over UDP
    	In fixed-line access links, a value of 500 ms is RECOMMENDED.
    */
    p_ctx->RTO = kStunRTO;
    /*	7.2.1.  Sending over UDP
    	Rc SHOULD be configurable and SHOULD have a default of 7.
    */
    p_ctx->Rc = kStunRC;

    return p_ctx;
}
예제 #4
0
/**@ingroup tsk_xml_group
* Initialize an XML element and set values
* @param element The XML element to initialize
* @param name The element name
* @param value The element value
* @param type The element type
*/
void tsk_xml_element_init_set(tsk_xml_element_t** element, const char* name, const char* value, tsk_xml_type_t type)
{
	TSK_XML_ELEMENT_CREATE((*element));
	(*element)->elements = TSK_LIST_CREATE();
	(*element)->attributes = TSK_LIST_CREATE();
	(*element)->namespaces = TSK_LIST_CREATE();
	(*element)->name = tsk_strdup(name);
	(*element)->value = tsk_strdup(value);
	(*element)->type = type;
}
예제 #5
0
static char* tdav_codec_g729ab_sdp_att_get(const tmedia_codec_t* codec, const char* att_name)
{
	tdav_codec_g729ab_t* g729a = (tdav_codec_g729ab_t*)codec;

	if(tsk_striequals(att_name, "fmtp")){
		if(g729a->encoder.vad_enable){
			return tsk_strdup("annexb=yes");
		}
		else{
			return tsk_strdup("annexb=no");
		}
	}
	return tsk_null;
}
예제 #6
0
파일: tmsrp_data.c 프로젝트: SayCV/doubango
//=================================================================================================
//	MSRP outgoing data object definition
//
static void* tmsrp_data_out_ctor(tsk_object_t * self, va_list * app)
{
	tmsrp_data_out_t *data_out = self;
	if(data_out){
		tsk_istr_t id;
		const void* pdata = va_arg(*app, const void*);
		tsk_size_t size = va_arg(*app, tsk_size_t);
		tsk_bool_t isfilepath = va_arg(*app, tsk_bool_t);
		
		if(isfilepath){
			if((data_out->file = fopen((const char*)pdata, "rb"))){
				int ret;
				if((ret = fseek(data_out->file, 0L, SEEK_END))){
					TSK_DEBUG_ERROR("fseek for file:[%s] failed with error code %d.", (const char*)pdata, ret);
					TMSRP_DATA(data_out)->isOK = tsk_false;
				}
				else{
					data_out->size = ftell(data_out->file);
					if((ret = fseek(data_out->file, 0L, SEEK_SET))){
						TSK_DEBUG_ERROR("fseek for file:[%s] failed with error code %d.", (const char*)pdata, ret);
						TMSRP_DATA(data_out)->isOK = tsk_false;
					}
					else{
						TMSRP_DATA(data_out)->isOK = tsk_true;
					}
				}
			}
			else{
				TSK_DEBUG_ERROR("Failed to open(rb) this file:[%s]", (const char*)pdata);
				TMSRP_DATA(data_out)->isOK = tsk_false;
			}
		}
		else{
			if((data_out->message = tsk_buffer_create(pdata, size))){
				TMSRP_DATA(data_out)->isOK = (data_out->message->size == size);
				data_out->size = data_out->message->size;
			}
		}
		
		// content type
		TMSRP_DATA(data_out)->ctype = tsk_strdup("application/octet-stream");
		TMSRP_DATA(data_out)->wctype = tsk_strdup("text/plain");
		// random id
		tsk_strrandom(&id);
		TMSRP_DATA(data_out)->id = tsk_strdup(id);
	}
	return self;
}
예제 #7
0
/**@ingroup tsip_challenge_group
*/
static tsk_object_t* tsip_challenge_ctor(tsk_object_t *self, va_list * app)
{
	tsip_challenge_t *challenge = self;
	if(challenge){
		const char* qop;

		challenge->stack = va_arg(*app, const tsip_stack_handle_t *);
		challenge->isproxy = va_arg(*app, tsk_bool_t);
		challenge->username = tsk_strdup(((const struct tsip_stack_s*)challenge->stack)->identity.impi);
		challenge->scheme = tsk_strdup(va_arg(*app, const char*));
		challenge->realm = tsk_strdup(va_arg(*app, const char*));
		challenge->nonce = tsk_strdup(va_arg(*app, const char*));
		challenge->opaque = tsk_strdup(va_arg(*app, const char*));
		challenge->algorithm = tsk_strdup(va_arg(*app, const char*));
		qop = va_arg(*app, const char*);
		if(qop){
			challenge->qop = tsk_strcontains(qop, tsk_strlen(qop), "auth-int") ? "auth-int" : 
					(tsk_strcontains(qop, tsk_strlen(qop), "auth") ? "auth" : tsk_null);
		}
		
		if(challenge->qop){
			tsip_challenge_reset_cnonce(challenge);
		}
	}
	else TSK_DEBUG_ERROR("Failed to create new sip challenge object.");
예제 #8
0
char* tdav_codec_dtmf_sdp_att_get(const tmedia_codec_t* self, const char* att_name)
{
	if(tsk_striequals(att_name, "fmtp")){
		return tsk_strdup("0-16");
	}
	return tsk_null;
}
예제 #9
0
/** Serializes a QName.
*/
int tnet_dns_rr_qname_serialize(const char* qname, tsk_buffer_t* output)
{
	/*
		QNAME       a domain name represented as a sequence of labels, where
					each label consists of a length octet followed by that
					number of octets.  The domain name terminates with the
					zero length octet for the null label of the root.  Note
					that this field may be an odd number of octets; no
					padding is used.

					Example: "doubango.com" ==> 8doubango3comNULL
	*/
	static uint8_t null = 0;

	if(qname){
		char* _qname = tsk_strdup(qname);
		char* label = strtok(_qname, ".");

		while(label){
			uint8_t length = tsk_strlen(label);
			tsk_buffer_append(output, &length, 1);
			tsk_buffer_append(output, label, tsk_strlen(label));

			label = strtok (tsk_null, ".");
		}

		TSK_FREE(_qname);
	}

	/* terminates domain name */
	tsk_buffer_append(output, &null, 1);

	return 0;
}
예제 #10
0
//=================================================================================================
//	param object definition
//
static tsk_object_t* tsk_param_ctor(tsk_object_t* self, va_list * app)
{
	tsk_param_t *param = self;
	if(param){
		const char* name = va_arg(*app, const char *);
		const char* value = va_arg(*app, const char *);

		if(!tsk_strnullORempty(name)) {
			param->name = tsk_strdup(name);
			if(!tsk_strnullORempty(value)) {
				param->value = tsk_strdup(value);
			}
		}
	}

	return self;
}
예제 #11
0
tmedia_param_t* tmedia_param_create(tmedia_param_access_type_t access_type, 
									tmedia_type_t media_type, 
									tmedia_param_plugin_type_t plugin_type, 
									tmedia_param_value_type_t value_type,
									const char* key,
									void* value)
{
	tmedia_param_t* param;
	
	if(!key ||!value){
		TSK_DEBUG_ERROR("Invalid parameter");
		return tsk_null;
	}

	if((param = tsk_object_new(tmedia_param_def_t))){
		param->access_type = access_type;
		param->media_type = media_type;
		param->plugin_type = plugin_type;
		param->value_type = value_type;
		param->key = tsk_strdup(key);
		switch(value_type){
			case tmedia_pvt_int32:
				if(param->value = tsk_calloc(1, sizeof(int32_t))){
					memcpy(param->value, value, sizeof(int32_t));
					//*((int32_t*)param->value) = *((int32_t*)value);
				}
				break;
			case tmedia_pvt_pobject:
				param->value = tsk_object_ref(value);
				break;
			case tmedia_pvt_pchar:
				param->value = tsk_strdup(value);
				break;
			case tmedia_pvt_int64:
				if(param->value = tsk_calloc(1, sizeof(int64_t))){
					memcpy(param->value, value, sizeof(int64_t));
					//*((int64_t*)param->value) = *((int64_t*)value);
				}
				break;
		}
	}
	else{
		TSK_DEBUG_ERROR("Failed to create media parameter");
	}
	return param;
}
예제 #12
0
//=================================================================================================
//	String object definition
//
static tsk_object_t* tsk_string_ctor(tsk_object_t * self, va_list * app)
{
	tsk_string_t *string = self;
	const char *value = va_arg(*app, const char *);
	if(value){
		string->value = tsk_strdup(value);
	}
	return self;
}
예제 #13
0
int tsip_transac_init(tsip_transac_t *self, tsip_transac_type_t type, tsk_bool_t reliable, int32_t cseq_value, const char* cseq_method, const char* callid, tsip_dialog_t* dialog, tsk_fsm_state_id curr, tsk_fsm_state_id term)
{
	if(self && !self->initialized){
		self->type = type;
		self->reliable = reliable;
		self->cseq_value = cseq_value;
		self->cseq_method = tsk_strdup(cseq_method);
		self->callid = tsk_strdup(callid);
		self->dialog = tsk_object_ref(dialog);

		/* FSM */
		self->fsm = tsk_fsm_create(curr, term);

		self->initialized = tsk_true;
				
		return 0;
	}
	return -1;
}
예제 #14
0
int tnet_transport_set_proxy_info(tnet_transport_handle_t *handle, enum tnet_proxy_type_e type, const char* host, tnet_port_t port, const char* login, const char* password)
{
    tnet_transport_t *transport = (tnet_transport_t*)handle;
    tnet_proxyinfo_t* proxy_info;
    if (!transport) {
        TSK_DEBUG_ERROR("Invalid server handle.");
        return -1;
    }
    if ((proxy_info = tnet_proxyinfo_create())) {
        proxy_info->type = type;
        proxy_info->hostname = tsk_strdup(host);
        proxy_info->port = port;
        proxy_info->username = tsk_strdup(login);
        proxy_info->password = tsk_strdup(password);
        
        TSK_OBJECT_SAFE_FREE(transport->proxy.info);
        transport->proxy.info = proxy_info;
        return 0;
    }
    else {
        return -1;
    }
}
예제 #15
0
thttp_challenge_t* thttp_challenge_create(tsk_bool_t isproxy, const char* scheme, const char* realm, const char* nonce, const char* opaque, const char* algorithm, const char* qop)
{
    thttp_challenge_t* challenge = tsk_object_new(thttp_challenge_def_t);
    if (challenge) {

        challenge->isproxy = isproxy;
        challenge->scheme = tsk_strdup(scheme);
        challenge->realm = tsk_strdup(realm);
        challenge->nonce = tsk_strdup(nonce);
        challenge->opaque = tsk_strdup(opaque);
        challenge->algorithm = tsk_strdup(algorithm);

        if (!tsk_strnullORempty(qop)) {
            challenge->qop = tsk_strcontains(qop, tsk_strlen(qop), "auth-int") ? "auth-int" :
                             (tsk_strcontains(qop, tsk_strlen(qop), "auth") ? "auth" : tsk_null);
        }

        if (challenge->qop) {
            _thttp_challenge_reset_cnonce(challenge);
        }
    }
    return challenge;
}
예제 #16
0
/**
 * Starts the client transaction.
 *
 * @param [in,out]	self	The client transaction to start. 
 * @param [in,out]	request	The SIP/IMS request to send. 
 *
 * @return	Zero if succeed and non-zero error code otherwise. 
**/
int tsip_transac_nict_start(tsip_transac_nict_t *self, const tsip_request_t* request)
{
	int ret = -1;
	if(self && request && !TSIP_TRANSAC(self)->running){
		/* Add branch to the new client transaction
		* IMPORTANT: CANCEL will have the same Via and Contact headers as the request it cancel
		*/
		if(TSIP_REQUEST_IS_CANCEL(request)){
			TSIP_TRANSAC(self)->branch = tsk_strdup(request->firstVia ? request->firstVia->branch : "doubango");
		}
		else if((TSIP_TRANSAC(self)->branch = tsk_strdup(TSIP_TRANSAC_MAGIC_COOKIE))){
			tsk_istr_t branch;
			tsk_strrandom(&branch);
			tsk_strcat(&(TSIP_TRANSAC(self)->branch), branch);
		}

		TSIP_TRANSAC(self)->running = tsk_true;
		self->request = tsk_object_ref((void*)request);

		ret = tsip_transac_fsm_act(TSIP_TRANSAC(self), _fsm_action_send, tsk_null);
	}
	return ret;
}
예제 #17
0
tsk_plugin_t* tsk_plugin_create(const char* path)
{
	tsk_plugin_t* plugin;
	symbol_get_def_count funcptr_get_def_count;
	tsk_plugin_handle_t* handle;

#if TSK_UNDER_WINDOWS
#	if TSK_UNDER_WINDOWS_RT
	wchar_t* szPath = (wchar_t*)tsk_calloc(tsk_strlen(path) + 1, sizeof(wchar_t));
	static const wchar_t* szFormat = L"%hs";
	swprintf(szPath, tsk_strlen(path) * sizeof(wchar_t), szFormat, path);
	handle = LoadPackagedLibrary(szPath, 0x00000000);
	TSK_FREE(szPath);
#	else /* Windows desktop */
	UINT currErrMode = SetErrorMode(SEM_FAILCRITICALERRORS); // save current ErrorMode. GetErrorMode() not supported on XP.
	SetErrorMode(currErrMode | SEM_FAILCRITICALERRORS);
	handle = LoadLibraryA(path);
	SetErrorMode(currErrMode); // restore ErrorMode
#	endif
#else
	handle = dlopen(path, RTLD_NOW);
#endif

	if(!handle){
		TSK_DEBUG_ERROR("Failed to load library with path=%s", path);
		return tsk_null;
	}

	if(!(funcptr_get_def_count = (symbol_get_def_count)_tsk_plugin_handle_get_symbol(handle, TSK_PLUGIN_FUNC_NAME_DEF_COUNT))){
		TSK_DEBUG_ERROR("Cannot find function with name=%s", TSK_PLUGIN_FUNC_NAME_DEF_COUNT);
		_tsk_plugin_handle_destroy(&handle);
		return tsk_null;
	}

	if(!(plugin = (tsk_plugin_t*)tsk_object_new(&tsk_plugin_def_s))){
		TSK_DEBUG_ERROR("Failed to create plugin object");
		_tsk_plugin_handle_destroy(&handle);
		return tsk_null;
	}

	plugin->handle = handle;
	plugin->def_count = funcptr_get_def_count();
	plugin->path = tsk_strdup(path);

	TSK_DEBUG_INFO("Plugin with path=[%s] created with [%d] defs", plugin->path, plugin->def_count);

	return plugin;
}
예제 #18
0
tnet_ice_event_t* tnet_ice_event_create(const struct tnet_ice_ctx_s* ctx, tnet_ice_event_type_t type, const char* phrase, const void* userdata)
{
	tnet_ice_event_t* e;

	if((e = tsk_object_new(tnet_ice_event_def_t))){
		e->ctx = ctx;
		e->type = type;
		e->phrase = tsk_strdup(phrase);
		e->userdata = userdata;
	}
	else{
		TSK_DEBUG_ERROR("Failed to create ICE event");
	}

	return e;
}
예제 #19
0
int thttp_challenge_get_digest_response(thttp_challenge_t *self, const char* username, const char* password, const char* method, const char* uristring, const tsk_buffer_t* entity_body, char** response)
{
	if (THTTP_CHALLENGE_IS_DIGEST(self)){
		tsk_md5string_t ha1, ha2, md5_response;
		nonce_count_t nc;

		/* ===
			Calculate HA1 = MD5(A1) = M5(username:realm:secret)
			*/
		thttp_auth_digest_HA1(username, self->realm, password, &ha1);

		/* ===
			HA2
			*/
		thttp_auth_digest_HA2(method,
			uristring,
			entity_body,
			self->qop,
			&ha2);

		/* RESPONSE */
		if (self->nc){
			THTTP_NCOUNT_2_STRING(self->nc, nc);
		}
		thttp_auth_digest_response((const tsk_md5string_t *)&ha1,
			self->nonce,
			nc,
			self->cnonce,
			self->qop,
			(const tsk_md5string_t *)&ha2,
			&md5_response);

		if (self->qop){
			self->nc++;
		}
		if (response && !*response){
			*response = tsk_strdup(md5_response);
		}

		return 0;
	}
	return -1;
}
예제 #20
0
tsip_header_t *tsip_challenge_create_empty_header_authorization(const char* username, const char* realm, const char* uristring)
{
	tsip_header_Authorization_t *header = tsip_header_Authorization_create();

	if(header){
		header->scheme = tsk_strdup("Digest");
		header->username = tsk_strdup(username);
		header->realm = tsk_strdup(realm);
		header->nonce = tsk_strdup("");
		header->response = tsk_strdup("");
		header->uri = tsk_strdup(uristring);
	}

	return TSIP_HEADER(header);
}
예제 #21
0
/**
 * Starts the client transaction.
 *
 * @param [in,out]	self	The client transaction to start. 
 * @param [in,out]	request	The SIP/IMS request to send. 
 *
 * @return	Zero if succeed and non-zero error code otherwise. 
**/
int tsip_transac_nict_start(tsip_transac_nict_t *self, const tsip_request_t* request)
{
	int ret = -1;
	if(self && request && !TSIP_TRANSAC(self)->running){
		/* Add branch to the new client transaction
		* - CANCEL will have the same Via and Contact headers as the request it cancel
		* - Transac will use request branch if exit (e.g. when request received over websocket)
		*/
		if((request->firstVia && !tsk_strnullORempty(request->firstVia->branch))){
			tsk_strupdate(&TSIP_TRANSAC(self)->branch, (request->firstVia ? request->firstVia->branch : "doubango"));
		}
		else if((TSIP_TRANSAC(self)->branch = tsk_strdup(TSIP_TRANSAC_MAGIC_COOKIE))){
			tsk_istr_t branch;
			tsk_strrandom(&branch);
			tsk_strcat_2(&(TSIP_TRANSAC(self)->branch), "-%s", branch);
		}

		TSIP_TRANSAC(self)->running = tsk_true;
		self->request = tsk_object_ref((void*)request);

		ret = tsip_transac_fsm_act(TSIP_TRANSAC(self), _fsm_action_send, tsk_null);
	}
	return ret;
}
tsip_header_Proxy_Authenticate_t *tsip_header_Proxy_Authenticate_parse(const char *data, tsk_size_t size)
{
	tsip_header_Proxy_Authenticate_t *sip_hdr = 0;
	thttp_header_Proxy_Authenticate_t* http_hdr;

	if((http_hdr = thttp_header_Proxy_Authenticate_parse(data, size))){
		sip_hdr = tsip_header_Proxy_Authenticate_create();

		sip_hdr->scheme = tsk_strdup(http_hdr->scheme);
		sip_hdr->realm = tsk_strdup(http_hdr->realm);
		sip_hdr->domain = tsk_strdup(http_hdr->domain);
		sip_hdr->nonce = tsk_strdup(http_hdr->nonce);
		sip_hdr->opaque = tsk_strdup(http_hdr->opaque);
		sip_hdr->algorithm = tsk_strdup(http_hdr->algorithm);
		sip_hdr->qop = tsk_strdup(http_hdr->qop);
		sip_hdr->stale = http_hdr->stale;
		
		TSIP_HEADER(sip_hdr)->params = tsk_object_ref(THTTP_HEADER(http_hdr)->params);

		TSK_OBJECT_SAFE_FREE(http_hdr);
	}
	
	return sip_hdr;
}
예제 #23
0
int tdav_session_msrp_set(tmedia_session_t* self, const tmedia_param_t* param)
{
	int ret = 0;
	tdav_session_msrp_t* msrp;

	if(!self){
		TSK_DEBUG_ERROR("Invalid parameter");
		return -1;
	}

	TSK_DEBUG_INFO("tdav_session_msrp_set");

	msrp = (tdav_session_msrp_t*)self;

	if(param->value_type == tmedia_pvt_pchar){
		if(tsk_striequals(param->key, "remote-ip")){
			// only if no ip associated to the "m=" line
			if(param->value && !msrp->remote_ip){
				msrp->remote_ip = tsk_strdup(param->value);
			}
		}
		else if(tsk_striequals(param->key, "local-ip")){
			tsk_strupdate(&msrp->local_ip, param->value);
		}
		else if(tsk_striequals(param->key, "local-ipver")){
			msrp->useIPv6 = tsk_striequals(param->value, "ipv6");
		}
		else if(tsk_striequals(param->key, "accept-types")){
			tsk_strupdate(&msrp->accept_types, param->value);
		}
		else if(tsk_striequals(param->key, "accept-wrapped-types")){
			tsk_strupdate(&msrp->accept_w_types, param->value);
		}

		/* Configuration */
		else if(tsk_striequals(param->key, "Failure-Report")){
			msrp->config->Failure_Report = tsk_striequals(param->value, "yes");
		}
		else if(tsk_striequals(param->key, "Success-Report")){
			msrp->config->Success_Report = tsk_striequals(param->value, "yes");
		}

		/* File Transfer */
		else if(tsk_striequals(param->key, "file-path") && !tsk_strnullORempty((const char*)param->value)){
			tsk_strupdate(&msrp->file.path, param->value);
		}
		else if(tsk_striequals(param->key, "file-selector")){
			tsk_strupdate(&msrp->file.selector, param->value);
		}
		else if(tsk_striequals(param->key, "file-disposition")){
			tsk_strupdate(&msrp->file.disposition, param->value);
		}
		else if(tsk_striequals(param->key, "file-date")){
			tsk_strupdate(&msrp->file.date, param->value);
		}
		else if(tsk_striequals(param->key, "file-icon")){
			tsk_strupdate(&msrp->file.icon, param->value);
		}
		else if(tsk_striequals(param->key, "file-transfer-id")){
			tsk_strupdate(&msrp->file.transfer_id, param->value);
		}
	}
	else if(param->value_type == tmedia_pvt_pobject){
		if(tsk_striequals(param->key, "natt-ctx")){
			TSK_OBJECT_SAFE_FREE(msrp->natt_ctx);
			msrp->natt_ctx = tsk_object_ref(param->value);
		}
	}
	else if(param->value_type == tmedia_pvt_int64 || param->value_type == tmedia_pvt_int32){
		if(tsk_striequals(param->key, "chunck-duration")){
			msrp->chunck_duration = TSK_TO_UINT32((uint8_t*)param->value);
			if(msrp->sender){
				msrp->sender->chunck_duration = msrp->chunck_duration;
			}
		}
	}

	return ret;
}
예제 #24
0
/**@ingroup tsk_string_group
* Updates the value of @a str.
* @param str The string to update.
* @param newval The new value of @a str.
*/
void tsk_strupdate(char** str, const char* newval)
{
	tsk_free((void**)str);
	*str = tsk_strdup(newval);
}
예제 #25
0
/**@ingroup tmedia_codec_group
*/
int tmedia_codec_parse_fmtp(const char* fmtp, unsigned* maxbr, unsigned* fps, unsigned *width, unsigned *height)
{
    char *copy, *pch, *saveptr;
    tsk_bool_t found = tsk_false;

    if(tsk_strnullORempty(fmtp)) {
        TSK_DEBUG_ERROR("Invalid parameter");
        return -1;
    }

    copy = tsk_strdup(fmtp);
    pch = tsk_strtok_r(copy, "; /", &saveptr);

    while(pch) {
        unsigned div = 0;

        if(sscanf(pch, "QCIF=%u", &div) == 1 && div) {
            *fps = 30/div;
            *width = 176;
            *height = 144;
            found = tsk_true;
        }
        else if(sscanf(pch, "CIF=%u", &div) == 1 && div) {
            *fps = 30/div;
            *width = 352;
            *height = 288;
            found = tsk_true;
        }
        else if(sscanf(pch, "SQCIF=%u", &div) == 1 && div) {
            *fps = 30/div;
            *width = 128;
            *height = 96;
            found = tsk_true;
        }
        else if(sscanf(pch, "QVGA=%u", &div) == 1 && div) {
            *fps = 30/div;
            *width = 320;
            *height = 240;
            found = tsk_true;
        }
        // to be continued

        if(found) {
            //found = tsk_false;
            pch = tsk_strtok_r(tsk_null, "; ", &saveptr);
            while(pch) {
                if(sscanf(pch, "MaxBR=%u", maxbr) == 1) {
                    //found = tsk_true;
                    break;
                }
                pch = tsk_strtok_r(tsk_null, "; /", &saveptr);
            }
        }

        if(found) {
            break;
        }

        pch = tsk_strtok_r(tsk_null, "; /", &saveptr);
    }

    TSK_FREE(copy);

    return found ? 0 : -2;
}
예제 #26
0
static int populate_lo(tdav_session_msrp_t* self, tsk_bool_t initial)
{
	if(!self || !TMEDIA_SESSION(self)->M.lo){
		TSK_DEBUG_ERROR("Invalid parameter");
		return -1;
	}

	if(initial){
		tsdp_header_M_add_headers(TMEDIA_SESSION(self)->M.lo,
			TSDP_HEADER_A_VA_ARGS("setup", setup_to_string(self->setup)),
			
			tsk_null
		);
		
		if(self->accept_types || self->neg_accept_type){
			/* a=accept-types:message/CPIM application/octet-stream */
			tsdp_header_M_add_headers(TMEDIA_SESSION(self)->M.lo,
				TSDP_HEADER_A_VA_ARGS("accept-types", self->accept_types ? self->accept_types : self->neg_accept_type),
				tsk_null);
		}
		if(self->accept_w_types || self->neg_accept_w_type){
			/* a=accept-wrapped-types:application/octet-stream */
			tsdp_header_M_add_headers(TMEDIA_SESSION(self)->M.lo,
				TSDP_HEADER_A_VA_ARGS("accept-wrapped-types", self->accept_w_types ? self->accept_w_types : self->neg_accept_w_type),
				tsk_null);
		}

		/*=== File Transfer ===*/
		if(self->file.path){
			/* Compute default 'file-selector' */
			if(!self->file.selector && !TMEDIA_SESSION(self)->M.ro){
				int index = tsk_strLastIndexOf(self->file.path, tsk_strlen(self->file.path), "\\");
				if(index == -1){
					index = tsk_strLastIndexOf(self->file.path, tsk_strlen(self->file.path), "/");
				}
				index++;
				tsk_sprintf(&self->file.selector, "name:\"%s\" type:application/octet-stream", (self->file.path + index));
			}
			/* Compute default 'file-transfer-id' */
			if(!self->file.transfer_id && !TMEDIA_SESSION(self)->M.ro){
				tsk_istr_t rand_string;
				tsk_strrandom(&rand_string);
				self->file.transfer_id = tsk_strdup(rand_string);
			}
			
			tsdp_header_M_add_headers(TMEDIA_SESSION(self)->M.lo,
				TSDP_HEADER_A_VA_ARGS("sendonly", tsk_null),
				tsk_null);
		}
		else{
			tsdp_header_M_add_headers(TMEDIA_SESSION(self)->M.lo,
				TSDP_HEADER_A_VA_ARGS("sendrecv", tsk_null),
				tsk_null);
		}

		if(self->file.selector){
			/* a=file-selector:name:"test.pcap" type:application/octet-stream size:11376 hash:sha-1:8D:55:24:2B:F4:F9:9B:A2:54:A3:5B:91:00:15:9E:A3:D4:48:D7:DF */
			tsdp_header_M_add_headers(TMEDIA_SESSION(self)->M.lo,
				TSDP_HEADER_A_VA_ARGS("file-selector", self->file.selector),
				tsk_null);
		}
		if(self->file.transfer_id){
			/* a=file-transfer-id:vscxggbwkfnqduxwfnfozvsrtkjprepg */
			tsdp_header_M_add_headers(TMEDIA_SESSION(self)->M.lo,
				TSDP_HEADER_A_VA_ARGS("file-transfer-id", self->file.transfer_id),
				tsk_null);
		}
		if(self->file.disposition){
			/* a=file-disposition:attachment */
			tsdp_header_M_add_headers(TMEDIA_SESSION(self)->M.lo,
				TSDP_HEADER_A_VA_ARGS("file-disposition", self->file.disposition),
				tsk_null);
		}
		if(self->file.date){
			/* a=file-date:creation:2010-02-13T17:50:31.763Z */
			tsdp_header_M_add_headers(TMEDIA_SESSION(self)->M.lo,
				TSDP_HEADER_A_VA_ARGS("file-date", self->file.date),
				tsk_null);
		}
		if(self->file.icon){
			/* a=file-icon:cid:[email protected] */
			tsdp_header_M_add_headers(TMEDIA_SESSION(self)->M.lo,
				TSDP_HEADER_A_VA_ARGS("file-icon", self->file.icon),
				tsk_null);
		}
	}

	return 0;
}
예제 #27
0
// @param str e.g. "1 1 udp 1 192.168.196.1 57806 typ host name video_rtcp network_name {0C0137CC-DB78-46B6-9B6C-7E097FFA79FE} username StFEVThMK2DHThkv password qkhKUDr4WqKRwZTo generation 0"
tnet_ice_candidate_t* tnet_ice_candidate_parse(const char* str)
{
	char *v, *copy;
	int32_t k;
	tnet_ice_candidate_t* candidate;

	if(tsk_strnullORempty(str)){
		TSK_DEBUG_ERROR("Invalid parameter");
		return tsk_null;
	}	

	if(!(candidate = tsk_object_new(&tnet_ice_candidate_def_s))){
		TSK_DEBUG_ERROR("Failed to create candidate");
		return tsk_null;
	}

	k = 0;
	copy = tsk_strdup(str);
	v = strtok(copy, " ");

	while(v){
		switch(k){
			case 0:
				{
					memcpy(candidate->foundation, v, TSK_MIN(tsk_strlen(v), sizeof(candidate->foundation)));
					break;
				}
			case 1:
				{
					candidate->comp_id = atoi(v);
					break;
				}
			case 2:
				{
					candidate->transport_str = tsk_strdup(v);
					break;
				}
			case 3:
				{
					candidate->priority = atoi(v);
					break;
				}
			case 4:
				{
					memcpy(candidate->connection_addr, v, TSK_MIN(tsk_strlen(v), sizeof(candidate->connection_addr)));
					break;
				}
			case 5:
				{
					tnet_family_t family;
					candidate->port = atoi(v);
					family = tnet_get_family(candidate->connection_addr, candidate->port);
					candidate->transport_e = _tnet_ice_candidate_get_transport_type((family == AF_INET6), candidate->transport_str);
					break;
				}
			case 6:
				{
					v = strtok(tsk_null, " ");
					tsk_strupdate(&candidate->cand_type_str, v);
					candidate->type_e = _tnet_ice_candtype_get_transport_type(v);
					break;
				}
			default:
				{
					const char* name = v;
					const char* value = (v = strtok(tsk_null, " "));
					tsk_param_t* param = tsk_param_create(name, value);
					if(param){
						tsk_list_push_back_data(candidate->extension_att_list, (void**)&param);
					}
					break;
				}
		}

		++k;
		v = strtok(tsk_null, " ");
	}

	if(k < 6){
		TSK_DEBUG_ERROR("Failed to parse: %s", str);
		TSK_OBJECT_SAFE_FREE(candidate);
	}
	TSK_FREE(copy);

	return candidate;
}
tsip_header_Authorization_t *tsip_header_Authorization_parse(const char *data, tsk_size_t size)
{
	tsip_header_Authorization_t *hdr_sip = 0;
	thttp_header_Authorization_t* hdr_http;

	if((hdr_http = thttp_header_Authorization_parse(data, size))){
		hdr_sip = tsip_header_Authorization_create();
		
		hdr_sip->scheme = tsk_strdup(hdr_http->scheme);
		hdr_sip->username = tsk_strdup(hdr_http->username);
		hdr_sip->realm =  tsk_strdup(hdr_http->realm);
		hdr_sip->nonce =  tsk_strdup(hdr_http->nonce);
		hdr_sip->uri =  tsk_strdup(hdr_http->uri);
		hdr_sip->response =  tsk_strdup(hdr_http->response);
		hdr_sip->algorithm =  tsk_strdup(hdr_http->algorithm);
		hdr_sip->cnonce =  tsk_strdup(hdr_http->cnonce);
		hdr_sip->opaque =  tsk_strdup(hdr_http->opaque);
		hdr_sip->qop =  tsk_strdup(hdr_http->qop);
		hdr_sip->nc =  tsk_strdup(hdr_http->nc);

		TSIP_HEADER(hdr_sip)->params = tsk_object_ref(THTTP_HEADER(hdr_http)->params);

		TSK_OBJECT_SAFE_FREE(hdr_http);
	}
	
	return hdr_sip;
}