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

respondd: add provider "respondd-providers" to list registrations #256

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 53 additions & 1 deletion net/respondd/src/respondd.c
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,11 @@ struct provider_list {
respondd_provider provider;
};

struct key_list {
struct key_list *next;
char *key;
};

struct request_type {
struct provider_list *providers;

Expand All @@ -101,6 +106,7 @@ struct request_schedule {

static int64_t now;
static struct hsearch_data htab;
static struct key_list *keys;


static struct json_object * merge_json(struct json_object *a, struct json_object *b);
Expand Down Expand Up @@ -272,6 +278,23 @@ static void load_cache_time(struct request_type *r, const char *name) {

}

static void add_key(const char *key) {
struct key_list **pos, *pentry;
int i = 0;

for (pos = &keys; *pos; pos = &(*pos)->next) {
if (strcmp(key, (*pos)->key) == 0)
return;
if (strcmp(key, (*pos)->key) < 0)
break;
}

pentry = malloc(sizeof(*pentry));
pentry->key = strdup(key);
pentry->next = *pos;
*pos = pentry;
}

static void add_provider(const char *name, const struct respondd_provider_info *provider) {
ENTRY key = {
.key = (char *)provider->request,
Expand Down Expand Up @@ -306,6 +329,31 @@ static void add_provider(const char *name, const struct respondd_provider_info *
*pos = pentry;
}

static struct json_object *respondd_provider_providers(void) {
struct key_list **pos;
struct json_object *provider;
struct json_object *ret = json_object_new_array();

if (!ret)
return NULL;

for (pos = &keys; *pos; pos = &(*pos)->next) {
provider = json_object_new_string((*pos)->key);
json_object_array_add(ret, provider);
}

return ret;
}

static void add_providers_provider(void) {
const struct respondd_provider_info providers[] = {
{"respondd-providers", respondd_provider_providers},
{}
};

add_provider("respondd", providers);
}

static void load_providers(const char *path) {
update_time();

Expand Down Expand Up @@ -339,10 +387,14 @@ static void load_providers(const char *path) {
if (!providers)
continue;

for (; providers->request; providers++)
for (; providers->request; providers++) {
add_provider(ent->d_name, providers);
add_key(providers->request);
}
}

add_providers_provider();

closedir(dir);

out:
Expand Down