chore: Package module now follows the naming and structure conventions of libvieter.

This commit is contained in:
GreekStapler 2023-01-29 11:48:59 +00:00
parent 1ccd4101af
commit 76e4adae92
13 changed files with 224 additions and 178 deletions

View file

@ -1,24 +0,0 @@
#ifndef VIETER_DYNARRAY
#define VIETER_DYNARRAY
#include <stdlib.h>
#include <string.h>
typedef struct dyn_array DynArray;
struct dyn_array {
char **array;
size_t capacity;
size_t size;
};
DynArray *dynarray_init(size_t initial_capacity);
void dynarray_add(DynArray *da, const char * s);
void dynarray_free(DynArray *da);
/**
* Convert a DynArray into an array by freeing all its surrounding components
* and returning the underlying array pointer.
*/
char **dynarray_convert(DynArray *da);
#endif

View file

@ -1,26 +0,0 @@
#ifndef VIETER_PACKAGE
#define VIETER_PACKAGE
#include <stdint.h>
#include <stdbool.h>
#include <string.h>
#include <stdlib.h>
#include <archive.h>
#include <archive_entry.h>
#include "package_info.h"
#include "dynarray.h"
typedef struct pkg {
char *path;
PkgInfo *info;
DynArray *files;
int compression;
} Pkg;
Pkg *package_read_archive(const char *pkg_path);
void package_free(Pkg ** ptp);
char *package_to_description(Pkg *pkg);
#endif

View file

@ -1,39 +0,0 @@
#ifndef VIETER_PACKAGE_INFO
#define VIETER_PACKAGE_INFO
#define FREE_STRING(sp) if (sp != NULL) free(sp)
#include <stdint.h>
#include "dynarray.h"
typedef struct pkg_info {
char *name;
char *base;
char *version;
char *description;
int64_t size;
int64_t csize;
char *url;
char *arch;
int64_t build_date;
char *packager;
char *pgpsig;
int64_t pgpsigsize;
DynArray *groups;
DynArray *licenses;
DynArray *replaces;
DynArray *depends;
DynArray *conflicts;
DynArray *provides;
DynArray *optdepends;
DynArray *makedepends;
DynArray *checkdepends;
} PkgInfo;
PkgInfo *package_info_init();
void package_info_parse(PkgInfo *pkg_info, char *pkg_info_str);
void package_info_free(PkgInfo *pkg_info);
#endif

View file

@ -1,34 +0,0 @@
/*********************************************************************
* Filename: sha256.h
* Author: Brad Conte (brad AT bradconte.com)
* Copyright:
* Disclaimer: This code is presented "as is" without any guarantees.
* Details: Defines the API for the corresponding SHA1 implementation.
*********************************************************************/
#ifndef SHA256_H
#define SHA256_H
/*************************** HEADER FILES ***************************/
#include <stddef.h>
/****************************** MACROS ******************************/
#define SHA256_BLOCK_SIZE 32 // SHA256 outputs a 32 byte digest
/**************************** DATA TYPES ****************************/
typedef unsigned char BYTE; // 8-bit byte
typedef unsigned int WORD; // 32-bit word, change to "long" for 16-bit machines
typedef struct {
BYTE data[64];
WORD datalen;
unsigned long long bitlen;
WORD state[8];
} SHA256_CTX;
/*********************** FUNCTION DECLARATIONS **********************/
void sha256_init(SHA256_CTX *ctx);
void sha256_update(SHA256_CTX *ctx, const BYTE data[], size_t len);
void sha256_final(SHA256_CTX *ctx, BYTE hash[]);
#endif // SHA256_H

30
include/vieter_package.h Normal file
View file

@ -0,0 +1,30 @@
#ifndef VIETER_PACKAGE
#define VIETER_PACKAGE
#include <stdint.h>
#include <stdbool.h>
#include <string.h>
#include <stdlib.h>
#include <archive.h>
#include <archive_entry.h>
typedef struct pkg Pkg;
/*
* Parse package file into something usable by libvieter.
* The pointer returned by this function will need to freed at a later point.
*/
Pkg *vieter_package_read_archive(const char *pkg_path);
/*
* Deallocate a package.
*/
void vieter_package_free(Pkg ** ptp);
/*
* Create string that will become the package's desc file.
*/
char *vieter_package_to_description(Pkg *pkg);
#endif