[asterisk-commits] oej: branch oej/codename-pineapple r47241 - in /team/oej/codename-pineapple/c...

asterisk-commits at lists.digium.com asterisk-commits at lists.digium.com
Tue Nov 7 00:02:03 MST 2006


Author: oej
Date: Tue Nov  7 01:02:03 2006
New Revision: 47241

URL: http://svn.digium.com/view/asterisk?rev=47241&view=rev
Log:
Make sip3_parse compile too.

Modified:
    team/oej/codename-pineapple/channels/Makefile
    team/oej/codename-pineapple/channels/chan_sip3.c
    team/oej/codename-pineapple/channels/sip3/Makefile
    team/oej/codename-pineapple/channels/sip3/sip3_compose.c
    team/oej/codename-pineapple/channels/sip3/sip3_parse.c
    team/oej/codename-pineapple/channels/sip3/sip3funcs.h

Modified: team/oej/codename-pineapple/channels/Makefile
URL: http://svn.digium.com/view/asterisk/team/oej/codename-pineapple/channels/Makefile?rev=47241&r1=47240&r2=47241&view=diff
==============================================================================
--- team/oej/codename-pineapple/channels/Makefile (original)
+++ team/oej/codename-pineapple/channels/Makefile Tue Nov  7 01:02:03 2006
@@ -15,7 +15,8 @@
 CC_MODS:=$(filter-out $(MENUSELECT_CHANNELS),$(patsubst %.cc,%,$(wildcard chan_*.cc)))
 SIP3_MODULES=chan_sip3.o sip3/sip3_network.o sip3/sip3_subscribe.o sip3/sip3_refer.o sip3/sip3_domain.o \
 	sip3/sip3_callerid.o sip3/sip3_auth.o sip3/sip3_sdprtp.o sip3/sip3_config.o \
-	sip3/sip3_cliami.o sip3/sip3_dialog.o sip3/sip3_services.o sip3/sip3_compose.o
+	sip3/sip3_cliami.o sip3/sip3_dialog.o sip3/sip3_services.o sip3/sip3_compose.o \
+	sip3/sip3_parse.o
 
 ifeq ($(OSARCH),OpenBSD)
   PTLIB=-lpt_OpenBSD_x86_r

Modified: team/oej/codename-pineapple/channels/chan_sip3.c
URL: http://svn.digium.com/view/asterisk/team/oej/codename-pineapple/channels/chan_sip3.c?rev=47241&r1=47240&r2=47241&view=diff
==============================================================================
--- team/oej/codename-pineapple/channels/chan_sip3.c (original)
+++ team/oej/codename-pineapple/channels/chan_sip3.c Tue Nov  7 01:02:03 2006
@@ -538,14 +538,11 @@
 static int parse_ok_contact(struct sip_dialog *pvt, struct sip_request *req);
 static int set_address_from_contact(struct sip_dialog *pvt);
 static void check_via(struct sip_dialog *p, struct sip_request *req);
-static int get_rdnis(struct sip_dialog *p, struct sip_request *oreq);
-static int get_destination(struct sip_dialog *p, struct sip_request *oreq);
 static int get_msg_text(char *buf, int len, struct sip_request *req);
 
 /*--- Constructing requests and responses */
 static int create_addr_from_peer(struct sip_dialog *r, struct sip_peer *peer);
 static int add_vidupdate(struct sip_request *req);
-static void build_rpid(struct sip_dialog *p);
 
 /*------Request handling functions */
 static int handle_request_invite(struct sip_dialog *p, struct sip_request *req, int debug, struct sockaddr_in *sin, int *recount, char *e);
@@ -2306,23 +2303,6 @@
 	return 0;
 }
 
-/*! \brief copy SIP request (mostly used to save request for responses) */
-GNURK void copy_request(struct sip_request *dst, const struct sip_request *src)
-{
-	long offset;
-	int x;
-
-	offset = ((void *)dst) - ((void *)src);
-	/* First copy stuff */
-	memcpy(dst, src, sizeof(*dst));
-	/* Now fix pointer arithmetic */
-	for (x=0; x < src->headers; x++)
-		dst->header[x] += offset;
-	for (x=0; x < src->lines; x++)
-		dst->line[x] += offset;
-}
-
-
 /*! \brief Transmit reinvite with SDP
 \note 	A re-invite is basically a new INVITE with the same CALL-ID and TAG as the
 	INVITE that opened the SIP dialogue 
@@ -2350,95 +2330,6 @@
 	initialize_initreq(p, &req);
 	p->lastinvite = p->ocseq;
 	return send_request(p, &req, XMIT_CRITICAL, p->ocseq);
-}
-
-/*! \brief Build contact header - the contact header we send out */
-GNURK void build_contact(struct sip_dialog *p)
-{
-	/* Construct Contact: header */
-	if (sipnet_ourport() != STANDARD_SIP_PORT)	/* Needs to be 5060, according to the RFC */
-		ast_string_field_build(p, our_contact, "<sip:%s%s%s:%d>", p->exten, ast_strlen_zero(p->exten) ? "" : "@", ast_inet_ntoa(p->ourip), sipnet_ourport());
-	else
-		ast_string_field_build(p, our_contact, "<sip:%s%s%s>", p->exten, ast_strlen_zero(p->exten) ? "" : "@", ast_inet_ntoa(p->ourip));
-}
-
-/*! \brief Build the Remote Party-ID & From using callingpres options */
-static void build_rpid(struct sip_dialog *p)
-{
-	int send_pres_tags = TRUE;
-	const char *privacy=NULL;
-	const char *screen=NULL;
-	char buf[256];
-	const char *clid = global.default_callerid;
-	const char *clin = NULL;
-	const char *fromdomain;
-
-	if (!ast_strlen_zero(p->rpid) || !ast_strlen_zero(p->rpid_from))  
-		return;
-
-	if (p->owner && p->owner->cid.cid_num)
-		clid = p->owner->cid.cid_num;
-	if (p->owner && p->owner->cid.cid_name)
-		clin = p->owner->cid.cid_name;
-	if (ast_strlen_zero(clin))
-		clin = clid;
-
-	switch (p->callingpres) {
-	case AST_PRES_ALLOWED_USER_NUMBER_NOT_SCREENED:
-		privacy = "off";
-		screen = "no";
-		break;
-	case AST_PRES_ALLOWED_USER_NUMBER_PASSED_SCREEN:
-		privacy = "off";
-		screen = "pass";
-		break;
-	case AST_PRES_ALLOWED_USER_NUMBER_FAILED_SCREEN:
-		privacy = "off";
-		screen = "fail";
-		break;
-	case AST_PRES_ALLOWED_NETWORK_NUMBER:
-		privacy = "off";
-		screen = "yes";
-		break;
-	case AST_PRES_PROHIB_USER_NUMBER_NOT_SCREENED:
-		privacy = "full";
-		screen = "no";
-		break;
-	case AST_PRES_PROHIB_USER_NUMBER_PASSED_SCREEN:
-		privacy = "full";
-		screen = "pass";
-		break;
-	case AST_PRES_PROHIB_USER_NUMBER_FAILED_SCREEN:
-		privacy = "full";
-		screen = "fail";
-		break;
-	case AST_PRES_PROHIB_NETWORK_NUMBER:
-		privacy = "full";
-		screen = "pass";
-		break;
-	case AST_PRES_NUMBER_NOT_AVAILABLE:
-		send_pres_tags = FALSE;
-		break;
-	default:
-		ast_log(LOG_WARNING, "Unsupported callingpres (%d)\n", p->callingpres);
-		if ((p->callingpres & AST_PRES_RESTRICTION) != AST_PRES_ALLOWED)
-			privacy = "full";
-		else
-			privacy = "off";
-		screen = "no";
-		break;
-	}
-	
-	fromdomain = S_OR(p->fromdomain, ast_inet_ntoa(p->ourip));
-
-	snprintf(buf, sizeof(buf), "\"%s\" <sip:%s@%s>", clin, clid, fromdomain);
-	if (send_pres_tags)
-		snprintf(buf + strlen(buf), sizeof(buf) - strlen(buf), ";privacy=%s;screen=%s", privacy, screen);
-	ast_string_field_set(p, rpid, buf);
-
-	ast_string_field_build(p, rpid_from, "\"%s\" <sip:%s@%s>;tag=%s", clin,
-			       S_OR(p->fromuser, clid),
-			       fromdomain, p->tag);
 }
 
 /*! \brief Build REFER/INVITE/OPTIONS message and transmit it */
@@ -3042,7 +2933,7 @@
 	/* Save URI for later ACKs, BYE or RE-invites */
 	ast_string_field_set(pvt, okcontacturi, c);
 
-	/* We should return false for URI:s we can't handle,
+	/*! \todo We should return false for URI:s we can't handle,
 		like sips:, tel:, mailto:,ldap: etc */
 	return TRUE;		
 }
@@ -3643,233 +3534,6 @@
 		ASTOBJ_UNREF(peer, sip_destroy_device);
 
 	return res;
-}
-
-/*! \brief Translate referring cause */
-static void sip_set_redirstr(struct sip_dialog *p, char *reason) {
-
-	if (strcmp(reason, "unknown")==0) {
-		ast_string_field_set(p, redircause, "UNKNOWN");
-	} else if (strcmp(reason, "user-busy")==0) {
-		ast_string_field_set(p, redircause, "BUSY");
-	} else if (strcmp(reason, "no-answer")==0) {
-		ast_string_field_set(p, redircause, "NOANSWER");
-	} else if (strcmp(reason, "unavailable")==0) {
-		ast_string_field_set(p, redircause, "UNREACHABLE");
-	} else if (strcmp(reason, "unconditional")==0) {
-		ast_string_field_set(p, redircause, "UNCONDITIONAL");
-	} else if (strcmp(reason, "time-of-day")==0) {
-		ast_string_field_set(p, redircause, "UNKNOWN");
-	} else if (strcmp(reason, "do-not-disturb")==0) {
-		ast_string_field_set(p, redircause, "UNKNOWN");
-	} else if (strcmp(reason, "deflection")==0) {
-		ast_string_field_set(p, redircause, "UNKNOWN");
-	} else if (strcmp(reason, "follow-me")==0) {
-		ast_string_field_set(p, redircause, "UNKNOWN");
-	} else if (strcmp(reason, "out-of-service")==0) {
-		ast_string_field_set(p, redircause, "UNREACHABLE");
-	} else if (strcmp(reason, "away")==0) {
-		ast_string_field_set(p, redircause, "UNREACHABLE");
-	} else {
-		ast_string_field_set(p, redircause, "UNKNOWN");
-	}
-}
-
-/*! \brief Get referring dnis */
-static int get_rdnis(struct sip_dialog *p, struct sip_request *oreq)
-{
-	char tmp[256], *exten, *rexten, *rdomain;
-	char *params, *reason = NULL;
-	struct sip_request *req;
-	
-	req = oreq ? oreq : &p->initreq;
-
-	ast_copy_string(tmp, get_header(req, "Diversion"), sizeof(tmp));
-	if (ast_strlen_zero(tmp))
-		return 0;
-
-	exten = get_in_brackets(tmp);
-	if (strncmp(exten, "sip:", 4)) {
-		ast_log(LOG_WARNING, "Huh?  Not an RDNIS SIP header (%s)?\n", exten);
-		return -1;
-	}
-	exten += 4;
-
-	/* Get diversion-reason param if present */
-	if ((params = strchr(tmp, ';'))) {
-		*params = '\0';	/* Cut off parameters  */
-		params++;
-		while (*params == ';' || *params == ' ')
-			params++;
-		/* Check if we have a reason parameter */
-		if ((reason = strcasestr(params, "reason="))) {
-			reason+=7;
-			/* Remove enclosing double-quotes */
-			if (*reason == '"') 
-				ast_strip_quoted(reason, "\"", "\"");
-			if (!ast_strlen_zero(reason)) {
-				sip_set_redirstr(p, reason);
-				if (p->owner) {
-					pbx_builtin_setvar_helper(p->owner, "__PRIREDIRECTREASON", p->redircause);
-					pbx_builtin_setvar_helper(p->owner, "__SIPREDIRECTREASON", reason);
-				}
-			}
-		}
-	}
-
-	rdomain = exten;
-	rexten = strsep(&rdomain, "@");	/* trim anything after @ */
-	if (p->owner) 
-		pbx_builtin_setvar_helper(p->owner, "__SIPRDNISDOMAIN", rdomain);
-
-	if (sip_debug_test_pvt(p))
-		ast_verbose("RDNIS for this call is is %s (reason %s)\n", exten, reason ? reason : "");
-
-	ast_string_field_set(p, rdnis, rexten);
-
-	return 0;
-}
-
-/*! \brief Find out who the call is for 
-	We use the INVITE uri to find out
-*/
-static int get_destination(struct sip_dialog *p, struct sip_request *oreq)
-{
-	char tmp[256] = "", *uri, *a;
-	char tmpf[256] = "", *from;
-	struct sip_request *req;
-	char *colon;
-	int localdomain = TRUE;
-	
-	req = oreq;
-	if (!req)
-		req = &p->initreq;
-
-	/* Find the request URI */
-	if (req->rlPart2)
-		ast_copy_string(tmp, req->rlPart2, sizeof(tmp));
-	
-	ast_uri_decode(tmp);
-
-	uri = get_in_brackets(tmp);
-
-	if (strncmp(uri, "sip:", 4)) {
-		ast_log(LOG_WARNING, "Huh?  Not a SIP header (%s)?\n", uri);
-		return -1;
-	}
-	uri += 4;
-
-	/* Now find the From: caller ID and name */
-	ast_copy_string(tmpf, get_header(req, "From"), sizeof(tmpf));
-	if (!ast_strlen_zero(tmpf)) {
-		ast_uri_decode(tmpf);
-		from = get_in_brackets(tmpf);
-	} else {
-		from = NULL;
-	}
-	
-	if (!ast_strlen_zero(from)) {
-		if (strncmp(from, "sip:", 4)) {
-			ast_log(LOG_WARNING, "Huh?  Not a SIP header (%s)?\n", from);
-			return -1;
-		}
-		from += 4;
-		if ((a = strchr(from, '@')))
-			*a++ = '\0';
-		else
-			a = from;	/* just a domain */
-		from = strsep(&from, ";");	/* Remove userinfo options */
-		a = strsep(&a, ";");		/* Remove URI options */
-		ast_string_field_set(p, fromdomain, a);
-	}
-
-	/* Skip any options and find the domain */
-
-	/* Get the target domain */
-	if ((a = strchr(uri, '@'))) {
-		*a++ = '\0';
-	} else {	/* No username part */
-		a = uri;
-		uri = "s";	/* Set extension to "s" */
-	}
-	colon = strchr(a, ':'); /* Remove :port */
-	if (colon)
-		*colon = '\0';
-
-	uri = strsep(&uri, ";");	/* Remove userinfo options */
-	a = strsep(&a, ";");		/* Remove URI options */
-
-	ast_string_field_set(p, domain, a);
-
-	if (domains_configured()) {
-		char domain_context[AST_MAX_EXTENSION];
-
-		domain_context[0] = '\0';
-		if (!check_sip_domain(p->domain, domain_context, sizeof(domain_context))) {
-			localdomain = FALSE;
-			if (!global.allow_external_domains && (req->method == SIP_INVITE || req->method == SIP_REFER)) {
-				if (option_debug)
-					ast_log(LOG_DEBUG, "Got SIP %s to non-local domain '%s'; refusing request.\n", sip_method2txt(req->method), p->domain);
-				return -2;
-			}
-		}
-		/* If we have a domain context defined, overwrite the original context */
-		if (!ast_strlen_zero(domain_context))
-			ast_string_field_set(p, context, domain_context);
-	}
-
-	/* If the URI starts with our magic marker and has a corresponding
-		entry in the registry, then replace the URI with the extension
-		we want to use */
-	/* We don't have to check this at all if we have no registry entries... */
-	if (localdomain && req->method == SIP_INVITE) {
-		if (option_debug)
-			ast_log(LOG_DEBUG, "Checking %s for magic registry marker \n", uri);
-		/* Check if the incoming URI is a registry entry */
-		/* Need a function in ASTOBJ to check if there are objects
-			in the container at all here to avoid this check 
-			when we have no registry entries */
-		if (!strncmp(uri, REG_MAGICMARKER, strlen(REG_MAGICMARKER))) {
-			int found = FALSE;
-
-			if (option_debug)
-				ast_log(LOG_DEBUG, "Checking for %s in registry\n", uri);
-			/* Traverse the registry to find something */
-			ASTOBJ_CONTAINER_TRAVERSE(&regl, !found, do {
-				ASTOBJ_RDLOCK(iterator);
-				if (!strcmp(uri, iterator->contact)) {
-					found = TRUE;
-					/* Use the extension of this registry item for the incoming call */
-					uri = (char *) iterator->extension;
-					p->registry = iterator;
-				}
-				ASTOBJ_UNLOCK(iterator);
-			} while(0));
-		}
-	}
-
-
-	if (sip_debug_test_pvt(p))
-		ast_verbose("Looking for %s in %s (domain %s)\n", uri, p->context, p->domain);
-
-	/* Check the dialplan for the username part of the request URI,
-	   the domain will be stored in the SIPDOMAIN variable
-		Return 0 if we have a matching extension */
-	if (ast_exists_extension(NULL, p->context, uri, 1, from) ||
-		!strcmp(uri, ast_pickup_ext())) {
-		if (!oreq)
-			ast_string_field_set(p, exten, uri);
-		return 0;
-	}
-
-	/* Return 1 for pickup extension or overlap dialling support (if we support it) */
-	if((ast_test_flag(&global.flags[1], SIP_PAGE2_ALLOWOVERLAP) && 
- 	    ast_canmatch_extension(NULL, p->context, uri, 1, from)) ||
-	    !strncmp(uri, ast_pickup_ext(), strlen(uri))) {
-		return 1;
-	}
-	
-	return -1;
 }
 
 /*! \brief Lock dialog list lock and find matching pvt lock  

Modified: team/oej/codename-pineapple/channels/sip3/Makefile
URL: http://svn.digium.com/view/asterisk/team/oej/codename-pineapple/channels/sip3/Makefile?rev=47241&r1=47240&r2=47241&view=diff
==============================================================================
--- team/oej/codename-pineapple/channels/sip3/Makefile (original)
+++ team/oej/codename-pineapple/channels/sip3/Makefile Tue Nov  7 01:02:03 2006
@@ -3,7 +3,7 @@
 #
 all: sip3_refer.o sip3_subscribe.o sip3_network.o sip3_domain.o sip3_callerid.o sip3_auth.o \
 	sip3_sdprtp.o sip3_config.o sip3_cliami.o sip3_dialog.o sip3_services.o \
-	sip3_compose.o
+	sip3_compose.o sip3_parse.o
 
 %.o: %.c sip3funcs.h sip3.h
 	$(CC) $(CFLAGS) -c -o $@ $<

Modified: team/oej/codename-pineapple/channels/sip3/sip3_compose.c
URL: http://svn.digium.com/view/asterisk/team/oej/codename-pineapple/channels/sip3/sip3_compose.c?rev=47241&r1=47240&r2=47241&view=diff
==============================================================================
--- team/oej/codename-pineapple/channels/sip3/sip3_compose.c (original)
+++ team/oej/codename-pineapple/channels/sip3/sip3_compose.c Tue Nov  7 01:02:03 2006
@@ -132,8 +132,19 @@
 	return 0;
 }
 
+/*! \brief Build contact header - the contact header we send out */
+void build_contact(struct sip_dialog *p)
+{
+	/* Construct Contact: header */
+	if (sipnet_ourport() != STANDARD_SIP_PORT)	/* Needs to be 5060, according to the RFC */
+		ast_string_field_build(p, our_contact, "<sip:%s%s%s:%d>", p->exten, ast_strlen_zero(p->exten) ? "" : "@", ast_inet_ntoa(p->ourip), sipnet_ourport());
+	else
+		ast_string_field_build(p, our_contact, "<sip:%s%s%s>", p->exten, ast_strlen_zero(p->exten) ? "" : "@", ast_inet_ntoa(p->ourip));
+}
+
+
 /*! \brief Build the Remote Party-ID & From using callingpres options */
-static void build_rpid(struct sip_dialog *p)
+void build_rpid(struct sip_dialog *p)
 {
 	int send_pres_tags = TRUE;
 	const char *privacy=NULL;

Modified: team/oej/codename-pineapple/channels/sip3/sip3_parse.c
URL: http://svn.digium.com/view/asterisk/team/oej/codename-pineapple/channels/sip3/sip3_parse.c?rev=47241&r1=47240&r2=47241&view=diff
==============================================================================
--- team/oej/codename-pineapple/channels/sip3/sip3_parse.c (original)
+++ team/oej/codename-pineapple/channels/sip3/sip3_parse.c Tue Nov  7 01:02:03 2006
@@ -68,26 +68,27 @@
 #include "asterisk/manager.h"
 #include "asterisk/callerid.h"
 #include "asterisk/cli.h"
-#include "asterisk/app.h"
+//#include "asterisk/app.h"
 #include "asterisk/musiconhold.h"
-#include "asterisk/dsp.h"
+//#include "asterisk/dsp.h"
 #include "asterisk/features.h"
-#include "asterisk/acl.h"
-#include "asterisk/srv.h"
-#include "asterisk/astdb.h"
+//#include "asterisk/srv.h"
+//#include "asterisk/astdb.h"
 #include "asterisk/causes.h"
 #include "asterisk/utils.h"
 #include "asterisk/file.h"
 #include "asterisk/astobj.h"
-#include "asterisk/dnsmgr.h"
-#include "asterisk/devicestate.h"
+//#include "asterisk/dnsmgr.h"
+//#include "asterisk/devicestate.h"
 #include "asterisk/linkedlists.h"
 #include "asterisk/stringfields.h"
 #include "asterisk/monitor.h"
-#include "asterisk/localtime.h"
-#include "asterisk/abstract_jb.h"
+//#include "asterisk/localtime.h"
+//#include "asterisk/abstract_jb.h"
 #include "asterisk/compiler.h"
+
 #include "sip3.h"
+#include "sip3funcs.h"
 
 /*! XXX Note that sip_methods[i].id == i must hold or the code breaks */
 const struct cfsip_methods sip_methods[] = {
@@ -156,7 +157,7 @@
  * a case-insensitive comparison to be more tolerant.
  * following Jon Postel's rule: Be gentle in what you accept, strict with what you send
  */
-static int method_match(enum sipmethod id, const char *name)
+int method_match(enum sipmethod id, const char *name)
 {
 	int len = strlen(sip_methods[id].text);
 	int l_name = name ? strlen(name) : 0;
@@ -166,7 +167,7 @@
 }
 
 /*! \brief  find_sip_method: Find SIP method from header */
-static int find_sip_method(const char *msg)
+int find_sip_method(const char *msg)
 {
 	int i, res = 0;
 	
@@ -180,13 +181,13 @@
 }
 
 /*! \brief return text string for sip method */
-static char *sip_method2txt(int method)
+char *sip_method2txt(int method)
 {
 	return sip_methods[method].text;
 }
 
 /*! \brief Check whether method needs RTP */
-static int sip_method_needrtp(int method)
+int sip_method_needrtp(int method)
 {
 	return sip_methods[method].need_rtp;
 }
@@ -213,28 +214,45 @@
 }
 
 /*! \brief Check if sip option is known to us, avoid x- options (non-standard) */ 
-static int sip_option_lookup(const char *optionlabel)
+int sip_option_lookup(const char *optionlabel)
 {
 	int i;
+
 	for (i=0; i < (sizeof(sip_options) / sizeof(sip_options[0])); i++) {
-		if (!strcasecmp(next, sip_options[i].text)) {
-			profile |= sip_options[i].id;
+		if (!strcasecmp(optionlabel, sip_options[i].text)) {
 			if (option_debug > 2 && sipdebug)
-				ast_log(LOG_DEBUG, "Matched SIP option: %s\n", next);
+				ast_log(LOG_DEBUG, "Matched SIP option: %s\n", optionlabel);
 			return i;
 		}
 	}
 	if (option_debug > 2) {
-		if (!strncasecmp(next, "x-", 2))
-			ast_log(LOG_DEBUG, "Found private SIP option, not supported: %s\n", next);
+		if (!strncasecmp(optionlabel, "x-", 2))
+			ast_log(LOG_DEBUG, "Found private SIP option, not supported: %s\n", optionlabel);
 		else
-			ast_log(LOG_DEBUG, "Found no match for SIP option: %s (Please file bug report!)\n", next);
+			ast_log(LOG_DEBUG, "Found no match for SIP option: %s (Please file bug report!)\n", optionlabel);
 	}
 	return -1;
 }
 
+/*! \brief copy SIP request (mostly used to save request for responses) */
+void copy_request(struct sip_request *dst, const struct sip_request *src)
+{
+	long offset;
+	int x;
+
+	offset = ((void *)dst) - ((void *)src);
+	/* First copy stuff */
+	memcpy(dst, src, sizeof(*dst));
+	/* Now fix pointer arithmetic */
+	for (x=0; x < src->headers; x++)
+		dst->header[x] += offset;
+	for (x=0; x < src->lines; x++)
+		dst->line[x] += offset;
+}
+
+
 /*! \brief Parse supported header in incoming packet */
-static unsigned int parse_sip_options(struct sip_dialog *pvt, const char *supported)
+unsigned int parse_sip_options(struct sip_dialog *pvt, const char *supported)
 {
 	char *next, *sep;
 	char *temp;
@@ -255,7 +273,7 @@
 		next = ast_skip_blanks(next);
 		if (option_debug > 2 && sipdebug)
 			ast_log(LOG_DEBUG, "Got SIP option: -%s-\n", next);
-		i = sip_options_lookup(next);
+		i = sip_option_lookup(next);
 		if (i > 0)
 			profile |= sip_options[i].id;
 	}
@@ -266,13 +284,13 @@
 }
 
 /*! \brief Return text representation of SIP option */
-static char *sip_option2text(int option)
-{
-	return sip_options[option].text);
+char *sip_option2text(int option)
+{
+	return sip_options[option].text;
 }
 
 /*! \brief Print options to cli */
-static void sip_options_print(int options, int fd)
+void sip_options_print(int options, int fd)
 {
 	int x;
 	int lastoption = -1;
@@ -323,7 +341,237 @@
 	return _default;
 }
 
-static const char *__get_header(const struct sip_request *req, const char *name, int *start)
+/*! \brief Translate referring cause 
+*/
+static void sip_set_redirstr(struct sip_dialog *p, char *reason) {
+
+	if (strcmp(reason, "unknown")==0) {
+		ast_string_field_set(p, redircause, "UNKNOWN");
+	} else if (strcmp(reason, "user-busy")==0) {
+		ast_string_field_set(p, redircause, "BUSY");
+	} else if (strcmp(reason, "no-answer")==0) {
+		ast_string_field_set(p, redircause, "NOANSWER");
+	} else if (strcmp(reason, "unavailable")==0) {
+		ast_string_field_set(p, redircause, "UNREACHABLE");
+	} else if (strcmp(reason, "unconditional")==0) {
+		ast_string_field_set(p, redircause, "UNCONDITIONAL");
+	} else if (strcmp(reason, "time-of-day")==0) {
+		ast_string_field_set(p, redircause, "UNKNOWN");
+	} else if (strcmp(reason, "do-not-disturb")==0) {
+		ast_string_field_set(p, redircause, "UNKNOWN");
+	} else if (strcmp(reason, "deflection")==0) {
+		ast_string_field_set(p, redircause, "UNKNOWN");
+	} else if (strcmp(reason, "follow-me")==0) {
+		ast_string_field_set(p, redircause, "UNKNOWN");
+	} else if (strcmp(reason, "out-of-service")==0) {
+		ast_string_field_set(p, redircause, "UNREACHABLE");
+	} else if (strcmp(reason, "away")==0) {
+		ast_string_field_set(p, redircause, "UNREACHABLE");
+	} else {
+		ast_string_field_set(p, redircause, "UNKNOWN");
+	}
+}
+
+
+/*! \brief Get referring dnis */
+int get_rdnis(struct sip_dialog *p, struct sip_request *oreq)
+{
+	char tmp[256], *exten, *rexten, *rdomain;
+	char *params, *reason = NULL;
+	struct sip_request *req;
+	
+	req = oreq ? oreq : &p->initreq;
+
+	ast_copy_string(tmp, get_header(req, "Diversion"), sizeof(tmp));
+	if (ast_strlen_zero(tmp))
+		return 0;
+
+	exten = get_in_brackets(tmp);
+	if (strncmp(exten, "sip:", 4)) {
+		ast_log(LOG_WARNING, "Huh?  Not an RDNIS SIP header (%s)?\n", exten);
+		return -1;
+	}
+	exten += 4;
+
+	/* Get diversion-reason param if present */
+	if ((params = strchr(tmp, ';'))) {
+		*params = '\0';	/* Cut off parameters  */
+		params++;
+		while (*params == ';' || *params == ' ')
+			params++;
+		/* Check if we have a reason parameter */
+		if ((reason = strcasestr(params, "reason="))) {
+			reason+=7;
+			/* Remove enclosing double-quotes */
+			if (*reason == '"') 
+				ast_strip_quoted(reason, "\"", "\"");
+			if (!ast_strlen_zero(reason)) {
+				sip_set_redirstr(p, reason);
+				if (p->owner) {
+					pbx_builtin_setvar_helper(p->owner, "__PRIREDIRECTREASON", p->redircause);
+					pbx_builtin_setvar_helper(p->owner, "__SIPREDIRECTREASON", reason);
+				}
+			}
+		}
+	}
+
+	rdomain = exten;
+	rexten = strsep(&rdomain, "@");	/* trim anything after @ */
+	if (p->owner) 
+		pbx_builtin_setvar_helper(p->owner, "__SIPRDNISDOMAIN", rdomain);
+
+	if (sip_debug_test_pvt(p))
+		ast_verbose("RDNIS for this call is is %s (reason %s)\n", exten, reason ? reason : "");
+
+	ast_string_field_set(p, rdnis, rexten);
+
+	return 0;
+}
+
+/*! \brief Find out who the call is for 
+	We use the INVITE request uri to find out
+	Runs a dialplan lookup
+*/
+int get_destination(struct sip_dialog *p, struct sip_request *oreq)
+{
+	char tmp[256] = "", *uri, *a;
+	char tmpf[256] = "", *from;
+	struct sip_request *req;
+	char *colon;
+	int localdomain = TRUE;
+	
+	req = oreq;
+	if (!req)
+		req = &p->initreq;
+
+	/* Find the request URI */
+	if (req->rlPart2)
+		ast_copy_string(tmp, req->rlPart2, sizeof(tmp));
+	
+	ast_uri_decode(tmp);
+
+	uri = get_in_brackets(tmp);
+
+	if (strncmp(uri, "sip:", 4)) {
+		ast_log(LOG_WARNING, "Huh?  Not a SIP header (%s)?\n", uri);
+		return -1;
+	}
+	uri += 4;
+
+	/* Now find the From: caller ID and name */
+	ast_copy_string(tmpf, get_header(req, "From"), sizeof(tmpf));
+	if (!ast_strlen_zero(tmpf)) {
+		ast_uri_decode(tmpf);
+		from = get_in_brackets(tmpf);
+	} else {
+		from = NULL;
+	}
+	
+	if (!ast_strlen_zero(from)) {
+		if (strncmp(from, "sip:", 4)) {
+			ast_log(LOG_WARNING, "Huh?  Not a SIP header (%s)?\n", from);
+			return -1;
+		}
+		from += 4;
+		if ((a = strchr(from, '@')))
+			*a++ = '\0';
+		else
+			a = from;	/* just a domain */
+		from = strsep(&from, ";");	/* Remove userinfo options */
+		a = strsep(&a, ";");		/* Remove URI options */
+		ast_string_field_set(p, fromdomain, a);
+	}
+
+	/* Skip any options and find the domain */
+
+	/* Get the target domain */
+	if ((a = strchr(uri, '@'))) {
+		*a++ = '\0';
+	} else {	/* No username part */
+		a = uri;
+		uri = "s";	/* Set extension to "s" */
+	}
+	colon = strchr(a, ':'); /* Remove :port */
+	if (colon)
+		*colon = '\0';
+
+	uri = strsep(&uri, ";");	/* Remove userinfo options */
+	a = strsep(&a, ";");		/* Remove URI options */
+
+	ast_string_field_set(p, domain, a);
+
+	if (domains_configured()) {
+		char domain_context[AST_MAX_EXTENSION];
+
+		domain_context[0] = '\0';
+		if (!check_sip_domain(p->domain, domain_context, sizeof(domain_context))) {
+			localdomain = FALSE;
+			if (!global.allow_external_domains && (req->method == SIP_INVITE || req->method == SIP_REFER)) {
+				if (option_debug)
+					ast_log(LOG_DEBUG, "Got SIP %s to non-local domain '%s'; refusing request.\n", sip_method2txt(req->method), p->domain);
+				return -2;
+			}
+		}
+		/* If we have a domain context defined, overwrite the original context */
+		if (!ast_strlen_zero(domain_context))
+			ast_string_field_set(p, context, domain_context);
+	}
+
+	/* If the URI starts with our magic marker and has a corresponding
+		entry in the registry, then replace the URI with the extension
+		we want to use */
+	/* We don't have to check this at all if we have no registry entries... */
+	if (localdomain && req->method == SIP_INVITE) {
+		if (option_debug)
+			ast_log(LOG_DEBUG, "Checking %s for magic registry marker \n", uri);
+		/* Check if the incoming URI is a registry entry */
+		/* Need a function in ASTOBJ to check if there are objects
+			in the container at all here to avoid this check 
+			when we have no registry entries */
+		if (!strncmp(uri, REG_MAGICMARKER, strlen(REG_MAGICMARKER))) {
+			int found = FALSE;
+
+			if (option_debug)
+				ast_log(LOG_DEBUG, "Checking for %s in registry\n", uri);
+			/* Traverse the registry to find something */
+			ASTOBJ_CONTAINER_TRAVERSE(&regl, !found, do {
+				ASTOBJ_RDLOCK(iterator);
+				if (!strcmp(uri, iterator->contact)) {
+					found = TRUE;
+					/* Use the extension of this registry item for the incoming call */
+					uri = (char *) iterator->extension;
+					p->registry = iterator;
+				}
+				ASTOBJ_UNLOCK(iterator);
+			} while(0));
+		}
+	}
+
+
+	if (sip_debug_test_pvt(p))
+		ast_verbose("Looking for %s in %s (domain %s)\n", uri, p->context, p->domain);
+
+	/* Check the dialplan for the username part of the request URI,
+	   the domain will be stored in the SIPDOMAIN variable
+		Return 0 if we have a matching extension */
+	if (ast_exists_extension(NULL, p->context, uri, 1, from) ||
+		!strcmp(uri, ast_pickup_ext())) {
+		if (!oreq)
+			ast_string_field_set(p, exten, uri);
+		return 0;
+	}
+
+	/* Return 1 for pickup extension or overlap dialling support (if we support it) */
+	if((ast_test_flag(&global.flags[1], SIP_PAGE2_ALLOWOVERLAP) && 
+ 	    ast_canmatch_extension(NULL, p->context, uri, 1, from)) ||
+	    !strncmp(uri, ast_pickup_ext(), strlen(uri))) {
+		return 1;
+	}
+	
+	return -1;
+}
+
+const char *__get_header(const struct sip_request *req, const char *name, int *start)
 {
 	int pass;
 
@@ -422,8 +670,8 @@
 			if (rport && *(rport+6) == '=') 
 				rport = NULL;		/* We already have a parameter to rport */
 
-			if (rport && ((ast_test_flag(&p->flags[0], SIP_NAT) == SIP_NAT_ALWAYS) ||
-				(ast_test_flag(&p->flags[0], SIP_NAT) == SIP_NAT_RFC3581) ) }
+			if (rport && ( (ast_test_flag(&p->flags[0], SIP_NAT) == SIP_NAT_ALWAYS) ||
+				(ast_test_flag(&p->flags[0], SIP_NAT) == SIP_NAT_RFC3581) ) ) {
 				/* We need to add received port - rport */
 				char tmp[256], *end;
 

Modified: team/oej/codename-pineapple/channels/sip3/sip3funcs.h
URL: http://svn.digium.com/view/asterisk/team/oej/codename-pineapple/channels/sip3/sip3funcs.h?rev=47241&r1=47240&r2=47241&view=diff
==============================================================================
--- team/oej/codename-pineapple/channels/sip3/sip3funcs.h (original)
+++ team/oej/codename-pineapple/channels/sip3/sip3funcs.h Tue Nov  7 01:02:03 2006
@@ -72,13 +72,11 @@
 GNURK void build_via(struct sip_dialog *p, int forcenewbranch);
 GNURK void __sip_pretend_ack(struct sip_dialog *p);
 GNURK int create_addr(struct sip_dialog *dialog, const char *opeer);
-GNURK void build_contact(struct sip_dialog *p);
 GNURK int init_req(struct sip_request *req, int sipmethod, const char *recip);
 GNURK void initialize_initreq(struct sip_dialog *p, struct sip_request *req);
 GNURK int __transmit_response(struct sip_dialog *p, const char *msg, const struct sip_request *req, enum xmittype reliable);
 GNURK int transmit_notify_with_sipfrag(struct sip_dialog *p, int cseq, char *message, int terminate);
 GNURK int init_resp(struct sip_request *resp, const char *msg);
-GNURK void copy_request(struct sip_request *dst, const struct sip_request *src);
 GNURK struct sip_dialog *get_sip_dialog_byid_locked(const char *callid, const char *totag, const char *fromtag);
 GNURK void ast_quiet_chan(struct ast_channel *chan);
 GNURK void sip_dump_history(struct sip_dialog *dialog);	/* Dump history to LOG_DEBUG at end of dialog, before destroying data */
@@ -122,6 +120,7 @@
 GNURK void sip_options_print(int options, int fd);
 GNURK const char *find_alias(const char *name, const char *_default);
 GNURK const char *get_header(const struct sip_request *req, const char *name);
+GNURK void copy_request(struct sip_request *dst, const struct sip_request *src);
 GNURK int copy_header(struct sip_request *req, const struct sip_request *orig, const char *field);
 GNURK int copy_all_header(struct sip_request *req, const struct sip_request *orig, const char *field);
 GNURK int copy_via_headers(struct sip_dialog *p, struct sip_request *req, const struct sip_request *orig, const char *field);
@@ -132,6 +131,8 @@
 GNURK int determine_firstline_parts(struct sip_request *req);
 GNURK void extract_uri(struct sip_dialog *p, struct sip_request *req);
 GNURK void parse_moved_contact(struct sip_dialog *p, struct sip_request *req);
+GNURK int get_rdnis(struct sip_dialog *p, struct sip_request *oreq);
+GNURK int get_destination(struct sip_dialog *p, struct sip_request *oreq);
 
 /*! sip3_compose.c : Composing new SIP messages */
 GNURK void build_callid_pvt(struct sip_dialog *pvt);
@@ -144,6 +145,8 @@
 GNURK int add_header_contentLength(struct sip_request *req, int len);
 GNURK void initreqprep(struct sip_request *req, struct sip_dialog *p, int sipmethod);
 GNURK int reqprep(struct sip_request *req, struct sip_dialog *p, int sipmethod, int seqno, int newbranch);
+GNURK void build_contact(struct sip_dialog *p);
+GNURK void build_rpid(struct sip_dialog *p);
 
 /*! sip3_domain.c: Domain handling functions (sip domain hosting, not DNS lookups) */
 GNURK int add_sip_domain(const char *domain, const enum domain_mode mode, const char *context);



More information about the asterisk-commits mailing list