/*
- * Copyright (C) 2016, 2017, 2018 "IoT.bzh"
+ * Copyright (C) 2016-2019 "IoT.bzh"
* Author José Bollo <jose.bollo@iot.bzh>
*
* Licensed under the Apache License, Version 2.0 (the "License");
#include <stdio.h>
#include <string.h>
#include <errno.h>
+#include <stdint.h>
-#include "afb-session.h"
#include "verbose.h"
#include "afb-api.h"
#include "afb-apiset.h"
#include "afb-context.h"
#include "afb-xreq.h"
+#include "jobs.h"
#define INCR 8 /* CAUTION: must be a power of 2 */
{
struct api_alias *next;
struct api_desc *api;
- char name[1];
+ char name[];
};
/**
{
struct api_class *next;
struct api_array providers;
- char name[1];
+ char name[];
};
/**
struct api_depend
{
struct afb_apiset *set;
- char name[1];
+ char name[];
};
/**
} onlack; /** not found handler */
int timeout; /**< the timeout in second for the apiset */
int refcount; /**< reference count for freeing resources */
- char name[1]; /**< name of the apiset */
+ char name[]; /**< name of the apiset */
};
/**
if (!create)
return NULL;
- c = calloc(1, strlen(name) + sizeof *c);
+ c = calloc(1, strlen(name) + 1 + sizeof *c);
if (!c)
errno = ENOMEM;
else {
{
struct afb_apiset *set;
- set = calloc(1, (name ? strlen(name) : 0) + sizeof *set);
+ set = calloc(1, (name ? strlen(name) : 0) + 1 + sizeof *set);
if (set) {
set->timeout = timeout;
set->refcount = 1;
}
/* allocates and init the struct */
- ali = malloc(sizeof *ali + strlen(alias));
+ ali = malloc(sizeof *ali + strlen(alias) + 1);
if (ali == NULL) {
ERROR("out of memory");
errno = ENOMEM;
return -1;
}
- INFO("API %s starting...", api->name);
+ NOTICE("API %s starting...", api->name);
api->status = EBUSY;
rc = start_array_classes(&api->require.classes);
if (rc < 0)
- ERROR("Can start classes needed by api %s", api->name);
+ ERROR("Cannot start classes needed by api %s", api->name);
else {
rc = start_array_depends(&api->require.apis);
if (rc < 0)
- ERROR("Can start apis needed by api %s", api->name);
+ ERROR("Cannot start apis needed by api %s", api->name);
else if (api->api.itf->service_start) {
rc = api->api.itf->service_start(api->api.closure);
if (rc < 0)
api->status = errno ?: ECANCELED;
return -1;
}
- NOTICE("API %s started", api->name);
+ INFO("API %s started", api->name);
api->status = 0;
return 0;
}
return ret;
}
+#if WITH_AFB_HOOK
/**
* Ask to update the hook flags of the 'api'
* @param set the api set
d->api.itf->update_hooks(d->api.closure);
}
}
+#endif
/**
* Set the logmask of the 'api' to 'mask'
return i->api.itf->get_logmask(i->api.closure);
}
-/**
- * Get the description of the API of 'name'
- * @param set the api set
- * @param name the api whose description is required
- * @return the description or NULL
- */
-struct json_object *afb_apiset_describe(struct afb_apiset *set, const char *name)
+void afb_apiset_describe(struct afb_apiset *set, const char *name, void (*describecb)(void *, struct json_object *), void *closure)
{
const struct api_desc *i;
-
- i = name ? searchrec(set, name) : NULL;
- return i && i->api.itf->describe ? i->api.itf->describe(i->api.closure) : NULL;
+ struct json_object *r;
+
+ r = NULL;
+ if (name) {
+ i = searchrec(set, name);
+ if (i) {
+ if (i->api.itf->describe) {
+ i->api.itf->describe(i->api.closure, describecb, closure);
+ return;
+ }
+ }
+ }
+ describecb(closure, r);
}
+
struct get_names {
union {
struct {
if (!a)
errno = ENOENT;
else {
- d = malloc(strlen(required) + sizeof *d);
+ d = malloc(strlen(required) + 1 + sizeof *d);
if (!d)
errno = ENOMEM;
else {