~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to plugin/pbms/src/cslib/CSS3Protocol.h

  • Committer: Brian Aker
  • Date: 2010-07-09 20:51:34 UTC
  • mfrom: (1643.4.3 drizzle)
  • Revision ID: brian@gaz-20100709205134-ru4s0889youfrmm5
Merge of Patrick

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#ifndef __CSS3PROTOCOL_H__
 
2
#define __CSS3PROTOCOL_H__
 
3
/* Copyright (c) 2009 PrimeBase Technologies GmbH, Germany
 
4
 *
 
5
 * PrimeBase Media Stream for MySQL
 
6
 *
 
7
 * This program is free software; you can redistribute it and/or modify
 
8
 * it under the terms of the GNU General Public License as published by
 
9
 * the Free Software Foundation; either version 2 of the License, or
 
10
 * (at your option) any later version.
 
11
 *
 
12
 * This program is distributed in the hope that it will be useful,
 
13
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
14
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
15
 * GNU General Public License for more details.
 
16
 *
 
17
 * You should have received a copy of the GNU General Public License
 
18
 * along with this program; if not, write to the Free Software
 
19
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
 
20
 *
 
21
 *  Created by Barry Leslie on 10/02/09.
 
22
 *
 
23
 */
 
24
 
 
25
#include "CSHTTPStream.h"
 
26
class S3ProtocolCon;
 
27
 
 
28
#define PUB_KEY_BIT             ((uint8_t)1)
 
29
#define PRIV_KEY_BIT    ((uint8_t)2)
 
30
#define SERVER_BIT              ((uint8_t)4)
 
31
 
 
32
 
 
33
class CSS3Protocol: public CSRefObject {
 
34
        private:
 
35
        
 
36
        CSStringBuffer *s3_server;
 
37
        
 
38
        CSString *s3_public_key;
 
39
        CSString *s3_private_key;
 
40
        
 
41
        uint8_t s3_ready; // A flag to indicate if the S3 protocol has been fully initialised.
 
42
        uint32_t s3_maxRetrys; 
 
43
        
 
44
        CSString *s3_getSignature(const char *verb, 
 
45
                                                                const char *md5, 
 
46
                                                                const char *content_type, 
 
47
                                                                const char *date, 
 
48
                                                                const char *bucket, 
 
49
                                                                const char *key,
 
50
                                                                CSString *headers = NULL 
 
51
                                                        );
 
52
                                                        
 
53
        public:
 
54
        CSS3Protocol();
 
55
                
 
56
        ~CSS3Protocol();
 
57
        
 
58
        void s3_setServer(const char *server_arg)
 
59
        {
 
60
                s3_server->setLength(0);
 
61
                if (server_arg && *server_arg) {
 
62
                        s3_ready |= SERVER_BIT;
 
63
                        
 
64
                        s3_server->append(server_arg);
 
65
                        if (server_arg[strlen(server_arg)-1] != '/')
 
66
                                s3_server->append("/");
 
67
                } else {
 
68
                        s3_ready ^= SERVER_BIT;
 
69
                }
 
70
        }
 
71
        const char *s3_getServer() { return s3_server->getCString();}
 
72
        
 
73
        void s3_setPublicKey(const char *key_arg) 
 
74
        {
 
75
                s3_public_key->release();
 
76
                s3_public_key = NULL;
 
77
                if (key_arg && *key_arg) {
 
78
                        s3_ready |= PUB_KEY_BIT;                                        
 
79
                        s3_public_key = CSString::newString(key_arg);
 
80
                } else {
 
81
                        s3_ready ^= PUB_KEY_BIT;
 
82
                }
 
83
        }
 
84
        const char *s3_getPublicKey() { return s3_public_key->getCString();}
 
85
        
 
86
        void s3_setPrivateKey(const char *key_arg)
 
87
        {
 
88
                s3_private_key->release();
 
89
                s3_private_key = NULL;
 
90
                if (key_arg && *key_arg) {
 
91
                        s3_ready |= PRIV_KEY_BIT;                                       
 
92
                        s3_private_key = CSString::newString(key_arg);
 
93
                } else {
 
94
                        s3_ready ^= PRIV_KEY_BIT;
 
95
                }
 
96
        }
 
97
 
 
98
        const char *s3_getPrivateKey() { return s3_private_key->getCString();}
 
99
        
 
100
        bool s3_isReady() { return ((s3_ready & SERVER_BIT) && (s3_ready & PUB_KEY_BIT) && (s3_ready & PRIV_KEY_BIT));}
 
101
        
 
102
        // s3_getAuthorization() returns the S3 Authorization sting and the time on which it was based.
 
103
        CSString *s3_getAuthorization(const char *bucket, const char *key, const char *content_type, uint32_t *s3AuthorizationTime);
 
104
        
 
105
        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);
 
106
 
 
107
        // s3_receive() returns false if the object was not found.
 
108
        CSVector *s3_receive(CSOutputStream *output, const char *bucket, const char *key, bool *found);
 
109
 
 
110
        // s3_delete() returns false if the object was not found.
 
111
        bool s3_delete(const char *bucket, const char *key);
 
112
        
 
113
        void s3_copy(const char *dest_server, const char *dest_bucket, const char *dest_key, const char *src_bucket, const char *src_key);
 
114
        
 
115
        // s3_list() returns a CSString list if the keys in the bucket with the specified prefix.
 
116
        // The list size returned can be limited with the 'max' parameter. The value 0 indicates no max.
 
117
        CSVector *s3_list(const char *bucket, const char *key_prefix = NULL, uint32_t max = 0);
 
118
 
 
119
        CSString *s3_getDataURL(const char *bucket, const char *key, uint32_t keep_alive);
 
120
};
 
121
 
 
122
#endif //__CSS3PROTOCOL_H__