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 *);
75 #define SENDF_TO_CLIENT_OR_FAIL(format, args...) \ 78 gchar *msg = g_markup_printf_escaped (format, ##args); \ 79 if (send_to_client (msg, gmp_parser->client_writer, \ 80 gmp_parser->client_writer_data)) \ 83 error_send_to_client (error); \ 98 #define SEND_TO_CLIENT_OR_FAIL(msg) \ 101 if (send_to_client (msg, gmp_parser->client_writer, \ 102 gmp_parser->client_writer_data)) \ 104 error_send_to_client (error); \ 111 log_event (
const char *,
const char *,
const char *,
const char *)
112 __attribute__ ((weak));
115 log_event_fail (
const char *,
const char *,
const char *,
const char *);
132 #define STATUS_ERROR_SYNTAX "400" 137 #define STATUS_ERROR_MUST_AUTH "401" 142 #define STATUS_ERROR_MUST_AUTH_TEXT "Authenticate first" 147 #define STATUS_ERROR_ACCESS "403" 152 #define STATUS_ERROR_ACCESS_TEXT "Access to resource forbidden" 157 #define STATUS_ERROR_MISSING "404" 162 #define STATUS_ERROR_MISSING_TEXT "Resource missing" 167 #define STATUS_ERROR_BUSY "409" 172 #define STATUS_ERROR_BUSY_TEXT "Resource busy" 177 #define STATUS_ERROR_AUTH_FAILED "400" 182 #define STATUS_ERROR_AUTH_FAILED_TEXT "Authentication failed" 187 #define STATUS_OK "200" 192 #define STATUS_OK_TEXT "OK" 197 #define STATUS_OK_CREATED "201" 202 #define STATUS_OK_CREATED_TEXT "OK, resource created" 207 #define STATUS_OK_REQUESTED "202" 212 #define STATUS_OK_REQUESTED_TEXT "OK, request submitted" 217 #define STATUS_INTERNAL_ERROR "500" 222 #define STATUS_INTERNAL_ERROR_TEXT "Internal error" 227 #define STATUS_SERVICE_UNAVAILABLE "503" 232 #define STATUS_SERVICE_DOWN "503" 237 #define STATUS_SERVICE_DOWN_TEXT "Service temporarily down" 245 #define XML_ERROR_SYNTAX(tag, text) \ 246 "<" tag "_response" \ 247 " status=\"" STATUS_ERROR_SYNTAX "\"" \ 248 " status_text=\"" text "\"/>" 255 #define XML_ERROR_ACCESS(tag) \ 256 "<" tag "_response" \ 257 " status=\"" STATUS_ERROR_ACCESS "\"" \ 258 " status_text=\"" STATUS_ERROR_ACCESS_TEXT "\"/>" 266 #define XML_ERROR_UNAVAILABLE(tag, text) \ 267 "<" tag "_response" \ 268 " status=\"" STATUS_SERVICE_UNAVAILABLE "\"" \ 269 " status_text=\"" text "\"/>" 276 #define XML_ERROR_MISSING(tag) \ 277 "<" tag "_response" \ 278 " status=\"" STATUS_ERROR_MISSING "\"" \ 279 " status_text=\"" STATUS_ERROR_MISSING_TEXT "\"/>" 286 #define XML_ERROR_AUTH_FAILED(tag) \ 287 "<" tag "_response" \ 288 " status=\"" STATUS_ERROR_AUTH_FAILED "\"" \ 289 " status_text=\"" STATUS_ERROR_AUTH_FAILED_TEXT "\"/>" 296 #define XML_ERROR_BUSY(tag) \ 297 "<" tag "_response" \ 298 " status=\"" STATUS_ERROR_BUSY "\"" \ 299 " status_text=\"" STATUS_ERROR_BUSY_TEXT "\"/>" 306 #define XML_OK(tag) \ 307 "<" tag "_response" \ 308 " status=\"" STATUS_OK "\"" \ 309 " status_text=\"" STATUS_OK_TEXT "\"/>" 316 #define XML_OK_CREATED(tag) \ 317 "<" tag "_response" \ 318 " status=\"" STATUS_OK_CREATED "\"" \ 319 " status_text=\"" STATUS_OK_CREATED_TEXT "\"/>" 326 #define XML_OK_CREATED_ID(tag) \ 327 "<" tag "_response" \ 328 " status=\"" STATUS_OK_CREATED "\"" \ 329 " status_text=\"" STATUS_OK_CREATED_TEXT "\"" \ 337 #define XML_OK_REQUESTED(tag) \ 338 "<" tag "_response" \ 339 " status=\"" STATUS_OK_REQUESTED "\"" \ 340 " status_text=\"" STATUS_OK_REQUESTED_TEXT "\"/>" 347 #define XML_INTERNAL_ERROR(tag) \ 348 "<" tag "_response" \ 349 " status=\"" STATUS_INTERNAL_ERROR "\"" \ 350 " status_text=\"" STATUS_INTERNAL_ERROR_TEXT "\"/>" 357 #define SEND_XML_SERVICE_DOWN(tag) \ 362 g_strdup_printf ("<%s_response status='%s' status_text='%s'/>", tag, \ 363 STATUS_SERVICE_DOWN, STATUS_SERVICE_DOWN_TEXT); \ 364 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:260
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:135
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:275
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:155
void error_send_to_client(GError **error)
Set an out of space parse error on a GError.
Definition: gmp_base.c:177
void internal_error_send_to_client(GError **error)
Set an internal error on a GError.
Definition: gmp_base.c:190
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