core: Need to be able to parse the app path more differently.

This commit is contained in:
2025-12-06 14:26:07 -05:00
parent d84b06f814
commit 6381ba6785
2 changed files with 29 additions and 2 deletions

View File

@@ -253,7 +253,26 @@ typedef struct _app_hello_t
static void _httpd_app_hello_work(tf_ssb_t* ssb, void* user_data)
{
app_hello_t* work = user_data;
tf_printf("%s\n", work->path);
char blob_id[k_id_base64_len] = { 0 };
tf_httpd_user_app_t* user_app = tf_httpd_parse_user_app_from_path(work->path, NULL);
tf_printf("path = %s\n", work->path);
if (user_app)
{
tf_printf("user = %s app = %s\n", user_app->user, user_app->app);
size_t length = strlen("path:") + strlen(user_app->app) + 1;
char* key = alloca(length);
snprintf(key, length, "path:%s", user_app->app);
const char* value = tf_ssb_db_get_property(ssb, user_app->user, key);
tf_string_set(blob_id, sizeof(blob_id), value);
tf_free((void*)value);
}
else if (work->path[0] == '/' && (work->path[1] == '%' || work->path[1] == '&') && strlen(work->path) >= 1 + k_blob_id_len && strstr(work->path, ".sha256"))
{
memcpy(blob_id, work->path + 1, strstr(work->path, ".sha256") - work->path - 1 + strlen(".sha256"));
}
tf_printf("BLOB ID=%s\n", blob_id);
tf_free(user_app);
}
static void _httpd_app_hello_after_work(tf_ssb_t* ssb, int status, void* user_data)

View File

@@ -587,7 +587,7 @@ tf_httpd_user_app_t* tf_httpd_parse_user_app_from_path(const char* path, const c
size_t length = strlen(path);
size_t suffix_length = expected_suffix ? strlen(expected_suffix) : 0;
if (length < suffix_length || strcmp(path + length - suffix_length, expected_suffix) != 0)
if (expected_suffix && (length < suffix_length || strcmp(path + length - suffix_length, expected_suffix) != 0))
{
return NULL;
}
@@ -602,6 +602,14 @@ tf_httpd_user_app_t* tf_httpd_parse_user_app_from_path(const char* path, const c
size_t user_length = (size_t)(slash - user);
const char* app = slash + 1;
size_t app_length = (size_t)(length - suffix_length - user_length - 3);
if (!expected_suffix)
{
char* app_slash = strchr(app, '/');
if (app_slash)
{
app_length = tf_min((size_t)(app_slash - app), app_length);
}
}
tf_httpd_user_app_t* result = tf_malloc(sizeof(tf_httpd_user_app_t) + user_length + 1 + app_length + 1);
*result = (tf_httpd_user_app_t) {