futility/updater_archive.c
/*
 * Reads and parses a setvars type file from archive, then stores into config.
 * Returns 0 on success (at least one entry found), otherwise failure.
 */
Reads and parses a setvars type file from archive, then stores into config.
Returns 0 on success (at least one entry found), otherwise failure.
Reads and parses a setvars type file from archive then stores into config . Returns 0 on success ( at least one entry found ) otherwise failure .
static int model_config_parse_setvars_file(
		struct model_config *cfg, struct archive *archive,
		const char *fpath)
{
	uint8_t *data;
	uint32_t len;
	char *ptr_line, *ptr_token;
	char *line, *k, *v;
	int valid = 0;
	if (archive_read_file(archive, fpath, &data, &len, NULL) != 0) {
		ERROR("Failed reading: %s\n", fpath);
		return -1;
	}
	if (len)
		data[len - 1] = '\0';
	for (line = strtok_r((char *)data, "\n\r", &ptr_line); line;
	     line = strtok_r(NULL, "\n\r", &ptr_line)) {
		char *expand_path = NULL;
		int found_valid = 1;
		k = strtok_r(line, "=", &ptr_token);
		if (!k)
			continue;
		v = strtok_r(NULL, "\"", &ptr_token);
		if (!v)
			continue;
		if (str_startswith(v, ENV_VAR_MODEL_DIR)) {
			ASPRINTF(&expand_path, "%s/%s%s", DIR_MODELS, cfg->name,
				 v + strlen(ENV_VAR_MODEL_DIR));
		}
		if (strcmp(k, SETVARS_IMAGE_MAIN) == 0)
			cfg->image = strdup(v);
		else if (strcmp(k, SETVARS_IMAGE_EC) == 0)
			cfg->ec_image = strdup(v);
		else if (strcmp(k, SETVARS_IMAGE_PD) == 0)
			cfg->pd_image = strdup(v);
		else if (strcmp(k, SETVARS_SIGNATURE_ID) == 0) {
			cfg->signature_id = strdup(v);
			if (str_startswith(v, SIG_ID_IN_VPD_PREFIX))
				cfg->is_white_label = 1;
		} else
			found_valid = 0;
		free(expand_path);
		valid += found_valid;
	}
	free(data);
	return valid == 0;
}
static int model_config_parse_setvars_file ( struct model_config * cfg , struct archive * archive , const char * fpath ) { uint8_t * data ; uint32_t len ; char * ptr_line , * ptr_token ; char * line , * k , * v ; int valid = 0 ; if ( archive_read_file ( archive , fpath , & data , & len , NULL ) != 0 ) { ERROR ( " \n " , fpath ) ; return -1 ; } if ( len ) data [ len - 1 ] = ' \0 ' ; for ( line = strtok_r ( ( char * ) data , " \n \r " , & ptr_line ) ; line ; line = strtok_r ( NULL , " \n \r " , & ptr_line ) ) { char * expand_path = NULL ; int found_valid = 1 ; k = strtok_r ( line , " " , & ptr_token ) ; if ( ! k ) continue ; v = strtok_r ( NULL , " \" " , & ptr_token ) ; if ( ! v ) continue ; if ( str_startswith ( v , ENV_VAR_MODEL_DIR ) ) { ASPRINTF ( & expand_path , " " , DIR_MODELS , cfg -> name , v + strlen ( ENV_VAR_MODEL_DIR ) ) ; } if ( strcmp ( k , SETVARS_IMAGE_MAIN ) == 0 ) cfg -> image = strdup ( v ) ; else if ( strcmp ( k , SETVARS_IMAGE_EC ) == 0 ) cfg -> ec_image = strdup ( v ) ; else if ( strcmp ( k , SETVARS_IMAGE_PD ) == 0 ) cfg -> pd_image = strdup ( v ) ; else if ( strcmp ( k , SETVARS_SIGNATURE_ID ) == 0 ) { cfg -> signature_id = strdup ( v ) ; if ( str_startswith ( v , SIG_ID_IN_VPD_PREFIX ) ) cfg -> is_white_label = 1 ; } else found_valid = 0 ; free ( expand_path ) ; valid += found_valid ; } free ( data ) ; return valid == 0 ; }
Reads and parses a setvars type file from archive, then stores into config.
Reads and parses a setvars type file from archive then stores into config .
/* Valid content should end with \n, or \"; ensure ASCIIZ for parsing */ /* Format: KEY="value" */ /* Some legacy updaters may be still using ${MODEL_DIR}. */