Drizzled Public API Documentation

CSS3Protocol.h
00001 #pragma once
00002 #ifndef __CSS3PROTOCOL_H__
00003 #define __CSS3PROTOCOL_H__
00004 /* Copyright (C) 2009 PrimeBase Technologies GmbH, Germany
00005  *
00006  * PrimeBase Media Stream for MySQL
00007  *
00008  * This program is free software; you can redistribute it and/or modify
00009  * it under the terms of the GNU General Public License as published by
00010  * the Free Software Foundation; either version 2 of the License, or
00011  * (at your option) any later version.
00012  *
00013  * This program is distributed in the hope that it will be useful,
00014  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00015  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00016  * GNU General Public License for more details.
00017  *
00018  * You should have received a copy of the GNU General Public License
00019  * along with this program; if not, write to the Free Software
00020  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
00021  *
00022  *  Created by Barry Leslie on 10/02/09.
00023  *
00024  */
00025 
00026 #include "CSHTTPStream.h"
00027 #include "CSMd5.h"
00028 class S3ProtocolCon;
00029 
00030 #define PUB_KEY_BIT   ((uint8_t)1)
00031 #define PRIV_KEY_BIT  ((uint8_t)2)
00032 #define SERVER_BIT    ((uint8_t)4)
00033 
00034 
00035 typedef struct S3Range {
00036    off64_t startByte;
00037    off64_t endByte;
00038 } S3RangeRec, *S3RangePtr;
00039 
00040 class CSS3Protocol: public CSRefObject {
00041   private:
00042   
00043   CSStringBuffer *s3_server;
00044   
00045   CSString *s3_public_key;
00046   CSString *s3_private_key;
00047   
00048   uint8_t s3_ready; // A flag to indicate if the S3 protocol has been fully initialised.
00049   uint32_t s3_maxRetries; 
00050   uint32_t s3_sleepTime; 
00051   
00052   CSString *s3_getSignature(const char *verb, 
00053                 const char *md5, 
00054                 const char *content_type, 
00055                 const char *date, 
00056                 const char *bucket, 
00057                 const char *key,
00058                 CSString *headers = NULL 
00059               );
00060               
00061   public:
00062   CSS3Protocol();
00063     
00064   ~CSS3Protocol();
00065   
00066   void s3_setServer(const char *server_arg)
00067   {
00068     s3_server->setLength(0);
00069     if (server_arg && *server_arg) {
00070       s3_ready |= SERVER_BIT;
00071       
00072       s3_server->append(server_arg);
00073       if (server_arg[strlen(server_arg)-1] != '/')
00074         s3_server->append("/");
00075     } else {
00076       s3_ready ^= SERVER_BIT;
00077     }
00078   }
00079   const char *s3_getServer() { return s3_server->getCString();}
00080   
00081   void s3_setPublicKey(const char *key_arg) 
00082   {
00083     s3_public_key->release();
00084     s3_public_key = NULL;
00085     if (key_arg && *key_arg) {
00086       s3_ready |= PUB_KEY_BIT;          
00087       s3_public_key = CSString::newString(key_arg);
00088     } else {
00089       s3_ready ^= PUB_KEY_BIT;
00090     }
00091   }
00092   const char *s3_getPublicKey() { return s3_public_key->getCString();}
00093   
00094   void s3_setPrivateKey(const char *key_arg)
00095   {
00096     s3_private_key->release();
00097     s3_private_key = NULL;
00098     if (key_arg && *key_arg) {
00099       s3_ready |= PRIV_KEY_BIT;         
00100       s3_private_key = CSString::newString(key_arg);
00101     } else {
00102       s3_ready ^= PRIV_KEY_BIT;
00103     }
00104   }
00105 
00106   void s3_setMaxRetries(uint32_t retries){s3_maxRetries = retries;}
00107   void s3_setSleepTime(uint32_t nap_time){s3_sleepTime = nap_time;}
00108   
00109   const char *s3_getPrivateKey() { return s3_private_key->getCString();}
00110   
00111   bool s3_isReady() { return ((s3_ready & SERVER_BIT) && (s3_ready & PUB_KEY_BIT) && (s3_ready & PRIV_KEY_BIT));}
00112   
00113   // s3_getAuthorization() returns the S3 Authorization sting and the time on which it was based.
00114   CSString *s3_getAuthorization(const char *bucket, const char *key, const char *content_type, uint32_t *s3AuthorizationTime);
00115   
00116   CSVector *s3_send(CSInputStream *input, const char *bucket, const char *key, off64_t size, const char *content_type = NULL, Md5Digest *digest = NULL, const char *s3Authorization = NULL, time_t s3AuthorizationTime = 0);
00117 
00118   // s3_receive() returns false if the object was not found.
00119   // If 'output' is NULL then only the headers will be fetched.
00120   CSVector *s3_receive(CSOutputStream *output, const char *bucket, const char *key, bool *found, S3RangePtr range = NULL, time_t *last_modified = NULL);
00121 
00122   // s3_delete() returns false if the object was not found.
00123   bool s3_delete(const char *bucket, const char *key);
00124   
00125   void s3_copy(const char *dest_server, const char *dest_bucket, const char *dest_key, const char *src_bucket, const char *src_key);
00126   
00127   // s3_list() returns a CSString list if the keys in the bucket with the specified prefix.
00128   // The list size returned can be limited with the 'max' parameter. The value 0 indicates no max.
00129   CSVector *s3_list(const char *bucket, const char *key_prefix = NULL, uint32_t max = 0);
00130 
00131   CSString *s3_getDataURL(const char *bucket, const char *key, uint32_t keep_alive);
00132 };
00133 
00134 #endif //__CSS3PROTOCOL_H__