summaryrefslogtreecommitdiffstats
path: root/src/server/net.c
diff options
context:
space:
mode:
authorSimon Rettberg2017-10-01 17:25:47 +0200
committerSimon Rettberg2017-10-01 17:25:47 +0200
commit893b125acba6633bf946adf2b9821f6359fc4d3c (patch)
tree9d3d83f6a321a84f9622cd119da168ee3dbf3c1f /src/server/net.c
parent[SERVER] Move includes from header to source unit (diff)
downloaddnbd3-893b125acba6633bf946adf2b9821f6359fc4d3c.tar.gz
dnbd3-893b125acba6633bf946adf2b9821f6359fc4d3c.tar.xz
dnbd3-893b125acba6633bf946adf2b9821f6359fc4d3c.zip
[SERVER] Implement HTTP RPC that supports different queries and ACL
- ACL is defined in new file rpc.acl - Queries are still WIP, for now something like /query?q=stats&q=images /query?q=clients works, although the parsing is still ugly - Also supports HTTP keep-alive
Diffstat (limited to 'src/server/net.c')
-rw-r--r--src/server/net.c20
1 files changed, 14 insertions, 6 deletions
diff --git a/src/server/net.c b/src/server/net.c
index f7a866b..9f317ad 100644
--- a/src/server/net.c
+++ b/src/server/net.c
@@ -172,7 +172,7 @@ void* net_handleNewConnection(void *clientPtr)
// Let's see if this looks like an HTTP request
if ( ret > 5 && request.magic != dnbd3_packet_magic
&& ( strncmp( (char*)&request, "GET ", 4 ) == 0 || strncmp( (char*)&request, "POST ", 5 ) == 0 ) ) {
- rpc_sendStatsJson( client->sock );
+ rpc_sendStatsJson( client->sock, &client->host, &request, (size_t)ret );
goto fail_preadd;
}
@@ -527,9 +527,15 @@ fail_preadd: ;
return NULL;
}
-json_t* net_clientsToJson()
+/**
+ * Get list of all clients and update the global stats counter while we're at it.
+ * This method sucks since it has a param that tells it not to generate the list
+ * but only update the global counter, which is a horrible relic from refactoring.
+ * Hopfully I'll fix it soon by splitting this up or something.
+ */
+json_t* net_clientsToJson(const bool fullList)
{
- json_t *jsonClients = json_array();
+ json_t *jsonClients = fullList ? json_array() : NULL;
json_t *clientStats;
int i;
int imgId;
@@ -552,15 +558,17 @@ json_t* net_clientsToJson()
spin_unlock( &client->lock );
imgId = -1;
} else {
- strncpy( host, client->hostName, HOSTNAMELEN - 1 );
- imgId = client->image->id;
+ if ( fullList ) {
+ strncpy( host, client->hostName, HOSTNAMELEN - 1 );
+ imgId = client->image->id;
+ }
spin_lock( &client->statsLock );
spin_unlock( &client->lock );
bytesSent = client->bytesSent;
net_updateGlobalSentStatsFromClient( client ); // Do this since we read the totalBytesSent counter later
spin_unlock( &client->statsLock );
}
- if ( imgId != -1 ) {
+ if ( fullList && imgId != -1 ) {
clientStats = json_pack( "{sssisI}",
"address", host,
"imageId", imgId,