From f6ac9134bf0e1ddc32f02eb1506f109e43622d95 Mon Sep 17 00:00:00 2001 From: mconway Date: Fri, 5 Sep 2014 10:22:50 -0400 Subject: [PATCH] #9 switched write opr to openedDataObjInp --- prods/src/RODSConn.class.php | 1081 +++++++---------- prods/src/RodsAPINum.inc.php | 2 + .../src/packet/RP_OpenedDataObjInp.class.php | 43 + 3 files changed, 494 insertions(+), 632 deletions(-) create mode 100644 prods/src/packet/RP_OpenedDataObjInp.class.php diff --git a/prods/src/RODSConn.class.php b/prods/src/RODSConn.class.php index 762b10e..d460e27 100644 --- a/prods/src/RODSConn.class.php +++ b/prods/src/RODSConn.class.php @@ -1,266 +1,231 @@ * @copyright Copyright © 2007, TBD * @package RODSConn */ - - require_once("autoload.inc.php"); require_once("RodsAPINum.inc.php"); require_once("RodsConst.inc.php"); -if (!defined("O_RDONLY")) define ("O_RDONLY", 0); -if (!defined("O_WRONLY")) define ("O_WRONLY", 1); -if (!defined("O_RDWR")) define ("O_RDWR", 2); -if (!defined("O_TRUNC")) define ("O_TRUNC", 512); - -class RODSConn -{ - private $conn; // (resource) socket connection to RODS server - - private $account; // RODS user account - - private $idle; - private $id; - - public $connected; - - /** - * Makes a new connection to RODS server, with supplied user information (name, passwd etc.) - * @param string $host hostname - * @param string $port port number - * @param string $user username - * @param string $pass passwd - * @param string $zone zonename - */ - public function __construct(RODSAccount &$account) - { - $this->account=$account; - $this->connected=false; - $this->conn=NULL; - $this->idle=true; - } - - public function __destruct() - { - if ($this->connected===true) - $this->disconnect(); - } - - public function equals(RODSConn $other) - { - return $this->account->equals($other->account); - } - - public function getSignature() - { - return $this->account->getSignature(); - } - - public function lock() - { - $this->idle=false; - } - - public function unlock() - { - $this->idle=true; - } - - public function isIdle() - { - return ($this->idle); - } - - public function getId() - { - return $this->id; - } - - public function setId($id) - { - $this->id=$id; - } - - public function getAccount() - { - return $this->account; - } - - public function connect() - { - $host=$this->account->host; - $port=$this->account->port; - $user=$this->account->user; - $pass=$this->account->pass; - $zone=$this->account->zone; - $auth_type = $this->account->auth_type; - - // if we're going to use PAM, set up the socket context - // options for SSL connections when we open the connection - if (strcasecmp($auth_type, "PAM") == 0) { - $ssl_opts = array('ssl' => array()); - if (array_key_exists('ssl', $GLOBALS['PRODS_CONFIG'])) { - $ssl_conf = $GLOBALS['PRODS_CONFIG']['ssl']; - if (array_key_exists('verify_peer', $ssl_conf)) { - if (strcasecmp("true", $ssl_conf['verify_peer']) == 0) { - $ssl_opts['ssl']['verify_peer'] = true; - } - } - if (array_key_exists('allow_self_signed', $ssl_conf)) { - if (strcasecmp("true", $ssl_conf['allow_self_signed']) == 0) { - $ssl_opts['ssl']['allow_self_signed'] = true; - } - } - if (array_key_exists('cafile', $ssl_conf)) { - $ssl_opts['ssl']['cafile'] = $ssl_conf['cafile']; - } - if (array_key_exists('capath', $ssl_conf)) { - $ssl_opts['ssl']['capath'] = $ssl_conf['capath']; - } - } - $ssl_ctx = stream_context_get_default($ssl_opts); - $sock_timeout = ini_get("default_socket_timeout"); - $conn = @stream_socket_client("tcp://$host:$port", $errno, $errstr, - $sock_timeout, STREAM_CLIENT_CONNECT, $ssl_ctx); +if (!defined("O_RDONLY")) + define("O_RDONLY", 0); +if (!defined("O_WRONLY")) + define("O_WRONLY", 1); +if (!defined("O_RDWR")) + define("O_RDWR", 2); +if (!defined("O_TRUNC")) + define("O_TRUNC", 512); + +class RODSConn { + + private $conn; // (resource) socket connection to RODS server + private $account; // RODS user account + private $idle; + private $id; + public $connected; + + /** + * Makes a new connection to RODS server, with supplied user information (name, passwd etc.) + * @param string $host hostname + * @param string $port port number + * @param string $user username + * @param string $pass passwd + * @param string $zone zonename + */ + public function __construct(RODSAccount &$account) { + $this->account = $account; + $this->connected = false; + $this->conn = NULL; + $this->idle = true; + } + + public function __destruct() { + if ($this->connected === true) + $this->disconnect(); + } + + public function equals(RODSConn $other) { + return $this->account->equals($other->account); + } + + public function getSignature() { + return $this->account->getSignature(); } - else { - $conn = @fsockopen($host, $port, $errno, $errstr); + + public function lock() { + $this->idle = false; } - if (!$conn) - throw new RODSException("Connection to '$host:$port' failed.1: ($errno)$errstr. ", - "SYS_SOCK_OPEN_ERR"); - $this->conn=$conn; - - // connect to RODS server - $msg=RODSMessage::packConnectMsg($user,$zone); - fwrite($conn, $msg); - - $msg=new RODSMessage(); - $intInfo=$msg->unpack($conn); - if ($intInfo<0) - { - throw new RODSException("Connection to '$host:$port' failed.2. User: $user Zone: $zone", - $GLOBALS['PRODS_ERR_CODES_REV']["$intInfo"]); + + public function unlock() { + $this->idle = true; } - - // are we doing PAM authentication - if (strcasecmp($auth_type, "PAM") == 0) - { - // Ask server to turn on SSL - $req_packet = new RP_sslStartInp(); - $msg=new RODSMessage("RODS_API_REQ_T", $req_packet, - $GLOBALS['PRODS_API_NUMS']['SSL_START_AN']); - fwrite($conn, $msg->pack()); - $msg=new RODSMessage(); - $intInfo=$msg->unpack($conn); - if ($intInfo<0) - { - throw new RODSException("Connection to '$host:$port' failed.ssl1. User: $user Zone: $zone", - $GLOBALS['PRODS_ERR_CODES_REV']["$intInfo"]); - } - // Turn on SSL on our side - if (!stream_socket_enable_crypto($conn, true, STREAM_CRYPTO_METHOD_TLS_CLIENT)) { - throw new RODSException("Error turning on SSL on connection to server '$host:$port'."); - } - - // all good ... do the PAM authentication over the encrypted connection - $req_packet = new RP_pamAuthRequestInp($user, $pass, -1); - $msg=new RODSMessage("RODS_API_REQ_T", $req_packet, - $GLOBALS['PRODS_API_NUMS']['PAM_AUTH_REQUEST_AN']); - fwrite($conn, $msg->pack()); - $msg=new RODSMessage(); - $intInfo=$msg->unpack($conn); - if ($intInfo<0) - { - throw new RODSException("PAM auth failed at server '$host:$port' User: $user Zone: $zone", - $GLOBALS['PRODS_ERR_CODES_REV']["$intInfo"]); - } - - // Update the account object with the temporary password - // and set the auth_type to irods for this connection - $pack = $msg->getBody(); - $pass = $this->account->pass = $pack->irodsPamPassword; - - // Done authentication ... turn ask the server to turn off SSL - $req_packet = new RP_sslEndInp(); - $msg=new RODSMessage("RODS_API_REQ_T", $req_packet, - $GLOBALS['PRODS_API_NUMS']['SSL_END_AN']); - fwrite($conn, $msg->pack()); - $msg=new RODSMessage(); - $intInfo=$msg->unpack($conn); - if ($intInfo<0) - { - throw new RODSException("Connection to '$host:$port' failed.ssl2. User: $user Zone: $zone", - $GLOBALS['PRODS_ERR_CODES_REV']["$intInfo"]); - } - // De-activate SSL on the connection - stream_socket_enable_crypto($conn, false); - - // nasty hack ... some characters are left over to be read - // from the socket after the SSL shutdown, and I can't - // figure out how to consume them via SSL routines, so I - // just read them and throw them away. They need to be consumed - // or later reads get out of sync with the API responses - $r = array($conn); - $w = $e = null; - while (stream_select($r, $w, $e, 0) > 0) { - $s = fread($conn, 1); - } + public function isIdle() { + return ($this->idle); } - - // request authentication - $msg=new RODSMessage("RODS_API_REQ_T",NULL, - $GLOBALS['PRODS_API_NUMS']['AUTH_REQUEST_AN']); - fwrite($conn, $msg->pack()); - - // get chalange string - $msg=new RODSMessage(); - $intInfo=$msg->unpack($conn); - if ($intInfo<0) - { - throw new RODSException("Connection to '$host:$port' failed.3. User: $user Zone: $zone", - $GLOBALS['PRODS_ERR_CODES_REV']["$intInfo"]); + + public function getId() { + return $this->id; } - $pack=$msg->getBody(); - $challenge_b64encoded=$pack->challenge; - $challenge=base64_decode($challenge_b64encoded); - - // encode chalange with passwd - $pad_pass=str_pad($pass,MAX_PASSWORD_LEN,"\0"); - $pwmd5=md5($challenge.$pad_pass,true); - for ($i=0;$iid = $id; } - $response=base64_encode($pwmd5); - - // set response - $resp_packet=new RP_authResponseInp($response,$user); - $msg=new RODSMessage("RODS_API_REQ_T",$resp_packet, - $GLOBALS['PRODS_API_NUMS']['AUTH_RESPONSE_AN']); - fwrite($conn, $msg->pack()); - - // check if we are connected - // get chalange string - $msg=new RODSMessage(); - $intInfo=$msg->unpack($conn); - if ($intInfo<0) - { - $this->disconnect(); - throw new RODSException("Connection to '$host:$port' failed.4 (login failed, possible wrong user/passwd). User: $user Pass: $pass Zone: $zone", - $GLOBALS['PRODS_ERR_CODES_REV']["$intInfo"]); + + public function getAccount() { + return $this->account; } - - $this->connected=true; - // use ticket if specified - if( !empty($this->account->ticket) ) { + + public function connect() { + $host = $this->account->host; + $port = $this->account->port; + $user = $this->account->user; + $pass = $this->account->pass; + $zone = $this->account->zone; + $auth_type = $this->account->auth_type; + + // if we're going to use PAM, set up the socket context + // options for SSL connections when we open the connection + if (strcasecmp($auth_type, "PAM") == 0) { + $ssl_opts = array('ssl' => array()); + if (array_key_exists('ssl', $GLOBALS['PRODS_CONFIG'])) { + $ssl_conf = $GLOBALS['PRODS_CONFIG']['ssl']; + if (array_key_exists('verify_peer', $ssl_conf)) { + if (strcasecmp("true", $ssl_conf['verify_peer']) == 0) { + $ssl_opts['ssl']['verify_peer'] = true; + } + } + if (array_key_exists('allow_self_signed', $ssl_conf)) { + if (strcasecmp("true", $ssl_conf['allow_self_signed']) == 0) { + $ssl_opts['ssl']['allow_self_signed'] = true; + } + } + if (array_key_exists('cafile', $ssl_conf)) { + $ssl_opts['ssl']['cafile'] = $ssl_conf['cafile']; + } + if (array_key_exists('capath', $ssl_conf)) { + $ssl_opts['ssl']['capath'] = $ssl_conf['capath']; + } + } + $ssl_ctx = stream_context_get_default($ssl_opts); + $sock_timeout = ini_get("default_socket_timeout"); + $conn = @stream_socket_client("tcp://$host:$port", $errno, $errstr, $sock_timeout, STREAM_CLIENT_CONNECT, $ssl_ctx); + } else { + $conn = @fsockopen($host, $port, $errno, $errstr); + } + if (!$conn) + throw new RODSException("Connection to '$host:$port' failed.1: ($errno)$errstr. ", "SYS_SOCK_OPEN_ERR"); + $this->conn = $conn; + + // connect to RODS server + $msg = RODSMessage::packConnectMsg($user, $zone); + fwrite($conn, $msg); + + $msg = new RODSMessage(); + $intInfo = $msg->unpack($conn); + if ($intInfo < 0) { + throw new RODSException("Connection to '$host:$port' failed.2. User: $user Zone: $zone", $GLOBALS['PRODS_ERR_CODES_REV']["$intInfo"]); + } + + // are we doing PAM authentication + if (strcasecmp($auth_type, "PAM") == 0) { + // Ask server to turn on SSL + $req_packet = new RP_sslStartInp(); + $msg = new RODSMessage("RODS_API_REQ_T", $req_packet, $GLOBALS['PRODS_API_NUMS']['SSL_START_AN']); + fwrite($conn, $msg->pack()); + $msg = new RODSMessage(); + $intInfo = $msg->unpack($conn); + if ($intInfo < 0) { + throw new RODSException("Connection to '$host:$port' failed.ssl1. User: $user Zone: $zone", $GLOBALS['PRODS_ERR_CODES_REV']["$intInfo"]); + } + // Turn on SSL on our side + if (!stream_socket_enable_crypto($conn, true, STREAM_CRYPTO_METHOD_TLS_CLIENT)) { + throw new RODSException("Error turning on SSL on connection to server '$host:$port'."); + } + + // all good ... do the PAM authentication over the encrypted connection + $req_packet = new RP_pamAuthRequestInp($user, $pass, -1); + $msg = new RODSMessage("RODS_API_REQ_T", $req_packet, $GLOBALS['PRODS_API_NUMS']['PAM_AUTH_REQUEST_AN']); + fwrite($conn, $msg->pack()); + $msg = new RODSMessage(); + $intInfo = $msg->unpack($conn); + if ($intInfo < 0) { + throw new RODSException("PAM auth failed at server '$host:$port' User: $user Zone: $zone", $GLOBALS['PRODS_ERR_CODES_REV']["$intInfo"]); + } + + // Update the account object with the temporary password + // and set the auth_type to irods for this connection + $pack = $msg->getBody(); + $pass = $this->account->pass = $pack->irodsPamPassword; + + // Done authentication ... turn ask the server to turn off SSL + $req_packet = new RP_sslEndInp(); + $msg = new RODSMessage("RODS_API_REQ_T", $req_packet, $GLOBALS['PRODS_API_NUMS']['SSL_END_AN']); + fwrite($conn, $msg->pack()); + $msg = new RODSMessage(); + $intInfo = $msg->unpack($conn); + if ($intInfo < 0) { + throw new RODSException("Connection to '$host:$port' failed.ssl2. User: $user Zone: $zone", $GLOBALS['PRODS_ERR_CODES_REV']["$intInfo"]); + } + // De-activate SSL on the connection + stream_socket_enable_crypto($conn, false); + + // nasty hack ... some characters are left over to be read + // from the socket after the SSL shutdown, and I can't + // figure out how to consume them via SSL routines, so I + // just read them and throw them away. They need to be consumed + // or later reads get out of sync with the API responses + $r = array($conn); + $w = $e = null; + while (stream_select($r, $w, $e, 0) > 0) { + $s = fread($conn, 1); + } + } + + // request authentication + $msg = new RODSMessage("RODS_API_REQ_T", NULL, $GLOBALS['PRODS_API_NUMS']['AUTH_REQUEST_AN']); + fwrite($conn, $msg->pack()); + + // get chalange string + $msg = new RODSMessage(); + $intInfo = $msg->unpack($conn); + if ($intInfo < 0) { + throw new RODSException("Connection to '$host:$port' failed.3. User: $user Zone: $zone", $GLOBALS['PRODS_ERR_CODES_REV']["$intInfo"]); + } + $pack = $msg->getBody(); + $challenge_b64encoded = $pack->challenge; + $challenge = base64_decode($challenge_b64encoded); + + // encode chalange with passwd + $pad_pass = str_pad($pass, MAX_PASSWORD_LEN, "\0"); + $pwmd5 = md5($challenge . $pad_pass, true); + for ($i = 0; $i < strlen($pwmd5); $i++) { //"escape" the string in RODS way... + if (ord($pwmd5[$i]) == 0) { + $pwmd5[$i] = chr(1); + } + } + $response = base64_encode($pwmd5); + + // set response + $resp_packet = new RP_authResponseInp($response, $user); + $msg = new RODSMessage("RODS_API_REQ_T", $resp_packet, $GLOBALS['PRODS_API_NUMS']['AUTH_RESPONSE_AN']); + fwrite($conn, $msg->pack()); + + // check if we are connected + // get chalange string + $msg = new RODSMessage(); + $intInfo = $msg->unpack($conn); + if ($intInfo < 0) { + $this->disconnect(); + throw new RODSException("Connection to '$host:$port' failed.4 (login failed, possible wrong user/passwd). User: $user Pass: $pass Zone: $zone", $GLOBALS['PRODS_ERR_CODES_REV']["$intInfo"]); + } + + $this->connected = true; + // use ticket if specified + if (!empty($this->account->ticket)) { $ticket_packet = new RP_ticketAdminInp('session', $this->account->ticket); $msg = new RODSMessage('RODS_API_REQ_T', $ticket_packet, 723); fwrite($conn, $msg->pack()); @@ -270,17 +235,15 @@ public function connect() $intInfo = $msg->unpack($conn); if ($intInfo < 0) { $this->disconnect(); - throw new RODSException('Cannot set session ticket.', - $GLOBALS['PRODS_ERR_CODES_REV']["$intInfo"]); + throw new RODSException('Cannot set session ticket.', $GLOBALS['PRODS_ERR_CODES_REV']["$intInfo"]); } } + } - } /** * Close the connection (socket) */ - public function disconnect($force = false) - { + public function disconnect($force = false) { if (($this->connected === false) && ($force !== true)) return; @@ -290,18 +253,15 @@ public function disconnect($force = false) $this->connected = false; } - public function createTicket( $object, $permission = 'read', $ticket = '' ) - { + public function createTicket($object, $permission = 'read', $ticket = '') { if ($this->connected === false) { - throw new RODSException("createTicket needs an active connection, but the connection is currently inactive", - 'PERR_CONN_NOT_ACTIVE'); + throw new RODSException("createTicket needs an active connection, but the connection is currently inactive", 'PERR_CONN_NOT_ACTIVE'); } - if( empty($ticket) ) - { + if (empty($ticket)) { // create a 16 characters long ticket $chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'; for ($i = 0; $i < 16; $i++) - $ticket .= $chars[mt_rand(1, strlen($chars))-1]; + $ticket .= $chars[mt_rand(1, strlen($chars)) - 1]; } $ticket_packet = new RP_ticketAdminInp('create', $ticket, $permission, $object); @@ -312,18 +272,15 @@ public function createTicket( $object, $permission = 'read', $ticket = '' ) $msg = new RODSMessage(); $intInfo = $msg->unpack($this->conn); if ($intInfo < 0) { - throw new RODSException('Cannot create ticket "'.$ticket.'" for object "'.$object.'" with permission "'.$permission.'".', - $GLOBALS['PRODS_ERR_CODES_REV']["$intInfo"]); + throw new RODSException('Cannot create ticket "' . $ticket . '" for object "' . $object . '" with permission "' . $permission . '".', $GLOBALS['PRODS_ERR_CODES_REV']["$intInfo"]); } return $ticket; } - public function deleteTicket( $ticket ) - { + public function deleteTicket($ticket) { if ($this->connected === false) { - throw new RODSException("deleteTicket needs an active connection, but the connection is currently inactive", - 'PERR_CONN_NOT_ACTIVE'); + throw new RODSException("deleteTicket needs an active connection, but the connection is currently inactive", 'PERR_CONN_NOT_ACTIVE'); } $ticket_packet = new RP_ticketAdminInp('delete', $ticket); $msg = new RODSMessage('RODS_API_REQ_T', $ticket_packet, 723); @@ -333,8 +290,7 @@ public function deleteTicket( $ticket ) $msg = new RODSMessage(); $intInfo = $msg->unpack($this->conn); if ($intInfo < 0) { - throw new RODSException('Cannot delete ticket "'.$ticket.'".', - $GLOBALS['PRODS_ERR_CODES_REV']["$intInfo"]); + throw new RODSException('Cannot delete ticket "' . $ticket . '".', $GLOBALS['PRODS_ERR_CODES_REV']["$intInfo"]); } } @@ -343,11 +299,9 @@ public function deleteTicket( $ticket ) * @param string $key key obtained from server to generate password. If this key is not specified, this function will ask server for a new key. * @return string temp password */ - public function getTempPassword($key = NULL) - { + public function getTempPassword($key = NULL) { if ($this->connected === false) { - throw new RODSException("getTempPassword needs an active connection, but the connection is currently inactive", - 'PERR_CONN_NOT_ACTIVE'); + throw new RODSException("getTempPassword needs an active connection, but the connection is currently inactive", 'PERR_CONN_NOT_ACTIVE'); } if (NULL == $key) $key = $this->getKeyForTempPassword(); @@ -358,26 +312,21 @@ public function getTempPassword($key = NULL) return $pwmd5; } - /** * Get a key for temp password from the server. this key can then be hashed together with real password to generate an temp password. * @return string key for temp password */ - public function getKeyForTempPassword() - { + public function getKeyForTempPassword() { if ($this->connected === false) { - throw new RODSException("getKeyForTempPassword needs an active connection, but the connection is currently inactive", - 'PERR_CONN_NOT_ACTIVE'); + throw new RODSException("getKeyForTempPassword needs an active connection, but the connection is currently inactive", 'PERR_CONN_NOT_ACTIVE'); } - $msg = new RODSMessage("RODS_API_REQ_T", null, - $GLOBALS['PRODS_API_NUMS']['GET_TEMP_PASSWORD_AN']); + $msg = new RODSMessage("RODS_API_REQ_T", null, $GLOBALS['PRODS_API_NUMS']['GET_TEMP_PASSWORD_AN']); fwrite($this->conn, $msg->pack()); // send it $msg = new RODSMessage(); - $intInfo = (int)$msg->unpack($this->conn); + $intInfo = (int) $msg->unpack($this->conn); if ($intInfo < 0) { - throw new RODSException("RODSConn::getKeyForTempPassword has got an error from the server", - $GLOBALS['PRODS_ERR_CODES_REV']["$intInfo"]); + throw new RODSException("RODSConn::getKeyForTempPassword has got an error from the server", $GLOBALS['PRODS_ERR_CODES_REV']["$intInfo"]); } return ($msg->getBody()->stringToHashWith); } @@ -387,8 +336,7 @@ public function getKeyForTempPassword() * @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($user = NULL) - { + public function getUserInfo($user = NULL) { if (!isset($user)) $user = $this->account->user; @@ -428,21 +376,17 @@ public function getUserInfo($user = NULL) * Make a new directory * @param string $dir input direcotory path string */ - public function mkdir($dir) - { + public function mkdir($dir) { $collInp_pk = new RP_CollInp($dir); - $msg = new RODSMessage("RODS_API_REQ_T", $collInp_pk, - $GLOBALS['PRODS_API_NUMS']['COLL_CREATE_AN']); + $msg = new RODSMessage("RODS_API_REQ_T", $collInp_pk, $GLOBALS['PRODS_API_NUMS']['COLL_CREATE_AN']); fwrite($this->conn, $msg->pack()); // send it $msg = new RODSMessage(); - $intInfo = (int)$msg->unpack($this->conn); + $intInfo = (int) $msg->unpack($this->conn); if ($intInfo < 0) { if (RODSException::rodsErrCodeToAbbr($intInfo) == 'CATALOG_ALREADY_HAS_ITEM_BY_THAT_NAME') { - throw new RODSException("Collection '$dir' Already exists!", - $GLOBALS['PRODS_ERR_CODES_REV']["$intInfo"]); + throw new RODSException("Collection '$dir' Already exists!", $GLOBALS['PRODS_ERR_CODES_REV']["$intInfo"]); } - throw new RODSException("RODSConn::mkdir has got an error from the server", - $GLOBALS['PRODS_ERR_CODES_REV']["$intInfo"]); + throw new RODSException("RODSConn::mkdir has got an error from the server", $GLOBALS['PRODS_ERR_CODES_REV']["$intInfo"]); } } @@ -459,9 +403,7 @@ public function mkdir($dir) * - 'lastObjPath' - last object that was processed. * If this function returns 1, progress will be stopped. */ - public function rmdir($dirpath, $recursive = true, $force = false, - $additional_flags = array(), $status_update_func = null) - { + public function rmdir($dirpath, $recursive = true, $force = false, $additional_flags = array(), $status_update_func = null) { $options = array(); if ($force === true) { $options["forceFlag"] = ""; @@ -477,19 +419,16 @@ public function rmdir($dirpath, $recursive = true, $force = false, $options_pk->fromAssocArray($options); $collInp_pk = new RP_CollInp($dirpath, $options_pk); - $msg = new RODSMessage("RODS_API_REQ_T", $collInp_pk, - $GLOBALS['PRODS_API_NUMS']['RM_COLL_AN']); + $msg = new RODSMessage("RODS_API_REQ_T", $collInp_pk, $GLOBALS['PRODS_API_NUMS']['RM_COLL_AN']); fwrite($this->conn, $msg->pack()); // send it $msg = new RODSMessage(); - $intInfo = (int)$msg->unpack($this->conn); + $intInfo = (int) $msg->unpack($this->conn); while ($msg->getBody() instanceof RP_CollOprStat) { - if (is_callable($status_update_func)) // call status update function if requested - { - $status = call_user_func($status_update_func, - array( - "filesCnt" => $msg->getBody()->filesCnt, - "lastObjPath" => $msg->getBody()->lastObjPath - ) + if (is_callable($status_update_func)) { // call status update function if requested + $status = call_user_func($status_update_func, array( + "filesCnt" => $msg->getBody()->filesCnt, + "lastObjPath" => $msg->getBody()->lastObjPath + ) ); if (false === $status) throw new Exception("status_update_func failed!"); @@ -502,15 +441,14 @@ public function rmdir($dirpath, $recursive = true, $force = false, break; $this->replyStatusPacket(); $msg = new RODSMessage(); - $intInfo = (int)$msg->unpack($this->conn); + $intInfo = (int) $msg->unpack($this->conn); } if ($intInfo < 0) { if (RODSException::rodsErrCodeToAbbr($intInfo) == 'CAT_NO_ROWS_FOUND') { return; } - throw new RODSException("RODSConn::rmdir has got an error from the server", - $GLOBALS['PRODS_ERR_CODES_REV']["$intInfo"]); + throw new RODSException("RODSConn::rmdir has got an error from the server", $GLOBALS['PRODS_ERR_CODES_REV']["$intInfo"]); } } @@ -518,8 +456,7 @@ public function rmdir($dirpath, $recursive = true, $force = false, // in status packet protocol, the server gives a status update packet: // SYS_SVR_TO_CLI_COLL_STAT (99999996) // and it expects an integer only SYS_CLI_TO_SVR_COLL_STAT_REPLY (99999997) - private function replyStatusPacket() - { + private function replyStatusPacket() { fwrite($this->conn, pack("N", 99999997)); } @@ -528,12 +465,9 @@ private function replyStatusPacket() * @param string $dir input direcotory path string * @return an array of string, each string is the name of a child directory. This fuction return empty array, if there is no child direcotry found */ - public function getChildDir($dir, $startingInx = 0, $maxresults = 500, - &$total_num_rows = -1) - { + public function getChildDir($dir, $startingInx = 0, $maxresults = 500, &$total_num_rows = -1) { $cond = array(new RODSQueryCondition("COL_COLL_PARENT_NAME", $dir)); - $que_result = $this->genQuery(array("COL_COLL_NAME"), $cond, array(), - $startingInx, $maxresults, true, array(), 0, $total_num_rows); + $que_result = $this->genQuery(array("COL_COLL_NAME"), $cond, array(), $startingInx, $maxresults, true, array(), 0, $total_num_rows); if (false === $que_result) { return array(); @@ -558,9 +492,7 @@ public function getChildDir($dir, $startingInx = 0, $maxresults = 500, * @param $orderby An associated array specifying how to sort the result by attributes. Each array key is the attribute, array val is 0 (assendent) or 1 (dessendent). The supported attributes are "name", "owner", "mtime". * @return an array of RODSDirStats */ - public function getChildDirWithStats($dir, $orderby = array(), $startingInx = 0, - $maxresults = 500, &$total_num_rows = -1) - { + public function getChildDirWithStats($dir, $orderby = array(), $startingInx = 0, $maxresults = 500, &$total_num_rows = -1) { // set selected value $select_val = array("COL_COLL_NAME", "COL_COLL_ID", "COL_COLL_OWNER_NAME", "COL_COLL_OWNER_ZONE", "COL_COLL_CREATE_TIME", "COL_COLL_MODIFY_TIME", @@ -572,25 +504,29 @@ public function getChildDirWithStats($dir, $orderby = array(), $startingInx = 0, $select_attr = array_fill(0, count($select_val), 1); foreach ($orderby as $key => $val) { if ($key == "name") { - if ($val == 0) $select_attr[0] = ORDER_BY; - else $select_attr[0] = ORDER_BY_DESC; + if ($val == 0) + $select_attr[0] = ORDER_BY; + else + $select_attr[0] = ORDER_BY_DESC; + } else + if ($key == "owner") { + if ($val == 0) + $select_attr[2] = ORDER_BY; + else + $select_attr[2] = ORDER_BY_DESC; } else - if ($key == "owner") { - if ($val == 0) $select_attr[2] = ORDER_BY; - else $select_attr[2] = ORDER_BY_DESC; - } else - if ($key == "mtime") { - if ($val == 0) $select_attr[5] = ORDER_BY; - else $select_attr[5] = ORDER_BY_DESC; - } + if ($key == "mtime") { + if ($val == 0) + $select_attr[5] = ORDER_BY; + else + $select_attr[5] = ORDER_BY_DESC; + } } } $cond = array(new RODSQueryCondition("COL_COLL_PARENT_NAME", $dir)); $continueInx = 0; - $que_result = $this->genQuery($select_val, $cond, - array(), $startingInx, $maxresults, true, - $select_attr, $continueInx, $total_num_rows); + $que_result = $this->genQuery($select_val, $cond, array(), $startingInx, $maxresults, true, $select_attr, $continueInx, $total_num_rows); if (false === $que_result) { return array(); @@ -599,13 +535,7 @@ public function getChildDirWithStats($dir, $orderby = array(), $startingInx = 0, for ($i = 0; $i < count($que_result['COL_COLL_ID']); $i++) { if ($que_result['COL_COLL_NAME'][$i] != "/") { $ret_val[] = new RODSDirStats( - basename($que_result['COL_COLL_NAME'][$i]), - $que_result['COL_COLL_OWNER_NAME'][$i], - $que_result['COL_COLL_OWNER_ZONE'][$i], - $que_result['COL_COLL_MODIFY_TIME'][$i], - $que_result['COL_COLL_CREATE_TIME'][$i], - $que_result['COL_COLL_ID'][$i], - $que_result['COL_COLL_COMMENTS'][$i] + basename($que_result['COL_COLL_NAME'][$i]), $que_result['COL_COLL_OWNER_NAME'][$i], $que_result['COL_COLL_OWNER_ZONE'][$i], $que_result['COL_COLL_MODIFY_TIME'][$i], $que_result['COL_COLL_CREATE_TIME'][$i], $que_result['COL_COLL_ID'][$i], $que_result['COL_COLL_COMMENTS'][$i] ); } } @@ -618,12 +548,9 @@ public function getChildDirWithStats($dir, $orderby = array(), $startingInx = 0, * @param string $dir input direcotory path string * @return an array of string, each string is the name of a child file. This fuction return empty array, if there is no child direcotry found. */ - public function getChildFile($dir, $startingInx = 0, $maxresults = 500, - &$total_num_rows = -1) - { + public function getChildFile($dir, $startingInx = 0, $maxresults = 500, &$total_num_rows = -1) { $cond = array(new RODSQueryCondition("COL_COLL_NAME", $dir)); - $que_result = $this->genQuery(array("COL_DATA_NAME"), $cond, array(), - $startingInx, $maxresults, true, array(), 0, $total_num_rows); + $que_result = $this->genQuery(array("COL_DATA_NAME"), $cond, array(), $startingInx, $maxresults, true, array(), 0, $total_num_rows); if (false === $que_result) { return array(); @@ -639,9 +566,7 @@ public function getChildFile($dir, $startingInx = 0, $maxresults = 500, * @param $orderby An associated array specifying how to sort the result by attributes. Each array key is the attribute, array val is 0 (assendent) or 1 (dessendent). The supported attributes are "name", "size", "owner", "mtime". * @return an array of RODSFileStats */ - public function getChildFileWithStats($dir, array $orderby = array(), - $startingInx = 0, $maxresults = 500, &$total_num_rows = -1) - { + public function getChildFileWithStats($dir, array $orderby = array(), $startingInx = 0, $maxresults = 500, &$total_num_rows = -1) { // set selected value $select_val = array("COL_DATA_NAME", "COL_D_DATA_ID", "COL_DATA_TYPE_NAME", "COL_D_RESC_NAME", "COL_DATA_SIZE", "COL_D_OWNER_NAME", @@ -653,29 +578,35 @@ public function getChildFileWithStats($dir, array $orderby = array(), $select_attr = array_fill(0, count($select_val), 1); foreach ($orderby as $key => $val) { if ($key == "name") { - if ($val == 0) $select_attr[0] = ORDER_BY; - else $select_attr[0] = ORDER_BY_DESC; + if ($val == 0) + $select_attr[0] = ORDER_BY; + else + $select_attr[0] = ORDER_BY_DESC; + } else + if ($key == "size") { + if ($val == 0) + $select_attr[4] = ORDER_BY; + else + $select_attr[4] = ORDER_BY_DESC; } else - if ($key == "size") { - if ($val == 0) $select_attr[4] = ORDER_BY; - else $select_attr[4] = ORDER_BY_DESC; - } else - if ($key == "owner") { - if ($val == 0) $select_attr[5] = ORDER_BY; - else $select_attr[5] = ORDER_BY_DESC; - } else - if ($key == "mtime") { - if ($val == 0) $select_attr[7] = ORDER_BY; - else $select_attr[7] = ORDER_BY_DESC; - } + if ($key == "owner") { + if ($val == 0) + $select_attr[5] = ORDER_BY; + else + $select_attr[5] = ORDER_BY_DESC; + } else + if ($key == "mtime") { + if ($val == 0) + $select_attr[7] = ORDER_BY; + else + $select_attr[7] = ORDER_BY_DESC; + } } } $cond = array(new RODSQueryCondition("COL_COLL_NAME", $dir)); $continueInx = 0; - $que_result = $this->genQuery($select_val, $cond, - array(), $startingInx, $maxresults, true, - $select_attr, $continueInx, $total_num_rows); + $que_result = $this->genQuery($select_val, $cond, array(), $startingInx, $maxresults, true, $select_attr, $continueInx, $total_num_rows); if (false === $que_result) { @@ -684,14 +615,7 @@ public function getChildFileWithStats($dir, array $orderby = array(), $ret_val = array(); for ($i = 0; $i < count($que_result['COL_D_DATA_ID']); $i++) { $ret_val[] = new RODSFileStats( - $que_result['COL_DATA_NAME'][$i], - $que_result['COL_DATA_SIZE'][$i], - $que_result['COL_D_OWNER_NAME'][$i], - $que_result['COL_D_MODIFY_TIME'][$i], - $que_result['COL_D_CREATE_TIME'][$i], - $que_result['COL_D_DATA_ID'][$i], - $que_result['COL_DATA_TYPE_NAME'][$i], - $que_result['COL_D_RESC_NAME'][$i] + $que_result['COL_DATA_NAME'][$i], $que_result['COL_DATA_SIZE'][$i], $que_result['COL_D_OWNER_NAME'][$i], $que_result['COL_D_MODIFY_TIME'][$i], $que_result['COL_D_CREATE_TIME'][$i], $que_result['COL_D_DATA_ID'][$i], $que_result['COL_DATA_TYPE_NAME'][$i], $que_result['COL_D_RESC_NAME'][$i] ); } return $ret_val; @@ -703,25 +627,18 @@ public function getChildFileWithStats($dir, array $orderby = array(), * @param string $dirpath input dir path string * @return RODSDirStats. If dir does not exists, return fales. */ - public function getDirStats($dirpath) - { + public function getDirStats($dirpath) { $cond = array(new RODSQueryCondition("COL_COLL_NAME", $dirpath)); $que_result = $this->genQuery( - array("COL_COLL_NAME", "COL_COLL_ID", "COL_COLL_OWNER_NAME", - "COL_COLL_OWNER_ZONE", "COL_COLL_CREATE_TIME", "COL_COLL_MODIFY_TIME", - "COL_COLL_COMMENTS"), - $cond, array(), 0, 1, false); - if ($que_result === false) return false; + array("COL_COLL_NAME", "COL_COLL_ID", "COL_COLL_OWNER_NAME", + "COL_COLL_OWNER_ZONE", "COL_COLL_CREATE_TIME", "COL_COLL_MODIFY_TIME", + "COL_COLL_COMMENTS"), $cond, array(), 0, 1, false); + if ($que_result === false) + return false; $stats = new RODSDirStats( - basename($que_result['COL_COLL_NAME'][0]), - $que_result['COL_COLL_OWNER_NAME'][0], - $que_result['COL_COLL_OWNER_ZONE'][0], - $que_result['COL_COLL_MODIFY_TIME'][0], - $que_result['COL_COLL_CREATE_TIME'][0], - $que_result['COL_COLL_ID'][0], - $que_result['COL_COLL_COMMENTS'][0] + basename($que_result['COL_COLL_NAME'][0]), $que_result['COL_COLL_OWNER_NAME'][0], $que_result['COL_COLL_OWNER_ZONE'][0], $que_result['COL_COLL_MODIFY_TIME'][0], $que_result['COL_COLL_CREATE_TIME'][0], $que_result['COL_COLL_ID'][0], $que_result['COL_COLL_COMMENTS'][0] ); return $stats; } @@ -731,8 +648,7 @@ public function getDirStats($dirpath) * @param string $filepath input file path string * @return RODSFileStats. If file does not exists, return fales. */ - public function getFileStats($filepath) - { + public function getFileStats($filepath) { $parent = dirname($filepath); $filename = basename($filepath); @@ -740,24 +656,15 @@ public function getFileStats($filepath) new RODSQueryCondition("COL_DATA_NAME", $filename)); $que_result = $this->genQuery( - array("COL_DATA_NAME", "COL_D_DATA_ID", "COL_DATA_TYPE_NAME", - "COL_D_RESC_NAME", "COL_DATA_SIZE", "COL_D_OWNER_NAME", "COL_D_OWNER_ZONE", - "COL_D_CREATE_TIME", - "COL_D_MODIFY_TIME", "COL_D_COMMENTS"), - $cond, array(), 0, 1, false); - if ($que_result === false) return false; + array("COL_DATA_NAME", "COL_D_DATA_ID", "COL_DATA_TYPE_NAME", + "COL_D_RESC_NAME", "COL_DATA_SIZE", "COL_D_OWNER_NAME", "COL_D_OWNER_ZONE", + "COL_D_CREATE_TIME", + "COL_D_MODIFY_TIME", "COL_D_COMMENTS"), $cond, array(), 0, 1, false); + if ($que_result === false) + return false; $stats = new RODSFileStats( - $que_result['COL_DATA_NAME'][0], - $que_result['COL_DATA_SIZE'][0], - $que_result['COL_D_OWNER_NAME'][0], - $que_result['COL_D_OWNER_ZONE'][0], - $que_result['COL_D_MODIFY_TIME'][0], - $que_result['COL_D_CREATE_TIME'][0], - $que_result['COL_D_DATA_ID'][0], - $que_result['COL_DATA_TYPE_NAME'][0], - $que_result['COL_D_RESC_NAME'][0], - $que_result['COL_D_COMMENTS'][0]); + $que_result['COL_DATA_NAME'][0], $que_result['COL_DATA_SIZE'][0], $que_result['COL_D_OWNER_NAME'][0], $que_result['COL_D_OWNER_ZONE'][0], $que_result['COL_D_MODIFY_TIME'][0], $que_result['COL_D_CREATE_TIME'][0], $que_result['COL_D_DATA_ID'][0], $que_result['COL_DATA_TYPE_NAME'][0], $que_result['COL_D_RESC_NAME'][0], $que_result['COL_D_COMMENTS'][0]); return $stats; } @@ -765,8 +672,7 @@ public function getFileStats($filepath) * Check whether a directory (in string) exists on RODS server. * @return true/false */ - public function dirExists($dir) - { + public function dirExists($dir) { $cond = array(new RODSQueryCondition("COL_COLL_NAME", $dir)); $que_result = $this->genQuery(array("COL_COLL_ID"), $cond); @@ -780,8 +686,7 @@ public function dirExists($dir) * Check whether a file (in string) exists on RODS server. * @return true/false */ - public function fileExists($filepath, $rescname = NULL) - { + public function fileExists($filepath, $rescname = NULL) { $parent = dirname($filepath); $filename = basename($filepath); if (empty($rescname)) { @@ -814,8 +719,7 @@ public function fileExists($filepath, $rescname = NULL) * 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($path_src, $desc_resc, array $options = array()) - { + public function repl($path_src, $desc_resc, array $options = array()) { require_once(dirname(__FILE__) . "/RODSObjIOOpr.inc.php"); require_once(dirname(__FILE__) . "/RodsGenQueryKeyWd.inc.php"); @@ -842,12 +746,11 @@ public function repl($path_src, $desc_resc, array $options = array()) case 'backupMode': if ($option_val === true) $opt_arr[$GLOBALS['PRODS_GENQUE_KEYWD'] - ['BACKUP_RESC_NAME_KW']] = $desc_resc; + ['BACKUP_RESC_NAME_KW']] = $desc_resc; break; default: - throw new RODSException("Option '$option_key'=>'$option_val' is not supported", - 'PERR_USER_INPUT_ERROR'); + throw new RODSException("Option '$option_key'=>'$option_val' is not supported", 'PERR_USER_INPUT_ERROR'); } } @@ -856,14 +759,12 @@ public function repl($path_src, $desc_resc, array $options = array()) $inp_pk = new RP_DataObjInp($path_src, 0, 0, 0, 0, 0, $optype, $keyvalpair); - $msg = new RODSMessage("RODS_API_REQ_T", $inp_pk, - $GLOBALS['PRODS_API_NUMS']['DATA_OBJ_REPL_AN']); + $msg = new RODSMessage("RODS_API_REQ_T", $inp_pk, $GLOBALS['PRODS_API_NUMS']['DATA_OBJ_REPL_AN']); fwrite($this->conn, $msg->pack()); // send it $msg = new RODSMessage(); - $intInfo = (int)$msg->unpack($this->conn); + $intInfo = (int) $msg->unpack($this->conn); if ($intInfo < 0) { - throw new RODSException("RODSConn::repl has got an error from the server", - $GLOBALS['PRODS_ERR_CODES_REV']["$intInfo"]); + throw new RODSException("RODSConn::repl has got an error from the server", $GLOBALS['PRODS_ERR_CODES_REV']["$intInfo"]); } $retpk = $msg->getBody(); @@ -877,8 +778,7 @@ public function repl($path_src, $desc_resc, array $options = array()) * @param integer $path_type if 0, then path type is file, if 1, then path type if directory * @return true/false */ - public function rename($path_src, $path_dest, $path_type) - { + public function rename($path_src, $path_dest, $path_type) { require_once(dirname(__FILE__) . "/RODSObjIOOpr.inc.php"); if ($path_type === 0) { @@ -889,14 +789,12 @@ public function rename($path_src, $path_dest, $path_type) $src_pk = new RP_DataObjInp($path_src, 0, 0, 0, 0, 0, $path_type_magic_num); $dest_pk = new RP_DataObjInp($path_dest, 0, 0, 0, 0, 0, $path_type_magic_num); $inp_pk = new RP_DataObjCopyInp($src_pk, $dest_pk); - $msg = new RODSMessage("RODS_API_REQ_T", $inp_pk, - $GLOBALS['PRODS_API_NUMS']['DATA_OBJ_RENAME_AN']); + $msg = new RODSMessage("RODS_API_REQ_T", $inp_pk, $GLOBALS['PRODS_API_NUMS']['DATA_OBJ_RENAME_AN']); fwrite($this->conn, $msg->pack()); // send it $msg = new RODSMessage(); - $intInfo = (int)$msg->unpack($this->conn); + $intInfo = (int) $msg->unpack($this->conn); if ($intInfo < 0) { - throw new RODSException("RODSConn::rename has got an error from the server", - $GLOBALS['PRODS_ERR_CODES_REV']["$intInfo"]); + throw new RODSException("RODSConn::rename has got an error from the server", $GLOBALS['PRODS_ERR_CODES_REV']["$intInfo"]); } } @@ -920,9 +818,7 @@ public function rename($path_src, $path_dest, $path_type) * @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. * @return integer level 1 descriptor */ - public function openFileDesc($path, $mode, &$position, $rescname = NULL, - $assum_file_exists = false, $filetype = 'generic', $cmode = 0644) - { + public function openFileDesc($path, $mode, &$position, $rescname = NULL, $assum_file_exists = false, $filetype = 'generic', $cmode = 0644) { $create_if_not_exists = false; $error_if_exists = false; $seek_to_end_of_file = false; @@ -936,11 +832,11 @@ public function openFileDesc($path, $mode, &$position, $rescname = NULL, $open_flag = O_RDWR; break; case 'w': - $open_flag = O_WRONLY|O_TRUNC; + $open_flag = O_WRONLY | O_TRUNC; $create_if_not_exists = true; break; case 'w+': - $open_flag = O_RDWR|O_TRUNC; + $open_flag = O_RDWR | O_TRUNC; $create_if_not_exists = true; break; case 'a': @@ -964,8 +860,7 @@ public function openFileDesc($path, $mode, &$position, $rescname = NULL, $error_if_exists = true; break; default: - throw new RODSException("RODSConn::openFileDesc() does not recognize input mode:'$mode' ", - "PERR_USER_INPUT_ERROR"); + throw new RODSException("RODSConn::openFileDesc() does not recognize input mode:'$mode' ", "PERR_USER_INPUT_ERROR"); } if ($assum_file_exists === true) @@ -974,29 +869,23 @@ public function openFileDesc($path, $mode, &$position, $rescname = NULL, $file_exists = $this->fileExists($path, $rescname); if (($error_if_exists) && ($file_exists === true)) { - throw new RODSException("RODSConn::openFileDesc() expect file '$path' dose not exists with mode '$mode', but the file does exists", - "PERR_USER_INPUT_ERROR"); + throw new RODSException("RODSConn::openFileDesc() expect file '$path' dose not exists with mode '$mode', but the file does exists", "PERR_USER_INPUT_ERROR"); } - if (($create_if_not_exists) && ($file_exists === false)) // create new file - { - $keyValPair_pk = new RP_KeyValPair(2, array("rescName", "dataType"), - array("$rescname", "$filetype")); - $dataObjInp_pk = new RP_DataObjInp($path, $cmode, $open_flag, 0, -1, 0, 0, - $keyValPair_pk); + if (($create_if_not_exists) && ($file_exists === false)) { // create new file + $keyValPair_pk = new RP_KeyValPair(2, array("rescName", "dataType"), array("$rescname", "$filetype")); + $dataObjInp_pk = new RP_DataObjInp($path, $cmode, $open_flag, 0, -1, 0, 0, $keyValPair_pk); $api_num = $GLOBALS['PRODS_API_NUMS']['DATA_OBJ_CREATE_AN']; - } else // open existing file - { + } else { // open existing file // open the file and get descriptor if (isset($rescname)) { - $keyValPair_pk = new RP_KeyValPair(1, array("rescName"), - array("$rescname")); + $keyValPair_pk = new RP_KeyValPair(1, array("rescName"), array("$rescname")); $dataObjInp_pk = new RP_DataObjInp - ($path, 0, $open_flag, 0, -1, 0, 0, $keyValPair_pk); + ($path, 0, $open_flag, 0, -1, 0, 0, $keyValPair_pk); } else { $dataObjInp_pk = new RP_DataObjInp - ($path, 0, $open_flag, 0, -1, 0, 0); + ($path, 0, $open_flag, 0, -1, 0, 0); } $api_num = $GLOBALS['PRODS_API_NUMS']['DATA_OBJ_OPEN_AN']; } @@ -1005,15 +894,13 @@ public function openFileDesc($path, $mode, &$position, $rescname = NULL, fwrite($this->conn, $msg->pack()); // send it // get value back $msg = new RODSMessage(); - $intInfo = (int)$msg->unpack($this->conn); + $intInfo = (int) $msg->unpack($this->conn); if ($intInfo < 0) { if (RODSException::rodsErrCodeToAbbr($intInfo) == 'CAT_NO_ROWS_FOUND') { throw new RODSException("trying to open a file '$path' " . - "which does not exists with mode '$mode' ", - "PERR_USER_INPUT_ERROR"); + "which does not exists with mode '$mode' ", "PERR_USER_INPUT_ERROR"); } - throw new RODSException("RODSConn::openFileDesc has got an error from the server", - $GLOBALS['PRODS_ERR_CODES_REV']["$intInfo"]); + throw new RODSException("RODSConn::openFileDesc has got an error from the server", $GLOBALS['PRODS_ERR_CODES_REV']["$intInfo"]); } $l1desc = $intInfo; @@ -1031,8 +918,7 @@ public function openFileDesc($path, $mode, &$position, $rescname = NULL, * @param boolean $force flag (true or false) indicating whether force delete or not. * */ - public function fileUnlink($path, $rescname = NULL, $force = false) - { + public function fileUnlink($path, $rescname = NULL, $force = false) { $options = array(); if (isset($rescname)) { $options['rescName'] = $rescname; @@ -1045,26 +931,23 @@ public function fileUnlink($path, $rescname = NULL, $force = false) $options_pk = new RP_KeyValPair(); $options_pk->fromAssocArray($options); $dataObjInp_pk = new RP_DataObjInp - ($path, 0, 0, 0, -1, 0, 0, $options_pk); + ($path, 0, 0, 0, -1, 0, 0, $options_pk); } else { $dataObjInp_pk = new RP_DataObjInp - ($path, 0, 0, 0, -1, 0, 0); + ($path, 0, 0, 0, -1, 0, 0); } - $msg = new RODSMessage("RODS_API_REQ_T", $dataObjInp_pk, - $GLOBALS['PRODS_API_NUMS']['DATA_OBJ_UNLINK_AN']); + $msg = new RODSMessage("RODS_API_REQ_T", $dataObjInp_pk, $GLOBALS['PRODS_API_NUMS']['DATA_OBJ_UNLINK_AN']); fwrite($this->conn, $msg->pack()); // send it // get value back $msg = new RODSMessage(); - $intInfo = (int)$msg->unpack($this->conn); + $intInfo = (int) $msg->unpack($this->conn); if ($intInfo < 0) { if (RODSException::rodsErrCodeToAbbr($intInfo) == 'CAT_NO_ROWS_FOUND') { throw new RODSException("trying to unlink a file '$path' " . - "which does not exists", - "PERR_USER_INPUT_ERROR"); + "which does not exists", "PERR_USER_INPUT_ERROR"); } - throw new RODSException("RODSConn::fileUnlink has got an error from the server", - $GLOBALS['PRODS_ERR_CODES_REV']["$intInfo"]); + throw new RODSException("RODSConn::fileUnlink has got an error from the server", $GLOBALS['PRODS_ERR_CODES_REV']["$intInfo"]); } } @@ -1073,19 +956,16 @@ public function fileUnlink($path, $rescname = NULL, $force = false) * * @param int $l1desc level 1 file descriptor */ - public function closeFileDesc($l1desc) - { + public function closeFileDesc($l1desc) { try { $dataObjCloseInp_pk = new RP_dataObjCloseInp($l1desc); - $msg = new RODSMessage("RODS_API_REQ_T", $dataObjCloseInp_pk, - $GLOBALS['PRODS_API_NUMS']['DATA_OBJ_CLOSE_AN']); + $msg = new RODSMessage("RODS_API_REQ_T", $dataObjCloseInp_pk, $GLOBALS['PRODS_API_NUMS']['DATA_OBJ_CLOSE_AN']); fwrite($this->conn, $msg->pack()); // send it // get value back $msg = new RODSMessage(); - $intInfo = (int)$msg->unpack($this->conn); + $intInfo = (int) $msg->unpack($this->conn); if ($intInfo < 0) { - trigger_error("Got an error from server:$intInfo", - E_USER_WARNING); + trigger_error("Got an error from server:$intInfo", E_USER_WARNING); } } catch (RODSException $e) { trigger_error("Got an exception:$e", E_USER_WARNING); @@ -1099,17 +979,14 @@ public function closeFileDesc($l1desc) * @param int $length up to how many bytes to read. * @return the read string. */ - public function fileRead($l1desc, $length) - { + public function fileRead($l1desc, $length) { $dataObjReadInp_pk = new RP_dataObjReadInp($l1desc, $length); - $msg = new RODSMessage("RODS_API_REQ_T", $dataObjReadInp_pk, - $GLOBALS['PRODS_API_NUMS']['DATA_OBJ_READ_AN']); + $msg = new RODSMessage("RODS_API_REQ_T", $dataObjReadInp_pk, $GLOBALS['PRODS_API_NUMS']['DATA_OBJ_READ_AN']); fwrite($this->conn, $msg->pack()); // send it $msg = new RODSMessage(); - $intInfo = (int)$msg->unpack($this->conn); + $intInfo = (int) $msg->unpack($this->conn); if ($intInfo < 0) { - throw new RODSException("RODSConn::fileRead has got an error from the server", - $GLOBALS['PRODS_ERR_CODES_REV']["$intInfo"]); + throw new RODSException("RODSConn::fileRead has got an error from the server", $GLOBALS['PRODS_ERR_CODES_REV']["$intInfo"]); } return $msg->getBinstr(); } @@ -1122,21 +999,21 @@ public function fileRead($l1desc, $length) * @param int $length up to how many bytes to read. * @return the number of bytes written. */ - public function fileWrite($l1desc, $string, $length = NULL) - { + public function fileWrite($l1desc, $string, $length = NULL) { if (!isset($length)) $length = strlen($string); - $dataObjWriteInp_pk = new RP_dataObjWriteInp($l1desc, $length); - $msg = new RODSMessage("RODS_API_REQ_T", $dataObjWriteInp_pk, - $GLOBALS['PRODS_API_NUMS']['DATA_OBJ_WRITE_AN'], $string); + //$dataObjWriteInp_pk = new RP_dataObjWriteInp($l1desc, $length); + + $openedDataObjInp = new RP_OpenedDataObjInp($l1desc, $length); + $msg = new RODSMessage("RODS_API_REQ_T", $openedDataObjInp, $GLOBALS['PRODS_API_NUMS']['OPENED_DATA_OBJ_WRITE_AN'], $string); + fwrite($this->conn, $msg->pack()); // send header and body msg fwrite($this->conn, $string); // send contents $msg = new RODSMessage(); - $intInfo = (int)$msg->unpack($this->conn); + $intInfo = (int) $msg->unpack($this->conn); if ($intInfo < 0) { - throw new RODSException("RODSConn::fileWrite has got an error from the server", - $GLOBALS['PRODS_ERR_CODES_REV']["$intInfo"]); + throw new RODSException("RODSConn::fileWrite has got an error from the server", $GLOBALS['PRODS_ERR_CODES_REV']["$intInfo"]); } return $intInfo; } @@ -1149,17 +1026,14 @@ public function fileWrite($l1desc, $string, $length = NULL) * If whence is not specified, it is assumed to be SEEK_SET. * @return int the current offset */ - public function fileSeek($l1desc, $offset, $whence = SEEK_SET) - { + public function fileSeek($l1desc, $offset, $whence = SEEK_SET) { $dataObjReadInp_pk = new RP_fileLseekInp($l1desc, $offset, $whence); - $msg = new RODSMessage("RODS_API_REQ_T", $dataObjReadInp_pk, - $GLOBALS['PRODS_API_NUMS']['DATA_OBJ_LSEEK_AN']); + $msg = new RODSMessage("RODS_API_REQ_T", $dataObjReadInp_pk, $GLOBALS['PRODS_API_NUMS']['DATA_OBJ_LSEEK_AN']); fwrite($this->conn, $msg->pack()); // send it $msg = new RODSMessage(); - $intInfo = (int)$msg->unpack($this->conn); + $intInfo = (int) $msg->unpack($this->conn); if ($intInfo < 0) { - throw new RODSException("RODSConn::fileSeek has got an error from the server", - $GLOBALS['PRODS_ERR_CODES_REV']["$intInfo"]); + throw new RODSException("RODSConn::fileSeek has got an error from the server", $GLOBALS['PRODS_ERR_CODES_REV']["$intInfo"]); } $retpk = $msg->getBody(); return $retpk->offset; @@ -1171,8 +1045,7 @@ public function fileSeek($l1desc, $offset, $whence = SEEK_SET) * @param string $name name of the target object. in the case of file and dir, use its full path * @return RODSMeta $meta meta data for the target. */ - public function getMeta($pathtype, $name) - { + public function getMeta($pathtype, $name) { switch ($pathtype) { case 'd': $select = array("COL_META_DATA_ATTR_NAME", "COL_META_DATA_ATTR_VALUE", @@ -1198,8 +1071,7 @@ public function getMeta($pathtype, $name) $condition = array(new RODSQueryCondition("COL_USER_NAME", $name)); break; default: - throw new RODSException("RODSConn::getMeta pathtype '$pathtype' is not supported!", - 'PERR_USER_INPUT_ERROR'); + throw new RODSException("RODSConn::getMeta pathtype '$pathtype' is not supported!", 'PERR_USER_INPUT_ERROR'); } $genque_result = $this->genQuery($select, $condition); @@ -1210,15 +1082,10 @@ public function getMeta($pathtype, $name) $ret_array = array(); for ($i = 0; $i < count($genque_result[$select[0]]); $i++) { $ret_array[$i] = new RODSMeta( - $genque_result[$select[0]][$i], - $genque_result[$select[1]][$i], - $genque_result[$select[2]][$i], - $genque_result[$select[3]][$i] + $genque_result[$select[0]][$i], $genque_result[$select[1]][$i], $genque_result[$select[2]][$i], $genque_result[$select[3]][$i] ); - } return $ret_array; - } /** @@ -1227,18 +1094,14 @@ public function getMeta($pathtype, $name) * @param string $name name of the target object. in the case of file and dir, use its full path * @param RODSMeta $meta meta data to be added. */ - public function addMeta($pathtype, $name, RODSMeta $meta) - { - $pkt = new RP_ModAVUMetadataInp("add", "-$pathtype", $name, $meta->name, - $meta->value, $meta->units); - $msg = new RODSMessage("RODS_API_REQ_T", $pkt, - $GLOBALS['PRODS_API_NUMS']['MOD_AVU_METADATA_AN']); + public function addMeta($pathtype, $name, RODSMeta $meta) { + $pkt = new RP_ModAVUMetadataInp("add", "-$pathtype", $name, $meta->name, $meta->value, $meta->units); + $msg = new RODSMessage("RODS_API_REQ_T", $pkt, $GLOBALS['PRODS_API_NUMS']['MOD_AVU_METADATA_AN']); fwrite($this->conn, $msg->pack()); // send it $msg = new RODSMessage(); - $intInfo = (int)$msg->unpack($this->conn); + $intInfo = (int) $msg->unpack($this->conn); if ($intInfo < 0) { - throw new RODSException("RODSConn::addMeta has got an error from the server", - $GLOBALS['PRODS_ERR_CODES_REV']["$intInfo"]); + throw new RODSException("RODSConn::addMeta has got an error from the server", $GLOBALS['PRODS_ERR_CODES_REV']["$intInfo"]); } } @@ -1248,18 +1111,14 @@ public function addMeta($pathtype, $name, RODSMeta $meta) * @param string $name name of the target object. in the case of file and dir, use its full path * @param RODSMeta $meta meta data to be removed. */ - public function rmMeta($pathtype, $name, RODSMeta $meta) - { - $pkt = new RP_ModAVUMetadataInp("rm", "-$pathtype", $name, $meta->name, - $meta->value, $meta->units); - $msg = new RODSMessage("RODS_API_REQ_T", $pkt, - $GLOBALS['PRODS_API_NUMS']['MOD_AVU_METADATA_AN']); + public function rmMeta($pathtype, $name, RODSMeta $meta) { + $pkt = new RP_ModAVUMetadataInp("rm", "-$pathtype", $name, $meta->name, $meta->value, $meta->units); + $msg = new RODSMessage("RODS_API_REQ_T", $pkt, $GLOBALS['PRODS_API_NUMS']['MOD_AVU_METADATA_AN']); fwrite($this->conn, $msg->pack()); // send it $msg = new RODSMessage(); - $intInfo = (int)$msg->unpack($this->conn); + $intInfo = (int) $msg->unpack($this->conn); if ($intInfo < 0) { - throw new RODSException("RODSConn::rmMeta has got an error from the server", - $GLOBALS['PRODS_ERR_CODES_REV']["$intInfo"]); + throw new RODSException("RODSConn::rmMeta has got an error from the server", $GLOBALS['PRODS_ERR_CODES_REV']["$intInfo"]); } } @@ -1269,18 +1128,15 @@ public function rmMeta($pathtype, $name, RODSMeta $meta) * @param string $name name of the target object. in the case of file and dir, use its full path * @param integer $metaid id of the metadata to be removed. */ - public function rmMetaByID($pathtype, $name, $metaid) - { + public function rmMetaByID($pathtype, $name, $metaid) { $pkt = new RP_ModAVUMetadataInp("rmi", "-$pathtype", $name, $metaid); - $msg = new RODSMessage("RODS_API_REQ_T", $pkt, - $GLOBALS['PRODS_API_NUMS']['MOD_AVU_METADATA_AN']); + $msg = new RODSMessage("RODS_API_REQ_T", $pkt, $GLOBALS['PRODS_API_NUMS']['MOD_AVU_METADATA_AN']); fwrite($this->conn, $msg->pack()); // send it $msg = new RODSMessage(); - $intInfo = (int)$msg->unpack($this->conn); + $intInfo = (int) $msg->unpack($this->conn); if ($intInfo < 0) { if (RODSException::rodsErrCodeToAbbr($intInfo) != 'CAT_SUCCESS_BUT_WITH_NO_INFO') { - throw new RODSException("RODSConn::rmMetaByID has got an error from the server", - $GLOBALS['PRODS_ERR_CODES_REV']["$intInfo"]); + throw new RODSException("RODSConn::rmMetaByID has got an error from the server", $GLOBALS['PRODS_ERR_CODES_REV']["$intInfo"]); } } } @@ -1292,18 +1148,14 @@ public function rmMetaByID($pathtype, $name, $metaid) * @param string $name_src name of the source target object. in the case of file and dir, use its full path * @param string $name_dest name of the destination target object. in the case of file and dir, use its full path */ - public function cpMeta($pathtype_src, $pathtype_dest, $name_src, $name_dest) - { - $pkt = new RP_ModAVUMetadataInp("cp", "-$pathtype_src", - "-$pathtype_dest", $name_src, $name_dest); - $msg = new RODSMessage("RODS_API_REQ_T", $pkt, - $GLOBALS['PRODS_API_NUMS']['MOD_AVU_METADATA_AN']); + public function cpMeta($pathtype_src, $pathtype_dest, $name_src, $name_dest) { + $pkt = new RP_ModAVUMetadataInp("cp", "-$pathtype_src", "-$pathtype_dest", $name_src, $name_dest); + $msg = new RODSMessage("RODS_API_REQ_T", $pkt, $GLOBALS['PRODS_API_NUMS']['MOD_AVU_METADATA_AN']); fwrite($this->conn, $msg->pack()); // send it $msg = new RODSMessage(); - $intInfo = (int)$msg->unpack($this->conn); + $intInfo = (int) $msg->unpack($this->conn); if ($intInfo < 0) { - throw new RODSException("RODSConn::cpMeta has got an error from the server", - $GLOBALS['PRODS_ERR_CODES_REV']["$intInfo"]); + throw new RODSException("RODSConn::cpMeta has got an error from the server", $GLOBALS['PRODS_ERR_CODES_REV']["$intInfo"]); } } @@ -1320,19 +1172,13 @@ public function cpMeta($pathtype_src, $pathtype_dest, $name_src, $name_dest) * @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... * @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 execUserRule($rule_body, - array $inp_params = array(), array $out_params = array(), - array $remotesvr = array(), RODSKeyValPair $options = null) - { + public function execUserRule($rule_body, array $inp_params = array(), array $out_params = array(), array $remotesvr = array(), RODSKeyValPair $options = null) { $inp_params_packets = array(); foreach ($inp_params as $inp_param_key => $inp_param_val) { if (is_a($inp_param_val, 'RODSKeyValPair')) { - $inp_params_packets[] = new RP_MsParam($inp_param_key, - $inp_param_val->makePacket()); - } else // a string - { - $inp_params_packets[] = new RP_MsParam($inp_param_key, - new RP_STR($inp_param_val)); + $inp_params_packets[] = new RP_MsParam($inp_param_key, $inp_param_val->makePacket()); + } else { // a string + $inp_params_packets[] = new RP_MsParam($inp_param_key, new RP_STR($inp_param_val)); } } $inp_param_arr_packet = new RP_MsParamArray($inp_params_packets); @@ -1340,10 +1186,9 @@ public function execUserRule($rule_body, $out_params_desc = implode('%', $out_params); if ((isset($remotesvr['host'])) && (isset($remotesvr['port'])) && - (isset($remotesvr['zone'])) + (isset($remotesvr['zone'])) ) { - $remotesvr_packet = new RP_RHostAddr($remotesvr['host'], - $remotesvr['zone'], $remotesvr['port']); + $remotesvr_packet = new RP_RHostAddr($remotesvr['host'], $remotesvr['zone'], $remotesvr['port']); } else { $remotesvr_packet = new RP_RHostAddr(); } @@ -1353,16 +1198,13 @@ public function execUserRule($rule_body, $options_packet = $options->makePacket(); - $pkt = new RP_ExecMyRuleInp($rule_body, $remotesvr_packet, - $options_packet, $out_params_desc, $inp_param_arr_packet); - $msg = new RODSMessage("RODS_API_REQ_T", $pkt, - $GLOBALS['PRODS_API_NUMS']['EXEC_MY_RULE_AN']); + $pkt = new RP_ExecMyRuleInp($rule_body, $remotesvr_packet, $options_packet, $out_params_desc, $inp_param_arr_packet); + $msg = new RODSMessage("RODS_API_REQ_T", $pkt, $GLOBALS['PRODS_API_NUMS']['EXEC_MY_RULE_AN']); fwrite($this->conn, $msg->pack()); // send it $resv_msg = new RODSMessage(); - $intInfo = (int)$resv_msg->unpack($this->conn); + $intInfo = (int) $resv_msg->unpack($this->conn); if ($intInfo < 0) { - throw new RODSException("RODSConn::execUserRule has got an error from the server", - $GLOBALS['PRODS_ERR_CODES_REV']["$intInfo"]); + throw new RODSException("RODSConn::execUserRule has got an error from the server", $GLOBALS['PRODS_ERR_CODES_REV']["$intInfo"]); } $retpk = $resv_msg->getBody(); $param_array = $retpk->MsParam_PI; @@ -1372,19 +1214,18 @@ public function execUserRule($rule_body, $label = $param->label; $ret_arr["$label"] = $param->STR_PI->myStr; } else - if ($param->type == 'KeyValPair_PI') { - $label = $param->label; - $ret_arr["$label"] = RODSKeyValPair::fromPacket($param->KeyValPair_PI); - } else - if ($param->type == 'ExecCmdOut_PI') { - $label = $param->label; - $exec_ret_val = $param->ExecCmdOut_PI->buf; - $ret_arr["$label"] = $exec_ret_val; - } else { - throw new RODSException("RODSConn::execUserRule got. " . - "an unexpected output param with type: '$param->type' \n", - "PERR_UNEXPECTED_PACKET_FORMAT"); - } + if ($param->type == 'KeyValPair_PI') { + $label = $param->label; + $ret_arr["$label"] = RODSKeyValPair::fromPacket($param->KeyValPair_PI); + } else + if ($param->type == 'ExecCmdOut_PI') { + $label = $param->label; + $exec_ret_val = $param->ExecCmdOut_PI->buf; + $ret_arr["$label"] = $exec_ret_val; + } else { + throw new RODSException("RODSConn::execUserRule got. " . + "an unexpected output param with type: '$param->type' \n", "PERR_UNEXPECTED_PACKET_FORMAT"); + } } return $ret_arr; } @@ -1403,14 +1244,9 @@ public function execUserRule($rule_body, * @return an associated array, keys are the returning field names, each value is an array of the field values. Also, it returns false (boolean), if no rows are found. * Note: This function is very low level. It's not recommended for beginners. */ - public function genQuery(array $select, array $condition = array(), - array $condition_kw = array(), $startingInx = 0, $maxresults = 500, - $getallrows = true, array $select_attr = array(), &$continueInx = 0, - &$total_num_rows = -1) - { + public function genQuery(array $select, array $condition = array(), array $condition_kw = array(), $startingInx = 0, $maxresults = 500, $getallrows = true, array $select_attr = array(), &$continueInx = 0, &$total_num_rows = -1) { if (count($select) > 50) { - trigger_error("genQuery(): Only upto 50 input are supported, rest ignored", - E_USER_WARNING); + trigger_error("genQuery(): Only upto 50 input are supported, rest ignored", E_USER_WARNING); $select = array_slice($select, 0, 50); } @@ -1421,7 +1257,6 @@ public function genQuery(array $select, array $condition = array(), require_once("RodsGenQueryNum.inc.php"); //load magic numbers require_once("RodsGenQueryKeyWd.inc.php"); //load magic numbers - // contruct select packet (RP_InxIvalPair $selectInp) $select_pk = NULL; if (count($select) > 0) { @@ -1432,8 +1267,7 @@ public function genQuery(array $select, array $condition = array(), if (isset($GLOBALS['PRODS_GENQUE_NUMS']["$selval"])) $idx[] = $GLOBALS['PRODS_GENQUE_NUMS']["$selval"]; else - trigger_error("genQuery(): select val '$selval' is not support, ignored", - E_USER_WARNING); + trigger_error("genQuery(): select val '$selval' is not support, ignored", E_USER_WARNING); } $select_pk = new RP_InxIvalPair(count($select), $idx, $select_attr); @@ -1458,12 +1292,10 @@ public function genQuery(array $select, array $condition = array(), $sqlCondInp->fromRODSQueryConditionArray($condition); // construct RP_GenQueryInp packet - $genque_input_pk = new RP_GenQueryInp($maxresults, $continueInx, $condInput, - $select_pk, $sqlCondInp, $GenQueInp_options, $startingInx); + $genque_input_pk = new RP_GenQueryInp($maxresults, $continueInx, $condInput, $select_pk, $sqlCondInp, $GenQueInp_options, $startingInx); // contruce a new API request message, with type GEN_QUERY_AN - $msg = new RODSMessage("RODS_API_REQ_T", $genque_input_pk, - $GLOBALS['PRODS_API_NUMS']['GEN_QUERY_AN']); + $msg = new RODSMessage("RODS_API_REQ_T", $genque_input_pk, $GLOBALS['PRODS_API_NUMS']['GEN_QUERY_AN']); fwrite($this->conn, $msg->pack()); // send it // get value back $msg_resv = new RODSMessage(); @@ -1473,8 +1305,7 @@ public function genQuery(array $select, array $condition = array(), return false; } - throw new RODSException("RODSConn::genQuery has got an error from the server", - $GLOBALS['PRODS_ERR_CODES_REV']["$intInfo"]); + throw new RODSException("RODSConn::genQuery has got an error from the server", $GLOBALS['PRODS_ERR_CODES_REV']["$intInfo"]); } $genque_result_pk = $msg_resv->getBody(); @@ -1490,8 +1321,7 @@ public function genQuery(array $select, array $condition = array(), $more_results = true; // if there are more results to be fetched - while (($genque_result_pk->continueInx > 0) && ($more_results === true) - && ($getallrows === true)) { + while (($genque_result_pk->continueInx > 0) && ($more_results === true) && ($getallrows === true)) { $msg->getBody()->continueInx = $genque_result_pk->continueInx; fwrite($this->conn, $msg->pack()); // re-send it with new continueInx // get value back @@ -1502,33 +1332,28 @@ public function genQuery(array $select, array $condition = array(), $more_results = false; break; } else - throw new RODSException("RODSConn::genQuery has got an error from the server", - $GLOBALS['PRODS_ERR_CODES_REV']["$intInfo"]); + throw new RODSException("RODSConn::genQuery has got an error from the server", $GLOBALS['PRODS_ERR_CODES_REV']["$intInfo"]); } $genque_result_pk = $msg_resv->getBody(); for ($i = 0; $i < $genque_result_pk->attriCnt; $i++) { $sql_res_pk = $genque_result_pk->SqlResult_PI[$i]; $attri_name = $GLOBALS['PRODS_GENQUE_NUMS_REV'][$sql_res_pk->attriInx]; - $result_arr["$attri_name"] = - array_merge($result_arr["$attri_name"], $sql_res_pk->value); + $result_arr["$attri_name"] = array_merge($result_arr["$attri_name"], $sql_res_pk->value); + } + } + + // Make sure and close the query if there are any results left. + if ($genque_result_pk->continueInx > 0) { + $msg->getBody()->continueInx = $genque_result_pk->continueInx; + $msg->getBody()->maxRows = -1; // tells the server to close the query + fwrite($this->conn, $msg->pack()); + $msg_resv = new RODSMessage(); + $intInfo = $msg_resv->unpack($this->conn); + if ($intInfo < 0) { + throw new RODSException("RODSConn::genQuery has got an error from the server", $GLOBALS['PRODS_ERR_CODES_REV']["$intInfo"]); } } - - // Make sure and close the query if there are any results left. - if ($genque_result_pk->continueInx > 0) - { - $msg->getBody()->continueInx=$genque_result_pk->continueInx; - $msg->getBody()->maxRows=-1; // tells the server to close the query - fwrite($this->conn, $msg->pack()); - $msg_resv=new RODSMessage(); - $intInfo=$msg_resv->unpack($this->conn); - if ($intInfo<0) - { - throw new RODSException("RODSConn::genQuery has got an error from the server", - $GLOBALS['PRODS_ERR_CODES_REV']["$intInfo"]); - } - } return $result_arr; } @@ -1542,12 +1367,9 @@ public function genQuery(array $select, array $condition = array(), * @return RODSGenQueResults * Note: This function is very low level. It's not recommended for beginners. */ - public function query(RODSGenQueSelFlds $select, RODSGenQueConds $condition, - $start = 0, $limit = -1) - { + public function query(RODSGenQueSelFlds $select, RODSGenQueConds $condition, $start = 0, $limit = -1) { if (($select->getCount() < 1) || ($select->getCount() > 50)) { - throw new RODSException("Only 1-50 fields are supported", - 'PERR_USER_INPUT_ERROR'); + throw new RODSException("Only 1-50 fields are supported", 'PERR_USER_INPUT_ERROR'); } // contruct select packet (RP_InxIvalPair $selectInp), and condition packets @@ -1556,10 +1378,10 @@ public function query(RODSGenQueSelFlds $select, RODSGenQueConds $condition, $condkw_pk = $condition->packetizeKW(); // determin max number of results per query - if (($limit > 0) && ($limit < 500)) - $max_result_per_query = $limit; - else - $max_result_per_query = 500; + if (($limit > 0) && ($limit < 500)) + $max_result_per_query = $limit; + else + $max_result_per_query = 500; $num_fetched_rows = 0; $continueInx = 0; @@ -1567,12 +1389,10 @@ public function query(RODSGenQueSelFlds $select, RODSGenQueConds $condition, do { // construct RP_GenQueryInp packet $options = 1 | $GLOBALS['PRODS_GENQUE_NUMS']['RETURN_TOTAL_ROW_COUNT']; - $genque_input_pk = new RP_GenQueryInp($max_result_per_query, - $continueInx, $condkw_pk, $select_pk, $cond_pk, $options, $start); + $genque_input_pk = new RP_GenQueryInp($max_result_per_query, $continueInx, $condkw_pk, $select_pk, $cond_pk, $options, $start); // contruce a new API request message, with type GEN_QUERY_AN - $msg = new RODSMessage("RODS_API_REQ_T", $genque_input_pk, - $GLOBALS['PRODS_API_NUMS']['GEN_QUERY_AN']); + $msg = new RODSMessage("RODS_API_REQ_T", $genque_input_pk, $GLOBALS['PRODS_API_NUMS']['GEN_QUERY_AN']); fwrite($this->conn, $msg->pack()); // send it // get value back $msg_resv = new RODSMessage(); @@ -1582,32 +1402,29 @@ public function query(RODSGenQueSelFlds $select, RODSGenQueConds $condition, break; } - throw new RODSException("RODSConn::query has got an error from the server", - $GLOBALS['PRODS_ERR_CODES_REV']["$intInfo"]); + throw new RODSException("RODSConn::query has got an error from the server", $GLOBALS['PRODS_ERR_CODES_REV']["$intInfo"]); } $genque_result_pk = $msg_resv->getBody(); $num_row_added = $results->addResults($genque_result_pk); $continueInx = $genque_result_pk->continueInx; $start = $start + $results->getNumRow(); } while (($continueInx > 0) && - (($results->getNumRow() < $limit) || ($limit < 0))); - + (($results->getNumRow() < $limit) || ($limit < 0))); + // Make sure and close the query if there are any results left. - if ($continueInx > 0) - { - $msg->getBody()->continueInx=$continueInx; - $msg->getBody()->maxRows=-1; // tells the server to close the query - fwrite($this->conn, $msg->pack()); - $msg_resv=new RODSMessage(); - $intInfo=$msg_resv->unpack($this->conn); - if ($intInfo<0) - { - throw new RODSException("RODSConn::query has got an error from the server", - $GLOBALS['PRODS_ERR_CODES_REV']["$intInfo"]); - } - } - + if ($continueInx > 0) { + $msg->getBody()->continueInx = $continueInx; + $msg->getBody()->maxRows = -1; // tells the server to close the query + fwrite($this->conn, $msg->pack()); + $msg_resv = new RODSMessage(); + $intInfo = $msg_resv->unpack($this->conn); + if ($intInfo < 0) { + throw new RODSException("RODSConn::query has got an error from the server", $GLOBALS['PRODS_ERR_CODES_REV']["$intInfo"]); + } + } + return $results; } + } diff --git a/prods/src/RodsAPINum.inc.php b/prods/src/RodsAPINum.inc.php index df112df..cb824ff 100644 --- a/prods/src/RodsAPINum.inc.php +++ b/prods/src/RodsAPINum.inc.php @@ -90,6 +90,7 @@ 'CLOSE_COLLECTION_AN' => '661', 'COLL_REPL_AN' => '662', 'RM_COLL_AN' => '663', + 'OPENED_DATA_OBJ_WRITE_AN' => '676', 'GET_MISC_SVR_INFO_AN' => '700', 'GENERAL_ADMIN_AN' => '701', 'GEN_QUERY_AN' => '702', @@ -196,6 +197,7 @@ '661' => 'CLOSE_COLLECTION_AN', '662' => 'COLL_REPL_AN', '663' => 'RM_COLL_AN', + '676' => 'OPENED_DATA_OBJ_WRITE_AN', '700' => 'GET_MISC_SVR_INFO_AN', '701' => 'GENERAL_ADMIN_AN', '702' => 'GEN_QUERY_AN', diff --git a/prods/src/packet/RP_OpenedDataObjInp.class.php b/prods/src/packet/RP_OpenedDataObjInp.class.php new file mode 100644 index 0000000..b5f81a2 --- /dev/null +++ b/prods/src/packet/RP_OpenedDataObjInp.class.php @@ -0,0 +1,43 @@ + -1"); + } + + if ($offset < 0) { + throw new IllegalArgumentException("offset must be non negative"); + } + + if ($length <= 0) { + throw new IllegalArgumentException("length must be greater than zero"); + } + + if ($oprType < 0) { + throw new IllegalArgumentException("oprtType must be greater than zero"); + } + + if ($whence >= SEEK_START && $whence <= SEEK_END) { + //ok + } else { + throw new IllegalArgumentException("invalid whence value"); + } + if (!isset($KeyValPair_PI)) { + $KeyValPair_PI = new RP_KeyValPair(); + } + $packlets = array("l1descInx" => $fd, "len" => $length, "whence" => $whence, "oprType" => $oprType, "offset" => $offset, "bytesWritten" => 0, 'KeyValPair_PI' => $KeyValPair_PI); + parent::__construct("OpenedDataObjInp_PI", $packlets); + } + +}