Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gmetad: Add wildcard support to gmetad http query interface. #64

Merged
merged 1 commit into from Oct 26, 2012
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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