summaryrefslogtreecommitdiff
path: root/src/rgw/rgw_env.cc
blob: b8f6b0440cc7e9e34741f39dda8b4e72201d0e5b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
#include "rgw_common.h"
#include "rgw_log.h"

#include <string>
#include <map>

#define dout_subsys ceph_subsys_rgw

RGWEnv::RGWEnv()
{
  conf = new RGWConf;
}

RGWEnv::~RGWEnv()
{
  delete conf;
}

void RGWEnv::init(CephContext *cct, char **envp)
{
  const char *p;

  env_map.clear();

  for (int i=0; (p = envp[i]); ++i) {
    string s(p);
    int pos = s.find('=');
    if (pos <= 0) // should never be 0
      continue;
    string name = s.substr(0, pos);
    string val = s.substr(pos + 1);
    env_map[name] = val;
  }

  conf->init(cct, this);
}

const char *RGWEnv::get(const char *name, const char *def_val)
{
  map<string, string>::iterator iter = env_map.find(name);
  if (iter == env_map.end())
    return def_val;

  return iter->second.c_str();
}

int RGWEnv::get_int(const char *name, int def_val)
{
  map<string, string>::iterator iter = env_map.find(name);
  if (iter == env_map.end())
    return def_val;

  const char *s = iter->second.c_str();
  return atoi(s);  
}

bool RGWEnv::get_bool(const char *name, bool def_val)
{
  map<string, string>::iterator iter = env_map.find(name);
  if (iter == env_map.end())
    return def_val;

  const char *s = iter->second.c_str();
  return rgw_str_to_bool(s, def_val);
}

size_t RGWEnv::get_size(const char *name, size_t def_val)
{
  map<string, string>::iterator iter = env_map.find(name);
  if (iter == env_map.end())
    return def_val;

  const char *s = iter->second.c_str();
  return atoll(s);  
}

void RGWConf::init(CephContext *cct, RGWEnv *env)
{
  enable_ops_log = cct->_conf->rgw_enable_ops_log;
  enable_usage_log = cct->_conf->rgw_enable_usage_log;
}