From 893b125acba6633bf946adf2b9821f6359fc4d3c Mon Sep 17 00:00:00 2001 From: Simon Rettberg Date: Sun, 1 Oct 2017 17:25:47 +0200 Subject: [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 --- src/server/net.c | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) (limited to 'src/server/net.c') 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, -- cgit v1.2.3-55-g7522