<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0">
	<channel>
		<title><![CDATA[Latest posts for the topic "Aplicatia Backticks in Asterisk 1.4"]]></title>
		<link>http://forum.modulo.ro/jforum/posts/list/1.page</link>
		<description><![CDATA[Latest messages posted in the topic "Aplicatia Backticks in Asterisk 1.4"]]></description>
		<generator>JForum - http://www.jforum.net</generator>
			<item>
				<title>Aplicatia Backticks in Asterisk 1.4</title>
				<description><![CDATA[ Una dintre aplicatiile care nu sunt incluse in distributia standard Asterisk este [url=http://www.voip-info.org/wiki/view/Asterisk+cmd+Backticks]Backticks[/url]. Aceasta aplicatie este foarte utila pentru a obtine in dialplan-ul Asterisk rezultatul unor scripturi sau programe externe.<br /> <br /> Versiunea [url=http://www.freeswitch.org/asterisk_stuff/app_backticks.c ]initiala[/url] a aplicatiei nu este compatibila cu Asterisk 1.4 astfel incat a fost necesara portarea acesteia.<br /> [url=http://www.voip-info.org/wiki/index.php?comment_page=4&page_id=3689&comments_page=1&page=3#editcomments]Aici[/url] este o prima referinta despre aceasta portare - problema este ca sursa a fost salvata in pagina de wiki si continutul a fost compromis de formatarea interna.<br /> <br /> Pe baza informatiilor din link-ul de mai sus am reusit sa modific versiunea initiala insa, la compilare in Asterisk 1.4.24.1 am avut erorile:<br /> [code]<br /> /usr/src/asterisk/asterisk-1.4.24.1/include/asterisk/lock.h:734: error: PTHREAD_MUTEX_RECURSIVE undeclared (first use in this function)<br /> /usr/src/asterisk/asterisk-1.4.24.1/include/asterisk/lock.h:734: error: (Each undeclared identifier is reported only once<br /> /usr/src/asterisk/asterisk-1.4.24.1/include/asterisk/lock.h:734: error: for each function it appears in.)<br /> [/code]<br /> Problema s-a rezolvat dupa ce am inclus si linia:<br /> [code]<br /> #include "asterisk.h"<br /> [/code]<br /> Dupa aceasta, instalarea a functionat fara probleme, cu exceptia unor mesaje de warning:<br /> [code]<br /> app_backticks.c:169: warning: initialization from incompatible pointer type<br /> app_backticks.c:173: warning: no previous prototype for unload_module<br /> app_backticks.c:183: warning: no previous prototype for load_module<br /> app_backticks.c:193: warning: no previous prototype for description<br /> [/code]<br /> Pasii pentru instalarea aplicatiei sub Asterisk 1.4 sunt redati mai jos:<br /> [code]<br /> cd /usr/src/&lt;asterisk_source_directory&gt;/<br /> cp /tmp/app_backticks.c ./apps<br /> make<br /> make install<br /> [/code]<br /> Cele 2 versiuni ale aplicatiei (pentru Asterisk 1.2 si 1.4) le puteti gasi mai jos.]]></description>
				<guid isPermaLink="true">http://forum.modulo.ro/jforum/posts/preList/78/4887.page</guid>
				<link>http://forum.modulo.ro/jforum/posts/preList/78/4887.page</link>
				<pubDate><![CDATA[Thu, 14 May 2009 15:40:26]]> GMT</pubDate>
				<author><![CDATA[ Nini]]></author>
			</item>
			<item>
				<title>Re:Aplicatia Backticks in Asterisk 1.4</title>
				<description><![CDATA[ app_backtics.c.1.2<br /> [code]<br /> /*<br />  * backticks Application For Asterisk<br />  *<br />  * Copyright (c) 2004-2007 Anthony Minessale II &lt;anthmct@yahoo.com&gt;<br />  *<br />  * Permission is hereby granted, free of charge, to any person<br />  * obtaining a copy of this software and associated documentation<br />  * files (the "Software"), to deal in the Software without<br />  * restriction, including without limitation the rights to use,<br />  * copy, modify, merge, publish, distribute, sublicense, and/or sell<br />  * copies of the Software, and to permit persons to whom the<br />  * Software is furnished to do so, subject to the following<br />  * conditions:<br />  *<br />  * The above copyright notice and this permission notice shall be<br />  * included in all copies or substantial portions of the Software.<br />  *<br />  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,<br />  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES<br />  * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND<br />  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT<br />  * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,<br />  * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING<br />  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR<br />  * OTHER DEALINGS IN THE SOFTWARE.<br />  */<br /> <br /> #include &lt;stdio.h&gt;<br /> #include &lt;asterisk/file.h&gt;<br /> #include &lt;asterisk/logger.h&gt;<br /> #include &lt;asterisk/channel.h&gt;<br /> #include &lt;asterisk/pbx.h&gt;<br /> #include &lt;asterisk/module.h&gt;<br /> #include &lt;asterisk/lock.h&gt;<br /> #include &lt;asterisk/app.h&gt;<br /> #include &lt;stdlib.h&gt;<br /> #include &lt;unistd.h&gt;<br /> #include &lt;string.h&gt;<br /> <br /> static char *tdesc = "backticks";<br /> static char *app = "BackTicks";<br /> static char *synopsis = "Execute a shell command and save the result as a variable.";<br /> static char *desc = ""<br /> "  Backticks(&lt;VARNAME&gt;|&lt;command&gt;)\n\n"<br /> "Be sure to include a full path!\n"<br /> <br /> ;<br /> <br /> STANDARD_LOCAL_USER;<br /> <br /> LOCAL_USER_DECL;<br /> <br /> static char *do_backticks(char *command, char *buf, size_t len)<br /> {<br />         int fds[2], pid = 0;<br />         char *ret = NULL;<br /> <br />         memset(buf, 0, len);<br /> <br />         if (pipe(fds)) {<br />                 ast_log(LOG_WARNING, "Pipe/Exec failed\n");<br />         } else { /* good to go*/<br /> <br />                 pid = fork();<br /> <br />                 if (pid &lt; 0) { /* ok maybe not */<br />                         ast_log(LOG_WARNING, "Fork failed\n");<br />                         close(fds[0]);<br />                         close(fds[1]);<br />                 } else if (pid) { /* parent */<br />                         close(fds[1]);<br />                         read(fds[0], buf, len);<br />                         close(fds[0]);<br />                         ret = buf;<br />                 } else { /*  child */<br />                         char *argv[255] = {0};<br />                         int argc = 0;<br />                         char *p;<br />                         char *mycmd = ast_strdupa(command);<br /> <br />                         close(fds[0]);<br />                         dup2(fds[1], STDOUT_FILENO);<br />                         argv[argc++] = mycmd;<br /> <br />                         do {<br />                                 if ((p = strchr(mycmd, ' '))) {<br />                                         *p = '\0';<br />                                         mycmd = ++p;<br />                                         argv[argc++] = mycmd;<br />                                 }<br />                         } while (p);<br /> <br />                         close(fds[1]);<br />                         execv(argv[0], argv);<br />                         /* DoH! */<br />                         ast_log(LOG_ERROR, "exec of %s failed\n", argv[0]);<br />                         exit(0);<br />                 }<br />         }<br /> <br />         return buf;<br /> }<br /> <br /> static int backticks_exec(struct ast_channel *chan, void *data)<br /> {<br />         int res = 0;<br />         struct localuser *u;<br />         const char *usage = "Usage: Backticks(&lt;VARNAME&gt;|&lt;command&gt;)";<br />         char buf[1024], *argv[2], *mydata;<br />         int argc = 0;<br /> <br /> <br />         if (!data) {<br />                 ast_log(LOG_WARNING, "%s\n", usage);<br />                 return -1;<br />         }<br /> <br /> <br />         LOCAL_USER_ADD(u);<br />         /* Do our thing here */<br /> <br />         if (!(mydata = ast_strdupa(data))) {<br />                 ast_log(LOG_ERROR, "Memory Error!\n");<br />                 res = -1;<br />         } else {<br />                 if((argc = ast_app_separate_args(mydata, '|', argv, sizeof(argv) / sizeof(argv[0]))) &lt; 2) {<br />                         ast_log(LOG_WARNING, "%s\n", usage);<br />                         res = -1;<br />                 }<br /> <br />                 if (do_backticks(argv[1], buf, sizeof(buf))) {<br />                         pbx_builtin_setvar_helper(chan, argv[0], buf);<br />                 } else {<br />                         ast_log(LOG_WARNING, "No Data!\n");<br />                         res = -1;<br />                 }<br />         }<br />         LOCAL_USER_REMOVE(u);<br />         return res;<br /> }<br /> <br /> <br /> static char *function_backticks(struct ast_channel *chan, char *cmd, char *data, char *buf, size_t len)<br /> {<br />         char *ret = NULL;<br /> <br />         if (do_backticks(data, buf, len)) {<br />                 ret = buf;<br />         }<br /> <br />         return ret;<br /> }<br /> <br /> static struct ast_custom_function backticks_function = {<br />         .name = "BACKTICKS",<br />         .desc = "Executes a shell command and evaluates to the result.",<br />         .syntax = "BACKTICKS(&lt;command&gt;)",<br />         .synopsis = "Executes a shell command.",<br />         .read = function_backticks<br /> };<br /> <br /> <br /> int unload_module(void)<br /> {<br />         STANDARD_HANGUP_LOCALUSERS;<br />         ast_custom_function_unregister(&backticks_function);<br />         return ast_unregister_application(app);<br /> }<br /> <br /> int load_module(void)<br /> {<br />         ast_custom_function_register(&backticks_function);<br /> <br />         return ast_register_application(app, backticks_exec, synopsis, desc);<br /> }<br /> <br /> char *description(void)<br /> {<br />         return tdesc;<br /> }<br /> <br /> int usecount(void)<br /> {<br />         int res;<br />         STANDARD_USECOUNT(res);<br />         return res;<br /> }<br /> <br /> char *key()<br /> {<br />         return ASTERISK_GPL_KEY;<br /> }<br /> [/code]]]></description>
				<guid isPermaLink="true">http://forum.modulo.ro/jforum/posts/preList/78/4888.page</guid>
				<link>http://forum.modulo.ro/jforum/posts/preList/78/4888.page</link>
				<pubDate><![CDATA[Thu, 14 May 2009 15:43:03]]> GMT</pubDate>
				<author><![CDATA[ Nini]]></author>
			</item>
			<item>
				<title>Re:Aplicatia Backticks in Asterisk 1.4</title>
				<description><![CDATA[ app_backticks.c.1.4<br /> [code]<br /> /*<br />  * backticks Application For Asterisk<br />  *<br />  * Copyright (c) 2004-2007 Anthony Minessale II &lt;anthmct@yahoo.com&gt;<br />  *<br />  * Permission is hereby granted, free of charge, to any person<br />  * obtaining a copy of this software and associated documentation<br />  * files (the "Software"), to deal in the Software without<br />  * restriction, including without limitation the rights to use,<br />  * copy, modify, merge, publish, distribute, sublicense, and/or sell<br />  * copies of the Software, and to permit persons to whom the<br />  * Software is furnished to do so, subject to the following<br />  * conditions:<br />  *<br />  * The above copyright notice and this permission notice shall be<br />  * included in all copies or substantial portions of the Software.<br />  *<br />  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,<br />  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES<br />  * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND<br />  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT<br />  * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,<br />  * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING<br />  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR<br />  * OTHER DEALINGS IN THE SOFTWARE.<br />  *<br />  *<br />  * ported to 1.4 by Hoai-Anh Ngo-Vi &lt;hoaianh@web.de&gt;<br />  *<br />  * updated for 1.4.24.1 by Ioan Indreias, www.modulo.ro<br />  *<br />  *<br />  */<br /> <br /> #include "asterisk.h"<br /> <br /> #include &lt;stdio.h&gt;<br /> #include &lt;asterisk/file.h&gt;<br /> #include &lt;asterisk/logger.h&gt;<br /> #include &lt;asterisk/channel.h&gt;<br /> #include &lt;asterisk/pbx.h&gt;<br /> #include &lt;asterisk/module.h&gt;<br /> #include &lt;asterisk/lock.h&gt;<br /> #include &lt;asterisk/app.h&gt;<br /> #include &lt;stdlib.h&gt;<br /> #include &lt;unistd.h&gt;<br /> #include &lt;string.h&gt;<br /> <br /> static char *tdesc = "backticks";<br /> static char *app = "BackTicks";<br /> static char *synopsis = "Execute a shell command and save the result as a variable.";<br /> static char *desc = ""<br /> "  Backticks(&lt;VARNAME&gt;|&lt;command&gt;)\n\n"<br /> "Be sure to include a full path!\n"<br /> <br /> ;<br /> <br /> //STANDARD_LOCAL_USER;<br /> <br /> //LOCAL_USER_DECL;<br /> <br /> static char *do_backticks(char *command, char *buf, size_t len)<br /> {<br />         int fds[2], pid = 0;<br />         char *ret = NULL;<br /> <br />         memset(buf, 0, len);<br /> <br />         if (pipe(fds)) {<br />                 ast_log(LOG_WARNING, "Pipe/Exec failed\n");<br />         } else { /* good to go*/<br /> <br />                 pid = fork();<br /> <br />                 if (pid &lt; 0) { /* ok maybe not */<br />                         ast_log(LOG_WARNING, "Fork failed\n");<br />                         close(fds[0]);<br />                         close(fds[1]);<br />                 } else if (pid) { /* parent */<br />                         close(fds[1]);<br />                         read(fds[0], buf, len);<br />                         close(fds[0]);<br />                         ret = buf;<br />                 } else { /*  child */<br />                         char *argv[255] = {0};<br />                         int argc = 0;<br />                         char *p;<br />                         char *mycmd = ast_strdupa(command);<br /> <br />                         close(fds[0]);<br />                         dup2(fds[1], STDOUT_FILENO);<br />                         argv[argc++] = mycmd;<br /> <br />                         do {<br />                                 if ((p = strchr(mycmd, ' '))) {<br />                                         *p = '\0';<br />                                         mycmd = ++p;<br />                                         argv[argc++] = mycmd;<br />                                 }<br />                         } while (p);<br /> <br />                         close(fds[1]);<br />                         execv(argv[0], argv);<br />                         /* DoH! */<br />                         ast_log(LOG_ERROR, "exec of %s failed\n", argv[0]);<br />                         exit(0);<br />                 }<br />         }<br /> <br />         return buf;<br /> }<br /> <br /> static int backticks_exec(struct ast_channel *chan, void *data)<br /> {<br />         int res = 0;<br />         struct ast_module_user *u;<br />         const char *usage = "Usage: Backticks(&lt;VARNAME&gt;|&lt;command&gt;)";<br />         char buf[1024], *argv[2], *mydata;<br />         int argc = 0;<br /> <br /> <br />         if (!data) {<br />                 ast_log(LOG_WARNING, "%s\n", usage);<br />                 return -1;<br />         }<br /> <br /> <br />         u = ast_module_user_add(chan);<br />         /* Do our thing here */<br /> <br />         if (!(mydata = ast_strdupa(data))) {<br />                 ast_log(LOG_ERROR, "Memory Error!\n");<br />                 res = -1;<br />         } else {<br />                 if((argc = ast_app_separate_args(mydata, '|', argv, sizeof(argv) / sizeof(argv[0]))) &lt; 2) {<br />                         ast_log(LOG_WARNING, "%s\n", usage);<br />                         res = -1;<br />                 }<br /> <br />                 if (do_backticks(argv[1], buf, sizeof(buf))) {<br />                         pbx_builtin_setvar_helper(chan, argv[0], buf);<br />                 } else {<br />                         ast_log(LOG_WARNING, "No Data!\n");<br />                         res = -1;<br />                 }<br />         }<br />         ast_module_user_remove(u);<br />         return res;<br /> }<br /> <br /> <br /> static char *function_backticks(struct ast_channel *chan, char *cmd, char *data, char *buf, size_t len)<br /> {<br />         char *ret = NULL;<br /> <br />         if (do_backticks(data, buf, len)) {<br />                 ret = buf;<br />         }<br /> <br />         return ret;<br /> }<br /> <br /> static struct ast_custom_function backticks_function = {<br />         .name = "BACKTICKS",<br />         .desc = "Executes a shell command and evaluates to the result.",<br />         .syntax = "BACKTICKS(&lt;command&gt;)",<br />         .synopsis = "Executes a shell command.",<br />         .read = function_backticks<br /> };<br /> <br /> <br /> int unload_module(void)<br /> {<br />         int res;<br />         res = ast_custom_function_unregister(&backticks_function);<br />         res |= ast_unregister_application(app);<br />         ast_module_user_hangup_all();<br /> <br />         return res;<br /> }<br /> <br /> int load_module(void)<br /> {<br />         int res;<br /> <br />         res = ast_custom_function_register(&backticks_function);<br />         res |= ast_register_application(app, backticks_exec, synopsis, desc);<br /> <br />         return res;<br /> }<br /> <br /> char *description(void)<br /> {<br />         return tdesc;<br /> }<br /> <br /> AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "Third Party BackTicks() application");<br /> [/code]]]></description>
				<guid isPermaLink="true">http://forum.modulo.ro/jforum/posts/preList/78/4889.page</guid>
				<link>http://forum.modulo.ro/jforum/posts/preList/78/4889.page</link>
				<pubDate><![CDATA[Thu, 14 May 2009 15:47:43]]> GMT</pubDate>
				<author><![CDATA[ Nini]]></author>
			</item>
	</channel>
</rss>
