~ubuntu-branches/ubuntu/utopic/nordugrid-arc/utopic-proposed

« back to all changes in this revision

Viewing changes to src/services/a-rex/grid-manager/conf/conf.cpp

  • Committer: Package Import Robot
  • Author(s): Mattias Ellert
  • Date: 2013-04-17 06:37:28 UTC
  • mfrom: (1.1.6)
  • Revision ID: package-import@ubuntu.com-20130417063728-h56uqu0belk87zqa
Tags: 3.0.0-1
3.0.0 Release (Closes: #690716)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#ifdef HAVE_CONFIG_H
2
 
#include <config.h>
3
 
#endif
4
 
 
5
 
#include <arc/StringConv.h>
6
 
 
7
 
#include "conf.h"
8
 
#include "../misc/escaped.h"
9
 
#include "environment.h"
10
 
 
11
 
bool config_open(std::ifstream &cfile,const GMEnvironment& env) {
12
 
  return config_open(cfile,env.nordugrid_config_loc());
13
 
}
14
 
 
15
 
bool config_open(std::ifstream &cfile,const std::string &name) {
16
 
  cfile.open(name.c_str(),std::ifstream::in);
17
 
  return cfile.is_open();
18
 
}
19
 
 
20
 
bool config_close(std::ifstream &cfile) {
21
 
  if(cfile.is_open()) cfile.close();
22
 
  return true;
23
 
}
24
 
 
25
 
std::string config_read_line(std::istream &cfile,std::string &rest,char separator) {
26
 
  rest = config_read_line(cfile);
27
 
  return config_next_arg(rest,separator);
28
 
}
29
 
 
30
 
std::string config_read_line(std::istream &cfile) {
31
 
  std::string rest;
32
 
  for(;;) {
33
 
    if(cfile.eof() || cfile.fail()) { rest=""; return rest; };
34
 
    std::getline(cfile,rest);
35
 
    Arc::trim(rest," \t\r\n");
36
 
    if(rest.empty()) continue; /* empty string - skip */
37
 
    if(rest[0] == '#') continue; /* comment - skip */
38
 
    break;
39
 
  };
40
 
  return rest;
41
 
}
42
 
 
43
 
std::string config_next_arg(std::string &rest,char separator) {
44
 
  int n;
45
 
  std::string arg;
46
 
  n=input_escaped_string(rest.c_str(),arg,separator);
47
 
  rest=rest.substr(n);
48
 
  return arg;
49
 
}    
50
 
 
51
 
config_file_type config_detect(std::istream& in) {
52
 
  char inchar;
53
 
  if (!in.good()) return config_file_unknown;
54
 
  while(in.good()) {
55
 
    inchar = (char)(in.get());
56
 
    if(isspace(inchar)) continue;
57
 
    if(inchar == '<') {
58
 
      // XML starts from < even if it is comment
59
 
      in.putback(inchar);
60
 
      return config_file_XML;
61
 
    };
62
 
    if((inchar == '#') || (inchar = '[')) {
63
 
      // INI file starts from comment or section
64
 
      in.putback(inchar);
65
 
      return config_file_INI;
66
 
    };
67
 
  };
68
 
  in.putback(inchar);
69
 
  return config_file_unknown;
70
 
}
71
 
 
72
 
 
73
 
bool elementtobool(Arc::XMLNode pnode,const char* ename,bool& val,Arc::Logger* logger) {
74
 
  std::string v = ename?pnode[ename]:pnode;
75
 
  if(v.empty()) return true; // default
76
 
  if((v == "true") || (v == "1")) {
77
 
    val=true;
78
 
    return true;
79
 
  };
80
 
  if((v == "false") || (v == "0")) {
81
 
    val=false;
82
 
    return true;
83
 
  };
84
 
  if(logger && ename) logger->msg(Arc::ERROR,"wrong boolean in %s: %s",ename,v.c_str());
85
 
  return false;
86
 
}
87
 
 
88
 
bool elementtoint(Arc::XMLNode pnode,const char* ename,unsigned int& val,Arc::Logger* logger) {
89
 
  std::string v = ename?pnode[ename]:pnode;
90
 
  if(v.empty()) return true; // default
91
 
  if(Arc::stringto(v,val)) return true;
92
 
  if(logger && ename) logger->msg(Arc::ERROR,"wrong number in %s: %s",ename,v.c_str());
93
 
  return false;
94
 
}
95
 
 
96
 
bool elementtoint(Arc::XMLNode pnode,const char* ename,int& val,Arc::Logger* logger) {
97
 
  std::string v = ename?pnode[ename]:pnode;
98
 
  if(v.empty()) return true; // default
99
 
  if(Arc::stringto(v,val)) return true;
100
 
  if(logger && ename) logger->msg(Arc::ERROR,"wrong number in %s: %s",ename,v.c_str());
101
 
  return false;
102
 
}
103
 
 
104
 
bool elementtoenum(Arc::XMLNode pnode,const char* ename,int& val,const char* const opts[],Arc::Logger* logger) {
105
 
  std::string v = ename?pnode[ename]:pnode;
106
 
  if(v.empty()) return true; // default
107
 
  for(int n = 0;opts[n];++n) {
108
 
    if(v == opts[n]) { val = n; return true; };
109
 
  }; 
110
 
  return false;
111
 
}