Skip to content

Commit

Permalink
Added Temp Url functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
Conrad Weidenkeller committed May 31, 2012
1 parent 5b45176 commit 930eb8d
Show file tree
Hide file tree
Showing 45 changed files with 12,107 additions and 5,205 deletions.
3 changes: 3 additions & 0 deletions Changelog
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
1.7.11 Conrad Weidenkeller <[email protected]>
* Added Temp URL Functionality.

1.7.10 Conrad Weidenkeller <[email protected]>
* Added Streaming URI Functionality

Expand Down
25 changes: 24 additions & 1 deletion cloudfiles.php
Original file line number Diff line number Diff line change
Expand Up @@ -921,7 +921,7 @@ class CF_Container
public $name;
public $object_count;
public $bytes_used;

public $metadata;
public $cdn_enabled;
public $cdn_streaming_uri;
public $cdn_ssl_uri;
Expand Down Expand Up @@ -959,6 +959,7 @@ function __construct(&$cfs_auth, &$cfs_http, $name, $count=0,
$this->name = $name;
$this->object_count = $count;
$this->bytes_used = $bytes;
$this->metadata = array();
$this->cdn_enabled = NULL;
$this->cdn_uri = NULL;
$this->cdn_ssl_uri = NULL;
Expand Down Expand Up @@ -2461,6 +2462,7 @@ function save_to_filename($filename)
* $obj->purge_from_cdn();
* # or
* $obj->purge_from_cdn("[email protected],[email protected]");
* </code>
* @returns boolean True if successful
* @throws CDNNotEnabledException if CDN Is not enabled on this connection
* @throws InvalidResponseException if the response expected is not returned
Expand Down Expand Up @@ -2567,6 +2569,27 @@ private function _initialize()
$this->manifest = $manifest;
return True;
}
/**
* Generate a Temp Url for a object
* Example:
* <code>
* # ... authentication code excluded (see previous examples) ...
* $conn = new CF_Connection($auth);
* $container = $conn->get_container("foo");
* $obj = $container->get_object("foo");
* $obj->get_tmp_url("shared secret, $expire_time_in_seconds, "HTTP_METHOD"
* </code>
* @returns The temp url
*/
public function get_temp_url($key, $expires, $method)
{

$expires += time();
$url = $this->container->cfs_http->getStorageUrl() . '/' . $this->container->name . '/' . $this->name;
return $url . '?temp_url_sig=' . hash_hmac('sha1', strtoupper($method) .
"\n" . $expires . "\n" . parse_url($url, PHP_URL_PATH), $key) .
'&temp_url_expires=' . $expires;
}

#private function _re_auth()
#{
Expand Down
114 changes: 99 additions & 15 deletions cloudfiles_http.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,19 @@
*/
require_once("cloudfiles_exceptions.php");

define("PHP_CF_VERSION", "1.7.10");
define("PHP_CF_VERSION", "1.7.11");
define("USER_AGENT", sprintf("PHP-CloudFiles/%s", PHP_CF_VERSION));
define("MAX_HEADER_NAME_LEN", 128);
define("MAX_HEADER_VALUE_LEN", 256);
define("ACCOUNT_CONTAINER_COUNT", "X-Account-Container-Count");
define("ACCOUNT_BYTES_USED", "X-Account-Bytes-Used");
define("ACCOUNT_KEY", "X-Account-Meta-Key");
define("ACCOUNT_METADATA_HEADER_PREFIX", "X-Account-Meta-");
define("CONTAINER_OBJ_COUNT", "X-Container-Object-Count");
define("CONTAINER_BYTES_USED", "X-Container-Bytes-Used");
define("CONTAINER_METADATA_HEADER_PREFIX", "X-Container-Meta-");
define("DELETE_AFTER", "X-Delete-After");
define("DELETE_AT", "X-Delete-At");
define("MANIFEST_HEADER", "X-Object-Manifest");
define("METADATA_HEADER_PREFIX", "X-Object-Meta-");
define("CONTENT_HEADER_PREFIX", "Content-");
Expand Down Expand Up @@ -80,7 +85,6 @@ class CF_Http
private $dbug;
private $cabundle_path;
private $api_version;

# Authentication instance variables
#
private $storage_url;
Expand All @@ -99,10 +103,15 @@ class CF_Http
private $_user_write_progress_callback_func;
private $_write_callback_type;
private $_text_list;
private $_account_metadata;
private $_account_container_count;
private $_account_bytes_used;
private $_account_key;
private $_container_metadata;
private $_container_object_count;
private $_container_bytes_used;
private $_obj_delete_after;
private $_obj_delete_at;
private $_obj_etag;
private $_obj_last_modified;
private $_obj_content_type;
Expand Down Expand Up @@ -154,10 +163,15 @@ function __construct($api_version)
$this->_write_callback_type = NULL;
$this->_text_list = array();
$this->_return_list = NULL;
$this->_account_metadata = array();
$this->_account_key = NULL;
$this->_account_container_count = 0;
$this->_account_bytes_used = 0;
$this->_container_metadata = array();
$this->_container_object_count = 0;
$this->_container_bytes_used = 0;
$this->_obj_delete_after = NULL;
$this->_obj_delete_at = NULL;
$this->_obj_write_resource = NULL;
$this->_obj_write_string = "";
$this->_obj_etag = NULL;
Expand Down Expand Up @@ -530,16 +544,17 @@ function head_account()

if (!$return_code) {
$this->error_str .= ": Failed to obtain valid HTTP response.";
return array(0,$this->error_str,0,0);
return array(0,$this->error_str,0,0, NULL, array());
}
if ($return_code == 404) {
return array($return_code,"Account not found.",0,0);
return array($return_code,"Account not found.",0,0, NULL, array());
}
if ($return_code == 204) {
return array($return_code,$this->response_reason,
$this->_account_container_count, $this->_account_bytes_used);
$this->_account_container_count, $this->_account_bytes_used,
$this->_account_key, $this->account_metadata);
}
return array($return_code,$this->response_reason,0,0);
return array($return_code,$this->response_reason,0,0, NULL, array());
}

# PUT /v1/Account/Container
Expand Down Expand Up @@ -725,16 +740,17 @@ function head_container($container_name)

if (!$return_code) {
$this->error_str .= ": Failed to obtain valid HTTP response.";
return array(0,$this->error_str,0,0);
return array(0,$this->error_str,0,0, array());
}
if ($return_code == 404) {
return array($return_code,"Container not found.",0,0);
return array($return_code,"Container not found.",0,0, array());
}
if ($return_code == 204 || $return_code == 200) {
return array($return_code,$this->response_reason,
$this->_container_object_count, $this->_container_bytes_used);
$this->_container_object_count, $this->_container_bytes_used,
$this->_container_metadata);
}
return array($return_code,$this->response_reason,0,0);
return array($return_code,$this->response_reason,0,0, array());
}

# GET /v1/Account/Container/Object
Expand Down Expand Up @@ -819,7 +835,6 @@ function put_object(&$obj, &$fp)

$conn_type = "PUT_OBJ";
$url_path = $this->_make_path("STORAGE", $obj->container->name,$obj->name);

$hdrs = $this->_headers($obj);

$etag = $obj->getETag();
Expand Down Expand Up @@ -866,6 +881,60 @@ function put_object(&$obj, &$fp)
}
return array($return_code,$this->response_reason,$this->_obj_etag);
}
function post_account(&$conn)
{
if (!is_object($conn) || get_class($conn) != "CF_Connection") {
throw new SyntaxException(
"Method argument is not a valid CF_Connection object.");
}
if (!is_array($conn->metadata)) {
throw new SyntaxException("Metadata array is empty");
}
$return_code = $this->_send_request("DEL_POST", $this->_make_path("STORAGE"), $conn->metadata, "POST");
switch ($return_code) {
case 202:
case 201:
break;
case 0:
$this->error_str .= ": Failed to obtain valid HTTP response.";
$return_code = 0;
break;
case 404:
$this->error_str = "Account, Container, or Object not found.";
break;
default:
$this->error_str = "Unexpected HTTP return code: $return_code";
break;
}
return $return_code;
}
function post_container(&$cont)
{
if (!is_object($cont) || get_class($cont) != "CF_Container") {
throw new SyntaxException(
"Method argument is not a valid CF_Container object.");
}
if (!is_array($cont->metadata)) {
throw new SyntaxException("Metadata array is empty");
}
$return_code = $this->_send_request("DEL_POST", $this->_make_path("STORAGE", $cont->name), $cont->metadata, "POST");
switch ($return_code) {
case 201:
case 202:
break;
case 0:
$this->error_str .= ": Failed to obtain valid HTTP response.";
$return_code = 0;
break;
case 404:
$this->error_str = "Account, Container, or Object not found.";
break;
default:
$this->error_str = "Unexpected HTTP return code: $return_code";
break;
}
return $return_code;
}

# POST /v1/Account/Container/Object
#
Expand Down Expand Up @@ -920,12 +989,12 @@ function head_object(&$obj)
if (!$return_code) {
$this->error_str .= ": Failed to obtain valid HTTP response.";
return array(0, $this->error_str." ".$this->response_reason,
NULL, NULL, NULL, NULL, array(), NULL, array());
NULL, NULL, NULL, NULL, array(), NULL, NULL, NULL, array());
}

if ($return_code == 404) {
return array($return_code, $this->response_reason,
NULL, NULL, NULL, NULL, array(), NULL, array());
NULL, NULL, NULL, NULL, array(), NULL, NULL, NULL, array());
}
if ($return_code == 204 || $return_code == 200) {
return array($return_code,$this->response_reason,
Expand All @@ -935,11 +1004,13 @@ function head_object(&$obj)
$this->_obj_content_length,
$this->_obj_metadata,
$this->_obj_manifest,
$this->_obj_delete_at,
$this->_obj_delete_after,
$this->_obj_headers);
}
$this->error_str = "Unexpected HTTP return code: $return_code";
return array($return_code, $this->error_str." ".$this->response_reason,
NULL, NULL, NULL, NULL, array(), NULL, array());
NULL, NULL, NULL, NULL, array(), NULL, NULL, NULL, array());
}

# COPY /v1/Account/Container/Object
Expand Down Expand Up @@ -1083,7 +1154,6 @@ function setWriteProgressFunc($func_name)
{
$this->_user_write_progress_callback_func = $func_name;
}

private function _header_cb($ch, $header)
{
$header_len = strlen($header);
Expand Down Expand Up @@ -1154,6 +1224,9 @@ private function _header_cb($ch, $header)
case strtolower(ORIGIN_HEADER):
$this->_obj_headers[ORIGIN_HEADER] = $value;
break;
case strtolower(ACCOUNT_KEY):
$this->_account_key = $value;
break;
default:
if (strncasecmp($name, METADATA_HEADER_PREFIX, strlen(METADATA_HEADER_PREFIX)) == 0) {
$name = substr($name, strlen(METADATA_HEADER_PREFIX));
Expand All @@ -1163,6 +1236,12 @@ private function _header_cb($ch, $header)
(strncasecmp($name, ACCESS_CONTROL_HEADER_PREFIX, strlen(ACCESS_CONTROL_HEADER_PREFIX)) == 0)) {
$this->_obj_headers[$name] = $value;
}
elseif (strncasecmp($name, ACCOUNT_METADATA_HEADER_PREFIX, strlen(ACCOUNT_METADATA_HEADER_PREFIX)) == 0) {
$this->_account_metadata[$name] = $value;
}
elseif (strncasecmp($name, CONTAINER_METADATA_HEADER_PREFIX, strlen(CONTAINER_METADATA_HEADER_PREFIX)) == 0) {
$this->_container_metadata[$name] = $value;
}
}
return $header_len;
}
Expand Down Expand Up @@ -1310,10 +1389,15 @@ private function _reset_callback_vars()
{
$this->_text_list = array();
$this->_return_list = NULL;
$this->_account_metadata = array();
$this->_account_key = NULL;
$this->_account_container_count = 0;
$this->_account_bytes_used = 0;
$this->_container_metadata = array();
$this->_container_object_count = 0;
$this->_container_bytes_used = 0;
$this->_obj_delete_at = NULL;
$this->_obj_delete_after = NULL;
$this->_obj_etag = NULL;
$this->_obj_last_modified = NULL;
$this->_obj_content_type = NULL;
Expand Down
59 changes: 59 additions & 0 deletions docs/classtrees_php-cloudfiles-exceptions.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
<html>
<head>
<title>Class Trees for Package php-cloudfiles-exceptions</title>
<link rel="stylesheet" type="text/css" href="media/style.css">
</head>
<body>

<table border="0" cellspacing="0" cellpadding="0" height="48" width="100%">
<tr>
<td class="header_top">php-cloudfiles-exceptions</td>
</tr>
<tr><td class="header_line"><img src="media/empty.png" width="1" height="1" border="0" alt="" /></td></tr>
<tr>
<td class="header_menu">


[ <a href="classtrees_php-cloudfiles-exceptions.html" class="menu">class tree: php-cloudfiles-exceptions</a> ]
[ <a href="elementindex_php-cloudfiles-exceptions.html" class="menu">index: php-cloudfiles-exceptions</a> ]
[ <a href="elementindex.html" class="menu">all elements</a> ]
</td>
</tr>
<tr><td class="header_line"><img src="media/empty.png" width="1" height="1" border="0" alt="" /></td></tr>
</table>

<table width="100%" border="0" cellpadding="0" cellspacing="0">
<tr valign="top">
<td width="200" class="menu">
<div id="ric">
<p><a href="ric_AUTHORS.html">AUTHORS</a></p>
<p><a href="ric_README.html">README</a></p>
<p><a href="ric_COPYING.html">COPYING</a></p>
<p><a href="ric_Changelog.html">Changelog</a></p>
</div>
<b>Packages:</b><br />
<a href="li_php-cloudfiles.html">php-cloudfiles</a><br />
<a href="li_php-cloudfiles-exceptions.html">php-cloudfiles-exceptions</a><br />
<a href="li_php-cloudfiles-http.html">php-cloudfiles-http</a><br />
<br /><br />
</td>
<td>
<table cellpadding="10" cellspacing="0" width="100%" border="0"><tr><td valign="top">

<h1>Class Trees for Package php-cloudfiles-exceptions</h1>
<hr />
<div class="classtree">Root class Exception</div><br />
<ul>
<li><a href="php-cloudfiles-exceptions/AuthenticationException.html">AuthenticationException</a></li><li><a href="php-cloudfiles-exceptions/BadContentTypeException.html">BadContentTypeException</a></li><li><a href="php-cloudfiles-exceptions/CDNNotEnabledException.html">CDNNotEnabledException</a></li><li><a href="php-cloudfiles-exceptions/ConnectionNotOpenException.html">ConnectionNotOpenException</a></li><li><a href="php-cloudfiles-exceptions/InvalidResponseException.html">InvalidResponseException</a></li><li><a href="php-cloudfiles-exceptions/InvalidUTF8Exception.html">InvalidUTF8Exception</a></li><li><a href="php-cloudfiles-exceptions/IOException.html">IOException</a></li><li><a href="php-cloudfiles-exceptions/MisMatchedChecksumException.html">MisMatchedChecksumException</a></li><li><a href="php-cloudfiles-exceptions/NonEmptyContainerException.html">NonEmptyContainerException</a></li><li><a href="php-cloudfiles-exceptions/NoSuchAccountException.html">NoSuchAccountException</a></li><li><a href="php-cloudfiles-exceptions/NoSuchContainerException.html">NoSuchContainerException</a></li><li><a href="php-cloudfiles-exceptions/NoSuchObjectException.html">NoSuchObjectException</a></li><li><a href="php-cloudfiles-exceptions/SyntaxException.html">SyntaxException</a></li></ul>

<div class="credit">
<hr />
Documentation generated on Thu, 31 May 2012 05:57:25 -0500 by <a href="http://www.phpdoc.org">phpDocumentor 1.4.1</a>
</div>
</td></tr></table>
</td>
</tr>
</table>

</body>
</html>
Loading

0 comments on commit 930eb8d

Please sign in to comment.