FS-10167: Significant overhaul to libblade and it's operations to match the first layer required by the blade protocol, still more work to be done but nodes can connect to router nodes and get initial identities registered based on realms configured for the master router node.
This commit is contained in:
parent
bbd87e4a67
commit
9fa52c742e
|
@ -21,6 +21,8 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "blades", "test\blades.vcxpr
|
|||
EndProject
|
||||
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "bladec", "test\bladec.vcxproj", "{4A70CDA9-AC5B-4818-BCF2-B0DD1B8F5F5F}"
|
||||
EndProject
|
||||
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "switchblade", "switchblade\switchblade.vcxproj", "{8330E669-77F3-4F70-A275-6F7BABE050A7}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|x64 = Debug|x64
|
||||
|
@ -177,6 +179,22 @@ Global
|
|||
{4A70CDA9-AC5B-4818-BCF2-B0DD1B8F5F5F}.ReleaseDLL|x64.Build.0 = Release|x64
|
||||
{4A70CDA9-AC5B-4818-BCF2-B0DD1B8F5F5F}.ReleaseDLL|x86.ActiveCfg = Release|Win32
|
||||
{4A70CDA9-AC5B-4818-BCF2-B0DD1B8F5F5F}.ReleaseDLL|x86.Build.0 = Release|Win32
|
||||
{8330E669-77F3-4F70-A275-6F7BABE050A7}.Debug|x64.ActiveCfg = Debug|x64
|
||||
{8330E669-77F3-4F70-A275-6F7BABE050A7}.Debug|x64.Build.0 = Debug|x64
|
||||
{8330E669-77F3-4F70-A275-6F7BABE050A7}.Debug|x86.ActiveCfg = Debug|Win32
|
||||
{8330E669-77F3-4F70-A275-6F7BABE050A7}.Debug|x86.Build.0 = Debug|Win32
|
||||
{8330E669-77F3-4F70-A275-6F7BABE050A7}.DebugDLL|x64.ActiveCfg = Debug|x64
|
||||
{8330E669-77F3-4F70-A275-6F7BABE050A7}.DebugDLL|x64.Build.0 = Debug|x64
|
||||
{8330E669-77F3-4F70-A275-6F7BABE050A7}.DebugDLL|x86.ActiveCfg = Debug|Win32
|
||||
{8330E669-77F3-4F70-A275-6F7BABE050A7}.DebugDLL|x86.Build.0 = Debug|Win32
|
||||
{8330E669-77F3-4F70-A275-6F7BABE050A7}.Release|x64.ActiveCfg = Release|x64
|
||||
{8330E669-77F3-4F70-A275-6F7BABE050A7}.Release|x64.Build.0 = Release|x64
|
||||
{8330E669-77F3-4F70-A275-6F7BABE050A7}.Release|x86.ActiveCfg = Release|Win32
|
||||
{8330E669-77F3-4F70-A275-6F7BABE050A7}.Release|x86.Build.0 = Release|Win32
|
||||
{8330E669-77F3-4F70-A275-6F7BABE050A7}.ReleaseDLL|x64.ActiveCfg = Release|x64
|
||||
{8330E669-77F3-4F70-A275-6F7BABE050A7}.ReleaseDLL|x64.Build.0 = Release|x64
|
||||
{8330E669-77F3-4F70-A275-6F7BABE050A7}.ReleaseDLL|x86.ActiveCfg = Release|Win32
|
||||
{8330E669-77F3-4F70-A275-6F7BABE050A7}.ReleaseDLL|x86.Build.0 = Release|Win32
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
|
|
|
@ -189,45 +189,24 @@
|
|||
<ItemGroup>
|
||||
<ClCompile Include="src\blade.c" />
|
||||
<ClCompile Include="src\blade_connection.c" />
|
||||
<ClCompile Include="src\blade_datastore.c" />
|
||||
<ClCompile Include="src\blade_identity.c" />
|
||||
<ClCompile Include="src\blade_method.c" />
|
||||
<ClCompile Include="src\blade_module.c" />
|
||||
<ClCompile Include="src\blade_module_wss.c" />
|
||||
<ClCompile Include="src\blade_protocol.c" />
|
||||
<ClCompile Include="src\blade_jsonrpc.c" />
|
||||
<ClCompile Include="src\blade_transport_wss.c" />
|
||||
<ClCompile Include="src\blade_session.c" />
|
||||
<ClCompile Include="src\blade_space.c" />
|
||||
<ClCompile Include="src\blade_stack.c" />
|
||||
<ClCompile Include="src\dht\ks_dht.c" />
|
||||
<ClCompile Include="src\dht\ks_dht_bucket.c" />
|
||||
<ClCompile Include="src\dht\ks_dht_datagram.c" />
|
||||
<ClCompile Include="src\dht\ks_dht_distribute.c" />
|
||||
<ClCompile Include="src\dht\ks_dht_endpoint.c" />
|
||||
<ClCompile Include="src\dht\ks_dht_job.c" />
|
||||
<ClCompile Include="src\dht\ks_dht_message.c" />
|
||||
<ClCompile Include="src\dht\ks_dht_publish.c" />
|
||||
<ClCompile Include="src\dht\ks_dht_search.c" />
|
||||
<ClCompile Include="src\dht\ks_dht_storageitem.c" />
|
||||
<ClCompile Include="src\dht\ks_dht_transaction.c" />
|
||||
<ClCompile Include="src\ks_bencode.c" />
|
||||
<ClCompile Include="src\blade_transport.c" />
|
||||
<ClCompile Include="src\unqlite.c" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="src\include\blade.h" />
|
||||
<ClInclude Include="src\include\blade_connection.h" />
|
||||
<ClInclude Include="src\include\blade_datastore.h" />
|
||||
<ClInclude Include="src\include\blade_identity.h" />
|
||||
<ClInclude Include="src\include\blade_method.h" />
|
||||
<ClInclude Include="src\include\blade_module.h" />
|
||||
<ClInclude Include="src\include\blade_module_wss.h" />
|
||||
<ClInclude Include="src\include\blade_protocol.h" />
|
||||
<ClInclude Include="src\include\blade_jsonrpc.h" />
|
||||
<ClInclude Include="src\include\blade_transport_wss.h" />
|
||||
<ClInclude Include="src\include\blade_session.h" />
|
||||
<ClInclude Include="src\include\blade_space.h" />
|
||||
<ClInclude Include="src\include\blade_stack.h" />
|
||||
<ClInclude Include="src\include\blade_transport.h" />
|
||||
<ClInclude Include="src\include\blade_types.h" />
|
||||
<ClInclude Include="src\include\ks_bencode.h" />
|
||||
<ClInclude Include="src\include\ks_dht-int.h" />
|
||||
<ClInclude Include="src\include\ks_dht.h" />
|
||||
<ClInclude Include="src\include\unqlite.h" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
|
|
|
@ -24,67 +24,22 @@
|
|||
<ClCompile Include="src\blade_connection.c">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="src\blade_datastore.c">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="src\blade_identity.c">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="src\blade_method.c">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="src\blade_module.c">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="src\blade_module_wss.c">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="src\blade_protocol.c">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="src\blade_session.c">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="src\blade_space.c">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="src\blade_stack.c">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="src\ks_bencode.c">
|
||||
<ClCompile Include="src\blade_transport.c">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="src\dht\ks_dht.c">
|
||||
<ClCompile Include="src\blade_jsonrpc.c">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="src\dht\ks_dht_bucket.c">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="src\dht\ks_dht_datagram.c">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="src\dht\ks_dht_distribute.c">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="src\dht\ks_dht_endpoint.c">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="src\dht\ks_dht_job.c">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="src\dht\ks_dht_message.c">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="src\dht\ks_dht_publish.c">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="src\dht\ks_dht_search.c">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="src\dht\ks_dht_storageitem.c">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="src\dht\ks_dht_transaction.c">
|
||||
<ClCompile Include="src\blade_transport_wss.c">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
|
@ -98,43 +53,25 @@
|
|||
<ClInclude Include="src\include\blade_connection.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="src\include\blade_datastore.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="src\include\blade_identity.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="src\include\blade_method.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="src\include\blade_module.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="src\include\blade_protocol.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="src\include\blade_session.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="src\include\blade_space.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="src\include\blade_stack.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="src\include\blade_types.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="src\include\ks_bencode.h">
|
||||
<ClInclude Include="src\include\blade_transport.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="src\include\ks_dht.h">
|
||||
<ClInclude Include="src\include\blade_jsonrpc.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="src\include\ks_dht-int.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="src\include\blade_module_wss.h">
|
||||
<ClInclude Include="src\include\blade_transport_wss.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
|
|
|
@ -54,12 +54,9 @@ struct blade_connection_s {
|
|||
};
|
||||
|
||||
void *blade_connection_state_thread(ks_thread_t *thread, void *data);
|
||||
ks_status_t blade_connection_state_on_disconnect(blade_connection_t *bc);
|
||||
ks_status_t blade_connection_state_on_new(blade_connection_t *bc);
|
||||
ks_status_t blade_connection_state_on_connect(blade_connection_t *bc);
|
||||
ks_status_t blade_connection_state_on_attach(blade_connection_t *bc);
|
||||
ks_status_t blade_connection_state_on_detach(blade_connection_t *bc);
|
||||
ks_status_t blade_connection_state_on_ready(blade_connection_t *bc);
|
||||
ks_status_t blade_connection_onstate_startup(blade_connection_t *bc);
|
||||
ks_status_t blade_connection_onstate_shutdown(blade_connection_t *bc);
|
||||
ks_status_t blade_connection_onstate_run(blade_connection_t *bc);
|
||||
|
||||
|
||||
static void blade_connection_cleanup(ks_pool_t *pool, void *ptr, void *arg, ks_pool_cleanup_action_t action, ks_pool_cleanup_type_t type)
|
||||
|
@ -260,29 +257,17 @@ blade_transport_state_callback_t blade_connection_state_callback_lookup(blade_co
|
|||
ks_assert(bc);
|
||||
|
||||
switch (state) {
|
||||
case BLADE_CONNECTION_STATE_DISCONNECT:
|
||||
if (bc->direction == BLADE_CONNECTION_DIRECTION_INBOUND) callback = bc->transport_callbacks->onstate_disconnect_inbound;
|
||||
else if(bc->direction == BLADE_CONNECTION_DIRECTION_OUTBOUND) callback = bc->transport_callbacks->onstate_disconnect_outbound;
|
||||
case BLADE_CONNECTION_STATE_SHUTDOWN:
|
||||
if (bc->direction == BLADE_CONNECTION_DIRECTION_INBOUND) callback = bc->transport_callbacks->onstate_shutdown_inbound;
|
||||
else if(bc->direction == BLADE_CONNECTION_DIRECTION_OUTBOUND) callback = bc->transport_callbacks->onstate_shutdown_outbound;
|
||||
break;
|
||||
case BLADE_CONNECTION_STATE_NEW:
|
||||
if (bc->direction == BLADE_CONNECTION_DIRECTION_INBOUND) callback = bc->transport_callbacks->onstate_new_inbound;
|
||||
else if(bc->direction == BLADE_CONNECTION_DIRECTION_OUTBOUND) callback = bc->transport_callbacks->onstate_new_outbound;
|
||||
case BLADE_CONNECTION_STATE_STARTUP:
|
||||
if (bc->direction == BLADE_CONNECTION_DIRECTION_INBOUND) callback = bc->transport_callbacks->onstate_startup_inbound;
|
||||
else if(bc->direction == BLADE_CONNECTION_DIRECTION_OUTBOUND) callback = bc->transport_callbacks->onstate_startup_outbound;
|
||||
break;
|
||||
case BLADE_CONNECTION_STATE_CONNECT:
|
||||
if (bc->direction == BLADE_CONNECTION_DIRECTION_INBOUND) callback = bc->transport_callbacks->onstate_connect_inbound;
|
||||
else if(bc->direction == BLADE_CONNECTION_DIRECTION_OUTBOUND) callback = bc->transport_callbacks->onstate_connect_outbound;
|
||||
break;
|
||||
case BLADE_CONNECTION_STATE_ATTACH:
|
||||
if (bc->direction == BLADE_CONNECTION_DIRECTION_INBOUND) callback = bc->transport_callbacks->onstate_attach_inbound;
|
||||
else if(bc->direction == BLADE_CONNECTION_DIRECTION_OUTBOUND) callback = bc->transport_callbacks->onstate_attach_outbound;
|
||||
break;
|
||||
case BLADE_CONNECTION_STATE_DETACH:
|
||||
if (bc->direction == BLADE_CONNECTION_DIRECTION_INBOUND) callback = bc->transport_callbacks->onstate_detach_inbound;
|
||||
else if(bc->direction == BLADE_CONNECTION_DIRECTION_OUTBOUND) callback = bc->transport_callbacks->onstate_detach_outbound;
|
||||
break;
|
||||
case BLADE_CONNECTION_STATE_READY:
|
||||
if (bc->direction == BLADE_CONNECTION_DIRECTION_INBOUND) callback = bc->transport_callbacks->onstate_ready_inbound;
|
||||
else if(bc->direction == BLADE_CONNECTION_DIRECTION_OUTBOUND) callback = bc->transport_callbacks->onstate_ready_outbound;
|
||||
case BLADE_CONNECTION_STATE_RUN:
|
||||
if (bc->direction == BLADE_CONNECTION_DIRECTION_INBOUND) callback = bc->transport_callbacks->onstate_run_inbound;
|
||||
else if(bc->direction == BLADE_CONNECTION_DIRECTION_OUTBOUND) callback = bc->transport_callbacks->onstate_run_outbound;
|
||||
break;
|
||||
default: break;
|
||||
}
|
||||
|
@ -322,9 +307,9 @@ KS_DECLARE(void) blade_connection_disconnect(blade_connection_t *bc)
|
|||
{
|
||||
ks_assert(bc);
|
||||
|
||||
if (bc->state != BLADE_CONNECTION_STATE_DETACH && bc->state != BLADE_CONNECTION_STATE_DISCONNECT && bc->state != BLADE_CONNECTION_STATE_CLEANUP) {
|
||||
if (bc->state != BLADE_CONNECTION_STATE_SHUTDOWN && bc->state != BLADE_CONNECTION_STATE_CLEANUP) {
|
||||
ks_log(KS_LOG_DEBUG, "Connection (%s) disconnecting\n", bc->id);
|
||||
blade_connection_state_set(bc, BLADE_CONNECTION_STATE_DETACH);
|
||||
blade_connection_state_set(bc, BLADE_CONNECTION_STATE_SHUTDOWN);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -382,24 +367,15 @@ void *blade_connection_state_thread(ks_thread_t *thread, void *data)
|
|||
state = bc->state;
|
||||
|
||||
switch (state) {
|
||||
case BLADE_CONNECTION_STATE_DISCONNECT:
|
||||
blade_connection_state_on_disconnect(bc);
|
||||
case BLADE_CONNECTION_STATE_SHUTDOWN:
|
||||
blade_connection_onstate_shutdown(bc);
|
||||
shutdown = KS_TRUE;
|
||||
break;
|
||||
case BLADE_CONNECTION_STATE_NEW:
|
||||
blade_connection_state_on_new(bc);
|
||||
case BLADE_CONNECTION_STATE_STARTUP:
|
||||
blade_connection_onstate_startup(bc);
|
||||
break;
|
||||
case BLADE_CONNECTION_STATE_CONNECT:
|
||||
blade_connection_state_on_connect(bc);
|
||||
break;
|
||||
case BLADE_CONNECTION_STATE_ATTACH:
|
||||
blade_connection_state_on_attach(bc);
|
||||
break;
|
||||
case BLADE_CONNECTION_STATE_DETACH:
|
||||
blade_connection_state_on_detach(bc);
|
||||
break;
|
||||
case BLADE_CONNECTION_STATE_READY:
|
||||
blade_connection_state_on_ready(bc);
|
||||
case BLADE_CONNECTION_STATE_RUN:
|
||||
blade_connection_onstate_run(bc);
|
||||
break;
|
||||
default: break;
|
||||
}
|
||||
|
@ -411,77 +387,27 @@ void *blade_connection_state_thread(ks_thread_t *thread, void *data)
|
|||
return NULL;
|
||||
}
|
||||
|
||||
ks_status_t blade_connection_state_on_disconnect(blade_connection_t *bc)
|
||||
{
|
||||
blade_transport_state_callback_t callback = NULL;
|
||||
|
||||
ks_assert(bc);
|
||||
|
||||
callback = blade_connection_state_callback_lookup(bc, BLADE_CONNECTION_STATE_DISCONNECT);
|
||||
if (callback) callback(bc, BLADE_CONNECTION_STATE_CONDITION_POST);
|
||||
|
||||
blade_connection_state_set(bc, BLADE_CONNECTION_STATE_CLEANUP);
|
||||
|
||||
return KS_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
ks_status_t blade_connection_state_on_new(blade_connection_t *bc)
|
||||
ks_status_t blade_connection_onstate_startup(blade_connection_t *bc)
|
||||
{
|
||||
blade_transport_state_callback_t callback = NULL;
|
||||
blade_connection_state_hook_t hook = BLADE_CONNECTION_STATE_HOOK_SUCCESS;
|
||||
|
||||
ks_assert(bc);
|
||||
|
||||
callback = blade_connection_state_callback_lookup(bc, BLADE_CONNECTION_STATE_NEW);
|
||||
callback = blade_connection_state_callback_lookup(bc, BLADE_CONNECTION_STATE_STARTUP);
|
||||
if (callback) hook = callback(bc, BLADE_CONNECTION_STATE_CONDITION_POST);
|
||||
|
||||
if (hook == BLADE_CONNECTION_STATE_HOOK_DISCONNECT) blade_connection_disconnect(bc);
|
||||
else if (hook == BLADE_CONNECTION_STATE_HOOK_SUCCESS) {
|
||||
blade_connection_state_set(bc, BLADE_CONNECTION_STATE_CONNECT);
|
||||
}
|
||||
|
||||
return KS_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
ks_status_t blade_connection_state_on_connect(blade_connection_t *bc)
|
||||
{
|
||||
blade_transport_state_callback_t callback = NULL;
|
||||
blade_connection_state_hook_t hook = BLADE_CONNECTION_STATE_HOOK_SUCCESS;
|
||||
|
||||
ks_assert(bc);
|
||||
|
||||
callback = blade_connection_state_callback_lookup(bc, BLADE_CONNECTION_STATE_CONNECT);
|
||||
if (callback) hook = callback(bc, BLADE_CONNECTION_STATE_CONDITION_POST);
|
||||
|
||||
if (hook == BLADE_CONNECTION_STATE_HOOK_DISCONNECT) blade_connection_disconnect(bc);
|
||||
else if (hook == BLADE_CONNECTION_STATE_HOOK_SUCCESS) {
|
||||
blade_connection_state_set(bc, BLADE_CONNECTION_STATE_ATTACH);
|
||||
}
|
||||
|
||||
return KS_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
ks_status_t blade_connection_state_on_attach(blade_connection_t *bc)
|
||||
{
|
||||
blade_transport_state_callback_t callback = NULL;
|
||||
blade_connection_state_hook_t hook = BLADE_CONNECTION_STATE_HOOK_SUCCESS;
|
||||
|
||||
ks_assert(bc);
|
||||
|
||||
callback = blade_connection_state_callback_lookup(bc, BLADE_CONNECTION_STATE_ATTACH);
|
||||
if (callback) hook = callback(bc, BLADE_CONNECTION_STATE_CONDITION_POST);
|
||||
|
||||
if (hook == BLADE_CONNECTION_STATE_HOOK_DISCONNECT) blade_connection_disconnect(bc);
|
||||
else if (hook == BLADE_CONNECTION_STATE_HOOK_SUCCESS) {
|
||||
// @todo this is adding a second lock, since we keep it locked in the callback to allow finishing, we don't want get locking here...
|
||||
// or just try unlocking twice to confirm...
|
||||
blade_session_t *bs = blade_handle_sessions_get(bc->handle, bc->session);
|
||||
// or just unlock twice...
|
||||
blade_session_t *bs = blade_handle_sessions_lookup(bc->handle, bc->session);
|
||||
ks_assert(bs); // should not happen because bs should still be locked
|
||||
|
||||
blade_session_connections_add(bs, bc->id);
|
||||
blade_session_connection_set(bs, bc->id);
|
||||
|
||||
blade_connection_state_set(bc, BLADE_CONNECTION_STATE_READY);
|
||||
blade_session_state_set(bs, BLADE_SESSION_STATE_READY); // @todo only set this if it's not already in the READY state from prior connection
|
||||
blade_connection_state_set(bc, BLADE_CONNECTION_STATE_RUN);
|
||||
blade_session_state_set(bs, BLADE_SESSION_STATE_STARTUP); // if reconnecting, we go from RUN back to STARTUP for the purpose of the reconnect which will return to RUN
|
||||
|
||||
blade_session_read_unlock(bs); // unlock the session we locked obtaining it above
|
||||
blade_session_read_unlock(bs); // unlock the session we expect to be locked during the callback to ensure we can finish attaching
|
||||
|
@ -490,29 +416,30 @@ ks_status_t blade_connection_state_on_attach(blade_connection_t *bc)
|
|||
return KS_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
ks_status_t blade_connection_state_on_detach(blade_connection_t *bc)
|
||||
ks_status_t blade_connection_onstate_shutdown(blade_connection_t *bc)
|
||||
{
|
||||
blade_transport_state_callback_t callback = NULL;
|
||||
|
||||
ks_assert(bc);
|
||||
|
||||
callback = blade_connection_state_callback_lookup(bc, BLADE_CONNECTION_STATE_DETACH);
|
||||
callback = blade_connection_state_callback_lookup(bc, BLADE_CONNECTION_STATE_SHUTDOWN);
|
||||
if (callback) callback(bc, BLADE_CONNECTION_STATE_CONDITION_POST);
|
||||
|
||||
if (bc->session) {
|
||||
blade_session_t *bs = blade_handle_sessions_get(bc->handle, bc->session);
|
||||
blade_session_t *bs = blade_handle_sessions_lookup(bc->handle, bc->session);
|
||||
ks_assert(bs);
|
||||
|
||||
blade_session_connections_remove(bs, bc->id);
|
||||
blade_session_connection_set(bs, NULL);
|
||||
blade_session_read_unlock(bs);
|
||||
// keep bc->session for later in case something triggers a reconnect later and needs the old session id for a hint
|
||||
}
|
||||
blade_connection_state_set(bc, BLADE_CONNECTION_STATE_DISCONNECT);
|
||||
|
||||
blade_connection_state_set(bc, BLADE_CONNECTION_STATE_CLEANUP);
|
||||
|
||||
return KS_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
ks_status_t blade_connection_state_on_ready(blade_connection_t *bc)
|
||||
ks_status_t blade_connection_onstate_run(blade_connection_t *bc)
|
||||
{
|
||||
blade_transport_state_callback_t callback = NULL;
|
||||
blade_connection_state_hook_t hook = BLADE_CONNECTION_STATE_HOOK_SUCCESS;
|
||||
|
@ -540,7 +467,7 @@ ks_status_t blade_connection_state_on_ready(blade_connection_t *bc)
|
|||
|
||||
if (!(done = (json == NULL))) {
|
||||
if (!bs) {
|
||||
bs = blade_handle_sessions_get(bc->handle, bc->session);
|
||||
bs = blade_handle_sessions_lookup(bc->handle, bc->session);
|
||||
ks_assert(bs);
|
||||
}
|
||||
blade_session_receiving_push(bs, json);
|
||||
|
@ -550,7 +477,7 @@ ks_status_t blade_connection_state_on_ready(blade_connection_t *bc)
|
|||
}
|
||||
if (bs) blade_session_read_unlock(bs);
|
||||
|
||||
callback = blade_connection_state_callback_lookup(bc, BLADE_CONNECTION_STATE_READY);
|
||||
callback = blade_connection_state_callback_lookup(bc, BLADE_CONNECTION_STATE_RUN);
|
||||
if (callback) hook = callback(bc, BLADE_CONNECTION_STATE_CONDITION_POST);
|
||||
|
||||
if (hook == BLADE_CONNECTION_STATE_HOOK_DISCONNECT) blade_connection_disconnect(bc);
|
||||
|
|
|
@ -1,250 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2007-2014, Anthony Minessale II
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* * Neither the name of the original author; nor the names of any contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
|
||||
* OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include "blade.h"
|
||||
|
||||
|
||||
struct blade_datastore_s {
|
||||
ks_pool_t *pool;
|
||||
ks_thread_pool_t *tpool;
|
||||
|
||||
const char *config_database_path;
|
||||
|
||||
unqlite *db;
|
||||
};
|
||||
|
||||
struct blade_datastore_fetch_userdata_s
|
||||
{
|
||||
blade_datastore_t *bds;
|
||||
blade_datastore_fetch_callback_t callback;
|
||||
void *userdata;
|
||||
};
|
||||
typedef struct blade_datastore_fetch_userdata_s blade_datastore_fetch_userdata_t;
|
||||
|
||||
|
||||
|
||||
KS_DECLARE(ks_status_t) blade_datastore_destroy(blade_datastore_t **bdsP)
|
||||
{
|
||||
blade_datastore_t *bds = NULL;
|
||||
|
||||
ks_assert(bdsP);
|
||||
|
||||
bds = *bdsP;
|
||||
*bdsP = NULL;
|
||||
|
||||
ks_assert(bds);
|
||||
|
||||
blade_datastore_shutdown(bds);
|
||||
|
||||
ks_pool_free(bds->pool, &bds);
|
||||
|
||||
return KS_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
KS_DECLARE(ks_status_t) blade_datastore_create(blade_datastore_t **bdsP, ks_pool_t *pool, ks_thread_pool_t *tpool)
|
||||
{
|
||||
blade_datastore_t *bds = NULL;
|
||||
|
||||
ks_assert(bdsP);
|
||||
ks_assert(pool);
|
||||
//ks_assert(tpool);
|
||||
|
||||
bds = ks_pool_alloc(pool, sizeof(*bds));
|
||||
bds->pool = pool;
|
||||
bds->tpool = tpool;
|
||||
*bdsP = bds;
|
||||
|
||||
return KS_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
ks_status_t blade_datastore_config(blade_datastore_t *bds, config_setting_t *config)
|
||||
{
|
||||
config_setting_t *tmp;
|
||||
config_setting_t *database = NULL;
|
||||
const char *config_database_path = NULL;
|
||||
|
||||
ks_assert(bds);
|
||||
|
||||
if (!config) return KS_STATUS_FAIL;
|
||||
if (!config_setting_is_group(config)) return KS_STATUS_FAIL;
|
||||
|
||||
database = config_setting_get_member(config, "database");
|
||||
if (!database) return KS_STATUS_FAIL;
|
||||
tmp = config_lookup_from(database, "path");
|
||||
if (!tmp) return KS_STATUS_FAIL;
|
||||
if (config_setting_type(tmp) != CONFIG_TYPE_STRING) return KS_STATUS_FAIL;
|
||||
config_database_path = config_setting_get_string(tmp);
|
||||
|
||||
if (bds->config_database_path) ks_pool_free(bds->pool, &bds->config_database_path);
|
||||
bds->config_database_path = ks_pstrdup(bds->pool, config_database_path);
|
||||
|
||||
return KS_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
KS_DECLARE(ks_status_t) blade_datastore_startup(blade_datastore_t *bds, config_setting_t *config)
|
||||
{
|
||||
ks_assert(bds);
|
||||
|
||||
// @todo check if already started
|
||||
|
||||
if (blade_datastore_config(bds, config) != KS_STATUS_SUCCESS) return KS_STATUS_FAIL;
|
||||
|
||||
if (unqlite_open(&bds->db, bds->config_database_path, UNQLITE_OPEN_CREATE) != UNQLITE_OK) {
|
||||
const char *errbuf = NULL;
|
||||
blade_datastore_error(bds, &errbuf, NULL);
|
||||
ks_log(KS_LOG_ERROR, "BDS Open Error: %s\n", errbuf);
|
||||
return KS_STATUS_FAIL;
|
||||
}
|
||||
|
||||
// @todo unqlite_lib_config(UNQLITE_LIB_CONFIG_MEM_ERR_CALLBACK)
|
||||
|
||||
// @todo VM init if document store is used (and output consumer callback)
|
||||
|
||||
return KS_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
KS_DECLARE(ks_status_t) blade_datastore_shutdown(blade_datastore_t *bds)
|
||||
{
|
||||
ks_assert(bds);
|
||||
|
||||
if (bds->db) {
|
||||
unqlite_close(bds->db);
|
||||
bds->db = NULL;
|
||||
}
|
||||
|
||||
if (bds->config_database_path) ks_pool_free(bds->pool, &bds->config_database_path);
|
||||
|
||||
return KS_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
KS_DECLARE(void) blade_datastore_error(blade_datastore_t *bds, const char **buffer, int32_t *buffer_length)
|
||||
{
|
||||
ks_assert(bds);
|
||||
ks_assert(bds->db);
|
||||
ks_assert(buffer);
|
||||
|
||||
unqlite_config(bds->db, UNQLITE_CONFIG_ERR_LOG, buffer, buffer_length);
|
||||
}
|
||||
|
||||
KS_DECLARE(ks_status_t) blade_datastore_store(blade_datastore_t *bds, const void *key, int32_t key_length, const void *data, int64_t data_length)
|
||||
{
|
||||
int32_t rc;
|
||||
ks_status_t ret = KS_STATUS_SUCCESS;
|
||||
|
||||
ks_assert(bds);
|
||||
ks_assert(bds->db);
|
||||
ks_assert(key);
|
||||
ks_assert(key_length > 0);
|
||||
ks_assert(data);
|
||||
ks_assert(data_length > 0);
|
||||
|
||||
rc = unqlite_begin(bds->db);
|
||||
|
||||
if (rc != UNQLITE_OK) {
|
||||
if (rc == UNQLITE_BUSY) ret = KS_STATUS_TIMEOUT;
|
||||
else {
|
||||
const char *errbuf;
|
||||
blade_datastore_error(bds, &errbuf, NULL);
|
||||
ks_log(KS_LOG_ERROR, "BDS Store Error: %s\n", errbuf);
|
||||
|
||||
ret = KS_STATUS_FAIL;
|
||||
}
|
||||
} else if (unqlite_kv_store(bds->db, key, key_length, data, data_length) == UNQLITE_OK) unqlite_commit(bds->db);
|
||||
else unqlite_rollback(bds->db);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
int blade_datastore_fetch_callback(const void *data, unsigned int data_length, void *userdata)
|
||||
{
|
||||
int rc = UNQLITE_OK;
|
||||
blade_datastore_fetch_userdata_t *ud = NULL;
|
||||
|
||||
ks_assert(data);
|
||||
ks_assert(data_length > 0);
|
||||
ks_assert(userdata);
|
||||
|
||||
ud = (blade_datastore_fetch_userdata_t *)userdata;
|
||||
if (!ud->callback(ud->bds, data, data_length, ud->userdata)) rc = UNQLITE_ABORT;
|
||||
|
||||
return rc;
|
||||
}
|
||||
|
||||
KS_DECLARE(ks_status_t) blade_datastore_fetch(blade_datastore_t *bds,
|
||||
blade_datastore_fetch_callback_t callback,
|
||||
const void *key,
|
||||
int32_t key_length,
|
||||
void *userdata)
|
||||
{
|
||||
int32_t rc;
|
||||
ks_status_t ret = KS_STATUS_SUCCESS;
|
||||
blade_datastore_fetch_userdata_t ud;
|
||||
|
||||
ks_assert(bds);
|
||||
ks_assert(bds->db);
|
||||
ks_assert(callback);
|
||||
ks_assert(key);
|
||||
ks_assert(key_length > 0);
|
||||
|
||||
ud.bds = bds;
|
||||
ud.callback = callback;
|
||||
ud.userdata = userdata;
|
||||
|
||||
rc = unqlite_kv_fetch_callback(bds->db, key, key_length, blade_datastore_fetch_callback, &ud);
|
||||
|
||||
if (rc != UNQLITE_OK) {
|
||||
if (rc == UNQLITE_BUSY) ret = KS_STATUS_TIMEOUT;
|
||||
else if(rc == UNQLITE_NOTFOUND) ret = KS_STATUS_NOT_FOUND;
|
||||
else {
|
||||
const char *errbuf;
|
||||
blade_datastore_error(bds, &errbuf, NULL);
|
||||
ks_log(KS_LOG_ERROR, "BDS Fetch Error: %s\n", errbuf);
|
||||
|
||||
ret = KS_STATUS_FAIL;
|
||||
}
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
/* For Emacs:
|
||||
* Local Variables:
|
||||
* mode:c
|
||||
* indent-tabs-mode:t
|
||||
* tab-width:4
|
||||
* c-basic-offset:4
|
||||
* End:
|
||||
* For VIM:
|
||||
* vim:set softtabstop=4 shiftwidth=4 tabstop=4 noet:
|
||||
*/
|
|
@ -0,0 +1,396 @@
|
|||
/*
|
||||
* Copyright (c) 2017, Shane Bryldt
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* * Neither the name of the original author; nor the names of any contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
|
||||
* OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include "blade.h"
|
||||
|
||||
struct blade_jsonrpc_s {
|
||||
blade_handle_t *handle;
|
||||
ks_pool_t *pool;
|
||||
|
||||
const char *method;
|
||||
|
||||
blade_jsonrpc_request_callback_t callback;
|
||||
void *callback_data;
|
||||
};
|
||||
|
||||
struct blade_jsonrpc_request_s {
|
||||
blade_handle_t *handle;
|
||||
ks_pool_t *pool;
|
||||
|
||||
const char *session_id;
|
||||
|
||||
cJSON *message;
|
||||
const char *message_id; // pulled from message for easier keying
|
||||
blade_jsonrpc_response_callback_t callback;
|
||||
// @todo ttl to wait for response before injecting an error response locally
|
||||
};
|
||||
|
||||
struct blade_jsonrpc_response_s {
|
||||
blade_handle_t *handle;
|
||||
ks_pool_t *pool;
|
||||
|
||||
const char *session_id;
|
||||
|
||||
blade_jsonrpc_request_t *request;
|
||||
|
||||
cJSON *message;
|
||||
};
|
||||
|
||||
|
||||
static void blade_jsonrpc_cleanup(ks_pool_t *pool, void *ptr, void *arg, ks_pool_cleanup_action_t action, ks_pool_cleanup_type_t type)
|
||||
{
|
||||
//blade_jsonrpc_t *bjsonrpc = (blade_jsonrpc_t *)ptr;
|
||||
|
||||
//ks_assert(bjsonrpc);
|
||||
|
||||
switch (action) {
|
||||
case KS_MPCL_ANNOUNCE:
|
||||
break;
|
||||
case KS_MPCL_TEARDOWN:
|
||||
break;
|
||||
case KS_MPCL_DESTROY:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
KS_DECLARE(ks_status_t) blade_jsonrpc_create(blade_jsonrpc_t **bjsonrpcP, blade_handle_t *bh, const char *method, blade_jsonrpc_request_callback_t callback, void *callback_data)
|
||||
{
|
||||
blade_jsonrpc_t *bjsonrpc = NULL;
|
||||
ks_pool_t *pool = NULL;
|
||||
|
||||
ks_assert(bjsonrpcP);
|
||||
ks_assert(bh);
|
||||
ks_assert(method);
|
||||
ks_assert(callback);
|
||||
|
||||
ks_pool_open(&pool);
|
||||
ks_assert(pool);
|
||||
|
||||
bjsonrpc = ks_pool_alloc(pool, sizeof(blade_jsonrpc_t));
|
||||
bjsonrpc->handle = bh;
|
||||
bjsonrpc->pool = pool;
|
||||
bjsonrpc->method = ks_pstrdup(pool, method);
|
||||
bjsonrpc->callback = callback;
|
||||
bjsonrpc->callback_data = callback_data;
|
||||
|
||||
ks_pool_set_cleanup(pool, bjsonrpc, NULL, blade_jsonrpc_cleanup);
|
||||
|
||||
*bjsonrpcP = bjsonrpc;
|
||||
|
||||
return KS_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
KS_DECLARE(ks_status_t) blade_jsonrpc_destroy(blade_jsonrpc_t **bjsonrpcP)
|
||||
{
|
||||
blade_jsonrpc_t *bjsonrpc = NULL;
|
||||
ks_pool_t *pool = NULL;
|
||||
|
||||
ks_assert(bjsonrpcP);
|
||||
ks_assert(*bjsonrpcP);
|
||||
|
||||
bjsonrpc = *bjsonrpcP;
|
||||
|
||||
pool = bjsonrpc->pool;
|
||||
|
||||
ks_pool_close(&pool);
|
||||
|
||||
*bjsonrpcP = NULL;
|
||||
|
||||
return KS_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
KS_DECLARE(blade_handle_t *) blade_jsonrpc_handle_get(blade_jsonrpc_t *bjsonrpc)
|
||||
{
|
||||
ks_assert(bjsonrpc);
|
||||
|
||||
return bjsonrpc->handle;
|
||||
}
|
||||
|
||||
KS_DECLARE(const char *) blade_jsonrpc_method_get(blade_jsonrpc_t *bjsonrpc)
|
||||
{
|
||||
ks_assert(bjsonrpc);
|
||||
|
||||
return bjsonrpc->method;
|
||||
}
|
||||
|
||||
KS_DECLARE(blade_jsonrpc_request_callback_t) blade_jsonrpc_callback_get(blade_jsonrpc_t *bjsonrpc)
|
||||
{
|
||||
ks_assert(bjsonrpc);
|
||||
|
||||
return bjsonrpc->callback;
|
||||
}
|
||||
|
||||
KS_DECLARE(void *) blade_jsonrpc_callback_data_get(blade_jsonrpc_t *bjsonrpc)
|
||||
{
|
||||
ks_assert(bjsonrpc);
|
||||
|
||||
return bjsonrpc->callback_data;
|
||||
}
|
||||
|
||||
|
||||
static void blade_jsonrpc_request_cleanup(ks_pool_t *pool, void *ptr, void *arg, ks_pool_cleanup_action_t action, ks_pool_cleanup_type_t type)
|
||||
{
|
||||
blade_jsonrpc_request_t *bjsonrpcreq = (blade_jsonrpc_request_t *)ptr;
|
||||
|
||||
ks_assert(bjsonrpcreq);
|
||||
|
||||
switch (action) {
|
||||
case KS_MPCL_ANNOUNCE:
|
||||
break;
|
||||
case KS_MPCL_TEARDOWN:
|
||||
ks_pool_free(bjsonrpcreq->pool, (void **)&bjsonrpcreq->session_id);
|
||||
cJSON_Delete(bjsonrpcreq->message);
|
||||
break;
|
||||
case KS_MPCL_DESTROY:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
KS_DECLARE(ks_status_t) blade_jsonrpc_request_create(blade_jsonrpc_request_t **bjsonrpcreqP,
|
||||
blade_handle_t *bh,
|
||||
ks_pool_t *pool,
|
||||
const char *session_id,
|
||||
cJSON *json,
|
||||
blade_jsonrpc_response_callback_t callback)
|
||||
{
|
||||
blade_jsonrpc_request_t *bjsonrpcreq = NULL;
|
||||
|
||||
ks_assert(bjsonrpcreqP);
|
||||
ks_assert(bh);
|
||||
ks_assert(pool);
|
||||
ks_assert(session_id);
|
||||
ks_assert(json);
|
||||
|
||||
bjsonrpcreq = ks_pool_alloc(pool, sizeof(blade_jsonrpc_request_t));
|
||||
bjsonrpcreq->handle = bh;
|
||||
bjsonrpcreq->pool = pool;
|
||||
bjsonrpcreq->session_id = ks_pstrdup(pool, session_id);
|
||||
bjsonrpcreq->message = cJSON_Duplicate(json, 1);
|
||||
bjsonrpcreq->message_id = cJSON_GetObjectCstr(bjsonrpcreq->message, "id");
|
||||
bjsonrpcreq->callback = callback;
|
||||
|
||||
ks_pool_set_cleanup(pool, bjsonrpcreq, NULL, blade_jsonrpc_request_cleanup);
|
||||
|
||||
*bjsonrpcreqP = bjsonrpcreq;
|
||||
|
||||
return KS_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
KS_DECLARE(ks_status_t) blade_jsonrpc_request_destroy(blade_jsonrpc_request_t **bjsonrpcreqP)
|
||||
{
|
||||
blade_jsonrpc_request_t *bjsonrpcreq = NULL;
|
||||
|
||||
ks_assert(bjsonrpcreqP);
|
||||
ks_assert(*bjsonrpcreqP);
|
||||
|
||||
bjsonrpcreq = *bjsonrpcreqP;
|
||||
|
||||
ks_pool_free(bjsonrpcreq->pool, bjsonrpcreqP);
|
||||
|
||||
return KS_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
KS_DECLARE(blade_handle_t *) blade_jsonrpc_request_handle_get(blade_jsonrpc_request_t *bjsonrpcreq)
|
||||
{
|
||||
ks_assert(bjsonrpcreq);
|
||||
return bjsonrpcreq->handle;
|
||||
}
|
||||
|
||||
KS_DECLARE(const char *) blade_jsonrpc_request_messageid_get(blade_jsonrpc_request_t *bjsonrpcreq)
|
||||
{
|
||||
ks_assert(bjsonrpcreq);
|
||||
return bjsonrpcreq->message_id;
|
||||
}
|
||||
|
||||
KS_DECLARE(blade_jsonrpc_response_callback_t) blade_jsonrpc_request_callback_get(blade_jsonrpc_request_t *bjsonrpcreq)
|
||||
{
|
||||
ks_assert(bjsonrpcreq);
|
||||
return bjsonrpcreq->callback;
|
||||
}
|
||||
|
||||
KS_DECLARE(ks_status_t) blade_jsonrpc_request_raw_create(ks_pool_t *pool, cJSON **json, cJSON **params, const char **id, const char *method)
|
||||
{
|
||||
cJSON *root = NULL;
|
||||
cJSON *p = NULL;
|
||||
uuid_t msgid;
|
||||
const char *mid = NULL;
|
||||
|
||||
ks_assert(pool);
|
||||
ks_assert(json);
|
||||
ks_assert(method);
|
||||
|
||||
root = cJSON_CreateObject();
|
||||
|
||||
cJSON_AddStringToObject(root, "jsonrpc", "2.0");
|
||||
|
||||
ks_uuid(&msgid);
|
||||
mid = ks_uuid_str(pool, &msgid);
|
||||
cJSON_AddStringToObject(root, "id", mid);
|
||||
ks_pool_free(pool, &mid);
|
||||
|
||||
cJSON_AddStringToObject(root, "method", method);
|
||||
|
||||
p = cJSON_CreateObject();
|
||||
cJSON_AddItemToObject(root, "params", p);
|
||||
|
||||
*json = root;
|
||||
if (params) *params = p;
|
||||
if (id) *id = cJSON_GetObjectCstr(root, "id");
|
||||
|
||||
return KS_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
static void blade_jsonrpc_response_cleanup(ks_pool_t *pool, void *ptr, void *arg, ks_pool_cleanup_action_t action, ks_pool_cleanup_type_t type)
|
||||
{
|
||||
blade_jsonrpc_response_t *bjsonrpcres = (blade_jsonrpc_response_t *)ptr;
|
||||
|
||||
ks_assert(bjsonrpcres);
|
||||
|
||||
switch (action) {
|
||||
case KS_MPCL_ANNOUNCE:
|
||||
break;
|
||||
case KS_MPCL_TEARDOWN:
|
||||
ks_pool_free(bjsonrpcres->pool, (void **)&bjsonrpcres->session_id);
|
||||
blade_jsonrpc_request_destroy(&bjsonrpcres->request);
|
||||
cJSON_Delete(bjsonrpcres->message);
|
||||
break;
|
||||
case KS_MPCL_DESTROY:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
KS_DECLARE(ks_status_t) blade_jsonrpc_response_create(blade_jsonrpc_response_t **bjsonrpcresP,
|
||||
blade_handle_t *bh,
|
||||
ks_pool_t *pool,
|
||||
const char *session_id,
|
||||
blade_jsonrpc_request_t *bjsonrpcreq,
|
||||
cJSON *json)
|
||||
{
|
||||
blade_jsonrpc_response_t *bjsonrpcres = NULL;
|
||||
|
||||
ks_assert(bjsonrpcresP);
|
||||
ks_assert(bh);
|
||||
ks_assert(pool);
|
||||
ks_assert(session_id);
|
||||
ks_assert(bjsonrpcreq);
|
||||
ks_assert(json);
|
||||
|
||||
bjsonrpcres = ks_pool_alloc(pool, sizeof(blade_jsonrpc_response_t));
|
||||
bjsonrpcres->handle = bh;
|
||||
bjsonrpcres->pool = pool;
|
||||
bjsonrpcres->session_id = ks_pstrdup(pool, session_id);
|
||||
bjsonrpcres->request = bjsonrpcreq;
|
||||
bjsonrpcres->message = cJSON_Duplicate(json, 1);
|
||||
|
||||
ks_pool_set_cleanup(pool, bjsonrpcres, NULL, blade_jsonrpc_response_cleanup);
|
||||
|
||||
*bjsonrpcresP = bjsonrpcres;
|
||||
|
||||
return KS_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
KS_DECLARE(ks_status_t) blade_jsonrpc_response_destroy(blade_jsonrpc_response_t **bjsonrpcresP)
|
||||
{
|
||||
blade_jsonrpc_response_t *bjsonrpcres = NULL;
|
||||
|
||||
ks_assert(bjsonrpcresP);
|
||||
ks_assert(*bjsonrpcresP);
|
||||
|
||||
bjsonrpcres = *bjsonrpcresP;
|
||||
|
||||
ks_pool_free(bjsonrpcres->pool, bjsonrpcresP);
|
||||
|
||||
return KS_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
KS_DECLARE(ks_status_t) blade_jsonrpc_response_raw_create(cJSON **json, cJSON **result, const char *id)
|
||||
{
|
||||
cJSON *root = NULL;
|
||||
cJSON *r = NULL;
|
||||
|
||||
ks_assert(json);
|
||||
ks_assert(id);
|
||||
|
||||
root = cJSON_CreateObject();
|
||||
|
||||
cJSON_AddStringToObject(root, "jsonrpc", "2.0");
|
||||
|
||||
cJSON_AddStringToObject(root, "id", id);
|
||||
|
||||
r = cJSON_CreateObject();
|
||||
cJSON_AddItemToObject(root, "result", r);
|
||||
|
||||
*json = root;
|
||||
if (result) *result = r;
|
||||
|
||||
return KS_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
KS_DECLARE(ks_status_t) blade_jsonrpc_error_raw_create(cJSON **json, cJSON **error, const char *id, int32_t code, const char *message)
|
||||
{
|
||||
cJSON *root = NULL;
|
||||
cJSON *e = NULL;
|
||||
|
||||
ks_assert(json);
|
||||
//ks_assert(id);
|
||||
ks_assert(message);
|
||||
|
||||
root = cJSON_CreateObject();
|
||||
|
||||
cJSON_AddStringToObject(root, "jsonrpc", "2.0");
|
||||
|
||||
if (id) cJSON_AddStringToObject(root, "id", id);
|
||||
|
||||
e = cJSON_CreateObject();
|
||||
cJSON_AddNumberToObject(e, "code", code);
|
||||
cJSON_AddStringToObject(e, "message", message);
|
||||
cJSON_AddItemToObject(root, "error", e);
|
||||
|
||||
*json = root;
|
||||
if (error) *error = e;
|
||||
|
||||
return KS_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
/* For Emacs:
|
||||
* Local Variables:
|
||||
* mode:c
|
||||
* indent-tabs-mode:t
|
||||
* tab-width:4
|
||||
* c-basic-offset:4
|
||||
* End:
|
||||
* For VIM:
|
||||
* vim:set softtabstop=4 shiftwidth=4 tabstop=4 noet:
|
||||
*/
|
|
@ -1,153 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2017, Shane Bryldt
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* * Neither the name of the original author; nor the names of any contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
|
||||
* OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include "blade.h"
|
||||
|
||||
struct blade_module_s {
|
||||
blade_handle_t *handle;
|
||||
ks_pool_t *pool;
|
||||
const char *id;
|
||||
|
||||
void *module_data;
|
||||
blade_module_callbacks_t *module_callbacks;
|
||||
};
|
||||
|
||||
static void blade_module_cleanup(ks_pool_t *pool, void *ptr, void *arg, ks_pool_cleanup_action_t action, ks_pool_cleanup_type_t type)
|
||||
{
|
||||
//blade_module_t *bm = (blade_module_t *)ptr;
|
||||
|
||||
//ks_assert(bm);
|
||||
|
||||
switch (action) {
|
||||
case KS_MPCL_ANNOUNCE:
|
||||
break;
|
||||
case KS_MPCL_TEARDOWN:
|
||||
break;
|
||||
case KS_MPCL_DESTROY:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
KS_DECLARE(ks_status_t) blade_module_create(blade_module_t **bmP, blade_handle_t *bh, ks_pool_t *pool, void *module_data, blade_module_callbacks_t *module_callbacks)
|
||||
{
|
||||
blade_module_t *bm = NULL;
|
||||
uuid_t uuid;
|
||||
|
||||
ks_assert(bmP);
|
||||
ks_assert(bh);
|
||||
ks_assert(pool);
|
||||
ks_assert(module_data);
|
||||
ks_assert(module_callbacks);
|
||||
|
||||
ks_uuid(&uuid);
|
||||
|
||||
bm = ks_pool_alloc(pool, sizeof(blade_module_t));
|
||||
bm->handle = bh;
|
||||
bm->pool = pool;
|
||||
bm->id = ks_uuid_str(pool, &uuid);
|
||||
bm->module_data = module_data;
|
||||
bm->module_callbacks = module_callbacks;
|
||||
|
||||
ks_pool_set_cleanup(pool, bm, NULL, blade_module_cleanup);
|
||||
|
||||
ks_log(KS_LOG_DEBUG, "Created\n");
|
||||
|
||||
*bmP = bm;
|
||||
|
||||
return KS_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
KS_DECLARE(ks_status_t) blade_module_destroy(blade_module_t **bmP)
|
||||
{
|
||||
blade_module_t *bm = NULL;
|
||||
ks_pool_t *pool = NULL;
|
||||
|
||||
ks_assert(bmP);
|
||||
ks_assert(*bmP);
|
||||
|
||||
bm = *bmP;
|
||||
|
||||
pool = bm->pool;
|
||||
//ks_pool_free(bm->pool, bmP);
|
||||
ks_pool_close(&pool);
|
||||
|
||||
*bmP = NULL;
|
||||
|
||||
return KS_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
KS_DECLARE(blade_handle_t *) blade_module_handle_get(blade_module_t *bm)
|
||||
{
|
||||
ks_assert(bm);
|
||||
|
||||
return bm->handle;
|
||||
}
|
||||
|
||||
KS_DECLARE(ks_pool_t *) blade_module_pool_get(blade_module_t *bm)
|
||||
{
|
||||
ks_assert(bm);
|
||||
|
||||
return bm->pool;
|
||||
}
|
||||
|
||||
KS_DECLARE(const char *) blade_module_id_get(blade_module_t *bm)
|
||||
{
|
||||
ks_assert(bm);
|
||||
|
||||
return bm->id;
|
||||
}
|
||||
|
||||
KS_DECLARE(void *) blade_module_data_get(blade_module_t *bm)
|
||||
{
|
||||
ks_assert(bm);
|
||||
|
||||
return bm->module_data;
|
||||
}
|
||||
|
||||
KS_DECLARE(blade_module_callbacks_t *) blade_module_callbacks_get(blade_module_t *bm)
|
||||
{
|
||||
ks_assert(bm);
|
||||
|
||||
return bm->module_callbacks;
|
||||
}
|
||||
|
||||
/* For Emacs:
|
||||
* Local Variables:
|
||||
* mode:c
|
||||
* indent-tabs-mode:t
|
||||
* tab-width:4
|
||||
* c-basic-offset:4
|
||||
* End:
|
||||
* For VIM:
|
||||
* vim:set softtabstop=4 shiftwidth=4 tabstop=4 noet:
|
||||
*/
|
|
@ -0,0 +1,274 @@
|
|||
/*
|
||||
* Copyright (c) 2017, Shane Bryldt
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* * Neither the name of the original author; nor the names of any contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
|
||||
* OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include "blade.h"
|
||||
|
||||
typedef struct blade_module_master_s blade_module_master_t;
|
||||
|
||||
struct blade_module_master_s {
|
||||
blade_handle_t *handle;
|
||||
ks_pool_t *pool;
|
||||
blade_module_t *module;
|
||||
|
||||
blade_space_t *blade_space;
|
||||
blade_space_t *blade_application_space;
|
||||
};
|
||||
|
||||
|
||||
ks_bool_t blade_register_request_handler(blade_module_t *bm, blade_request_t *breq);
|
||||
// @todo blade_unregister_request_handler for more graceful shutdowns which intend to disconnect, and won't reconnect, which expire a session immediately
|
||||
ks_bool_t blade_application_register_request_handler(blade_module_t *bm, blade_request_t *breq); // @todo response of registration indicates if you are the primary, or a slave
|
||||
// @todo blade_application_unregister_request_handler for ability to unregister a slave (or primary) from the application, upon last node unregistering, the application entry would be automatically destroyed
|
||||
// @todo event (or request to confirm acceptance with a response?) that allows a master to tell a slave it's the new primary for an application it has registered to provide when a primary disconnects, or a
|
||||
// primary change is requested externally
|
||||
// @todo to avoid a race condition, if a slave gets unexpected primary calls before being notified by an event, should it assume it has become the primary and not yet notified?
|
||||
|
||||
static blade_module_callbacks_t g_module_master_callbacks =
|
||||
{
|
||||
blade_module_master_on_startup,
|
||||
blade_module_master_on_shutdown,
|
||||
};
|
||||
|
||||
|
||||
static void blade_module_master_cleanup(ks_pool_t *pool, void *ptr, void *arg, ks_pool_cleanup_action_t action, ks_pool_cleanup_type_t type)
|
||||
{
|
||||
//blade_module_master_t *bm_master = (blade_module_master_t *)ptr;
|
||||
|
||||
//ks_assert(bm_master);
|
||||
|
||||
switch (action) {
|
||||
case KS_MPCL_ANNOUNCE:
|
||||
break;
|
||||
case KS_MPCL_TEARDOWN:
|
||||
break;
|
||||
case KS_MPCL_DESTROY:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
KS_DECLARE(ks_status_t) blade_module_master_create(blade_module_t **bmP, blade_handle_t *bh)
|
||||
{
|
||||
blade_module_master_t *bm_master = NULL;
|
||||
ks_pool_t *pool = NULL;
|
||||
|
||||
ks_assert(bmP);
|
||||
ks_assert(bh);
|
||||
|
||||
ks_pool_open(&pool);
|
||||
ks_assert(pool);
|
||||
|
||||
bm_master = ks_pool_alloc(pool, sizeof(blade_module_master_t));
|
||||
bm_master->handle = bh;
|
||||
bm_master->pool = pool;
|
||||
|
||||
blade_module_create(&bm_master->module, bh, pool, bm_master, &g_module_master_callbacks);
|
||||
|
||||
ks_pool_set_cleanup(pool, bm_master, NULL, blade_module_master_cleanup);
|
||||
|
||||
ks_log(KS_LOG_DEBUG, "Created\n");
|
||||
|
||||
*bmP = bm_master->module;
|
||||
|
||||
return KS_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
ks_status_t blade_module_master_config(blade_module_master_t *bm_master, config_setting_t *config)
|
||||
{
|
||||
ks_assert(bm_master);
|
||||
ks_assert(config);
|
||||
|
||||
ks_log(KS_LOG_DEBUG, "Configured\n");
|
||||
|
||||
return KS_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
KS_DECLARE(ks_status_t) blade_module_master_on_startup(blade_module_t *bm, config_setting_t *config)
|
||||
{
|
||||
blade_module_master_t *bm_master = NULL;
|
||||
blade_space_t *space = NULL;
|
||||
blade_method_t *method = NULL;
|
||||
|
||||
ks_assert(bm);
|
||||
ks_assert(config);
|
||||
|
||||
bm_master = (blade_module_master_t *)blade_module_data_get(bm);
|
||||
|
||||
if (blade_module_master_config(bm_master, config) != KS_STATUS_SUCCESS) {
|
||||
ks_log(KS_LOG_DEBUG, "blade_module_master_config failed\n");
|
||||
return KS_STATUS_FAIL;
|
||||
}
|
||||
|
||||
blade_space_create(&space, bm_master->handle, bm, "blade");
|
||||
ks_assert(space);
|
||||
|
||||
bm_master->blade_space = space;
|
||||
|
||||
blade_method_create(&method, space, "register", blade_register_request_handler);
|
||||
ks_assert(method);
|
||||
blade_space_methods_add(space, method);
|
||||
|
||||
blade_handle_space_register(space);
|
||||
|
||||
|
||||
blade_space_create(&space, bm_master->handle, bm, "blade.application");
|
||||
ks_assert(space);
|
||||
|
||||
bm_master->blade_application_space = space;
|
||||
|
||||
blade_method_create(&method, space, "register", blade_application_register_request_handler);
|
||||
ks_assert(method);
|
||||
blade_space_methods_add(space, method);
|
||||
|
||||
blade_handle_space_register(space);
|
||||
|
||||
|
||||
ks_log(KS_LOG_DEBUG, "Started\n");
|
||||
|
||||
return KS_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
KS_DECLARE(ks_status_t) blade_module_master_on_shutdown(blade_module_t *bm)
|
||||
{
|
||||
blade_module_master_t *bm_master = NULL;
|
||||
|
||||
ks_assert(bm);
|
||||
|
||||
bm_master = (blade_module_master_t *)blade_module_data_get(bm);
|
||||
|
||||
if (bm_master->blade_application_space) blade_handle_space_unregister(bm_master->blade_application_space);
|
||||
if (bm_master->blade_space) blade_handle_space_unregister(bm_master->blade_space);
|
||||
|
||||
ks_log(KS_LOG_DEBUG, "Stopped\n");
|
||||
|
||||
return KS_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
ks_bool_t blade_register_request_handler(blade_module_t *bm, blade_request_t *breq)
|
||||
{
|
||||
blade_module_master_t *bm_master = NULL;
|
||||
blade_session_t *bs = NULL;
|
||||
cJSON *params = NULL;
|
||||
cJSON *res = NULL;
|
||||
const char *params_identity = NULL;
|
||||
const char *identity = NULL;
|
||||
|
||||
ks_assert(bm);
|
||||
ks_assert(breq);
|
||||
|
||||
ks_log(KS_LOG_DEBUG, "Request Received!\n");
|
||||
|
||||
bm_master = (blade_module_master_t *)blade_module_data_get(bm);
|
||||
ks_assert(bm_master);
|
||||
|
||||
bs = blade_handle_sessions_get(breq->handle, breq->session_id);
|
||||
ks_assert(bs);
|
||||
|
||||
blade_session_properties_write_lock(bs, KS_TRUE);
|
||||
|
||||
params = cJSON_GetObjectItem(breq->message, "params"); // @todo cache this in blade_request_t for quicker/easier access
|
||||
if (!params) {
|
||||
ks_log(KS_LOG_DEBUG, "Session (%s) attempted to register with no 'params' object\n", blade_session_id_get(bs));
|
||||
blade_rpc_error_create(&res, NULL, breq->message_id, -32602, "Missing params object");
|
||||
}
|
||||
else if (!(params_identity = cJSON_GetObjectCstr(params, "identity"))) {
|
||||
ks_log(KS_LOG_DEBUG, "Session (%s) attempted to register with no 'identity'\n", blade_session_id_get(bs));
|
||||
blade_rpc_error_create(&res, NULL, breq->message_id, -32602, "Missing params identity string");
|
||||
} else {
|
||||
identity = blade_session_identity_get(bs);
|
||||
if (identity && identity[0]) {
|
||||
ks_log(KS_LOG_DEBUG, "Session (%s) attempted to register with master but is already registered as %s\n", blade_session_id_get(bs), identity);
|
||||
blade_rpc_error_create(&res, NULL, breq->message_id, -1000, "Already registered");
|
||||
} else {
|
||||
// @todo plug in authentication to confirm if this registration is permitted, just allow it for now as long as it's not already in use
|
||||
|
||||
blade_rpc_response_create(&res, NULL, breq->message_id);
|
||||
|
||||
// @todo this is completely unfinished, return to finish this after catching up other changes
|
||||
//blade_handle_session_identify(bh, identity, bs);
|
||||
//blade_session_identity_set(bs, params_identity);
|
||||
}
|
||||
}
|
||||
|
||||
blade_session_properties_write_unlock(bs);
|
||||
|
||||
blade_session_send(bs, res, NULL);
|
||||
|
||||
blade_session_read_unlock(bs);
|
||||
|
||||
cJSON_Delete(res);
|
||||
|
||||
return KS_FALSE;
|
||||
}
|
||||
|
||||
ks_bool_t blade_application_register_request_handler(blade_module_t *bm, blade_request_t *breq)
|
||||
{
|
||||
blade_module_master_t *bm_master = NULL;
|
||||
blade_session_t *bs = NULL;
|
||||
//cJSON *res = NULL;
|
||||
|
||||
ks_assert(bm);
|
||||
ks_assert(breq);
|
||||
|
||||
ks_log(KS_LOG_DEBUG, "Request Received!\n");
|
||||
|
||||
bm_master = (blade_module_master_t *)blade_module_data_get(bm);
|
||||
ks_assert(bm_master);
|
||||
|
||||
bs = blade_handle_sessions_get(breq->handle, breq->session_id);
|
||||
ks_assert(bs);
|
||||
|
||||
//blade_rpc_error_create(&res, NULL, breq->message_id, -10000, "???");
|
||||
//blade_rpc_response_create(&res, NULL, breq->message_id);
|
||||
|
||||
|
||||
//blade_session_send(bs, res, NULL);
|
||||
|
||||
blade_session_read_unlock(bs);
|
||||
|
||||
//cJSON_Delete(res);
|
||||
|
||||
return KS_FALSE;
|
||||
}
|
||||
|
||||
|
||||
/* For Emacs:
|
||||
* Local Variables:
|
||||
* mode:c
|
||||
* indent-tabs-mode:t
|
||||
* tab-width:4
|
||||
* c-basic-offset:4
|
||||
* End:
|
||||
* For VIM:
|
||||
* vim:set softtabstop=4 shiftwidth=4 tabstop=4 noet:
|
||||
*/
|
File diff suppressed because it is too large
Load Diff
|
@ -1,339 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2017, Shane Bryldt
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* * Neither the name of the original author; nor the names of any contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
|
||||
* OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include "blade.h"
|
||||
|
||||
static void blade_request_cleanup(ks_pool_t *pool, void *ptr, void *arg, ks_pool_cleanup_action_t action, ks_pool_cleanup_type_t type)
|
||||
{
|
||||
blade_request_t *breq = (blade_request_t *)ptr;
|
||||
|
||||
ks_assert(breq);
|
||||
|
||||
switch (action) {
|
||||
case KS_MPCL_ANNOUNCE:
|
||||
break;
|
||||
case KS_MPCL_TEARDOWN:
|
||||
ks_pool_free(breq->pool, (void **)&breq->session_id);
|
||||
cJSON_Delete(breq->message);
|
||||
break;
|
||||
case KS_MPCL_DESTROY:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
KS_DECLARE(ks_status_t) blade_request_create(blade_request_t **breqP,
|
||||
blade_handle_t *bh,
|
||||
ks_pool_t *pool,
|
||||
const char *session_id,
|
||||
cJSON *json,
|
||||
blade_response_callback_t callback)
|
||||
{
|
||||
blade_request_t *breq = NULL;
|
||||
|
||||
ks_assert(breqP);
|
||||
ks_assert(bh);
|
||||
ks_assert(pool);
|
||||
ks_assert(session_id);
|
||||
ks_assert(json);
|
||||
|
||||
breq = ks_pool_alloc(pool, sizeof(blade_request_t));
|
||||
breq->handle = bh;
|
||||
breq->pool = pool;
|
||||
breq->session_id = ks_pstrdup(pool, session_id);
|
||||
breq->message = cJSON_Duplicate(json, 1);
|
||||
breq->message_id = cJSON_GetObjectCstr(breq->message, "id");
|
||||
breq->callback = callback;
|
||||
|
||||
ks_pool_set_cleanup(pool, breq, NULL, blade_request_cleanup);
|
||||
|
||||
*breqP = breq;
|
||||
|
||||
return KS_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
KS_DECLARE(ks_status_t) blade_request_destroy(blade_request_t **breqP)
|
||||
{
|
||||
blade_request_t *breq = NULL;
|
||||
|
||||
ks_assert(breqP);
|
||||
ks_assert(*breqP);
|
||||
|
||||
breq = *breqP;
|
||||
|
||||
ks_pool_free(breq->pool, breqP);
|
||||
|
||||
return KS_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
static void blade_response_cleanup(ks_pool_t *pool, void *ptr, void *arg, ks_pool_cleanup_action_t action, ks_pool_cleanup_type_t type)
|
||||
{
|
||||
blade_response_t *bres = (blade_response_t *)ptr;
|
||||
|
||||
ks_assert(bres);
|
||||
|
||||
switch (action) {
|
||||
case KS_MPCL_ANNOUNCE:
|
||||
break;
|
||||
case KS_MPCL_TEARDOWN:
|
||||
ks_pool_free(bres->pool, (void **)&bres->session_id);
|
||||
blade_request_destroy(&bres->request);
|
||||
cJSON_Delete(bres->message);
|
||||
break;
|
||||
case KS_MPCL_DESTROY:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
KS_DECLARE(ks_status_t) blade_response_create(blade_response_t **bresP,
|
||||
blade_handle_t *bh,
|
||||
ks_pool_t *pool,
|
||||
const char *session_id,
|
||||
blade_request_t *breq,
|
||||
cJSON *json)
|
||||
{
|
||||
blade_response_t *bres = NULL;
|
||||
|
||||
ks_assert(bresP);
|
||||
ks_assert(bh);
|
||||
ks_assert(pool);
|
||||
ks_assert(session_id);
|
||||
ks_assert(breq);
|
||||
ks_assert(json);
|
||||
|
||||
bres = ks_pool_alloc(pool, sizeof(blade_response_t));
|
||||
bres->handle = bh;
|
||||
bres->pool = pool;
|
||||
bres->session_id = ks_pstrdup(pool, session_id);
|
||||
bres->request = breq;
|
||||
bres->message = cJSON_Duplicate(json, 1);
|
||||
|
||||
ks_pool_set_cleanup(pool, bres, NULL, blade_response_cleanup);
|
||||
|
||||
*bresP = bres;
|
||||
|
||||
return KS_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
KS_DECLARE(ks_status_t) blade_response_destroy(blade_response_t **bresP)
|
||||
{
|
||||
blade_response_t *bres = NULL;
|
||||
|
||||
ks_assert(bresP);
|
||||
ks_assert(*bresP);
|
||||
|
||||
bres = *bresP;
|
||||
|
||||
ks_pool_free(bres->pool, bresP);
|
||||
|
||||
return KS_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
static void blade_event_cleanup(ks_pool_t *pool, void *ptr, void *arg, ks_pool_cleanup_action_t action, ks_pool_cleanup_type_t type)
|
||||
{
|
||||
blade_event_t *bev = (blade_event_t *)ptr;
|
||||
|
||||
ks_assert(bev);
|
||||
|
||||
switch (action) {
|
||||
case KS_MPCL_ANNOUNCE:
|
||||
break;
|
||||
case KS_MPCL_TEARDOWN:
|
||||
ks_pool_free(bev->pool, &bev->session_id);
|
||||
cJSON_Delete(bev->message);
|
||||
break;
|
||||
case KS_MPCL_DESTROY:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
KS_DECLARE(ks_status_t) blade_event_create(blade_event_t **bevP,
|
||||
blade_handle_t *bh,
|
||||
ks_pool_t *pool,
|
||||
const char *session_id,
|
||||
cJSON *json)
|
||||
{
|
||||
blade_event_t *bev = NULL;
|
||||
|
||||
ks_assert(bevP);
|
||||
ks_assert(bh);
|
||||
ks_assert(pool);
|
||||
ks_assert(session_id);
|
||||
ks_assert(json);
|
||||
|
||||
bev = ks_pool_alloc(pool, sizeof(blade_event_t));
|
||||
bev->handle = bh;
|
||||
bev->pool = pool;
|
||||
bev->session_id = ks_pstrdup(pool, session_id);
|
||||
bev->message = cJSON_Duplicate(json, 1);
|
||||
|
||||
ks_pool_set_cleanup(pool, bev, NULL, blade_event_cleanup);
|
||||
|
||||
*bevP = bev;
|
||||
|
||||
return KS_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
KS_DECLARE(ks_status_t) blade_event_destroy(blade_event_t **bevP)
|
||||
{
|
||||
blade_event_t *bev = NULL;
|
||||
|
||||
ks_assert(bevP);
|
||||
ks_assert(*bevP);
|
||||
|
||||
bev = *bevP;
|
||||
|
||||
ks_pool_free(bev->pool, bevP);
|
||||
|
||||
return KS_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
KS_DECLARE(ks_status_t) blade_rpc_request_create(ks_pool_t *pool, cJSON **json, cJSON **params, const char **id, const char *method)
|
||||
{
|
||||
cJSON *root = NULL;
|
||||
cJSON *p = NULL;
|
||||
uuid_t msgid;
|
||||
const char *mid = NULL;
|
||||
|
||||
ks_assert(pool);
|
||||
ks_assert(json);
|
||||
ks_assert(method);
|
||||
|
||||
root = cJSON_CreateObject();
|
||||
|
||||
cJSON_AddStringToObject(root, "jsonrpc", "2.0");
|
||||
|
||||
ks_uuid(&msgid);
|
||||
mid = ks_uuid_str(pool, &msgid);
|
||||
cJSON_AddStringToObject(root, "id", mid);
|
||||
ks_pool_free(pool, &mid);
|
||||
|
||||
cJSON_AddStringToObject(root, "method", method);
|
||||
|
||||
p = cJSON_CreateObject();
|
||||
cJSON_AddItemToObject(root, "params", p);
|
||||
|
||||
*json = root;
|
||||
if (params) *params = p;
|
||||
if (id) *id = cJSON_GetObjectCstr(root, "id");
|
||||
|
||||
return KS_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
KS_DECLARE(ks_status_t) blade_rpc_response_create(cJSON **json, cJSON **result, const char *id)
|
||||
{
|
||||
cJSON *root = NULL;
|
||||
cJSON *r = NULL;
|
||||
|
||||
ks_assert(json);
|
||||
ks_assert(id);
|
||||
|
||||
root = cJSON_CreateObject();
|
||||
|
||||
cJSON_AddStringToObject(root, "jsonrpc", "2.0");
|
||||
|
||||
cJSON_AddStringToObject(root, "id", id);
|
||||
|
||||
r = cJSON_CreateObject();
|
||||
cJSON_AddItemToObject(root, "result", r);
|
||||
|
||||
*json = root;
|
||||
if (result) *result = r;
|
||||
|
||||
return KS_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
KS_DECLARE(ks_status_t) blade_rpc_error_create(cJSON **json, cJSON **error, const char *id, int32_t code, const char *message)
|
||||
{
|
||||
cJSON *root = NULL;
|
||||
cJSON *e = NULL;
|
||||
|
||||
ks_assert(json);
|
||||
//ks_assert(id);
|
||||
ks_assert(message);
|
||||
|
||||
root = cJSON_CreateObject();
|
||||
|
||||
cJSON_AddStringToObject(root, "jsonrpc", "2.0");
|
||||
|
||||
if (id) cJSON_AddStringToObject(root, "id", id);
|
||||
|
||||
e = cJSON_CreateObject();
|
||||
cJSON_AddNumberToObject(e, "code", code);
|
||||
cJSON_AddStringToObject(e, "message", message);
|
||||
cJSON_AddItemToObject(root, "error", e);
|
||||
|
||||
*json = root;
|
||||
if (error) *error = e;
|
||||
|
||||
return KS_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
KS_DECLARE(ks_status_t) blade_rpc_event_create(cJSON **json, cJSON **result, const char *event)
|
||||
{
|
||||
cJSON *root = NULL;
|
||||
cJSON *b = NULL;
|
||||
cJSON *r = NULL;
|
||||
|
||||
ks_assert(json);
|
||||
ks_assert(event);
|
||||
|
||||
root = cJSON_CreateObject();
|
||||
|
||||
cJSON_AddStringToObject(root, "jsonrpc", "2.0");
|
||||
|
||||
b = cJSON_CreateObject();
|
||||
cJSON_AddStringToObject(b, "event", event);
|
||||
cJSON_AddItemToObject(root, "blade", b);
|
||||
|
||||
if (result) {
|
||||
r = cJSON_CreateObject();
|
||||
cJSON_AddItemToObject(root, "result", r);
|
||||
*result = r;
|
||||
}
|
||||
|
||||
*json = root;
|
||||
|
||||
return KS_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
/* For Emacs:
|
||||
* Local Variables:
|
||||
* mode:c
|
||||
* indent-tabs-mode:t
|
||||
* tab-width:4
|
||||
* c-basic-offset:4
|
||||
* End:
|
||||
* For VIM:
|
||||
* vim:set softtabstop=4 shiftwidth=4 tabstop=4 noet:
|
||||
*/
|
|
@ -44,20 +44,24 @@ struct blade_session_s {
|
|||
|
||||
ks_cond_t *cond;
|
||||
|
||||
ks_list_t *connections;
|
||||
const char *connection;
|
||||
ks_time_t ttl;
|
||||
|
||||
ks_q_t *sending;
|
||||
ks_q_t *receiving;
|
||||
|
||||
ks_hash_t *identities;
|
||||
ks_hash_t *realms;
|
||||
ks_hash_t *routes;
|
||||
|
||||
cJSON *properties;
|
||||
ks_rwl_t *properties_lock;
|
||||
};
|
||||
|
||||
void *blade_session_state_thread(ks_thread_t *thread, void *data);
|
||||
ks_status_t blade_session_state_on_destroy(blade_session_t *bs);
|
||||
ks_status_t blade_session_state_on_hangup(blade_session_t *bs);
|
||||
ks_status_t blade_session_state_on_ready(blade_session_t *bs);
|
||||
ks_status_t blade_session_onstate_startup(blade_session_t *bs);
|
||||
ks_status_t blade_session_onstate_shutdown(blade_session_t *bs);
|
||||
ks_status_t blade_session_onstate_run(blade_session_t *bs);
|
||||
ks_status_t blade_session_process(blade_session_t *bs, cJSON *json);
|
||||
|
||||
static void blade_session_cleanup(ks_pool_t *pool, void *ptr, void *arg, ks_pool_cleanup_action_t action, ks_pool_cleanup_type_t type)
|
||||
|
@ -84,7 +88,7 @@ static void blade_session_cleanup(ks_pool_t *pool, void *ptr, void *arg, ks_pool
|
|||
bs->properties_lock = NULL;
|
||||
bs->receiving = NULL;
|
||||
bs->sending = NULL;
|
||||
bs->connections = NULL;
|
||||
bs->connection = NULL;
|
||||
bs->cond = NULL;
|
||||
bs->lock = NULL;
|
||||
|
||||
|
@ -95,7 +99,7 @@ static void blade_session_cleanup(ks_pool_t *pool, void *ptr, void *arg, ks_pool
|
|||
}
|
||||
|
||||
|
||||
KS_DECLARE(ks_status_t) blade_session_create(blade_session_t **bsP, blade_handle_t *bh, const char *sid)
|
||||
KS_DECLARE(ks_status_t) blade_session_create(blade_session_t **bsP, blade_handle_t *bh, const char *id)
|
||||
{
|
||||
blade_session_t *bs = NULL;
|
||||
ks_pool_t *pool = NULL;
|
||||
|
@ -110,7 +114,7 @@ KS_DECLARE(ks_status_t) blade_session_create(blade_session_t **bsP, blade_handle
|
|||
bs->handle = bh;
|
||||
bs->pool = pool;
|
||||
|
||||
if (sid) bs->id = ks_pstrdup(pool, sid);
|
||||
if (id) bs->id = ks_pstrdup(pool, id);
|
||||
else {
|
||||
uuid_t id;
|
||||
ks_uuid(&id);
|
||||
|
@ -123,14 +127,20 @@ KS_DECLARE(ks_status_t) blade_session_create(blade_session_t **bsP, blade_handle
|
|||
ks_cond_create(&bs->cond, pool);
|
||||
ks_assert(bs->cond);
|
||||
|
||||
ks_list_create(&bs->connections, pool);
|
||||
ks_assert(bs->connections);
|
||||
|
||||
ks_q_create(&bs->sending, pool, 0);
|
||||
ks_assert(bs->sending);
|
||||
ks_q_create(&bs->receiving, pool, 0);
|
||||
ks_assert(bs->receiving);
|
||||
|
||||
ks_hash_create(&bs->identities, KS_HASH_MODE_CASE_INSENSITIVE, KS_HASH_FLAG_RWLOCK | KS_HASH_FLAG_DUP_CHECK | KS_HASH_FLAG_FREE_KEY, bs->pool);
|
||||
ks_assert(bs->identities);
|
||||
|
||||
ks_hash_create(&bs->realms, KS_HASH_MODE_CASE_INSENSITIVE, KS_HASH_FLAG_RWLOCK | KS_HASH_FLAG_DUP_CHECK | KS_HASH_FLAG_FREE_KEY, bs->pool);
|
||||
ks_assert(bs->realms);
|
||||
|
||||
ks_hash_create(&bs->routes, KS_HASH_MODE_CASE_INSENSITIVE, KS_HASH_FLAG_RWLOCK | KS_HASH_FLAG_DUP_CHECK | KS_HASH_FLAG_FREE_KEY, bs->pool);
|
||||
ks_assert(bs->routes);
|
||||
|
||||
bs->properties = cJSON_CreateObject();
|
||||
ks_assert(bs->properties);
|
||||
ks_rwl_create(&bs->properties_lock, pool);
|
||||
|
@ -187,10 +197,24 @@ KS_DECLARE(ks_status_t) blade_session_startup(blade_session_t *bs)
|
|||
|
||||
KS_DECLARE(ks_status_t) blade_session_shutdown(blade_session_t *bs)
|
||||
{
|
||||
ks_hash_iterator_t *it = NULL;
|
||||
cJSON *json = NULL;
|
||||
|
||||
ks_assert(bs);
|
||||
|
||||
// if this is an upstream session there will be no routes, so this is harmless to always run regardless
|
||||
ks_hash_read_lock(bs->routes);
|
||||
for (it = ks_hash_first(bs->routes, KS_UNLOCKED); it; it = ks_hash_next(&it)) {
|
||||
void *key = NULL;
|
||||
void *value = NULL;
|
||||
|
||||
ks_hash_this(it, &key, NULL, &value);
|
||||
|
||||
blade_handle_route_remove(bs->handle, (const char *)key);
|
||||
}
|
||||
ks_hash_read_unlock(bs->routes);
|
||||
|
||||
// this will also clear the identities and realms in the handle if this is the upstream session
|
||||
blade_handle_sessions_remove(bs);
|
||||
|
||||
while (ks_q_trypop(bs->sending, (void **)&json) == KS_STATUS_SUCCESS && json) cJSON_Delete(json);
|
||||
|
@ -222,6 +246,87 @@ KS_DECLARE(blade_session_state_t) blade_session_state_get(blade_session_t *bs)
|
|||
return bs->state;
|
||||
}
|
||||
|
||||
KS_DECLARE(ks_status_t) blade_session_identity_add(blade_session_t *bs, const char *identity)
|
||||
{
|
||||
char *key = NULL;
|
||||
|
||||
ks_assert(bs);
|
||||
ks_assert(identity);
|
||||
|
||||
key = ks_pstrdup(bs->pool, identity);
|
||||
ks_hash_insert(bs->identities, (void *)key, (void *)KS_TRUE);
|
||||
|
||||
return KS_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
KS_DECLARE(ks_status_t) blade_session_identity_remove(blade_session_t *bs, const char *identity)
|
||||
{
|
||||
ks_assert(bs);
|
||||
ks_assert(identity);
|
||||
|
||||
ks_hash_remove(bs->identities, (void *)identity);
|
||||
|
||||
return KS_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
KS_DECLARE(ks_hash_t *) blade_session_identities_get(blade_session_t *bs)
|
||||
{
|
||||
ks_assert(bs);
|
||||
return bs->identities;
|
||||
}
|
||||
|
||||
KS_DECLARE(ks_status_t) blade_session_realm_add(blade_session_t *bs, const char *realm)
|
||||
{
|
||||
char *key = NULL;
|
||||
|
||||
ks_assert(bs);
|
||||
ks_assert(realm);
|
||||
|
||||
key = ks_pstrdup(bs->pool, realm);
|
||||
ks_hash_insert(bs->realms, (void *)key, (void *)KS_TRUE);
|
||||
|
||||
return KS_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
KS_DECLARE(ks_status_t) blade_session_realm_remove(blade_session_t *bs, const char *realm)
|
||||
{
|
||||
ks_assert(bs);
|
||||
ks_assert(realm);
|
||||
|
||||
ks_hash_remove(bs->realms, (void *)realm);
|
||||
|
||||
return KS_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
KS_DECLARE(ks_hash_t *) blade_session_realms_get(blade_session_t *bs)
|
||||
{
|
||||
ks_assert(bs);
|
||||
return bs->realms;
|
||||
}
|
||||
|
||||
KS_DECLARE(ks_status_t) blade_session_route_add(blade_session_t *bs, const char *identity)
|
||||
{
|
||||
char *key = NULL;
|
||||
|
||||
ks_assert(bs);
|
||||
ks_assert(identity);
|
||||
|
||||
key = ks_pstrdup(bs->pool, identity);
|
||||
ks_hash_insert(bs->routes, (void *)key, (void *)KS_TRUE);
|
||||
|
||||
return KS_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
KS_DECLARE(ks_status_t) blade_session_route_remove(blade_session_t *bs, const char *identity)
|
||||
{
|
||||
ks_assert(bs);
|
||||
ks_assert(identity);
|
||||
|
||||
ks_hash_remove(bs->routes, (void *)identity);
|
||||
|
||||
return KS_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
KS_DECLARE(cJSON *) blade_session_properties_get(blade_session_t *bs)
|
||||
{
|
||||
ks_assert(bs);
|
||||
|
@ -321,7 +426,7 @@ KS_DECLARE(void) blade_session_hangup(blade_session_t *bs)
|
|||
|
||||
if (!blade_session_terminating(bs)) {
|
||||
ks_log(KS_LOG_DEBUG, "Session (%s) hanging up\n", bs->id);
|
||||
blade_session_state_set(bs, BLADE_SESSION_STATE_HANGUP);
|
||||
blade_session_state_set(bs, BLADE_SESSION_STATE_SHUTDOWN);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -329,83 +434,41 @@ KS_DECLARE(ks_bool_t) blade_session_terminating(blade_session_t *bs)
|
|||
{
|
||||
ks_assert(bs);
|
||||
|
||||
return bs->state == BLADE_SESSION_STATE_HANGUP || bs->state == BLADE_SESSION_STATE_DESTROY || bs->state == BLADE_SESSION_STATE_CLEANUP;
|
||||
return bs->state == BLADE_SESSION_STATE_SHUTDOWN || bs->state == BLADE_SESSION_STATE_CLEANUP;
|
||||
}
|
||||
|
||||
KS_DECLARE(ks_status_t) blade_session_connections_add(blade_session_t *bs, const char *id)
|
||||
KS_DECLARE(const char *) blade_session_connection_get(blade_session_t *bs)
|
||||
{
|
||||
ks_status_t ret = KS_STATUS_SUCCESS;
|
||||
const char *cid = NULL;
|
||||
|
||||
ks_assert(bs);
|
||||
|
||||
cid = ks_pstrdup(bs->pool, id);
|
||||
ks_assert(cid);
|
||||
|
||||
ks_list_append(bs->connections, cid);
|
||||
bs->ttl = 0;
|
||||
|
||||
ks_log(KS_LOG_DEBUG, "Session (%s) connection added (%s)\n", bs->id, id);
|
||||
|
||||
|
||||
return ret;
|
||||
return bs->connection;
|
||||
}
|
||||
|
||||
KS_DECLARE(ks_status_t) blade_session_connections_remove(blade_session_t *bs, const char *id)
|
||||
KS_DECLARE(ks_status_t) blade_session_connection_set(blade_session_t *bs, const char *id)
|
||||
{
|
||||
ks_status_t ret = KS_STATUS_SUCCESS;
|
||||
|
||||
ks_assert(bs);
|
||||
|
||||
ks_list_iterator_start(bs->connections);
|
||||
while (ks_list_iterator_hasnext(bs->connections)) {
|
||||
const char *cid = (const char *)ks_list_iterator_next(bs->connections);
|
||||
if (!strcasecmp(cid, id)) {
|
||||
ks_log(KS_LOG_DEBUG, "Session (%s) connection removed (%s)\n", bs->id, id);
|
||||
ks_list_delete_iterator(bs->connections);
|
||||
ks_pool_free(bs->pool, &cid);
|
||||
break;
|
||||
if (id) {
|
||||
if (bs->connection) {
|
||||
// @todo best that can be done in this situation is see if the connection is still available, and if so then disconnect it... this really shouldn't happen
|
||||
ks_pool_free(bs->pool, &bs->connection);
|
||||
}
|
||||
}
|
||||
ks_list_iterator_stop(bs->connections);
|
||||
bs->connection = ks_pstrdup(bs->pool, id);
|
||||
ks_assert(bs->connection);
|
||||
|
||||
if (ks_list_size(bs->connections) == 0) bs->ttl = ks_time_now() + (5 * KS_USEC_PER_SEC);
|
||||
bs->ttl = 0;
|
||||
|
||||
return ret;
|
||||
}
|
||||
ks_log(KS_LOG_DEBUG, "Session (%s) associated to connection (%s)\n", bs->id, id);
|
||||
|
||||
ks_status_t blade_session_connections_choose(blade_session_t *bs, cJSON *json, blade_connection_t **bcP)
|
||||
{
|
||||
ks_status_t ret = KS_STATUS_SUCCESS;
|
||||
blade_connection_t *bc = NULL;
|
||||
const char *cid = NULL;
|
||||
// @todo signal the wait condition for the state machine to see a reconnect immediately
|
||||
} else if (bs->connection) {
|
||||
ks_log(KS_LOG_DEBUG, "Session (%s) cleared connection (%s)\n", bs->id, bs->connection);
|
||||
|
||||
ks_assert(bs);
|
||||
ks_assert(json);
|
||||
ks_assert(bcP);
|
||||
ks_pool_free(bs->pool, &bs->connection);
|
||||
|
||||
// @todo may be multiple connections, for now let's just assume there will be only one
|
||||
// later there will need to be a way to pick which connection to use
|
||||
cid = ks_list_get_at(bs->connections, 0);
|
||||
if (!cid) {
|
||||
// no connections available
|
||||
ret = KS_STATUS_FAIL;
|
||||
goto done;
|
||||
bs->ttl = ks_time_now() + (5 * KS_USEC_PER_SEC);
|
||||
}
|
||||
|
||||
bc = blade_handle_connections_get(bs->handle, cid);
|
||||
if (!bc) {
|
||||
// @todo error logging... this shouldn't happen
|
||||
ret = KS_STATUS_FAIL;
|
||||
goto done;
|
||||
}
|
||||
// @todo make sure the connection is in the READY state before allowing it to be choosen, just in case it is detaching or not quite fully attached
|
||||
|
||||
*bcP = bc;
|
||||
|
||||
done:
|
||||
|
||||
return ret;
|
||||
return KS_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
KS_DECLARE(ks_status_t) blade_session_sending_push(blade_session_t *bs, cJSON *json)
|
||||
|
@ -471,45 +534,40 @@ void *blade_session_state_thread(ks_thread_t *thread, void *data)
|
|||
|
||||
state = bs->state;
|
||||
|
||||
if (!ks_list_empty(bs->connections)) {
|
||||
while (blade_session_sending_pop(bs, &json) == KS_STATUS_SUCCESS && json) {
|
||||
blade_connection_t *bc = NULL;
|
||||
if (blade_session_connections_choose(bs, json, &bc) == KS_STATUS_SUCCESS) {
|
||||
if (bs->connection) {
|
||||
blade_connection_t *bc = blade_handle_connections_lookup(bs->handle, bs->connection);
|
||||
if (bc) {
|
||||
// @note in order for this to work on session reconnecting, the assumption is that as soon as a session has a connection set,
|
||||
// we can start stuffing any messages queued for output on the session straight to the connection right away, may need to only
|
||||
// do this when in session ready state but there may be implications of other states sending messages through the session
|
||||
while (blade_session_sending_pop(bs, &json) == KS_STATUS_SUCCESS && json) {
|
||||
blade_connection_sending_push(bc, json);
|
||||
blade_connection_read_unlock(bc);
|
||||
} else {
|
||||
// @todo review this, possible the connection is dropped after popping a message, which results in it just being deleted without sending
|
||||
cJSON_Delete(json);
|
||||
}
|
||||
cJSON_Delete(json);
|
||||
blade_connection_read_unlock(bc);
|
||||
}
|
||||
}
|
||||
|
||||
// @todo evolve this system, it's probably not the best way to handle receiving session state updates externally
|
||||
blade_handle_session_state_callbacks_execute(bs, BLADE_SESSION_STATE_CONDITION_POST);
|
||||
|
||||
switch (state) {
|
||||
case BLADE_SESSION_STATE_DESTROY:
|
||||
blade_session_state_on_destroy(bs);
|
||||
case BLADE_SESSION_STATE_STARTUP:
|
||||
// @todo this may occur from a reconnect, should have some way to identify it is a reconnected session until we hit RUN state at least
|
||||
ks_log(KS_LOG_DEBUG, "Session (%s) state startup\n", bs->id);
|
||||
blade_session_state_set(bs, BLADE_SESSION_STATE_RUN);
|
||||
break;
|
||||
case BLADE_SESSION_STATE_SHUTDOWN:
|
||||
blade_session_onstate_shutdown(bs);
|
||||
shutdown = KS_TRUE;
|
||||
break;
|
||||
case BLADE_SESSION_STATE_HANGUP:
|
||||
blade_session_state_on_hangup(bs);
|
||||
break;
|
||||
case BLADE_SESSION_STATE_CONNECT:
|
||||
ks_log(KS_LOG_DEBUG, "Session (%s) state connect\n", bs->id);
|
||||
break;
|
||||
case BLADE_SESSION_STATE_ATTACH:
|
||||
ks_log(KS_LOG_DEBUG, "Session (%s) state attach\n", bs->id);
|
||||
break;
|
||||
case BLADE_SESSION_STATE_DETACH:
|
||||
ks_log(KS_LOG_DEBUG, "Session (%s) state detach\n", bs->id);
|
||||
break;
|
||||
case BLADE_SESSION_STATE_READY:
|
||||
blade_session_state_on_ready(bs);
|
||||
case BLADE_SESSION_STATE_RUN:
|
||||
blade_session_onstate_run(bs);
|
||||
break;
|
||||
default: break;
|
||||
}
|
||||
|
||||
if (ks_list_empty(bs->connections) &&
|
||||
if (!bs->connection &&
|
||||
bs->ttl > 0 &&
|
||||
!blade_session_terminating(bs) &&
|
||||
ks_time_now() >= bs->ttl) {
|
||||
|
@ -524,56 +582,43 @@ void *blade_session_state_thread(ks_thread_t *thread, void *data)
|
|||
return NULL;
|
||||
}
|
||||
|
||||
ks_status_t blade_session_state_on_destroy(blade_session_t *bs)
|
||||
ks_status_t blade_session_onstate_shutdown(blade_session_t *bs)
|
||||
{
|
||||
ks_assert(bs);
|
||||
|
||||
ks_log(KS_LOG_DEBUG, "Session (%s) state destroy\n", bs->id);
|
||||
ks_log(KS_LOG_DEBUG, "Session (%s) state shutdown\n", bs->id);
|
||||
|
||||
blade_session_state_set(bs, BLADE_SESSION_STATE_CLEANUP);
|
||||
|
||||
// @todo ignoring returns for now, see what makes sense later
|
||||
return KS_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
ks_status_t blade_session_state_on_hangup(blade_session_t *bs)
|
||||
{
|
||||
ks_assert(bs);
|
||||
|
||||
ks_log(KS_LOG_DEBUG, "Session (%s) state hangup\n", bs->id);
|
||||
|
||||
ks_list_iterator_start(bs->connections);
|
||||
while (ks_list_iterator_hasnext(bs->connections)) {
|
||||
const char *cid = (const char *)ks_list_iterator_next(bs->connections);
|
||||
blade_connection_t *bc = blade_handle_connections_get(bs->handle, cid);
|
||||
ks_assert(bc);
|
||||
|
||||
blade_connection_disconnect(bc);
|
||||
blade_connection_read_unlock(bc);
|
||||
if (bs->connection) {
|
||||
blade_connection_t *bc = blade_handle_connections_lookup(bs->handle, bs->connection);
|
||||
if (bc) {
|
||||
blade_connection_disconnect(bc);
|
||||
blade_connection_read_unlock(bc);
|
||||
}
|
||||
}
|
||||
ks_list_iterator_stop(bs->connections);
|
||||
|
||||
// @todo review this code, it may end up blocking forever as the mutex for the session is locked and the connection thread will not be able to lock to remove the connection...
|
||||
// isolate another mutex for the connection list, simclist is not intrinsicly thread safe like other containers
|
||||
while (!ks_list_empty(bs->connections)) ks_sleep(100);
|
||||
|
||||
blade_session_state_set(bs, BLADE_SESSION_STATE_DESTROY);
|
||||
// @note wait for the connection to disconnect before we resume session cleanup
|
||||
while (bs->connection) ks_sleep(100);
|
||||
|
||||
return KS_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
ks_status_t blade_session_state_on_ready(blade_session_t *bs)
|
||||
ks_status_t blade_session_onstate_run(blade_session_t *bs)
|
||||
{
|
||||
cJSON *json = NULL;
|
||||
|
||||
ks_assert(bs);
|
||||
|
||||
//ks_log(KS_LOG_DEBUG, "Session (%s) state ready\n", bs->id);
|
||||
//ks_log(KS_LOG_DEBUG, "Session (%s) state run\n", bs->id);
|
||||
|
||||
// @todo for now only process messages if there is a connection available
|
||||
if (ks_list_size(bs->connections) > 0) {
|
||||
if (bs->connection) {
|
||||
// @todo may only want to pop once per call to give sending a chance to keep up
|
||||
while (blade_session_receiving_pop(bs, &json) == KS_STATUS_SUCCESS && json) {
|
||||
// @todo all messages will pass through the local jsonrpc method handlers, but each needs to determine if the
|
||||
// message is destined for the local node, and if not then each handler can determine how routing occurs as
|
||||
// they differ, especially when it comes to the announcing of identities and propagation of multicast events
|
||||
blade_session_process(bs, json);
|
||||
cJSON_Delete(json);
|
||||
}
|
||||
|
@ -584,9 +629,9 @@ ks_status_t blade_session_state_on_ready(blade_session_t *bs)
|
|||
}
|
||||
|
||||
|
||||
KS_DECLARE(ks_status_t) blade_session_send(blade_session_t *bs, cJSON *json, blade_response_callback_t callback)
|
||||
KS_DECLARE(ks_status_t) blade_session_send(blade_session_t *bs, cJSON *json, blade_jsonrpc_response_callback_t callback)
|
||||
{
|
||||
blade_request_t *request = NULL;
|
||||
blade_jsonrpc_request_t *bjsonrpcreq = NULL;
|
||||
const char *method = NULL;
|
||||
const char *id = NULL;
|
||||
|
||||
|
@ -594,36 +639,31 @@ KS_DECLARE(ks_status_t) blade_session_send(blade_session_t *bs, cJSON *json, bla
|
|||
ks_assert(json);
|
||||
|
||||
method = cJSON_GetObjectCstr(json, "method");
|
||||
|
||||
id = cJSON_GetObjectCstr(json, "id");
|
||||
if (!id) {
|
||||
cJSON *blade = NULL;
|
||||
const char *event = NULL;
|
||||
ks_assert(id);
|
||||
|
||||
blade = cJSON_GetObjectItem(json, "blade");
|
||||
event = cJSON_GetObjectCstr(blade, "event");
|
||||
|
||||
ks_log(KS_LOG_DEBUG, "Session (%s) sending event (%s)\n", bs->id, event);
|
||||
} else if (method) {
|
||||
if (method) {
|
||||
// @note This is scenario 1
|
||||
// 1) Sending a request (client: method caller or consumer)
|
||||
ks_log(KS_LOG_DEBUG, "Session (%s) sending request (%s) for %s\n", bs->id, id, method);
|
||||
|
||||
blade_request_create(&request, bs->handle, blade_handle_pool_get(bs->handle), bs->id, json, callback);
|
||||
ks_assert(request);
|
||||
blade_jsonrpc_request_create(&bjsonrpcreq, bs->handle, blade_handle_pool_get(bs->handle), bs->id, json, callback);
|
||||
ks_assert(bjsonrpcreq);
|
||||
|
||||
// @todo set request TTL and figure out when requests are checked for expiration (separate thread in the handle?)
|
||||
blade_handle_requests_add(request);
|
||||
blade_handle_requests_add(bjsonrpcreq);
|
||||
} else {
|
||||
// @note This is scenario 3
|
||||
// 3) Sending a response or error (server: method callee or provider)
|
||||
ks_log(KS_LOG_DEBUG, "Session (%s) sending response (%s)\n", bs->id, id);
|
||||
}
|
||||
|
||||
if (ks_list_empty(bs->connections)) {
|
||||
if (!bs->connection) {
|
||||
blade_session_sending_push(bs, json);
|
||||
} else {
|
||||
blade_connection_t *bc = NULL;
|
||||
if (blade_session_connections_choose(bs, json, &bc) != KS_STATUS_SUCCESS) {
|
||||
blade_connection_t *bc = blade_handle_connections_lookup(bs->handle, bs->connection);
|
||||
if (!bc) {
|
||||
blade_session_sending_push(bs, json);
|
||||
return KS_STATUS_FAIL;
|
||||
}
|
||||
|
@ -636,12 +676,9 @@ KS_DECLARE(ks_status_t) blade_session_send(blade_session_t *bs, cJSON *json, bla
|
|||
|
||||
ks_status_t blade_session_process(blade_session_t *bs, cJSON *json)
|
||||
{
|
||||
blade_request_t *breq = NULL;
|
||||
blade_response_t *bres = NULL;
|
||||
blade_event_t *bev = NULL;
|
||||
blade_jsonrpc_request_t *bjsonrpcreq = NULL;
|
||||
blade_jsonrpc_response_t *bjsonrpcres = NULL;
|
||||
const char *jsonrpc = NULL;
|
||||
cJSON *blade = NULL;
|
||||
const char *blade_event = NULL;
|
||||
const char *id = NULL;
|
||||
const char *method = NULL;
|
||||
ks_bool_t disconnect = KS_FALSE;
|
||||
|
@ -660,99 +697,63 @@ ks_status_t blade_session_process(blade_session_t *bs, cJSON *json)
|
|||
return KS_STATUS_FAIL;
|
||||
}
|
||||
|
||||
blade = cJSON_GetObjectItem(json, "blade");
|
||||
if (blade) {
|
||||
blade_event = cJSON_GetObjectCstr(blade, "event");
|
||||
|
||||
id = cJSON_GetObjectCstr(json, "id");
|
||||
if (!id) {
|
||||
ks_log(KS_LOG_DEBUG, "Received message is missing 'id'\n");
|
||||
// @todo send error response, code = -32600 (invalid request)
|
||||
// @todo hangup session entirely?
|
||||
return KS_STATUS_FAIL;
|
||||
}
|
||||
|
||||
if (blade_event) {
|
||||
blade_event_callback_t callback = blade_handle_event_lookup(blade_session_handle_get(bs), blade_event);
|
||||
if (!callback) {
|
||||
ks_log(KS_LOG_DEBUG, "Received event message with no event callback '%s'\n", blade_event);
|
||||
} else {
|
||||
ks_log(KS_LOG_DEBUG, "Session (%s) processing event %s\n", bs->id, blade_event);
|
||||
method = cJSON_GetObjectCstr(json, "method");
|
||||
if (method) {
|
||||
// @note This is scenario 2
|
||||
// 2) Receiving a request (server: method callee or provider)
|
||||
blade_jsonrpc_t *bjsonrpc = NULL;
|
||||
blade_jsonrpc_request_callback_t callback = NULL;
|
||||
|
||||
blade_event_create(&bev, bs->handle, bs->pool, bs->id, json);
|
||||
ks_assert(bev);
|
||||
ks_log(KS_LOG_DEBUG, "Session (%s) receiving request (%s) for %s\n", bs->id, id, method);
|
||||
|
||||
disconnect = callback(bev);
|
||||
bjsonrpc = blade_handle_jsonrpc_lookup(bs->handle, method);
|
||||
|
||||
blade_event_destroy(&bev);
|
||||
if (!bjsonrpc) {
|
||||
ks_log(KS_LOG_DEBUG, "Received unknown jsonrpc method %s\n", method);
|
||||
// @todo send error response, code = -32601 (method not found)
|
||||
return KS_STATUS_FAIL;
|
||||
}
|
||||
callback = blade_jsonrpc_callback_get(bjsonrpc);
|
||||
ks_assert(callback);
|
||||
|
||||
blade_jsonrpc_request_create(&bjsonrpcreq, bs->handle, blade_handle_pool_get(bs->handle), bs->id, json, NULL);
|
||||
ks_assert(bjsonrpcreq);
|
||||
|
||||
disconnect = callback(bjsonrpcreq, blade_jsonrpc_callback_data_get(bjsonrpc));
|
||||
|
||||
blade_jsonrpc_request_destroy(&bjsonrpcreq);
|
||||
} else {
|
||||
id = cJSON_GetObjectCstr(json, "id");
|
||||
if (!id) {
|
||||
ks_log(KS_LOG_DEBUG, "Received non-event message is missing 'id'\n");
|
||||
// @todo send error response, code = -32600 (invalid request)
|
||||
// @note This is scenario 4
|
||||
// 4) Receiving a response or error (client: method caller or consumer)
|
||||
blade_jsonrpc_response_callback_t callback = NULL;
|
||||
|
||||
ks_log(KS_LOG_DEBUG, "Session (%s) receiving response (%s)\n", bs->id, id);
|
||||
|
||||
bjsonrpcreq = blade_handle_requests_lookup(bs->handle, id);
|
||||
if (!bjsonrpcreq) {
|
||||
// @todo hangup session entirely?
|
||||
return KS_STATUS_FAIL;
|
||||
}
|
||||
blade_handle_requests_remove(bjsonrpcreq);
|
||||
|
||||
method = cJSON_GetObjectCstr(json, "method");
|
||||
if (method) {
|
||||
// @note This is scenario 2
|
||||
// 2) Receiving a request (server: method callee or provider)
|
||||
blade_space_t *tmp_space = NULL;
|
||||
blade_method_t *tmp_method = NULL;
|
||||
blade_request_callback_t callback = NULL;
|
||||
char *space_name = ks_pstrdup(bs->pool, method);
|
||||
char *method_name = strrchr(space_name, '.');
|
||||
callback = blade_jsonrpc_request_callback_get(bjsonrpcreq);
|
||||
ks_assert(callback);
|
||||
|
||||
ks_log(KS_LOG_DEBUG, "Session (%s) receiving request (%s) for %s\n", bs->id, id, method);
|
||||
blade_jsonrpc_response_create(&bjsonrpcres, bs->handle, bs->pool, bs->id, bjsonrpcreq, json);
|
||||
ks_assert(bjsonrpcres);
|
||||
|
||||
if (!method_name || method_name == space_name) {
|
||||
ks_log(KS_LOG_DEBUG, "Received unparsable method\n");
|
||||
ks_pool_free(bs->pool, (void **)&space_name);
|
||||
// @todo send error response, code = -32601 (method not found)
|
||||
return KS_STATUS_FAIL;
|
||||
}
|
||||
*method_name = '\0';
|
||||
method_name++; // @todo check if can be postfixed safely on previous assignment, can't recall
|
||||
disconnect = callback(bjsonrpcres);
|
||||
|
||||
ks_log(KS_LOG_DEBUG, "Looking for space %s\n", space_name);
|
||||
|
||||
tmp_space = blade_handle_space_lookup(bs->handle, space_name);
|
||||
if (tmp_space) {
|
||||
ks_log(KS_LOG_DEBUG, "Looking for method %s\n", method_name);
|
||||
tmp_method = blade_space_methods_get(tmp_space, method_name);
|
||||
}
|
||||
|
||||
ks_pool_free(bs->pool, (void **)&space_name);
|
||||
|
||||
if (!tmp_method) {
|
||||
ks_log(KS_LOG_DEBUG, "Received unknown method\n");
|
||||
// @todo send error response, code = -32601 (method not found)
|
||||
return KS_STATUS_FAIL;
|
||||
}
|
||||
callback = blade_method_callback_get(tmp_method);
|
||||
ks_assert(callback);
|
||||
|
||||
blade_request_create(&breq, bs->handle, blade_handle_pool_get(bs->handle), bs->id, json, NULL);
|
||||
ks_assert(breq);
|
||||
|
||||
disconnect = callback(blade_space_module_get(tmp_space), breq);
|
||||
|
||||
blade_request_destroy(&breq);
|
||||
} else {
|
||||
// @note This is scenario 4
|
||||
// 4) Receiving a response or error (client: method caller or consumer)
|
||||
|
||||
ks_log(KS_LOG_DEBUG, "Session (%s) receiving response (%s)\n", bs->id, id);
|
||||
|
||||
breq = blade_handle_requests_get(bs->handle, id);
|
||||
if (!breq) {
|
||||
// @todo hangup session entirely?
|
||||
return KS_STATUS_FAIL;
|
||||
}
|
||||
blade_handle_requests_remove(breq);
|
||||
|
||||
blade_response_create(&bres, bs->handle, bs->pool, bs->id, breq, json);
|
||||
ks_assert(bres);
|
||||
|
||||
disconnect = breq->callback(bres);
|
||||
|
||||
blade_response_destroy(&bres);
|
||||
}
|
||||
blade_jsonrpc_response_destroy(&bjsonrpcres);
|
||||
}
|
||||
|
||||
if (disconnect) {
|
||||
|
|
|
@ -1,172 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2017, Shane Bryldt
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* * Neither the name of the original author; nor the names of any contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
|
||||
* OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include "blade.h"
|
||||
|
||||
struct blade_space_s {
|
||||
blade_handle_t *handle;
|
||||
ks_pool_t *pool;
|
||||
blade_module_t *module;
|
||||
|
||||
const char *path;
|
||||
ks_hash_t *methods;
|
||||
};
|
||||
|
||||
static void blade_space_cleanup(ks_pool_t *pool, void *ptr, void *arg, ks_pool_cleanup_action_t action, ks_pool_cleanup_type_t type)
|
||||
{
|
||||
blade_space_t *bs = (blade_space_t *)ptr;
|
||||
|
||||
ks_assert(bs);
|
||||
|
||||
switch (action) {
|
||||
case KS_MPCL_ANNOUNCE:
|
||||
break;
|
||||
case KS_MPCL_TEARDOWN:
|
||||
ks_pool_free(bs->pool, &bs->path);
|
||||
ks_hash_destroy(&bs->methods);
|
||||
break;
|
||||
case KS_MPCL_DESTROY:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
KS_DECLARE(ks_status_t) blade_space_create(blade_space_t **bsP, blade_handle_t *bh, blade_module_t *bm, const char *path)
|
||||
{
|
||||
blade_space_t *bs = NULL;
|
||||
ks_pool_t *pool = NULL;
|
||||
|
||||
ks_assert(bsP);
|
||||
ks_assert(bh);
|
||||
ks_assert(path);
|
||||
|
||||
pool = blade_module_pool_get(bm);
|
||||
ks_assert(pool);
|
||||
|
||||
bs = ks_pool_alloc(pool, sizeof(blade_space_t));
|
||||
bs->handle = bh;
|
||||
bs->pool = pool;
|
||||
bs->module = bm;
|
||||
bs->path = ks_pstrdup(pool, path);
|
||||
ks_hash_create(&bs->methods, KS_HASH_MODE_CASE_INSENSITIVE, KS_HASH_FLAG_RWLOCK | KS_HASH_FLAG_DUP_CHECK | KS_HASH_FLAG_FREE_VALUE, bs->pool);
|
||||
ks_assert(bs);
|
||||
|
||||
ks_pool_set_cleanup(pool, bs, NULL, blade_space_cleanup);
|
||||
|
||||
*bsP = bs;
|
||||
|
||||
ks_log(KS_LOG_DEBUG, "Space Created: %s\n", path);
|
||||
|
||||
return KS_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
KS_DECLARE(blade_handle_t *) blade_space_handle_get(blade_space_t *bs)
|
||||
{
|
||||
ks_assert(bs);
|
||||
|
||||
return bs->handle;
|
||||
}
|
||||
|
||||
KS_DECLARE(ks_pool_t *) blade_space_pool_get(blade_space_t *bs)
|
||||
{
|
||||
ks_assert(bs);
|
||||
|
||||
return bs->pool;
|
||||
}
|
||||
|
||||
KS_DECLARE(blade_module_t *) blade_space_module_get(blade_space_t *bs)
|
||||
{
|
||||
ks_assert(bs);
|
||||
|
||||
return bs->module;
|
||||
}
|
||||
|
||||
KS_DECLARE(const char *) blade_space_path_get(blade_space_t *bs)
|
||||
{
|
||||
ks_assert(bs);
|
||||
|
||||
return bs->path;
|
||||
}
|
||||
|
||||
KS_DECLARE(ks_status_t) blade_space_methods_add(blade_space_t *bs, blade_method_t *bm)
|
||||
{
|
||||
const char *name = NULL;
|
||||
|
||||
ks_assert(bs);
|
||||
ks_assert(bm);
|
||||
|
||||
name = blade_method_name_get(bm);
|
||||
ks_assert(name);
|
||||
|
||||
ks_hash_insert(bs->methods, (void *)name, (void *)bm);
|
||||
|
||||
return KS_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
KS_DECLARE(ks_status_t) blade_space_methods_remove(blade_space_t *bs, blade_method_t *bm)
|
||||
{
|
||||
const char *name = NULL;
|
||||
|
||||
ks_assert(bs);
|
||||
ks_assert(bm);
|
||||
|
||||
name = blade_method_name_get(bm);
|
||||
ks_assert(name);
|
||||
|
||||
ks_hash_remove(bs->methods, (void *)name);
|
||||
|
||||
return KS_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
KS_DECLARE(blade_method_t *) blade_space_methods_get(blade_space_t *bs, const char *name)
|
||||
{
|
||||
blade_method_t *bm = NULL;
|
||||
ks_assert(bs);
|
||||
ks_assert(name);
|
||||
|
||||
bm = ks_hash_search(bs->methods, (void *)name, KS_READLOCKED);
|
||||
ks_hash_read_unlock(bs->methods);
|
||||
|
||||
return bm;
|
||||
}
|
||||
|
||||
|
||||
/* For Emacs:
|
||||
* Local Variables:
|
||||
* mode:c
|
||||
* indent-tabs-mode:t
|
||||
* tab-width:4
|
||||
* c-basic-offset:4
|
||||
* End:
|
||||
* For VIM:
|
||||
* vim:set softtabstop=4 shiftwidth=4 tabstop=4 noet:
|
||||
*/
|
File diff suppressed because it is too large
Load Diff
|
@ -33,78 +33,100 @@
|
|||
|
||||
#include "blade.h"
|
||||
|
||||
struct blade_method_s {
|
||||
struct blade_transport_s {
|
||||
blade_handle_t *handle;
|
||||
ks_pool_t *pool;
|
||||
|
||||
blade_space_t *space;
|
||||
const char *name;
|
||||
|
||||
blade_request_callback_t callback;
|
||||
// @todo more fun descriptive information about the call for remote registrations
|
||||
void *data;
|
||||
blade_transport_callbacks_t *callbacks;
|
||||
};
|
||||
|
||||
static void blade_method_cleanup(ks_pool_t *pool, void *ptr, void *arg, ks_pool_cleanup_action_t action, ks_pool_cleanup_type_t type)
|
||||
{
|
||||
blade_method_t *bm = (blade_method_t *)ptr;
|
||||
|
||||
ks_assert(bm);
|
||||
static void blade_transport_cleanup(ks_pool_t *pool, void *ptr, void *arg, ks_pool_cleanup_action_t action, ks_pool_cleanup_type_t type)
|
||||
{
|
||||
//blade_transport_t *bt = (blade_transport_t *)ptr;
|
||||
|
||||
//ks_assert(bt);
|
||||
|
||||
switch (action) {
|
||||
case KS_MPCL_ANNOUNCE:
|
||||
break;
|
||||
case KS_MPCL_TEARDOWN:
|
||||
ks_pool_free(bm->pool, &bm->name);
|
||||
break;
|
||||
case KS_MPCL_DESTROY:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
KS_DECLARE(ks_status_t) blade_method_create(blade_method_t **bmP, blade_space_t *bs, const char *name, blade_request_callback_t callback)
|
||||
KS_DECLARE(ks_status_t) blade_transport_create(blade_transport_t **btP, blade_handle_t *bh, ks_pool_t *pool, const char *name, void *data, blade_transport_callbacks_t *callbacks)
|
||||
{
|
||||
blade_handle_t *bh = NULL;
|
||||
blade_method_t *bm = NULL;
|
||||
ks_pool_t *pool = NULL;
|
||||
blade_transport_t *bt = NULL;
|
||||
|
||||
ks_assert(bmP);
|
||||
ks_assert(bs);
|
||||
ks_assert(name);
|
||||
|
||||
bh = blade_space_handle_get(bs);
|
||||
ks_assert(btP);
|
||||
ks_assert(bh);
|
||||
|
||||
pool = blade_space_pool_get(bs);
|
||||
ks_assert(pool);
|
||||
ks_assert(name);
|
||||
ks_assert(callbacks);
|
||||
|
||||
bm = ks_pool_alloc(pool, sizeof(blade_method_t));
|
||||
bm->handle = bh;
|
||||
bm->pool = pool;
|
||||
bm->space = bs;
|
||||
bm->name = ks_pstrdup(pool, name);
|
||||
bm->callback = callback;
|
||||
bt = ks_pool_alloc(pool, sizeof(blade_transport_t));
|
||||
bt->handle = bh;
|
||||
bt->pool = pool;
|
||||
bt->name = ks_pstrdup(pool, name);
|
||||
bt->data = data;
|
||||
bt->callbacks = callbacks;
|
||||
|
||||
ks_pool_set_cleanup(pool, bm, NULL, blade_method_cleanup);
|
||||
ks_pool_set_cleanup(pool, bt, NULL, blade_transport_cleanup);
|
||||
|
||||
*bmP = bm;
|
||||
ks_log(KS_LOG_DEBUG, "Created transport %s\n", name);
|
||||
|
||||
*btP = bt;
|
||||
|
||||
return KS_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
KS_DECLARE(const char *) blade_method_name_get(blade_method_t *bm)
|
||||
KS_DECLARE(ks_status_t) blade_transport_destroy(blade_transport_t **btP)
|
||||
{
|
||||
ks_assert(bm);
|
||||
blade_transport_t *bt = NULL;
|
||||
ks_pool_t *pool = NULL;
|
||||
|
||||
return bm->name;
|
||||
ks_assert(btP);
|
||||
ks_assert(*btP);
|
||||
|
||||
bt = *btP;
|
||||
|
||||
pool = bt->pool;
|
||||
|
||||
ks_pool_close(&pool);
|
||||
|
||||
*btP = NULL;
|
||||
|
||||
return KS_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
KS_DECLARE(blade_request_callback_t) blade_method_callback_get(blade_method_t *bm)
|
||||
KS_DECLARE(blade_handle_t *) blade_transport_handle_get(blade_transport_t *bt)
|
||||
{
|
||||
ks_assert(bm);
|
||||
|
||||
return bm->callback;
|
||||
ks_assert(bt);
|
||||
return bt->handle;
|
||||
}
|
||||
|
||||
KS_DECLARE(const char *) blade_transport_name_get(blade_transport_t *bt)
|
||||
{
|
||||
ks_assert(bt);
|
||||
return bt->name;
|
||||
}
|
||||
|
||||
KS_DECLARE(void *) blade_transport_data_get(blade_transport_t *bt)
|
||||
{
|
||||
ks_assert(bt);
|
||||
return bt->data;
|
||||
}
|
||||
|
||||
KS_DECLARE(blade_transport_callbacks_t *) blade_transport_callbacks_get(blade_transport_t *bt)
|
||||
{
|
||||
ks_assert(bt);
|
||||
return bt->callbacks;
|
||||
}
|
||||
|
||||
/* For Emacs:
|
||||
* Local Variables:
|
File diff suppressed because it is too large
Load Diff
|
@ -34,28 +34,25 @@
|
|||
#ifndef _BLADE_H_
|
||||
#define _BLADE_H_
|
||||
#include <ks.h>
|
||||
#include <ks_dht.h>
|
||||
#include <sodium.h>
|
||||
#include <libconfig.h>
|
||||
#include "unqlite.h"
|
||||
#include "blade_types.h"
|
||||
#include "blade_stack.h"
|
||||
#include "blade_identity.h"
|
||||
#include "blade_module.h"
|
||||
#include "blade_transport.h"
|
||||
#include "blade_jsonrpc.h"
|
||||
#include "blade_connection.h"
|
||||
#include "blade_session.h"
|
||||
#include "blade_protocol.h"
|
||||
#include "blade_datastore.h"
|
||||
#include "blade_space.h"
|
||||
#include "blade_method.h"
|
||||
#include "ks_dht.h"
|
||||
#include "ks_bencode.h"
|
||||
|
||||
#include "blade_module_wss.h"
|
||||
#include "blade_transport_wss.h"
|
||||
|
||||
KS_BEGIN_EXTERN_C
|
||||
|
||||
#ifdef _WIN32
|
||||
// @todo look into why the tarball build has a different function name from the debian package
|
||||
#define config_lookup_from config_setting_lookup
|
||||
#endif
|
||||
|
||||
|
|
|
@ -52,7 +52,6 @@ KS_DECLARE(void) blade_connection_transport_set(blade_connection_t *bc, void *tr
|
|||
KS_DECLARE(void) blade_connection_state_set(blade_connection_t *bc, blade_connection_state_t state);
|
||||
KS_DECLARE(blade_connection_state_t) blade_connection_state_get(blade_connection_t *bc);
|
||||
KS_DECLARE(void) blade_connection_disconnect(blade_connection_t *bc);
|
||||
KS_DECLARE(blade_connection_rank_t) blade_connection_rank(blade_connection_t *bc, blade_identity_t *target);
|
||||
KS_DECLARE(ks_status_t) blade_connection_sending_push(blade_connection_t *bc, cJSON *json);
|
||||
KS_DECLARE(ks_status_t) blade_connection_sending_pop(blade_connection_t *bc, cJSON **json);
|
||||
KS_DECLARE(const char *) blade_connection_session_get(blade_connection_t *bc);
|
||||
|
|
|
@ -1,64 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2007-2014, Anthony Minessale II
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* * Neither the name of the original author; nor the names of any contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
|
||||
* OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#ifndef _BLADE_DATASTORE_H_
|
||||
#define _BLADE_DATASTORE_H_
|
||||
#include <blade.h>
|
||||
|
||||
KS_BEGIN_EXTERN_C
|
||||
KS_DECLARE(ks_status_t) blade_datastore_create(blade_datastore_t **bdsP, ks_pool_t *pool, ks_thread_pool_t *tpool);
|
||||
KS_DECLARE(ks_status_t) blade_datastore_destroy(blade_datastore_t **bdsP);
|
||||
KS_DECLARE(ks_status_t) blade_datastore_startup(blade_datastore_t *bds, config_setting_t *config);
|
||||
KS_DECLARE(ks_status_t) blade_datastore_shutdown(blade_datastore_t *bds);
|
||||
|
||||
KS_DECLARE(void) blade_datastore_error(blade_datastore_t *bds, const char **buffer, int32_t *buffer_length);
|
||||
KS_DECLARE(ks_status_t) blade_datastore_store(blade_datastore_t *bds, const void *key, int32_t key_length, const void *data, int64_t data_length);
|
||||
KS_DECLARE(ks_status_t) blade_datastore_fetch(blade_datastore_t *bds,
|
||||
blade_datastore_fetch_callback_t callback,
|
||||
const void *key,
|
||||
int32_t key_length,
|
||||
void *userdata);
|
||||
KS_END_EXTERN_C
|
||||
|
||||
#endif
|
||||
|
||||
/* For Emacs:
|
||||
* Local Variables:
|
||||
* mode:c
|
||||
* indent-tabs-mode:t
|
||||
* tab-width:4
|
||||
* c-basic-offset:4
|
||||
* End:
|
||||
* For VIM:
|
||||
* vim:set softtabstop=4 shiftwidth=4 tabstop=4 noet:
|
||||
*/
|
|
@ -0,0 +1,80 @@
|
|||
/*
|
||||
* Copyright (c) 2017, Shane Bryldt
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* * Neither the name of the original author; nor the names of any contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
|
||||
* OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#ifndef _BLADE_JSONRPC_H_
|
||||
#define _BLADE_JSONRPC_H_
|
||||
#include <blade.h>
|
||||
|
||||
KS_BEGIN_EXTERN_C
|
||||
KS_DECLARE(ks_status_t) blade_jsonrpc_create(blade_jsonrpc_t **bjsonrpcP, blade_handle_t *bh, const char *method, blade_jsonrpc_request_callback_t callback, void *callback_data);
|
||||
KS_DECLARE(ks_status_t) blade_jsonrpc_destroy(blade_jsonrpc_t **bjsonrpcP);
|
||||
KS_DECLARE(blade_handle_t *) blade_jsonrpc_handle_get(blade_jsonrpc_t *bjsonrpc);
|
||||
KS_DECLARE(const char *) blade_jsonrpc_method_get(blade_jsonrpc_t *bjsonrpc);
|
||||
KS_DECLARE(blade_jsonrpc_request_callback_t) blade_jsonrpc_callback_get(blade_jsonrpc_t *bjsonrpc);
|
||||
KS_DECLARE(void *) blade_jsonrpc_callback_data_get(blade_jsonrpc_t *bjsonrpc);
|
||||
|
||||
KS_DECLARE(ks_status_t) blade_jsonrpc_request_create(blade_jsonrpc_request_t **bjsonrpcreqP,
|
||||
blade_handle_t *bh,
|
||||
ks_pool_t *pool,
|
||||
const char *session_id,
|
||||
cJSON *json,
|
||||
blade_jsonrpc_response_callback_t callback);
|
||||
KS_DECLARE(ks_status_t) blade_jsonrpc_request_destroy(blade_jsonrpc_request_t **bjsonrpcreqP);
|
||||
KS_DECLARE(blade_handle_t *) blade_jsonrpc_request_handle_get(blade_jsonrpc_request_t *bjsonrpcreq);
|
||||
KS_DECLARE(const char *) blade_jsonrpc_request_messageid_get(blade_jsonrpc_request_t *bjsonrpcreq);
|
||||
KS_DECLARE(blade_jsonrpc_response_callback_t) blade_jsonrpc_request_callback_get(blade_jsonrpc_request_t *bjsonrpcreq);
|
||||
KS_DECLARE(ks_status_t) blade_jsonrpc_request_raw_create(ks_pool_t *pool, cJSON **json, cJSON **params, const char **id, const char *method);
|
||||
|
||||
KS_DECLARE(ks_status_t) blade_jsonrpc_response_create(blade_jsonrpc_response_t **bjsonrpcresP,
|
||||
blade_handle_t *bh,
|
||||
ks_pool_t *pool,
|
||||
const char *session_id,
|
||||
blade_jsonrpc_request_t *bjsonrpcreq,
|
||||
cJSON *json);
|
||||
KS_DECLARE(ks_status_t) blade_jsonrpc_response_destroy(blade_jsonrpc_response_t **bjsonrpcresP);
|
||||
KS_DECLARE(ks_status_t) blade_jsonrpc_response_raw_create(cJSON **json, cJSON **result, const char *id);
|
||||
KS_DECLARE(ks_status_t) blade_jsonrpc_error_raw_create(cJSON **json, cJSON **error, const char *id, int32_t code, const char *message);
|
||||
KS_END_EXTERN_C
|
||||
|
||||
#endif
|
||||
|
||||
/* For Emacs:
|
||||
* Local Variables:
|
||||
* mode:c
|
||||
* indent-tabs-mode:t
|
||||
* tab-width:4
|
||||
* c-basic-offset:4
|
||||
* End:
|
||||
* For VIM:
|
||||
* vim:set softtabstop=4 shiftwidth=4 tabstop=4 noet:
|
||||
*/
|
|
@ -31,14 +31,17 @@
|
|||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#ifndef _BLADE_METHOD_H_
|
||||
#define _BLADE_METHOD_H_
|
||||
#ifndef _BLADE_MODULE_MASTER_H_
|
||||
#define _BLADE_MODULE_MASTER_H_
|
||||
#include <blade.h>
|
||||
|
||||
KS_BEGIN_EXTERN_C
|
||||
KS_DECLARE(ks_status_t) blade_method_create(blade_method_t **bmP, blade_space_t *bs, const char *name, blade_request_callback_t callback);
|
||||
KS_DECLARE(const char *) blade_method_name_get(blade_method_t *bm);
|
||||
KS_DECLARE(blade_request_callback_t) blade_method_callback_get(blade_method_t *bm);
|
||||
|
||||
KS_DECLARE(ks_status_t) blade_module_master_create(blade_module_t **bmP, blade_handle_t *bh);
|
||||
|
||||
KS_DECLARE(ks_status_t) blade_module_master_on_startup(blade_module_t *bm, config_setting_t *config);
|
||||
KS_DECLARE(ks_status_t) blade_module_master_on_shutdown(blade_module_t *bm);
|
||||
|
||||
KS_END_EXTERN_C
|
||||
|
||||
#endif
|
|
@ -1,67 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2017, Shane Bryldt
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* * Neither the name of the original author; nor the names of any contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
|
||||
* OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#ifndef _BLADE_PROTOCOL_H_
|
||||
#define _BLADE_PROTOCOL_H_
|
||||
#include <blade.h>
|
||||
|
||||
KS_BEGIN_EXTERN_C
|
||||
KS_DECLARE(ks_status_t) blade_request_create(blade_request_t **breqP,
|
||||
blade_handle_t *bh,
|
||||
ks_pool_t *pool,
|
||||
const char *session_id,
|
||||
cJSON *json,
|
||||
blade_response_callback_t callback);
|
||||
KS_DECLARE(ks_status_t) blade_request_destroy(blade_request_t **breqP);
|
||||
KS_DECLARE(ks_status_t) blade_response_create(blade_response_t **bresP, blade_handle_t *bh, ks_pool_t *pool, const char *session_id, blade_request_t *breq, cJSON *json);
|
||||
KS_DECLARE(ks_status_t) blade_response_destroy(blade_response_t **bresP);
|
||||
KS_DECLARE(ks_status_t) blade_event_create(blade_event_t **bevP, blade_handle_t *bh, ks_pool_t *pool, const char *session_id, cJSON *json);
|
||||
KS_DECLARE(ks_status_t) blade_event_destroy(blade_event_t **bevP);
|
||||
KS_DECLARE(ks_status_t) blade_rpc_request_create(ks_pool_t *pool, cJSON **json, cJSON **params, const char **id, const char *method);
|
||||
KS_DECLARE(ks_status_t) blade_rpc_response_create(cJSON **json, cJSON **result, const char *id);
|
||||
KS_DECLARE(ks_status_t) blade_rpc_error_create(cJSON **json, cJSON **error, const char *id, int32_t code, const char *message);
|
||||
KS_DECLARE(ks_status_t) blade_rpc_event_create(cJSON **json, cJSON **result, const char *event);
|
||||
KS_END_EXTERN_C
|
||||
|
||||
#endif
|
||||
|
||||
/* For Emacs:
|
||||
* Local Variables:
|
||||
* mode:c
|
||||
* indent-tabs-mode:t
|
||||
* tab-width:4
|
||||
* c-basic-offset:4
|
||||
* End:
|
||||
* For VIM:
|
||||
* vim:set softtabstop=4 shiftwidth=4 tabstop=4 noet:
|
||||
*/
|
|
@ -36,13 +36,21 @@
|
|||
#include <blade.h>
|
||||
|
||||
KS_BEGIN_EXTERN_C
|
||||
KS_DECLARE(ks_status_t) blade_session_create(blade_session_t **bsP, blade_handle_t *bh, const char *sid);
|
||||
KS_DECLARE(ks_status_t) blade_session_create(blade_session_t **bsP, blade_handle_t *bh, const char *id);
|
||||
KS_DECLARE(ks_status_t) blade_session_destroy(blade_session_t **bsP);
|
||||
KS_DECLARE(ks_status_t) blade_session_startup(blade_session_t *bs);
|
||||
KS_DECLARE(ks_status_t) blade_session_shutdown(blade_session_t *bs);
|
||||
KS_DECLARE(blade_handle_t *) blade_session_handle_get(blade_session_t *bs);
|
||||
KS_DECLARE(const char *) blade_session_id_get(blade_session_t *bs);
|
||||
KS_DECLARE(blade_session_state_t) blade_session_state_get(blade_session_t *bs);
|
||||
KS_DECLARE(ks_status_t) blade_session_identity_add(blade_session_t *bs, const char *identity);
|
||||
KS_DECLARE(ks_status_t) blade_session_identity_remove(blade_session_t *bs, const char *identity);
|
||||
KS_DECLARE(ks_hash_t *) blade_session_identities_get(blade_session_t *bs);
|
||||
KS_DECLARE(ks_status_t) blade_session_realm_add(blade_session_t *bs, const char *realm);
|
||||
KS_DECLARE(ks_status_t) blade_session_realm_remove(blade_session_t *bs, const char *realm);
|
||||
KS_DECLARE(ks_hash_t *) blade_session_realms_get(blade_session_t *bs);
|
||||
KS_DECLARE(ks_status_t) blade_session_route_add(blade_session_t *bs, const char *identity);
|
||||
KS_DECLARE(ks_status_t) blade_session_route_remove(blade_session_t *bs, const char *identity);
|
||||
KS_DECLARE(cJSON *) blade_session_properties_get(blade_session_t *bs);
|
||||
KS_DECLARE(ks_status_t) blade_session_read_lock(blade_session_t *bs, ks_bool_t block);
|
||||
KS_DECLARE(ks_status_t) blade_session_read_unlock(blade_session_t *bs);
|
||||
|
@ -55,9 +63,9 @@ KS_DECLARE(ks_status_t) blade_session_properties_write_unlock(blade_session_t *b
|
|||
KS_DECLARE(void) blade_session_state_set(blade_session_t *bs, blade_session_state_t state);
|
||||
KS_DECLARE(void) blade_session_hangup(blade_session_t *bs);
|
||||
KS_DECLARE(ks_bool_t) blade_session_terminating(blade_session_t *bs);
|
||||
KS_DECLARE(ks_status_t) blade_session_connections_add(blade_session_t *bs, const char *id);
|
||||
KS_DECLARE(ks_status_t) blade_session_connections_remove(blade_session_t *bs, const char *id);
|
||||
KS_DECLARE(ks_status_t) blade_session_send(blade_session_t *bs, cJSON *json, blade_response_callback_t callback);
|
||||
KS_DECLARE(const char *) blade_session_connection_get(blade_session_t *bs);
|
||||
KS_DECLARE(ks_status_t) blade_session_connection_set(blade_session_t *bs, const char *id);
|
||||
KS_DECLARE(ks_status_t) blade_session_send(blade_session_t *bs, cJSON *json, blade_jsonrpc_response_callback_t callback);
|
||||
KS_DECLARE(ks_status_t) blade_session_sending_push(blade_session_t *bs, cJSON *json);
|
||||
KS_DECLARE(ks_status_t) blade_session_sending_pop(blade_session_t *bs, cJSON **json);
|
||||
KS_DECLARE(ks_status_t) blade_session_receiving_push(blade_session_t *bs, cJSON *json);
|
||||
|
|
|
@ -1,60 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2017, Shane Bryldt
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* * Neither the name of the original author; nor the names of any contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
|
||||
* OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#ifndef _BLADE_SPACE_H_
|
||||
#define _BLADE_SPACE_H_
|
||||
#include <blade.h>
|
||||
|
||||
KS_BEGIN_EXTERN_C
|
||||
KS_DECLARE(ks_status_t) blade_space_create(blade_space_t **bsP, blade_handle_t *bh, blade_module_t *bm, const char *path);
|
||||
KS_DECLARE(blade_handle_t *) blade_space_handle_get(blade_space_t *bs);
|
||||
KS_DECLARE(ks_pool_t *) blade_space_pool_get(blade_space_t *bs);
|
||||
KS_DECLARE(blade_module_t *) blade_space_module_get(blade_space_t *bs);
|
||||
KS_DECLARE(const char *) blade_space_path_get(blade_space_t *bs);
|
||||
KS_DECLARE(ks_status_t) blade_space_methods_add(blade_space_t *bs, blade_method_t *bm);
|
||||
KS_DECLARE(ks_status_t) blade_space_methods_remove(blade_space_t *bs, blade_method_t *bm);
|
||||
KS_DECLARE(blade_method_t *) blade_space_methods_get(blade_space_t *bs, const char *name);
|
||||
KS_END_EXTERN_C
|
||||
|
||||
#endif
|
||||
|
||||
/* For Emacs:
|
||||
* Local Variables:
|
||||
* mode:c
|
||||
* indent-tabs-mode:t
|
||||
* tab-width:4
|
||||
* c-basic-offset:4
|
||||
* End:
|
||||
* For VIM:
|
||||
* vim:set softtabstop=4 shiftwidth=4 tabstop=4 noet:
|
||||
*/
|
|
@ -48,45 +48,46 @@ KS_DECLARE(ks_status_t) blade_handle_shutdown(blade_handle_t *bh);
|
|||
KS_DECLARE(ks_pool_t *) blade_handle_pool_get(blade_handle_t *bh);
|
||||
KS_DECLARE(ks_thread_pool_t *) blade_handle_tpool_get(blade_handle_t *bh);
|
||||
|
||||
KS_DECLARE(ks_status_t) blade_handle_module_register(blade_module_t *bm);
|
||||
//KS_DECLARE(ks_status_t) blade_handle_module_unregister(blade_module_t *bm);
|
||||
KS_DECLARE(ks_status_t) blade_handle_identity_register(blade_handle_t *bh, const char *identity);
|
||||
KS_DECLARE(ks_status_t) blade_handle_identity_unregister(blade_handle_t *bh, const char *identity);
|
||||
|
||||
KS_DECLARE(ks_status_t) blade_handle_transport_register(blade_handle_t *bh, blade_module_t *bm, const char *name, blade_transport_callbacks_t *callbacks);
|
||||
KS_DECLARE(ks_status_t) blade_handle_transport_unregister(blade_handle_t *bh, const char *name);
|
||||
KS_DECLARE(ks_status_t) blade_handle_realm_register(blade_handle_t *bh, const char *realm);
|
||||
KS_DECLARE(ks_status_t) blade_handle_realm_unregister(blade_handle_t *bh, const char *realm);
|
||||
KS_DECLARE(ks_hash_t *) blade_handle_realms_get(blade_handle_t *bh);
|
||||
|
||||
KS_DECLARE(ks_status_t) blade_handle_space_register(blade_space_t *bs);
|
||||
KS_DECLARE(ks_status_t) blade_handle_space_unregister(blade_space_t *bs);
|
||||
KS_DECLARE(blade_space_t *) blade_handle_space_lookup(blade_handle_t *bh, const char *path);
|
||||
KS_DECLARE(ks_status_t) blade_handle_route_add(blade_handle_t *bh, const char *identity, const char *id);
|
||||
KS_DECLARE(ks_status_t) blade_handle_route_remove(blade_handle_t *bh, const char *identity);
|
||||
KS_DECLARE(blade_session_t *) blade_handle_route_lookup(blade_handle_t *bh, const char *identity);
|
||||
|
||||
KS_DECLARE(ks_status_t) blade_handle_transport_register(blade_transport_t *bt);
|
||||
KS_DECLARE(ks_status_t) blade_handle_transport_unregister(blade_transport_t *bt);
|
||||
|
||||
KS_DECLARE(ks_status_t) blade_handle_jsonrpc_register(blade_jsonrpc_t *bjsonrpc);
|
||||
KS_DECLARE(ks_status_t) blade_handle_jsonrpc_unregister(blade_jsonrpc_t *bjsonrpc);
|
||||
KS_DECLARE(blade_jsonrpc_t *) blade_handle_jsonrpc_lookup(blade_handle_t *bh, const char *method);
|
||||
|
||||
KS_DECLARE(ks_status_t) blade_handle_requests_add(blade_jsonrpc_request_t *bjsonrpcreq);
|
||||
KS_DECLARE(ks_status_t) blade_handle_requests_remove(blade_jsonrpc_request_t *bjsonrpcreq);
|
||||
KS_DECLARE(blade_jsonrpc_request_t *) blade_handle_requests_lookup(blade_handle_t *bh, const char *id);
|
||||
|
||||
KS_DECLARE(ks_status_t) blade_handle_event_register(blade_handle_t *bh, const char *event, blade_event_callback_t callback);
|
||||
KS_DECLARE(ks_status_t) blade_handle_event_unregister(blade_handle_t *bh, const char *event);
|
||||
KS_DECLARE(blade_event_callback_t) blade_handle_event_lookup(blade_handle_t *bh, const char *event);
|
||||
|
||||
KS_DECLARE(ks_status_t) blade_handle_connect(blade_handle_t *bh, blade_connection_t **bcP, blade_identity_t *target, const char *session_id);
|
||||
|
||||
KS_DECLARE(blade_connection_t *) blade_handle_connections_get(blade_handle_t *bh, const char *cid);
|
||||
KS_DECLARE(ks_status_t) blade_handle_connections_add(blade_connection_t *bc);
|
||||
KS_DECLARE(ks_status_t) blade_handle_connections_remove(blade_connection_t *bc);
|
||||
KS_DECLARE(blade_connection_t *) blade_handle_connections_lookup(blade_handle_t *bh, const char *id);
|
||||
|
||||
KS_DECLARE(blade_session_t *) blade_handle_sessions_get(blade_handle_t *bh, const char *sid);
|
||||
KS_DECLARE(ks_status_t) blade_handle_sessions_add(blade_session_t *bs);
|
||||
KS_DECLARE(ks_status_t) blade_handle_sessions_remove(blade_session_t *bs);
|
||||
KS_DECLARE(blade_session_t *) blade_handle_sessions_lookup(blade_handle_t *bh, const char *id);
|
||||
|
||||
KS_DECLARE(ks_status_t) blade_handle_upstream_set(blade_handle_t *bh, const char *id);
|
||||
|
||||
KS_DECLARE(void) blade_handle_sessions_send(blade_handle_t *bh, ks_list_t *sessions, const char *exclude, cJSON *json);
|
||||
KS_DECLARE(ks_status_t) blade_handle_session_state_callback_register(blade_handle_t *bh, void *data, blade_session_state_callback_t callback, const char **id);
|
||||
KS_DECLARE(ks_status_t) blade_handle_session_state_callback_unregister(blade_handle_t *bh, const char *id);
|
||||
KS_DECLARE(void) blade_handle_session_state_callbacks_execute(blade_session_t *bs, blade_session_state_condition_t condition);
|
||||
|
||||
KS_DECLARE(blade_request_t *) blade_handle_requests_get(blade_handle_t *bh, const char *mid);
|
||||
KS_DECLARE(ks_status_t) blade_handle_requests_add(blade_request_t *br);
|
||||
KS_DECLARE(ks_status_t) blade_handle_requests_remove(blade_request_t *br);
|
||||
|
||||
KS_DECLARE(ks_bool_t) blade_handle_datastore_available(blade_handle_t *bh);
|
||||
KS_DECLARE(ks_status_t) blade_handle_datastore_store(blade_handle_t *bh, const void *key, int32_t key_length, const void *data, int64_t data_length);
|
||||
KS_DECLARE(ks_status_t) blade_handle_datastore_fetch(blade_handle_t *bh,
|
||||
blade_datastore_fetch_callback_t callback,
|
||||
const void *key,
|
||||
int32_t key_length,
|
||||
void *userdata);
|
||||
KS_END_EXTERN_C
|
||||
|
||||
#endif
|
||||
|
|
|
@ -1,23 +1,23 @@
|
|||
/*
|
||||
* Copyright (c) 2017, Shane Bryldt
|
||||
* All rights reserved.
|
||||
*
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
*
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
*
|
||||
* * Neither the name of the original author; nor the names of any contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
|
@ -31,20 +31,17 @@
|
|||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#ifndef _BLADE_MODULE_H_
|
||||
#define _BLADE_MODULE_H_
|
||||
#ifndef _BLADE_TRANSPORT_H_
|
||||
#define _BLADE_TRANSPORT_H_
|
||||
#include <blade.h>
|
||||
|
||||
KS_BEGIN_EXTERN_C
|
||||
|
||||
KS_DECLARE(ks_status_t) blade_module_create(blade_module_t **bmP, blade_handle_t *bh, ks_pool_t *pool, void *module_data, blade_module_callbacks_t *module_callbacks);
|
||||
KS_DECLARE(ks_status_t) blade_module_destroy(blade_module_t **bmP);
|
||||
KS_DECLARE(blade_handle_t *) blade_module_handle_get(blade_module_t *bm);
|
||||
KS_DECLARE(ks_pool_t *) blade_module_pool_get(blade_module_t *bm);
|
||||
KS_DECLARE(const char *) blade_module_id_get(blade_module_t *bm);
|
||||
KS_DECLARE(void *) blade_module_data_get(blade_module_t *bm);
|
||||
KS_DECLARE(blade_module_callbacks_t *) blade_module_callbacks_get(blade_module_t *bm);
|
||||
|
||||
KS_DECLARE(ks_status_t) blade_transport_create(blade_transport_t **btP, blade_handle_t *bh, ks_pool_t *pool, const char *name, void *data, blade_transport_callbacks_t *callbacks);
|
||||
KS_DECLARE(ks_status_t) blade_transport_destroy(blade_transport_t **btP);
|
||||
KS_DECLARE(blade_handle_t *) blade_transport_handle_get(blade_transport_t *bt);
|
||||
KS_DECLARE(const char *) blade_transport_name_get(blade_transport_t *bt);
|
||||
KS_DECLARE(void *) blade_transport_data_get(blade_transport_t *bt);
|
||||
KS_DECLARE(blade_transport_callbacks_t *) blade_transport_callbacks_get(blade_transport_t *bt);
|
||||
KS_END_EXTERN_C
|
||||
|
||||
#endif
|
|
@ -37,10 +37,7 @@
|
|||
|
||||
KS_BEGIN_EXTERN_C
|
||||
|
||||
KS_DECLARE(ks_status_t) blade_module_wss_create(blade_module_t **bmP, blade_handle_t *bh);
|
||||
|
||||
KS_DECLARE(ks_status_t) blade_module_wss_on_startup(blade_module_t *bm, config_setting_t *config);
|
||||
KS_DECLARE(ks_status_t) blade_module_wss_on_shutdown(blade_module_t *bm);
|
||||
KS_DECLARE(ks_status_t) blade_transport_wss_create(blade_transport_t **btP, blade_handle_t *bh);
|
||||
|
||||
KS_END_EXTERN_C
|
||||
|
|
@ -40,25 +40,22 @@ KS_BEGIN_EXTERN_C
|
|||
|
||||
typedef struct blade_handle_s blade_handle_t;
|
||||
typedef struct blade_identity_s blade_identity_t;
|
||||
typedef struct blade_module_s blade_module_t;
|
||||
typedef struct blade_module_callbacks_s blade_module_callbacks_t;
|
||||
typedef struct blade_transport_s blade_transport_t;
|
||||
typedef struct blade_transport_callbacks_s blade_transport_callbacks_t;
|
||||
typedef struct blade_jsonrpc_s blade_jsonrpc_t;
|
||||
typedef struct blade_jsonrpc_request_s blade_jsonrpc_request_t;
|
||||
typedef struct blade_jsonrpc_response_s blade_jsonrpc_response_t;
|
||||
typedef struct blade_session_callbacks_s blade_session_callbacks_t;
|
||||
typedef struct blade_connection_s blade_connection_t;
|
||||
typedef struct blade_session_s blade_session_t;
|
||||
typedef struct blade_request_s blade_request_t;
|
||||
typedef struct blade_response_s blade_response_t;
|
||||
typedef struct blade_event_s blade_event_t;
|
||||
typedef struct blade_space_s blade_space_t;
|
||||
typedef struct blade_method_s blade_method_t;
|
||||
typedef struct blade_application_s blade_application_t;
|
||||
|
||||
|
||||
typedef struct blade_datastore_s blade_datastore_t;
|
||||
|
||||
typedef ks_bool_t (*blade_jsonrpc_request_callback_t)(blade_jsonrpc_request_t *breq, void *data);
|
||||
typedef ks_bool_t (*blade_jsonrpc_response_callback_t)(blade_jsonrpc_response_t *bres);
|
||||
|
||||
typedef ks_bool_t (*blade_request_callback_t)(blade_module_t *bm, blade_request_t *breq);
|
||||
typedef ks_bool_t (*blade_response_callback_t)(blade_response_t *bres);
|
||||
typedef ks_bool_t (*blade_event_callback_t)(blade_event_t *bev);
|
||||
|
||||
typedef ks_bool_t (*blade_datastore_fetch_callback_t)(blade_datastore_t *bds, const void *data, uint32_t data_length, void *userdata);
|
||||
|
||||
|
@ -66,12 +63,9 @@ typedef ks_bool_t (*blade_datastore_fetch_callback_t)(blade_datastore_t *bds, co
|
|||
typedef enum {
|
||||
BLADE_CONNECTION_STATE_NONE,
|
||||
BLADE_CONNECTION_STATE_CLEANUP,
|
||||
BLADE_CONNECTION_STATE_DISCONNECT,
|
||||
BLADE_CONNECTION_STATE_NEW,
|
||||
BLADE_CONNECTION_STATE_CONNECT,
|
||||
BLADE_CONNECTION_STATE_ATTACH,
|
||||
BLADE_CONNECTION_STATE_DETACH,
|
||||
BLADE_CONNECTION_STATE_READY,
|
||||
BLADE_CONNECTION_STATE_STARTUP,
|
||||
BLADE_CONNECTION_STATE_SHUTDOWN,
|
||||
BLADE_CONNECTION_STATE_RUN,
|
||||
} blade_connection_state_t;
|
||||
|
||||
typedef enum {
|
||||
|
@ -90,13 +84,6 @@ typedef enum {
|
|||
BLADE_CONNECTION_STATE_HOOK_BYPASS,
|
||||
} blade_connection_state_hook_t;
|
||||
|
||||
typedef enum {
|
||||
BLADE_CONNECTION_RANK_POOR,
|
||||
BLADE_CONNECTION_RANK_AVERAGE,
|
||||
BLADE_CONNECTION_RANK_GOOD,
|
||||
BLADE_CONNECTION_RANK_GREAT,
|
||||
} blade_connection_rank_t;
|
||||
|
||||
|
||||
typedef enum {
|
||||
BLADE_SESSION_STATE_CONDITION_PRE,
|
||||
|
@ -106,83 +93,41 @@ typedef enum {
|
|||
typedef enum {
|
||||
BLADE_SESSION_STATE_NONE,
|
||||
BLADE_SESSION_STATE_CLEANUP,
|
||||
BLADE_SESSION_STATE_DESTROY,
|
||||
BLADE_SESSION_STATE_HANGUP,
|
||||
BLADE_SESSION_STATE_CONNECT,
|
||||
BLADE_SESSION_STATE_ATTACH,
|
||||
BLADE_SESSION_STATE_DETACH,
|
||||
BLADE_SESSION_STATE_READY,
|
||||
BLADE_SESSION_STATE_STARTUP,
|
||||
BLADE_SESSION_STATE_SHUTDOWN,
|
||||
BLADE_SESSION_STATE_RUN,
|
||||
} blade_session_state_t;
|
||||
|
||||
|
||||
|
||||
typedef ks_status_t (*blade_module_startup_callback_t)(blade_module_t *bm, config_setting_t *config);
|
||||
typedef ks_status_t(*blade_module_shutdown_callback_t)(blade_module_t *bm);
|
||||
|
||||
struct blade_module_callbacks_s {
|
||||
blade_module_startup_callback_t onstartup;
|
||||
blade_module_shutdown_callback_t onshutdown;
|
||||
};
|
||||
|
||||
|
||||
typedef ks_status_t (*blade_transport_connect_callback_t)(blade_connection_t **bcP, blade_module_t *bm, blade_identity_t *target, const char *session_id);
|
||||
typedef blade_connection_rank_t (*blade_transport_rank_callback_t)(blade_connection_t *bc, blade_identity_t *target);
|
||||
typedef ks_status_t (*blade_transport_startup_callback_t)(blade_transport_t *bt, config_setting_t *config);
|
||||
typedef ks_status_t (*blade_transport_shutdown_callback_t)(blade_transport_t *bt);
|
||||
typedef ks_status_t (*blade_transport_connect_callback_t)(blade_connection_t **bcP, blade_transport_t *bt, blade_identity_t *target, const char *session_id);
|
||||
typedef ks_status_t (*blade_transport_send_callback_t)(blade_connection_t *bc, cJSON *json);
|
||||
typedef ks_status_t (*blade_transport_receive_callback_t)(blade_connection_t *bc, cJSON **json);
|
||||
typedef blade_connection_state_hook_t (*blade_transport_state_callback_t)(blade_connection_t *bc, blade_connection_state_condition_t condition);
|
||||
|
||||
struct blade_transport_callbacks_s {
|
||||
blade_transport_startup_callback_t onstartup;
|
||||
blade_transport_shutdown_callback_t onshutdown;
|
||||
|
||||
blade_transport_connect_callback_t onconnect;
|
||||
blade_transport_rank_callback_t onrank;
|
||||
|
||||
blade_transport_send_callback_t onsend;
|
||||
blade_transport_receive_callback_t onreceive;
|
||||
|
||||
blade_transport_state_callback_t onstate_disconnect_inbound;
|
||||
blade_transport_state_callback_t onstate_disconnect_outbound;
|
||||
blade_transport_state_callback_t onstate_new_inbound;
|
||||
blade_transport_state_callback_t onstate_new_outbound;
|
||||
blade_transport_state_callback_t onstate_connect_inbound;
|
||||
blade_transport_state_callback_t onstate_connect_outbound;
|
||||
blade_transport_state_callback_t onstate_attach_inbound;
|
||||
blade_transport_state_callback_t onstate_attach_outbound;
|
||||
blade_transport_state_callback_t onstate_detach_inbound;
|
||||
blade_transport_state_callback_t onstate_detach_outbound;
|
||||
blade_transport_state_callback_t onstate_ready_inbound;
|
||||
blade_transport_state_callback_t onstate_ready_outbound;
|
||||
blade_transport_state_callback_t onstate_startup_inbound;
|
||||
blade_transport_state_callback_t onstate_startup_outbound;
|
||||
blade_transport_state_callback_t onstate_shutdown_inbound;
|
||||
blade_transport_state_callback_t onstate_shutdown_outbound;
|
||||
blade_transport_state_callback_t onstate_run_inbound;
|
||||
blade_transport_state_callback_t onstate_run_outbound;
|
||||
};
|
||||
|
||||
typedef void (*blade_session_state_callback_t)(blade_session_t *bs, blade_session_state_condition_t condition, void *data);
|
||||
|
||||
|
||||
struct blade_request_s {
|
||||
blade_handle_t *handle;
|
||||
ks_pool_t *pool;
|
||||
const char *session_id;
|
||||
|
||||
cJSON *message;
|
||||
const char *message_id; // pulled from message for easier keying
|
||||
blade_response_callback_t callback;
|
||||
// @todo ttl to wait for response before injecting an error response locally
|
||||
// @todo rpc response callback
|
||||
};
|
||||
|
||||
struct blade_response_s {
|
||||
blade_handle_t *handle;
|
||||
ks_pool_t *pool;
|
||||
const char *session_id;
|
||||
blade_request_t *request;
|
||||
|
||||
cJSON *message;
|
||||
};
|
||||
|
||||
struct blade_event_s {
|
||||
blade_handle_t *handle;
|
||||
ks_pool_t *pool;
|
||||
const char *session_id;
|
||||
|
||||
cJSON *message;
|
||||
};
|
||||
|
||||
KS_END_EXTERN_C
|
||||
|
||||
#endif
|
||||
|
|
|
@ -0,0 +1,5 @@
|
|||
switchblade_SOURCES = switchblade.c
|
||||
switchblade_CFLAGS = $(AM_CFLAGS) -I$(abs_top_srcdir)/src/include -g -ggdb -O0
|
||||
switchblade_LDADD = $(abs_top_builddir)/libblade.la -lconfig -lm -lpthread
|
||||
|
||||
all: switchblade
|
|
@ -0,0 +1,73 @@
|
|||
#include "blade.h"
|
||||
|
||||
// @todo switch to wait condition once something is being done with the main thread during runtime
|
||||
ks_bool_t g_shutdown = KS_FALSE;
|
||||
|
||||
void idle(blade_handle_t *bh);
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
blade_handle_t *bh = NULL;
|
||||
config_t config;
|
||||
config_setting_t *config_blade = NULL;
|
||||
const char *cfgpath = "switchblade.cfg";
|
||||
|
||||
ks_global_set_default_logger(KS_LOG_LEVEL_DEBUG);
|
||||
|
||||
blade_init();
|
||||
|
||||
blade_handle_create(&bh);
|
||||
|
||||
config_init(&config);
|
||||
if (!config_read_file(&config, cfgpath)) {
|
||||
ks_log(KS_LOG_ERROR, "%s:%d - %s\n", config_error_file(&config), config_error_line(&config), config_error_text(&config));
|
||||
config_destroy(&config);
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
config_blade = config_lookup(&config, "blade");
|
||||
if (!config_blade) {
|
||||
ks_log(KS_LOG_ERROR, "Missing 'blade' config group\n");
|
||||
config_destroy(&config);
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
if (config_setting_type(config_blade) != CONFIG_TYPE_GROUP) {
|
||||
ks_log(KS_LOG_ERROR, "The 'blade' config setting is not a group\n");
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
if (blade_handle_startup(bh, config_blade) != KS_STATUS_SUCCESS) {
|
||||
ks_log(KS_LOG_ERROR, "Blade startup failed\n");
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
// @todo portable process signal handler (SIGINT, SIGHUP, etc)
|
||||
|
||||
idle(bh);
|
||||
|
||||
blade_handle_destroy(&bh);
|
||||
|
||||
config_destroy(&config);
|
||||
|
||||
blade_shutdown();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void idle(blade_handle_t *bh)
|
||||
{
|
||||
while (!g_shutdown) {
|
||||
ks_sleep_ms(1000);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* For Emacs:
|
||||
* Local Variables:
|
||||
* mode:c
|
||||
* indent-tabs-mode:t
|
||||
* tab-width:4
|
||||
* c-basic-offset:4
|
||||
* End:
|
||||
* For VIM:
|
||||
* vim:set softtabstop=4 shiftwidth=4 tabstop=4 noet:
|
||||
*/
|
|
@ -0,0 +1,18 @@
|
|||
blade:
|
||||
{
|
||||
identity = "master1@yourdomain.com";
|
||||
wss:
|
||||
{
|
||||
endpoints:
|
||||
{
|
||||
ipv4 = ( { address = "0.0.0.0", port = 2100 } );
|
||||
ipv6 = ( { address = "::", port = 2100 } );
|
||||
backlog = 128;
|
||||
};
|
||||
# SSL group is optional, disabled when absent
|
||||
ssl:
|
||||
{
|
||||
# todo: server SSL stuffs here
|
||||
};
|
||||
};
|
||||
};
|
|
@ -0,0 +1,214 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project DefaultTargets="Build" ToolsVersion="14.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<ItemGroup Label="ProjectConfigurations">
|
||||
<ProjectConfiguration Include="Debug|Win32">
|
||||
<Configuration>Debug</Configuration>
|
||||
<Platform>Win32</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="Release|Win32">
|
||||
<Configuration>Release</Configuration>
|
||||
<Platform>Win32</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="Debug|x64">
|
||||
<Configuration>Debug</Configuration>
|
||||
<Platform>x64</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="Release|x64">
|
||||
<Configuration>Release</Configuration>
|
||||
<Platform>x64</Platform>
|
||||
</ProjectConfiguration>
|
||||
</ItemGroup>
|
||||
<PropertyGroup Label="Globals">
|
||||
<ProjectGuid>{8330E669-77F3-4F70-A275-6F7BABE050A7}</ProjectGuid>
|
||||
<Keyword>Win32Proj</Keyword>
|
||||
<RootNamespace>switchblade</RootNamespace>
|
||||
<WindowsTargetPlatformVersion>8.1</WindowsTargetPlatformVersion>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>true</UseDebugLibraries>
|
||||
<PlatformToolset>v140</PlatformToolset>
|
||||
<CharacterSet>Unicode</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>false</UseDebugLibraries>
|
||||
<PlatformToolset>v140</PlatformToolset>
|
||||
<WholeProgramOptimization>true</WholeProgramOptimization>
|
||||
<CharacterSet>Unicode</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>true</UseDebugLibraries>
|
||||
<PlatformToolset>v140</PlatformToolset>
|
||||
<CharacterSet>Unicode</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>false</UseDebugLibraries>
|
||||
<PlatformToolset>v140</PlatformToolset>
|
||||
<WholeProgramOptimization>true</WholeProgramOptimization>
|
||||
<CharacterSet>Unicode</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
|
||||
<ImportGroup Label="ExtensionSettings">
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="Shared">
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
<Import Project="..\..\..\w32\openssl-version.props" />
|
||||
<Import Project="..\..\..\w32\sodium.props" />
|
||||
<Import Project="..\..\..\w32\config.props" />
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
<Import Project="..\..\..\w32\openssl-version.props" />
|
||||
<Import Project="..\..\..\w32\sodium.props" />
|
||||
<Import Project="..\..\..\w32\config.props" />
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
<Import Project="..\..\..\w32\openssl-version.props" />
|
||||
<Import Project="..\..\..\w32\sodium.props" />
|
||||
<Import Project="..\..\..\w32\config.props" />
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
<Import Project="..\..\..\w32\openssl-version.props" />
|
||||
<Import Project="..\..\..\w32\sodium.props" />
|
||||
<Import Project="..\..\..\w32\config.props" />
|
||||
</ImportGroup>
|
||||
<PropertyGroup Label="UserMacros" />
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||
<LinkIncremental>true</LinkIncremental>
|
||||
<IntDir>$(Platform)\$(Configuration)\$(ProjectName)\</IntDir>
|
||||
<OutDir>$(SolutionDir)$(Platform)\$(Configuration)\</OutDir>
|
||||
<IncludePath>$(SolutionDir);$(SolutionDir)..\libks\src\include;$(SolutionDir)..\libsodium-$(SodiumVersion)\src\libsodium\include;$(SolutionDir)..\libconfig-$(ConfigVersion)\lib;$(SolutionDir)\openssl\include;$(IncludePath)</IncludePath>
|
||||
<LibraryPath>$(LibraryPath)</LibraryPath>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||
<LinkIncremental>true</LinkIncremental>
|
||||
<IntDir>$(Platform)\$(Configuration)\$(ProjectName)\</IntDir>
|
||||
<IncludePath>$(SolutionDir);$(SolutionDir)..\libks\src\include;$(SolutionDir)..\libsodium-$(SodiumVersion)\src\libsodium\include;$(SolutionDir)..\libconfig-$(ConfigVersion)\lib;$(SolutionDir)\openssl\include64;$(IncludePath)</IncludePath>
|
||||
<LibraryPath>$(LibraryPath)</LibraryPath>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||
<LinkIncremental>false</LinkIncremental>
|
||||
<IntDir>$(Platform)\$(Configuration)\$(ProjectName)\</IntDir>
|
||||
<OutDir>$(SolutionDir)$(Platform)\$(Configuration)\</OutDir>
|
||||
<IncludePath>$(SolutionDir);$(SolutionDir)..\libks\src\include;$(SolutionDir)..\libsodium-$(SodiumVersion)\src\libsodium\include;$(SolutionDir)..\libconfig-$(ConfigVersion)\lib;$(SolutionDir)\openssl\include;$(IncludePath)</IncludePath>
|
||||
<LibraryPath>$(LibraryPath)</LibraryPath>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
||||
<LinkIncremental>false</LinkIncremental>
|
||||
<IntDir>$(Platform)\$(Configuration)\$(ProjectName)\</IntDir>
|
||||
<IncludePath>$(SolutionDir);$(SolutionDir)..\libks\src\include;$(SolutionDir)..\libsodium-$(SodiumVersion)\src\libsodium\include;$(SolutionDir)..\libconfig-$(ConfigVersion)\lib;$(SolutionDir)\openssl\include64;$(IncludePath)</IncludePath>
|
||||
<LibraryPath>$(LibraryPath)</LibraryPath>
|
||||
</PropertyGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||
<ClCompile>
|
||||
<PrecompiledHeader>
|
||||
</PrecompiledHeader>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<Optimization>Disabled</Optimization>
|
||||
<PreprocessorDefinitions>_CRT_SECURE_NO_WARNINGS;WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<SDLCheck>true</SDLCheck>
|
||||
<AdditionalIncludeDirectories>$(SolutionDir)..\win32\openssl\include;$(SolutionDir)..\win32\openssl\include_x86;../src/include;.</AdditionalIncludeDirectories>
|
||||
<DisableSpecificWarnings>4090</DisableSpecificWarnings>
|
||||
<MultiProcessorCompilation>true</MultiProcessorCompilation>
|
||||
<MinimalRebuild>false</MinimalRebuild>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<SubSystem>Console</SubSystem>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||
<ClCompile>
|
||||
<PrecompiledHeader>
|
||||
</PrecompiledHeader>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<Optimization>Disabled</Optimization>
|
||||
<PreprocessorDefinitions>_CRT_SECURE_NO_WARNINGS;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<SDLCheck>true</SDLCheck>
|
||||
<AdditionalIncludeDirectories>$(SolutionDir)..\win32\openssl\include;$(SolutionDir)..\win32\openssl\include_x64;../src/include;.</AdditionalIncludeDirectories>
|
||||
<DisableSpecificWarnings>4090</DisableSpecificWarnings>
|
||||
<MultiProcessorCompilation>true</MultiProcessorCompilation>
|
||||
<MinimalRebuild>false</MinimalRebuild>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<SubSystem>Console</SubSystem>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||
<ClCompile>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<PrecompiledHeader>
|
||||
</PrecompiledHeader>
|
||||
<Optimization>MaxSpeed</Optimization>
|
||||
<FunctionLevelLinking>true</FunctionLevelLinking>
|
||||
<IntrinsicFunctions>true</IntrinsicFunctions>
|
||||
<PreprocessorDefinitions>_CRT_SECURE_NO_WARNINGS;WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<SDLCheck>true</SDLCheck>
|
||||
<AdditionalIncludeDirectories>$(SolutionDir)..\win32\openssl\include;$(SolutionDir)..\win32\openssl\include_x86;../src/include;.</AdditionalIncludeDirectories>
|
||||
<DisableSpecificWarnings>4090</DisableSpecificWarnings>
|
||||
<MultiProcessorCompilation>true</MultiProcessorCompilation>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<SubSystem>Console</SubSystem>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
<EnableCOMDATFolding>true</EnableCOMDATFolding>
|
||||
<OptimizeReferences>true</OptimizeReferences>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
||||
<ClCompile>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<PrecompiledHeader>
|
||||
</PrecompiledHeader>
|
||||
<Optimization>MaxSpeed</Optimization>
|
||||
<FunctionLevelLinking>true</FunctionLevelLinking>
|
||||
<IntrinsicFunctions>true</IntrinsicFunctions>
|
||||
<PreprocessorDefinitions>_CRT_SECURE_NO_WARNINGS;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<SDLCheck>true</SDLCheck>
|
||||
<AdditionalIncludeDirectories>$(SolutionDir)..\win32\openssl\include;$(SolutionDir)..\win32\openssl\include_x64;../src/include;.</AdditionalIncludeDirectories>
|
||||
<DisableSpecificWarnings>4090</DisableSpecificWarnings>
|
||||
<MultiProcessorCompilation>true</MultiProcessorCompilation>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<SubSystem>Console</SubSystem>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
<EnableCOMDATFolding>true</EnableCOMDATFolding>
|
||||
<OptimizeReferences>true</OptimizeReferences>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="switchblade.c" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\..\libks\libks.vcxproj">
|
||||
<Project>{70d178d8-1100-4152-86c0-809a91cff832}</Project>
|
||||
</ProjectReference>
|
||||
<ProjectReference Include="..\..\win32\libconfig\libconfig.2015.vcxproj">
|
||||
<Project>{1a234565-926d-49b2-83e4-d56e0c38c9f2}</Project>
|
||||
</ProjectReference>
|
||||
<ProjectReference Include="..\..\win32\libsodium\libsodium.2015.vcxproj">
|
||||
<Project>{a185b162-6cb6-4502-b03f-b56f7699a8d9}</Project>
|
||||
</ProjectReference>
|
||||
<ProjectReference Include="..\..\win32\openssl\libeay32.2015.vcxproj">
|
||||
<Project>{d331904d-a00a-4694-a5a3-fcff64ab5dbe}</Project>
|
||||
</ProjectReference>
|
||||
<ProjectReference Include="..\..\win32\openssl\ssleay32.2015.vcxproj">
|
||||
<Project>{b4b62169-5ad4-4559-8707-3d933ac5db39}</Project>
|
||||
</ProjectReference>
|
||||
<ProjectReference Include="..\libblade.vcxproj">
|
||||
<Project>{a89d6d18-6203-4149-9051-f8e798e7a3e7}</Project>
|
||||
</ProjectReference>
|
||||
</ItemGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
||||
<ImportGroup Label="ExtensionTargets">
|
||||
</ImportGroup>
|
||||
</Project>
|
|
@ -17,19 +17,19 @@ struct command_def_s {
|
|||
|
||||
void command_quit(blade_handle_t *bh, char *args);
|
||||
void command_connect(blade_handle_t *bh, char *args);
|
||||
void command_chat(blade_handle_t *bh, char *args);
|
||||
//void command_chat(blade_handle_t *bh, char *args);
|
||||
|
||||
static const struct command_def_s command_defs[] = {
|
||||
{ "quit", command_quit },
|
||||
{ "connect", command_connect },
|
||||
{ "chat", command_chat },
|
||||
// { "chat", command_chat },
|
||||
|
||||
{ NULL, NULL }
|
||||
};
|
||||
|
||||
ks_bool_t on_blade_chat_join_response(blade_response_t *bres);
|
||||
ks_bool_t on_blade_chat_message_event(blade_event_t *bev);
|
||||
void on_blade_session_state_callback(blade_session_t *bs, blade_session_state_condition_t condition, void *data);
|
||||
//ks_bool_t on_blade_chat_join_response(blade_response_t *bres);
|
||||
//ks_bool_t on_blade_chat_message_event(blade_event_t *bev);
|
||||
//void on_blade_session_state_callback(blade_session_t *bs, blade_session_state_condition_t condition, void *data);
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
|
@ -71,8 +71,8 @@ int main(int argc, char **argv)
|
|||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
blade_handle_event_register(bh, "blade.chat.message", on_blade_chat_message_event);
|
||||
blade_handle_session_state_callback_register(bh, NULL, on_blade_session_state_callback, &session_state_callback_id);
|
||||
//blade_handle_event_register(bh, "blade.chat.message", on_blade_chat_message_event);
|
||||
//blade_handle_session_state_callback_register(bh, NULL, on_blade_session_state_callback, &session_state_callback_id);
|
||||
|
||||
if (autoconnect) {
|
||||
blade_connection_t *bc = NULL;
|
||||
|
@ -84,7 +84,7 @@ int main(int argc, char **argv)
|
|||
|
||||
blade_identity_destroy(&target);
|
||||
|
||||
ks_sleep_ms(2000);
|
||||
ks_sleep_ms(5000);
|
||||
} else loop(bh);
|
||||
|
||||
//blade_handle_session_state_callback_unregister(bh, session_state_callback_id);
|
||||
|
@ -98,37 +98,37 @@ int main(int argc, char **argv)
|
|||
return 0;
|
||||
}
|
||||
|
||||
ks_bool_t on_blade_chat_message_event(blade_event_t *bev)
|
||||
{
|
||||
cJSON *res = NULL;
|
||||
const char *from = NULL;
|
||||
const char *message = NULL;
|
||||
|
||||
ks_assert(bev);
|
||||
|
||||
res = cJSON_GetObjectItem(bev->message, "result");
|
||||
from = cJSON_GetObjectCstr(res, "from");
|
||||
message = cJSON_GetObjectCstr(res, "message");
|
||||
|
||||
ks_log(KS_LOG_DEBUG, "Received Chat Message Event: (%s) %s\n", from, message);
|
||||
|
||||
return KS_FALSE;
|
||||
}
|
||||
|
||||
void on_blade_session_state_callback(blade_session_t *bs, blade_session_state_condition_t condition, void *data)
|
||||
{
|
||||
blade_session_state_t state = blade_session_state_get(bs);
|
||||
|
||||
if (condition == BLADE_SESSION_STATE_CONDITION_PRE) {
|
||||
ks_log(KS_LOG_DEBUG, "Blade Session State Changed: %s, %d\n", blade_session_id_get(bs), state);
|
||||
if (state == BLADE_SESSION_STATE_READY) {
|
||||
cJSON *req = NULL;
|
||||
blade_rpc_request_create(blade_handle_pool_get(blade_session_handle_get(bs)), &req, NULL, NULL, "blade.chat.join");
|
||||
blade_session_send(bs, req, on_blade_chat_join_response);
|
||||
cJSON_Delete(req);
|
||||
}
|
||||
}
|
||||
}
|
||||
//ks_bool_t on_blade_chat_message_event(blade_event_t *bev)
|
||||
//{
|
||||
// cJSON *res = NULL;
|
||||
// const char *from = NULL;
|
||||
// const char *message = NULL;
|
||||
//
|
||||
// ks_assert(bev);
|
||||
//
|
||||
// res = cJSON_GetObjectItem(bev->message, "result");
|
||||
// from = cJSON_GetObjectCstr(res, "from");
|
||||
// message = cJSON_GetObjectCstr(res, "message");
|
||||
//
|
||||
// ks_log(KS_LOG_DEBUG, "Received Chat Message Event: (%s) %s\n", from, message);
|
||||
//
|
||||
// return KS_FALSE;
|
||||
//}
|
||||
//
|
||||
//void on_blade_session_state_callback(blade_session_t *bs, blade_session_state_condition_t condition, void *data)
|
||||
//{
|
||||
// blade_session_state_t state = blade_session_state_get(bs);
|
||||
//
|
||||
// if (condition == BLADE_SESSION_STATE_CONDITION_PRE) {
|
||||
// ks_log(KS_LOG_DEBUG, "Blade Session State Changed: %s, %d\n", blade_session_id_get(bs), state);
|
||||
// if (state == BLADE_SESSION_STATE_READY) {
|
||||
// cJSON *req = NULL;
|
||||
// blade_jsonrpc_request_raw_create(blade_handle_pool_get(blade_session_handle_get(bs)), &req, NULL, NULL, "blade.chat.join");
|
||||
// blade_session_send(bs, req, on_blade_chat_join_response);
|
||||
// cJSON_Delete(req);
|
||||
// }
|
||||
// }
|
||||
//}
|
||||
|
||||
void loop(blade_handle_t *bh)
|
||||
{
|
||||
|
@ -210,77 +210,77 @@ void command_connect(blade_handle_t *bh, char *args)
|
|||
blade_identity_destroy(&target);
|
||||
}
|
||||
|
||||
ks_bool_t on_blade_chat_send_response(blade_response_t *bres);
|
||||
|
||||
ks_bool_t on_blade_chat_join_response(blade_response_t *bres) // @todo this should get userdata passed in from when the callback is registered
|
||||
{
|
||||
blade_session_t *bs = NULL;
|
||||
cJSON *req = NULL;
|
||||
cJSON *params = NULL;
|
||||
|
||||
ks_log(KS_LOG_DEBUG, "Received Chat Join Response!\n");
|
||||
|
||||
bs = blade_handle_sessions_get(bres->handle, bres->session_id);
|
||||
if (!bs) {
|
||||
ks_log(KS_LOG_DEBUG, "Unknown Session: %s\n", bres->session_id);
|
||||
return KS_FALSE;
|
||||
}
|
||||
|
||||
blade_rpc_request_create(blade_handle_pool_get(bres->handle), &req, ¶ms, NULL, "blade.chat.send");
|
||||
ks_assert(req);
|
||||
ks_assert(params);
|
||||
|
||||
cJSON_AddStringToObject(params, "message", "Hello World!");
|
||||
|
||||
blade_session_send(bs, req, on_blade_chat_send_response);
|
||||
|
||||
blade_session_read_unlock(bs);
|
||||
|
||||
return KS_FALSE;
|
||||
}
|
||||
|
||||
ks_bool_t on_blade_chat_send_response(blade_response_t *bres) // @todo this should get userdata passed in from when the callback is registered
|
||||
{
|
||||
ks_log(KS_LOG_DEBUG, "Received Chat Send Response!\n");
|
||||
return KS_FALSE;
|
||||
}
|
||||
|
||||
void command_chat(blade_handle_t *bh, char *args)
|
||||
{
|
||||
char *cmd = NULL;
|
||||
|
||||
ks_assert(bh);
|
||||
ks_assert(args);
|
||||
|
||||
parse_argument(&args, &cmd, ' ');
|
||||
ks_log(KS_LOG_DEBUG, "Chat Command: %s, Args: %s\n", cmd, args);
|
||||
|
||||
if (!strcmp(cmd, "leave")) {
|
||||
} else if (!strcmp(cmd, "send")) {
|
||||
char *sid = NULL;
|
||||
blade_session_t *bs = NULL;
|
||||
cJSON *req = NULL;
|
||||
cJSON *params = NULL;
|
||||
|
||||
parse_argument(&args, &sid, ' ');
|
||||
|
||||
bs = blade_handle_sessions_get(bh, sid);
|
||||
if (!bs) {
|
||||
ks_log(KS_LOG_DEBUG, "Unknown Session: %s\n", sid);
|
||||
return;
|
||||
}
|
||||
blade_rpc_request_create(blade_handle_pool_get(bh), &req, ¶ms, NULL, "blade.chat.send");
|
||||
ks_assert(req);
|
||||
ks_assert(params);
|
||||
|
||||
cJSON_AddStringToObject(params, "message", args);
|
||||
|
||||
blade_session_send(bs, req, on_blade_chat_send_response);
|
||||
|
||||
blade_session_read_unlock(bs);
|
||||
|
||||
cJSON_Delete(req);
|
||||
} else {
|
||||
ks_log(KS_LOG_DEBUG, "Unknown Chat Command: %s\n", cmd);
|
||||
}
|
||||
}
|
||||
//ks_bool_t on_blade_chat_send_response(blade_response_t *bres);
|
||||
//
|
||||
//ks_bool_t on_blade_chat_join_response(blade_response_t *bres) // @todo this should get userdata passed in from when the callback is registered
|
||||
//{
|
||||
// blade_session_t *bs = NULL;
|
||||
// cJSON *req = NULL;
|
||||
// cJSON *params = NULL;
|
||||
//
|
||||
// ks_log(KS_LOG_DEBUG, "Received Chat Join Response!\n");
|
||||
//
|
||||
// bs = blade_handle_sessions_get(bres->handle, bres->session_id);
|
||||
// if (!bs) {
|
||||
// ks_log(KS_LOG_DEBUG, "Unknown Session: %s\n", bres->session_id);
|
||||
// return KS_FALSE;
|
||||
// }
|
||||
//
|
||||
// blade_jsonrpc_request_raw_create(blade_handle_pool_get(bres->handle), &req, ¶ms, NULL, "blade.chat.send");
|
||||
// ks_assert(req);
|
||||
// ks_assert(params);
|
||||
//
|
||||
// cJSON_AddStringToObject(params, "message", "Hello World!");
|
||||
//
|
||||
// blade_session_send(bs, req, on_blade_chat_send_response);
|
||||
//
|
||||
// blade_session_read_unlock(bs);
|
||||
//
|
||||
// return KS_FALSE;
|
||||
//}
|
||||
//
|
||||
//ks_bool_t on_blade_chat_send_response(blade_response_t *bres) // @todo this should get userdata passed in from when the callback is registered
|
||||
//{
|
||||
// ks_log(KS_LOG_DEBUG, "Received Chat Send Response!\n");
|
||||
// return KS_FALSE;
|
||||
//}
|
||||
//
|
||||
//void command_chat(blade_handle_t *bh, char *args)
|
||||
//{
|
||||
// char *cmd = NULL;
|
||||
//
|
||||
// ks_assert(bh);
|
||||
// ks_assert(args);
|
||||
//
|
||||
// parse_argument(&args, &cmd, ' ');
|
||||
// ks_log(KS_LOG_DEBUG, "Chat Command: %s, Args: %s\n", cmd, args);
|
||||
//
|
||||
// if (!strcmp(cmd, "leave")) {
|
||||
// } else if (!strcmp(cmd, "send")) {
|
||||
// char *sid = NULL;
|
||||
// blade_session_t *bs = NULL;
|
||||
// cJSON *req = NULL;
|
||||
// cJSON *params = NULL;
|
||||
//
|
||||
// parse_argument(&args, &sid, ' ');
|
||||
//
|
||||
// bs = blade_handle_sessions_get(bh, sid);
|
||||
// if (!bs) {
|
||||
// ks_log(KS_LOG_DEBUG, "Unknown Session: %s\n", sid);
|
||||
// return;
|
||||
// }
|
||||
// blade_jsonrpc_request_raw_create(blade_handle_pool_get(bh), &req, ¶ms, NULL, "blade.chat.send");
|
||||
// ks_assert(req);
|
||||
// ks_assert(params);
|
||||
//
|
||||
// cJSON_AddStringToObject(params, "message", args);
|
||||
//
|
||||
// blade_session_send(bs, req, on_blade_chat_send_response);
|
||||
//
|
||||
// blade_session_read_unlock(bs);
|
||||
//
|
||||
// cJSON_Delete(req);
|
||||
// } else {
|
||||
// ks_log(KS_LOG_DEBUG, "Unknown Chat Command: %s\n", cmd);
|
||||
// }
|
||||
//}
|
||||
|
|
|
@ -1,11 +1,3 @@
|
|||
blade:
|
||||
{
|
||||
identity = "peer@domain";
|
||||
datastore:
|
||||
{
|
||||
database:
|
||||
{
|
||||
path = ":mem:";
|
||||
};
|
||||
};
|
||||
};
|
||||
|
|
|
@ -25,34 +25,34 @@ static const struct command_def_s command_defs[] = {
|
|||
|
||||
|
||||
|
||||
ks_status_t blade_module_chat_create(blade_module_t **bmP, blade_handle_t *bh);
|
||||
ks_status_t blade_module_chat_on_startup(blade_module_t *bm, config_setting_t *config);
|
||||
ks_status_t blade_module_chat_on_shutdown(blade_module_t *bm);
|
||||
|
||||
typedef struct blade_module_chat_s blade_module_chat_t;
|
||||
struct blade_module_chat_s {
|
||||
blade_handle_t *handle;
|
||||
ks_pool_t *pool;
|
||||
ks_thread_pool_t *tpool;
|
||||
blade_module_t *module;
|
||||
//blade_module_callbacks_t *module_callbacks;
|
||||
|
||||
blade_space_t *blade_chat_space;
|
||||
const char *session_state_callback_id;
|
||||
ks_list_t *participants;
|
||||
};
|
||||
|
||||
void blade_module_chat_on_session_state(blade_session_t *bs, blade_session_state_condition_t condition, void *data);
|
||||
|
||||
ks_bool_t blade_chat_join_request_handler(blade_module_t *bm, blade_request_t *breq);
|
||||
ks_bool_t blade_chat_leave_request_handler(blade_module_t *bm, blade_request_t *breq);
|
||||
ks_bool_t blade_chat_send_request_handler(blade_module_t *bm, blade_request_t *breq);
|
||||
|
||||
static blade_module_callbacks_t g_module_chat_callbacks =
|
||||
{
|
||||
blade_module_chat_on_startup,
|
||||
blade_module_chat_on_shutdown,
|
||||
};
|
||||
//ks_status_t blade_module_chat_create(blade_module_t **bmP, blade_handle_t *bh);
|
||||
//ks_status_t blade_module_chat_on_startup(blade_module_t *bm, config_setting_t *config);
|
||||
//ks_status_t blade_module_chat_on_shutdown(blade_module_t *bm);
|
||||
//
|
||||
//typedef struct blade_module_chat_s blade_module_chat_t;
|
||||
//struct blade_module_chat_s {
|
||||
// blade_handle_t *handle;
|
||||
// ks_pool_t *pool;
|
||||
// ks_thread_pool_t *tpool;
|
||||
// blade_module_t *module;
|
||||
// //blade_module_callbacks_t *module_callbacks;
|
||||
//
|
||||
// blade_space_t *blade_chat_space;
|
||||
// const char *session_state_callback_id;
|
||||
// ks_list_t *participants;
|
||||
//};
|
||||
//
|
||||
//void blade_module_chat_on_session_state(blade_session_t *bs, blade_session_state_condition_t condition, void *data);
|
||||
//
|
||||
//ks_bool_t blade_chat_join_request_handler(blade_module_t *bm, blade_request_t *breq);
|
||||
//ks_bool_t blade_chat_leave_request_handler(blade_module_t *bm, blade_request_t *breq);
|
||||
//ks_bool_t blade_chat_send_request_handler(blade_module_t *bm, blade_request_t *breq);
|
||||
//
|
||||
//static blade_module_callbacks_t g_module_chat_callbacks =
|
||||
//{
|
||||
// blade_module_chat_on_startup,
|
||||
// blade_module_chat_on_shutdown,
|
||||
//};
|
||||
|
||||
|
||||
int main(int argc, char **argv)
|
||||
|
@ -60,7 +60,7 @@ int main(int argc, char **argv)
|
|||
blade_handle_t *bh = NULL;
|
||||
config_t config;
|
||||
config_setting_t *config_blade = NULL;
|
||||
blade_module_t *mod_chat = NULL;
|
||||
//blade_module_t *mod_chat = NULL;
|
||||
//blade_identity_t *id = NULL;
|
||||
const char *cfgpath = "blades.cfg";
|
||||
|
||||
|
@ -90,8 +90,8 @@ int main(int argc, char **argv)
|
|||
}
|
||||
|
||||
// must occur before startup
|
||||
blade_module_chat_create(&mod_chat, bh);
|
||||
blade_handle_module_register(mod_chat);
|
||||
//blade_module_chat_create(&mod_chat, bh);
|
||||
//blade_handle_module_register(mod_chat);
|
||||
|
||||
if (blade_handle_startup(bh, config_blade) != KS_STATUS_SUCCESS) {
|
||||
ks_log(KS_LOG_ERROR, "Blade startup failed\n");
|
||||
|
@ -177,328 +177,328 @@ void command_quit(blade_handle_t *bh, char *args)
|
|||
|
||||
|
||||
|
||||
static void blade_module_chat_cleanup(ks_pool_t *pool, void *ptr, void *arg, ks_pool_cleanup_action_t action, ks_pool_cleanup_type_t type)
|
||||
{
|
||||
blade_module_chat_t *bm_chat = (blade_module_chat_t *)ptr;
|
||||
|
||||
ks_assert(bm_chat);
|
||||
|
||||
switch (action) {
|
||||
case KS_MPCL_ANNOUNCE:
|
||||
break;
|
||||
case KS_MPCL_TEARDOWN:
|
||||
break;
|
||||
case KS_MPCL_DESTROY:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
ks_status_t blade_module_chat_create(blade_module_t **bmP, blade_handle_t *bh)
|
||||
{
|
||||
blade_module_chat_t *bm_chat = NULL;
|
||||
ks_pool_t *pool = NULL;
|
||||
|
||||
ks_assert(bmP);
|
||||
ks_assert(bh);
|
||||
|
||||
ks_pool_open(&pool);
|
||||
ks_assert(pool);
|
||||
|
||||
bm_chat = ks_pool_alloc(pool, sizeof(blade_module_chat_t));
|
||||
bm_chat->handle = bh;
|
||||
bm_chat->pool = pool;
|
||||
bm_chat->tpool = blade_handle_tpool_get(bh);
|
||||
bm_chat->session_state_callback_id = NULL;
|
||||
|
||||
ks_list_create(&bm_chat->participants, pool);
|
||||
ks_assert(bm_chat->participants);
|
||||
|
||||
blade_module_create(&bm_chat->module, bh, pool, bm_chat, &g_module_chat_callbacks);
|
||||
ks_assert(bm_chat->module);
|
||||
|
||||
ks_pool_set_cleanup(pool, bm_chat, NULL, blade_module_chat_cleanup);
|
||||
|
||||
ks_log(KS_LOG_DEBUG, "Created\n");
|
||||
|
||||
*bmP = bm_chat->module;
|
||||
|
||||
return KS_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
ks_status_t blade_module_chat_config(blade_module_chat_t *bm_chat, config_setting_t *config)
|
||||
{
|
||||
config_setting_t *chat = NULL;
|
||||
|
||||
ks_assert(bm_chat);
|
||||
ks_assert(config);
|
||||
|
||||
if (!config_setting_is_group(config)) {
|
||||
ks_log(KS_LOG_DEBUG, "!config_setting_is_group(config)\n");
|
||||
return KS_STATUS_FAIL;
|
||||
}
|
||||
|
||||
chat = config_setting_get_member(config, "chat");
|
||||
if (chat) {
|
||||
}
|
||||
|
||||
|
||||
// Configuration is valid, now assign it to the variables that are used
|
||||
// If the configuration was invalid, then this does not get changed
|
||||
|
||||
ks_log(KS_LOG_DEBUG, "Configured\n");
|
||||
|
||||
return KS_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
ks_status_t blade_module_chat_on_startup(blade_module_t *bm, config_setting_t *config)
|
||||
{
|
||||
blade_module_chat_t *bm_chat = NULL;
|
||||
blade_space_t *space = NULL;
|
||||
blade_method_t *method = NULL;
|
||||
|
||||
ks_assert(bm);
|
||||
ks_assert(config);
|
||||
|
||||
bm_chat = (blade_module_chat_t *)blade_module_data_get(bm);
|
||||
|
||||
if (blade_module_chat_config(bm_chat, config) != KS_STATUS_SUCCESS) {
|
||||
ks_log(KS_LOG_DEBUG, "blade_module_chat_config failed\n");
|
||||
return KS_STATUS_FAIL;
|
||||
}
|
||||
|
||||
blade_space_create(&space, bm_chat->handle, bm, "blade.chat");
|
||||
ks_assert(space);
|
||||
|
||||
bm_chat->blade_chat_space = space;
|
||||
|
||||
blade_method_create(&method, space, "join", blade_chat_join_request_handler);
|
||||
ks_assert(method);
|
||||
blade_space_methods_add(space, method);
|
||||
|
||||
blade_method_create(&method, space, "leave", blade_chat_leave_request_handler);
|
||||
ks_assert(method);
|
||||
blade_space_methods_add(space, method);
|
||||
|
||||
blade_method_create(&method, space, "send", blade_chat_send_request_handler);
|
||||
ks_assert(method);
|
||||
blade_space_methods_add(space, method);
|
||||
|
||||
blade_handle_space_register(space);
|
||||
|
||||
blade_handle_session_state_callback_register(blade_module_handle_get(bm), bm, blade_module_chat_on_session_state, &bm_chat->session_state_callback_id);
|
||||
|
||||
ks_log(KS_LOG_DEBUG, "Started\n");
|
||||
|
||||
return KS_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
ks_status_t blade_module_chat_on_shutdown(blade_module_t *bm)
|
||||
{
|
||||
blade_module_chat_t *bm_chat = NULL;
|
||||
|
||||
ks_assert(bm);
|
||||
|
||||
bm_chat = (blade_module_chat_t *)blade_module_data_get(bm);
|
||||
ks_assert(bm_chat);
|
||||
|
||||
if (bm_chat->session_state_callback_id) blade_handle_session_state_callback_unregister(blade_module_handle_get(bm), bm_chat->session_state_callback_id);
|
||||
bm_chat->session_state_callback_id = NULL;
|
||||
|
||||
if (bm_chat->blade_chat_space) blade_handle_space_unregister(bm_chat->blade_chat_space);
|
||||
|
||||
ks_log(KS_LOG_DEBUG, "Stopped\n");
|
||||
|
||||
return KS_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
void blade_module_chat_on_session_state(blade_session_t *bs, blade_session_state_condition_t condition, void *data)
|
||||
{
|
||||
blade_module_t *bm = NULL;
|
||||
blade_module_chat_t *bm_chat = NULL;
|
||||
|
||||
ks_assert(bs);
|
||||
ks_assert(data);
|
||||
|
||||
bm = (blade_module_t *)data;
|
||||
bm_chat = (blade_module_chat_t *)blade_module_data_get(bm);
|
||||
ks_assert(bm_chat);
|
||||
|
||||
if (blade_session_state_get(bs) == BLADE_SESSION_STATE_HANGUP && condition == BLADE_SESSION_STATE_CONDITION_PRE) {
|
||||
cJSON *props = NULL;
|
||||
|
||||
ks_log(KS_LOG_DEBUG, "Removing session from chat participants if present\n");
|
||||
|
||||
props = blade_session_properties_get(bs);
|
||||
ks_assert(props);
|
||||
|
||||
cJSON_DeleteItemFromObject(props, "blade.chat.participant");
|
||||
|
||||
ks_list_delete(bm_chat->participants, blade_session_id_get(bs)); // @todo make copy of session id instead and search manually, also free the id
|
||||
}
|
||||
}
|
||||
|
||||
ks_bool_t blade_chat_join_request_handler(blade_module_t *bm, blade_request_t *breq)
|
||||
{
|
||||
blade_module_chat_t *bm_chat = NULL;
|
||||
blade_session_t *bs = NULL;
|
||||
cJSON *res = NULL;
|
||||
cJSON *props = NULL;
|
||||
cJSON *props_participant = NULL;
|
||||
|
||||
ks_assert(bm);
|
||||
ks_assert(breq);
|
||||
|
||||
ks_log(KS_LOG_DEBUG, "Request Received!\n");
|
||||
|
||||
bm_chat = (blade_module_chat_t *)blade_module_data_get(bm);
|
||||
ks_assert(bm_chat);
|
||||
|
||||
bs = blade_handle_sessions_get(breq->handle, breq->session_id);
|
||||
ks_assert(bs);
|
||||
|
||||
// @todo properties only used to demonstrate a flexible container for session data, should just rely on the participants list/hash
|
||||
blade_session_properties_write_lock(bs, KS_TRUE);
|
||||
|
||||
props = blade_session_properties_get(bs);
|
||||
ks_assert(props);
|
||||
|
||||
props_participant = cJSON_GetObjectItem(props, "blade.chat.participant");
|
||||
if (props_participant && props_participant->type == cJSON_True) {
|
||||
ks_log(KS_LOG_DEBUG, "Session (%s) attempted to join chat but is already a participant\n", blade_session_id_get(bs));
|
||||
blade_rpc_error_create(&res, NULL, breq->message_id, -10000, "Already a participant of chat");
|
||||
}
|
||||
else {
|
||||
ks_log(KS_LOG_DEBUG, "Session (%s) joined chat\n", blade_session_id_get(bs));
|
||||
|
||||
if (props_participant) props_participant->type = cJSON_True;
|
||||
else cJSON_AddTrueToObject(props, "blade.chat.participant");
|
||||
|
||||
ks_list_append(bm_chat->participants, blade_session_id_get(bs)); // @todo make copy of session id instead and cleanup when removed
|
||||
|
||||
blade_rpc_response_create(&res, NULL, breq->message_id);
|
||||
|
||||
// @todo create an event to send to participants when a session joins and leaves, send after main response though
|
||||
}
|
||||
|
||||
blade_session_properties_write_unlock(bs);
|
||||
|
||||
blade_session_send(bs, res, NULL);
|
||||
|
||||
blade_session_read_unlock(bs);
|
||||
|
||||
cJSON_Delete(res);
|
||||
|
||||
return KS_FALSE;
|
||||
}
|
||||
|
||||
ks_bool_t blade_chat_leave_request_handler(blade_module_t *bm, blade_request_t *breq)
|
||||
{
|
||||
blade_module_chat_t *bm_chat = NULL;
|
||||
blade_session_t *bs = NULL;
|
||||
cJSON *res = NULL;
|
||||
cJSON *props = NULL;
|
||||
cJSON *props_participant = NULL;
|
||||
|
||||
ks_assert(bm);
|
||||
ks_assert(breq);
|
||||
|
||||
ks_log(KS_LOG_DEBUG, "Request Received!\n");
|
||||
|
||||
bm_chat = (blade_module_chat_t *)blade_module_data_get(bm);
|
||||
ks_assert(bm_chat);
|
||||
|
||||
bs = blade_handle_sessions_get(breq->handle, breq->session_id);
|
||||
ks_assert(bs);
|
||||
|
||||
blade_session_properties_write_lock(bs, KS_TRUE);
|
||||
|
||||
props = blade_session_properties_get(bs);
|
||||
ks_assert(props);
|
||||
|
||||
props_participant = cJSON_GetObjectItem(props, "blade.chat.participant");
|
||||
if (!props_participant || props_participant->type == cJSON_False) {
|
||||
ks_log(KS_LOG_DEBUG, "Session (%s) attempted to leave chat but is not a participant\n", blade_session_id_get(bs));
|
||||
blade_rpc_error_create(&res, NULL, breq->message_id, -10000, "Not a participant of chat");
|
||||
}
|
||||
else {
|
||||
ks_log(KS_LOG_DEBUG, "Session (%s) left chat\n", blade_session_id_get(bs));
|
||||
|
||||
cJSON_DeleteItemFromObject(props, "blade.chat.participant");
|
||||
|
||||
ks_list_delete(bm_chat->participants, blade_session_id_get(bs)); // @todo make copy of session id instead and search manually, also free the id
|
||||
|
||||
blade_rpc_response_create(&res, NULL, breq->message_id);
|
||||
|
||||
// @todo create an event to send to participants when a session joins and leaves, send after main response though
|
||||
}
|
||||
|
||||
blade_session_properties_write_unlock(bs);
|
||||
|
||||
blade_session_send(bs, res, NULL);
|
||||
|
||||
blade_session_read_unlock(bs);
|
||||
|
||||
cJSON_Delete(res);
|
||||
|
||||
return KS_FALSE;
|
||||
}
|
||||
|
||||
ks_bool_t blade_chat_send_request_handler(blade_module_t *bm, blade_request_t *breq)
|
||||
{
|
||||
blade_module_chat_t *bm_chat = NULL;
|
||||
blade_session_t *bs = NULL;
|
||||
cJSON *params = NULL;
|
||||
cJSON *res = NULL;
|
||||
cJSON *event = NULL;
|
||||
const char *message = NULL;
|
||||
ks_bool_t sendevent = KS_FALSE;
|
||||
|
||||
ks_assert(bm);
|
||||
ks_assert(breq);
|
||||
|
||||
ks_log(KS_LOG_DEBUG, "Request Received!\n");
|
||||
|
||||
bm_chat = (blade_module_chat_t *)blade_module_data_get(bm);
|
||||
ks_assert(bm_chat);
|
||||
|
||||
params = cJSON_GetObjectItem(breq->message, "params"); // @todo cache this in blade_request_t for quicker/easier access
|
||||
if (!params) {
|
||||
ks_log(KS_LOG_DEBUG, "Session (%s) attempted to send chat message with no 'params' object\n", blade_session_id_get(bs));
|
||||
blade_rpc_error_create(&res, NULL, breq->message_id, -32602, "Missing params object");
|
||||
}
|
||||
else if (!(message = cJSON_GetObjectCstr(params, "message"))) {
|
||||
ks_log(KS_LOG_DEBUG, "Session (%s) attempted to send chat message with no 'message'\n", blade_session_id_get(bs));
|
||||
blade_rpc_error_create(&res, NULL, breq->message_id, -32602, "Missing params message string");
|
||||
}
|
||||
|
||||
bs = blade_handle_sessions_get(breq->handle, breq->session_id);
|
||||
ks_assert(bs);
|
||||
|
||||
if (!res) {
|
||||
blade_rpc_response_create(&res, NULL, breq->message_id);
|
||||
sendevent = KS_TRUE;
|
||||
}
|
||||
blade_session_send(bs, res, NULL);
|
||||
|
||||
blade_session_read_unlock(bs);
|
||||
|
||||
cJSON_Delete(res);
|
||||
|
||||
if (sendevent) {
|
||||
blade_rpc_event_create(&event, &res, "blade.chat.message");
|
||||
ks_assert(event);
|
||||
cJSON_AddStringToObject(res, "from", breq->session_id); // @todo should really be the identity, but we don't have that in place yet
|
||||
cJSON_AddStringToObject(res, "message", message);
|
||||
|
||||
blade_handle_sessions_send(breq->handle, bm_chat->participants, NULL, event);
|
||||
|
||||
cJSON_Delete(event);
|
||||
}
|
||||
|
||||
return KS_FALSE;
|
||||
}
|
||||
//static void blade_module_chat_cleanup(ks_pool_t *pool, void *ptr, void *arg, ks_pool_cleanup_action_t action, ks_pool_cleanup_type_t type)
|
||||
//{
|
||||
// blade_module_chat_t *bm_chat = (blade_module_chat_t *)ptr;
|
||||
//
|
||||
// ks_assert(bm_chat);
|
||||
//
|
||||
// switch (action) {
|
||||
// case KS_MPCL_ANNOUNCE:
|
||||
// break;
|
||||
// case KS_MPCL_TEARDOWN:
|
||||
// break;
|
||||
// case KS_MPCL_DESTROY:
|
||||
// break;
|
||||
// }
|
||||
//}
|
||||
//
|
||||
//
|
||||
//ks_status_t blade_module_chat_create(blade_module_t **bmP, blade_handle_t *bh)
|
||||
//{
|
||||
// blade_module_chat_t *bm_chat = NULL;
|
||||
// ks_pool_t *pool = NULL;
|
||||
//
|
||||
// ks_assert(bmP);
|
||||
// ks_assert(bh);
|
||||
//
|
||||
// ks_pool_open(&pool);
|
||||
// ks_assert(pool);
|
||||
//
|
||||
// bm_chat = ks_pool_alloc(pool, sizeof(blade_module_chat_t));
|
||||
// bm_chat->handle = bh;
|
||||
// bm_chat->pool = pool;
|
||||
// bm_chat->tpool = blade_handle_tpool_get(bh);
|
||||
// bm_chat->session_state_callback_id = NULL;
|
||||
//
|
||||
// ks_list_create(&bm_chat->participants, pool);
|
||||
// ks_assert(bm_chat->participants);
|
||||
//
|
||||
// blade_module_create(&bm_chat->module, bh, pool, bm_chat, &g_module_chat_callbacks);
|
||||
// ks_assert(bm_chat->module);
|
||||
//
|
||||
// ks_pool_set_cleanup(pool, bm_chat, NULL, blade_module_chat_cleanup);
|
||||
//
|
||||
// ks_log(KS_LOG_DEBUG, "Created\n");
|
||||
//
|
||||
// *bmP = bm_chat->module;
|
||||
//
|
||||
// return KS_STATUS_SUCCESS;
|
||||
//}
|
||||
//
|
||||
//
|
||||
//ks_status_t blade_module_chat_config(blade_module_chat_t *bm_chat, config_setting_t *config)
|
||||
//{
|
||||
// config_setting_t *chat = NULL;
|
||||
//
|
||||
// ks_assert(bm_chat);
|
||||
// ks_assert(config);
|
||||
//
|
||||
// if (!config_setting_is_group(config)) {
|
||||
// ks_log(KS_LOG_DEBUG, "!config_setting_is_group(config)\n");
|
||||
// return KS_STATUS_FAIL;
|
||||
// }
|
||||
//
|
||||
// chat = config_setting_get_member(config, "chat");
|
||||
// if (chat) {
|
||||
// }
|
||||
//
|
||||
//
|
||||
// // Configuration is valid, now assign it to the variables that are used
|
||||
// // If the configuration was invalid, then this does not get changed
|
||||
//
|
||||
// ks_log(KS_LOG_DEBUG, "Configured\n");
|
||||
//
|
||||
// return KS_STATUS_SUCCESS;
|
||||
//}
|
||||
//
|
||||
//ks_status_t blade_module_chat_on_startup(blade_module_t *bm, config_setting_t *config)
|
||||
//{
|
||||
// blade_module_chat_t *bm_chat = NULL;
|
||||
// blade_space_t *space = NULL;
|
||||
// blade_method_t *method = NULL;
|
||||
//
|
||||
// ks_assert(bm);
|
||||
// ks_assert(config);
|
||||
//
|
||||
// bm_chat = (blade_module_chat_t *)blade_module_data_get(bm);
|
||||
//
|
||||
// if (blade_module_chat_config(bm_chat, config) != KS_STATUS_SUCCESS) {
|
||||
// ks_log(KS_LOG_DEBUG, "blade_module_chat_config failed\n");
|
||||
// return KS_STATUS_FAIL;
|
||||
// }
|
||||
//
|
||||
// blade_space_create(&space, bm_chat->handle, bm, "blade.chat");
|
||||
// ks_assert(space);
|
||||
//
|
||||
// bm_chat->blade_chat_space = space;
|
||||
//
|
||||
// blade_method_create(&method, space, "join", blade_chat_join_request_handler);
|
||||
// ks_assert(method);
|
||||
// blade_space_methods_add(space, method);
|
||||
//
|
||||
// blade_method_create(&method, space, "leave", blade_chat_leave_request_handler);
|
||||
// ks_assert(method);
|
||||
// blade_space_methods_add(space, method);
|
||||
//
|
||||
// blade_method_create(&method, space, "send", blade_chat_send_request_handler);
|
||||
// ks_assert(method);
|
||||
// blade_space_methods_add(space, method);
|
||||
//
|
||||
// blade_handle_space_register(space);
|
||||
//
|
||||
// blade_handle_session_state_callback_register(blade_module_handle_get(bm), bm, blade_module_chat_on_session_state, &bm_chat->session_state_callback_id);
|
||||
//
|
||||
// ks_log(KS_LOG_DEBUG, "Started\n");
|
||||
//
|
||||
// return KS_STATUS_SUCCESS;
|
||||
//}
|
||||
//
|
||||
//ks_status_t blade_module_chat_on_shutdown(blade_module_t *bm)
|
||||
//{
|
||||
// blade_module_chat_t *bm_chat = NULL;
|
||||
//
|
||||
// ks_assert(bm);
|
||||
//
|
||||
// bm_chat = (blade_module_chat_t *)blade_module_data_get(bm);
|
||||
// ks_assert(bm_chat);
|
||||
//
|
||||
// if (bm_chat->session_state_callback_id) blade_handle_session_state_callback_unregister(blade_module_handle_get(bm), bm_chat->session_state_callback_id);
|
||||
// bm_chat->session_state_callback_id = NULL;
|
||||
//
|
||||
// if (bm_chat->blade_chat_space) blade_handle_space_unregister(bm_chat->blade_chat_space);
|
||||
//
|
||||
// ks_log(KS_LOG_DEBUG, "Stopped\n");
|
||||
//
|
||||
// return KS_STATUS_SUCCESS;
|
||||
//}
|
||||
//
|
||||
//void blade_module_chat_on_session_state(blade_session_t *bs, blade_session_state_condition_t condition, void *data)
|
||||
//{
|
||||
// blade_module_t *bm = NULL;
|
||||
// blade_module_chat_t *bm_chat = NULL;
|
||||
//
|
||||
// ks_assert(bs);
|
||||
// ks_assert(data);
|
||||
//
|
||||
// bm = (blade_module_t *)data;
|
||||
// bm_chat = (blade_module_chat_t *)blade_module_data_get(bm);
|
||||
// ks_assert(bm_chat);
|
||||
//
|
||||
// if (blade_session_state_get(bs) == BLADE_SESSION_STATE_HANGUP && condition == BLADE_SESSION_STATE_CONDITION_PRE) {
|
||||
// cJSON *props = NULL;
|
||||
//
|
||||
// ks_log(KS_LOG_DEBUG, "Removing session from chat participants if present\n");
|
||||
//
|
||||
// props = blade_session_properties_get(bs);
|
||||
// ks_assert(props);
|
||||
//
|
||||
// cJSON_DeleteItemFromObject(props, "blade.chat.participant");
|
||||
//
|
||||
// ks_list_delete(bm_chat->participants, blade_session_id_get(bs)); // @todo make copy of session id instead and search manually, also free the id
|
||||
// }
|
||||
//}
|
||||
//
|
||||
//ks_bool_t blade_chat_join_request_handler(blade_module_t *bm, blade_request_t *breq)
|
||||
//{
|
||||
// blade_module_chat_t *bm_chat = NULL;
|
||||
// blade_session_t *bs = NULL;
|
||||
// cJSON *res = NULL;
|
||||
// cJSON *props = NULL;
|
||||
// cJSON *props_participant = NULL;
|
||||
//
|
||||
// ks_assert(bm);
|
||||
// ks_assert(breq);
|
||||
//
|
||||
// ks_log(KS_LOG_DEBUG, "Request Received!\n");
|
||||
//
|
||||
// bm_chat = (blade_module_chat_t *)blade_module_data_get(bm);
|
||||
// ks_assert(bm_chat);
|
||||
//
|
||||
// bs = blade_handle_sessions_get(breq->handle, breq->session_id);
|
||||
// ks_assert(bs);
|
||||
//
|
||||
// // @todo properties only used to demonstrate a flexible container for session data, should just rely on the participants list/hash
|
||||
// blade_session_properties_write_lock(bs, KS_TRUE);
|
||||
//
|
||||
// props = blade_session_properties_get(bs);
|
||||
// ks_assert(props);
|
||||
//
|
||||
// props_participant = cJSON_GetObjectItem(props, "blade.chat.participant");
|
||||
// if (props_participant && props_participant->type == cJSON_True) {
|
||||
// ks_log(KS_LOG_DEBUG, "Session (%s) attempted to join chat but is already a participant\n", blade_session_id_get(bs));
|
||||
// blade_rpc_error_create(&res, NULL, breq->message_id, -10000, "Already a participant of chat");
|
||||
// }
|
||||
// else {
|
||||
// ks_log(KS_LOG_DEBUG, "Session (%s) joined chat\n", blade_session_id_get(bs));
|
||||
//
|
||||
// if (props_participant) props_participant->type = cJSON_True;
|
||||
// else cJSON_AddTrueToObject(props, "blade.chat.participant");
|
||||
//
|
||||
// ks_list_append(bm_chat->participants, blade_session_id_get(bs)); // @todo make copy of session id instead and cleanup when removed
|
||||
//
|
||||
// blade_rpc_response_create(&res, NULL, breq->message_id);
|
||||
//
|
||||
// // @todo create an event to send to participants when a session joins and leaves, send after main response though
|
||||
// }
|
||||
//
|
||||
// blade_session_properties_write_unlock(bs);
|
||||
//
|
||||
// blade_session_send(bs, res, NULL);
|
||||
//
|
||||
// blade_session_read_unlock(bs);
|
||||
//
|
||||
// cJSON_Delete(res);
|
||||
//
|
||||
// return KS_FALSE;
|
||||
//}
|
||||
//
|
||||
//ks_bool_t blade_chat_leave_request_handler(blade_module_t *bm, blade_request_t *breq)
|
||||
//{
|
||||
// blade_module_chat_t *bm_chat = NULL;
|
||||
// blade_session_t *bs = NULL;
|
||||
// cJSON *res = NULL;
|
||||
// cJSON *props = NULL;
|
||||
// cJSON *props_participant = NULL;
|
||||
//
|
||||
// ks_assert(bm);
|
||||
// ks_assert(breq);
|
||||
//
|
||||
// ks_log(KS_LOG_DEBUG, "Request Received!\n");
|
||||
//
|
||||
// bm_chat = (blade_module_chat_t *)blade_module_data_get(bm);
|
||||
// ks_assert(bm_chat);
|
||||
//
|
||||
// bs = blade_handle_sessions_get(breq->handle, breq->session_id);
|
||||
// ks_assert(bs);
|
||||
//
|
||||
// blade_session_properties_write_lock(bs, KS_TRUE);
|
||||
//
|
||||
// props = blade_session_properties_get(bs);
|
||||
// ks_assert(props);
|
||||
//
|
||||
// props_participant = cJSON_GetObjectItem(props, "blade.chat.participant");
|
||||
// if (!props_participant || props_participant->type == cJSON_False) {
|
||||
// ks_log(KS_LOG_DEBUG, "Session (%s) attempted to leave chat but is not a participant\n", blade_session_id_get(bs));
|
||||
// blade_rpc_error_create(&res, NULL, breq->message_id, -10000, "Not a participant of chat");
|
||||
// }
|
||||
// else {
|
||||
// ks_log(KS_LOG_DEBUG, "Session (%s) left chat\n", blade_session_id_get(bs));
|
||||
//
|
||||
// cJSON_DeleteItemFromObject(props, "blade.chat.participant");
|
||||
//
|
||||
// ks_list_delete(bm_chat->participants, blade_session_id_get(bs)); // @todo make copy of session id instead and search manually, also free the id
|
||||
//
|
||||
// blade_rpc_response_create(&res, NULL, breq->message_id);
|
||||
//
|
||||
// // @todo create an event to send to participants when a session joins and leaves, send after main response though
|
||||
// }
|
||||
//
|
||||
// blade_session_properties_write_unlock(bs);
|
||||
//
|
||||
// blade_session_send(bs, res, NULL);
|
||||
//
|
||||
// blade_session_read_unlock(bs);
|
||||
//
|
||||
// cJSON_Delete(res);
|
||||
//
|
||||
// return KS_FALSE;
|
||||
//}
|
||||
//
|
||||
//ks_bool_t blade_chat_send_request_handler(blade_module_t *bm, blade_request_t *breq)
|
||||
//{
|
||||
// blade_module_chat_t *bm_chat = NULL;
|
||||
// blade_session_t *bs = NULL;
|
||||
// cJSON *params = NULL;
|
||||
// cJSON *res = NULL;
|
||||
// cJSON *event = NULL;
|
||||
// const char *message = NULL;
|
||||
// ks_bool_t sendevent = KS_FALSE;
|
||||
//
|
||||
// ks_assert(bm);
|
||||
// ks_assert(breq);
|
||||
//
|
||||
// ks_log(KS_LOG_DEBUG, "Request Received!\n");
|
||||
//
|
||||
// bm_chat = (blade_module_chat_t *)blade_module_data_get(bm);
|
||||
// ks_assert(bm_chat);
|
||||
//
|
||||
// params = cJSON_GetObjectItem(breq->message, "params"); // @todo cache this in blade_request_t for quicker/easier access
|
||||
// if (!params) {
|
||||
// ks_log(KS_LOG_DEBUG, "Session (%s) attempted to send chat message with no 'params' object\n", blade_session_id_get(bs));
|
||||
// blade_rpc_error_create(&res, NULL, breq->message_id, -32602, "Missing params object");
|
||||
// }
|
||||
// else if (!(message = cJSON_GetObjectCstr(params, "message"))) {
|
||||
// ks_log(KS_LOG_DEBUG, "Session (%s) attempted to send chat message with no 'message'\n", blade_session_id_get(bs));
|
||||
// blade_rpc_error_create(&res, NULL, breq->message_id, -32602, "Missing params message string");
|
||||
// }
|
||||
//
|
||||
// bs = blade_handle_sessions_get(breq->handle, breq->session_id);
|
||||
// ks_assert(bs);
|
||||
//
|
||||
// if (!res) {
|
||||
// blade_rpc_response_create(&res, NULL, breq->message_id);
|
||||
// sendevent = KS_TRUE;
|
||||
// }
|
||||
// blade_session_send(bs, res, NULL);
|
||||
//
|
||||
// blade_session_read_unlock(bs);
|
||||
//
|
||||
// cJSON_Delete(res);
|
||||
//
|
||||
// if (sendevent) {
|
||||
// blade_rpc_event_create(&event, &res, "blade.chat.message");
|
||||
// ks_assert(event);
|
||||
// cJSON_AddStringToObject(res, "from", breq->session_id); // @todo should really be the identity, but we don't have that in place yet
|
||||
// cJSON_AddStringToObject(res, "message", message);
|
||||
//
|
||||
// blade_handle_sessions_send(breq->handle, bm_chat->participants, NULL, event);
|
||||
//
|
||||
// cJSON_Delete(event);
|
||||
// }
|
||||
//
|
||||
// return KS_FALSE;
|
||||
//}
|
||||
|
||||
|
||||
/* For Emacs:
|
||||
|
|
|
@ -1,28 +1,26 @@
|
|||
blade:
|
||||
{
|
||||
identity = "service@domain";
|
||||
directory:
|
||||
{
|
||||
};
|
||||
datastore:
|
||||
{
|
||||
database:
|
||||
{
|
||||
path = ":mem:";
|
||||
};
|
||||
};
|
||||
wss:
|
||||
{
|
||||
endpoints:
|
||||
{
|
||||
ipv4 = ( { address = "0.0.0.0", port = 2100 } );
|
||||
ipv6 = ( { address = "::", port = 2100 } );
|
||||
backlog = 128;
|
||||
};
|
||||
# SSL group is optional, disabled when absent
|
||||
ssl:
|
||||
{
|
||||
# todo: server SSL stuffs here
|
||||
};
|
||||
};
|
||||
master:
|
||||
{
|
||||
enabled = true;
|
||||
user = "00000000-0000-0000-0000-000000000000";
|
||||
realms = ( "mydomain.com" );
|
||||
};
|
||||
transport:
|
||||
{
|
||||
wss:
|
||||
{
|
||||
endpoints:
|
||||
{
|
||||
ipv4 = ( { address = "0.0.0.0", port = 2100 } );
|
||||
ipv6 = ( { address = "::", port = 2100 } );
|
||||
backlog = 128;
|
||||
};
|
||||
# SSL group is optional, disabled when absent
|
||||
ssl:
|
||||
{
|
||||
# todo: server SSL stuffs here
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue