Exemple #1
0
/**@ingroup thttp_action_group
* Sends a custom HTTP/HTTPS request.
* @param session The @a session (or connection) to use.
* @param urlstring The Request-URI. If the url scheme is 'https', then the default port will be 443, otherwise the port value will be 80.
* @param method The method to use for the HTTP request (e.g. GET, PUT, DELETE, POST ...).
* @retval Zero if succeed and non-zero error code otherwise.
*
* @code
thttp_action_perform(session, "http://www.google.com", "GET"
		// request-level parameters
		THTTP_ACTION_SET_PARAM("timeout", "6000"),

		// request-level headers
		THTTP_ACTION_SET_HEADER("Pragma", "No-Cache"),
		THTTP_ACTION_SET_HEADER("Connection", "Keep-Alive"),
		
		// close parameters
		THTTP_ACTION_SET_NULL());
* @endcode
* @sa @ref thttp_action_CONNECT<br>@ref thttp_action_DELETE<br>@ref thttp_action_GET<br>@ref thttp_action_HEAD<br>@ref thttp_action_OPTIONS<br>
* @ref thttp_action_PATCH<br>@ref thttp_action_POST<br>@ref thttp_action_PUT<br>@ref thttp_action_TRACE
*/
int thttp_action_perform(thttp_session_handle_t *session, const char* urlstring, const char* method, ...)
{
	thttp_session_t* sess = session;
	va_list ap;
	thttp_action_t* action;
	thttp_dialog_t* dialog;
	int ret = -1;	

	if(!sess || !sess->stack || !urlstring || !method){
		TSK_DEBUG_ERROR("Invalid parameter");
		return ret;
	}
	
	va_start(ap, method);
	if((action = thttp_action_create(thttp_atype_o_request, urlstring, method, &ap))){		
		if((dialog = thttp_dialog_new(sess))){
			ret = thttp_dialog_fsm_act(dialog, action->type, tsk_null, action);
			
			tsk_object_unref(dialog);
		}
		else{
			TSK_DEBUG_ERROR("Failed to create new HTTP/HTTPS dialog.");
			ret = -2;
		}
		TSK_OBJECT_SAFE_FREE(action);
	}
	va_end(ap);

	return ret;
}
int tsip_api_publish_send_publish(const tsip_ssession_handle_t *ss, ...)
{
	const tsip_ssession_t* _ss;
	va_list ap;
	tsip_action_t* action;
	tsip_dialog_t* dialog;
	int ret = -1;

	if(!(_ss = ss) || !_ss->stack){
		TSK_DEBUG_ERROR("Invalid parameter.");
		return ret;
	}

	/* Checks if the stack has been started */
	if(!TSK_RUNNABLE(_ss->stack)->started){
		TSK_DEBUG_ERROR("Stack not started.");
		return -2;
	}
	
	va_start(ap, ss);
	if((action = _tsip_action_create(tsip_atype_publish, &ap))){
		if(!(dialog = tsip_dialog_layer_find_by_ss(_ss->stack->layer_dialog, ss))){
			dialog = tsip_dialog_layer_new(_ss->stack->layer_dialog, tsip_dialog_PUBLISH, ss);
		}
		ret = tsip_dialog_fsm_act(dialog, action->type, tsk_null, action);
		
		tsk_object_unref(dialog);
		TSK_OBJECT_SAFE_FREE(action);
	}
	va_end(ap);

	return ret;
}
Exemple #3
0
/**@ingroup tsk_list_group
* Removes an item from the @ref tsk_list_t "list" using a @ref _Anchor_TinySAK_Linked_List_Predicates "predicate".
* @param list The list from which to remove the @ref tsk_list_item_t "item".
* @param predicate The @ref _Anchor_TinySAK_Linked_List_Predicates "predicate" used to match the item to remove.
* @param data Arbitrary data to pass to the @ref _Anchor_TinySAK_Linked_List_Predicates "predicate".
* @return @ref tsk_true if an item have been removed and @ref tsk_false otherwise.
*/
tsk_bool_t tsk_list_remove_item_by_pred(tsk_list_t* list, tsk_list_func_predicate predicate, const void * data)
{
	tsk_list_item_t* item;
	if((item = tsk_list_pop_item_by_pred(list, predicate, data))){
		tsk_object_unref(item);
		return tsk_true;
	}
	return tsk_false;
}
Exemple #4
0
/**@ingroup tsk_list_group
* Removes an object from the @ref tsk_list_t "list". The reference counter value of the @ref _Page_TinySAK_AnsiC_Object_Programming "well-defined" object held by the item will be decremented.
* @param list The @ref tsk_list_t "list" from which to remove the object.
* @param tskobj Any valid @ref _Page_TinySAK_AnsiC_Object_Programming "well-defined" object to remove.
* @return @ref tsk_true if an item have been removed; @ref tsk_false otherwise.
*/
tsk_bool_t tsk_list_remove_item_by_data(tsk_list_t* list, const tsk_object_t * tskobj)
{
	tsk_list_item_t* item;
	if((item = tsk_list_pop_item_by_data(list, tskobj))){
		tsk_object_unref(item);
		return tsk_true;
	}
	return tsk_false;
}
Exemple #5
0
int tsip_transac_remove(const tsip_transac_t* self)
{
	int ret;
	tsip_transac_t* safe_copy;
	
	safe_copy = (tsip_transac_t*)tsk_object_ref(TSK_OBJECT(self));
	ret = tsip_transac_layer_remove(TSIP_TRANSAC_GET_STACK(self)->layer_transac, safe_copy);
	tsk_object_unref(safe_copy);
	
	return ret;
}
Exemple #6
0
int tnet_transport_get_public_ip_n_port(const tnet_transport_handle_t *handle, tnet_fd_t fd, tnet_ip_t *ip, tnet_port_t *port)
{
	tsk_bool_t stun_ok = tsk_false;
	struct tnet_nat_ctx_s* natt_ctx;
	const tnet_transport_t *transport = handle;
	if(!transport){
		TSK_DEBUG_ERROR("Invalid parameter");
		return -1;
	}

	if (TNET_SOCKET_TYPE_IS_DGRAM(transport->type) && (natt_ctx = tsk_object_ref(transport->natt_ctx))) {
		tnet_stun_binding_id_t bind_id = kStunBindingInvalidId;
		// if the socket is already monitored by the transport we should pause because both the transport and
		// NAT binder will try to read from it
		
		// Pause the soket
		tnet_transport_pause_socket(transport, fd, tsk_true);
		// Performs STUN binding
		bind_id = tnet_nat_stun_bind(transport->natt_ctx, fd);
		// Resume the socket
		tnet_transport_pause_socket(transport, fd, tsk_false);
		
		if (bind_id != kStunBindingInvalidId) {
			char* public_ip = tsk_null;
			if(tnet_nat_stun_get_reflexive_address(transport->natt_ctx, bind_id, &public_ip, port) == 0){
				if(ip && public_ip){
					tsk_size_t ip_len = tsk_strlen(public_ip);
					memcpy(ip, public_ip, ip_len> sizeof(*ip)?sizeof(*ip):ip_len);
				}
				stun_ok = tsk_true;
			}
			TSK_FREE(public_ip);
			tnet_nat_stun_unbind(transport->natt_ctx, bind_id);
		}
		tsk_object_unref(natt_ctx);
	}

	if(!stun_ok){
		if(fd == TNET_INVALID_FD && transport->local_ip){
			memcpy(*ip, transport->local_ip, TSK_MIN(sizeof(tnet_ip_t), tsk_strlen(transport->local_ip)));
			*port = transport->bind_local_port;
			return 0;
		}
		else{
			return tnet_transport_get_ip_n_port(handle, fd, ip, port);
		}
	}
	
	return 0;
}
Exemple #7
0
/**@ingroup tsk_list_group
* Cleans up and remove all items from the @ref tsk_list_t "list". The reference counter for each item will be decremented. An item will be freed only if its new reference counter value is equal to 0.
* @param list The list to clean up.
*/
void tsk_list_clear_items(tsk_list_t* list)
{
	if(list){
		tsk_list_item_t* next = tsk_null;
		tsk_list_item_t* curr = list->head;

		while(curr){
			next = curr->next;
			tsk_object_unref(curr);
			curr = next;
		}
		list->head = tsk_null;
		list->tail = tsk_null;
	}
}
Exemple #8
0
int tdav_audiounit_handle_destroy(tdav_audiounit_handle_t** self){
	if(!self || !*self){
		TSK_DEBUG_ERROR("Invalid parameter");
		return -1;
	}
	tsk_list_lock(__audioUnitInstances);
	if(tsk_object_get_refcount(*self)==1){
		tsk_list_remove_item_by_data(__audioUnitInstances, *self);
	}
	else {
		tsk_object_unref(*self);
	}
	tsk_list_unlock(__audioUnitInstances);
	*self = tsk_null;
	return 0;
}
Exemple #9
0
int tsip_transac_fsm_act(tsip_transac_t* self, tsk_fsm_action_id action_id, const tsip_message_t* message)
{
	int ret;
	tsip_transac_t* safe_copy;

	if(!self || !self->fsm){
		TSK_DEBUG_WARN("Invalid parameter.");
		return -1;
	}

	safe_copy = tsk_object_ref(TSK_OBJECT(self));
	ret = tsk_fsm_act(self->fsm, action_id, safe_copy, message, self, message);
	tsk_object_unref(safe_copy);

	return ret;
}
int tdav_msrp_event_proxy_cb(tmsrp_event_t* _event/*!Not the owner of the object*/)
{
	tdav_session_msrp_t* msrp;
	int ret = 0;	

	if(!_event || !_event->callback_data){
		TSK_DEBUG_ERROR("Invalid parameter");
		return -1;
	}

	msrp = tsk_object_ref((void*)_event->callback_data);
	if(TMEDIA_SESSION_MSRP(msrp)->callback.func){
		_event->callback_data = TMEDIA_SESSION_MSRP(msrp)->callback.data; // steal callback data
		ret = TMEDIA_SESSION_MSRP(msrp)->callback.func(_event); // call callback function()
	}
	tsk_object_unref(msrp);

	return ret;
}
Exemple #11
0
/*
* Runnable interface implementation.
*/
static void* TSK_STDCALL run(void* self)
{
	int ret = 0;
	tsk_list_item_t *curr;
	tnet_transport_t *transport = self;
	
	TSK_DEBUG_INFO("Transport::run() - enter");

	/* create main thread */
	if((ret = tsk_thread_create(transport->mainThreadId, tnet_transport_mainthread, transport))){ /* More important than "tsk_runnable_start" ==> start it first. */
		TSK_FREE(transport->context); /* Otherwise (tsk_thread_create is ok) will be freed when mainthread exit. */
		TSK_DEBUG_FATAL("Failed to create main thread [%d]", ret);
		return tsk_null;
	}
	/* set thread priority 
     iOS and OSX: no incoming pkts (STUN, rtp, dtls...) when thread priority is changed -> to be checked
     */
#if !TNET_UNDER_APPLE
	ret = tsk_thread_set_priority(transport->mainThreadId[0], TSK_THREAD_PRIORITY_TIME_CRITICAL);
#endif
	
	TSK_RUNNABLE_RUN_BEGIN(transport);
	
	if((curr = TSK_RUNNABLE_POP_FIRST_SAFE(TSK_RUNNABLE(transport)))){
		const tnet_transport_event_t *e = (const tnet_transport_event_t*)curr->data;
		
		if (transport->callback) {
			transport->callback(e);
		}
		tsk_object_unref(curr);
	}
	
	TSK_RUNNABLE_RUN_END(transport);

	TSK_DEBUG_INFO("Transport::run(%s) - exit", transport->description);

	return tsk_null;
}
int tdav_transport_layer_stream_cb(const tnet_transport_event_t* e)
{
	const tdav_session_msrp_t *session = e->callback_data;
	tmsrp_receiver_t* receiver;
	int ret = -1;

#define TMSRP_ALERT_USER(type) \
	{ \
		tdav_session_msrp_t *msrp = tsk_object_ref((void*)session); \
		tmsrp_event_t* _event = tmsrp_event_create(msrp, tsk_false, type, tsk_null); \
		tdav_msrp_event_proxy_cb(_event); \
		TSK_OBJECT_SAFE_FREE(_event); \
		tsk_object_unref(msrp); \
	}

	switch(e->type){
		case event_data: {
				break;
			}
		case event_accepted:
			if(!session->connectedFD){
				tdav_session_msrp_t *msrp = tsk_object_ref((void*)session);
				/* We are passive ==> update connection info */
				msrp->connectedFD = e->local_fd;
				tmsrp_sender_set_fd(msrp->sender, msrp->connectedFD);
				tmsrp_receiver_set_fd(msrp->receiver, msrp->connectedFD);
				msrp->fresh_conn = tsk_true;
				/* Send Bodiless request */
				if(msrp->send_bodiless){
					send_bodiless(msrp);
					msrp->send_bodiless = tsk_false;
				}
				/* Alert user */
				TMSRP_ALERT_USER(tmsrp_event_type_connected);

				tsk_object_unref(msrp);
			}
			break;
		case event_closed:
			if(e->local_fd == session->connectedFD){
				TSK_DEBUG_INFO("MSRP Socket closed");
				TMSRP_ALERT_USER(tmsrp_event_type_disconnected);
			}
			return 0;

		case event_connected:
			{
				tdav_session_msrp_t *msrp = tsk_object_ref((void*)session);
				if(e->local_fd == msrp->connectedFD){
					msrp->fresh_conn = tsk_true;
					/* Send Bodiless request */
					if(msrp->send_bodiless){
						send_bodiless(msrp);
						msrp->send_bodiless = tsk_false;
					}
					/* Alert user */
					TMSRP_ALERT_USER(tmsrp_event_type_connected);
				}
				tsk_object_unref(msrp);
			}
			break;
		default:{
				return 0;
			}
	}

	if(e->data && (receiver = tsk_object_ref((void*)session->receiver))){
		ret = tmsrp_receiver_recv(receiver, e->data, e->size);
		tsk_object_unref(receiver);
	}

	if(session->fresh_conn){
		tdav_session_msrp_t *msrp = tsk_object_ref((void*)session);
		/* send pending file - and data?*/
		if(session->offerer){
			send_pending_file(msrp);
		}
		msrp->fresh_conn = tsk_false;
		tsk_object_unref(msrp);
	}

	return ret;
}