forked from cory/tildefriends
Implement the rest of the endpoints that were already mostly C in C.
git-svn-id: https://www.unprompted.com/svn/projects/tildefriends/trunk@4727 ed5197a5-7fde-0310-b194-c3ffbd925b24
This commit is contained in:
@ -427,6 +427,69 @@ static void _httpd_endpoint_mem(tf_http_request_t* request)
|
||||
tf_trace_end(trace);
|
||||
}
|
||||
|
||||
static void _httpd_endpoint_disconnections(tf_http_request_t* request)
|
||||
{
|
||||
if (_httpd_redirect(request))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
tf_task_t* task = request->user_data;
|
||||
tf_trace_t* trace = tf_task_get_trace(task);
|
||||
tf_trace_begin(trace, __func__);
|
||||
char* response = tf_task_get_disconnections(task);
|
||||
const char* headers[] =
|
||||
{
|
||||
"Content-Type", "application/json; charset=utf-8",
|
||||
"Access-Control-Allow-Origin", "*",
|
||||
};
|
||||
tf_http_respond(request, 200, headers, tf_countof(headers) / 2, response, response ? strlen(response) : 0);
|
||||
tf_free(response);
|
||||
tf_trace_end(trace);
|
||||
}
|
||||
|
||||
static void _httpd_endpoint_hitches(tf_http_request_t* request)
|
||||
{
|
||||
if (_httpd_redirect(request))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
tf_task_t* task = request->user_data;
|
||||
tf_trace_t* trace = tf_task_get_trace(task);
|
||||
tf_trace_begin(trace, __func__);
|
||||
char* response = tf_task_get_hitches(task);
|
||||
const char* headers[] =
|
||||
{
|
||||
"Content-Type", "application/json; charset=utf-8",
|
||||
"Access-Control-Allow-Origin", "*",
|
||||
};
|
||||
tf_http_respond(request, 200, headers, tf_countof(headers) / 2, response, response ? strlen(response) : 0);
|
||||
tf_free(response);
|
||||
tf_trace_end(trace);
|
||||
}
|
||||
|
||||
static void _httpd_endpoint_debug(tf_http_request_t* request)
|
||||
{
|
||||
if (_httpd_redirect(request))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
tf_task_t* task = request->user_data;
|
||||
tf_trace_t* trace = tf_task_get_trace(task);
|
||||
tf_trace_begin(trace, __func__);
|
||||
char* response = tf_task_get_debug(task);
|
||||
const char* headers[] =
|
||||
{
|
||||
"Content-Type", "application/json; charset=utf-8",
|
||||
"Access-Control-Allow-Origin", "*",
|
||||
};
|
||||
tf_http_respond(request, 200, headers, tf_countof(headers) / 2, response, response ? strlen(response) : 0);
|
||||
tf_free(response);
|
||||
tf_trace_end(trace);
|
||||
}
|
||||
|
||||
void tf_httpd_register(JSContext* context)
|
||||
{
|
||||
JS_NewClassID(&_httpd_class_id);
|
||||
@ -457,8 +520,11 @@ void tf_httpd_register(JSContext* context)
|
||||
tf_http_t* http = tf_http_create(loop);
|
||||
JS_SetOpaque(httpd, http);
|
||||
|
||||
tf_http_add_handler(http, "/trace", _httpd_endpoint_trace, task);
|
||||
tf_http_add_handler(http, "/debug", _httpd_endpoint_debug, task);
|
||||
tf_http_add_handler(http, "/disconnections", _httpd_endpoint_disconnections, task);
|
||||
tf_http_add_handler(http, "/hitches", _httpd_endpoint_hitches, task);
|
||||
tf_http_add_handler(http, "/mem", _httpd_endpoint_mem, task);
|
||||
tf_http_add_handler(http, "/trace", _httpd_endpoint_trace, task);
|
||||
|
||||
JS_SetPropertyStr(context, httpd, "handlers", JS_NewObject(context));
|
||||
JS_SetPropertyStr(context, httpd, "all", JS_NewCFunction(context, _httpd_all, "all", 2));
|
||||
|
Reference in New Issue
Block a user