core: Add a helper for getting a property by string as a string. I've typed this too much.
All checks were successful
Build Tilde Friends / Build-All (push) Successful in 9m15s
All checks were successful
Build Tilde Friends / Build-All (push) Successful in 9m15s
This commit is contained in:
@@ -243,9 +243,44 @@ static void _httpd_app_kill_task(app_t* work)
|
||||
}
|
||||
}
|
||||
|
||||
typedef struct _app_hello_t
|
||||
{
|
||||
app_t* app;
|
||||
JSValue message;
|
||||
const char* path;
|
||||
} 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);
|
||||
}
|
||||
|
||||
static void _httpd_app_hello_after_work(tf_ssb_t* ssb, int status, void* user_data)
|
||||
{
|
||||
app_hello_t* work = user_data;
|
||||
JSContext* context = tf_ssb_get_context(ssb);
|
||||
tf_http_request_unref(work->app->request);
|
||||
JS_FreeCString(context, work->path);
|
||||
JS_FreeValue(context, work->message);
|
||||
tf_free(work);
|
||||
}
|
||||
|
||||
static void _httpd_app_message_hello(app_t* work, JSValue message)
|
||||
{
|
||||
/* TODO */
|
||||
JSContext* context = work->request->context;
|
||||
tf_task_t* task = tf_task_get(context);
|
||||
tf_ssb_t* ssb = tf_task_get_ssb(task);
|
||||
tf_http_request_ref(work->request);
|
||||
JSValue path = JS_GetPropertyStr(context, message, "path");
|
||||
app_hello_t* hello = tf_malloc(sizeof(app_hello_t));
|
||||
*hello = (app_hello_t) {
|
||||
.app = work,
|
||||
.message = JS_DupValue(context, message),
|
||||
.path = JS_ToCString(context, path),
|
||||
};
|
||||
JS_FreeValue(context, path);
|
||||
tf_ssb_run_work(ssb, _httpd_app_hello_work, _httpd_app_hello_after_work, hello);
|
||||
}
|
||||
|
||||
static bool _httpd_app_message_call_client_api(app_t* work, JSValue message, const char* action_string)
|
||||
@@ -301,8 +336,6 @@ static void _httpd_app_on_message(tf_http_request_t* request, int op_code, const
|
||||
/* BINARY */
|
||||
case 0x2:
|
||||
{
|
||||
char* copy = tf_malloc(size + 1);
|
||||
memcpy(copy, data, size);
|
||||
JSValue message = JS_ParseJSON(context, data, size, NULL);
|
||||
if (JS_IsException(message) || !JS_IsObject(message))
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user