Mostly minor fixes up until version 0.8.10.
[irreco.git] / irreco / src / webdb / irreco_webdb_cache.c
blobdedab58aefdbea68cfc7e6eb2e9b32b24e5594b3
1 /*
2 * irreco - Ir Remote Control
3 * Copyright (C) 2007,2008 Arto Karppinen (arto.karppinen@iki.fi),
4 * Joni Kokko (t5kojo01@students.oamk.fi),
5 * Sami Mäki (kasmra@xob.kapsi.fi),
6 * Harri Vattulainen (t5vaha01@students.oamk.fi),
7 * Pekka Gehör (pegu6@msn.com)
9 * This program is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU General Public License
11 * as published by the Free Software Foundation; either version 2
12 * of the License, or (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software Foundation,
21 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
24 #include "irreco_webdb_cache.h"
25 #include "irreco_webdb_client.h"
27 /**
28 * @addtogroup IrrecoWebdbCache
29 * @ingroup IrrecoWebdb
31 * Caches XML-RPC calls, enables error handling and retries failed calls.
33 * @{
36 /**
37 * @file
38 * Source file of @ref IrrecoWebdbCache.
43 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
44 /* Prototypes */
45 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
47 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
48 /* Construction & Destruction */
49 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
51 /**
52 * @name Construction & Destruction
53 * @{
56 /**
57 * Create new IrrecoWebdb Object
59 IrrecoWebdbCache *irreco_webdb_cache_new()
61 IrrecoWebdbCache *self;
62 IRRECO_ENTER
64 self = g_slice_new0(IrrecoWebdbCache);
65 self->private = irreco_webdb_client_new();
66 self->remote_categories = NULL;
67 self->error_msg = g_string_new("");
68 self->loop = irreco_retry_loop_new(IRRECO_SECONDS_TO_USEC(0.3),
69 IRRECO_SECONDS_TO_USEC(3));
70 self->conf_hash = g_hash_table_new_full(g_int_hash, g_int_equal, NULL,
71 (GDestroyNotify) irreco_webdb_conf_free);
73 self->theme_id_hash = g_hash_table_new_full(g_int_hash, g_int_equal, NULL,
74 (GDestroyNotify) irreco_webdb_theme_free);
76 self->remote_id_hash = g_hash_table_new_full(g_int_hash, g_int_equal,
77 NULL, (GDestroyNotify) irreco_webdb_remote_free);
79 IRRECO_RETURN_PTR(self);
82 /**
83 * Free resources of IrrecoWebdbCache Object.
85 void irreco_webdb_cache_free(IrrecoWebdbCache *self)
87 IRRECO_ENTER
88 g_string_free(self->error_msg, TRUE);
89 self->error_msg = NULL;
90 irreco_retry_loop_free(self->loop);
91 self->loop = NULL;
92 if (self->remote_categories != NULL) {
93 irreco_string_table_free(self->remote_categories);
94 self->remote_categories = NULL;
96 irreco_webdb_client_free(self->private);
97 self->private = NULL;
98 g_slice_free(IrrecoWebdbCache, self);
99 if (self->conf_hash != NULL) {
100 g_hash_table_destroy(self->conf_hash);
101 self->conf_hash = NULL;
103 if (self->theme_id_hash != NULL) {
104 g_hash_table_destroy(self->theme_id_hash);
105 self->theme_id_hash = NULL;
107 if (self->remote_id_hash != NULL) {
108 g_hash_table_destroy(self->remote_id_hash);
109 self->remote_id_hash = NULL;
111 IRRECO_RETURN
114 /** @} */
116 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
117 /* Private Functions */
118 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
121 * @name Private Functions
122 * @{
126 * A simple test on Irreco WebDB to test if WebDB returns correct and
127 * meaningfull results.
129 * This function generates two numbers and asks WebDB to sum them. If the sum
130 * if correct, then our connection to the WebDB seems to be working.
132 * @return TRUE on success, FALSE otherwise.
134 static gboolean irreco_webdb_cache_test(IrrecoWebdbCache *self)
136 IrrecoWebdbClient *client;
137 GRand *rand;
138 gint32 num_a;
139 gint32 num_b;
140 glong sum;
141 IRRECO_ENTER
143 if (self->test_ok) IRRECO_RETURN_BOOL(self->test_ok);
145 rand = g_rand_new();
146 client = (IrrecoWebdbClient *) self->private;
148 IRRECO_RETRY_LOOP_START(self->loop)
149 num_a = g_rand_int_range(rand, 1, 1000);
150 num_b = g_rand_int_range(rand, 1, 1000);
151 self->test_ok = irreco_webdb_client_sum(
152 client, num_a, num_b, &sum);
154 if (self->test_ok) {
155 if (sum == num_a + num_b) {
156 break;
157 } else {
158 g_string_printf(self->error_msg,
159 "Got invalid result from "
160 "sum method. %i + %i = %i. "
161 "Expected %i.",
162 num_a, num_b, (gint) sum,
163 num_a + num_b);
164 IRRECO_PRINTF("%s\n", self->error_msg->str);
165 self->test_ok = FALSE;
167 } else {
168 irreco_webdb_client_get_error_msg(
169 client, self->error_msg);
171 IRRECO_RETRY_LOOP_END(self->loop)
173 g_rand_free(rand);
174 IRRECO_RETURN_BOOL(self->test_ok);
178 * Shows error message in case categories list is empty.
180 * @return TRUE if categories is not empty, FALSE otherwise.
182 static gboolean irreco_webdb_cache_verify_category(IrrecoWebdbCache *self)
184 IRRECO_ENTER
185 if (self->categories == NULL) {
186 g_string_printf(self->error_msg, "list of categories is NULL");
187 IRRECO_PRINTF("%s\n", self->error_msg->str);
188 IRRECO_RETURN_BOOL(FALSE)
190 IRRECO_RETURN_BOOL(TRUE)
194 * Shows error message in case manufacturers list is empty.
196 * @return TRUE if manufacturers list contains data, FALSE otherwise.
198 static gboolean
199 irreco_webdb_cache_verify_manufacturer(IrrecoWebdbCache *self,
200 const gchar *category,
201 IrrecoStringTable **manufactures)
203 IRRECO_ENTER
204 if (!irreco_string_table_get(self->categories, category,
205 (gpointer*) manufactures)) {
206 g_string_printf(self->error_msg,
207 "list of manufacturers is NULL");
208 IRRECO_PRINTF("%s\n", self->error_msg->str);
209 IRRECO_RETURN_BOOL(FALSE)
211 IRRECO_RETURN_BOOL(TRUE)
216 * Shows error message in case models list is empty.
218 * @return TRUE if models list contains data, FALSE otherwise.
220 static gboolean irreco_webdb_cache_verify_model(IrrecoWebdbCache *self,
221 IrrecoStringTable *manuf_list,
222 const gchar *manufacturer,
223 IrrecoStringTable **models)
225 IRRECO_ENTER
226 if (!irreco_string_table_get(manuf_list, manufacturer,
227 (gpointer*) models)) {
228 g_string_printf(self->error_msg, "list of models is NULL");
229 IRRECO_PRINTF("%s\n", self->error_msg->str);
230 IRRECO_RETURN_BOOL(FALSE)
232 IRRECO_RETURN_BOOL(TRUE)
236 * Shows error message in case configurations list is empty.
238 * @return TRUE if configurations list contains data, FALSE otherwise.
240 static gboolean irreco_webdb_cache_verify_config(IrrecoWebdbCache *self,
241 IrrecoStringTable *models,
242 const gchar *model,
243 IrrecoStringTable **configs)
245 IRRECO_ENTER
246 if (!irreco_string_table_get(models, model, (gpointer*) configs)) {
247 g_string_printf(self->error_msg,
248 "list of configurations is NULL");
249 IRRECO_PRINTF("%s\n", self->error_msg->str);
250 IRRECO_RETURN_BOOL(FALSE)
252 IRRECO_RETURN_BOOL(TRUE)
255 /** @} */
257 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
258 /* Functions */
259 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
262 * @name Public Functions
263 * @{
268 * Adds new user (name, email, password) to database.
270 * @return TRUE if user is added succesfully, FALSE otherwise.
272 gboolean irreco_webdb_cache_add_user(IrrecoWebdbCache *self,
273 const gchar *name,
274 const gchar *email,
275 const gchar *passwd)
277 IrrecoWebdbClient *client;
279 IRRECO_ENTER
281 client = (IrrecoWebdbClient *) self->private;
283 IRRECO_RETRY_LOOP_START(self->loop)
284 /* test connection to webdb */
285 if (irreco_webdb_cache_test(self) == FALSE){
286 g_string_printf(self->error_msg,
287 "Failed cache self test.");
288 IRRECO_PRINTF("%s\n", self->error_msg->str);
289 IRRECO_RETURN_BOOL(FALSE);
292 if(irreco_webdb_client_add_user(client, name, email, passwd)) {
293 IRRECO_RETURN_BOOL(TRUE);
294 } else {
295 /* irreco_webdb_client_add_user failed, get err msg */
296 irreco_webdb_client_get_error_msg(client,
297 self->error_msg);
298 IRRECO_RETURN_BOOL(FALSE);
300 IRRECO_RETRY_LOOP_END(self->loop)
302 IRRECO_RETURN_BOOL(FALSE);
306 * Adds new configuration to database.
308 * @return TRUE if configuration is uploaded succesfully, FALSE otherwise.
310 gboolean irreco_webdb_cache_upload_configuration(IrrecoWebdbCache *self,
311 const gchar *backend,
312 const gchar *category,
313 const gchar *file_hash,
314 const gchar *file_name,
315 const gchar *manufacturer,
316 const gchar *model,
317 const gchar *password,
318 const gchar *user,
319 const gchar *data)
321 IrrecoWebdbClient *client;
323 IRRECO_ENTER
325 client = (IrrecoWebdbClient *) self->private;
327 IRRECO_RETRY_LOOP_START(self->loop)
328 /* test connection to webdb */
329 if (irreco_webdb_cache_test(self) == FALSE){
330 g_string_printf(self->error_msg,
331 "Failed cache self test.");
332 IRRECO_PRINTF("%s\n", self->error_msg->str);
333 IRRECO_RETURN_BOOL(FALSE);
336 if(irreco_webdb_client_upload_configuration(client, backend,
337 category, file_hash, file_name,
338 manufacturer, model, password, user,
339 data)) {
341 IRRECO_RETURN_BOOL(TRUE);
342 } else {
343 /* irreco_webdb_client_upload_configuration failed,
344 get err msg */
345 irreco_webdb_client_get_error_msg(client,
346 self->error_msg);
347 IRRECO_RETURN_BOOL(FALSE);
349 IRRECO_RETRY_LOOP_END(self->loop)
351 IRRECO_RETURN_BOOL(FALSE);
355 * Extracts error message from IrrecoWebdbCache object.
357 * @return error message as string.
359 const gchar *irreco_webdb_cache_get_error(IrrecoWebdbCache *self)
361 IRRECO_ENTER
362 IRRECO_RETURN_STR(self->error_msg->str);
366 * Fetches categories from DB
368 * @return TRUE if categories are fetched succesfully, FALSE otherwise.
370 gboolean irreco_webdb_cache_get_categories(IrrecoWebdbCache *self,
371 IrrecoStringTable **categories)
373 IRRECO_ENTER
375 if (self->categories == NULL) {
376 gboolean success = FALSE;
377 IrrecoWebdbClient *client = (IrrecoWebdbClient *) self->private;
379 IRRECO_RETRY_LOOP_START(self->loop)
380 if (irreco_webdb_cache_test(self) == FALSE) break;
381 success = irreco_webdb_client_get_categories(
382 client, &self->categories);
383 if (success) {
384 break;
386 irreco_webdb_client_get_error_msg(
387 client, self->error_msg);
388 IRRECO_RETRY_LOOP_END(self->loop)
390 if (success == FALSE) IRRECO_RETURN_BOOL(FALSE);
392 irreco_string_table_sort_abc (self->categories);
395 *categories = self->categories;
396 IRRECO_RETURN_BOOL(TRUE)
400 * Fetches all categories from DB.
402 * @param all_categories must be freed if return value is TRUE.
403 * @return TRUE if categories are fetched succesfully, FALSE otherwise.
405 gboolean irreco_webdb_cache_get_all_categories(IrrecoWebdbCache *self,
406 IrrecoStringTable **all_categories)
408 gboolean success = FALSE;
409 IrrecoWebdbClient *client = (IrrecoWebdbClient *) self->private;
410 IRRECO_ENTER
413 IRRECO_RETRY_LOOP_START(self->loop)
414 if (irreco_webdb_cache_test(self) == FALSE) break;
415 success = irreco_webdb_client_get_all_categories(
416 client, all_categories);
417 if (success) {
418 break;
420 irreco_webdb_client_get_error_msg(
421 client, self->error_msg);
422 IRRECO_RETRY_LOOP_END(self->loop)
424 if (success == FALSE) IRRECO_RETURN_BOOL(FALSE);
426 irreco_string_table_sort_abc(*all_categories);
428 IRRECO_RETURN_BOOL(TRUE)
432 * Fetches manufacturers from DB.
434 * @param category contains category in which type manufacturers are returned.
435 * @return TRUE if manufacturers are fetched succesfully, FALSE otherwise.
437 gboolean irreco_webdb_cache_get_manufacturers(IrrecoWebdbCache *self,
438 const gchar *category,
439 IrrecoStringTable **manufacturers)
441 IrrecoStringTable *manufacturer_list;
442 IRRECO_ENTER
444 if (!irreco_webdb_cache_verify_category(self) ||
445 !irreco_webdb_cache_verify_manufacturer(self, category,
446 &manufacturer_list)) {
447 IRRECO_RETURN_BOOL(FALSE)
450 if(manufacturer_list == NULL) {
451 gboolean success = FALSE;
452 IrrecoWebdbClient *client = (IrrecoWebdbClient *) self->private;
454 IRRECO_RETRY_LOOP_START(self->loop)
455 if (irreco_webdb_cache_test(self) == FALSE) break;
456 success = irreco_webdb_client_get_manufacturers(
457 client, category, &manufacturer_list);
459 if (success) break;
460 irreco_webdb_client_get_error_msg(
461 client, self->error_msg);
462 IRRECO_RETRY_LOOP_END(self->loop)
464 if (success == FALSE) IRRECO_RETURN_BOOL(FALSE);
466 irreco_string_table_sort_abc (manufacturer_list);
467 irreco_string_table_change_data(self->categories, category,
468 manufacturer_list);
471 irreco_string_table_get(self->categories, category,
472 (gpointer *) manufacturers);
473 IRRECO_RETURN_BOOL(TRUE)
477 * Fetches all manufacturers from DB.
479 * @param all_manufacturers must be released if function returns TRUE.
480 * @return TRUE if manufacturers are fetched succesfully, FALSE otherwise.
482 gboolean irreco_webdb_cache_get_all_manufacturers(IrrecoWebdbCache *self,
483 IrrecoStringTable **all_manufacturers)
485 gboolean success = FALSE;
486 IrrecoWebdbClient *client = (IrrecoWebdbClient *) self->private;
487 IRRECO_ENTER
490 IRRECO_RETRY_LOOP_START(self->loop)
491 if (irreco_webdb_cache_test(self) == FALSE) break;
492 success = irreco_webdb_client_get_all_manufacturers(
493 client, all_manufacturers);
494 if (success) {
495 break;
497 irreco_webdb_client_get_error_msg(
498 client, self->error_msg);
499 IRRECO_RETRY_LOOP_END(self->loop)
501 if (success == FALSE) IRRECO_RETURN_BOOL(FALSE);
503 irreco_string_table_sort_abc(*all_manufacturers);
505 IRRECO_RETURN_BOOL(TRUE)
509 * Fetches models belonging given category and manufacturer.
511 * @param models must be freed if function returns TRUE.
512 * @return TRUE if models are fetched succesfully, FALSE otherwise.
514 gboolean irreco_webdb_cache_get_models(IrrecoWebdbCache *self,
515 const gchar *category,
516 const gchar *manufacturer,
517 IrrecoStringTable **models)
519 IrrecoStringTable *model_list;
520 IrrecoStringTable *manufacturer_list;
521 IRRECO_ENTER
523 if (!irreco_webdb_cache_verify_category(self) ||
524 !irreco_webdb_cache_verify_manufacturer(self, category,
525 &manufacturer_list) ||
526 !irreco_webdb_cache_verify_model(self, manufacturer_list,
527 manufacturer, &model_list)) {
528 IRRECO_RETURN_BOOL(FALSE)
531 if(model_list == NULL) {
532 gboolean success = FALSE;
533 IrrecoWebdbClient *client = (IrrecoWebdbClient *) self->private;
535 IRRECO_RETRY_LOOP_START(self->loop)
536 if (irreco_webdb_cache_test(self) == FALSE) break;
537 success = irreco_webdb_client_get_models(
538 client, category, manufacturer, &model_list);
540 if (success) break;
541 irreco_webdb_client_get_error_msg(
542 client, self->error_msg);
543 IRRECO_RETRY_LOOP_END(self->loop)
545 if (success == FALSE) IRRECO_RETURN_BOOL(FALSE);
547 irreco_string_table_sort_abc (model_list);
548 irreco_string_table_change_data(manufacturer_list, manufacturer,
549 model_list);
552 irreco_string_table_get(manufacturer_list, manufacturer,
553 (gpointer *) models);
554 IRRECO_RETURN_BOOL(TRUE)
558 * Fetches configs belonging given category, manufacturer and model.
560 * @return TRUE if configs are fetched succesfully, FALSE otherwise.
562 gboolean irreco_webdb_cache_get_configs(IrrecoWebdbCache *self,
563 const gchar *category,
564 const gchar *manufacturer,
565 const gchar *model,
566 IrrecoStringTable **configs)
568 IrrecoStringTable * config_list;
569 IrrecoStringTable * model_list;
570 IrrecoStringTable * manufacturer_list;
571 IRRECO_ENTER
573 if (!irreco_webdb_cache_verify_category(self) ||
574 !irreco_webdb_cache_verify_manufacturer(self, category,
575 &manufacturer_list) ||
576 !irreco_webdb_cache_verify_model(self, manufacturer_list,
577 manufacturer, &model_list) ||
578 !irreco_webdb_cache_verify_config(self, model_list, model,
579 &config_list)) {
580 IRRECO_RETURN_BOOL(FALSE)
583 if(config_list == NULL) {
584 gboolean success = FALSE;
585 IrrecoWebdbClient *client = (IrrecoWebdbClient *) self->private;
587 IRRECO_RETRY_LOOP_START(self->loop)
588 if (irreco_webdb_cache_test(self) == FALSE) break;
589 success = irreco_webdb_client_get_configs(client,
590 manufacturer, model, &config_list);
592 if (success) break;
593 irreco_webdb_client_get_error_msg(
594 client, self->error_msg);
595 IRRECO_RETRY_LOOP_END(self->loop)
597 if (success == FALSE) IRRECO_RETURN_BOOL(FALSE);
599 irreco_string_table_change_data(model_list, model, config_list);
602 irreco_string_table_get(model_list, model, (gpointer *) configs);
603 IRRECO_RETURN_BOOL(TRUE)
607 * Fetches configuration by given ID.
609 * @return TRUE if configuration is fetched succesfully, FALSE otherwise.
611 gboolean irreco_webdb_cache_get_configuration(IrrecoWebdbCache *self,
612 gint id,
613 IrrecoWebdbConf **config)
615 IrrecoWebdbConf * configuration;
616 IRRECO_ENTER
618 configuration = irreco_webdb_conf_new();
620 if (g_hash_table_lookup(self->conf_hash, (gconstpointer) &id) == NULL) {
621 gboolean success = FALSE;
622 IrrecoWebdbClient *client = (IrrecoWebdbClient *) self->private;
624 IRRECO_RETRY_LOOP_START(self->loop)
625 if (irreco_webdb_cache_test(self) == FALSE) break;
626 success = irreco_webdb_client_get_configuration(
627 client, id, &configuration);
629 if (success) break;
630 irreco_webdb_client_get_error_msg(client,
631 self->error_msg);
632 IRRECO_RETRY_LOOP_END(self->loop)
634 if (success == FALSE) IRRECO_RETURN_BOOL(FALSE);
636 g_hash_table_insert(self->conf_hash,
637 (gpointer) &configuration->id,
638 (gpointer) configuration);
641 *config = g_hash_table_lookup(self->conf_hash, (gconstpointer) &id);
643 IRRECO_RETURN_BOOL(TRUE)
646 gint irreco_webdb_cache_get_config_id(IrrecoWebdbCache *self,
647 const gchar *file_hash,
648 const gchar *file_name)
650 IRRECO_ENTER
651 IRRECO_RETURN_INT(
652 irreco_webdb_client_get_config_id_by_file_hash_and_file_name(
653 self->private, file_hash, file_name));
657 * Fetches file by given hash and name.
659 * @return TRUE if configuration is fetched succesfully, FALSE otherwise.
661 gboolean irreco_webdb_cache_get_file(IrrecoWebdbCache *self,
662 const gchar *file_hash,
663 const gchar *file_name,
664 GString **file_data)
666 GString *file;
667 gboolean success = FALSE;
668 IrrecoWebdbClient *client;
669 IRRECO_ENTER
671 client = (IrrecoWebdbClient *) self->private;
673 IRRECO_RETRY_LOOP_START(self->loop)
674 if (irreco_webdb_cache_test(self) == FALSE) break;
675 success = irreco_webdb_client_get_file(
676 client, file_hash, file_name, &file);
678 if (success) break;
679 irreco_webdb_client_get_error_msg(client, self->error_msg);
680 IRRECO_RETRY_LOOP_END(self->loop)
682 if (success == FALSE) IRRECO_RETURN_BOOL(FALSE);
684 *file_data = file;
686 IRRECO_RETURN_BOOL(TRUE)
690 * Check if user with given name is already at DB.
692 *.@param user_exists will contain info wether user name was at DB.
693 * @return TRUE if test is done succesfully, FALSE otherwise.
695 gboolean irreco_webdb_cache_get_user_exists(IrrecoWebdbCache *self,
696 const gchar *name,
697 gboolean *user_exists)
699 IrrecoWebdbClient *client;
700 gboolean success = FALSE;
702 IRRECO_ENTER
703 client = (IrrecoWebdbClient *) self->private;
704 IRRECO_RETRY_LOOP_START(self->loop)
705 /* test connection to webdb */
706 if (irreco_webdb_cache_test(self) == FALSE) break;
708 success = irreco_webdb_client_get_user_exists(client,
709 name,
710 user_exists);
712 if (success) break;
714 /* irreco_webdb_client_get_user_exists failed, get err msg */
715 irreco_webdb_client_get_error_msg(client, self->error_msg);
716 IRRECO_RETRY_LOOP_END(self->loop)
718 if (success == FALSE) IRRECO_RETURN_BOOL(FALSE);
720 IRRECO_RETURN_BOOL(TRUE)
724 * Get maximum image size accepted by database
726 gint irreco_webdb_cache_get_max_image_size(IrrecoWebdbCache *self)
728 IrrecoWebdbClient *client;
729 IRRECO_ENTER
730 client = (IrrecoWebdbClient *) self->private;
731 IRRECO_RETURN_INT(irreco_webdb_client_get_max_image_size(client));
735 * Create theme
737 gint irreco_webdb_cache_create_theme(IrrecoWebdbCache *self,
738 const gchar *name,
739 const gchar *comment,
740 const gchar *preview_button,
741 const gchar *folder,
742 const gchar *user,
743 const gchar *password)
745 IrrecoWebdbClient *client;
746 IRRECO_ENTER
747 client = (IrrecoWebdbClient *) self->private;
748 IRRECO_RETURN_INT(irreco_webdb_client_create_theme(
749 client,
750 name,
751 comment,
752 preview_button,
753 folder,
754 user,
755 password));
759 * Set theme downloadable
761 gboolean irreco_webdb_cache_set_theme_downloadable(IrrecoWebdbCache *self,
762 gint id,
763 gboolean downloadable,
764 const gchar *user,
765 const gchar *password)
767 IrrecoWebdbClient *client;
768 IRRECO_ENTER
769 client = (IrrecoWebdbClient *) self->private;
770 IRRECO_RETURN_BOOL(irreco_webdb_client_set_theme_downloadable(
771 client,
773 downloadable,
774 user,
775 password));
779 * Login to database.
781 * @return TRUE if login is succesful, FALSE otherwise.
783 gboolean irreco_webdb_cache_login(IrrecoWebdbCache *self,
784 const gchar *user,
785 const gchar *password)
787 IrrecoWebdbClient *client;
789 IRRECO_ENTER
791 client = (IrrecoWebdbClient *) self->private;
793 IRRECO_RETRY_LOOP_START(self->loop)
794 /* test connection to webdb */
795 if (irreco_webdb_cache_test(self) == FALSE){
796 g_string_printf(self->error_msg,
797 "Failed cache self test.");
798 IRRECO_PRINTF("%s\n", self->error_msg->str);
799 IRRECO_RETURN_BOOL(FALSE);
802 if(irreco_webdb_client_login(client, user, password)) {
804 IRRECO_RETURN_BOOL(TRUE);
805 } else {
806 /* irreco_webdb_client_login failed,
807 get err msg */
808 irreco_webdb_client_get_error_msg(client,
809 self->error_msg);
810 IRRECO_RETURN_BOOL(FALSE);
812 IRRECO_RETRY_LOOP_END(self->loop)
814 IRRECO_RETURN_BOOL(FALSE);
817 gboolean irreco_webdb_cache_get_themes(IrrecoWebdbCache *self,
818 IrrecoStringTable **theme)
820 gboolean success = FALSE;
821 IrrecoWebdbClient *client = (IrrecoWebdbClient *) self->private;
822 IRRECO_ENTER
824 IRRECO_RETRY_LOOP_START(self->loop)
825 if (irreco_webdb_cache_test(self) == FALSE) break;
826 success = irreco_webdb_client_get_themes(client, theme);
828 if (success) break;
829 irreco_webdb_client_get_error_msg(client, self->error_msg);
830 IRRECO_RETRY_LOOP_END(self->loop)
832 IRRECO_RETURN_BOOL(success)
835 gboolean irreco_webdb_cache_get_theme_by_id(IrrecoWebdbCache *self,
836 gint theme_id,
837 IrrecoWebdbTheme **theme)
839 IrrecoWebdbTheme *get_theme;
840 IRRECO_ENTER
843 if (g_hash_table_lookup(self->theme_id_hash,
844 (gconstpointer) &theme_id) == NULL) {
845 gboolean success = FALSE;
846 IrrecoWebdbClient *client = (IrrecoWebdbClient *) self->private;
848 IRRECO_RETRY_LOOP_START(self->loop)
849 if (irreco_webdb_cache_test(self) == FALSE) break;
850 success = irreco_webdb_client_get_theme_by_id(
851 client, theme_id, &get_theme);
853 if (success) break;
854 irreco_webdb_client_get_error_msg(client,
855 self->error_msg);
856 IRRECO_RETRY_LOOP_END(self->loop)
858 if (success == FALSE) IRRECO_RETURN_BOOL(FALSE);
860 g_hash_table_insert(self->theme_id_hash,
861 (gpointer) &get_theme->id,
862 (gpointer) get_theme);
865 *theme = g_hash_table_lookup(self->theme_id_hash, (gconstpointer) &theme_id);
867 IRRECO_RETURN_BOOL(TRUE)
870 gint irreco_webdb_cache_get_theme_id_by_name_and_date(IrrecoWebdbCache *self,
871 const gchar *name,
872 const gchar *date)
874 IRRECO_ENTER
875 IRRECO_RETURN_INT(irreco_webdb_client_get_theme_id_by_name_and_date(
876 self->private, name, date));
880 gboolean irreco_webdb_cache_get_preview_button(IrrecoWebdbCache *self,
881 gint theme_id,
882 IrrecoWebdbTheme **theme)
884 gboolean success = TRUE;
885 IrrecoWebdbClient *client = (IrrecoWebdbClient *) self->private;
886 IRRECO_ENTER
888 *theme = g_hash_table_lookup(self->theme_id_hash,
889 (gconstpointer) &theme_id);
890 if (*theme == NULL) {
891 success = irreco_webdb_cache_get_theme_by_id(self, theme_id,
892 theme);
893 if (success == FALSE) {
894 irreco_webdb_client_get_error_msg(client, self->error_msg);
895 goto end;
899 if ((*theme)->preview_button == NULL)
901 IRRECO_RETRY_LOOP_START(self->loop)
903 if (irreco_webdb_cache_test(self) == FALSE) break;
905 success = irreco_webdb_client_get_preview_button(client,
906 theme_id, &(*theme)->preview_button);
908 if (success) break;
910 irreco_webdb_client_get_error_msg(client, self->error_msg);
911 IRRECO_RETRY_LOOP_END(self->loop)
914 end:
916 IRRECO_RETURN_BOOL(success)
920 * Add bg to theme
922 gint irreco_webdb_cache_add_bg_to_theme(IrrecoWebdbCache *self,
923 const gchar *name,
924 const gchar *image_hash,
925 const gchar *image_name,
926 const guchar *image,
927 gint image_len,
928 const gchar *folder,
929 gint theme_id,
930 const gchar *user,
931 const gchar *password)
933 IrrecoWebdbClient *client;
934 IRRECO_ENTER
935 client = (IrrecoWebdbClient *) self->private;
936 IRRECO_RETURN_INT(irreco_webdb_client_add_bg_to_theme(
937 client,
938 name,
939 image_hash,
940 image_name,
941 image,
942 image_len,
943 folder,
944 theme_id,
945 user,
946 password));
949 gboolean irreco_webdb_cache_get_backgrounds(IrrecoWebdbCache *self,
950 gint theme_id,
951 IrrecoStringTable **bg_list){
952 IrrecoWebdbClient *client;
953 gboolean success = TRUE;
954 IRRECO_ENTER
956 client = (IrrecoWebdbClient *) self->private;
957 IRRECO_RETRY_LOOP_START(self->loop)
958 if (irreco_webdb_cache_test(self) == FALSE) break;
959 success = irreco_webdb_client_get_backgrounds(client,
960 theme_id,
961 bg_list);
962 if (success) break;
963 irreco_webdb_client_get_error_msg(client, self->error_msg);
964 IRRECO_RETRY_LOOP_END(self->loop)
966 IRRECO_RETURN_BOOL(success)
969 gboolean irreco_webdb_cache_get_bg_by_id(IrrecoWebdbCache *self,
970 gint bg_id,
971 const char *theme_bg_dir)
973 IrrecoWebdbClient *client = (IrrecoWebdbClient *) self->private;
974 gboolean success = TRUE;
975 IRRECO_ENTER
977 IRRECO_RETRY_LOOP_START(self->loop)
978 if (irreco_webdb_cache_test(self) == FALSE) break;
979 success = irreco_webdb_client_get_bg_by_id(client,
980 bg_id,
981 theme_bg_dir);
982 if (success) break;
983 irreco_webdb_client_get_error_msg(client, self->error_msg);
984 IRRECO_RETRY_LOOP_END(self->loop)
985 IRRECO_RETURN_BOOL(success)
989 * Add button to theme
991 gint irreco_webdb_cache_add_button_to_theme(IrrecoWebdbCache *self,
992 const gchar *name,
993 gboolean allow_text,
994 const gchar *text_format_up,
995 const gchar *text_format_down,
996 gint text_padding,
997 gfloat text_h_align,
998 gfloat text_v_align,
999 const gchar *image_up_hash,
1000 const gchar *image_up_name,
1001 const guchar *image_up,
1002 gint image_up_len,
1003 const gchar *image_down_hash,
1004 const gchar *image_down_name,
1005 const guchar *image_down,
1006 gint image_down_len,
1007 const gchar *folder,
1008 gint theme_id,
1009 const gchar *user,
1010 const gchar *password)
1012 IrrecoWebdbClient *client;
1013 IRRECO_ENTER
1014 client = (IrrecoWebdbClient *) self->private;
1015 IRRECO_RETURN_INT(irreco_webdb_client_add_button_to_theme(
1016 client,
1017 name,
1018 allow_text,
1019 text_format_up,
1020 text_format_down,
1021 text_padding,
1022 text_h_align,
1023 text_v_align,
1024 image_up_hash,
1025 image_up_name,
1026 image_up,
1027 image_up_len,
1028 image_down_hash,
1029 image_down_name,
1030 image_down,
1031 image_down_len,
1032 folder,
1033 theme_id,
1034 user,
1035 password));
1038 gboolean irreco_webdb_cache_get_buttons(IrrecoWebdbCache *self,
1039 gint theme_id,
1040 IrrecoStringTable **button_list)
1042 IrrecoWebdbClient *client = (IrrecoWebdbClient *) self->private;
1043 gboolean success = TRUE;
1044 IRRECO_ENTER
1046 IRRECO_RETRY_LOOP_START(self->loop)
1047 if (irreco_webdb_cache_test(self) == FALSE) break;
1048 success = irreco_webdb_client_get_buttons(client,
1049 theme_id,
1050 button_list);
1051 if (success) break;
1052 irreco_webdb_client_get_error_msg(client, self->error_msg);
1053 IRRECO_RETRY_LOOP_END(self->loop)
1054 IRRECO_RETURN_BOOL(success)
1057 gboolean irreco_webdb_cache_get_button_by_id(IrrecoWebdbCache *self,
1058 gint button_id,
1059 const char *theme_button_dir)
1061 IrrecoWebdbClient *client = (IrrecoWebdbClient *) self->private;
1062 gboolean success = TRUE;
1063 IRRECO_ENTER
1065 IRRECO_RETRY_LOOP_START(self->loop)
1066 if (irreco_webdb_cache_test(self) == FALSE) break;
1067 success = irreco_webdb_client_get_button_by_id(client,
1068 button_id,
1069 theme_button_dir);
1070 if (success) break;
1071 irreco_webdb_client_get_error_msg(client, self->error_msg);
1072 IRRECO_RETRY_LOOP_END(self->loop)
1074 IRRECO_RETURN_BOOL(success)
1078 gint irreco_webdb_cache_create_new_remote(IrrecoWebdbCache *self,
1079 const gchar *comment,
1080 const gchar *category,
1081 const gchar *manufacturer,
1082 const gchar *model,
1083 const gchar *file_name,
1084 const gchar *file_data,
1085 const gchar *user,
1086 const gchar *password)
1088 IRRECO_ENTER
1089 if (irreco_webdb_cache_test(self) == FALSE) IRRECO_RETURN_INT(0);
1090 IRRECO_RETURN_INT(irreco_webdb_client_create_new_remote(self->private,
1091 comment, category, manufacturer, model, file_name,
1092 file_data, user, password));
1095 gboolean irreco_webdb_cache_set_remote_downloadable(IrrecoWebdbCache *self,
1096 gint id,
1097 gboolean downloadable,
1098 const gchar *user,
1099 const gchar *password)
1101 gboolean success;
1102 IRRECO_ENTER
1104 IRRECO_RETRY_LOOP_START(self->loop)
1105 if (irreco_webdb_cache_test(self) == FALSE) break;
1106 success = irreco_webdb_client_set_remote_downloadable(
1107 self->private, id, downloadable, user, password);
1108 if (success) break;
1109 irreco_webdb_client_get_error_msg(self->private,
1110 self->error_msg);
1111 IRRECO_RETRY_LOOP_END(self->loop)
1112 IRRECO_RETURN_BOOL(success);
1115 gboolean irreco_webdb_cache_add_configuration_to_remote(IrrecoWebdbCache *self,
1116 gint remote_id,
1117 gint configuration_id,
1118 const gchar *user,
1119 const gchar *password)
1121 gboolean success;
1122 IRRECO_ENTER
1124 IRRECO_RETRY_LOOP_START(self->loop)
1125 if (irreco_webdb_cache_test(self) == FALSE) break;
1126 success = irreco_webdb_client_add_configuration_to_remote(
1127 self->private, remote_id,
1128 configuration_id, user,
1129 password);
1130 if (success) break;
1131 irreco_webdb_client_get_error_msg(self->private,
1132 self->error_msg);
1133 IRRECO_RETRY_LOOP_END(self->loop)
1134 IRRECO_RETURN_BOOL(success);
1137 gboolean irreco_webdb_cache_add_theme_to_remote(IrrecoWebdbCache *self,
1138 gint remote_id,
1139 gint theme_id,
1140 const gchar *user,
1141 const gchar *password)
1143 gboolean success;
1144 IRRECO_ENTER
1146 IRRECO_RETRY_LOOP_START(self->loop)
1147 if (irreco_webdb_cache_test(self) == FALSE) break;
1148 success = irreco_webdb_client_add_theme_to_remote(
1149 self->private, remote_id,
1150 theme_id, user, password);
1151 if (success) break;
1152 irreco_webdb_client_get_error_msg(self->private,
1153 self->error_msg);
1154 IRRECO_RETRY_LOOP_END(self->loop)
1155 IRRECO_RETURN_BOOL(success);
1159 * Fetches remote categories from DB
1161 * @param categories points to internally allocated storage in the cache
1162 * and must not be freed
1163 * @return TRUE if categories are fetched succesfully, FALSE otherwise.
1165 gboolean irreco_webdb_cache_get_remote_categories(IrrecoWebdbCache *self,
1166 IrrecoStringTable **categories)
1168 IRRECO_ENTER
1170 if (self->remote_categories == NULL) {
1171 gboolean success = FALSE;
1173 IRRECO_RETRY_LOOP_START(self->loop)
1174 if (irreco_webdb_cache_test(self) == FALSE) break;
1175 success = irreco_webdb_client_get_remote_categories(
1176 self->private, &self->remote_categories);
1177 if (success) {
1178 break;
1180 irreco_webdb_client_get_error_msg(self->private,
1181 self->error_msg);
1182 IRRECO_RETRY_LOOP_END(self->loop)
1184 if (success == FALSE) IRRECO_RETURN_BOOL(FALSE);
1186 irreco_string_table_sort_abc(self->remote_categories);
1189 *categories = self->remote_categories;
1190 IRRECO_RETURN_BOOL(TRUE)
1194 * Fetches remote manufacturers from DB.
1196 * @param category contains category in which type manufacturers are returned.
1197 * @param manufacturers points to internally allocated storage in the cache
1198 * and must not be freed
1199 * @return TRUE if manufacturers are fetched succesfully, FALSE otherwise.
1201 gboolean irreco_webdb_cache_get_remote_manufacturers(IrrecoWebdbCache *self,
1202 const gchar *category,
1203 IrrecoStringTable **manufacturers)
1205 IrrecoStringTable *categories;
1206 IrrecoStringTable *manufacturer_list;
1207 IRRECO_ENTER
1209 if (!irreco_webdb_cache_get_remote_categories(self, &categories)) {
1210 IRRECO_RETURN_BOOL(FALSE)
1213 if (!irreco_string_table_exists(categories, category)) {
1214 g_string_printf(self->error_msg, "%s",
1215 "Can't find category");
1216 IRRECO_RETURN_BOOL(FALSE)
1219 irreco_string_table_get(categories, category,
1220 (gpointer *) &manufacturer_list);
1222 if (manufacturer_list == NULL) {
1223 gboolean success = FALSE;
1224 IRRECO_RETRY_LOOP_START(self->loop)
1225 if (irreco_webdb_cache_test(self) == FALSE) break;
1226 success = irreco_webdb_client_get_remote_manufacturers(
1227 self->private, category, &manufacturer_list);
1229 if (success) break;
1230 irreco_webdb_client_get_error_msg(self->private,
1231 self->error_msg);
1232 IRRECO_RETRY_LOOP_END(self->loop)
1234 if (success == FALSE) IRRECO_RETURN_BOOL(FALSE);
1236 irreco_string_table_sort_abc (manufacturer_list);
1237 irreco_string_table_change_data(categories, category,
1238 manufacturer_list);
1241 irreco_string_table_get(categories, category,
1242 (gpointer *) manufacturers);
1244 IRRECO_RETURN_BOOL(TRUE)
1248 * Fetches remote models belonging given category and manufacturer.
1250 * @param models points to internally allocated storage in the cache
1251 * and must not be freed
1252 * @return TRUE if models are fetched succesfully, FALSE otherwise.
1254 gboolean irreco_webdb_cache_get_remote_models(IrrecoWebdbCache *self,
1255 const gchar *category,
1256 const gchar *manufacturer,
1257 IrrecoStringTable **models)
1259 IrrecoStringTable *manufacturer_list;
1260 IrrecoStringTable *model_list;
1261 IRRECO_ENTER
1263 if (!irreco_webdb_cache_get_remote_manufacturers(self, category,
1264 &manufacturer_list)) {
1265 IRRECO_RETURN_BOOL(FALSE)
1268 if (!irreco_string_table_exists(manufacturer_list, manufacturer)) {
1269 g_string_printf(self->error_msg, "%s",
1270 "Can't find manufacturer");
1271 IRRECO_RETURN_BOOL(FALSE)
1274 irreco_string_table_get(manufacturer_list, manufacturer,
1275 (gpointer *) &model_list);
1277 if(model_list == NULL) {
1278 gboolean success = FALSE;
1280 IRRECO_RETRY_LOOP_START(self->loop)
1281 if (irreco_webdb_cache_test(self) == FALSE) break;
1282 success = irreco_webdb_client_get_remote_models(
1283 self->private, category, manufacturer,
1284 &model_list);
1286 if (success) break;
1287 irreco_webdb_client_get_error_msg(self->private,
1288 self->error_msg);
1289 IRRECO_RETRY_LOOP_END(self->loop)
1291 if (success == FALSE) IRRECO_RETURN_BOOL(FALSE);
1293 irreco_string_table_sort_abc (model_list);
1294 irreco_string_table_change_data(manufacturer_list, manufacturer,
1295 model_list);
1298 irreco_string_table_get(manufacturer_list, manufacturer,
1299 (gpointer *) models);
1300 IRRECO_RETURN_BOOL(TRUE)
1304 * Fetches creators belonging given category, manufacturer and model.
1306 * @param creators points to internally allocated storage in the cache
1307 * and must not be freed
1308 * @return TRUE if configs are fetched succesfully, FALSE otherwise.
1310 gboolean irreco_webdb_cache_get_remote_creators(IrrecoWebdbCache *self,
1311 const gchar *category,
1312 const gchar *manufacturer,
1313 const gchar *model,
1314 IrrecoStringTable **creators)
1316 IrrecoStringTable * model_list;
1317 IrrecoStringTable * creator_list;
1318 IRRECO_ENTER
1320 if (!irreco_webdb_cache_get_remote_models(self, category, manufacturer,
1321 &model_list)) {
1322 IRRECO_RETURN_BOOL(FALSE)
1325 if (!irreco_string_table_exists(model_list, model)) {
1326 g_string_printf(self->error_msg, "%s",
1327 "Can't find model");
1328 IRRECO_RETURN_BOOL(FALSE)
1331 irreco_string_table_get(model_list, model, (gpointer *) &creator_list);
1333 if(creator_list == NULL) {
1334 gboolean success = FALSE;
1336 IRRECO_RETRY_LOOP_START(self->loop)
1337 if (irreco_webdb_cache_test(self) == FALSE) break;
1338 success = irreco_webdb_client_get_remote_creators(
1339 self->private, category, manufacturer,
1340 model, &creator_list);
1342 if (success) break;
1343 irreco_webdb_client_get_error_msg(self->private,
1344 self->error_msg);
1345 IRRECO_RETRY_LOOP_END(self->loop)
1347 if (success == FALSE) IRRECO_RETURN_BOOL(FALSE);
1349 irreco_string_table_change_data(model_list, model,
1350 creator_list);
1353 irreco_string_table_get(model_list, model, (gpointer *) creators);
1354 IRRECO_RETURN_BOOL(TRUE)
1358 * Fetches creators belonging given category, manufacturer and model.
1360 * @param creators points to internally allocated storage in the cache
1361 * and must not be freed
1362 * @return TRUE if configs are fetched succesfully, FALSE otherwise.
1364 gboolean irreco_webdb_cache_get_remotes(IrrecoWebdbCache *self,
1365 const gchar *category,
1366 const gchar *manufacturer,
1367 const gchar *model,
1368 const gchar *creator,
1369 GList **remote_list)
1371 IrrecoStringTable * creator_list;
1372 IRRECO_ENTER
1374 if (!irreco_webdb_cache_get_remote_creators(self, category,
1375 manufacturer, model,
1376 &creator_list)) {
1377 IRRECO_RETURN_BOOL(FALSE)
1380 if (!irreco_string_table_exists(creator_list, creator)) {
1381 g_string_printf(self->error_msg, "%s",
1382 "Can't find creator");
1383 IRRECO_RETURN_BOOL(FALSE)
1386 irreco_string_table_get(creator_list, creator,
1387 (gpointer *) remote_list);
1389 if(*remote_list == NULL) {
1390 gboolean success = FALSE;
1392 IRRECO_RETRY_LOOP_START(self->loop)
1393 if (irreco_webdb_cache_test(self) == FALSE) break;
1394 success = irreco_webdb_client_get_remotes(self->private,
1395 category, manufacturer, model,
1396 creator, remote_list);
1398 if (success) break;
1399 irreco_webdb_client_get_error_msg(self->private,
1400 self->error_msg);
1401 IRRECO_RETRY_LOOP_END(self->loop)
1403 if (success == FALSE) IRRECO_RETURN_BOOL(FALSE);
1405 irreco_string_table_change_data(creator_list, creator,
1406 *remote_list);
1409 irreco_string_table_get(creator_list, creator,
1410 (gpointer *) remote_list);
1411 IRRECO_RETURN_BOOL(TRUE)
1415 * Fetches remote by given ID.
1417 * @param remote points to internally allocated storage in the cache
1418 * and must not be freed
1419 * @return TRUE if remote is fetched succesfully, FALSE otherwise.
1421 gboolean irreco_webdb_cache_get_remote_by_id(IrrecoWebdbCache *self,
1422 gint id,
1423 IrrecoWebdbRemote **remote)
1425 IRRECO_ENTER
1427 if (g_hash_table_lookup(self->remote_id_hash,
1428 (gconstpointer) &id) == NULL) {
1429 gboolean success = FALSE;
1431 IRRECO_RETRY_LOOP_START(self->loop)
1432 if (irreco_webdb_cache_test(self) == FALSE) break;
1433 success = irreco_webdb_client_get_remote_by_id(
1434 self->private, id, remote);
1436 if (success) break;
1437 irreco_webdb_client_get_error_msg(self->private,
1438 self->error_msg);
1439 IRRECO_RETRY_LOOP_END(self->loop)
1441 if (success == FALSE) IRRECO_RETURN_BOOL(FALSE);
1443 g_hash_table_insert(self->remote_id_hash,
1444 (gpointer) &((*remote)->id),
1445 (gpointer) *remote);
1448 *remote = g_hash_table_lookup(self->remote_id_hash,
1449 (gconstpointer) &id);
1451 IRRECO_RETURN_BOOL(TRUE)
1455 * Fetches configurations belonging given remote_id.
1457 * @param configs points to internally allocated storage in the cache
1458 * and must not be freed
1459 * @return TRUE if remote is fetched succesfully, FALSE otherwise.
1461 gboolean irreco_webdb_cache_get_configurations_of_remote(IrrecoWebdbCache *self,
1462 gint remote_id,
1463 GList **configs)
1465 IrrecoWebdbRemote *remote;
1466 GList *configuration_list = NULL;
1467 gboolean success = FALSE;
1468 IRRECO_ENTER
1470 if (!irreco_webdb_cache_get_remote_by_id(self, remote_id, &remote)) {
1471 IRRECO_RETURN_BOOL(FALSE)
1475 if (remote->configurations != NULL) {
1476 goto end;
1479 IRRECO_RETRY_LOOP_START(self->loop)
1480 if (irreco_webdb_cache_test(self) == FALSE) break;
1481 success = irreco_webdb_client_get_configurations_of_remote(
1482 self->private, remote_id,
1483 &configuration_list);
1485 if (success) break;
1486 irreco_webdb_client_get_error_msg(self->private,
1487 self->error_msg);
1488 IRRECO_RETRY_LOOP_END(self->loop)
1490 if (success == FALSE) IRRECO_RETURN_BOOL(FALSE);
1492 configuration_list = g_list_first(configuration_list);
1493 while(configuration_list) {
1494 irreco_webdb_remote_add_configuration_id(remote,
1495 GPOINTER_TO_INT(configuration_list->data));
1496 configuration_list = configuration_list->next;
1498 g_list_free(configuration_list);
1500 end:
1501 *configs = remote->configurations;
1503 IRRECO_RETURN_BOOL(TRUE)
1507 * Fetches themes belonging given remote_id.
1509 * @param themes points to internally allocated storage in the cache
1510 * and must not be freed
1511 * @return TRUE if remote is fetched succesfully, FALSE otherwise.
1513 gboolean irreco_webdb_cache_get_themes_of_remote(IrrecoWebdbCache *self,
1514 gint remote_id,
1515 GList **themes)
1517 IrrecoWebdbRemote *remote;
1518 GList *theme_list = NULL;
1519 gboolean success = FALSE;
1520 IRRECO_ENTER
1522 if (!irreco_webdb_cache_get_remote_by_id(self, remote_id, &remote)) {
1523 IRRECO_RETURN_BOOL(FALSE)
1526 if (remote->themes != NULL) {
1527 goto end;
1530 IRRECO_RETRY_LOOP_START(self->loop)
1531 if (irreco_webdb_cache_test(self) == FALSE) break;
1532 success = irreco_webdb_client_get_themes_of_remote(
1533 self->private, remote_id,
1534 &theme_list);
1536 if (success) break;
1537 irreco_webdb_client_get_error_msg(self->private,
1538 self->error_msg);
1539 IRRECO_RETRY_LOOP_END(self->loop)
1541 if (success == FALSE) IRRECO_RETURN_BOOL(FALSE);
1543 theme_list = g_list_first(theme_list);
1544 while(theme_list) {
1545 irreco_webdb_remote_add_theme_id(remote, GPOINTER_TO_INT(
1546 theme_list->data));
1547 theme_list = theme_list->next;
1549 g_list_free(theme_list);
1551 end:
1552 *themes = remote->themes;
1554 IRRECO_RETURN_BOOL(TRUE)
1558 * Fetches remote data by given ID.
1560 * @return TRUE if data is fetched succesfully, FALSE otherwise.
1562 gboolean irreco_webdb_cache_get_remote_data(IrrecoWebdbCache *self,
1563 gint remote_id,
1564 gchar **file_data)
1566 gboolean success;
1567 IRRECO_ENTER
1569 IRRECO_RETRY_LOOP_START(self->loop)
1570 if (irreco_webdb_cache_test(self) == FALSE) break;
1571 success = irreco_webdb_client_get_remote_data(self->private,
1572 remote_id,
1573 file_data);
1574 if (success) break;
1575 irreco_webdb_client_get_error_msg(self->private,
1576 self->error_msg);
1577 IRRECO_RETRY_LOOP_END(self->loop)
1578 IRRECO_RETURN_BOOL(success);
1581 gboolean irreco_webdb_cache_get_lirc_dirs(IrrecoWebdbCache *self,
1582 IrrecoStringTable **dir_list)
1584 gboolean success = FALSE;
1585 IrrecoWebdbClient *client = (IrrecoWebdbClient *) self->private;
1587 IRRECO_ENTER
1589 IRRECO_RETRY_LOOP_START(self->loop)
1590 if (irreco_webdb_cache_test(self) == FALSE) break;
1591 success = irreco_webdb_client_get_lirc_dirs(client,
1592 dir_list);
1593 if (success) break;
1594 irreco_webdb_client_get_error_msg(client,
1595 self->error_msg);
1596 IRRECO_RETRY_LOOP_END(self->loop)
1598 if(success == FALSE) IRRECO_RETURN_BOOL(FALSE);
1600 IRRECO_RETURN_BOOL(success);
1603 gboolean irreco_webdb_cache_get_lirc_manufacturers(IrrecoWebdbCache *self,
1604 const gchar *range,
1605 IrrecoStringTable **manufacturer_list)
1607 gboolean success = FALSE;
1608 IrrecoWebdbClient *client = (IrrecoWebdbClient *) self->private;
1610 IRRECO_ENTER
1612 IRRECO_RETRY_LOOP_START(self->loop)
1613 if (irreco_webdb_cache_test(self) == FALSE) break;
1614 success = irreco_webdb_client_get_lirc_manufacturers(
1615 client,
1616 range,
1617 manufacturer_list);
1618 if (success) break;
1619 irreco_webdb_client_get_error_msg(client,
1620 self->error_msg);
1621 IRRECO_RETRY_LOOP_END(self->loop)
1623 if(success == FALSE) IRRECO_RETURN_BOOL(FALSE);
1625 IRRECO_RETURN_BOOL(success);
1628 gboolean irreco_webdb_cache_get_lirc_models(IrrecoWebdbCache *self,
1629 const gchar *manufacturer,
1630 IrrecoStringTable **model_list)
1632 gboolean success = FALSE;
1633 IrrecoWebdbClient *client = (IrrecoWebdbClient *) self->private;
1635 IRRECO_ENTER
1637 IRRECO_RETRY_LOOP_START(self->loop)
1638 if (irreco_webdb_cache_test(self) == FALSE) break;
1639 success = irreco_webdb_client_get_lirc_models(
1640 client,
1641 manufacturer,
1642 model_list);
1643 if (success) break;
1644 irreco_webdb_client_get_error_msg(client,
1645 self->error_msg);
1646 IRRECO_RETRY_LOOP_END(self->loop)
1648 if(success == FALSE) IRRECO_RETURN_BOOL(FALSE);
1650 IRRECO_RETURN_BOOL(success);
1653 gboolean irreco_webdb_cache_get_lirc_file(IrrecoWebdbCache *self,
1654 const gchar *model,
1655 IrrecoStringTable **file)
1657 gboolean success = FALSE;
1658 IrrecoWebdbClient *client = (IrrecoWebdbClient *) self->private;
1660 IRRECO_ENTER
1662 IRRECO_RETRY_LOOP_START(self->loop)
1663 if (irreco_webdb_cache_test(self) == FALSE) break;
1664 success = irreco_webdb_client_get_lirc_file(
1665 client,
1666 model,
1667 file);
1668 if (success) break;
1669 irreco_webdb_client_get_error_msg(client,
1670 self->error_msg);
1671 IRRECO_RETRY_LOOP_END(self->loop)
1673 if(success == FALSE) IRRECO_RETURN_BOOL(FALSE);
1675 IRRECO_RETURN_BOOL(success);
1678 /** @} */
1680 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
1681 /* Events and Callbacks */
1682 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
1684 /** @} */