mirror of
				https://github.com/RangeNetworks/openbts.git
				synced 2025-11-04 13:53:15 +00:00 
			
		
		
		
	git-svn-id: http://wush.net/svn/range/software/public/openbts/trunk@6168 19bc5d8c-e614-43d4-8b26-e1612bc8e597
		
			
				
	
	
		
			120 lines
		
	
	
		
			2.6 KiB
		
	
	
	
		
			C++
		
	
	
	
	
	
			
		
		
	
	
			120 lines
		
	
	
		
			2.6 KiB
		
	
	
	
		
			C++
		
	
	
	
	
	
/*
 | 
						|
* Copyright 2008 Free Software Foundation, Inc.
 | 
						|
*
 | 
						|
* This software is distributed under multiple licenses; see the COPYING file in the main directory for licensing information for this specific distribuion.
 | 
						|
*
 | 
						|
* This use of this software may be subject to additional restrictions.
 | 
						|
* See the LEGAL file in the main directory for details.
 | 
						|
 | 
						|
    This program is distributed in the hope that it will be useful,
 | 
						|
    but WITHOUT ANY WARRANTY; without even the implied warranty of
 | 
						|
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 | 
						|
 | 
						|
*/
 | 
						|
 | 
						|
 | 
						|
#include <stdio.h>
 | 
						|
#include <stdlib.h>
 | 
						|
#include <signal.h>
 | 
						|
 | 
						|
#include <signal.h>
 | 
						|
#include <stdlib.h>
 | 
						|
 | 
						|
#include <ortp/ortp.h>
 | 
						|
#include <osipparser2/osip_md5.h>
 | 
						|
#include <osipparser2/sdp_message.h>
 | 
						|
 | 
						|
#include "SIPInterface.h"
 | 
						|
#include "SIPUtility.h"
 | 
						|
 | 
						|
 | 
						|
using namespace SIP;
 | 
						|
using namespace std;
 | 
						|
 | 
						|
 | 
						|
 | 
						|
#define DEBUG 1
 | 
						|
 | 
						|
 | 
						|
 | 
						|
 | 
						|
 | 
						|
bool SIP::get_owner_ip( osip_message_t * msg, char * o_addr )
 | 
						|
{
 | 
						|
	osip_body_t * sdp_body = (osip_body_t*)osip_list_get(&msg->bodies, 0);
 | 
						|
	if (!sdp_body) return false;
 | 
						|
	char * sdp_str = sdp_body->body;
 | 
						|
	if (!sdp_str) return false;
 | 
						|
 | 
						|
	sdp_message_t * sdp;
 | 
						|
	sdp_message_init(&sdp);
 | 
						|
	sdp_message_parse(sdp, sdp_str);
 | 
						|
	strcpy(o_addr, sdp->o_addr);
 | 
						|
	return true;
 | 
						|
}
 | 
						|
 | 
						|
bool SIP::get_rtp_params(const osip_message_t * msg, char * port, char * ip_addr )
 | 
						|
{
 | 
						|
	osip_body_t * sdp_body = (osip_body_t*)osip_list_get(&msg->bodies, 0);
 | 
						|
	if (!sdp_body) return false;
 | 
						|
	char * sdp_str = sdp_body->body;
 | 
						|
	if (!sdp_str) return false;
 | 
						|
 | 
						|
	sdp_message_t * sdp;
 | 
						|
	sdp_message_init(&sdp);
 | 
						|
	sdp_message_parse(sdp, sdp_str);
 | 
						|
 | 
						|
	strcpy(port,sdp_message_m_port_get(sdp,0));
 | 
						|
	strcpy(ip_addr, sdp->c_connection->c_addr);
 | 
						|
	return true;
 | 
						|
}
 | 
						|
 | 
						|
void SIP::make_tag(char * tag)
 | 
						|
{
 | 
						|
	uint64_t r1 = random();
 | 
						|
	uint64_t r2 = random();
 | 
						|
	uint64_t val = (r1<<32) + r2;
 | 
						|
	
 | 
						|
	// map [0->26] to [a-z] 
 | 
						|
	int k;
 | 
						|
	for (k=0; k<16; k++) {
 | 
						|
		tag[k] = val%26+'a';
 | 
						|
		val = val >> 4;
 | 
						|
	}
 | 
						|
	tag[k] = '\0';
 | 
						|
}
 | 
						|
 | 
						|
void SIP::make_branch( char * branch )
 | 
						|
{
 | 
						|
	uint64_t r1 = random();
 | 
						|
	uint64_t r2 = random();
 | 
						|
	uint64_t val = (r1<<32) + r2;
 | 
						|
	sprintf(branch,"z9hG4bKobts28%llx", val);
 | 
						|
}
 | 
						|
 | 
						|
/* get the return address from the SIP VIA header
 | 
						|
   if port not available, guess at 5060
 | 
						|
   if header not available, guess from SIP.Proxy.SMS 
 | 
						|
   -kurtis 
 | 
						|
*/
 | 
						|
string SIP::get_return_address(osip_message_t * msg){
 | 
						|
 | 
						|
	string result;
 | 
						|
	osip_via* via = (osip_via *) osip_list_get(&msg->vias,0);
 | 
						|
	if (via){
 | 
						|
		result = string(via->host);
 | 
						|
		if (via->port) {
 | 
						|
			result += string(":") + string(via->port);
 | 
						|
		}
 | 
						|
		else {
 | 
						|
			result += string(":") + string("5060"); //assume SIP
 | 
						|
		}
 | 
						|
	}
 | 
						|
	else { //no via header? Take best guess from conf -k
 | 
						|
		result = gConfig.getStr("SIP.Proxy.SMS");
 | 
						|
	}
 | 
						|
	return result;
 | 
						|
}
 | 
						|
 | 
						|
// vim: ts=4 sw=4
 |