[svn-commits] branch kpfleming/stringfields - r7766 in
/team/kpfleming/stringfields: ./ cha...
svn-commits at lists.digium.com
svn-commits at lists.digium.com
Tue Jan 3 22:11:43 CST 2006
Author: kpfleming
Date: Tue Jan 3 22:11:42 2006
New Revision: 7766
URL: http://svn.digium.com/view/asterisk?rev=7766&view=rev
Log:
convert remaining sip_pvt buffers to string fields
add 'const' qualifiers to a few API calls
Modified:
team/kpfleming/stringfields/channels/chan_sip.c
team/kpfleming/stringfields/include/asterisk/pbx.h
team/kpfleming/stringfields/include/asterisk/stringfields.h
team/kpfleming/stringfields/include/asterisk/utils.h
team/kpfleming/stringfields/pbx.c
team/kpfleming/stringfields/utils.c
Modified: team/kpfleming/stringfields/channels/chan_sip.c
URL: http://svn.digium.com/view/asterisk/team/kpfleming/stringfields/channels/chan_sip.c?rev=7766&r1=7765&r2=7766&view=diff
==============================================================================
--- team/kpfleming/stringfields/channels/chan_sip.c (original)
+++ team/kpfleming/stringfields/channels/chan_sip.c Tue Jan 3 22:11:42 2006
@@ -606,6 +606,36 @@
AST_STRING_FIELD(opaque); /*!< Opaque nonsense */
AST_STRING_FIELD(qop); /*!< Quality of Protection, since SIP wasn't complicated enough yet. */
AST_STRING_FIELD(domain); /*!< Authorization domain */
+ AST_STRING_FIELD(refer_to); /*!< Place to store REFER-TO extension */
+ AST_STRING_FIELD(referred_by); /*!< Place to store REFERRED-BY extension */
+ AST_STRING_FIELD(refer_contact);/*!< Place to store Contact info from a REFER extension */
+ AST_STRING_FIELD(from); /*!< The From: header */
+ AST_STRING_FIELD(useragent); /*!< User agent in SIP request */
+ AST_STRING_FIELD(exten); /*!< Extension where to start */
+ AST_STRING_FIELD(context); /*!< Context for this call */
+ AST_STRING_FIELD(subscribecontext); /*!< Subscribecontext */
+ AST_STRING_FIELD(fromdomain); /*!< Domain to show in the from field */
+ AST_STRING_FIELD(fromuser); /*!< User to show in the user field */
+ AST_STRING_FIELD(fromname); /*!< Name to show in the user field */
+ AST_STRING_FIELD(tohost); /*!< Host we should put in the "to" field */
+ AST_STRING_FIELD(language); /*!< Default language for this call */
+ AST_STRING_FIELD(musicclass); /*!< Music on Hold class */
+ AST_STRING_FIELD(rdnis); /*!< Referring DNIS */
+ AST_STRING_FIELD(theirtag); /*!< Their tag */
+ AST_STRING_FIELD(username); /*!< [user] name */
+ AST_STRING_FIELD(peername); /*!< [peer] name, not set if [user] */
+ AST_STRING_FIELD(authname); /*!< Who we use for authentication */
+ AST_STRING_FIELD(uri); /*!< Original requested URI */
+ AST_STRING_FIELD(okcontacturi); /*!< URI from the 200 OK on INVITE */
+ AST_STRING_FIELD(peersecret); /*!< Password */
+ AST_STRING_FIELD(peermd5secret);
+ AST_STRING_FIELD(cid_num); /*!< Caller*ID */
+ AST_STRING_FIELD(cid_name); /*!< Caller*ID */
+ AST_STRING_FIELD(via); /*!< Via: header */
+ AST_STRING_FIELD(fullcontact); /*!< The Contact: that the UA registers with us */
+ AST_STRING_FIELD(our_contact); /*!< Our contact header */
+ AST_STRING_FIELD(rpid); /*!< Our RPID header */
+ AST_STRING_FIELD(rpid_from); /*!< Our RPID From header */
);
struct ast_codec_pref prefs; /*!< codec prefs */
unsigned int ocseq; /*!< Current outgoing seqno */
@@ -635,40 +665,10 @@
struct sockaddr_in recv; /*!< Received as */
struct in_addr ourip; /*!< Our IP */
struct ast_channel *owner; /*!< Who owns us */
- char exten[AST_MAX_EXTENSION]; /*!< Extension where to start */
- 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 refer_contact[AST_MAX_EXTENSION]; /*!< Place to store Contact info from a REFER extension */
struct sip_pvt *refer_call; /*!< Call we are referring */
struct sip_route *route; /*!< Head of linked list of routing steps (fm Record-Route) */
int route_persistant; /*!< Is this the "real" route? */
- char from[256]; /*!< The From: header */
- char useragent[256]; /*!< User agent in SIP request */
- char context[AST_MAX_CONTEXT]; /*!< Context for this call */
- char subscribecontext[AST_MAX_CONTEXT]; /*!< Subscribecontext */
- char fromdomain[MAXHOSTNAMELEN]; /*!< Domain to show in the from field */
- char fromuser[AST_MAX_EXTENSION]; /*!< User to show in the user field */
- char fromname[AST_MAX_EXTENSION]; /*!< Name to show in the user field */
- char tohost[MAXHOSTNAMELEN]; /*!< Host we should put in the "to" field */
- char language[MAX_LANGUAGE]; /*!< Default language for this call */
- char musicclass[MAX_MUSICCLASS]; /*!< Music on Hold class */
- char rdnis[256]; /*!< Referring DNIS */
- char theirtag[256]; /*!< Their tag */
- char username[256]; /*!< [user] name */
- char peername[256]; /*!< [peer] name, not set if [user] */
- char authname[256]; /*!< Who we use for authentication */
- char uri[256]; /*!< Original requested URI */
- char okcontacturi[256]; /*!< URI from the 200 OK on INVITE */
- char peersecret[256]; /*!< Password */
- char peermd5secret[256];
struct sip_auth *peerauth; /*!< Realm authentication */
- char cid_num[256]; /*!< Caller*ID */
- char cid_name[256]; /*!< Caller*ID */
- char via[256]; /*!< Via: header */
- char fullcontact[128]; /*!< The Contact: that the UA registers with us */
- char our_contact[256]; /*!< Our contact header */
- char *rpid; /*!< Our RPID header */
- char *rpid_from; /*!< Our RPID From header */
int noncecount; /*!< Nonce-count */
char lastmsg[256]; /*!< Last Message sent/received */
int amaflags; /*!< AMA Flags */
@@ -1086,15 +1086,15 @@
static void sip_destroy(struct sip_pvt *p);
/*! \brief build_via: Build a Via header for a request ---*/
-static void build_via(struct sip_pvt *p, char *buf, int len)
+static void build_via(struct sip_pvt *p)
{
char iabuf[INET_ADDRSTRLEN];
/* Work around buggy UNIDEN UIP200 firmware */
- const char *rport= ast_test_flag(p, SIP_NAT) & SIP_NAT_RFC3581 ? ";rport" : "";
+ const char *rport = ast_test_flag(p, SIP_NAT) & SIP_NAT_RFC3581 ? ";rport" : "";
/* z9hG4bK is a magic cookie. See RFC 3261 section 8.1.1.7 */
- snprintf(buf, len, "SIP/2.0/UDP %s:%d;branch=z9hG4bK%08x%s",
- ast_inet_ntoa(iabuf, sizeof(iabuf), p->ourip), ourport, p->branch, rport);
+ ast_string_field_build(p, via, "SIP/2.0/UDP %s:%d;branch=z9hG4bK%08x%s",
+ ast_inet_ntoa(iabuf, sizeof(iabuf), p->ourip), ourport, p->branch, rport);
}
/*! \brief ast_sip_ouraddrfor: NAT fix - decide which IP address to use for ASterisk server? ---*/
@@ -1859,28 +1859,31 @@
ast_log(LOG_DEBUG, "Setting NAT on VRTP to %d\n", (ast_test_flag(r, SIP_NAT) & SIP_NAT_ROUTE));
ast_rtp_setnat(r->vrtp, (ast_test_flag(r, SIP_NAT) & SIP_NAT_ROUTE));
}
- ast_copy_string(r->peername, peer->username, sizeof(r->peername));
- ast_copy_string(r->authname, peer->username, sizeof(r->authname));
- ast_copy_string(r->username, peer->username, sizeof(r->username));
- ast_copy_string(r->peersecret, peer->secret, sizeof(r->peersecret));
- ast_copy_string(r->peermd5secret, peer->md5secret, sizeof(r->peermd5secret));
- ast_copy_string(r->tohost, peer->tohost, sizeof(r->tohost));
- ast_copy_string(r->fullcontact, peer->fullcontact, sizeof(r->fullcontact));
+ ast_string_field_set(r, peername, peer->username);
+ ast_string_field_set(r, authname, peer->username);
+ ast_string_field_set(r, username, peer->username);
+ ast_string_field_set(r, peersecret, peer->secret);
+ ast_string_field_set(r, peermd5secret, peer->md5secret);
+ ast_string_field_set(r, tohost, peer->tohost);
+ ast_string_field_set(r, fullcontact, peer->fullcontact);
if (!r->initreq.headers && !ast_strlen_zero(peer->fromdomain)) {
if ((callhost = strchr(r->callid, '@'))) {
strncpy(callhost + 1, peer->fromdomain, sizeof(r->callid) - (callhost - r->callid) - 2);
}
}
if (ast_strlen_zero(r->tohost)) {
+ char iabuf[INET_ADDRSTRLEN];
+
if (peer->addr.sin_addr.s_addr)
- ast_inet_ntoa(r->tohost, sizeof(r->tohost), peer->addr.sin_addr);
+ ast_inet_ntoa(iabuf, sizeof(iabuf), peer->addr.sin_addr);
else
- ast_inet_ntoa(r->tohost, sizeof(r->tohost), peer->defaddr.sin_addr);
+ ast_inet_ntoa(iabuf, sizeof(iabuf), peer->defaddr.sin_addr);
+ ast_string_field_set(r, tohost, iabuf);
}
if (!ast_strlen_zero(peer->fromdomain))
- ast_copy_string(r->fromdomain, peer->fromdomain, sizeof(r->fromdomain));
+ ast_string_field_set(r, fromdomain, peer->fromdomain);
if (!ast_strlen_zero(peer->fromuser))
- ast_copy_string(r->fromuser, peer->fromuser, sizeof(r->fromuser));
+ ast_string_field_set(r, fromuser, peer->fromuser);
r->maxtime = peer->maxms;
r->callgroup = peer->callgroup;
r->pickupgroup = peer->pickupgroup;
@@ -1891,7 +1894,7 @@
r->noncodeccapability |= AST_RTP_DTMF;
else
r->noncodeccapability &= ~AST_RTP_DTMF;
- ast_copy_string(r->context, peer->context,sizeof(r->context));
+ ast_string_field_set(r, context, peer->context);
r->rtptimeout = peer->rtptimeout;
r->rtpholdtimeout = peer->rtpholdtimeout;
r->rtpkeepalive = peer->rtpkeepalive;
@@ -1952,7 +1955,7 @@
}
hp = ast_gethostbyname(hostn, &ahp);
if (hp) {
- ast_copy_string(dialog->tohost, peer, sizeof(dialog->tohost));
+ ast_string_field_set(dialog, tohost, peer);
memcpy(&dialog->sa.sin_addr, hp->h_addr, sizeof(dialog->sa.sin_addr));
dialog->sa.sin_port = htons(portno);
memcpy(&dialog->recv, &dialog->sa, sizeof(dialog->recv));
@@ -2117,12 +2120,6 @@
p->registry->call = NULL;
ASTOBJ_UNREF(p->registry,sip_registry_destroy);
}
-
- if (p->rpid)
- free(p->rpid);
-
- if (p->rpid_from)
- free(p->rpid_from);
/* Unlink us from the owner if we have one */
if (p->owner) {
@@ -2712,7 +2709,7 @@
/*! \brief sip_new: Initiate a call in the SIP channel */
/* called from sip_request_call (calls from the pbx ) */
-static struct ast_channel *sip_new(struct sip_pvt *i, int state, char *title)
+static struct ast_channel *sip_new(struct sip_pvt *i, int state, const char *title)
{
struct ast_channel *tmp;
struct ast_variable *v = NULL;
@@ -3110,19 +3107,19 @@
}
if (p->method != SIP_REGISTER)
- ast_copy_string(p->fromdomain, default_fromdomain, sizeof(p->fromdomain));
- build_via(p, p->via, sizeof(p->via));
+ ast_string_field_set(p, fromdomain, default_fromdomain);
+ build_via(p);
if (!callid)
build_callid_pvt(p);
else
ast_string_field_set(p, callid, callid);
ast_copy_flags(p, &global_flags, SIP_FLAGS_TO_COPY);
/* Assign default music on hold class */
- strcpy(p->musicclass, global_musicclass);
+ ast_string_field_set(p, musicclass, global_musicclass);
p->capability = global_capability;
if ((ast_test_flag(p, SIP_DTMF) == SIP_DTMF_RFC2833) || (ast_test_flag(p, SIP_DTMF) == SIP_DTMF_AUTO))
p->noncodeccapability |= AST_RTP_DTMF;
- strcpy(p->context, default_context);
+ ast_string_field_set(p, context, default_context);
/* Add to active dialog list */
ast_mutex_lock(&iflock);
@@ -3979,7 +3976,7 @@
}
/*! \brief init_req: Initialize SIP request ---*/
-static int init_req(struct sip_request *req, int sipmethod, char *recip)
+static int init_req(struct sip_request *req, int sipmethod, const char *recip)
{
/* Initialize a response */
if (req->headers || req->len) {
@@ -4050,7 +4047,8 @@
char stripped[80];
char tmp[80];
char newto[256];
- char *c, *n;
+ const char *c;
+ char *n;
char *ot, *of;
int is_strict = 0; /* Strict routing flag */
@@ -4065,7 +4063,7 @@
if (newbranch) {
p->branch ^= thread_safe_rand();
- build_via(p, p->via, sizeof(p->via));
+ build_via(p);
}
/* Check for strict or loose router */
@@ -4087,8 +4085,8 @@
c = p->uri;
} else {
/* We have no URI, use To: or From: header as URI (depending on direction) */
- c = get_header(orig, (ast_test_flag(p, SIP_OUTGOING)) ? "To" : "From");
- ast_copy_string(stripped, c, sizeof(stripped));
+ ast_copy_string(stripped, get_header(orig, (ast_test_flag(p, SIP_OUTGOING)) ? "To" : "From"),
+ sizeof(stripped));
c = get_in_brackets(stripped);
n = strchr(c, ';');
if (n)
@@ -4637,7 +4635,7 @@
if (n)
*n = '\0';
if (!ast_strlen_zero(c))
- ast_copy_string(p->uri, c, sizeof(p->uri));
+ ast_string_field_set(p, uri, c);
}
/*! \brief build_contact: Build contact header - the contact header we send out ---*/
@@ -4647,9 +4645,9 @@
/* Construct Contact: header */
if (ourport != 5060) /* Needs to be 5060, according to the RFC */
- snprintf(p->our_contact, sizeof(p->our_contact), "<sip:%s%s%s:%d>", p->exten, ast_strlen_zero(p->exten) ? "" : "@", ast_inet_ntoa(iabuf, sizeof(iabuf), p->ourip), ourport);
+ ast_string_field_build(p, our_contact, "<sip:%s%s%s:%d>", p->exten, ast_strlen_zero(p->exten) ? "" : "@", ast_inet_ntoa(iabuf, sizeof(iabuf), p->ourip), ourport);
else
- snprintf(p->our_contact, sizeof(p->our_contact), "<sip:%s%s%s>", p->exten, ast_strlen_zero(p->exten) ? "" : "@", ast_inet_ntoa(iabuf, sizeof(iabuf), p->ourip));
+ ast_string_field_build(p, our_contact, "<sip:%s%s%s>", p->exten, ast_strlen_zero(p->exten) ? "" : "@", ast_inet_ntoa(iabuf, sizeof(iabuf), p->ourip));
}
/*! \brief build_rpid: Build the Remote Party-ID & From using callingpres options ---*/
@@ -4725,12 +4723,11 @@
snprintf(buf, sizeof(buf), "\"%s\" <sip:%s@%s>", clin, clid, fromdomain);
if (send_pres_tags)
snprintf(buf + strlen(buf), sizeof(buf) - strlen(buf), ";privacy=%s;screen=%s", privacy, screen);
- p->rpid = strdup(buf);
-
- snprintf(buf, sizeof(buf), "\"%s\" <sip:%s@%s>;tag=%s", clin,
- ast_strlen_zero(p->fromuser) ? clid : p->fromuser,
- fromdomain, p->tag);
- p->rpid_from = strdup(buf);
+ ast_string_field_set(p, rpid, buf);
+
+ ast_string_field_build(p, rpid_from, "\"%s\" <sip:%s@%s>;tag=%s", clin,
+ ast_strlen_zero(p->fromuser) ? clid : p->fromuser,
+ fromdomain, p->tag);
}
/*! \brief initreqprep: Initiate new SIP request to peer/user ---*/
@@ -4744,7 +4741,7 @@
char tmp[BUFSIZ/2];
char tmp2[BUFSIZ/2];
char iabuf[INET_ADDRSTRLEN];
- char *l = NULL, *n = NULL;
+ const char *l = NULL, *n = NULL;
int x;
char urioptions[256]="";
@@ -4792,13 +4789,13 @@
if (!ast_strlen_zero(p->fromuser))
l = p->fromuser;
else /* Save for any further attempts */
- ast_copy_string(p->fromuser, l, sizeof(p->fromuser));
+ ast_string_field_set(p, fromuser, l);
/* Allow user to be overridden */
if (!ast_strlen_zero(p->fromname))
n = p->fromname;
else /* Save for any further attempts */
- ast_copy_string(p->fromname, n, sizeof(p->fromname));
+ ast_string_field_set(p, fromname, n);
if (pedanticsipchecking) {
ast_uri_encode(n, tmp, sizeof(tmp), 0);
@@ -4836,8 +4833,8 @@
/* If custom URI options have been provided, append them */
if (p->options && p->options->uri_options)
ast_build_string(&invite, &invite_max, ";%s", p->options->uri_options);
-
- ast_copy_string(p->uri, invite_buf, sizeof(p->uri));
+
+ ast_string_field_set(p, uri, invite_buf);
/* If there is a VXML URL append it to the SIP URL */
if (p->options && p->options->vxml_url) {
@@ -4860,7 +4857,7 @@
add_header(req, "From", from);
}
add_header(req, "To", to);
- ast_copy_string(p->exten, l, sizeof(p->exten));
+ ast_string_field_set(p, exten, l);
build_contact(p);
add_header(req, "Contact", p->our_contact);
add_header(req, "Call-ID", p->callid);
@@ -4880,7 +4877,7 @@
if (init) {
/* Bump branch even on initial requests */
p->branch ^= thread_safe_rand();
- build_via(p, p->via, sizeof(p->via));
+ build_via(p);
if (init > 1)
initreqprep(&req, p, sipmethod);
else
@@ -5326,7 +5323,6 @@
char from[256];
char to[256];
char tmp[80];
- char via[80];
char addr[80];
struct sip_pvt *p;
@@ -5343,7 +5339,7 @@
} else {
p = r->call;
make_our_tag(p->tag, sizeof(p->tag)); /* create a new local tag for every register attempt */
- p->theirtag[0]='\0'; /* forget their old tag, so we don't match tags when getting response */
+ ast_string_field_free(p, theirtag); /* forget their old tag, so we don't match tags when getting response */
}
} else {
/* Build callid for registration if we haven't registered before */
@@ -5383,25 +5379,25 @@
r->call=p; /* Save pointer to SIP packet */
p->registry=ASTOBJ_REF(r); /* Add pointer to registry in packet */
if (!ast_strlen_zero(r->secret)) /* Secret (password) */
- ast_copy_string(p->peersecret, r->secret, sizeof(p->peersecret));
+ ast_string_field_set(p, peersecret, r->secret);
if (!ast_strlen_zero(r->md5secret))
- ast_copy_string(p->peermd5secret, r->md5secret, sizeof(p->peermd5secret));
+ ast_string_field_set(p, peermd5secret, r->md5secret);
/* User name in this realm
- if authuser is set, use that, otherwise use username */
if (!ast_strlen_zero(r->authuser)) {
- ast_copy_string(p->peername, r->authuser, sizeof(p->peername));
- ast_copy_string(p->authname, r->authuser, sizeof(p->authname));
+ ast_string_field_set(p, peername, r->authuser);
+ ast_string_field_set(p, authname, r->authuser);
} else {
if (!ast_strlen_zero(r->username)) {
- ast_copy_string(p->peername, r->username, sizeof(p->peername));
- ast_copy_string(p->authname, r->username, sizeof(p->authname));
- ast_copy_string(p->fromuser, r->username, sizeof(p->fromuser));
+ ast_string_field_set(p, peername, r->username);
+ ast_string_field_set(p, authname, r->username);
+ ast_string_field_set(p, fromuser, r->username);
}
}
if (!ast_strlen_zero(r->username))
- ast_copy_string(p->username, r->username, sizeof(p->username));
+ ast_string_field_set(p, username, r->username);
/* Save extension in packet */
- ast_copy_string(p->exten, r->contact, sizeof(p->exten));
+ ast_string_field_set(p, exten, r->contact);
/*
check which address we should use in our contact header
@@ -5443,7 +5439,7 @@
snprintf(addr, sizeof(addr), "sip:%s", p->fromdomain);
else
snprintf(addr, sizeof(addr), "sip:%s", r->hostname);
- ast_copy_string(p->uri, addr, sizeof(p->uri));
+ ast_string_field_set(p, uri, addr);
p->branch ^= thread_safe_rand();
@@ -5454,8 +5450,8 @@
snprintf(tmp, sizeof(tmp), "%u %s", ++r->ocseq, sip_methods[sipmethod].text);
p->ocseq = r->ocseq;
- build_via(p, via, sizeof(via));
- add_header(&req, "Via", via);
+ build_via(p);
+ add_header(&req, "Via", p->via);
add_header(&req, "From", from);
add_header(&req, "To", to);
add_header(&req, "Call-ID", p->callid);
@@ -5529,7 +5525,7 @@
of = get_header(&p->initreq, "From");
ast_copy_string(from, of, sizeof(from));
of = get_in_brackets(from);
- ast_copy_string(p->from,of,sizeof(p->from));
+ ast_string_field_set(p, from, of);
if (strncmp(of, "sip:", 4)) {
ast_log(LOG_NOTICE, "From address missing 'sip:', using it anyway\n");
} else
@@ -5548,8 +5544,8 @@
}
/* save in case we get 407 challenge */
- ast_copy_string(p->refer_to, referto, sizeof(p->refer_to));
- ast_copy_string(p->referred_by, p->our_contact, sizeof(p->referred_by));
+ ast_string_field_set(p, refer_to, referto);
+ ast_string_field_set(p, referred_by, p->our_contact);
reqprep(&req, p, SIP_REFER, 0, 1);
add_header(&req, "Refer-To", referto);
@@ -5739,10 +5735,10 @@
c = get_in_brackets(contact);
/* Save full contact to call pvt for later bye or re-invite */
- ast_copy_string(pvt->fullcontact, c, sizeof(pvt->fullcontact));
+ ast_string_field_set(pvt, fullcontact, c);
/* Save URI for later ACKs, BYE or RE-invites */
- ast_copy_string(pvt->okcontacturi, c, sizeof(pvt->okcontacturi));
+ ast_string_field_set(pvt, okcontacturi, c);
/* Make sure it's a SIP URL */
if (strncasecmp(c, "sip:", 4)) {
@@ -5871,7 +5867,7 @@
}
ast_copy_string(p->fullcontact, c, sizeof(p->fullcontact));
/* For the 200 OK, we should use the received contact */
- snprintf(pvt->our_contact, sizeof(pvt->our_contact) - 1, "<%s>", c);
+ ast_string_field_build(pvt, our_contact, "<%s>", c);
/* Make sure it's a SIP URL */
if (strncasecmp(c, "sip:", 4)) {
ast_log(LOG_NOTICE, "'%s' is not a valid SIP contact (missing sip:) trying to use anyway\n", c);
@@ -6099,7 +6095,9 @@
/*! \brief check_auth: Check user authorization from peer definition ---*/
/* Some actions, like REGISTER and INVITEs from peers require
authentication (if peer have secret set) */
-static int check_auth(struct sip_pvt *p, struct sip_request *req, char *username, char *secret, char *md5secret, int sipmethod, char *uri, int reliable, int ignore)
+static int check_auth(struct sip_pvt *p, struct sip_request *req, const char *username,
+ const char *secret, const char *md5secret, int sipmethod,
+ char *uri, int reliable, int ignore)
{
int res = -1;
char *response = "407 Proxy Authentication Required";
@@ -6397,7 +6395,7 @@
}
}
- ast_copy_string(p->exten, name, sizeof(p->exten));
+ ast_string_field_set(p, exten, name);
build_contact(p);
peer = find_peer(name, NULL, 1);
if (!(peer && ast_apply_ha(peer->ha, sin))) {
@@ -6516,7 +6514,7 @@
}
if (sip_debug_test_pvt(p))
ast_verbose("RDNIS is %s\n", c);
- ast_copy_string(p->rdnis, c, sizeof(p->rdnis));
+ ast_string_field_set(p, rdnis, c);
return 0;
}
@@ -6585,7 +6583,7 @@
}
/* If we have a context defined, overwrite the original context */
if (!ast_strlen_zero(domain_context))
- ast_copy_string(p->context, domain_context, sizeof(p->context));
+ ast_string_field_set(p, context, domain_context);
}
if (from) {
@@ -6593,9 +6591,9 @@
*a = '\0';
if ((a = strchr(from, '@'))) {
*a = '\0';
- ast_copy_string(p->fromdomain, a + 1, sizeof(p->fromdomain));
+ ast_string_field_set(p, fromdomain, a + 1);
} else
- ast_copy_string(p->fromdomain, from, sizeof(p->fromdomain));
+ ast_string_field_set(p, fromdomain, from);
}
if (sip_debug_test_pvt(p))
ast_verbose("Looking for %s in %s (domain %s)\n", uri, p->context, p->domain);
@@ -6604,7 +6602,7 @@
if (ast_exists_extension(NULL, p->context, uri, 1, from) ||
!strcmp(uri, ast_pickup_ext())) {
if (!oreq)
- ast_copy_string(p->exten, uri, sizeof(p->exten));
+ ast_string_field_set(p, exten, uri);
return 0;
}
@@ -6740,9 +6738,9 @@
/* This is a supervised transfer */
ast_log(LOG_DEBUG,"Assigning Replace-Call-ID Info %s to REPLACE_CALL_ID\n",replace_callid);
- ast_copy_string(sip_pvt->refer_to, "", sizeof(sip_pvt->refer_to));
- ast_copy_string(sip_pvt->referred_by, "", sizeof(sip_pvt->referred_by));
- ast_copy_string(sip_pvt->refer_contact, "", sizeof(sip_pvt->refer_contact));
+ ast_string_field_free(sip_pvt, refer_to);
+ ast_string_field_free(sip_pvt, referred_by);
+ ast_string_field_free(sip_pvt, refer_contact);
sip_pvt->refer_call = NULL;
if ((sip_pvt_ptr = get_sip_pvt_byid_locked(replace_callid))) {
sip_pvt->refer_call = sip_pvt_ptr;
@@ -6764,11 +6762,11 @@
if (referred_by)
ast_log(LOG_DEBUG,"Transferred by (Referred-by: ) %s \n", referred_by);
ast_log(LOG_DEBUG,"Transfer Contact Info %s (REFER_CONTACT)\n", h_contact);
- ast_copy_string(sip_pvt->refer_to, refer_to, sizeof(sip_pvt->refer_to));
+ ast_string_field_set(sip_pvt, refer_to, refer_to);
if (referred_by)
- ast_copy_string(sip_pvt->referred_by, referred_by, sizeof(sip_pvt->referred_by));
+ ast_string_field_set(sip_pvt, referred_by, referred_by);
if (h_contact) {
- ast_copy_string(sip_pvt->refer_contact, h_contact, sizeof(sip_pvt->refer_contact));
+ ast_string_field_set(sip_pvt, refer_contact, h_contact);
}
sip_pvt->refer_call = NULL;
if ((chan = sip_pvt->owner) && (peer = ast_bridged_channel(sip_pvt->owner))) {
@@ -6813,9 +6811,9 @@
if (ast_exists_extension(NULL, p->context, c, 1, NULL)) {
/* This is an unsupervised transfer */
ast_log(LOG_DEBUG,"Assigning Extension %s to REFER-TO\n", c);
- ast_copy_string(p->refer_to, c, sizeof(p->refer_to));
- ast_copy_string(p->referred_by, "", sizeof(p->referred_by));
- ast_copy_string(p->refer_contact, "", sizeof(p->refer_contact));
+ ast_string_field_set(p, refer_to, c);
+ ast_string_field_free(p, referred_by);
+ ast_string_field_free(p, refer_contact);
p->refer_call = NULL;
return 0;
} else if (ast_canmatch_extension(NULL, p->context, c, 1, NULL)) {
@@ -6977,7 +6975,7 @@
memset(calleridname, 0, sizeof(calleridname));
get_calleridname(from, calleridname, sizeof(calleridname));
if (calleridname[0])
- ast_copy_string(p->cid_name, calleridname, sizeof(p->cid_name));
+ ast_string_field_set(p, cid_name, calleridname);
rpid = get_header(req, "Remote-Party-ID");
memset(rpid_num, 0, sizeof(rpid_num));
@@ -6989,7 +6987,7 @@
t = uri;
if (!strncmp(t, "sip:", 4))
t+= 4;
- ast_copy_string(p->exten, t, sizeof(p->exten));
+ ast_string_field_set(p, exten, t);
t = strchr(p->exten, '@');
if (t)
*t = '\0';
@@ -6997,7 +6995,7 @@
build_contact(p);
}
/* save the URI part of the From header */
- ast_copy_string(p->from, of, sizeof(p->from));
+ ast_string_field_set(p, from, of);
if (strncmp(of, "sip:", 4)) {
ast_log(LOG_NOTICE, "From address missing 'sip:', using it anyway\n");
} else
@@ -7007,8 +7005,8 @@
*c = '\0';
if ((c = strchr(of, ':')))
*c = '\0';
- ast_copy_string(p->cid_num, of, sizeof(p->cid_num));
- ast_shrink_phone_number(p->cid_num);
+ ast_string_field_set(p, cid_num, of);
+ ast_shrink_phone_number((char *) p->cid_num);
}
if (ast_strlen_zero(of))
return 0;
@@ -7030,9 +7028,9 @@
/* replace callerid if rpid found, and not restricted */
if (!ast_strlen_zero(rpid_num) && ast_test_flag(p, SIP_TRUSTRPID)) {
if (*calleridname)
- ast_copy_string(p->cid_name, calleridname, sizeof(p->cid_name));
- ast_copy_string(p->cid_num, rpid_num, sizeof(p->cid_num));
- ast_shrink_phone_number(p->cid_num);
+ ast_string_field_set(p, cid_name, calleridname);
+ ast_string_field_set(p, cid_num, rpid_num);
+ ast_shrink_phone_number((char *) p->cid_num);
}
if (p->rtp) {
@@ -7056,20 +7054,20 @@
if (user->call_limit)
ast_set_flag(p, SIP_CALL_LIMIT);
if (!ast_strlen_zero(user->context))
- ast_copy_string(p->context, user->context, sizeof(p->context));
- if (!ast_strlen_zero(user->cid_num) && !ast_strlen_zero(p->cid_num)) {
- ast_copy_string(p->cid_num, user->cid_num, sizeof(p->cid_num));
- ast_shrink_phone_number(p->cid_num);
+ ast_string_field_set(p, context, user->context);
+ if (!ast_strlen_zero(user->cid_num) && !ast_strlen_zero(p->cid_num)) {
+ ast_string_field_set(p, cid_num, user->cid_num);
+ ast_shrink_phone_number((char *) p->cid_num);
}
- if (!ast_strlen_zero(user->cid_name) && !ast_strlen_zero(p->cid_num))
- ast_copy_string(p->cid_name, user->cid_name, sizeof(p->cid_name));
- ast_copy_string(p->username, user->name, sizeof(p->username));
- ast_copy_string(p->peersecret, user->secret, sizeof(p->peersecret));
- ast_copy_string(p->subscribecontext, user->subscribecontext, sizeof(p->subscribecontext));
- ast_copy_string(p->peermd5secret, user->md5secret, sizeof(p->peermd5secret));
+ if (!ast_strlen_zero(user->cid_name) && !ast_strlen_zero(p->cid_num))
+ ast_string_field_set(p, cid_name, user->cid_name);
+ ast_string_field_set(p, username, user->name);
+ ast_string_field_set(p, peersecret, user->secret);
+ ast_string_field_set(p, peermd5secret, user->md5secret);
+ ast_string_field_set(p, subscribecontext, user->subscribecontext);
ast_string_field_set(p, accountcode, user->accountcode);
- ast_copy_string(p->language, user->language, sizeof(p->language));
- ast_copy_string(p->musicclass, user->musicclass, sizeof(p->musicclass));
+ ast_string_field_set(p, language, user->language);
+ ast_string_field_set(p, musicclass, user->musicclass);
p->amaflags = user->amaflags;
p->callgroup = user->callgroup;
p->pickupgroup = user->pickupgroup;
@@ -7119,9 +7117,9 @@
/* replace callerid if rpid found, and not restricted */
if (!ast_strlen_zero(rpid_num) && ast_test_flag(p, SIP_TRUSTRPID)) {
if (*calleridname)
- ast_copy_string(p->cid_name, calleridname, sizeof(p->cid_name));
- ast_copy_string(p->cid_num, rpid_num, sizeof(p->cid_num));
- ast_shrink_phone_number(p->cid_num);
+ ast_string_field_set(p, cid_name, calleridname);
+ ast_string_field_set(p, cid_num, rpid_num);
+ ast_shrink_phone_number((char *) p->cid_num);
}
if (p->rtp) {
ast_log(LOG_DEBUG, "Setting NAT on RTP to %d\n", (ast_test_flag(p, SIP_NAT) & SIP_NAT_ROUTE));
@@ -7131,26 +7129,25 @@
ast_log(LOG_DEBUG, "Setting NAT on VRTP to %d\n", (ast_test_flag(p, SIP_NAT) & SIP_NAT_ROUTE));
ast_rtp_setnat(p->vrtp, (ast_test_flag(p, SIP_NAT) & SIP_NAT_ROUTE));
}
- ast_copy_string(p->peersecret, peer->secret, sizeof(p->peersecret));
- p->peersecret[sizeof(p->peersecret)-1] = '\0';
- ast_copy_string(p->subscribecontext, peer->subscribecontext, sizeof(p->subscribecontext));
- ast_copy_string(p->peermd5secret, peer->md5secret, sizeof(p->peermd5secret));
- p->peermd5secret[sizeof(p->peermd5secret)-1] = '\0';
+ ast_string_field_set(p, peersecret, peer->secret);
+ ast_string_field_set(p, peermd5secret, peer->md5secret);
+ ast_string_field_set(p, subscribecontext, peer->subscribecontext);
p->callingpres = peer->callingpres;
if (peer->maxms && peer->lastms)
p->timer_t1 = peer->lastms;
if (ast_test_flag(peer, SIP_INSECURE_INVITE)) {
/* Pretend there is no required authentication */
- p->peersecret[0] = '\0';
- p->peermd5secret[0] = '\0';
+ ast_string_field_free(p, peersecret);
+ ast_string_field_free(p, peermd5secret);
}
if (!(res = check_auth(p, req, peer->name, p->peersecret, p->peermd5secret, sipmethod, uri, reliable, ignore))) {
ast_copy_flags(p, peer, SIP_FLAGS_TO_COPY);
/* If we have a call limit, set flag */
if (peer->call_limit)
ast_set_flag(p, SIP_CALL_LIMIT);
- ast_copy_string(p->peername, peer->name, sizeof(p->peername));
- ast_copy_string(p->authname, peer->name, sizeof(p->authname));
+ ast_string_field_set(p, peername, peer->name);
+ ast_string_field_set(p, authname, peer->name);
+
/* copy channel vars */
for (v = peer->chanvars ; v ; v = v->next) {
if ((tmpvar = ast_variable_new(v->name, v->value))) {
@@ -7161,22 +7158,22 @@
if (mailbox)
snprintf(mailbox, mailboxlen, ",%s,", peer->mailbox);
if (!ast_strlen_zero(peer->username)) {
- ast_copy_string(p->username, peer->username, sizeof(p->username));
+ ast_string_field_set(p, username, peer->username);
/* Use the default username for authentication on outbound calls */
- ast_copy_string(p->authname, peer->username, sizeof(p->authname));
+ ast_string_field_set(p, authname, peer->username);
}
- if (!ast_strlen_zero(peer->cid_num) && !ast_strlen_zero(p->cid_num)) {
- ast_copy_string(p->cid_num, peer->cid_num, sizeof(p->cid_num));
- ast_shrink_phone_number(p->cid_num);
+ if (!ast_strlen_zero(peer->cid_num) && !ast_strlen_zero(p->cid_num)) {
+ ast_string_field_set(p, cid_num, peer->cid_num);
+ ast_shrink_phone_number((char *) p->cid_num);
}
if (!ast_strlen_zero(peer->cid_name) && !ast_strlen_zero(p->cid_name))
- ast_copy_string(p->cid_name, peer->cid_name, sizeof(p->cid_name));
- ast_copy_string(p->fullcontact, peer->fullcontact, sizeof(p->fullcontact));
+ ast_string_field_set(p, cid_name, peer->cid_name);
+ ast_string_field_set(p, fullcontact, peer->fullcontact);
if (!ast_strlen_zero(peer->context))
- ast_copy_string(p->context, peer->context, sizeof(p->context));
- ast_copy_string(p->peersecret, peer->secret, sizeof(p->peersecret));
- ast_copy_string(p->peermd5secret, peer->md5secret, sizeof(p->peermd5secret));
- ast_copy_string(p->language, peer->language, sizeof(p->language));
+ ast_string_field_set(p, context, peer->context);
+ ast_string_field_set(p, peersecret, peer->secret);
+ ast_string_field_set(p, peermd5secret, peer->md5secret);
+ ast_string_field_set(p, language, peer->language);
ast_string_field_set(p, accountcode, peer->accountcode);
p->amaflags = peer->amaflags;
p->callgroup = peer->callgroup;
@@ -8808,7 +8805,7 @@
/* Recalculate our side, and recalculate Call ID */
if (ast_sip_ouraddrfor(&p->sa.sin_addr, &p->ourip))
memcpy(&p->ourip, &__ourip, sizeof(p->ourip));
- build_via(p, p->via, sizeof(p->via));
+ build_via(p);
build_callid_pvt(p);
ast_cli(fd, "Sending NOTIFY of type '%s' to '%s'\n", argv[2], argv[i]);
transmit_sip_request(p, &req);
@@ -8989,9 +8986,9 @@
char uri[256];
char cnonce[80];
char iabuf[INET_ADDRSTRLEN];
- char *username;
- char *secret;
- char *md5secret;
+ const char *username;
+ const char *secret;
+ const char *md5secret;
struct sip_auth *auth = (struct sip_auth *) NULL; /* Realm authentication */
if (!ast_strlen_zero(p->domain))
@@ -9523,7 +9520,7 @@
p->options->auth_type = (resp == 401 ? WWW_AUTH : PROXY_AUTH);
/* Then we AUTH */
- p->theirtag[0]='\0'; /* forget their old tag, so we don't match tags when getting response */
+ ast_string_field_free(p, theirtag); /* forget their old tag, so we don't match tags when getting response */
if (!ignore) {
char *authenticate = (resp == 401 ? "WWW-Authenticate" : "Proxy-Authenticate");
char *authorization = (resp == 401 ? "Authorization" : "Proxy-Authorization");
@@ -9769,7 +9766,10 @@
/* Get their tag if we haven't already */
if (ast_strlen_zero(p->theirtag) || (resp >= 200)) {
- gettag(req, "To", p->theirtag, sizeof(p->theirtag));
+ char tag[128];
+
+ gettag(req, "To", tag, sizeof(tag));
+ ast_string_field_set(p, theirtag, tag);
}
if (p->peerpoke) {
/* We don't really care what the response is, just that it replied back.
@@ -9955,7 +9955,10 @@
if (resp == 200) {
/* Tags in early session is replaced by the tag in 200 OK, which is
the final reply to our INVITE */
- gettag(req, "To", p->theirtag, sizeof(p->theirtag));
+ char tag[128];
+
+ gettag(req, "To", tag, sizeof(tag));
+ ast_string_field_set(p, theirtag, tag);
}
switch(resp) {
@@ -10190,9 +10193,7 @@
/*! \brief gettag: Get tag from packet */
static char *gettag(struct sip_request *req, char *header, char *tagbuf, int tagbufsize)
{
-
char *thetag, *sep;
-
if (!tagbuf)
return NULL;
@@ -10218,7 +10219,7 @@
build_contact(p);
/* XXX Should we authenticate OPTIONS? XXX */
if (ast_strlen_zero(p->context))
- strcpy(p->context, default_context);
+ ast_string_field_set(p, context, default_context);
if (res < 0)
transmit_response_with_allow(p, "404 Not Found", req, 0);
else if (res > 0)
@@ -10311,8 +10312,8 @@
transmit_response(p, "403 Forbidden", req);
else
transmit_response_reliable(p, "403 Forbidden", req, 1);
- ast_set_flag(p, SIP_NEEDDESTROY);
- p->theirtag[0] = '\0'; /* Forget their to-tag, we'll get a new one */
+ ast_set_flag(p, SIP_NEEDDESTROY);
+ ast_string_field_free(p, theirtag);
}
return 0;
}
@@ -10332,7 +10333,7 @@
ast_queue_frame(p->owner, &af);
/* Initialize the context if it hasn't been already */
if (ast_strlen_zero(p->context))
- strcpy(p->context, default_context);
+ ast_string_field_set(p, context, default_context);
/* Check number of concurrent calls -vs- incoming limit HERE */
ast_log(LOG_DEBUG, "Checking SIP call limits for device %s\n", p->username);
res = update_call_counter(p, INC_CALL_LIMIT);
@@ -10372,11 +10373,11 @@
} else {
/* If no extension was specified, use the s one */
if (ast_strlen_zero(p->exten))
- ast_copy_string(p->exten, "s", sizeof(p->exten));
+ ast_string_field_set(p, exten, "s");
/* Initialize tag */
make_our_tag(p->tag, sizeof(p->tag));
/* First invitation */
- c = sip_new(p, AST_STATE_DOWN, ast_strlen_zero(p->username) ? NULL : p->username );
+ c = sip_new(p, AST_STATE_DOWN, ast_strlen_zero(p->username) ? NULL : p->username);
*recount = 1;
/* Save Record-Route for any later requests we make on this dialogue */
build_route(p, req, 0);
@@ -10502,7 +10503,7 @@
if (option_debug > 2)
ast_log(LOG_DEBUG, "SIP call transfer received for call %s (REFER)!\n", p->callid);
if (ast_strlen_zero(p->context))
- strcpy(p->context, default_context);
+ ast_string_field_set(p, context, default_context);
res = get_refer_info(p, req);
if (res < 0)
transmit_response_with_allow(p, "404 Not Found", req, 1);
@@ -10614,7 +10615,7 @@
ast_log(LOG_NOTICE, "Client '%s' using deprecated BYE/Also transfer method. Ask vendor to support REFER instead\n",
ast_inet_ntoa(iabuf, sizeof(iabuf), p->recv.sin_addr));
if (ast_strlen_zero(p->context))
- strcpy(p->context, default_context);
+ ast_string_field_set(p, context, default_context);
res = get_also_info(p, req);
if (!res) {
c = p->owner;
@@ -10708,9 +10709,9 @@
}
/* Initialize the context if it hasn't been already */
if (!ast_strlen_zero(p->subscribecontext))
- ast_copy_string(p->context, p->subscribecontext, sizeof(p->context));
+ ast_string_field_set(p, context, p->subscribecontext);
else if (ast_strlen_zero(p->context))
- strcpy(p->context, default_context);
+ ast_string_field_set(p, context, default_context);
/* Get destination right away */
gotdest = get_destination(p, NULL);
build_contact(p);
@@ -10917,7 +10918,7 @@
/* Save useragent of the client */
useragent = get_header(req, "User-Agent");
if (!ast_strlen_zero(useragent))
- ast_copy_string(p->useragent, useragent, sizeof(p->useragent));
+ ast_string_field_set(p, useragent, useragent);
/* Find out SIP method for incoming request */
if (req->method == SIP_RESPONSE) { /* Response to our request */
@@ -10976,7 +10977,10 @@
/* Find their tag if we haven't got it */
if (ast_strlen_zero(p->theirtag)) {
- gettag(req, "From", p->theirtag, sizeof(p->theirtag));
+ char tag[128];
+
+ gettag(req, "From", tag, sizeof(tag));
+ ast_string_field_set(p, theirtag, tag);
}
snprintf(p->lastmsg, sizeof(p->lastmsg), "Rx: %s", cmd);
@@ -11184,7 +11188,7 @@
/* Recalculate our side, and recalculate Call ID */
if (ast_sip_ouraddrfor(&p->sa.sin_addr,&p->ourip))
memcpy(&p->ourip, &__ourip, sizeof(p->ourip));
- build_via(p, p->via, sizeof(p->via));
+ build_via(p);
build_callid_pvt(p);
/* Send MWI */
ast_set_flag(p, SIP_OUTGOING);
@@ -11407,19 +11411,22 @@
memcpy(&p->recv, &peer->addr, sizeof(p->sa));
/* Send options to peer's fullcontact */
- if (!ast_strlen_zero(peer->fullcontact)) {
- ast_copy_string (p->fullcontact, peer->fullcontact, sizeof(p->fullcontact));
- }
+ if (!ast_strlen_zero(peer->fullcontact))
+ ast_string_field_set(p, fullcontact, peer->fullcontact);
if (!ast_strlen_zero(peer->tohost))
- ast_copy_string(p->tohost, peer->tohost, sizeof(p->tohost));
- else
- ast_inet_ntoa(p->tohost, sizeof(p->tohost), peer->addr.sin_addr);
+ ast_string_field_set(p, tohost, peer->tohost);
+ else {
+ char iabuf[INET_ADDRSTRLEN];
+
+ ast_inet_ntoa(iabuf, sizeof(iabuf), peer->addr.sin_addr);
+ ast_string_field_set(p, tohost, iabuf);
+ }
/* Recalculate our side, and recalculate Call ID */
if (ast_sip_ouraddrfor(&p->sa.sin_addr,&p->ourip))
memcpy(&p->ourip, &__ourip, sizeof(p->ourip));
- build_via(p, p->via, sizeof(p->via));
+ build_via(p);
build_callid_pvt(p);
if (peer->pokeexpire > -1)
@@ -11556,11 +11563,11 @@
return NULL;
}
if (ast_strlen_zero(p->peername) && ext)
- ast_copy_string(p->peername, ext, sizeof(p->peername));
+ ast_string_field_set(p, peername, ext);
/* Recalculate our side, and recalculate Call ID */
if (ast_sip_ouraddrfor(&p->sa.sin_addr,&p->ourip))
memcpy(&p->ourip, &__ourip, sizeof(p->ourip));
- build_via(p, p->via, sizeof(p->via));
+ build_via(p);
build_callid_pvt(p);
/* We have an extension to call, don't use the full contact here */
@@ -11568,8 +11575,8 @@
like SIP/peername/extension
SIP/peername will still use the full contact */
if (ext) {
- ast_copy_string(p->username, ext, sizeof(p->username));
- p->fullcontact[0] = 0;
[... 157 lines stripped ...]
More information about the svn-commits
mailing list