1 /*
2  * This File is part of Davix, The IO library for HTTP based protocols
3  * Copyright (C) CERN 2018
4  * Author: Georgios Bitzes <georgios.bitzes@cern.ch>
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
19  *
20 */
21 
22 #ifndef S3_IO_HPP
23 #define S3_IO_HPP
24 
25 #include <fileops/httpiochain.hpp>
26 
27 namespace Davix{
28 
29 struct DynafedUris {
30   std::vector<std::string> chunks;
31   std::string post;
32 };
33 
34 class S3IO : public HttpIOChain {
35 public:
36   S3IO();
37   ~S3IO();
38 
39   // write the entire content from a file descriptor
40   virtual dav_ssize_t writeFromFd(IOChainContext & iocontext, int fd, dav_size_t size);
41 
42   // wirte the entire content from a defined callback
43   virtual dav_ssize_t writeFromCb(IOChainContext & iocontext, const DataProviderFun & func, dav_size_t size);
44 
45   void performUgrS3MultiPart(IOChainContext & iocontext, const std::string &posturl, const std::string &pluginId, const DataProviderFun &func, dav_size_t size, DavixError **err);
46 
47 private:
48 
49   // Returns uploadId
50   std::string initiateMultipart(IOChainContext & iocontext);
51   std::string initiateMultipart(IOChainContext & iocontext, const Uri &url);
52 
53   DynafedUris retrieveDynafedUris(IOChainContext & iocontext, const std::string &uploadId, const std::string &pluginId, size_t nchunks);
54 
55   // Given the upload id, write the given chunk. Return object ETag,
56   // necessary to commit upload.
57   std::string writeChunk(IOChainContext & iocontext, const char* buff, dav_size_t size, const std::string &uploadId, int partNumber);
58   std::string writeChunk(IOChainContext & iocontext, const char* buff, dav_size_t size, const Uri &uri, int partNumber);
59 
60 
61   // Given upload id and last chunk, commit chunks
62   void commitChunks(IOChainContext & iocontext,  const std::string &uploadId, const std::vector<std::string> &etags);
63   void commitChunks(IOChainContext & iocontext,  const Uri &uri, const std::vector<std::string> &etags);
64 };
65 
66 }
67 
68 #endif
69