forked from cory/tildefriends
Make the connections tab know more about tunnels and such.
git-svn-id: https://www.unprompted.com/svn/projects/tildefriends/trunk@4426 ed5197a5-7fde-0310-b194-c3ffbd925b24
This commit is contained in:
36
src/ssb.js.c
36
src/ssb.js.c
@ -22,6 +22,10 @@
|
||||
#include <assert.h>
|
||||
#include <inttypes.h>
|
||||
|
||||
#if !defined(_countof)
|
||||
#define _countof(a) ((int)(sizeof((a)) / sizeof(*(a))))
|
||||
#endif
|
||||
|
||||
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);
|
||||
@ -319,16 +323,34 @@ static JSValue _tf_ssb_connections(JSContext* context, JSValueConst this_val, in
|
||||
tf_ssb_t* ssb = JS_GetOpaque(this_val, _tf_ssb_classId);
|
||||
if (ssb)
|
||||
{
|
||||
const char** connections = tf_ssb_get_connection_ids(ssb);
|
||||
if (connections)
|
||||
tf_ssb_connection_t* connections[32];
|
||||
int count = tf_ssb_get_connections(ssb, connections, _countof(connections));
|
||||
|
||||
result = JS_NewArray(context);
|
||||
for (int i = 0; i < count; i++)
|
||||
{
|
||||
result = JS_NewArray(context);
|
||||
uint32_t i = 0;
|
||||
for (const char** p = connections; *p; p++, i++)
|
||||
char id[k_id_base64_len] = { 0 };
|
||||
tf_ssb_connection_t* connection = connections[i];
|
||||
JSValue object = JS_NewObject(context);
|
||||
tf_ssb_connection_get_id(connection, id, sizeof(id));
|
||||
JS_SetPropertyStr(context, object, "id", JS_NewString(context, id));
|
||||
JS_SetPropertyStr(context, object, "host", JS_NewString(context, tf_ssb_connection_get_host(connection)));
|
||||
JS_SetPropertyStr(context, object, "port", JS_NewInt32(context, tf_ssb_connection_get_port(connection)));
|
||||
tf_ssb_connection_t* tunnel = tf_ssb_connection_get_tunnel(connection);
|
||||
if (tunnel)
|
||||
{
|
||||
JS_SetPropertyUint32(context, result, i, JS_NewString(context, *p));
|
||||
int tunnel_index = -1;
|
||||
for (int j = 0; j < count; j++)
|
||||
{
|
||||
if (connections[j] == tunnel)
|
||||
{
|
||||
tunnel_index = j;
|
||||
break;
|
||||
}
|
||||
}
|
||||
JS_SetPropertyStr(context, object, "tunnel", JS_NewInt32(context, tunnel_index));
|
||||
}
|
||||
tf_free(connections);
|
||||
JS_SetPropertyUint32(context, result, i, object);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
|
Reference in New Issue
Block a user