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 <config.h>
25 #include <dbus/dbus-internals.h>
26 #include <string.h>
27 
28 #include "config-parser-common.h"
29 #include "utils.h"
30 
31 ElementType
bus_config_parser_element_name_to_type(const char * name)32 bus_config_parser_element_name_to_type (const char *name)
33 {
34   if (strcmp (name, "none") == 0)
35     {
36       return ELEMENT_NONE;
37     }
38   else if (strcmp (name, "busconfig") == 0)
39     {
40       return ELEMENT_BUSCONFIG;
41     }
42   else if (strcmp (name, "user") == 0)
43     {
44       return ELEMENT_USER;
45     }
46   else if (strcmp (name, "auth") == 0)
47     {
48       return ELEMENT_AUTH;
49     }
50   else if (strcmp (name, "type") == 0)
51     {
52       return ELEMENT_CONFIGTYPE;
53     }
54   else if (strcmp (name, "fork") == 0)
55     {
56       return ELEMENT_FORK;
57     }
58   else if (strcmp (name, "pidfile") == 0)
59     {
60       return ELEMENT_PIDFILE;
61     }
62   else if (strcmp (name, "listen") == 0)
63     {
64       return ELEMENT_LISTEN;
65     }
66   else if (strcmp (name, "auth") == 0)
67     {
68       return ELEMENT_AUTH;
69     }
70   else if (strcmp (name, "allow") == 0)
71     {
72       return ELEMENT_ALLOW;
73     }
74   else if (strcmp (name, "deny") == 0)
75     {
76       return ELEMENT_DENY;
77     }
78   else if (strcmp (name, "servicehelper") == 0)
79     {
80       return ELEMENT_SERVICEHELPER;
81     }
82   else if (strcmp (name, "includedir") == 0)
83     {
84       return ELEMENT_INCLUDEDIR;
85     }
86   else if (strcmp (name, "standard_session_servicedirs") == 0)
87     {
88       return ELEMENT_STANDARD_SESSION_SERVICEDIRS;
89     }
90   else if (strcmp (name, "standard_system_servicedirs") == 0)
91     {
92       return ELEMENT_STANDARD_SYSTEM_SERVICEDIRS;
93     }
94   else if (strcmp (name, "servicedir") == 0)
95     {
96       return ELEMENT_SERVICEDIR;
97     }
98   else if (strcmp (name, "include") == 0)
99     {
100       return ELEMENT_INCLUDE;
101     }
102   else if (strcmp (name, "policy") == 0)
103     {
104       return ELEMENT_POLICY;
105     }
106   else if (strcmp (name, "limit") == 0)
107     {
108       return ELEMENT_LIMIT;
109     }
110   else if (strcmp (name, "selinux") == 0)
111     {
112       return ELEMENT_SELINUX;
113     }
114   else if (strcmp (name, "associate") == 0)
115     {
116       return ELEMENT_ASSOCIATE;
117     }
118   else if (strcmp (name, "syslog") == 0)
119     {
120       return ELEMENT_SYSLOG;
121     }
122   else if (strcmp (name, "keep_umask") == 0)
123     {
124       return ELEMENT_KEEP_UMASK;
125     }
126   else if (strcmp (name, "allow_anonymous") == 0)
127     {
128       return ELEMENT_ALLOW_ANONYMOUS;
129     }
130   else if (strcmp (name, "apparmor") == 0)
131     {
132       return ELEMENT_APPARMOR;
133     }
134   return ELEMENT_NONE;
135 }
136 
137 const char*
bus_config_parser_element_type_to_name(ElementType type)138 bus_config_parser_element_type_to_name (ElementType type)
139 {
140   switch (type)
141     {
142     case ELEMENT_NONE:
143       return NULL;
144     case ELEMENT_BUSCONFIG:
145       return "busconfig";
146     case ELEMENT_INCLUDE:
147       return "include";
148     case ELEMENT_USER:
149       return "user";
150     case ELEMENT_LISTEN:
151       return "listen";
152     case ELEMENT_AUTH:
153       return "auth";
154     case ELEMENT_POLICY:
155       return "policy";
156     case ELEMENT_LIMIT:
157       return "limit";
158     case ELEMENT_ALLOW:
159       return "allow";
160     case ELEMENT_DENY:
161       return "deny";
162     case ELEMENT_FORK:
163       return "fork";
164     case ELEMENT_PIDFILE:
165       return "pidfile";
166     case ELEMENT_STANDARD_SESSION_SERVICEDIRS:
167       return "standard_session_servicedirs";
168     case ELEMENT_STANDARD_SYSTEM_SERVICEDIRS:
169       return "standard_system_servicedirs";
170     case ELEMENT_SERVICEDIR:
171       return "servicedir";
172     case ELEMENT_SERVICEHELPER:
173       return "servicehelper";
174     case ELEMENT_INCLUDEDIR:
175       return "includedir";
176     case ELEMENT_CONFIGTYPE:
177       return "type";
178     case ELEMENT_SELINUX:
179       return "selinux";
180     case ELEMENT_ASSOCIATE:
181       return "associate";
182     case ELEMENT_SYSLOG:
183       return "syslog";
184     case ELEMENT_KEEP_UMASK:
185       return "keep_umask";
186     case ELEMENT_ALLOW_ANONYMOUS:
187       return "allow_anonymous";
188     case ELEMENT_APPARMOR:
189       return "apparmor";
190     default:
191       _dbus_assert_not_reached ("bad element type");
192       return NULL;
193     }
194 }
195 
196