function _xmlrpcs_listMethods($server, $m)
 {
     global $xmlrpcerr, $xmlrpcstr, $_xmlrpcs_dmap;
     $v = new xmlrpcval();
     $dmap = $server->dmap;
     $outAr = array();
     for (reset($dmap); list($key, $val) = each($dmap);) {
         $outAr[] = new xmlrpcval($key, 'string');
     }
     $dmap = $_xmlrpcs_dmap;
     for (reset($dmap); list($key, $val) = each($dmap);) {
         $outAr[] = new xmlrpcval($key, 'string');
     }
     $v->addArray($outAr);
     return new xmlrpcresp($v);
 }
Exemple #2
0
function xmlrpc_encode($php_val)
{
    global $xmlrpcInt;
    global $xmlrpcDouble;
    global $xmlrpcString;
    global $xmlrpcArray;
    global $xmlrpcStruct;
    global $xmlrpcBoolean;
    $type = gettype($php_val);
    $xmlrpc_val = new xmlrpcval();
    switch ($type) {
        case "array":
        case "object":
            $arr = array();
            while (list($k, $v) = each($php_val)) {
                $arr[$k] = xmlrpc_encode($v);
            }
            $xmlrpc_val->addStruct($arr);
            break;
        case "integer":
            $xmlrpc_val->addScalar($php_val, $xmlrpcInt);
            break;
        case "double":
            $xmlrpc_val->addScalar($php_val, $xmlrpcDouble);
            break;
        case "string":
            $xmlrpc_val->addScalar($php_val, $xmlrpcString);
            break;
            // <G_Giunta_2001-02-29>
            // Add support for encoding/decoding of booleans, since they are supported in PHP
        // <G_Giunta_2001-02-29>
        // Add support for encoding/decoding of booleans, since they are supported in PHP
        case "boolean":
            $xmlrpc_val->addScalar($php_val, $xmlrpcBoolean);
            break;
            // </G_Giunta_2001-02-29>
        // </G_Giunta_2001-02-29>
        case "unknown type":
        default:
            // giancarlo pinerolo <*****@*****.**>
            // it has to return
            // an empty object in case (which is already
            // at this point), not a boolean.
            break;
    }
    return $xmlrpc_val;
}
Exemple #3
0
<p></p>
<?php 
include "xmlrpc.inc";
$inAr = array("Dave" => 24, "Edd" => 45, "Joe" => 37, "Fred" => 27);
reset($inAr);
print "This is the input data:<br/><pre>";
while (list($key, $val) = each($inAr)) {
    print $key . ", " . $val . "\n";
}
print "</pre>";
// create parameters from the input array: an xmlrpc array of xmlrpc structs
$p = array();
foreach ($inAr as $key => $val) {
    $p[] = new xmlrpcval(array("name" => new xmlrpcval($key), "age" => new xmlrpcval($val, "int")), "struct");
}
$v = new xmlrpcval($p, "array");
print "Encoded into xmlrpc format it looks like this: <pre>\n" . htmlentities($v->serialize()) . "</pre>\n";
// create client and message objects
$f = new xmlrpcmsg('examples.sortByAge', array($v));
$c = new xmlrpc_client("/server.php", "phpxmlrpc.sourceforge.net", 80);
// set maximum debug level, to have the complete communication printed to screen
$c->setDebug(2);
// send request
print "Now sending request (detailed debug info follows)";
$r =& $c->send($f);
// check response for errors, and take appropriate action
if (!$r->faultCode()) {
    print "The server gave me these results:<pre>";
    $v = $r->value();
    $max = $v->arraysize();
    for ($i = 0; $i < $max; $i++) {
 switch ($task) {
     case 'list_methods':
         jimport('joomla.html.html');
         $msg = new xmlrpcmsg('system.listMethods');
         $xmlrpcdoc = $client->send($msg);
         //echo var_dump($xmlrpcdoc);
         //die;
         if ($xmlrpcdoc->faultCode() == 0) {
             $result = $xmlrpcdoc->value();
             $array = $result->scalarval();
         } else {
             print $xmlrpcdoc->faultString();
         }
         $methods = array();
         for ($i = 0; $i < sizeof($array); $i++) {
             $var = new xmlrpcval($array[$i]);
             $array_method = $var->scalarval();
             $methods[$i] = JHTML::_('select.option', $array_method->scalarval());
         }
         $output = 'Methods<br />';
         $output .= JHTML::_('select.genericlist', $methods, 'method', 'size="10"', 'value', 'text');
         $output .= ' <input name="args" type="text" />';
         $output .= ' <input name="task" type="submit" value="exec" />';
         break;
     case 'exec':
         $method = JRequest::getVar('method', '', '', 'cmd');
         $args = JRequest::getVar('args');
         $message = new xmlrpcmsg($method, array(new xmlrpcval(0, "int")));
         $xmlrpcdoc = $client->send($message);
         if ($xmlrpcdoc->faultCode() == 0) {
             $scalar_var = $xmlrpcdoc->value();
 function testStringInt()
 {
     $v = new xmlrpcval('hello world', 'int');
     $s = $v->serialize();
     $this->assertequals("<value><int>0</int></value>\n", $s);
 }
Exemple #6
0
	/**
	* Takes an xmlrpc value in PHP xmlrpcval object format and translates it into native PHP types.
	*
	* Works with xmlrpc message objects as input, too.
	*
	* Given proper options parameter, can rebuild generic php object instances
	* (provided those have been encoded to xmlrpc format using a corresponding
	* option in php_xmlrpc_encode())
	* PLEASE NOTE that rebuilding php objects involves calling their constructor function.
	* This means that the remote communication end can decide which php code will
	* get executed on your server, leaving the door possibly open to 'php-injection'
	* style of attacks (provided you have some classes defined on your server that
	* might wreak havoc if instances are built outside an appropriate context).
	* Make sure you trust the remote server/client before eanbling this!
	*
	* @author Dan Libby (dan@libby.com)
	*
	* @param xmlrpcval $xmlrpc_val
	* @param array $options if 'decode_php_objs' is set in the options array, xmlrpc structs can be decoded into php objects
	* @return mixed
	*/
	function php_xmlrpc_decode($xmlrpc_val, $options=array())
	{
		switch($xmlrpc_val->kindOf())
		{
			case 'scalar':
				if (in_array('extension_api', $options))
				{
					reset($xmlrpc_val->me);
					list($typ,$val) = each($xmlrpc_val->me);
					switch ($typ)
					{
						case 'dateTime.iso8601':
							$xmlrpc_val->scalar = $val;
							$xmlrpc_val->xmlrpc_type = 'datetime';
							$xmlrpc_val->timestamp = iso8601_decode($val);
							return $xmlrpc_val;
						case 'base64':
							$xmlrpc_val->scalar = $val;
							$xmlrpc_val->type = $typ;
							return $xmlrpc_val;
						default:
							return $xmlrpc_val->scalarval();
					}
				}
				return $xmlrpc_val->scalarval();
			case 'array':
				$size = $xmlrpc_val->arraysize();
				$arr = array();
				for($i = 0; $i < $size; $i++)
				{
					$arr[] = php_xmlrpc_decode($xmlrpc_val->arraymem($i), $options);
				}
				return $arr;
			case 'struct':
				$xmlrpc_val->structreset();
				// If user said so, try to rebuild php objects for specific struct vals.
				/// @todo should we raise a warning for class not found?
				// shall we check for proper subclass of xmlrpcval instead of
				// presence of _php_class to detect what we can do?
				if (in_array('decode_php_objs', $options) && $xmlrpc_val->_php_class != ''
					&& class_exists($xmlrpc_val->_php_class))
				{
					$obj = @new $xmlrpc_val->_php_class;
					while(list($key,$value)=$xmlrpc_val->structeach())
					{
						$obj->$key = php_xmlrpc_decode($value, $options);
					}
					return $obj;
				}
				else
				{
					$arr = array();
					while(list($key,$value)=$xmlrpc_val->structeach())
					{
						$arr[$key] = php_xmlrpc_decode($value, $options);
					}
					return $arr;
				}
			case 'msg':
				$paramcount = $xmlrpc_val->getNumParams();
				$arr = array();
				for($i = 0; $i < $paramcount; $i++)
				{
					$arr[] = php_xmlrpc_decode($xmlrpc_val->getParam($i));
				}
				return $arr;
			}
	}
 public function testDateTime()
 {
     $time = time();
     $t1 = new xmlrpcval($time, 'dateTime.iso8601');
     $t2 = new xmlrpcval(iso8601_encode($time), 'dateTime.iso8601');
     $this->assertEquals($t1->serialize(), $t2->serialize());
     if (class_exists('DateTime')) {
         $datetime = new DateTime();
         // skip this test for php 5.2. It is a bit harder there to build a DateTime from unix timestamp with proper TZ info
         if (is_callable(array($datetime, 'setTimestamp'))) {
             $t3 = new xmlrpcval($datetime->setTimestamp($time), 'dateTime.iso8601');
             $this->assertEquals($t1->serialize(), $t3->serialize());
         }
     }
 }
Exemple #8
0
<body>
<?php 
include "xmlrpc.inc";
$f = new xmlrpcmsg('examples.getStateName');
print "<h3>Testing value serialization</h3>\n";
$v = new xmlrpcval(23, "int");
print "<PRE>" . htmlentities($v->serialize()) . "</PRE>";
$v = new xmlrpcval("What are you saying? >> << &&");
print "<PRE>" . htmlentities($v->serialize()) . "</PRE>";
$v = new xmlrpcval(array(new xmlrpcval("ABCDEFHIJ"), new xmlrpcval(1234, 'int'), new xmlrpcval(1, 'boolean')), "array");
print "<PRE>" . htmlentities($v->serialize()) . "</PRE>";
$v = new xmlrpcval(array("thearray" => new xmlrpcval(array(new xmlrpcval("ABCDEFHIJ"), new xmlrpcval(1234, 'int'), new xmlrpcval(1, 'boolean'), new xmlrpcval(0, 'boolean'), new xmlrpcval(true, 'boolean'), new xmlrpcval(false, 'boolean')), "array"), "theint" => new xmlrpcval(23, 'int'), "thestring" => new xmlrpcval("foobarwhizz"), "thestruct" => new xmlrpcval(array("one" => new xmlrpcval(1, 'int'), "two" => new xmlrpcval(2, 'int')), "struct")), "struct");
print "<PRE>" . htmlentities($v->serialize()) . "</PRE>";
$w = new xmlrpcval(array($v, new xmlrpcval("That was the struct!")), "array");
print "<PRE>" . htmlentities($w->serialize()) . "</PRE>";
$w = new xmlrpcval("Mary had a little lamb,\nWhose fleece was white as snow,\nAnd everywhere that Mary went\nthe lamb was sure to go.\n\nMary had a little lamb\nShe tied it to a pylon\nTen thousand volts went down its back\nAnd turned it into nylon", "base64");
print "<PRE>" . htmlentities($w->serialize()) . "</PRE>";
print "<PRE>Value of base64 string is: '" . $w->scalarval() . "'</PRE>";
$f->method('');
$f->addParam(new xmlrpcval("41", "int"));
print "<h3>Testing request serialization</h3>\n";
$op = $f->serialize();
print "<PRE>" . htmlentities($op) . "</PRE>";
print "<h3>Testing ISO date format</h3><pre>\n";
$t = time();
$date = iso8601_encode($t);
print "Now is {$t} --> {$date}\n";
print "Or in UTC, that is " . iso8601_encode($t, 1) . "\n";
$tb = iso8601_decode($date);
print "That is to say {$date} --> {$tb}\n";
print "Which comes out at " . iso8601_encode($tb) . "\n";
Exemple #9
0
function processResult($result)
{
    $ret = new xmlrpcval();
    if (is_object($result)) {
        $result = get_object_vars($result);
    }
    if (is_associative_array($result)) {
        $ar = array();
        $keys = array_keys($result);
        foreach ($keys as $k) {
            $tmp = new xmlrpcval(array($k => new xmlrpcval($result[$k])), 'struct');
            $ar[] = $tmp;
        }
        $ret->addArray($ar);
    } else {
        if (is_array($result)) {
            foreach ($result as $key => $value) {
                if (!is_string($value)) {
                    $tmp = processResult($value);
                } else {
                    $tmp = new xmlrpcval();
                    $tmp->addScalar($value);
                }
                $result[$key] = $tmp;
            }
            $ret->addArray($result);
        } else {
            if (is_bool($result)) {
                $ret->addScalar($result, "boolean");
            } else {
                $ret->addScalar($result);
            }
        }
    }
    return $ret;
}
 function TestLocale()
 {
     $locale = setlocale(LC_NUMERIC, 0);
     /// @todo on php 5.3/win setting locale to german does not seem to set decimal separator to comma...
     if (setlocale(LC_NUMERIC, 'deu', 'de_DE@euro', 'de_DE', 'de', 'ge') !== false) {
         $v = new xmlrpcval(1.1, 'double');
         if (strpos($v->scalarval(), ',') == 1) {
             $r = $v->serialize();
             $this->assertequals(false, strpos($r, ','));
         }
         setlocale(LC_NUMERIC, $locale);
     }
 }
 function __phpxmlrpc_encapsulate($arg)
 {
     // The class xmlrpcval is defined in the phpxmlrpc library. It requires both the variable
     // and the type. Dates are handled through the API as ISO 8601 string representations.
     if (is_string($arg)) {
         $encapArg = new xmlrpcval($arg, 'string');
     } elseif (is_int($arg)) {
         $encapArg = new xmlrpcval($arg, 'int');
     } elseif (is_bool($arg)) {
         $encapArg = new xmlrpcval($arg, 'boolean');
     } elseif (is_array($arg)) {
         // The API server treats indexed arrays (lists) and associative arrays (dictionaries)
         // differently where in php they are essentially the same. Assuming that having a zero
         // index set indicates an indexed array is not perfect but should suffice for the
         // purpose of the API examples.
         if (isset($arg[0])) {
             $array = array();
             foreach ($arg as $key => $value) {
                 $array[] = $this->__phpxmlrpc_encapsulate($value);
             }
             $encapArray = new xmlrpcval();
             $encapArray->addArray($array);
             $encapArg = $encapArray;
         } else {
             $struct = array();
             foreach ($arg as $key => $value) {
                 $struct[$key] = $this->__phpxmlrpc_encapsulate($value);
             }
             $encapStruct = new xmlrpcval();
             $encapStruct->addStruct($struct);
             $encapArg = $encapStruct;
         }
     } else {
         $encapArg = new xmlrpcval($arg, 'string');
     }
     return $encapArg;
 }
Exemple #12
0
 function testMinusOneString()
 {
     $v = new xmlrpcval('-1');
     $u = new xmlrpcval('-1', 'string');
     $this->assertEquals($u->scalarval(), $v->scalarval());
 }
 function TestLocale()
 {
     $locale = setlocale(LC_NUMERIC, 0);
     if (setlocale(LC_NUMERIC, 'deu', 'de_DE@euro', 'de_DE', 'de', 'ge') !== false) {
         $v = new xmlrpcval(1.1, 'double');
         $r = $v->serialize();
         $this->assertequals(false, strpos($r, ','));
         $this->assertequals(1, strpos($v->scalarval(), ','));
         setlocale(LC_NUMERIC, $locale);
     }
 }
Exemple #14
0
/**
 * Takes an xmlrpc value in PHP xmlrpcval object format
 * and translates it into native PHP types.
 *
 * @author Dan Libby (dan@libby.com)
 *
 * @param  xmlrpcval $xmlrpc_val
 * @param  array     $options    if 'decode_php_objs' is set in the options array, xmlrpc structs can be decoded into php objects
 * @return mixed
 */
function php_xmlrpc_decode($xmlrpc_val, $options = '')
{
    $kind = $xmlrpc_val->kindOf();
    if ($kind == 'scalar') {
        return $xmlrpc_val->scalarval();
    } elseif ($kind == 'array') {
        $size = $xmlrpc_val->arraysize();
        $arr = array();
        for ($i = 0; $i < $size; $i++) {
            $arr[] = php_xmlrpc_decode($xmlrpc_val->arraymem($i), $options);
        }
        return $arr;
    } elseif ($kind == 'struct') {
        $xmlrpc_val->structreset();
        // If user said so, try to rebuild php objects for specific struct vals.
        /// @todo should we raise a warning for class not found?
        // shall we check for proper subclass of xmlrpcval instead of
        // presence of _php_class to detect what we can do?
        if (@in_array('decode_php_objs', $options) && $xmlrpc_val->_php_class != '' && class_exists($xmlrpc_val->_php_class)) {
            $obj = @new $xmlrpc_val->_php_class();
            while (list($key, $value) = $xmlrpc_val->structeach()) {
                $obj->{$key} = php_xmlrpc_decode($value, $options);
            }
            return $obj;
        } else {
            $arr = array();
            while (list($key, $value) = $xmlrpc_val->structeach()) {
                $arr[$key] = php_xmlrpc_decode($value, $options);
            }
            return $arr;
        }
    }
}
Exemple #15
0
function _book_request($token, $fac, $rooms, $grooms)
{
    $fac->request = 0;
    $server = _serv();
    $arooms = array();
    foreach ($rooms as $rid => $how) {
        $fat = new xmlrpcval();
        $show = new xmlrpcval($how, 'int');
        $srid = new xmlrpcval($rid, 'int');
        $fat->addStruct(array('number' => $show, 'id' => $srid));
        $arooms[] = $fat;
    }
    $lcode = $fac->lcode;
    $message = new xmlrpcmsg('rooms_request', array(new xmlrpcval($token, 'string'), new xmlrpcval($lcode, 'int'), new xmlrpcval($arooms, 'array')));
    $struct = $server->send($message)->value();
    $res = _scal($struct, 0);
    if ($res < 0) {
        return -1;
    }
    $s = $struct->arraymem(1);
    $br = parse_book_request($s);
    $fac->request = $br;
    return $br;
}
Exemple #16
0
/**
 * Takes an xmlrpc value in PHP xmlrpcval object format and translates it into native PHP types.
 *
 * Works with xmlrpc message objects as input, too.
 *
 * Given proper options parameter, can rebuild generic php object instances
 * (provided those have been encoded to xmlrpc format using a corresponding
 * option in php_xmlrpc_encode())
 * PLEASE NOTE that rebuilding php objects involves calling their constructor function.
 * This means that the remote communication end can decide which php code will
 * get executed on your server, leaving the door possibly open to 'php-injection'
 * style of attacks (provided you have some classes defined on your server that
 * might wreak havoc if instances are built outside an appropriate context).
 * Make sure you trust the remote server/client before eanbling this!
 *
 * @author Dan Libby (dan@libby.com)
 *
 * @param xmlrpcval $xmlrpc_val
 * @param array $options if 'decode_php_objs' is set in the options array, xmlrpc structs can be decoded into php objects; if 'dates_as_objects' is set xmlrpc datetimes are decoded as php DateTime objects (standard is
 * @return mixed
 */
function php_xmlrpc_decode($xmlrpc_val, $options = array())
{
    switch ($xmlrpc_val->kindOf()) {
        case 'scalar':
            if (in_array('extension_api', $options)) {
                reset($xmlrpc_val->me);
                list($typ, $val) = each($xmlrpc_val->me);
                switch ($typ) {
                    case 'dateTime.iso8601':
                        $xmlrpc_val->scalar = $val;
                        $xmlrpc_val->xmlrpc_type = 'datetime';
                        $xmlrpc_val->timestamp = iso8601_decode($val);
                        return $xmlrpc_val;
                    case 'base64':
                        $xmlrpc_val->scalar = $val;
                        $xmlrpc_val->type = $typ;
                        return $xmlrpc_val;
                    default:
                        return $xmlrpc_val->scalarval();
                }
            }
            if (in_array('dates_as_objects', $options) && $xmlrpc_val->scalartyp() == 'dateTime.iso8601') {
                // we return a Datetime object instead of a string
                // since now the constructor of xmlrpcval accepts safely strings, ints and datetimes,
                // we cater to all 3 cases here
                $out = $xmlrpc_val->scalarval();
                if (is_string($out)) {
                    $out = strtotime($out);
                }
                if (is_int($out)) {
                    $result = new Datetime();
                    $result->setTimestamp($out);
                    return $result;
                } elseif (is_a($out, 'Datetime')) {
                    return $out;
                }
            }
            return $xmlrpc_val->scalarval();
        case 'array':
            $size = $xmlrpc_val->arraysize();
            $arr = array();
            for ($i = 0; $i < $size; $i++) {
                $arr[] = php_xmlrpc_decode($xmlrpc_val->arraymem($i), $options);
            }
            return $arr;
        case 'struct':
            $xmlrpc_val->structreset();
            // If user said so, try to rebuild php objects for specific struct vals.
            /// @todo should we raise a warning for class not found?
            // shall we check for proper subclass of xmlrpcval instead of
            // presence of _php_class to detect what we can do?
            if (in_array('decode_php_objs', $options) && $xmlrpc_val->_php_class != '' && class_exists($xmlrpc_val->_php_class)) {
                $obj = @new $xmlrpc_val->_php_class();
                while (list($key, $value) = $xmlrpc_val->structeach()) {
                    $obj->{$key} = php_xmlrpc_decode($value, $options);
                }
                return $obj;
            } else {
                $arr = array();
                while (list($key, $value) = $xmlrpc_val->structeach()) {
                    $arr[$key] = php_xmlrpc_decode($value, $options);
                }
                return $arr;
            }
        case 'msg':
            $paramcount = $xmlrpc_val->getNumParams();
            $arr = array();
            for ($i = 0; $i < $paramcount; $i++) {
                $arr[] = php_xmlrpc_decode($xmlrpc_val->getParam($i));
            }
            return $arr;
    }
}
Exemple #17
0
            $values = array();
            $values[] = new xmlrpcval($val[0], 'int');
            $values[] = new xmlrpcval($val[1], 'double');
            $values[] = new xmlrpcval($val[2], 'string');
            $values[] = new xmlrpcval($val[3], 'boolean');
            $values[] = new xmlrpcval($val[4], 'dateTime.iso8601');
            $values[] = new xmlrpcval($val[5], 'int');
            $values[] = new xmlrpcval($val[6], 'double');
            $values[] = new xmlrpcval($val[7], 'string');
            $values[] = new xmlrpcval($val[8], 'boolean');
            $values[] = new xmlrpcval($val[9], 'dateTime.iso8601');
            $valarray[$key] = new xmlrpcval($values, 'array');
        }
        $vals[] = new xmlrpcval($valarray, 'struct');
    }
    $value = new xmlrpcval($vals, 'array');
    $out = $value->serialize();
}
end_test('Data encoding (large array)', 'manual encoding', $out);
begin_test('Data encoding (large array)', 'automatic encoding');
for ($i = 0; $i < $num_tests; $i++) {
    $value = php_xmlrpc_encode($data, array('auto_dates'));
    $out = $value->serialize();
}
end_test('Data encoding (large array)', 'automatic encoding', $out);
if (function_exists('xmlrpc_set_type')) {
    begin_test('Data encoding (large array)', 'xmlrpc-epi encoding');
    for ($i = 0; $i < $num_tests; $i++) {
        for ($j = 0; $j < 10; $j++) {
            foreach ($keys as $k) {
                xmlrpc_set_type($data[$j][$k][4], 'datetime');
Exemple #18
0
function agesorter($m)
{
    global $agesorter_arr, $xmlrpcerruser, $s;
    xmlrpc_debugmsg("Entering 'agesorter'");
    // get the parameter
    $sno = $m->getParam(0);
    // error string for [if|when] things go wrong
    $err = "";
    // create the output value
    $v = new xmlrpcval();
    $agar = array();
    if (isset($sno) && $sno->kindOf() == "array") {
        $max = $sno->arraysize();
        // TODO: create debug method to print can work once more
        // print "<!-- found $max array elements -->\n";
        for ($i = 0; $i < $max; $i++) {
            $rec = $sno->arraymem($i);
            if ($rec->kindOf() != "struct") {
                $err = "Found non-struct in array at element {$i}";
                break;
            }
            // extract name and age from struct
            $n = $rec->structmem("name");
            $a = $rec->structmem("age");
            // $n and $a are xmlrpcvals,
            // so get the scalarval from them
            $agar[$n->scalarval()] = $a->scalarval();
        }
        $agesorter_arr = $agar;
        // hack, must make global as uksort() won't
        // allow us to pass any other auxilliary information
        uksort($agesorter_arr, agesorter_compare);
        $outAr = array();
        while (list($key, $val) = each($agesorter_arr)) {
            // recreate each struct element
            $outAr[] = new xmlrpcval(array("name" => new xmlrpcval($key), "age" => new xmlrpcval($val, "int")), "struct");
        }
        // add this array to the output value
        $v->addArray($outAr);
    } else {
        $err = "Must be one parameter, an array of structs";
    }
    if ($err) {
        return new xmlrpcresp(0, $xmlrpcerruser, $err);
    } else {
        return new xmlrpcresp($v);
    }
}
Exemple #19
0
 /**
  * implements <i>samurai.SessionInitiate</i>
  *
  * @param string $LocalUri as SIP-URI
  * @param string $RemoteUri as SIP-URI
  * @param string $TOS Type of service as defined in $availableTOS
  * @param string $Content depends on TOS
  * @param dateTime $schedule as unix timestamp
  *
  * @return string SessionID, if available
  *
  * @throws sipgateAPI_Server_Exception on Server responses != 200 OK
  */
 protected function samurai_SessionInitiate($LocalUri, $RemoteUri, $TOS, $Content, $Schedule = NULL)
 {
     if (isset($LocalUri)) {
         $val_a["LocalUri"] = new xmlrpcval($LocalUri);
     }
     if (isset($RemoteUri)) {
         $val_a["RemoteUri"] = new xmlrpcval($RemoteUri);
     } else {
         throw new sipgateAPI_Exception("No RemoteUri");
     }
     if (isset($TOS)) {
         $val_a["TOS"] = new xmlrpcval($TOS);
     } else {
         throw new sipgateAPI_Exception("No valid TOS");
     }
     if (isset($Content)) {
         $val_a["Content"] = new xmlrpcval($Content);
     }
     if (isset($Schedule)) {
         $val_a["Schedule"] = new xmlrpcval(iso8601_encode($Schedule), "dateTime.iso8601");
     }
     $val_s = new xmlrpcval();
     $val_s->addStruct($val_a);
     $v = array();
     $v[] = $val_s;
     // create message
     $m = new xmlrpcmsg('samurai.SessionInitiate', $v);
     // send message
     $r = $this->client->send($m);
     if (!$r->faultCode()) {
         $php_r = php_xmlrpc_decode($r->value());
         return $php_r["SessionID"];
     } else {
         throw new sipgateAPI_Server_Exception($r->faultString(), $r->faultCode());
     }
 }