libwebsockets
Lightweight C library for HTML5 websockets
Loading...
Searching...
No Matches
lws-stub.h
Go to the documentation of this file.
1/*
2 * libwebsockets - small server side websockets and web server implementation
3 *
4 * Copyright (C) 2010 - 2026 Andy Green <andy@warmcat.com>
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 * of this software and associated documentation files (the "Software"), to
8 * deal in the Software without restriction, including without limitation the
9 * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
10 * sell copies of the Software, and to permit persons to whom the Software is
11 * furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be included in
14 * all copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
22 * IN THE SOFTWARE.
23 *
24 * lws_stub - generalized API for spawning and communicating with root stubs
25 * via UDS and JSON-RPC
26 */
27
28#ifndef _LWS_STUB_H
29#define _LWS_STUB_H
30
31#if defined(LWS_WITH_STUB)
32
33struct lws_stub_manager;
34
35/*
36 * Opaque handle for one queued request, valid until the request is retired.
37 * Zero is never a valid handle, and handles are never reused, so a handle
38 * kept after its request was retired is simply dead and safe to pass to
39 * lws_stub_request_cancel().
40 */
41typedef uint64_t lws_stub_req_h;
42
43struct lws_stub_config {
44 struct lws_context *cx;
45 struct lws_vhost *vh;
46 const char *stub_name; /* e.g. "distribution-client" */
47 const char *uds_path; /* e.g. "/var/run/lws-cert-dist-stub.sock" */
48 const struct lws_protocols *protocols; /* Protocol array for the UDS server vhost */
49 const void *extra_payload; /* Optional extra data to write to child stdin */
50 size_t extra_payload_len;
51 void *user; /* Opaque user pointer passed to vhost */
52 void (*connected_cb)(struct lws_stub_manager *mgr); /* Called when UDS connects */
53 void (*parent_gone_cb)(void *user); /* Stub process side only: called when the
54 * stub is about to exit autonomously
55 * because its parent died (or SIGTERM was
56 * received and no app handler was
57 * installed), just before the UDS socket
58 * is unlinked and the process exits. This
59 * is the stub's last chance to clean up
60 * or persist its own state. */
61 const char *parent_protocol_name; /* Protocol to bind parent pipes to. If set, this
62 * protocol must call lws_spawn_stdwsi_closed()
63 * with lws_stub_get_lsp(mgr) from its
64 * LWS_CALLBACK_RAW_CLOSE_FILE handler. */
65};
66
67struct lws_stub_manager;
68
81LWS_VISIBLE LWS_EXTERN struct lws_stub_manager *
82lws_stub_spawn(const struct lws_stub_config *config);
83
108lws_stub_server_init(const struct lws_stub_config *config, char *secret_out, void *extra_out, size_t extra_len);
109
129lws_stub_request(struct lws_stub_manager *mgr,
130 const char *json,
131 const char * const *rx_paths,
132 size_t rx_paths_count,
133 signed char (*rx_cb)(struct lejp_ctx *ctx, char reason),
134 void (*raw_cb)(const char *in, size_t len, void *user),
135 void *user);
136
175LWS_VISIBLE LWS_EXTERN lws_stub_req_h
176lws_stub_request_h(struct lws_stub_manager *mgr,
177 const char *json,
178 const char * const *rx_paths,
179 size_t rx_paths_count,
180 signed char (*rx_cb)(struct lejp_ctx *ctx, char reason),
181 void (*raw_cb)(const char *in, size_t len, void *user),
182 void *user);
183
203lws_stub_request_cancel(struct lws_stub_manager *mgr, lws_stub_req_h h);
204
213lws_stub_destroy(struct lws_stub_manager **_mgr);
214
222LWS_VISIBLE LWS_EXTERN const char *
223lws_stub_get_secret(struct lws_stub_manager *mgr);
224
237LWS_VISIBLE LWS_EXTERN struct lws_spawn_piped *
238lws_stub_get_lsp(struct lws_stub_manager *mgr);
239
240
242lws_callback_stub_client(struct lws *wsi, enum lws_callback_reasons reason,
243 void *user, void *in, size_t len);
244
245#endif /* LWS_WITH_STUB */
246
247#endif /* _LWS_STUB_H */
lws_callback_reasons
#define LWS_EXTERN
#define LWS_VISIBLE