[asterisk-commits] russell: branch group/sip_session_timers r84369 - /team/group/sip_session_tim...
SVN commits to the Asterisk project
asterisk-commits at lists.digium.com
Tue Oct 2 09:06:08 CDT 2007
Author: russell
Date: Tue Oct 2 09:06:07 2007
New Revision: 84369
URL: http://svn.digium.com/view/asterisk?view=rev&rev=84369
Log:
Simplify some code. sprintf/snprintf guarantee the string to be terminated so
there is no need to do it explicitly afterwards. Also, fix more spaces to tabs.
Modified:
team/group/sip_session_timers/channels/chan_sip.c
Modified: team/group/sip_session_timers/channels/chan_sip.c
URL: http://svn.digium.com/view/asterisk/team/group/sip_session_timers/channels/chan_sip.c?view=diff&rev=84369&r1=84368&r2=84369
==============================================================================
--- team/group/sip_session_timers/channels/chan_sip.c (original)
+++ team/group/sip_session_timers/channels/chan_sip.c Tue Oct 2 09:06:07 2007
@@ -6572,9 +6572,8 @@
/* Add Session-Timers related headers if the feature is active for this session */
if (p->st_active == TRUE && p->st_active_peer_ua == TRUE) {
char se_hdr[256];
- int se_len = 0;
- se_len = sprintf(&se_hdr[se_len], "%d;refresher=%s", p->st_interval, strefresher2str(p->st_ref));
- se_hdr[se_len] = '\0';
+ snprintf(se_hdr, sizeof(se_hdr), "%d;refresher=%s", p->st_interval,
+ strefresher2str(p->st_ref));
add_header(resp, "Require", "timer");
add_header(resp, "Session-Expires", se_hdr);
}
@@ -6713,14 +6712,11 @@
/* Add Session-Timers related headers if the feature is active for this session */
if (p->st_active == TRUE && p->st_active_peer_ua == TRUE) {
char se_hdr[256];
- int se_len = 0;
- se_len = sprintf(&se_hdr[se_len], "%d;refresher=%s", p->st_interval, strefresher2str(p->st_ref));
- se_hdr[se_len] = '\0';
+ snprintf(se_hdr, sizeof(se_hdr), "%d;refresher=%s", p->st_interval,
+ strefresher2str(p->st_ref));
add_header(req, "Require", "timer");
add_header(req, "Session-Expires", se_hdr);
- se_len = 0;
- se_len = sprintf(&se_hdr[se_len], "%d", st_get_min_se(p));
- se_hdr[se_len] = '\0';
+ snprintf(se_hdr, sizeof(se_hdr), "%d", st_get_min_se(p));
add_header(req, "Min-SE", se_hdr);
}
@@ -6840,16 +6836,12 @@
{
struct sip_request resp;
char minse_str[20];
- int minse_str_len;
respprep(&resp, p, msg, req);
append_date(&resp);
- minse_str_len = sprintf(&minse_str[0], "%d", minse_int);
- if (minse_str_len) {
- minse_str[minse_str_len] = '\0';
- add_header(&resp, "Min-SE", &minse_str[0]);
- }
+ snprintf(minse_str, sizeof(minse_str), "%d", minse_int);
+ add_header(&resp, "Min-SE", minse_str);
add_header_contentLength(&resp, 0);
return send_response(p, &resp, XMIT_UNRELIABLE, 0);
@@ -7931,7 +7923,7 @@
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)) {
- sprintf(buf, "%s <%s>", p->refer->referred_by_name, p->refer->referred_by);
+ snprintf(buf, sizeof(buf), "%s <%s>", p->refer->referred_by_name, p->refer->referred_by);
add_header(&req, "Referred-By", buf);
}
}
@@ -7946,21 +7938,16 @@
/* Add Session-Timers related headers */
if (st_get_mode(p) == SESSION_TIMER_MODE_ORIGINATE) {
char i2astr[10];
- int i2aidx;
-
- if (!p->st_interval) {
+
+ if (!p->st_interval)
p->st_interval = st_get_max_se(p);
- }
p->st_active = TRUE;
- i2aidx = sprintf(&i2astr[0], "%d", p->st_interval);
- i2astr[i2aidx] = '\0';
+ snprintf(i2astr, sizeof(i2astr), "%d", p->st_interval);
add_header(&req, "Session-Expires", i2astr);
- i2aidx = 0;
- i2aidx = sprintf(&i2astr[0], "%d", st_get_min_se(p));
- i2astr[i2aidx] = '\0';
+ snprintf(i2astr, sizeof(i2astr), "%d", st_get_min_se(p));
add_header(&req, "Min-SE", i2astr);
}
More information about the asterisk-commits
mailing list