~drizzle-trunk/drizzle/development

« back to all changes in this revision

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

  • Committer: Jay Pipes
  • Date: 2009-09-15 21:01:42 UTC
  • mto: (1126.2.5 merge)
  • mto: This revision was merged to the branch mainline in revision 1128.
  • Revision ID: jpipes@serialcoder-20090915210142-x8mwiqn1q0vzjspp
Moves Alter_info out into its own header and source file, cleans up some related include mess in sql_lex.h, and renames Alter_info to AlterInfo.

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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20
 
 *
21
 
 *  Created by Barry Leslie on 10/02/09.
22
 
 *
23
 
 */
24
 
 
25
 
#include "CSHTTPStream.h"
26
 
#include "CSMd5.h"
27
 
class S3ProtocolCon;
28
 
 
29
 
#define PUB_KEY_BIT             ((uint8_t)1)
30
 
#define PRIV_KEY_BIT    ((uint8_t)2)
31
 
#define SERVER_BIT              ((uint8_t)4)
32
 
 
33
 
 
34
 
typedef struct S3Range {
35
 
         off64_t startByte;
36
 
         off64_t endByte;
37
 
} S3RangeRec, *S3RangePtr;
38
 
 
39
 
class CSS3Protocol: public CSRefObject {
40
 
        private:
41
 
        
42
 
        CSStringBuffer *s3_server;
43
 
        
44
 
        CSString *s3_public_key;
45
 
        CSString *s3_private_key;
46
 
        
47
 
        uint8_t s3_ready; // A flag to indicate if the S3 protocol has been fully initialised.
48
 
        uint32_t s3_maxRetries; 
49
 
        uint32_t s3_sleepTime; 
50
 
        
51
 
        CSString *s3_getSignature(const char *verb, 
52
 
                                                                const char *md5, 
53
 
                                                                const char *content_type, 
54
 
                                                                const char *date, 
55
 
                                                                const char *bucket, 
56
 
                                                                const char *key,
57
 
                                                                CSString *headers = NULL 
58
 
                                                        );
59
 
                                                        
60
 
        public:
61
 
        CSS3Protocol();
62
 
                
63
 
        ~CSS3Protocol();
64
 
        
65
 
        void s3_setServer(const char *server_arg)
66
 
        {
67
 
                s3_server->setLength(0);
68
 
                if (server_arg && *server_arg) {
69
 
                        s3_ready |= SERVER_BIT;
70
 
                        
71
 
                        s3_server->append(server_arg);
72
 
                        if (server_arg[strlen(server_arg)-1] != '/')
73
 
                                s3_server->append("/");
74
 
                } else {
75
 
                        s3_ready ^= SERVER_BIT;
76
 
                }
77
 
        }
78
 
        const char *s3_getServer() { return s3_server->getCString();}
79
 
        
80
 
        void s3_setPublicKey(const char *key_arg) 
81
 
        {
82
 
                s3_public_key->release();
83
 
                s3_public_key = NULL;
84
 
                if (key_arg && *key_arg) {
85
 
                        s3_ready |= PUB_KEY_BIT;                                        
86
 
                        s3_public_key = CSString::newString(key_arg);
87
 
                } else {
88
 
                        s3_ready ^= PUB_KEY_BIT;
89
 
                }
90
 
        }
91
 
        const char *s3_getPublicKey() { return s3_public_key->getCString();}
92
 
        
93
 
        void s3_setPrivateKey(const char *key_arg)
94
 
        {
95
 
                s3_private_key->release();
96
 
                s3_private_key = NULL;
97
 
                if (key_arg && *key_arg) {
98
 
                        s3_ready |= PRIV_KEY_BIT;                                       
99
 
                        s3_private_key = CSString::newString(key_arg);
100
 
                } else {
101
 
                        s3_ready ^= PRIV_KEY_BIT;
102
 
                }
103
 
        }
104
 
 
105
 
        void s3_setMaxRetries(uint32_t retries){s3_maxRetries = retries;}
106
 
        void s3_setSleepTime(uint32_t nap_time){s3_sleepTime = nap_time;}
107
 
        
108
 
        const char *s3_getPrivateKey() { return s3_private_key->getCString();}
109
 
        
110
 
        bool s3_isReady() { return ((s3_ready & SERVER_BIT) && (s3_ready & PUB_KEY_BIT) && (s3_ready & PRIV_KEY_BIT));}
111
 
        
112
 
        // s3_getAuthorization() returns the S3 Authorization sting and the time on which it was based.
113
 
        CSString *s3_getAuthorization(const char *bucket, const char *key, const char *content_type, uint32_t *s3AuthorizationTime);
114
 
        
115
 
        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);
116
 
 
117
 
        // s3_receive() returns false if the object was not found.
118
 
        // If 'output' is NULL then only the headers will be fetched.
119
 
        CSVector *s3_receive(CSOutputStream *output, const char *bucket, const char *key, bool *found, S3RangePtr range = NULL, time_t *last_modified = NULL);
120
 
 
121
 
        // s3_delete() returns false if the object was not found.
122
 
        bool s3_delete(const char *bucket, const char *key);
123
 
        
124
 
        void s3_copy(const char *dest_server, const char *dest_bucket, const char *dest_key, const char *src_bucket, const char *src_key);
125
 
        
126
 
        // s3_list() returns a CSString list if the keys in the bucket with the specified prefix.
127
 
        // The list size returned can be limited with the 'max' parameter. The value 0 indicates no max.
128
 
        CSVector *s3_list(const char *bucket, const char *key_prefix = NULL, uint32_t max = 0);
129
 
 
130
 
        CSString *s3_getDataURL(const char *bucket, const char *key, uint32_t keep_alive);
131
 
};
132
 
 
133
 
#endif //__CSS3PROTOCOL_H__