diff options
author | Luigi Rizzo <rizzo@icir.org> | 2006-05-11 10:22:18 +0000 |
---|---|---|
committer | Luigi Rizzo <rizzo@icir.org> | 2006-05-11 10:22:18 +0000 |
commit | 96478ea3a2075e5f26e2081ff920dbf72da8ae0c (patch) | |
tree | d8910824f2aa4fc1c55ee4ee1cc2481a5a3eda6e /channels | |
parent | 476c7a53e1dbec02011f6e7262007b794de6aee3 (diff) |
remove duplicated code in add_header
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@26846 65c4cc65-6c06-0410-ace0-fbb531ad65f3
Diffstat (limited to 'channels')
-rw-r--r-- | channels/chan_sip.c | 6 |
1 files changed, 4 insertions, 2 deletions
diff --git a/channels/chan_sip.c b/channels/chan_sip.c index 3994615d1..4e53bc888 100644 --- a/channels/chan_sip.c +++ b/channels/chan_sip.c @@ -4111,6 +4111,8 @@ static int process_sdp(struct sip_pvt *p, struct sip_request *req) /*! \brief Add header to SIP message */ static int add_header(struct sip_request *req, const char *var, const char *value) { + int maxlen = sizeof(req->data) - 4 - req->len; /* 4 bytes are for two \r\n ? */ + if (req->headers == SIP_MAX_HEADERS) { ast_log(LOG_WARNING, "Out of SIP header space\n"); return -1; @@ -4121,7 +4123,7 @@ static int add_header(struct sip_request *req, const char *var, const char *valu return -1; } - if (req->len >= sizeof(req->data) - 4) { + if (maxlen <= 0) { ast_log(LOG_WARNING, "Out of space, can't add anymore (%s:%s)\n", var, value); return -1; } @@ -4131,7 +4133,7 @@ static int add_header(struct sip_request *req, const char *var, const char *valu if (compactheaders) var = find_alias(var, var); - snprintf(req->header[req->headers], sizeof(req->data) - req->len - 4, "%s: %s\r\n", var, value); + snprintf(req->header[req->headers], maxlen, "%s: %s\r\n", var, value); req->len += strlen(req->header[req->headers]); req->headers++; |