26 #ifndef _GVMD_GMP_BASE_H 27 #define _GVMD_GMP_BASE_H 36 int (*client_writer) (
const char *,
void *);
45 find_attribute (
const gchar **,
const gchar **,
const char *,
const gchar **);
54 send_to_client (
const char *,
int (*) (
const char *,
void *),
void *);
59 int (*) (
const char *,
void *),
83 #define SENDF_TO_CLIENT_OR_FAIL(format, args...) \ 86 gchar *msg = g_markup_printf_escaped (format, ##args); \ 87 if (send_to_client ( \ 88 msg, gmp_parser->client_writer, gmp_parser->client_writer_data)) \ 91 error_send_to_client (error); \ 106 #define SEND_TO_CLIENT_OR_FAIL(msg) \ 109 if (send_to_client ( \ 110 msg, gmp_parser->client_writer, gmp_parser->client_writer_data)) \ 112 error_send_to_client (error); \ 119 log_event (
const char *,
const char *,
const char *,
const char *);
122 log_event_fail (
const char *,
const char *,
const char *,
const char *);
139 #define STATUS_ERROR_SYNTAX "400" 144 #define STATUS_ERROR_MUST_AUTH "401" 149 #define STATUS_ERROR_MUST_AUTH_TEXT "Authenticate first" 154 #define STATUS_ERROR_ACCESS "403" 159 #define STATUS_ERROR_ACCESS_TEXT "Access to resource forbidden" 164 #define STATUS_ERROR_MISSING "404" 169 #define STATUS_ERROR_MISSING_TEXT "Resource missing" 174 #define STATUS_ERROR_BUSY "409" 179 #define STATUS_ERROR_BUSY_TEXT "Resource busy" 184 #define STATUS_ERROR_AUTH_FAILED "400" 189 #define STATUS_ERROR_AUTH_FAILED_TEXT "Authentication failed" 194 #define STATUS_OK "200" 199 #define STATUS_OK_TEXT "OK" 204 #define STATUS_OK_CREATED "201" 209 #define STATUS_OK_CREATED_TEXT "OK, resource created" 214 #define STATUS_OK_REQUESTED "202" 219 #define STATUS_OK_REQUESTED_TEXT "OK, request submitted" 224 #define STATUS_INTERNAL_ERROR "500" 229 #define STATUS_INTERNAL_ERROR_TEXT "Internal error" 234 #define STATUS_SERVICE_UNAVAILABLE "503" 239 #define STATUS_SERVICE_DOWN "503" 244 #define STATUS_SERVICE_DOWN_TEXT "Service temporarily down" 252 #define XML_ERROR_SYNTAX(tag, text) \ 253 "<" tag "_response" \ 254 " status=\"" STATUS_ERROR_SYNTAX "\"" \ 255 " status_text=\"" text "\"/>" 262 #define XML_ERROR_ACCESS(tag) \ 263 "<" tag "_response" \ 264 " status=\"" STATUS_ERROR_ACCESS "\"" \ 265 " status_text=\"" STATUS_ERROR_ACCESS_TEXT "\"/>" 273 #define XML_ERROR_UNAVAILABLE(tag, text) \ 274 "<" tag "_response" \ 275 " status=\"" STATUS_SERVICE_UNAVAILABLE "\"" \ 276 " status_text=\"" text "\"/>" 283 #define XML_ERROR_MISSING(tag) \ 284 "<" tag "_response" \ 285 " status=\"" STATUS_ERROR_MISSING "\"" \ 286 " status_text=\"" STATUS_ERROR_MISSING_TEXT "\"/>" 293 #define XML_ERROR_AUTH_FAILED(tag) \ 294 "<" tag "_response" \ 295 " status=\"" STATUS_ERROR_AUTH_FAILED "\"" \ 296 " status_text=\"" STATUS_ERROR_AUTH_FAILED_TEXT "\"/>" 303 #define XML_ERROR_BUSY(tag) \ 304 "<" tag "_response" \ 305 " status=\"" STATUS_ERROR_BUSY "\"" \ 306 " status_text=\"" STATUS_ERROR_BUSY_TEXT "\"/>" 313 #define XML_OK(tag) \ 314 "<" tag "_response" \ 315 " status=\"" STATUS_OK "\"" \ 316 " status_text=\"" STATUS_OK_TEXT "\"/>" 323 #define XML_OK_CREATED(tag) \ 324 "<" tag "_response" \ 325 " status=\"" STATUS_OK_CREATED "\"" \ 326 " status_text=\"" STATUS_OK_CREATED_TEXT "\"/>" 333 #define XML_OK_CREATED_ID(tag) \ 334 "<" tag "_response" \ 335 " status=\"" STATUS_OK_CREATED "\"" \ 336 " status_text=\"" STATUS_OK_CREATED_TEXT "\"" \ 344 #define XML_OK_REQUESTED(tag) \ 345 "<" tag "_response" \ 346 " status=\"" STATUS_OK_REQUESTED "\"" \ 347 " status_text=\"" STATUS_OK_REQUESTED_TEXT "\"/>" 354 #define XML_INTERNAL_ERROR(tag) \ 355 "<" tag "_response" \ 356 " status=\"" STATUS_INTERNAL_ERROR "\"" \ 357 " status_text=\"" STATUS_INTERNAL_ERROR_TEXT "\"/>" 364 #define SEND_XML_SERVICE_DOWN(tag) \ 368 if (scanner_current_loading && scanner_total_loading) \ 369 str = g_strdup_printf ("<%s_response status='%s' " \ 370 "status_text='Scanner loading nvts (%d/%d)'/>", \ 372 STATUS_SERVICE_DOWN, \ 373 scanner_current_loading, \ 374 scanner_total_loading); \ 376 str = g_strdup_printf ("<%s_response status='%s' status_text='%s'/>", \ 378 STATUS_SERVICE_DOWN, \ 379 STATUS_SERVICE_DOWN_TEXT); \ 380 SEND_TO_CLIENT_OR_FAIL (str); \ void log_event(const char *type, const char *type_name, const char *id, const char *action)
Creates a log event entry for a resource action.
Definition: gmp_base.c:300
gboolean send_element_error_to_client(const char *command, const char *element, int(*write_to_client)(const char *, void *), void *write_to_client_data)
Send an XML element error response message to the client.
Definition: gmp_base.c:154
gboolean send_to_client(const char *msg, int(*user_send_to_client)(const char *, void *), void *user_send_to_client_data)
Send a response message to the client.
Definition: gmp_base.c:134
int find_attribute(const gchar **attribute_names, const gchar **attribute_values, const char *attribute_name, const gchar **attribute_value)
Find an attribute in a parser callback list of attributes.
Definition: gmp_base.c:59
int parent_state
Parent state when reading over.
Definition: gmp_base.h:40
void log_event_fail(const char *type, const char *type_name, const char *id, const char *action)
Creates a log event failure entry for a resource action.
Definition: gmp_base.c:317
A handle on a GMP parser.
Definition: gmp_base.h:34
int append_attribute(const gchar **attribute_names, const gchar **attribute_values, const char *attribute_name, gchar **string)
Find an attribute in a parser callback list of attributes and append.
Definition: gmp_base.c:88
int read_over
Read over any child elements.
Definition: gmp_base.h:39
gboolean send_find_error_to_client(const char *command, const char *type, const char *id, gmp_parser_t *gmp_parser)
Send an XML find error response message to the client.
Definition: gmp_base.c:183
void error_send_to_client(GError **error)
Set an out of space parse error on a GError.
Definition: gmp_base.c:208
void internal_error_send_to_client(GError **error)
Set an internal error on a GError.
Definition: gmp_base.c:223
void buffer_xml_append_printf(GString *buffer, const char *format,...)
Format XML into a buffer.
Definition: gmp_base.c:111
void * client_writer_data
Argument to client_writer.
Definition: gmp_base.h:37
int importing
Whether the current op is importing.
Definition: gmp_base.h:38
gchar ** disabled_commands
Disabled commands.
Definition: gmp_base.h:41