<br><br>---------- Forwarded message ----------<br><span class="gmail_quote">From: <b class="gmail_sendername">Rafael Vidal Aroca</b> <<a href="mailto:rafael@3wt.com.br">rafael@3wt.com.br</a>><br>Date: May 2, 2006 5:24 AM
<br>Subject: Re: [asterisk-dev] new feature<br>To: Asterisk Developers Mailing List <<a href="mailto:asterisk-dev@lists.digium.com">asterisk-dev@lists.digium.com</a>><br><br></span><br> No, it is not on cvs. You should copy and add it to your asterisk.
<br>If needed, i have patches for the 1.26<br><br>--<br>Rafael Vidal Aroca<br>3WT - Wireless Web World Tech<br><a href="mailto:rafael@3WT.com.br">rafael@3WT.com.br</a><br>Tel/Fax: +55 16 3371-7761<br>Cel: +55 16 8126-8014
<br><br><br><br>陈帆 wrote:<br><br>> hi,Radael..<br>><br>> This code have add to CVS ?<br>><br>> thanks...<br>><br>><br>><br>> On 3/5/06, *Rafael Vidal Aroca* <<a href="mailto:rafael@3wt.com.br">
rafael@3wt.com.br</a><br>> <mailto:<a href="mailto:rafael@3wt.com.br">rafael@3wt.com.br</a>>> wrote:<br>><br>><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<br>> decided to<br>> implement a general solution, that should work for other problems<br>> 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> <mailto:<a href="mailto:rafael@3wt.com.br">rafael@3wt.com.br
</a>>><br>> #Test script executed by asterisk on registering and<br>> 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<br>> clients<br>> gets UNREGISTERED, /tmp/output receives a new line. My output now
<br>> 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<br>> 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:
<br>> 46.000000000 -0200<br>> +++ asterisk-1.2.4-tmp/channels/chan_iax2.c 2006-03-05<br>> 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",
<br>> 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,
<br>> "unregister", p->name, NULL);<br>> + } else {<br>> + res_exec = -1;<br>> + }<br>> +<br>> + if (res_exec < 0) {
<br>> + ast_log(LOG_NOTICE, "Could not<br>> exec %s", execOnRegister);<br>> + } else {<br>> + ast_log(LOG_NOTICE, "Process
<br>> 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",<br>> ast_inet_ntoa(iabuf, sizeof(iabuf), sin->sin_addr),
<br>> ntohs(sin->sin_port), p->expiry);<br>> if (!ast_test_flag(p, IAX_TEMPONLY) &&<br>> 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<br>> '%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",<br>> "-la", NULL);<br>> + res_exec = execlp(execOnRegister,
<br>> 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<br>> exec %s", execOnRegister);<br>> + } else {
<br>> + ast_log(LOG_NOTICE, "Process<br>> spawned with PID %d", res_fork);<br>> + }<br>> +<br>> if (option_verbose > 2)
<br>> ast_verbose(VERBOSE_PREFIX_3<br>> "Registered IAX2 '%s' (%s) at %s:%d\n", p->name,<br>><br>> ast_test_flag(&iaxs[callno]->state, IAX_STATE_AUTHENTICATED) ?
<br>> "AUTHENTICATED" : "UNAUTHENTICATED", ast_inet_ntoa(iabuf,<br>> sizeof(iabuf), sin->sin_addr), ntohs(sin->sin_port));<br>> +<br>> manager_event(EVENT_FLAG_SYSTEM,
<br>> "PeerStatus", "Peer: IAX2/%s\r\nPeerStatus: Registered\r\n", p->name);<br>> register_peer_exten(p, 1);<br>> ast_device_state_changed("IAX2/%s",
<br>> 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,
<br>> 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>> <<a href="http://Easynews.com">http://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>><br>><br>><br>> --<br>> Jeffery<br>><br>> iaxtel Num: 1-700-576-1311<br>> fwdnet Num: 728150<br>><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><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 clear="all"><br>-- <br>Jeffery<br><br>iaxtel Num: 1-700-576-1311<br>fwdnet Num: 728150