forked from cory/tildefriends
Add missing .clang-format, and fix some spaces that slipped through.
git-svn-id: https://www.unprompted.com/svn/projects/tildefriends/trunk@4856 ed5197a5-7fde-0310-b194-c3ffbd925b24
This commit is contained in:
parent
1958623a7a
commit
d0e11bc68b
20
.clang-format
Normal file
20
.clang-format
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
# Format Style Options - Created with Clang Power Tools
|
||||||
|
---
|
||||||
|
BasedOnStyle: WebKit
|
||||||
|
AlignEscapedNewlines: DontAlign
|
||||||
|
AlignOperands: DontAlign
|
||||||
|
AllowShortCaseLabelsOnASingleLine: false
|
||||||
|
AllowShortFunctionsOnASingleLine: false
|
||||||
|
BreakBeforeBinaryOperators: None
|
||||||
|
BreakBeforeBraces: Allman
|
||||||
|
ColumnLimit: 180
|
||||||
|
ContinuationIndentWidth: 4
|
||||||
|
IndentCaseBlocks: true
|
||||||
|
IndentWidth: 4
|
||||||
|
MaxEmptyLinesToKeep: 1
|
||||||
|
ObjCBlockIndentWidth: 4
|
||||||
|
ObjCBreakBeforeNestedBlockParam: false
|
||||||
|
SortIncludes: false
|
||||||
|
TabWidth: 4
|
||||||
|
UseTab: Always
|
||||||
|
...
|
@ -236,8 +236,7 @@ static JSValue _database_get_all(JSContext* context, JSValueConst this_val, int
|
|||||||
uint32_t index = 0;
|
uint32_t index = 0;
|
||||||
while (sqlite3_step(statement) == SQLITE_ROW)
|
while (sqlite3_step(statement) == SQLITE_ROW)
|
||||||
{
|
{
|
||||||
JS_SetPropertyUint32(
|
JS_SetPropertyUint32(context, array, index++, JS_NewStringLen(context, (const char*)sqlite3_column_text(statement, 0), sqlite3_column_bytes(statement, 0)));
|
||||||
context, array, index++, JS_NewStringLen(context, (const char*)sqlite3_column_text(statement, 0), sqlite3_column_bytes(statement, 0)));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
sqlite3_finalize(statement);
|
sqlite3_finalize(statement);
|
||||||
@ -292,8 +291,7 @@ static JSValue _databases_list(JSContext* context, JSValueConst this_val, int ar
|
|||||||
uint32_t index = 0;
|
uint32_t index = 0;
|
||||||
while (sqlite3_step(statement) == SQLITE_ROW)
|
while (sqlite3_step(statement) == SQLITE_ROW)
|
||||||
{
|
{
|
||||||
JS_SetPropertyUint32(
|
JS_SetPropertyUint32(context, array, index++, JS_NewStringLen(context, (const char*)sqlite3_column_text(statement, 0), sqlite3_column_bytes(statement, 0)));
|
||||||
context, array, index++, JS_NewStringLen(context, (const char*)sqlite3_column_text(statement, 0), sqlite3_column_bytes(statement, 0)));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
JS_FreeCString(context, pattern);
|
JS_FreeCString(context, pattern);
|
||||||
|
12
src/http.c
12
src/http.c
@ -132,8 +132,7 @@ static bool _http_find_handler(tf_http_t* http, const char* path, tf_http_callba
|
|||||||
for (int i = 0; i < http->handlers_count; i++)
|
for (int i = 0; i < http->handlers_count; i++)
|
||||||
{
|
{
|
||||||
if (!http->handlers[i].pattern || !*http->handlers[i].pattern || strcmp(path, http->handlers[i].pattern) == 0 ||
|
if (!http->handlers[i].pattern || !*http->handlers[i].pattern || strcmp(path, http->handlers[i].pattern) == 0 ||
|
||||||
(*http->handlers[i].pattern && strncmp(path, http->handlers[i].pattern, strlen(http->handlers[i].pattern)) == 0 &&
|
(*http->handlers[i].pattern && strncmp(path, http->handlers[i].pattern, strlen(http->handlers[i].pattern)) == 0 && path[strlen(http->handlers[i].pattern) - 1] == '/'))
|
||||||
path[strlen(http->handlers[i].pattern) - 1] == '/'))
|
|
||||||
{
|
{
|
||||||
*out_callback = http->handlers[i].callback;
|
*out_callback = http->handlers[i].callback;
|
||||||
*out_trace_name = http->handlers[i].pattern;
|
*out_trace_name = http->handlers[i].pattern;
|
||||||
@ -301,8 +300,7 @@ static void _http_add_body_bytes(tf_http_connection_t* connection, const void* d
|
|||||||
size_t total_length = mask_start + 4 + length;
|
size_t total_length = mask_start + 4 + length;
|
||||||
if (connection->body_length >= total_length)
|
if (connection->body_length >= total_length)
|
||||||
{
|
{
|
||||||
uint32_t mask =
|
uint32_t mask = (uint32_t)p[mask_start + 0] | (uint32_t)p[mask_start + 1] << 8 | (uint32_t)p[mask_start + 2] << 16 | (uint32_t)p[mask_start + 3] << 24;
|
||||||
(uint32_t)p[mask_start + 0] | (uint32_t)p[mask_start + 1] << 8 | (uint32_t)p[mask_start + 2] << 16 | (uint32_t)p[mask_start + 3] << 24;
|
|
||||||
uint8_t* message = p + mask_start + 4;
|
uint8_t* message = p + mask_start + 4;
|
||||||
_http_websocket_mask_in_place(message, mask, length);
|
_http_websocket_mask_in_place(message, mask, length);
|
||||||
|
|
||||||
@ -324,8 +322,7 @@ static void _http_add_body_bytes(tf_http_connection_t* connection, const void* d
|
|||||||
{
|
{
|
||||||
tf_trace_begin(connection->http->trace, connection->trace_name ? connection->trace_name : "websocket");
|
tf_trace_begin(connection->http->trace, connection->trace_name ? connection->trace_name : "websocket");
|
||||||
connection->request->on_message(connection->request, connection->fragment_length ? connection->fragment_op_code : op_code,
|
connection->request->on_message(connection->request, connection->fragment_length ? connection->fragment_op_code : op_code,
|
||||||
connection->fragment_length ? connection->fragment : message,
|
connection->fragment_length ? connection->fragment : message, connection->fragment_length ? connection->fragment_length : length);
|
||||||
connection->fragment_length ? connection->fragment_length : length);
|
|
||||||
tf_trace_end(connection->http->trace);
|
tf_trace_end(connection->http->trace);
|
||||||
}
|
}
|
||||||
connection->fragment_length = 0;
|
connection->fragment_length = 0;
|
||||||
@ -445,8 +442,7 @@ static size_t _http_on_read_plain_internal(tf_http_connection_t* connection, con
|
|||||||
connection->body = tf_realloc(connection->body, connection->content_length);
|
connection->body = tf_realloc(connection->body, connection->content_length);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!_http_find_handler(connection->http, connection->path, &connection->callback, &connection->trace_name, &connection->user_data) ||
|
if (!_http_find_handler(connection->http, connection->path, &connection->callback, &connection->trace_name, &connection->user_data) || !connection->callback)
|
||||||
!connection->callback)
|
|
||||||
{
|
{
|
||||||
connection->callback = _http_builtin_404_handler;
|
connection->callback = _http_builtin_404_handler;
|
||||||
connection->trace_name = "404";
|
connection->trace_name = "404";
|
||||||
|
@ -305,8 +305,7 @@ static JSValue _httpd_websocket_upgrade(JSContext* context, JSValueConst this_va
|
|||||||
headers[headers_count * 2 + 1] = key;
|
headers[headers_count * 2 + 1] = key;
|
||||||
headers_count++;
|
headers_count++;
|
||||||
|
|
||||||
bool send_version =
|
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)
|
if (send_version)
|
||||||
{
|
{
|
||||||
headers[headers_count * 2 + 0] = "Sec-WebSocket-Accept";
|
headers[headers_count * 2 + 0] = "Sec-WebSocket-Accept";
|
||||||
|
@ -63,7 +63,6 @@ static void _start_initial_load(WKWebView* web_view)
|
|||||||
[self presentViewController:alertController animated:YES completion:^ {}];
|
[self presentViewController:alertController animated:YES completion:^ {}];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
- (void)webView:(WKWebView*)webView
|
- (void)webView:(WKWebView*)webView
|
||||||
runJavaScriptTextInputPanelWithPrompt:(NSString*)prompt
|
runJavaScriptTextInputPanelWithPrompt:(NSString*)prompt
|
||||||
defaultText:(NSString*)defaultText
|
defaultText:(NSString*)defaultText
|
||||||
@ -77,9 +76,7 @@ static void _start_initial_load(WKWebView* web_view)
|
|||||||
textField.placeholder = defaultText;
|
textField.placeholder = defaultText;
|
||||||
textField.text = defaultText;
|
textField.text = defaultText;
|
||||||
}];
|
}];
|
||||||
[alertController addAction:[UIAlertAction actionWithTitle:@"OK"
|
[alertController addAction:[UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleDefault handler:^(UIAlertAction* action) {
|
||||||
style:UIAlertActionStyleDefault
|
|
||||||
handler:^(UIAlertAction* action) {
|
|
||||||
NSString* input = ((UITextField*)alertController.textFields.firstObject).text;
|
NSString* input = ((UITextField*)alertController.textFields.firstObject).text;
|
||||||
completionHandler(input);
|
completionHandler(input);
|
||||||
}]];
|
}]];
|
||||||
|
@ -117,8 +117,7 @@ static int _tf_command_test(const char* file, int argc, char* argv[])
|
|||||||
const char** extras = NULL;
|
const char** extras = NULL;
|
||||||
int extra_count = 0;
|
int extra_count = 0;
|
||||||
const char* err = NULL;
|
const char* err = NULL;
|
||||||
XOPT_PARSE(
|
XOPT_PARSE(file, XOPT_CTX_KEEPFIRST | XOPT_CTX_STRICT, options, &args, argc, (const char**)argv, &extra_count, &extras, &err, stderr, "test [options]", "options:", NULL, 15);
|
||||||
file, XOPT_CTX_KEEPFIRST | XOPT_CTX_STRICT, options, &args, argc, (const char**)argv, &extra_count, &extras, &err, stderr, "test [options]", "options:", NULL, 15);
|
|
||||||
if (err)
|
if (err)
|
||||||
{
|
{
|
||||||
fprintf(stderr, "Error: %s\n", err);
|
fprintf(stderr, "Error: %s\n", err);
|
||||||
|
@ -451,16 +451,14 @@ static void _socket_onResolvedForBind(uv_getaddrinfo_t* resolver, int status, st
|
|||||||
socket_resolve_data_t* data = (socket_resolve_data_t*)resolver->data;
|
socket_resolve_data_t* data = (socket_resolve_data_t*)resolver->data;
|
||||||
if (status != 0)
|
if (status != 0)
|
||||||
{
|
{
|
||||||
tf_task_reject_promise(
|
tf_task_reject_promise(data->socket->_task, data->promise, JS_ThrowInternalError(tf_task_get_context(data->socket->_task), "uv_getaddrinfo: %s", uv_strerror(status)));
|
||||||
data->socket->_task, data->promise, JS_ThrowInternalError(tf_task_get_context(data->socket->_task), "uv_getaddrinfo: %s", uv_strerror(status)));
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
int bindResult = uv_tcp_bind(&data->socket->_socket, result->ai_addr, 0);
|
int bindResult = uv_tcp_bind(&data->socket->_socket, result->ai_addr, 0);
|
||||||
if (bindResult != 0)
|
if (bindResult != 0)
|
||||||
{
|
{
|
||||||
tf_task_reject_promise(
|
tf_task_reject_promise(data->socket->_task, data->promise, JS_ThrowInternalError(tf_task_get_context(data->socket->_task), "uv_tcp_bind: %s", uv_strerror(bindResult)));
|
||||||
data->socket->_task, data->promise, JS_ThrowInternalError(tf_task_get_context(data->socket->_task), "uv_tcp_bind: %s", uv_strerror(bindResult)));
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
34
src/ssb.c
34
src/ssb.c
@ -482,8 +482,7 @@ static void _tf_ssb_write(tf_ssb_connection_t* connection, void* data, size_t si
|
|||||||
}
|
}
|
||||||
else if (connection->tunnel_connection)
|
else if (connection->tunnel_connection)
|
||||||
{
|
{
|
||||||
tf_ssb_connection_rpc_send(
|
tf_ssb_connection_rpc_send(connection->tunnel_connection, k_ssb_rpc_flag_binary | k_ssb_rpc_flag_stream, -connection->tunnel_request_number, data, size, NULL, NULL, NULL);
|
||||||
connection->tunnel_connection, k_ssb_rpc_flag_binary | k_ssb_rpc_flag_stream, -connection->tunnel_request_number, data, size, NULL, NULL, NULL);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -556,7 +555,6 @@ static void _tf_ssb_connection_send_identity(tf_ssb_connection_t* connection, ui
|
|||||||
connection->state = k_tf_ssb_state_sent_identity;
|
connection->state = k_tf_ssb_state_sent_identity;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static void _tf_ssb_nonce_inc(uint8_t* nonce)
|
static void _tf_ssb_nonce_inc(uint8_t* nonce)
|
||||||
{
|
{
|
||||||
int i = 23;
|
int i = 23;
|
||||||
@ -773,9 +771,9 @@ void tf_ssb_connection_rpc_send(tf_ssb_connection_t* connection, uint8_t flags,
|
|||||||
memcpy(combined + 1 + 2 * sizeof(uint32_t), message, size);
|
memcpy(combined + 1 + 2 * sizeof(uint32_t), message, size);
|
||||||
if (connection->ssb->verbose)
|
if (connection->ssb->verbose)
|
||||||
{
|
{
|
||||||
tf_printf(MAGENTA "%s RPC SEND" RESET " end/error=%s stream=%s type=%s RN=%d: [%zd B] %.*s\n", connection->name,
|
tf_printf(MAGENTA "%s RPC SEND" RESET " end/error=%s stream=%s type=%s RN=%d: [%zd B] %.*s\n", connection->name, (flags & k_ssb_rpc_flag_end_error) ? "true" : "false",
|
||||||
(flags & k_ssb_rpc_flag_end_error) ? "true" : "false", (flags & k_ssb_rpc_flag_stream) ? "true" : "false", k_ssb_type_names[flags & k_ssb_rpc_mask_type],
|
(flags & k_ssb_rpc_flag_stream) ? "true" : "false", k_ssb_type_names[flags & k_ssb_rpc_mask_type], request_number, size,
|
||||||
request_number, size, (flags & k_ssb_rpc_mask_type) == k_ssb_rpc_flag_binary ? 0 : (int)size, message);
|
(flags & k_ssb_rpc_mask_type) == k_ssb_rpc_flag_binary ? 0 : (int)size, message);
|
||||||
}
|
}
|
||||||
_tf_ssb_connection_add_debug_message(connection, true, flags & k_ssb_rpc_mask_send, request_number, message, size);
|
_tf_ssb_connection_add_debug_message(connection, true, flags & k_ssb_rpc_mask_send, request_number, message, size);
|
||||||
_tf_ssb_connection_box_stream_send(connection, combined, 1 + 2 * sizeof(uint32_t) + size);
|
_tf_ssb_connection_box_stream_send(connection, combined, 1 + 2 * sizeof(uint32_t) + size);
|
||||||
@ -798,8 +796,7 @@ void tf_ssb_connection_rpc_send_json(
|
|||||||
JSValue json = JS_JSONStringify(context, message, JS_NULL, JS_NULL);
|
JSValue json = JS_JSONStringify(context, message, JS_NULL, JS_NULL);
|
||||||
size_t size = 0;
|
size_t size = 0;
|
||||||
const char* json_string = JS_ToCStringLen(context, &size, json);
|
const char* json_string = JS_ToCStringLen(context, &size, json);
|
||||||
tf_ssb_connection_rpc_send(
|
tf_ssb_connection_rpc_send(connection, k_ssb_rpc_flag_json | (flags & ~k_ssb_rpc_mask_type), request_number, (const uint8_t*)json_string, size, callback, cleanup, user_data);
|
||||||
connection, k_ssb_rpc_flag_json | (flags & ~k_ssb_rpc_mask_type), request_number, (const uint8_t*)json_string, size, callback, cleanup, user_data);
|
|
||||||
JS_FreeCString(context, json_string);
|
JS_FreeCString(context, json_string);
|
||||||
JS_FreeValue(context, json);
|
JS_FreeValue(context, json);
|
||||||
}
|
}
|
||||||
@ -1528,9 +1525,8 @@ static void _tf_ssb_connection_rpc_recv(tf_ssb_connection_t* connection, uint8_t
|
|||||||
tf_ssb_id_bin_to_str(id, sizeof(id), connection->serverpub);
|
tf_ssb_id_bin_to_str(id, sizeof(id), connection->serverpub);
|
||||||
if (connection->ssb->verbose)
|
if (connection->ssb->verbose)
|
||||||
{
|
{
|
||||||
tf_printf(CYAN "%s RPC RECV" RESET " end/error=%s stream=%s type=%s RN=%d: [%zd B] %.*s\n", connection->name,
|
tf_printf(CYAN "%s RPC RECV" RESET " end/error=%s stream=%s type=%s RN=%d: [%zd B] %.*s\n", connection->name, (flags & k_ssb_rpc_flag_end_error) ? "true" : "false",
|
||||||
(flags & k_ssb_rpc_flag_end_error) ? "true" : "false", (flags & k_ssb_rpc_flag_stream) ? "true" : "false",
|
(flags & k_ssb_rpc_flag_stream) ? "true" : "false", k_ssb_type_names[flags & k_ssb_rpc_mask_type], request_number, size, (int)size, message);
|
||||||
k_ssb_type_names[flags & k_ssb_rpc_mask_type], request_number, size, (int)size, message);
|
|
||||||
}
|
}
|
||||||
JSContext* context = connection->ssb->context;
|
JSContext* context = connection->ssb->context;
|
||||||
JSValue val = JS_ParseJSON(context, (const char*)message, size, NULL);
|
JSValue val = JS_ParseJSON(context, (const char*)message, size, NULL);
|
||||||
@ -1589,9 +1585,8 @@ static void _tf_ssb_connection_rpc_recv(tf_ssb_connection_t* connection, uint8_t
|
|||||||
{
|
{
|
||||||
if (connection->ssb->verbose)
|
if (connection->ssb->verbose)
|
||||||
{
|
{
|
||||||
tf_printf(CYAN "%s RPC RECV" RESET " end/error=%s stream=%s type=%s RN=%d: [%zd B]\n", connection->name,
|
tf_printf(CYAN "%s RPC RECV" RESET " end/error=%s stream=%s type=%s RN=%d: [%zd B]\n", connection->name, (flags & k_ssb_rpc_flag_end_error) ? "true" : "false",
|
||||||
(flags & k_ssb_rpc_flag_end_error) ? "true" : "false", (flags & k_ssb_rpc_flag_stream) ? "true" : "false",
|
(flags & k_ssb_rpc_flag_stream) ? "true" : "false", k_ssb_type_names[flags & k_ssb_rpc_mask_type], request_number, size);
|
||||||
k_ssb_type_names[flags & k_ssb_rpc_mask_type], request_number, size);
|
|
||||||
}
|
}
|
||||||
tf_ssb_rpc_callback_t* callback = NULL;
|
tf_ssb_rpc_callback_t* callback = NULL;
|
||||||
void* user_data = NULL;
|
void* user_data = NULL;
|
||||||
@ -1700,8 +1695,7 @@ static bool _tf_ssb_connection_box_stream_recv(tf_ssb_connection_t* connection)
|
|||||||
memcpy(connection->box_stream_buf, connection->body_auth_tag, sizeof(connection->body_auth_tag));
|
memcpy(connection->box_stream_buf, connection->body_auth_tag, sizeof(connection->body_auth_tag));
|
||||||
if (_tf_ssb_connection_recv_pop(connection, connection->box_stream_buf + 16, connection->body_len))
|
if (_tf_ssb_connection_recv_pop(connection, connection->box_stream_buf + 16, connection->body_len))
|
||||||
{
|
{
|
||||||
if (crypto_secretbox_open_easy(
|
if (crypto_secretbox_open_easy(connection->secretbox_buf, connection->box_stream_buf, 16 + connection->body_len, connection->nonce, connection->s_to_c_box_key) != 0)
|
||||||
connection->secretbox_buf, connection->box_stream_buf, 16 + connection->body_len, connection->nonce, connection->s_to_c_box_key) != 0)
|
|
||||||
{
|
{
|
||||||
_tf_ssb_connection_close(connection, "failed to open secret box");
|
_tf_ssb_connection_close(connection, "failed to open secret box");
|
||||||
return false;
|
return false;
|
||||||
@ -3370,8 +3364,8 @@ void tf_ssb_notify_message_added(tf_ssb_t* ssb, const char* id, JSValue message_
|
|||||||
{
|
{
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
tf_ssb_connection_message_request_t* message_request = bsearch(
|
tf_ssb_connection_message_request_t* message_request =
|
||||||
author_string, connection->message_requests, connection->message_requests_count, sizeof(tf_ssb_connection_message_request_t), _message_request_compare);
|
bsearch(author_string, connection->message_requests, connection->message_requests_count, sizeof(tf_ssb_connection_message_request_t), _message_request_compare);
|
||||||
if (message_request)
|
if (message_request)
|
||||||
{
|
{
|
||||||
tf_ssb_connection_rpc_send_json(
|
tf_ssb_connection_rpc_send_json(
|
||||||
@ -3625,8 +3619,8 @@ JSValue tf_ssb_get_disconnection_debug(tf_ssb_t* ssb, JSContext* context)
|
|||||||
JS_SetPropertyStr(context, message, "flags", JS_NewInt32(context, ssb->debug_close[i].messages[j]->flags));
|
JS_SetPropertyStr(context, message, "flags", JS_NewInt32(context, ssb->debug_close[i].messages[j]->flags));
|
||||||
JS_SetPropertyStr(context, message, "request_number", JS_NewInt32(context, ssb->debug_close[i].messages[j]->request_number));
|
JS_SetPropertyStr(context, message, "request_number", JS_NewInt32(context, ssb->debug_close[i].messages[j]->request_number));
|
||||||
JS_SetPropertyStr(context, message, "timestamp", JS_NewFloat64(context, ssb->debug_close[i].messages[j]->timestamp));
|
JS_SetPropertyStr(context, message, "timestamp", JS_NewFloat64(context, ssb->debug_close[i].messages[j]->timestamp));
|
||||||
JS_SetPropertyStr(context, message, "payload",
|
JS_SetPropertyStr(
|
||||||
JS_NewStringLen(context, (const char*)ssb->debug_close[i].messages[j]->data, ssb->debug_close[i].messages[j]->size));
|
context, message, "payload", JS_NewStringLen(context, (const char*)ssb->debug_close[i].messages[j]->data, ssb->debug_close[i].messages[j]->size));
|
||||||
JS_SetPropertyUint32(context, messages, j, message);
|
JS_SetPropertyUint32(context, messages, j, message);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -53,8 +53,8 @@ static bool _tf_ssb_connections_get_next_connection(tf_ssb_connections_t* connec
|
|||||||
bool result = false;
|
bool result = false;
|
||||||
sqlite3_stmt* statement;
|
sqlite3_stmt* statement;
|
||||||
sqlite3* db = tf_ssb_acquire_db_reader(connections->ssb);
|
sqlite3* db = tf_ssb_acquire_db_reader(connections->ssb);
|
||||||
if (sqlite3_prepare(db, "SELECT host, port, key FROM connections WHERE last_attempt IS NULL OR (strftime('%s', 'now') - last_attempt > ?1) ORDER BY last_attempt LIMIT 1",
|
if (sqlite3_prepare(db, "SELECT host, port, key FROM connections WHERE last_attempt IS NULL OR (strftime('%s', 'now') - last_attempt > ?1) ORDER BY last_attempt LIMIT 1", -1,
|
||||||
-1, &statement, NULL) == SQLITE_OK)
|
&statement, NULL) == SQLITE_OK)
|
||||||
{
|
{
|
||||||
if (sqlite3_bind_int(statement, 1, 60000) == SQLITE_OK && sqlite3_step(statement) == SQLITE_ROW)
|
if (sqlite3_bind_int(statement, 1, 60000) == SQLITE_OK && sqlite3_step(statement) == SQLITE_ROW)
|
||||||
{
|
{
|
||||||
@ -179,8 +179,7 @@ static void _tf_ssb_connections_update_work(uv_work_t* work)
|
|||||||
sqlite3* db = tf_ssb_acquire_db_writer(update->ssb);
|
sqlite3* db = tf_ssb_acquire_db_writer(update->ssb);
|
||||||
if (update->attempted)
|
if (update->attempted)
|
||||||
{
|
{
|
||||||
if (sqlite3_prepare(db, "UPDATE connections SET last_attempt = strftime('%s', 'now') WHERE host = ?1 AND port = ?2 AND key = ?3", -1, &statement, NULL) ==
|
if (sqlite3_prepare(db, "UPDATE connections SET last_attempt = strftime('%s', 'now') WHERE host = ?1 AND port = ?2 AND key = ?3", -1, &statement, NULL) == SQLITE_OK)
|
||||||
SQLITE_OK)
|
|
||||||
{
|
{
|
||||||
if (sqlite3_bind_text(statement, 1, update->host, -1, NULL) == SQLITE_OK && sqlite3_bind_int(statement, 2, update->port) == SQLITE_OK &&
|
if (sqlite3_bind_text(statement, 1, update->host, -1, NULL) == SQLITE_OK && sqlite3_bind_int(statement, 2, update->port) == SQLITE_OK &&
|
||||||
sqlite3_bind_text(statement, 3, update->key, -1, NULL) == SQLITE_OK)
|
sqlite3_bind_text(statement, 3, update->key, -1, NULL) == SQLITE_OK)
|
||||||
@ -195,8 +194,7 @@ static void _tf_ssb_connections_update_work(uv_work_t* work)
|
|||||||
}
|
}
|
||||||
else if (update->succeeded)
|
else if (update->succeeded)
|
||||||
{
|
{
|
||||||
if (sqlite3_prepare(db, "UPDATE connections SET last_success = strftime('%s', 'now') WHERE host = ?1 AND port = ?2 AND key = ?3", -1, &statement, NULL) ==
|
if (sqlite3_prepare(db, "UPDATE connections SET last_success = strftime('%s', 'now') WHERE host = ?1 AND port = ?2 AND key = ?3", -1, &statement, NULL) == SQLITE_OK)
|
||||||
SQLITE_OK)
|
|
||||||
{
|
{
|
||||||
if (sqlite3_bind_text(statement, 1, update->host, -1, NULL) == SQLITE_OK && sqlite3_bind_int(statement, 2, update->port) == SQLITE_OK &&
|
if (sqlite3_bind_text(statement, 1, update->host, -1, NULL) == SQLITE_OK && sqlite3_bind_int(statement, 2, update->port) == SQLITE_OK &&
|
||||||
sqlite3_bind_text(statement, 3, update->key, -1, NULL) == SQLITE_OK)
|
sqlite3_bind_text(statement, 3, update->key, -1, NULL) == SQLITE_OK)
|
||||||
|
18
src/ssb.db.c
18
src/ssb.db.c
@ -165,8 +165,7 @@ void tf_ssb_db_init(tf_ssb_t* ssb)
|
|||||||
tf_printf("Done.\n");
|
tf_printf("Done.\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
_tf_ssb_db_exec(
|
_tf_ssb_db_exec(db, "CREATE TRIGGER IF NOT EXISTS messages_ai AFTER INSERT ON messages BEGIN INSERT INTO messages_fts(rowid, content) VALUES (new.rowid, new.content); END");
|
||||||
db, "CREATE TRIGGER IF NOT EXISTS messages_ai AFTER INSERT ON messages BEGIN INSERT INTO messages_fts(rowid, content) VALUES (new.rowid, new.content); END");
|
|
||||||
_tf_ssb_db_exec(db,
|
_tf_ssb_db_exec(db,
|
||||||
"CREATE TRIGGER IF NOT EXISTS messages_ad AFTER DELETE ON messages BEGIN INSERT INTO messages_fts(messages_fts, rowid, content) VALUES ('delete', old.rowid, "
|
"CREATE TRIGGER IF NOT EXISTS messages_ad AFTER DELETE ON messages BEGIN INSERT INTO messages_fts(messages_fts, rowid, content) VALUES ('delete', old.rowid, "
|
||||||
"old.content); END");
|
"old.content); END");
|
||||||
@ -722,8 +721,7 @@ bool tf_ssb_db_blob_store(tf_ssb_t* ssb, const uint8_t* blob, size_t size, char*
|
|||||||
|
|
||||||
sqlite3* db = tf_ssb_acquire_db_writer(ssb);
|
sqlite3* db = tf_ssb_acquire_db_writer(ssb);
|
||||||
sqlite3_stmt* statement;
|
sqlite3_stmt* statement;
|
||||||
if (sqlite3_prepare(db, "INSERT INTO blobs (id, content, created) VALUES (?1, ?2, CAST(strftime('%s') AS INTEGER)) ON CONFLICT DO NOTHING", -1, &statement, NULL) ==
|
if (sqlite3_prepare(db, "INSERT INTO blobs (id, content, created) VALUES (?1, ?2, CAST(strftime('%s') AS INTEGER)) ON CONFLICT DO NOTHING", -1, &statement, NULL) == SQLITE_OK)
|
||||||
SQLITE_OK)
|
|
||||||
{
|
{
|
||||||
if (sqlite3_bind_text(statement, 1, id, -1, NULL) == SQLITE_OK && sqlite3_bind_blob(statement, 2, blob, size, NULL) == SQLITE_OK)
|
if (sqlite3_bind_text(statement, 1, id, -1, NULL) == SQLITE_OK && sqlite3_bind_blob(statement, 2, blob, size, NULL) == SQLITE_OK)
|
||||||
{
|
{
|
||||||
@ -770,8 +768,7 @@ bool tf_ssb_db_get_message_by_author_and_sequence(
|
|||||||
sqlite3* db = tf_ssb_acquire_db_reader(ssb);
|
sqlite3* db = tf_ssb_acquire_db_reader(ssb);
|
||||||
if (sqlite3_prepare(db, query, -1, &statement, NULL) == SQLITE_OK)
|
if (sqlite3_prepare(db, query, -1, &statement, NULL) == SQLITE_OK)
|
||||||
{
|
{
|
||||||
if (sqlite3_bind_text(statement, 1, author, -1, NULL) == SQLITE_OK && sqlite3_bind_int64(statement, 2, sequence) == SQLITE_OK &&
|
if (sqlite3_bind_text(statement, 1, author, -1, NULL) == SQLITE_OK && sqlite3_bind_int64(statement, 2, sequence) == SQLITE_OK && sqlite3_step(statement) == SQLITE_ROW)
|
||||||
sqlite3_step(statement) == SQLITE_ROW)
|
|
||||||
{
|
{
|
||||||
if (out_message_id)
|
if (out_message_id)
|
||||||
{
|
{
|
||||||
@ -927,9 +924,8 @@ int tf_ssb_sqlite_authorizer(void* user_data, int action_code, const char* arg0,
|
|||||||
break;
|
break;
|
||||||
case SQLITE_READ:
|
case SQLITE_READ:
|
||||||
result = (strcmp(arg0, "blob_wants_view") == 0 || strcmp(arg0, "json_each") == 0 || strcmp(arg0, "json_tree") == 0 || strcmp(arg0, "messages") == 0 ||
|
result = (strcmp(arg0, "blob_wants_view") == 0 || strcmp(arg0, "json_each") == 0 || strcmp(arg0, "json_tree") == 0 || strcmp(arg0, "messages") == 0 ||
|
||||||
strcmp(arg0, "messages_fts") == 0 || strcmp(arg0, "messages_fts_idx") == 0 || strcmp(arg0, "messages_fts_config") == 0 ||
|
strcmp(arg0, "messages_fts") == 0 || strcmp(arg0, "messages_fts_idx") == 0 || strcmp(arg0, "messages_fts_config") == 0 || strcmp(arg0, "messages_refs") == 0 ||
|
||||||
strcmp(arg0, "messages_refs") == 0 || strcmp(arg0, "messages_refs_message_idx") == 0 || strcmp(arg0, "messages_refs_ref_idx") == 0 ||
|
strcmp(arg0, "messages_refs_message_idx") == 0 || strcmp(arg0, "messages_refs_ref_idx") == 0 || strcmp(arg0, "sqlite_master") == 0 || false)
|
||||||
strcmp(arg0, "sqlite_master") == 0 || false)
|
|
||||||
? SQLITE_OK
|
? SQLITE_OK
|
||||||
: SQLITE_DENY;
|
: SQLITE_DENY;
|
||||||
break;
|
break;
|
||||||
@ -1485,8 +1481,8 @@ JSValue tf_ssb_db_get_message_by_id(tf_ssb_t* ssb, const char* id, bool is_keys)
|
|||||||
JSContext* context = tf_ssb_get_context(ssb);
|
JSContext* context = tf_ssb_get_context(ssb);
|
||||||
sqlite3* db = tf_ssb_acquire_db_reader(ssb);
|
sqlite3* db = tf_ssb_acquire_db_reader(ssb);
|
||||||
sqlite3_stmt* statement;
|
sqlite3_stmt* statement;
|
||||||
if (sqlite3_prepare(db, "SELECT previous, author, id, sequence, timestamp, hash, content, signature, sequence_before_author FROM messages WHERE id = ?", -1, &statement,
|
if (sqlite3_prepare(
|
||||||
NULL) == SQLITE_OK)
|
db, "SELECT previous, author, id, sequence, timestamp, hash, content, signature, sequence_before_author FROM messages WHERE id = ?", -1, &statement, NULL) == SQLITE_OK)
|
||||||
{
|
{
|
||||||
if (sqlite3_bind_text(statement, 1, id, -1, NULL) == SQLITE_OK)
|
if (sqlite3_bind_text(statement, 1, id, -1, NULL) == SQLITE_OK)
|
||||||
{
|
{
|
||||||
|
@ -92,8 +92,7 @@ void tf_ssb_export(tf_ssb_t* ssb, const char* key)
|
|||||||
sqlite3_stmt* statement;
|
sqlite3_stmt* statement;
|
||||||
if (sqlite3_prepare(db, "SELECT value FROM properties WHERE id = ?1 AND key = 'path:' || ?2", -1, &statement, NULL) == SQLITE_OK)
|
if (sqlite3_prepare(db, "SELECT value FROM properties WHERE id = ?1 AND key = 'path:' || ?2", -1, &statement, NULL) == SQLITE_OK)
|
||||||
{
|
{
|
||||||
if (sqlite3_bind_text(statement, 1, user, -1, NULL) == SQLITE_OK && sqlite3_bind_text(statement, 2, path, -1, NULL) == SQLITE_OK &&
|
if (sqlite3_bind_text(statement, 1, user, -1, NULL) == SQLITE_OK && sqlite3_bind_text(statement, 2, path, -1, NULL) == SQLITE_OK && sqlite3_step(statement) == SQLITE_ROW)
|
||||||
sqlite3_step(statement) == SQLITE_ROW)
|
|
||||||
{
|
{
|
||||||
int len = sqlite3_column_bytes(statement, 0);
|
int len = sqlite3_column_bytes(statement, 0);
|
||||||
if (len >= (int)sizeof(app_blob_id))
|
if (len >= (int)sizeof(app_blob_id))
|
||||||
|
@ -70,8 +70,7 @@ static void _tf_ssb_import_add_app(tf_ssb_t* ssb, const char* user, const char*
|
|||||||
const char* text = JS_ToCString(context, json);
|
const char* text = JS_ToCString(context, json);
|
||||||
if (sqlite3_prepare(db, "INSERT OR REPLACE INTO properties (id, key, value) VALUES (?1, 'apps', ?2)", -1, &statement, NULL) == SQLITE_OK)
|
if (sqlite3_prepare(db, "INSERT OR REPLACE INTO properties (id, key, value) VALUES (?1, 'apps', ?2)", -1, &statement, NULL) == SQLITE_OK)
|
||||||
{
|
{
|
||||||
if (sqlite3_bind_text(statement, 1, user, -1, NULL) == SQLITE_OK && sqlite3_bind_text(statement, 2, text, -1, NULL) == SQLITE_OK &&
|
if (sqlite3_bind_text(statement, 1, user, -1, NULL) == SQLITE_OK && sqlite3_bind_text(statement, 2, text, -1, NULL) == SQLITE_OK && sqlite3_step(statement) == SQLITE_OK)
|
||||||
sqlite3_step(statement) == SQLITE_OK)
|
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
sqlite3_finalize(statement);
|
sqlite3_finalize(statement);
|
||||||
|
@ -1404,14 +1404,12 @@ static bool _tf_ssb_get_private_key_curve25519(sqlite3* db, const char* user, co
|
|||||||
sqlite3_stmt* statement = NULL;
|
sqlite3_stmt* statement = NULL;
|
||||||
if (sqlite3_prepare(db, "SELECT private_key FROM identities WHERE user = ? AND public_key = ?", -1, &statement, NULL) == SQLITE_OK)
|
if (sqlite3_prepare(db, "SELECT private_key FROM identities WHERE user = ? AND public_key = ?", -1, &statement, NULL) == SQLITE_OK)
|
||||||
{
|
{
|
||||||
if (sqlite3_bind_text(statement, 1, user, -1, NULL) == SQLITE_OK &&
|
if (sqlite3_bind_text(statement, 1, user, -1, NULL) == SQLITE_OK && sqlite3_bind_text(statement, 2, *identity == '@' ? identity + 1 : identity, -1, NULL) == SQLITE_OK)
|
||||||
sqlite3_bind_text(statement, 2, *identity == '@' ? identity + 1 : identity, -1, NULL) == SQLITE_OK)
|
|
||||||
{
|
{
|
||||||
while (sqlite3_step(statement) == SQLITE_ROW)
|
while (sqlite3_step(statement) == SQLITE_ROW)
|
||||||
{
|
{
|
||||||
uint8_t key[crypto_sign_SECRETKEYBYTES] = { 0 };
|
uint8_t key[crypto_sign_SECRETKEYBYTES] = { 0 };
|
||||||
int length =
|
int length = tf_base64_decode((const char*)sqlite3_column_text(statement, 0), sqlite3_column_bytes(statement, 0) - strlen(".ed25519"), key, sizeof(key));
|
||||||
tf_base64_decode((const char*)sqlite3_column_text(statement, 0), sqlite3_column_bytes(statement, 0) - strlen(".ed25519"), key, sizeof(key));
|
|
||||||
if (length == crypto_sign_SECRETKEYBYTES)
|
if (length == crypto_sign_SECRETKEYBYTES)
|
||||||
{
|
{
|
||||||
success = crypto_sign_ed25519_sk_to_curve25519(out_private_key, key) == 0;
|
success = crypto_sign_ed25519_sk_to_curve25519(out_private_key, key) == 0;
|
||||||
|
@ -111,8 +111,8 @@ static void _tf_ssb_rpc_blobs_get(tf_ssb_connection_t* connection, uint8_t flags
|
|||||||
JS_FreeValue(context, arg);
|
JS_FreeValue(context, arg);
|
||||||
}
|
}
|
||||||
JS_FreeValue(context, ids);
|
JS_FreeValue(context, ids);
|
||||||
tf_ssb_connection_rpc_send(connection, k_ssb_rpc_flag_json | k_ssb_rpc_flag_end_error | k_ssb_rpc_flag_stream, -request_number,
|
tf_ssb_connection_rpc_send(connection, k_ssb_rpc_flag_json | k_ssb_rpc_flag_end_error | k_ssb_rpc_flag_stream, -request_number, (const uint8_t*)(success ? "true" : "false"),
|
||||||
(const uint8_t*)(success ? "true" : "false"), strlen(success ? "true" : "false"), NULL, NULL, NULL);
|
strlen(success ? "true" : "false"), NULL, NULL, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void _tf_ssb_rpc_blobs_has(tf_ssb_connection_t* connection, uint8_t flags, int32_t request_number, JSValue args, const uint8_t* message, size_t size, void* user_data)
|
static void _tf_ssb_rpc_blobs_has(tf_ssb_connection_t* connection, uint8_t flags, int32_t request_number, JSValue args, const uint8_t* message, size_t size, void* user_data)
|
||||||
@ -436,8 +436,8 @@ static void _tf_ssb_rpc_connection_blobs_get_callback(
|
|||||||
}
|
}
|
||||||
/* TODO: Should we send the response in the callback? */
|
/* TODO: Should we send the response in the callback? */
|
||||||
bool stored = true;
|
bool stored = true;
|
||||||
tf_ssb_connection_rpc_send(connection, k_ssb_rpc_flag_json | k_ssb_rpc_flag_stream | k_ssb_rpc_flag_end_error, -request_number,
|
tf_ssb_connection_rpc_send(connection, k_ssb_rpc_flag_json | k_ssb_rpc_flag_stream | k_ssb_rpc_flag_end_error, -request_number, (const uint8_t*)(stored ? "true" : "false"),
|
||||||
(const uint8_t*)(stored ? "true" : "false"), strlen(stored ? "true" : "false"), NULL, NULL, NULL);
|
strlen(stored ? "true" : "false"), NULL, NULL, NULL);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -678,7 +678,8 @@ static void _tf_ssb_connection_send_history_stream_work(tf_ssb_connection_t* con
|
|||||||
sqlite3_stmt* statement;
|
sqlite3_stmt* statement;
|
||||||
const int k_max = 32;
|
const int k_max = 32;
|
||||||
if (sqlite3_prepare(db,
|
if (sqlite3_prepare(db,
|
||||||
"SELECT previous, author, id, sequence, timestamp, hash, content, signature, sequence_before_author FROM messages WHERE author = ?1 AND sequence > ?2 AND sequence "
|
"SELECT previous, author, id, sequence, timestamp, hash, content, signature, sequence_before_author FROM messages WHERE author = ?1 AND sequence > ?2 AND "
|
||||||
|
"sequence "
|
||||||
"< ?3 ORDER BY sequence",
|
"< ?3 ORDER BY sequence",
|
||||||
-1, &statement, NULL) == SQLITE_OK)
|
-1, &statement, NULL) == SQLITE_OK)
|
||||||
{
|
{
|
||||||
@ -1102,8 +1103,8 @@ static void _tf_ssb_rpc_connections_changed_callback(tf_ssb_t* ssb, tf_ssb_chang
|
|||||||
JS_SetPropertyUint32(context, name, 1, JS_NewString(context, "isRoom"));
|
JS_SetPropertyUint32(context, name, 1, JS_NewString(context, "isRoom"));
|
||||||
JS_SetPropertyStr(context, message, "name", name);
|
JS_SetPropertyStr(context, message, "name", name);
|
||||||
JS_SetPropertyStr(context, message, "args", JS_NewArray(context));
|
JS_SetPropertyStr(context, message, "args", JS_NewArray(context));
|
||||||
tf_ssb_connection_rpc_send_json(connection, k_ssb_rpc_flag_new_request, tf_ssb_connection_next_request_number(connection), message,
|
tf_ssb_connection_rpc_send_json(
|
||||||
_tf_ssb_rpc_connection_tunnel_isRoom_callback, NULL, NULL);
|
connection, k_ssb_rpc_flag_new_request, tf_ssb_connection_next_request_number(connection), message, _tf_ssb_rpc_connection_tunnel_isRoom_callback, NULL, NULL);
|
||||||
JS_FreeValue(context, message);
|
JS_FreeValue(context, message);
|
||||||
|
|
||||||
_tf_ssb_rpc_send_ebt_replicate(connection);
|
_tf_ssb_rpc_send_ebt_replicate(connection);
|
||||||
@ -1125,8 +1126,7 @@ static void _tf_ssb_rpc_connections_changed_callback(tf_ssb_t* ssb, tf_ssb_chang
|
|||||||
{
|
{
|
||||||
if (tf_ssb_connection_is_attendant(connections[i]))
|
if (tf_ssb_connection_is_attendant(connections[i]))
|
||||||
{
|
{
|
||||||
tf_ssb_connection_rpc_send_json(
|
tf_ssb_connection_rpc_send_json(connections[i], k_ssb_rpc_flag_stream, -tf_ssb_connection_get_attendant_request_number(connections[i]), left, NULL, NULL, NULL);
|
||||||
connections[i], k_ssb_rpc_flag_stream, -tf_ssb_connection_get_attendant_request_number(connections[i]), left, NULL, NULL, NULL);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
JS_FreeValue(context, left);
|
JS_FreeValue(context, left);
|
||||||
|
@ -715,8 +715,8 @@ static void _close_callback(uv_timer_t* timer)
|
|||||||
close_t* data = timer->data;
|
close_t* data = timer->data;
|
||||||
tf_printf("breaking %s %p\n", data->id, data->connection);
|
tf_printf("breaking %s %p\n", data->id, data->connection);
|
||||||
const char* message = "{\"name\":\"Error\",\"message\":\"whoops\",\"stack\":\"nah\"}";
|
const char* message = "{\"name\":\"Error\",\"message\":\"whoops\",\"stack\":\"nah\"}";
|
||||||
tf_ssb_connection_rpc_send(data->connection, k_ssb_rpc_flag_stream | k_ssb_rpc_flag_json | k_ssb_rpc_flag_end_error, data->request_number, (const uint8_t*)message,
|
tf_ssb_connection_rpc_send(
|
||||||
strlen(message), NULL, NULL, NULL);
|
data->connection, k_ssb_rpc_flag_stream | k_ssb_rpc_flag_json | k_ssb_rpc_flag_end_error, data->request_number, (const uint8_t*)message, strlen(message), NULL, NULL, NULL);
|
||||||
uv_close((uv_handle_t*)timer, _timer_close);
|
uv_close((uv_handle_t*)timer, _timer_close);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -455,7 +455,6 @@ static tf_taskstub_t* _tf_task_get_stub(tf_task_t* task, taskid_t id)
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static JSValue _import_call(JSContext* context, JSValueConst func_obj, JSValueConst this_val, int argc, JSValueConst* argv, int flags)
|
static JSValue _import_call(JSContext* context, JSValueConst func_obj, JSValueConst this_val, int argc, JSValueConst* argv, int flags)
|
||||||
{
|
{
|
||||||
import_record_t* import = JS_GetOpaque(func_obj, _import_class_id);
|
import_record_t* import = JS_GetOpaque(func_obj, _import_class_id);
|
||||||
@ -1015,8 +1014,7 @@ void tf_task_on_receive_packet(int packetType, const char* begin, size_t length,
|
|||||||
memcpy(&promise, begin, sizeof(promise));
|
memcpy(&promise, begin, sizeof(promise));
|
||||||
memcpy(&exportId, begin + sizeof(promise), sizeof(exportId));
|
memcpy(&exportId, begin + sizeof(promise), sizeof(exportId));
|
||||||
|
|
||||||
JSValue result =
|
JSValue result = _task_invokeExport_internal(from, to, exportId, begin + sizeof(promiseid_t) + sizeof(exportid_t), length - sizeof(promiseid_t) - sizeof(exportid_t));
|
||||||
_task_invokeExport_internal(from, to, exportId, begin + sizeof(promiseid_t) + sizeof(exportid_t), length - sizeof(promiseid_t) - sizeof(exportid_t));
|
|
||||||
if (JS_IsException(result))
|
if (JS_IsException(result))
|
||||||
{
|
{
|
||||||
_tf_task_sendPromiseReject(to, from, promise, result);
|
_tf_task_sendPromiseReject(to, from, promise, result);
|
||||||
|
10
src/trace.c
10
src/trace.c
@ -298,8 +298,7 @@ static void _tf_trace_end_tagged(tf_trace_t* trace, void* tag)
|
|||||||
}
|
}
|
||||||
|
|
||||||
char line[1024];
|
char line[1024];
|
||||||
int p =
|
int p = snprintf(line, sizeof(line), "{\"ph\": \"E\", \"pid\": %d, \"tid\": %" PRId64 ", \"ts\": %" PRId64 ", \"name\": \"", getpid(), (int64_t)pthread_self(), _trace_ts());
|
||||||
snprintf(line, sizeof(line), "{\"ph\": \"E\", \"pid\": %d, \"tid\": %" PRId64 ", \"ts\": %" PRId64 ", \"name\": \"", getpid(), (int64_t)pthread_self(), _trace_ts());
|
|
||||||
p += _tf_trace_escape_name(line + p, sizeof(line) - p, name);
|
p += _tf_trace_escape_name(line + p, sizeof(line) - p, name);
|
||||||
p += snprintf(line + p, sizeof(line) - p, "\"},");
|
p += snprintf(line + p, sizeof(line) - p, "\"},");
|
||||||
p = tf_min(p, tf_countof(line));
|
p = tf_min(p, tf_countof(line));
|
||||||
@ -327,15 +326,14 @@ char* tf_trace_export(tf_trace_t* trace)
|
|||||||
size += snprintf(buffer, k_buffer_size, "{\"displayTimeUnit\": \"ns\",\n\"traceEvents\": [\n");
|
size += snprintf(buffer, k_buffer_size, "{\"displayTimeUnit\": \"ns\",\n\"traceEvents\": [\n");
|
||||||
if (*trace->process_name)
|
if (*trace->process_name)
|
||||||
{
|
{
|
||||||
size += snprintf(
|
size += snprintf(buffer + size, k_buffer_size - size, "{\"ph\":\"M\",\"pid\":%d,\"name\":\"process_name\",\"args\":{\"name\":\"%s\"}},\n", getpid(), trace->process_name);
|
||||||
buffer + size, k_buffer_size - size, "{\"ph\":\"M\",\"pid\":%d,\"name\":\"process_name\",\"args\":{\"name\":\"%s\"}},\n", getpid(), trace->process_name);
|
|
||||||
}
|
}
|
||||||
uv_rwlock_rdlock(&trace->threads_lock);
|
uv_rwlock_rdlock(&trace->threads_lock);
|
||||||
for (int i = 0; i < trace->threads_count; i++)
|
for (int i = 0; i < trace->threads_count; i++)
|
||||||
{
|
{
|
||||||
tf_trace_thread_t* thread = trace->threads[i];
|
tf_trace_thread_t* thread = trace->threads[i];
|
||||||
size += snprintf(buffer + size, k_buffer_size - size, "{\"ph\":\"M\",\"pid\":%d,\"tid\":%" PRId64 ",\"name\":\"thread_name\",\"args\":{\"name\":\"%s\"}},\n",
|
size += snprintf(buffer + size, k_buffer_size - size, "{\"ph\":\"M\",\"pid\":%d,\"tid\":%" PRId64 ",\"name\":\"thread_name\",\"args\":{\"name\":\"%s\"}},\n", getpid(),
|
||||||
getpid(), (uint64_t)thread->id, thread->name);
|
(uint64_t)thread->id, thread->name);
|
||||||
}
|
}
|
||||||
uv_rwlock_rdunlock(&trace->threads_lock);
|
uv_rwlock_rdunlock(&trace->threads_lock);
|
||||||
if (begin)
|
if (begin)
|
||||||
|
@ -273,8 +273,7 @@ static JSValue _util_parseHttpRequest(JSContext* context, JSValueConst this_val,
|
|||||||
|
|
||||||
if (array)
|
if (array)
|
||||||
{
|
{
|
||||||
int parse_result =
|
int parse_result = phr_parse_request((const char*)array, length, &method, &method_length, &path, &path_length, &minor_version, headers, &header_count, previous_length);
|
||||||
phr_parse_request((const char*)array, length, &method, &method_length, &path, &path_length, &minor_version, headers, &header_count, previous_length);
|
|
||||||
if (parse_result > 0)
|
if (parse_result > 0)
|
||||||
{
|
{
|
||||||
result = JS_NewObject(context);
|
result = JS_NewObject(context);
|
||||||
|
Loading…
Reference in New Issue
Block a user