Add missing statics, and remove the 'tildefriends check' command.

git-svn-id: https://www.unprompted.com/svn/projects/tildefriends/trunk@4838 ed5197a5-7fde-0310-b194-c3ffbd925b24
This commit is contained in:
Cory McWilliams 2024-02-10 16:50:00 +00:00
parent 51a327c52d
commit 6c5a7b0751
17 changed files with 93 additions and 304 deletions

View File

@ -890,16 +890,6 @@ function enableStats(process, enabled) {
} }
} }
function stringResponse(response, data) {
let bytes = utf8Encode(data);
response.writeHead(200, {
"Content-Type": "application/json; charset=utf-8",
"Content-Length": bytes.byteLength.toString(),
"Access-Control-Allow-Origin": "*",
});
return response.end(bytes);
}
loadSettings().then(function() { loadSettings().then(function() {
if (tildefriends.https_port && gGlobalSettings.http_redirect) { if (tildefriends.https_port && gGlobalSettings.http_redirect) {
httpd.set_http_redirect(gGlobalSettings.http_redirect); httpd.set_http_redirect(gGlobalSettings.http_redirect);

View File

@ -3,25 +3,10 @@
#include "task.h" #include "task.h"
#include "ow-crypt.h" #include "ow-crypt.h"
#include "quickjs.h" #include "quickjs.h"
#include "uv.h"
#include <uv.h> static JSValue _crypt_hashpw(JSContext* context, JSValueConst this_val, int argc, JSValueConst* argv)
JSValue _crypt_hashpw(JSContext* context, JSValueConst this_val, int argc, JSValueConst* argv);
JSValue _crypt_gensalt(JSContext* context, JSValueConst this_val, int argc, JSValueConst* argv);
void tf_bcrypt_register(JSContext* context)
{
JSValue global = JS_GetGlobalObject(context);
JSValue bcrypt = JS_NewObject(context);
JS_SetPropertyStr(context, global, "bCrypt", bcrypt);
JS_SetPropertyStr(context, bcrypt, "hashpw", JS_NewCFunction(context, _crypt_hashpw, "hashpw", 2));
JS_SetPropertyStr(context, bcrypt, "gensalt", JS_NewCFunction(context, _crypt_gensalt, "gensalt", 1));
JS_FreeValue(context, global);
}
JSValue _crypt_hashpw(JSContext* context, JSValueConst this_val, int argc, JSValueConst* argv)
{ {
const char* key = JS_ToCString(context, argv[0]); const char* key = JS_ToCString(context, argv[0]);
const char* salt = JS_ToCString(context, argv[1]); const char* salt = JS_ToCString(context, argv[1]);
@ -33,7 +18,7 @@ JSValue _crypt_hashpw(JSContext* context, JSValueConst this_val, int argc, JSVal
return result; return result;
} }
JSValue _crypt_gensalt(JSContext* context, JSValueConst this_val, int argc, JSValueConst* argv) static JSValue _crypt_gensalt(JSContext* context, JSValueConst this_val, int argc, JSValueConst* argv)
{ {
int length = 0; int length = 0;
JS_ToInt32(context, &length, argv[0]); JS_ToInt32(context, &length, argv[0]);
@ -45,3 +30,13 @@ JSValue _crypt_gensalt(JSContext* context, JSValueConst this_val, int argc, JSVa
JSValue result = JS_NewString(context, salt); JSValue result = JS_NewString(context, salt);
return result; return result;
} }
void tf_bcrypt_register(JSContext* context)
{
JSValue global = JS_GetGlobalObject(context);
JSValue bcrypt = JS_NewObject(context);
JS_SetPropertyStr(context, global, "bCrypt", bcrypt);
JS_SetPropertyStr(context, bcrypt, "hashpw", JS_NewCFunction(context, _crypt_hashpw, "hashpw", 2));
JS_SetPropertyStr(context, bcrypt, "gensalt", JS_NewCFunction(context, _crypt_gensalt, "gensalt", 1));
JS_FreeValue(context, global);
}

View File

@ -120,7 +120,7 @@ static JSValue _database_get(JSContext* context, JSValueConst this_val, int argc
return entry; return entry;
} }
JSValue _database_set(JSContext* context, JSValueConst this_val, int argc, JSValueConst* argv) static JSValue _database_set(JSContext* context, JSValueConst this_val, int argc, JSValueConst* argv)
{ {
database_t* database = JS_GetOpaque(this_val, _database_class_id); database_t* database = JS_GetOpaque(this_val, _database_class_id);
if (database) if (database)
@ -204,7 +204,7 @@ static JSValue _database_exchange(JSContext* context, JSValueConst this_val, int
return exchanged; return exchanged;
} }
JSValue _database_remove(JSContext* context, JSValueConst this_val, int argc, JSValueConst* argv) static JSValue _database_remove(JSContext* context, JSValueConst this_val, int argc, JSValueConst* argv)
{ {
database_t* database = JS_GetOpaque(this_val, _database_class_id); database_t* database = JS_GetOpaque(this_val, _database_class_id);
if (database) if (database)
@ -229,7 +229,7 @@ JSValue _database_remove(JSContext* context, JSValueConst this_val, int argc, JS
return JS_UNDEFINED; return JS_UNDEFINED;
} }
JSValue _database_get_all(JSContext* context, JSValueConst this_val, int argc, JSValueConst* argv) static JSValue _database_get_all(JSContext* context, JSValueConst this_val, int argc, JSValueConst* argv)
{ {
JSValue array = JS_UNDEFINED; JSValue array = JS_UNDEFINED;
database_t* database = JS_GetOpaque(this_val, _database_class_id); database_t* database = JS_GetOpaque(this_val, _database_class_id);
@ -256,7 +256,7 @@ JSValue _database_get_all(JSContext* context, JSValueConst this_val, int argc, J
return array; return array;
} }
JSValue _database_get_like(JSContext* context, JSValueConst this_val, int argc, JSValueConst* argv) static JSValue _database_get_like(JSContext* context, JSValueConst this_val, int argc, JSValueConst* argv)
{ {
JSValue result = JS_UNDEFINED; JSValue result = JS_UNDEFINED;
database_t* database = JS_GetOpaque(this_val, _database_class_id); database_t* database = JS_GetOpaque(this_val, _database_class_id);

View File

@ -353,7 +353,7 @@ static JSValue _file_read_file_zip(JSContext* context, JSValueConst this_val, in
return promise_value; return promise_value;
} }
JSValue _file_stat(JSContext* context, JSValueConst this_val, int argc, JSValueConst* argv) static JSValue _file_stat(JSContext* context, JSValueConst this_val, int argc, JSValueConst* argv)
{ {
void* task = JS_GetContextOpaque(context); void* task = JS_GetContextOpaque(context);
const char* path = JS_ToCString(context, argv[0]); const char* path = JS_ToCString(context, argv[0]);
@ -377,7 +377,7 @@ JSValue _file_stat(JSContext* context, JSValueConst this_val, int argc, JSValueC
return promise_value; return promise_value;
} }
JSValue _file_stat_zip(JSContext* context, JSValueConst this_val, int argc, JSValueConst* argv) static JSValue _file_stat_zip(JSContext* context, JSValueConst this_val, int argc, JSValueConst* argv)
{ {
void* task = JS_GetContextOpaque(context); void* task = JS_GetContextOpaque(context);
promiseid_t promise = -1; promiseid_t promise = -1;

View File

@ -120,13 +120,13 @@ void tf_http_set_trace(tf_http_t* http, tf_trace_t* trace)
http->trace = trace; http->trace = trace;
} }
void _http_allocate_buffer(uv_handle_t* handle, size_t suggested_size, uv_buf_t* buf) static void _http_allocate_buffer(uv_handle_t* handle, size_t suggested_size, uv_buf_t* buf)
{ {
tf_http_connection_t* connection = handle->data; tf_http_connection_t* connection = handle->data;
*buf = uv_buf_init(connection->incoming, sizeof(connection->incoming)); *buf = uv_buf_init(connection->incoming, sizeof(connection->incoming));
} }
bool _http_find_handler(tf_http_t* http, const char* path, tf_http_callback_t** out_callback, const char** out_trace_name, void** out_user_data) static bool _http_find_handler(tf_http_t* http, const char* path, tf_http_callback_t** out_callback, const char** out_trace_name, void** out_user_data)
{ {
for (int i = 0; i < http->handlers_count; i++) for (int i = 0; i < http->handlers_count; i++)
{ {

View File

@ -75,7 +75,6 @@ static int _tf_command_import(const char* file, int argc, char* argv[]);
static int _tf_command_export(const char* file, int argc, char* argv[]); static int _tf_command_export(const char* file, int argc, char* argv[]);
static int _tf_command_run(const char* file, int argc, char* argv[]); static int _tf_command_run(const char* file, int argc, char* argv[]);
static int _tf_command_sandbox(const char* file, int argc, char* argv[]); static int _tf_command_sandbox(const char* file, int argc, char* argv[]);
static int _tf_command_check(const char* file, int argc, char* argv[]);
static int _tf_command_usage(const char* file, int argc, char* argv[]); static int _tf_command_usage(const char* file, int argc, char* argv[]);
typedef struct _command_t { typedef struct _command_t {
@ -90,7 +89,6 @@ const command_t k_commands[] = {
{ "import", _tf_command_import, "Import apps to SSB." }, { "import", _tf_command_import, "Import apps to SSB." },
{ "export", _tf_command_export, "Export apps from SSB." }, { "export", _tf_command_export, "Export apps from SSB." },
{ "test", _tf_command_test, "Test SSB." }, { "test", _tf_command_test, "Test SSB." },
{ "check", _tf_command_check, "Validate messages in the SSB database." },
}; };
static int _tf_command_test(const char* file, int argc, char* argv[]) static int _tf_command_test(const char* file, int argc, char* argv[])
@ -519,57 +517,6 @@ xopt_help:
} }
#if !defined(__ANDROID__) #if !defined(__ANDROID__)
static int _tf_command_check(const char* file, int argc, char* argv[])
{
typedef struct args_t {
bool help;
} args_t;
xoptOption options[] = {
{ "help", 'h', offsetof(args_t, help), NULL, XOPT_TYPE_BOOL, NULL, "Shows this help message." },
XOPT_NULLOPTION,
};
args_t args = { 0 };
const char** extras = NULL;
int extra_count = 0;
const char *err = NULL;
XOPT_PARSE(file, XOPT_CTX_KEEPFIRST | XOPT_CTX_STRICT, options, &args, argc, (const char**)argv, &extra_count, &extras, &err, stderr, "check [options]", "options:", NULL, 15);
if (err)
{
fprintf(stderr, "Error: %s\n", err);
return 2;
}
bool result = true;
sqlite3* db = NULL;
sqlite3_open(k_db_path_default, &db);
if (extra_count)
{
for (int i = 0; i < extra_count; i++)
{
result = result && tf_ssb_db_check(db, extras[i]);
}
}
else
{
result = tf_ssb_db_check(db, NULL);
}
sqlite3_close(db);
if (extras)
{
free((void*)extras);
}
return result ? EXIT_SUCCESS : EXIT_FAILURE;
xopt_help:
if (extras)
{
free((void*)extras);
}
return 1;
}
static int _tf_command_usage(const char* file, int argc, char* argv[]) static int _tf_command_usage(const char* file, int argc, char* argv[])
{ {
tf_printf("Usage: %s command [command-options]\n", file); tf_printf("Usage: %s command [command-options]\n", file);

View File

@ -398,27 +398,27 @@ size_t tf_mem_get_uv_malloc_size()
} }
#if defined(__OpenBSD__) #if defined(__OpenBSD__)
void* _tf_tls_alloc(size_t size) static void* _tf_tls_alloc(size_t size)
#else #else
void* _tf_tls_alloc(size_t size, const char* file, int line) static void* _tf_tls_alloc(size_t size, const char* file, int line)
#endif #endif
{ {
return _tf_alloc(&s_tls_malloc_size, size); return _tf_alloc(&s_tls_malloc_size, size);
} }
#if defined(__OpenBSD__) #if defined(__OpenBSD__)
void* _tf_tls_realloc(void* ptr, size_t size) static void* _tf_tls_realloc(void* ptr, size_t size)
#else #else
void* _tf_tls_realloc(void* ptr, size_t size, const char* file, int line) static void* _tf_tls_realloc(void* ptr, size_t size, const char* file, int line)
#endif #endif
{ {
return _tf_realloc(&s_tls_malloc_size, ptr, size); return _tf_realloc(&s_tls_malloc_size, ptr, size);
} }
#if defined(__OpenBSD__) #if defined(__OpenBSD__)
void _tf_tls_free(void* ptr) static void _tf_tls_free(void* ptr)
#else #else
void _tf_tls_free(void* ptr, const char* file, int line) static void _tf_tls_free(void* ptr, const char* file, int line)
#endif #endif
{ {
_tf_free(&s_tls_malloc_size, ptr); _tf_free(&s_tls_malloc_size, ptr);

View File

@ -84,22 +84,22 @@ static void _buffer_append(buffer_t* buffer, const void* data, size_t size)
buffer->size += size; buffer->size += size;
} }
void _serialize_writeInt8(buffer_t* buffer, int8_t value) static void _serialize_writeInt8(buffer_t* buffer, int8_t value)
{ {
_buffer_append(buffer, &value, sizeof(value)); _buffer_append(buffer, &value, sizeof(value));
} }
void _serialize_writeInt32(buffer_t* buffer, int32_t value) static void _serialize_writeInt32(buffer_t* buffer, int32_t value)
{ {
_buffer_append(buffer, &value, sizeof(value)); _buffer_append(buffer, &value, sizeof(value));
} }
void _serialize_writeInt64(buffer_t* buffer, int64_t value) static void _serialize_writeInt64(buffer_t* buffer, int64_t value)
{ {
_buffer_append(buffer, &value, sizeof(value)); _buffer_append(buffer, &value, sizeof(value));
} }
void _serialize_writeDouble(buffer_t* buffer, double value) static void _serialize_writeDouble(buffer_t* buffer, double value)
{ {
_buffer_append(buffer, &value, sizeof(value)); _buffer_append(buffer, &value, sizeof(value));
} }
@ -119,21 +119,21 @@ static int8_t _serialize_readInt8(const char** buffer, size_t* size)
return result; return result;
} }
int32_t _serialize_readInt32(const char** buffer, size_t* size) static int32_t _serialize_readInt32(const char** buffer, size_t* size)
{ {
int32_t result = 0; int32_t result = 0;
_serialize_read(buffer, size, &result, sizeof(result)); _serialize_read(buffer, size, &result, sizeof(result));
return result; return result;
} }
int64_t _serialize_readInt64(const char** buffer, size_t* size) static int64_t _serialize_readInt64(const char** buffer, size_t* size)
{ {
int64_t result = 0; int64_t result = 0;
_serialize_read(buffer, size, &result, sizeof(result)); _serialize_read(buffer, size, &result, sizeof(result));
return result; return result;
} }
double _serialize_readDouble(const char** buffer, size_t* size) static double _serialize_readDouble(const char** buffer, size_t* size)
{ {
double result = 0; double result = 0;
_serialize_read(buffer, size, &result, sizeof(result)); _serialize_read(buffer, size, &result, sizeof(result));

View File

@ -164,7 +164,7 @@ typedef struct _socket_resolve_data_t {
promiseid_t promise; promiseid_t promise;
} socket_resolve_data_t; } socket_resolve_data_t;
socket_t* _socket_create_internal(JSContext* context) static socket_t* _socket_create_internal(JSContext* context)
{ {
socket_t* socket = tf_malloc(sizeof(socket_t)); socket_t* socket = tf_malloc(sizeof(socket_t));
memset(socket, 0, sizeof(*socket)); memset(socket, 0, sizeof(*socket));
@ -226,12 +226,12 @@ socket_t* _socket_create_internal(JSContext* context)
return socket; return socket;
} }
JSValue _socket_create(JSContext* context, JSValueConst this_val, int argc, JSValueConst* argv) static JSValue _socket_create(JSContext* context, JSValueConst this_val, int argc, JSValueConst* argv)
{ {
return _socket_create_internal(context)->_object; return _socket_create_internal(context)->_object;
} }
void _socket_close_internal(socket_t* socket) static void _socket_close_internal(socket_t* socket)
{ {
_socket_set_handler(socket, &socket->_onRead, JS_UNDEFINED); _socket_set_handler(socket, &socket->_onRead, JS_UNDEFINED);
_socket_set_handler(socket, &socket->_onError, JS_UNDEFINED); _socket_set_handler(socket, &socket->_onError, JS_UNDEFINED);
@ -271,14 +271,14 @@ void _socket_close_internal(socket_t* socket)
} }
} }
void _socket_finalizer(JSRuntime* runtime, JSValue value) static void _socket_finalizer(JSRuntime* runtime, JSValue value)
{ {
socket_t* socket = JS_GetOpaque(value, _classId); socket_t* socket = JS_GetOpaque(value, _classId);
socket->_object = JS_UNDEFINED; socket->_object = JS_UNDEFINED;
_socket_close_internal(socket); _socket_close_internal(socket);
} }
void _socket_reportError(socket_t* socket, const char* error) static void _socket_reportError(socket_t* socket, const char* error)
{ {
JSContext* context = tf_task_get_context(socket->_task); JSContext* context = tf_task_get_context(socket->_task);
JSValue ref = JS_DupValue(context, socket->_object); JSValue ref = JS_DupValue(context, socket->_object);
@ -299,7 +299,7 @@ void _socket_reportError(socket_t* socket, const char* error)
JS_FreeValue(context, ref); JS_FreeValue(context, ref);
} }
void _socket_reportTlsErrors(socket_t* socket) static void _socket_reportTlsErrors(socket_t* socket)
{ {
char buffer[4096]; char buffer[4096];
while (socket->_tls && tf_tls_session_get_error(socket->_tls, buffer, sizeof(buffer))) while (socket->_tls && tf_tls_session_get_error(socket->_tls, buffer, sizeof(buffer)))
@ -308,7 +308,7 @@ void _socket_reportTlsErrors(socket_t* socket)
} }
} }
JSValue _socket_startTls(JSContext* context, JSValueConst this_val, int argc, JSValueConst* argv) static JSValue _socket_startTls(JSContext* context, JSValueConst this_val, int argc, JSValueConst* argv)
{ {
socket_t* socket = JS_GetOpaque(this_val, _classId); socket_t* socket = JS_GetOpaque(this_val, _classId);
if (!socket->_tls) if (!socket->_tls)
@ -359,7 +359,7 @@ JSValue _socket_startTls(JSContext* context, JSValueConst this_val, int argc, JS
} }
} }
JSValue _socket_stopTls(JSContext* context, JSValueConst this_val, int argc, JSValueConst* argv) static JSValue _socket_stopTls(JSContext* context, JSValueConst this_val, int argc, JSValueConst* argv)
{ {
socket_t* socket = JS_GetOpaque(this_val, _classId); socket_t* socket = JS_GetOpaque(this_val, _classId);
if (socket->_tls) if (socket->_tls)
@ -375,7 +375,7 @@ JSValue _socket_stopTls(JSContext* context, JSValueConst this_val, int argc, JSV
return JS_NULL; return JS_NULL;
} }
bool _socket_processSomeOutgoingTls(socket_t* socket, promiseid_t promise, uv_write_cb callback) static bool _socket_processSomeOutgoingTls(socket_t* socket, promiseid_t promise, uv_write_cb callback)
{ {
if (!socket->_socket.data) if (!socket->_socket.data)
{ {
@ -416,14 +416,14 @@ bool _socket_processSomeOutgoingTls(socket_t* socket, promiseid_t promise, uv_wr
return result > 0; return result > 0;
} }
void _socket_processOutgoingTls(socket_t* socket) static void _socket_processOutgoingTls(socket_t* socket)
{ {
while (_socket_processSomeOutgoingTls(socket, -1, _socket_onWrite)) while (_socket_processSomeOutgoingTls(socket, -1, _socket_onWrite))
{ {
} }
} }
JSValue _socket_bind(JSContext* context, JSValueConst this_val, int argc, JSValueConst* argv) static JSValue _socket_bind(JSContext* context, JSValueConst this_val, int argc, JSValueConst* argv)
{ {
socket_t* socket = JS_GetOpaque(this_val, _classId); socket_t* socket = JS_GetOpaque(this_val, _classId);
const char* node = JS_ToCString(tf_task_get_context(socket->_task), argv[0]); const char* node = JS_ToCString(tf_task_get_context(socket->_task), argv[0]);
@ -450,7 +450,7 @@ JSValue _socket_bind(JSContext* context, JSValueConst this_val, int argc, JSValu
return promise; return promise;
} }
void _socket_onResolvedForBind(uv_getaddrinfo_t* resolver, int status, struct addrinfo* result) static void _socket_onResolvedForBind(uv_getaddrinfo_t* resolver, int status, struct addrinfo* result)
{ {
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)
@ -486,7 +486,7 @@ void _socket_onResolvedForBind(uv_getaddrinfo_t* resolver, int status, struct ad
tf_free(data); tf_free(data);
} }
JSValue _socket_connect(JSContext* context, JSValueConst this_val, int argc, JSValueConst* argv) static JSValue _socket_connect(JSContext* context, JSValueConst this_val, int argc, JSValueConst* argv)
{ {
socket_t* socket = JS_GetOpaque(this_val, _classId); socket_t* socket = JS_GetOpaque(this_val, _classId);
socket->_direction = kConnect; socket->_direction = kConnect;
@ -520,7 +520,7 @@ JSValue _socket_connect(JSContext* context, JSValueConst this_val, int argc, JSV
return promise; return promise;
} }
void _socket_onResolvedForConnect(uv_getaddrinfo_t* resolver, int status, struct addrinfo* result) static void _socket_onResolvedForConnect(uv_getaddrinfo_t* resolver, int status, struct addrinfo* result)
{ {
socket_resolve_data_t* data = resolver->data; socket_resolve_data_t* data = resolver->data;
if (status != 0) if (status != 0)
@ -549,7 +549,7 @@ void _socket_onResolvedForConnect(uv_getaddrinfo_t* resolver, int status, struct
tf_free(data); tf_free(data);
} }
void _socket_onConnect(uv_connect_t* request, int status) static void _socket_onConnect(uv_connect_t* request, int status)
{ {
promiseid_t promise = (intptr_t)request->data; promiseid_t promise = (intptr_t)request->data;
if (promise != -1) if (promise != -1)
@ -571,7 +571,7 @@ void _socket_onConnect(uv_connect_t* request, int status)
tf_free(request); tf_free(request);
} }
JSValue _socket_listen(JSContext* context, JSValueConst this_val, int argc, JSValueConst* argv) static JSValue _socket_listen(JSContext* context, JSValueConst this_val, int argc, JSValueConst* argv)
{ {
socket_t* socket = JS_GetOpaque(this_val, _classId); socket_t* socket = JS_GetOpaque(this_val, _classId);
socket->_listening = true; socket->_listening = true;
@ -593,7 +593,7 @@ JSValue _socket_listen(JSContext* context, JSValueConst this_val, int argc, JSVa
} }
} }
void _socket_onNewConnection(uv_stream_t* server, int status) static void _socket_onNewConnection(uv_stream_t* server, int status)
{ {
socket_t* socket = server->data; socket_t* socket = server->data;
JSContext* context = tf_task_get_context(socket->_task); JSContext* context = tf_task_get_context(socket->_task);
@ -609,7 +609,7 @@ void _socket_onNewConnection(uv_stream_t* server, int status)
JS_FreeValue(context, ref); JS_FreeValue(context, ref);
} }
JSValue _socket_accept(JSContext* context, JSValueConst this_val, int argc, JSValueConst* argv) static JSValue _socket_accept(JSContext* context, JSValueConst this_val, int argc, JSValueConst* argv)
{ {
socket_t* socket = JS_GetOpaque(this_val, _classId); socket_t* socket = JS_GetOpaque(this_val, _classId);
@ -639,7 +639,7 @@ JSValue _socket_accept(JSContext* context, JSValueConst this_val, int argc, JSVa
return result; return result;
} }
JSValue _socket_close(JSContext* context, JSValueConst this_val, int argc, JSValueConst* argv) static JSValue _socket_close(JSContext* context, JSValueConst this_val, int argc, JSValueConst* argv)
{ {
socket_t* socket = JS_GetOpaque(this_val, _classId); socket_t* socket = JS_GetOpaque(this_val, _classId);
if (socket->_closePromise == -1 && if (socket->_closePromise == -1 &&
@ -653,7 +653,7 @@ JSValue _socket_close(JSContext* context, JSValueConst this_val, int argc, JSVal
return JS_UNDEFINED; return JS_UNDEFINED;
} }
JSValue _socket_shutdown(JSContext* context, JSValueConst this_val, int argc, JSValueConst* argv) static JSValue _socket_shutdown(JSContext* context, JSValueConst this_val, int argc, JSValueConst* argv)
{ {
socket_t* socket = JS_GetOpaque(this_val, _classId); socket_t* socket = JS_GetOpaque(this_val, _classId);
promiseid_t promise = -1; promiseid_t promise = -1;
@ -669,7 +669,7 @@ JSValue _socket_shutdown(JSContext* context, JSValueConst this_val, int argc, JS
return result; return result;
} }
void _socket_shutdownInternal(socket_t* socket, promiseid_t promise) static void _socket_shutdownInternal(socket_t* socket, promiseid_t promise)
{ {
uv_shutdown_t* request = tf_malloc(sizeof(uv_shutdown_t)); uv_shutdown_t* request = tf_malloc(sizeof(uv_shutdown_t));
memset(request, 0, sizeof(*request)); memset(request, 0, sizeof(*request));
@ -684,7 +684,7 @@ void _socket_shutdownInternal(socket_t* socket, promiseid_t promise)
} }
} }
void _socket_processTlsShutdown(socket_t* socket, promiseid_t promise) static void _socket_processTlsShutdown(socket_t* socket, promiseid_t promise)
{ {
if (!socket->_tls) if (!socket->_tls)
{ {
@ -700,7 +700,7 @@ void _socket_processTlsShutdown(socket_t* socket, promiseid_t promise)
} }
} }
void _socket_onTlsShutdown(uv_write_t* request, int status) static void _socket_onTlsShutdown(uv_write_t* request, int status)
{ {
socket_t* socket = request->handle->data; socket_t* socket = request->handle->data;
promiseid_t promise = (intptr_t)request->data; promiseid_t promise = (intptr_t)request->data;
@ -708,14 +708,14 @@ void _socket_onTlsShutdown(uv_write_t* request, int status)
tf_free(request); tf_free(request);
} }
JSValue _socket_onError(JSContext* context, JSValueConst this_val, int argc, JSValueConst* argv) static JSValue _socket_onError(JSContext* context, JSValueConst this_val, int argc, JSValueConst* argv)
{ {
socket_t* socket = JS_GetOpaque(this_val, _classId); socket_t* socket = JS_GetOpaque(this_val, _classId);
_socket_set_handler(socket, &socket->_onError, argv[0]); _socket_set_handler(socket, &socket->_onError, argv[0]);
return JS_NULL; return JS_NULL;
} }
JSValue _socket_read(JSContext* context, JSValueConst this_val, int argc, JSValueConst* argv) static JSValue _socket_read(JSContext* context, JSValueConst this_val, int argc, JSValueConst* argv)
{ {
socket_t* socket = JS_GetOpaque(this_val, _classId); socket_t* socket = JS_GetOpaque(this_val, _classId);
JSValue ref = JS_DupValue(context, socket->_object); JSValue ref = JS_DupValue(context, socket->_object);
@ -745,12 +745,12 @@ JSValue _socket_read(JSContext* context, JSValueConst this_val, int argc, JSValu
return read_result; return read_result;
} }
void _socket_allocateBuffer(uv_handle_t* handle, size_t suggestedSize, uv_buf_t* buf) static void _socket_allocateBuffer(uv_handle_t* handle, size_t suggestedSize, uv_buf_t* buf)
{ {
*buf = uv_buf_init(tf_malloc(suggestedSize), suggestedSize); *buf = uv_buf_init(tf_malloc(suggestedSize), suggestedSize);
} }
void _socket_onRead(uv_stream_t* stream, ssize_t readSize, const uv_buf_t* buffer) static void _socket_onRead(uv_stream_t* stream, ssize_t readSize, const uv_buf_t* buffer)
{ {
socket_t* socket = stream->data; socket_t* socket = stream->data;
_socket_resetTimeout(socket); _socket_resetTimeout(socket);
@ -849,7 +849,7 @@ void _socket_onRead(uv_stream_t* stream, ssize_t readSize, const uv_buf_t* buffe
JS_FreeValue(context, ref); JS_FreeValue(context, ref);
} }
void _socket_notifyDataRead(socket_t* socket, const char* data, size_t length) static void _socket_notifyDataRead(socket_t* socket, const char* data, size_t length)
{ {
if (data && length > 0) if (data && length > 0)
{ {
@ -870,7 +870,7 @@ void _socket_notifyDataRead(socket_t* socket, const char* data, size_t length)
} }
} }
int _socket_writeBytes(socket_t* socket, promiseid_t promise, int (*callback)(socket_t* socket, promiseid_t promise, const char*, size_t), JSValue value, int* outLength) static int _socket_writeBytes(socket_t* socket, promiseid_t promise, int (*callback)(socket_t* socket, promiseid_t promise, const char*, size_t), JSValue value, int* outLength)
{ {
int result = -1; int result = -1;
size_t length; size_t length;
@ -910,7 +910,7 @@ int _socket_writeBytes(socket_t* socket, promiseid_t promise, int (*callback)(so
return result; return result;
} }
int _socket_writeInternal(socket_t* socket, promiseid_t promise, const char* data, size_t length) static int _socket_writeInternal(socket_t* socket, promiseid_t promise, const char* data, size_t length)
{ {
if (!socket->_socket.data) if (!socket->_socket.data)
{ {
@ -942,7 +942,7 @@ static int _socket_write_tls(socket_t* socket, promiseid_t promise, const char*
return tf_tls_session_write_plain(socket->_tls, data, size); return tf_tls_session_write_plain(socket->_tls, data, size);
} }
JSValue _socket_write(JSContext* context, JSValueConst this_val, int argc, JSValueConst* argv) static JSValue _socket_write(JSContext* context, JSValueConst this_val, int argc, JSValueConst* argv)
{ {
socket_t* socket = JS_GetOpaque(this_val, _classId); socket_t* socket = JS_GetOpaque(this_val, _classId);
promiseid_t promise = -1; promiseid_t promise = -1;
@ -989,7 +989,7 @@ JSValue _socket_write(JSContext* context, JSValueConst this_val, int argc, JSVal
return write_result; return write_result;
} }
void _socket_onWrite(uv_write_t* request, int status) static void _socket_onWrite(uv_write_t* request, int status)
{ {
socket_t* socket = request->handle->data; socket_t* socket = request->handle->data;
_socket_resumeTimeout(socket); _socket_resumeTimeout(socket);
@ -1014,7 +1014,7 @@ static void _socket_timeout(uv_timer_t* timer)
_socket_close_internal(socket); _socket_close_internal(socket);
} }
JSValue _socket_setActivityTimeout(JSContext* context, JSValueConst this_val, int argc, JSValueConst* argv) static JSValue _socket_setActivityTimeout(JSContext* context, JSValueConst this_val, int argc, JSValueConst* argv)
{ {
socket_t* socket = JS_GetOpaque(this_val, _classId); socket_t* socket = JS_GetOpaque(this_val, _classId);
int64_t timeout = 0; int64_t timeout = 0;
@ -1028,13 +1028,13 @@ JSValue _socket_setActivityTimeout(JSContext* context, JSValueConst this_val, in
return JS_UNDEFINED; return JS_UNDEFINED;
} }
JSValue _socket_isConnected(JSContext* context, JSValueConst this_val, int argc, JSValueConst* argv) static JSValue _socket_isConnected(JSContext* context, JSValueConst this_val, int argc, JSValueConst* argv)
{ {
socket_t* socket = JS_GetOpaque(this_val, _classId); socket_t* socket = JS_GetOpaque(this_val, _classId);
return socket->_connected ? JS_TRUE : JS_FALSE; return socket->_connected ? JS_TRUE : JS_FALSE;
} }
void _socket_onClose(uv_handle_t* handle) static void _socket_onClose(uv_handle_t* handle)
{ {
--_open_count; --_open_count;
socket_t* socket = handle->data; socket_t* socket = handle->data;
@ -1056,7 +1056,7 @@ void _socket_onClose(uv_handle_t* handle)
_socket_close_internal(socket); _socket_close_internal(socket);
} }
void _socket_onShutdown(uv_shutdown_t* request, int status) static void _socket_onShutdown(uv_shutdown_t* request, int status)
{ {
socket_t* socket = request->handle->data; socket_t* socket = request->handle->data;
_socket_resetTimeout(socket); _socket_resetTimeout(socket);
@ -1074,7 +1074,7 @@ void _socket_onShutdown(uv_shutdown_t* request, int status)
tf_free(request); tf_free(request);
} }
JSValue _socket_getPeerName(JSContext* context, JSValueConst this_val, int argc, JSValueConst* argv) static JSValue _socket_getPeerName(JSContext* context, JSValueConst this_val, int argc, JSValueConst* argv)
{ {
socket_t* socket = JS_GetOpaque(this_val, _classId); socket_t* socket = JS_GetOpaque(this_val, _classId);
struct sockaddr_in6 addr; struct sockaddr_in6 addr;
@ -1100,7 +1100,7 @@ JSValue _socket_getPeerName(JSContext* context, JSValueConst this_val, int argc,
return JS_UNDEFINED; return JS_UNDEFINED;
} }
JSValue _socket_getPeerCertificate(JSContext* context, JSValueConst this_val, int argc, JSValueConst* argv) static JSValue _socket_getPeerCertificate(JSContext* context, JSValueConst this_val, int argc, JSValueConst* argv)
{ {
socket_t* socket = JS_GetOpaque(this_val, _classId); socket_t* socket = JS_GetOpaque(this_val, _classId);
if (socket->_tls) if (socket->_tls)
@ -1115,13 +1115,13 @@ JSValue _socket_getPeerCertificate(JSContext* context, JSValueConst this_val, in
return JS_UNDEFINED; return JS_UNDEFINED;
} }
JSValue _socket_getNoDelay(JSContext* context, JSValueConst this_val, int argc, JSValueConst* argv) static JSValue _socket_getNoDelay(JSContext* context, JSValueConst this_val, int argc, JSValueConst* argv)
{ {
socket_t* socket = JS_GetOpaque(this_val, _classId); socket_t* socket = JS_GetOpaque(this_val, _classId);
return JS_NewBool(context, socket->_noDelay); return JS_NewBool(context, socket->_noDelay);
} }
JSValue _socket_setNoDelay(JSContext* context, JSValueConst this_val, int argc, JSValueConst* argv) static JSValue _socket_setNoDelay(JSContext* context, JSValueConst this_val, int argc, JSValueConst* argv)
{ {
socket_t* socket = JS_GetOpaque(this_val, _classId); socket_t* socket = JS_GetOpaque(this_val, _classId);
int result = JS_ToBool(context, argv[0]); int result = JS_ToBool(context, argv[0]);
@ -1130,7 +1130,7 @@ JSValue _socket_setNoDelay(JSContext* context, JSValueConst this_val, int argc,
return JS_UNDEFINED; return JS_UNDEFINED;
} }
JSValue _sockets_get(JSContext* context, JSValueConst this_val, int argc, JSValueConst* argv) static JSValue _sockets_get(JSContext* context, JSValueConst this_val, int argc, JSValueConst* argv)
{ {
JSValue array = JS_NewArray(context); JSValue array = JS_NewArray(context);
for (int i = 0; i < _sockets_count; i++) for (int i = 0; i < _sockets_count; i++)

View File

@ -1033,132 +1033,6 @@ JSValue tf_ssb_format_message(JSContext* context, const char* previous, const ch
return value; return value;
} }
bool _tf_ssb_update_message_id(sqlite3* db, const char* old_id, const char* new_id)
{
bool success = false;
sqlite3_stmt* statement = NULL;
if (sqlite3_prepare(db, "UPDATE messages SET id = ? WHERE id = ?", -1, &statement, NULL) == SQLITE_OK)
{
if (sqlite3_bind_text(statement, 1, new_id, -1, NULL) == SQLITE_OK &&
sqlite3_bind_text(statement, 2, old_id, -1, NULL) == SQLITE_OK)
{
success = sqlite3_step(statement) == SQLITE_DONE;
}
sqlite3_finalize(statement);
}
return success;
}
bool tf_ssb_db_check(sqlite3* db, const char* check_author)
{
JSMallocFunctions funcs = { 0 };
tf_get_js_malloc_functions(&funcs);
JSRuntime* runtime = JS_NewRuntime2(&funcs, NULL);
JSContext* context = JS_NewContext(runtime);
sqlite3_stmt* statement = NULL;
int result = check_author ?
sqlite3_prepare(db, "SELECT id, previous, author, sequence, timestamp, hash, content, signature, sequence_before_author FROM messages WHERE author = ? ORDER BY author, sequence", -1, &statement, NULL) :
sqlite3_prepare(db, "SELECT id, previous, author, sequence, timestamp, hash, content, signature, sequence_before_author FROM messages ORDER BY author, sequence", -1, &statement, NULL);
if (result == SQLITE_OK)
{
if (check_author)
{
sqlite3_bind_text(statement, 1, check_author, -1, NULL);
}
char previous_id[k_id_base64_len];
int64_t previous_sequence = -1;
char previous_author[k_id_base64_len] = { 0 };
while (sqlite3_step(statement) == SQLITE_ROW)
{
const char* id = (const char*)sqlite3_column_text(statement, 0);
const char* previous = (const char*)sqlite3_column_text(statement, 1);
const char* author = (const char*)sqlite3_column_text(statement, 2);
int64_t sequence = sqlite3_column_int64(statement, 3);
double timestamp = sqlite3_column_double(statement, 4);
const char* hash = (const char*)sqlite3_column_text(statement, 5);
const char* content = (const char*)sqlite3_column_text(statement, 6);
const char* signature = (const char*)sqlite3_column_text(statement, 7);
bool sequence_before_author = sqlite3_column_int(statement, 8);
JSValue message = tf_ssb_format_message(context, previous, author, sequence, timestamp, hash, content, signature, sequence_before_author);
char out_signature[512];
char actual_id[k_id_base64_len];
bool actual_sequence_before_author = false;
JSValue j = JS_JSONStringify(context, message, JS_NULL, JS_NewInt32(context, 2));
const char* jv = JS_ToCString(context, j);
bool delete_following = false;
if (strcmp(author, previous_author))
{
tf_printf("%s\n", author);
}
if (strcmp(author, previous_author) == 0 && sequence != previous_sequence + 1)
{
tf_printf("Detected gap in messages for %s at sequence = %" PRId64 " => %" PRId64 ".\n", author, previous_sequence, sequence);
delete_following = true;
}
else
{
if (tf_ssb_verify_and_strip_signature(context, message, actual_id, sizeof(actual_id), out_signature, sizeof(out_signature), &actual_sequence_before_author))
{
if (previous && strcmp(previous, previous_id))
{
tf_printf("%s:%d previous was %s should be %s\n", id, (int)sequence, previous_id, previous);
}
if (strcmp(id, actual_id))
{
if (_tf_ssb_update_message_id(db, id, actual_id))
{
tf_printf("updated %s to %s\n", id, actual_id);
}
else
{
tf_printf("failed to update %s to %s\n", id, actual_id);
}
}
}
else
{
tf_printf("%s sequence=%" PRId64 " unable to verify signature for %s sequence_before_author=%d message=[%.*s]\n", author, sequence, id, sequence_before_author, (int)strlen(jv), jv);
delete_following = true;
}
}
if (delete_following)
{
tf_printf("Deleting author = %s sequence >= %" PRId64 ".\n", author, sequence);
sqlite3_stmt* delete_statement = NULL;
if (sqlite3_prepare(db, "DELETE FROM messages WHERE author = ? AND sequence >= ?", -1, &delete_statement, NULL) == SQLITE_OK)
{
if (sqlite3_bind_text(delete_statement, 1, author, -1, NULL) == SQLITE_OK &&
sqlite3_bind_int64(delete_statement, 2, sequence) == SQLITE_OK)
{
if (sqlite3_step(delete_statement) != SQLITE_DONE)
{
tf_printf("Error deleting author = %s sequence >= %" PRId64 ".\n", author, sequence);
}
}
sqlite3_finalize(delete_statement);
}
}
snprintf(previous_author, sizeof(previous_author), "%s", author);
previous_sequence = sequence;
JS_FreeCString(context, jv);
JS_FreeValue(context, j);
snprintf(previous_id, sizeof(previous_id), "%s", id);
JS_FreeValue(context, message);
}
sqlite3_finalize(statement);
}
JS_FreeContext(context);
JS_FreeRuntime(runtime);
return false;
}
int tf_ssb_db_identity_get_count_for_user(tf_ssb_t* ssb, const char* user) int tf_ssb_db_identity_get_count_for_user(tf_ssb_t* ssb, const char* user)
{ {
int count = 0; int count = 0;

View File

@ -29,7 +29,6 @@ static const int k_sql_async_timeout_ms = 60 * 1000;
static JSClassID _tf_ssb_classId; static JSClassID _tf_ssb_classId;
void _tf_ssb_on_rpc(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 JSValue _tf_ssb_appendMessageWithIdentity(JSContext* context, JSValueConst this_val, int argc, JSValueConst* argv); static JSValue _tf_ssb_appendMessageWithIdentity(JSContext* context, JSValueConst this_val, int argc, JSValueConst* argv);
static JSValue _tf_ssb_createIdentity(JSContext* context, JSValueConst this_val, int argc, JSValueConst* argv) static JSValue _tf_ssb_createIdentity(JSContext* context, JSValueConst this_val, int argc, JSValueConst* argv)
@ -413,7 +412,7 @@ typedef struct _blob_store_t
uint8_t* buffer; uint8_t* buffer;
} blob_store_t; } blob_store_t;
void _tf_ssb_blob_store_complete(blob_store_t* store, const char* id) static void _tf_ssb_blob_store_complete(blob_store_t* store, const char* id)
{ {
JSValue result = JS_UNDEFINED; JSValue result = JS_UNDEFINED;
if (id) if (id)
@ -437,7 +436,7 @@ void _tf_ssb_blob_store_complete(blob_store_t* store, const char* id)
tf_free(store); tf_free(store);
} }
void _tf_ssb_blob_store_callback(const char* id, bool is_new, void* user_data) static void _tf_ssb_blob_store_callback(const char* id, bool is_new, void* user_data)
{ {
blob_store_t* store = user_data; blob_store_t* store = user_data;
_tf_ssb_blob_store_complete(store, id); _tf_ssb_blob_store_complete(store, id);
@ -975,7 +974,7 @@ typedef struct _message_store_t
JSValue promise[2]; JSValue promise[2];
} message_store_t; } message_store_t;
void _tf_ssb_message_store_callback(const char* id, bool verified, bool is_new, void* user_data) static void _tf_ssb_message_store_callback(const char* id, bool verified, bool is_new, void* user_data)
{ {
message_store_t* store = user_data; message_store_t* store = user_data;
JSValue result = JS_Call(store->context, id ? store->promise[0] : store->promise[1], JS_UNDEFINED, 0, NULL); JSValue result = JS_Call(store->context, id ? store->promise[0] : store->promise[1], JS_UNDEFINED, 0, NULL);

View File

@ -257,7 +257,7 @@ typedef struct tunnel_t
int32_t request_number; int32_t request_number;
} tunnel_t; } tunnel_t;
void _tf_ssb_rpc_tunnel_callback(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_tunnel_callback(tf_ssb_connection_t* connection, uint8_t flags, int32_t request_number, JSValue args, const uint8_t* message, size_t size, void* user_data)
{ {
tunnel_t* tun = user_data; tunnel_t* tun = user_data;
if (flags & k_ssb_rpc_flag_end_error) if (flags & k_ssb_rpc_flag_end_error)
@ -271,7 +271,7 @@ void _tf_ssb_rpc_tunnel_callback(tf_ssb_connection_t* connection, uint8_t flags,
} }
} }
void _tf_ssb_rpc_tunnel_cleanup(tf_ssb_t* ssb, void* user_data) static void _tf_ssb_rpc_tunnel_cleanup(tf_ssb_t* ssb, void* user_data)
{ {
tf_free(user_data); tf_free(user_data);
} }

View File

@ -192,24 +192,12 @@ static bool _export_record_release(tf_task_t* task, export_record_t** export)
return false; return false;
} }
static JSValue _tf_task_version(JSContext* context, JSValueConst this_val, int argc, JSValueConst* argv);
static JSValue _tf_task_platform(JSContext* context, JSValueConst this_val, int argc, JSValueConst* argv);
static JSValue _tf_task_get_parent(JSContext* context, JSValueConst this_val, int argc, JSValueConst* argv);
static JSValue _tf_task_exit(JSContext* context, JSValueConst this_val, int argc, JSValueConst* argv);
static JSValue _tf_task_getStats(JSContext* context, JSValueConst this_val, int argc, JSValueConst* argv);
static JSValue _tf_task_getFile(JSContext* context, JSValueConst this_val, int argc, JSValueConst* argv);
static JSValue _tf_task_setTimeout(JSContext* context, JSValueConst this_val, int argc, JSValueConst* argv); static JSValue _tf_task_setTimeout(JSContext* context, JSValueConst this_val, int argc, JSValueConst* argv);
static promise_t* _tf_task_find_promise(tf_task_t* task, promiseid_t id); static promise_t* _tf_task_find_promise(tf_task_t* task, promiseid_t id);
static void _tf_task_sendPromiseResolve(tf_task_t* from, tf_taskstub_t* to, promiseid_t promise, JSValue result);
static void _tf_task_sendPromiseReject(tf_task_t* from, tf_taskstub_t* to, promiseid_t promise, JSValue result);
static void _tf_task_sendPromiseExportMessage(tf_task_t* from, tf_taskstub_t* to, tf_task_message_t messageType, promiseid_t promiseId, exportid_t exportId, JSValue result); static void _tf_task_sendPromiseExportMessage(tf_task_t* from, tf_taskstub_t* to, tf_task_message_t messageType, promiseid_t promiseId, exportid_t exportId, JSValue result);
static JSValue _tf_task_executeSource(tf_task_t* task, const char* source, const char* name); static JSValue _tf_task_executeSource(tf_task_t* task, const char* source, const char* name);
static tf_taskstub_t* _tf_task_get_stub(tf_task_t* task, taskid_t id); static tf_taskstub_t* _tf_task_get_stub(tf_task_t* task, taskid_t id);
static void _tf_task_release_export(tf_taskstub_t* stub, exportid_t exportId); static void _tf_task_release_export(tf_taskstub_t* stub, exportid_t exportId);
static bool _tf_task_run_jobs(tf_task_t* task);
static void _tf_task_run_jobs_idle(uv_idle_t* idle);
static void _tf_task_run_jobs_prepare(uv_prepare_t* prepare); static void _tf_task_run_jobs_prepare(uv_prepare_t* prepare);
static void _timeout_unlink(tf_task_t* task, timeout_t* timeout); static void _timeout_unlink(tf_task_t* task, timeout_t* timeout);
static void _timeout_closed(uv_handle_t* handle); static void _timeout_closed(uv_handle_t* handle);
@ -386,7 +374,7 @@ static const char* _task_loadFile(tf_task_t* task, const char* fileName, size_t*
return result; return result;
} }
JSValue _tf_task_exit(JSContext* context, JSValueConst this_val, int argc, JSValueConst* argv) static JSValue _tf_task_exit(JSContext* context, JSValueConst this_val, int argc, JSValueConst* argv)
{ {
tf_task_t* task = JS_GetContextOpaque(context); tf_task_t* task = JS_GetContextOpaque(context);
tf_trace_begin(task->_trace, __func__); tf_trace_begin(task->_trace, __func__);
@ -507,7 +495,7 @@ static export_record_t** _task_get_export(tf_task_t* task, exportid_t export_id)
return it; return it;
} }
JSValue _task_invokeExport_internal(tf_taskstub_t* from, tf_task_t* to, exportid_t exportId, const char* buffer, size_t size) static JSValue _task_invokeExport_internal(tf_taskstub_t* from, tf_task_t* to, exportid_t exportId, const char* buffer, size_t size)
{ {
JSValue result = JS_NULL; JSValue result = JS_NULL;
export_record_t** it = _task_get_export(to, exportId); export_record_t** it = _task_get_export(to, exportId);
@ -691,7 +679,7 @@ static void _tf_task_sendPromiseExportMessage(tf_task_t* from, tf_taskstub_t* to
tf_free(copy); tf_free(copy);
} }
JSValue _tf_task_get_parent(JSContext* context, JSValueConst this_val, int argc, JSValueConst* argv) static JSValue _tf_task_get_parent(JSContext* context, JSValueConst this_val, int argc, JSValueConst* argv)
{ {
tf_task_t* task = JS_GetContextOpaque(context); tf_task_t* task = JS_GetContextOpaque(context);
return task->_parent ? JS_DupValue(context, tf_taskstub_get_task_object(task->_parent)) : JS_UNDEFINED; return task->_parent ? JS_DupValue(context, tf_taskstub_get_task_object(task->_parent)) : JS_UNDEFINED;
@ -979,7 +967,7 @@ static JSValue _tf_task_getFile(JSContext* context, JSValueConst this_val, int a
return result; return result;
} }
const char* _tf_task_get_message_type(tf_task_message_t type) static const char* _tf_task_get_message_type(tf_task_message_t type)
{ {
switch (type) switch (type)
{ {
@ -1545,7 +1533,7 @@ static void _tf_task_run_jobs_prepare(uv_prepare_t* prepare)
} }
} }
JSModuleDef* _tf_task_module_loader(JSContext* context, const char* module_name, void* opaque) static JSModuleDef* _tf_task_module_loader(JSContext* context, const char* module_name, void* opaque)
{ {
tf_task_t* task = opaque; tf_task_t* task = opaque;
JSValue source_value = JS_GetPropertyStr(context, task->_loadedFiles, module_name); JSValue source_value = JS_GetPropertyStr(context, task->_loadedFiles, module_name);

View File

@ -208,7 +208,7 @@ static JSValue _taskstub_create(JSContext* context, JSValueConst this_val, int a
return result; return result;
} }
void _taskstub_gc_mark(JSRuntime* rt, JSValueConst value, JS_MarkFunc mark_func) static void _taskstub_gc_mark(JSRuntime* rt, JSValueConst value, JS_MarkFunc mark_func)
{ {
tf_taskstub_t* stub = JS_GetOpaque(value, _classId); tf_taskstub_t* stub = JS_GetOpaque(value, _classId);
if (stub) if (stub)

View File

@ -189,7 +189,7 @@ int tf_tls_session_get_peer_certificate(tf_tls_session_t* session, char* buffer,
} }
#if OPENSSL_VERSION_NUMBER < 0x10100000L #if OPENSSL_VERSION_NUMBER < 0x10100000L
bool _tls_session_wildcard_match(const char* pattern, size_t pattern_length, const char* name) static bool _tls_session_wildcard_match(const char* pattern, size_t pattern_length, const char* name)
{ {
const char* it = pattern; const char* it = pattern;
while (it - pattern < pattern_length && *name) while (it - pattern < pattern_length && *name)

View File

@ -17,14 +17,10 @@ typedef struct _tf_tls_context_t {
JSValue object; JSValue object;
} tf_tls_context_t; } tf_tls_context_t;
static JSValue _tls_context_set_certificate(JSContext* context, JSValueConst this_val, int argc, JSValueConst* argv);
static JSValue _tls_context_set_private_key(JSContext* context, JSValueConst this_val, int argc, JSValueConst* argv);
static JSValue _tls_context_add_trusted_certificate(JSContext* context, JSValueConst this_val, int argc, JSValueConst* argv);
static JSValue _tls_context_create(JSContext* context, JSValueConst this_val, int argc, JSValueConst* argv); static JSValue _tls_context_create(JSContext* context, JSValueConst this_val, int argc, JSValueConst* argv);
static void _tls_context_finalizer(JSRuntime *runtime, JSValue value); static void _tls_context_finalizer(JSRuntime *runtime, JSValue value);
JSValue _tls_context_set_certificate(JSContext* context, JSValueConst this_val, int argc, JSValueConst* argv) static JSValue _tls_context_set_certificate(JSContext* context, JSValueConst this_val, int argc, JSValueConst* argv)
{ {
tf_tls_context_t* tls = JS_GetOpaque(this_val, _classId); tf_tls_context_t* tls = JS_GetOpaque(this_val, _classId);
const char* value = JS_ToCString(context, argv[0]); const char* value = JS_ToCString(context, argv[0]);
@ -33,7 +29,7 @@ JSValue _tls_context_set_certificate(JSContext* context, JSValueConst this_val,
return JS_UNDEFINED; return JS_UNDEFINED;
} }
JSValue _tls_context_set_private_key(JSContext* context, JSValueConst this_val, int argc, JSValueConst* argv) static JSValue _tls_context_set_private_key(JSContext* context, JSValueConst this_val, int argc, JSValueConst* argv)
{ {
tf_tls_context_t* tls = JS_GetOpaque(this_val, _classId); tf_tls_context_t* tls = JS_GetOpaque(this_val, _classId);
const char* value = JS_ToCString(context, argv[0]); const char* value = JS_ToCString(context, argv[0]);
@ -42,7 +38,7 @@ JSValue _tls_context_set_private_key(JSContext* context, JSValueConst this_val,
return JS_UNDEFINED; return JS_UNDEFINED;
} }
JSValue _tls_context_add_trusted_certificate(JSContext* context, JSValueConst this_val, int argc, JSValueConst* argv) static JSValue _tls_context_add_trusted_certificate(JSContext* context, JSValueConst this_val, int argc, JSValueConst* argv)
{ {
tf_tls_context_t* tls = JS_GetOpaque(this_val, _classId); tf_tls_context_t* tls = JS_GetOpaque(this_val, _classId);
const char* value = JS_ToCString(context, argv[0]); const char* value = JS_ToCString(context, argv[0]);
@ -77,7 +73,7 @@ int tf_tls_context_get_count()
return _count; return _count;
} }
JSValue _tls_context_create(JSContext* context, JSValueConst this_val, int argc, JSValueConst* argv) static JSValue _tls_context_create(JSContext* context, JSValueConst this_val, int argc, JSValueConst* argv)
{ {
tf_tls_context_t* tls = tf_malloc(sizeof(tf_tls_context_t)); tf_tls_context_t* tls = tf_malloc(sizeof(tf_tls_context_t));
memset(tls, 0, sizeof(*tls)); memset(tls, 0, sizeof(*tls));
@ -96,7 +92,7 @@ JSValue _tls_context_create(JSContext* context, JSValueConst this_val, int argc,
return tls->object; return tls->object;
} }
void _tls_context_finalizer(JSRuntime *runtime, JSValue value) static void _tls_context_finalizer(JSRuntime *runtime, JSValue value)
{ {
tf_tls_context_t* tls = JS_GetOpaque(value, _classId); tf_tls_context_t* tls = JS_GetOpaque(value, _classId);
if (tls->context) if (tls->context)

View File

@ -183,7 +183,7 @@ JSValue tf_util_try_get_typed_array_buffer(JSContext* context, JSValueConst obj,
return result; return result;
} }
JSValue _util_print(JSContext* context, JSValueConst this_val, int argc, JSValueConst* argv) static JSValue _util_print(JSContext* context, JSValueConst this_val, int argc, JSValueConst* argv)
{ {
tf_task_t* task = JS_GetContextOpaque(context); tf_task_t* task = JS_GetContextOpaque(context);
if (task) if (task)