Greenbone Vulnerability Manager  9.0.1
gmp_get.h
1 /* GVM
2  * $Id$
3  * Description: GVM GMP layer: Common GET command headers.
4  *
5  * Authors:
6  * Matthew Mundell <matthew.mundell@greenbone.net>
7  *
8  * Copyright:
9  * Copyright (C) 2018 Greenbone Networks GmbH
10  *
11  * This program is free software; you can redistribute it and/or
12  * modify it under the terms of the GNU General Public License
13  * as published by the Free Software Foundation; either version 2
14  * of the License, or (at your option) any later version.
15  *
16  * This program is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19  * GNU General Public License for more details.
20  *
21  * You should have received a copy of the GNU General Public License
22  * along with this program; if not, write to the Free Software
23  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
24  */
25 
26 #ifndef _GVMD_GMP_GET_H
27 #define _GVMD_GMP_GET_H
28 
29 #include "manage.h"
30 
31 void
32 get_data_parse_attributes (get_data_t *, const gchar *, const gchar **,
33  const gchar **);
34 
35 int
36 init_get (gchar *, get_data_t *, const gchar *, int *);
37 
44 #define INIT_GET(type, capital) \
45  count = 0; \
46  ret = init_get ("get_" G_STRINGIFY (type) "s", &get_##type##s_data->get, \
47  G_STRINGIFY (capital) "s", &first); \
48  if (ret) \
49  { \
50  switch (ret) \
51  { \
52  case 99: \
53  SEND_TO_CLIENT_OR_FAIL (XML_ERROR_SYNTAX ( \
54  "get_" G_STRINGIFY (type) "s", "Permission denied")); \
55  break; \
56  default: \
57  internal_error_send_to_client (error); \
58  return; \
59  } \
60  get_##type##s_data_reset (get_##type##s_data); \
61  set_client_state (CLIENT_AUTHENTIC); \
62  return; \
63  }
64 
65 int
66 get_next (iterator_t *, get_data_t *, int *, int *,
67  int (*) (iterator_t *, const get_data_t *));
68 
69 int
70 send_get_start (const char *, int (*) (const char *, void *), void *);
71 
78 #define SEND_GET_START(type) \
79  do \
80  { \
81  if (send_get_start (type, gmp_parser->client_writer, \
82  gmp_parser->client_writer_data)) \
83  { \
84  error_send_to_client (error); \
85  return; \
86  } \
87  } \
88  while (0)
89 
90 int
91 send_get_common (const char *, get_data_t *, iterator_t *,
92  int (*) (const char *, void *), void *, int, int);
93 
101 #define SEND_GET_COMMON(type, get, iterator) \
102  do \
103  { \
104  if (send_get_common ( \
105  G_STRINGIFY (type), get, iterator, gmp_parser->client_writer, \
106  gmp_parser->client_writer_data, \
107  (get)->trash \
108  ? trash_##type##_writable (get_iterator_resource (iterator)) \
109  : type##_writable (get_iterator_resource (iterator)), \
110  (get)->trash \
111  ? trash_##type##_in_use (get_iterator_resource (iterator)) \
112  : type##_in_use (get_iterator_resource (iterator)))) \
113  { \
114  error_send_to_client (error); \
115  return; \
116  } \
117  } \
118  while (0)
119 
129 #define SEND_GET_COMMON_NO_TRASH(type, get, iterator) \
130  do \
131  { \
132  if (send_get_common (G_STRINGIFY (type), get, iterator, \
133  gmp_parser->client_writer, \
134  gmp_parser->client_writer_data, \
135  type##_writable (get_iterator_resource (iterator)), \
136  type##_in_use (get_iterator_resource (iterator)))) \
137  { \
138  error_send_to_client (error); \
139  return; \
140  } \
141  } \
142  while (0)
143 
144 int
145 buffer_get_filter_xml (GString *, const char *, const get_data_t *,
146  const char *, const char *);
147 
148 int
149 send_get_end (const char *, get_data_t *, int, int, int,
150  int (*) (const char *, void *), void *);
151 
152 int
153 send_get_end_no_counts (const char *, get_data_t *,
154  int (*) (const char *, void *), void *);
155 
162 #define SEND_GET_END(type, get, count, filtered) \
163  do \
164  { \
165  if (send_get_end (type, get, count, filtered, \
166  resource_count (type, get), gmp_parser->client_writer, \
167  gmp_parser->client_writer_data)) \
168  { \
169  error_send_to_client (error); \
170  return; \
171  } \
172  } \
173  while (0)
174 
175 #endif /* not _GVMD_GMP_GET_H */
get_next
int get_next(iterator_t *resources, get_data_t *get, int *first, int *count, int(*init)(iterator_t *, const get_data_t *))
Iterate a GET iterator.
Definition: gmp_get.c:236
send_get_start
int send_get_start(const char *type, int(*write_to_client)(const char *, void *), void *write_to_client_data)
Send start of GET response.
Definition: gmp_get.c:280
send_get_end_no_counts
int send_get_end_no_counts(const char *type, get_data_t *get, int(*write_to_client)(const char *, void *), void *write_to_client_data)
Send end of GET response, skipping result counts.
Definition: gmp_get.c:732
init_get
int init_get(gchar *command, get_data_t *get, const gchar *setting_name, int *first)
Init for a GET handler.
Definition: gmp_get.c:110
iterator
A generic SQL iterator structure.
Definition: iterator.h:50
get_data_t
Command data for a get command.
Definition: manage.h:354
get_data_parse_attributes
void get_data_parse_attributes(get_data_t *data, const gchar *type, const gchar **attribute_names, const gchar **attribute_values)
Parse attributes for a GET command.
Definition: gmp_get.c:57
send_get_common
int send_get_common(const char *type, get_data_t *get, iterator_t *iterator, int(*write_to_client)(const char *, void *), void *write_to_client_data, int writable, int in_use)
Send common part of GET response for a single resource.
Definition: gmp_get.c:320
buffer_get_filter_xml
int buffer_get_filter_xml(GString *msg, const char *type, const get_data_t *get, const char *filter_term, const char *extra_xml)
Write data of a GET command filter to a string buffer as XML.
Definition: gmp_get.c:486
send_get_end
int send_get_end(const char *type, get_data_t *get, int count, int filtered, int full, int(*write_to_client)(const char *, void *), void *write_to_client_data)
Send end of GET response.
Definition: gmp_get.c:712