OpenVAS Manager  7.0.3~git
ovas-mngr-comm.c
Go to the documentation of this file.
1 /* OpenVAS Manager
2  * $Id$
3  * Description: Module for OpenVAS Manager: the Comm Library.
4  *
5  * Authors:
6  * Matthew Mundell <matthew.mundell@greenbone.net>
7  * Jan-Oliver Wagner <jan-oliver.wagner@greenbone.net>
8  *
9  * Copyright:
10  * Copyright (C) 2009 Greenbone Networks GmbH
11  *
12  * This program is free software; you can redistribute it and/or
13  * modify it under the terms of the GNU General Public License
14  * as published by the Free Software Foundation; either version 2
15  * of the License, or (at your option) any later version.
16  *
17  * This program is distributed in the hope that it will be useful,
18  * but WITHOUT ANY WARRANTY; without even the implied warranty of
19  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20  * GNU General Public License for more details.
21  *
22  * You should have received a copy of the GNU General Public License
23  * along with this program; if not, write to the Free Software
24  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
25  */
26 
35 #include <errno.h>
36 #include <fcntl.h>
37 #include <glib.h>
38 #include <netinet/in.h>
39 #include <string.h>
40 #include <sys/socket.h>
41 #include <sys/types.h>
42 #include <unistd.h>
43 
44 #include "logf.h"
45 
48 #undef G_LOG_DOMAIN
49 
52 #define G_LOG_DOMAIN "md comm"
53 
59 #define TO_SERVER_BUFFER_SIZE 26214400
60 
68 char to_server[TO_SERVER_BUFFER_SIZE];
69 
73 int to_server_end = 0;
74 
78 int to_server_start = 0;
79 
87 unsigned int
89 {
90  if (to_server_end < to_server_start) abort ();
91  return (unsigned int) (to_server_end - to_server_start);
92 }
93 
102 int
103 sendn_to_server (const void * msg, size_t n)
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 }
119 
127 int
128 send_to_server (const char * msg)
129 {
130  return sendn_to_server (msg, strlen (msg));
131 }
132 
140 int
141 sendf_to_server (const char* format, ...)
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 }
153 
int sendn_to_server(const void *msg, size_t n)
Send a number of bytes to the server.
unsigned int to_server_buffer_space()
Get the number of characters free in the server output buffer.
int sendf_to_server(const char *format,...)
Format and send a message to the server.
int send_to_server(const char *msg)
Send a message to the server.
A printf like macro for logging communication.
char to_server[]
int to_server_end
int to_server_start