19 #ifndef _GVMD_GMP_BASE_H
20 #define _GVMD_GMP_BASE_H
29 int (*client_writer) (
const char *,
void *);
38 find_attribute (
const gchar **,
const gchar **,
const char *,
const gchar **);
47 send_to_client (
const char *,
int (*) (
const char *,
void *),
void *);
69 #define SENDF_TO_CLIENT_OR_FAIL_WITH_RETURN(err_ret, format, args...) \
72 gchar *msg = g_markup_printf_escaped (format, ##args); \
73 if (send_to_client (msg, gmp_parser->client_writer, \
74 gmp_parser->client_writer_data)) \
77 error_send_to_client (error); \
93 #define SENDF_TO_CLIENT_OR_FAIL(format, args...) \
96 gchar *msg = g_markup_printf_escaped (format, ##args); \
97 if (send_to_client (msg, gmp_parser->client_writer, \
98 gmp_parser->client_writer_data)) \
101 error_send_to_client (error); \
116 #define SEND_TO_CLIENT_OR_FAIL(msg) \
119 if (send_to_client (msg, gmp_parser->client_writer, \
120 gmp_parser->client_writer_data)) \
122 error_send_to_client (error); \
129 log_event (
const char *,
const char *,
const char *,
const char *)
133 log_event_fail (
const char *,
const char *,
const char *,
const char *);
150 #define STATUS_ERROR_SYNTAX "400"
155 #define STATUS_ERROR_MUST_AUTH "401"
160 #define STATUS_ERROR_MUST_AUTH_TEXT "Authenticate first"
165 #define STATUS_ERROR_ACCESS "403"
170 #define STATUS_ERROR_ACCESS_TEXT "Access to resource forbidden"
175 #define STATUS_ERROR_MISSING "404"
180 #define STATUS_ERROR_MISSING_TEXT "Resource missing"
185 #define STATUS_ERROR_BUSY "409"
190 #define STATUS_ERROR_BUSY_TEXT "Resource busy"
195 #define STATUS_ERROR_AUTH_FAILED "400"
200 #define STATUS_ERROR_AUTH_FAILED_TEXT "Authentication failed"
205 #define STATUS_OK "200"
210 #define STATUS_OK_TEXT "OK"
215 #define STATUS_OK_CREATED "201"
220 #define STATUS_OK_CREATED_TEXT "OK, resource created"
225 #define STATUS_OK_REQUESTED "202"
230 #define STATUS_OK_REQUESTED_TEXT "OK, request submitted"
235 #define STATUS_INTERNAL_ERROR "500"
240 #define STATUS_INTERNAL_ERROR_TEXT "Internal error"
245 #define STATUS_SERVICE_UNAVAILABLE "503"
250 #define STATUS_SERVICE_DOWN "503"
255 #define STATUS_SERVICE_DOWN_TEXT "Service temporarily down"
263 #define XML_ERROR_SYNTAX(tag, text) \
264 "<" tag "_response" \
265 " status=\"" STATUS_ERROR_SYNTAX "\"" \
266 " status_text=\"" text "\"/>"
273 #define XML_ERROR_ACCESS(tag) \
274 "<" tag "_response" \
275 " status=\"" STATUS_ERROR_ACCESS "\"" \
276 " status_text=\"" STATUS_ERROR_ACCESS_TEXT "\"/>"
284 #define XML_ERROR_UNAVAILABLE(tag, text) \
285 "<" tag "_response" \
286 " status=\"" STATUS_SERVICE_UNAVAILABLE "\"" \
287 " status_text=\"" text "\"/>"
294 #define XML_ERROR_MISSING(tag) \
295 "<" tag "_response" \
296 " status=\"" STATUS_ERROR_MISSING "\"" \
297 " status_text=\"" STATUS_ERROR_MISSING_TEXT "\"/>"
304 #define XML_ERROR_AUTH_FAILED(tag) \
305 "<" tag "_response" \
306 " status=\"" STATUS_ERROR_AUTH_FAILED "\"" \
307 " status_text=\"" STATUS_ERROR_AUTH_FAILED_TEXT "\"/>"
314 #define XML_ERROR_BUSY(tag) \
315 "<" tag "_response" \
316 " status=\"" STATUS_ERROR_BUSY "\"" \
317 " status_text=\"" STATUS_ERROR_BUSY_TEXT "\"/>"
324 #define XML_OK(tag) \
325 "<" tag "_response" \
326 " status=\"" STATUS_OK "\"" \
327 " status_text=\"" STATUS_OK_TEXT "\"/>"
334 #define XML_OK_CREATED(tag) \
335 "<" tag "_response" \
336 " status=\"" STATUS_OK_CREATED "\"" \
337 " status_text=\"" STATUS_OK_CREATED_TEXT "\"/>"
344 #define XML_OK_CREATED_ID(tag) \
345 "<" tag "_response" \
346 " status=\"" STATUS_OK_CREATED "\"" \
347 " status_text=\"" STATUS_OK_CREATED_TEXT "\"" \
355 #define XML_OK_REQUESTED(tag) \
356 "<" tag "_response" \
357 " status=\"" STATUS_OK_REQUESTED "\"" \
358 " status_text=\"" STATUS_OK_REQUESTED_TEXT "\"/>"
365 #define XML_INTERNAL_ERROR(tag) \
366 "<" tag "_response" \
367 " status=\"" STATUS_INTERNAL_ERROR "\"" \
368 " status_text=\"" STATUS_INTERNAL_ERROR_TEXT "\"/>"
375 #define SEND_XML_SERVICE_DOWN(tag) \
380 g_strdup_printf ("<%s_response status='%s' status_text='%s'/>", tag, \
381 STATUS_SERVICE_DOWN, STATUS_SERVICE_DOWN_TEXT); \
382 SEND_TO_CLIENT_OR_FAIL (str); \
void error_send_to_client(GError **error)
Set an out of space parse error on a GError.
Definition: gmp_base.c:170
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:52
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:81
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:148
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:268
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:128
void internal_error_send_to_client(GError **error)
Set an internal error on a GError.
Definition: gmp_base.c:183
void buffer_xml_append_printf(GString *buffer, const char *format,...)
Format XML into a buffer.
Definition: gmp_base.c:104
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:253
__attribute__((deprecated))
Return if argument 1 matches regular expression in argument 2.
Definition: manage_pg_server.c:52
A handle on a GMP parser.
Definition: gmp_base.h:28
int parent_state
Parent state when reading over.
Definition: gmp_base.h:33
void * client_writer_data
Argument to client_writer.
Definition: gmp_base.h:30
int importing
Whether the current op is importing.
Definition: gmp_base.h:31
gchar ** disabled_commands
Disabled commands.
Definition: gmp_base.h:34
int read_over
Read over any child elements.
Definition: gmp_base.h:32