#include "afb-msg-json.h"
#include "afb-context.h"
#include "afb-hreq.h"
+#include "afb-hsrv.h"
#include "afb-session.h"
#include "afb-cred.h"
#include "verbose.h"
hreq->replied = 1;
if (hreq->suspended != 0) {
- extern void run_micro_httpd(struct afb_hsrv *hsrv);
MHD_resume_connection (hreq->connection);
hreq->suspended = 0;
- run_micro_httpd(hreq->hsrv);
+ afb_hsrv_run(hreq->hsrv);
}
}
fdev_set_events(hsrv->fdev, EPOLLIN);
}
-void run_micro_httpd(struct afb_hsrv *hsrv)
+void afb_hsrv_run(struct afb_hsrv *hsrv)
{
fdev_set_events(hsrv->fdev, 0);
if (jobs_queue(hsrv, 0, do_run, hsrv) < 0)
static void listen_callback(void *hsrv, uint32_t revents, struct fdev *fdev)
{
- run_micro_httpd(hsrv);
+ afb_hsrv_run(hsrv);
}
static int new_client_handler(void *cls, const struct sockaddr *addr, socklen_t addrlen)
extern int afb_hsrv_add_alias_root(struct afb_hsrv *hsrv, const char *prefix, struct locale_root *root, int priority, int relax);
extern int afb_hsrv_add_handler(struct afb_hsrv *hsrv, const char *prefix, int (*handler) (struct afb_hreq *, void *), void *data, int priority);
+extern void afb_hsrv_run(struct afb_hsrv *hsrv);
struct afb_session
{
struct afb_session *next; /**< link to the next */
- unsigned refcount; /**< external reference count of the session */
+ unsigned refcount; /**< count of reference to the session */
int timeout; /**< timeout of the session */
time_t expiration; /**< expiration time of the token */
pthread_mutex_t mutex; /**< mutex of the session */
#include "wrap-json.h"
#include "jobs.h"
-extern struct afb_config *main_config;
-
/* api and apiset name */
static const char supervision_apiname[] = AFS_SUPERVISION_APINAME;
static const char supervisor_apiname[] = AFS_SUPERVISOR_APINAME;
static pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER;
/* the standard apiset */
-extern struct afb_apiset *main_apiset;
+static struct {
+ struct afb_apiset *apiset;
+ struct afb_config *config;
+} global;
/* the supervision apiset (not exported) */
static struct afb_apiset *supervision_apiset;
/**
* initialize the supervision
*/
-int afb_supervision_init()
+int afb_supervision_init(struct afb_apiset *apiset, struct afb_config *config)
{
int rc;
struct sigaction sa;
return rc;
}
+ /* init the globals */
+ global.apiset = apiset;
+ global.config = config;
+
/* get SIGHUP */
memset(&sa, 0, sizeof sa);
sa.sa_handler = on_sighup;
afb_xreq_reply(xreq, list, NULL, NULL);
break;
case Config:
- afb_xreq_reply(xreq, afb_config_json(main_config), NULL, NULL);
+ afb_xreq_reply(xreq, afb_config_json(global.config), NULL, NULL);
break;
case Trace:
if (!trace)
if (wrap_json_unpack(args, "{ss ss s?o*}", "api", &api, "verb", &verb, "args", &sub))
afb_xreq_reply(xreq, NULL, "error", "bad request");
else {
- xapi = afb_apiset_lookup_started(main_apiset, api, 1);
+ xapi = afb_apiset_lookup_started(global.apiset, api, 1);
if (!xapi)
afb_xreq_reply_unknown_api(xreq);
else {
#pragma once
-extern int afb_supervision_init();
+struct afb_apiset;
+struct afb_config;
+
+extern int afb_supervision_init(struct afb_apiset *apiset, struct afb_config *config);
}
/* drop traces */
-extern int afb_trace_drop(afb_req_t req, struct json_object *args, struct afb_trace *trace)
+int afb_trace_drop(afb_req_t req, struct json_object *args, struct afb_trace *trace)
{
int rc;
struct context context;
goto error;
}
#if defined(WITH_SUPERVISION)
- if (afb_supervision_init() < 0) {
+ if (afb_supervision_init(main_apiset, main_config) < 0) {
ERROR("failed to setup supervision");
goto error;
}