From 3b8f6ac1d9798ca308f4527883bc76412b959903 Mon Sep 17 00:00:00 2001 From: Will Xyen Date: Mon, 23 Dec 2019 20:16:58 -0500 Subject: [PATCH] launcher: make app_config.xml optional --- src/main/launcher/main.c | 9 +++++- src/main/launcher/property.c | 57 ++++++++++++++++++++++++++++++++++++ src/main/launcher/property.h | 1 + 3 files changed, 66 insertions(+), 1 deletion(-) diff --git a/src/main/launcher/main.c b/src/main/launcher/main.c index 05cfb27..4e1c493 100644 --- a/src/main/launcher/main.c +++ b/src/main/launcher/main.c @@ -17,6 +17,7 @@ #include "util/codepage.h" #include "util/defs.h" +#include "util/fs.h" #include "util/log.h" #include "util/mem.h" #include "util/str.h" @@ -243,7 +244,13 @@ int main(int argc, const char **argv) /* Invoke dll_entry_init */ - app_config = boot_property_load(options.app_config_path); + if (path_exists(options.app_config_path)) { + app_config = boot_property_load(options.app_config_path); + } else { + log_warning("%s: app config file missing, using empty", options.app_config_path); + app_config = boot_property_load_cstring("dummy"); + } + app_config_root = property_search(app_config, 0, "/param"); if (app_config_root == NULL) { diff --git a/src/main/launcher/property.c b/src/main/launcher/property.c index 9274e0f..a418dd8 100644 --- a/src/main/launcher/property.c +++ b/src/main/launcher/property.c @@ -20,6 +20,25 @@ static int boot_property_fread(uint32_t context, void *bytes, size_t nbytes) return fread(bytes, 1, nbytes, f); } +struct cstring_read_handle { + const char * buffer; + size_t buffer_len; + size_t offset; +}; + +static int boot_property_cstring_read(uint32_t context, void *bytes, size_t nbytes) +{ + int result = 0; + struct cstring_read_handle* h = TlsGetValue(context); + + if (h->offset < h->buffer_len){ + result = min(nbytes, h->buffer_len - h->offset); + memcpy(bytes, (const void *)(h->buffer + h->offset), result); + h->offset += result; + } + return result; +} + struct property *boot_property_load(const char *filename) { struct property *prop; @@ -65,6 +84,44 @@ struct property *boot_property_load(const char *filename) return prop; } +struct property *boot_property_load_cstring(const char *cstring) +{ + struct property *prop; + void *buffer; + int nbytes; + uint32_t s_keyhole; + + // see above + struct cstring_read_handle read_handle; + read_handle.buffer = cstring; + read_handle.buffer_len = strlen(cstring); + read_handle.offset = 0; + + s_keyhole = TlsAlloc(); + TlsSetValue(s_keyhole, &read_handle); + + nbytes = property_read_query_memsize(boot_property_cstring_read, s_keyhole, 0, 0); + + if (nbytes < 0) { + log_fatal("Error querying configuration string"); + } + + buffer = xmalloc(nbytes); + prop = property_create( + PROPERTY_FLAG_READ | PROPERTY_FLAG_WRITE | PROPERTY_FLAG_CREATE | PROPERTY_FLAG_APPEND, + buffer, + nbytes + ); + + read_handle.offset = 0; + if (!property_insert_read(prop, 0, boot_property_cstring_read, s_keyhole)) { + log_fatal("Error inserting configuration string"); + } + + TlsFree(s_keyhole); + + return prop; +} void boot_property_free(struct property *prop) { diff --git a/src/main/launcher/property.h b/src/main/launcher/property.h index ed7a132..c3f14d0 100644 --- a/src/main/launcher/property.h +++ b/src/main/launcher/property.h @@ -4,6 +4,7 @@ #include "imports/avs.h" struct property *boot_property_load(const char *filename); +struct property *boot_property_load_cstring(const char *cstring); void boot_property_free(struct property *prop); #endif