<div>hi,Radael..</div>
<div> </div>
<div>This code have add to CVS ?</div>
<div> </div>
<div>thanks...</div>
<div><br><br> </div>
<div><span class="gmail_quote">On 3/5/06, <b class="gmail_sendername">Rafael Vidal Aroca</b> <<a href="mailto:rafael@3wt.com.br">rafael@3wt.com.br</a>> wrote:</span>
<blockquote class="gmail_quote" style="PADDING-LEFT: 1ex; MARGIN: 0px 0px 0px 0.8ex; BORDER-LEFT: #ccc 1px solid"><br> Hi guys,<br><br> some days ago i was asking in this list how we could avoid 2 users<br>from simultaneosly connecting. Well, after some discussion, i decided to
<br>implement a general solution, that should work for other problems too.<br><br> The idea is to execute an exeternal program every time a user<br>registers or unregisters, so we can setup scripts to insert data in<br>
databases, or take some actions.<br><br> I made it for IAX2, but will implement that for SIP too, if needed.<br><br> An working example is:<br><br> Configure iax.conf<br><br> - In the section [general] add a parameter
<br> exec=/tmp/script.sh<br><br> Then, create the /tmp/script.sh<br> #!/bin/sh<br> #Sun Mar 5 09:56:53 BRT 2006<br> #Rafael Aroca <<a href="mailto:rafael@3wt.com.br">rafael@3wt.com.br</a>><br> #Test script executed by asterisk on registering and unregistering peers
<br><br> echo "[`date`] Received from asterisk parameters $*" >> /tmp/output<br><br> Apply the patch, compile, copy the new channel_iax2.so, and run<br>asterisk.<br><br> Everytime asterisk receives an IAX2 message of REGISTER or a clients
<br>gets UNREGISTERED, /tmp/output receives a new line. My output now after<br>some tests is:<br><br>root@gemini:/home/rafael/voip# cat /tmp/output<br>[Sun Mar 5 11:03:43 BRT 2006] Received from asterisk parameters<br>register 2005
<br>[Sun Mar 5 11:03:51 BRT 2006] Received from asterisk parameters<br>unregister 2004<br>[Sun Mar 5 11:44:14 BRT 2006] Received from asterisk parameters<br>register 2005<br>[Sun Mar 5 11:44:40 BRT 2006] Received from asterisk parameters
<br>register 2005<br>[Sun Mar 5 11:45:14 BRT 2006] Received from asterisk parameters<br>register 2005<br>[Sun Mar 5 11:45:40 BRT 2006] Received from asterisk parameters<br>register 2005<br>[Sun Mar 5 11:46:14 BRT 2006] Received from asterisk parameters
<br>register 2005<br>[Sun Mar 5 11:47:24 BRT 2006] Received from asterisk parameters<br>unregister 2005<br><br><br> Based on that, we can connect to database, or do some other<br>interesting actions.<br><br> The patch for this feature follows attached. By the way, would it be
<br>possible (if my code is safe and verified by someone else) to add this<br>to asterisk SVN?<br><br>thanks<br><br>[] Rafael.<br><br><br><br><br><br><br><br><br><br>--- asterisk-1.2.4/channels/chan_iax2.c 2006-01-19 23:00:
46.000000000 -0200<br>+++ asterisk-1.2.4-tmp/channels/chan_iax2.c 2006-03-05 10:55:58.000000000 -0300<br>@@ -145,6 +145,7 @@<br><br>static char language[MAX_LANGUAGE] = "";<br>static char regcontext[AST_MAX_CONTEXT] = "";
<br>+static char execOnRegister[100] = "";<br><br>static int max_retries = 4;<br>static int ping_time = 20;<br>@@ -5552,8 +5553,31 @@<br>static int expire_registry(void *data)<br>{<br> struct iax2_peer *p = data;
<br>+ int res_fork, res_exec;<br><br> ast_log(LOG_DEBUG, "Expiring registration for peer '%s'\n", p->name);<br>+<br>+ res_fork = fork();<br>+ if (res_fork < 0) {<br>+ ast_log(LOG_NOTICE, "Could not fork");
<br>+ }<br>+<br>+ if (res_fork == 0) {<br>+ //Example: works fine<br>+ //res_exec = execlp("ls", "ls", "-la", NULL);<br>+ res_exec = execlp(execOnRegister, execOnRegister, "unregister", p->name, NULL);
<br>+ } else {<br>+ res_exec = -1;<br>+ }<br>+<br>+ if (res_exec < 0) {<br>+ ast_log(LOG_NOTICE, "Could not exec %s", execOnRegister);
<br>+ } else {<br>+ ast_log(LOG_NOTICE, "Process spawned with PID %d", res_fork);<br>+ }<br>+<br>+<br>+<br> /* Reset the address */
<br> memset(&p->addr, 0, sizeof(p->addr));<br> /* Reset expire notice */<br>@@ -5626,6 +5650,7 @@<br> char data[80];<br> char iabuf[INET_ADDRSTRLEN];<br> int version;<br>+ int res_fork, res_exec;
<br><br> memset(&ied, 0, sizeof(ied));<br><br>@@ -5645,9 +5670,33 @@<br> snprintf(data, sizeof(data), "%s:%d:%d", ast_inet_ntoa(iabuf, sizeof(iabuf), sin->sin_addr), ntohs(sin->sin_port), p->expiry);
<br> if (!ast_test_flag(p, IAX_TEMPONLY) && sin->sin_addr.s_addr) {<br> ast_db_put("IAX/Registry", p->name, data);<br>+<br>+<br>+ ast_log(LOG_NOTICE, "Running %s for peer '%s'\n", execOnRegister, p->name);
<br>+<br>+ res_fork = fork();<br>+ if (res_fork < 0) {<br>+ ast_log(LOG_NOTICE, "Could not fork");<br>+ }<br>+<br>
+ if (res_fork == 0) {<br>+ //Example: works fine<br>+ //res_exec = execlp("ls", "ls", "-la", NULL);<br>+ res_exec = execlp(execOnRegister, execOnRegister, "register", p->name, NULL);
<br>+ } else {<br>+ res_exec = -1;<br>+ }<br>+<br>+ if (res_exec < 0) {<br>+ ast_log(LOG_NOTICE, "Could not exec %s", execOnRegister);
<br>+ } else {<br>+ ast_log(LOG_NOTICE, "Process spawned with PID %d", res_fork);<br>+ }<br>+<br> if (option_verbose > 2)
<br> ast_verbose(VERBOSE_PREFIX_3 "Registered IAX2 '%s' (%s) at %s:%d\n", p->name,<br> ast_test_flag(&iaxs[callno]->state, IAX_STATE_AUTHENTICATED) ? "AUTHENTICATED" : "UNAUTHENTICATED", ast_inet_ntoa(iabuf, sizeof(iabuf), sin->sin_addr), ntohs(sin->sin_port));
<br>+<br> manager_event(EVENT_FLAG_SYSTEM, "PeerStatus", "Peer: IAX2/%s\r\nPeerStatus: Registered\r\n", p->name);<br> register_peer_exten(p, 1);<br> ast_device_state_changed("IAX2/%s", p->name); /* Activate notification */
<br>@@ -8624,6 +8673,8 @@<br> portno = atoi(v->value);<br> } else if (!strcasecmp(v->name, "pingtime"))<br> ping_time = atoi(v->value);<br>
+ else if (!strcasecmp(v->name, "exec"))<br>+ ast_copy_string(execOnRegister, v->value, sizeof(execOnRegister));<br> else if (!strcasecmp(v->name, "nochecksums")) {
<br>#ifdef SO_NO_CHECK<br> if (ast_true(v->value))<br><br><br>_______________________________________________<br>--Bandwidth and Colocation provided by <a href="http://Easynews.com">Easynews.com</a>
--<br><br>asterisk-dev mailing list<br>To UNSUBSCRIBE or update options visit:<br> <a href="http://lists.digium.com/mailman/listinfo/asterisk-dev">http://lists.digium.com/mailman/listinfo/asterisk-dev</a><br><br><br></blockquote>
</div><br><br clear="all"><br>-- <br>Jeffery<br><br>iaxtel Num: 1-700-576-1311<br>fwdnet Num: 728150