Index: channels/chan_iax2.c =================================================================== --- channels/chan_iax2.c (revision 122798) +++ channels/chan_iax2.c (working copy) @@ -11703,6 +11703,51 @@ "\n" }; +/*! \brief ${IAXCHANINFO()} Dialplan function - reads iax channel data */ +static int function_iaxchaninfo_read(struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t len) +{ + struct chan_iax2_pvt *p = NULL; + + *buf = 0; + + if (!data) { + ast_log(LOG_WARNING, "This function requires a parameter name.\n"); + return -1; + } + + ast_channel_lock(chan); + if (strcmp(chan->tech->type, "IAX2") != 0) { + ast_log(LOG_WARNING, "This function can only be used on IAX2 channels.\n"); + ast_channel_unlock(chan); + return -1; + } + p = iaxs[PTR_TO_CALLNO(chan->tech_pvt)]; + + if (!strcasecmp(data, "peerip")) { + ast_copy_string(buf, p->addr.sin_addr.s_addr ? ast_inet_ntoa(p->addr.sin_addr) : "", len); + } + else if (!strcasecmp(data, "peername")) + ast_copy_string(buf, p->username, len); + else { + ast_channel_unlock(chan); + return -1; + } + ast_channel_unlock(chan); + + return 0; + } + +/*! \brief Structure to declare a dialplan function: IAXCHANINFO */ +static struct ast_custom_function iaxchaninfo_function = { + .name = "IAXCHANINFO", + .synopsis = "Gets the specified IAX parameter from the current channel", + .syntax = "IAXCHANINFO(item)", + .read = function_iaxchaninfo_read, + .desc = "Valid items are:\n" + "- peerip The IP address of the peer.\n" + "- peername The name of the peer.\n" +}; + static int acf_channel_write(struct ast_channel *chan, const char *function, char *args, const char *value) { struct chan_iax2_pvt *pvt; @@ -12032,6 +12077,7 @@ static int unload_module(void) { ast_custom_function_unregister(&iaxpeer_function); + ast_custom_function_unregister(&iaxchaninfo_function); ast_custom_function_unregister(&iaxvar_function); return __unload_module(); } @@ -12087,6 +12133,7 @@ } ast_custom_function_register(&iaxpeer_function); + ast_custom_function_register(&iaxchaninfo_function); ast_custom_function_register(&iaxvar_function); iax_set_output(iax_debug_output);