[asterisk-commits] rizzo: branch rizzo/astobj2 r75524 - /team/rizzo/astobj2/channels/chan_sip.c

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Wed Jul 18 00:47:00 CDT 2007


Author: rizzo
Date: Wed Jul 18 00:47:00 2007
New Revision: 75524

URL: http://svn.digium.com/view/asterisk?view=rev&rev=75524
Log:
some small simplification to build_contact(), and
comments on the management of the 'localnet' list
(both trunk candidates.)

adapt to 64-bit ast_flags - the patch is copied from
trunk, but i am not sure it is entirely correct (both
there and here). In particulat, "flags" should be declared
as 'struct ast_flag' and not as the internal representation,
which is too error prone; and the print of 'Need Destroy'
should be just a 0/1 value not the actual flag
(this is a minor bug in trunk).


Modified:
    team/rizzo/astobj2/channels/chan_sip.c

Modified: team/rizzo/astobj2/channels/chan_sip.c
URL: http://svn.digium.com/view/asterisk/team/rizzo/astobj2/channels/chan_sip.c?view=diff&rev=75524&r1=75523&r2=75524
==============================================================================
--- team/rizzo/astobj2/channels/chan_sip.c (original)
+++ team/rizzo/astobj2/channels/chan_sip.c Wed Jul 18 00:47:00 2007
@@ -656,7 +656,7 @@
 	int headers;            /*!< # of SIP Headers */
 	int method;             /*!< Method of this request */
 	int lines;              /*!< Body Content */
-	unsigned int flags;     /*!< SIP_PKT Flags for this packet */
+	uint64_t flags;		/*!< SIP_PKT Flags for this packet */
 	unsigned int sdp_start; /*!< the line number where the SDP begins */
 	unsigned int sdp_end;   /*!< the line number where the SDP ends */
 	char *header[SIP_MAX_HEADERS];
@@ -1129,7 +1129,7 @@
 /*! \brief test the SIP_NEEDDESTROY flag on a dialog */
 static inline int test_destroy(const struct sip_pvt *pvt)
 {
-	return ast_test_flag(&pvt->flags[0], SIP_NEEDDESTROY);	
+	return ast_test_flag(&pvt->flags[0], SIP_NEEDDESTROY) ? 1 : 0;
 }
 
 #define FLAG_RESPONSE (1 << 0)
@@ -1146,7 +1146,7 @@
 	int retrans;				/*!< Retransmission number */
 	int method;				/*!< SIP method for this packet */
 	int seqno;				/*!< Sequence number */
-	unsigned int flags;			/*!< non-zero if this is a response packet (e.g. 200 OK) */
+	uint64_t flags;				/*!< non-zero if this is a response packet (e.g. 200 OK) */
 	struct sip_pvt *pvt;			/*!< Owner AST call */
 	int retransid;				/*!< Retransmission ID */
 	int timer_a;				/*!< SIP timer A, retransmission timer */
@@ -1393,7 +1393,15 @@
 static char externhost[MAXHOSTNAMELEN];		/*!< External host name (possibly with dynamic DNS and DHCP */
 static time_t externexpire = 0;			/*!< Expiration counter for re-resolving external host name in dynamic DNS */
 static int externrefresh = 10;
-static struct ast_ha *localaddr;		/*!< List of local networks, on the same side of NAT as this Asterisk */
+
+/*! \brief  List of local networks
+ * We store "localnet" addresses from the config file into an access list,
+ * marked as 'DENY', so the call to ast_apply_ha() will return
+ * AST_SENSE_DENY for 'local' addresses, and AST_SENSE_ALLOW for 'non local'
+ * (i.e. presumably public) addresses.
+ */
+static struct ast_ha *localaddr;
+
 static struct in_addr __ourip;
 static int ourport;
 static struct sockaddr_in debugaddr;
@@ -2184,8 +2192,11 @@
 	theirs.sin_addr = *them;
 	ours.sin_addr = *us;
 
+	/* localaddr contains 'internal' addresses marked as 'deny',
+	 * so 'external' addresses will return AST_SENSE_ALLOW.
+	 */
 	if (localaddr && externip.sin_addr.s_addr &&
-	    ast_apply_ha(localaddr, &theirs) &&
+	    ast_apply_ha(localaddr, &theirs) == AST_SENSE_ALLOW &&
 	    (!global_matchexterniplocally || !ast_apply_ha(localaddr, &ours))) {
 		if (externexpire && time(NULL) >= externexpire) {
 			externexpire = time(NULL) + externrefresh;
@@ -7467,10 +7478,13 @@
 static void build_contact(struct sip_pvt *p)
 {
 	/* Construct Contact: header */
+	char port[16];
+	port[0] = '\0';
 	if (ourport != STANDARD_SIP_PORT)
-		ast_string_field_build(p, our_contact, "<sip:%s%s%s:%d>", p->exten, ast_strlen_zero(p->exten) ? "" : "@", ast_inet_ntoa(p->ourip), 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));
+		snprintf(port, sizeof(port), ":%6d", ourport);
+	ast_string_field_build(p, our_contact, "<sip:%s%s%s%s>",
+		p->exten, ast_strlen_zero(p->exten) ? "" : "@",
+		ast_inet_ntoa(p->ourip), port);
 }
 
 /*! \brief Build the Remote Party-ID & From using callingpres options */




More information about the asterisk-commits mailing list