1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2 // vim: ts=8 sw=2 smarttab
4 * Ceph - scalable distributed file system
6 * Copyright (C) 2013 eNovance SAS <licensing@enovance.com>
8 * This is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License version 2.1, as published by the Free Software
11 * Foundation. See file COPYING.
15 #ifndef CEPH_RGW_CORS_H
16 #define CEPH_RGW_CORS_H
20 #include <include/types.h>
22 #define RGW_CORS_GET 0x1
23 #define RGW_CORS_PUT 0x2
24 #define RGW_CORS_HEAD 0x4
25 #define RGW_CORS_POST 0x8
26 #define RGW_CORS_DELETE 0x10
27 #define RGW_CORS_COPY 0x20
28 #define RGW_CORS_ALL (RGW_CORS_GET | \
35 #define CORS_MAX_AGE_INVALID ((uint32_t)-1)
41 uint8_t allowed_methods;
43 std::set<string> allowed_hdrs; /* If you change this, you need to discard lowercase_allowed_hdrs */
44 std::set<string> lowercase_allowed_hdrs; /* Not built until needed in RGWCORSRule::is_header_allowed */
45 std::set<string> allowed_origins;
46 std::list<string> exposable_hdrs;
49 RGWCORSRule() : max_age(CORS_MAX_AGE_INVALID),allowed_methods(0) {}
50 RGWCORSRule(std::set<string>& o, std::set<string>& h,
51 std::list<string>& e, uint8_t f, uint32_t a)
57 virtual ~RGWCORSRule() {}
59 std::string& get_id() { return id; }
60 uint32_t get_max_age() { return max_age; }
61 uint8_t get_allowed_methods() { return allowed_methods; }
63 void encode(bufferlist& bl) const {
64 ENCODE_START(1, 1, bl);
65 ::encode(max_age, bl);
66 ::encode(allowed_methods, bl);
68 ::encode(allowed_hdrs, bl);
69 ::encode(allowed_origins, bl);
70 ::encode(exposable_hdrs, bl);
73 void decode(bufferlist::iterator& bl) {
75 ::decode(max_age, bl);
76 ::decode(allowed_methods, bl);
78 ::decode(allowed_hdrs, bl);
79 ::decode(allowed_origins, bl);
80 ::decode(exposable_hdrs, bl);
83 bool has_wildcard_origin();
84 bool is_origin_present(const char *o);
85 void format_exp_headers(std::string& s);
86 void erase_origin_if_present(std::string& origin, bool *rule_empty);
88 void dump(Formatter *f) const;
89 bool is_header_allowed(const char *hdr, size_t len);
91 WRITE_CLASS_ENCODER(RGWCORSRule)
93 class RGWCORSConfiguration
96 std::list<RGWCORSRule> rules;
98 RGWCORSConfiguration() {}
99 ~RGWCORSConfiguration() {}
101 void encode(bufferlist& bl) const {
102 ENCODE_START(1, 1, bl);
106 void decode(bufferlist::iterator& bl) {
111 void dump(Formatter *f) const;
112 std::list<RGWCORSRule>& get_rules() {
116 return rules.empty();
118 void get_origins_list(const char *origin, std::list<string>& origins);
119 RGWCORSRule * host_name_rule(const char *origin);
120 void erase_host_name_rule(std::string& origin);
122 void stack_rule(RGWCORSRule& r) {
126 WRITE_CLASS_ENCODER(RGWCORSConfiguration)
128 static inline int validate_name_string(string& o) {
131 if (o.find_first_of("*") != o.find_last_of("*"))
135 #endif /*CEPH_RGW_CORS_H*/