Ejemplo n.º 1
0
 /** @see \FutoIn\AdvancedCCM */
 public function cacheInit(\FutoIn\AsyncSteps $as)
 {
     // TODO:
     $as->error(\FutoIn\Error::NotImplemented);
 }
Ejemplo n.º 2
0
 /** @see \FutoIn\SimpleCCM */
 public function register(\FutoIn\AsyncSteps $as, $name, $ifacever, $endpoint, $credentials = null, $options = null)
 {
     // Unregister First
     if (array_key_exists($name, $this->iface_info)) {
         $as->error(\FutoIn\Error::InvokerError, "Already registered");
     }
     // Check ifacever
     if (!preg_match('/^(([a-z][a-z0-9]*)(\\.[a-z][a-z0-9]*)+):(([0-9]+)\\.([0-9]+))$/', $ifacever, $m)) {
         $as->error(\FutoIn\Error::InvokerError, "Invalid ifacever");
     }
     $iface = $m[1];
     $mjrmnr = $m[4];
     $mjr = $m[5];
     $mnr = $m[6];
     if (!is_string($endpoint)) {
         $as->error(\FutoIn\Error::InvokerError, "Invalid endpoint");
     }
     $endpoint = preg_replace('/^secure\\+/', '', $endpoint, 1, $repcnt);
     $secure_channel = $repcnt > 0;
     // Silently map WebSockets to HTTP/HTTPS as per FTN7 spec, if not supported
     $endpoint = preg_replace('/^ws(s?):\\/\\//', 'http${1}://', $endpoint);
     if (!$secure_channel && preg_match('/^(https|wss|unix):/', $endpoint)) {
         $secure_channel = true;
     }
     $url = parse_url($endpoint);
     if ($url['scheme'] === 'self') {
         $impl = str_replace('.', '\\', $url['host']);
     } else {
         $impl = "\\FutoIn\\RI\\Invoker\\Details\\NativeInterface";
     }
     $options = array_merge((array) $options, $this->impl->options);
     $info = new Details\RegistrationInfo();
     $info->iface = $iface;
     $info->version = $mjrmnr;
     $info->mjrver = $mjr;
     $info->mnrver = $mnr;
     $info->endpoint = $endpoint;
     $info->creds = $credentials;
     $info->secure_channel = $secure_channel;
     $info->impl = $impl;
     $info->regname = $name;
     $info->options =& $options;
     $this->iface_info[$name] = $info;
     $this->impl->onRegister($as, $info);
     $as->add(function ($as) use($name, $ifacever, $info) {
         if (!$info->simple_req) {
             if (!isset($info->constraints['AllowAnonymous']) && !$info->creds) {
                 $as->error(\FutoIn\Error::SecurityError, "Requires authenticated user");
             }
             if (isset($info->constraints['SecureChannel']) && !$info->secure_channel) {
                 $as->error(\FutoIn\Error::SecurityError, "SecureChannel is required");
             }
             if (isset($info->constraints['MessageSignature']) && !$info->creds_master && !$info->creds_hmac) {
                 $as->error(\FutoIn\Error::SecurityError, "SecureChannel is required");
             }
             if (isset($info->constraints['BiDirectChannel']) && !false) {
                 $as->error(\FutoIn\Error::InvokerError, "BiDirectChannel is required");
             }
         }
         $this->emit('register', [$name, $ifacever, $info]);
     });
 }
Ejemplo n.º 3
0
 public function onDataResponse(\FutoIn\AsyncSteps $as, $ctx)
 {
     if ($ctx->info->funcs[$ctx->name]->rawresult) {
         $as->success($as->_futoin_response);
     } else {
         $as->error(\FutoIn\Error::InternalError, "Raw result is not expected");
     }
 }
Ejemplo n.º 4
0
 public function onMessageResponse(\FutoIn\AsyncSteps $as, $ctx, $rsp)
 {
     if (isset($rsp->e)) {
         $as->error($rsp->e);
     } else {
         $as->success($rsp->r);
     }
 }
Ejemplo n.º 5
0
 public static function checkFutoInType(\FutoIn\AsyncSteps $as, $type, $var, $val)
 {
     $rtype = '';
     switch ($type) {
         case 'boolean':
         case 'integer':
         case 'string':
         case 'array':
             $rtype = $type;
             break;
         case 'map':
             $rtype = 'object';
             break;
         case 'number':
             $rtype = 'string';
             break;
     }
     if (gettype($val) !== $rtype) {
         $as->error(\FutoIn\Error::InvalidRequest, "Type mismatch for parameter");
     }
 }