forked from cory/tildefriends
Appease gcc 12's analyzer.
git-svn-id: https://www.unprompted.com/svn/projects/tildefriends/trunk@4740 ed5197a5-7fde-0310-b194-c3ffbd925b24
This commit is contained in:
203
src/ssb.rpc.c
203
src/ssb.rpc.c
@ -563,72 +563,74 @@ static void _tf_ssb_rpc_connection_blobs_createWants_callback(tf_ssb_connection_
|
||||
return;
|
||||
}
|
||||
|
||||
JSPropertyEnum* ptab;
|
||||
uint32_t plen;
|
||||
JS_GetOwnPropertyNames(context, &ptab, &plen, args, JS_GPN_STRING_MASK);
|
||||
for (uint32_t i = 0; i < plen; ++i)
|
||||
JSPropertyEnum* ptab = NULL;
|
||||
uint32_t plen = 0;
|
||||
if (JS_GetOwnPropertyNames(context, &ptab, &plen, args, JS_GPN_STRING_MASK) == 0)
|
||||
{
|
||||
JSValue key = JS_AtomToString(context, ptab[i].atom);
|
||||
JSPropertyDescriptor desc;
|
||||
JSValue key_value = JS_NULL;
|
||||
if (JS_GetOwnProperty(context, &desc, args, ptab[i].atom) == 1)
|
||||
for (uint32_t i = 0; i < plen; ++i)
|
||||
{
|
||||
key_value = desc.value;
|
||||
JS_FreeValue(context, desc.setter);
|
||||
JS_FreeValue(context, desc.getter);
|
||||
}
|
||||
const char* blob_id = JS_ToCString(context, key);
|
||||
int64_t size = 0;
|
||||
JS_ToInt64(context, &size, key_value);
|
||||
if (--blob_wants->wants_sent == 0)
|
||||
{
|
||||
_tf_ssb_rpc_request_more_blobs(connection);
|
||||
}
|
||||
if (size < 0)
|
||||
{
|
||||
size_t blob_size = 0;
|
||||
if (tf_ssb_db_blob_get(ssb, blob_id, NULL, &blob_size))
|
||||
JSValue key = JS_AtomToString(context, ptab[i].atom);
|
||||
JSPropertyDescriptor desc;
|
||||
JSValue key_value = JS_NULL;
|
||||
if (JS_GetOwnProperty(context, &desc, args, ptab[i].atom) == 1)
|
||||
{
|
||||
JSValue message = JS_NewObject(context);
|
||||
JS_SetPropertyStr(context, message, blob_id, JS_NewInt64(context, blob_size));
|
||||
tf_ssb_connection_rpc_send_json(
|
||||
connection,
|
||||
k_ssb_rpc_flag_stream,
|
||||
-blob_wants->request_number,
|
||||
message,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL);
|
||||
JS_FreeValue(context, message);
|
||||
key_value = desc.value;
|
||||
JS_FreeValue(context, desc.setter);
|
||||
JS_FreeValue(context, desc.getter);
|
||||
}
|
||||
else if (size == -1LL)
|
||||
const char* blob_id = JS_ToCString(context, key);
|
||||
int64_t size = 0;
|
||||
JS_ToInt64(context, &size, key_value);
|
||||
if (--blob_wants->wants_sent == 0)
|
||||
{
|
||||
JSValue message = JS_NewObject(context);
|
||||
JS_SetPropertyStr(context, message, blob_id, JS_NewInt64(context, -2));
|
||||
tf_ssb_connection_rpc_send_json(
|
||||
connection,
|
||||
k_ssb_rpc_flag_stream,
|
||||
-blob_wants->request_number,
|
||||
message,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL);
|
||||
JS_FreeValue(context, message);
|
||||
_tf_ssb_rpc_request_more_blobs(connection);
|
||||
}
|
||||
if (size < 0)
|
||||
{
|
||||
size_t blob_size = 0;
|
||||
if (tf_ssb_db_blob_get(ssb, blob_id, NULL, &blob_size))
|
||||
{
|
||||
JSValue message = JS_NewObject(context);
|
||||
JS_SetPropertyStr(context, message, blob_id, JS_NewInt64(context, blob_size));
|
||||
tf_ssb_connection_rpc_send_json(
|
||||
connection,
|
||||
k_ssb_rpc_flag_stream,
|
||||
-blob_wants->request_number,
|
||||
message,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL);
|
||||
JS_FreeValue(context, message);
|
||||
}
|
||||
else if (size == -1LL)
|
||||
{
|
||||
JSValue message = JS_NewObject(context);
|
||||
JS_SetPropertyStr(context, message, blob_id, JS_NewInt64(context, -2));
|
||||
tf_ssb_connection_rpc_send_json(
|
||||
connection,
|
||||
k_ssb_rpc_flag_stream,
|
||||
-blob_wants->request_number,
|
||||
message,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL);
|
||||
JS_FreeValue(context, message);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
_tf_ssb_rpc_connection_blobs_get(connection, blob_id, size);
|
||||
}
|
||||
JS_FreeCString(context, blob_id);
|
||||
JS_FreeValue(context, key);
|
||||
JS_FreeValue(context, key_value);
|
||||
}
|
||||
else
|
||||
for (uint32_t i = 0; i < plen; ++i)
|
||||
{
|
||||
_tf_ssb_rpc_connection_blobs_get(connection, blob_id, size);
|
||||
JS_FreeAtom(context, ptab[i].atom);
|
||||
}
|
||||
JS_FreeCString(context, blob_id);
|
||||
JS_FreeValue(context, key);
|
||||
JS_FreeValue(context, key_value);
|
||||
js_free(context, ptab);
|
||||
}
|
||||
for (uint32_t i = 0; i < plen; ++i)
|
||||
{
|
||||
JS_FreeAtom(context, ptab[i].atom);
|
||||
}
|
||||
js_free(context, ptab);
|
||||
}
|
||||
|
||||
static void _tf_ssb_rpc_connection_room_attendants_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)
|
||||
@ -1007,23 +1009,33 @@ static void _tf_ssb_rpc_ebt_replicate_send_clock(tf_ssb_connection_t* connection
|
||||
|
||||
if (!JS_IsUndefined(message))
|
||||
{
|
||||
JSPropertyEnum* ptab;
|
||||
JSPropertyEnum* ptab = NULL;
|
||||
uint32_t plen = 0;
|
||||
JS_GetOwnPropertyNames(context, &ptab, &plen, message, JS_GPN_STRING_MASK);
|
||||
work->clock_count = (int)plen;
|
||||
work->clock = tf_malloc(sizeof(ebt_clock_row_t) * plen);
|
||||
for (uint32_t i = 0; i < plen; ++i)
|
||||
if (JS_GetOwnPropertyNames(context, &ptab, &plen, message, JS_GPN_STRING_MASK) == 0)
|
||||
{
|
||||
const char* id = JS_AtomToCString(context, ptab[i].atom);
|
||||
snprintf(work->clock[i].id, sizeof(work->clock[i].id), "%s", id);
|
||||
JS_FreeCString(context, id);
|
||||
work->clock_count = (int)plen;
|
||||
work->clock = tf_malloc(sizeof(ebt_clock_row_t) * plen);
|
||||
memset(work->clock, 0, sizeof(ebt_clock_row_t) * plen);
|
||||
for (uint32_t i = 0; i < plen; ++i)
|
||||
{
|
||||
const char* id = JS_AtomToCString(context, ptab[i].atom);
|
||||
snprintf(work->clock[i].id, sizeof(work->clock[i].id), "%s", id);
|
||||
JS_FreeCString(context, id);
|
||||
|
||||
JSValue value = JS_GetProperty(context, message, ptab[i].atom);
|
||||
JS_ToInt64(context, &work->clock[i].value, value);
|
||||
JS_FreeValue(context, value);
|
||||
JS_FreeAtom(context, ptab[i].atom);
|
||||
JSPropertyDescriptor desc = { 0 };
|
||||
JSValue key_value = JS_UNDEFINED;
|
||||
if (JS_GetOwnProperty(context, &desc, message, ptab[i].atom) == 1)
|
||||
{
|
||||
key_value = desc.value;
|
||||
JS_FreeValue(context, desc.setter);
|
||||
JS_FreeValue(context, desc.getter);
|
||||
}
|
||||
JS_ToInt64(context, &work->clock[i].value, key_value);
|
||||
JS_FreeValue(context, key_value);
|
||||
JS_FreeAtom(context, ptab[i].atom);
|
||||
}
|
||||
js_free(context, ptab);
|
||||
}
|
||||
js_free(context, ptab);
|
||||
}
|
||||
|
||||
tf_ssb_connection_run_work(connection, _tf_ssb_rpc_ebt_replicate_send_clock_work, _tf_ssb_rpc_ebt_replicate_send_clock_after_work, work);
|
||||
@ -1040,36 +1052,45 @@ static void _tf_ssb_rpc_ebt_replicate_send_messages(tf_ssb_connection_t* connect
|
||||
JSContext* context = tf_ssb_get_context(ssb);
|
||||
JSPropertyEnum* ptab = NULL;
|
||||
uint32_t plen = 0;
|
||||
JS_GetOwnPropertyNames(context, &ptab, &plen, message, JS_GPN_STRING_MASK);
|
||||
for (uint32_t i = 0; i < plen; ++i)
|
||||
if (JS_GetOwnPropertyNames(context, &ptab, &plen, message, JS_GPN_STRING_MASK) == 0)
|
||||
{
|
||||
JSValue in_clock = JS_GetProperty(context, message, ptab[i].atom);
|
||||
if (!JS_IsUndefined(in_clock))
|
||||
for (uint32_t i = 0; i < plen; ++i)
|
||||
{
|
||||
JSValue key = JS_AtomToString(context, ptab[i].atom);
|
||||
int64_t sequence = -1;
|
||||
JS_ToInt64(context, &sequence, in_clock);
|
||||
const char* author = JS_ToCString(context, key);
|
||||
if (sequence >= 0 && (sequence & 1) == 0)
|
||||
JSValue in_clock = JS_UNDEFINED;
|
||||
JSPropertyDescriptor desc = { 0 };
|
||||
if (JS_GetOwnProperty(context, &desc, message, ptab[i].atom) == 1)
|
||||
{
|
||||
int32_t request_number = tf_ssb_connection_get_ebt_request_number(connection);
|
||||
_tf_ssb_connection_send_history_stream(connection, request_number, author, sequence >> 1, false, true);
|
||||
tf_ssb_connection_add_new_message_request(connection, author, request_number, false);
|
||||
in_clock = desc.value;
|
||||
JS_FreeValue(context, desc.setter);
|
||||
JS_FreeValue(context, desc.getter);
|
||||
}
|
||||
else
|
||||
if (!JS_IsUndefined(in_clock))
|
||||
{
|
||||
tf_ssb_connection_remove_new_message_request(connection, author);
|
||||
JSValue key = JS_AtomToString(context, ptab[i].atom);
|
||||
int64_t sequence = -1;
|
||||
JS_ToInt64(context, &sequence, in_clock);
|
||||
const char* author = JS_ToCString(context, key);
|
||||
if (sequence >= 0 && (sequence & 1) == 0)
|
||||
{
|
||||
int32_t request_number = tf_ssb_connection_get_ebt_request_number(connection);
|
||||
_tf_ssb_connection_send_history_stream(connection, request_number, author, sequence >> 1, false, true);
|
||||
tf_ssb_connection_add_new_message_request(connection, author, request_number, false);
|
||||
}
|
||||
else
|
||||
{
|
||||
tf_ssb_connection_remove_new_message_request(connection, author);
|
||||
}
|
||||
JS_FreeCString(context, author);
|
||||
JS_FreeValue(context, key);
|
||||
}
|
||||
JS_FreeCString(context, author);
|
||||
JS_FreeValue(context, key);
|
||||
JS_FreeValue(context, in_clock);
|
||||
}
|
||||
JS_FreeValue(context, in_clock);
|
||||
for (uint32_t i = 0; i < plen; ++i)
|
||||
{
|
||||
JS_FreeAtom(context, ptab[i].atom);
|
||||
}
|
||||
js_free(context, ptab);
|
||||
}
|
||||
for (uint32_t i = 0; i < plen; ++i)
|
||||
{
|
||||
JS_FreeAtom(context, ptab[i].atom);
|
||||
}
|
||||
js_free(context, ptab);
|
||||
}
|
||||
|
||||
static void _tf_ssb_rpc_ebt_replicate(tf_ssb_connection_t* connection, uint8_t flags, int32_t request_number, JSValue args, const uint8_t* message, size_t size, void* user_data)
|
||||
|
Reference in New Issue
Block a user