Fixed #374055:Only the first "tag" is detected in digikam.
[beagle.git] / libbeagle / beagle / beagle-indexing-service-request.c
blob4e20bafb0d27e676e985364d9eeafe9a6cff47ab
1 /*
2 * beagle-indexing-service-request.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-indexing-service-request.h"
34 #include "beagle-private.h"
35 #include "beagle-empty-response.h"
37 #include <libxml/parser.h>
39 typedef struct {
40 const char *service_name;
41 GSList *to_add;
42 GSList *to_remove;
43 } BeagleIndexingServiceRequestPrivate;
45 #define BEAGLE_INDEXING_SERVICE_REQUEST_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), BEAGLE_TYPE_INDEXING_SERVICE_REQUEST, BeagleIndexingServiceRequestPrivate))
47 static GObjectClass *parent_class = NULL;
49 static GString *
50 beagle_indexing_service_request_to_xml (BeagleRequest *request, GError **err)
52 BeagleIndexingServiceRequestPrivate *priv = BEAGLE_INDEXING_SERVICE_REQUEST_GET_PRIVATE (request);
53 GString *data = g_string_new (NULL);
54 GSList *list;
56 _beagle_request_append_standard_header (data, priv->service_name);
58 g_string_append (data, "<ToAdd>");
60 for (list = priv->to_add; list != NULL; list = list->next) {
61 BeagleIndexable *indexable = list->data;
63 _beagle_indexable_to_xml (indexable, data);
66 g_string_append (data, "</ToAdd>");
68 g_string_append (data, "<ToRemove>");
70 for (list = priv->to_remove; list != NULL; list = list->next) {
71 char *str = list->data;
73 g_string_append_printf (data, "<string>%s</string>", str);
75 g_string_append (data, "</ToRemove>");
77 _beagle_request_append_standard_footer (data);
79 return data;
82 G_DEFINE_TYPE (BeagleIndexingServiceRequest, beagle_indexing_service_request, BEAGLE_TYPE_REQUEST)
84 static void
85 beagle_indexing_service_request_finalize (GObject *obj)
87 BeagleIndexingServiceRequestPrivate *priv = BEAGLE_INDEXING_SERVICE_REQUEST_GET_PRIVATE (obj);
89 g_slist_foreach (priv->to_add, (GFunc)beagle_indexable_free, NULL);
90 g_slist_free (priv->to_add);
92 g_slist_foreach (priv->to_remove, (GFunc)g_free, NULL);
93 g_slist_free (priv->to_remove);
95 if (G_OBJECT_CLASS (parent_class)->finalize)
96 G_OBJECT_CLASS (parent_class)->finalize (obj);
99 static void
100 beagle_indexing_service_request_class_init (BeagleIndexingServiceRequestClass *klass)
102 GObjectClass *obj_class = G_OBJECT_CLASS (klass);
103 BeagleRequestClass *request_class = BEAGLE_REQUEST_CLASS (klass);
105 parent_class = g_type_class_peek_parent (klass);
107 obj_class->finalize = beagle_indexing_service_request_finalize;
108 request_class->to_xml = beagle_indexing_service_request_to_xml;
110 g_type_class_add_private (klass, sizeof (BeagleIndexingServiceRequestPrivate));
112 _beagle_request_class_set_response_types (request_class,
113 "EmptyResponse",
114 BEAGLE_TYPE_EMPTY_RESPONSE,
115 NULL);
118 static void
119 beagle_indexing_service_request_init (BeagleIndexingServiceRequest *indexing_service_request)
123 BeagleIndexingServiceRequest *
124 beagle_indexing_service_request_new_for_service (const char *name)
126 BeagleIndexingServiceRequest *indexing_service_request = g_object_new (BEAGLE_TYPE_INDEXING_SERVICE_REQUEST, 0);
127 // should indexing_service_request be checked by g_return_if_fail ?
129 BeagleIndexingServiceRequestPrivate *priv;
130 priv = BEAGLE_INDEXING_SERVICE_REQUEST_GET_PRIVATE (indexing_service_request);
131 priv->service_name = name;
133 return indexing_service_request;
137 * beagle_indexing_service_request_new:
139 * Creates a new #BeagleIndexingServiceRequest.
141 * Return value: a newly created #BeagleIndexingServiceRequest.
143 BeagleIndexingServiceRequest *
144 beagle_indexing_service_request_new (void)
146 return beagle_indexing_service_request_new_for_service ("IndexingServiceRequest");
150 * beagle_indexing_service_request_add:
151 * @request: a #BeagleIndexingServiceRequest
152 * @indexable: a #BeagleIndexable
154 * Adds a #BeagleIndexable to the given #BeagleIndexingServiceRequest.
156 void
157 beagle_indexing_service_request_add (BeagleIndexingServiceRequest *request, BeagleIndexable *indexable)
159 BeagleIndexingServiceRequestPrivate *priv;
161 g_return_if_fail (BEAGLE_IS_INDEXING_SERVICE_REQUEST (request));
162 g_return_if_fail (indexable != NULL);
164 priv = BEAGLE_INDEXING_SERVICE_REQUEST_GET_PRIVATE (request);
166 priv->to_add = g_slist_prepend (priv->to_add, indexable);
170 * beagle_indexing_service_request_remove:
171 * @request: a #BeagleIndexingServiceRequest
172 * @uri: a string
174 * Adds the given @uri to the list of uris to be removed tothe given
175 * #BeagleIndexingServiceRequest.
177 void
178 beagle_indexing_service_request_remove (BeagleIndexingServiceRequest *request, const char *uri)
180 BeagleIndexingServiceRequestPrivate *priv;
182 g_return_if_fail (BEAGLE_IS_INDEXING_SERVICE_REQUEST (request));
183 g_return_if_fail (uri != NULL);
185 priv = BEAGLE_INDEXING_SERVICE_REQUEST_GET_PRIVATE (request);
187 priv->to_remove = g_slist_prepend (priv->to_remove, g_strdup (uri));