[asterisk-commits] oej: branch 1.4 r99652 - /branches/1.4/channels/chan_sip.c

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Tue Jan 22 14:56:10 CST 2008


Author: oej
Date: Tue Jan 22 14:56:09 2008
New Revision: 99652

URL: http://svn.digium.com/view/asterisk?view=rev&rev=99652
Log:
Thanks to Russell's education I realize that BUFSIZ has changed since I learned the C language 
over 20 years ago... Resetting chan_sip to the size of BUFSIZ that I expected in my old 
head to avoid to heavy memory allocations on some systems.

Modified:
    branches/1.4/channels/chan_sip.c

Change Statistics:
 0 files changed

Modified: branches/1.4/channels/chan_sip.c
URL: http://svn.digium.com/view/asterisk/branches/1.4/channels/chan_sip.c?view=diff&rev=99652&r1=99651&r2=99652
==============================================================================
--- branches/1.4/channels/chan_sip.c (original)
+++ branches/1.4/channels/chan_sip.c Tue Jan 22 14:56:09 2008
@@ -159,6 +159,8 @@
 #define TRUE     1
 #endif
 
+#define	SIPBUFSIZE		512
+
 #define XMIT_ERROR		-2
 
 #define VIDEO_CODEC_MASK        0x1fc0000 /*!< Video codecs from H.261 thru AST_FORMAT_MAX_VIDEO */
@@ -889,9 +891,9 @@
 	char referred_by[AST_MAX_EXTENSION];		/*!< Place to store REFERRED-BY extension */
 	char referred_by_name[AST_MAX_EXTENSION];	/*!< Place to store REFERRED-BY extension */
 	char refer_contact[AST_MAX_EXTENSION];		/*!< Place to store Contact info from a REFER extension */
-	char replaces_callid[BUFSIZ];			/*!< Replace info: callid */
-	char replaces_callid_totag[BUFSIZ/2];		/*!< Replace info: to-tag */
-	char replaces_callid_fromtag[BUFSIZ/2];		/*!< Replace info: from-tag */
+	char replaces_callid[SIPBUFSIZE];			/*!< Replace info: callid */
+	char replaces_callid_totag[SIPBUFSIZE/2];		/*!< Replace info: to-tag */
+	char replaces_callid_fromtag[SIPBUFSIZE/2];		/*!< Replace info: from-tag */
 	struct sip_pvt *refer_call;			/*!< Call we are referring */
 	int attendedtransfer;				/*!< Attended or blind transfer? */
 	int localtransfer;				/*!< Transfer to local domain? */
@@ -2984,7 +2986,7 @@
 	ast_set_flag(&p->flags[0], SIP_OUTGOING);
 
 	if (p->options->transfer) {
-		char buf[BUFSIZ/2];
+		char buf[SIPBUFSIZE/2];
 
 		if (referer) {
 			if (sipdebug && option_debug > 2)
@@ -3996,13 +3998,13 @@
 	/* Set the native formats for audio  and merge in video */
 	tmp->nativeformats = ast_codec_choose(&i->prefs, what, 1) | video;
 	if (option_debug > 2) {
-		char buf[BUFSIZ];
-		ast_log(LOG_DEBUG, "*** Our native formats are %s \n", ast_getformatname_multiple(buf, BUFSIZ, tmp->nativeformats));
-		ast_log(LOG_DEBUG, "*** Joint capabilities are %s \n", ast_getformatname_multiple(buf, BUFSIZ, i->jointcapability));
-		ast_log(LOG_DEBUG, "*** Our capabilities are %s \n", ast_getformatname_multiple(buf, BUFSIZ, i->capability));
-		ast_log(LOG_DEBUG, "*** AST_CODEC_CHOOSE formats are %s \n", ast_getformatname_multiple(buf, BUFSIZ, ast_codec_choose(&i->prefs, what, 1)));
+		char buf[SIPBUFSIZE];
+		ast_log(LOG_DEBUG, "*** Our native formats are %s \n", ast_getformatname_multiple(buf, SIPBUFSIZE, tmp->nativeformats));
+		ast_log(LOG_DEBUG, "*** Joint capabilities are %s \n", ast_getformatname_multiple(buf, SIPBUFSIZE, i->jointcapability));
+		ast_log(LOG_DEBUG, "*** Our capabilities are %s \n", ast_getformatname_multiple(buf, SIPBUFSIZE, i->capability));
+		ast_log(LOG_DEBUG, "*** AST_CODEC_CHOOSE formats are %s \n", ast_getformatname_multiple(buf, SIPBUFSIZE, ast_codec_choose(&i->prefs, what, 1)));
 		if (i->prefcodec)
-			ast_log(LOG_DEBUG, "*** Our preferred formats from the incoming channel are %s \n", ast_getformatname_multiple(buf, BUFSIZ, i->prefcodec));
+			ast_log(LOG_DEBUG, "*** Our preferred formats from the incoming channel are %s \n", ast_getformatname_multiple(buf, SIPBUFSIZE, i->prefcodec));
 	}
 
 	/* XXX Why are we choosing a codec from the native formats?? */
@@ -5409,18 +5411,18 @@
 		
 	if (debug) {
 		/* shame on whoever coded this.... */
-		char s1[BUFSIZ], s2[BUFSIZ], s3[BUFSIZ], s4[BUFSIZ];
+		char s1[SIPBUFSIZE], s2[SIPBUFSIZE], s3[SIPBUFSIZE], s4[SIPBUFSIZE];
 
 		ast_verbose("Capabilities: us - %s, peer - audio=%s/video=%s, combined - %s\n",
-			    ast_getformatname_multiple(s1, BUFSIZ, p->capability),
-			    ast_getformatname_multiple(s2, BUFSIZ, newpeercapability),
-			    ast_getformatname_multiple(s3, BUFSIZ, vpeercapability),
-			    ast_getformatname_multiple(s4, BUFSIZ, newjointcapability));
+			    ast_getformatname_multiple(s1, SIPBUFSIZE, p->capability),
+			    ast_getformatname_multiple(s2, SIPBUFSIZE, newpeercapability),
+			    ast_getformatname_multiple(s3, SIPBUFSIZE, vpeercapability),
+			    ast_getformatname_multiple(s4, SIPBUFSIZE, newjointcapability));
 
 		ast_verbose("Non-codec capabilities (dtmf): us - %s, peer - %s, combined - %s\n",
-			    ast_rtp_lookup_mime_multiple(s1, BUFSIZ, p->noncodeccapability, 0, 0),
-			    ast_rtp_lookup_mime_multiple(s2, BUFSIZ, peernoncodeccapability, 0, 0),
-			    ast_rtp_lookup_mime_multiple(s3, BUFSIZ, newnoncodeccapability, 0, 0));
+			    ast_rtp_lookup_mime_multiple(s1, SIPBUFSIZE, p->noncodeccapability, 0, 0),
+			    ast_rtp_lookup_mime_multiple(s2, SIPBUFSIZE, peernoncodeccapability, 0, 0),
+			    ast_rtp_lookup_mime_multiple(s3, SIPBUFSIZE, newnoncodeccapability, 0, 0));
 	}
 	if (!newjointcapability) {
 		/* If T.38 was not negotiated either, totally bail out... */
@@ -5474,8 +5476,8 @@
 
 	/* Ok, we're going with this offer */
 	if (option_debug > 1) {
-		char buf[BUFSIZ];
-		ast_log(LOG_DEBUG, "We're settling with these formats: %s\n", ast_getformatname_multiple(buf, BUFSIZ, p->jointcapability));
+		char buf[SIPBUFSIZE];
+		ast_log(LOG_DEBUG, "We're settling with these formats: %s\n", ast_getformatname_multiple(buf, SIPBUFSIZE, p->jointcapability));
 	}
 
 	if (!p->owner) 	/* There's no open channel owning us so we can return here. For a re-invite or so, we proceed */
@@ -5486,10 +5488,10 @@
 
 	if (!(p->owner->nativeformats & p->jointcapability) && (p->jointcapability & AST_FORMAT_AUDIO_MASK)) {
 		if (debug) {
-			char s1[BUFSIZ], s2[BUFSIZ];
+			char s1[SIPBUFSIZE], s2[SIPBUFSIZE];
 			ast_log(LOG_DEBUG, "Oooh, we need to change our audio formats since our peer supports only %s and not %s\n", 
-				ast_getformatname_multiple(s1, BUFSIZ, p->jointcapability),
-				ast_getformatname_multiple(s2, BUFSIZ, p->owner->nativeformats));
+				ast_getformatname_multiple(s1, SIPBUFSIZE, p->jointcapability),
+				ast_getformatname_multiple(s2, SIPBUFSIZE, p->owner->nativeformats));
 		}
 		p->owner->nativeformats = ast_codec_choose(&p->prefs, p->jointcapability, 1) | (p->capability & vpeercapability);
 		ast_set_read_format(p->owner, p->owner->readformat);
@@ -5685,7 +5687,7 @@
 /*! \brief Add route header into request per learned route */
 static void add_route(struct sip_request *req, struct sip_route *route)
 {
-	char r[BUFSIZ*2], *p;
+	char r[SIPBUFSIZE*2], *p;
 	int n, rem = sizeof(r);
 
 	if (!route)
@@ -5839,7 +5841,7 @@
 		snprintf(tmp, sizeof(tmp), "%d", p->expiry);
 		add_header(resp, "Expires", tmp);
 		if (p->expiry) {	/* Only add contact if we have an expiry time */
-			char contact[BUFSIZ];
+			char contact[SIPBUFSIZE];
 			snprintf(contact, sizeof(contact), "%s;expires=%d", p->our_contact, p->expiry);
 			add_header(resp, "Contact", contact);	/* Not when we unregister */
 		}
@@ -6427,7 +6429,7 @@
 
 
 	if (option_debug > 1) {
-		char codecbuf[BUFSIZ];
+		char codecbuf[SIPBUFSIZE];
 		ast_log(LOG_DEBUG, "** Our capability: %s Video flag: %s\n", ast_getformatname_multiple(codecbuf, sizeof(codecbuf), capability), ast_test_flag(&p->flags[0], SIP_NOVIDEO) ? "True" : "False");
 		ast_log(LOG_DEBUG, "** Our prefcodec: %s \n", ast_getformatname_multiple(codecbuf, sizeof(codecbuf), p->prefcodec));
 	}
@@ -6604,8 +6606,8 @@
 	p->lastrtprx = p->lastrtptx = time(NULL); /* XXX why both ? */
 
 	if (option_debug > 2) {
-		char buf[BUFSIZ];
-		ast_log(LOG_DEBUG, "Done building SDP. Settling with this capability: %s\n", ast_getformatname_multiple(buf, BUFSIZ, capability));
+		char buf[SIPBUFSIZE];
+		ast_log(LOG_DEBUG, "Done building SDP. Settling with this capability: %s\n", ast_getformatname_multiple(buf, SIPBUFSIZE, capability));
 	}
 
 	return AST_SUCCESS;
@@ -6769,7 +6771,7 @@
 /*! \brief Check Contact: URI of SIP message */
 static void extract_uri(struct sip_pvt *p, struct sip_request *req)
 {
-	char stripped[BUFSIZ];
+	char stripped[SIPBUFSIZE];
 	char *c;
 
 	ast_copy_string(stripped, get_header(req, "Contact"), sizeof(stripped));
@@ -6876,8 +6878,8 @@
 	size_t invite_max = sizeof(invite_buf);
 	char from[256];
 	char to[256];
-	char tmp[BUFSIZ/2];
-	char tmp2[BUFSIZ/2];
+	char tmp[SIPBUFSIZE/2];
+	char tmp2[SIPBUFSIZE/2];
 	const char *l = NULL, *n = NULL;
 	const char *urioptions = "";
 
@@ -7024,7 +7026,7 @@
 	append_date(&req);
 	if (sipmethod == SIP_REFER) {	/* Call transfer */
 		if (p->refer) {
-			char buf[BUFSIZ];
+			char buf[SIPBUFSIZE];
 			if (!ast_strlen_zero(p->refer->refer_to))
 				add_header(&req, "Refer-To", p->refer->refer_to);
 			if (!ast_strlen_zero(p->refer->referred_by)) {
@@ -7337,7 +7339,7 @@
 static int transmit_notify_with_sipfrag(struct sip_pvt *p, int cseq, char *message, int terminate)
 {
 	struct sip_request req;
-	char tmp[BUFSIZ/2];
+	char tmp[SIPBUFSIZE/2];
 
 	reqprep(&req, p, SIP_NOTIFY, 0, 1);
 	snprintf(tmp, sizeof(tmp), "refer;id=%d", cseq);
@@ -7924,7 +7926,7 @@
 /*! \brief Save contact header for 200 OK on INVITE */
 static int parse_ok_contact(struct sip_pvt *pvt, struct sip_request *req)
 {
-	char contact[BUFSIZ]; 
+	char contact[SIPBUFSIZE]; 
 	char *c;
 
 	/* Look for brackets */
@@ -8008,8 +8010,8 @@
 /*! \brief Parse contact header and save registration (peer registration) */
 static enum parse_register_result parse_register_contact(struct sip_pvt *pvt, struct sip_peer *peer, struct sip_request *req)
 {
-	char contact[BUFSIZ]; 
-	char data[BUFSIZ];
+	char contact[SIPBUFSIZE]; 
+	char data[SIPBUFSIZE];
 	const char *expires = get_header(req, "Expires");
 	int expiry = atoi(expires);
 	char *curi, *n, *pt;
@@ -10581,7 +10583,7 @@
 {
 	int realtimepeers;
 	int realtimeusers;
-	char codec_buf[BUFSIZ];
+	char codec_buf[SIPBUFSIZE];
 
 	realtimepeers = ast_check_realtime("sippeers");
 	realtimeusers = ast_check_realtime("sipusers");
@@ -10745,7 +10747,7 @@
 			referstatus = referstatus2str(cur->refer->status);
 		}
 		if (cur->subscribed == NONE && !subscriptions) {
-			char formatbuf[BUFSIZ/2];
+			char formatbuf[SIPBUFSIZE/2];
 			ast_cli(fd, FORMAT, ast_inet_ntoa(cur->sa.sin_addr), 
 				S_OR(cur->username, S_OR(cur->cid_num, "(None)")),
 				cur->callid, 
@@ -10925,7 +10927,7 @@
 	ast_mutex_lock(&iflock);
 	for (cur = iflist; cur; cur = cur->next) {
 		if (!strncasecmp(cur->callid, argv[3], len)) {
-			char formatbuf[BUFSIZ/2];
+			char formatbuf[SIPBUFSIZE/2];
 			ast_cli(fd,"\n");
 			if (cur->subscribed != NONE)
 				ast_cli(fd, "  * Subscription (type: %s)\n", subscription_type2str(cur->subscribed));
@@ -11881,7 +11883,7 @@
 /*! \brief Parse 302 Moved temporalily response */
 static void parse_moved_contact(struct sip_pvt *p, struct sip_request *req)
 {
-	char tmp[BUFSIZ];
+	char tmp[SIPBUFSIZE];
 	char *s, *e, *uri, *t;
 	char *domain;
 
@@ -14482,7 +14484,7 @@
 	}
 	/* Generate a Replaces string to be used in the INVITE during attended transfer */
 	if (p->refer->replaces_callid && !ast_strlen_zero(p->refer->replaces_callid)) {
-		char tempheader[BUFSIZ];
+		char tempheader[SIPBUFSIZE];
 		snprintf(tempheader, sizeof(tempheader), "%s%s%s%s%s", p->refer->replaces_callid, 
 				p->refer->replaces_callid_totag ? ";to-tag=" : "", 
 				p->refer->replaces_callid_totag, 




More information about the asterisk-commits mailing list