Debian Codegraph @

src/tools/davix_op.hpp

raw
1 /*
2 * This File is part of Davix, The IO library for HTTP based protocols
3 * Copyright (C) CERN 2013
4 * Author: Kwong Tat Cheung <[email protected]>
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 DAVIX_OP_HPP
23 #define DAVIX_OP_HPP
24
25 #include <davix.hpp>
26 #include <tools/davix_tool_params.hpp>
27 #include <tools/davix_tool_util.hpp>
28 #include <tools/davix_mutex.hpp>
29
30 namespace Davix{
31
32 class DavixOp{
33
34 protected:
35 std::string _target_url;
36 std::string _destination_url;
37 std::string opType;
38 Tool::OptParams _opts;
39 Context& _c;
40 std::string _scope;
41
42 DavixOp(const Tool::OptParams& opts, std::string target_url, std::string destination_url, Context& c);
43
44 //virtual ~DavixOp();
45
46 public:
47 virtual int executeOp()=0;
48 virtual ~DavixOp();
49 std::string getTargetUrl();
50 std::string getDestinationUrl();
51 std::string getOpType();
52
53 private:
54
55 };
56
57
58 class GetOp : public DavixOp{
59
60 public:
61 GetOp(const Tool::OptParams& opts, std::string target_url, std::string destination_url, Context& c);
62 virtual ~GetOp();
63 virtual int executeOp();
64 int getOutFd();
65
66 private:
67
68 };
69
70
71 class PutOp : public DavixOp{
72
73 public:
74 PutOp(const Tool::OptParams& opts, std::string target_url, std::string destination_url, dav_size_t file_size, Context& c);
75 virtual ~PutOp();
76 virtual int executeOp();
77 int getInFd(DavixError** err);
78
79 private:
80 dav_size_t _file_size;
81
82
83 };
84
85
86 class DeleteOp : public DavixOp{
87
88 public:
89 // for s3 batch delete, need post request and body
90 DeleteOp(const Tool::OptParams& opts, std::string destination_url, Context& c, std::string buf);
91 // for anything else
92 DeleteOp(const Tool::OptParams& opts, std::string destination_url, Context& c);
93 virtual ~DeleteOp();
94 virtual int executeOp();
95 std::string calculateMD5(std::string content, DavixError** err);
96 void parse_deletion_result(int code, const Uri & u, const std::string & scope, const std::vector<char> & body);
97
98 private:
99 std::string _buf;
100
101
102 };
103
104 // forward declaration
105 class DavixTaskQueue;
106
107 // ListOp, used in davix-ls for recursively crawling the namespace
108 class ListOp : public DavixOp{
109
110 public:
111 ListOp(const Tool::OptParams& opts, std::string target_url, Context& c, DavixTaskQueue* listing_tq, FILE* filestream, pthread_mutex_t& output_mutex);
112 virtual ~ListOp();
113 virtual int executeOp();
114
115 private:
116 DavixTaskQueue* _listing_tq;
117 FILE* _filestream;
118 pthread_mutex_t& _output_mutex;
119 static void display_file_entry(const std::string & filename, const Tool::OptParams & opts, FILE* filestream);
120 static void display_long_file_entry(const std::string & filename, struct stat* st, const Tool::OptParams & opts, FILE* filestream);
121 };
122
123
124 // ListppOp, used in davix-get for recursively crawling namespace and getting files
125 // different than ListOp, doesn't print out info of entries, instead, it populates another taskqueue with GetOps
126 class ListppOp : public DavixOp{
127
128 public:
129 ListppOp(const Tool::OptParams& opts, std::string target_url, std::string destination_url, Context& c, DavixTaskQueue* tq, DavixTaskQueue* listing_tq);
130 virtual ~ListppOp();
131 virtual int executeOp();
132
133 private:
134 DavixTaskQueue* _tq;
135 DavixTaskQueue* _listing_tq;
136 };
137
138 }
139
140 #endif // DAVIX_OP_HPP