}
        $capability = trim($request['cap']);
        $operation = trim($request['RequestMethod']);
    }
}
log_message('debug', sprintf("cap=%s, op=%s, request=%s", $capability, $operation, json_encode($request)));
// --------------- validate the capability ---------------
if (!empty($config['authorize_commands'])) {
    if (!UUID::TryParse($capability, $capid)) {
        log_message('warn', sprintf("invalid uuid %s", $capability));
        RequestFailed('Invalid capability');
    }
    $cap = get_capability($capability);
    if ($cap == null) {
        log_message('warn', sprintf("invalid capability %s", $capability));
        RequestFailed('Invalid capability');
    }
    // log_message('debug',sprintf("Capability=%s",json_encode($cap)));
}
// execute_command($operation, $capability, $request);
if (file_exists(BASEPATH . "lib/Class.{$operation}.php")) {
    if (include_once BASEPATH . "lib/Class.{$operation}.php") {
        $gMethodName = $operation;
        $instance = new $operation();
        $instance->Execute($request);
        exit;
    }
}
log_message('warn', sprintf("unknown operation %s", $operation));
RequestFailed('No such operation');
 public function Execute($params)
 {
     if (!isset($params["mesh_id"]) || !UUID::TryParse($params["mesh_id"], $meshID)) {
         RequestFailed('invalid or missing mesh identifier');
     }
     $meshfile = $this->ComputeMeshFile($meshID);
     // Check to see if we already have the file
     if (!file_exists($meshfile)) {
         // There is definitely a race condition here, the time between the check for an existing
         // file and acquiring a lock opens up the potential for overwriting the file
         $handle = fopen($meshfile, "wb");
         if (!flock($handle, LOCK_EX)) {
             fclose($handle);
             unlink($meshfile);
             RequestFailed('unable to acquire lock on cache file');
         }
         // Pull it back from the asset service and store it locally
         if (!get_asset($meshID, $meshInfo)) {
             flock($handle, LOCK_UN);
             fclose($handle);
             unlink($meshfile);
             log_message('error', "[GetMesh] mesh {$meshID} not found");
             print_r($meshInfo);
             RequestFailed('mesh not found');
         }
         //content type check
         if (empty(self::$MeshTypes[$meshInfo['ContentType']])) {
             flock($handle, LOCK_UN);
             fclose($handle);
             unlink($texturefile);
             log_message('error', sprintf('[GetMesh] wrong asset type; %s', $meshInfo['ContentType']));
             RequestFailed(sprintf('wrong asset type; %s', $meshInfo['ContentType']));
         }
         if (!fwrite($handle, $meshInfo['Content'])) {
             flock($handle, LOCK_UN);
             fclose($handle);
             unlink($meshfile);
             log_message('error', '[GetMesh] write to file failed');
             RequestFailed('unable to write cache file');
         }
         flock($handle, LOCK_UN);
         fclose($handle);
     }
     $this->SendMeshFile($meshID, $meshfile);
 }