libropkg: implement package manifest parsing

This commit is contained in:
2025-08-06 22:07:47 +01:00
parent f35ade11d6
commit 6275836e40
5 changed files with 588 additions and 2 deletions

View File

@@ -0,0 +1,87 @@
#ifndef ROPKG_MANIFEST_H_
#define ROPKG_MANIFEST_H_
#include <blue/core/error.h>
#include <ropkg/misc.h>
#include <ropkg/status.h>
#include <stdio.h>
enum ropkg_manifest_value_type {
ROPKG_MANIFEST_VALUE_T_NONE = 0,
ROPKG_MANIFEST_VALUE_T_STRING,
ROPKG_MANIFEST_VALUE_T_INT,
};
enum ropkg_manifest_value_id {
ROPKG_MANIFEST_VALUE_N_NONE = 0,
ROPKG_MANIFEST_VALUE_N_NAME,
ROPKG_MANIFEST_VALUE_N_ARCHITECTURE,
ROPKG_MANIFEST_VALUE_N_VERSION,
ROPKG_MANIFEST_VALUE_N_PRIORITY,
ROPKG_MANIFEST_VALUE_N_CATEGORY,
ROPKG_MANIFEST_VALUE_N_MAINTAINER,
ROPKG_MANIFEST_VALUE_N_PROVIDES,
ROPKG_MANIFEST_VALUE_N_DEPENDS,
ROPKG_MANIFEST_VALUE_N_RECOMMENDS,
ROPKG_MANIFEST_VALUE_N_SUGGESTS,
ROPKG_MANIFEST_VALUE_N_CONFLICTS,
ROPKG_MANIFEST_VALUE_N_ENHANCES,
ROPKG_MANIFEST_VALUE_N_INSTALLED_SIZE,
ROPKG_MANIFEST_VALUE_N_DESCRIPTION,
};
struct ropkg_manifest;
struct ropkg_manifest_value;
ROPKG_API enum ropkg_status ropkg_manifest_create(struct ropkg_manifest **out);
ROPKG_API void ropkg_manifest_destroy(struct ropkg_manifest *manifest);
ROPKG_API b_result ropkg_manifest_parse(FILE *fp, struct ropkg_manifest *dest);
ROPKG_API enum ropkg_status ropkg_manifest_get_by_name(
struct ropkg_manifest *manifest,
const char *name,
struct ropkg_manifest_value **out);
ROPKG_API enum ropkg_status ropkg_manifest_get_by_id(
struct ropkg_manifest *manifest,
enum ropkg_manifest_value_id id,
struct ropkg_manifest_value **out);
ROPKG_API enum ropkg_status ropkg_manifest_put(
struct ropkg_manifest *manifest,
struct ropkg_manifest_value *value);
ROPKG_API const struct ropkg_manifest_value *ropkg_manifest_get_first_value(
const struct ropkg_manifest *manifest);
ROPKG_API const struct ropkg_manifest_value *ropkg_manifest_get_next_value(
const struct ropkg_manifest *manifest,
const struct ropkg_manifest_value *value);
ROPKG_API enum ropkg_status ropkg_manifest_value_create_int_with_name(
size_t value,
const char *name,
struct ropkg_manifest_value **out);
ROPKG_API enum ropkg_status ropkg_manifest_value_create_int_with_id(
size_t value,
enum ropkg_manifest_value_id id,
struct ropkg_manifest_value **out);
ROPKG_API enum ropkg_status ropkg_manifest_value_create_string_with_name(
const char *value,
const char *name,
struct ropkg_manifest_value **out);
ROPKG_API enum ropkg_status ropkg_manifest_value_create_string_with_id(
const char *value,
enum ropkg_manifest_value_id id,
struct ropkg_manifest_value **out);
ROPKG_API void ropkg_manifest_value_destroy(struct ropkg_manifest_value *value);
ROPKG_API enum ropkg_manifest_value_type ropkg_manifest_value_get_type(
const struct ropkg_manifest_value *value);
ROPKG_API const char *ropkg_manifest_value_get_name(
const struct ropkg_manifest_value *value);
ROPKG_API enum ropkg_manifest_value_id ropkg_manifest_value_get_id(
const struct ropkg_manifest_value *value);
ROPKG_API const char *ropkg_manifest_value_get_string(
const struct ropkg_manifest_value *value);
ROPKG_API size_t
ropkg_manifest_value_get_int(const struct ropkg_manifest_value *value);
#endif

View File

@@ -4,11 +4,12 @@
#include <blue/core/error.h>
#include <ropkg/misc.h>
#define ROPKG_ERROR_VENDOR (ropkg_error_vendor())
#define ROPKG_ERROR_VENDOR (ropkg_error_vendor())
#define ROPKG_RESULT_SUCCESS B_RESULT_SUCCESS
#define ROPKG_RESULT_ERR(code) \
b_error_with_code(ROPKG_ERROR_VENDOR, ROPKG_ERR_##code)
#define ROPKG_RESULT_SUCCESS B_RESULT_SUCCESS
#define ROPKG_RESULT_STATUS(code) b_error_with_code(ROPKG_ERROR_VENDOR, code)
enum ropkg_status {
ROPKG_SUCCESS = 0,
@@ -18,11 +19,17 @@ enum ropkg_status {
ROPKG_ERR_BAD_STATE,
ROPKG_ERR_INTERNAL_FAILURE,
ROPKG_ERR_IO_FAILURE,
ROPKG_ERR_NO_ENTRY,
ROPKG_ERR_NO_DATA,
ROPKG_ERR_NAME_EXISTS,
ROPKG_ERR_DIR_OPEN_FAILED,
ROPKG_ERR_INSTANCE_DIR_CREATE_FAILED,
ROPKG_ERR_FILE_OPEN_FAILED,
ROPKG_ERR_INVALID_MANIFEST_FORMAT,
ROPKG_ERR_INVALID_VERSION_FORMAT,
ROPKG_ERR_INVALID_PKG_EXPR,
ROPKG_ERR_INVALID_PKG_FILE,
};
enum ropkg_error_msg {