new: implement PULL command, add join functions
This commit is contained in:
63
src/package/data.c
Normal file
63
src/package/data.c
Normal file
@ -0,0 +1,63 @@
|
||||
#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_t *pkg = data;
|
||||
|
||||
if(NULL == pkg->name){
|
||||
if(!package_name_valid(section))
|
||||
return 0;
|
||||
pkg->name = strdup(section);
|
||||
}
|
||||
|
||||
else if(!eq(pkg->name, section))
|
||||
return 0;
|
||||
|
||||
if(eq(key, PKG_DATA_DESC))
|
||||
pkg->desc = strdup(value);
|
||||
|
||||
else if(eq(key, PKG_DATA_VERSION)){
|
||||
if(!package_version_valid(value))
|
||||
return 0;
|
||||
pkg->version = strdup(value);
|
||||
}
|
||||
|
||||
else if(eq(key, PKG_DATA_SIZE))
|
||||
pkg->size = atol(value);
|
||||
|
||||
else if(eq(key, PKG_DATA_DEPENDS)){
|
||||
if(!lm_package_depend_add(pkg, value))
|
||||
return 0;
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
bool lm_package_data_load(lm_pkg_t *pkg, char *file){
|
||||
lm_package_data_free(pkg);
|
||||
|
||||
if (ini_parse(file, lm_package_data_handler, pkg) < 0) {
|
||||
lm_error_set(LM_ERR_PkgDataBad);
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void lm_package_data_free(lm_pkg_t *pkg){
|
||||
free(pkg->desc);
|
||||
free(pkg->name);
|
||||
free(pkg->version);
|
||||
|
||||
if(NULL != pkg->depends){
|
||||
for(int i = 0; pkg->depends[i] != NULL; i++)
|
||||
free(pkg->depends[i]);
|
||||
}
|
||||
}
|
44
src/package/depend.c
Normal file
44
src/package/depend.c
Normal file
@ -0,0 +1,44 @@
|
||||
#include "../../include/package.h"
|
||||
#include "../../include/error.h"
|
||||
#include "../../include/types.h"
|
||||
#include "../../include/util.h"
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
size_t lm_package_depend_count(lm_pkg_t *pkg){
|
||||
size_t index = 0;
|
||||
|
||||
if(NULL == pkg->depends)
|
||||
return 0;
|
||||
|
||||
while(pkg->depends[index] != NULL)
|
||||
index++;
|
||||
|
||||
return index;
|
||||
}
|
||||
|
||||
bool lm_package_depend_add(lm_pkg_t *pkg, char *depend){
|
||||
if(NULL == depend){
|
||||
lm_error_set(LM_ERR_ArgNULL);
|
||||
return false;
|
||||
}
|
||||
|
||||
if(!package_name_valid(depend)){
|
||||
lm_error_set(LM_ERR_PkgBadName);
|
||||
return false;
|
||||
}
|
||||
|
||||
if(NULL == pkg->depends){
|
||||
pkg->depends = malloc(sizeof(char*)*2);
|
||||
pkg->depends[0] = strdup(depend);
|
||||
pkg->depends[1] = NULL;
|
||||
return true;
|
||||
}
|
||||
|
||||
size_t count = lm_package_depend_count(pkg);
|
||||
pkg->depends = realloc(pkg->depends, sizeof(char*)*(count+2));
|
||||
pkg->depends[count++] = strdup(depend);
|
||||
pkg->depends[count] = NULL;
|
||||
return true;
|
||||
}
|
17
src/package/package.c
Normal file
17
src/package/package.c
Normal file
@ -0,0 +1,17 @@
|
||||
#include "../../include/package.h"
|
||||
#include "../../include/error.h"
|
||||
#include "../../include/types.h"
|
||||
#include "../../include/mptp.h"
|
||||
|
||||
#include <strings.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
lm_pkg_t *lm_package_new(){
|
||||
lm_pkg_t *pkg = malloc(sizeof(lm_pkg_t));
|
||||
bzero(pkg, sizeof(lm_pkg_t));
|
||||
return pkg;
|
||||
}
|
||||
|
||||
void lm_package_free(lm_pkg_t *pkg){
|
||||
lm_package_data_free(pkg);
|
||||
}
|
44
src/package/path.c
Normal file
44
src/package/path.c
Normal file
@ -0,0 +1,44 @@
|
||||
#include "../../include/package.h"
|
||||
#include "../../include/types.h"
|
||||
#include "../../include/util.h"
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
bool lm_package_path_set_archive(lm_pkg_t *pkg, char *archive_path){
|
||||
free(pkg->paths.archive);
|
||||
pkg->paths.archive = NULL;
|
||||
|
||||
if(NULL == archive_path)
|
||||
return true;
|
||||
|
||||
if(is_dir(archive_path))
|
||||
return false;
|
||||
|
||||
pkg->paths.archive = strdup(archive_path);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool lm_package_path_set_signature(lm_pkg_t *pkg, char *signature_path){
|
||||
free(pkg->paths.signature);
|
||||
pkg->paths.signature = NULL;
|
||||
|
||||
if(NULL == signature_path)
|
||||
return true;
|
||||
|
||||
if(is_dir(signature_path))
|
||||
return false;
|
||||
|
||||
pkg->paths.signature = strdup(signature_path);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool lm_package_path_is_empty(lm_pkg_t *pkg){
|
||||
return NULL == pkg->paths.signature ||
|
||||
NULL == pkg->paths.archive;
|
||||
}
|
||||
|
||||
void lm_package_path_free(lm_pkg_t *pkg){
|
||||
free(pkg->paths.signature);
|
||||
free(pkg->paths.archive);
|
||||
}
|
Reference in New Issue
Block a user