/*
- * Copyright (C) 2015-2018 "IoT.bzh"
+ * Copyright (C) 2015-2019 "IoT.bzh"
* Author José Bollo <jose.bollo@iot.bzh>
*
* Licensed under the Apache License, Version 2.0 (the "License");
uint8_t is_client;
/* the api name */
- char apiname[1];
+ char apiname[];
};
static struct afb_proto_ws *afb_stub_ws_create_proto(struct afb_stub_ws *stubws, struct fdev *fdev, uint8_t server);
return;
}
+ afb_xreq_unhooked_addref(xreq);
rc = afb_proto_ws_client_call(
proto,
xreq->request.called_verb,
afb_session_uuid(xreq->context.session),
xreq,
xreq_on_behalf_cred_export(xreq));
- if (rc >= 0)
- afb_xreq_unhooked_addref(xreq);
- else
+ if (rc < 0) {
afb_xreq_reply(xreq, NULL, "internal", "can't send message");
+ afb_xreq_unhooked_unref(xreq);
+ }
}
static void client_on_description_cb(void *closure, struct json_object *data)
/******************* server part: manage events **********************************/
-static void server_event_add_cb(void *closure, const char *event, int eventid)
+static void server_event_add_cb(void *closure, const char *event, uint16_t eventid)
{
struct afb_stub_ws *stubws = closure;
afb_proto_ws_server_event_create(stubws->proto, event, eventid);
}
-static void server_event_remove_cb(void *closure, const char *event, int eventid)
+static void server_event_remove_cb(void *closure, const char *event, uint16_t eventid)
{
struct afb_stub_ws *stubws = closure;
afb_proto_ws_server_event_remove(stubws->proto, event, eventid);
}
-static void server_event_push_cb(void *closure, const char *event, int eventid, struct json_object *object)
+static void server_event_push_cb(void *closure, const char *event, uint16_t eventid, struct json_object *object)
{
struct afb_stub_ws *stubws = closure;
json_object_put(object);
}
-static void server_event_broadcast_cb(void *closure, const char *event, int eventid, struct json_object *object)
+static void server_event_broadcast_cb(void *closure, const char *event, struct json_object *object, const uuid_binary_t uuid, uint8_t hop)
{
struct afb_stub_ws *stubws = closure;
if (stubws->proto != NULL)
- afb_proto_ws_server_event_broadcast(stubws->proto, event, object);
+ afb_proto_ws_server_event_broadcast(stubws->proto, event, object, uuid, hop);
json_object_put(object);
}
ERROR("unreadable push event");
}
-static void client_on_event_broadcast_cb(void *closure, const char *event_name, struct json_object *data)
+static void client_on_event_broadcast_cb(void *closure, const char *event_name, struct json_object *data, const uuid_binary_t uuid, uint8_t hop)
{
- afb_evt_broadcast(event_name, data);
+ afb_evt_rebroadcast(event_name, data, uuid, hop);
}
/*****************************************************/
wreq->call = call;
/* init the context */
- if (afb_context_connect(&wreq->xreq.context, sessionid, NULL) < 0)
+ if (afb_context_connect_validated(&wreq->xreq.context, sessionid) < 0)
goto unconnected;
- wreq->xreq.context.validated = 1;
server_record_session(stubws, wreq->xreq.context.session);
if (wreq->xreq.context.created)
afb_session_set_autoclose(wreq->xreq.context.session, 1);
/* makes the call */
- wreq->xreq.cred = afb_cred_mixed_on_behalf_import(stubws->cred, sessionid, user_creds);
+ wreq->xreq.cred = afb_cred_mixed_on_behalf_import(stubws->cred, &wreq->xreq.context, user_creds);
wreq->xreq.request.called_api = stubws->apiname;
wreq->xreq.request.called_verb = verb;
wreq->xreq.json = args;
{
struct afb_stub_ws *stubws;
- stubws = calloc(1, sizeof *stubws + strlen(apiname));
+ stubws = calloc(1, sizeof *stubws + 1 + strlen(apiname));
if (stubws == NULL)
errno = ENOMEM;
else {