Skip to content

Commit

Permalink
Merge pull request #64 from miherran/gmetad_wildcards
Browse files Browse the repository at this point in the history
gmetad: Add wildcard support to gmetad http query interface.
  • Loading branch information
jbuchbinder committed Oct 26, 2012
2 parents 5eb4434 + 9a5752a commit f982643
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
17 changes: 17 additions & 0 deletions gmetad/server.c
Expand Up @@ -13,6 +13,7 @@
#include "dtd.h"
#include "gmetad.h"
#include "my_inet_ntop.h"
#include "server_priv.h"

extern g_tcp_socket *server_socket;
extern pthread_mutex_t server_socket_mutex;
Expand Down Expand Up @@ -464,6 +465,14 @@ process_path (client_t *client, char *path, datum_t *myroot, datum_t *key)
/* report this element */
rc = process_path(client, 0, myroot, NULL);
}
else if (!strcmp(element, "*"))
{
/* wildcard detected -> process every child */
struct request_context ctxt;
ctxt.path = q;
ctxt.client = client;
hash_foreach(node->children, process_path_adapter, (void*) &ctxt);
}
else
{
/* element not found */
Expand All @@ -483,6 +492,14 @@ process_path (client_t *client, char *path, datum_t *myroot, datum_t *key)
}


static int
process_path_adapter (datum_t *key, datum_t *val, void *arg)
{
struct request_context *ctxt = (struct request_context*) arg;
return process_path(ctxt->client, ctxt->path, val, key);
}


/* 'Cleans' the request and calls the appropriate handlers.
* This function alters the path to prepare it for processpath().
*/
Expand Down
12 changes: 12 additions & 0 deletions gmetad/server_priv.h
@@ -0,0 +1,12 @@
#ifndef SERVER_PRIV_H
#define SERVER_PRIV_H 1

struct request_context {
char *path;
client_t *client;
};

static int
process_path_adapter (datum_t *key, datum_t *val, void *arg);

#endif

0 comments on commit f982643

Please sign in to comment.