diff -NaurbB old/chan_sip.c new/chan_sip.c --- old/chan_sip.c 2008-09-06 21:21:51.000000000 +0100 +++ new/chan_sip.c 2009-01-07 17:31:46.000000000 +0000 @@ -1542,7 +1542,8 @@ enum sip_transport transport; 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 */ @@ -6084,12 +6085,26 @@ char *username = NULL; char *hostname=NULL, *secret=NULL, *authuser=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. */ @@ -6108,12 +6123,7 @@ if (authuser) *authuser++ = '\0'; } - /* split host[:port][/contact] */ - callback = strchr(hostname, '/'); - if (callback) - *callback++ = '\0'; - if (ast_strlen_zero(callback)) - callback = "s"; + if (!(reg = ast_calloc(1, sizeof(*reg)))) { ast_log(LOG_ERROR, "Out of memory. Can't allocate SIP registry entry\n"); return -1; @@ -6138,9 +6148,26 @@ ast_string_field_set(reg, secret, secret); reg->transport = transport; reg->expire = -1; - reg->expiry = 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->refresh = reg->expiry; + reg->timeout = -1; - reg->refresh = default_expiry; reg->portno = portnum; reg->callid_valid = FALSE; reg->ocseq = INITIAL_CSEQ; @@ -9454,7 +9481,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(&req, "Event", "registration"); @@ -15110,7 +15137,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;