]>
Commit | Line | Data |
---|---|---|
7c673cae | 1 | // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- |
9f95a23c | 2 | // vim: ts=8 sw=2 smarttab ft=cpp |
11fdf7f2 | 3 | |
7c673cae FG |
4 | /* |
5 | * Ceph - scalable distributed file system | |
6 | * | |
7 | * Copyright (C) 2013 eNovance SAS <licensing@enovance.com> | |
8 | * | |
9 | * This is free software; you can redistribute it and/or | |
10 | * modify it under the terms of the GNU Lesser General Public | |
11 | * License version 2.1, as published by the Free Software | |
12 | * Foundation. See file COPYING. | |
13 | * | |
14 | */ | |
15 | ||
1e59de90 | 16 | #pragma once |
7c673cae FG |
17 | |
18 | #include <map> | |
19 | #include <string> | |
20 | #include <vector> | |
21 | #include <include/types.h> | |
22 | #include <include/str_list.h> | |
23 | ||
24 | #include "rgw_cors.h" | |
25 | ||
7c673cae FG |
26 | class RGWCORSConfiguration_SWIFT : public RGWCORSConfiguration |
27 | { | |
28 | public: | |
29 | RGWCORSConfiguration_SWIFT() {} | |
30 | ~RGWCORSConfiguration_SWIFT() {} | |
31 | int create_update(const char *allow_origins, const char *allow_headers, | |
32 | const char *expose_headers, const char *max_age) { | |
20effc67 TL |
33 | std::set<std::string> o, h; |
34 | std::list<std::string> e; | |
7c673cae FG |
35 | unsigned long a = CORS_MAX_AGE_INVALID; |
36 | uint8_t flags = RGW_CORS_ALL; | |
37 | ||
f67539c2 TL |
38 | int nr_invalid_names = 0; |
39 | auto add_host = [&nr_invalid_names, &o] (auto host) { | |
40 | if (validate_name_string(host) == 0) { | |
41 | o.emplace(std::string{host}); | |
42 | } else { | |
43 | nr_invalid_names++; | |
44 | } | |
45 | }; | |
46 | for_each_substr(allow_origins, ";,= \t", add_host); | |
47 | if (o.empty() || nr_invalid_names > 0) { | |
7c673cae | 48 | return -EINVAL; |
7c673cae | 49 | } |
f67539c2 | 50 | |
7c673cae | 51 | if (allow_headers) { |
f67539c2 TL |
52 | int nr_invalid_headers = 0; |
53 | auto add_header = [&nr_invalid_headers, &h] (auto allow_header) { | |
54 | if (validate_name_string(allow_header) == 0) { | |
55 | h.emplace(std::string{allow_header}); | |
56 | } else { | |
57 | nr_invalid_headers++; | |
58 | } | |
59 | }; | |
60 | for_each_substr(allow_headers, ";,= \t", add_header); | |
61 | if (h.empty() || nr_invalid_headers > 0) { | |
62 | return -EINVAL; | |
7c673cae FG |
63 | } |
64 | } | |
65 | ||
66 | if (expose_headers) { | |
f67539c2 TL |
67 | for_each_substr(expose_headers, ";,= \t", |
68 | [&e] (auto expose_header) { | |
69 | e.emplace_back(std::string(expose_header)); | |
70 | }); | |
7c673cae FG |
71 | } |
72 | if (max_age) { | |
73 | char *end = NULL; | |
74 | a = strtoul(max_age, &end, 10); | |
75 | if (a == ULONG_MAX) | |
76 | a = CORS_MAX_AGE_INVALID; | |
77 | } | |
78 | ||
79 | RGWCORSRule rule(o, h, e, flags, a); | |
80 | stack_rule(rule); | |
81 | return 0; | |
82 | } | |
83 | }; |