dbus-marshal-byteswap: Byte-swap Unix fd indexes if needed
[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 <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
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, "check") == 0)
79     {
80       return ELEMENT_CHECK;
81     }
82   else if (strcmp (name, "servicehelper") == 0)
83     {
84       return ELEMENT_SERVICEHELPER;
85     }
86   else if (strcmp (name, "includedir") == 0)
87     {
88       return ELEMENT_INCLUDEDIR;
89     }
90   else if (strcmp (name, "standard_session_servicedirs") == 0)
91     {
92       return ELEMENT_STANDARD_SESSION_SERVICEDIRS;
93     }
94   else if (strcmp (name, "standard_system_servicedirs") == 0)
95     {
96       return ELEMENT_STANDARD_SYSTEM_SERVICEDIRS;
97     }
98   else if (strcmp (name, "servicedir") == 0)
99     {
100       return ELEMENT_SERVICEDIR;
101     }
102   else if (strcmp (name, "include") == 0)
103     {
104       return ELEMENT_INCLUDE;
105     }
106   else if (strcmp (name, "policy") == 0)
107     {
108       return ELEMENT_POLICY;
109     }
110   else if (strcmp (name, "limit") == 0)
111     {
112       return ELEMENT_LIMIT;
113     }
114   else if (strcmp (name, "selinux") == 0)
115     {
116       return ELEMENT_SELINUX;
117     }
118   else if (strcmp (name, "associate") == 0)
119     {
120       return ELEMENT_ASSOCIATE;
121     }
122   else if (strcmp (name, "syslog") == 0)
123     {
124       return ELEMENT_SYSLOG;
125     }
126   else if (strcmp (name, "keep_umask") == 0)
127     {
128       return ELEMENT_KEEP_UMASK;
129     }
130   else if (strcmp (name, "allow_anonymous") == 0)
131     {
132       return ELEMENT_ALLOW_ANONYMOUS;
133     }
134   else if (strcmp (name, "apparmor") == 0)
135     {
136       return ELEMENT_APPARMOR;
137     }
138   return ELEMENT_NONE;
139 }
140
141 const char*
142 bus_config_parser_element_type_to_name (ElementType type)
143 {
144   switch (type)
145     {
146     case ELEMENT_NONE:
147       return NULL;
148     case ELEMENT_BUSCONFIG:
149       return "busconfig";
150     case ELEMENT_INCLUDE:
151       return "include";
152     case ELEMENT_USER:
153       return "user";
154     case ELEMENT_LISTEN:
155       return "listen";
156     case ELEMENT_AUTH:
157       return "auth";
158     case ELEMENT_POLICY:
159       return "policy";
160     case ELEMENT_LIMIT:
161       return "limit";
162     case ELEMENT_ALLOW:
163       return "allow";
164     case ELEMENT_DENY:
165       return "deny";
166     case ELEMENT_CHECK:
167       return "check";
168     case ELEMENT_FORK:
169       return "fork";
170     case ELEMENT_PIDFILE:
171       return "pidfile";
172     case ELEMENT_STANDARD_SESSION_SERVICEDIRS:
173       return "standard_session_servicedirs";
174     case ELEMENT_STANDARD_SYSTEM_SERVICEDIRS:
175       return "standard_system_servicedirs";
176     case ELEMENT_SERVICEDIR:
177       return "servicedir";
178     case ELEMENT_SERVICEHELPER:
179       return "servicehelper";
180     case ELEMENT_INCLUDEDIR:
181       return "includedir";
182     case ELEMENT_CONFIGTYPE:
183       return "type";
184     case ELEMENT_SELINUX:
185       return "selinux";
186     case ELEMENT_ASSOCIATE:
187       return "associate";
188     case ELEMENT_SYSLOG:
189       return "syslog";
190     case ELEMENT_KEEP_UMASK:
191       return "keep_umask";
192     case ELEMENT_ALLOW_ANONYMOUS:
193       return "allow_anonymous";
194     case ELEMENT_APPARMOR:
195       return "apparmor";
196     default:
197       _dbus_assert_not_reached ("bad element type");
198       return NULL;
199     }
200 }
201