X-Git-Url: https://gerrit.automotivelinux.org/gerrit/gitweb?a=blobdiff_plain;f=src%2Fafb-api-ws.c;h=a56cfbef7feb7236752b75ec0febce04a4c6f54b;hb=f5ce0df45f5ce9f0b57b250dfd44513d085f1e54;hp=e81306a390e4235731b279fed62b44c2f6361371;hpb=2f585aedc463109b3d59ad63a9a6c82f324dd500;p=src%2Fapp-framework-binder.git diff --git a/src/afb-api-ws.c b/src/afb-api-ws.c index e81306a3..a56cfbef 100644 --- a/src/afb-api-ws.c +++ b/src/afb-api-ws.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2015, 2016 "IoT.bzh" + * Copyright (C) 2015, 2016, 2017 "IoT.bzh" * Author José Bollo * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -37,7 +37,7 @@ #include "afb-common.h" -#include "session.h" +#include "afb-session.h" #include "afb-ws.h" #include "afb-msg-json.h" #include "afb-apis.h" @@ -46,6 +46,7 @@ #include "afb-evt.h" #include "afb-subcall.h" #include "verbose.h" +#include "sd-fds.h" struct api_ws_memo; struct api_ws_event; @@ -212,7 +213,9 @@ static struct api_ws *api_ws_make(const char *path) memcpy(api->path, path, length + 1); /* api name is at the end of the path */ - api->api = strrchr(api->path, '/'); + while (length && path[length - 1] != '/' && path[length - 1] != ':') + length = length - 1; + api->api = &api->path[length]; if (api->api == NULL || !afb_apis_is_valid_api_name(++api->api)) { errno = EINVAL; goto error2; @@ -314,21 +317,29 @@ static int api_ws_socket(const char *path, int server) { int fd, rc; - /* check for unix socket */ - if (0 == strncmp(path, "unix:", 5)) - fd = api_ws_socket_unix(path + 5, server); - else - fd = api_ws_socket_inet(path, server); - - if (fd >= 0) { - fcntl(fd, F_SETFD, FD_CLOEXEC); - fcntl(fd, F_SETFL, O_NONBLOCK); - if (server) { + /* check for systemd socket */ + if (0 == strncmp(path, "sd:", 3)) + fd = sd_fds_for(path + 3); + else { + /* check for unix socket */ + if (0 == strncmp(path, "unix:", 5)) + /* unix socket */ + fd = api_ws_socket_unix(path + 5, server); + else + /* inet socket */ + fd = api_ws_socket_inet(path, server); + + if (fd >= 0 && server) { rc = 1; setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, &rc, sizeof rc); rc = listen(fd, 5); } } + /* configure the socket */ + if (fd >= 0) { + fcntl(fd, F_SETFD, FD_CLOEXEC); + fcntl(fd, F_SETFL, O_NONBLOCK); + } return fd; } @@ -827,7 +838,7 @@ static void api_ws_client_call_cb(void * closure, struct afb_req req, struct afb if (!api_ws_write_uint32(&wb, memo->msgid) || !api_ws_write_uint32(&wb, (uint32_t)context->flags) || !api_ws_write_string_nz(&wb, verb, lenverb) - || !api_ws_write_string(&wb, ctxClientGetUuid(context->session)) + || !api_ws_write_string(&wb, afb_session_uuid(context->session)) || !api_ws_write_string_length(&wb, raw, szraw)) goto overflow; @@ -1023,6 +1034,8 @@ static void api_ws_server_accept(struct api_ws *api) lenaddr = (socklen_t)sizeof addr; client->fd = accept(api->fd, &addr, &lenaddr); if (client->fd >= 0) { + fcntl(client->fd, F_SETFD, FD_CLOEXEC); + fcntl(client->fd, F_SETFL, O_NONBLOCK); client->ws = afb_ws_create(afb_common_get_event_loop(), client->fd, &api_ws_server_ws_itf, client); if (client->ws != NULL) { client->api = api->api;