67 lines
1.5 KiB
C
67 lines
1.5 KiB
C
#include "../../include/package.h"
|
|
#include "../../include/error.h"
|
|
#include "../../include/util.h"
|
|
|
|
#include <stdbool.h>
|
|
#include <stdlib.h>
|
|
#include <string.h>
|
|
#include <ini.h>
|
|
|
|
int lm_package_data_handler(void *_data, const char *_section, const char *_key, const char *_value) {
|
|
char *section = (char *)_section, *value = (char *)_value, *key = (char *)_key;
|
|
lm_pkg_data_t *data = _data;
|
|
|
|
if(NULL == data->name){
|
|
if(!package_name_valid(section))
|
|
return 0;
|
|
data->name = strdup(section);
|
|
}
|
|
|
|
else if(!eq(data->name, section))
|
|
return 0;
|
|
|
|
if(eq(key, PKG_DATA_DESC))
|
|
data->desc = strdup(value);
|
|
|
|
else if(eq(key, PKG_DATA_VERSION)){
|
|
if(!package_version_valid(value))
|
|
return 0;
|
|
data->version = strdup(value);
|
|
}
|
|
|
|
else if(eq(key, PKG_DATA_SIZE))
|
|
data->size = atol(value);
|
|
|
|
else if(eq(key, PKG_DATA_DEPENDS)){
|
|
if(!lm_package_data_depend_add(data, value))
|
|
return 0;
|
|
}
|
|
|
|
else if(eq(key, PKG_DATA_KEEPS)){
|
|
if(!lm_package_data_keep_add(data, value))
|
|
return 0;
|
|
}
|
|
|
|
return 1;
|
|
}
|
|
|
|
bool lm_package_data_load(lm_pkg_data_t *data, char *file){
|
|
lm_package_data_free(data);
|
|
|
|
if (ini_parse(file, lm_package_data_handler, data) < 0) {
|
|
lm_error_set(LM_ERR_PkgDataBad);
|
|
return false;
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
void lm_package_data_free(lm_pkg_data_t *data){
|
|
free(data->name);
|
|
free(data->desc);
|
|
free(data->version);
|
|
lm_package_data_depend_free(data);
|
|
lm_package_data_keep_free(data);
|
|
bzero(&data, sizeof(lm_pkg_data_t));
|
|
}
|