mirror of
https://github.com/limine-bootloader/limine
synced 2024-11-27 02:49:56 +03:00
Add URI parser
This commit is contained in:
parent
0c5ccf14b4
commit
7863c92cae
@ -1,4 +1,5 @@
|
||||
#include <stddef.h>
|
||||
#include <stdbool.h>
|
||||
#include <lib/config.h>
|
||||
#include <lib/libc.h>
|
||||
#include <lib/blib.h>
|
||||
@ -116,3 +117,41 @@ char *config_get_value(char *buf, size_t index, size_t limit, const char *key) {
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
// A URI takes the form of: resource://root/path
|
||||
// The following function splits up a URI into its componenets
|
||||
bool config_resolve_uri(char *uri, char **resource, char **root, char **path) {
|
||||
*resource = *root = *path = NULL;
|
||||
|
||||
// Get resource
|
||||
for (size_t i = 0; ; i++) {
|
||||
if (strlen(uri + i) < 3)
|
||||
return false;
|
||||
|
||||
if (!memcmp(uri + i, "://", 3)) {
|
||||
*resource = uri;
|
||||
uri[i] = 0;
|
||||
uri += i + 3;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
for (size_t i = 0; ; i++) {
|
||||
if (uri[i] == 0)
|
||||
return false;
|
||||
|
||||
if (uri[i] == '/') {
|
||||
*root = uri;
|
||||
uri[i] = 0;
|
||||
uri += i + 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (*uri == 0)
|
||||
return false;
|
||||
|
||||
*path = uri;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@ -2,10 +2,12 @@
|
||||
#define __LIB__CONFIG_H__
|
||||
|
||||
#include <stddef.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
int init_config(int drive, int part);
|
||||
int config_get_entry_name(char *ret, size_t index, size_t limit);
|
||||
int config_set_entry(size_t index);
|
||||
char *config_get_value(char *buf, size_t index, size_t limit, const char *key);
|
||||
bool config_resolve_uri(char *uri, char **resource, char **root, char **path);
|
||||
|
||||
#endif
|
||||
|
Loading…
Reference in New Issue
Block a user