Dont add null mimetypes. Fixes bgo# 337431. The patch hasnt been officially accepted...
[beagle.git] / libbeagle / beagle / beagle-error-response.c
blob6bbe3131f89eec93e53c302f4a9ebc6e7b6b5821
1 /*
2 * beagle-error-response.c
4 * Copyright (C) 2005 Novell, Inc.
6 */
8 /*
9 * Permission is hereby granted, free of charge, to any person obtaining a
10 * copy of this software and associated documentation files (the "Software"),
11 * to deal in the Software without restriction, including without limitation
12 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
13 * and/or sell copies of the Software, and to permit persons to whom the
14 * Software is furnished to do so, subject to the following conditions:
16 * The above copyright notice and this permission notice shall be included in
17 * all copies or substantial portions of the Software.
19 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
24 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
25 * DEALINGS IN THE SOFTWARE.
28 #include <stdlib.h>
29 #include <sys/types.h>
30 #include <sys/socket.h>
31 #include <sys/un.h>
33 #include "beagle-error-response.h"
34 #include "beagle-private.h"
35 #include "beagle-util.h"
37 typedef struct {
38 char *message;
39 char *details;
40 } BeagleErrorResponsePrivate;
42 #define BEAGLE_ERROR_RESPONSE_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), BEAGLE_TYPE_ERROR_RESPONSE, BeagleErrorResponsePrivate))
44 static BeagleResponseClass *parent_class = NULL;
46 G_DEFINE_TYPE (BeagleErrorResponse, beagle_error_response, BEAGLE_TYPE_RESPONSE)
48 static void
49 beagle_error_response_finalize (GObject *obj)
51 BeagleErrorResponsePrivate *priv = BEAGLE_ERROR_RESPONSE_GET_PRIVATE (obj);
53 g_free (priv->message);
55 if (G_OBJECT_CLASS (parent_class)->finalize)
56 G_OBJECT_CLASS (parent_class)->finalize (obj);
59 static void
60 end_error_message (BeagleParserContext *ctx)
62 BeagleErrorResponse *response = BEAGLE_ERROR_RESPONSE (_beagle_parser_context_get_response (ctx));
63 BeagleErrorResponsePrivate *priv = BEAGLE_ERROR_RESPONSE_GET_PRIVATE (response);
65 priv->message = _beagle_parser_context_get_text_buffer (ctx);
68 static void
69 end_error_details (BeagleParserContext *ctx)
71 BeagleErrorResponse *response = BEAGLE_ERROR_RESPONSE (_beagle_parser_context_get_response (ctx));
72 BeagleErrorResponsePrivate *priv = BEAGLE_ERROR_RESPONSE_GET_PRIVATE (response);
74 priv->details = _beagle_parser_context_get_text_buffer (ctx);
77 enum {
78 PARSER_STATE_MESSAGE,
79 PARSER_STATE_DETAILS,
82 static BeagleParserHandler parser_handlers[] = {
83 { "Message",
84 -1,
85 PARSER_STATE_MESSAGE,
86 NULL,
87 end_error_message },
89 { "Details",
90 -1,
91 PARSER_STATE_DETAILS,
92 NULL,
93 end_error_details },
95 { 0 }
98 static void
99 beagle_error_response_class_init (BeagleErrorResponseClass *klass)
101 GObjectClass *obj_class = G_OBJECT_CLASS (klass);
103 parent_class = g_type_class_peek_parent (klass);
105 obj_class->finalize = beagle_error_response_finalize;
107 _beagle_response_class_set_parser_handlers (BEAGLE_RESPONSE_CLASS (klass),
108 parser_handlers);
110 g_type_class_add_private (klass, sizeof (BeagleErrorResponsePrivate));
113 static void
114 beagle_error_response_init (BeagleErrorResponse *response)
119 * beagle_error_response_get_message:
120 * @response: a #BeagleErrorResponse
122 * Get the message from given #BeagleErrorResponse.
124 * Return value: the error message from the #BeagleErrorResponse.
126 const char *
127 beagle_error_response_get_message (BeagleErrorResponse *response)
129 BeagleErrorResponsePrivate *priv;
131 g_return_val_if_fail (BEAGLE_IS_ERROR_RESPONSE (response), NULL);
133 priv = BEAGLE_ERROR_RESPONSE_GET_PRIVATE (response);
135 return priv->message;
139 * beagle_error_response_get_details:
140 * @response: a #BeagleErrorResponse
142 * Gets the error's details from given #BeagleErrorResponse.
144 * Return value: the error details from the #BeagleErrorResponse.
146 const char *
147 beagle_error_response_get_details (BeagleErrorResponse *response)
149 BeagleErrorResponsePrivate *priv;
151 g_return_val_if_fail (BEAGLE_IS_ERROR_RESPONSE (response), NULL);
153 priv = BEAGLE_ERROR_RESPONSE_GET_PRIVATE (response);
155 return priv->details;
159 void
160 _beagle_error_response_to_g_error (BeagleErrorResponse *response,
161 GError **error)
163 BeagleErrorResponsePrivate *priv;
165 priv = BEAGLE_ERROR_RESPONSE_GET_PRIVATE (response);
167 g_set_error (error, BEAGLE_ERROR, BEAGLE_ERROR_DAEMON_ERROR,
168 "%s", priv->message);