#endif
#include <unistd.h>
+#include <assert.h>
+#include <pthread.h>
#include "tzplatform_variables.h"
#include "tzplatform_config.h"
#include "shared-api.h"
#include "isadmin.h"
-
#include "signup.inc"
+#define TZ_UID_START 5000
+#define TZ_UID_MAX 128
+#define uid2idx(x) ((x > TZ_UID_START) ? (x - TZ_UID_START) : x)
+static struct tzplatform_context *_context[TZ_UID_MAX] = {0};
+
+int init_internal_context(uid_t uid)
+{
+ int ret;
+ int idx;
+ static pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER;
+
+ if (uid <= TZ_UID_START)
+ assert(uid == 0);
+
+ idx = uid2idx(uid);
+ assert(idx < TZ_UID_MAX);
+
+ if (_context[idx]) return 0;
+
+ pthread_mutex_lock(&mutex);
+
+ ret = tzplatform_context_create(&_context[idx]);
+ if (ret < 0) {
+ pthread_mutex_unlock(&mutex);
+ return ret;
+ }
+
+ ret = tzplatform_context_set_user(_context[idx], uid);
+ if (ret < 0) {
+ tzplatform_context_destroy(_context[idx]);
+ _context[idx] = NULL;
+
+ pthread_mutex_unlock(&mutex);
+ return ret;
+ }
+
+ pthread_mutex_unlock(&mutex);
+
+ return 0;
+}
+
int tzplatform_getcount()
{
return _TZPLATFORM_VARIABLES_COUNT_;
return _getenv_tzplatform_(id, tizen_platform_config_signup);
}
+const char* tzplatform_uid_getenv(uid_t uid, enum tzplatform_variable id)
+{
+ int ret = init_internal_context(uid);
+ if (ret < 0)
+ return NULL;
+
+ return _context_getenv_tzplatform_(id, tizen_platform_config_signup, _context[uid2idx(uid)]);
+}
+
const char* tzplatform_context_getenv(struct tzplatform_context *context, enum tzplatform_variable id)
{
return _context_getenv_tzplatform_(id, tizen_platform_config_signup, context);
return _context_getenv_int_tzplatform_(id, tizen_platform_config_signup, context);
}
-const char* tzplatform_mkstr(enum tzplatform_variable id, const char * str)
+const char* tzplatform_mkstr(enum tzplatform_variable id, const char *str)
{
return _mkstr_tzplatform_(id, str, tizen_platform_config_signup);
}
return _context_mkstr_tzplatform_(id, str, tizen_platform_config_signup, context);
}
-const char* tzplatform_mkpath(enum tzplatform_variable id, const char * path)
+const char* tzplatform_mkpath(enum tzplatform_variable id, const char *path)
{
return _mkpath_tzplatform_(id, path, tizen_platform_config_signup);
}
+const char* tzplatform_uid_mkpath(uid_t uid, enum tzplatform_variable id, const char *path)
+{
+ int ret = init_internal_context(uid);
+ if (ret < 0)
+ return NULL;
+
+ return _context_mkpath_tzplatform_(id, path, tizen_platform_config_signup, _context[uid2idx(uid)]);
+}
+
const char* tzplatform_context_mkpath(struct tzplatform_context *context, enum tzplatform_variable id, const char *path)
{
return _context_mkpath_tzplatform_(id, path, tizen_platform_config_signup, context);
return _mkpath3_tzplatform_(id, path, path2, tizen_platform_config_signup);
}
+const char* tzplatform_uid_mkpath3(uid_t uid, enum tzplatform_variable id, const char *path, const char *path2)
+{
+ int ret = init_internal_context(uid);
+ if (ret < 0)
+ return NULL;
+
+ return _context_mkpath3_tzplatform_(id, path, path2, tizen_platform_config_signup, _context[uid2idx(uid)]);
+}
const char* tzplatform_context_mkpath3(struct tzplatform_context *context, enum tzplatform_variable id, const char *path, const char *path2)
{
return _context_mkpath3_tzplatform_(id, path, path2, tizen_platform_config_signup, context);
return _mkpath4_tzplatform_(id, path, path2, path3, tizen_platform_config_signup);
}
+const char* tzplatform_uid_mkpath4(uid_t uid, enum tzplatform_variable id, const char *path, const char *path2, const char *path3)
+{
+ int ret = init_internal_context(uid);
+ if (ret < 0)
+ return NULL;
+
+ return _context_mkpath4_tzplatform_(id, path, path2, path3, tizen_platform_config_signup, _context[uid2idx(uid)]);
+}
+
const char* tzplatform_context_mkpath4(struct tzplatform_context *context, enum tzplatform_variable id, const char *path, const char *path2, const char *path3)
{
return _context_mkpath4_tzplatform_(id, path, path2, path3, tizen_platform_config_signup, context);
return 0;
}
#endif
-
-
#include <sys/types.h>
#include <tzplatform_variables.h>
-/*------------------------------ COMMON API (no context) ---------------*/
+//=================================================================================
+//======================== COMMON APIs (No context) ===============================
+//=================================================================================
/*
Return the count of variables.
extern
enum tzplatform_variable tzplatform_getid(const char *name);
-/*------------------------------ GLOBAL API (default global context) ----*/
+//=================================================================================
+//====================== GLOBAL APIs (default global context) =====================
+//=================================================================================
/*
Enforces the removal of the previously evaluated tizen platform variables.
*/
extern
const char* tzplatform_mkpath3(enum tzplatform_variable id, const char *path,
- const char *path2);
+ const char *path2);
/*
Return the string resulting of the path-concatenation of string value of the
*/
extern
const char* tzplatform_mkpath4(enum tzplatform_variable id, const char *path,
- const char *path2, const char *path3);
+ const char *path2, const char *path3);
/*
Return the uid for a given user name, stored in variable <id>
extern
gid_t tzplatform_getgid(enum tzplatform_variable id);
-/*------------------------------ CONTEXTUAL API --------------------------*/
+//=================================================================================
+//============================ UID-based APIs =====================================
+//=================================================================================
+
+/*
+ In the following APIs, a 'uid' parameter is added to the form of GLOBAL APIs.
+
+ How-to-use is the same with GLOBAL APIs, but contexts are internally created and set for each uid.
+
+ uid should be one of root(0), owner(5001), and so on.
+*/
+
+extern
+const char* tzplatform_uid_getenv(uid_t uid, enum tzplatform_variable id);
+
+extern
+const char* tzplatform_uid_mkpath(uid_t uid, enum tzplatform_variable id, const char *path);
+
+extern
+const char* tzplatform_uid_mkpath3(uid_t uid, enum tzplatform_variable id, const char *path,
+ const char *path2);
+
+extern
+const char* tzplatform_uid_mkpath4(uid_t uid, enum tzplatform_variable id, const char *path,
+ const char *path2, const char *path3);
+
+//=================================================================================
+//============================ CONTEXTUAL APIs ====================================
+//=================================================================================
struct tzplatform_context;
Can return NULL in case of internal error or when 'id' isn't defined.
*/
extern
-const char* tzplatform_context_getenv(struct tzplatform_context *context, enum tzplatform_variable id);
+const char* tzplatform_context_getenv(struct tzplatform_context *context,
+ enum tzplatform_variable id);
/*
Return the integer value of the tizen plaform variable 'id'.
*/
extern
-int tzplatform_context_getenv_int(struct tzplatform_context *context, enum tzplatform_variable id);
+int tzplatform_context_getenv_int(struct tzplatform_context *context,
+ enum tzplatform_variable id);
/*
Return the string resulting of the concatenation of string value of the
will return "/opt/home-yes"
*/
extern
-const char* tzplatform_context_mkstr(struct tzplatform_context *context, enum tzplatform_variable id, const char *str);
+const char* tzplatform_context_mkstr(struct tzplatform_context *context,
+ enum tzplatform_variable id, const char *str);
/*
Return the string resulting of the path-concatenation of string value of the
will return "/opt/home/yes"
*/
extern
-const char* tzplatform_context_mkpath(struct tzplatform_context *context, enum tzplatform_variable id, const char *path);
+const char* tzplatform_context_mkpath(struct tzplatform_context *context,
+ enum tzplatform_variable id, const char *path);
/*
Return the string resulting of the path-concatenation of string value of the
will return "/opt/home/yes/no"
*/
extern
-const char* tzplatform_context_mkpath3(struct tzplatform_context *context, enum tzplatform_variable id, const char *path,
- const char *path2);
+const char* tzplatform_context_mkpath3(struct tzplatform_context *context,
+ enum tzplatform_variable id, const char *path,
+ const char *path2);
/*
Return the string resulting of the path-concatenation of string value of the
will return "/opt/home/yes/no/maybe"
*/
extern
-const char* tzplatform_context_mkpath4(struct tzplatform_context *context, enum tzplatform_variable id, const char *path,
- const char *path2, const char *path3);
+const char* tzplatform_context_mkpath4(struct tzplatform_context *context,
+ enum tzplatform_variable id, const char *path,
+ const char *path2, const char *path3);
/*
Return the uid for a given user name, stored in variable <id>