2
#ifndef __CSS3PROTOCOL_H__
3
#define __CSS3PROTOCOL_H__
4
/* Copyright (C) 2009 PrimeBase Technologies GmbH, Germany
6
* PrimeBase Media Stream for MySQL
8
* This program is free software; you can redistribute it and/or modify
9
* it under the terms of the GNU General Public License as published by
10
* the Free Software Foundation; either version 2 of the License, or
11
* (at your option) any later version.
13
* This program is distributed in the hope that it will be useful,
14
* but WITHOUT ANY WARRANTY; without even the implied warranty of
15
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16
* GNU General Public License for more details.
18
* You should have received a copy of the GNU General Public License
19
* along with this program; if not, write to the Free Software
20
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
22
* Created by Barry Leslie on 10/02/09.
26
#include "CSHTTPStream.h"
30
#define PUB_KEY_BIT ((uint8_t)1)
31
#define PRIV_KEY_BIT ((uint8_t)2)
32
#define SERVER_BIT ((uint8_t)4)
35
typedef struct S3Range {
38
} S3RangeRec, *S3RangePtr;
40
class CSS3Protocol: public CSRefObject {
43
CSStringBuffer *s3_server;
45
CSString *s3_public_key;
46
CSString *s3_private_key;
48
uint8_t s3_ready; // A flag to indicate if the S3 protocol has been fully initialised.
49
uint32_t s3_maxRetries;
50
uint32_t s3_sleepTime;
52
CSString *s3_getSignature(const char *verb,
54
const char *content_type,
58
CSString *headers = NULL
66
void s3_setServer(const char *server_arg)
68
s3_server->setLength(0);
69
if (server_arg && *server_arg) {
70
s3_ready |= SERVER_BIT;
72
s3_server->append(server_arg);
73
if (server_arg[strlen(server_arg)-1] != '/')
74
s3_server->append("/");
76
s3_ready ^= SERVER_BIT;
79
const char *s3_getServer() { return s3_server->getCString();}
81
void s3_setPublicKey(const char *key_arg)
83
s3_public_key->release();
85
if (key_arg && *key_arg) {
86
s3_ready |= PUB_KEY_BIT;
87
s3_public_key = CSString::newString(key_arg);
89
s3_ready ^= PUB_KEY_BIT;
92
const char *s3_getPublicKey() { return s3_public_key->getCString();}
94
void s3_setPrivateKey(const char *key_arg)
96
s3_private_key->release();
97
s3_private_key = NULL;
98
if (key_arg && *key_arg) {
99
s3_ready |= PRIV_KEY_BIT;
100
s3_private_key = CSString::newString(key_arg);
102
s3_ready ^= PRIV_KEY_BIT;
106
void s3_setMaxRetries(uint32_t retries){s3_maxRetries = retries;}
107
void s3_setSleepTime(uint32_t nap_time){s3_sleepTime = nap_time;}
109
const char *s3_getPrivateKey() { return s3_private_key->getCString();}
111
bool s3_isReady() { return ((s3_ready & SERVER_BIT) && (s3_ready & PUB_KEY_BIT) && (s3_ready & PRIV_KEY_BIT));}
113
// s3_getAuthorization() returns the S3 Authorization sting and the time on which it was based.
114
CSString *s3_getAuthorization(const char *bucket, const char *key, const char *content_type, uint32_t *s3AuthorizationTime);
116
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);
118
// s3_receive() returns false if the object was not found.
119
// If 'output' is NULL then only the headers will be fetched.
120
CSVector *s3_receive(CSOutputStream *output, const char *bucket, const char *key, bool *found, S3RangePtr range = NULL, time_t *last_modified = NULL);
122
// s3_delete() returns false if the object was not found.
123
bool s3_delete(const char *bucket, const char *key);
125
void s3_copy(const char *dest_server, const char *dest_bucket, const char *dest_key, const char *src_bucket, const char *src_key);
127
// s3_list() returns a CSString list if the keys in the bucket with the specified prefix.
128
// The list size returned can be limited with the 'max' parameter. The value 0 indicates no max.
129
CSVector *s3_list(const char *bucket, const char *key_prefix = NULL, uint32_t max = 0);
131
CSString *s3_getDataURL(const char *bucket, const char *key, uint32_t keep_alive);
134
#endif //__CSS3PROTOCOL_H__