2 * beagle-search-term-response.c
4 * Copyright (C) 2005 Novell, Inc.
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.
29 #include <sys/types.h>
30 #include <sys/socket.h>
33 #include "beagle-search-term-response.h"
34 #include "beagle-private.h"
35 #include "beagle-property.h"
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
)
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
64 if (G_OBJECT_CLASS (parent_class
)->finalize
)
65 G_OBJECT_CLASS (parent_class
)->finalize (obj
);
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
;
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
;
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
));
100 static BeagleParserHandler parser_handlers
[] = {
109 PARSER_STATE_STEMMED
,
120 PARSER_STATE_STEMMED
,
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
),
140 g_type_class_add_private (klass
, sizeof (BeagleSearchTermResponsePrivate
));
144 beagle_search_term_response_init (BeagleSearchTermResponse
*response
)
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
;
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
;