Example #1
0
void linphone_proxy_config_register_again_with_updated_contact(LinphoneProxyConfig *obj, osip_message_t *orig_request, osip_message_t *last_answer){
	osip_message_t *msg;
	const char *rport,*received;
	osip_via_t *via=NULL;
	osip_generic_param_t *param=NULL;
	osip_contact_t *ctt=NULL;
	osip_message_get_via(last_answer,0,&via);
	if (!via) return;
	osip_via_param_get_byname(via,"rport",&param);
	if (param) rport=param->gvalue;
	else return;
	param=NULL;
	osip_via_param_get_byname(via,"received",&param);
	if (param) received=param->gvalue;
	else return;
	osip_message_get_contact(orig_request,0,&ctt);
	if (strcmp(ctt->url->host,received)==0 && (ctt->url->port!=0 && strcmp(ctt->url->port,rport)==0)){
		ms_message("Register has up to date contact, doing nothing.");
		return;
	}
	eXosip_lock();
	eXosip_register_build_register(obj->rid,obj->expires,&msg);
	osip_message_get_contact(msg,0,&ctt);
	if (ctt->url->host!=NULL){
		osip_free(ctt->url->host);
	}
	ctt->url->host=osip_strdup(received);
	if (ctt->url->port!=NULL){
		osip_free(ctt->url->port);
	}
	ctt->url->port=osip_strdup(rport);
	eXosip_register_send_register(obj->rid,msg);
	eXosip_unlock();
	ms_message("Resending new register with updated contact %s:%i",received,rport);
}
Example #2
0
static void linphone_proxy_config_register(LinphoneProxyConfig *obj){
	osip_message_t *msg;
	eXosip_lock();
	eXosip_register_build_register(obj->rid,obj->expires,&msg);
	eXosip_register_send_register(obj->rid,msg);
	eXosip_unlock();
}
Example #3
0
void linphone_proxy_config_edit(LinphoneProxyConfig *obj){
	obj->frozen=TRUE;
	if (obj->reg_sendregister){
		/* unregister */
		if (obj->registered) {
			osip_message_t *msg;
			eXosip_lock();
			eXosip_register_build_register(obj->rid,0,&msg);
			eXosip_register_send_register(obj->rid,msg);
			eXosip_unlock();
			obj->registered=FALSE;
		}
	}
}
Example #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;
}