Exemplo n.º 1
0
function getBoolValue($str, $defVal)
{
    if (empty($str)) {
        return $defVal;
    }
    return Yate::Str2bool($str);
}
Exemplo n.º 2
0
 $ev = Yate::GetEvent();
 /* If Yate disconnected us then exit cleanly */
 if ($ev === false) {
     break;
 }
 /* No need to handle empty events in this application */
 if ($ev === true) {
     continue;
 }
 /* If we reached here we should have a valid object */
 switch ($ev->type) {
     case "incoming":
         switch ($ev->name) {
             case "call.execute":
                 $mailbox = $ev->GetValue("user");
                 $untrusted = Yate::Str2bool($ev->GetValue("untrusted"));
                 $partycallid = $ev->GetValue("id");
                 $ev->params["targetid"] = $ourcallid;
                 $ev->handled = true;
                 /* We must ACK this message before dispatching a call.answered */
                 $ev->Acknowledge();
                 /* Prevent a warning if trying to ACK this message again */
                 $ev = false;
                 /* Signal we are answering the call */
                 $m = new Yate("call.answered");
                 $m->params["id"] = $ourcallid;
                 $m->params["targetid"] = $partycallid;
                 $m->Dispatch();
                 /* If the user is unknown we need to identify and authenticate */
                 if ($mailbox == "") {
                     setState("user");
Exemplo n.º 3
0
 /**
  * This static function processes just one input line.
  * It must be called in a loop to keep messages running. Or else.
  * @return false if we should exit, true if we should keep running,
  *  or an Yate object instance. Remember to use === and !== operators
  *  when comparing against true and false.
  */
 static function GetEvent()
 {
     global $yate_stdin, $yate_socket;
     if ($yate_socket) {
         $line = @socket_read($yate_socket, 8192, PHP_NORMAL_READ);
         // check for error
         if ($line == false) {
             return false;
         }
         // check for EOF
         if ($line === "") {
             return false;
         }
     } else {
         if ($yate_stdin == false) {
             return false;
         }
         // check for EOF
         if (feof($yate_stdin)) {
             return false;
         }
         $line = fgets($yate_stdin, 8192);
         // check for async read no data
         if ($line == false) {
             return true;
         }
     }
     $line = str_replace("\n", "", $line);
     if ($line == "") {
         return true;
     }
     $ev = true;
     $part = explode(":", $line);
     switch ($part[0]) {
         case "%%>message":
             /* incoming message str_id:int_time:str_name:str_retval[:key=value...] */
             $ev = new Yate(Yate::Unescape($part[3]), Yate::Unescape($part[4]), Yate::Unescape($part[1]));
             $ev->type = "incoming";
             $ev->origin = 0 + $part[2];
             $ev->FillParams($part, 5);
             break;
         case "%%<message":
             /* message answer str_id:bool_handled:str_name:str_retval[:key=value...] */
             $ev = new Yate(Yate::Unescape($part[3]), Yate::Unescape($part[4]), Yate::Unescape($part[1]));
             $ev->type = "answer";
             $ev->handled = Yate::Str2bool($part[2]);
             $ev->FillParams($part, 5);
             break;
         case "%%<install":
             /* install answer num_priority:str_name:bool_success */
             $ev = new Yate(Yate::Unescape($part[2]), "", 0 + $part[1]);
             $ev->type = "installed";
             $ev->handled = Yate::Str2bool($part[3]);
             break;
         case "%%<uninstall":
             /* uninstall answer num_priority:str_name:bool_success */
             $ev = new Yate(Yate::Unescape($part[2]), "", 0 + $part[1]);
             $ev->type = "uninstalled";
             $ev->handled = Yate::Str2bool($part[3]);
             break;
         case "%%<watch":
             /* watch answer str_name:bool_success */
             $ev = new Yate(Yate::Unescape($part[1]));
             $ev->type = "watched";
             $ev->handled = Yate::Str2bool($part[2]);
             break;
         case "%%<unwatch":
             /* unwatch answer str_name:bool_success */
             $ev = new Yate(Yate::Unescape($part[1]));
             $ev->type = "unwatched";
             $ev->handled = Yate::Str2bool($part[2]);
             break;
         case "%%<connect":
             /* connect answer str_role:bool_success */
             $ev = new Yate(Yate::Unescape($part[1]));
             $ev->type = "connected";
             $ev->handled = Yate::Str2bool($part[2]);
             break;
         case "%%<setlocal":
             /* local parameter answer str_name:str_value:bool_success */
             $ev = new Yate(Yate::Unescape($part[1]), Yate::Unescape($part[2]));
             $ev->type = "setlocal";
             $ev->handled = Yate::Str2bool($part[3]);
             break;
         case "Error in":
             /* We are already in error so better stay quiet */
             break;
         default:
             Yate::Output("PHP parse error: " . $line);
     }
     return $ev;
 }
Exemplo n.º 4
0
 $ev = Yate::GetEvent();
 /* If Yate disconnected us then exit cleanly */
 if ($ev === false) {
     break;
 }
 if ($ev === true) {
     continue;
 }
 /* If we reached here we should have a valid object */
 switch ($ev->type) {
     case "incoming":
         switch ($ev->name) {
             case "call.execute":
                 $partycallid = $ev->GetValue("id");
                 $ev->params["targetid"] = $ourcallid;
                 $routeOnly = !Yate::Str2bool($ev->getValue("accept_call"));
                 $interdigit = 1 * $ev->GetValue("interdigit", $interdigit);
                 $autoanswer = false;
                 $callednum = "";
                 $lang = $ev->getValue("lang");
                 if ($routeOnly) {
                     $callednum = $ev->GetValue("called");
                     if ($callednum == "off-hook") {
                         $callednum = "";
                     }
                 } else {
                     $autoanswer = $ev->GetValue("called") != "off-hook";
                 }
                 $executeParams = $ev->params;
                 $ev->handled = true;
                 // we must ACK this message before dispatching a call.answered