]> git.proxmox.com Git - ceph.git/blob - ceph/src/rgw/rgw_cors_swift.h
import ceph quincy 17.2.6
[ceph.git] / ceph / src / rgw / rgw_cors_swift.h
1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2 // vim: ts=8 sw=2 smarttab ft=cpp
3
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
16 #ifndef CEPH_RGW_CORS_SWIFT3_H
17 #define CEPH_RGW_CORS_SWIFT3_H
18
19 #include <map>
20 #include <string>
21 #include <vector>
22 #include <include/types.h>
23 #include <include/str_list.h>
24
25 #include "rgw_cors.h"
26
27 class RGWCORSConfiguration_SWIFT : public RGWCORSConfiguration
28 {
29 public:
30 RGWCORSConfiguration_SWIFT() {}
31 ~RGWCORSConfiguration_SWIFT() {}
32 int create_update(const char *allow_origins, const char *allow_headers,
33 const char *expose_headers, const char *max_age) {
34 std::set<std::string> o, h;
35 std::list<std::string> e;
36 unsigned long a = CORS_MAX_AGE_INVALID;
37 uint8_t flags = RGW_CORS_ALL;
38
39 int nr_invalid_names = 0;
40 auto add_host = [&nr_invalid_names, &o] (auto host) {
41 if (validate_name_string(host) == 0) {
42 o.emplace(std::string{host});
43 } else {
44 nr_invalid_names++;
45 }
46 };
47 for_each_substr(allow_origins, ";,= \t", add_host);
48 if (o.empty() || nr_invalid_names > 0) {
49 return -EINVAL;
50 }
51
52 if (allow_headers) {
53 int nr_invalid_headers = 0;
54 auto add_header = [&nr_invalid_headers, &h] (auto allow_header) {
55 if (validate_name_string(allow_header) == 0) {
56 h.emplace(std::string{allow_header});
57 } else {
58 nr_invalid_headers++;
59 }
60 };
61 for_each_substr(allow_headers, ";,= \t", add_header);
62 if (h.empty() || nr_invalid_headers > 0) {
63 return -EINVAL;
64 }
65 }
66
67 if (expose_headers) {
68 for_each_substr(expose_headers, ";,= \t",
69 [&e] (auto expose_header) {
70 e.emplace_back(std::string(expose_header));
71 });
72 }
73 if (max_age) {
74 char *end = NULL;
75 a = strtoul(max_age, &end, 10);
76 if (a == ULONG_MAX)
77 a = CORS_MAX_AGE_INVALID;
78 }
79
80 RGWCORSRule rule(o, h, e, flags, a);
81 stack_rule(rule);
82 return 0;
83 }
84 };
85 #endif /*CEPH_RGW_CORS_SWIFT3_H*/