[svn-commits] rizzo: branch rizzo/astobj2 r48539 - /team/rizzo/astobj2/channels/chan_sip.c

svn-commits at lists.digium.com svn-commits at lists.digium.com
Sun Dec 17 01:31:57 MST 2006


Author: rizzo
Date: Sun Dec 17 02:31:56 2006
New Revision: 48539

URL: http://svn.digium.com/view/asterisk?view=rev&rev=48539
Log:
get rid of more useless fields in struct sip_msg_out;

remove two erroneous remarks i made on the return value of snprintf.


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=48539&r1=48538&r2=48539
==============================================================================
--- team/rizzo/astobj2/channels/chan_sip.c (original)
+++ team/rizzo/astobj2/channels/chan_sip.c Sun Dec 17 02:31:56 2006
@@ -654,8 +654,8 @@
 	unsigned int _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];
-	char *line[SIP_MAX_LINES];
+	char *_header[SIP_MAX_HEADERS];
+	char *_line[SIP_MAX_LINES];
 	char data[SIP_MAX_PACKET];
 };
 
@@ -5692,7 +5692,7 @@
 	int maxlen = sizeof(req->data) - 4 - req->len; /* 4 bytes are for two \r\n ? */
 	char *dst;
 
-	if (req->headers == SIP_MAX_HEADERS) {
+	if (req->headers >= SIP_MAX_HEADERS) {
 		ast_log(LOG_WARNING, "Out of SIP header space\n");
 		return -1;
 	}
@@ -5707,7 +5707,7 @@
 		return -1;
 	}
 
-	dst = req->header[req->headers] = req->data + req->len;
+	dst = req->data + req->len;
 
 	if (compactheaders)
 		var = find_alias(var, var);
@@ -5731,7 +5731,9 @@
 /*! \brief Add content (not header) to SIP message */
 static int add_line(struct sip_msg_out *req, const char *line)
 {
-	if (req->lines == SIP_MAX_LINES)  {
+	char *dst;
+
+	if (req->lines >= SIP_MAX_LINES)  {
 		ast_log(LOG_WARNING, "Out of SIP line space\n");
 		return -1;
 	}
@@ -5744,9 +5746,9 @@
 		ast_log(LOG_WARNING, "Out of space, can't add anymore\n");
 		return -1;
 	}
-	req->line[req->lines] = req->data + req->len;
-	snprintf(req->line[req->lines], sizeof(req->data) - req->len, "%s", line);
-	req->len += strlen(req->line[req->lines]);
+	dst = req->data + req->len;
+	snprintf(dst, sizeof(req->data) - req->len, "%s", line);
+	req->len += strlen(dst);
 	req->lines++;
 	return 0;	
 }
@@ -5938,13 +5940,12 @@
 /*! \brief Initialize SIP response, based on SIP request */
 static int init_resp(struct sip_msg_out *resp, const char *msg)
 {
-	/* Initialize a response */
+	char *dst = resp->data;
+
 	memset(resp, 0, sizeof(*resp));
 	resp->method = SIP_RESPONSE;
-	resp->header[0] = resp->data;
-	snprintf(resp->header[0], sizeof(resp->data), "SIP/2.0 %s\r\n", msg);
-	/* XXX no need to do a strlen, sprintf tells us what the size is */
-	resp->len = strlen(resp->header[0]);
+	snprintf(dst, sizeof(resp->data) - 4, "SIP/2.0 %s\r\n", msg);
+	resp->len = strlen(dst);
 	resp->headers++;
 	return 0;
 }
@@ -5952,13 +5953,12 @@
 /*! \brief Initialize SIP request */
 static int init_req(struct sip_msg_out *req, int sipmethod, const char *recip)
 {
-	/* Initialize a request */
+	char *dst = req->data;
+
 	memset(req, 0, sizeof(*req));
         req->method = sipmethod;
-	req->header[0] = req->data;
-	snprintf(req->header[0], sizeof(req->data), "%s %s SIP/2.0\r\n", sip_methods[sipmethod].text, recip);
-	/* XXX no need to do a strlen, sprintf tells us what the size is */
-	req->len = strlen(req->header[0]);
+	snprintf(dst, sizeof(req->data) - 4, "%s %s SIP/2.0\r\n", sip_methods[sipmethod].text, recip);
+	req->len = strlen(dst);
 	req->headers++;
 	return 0;
 }



More information about the svn-commits mailing list