Greenbone Vulnerability Manager  22.4.0~dev1
gmp_get.h
1 /* Copyright (C) 2018-2022 Greenbone Networks GmbH
2  *
3  * SPDX-License-Identifier: AGPL-3.0-or-later
4  *
5  * This program is free software: you can redistribute it and/or modify
6  * it under the terms of the GNU Affero General Public License as
7  * published by the Free Software Foundation, either version 3 of the
8  * License, or (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU Affero General Public License for more details.
14  *
15  * You should have received a copy of the GNU Affero General Public License
16  * along with this program. If not, see <http://www.gnu.org/licenses/>.
17  */
18 
19 #ifndef _GVMD_GMP_GET_H
20 #define _GVMD_GMP_GET_H
21 
22 #include "manage_get.h"
23 
24 void
25 get_data_parse_attributes (get_data_t *, const gchar *, const gchar **,
26  const gchar **);
27 
28 int
29 init_get (gchar *, get_data_t *, const gchar *, int *);
30 
37 #define INIT_GET(type, capital) \
38  count = 0; \
39  ret = init_get ("get_" G_STRINGIFY (type) "s", &get_##type##s_data->get, \
40  G_STRINGIFY (capital) "s", &first); \
41  if (ret) \
42  { \
43  switch (ret) \
44  { \
45  case 99: \
46  SEND_TO_CLIENT_OR_FAIL (XML_ERROR_SYNTAX ( \
47  "get_" G_STRINGIFY (type) "s", "Permission denied")); \
48  break; \
49  default: \
50  internal_error_send_to_client (error); \
51  return; \
52  } \
53  get_##type##s_data_reset (get_##type##s_data); \
54  set_client_state (CLIENT_AUTHENTIC); \
55  return; \
56  }
57 
58 int
59 get_next (iterator_t *, get_data_t *, int *, int *,
60  int (*) (iterator_t *, const get_data_t *));
61 
62 int
63 send_get_start (const char *, int (*) (const char *, void *), void *);
64 
71 #define SEND_GET_START(type) \
72  do \
73  { \
74  if (send_get_start (type, gmp_parser->client_writer, \
75  gmp_parser->client_writer_data)) \
76  { \
77  error_send_to_client (error); \
78  return; \
79  } \
80  } \
81  while (0)
82 
83 int
84 send_get_common (const char *, get_data_t *, iterator_t *,
85  int (*) (const char *, void *), void *, int, int);
86 
94 #define SEND_GET_COMMON(type, get, iterator) \
95  do \
96  { \
97  if (send_get_common ( \
98  G_STRINGIFY (type), get, iterator, gmp_parser->client_writer, \
99  gmp_parser->client_writer_data, \
100  (get)->trash \
101  ? trash_##type##_writable (get_iterator_resource (iterator)) \
102  : type##_writable (get_iterator_resource (iterator)), \
103  (get)->trash \
104  ? trash_##type##_in_use (get_iterator_resource (iterator)) \
105  : type##_in_use (get_iterator_resource (iterator)))) \
106  { \
107  error_send_to_client (error); \
108  return; \
109  } \
110  } \
111  while (0)
112 
122 #define SEND_GET_COMMON_NO_TRASH(type, get, iterator) \
123  do \
124  { \
125  if (send_get_common (G_STRINGIFY (type), get, iterator, \
126  gmp_parser->client_writer, \
127  gmp_parser->client_writer_data, \
128  type##_writable (get_iterator_resource (iterator)), \
129  type##_in_use (get_iterator_resource (iterator)))) \
130  { \
131  error_send_to_client (error); \
132  return; \
133  } \
134  } \
135  while (0)
136 
137 int
138 buffer_get_filter_xml (GString *, const char *, const get_data_t *,
139  const char *, const char *);
140 
141 int
142 send_get_end (const char *, get_data_t *, int, int, int,
143  int (*) (const char *, void *), void *);
144 
145 int
146 send_get_end_no_counts (const char *, get_data_t *,
147  int (*) (const char *, void *), void *);
148 
155 #define SEND_GET_END(type, get, count, filtered) \
156  do \
157  { \
158  if (send_get_end (type, get, count, filtered, \
159  resource_count (type, get), gmp_parser->client_writer, \
160  gmp_parser->client_writer_data)) \
161  { \
162  error_send_to_client (error); \
163  return; \
164  } \
165  } \
166  while (0)
167 
168 #endif /* not _GVMD_GMP_GET_H */
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
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:311
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:477
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:271
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:227
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
int init_get(gchar *command, get_data_t *get, const gchar *setting_name, int *first)
Init for a GET handler.
Definition: gmp_get.c:101
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:48
Command data for a get command.
Definition: manage_get.h:35
A generic SQL iterator structure.
Definition: iterator.h:50