Add SIPUSERAGENT, SIPCALLID, and fix some formatting (bug #1593)

git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@2937 65c4cc65-6c06-0410-ace0-fbb531ad65f3
This commit is contained in:
Mark Spencer
2004-05-09 21:05:43 +00:00
parent 62eef7c695
commit 6ead43beb1
2 changed files with 120 additions and 79 deletions

View File

@@ -223,13 +223,13 @@ static struct sip_pvt {
char randdata[80]; /* Random data */ char randdata[80]; /* Random data */
unsigned int ocseq; /* Current outgoing seqno */ unsigned int ocseq; /* Current outgoing seqno */
unsigned int icseq; /* Current incoming seqno */ unsigned int icseq; /* Current incoming seqno */
unsigned int callgroup; unsigned int callgroup; /* Call group */
unsigned int pickupgroup; unsigned int pickupgroup; /* Pickup group */
int lastinvite; /* Last Cseq of invite */ int lastinvite; /* Last Cseq of invite */
int alreadygone; /* Whether or not we've already been destroyed by or peer */ int alreadygone; /* Whether or not we've already been destroyed by or peer */
int needdestroy; /* if we need to be destroyed */ int needdestroy; /* if we need to be destroyed */
int capability; /* Special capability */ int capability; /* Special capability (codec) */
int jointcapability; /* Supported capability at both ends */ int jointcapability; /* Supported capability at both ends (codecs ) */
int prefcodec; /* Preferred codec (outbound only) */ int prefcodec; /* Preferred codec (outbound only) */
int noncodeccapability; int noncodeccapability;
int outgoing; /* Outgoing or incoming call? */ int outgoing; /* Outgoing or incoming call? */
@@ -250,7 +250,7 @@ static struct sip_pvt {
struct sockaddr_in recv; /* Received as */ struct sockaddr_in recv; /* Received as */
struct in_addr ourip; /* Our IP */ struct in_addr ourip; /* Our IP */
struct ast_channel *owner; /* Who owns us */ struct ast_channel *owner; /* Who owns us */
char exten[AST_MAX_EXTENSION]; /* Extention where to start */ char exten[AST_MAX_EXTENSION]; /* Extension where to start */
char refer_to[AST_MAX_EXTENSION]; /* Place to store REFER-TO extension */ char refer_to[AST_MAX_EXTENSION]; /* Place to store REFER-TO extension */
char referred_by[AST_MAX_EXTENSION]; /* Place to store REFERRED-BY extension */ char referred_by[AST_MAX_EXTENSION]; /* Place to store REFERRED-BY extension */
char refer_contact[AST_MAX_EXTENSION]; /* Place to store Contact info from a REFER extension */ char refer_contact[AST_MAX_EXTENSION]; /* Place to store Contact info from a REFER extension */
@@ -258,12 +258,13 @@ static struct sip_pvt {
struct sip_route *route; /* Head of linked list of routing steps (fm Record-Route) */ struct sip_route *route; /* Head of linked list of routing steps (fm Record-Route) */
int route_persistant; /* Is this the "real" route? */ int route_persistant; /* Is this the "real" route? */
char remote_party_id[256]; char remote_party_id[256];
char from[256]; char from[256]; /* The From: header */
char context[AST_MAX_EXTENSION]; char useragent[256]; /* User agent in SIP request */
char context[AST_MAX_EXTENSION]; /* Context for this call */
char fromdomain[AST_MAX_EXTENSION]; /* Domain to show in the from field */ char fromdomain[AST_MAX_EXTENSION]; /* Domain to show in the from field */
char fromuser[AST_MAX_EXTENSION]; /* Domain to show in the user field */ char fromuser[AST_MAX_EXTENSION]; /* Domain to show in the user field */
char tohost[AST_MAX_EXTENSION]; /* Host we should put in the "to" field */ char tohost[AST_MAX_EXTENSION]; /* Host we should put in the "to" field */
char language[MAX_LANGUAGE]; char language[MAX_LANGUAGE]; /* Default language for this call */
char musicclass[MAX_LANGUAGE]; /* Music on Hold class */ char musicclass[MAX_LANGUAGE]; /* Music on Hold class */
char rdnis[256]; /* Referring DNIS */ char rdnis[256]; /* Referring DNIS */
char theirtag[256]; /* Their tag */ char theirtag[256]; /* Their tag */
@@ -306,7 +307,7 @@ static struct sip_pvt {
struct ast_rtp *rtp; /* RTP Session */ struct ast_rtp *rtp; /* RTP Session */
struct ast_rtp *vrtp; /* Video RTP session */ struct ast_rtp *vrtp; /* Video RTP session */
struct sip_pkt *packets; /* Packets scheduled for re-transmission */ struct sip_pkt *packets; /* Packets scheduled for re-transmission */
struct sip_pvt *next; struct sip_pvt *next; /* Next call in chain */
} *iflist = NULL; } *iflist = NULL;
#define FLAG_RESPONSE (1 << 0) #define FLAG_RESPONSE (1 << 0)
@@ -334,6 +335,7 @@ struct sip_user {
char accountcode[20]; char accountcode[20];
char language[MAX_LANGUAGE]; char language[MAX_LANGUAGE];
char musicclass[MAX_LANGUAGE]; /* Music on Hold class */ char musicclass[MAX_LANGUAGE]; /* Music on Hold class */
char useragent[256]; /* User agent in SIP request */
unsigned int callgroup; unsigned int callgroup;
unsigned int pickupgroup; unsigned int pickupgroup;
int nat; int nat;
@@ -365,6 +367,7 @@ struct sip_peer {
char mailbox[AST_MAX_EXTENSION]; char mailbox[AST_MAX_EXTENSION];
char language[MAX_LANGUAGE]; char language[MAX_LANGUAGE];
char musicclass[MAX_LANGUAGE]; /* Music on Hold class */ char musicclass[MAX_LANGUAGE]; /* Music on Hold class */
char useragent[256]; /* User agent in SIP request */
int lastmsgssent; int lastmsgssent;
time_t lastmsgcheck; time_t lastmsgcheck;
int dynamic; int dynamic;
@@ -1661,6 +1664,12 @@ static struct ast_channel *sip_new(struct sip_pvt *i, int state, char *title)
if (!ast_strlen_zero(i->domain)) { if (!ast_strlen_zero(i->domain)) {
pbx_builtin_setvar_helper(tmp, "SIPDOMAIN", i->domain); pbx_builtin_setvar_helper(tmp, "SIPDOMAIN", i->domain);
} }
if (!ast_strlen_zero(i->useragent)) {
pbx_builtin_setvar_helper(tmp, "SIPUSERAGENT", i->useragent);
}
if (!ast_strlen_zero(i->callid)) {
pbx_builtin_setvar_helper(tmp, "SIPCALLID", i->callid);
}
ast_setstate(tmp, state); ast_setstate(tmp, state);
if (state != AST_STATE_DOWN) { if (state != AST_STATE_DOWN) {
if (ast_pbx_start(tmp)) { if (ast_pbx_start(tmp)) {
@@ -3733,6 +3742,12 @@ static int parse_contact(struct sip_pvt *pvt, struct sip_peer *p, struct sip_req
if (option_verbose > 2) if (option_verbose > 2)
ast_verbose(VERBOSE_PREFIX_3 "Registered SIP '%s' at %s port %d expires %d\n", p->name, inet_ntoa(p->addr.sin_addr), ntohs(p->addr.sin_port), expiry); ast_verbose(VERBOSE_PREFIX_3 "Registered SIP '%s' at %s port %d expires %d\n", p->name, inet_ntoa(p->addr.sin_addr), ntohs(p->addr.sin_port), expiry);
} }
/* Save User agent */
strncpy(p->useragent, get_header(req, "User-Agent"),sizeof(p->useragent));
if (option_verbose > 2)
ast_verbose(VERBOSE_PREFIX_3 "Saved useragent \"%s\" for peer %s\n",p->useragent,p->name);
return 0; return 0;
} }
@@ -4856,6 +4871,7 @@ static int sip_show_peer(int fd, int argc, char *argv[])
else else
strcpy(status, "UNKNOWN"); strcpy(status, "UNKNOWN");
ast_cli(fd, "%s\n",status); ast_cli(fd, "%s\n",status);
ast_cli(fd, " Useragent : %s\n", peer->useragent);
ast_cli(fd,"\n"); ast_cli(fd,"\n");
} else { } else {
ast_cli(fd,"Peer %s not found.\n", argv[3]); ast_cli(fd,"Peer %s not found.\n", argv[3]);
@@ -4965,6 +4981,7 @@ static char *complete_sipch(char *line, char *word, int pos, int state)
return c; return c;
} }
/*--- sip_show_channel: Show details of one call ---*/
static int sip_show_channel(int fd, int argc, char *argv[]) static int sip_show_channel(int fd, int argc, char *argv[])
{ {
struct sip_pvt *cur; struct sip_pvt *cur;
@@ -4977,15 +4994,31 @@ static int sip_show_channel(int fd, int argc, char *argv[])
cur = iflist; cur = iflist;
while(cur) { while(cur) {
if (!strncasecmp(cur->callid, argv[3],len)) { if (!strncasecmp(cur->callid, argv[3],len)) {
ast_cli(fd,"\n");
if (cur->subscribed)
ast_cli(fd, " * Subscription\n");
else
ast_cli(fd, " * SIP Call\n");
ast_cli(fd, " Direction: %s\n", cur->outgoing?"Outgoing":"Incoming");
ast_cli(fd, " Call-ID: %s\n", cur->callid); ast_cli(fd, " Call-ID: %s\n", cur->callid);
ast_cli(fd, " Our Codec Capability: %d\n", cur->capability); ast_cli(fd, " Our Codec Capability: %d\n", cur->capability);
ast_cli(fd, " Non-Codec Capability: %d\n", cur->noncodeccapability); ast_cli(fd, " Non-Codec Capability: %d\n", cur->noncodeccapability);
ast_cli(fd, " Joint Codec Capability: %d\n", cur->jointcapability); ast_cli(fd, " Joint Codec Capability: %d\n", cur->jointcapability);
ast_cli(fd, " Format %s\n", ast_getformatname(cur->owner ? cur->owner->nativeformats : 0) );
ast_cli(fd, " Theoretical Address: %s:%d\n", inet_ntoa(cur->sa.sin_addr), ntohs(cur->sa.sin_port)); ast_cli(fd, " Theoretical Address: %s:%d\n", inet_ntoa(cur->sa.sin_addr), ntohs(cur->sa.sin_port));
ast_cli(fd, " Received Address: %s:%d\n", inet_ntoa(cur->recv.sin_addr), ntohs(cur->recv.sin_port)); ast_cli(fd, " Received Address: %s:%d\n", inet_ntoa(cur->recv.sin_addr), ntohs(cur->recv.sin_port));
ast_cli(fd, " NAT Support: %s\n", cur->nat ? "Yes" : "No"); ast_cli(fd, " NAT Support: %s\n", cur->nat ? "Yes" : "No");
ast_cli(fd, " Our Tag: %08d\n", cur->tag); ast_cli(fd, " Our Tag: %08d\n", cur->tag);
ast_cli(fd, " Their Tag: %s\n", cur->theirtag); ast_cli(fd, " Their Tag: %s\n", cur->theirtag);
ast_cli(fd, " SIP User agent: %s\n", cur->useragent);
if (!ast_strlen_zero(cur->username))
ast_cli(fd, " Username: %s\n", cur->username);
if (!ast_strlen_zero(cur->peername))
ast_cli(fd, " Peername: %s\n", cur->peername);
if (!ast_strlen_zero(cur->uri))
ast_cli(fd, " Original uri: %s\n", cur->uri);
if (!ast_strlen_zero(cur->callerid))
ast_cli(fd, " Caller-ID: %s\n", cur->callerid);
ast_cli(fd, " Need Destroy: %d\n", cur->needdestroy); ast_cli(fd, " Need Destroy: %d\n", cur->needdestroy);
ast_cli(fd, " Last Message: %s\n", cur->lastmsg); ast_cli(fd, " Last Message: %s\n", cur->lastmsg);
ast_cli(fd, " Route: %s\n", cur->route ? cur->route->hop : "N/A"); ast_cli(fd, " Route: %s\n", cur->route ? cur->route->hop : "N/A");
@@ -5796,6 +5829,7 @@ static int handle_request(struct sip_pvt *p, struct sip_request *req, struct soc
char *cseq; char *cseq;
char *from; char *from;
char *e; char *e;
char *useragent;
struct ast_channel *c=NULL; struct ast_channel *c=NULL;
struct ast_channel *transfer_to; struct ast_channel *transfer_to;
int seqno; int seqno;
@@ -5827,6 +5861,11 @@ static int handle_request(struct sip_pvt *p, struct sip_request *req, struct soc
cmd= req->rlPart1; cmd= req->rlPart1;
e= req->rlPart2; e= req->rlPart2;
/* Save useragent of the client */
useragent = get_header(req, "User-Agent");
strncpy(p->useragent, useragent, sizeof(p->useragent)-1);
if (strcasecmp(cmd, "SIP/2.0")) { if (strcasecmp(cmd, "SIP/2.0")) {
/* Request coming in */ /* Request coming in */
if (p->icseq && (p->icseq < seqno)) { if (p->icseq && (p->icseq < seqno)) {

View File

@@ -67,6 +67,8 @@ ${HANGUPCAUSE} Asterisk hangup cause
${ACCOUNTCODE} Account code (if specified) ${ACCOUNTCODE} Account code (if specified)
${LANGUAGE} Current language ${LANGUAGE} Current language
${SIPDOMAIN} SIP destination domain of an inbound call (if appropriate) ${SIPDOMAIN} SIP destination domain of an inbound call (if appropriate)
${SIPUSERAGENT} SIP user agent
${SIPCALLID} SIP Call-ID: header verbatim (for logging or CDR matching)
There are two reference modes - reference by value and reference by name. There are two reference modes - reference by value and reference by name.
To refer to a variable with its name (as an argument to a function that To refer to a variable with its name (as an argument to a function that