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

asterisk-commits at lists.digium.com asterisk-commits at lists.digium.com
Sat Oct 28 11:21:16 MST 2006


Author: oej
Date: Sat Oct 28 13:21:16 2006
New Revision: 46381

URL: http://svn.digium.com/view/asterisk?rev=46381&view=rev
Log:
More movements can be seen here.

Modified:
    team/oej/codename-pineapple/channels/chan_sip3.c
    team/oej/codename-pineapple/channels/sip3/sip3_dialog.c
    team/oej/codename-pineapple/channels/sip3/sip3_network.c
    team/oej/codename-pineapple/channels/sip3/sip3_parse.c
    team/oej/codename-pineapple/channels/sip3/sip3_services.c
    team/oej/codename-pineapple/channels/sip3/sip3funcs.h

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=46381&r1=46380&r2=46381&view=diff
==============================================================================
--- team/oej/codename-pineapple/channels/chan_sip3.c (original)
+++ team/oej/codename-pineapple/channels/chan_sip3.c Sat Oct 28 13:21:16 2006
@@ -301,7 +301,6 @@
 #include "asterisk/localtime.h"
 #include "asterisk/abstract_jb.h"
 #include "asterisk/compiler.h"
-#include "asterisk/threadstorage.h"
 
 #include "sip3/sip3.h"
 #include "sip3/sip3funcs.h"
@@ -351,13 +350,6 @@
 
 /*! \brief The peer list: Peers and Friends */
 struct sip_device_list devicelist;
-
-/* Forward declaration */
-static int temp_pvt_init(void *data);
-static void temp_pvt_cleanup(void *data);
-
-/*! \brief A per-thread temporary pvt structure */
-AST_THREADSTORAGE_CUSTOM(ts_temp_pvt, temp_pvt_init, temp_pvt_cleanup);
 
 /*! \todo Move the sip_auth list to AST_LIST */
 struct sip_auth *authl = NULL;		/*!< Authentication list for realm authentication */
@@ -383,9 +375,7 @@
 static int sip_senddigit_end(struct ast_channel *ast, char digit);
 
 /*--- Transmitting responses and requests */
-static int __transmit_response(struct sip_dialog *p, const char *msg, const struct sip_request *req, enum xmittype reliable);
 static int transmit_sip_request(struct sip_dialog *p, struct sip_request *req);
-static int transmit_response_using_temp(ast_string_field callid, struct sockaddr_in *sin, int useglobal_nat, const int intended_method, const struct sip_request *req, const char *msg);
 static int transmit_response_reliable(struct sip_dialog *p, const char *msg, const struct sip_request *req);
 static int transmit_response_with_date(struct sip_dialog *p, const char *msg, const struct sip_request *req);
 static int transmit_response_with_sdp(struct sip_dialog *p, const char *msg, const struct sip_request *req, enum xmittype reliable);
@@ -496,7 +486,6 @@
 /*--- Parsing SIP requests and responses */
 static void append_date(struct sip_request *req);	/* Append date to SIP packet */
 static int determine_firstline_parts(struct sip_request *req);
-static const char *gettag(const struct sip_request *req, const char *header, char *tagbuf, int tagbufsize);
 static void extract_uri(struct sip_dialog *p, struct sip_request *req);
 static int get_refer_info(struct sip_dialog *transferer, struct sip_request *outgoing_req);
 static int get_also_info(struct sip_dialog *p, struct sip_request *oreq);
@@ -506,7 +495,6 @@
 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);
-static const char *gettag(const struct sip_request *req, const char *header, char *tagbuf, int tagbufsize);
 static void free_old_route(struct sip_route *route);
 
 /*--- Constructing requests and responses */
@@ -2027,120 +2015,6 @@
 	return tmp;
 }
 
-/*! \brief Generate 32 byte random string for callid's etc */
-GNURK char *generate_random_string(char *buf, size_t size)
-{
-	long val[4];
-	int x;
-
-	for (x=0; x<4; x++)
-		val[x] = ast_random();
-	snprintf(buf, size, "%08lx%08lx%08lx%08lx", val[0], val[1], val[2], val[3]);
-
-	return buf;
-}
-
-/*! \brief Build SIP Call-ID value for a non-REGISTER transaction */
-GNURK void build_callid_pvt(struct sip_dialog *pvt)
-{
-	char buf[33];
-
-	const char *host = S_OR(pvt->fromdomain, ast_inet_ntoa(pvt->ourip));
-	
-	ast_string_field_build(pvt, callid, "%s@%s", generate_random_string(buf, sizeof(buf)), host);
-
-}
-
-/*! \brief Connect incoming SIP message to current dialog or create new dialog structure
-	Called by handle_request, sipsock_read */
-GNURK struct sip_dialog *find_call(struct sip_request *req, struct sockaddr_in *sin, const int intended_method)
-{
-	struct sip_dialog *p = NULL;
-	char *tag = "";	/* note, tag is never NULL */
-	char totag[128];
-	char fromtag[128];
-	const char *callid = get_header(req, "Call-ID");
-	const char *from = get_header(req, "From");
-	const char *to = get_header(req, "To");
-	const char *cseq = get_header(req, "Cseq");
-
-	/* Call-ID, to, from and Cseq are required by RFC 3261. (Max-forwards and via too - ignored now) */
-	/* get_header always returns non-NULL so we must use ast_strlen_zero() */
-	if (ast_strlen_zero(callid) || ast_strlen_zero(to) ||
-			ast_strlen_zero(from) || ast_strlen_zero(cseq))
-		return NULL;	/* Invalid packet */
-
-	/* In principle Call-ID's uniquely identify a call, but with a forking SIP proxy
-	   we need more to identify a branch - so we have to check branch, from
-	   and to tags to identify a call leg.
-	   */
-	if (gettag(req, "To", totag, sizeof(totag)))
-		ast_set_flag(req, SIP_PKT_WITH_TOTAG);	/* Used in handle_request/response */
-	gettag(req, "From", fromtag, sizeof(fromtag));
-
-	tag = (req->method == SIP_RESPONSE) ? totag : fromtag;
-
-	if (option_debug > 4 )
-		ast_log(LOG_DEBUG, "= Looking for  Call ID: %s (Checking %s) --From tag %s --To-tag %s  \n", callid, req->method==SIP_RESPONSE ? "To" : "From", fromtag, totag);
-
-	dialoglist_lock();
-	for (p = dialoglist; p; p = p->next) {
-		/* we do not want packets with bad syntax to be connected to a PVT */
-		int found = FALSE;
-		if (req->method == SIP_REGISTER)
-			found = (!strcmp(p->callid, callid));
-		else 
-			found = (!strcmp(p->callid, callid) && 
-			(!tag || ast_strlen_zero(p->theirtag) || !strcmp(p->theirtag, tag))) ;
-
-		if (option_debug > 4)
-			ast_log(LOG_DEBUG, "= %s Their Call ID: %s Their Tag %s Our tag: %s\n", found ? "Found" : "No match", p->callid, p->theirtag, p->tag);
-
-		/* If we get a new request within an existing to-tag - check the to tag as well */
-		if (found  && req->method != SIP_RESPONSE) {	/* SIP Request */
-			if (p->tag[0] == '\0' && totag[0]) {
-				/* We have no to tag, but they have. Wrong dialog */
-				found = FALSE;
-			} else if (totag[0]) {			/* Both have tags, compare them */
-				if (strcmp(totag, p->tag)) {
-					found = FALSE;		/* This is not our packet */
-				}
-			}
-			if (!found && option_debug > 4)
-				ast_log(LOG_DEBUG, "= Being pedantic: This is not our match on request: Call ID: %s Ourtag <null> Totag %s Method %s\n", p->callid, totag, sip_method2txt(req->method));
-		}
-
-
-		if (found) {
-			/* Found the call */
-			ast_mutex_lock(&p->lock);
-			dialoglist_unlock();
-			return p;
-		}
-	}
-	dialoglist_unlock();
-	if (sip_methods[intended_method].creates_dialog == CAN_CREATE_DIALOG) {
-		if (intended_method == SIP_REFER) {
-
-			/* We do not support out-of-dialog REFERs yet */
-			transmit_response_using_temp(callid, sin, 1, intended_method, req, "603 Declined (no dialog)");
-		} else if (intended_method == SIP_NOTIFY) {
-			/* We do not support out-of-dialog NOTIFY either,
-			  like voicemail notification, so cancel that early */
-			transmit_response_using_temp(callid, sin, 1, intended_method, req, "489 Bad event");
-		} else if ((p = sip_alloc(callid, sin, 1, intended_method))) {
-			/* This method creates dialog */
-			/* Ok, we've created a dialog, let's go and process it */
-			ast_mutex_lock(&p->lock);
-		}
-	} else {
-		if (intended_method != SIP_RESPONSE)
-			transmit_response_using_temp(callid, sin, 1, intended_method, req, "481 Call leg/transaction does not exist");
-	}
-
-	return p;
-}
-
 /*! \brief Parse a SIP message 
 	\note this function is used both on incoming and outgoing packets
 */
@@ -2522,7 +2396,7 @@
 }
 
 /*! \brief Base transmit response function */
-static int __transmit_response(struct sip_dialog *p, const char *msg, const struct sip_request *req, enum xmittype reliable)
+GNURK int __transmit_response(struct sip_dialog *p, const char *msg, const struct sip_request *req, enum xmittype reliable)
 {
 	struct sip_request resp;
 	int seqno = 0;
@@ -2543,75 +2417,6 @@
 		add_header(&resp, "X-Asterisk-HangupCauseCode", buf);
 	}
 	return send_response(p, &resp, reliable, seqno);
-}
-
-/*! \brief Initialize temporary PVT */
-static int temp_pvt_init(void *data)
-{
-	struct sip_dialog *p = data;
-
-	ast_set_flag(&p->flags[0], SIP_NO_HISTORY);
-	return ast_string_field_init(p, 512);
-}
-
-/*! \brief Cleanup temporary PVT */
-static void temp_pvt_cleanup(void *data)
-{
-	struct sip_dialog *p = data;
-
-	ast_string_field_free_pools(p);
-
-	free(data);
-}
-
-/*! \brief Transmit response, no retransmits, using a temporary pvt structure */
-static int transmit_response_using_temp(ast_string_field callid, struct sockaddr_in *sin, int useglobal_nat, const int intended_method, const struct sip_request *req, const char *msg)
-{
-	struct sip_dialog *p = NULL;
-
-	if (!(p = ast_threadstorage_get(&ts_temp_pvt, sizeof(*p)))) {
-		ast_log(LOG_NOTICE, "Failed to get temporary pvt\n");
-		return -1;
-	}
-
-	/* if the structure was just allocated, initialize it */
-	if (!ast_test_flag(&p->flags[0], SIP_NO_HISTORY)) {
-		ast_set_flag(&p->flags[0], SIP_NO_HISTORY);
-		if (ast_string_field_init(p, 512))
-			return -1;
-	}
-
-	/* Initialize the bare minimum */
-	p->method = intended_method;
-
-	if (sin) {
-		p->sa = *sin;
-		if (sip_ouraddrfor(&p->sa.sin_addr, &p->ourip))
-			p->ourip = sipnet.__ourip;
-	} else
-		p->ourip = sipnet.__ourip;
-
-	p->branch = ast_random();
-	make_our_tag(p->tag, sizeof(p->tag));
-	p->ocseq = INITIAL_CSEQ;
-
-	if (useglobal_nat && sin) {
-		ast_copy_flags(&p->flags[0], &global.flags[0], SIP_NAT);
-		p->recv = *sin;
-		do_setnat(p, ast_test_flag(&p->flags[0], SIP_NAT) & SIP_NAT_ROUTE);
-	}
-
-	ast_string_field_set(p, fromdomain, global.default_fromdomain);
-	build_via(p);
-	ast_string_field_set(p, callid, callid);
-
-	/* Use this temporary pvt structure to send the message */
-	__transmit_response(p, msg, req, XMIT_UNRELIABLE);
-
-	/* Free the string fields, but not the pool space */
-	ast_string_field_free_all(p);
-
-	return 0;
 }
 
 /*! \brief Transmit response, no retransmits */
@@ -6776,30 +6581,8 @@
 	return 0;
 }
 
-/*! \brief Get tag from packet 
- *
- * \return Returns the pointer to the provided tag buffer,
- *         or NULL if the tag was not found.
- */
-static const char *gettag(const struct sip_request *req, const char *header, char *tagbuf, int tagbufsize)
-{
-	const char *thetag;
-
-	if (!tagbuf)
-		return NULL;
-	tagbuf[0] = '\0'; 	/* reset the buffer */
-	thetag = get_header(req, header);
-	thetag = strcasestr(thetag, ";tag=");
-	if (thetag) {
-		thetag += 5;
-		ast_copy_string(tagbuf, thetag, tagbufsize);
-		return strsep(&tagbuf, ";");
-	}
-	return NULL;
-}
-
 /*! \brief Handle incoming notifications 
- * \note Out of dialog NOTIFY messages are killed in find_call()
+ * \note Out of dialog NOTIFY messages are killed in match_or_create_dialog()
  	If implementing VMI support, that needs to change 
  */
 static int handle_request_notify(struct sip_dialog *p, struct sip_request *req, struct sockaddr_in *sin, int seqno, char *e)
@@ -7774,7 +7557,7 @@
 	We can't destroy dialogs, since we want the call to continue.
 	
 	*/
-/*	XXX note that out-of-dialog refers are killed in find_call() */
+/*	XXX note that out-of-dialog refers are killed in match_or_create_dialog() */
 static int handle_request_refer(struct sip_dialog *p, struct sip_request *req, int debug, int seqno, int *nounlock)
 {
 	struct sip_dual current;	/* Chan1: Call between asterisk and transferer */

Modified: team/oej/codename-pineapple/channels/sip3/sip3_dialog.c
URL: http://svn.digium.com/view/asterisk/team/oej/codename-pineapple/channels/sip3/sip3_dialog.c?rev=46381&r1=46380&r2=46381&view=diff
==============================================================================
--- team/oej/codename-pineapple/channels/sip3/sip3_dialog.c (original)
+++ team/oej/codename-pineapple/channels/sip3/sip3_dialog.c Sat Oct 28 13:21:16 2006
@@ -87,6 +87,7 @@
 #include "asterisk/localtime.h"
 #include "asterisk/abstract_jb.h"
 #include "asterisk/compiler.h"
+#include "asterisk/threadstorage.h"
 #include "sip3.h"
 #include "sip3funcs.h"
 
@@ -103,6 +104,14 @@
 	\ref enum dialogstate
 
 */
+
+/* Forward declaration */
+static int temp_pvt_init(void *data);
+static void temp_pvt_cleanup(void *data);
+
+/*! \brief A per-thread temporary pvt structure */
+AST_THREADSTORAGE_CUSTOM(ts_temp_pvt, temp_pvt_init, temp_pvt_cleanup);
+
 
 /*! \brief Protect the SIP dialog list (of sip_dialog's) */
 AST_MUTEX_DEFINE_STATIC(dialoglock);
@@ -471,3 +480,161 @@
 	return p;
 }
 
+/*! \brief Initialize temporary PVT */
+static int temp_pvt_init(void *data)
+{
+	struct sip_dialog *p = data;
+
+	ast_set_flag(&p->flags[0], SIP_NO_HISTORY);
+	return ast_string_field_init(p, 512);
+}
+
+/*! \brief Cleanup temporary PVT */
+static void temp_pvt_cleanup(void *data)
+{
+	struct sip_dialog *p = data;
+
+	ast_string_field_free_pools(p);
+
+	free(data);
+}
+
+/*! \brief Transmit response, no retransmits, using a temporary pvt structure */
+static int transmit_response_using_temp(ast_string_field callid, struct sockaddr_in *sin, int useglobal_nat, const int intended_method, const struct sip_request *req, const char *msg)
+{
+	struct sip_dialog *p = NULL;
+
+	if (!(p = ast_threadstorage_get(&ts_temp_pvt, sizeof(*p)))) {
+		ast_log(LOG_NOTICE, "Failed to get temporary pvt\n");
+		return -1;
+	}
+
+	/* if the structure was just allocated, initialize it */
+	if (!ast_test_flag(&p->flags[0], SIP_NO_HISTORY)) {
+		ast_set_flag(&p->flags[0], SIP_NO_HISTORY);
+		if (ast_string_field_init(p, 512))
+			return -1;
+	}
+
+	/* Initialize the bare minimum */
+	p->method = intended_method;
+
+	if (sin) {
+		p->sa = *sin;
+		if (sip_ouraddrfor(&p->sa.sin_addr, &p->ourip))
+			p->ourip = sipnet.__ourip;
+	} else
+		p->ourip = sipnet.__ourip;
+
+	p->branch = ast_random();
+	make_our_tag(p->tag, sizeof(p->tag));
+	p->ocseq = INITIAL_CSEQ;
+
+	if (useglobal_nat && sin) {
+		ast_copy_flags(&p->flags[0], &global.flags[0], SIP_NAT);
+		p->recv = *sin;
+		do_setnat(p, ast_test_flag(&p->flags[0], SIP_NAT) & SIP_NAT_ROUTE);
+	}
+
+	ast_string_field_set(p, fromdomain, global.default_fromdomain);
+	build_via(p);
+	ast_string_field_set(p, callid, callid);
+
+	/* Use this temporary pvt structure to send the message */
+	__transmit_response(p, msg, req, XMIT_UNRELIABLE);
+
+	/* Free the string fields, but not the pool space */
+	ast_string_field_free_all(p);
+
+	return 0;
+}
+
+/*! \brief Connect incoming SIP message to current dialog or create new dialog structure
+	Called by handle_request, sipsock_read */
+struct sip_dialog *match_or_create_dialog(struct sip_request *req, struct sockaddr_in *sin, const int intended_method)
+{
+	struct sip_dialog *p = NULL;
+	char *tag = "";	/* note, tag is never NULL */
+	char totag[128];
+	char fromtag[128];
+	const char *callid = get_header(req, "Call-ID");
+	const char *from = get_header(req, "From");
+	const char *to = get_header(req, "To");
+	const char *cseq = get_header(req, "Cseq");
+
+	/* Call-ID, to, from and Cseq are required by RFC 3261. (Max-forwards and via too - ignored now) */
+	/* get_header always returns non-NULL so we must use ast_strlen_zero() */
+	if (ast_strlen_zero(callid) || ast_strlen_zero(to) ||
+			ast_strlen_zero(from) || ast_strlen_zero(cseq))
+		return NULL;	/* Invalid packet */
+
+	/* In principle Call-ID's uniquely identify a call, but with a forking SIP proxy
+	   we need more to identify a branch - so we have to check branch, from
+	   and to tags to identify a call leg.
+	   */
+	if (gettag(req, "To", totag, sizeof(totag)))
+		ast_set_flag(req, SIP_PKT_WITH_TOTAG);	/* Used in handle_request/response */
+	gettag(req, "From", fromtag, sizeof(fromtag));
+
+	tag = (req->method == SIP_RESPONSE) ? totag : fromtag;
+
+	if (option_debug > 4 )
+		ast_log(LOG_DEBUG, "= Looking for  Call ID: %s (Checking %s) --From tag %s --To-tag %s  \n", callid, req->method==SIP_RESPONSE ? "To" : "From", fromtag, totag);
+
+	dialoglist_lock();
+	for (p = dialoglist; p; p = p->next) {
+		/* we do not want packets with bad syntax to be connected to a PVT */
+		int found = FALSE;
+		if (req->method == SIP_REGISTER)
+			found = (!strcmp(p->callid, callid));
+		else 
+			found = (!strcmp(p->callid, callid) && 
+			(!tag || ast_strlen_zero(p->theirtag) || !strcmp(p->theirtag, tag))) ;
+
+		if (option_debug > 4)
+			ast_log(LOG_DEBUG, "= %s Their Call ID: %s Their Tag %s Our tag: %s\n", found ? "Found" : "No match", p->callid, p->theirtag, p->tag);
+
+		/* If we get a new request within an existing to-tag - check the to tag as well */
+		if (found  && req->method != SIP_RESPONSE) {	/* SIP Request */
+			if (p->tag[0] == '\0' && totag[0]) {
+				/* We have no to tag, but they have. Wrong dialog */
+				found = FALSE;
+			} else if (totag[0]) {			/* Both have tags, compare them */
+				if (strcmp(totag, p->tag)) {
+					found = FALSE;		/* This is not our packet */
+				}
+			}
+			if (!found && option_debug > 4)
+				ast_log(LOG_DEBUG, "= Being pedantic: This is not our match on request: Call ID: %s Ourtag <null> Totag %s Method %s\n", p->callid, totag, sip_method2txt(req->method));
+		}
+
+
+		if (found) {
+			/* Found the call */
+			ast_mutex_lock(&p->lock);
+			dialoglist_unlock();
+			return p;
+		}
+	}
+	dialoglist_unlock();
+	if (sip_methods[intended_method].creates_dialog == CAN_CREATE_DIALOG) {
+		if (intended_method == SIP_REFER) {
+
+			/* We do not support out-of-dialog REFERs yet */
+			transmit_response_using_temp(callid, sin, 1, intended_method, req, "603 Declined (no dialog)");
+		} else if (intended_method == SIP_NOTIFY) {
+			/* We do not support out-of-dialog NOTIFY either,
+			  like voicemail notification, so cancel that early */
+			transmit_response_using_temp(callid, sin, 1, intended_method, req, "489 Bad event");
+		} else if ((p = sip_alloc(callid, sin, 1, intended_method))) {
+			/* This method creates dialog */
+			/* Ok, we've created a dialog, let's go and process it */
+			ast_mutex_lock(&p->lock);
+		}
+	} else {
+		if (intended_method != SIP_RESPONSE)
+			transmit_response_using_temp(callid, sin, 1, intended_method, req, "481 Call leg/transaction does not exist");
+	}
+
+	return p;
+}

Modified: team/oej/codename-pineapple/channels/sip3/sip3_network.c
URL: http://svn.digium.com/view/asterisk/team/oej/codename-pineapple/channels/sip3/sip3_network.c?rev=46381&r1=46380&r2=46381&view=diff
==============================================================================
--- team/oej/codename-pineapple/channels/sip3/sip3_network.c (original)
+++ team/oej/codename-pineapple/channels/sip3/sip3_network.c Sat Oct 28 13:21:16 2006
@@ -170,7 +170,7 @@
 	sipnet_lock();
 
 	/* Find the active SIP dialog or create a new one */
-	p = find_call(&req, &sin, req.method);	/* returns p locked */
+	p = match_or_create_dialog(&req, &sin, req.method);	/* returns p locked */
 	if (p == NULL) {
 		if (option_debug)
 			ast_log(LOG_DEBUG, "Invalid SIP message - rejected , no callid, len %d\n", req.len);

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=46381&r1=46380&r2=46381&view=diff
==============================================================================
--- team/oej/codename-pineapple/channels/sip3/sip3_parse.c (original)
+++ team/oej/codename-pineapple/channels/sip3/sip3_parse.c Sat Oct 28 13:21:16 2006
@@ -191,6 +191,28 @@
 	return sip_methods[method].need_rtp;
 }
 
+/*! \brief Get tag from packet 
+ *
+ * \return Returns the pointer to the provided tag buffer,
+ *         or NULL if the tag was not found.
+ */
+const char *gettag(const struct sip_request *req, const char *header, char *tagbuf, int tagbufsize)
+{
+	const char *thetag;
+
+	if (!tagbuf)
+		return NULL;
+	tagbuf[0] = '\0'; 	/* reset the buffer */
+	thetag = get_header(req, header);
+	thetag = strcasestr(thetag, ";tag=");
+	if (thetag) {
+		thetag += 5;
+		ast_copy_string(tagbuf, thetag, tagbufsize);
+		return strsep(&tagbuf, ";");
+	}
+	return NULL;
+}
+
 /*! \brief Check if sip option is known to us, avoid x- options (non-standard) */ 
 static int sip_option_lookup(const char *optionlabel)
 {
@@ -547,3 +569,27 @@
 	return t; 
 }
 
+/*! \brief Build SIP Call-ID value for a non-REGISTER transaction */
+void build_callid_pvt(struct sip_dialog *pvt)
+{
+	char buf[33];
+
+	const char *host = S_OR(pvt->fromdomain, ast_inet_ntoa(pvt->ourip));
+	
+	ast_string_field_build(pvt, callid, "%s@%s", generate_random_string(buf, sizeof(buf)), host);
+
+}
+
+/*! \brief Generate 32 byte random string for callid's etc */
+char *generate_random_string(char *buf, size_t size)
+{
+	long val[4];
+	int x;
+
+	for (x=0; x<4; x++)
+		val[x] = ast_random();
+	snprintf(buf, size, "%08lx%08lx%08lx%08lx", val[0], val[1], val[2], val[3]);
+
+	return buf;
+}
+

Modified: team/oej/codename-pineapple/channels/sip3/sip3_services.c
URL: http://svn.digium.com/view/asterisk/team/oej/codename-pineapple/channels/sip3/sip3_services.c?rev=46381&r1=46380&r2=46381&view=diff
==============================================================================
--- team/oej/codename-pineapple/channels/sip3/sip3_services.c (original)
+++ team/oej/codename-pineapple/channels/sip3/sip3_services.c Sat Oct 28 13:21:16 2006
@@ -93,7 +93,6 @@
 #include "sip3funcs.h"
 
 /* Forward declaration */
-static int transmit_register(struct sip_registry *r, int sipmethod, const char *auth, const char *authheader);
 static int sip_reregister(void *data);
 
 /*! \brief  The register list: Other SIP proxys we register with and place calls to */
@@ -337,7 +336,7 @@
 }
 
 /*! \brief Transmit register to SIP proxy or UA */
-static int transmit_register(struct sip_registry *r, int sipmethod, const char *auth, const char *authheader)
+int transmit_register(struct sip_registry *r, int sipmethod, const char *auth, const char *authheader)
 {
 	struct sip_request req;
 	char from[256];

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=46381&r1=46380&r2=46381&view=diff
==============================================================================
--- team/oej/codename-pineapple/channels/sip3/sip3funcs.h (original)
+++ team/oej/codename-pineapple/channels/sip3/sip3funcs.h Sat Oct 28 13:21:16 2006
@@ -49,7 +49,6 @@
 GNURK void sip_peer_hold(struct sip_dialog *p, int hold);
 GNURK struct sip_auth *add_realm_authentication(struct sip_auth *authlist, char *configuration, int lineno);	/* Add realm authentication in list */
 GNURK int transmit_reinvite_with_sdp(struct sip_dialog *p);
-GNURK struct sip_dialog *find_call(struct sip_request *req, struct sockaddr_in *sin, const int intended_method);
 GNURK void add_blank(struct sip_request *req);
 GNURK int handle_request(struct sip_dialog *p, struct sip_request *req, struct sockaddr_in *sin, int *recount, int *nounlock);
 GNURK int add_header(struct sip_request *req, const char *var, const char *value);
@@ -76,14 +75,13 @@
 GNURK int transmit_request_with_auth(struct sip_dialog *p, int sipmethod, int seqno, enum xmittype reliable, int newbranch);
 GNURK void sip_destroy(struct sip_dialog *p);
 GNURK void do_setnat(struct sip_dialog *p, int natflags);
-GNURK void build_callid_pvt(struct sip_dialog *pvt);
 GNURK void build_via(struct sip_dialog *p);
-GNURK char *generate_random_string(char *buf, size_t size);
 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);
 
 /*! sip3_refer.c */
 GNURK const char *referstatus2str(enum referstatus rstatus) attribute_pure;
@@ -124,8 +122,10 @@
 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);
 GNURK const char *__get_header(const struct sip_request *req, const char *name, int *start);
-//GNURK const char *find_closing_quote(const char *start, const char *lim);
 GNURK char *get_in_brackets(char *tmp);
+GNURK char *generate_random_string(char *buf, size_t size);
+GNURK void build_callid_pvt(struct sip_dialog *pvt);
+GNURK const char *gettag(const struct sip_request *req, const char *header, char *tagbuf, int tagbufsize);
 
 /*! 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);
@@ -186,7 +186,7 @@
 GNURK char *complete_sip_user(const char *word, int state, int flags2);
 
 
-/* sip3_dialog.h */
+/* sip3_dialog.c */
 GNURK void dialoglist_lock(void);
 GNURK void dialoglist_unlock(void);
 GNURK void sip_scheddestroy(struct sip_dialog *p, int ms);
@@ -195,13 +195,15 @@
 GNURK const char *hangup_cause2sip(int cause);
 GNURK struct sip_dialog *sip_alloc(ast_string_field callid, struct sockaddr_in *sin, int useglobal_nat, const int intended_method);
 GNURK void make_our_tag(char *tagbuf, size_t len);
-
-/* sip3_services.h - outbound registration for services from other servers/providers  */
+GNURK struct sip_dialog *match_or_create_dialog(struct sip_request *req, struct sockaddr_in *sin, const int intended_method);
+
+/* sip3_services.c - outbound registration for services from other servers/providers  */
 
 GNURK void sip_send_all_registers(void);
 GNURK int sip_register(char *value, int lineno);
 GNURK void sip_registry_destroy(struct sip_registry *reg);
 GNURK char *regstate2str(enum sipregistrystate regstate) attribute_const;
 GNURK int handle_response_register(struct sip_dialog *p, int resp, char *rest, struct sip_request *req, int seqno);
+GNURK int transmit_register(struct sip_registry *r, int sipmethod, const char *auth, const char *authheader);
 
 #endif



More information about the asterisk-commits mailing list