8#include <json-glib/json-glib.h>
13#define G_LOG_DOMAIN "lib misc"
150 const char *
hostname,
size_t hostname_len)
154 if (source == NULL ||
hostname == NULL)
156 if ((data = calloc (1,
sizeof (*data))) == NULL)
159 if ((hnd = calloc (1,
sizeof (*hnd))) == NULL)
162 hnd->
source = g_strdup (source);
202 gchar *ua_str = NULL;
207 if ((data = calloc (1,
sizeof (*data))) == NULL)
211 if ((uad = calloc (1,
sizeof (*uad))) == NULL)
255 if (data_ready != FALSE && data_ready != TRUE)
258 if ((data = calloc (1,
sizeof (*data))) == NULL)
262 if ((lscd = calloc (1,
sizeof (*lscd))) == NULL)
298 switch ((*data)->type)
327 JsonBuilder *builder;
342 builder = json_builder_new ();
344 json_builder_begin_object (builder);
346 json_builder_set_member_name (builder,
"type");
347 builder = json_builder_add_int_value (builder, type);
352 json_builder_set_member_name (builder,
"source");
353 builder = json_builder_add_string_value (builder, hn->
source);
354 json_builder_set_member_name (builder,
"hostname");
355 builder = json_builder_add_string_value (builder, hn->
hostname);
360 json_builder_set_member_name (builder,
"user-agent");
361 builder = json_builder_add_string_value (builder, ua->
user_agent);
366 json_builder_set_member_name (builder,
"data_ready");
367 builder = json_builder_add_boolean_value (builder, lsc->
data_ready);
371 g_warning (
"%s: Unknown data type %d.", __func__, type);
374 json_builder_end_object (builder);
376 gen = json_generator_new ();
377 root = json_builder_get_root (builder);
378 json_generator_set_root (gen, root);
379 json_str = json_generator_to_data (gen, NULL);
381 json_node_free (root);
382 g_object_unref (gen);
383 g_object_unref (builder);
385 if (json_str == NULL)
386 g_warning (
"%s: Error while creating JSON.", __func__);
402 JsonParser *parser = NULL;
403 JsonReader *reader = NULL;
413 if ((ret = calloc (1,
sizeof (*ret))) == NULL)
420 parser = json_parser_new ();
421 if (!json_parser_load_from_data (parser, json,
len, &err))
426 reader = json_reader_new (json_parser_get_root (parser));
428 if (!json_reader_read_member (reader,
"type"))
433 type = json_reader_get_int_value (reader);
435 json_reader_end_member (reader);
443 if ((hn = calloc (1,
sizeof (*hn))) == NULL)
445 if (!json_reader_read_member (reader,
"hostname"))
450 hn->
hostname = g_strdup (json_reader_get_string_value (reader));
452 json_reader_end_member (reader);
453 if (!json_reader_read_member (reader,
"source"))
458 hn->
source = g_strdup (json_reader_get_string_value (reader));
460 json_reader_end_member (reader);
466 if ((ua = calloc (1,
sizeof (*ua))) == NULL)
468 if (!json_reader_read_member (reader,
"user-agent"))
473 ua->
user_agent = g_strdup (json_reader_get_string_value (reader));
475 json_reader_end_member (reader);
480 if ((lsc = calloc (1,
sizeof (*lsc))) == NULL)
482 if (!json_reader_read_member (reader,
"data_ready"))
486 lsc->
data_ready = json_reader_get_boolean_value (reader);
487 json_reader_end_member (reader);
494 g_object_unref (reader);
495 g_object_unref (parser);
499 g_warning (
"%s: Unable to parse json (%s). Reason: %s", __func__, json,
ipc_data_t * ipc_data_from_json(const char *json, size_t len)
transforms json string to a ipc_data struct
Definition ipc_openvas.c:400
gchar * ipc_get_hostname_from_data(ipc_data_t *data)
Get the hostname from IPC data.
Definition ipc_openvas.c:82
struct ipc_hostname ipc_hostname_t
Definition ipc_openvas.c:26
enum ipc_data_type ipc_get_data_type_from_data(ipc_data_t *data)
Get the data type in data.
Definition ipc_openvas.c:67
static void ipc_user_agent_destroy(ipc_user_agent_t *data)
Free a user agent data structure.
Definition ipc_openvas.c:232
void ipc_data_destroy(ipc_data_t **data)
destroys ipc_data.
Definition ipc_openvas.c:294
ipc_data_t * ipc_data_type_from_lsc(gboolean data_ready)
initializes ipc_data for the table driven LSC.
Definition ipc_openvas.c:250
const char * ipc_data_to_json(ipc_data_t *data)
transforms ipc_data to a json string
Definition ipc_openvas.c:325
gchar * ipc_get_user_agent_from_data(ipc_data_t *data)
Get the User-Agent from IPC data.
Definition ipc_openvas.c:114
static void ipc_lsc_destroy(ipc_lsc_t *data)
Free a LSC data structure.
Definition ipc_openvas.c:280
gboolean ipc_get_lsc_data_ready_flag(ipc_data_t *data)
Get the package list from LSC IPC data.
Definition ipc_openvas.c:130
ipc_data_t * ipc_data_type_from_user_agent(const char *user_agent, size_t user_agent_len)
initializes ipc_data for the User-Agent.
Definition ipc_openvas.c:198
gchar * ipc_get_hostname_source_from_data(ipc_data_t *data)
Get the vhost hostname source from IPC data.
Definition ipc_openvas.c:98
struct ipc_lsc ipc_lsc_t
Definition ipc_openvas.c:43
static void ipc_hostname_destroy(ipc_hostname_t *data)
Free ipc_hostname_t data.
Definition ipc_openvas.c:178
struct ipc_user_agent ipc_user_agent_t
Definition ipc_openvas.c:35
ipc_data_t * ipc_data_type_from_hostname(const char *source, size_t source_len, const char *hostname, size_t hostname_len)
initializes ipc_data for a hostname data.
Definition ipc_openvas.c:149
struct ipc_data ipc_data_t
Definition ipc_openvas.h:23
ipc_data_type
Definition ipc_openvas.h:15
@ IPC_DT_NO_DATA
Definition ipc_openvas.h:17
@ IPC_DT_HOSTNAME
Definition ipc_openvas.h:18
@ IPC_DT_USER_AGENT
Definition ipc_openvas.h:19
@ IPC_DT_ERROR
Definition ipc_openvas.h:16
@ IPC_DT_LSC
Definition ipc_openvas.h:20
uint8_t len
Definition nasl_packet_forgery.c:1
const char * hostname
Definition pluginlaunch.c:68
Definition ipc_openvas.c:47
ipc_hostname_t * ipc_hostname
Definition ipc_openvas.c:52
enum ipc_data_type type
Definition ipc_openvas.c:48
ipc_user_agent_t * ipc_user_agent
Definition ipc_openvas.c:51
ipc_lsc_t * ipc_lsc
Definition ipc_openvas.c:53
Definition ipc_openvas.c:19
size_t hostname_len
Definition ipc_openvas.c:23
char * hostname
Definition ipc_openvas.c:21
char * source
Definition ipc_openvas.c:20
size_t source_len
Definition ipc_openvas.c:22
Definition ipc_openvas.c:39
gboolean data_ready
Definition ipc_openvas.c:40
Definition ipc_openvas.c:30
char * user_agent
Definition ipc_openvas.c:31
size_t user_agent_len
Definition ipc_openvas.c:32
static gchar * user_agent
user-agent, or NULL.
Definition user_agent.c:29