FilterHtml.cs: Add ExtractText(string) command to extract text out of large html...
[beagle.git] / libbeagle / beagle / beagle-hits-subtracted-response.c
blob7972f906d57df00edae7a68211fcf68dc6794e78
1 /*
2 * beagle-hits-subtracted-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-hits-subtracted-response.h"
34 #include "beagle-private.h"
36 typedef struct {
37 GSList *uris; /* of char * */
38 } BeagleHitsSubtractedResponsePrivate;
40 #define BEAGLE_HITS_SUBTRACTED_RESPONSE_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), BEAGLE_TYPE_HITS_SUBTRACTED_RESPONSE, BeagleHitsSubtractedResponsePrivate))
42 static BeagleResponseClass *parent_class = NULL;
44 G_DEFINE_TYPE (BeagleHitsSubtractedResponse, beagle_hits_subtracted_response, BEAGLE_TYPE_RESPONSE)
46 static void
47 beagle_hits_subtracted_response_finalize (GObject *obj)
49 BeagleHitsSubtractedResponsePrivate *priv = BEAGLE_HITS_SUBTRACTED_RESPONSE_GET_PRIVATE (obj);
51 g_slist_foreach (priv->uris, (GFunc)g_free, NULL);
52 g_slist_free (priv->uris);
54 if (G_OBJECT_CLASS (parent_class)->finalize)
55 G_OBJECT_CLASS (parent_class)->finalize (obj);
58 static void
59 end_uri (BeagleParserContext *ctx)
61 BeagleHitsSubtractedResponse *response = BEAGLE_HITS_SUBTRACTED_RESPONSE (_beagle_parser_context_get_response (ctx));
62 BeagleHitsSubtractedResponsePrivate *priv = BEAGLE_HITS_SUBTRACTED_RESPONSE_GET_PRIVATE (response);
64 priv->uris = g_slist_prepend (priv->uris, _beagle_parser_context_get_text_buffer (ctx));
67 enum {
68 PARSER_STATE_URIS,
69 PARSER_STATE_URI
72 static BeagleParserHandler parser_handlers[] = {
73 { "Uris",
74 -1,
75 PARSER_STATE_URIS,
76 NULL,
77 NULL },
78 { "Uri",
79 PARSER_STATE_URIS,
80 PARSER_STATE_URI,
81 NULL,
82 end_uri },
83 { 0 }
86 static void
87 beagle_hits_subtracted_response_class_init (BeagleHitsSubtractedResponseClass *klass)
89 GObjectClass *obj_class = G_OBJECT_CLASS (klass);
91 parent_class = g_type_class_peek_parent (klass);
93 obj_class->finalize = beagle_hits_subtracted_response_finalize;
95 _beagle_response_class_set_parser_handlers (BEAGLE_RESPONSE_CLASS (klass),
96 parser_handlers);
98 g_type_class_add_private (klass, sizeof (BeagleHitsSubtractedResponsePrivate));
101 static void
102 beagle_hits_subtracted_response_init (BeagleHitsSubtractedResponse *response)
107 * beagle_hits_subtracted_response_get_uris:
108 * @response: a #BeagleHitsSubtractedResponse
110 * Fetches the list of hit uris contained in the given #BeagleHitsSubtractedResponse. The list should not be modified or freed.
112 * Return value: A list of uri strings.
114 GSList *
115 beagle_hits_subtracted_response_get_uris (BeagleHitsSubtractedResponse *response)
117 BeagleHitsSubtractedResponsePrivate *priv;
119 g_return_val_if_fail (BEAGLE_IS_HITS_SUBTRACTED_RESPONSE (response), NULL);
121 priv = BEAGLE_HITS_SUBTRACTED_RESPONSE_GET_PRIVATE (response);
123 return priv->uris;