Debian Codegraph @

src/fileops/httpiovec.hpp

raw
1 /*
2 * This File is part of Davix, The IO library for HTTP based protocols
3 * Copyright (C) CERN 2013
4 * Author: Adrien Devresse <[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 HTTPIOVEC_HPP
23 #define HTTPIOVEC_HPP
24
25 #include <davix.hpp>
26 #include <fileops/iobuffmap.hpp>
27 #include <fileops/httpiochain.hpp>
28 #include "libs/IntervalTree.h"
29
30 namespace Davix{
31
32 // simple chunk info handler
33 struct ChunkInfo {
34 ChunkInfo() :
35 offset(0),
36 size(0),
37 bounded(false){}
38 dav_off_t offset;
39 dav_size_t size;
40 bool bounded;
41 };
42
43 struct ElemChunk{
44 ElemChunk(const DavIOVecInput* in, DavIOVecOuput* ou) :
45 _in(in),
46 _ou(ou),
47 _cursor((char*) in->diov_buffer){
48 _ou->diov_size=0; // reset elem read status
49 _ou->diov_buffer = _in->diov_buffer;
50 }
51
52 const DavIOVecInput *_in;
53 DavIOVecOuput * _ou;
54 char *_cursor;
55
56 };
57
58 typedef std::multimap<dav_off_t, ElemChunk> MapChunk;
59 typedef std::vector<std::pair<dav_off_t, dav_size_t> > SortedRanges;
60
61 struct MultirangeResult {
62 enum OperationResult { SUCCESS, NOMULTIRANGE, SUCCESS_BUT_NO_MULTIRANGE };
63 OperationResult res;
64 dav_ssize_t size_bytes;
65
66 MultirangeResult(OperationResult _res, dav_ssize_t _size_bytes)
67 : res(_res), size_bytes(_size_bytes) {}
68 };
69
70 ////
71 /// \brief The HttpIOVecOps class
72 ///
73 /// the HttpIOVecOps io vec chain element handle all operations relative to Vector requests
74 class HttpIOVecOps : public HttpIOChain
75 {
76 public:
77 HttpIOVecOps(){}
78 virtual ~HttpIOVecOps(){}
79
80 dav_ssize_t preadVec(IOChainContext & iocontext, const DavIOVecInput * input_vec,
81 DavIOVecOuput * output_vec,
82 const dav_size_t count_vec);
83
84 // these two should have been private, but because of pthread we need to call them from
85 // a function
86 dav_ssize_t singleRangeRequest(IOChainContext & iocontext,
87 const DavIOVecInput * input,
88 DavIOVecOuput * output);
89
90 dav_ssize_t singleRangeRequest(IOChainContext & iocontext,
91 const IntervalTree<ElemChunk> & tree,
92 dav_off_t offset, dav_size_t size);
93
94 private:
95
96 MultirangeResult performMultirange(IOChainContext & iocontext,
97 const IntervalTree<ElemChunk> &tree,
98 const SortedRanges & ranges);
99
100 dav_ssize_t simulateMultirange(IOChainContext & iocontext,
101 const IntervalTree<ElemChunk> & tree,
102 const SortedRanges & ranges,
103 uint nconnections);
104
105 dav_ssize_t parseMultipartRequest(HttpRequest & req,
106 const IntervalTree<ElemChunk> & tree,
107 DavixError** tmp_err);
108
109 dav_ssize_t simulateMultiPartRequest(HttpRequest & _req,
110 const IntervalTree<ElemChunk> & tree,
111 DavixError** err);
112 };
113
114
115 int find_header_params(char* buffer, dav_size_t buffer_len, dav_size_t* part_size, dav_off_t* part_offset);
116
117 int http_extract_boundary_from_content_type(const std::string & buffer, std::string & boundary, DavixError** err);
118
119
120 int parse_multi_part_header(HttpRequest& req, const std::string & boundary, ChunkInfo & info,
121 int & n_try, DavixError** err);
122
123 void HttpIoVecSetupErrorMultiPart(DavixError** err);
124
125 } // Davix
126
127 #endif // HTTPIOVEC_HPP