#define MC_CLIENT "mcclient"
#define MC_SERVER "mcserver"
-#define MC_DEFAULT_TYPE 0
-#define MC_CLIENT_TYPE 1
-#define MC_SEVER_TYPE 2
-
#define MC_DBUS_SIGNAL_NAME_SERVER_STATE "server_state"
#define MC_DBUS_SIGNAL_NAME_PLAY_BACK "playback"
#define MC_DBUS_SIGNAL_NAME_METADATA "metadata"
int mc_util_get_own_name(char **name);
char* mc_util_get_interface_name(const char *type, const char *name);
int mc_util_make_filter_interface_name(const char *prefix, const char *filter, char **interface_name);
-int mc_util_set_command_available(const char *name, const char *command_type, const char *command);
-int mc_util_get_command_available(const char *name, const char *command_type, const char *command);
+int mc_util_set_command_available(mc_priv_type_e priv_type, const char *name, const char *command_type, const char *command);
+int mc_util_get_command_available(mc_priv_type_e priv_type, const char *name, const char *command_type, const char *command);
int mc_util_get_request_id(unsigned int *req_id);
int mc_util_bundle_to_string(bundle *bundle_data, char **str_data);
int mc_safe_strtoi(const char *buffer, int *value);
int mc_ipc_unregister_listener(GList **manage_list, GDBusConnection *connection, const char *interface_name, const char *signal_name);
int mc_ipc_unregister_all_listener(GList **manage_list, GDBusConnection *connection);
int mc_ipc_send_message(GDBusConnection *connection, const char *dbus_name, const char *interface_name, const char* signal_name, const char* message, unsigned int *request_id);
-int mc_ipc_send_message_to_server(mc_msg_type_e msg_type, const int type, const char *request_msg);
-int mc_ipc_service_connect(const int type);
+int mc_ipc_send_message_to_server(mc_msg_type_e msg_type, mc_priv_type_e priv_type, const char *request_msg);
+int mc_ipc_service_connect(mc_priv_type_e type);
#ifdef __cplusplus
}
Name: capi-media-controller
Summary: A media controller library in Tizen Native API
-Version: 0.1.59
+Version: 0.1.60
Release: 1
Group: Multimedia/API
License: Apache-2.0
mc_retvm_if(ret != MEDIA_CONTROLLER_ERROR_NONE, ret, "Error mc_db_check_server_table_exist [%d]", ret);
mc_retvm_if(exist_server == FALSE, MEDIA_CONTROLLER_ERROR_INVALID_PARAMETER, "Error Invalid server_name");
- ret = mc_util_set_command_available(mc_client->client_name, command_type, command);
+ ret = mc_util_set_command_available(MC_PRIV_TYPE_CLIENT, mc_client->client_name, command_type, command);
mc_retvm_if(ret != MEDIA_CONTROLLER_ERROR_NONE, ret, "Error mc_util_set_command_available [%d]", ret);
interface_name = mc_util_get_interface_name(MC_SERVER, server_name);
mc_retvm_if(client == NULL, MEDIA_CONTROLLER_ERROR_INVALID_PARAMETER, "Handle is NULL");
/*Try Socket Activation by systemd*/
- ret = mc_ipc_service_connect(MC_CLIENT_TYPE);
+ ret = mc_ipc_service_connect(MC_PRIV_TYPE_CLIENT);
if (ret != MEDIA_CONTROLLER_ERROR_NONE) {
mc_error("Failed to get mc_ipc_service_connect [%d]", ret);
return ret;
mc_error("Error mc_ipc_unregister_all_listener [%d]", ret);
/*Send Disconnection Msg to Server*/
- ret = mc_ipc_send_message_to_server(MC_MSG_SERVER_DISCONNECTION, MC_CLIENT_TYPE, MC_SERVER_DISCONNECTION_MSG);
+ ret = mc_ipc_send_message_to_server(MC_MSG_SERVER_DISCONNECTION, MC_PRIV_TYPE_CLIENT, MC_SERVER_DISCONNECTION_MSG);
if (ret != MEDIA_CONTROLLER_ERROR_NONE)
mc_error("Failed to mc_ipc_send_message_to_server [%d]", ret);
return 100 - count;
}
-static int __mc_db_update_db(void *handle, const char *sql_str)
+static int __mc_db_update_db(void *handle, mc_priv_type_e priv_type, const char *sql_str)
{
int ret = MEDIA_CONTROLLER_ERROR_NONE;
mc_retvm_if(!MC_STRING_VALID(sql_str), MEDIA_CONTROLLER_ERROR_INVALID_PARAMETER, "Invalid Query");
- ret = mc_ipc_send_message_to_server(MC_MSG_DB_UPDATE, MC_DEFAULT_TYPE, sql_str);
+ ret = mc_ipc_send_message_to_server(MC_MSG_DB_UPDATE, priv_type, sql_str);
if (ret != MEDIA_CONTROLLER_ERROR_NONE)
mc_error("mc_ipc_send_message_to_server failed : %d", ret);
index);
mc_retvm_if(sql_str == NULL, MEDIA_CONTROLLER_ERROR_INVALID_OPERATION, "fail making sql_str");
- ret = __mc_db_update_db(handle, sql_str);
+ ret = __mc_db_update_db(handle, MC_PRIV_TYPE_SERVER, sql_str);
MC_SAFE_FREE(sql_str);
picture);
- ret = __mc_db_update_db(handle, sql_str);
+ ret = __mc_db_update_db(handle, MC_PRIV_TYPE_SERVER, sql_str);
MC_SAFE_FREE(sql_str);
sql_str = g_strdup_printf("%s%s%s%s%d", MC_DB_CMD_UPDATE_SHUFFLE, MC_STRING_DELIMITER, server_name, MC_STRING_DELIMITER, shuffle_mode);
- ret = __mc_db_update_db(handle, sql_str);
+ ret = __mc_db_update_db(handle, MC_PRIV_TYPE_SERVER, sql_str);
MC_SAFE_FREE(sql_str);
sql_str = g_strdup_printf("%s%s%s%s%d", MC_DB_CMD_UPDATE_REPEAT, MC_STRING_DELIMITER, server_name, MC_STRING_DELIMITER, repeat_mode);
- ret = __mc_db_update_db(handle, sql_str);
+ ret = __mc_db_update_db(handle, MC_PRIV_TYPE_SERVER, sql_str);
MC_SAFE_FREE(sql_str);
sql_str = g_strdup_printf("%s%s%s", MC_DB_CMD_UPDATE_SERVER_LIST, MC_STRING_DELIMITER, address);
- ret = __mc_db_update_db(handle, sql_str);
+ ret = __mc_db_update_db(handle, MC_PRIV_TYPE_SERVER, sql_str);
MC_SAFE_FREE(sql_str);
sql_str = g_strdup_printf("%s%s%s", MC_DB_CMD_REMOVE_SERVER_LIST, MC_STRING_DELIMITER, address);
- ret = __mc_db_update_db(handle, sql_str);
+ ret = __mc_db_update_db(handle, MC_PRIV_TYPE_SERVER, sql_str);
MC_SAFE_FREE(sql_str);
sql_str = g_strdup_printf("%s%s%s", MC_DB_CMD_CREATE_SERVER, MC_STRING_DELIMITER, server_name);
- ret = __mc_db_update_db(handle, sql_str);
+ ret = __mc_db_update_db(handle, MC_PRIV_TYPE_SERVER, sql_str);
MC_SAFE_FREE(sql_str);
sql_str = g_strdup_printf("%s%s%s", MC_DB_CMD_REMOVE_SERVER, MC_STRING_DELIMITER, server_name);
- ret = __mc_db_update_db(handle, sql_str);
+ ret = __mc_db_update_db(handle, MC_PRIV_TYPE_SERVER, sql_str);
MC_SAFE_FREE(sql_str);
sql_str = g_strdup_printf("%s%s%s%s%d%s%d", MC_DB_CMD_UPDATE_STATE_PLAYBACK, MC_STRING_DELIMITER, server_name, MC_STRING_DELIMITER, server_state, MC_STRING_DELIMITER, playback_state);
- ret = __mc_db_update_db(handle, sql_str);
+ ret = __mc_db_update_db(handle, MC_PRIV_TYPE_SERVER, sql_str);
MC_SAFE_FREE(sql_str);
sql_str = g_strdup_printf("%s%s%s", MC_DB_CMD_UPDATE_LATEST, MC_STRING_DELIMITER, server_name);
- ret = __mc_db_update_db(handle, sql_str);
+ ret = __mc_db_update_db(handle, MC_PRIV_TYPE_SERVER, sql_str);
MC_SAFE_FREE(sql_str);
sql_str = g_strdup_printf("%s%s%s", MC_DB_CMD_REMOVE_PLAYLIST, MC_STRING_DELIMITER, server_name);
- ret = __mc_db_update_db(handle, sql_str);
+ ret = __mc_db_update_db(handle, MC_PRIV_TYPE_SERVER, sql_str);
MC_SAFE_FREE(sql_str);
sql_str = g_strdup_printf("%s%s%s%s%s%s%s%s%d", MC_DB_CMD_UPDATE_PLAYLIST, MC_STRING_DELIMITER, server_name,
MC_STRING_DELIMITER, playlist_name, MC_STRING_DELIMITER, raw_data, MC_STRING_DELIMITER, size_r);
- ret = __mc_db_update_db(handle, sql_str);
+ ret = __mc_db_update_db(handle, MC_PRIV_TYPE_SERVER, sql_str);
MC_SAFE_FREE(raw_data);
MC_SAFE_FREE(sql_str);
#define MC_SVC_NAME "mediacontroller"
/* This checks if service daemon is running */
-static int __is_service_activated(const int type)
+static int __is_service_activated(mc_priv_type_e priv_type)
{
int ret = MEDIA_CONTROLLER_ERROR_NONE;
- ret = mc_ipc_send_message_to_server(MC_MSG_SERVER_CONNECTION, type, MC_SERVER_CONNECTION_MSG);
+ ret = mc_ipc_send_message_to_server(MC_MSG_SERVER_CONNECTION, priv_type, MC_SERVER_CONNECTION_MSG);
return ret;
}
return MEDIA_CONTROLLER_ERROR_NONE;
}
-int mc_ipc_send_message_to_server(mc_msg_type_e msg_type, const int type, const char *request_msg)
+int mc_ipc_send_message_to_server(mc_msg_type_e msg_type, mc_priv_type_e priv_type, const char *request_msg)
{
int ret = MEDIA_CONTROLLER_ERROR_NONE;
int request_msg_size = 0;
return MEDIA_CONTROLLER_ERROR_INVALID_PARAMETER;
}
- mc_secure_debug("type [%d], message [%s]", type, request_msg);
+ mc_secure_debug("msg_type[%d] priv_type[%d], message[%s]", msg_type, priv_type, request_msg);
mc_comm_msg_s send_msg;
memset((void *)&send_msg, 0, sizeof(mc_comm_msg_s));
send_msg.msg_type = msg_type;
- send_msg.type = type;
+ send_msg.priv_type = priv_type;
send_msg.pid = getpid();
send_msg.uid = getuid();
send_msg.msg_size = request_msg_size;
return ret;
}
-int mc_ipc_service_connect(const int type)
+int mc_ipc_service_connect(mc_priv_type_e priv_type)
{
int ret = MEDIA_CONTROLLER_ERROR_NONE;
int sockfd = -1;
struct sockaddr_un serv_addr;
unsigned int retrycount = 0;
- ret = __is_service_activated(type);
+ ret = __is_service_activated(priv_type);
if (ret == MEDIA_CONTROLLER_ERROR_NONE) {
mc_debug("service is already running!");
close(sockfd);
- ret = __is_service_activated(type);
+ ret = __is_service_activated(priv_type);
if (ret == MEDIA_CONTROLLER_ERROR_PERMISSION_DENIED) {
mc_error("Permission deny!");
return ret;
while ((ret != MEDIA_CONTROLLER_ERROR_NONE) && (retrycount++ < MAX_WAIT_COUNT)) {
MC_MILLISEC_SLEEP(200);
mc_error("[No-Error] retry count [%d]", retrycount);
- ret = __is_service_activated(type);
+ ret = __is_service_activated(priv_type);
if (ret == MEDIA_CONTROLLER_ERROR_PERMISSION_DENIED) {
mc_error("Permission deny!");
return ret;
params = g_strsplit(message, MC_STRING_DELIMITER, 0);
mc_retm_if(params == NULL, "invalid playback state command");
- if (mc_util_get_command_available(params[0], MC_COMMAND_PLAYBACKSTATE, NULL) != MEDIA_CONTROLLER_ERROR_NONE) {
+ if (mc_util_get_command_available(MC_PRIV_TYPE_SERVER, params[0], MC_COMMAND_PLAYBACKSTATE, NULL) != MEDIA_CONTROLLER_ERROR_NONE) {
mc_error("Error permission denied");
g_strfreev(params);
return;
params = g_strsplit(message, MC_STRING_DELIMITER, 0);
mc_retm_if(params == NULL, "invalid playback_action command");
- if (mc_util_get_command_available(params[0], MC_COMMAND_PLAYBACKACTION, NULL) != MEDIA_CONTROLLER_ERROR_NONE) {
+ if (mc_util_get_command_available(MC_PRIV_TYPE_SERVER, params[0], MC_COMMAND_PLAYBACKACTION, NULL) != MEDIA_CONTROLLER_ERROR_NONE) {
mc_error("Error permission denied");
g_strfreev(params);
return;
params = g_strsplit(message, MC_STRING_DELIMITER, 0);
mc_retm_if(params == NULL, "invalid playback_position command");
- if (mc_util_get_command_available(params[0], MC_COMMAND_PLAYBACKPOSITION, NULL) != MEDIA_CONTROLLER_ERROR_NONE) {
+ if (mc_util_get_command_available(MC_PRIV_TYPE_SERVER, params[0], MC_COMMAND_PLAYBACKPOSITION, NULL) != MEDIA_CONTROLLER_ERROR_NONE) {
mc_error("Error permission denied");
g_strfreev(params);
return;
params = g_strsplit(message, MC_STRING_DELIMITER, 0);
mc_retm_if(params == NULL, "invalid shuffle_mode command");
- if (mc_util_get_command_available(params[0], MC_COMMAND_SHUFFLE, NULL) != MEDIA_CONTROLLER_ERROR_NONE) {
+ if (mc_util_get_command_available(MC_PRIV_TYPE_SERVER, params[0], MC_COMMAND_SHUFFLE, NULL) != MEDIA_CONTROLLER_ERROR_NONE) {
mc_error("Error permission denied");
g_strfreev(params);
return;
params = g_strsplit(message, MC_STRING_DELIMITER, 0);
mc_retm_if(params == NULL, "invalid repeat_mode command");
- if (mc_util_get_command_available(params[0], MC_COMMAND_REPEAT, NULL) != MEDIA_CONTROLLER_ERROR_NONE) {
+ if (mc_util_get_command_available(MC_PRIV_TYPE_SERVER, params[0], MC_COMMAND_REPEAT, NULL) != MEDIA_CONTROLLER_ERROR_NONE) {
mc_error("Error permission denied");
g_strfreev(params);
return;
if (params[0])
sender = strdup(params[0]);
- if (mc_util_get_command_available(sender, MC_COMMAND_CUSTOM, params[1]) != MEDIA_CONTROLLER_ERROR_NONE) {
+ if (mc_util_get_command_available(MC_PRIV_TYPE_SERVER, sender, MC_COMMAND_CUSTOM, params[1]) != MEDIA_CONTROLLER_ERROR_NONE) {
mc_error("Error permission denied");
MC_SAFE_FREE(sender);
g_strfreev(params);
params = g_strsplit(message, MC_STRING_DELIMITER, 0);
mc_retm_if(params == NULL, "invalid play_playlist command");
- if (mc_util_get_command_available(params[0], MC_COMMAND_PLAY_PLAYLIST, NULL) != MEDIA_CONTROLLER_ERROR_NONE) {
+ if (mc_util_get_command_available(MC_PRIV_TYPE_SERVER, params[0], MC_COMMAND_PLAY_PLAYLIST, NULL) != MEDIA_CONTROLLER_ERROR_NONE) {
mc_error("Error permission denied");
g_strfreev(params);
return;
mc_retvm_if(server == NULL, MEDIA_CONTROLLER_ERROR_INVALID_PARAMETER, "Handle is null");
/*Try Socket Activation by systemd*/
- ret = mc_ipc_service_connect(MC_SEVER_TYPE);
+ ret = mc_ipc_service_connect(MC_PRIV_TYPE_SERVER);
if (ret != MEDIA_CONTROLLER_ERROR_NONE) {
mc_error("Failed to get mc_ipc_service_connect [%d]", ret);
return ret;
mc_error("Error __mc_server_send_message [%d]", ret);
/*Send Disconnection Msg to Server*/
- ret = mc_ipc_send_message_to_server(MC_MSG_SERVER_DISCONNECTION, MC_SEVER_TYPE, MC_SERVER_DISCONNECTION_MSG);
+ ret = mc_ipc_send_message_to_server(MC_MSG_SERVER_DISCONNECTION, MC_PRIV_TYPE_SERVER, MC_SERVER_DISCONNECTION_MSG);
if (ret != MEDIA_CONTROLLER_ERROR_NONE)
mc_error("Failed to mc_ipc_send_message_to_server [%d]", ret);
return MEDIA_CONTROLLER_ERROR_NONE;
}
-int mc_util_set_command_available(const char *name, const char *command_type, const char *command)
+int mc_util_set_command_available(mc_priv_type_e priv_type, const char *name, const char *command_type, const char *command)
{
int ret = MEDIA_CONTROLLER_ERROR_NONE;
char *message = NULL;
else
message = g_strdup_printf("%s%s%s", name, command_type, command);
- ret = mc_ipc_send_message_to_server(MC_MSG_CLIENT_SET, MC_DEFAULT_TYPE, message);
+ ret = mc_ipc_send_message_to_server(MC_MSG_CLIENT_SET, priv_type, message);
MC_SAFE_G_FREE(message);
return ret;
}
-int mc_util_get_command_available(const char *name, const char *command_type, const char *command)
+int mc_util_get_command_available(mc_priv_type_e priv_type, const char *name, const char *command_type, const char *command)
{
int ret = MEDIA_CONTROLLER_ERROR_NONE;
char *message = NULL;
else
message = g_strdup_printf("%s%s%s", name, command_type, command);
- ret = mc_ipc_send_message_to_server(MC_MSG_CLIENT_GET, MC_DEFAULT_TYPE, message);
+ ret = mc_ipc_send_message_to_server(MC_MSG_CLIENT_GET, priv_type, message);
MC_SAFE_G_FREE(message);
MC_MSG_MAX,
} mc_msg_type_e;
+typedef enum {
+ MC_PRIV_TYPE_SERVER = 0,
+ MC_PRIV_TYPE_CLIENT,
+} mc_priv_type_e;
+
typedef struct {
mc_msg_type_e msg_type;
- int type;
+ mc_priv_type_e priv_type;
int pid;
uid_t uid;
int result;
#endif /* __cplusplus */
typedef struct {
- int pid;
- int type;
- GList *s_data;
-} mc_list_data_set_t;
-
-typedef struct {
GQueue *queue;
GSource *source;
} mc_manage_queue_t;
typedef struct {
int client_sock;
- int permission;
mc_comm_msg_s *req_msg;
} mc_service_request;
unsigned int result;
} mc_list_user_data;
+typedef struct {
+ int pid;
+ mc_priv_type_e priv_type;
+ GList *s_data;
+} mc_list_data_set_t;
+
static int __mc_sys_get_uid(uid_t *uid)
{
uid_t *list = NULL;
return TRUE;
}
-static int _mc_service_get_list_index(GList *list, int pid, int type)
+static int _mc_service_get_list_index(GList *list, int pid, mc_priv_type_e priv_type)
{
unsigned int length_of_list = 0;
unsigned int i;
if (ptr == NULL)
return -1;
if (ptr->pid == pid) {
- if (type == MC_DEFAULT_TYPE)
- return i;
- if (ptr->type == type)
+ if (ptr->priv_type == priv_type)
return i;
}
}
return -1;
}
-static gboolean _mc_service_is_exist_pid(GList *list, int pid, int type)
+static gboolean _mc_service_is_exist_pid(GList *list, int pid, mc_priv_type_e priv_type)
{
- int res = _mc_service_get_list_index(list, pid, type);
+ int res = _mc_service_get_list_index(list, pid, priv_type);
return (res == -1) ? FALSE : TRUE;
}
if (request_msg->msg_type != MC_MSG_SERVER_CONNECTION) {
if (connected_list == NULL)
return FALSE;
- if (!_mc_service_is_exist_pid(connected_list, request_msg->pid, request_msg->type))
+ if (!_mc_service_is_exist_pid(connected_list, request_msg->pid, request_msg->priv_type))
return FALSE;
}
return TRUE;
mc_list_data_set_t *data = NULL;
- if (*connected_list != NULL && _mc_service_is_exist_pid(*connected_list, request_msg->pid, request_msg->type)) {
- mc_error("[No-error] connected but do not increase counter [%d]", g_connection_cnt);
+ mc_retvm_if(request_msg == NULL, MEDIA_CONTROLLER_ERROR_INVALID_PARAMETER, "request_msg is NULL");
+ mc_retvm_if(((request_msg->priv_type != MC_PRIV_TYPE_SERVER) && (request_msg->priv_type != MC_PRIV_TYPE_CLIENT)), MEDIA_CONTROLLER_ERROR_INVALID_PARAMETER, "invalid priv_type[%d]", request_msg->priv_type);
+
+ if (*connected_list != NULL && _mc_service_is_exist_pid(*connected_list, request_msg->pid, request_msg->priv_type)) {
+ mc_error("Already connected[%d]", g_connection_cnt);
return MEDIA_CONTROLLER_ERROR_INVALID_PARAMETER;
}
}
data->pid = request_msg->pid;
- data->type = request_msg->type;
+ data->priv_type = request_msg->priv_type;
*connected_list = g_list_append(*connected_list, data);
if (g_connection_cnt == -1)
g_connection_cnt++;
mc_error("[No-error] increased connection count [%d]", g_connection_cnt);
+
mc_debug_fleave();
+
return MEDIA_CONTROLLER_ERROR_NONE;
}
{
mc_debug_fenter();
- int idx = _mc_service_get_list_index(*connected_list, request_msg->pid, request_msg->type);
+ int idx = _mc_service_get_list_index(*connected_list, request_msg->pid, request_msg->priv_type);
if (idx == -1) {
mc_error("node is null, it is already disconnected!");
return MEDIA_CONTROLLER_ERROR_NONE;
goto ERROR;
}
- ret = mc_cynara_check(&creds, MC_SERVER_PRIVILEGE);
- if (ret != MEDIA_CONTROLLER_ERROR_NONE) {
- mc_error("permission is denied![%d]", ret);
+ if (recv_msg.priv_type == MC_PRIV_TYPE_SERVER) {
+ ret = mc_cynara_check(&creds, MC_SERVER_PRIVILEGE);
+ } else if (recv_msg.priv_type == MC_PRIV_TYPE_CLIENT) {
ret = mc_cynara_check(&creds, MC_CLIENT_PRIVILEGE);
- if (ret != MEDIA_CONTROLLER_ERROR_NONE) {
- mc_error("permission is denied![%d]", ret);
-
- send_msg = MEDIA_CONTROLLER_ERROR_PERMISSION_DENIED;
- goto ERROR;
- } else {
- req->permission = 2;
- }
} else {
- req->permission = 1;
+ mc_error("wroing priv_type[%d]", recv_msg.priv_type);
+ send_msg = MEDIA_CONTROLLER_ERROR_INVALID_OPERATION;
+ goto ERROR;
+ }
+
+ if (ret != MEDIA_CONTROLLER_ERROR_NONE) {
+ mc_error("permission is denied![%d]", ret);
+ send_msg = MEDIA_CONTROLLER_ERROR_PERMISSION_DENIED;
+ goto ERROR;
}
if (recv_msg.msg_type >= 0 && recv_msg.msg_type < MC_MSG_MAX) {