Edit File by line
/home/barbar84/www/wp-conte.../plugins/updraftp.../includes/cloudfil...
File: cloudfiles_http.php
<?php
[0] Fix | Delete
/**
[1] Fix | Delete
* This is an HTTP client class for Cloud Files. It uses PHP's cURL module
[2] Fix | Delete
* to handle the actual HTTP request/response. This is NOT a generic HTTP
[3] Fix | Delete
* client class and is only used to abstract out the HTTP communication for
[4] Fix | Delete
* the PHP Cloud Files API.
[5] Fix | Delete
*
[6] Fix | Delete
* This module was designed to re-use existing HTTP(S) connections between
[7] Fix | Delete
* subsequent operations. For example, performing multiple PUT operations
[8] Fix | Delete
* will re-use the same connection.
[9] Fix | Delete
*
[10] Fix | Delete
* This modules also provides support for streaming content into and out
[11] Fix | Delete
* of Cloud Files. The majority (all?) of the PHP HTTP client modules expect
[12] Fix | Delete
* to read the server's response into a string variable. This will not work
[13] Fix | Delete
* with large files without killing your server. Methods like,
[14] Fix | Delete
* get_object_to_stream() and put_object() take an open filehandle
[15] Fix | Delete
* argument for streaming data out of or into Cloud Files.
[16] Fix | Delete
*
[17] Fix | Delete
* Requres PHP 5.x (for Exceptions and OO syntax)
[18] Fix | Delete
*
[19] Fix | Delete
* See COPYING for license information.
[20] Fix | Delete
*
[21] Fix | Delete
* @author Eric "EJ" Johnson <ej@racklabs.com>
[22] Fix | Delete
* @copyright Copyright (c) 2008, Rackspace US, Inc.
[23] Fix | Delete
* @package php-cloudfiles-http
[24] Fix | Delete
*/
[25] Fix | Delete
[26] Fix | Delete
/**
[27] Fix | Delete
*/
[28] Fix | Delete
require_once("cloudfiles_exceptions.php");
[29] Fix | Delete
[30] Fix | Delete
@define("PHP_CF_VERSION", "1.7.11");
[31] Fix | Delete
@define("USER_AGENT", sprintf("PHP-CloudFiles/%s", PHP_CF_VERSION));
[32] Fix | Delete
@define("MAX_HEADER_NAME_LEN", 128);
[33] Fix | Delete
@define("MAX_HEADER_VALUE_LEN", 256);
[34] Fix | Delete
@define("ACCOUNT_CONTAINER_COUNT", "X-Account-Container-Count");
[35] Fix | Delete
@define("ACCOUNT_BYTES_USED", "X-Account-Bytes-Used");
[36] Fix | Delete
@define("ACCOUNT_KEY", "X-Account-Meta-Key");
[37] Fix | Delete
@define("ACCOUNT_METADATA_HEADER_PREFIX", "X-Account-Meta-");
[38] Fix | Delete
@define("CONTAINER_OBJ_COUNT", "X-Container-Object-Count");
[39] Fix | Delete
@define("CONTAINER_BYTES_USED", "X-Container-Bytes-Used");
[40] Fix | Delete
@define("CONTAINER_METADATA_HEADER_PREFIX", "X-Container-Meta-");
[41] Fix | Delete
@define("DELETE_AFTER", "X-Delete-After");
[42] Fix | Delete
@define("DELETE_AT", "X-Delete-At");
[43] Fix | Delete
@define("MANIFEST_HEADER", "X-Object-Manifest");
[44] Fix | Delete
@define("METADATA_HEADER_PREFIX", "X-Object-Meta-");
[45] Fix | Delete
@define("CONTENT_HEADER_PREFIX", "Content-");
[46] Fix | Delete
@define("ACCESS_CONTROL_HEADER_PREFIX", "Access-Control-");
[47] Fix | Delete
@define("ORIGIN_HEADER", "Origin");
[48] Fix | Delete
@define("CDN_URI", "X-CDN-URI");
[49] Fix | Delete
@define("CDN_SSL_URI", "X-CDN-SSL-URI");
[50] Fix | Delete
@define("CDN_STREAMING_URI", "X-CDN-Streaming-URI");
[51] Fix | Delete
@define("CDN_ENABLED", "X-CDN-Enabled");
[52] Fix | Delete
@define("CDN_LOG_RETENTION", "X-Log-Retention");
[53] Fix | Delete
@define("CDN_ACL_USER_AGENT", "X-User-Agent-ACL");
[54] Fix | Delete
@define("CDN_ACL_REFERRER", "X-Referrer-ACL");
[55] Fix | Delete
@define("CDN_TTL", "X-TTL");
[56] Fix | Delete
@define("CDNM_URL", "X-CDN-Management-Url");
[57] Fix | Delete
@define("STORAGE_URL", "X-Storage-Url");
[58] Fix | Delete
@define("AUTH_TOKEN", "X-Auth-Token");
[59] Fix | Delete
@define("AUTH_USER_HEADER", "X-Auth-User");
[60] Fix | Delete
@define("AUTH_KEY_HEADER", "X-Auth-Key");
[61] Fix | Delete
@define("AUTH_USER_HEADER_LEGACY", "X-Storage-User");
[62] Fix | Delete
@define("AUTH_KEY_HEADER_LEGACY", "X-Storage-Pass");
[63] Fix | Delete
@define("AUTH_TOKEN_LEGACY", "X-Storage-Token");
[64] Fix | Delete
@define("CDN_EMAIL", "X-Purge-Email");
[65] Fix | Delete
@define("DESTINATION", "Destination");
[66] Fix | Delete
@define("ETAG_HEADER", "ETag");
[67] Fix | Delete
@define("LAST_MODIFIED_HEADER", "Last-Modified");
[68] Fix | Delete
@define("CONTENT_TYPE_HEADER", "Content-Type");
[69] Fix | Delete
@define("CONTENT_LENGTH_HEADER", "Content-Length");
[70] Fix | Delete
@define("USER_AGENT_HEADER", "User-Agent");
[71] Fix | Delete
[72] Fix | Delete
/**
[73] Fix | Delete
* HTTP/cURL wrapper for Cloud Files
[74] Fix | Delete
*
[75] Fix | Delete
* This class should not be used directly. It's only purpose is to abstract
[76] Fix | Delete
* out the HTTP communication from the main API.
[77] Fix | Delete
*
[78] Fix | Delete
* @package php-cloudfiles-http
[79] Fix | Delete
*/
[80] Fix | Delete
class UpdraftPlus_CF_Http
[81] Fix | Delete
{
[82] Fix | Delete
private $error_str;
[83] Fix | Delete
private $dbug;
[84] Fix | Delete
private $cabundle_path;
[85] Fix | Delete
private $api_version;
[86] Fix | Delete
# Authentication instance variables
[87] Fix | Delete
#
[88] Fix | Delete
private $storage_url;
[89] Fix | Delete
private $cdnm_url;
[90] Fix | Delete
private $auth_token;
[91] Fix | Delete
[92] Fix | Delete
# Request/response variables
[93] Fix | Delete
#
[94] Fix | Delete
private $response_status;
[95] Fix | Delete
private $response_reason;
[96] Fix | Delete
private $connections;
[97] Fix | Delete
[98] Fix | Delete
# Variables used for content/header callbacks
[99] Fix | Delete
#
[100] Fix | Delete
private $_user_read_progress_callback_func;
[101] Fix | Delete
private $_user_write_progress_callback_func;
[102] Fix | Delete
private $_write_callback_type;
[103] Fix | Delete
private $_text_list;
[104] Fix | Delete
private $_account_metadata;
[105] Fix | Delete
private $_account_container_count;
[106] Fix | Delete
private $_account_bytes_used;
[107] Fix | Delete
private $_account_key;
[108] Fix | Delete
private $_container_metadata;
[109] Fix | Delete
private $_container_object_count;
[110] Fix | Delete
private $_container_bytes_used;
[111] Fix | Delete
private $_obj_delete_after;
[112] Fix | Delete
private $_obj_delete_at;
[113] Fix | Delete
private $_obj_etag;
[114] Fix | Delete
private $_obj_last_modified;
[115] Fix | Delete
private $_obj_content_type;
[116] Fix | Delete
private $_obj_content_length;
[117] Fix | Delete
private $_obj_metadata;
[118] Fix | Delete
private $_obj_headers;
[119] Fix | Delete
private $_obj_manifest;
[120] Fix | Delete
private $_obj_write_resource;
[121] Fix | Delete
private $_obj_write_string;
[122] Fix | Delete
private $_cdn_enabled;
[123] Fix | Delete
private $_cdn_ssl_uri;
[124] Fix | Delete
private $_cdn_streaming_uri;
[125] Fix | Delete
private $_cdn_uri;
[126] Fix | Delete
private $_cdn_ttl;
[127] Fix | Delete
private $_cdn_log_retention;
[128] Fix | Delete
private $_cdn_acl_user_agent;
[129] Fix | Delete
private $_cdn_acl_referrer;
[130] Fix | Delete
[131] Fix | Delete
function __construct($api_version)
[132] Fix | Delete
{
[133] Fix | Delete
$this->dbug = False;
[134] Fix | Delete
$this->cabundle_path = NULL;
[135] Fix | Delete
$this->api_version = $api_version;
[136] Fix | Delete
$this->error_str = NULL;
[137] Fix | Delete
[138] Fix | Delete
$this->storage_url = NULL;
[139] Fix | Delete
$this->cdnm_url = NULL;
[140] Fix | Delete
$this->auth_token = NULL;
[141] Fix | Delete
[142] Fix | Delete
$this->response_status = NULL;
[143] Fix | Delete
$this->response_reason = NULL;
[144] Fix | Delete
[145] Fix | Delete
# Curl connections array - since there is no way to "re-set" the
[146] Fix | Delete
# connection paramaters for a cURL handle, we keep an array of
[147] Fix | Delete
# the unique use-cases and funnel all of those same type
[148] Fix | Delete
# requests through the appropriate curl connection.
[149] Fix | Delete
#
[150] Fix | Delete
$this->connections = array(
[151] Fix | Delete
"GET_CALL" => NULL, # GET objects/containers/lists
[152] Fix | Delete
"PUT_OBJ" => NULL, # PUT object
[153] Fix | Delete
"HEAD" => NULL, # HEAD requests
[154] Fix | Delete
"PUT_CONT" => NULL, # PUT container
[155] Fix | Delete
"DEL_POST" => NULL, # DELETE containers/objects, POST objects
[156] Fix | Delete
"COPY" => null, # COPY objects
[157] Fix | Delete
);
[158] Fix | Delete
[159] Fix | Delete
$this->_user_read_progress_callback_func = NULL;
[160] Fix | Delete
$this->_user_write_progress_callback_func = NULL;
[161] Fix | Delete
$this->_write_callback_type = NULL;
[162] Fix | Delete
$this->_text_list = array();
[163] Fix | Delete
$this->_return_list = NULL;
[164] Fix | Delete
$this->_account_metadata = array();
[165] Fix | Delete
$this->_account_key = NULL;
[166] Fix | Delete
$this->_account_container_count = 0;
[167] Fix | Delete
$this->_account_bytes_used = 0;
[168] Fix | Delete
$this->_container_metadata = array();
[169] Fix | Delete
$this->_container_object_count = 0;
[170] Fix | Delete
$this->_container_bytes_used = 0;
[171] Fix | Delete
$this->_obj_delete_after = NULL;
[172] Fix | Delete
$this->_obj_delete_at = NULL;
[173] Fix | Delete
$this->_obj_write_resource = NULL;
[174] Fix | Delete
$this->_obj_write_string = "";
[175] Fix | Delete
$this->_obj_etag = NULL;
[176] Fix | Delete
$this->_obj_last_modified = NULL;
[177] Fix | Delete
$this->_obj_content_type = NULL;
[178] Fix | Delete
$this->_obj_content_length = NULL;
[179] Fix | Delete
$this->_obj_metadata = array();
[180] Fix | Delete
$this->_obj_manifest = NULL;
[181] Fix | Delete
$this->_obj_headers = NULL;
[182] Fix | Delete
$this->_cdn_enabled = NULL;
[183] Fix | Delete
$this->_cdn_ssl_uri = NULL;
[184] Fix | Delete
$this->_cdn_streaming_uri = NULL;
[185] Fix | Delete
$this->_cdn_uri = NULL;
[186] Fix | Delete
$this->_cdn_ttl = NULL;
[187] Fix | Delete
$this->_cdn_log_retention = NULL;
[188] Fix | Delete
$this->_cdn_acl_user_agent = NULL;
[189] Fix | Delete
$this->_cdn_acl_referrer = NULL;
[190] Fix | Delete
[191] Fix | Delete
# The OS list with a PHP without an updated CA File for CURL to
[192] Fix | Delete
# connect to SSL Websites. It is the first 3 letters of the PHP_OS
[193] Fix | Delete
# variable.
[194] Fix | Delete
$OS_CAFILE_NONUPDATED=array(
[195] Fix | Delete
"win","dar"
[196] Fix | Delete
);
[197] Fix | Delete
[198] Fix | Delete
// We don't want this happening automatically - since the UpdraftPlus default is to use our own certificate already
[199] Fix | Delete
// if (in_array((strtolower (substr(PHP_OS, 0,3))), $OS_CAFILE_NONUPDATED))
[200] Fix | Delete
// $this->ssl_use_cabundle();
[201] Fix | Delete
[202] Fix | Delete
}
[203] Fix | Delete
[204] Fix | Delete
function ssl_use_cabundle($path=NULL)
[205] Fix | Delete
{
[206] Fix | Delete
if ($path) {
[207] Fix | Delete
$this->cabundle_path = $path;
[208] Fix | Delete
} else {
[209] Fix | Delete
$this->cabundle_path = UPDRAFTPLUS_DIR.'/includes/cacert.pem';
[210] Fix | Delete
}
[211] Fix | Delete
if (!file_exists($this->cabundle_path)) {
[212] Fix | Delete
throw new IOException("Could not use CA bundle: "
[213] Fix | Delete
. $this->cabundle_path);
[214] Fix | Delete
}
[215] Fix | Delete
return;
[216] Fix | Delete
}
[217] Fix | Delete
[218] Fix | Delete
# Uses separate cURL connection to authenticate
[219] Fix | Delete
#
[220] Fix | Delete
function authenticate($user, $pass, $acct=NULL, $host=NULL)
[221] Fix | Delete
{
[222] Fix | Delete
$path = array();
[223] Fix | Delete
if (isset($acct)){
[224] Fix | Delete
$headers = array(
[225] Fix | Delete
sprintf("%s: %s", AUTH_USER_HEADER_LEGACY, $user),
[226] Fix | Delete
sprintf("%s: %s", AUTH_KEY_HEADER_LEGACY, $pass),
[227] Fix | Delete
);
[228] Fix | Delete
$path[] = $host;
[229] Fix | Delete
$path[] = rawurlencode(sprintf("v%d",$this->api_version));
[230] Fix | Delete
$path[] = rawurlencode($acct);
[231] Fix | Delete
} else {
[232] Fix | Delete
$headers = array(
[233] Fix | Delete
sprintf("%s: %s", AUTH_USER_HEADER, $user),
[234] Fix | Delete
sprintf("%s: %s", AUTH_KEY_HEADER, $pass),
[235] Fix | Delete
);
[236] Fix | Delete
$path[] = $host;
[237] Fix | Delete
}
[238] Fix | Delete
$path[] = "v1.0";
[239] Fix | Delete
$url = implode("/", $path);
[240] Fix | Delete
[241] Fix | Delete
$curl_ch = curl_init();
[242] Fix | Delete
if (!is_null($this->cabundle_path)) {
[243] Fix | Delete
curl_setopt($curl_ch, CURLOPT_CAINFO, $this->cabundle_path);
[244] Fix | Delete
}
[245] Fix | Delete
if (defined('UPDRAFTPLUS_SSL_DISABLEVERIFY')) {
[246] Fix | Delete
curl_setopt($curl_ch, CURLOPT_SSL_VERIFYPEER, UPDRAFTPLUS_SSL_DISABLEVERIFY);
[247] Fix | Delete
} elseif (UpdraftPlus_Options::get_updraft_option('updraft_ssl_disableverify')) {
[248] Fix | Delete
curl_setopt($curl_ch, CURLOPT_SSL_VERIFYPEER, false);
[249] Fix | Delete
} else {
[250] Fix | Delete
curl_setopt($curl_ch, CURLOPT_SSL_VERIFYPEER, true);
[251] Fix | Delete
}
[252] Fix | Delete
[253] Fix | Delete
curl_setopt($curl_ch, CURLOPT_VERBOSE, $this->dbug);
[254] Fix | Delete
curl_setopt($curl_ch, CURLOPT_FOLLOWLOCATION, 1);
[255] Fix | Delete
curl_setopt($curl_ch, CURLOPT_MAXREDIRS, 4);
[256] Fix | Delete
curl_setopt($curl_ch, CURLOPT_HEADER, 0);
[257] Fix | Delete
curl_setopt($curl_ch, CURLOPT_HTTPHEADER, $headers);
[258] Fix | Delete
curl_setopt($curl_ch, CURLOPT_USERAGENT, USER_AGENT);
[259] Fix | Delete
curl_setopt($curl_ch, CURLOPT_RETURNTRANSFER, TRUE);
[260] Fix | Delete
curl_setopt($curl_ch, CURLOPT_HEADERFUNCTION,array(&$this,'_auth_hdr_cb'));
[261] Fix | Delete
curl_setopt($curl_ch, CURLOPT_CONNECTTIMEOUT, 10);
[262] Fix | Delete
curl_setopt($curl_ch, CURLOPT_URL, $url);
[263] Fix | Delete
curl_exec($curl_ch);
[264] Fix | Delete
curl_close($curl_ch);
[265] Fix | Delete
[266] Fix | Delete
return array($this->response_status, $this->response_reason,
[267] Fix | Delete
$this->storage_url, $this->cdnm_url, $this->auth_token);
[268] Fix | Delete
}
[269] Fix | Delete
[270] Fix | Delete
# (CDN) GET /v1/Account
[271] Fix | Delete
#
[272] Fix | Delete
function list_cdn_containers($enabled_only)
[273] Fix | Delete
{
[274] Fix | Delete
$conn_type = "GET_CALL";
[275] Fix | Delete
$url_path = $this->_make_path("CDN");
[276] Fix | Delete
[277] Fix | Delete
$this->_write_callback_type = "TEXT_LIST";
[278] Fix | Delete
if ($enabled_only)
[279] Fix | Delete
{
[280] Fix | Delete
$return_code = $this->_send_request($conn_type, $url_path .
[281] Fix | Delete
'/?enabled_only=true');
[282] Fix | Delete
}
[283] Fix | Delete
else
[284] Fix | Delete
{
[285] Fix | Delete
$return_code = $this->_send_request($conn_type, $url_path);
[286] Fix | Delete
}
[287] Fix | Delete
if (!$return_code) {
[288] Fix | Delete
$this->error_str .= ": Failed to obtain valid HTTP response.";
[289] Fix | Delete
return array(0,$this->error_str,array());
[290] Fix | Delete
}
[291] Fix | Delete
if ($return_code == 401) {
[292] Fix | Delete
return array($return_code,"Unauthorized",array());
[293] Fix | Delete
}
[294] Fix | Delete
if ($return_code == 404) {
[295] Fix | Delete
return array($return_code,"Account not found.",array());
[296] Fix | Delete
}
[297] Fix | Delete
if ($return_code == 204) {
[298] Fix | Delete
return array($return_code,"Account has no CDN enabled Containers.",
[299] Fix | Delete
array());
[300] Fix | Delete
}
[301] Fix | Delete
if ($return_code == 200) {
[302] Fix | Delete
$this->create_array();
[303] Fix | Delete
return array($return_code,$this->response_reason,$this->_text_list);
[304] Fix | Delete
}
[305] Fix | Delete
$this->error_str = "Unexpected HTTP response: ".$this->response_reason;
[306] Fix | Delete
return array($return_code,$this->error_str,array());
[307] Fix | Delete
}
[308] Fix | Delete
[309] Fix | Delete
# (CDN) DELETE /v1/Account/Container or /v1/Account/Container/Object
[310] Fix | Delete
#
[311] Fix | Delete
function purge_from_cdn($path, $email=null)
[312] Fix | Delete
{
[313] Fix | Delete
if(!$path)
[314] Fix | Delete
throw new SyntaxException("Path not set");
[315] Fix | Delete
$url_path = $this->_make_path("CDN", NULL, $path);
[316] Fix | Delete
if($email)
[317] Fix | Delete
{
[318] Fix | Delete
$hdrs = array(CDN_EMAIL => $email);
[319] Fix | Delete
$return_code = $this->_send_request("DEL_POST",$url_path,$hdrs,"DELETE");
[320] Fix | Delete
}
[321] Fix | Delete
else
[322] Fix | Delete
$return_code = $this->_send_request("DEL_POST",$url_path,null,"DELETE");
[323] Fix | Delete
return $return_code;
[324] Fix | Delete
}
[325] Fix | Delete
[326] Fix | Delete
# (CDN) POST /v1/Account/Container
[327] Fix | Delete
function update_cdn_container($container_name, $ttl=86400, $cdn_log_retention=False,
[328] Fix | Delete
$cdn_acl_user_agent="", $cdn_acl_referrer)
[329] Fix | Delete
{
[330] Fix | Delete
if ($container_name == "")
[331] Fix | Delete
throw new SyntaxException("Container name not set.");
[332] Fix | Delete
[333] Fix | Delete
if ($container_name != "0" and !isset($container_name))
[334] Fix | Delete
throw new SyntaxException("Container name not set.");
[335] Fix | Delete
[336] Fix | Delete
$url_path = $this->_make_path("CDN", $container_name);
[337] Fix | Delete
$hdrs = array(
[338] Fix | Delete
CDN_ENABLED => "True",
[339] Fix | Delete
CDN_TTL => $ttl,
[340] Fix | Delete
CDN_LOG_RETENTION => $cdn_log_retention ? "True" : "False",
[341] Fix | Delete
CDN_ACL_USER_AGENT => $cdn_acl_user_agent,
[342] Fix | Delete
CDN_ACL_REFERRER => $cdn_acl_referrer,
[343] Fix | Delete
);
[344] Fix | Delete
$return_code = $this->_send_request("DEL_POST",$url_path,$hdrs,"POST");
[345] Fix | Delete
if ($return_code == 401) {
[346] Fix | Delete
$this->error_str = "Unauthorized";
[347] Fix | Delete
return array($return_code, $this->error_str, NULL);
[348] Fix | Delete
}
[349] Fix | Delete
if ($return_code == 404) {
[350] Fix | Delete
$this->error_str = "Container not found.";
[351] Fix | Delete
return array($return_code, $this->error_str, NULL);
[352] Fix | Delete
}
[353] Fix | Delete
if ($return_code != 202) {
[354] Fix | Delete
$this->error_str="Unexpected HTTP response: ".$this->response_reason;
[355] Fix | Delete
return array($return_code, $this->error_str, NULL);
[356] Fix | Delete
}
[357] Fix | Delete
return array($return_code, "Accepted", $this->_cdn_uri, $this->_cdn_ssl_uri);
[358] Fix | Delete
[359] Fix | Delete
}
[360] Fix | Delete
[361] Fix | Delete
# (CDN) PUT /v1/Account/Container
[362] Fix | Delete
#
[363] Fix | Delete
function add_cdn_container($container_name, $ttl=86400)
[364] Fix | Delete
{
[365] Fix | Delete
if ($container_name == "")
[366] Fix | Delete
throw new SyntaxException("Container name not set.");
[367] Fix | Delete
[368] Fix | Delete
if ($container_name != "0" and !isset($container_name))
[369] Fix | Delete
throw new SyntaxException("Container name not set.");
[370] Fix | Delete
[371] Fix | Delete
$url_path = $this->_make_path("CDN", $container_name);
[372] Fix | Delete
$hdrs = array(
[373] Fix | Delete
CDN_ENABLED => "True",
[374] Fix | Delete
CDN_TTL => $ttl,
[375] Fix | Delete
);
[376] Fix | Delete
$return_code = $this->_send_request("PUT_CONT", $url_path, $hdrs);
[377] Fix | Delete
if ($return_code == 401) {
[378] Fix | Delete
$this->error_str = "Unauthorized";
[379] Fix | Delete
return array($return_code,$this->response_reason,False);
[380] Fix | Delete
}
[381] Fix | Delete
if (!in_array($return_code, array(201,202))) {
[382] Fix | Delete
$this->error_str="Unexpected HTTP response: ".$this->response_reason;
[383] Fix | Delete
return array($return_code,$this->response_reason,False);
[384] Fix | Delete
}
[385] Fix | Delete
return array($return_code,$this->response_reason,$this->_cdn_uri,
[386] Fix | Delete
$this->_cdn_ssl_uri);
[387] Fix | Delete
}
[388] Fix | Delete
[389] Fix | Delete
# (CDN) POST /v1/Account/Container
[390] Fix | Delete
#
[391] Fix | Delete
function remove_cdn_container($container_name)
[392] Fix | Delete
{
[393] Fix | Delete
if ($container_name == "")
[394] Fix | Delete
throw new SyntaxException("Container name not set.");
[395] Fix | Delete
[396] Fix | Delete
if ($container_name != "0" and !isset($container_name))
[397] Fix | Delete
throw new SyntaxException("Container name not set.");
[398] Fix | Delete
[399] Fix | Delete
$url_path = $this->_make_path("CDN", $container_name);
[400] Fix | Delete
$hdrs = array(CDN_ENABLED => "False");
[401] Fix | Delete
$return_code = $this->_send_request("DEL_POST",$url_path,$hdrs,"POST");
[402] Fix | Delete
if ($return_code == 401) {
[403] Fix | Delete
$this->error_str = "Unauthorized";
[404] Fix | Delete
return array($return_code, $this->error_str);
[405] Fix | Delete
}
[406] Fix | Delete
if ($return_code == 404) {
[407] Fix | Delete
$this->error_str = "Container not found.";
[408] Fix | Delete
return array($return_code, $this->error_str);
[409] Fix | Delete
}
[410] Fix | Delete
if ($return_code != 202) {
[411] Fix | Delete
$this->error_str="Unexpected HTTP response: ".$this->response_reason;
[412] Fix | Delete
return array($return_code, $this->error_str);
[413] Fix | Delete
}
[414] Fix | Delete
return array($return_code, "Accepted");
[415] Fix | Delete
}
[416] Fix | Delete
[417] Fix | Delete
# (CDN) HEAD /v1/Account
[418] Fix | Delete
#
[419] Fix | Delete
function head_cdn_container($container_name)
[420] Fix | Delete
{
[421] Fix | Delete
if ($container_name == "")
[422] Fix | Delete
throw new SyntaxException("Container name not set.");
[423] Fix | Delete
[424] Fix | Delete
if ($container_name != "0" and !isset($container_name))
[425] Fix | Delete
throw new SyntaxException("Container name not set.");
[426] Fix | Delete
[427] Fix | Delete
$conn_type = "HEAD";
[428] Fix | Delete
$url_path = $this->_make_path("CDN", $container_name);
[429] Fix | Delete
$return_code = $this->_send_request($conn_type, $url_path, NULL, "GET", True);
[430] Fix | Delete
[431] Fix | Delete
if (!$return_code) {
[432] Fix | Delete
$this->error_str .= ": Failed to obtain valid HTTP response.";
[433] Fix | Delete
return array(0,$this->error_str,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL);
[434] Fix | Delete
}
[435] Fix | Delete
if ($return_code == 401) {
[436] Fix | Delete
return array($return_code,"Unauthorized",NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL);
[437] Fix | Delete
}
[438] Fix | Delete
if ($return_code == 404) {
[439] Fix | Delete
return array($return_code,"Account not found.",NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL);
[440] Fix | Delete
}
[441] Fix | Delete
if ($return_code == 204) {
[442] Fix | Delete
return array($return_code,$this->response_reason,
[443] Fix | Delete
$this->_cdn_enabled, $this->_cdn_ssl_uri,
[444] Fix | Delete
$this->_cdn_streaming_uri,
[445] Fix | Delete
$this->_cdn_uri, $this->_cdn_ttl,
[446] Fix | Delete
$this->_cdn_log_retention,
[447] Fix | Delete
$this->_cdn_acl_user_agent,
[448] Fix | Delete
$this->_cdn_acl_referrer
[449] Fix | Delete
);
[450] Fix | Delete
}
[451] Fix | Delete
return array($return_code,$this->response_reason,
[452] Fix | Delete
NULL,NULL,NULL,NULL,
[453] Fix | Delete
$this->_cdn_log_retention,
[454] Fix | Delete
$this->_cdn_acl_user_agent,
[455] Fix | Delete
$this->_cdn_acl_referrer,
[456] Fix | Delete
NULL
[457] Fix | Delete
);
[458] Fix | Delete
}
[459] Fix | Delete
[460] Fix | Delete
# GET /v1/Account
[461] Fix | Delete
#
[462] Fix | Delete
function list_containers($limit=0, $marker=NULL)
[463] Fix | Delete
{
[464] Fix | Delete
$conn_type = "GET_CALL";
[465] Fix | Delete
$url_path = $this->_make_path();
[466] Fix | Delete
[467] Fix | Delete
$limit = intval($limit);
[468] Fix | Delete
$params = array();
[469] Fix | Delete
if ($limit > 0) {
[470] Fix | Delete
$params[] = "limit=$limit";
[471] Fix | Delete
}
[472] Fix | Delete
if ($marker) {
[473] Fix | Delete
$params[] = "marker=".rawurlencode($marker);
[474] Fix | Delete
}
[475] Fix | Delete
if (!empty($params)) {
[476] Fix | Delete
$url_path .= "?" . implode("&", $params);
[477] Fix | Delete
}
[478] Fix | Delete
[479] Fix | Delete
$this->_write_callback_type = "TEXT_LIST";
[480] Fix | Delete
$return_code = $this->_send_request($conn_type, $url_path);
[481] Fix | Delete
[482] Fix | Delete
if (!$return_code) {
[483] Fix | Delete
$this->error_str .= ": Failed to obtain valid HTTP response.";
[484] Fix | Delete
return array(0,$this->error_str,array());
[485] Fix | Delete
}
[486] Fix | Delete
if ($return_code == 204) {
[487] Fix | Delete
return array($return_code, "Account has no containers.", array());
[488] Fix | Delete
}
[489] Fix | Delete
if ($return_code == 404) {
[490] Fix | Delete
$this->error_str = "Invalid account name for authentication token.";
[491] Fix | Delete
return array($return_code,$this->error_str,array());
[492] Fix | Delete
}
[493] Fix | Delete
if ($return_code == 200) {
[494] Fix | Delete
$this->create_array();
[495] Fix | Delete
return array($return_code, $this->response_reason, $this->_text_list);
[496] Fix | Delete
}
[497] Fix | Delete
$this->error_str = "Unexpected HTTP response: ".$this->response_reason;
[498] Fix | Delete
return array($return_code,$this->error_str,array());
[499] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function