Adding signature checking
[platform/core/system/tizen-platform-wrapper.git] / src / static-api.c
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 #define _GNU_SOURCE
25
26 #ifdef HAVE_CONFIG_H
27 # include "config.h"
28 #endif
29
30 #include <unistd.h>
31 #include "tzplatform_variables.h"
32 #include "tzplatform_config.h"
33
34 #include "shared-api.h"
35
36 #include "signup.inc"
37
38 int tzplatform_getcount()
39 {
40     return _TZPLATFORM_VARIABLES_COUNT_;
41 }
42
43 const char* tzplatform_getname(enum tzplatform_variable id)
44 {
45     return _getname_tzplatform_(id, tizen_platform_config_signup);
46 }
47
48 enum tzplatform_variable tzplatform_getid(const char *name)
49 {
50     return _getid_tzplatform_(name, tizen_platform_config_signup);
51 }
52
53 const char* tzplatform_getenv(enum tzplatform_variable id) 
54 {
55     return _getenv_tzplatform_(id, tizen_platform_config_signup);
56 }
57
58 const char* tzplatform_context_getenv(struct tzplatform_context *context, enum tzplatform_variable id)
59 {
60     return _context_getenv_tzplatform_(id, tizen_platform_config_signup, context);
61 }
62
63 int tzplatform_getenv_int(enum tzplatform_variable id)
64 {
65     return _getenv_int_tzplatform_(id, tizen_platform_config_signup);
66 }
67
68 int tzplatform_context_getenv_int(struct tzplatform_context *context, enum tzplatform_variable id)
69 {
70     return _context_getenv_int_tzplatform_(id, tizen_platform_config_signup, context);
71 }
72
73 const char* tzplatform_mkstr(enum tzplatform_variable id, const char * str)
74 {
75     return _mkstr_tzplatform_(id, str, tizen_platform_config_signup);
76 }
77
78 const char* tzplatform_context_mkstr(struct tzplatform_context *context, enum tzplatform_variable id, const char *str)
79 {
80     return _context_mkstr_tzplatform_(id, str, tizen_platform_config_signup, context);
81 }
82
83 const char* tzplatform_mkpath(enum tzplatform_variable id, const char * path)
84 {
85     return _mkpath_tzplatform_(id, path, tizen_platform_config_signup);
86 }
87
88 const char* tzplatform_context_mkpath(struct tzplatform_context *context, enum tzplatform_variable id, const char *path)
89 {
90     return _context_mkpath_tzplatform_(id, path, tizen_platform_config_signup, context);
91 }
92
93 const char* tzplatform_mkpath3(enum tzplatform_variable id, const char * path, const char* path2)
94 {
95     return _mkpath3_tzplatform_(id, path, path2, tizen_platform_config_signup);
96 }
97
98 const char* tzplatform_context_mkpath3(struct tzplatform_context *context, enum tzplatform_variable id, const char *path, const char *path2)
99 {
100     return _context_mkpath3_tzplatform_(id, path, path2, tizen_platform_config_signup, context);
101 }
102
103 const char* tzplatform_mkpath4(enum tzplatform_variable id, const char * path, const char* path2, const char *path3)
104 {
105     return _mkpath4_tzplatform_(id, path, path2, path3, tizen_platform_config_signup);
106 }
107
108 const char* tzplatform_context_mkpath4(struct tzplatform_context *context, enum tzplatform_variable id, const char *path, const char *path2, const char *path3)
109 {
110     return _context_mkpath4_tzplatform_(id, path, path2, path3, tizen_platform_config_signup, context);
111 }
112
113 uid_t tzplatform_getuid(enum tzplatform_variable id)
114 {
115     return _getuid_tzplatform_(id, tizen_platform_config_signup);
116 }
117
118 uid_t tzplatform_context_getuid(struct tzplatform_context *context, enum tzplatform_variable id)
119 {
120     return _context_getuid_tzplatform_(id, tizen_platform_config_signup, context);
121 }
122
123 gid_t tzplatform_getgid(enum tzplatform_variable id)
124 {
125     return _getgid_tzplatform_(id, tizen_platform_config_signup);
126 }
127
128 gid_t tzplatform_context_getgid(struct tzplatform_context *context, enum tzplatform_variable id)
129 {
130     return _context_getgid_tzplatform_(id, tizen_platform_config_signup, context);
131 }
132
133 #ifdef TEST
134 #include <stdlib.h>
135 #include <stdio.h>
136
137 int main() {
138     int i;
139     struct tzplatform_context *context;
140     enum tzplatform_variable id;
141     const char *name;
142     const char *value;
143     int xid;
144     uid_t uid;
145
146     i = 0;
147     while(i != tzplatform_getcount()) {
148         id = (enum tzplatform_variable)i;
149         name = tzplatform_getname(id);
150         value = tzplatform_getenv(id);
151         xid = (int)tzplatform_getid(name);
152         printf("%d=%d\t%s=%s\n",i,xid,name,value?value:"<null>");
153         i++;
154     }
155
156     printf("------------------------\n");
157     i = tzplatform_context_create(&context);
158     if (i) {
159         printf("error while creating context %d\n",i);
160         return 1;
161     }
162
163     uid = (uid_t)0;
164     i = tzplatform_context_set_user(context, uid);
165     if (i) {
166         printf("error %d while switching to user %d\n",i,(int)uid);
167         return 1;
168     }
169     i = 0;
170     while(i != tzplatform_getcount()) {
171         id = (enum tzplatform_variable)i;
172         name = tzplatform_getname(id);
173         value = tzplatform_context_getenv(context, id);
174         xid = (int)tzplatform_getid(name);
175         printf("%d=%d\t%s=%s\n",i,xid,name,value?value:"<null>");
176         i++;
177     }
178     tzplatform_context_destroy(context);
179
180     return 0;
181 }
182 #endif
183
184