diff --git a/channels/chan_sip.c b/channels/chan_sip.c index 9a18c2374342796ca6c32fa990b22c7405e9fcbe..58afb294e913be6db9ca9be5af032e5fbcbd4a1c 100755 --- a/channels/chan_sip.c +++ b/channels/chan_sip.c @@ -262,6 +262,7 @@ static struct sip_pvt { int canreinvite; /* Do we support reinvite */ int ringing; /* Have sent 180 ringing */ int progress; /* Have sent 183 message progress */ + int useclientcode; /* Trust X-ClientCode info message */ int tag; /* Another random number */ int nat; /* Whether to try to support NAT */ int sessionid; /* SDP Session ID */ @@ -392,6 +393,7 @@ struct sip_user { int outUse; int outgoinglimit; int promiscredir; + int useclientcode; int trustrpid; int progressinband; struct ast_ha *ha; @@ -436,6 +438,7 @@ struct sip_peer { int promiscredir; int dtmfmode; int trustrpid; + int useclientcode; int progressinband; struct sockaddr_in addr; struct in_addr mask; @@ -5295,6 +5298,7 @@ static int check_user_full(struct sip_pvt *p, struct sip_request *req, char *cmd p->ospauth = user->ospauth; #endif p->trustrpid = user->trustrpid; + p->useclientcode = user->useclientcode; p->progressinband = user->progressinband; /* replace callerid if rpid found, and not restricted */ if(!ast_strlen_zero(rpid_num) && p->trustrpid) { @@ -5373,6 +5377,7 @@ static int check_user_full(struct sip_pvt *p, struct sip_request *req, char *cmd /* Take the peer */ p->nat = peer->nat; p->trustrpid = peer->trustrpid; + p->useclientcode = peer->useclientcode; p->progressinband = peer->progressinband; /* replace callerid if rpid found, and not restricted */ if(!ast_strlen_zero(rpid_num) && p->trustrpid) { @@ -6061,6 +6066,18 @@ static void receive_info(struct sip_pvt *p, struct sip_request *req) p->needdestroy = 1; } return; + } else if ((c = get_header(req, "X-ClientCode"))) { + /* Client code (from SNOM phone) */ + if (p->useclientcode) { + if (p->owner && p->owner->cdr) + ast_cdr_setaccount(p->owner, c); + if (p->owner && ast_bridged_channel(p->owner) && ast_bridged_channel(p->owner)->cdr) + ast_cdr_setaccount(ast_bridged_channel(p->owner), c); + transmit_response(p, "200 OK", req); + } else { + transmit_response(p, "403 Unauthorized", req); + } + return; } /* Other type of INFO message, not really understood by Asterisk */ /* if (get_msg_text(buf, sizeof(buf), req)) { */ @@ -8170,6 +8187,8 @@ static struct sip_user *build_user(const char *name, struct ast_variable *v) user->callingpres = atoi(v->value); } else if (!strcasecmp(v->name, "trustrpid")) { user->trustrpid = ast_true(v->value); + } else if (!strcasecmp(v->name, "useclientcode")) { + user->useclientcode = ast_true(v->value); } else if (!strcasecmp(v->name, "progressinband")) { user->progressinband = ast_true(v->value); #ifdef OSP_SUPPORT @@ -8432,6 +8451,8 @@ static struct sip_peer *build_peer(const char *name, struct ast_variable *v, int ast_log(LOG_WARNING, "Qualification of peer '%s' should be 'yes', 'no', or a number of milliseconds at line %d of sip.conf\n", peer->name, v->lineno); peer->maxms = 0; } + } else if (!strcasecmp(v->name, "useclientcode")) { + peer->useclientcode = ast_true(v->value); } else if (!strcasecmp(v->name, "trustrpid")) { peer->trustrpid = ast_true(v->value); } else if (!strcasecmp(v->name, "progressinband")) { diff --git a/configs/sip.conf.sample b/configs/sip.conf.sample index de46d943923802dd8ab994a4017f141d440a0bfe..5ca5b78293339dcad8efd7902a5c47935c2f48a6 100755 --- a/configs/sip.conf.sample +++ b/configs/sip.conf.sample @@ -146,6 +146,7 @@ srvlookup=yes ; Enable DNS SRV lookups on outbound calls ; trustrpid trustrpid ; progressinband progressinband ; promiscredir promiscredir +; useclientcode useclientcode ; callerid ; accountcode ; amaflags