2 * beagle-snippet-request.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-private.h"
34 #include "beagle-snippet-request.h"
35 #include "beagle-snippet-response.h"
40 } BeagleSnippetRequestPrivate
;
42 #define BEAGLE_SNIPPET_REQUEST_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), BEAGLE_TYPE_SNIPPET_REQUEST, BeagleSnippetRequestPrivate))
44 static GObjectClass
*parent_class
= NULL
;
47 beagle_snippet_request_to_xml (BeagleRequest
*request
, GError
**err
)
49 BeagleSnippetRequestPrivate
*priv
= BEAGLE_SNIPPET_REQUEST_GET_PRIVATE (request
);
53 g_return_val_if_fail (priv
->query
!= NULL
, NULL
);
54 g_return_val_if_fail (priv
->hit
!= NULL
, NULL
);
56 data
= g_string_new (NULL
);
58 _beagle_request_append_standard_header (data
, "SnippetRequest");
60 _beagle_hit_to_xml (priv
->hit
, data
);
62 g_string_append (data
, "<QueryTerms>");
63 for (list
= beagle_query_get_stemmed_text (priv
->query
); list
!= NULL
; list
= list
->next
) {
64 char *term
= list
->data
;
66 g_string_append_printf (data
, "<string>%s</string>", term
);
68 g_string_append (data
, "</QueryTerms>");
70 _beagle_request_append_standard_footer (data
);
75 G_DEFINE_TYPE (BeagleSnippetRequest
, beagle_snippet_request
, BEAGLE_TYPE_REQUEST
)
78 beagle_snippet_request_finalize (GObject
*obj
)
80 BeagleSnippetRequestPrivate
*priv
= BEAGLE_SNIPPET_REQUEST_GET_PRIVATE (obj
);
83 beagle_hit_unref (priv
->hit
);
85 if (priv
->query
!= NULL
)
86 g_object_unref (priv
->query
);
88 if (G_OBJECT_CLASS (parent_class
)->finalize
)
89 G_OBJECT_CLASS (parent_class
)->finalize (obj
);
93 beagle_snippet_request_class_init (BeagleSnippetRequestClass
*klass
)
95 GObjectClass
*obj_class
= G_OBJECT_CLASS (klass
);
96 BeagleRequestClass
*request_class
= BEAGLE_REQUEST_CLASS (klass
);
98 parent_class
= g_type_class_peek_parent (klass
);
100 obj_class
->finalize
= beagle_snippet_request_finalize
;
101 request_class
->to_xml
= beagle_snippet_request_to_xml
;
103 g_type_class_add_private (klass
, sizeof (BeagleSnippetRequestPrivate
));
105 _beagle_request_class_set_response_types (request_class
,
107 BEAGLE_TYPE_SNIPPET_RESPONSE
,
112 beagle_snippet_request_init (BeagleSnippetRequest
*snippet_request
)
117 * beagle_snippet_request_new:
119 * Creates a new #BeagleSnippetRequest.
121 * Return value: the newly created #BeagleSnippetRequest.
123 BeagleSnippetRequest
*
124 beagle_snippet_request_new (void)
126 BeagleSnippetRequest
*snippet_request
= g_object_new (BEAGLE_TYPE_SNIPPET_REQUEST
, 0);
128 return snippet_request
;
132 * beagle_snippet_request_set_hit:
133 * @request: a #BeagleSnippetRequest
136 * Sets the @hit on the given #BeagleSnippetRequest.
139 beagle_snippet_request_set_hit (BeagleSnippetRequest
*request
,
142 BeagleSnippetRequestPrivate
*priv
;
144 g_return_if_fail (BEAGLE_IS_SNIPPET_REQUEST (request
));
145 g_return_if_fail (hit
!= NULL
);
147 priv
= BEAGLE_SNIPPET_REQUEST_GET_PRIVATE (request
);
149 beagle_hit_ref (hit
);
152 beagle_hit_unref (priv
->hit
);
158 * beagle_snippet_request_set:
159 * @request: a #BeagleSnippetRequest
160 * @query: a #BeagleQuery
162 * Set the query of the given #BeagleSnippetRequest from which to pull query terms.
165 beagle_snippet_request_set_query (BeagleSnippetRequest
*request
,
168 BeagleSnippetRequestPrivate
*priv
;
170 g_return_if_fail (BEAGLE_IS_SNIPPET_REQUEST (request
));
171 g_return_if_fail (query
!= NULL
);
173 priv
= BEAGLE_SNIPPET_REQUEST_GET_PRIVATE (request
);
175 g_object_ref (query
);
177 if (priv
->query
!= NULL
)
178 g_object_unref (query
);