Dont add null mimetypes. Fixes bgo# 337431. The patch hasnt been officially accepted...
[beagle.git] / libbeagle / beagle / beagle-search-term-response.c
blob0dc714f4869464663158eaba3cdedbe5be81d944
1 /*
2 * beagle-search-term-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-search-term-response.h"
34 #include "beagle-private.h"
35 #include "beagle-property.h"
37 typedef struct {
38 GSList *exact_text; /* of string */
39 GSList *stemmed_text; /* of string */
41 GSList **current_list; /* points to one of the two above */
42 } BeagleSearchTermResponsePrivate;
44 #define BEAGLE_SEARCH_TERM_RESPONSE_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), BEAGLE_TYPE_SEARCH_TERM_RESPONSE, BeagleSearchTermResponsePrivate))
46 static BeagleResponseClass *parent_class = NULL;
48 G_DEFINE_TYPE (BeagleSearchTermResponse, beagle_search_term_response, BEAGLE_TYPE_RESPONSE)
50 static void
51 beagle_search_term_response_finalize (GObject *obj)
53 BeagleSearchTermResponsePrivate *priv = BEAGLE_SEARCH_TERM_RESPONSE_GET_PRIVATE (obj);
56 * Note, we don't free the lists or their contents here! This is
57 * because the BeagleSearchTermResponse is internal to BeagleQuery.
58 * This response never happens in reply to any other request, and
59 * the BeagleQuery gets these lists through the get_exact_text()
60 * and get_stemmed_text() functions below. They take ownership
61 * of them.
64 if (G_OBJECT_CLASS (parent_class)->finalize)
65 G_OBJECT_CLASS (parent_class)->finalize (obj);
68 static void
69 start_exact (BeagleParserContext *ctx, const char **attrs)
71 BeagleSearchTermResponse *response = BEAGLE_SEARCH_TERM_RESPONSE (_beagle_parser_context_get_response (ctx));
72 BeagleSearchTermResponsePrivate *priv = BEAGLE_SEARCH_TERM_RESPONSE_GET_PRIVATE (response);
74 priv->current_list = &priv->exact_text;
77 static void
78 start_stemmed (BeagleParserContext *ctx, const char **attrs)
80 BeagleSearchTermResponse *response = BEAGLE_SEARCH_TERM_RESPONSE (_beagle_parser_context_get_response (ctx));
81 BeagleSearchTermResponsePrivate *priv = BEAGLE_SEARCH_TERM_RESPONSE_GET_PRIVATE (response);
83 priv->current_list = &priv->stemmed_text;
86 static void
87 end_text (BeagleParserContext *ctx)
89 BeagleSearchTermResponse *response = BEAGLE_SEARCH_TERM_RESPONSE (_beagle_parser_context_get_response (ctx));
90 BeagleSearchTermResponsePrivate *priv = BEAGLE_SEARCH_TERM_RESPONSE_GET_PRIVATE (response);
92 *priv->current_list = g_slist_append (*priv->current_list, _beagle_parser_context_get_text_buffer (ctx));
94 enum {
95 PARSER_STATE_EXACT,
96 PARSER_STATE_STEMMED,
97 PARSER_STATE_TEXT,
100 static BeagleParserHandler parser_handlers[] = {
101 { "Exact",
103 PARSER_STATE_EXACT,
104 start_exact,
105 NULL },
107 { "Stemmed",
109 PARSER_STATE_STEMMED,
110 start_stemmed,
111 NULL },
113 { "Text",
114 PARSER_STATE_EXACT,
115 PARSER_STATE_TEXT,
116 NULL,
117 end_text },
119 { "Text",
120 PARSER_STATE_STEMMED,
121 PARSER_STATE_TEXT,
122 NULL,
123 end_text },
125 { 0 }
128 static void
129 beagle_search_term_response_class_init (BeagleSearchTermResponseClass *klass)
131 GObjectClass *obj_class = G_OBJECT_CLASS (klass);
133 parent_class = g_type_class_peek_parent (klass);
135 obj_class->finalize = beagle_search_term_response_finalize;
137 _beagle_response_class_set_parser_handlers (BEAGLE_RESPONSE_CLASS (klass),
138 parser_handlers);
140 g_type_class_add_private (klass, sizeof (BeagleSearchTermResponsePrivate));
143 static void
144 beagle_search_term_response_init (BeagleSearchTermResponse *response)
148 GSList *
149 _beagle_search_term_response_get_exact_text (BeagleSearchTermResponse *response)
151 BeagleSearchTermResponsePrivate *priv;
153 g_return_val_if_fail (BEAGLE_IS_SEARCH_TERM_RESPONSE (response), NULL);
155 priv = BEAGLE_SEARCH_TERM_RESPONSE_GET_PRIVATE (response);
157 return priv->exact_text;
160 GSList *
161 _beagle_search_term_response_get_stemmed_text (BeagleSearchTermResponse *response)
163 BeagleSearchTermResponsePrivate *priv;
165 g_return_val_if_fail (BEAGLE_IS_SEARCH_TERM_RESPONSE (response), NULL);
167 priv = BEAGLE_SEARCH_TERM_RESPONSE_GET_PRIVATE (response);
169 return priv->stemmed_text;