forked from cory/tildefriends
clang-format the source. Not exactly how I want it, but automated is better than perfect.
git-svn-id: https://www.unprompted.com/svn/projects/tildefriends/trunk@4845 ed5197a5-7fde-0310-b194-c3ffbd925b24
This commit is contained in:
@ -230,8 +230,7 @@ static void _httpd_callback_internal(tf_http_request_t* request, bool is_websock
|
||||
JS_SetPropertyStr(context, response_object, "end", JS_NewCFunction(context, _httpd_response_end, "end", 1));
|
||||
JS_SetPropertyStr(context, response_object, "send", JS_NewCFunction(context, _httpd_response_send, "send", 2));
|
||||
JS_SetPropertyStr(context, response_object, "upgrade", JS_NewCFunction(context, _httpd_websocket_upgrade, "upgrade", 2));
|
||||
JSValue args[] =
|
||||
{
|
||||
JSValue args[] = {
|
||||
request_object,
|
||||
response_object,
|
||||
};
|
||||
@ -278,11 +277,7 @@ static JSValue _httpd_websocket_upgrade(JSContext* context, JSValueConst this_va
|
||||
const char* header_connection = tf_http_request_get_header(request, "connection");
|
||||
const char* header_upgrade = tf_http_request_get_header(request, "upgrade");
|
||||
const char* header_sec_websocket_key = tf_http_request_get_header(request, "sec-websocket-key");
|
||||
if (header_connection &&
|
||||
header_upgrade &&
|
||||
header_sec_websocket_key &&
|
||||
strstr(header_connection, "Upgrade") &&
|
||||
strcasecmp(header_upgrade, "websocket") == 0)
|
||||
if (header_connection && header_upgrade && header_sec_websocket_key && strstr(header_connection, "Upgrade") && strcasecmp(header_upgrade, "websocket") == 0)
|
||||
{
|
||||
static const char* k_magic = "258EAFA5-E914-47DA-95CA-C5AB0DC85B11";
|
||||
size_t key_length = strlen(header_sec_websocket_key);
|
||||
@ -311,8 +306,7 @@ static JSValue _httpd_websocket_upgrade(JSContext* context, JSValueConst this_va
|
||||
headers_count++;
|
||||
|
||||
bool send_version =
|
||||
!tf_http_request_get_header(request, "sec-websocket-version") ||
|
||||
strcmp(tf_http_request_get_header(request, "sec-websocket-version"), "13") != 0;
|
||||
!tf_http_request_get_header(request, "sec-websocket-version") || strcmp(tf_http_request_get_header(request, "sec-websocket-version"), "13") != 0;
|
||||
if (send_version)
|
||||
{
|
||||
headers[headers_count * 2 + 0] = "Sec-WebSocket-Accept";
|
||||
@ -433,10 +427,11 @@ static void _httpd_endpoint_trace(tf_http_request_t* request)
|
||||
tf_task_t* task = request->user_data;
|
||||
tf_trace_t* trace = tf_task_get_trace(task);
|
||||
char* json = tf_trace_export(trace);
|
||||
const char* headers[] =
|
||||
{
|
||||
"Content-Type", "application/json; charset=utf-8",
|
||||
"Access-Control-Allow-Origin", "*",
|
||||
const char* headers[] = {
|
||||
"Content-Type",
|
||||
"application/json; charset=utf-8",
|
||||
"Access-Control-Allow-Origin",
|
||||
"*",
|
||||
};
|
||||
tf_http_respond(request, 200, headers, tf_countof(headers) / 2, json, json ? strlen(json) : 0);
|
||||
tf_free(json);
|
||||
@ -465,10 +460,11 @@ static void _httpd_endpoint_mem(tf_http_request_t* request)
|
||||
}
|
||||
tf_free(alloc);
|
||||
|
||||
const char* headers[] =
|
||||
{
|
||||
"Content-Type", "text/plain; charset=utf-8",
|
||||
"Access-Control-Allow-Origin", "*",
|
||||
const char* headers[] = {
|
||||
"Content-Type",
|
||||
"text/plain; charset=utf-8",
|
||||
"Access-Control-Allow-Origin",
|
||||
"*",
|
||||
};
|
||||
tf_http_respond(request, 200, headers, tf_countof(headers) / 2, response, length);
|
||||
tf_free(response);
|
||||
@ -483,10 +479,11 @@ static void _httpd_endpoint_disconnections(tf_http_request_t* request)
|
||||
|
||||
tf_task_t* task = request->user_data;
|
||||
char* response = tf_task_get_disconnections(task);
|
||||
const char* headers[] =
|
||||
{
|
||||
"Content-Type", "application/json; charset=utf-8",
|
||||
"Access-Control-Allow-Origin", "*",
|
||||
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);
|
||||
@ -501,10 +498,11 @@ static void _httpd_endpoint_hitches(tf_http_request_t* request)
|
||||
|
||||
tf_task_t* task = request->user_data;
|
||||
char* response = tf_task_get_hitches(task);
|
||||
const char* headers[] =
|
||||
{
|
||||
"Content-Type", "application/json; charset=utf-8",
|
||||
"Access-Control-Allow-Origin", "*",
|
||||
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);
|
||||
@ -560,21 +558,24 @@ static void _httpd_endpoint_static_read(tf_task_t* task, const char* path, int r
|
||||
if (strcmp(path, "core/tfrpc.js") == 0)
|
||||
{
|
||||
const char* content_type = _ext_to_content_type(strrchr(path, '.'));
|
||||
const char* headers[] =
|
||||
{
|
||||
"Content-Type", content_type,
|
||||
"etag", file->etag,
|
||||
"Access-Control-Allow-Origin", "null",
|
||||
const char* headers[] = {
|
||||
"Content-Type",
|
||||
content_type,
|
||||
"etag",
|
||||
file->etag,
|
||||
"Access-Control-Allow-Origin",
|
||||
"null",
|
||||
};
|
||||
tf_http_respond(request, 200, headers, tf_countof(headers) / 2, data, result);
|
||||
}
|
||||
else
|
||||
{
|
||||
const char* content_type = _ext_to_content_type(strrchr(path, '.'));
|
||||
const char* headers[] =
|
||||
{
|
||||
"Content-Type", content_type,
|
||||
"etag", file->etag,
|
||||
const char* headers[] = {
|
||||
"Content-Type",
|
||||
content_type,
|
||||
"etag",
|
||||
file->etag,
|
||||
};
|
||||
tf_http_respond(request, 200, headers, tf_countof(headers) / 2, data, result);
|
||||
}
|
||||
@ -625,8 +626,7 @@ static void _httpd_endpoint_static(tf_http_request_t* request)
|
||||
return;
|
||||
}
|
||||
|
||||
const char* k_static_files[] =
|
||||
{
|
||||
const char* k_static_files[] = {
|
||||
"index.html",
|
||||
"client.js",
|
||||
"favicon.png",
|
||||
@ -636,8 +636,7 @@ static void _httpd_endpoint_static(tf_http_request_t* request)
|
||||
"w3.css",
|
||||
};
|
||||
|
||||
const char* k_map[][2] =
|
||||
{
|
||||
const char* k_map[][2] = {
|
||||
{ "/static/", "core/" },
|
||||
{ "/lit/", "deps/lit/" },
|
||||
{ "/codemirror/", "deps/codemirror/" },
|
||||
@ -696,10 +695,9 @@ static void _httpd_endpoint_robots_txt(tf_http_request_t* request)
|
||||
{
|
||||
return;
|
||||
}
|
||||
char* response =
|
||||
"User-Agent: *\n"
|
||||
"Disallow: /*/*/edit\n"
|
||||
"Allow: /\n";
|
||||
char* response = "User-Agent: *\n"
|
||||
"Disallow: /*/*/edit\n"
|
||||
"Allow: /\n";
|
||||
const char* headers[] = { "Content-Type", "text/plain; charset=utf-8" };
|
||||
tf_http_respond(request, 200, headers, tf_countof(headers) / 2, response, response ? strlen(response) : 0);
|
||||
}
|
||||
@ -713,10 +711,11 @@ static void _httpd_endpoint_debug(tf_http_request_t* request)
|
||||
|
||||
tf_task_t* task = request->user_data;
|
||||
char* response = tf_task_get_debug(task);
|
||||
const char* headers[] =
|
||||
{
|
||||
"Content-Type", "application/json; charset=utf-8",
|
||||
"Access-Control-Allow-Origin", "*",
|
||||
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);
|
||||
@ -726,8 +725,7 @@ void tf_httpd_register(JSContext* context)
|
||||
{
|
||||
JS_NewClassID(&_httpd_class_id);
|
||||
JS_NewClassID(&_httpd_request_class_id);
|
||||
JSClassDef httpd_def =
|
||||
{
|
||||
JSClassDef httpd_def = {
|
||||
.class_name = "Httpd",
|
||||
.finalizer = &_httpd_finalizer,
|
||||
};
|
||||
@ -735,8 +733,7 @@ void tf_httpd_register(JSContext* context)
|
||||
{
|
||||
fprintf(stderr, "Failed to register Httpd.\n");
|
||||
}
|
||||
JSClassDef request_def =
|
||||
{
|
||||
JSClassDef request_def = {
|
||||
.class_name = "Request",
|
||||
.finalizer = &_httpd_request_finalizer,
|
||||
};
|
||||
|
Reference in New Issue
Block a user