Skip to content

Commit

Permalink
Added CDN Purge functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
Conrad Weidenkeller committed Feb 24, 2011
1 parent 694e8fd commit 76dff8b
Show file tree
Hide file tree
Showing 15 changed files with 4,534 additions and 4,563 deletions.
3 changes: 3 additions & 0 deletions Changelog
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
1.7.7 Conrad Weidenkeller <[email protected]>
* Added CDN Purge Functionality

1.7.6 - Chmouel Boudjnah <[email protected]>
* Add Cloud UK Support (conrad.weidenkeller).

Expand Down
64 changes: 63 additions & 1 deletion cloudfiles.php
Original file line number Diff line number Diff line change
Expand Up @@ -1068,7 +1068,37 @@ function make_public($ttl=86400)
$this->cdn_acl_referrer = "";
return $this->cdn_uri;
}

/**
* Purge Containers objects from CDN Cache.
* Example:
* <code>
* # ... authentication code excluded (see previous examples) ...
* #
* $conn = new CF_Authentication($auth);
* $container = $conn->get_container("cdn_enabled");
* $container->purge_from_cdn("[email protected]");
* # or
* $container->purge_from_cdn();
* # or
* $container->purge_from_cdn("[email protected],[email protected]");
* @returns boolean True if successful
* @throws CDNNotEnabledException if CDN Is not enabled on this connection
* @throws InvalidResponseException if the response expected is not returned
*/
function purge_from_cdn($email=null)
{
if (!$this->cfs_http->getCDNMUrl())
{
throw new CDNNotEnabledException(
"Authentication response did not indicate CDN availability");
}
$status = $this->cfs_http->purge_from_cdn($this->name, $email);
if ($status < 199 or $status > 299) {
throw new InvalidResponseException(
"Invalid response (".$status."): ".$this->cfs_http->get_error());
}
return True;
}
/**
* Enable ACL restriction by User Agent for this container.
*
Expand Down Expand Up @@ -2065,6 +2095,38 @@ function save_to_filename($filename)
fclose($fp);
return $result;
}
/**
* Purge this Object from CDN Cache.
* Example:
* <code>
* # ... authentication code excluded (see previous examples) ...
* #
* $conn = new CF_Authentication($auth);
* $container = $conn->get_container("cdn_enabled");
* $obj = $container->get_object("object");
* $obj->purge_from_cdn("[email protected]");
* # or
* $obj->purge_from_cdn();
* # or
* $obj->purge_from_cdn("[email protected],[email protected]");
* @returns boolean True if successful
* @throws CDNNotEnabledException if CDN Is not enabled on this connection
* @throws InvalidResponseException if the response expected is not returned
*/
function purge_from_cdn($email=null)
{
if (!$this->container->cfs_http->getCDNMUrl())
{
throw new CDNNotEnabledException(
"Authentication response did not indicate CDN availability");
}
$status = $this->container->cfs_http->purge_from_cdn($this->container->name . "/" . $this->name, $email);
if ($status < 199 or $status > 299) {
throw new InvalidResponseException(
"Invalid response (".$status."): ".$this->container->cfs_http->get_error());
}
return True;
}

/**
* Set Object's MD5 checksum
Expand Down
22 changes: 19 additions & 3 deletions cloudfiles_http.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
*/
require_once("cloudfiles_exceptions.php");

define("PHP_CF_VERSION", "1.7.6");
define("PHP_CF_VERSION", "1.7.7");
define("USER_AGENT", sprintf("PHP-CloudFiles/%s", PHP_CF_VERSION));
define("ACCOUNT_CONTAINER_COUNT", "X-Account-Container-Count");
define("ACCOUNT_BYTES_USED", "X-Account-Bytes-Used");
Expand All @@ -50,7 +50,7 @@
define("AUTH_USER_HEADER_LEGACY", "X-Storage-User");
define("AUTH_KEY_HEADER_LEGACY", "X-Storage-Pass");
define("AUTH_TOKEN_LEGACY", "X-Storage-Token");

define("CDN_EMAIL", "X-Purge-Email");
/**
* HTTP/cURL wrapper for Cloud Files
*
Expand Down Expand Up @@ -262,8 +262,24 @@ function list_cdn_containers($enabled_only)
return array($return_code,$this->error_str,array());
}

# (CDN) POST /v1/Account/Container
# (CDN) DELETE /v1/Account/Container or /v1/Account/Container/Object
#
function purge_from_cdn($path, $email=null)
{
if(!$path)
throw new SyntaxException("Path not set");
$url_path = $this->_make_path("CDN", NULL, $path);
if($email)
{
$hdrs = array(CDN_EMAIL => $email);
$return_code = $this->_send_request("DEL_POST",$url_path,$hdrs,"DELETE");
}
else
$return_code = $this->_send_request("DEL_POST",$url_path,null,"DELETE");
return $return_code;
}

# (CDN) POST /v1/Account/Container
function update_cdn_container($container_name, $ttl=86400, $cdn_log_retention=False,
$cdn_acl_user_agent="", $cdn_acl_referrer)
{
Expand Down
84 changes: 61 additions & 23 deletions docs/classtrees_php-cloudfiles.html
Original file line number Diff line number Diff line change
@@ -1,36 +1,74 @@
<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<!-- template designed by Marco Von Ballmoos -->
<title></title>
<link rel="stylesheet" href="media/stylesheet.css" />
<meta http-equiv='Content-Type' content='text/html; charset=iso-8859-1'/>
</head>
<body>

<!-- Start of Class Data -->
<H2>

</H2>
<h2>Root class CF_Authentication</h2>
<html>
<head>
<title>Class Trees for Package php-cloudfiles</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</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.html" class="menu">class tree: php-cloudfiles</a> ]
[ <a href="elementindex_php-cloudfiles.html" class="menu">index: php-cloudfiles</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_COPYING.html">COPYING</a></p>
<p><a href="ric_README.html">README</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</h1>
<hr />
<div class="classtree">Root class CF_Authentication</div><br />
<ul>
<li><a href="php-cloudfiles/CF_Authentication.html">CF_Authentication</a></li></ul>

<h2>Root class CF_Connection</h2>
<hr />
<div class="classtree">Root class CF_Connection</div><br />
<ul>
<li><a href="php-cloudfiles/CF_Connection.html">CF_Connection</a></li></ul>

<h2>Root class CF_Container</h2>
<hr />
<div class="classtree">Root class CF_Container</div><br />
<ul>
<li><a href="php-cloudfiles/CF_Container.html">CF_Container</a></li></ul>

<h2>Root class CF_Object</h2>
<hr />
<div class="classtree">Root class CF_Object</div><br />
<ul>
<li><a href="php-cloudfiles/CF_Object.html">CF_Object</a></li></ul>

<p class="notes" id="credit">
Documentation generated on Tue, 14 Dec 2010 05:19:53 -0600 by <a href="http://www.phpdoc.org" target="_blank">phpDocumentor 1.4.3</a>
</p>
</body>
<div class="credit">
<hr />
Documentation generated on Thu, 24 Feb 2011 15:05:56 -0600 by <a href="http://www.phpdoc.org">phpDocumentor 1.4.3</a>
</div>
</td></tr></table>
</td>
</tr>
</table>

</body>
</html>
Loading

0 comments on commit 76dff8b

Please sign in to comment.