Exemplo n.º 1
0
 /**
  * validate jsonp request testing for request parameter to be valid and checking all
  * additional parameters
  *
  * @error 14705
  * @param array $call expects the call to validate
  * @return void
  * @throws Xapp_Rpc_Fault
  */
 protected function validate($call)
 {
     $get = $this->request()->getGet();
     $service = null;
     if ($this->smd()->has($call[2], $call[1])) {
         if ($call[2] !== null) {
             $service = $this->smd()->get($call[2] . '.' . $call[1]);
         } else {
             $service = $this->smd()->get($call[1]);
         }
     } else {
         Xapp_Rpc_Fault::t("method or function is not registered as service", array(1470501, -32601));
     }
     if (!empty($service->parameters)) {
         foreach ($service->parameters as $k => $v) {
             if (!$v->optional && (!array_key_exists($v->name, $get) || !xapp_is_value($get[$v->name]))) {
                 Xapp_Rpc_Fault::t(xapp_sprintf("param: %s must be set", array($v->name)), array(1470503, -32602));
             }
             if (isset($v->type) && array_key_exists($v->name, $get) && !in_array('mixed', (array) $v->type) && !in_array(xapp_type($get[$v->name], true), (array) $v->type)) {
                 Xapp_Rpc_Fault::t(xapp_sprintf("param: %s must be of the following types: %s", array($v->name, implode('|', (array) $v->type))), array(1470504, -32602));
             }
         }
     }
     if (xapp_is_option(self::ADDITIONAL_PARAMETERS, $this)) {
         foreach (xapp_get_option(self::ADDITIONAL_PARAMETERS, $this) as $k => $v) {
             $type = isset($v[0]) ? (array) $v[0] : false;
             $optional = isset($v[1]) ? (bool) $v[1] : true;
             if (!$optional && !array_key_exists($k, $get)) {
                 Xapp_Rpc_Fault::t(xapp_sprintf("additional param: %s must be set", array($k)), array(1470505, -32602));
             }
             if ($type && !in_array('mixed', $type) && !in_array(xapp_type($get[$k], true), $type)) {
                 Xapp_Rpc_Fault::t(xapp_sprintf("additional param: %s must be of the following types: %s", array($k, implode('|', $type))), array(1470506, -32602));
             }
         }
     }
 }
Exemplo n.º 2
0
 /**
  * set any value to object at any point in object structure defined by second parameter which can be a path or
  * path/query array value. the fourth parameter defines if the object is extendable that when nothing was found at
  * path/query the value will be created/append there. the fifth parameter is an optional position value, see
  * Xapp_Util_Std_Query::set for more details. the last optional parameter defines whether the value will only be set
  * /overwritten if the to be replaced value is of the same type. will throw result exception if path/query does not
  * return any value and fourth parameter is to false
  *
  * @error 17021
  * @see Xapp_Util_Std_Query::find
  * @see Xapp_Util_Std_Query::retrieve
  * @param object $object expects the object to set values to
  * @param null|string|array $mixed expects either null for connected query call, string for path or array for path/query
  * @param null|mixed $value expects the value to set at second parameter
  * @param bool $extend expects optional extend value as explained above
  * @param null|string|int $position expects optional set position as explained in Xapp_Util_Std_Query::set
  * @param bool $typesafe expects optional typesafe value as explained above
  * @throws Xapp_Result_Exception
  * @throws Xapp_Util_Std_Exception
  */
 public static function _set(&$object, $mixed = null, $value = null, $extend = true, $position = null, $typesafe = false)
 {
     $last = null;
     $parent = null;
     $extend = (bool) $extend;
     $typesafe = (bool) $typesafe;
     if ($mixed === null) {
         $mixed = '';
     } else {
         if (is_array($mixed)) {
             $mixed[0] = trim($mixed[0], './* ');
         } else {
             if (is_string($mixed)) {
                 $mixed = trim($mixed, './* ');
             }
         }
     }
     try {
         if ($value === '__REMOVE__' && is_string($mixed)) {
             if (substr($mixed, 0, 1) !== '/' && strpos($mixed, '/') !== false) {
                 $last = substr($mixed, strrpos($mixed, '/') + 1);
                 $mixed = substr($mixed, 0, strrpos($mixed, '/'));
             } else {
                 $last = $mixed;
                 $mixed = '';
             }
         }
         if (is_array($mixed) && sizeof($mixed) >= 2) {
             if (array_key_exists(2, $mixed)) {
                 $mixed[2] = strtolower(trim((string) $mixed[2]));
             } else {
                 $mixed[2] = 'first';
             }
             $result =& Xapp_Util_Std_Query::find($object, $mixed[0], (array) $mixed[1], $mixed[2], $parent);
         } else {
             $result =& Xapp_Util_Std_Query::retrieve($object, $mixed, false, $parent);
         }
     } catch (Xapp_Result_Exception $e) {
         $result = false;
     }
     if ($result !== false) {
         if (is_array($result)) {
             if ($value === '__REMOVE__') {
                 unset($result[(int) $last]);
             } else {
                 if ($value === '__RESET__') {
                     $result = null;
                 } else {
                     if ($value === '__SERIALIZE__') {
                         $result = self::encode($result);
                     } else {
                         if ($position !== null) {
                             if ($position === -1 || $position === 'last') {
                                 array_push($result, $value);
                             } else {
                                 if ($position === 0 || $position === 'first') {
                                     array_unshift($result, $value);
                                 } else {
                                     if (is_int($position)) {
                                         if ($position < sizeof($result)) {
                                             array_splice($result, $position, 0, array($value));
                                         } else {
                                             array_push($result, $value);
                                         }
                                     }
                                 }
                             }
                         } else {
                             if ($typesafe) {
                                 if (xapp_type($result) === xapp_type($value)) {
                                     $result = $value;
                                 } else {
                                     throw new Xapp_Util_Std_Exception(_("value found at path can not be overwritten due to typesafe protection"), 1702101);
                                 }
                             } else {
                                 $result = $value;
                             }
                         }
                     }
                 }
             }
         } else {
             if ($value === '__REMOVE__') {
                 unset($result->{$last});
             } else {
                 if ($value === '__RESET__') {
                     $result = null;
                 } else {
                     if ($value === '__SERIALIZE__') {
                         $result = self::encode($result);
                     } else {
                         if ($position !== null) {
                             if ($position === -1 || $position === 'last') {
                                 $result = (object) array_merge((array) $result, (array) $value);
                             } else {
                                 if ($position === 0 || $position === 'first') {
                                     $result = (object) array_merge((array) $value, (array) $result);
                                 } else {
                                     if (is_int($position)) {
                                         if ($position < sizeof((array) $result)) {
                                             $result = (object) array_merge(array_slice((array) $result, 0, $position), (array) $value, array_slice((array) $result, $position));
                                         } else {
                                             $result = (object) array_merge((array) $result, (array) $value);
                                         }
                                     }
                                 }
                             }
                         } else {
                             if ($typesafe) {
                                 if (xapp_type($result) === xapp_type($value)) {
                                     $result = $value;
                                 } else {
                                     throw new Xapp_Util_Std_Exception(_("value found at path can not be overwritten due to typesafe protection"), 1702101);
                                 }
                             } else {
                                 $result = $value;
                             }
                         }
                     }
                 }
             }
         }
     } else {
         if ($extend && is_object($parent)) {
             $parent->{trim(substr($mixed, strrpos($mixed, '/') + 1))} = $value;
         } else {
             throw new Xapp_Result_Exception(_("no result found for query"), 1702102);
         }
     }
 }
Exemplo n.º 3
0
 /**
  * validate json request object testing all request object parameters for validity. also checking all additional
  * parameters for validity and throwing fault if necessary
  *
  * @error 14604
  * @param array $call expects the call to validate
  * @return void
  * @throws Xapp_Rpc_Fault
  */
 protected function validate($call)
 {
     if (!xapp_get_option(self::VALIDATE, $this)) {
         return;
     }
     if ($this->request()->isPost()) {
         if ($this->request()->getRaw() === "") {
             Xapp_Rpc_Fault::t("empty or invalid request object", array(1460401, -32600));
         }
         if ($this->request()->getVersion($call[3]) != xapp_get_option(self::VERSION, $this)) {
             Xapp_Rpc_Fault::t("rpc version not set or version miss match", array(1460402, -32013));
         }
         if (!xapp_get_option(self::ALLOW_NOTIFICATIONS, $this) || array_key_exists('id', $call[3])) {
             if (!array_key_exists('id', $call[3])) {
                 Xapp_Rpc_Fault::t("rpc transaction id must be set", array(1460405, -32015));
             }
             if (!is_numeric($call[3]['id']) && !is_string($call[3]['id'])) {
                 Xapp_Rpc_Fault::t("rpc transaction id must be string or integer", array(1460406, -32016));
             }
             if (xapp_is_option(self::TRANSACTION_ID_REGEX, $this) && !preg_match(trim((string) xapp_get_option(self::TRANSACTION_ID_REGEX, $this)), $call[3]['id'])) {
                 Xapp_Rpc_Fault::t("rpc transaction id does not match transaction id regex pattern", array(1460411, -32017));
             }
         }
         if (!xapp_get_option(self::ALLOW_FUNCTIONS, $this) && empty($call[2])) {
             Xapp_Rpc_Fault::t("php functions as service are not supported by this rpc service", 1460412, -32018);
         }
         if (!array_key_exists('method', $call[3])) {
             Xapp_Rpc_Fault::t("rpc method must be set", array(1460403, -32014));
         }
         if (!$this->smd()->has($call[2], $call[1])) {
             Xapp_Rpc_Fault::t("method or function is not registered as service", array(1460404, -32601));
         }
         if (!is_null($call[2])) {
             $service = $this->smd()->get($call[2] . '.' . $call[1]);
         } else {
             $service = $this->smd()->get($call[1]);
         }
         if (!empty($service->parameters)) {
             $params = array_key_exists('params', $call[3]) ? $call[3]['params'] : null;
             $p = (array) $params;
             $k = is_null($params) || array_values($p) !== $p ? 'n' : 'i';
             $i = 0;
             foreach ($service->parameters as $v) {
                 $n = $v->name;
                 if (!$v->optional && (!array_key_exists(${$k}, $p) || !xapp_is_value($p[${$k}]))) {
                     Xapp_Rpc_Fault::t(xapp_sprintf("param: %s must be set", array(${$k})), array(1460407, -32602));
                 }
                 if (isset($v->type) && array_key_exists(${$k}, $p) && !in_array('mixed', (array) $v->type) && !in_array(xapp_type($p[${$k}]), (array) $v->type)) {
                     Xapp_Rpc_Fault::t(xapp_sprintf("param: %s must be of the following types: %s", array(${$k}, implode('|', (array) $v->type))), array(1460408, -32602));
                 }
                 $i++;
             }
         }
         if (xapp_is_option(self::ADDITIONAL_PARAMETERS, $this)) {
             foreach (xapp_get_option(self::ADDITIONAL_PARAMETERS, $this) as $k => $v) {
                 $type = isset($v[0]) ? (array) $v[0] : false;
                 $optional = isset($v[1]) ? (bool) $v[1] : true;
                 if (!$optional && !$this->request()->hasParam($k)) {
                     Xapp_Rpc_Fault::t(xapp_sprintf("additional param: %s must be set", array($k)), array(1460409, -32602));
                 }
                 if ($type && !in_array('mixed', $type) && !in_array(xapp_type($this->request()->getParam($k)), $type)) {
                     Xapp_Rpc_Fault::t(xapp_sprintf("additional param: %s must be of the following types: %s", array($k, implode('|', $type))), array(1460410, -32602));
                 }
             }
         }
     }
 }