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"; in
48 * the stub process, NULL means use the one
49 * the parent gave on our cmdline */
50 const struct lws_protocols *protocols; /* Protocol array for the UDS server vhost */
51 const void *extra_payload; /* Optional extra data to write to child stdin */
52 size_t extra_payload_len;
53 void *user; /* Opaque user pointer passed to vhost */
54 void (*connected_cb)(struct lws_stub_manager *mgr); /* Called when UDS connects */
55 void (*parent_gone_cb)(void *user); /* Stub process side only: called when the
56 * stub is about to exit autonomously
57 * because its parent died (or SIGTERM was
58 * received and no app handler was
59 * installed), just before the UDS socket
60 * is unlinked and the process exits. This
61 * is the stub's last chance to clean up
62 * or persist its own state. */
63 const char *parent_protocol_name; /* Protocol to bind parent pipes to. If set, this
64 * protocol must call lws_spawn_stdwsi_closed()
65 * with lws_stub_get_lsp(mgr) from its
66 * LWS_CALLBACK_RAW_CLOSE_FILE handler. */
67};
68
69struct lws_stub_manager;
70
84LWS_VISIBLE LWS_EXTERN struct lws_stub_manager *
85lws_stub_spawn(const struct lws_stub_config *config);
86
118lws_stub_server_init(const struct lws_stub_config *config, char *secret_out, void *extra_out, size_t extra_len);
119
139lws_stub_request(struct lws_stub_manager *mgr,
140 const char *json,
141 const char * const *rx_paths,
142 size_t rx_paths_count,
143 signed char (*rx_cb)(struct lejp_ctx *ctx, char reason),
144 void (*raw_cb)(const char *in, size_t len, void *user),
145 void *user);
146
185LWS_VISIBLE LWS_EXTERN lws_stub_req_h
186lws_stub_request_h(struct lws_stub_manager *mgr,
187 const char *json,
188 const char * const *rx_paths,
189 size_t rx_paths_count,
190 signed char (*rx_cb)(struct lejp_ctx *ctx, char reason),
191 void (*raw_cb)(const char *in, size_t len, void *user),
192 void *user);
193
213lws_stub_request_cancel(struct lws_stub_manager *mgr, lws_stub_req_h h);
214
223lws_stub_destroy(struct lws_stub_manager **_mgr);
224
232LWS_VISIBLE LWS_EXTERN const char *
233lws_stub_get_secret(struct lws_stub_manager *mgr);
234
247LWS_VISIBLE LWS_EXTERN struct lws_spawn_piped *
248lws_stub_get_lsp(struct lws_stub_manager *mgr);
249
250
252lws_callback_stub_client(struct lws *wsi, enum lws_callback_reasons reason,
253 void *user, void *in, size_t len);
254
255#endif /* LWS_WITH_STUB */
256
257#endif /* _LWS_STUB_H */
lws_callback_reasons
#define LWS_EXTERN
#define LWS_VISIBLE