diff -r -u asterisk-1.4.13/channels/chan_sip.c asterisk-1.4.13-sipprefix/channels/chan_sip.c --- asterisk-1.4.13/channels/chan_sip.c 2007-10-10 15:42:00.000000000 +0100 +++ asterisk-1.4.13-sipprefix/channels/chan_sip.c 2007-11-09 22:48:32.000000000 +0000 @@ -1485,7 +1485,7 @@ static int create_addr_from_peer(struct sip_pvt *r, struct sip_peer *peer); static int create_addr(struct sip_pvt *dialog, const char *opeer); static char *generate_random_string(char *buf, size_t size); -static void build_callid_pvt(struct sip_pvt *pvt); +static void build_callid_pvt(struct sip_pvt *pvt, const char *prefix); static void build_callid_registry(struct sip_registry *reg, struct in_addr ourip, const char *fromdomain); static void make_our_tag(char *tagbuf, size_t len); static int add_header(struct sip_request *req, const char *var, const char *value); @@ -2897,6 +2897,7 @@ struct varshead *headp; struct ast_var_t *current; const char *referer = NULL; /* SIP refererer */ + const char *callidprefix = NULL; p = ast->tech_pvt; if ((ast->_state != AST_STATE_DOWN) && (ast->_state != AST_STATE_RESERVED)) { @@ -2904,6 +2905,14 @@ return -1; } + callidprefix = pbx_builtin_getvar_helper(p->owner, "SIP_CALLID_PREFIX"); + if (callidprefix) { + /* Rebuild the callid with the prefix */ + ast_log(LOG_NOTICE, "Setting SIP Call-ID prefix to %s\n", callidprefix); + + build_callid_pvt(p, callidprefix); + } + /* Check whether there is vxml_url, distinctive ring variables */ headp=&ast->varshead; AST_LIST_TRAVERSE(headp,current,entries) { @@ -4304,13 +4313,16 @@ } /*! \brief Build SIP Call-ID value for a non-REGISTER transaction */ -static void build_callid_pvt(struct sip_pvt *pvt) +static void build_callid_pvt(struct sip_pvt *pvt, const char *prefix) { char buf[33]; const char *host = S_OR(pvt->fromdomain, ast_inet_ntoa(pvt->ourip)); - ast_string_field_build(pvt, callid, "%s@%s", generate_random_string(buf, sizeof(buf)), host); + if (prefix) + ast_string_field_build(pvt, callid, "%s-%s@%s", prefix, generate_random_string(buf, sizeof(buf)), host); + else + ast_string_field_build(pvt, callid, "%s@%s", generate_random_string(buf, sizeof(buf)), host); } @@ -4421,7 +4433,7 @@ ast_string_field_set(p, fromdomain, default_fromdomain); build_via(p); if (!callid) - build_callid_pvt(p); + build_callid_pvt(p, NULL); else ast_string_field_set(p, callid, callid); /* Assign default music on hold class */ @@ -11149,7 +11161,7 @@ if (ast_sip_ouraddrfor(&p->sa.sin_addr, &p->ourip)) p->ourip = __ourip; build_via(p); - build_callid_pvt(p); + build_callid_pvt(p, NULL); ast_cli(fd, "Sending NOTIFY of type '%s' to '%s'\n", argv[2], argv[i]); transmit_sip_request(p, &req); sip_scheddestroy(p, DEFAULT_TRANS_TIMEOUT); @@ -15234,7 +15246,7 @@ if (ast_sip_ouraddrfor(&p->sa.sin_addr, &p->ourip)) p->ourip = __ourip; build_via(p); - build_callid_pvt(p); + build_callid_pvt(p, NULL); /* Destroy this session after 32 secs */ sip_scheddestroy(p, DEFAULT_TRANS_TIMEOUT); } @@ -15516,7 +15528,7 @@ if (ast_sip_ouraddrfor(&p->sa.sin_addr, &p->ourip)) p->ourip = __ourip; build_via(p); - build_callid_pvt(p); + build_callid_pvt(p, NULL); if (peer->pokeexpire > -1) ast_sched_del(sched, peer->pokeexpire); @@ -15701,7 +15713,7 @@ if (ast_sip_ouraddrfor(&p->sa.sin_addr, &p->ourip)) p->ourip = __ourip; build_via(p); - build_callid_pvt(p); + build_callid_pvt(p, NULL); /* We have an extension to call, don't use the full contact here */ /* This to enable dialing registered peers with extension dialling,