Fix some bugs when testing opensds ansible
[stor4nfv.git] / src / 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
3 /*
4  * Ceph - scalable distributed file system
5  *
6  * Copyright (C) 2013 eNovance SAS <licensing@enovance.com>
7  *
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.
12  *
13  */
14
15 #ifndef CEPH_RGW_CORS_SWIFT3_H
16 #define CEPH_RGW_CORS_SWIFT3_H
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
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) {
33       set<string> o, h, oc;
34       list<string> e;
35       unsigned long a = CORS_MAX_AGE_INVALID;
36       uint8_t flags = RGW_CORS_ALL;
37
38       string ao = allow_origins;
39       get_str_set(ao, oc);
40       if (oc.empty())
41         return -EINVAL;
42       for(set<string>::iterator it = oc.begin(); it != oc.end(); ++it) {
43         string host = *it;
44         if (validate_name_string(host) != 0)
45           return -EINVAL;
46         o.insert(o.end(), host);
47       }
48       if (allow_headers) {
49         string ah = allow_headers;
50         get_str_set(ah, h);
51         for(set<string>::iterator it = h.begin();
52             it != h.end(); ++it) {
53           string s = (*it);
54           if (validate_name_string(s) != 0)
55             return -EINVAL;
56         }
57       }
58
59       if (expose_headers) {
60         string eh = expose_headers;
61         get_str_list(eh, e);
62       }
63       if (max_age) {
64         char *end = NULL;
65         a = strtoul(max_age, &end, 10);
66         if (a == ULONG_MAX)
67           a = CORS_MAX_AGE_INVALID;
68       }
69
70       RGWCORSRule rule(o, h, e, flags, a);
71       stack_rule(rule);
72       return 0;
73     }
74 };
75 #endif /*CEPH_RGW_CORS_SWIFT3_H*/