2007-08-28 Murray Cumming <murrayc@murrayc.com>
[modest] / src / modest-search.c
1 /* Copyright (c) 2006, Nokia Corporation
2  * All rights reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions are
6  * met:
7  *
8  * * Redistributions of source code must retain the above copyright
9  *   notice, this list of conditions and the following disclaimer.
10  * * Redistributions in binary form must reproduce the above copyright
11  *   notice, this list of conditions and the following disclaimer in the
12  *   documentation and/or other materials provided with the distribution.
13  * * Neither the name of the Nokia Corporation nor the names of its
14  *   contributors may be used to endorse or promote products derived from
15  *   this software without specific prior written permission.
16  *
17  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
18  * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
19  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
20  * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
21  * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
22  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
23  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
24  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
25  * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
26  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
27  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28  */
29
30 #ifndef _GNU_SOURCE
31 #define _GNU_SOURCE
32 #endif
33
34 #ifdef HAVE_CONFIG_H
35 #include <config.h>
36 #endif
37
38 #include <string.h>
39
40 #include <tny-shared.h>
41 #include <tny-folder.h>
42 #include <tny-folder-store.h>
43 #include <tny-list.h>
44 #include <tny-iterator.h>
45 #include <tny-simple-list.h>
46
47 #include <libmodest-dbus-client/libmodest-dbus-client.h>
48
49 #include "modest-text-utils.h"
50 #include "modest-account-mgr.h"
51 #include "modest-tny-account-store.h"
52 #include "modest-tny-account.h"
53 #include "modest-search.h"
54 #include "modest-runtime.h"
55
56 static gchar *
57 g_strdup_or_null (const gchar *str)
58 {
59         gchar *string = NULL;
60
61         if  (str != NULL) {
62                 string = g_strdup (str);
63         }
64
65         return string;
66 }
67
68 typedef struct
69 {
70         GMainLoop* loop;
71         TnyAccount *account;
72         gboolean is_online;
73         gint count_tries;
74 } UtilIdleData;
75
76 #define NUMBER_OF_TRIES 10 /* Try approx every second, ten times. */
77
78 static gboolean 
79 on_timeout_check_account_is_online(gpointer user_data)
80 {
81         printf ("DEBUG: %s:\n", __FUNCTION__);
82         UtilIdleData *data = (UtilIdleData*)user_data;
83         
84         if (!data) {
85                 g_warning ("%s: data is NULL.\n", __FUNCTION__);
86         }
87         
88         if (!(data->account)) {
89                 g_warning ("%s: data->account is NULL.\n", __FUNCTION__);
90         }
91         
92         if (data && data->account) {
93                 printf ("DEBUG: %s: tny_account_get_connection_status()==%d\n", __FUNCTION__, tny_account_get_connection_status (data->account));       
94         }
95         
96         gboolean stop_trying = FALSE;
97         if (data && data->account && 
98                 (tny_account_get_connection_status (data->account) == TNY_CONNECTION_STATUS_CONNECTED) )
99         {
100                 data->is_online = TRUE;
101                 
102                 stop_trying = TRUE;
103         }
104         else {
105                 /* Give up if we have tried too many times: */
106                 if (data->count_tries >= NUMBER_OF_TRIES)
107                 {
108                         stop_trying = TRUE;
109                 }
110                 else {
111                         /* Wait for another timeout: */
112                         ++(data->count_tries);
113                 }
114         }
115         
116         if (stop_trying) {
117                 /* Allow the function that requested this idle callback to continue: */
118                 if (data->loop)
119                         g_main_loop_quit (data->loop);
120                         
121                 if (data->account)
122                         g_object_unref (data->account);
123                 
124                 return FALSE; /* Don't call this again. */
125         } else {
126                 return TRUE; /* Call this timeout callback again. */
127         }
128 }
129
130 /* Return TRUE immediately if the account is already online,
131  * otherwise check every second for NUMBER_OF_TRIES seconds and return TRUE as 
132  * soon as the account is online, or FALSE if the account does 
133  * not become online in the NUMBER_OF_TRIES seconds.
134  * This is useful when the D-Bus method was run immediately after 
135  * the application was started (when using D-Bus activation), 
136  * because the account usually takes a short time to go online.
137  * The return value is maybe not very useful.
138  */
139 static gboolean
140 check_and_wait_for_account_is_online(TnyAccount *account)
141 {
142         g_return_val_if_fail (account, FALSE);
143         
144         printf ("DEBUG: %s: account id=%s\n", __FUNCTION__, tny_account_get_id (account));
145         
146         if (!tny_device_is_online (modest_runtime_get_device())) {
147                 printf ("DEBUG: %s: device is offline.\n", __FUNCTION__);
148                 return FALSE;
149         }
150                 
151         printf ("DEBUG: %s: tny_account_get_connection_status()==%d\n", __FUNCTION__, tny_account_get_connection_status (account));
152         
153         /* TODO: The local_folders account never seems to leave TNY_CONNECTION_STATUS_INIT,
154          * so we wait unnecessarily,
155          * but that enum value isn't enough to get a message list from POP and IMAP. */
156         if (tny_account_get_connection_status (account) == TNY_CONNECTION_STATUS_CONNECTED)
157                 return TRUE;
158                 
159         /* This blocks on the result: */
160         UtilIdleData *data = g_slice_new0 (UtilIdleData);
161         data->is_online = FALSE;
162         data->account = account;
163         g_object_ref (data->account);
164         data->count_tries = 0;
165                 
166         GMainContext *context = NULL; /* g_main_context_new (); */
167         data->loop = g_main_loop_new (context, FALSE /* not running */);
168
169         g_timeout_add (1000, &on_timeout_check_account_is_online, data);
170
171         /* This main loop will run until the idle handler has stopped it: */
172         g_main_loop_run (data->loop);
173
174         g_main_loop_unref (data->loop);
175         /* g_main_context_unref (context); */
176
177         g_slice_free (UtilIdleData, data);
178         
179         return data->is_online; 
180 }
181
182 static GList*
183 add_hit (GList *list, TnyHeader *header, TnyFolder *folder)
184 {
185         ModestSearchHit *hit;
186         TnyHeaderFlags   flags;
187         char            *furl;
188         char            *msg_url;
189         const char      *uid;
190         const char      *subject;
191         const char      *sender;
192
193         hit = g_slice_new0 (ModestSearchHit);
194
195         furl = tny_folder_get_url_string (folder);
196         printf ("DEBUG: %s: folder URL=%s\n", __FUNCTION__, furl);
197         if (!furl) {
198                 g_warning ("%s: tny_folder_get_url_string(): returned NULL for folder. Folder name=%s\n", __FUNCTION__, tny_folder_get_name (folder));
199         }
200         
201         /* Make sure that we use the short UID instead of the long UID,
202          * and/or find out what UID form is used when finding, in camel_data_cache_get().
203          * so we can find what we get. Philip is working on this.
204          */
205         uid = tny_header_get_uid (header);
206         if (!furl) {
207                 g_warning ("%s: tny_header_get_uid(): returned NULL for message with subject=%s\n", __FUNCTION__, tny_header_get_subject (header));
208         }
209         
210         msg_url = g_strdup_printf ("%s/%s", furl, uid);
211         g_free (furl);
212         
213         subject = tny_header_get_subject (header);
214         sender = tny_header_get_from (header);
215         
216         flags = tny_header_get_flags (header);
217
218         hit->msgid = msg_url;
219         hit->subject = g_strdup_or_null (subject);
220         hit->sender = g_strdup_or_null (sender);
221         hit->folder = g_strdup_or_null (tny_folder_get_name (folder));
222         hit->msize = tny_header_get_message_size (header);
223         hit->has_attachment = flags & TNY_HEADER_FLAG_ATTACHMENTS;
224         hit->is_unread = ! (flags & TNY_HEADER_FLAG_SEEN);
225         hit->timestamp = tny_header_get_date_received (header);
226         
227         return g_list_prepend (list, hit);
228 }
229
230 /** Call this until it returns FALSE or nread is set to 0.
231  * 
232  * @result: FALSE is something failed. */
233 static gboolean
234 read_chunk (TnyStream *stream, char *buffer, gsize count, gsize *nread)
235 {
236         gsize _nread = 0;
237         gssize res = 0;
238
239         while (_nread < count) {
240                 res = tny_stream_read (stream,
241                                        buffer + _nread, 
242                                        count - _nread);
243                 if (res == -1) { /* error */
244                         *nread = _nread;
245                         return FALSE;
246                 }
247
248                 _nread += res;
249                 
250                 if (res == 0) { /* no more bytes read. */
251                         *nread = _nread;
252                         return TRUE;
253                 }
254         }
255
256         *nread = _nread;
257         return TRUE;
258 }
259
260 #ifdef MODEST_HAVE_OGS
261 static gboolean
262 search_mime_part_ogs (TnyMimePart *part, ModestSearch *search)
263 {
264         TnyStream *stream = NULL;
265         char       buffer[4096];
266         const gsize len = sizeof (buffer);
267         gsize      nread = 0;
268         gboolean   is_text_html = FALSE;
269         gboolean   found = FALSE;
270         gboolean   res = FALSE;
271
272         gboolean is_text = tny_mime_part_content_type_is (part, "text/*");
273         if (!is_text) {
274                 g_debug ("%s: tny_mime_part_content_type_is() failed to find a "
275                         "text/* MIME part. Content type is %s", 
276                 __FUNCTION__, "Unknown (calling tny_mime_part_get_content_type(part) causes a deadlock)");
277                 
278             /* Retry with specific MIME types, because the wildcard seems to fail
279              * in tinymail.
280              * Actually I'm not sure anymore that it fails, so we could probalby 
281              * remove this later: murrayc */
282             is_text = (
283                 tny_mime_part_content_type_is (part, "text/plain") ||
284                 tny_mime_part_content_type_is (part, "text/html") );
285                 
286                 if (is_text) {
287                   g_debug ("%s: Retryting with text/plain or text/html succeeded", 
288                         __FUNCTION__);  
289                 }
290         }
291         
292         if (!is_text) {
293             return FALSE;
294         }
295         
296         is_text_html = tny_mime_part_content_type_is (part, "text/html");
297
298         stream = tny_mime_part_get_stream (part);
299
300         res = read_chunk (stream, buffer, len, &nread);
301         while (res && (nread > 0)) {
302                 /* search->text_searcher was instantiated in modest_search_folder(). */
303                 
304                 if (is_text_html) {
305
306                         found = ogs_text_searcher_search_html (search->text_searcher,
307                                                                buffer,
308                                                                nread,
309                                                                nread < len);
310                 } else {
311                         found = ogs_text_searcher_search_text (search->text_searcher,
312                                                                buffer,
313                                                                nread);
314                 }
315
316                 if (found) {
317                         break;
318                 }
319                 
320                 nread = 0;
321                 res = read_chunk (stream, buffer, len, &nread);
322         }
323
324         if (!found) {
325                 found = ogs_text_searcher_search_done (search->text_searcher);
326         }
327
328         ogs_text_searcher_reset (search->text_searcher);
329         
330         /* debug stuff:
331         if (!found) {
332                 buffer[len -1] = 0;
333                 printf ("DEBUG: %s: query %s was not found in message text: %s\n", 
334                         __FUNCTION__, search->query, buffer);   
335                 
336         } else {
337                 printf ("DEBUG: %s: found.\n", __FUNCTION__);   
338         }
339         */
340
341         return found;
342 }
343
344 #else
345
346 static gboolean
347 search_mime_part_strcmp (TnyMimePart *part, ModestSearch *search)
348 {
349         TnyStream *stream;
350         char       buffer[8193];
351         char      *chunk[2];
352         gssize     len;
353         gsize     nread;
354         gboolean   found;
355         gboolean   res;
356
357         if (! tny_mime_part_content_type_is (part, "text/*")) {
358                 g_debug ("%s: No text MIME part found.\n", __FUNCTION__);
359                 return FALSE;
360         }
361
362         found = FALSE;
363         len = (sizeof (buffer) - 1) / 2;
364
365         if (strlen (search->body) > len) {
366                 g_warning ("Search term bigger then chunk."
367                            "We might not find everything");     
368         }
369
370         stream = tny_mime_part_get_stream (part);
371
372         memset (buffer, 0, sizeof (buffer));
373         chunk[0] = buffer;
374         chunk[1] = buffer + len;
375
376         res = read_chunk (stream, chunk[0], len, &nread);
377
378         if (res == FALSE) {
379                 goto done;
380         }
381
382         found = !modest_text_utils_utf8_strcmp (search->body,
383                                                 buffer,
384                                                 TRUE);
385         if (found) {
386                 goto done;
387         }
388
389         /* This works like this:
390          * buffer: [ooooooooooo|xxxxxxxxxxxx|\0] 
391          *          ^chunk[0]  ^chunk[1]
392          * we have prefilled chunk[0] now we always read into chunk[1]
393          * and then move the content of chunk[1] to chunk[0].
394          * The idea is to prevent not finding search terms that are
395          * spread across 2 reads:        
396          * buffer: [ooooooooTES|Txxxxxxxxxxx|\0] 
397          * We should catch that because we always search the whole
398          * buffer not only the chunks.
399          *
400          * Of course that breaks for search terms > sizeof (chunk)
401          * but sizeof (chunk) should be big enough I guess (see
402          * the g_warning in this function)
403          * */   
404         while ((res = read_chunk (stream, chunk[1], len, &nread))) {
405                 buffer[len + nread] = '\0';
406
407                 found = !modest_text_utils_utf8_strcmp (search->body,
408                                                         buffer,
409                                                         TRUE);
410
411                 if (found) {
412                         break;
413                 }
414
415                 /* also move the \0 */
416                 g_memmove (chunk[0], chunk[1], len + 1);
417         }
418
419 done:
420         g_object_unref (stream);
421         return found;
422 }
423 #endif /*MODEST_HAVE_OGS*/
424
425 static gboolean
426 search_string (const char      *what,
427                const char      *where,
428                ModestSearch    *search)
429 {
430         gboolean found;
431 #ifdef MODEST_HAVE_OGS
432         if (search->flags & MODEST_SEARCH_USE_OGS) {
433                 found = ogs_text_searcher_search_text (search->text_searcher,
434                                                        where,
435                                                        strlen (where));
436
437                 ogs_text_searcher_reset (search->text_searcher);
438         } else {
439 #endif
440                 if (what == NULL || where == NULL) {
441                         return FALSE;
442                 }
443
444                 found = !modest_text_utils_utf8_strcmp (what, where, TRUE);
445 #ifdef MODEST_HAVE_OGS
446         }
447 #endif
448         return found;
449 }
450
451
452 static gboolean search_mime_part_and_child_parts (TnyMimePart *part, ModestSearch *search)
453 {
454         gboolean found = FALSE;
455         #ifdef MODEST_HAVE_OGS
456         found = search_mime_part_ogs (part, search);
457         #else
458         found = search_mime_part_strcmp (part, search);
459         #endif
460
461         if (found) {    
462                 return found;           
463         }
464         
465         /* Check the child part too, recursively: */
466         TnyList *child_parts = tny_simple_list_new ();
467         tny_mime_part_get_parts (TNY_MIME_PART (part), child_parts);
468
469         TnyIterator *piter = tny_list_create_iterator (child_parts);
470         while (!found && !tny_iterator_is_done (piter)) {
471                 TnyMimePart *pcur = (TnyMimePart *) tny_iterator_get_current (piter);
472                 if (pcur) {
473                         found = search_mime_part_and_child_parts (pcur, search);
474
475                         g_object_unref (pcur);
476                 }
477
478                 tny_iterator_next (piter);
479         }
480
481         g_object_unref (piter);
482         g_object_unref (child_parts);
483         
484         return found;
485 }
486
487 /**
488  * modest_search:
489  * @folder: a #TnyFolder instance
490  * @search: a #ModestSearch query
491  *
492  * This operation will search @folder for headers that match the query @search,
493  * if the folder itself matches the query.
494  * It will return a doubly linked list with URIs that point to the message.
495  **/
496 GList *
497 modest_search_folder (TnyFolder *folder, ModestSearch *search)
498 {
499         /* Check that we should be searching this folder. */
500         /* Note that we don't try to search sub-folders. 
501          * Maybe we should, but that should be specified. */
502         if (search->folder && strlen (search->folder) && (strcmp (tny_folder_get_id (folder), search->folder) != 0))
503                 return NULL;
504         
505         GList *retval = NULL;
506         TnyIterator *iter = NULL;
507         TnyList *list = NULL;
508         
509 #ifdef MODEST_HAVE_OGS
510         if (search->flags & MODEST_SEARCH_USE_OGS) {
511         
512                 if (search->text_searcher == NULL && search->query != NULL) {
513                         OgsTextSearcher *text_searcher; 
514
515                         text_searcher = ogs_text_searcher_new (FALSE);
516                         ogs_text_searcher_parse_query (text_searcher, search->query);
517                         search->text_searcher = text_searcher;
518                 }
519         }
520 #endif
521
522         list = tny_simple_list_new ();
523         GError *error = NULL;
524         tny_folder_get_headers (folder, list, FALSE /* don't refresh */, &error);
525         if (error) {
526                 g_warning ("%s: tny_folder_get_headers() failed with error=%s.\n", 
527                 __FUNCTION__, error->message);
528                 g_error_free (error);
529                 error = NULL;   
530         }
531
532         iter = tny_list_create_iterator (list);
533
534         while (!tny_iterator_is_done (iter)) {
535                 TnyHeader *cur = (TnyHeader *) tny_iterator_get_current (iter);
536                 const time_t t = tny_header_get_date_sent (cur);
537                 gboolean found = FALSE;
538                 
539                 /* Ignore deleted (not yet expunged) emails: */
540                 if (tny_header_get_flags(cur) & TNY_HEADER_FLAG_DELETED)
541                         goto go_next;
542                         
543                 if (search->flags & MODEST_SEARCH_BEFORE)
544                         if (!(t <= search->end_date))
545                                 goto go_next;
546
547                 if (search->flags & MODEST_SEARCH_AFTER)
548                         if (!(t >= search->start_date))
549                                 goto go_next;
550
551                 if (search->flags & MODEST_SEARCH_SIZE)
552                         if (tny_header_get_message_size (cur) < search->minsize)
553                                 goto go_next;
554
555                 if (search->flags & MODEST_SEARCH_SUBJECT) {
556                         const char *str = tny_header_get_subject (cur);
557
558                         if ((found = search_string (search->subject, str, search))) {
559                             retval = add_hit (retval, cur, folder);
560                         }
561                 }
562                 
563                 if (!found && search->flags & MODEST_SEARCH_SENDER) {
564                         char *str = g_strdup (tny_header_get_from (cur));
565
566                         if ((found = search_string (search->from, (const gchar *) str, search))) {
567                                 retval = add_hit (retval, cur, folder);
568                         }
569                         g_free (str);
570                 }
571                 
572                 if (!found && search->flags & MODEST_SEARCH_RECIPIENT) {
573                         const char *str = tny_header_get_to (cur);
574
575                         if ((found = search_string (search->recipient, str, search))) {
576                                 retval = add_hit (retval, cur, folder);
577                         }
578                 }
579         
580                 if (!found && search->flags & MODEST_SEARCH_BODY) {
581                         TnyHeaderFlags flags;
582                         GError      *err = NULL;
583                         TnyMsg      *msg = NULL;
584
585                         flags = tny_header_get_flags (cur);
586
587                         if (!(flags & TNY_HEADER_FLAG_CACHED)) {
588                                 goto go_next;
589                         }
590
591                         msg = tny_folder_get_msg (folder, cur, &err);
592
593                         if (err != NULL || msg == NULL) {
594                                 g_warning ("%s: Could not get message.\n", __FUNCTION__);
595                                 g_error_free (err);
596
597                                 if (msg) {
598                                         g_object_unref (msg);
599                                 }
600                         } else {        
601                         
602                                 found = search_mime_part_and_child_parts (TNY_MIME_PART (msg), 
603                                                                           search);
604                                 if (found) {
605                                         retval = add_hit (retval, cur, folder);
606                                 }
607                         }
608                         
609                         if (msg)
610                                 g_object_unref (msg);
611                 }
612
613 go_next:
614                 g_object_unref (cur);
615                 tny_iterator_next (iter);
616         }
617
618         g_object_unref (iter);
619         g_object_unref (list);
620         return retval;
621 }
622
623 GList *
624 modest_search_account (TnyAccount *account, ModestSearch *search)
625 {
626         TnyFolderStore      *store;
627         TnyIterator         *iter;
628         TnyList             *folders;
629         GList               *hits;
630         GError              *error;
631
632         error = NULL;
633         hits = NULL;
634
635         store = TNY_FOLDER_STORE (account);
636
637         folders = tny_simple_list_new ();
638         tny_folder_store_get_folders (store, folders, NULL, &error);
639         
640         if (error != NULL) {
641                 g_object_unref (folders);
642                 return NULL;
643         }
644
645         iter = tny_list_create_iterator (folders);
646         while (!tny_iterator_is_done (iter)) {
647                 TnyFolder *folder = NULL;
648                 GList     *res = NULL;
649
650                 folder = TNY_FOLDER (tny_iterator_get_current (iter));
651                 if (folder) {
652                         /* g_debug ("DEBUG: %s: searching folder %s.", 
653                                 __FUNCTION__, tny_folder_get_name (folder)); */
654                 
655                         res = modest_search_folder (folder, search);
656
657                         if (res != NULL) {
658                                 if (hits == NULL) {
659                                         hits = res;
660                                 } else {
661                                         hits = g_list_concat (hits, res);
662                                 }
663                         }
664
665                         g_object_unref (folder);
666                 }
667
668                 tny_iterator_next (iter);
669         }
670
671         g_object_unref (iter);
672         g_object_unref (folders);
673
674         /* printf ("DEBUG: %s: hits length = %d\n", __FUNCTION__, g_list_length (hits)); */
675         return hits;
676 }
677
678 GList *
679 modest_search_all_accounts (ModestSearch *search)
680 {
681         /* printf ("DEBUG: %s: query=%s\n", __FUNCTION__, search->query); */
682         ModestTnyAccountStore *astore;
683         TnyList               *accounts;
684         TnyIterator           *iter;
685         GList                 *hits;
686
687         hits = NULL;
688         astore = modest_runtime_get_account_store ();
689
690         accounts = tny_simple_list_new ();
691         tny_account_store_get_accounts (TNY_ACCOUNT_STORE (astore),
692                                         accounts,
693                                         TNY_ACCOUNT_STORE_STORE_ACCOUNTS);
694
695         iter = tny_list_create_iterator (accounts);
696         while (!tny_iterator_is_done (iter)) {
697                 TnyAccount *account = NULL;
698                 GList      *res = NULL;
699
700                 account = TNY_ACCOUNT (tny_iterator_get_current (iter));
701                 if (account) {
702                         /* g_debug ("DEBUG: %s: Searching account %s",
703                          __FUNCTION__, tny_account_get_name (account)); */
704                          
705                         /* Give the account time to go online if necessary, 
706                          * for instance if this is immediately after startup,
707                          * after D-Bus activation: */
708                         check_and_wait_for_account_is_online (account);
709                         
710                         /* Search: */
711                         res = modest_search_account (account, search);
712                         
713                         if (res != NULL) {      
714                                 if (hits == NULL) {
715                                         hits = res;
716                                 } else {
717                                         hits = g_list_concat (hits, res);
718                                 }
719                         }
720                         
721                         g_object_unref (account);
722                 }
723
724                 tny_iterator_next (iter);
725         }
726
727         g_object_unref (accounts);
728         g_object_unref (iter);
729
730         /* printf ("DEBUG: %s: end: hits length=%d\n", __FUNCTION__, g_list_length(hits)); */
731         return hits;
732 }
733
734