diff options
author | Kevin P. Fleming <kpfleming@digium.com> | 2006-02-12 04:28:58 +0000 |
---|---|---|
committer | Kevin P. Fleming <kpfleming@digium.com> | 2006-02-12 04:28:58 +0000 |
commit | 96bf384e7d84291c40dcbe2e26e16af1c5a974c1 (patch) | |
tree | 5c4270c1ac3d265b96361d98722a75b947f2f8c6 /channels | |
parent | 3d2404c62cc4ff50c05900f305d2a4939a9d5c8b (diff) |
major dialplan functions update
deprecate LANGUAGE() and MUSICCLASS(), in favor of CHANNEL()
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@9674 65c4cc65-6c06-0410-ace0-fbb531ad65f3
Diffstat (limited to 'channels')
-rw-r--r-- | channels/chan_agent.c | 12 | ||||
-rw-r--r-- | channels/chan_iax2.c | 29 | ||||
-rw-r--r-- | channels/chan_sip.c | 58 |
3 files changed, 43 insertions, 56 deletions
diff --git a/channels/chan_agent.c b/channels/chan_agent.c index ff0308b7b..b8bc94f66 100644 --- a/channels/chan_agent.c +++ b/channels/chan_agent.c @@ -1,7 +1,7 @@ /* * Asterisk -- An open source telephony toolkit. * - * Copyright (C) 1999 - 2005, Digium, Inc. + * Copyright (C) 1999 - 2006, Digium, Inc. * * Mark Spencer <markster@digium.com> * @@ -2409,7 +2409,7 @@ struct agent_pvt *find_agent(char *agentid) return cur; } -static char *function_agent(struct ast_channel *chan, char *cmd, char *data, char *buf, size_t len) +static int function_agent(struct ast_channel *chan, char *cmd, char *data, char *buf, size_t len) { char *parse; AST_DECLARE_APP_ARGS(args, @@ -2423,11 +2423,11 @@ static char *function_agent(struct ast_channel *chan, char *cmd, char *data, cha if (ast_strlen_zero(data)) { ast_log(LOG_WARNING, "The AGENT function requires an argument - agentid!\n"); - return buf; + return -1; } if (!(parse = ast_strdupa(data))) - return buf; + return -1; AST_NONSTANDARD_APP_ARGS(args, parse, ':'); if (!args.item) @@ -2435,7 +2435,7 @@ static char *function_agent(struct ast_channel *chan, char *cmd, char *data, cha if (!(agent = find_agent(args.agentid))) { ast_log(LOG_WARNING, "Agent '%s' not found!\n", args.agentid); - return buf; + return -1; } if (!strcasecmp(args.item, "status")) { @@ -2461,7 +2461,7 @@ static char *function_agent(struct ast_channel *chan, char *cmd, char *data, cha ast_copy_string(buf, agent->loginchan, len); } - return buf; + return 0; } struct ast_custom_function agent_function = { diff --git a/channels/chan_iax2.c b/channels/chan_iax2.c index 2c5bab2c3..b54f17d21 100644 --- a/channels/chan_iax2.c +++ b/channels/chan_iax2.c @@ -9170,31 +9170,29 @@ static int iax2_exec(struct ast_channel *chan, const char *context, const char * return -1; } -static char *function_iaxpeer(struct ast_channel *chan, char *cmd, char *data, char *buf, size_t len) +static int function_iaxpeer(struct ast_channel *chan, char *cmd, char *data, char *buf, size_t len) { - char *ret = NULL; struct iax2_peer *peer; char *peername, *colname; char iabuf[INET_ADDRSTRLEN]; if (!(peername = ast_strdupa(data))) - return ret; + return -1; /* if our channel, return the IP address of the endpoint of current channel */ if (!strcmp(peername,"CURRENTCHANNEL")) { unsigned short callno = PTR_TO_CALLNO(chan->tech_pvt); ast_copy_string(buf, iaxs[callno]->addr.sin_addr.s_addr ? ast_inet_ntoa(iabuf, sizeof(iabuf), iaxs[callno]->addr.sin_addr) : "", len); - return buf; + return 0; } - if ((colname = strchr(peername, ':'))) { - *colname = '\0'; - colname++; - } else { + if ((colname = strchr(peername, ':'))) + *colname++ = '\0'; + else colname = "ip"; - } + if (!(peer = find_peer(peername, 1))) - return ret; + return -1; if (!strcasecmp(colname, "ip")) { ast_copy_string(buf, peer->addr.sin_addr.s_addr ? ast_inet_ntoa(iabuf, sizeof(iabuf), peer->addr.sin_addr) : "", len); @@ -9229,16 +9227,15 @@ static char *function_iaxpeer(struct ast_channel *chan, char *cmd, char *data, c ast_copy_string(buf, ast_getformatname(codec), len); } } - ret = buf; - return ret; + return 0; } struct ast_custom_function iaxpeer_function = { - .name = "IAXPEER", - .synopsis = "Gets IAX peer information", - .syntax = "IAXPEER(<peername|CURRENTCHANNEL>[:item])", - .read = function_iaxpeer, + .name = "IAXPEER", + .synopsis = "Gets IAX peer information", + .syntax = "IAXPEER(<peername|CURRENTCHANNEL>[:item])", + .read = function_iaxpeer, .desc = "If peername specified, valid items are:\n" "- ip (default) The IP address.\n" "- status The peer's status (if qualify=yes)\n" diff --git a/channels/chan_sip.c b/channels/chan_sip.c index 484138216..6c42f84ee 100644 --- a/channels/chan_sip.c +++ b/channels/chan_sip.c @@ -9269,21 +9269,21 @@ static char show_settings_usage[] = /*! \brief func_header_read: Read SIP header (dialplan function) */ -static char *func_header_read(struct ast_channel *chan, char *cmd, char *data, char *buf, size_t len) +int func_header_read(struct ast_channel *chan, char *function, char *data, char *buf, size_t len) { struct sip_pvt *p; char *content; if (!data) { ast_log(LOG_WARNING, "This function requires a header name.\n"); - return NULL; + return -1; } ast_mutex_lock(&chan->lock); if (chan->tech != &sip_tech) { ast_log(LOG_WARNING, "This function can only be used on SIP channels.\n"); ast_mutex_unlock(&chan->lock); - return NULL; + return -1; } p = chan->tech_pvt; @@ -9291,23 +9291,22 @@ static char *func_header_read(struct ast_channel *chan, char *cmd, char *data, c /* If there is no private structure, this channel is no longer alive */ if (!p) { ast_mutex_unlock(&chan->lock); - return NULL; + return -1; } content = get_header(&p->initreq, data); if (ast_strlen_zero(content)) { ast_mutex_unlock(&chan->lock); - return NULL; + return -1; } ast_copy_string(buf, content, len); ast_mutex_unlock(&chan->lock); - return buf; + return 0; } - static struct ast_custom_function sip_header_function = { .name = "SIP_HEADER", .synopsis = "Gets or sets the specified SIP header", @@ -9316,17 +9315,17 @@ static struct ast_custom_function sip_header_function = { }; /*! \brief function_check_sipdomain: Dial plan function to check if domain is local */ -static char *func_check_sipdomain(struct ast_channel *chan, char *cmd, char *data, char *buf, size_t len) +int func_check_sipdomain(struct ast_channel *chan, char *cmd, char *data, char *buf, size_t len) { if (ast_strlen_zero(data)) { ast_log(LOG_WARNING, "CHECKSIPDOMAIN requires an argument - A domain name\n"); - return buf; + return -1; } if (check_sip_domain(data, NULL, 0)) ast_copy_string(buf, data, len); else buf[0] = '\0'; - return buf; + return 0; } static struct ast_custom_function checksipdomain_function = { @@ -9340,26 +9339,20 @@ static struct ast_custom_function checksipdomain_function = { "Check the domain= configuration in sip.conf\n", }; - /*! \brief function_sippeer: ${SIPPEER()} Dialplan function - reads peer data */ -static char *function_sippeer(struct ast_channel *chan, char *cmd, char *data, char *buf, size_t len) +int function_sippeer(struct ast_channel *chan, char *cmd, char *data, char *buf, size_t len) { - char *ret = NULL; struct sip_peer *peer; char *peername, *colname; char iabuf[INET_ADDRSTRLEN]; - if (!(peername = ast_strdupa(data))) - return ret; - - if ((colname = strchr(peername, ':'))) { - *colname = '\0'; - colname++; - } else { + if ((colname = strchr(data, ':'))) + *colname++ = '\0'; + else colname = "ip"; - } + if (!(peer = find_peer(peername, NULL, 1))) - return ret; + return -1; if (!strcasecmp(colname, "ip")) { ast_copy_string(buf, peer->addr.sin_addr.s_addr ? ast_inet_ntoa(iabuf, sizeof(iabuf), peer->addr.sin_addr) : "", len); @@ -9396,19 +9389,18 @@ static char *function_sippeer(struct ast_channel *chan, char *cmd, char *data, c codecnum = strchr(colname, '['); *codecnum = '\0'; codecnum++; - if ((ptr = strchr(codecnum, ']'))) { + if ((ptr = strchr(codecnum, ']'))) *ptr = '\0'; - } + index = atoi(codecnum); if((codec = ast_codec_pref_index(&peer->prefs, index))) { ast_copy_string(buf, ast_getformatname(codec), len); } } - ret = buf; ASTOBJ_UNREF(peer, sip_destroy_peer); - return ret; + return 0; } /*! \brief Structure to declare a dialplan function: SIPPEER */ @@ -9438,7 +9430,7 @@ struct ast_custom_function sippeer_function = { }; /*! \brief function_sipchaninfo_read: ${SIPCHANINFO()} Dialplan function - reads sip channel data */ -static char *function_sipchaninfo_read(struct ast_channel *chan, char *cmd, char *data, char *buf, size_t len) +int function_sipchaninfo_read(struct ast_channel *chan, char *cmd, char *data, char *buf, size_t len) { struct sip_pvt *p; char iabuf[INET_ADDRSTRLEN]; @@ -9447,14 +9439,14 @@ static char *function_sipchaninfo_read(struct ast_channel *chan, char *cmd, char if (!data) { ast_log(LOG_WARNING, "This function requires a parameter name.\n"); - return NULL; + return -1; } ast_mutex_lock(&chan->lock); if (chan->tech != &sip_tech) { ast_log(LOG_WARNING, "This function can only be used on SIP channels.\n"); ast_mutex_unlock(&chan->lock); - return NULL; + return -1; } /* ast_verbose("function_sipchaninfo_read: %s\n", data); */ @@ -9463,7 +9455,7 @@ static char *function_sipchaninfo_read(struct ast_channel *chan, char *cmd, char /* If there is no private structure, this channel is no longer alive */ if (!p) { ast_mutex_unlock(&chan->lock); - return NULL; + return -1; } if (!strcasecmp(data, "peerip")) { @@ -9480,11 +9472,11 @@ static char *function_sipchaninfo_read(struct ast_channel *chan, char *cmd, char ast_copy_string(buf, p->peername, len); } else { ast_mutex_unlock(&chan->lock); - return NULL; + return -1; } ast_mutex_unlock(&chan->lock); - return buf; + return 0; } /*! \brief Structure to declare a dialplan function: SIPCHANINFO */ @@ -9502,8 +9494,6 @@ static struct ast_custom_function sipchaninfo_function = { "- peername The name of the peer.\n" }; - - /*! \brief parse_moved_contact: Parse 302 Moved temporalily response */ static void parse_moved_contact(struct sip_pvt *p, struct sip_request *req) { |