Esempio n. 1
0
int publish_handle_event(const tsip_event_t *_event)
{
	const tsip_publish_event_t* pub_event = TSIP_PUBLISH_EVENT(_event);
	const session_t* session;
	tsip_ssession_id_t sid;

	/* Find associated session */
	sid = tsip_ssession_get_id(_event->ss);
	if(!(session = session_get_by_sid(ctx->sessions, sid))){
		TSK_DEBUG_WARN("Failed to match session event.");
		return -1;
	}

	switch(pub_event->type){
		case tsip_ao_publish: /* Answer to outgoing PUBLISH */
			{
				if(_event->sipmessage){
					if(TSIP_MESSAGE_IS_RESPONSE(_event->sipmessage)){
						TSK_DEBUG_INFO("Event: Answer to outgoing PUBLISH. Code=%d and phrase=%s", 
							_event->sipmessage->line.response.status_code, _event->sipmessage->line.response.reason_phrase);
					}
					else{
						// request
					}
				}
				break;
			}
		
		case tsip_ao_unpublish: /* Answer to outgoing unPUBLISH */
			{
				if(_event->sipmessage){
					if(TSIP_MESSAGE_IS_RESPONSE(_event->sipmessage)){
						TSK_DEBUG_INFO("Event: Answer to outgoing UNPUBLISH. Code=%d and phrase=%s", 
							_event->sipmessage->line.response.status_code, _event->sipmessage->line.response.reason_phrase);
					}
					else{
						// request
					}
				}
				break;
			}

		/* Server events (For whose dev. Server Side IMS Services) */
		case tsip_i_publish: /* Incoming PUBLISH */
		case tsip_i_unpublish: /* Incoming unPUBLISH */
			{	
				TSK_DEBUG_WARN("Event not support by Client Framework.");
				break;
			}

		default:
			{	/* Any other event */
				TSK_DEBUG_WARN("%d not a valid SIP Subscription event.", pub_event->type);
				break;
			}
	}

	return 0;
}
Esempio n. 2
0
static tsk_size_t tdav_speex_jitterbuffer_get(tmedia_jitterbuffer_t* self, void* out_data, tsk_size_t out_size)
{
	tdav_speex_jitterbuffer_t *jb = (tdav_speex_jitterbuffer_t *)self;
	JitterBufferPacket jb_packet;
	int ret, miss = 0;
	tsk_size_t ret_size = 0;

	if (!out_data || !out_size) {
		TSK_DEBUG_ERROR("Invalid parameter");
		return 0;
	}
	if (!jb->state) {
		TSK_DEBUG_ERROR("Invalid state");
		return 0;
	}
	if (jb->x_data_size != out_size) { // consumer must request PTIME data
		TSK_DEBUG_WARN("%d not expected as frame size. %u<>%u", out_size, jb->frame_duration, (out_size * 500) / jb->rate);
		return 0;
	}

	jb_packet.data = out_data;
	jb_packet.len = (spx_uint32_t)out_size;

	if ((ret = jitter_buffer_get(jb->state, &jb_packet, jb->frame_duration/*(out_size * 500)/jb->rate*/, tsk_null)) != JITTER_BUFFER_OK) {
		++jb->num_pkt_miss;
		switch (ret) {
		case JITTER_BUFFER_MISSING:
			/*TSK_DEBUG_INFO("JITTER_BUFFER_MISSING - %d", ret);*/
			if (jb->num_pkt_miss > jb->num_pkt_miss_max /*too much missing pkts*/ && jb->num_pkt_in > jb->num_pkt_miss_max/*we're really receiving pkts*/) {
				jb->num_pkt_miss = 0;
				self->plugin->reset(self);
				TSK_DEBUG_WARN("Too much missing audio pkts");
			}
			break;
		case JITTER_BUFFER_INSERTION:
			/*TSK_DEBUG_INFO("JITTER_BUFFER_INSERTION - %d", ret);*/
			break;
		default:
			TSK_DEBUG_INFO("jitter_buffer_get() failed - %d", ret);
			break;
		}
		// jitter_buffer_update_delay(jb->state, &jb_packet, NULL);
		//return 0;
	}
	else {
		jb->num_pkt_miss = 0; // reset
		ret_size = jb_packet.len;
	}
	//jitter_buffer_update_delay(jb->state, &jb_packet, NULL);

	return ret_size;
}
Esempio n. 3
0
int tdav_producer_dsound_stop(tmedia_producer_t* self)
{
	tdav_producer_dsound_t* dsound = (tdav_producer_dsound_t*)self;

	HRESULT hr;

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

	if(!dsound->started){
		TSK_DEBUG_WARN("Producer not started");
		return 0;
	}

	/* should be done here */
	dsound->started = tsk_false;

	/* stop thread */
	if(dsound->tid[0]){
		tsk_thread_join(&(dsound->tid[0]));
	}

	if((hr = IDirectSoundCaptureBuffer_Stop(dsound->captureBuffer)) != DS_OK){
		tdav_win32_print_error("IDirectSoundCaptureBuffer_Stop", hr);
	}

	return 0;
}
Esempio n. 4
0
/**@ingroup tmedia_codec_group
* Prepares a codec by opening it.
* @param self The codec to open.
* @retval Zero if succeed and non-zero error code otherwise.
* @sa @ref tmedia_codec_close()
*/
int tmedia_codec_open(tmedia_codec_t* self)
{
    if(!self || !self->plugin) {
        TSK_DEBUG_ERROR("Invalid parameter");
        return -1;
    }
    if(self->opened) {
        TSK_DEBUG_WARN("Codec already opened");
        return 0;
    }

    if(self->plugin->open) {
        int ret;
        if((ret = self->plugin->open(self))) {
            TSK_DEBUG_ERROR("Failed to open [%s] codec", self->plugin->desc);
            return ret;
        }
        else {
            self->opened = tsk_true;
            return 0;
        }
    }
    else {
        self->opened = tsk_true;
        return 0;
    }
}
Esempio n. 5
0
static int tdav_producer_audiounit_start(tmedia_producer_t* self)
{
	tdav_producer_audiounit_t* producer = (tdav_producer_audiounit_t*)self;
	
    if(!producer){
		TSK_DEBUG_ERROR("Invalid parameter");
		return -1;
	}
	if(producer->paused){
		producer->paused = tsk_false;
		return tsk_false;
	}
	
	int ret;
	if(producer->started){
		TSK_DEBUG_WARN("Already started");
		return 0;
	}
	else {
		ret = tdav_audiounit_handle_start(producer->audioUnitHandle);
		if(ret){
			TSK_DEBUG_ERROR("tdav_audiounit_handle_start failed with error code=%d", ret);
			return ret;
		}
	}
	producer->started = tsk_true;
    
    // apply parameters (because could be lost when the producer is restarted -handle recreated-)
    ret = tdav_audiounit_handle_mute(producer->audioUnitHandle, producer->muted);

	TSK_DEBUG_INFO("AudioUnit producer started");
	return 0;
}
int tnet_transport_add_socket(const tnet_transport_handle_t *handle, tnet_fd_t fd, tnet_socket_type_t type, tsk_bool_t take_ownership, tsk_bool_t isClient)
{
	tnet_transport_t *transport = (tnet_transport_t*)handle;
	transport_context_t* context;
	int ret = -1;
    
	if (!transport) {
		TSK_DEBUG_ERROR("Invalid server handle.");
		return ret;
	}
	
	if (!(context = (transport_context_t*)transport->context)) {
		TSK_DEBUG_ERROR("Invalid context.");
		return -2;
	}
    
	if (TNET_SOCKET_TYPE_IS_TLS(type)) {
		transport->tls.have_tls = 1;
	}
	
	if ((ret = addSocket(fd, type, transport, take_ownership, isClient))) {
		TSK_DEBUG_ERROR("Failed to add new Socket.");
		return ret;
	}
    
	if (context->cf_run_loop) {
		// Signal the run-loop
        CFRunLoopWakeUp(context->cf_run_loop);
        return 0;
	} else {
		TSK_DEBUG_WARN("run_loop not initialized yet.");
		return 0; //Will be taken when mainthead start
	}
}
Esempio n. 7
0
int tdav_consumer_dsound_stop(tmedia_consumer_t* self)
{
	tdav_consumer_dsound_t* dsound = (tdav_consumer_dsound_t*)self;

	HRESULT hr;

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

	if(!dsound->started){
		TSK_DEBUG_WARN("Consumer not started");
		return 0;
	}

	/* should be done here */
	dsound->started = tsk_false;

	/* stop thread */
	if(dsound->tid[0]){
		tsk_thread_join(&(dsound->tid[0]));
	}

	if((hr = IDirectSoundBuffer_Stop(dsound->secondaryBuffer)) != DS_OK){
		tdav_win32_print_error("IDirectSoundBuffer_Stop", hr);
	}
	if((hr = IDirectSoundBuffer_SetCurrentPosition(dsound->secondaryBuffer, 0)) != DS_OK){
		tdav_win32_print_error("IDirectSoundBuffer_SetCurrentPosition", hr);
	}

	return 0;
}
static int tdav_consumer_audiounit_start(tmedia_consumer_t* self)
{
	tdav_consumer_audiounit_t* consumer = (tdav_consumer_audiounit_t*)self;
	
    if(!consumer){
		TSK_DEBUG_ERROR("Invalid parameter");
		return -1;
	}
	if(consumer->paused){
		consumer->paused = tsk_false;
	}
	if(consumer->started){
		TSK_DEBUG_WARN("Already started");
		return 0;
	}
	else {
		int ret = tdav_audiounit_handle_start(consumer->audioUnitHandle);
		if(ret){
			TSK_DEBUG_ERROR("tdav_audiounit_handle_start failed with error code=%d", ret);
			return ret;
		}
	}
	consumer->started = tsk_true;
	TSK_DEBUG_INFO("AudioUnit consumer started");
	return 0;
}
Esempio n. 9
0
int options_handle_event(const tsip_event_t *_event)
{
	const tsip_options_event_t* opt_event = TSIP_OPTIONS_EVENT(_event);
	const session_t* session;
	tsip_ssession_id_t sid;

	/* Find associated session */
	sid = tsip_ssession_get_id(_event->ss);
	if(!(session = session_get_by_sid(ctx->sessions, sid))){
		TSK_DEBUG_WARN("Failed to match session event.");
		return -1;
	}

	switch(opt_event->type){
		case tsip_i_options: /* incoming OPTIONS */
			break;
		case tsip_ao_options: /* answer to outgoing OPTIONS */
#if HACK_AOR
			if(TSIP_MESSAGE_IS_RESPONSE(_event->sipmessage)){
				options_hack_aor(_event->sipmessage);
			}
#endif
			break;
	}

	return 0;
}
static tsk_size_t tdav_speex_jitterbuffer_get(tmedia_jitterbuffer_t* self, void* out_data, tsk_size_t out_size)
{
	tdav_speex_jitterbuffer_t *jb = (tdav_speex_jitterbuffer_t *)self;
    JitterBufferPacket jb_packet;
    int ret;

    if(!out_data || !out_size){
        TSK_DEBUG_ERROR("Invalid parameter");
        return 0;
    }
    if(!jb->state){
        TSK_DEBUG_ERROR("Invalid state");
        return 0;
    }
	if(jb->x_data_size != out_size){ // consumer must request PTIME data
		TSK_DEBUG_WARN("%d not expected as frame size. %u<>%u", out_size, jb->frame_duration, (out_size * 500)/jb->rate);
		return 0;
	}

    jb_packet.data = out_data;
    jb_packet.len = out_size;

	if ((ret = jitter_buffer_get(jb->state, &jb_packet, jb->frame_duration/*(out_size * 500)/jb->rate*/, tsk_null)) != JITTER_BUFFER_OK) {
        switch(ret){
            case JITTER_BUFFER_MISSING: /*TSK_DEBUG_INFO("JITTER_BUFFER_MISSING - %d", ret);*/ break;
            case JITTER_BUFFER_INSERTION: /*TSK_DEBUG_INFO("JITTER_BUFFER_INSERTION - %d", ret);*/ break;
            default: TSK_DEBUG_INFO("jitter_buffer_get() failed - %d", ret); break;
        }
        jitter_buffer_update_delay(jb->state, &jb_packet, NULL);
        return 0;
    }
    // jitter_buffer_update_delay(jitterbuffer->state, &jb_packet, NULL);

    return out_size;
}
Esempio n. 11
0
/** Initialze the list of auids with default values from __txcap_auids
* auids must be null;
*/
int txcap_auids_init(txcap_auids_L_t** auids)
{
	size_t i;
	size_t count;
	if(!auids){
		TSK_DEBUG_ERROR("invalid parameter.");
		return -1;
	}
	else if(*auids){
		TSK_DEBUG_WARN("auids already initialized.");
	}
	else{
		*auids = tsk_list_create();
	}
	
	count = sizeof(__txcap_auids)/sizeof(auid_t);
	for(i = 0; i<count; i++){
		txcap_auid_t* auid = txcap_auid_create(__txcap_auids[i].type,
			__txcap_auids[i].id,
			__txcap_auids[i].mime_type,
			__txcap_auids[i].ns,
			__txcap_auids[i].document_name,
			__txcap_auids[i].global);
		tsk_list_push_back_data(*auids, (void**)&auid);
	}

	return 0;
}
Esempio n. 12
0
// This function returns first DTLS record. It's useful to send handshaking data by records to avoid IP fragmentation
int tnet_dtls_socket_get_record_first(const void* records, tsk_size_t records_size, const void** record, tsk_size_t* size)
{
	/* https://tools.ietf.org/html/rfc6347#section-3.2.3
	TLS and DTLS handshake messages can be quite large(in theory up to
	2 ^ 24 - 1 bytes, in practice many kilobytes).By contrast, UDP
	datagrams are often limited to <1500 bytes if IP fragmentation is not
	desired.In order to compensate for this limitation, each DTLS
	handshake message may be fragmented over several DTLS records, each
	of which is intended to fit in a single IP datagram.Each DTLS
	handshake message contains both a fragment offset and a fragment
	length.Thus, a recipient in possession of all bytes of a handshake
	message can reassemble the original unfragmented message. */
	// 4.1.  Record Layer - https://tools.ietf.org/html/rfc6347#section-4.1
#define kDTLSv1RecordHdrStartIndex		11
#define kDTLSv1RecordHdrLengthFieldLen	2 // uint16
#define kDTLSv1RecordHdrLen				(kDTLSv1RecordHdrStartIndex + kDTLSv1RecordHdrLengthFieldLen)
	
	const uint8_t* pc_records;
	tsk_size_t record_length;
	if (!records || records_size < kDTLSv1RecordHdrLen || !record || !size) {
		TSK_DEBUG_ERROR("Invalid parameter");
		return -1;
	}
	pc_records = (const uint8_t*)records;
	record_length = ((pc_records[kDTLSv1RecordHdrStartIndex] << 8) & 0xFF00) | (pc_records[kDTLSv1RecordHdrStartIndex + 1] & 0xFF);
	*record = records;
	*size = kDTLSv1RecordHdrLen + record_length;
	if ((*size) > TNET_DTLS_MTU) {
		TSK_DEBUG_WARN("DTLS record length(%u) > MTU(%u)", (unsigned)(*size), TNET_DTLS_MTU);
	}

	return 0;
}
Esempio n. 13
0
int tnet_dtls_socket_set_setup(tnet_dtls_socket_handle_t* handle, tnet_dtls_setup_t setup)
{
#if !HAVE_OPENSSL || !HAVE_OPENSSL_DTLS
	TSK_DEBUG_ERROR("OpenSSL or DTLS not enabled");
	return -200;
#else
	tnet_dtls_socket_t* socket = handle;
	if (!socket){
		TSK_DEBUG_ERROR("Invalid parameter");
		return -1;
	}

	switch ((socket->setup = setup)){
	case tnet_dtls_setup_passive:
		SSL_set_accept_state(socket->ssl);
		break;
	case tnet_dtls_setup_active:
	case tnet_dtls_setup_actpass:
	case tnet_dtls_setup_none:
		if (setup != tnet_dtls_setup_active){
			TSK_DEBUG_WARN("using setup=%s is not a good idea", TNET_DTLS_SETUP_NAMES[setup]);
		}
		SSL_set_connect_state(socket->ssl);
		break;
	default:
		TSK_DEBUG_ERROR("%d not valid value for DTLS setup", (int32_t)setup);
		break;
	}
	return 0;
#endif
}
Esempio n. 14
0
int tdav_producer_waveapi_stop(tmedia_producer_t* self)
{
	tdav_producer_waveapi_t* producer = (tdav_producer_waveapi_t*)self;
	MMRESULT result;

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

	if(!producer->started){
		TSK_DEBUG_WARN("Producer not started");
		return 0;
	}

	/* stop thread */
	if(producer->tid[0]){
		SetEvent(producer->events[1]);
		tsk_thread_join(&(producer->tid[0]));
	}

	/* should be done here */
	producer->started = tsk_false;

	if(producer->hWaveIn && (((result = waveInReset(producer->hWaveIn)) != MMSYSERR_NOERROR) || ((result = waveInClose(producer->hWaveIn)) != MMSYSERR_NOERROR))){
		print_last_error(result, "waveInReset/waveInClose");
	}

	return 0;
}
Esempio n. 15
0
int tmedia_jitterbuffer_close(tmedia_jitterbuffer_t* self)
{
	if(!self || !self->plugin){
		TSK_DEBUG_ERROR("Invalid parameter");
		return -1;
	}
	if(!self->opened){
		TSK_DEBUG_WARN("JitterBuffer not opened");
		return 0;
	}

	if(self->plugin->close){
		int ret;

		if((ret = self->plugin->close(self))){
			TSK_DEBUG_ERROR("Failed to close [%s] jitterbufferr", self->plugin->desc);
			return ret;
		}
		else{
			self->opened = tsk_false;
			return 0;
		}
	}
	else{
		self->opened = tsk_false;
		return 0;
	}
}
Esempio n. 16
0
/**@ingroup tsk_object_group
* Creates new object. The object MUST be declared using @ref TSK_DECLARE_OBJECT macro.
* @param objdef The object meta-data (definition). For more infomation see @ref tsk_object_def_t.
* @param ... List of parameters to pass to the constructor(defined in the meta-data).
* @retval @ref tsk_object_t object with a reference counter equal to 1.
* @sa @ref tsk_object_new_2.
*/
tsk_object_t* tsk_object_new(const tsk_object_def_t *objdef, ...)
{
	// Do not check "objdef", let the application die if it's null
	tsk_object_t *newobj = tsk_calloc(1, objdef->size);
	if(newobj){
		(*(const tsk_object_def_t **) newobj) = objdef;
		TSK_OBJECT_HEADER(newobj)->refCount = 1;
		if(objdef->constructor){ 
			va_list ap;
			tsk_object_t * newobj_ = newobj;// save
			va_start(ap, objdef);
			newobj = objdef->constructor(newobj, &ap); // must return new
			va_end(ap);

			if(!newobj){ // null if constructor failed to initialized the object
				if(objdef->destructor){
					objdef->destructor(newobj_);
				}
				tsk_free(&newobj_);
			}

#if TSK_DEBUG_OBJECTS
		TSK_DEBUG_INFO("N∞ objects:%d", ++tsk_objects_count);
#endif
		}
		else{
			TSK_DEBUG_WARN("No constructor found.");
		}
	}
	else{
		TSK_DEBUG_ERROR("Failed to create new tsk_object.");
	}

	return newobj;
}
Esempio n. 17
0
int tdav_producer_send_data(tdav_producer_t140_t* self, enum tmedia_t140_data_type_e data_type, const void* data_ptr, unsigned data_size)
{
	if(!self){
		TSK_DEBUG_ERROR("Invalid parameter");
		return -1;
	}
	if(TMEDIA_PRODUCER(self)->enc_cb.callback){
		if(data_type != tmedia_t140_data_type_utf8){
			// build data
			tsk_size_t cmd_size = 0, i;
			int32_t cmd_val = (int32_t)data_type;
			if(data_ptr || data_size){
				TSK_DEBUG_WARN("Data not expected for commands");
			}
			// TODO: use ASM POPCNT
			for(i = 0; i < 32; i+= 8){
				if(((cmd_val >> i) & 0xFF)){
					++cmd_size;
				}
			}
			if(cmd_size){
				TMEDIA_PRODUCER(self)->enc_cb.callback(TMEDIA_PRODUCER(self)->enc_cb.callback_data, &cmd_val, cmd_size);
			}
		}
		else{
Esempio n. 18
0
int tsip_transac_fsm_act(tsip_transac_t* self, tsk_fsm_action_id action_id, const tsip_message_t* message)
{
	if(!self || !self->fsm){
		TSK_DEBUG_WARN("Invalid parameter.");
		return -1;
	}
	return tsk_fsm_act(self->fsm, action_id, self, message, self, message);
}
Esempio n. 19
0
int tdav_consumer_dsound_start(tmedia_consumer_t* self)
{
	tdav_consumer_dsound_t* dsound = (tdav_consumer_dsound_t*)self;

	tsk_size_t i;
	HRESULT hr;
	LPDIRECTSOUNDNOTIFY lpDSBNotify;
	DSBPOSITIONNOTIFY pPosNotify[TDAV_DSOUNS_CONSUMER_NOTIF_POS_COUNT] = {0};

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

	if(!dsound->device || !dsound->primaryBuffer || !dsound->secondaryBuffer){
		TSK_DEBUG_ERROR("Consumer not prepared");
		return -2;
	}

	if(dsound->started){
		TSK_DEBUG_WARN("Consumer already started");
		return 0;
	}

	if((hr = IDirectSoundBuffer_QueryInterface(dsound->secondaryBuffer, &IID_IDirectSoundNotify, (LPVOID*)&lpDSBNotify)) != DS_OK){
		tdav_win32_print_error("IDirectSoundBuffer_QueryInterface", hr);
		return -3;
	}

	/* Events associated to notification points */
	for(i = 0; i<sizeof(dsound->notifEvents)/sizeof(HANDLE); i++){
		dsound->notifEvents[i] = CreateEvent(NULL, FALSE, FALSE, NULL);
		pPosNotify[i].dwOffset = ((dsound->bytes_per_notif * i) + dsound->bytes_per_notif) - 1;
		pPosNotify[i].hEventNotify = dsound->notifEvents[i];
	}
	if((hr = IDirectSoundNotify_SetNotificationPositions(lpDSBNotify, TDAV_DSOUNS_CONSUMER_NOTIF_POS_COUNT, pPosNotify)) != DS_OK){
		IDirectSoundNotify_Release(lpDSBNotify);
		tdav_win32_print_error("IDirectSoundBuffer_QueryInterface", hr);
		return -4;
	}
	
	if((hr = IDirectSoundNotify_Release(lpDSBNotify))){
		tdav_win32_print_error("IDirectSoundNotify_Release", hr);
	}
	
	/* start the reader thread */
	tsk_thread_create(&dsound->tid[0], __playback_thread, dsound);

	/* Start the buffer */
	if((hr = IDirectSoundBuffer_Play(dsound->secondaryBuffer,0, 0, DSBPLAY_LOOPING)) != DS_OK){
		tdav_win32_print_error("IDirectSoundNotify_Release", hr);
		return -5;
	}

	dsound->started = tsk_true;

	return 0;
}
Esempio n. 20
0
/**@ingroup tsk_mutex_group
* Unlock a mutex previously locked using @ref tsk_mutex_lock.
* @param handle The handle of the mutex to unlock.
* @retval Zero if succeed and non-zero otherwise.
* @sa @ref tsk_mutex_lock.
*/
int tsk_mutex_unlock(tsk_mutex_handle_t* handle)
{
    int ret = EINVAL;
    if(handle)
    {
#if TSK_UNDER_WINDOWS
        if((ret = ReleaseMutex((MUTEX_T)handle) ? 0 : -1)) {
            ret = GetLastError();
#else
        if((ret = pthread_mutex_unlock((MUTEX_T)handle)))
        {
#endif
            if(ret == TSK_ERROR_NOT_OWNER) {
                TSK_DEBUG_WARN("The calling thread does not own the mutex: %d", ret);
            }
            else {
                TSK_DEBUG_ERROR("Failed to unlock the mutex: %d", ret);
            }
        }
    }
    return ret;
}

/**@ingroup tsk_mutex_group
* Free/destroy a mutex.
* @param handle The mutex to free.
* @sa @ref tsk_mutex_create.
*/
void tsk_mutex_destroy(tsk_mutex_handle_t** handle)
{
    if(handle && *handle) {
#if TSK_UNDER_WINDOWS
        CloseHandle((MUTEX_T)*handle);
        *handle = tsk_null;
#else
        pthread_mutex_destroy((MUTEX_T)*handle);
        tsk_free(handle);
#endif
    }
    else {
        TSK_DEBUG_WARN("Cannot free an uninitialized mutex");
    }
}
Esempio n. 21
0
/**@ingroup tipsec_xp_group
*/
int tipsec_start(tipsec_context_t* ctx)
{
	tipsec_context_xp_t* ctx_xp = TIPSEC_CONTEXT_XP(ctx);
	int ret = -1;
	
	if(!ctx_xp){
		ret = -1;
		goto bail;
	}

	if(TIPSEC_CONTEXT(ctx_xp)->started){
		TSK_DEBUG_WARN("The IPSec context already started.");
		ret = -2;
		goto bail;
	}

	if(TIPSEC_CONTEXT(ctx_xp)->state != state_full){
		TSK_DEBUG_ERROR("IPSec context is in the wrong state.");
		ret = -3;
		goto bail;
	}

	if((ret = tipsec_set_IKey(ctx_xp))){
		TSK_DEBUG_ERROR("Failed to set IKey.");
		goto bail;
	}

	if((ret = tipsec_set_SPDs(ctx_xp))){
		TSK_DEBUG_ERROR("Failed to set SPDs.");
		goto bail;
	}

	if((ret = tipsec_set_SAs(ctx_xp))){
		TSK_DEBUG_ERROR("Failed to set SAs.");
		goto bail;
	}

	/* delete previous Policies */
	tipsec_run_command(TEXT("d sp "TEXT(TINYIPSEC_IPSEC6_UCPS_POLICY)));
	tipsec_run_command(TEXT("d sp "TEXT(TINYIPSEC_IPSEC6_USPC_POLICY)));

	/* Load new policies */
	if(!(ret = tipsec_run_command(TEXT("l "TEXT(TINYIPSEC_IPSEC6_FILE))))){
		TIPSEC_CONTEXT(ctx_xp)->started = 1;
	}
	
bail:
	/* Remove files */
	remove(TINYIPSEC_IPSEC6_FILE_SPD);
	remove(TINYIPSEC_IPSEC6_FILE_SAD);
	remove(TINYIPSEC_IPSEC6_FILE_KEY);

	return ret;
}
Esempio n. 22
0
int tdav_producer_waveapi_start(tmedia_producer_t* self)
{
	tdav_producer_waveapi_t* producer = (tdav_producer_waveapi_t*)self;
	MMRESULT result;
	tsk_size_t i;

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

	if(producer->started || producer->hWaveIn){
		TSK_DEBUG_WARN("Producer already started");
		return 0;
	}

	/* create events */
	if(!producer->events[0]){
		producer->events[0] = CreateEvent(NULL, FALSE, FALSE, NULL);
	}
	if(!producer->events[1]){
		producer->events[1] = CreateEvent(NULL, FALSE, FALSE, NULL);
	}

	/* open */
	 result = waveInOpen((HWAVEIN *)&producer->hWaveIn, /*WAVE_MAPPER*/0, &producer->wfx, (DWORD)producer->events[0], (DWORD_PTR)producer, CALLBACK_EVENT);
	 if(result != MMSYSERR_NOERROR){
		print_last_error(result, "waveInOpen");
		return -2;
	 }

	 /* start */
	 result = waveInStart(producer->hWaveIn);
	 if(result != MMSYSERR_NOERROR){
		print_last_error(result, "waveInStart");
		return -2;
	 }

	 /* start thread */
	 tsk_thread_create(&producer->tid[0], __record_thread, producer);

	 /* write */
	 for(i = 0; i< sizeof(producer->hWaveHeaders)/sizeof(LPWAVEHDR); i++){
		add_wavehdr(producer, i);
	}

	producer->started = tsk_true;

	return 0;
}
Esempio n. 23
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;
}
Esempio n. 24
0
static void send_bodiless(tdav_session_msrp_t *msrp){
	tmsrp_request_t* BODILESS;
	if(msrp->config->To_Path && msrp->config->From_Path){
		if((BODILESS = tmsrp_create_bodiless(msrp->config->To_Path->uri, msrp->config->From_Path->uri))){
			char* str;
			if((str = tmsrp_message_tostring(BODILESS))){
				if(!tnet_sockfd_send(msrp->connectedFD, str, tsk_strlen(str), 0)){
					TSK_DEBUG_WARN("Failed to send bodiless request.");
				}
				TSK_FREE(str);
			}

			TSK_OBJECT_SAFE_FREE(BODILESS);
		}
	}
}
Esempio n. 25
0
/**@ingroup tsk_object_group
* Delete an object. This function will delete the object even if it's reference counter is greater than 1.
* This mean that this function is not safe. You should use @ref TSK_OBJECT_SAFE_FREE to safely delete an object.
* The object MUST be declared using @ref TSK_DECLARE_OBJECT macro and created using @ref tsk_object_new or @ref tsk_object_new_2.
* @param self The object to delete.
* @sa @ref TSK_OBJECT_SAFE_FREE.
*/
void tsk_object_delete(tsk_object_t *self)
{
	const tsk_object_def_t ** objdef = (const tsk_object_def_t **)self;
	if(self && *objdef){
		if((*objdef)->destructor){
			self = (*objdef)->destructor(self);
#if TSK_DEBUG_OBJECTS
		TSK_DEBUG_INFO("N∞ objects:%d", --tsk_objects_count);
#endif
		}
		else{
			TSK_DEBUG_WARN("No destructor found.");
		}
		free(self);
	}
}
Esempio n. 26
0
/**@ingroup tsk_condwait_group
* Safely free a condwait variable previously created using @ref tsk_condwait_create.
* @param handle The condwait handle to free.
* @sa @ref tsk_condwait_create
*/
void tsk_condwait_destroy(tsk_condwait_handle_t** handle)
{
	tsk_condwait_t **condwait = (tsk_condwait_t**)handle;
	
	if(condwait && *condwait){
#if TSK_UNDER_WINDOWS
		CloseHandle((*condwait)->pcond);
#else
		tsk_mutex_destroy(&((*condwait)->mutex));
		pthread_cond_destroy((*condwait)->pcond);
		TSK_FREE((*condwait)->pcond);
#endif
		tsk_free((void**)condwait);
	}
	else{
		TSK_DEBUG_WARN("Cannot free an uninitialized condwait object");
	}
}
Esempio n. 27
0
static int tdav_producer_audiounit_start(tmedia_producer_t* self)
{
	tdav_producer_audiounit_t* producer = (tdav_producer_audiounit_t*)self;
	
    if(!producer){
		TSK_DEBUG_ERROR("Invalid parameter");
		return -1;
	}
	if(producer->paused){
		producer->paused = tsk_false;
		return tsk_false;
	}
	
	int ret;
	if(producer->started){
		TSK_DEBUG_WARN("Already started");
		return 0;
	}
	else {
		ret = tdav_audiounit_handle_start(producer->audioUnitHandle);
		if(ret){
			TSK_DEBUG_ERROR("tdav_audiounit_handle_start failed with error code=%d", ret);
			return ret;
		}
	}
	producer->started = tsk_true;
	
	// create conditional variable
    if (!producer->senderCondWait) {
        if (!(producer->senderCondWait = tsk_condwait_create())){
            TSK_DEBUG_ERROR("Failed to create conditional variable");
            return -2;
        }
    }
	// start the reader thread
	ret = tsk_thread_create(&producer->senderThreadId[0], __sender_thread, producer);
	if(ret){
		TSK_DEBUG_ERROR("Failed to start the sender thread. error code=%d", ret);
		return ret;
	}

	TSK_DEBUG_INFO("AudioUnit producer started");
	return 0;
}
Esempio n. 28
0
/**
 * Callback function called by the transport layer to alert the transaction for incoming messages
 *			or errors (e.g. transport error).
 *
 * @param [in,out]	self	A pointer to the NIC transaction. 
 * @param	type		The event type. 
 * @param [in,out]	msg	The incoming message.
 *
 * @return	Zero if succeed and no-zero error code otherwise. 
**/
int tsip_transac_nict_event_callback(const tsip_transac_nict_t *self, tsip_transac_event_type_t type, const tsip_message_t *msg)
{	
	int ret = 0;

	switch(type)
	{
	case tsip_transac_incoming_msg:
		{
			if(msg && TSIP_MESSAGE_IS_RESPONSE(msg)){
				if(TSIP_RESPONSE_IS_1XX(msg)){
					ret = tsip_transac_fsm_act(TSIP_TRANSAC(self), _fsm_action_1xx, msg);
				}
				else if(TSIP_RESPONSE_IS_23456(msg)){
					ret = tsip_transac_fsm_act(TSIP_TRANSAC(self), _fsm_action_200_to_699, msg);
				}
				else{
					TSK_DEBUG_WARN("Not supported status code: %d", TSIP_RESPONSE_CODE(msg));
				}
			}
			break;
		}

	case tsip_transac_canceled:
	case tsip_transac_terminated:
	case tsip_transac_timedout:
		break;

	case tsip_transac_error:
		{
			ret = tsip_transac_fsm_act(TSIP_TRANSAC(self), _fsm_action_error, msg);
			break;
		}

	case tsip_transac_transport_error:
		{
			ret = tsip_transac_fsm_act(TSIP_TRANSAC(self), _fsm_action_transporterror, msg);
			break;
		}
            
        default: break;
	}

	return ret;
}
int tnet_transport_pause_socket(const tnet_transport_handle_t *handle, tnet_fd_t fd, tsk_bool_t pause)
{
    tnet_transport_t *transport = (tnet_transport_t*)handle;
    transport_context_t *context;
    transport_socket_xt* socket;

    if(!transport || !(context = (transport_context_t*)transport->context)) {
        TSK_DEBUG_ERROR("Invalid parameter");
        return -1;
    }

    if((socket = getSocket(context, fd))) {
        socket->paused = pause;
    }
    else {
        TSK_DEBUG_WARN("Socket does not exist in this context");
    }
    return 0;
}
Esempio n. 30
0
static int tdav_producer_audioqueue_stop(tmedia_producer_t* self)
{
    OSStatus ret;
	tdav_producer_audioqueue_t* producer = (tdav_producer_audioqueue_t*)self;
	
	if(!self){
		TSK_DEBUG_ERROR("Invalid parameter");
		return -1;
	}
	
	if(!producer->started){
		TSK_DEBUG_WARN("Producer not started");
		return 0;
	}
    
	producer->started = tsk_false;
    ret = AudioQueueStop(producer->queue, false);
    
	return ret;
}