]>
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 | ||
16 | #ifndef CEPH_RGW_CORS_H | |
17 | #define CEPH_RGW_CORS_H | |
18 | ||
19 | #include <map> | |
20 | #include <string> | |
21 | #include <include/types.h> | |
22 | ||
23 | #define RGW_CORS_GET 0x1 | |
24 | #define RGW_CORS_PUT 0x2 | |
25 | #define RGW_CORS_HEAD 0x4 | |
26 | #define RGW_CORS_POST 0x8 | |
27 | #define RGW_CORS_DELETE 0x10 | |
28 | #define RGW_CORS_COPY 0x20 | |
29 | #define RGW_CORS_ALL (RGW_CORS_GET | \ | |
30 | RGW_CORS_PUT | \ | |
31 | RGW_CORS_HEAD | \ | |
32 | RGW_CORS_POST | \ | |
33 | RGW_CORS_DELETE | \ | |
34 | RGW_CORS_COPY) | |
35 | ||
36 | #define CORS_MAX_AGE_INVALID ((uint32_t)-1) | |
37 | ||
38 | class RGWCORSRule | |
39 | { | |
40 | protected: | |
41 | uint32_t max_age; | |
42 | uint8_t allowed_methods; | |
43 | std::string id; | |
44 | std::set<string> allowed_hdrs; /* If you change this, you need to discard lowercase_allowed_hdrs */ | |
45 | std::set<string> lowercase_allowed_hdrs; /* Not built until needed in RGWCORSRule::is_header_allowed */ | |
46 | std::set<string> allowed_origins; | |
47 | std::list<string> exposable_hdrs; | |
48 | ||
49 | public: | |
50 | RGWCORSRule() : max_age(CORS_MAX_AGE_INVALID),allowed_methods(0) {} | |
51 | RGWCORSRule(std::set<string>& o, std::set<string>& h, | |
52 | std::list<string>& e, uint8_t f, uint32_t a) | |
53 | :max_age(a), | |
54 | allowed_methods(f), | |
55 | allowed_hdrs(h), | |
56 | allowed_origins(o), | |
57 | exposable_hdrs(e) {} | |
58 | virtual ~RGWCORSRule() {} | |
59 | ||
60 | std::string& get_id() { return id; } | |
61 | uint32_t get_max_age() { return max_age; } | |
62 | uint8_t get_allowed_methods() { return allowed_methods; } | |
63 | ||
64 | void encode(bufferlist& bl) const { | |
65 | ENCODE_START(1, 1, bl); | |
11fdf7f2 TL |
66 | encode(max_age, bl); |
67 | encode(allowed_methods, bl); | |
68 | encode(id, bl); | |
69 | encode(allowed_hdrs, bl); | |
70 | encode(allowed_origins, bl); | |
71 | encode(exposable_hdrs, bl); | |
7c673cae FG |
72 | ENCODE_FINISH(bl); |
73 | } | |
11fdf7f2 | 74 | void decode(bufferlist::const_iterator& bl) { |
7c673cae | 75 | DECODE_START(1, bl); |
11fdf7f2 TL |
76 | decode(max_age, bl); |
77 | decode(allowed_methods, bl); | |
78 | decode(id, bl); | |
79 | decode(allowed_hdrs, bl); | |
80 | decode(allowed_origins, bl); | |
81 | decode(exposable_hdrs, bl); | |
7c673cae FG |
82 | DECODE_FINISH(bl); |
83 | } | |
84 | bool has_wildcard_origin(); | |
85 | bool is_origin_present(const char *o); | |
86 | void format_exp_headers(std::string& s); | |
87 | void erase_origin_if_present(std::string& origin, bool *rule_empty); | |
88 | void dump_origins(); | |
89 | void dump(Formatter *f) const; | |
90 | bool is_header_allowed(const char *hdr, size_t len); | |
91 | }; | |
92 | WRITE_CLASS_ENCODER(RGWCORSRule) | |
93 | ||
94 | class RGWCORSConfiguration | |
95 | { | |
96 | protected: | |
97 | std::list<RGWCORSRule> rules; | |
98 | public: | |
99 | RGWCORSConfiguration() {} | |
100 | ~RGWCORSConfiguration() {} | |
101 | ||
102 | void encode(bufferlist& bl) const { | |
103 | ENCODE_START(1, 1, bl); | |
11fdf7f2 | 104 | encode(rules, bl); |
7c673cae FG |
105 | ENCODE_FINISH(bl); |
106 | } | |
11fdf7f2 | 107 | void decode(bufferlist::const_iterator& bl) { |
7c673cae | 108 | DECODE_START(1, bl); |
11fdf7f2 | 109 | decode(rules, bl); |
7c673cae FG |
110 | DECODE_FINISH(bl); |
111 | } | |
112 | void dump(Formatter *f) const; | |
113 | std::list<RGWCORSRule>& get_rules() { | |
114 | return rules; | |
115 | } | |
116 | bool is_empty() { | |
117 | return rules.empty(); | |
118 | } | |
119 | void get_origins_list(const char *origin, std::list<string>& origins); | |
120 | RGWCORSRule * host_name_rule(const char *origin); | |
121 | void erase_host_name_rule(std::string& origin); | |
122 | void dump(); | |
123 | void stack_rule(RGWCORSRule& r) { | |
124 | rules.push_front(r); | |
125 | } | |
126 | }; | |
127 | WRITE_CLASS_ENCODER(RGWCORSConfiguration) | |
128 | ||
129 | static inline int validate_name_string(string& o) { | |
130 | if (o.length() == 0) | |
131 | return -1; | |
132 | if (o.find_first_of("*") != o.find_last_of("*")) | |
133 | return -1; | |
134 | return 0; | |
135 | } | |
136 | #endif /*CEPH_RGW_CORS_H*/ |