Yate Community Forum

General Category => Yate users hangout place => Topic started by: jehanzaib_kiani on November 26, 2014, 10:55:10 PM

Title: simple sip phone dial
Post by: jehanzaib_kiani on November 26, 2014, 10:55:10 PM
Hi team,

i have used db to register my sip users. this works fine. but when i try to dial this user it does not route and says NOT FOUND.
[user.register]
; Query for the user.register message
query=UPDATE sip_users SET fullcontact='${data}',expires=DATE_ADD(NOW(), INTERVAL ${expires} SECOND) WHERE username='${username}'


i have user 100 is regsiter and calling 100. here is my route.php. the script is run and i see it set the line but dont route and say 404 Not found.

         if ($ev->getValue("called")=="100") {
           $ev->retval = "sip/".$ev->getValue("called");
           $ev->params["line"] = "100";
           //$ev->params["targetid"] = $ev->getValue("callid");
           $ev->handled = true;
           $ev->Acknowledge();
           break;
         }


here r logs
  param['rtp_forward'] = 'possible'
  param['handlers'] = 'register:50,regexroute:100,cdrbuild:50,register:50,route.php:80,gvoice:20,queues:45,yrtp:50,cdrbuild:50,lateroute:75,dbwave:90,analyzer:90,iax:90,tone:90,conf:90,dumb:90,filetransfer:90,sip:90,wave:90,callfork:100,extmodule:100,pbx:100,callgen:100,moh:100,park:100'
  param['line'] = '100'
  param['targetid'] = 'sip/4c578f4d7a34f816/e9155934/'
  param['callto'] = 'sip/100'
  param['error'] = 'offline'

Title: Re: simple sip phone dial
Post by: marian on November 27, 2014, 03:01:22 AM
The register module has its own route handler which route the call to registered user location when the called number matches the registered username.
All you have to do is to remove comments (the ; char) in register.conf, [call.route] section and enable the handler in register.conf:
[general]
call.route=yes

NOTE: A line (used to route calls to it) is an user yate registers to another entity. E.g. yate is the client (user) of another server.
Title: Re: simple sip phone dial
Post by: marian on November 27, 2014, 03:03:11 AM
Looking at your post I noticed you are using different names for table and location field.
Change them in [call.route] also.
Title: Re: simple sip phone dial
Post by: jehanzaib_kiani on December 02, 2014, 01:54:37 AM
should i put ${data} in the location field? currently i am not using location.
Title: Re: simple sip phone dial
Post by: marian on December 02, 2014, 06:18:55 AM
Yes. 'location' is the default field name.

NOTE: You can put ${data} in any database field you want as long as you properly return it when routing.
Title: Re: simple sip phone dial
Post by: jehanzaib_kiani on December 04, 2014, 02:06:19 AM
weired. i have call.route=yes in register.conf. but all the calls are going to route.php
and if i do a check in route.php phone still does not ring. its ok to route the call via route.php because i have to send the call to voicemail server if it timeouts on the user.
here is my route.php

        Yate::Output("Route Message: " . $ev->name . " id: " . $ev->id . " called: " . $ev->params["called"] . " caller: " . $ev->params["caller"]);
         if ($ev->getValue("called")=="100") {
           $ev->retval = "sip/".$ev->getValue("called");
           $ev->params["line"] = "100";
           $ev->params["targetid"] = $ev->getValue("callid");
           $ev->handled = true;
           $ev->Acknowledge();
           break;
         }


have a look at the attached logs, i can see call goes to route.php but it is again saying offline in the error. i also have now added location in the sip register/unregister query. can you please have a look. thanks. also if i have to timeout the call to my voicemail server how it will be acheived? say after 20 seconds if nobody picks up, route to voicemail.com server.
thanks
Title: Re: simple sip phone dial
Post by: marian on December 04, 2014, 02:59:42 AM
There is no database message sent by register module when routing.
Are you sure you removed comment char from register.conf, call.route section?
Title: Re: simple sip phone dial
Post by: jehanzaib_kiani on December 04, 2014, 05:53:32 PM
yah that's weired. please see my attached register.conf
i dont want to use native call.route actually. i want to route it using route.php beacuse after 20 seconds i have to send the call to another IP.
this is for testing where i have checked if the dialed number is 100 then first route it to extension 100 if nobody picks up or busy then forward it to another ip for example myotherip.com  thats what i want

         if ($ev->getValue("called")=="100") {
           $ev->retval = "sip/".$ev->getValue("called");
           $ev->params["line"] = "100";
           //$ev->params["targetid"] = $ev->getValue("callid");
           $ev->handled = true;
           $ev->Acknowledge();
           break;
         }
Title: Re: simple sip phone dial
Post by: marian on December 05, 2014, 03:15:14 AM
Something is wrong.
Make sure you are loading the right register.conf file and restarted yate after changing register.conf.
The configured priority of call.route is 120. In the log you posted register call.route priority is 50.
Title: Re: simple sip phone dial
Post by: jehanzaib_kiani on December 07, 2014, 12:44:56 AM
agreed. thats what i am wondered about. when i restart the yate it says register:120 you can see below. but when i make a call i saw register 50. 
what it could be any clue?

param['handlers'] ='engine:100,callgen:100,extmodule:100,cdrcombine:100,cdrbuild:100,ilbcwebrtc:100,isaccodec:100,accfile:100,regfile:100,regexroute:110,analogdetect:120,subscription:120,mysqldb:120,mux:120,socks:120,openssl:120,zlibcompress:120,analyzer:120,enumroute:120,tonedetect:120,callfork:120,stun:120,iax:120,tone:120,filetransfer:120,conf:120,fileinfo:120,pbx:120,dumb:120,queues:120,users:120,wave:120,sip:120,yrtp:120,gvoice:120,park:120,monitoring:120,presence:120,queuesnotify:120,cache:120,register:120,snmpagent:120,mrcp:120,sipfeatures:120'
Title: Re: simple sip phone dial
Post by: jehanzaib_kiani on December 07, 2014, 01:21:06 AM
also

  param['rtp_forward'] = 'possible'
  param['handlers'] = 'register:50,regexroute:100,cdrbuild:50,route.php:80,gvoice:20,queues:45,yrtp:50,cdrbuild:50,lateroute:75,dbwave:90,analyzer:90,iax:90,tone:90,conf:90,dumb:90,filetransfer:90,sip:90,wave:90,callfork:100,extmodule:100,pbx:100,callgen:100,moh:100,park:100'
  param['line'] = '100'
  param['targetid'] = 'sip/6213646a5a29720d/2e57b003/'
  param['callto'] = 'sip/100'
  param['error'] = 'offline'

here the logs says error is offline. unable to figure out where the issue
Title: Re: simple sip phone dial
Post by: marian on December 08, 2014, 05:12:02 AM
The register appearing in handlers parameter is set when call.preroute message is handled. When call.preroute succeeds it is renamed to call.route and re-dispatched: this is the reason register appears there.

The call is routed by route.php. Priority 80.
If you want the routing to be handled nu register before route.php set a lower value priority in it (lower value means higher priority).
Title: Re: simple sip phone dial
Post by: jehanzaib_kiani on December 08, 2014, 06:41:12 AM
Actually i want to handle the call by route.php so its fine. but its not working i tried all the possibilities.
The below should work, but its not. any clue please

           $ev->retval = "sip/".$ev->getValue("called");
           $ev->params["line"] = "100";
           //$ev->params["targetid"] = $ev->getValue("callid");
           $ev->handled = true;
           $ev->Acknowledge();
           break;
         }
Title: Re: simple sip phone dial
Post by: marian on December 08, 2014, 06:56:49 AM
As noted in November 27 post a line is an account registered by yate to another server.

If you want to route a call to an user registered to yate you should either:
1. Let register route the call
2. Query the database to retrieve user location and route the call to it
Title: Re: simple sip phone dial
Post by: jehanzaib_kiani on December 09, 2014, 02:24:01 AM
sure let's say i have location saved and now i want to route it.

the location is sip/sip:100@xx.xx.xx.xx:6055

how to route in route.php to this location?

         $location = my above location value from db
         if ($ev->getValue("called")=="100") {
           $ev->retval = $location;
           $ev->params["line"] = "100";
           //$ev->params["targetid"] = $ev->getValue("callid");
           $ev->handled = true;
           $ev->Acknowledge();
           break;
         }

will this work? and how to timeout on busy or no answer? if the call timeouts or busy i will put different server IP in the location and route to anywhere else. that;s what i want. Can you please guide this ? ihave hard time to get this done
Title: Re: simple sip phone dial
Post by: marian on December 09, 2014, 02:55:40 AM
If you set the 'line' parameter the call will fail (I suppose you don't have a line '100' registered to another server).
NOTE: If you want to call on a different path a busy target you should be aware you might call again to someone that rejected the call!

If you want to fallback to another target use fork.
See http://docs.yate.ro/wiki/Call_Forker

The handler should look like this:

if ($ev->getValue("called")=="100") {
  $ev->retval = "fork";
  $ev->params["callto.1"] = $location;
  $ev->params["callto.2"] = "|";
  $ev->params["callto.3"] = PUT_HERE_THE_SECOND_TARGET;
  $ev->params["callto.1.maxcall"] = PUT_HERE_MAX_CALLING_TIME_IN_MILISECONDS;
  $ev->params["stoperror"] = "noanswer|busy^";
  $ev->params[""] = ;
  $ev->handled = true;
  $ev->Acknowledge();
  break;
}
Title: Re: simple sip phone dial
Post by: jehanzaib_kiani on December 09, 2014, 05:50:36 PM
so i changed it to below. and my 100phone rang for 20 seconds then it just hangup saying Temporarily unavailable.  it did not try on my second server after the timeout. you might be able to figure out from the attached logs. by the way i am dialing from 100 to 100.

 $ev->retval = "fork";
  $ev->params["callto.1"] = "sip/sip:100@xx.xx.xx.xx:6542";
  $ev->params["callto.2"] = "|";
  $ev->params["callto.3"] = "sip/sip:100@mysecondserver.com";
  $ev->params["callto.1.maxcall"] = 20000;
  $ev->params["stoperror"] = "noanswer|busy^";
  $ev->handled = true;
  $ev->Acknowledge();
  break;
Title: Re: simple sip phone dial
Post by: marian on December 10, 2014, 01:42:09 AM
Sorry, bad regexp (| char must be escaped), set stoperror:
$ev->params["stoperror"] = "noanswer\|busy^";

Also replace 'stoperror' (obsolete) with new 'fork.stop':
$ev->params["fork.stop"] = "noanswer\|busy^";