OpenVAS Manager  7.0.3~git
ovas-mngr-comm.c File Reference

API for communication between openvas-manager and openvas-server. More...

#include <errno.h>
#include <fcntl.h>
#include <glib.h>
#include <netinet/in.h>
#include <string.h>
#include <sys/socket.h>
#include <sys/types.h>
#include <unistd.h>
#include "logf.h"
Include dependency graph for ovas-mngr-comm.c:

Go to the source code of this file.

Macros

#define G_LOG_DOMAIN   "md comm"
 GLib log domain. More...
 

Functions

unsigned int to_server_buffer_space ()
 Get the number of characters free in the server output buffer. More...
 
int sendn_to_server (const void *msg, size_t n)
 Send a number of bytes to the server. More...
 
int send_to_server (const char *msg)
 Send a message to the server. More...
 
int sendf_to_server (const char *format,...)
 Format and send a message to the server. More...
 

Detailed Description

API for communication between openvas-manager and openvas-server.

This file contains an API for communicating with an openvas-server which uses OTP as protocol.

Definition in file ovas-mngr-comm.c.

Macro Definition Documentation

◆ G_LOG_DOMAIN

#define G_LOG_DOMAIN   "md comm"

GLib log domain.

Todo:
Consider moving to libs (so please leave "server" in the names).

Definition at line 52 of file ovas-mngr-comm.c.

Function Documentation

◆ send_to_server()

int send_to_server ( const char *  msg)

Send a message to the server.

Parameters
[in]msgThe message, a string.
Returns
0 for success, any other value for failure.

Definition at line 128 of file ovas-mngr-comm.c.

References sendn_to_server().

Referenced by acknowledge_bye(), acknowledge_feed_version_info(), manage_check_current_task(), and sendf_to_server().

129 {
130  return sendn_to_server (msg, strlen (msg));
131 }
int sendn_to_server(const void *msg, size_t n)
Send a number of bytes to the server.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ sendf_to_server()

int sendf_to_server ( const char *  format,
  ... 
)

Format and send a message to the server.

Parameters
[in]formatprintf-style format string for message.
Returns
0 for success, any other value for failure.

Definition at line 141 of file ovas-mngr-comm.c.

References send_to_server().

142 {
143  va_list args;
144  gchar* msg;
145  int ret;
146  va_start (args, format);
147  msg = g_strdup_vprintf (format, args);
148  ret = send_to_server (msg);
149  g_free (msg);
150  va_end (args);
151  return ret;
152 }
int send_to_server(const char *msg)
Send a message to the server.
Here is the call graph for this function:

◆ sendn_to_server()

int sendn_to_server ( const void *  msg,
size_t  n 
)

Send a number of bytes to the server.

Parameters
[in]msgThe message, a sequence of bytes.
[in]nThe number of bytes from msg to send.
Returns
0 for success, any other value for failure.

Definition at line 103 of file ovas-mngr-comm.c.

References to_server, and to_server_end.

Referenced by send_to_server().

104 {
105  if (TO_SERVER_BUFFER_SIZE - to_server_end < n)
106  {
107  g_debug (" sendn_to_server: available space (%i) < n (%zu)\n",
108  TO_SERVER_BUFFER_SIZE - to_server_end, n);
109  return 1;
110  }
111 
112  memmove (to_server + to_server_end, msg, n);
113  g_debug ("s> server (string) %.*s\n", (int) n, to_server + to_server_end);
114  g_debug ("-> server %zu bytes\n", n);
115  to_server_end += n;
116 
117  return 0;
118 }
char to_server[]
int to_server_end
Here is the caller graph for this function:

◆ to_server_buffer_space()

unsigned int to_server_buffer_space ( )

Get the number of characters free in the server output buffer.

Returns
Number of characters free in server output buffer. 0 when full.

Definition at line 88 of file ovas-mngr-comm.c.

References to_server_end, and to_server_start.

89 {
90  if (to_server_end < to_server_start) abort ();
91  return (unsigned int) (to_server_end - to_server_start);
92 }
int to_server_end
int to_server_start