Debian Codegraph @

src/utils/davix_utils_internal.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 #pragma once
23 #ifndef DAVIX_UTILS_INTERNAL_HPP
24 #define DAVIX_UTILS_INTERNAL_HPP
25
26 #include <set>
27 #include <utils/davix_uri.hpp>
28 #include <params/davixrequestparams.hpp>
29
30 namespace Davix {
31
32 inline bool isS3SignedURL(const Davix::Uri &url) {
33 if(url.queryParamExists("AWSAccessKeyId") && url.queryParamExists("Signature")) {
34 return true;
35 }
36
37 if(url.queryParamExists("X-Amz-Credential") && url.queryParamExists("X-Amz-Signature")) {
38 return true;
39 }
40
41 return false;
42 }
43
44 inline std::string extractCanonicalizedResourceQueryParams(const Davix::Uri &url) {
45 std::set<std::string> targetParams;
46
47 targetParams.insert("acl");
48 targetParams.insert("lifecycle");
49 targetParams.insert("location");
50 targetParams.insert("logging");
51 targetParams.insert("notification");
52 targetParams.insert("partNumber");
53 targetParams.insert("policy");
54 targetParams.insert("requestPayment");
55 targetParams.insert("uploadId");
56 targetParams.insert("uploads");
57 targetParams.insert("versionId");
58 targetParams.insert("versioning");
59 targetParams.insert("versions");
60 targetParams.insert("website");
61
62 targetParams.insert("delete"); // ?
63
64 ParamVec canonicalizedParams;
65
66 const ParamVec &params = url.getQueryVec();
67 for(ParamVec::const_iterator it = params.begin(); it != params.end(); it++) {
68 if(targetParams.count(it->first) != 0u) {
69 canonicalizedParams.push_back(*it);
70 }
71 }
72
73 std::sort(canonicalizedParams.begin(), canonicalizedParams.end());
74
75 if(canonicalizedParams.empty()) {
76 return "";
77 }
78
79 std::ostringstream ss;
80 ss << "?";
81
82 for(ParamVec::const_iterator it = canonicalizedParams.begin(); it != canonicalizedParams.end(); it++) {
83 ss << it->first;
84 if(!it->second.empty()) {
85 ss << "=" << it->second;
86 }
87
88 if(it+1 != canonicalizedParams.end()) {
89 ss << "&";
90 }
91 }
92
93 return ss.str();
94 }
95
96 }
97
98 #endif // DAVIX_UTILS_INTERNAL_HPP