The SSH host key has changed on 8 April, 2022 to this one: SHA256:573uTBSeh74kvOo0HJXi5ijdzRm8me27suzNEDlGyrQ

wip: port all enums, add signals

initial-version
Gergely Polonkai 4 years ago
parent 91c5225e55
commit cc4e304418
  1. 93
      ssb-gtk/sbot.c

@ -28,6 +28,20 @@ struct _SsbScuttler {
GSocketConnection *connection;
};
typedef enum {
SSB_PACKET_TYPE_BUFFER = 0,
SSB_PACKET_TYPE_STRING = 1,
SSB_PACKET_TYPE_JSON = 2,
} SsbPacketType;
typedef enum {
SSB_PACKET_FLAGS_BUFFER = 0,
SSB_PACKET_FLAGS_STRING = 1,
SSB_PACKET_FLAGS_JSON = 2,
SSB_PACKET_FLAGS_END = 4,
SSB_PACKET_FLAGS_STREAM = 8,
} SsbPacketFlags;
typedef enum {
SSB_RPC_ASYNC,
SSB_RPC_SOURCE,
@ -36,10 +50,10 @@ typedef enum {
} SsbRPCType;
typedef enum {
SSB_PACKET_TYPE_BUFFER = 0,
SSB_PACKET_TYPE_STRING = 1,
SSB_PACKET_TYPE_JSON = 2,
} SsbPacketType;
SSB_STREAM_STATE_OPEN,
SSB_STREAM_STATE_ENDED_OK,
SSB_STREAM_STATE_ENDED_ERROR,
} SsbStreamState;
#define MAX_MESSAGE_SIZE 32768
#define BOXS_MAXLEN 4096
@ -72,6 +86,15 @@ static const guchar ssb_cap[] = {
0x08, 0x39, 0xb7, 0x55, 0x84, 0x5a, 0x9f, 0xfb
};
enum {
SIGNAL_INITIALISED,
SIGNAL_CONNECTED,
SIGNAL_LAST
};
static guint ssb_scuttler_signals[SIGNAL_LAST] = {0
};
GMainLoop *scuttle_loop = NULL;
SsbScuttler *singleton = NULL;
@ -202,6 +225,12 @@ parse_commented_json(gchar *json_data, GError **error)
return result;
}
static void
emit_initialised(SsbScuttler *scuttler, gboolean success)
{
g_signal_emit(scuttler, ssb_scuttler_signals[SIGNAL_INITIALISED], 0, success);
}
static void
initialise(SsbScuttler *scuttler, gchar *ssb_dir)
{
@ -221,6 +250,8 @@ initialise(SsbScuttler *scuttler, gchar *ssb_dir)
g_free(config_data);
emit_initialised(scuttler, FALSE);
return;
}
@ -240,6 +271,8 @@ initialise(SsbScuttler *scuttler, gchar *ssb_dir)
g_free(config_data);
emit_initialised(scuttler, FALSE);
return;
}
@ -248,6 +281,8 @@ initialise(SsbScuttler *scuttler, gchar *ssb_dir)
if ((private_key = g_strdup(json_object_get_string_member(secret_object, "private"))) == NULL) {
g_critical("Could not read private key, can not continue");
emit_initialised(scuttler, FALSE);
return;
}
@ -262,6 +297,8 @@ initialise(SsbScuttler *scuttler, gchar *ssb_dir)
g_critical("Could not decode private key, can not continue");
g_free(private_key);
emit_initialised(scuttler, FALSE);
return;
}
@ -277,6 +314,8 @@ initialise(SsbScuttler *scuttler, gchar *ssb_dir)
memcpy(scuttler->app_key, ssb_cap, sizeof(ssb_cap));
scuttler->initialised = TRUE;
emit_initialised(scuttler, TRUE);
}
/**
@ -313,6 +352,7 @@ second_hook_cb()
return TRUE;
}
// was: write_all
static gboolean
ssb_scuttler_send_plain(SsbScuttler *scuttler, gpointer data, gsize data_len, GError **error)
{
@ -328,6 +368,7 @@ ssb_scuttler_send_plain(SsbScuttler *scuttler, gpointer data, gsize data_len, GE
return TRUE;
}
// was: read_all
static gboolean
ssb_scuttler_read(SsbScuttler *scuttler, gpointer buffer, gsize buffer_len, GError **error)
{
@ -343,6 +384,7 @@ ssb_scuttler_read(SsbScuttler *scuttler, gpointer buffer, gsize buffer_len, GErr
return TRUE;
}
// was: shs_connect
static gboolean
ssb_scuttler_shs_connect(SsbScuttler *scuttler, GError **error)
{
@ -558,6 +600,13 @@ ssb_scuttler_shs_connect(SsbScuttler *scuttler, GError **error)
return TRUE;
}
static void
emit_connected(SsbScuttler *scuttler, gboolean success)
{
g_signal_emit(scuttler, ssb_scuttler_signals[SIGNAL_CONNECTED], 0, success);
}
// extracted from main
static gboolean
ssb_scuttler_connect(SsbScuttler *scuttler, GError **error)
{
@ -603,6 +652,7 @@ increment_nonce(guchar nonce[24])
}
}
// was: bs_write_packet
static gboolean
ssb_scuttler_write_packet(SsbScuttler *scuttler, const guchar *data, guint16 data_len, GError **error)
{
@ -642,6 +692,7 @@ ssb_scuttler_write_packet(SsbScuttler *scuttler, const guchar *data, guint16 dat
return TRUE;
}
// was: bs_write
static gboolean
ssb_scuttler_send_bytes(SsbScuttler *scuttler, const guchar *data, gsize data_len, GError **error)
{
@ -663,6 +714,7 @@ ssb_scuttler_send_bytes(SsbScuttler *scuttler, const guchar *data, gsize data_le
return TRUE;
}
// was: ps_write
static gboolean
ssb_scuttler_send_packet(SsbScuttler *scuttler,
SsbPacketType type,
@ -694,6 +746,7 @@ ssb_scuttler_send_packet(SsbScuttler *scuttler,
return TRUE;
}
// was: muxrpc_call
static void
ssb_scuttler_muxrpc_call(SsbScuttler *scuttler,
const gchar *method,
@ -725,9 +778,9 @@ ssb_scuttler_muxrpc_call(SsbScuttler *scuttler,
g_set_error(error, SSB_SCUTTLER_ERROR, SSB_SCUTTLER_ERROR_REQUEST_TOO_LARGE, "Request too large");
return;
}zq
}
if (!ssb_scuttler_send_packet(scuttler, request, request_len, SSB_PACKET_TYPE_JSON, req_id, !is_request, FALSE, &err)) {
if (!ssb_scuttler_send_packet(scuttler, SSB_PACKET_TYPE_JSON, request, request_len, req_id, !is_request, FALSE, &err)) {
g_propagate_error(error, err);
return;
@ -770,6 +823,34 @@ ssb_scuttler_class_init(SsbScuttlerClass *klass)
gobject_class->dispose = ssb_scuttler_dispose;
gobject_class->finalize = ssb_scuttler_finalize;
/**
* SsbScuttler::initialised:
* @success: if %TRUE, initialisation succeeded
*
* Emitted when the SsbScuttler object is initialised.
*/
ssb_scuttler_signals[SIGNAL_INITIALISED] = g_signal_new(
"initialised",
G_TYPE_FROM_CLASS(klass),
G_SIGNAL_RUN_FIRST,
0, NULL, NULL,
g_cclosure_marshal_VOID__BOOLEAN, G_TYPE_NONE, 1,
G_TYPE_BOOLEAN);
/**
* SsbScuttler::connected:
* @success: if %TRUE, the connection and handshake has succeeded
*
* Emitted when the SsbScuttler object is connected to the SBOT server.
*/
ssb_scuttler_signals[SIGNAL_CONNECTED] = g_signal_new(
"connected",
G_TYPE_FROM_CLASS(klass),
G_SIGNAL_RUN_FIRST,
0, NULL, NULL,
g_cclosure_marshal_VOID__BOOLEAN, G_TYPE_NONE, 1,
G_TYPE_BOOLEAN);
}
static void

Loading…
Cancel
Save