Fix coding rule violation
[platform/core/system/tizen-platform-config.git] / src / tzplatform_config.h
1 /*
2  * Copyright (C) 2013-2014 Intel Corporation.
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Library General Public
6  * License as published by the Free Software Foundation; either
7  * version 2 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  * Library General Public License for more details.
13  *
14  * You should have received a copy of the GNU Library General Public
15  * License along with this library; if not, write to the Free Software
16  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
17  *
18  * Authors:
19  *       José Bollo <jose.bollo@open.eurogiciel.org>
20  *       Stéphane Desneux <stephane.desneux@open.eurogiciel.org>
21  *       Jean-Benoit Martin <jean-benoit.martin@open.eurogiciel.org>
22  *
23  */
24 #ifndef LIBTIZEN_PLATFORM_WRAPPER
25 #define LIBTIZEN_PLATFORM_WRAPPER
26
27 #ifdef __cplusplus
28 extern "C" {
29 #endif
30
31 #include <sys/types.h>
32 #include <tzplatform_variables.h>
33
34 /*------------------------------ COMMON API (no context) ---------------*/
35
36 /*
37  Return the count of variables.
38 */
39 extern
40 int tzplatform_getcount();
41
42 /*
43  Return the name of the variable 'id' as a string.
44  Return NULL if 'id' is invalid.
45 */
46 extern
47 const char* tzplatform_getname(enum tzplatform_variable id);
48
49 /*
50  Return the id of the variable of 'name'.
51  Return _TZPLATFORM_VARIABLES_INVALID_ if 'name' doesn't match a
52  valid variable name.
53 */
54 extern
55 enum tzplatform_variable tzplatform_getid(const char *name);
56
57 /*------------------------------ GLOBAL API (default global context) ----*/
58
59 /*
60  Enforces the removal of the previously evaluated tizen platform variables.
61
62  Call this function in case of changing of user inside the application.
63 */
64 extern
65 void tzplatform_reset();
66
67 /*
68  Set the user used for UID/EUID/USER/EUSER computations.
69  Using uid==(uid_t)-1 reset the context as if tzplatform_reset_user
70  was called.
71
72  Returns 0 if uid is valid or -1 if not valid.
73 */
74 extern
75 int tzplatform_set_user(uid_t uid);
76
77 /*
78 */
79 extern
80 uid_t tzplatform_get_user();
81
82 /*
83  Reset the user context to use the values returned by
84  getuid and geteuid.
85 */
86 extern
87 void tzplatform_reset_user();
88
89 /*
90  Return the read-only string value of the tizen plaform variable 'id'.
91
92  The returned value is an allocated unique string that MUST not be freed.
93
94  Can return NULL in case of internal error or when 'id' isn't defined.
95 */
96 extern
97 const char* tzplatform_getenv(enum tzplatform_variable id);
98
99 /*
100  Return the integer value of the tizen plaform variable 'id'.
101 */
102 extern
103 int tzplatform_getenv_int(enum tzplatform_variable id);
104
105 /*
106  Return the string resulting of the concatenation of string value of the
107  tizen plaform variable 'id' and the given string 'str'.
108
109  The returned value is an allocated unique string that MUST not be freed.
110
111  Can return NULL in case of internal error.
112
113  Example:
114         if TZ_SYS_HOME == "/opt/home" then calling
115
116            tzplatform_mkstr(TZ_SYS_HOME,"-yes")
117
118         will return "/opt/home-yes"
119 */
120 extern
121 const char* tzplatform_mkstr(enum tzplatform_variable id, const char *str);
122
123 /*
124  Return the string resulting of the path-concatenation of string value of the
125  tizen plaform variable 'id' and the given string 'path'.
126
127  path-concatenation is the concatenation taking care of / characters.
128
129  The returned value is an allocated unique string that MUST not be freed.
130
131  Can return NULL in case of internal error.
132
133  Example:
134         if TZ_SYS_HOME == "/opt/home" then calling
135
136            tzplatform_mkpath(TZ_SYS_HOME,"yes")
137
138         will return "/opt/home/yes"
139 */
140 extern
141 const char* tzplatform_mkpath(enum tzplatform_variable id, const char *path);
142
143 /*
144  Return the string resulting of the path-concatenation of string value of the
145  tizen plaform variable 'id' and the given strings 'path' and 'path2'.
146
147  path-concatenation is the concatenation taking care of / characters.
148
149  The returned value is an allocated unique string that MUST not be freed.
150
151  Can return NULL in case of internal error.
152
153  Example:
154         if TZ_SYS_HOME == "/opt/home" then calling
155
156            tzplatform_mkpath3(TZ_SYS_HOME,"yes","no")
157
158         will return "/opt/home/yes/no"
159 */
160 extern
161 const char* tzplatform_mkpath3(enum tzplatform_variable id, const char *path,
162                                                                                                                         const char *path2);
163
164 /*
165  Return the string resulting of the path-concatenation of string value of the
166  tizen plaform variable 'id' and the given strings 'path', 'path2' and 'path3'.
167
168  path-concatenation is the concatenation taking care of / characters.
169
170  The returned value is an allocated unique string that MUST not be freed.
171
172  Can return NULL in case of internal error.
173
174  Example:
175         if TZ_SYS_HOME == "/opt/home" then calling
176
177            tzplatform_mkpath4(TZ_SYS_HOME,"yes","no","/maybe")
178
179         will return "/opt/home/yes/no/maybe"
180 */
181 extern
182 const char* tzplatform_mkpath4(enum tzplatform_variable id, const char *path,
183                                                                                 const char *path2, const char *path3);
184
185 /*
186  Return the uid for a given user name, stored in variable <id>
187  Retun -1 in case of error.
188
189  Example:
190         if TZ_USER_NAME=="app" then calling:
191
192            tzplatform_getuid(TZ_USER_NAME)
193
194         will return the uid of the user 'app'
195 */
196 extern
197 uid_t tzplatform_getuid(enum tzplatform_variable id);
198
199 /*
200  Return the gid for a given user name, stored in variable <id>
201  Retun -1 in case of error.
202
203  Example:
204         if TZ_USER_NAME=="app" then calling:
205
206            tzplatform_getuid(TZ_USER_NAME)
207
208         will return the gid of the user 'app'
209 */
210 extern
211 gid_t tzplatform_getgid(enum tzplatform_variable id);
212
213 /*------------------------------ CONTEXTUAL API --------------------------*/
214
215 struct tzplatform_context;
216
217 /*
218  Creates a new platform 'context'.
219  Return 0 in case of success or a negative value in case of error.
220 */
221 extern
222 int tzplatform_context_create(struct tzplatform_context **context);
223
224 /*
225  Destroys the platform 'context' previously created with 'tzplatform_context_create'.
226  The destroyed context must not be used after calling this function.
227 */
228 extern
229 void tzplatform_context_destroy(struct tzplatform_context *context);
230
231 /*
232  Enforces the removal of the previously evaluated tizen platform variables.
233 */
234 extern
235 void tzplatform_context_reset(struct tzplatform_context *context);
236
237 /*
238  Set the user used for UID/EUID/USER/EUSER computations.
239  Using uid==(uid_t)-1 reset the context as if tzplatform_context_reset_user
240  was called.
241
242  Returns 0 if uid is valid or -1 if not valid.
243 */
244 extern
245 int tzplatform_context_set_user(struct tzplatform_context *context, uid_t uid);
246
247 /*
248  Get the user set to the context.
249 */
250 extern
251 uid_t tzplatform_context_get_user(struct tzplatform_context *context);
252
253 /*
254  Reset the user context to use the values returned by
255  getuid and geteuid.
256 */
257 extern
258 void tzplatform_context_reset_user(struct tzplatform_context *context);
259
260 /*
261  Return the read-only string value of the tizen plaform variable 'id'.
262
263  The returned value is an allocated unique string that MUST not be freed.
264
265  Can return NULL in case of internal error or when 'id' isn't defined.
266 */
267 extern
268 const char* tzplatform_context_getenv(struct tzplatform_context *context, enum tzplatform_variable id);
269
270 /*
271  Return the integer value of the tizen plaform variable 'id'.
272 */
273 extern
274 int tzplatform_context_getenv_int(struct tzplatform_context *context, enum tzplatform_variable id);
275
276 /*
277  Return the string resulting of the concatenation of string value of the
278  tizen plaform variable 'id' and the given string 'str'.
279
280  The returned value is an allocated unique string that MUST not be freed.
281
282  Can return NULL in case of internal error.
283
284  Example:
285         if TZ_SYS_HOME == "/opt/home" then calling
286
287            tzplatform_context_mkstr(context, TZ_SYS_HOME,"-yes")
288
289         will return "/opt/home-yes"
290 */
291 extern
292 const char* tzplatform_context_mkstr(struct tzplatform_context *context, enum tzplatform_variable id, const char *str);
293
294 /*
295  Return the string resulting of the path-concatenation of string value of the
296  tizen plaform variable 'id' and the given string 'path'.
297
298  path-concatenation is the concatenation taking care of / characters.
299
300  The returned value is an allocated unique string that MUST not be freed.
301
302  Can return NULL in case of internal error.
303
304  Example:
305         if TZ_SYS_HOME == "/opt/home" then calling
306
307            tzplatform_context_mkpath(context, TZ_SYS_HOME,"yes")
308
309         will return "/opt/home/yes"
310 */
311 extern
312 const char* tzplatform_context_mkpath(struct tzplatform_context *context, enum tzplatform_variable id, const char *path);
313
314 /*
315  Return the string resulting of the path-concatenation of string value of the
316  tizen plaform variable 'id' and the given strings 'path' and 'path2'.
317
318  path-concatenation is the concatenation taking care of / characters.
319
320  The returned value is an allocated unique string that MUST not be freed.
321
322  Can return NULL in case of internal error.
323
324  Example:
325         if TZ_SYS_HOME == "/opt/home" then calling
326
327            tzplatform_context_mkpath3(context, TZ_SYS_HOME,"yes","no")
328
329         will return "/opt/home/yes/no"
330 */
331 extern
332 const char* tzplatform_context_mkpath3(struct tzplatform_context *context, enum tzplatform_variable id, const char *path,
333                                                                                                                         const char *path2);
334
335 /*
336  Return the string resulting of the path-concatenation of string value of the
337  tizen plaform variable 'id' and the given strings 'path', 'path2' and 'path3'.
338
339  path-concatenation is the concatenation taking care of / characters.
340
341  The returned value is an allocated unique string that MUST not be freed.
342
343  Can return NULL in case of internal error.
344
345  Example:
346         if TZ_SYS_HOME == "/opt/home" then calling
347
348            tzplatform_context_mkpath4(context, TZ_SYS_HOME,"yes","no","/maybe")
349
350         will return "/opt/home/yes/no/maybe"
351 */
352 extern
353 const char* tzplatform_context_mkpath4(struct tzplatform_context *context, enum tzplatform_variable id, const char *path,
354                                                                                 const char *path2, const char *path3);
355
356 /*
357  Return the uid for a given user name, stored in variable <id>
358  Retun -1 in case of error.
359
360  Example:
361         if TZ_USER_NAME=="app" then calling:
362
363            tzplatform_context_getuid(context, TZ_USER_NAME)
364
365         will return the uid of the user 'app'
366 */
367 extern
368 uid_t tzplatform_context_getuid(struct tzplatform_context *context, enum tzplatform_variable id);
369
370 /*
371  Return the gid for a given user name, stored in variable <id>
372  Retun -1 in case of error.
373
374  Example:
375         if TZ_USER_NAME=="app" then calling:
376
377            tzplatform_context_getuid(context, TZ_USER_NAME)
378
379         will return the gid of the user 'app'
380 */
381 extern
382 gid_t tzplatform_context_getgid(struct tzplatform_context *context, enum tzplatform_variable id);
383
384
385 /*
386  Return 1 if given uid is in the system admin group (named "system")
387  Return 0 if not
388  Return -1 in case of error.
389
390  Example:
391                 tzplatform_has_system_group(1000)
392
393         will return 0 or 1 depends on right of given uid.
394
395    NOTE :
396    * If you pass the -1 value to this function it will take the current uid given
397    * by the POSIX function getuid();
398
399    *** WARNING : ***
400    * This is a temporary feature
401    * This will be managed by Cynara
402
403 */
404 extern
405 int tzplatform_has_system_group(uid_t uid);
406
407 #ifdef __cplusplus
408 }
409 #endif
410
411 #endif /* LIBTIZEN_PLATFORM_WRAPPER */
412