Пример #1
0
 function inputs()
 {
     $size = strlen($this->name) + 1;
     $this->global['size'] = [CY_TYPE_UINT32, 8 + $size];
     $binary = cy_pack(["global" => [CY_TYPE_OBJECT, $this->global], "version" => [CY_TYPE_UINT32, 0], "length" => [CY_TYPE_UINT32, $size], "name" => [CY_TYPE_STRING, $this->name . chr(0)]]);
     return $binary;
 }
Пример #2
0
 function inputs()
 {
     $key = self::$i_meta;
     $key['size'] = [CY_TYPE_UINT32, strlen($this->key)];
     $key['body'] = [CY_TYPE_STRING, $this->key];
     $this->global['size'] = [CY_TYPE_UINT32, 47 + strlen($this->key)];
     return cy_pack(["global" => [CY_TYPE_OBJECT, $this->global], "flag" => [CY_TYPE_UINT8, 0], "area" => [CY_TYPE_UINT16, $this->area], "count" => [CY_TYPE_UINT32, 1], "key" => [CY_TYPE_OBJECT, $key]]);
 }
Пример #3
0
 function inputs()
 {
     $key = self::$i_meta;
     $val = self::$i_meta;
     $key['size'] = [CY_TYPE_UINT32, strlen($this->key)];
     $key['body'] = [CY_TYPE_STRING, $this->key];
     $val['size'] = [CY_TYPE_UINT32, strlen($this->val)];
     $val['body'] = [CY_TYPE_STRING, $this->val];
     $this->global['size'] = [CY_TYPE_UINT32, 89 + strlen($this->key) + strlen($this->val)];
     return cy_pack(["global" => [CY_TYPE_OBJECT, $this->global], "flag" => [CY_TYPE_UINT8, 0], "area" => [CY_TYPE_UINT16, $this->area], "version" => [CY_TYPE_UINT16, 0], "expired" => [CY_TYPE_UINT32, $this->expired], "key" => [CY_TYPE_OBJECT, $key], "value" => [CY_TYPE_OBJECT, $val]]);
 }
Пример #4
0
 function run($client, $request = "")
 {
     $errno = 0;
     $error = '';
     $display = 'json';
     $b = cy_unpack($request, $this->config);
     if (!$b || empty($b['raw_header']) || empty($b['raw_len_head']) || $b['raw_len_head'] < 4) {
         $errno = CYE_PARAM_ERROR;
         $error = "invalid request.";
         goto error;
     }
     $r = cy_unpack($b['raw_header'], $this->config_head);
     $r['length'] = $b['raw_len_body'];
     $_ENV['module'] = $module = $r['module'];
     $_ENV['id'] = $id = $r['id'];
     $_ENV['method'] = $method = isset($r['method']) ? $r['method'] : 'get';
     $_ENV['display'] = $display = $r['fmt'];
     $_ENV['version'] = $version = isset($r['version']) ? $r['version'] : 1;
     $classname = 'CA_Entry_' . $module;
     if (!method_exists($classname, $method) && !method_exists($classname, '__call')) {
         $classname .= '_' . $method;
         $run = isset($_GET['a']) ? $_GET['a'] : 'run';
         if (!method_exists($classname, $run)) {
             $errno = CYE_PARAM_ERROR;
             $error = "method is not exists {$classname}:{$method}";
             goto error;
         }
     }
     switch ($display) {
         case 'raw':
             $req = $b['raw_body'];
             break;
         case 'json':
             $req = json_decode($b['raw_body'], true);
             if (empty($req)) {
                 $errno = json_last_error();
                 $error = json_last_error_msg();
                 goto error;
             }
             break;
         case 'mgp':
             $req = msgpack_unpack($b['raw_body']);
             $req = ['errno' => 0, 'data' => $data];
             break;
         default:
             $errno = -1;
             $error = 'unkown formant';
             break;
     }
     $eny = new $classname();
     $dt = $eny->get($id, $req, $_ENV);
     unset($eny);
     response:
     switch ($display) {
         case 'raw':
             $body = $dt;
             break;
         case 'json':
             $body = json_encode($dt);
             break;
         case 'mpg':
             $body = msgpack_pack($dt);
             break;
         default:
             $body = 'unknown format ' . $display;
             break;
     }
     if (empty($body) || !is_string($body)) {
         return ['errno' => 0, 'error' => 'error response body.'];
     }
     $hd = ['raw_len_head' => 0, 'raw_header' => ''];
     if (isset($b['raw_len_head'])) {
         $hd['raw_len_head'] = $b['raw_len_head'];
     }
     if (isset($b['raw_header'])) {
         $hd['raw_header'] = $b['raw_header'];
     }
     $inputs = array([CY_TYPE_UINT16, $hd['raw_len_head']], [CY_TYPE_STRING, $hd['raw_header']], [CY_TYPE_UINT16, strlen($body)], [CY_TYPE_STRING, $body]);
     return ['errno' => $errno, 'error' => $error, 'data' => cy_pack($inputs)];
     error:
     $dt = array('errno' => $errno, 'error' => $error);
     cy_log(CYE_WARNING, "{$client} " . $error);
     goto response;
 }