api versioning for modules

This commit is contained in:
jacekpoz 2024-02-11 17:50:10 +01:00
parent 2695a19da4
commit 1640be4666
No known key found for this signature in database
GPG key ID: 94E812A8B12AAE3C
4 changed files with 48 additions and 4 deletions

10
mod.h
View file

@ -4,10 +4,18 @@
#include "semver.h" #include "semver.h"
#include <stdint.h> #include <stdint.h>
static const semver API_VERSION = {
.major = 0,
.minor = 1,
.patch = 0,
};
static const uint8_t MFERR_APIVER = 1;
semver version(void); semver version(void);
const char *name(void); const char *name(void);
void init(char **config); uint8_t init(char **config);
const char *get(void); const char *get(void);
#endif // _MODFETCH_MOD_H #endif // _MODFETCH_MOD_H

View file

@ -8,6 +8,12 @@
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
static const semver api_ver = {
.major = 0,
.minor = 1,
.patch = 0,
};
static const semver _version = { static const semver _version = {
.major = 0, .major = 0,
.minor = 1, .minor = 1,
@ -17,8 +23,14 @@ static const semver _version = {
semver version(void) { return _version; } semver version(void) { return _version; }
const char *name(void) { return "desktop"; } const char *name(void) { return "desktop"; }
void init(char **config) { uint8_t init(char **config) {
if (!sveq(api_ver, API_VERSION)) {
return MFERR_APIVER;
}
(void)config; (void)config;
return 0;
} }
const char *get(void) { const char *get(void) {

View file

@ -10,6 +10,12 @@
#include <string.h> #include <string.h>
#include <sys/types.h> #include <sys/types.h>
static const semver api_ver = {
.major = 0,
.minor = 1,
.patch = 0,
};
static const semver _version = { static const semver _version = {
.major = 0, .major = 0,
.minor = 1, .minor = 1,
@ -19,8 +25,14 @@ static const semver _version = {
semver version(void) { return _version; } semver version(void) { return _version; }
const char *name(void) { return "os"; } const char *name(void) { return "os"; }
void init(char **config) { uint8_t init(char **config) {
if (!sveq(api_ver, API_VERSION)) {
return MFERR_APIVER;
}
(void)config; (void)config;
return 0;
} }
const char *get(void) { const char *get(void) {

View file

@ -12,6 +12,12 @@
#include <string.h> #include <string.h>
#include <stdlib.h> #include <stdlib.h>
static const semver api_ver = {
.major = 0,
.minor = 1,
.patch = 0,
};
static const semver _version = { static const semver _version = {
.major = 1, .major = 1,
.minor = 0, .minor = 0,
@ -25,7 +31,11 @@ static size_t length = 8;
static char *sep_char = "-"; static char *sep_char = "-";
static size_t sep_char_length = 1; static size_t sep_char_length = 1;
void init(char **config) { uint8_t init(char **config) {
if (!sveq(api_ver, API_VERSION)) {
return MFERR_APIVER;
}
for (char *opt = *config; opt != NULL; opt = *++config) { for (char *opt = *config; opt != NULL; opt = *++config) {
if (strncmp(opt, "sep", 3) == 0) { if (strncmp(opt, "sep", 3) == 0) {
char *valstr = opt + 4; // skip 'sep=' char *valstr = opt + 4; // skip 'sep='
@ -47,6 +57,8 @@ void init(char **config) {
} }
} }
} }
return 0;
} }
const char *get(void) { const char *get(void) {