const char * get_network_ip(void) { const char * ip = get_kcmdline_string(NETWORK_IP_KEY); if (ip != NULL) return(ip); return(get_conf_string(NETWORK_ENTRY, NETWORK_IP_KEY)); }
char * get_network_gateway(void) { char * gw = get_kcmdline_string(NETWORK_GATEWAY_KEY); if (gw != NULL) return(gw); return(get_conf_string(NETWORK_ENTRY, NETWORK_GATEWAY_KEY)); }
char * get_mode_setting(void) { char * mode = get_kcmdline_string(MODE_SETTING_KEY); if (mode != NULL) return(mode); return(get_conf_string(MODE_SETTING_ENTRY, MODE_SETTING_KEY)); }
const char *find_mounts(void) { const char *ret = NULL; ret = get_conf_string(FS_MOUNT_ENTRY, FS_MOUNT_KEY); if(ret == NULL) { ret = g_strdup(FS_MOUNT_DEFAULT); log_debug("Default mount = %s\n", ret); } return(ret); }
char * get_android_product_id(void) { return(get_conf_string(ANDROID_ENTRY, ANDROID_PRODUCT_ID_KEY)); }
char * get_android_vendor_id(void) { return(get_conf_string(ANDROID_ENTRY, ANDROID_VENDOR_ID_KEY)); }
char * get_android_manufacturer(void) { return(get_conf_string(ANDROID_ENTRY, ANDROID_MANUFACTURER_KEY)); }
int conf_file_merge(void) { GDir *confdir; struct stat fileinfo, dir; char *mode = 0, *ip = 0, *gateway = 0, *udev = 0; gchar *filename_full; const gchar *filename; GString *keyfile_string = NULL; GKeyFile *settingsfile; int ret = 0, test = 0, conffile_created = 0; confdir = g_dir_open(CONFIG_FILE_DIR, 0, NULL); if(!confdir) { log_debug("No configuration. Creating defaults.\n"); create_conf_file(); /* since there was no configuration at all there is no info to be merged */ return (ret); } if (stat(FS_MOUNT_CONFIG_FILE, &fileinfo) == -1) { /* conf file not created yet, make default and merge all */ create_conf_file(); conffile_created = 1; } /* config file is created, so the dir must exists */ if(stat(CONFIG_FILE_DIR, &dir)) { log_warning("Directory still does not exists. FS might be ro/corrupted!\n"); ret = 1; goto end; } /* st_mtime is changed by file modifications, st_mtime of a directory is changed by the creation or deletion of files in that directory. So if the st_mtime of the config file is equal to the directory time we can be sure the config is untouched and we do not need to re-merge the config. */ if(fileinfo.st_mtime == dir.st_mtime) { /* if a conffile was created, the st_mtime would have been updated so this check will miss information that might be there already, like after a config file removal for example. So we run a merge anyway if we needed to create the conf file */ if(!conffile_created) goto end; } log_debug("Merging/creating configuration.\n"); keyfile_string = g_string_new(NULL); /* check each ini file and get contents */ while((filename = g_dir_read_name(confdir)) != NULL) { if(!strstr(filename, ".ini")) { /* skip this file as it might be a dir or not an ini file */ continue; } filename_full = g_strconcat(CONFIG_FILE_DIR, "/", filename, NULL); log_debug("filename = %s\n", filename_full); if(!strcmp(filename_full, FS_MOUNT_CONFIG_FILE)) { /* store mode info to add it later as we want to keep it */ mode = get_mode_setting(); /* store udev path (especially important for the upgrade path */ udev = find_udev_path(); ip = get_conf_string(NETWORK_ENTRY, NETWORK_IP_KEY); gateway = get_conf_string(NETWORK_ENTRY, NETWORK_GATEWAY_KEY); continue; } /* load contents of file, if it fails skip to next one */ settingsfile = g_key_file_new(); test = g_key_file_load_from_file(settingsfile, filename_full, G_KEY_FILE_KEEP_COMMENTS, NULL); if(!test) { log_debug("%d failed loading config file %s\n", test, filename_full); goto next; } log_debug("file data = %s\n", g_key_file_to_data(settingsfile, NULL, NULL)); keyfile_string = g_string_append(keyfile_string, g_key_file_to_data(settingsfile, NULL, NULL)); log_debug("keyfile_string = %s\n", keyfile_string->str); g_key_file_free(settingsfile); next: g_free(filename_full); } if(keyfile_string) { /* write out merged config file */ /* g_file_set_contents returns 1 on succes, this function returns 0 */ ret = !g_file_set_contents(FS_MOUNT_CONFIG_FILE, keyfile_string->str, -1, NULL); g_string_free(keyfile_string, TRUE); if(mode) { set_mode_setting(mode); } if(udev) { set_config_setting(UDEV_PATH_ENTRY, UDEV_PATH_KEY, udev); } /* check if no network data came from an ini file */ if( get_conf_string(NETWORK_ENTRY, NETWORK_IP_KEY)) goto cleanup; if(ip) set_network_setting(NETWORK_IP_KEY, ip); if(gateway) set_network_setting(NETWORK_GATEWAY_KEY, gateway); } else ret = 1; cleanup: if(mode) free(mode); if(udev) free(udev); if(ip) free(ip); if(gateway) free(gateway); end: g_dir_close(confdir); return(ret); }
char * find_udev_subsystem(void) { return(get_conf_string(UDEV_PATH_ENTRY, UDEV_SUBSYSTEM_KEY)); }
char * get_trigger_value(void) { return(get_conf_string(TRIGGER_ENTRY, TRIGGER_PROPERTY_VALUE_KEY)); }
char * get_trigger_property(void) { return(get_conf_string(TRIGGER_ENTRY, TRIGGER_PROPERTY_KEY)); }
char * get_trigger_mode(void) { return(get_conf_string(TRIGGER_ENTRY, TRIGGER_MODE_KEY)); }
char * get_trigger_subsystem(void) { return(get_conf_string(TRIGGER_ENTRY, TRIGGER_UDEV_SUBSYSTEM)); }
const char * find_cdrom_path(void) { return(get_conf_string(CDROM_ENTRY, CDROM_PATH_KEY)); }
const char * find_alt_mount(void) { return(get_conf_string(ALT_MOUNT_ENTRY, ALT_MOUNT_KEY)); }
char * find_udev_path(void) { return(get_conf_string(UDEV_PATH_ENTRY, UDEV_PATH_KEY)); }
char * get_network_nat_interface(void) { return(get_conf_string(NETWORK_ENTRY, NETWORK_NAT_INTERFACE_KEY)); }
char * check_trigger(void) { return(get_conf_string(TRIGGER_ENTRY, TRIGGER_PATH_KEY)); }
const char * get_soft_connect_path(void) { return(get_conf_string(SOFT_CONNECT_ENTRY, SOFT_CONNECT_PATH_KEY)); }