diff -NaurbB old/chan_sip.c new/chan_sip.c --- old/chan_sip.c 2009-01-12 11:52:16.000000000 +0000 +++ new/chan_sip.c 2009-01-12 11:49:21.000000000 +0000 @@ -1889,7 +1889,8 @@ enum sip_transport transport; /*!< Transport for this registration UDP, TCP or TLS */ int portno; /*!< Optional port override */ int expire; /*!< Sched ID of expiration */ - int expiry; /*!< Value to use for the Expires header */ + int expiryrequest; /*!< Value to use for the Expires header */ + int expiry; /*!< Value of Expires header accepted by registrar */ int regattempts; /*!< Number of attempts (since the last success) */ int timeout; /*!< sched id of sip_reg_timeout */ int refresh; /*!< How often to refresh */ @@ -6836,12 +6837,25 @@ char *port = NULL; char *hostname=NULL, *secret=NULL, *authuser=NULL, *expire=NULL; char *callback=NULL; + char *expiryrequest=NULL; if (!value) return -1; ast_copy_string(buf, value, sizeof(buf)); + /* split off [/contact][~expiry] before using sip_parse_host function */ + + expiryrequest = strrchr(buf, '~'); + if (expiryrequest) + *expiryrequest++ = '\0'; + + callback = strchr(buf, '/'); + if (callback) + *callback++ = '\0'; + if (ast_strlen_zero(callback)) + callback = "s"; + sip_parse_host(buf, lineno, &username, &portnum, &transport); /* First split around the last '@' then parse the two components. */ @@ -6861,15 +6875,6 @@ *authuser++ = '\0'; } - /* split host[:port][/contact] */ - expire = strchr(hostname, '~'); - if (expire) - *expire++ = '\0'; - callback = strchr(hostname, '/'); - if (callback) - *callback++ = '\0'; - if (ast_strlen_zero(callback)) - callback = "s"; /* Separate host from port when checking for reserved characters */ if ((port = strchr(hostname, ':'))) { @@ -6904,7 +6909,24 @@ ast_string_field_set(reg, secret, secret); reg->transport = transport; reg->expire = -1; - reg->expiry = (expire ? atoi(expire) : default_expiry); + + reg->expiryrequest = default_expiry; + if (expiryrequest) + reg->expiryrequest = atoi(expiryrequest); + if (reg->expiryrequest < 1) { + ast_log(LOG_WARNING, "Invalid expiry value. Setting to %d\n", default_expiry); + reg->expiryrequest = default_expiry; + } + if (reg->expiryrequest < min_expiry) { + ast_log(LOG_WARNING, "Expiry value less than minexpiry value. (To permit this expiry value set global minexpiry=%d in sip.conf.) Setting to %d\n", reg->expiryrequest, default_expiry); + reg->expiryrequest = default_expiry; + } + if (reg->expiryrequest > max_expiry) { + ast_log(LOG_WARNING, "Expiry value greater than maxexpiry value. (To permit this expiry value set global maxexpiry=%d in sip.conf.) Setting to %d\n", reg->expiryrequest, default_expiry); + reg->expiryrequest = default_expiry; + } + reg->expiry = reg->expiryrequest; + reg->timeout = -1; reg->refresh = reg->expiry; reg->portno = portnum; @@ -10680,7 +10702,7 @@ } - snprintf(tmp, sizeof(tmp), "%d", r->expiry); + snprintf(tmp, sizeof(tmp), "%d", r->expiryrequest); add_header(&req, "Expires", tmp); add_header(&req, "Contact", p->our_contact); add_header_contentLength(&req, 0); @@ -16661,7 +16683,7 @@ } if (r->expiry > max_expiry) { ast_log(LOG_WARNING, "Required expiration time from %s@%s is too high, giving up\n", p->registry->username, p->registry->hostname); - r->expiry = default_expiry; + r->expiry = r->expiryrequest; r->regstate = REG_STATE_REJECTED; } else { r->regstate = REG_STATE_UNREGISTERED;