2 * Copyright (C) 2013-2014 Intel Corporation.
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.
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.
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
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>
24 #ifndef LIBTIZEN_PLATFORM_WRAPPER
25 #define LIBTIZEN_PLATFORM_WRAPPER
31 #include <sys/types.h>
32 #include <tzplatform_variables.h>
34 /*------------------------------ COMMON API (no context) ---------------*/
37 Return the count of variables.
40 int tzplatform_getcount();
43 Return the name of the variable 'id' as a string.
44 Return NULL if 'id' is invalid.
47 const char* tzplatform_getname(enum tzplatform_variable id);
50 Return the id of the variable of 'name'.
51 Return _TZPLATFORM_VARIABLES_INVALID_ if 'name' doesn't match a
55 enum tzplatform_variable tzplatform_getid(const char *name);
57 /*------------------------------ GLOBAL API (default global context) ----*/
60 Enforces the removal of the previously evaluated tizen platform variables.
62 Call this function in case of changing of user inside the application.
65 void tzplatform_reset();
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
72 Returns 0 if uid is valid or -1 if not valid.
75 int tzplatform_set_user(uid_t uid);
80 uid_t tzplatform_get_user();
83 Reset the user context to use the values returned by
87 void tzplatform_reset_user();
90 Return the read-only string value of the tizen plaform variable 'id'.
92 The returned value is an allocated unique string that MUST not be freed.
94 Can return NULL in case of internal error or when 'id' isn't defined.
97 const char* tzplatform_getenv(enum tzplatform_variable id);
100 Return the integer value of the tizen plaform variable 'id'.
103 int tzplatform_getenv_int(enum tzplatform_variable id);
106 Return the string resulting of the concatenation of string value of the
107 tizen plaform variable 'id' and the given string 'str'.
109 The returned value is an allocated unique string that MUST not be freed.
111 Can return NULL in case of internal error.
114 if TZ_SYS_HOME == "/opt/home" then calling
116 tzplatform_mkstr(TZ_SYS_HOME,"-yes")
118 will return "/opt/home-yes"
121 const char* tzplatform_mkstr(enum tzplatform_variable id, const char *str);
124 Return the string resulting of the path-concatenation of string value of the
125 tizen plaform variable 'id' and the given string 'path'.
127 path-concatenation is the concatenation taking care of / characters.
129 The returned value is an allocated unique string that MUST not be freed.
131 Can return NULL in case of internal error.
134 if TZ_SYS_HOME == "/opt/home" then calling
136 tzplatform_mkpath(TZ_SYS_HOME,"yes")
138 will return "/opt/home/yes"
141 const char* tzplatform_mkpath(enum tzplatform_variable id, const char *path);
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'.
147 path-concatenation is the concatenation taking care of / characters.
149 The returned value is an allocated unique string that MUST not be freed.
151 Can return NULL in case of internal error.
154 if TZ_SYS_HOME == "/opt/home" then calling
156 tzplatform_mkpath3(TZ_SYS_HOME,"yes","no")
158 will return "/opt/home/yes/no"
161 const char* tzplatform_mkpath3(enum tzplatform_variable id, const char *path,
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'.
168 path-concatenation is the concatenation taking care of / characters.
170 The returned value is an allocated unique string that MUST not be freed.
172 Can return NULL in case of internal error.
175 if TZ_SYS_HOME == "/opt/home" then calling
177 tzplatform_mkpath4(TZ_SYS_HOME,"yes","no","/maybe")
179 will return "/opt/home/yes/no/maybe"
182 const char* tzplatform_mkpath4(enum tzplatform_variable id, const char *path,
183 const char *path2, const char *path3);
186 Return the uid for a given user name, stored in variable <id>
187 Retun -1 in case of error.
190 if TZ_USER_NAME=="app" then calling:
192 tzplatform_getuid(TZ_USER_NAME)
194 will return the uid of the user 'app'
197 uid_t tzplatform_getuid(enum tzplatform_variable id);
200 Return the gid for a given group name, stored in variable <id>
201 Retun -1 in case of error.
204 if TZ_USER_GROUP=="app" then calling:
206 tzplatform_getuid(TZ_USER_GROUP)
208 will return the gid of the group 'app'
211 gid_t tzplatform_getgid(enum tzplatform_variable id);
213 /*------------------------------ CONTEXTUAL API --------------------------*/
215 struct tzplatform_context;
218 Creates a new platform 'context'.
219 Return 0 in case of success or a negative value in case of error.
222 int tzplatform_context_create(struct tzplatform_context **context);
225 Destroys the platform 'context' previously created with 'tzplatform_context_create'.
226 The destroyed context must not be used after calling this function.
229 void tzplatform_context_destroy(struct tzplatform_context *context);
232 Enforces the removal of the previously evaluated tizen platform variables.
235 void tzplatform_context_reset(struct tzplatform_context *context);
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
242 Returns 0 if uid is valid or -1 if not valid.
245 int tzplatform_context_set_user(struct tzplatform_context *context, uid_t uid);
248 Get the user set to the context.
251 uid_t tzplatform_context_get_user(struct tzplatform_context *context);
254 Reset the user context to use the values returned by
258 void tzplatform_context_reset_user(struct tzplatform_context *context);
261 Return the read-only string value of the tizen plaform variable 'id'.
263 The returned value is an allocated unique string that MUST not be freed.
265 Can return NULL in case of internal error or when 'id' isn't defined.
268 const char* tzplatform_context_getenv(struct tzplatform_context *context, enum tzplatform_variable id);
271 Return the integer value of the tizen plaform variable 'id'.
274 int tzplatform_context_getenv_int(struct tzplatform_context *context, enum tzplatform_variable id);
277 Return the string resulting of the concatenation of string value of the
278 tizen plaform variable 'id' and the given string 'str'.
280 The returned value is an allocated unique string that MUST not be freed.
282 Can return NULL in case of internal error.
285 if TZ_SYS_HOME == "/opt/home" then calling
287 tzplatform_context_mkstr(context, TZ_SYS_HOME,"-yes")
289 will return "/opt/home-yes"
292 const char* tzplatform_context_mkstr(struct tzplatform_context *context, enum tzplatform_variable id, const char *str);
295 Return the string resulting of the path-concatenation of string value of the
296 tizen plaform variable 'id' and the given string 'path'.
298 path-concatenation is the concatenation taking care of / characters.
300 The returned value is an allocated unique string that MUST not be freed.
302 Can return NULL in case of internal error.
305 if TZ_SYS_HOME == "/opt/home" then calling
307 tzplatform_context_mkpath(context, TZ_SYS_HOME,"yes")
309 will return "/opt/home/yes"
312 const char* tzplatform_context_mkpath(struct tzplatform_context *context, enum tzplatform_variable id, const char *path);
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'.
318 path-concatenation is the concatenation taking care of / characters.
320 The returned value is an allocated unique string that MUST not be freed.
322 Can return NULL in case of internal error.
325 if TZ_SYS_HOME == "/opt/home" then calling
327 tzplatform_context_mkpath3(context, TZ_SYS_HOME,"yes","no")
329 will return "/opt/home/yes/no"
332 const char* tzplatform_context_mkpath3(struct tzplatform_context *context, enum tzplatform_variable id, const char *path,
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'.
339 path-concatenation is the concatenation taking care of / characters.
341 The returned value is an allocated unique string that MUST not be freed.
343 Can return NULL in case of internal error.
346 if TZ_SYS_HOME == "/opt/home" then calling
348 tzplatform_context_mkpath4(context, TZ_SYS_HOME,"yes","no","/maybe")
350 will return "/opt/home/yes/no/maybe"
353 const char* tzplatform_context_mkpath4(struct tzplatform_context *context, enum tzplatform_variable id, const char *path,
354 const char *path2, const char *path3);
357 Return the uid for a given user name, stored in variable <id>
358 Retun -1 in case of error.
361 if TZ_USER_NAME=="app" then calling:
363 tzplatform_context_getuid(context, TZ_USER_NAME)
365 will return the uid of the user 'app'
368 uid_t tzplatform_context_getuid(struct tzplatform_context *context, enum tzplatform_variable id);
371 Return the gid for a given group name, stored in variable <id>
372 Retun -1 in case of error.
375 if TZ_USER_GROUP=="app" then calling:
377 tzplatform_context_getuid(context, TZ_USER_GROUP)
379 will return the gid of the group 'app'
382 gid_t tzplatform_context_getgid(struct tzplatform_context *context, enum tzplatform_variable id);
386 Return 1 if given uid is in the system admin group (named "system")
388 Return -1 in case of error.
391 tzplatform_isadmin(1000)
393 will return 0 or 1 depends on right of given uid.
396 * If you pass the -1 value to this function it will take the current uid given
397 * by the POSIX function getuid();
400 * This is a temporary feature
401 * This will be managed by Cynara
405 int tzplatform_isadmin(uid_t uid);
411 #endif /* LIBTIZEN_PLATFORM_WRAPPER */