OpenVAS Scanner 23.23.1
ipc.c File Reference
#include "ipc.h"
#include "ipc_pipe.h"
#include <errno.h>
#include <fcntl.h>
#include <glib.h>
#include <gvm/base/logging.h>
#include <json-glib/json-glib.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <unistd.h>

Macros

#define G_LOG_DOMAIN   "lib misc"
 GLib logging domain.
#define IPC_CONTEXTS_CAP_STEP   10

Functions

int ipc_send (struct ipc_context *context, enum ipc_relation to, const char *msg, size_t len)
 sends given msg to the target based on the given context
int ipc_destroy (struct ipc_context *context)
 destroys given context
char * ipc_retrieve (struct ipc_context *context, enum ipc_relation from)
 retrieves data for the relation based on the context
int ipc_close (struct ipc_context *context)
 closes given context
struct ipc_contextipc_init (enum ipc_protocol type, enum ipc_relation relation)
 initializes a new context.
struct ipc_contextipc_exec_as_process (enum ipc_protocol type, struct ipc_exec_context exec_ctx)
 runs given functions with the given protocol type.
struct ipc_contextsipc_contexts_init (int cap)
 initializes ipc_contexts with a given preallocated capacity.
struct ipc_contextsipc_add_context (struct ipc_contexts *ctxs, struct ipc_context *ctx)
 adds a given context to contexts
int ipc_destroy_contexts (struct ipc_contexts *ctxs)
 destroys given contexts

Macro Definition Documentation

◆ G_LOG_DOMAIN

#define G_LOG_DOMAIN   "lib misc"

GLib logging domain.

◆ IPC_CONTEXTS_CAP_STEP

#define IPC_CONTEXTS_CAP_STEP   10

Function Documentation

◆ ipc_add_context()

struct ipc_contexts * ipc_add_context ( struct ipc_contexts * ctxs,
struct ipc_context * ctx )

adds a given context to contexts

Parameters
ctxsthe context holder array to be used to add a new ctx
ctxthe context to be added to ctxs
Returns
a pointer to the given ctxs or NULL on failure.

◆ ipc_close()

int ipc_close ( struct ipc_context * context)

closes given context

Parameters
contextthe ipc_context to be closed
Returns
-1 when context is either NULL or already closed or 0 on success.

◆ ipc_contexts_init()

struct ipc_contexts * ipc_contexts_init ( int cap)

initializes ipc_contexts with a given preallocated capacity.

Parameters
capto size to be preallocated, if 0 it will not preallocate but allocate on each enw entry.
Returns
a heap initialized contexts or NULL on failure.

◆ ipc_destroy()

int ipc_destroy ( struct ipc_context * context)

destroys given context

Parameters
contextthe ipc_context to be destroyed.
Returns
0 on success, -1 on context null or failure to destroy

◆ ipc_destroy_contexts()

int ipc_destroy_contexts ( struct ipc_contexts * ctxs)

destroys given contexts

Parameters
ctxsthe context holder array to be destroyed.
Returns
0 on success or -1 on failure.

◆ ipc_exec_as_process()

struct ipc_context * ipc_exec_as_process ( enum ipc_protocol type,
struct ipc_exec_context exec_ctx )

runs given functions with the given protocol type.

Parameters
typethe protocol type to be initialized
exec_ctxthe execution context to be executed.
Returns
a heap initialized context or NULL on failure.

◆ ipc_init()

struct ipc_context * ipc_init ( enum ipc_protocol type,
enum ipc_relation relation )

initializes a new context.

Parameters
typethe protocol type to be initialized
relationthe relation of the context to be initialized when supported by the type.
Returns
a heap initialized context or NULL on failure.

◆ ipc_retrieve()

char * ipc_retrieve ( struct ipc_context * context,
enum ipc_relation from )

retrieves data for the relation based on the context

Parameters
contextthe ipc_context to be used; must be previously initialized via ipc_init.
tothe recieving direction of the message when it is supported by the given ipc_context.
Returns
a heap initialized data or NULL

◆ ipc_send()

int ipc_send ( struct ipc_context * context,
enum ipc_relation to,
const char * msg,
size_t len )

sends given msg to the target based on the given context

Parameters
contextthe ipc_context to be used; must be previously initialized via ipc_init.
tothe target direction of the message when it is supported by the given ipc_context.
msgthe message to send
lenthe length of msg
Returns
bytes written, -2 when the context or msg or context type is unknown, -1 on write error