ca78b35c283bb826a8cb9a597b09f1f6d8f3c931
[platform/core/system/tizen-platform-wrapper.git] / src / tzplatform_config.h
1 /*
2  * Copyright (C) 2013 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 group name, stored in variable <id>
201  Retun -1 in case of error.
202
203  Example:
204     if TZ_USER_GROUP=="app" then calling:
205
206        tzplatform_getuid(TZ_USER_GROUP)
207
208     will return the gid of the group '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  Call this function in case of changing of user inside the application.
235 */
236 extern
237 void tzplatform_context_reset(struct tzplatform_context *context);
238
239 /*
240  Set the user used for UID/EUID/USER/EUSER computations.
241  Using uid==(uid_t)-1 reset the context as if tzplatform_context_reset_user
242  was called.
243
244  Returns 0 if uid is valid or -1 if not valid.
245 */
246 extern
247 int tzplatform_context_set_user(struct tzplatform_context *context, uid_t uid);
248
249 /*
250 */
251 extern
252 uid_t tzplatform_context_get_user(struct tzplatform_context *context);
253
254 /*
255  Reset the user context to use the values returned by
256  getuid and geteuid.
257 */
258 extern
259 void tzplatform_context_reset_user(struct tzplatform_context *context);
260
261 /*
262  Return the read-only string value of the tizen plaform variable 'id'.
263
264  The returned value is an allocated unique string that MUST not be freed.
265
266  Can return NULL in case of internal error or when 'id' isn't defined.
267 */
268 extern
269 const char* tzplatform_context_getenv(struct tzplatform_context *context, enum tzplatform_variable id);
270
271 /*
272  Return the integer value of the tizen plaform variable 'id'.
273 */
274 extern
275 int tzplatform_context_getenv_int(struct tzplatform_context *context, enum tzplatform_variable id);
276
277 /*
278  Return the string resulting of the concatenation of string value of the
279  tizen plaform variable 'id' and the given string 'str'.
280
281  The returned value is an allocated unique string that MUST not be freed.
282
283  Can return NULL in case of internal error.
284
285  Example:
286     if TZ_SYS_HOME == "/opt/home" then calling
287
288        tzplatform_context_mkstr(context, TZ_SYS_HOME,"-yes")
289
290     will return "/opt/home-yes"
291 */
292 extern
293 const char* tzplatform_context_mkstr(struct tzplatform_context *context, enum tzplatform_variable id, const char *str);
294
295 /*
296  Return the string resulting of the path-concatenation of string value of the
297  tizen plaform variable 'id' and the given string 'path'.
298
299  path-concatenation is the concatenation taking care of / characters.
300
301  The returned value is an allocated unique string that MUST not be freed.
302
303  Can return NULL in case of internal error.
304
305  Example:
306     if TZ_SYS_HOME == "/opt/home" then calling
307
308        tzplatform_context_mkpath(context, TZ_SYS_HOME,"yes")
309
310     will return "/opt/home/yes"
311 */
312 extern
313 const char* tzplatform_context_mkpath(struct tzplatform_context *context, enum tzplatform_variable id, const char *path);
314
315 /*
316  Return the string resulting of the path-concatenation of string value of the
317  tizen plaform variable 'id' and the given strings 'path' and 'path2'.
318
319  path-concatenation is the concatenation taking care of / characters.
320
321  The returned value is an allocated unique string that MUST not be freed.
322
323  Can return NULL in case of internal error.
324
325  Example:
326     if TZ_SYS_HOME == "/opt/home" then calling
327
328        tzplatform_context_mkpath3(context, TZ_SYS_HOME,"yes","no")
329
330     will return "/opt/home/yes/no"
331 */
332 extern
333 const char* tzplatform_context_mkpath3(struct tzplatform_context *context, enum tzplatform_variable id, const char *path,
334                                                             const char *path2);
335
336 /*
337  Return the string resulting of the path-concatenation of string value of the
338  tizen plaform variable 'id' and the given strings 'path', 'path2' and 'path3'.
339
340  path-concatenation is the concatenation taking care of / characters.
341
342  The returned value is an allocated unique string that MUST not be freed.
343
344  Can return NULL in case of internal error.
345
346  Example:
347     if TZ_SYS_HOME == "/opt/home" then calling
348
349        tzplatform_context_mkpath4(context, TZ_SYS_HOME,"yes","no","/maybe")
350
351     will return "/opt/home/yes/no/maybe"
352 */
353 extern
354 const char* tzplatform_context_mkpath4(struct tzplatform_context *context, enum tzplatform_variable id, const char *path,
355                                         const char *path2, const char *path3);
356
357 /*
358  Return the uid for a given user name, stored in variable <id>
359  Retun -1 in case of error.
360
361  Example:
362     if TZ_USER_NAME=="app" then calling:
363
364        tzplatform_context_getuid(context, TZ_USER_NAME)
365
366     will return the uid of the user 'app'
367 */
368 extern
369 uid_t tzplatform_context_getuid(struct tzplatform_context *context, enum tzplatform_variable id);
370
371 /*
372  Return the gid for a given group name, stored in variable <id>
373  Retun -1 in case of error.
374
375  Example:
376     if TZ_USER_GROUP=="app" then calling:
377
378        tzplatform_context_getuid(context, TZ_USER_GROUP)
379
380     will return the gid of the group 'app'
381 */
382 extern
383 gid_t tzplatform_context_getgid(struct tzplatform_context *context, enum tzplatform_variable id);
384
385 #ifdef __cplusplus
386 }
387 #endif
388
389 #endif /* LIBTIZEN_PLATFORM_WRAPPER */
390