Debian Codegraph @

src/transports/janus_nanomsg.c

raw symbols SCIP
1 /*! \file janus_nanomsg.c
2 * \author Lorenzo Miniero <[email protected]>
3 * \copyright GNU General Public License v3
4 * \brief Janus Nanomsg transport plugin
5 * \details This is an implementation of a Nanomsg transport for the
6 * Janus API. This means that, with the help of this module, local and
7 * remote applications can use Nanomsg to make requests to Janus.
8 * Note that not all the protocols Nanomsg implements are made available
9 * in this plugin: specifically, you'll only be able to use the \c NN_PAIR
10 * transport mechanism. Future versions may implement more, but for the
11 * time being these should be enough to cover most development requirements.
12 *
13 * \ingroup transports
14 * \ref transports
15 */
16
17 #include "transport.h"cxx . . $ `<file>/src/transports/transport.h`/
18
19 #include <nanomsg/nn.h>
20 #include <nanomsg/pair.h>
21 #include <nanomsg/inproc.h>
22 #include <nanomsg/ipc.h>
23 #include <nanomsg/pipeline.h>
24
25 #include "../debug.h"cxx . . $ `<file>/src/debug.h`/
26 #include "../apierror.h"cxx . . $ `<file>/src/apierror.h`/
27 #include "../config.h"cxx . . $ `<file>/src/config.h`/
28 #include "../utils.h"cxx . . $ `<file>/src/utils.h`/
29
30
31 /* Transport plugin information */
32 #define JANUS_NANOMSG_VERSIONcxx . . $ `src/transports/janus_nanomsg.c:32:9`! 1
33 #define JANUS_NANOMSG_VERSION_STRINGcxx . . $ `src/transports/janus_nanomsg.c:33:9`! "0.0.1"
34 #define JANUS_NANOMSG_DESCRIPTIONcxx . . $ `src/transports/janus_nanomsg.c:34:9`! "This transport plugin adds Nanomsg support to the Janus API."
35 #define JANUS_NANOMSG_NAMEcxx . . $ `src/transports/janus_nanomsg.c:35:9`! "JANUS Nanomsg transport plugin"
36 #define JANUS_NANOMSG_AUTHORcxx . . $ `src/transports/janus_nanomsg.c:36:9`! "Meetecho s.r.l."
37 #define JANUS_NANOMSG_PACKAGEcxx . . $ `src/transports/janus_nanomsg.c:37:9`! "janus.transport.nanomsg"
38
39 /* Transport methods */
40 janus_transportcxx . . $ janus_transport# *createcxx . . $ create(3f3037b43839689).(void);
41 int janus_nanomsg_initcxx . . $ janus_nanomsg_init(b353b9c8d404ddc).(janus_transport_callbackscxx . . $ janus_transport_callbacks# *callback, const char *config_path);
42 void janus_nanomsg_destroycxx . . $ janus_nanomsg_destroy(49f6e7a06ebc5aa8).(void);
43 int janus_nanomsg_get_api_compatibilitycxx . . $ janus_nanomsg_get_api_compatibility(b126dc7c1de90089).(void);
44 int janus_nanomsg_get_versioncxx . . $ janus_nanomsg_get_version(b126dc7c1de90089).(void);
45 const char *janus_nanomsg_get_version_stringcxx . . $ janus_nanomsg_get_version_string(33a1f659e94feb42).(void);
46 const char *janus_nanomsg_get_descriptioncxx . . $ janus_nanomsg_get_description(33a1f659e94feb42).(void);
47 const char *janus_nanomsg_get_namecxx . . $ janus_nanomsg_get_name(33a1f659e94feb42).(void);
48 const char *janus_nanomsg_get_authorcxx . . $ janus_nanomsg_get_author(33a1f659e94feb42).(void);
49 const char *janus_nanomsg_get_packagecxx . . $ janus_nanomsg_get_package(33a1f659e94feb42).(void);
50 gbooleancxx . . $ gboolean# janus_nanomsg_is_janus_api_enabledcxx . . $ janus_nanomsg_is_janus_api_enabled(b126dc7c1de90089).(void);
51 gbooleancxx . . $ gboolean# janus_nanomsg_is_admin_api_enabledcxx . . $ janus_nanomsg_is_admin_api_enabled(b126dc7c1de90089).(void);
52 int janus_nanomsg_send_messagecxx . . $ janus_nanomsg_send_message(6b64b6dff4e02fa6).(janus_transport_sessioncxx . . $ janus_transport_session# *transport, void *request_id, gbooleancxx . . $ gboolean# admin, json_tcxx . . $ json_t# *message);
53 void janus_nanomsg_session_createdcxx . . $ janus_nanomsg_session_created(b5ed81ddbcd64883).(janus_transport_sessioncxx . . $ janus_transport_session# *transport, guint64cxx . . $ guint64# session_id);
54 void janus_nanomsg_session_overcxx . . $ janus_nanomsg_session_over(c088a477eeb7160b).(janus_transport_sessioncxx . . $ janus_transport_session# *transport, guint64cxx . . $ guint64# session_id, gbooleancxx . . $ gboolean# timeout, gbooleancxx . . $ gboolean# claimed);
55 void janus_nanomsg_session_claimedcxx . . $ janus_nanomsg_session_claimed(b5ed81ddbcd64883).(janus_transport_sessioncxx . . $ janus_transport_session# *transport, guint64cxx . . $ guint64# session_id);
56 json_tcxx . . $ json_t# *janus_nanomsg_query_transportcxx . . $ janus_nanomsg_query_transport(d6c74909b48cac1f).(json_tcxx . . $ json_t# *request);
57
58
59 /* Transport setup */
60 static janus_transportcxx . . $ janus_transport# janus_nanomsg_transportcxx . . $ janus_nanomsg_transport. =
61 JANUS_TRANSPORT_INITcxx . . $ `src/transports/transport.h:116:9`! (
62 .init = janus_nanomsg_init,
63 .destroy = janus_nanomsg_destroy,
64
65 .get_api_compatibility = janus_nanomsg_get_api_compatibility,
66 .get_version = janus_nanomsg_get_version,
67 .get_version_string = janus_nanomsg_get_version_string,
68 .get_description = janus_nanomsg_get_description,
69 .get_name = janus_nanomsg_get_name,
70 .get_author = janus_nanomsg_get_author,
71 .get_package = janus_nanomsg_get_package,
72
73 .is_janus_api_enabled = janus_nanomsg_is_janus_api_enabled,
74 .is_admin_api_enabled = janus_nanomsg_is_admin_api_enabled,
75
76 .send_message = janus_nanomsg_send_message,
77 .session_created = janus_nanomsg_session_created,
78 .session_over = janus_nanomsg_session_over,
79 .session_claimed = janus_nanomsg_session_claimed,
80
81 .query_transport = janus_nanomsg_query_transport,
82 );
83
84 /* Transport creator */
85 janus_transportcxx . . $ janus_transport# *createcxx . . $ create(3f3037b43839689).(void) {
86 JANUS_LOGcxx . . $ `src/debug.h:91:9`!(LOG_VERBcxx . . $ `src/debug.h:49:9`!, "%s created!\n", JANUS_NANOMSG_NAMEcxx . . $ `src/transports/janus_nanomsg.c:35:9`!);
87 return &janus_nanomsg_transportcxx . . $ janus_nanomsg_transport.;
88 }
89
90
91 /* Useful stuff */
92 static gintcxx . . $ gint# initializedcxx . . $ initialized. = 0, stoppingcxx . . $ stopping. = 0;
93 static janus_transport_callbackscxx . . $ janus_transport_callbacks# *gatewaycxx . . $ gateway. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!;
94 static gbooleancxx . . $ gboolean# notify_eventscxx . . $ notify_events. = TRUEcxx . . $ `<external>/12741050725406041920/gmacros.h:971:9`!;
95
96 /* JSON serialization options */
97 static size_t json_formatcxx . . $ json_format. = JSON_COMPACTcxx . . $ `<external>/8172222224910760005/jansson.h:383:9`! | JSON_PRESERVE_ORDERcxx . . $ `<external>/8172222224910760005/jansson.h:386:9`!;
98
99 #define BUFFER_SIZEcxx . . $ `src/transports/janus_nanomsg.c:99:9`! 8192
100
101 /* Parameter validation (for tweaking and queries via Admin API) */
102 static struct janus_json_parametercxx . . $ janus_json_parameter# request_parameterscxx . . $ request_parameters.[] = {
103 {"request", JSON_STRINGcxx . . $ JSON_STRING., JANUS_JSON_PARAM_REQUIREDcxx . . $ `src/utils.h:25:9`!}
104 };
105 static struct janus_json_parametercxx . . $ janus_json_parameter# configure_parameterscxx . . $ configure_parameters.[] = {
106 {"events", JANUS_JSON_BOOLcxx . . $ `src/utils.h:24:9`!, 0},
107 {"json", JSON_STRINGcxx . . $ JSON_STRING., 0},
108 };
109 /* Error codes (for the tweaking and queries via Admin API) */
110 #define JANUS_NANOMSG_ERROR_INVALID_REQUESTcxx . . $ `src/transports/janus_nanomsg.c:110:9`! 411
111 #define JANUS_NANOMSG_ERROR_MISSING_ELEMENTcxx . . $ `src/transports/janus_nanomsg.c:111:9`! 412
112 #define JANUS_NANOMSG_ERROR_INVALID_ELEMENTcxx . . $ `src/transports/janus_nanomsg.c:112:9`! 413
113 #define JANUS_NANOMSG_ERROR_UNKNOWN_ERRORcxx . . $ `src/transports/janus_nanomsg.c:113:9`! 499
114
115
116 /* Nanomsg server thread */
117 static GThreadcxx . . $ GThread# *nanomsg_threadcxx . . $ nanomsg_thread. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!;
118 void *janus_nanomsg_threadcxx . . $ janus_nanomsg_thread(9f162e79bfc6c74).(void *data);
119
120 /* Nanomsg servers */
121 static int nfdcxx . . $ nfd. = -1, nfd_addrcxx . . $ nfd_addr. = -1, admin_nfdcxx . . $ admin_nfd. = -1, admin_nfd_addrcxx . . $ admin_nfd_addr. = -1;
122 /* Pipeline to notify about the need for outgoing data */
123 static int write_nfdcxx . . $ write_nfd.[2];
124
125 /* Nanomsg client session */
126 typedef struct janus_nanomsg_clientcxx . . $ janus_nanomsg_client# {
127 gbooleancxx . . $ gboolean# admincxx . . $ janus_nanomsg_client#admin.; /* Whether this client is for the Admin or Janus API */
128 GAsyncQueuecxx . . $ GAsyncQueue# *messagescxx . . $ janus_nanomsg_client#messages.; /* Queue of outgoing messages to push */
129 janus_transport_sessioncxx . . $ janus_transport_session# *tscxx . . $ janus_nanomsg_client#ts.; /* Janus core-transport session */
130 } janus_nanomsg_clientcxx . . $ janus_nanomsg_client#;
131 /* We only handle a single client per API, since we use NN_PAIR and we bind locally */
132 static janus_nanomsg_clientcxx . . $ janus_nanomsg_client# clientcxx . . $ client., admin_clientcxx . . $ admin_client.;
133
134
135 /* Transport implementation */
136 int janus_nanomsg_initcxx . . $ janus_nanomsg_init(b353b9c8d404ddc).(janus_transport_callbackscxx . . $ janus_transport_callbacks# *callback, const char *config_path) {
137 if(g_atomic_int_getcxx . . $ `<external>/742587799302188836/gatomic.h:109:9`!(&stopping)) {
138 /* Still stopping from before */
139 return -1;
140 }
141 if(callback == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`! || config_path == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!) {
142 /* Invalid arguments */
143 return -1;
144 }
145
146 /* This is the callback we'll need to invoke to contact the Janus core */
147 gatewaycxx . . $ gateway. = callback;
148
149 /* Read configuration */
150 char filename[255];
151 g_snprintfcxx . . $ g_snprintf(ea502d73e74c754c).(filename, 255, "%s/%s.jcfg", config_path, JANUS_NANOMSG_PACKAGEcxx . . $ `src/transports/janus_nanomsg.c:37:9`!);
152 JANUS_LOGcxx . . $ `src/debug.h:91:9`!(LOG_VERBcxx . . $ `src/debug.h:49:9`!, "Configuration file: %s\n", filename);
153 janus_configcxx . . $ janus_config# *config = janus_config_parsecxx . . $ janus_config_parse(569dd6a74ea9e7ee).(filename);
154 if(config == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!) {
155 JANUS_LOGcxx . . $ `src/debug.h:91:9`!(LOG_WARNcxx . . $ `src/debug.h:45:9`!, "Couldn't find .jcfg configuration file (%s), trying .cfg\n", JANUS_NANOMSG_PACKAGEcxx . . $ `src/transports/janus_nanomsg.c:37:9`!);
156 g_snprintfcxx . . $ g_snprintf(ea502d73e74c754c).(filename, 255, "%s/%s.cfg", config_path, JANUS_NANOMSG_PACKAGEcxx . . $ `src/transports/janus_nanomsg.c:37:9`!);
157 JANUS_LOGcxx . . $ `src/debug.h:91:9`!(LOG_VERBcxx . . $ `src/debug.h:49:9`!, "Configuration file: %s\n", filename);
158 config = janus_config_parsecxx . . $ janus_config_parse(569dd6a74ea9e7ee).(filename);
159 }
160 if(config != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!) {
161 /* Handle configuration */
162 janus_config_printcxx . . $ janus_config_print(95a2b4d96b3e84c9).(config);
163 janus_config_categorycxx . . $ janus_config_category# *config_general = janus_config_get_createcxx . . $ janus_config_get_create(7f9b951c745e015c).(config, NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!, janus_config_type_categorycxx . . $ janus_config_type_category., "general");
164 janus_config_categorycxx . . $ janus_config_category# *config_admin = janus_config_get_createcxx . . $ janus_config_get_create(7f9b951c745e015c).(config, NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!, janus_config_type_categorycxx . . $ janus_config_type_category., "admin");
165
166 janus_config_itemcxx . . $ janus_config_item# *item = janus_config_getcxx . . $ janus_config_get(7f9b951c745e015c).(config, config_general, janus_config_type_itemcxx . . $ janus_config_type_item., "json");
167 if(item && item->valuecxx . . $ janus_config_container#value.) {
168 /* Check how we need to format/serialize the JSON output */
169 if(!strcasecmpcxx . . $ strcasecmp(5ae29d726ae57f88).(item->valuecxx . . $ janus_config_container#value., "indented")) {
170 /* Default: indented, we use three spaces for that */
171 json_formatcxx . . $ json_format. = JSON_INDENTcxx . . $ `<external>/8172222224910760005/jansson.h:382:9`!(3) | JSON_PRESERVE_ORDERcxx . . $ `<external>/8172222224910760005/jansson.h:386:9`!;
172 } else if(!strcasecmpcxx . . $ strcasecmp(5ae29d726ae57f88).(item->valuecxx . . $ janus_config_container#value., "plain")) {
173 /* Not indented and no new lines, but still readable */
174 json_formatcxx . . $ json_format. = JSON_INDENTcxx . . $ `<external>/8172222224910760005/jansson.h:382:9`!(0) | JSON_PRESERVE_ORDERcxx . . $ `<external>/8172222224910760005/jansson.h:386:9`!;
175 } else if(!strcasecmpcxx . . $ strcasecmp(5ae29d726ae57f88).(item->valuecxx . . $ janus_config_container#value., "compact")) {
176 /* Compact, so no spaces between separators */
177 json_formatcxx . . $ json_format. = JSON_COMPACTcxx . . $ `<external>/8172222224910760005/jansson.h:383:9`! | JSON_PRESERVE_ORDERcxx . . $ `<external>/8172222224910760005/jansson.h:386:9`!;
178 } else {
179 JANUS_LOGcxx . . $ `src/debug.h:91:9`!(LOG_WARNcxx . . $ `src/debug.h:45:9`!, "Unsupported JSON format option '%s', using default (compact)\n", item->value);
180 json_formatcxx . . $ json_format. = JSON_COMPACTcxx . . $ `<external>/8172222224910760005/jansson.h:383:9`! | JSON_PRESERVE_ORDERcxx . . $ `<external>/8172222224910760005/jansson.h:386:9`!;
181 }
182 }
183
184 /* Check if we need to send events to handlers */
185 janus_config_itemcxx . . $ janus_config_item# *events = janus_config_getcxx . . $ janus_config_get(7f9b951c745e015c).(config, config_general, janus_config_type_itemcxx . . $ janus_config_type_item., "events");
186 if(events != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`! && events->valuecxx . . $ janus_config_container#value. != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!)
187 notify_eventscxx . . $ notify_events. = janus_is_truecxx . . $ janus_is_true(5c4306d8553b3696).(events->valuecxx . . $ janus_config_container#value.);
188 if(!notify_eventscxx . . $ notify_events. && callback->events_is_enabledcxx . . $ janus_transport_callbacks#events_is_enabled.()) {
189 JANUS_LOGcxx . . $ `src/debug.h:91:9`!(LOG_WARNcxx . . $ `src/debug.h:45:9`!, "Notification of events to handlers disabled for %s\n", JANUS_NANOMSG_NAMEcxx . . $ `src/transports/janus_nanomsg.c:35:9`!);
190 }
191
192 /* First of all, initialize the pipeline for writeable notifications */
193 write_nfdcxx . . $ write_nfd.[0] = nn_socketcxx . . $ nn_socket(9b79fb6aee4c0440).(AF_SPcxx . . $ `<external>/13568548034321366761/nn.h:310:9`!, NN_PULLcxx . . $ `<external>/4028107603240996394/pipeline.h:34:9`!);
194 write_nfdcxx . . $ write_nfd.[1] = nn_socketcxx . . $ nn_socket(9b79fb6aee4c0440).(AF_SPcxx . . $ `<external>/13568548034321366761/nn.h:310:9`!, NN_PUSHcxx . . $ `<external>/4028107603240996394/pipeline.h:33:9`!);
195 if(nn_bindcxx . . $ nn_bind(95e580389a7cc305).(write_nfdcxx . . $ write_nfd.[0], "inproc://janus") < 0) {
196 JANUS_LOGcxx . . $ `src/debug.h:91:9`!(LOG_WARNcxx . . $ `src/debug.h:45:9`!, "Error configuring internal Nanomsg pipeline... %d (%s)\n", errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`!, nn_strerror(errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`!));
197 return -1; /* No point in keeping the plugin loaded */
198 }
199 if(nn_connectcxx . . $ nn_connect(95e580389a7cc305).(write_nfdcxx . . $ write_nfd.[1], "inproc://janus") < 0) {
200 JANUS_LOGcxx . . $ `src/debug.h:91:9`!(LOG_WARNcxx . . $ `src/debug.h:45:9`!, "Error configuring internal Nanomsg pipeline...%d (%s)\n", errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`!, nn_strerror(errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`!));
201 return -1; /* No point in keeping the plugin loaded */
202 }
203
204 /* Setup the Janus API Nanomsg server(s) */
205 item = janus_config_getcxx . . $ janus_config_get(7f9b951c745e015c).(config, config_general, janus_config_type_itemcxx . . $ janus_config_type_item., "enabled");
206 if(!item || !item->valuecxx . . $ janus_config_container#value. || !janus_is_truecxx . . $ janus_is_true(5c4306d8553b3696).(item->valuecxx . . $ janus_config_container#value.)) {
207 JANUS_LOGcxx . . $ `src/debug.h:91:9`!(LOG_VERBcxx . . $ `src/debug.h:49:9`!, "Nanomsg server disabled (Janus API)\n");
208 } else {
209 item = janus_config_getcxx . . $ janus_config_get(7f9b951c745e015c).(config, config_general, janus_config_type_itemcxx . . $ janus_config_type_item., "address");
210 const char *address = item && item->valuecxx . . $ janus_config_container#value. ? item->valuecxx . . $ janus_config_container#value. : NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!;
211 item = janus_config_getcxx . . $ janus_config_get(7f9b951c745e015c).(config, config_general, janus_config_type_itemcxx . . $ janus_config_type_item., "mode");
212 const char *mode = item && item->valuecxx . . $ janus_config_container#value. ? item->valuecxx . . $ janus_config_container#value. : NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!;
213 if(mode == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!)
214 mode = "bind";
215 nfdcxx . . $ nfd. = nn_socketcxx . . $ nn_socket(9b79fb6aee4c0440).(AF_SPcxx . . $ `<external>/13568548034321366761/nn.h:310:9`!, NN_PAIRcxx . . $ `<external>/13145009363815210213/pair.h:32:9`!);
216 if(nfdcxx . . $ nfd. < 0) {
217 JANUS_LOGcxx . . $ `src/debug.h:91:9`!(LOG_ERRcxx . . $ `src/debug.h:43:9`!, "Error creating Janus API Nanomsg socket: %d (%s)\n", errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`!, nn_strerror(errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`!));
218 } else {
219 if(!strcasecmpcxx . . $ strcasecmp(5ae29d726ae57f88).(mode, "bind")) {
220 /* Bind to this address */
221 nfd_addrcxx . . $ nfd_addr. = nn_bindcxx . . $ nn_bind(95e580389a7cc305).(nfdcxx . . $ nfd., address);
222 if(nfd_addrcxx . . $ nfd_addr. < 0) {
223 JANUS_LOGcxx . . $ `src/debug.h:91:9`!(LOG_ERRcxx . . $ `src/debug.h:43:9`!, "Error binding Janus API Nanomsg socket to address '%s': %d (%s)\n",
224 address, errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`!, nn_strerror(errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`!));
225 nn_closecxx . . $ nn_close(7864480464b09eea).(nfdcxx . . $ nfd.);
226 nfdcxx . . $ nfd. = -1;
227 }
228 } else if(!strcasecmpcxx . . $ strcasecmp(5ae29d726ae57f88).(mode, "connect")) {
229 /* Connect to this address */
230 nfd_addrcxx . . $ nfd_addr. = nn_connectcxx . . $ nn_connect(95e580389a7cc305).(nfdcxx . . $ nfd., address);
231 if(nfd_addrcxx . . $ nfd_addr. < 0) {
232 JANUS_LOGcxx . . $ `src/debug.h:91:9`!(LOG_ERRcxx . . $ `src/debug.h:43:9`!, "Error connecting Janus API Nanomsg socket to address '%s': %d (%s)\n",
233 address, errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`!, nn_strerror(errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`!));
234 nn_closecxx . . $ nn_close(7864480464b09eea).(nfdcxx . . $ nfd.);
235 nfdcxx . . $ nfd. = -1;
236 }
237 } else {
238 /* Unsupported mode */
239 JANUS_LOGcxx . . $ `src/debug.h:91:9`!(LOG_ERRcxx . . $ `src/debug.h:43:9`!, "Unsupported mode '%s'\n", mode);
240 nn_closecxx . . $ nn_close(7864480464b09eea).(nfdcxx . . $ nfd.);
241 nfdcxx . . $ nfd. = -1;
242 }
243 }
244 }
245 /* Do the same for the Admin API, if enabled */
246 item = janus_config_getcxx . . $ janus_config_get(7f9b951c745e015c).(config, config_admin, janus_config_type_itemcxx . . $ janus_config_type_item., "admin_enabled");
247 if(!item || !item->valuecxx . . $ janus_config_container#value. || !janus_is_truecxx . . $ janus_is_true(5c4306d8553b3696).(item->valuecxx . . $ janus_config_container#value.)) {
248 JANUS_LOGcxx . . $ `src/debug.h:91:9`!(LOG_VERBcxx . . $ `src/debug.h:49:9`!, "Nanomsg server disabled (Admin API)\n");
249 } else {
250 item = janus_config_getcxx . . $ janus_config_get(7f9b951c745e015c).(config, config_admin, janus_config_type_itemcxx . . $ janus_config_type_item., "admin_address");
251 const char *address = item && item->valuecxx . . $ janus_config_container#value. ? item->valuecxx . . $ janus_config_container#value. : NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!;
252 item = janus_config_getcxx . . $ janus_config_get(7f9b951c745e015c).(config, config_admin, janus_config_type_itemcxx . . $ janus_config_type_item., "admin_mode");
253 const char *mode = item && item->valuecxx . . $ janus_config_container#value. ? item->valuecxx . . $ janus_config_container#value. : NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!;
254 if(mode == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!)
255 mode = "bind";
256 admin_nfdcxx . . $ admin_nfd. = nn_socketcxx . . $ nn_socket(9b79fb6aee4c0440).(AF_SPcxx . . $ `<external>/13568548034321366761/nn.h:310:9`!, NN_PAIRcxx . . $ `<external>/13145009363815210213/pair.h:32:9`!);
257 if(admin_nfdcxx . . $ admin_nfd. < 0) {
258 JANUS_LOGcxx . . $ `src/debug.h:91:9`!(LOG_ERRcxx . . $ `src/debug.h:43:9`!, "Error creating Admin API Nanomsg socket: %d (%s)\n", errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`!, nn_strerror(errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`!));
259 } else {
260 if(!strcasecmpcxx . . $ strcasecmp(5ae29d726ae57f88).(mode, "bind")) {
261 /* Bind to this address */
262 admin_nfd_addrcxx . . $ admin_nfd_addr. = nn_bindcxx . . $ nn_bind(95e580389a7cc305).(admin_nfdcxx . . $ admin_nfd., address);
263 if(admin_nfd_addrcxx . . $ admin_nfd_addr. < 0) {
264 JANUS_LOGcxx . . $ `src/debug.h:91:9`!(LOG_ERRcxx . . $ `src/debug.h:43:9`!, "Error binding Admin API Nanomsg socket to address '%s': %d (%s)\n",
265 address, errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`!, nn_strerror(errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`!));
266 nn_closecxx . . $ nn_close(7864480464b09eea).(admin_nfdcxx . . $ admin_nfd.);
267 admin_nfdcxx . . $ admin_nfd. = -1;
268 }
269 } else if(!strcasecmpcxx . . $ strcasecmp(5ae29d726ae57f88).(mode, "connect")) {
270 /* Connect to this address */
271 admin_nfd_addrcxx . . $ admin_nfd_addr. = nn_connectcxx . . $ nn_connect(95e580389a7cc305).(admin_nfdcxx . . $ admin_nfd., address);
272 if(admin_nfd_addrcxx . . $ admin_nfd_addr. < 0) {
273 JANUS_LOGcxx . . $ `src/debug.h:91:9`!(LOG_ERRcxx . . $ `src/debug.h:43:9`!, "Error connecting Admin API Nanomsg socket to address '%s': %d (%s)\n",
274 address, errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`!, nn_strerror(errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`!));
275 nn_closecxx . . $ nn_close(7864480464b09eea).(admin_nfdcxx . . $ admin_nfd.);
276 admin_nfdcxx . . $ admin_nfd. = -1;
277 }
278 } else {
279 /* Unsupported mode */
280 JANUS_LOGcxx . . $ `src/debug.h:91:9`!(LOG_ERRcxx . . $ `src/debug.h:43:9`!, "Unsupported mode '%s'\n", mode);
281 nn_closecxx . . $ nn_close(7864480464b09eea).(admin_nfdcxx . . $ admin_nfd.);
282 admin_nfdcxx . . $ admin_nfd. = -1;
283 }
284 }
285 }
286 }
287 janus_config_destroycxx . . $ janus_config_destroy(95a2b4d96b3e84c9).(config);
288 config = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!;
289 if(nfdcxx . . $ nfd. < 0 && admin_nfdcxx . . $ admin_nfd. < 0) {
290 JANUS_LOGcxx . . $ `src/debug.h:91:9`!(LOG_WARNcxx . . $ `src/debug.h:45:9`!, "No Nanomsg server started, giving up...\n");
291 return -1; /* No point in keeping the plugin loaded */
292 }
293
294 /* Create the clients */
295 memsetcxx . . $ memset(d1de1e4fb215f1c6).(&clientcxx . . $ client., 0, sizeof(janus_nanomsg_clientcxx . . $ janus_nanomsg_client#));
296 if(nfdcxx . . $ nfd. > -1) {
297 clientcxx . . $ client..admincxx . . $ janus_nanomsg_client#admin. = FALSEcxx . . $ `<external>/12741050725406041920/gmacros.h:967:9`!;
298 clientcxx . . $ client..messagescxx . . $ janus_nanomsg_client#messages. = g_async_queue_newcxx . . $ g_async_queue_new(33b7581b26599ba9).();
299 /* Create a transport instance as well */
300 clientcxx . . $ client..tscxx . . $ janus_nanomsg_client#ts. = janus_transport_session_createcxx . . $ janus_transport_session_create(90044deb547daced).(&clientcxx . . $ client., NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!);
301 /* Notify handlers about this new transport */
302 if(notify_eventscxx . . $ notify_events. && gatewaycxx . . $ gateway.->events_is_enabledcxx . . $ janus_transport_callbacks#events_is_enabled.()) {
303 json_tcxx . . $ json_t# *info = json_objectcxx . . $ json_object(ddf554718f1c8728).();
304 json_object_set_newcxx . . $ json_object_set_new(6a89ae69e2653183).(info, "event", json_stringcxx . . $ json_string(2f6de68c9404c25a).("created"));
305 json_object_set_newcxx . . $ json_object_set_new(6a89ae69e2653183).(info, "admin_api", json_falsecxx . . $ json_false(ddf554718f1c8728).());
306 json_object_set_newcxx . . $ json_object_set_new(6a89ae69e2653183).(info, "socket", json_integercxx . . $ json_integer(90ae68dba811b408).(nfdcxx . . $ nfd.));
307 gatewaycxx . . $ gateway.->notify_eventcxx . . $ janus_transport_callbacks#notify_event.(&janus_nanomsg_transportcxx . . $ janus_nanomsg_transport., clientcxx . . $ client..tscxx . . $ janus_nanomsg_client#ts., info);
308 }
309 }
310 memsetcxx . . $ memset(d1de1e4fb215f1c6).(&admin_clientcxx . . $ admin_client., 0, sizeof(janus_nanomsg_clientcxx . . $ janus_nanomsg_client#));
311 if(admin_nfdcxx . . $ admin_nfd. > -1) {
312 admin_clientcxx . . $ admin_client..admincxx . . $ janus_nanomsg_client#admin. = TRUEcxx . . $ `<external>/12741050725406041920/gmacros.h:971:9`!;
313 admin_clientcxx . . $ admin_client..messagescxx . . $ janus_nanomsg_client#messages. = g_async_queue_newcxx . . $ g_async_queue_new(33b7581b26599ba9).();
314 /* Create a transport instance as well */
315 admin_clientcxx . . $ admin_client..tscxx . . $ janus_nanomsg_client#ts. = janus_transport_session_createcxx . . $ janus_transport_session_create(90044deb547daced).(&admin_clientcxx . . $ admin_client., NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!);
316 /* Notify handlers about this new transport */
317 if(notify_eventscxx . . $ notify_events. && gatewaycxx . . $ gateway.->events_is_enabledcxx . . $ janus_transport_callbacks#events_is_enabled.()) {
318 json_tcxx . . $ json_t# *info = json_objectcxx . . $ json_object(ddf554718f1c8728).();
319 json_object_set_newcxx . . $ json_object_set_new(6a89ae69e2653183).(info, "event", json_stringcxx . . $ json_string(2f6de68c9404c25a).("created"));
320 json_object_set_newcxx . . $ json_object_set_new(6a89ae69e2653183).(info, "admin_api", json_truecxx . . $ json_true(ddf554718f1c8728).());
321 json_object_set_newcxx . . $ json_object_set_new(6a89ae69e2653183).(info, "socket", json_integercxx . . $ json_integer(90ae68dba811b408).(admin_nfdcxx . . $ admin_nfd.));
322 gatewaycxx . . $ gateway.->notify_eventcxx . . $ janus_transport_callbacks#notify_event.(&janus_nanomsg_transportcxx . . $ janus_nanomsg_transport., admin_clientcxx . . $ admin_client..tscxx . . $ janus_nanomsg_client#ts., info);
323 }
324 }
325
326 /* Start the Nanomsg service thread */
327 GErrorcxx . . $ GError# *error = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!;
328 nanomsg_threadcxx . . $ nanomsg_thread. = g_thread_try_newcxx . . $ g_thread_try_new(e63133a8f5fd7576).("nanomsg thread", &janus_nanomsg_threadcxx . . $ janus_nanomsg_thread(9f162e79bfc6c74)., NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!, &error);
329 if(error != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!) {
330 g_atomic_int_setcxx . . $ `<external>/742587799302188836/gatomic.h:117:9`!(&initialized, 0);
331 JANUS_LOGcxx . . $ `src/debug.h:91:9`!(LOG_ERRcxx . . $ `src/debug.h:43:9`!, "Got error %d (%s) trying to launch the Nanomsg thread...\n",
332 error->code, error->message ? error->message : "??");
333 g_error_freecxx . . $ g_error_free(2ff7d11a2ecc01bd).(error);
334 return -1;
335 }
336
337 /* Done */
338 g_atomic_int_setcxx . . $ `<external>/742587799302188836/gatomic.h:117:9`!(&initialized, 1);
339 JANUS_LOGcxx . . $ `src/debug.h:91:9`!(LOG_INFOcxx . . $ `src/debug.h:47:9`!, "%s initialized!\n", JANUS_NANOMSG_NAMEcxx . . $ `src/transports/janus_nanomsg.c:35:9`!);
340 return 0;
341 }
342
343 void janus_nanomsg_destroycxx . . $ janus_nanomsg_destroy(49f6e7a06ebc5aa8).(void) {
344 if(!g_atomic_int_getcxx . . $ `<external>/742587799302188836/gatomic.h:109:9`!(&initialized))
345 return;
346 g_atomic_int_setcxx . . $ `<external>/742587799302188836/gatomic.h:117:9`!(&stopping, 1);
347
348 /* Stop the service thread */
349 (void)nn_sendcxx . . $ nn_send(9d1ebb2cd9604347).(write_nfdcxx . . $ write_nfd.[1], "x", 1, 0);
350
351 if(nanomsg_threadcxx . . $ nanomsg_thread. != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!) {
352 g_thread_joincxx . . $ g_thread_join(cee1cddadd89739f).(nanomsg_threadcxx . . $ nanomsg_thread.);
353 nanomsg_threadcxx . . $ nanomsg_thread. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!;
354 }
355
356 g_atomic_int_setcxx . . $ `<external>/742587799302188836/gatomic.h:117:9`!(&initialized, 0);
357 g_atomic_int_setcxx . . $ `<external>/742587799302188836/gatomic.h:117:9`!(&stopping, 0);
358 JANUS_LOGcxx . . $ `src/debug.h:91:9`!(LOG_INFOcxx . . $ `src/debug.h:47:9`!, "%s destroyed!\n", JANUS_NANOMSG_NAMEcxx . . $ `src/transports/janus_nanomsg.c:35:9`!);
359 }
360
361 int janus_nanomsg_get_api_compatibilitycxx . . $ janus_nanomsg_get_api_compatibility(b126dc7c1de90089).(void) {
362 /* Important! This is what your plugin MUST always return: don't lie here or bad things will happen */
363 return JANUS_TRANSPORT_API_VERSIONcxx . . $ `src/transports/transport.h:100:9`!;
364 }
365
366 int janus_nanomsg_get_versioncxx . . $ janus_nanomsg_get_version(b126dc7c1de90089).(void) {
367 return JANUS_NANOMSG_VERSIONcxx . . $ `src/transports/janus_nanomsg.c:32:9`!;
368 }
369
370 const char *janus_nanomsg_get_version_stringcxx . . $ janus_nanomsg_get_version_string(33a1f659e94feb42).(void) {
371 return JANUS_NANOMSG_VERSION_STRINGcxx . . $ `src/transports/janus_nanomsg.c:33:9`!;
372 }
373
374 const char *janus_nanomsg_get_descriptioncxx . . $ janus_nanomsg_get_description(33a1f659e94feb42).(void) {
375 return JANUS_NANOMSG_DESCRIPTIONcxx . . $ `src/transports/janus_nanomsg.c:34:9`!;
376 }
377
378 const char *janus_nanomsg_get_namecxx . . $ janus_nanomsg_get_name(33a1f659e94feb42).(void) {
379 return JANUS_NANOMSG_NAMEcxx . . $ `src/transports/janus_nanomsg.c:35:9`!;
380 }
381
382 const char *janus_nanomsg_get_authorcxx . . $ janus_nanomsg_get_author(33a1f659e94feb42).(void) {
383 return JANUS_NANOMSG_AUTHORcxx . . $ `src/transports/janus_nanomsg.c:36:9`!;
384 }
385
386 const char *janus_nanomsg_get_packagecxx . . $ janus_nanomsg_get_package(33a1f659e94feb42).(void) {
387 return JANUS_NANOMSG_PACKAGEcxx . . $ `src/transports/janus_nanomsg.c:37:9`!;
388 }
389
390 gbooleancxx . . $ gboolean# janus_nanomsg_is_janus_api_enabledcxx . . $ janus_nanomsg_is_janus_api_enabled(b126dc7c1de90089).(void) {
391 return nfdcxx . . $ nfd. > -1;
392 }
393
394 gbooleancxx . . $ gboolean# janus_nanomsg_is_admin_api_enabledcxx . . $ janus_nanomsg_is_admin_api_enabled(b126dc7c1de90089).(void) {
395 return admin_nfdcxx . . $ admin_nfd. > -1;
396 }
397
398 int janus_nanomsg_send_messagecxx . . $ janus_nanomsg_send_message(6b64b6dff4e02fa6).(janus_transport_sessioncxx . . $ janus_transport_session# *transport, void *request_id, gbooleancxx . . $ gboolean# admin, json_tcxx . . $ json_t# *message) {
399 if(message == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!)
400 return -1;
401 /* Convert to string */
402 char *payload = json_dumpscxx . . $ json_dumps(2d3f8bb6f822a904).(message, json_formatcxx . . $ json_format.);
403 json_decrefcxx . . $ json_decref(f530285a7fd488d8).(message);
404 if(payload == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!) {
405 JANUS_LOGcxx . . $ `src/debug.h:91:9`!(LOG_ERRcxx . . $ `src/debug.h:43:9`!, "Failed to stringify message...\n");
406 return -1;
407 }
408 /* Enqueue the packet and have poll tell us when it's time to send it */
409 g_async_queue_pushcxx . . $ g_async_queue_push(fd2da36363e73393).(admin ? admin_clientcxx . . $ admin_client..messagescxx . . $ janus_nanomsg_client#messages. : clientcxx . . $ client..messagescxx . . $ janus_nanomsg_client#messages., payload);
410 /* Notify the thread there's data to send */
411 (void)nn_sendcxx . . $ nn_send(9d1ebb2cd9604347).(write_nfdcxx . . $ write_nfd.[1], "x", 1, 0);
412 return 0;
413 }
414
415 void janus_nanomsg_session_createdcxx . . $ janus_nanomsg_session_created(b5ed81ddbcd64883).(janus_transport_sessioncxx . . $ janus_transport_session# *transport, guint64cxx . . $ guint64# session_id) {
416 /* We don't care */
417 }
418
419 void janus_nanomsg_session_overcxx . . $ janus_nanomsg_session_over(c088a477eeb7160b).(janus_transport_sessioncxx . . $ janus_transport_session# *transport, guint64cxx . . $ guint64# session_id, gbooleancxx . . $ gboolean# timeout, gbooleancxx . . $ gboolean# claimed) {
420 /* We don't care */
421 }
422
423 void janus_nanomsg_session_claimedcxx . . $ janus_nanomsg_session_claimed(b5ed81ddbcd64883).(janus_transport_sessioncxx . . $ janus_transport_session# *transport, guint64cxx . . $ guint64# session_id) {
424 /* We don't care about this. We should start receiving messages from the core about this session: no action necessary */
425 /* FIXME Is the above statement accurate? Should we care? Unlike the HTTP transport, there is no hashtable to update */
426 }
427
428 json_tcxx . . $ json_t# *janus_nanomsg_query_transportcxx . . $ janus_nanomsg_query_transport(d6c74909b48cac1f).(json_tcxx . . $ json_t# *request) {
429 if(g_atomic_int_getcxx . . $ `<external>/742587799302188836/gatomic.h:109:9`!(&stopping) || !g_atomic_int_getcxx . . $ `<external>/742587799302188836/gatomic.h:109:9`!(&initialized)) {
430 return NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!;
431 }
432 /* We can use this request to dynamically change the behaviour of
433 * the transport plugin, and/or query for some specific information */
434 json_tcxx . . $ json_t# *response = json_objectcxx . . $ json_object(ddf554718f1c8728).();
435 int error_code = 0;
436 char error_cause[512];
437 JANUS_VALIDATE_JSON_OBJECTcxx . . $ `src/utils.h:304:9`!(request, request_parameters,
438 error_code, error_cause, TRUEcxx . . $ `<external>/12741050725406041920/gmacros.h:971:9`!,
439 JANUS_NANOMSG_ERROR_MISSING_ELEMENTcxx . . $ `src/transports/janus_nanomsg.c:111:9`!, JANUS_NANOMSG_ERROR_INVALID_ELEMENTcxx . . $ `src/transports/janus_nanomsg.c:112:9`!);
440 if(error_code != 0)
441 goto plugin_response;
442 /* Get the request */
443 const char *request_text = json_string_valuecxx . . $ json_string_value(85321e2e0e6e739).(json_object_getcxx . . $ json_object_get(d1dcf86e9b8660de).(request, "request"));
444 if(!strcasecmpcxx . . $ strcasecmp(5ae29d726ae57f88).(request_text, "configure")) {
445 /* We only allow for the configuration of some basic properties:
446 * changing more complex things (e.g., port to bind to, etc.)
447 * would likely require restarting backends, so just too much */
448 JANUS_VALIDATE_JSON_OBJECTcxx . . $ `src/utils.h:304:9`!(request, configure_parameters,
449 error_code, error_cause, TRUEcxx . . $ `<external>/12741050725406041920/gmacros.h:971:9`!,
450 JANUS_NANOMSG_ERROR_MISSING_ELEMENTcxx . . $ `src/transports/janus_nanomsg.c:111:9`!, JANUS_NANOMSG_ERROR_INVALID_ELEMENTcxx . . $ `src/transports/janus_nanomsg.c:112:9`!);
451 /* Check if we now need to send events to handlers */
452 json_object_set_newcxx . . $ json_object_set_new(6a89ae69e2653183).(response, "result", json_integercxx . . $ json_integer(90ae68dba811b408).(200));
453 json_tcxx . . $ json_t# *notes = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!;
454 gbooleancxx . . $ gboolean# events = json_is_truecxx . . $ `<external>/8172222224910760005/jansson.h:87:9`!(json_object_get(request, "events"));
455 if(events && !gatewaycxx . . $ gateway.->events_is_enabledcxx . . $ janus_transport_callbacks#events_is_enabled.()) {
456 /* Notify that this will be ignored */
457 notes = json_arraycxx . . $ json_array(ddf554718f1c8728).();
458 json_array_append_newcxx . . $ json_array_append_new(120152faeb96c420).(notes, json_stringcxx . . $ json_string(2f6de68c9404c25a).("Event handlers disabled at the core level"));
459 json_object_set_newcxx . . $ json_object_set_new(6a89ae69e2653183).(response, "notes", notes);
460 }
461 if(events != notify_eventscxx . . $ notify_events.) {
462 notify_eventscxx . . $ notify_events. = events;
463 if(!notify_eventscxx . . $ notify_events. && gatewaycxx . . $ gateway.->events_is_enabledcxx . . $ janus_transport_callbacks#events_is_enabled.()) {
464 JANUS_LOGcxx . . $ `src/debug.h:91:9`!(LOG_WARNcxx . . $ `src/debug.h:45:9`!, "Notification of events to handlers disabled for %s\n", JANUS_NANOMSG_NAMEcxx . . $ `src/transports/janus_nanomsg.c:35:9`!);
465 }
466 }
467 const char *indentation = json_string_valuecxx . . $ json_string_value(85321e2e0e6e739).(json_object_getcxx . . $ json_object_get(d1dcf86e9b8660de).(request, "json"));
468 if(indentation != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!) {
469 if(!strcasecmpcxx . . $ strcasecmp(5ae29d726ae57f88).(indentation, "indented")) {
470 /* Default: indented, we use three spaces for that */
471 json_formatcxx . . $ json_format. = JSON_INDENTcxx . . $ `<external>/8172222224910760005/jansson.h:382:9`!(3) | JSON_PRESERVE_ORDERcxx . . $ `<external>/8172222224910760005/jansson.h:386:9`!;
472 } else if(!strcasecmpcxx . . $ strcasecmp(5ae29d726ae57f88).(indentation, "plain")) {
473 /* Not indented and no new lines, but still readable */
474 json_formatcxx . . $ json_format. = JSON_INDENTcxx . . $ `<external>/8172222224910760005/jansson.h:382:9`!(0) | JSON_PRESERVE_ORDERcxx . . $ `<external>/8172222224910760005/jansson.h:386:9`!;
475 } else if(!strcasecmpcxx . . $ strcasecmp(5ae29d726ae57f88).(indentation, "compact")) {
476 /* Compact, so no spaces between separators */
477 json_formatcxx . . $ json_format. = JSON_COMPACTcxx . . $ `<external>/8172222224910760005/jansson.h:383:9`! | JSON_PRESERVE_ORDERcxx . . $ `<external>/8172222224910760005/jansson.h:386:9`!;
478 } else {
479 JANUS_LOGcxx . . $ `src/debug.h:91:9`!(LOG_WARNcxx . . $ `src/debug.h:45:9`!, "Unsupported JSON format option '%s', ignoring tweak\n", indentation);
480 /* Notify that this will be ignored */
481 if(notes == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!) {
482 notes = json_arraycxx . . $ json_array(ddf554718f1c8728).();
483 json_object_set_newcxx . . $ json_object_set_new(6a89ae69e2653183).(response, "notes", notes);
484 }
485 json_array_append_newcxx . . $ json_array_append_new(120152faeb96c420).(notes, json_stringcxx . . $ json_string(2f6de68c9404c25a).("Ignored unsupported indentation format"));
486 }
487 }
488 } else {
489 JANUS_LOGcxx . . $ `src/debug.h:91:9`!(LOG_VERBcxx . . $ `src/debug.h:49:9`!, "Unknown request '%s'\n", request_text);
490 error_code = JANUS_NANOMSG_ERROR_INVALID_REQUESTcxx . . $ `src/transports/janus_nanomsg.c:110:9`!;
491 g_snprintfcxx . . $ g_snprintf(ea502d73e74c754c).(error_cause, 512, "Unknown request '%s'", request_text);
492 }
493
494 plugin_response:
495 {
496 if(error_code != 0) {
497 /* Prepare JSON error event */
498 json_object_set_newcxx . . $ json_object_set_new(6a89ae69e2653183).(response, "error_code", json_integercxx . . $ json_integer(90ae68dba811b408).(error_code));
499 json_object_set_newcxx . . $ json_object_set_new(6a89ae69e2653183).(response, "error", json_stringcxx . . $ json_string(2f6de68c9404c25a).(error_cause));
500 }
501 return response;
502 }
503 }
504
505
506 /* Thread */
507 void *janus_nanomsg_threadcxx . . $ janus_nanomsg_thread(9f162e79bfc6c74).(void *data) {
508 JANUS_LOGcxx . . $ `src/debug.h:91:9`!(LOG_INFOcxx . . $ `src/debug.h:47:9`!, "Nanomsg thread started\n");
509
510 int fds = 0;
511 struct nn_pollfdcxx . . $ nn_pollfd# poll_nfds[3]; /* FIXME Should we allow for more clients? */
512 char buffer[BUFFER_SIZEcxx . . $ `src/transports/janus_nanomsg.c:99:9`!];
513
514 while(g_atomic_int_getcxx . . $ `<external>/742587799302188836/gatomic.h:109:9`!(&initialized) && !g_atomic_int_getcxx . . $ `<external>/742587799302188836/gatomic.h:109:9`!(&stopping)) {
515 /* Prepare poll list of file descriptors */
516 fds = 0;
517 /* Writeable monitor */
518 poll_nfds[fds].fdcxx . . $ nn_pollfd#fd. = write_nfdcxx . . $ write_nfd.[0];
519 poll_nfds[fds].eventscxx . . $ nn_pollfd#events. = NN_POLLINcxx . . $ `<external>/13568548034321366761/nn.h:364:9`!;
520 fds++;
521 if(nfdcxx . . $ nfd. > -1) {
522 /* Janus API */
523 poll_nfds[fds].fdcxx . . $ nn_pollfd#fd. = nfdcxx . . $ nfd.;
524 poll_nfds[fds].eventscxx . . $ nn_pollfd#events. = NN_POLLINcxx . . $ `<external>/13568548034321366761/nn.h:364:9`!;
525 if(clientcxx . . $ client..messagescxx . . $ janus_nanomsg_client#messages. != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`! && g_async_queue_lengthcxx . . $ g_async_queue_length(5a676b5b2a16ae3b).(clientcxx . . $ client..messagescxx . . $ janus_nanomsg_client#messages.) > 0)
526 poll_nfds[fds].eventscxx . . $ nn_pollfd#events. |= NN_POLLOUTcxx . . $ `<external>/13568548034321366761/nn.h:365:9`!;
527 fds++;
528 }
529 if(admin_nfdcxx . . $ admin_nfd. > -1) {
530 /* Admin API */
531 poll_nfds[fds].fdcxx . . $ nn_pollfd#fd. = admin_nfdcxx . . $ admin_nfd.;
532 poll_nfds[fds].eventscxx . . $ nn_pollfd#events. = NN_POLLINcxx . . $ `<external>/13568548034321366761/nn.h:364:9`!;
533 if(admin_clientcxx . . $ admin_client..messagescxx . . $ janus_nanomsg_client#messages. != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`! && g_async_queue_lengthcxx . . $ g_async_queue_length(5a676b5b2a16ae3b).(admin_clientcxx . . $ admin_client..messagescxx . . $ janus_nanomsg_client#messages.) > 0)
534 poll_nfds[fds].eventscxx . . $ nn_pollfd#events. |= NN_POLLOUTcxx . . $ `<external>/13568548034321366761/nn.h:365:9`!;
535 fds++;
536 }
537 /* Start polling */
538 int res = nn_pollcxx . . $ nn_poll(7ca859798f8df785).(poll_nfds, fds, -1);
539 if(res == 0)
540 continue;
541 if(res < 0) {
542 if(errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`! == EINTRcxx . . $ `<external>/8987895939074593727/errno-base.h:8:9`!) {
543 JANUS_LOGcxx . . $ `src/debug.h:91:9`!(LOG_HUGEcxx . . $ `src/debug.h:51:9`!, "Got an EINTR (%s) polling the Nanomsg descriptors, ignoring...\n", nn_strerror(errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`!));
544 continue;
545 }
546 JANUS_LOGcxx . . $ `src/debug.h:91:9`!(LOG_ERRcxx . . $ `src/debug.h:43:9`!, "poll() failed: %d (%s)\n", errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`!, nn_strerror(errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`!));
547 break;
548 }
549 int i = 0;
550 for(i=0; i<fds; i++) {
551 /* FIXME Is there a Nanomsg equivalent of POLLERR? */
552 if(poll_nfds[i].reventscxx . . $ nn_pollfd#revents. & NN_POLLOUTcxx . . $ `<external>/13568548034321366761/nn.h:365:9`!) {
553 /* Find the client from its file descriptor */
554 if(poll_nfds[i].fdcxx . . $ nn_pollfd#fd. == nfdcxx . . $ nfd. || poll_nfds[i].fdcxx . . $ nn_pollfd#fd. == admin_nfdcxx . . $ admin_nfd.) {
555 char *payload = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!;
556 while((payload = g_async_queue_try_popcxx . . $ g_async_queue_try_pop(624ec77f9da27fb1).(poll_nfds[i].fdcxx . . $ nn_pollfd#fd. == nfdcxx . . $ nfd. ? clientcxx . . $ client..messagescxx . . $ janus_nanomsg_client#messages. : admin_clientcxx . . $ admin_client..messagescxx . . $ janus_nanomsg_client#messages.)) != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!) {
557 int res = nn_sendcxx . . $ nn_send(9d1ebb2cd9604347).(poll_nfds[i].fdcxx . . $ nn_pollfd#fd., payload, strlencxx . . $ strlen(751346f8406fd082).(payload), 0);
558 /* FIXME Should we check if sent everything? */
559 JANUS_LOGcxx . . $ `src/debug.h:91:9`!(LOG_HUGEcxx . . $ `src/debug.h:51:9`!, "Written %d/%zu bytes on %d\n", res, strlen(payload), poll_nfds[i].fd);
560 freecxx . . $ free(5d22bdacc48458e8).(payload);
561 }
562 }
563 }
564 if(poll_nfds[i].reventscxx . . $ nn_pollfd#revents. & NN_POLLINcxx . . $ `<external>/13568548034321366761/nn.h:364:9`!) {
565 if(poll_nfds[i].fdcxx . . $ nn_pollfd#fd. == write_nfdcxx . . $ write_nfd.[0]) {
566 /* Read and ignore: we use this to unlock the poll if there's data to write */
567 (void)nn_recvcxx . . $ nn_recv(6076e73854a1e617).(poll_nfds[i].fdcxx . . $ nn_pollfd#fd., buffer, BUFFER_SIZEcxx . . $ `src/transports/janus_nanomsg.c:99:9`!, 0);
568 } else if(poll_nfds[i].fdcxx . . $ nn_pollfd#fd. == nfdcxx . . $ nfd. || poll_nfds[i].fdcxx . . $ nn_pollfd#fd. == admin_nfdcxx . . $ admin_nfd.) {
569 /* Janus/Admin API: get the message from the client */
570 int res = nn_recvcxx . . $ nn_recv(6076e73854a1e617).(poll_nfds[i].fdcxx . . $ nn_pollfd#fd., buffer, BUFFER_SIZEcxx . . $ `src/transports/janus_nanomsg.c:99:9`!, 0);
571 if(res < 0) {
572 JANUS_LOGcxx . . $ `src/debug.h:91:9`!(LOG_WARNcxx . . $ `src/debug.h:45:9`!, "Error receiving %s API message... %d (%s)\n",
573 poll_nfds[i].fd == nfd ? "Janus" : "Admin", errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`!, nn_strerror(errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`!));
574 continue;
575 }
576 /* If we got here, there's data to handle */
577 buffer[res] = '\0';
578 JANUS_LOGcxx . . $ `src/debug.h:91:9`!(LOG_VERBcxx . . $ `src/debug.h:49:9`!, "Got %s API message (%d bytes)\n",
579 poll_nfds[i].fd == nfd ? "Janus" : "Admin", res);
580 JANUS_LOGcxx . . $ `src/debug.h:91:9`!(LOG_HUGEcxx . . $ `src/debug.h:51:9`!, "%s\n", buffer);
581 /* Parse the JSON payload */
582 json_error_tcxx . . $ json_error_t# error;
583 json_tcxx . . $ json_t# *root = json_loadscxx . . $ json_loads(be2856bea7bd97c6).(buffer, 0, &error);
584 /* Notify the core, passing both the object and, since it may be needed, the error */
585 gatewaycxx . . $ gateway.->incoming_requestcxx . . $ janus_transport_callbacks#incoming_request.(&janus_nanomsg_transportcxx . . $ janus_nanomsg_transport.,
586 poll_nfds[i].fdcxx . . $ nn_pollfd#fd. == nfdcxx . . $ nfd. ? clientcxx . . $ client..tscxx . . $ janus_nanomsg_client#ts. : admin_clientcxx . . $ admin_client..tscxx . . $ janus_nanomsg_client#ts.,
587 NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!,
588 poll_nfds[i].fdcxx . . $ nn_pollfd#fd. == nfdcxx . . $ nfd. ? FALSEcxx . . $ `<external>/12741050725406041920/gmacros.h:967:9`! : TRUEcxx . . $ `<external>/12741050725406041920/gmacros.h:971:9`!,
589 root, &error);
590 }
591 }
592 }
593 }
594
595 nn_closecxx . . $ nn_close(7864480464b09eea).(write_nfdcxx . . $ write_nfd.[0]);
596 nn_closecxx . . $ nn_close(7864480464b09eea).(write_nfdcxx . . $ write_nfd.[1]);
597 if(nfdcxx . . $ nfd. > -1) {
598 nn_shutdowncxx . . $ nn_shutdown(9b79fb6aee4c0440).(nfdcxx . . $ nfd., nfd_addrcxx . . $ nfd_addr.);
599 nn_closecxx . . $ nn_close(7864480464b09eea).(nfdcxx . . $ nfd.);
600 janus_transport_session_destroycxx . . $ janus_transport_session_destroy(49b64b85178c1822).(clientcxx . . $ client..tscxx . . $ janus_nanomsg_client#ts.);
601 clientcxx . . $ client..tscxx . . $ janus_nanomsg_client#ts. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!;
602 }
603 if(admin_nfdcxx . . $ admin_nfd. > -1) {
604 nn_shutdowncxx . . $ nn_shutdown(9b79fb6aee4c0440).(admin_nfdcxx . . $ admin_nfd., admin_nfd_addrcxx . . $ admin_nfd_addr.);
605 nn_closecxx . . $ nn_close(7864480464b09eea).(admin_nfdcxx . . $ admin_nfd.);
606 janus_transport_session_destroycxx . . $ janus_transport_session_destroy(49b64b85178c1822).(admin_clientcxx . . $ admin_client..tscxx . . $ janus_nanomsg_client#ts.);
607 admin_clientcxx . . $ admin_client..tscxx . . $ janus_nanomsg_client#ts. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!;
608 }
609
610 /* Done */
611 JANUS_LOGcxx . . $ `src/debug.h:91:9`!(LOG_INFOcxx . . $ `src/debug.h:47:9`!, "Nanomsg thread ended\n");
612 return NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!;
613 }