Пример #1
0
void sipomatic_iterate(Sipomatic *obj)
{
	MSList *elem;
	MSList *to_be_destroyed=NULL;
	Call *call;
	double elapsed;
	eXosip_event_t *ev;

	while((ev=eXosip_event_wait(0,0))!=NULL){
		sipomatic_process_event(obj,ev);
	}
	elem=obj->calls;
	while(elem!=NULL){
		call=(Call*)elem->data;
		elapsed=time(NULL)-call->time;
		switch(call->state){
			case CALL_STATE_INIT:
				if (elapsed>obj->acceptance_time){
					call_accept(call);
				}
			break;
			case CALL_STATE_RUNNING:
				if (elapsed>obj->max_call_time || call->eof){
					call_release(call);
					to_be_destroyed=ms_list_append(to_be_destroyed,call);
				}
			break;
		}
		elem=ms_list_next(elem);
	}
	for(;to_be_destroyed!=NULL; to_be_destroyed=ms_list_next(to_be_destroyed)){
		call_destroy((Call*)to_be_destroyed->data);
	}
}
Пример #2
0
int main ( int argc, char *argv[] )
{
    int i, port = 5060;
    osip_trace_initialize_func(END_TRACE_LEVEL, &android_trace_func);
    i=eXosip_init();
    if (i!=0)
        return -1;
    i = eXosip_listen_addr (IPPROTO_UDP, NULL, port, AF_INET, 0);
    if (i!=0)
    {
        eXosip_quit();
        __android_log_print(ANDROID_LOG_ERROR, LOG_TAG, "%s", "could not initialize transport layer\n");
        return -1;
    }

    eXosip_event_t *je;
    for (;;)
    {
        je = eXosip_event_wait (0, 24*60*60*1000);
        eXosip_lock();
        eXosip_automatic_action ();
        eXosip_unlock();
        if (je == NULL)
            break;
        if (je->type == EXOSIP_CALL_INVITE)
        {
            __android_log_print(ANDROID_LOG_DEBUG, LOG_TAG, "%s", "incoming call\n");
            std::cout << "incoming call" << std::endl;
        }
    }

    return 0;
}				// ----------  end of function main  ----------
Пример #3
0
int uac_waitfor(const sessionId* id, const eXosip_event_type_t t,eXosip_event_t **event)
{
	eXosip_event_t *g_event  = NULL;/*消息事件*/
	while(1)
	{
	/*等待新消息的到来*/
		g_event = eXosip_event_wait(0, 50);/*侦听消息的到来*/
		eXosip_lock();
		eXosip_default_action(g_event);
		eXosip_automatic_refresh();/*Refresh REGISTER and SUBSCRIBE before the expiration delay*/
		eXosip_unlock();
		if ( g_event == NULL)
		{
			continue;
		}
		if(g_event->request==NULL)
		{
			continue;
		}

		if(id!=NULL && strcmp(id->call_id,g_event->request->call_id->number))
		{
			printf("id->call_id:%s g_event->request->call_id->number:%s\n",
					id->call_id, g_event->request->call_id->number);
			printf("id!=NULL &&\n");
			continue;
		}
		if(g_event->type==EXOSIP_CALL_RINGING || g_event->type==EXOSIP_MESSAGE_ANSWERED)
		{
			continue;
		}
		if(g_event->type==t)
		{
			(*event)=g_event;
			return 1;
		}
		else
		{
			(*event)=g_event;
			return 0;
		}
	}

	if(event==NULL)
	{
		printf("no response\n\n");
		return 0;
	}

	return 0;
}
Пример #4
0
int uac_register()
{
		int expires=3600;		/* 注册存活时间 */
		int ret = 0;			/* 注册返回值 */
		eXosip_event_t *je  = NULL;	/* 监听到的消息指针 */
		osip_message_t *reg = NULL;	/* 注册的消息体指针 */
		char from[100];/*sip:主叫用户名@被叫IP地址*/
		char proxy[100];/*sip:被叫IP地址:被叫IP端口*/

		memset(from, 0, 100);
		memset(proxy, 0, 100);
		sprintf(from, "sip:%s@%s", device_info.ipc_id, device_info.server_ip);
		sprintf(proxy, "sip:%s:%s", device_info.server_ip, device_info.server_port);

	/*------step 1-----------发送不带认证信息的注册请求-----------------------*/
	retry:
		eXosip_lock();
		g_register_id = eXosip_register_build_initial_register(from, proxy, NULL, expires, &reg);
		char mac[12];
		memset(mac,0,12);
		memcpy(mac,RegisterCon->self_MACaddr.macaddr,sizeof(RegisterCon->self_MACaddr.macaddr));
		//mac[12]='\n';
		//getNetInfo(NULL,mac);//printf("mac:%02x %02x %02x %02x %02x %02x",mac[0],mac[1],mac[2],mac[3],mac[4],mac[5]);

		codeToChar(mac,sizeof(mac));
		char mac_subject[20];
		sprintf(mac_subject,"MAC:%s\r\n",mac);
		osip_message_set_subject(reg,mac_subject);
		osip_message_set_authorization(reg, "Capability algorithm=\"H:MD5\"");
		if (0 > g_register_id)
		{
			eXosip_lock();
			printf("eXosip_register_build_initial_register error!\r\n");
			return -1;
		}
		printf("eXosip_register_build_initial_register success!\r\n");

		ret = eXosip_register_send_register(g_register_id, reg);
		eXosip_unlock();
		if (0 != ret)
		{
			printf("eXosip_register_send_register no authorization error!\r\n");
			return -1;
		}
		printf("eXosip_register_send_register no authorization success!\r\n");

		printf("g_register_id=%d\r\n", g_register_id);

		for (;;)
		{
			je = eXosip_event_wait(10, 500);/*侦听消息的到来*/

			if (NULL == je)/*没有接收到消息*/
			{
				continue;
			}
			if (EXOSIP_REGISTRATION_FAILURE == je->type)/*注册失败*/
			{
				printf("<EXOSIP_REGISTRATION_FAILURE>\r\n");
				printf("je->rid=%d\r\n", je->rid);
				/*-------step 2---------收到服务器返回的注册失败/401未认证状态------------*/
				if ((NULL != je->response)&&(401 == je->response->status_code))
				{
					AuthActive * auth_active_packet_data=NULL;
					osip_body_t *body;

					osip_header_t * subject;
					osip_message_get_subject(je->response,0,&subject);
					if(subject==NULL)
					{
						printf("no subject\n");
						return 0;
					}
					//printf("subject->hvalue:%s\n",subject->hvalue);
					char mac[12];
					memset(mac, 0, 12);
					memcpy(mac,subject->hvalue,4);
					if(!strcmp(mac,"MAC:"))
					{
						memcpy(mac,subject->hvalue+4,12);
						decodeFromChar(mac,12);
						memcpy(RegisterCon->peer_MACaddr.macaddr,mac,6);
					}
					else
					{
						printf("subject not match\n");
						return 0;
					}

					osip_message_get_body (je->response, 0, &body);
					if(!auth_active_packet_data)
					{
						free(auth_active_packet_data);
						auth_active_packet_data=NULL;
					}
					if((sizeof(AuthActive)*2)>(body->length))
					{
						printf("body->length is not enough");
						return 0;
					}
					auth_active_packet_data=(AuthActive *)malloc (sizeof(AuthActive)*2);//;body->length*sizeof(char));
					memset(auth_active_packet_data,0,sizeof(AuthActive)*2);
					memcpy(auth_active_packet_data,body->body, sizeof(AuthActive)*2);
					decodeFromChar((char*)auth_active_packet_data,sizeof(AuthActive)*2);
					if(!HandleWAPIProtocolAuthActive(RegisterCon,auth_active_packet_data))
					{
						printf("HandleWAPIProtocolAuthActive error\n");
						return 0;
					}

					/*
					//printf("message:%s\n",message);
					if(0/*when receive 401Unauthorized package,send ACK and Regester/)
					{
						osip_message_t *ack = NULL;
						int call_id=atoi(reg->call_id->number);
						printf("je->did:%d\n",je->did);
						ret=eXosip_call_build_ack(je->rid,&ack);
						ret=eXosip_call_send_ack(atoi(je->rid),ack);
					}
					*/

					reg = NULL;
					/*----------step 3-------------发送携带认证信息的注册请求----------------------*/
					eXosip_lock();
					int return_num;

					return_num=eXosip_clear_authentication_info();/*清除认证信息*/
					printf("return_num:%d\n",return_num);
					return_num=eXosip_add_authentication_info(device_info.ipc_id, device_info.ipc_id, device_info.ipc_pwd, "MD5", NULL);/*添加主叫用户的认证信息*/
					printf("return_num:%d\n",return_num);
					printf("je->rid:%d expires:%d return num:%d\n",je->rid,expires,eXosip_register_build_register(je->rid, expires, &reg));

					//if(auth_request_packet_data!=NULL)
					//{

						//free(auth_request_packet_data);
						//auth_request_packet_data=NULL;
					//}

					auth_request_packet_data=(AccessAuthRequ*)malloc(sizeof(AccessAuthRequ)*2);

					memset(auth_request_packet_data,0, sizeof(AccessAuthRequ)*2);

					if(ProcessWAPIProtocolAccessAuthRequest(RegisterCon,auth_active_packet_data,auth_request_packet_data)<1)
					{
						printf("ProcessWAPIProtocolAccessAuthRequest error\n");
						return 0;
					}
					codeToChar((char*)auth_request_packet_data,sizeof(AccessAuthRequ)*2);

					//printf("length:%d",(sizeof(AuthActive)*2));
					//printf("length:%d",(sizeof(AccessAuthRequ)*2));
					//printf("length:%d",(sizeof(CertificateAuthRequ)*2));
					//printf("length:%d",sizeof(CertificateAuthResp)*2);
					//printf("length:%d",sizeof(AccessAuthResp)*2);
					printf("111\n");
					if(reg==NULL)
					{
						printf("reg==NULL\n");
					}
					osip_message_set_body(reg,(char*)auth_request_packet_data,sizeof(AccessAuthRequ)*2);printf("222\n");
					printf("333\n");
					printf("je->rid:%d\n",je->rid);printf("444\n");
					ret = eXosip_register_send_register(je->rid, reg);
					eXosip_unlock();
					decodeFromChar((char *)auth_request_packet_data,sizeof(AccessAuthRequ)*2);
					if (0 != ret)
					{
						printf("eXosip_register_send_register authorization error!\r\n");
						return -1;
					}
					printf("eXosip_register_send_register authorization success!\r\n");
					eXosip_event_free (je);
					//free(auth_active_packet_data);
printf("end\n");
				}
				else/*真正的注册失败*/
				{
					printf("EXOSIP_REGISTRATION_FAILURE error!\r\n");
					eXosip_event_free (je);
					return -1;
					//goto retry;/*重新注册*/
				}
			}
			else if (EXOSIP_REGISTRATION_SUCCESS == je->type)
			{printf("recieve EXOSIP_REGISTRATION_SUCCESS\n");
				/*---------step 6-------------收到服务器返回的注册成功--------------------------------*/

				AccessAuthResp * access_auth_resp_data;
				osip_body_t *body;
				osip_message_get_body (je->response, 0, &body);
				if(body==NULL)
				{
					printf("body==NULL\n");
					return 0;
				}
				if( body->length<sizeof(AccessAuthResp)*2)
				{
					printf("message length is too short:%d\n",body->length);
					return 0;
				}
				access_auth_resp_data=(AccessAuthResp *)malloc (body->length*sizeof(char));
				memcpy(access_auth_resp_data,body->body, body->length);

				decodeFromChar((char*)access_auth_resp_data,sizeof(AccessAuthResp)*2);

				if(auth_request_packet_data==NULL)
				{
					printf("auth_request_packet_data = NULL\n");
				}
				if(HandleWAPIProtocolAccessAuthResp(RegisterCon,auth_request_packet_data,access_auth_resp_data)<1)
				{
					printf("HandleWAPIProtocolAccessAuthResp error\n");
					return 0;
				}

				g_register_id = je->rid;/*保存注册成功的注册ID*/
				printf("g_register_id=%d\r\n", g_register_id);
				printf("<EXOSIP_REGISTRATION_SUCCESS>\r\n");
				/*
				//send key agreement package  发送密钥协商包
				osip_message_t * inforequest;
				ret=eXosip_message_build_request(&inforequest,"MESSAGE",proxy,from,NULL);
				ret=osip_message_set_body(inforequest,"sssss",6);
				ret=eXosip_message_send_request(inforequest);

				*/
				eXosip_event_free (je);
				free(auth_request_packet_data);
				free(access_auth_resp_data);
				return 1;
				break;
			}
		}

		return 0;
}
Пример #5
0
int csenn_eXosip_invit(sessionId * id, char * to, char * sdpMessage, char * responseSdp)
{
	osip_message_t *invite;
	int i;// optionnal route header
	char to_[100];
	snprintf (to_, 100,"sip:%s", to);
	char from_[100];
		snprintf (from_, 100,
			"sip:%s:%s", device_info.ipc_ip ,device_info.ipc_port );
		//snprintf (tmp, 4096, "");
	/*i = eXosip_call_build_initial_invite (&invite,
			"sip:[email protected]:5060",
			"sip:[email protected]:5060",
			NULL,
			"34020000001320000001:1,34020000001180000002:1" );*/
		i = eXosip_call_build_initial_invite (&invite,
					to_,
					from_,
					NULL,
					"This is a call for a conversation" );
	//i = eXosip_call_build_initial_invite (&invite,"<sip:[email protected]>",	"<sip:[email protected]>",NULL,	"This is a call for a conversation" );
	if (i != 0)
	{
	return -1;
	}
	//osip_message_set_supported (invite, "100rel");
	{
	char tmp[4096];
	char localip[128];
	eXosip_guess_localip (AF_INET, localip, 128);
	localip[128]=device_info.ipc_ip;

	i=osip_message_set_body (invite, sdpMessage, strlen (sdpMessage));
	i=osip_message_set_content_type (invite, "APPLICATION/SDP");
	}
	eXosip_lock ();
	i = eXosip_call_send_initial_invite (invite);

	if (i > 0)
	{
	//eXosip_call_set_reference (i, "ssss");
	}
	eXosip_unlock ();
	int flag1 = 1;
	      while (flag1)
	        {
	    	  eXosip_event_t *je;
	          je = eXosip_event_wait (0, 1000);

	       if (je == NULL)
	        {
	          printf ("No response or the time is over!\n");
	          break;
	        }

	       switch (je->type)
	        {
	        case EXOSIP_CALL_INVITE:
	          printf ("a new invite reveived!\n");
	          break;
	        case EXOSIP_CALL_PROCEEDING:
	          printf ("proceeding!\n");
	          break;
	        case EXOSIP_CALL_RINGING:
	          printf ("ringing!\n");
	          //printf ("call_id is %d, dialog_id is %d \n", je->cid, je->did);
	          break;
	        case EXOSIP_CALL_ANSWERED:
	          printf ("ok! connected!\n");
	          printf ("call_id is %d, dialog_id is %d \n", je->cid, je->did);
	          id->cid=je->cid;
	          id->did=je->did;
	          osip_body_t *body;
	          osip_message_get_body (je->response, 0, &body);
	          //printf ("I get the msg is: %s\n", body->body);
	          //(*responseSdp)=(char *)malloc (body->length*sizeof(char));
	          if(body!=NULL)
	          snprintf (responseSdp, body->length,"%s", body->body);

	           //response a ack
	          osip_message_t *ack = NULL;
	          eXosip_call_build_ack (je->did, &ack);
	          eXosip_call_send_ack (je->did, ack);
	          flag1 = 0;
	          break;
	        case EXOSIP_CALL_CLOSED:
	          printf ("the other sid closed!\n");
	          break;
	        case EXOSIP_CALL_ACK:
	          printf ("ACK received!\n");
	          break;
	        default:
	          printf ("other response!\n");
	          break;
	        }
	       eXosip_event_free (je);

	        }
	return 0;

}
Пример #6
0
int main (int argc, char *argv[])
{
	int port = 5060;
	eXosip_event_t *event = NULL;
	succeed_type flag;
#if !defined(__arc__)
	struct servent *service = NULL;
#endif
	struct regparam_t regparam = { 0, 3600, 0 };
	int debug = 1;

	port = 5060;
#if 0
	if (debug > 0)
		TRACE_INITIALIZE (6, NULL);
#endif
	context_eXosip = eXosip_malloc ();
	if (eXosip_init (context_eXosip)) {
		printf("eXosip_init failed\r\n");
		exit (1);
	}
	if (eXosip_listen_addr (context_eXosip, IPPROTO_UDP, "192.168.5.118", port, AF_INET, 0)) {
		printf("eXosip_listen_addr failed\r\n");
		exit (1);
	}

	/*start the notify thread */

#ifndef OSIP_MONOTHREAD
	notify_thread = osip_thread_create(20000, notify_proc, &regparam);

#endif

	for(;;)
	{

		eXosip_event_t *event;

		if (!(event = eXosip_event_wait (context_eXosip, 0, 1))) {
#ifdef OSIP_MONOTHREAD
			eXosip_execute (context_eXosip);
			eXosip_automatic_action (context_eXosip);
#endif
//			osip_usleep (10000);
			continue;
		}

		eXosip_lock(context_eXosip);
#ifdef OSIP_MONOTHREAD	
		eXosip_execute (context_eXosip);
#endif			
		//		eXosip_automatic_action (context_eXosip);
		eXosip_unlock(context_eXosip);
		
		eXosip_automatic_action(context_eXosip);
		switch (event->type) {

			case EXOSIP_CALL_INVITE: 
				if(MSG_IS_INVITE(event->request))
				{
					flag = handle_request_invite(context_eXosip, event);
					if(flag == succeed_type_failed)
					{
						printf("handle invite request failed\r\n");
					}else{
						printf("handle invite request succeed\r\n");
					}
					continue;
				}
				break;
			case EXOSIP_CALL_REINVITE:
				break;
			case EXOSIP_CALL_NOANSWER:
				break;
			case EXOSIP_CALL_PROCEEDING:
				break;
			case EXOSIP_CALL_RINGING:
				break;
			case EXOSIP_CALL_ANSWERED:
				break;
			case EXOSIP_CALL_REDIRECTED:
				break;
			case EXOSIP_CALL_REQUESTFAILURE:
				break;
			case EXOSIP_CALL_SERVERFAILURE:
				break;
			case EXOSIP_CALL_GLOBALFAILURE:
				break;
			case EXOSIP_CALL_ACK:
				break;
			case EXOSIP_CALL_CANCELLED:
				break;
			case EXOSIP_CALL_MESSAGE_NEW:

				break;
			case EXOSIP_CALL_MESSAGE_PROCEEDING:
				printf("EXOSIP_CALL_MESSAGE_PROCEEDING\r\n");
				break;
			case EXOSIP_CALL_MESSAGE_ANSWERED:
				break;
			case EXOSIP_CALL_MESSAGE_REDIRECTED:
				break;
			case EXOSIP_CALL_MESSAGE_REQUESTFAILURE:
				break;
			case EXOSIP_CALL_MESSAGE_SERVERFAILURE:
				break;
			case EXOSIP_CALL_MESSAGE_GLOBALFAILURE:
				break;
			case EXOSIP_CALL_CLOSED:
				break;
			case EXOSIP_CALL_RELEASED:
				break;
			case EXOSIP_MESSAGE_NEW:
				printf("answer EXOSIP_MESSAGE_NEW\r\n");
				if(MSG_IS_MESSAGE(event->request)) 
				{
					flag = handle_request_message(context_eXosip, event);
					if(flag == succeed_type_failed)
					{
						printf("handle message request failed\r\n");
					}else{
						printf("handle message request succeed\r\n");
					}
					continue;
				}

				if(MSG_IS_REGISTER(event->request))
				{
					flag = handle_request_register(context_eXosip, event);
					if(flag == succeed_type_failed)
					{
						printf("handle register request failed\r\n");
					}else{
						printf("handle register request succeed\r\n");
					}
					continue;
				}

				break;
			case EXOSIP_MESSAGE_PROCEEDING:
				break;
			case EXOSIP_MESSAGE_ANSWERED:
				break;
			case EXOSIP_MESSAGE_REDIRECTED:
				break;
			case EXOSIP_MESSAGE_REQUESTFAILURE:
				break;
			case EXOSIP_MESSAGE_SERVERFAILURE:
				break;
			case EXOSIP_MESSAGE_GLOBALFAILURE:
				break;
			case EXOSIP_SUBSCRIPTION_NOANSWER:
				break;
			case EXOSIP_SUBSCRIPTION_PROCEEDING:
				break;
			case EXOSIP_SUBSCRIPTION_ANSWERED:
				break;
			case EXOSIP_SUBSCRIPTION_REDIRECTED:
				break;
			case EXOSIP_SUBSCRIPTION_REQUESTFAILURE:
				break;
			case EXOSIP_SUBSCRIPTION_SERVERFAILURE:
				break;
			case EXOSIP_SUBSCRIPTION_GLOBALFAILURE:
				break;
			case EXOSIP_SUBSCRIPTION_NOTIFY:
				break;
			case EXOSIP_IN_SUBSCRIPTION_NEW:  //subscribe event
				if(MSG_IS_SUBSCRIBE(event->request))
				{

					flag = handle_request_subscribe(context_eXosip, event);
					if(flag == succeed_type_failed)
					{
						printf("handle subscribe request failed\r\n");
					}else{
						printf("handle subscribe request succeed\r\n");
					}
					continue;
				}
				break;
			case EXOSIP_NOTIFICATION_NOANSWER:
				break;
			case EXOSIP_NOTIFICATION_PROCEEDING:
				break;
			case EXOSIP_NOTIFICATION_ANSWERED:
				break;
			case EXOSIP_NOTIFICATION_REDIRECTED:
				break;
			case EXOSIP_NOTIFICATION_REQUESTFAILURE:
				break;
			case EXOSIP_NOTIFICATION_SERVERFAILURE:
				break;
			case EXOSIP_NOTIFICATION_GLOBALFAILURE:
				break;
			case EXOSIP_EVENT_COUNT:
				break;
			default:
				printf( "recieved unknown eXosip event (type, did, cid) = (%d, %d, %d)", event->type, event->did, event->cid);

		}
		eXosip_event_free (event);
	}
		

	
}
Пример #7
0
gint get_exosip_events(gpointer main_window)
{
	eXosip_event_t *je;
	char display[500] = "";
 	eXosip_lock();
	eXosip_unlock();

	/* Check for eXosip event - timeout after 50ms */
	if((je = eXosip_event_wait(0,50)) != NULL)
	{
		/* Uncomment the next line for debugging */
		 //fprintf(stderr, "Event type: %d %s\n", je->type, je->textinfo);

		imsua_display_event_info(je);

		if (je->type == EXOSIP_CALL_INVITE)
		{
			ims_process_incoming_invite(je);
		}
		else if (je->type == EXOSIP_CALL_REINVITE)
		{
			ims_process_incoming_reinvite(je);
		}
		else if (je->type == EXOSIP_CALL_RINGING)
		{
			ims_process_18x(je);
		}
		else if (je->type == EXOSIP_CALL_GLOBALFAILURE)
		{
			ims_process_released_call(je);
		}
		else if (je->type == EXOSIP_CALL_CLOSED)
		{
			ims_process_released_call(je);
		}
		else if (je->type == EXOSIP_CALL_ANSWERED)
		{
			ims_process_200ok(je);

		}
		else if (je->type == EXOSIP_CALL_RELEASED)
		{
			ims_process_released_call(je);

		}
		else if (je->type ==  EXOSIP_CALL_CANCELLED)
		{
		 	ims_process_released_call(je);
		}
		else if (je->type == EXOSIP_CALL_ACK)
		{
			ims_process_ack(je);
		}
		else if (je->type == EXOSIP_CALL_MESSAGE_REQUESTFAILURE)
		{
			ims_process_released_call(je);
		}
		else if (je->type == EXOSIP_CALL_REQUESTFAILURE)
		{
			set_display("Call released");
		}
		else if (je->type == EXOSIP_CALL_SERVERFAILURE)
		{
			set_display("Call released by server");
		}
		else if (je->type == EXOSIP_CALL_MESSAGE_NEW)
		{
			if (MSG_IS_PRACK(je->request))
				ims_process_prack(je);
			else if (MSG_IS_UPDATE(je->request))
				ims_process_update(je);
			else if (MSG_IS_INFO(je->request))
				common_process_info(je);
			else if (MSG_IS_BYE(je->request))
				imsua_set_message_display("OK (BYE)", 1);
		}
		else if (je->type == EXOSIP_CALL_MESSAGE_ANSWERED)
		{
			if (MSG_IS_BYE(je->request))
				ims_process_released_call(je);
			else if (MSG_IS_UPDATE(je->request) || MSG_IS_PRACK(je->request))
				ims_process_2xx(je);
		}
		else if (je->type == EXOSIP_MESSAGE_NEW)
		{
			if (MSG_IS_MESSAGE(je->request))
			{
				/* Checks that message is actually destined for user by comparing sending TO field to IMPU */
				char sending_ui[50];
				strcpy(sending_ui,(((je->request)->to)->url)->username);
				strcat(sending_ui,"@");
				strcat(sending_ui,(((je->request)->to)->url)->host);

				char *temp;
				temp = strstr(pref->impu,":") + 1;

				if(strcmp(sending_ui,temp)==0)
				{
					char *null_string = NULL;
					ims_start_im_session(je, null_string);
				}

			}
			else if (MSG_IS_BYE(je->request))
			{
				set_display("Call ended");
			}

		}
		else if(je->type == EXOSIP_MESSAGE_REQUESTFAILURE)
		{

		}
		else if(je->type == EXOSIP_MESSAGE_ANSWERED)
		{

		}
		else if(je->type == EXOSIP_REGISTRATION_SUCCESS)
		{

			if(is_message_deregister == 1)
			{
				registered = NOT_REGISTERED;

				is_message_deregister = 0;

				sprintf(display, "Deregistered with %s",pref->realm);
				set_display(display);

				sprintf(display,"Not registered");
				set_status_bar(display);

				watchers_remove_all_watchers();

				num_associated_uris = 0;

			}
			else
			{
				registered = REGISTERED;
				ims_process_registration_200ok(je);

			}
		}
		else if(je->type == EXOSIP_REGISTRATION_FAILURE)
		{

			if((je->response)== NULL)
			{
				set_display("Registration failed for unknown reason\nMost probably incorrect credentials\n\nCheck Preferences");
			}
			else if(((je->response)->status_code == 403))
			{
				set_display("Invalid user name\n\nCheck Preferences");
			}
			else if(((je->response)->status_code == 401))
			{
				ims_process_401(je);
			}
			else if(((je->response)->status_code == 404) || ((je->response)->status_code == 407))
			{

				set_display("Error with credentials\n\nCheck Preferences");
			}
			else
			{
				set_display("Registration failed for unknown reason\n\nMost probably incorrect credentials\nCheck Preferences");
			}

		}
		else if(je->type == EXOSIP_REGISTRATION_REFRESHED)
		{
			set_display("Registration Refreshed");
			registered = REGISTERED;
		}
		else if(je->type == EXOSIP_REGISTRATION_TERMINATED)
		{
		}
		else if(je->type == EXOSIP_SUBSCRIPTION_ANSWERED)
		{
			ims_process_subscription_answered(je);
		}
		else if (je->type == EXOSIP_SUBSCRIPTION_NOTIFY)
		{
			ims_process_notify(je);

		}
		else if (je->type == EXOSIP_SUBSCRIPTION_REQUESTFAILURE)
		{

		}
		else if (je->type == EXOSIP_IN_SUBSCRIPTION_NEW)
		{

		}
		else if((je->response)&&((je->response)->status_code == 302))
		{
			ims_process_302(je);
		}
		else
		{
		}

	}

	return TRUE;
}
Пример #8
0
int main( int argc, char *argv[] )
{

	/* Set default preferences and retrieve existing preferences */
	preferences_set_default_preferences();
	preferences_get_preferences_from_xml_file("preferences.xml");

	state = IDLE;

	/* Initialize libraries */
	gtk_init (&argc, &argv);
	gst_init(NULL, NULL);
	if(msrp_init(events_msrp) < 0) {
		printf("Error initializing the MSRP library...\n");
	}

	/* Display the main GUI */
	imsUA = create_imsUA ();
	gtk_widget_show (imsUA);

	/* Setup our IPTV window */
	videoWin = create_videoWin();
	gtk_window_set_decorated(GTK_WINDOW(videoWin),FALSE);

	/* Prepare a GST pipeline for the background video */
	backgroundVideoPipeline = NULL;




	if (initialise_eXosip() < 0)
	{
		fprintf(stderr, "Could not initialise - Is port 5060 in use?\n");
	}
	else
	{
		eXosip_set_user_agent("UCT IMS Client");

		presence_get_buddy_list_from_file("buddylist");

		/* Check for incoming eXosip events every 200 ms */
		g_timeout_add (200, get_exosip_events, imsUA);

		/* run the main GUI */
		gtk_main ();

		/* if registered to a proxy deregister on exit*/
		if(registered == REGISTERED)//if client is registered
		{
			ims_send_deregister_message ();

			sleep(1);

			eXosip_event_t *je;

			while((je = eXosip_event_wait(0,50)) != NULL)
			{
				if((je->type == EXOSIP_REGISTRATION_FAILURE) && ((je->response)->status_code == 401))
					ims_process_401(je);
			}

		}

		presence_write_buddy_list_to_file("buddylist");

		preferences_write_preferences_to_xml_file("preferences.xml");

		msrp_quit();
		eXosip_quit();
		return 0;
	}
}
Пример #9
0
int
main (int argc, char *argv[])
{
  eXosip_event_t *je;
  osip_message_t *reg = NULL;
  osip_message_t *invite = NULL;
  osip_message_t *ack = NULL;
  osip_message_t *info = NULL;
  osip_message_t *message = NULL;

  int call_id, dialog_id;
  int i,flag;
  int flag1 = 1;
  int id;
 
  char *identity = "sip:[email protected]";
  char *registerer = "sip:192.168.44.100:5060";
  char *source_call = "sip:[email protected]";
  char *dest_call = "sip:[email protected]:5060";
 
  char command;
  char tmp[4096];
  char localip[128];

  printf("r     向服务器注册\n\n");
  printf("c     取消注册\n\n");
  printf("i     发起呼叫请求\n\n");
  printf("h     挂断\n\n");
  printf("q     退出程序\n\n");
  printf("s     执行方法INFO\n\n");
  printf("m     执行方法MESSAGE\n\n");
  //初始化
  i = eXosip_init ();
  if (i != 0)
    {
      printf ("Couldn't initialize eXosip!\n");
      return -1;
    }
  else
    {
      printf ("eXosip_init successfully!\n");
    }

  i = eXosip_listen_addr (IPPROTO_UDP, NULL, 5060, AF_INET, 0);
  if (i != 0)
    {
      eXosip_quit ();
      fprintf (stderr, "Couldn't initialize transport layer!\n");
      return -1;
    }
  flag = 1;
  while (flag)
    {
      printf ("please input the comand:\n");
      
      scanf ("%c", &command);
      getchar ();
      
      switch (command)
    {
    case 'r':
      printf ("This modal isn't commpleted!\n");
      break;
    case 'i':/* INVITE */
      i = eXosip_call_build_initial_invite (&invite, dest_call, source_call, NULL, "This si a call for a conversation");
      if (i != 0)
        {
          printf ("Intial INVITE failed!\n");
          break;
        }
        //符合SDP格式,其中属性a是自定义格式,也就是说可以存放自己的信息,但是只能是两列,比如帐户信息
        //但是经测试,格式:v o t必不可少,原因未知,估计是协议栈在传输时需要检查的
      snprintf (tmp, 4096,
            "v=0\r\n"
            "o=anonymous 0 0 IN IP4 0.0.0.0\r\n"
            "t=1 10\r\n"
            "a=username:rainfish\r\n"
            "a=password:123\r\n");
      osip_message_set_body (invite, tmp, strlen(tmp));
      osip_message_set_content_type (invite, "application/sdp");
      
      eXosip_lock ();
      i = eXosip_call_send_initial_invite (invite);
      eXosip_unlock ();
      flag1 = 1;
      while (flag1)
        {
          je = eXosip_event_wait (0, 200);
          
          if (je == NULL)
        {
          printf ("No response or the time is over!\n");
          break;
        }
          
          switch (je->type)
        {
        case EXOSIP_CALL_INVITE:
          printf ("a new invite reveived!\n");
          break;
        case EXOSIP_CALL_PROCEEDING:
          printf ("proceeding!\n");
          break;
        case EXOSIP_CALL_RINGING:
          printf ("ringing!\n");
          // call_id = je->cid;
          // dialog_id = je->did;
          printf ("call_id is %d, dialog_id is %d \n", je->cid, je->did);
          break;
        case EXOSIP_CALL_ANSWERED:
          printf ("ok! connected!\n");
          call_id = je->cid;
          dialog_id = je->did;
          printf ("call_id is %d, dialog_id is %d \n", je->cid, je->did);

          eXosip_call_build_ack (je->did, &ack);
          eXosip_call_send_ack (je->did, ack);
          flag1 = 0;
          break;
        case EXOSIP_CALL_CLOSED:
          printf ("the other sid closed!\n");
          break;
        case EXOSIP_CALL_ACK:
          printf ("ACK received!\n");
          break;
        default:
          printf ("other response!\n");
          break;
        }
          eXosip_event_free (je);
         
        }
      break;
    case 'h':
      printf ("Holded !\n");
      
      eXosip_lock ();
      eXosip_call_terminate (call_id, dialog_id);
      eXosip_unlock ();
      break;
    case 'c':
      printf ("This modal isn't commpleted!\n");
      break;
    case 's':
    //传输INFO方法
      eXosip_call_build_info (dialog_id, &info);
      snprintf (tmp , 4096,
            "hello,rainfish");
      osip_message_set_body (info, tmp, strlen(tmp));
      //格式可以任意设定,text/plain代表文本信息
      osip_message_set_content_type (info, "text/plain");
      eXosip_call_send_request (dialog_id, info);
      break;
    case 'm':
    //传输MESSAGE方法,也就是即时消息,和INFO方法相比,我认为主要区别,是MESSAGE不用建立连接,直接传输信息,而INFO必须
    //在建立INVITE的基础上传输。
      printf ("the mothed :MESSAGE\n");
      eXosip_message_build_request (&message, "MESSAGE", dest_call, source_call, NULL);
      snprintf (tmp, 4096,
            "hellor rainfish");
      osip_message_set_body (message, tmp, strlen(tmp));
      //假设格式是xml
      osip_message_set_content_type (message, "text/xml");
      eXosip_message_send_request (message);
      break;
    case 'q':
      eXosip_quit ();
      printf ("Exit the setup!\n");
      flag = 0;
      break;
    }
    }
  return (0);
}
Пример #10
0
int josua_event_get()
{
	int counter =0;
	/* use events to print some info */
	eXosip_event_t *je;
	for (;;)
	{
		char buf[100];
		je = eXosip_event_wait(0,50);
		if (je==NULL)
			break;
		counter++;
		printf( "\r\n#######<- (%i ) eXosip_event_wait from: %s",
				je->type,
				je->remote_uri);
			josua_printf(buf);

		if (je->type==EXOSIP_CALL_NEW)
		{
			printf( "<- (%i %i) INVITE from: %s",
				je->cid, je->did,
				je->remote_uri);
			josua_printf(buf);

			//			call.build(je);
		}
		else if (je->type==EXOSIP_CALL_ANSWERED)
		{
			printf( "<- (%i %i) [%i %s ANSWERED] %s",
				je->cid, je->did, 
				je->status_code,
				je->reason_phrase,
				je->remote_uri);
			josua_printf(buf);
			call.build(je);
		}
		else if (je->type==EXOSIP_CALL_PROCEEDING)
		{
			printf( "<- (%i %i) [%i %s] %s",
				je->cid, je->did, 
				je->status_code,
				je->reason_phrase,
				je->remote_uri);
			josua_printf(buf);
			cout<<("EXOSIP_CALL_PROCEEDING")<<endl;
		}
		else if (je->type==EXOSIP_CALL_RINGING)
		{
			printf( "<- (%i %i) [%i %s] %s",
				je->cid, je->did, 
				je->status_code,
				je->reason_phrase,
				je->remote_uri);
			josua_printf(buf);
			cout<<"EXOSIP_CALL_RINGING"<<endl;
		}
		else if (je->type==EXOSIP_CALL_CANCELLED)
		{cout<<"cancer";
		}
		else if (je->type==EXOSIP_CALL_REDIRECTED)
		{
			printf( "<- (%i %i) [%i %s] %s",
				je->cid, je->did,
				je->status_code,
				je->reason_phrase,
				je->remote_uri);
			josua_printf(buf);
			cout<<"EXOSIP_CALL_REDIRECTED"<<endl;
		}
		else if (je->type==EXOSIP_CALL_REQUESTFAILURE)
		{
			printf( "<- (%i %i) [%i %s] %s",
				je->cid, je->did,
				je->status_code,
				je->reason_phrase,
				je->remote_uri);
			josua_printf(buf);
			cout<<"EXOSIP_CALL_REQUESTFAILURE"<<endl;
		}
		else if (je->type==EXOSIP_CALL_SERVERFAILURE)
		{
			printf( "<- (%i %i) [%i %s] %s",
				je->cid, je->did, 
				je->status_code,
				je->reason_phrase,
				je->remote_uri);
			josua_printf(buf);
		}
		else if (je->type==EXOSIP_CALL_GLOBALFAILURE)
		{
			printf( "<- (%i %i) [%i %s] %s",
				je->cid, je->did,
				je->status_code,
				je->reason_phrase,
				je->remote_uri);
			josua_printf(buf);
		}
		else if (je->type==EXOSIP_CALL_CLOSED)
		{
			printf( "<- (%i %i) BYE from: %s",
				je->cid, je->did, je->remote_uri);
			josua_printf(buf);
		}
		else if (je->type==EXOSIP_CALL_HOLD)
		{
			printf( "<- (%i %i) INVITE (On Hold) from: %s",
				je->cid, je->did, je->remote_uri);
			josua_printf(buf);
		}
		else if (je->type==EXOSIP_CALL_OFFHOLD)
		{
			printf( "<- (%i %i) INVITE (Off Hold) from: %s",
				je->cid, je->did, je->remote_uri);
			josua_printf(buf);
		}
		else if (je->type==EXOSIP_REGISTRATION_SUCCESS)
		{
			printf( "<- (%i) [%i %s] %s for REGISTER_SUCCESS %s",
				je->rid,
				je->status_code,
				je->reason_phrase,
				je->remote_uri,
				je->req_uri);
			josua_printf(buf);
			cout<<endl;
		}
		else if (je->type==EXOSIP_REGISTRATION_REFRESHED)
		{

		}
		else if (je->type== EXOSIP_REGISTRATION_TERMINATED)
		{

		}
		else if (je->type==EXOSIP_REGISTRATION_FAILURE)
		{
			reg_id = eXosip_register_init(identity, registrar, contact);
			if(eXosip_add_authentication_info(username, username, password, NULL, NULL)) 
			{
				exit(1);
			}
			eXosip_lock();
			j = eXosip_register(reg_id, expires);
			eXosip_unlock();
			cout<<"REGISTER_FAILURE";
			printf( "<- (%i) [%i %s] %s for REGISTER_FAILURE %s",
				je->rid,
				je->status_code,
				je->reason_phrase,
				je->remote_uri,
				je->req_uri);
			josua_printf(buf);
		}
		else if (je->type==EXOSIP_OPTIONS_NEW)
		{
			printf( "<- (%i %i) OPTIONS from: %s",
				je->cid, je->did,
				je->remote_uri);
			josua_printf(buf);

		}
		else if (je->type==EXOSIP_OPTIONS_ANSWERED)
		{
			printf( "<- (%i %i) [%i %s] %s",
				je->cid, je->did, 
				je->status_code,
				je->reason_phrase,
				je->remote_uri);
			josua_printf(buf);
		}
		else if (je->type==EXOSIP_OPTIONS_PROCEEDING)
		{
			printf( "<- (%i %i) [%i %s] %s",
				je->cid, je->did, 
				je->status_code,
				je->reason_phrase,
				je->remote_uri);
			josua_printf(buf);

		}
		else if (je->type==EXOSIP_OPTIONS_REDIRECTED)
		{
			printf( "<- (%i %i) [%i %s] %s",
				je->cid, je->did,
				je->status_code,
				je->reason_phrase,
				je->remote_uri);
			josua_printf(buf);
		}
		else if (je->type==EXOSIP_OPTIONS_REQUESTFAILURE)
		{
			printf( "<- (%i %i) [%i %s] %s",
				je->cid, je->did,
				je->status_code,
				je->reason_phrase,
				je->remote_uri);
			josua_printf(buf);
		}
		else if (je->type==EXOSIP_OPTIONS_SERVERFAILURE)
		{
			printf( "<- (%i %i) [%i %s] %s",
				je->cid, je->did, 
				je->status_code,
				je->reason_phrase,
				je->remote_uri);
			josua_printf(buf);
		}
		else if (je->type==EXOSIP_OPTIONS_GLOBALFAILURE)
		{
			printf( "<- (%i %i) [%i %s] %s",
				je->cid, je->did,
				je->status_code,
				je->reason_phrase,
				je->remote_uri);
			josua_printf(buf);
		}
		else if (je->type==EXOSIP_INFO_NEW)
		{
			printf( "<- (%i %i) INFO from: %s",
				je->cid, je->did,
				je->remote_uri);
			josua_printf(buf);
		}
		else if (je->type==EXOSIP_INFO_ANSWERED)
		{
			printf( "<- (%i %i) [%i %s] %s",
				je->cid, je->did, 
				je->status_code,
				je->reason_phrase,
				je->remote_uri);
			josua_printf(buf);
		}
		else if (je->type==EXOSIP_INFO_PROCEEDING)
		{
			printf( "<- (%i %i) [%i %s] %s",
				je->cid, je->did, 
				je->status_code,
				je->reason_phrase,
				je->remote_uri);
			josua_printf(buf);
		}
		else if (je->type==EXOSIP_INFO_REDIRECTED)
		{
			printf( "<- (%i %i) [%i %s] %s",
				je->cid, je->did,
				je->status_code,
				je->reason_phrase,
				je->remote_uri);
			josua_printf(buf);
		}
		else if (je->type==EXOSIP_INFO_REQUESTFAILURE)
		{
			printf( "<- (%i %i) [%i %s] %s",
				je->cid, je->did,
				je->status_code,
				je->reason_phrase,
				je->remote_uri);
			josua_printf(buf);
		}
		else if (je->type==EXOSIP_INFO_SERVERFAILURE)
		{
			printf( "<- (%i %i) [%i %s] %s",
				je->cid, je->did, 
				je->status_code,
				je->reason_phrase,
				je->remote_uri);
			josua_printf(buf);
		}
		else if (je->type==EXOSIP_INFO_GLOBALFAILURE)
		{
			printf( "<- (%i %i) [%i %s] %s",
				je->cid, je->did,
				je->status_code,
				je->reason_phrase,
				je->remote_uri);
			josua_printf(buf);
		}

		else if (je->type==EXOSIP_SUBSCRIPTION_ANSWERED)
		{
			printf( "<- (%i %i) [%i %s] %s for SUBSCRIBE",
				je->sid, je->did, 
				je->status_code,
				je->reason_phrase,
				je->remote_uri);
			josua_printf(buf);

			printf( "<- (%i %i) online=%i [status: %i reason:%i]",
				je->sid, je->did, 
				je->online_status,
				je->ss_status,
				je->ss_reason);
			josua_printf(buf);

		}
		else if (je->type==EXOSIP_SUBSCRIPTION_PROCEEDING)
		{
			printf( "<- (%i %i) [%i %s] %s for SUBSCRIBE",
				je->sid, je->did, 
				je->status_code,
				je->reason_phrase,
				je->remote_uri);
			josua_printf(buf);

		}
		else if (je->type==EXOSIP_SUBSCRIPTION_REDIRECTED)
		{
			printf( "<- (%i %i) [%i %s] %s for SUBSCRIBE",
				je->sid, je->did,
				je->status_code,
				je->reason_phrase,
				je->remote_uri);
			josua_printf(buf);
		}
		else if (je->type==EXOSIP_SUBSCRIPTION_REQUESTFAILURE)
		{
			printf( "<- (%i %i) [%i %s] %s for SUBSCRIBE",
				je->sid, je->did,
				je->status_code,
				je->reason_phrase,
				je->remote_uri);
			josua_printf(buf);
		}
		else if (je->type==EXOSIP_SUBSCRIPTION_SERVERFAILURE)
		{
			printf( "<- (%i %i) [%i %s] %s for SUBSCRIBE",
				je->sid, je->did, 
				je->status_code,
				je->reason_phrase,
				je->remote_uri);
			josua_printf(buf);
		}
		else if (je->type==EXOSIP_SUBSCRIPTION_GLOBALFAILURE)
		{
			printf( "<- (%i %i) [%i %s] %s for SUBSCRIBE",
				je->sid, je->did,
				je->status_code,
				je->reason_phrase,
				je->remote_uri);
			josua_printf(buf);
		}
		else if (je->type==EXOSIP_SUBSCRIPTION_NOTIFY)
		{
			printf( "<- (%i %i) NOTIFY from: %s",
				je->sid, je->did,
				je->remote_uri);
			josua_printf(buf);

			printf( "<- (%i %i) online=%i [status: %i reason:%i]",
				je->sid, je->did, 
				je->online_status,
				je->ss_status,
				je->ss_reason);
			josua_printf(buf);

		}
		else if (je->type==EXOSIP_IN_SUBSCRIPTION_NEW)
		{
			printf( "<- (%i %i) SUBSCRIBE from: %s",
				je->nid, je->did,
				je->remote_uri);
			josua_printf(buf);

			/* search for the user to see if he has been
			previously accepted or not! */

			eXosip_notify(je->did, EXOSIP_SUBCRSTATE_PENDING, EXOSIP_NOTIFY_AWAY);
		}
		else if (je->textinfo[0]!='\0')
		{
			printf( "(%i %i %i %i) %s", je->cid, je->sid, je->nid, je->did, je->textinfo);
			josua_printf(buf);
		}


		eXosip_event_free(je);
	}
	if (counter>0)
		return 0;
	return -1;
}
Пример #11
0
/**
 * Processing the events, return the number of event happened.
 */
int jua_process_event(eXosipua_t *jua)
{
	int counter =0;

	eXosip_event_t *je;

	for (;;)
   {
		char buf[100];

		je = eXosip_event_wait(0,50);

		if (je==NULL)
			break;
      
		counter++;

      jua_debug(("jua_process_event: je->status_code[%d]\n", je->status_code));

		if (je->type==EXOSIP_CALL_NEW)
		{
         jua_log(("jua_process_event: EXOSIP_CALL_NEW\n"));
			jcall_new(jua, je);
		}
		else if (je->type==EXOSIP_CALL_ANSWERED)
		{
         jua_log(("jua_process_event: EXOSIP_CALL_ANSWERED\n"));
			jcall_answered(jua, je);
		}
		else if (je->type==EXOSIP_CALL_ACK)
		{
         jua_log(("jua_process_event: EXOSIP_CALL_ACK\n"));
         jcall_ack(jua, je);
		}
		else if (je->type==EXOSIP_CALL_PROCEEDING)
		{
         jua_log(("jua_process_event: EXOSIP_CALL_PROCEEDING\n"));
         jcall_proceeding(jua, je);
		}
		else if (je->type==EXOSIP_CALL_RINGING)
		{
         jua_log(("jua_process_event: EXOSIP_CALL_RINGING\n"));
         jcall_ringing(jua, je);
		}
		else if (je->type==EXOSIP_CALL_REDIRECTED)
		{
         jua_log(("jua_process_event: EXOSIP_CALL_REDIRECTED\n"));
			jcall_redirected(jua, je);
		}
		else if (je->type==EXOSIP_CALL_REQUESTFAILURE)
		{
         jua_log(("jua_process_event: EXOSIP_CALL_REQUESTFAILURE\n"));
			jcall_requestfailure(jua, je);
		}
		else if (je->type==EXOSIP_CALL_SERVERFAILURE)
		{                               
         jua_log(("jua_process_event: EXOSIP_CALL_SERVERFAILURE\n"));
			jcall_serverfailure(jua, je);
		}
		else if (je->type==EXOSIP_CALL_GLOBALFAILURE)
		{
         jua_log(("jua_process_event: EXOSIP_CALL_GLOBALFAILURE\n"));
			jcall_globalfailure(jua, je);
		}
		else if (je->type==EXOSIP_CALL_CLOSED)
		{
         jua_log(("jua_process_event: EXOSIP_CALL_CLOSED\n"));
			jcall_closed(jua, je);
		}
		else if (je->type==EXOSIP_CALL_HOLD)
		{
         jua_log(("jua_process_event: EXOSIP_CALL_HOLD\n"));
			jcall_onhold(jua, je);
		}
		else if (je->type==EXOSIP_CALL_OFFHOLD)
		{
         jua_log(("jua_process_event: EXOSIP_CALL_OFFHOLD\n"));
			jcall_offhold(jua, je);
		}
		else if (je->type==EXOSIP_REGISTRATION_SUCCESS)
		{
			sipua_reg_event_t reg_e;
         
			eXosip_reg_t *jr;
         osip_message_t *message = NULL;

			reg_e.event.call_info = NULL;

         reg_e.event.type = SIPUA_EVENT_REGISTRATION_SUCCEEDED;
			reg_e.status_code = je->status_code;	/* eg: 200*/
			reg_e.server_info = je->reason_phrase;  /* eg: OK */
			reg_e.server = je->req_uri;				/* eg: sip:registrar.domain */
			/*
			je->remote_uri // eg: regname@domain 
			*/

			/*
          * Retrieve exactly returned expiration seconds
			 */
         message = eXosipua_extract_message(jua, je);
         if(message)
         {
            osip_contact_t  *contact = NULL;
            osip_message_get_contact(message, 0, &contact);

            if(contact)
            {
               osip_uri_param_t *expires = NULL;
               
               osip_contact_param_get_byname(contact, "expires", &expires);

               if(expires)
                  reg_e.seconds_expires = strtol(expires->gvalue, NULL, 10);
            }

            osip_message_free(message);
         }                                                                
         else
         {
			   jr = eXosip_event_get_reginfo(je);
			   reg_e.seconds_expires = jr->r_reg_period;
         }

			/*
			snprintf(buf, 99, "<- (%i) [%i %s] %s for REGISTER %s",
					je->rid, je->status_code, je->reason_phrase,
					je->remote_uri, je->req_uri);

			printf("jua_process_event: reg ok! [%s]\n", buf);
			*/

			jua->registration_status = je->status_code;
			
			snprintf(jua->registration_server, 100, "%s", je->req_uri);
	  
			if (je->reason_phrase!='\0')
				snprintf(jua->registration_reason_phrase, 100, "%s", je->reason_phrase);
			else 
				jua->registration_reason_phrase[0] = '\0';
	
			reg_e.event.from = jua->registration_server;
			reg_e.event.content = NULL;

			/* event back to sipuac */
			jua->sipuas.notify_event(jua->sipuas.lisener, &reg_e.event);
		}
		else if (je->type==EXOSIP_REGISTRATION_FAILURE)
		{
			sipua_reg_event_t reg_e;

			reg_e.event.type = SIPUA_EVENT_REGISTRATION_FAILURE;
			reg_e.status_code = je->status_code;
			reg_e.server_info = je->reason_phrase;

			reg_e.server = je->req_uri;

			reg_e.event.from = je->req_uri;

			reg_e.event.content = NULL;
			reg_e.event.call_info = NULL;

			/* event back to sipuac */
			jua->sipuas.notify_event(jua->sipuas.lisener, &reg_e.event);
		}
		else if (je->type==EXOSIP_OPTIONS_NEW)
		{
			int k;
	  
			/*
			snprintf(buf, 99, "<- (%i %i) OPTIONS from: %s",
					je->cid, je->did, je->remote_uri);
	  
            josua_printf(buf);
            */

			/* answer the OPTIONS method */

			/* 1: search for an existing call */
			for (k=0;k<MAX_NUMBER_OF_CALLS;k++)
			{
				if (jua->jcalls[k].state != NOT_USED || jua->jcalls[k].cid==je->cid)
					break;
			}
	  
			eXosip_lock();
	  
			if (jua->jcalls[k].cid==je->cid)
			{
				/* already answered! */
			}
			else if (k==MAX_NUMBER_OF_CALLS)
			{
				/* answer 200 ok */
				eXosip_answer_options(je->cid, je->did, 200);
			}
			else
			{

				/* answer 486 ok */
				eXosip_answer_options(je->cid, je->did, 486);
			}
	  
			eXosip_unlock();
		}
		else if (je->type==EXOSIP_OPTIONS_ANSWERED)
		{
			/*
			snprintf(buf, 99, "<- (%i %i) [%i %s] %s",
					je->cid, je->did, je->status_code,
					je->reason_phrase, je->remote_uri);
	  
            josua_printf(buf);
            */
		}
		else if (je->type==EXOSIP_OPTIONS_PROCEEDING)
		{
			/*
			snprintf(buf, 99, "<- (%i %i) [%i %s] %s",
					je->cid, je->did, je->status_code,
					je->reason_phrase, je->remote_uri);
	  
            josua_printf(buf);
            */
		}
		else if (je->type==EXOSIP_OPTIONS_REDIRECTED)
		{
			/*
			snprintf(buf, 99, "<- (%i %i) [%i %s] %s",
					je->cid, je->did, je->status_code,
					je->reason_phrase, je->remote_uri);
	  
            josua_printf(buf);
            */

		}
		else if (je->type==EXOSIP_OPTIONS_REQUESTFAILURE)
		{
			/*
			snprintf(buf, 99, "<- (%i %i) [%i %s] %s",
					je->cid, je->did, je->status_code,
					je->reason_phrase, je->remote_uri);
	  
            josua_printf(buf);
            */
		}
		else if (je->type==EXOSIP_OPTIONS_SERVERFAILURE)
		{
			/*
			snprintf(buf, 99, "<- (%i %i) [%i %s] %s",
					je->cid, je->did, je->status_code,
					je->reason_phrase, je->remote_uri);
	  
            josua_printf(buf);
            */
		}
		else if (je->type==EXOSIP_OPTIONS_GLOBALFAILURE)
		{
			/*
			snprintf(buf, 99, "<- (%i %i) [%i %s] %s",
					je->cid, je->did, je->status_code,
					je->reason_phrase, je->remote_uri);
			
            josua_printf(buf);
            */
		}
		else if (je->type==EXOSIP_INFO_NEW)
		{
			/*
			snprintf(buf, 99, "<- (%i %i) INFO from: %s",
					je->cid, je->did, je->remote_uri);
	  
			josua_printf(buf);
			*/
		}
		else if (je->type==EXOSIP_INFO_ANSWERED)
		{
			/*
			snprintf(buf, 99, "<- (%i %i) [%i %s] %s",
					je->cid, je->did, je->status_code,
					je->reason_phrase, je->remote_uri);

	  
            josua_printf(buf);
            */
		}
		else if (je->type==EXOSIP_INFO_PROCEEDING)
		{
			/*
			snprintf(buf, 99, "<- (%i %i) [%i %s] %s",
					je->cid, je->did, je->status_code,
					je->reason_phrase, je->remote_uri);
	  
            josua_printf(buf);
            */
		}
		else if (je->type==EXOSIP_INFO_REDIRECTED)
		{
			/*
			snprintf(buf, 99, "<- (%i %i) [%i %s] %s",
					je->cid, je->did, je->status_code,
					je->reason_phrase, je->remote_uri);
	  
            josua_printf(buf);
            */
		}
		else if (je->type==EXOSIP_INFO_REQUESTFAILURE)
		{
			snprintf(buf, 99, "<- (%i %i) [%i %s] %s",
					je->cid, je->did, je->status_code,
					je->reason_phrase, je->remote_uri);
	  
			/*josua_printf(buf);*/
		}
		else if (je->type==EXOSIP_INFO_SERVERFAILURE)
		{
			/*
			snprintf(buf, 99, "<- (%i %i) [%i %s] %s",
					je->cid, je->did, je->status_code,
					je->reason_phrase, je->remote_uri);
	  
            josua_printf(buf);
            */
		}
		else if (je->type==EXOSIP_INFO_GLOBALFAILURE)
		{
			/*
			snprintf(buf, 99, "<- (%i %i) [%i %s] %s",
					je->cid, je->did, je->status_code,
					je->reason_phrase, je->remote_uri);
	  
            josua_printf(buf);
            */
		}
		else if (je->type==EXOSIP_SUBSCRIPTION_ANSWERED)
		{
			/*
			snprintf(buf, 99, "<- (%i %i) [%i %s] %s for SUBSCRIBE",
					je->sid, je->did, je->status_code,
					je->reason_phrase, je->remote_uri);
	  
            josua_printf(buf);

            snprintf(buf, 99, "<- (%i %i) online=%i [status: %i reason:%i]",
					je->sid, je->did, je->online_status,
					je->ss_status, je->ss_reason);
	  
            josua_printf(buf);
            */
			jsubscription_answered(jua, je);
		}
		else if (je->type==EXOSIP_SUBSCRIPTION_PROCEEDING)
		{
			/*
			snprintf(buf, 99, "<- (%i %i) [%i %s] %s for SUBSCRIBE",
					je->sid, je->did, je->status_code,
					je->reason_phrase, je->remote_uri);
	  
            josua_printf(buf);
            */
			jsubscription_proceeding(jua, je);
		}
		else if (je->type==EXOSIP_SUBSCRIPTION_REDIRECTED)
		{
			/*
			snprintf(buf, 99, "<- (%i %i) [%i %s] %s for SUBSCRIBE",
					je->sid, je->did, je->status_code,
					je->reason_phrase, je->remote_uri);
	  
            josua_printf(buf);
            */
			jsubscription_redirected(jua, je);
		}
		else if (je->type==EXOSIP_SUBSCRIPTION_REQUESTFAILURE)
		{
			/*

			snprintf(buf, 99, "<- (%i %i) [%i %s] %s for SUBSCRIBE",
					je->sid, je->did, je->status_code,
					je->reason_phrase, je->remote_uri);
	  
            josua_printf(buf);
            */
			jsubscription_requestfailure(jua, je);
		}
		else if (je->type==EXOSIP_SUBSCRIPTION_SERVERFAILURE)
		{
			snprintf(buf, 99, "<- (%i %i) [%i %s] %s for SUBSCRIBE",
					je->sid, je->did, je->status_code,
					je->reason_phrase, je->remote_uri);
	  
			/*josua_printf(buf);*/
			jsubscription_serverfailure(jua, je);
		}
		else if (je->type==EXOSIP_SUBSCRIPTION_GLOBALFAILURE)
		{
			/*
			snprintf(buf, 99, "<- (%i %i) [%i %s] %s for SUBSCRIBE",
					je->sid, je->did, je->status_code,
					je->reason_phrase, je->remote_uri);
	  
            josua_printf(buf);

            */
			jsubscription_globalfailure(jua, je);
		}
		else if (je->type==EXOSIP_SUBSCRIPTION_NOTIFY)
		{
			/*
			snprintf(buf, 99, "<- (%i %i) NOTIFY from: %s",
					je->sid, je->did, je->remote_uri);
	  
            josua_printf(buf);

			snprintf(buf, 99, "<- (%i %i) online=%i [status: %i reason:%i]",
					je->sid, je->did, je->online_status,
					je->ss_status, je->ss_reason);
	  
            josua_printf(buf);
            */

			jsubscription_notify(jua, je);
		}
		else if (je->type==EXOSIP_IN_SUBSCRIPTION_NEW)
		{
			/*
			snprintf(buf, 99, "<- (%i %i) SUBSCRIBE from: %s",
					je->nid, je->did, je->remote_uri);
	  

            josua_printf(buf);
            */

			/* search for the user to see if he has been
				previously accepted or not! */

			eXosip_notify(je->did, EXOSIP_SUBCRSTATE_PENDING, EXOSIP_NOTIFY_AWAY);
			jinsubscription_new(jua, je);
		}
		else if (je->textinfo[0]!='\0')
		{
			/*
			snprintf(buf, 99, "(%i %i %i %i) %s", je->cid, je->sid, je->nid, je->did, je->textinfo);
	  
            josua_printf(buf);
            */

		}
	
		eXosip_event_free(je);
	}
  
	return(counter);
}
Пример #12
0
int
main (int argc, char *argv[])
#endif
{
  int c;
  int port = 5060;
  char *contact = NULL;
  char *fromuser = NULL;
  const char *localip = NULL;
  const char *firewallip = NULL;
  char *proxy = NULL;

#if !defined(__arc__)
  struct servent *service;
#endif
  char *username = NULL;
  char *password = NULL;
  struct regparam_t regparam = { 0, 3600, 0 };
#ifndef OSIP_MONOTHREAD
  struct osip_thread *register_thread;
#endif
  int debug = 0;
  int nofork = 0;

#ifdef _WIN32_WCE
  proxy = osip_strdup ("sip:sip.antisip.com");
  fromuser = osip_strdup ("sip:[email protected]");

#else
  for (;;) {
#define short_options "c:de:f:hl:p:r:u:U:P:"
#ifdef _GNU_SOURCE
    int option_index = 0;

    static struct option long_options[] = {
      {"contact", required_argument, NULL, 'c'},
      {"debug", no_argument, NULL, 'd'},
      {"expiry", required_argument, NULL, 'e'},
      {"firewallip", required_argument, NULL, 'f'},
      {"from", required_argument, NULL, 'u'},
      {"help", no_argument, NULL, 'h'},
      {"localip", required_argument, NULL, 'l'},
      {"port", required_argument, NULL, 'p'},
      {"proxy", required_argument, NULL, 'r'},
      {"username", required_argument, NULL, 'U'},
      {"password", required_argument, NULL, 'P'},
      {NULL, 0, NULL, 0}
    };

    c = getopt_long (argc, argv, short_options, long_options, &option_index);
#else
    c = getopt (argc, argv, short_options);
#endif
    if (c == -1)
      break;

    switch (c) {
    case 'c':
      contact = optarg;
      break;
    case 'd':
      nofork = 1;
#ifdef LOG_PERROR
      debug = LOG_PERROR;
#endif
      break;
    case 'e':
      regparam.expiry = atoi (optarg);
      break;
    case 'f':
      firewallip = optarg;
      break;
    case 'h':
      usage ();
      exit (0);
    case 'l':
      localip = optarg;
      break;
    case 'p':
#if !defined(__arc__)
      service = getservbyname (optarg, "udp");
      if (service)
        port = ntohs (service->s_port);
      else
        port = atoi (optarg);
#else
      port = atoi (optarg);
#endif
      break;
    case 'r':
      proxy = optarg;
      break;
    case 'u':
      fromuser = optarg;
      break;
    case 'U':
      username = optarg;
      break;
    case 'P':
      password = optarg;
      break;
    default:
      break;
    }
  }
#endif


  if (!proxy || !fromuser) {
    usage ();
    exit (1);
  }
#ifndef _WIN32_WCE
  if (!nofork) {
    daemon (1, 0);
  }
#endif

#if 0
  openlog (PROG_NAME, LOG_PID | debug, SYSLOG_FACILITY);
#endif

  syslog_wrapper (LOG_INFO, UA_STRING " up and running");
  syslog_wrapper (LOG_INFO, "proxy: %s", proxy);
  syslog_wrapper (LOG_INFO, "fromuser: %s", fromuser);
  syslog_wrapper (LOG_INFO, "contact: %s", contact);
  syslog_wrapper (LOG_INFO, "expiry: %d", regparam.expiry);
  syslog_wrapper (LOG_INFO, "local port: %d", port);

  if (debug > 0)
    TRACE_INITIALIZE (6, NULL);

  context_eXosip = eXosip_malloc ();
  if (eXosip_init (context_eXosip)) {
    syslog_wrapper (LOG_ERR, "eXosip_init failed");
    exit (1);
  }
  if (eXosip_listen_addr (context_eXosip, IPPROTO_UDP, NULL, port, AF_INET, 0)) {
    syslog_wrapper (LOG_ERR, "eXosip_listen_addr failed");
    exit (1);
  }

  if (localip) {
    syslog_wrapper (LOG_INFO, "local address: %s", localip);
    eXosip_masquerade_contact (context_eXosip, localip, port);
  }

  if (firewallip) {
    syslog_wrapper (LOG_INFO, "firewall address: %s:%i", firewallip, port);
    eXosip_masquerade_contact (context_eXosip, firewallip, port);
  }

  eXosip_set_user_agent (context_eXosip, UA_STRING);

  if (username && password) {
    syslog_wrapper (LOG_INFO, "username: %s", username);
    syslog_wrapper (LOG_INFO, "password: [removed]");
    if (eXosip_add_authentication_info (context_eXosip, username, username, password, NULL, NULL)) {
      syslog_wrapper (LOG_ERR, "eXosip_add_authentication_info failed");
      exit (1);
    }
  }

  {
    osip_message_t *reg = NULL;
    int i;

    regparam.regid = eXosip_register_build_initial_register (context_eXosip, fromuser, proxy, contact, regparam.expiry * 2, &reg);
    if (regparam.regid < 1) {
      syslog_wrapper (LOG_ERR, "eXosip_register_build_initial_register failed");
      exit (1);
    }
    i = eXosip_register_send_register (context_eXosip, regparam.regid, reg);
    if (i != 0) {
      syslog_wrapper (LOG_ERR, "eXosip_register_send_register failed");
      exit (1);
    }
  }

#ifndef OSIP_MONOTHREAD
  register_thread = osip_thread_create (20000, register_proc, &regparam);
  if (register_thread == NULL) {
    syslog_wrapper (LOG_ERR, "pthread_create failed");
    exit (1);
  }
#endif

  for (;;) {
    eXosip_event_t *event;

    if (!(event = eXosip_event_wait (context_eXosip, 0, 1))) {
#ifdef OSIP_MONOTHREAD
      eXosip_execute (context_eXosip);
      eXosip_automatic_action (context_eXosip);
#endif
      osip_usleep (10000);
      continue;
    }
#ifdef OSIP_MONOTHREAD
    eXosip_execute (context_eXosip);
#endif

    eXosip_automatic_action (context_eXosip);
    switch (event->type) {
    case EXOSIP_REGISTRATION_SUCCESS:
      syslog_wrapper (LOG_INFO, "registrered successfully");
      break;
    case EXOSIP_REGISTRATION_FAILURE:
      regparam.auth = 1;
      break;
    default:
      syslog_wrapper (LOG_DEBUG, "recieved unknown eXosip event (type, did, cid) = (%d, %d, %d)", event->type, event->did, event->cid);

    }
    eXosip_event_free (event);
  }
}