Merge branch 'dbus-1.2'
[platform/upstream/dbus.git] / bus / config-parser-common.c
1 /* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
2 /* config-parser-common.c  Common defines and routines for config file parsing
3  *
4  * Copyright (C) 2007 Red Hat, Inc.
5  *
6  * Licensed under the Academic Free License version 2.1
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 2 of the License, or
11  * (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program; if not, write to the Free Software
20  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
21  *
22  */
23  
24 #include <dbus/dbus-internals.h>
25 #include <string.h>
26
27 #include "config-parser-common.h"
28 #include "utils.h"
29
30 ElementType
31 bus_config_parser_element_name_to_type (const char *name)
32 {
33   if (strcmp (name, "none") == 0)
34     {
35       return ELEMENT_NONE;
36     }
37   else if (strcmp (name, "busconfig") == 0)
38     {
39       return ELEMENT_BUSCONFIG;
40     }
41   else if (strcmp (name, "user") == 0)
42     {
43       return ELEMENT_USER;
44     }
45   else if (strcmp (name, "auth") == 0)
46     {
47       return ELEMENT_AUTH;
48     }
49   else if (strcmp (name, "type") == 0)
50     {
51       return ELEMENT_TYPE;
52     }
53   else if (strcmp (name, "fork") == 0)
54     {
55       return ELEMENT_FORK;
56     }
57   else if (strcmp (name, "pidfile") == 0)
58     {
59       return ELEMENT_PIDFILE;
60     }
61   else if (strcmp (name, "listen") == 0)
62     {
63       return ELEMENT_LISTEN;
64     }
65   else if (strcmp (name, "auth") == 0)
66     {
67       return ELEMENT_AUTH;
68     }
69   else if (strcmp (name, "allow") == 0)
70     {
71       return ELEMENT_ALLOW;
72     }
73   else if (strcmp (name, "deny") == 0)
74     {
75       return ELEMENT_DENY;
76     }
77   else if (strcmp (name, "servicehelper") == 0)
78     {
79       return ELEMENT_SERVICEHELPER;
80     }
81   else if (strcmp (name, "includedir") == 0)
82     {
83       return ELEMENT_INCLUDEDIR;
84     }
85   else if (strcmp (name, "standard_session_servicedirs") == 0)
86     {
87       return ELEMENT_STANDARD_SESSION_SERVICEDIRS;
88     }
89   else if (strcmp (name, "standard_system_servicedirs") == 0)
90     {
91       return ELEMENT_STANDARD_SYSTEM_SERVICEDIRS;
92     }
93   else if (strcmp (name, "servicedir") == 0)
94     {
95       return ELEMENT_SERVICEDIR;
96     }
97   else if (strcmp (name, "include") == 0)
98     {
99       return ELEMENT_INCLUDE;
100     }
101   else if (strcmp (name, "policy") == 0)
102     {
103       return ELEMENT_POLICY;
104     }
105   else if (strcmp (name, "limit") == 0)
106     {
107       return ELEMENT_LIMIT;
108     }
109   else if (strcmp (name, "selinux") == 0)
110     {
111       return ELEMENT_SELINUX;
112     }
113   else if (strcmp (name, "associate") == 0)
114     {
115       return ELEMENT_ASSOCIATE;
116     }
117   else if (strcmp (name, "syslog") == 0)
118     {
119       return ELEMENT_SYSLOG;
120     }
121   else if (strcmp (name, "keep_umask") == 0)
122     {
123       return ELEMENT_KEEP_UMASK;
124     }
125   else if (strcmp (name, "allow_anonymous") == 0)
126     {
127       return ELEMENT_ALLOW_ANONYMOUS;
128     }
129   return ELEMENT_NONE;
130 }
131
132 const char*
133 bus_config_parser_element_type_to_name (ElementType type)
134 {
135   switch (type)
136     {
137     case ELEMENT_NONE:
138       return NULL;
139     case ELEMENT_BUSCONFIG:
140       return "busconfig";
141     case ELEMENT_INCLUDE:
142       return "include";
143     case ELEMENT_USER:
144       return "user";
145     case ELEMENT_LISTEN:
146       return "listen";
147     case ELEMENT_AUTH:
148       return "auth";
149     case ELEMENT_POLICY:
150       return "policy";
151     case ELEMENT_LIMIT:
152       return "limit";
153     case ELEMENT_ALLOW:
154       return "allow";
155     case ELEMENT_DENY:
156       return "deny";
157     case ELEMENT_FORK:
158       return "fork";
159     case ELEMENT_PIDFILE:
160       return "pidfile";
161     case ELEMENT_STANDARD_SESSION_SERVICEDIRS:
162       return "standard_session_servicedirs";
163     case ELEMENT_STANDARD_SYSTEM_SERVICEDIRS:
164       return "standard_system_servicedirs";
165     case ELEMENT_SERVICEDIR:
166       return "servicedir";
167     case ELEMENT_SERVICEHELPER:
168       return "servicehelper";
169     case ELEMENT_INCLUDEDIR:
170       return "includedir";
171     case ELEMENT_TYPE:
172       return "type";
173     case ELEMENT_SELINUX:
174       return "selinux";
175     case ELEMENT_ASSOCIATE:
176       return "associate";
177     case ELEMENT_SYSLOG:
178       return "syslog";
179     case ELEMENT_KEEP_UMASK:
180       return "keep_umask";
181     case ELEMENT_ALLOW_ANONYMOUS:
182       return "allow_anonymous";
183     }
184
185   _dbus_assert_not_reached ("bad element type");
186
187   return NULL;
188 }
189