-/*
- * create a structure api_ws not connected to the 'path'.
- */
-static struct api_ws *api_ws_make(const char *path)
-{
- struct api_ws *api;
- size_t length;
-
- /* allocates the structure */
- length = strlen(path);
- api = calloc(1, sizeof *api + 1 + length);
- if (api == NULL) {
- errno = ENOMEM;
- goto error;
- }
-
- /* path is copied after the struct */
- api->path = (char*)(api+1);
- memcpy(api->path, path, length + 1);
-
- /* api name is at the end of the path */
- while (length && path[length - 1] != '/' && path[length - 1] != ':')
- length = length - 1;
- api->api = &api->path[length];
- if (api->api == NULL || !afb_api_is_valid_name(api->api)) {
- errno = EINVAL;
- goto error2;
- }
-
- return api;
-
-error2:
- free(api);
-error:
- return NULL;
-}
-
-static int api_ws_socket_unix(const char *path, int server)
-{
- int fd, rc;
- struct sockaddr_un addr;
- size_t length;
-
- length = strlen(path);
- if (length >= 108) {
- errno = ENAMETOOLONG;
- return -1;
- }
-
- if (server && path[0] != '@')
- unlink(path);
-
- fd = socket(AF_UNIX, SOCK_STREAM, 0);
- if (fd < 0)
- return fd;
-
- memset(&addr, 0, sizeof addr);
- addr.sun_family = AF_UNIX;
- strcpy(addr.sun_path, path);
- if (addr.sun_path[0] == '@')
- addr.sun_path[0] = 0; /* implement abstract sockets */
- if (server) {
- rc = bind(fd, (struct sockaddr *) &addr, (socklen_t)(sizeof addr));
- } else {
- rc = connect(fd, (struct sockaddr *) &addr, (socklen_t)(sizeof addr));
- }
- if (rc < 0) {
- close(fd);
- return rc;
- }
- return fd;
-}
-
-static int api_ws_socket_inet(const char *path, int server)