示例#1
0
/**
 * libeXosip cannot delete single authentication info, so I clear and re-add all rest auth,
 * libeXosip2 can change its api, so I don't need store all passwords.
 */
int uas_clear_authentication_info(sipua_uas_t *sipuas, char *regid, char *realm)
{
   xlist_user_t lu;
   int nauth;

   sipua_auth_t *auth;
   sipua_auth_t search_auth = {regid, realm};

   nauth = xlist_size(sipuas->auth_list);
	jua_debug(("\ruas_clear_authentication_info: ok\n"));
   
   xlist_delete_if(sipuas->auth_list, &search_auth, uas_match_auth, uas_done_auth);
   if(nauth == xlist_size(sipuas->auth_list))
   {
      return UA_FAIL;
   }
      
   eXosip_clear_authentication_info();

   auth = (sipua_auth_t*)xlist_first(sipuas->auth_list, &lu);
   while(auth)
   {
      eXosip_add_authentication_info(auth->regid, auth->authid, auth->password, NULL, auth->realm);
      auth = (sipua_auth_t*)xlist_next(sipuas->auth_list, &lu);
   }

   return UA_OK;
}
示例#2
0
static int jidentity_init(jidentity_t **fr, char *ch)
{
  char *next;
  int i;

  *fr = (jidentity_t *)osip_malloc(sizeof(jidentity_t));
  if (*fr==NULL) return -1;

  i = jidentity_get_and_set_next_token(&((*fr)->i_identity), ch, &next);
  if (i != 0)
    goto ji_error1;
  osip_clrspace ((*fr)->i_identity);
  ch = next;

  i = jidentity_get_and_set_next_token(&((*fr)->i_registrar), next, &next);
  if (i != 0)
    goto ji_error2;
  osip_clrspace ((*fr)->i_registrar);
  ch = next;

  i = jidentity_get_and_set_next_token(&((*fr)->i_realm), ch, &next);
  if (i != 0)
    goto ji_error3;
  osip_clrspace ((*fr)->i_realm);
  ch = next;

  i = jidentity_get_and_set_next_token(&((*fr)->i_userid), ch, &next);
  if (i != 0)
    goto ji_error4;
  osip_clrspace ((*fr)->i_userid);

  (*fr)->i_pwd = osip_strdup(next);
  osip_clrspace ((*fr)->i_pwd);

  if ((*fr)->i_pwd!=NULL && (*fr)->i_pwd[0]!='\0')
    {
      eXosip_add_authentication_info((*fr)->i_userid, (*fr)->i_userid,
				     (*fr)->i_pwd, NULL,
				     (*fr)->i_realm);
    }
  return 0;

 ji_error4:
  osip_free((*fr)->i_realm);
 ji_error3:
  osip_free((*fr)->i_registrar);
 ji_error2:
  osip_free((*fr)->i_identity);
 ji_error1:
  osip_free(*fr);
  *fr = NULL;
  return -1;
}
示例#3
0
int uas_set_authentication_info(sipua_uas_t *sipuas, char *regid, char *userid, char*passwd, char *realm)
{
   xlist_user_t lu;
   char username[256];
   int i;
   
   sipua_auth_t *new_auth;
   sipua_auth_t auth = {regid, realm, NULL, NULL};

	jua_debug(("\ruas_set_authentication_info: regid[%s] realm[%s]\n", regid, realm));

   if(xlist_find(sipuas->auth_list, &auth, uas_match_auth, &lu))
   {
      return UA_OK;
   }
   
   new_auth = uas_new_auth(regid, realm, userid, passwd);
   if(new_auth)
   {
      xlist_addto_first(sipuas->auth_list, new_auth);

      i=0;
      while(regid[i] != '@' && i < (256-1))
      {
         username[i] = regid[i];
         i++;
      }
      username[i] = '\0';

      if(eXosip_add_authentication_info(username, userid, passwd, NULL, realm) == 0)
      {
	      jua_debug(("\ruas_set_authentication_info: ok\n"));
         return UA_OK;
      }
   }
   
   return UA_FAIL;
}
示例#4
0
/**
 * owplLineAddCredential
 *
 * Add credential information to a line
 */
OWPL_RESULT
owplLineAddCredential(const OWPL_LINE hLine,                                                 
						const char* szUserID,
						const char* szPasswd,
						const char* szRealm)
{
	int ret;
	OWSIPAccount account ;

	account = owplLineSipAccountGet (hLine) ;
	if (account <= 0)
	{
		return OWPL_RESULT_INVALID_ARGS ;
	}

	if (szUserID == NULL || szPasswd == NULL)
	{
		return OWPL_RESULT_INVALID_ARGS ;
	}

	if (szRealm == NULL)
	{
		szRealm = owsip_account_domain_get (account) ;
		if (szRealm == NULL)
		{
			return OWPL_RESULT_FAILURE ;
		}
	}

	eXosip_lock();
	ret = eXosip_add_authentication_info(szUserID, szUserID, szPasswd, "", szRealm);
	eXosip_unlock();

	if(ret != 0) {
		return OWPL_RESULT_FAILURE;
	}
	return OWPL_RESULT_SUCCESS;
}
示例#5
0
/**
 * owplLineAddCredential
 *
 * Add credential information to a line
 */
MY_DLLEXPORT OWPL_RESULT
owplLineAddCredential(const OWPL_LINE hLine,                                                 
						const char* szUserID,
						const char* szPasswd,
						const char* szRealm)
{
	int ret;

	if (!szUserID
		|| !szPasswd
		|| !szRealm)
	{
		return OWPL_RESULT_INVALID_ARGS;
	}

	eXosip_lock();
	ret = eXosip_add_authentication_info(szUserID, szUserID, szPasswd, "", szRealm);
	eXosip_unlock();

	if(ret != 0) {
		return OWPL_RESULT_FAILURE;
	}
	return OWPL_RESULT_SUCCESS;
}
示例#6
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;
}
示例#7
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;
}
示例#8
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);
  }
}