Skip to content
Snippets Groups Projects
Commit 9128900c authored by Thomas Müller's avatar Thomas Müller
Browse files

drop files_irods from apps_external

parent 727e3e23
No related branches found
No related tags found
No related merge requests found
Showing
with 0 additions and 4528 deletions
iRODS license terms and copyright info from the irods site at: https://www.irods.org/index.php/License
License
iRODS Copyright and Licensing
iRODS is open source software released under a BSD License, see license text in "iRODS License Terms and Conditions" below.
The BSD license has been described in very general terms as allowing you to do whatever you want to with the software and
source code as long as you acknowledge who wrote it and that, as with any open source software, there is no warranty and you're using the code "as is."
In the spirit of collaborative open source software, the iRODS community encourages you to communicate with us, letting us know what features you like,
features that would be useful, problems, bugs, suggestions, etc., and to perhaps contribute source code.
The iRODS community has formed the Data Intensive Cyberinfrastructure Foundation, a 501(c)(3) nonprofit corporation established to serve
as the home of the iRODS open source community over the long term. If you choose to contribute new code, you'll receive full acknowledgment. All you do is complete the Contributor's Agreement, under which you retain copyright ownership
in your code but give a free license to the iRODS nonprofit foundation, allowing your code to be integrated into iRODS and in turn released under the BSD license.
Note: The above text is an educational overview of iRODS open source licensing, and not intended as legal advice nor is it part of the iRODS license agreement, which is below. As always, for legal advice consult an attorney.
iRODS License Terms and Conditions Notice
Copyright (c) 2005-2011, Regents of the University of California, the University of North Carolina, and the Data Intensive Cyberinfrastructure Foundation
All rights reserved.
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
Neither the name of the University of California, San Diego (UCSD) nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT
NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
\ No newline at end of file
;; phpDocumentor demonstration parse configuration file
;;
;; RUN THIS FILE FROM THE INSTALL DIRECTORY
;; CHANGE HERE:
;; where should the documentation be written?
;; legal values: a legal path
;target = /home/CelloG/output
target = ./doc
;; DONT CHANGE BELOW HERE
;;
;; This file is designed to cut down on repetitive typing on the command-line or web interface
;; You can copy this file to create a number of configuration files that can be used with the
;; command-line switch -c, as in phpdoc -c default.ini or phpdoc -c myini.ini. The web
;; interface will automatically generate a list of .ini files that can be used.
;;
;; ALL .ini files must be in the user subdirectory of phpDocumentor with an extension of .ini
;;
;; Copyright 2002, Greg Beaver <cellog@php.net>
;;
;; WARNING: do not change the
[Parse Data]
;; title of all the documentation
;; legal values: any string
title = PRODS (iRODS PHP Client API) Documentation
;; parse files that start with a . like .bash_profile
;; legal values: true, false
hidden = false
;; show elements marked @access private in documentation by setting this to on
;; legal values: on, off
parseprivate = off
;; parse with javadoc-like description (first sentence is always the short description)
;; legal values: on, off
javadocdesc = on
;target=/dev/null
;; add any custom @tags separated by commas here
;; legal values: any legal tagname separated by commas.
;customtags = mytag1,mytag2
;; what is the main package?
;; legal values: alphanumeric string plus - and _
defaultpackagename = Prods
;; output any parsing information? set to on for cron jobs
;; legal values: on
;quiet = on
;; limit output to the specified packages, even if others are parsed
;; legal values: package names separated by commas
;packageoutput = package1,package2
;; comma-separated list of files to parse
;; legal values: paths separated by commas
;filename = /path/to/file1,/path/to/file2,fileincurrentdirectory
;; comma-separated list of directories to parse
;; legal values: directory paths separated by commas
;directory = /path1,/path2,.,..,subdirectory
;directory = /home/jeichorn/cvs/pear
;directory = /you-MUST/change-me/to-fit/your-environment
;directory = .
directory = ./src,./tutorials
;; comma-separated list of files, directories or wildcards ? and * (any wildcard) to ignore
;; legal values: any wildcard strings separated by commas
;; remember, this pathing is RELATIVE to the top-most directory in your "directory" value
;ignore = path/to/ignore*,*list.php,myfile.php,subdirectory/
ignore = templates_c/,*HTML/default/*,spec/,*.inc.php,packet/,set*.php,ProdsStreamer.class.php,RODSMessage.class.php,RODSConn.class.php,RODSKeyValPair.class.php,RODSConnManager.class.php
;; comma-separated list of Converters to use in outputformat:Convertername:templatedirectory format
;; legal values: HTML:frames:default,HTML:frames:l0l33t,HTML:frames:phpdoc.de,HTML:frames:phphtmllib
;; HTML:frames:phpedit,HTML:frames:DOM/default,HTML:frames:DOM/l0l33t,HTML:frames:DOM/phpdoc.de
;; HTML:Smarty:default,HTML:Smarty:PHP,PDF:default:default,CHM:default:default,XML:DocBook:default
output=HTML:Smarty:PHP
;; turn this option on if you want highlighted source code for every file
;; legal values: on/off
sourcecode = on
*'''Project''': PHP Prods API for iRODS
*'''Date''': 06/04/2013
*'''Release Version''': 3.3.0-beta1
*'''git tag''': 3.3.0-beta1
==News==
PHP API for iRODS
This alpha is a merge of community supported additions for PAM and tickets
GForge for iDrop-swing is at: [[https://code.renci.org/gf/project/irodsphp/]]
==Requirements==
Note that the following bug and feature requests are logged in GForge with related commit information [[https://code.renci.org/gf/project/irodsphp/tracker/]]
==Features==
*[#1280] Add PAM support to PHP
*[#1122] Add Ticket support to PHP
==Bug Fixes==
==Outstanding Issues==
Please consult [[https://code.renci.org/gf/project/irodsphp/tracker/]]
for the latest open bugs and Jargon feature requests
iRODS license terms and copyright info from the irods site at: https://www.irods.org/index.php/License
License
iRODS Copyright and Licensing
iRODS is open source software released under a BSD License, see license text in "iRODS License Terms and Conditions" below.
The BSD license has been described in very general terms as allowing you to do whatever you want to with the software and
source code as long as you acknowledge who wrote it and that, as with any open source software, there is no warranty and you're using the code "as is."
In the spirit of collaborative open source software, the iRODS community encourages you to communicate with us, letting us know what features you like,
features that would be useful, problems, bugs, suggestions, etc., and to perhaps contribute source code.
The iRODS community has formed the Data Intensive Cyberinfrastructure Foundation, a 501(c)(3) nonprofit corporation established to serve
as the home of the iRODS open source community over the long term. If you choose to contribute new code, you'll receive full acknowledgment. All you do is complete the Contributor's Agreement, under which you retain copyright ownership
in your code but give a free license to the iRODS nonprofit foundation, allowing your code to be integrated into iRODS and in turn released under the BSD license.
Note: The above text is an educational overview of iRODS open source licensing, and not intended as legal advice nor is it part of the iRODS license agreement, which is below. As always, for legal advice consult an attorney.
iRODS License Terms and Conditions Notice
Copyright (c) 2005-2011, Regents of the University of California, the University of North Carolina, and the Data Intensive Cyberinfrastructure Foundation
All rights reserved.
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
Neither the name of the University of California, San Diego (UCSD) nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT
NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
\ No newline at end of file
<?php
require_once("autoload.inc.php");
require_once("ProdsConfig.inc.php");
<?php
/**#@+
* Constants
*/
define("RODS_REL_VERSION", 'rods1.1');
define("RODS_API_VERSION", 'd');
/**#@-*/
if (file_exists(__DIR__ . "/prods.ini")) {
$GLOBALS['PRODS_CONFIG'] = parse_ini_file(__DIR__ . "/prods.ini", true);
}
else {
$GLOBALS['PRODS_CONFIG'] = array();
}
This diff is collapsed.
<?php
/**
* PRODS file class
* @author Sifang Lu <sifang@sdsc.edu>
* @copyright Copyright &copy; 2007, TBD
* @package Prods
*/
require_once("autoload.inc.php");
class ProdsFile extends ProdsPath
{
public $stats;
private $rodsconn; //real RODS connection
private $l1desc; //lvl 1 descriptor on RODS server
private $conn; //the connection to RODS agent l1desc lives on.
private $rescname; //resource name.
private $openmode; //open mode used if file is opened
private $position; //current position of the file, if opened.
/**
* The class constructor
*/
public function __construct(RODSAccount &$account, $path_str,
$verify = false, RODSFileStats $stats = NULL)
{
$this->l1desc = -1;
$this->stats = $stats;
if ($path_str{strlen($path_str) - 1} == '/') {
throw new RODSException("Invalid file name '$path_str' ",
'PERR_USER_INPUT_PATH_ERROR');
}
parent::__construct($account, $path_str);
if ($verify === true) {
if ($this->exists() === false) {
throw new RODSException("File '$this' does not exist",
'PERR_PATH_DOES_NOT_EXISTS');
}
}
}
/**
* Create a new ProdsFile object from URI string.
* @param string $path the URI Sting
* @param boolean $verify whether verify if the path exsits
* @return a new ProdsDir
*/
public static function fromURI($path, $verify=false)
{
if (0!=strncmp($path,"rods://",7))
$path="rods://".$path;
$url=parse_url($path);
$host=isset($url['host'])?$url['host']:'';
$port=isset($url['port'])?$url['port']:'';
$user='';
$zone='';
$authtype='irods';
if (isset($url['user']))
{
if (strstr($url['user'],".")!==false) {
$user_array=@explode(".",$url['user']);
if (count($user_array)===3) {
$user=$user_array[0];
$zone=$user_array[1];
$authtype=$user_array[2];
}
else {
$user=$user_array[0];
$zone=$user_array[1];
}
}
else
$user=$url['user'];
}
$pass=isset($url['pass'])?$url['pass']:'';
$account=new RODSAccount($host, $port, $user, $pass, $zone, '', $authtype);
$path_str=isset($url['path'])?$url['path']:'';
// treat query and fragment as part of name
if (isset($url['query'])&&(strlen($url['query'])>0))
$path_str=$path_str.'?'.$url['query'];
if (isset($url['fragment'])&&(strlen($url['fragment'])>0))
$path_str=$path_str.'#'.$url['fragment'];
if (empty($path_str))
$path_str='/';
return (new ProdsFile($account,$path_str,$verify));
}
/**
* Verify if this file exist with server. This function shouldn't be called directly, use {@link exists}
*/
protected function verify()
{
$conn = RODSConnManager::getConn($this->account);
$this->path_exists= $conn -> fileExists ($this->path_str);
RODSConnManager::releaseConn($conn);
}
/**
* get the file stats
*/
public function getStats()
{
$conn = RODSConnManager::getConn($this->account);
$stats=$conn->getFileStats($this->path_str);
RODSConnManager::releaseConn($conn);
if ($stats===false) $this->stats=NULL;
else $this->stats=$stats;
return $this->stats;
}
/**
* Open a file path (string) exists on RODS server.
*
* @param string $mode open mode. Supported modes are:
* - 'r' Open for reading only; place the file pointer at the beginning of the file.
* - 'r+' Open for reading and writing; place the file pointer at the beginning of the file.
* - 'w' Open for writing only; place the file pointer at the beginning of the file and truncate the file to zero length. If the file does not exist, attempt to create it.
* - 'w+' Open for reading and writing; place the file pointer at the beginning of the file and truncate the file to zero length. If the file does not exist, attempt to create it.
* - 'a' Open for writing only; place the file pointer at the end of the file. If the file does not exist, attempt to create it.
* - 'a+' Open for reading and writing; place the file pointer at the end of the file. If the file does not exist, attempt to create it.
* - 'x' Create and open for writing only; place the file pointer at the beginning of the file. If the file already exists, the fopen() call will fail by returning FALSE and generating an error of level E_WARNING. If the file does not exist, attempt to create it. This is equivalent to specifying O_EXCL|O_CREAT flags for the underlying open(2) system call.
* - 'x+' Create and open for reading and writing; place the file pointer at the beginning of the file. If the file already exists, the fopen() call will fail by returning FALSE and generating an error of level E_WARNING. If the file does not exist, attempt to create it. This is equivalent to specifying O_EXCL|O_CREAT flags for the underlying open(2) system call.
* @param string $rescname. Note that this parameter is required only if the file does not exists (create mode). If the file already exists, and if file resource is unknown or unique or you-dont-care for that file, leave the field, or pass NULL.
* @param boolean $assum_file_exists. This parameter specifies whether file exists. If the value is false, this mothod will check with RODS server to make sure. If value is true, the check will NOT be done. Default value is false.
* @param string $filetype. This parameter only make sense when you want to specify the file type, if file does not exists (create mode). If not specified, it defaults to "generic"
* @param integer $cmode. This parameter is only used for "createmode". It specifies the file mode on physical storage system (RODS vault), in octal 4 digit format. For instance, 0644 is owner readable/writeable, and nothing else. 0777 is all readable, writable, and excutable. If not specified, and the open flag requirs create mode, it defaults to 0644.
*/
public function open($mode, $rescname = NULL,
$assum_file_exists = false, $filetype = 'generic', $cmode = 0644)
{
if ($this->l1desc >= 0)
return;
if (!empty($rescname))
$this->rescname = $rescname;
$this->conn = RODSConnManager::getConn($this->account);
$this->l1desc = $this->conn->openFileDesc($this->path_str, $mode,
$this->postion, $rescname, $assum_file_exists, $filetype, $cmode);
$this->openmode = $mode;
RODSConnManager::releaseConn($this->conn);
}
/**
* get the file open mode, if opened previously
* @return string open mode, if not opened, it return NULL
*/
public function getOpenmode()
{
return $this->openmode;
}
/**
* get the file current position, if opened previously
* @return string open mode, if not opened, it return NULL
*/
public function tell()
{
return $this->position;
}
/**
* unlink the file on server
* @param string $rescname resource name. Not required if there is no other replica.
* @param boolean $force flag (true or false) indicating whether force delete or not.
*/
public function unlink($rescname = NULL, $force = false)
{
$conn = RODSConnManager::getConn($this->account);
$conn->fileUnlink($this->path_str, $rescname, $force);
RODSConnManager::releaseConn($conn);
}
/**
* close the file descriptor (private) made from RODS server earlier.
*/
public function close()
{
if ($this->l1desc >= 0) {
while ($this->conn->isIdle() === false) {
trigger_error("The connection is not available! sleep for a while and retry...",
E_USER_WARNING);
usleep(50);
}
$this->conn->lock();
$this->conn->closeFileDesc($this->l1desc);
$this->conn->unlock();
$this->conn = null; //release the connection
$this->l1desc = -1;
}
}
/**
* reads up to length bytes from the file. Reading stops when up to length bytes have been read, EOF (end of file) is reached
*
* @param int $length up to how many bytes to read.
* @return the read string.
*/
public function read($length)
{
if ($this->l1desc < 0) {
throw new RODSException("File '$this' is not opened! l1desc=$this->l1desc",
'PERR_USER_INPUT_ERROR');
}
while ($this->conn->isIdle() === false) {
trigger_error("The connection is not available! sleep for a while and retry...",
E_USER_WARNING);
usleep(50);
}
$this->conn->lock();
$retval = $this->conn->fileRead($this->l1desc, $length);
$this->position = $this->position + strlen($retval);
$this->conn->unlock();
return $retval;
}
/**
* write up to length bytes to the server. this function is binary safe.
* @param string $string contents to be written.
* @param int $length up to how many bytes to write.
* @return the number of bytes written.
*/
public function write($string, $length = NULL)
{
if ($this->l1desc < 0) {
throw new RODSException("File '$this' is not opened! l1desc=$this->l1desc",
'PERR_USER_INPUT_ERROR');
}
while ($this->conn->isIdle() === false) {
trigger_error("The connection is not available! sleep for a while and retry...",
E_USER_WARNING);
usleep(50);
}
$this->conn->lock();
$retval = $this->conn->fileWrite($this->l1desc, $string, $length);
$this->position = $this->position + (int)$retval;
$this->conn->unlock();
return $retval;
}
/**
* Sets the file position for the file. The new position, measured in bytes from the beginning of the file, is obtained by adding offset to the position specified by whence, whose values are defined as follows:
* SEEK_SET - Set position equal to offset bytes.
* SEEK_CUR - Set position to current location plus offset.
* SEEK_END - Set position to end-of-file plus offset. (To move to a position before the end-of-file, you need to pass a negative value in offset.)
* If whence is not specified, it is assumed to be SEEK_SET.
* @return int the current offset
*/
public function seek($offset, $whence = SEEK_SET)
{
if ($this->l1desc < 0) {
throw new RODSException("File '$this' is not opened! l1desc=$this->l1desc",
'PERR_USER_INPUT_ERROR');
}
while ($this->conn->isIdle() === false) {
trigger_error("The connection is not available! sleep for a while and retry...",
E_USER_WARNING);
usleep(50);
}
$this->conn->lock();
$retval = $this->conn->fileSeek($this->l1desc, $offset, $whence);
$this->position = (int)$retval;
$this->conn->unlock();
return $retval;
}
/**
* Sets the file position to the beginning of the file stream.
*/
public function rewind()
{
while ($this->conn->isIdle() === false) {
trigger_error("The connection is not available! sleep for a while and retry...",
E_USER_WARNING);
usleep(50);
}
$this->seek(0, SEEK_SET);
$this->position = 0;
}
/**
* get the file descriptor (private) made from RODS server earlier.
*/
public function getL1desc()
{
return $this->l1desc;
}
/**
* Because RODS server can only do file operations in a single connection, a RODS
* connection is 'reserved' when file is opened, and released when closed.
*/
public function getConn()
{
return $this->conn;
}
/**
* Replicate file to resources with options.
* @param string $desc_resc destination resource
* @param array $options an assosive array of options:
* - 'all' (boolean): only meaningful if input resource is a resource group. Replicate to all the resources in the resource group.
* - 'backupMode' (boolean): if a good copy already exists in this resource, don't make another copy.
* - 'admin' (boolean): admin user uses this option to backup/replicate other users files
* - 'replNum' (integer): the replica to copy, typically not needed
* - 'srcResc' (string): specifies the source resource of the data object to be replicate, only copies stored in this resource will be replicated. Otherwise, one of the copy will be replicated
* These options are all 'optional', if omitted, the server will try to do it anyway
* @return number of bytes written if success, in case of faliure, throw an exception
*/
public function repl($desc_resc, array $options = array())
{
$conn = RODSConnManager::getConn($this->account);
$bytesWritten = $conn->repl($this->path_str, $desc_resc, $options);
RODSConnManager::releaseConn($conn);
return $bytesWritten;
}
/**
* get replica information for this file
* @return array of array, each child array is a associative and contains:
* [repl_num] : replica number
* [chk_sum] : checksum of the file
* [size] : size of the file (replica)
* [resc_name] : resource name
* [resc_repl_status] : replica status (dirty bit), whether this replica is dirty (modifed), and requirs synchs to other replicas.
* [resc_grp_name] : resource group name
* [resc_type] : resource type name
* [resc_class] : resource class name
* [resc_loc] : resource location
* [resc_freespace]: resource freespace
* [data_status] : data status
* [ctime] : data creation time (unix timestamp)
* [mtime] : data last modified time (unix timestamp)
*/
public function getReplInfo()
{
$select = new RODSGenQueSelFlds(
array("COL_DATA_REPL_NUM", "COL_D_DATA_CHECKSUM", 'COL_DATA_SIZE',
"COL_D_RESC_NAME", "COL_D_RESC_GROUP_NAME",
"COL_D_DATA_STATUS", "COL_D_CREATE_TIME",
"COL_D_MODIFY_TIME", 'COL_R_TYPE_NAME', 'COL_R_CLASS_NAME',
'COL_R_LOC', 'COL_R_FREE_SPACE', 'COL_D_REPL_STATUS')
);
$condition = new RODSGenQueConds(
array("COL_COLL_NAME", "COL_DATA_NAME"),
array("=", "="),
array($this->parent_path, $this->name)
);
$conn = RODSConnManager::getConn($this->account);
$que_result = $conn->query($select, $condition);
RODSConnManager::releaseConn($conn);
$ret_arr = array();
for ($i = 0; $i < $que_result->getNumRow(); $i++) {
$ret_arr_row = array();
$que_result_val = $que_result->getValues();
$ret_arr_row['repl_num'] = $que_result_val['COL_DATA_REPL_NUM'][$i];
$ret_arr_row['chk_sum'] = $que_result_val['COL_D_DATA_CHECKSUM'][$i];
$ret_arr_row['size'] = $que_result_val['COL_DATA_SIZE'][$i];
$ret_arr_row['resc_name'] = $que_result_val['COL_D_RESC_NAME'][$i];
$ret_arr_row['resc_grp_name'] = $que_result_val['COL_D_RESC_GROUP_NAME'][$i];
$ret_arr_row['data_status'] = $que_result_val['COL_D_DATA_STATUS'][$i];
$ret_arr_row['ctime'] = $que_result_val['COL_D_CREATE_TIME'][$i];
$ret_arr_row['mtime'] = $que_result_val['COL_D_MODIFY_TIME'][$i];
$ret_arr_row['resc_type'] = $que_result_val['COL_R_TYPE_NAME'][$i];
$ret_arr_row['resc_class'] = $que_result_val['COL_R_CLASS_NAME'][$i];
$ret_arr_row['resc_loc'] = $que_result_val['COL_R_LOC'][$i];
$ret_arr_row['resc_freespace'] = $que_result_val['COL_R_FREE_SPACE'][$i];
$ret_arr_row['resc_repl_status'] = $que_result_val['COL_D_REPL_STATUS'][$i];
$ret_arr[] = $ret_arr_row;
}
return $ret_arr;
}
/**
* Get ACL (users and their rights on a file)
* @param string $filepath input file path string
* @return RODSFileStats. If file does not exists, return fales.
*/
public function getACL()
{
$filepath = $this->path_str;
$parent = dirname($filepath);
$filename = basename($filepath);
// $cond = array(new RODSQueryCondition("COL_COLL_NAME", $parent),
// new RODSQueryCondition("COL_DATA_NAME", $filename));
$cond = array(new RODSQueryCondition("COL_DATA_NAME", $filename),
new RODSQueryCondition("COL_COLL_NAME", $parent));
$connLocal = RODSConnManager::getConn($this->account);
$que_result = $connLocal->genQuery(
array("COL_USER_NAME", "COL_USER_ZONE", "COL_DATA_ACCESS_NAME"),
$cond, array());
RODSConnManager::releaseConn($connLocal);
if ($que_result === false) return false;
for($i=0; $i < sizeof($que_result['COL_USER_NAME']); $i++) {
$users[] = (object) array(
"COL_USER_NAME" => $que_result['COL_USER_NAME'][$i],
"COL_USER_ZONE" => $que_result['COL_USER_ZONE'][$i],
"COL_DATA_ACCESS_NAME" => $que_result['COL_DATA_ACCESS_NAME'][$i]
);
}
return $users;
}
}
<?php
/**
* ProdsPath class file.
* @author Sifang Lu <sifang@sdsc.edu>
* @copyright Copyright &copy; 2007, TBD
* @package Prods
*/
require_once("autoload.inc.php");
require_once(CLASS_DIR . "/ProdsConfig.inc.php");
/**
* ProdsPath class. This class is a abastract class for objects that can be represented as a path, such as file or directory
* @package Prods
*/
abstract class ProdsPath
{
/**
* string path
* @var string
*/
public $path_str;
public $account;
protected $path_exists;
protected $parent_path;
protected $name;
/**
* Default Constructor. Because this class is abstract, this constructor should not be called directly.
*
* @param RODSAccount account iRODS account used for connection
* @param string $path_str the path of this dir
* @return ProdsPath a new ProdsPath
*/
public function __construct(RODSAccount &$account, $path_str)
{
$this->account = $account;
// strip the tailing "/"
while ((strlen($path_str) > 1) && ($path_str{strlen($path_str) - 1} == '/')) {
$path_str = substr($path_str, 0, strlen($path_str) - 1);
}
// remove duplicate '/' characters
$path_str = str_replace('//', '/', $path_str);
$this->path_str = $path_str;
if ($path_str == '/') {
$this->parent_path = null;
} else {
$this->parent_path = dirname($this->path_str);
}
$this->name = basename($this->path_str);
}
public function __toString()
{
return $this->account . $this->path_str;
}
/**
* Whether this path (dir or file) exists on the server.
* @return boolean
*/
public function exists()
{
if (isset($this->path_exists))
return $this->path_exists;
else {
$this->verify();
return $this->path_exists;
}
}
/**
* Verify if a path exist with server. This function shouldn't be called directly, use {@link exists}
*/
abstract protected function verify();
/**
* Get meta data of this path (file or dir).
* @return array array of RODSMeta.
*/
//public function getMeta()
public function getMeta($get_cb = array('RODSConnManager', 'getConn'),
$rel_cb = array('RODSConnManager', 'releaseConn'))
{
if ($this instanceof ProdsFile)
$type = 'd';
else
if ($this instanceof ProdsDir)
$type = 'c';
else
throw new RODSException("Unsupported data type:" . get_class($this),
"PERR_INTERNAL_ERR");
//$conn = RODSConnManager::getConn($this->account);
$conn = call_user_func_array($get_cb, array(&$this->account));
$meta_array = $conn->getMeta($type, $this->path_str);
//RODSConnManager::releaseConn($conn);
call_user_func($rel_cb, $conn);
return $meta_array;
}
/**
* update metadata to this path (file or dir)
*/
public function updateMeta(RODSMeta $meta_old, RODSMeta $meta_new)
{
$this->rmMeta($meta_old);
$this->addMeta($meta_new);
}
/**
* Add metadata to this path (file or dir)
*/
// public function addMeta(RODSMeta $meta)
public function addMeta(RODSMeta $meta,
$get_cb = array('RODSConnManager', 'getConn'),
$rel_cb = array('RODSConnManager', 'releaseConn'))
{
if ($this instanceof ProdsFile)
$type = 'd';
else
if ($this instanceof ProdsDir)
$type = 'c';
else
throw new RODSException("Unsupported data type:" . get_class($this),
"PERR_INTERNAL_ERR");
//$conn = RODSConnManager::getConn($this->account);
$conn = call_user_func_array($get_cb, array(&$this->account));
$conn->addMeta($type, $this->path_str, $meta);
//RODSConnManager::releaseConn($conn);
call_user_func($rel_cb, $conn);
}
/**
* remove metadata to this path (file or dir)
*/
// public function rmMeta(RODSMeta $meta)
public function rmMeta(RODSMeta $meta,
$get_cb = array('RODSConnManager', 'getConn'),
$rel_cb = array('RODSConnManager', 'releaseConn'))
{
if ($this instanceof ProdsFile)
$type = 'd';
else
if ($this instanceof ProdsDir)
$type = 'c';
else
throw new RODSException("Unsupported data type:" . get_class($this),
"PERR_INTERNAL_ERR");
//$conn = RODSConnManager::getConn($this->account);
$conn = call_user_func_array($get_cb, array(&$this->account));
$conn->rmMeta($type, $this->path_str, $meta);
//RODSConnManager::releaseConn($conn);
call_user_func($rel_cb, $conn);
}
/**
* remove metadata of this path (file or dir) by id
* @param integer metaid id of the metadata entry
*/
// public function rmMetaByID ($metaid)
public function rmMetaByID($metaid,
$get_cb = array('RODSConnManager', 'getConn'),
$rel_cb = array('RODSConnManager', 'releaseConn'))
{
if ($this instanceof ProdsFile)
$type = 'd';
else
if ($this instanceof ProdsDir)
$type = 'c';
else
throw new RODSException("Unsupported data type:" . get_class($this),
"PERR_INTERNAL_ERR");
//$conn = RODSConnManager::getConn($this->account);
$conn = call_user_func_array($get_cb, array(&$this->account));
$conn->rmMetaByID($type, $this->path_str, $metaid);
//RODSConnManager::releaseConn($conn);
call_user_func($rel_cb, $conn);
}
/**
* copy meta data from this path (file or dir) to $dest path
*/
// public function cpMeta(ProdsPath $dest)
public function cpMeta(ProdsPath $dest,
$get_cb = array('RODSConnManager', 'getConn'),
$rel_cb = array('RODSConnManager', 'releaseConn'))
{
if ($this instanceof ProdsFile)
$type_src = 'd';
else
if ($this instanceof ProdsDir)
$type_src = 'c';
else
throw new RODSException("Unsupported data type:" . get_class($this),
"PERR_INTERNAL_ERR");
if ($dest instanceof ProdsFile)
$type_dest = 'd';
else
if ($dest instanceof ProdsDir)
$type_dest = 'c';
else
throw new RODSException("Unsupported data type:" . get_class($this),
"PERR_INTERNAL_ERR");
//$conn = RODSConnManager::getConn($this->account);
$conn = call_user_func_array($get_cb, array(&$this->account));
$conn->cpMeta($type_src, $type_dest, $this->path_str, $dest->path_str);
//RODSConnManager::releaseConn($conn);
call_user_func($rel_cb, $conn);
}
/**
* rename this path (file of dir)
* @param string $new_path_str new path string to be renamed to.
*/
// public function rename($new_path_str)
public function rename($new_path_str,
$get_cb = array('RODSConnManager', 'getConn'),
$rel_cb = array('RODSConnManager', 'releaseConn'))
{
if ($this instanceof ProdsFile)
$type = 0;
else
$type = 1;
//$conn = RODSConnManager::getConn($this->account);
$conn = call_user_func_array($get_cb, array(&$this->account));
$conn->rename($this->path_str, $new_path_str, $type);
//RODSConnManager::releaseConn($conn);
call_user_func($rel_cb, $conn);
$this->path_str = $new_path_str;
$this->parent_path = dirname($this->path_str);
$this->name = basename($this->path_str);
}
/**
* Get name of this path. note that this is not the full path. for instance if path is "/foo/bar", the name is "bar"
* @return string name of the path.
*/
public function getName()
{
return $this->name;
}
/**
* Get string form of this path. note that this is the full path.
* @return string form of the path.
*/
public function getPath()
{
return $this->path_str;
}
/**
* Get parent's path of this path.
* @return string parent's path.
*/
public function getParentPath()
{
return $this->parent_path;
}
/**
* Get URI of this path.
* @return string this path's URI.
*/
public function toURI()
{
return $this->account->toURI() . $this->path_str;
}
}
<?php
/**
* ProdsQuery class.
*
* This class provides high level PRODS queries, which aren't specific
* to a path, account or resource.
* @author Sifang Lu <sifang@sdsc.edu>
* @copyright Copyright &copy; 2007, TBD
* @package Prods
*/
require_once("autoload.inc.php");
class ProdsQuery
{
public $account;
public function __construct(RODSAccount $account)
{
$this->account = $account;
}
/**
* Get all user defined metadata names for all files on the server.
* @return array of strings (metadata names).
*/
public function getMetadataNamesForAllFiles()
{
$flds = array("COL_META_DATA_ATTR_NAME" => NULL);
$select = new RODSGenQueSelFlds(array_keys($flds), array_values($flds));
$condition = new RODSGenQueConds();
$condition->add('COL_D_DATA_ID', '>=', '0');
$conn = RODSConnManager::getConn($this->account);
$results = $conn->query($select, $condition);
RODSConnManager::releaseConn($conn);
if ($results->getNumRow() < 1)
return array();
else {
$values = $results->getValues();
return $values['COL_META_DATA_ATTR_NAME'];
}
}
/**
* Get all user defined metadata names for all directories(collections) on the server.
* @return array of strings (metadata names).
*/
public function getMetadataNamesForAllDirs()
{
$flds = array("COL_META_COLL_ATTR_NAME" => NULL);
$select = new RODSGenQueSelFlds(array_keys($flds), array_values($flds));
$condition = new RODSGenQueConds();
$condition->add('COL_COLL_ID', '>=', '0');
$conn = RODSConnManager::getConn($this->account);
$results = $conn->query($select, $condition);
RODSConnManager::releaseConn($conn);
if ($results->getNumRow() < 1)
return array();
else {
$values = $results->getValues();
return $values['COL_META_COLL_ATTR_NAME'];
}
}
/**
* Get all resources registered on the server
* @return array with fields: id, name, type, zone, class, loc, info, comment, ctime, mtime, vault_path, free_space. If user not found return empty array.
*/
public function getResources()
{
// set selected value
$flds = array("COL_R_RESC_ID" => NULL, "COL_R_RESC_NAME" => NULL,
"COL_R_ZONE_NAME" => NULL, "COL_R_TYPE_NAME" => NULL,
"COL_R_CLASS_NAME" => NULL, "COL_R_LOC" => NULL,
"COL_R_VAULT_PATH" => NULL, "COL_R_FREE_SPACE" => NULL,
"COL_R_RESC_INFO" => NULL, "COL_R_RESC_COMMENT" => NULL,
"COL_R_CREATE_TIME" => NULL, "COL_R_MODIFY_TIME" => NULL);
$select = new RODSGenQueSelFlds(array_keys($flds), array_values($flds));
$condition = new RODSGenQueConds();
$conn = RODSConnManager::getConn($this->account);
$results = $conn->query($select, $condition);
RODSConnManager::releaseConn($conn);
$result_vals = $results->getValues();
$retval = array();
for ($i = 0; $i < $results->getNumRow(); $i++) {
$retval_row = array();
$retval_row['id'] = $result_vals["COL_R_RESC_ID"][$i];
$retval_row['name'] = $result_vals["COL_R_RESC_NAME"][$i];
$retval_row['type'] = $result_vals["COL_R_TYPE_NAME"][$i];
$retval_row['zone'] = $result_vals["COL_R_ZONE_NAME"][$i];
$retval_row['class'] = $result_vals["COL_R_CLASS_NAME"][$i];
$retval_row['loc'] = $result_vals["COL_R_LOC"][$i];
$retval_row['info'] = $result_vals["COL_R_RESC_INFO"][$i];
$retval_row['comment'] = $result_vals["COL_R_RESC_COMMENT"][$i];
$retval_row['ctime'] = $result_vals["COL_R_CREATE_TIME"][$i];
$retval_row['mtime'] = $result_vals["COL_R_MODIFY_TIME"][$i];
$retval_row['vault_path'] = $result_vals["COL_R_VAULT_PATH"][$i];
$retval_row['free_space'] = $result_vals["COL_R_FREE_SPACE"][$i];
$retval[] = $retval_row;
}
return $retval;
}
}
<?php
/**
* ProdsRule class. Provides iRODS rule related functionalities.
* @author Sifang Lu <sifang@sdsc.edu>
* @copyright Copyright &copy; 2007, TBD
* @package Prods
*/
require_once("autoload.inc.php");
class ProdsRule
{
public $account;
public $body;
public $inp_params;
public $out_params;
public $remotesvr;
public $options;
/*
* @param RODSAccount account this is the account used to connect to iRODS server
* @param string $rule_body body of the rule. Read this tutorial for details about rules: http://www.irods.org/index.php/Executing_user_defined_rules/workflow
* @param array $inp_params associative array defining input parameters for micro services used in this rule. only string and keyval pair are supported at this time. If the array value is a string, then type is string, if the array value is an RODSKeyValPair object, it will be treated a keyval pair
* @param array $out_params an array of names (strings)
* @param array $remotesvr if this rule need to run at remote server, this associative array should have the following keys:
* - 'host' remote host name or address
* - 'port' remote port
* - 'zone' remote zone
* if any of the value is empty, this option will be ignored.
* @param RODSKeyValPair $options an RODSKeyValPair specifying additional options, purpose of this is unknown at the developement time. Leave it alone if you are as clueless as me...
*/
public function __construct(RODSAccount $account, $rule_body,
array $inp_params = array(), array $out_params = array(),
array $remotesvr = array(), RODSKeyValPair $options = null)
{
$this->account = $account;
$this->rule_body = $rule_body;
$this->inp_params = $inp_params;
$this->out_params = $out_params;
$this->remotesvr = $remotesvr;
if (isset($options))
$this->options = $options;
else
$this->options = new RODSKeyValPair();
}
/**
* Excute the rule, assign
* @return an associative array. Each array key is the lable, and each array value's type will depend on the type of $out_param, at this moment, only string and RODSKeyValPair are supported
*/
public function execute()
{
$conn = RODSConnManager::getConn($this->account);
$result = $conn->execUserRule($this->rule_body, $this->inp_params,
$this->out_params, $this->remotesvr, $this->options = null);
RODSConnManager::releaseConn($conn);
return $result;
}
}
<?php
/**
* PRODS class
* @author Sifang Lu <sifang@sdsc.edu>
* @copyright Copyright &copy; 2007, TBD
* @package Prods
*/
require_once("autoload.inc.php");
class ProdsStreamer
{
/**
* current position of the file or dir
*
* @access private
*/
private $position;
/**
* Name of the directory/collection specified in the URI to opendir().
*
* @access private
*/
private $dir;
/**
* Name of the file specified in the URI to fopen().
*
* @access private
*/
private $file;
/**
* url_stat() handler.
*
* @access private
*/
public function url_stat($path)
{
try {
$file=ProdsDir::fromURI($path);
$conn = RODSConnManager::getConn($file->account);
$stats = $this->stat_file($conn, $file->path_str);
if (!$stats) {
$stats = $this->stat_dir($conn, $file->path_str);
}
RODSConnManager::releaseConn($conn);
return $stats;
} catch (Exception $e) {
trigger_error("Got an exception:$e", E_USER_WARNING);
return false;
}
}
/**
* @param $conn
* @param $file
* @return mixed
*/
private function stat_dir($conn, $path_str) {
try {
$irods_stats = $conn->getDirStats($path_str);
if (!$irods_stats)
return false;
$stats = array();
$stats[0] = $stats['dev'] = 0;
$stats[1] = $stats['ino'] = 0;
$stats[2] = $stats['mode'] = octdec('040755');
$stats[3] = $stats['nlink'] = 1;
$stats[4] = $stats['uid'] = 0;
$stats[5] = $stats['gid'] = 0;
$stats[6] = $stats['rdev'] = -1;
$stats[7] = $stats['size'] = 0;
$stats[8] = $stats['atime'] = time();
$stats[9] = $stats['mtime'] = $irods_stats->mtime;
$stats[10] = $stats['ctime'] = $irods_stats->ctime;
$stats[11] = $stats['blksize'] = -1;
$stats[12] = $stats['blocks'] = -1;
return $stats;
} catch (Exception $e) {
trigger_error("Got an exception: $e", E_USER_WARNING);
return false;
}
}
/**
* @param $conn
* @param $file
* @return mixed
*/
private function stat_file($conn, $path_str) {
try {
$irods_stats = $conn->getFileStats($path_str);
if (!$irods_stats)
return false;
$stats = array();
$stats[0] = $stats['dev'] = 0;
$stats[1] = $stats['ino'] = 0;
$stats[2] = $stats['mode'] = octdec('100644');
$stats[3] = $stats['nlink'] = 1;
$stats[4] = $stats['uid'] = 0;
$stats[5] = $stats['gid'] = 0;
$stats[6] = $stats['rdev'] = -1;
$stats[7] = $stats['size'] = $irods_stats->size;
$stats[8] = $stats['atime'] = time();
$stats[9] = $stats['mtime'] = $irods_stats->mtime;
$stats[10] = $stats['ctime'] = $irods_stats->ctime;
$stats[11] = $stats['blksize'] = -1;
$stats[12] = $stats['blocks'] = -1;
return $stats;
} catch (Exception $e) {
trigger_error("Got an exception: $e", E_USER_WARNING);
return false;
}
}
/**
* mkdir() handler.
*
* @access private
*/
function mkdir ($url, $mode, $options) {
try {
$file=ProdsDir::fromURI($url);
$conn = RODSConnManager::getConn($file->account);
$conn->mkdir($file->path_str);
RODSConnManager::releaseConn($conn);
return true;
} catch (Exception $e) {
trigger_error("Got an exception:$e", E_USER_WARNING);
return false;
}
}
/**
* rmdir() handler
*
* @param $url
* @return bool
*/
function rmdir ($url) {
try {
$file=ProdsDir::fromURI($url);
$conn = RODSConnManager::getConn($file->account);
$conn->rmdir($file->path_str);
RODSConnManager::releaseConn($conn);
return true;
} catch (Exception $e) {
trigger_error("Got an exception:$e", E_USER_WARNING);
return false;
}
}
/**
* unlink() handler.
*
* @access private
*/
function unlink ($url) {
try {
$file=ProdsDir::fromURI($url);
$conn = RODSConnManager::getConn($file->account);
if (is_dir($url)) {
$conn->rmdir($file->path_str, true, true);
} else {
$conn->fileUnlink($file->path_str, NULL, true);
}
RODSConnManager::releaseConn($conn);
return true;
} catch (Exception $e) {
trigger_error("Got an exception:$e", E_USER_WARNING);
return false;
}
}
/**
* rename() handler.
*
* @access private
*/
function rename ($url_from, $url_to) {
try {
$file_from=ProdsDir::fromURI($url_from);
$file_to=ProdsDir::fromURI($url_to);
$conn = RODSConnManager::getConn($file_from->account);
if (is_dir($url_from)) {
$conn->rename($file_from->path_str, $file_to->path_str, 0);
} else {
$conn->rename($file_from->path_str, $file_to->path_str, 1);
}
RODSConnManager::releaseConn($conn);
return true;
} catch (Exception $e) {
trigger_error("Got an exception:$e", E_USER_WARNING);
return false;
}
}
/**
* opendir() handler.
*
* @access private
*/
public function dir_opendir ($path, $options)
{
try {
$this->dir=ProdsDir::fromURI($path,true);
return true;
} catch (Exception $e) {
trigger_error("Got an exception:$e", E_USER_WARNING);
return false;
}
}
/**
* readdir() handler.
*
* @access private
*/
public function dir_readdir()
{
try {
$child = $this->dir->getNextChild();
if ($child === false) return false;
return $child->getName();
} catch (Exception $e) {
trigger_error("Got an exception:$e", E_USER_WARNING);
return false;
}
}
/**
* fread() and fgets() handler.
*
* @access private
*/
public function stream_read ($count) {
if (in_array ($this->file->getOpenMode(), array ('w', 'a', 'x'))) {
return false;
}
try {
$ret = $this->file->read($count);
$this->position=$this->file->tell();
return $ret;
} catch (Exception $e) {
trigger_error("Got an exception:$e", E_USER_WARNING);
return false;
}
}
/**
* fwrite() handler.
*
* @access private
*/
public function stream_write ($data) {
if ($this->file->getOpenMode() =='r') {
return false;
}
try {
$ret = $this->file->write($data);
$this->position=$this->file->tell();
return $ret;
} catch (Exception $e) {
trigger_error("Got an exception:$e", E_USER_WARNING);
return false;
}
}
/**
* rewinddir() handler.
*
* @access private
*/
public function dir_rewinddir()
{
try {
$this->dir->rewind();
return true;
} catch (Exception $e) {
trigger_error("Got an exception:$e", E_USER_WARNING);
return false;
}
}
/**
* closedir() handler.
*
* @access private
*/
public function dir_closedir()
{
try {
$this->dir->rewind();
return true;
} catch (Exception $e) {
trigger_error("Got an exception:$e", E_USER_WARNING);
return false;
}
}
/**
* fopen() handler.
*
* @access private
*/
public function stream_open($path, $mode, $options, &$opened_path)
{
// get rid of tailing 'b', if any.
if (($mode{strlen($mode) - 1} == 'b') && (strlen($mode) > 1))
$mode = substr($mode, 0, strlen($mode) - 1);
try {
$this->file = ProdsFile::fromURI($path);
$this->file->open($mode);
return true;
} catch (Exception $e) {
trigger_error("Got an exception:$e", E_USER_WARNING);
return false;
}
}
/**
* fstat() handler.
*
* @access private
*/
function stream_stat () {
try {
$stats=$this->file->getStats();
return array (
-1, -1, -1, -1, -1, -1, $stats->size, time (), $stats->mtime, $stats->ctime, -1, -1,
'dev' => -1,
'ino' => -1,
'mode' => -1,
'nlink' => -1,
'uid' => -1,
'gid' => -1,
'rdev' => -1,
'size' => $stats->size,
'atime' => time (),
'mtime' => $stats->mtime,
'ctime' => $stats->ctime,
'blksize' => -1,
'blocks' => -1,
);
} catch (Exception $e) {
trigger_error("Got an exception:$e", E_USER_WARNING);
return false;
}
}
/**
* fclose() handler.
*
* @access private
*/
function stream_close () {
$this->file->close();
$this->position = 0;
$this->file = null;
$this->dir = null;
}
/**
* ftell() handler.
*
* @access private
*/
function stream_tell()
{
return $this->position;
}
/**
* feof() handler.
*
* @access private
*/
function stream_eof()
{
try {
$stats = $this->file->getStats();
return $this->position >= $stats->size;
} catch (Exception $e) {
trigger_error("Got an exception:$e", E_USER_WARNING);
return true;
}
}
/**
* fseek() handler.
*
* @access private
*/
function stream_seek($offset, $whence)
{
try {
$this->file->seek($offset, $whence);
return true;
} catch (Exception $e) {
trigger_error("Got an exception:$e", E_USER_WARNING);
return false;
}
}
/**
* fflush() handler. Please Note: This method must be called for any
* changes to be committed to the repository.
*
* @access private
*/
function stream_flush()
{
return true;
}
}
stream_wrapper_register('rods', 'ProdsStreamer')
or die ('Failed to register protocol:rods');
stream_wrapper_register('rods+ticket', 'ProdsStreamer')
or die ('Failed to register protocol:rods');
<?php
/**
* Developer: Daniel Speichert <s@drexel.edu>
* Date: 30.01.13
* Time: 14:15
*/
require_once("autoload.inc.php");
class ProdsTicket
{
private $account;
public function __construct( RODSAccount &$account )
{
$this->account = $account;
}
/*
* This is just a stupid wrapper
* It proxifies RODSConn->createTicket
*/
public function createTicket( $object, $permission = 'read', $ticket = '' )
{
$conn = RODSConnManager::getConn($this->account);
$ticket = $conn->createTicket($object, $permission, $ticket );
RODSConnManager::releaseConn($conn);
return $ticket;
}
/*
* This is also a stupid wrapper
* It proxifies RODSConn->deleteTicket
*/
public function deleteTicket( $ticket )
{
$conn = RODSConnManager::getConn($this->account);
$ticket = $conn->deleteTicket( $ticket );
RODSConnManager::releaseConn($conn);
}
}
\ No newline at end of file
<?php
/**#@+
* Constants
*/
/**
* Maximum lengh of password string. Only up to this lengh of password are submitted to RODS server.
*/
define("MAX_PASSWORD_LEN", 50);
/**#@-*/
require_once("autoload.inc.php");
class RODSAccount
{
/**#@+
* @var string
*/
public $user;
public $pass;
public $host;
public $port;
public $zone;
public $default_resc;
public $auth_type;
public $ticket;
/**#@-*/
public function __construct($host, $port, $user, $pass, $zone="",
$default_resc="", $auth_type="irods",$ticket = '')
{
$this->host=$host;
$this->port=$port;
$this->user=$user;
$this->pass=$pass;
$this->zone=$zone;
$this->default_resc=$default_resc;
$this->auth_type=$auth_type;
$this->ticket = $ticket;
}
/**
* Create a RODSAccount object from URI string.
* @param string $uri
* @return a new RODSAccount object
*/
public static function fromURI($uri)
{
$url=parse_url($uri);
$host=isset($url['host'])?$url['host']:'';
$port=isset($url['port'])?$url['port']:'';
$user='';
$zone='';
$authtype='irods';
if (isset($url['user']))
{
if (strstr($url['user'],".")!==false) {
$user_array=@explode(".",$url['user']);
if (count($user_array)===3) {
$user=$user_array[0];
$zone=$user_array[1];
$authtype=$user_array[2];
}
else {
$user=$user_array[0];
$zone=$user_array[1];
}
}
else
$user=$url['user'];
}
$pass=isset($url['pass'])?$url['pass']:'';
return (new RODSAccount($host, $port, $user, $pass, $zone, "", $authtype,$ticket = ''));
}
public function equals(RODSAccount $other)
{
if (!isset($other))
return false;
if (($this->host == $other->host) &&
($this->port == $other->port) &&
($this->user == $other->user)
) {
$ret_val = true;
} else
$ret_val = false;
//echo ( "$this->host,$this->port,$this->user vs. $other->host,$other->port,$other->user = $ret_val");
//flush();
return $ret_val;
}
public function getSignature()
{
return (bin2hex(md5("$this->user.$this->zone:this->pass@$this->host:$this->port.$this->ticket", TRUE)));
}
public function __toString()
{
return "$this->user.$this->zone:(password hidden)@$this->host:$this->port";
}
public function toURI()
{
return ($this->user .
(empty($this->zone) ? '' : '.' . $this->zone) .
"@" . $this->host . ":" . $this->port);
}
/**
* Get user information
* @param string username, if not specified, it will use current username instead
* @return array with fields: id, name, type, zone, dn, info, comment, ctime, mtime. If user not found return empty array.
*/
public function getUserInfo($username = NULL,
$get_cb = array('RODSConnManager', 'getConn'),
$rel_cb = array('RODSConnManager', 'releaseConn'))
{
//$conn = RODSConnManager::getConn($this);
$conn = call_user_func_array($get_cb, array(&$this));
//TODO: Overcome fear of passing $this by reference or stop passing $this by reference
$userinfo = $conn->getUserInfo($username);
//RODSConnManager::releaseConn($conn);
call_user_func($rel_cb, $conn);
if ((!empty($userinfo)) && (!empty($userinfo['zone'])))
$this->zone = $userinfo['zone'];
return $userinfo;
}
/**
* Get a temp password for current user
* @return string of temp password
*/
public function getTempPassword($get_cb = array('RODSConnManager', 'getConn'),
$rel_cb = array('RODSConnManager', 'releaseConn'))
{
//$conn = RODSConnManager::getConn($this);
$conn = call_user_func_array($get_cb, array(&$this));
//TODO: Overcome fear of passing $this by reference or stop passing $this by reference
$temppass = $conn->getTempPassword();
// RODSConnManager::releaseConn($conn);
call_user_func($rel_cb, $conn);
return $temppass;
}
/**
* Get user's home directory
* @param string init_path, if specified, it will overwrite the default path
* @return ProdsDir User's home directory
*/
public function getUserHomeDir($init_path = NULL)
{
if (empty($this->zone))
$this->getUserInfo();
if (isset($init_path)) {
$dir = new ProdsDir($this, $init_path);
if ($dir->exists()) {
return $dir;
}
}
return new ProdsDir($this, "/$this->zone/home/$this->user");
}
/**
* Get user's home directory URI
* @param string init_path, if specified, it will overwrite the default path
* @return String User's home
*/
public function getUserHomeDirURI($init_path = NULL)
{
$dir = $this->getUserHomeDir($init_path);
return $dir->toURI();
}
/**
* Get user's trash directory
* @return ProdsDir User's trash dir
*/
public function getUserTrashDir()
{
if (empty($this->zone))
$this->getUserInfo();
return new ProdsDir($this, "/$this->zone/trash/home/$this->user");
}
/**
* Get user's trash directory URI
* @return String User's trash URI
*/
public function getUserTrashDirURI()
{
$dir = $this->getUserTrashDir();
return $dir->toURI();
}
}
This diff is collapsed.
<?php
/**#@+
* Constants
*/
/**
* Maximum number of connection per user per server
*/
define("MAX_NUM_CONN_PER_USER_SERVER", 5);
/**#@-*/
if (!isset($GLOBALS['RODSConnManager']))
$GLOBALS['RODSConnManager'] = new RODSConnManager();
class RODSConnManager
{
private $waiting_queue;
private $conn_map;
public function __construct()
{
$this->waiting_queue = array();
$this->conn_map = array();
}
public static function getConn(RODSAccount $account)
{
$manager = $GLOBALS['RODSConnManager'];
$conn = new RODSConn($account);
$conn_sig = $conn->getSignature();
if (!isset($manager->conn_map[$conn_sig]))
$manager->conn_map[$conn_sig] = array();
//check if there is any opened connection idle
foreach ($manager->conn_map[$conn_sig] as &$opened_conn) {
if ($opened_conn->isIdle()) {
//$opened_conn->lock();
$account = $opened_conn->getAccount(); //update account if needed...
return $opened_conn;
}
}
//check if there is any more new connection allowed
if (count($manager->conn_map[$conn_sig]) < MAX_NUM_CONN_PER_USER_SERVER) {
$conn->connect();
$id = count($manager->conn_map[$conn_sig]);
$manager->conn_map[$conn_sig][$id] = $conn;
$conn->setId($id);
//$conn->lock();
$account = $conn->getAccount(); //update account if needed...
return $conn;
}
//because PHP doesn't support multithread, if we run out of connections,
//there is probably something went wrong.
throw new RODSException("Unexpectedly ran out of connections. Maybe some connections are not released??? ",
"PERR_INTERNAL_ERR");
//if no connection are available, sleep for 100ms and retry
usleep(100);
echo "i am sleeping... <br/> \n";
return RODSConnManager::getConn($account);
}
public static function releaseConn(RODSConn $conn)
{
$manager = $GLOBALS['RODSConnManager'];
$conn_sig = $conn->getSignature();
//echo "id:".$conn->getId()." ".implode(",",array_keys($manager->conn_map[$conn_sig]))."<br/>\n";
if (isset($manager->conn_map[$conn_sig][$conn->getId()])) {
$manager->conn_map[$conn_sig][$conn->getId()]->unlock();
}
}
}
<?php
class RODSDirStats
{
public $name;
public $owner;
public $ownerzone;
public $mtime;
public $ctime;
public $id;
public $comments;
public function __construct($name, $owner, $ownerzone, $mtime, $ctime, $id, $comments)
{
$this->name = $name;
$this->owner = $owner;
$this->ownerzone = $ownerzone;
$this->mtime = $mtime;
$this->ctime = $ctime;
$this->id = $id;
$this->comments = $comments;
}
}
\ No newline at end of file
<?php
/**
* RODS exception class
* @author Sifang Lu <sifang@sdsc.edu>
* @copyright Copyright &copy; 2007, TBD
* @package Prods
*/
$errtable_file = dirname(__FILE__) . "/RodsErrorTable.inc.php";
if (is_readable($errtable_file))
require_once($errtable_file);
else
die("Could not read file $errtable_file <br/>\n");
/**
* custom exception class for RODS
*/
class RODSException extends Exception
{
private $code_abbr;
private $cause;
/**
* Makes a new RODS excption
* @param string $message err/exception message
* @param string $code_abbr error code abbreviation
*/
public function __construct($message, $code_abbr = "UNKNOWN_PRODS_ERR",
Exception $cause = NULL)
{
$this->code_abbr = $code_abbr;
$this->cause = $cause;
parent::__construct($message, $GLOBALS['PRODS_ERR_CODES'][$code_abbr]);
}
public function getCause()
{
return $this->cause;
}
public function getCodeAbbr()
{
return $this->code_abbr;
}
public static function rodsErrCodeToAbbr($code)
{
if (isset($GLOBALS['PRODS_ERR_CODES_REV']["$code"]))
return $GLOBALS['PRODS_ERR_CODES_REV']["$code"];
else
return null;
}
public static function rodsErrAbbrToCode($codeabbr)
{
if (isset($GLOBALS['PRODS_ERR_CODES']["$codeabbr"]))
return $GLOBALS['PRODS_ERR_CODES']["$codeabbr"];
else
return null;
}
public function getStackTrace()
{
if ($this->cause !== null) {
$arr = array();
$trace = $this->getTrace();
array_push($arr, $trace[0]);
unset($trace);
if (get_class($this->cause) == "RODSException") {
foreach ($this->cause->getStackTrace() as $key => $trace) {
array_push($arr, $trace);
}
} else {
foreach ($this->cause->getTrace() as $key => $trace) {
array_push($arr, $trace);
}
}
return $arr;
} else {
return $this->getTrace();
}
}
public function showStackTrace()
{
$htmldoc = "<p style=\"font-family: monospace; border: solid 1px #000000\"><span style=\"font-weight: bold; color: #000000;\">An exception was thrown :<br/></span>";
$htmldoc .= "Exception code : $this->code<br/>";
$htmldoc .= "Exception abbr : $this->code_abbr<br/>";
$htmldoc .= "Exception message : $this->message<br/>";
$htmldoc .= "<span style=\"color: #0000FF;\">";
$i = 0;
foreach ($this->getStackTrace() as $key => $trace) {
$htmldoc .= $this->showTrace($trace, $i);
$i++;
}
$htmldoc .= "#$i {main}<br/>";
unset($i);
$htmldoc .= "</span></p>";
return $htmldoc;
}
private function showTrace($_trace, $_i)
{
$htmldoc = "#$_i ";
if (array_key_exists("file", $_trace)) {
$htmldoc .= $_trace["file"];
}
if (array_key_exists("line", $_trace)) {
$htmldoc .= "(" . $_trace["line"] . "): ";
}
if (array_key_exists("class", $_trace) && array_key_exists("type", $_trace)) {
$htmldoc .= $_trace["class"] . $_trace["type"];
}
if (array_key_exists("function", $_trace)) {
$htmldoc .= $_trace["function"] . "(";
if (array_key_exists("args", $_trace)) {
if (count($_trace["args"]) > 0) {
$args = $_trace["args"];
$type = gettype($args[0]);
$value = $args[0];
unset($args);
if ($type == "boolean") {
if ($value) {
$htmldoc .= "true";
} else {
$htmldoc .= "false";
}
} elseif ($type == "integer" || $type == "double") {
if (settype($value, "string")) {
if (strlen($value) <= 20) {
$htmldoc .= $value;
} else {
$htmldoc .= substr($value, 0, 17) . "...";
}
} else {
if ($type == "integer") {
$htmldoc .= "? integer ?";
} else {
$htmldoc .= "? double or float ?";
}
}
} elseif ($type == "string") {
if (strlen($value) <= 18) {
$htmldoc .= "'$value'";
} else {
$htmldoc .= "'" . substr($value, 0, 15) . "...'";
}
} elseif ($type == "array") {
$htmldoc .= "Array";
} elseif ($type == "object") {
$htmldoc .= "Object";
} elseif ($type == "resource") {
$htmldoc .= "Resource";
} elseif ($type == "NULL") {
$htmldoc .= "null";
} elseif ($type == "unknown type") {
$htmldoc .= "? unknown type ?";
}
unset($type);
unset($value);
}
if (count($_trace["args"]) > 1) {
$htmldoc .= ",...";
}
}
$htmldoc .= ")<br/>";
}
return $htmldoc;
}
/**
* Magic function to turn exception obj to a string
*/
public function __toString()
{
return __CLASS__ . ": [{$this->code} $this->code_abbr]: {$this->message}\n";
//return $this->showStackTrace();
}
}
<?php
class RODSFileStats
{
public $name;
public $size;
public $owner;
public $ownerzone;
public $mtime;
public $ctime;
public $id;
public $typename;
public $rescname;
public $comments;
public $num_replica;
public function __construct($name, $size, $owner, $ownerzone, $mtime, $ctime, $id, $typename,
$rescname, $comments, $num_replica = null)
{
$this->name = $name;
$this->size = $size;
$this->owner = $owner;
$this->ownerzone = $ownerzone;
$this->mtime = $mtime;
$this->ctime = $ctime;
$this->id = $id;
$this->typename = $typename;
$this->rescname = $rescname;
$this->comments = $comments;
$this->num_replica = $num_replica;
}
}
\ No newline at end of file
<?php
require_once("autoload.inc.php");
class RODSGenQueConds
{
private $cond;
private $cond_kw;
/**
* default constructor. It take names, ops, and vals.
* suppose name='foo' op='>=' and val='0', then the triplex means
* "foo >= 0" as one iRODS general query condition.
* @param array (of string) $names names of the field, which must be one defined in file 'RodsGenQueryNum.inc.php'.
* @param array (of string) $ops logical operator, such as '=' 'like' '>'
* @param array (of string) $vals value of the filed
*/
public function __construct(array $names = array(), array $ops = array(),
array $vals = array())
{
require_once("RodsGenQueryNum.inc.php"); //load magic numbers
require_once("RodsGenQueryKeyWd.inc.php"); //load magic keywords
$this->cond = array('names' => array(), 'sysnames' => array(), 'values' => array());
$this->cond_kw = array('names' => array(), 'sysnames' => array(), 'values' => array());
for ($i = 0; $i < count($names); $i++) {
$name = $names[$i];
$op = $ops[$i];
$val = $vals[$i];
if (isset($GLOBALS['PRODS_GENQUE_NUMS']["$name"])) {
$this->cond['names'][] = $name;
$this->cond['sysnames'][] = $GLOBALS['PRODS_GENQUE_NUMS']["$name"];
$this->cond['values'][] = "$op '$val'";
} else
if (isset($GLOBALS['PRODS_GENQUE_KEYWD']["$name"])) {
$this->cond_kw['names'][] = $name;
$this->cond_kw['sysnames'][] = $GLOBALS['PRODS_GENQUE_KEYWD']["$name"];
$this->cond_kw['values'][] = "$op '$val'";
} else {
throw new RODSException("General Query condition field name '$name' is not valid",
'PERR_USER_INPUT_ERROR');
}
}
}
/**
* Add a single select field.
* @param string $name names of the field, which must be one defined in file 'RodsGenQueryNum.inc.php'.
* @param string $op logical operator, such as '=' 'like' '>'
* @param string $val value of the filed
* @param array an array of tuples of extra op's and val's, each tuple is an assosive array that has key 'op' and 'val'. These conditions will be 'OR' with the other conditions.
* for example add ('COL_D_DATA_ID','like', '/tempZone/home/rods/%', array(array('op'=>'=','val'=>'/tempZone/home/rods'")))
* would select all file ids both in subdirectories under '/tempZone/home/rods' and directly under '/tempZone/home/rods'
*/
public function add($name, $op, $val, array $OR_ops_vals = array())
{
require_once("RodsGenQueryNum.inc.php"); //load magic numbers
require_once("RodsGenQueryKeyWd.inc.php"); //load magic keywords
if (isset($GLOBALS['PRODS_GENQUE_NUMS']["$name"])) {
$this->cond['names'][] = $name;
$this->cond['sysnames'][] = $GLOBALS['PRODS_GENQUE_NUMS']["$name"];
$value = "$op '$val'";
foreach ($OR_ops_vals as $op_val) {
$or_op = $op_val['op'];
$or_val = $op_val['val'];
if (empty($or_op) || empty($or_val))
continue;
$value = $value . " || $or_op '$or_val'";
}
$this->cond['values'][] = $value;
} else
if (isset($GLOBALS['PRODS_GENQUE_KEYWD']["$name"])) {
$this->cond_kw['names'][] = $name;
$this->cond_kw['sysnames'][] = $GLOBALS['PRODS_GENQUE_KEYWD']["$name"];
$value = "$op '$val'";
foreach ($OR_ops_vals as $op_val) {
$or_op = $op_val['op'];
$or_val = $op_val['val'];
if (empty($or_op) || empty($or_val))
continue;
$value = $value . " || $or_op '$or_val'";
}
$this->cond_kw['values'][] = $value;
} else {
throw new RODSException("General Query condition field name '$name' is not valid",
'PERR_USER_INPUT_ERROR');
}
}
/**
* make a RP_InxValPair.
*/
public function packetize()
{
return (new RP_InxValPair(count($this->cond['names']),
$this->cond['sysnames'], $this->cond['values']));
}
/**
* make a RP_KeyValPair.
*/
public function packetizeKW()
{
return (new RP_KeyValPair(count($this->cond_kw['names']),
$this->cond_kw['sysnames'], $this->cond_kw['values']));
}
public function getCond()
{
return $this->cond;
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment