Debian Codegraph @

src/neon/neonrequest.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 DAVIX_NEONREQUEST_H
23 #define DAVIX_NEONREQUEST_H
24
25 #include <vector>
26 #include <utility>
27 #include <memory>
28 #include <string>
29
30 #include <davix_internal.hpp>
31
32 #include <ne_request.h>
33 #include <ne_auth.h>
34 #include <neon/neonsessionfactory.hpp>
35
36 #include <neon/neonsession.hpp>
37 #include <backend/BoundHooks.hpp>
38 #include <status/DavixStatus.hpp>
39
40 #include "../backend/BackendRequest.hpp"
41
42 namespace Davix {
43
44 #define NEON_BUFFER_SIZE 65000
45 #define NEON_REDIRECT_LIMIT 5
46
47 class NEONSessionFactory;
48 class NEONSession;
49 class NEONSessionWrapper;
50 class StandaloneRequest;
51
52 class NeonRequest : public BackendRequest
53 {
54 public:
55 NeonRequest(const BoundHooks &hooks, Context& f, const Uri & uri_req);
56 virtual ~NeonRequest();
57
58 //--------------------------------------------------------------------------
59 // Execute request synchronously, and store result in internal buffer.
60 //--------------------------------------------------------------------------
61 virtual int executeRequest(DavixError** err);
62
63 //--------------------------------------------------------------------------
64 // Major read member - implementations need to override.
65 // Read a block of max_size bytes (at max) into buffer.
66 //--------------------------------------------------------------------------
67 virtual dav_ssize_t readBlock(char* buffer, dav_size_t max_size,DavixError** err);
68
69 //--------------------------------------------------------------------------
70 // Start request.
71 //--------------------------------------------------------------------------
72 virtual int beginRequest(DavixError** err);
73
74 //--------------------------------------------------------------------------
75 // Finish an already started request.
76 //--------------------------------------------------------------------------
77 virtual int endRequest(DavixError** err);
78
79 //--------------------------------------------------------------------------
80 // Get response status.
81 //--------------------------------------------------------------------------
82 virtual int getRequestCode();
83
84 //--------------------------------------------------------------------------
85 // Get a specific response header
86 //--------------------------------------------------------------------------
87 virtual bool getAnswerHeader(const std::string &header_name, std::string &value) const;
88
89 //--------------------------------------------------------------------------
90 // Get all response headers
91 //--------------------------------------------------------------------------
92 virtual size_t getAnswerHeaders(std::vector<std::pair<std::string, std::string > > & vec_headers) const;
93
94 private:
95 //--------------------------------------------------------------------------
96 // Initialize and configure _neon_req
97 //--------------------------------------------------------------------------
98 void createBackendRequest();
99
100 //--------------------------------------------------------------------------
101 // Check redirect cache
102 //--------------------------------------------------------------------------
103 void checkRedirectCache();
104
105 //--------------------------------------------------------------------------
106 // Prepare URI & params
107 //--------------------------------------------------------------------------
108 void prepareUriParams();
109
110 //--------------------------------------------------------------------------
111 // Initialize standalone request
112 //--------------------------------------------------------------------------
113 void initStandaloneRequest();
114
115 // neon standalone request
116 std::unique_ptr<StandaloneRequest> _standalone_req;
117
118 // bound hooks
119 BoundHooks _bound_hooks;
120
121 // req info
122 int _number_try;
123 // number of redirects so far
124 int _redirects;
125 // read info
126 dav_ssize_t _total_read_size, _last_read;
127
128 bool _headers_configured;
129 int _accepted_202_retries;
130
131 ////////////////////////////////////////////
132 // Private Members
133 int startRequest(DavixError** err);
134
135 int processRedirection(DavixError** err); // analyze and process redirection if needed
136
137 void configureHeaders();
138 void cancelSessionReuse();
139
140 // negociate the request : authentication, redirection, name resolution
141 int negotiateRequest(DavixError** err);
142
143 // redirection logic
144 int redirectRequest(DavixError** err);
145
146 // redirecttion caching cleaning function
147 bool requestCleanup();
148
149 void freeRequest();
150
151 void createError(int ne_status, DavixError** err);
152 friend class NEONSessionWrapper;
153 };
154
155
156 //
157 // translate a neon error code to a davix one
158 //
159 void neon_simple_req_code_to_davix_code(int ne_status, ne_session* sess, const std::string & scope, DavixError** err);
160
161 void configureRequestParamsProto(const Uri &uri, RequestParams &params);
162
163
164 } // namespace Davix
165
166 #endif // DAVIX_NEONREQUEST_H