#include <string.h>
#include <errno.h>
#include <stdbool.h>
+#include <unistd.h>
#include <libsyscommon/ini-parser.h>
#include <libsyscommon/list.h>
return false;
}
-static void parse_input_device_property(gpointer data, gpointer user_data)
+static int parse_input_device_property(gpointer data, gpointer user_data)
{
struct section_property *prop = (struct section_property *) data;
struct input_device_info *input_dev_info = *(struct input_device_info **)user_data;
if (!prop || !input_dev_info)
- return;
+ return 0;
if (MATCH(prop->key, "InputDeviceType")) {
if (MATCH(prop->value, "unknown"))
input_dev_info->input_device_type = (int)HAL_DEVICE_INPUT_TYPE_KEYBOARD;
else if (MATCH(prop->value, "custom_knob"))
input_dev_info->input_device_type = (int)HAL_DEVICE_INPUT_TYPE_CUSTOM_KNOB;
+ else
+ return -EPERM;
} else if (MATCH(prop->key, "InputDeviceId")) {
sscanf(prop->value, "%d", (&input_dev_info->input_device_id));
} else if (MATCH(prop->key, "InputDeviceName")) {
input_dev_info->input_device_default = 1;
else if (MATCH(prop->value, "no"))
input_dev_info->input_device_default = 0;
+ else
+ return -EPERM;
}
+ return 0;
}
static int parse_input_device_section(const struct parse_result *result, void *data)
{
struct input_device_info *input_dev_info;
+ struct section_property *temp_section_prop;
+ GList *temp_glist;
int ret;
if (!result || !result->props)
if (!input_dev_info)
return -ENOMEM;
- g_list_foreach(result->props, parse_input_device_property, &input_dev_info);
+ SYS_G_LIST_FOREACH(result->props, temp_glist, temp_section_prop) {
+ if (parse_input_device_property(temp_section_prop, &input_dev_info) < 0)
+ return -EPERM;
+ }
+
if (input_dev_info->input_device_default == 1) {
if (is_default_input_device_duplicated(input_dev_info->input_device_type))
return -EPERM;
g_hash_table_to_check_default_duplicated = g_hash_table_new_full(g_int_hash, g_int_equal,
g_free, g_free);
+ if (access(INPUT_CONF_PATH, F_OK) == -1)
+ return 0;
+
ret = libsys_config_parse_by_section(INPUT_CONF_PATH, parse_input_device_section, NULL);
if (g_hash_table_to_check_default_duplicated) {