Created function which returns configuration_id by file_hash and file_name
[irreco.git] / irreco / src / webdb / irreco_webdb_client.c
blob5243b4bbab6d365ba3da65ec124f685334fc63e4
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)
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License
10 * as published by the Free Software Foundation; either version 2
11 * of the License, or (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software Foundation,
20 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
23 #include "irreco_webdb_client.h"
24 #include "config.h"
26 /**
27 * @addtogroup IrrecoWebdbClient
28 * @ingroup IrrecoWebdb
30 * Irreco Web Database API implementation. These functions connect to the
31 * IrrecoWebdbClient trough XML-RPC connection, pass arguments, and decode
32 * return values.
34 * @{
37 /**
38 * @file
39 * Source file of @ref IrrecoWebdbClient.
42 /*#define IRRECO_WEBDB_URL "http://mercury.wipsl.com/irreco/webdb/"*/
43 /*#define IRRECO_WEBDB_URL "http://127.0.0.1/irreco/webdb/"*/
46 for php files
47 svn co svn+irreco:///irreco/irreco/database/trunk/php /var/www/irreco/webdb
50 static const char *const value_type[] = {
51 "BAD",
52 "int",
53 "boolean",
54 "string",
55 "double",
56 "datetime",
57 "base64",
58 "struct",
59 "array"
62 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
63 /* Prototypes */
64 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
66 static void irreco_webdb_client_reset_env();
67 static SoupXmlrpcResponse *do_xmlrpc(SoupXmlrpcMessage *xmsg,
68 SoupXmlrpcValueType type,
69 IrrecoWebdbClient *self);
72 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
73 /* Construction & Destruction */
74 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
76 /**
77 * @name Construction & Destruction
78 * @{
81 /**
82 * Create new IrrecoWebdbClient Object
84 IrrecoWebdbClient *irreco_webdb_client_new()
86 IrrecoWebdbClient *self;
87 IRRECO_ENTER
89 self = g_slice_new0(IrrecoWebdbClient);
91 /* Allocate 1000 characters to soup error message */
92 /*self->error_msg = g_malloc0(1000*sizeof(*self->error_msg));*/
93 /** @todo do same to do_xmlrpc errormsg gchar */
94 /* use GString->str if that can grow on it own*/
95 self->error_msg = g_string_new(NULL);
97 IRRECO_RETURN_PTR(self);
100 void irreco_webdb_client_free(IrrecoWebdbClient *self)
102 IRRECO_ENTER
104 g_assert(self != NULL);
106 /* Free self->error_msg resource */
107 g_string_free(self->error_msg, TRUE);
108 self->error_msg = NULL;
110 g_slice_free(IrrecoWebdbClient, self);
111 self = NULL;
113 IRRECO_RETURN
116 /** @} */
118 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
119 /* Private Functions */
120 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
123 * @name Private Functions
124 * @{
128 * Release of RPC results and errors.
130 static void irreco_webdb_client_reset_env(IrrecoWebdbClient *self)
132 IRRECO_ENTER
134 self->error_msg = g_string_erase(self->error_msg, 0, -1);
136 IRRECO_RETURN
139 /** @todo Funcs return bool wether they succeeded, so this could be removed. */
141 * Check if the previous call to XMLRPC-C succeeded.
143 * @return TRUE if error occured, FALSE otherwise.
145 /*static gboolean irreco_webdb_client_check_error(IrrecoWebdbClient *self)
147 IRRECO_ENTER
148 if(self->error_env->fault_occurred) {
149 IRRECO_ERROR("%d: %s\n", self->error_env->fault_code,
150 self->error_env->fault_string);
151 IRRECO_RETURN_BOOL(TRUE);
153 IRRECO_RETURN_BOOL(FALSE);
157 /**@} */
160 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
161 /* Functions */
162 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
165 * @name Public Functions
166 * @{
170 * Get error message.
172 * @param msg GString object to recieve the error message.
174 void irreco_webdb_client_get_error_msg(IrrecoWebdbClient *self, GString *msg)
176 IRRECO_ENTER
178 /* Clear and set msg */
179 msg = g_string_erase(msg, 0, -1);
180 msg = g_string_insert(msg, 0, self->error_msg->str);
182 IRRECO_RETURN
186 * Ask WebDB to sum two numbers.
188 * @param num_a First number.
189 * @param num_b Second number.
190 * @param sum Variable to receive the result.
191 * @return TRUE on successfull XML-RPC call, FALSE otherwise.
193 gboolean irreco_webdb_client_sum(IrrecoWebdbClient *self,
194 gint num_a,
195 gint num_b,
196 gint *sum)
198 gboolean rvalue = TRUE;
199 SoupXmlrpcMessage *msg;
200 SoupXmlrpcResponse *response;
201 SoupXmlrpcValue *value;
202 IRRECO_ENTER
204 irreco_webdb_client_reset_env(self);
206 msg = soup_xmlrpc_message_new (IRRECO_WEBDB_URL);
207 soup_xmlrpc_message_start_call (msg, "sum");
208 soup_xmlrpc_message_start_param (msg);
209 soup_xmlrpc_message_write_int(msg, num_a);
210 soup_xmlrpc_message_end_param (msg);
211 soup_xmlrpc_message_start_param (msg);
212 soup_xmlrpc_message_write_int(msg, num_b);
213 soup_xmlrpc_message_end_param (msg);
214 soup_xmlrpc_message_end_call (msg);
216 /* Execute XML-RPC call. */
217 response = (SoupXmlrpcResponse*) do_xmlrpc (msg,
218 SOUP_XMLRPC_VALUE_TYPE_INT, self);
219 /* Check response exists */
220 if(!response) {
221 IRRECO_DEBUG(" No response, failed something\n");
222 IRRECO_RETURN_BOOL(FALSE);
225 value = soup_xmlrpc_response_get_value (response);
227 /* Get gint (as glong) out of value */
228 if(!soup_xmlrpc_value_get_int(value, (glong*)sum)){
229 IRRECO_DEBUG("ERROR: Not proper return value\n");
230 g_string_printf(self->error_msg, "ERROR: Not proper return value\n");
231 g_object_unref (response);
232 IRRECO_RETURN_BOOL(FALSE);
235 g_object_unref (response);
237 /* Everything went fine, return TRUE */
238 IRRECO_RETURN_BOOL(rvalue);
241 gboolean irreco_webdb_client_upload_configuration(IrrecoWebdbClient *self,
242 const gchar *backend,
243 const gchar *category,
244 const gchar *file_hash,
245 const gchar *file_name,
246 const gchar *manufacturer,
247 const gchar *model,
248 const gchar *password,
249 const gchar *user,
250 const gchar *data)
252 gboolean rvalue = TRUE;
253 SoupXmlrpcMessage *msg;
254 SoupXmlrpcResponse *response;
255 SoupXmlrpcValue *value;
256 IRRECO_ENTER
258 /* Init msg with URI and other data */
259 msg = soup_xmlrpc_message_new (IRRECO_WEBDB_URL);
260 soup_xmlrpc_message_start_call (msg, "uploadConfiguration");
261 soup_xmlrpc_message_start_param (msg);
262 soup_xmlrpc_message_write_string(msg, backend);
263 soup_xmlrpc_message_end_param (msg);
264 soup_xmlrpc_message_start_param (msg);
265 soup_xmlrpc_message_write_string(msg, category);
266 soup_xmlrpc_message_end_param (msg);
267 soup_xmlrpc_message_start_param (msg);
268 soup_xmlrpc_message_write_string(msg, manufacturer);
269 soup_xmlrpc_message_end_param (msg);
270 soup_xmlrpc_message_start_param (msg);
271 soup_xmlrpc_message_write_string(msg, model);
272 soup_xmlrpc_message_end_param (msg);
273 soup_xmlrpc_message_start_param (msg);
274 soup_xmlrpc_message_write_string(msg, user);
275 soup_xmlrpc_message_end_param (msg);
276 soup_xmlrpc_message_start_param (msg);
277 soup_xmlrpc_message_write_string(msg, password);
278 soup_xmlrpc_message_end_param (msg);
279 soup_xmlrpc_message_start_param (msg);
280 soup_xmlrpc_message_write_string(msg, file_hash);
281 soup_xmlrpc_message_end_param (msg);
282 soup_xmlrpc_message_start_param (msg);
283 soup_xmlrpc_message_write_string(msg, file_name);
284 soup_xmlrpc_message_end_param (msg);
285 soup_xmlrpc_message_start_param (msg);
286 soup_xmlrpc_message_write_string(msg, data);
287 soup_xmlrpc_message_end_param (msg);
288 soup_xmlrpc_message_end_call (msg);
290 irreco_webdb_client_reset_env(self);
292 /* Execute XML-RPC call. */
293 response = (SoupXmlrpcResponse*) do_xmlrpc (msg,
294 SOUP_XMLRPC_VALUE_TYPE_STRING, self);
296 /* Check response exists */
297 if(!response) {
298 IRRECO_DEBUG(" No response, failed something\n");
299 IRRECO_RETURN_BOOL(FALSE);
302 value = soup_xmlrpc_response_get_value (response);
304 g_object_unref (response);
306 /* Everything went fine, return TRUE */
307 IRRECO_RETURN_BOOL(rvalue);
311 gboolean irreco_webdb_client_get_categories(IrrecoWebdbClient *self,
312 IrrecoStringTable **category_list)
314 gboolean rvalue = FALSE;
315 SoupXmlrpcMessage *msg;
316 SoupXmlrpcResponse *response;
317 SoupXmlrpcValueArrayIterator *iter;
318 SoupXmlrpcValue *value;
319 SoupXmlrpcValue *array_val;
320 gchar *ret = NULL;
322 IRRECO_ENTER
324 irreco_webdb_client_reset_env(self);
326 *category_list = irreco_string_table_new(NULL, NULL);
328 irreco_webdb_client_reset_env(self);
330 msg = soup_xmlrpc_message_new (IRRECO_WEBDB_URL);
331 soup_xmlrpc_message_start_call (msg, "getCategories");
332 soup_xmlrpc_message_end_call (msg);
334 response = (SoupXmlrpcResponse*) do_xmlrpc (msg,
335 SOUP_XMLRPC_VALUE_TYPE_ARRAY, self);
336 if(!response) {
337 IRRECO_DEBUG(" No response, failed something\n");
338 IRRECO_RETURN_BOOL(rvalue);
341 value = soup_xmlrpc_response_get_value (response);
343 soup_xmlrpc_value_array_get_iterator(value, &iter);
345 while (iter) {
346 soup_xmlrpc_value_array_iterator_get_value(iter, &array_val);
348 if (!soup_xmlrpc_value_get_string(array_val, &ret)) {
349 IRRECO_DEBUG ("NO value\n");
350 g_object_unref (response);
351 IRRECO_RETURN_BOOL(rvalue);
353 IRRECO_DEBUG("%s\n", ret);
355 irreco_string_table_add(*category_list, ret, NULL);
357 iter = soup_xmlrpc_value_array_iterator_next(iter);
360 rvalue = TRUE;
362 IRRECO_RETURN_BOOL(rvalue);
365 gboolean irreco_webdb_client_get_all_categories(IrrecoWebdbClient *self,
366 IrrecoStringTable **category_list)
368 gboolean rvalue = FALSE;
369 SoupXmlrpcMessage *msg;
370 SoupXmlrpcResponse *response;
371 SoupXmlrpcValueArrayIterator *iter;
372 SoupXmlrpcValue *value;
373 SoupXmlrpcValue *array_val;
374 gchar *ret = NULL;
376 IRRECO_ENTER
378 *category_list = NULL;
379 irreco_webdb_client_reset_env(self);
381 *category_list = NULL;
382 *category_list = irreco_string_table_new(NULL, NULL);
384 irreco_webdb_client_reset_env(self);
386 msg = soup_xmlrpc_message_new (IRRECO_WEBDB_URL);
387 soup_xmlrpc_message_start_call (msg, "getAllCategories");
388 soup_xmlrpc_message_end_call (msg);
390 /** @todo
391 * Upload device dialog also shows category named category
392 * That comes from where and why?
393 * Don't think there should be such
394 * Same thing with manufacturer field
397 response = (SoupXmlrpcResponse*) do_xmlrpc (msg,
398 SOUP_XMLRPC_VALUE_TYPE_ARRAY, self);
399 if(!response) {
400 IRRECO_DEBUG(" No response, failed something\n");
401 IRRECO_RETURN_BOOL(rvalue);
404 value = soup_xmlrpc_response_get_value (response);
406 soup_xmlrpc_value_array_get_iterator(value, &iter);
408 while (iter) {
409 soup_xmlrpc_value_array_iterator_get_value(iter, &array_val);
411 if (!soup_xmlrpc_value_get_string(array_val, &ret)) {
412 IRRECO_DEBUG ("NO value\n");
413 g_object_unref (response);
414 IRRECO_RETURN_BOOL(rvalue);
416 IRRECO_DEBUG("%s\n", ret);
418 irreco_string_table_add(*category_list, ret, NULL);
420 iter = soup_xmlrpc_value_array_iterator_next(iter);
423 rvalue = TRUE;
425 IRRECO_RETURN_BOOL(rvalue);
427 gboolean irreco_webdb_client_get_manufacturers(IrrecoWebdbClient *self,
428 const gchar *category,
429 IrrecoStringTable **manufacturer_list)
431 gboolean rvalue = FALSE;
432 SoupXmlrpcMessage *msg;
433 SoupXmlrpcResponse *response;
434 SoupXmlrpcValueArrayIterator *iter;
435 SoupXmlrpcValue *value;
436 SoupXmlrpcValue *array_val;
437 gchar *ret = NULL;
439 IRRECO_ENTER
441 *manufacturer_list = NULL;
442 irreco_webdb_client_reset_env(self);
444 *manufacturer_list = NULL;
445 *manufacturer_list = irreco_string_table_new(NULL, NULL);
447 irreco_webdb_client_reset_env(self);
449 msg = soup_xmlrpc_message_new (IRRECO_WEBDB_URL);
450 soup_xmlrpc_message_start_call (msg, "getManufacturers");
451 soup_xmlrpc_message_start_param (msg);
452 soup_xmlrpc_message_write_string(msg, category);
453 soup_xmlrpc_message_end_param (msg);
454 soup_xmlrpc_message_end_call (msg);
456 response = (SoupXmlrpcResponse*) do_xmlrpc (msg,
457 SOUP_XMLRPC_VALUE_TYPE_ARRAY, self);
458 if(!response) {
459 IRRECO_DEBUG(" No response, failed something\n");
460 IRRECO_RETURN_BOOL(rvalue);
463 value = soup_xmlrpc_response_get_value (response);
465 soup_xmlrpc_value_array_get_iterator(value, &iter);
467 while (iter) {
468 soup_xmlrpc_value_array_iterator_get_value(iter, &array_val);
470 if (!soup_xmlrpc_value_get_string(array_val, &ret)) {
471 IRRECO_DEBUG ("NO value\n");
472 g_object_unref (response);
473 IRRECO_RETURN_BOOL(rvalue);
475 IRRECO_DEBUG("%s\n", ret);
477 irreco_string_table_add(*manufacturer_list, ret, NULL);
479 iter = soup_xmlrpc_value_array_iterator_next(iter);
482 rvalue = TRUE;
484 IRRECO_RETURN_BOOL(rvalue);
487 gboolean irreco_webdb_client_get_all_manufacturers(IrrecoWebdbClient *self,
488 IrrecoStringTable **manufacturer_list)
490 gboolean rvalue = FALSE;
491 SoupXmlrpcMessage *msg;
492 SoupXmlrpcResponse *response;
493 SoupXmlrpcValueArrayIterator *iter;
494 SoupXmlrpcValue *value;
495 SoupXmlrpcValue *array_val;
496 gchar *ret = NULL;
498 IRRECO_ENTER
500 *manufacturer_list = NULL;
501 irreco_webdb_client_reset_env(self);
503 *manufacturer_list = NULL;
504 *manufacturer_list = irreco_string_table_new(NULL, NULL);
506 irreco_webdb_client_reset_env(self);
508 msg = soup_xmlrpc_message_new (IRRECO_WEBDB_URL);
509 soup_xmlrpc_message_start_call (msg, "getAllManufacturers");
510 soup_xmlrpc_message_end_call (msg);
512 response = (SoupXmlrpcResponse*) do_xmlrpc (msg,
513 SOUP_XMLRPC_VALUE_TYPE_ARRAY, self);
514 if(!response) {
515 IRRECO_DEBUG(" No response, failed something\n");
516 IRRECO_RETURN_BOOL(rvalue);
519 value = soup_xmlrpc_response_get_value (response);
521 soup_xmlrpc_value_array_get_iterator(value, &iter);
523 while (iter) {
524 soup_xmlrpc_value_array_iterator_get_value(iter, &array_val);
526 if (!soup_xmlrpc_value_get_string(array_val, &ret)) {
527 IRRECO_DEBUG ("No value\n");
528 g_object_unref (response);
529 IRRECO_RETURN_BOOL(rvalue);
531 IRRECO_DEBUG("%s\n", ret);
533 irreco_string_table_add(*manufacturer_list, ret, NULL);
535 iter = soup_xmlrpc_value_array_iterator_next(iter);
538 rvalue = TRUE;
540 IRRECO_RETURN_BOOL(rvalue);
543 gboolean irreco_webdb_client_get_models(IrrecoWebdbClient *self,
544 const gchar *category,
545 const gchar *manufacturer,
546 IrrecoStringTable **model_list)
548 gboolean rvalue = FALSE;
549 SoupXmlrpcMessage *msg;
550 SoupXmlrpcResponse *response;
551 SoupXmlrpcValueArrayIterator *iter;
552 SoupXmlrpcValue *value;
553 SoupXmlrpcValue *array_val;
554 gchar *ret = NULL;
556 IRRECO_ENTER
558 *model_list = NULL;
559 irreco_webdb_client_reset_env(self);
561 *model_list = NULL;
562 *model_list = irreco_string_table_new(NULL, NULL);
564 irreco_webdb_client_reset_env(self);
566 msg = soup_xmlrpc_message_new (IRRECO_WEBDB_URL);
567 soup_xmlrpc_message_start_call (msg, "getModels");
568 soup_xmlrpc_message_start_param (msg);
569 soup_xmlrpc_message_write_string(msg, category);
570 soup_xmlrpc_message_end_param (msg);
571 soup_xmlrpc_message_start_param (msg);
572 soup_xmlrpc_message_write_string(msg, manufacturer);
573 soup_xmlrpc_message_end_param (msg);
574 soup_xmlrpc_message_end_call (msg);
576 response = (SoupXmlrpcResponse*) do_xmlrpc (msg,
577 SOUP_XMLRPC_VALUE_TYPE_ARRAY, self);
578 if(!response) {
579 IRRECO_DEBUG(" No response, failed something\n");
580 IRRECO_RETURN_BOOL(rvalue);
583 value = soup_xmlrpc_response_get_value (response);
585 soup_xmlrpc_value_array_get_iterator(value, &iter);
587 while (iter) {
588 soup_xmlrpc_value_array_iterator_get_value(iter, &array_val);
590 if (!soup_xmlrpc_value_get_string(array_val, &ret)) {
591 IRRECO_DEBUG ("No value\n");
592 g_object_unref (response);
593 IRRECO_RETURN_BOOL(rvalue);
595 IRRECO_DEBUG("%s\n", ret);
597 irreco_string_table_add(*model_list, ret, NULL);
599 iter = soup_xmlrpc_value_array_iterator_next(iter);
602 rvalue = TRUE;
604 IRRECO_RETURN_BOOL(rvalue);
608 gboolean irreco_webdb_client_get_configs(IrrecoWebdbClient *self,
609 const gchar *category,
610 const gchar *manufacturer,
611 const gchar *model,
612 IrrecoStringTable **config_list)
614 gboolean rvalue = FALSE;
615 SoupXmlrpcMessage *msg;
616 SoupXmlrpcResponse *response;
617 SoupXmlrpcValueArrayIterator *iter;
618 SoupXmlrpcValue *value;
619 SoupXmlrpcValue *array_val;
620 gchar *ret = NULL;
622 IRRECO_ENTER
624 *config_list = NULL;
625 *config_list = irreco_string_table_new(NULL, NULL);
627 irreco_webdb_client_reset_env(self);
629 msg = soup_xmlrpc_message_new (IRRECO_WEBDB_URL);
630 soup_xmlrpc_message_start_call (msg, "getConfigurations");
631 soup_xmlrpc_message_start_param (msg);
632 soup_xmlrpc_message_write_string(msg, manufacturer);
633 soup_xmlrpc_message_end_param (msg);
634 soup_xmlrpc_message_start_param (msg);
635 soup_xmlrpc_message_write_string(msg, model);
636 soup_xmlrpc_message_end_param (msg);
637 soup_xmlrpc_message_end_call (msg);
639 response = (SoupXmlrpcResponse*) do_xmlrpc (msg,
640 SOUP_XMLRPC_VALUE_TYPE_ARRAY, self);
641 if(!response) {
642 IRRECO_DEBUG(" No response, failed something\n");
643 IRRECO_RETURN_BOOL(rvalue);
646 value = soup_xmlrpc_response_get_value (response);
648 soup_xmlrpc_value_array_get_iterator(value, &iter);
650 while (iter) {
651 soup_xmlrpc_value_array_iterator_get_value(iter, &array_val);
653 if (!soup_xmlrpc_value_get_string(array_val, &ret)) {
654 IRRECO_DEBUG ("No value\n");
655 g_object_unref (response);
656 IRRECO_RETURN_BOOL(rvalue);
658 IRRECO_DEBUG("Config: %s\n", ret);
660 irreco_string_table_add(*config_list, ret, NULL);
662 iter = soup_xmlrpc_value_array_iterator_next(iter);
665 /* No error occured. */
666 rvalue = TRUE;
668 IRRECO_RETURN_BOOL(rvalue);
672 gboolean irreco_webdb_client_get_configuration(IrrecoWebdbClient *self,
673 gint id,
674 IrrecoWebdbConf **configuration)
676 gboolean rvalue = FALSE;
677 const gchar *user = NULL;
678 const gchar *backend;
679 const gchar *category;
680 const gchar *manufacturer;
681 const gchar *model;
682 const gchar *file_hash;
683 const gchar *file_name;
684 const gchar *uploaded;
685 const gchar *download_count;
686 SoupXmlrpcMessage *msg;
687 SoupXmlrpcResponse *response;
688 SoupXmlrpcValue *value;
689 GHashTable *tmp = NULL;
690 gchar *ret = NULL;
691 SoupXmlrpcValue *hash = NULL;
693 IRRECO_ENTER
695 *configuration = irreco_webdb_conf_new();
697 irreco_webdb_client_reset_env(self);
699 /* Build query */
700 msg = soup_xmlrpc_message_new (IRRECO_WEBDB_URL);
701 soup_xmlrpc_message_start_call (msg, "getConfigurationById");
702 soup_xmlrpc_message_start_param (msg);
703 soup_xmlrpc_message_write_int(msg, (long) id);
704 soup_xmlrpc_message_end_param (msg);
705 soup_xmlrpc_message_end_call (msg);
707 /* Execute XML-RPC call. */
708 response = (SoupXmlrpcResponse*) do_xmlrpc (msg,
709 SOUP_XMLRPC_VALUE_TYPE_STRUCT, self);
711 /* Check response */
712 if(!response) {
713 IRRECO_DEBUG(" No response, failed something\n");
714 IRRECO_RETURN_BOOL(rvalue);
717 /* Get array out from response */
718 value = soup_xmlrpc_response_get_value (response);
720 if(!soup_xmlrpc_value_get_struct(value, &tmp)){
721 g_string_printf(self->error_msg,
722 "ERROR: Not proper return value\n");
723 g_object_unref (response);
724 IRRECO_RETURN_BOOL(FALSE);
727 /* Seek data */
728 hash = g_hash_table_lookup (tmp, "user");
729 if (!soup_xmlrpc_value_get_string(hash, &ret)) {
730 IRRECO_DEBUG("No value in response\n");
731 g_hash_table_destroy (tmp);
732 g_object_unref (response);
733 IRRECO_RETURN_BOOL(FALSE);
735 user = ret;
737 hash = g_hash_table_lookup (tmp, "backend");
738 if (!soup_xmlrpc_value_get_string(hash, &ret)) {
739 IRRECO_DEBUG ("No value in response\n");
740 g_hash_table_destroy (tmp);
741 g_object_unref (response);
742 IRRECO_RETURN_BOOL(FALSE);
744 backend = ret;
746 hash = g_hash_table_lookup (tmp, "category");
747 if (!soup_xmlrpc_value_get_string(hash, &ret)) {
748 IRRECO_DEBUG ("No value in response\n");
749 g_hash_table_destroy (tmp);
750 g_object_unref (response);
751 IRRECO_RETURN_BOOL(FALSE);
753 category = ret;
755 hash = g_hash_table_lookup (tmp, "manufacturer");
756 if (!soup_xmlrpc_value_get_string(hash, &ret)) {
757 IRRECO_DEBUG ("No value in response\n");
758 g_hash_table_destroy (tmp);
759 g_object_unref (response);
760 IRRECO_RETURN_BOOL(FALSE);
762 manufacturer = ret;
764 hash = g_hash_table_lookup (tmp, "model");
765 if (!soup_xmlrpc_value_get_string(hash, &ret)) {
766 IRRECO_DEBUG ("No value in response\n");
767 g_hash_table_destroy (tmp);
768 g_object_unref (response);
769 IRRECO_RETURN_BOOL(FALSE);
771 model = ret;
773 hash = g_hash_table_lookup (tmp, "file_hash");
774 if (!soup_xmlrpc_value_get_string(hash, &ret)) {
775 IRRECO_DEBUG ("No value in response\n");
776 g_hash_table_destroy (tmp);
777 g_object_unref (response);
778 IRRECO_RETURN_BOOL(FALSE);
780 file_hash = ret;
782 hash = g_hash_table_lookup (tmp, "file_name");
783 if (!soup_xmlrpc_value_get_string(hash, &ret)) {
784 IRRECO_DEBUG ("No value in response\n");
785 g_hash_table_destroy (tmp);
786 g_object_unref (response);
787 IRRECO_RETURN_BOOL(FALSE);
789 file_name = ret;
791 hash = g_hash_table_lookup (tmp, "uploaded");
792 if (!soup_xmlrpc_value_get_string(hash, &ret)) {
793 IRRECO_DEBUG ("No value in response\n");
794 g_hash_table_destroy (tmp);
795 g_object_unref (response);
796 IRRECO_RETURN_BOOL(FALSE);
798 uploaded = ret;
800 hash = g_hash_table_lookup (tmp, "download_count");
801 if (!soup_xmlrpc_value_get_string(hash, &ret)) {
802 IRRECO_DEBUG ("No value in response\n");
803 g_hash_table_destroy (tmp);
804 g_object_unref (response);
805 IRRECO_RETURN_BOOL(FALSE);
807 download_count = ret;
809 IRRECO_DEBUG("Configuration: %d %s %s %s %s %s %s %s %s %s\n",
810 id, user, backend, category, manufacturer,
811 model, file_hash, file_name, uploaded, download_count);
813 irreco_webdb_conf_set(*configuration, id, user, backend, category,
814 manufacturer, model, file_hash, file_name,
815 uploaded, download_count);
817 /* No error occured. */
818 rvalue = TRUE;
820 IRRECO_RETURN_BOOL(rvalue);
823 gint irreco_webdb_client_get_config_id_by_file_hash_and_file_name(
824 IrrecoWebdbClient *self,
825 const gchar *file_hash,
826 const gchar *file_name)
828 SoupXmlrpcMessage *msg;
829 SoupXmlrpcResponse *response;
830 SoupXmlrpcValue *value;
831 glong id = 0;
833 IRRECO_ENTER
835 msg = soup_xmlrpc_message_new(IRRECO_WEBDB_URL);
836 soup_xmlrpc_message_start_call(msg, "getConfigIdByFilehashAndFilename");
837 soup_xmlrpc_message_start_param (msg);
838 soup_xmlrpc_message_write_string(msg, file_hash);
839 soup_xmlrpc_message_write_string(msg, file_name);
840 soup_xmlrpc_message_end_param(msg);
841 soup_xmlrpc_message_end_call (msg);
843 irreco_webdb_client_reset_env(self);
845 response = (SoupXmlrpcResponse*)do_xmlrpc(msg,
846 SOUP_XMLRPC_VALUE_TYPE_INT,
847 self);
849 /* Check response exists */
850 if(!response) {
851 IRRECO_DEBUG(" No response, failed at do_xmlrpc\n");
852 goto end;
855 value = soup_xmlrpc_response_get_value(response);
857 /* Try to get integer out of value */
858 if(!soup_xmlrpc_value_get_int(value, &id)) {
859 id = 0;
862 end:
863 g_object_unref (response);
864 IRRECO_RETURN_INT(id);
868 gboolean irreco_webdb_client_get_file(IrrecoWebdbClient *self,
869 const gchar *file_hash,
870 const gchar *file_name,
871 GString **file_data)
873 gboolean rvalue = FALSE;
874 SoupXmlrpcMessage *msg;
875 SoupXmlrpcResponse *response;
876 SoupXmlrpcValue *value;
877 GHashTable *tmp = NULL;
878 gchar *ret = NULL;
879 SoupXmlrpcValue *hash = NULL;
881 IRRECO_ENTER
883 irreco_webdb_client_reset_env(self);
885 IRRECO_LINE
887 /* Build query */
888 msg = soup_xmlrpc_message_new (IRRECO_WEBDB_URL);
889 soup_xmlrpc_message_start_call (msg, "getFile");
890 soup_xmlrpc_message_start_param (msg);
891 soup_xmlrpc_message_write_string(msg, file_hash);
892 soup_xmlrpc_message_end_param (msg);
893 soup_xmlrpc_message_start_param (msg);
894 soup_xmlrpc_message_write_string(msg, file_name);
895 soup_xmlrpc_message_end_param (msg);
896 soup_xmlrpc_message_end_call (msg);
898 /* Execute XML-RPC call. */
899 response = (SoupXmlrpcResponse*) do_xmlrpc (msg,
900 SOUP_XMLRPC_VALUE_TYPE_STRUCT, self);
902 /* Check response */
903 if(!response) {
904 IRRECO_DEBUG(" No response, failed at do_xmlrpc\n");
905 IRRECO_RETURN_BOOL(FALSE);
908 /* Get array out from response */
909 value = soup_xmlrpc_response_get_value (response);
911 /* Get string out from array */
912 if(!soup_xmlrpc_value_get_struct(value, &tmp)){
913 g_string_printf(self->error_msg,
914 "ERROR: Not proper return value\n");
915 g_object_unref (response);
916 IRRECO_RETURN_BOOL(FALSE);
919 /* Seek data */
920 hash = g_hash_table_lookup (tmp, "data");
922 if (!soup_xmlrpc_value_get_string(hash, &ret)) {
923 IRRECO_DEBUG ("No value in response\n");
924 g_hash_table_destroy (tmp);
925 g_object_unref (response);
926 IRRECO_RETURN_BOOL(FALSE);
929 IRRECO_DEBUG("File data:\n%s\n",ret);
931 *file_data = g_string_new(ret);
933 g_hash_table_destroy (tmp);
934 g_object_unref (response);
936 rvalue = TRUE;
938 IRRECO_RETURN_BOOL(rvalue);
942 gboolean irreco_webdb_client_get_user_exists(IrrecoWebdbClient *self,
943 const gchar *name,
944 gboolean *user_exists)
946 SoupXmlrpcMessage *msg;
947 SoupXmlrpcResponse *response;
948 SoupXmlrpcValue *value;
950 IRRECO_ENTER
952 msg = soup_xmlrpc_message_new (IRRECO_WEBDB_URL);
953 soup_xmlrpc_message_start_call (msg, "getUserExists");
954 soup_xmlrpc_message_start_param (msg);
955 soup_xmlrpc_message_write_string(msg, name);
956 soup_xmlrpc_message_end_param (msg);
957 soup_xmlrpc_message_end_call (msg);
959 irreco_webdb_client_reset_env(self);
961 response = (SoupXmlrpcResponse*) do_xmlrpc (msg,
962 SOUP_XMLRPC_VALUE_TYPE_BOOLEAN, self);
964 /* Check response exists */
965 if(!response) {
966 IRRECO_DEBUG(" No response, failed at do_xmlrpc\n");
967 IRRECO_RETURN_BOOL(FALSE);
970 value = soup_xmlrpc_response_get_value (response);
972 /* Try to get gboolean out of value */
973 if(!soup_xmlrpc_value_get_boolean(value, user_exists)){
974 g_string_printf(self->error_msg,
975 "ERROR: Not proper return value\n");
976 g_object_unref (response);
977 IRRECO_RETURN_BOOL(FALSE);
980 g_object_unref (response);
981 IRRECO_RETURN_BOOL(TRUE);
984 gint irreco_webdb_client_get_max_image_size(IrrecoWebdbClient *self)
986 SoupXmlrpcMessage *msg;
987 SoupXmlrpcResponse *response;
988 SoupXmlrpcValue *value;
989 gint max_image_size = 0;
991 IRRECO_ENTER
993 msg = soup_xmlrpc_message_new (IRRECO_WEBDB_URL);
994 soup_xmlrpc_message_start_call (msg, "getMaxImageSize");
995 soup_xmlrpc_message_start_param (msg);
996 soup_xmlrpc_message_end_param (msg);
997 soup_xmlrpc_message_end_call (msg);
999 irreco_webdb_client_reset_env(self);
1001 response = (SoupXmlrpcResponse*) do_xmlrpc(msg,
1002 SOUP_XMLRPC_VALUE_TYPE_INT,
1003 self);
1005 /* Check response exists */
1006 if(!response) {
1007 IRRECO_DEBUG(" No response, failed at do_xmlrpc\n");
1008 goto end;
1011 value = soup_xmlrpc_response_get_value (response);
1013 /* Try to get integer out of value */
1014 if(!soup_xmlrpc_value_get_int(value, (glong *) &max_image_size)) {
1015 max_image_size = 0;
1018 end:
1019 g_object_unref (response);
1020 IRRECO_RETURN_INT(max_image_size);
1023 gint irreco_webdb_client_create_theme(IrrecoWebdbClient *self,
1024 const gchar *name,
1025 const gchar *comment,
1026 const gchar *preview_button,
1027 const gchar *folder,
1028 const gchar *user,
1029 const gchar *password)
1031 SoupXmlrpcMessage *msg;
1032 SoupXmlrpcResponse *response;
1033 SoupXmlrpcValue *value;
1034 gint theme_id;
1036 IRRECO_ENTER
1037 msg = soup_xmlrpc_message_new (IRRECO_WEBDB_URL);
1038 soup_xmlrpc_message_start_call (msg, "createNewTheme");
1039 soup_xmlrpc_message_start_param (msg);
1040 soup_xmlrpc_message_write_string(msg, name);
1041 soup_xmlrpc_message_write_string(msg, comment);
1042 soup_xmlrpc_message_write_string(msg, preview_button);
1043 soup_xmlrpc_message_write_string(msg, folder);
1044 soup_xmlrpc_message_write_string(msg, user);
1045 soup_xmlrpc_message_write_string(msg, password);
1046 soup_xmlrpc_message_end_param (msg);
1047 soup_xmlrpc_message_end_call (msg);
1049 irreco_webdb_client_reset_env(self);
1051 response = (SoupXmlrpcResponse*) do_xmlrpc (msg,
1052 SOUP_XMLRPC_VALUE_TYPE_INT, self);
1054 /* Check response exists */
1055 if(!response) {
1056 IRRECO_DEBUG(" No response, failed at do_xmlrpc\n");
1057 IRRECO_RETURN_BOOL(FALSE);
1060 value = soup_xmlrpc_response_get_value (response);
1062 /* Try to get integer out of value */
1063 if(soup_xmlrpc_value_get_int(value, (glong *) &theme_id)){
1064 g_object_unref (response);
1065 IRRECO_RETURN_INT(theme_id);
1068 g_string_printf(self->error_msg,
1069 "ERROR: Not proper return value\n");
1070 g_object_unref (response);
1071 IRRECO_RETURN_INT(0);
1074 gboolean irreco_webdb_client_set_theme_downloadable(IrrecoWebdbClient *self,
1075 gint id,
1076 gboolean downloadable,
1077 const gchar *user,
1078 const gchar *password)
1080 SoupXmlrpcMessage *msg;
1081 SoupXmlrpcResponse *response;
1082 SoupXmlrpcValue *value;
1083 gboolean rvalue = FALSE;
1085 IRRECO_ENTER
1086 msg = soup_xmlrpc_message_new (IRRECO_WEBDB_URL);
1087 soup_xmlrpc_message_start_call (msg, "setThemeDownloadable");
1088 soup_xmlrpc_message_start_param (msg);
1089 soup_xmlrpc_message_write_int(msg, id);
1090 soup_xmlrpc_message_write_boolean(msg, downloadable);
1091 soup_xmlrpc_message_write_string(msg, user);
1092 soup_xmlrpc_message_write_string(msg, password);
1093 soup_xmlrpc_message_end_param (msg);
1094 soup_xmlrpc_message_end_call (msg);
1096 irreco_webdb_client_reset_env(self);
1098 response = (SoupXmlrpcResponse*) do_xmlrpc (msg,
1099 SOUP_XMLRPC_VALUE_TYPE_BOOLEAN, self);
1101 /* Check response exists */
1102 if(!response) {
1103 IRRECO_DEBUG(" No response, failed at do_xmlrpc\n");
1104 IRRECO_RETURN_BOOL(FALSE);
1107 value = soup_xmlrpc_response_get_value (response);
1109 /* Try to get boolean out of value */
1110 soup_xmlrpc_value_get_boolean(value, &rvalue);
1112 g_object_unref (response);
1113 IRRECO_RETURN_BOOL(rvalue);
1116 gboolean irreco_webdb_client_get_themes(IrrecoWebdbClient *self,
1117 IrrecoStringTable **theme_list)
1119 gboolean rvalue = FALSE;
1120 SoupXmlrpcMessage *msg;
1121 SoupXmlrpcResponse *response;
1122 SoupXmlrpcValueArrayIterator *iter;
1123 SoupXmlrpcValue *value;
1124 SoupXmlrpcValue *array_val;
1125 gchar *ret = NULL;
1126 IRRECO_ENTER
1128 irreco_webdb_client_reset_env(self);
1130 *theme_list = irreco_string_table_new(NULL, NULL);
1132 irreco_webdb_client_reset_env(self);
1134 msg = soup_xmlrpc_message_new (IRRECO_WEBDB_URL);
1135 soup_xmlrpc_message_start_call (msg, "getThemes");
1136 soup_xmlrpc_message_end_call (msg);
1138 response = (SoupXmlrpcResponse*) do_xmlrpc (msg,
1139 SOUP_XMLRPC_VALUE_TYPE_ARRAY, self);
1140 if(!response) {
1141 IRRECO_DEBUG(" No response, failed something\n");
1142 IRRECO_RETURN_BOOL(rvalue);
1145 value = soup_xmlrpc_response_get_value (response);
1147 soup_xmlrpc_value_array_get_iterator(value, &iter);
1149 while (iter) {
1150 soup_xmlrpc_value_array_iterator_get_value(iter, &array_val);
1152 if (!soup_xmlrpc_value_get_string(array_val, &ret)) {
1153 IRRECO_DEBUG ("NO value\n");
1154 g_object_unref (response);
1155 IRRECO_RETURN_BOOL(rvalue);
1157 IRRECO_DEBUG("%s\n", ret);
1159 irreco_string_table_add(*theme_list, ret, NULL);
1161 iter = soup_xmlrpc_value_array_iterator_next(iter);
1164 rvalue = TRUE;
1166 IRRECO_RETURN_BOOL(rvalue);
1169 gboolean irreco_webdb_client_get_theme_by_id(IrrecoWebdbClient *self,
1170 gint theme_id,
1171 IrrecoWebdbTheme **theme)
1173 gboolean rvalue = FALSE;
1174 gchar *name = NULL;
1175 gchar *user = NULL;
1176 gchar *comment = NULL;
1177 gchar *preview_button = NULL;
1178 gchar *folder = NULL;
1179 gchar *uploaded = NULL;
1180 gchar *modified = NULL;
1181 gchar *downloaded = NULL;
1182 gint download_count;
1183 GHashTable *tmp = NULL;
1184 SoupXmlrpcValue *hash = NULL;
1185 SoupXmlrpcMessage *msg;
1186 SoupXmlrpcResponse *response = NULL;
1187 SoupXmlrpcValue *value;
1188 IRRECO_ENTER
1190 irreco_webdb_client_reset_env(self);
1192 /* Build query */
1193 msg = soup_xmlrpc_message_new (IRRECO_WEBDB_URL);
1194 soup_xmlrpc_message_start_call (msg, "getThemeById");
1195 soup_xmlrpc_message_start_param (msg);
1196 soup_xmlrpc_message_write_int(msg, (glong) theme_id);
1197 soup_xmlrpc_message_end_param (msg);
1198 soup_xmlrpc_message_end_call (msg);
1200 /* Execute XML-RPC call. */
1201 response = (SoupXmlrpcResponse*) do_xmlrpc (msg,
1202 SOUP_XMLRPC_VALUE_TYPE_STRUCT, self);
1204 /* Check response */
1205 if(!response) {
1206 IRRECO_DEBUG(" No response, failed something\n");
1207 goto end;
1210 /* Get array out from response */
1211 value = soup_xmlrpc_response_get_value (response);
1213 if(!soup_xmlrpc_value_get_struct(value, &tmp)){
1214 g_string_printf(self->error_msg,
1215 "ERROR: Not proper return value\n");
1216 goto end;
1219 /* Seek data */
1220 hash = g_hash_table_lookup(tmp, "name");
1221 if (!soup_xmlrpc_value_get_string(hash, &name)) {
1222 IRRECO_DEBUG("No value in response\n");
1223 goto end;
1226 hash = g_hash_table_lookup(tmp, "user");
1227 if (!soup_xmlrpc_value_get_string(hash, &user)) {
1228 IRRECO_DEBUG("No value in response\n");
1229 goto end;
1232 hash = g_hash_table_lookup(tmp, "comment");
1233 if (!soup_xmlrpc_value_get_string(hash, &comment)) {
1234 IRRECO_DEBUG("No value in response\n");
1235 goto end;
1238 hash = g_hash_table_lookup(tmp, "preview_button");
1239 if (!soup_xmlrpc_value_get_string(hash, &preview_button)) {
1240 IRRECO_DEBUG("No value in response\n");
1241 goto end;
1244 hash = g_hash_table_lookup(tmp, "folder");
1245 if (!soup_xmlrpc_value_get_string(hash, &folder)) {
1246 IRRECO_DEBUG("No value in response\n");
1247 goto end;
1250 hash = g_hash_table_lookup(tmp, "uploaded");
1251 if (!soup_xmlrpc_value_get_string(hash, &uploaded)) {
1252 IRRECO_DEBUG("No value in response\n");
1253 goto end;
1256 hash = g_hash_table_lookup(tmp, "modified");
1257 if (!soup_xmlrpc_value_get_string(hash, &modified)) {
1258 IRRECO_DEBUG("No value in response\n");
1259 goto end;
1262 hash = g_hash_table_lookup(tmp, "downloaded");
1263 if (!soup_xmlrpc_value_get_string(hash, &downloaded)) {
1264 IRRECO_DEBUG("No value in response\n");
1265 goto end;
1268 hash = g_hash_table_lookup(tmp, "download_count");
1269 if (!soup_xmlrpc_value_get_int(hash, (glong *) &download_count)) {
1270 IRRECO_DEBUG("No value in response\n");
1271 goto end;
1274 *theme = irreco_webdb_theme_new();
1276 irreco_webdb_theme_set(*theme, theme_id, name, user, comment,
1277 preview_button, NULL, folder, uploaded, modified,
1278 downloaded, download_count);
1280 irreco_webdb_client_get_theme_versions_by_name(self, name,
1281 &(*theme)->versions);
1283 /* Get dates for versions */
1284 if ((*theme)->versions != NULL)
1286 IRRECO_STRING_TABLE_FOREACH_KEY((*theme)->versions, key)
1287 gchar *date = irreco_webdb_client_get_theme_date_by_id(
1288 self, atoi(key));
1290 irreco_string_table_change_data ((*theme)->versions,
1291 key, (gpointer) date);
1292 IRRECO_STRING_TABLE_FOREACH_END
1295 /* No error occured. */
1296 rvalue = TRUE;
1298 end:
1299 if (response != NULL) g_object_unref(response);
1300 if (tmp != NULL) g_hash_table_destroy(tmp);
1301 if (name != NULL) g_free(name);
1302 if (user != NULL) g_free(user);
1303 if (comment != NULL) g_free(comment);
1304 if (preview_button != NULL) g_free(preview_button);
1305 if (folder != NULL) g_free(folder);
1306 if (uploaded != NULL) g_free(uploaded);
1307 if (modified != NULL) g_free(modified);
1308 if (downloaded != NULL) g_free(downloaded);
1310 IRRECO_RETURN_BOOL(rvalue);
1313 gboolean irreco_webdb_client_get_theme_versions_by_name(IrrecoWebdbClient *self,
1314 const char *name,
1315 IrrecoStringTable **theme_list)
1317 gboolean rvalue = FALSE;
1318 SoupXmlrpcMessage *msg;
1319 SoupXmlrpcResponse *response;
1320 SoupXmlrpcValueArrayIterator *iter;
1321 SoupXmlrpcValue *value;
1322 SoupXmlrpcValue *array_val;
1323 gchar *ret = NULL;
1324 IRRECO_ENTER
1326 irreco_webdb_client_reset_env(self);
1328 *theme_list = irreco_string_table_new(NULL, NULL);
1330 irreco_webdb_client_reset_env(self);
1332 msg = soup_xmlrpc_message_new (IRRECO_WEBDB_URL);
1333 soup_xmlrpc_message_start_call (msg, "getThemeVersionsByName");
1334 soup_xmlrpc_message_start_param (msg);
1335 soup_xmlrpc_message_write_string(msg, name);
1336 soup_xmlrpc_message_end_param (msg);
1337 soup_xmlrpc_message_end_call (msg);
1339 response = (SoupXmlrpcResponse*) do_xmlrpc (msg,
1340 SOUP_XMLRPC_VALUE_TYPE_ARRAY, self);
1341 if(!response) {
1342 IRRECO_DEBUG(" No response, failed something\n");
1343 goto end;
1346 value = soup_xmlrpc_response_get_value (response);
1348 soup_xmlrpc_value_array_get_iterator(value, &iter);
1350 while (iter) {
1351 soup_xmlrpc_value_array_iterator_get_value(iter, &array_val);
1353 if (!soup_xmlrpc_value_get_string(array_val, &ret)) {
1354 IRRECO_DEBUG ("NO value\n");
1355 goto end;
1357 IRRECO_DEBUG("%s\n", ret);
1359 irreco_string_table_add(*theme_list, ret, NULL);
1361 iter = soup_xmlrpc_value_array_iterator_next(iter);
1364 rvalue = TRUE;
1366 end:
1367 if (rvalue == FALSE) irreco_string_table_free(*theme_list);
1368 g_object_unref (response);
1370 IRRECO_RETURN_BOOL(rvalue);
1373 gchar *irreco_webdb_client_get_theme_date_by_id(IrrecoWebdbClient *self,
1374 gint theme_id)
1376 SoupXmlrpcMessage *msg;
1377 SoupXmlrpcResponse *response;
1378 SoupXmlrpcValue *value;
1379 gchar *date = NULL;
1381 IRRECO_ENTER
1383 msg = soup_xmlrpc_message_new (IRRECO_WEBDB_URL);
1384 soup_xmlrpc_message_start_call (msg, "getThemeDateById");
1385 soup_xmlrpc_message_start_param (msg);
1386 soup_xmlrpc_message_write_int(msg, theme_id);
1387 soup_xmlrpc_message_end_param (msg);
1388 soup_xmlrpc_message_end_call (msg);
1390 irreco_webdb_client_reset_env(self);
1392 response = (SoupXmlrpcResponse*)do_xmlrpc(msg,
1393 SOUP_XMLRPC_VALUE_TYPE_STRING,
1394 self);
1396 /* Check response exists */
1397 if(!response) {
1398 IRRECO_DEBUG(" No response, failed at do_xmlrpc\n");
1399 goto end;
1402 value = soup_xmlrpc_response_get_value (response);
1404 /* Try to get integer out of value */
1405 if(!soup_xmlrpc_value_get_string(value, &date)) {
1406 date = NULL;
1409 end:
1410 g_object_unref (response);
1411 IRRECO_RETURN_PTR(date);
1414 gint irreco_webdb_client_get_theme_id_by_name_and_date(IrrecoWebdbClient *self,
1415 const gchar *name,
1416 const gchar *date)
1418 SoupXmlrpcMessage *msg;
1419 SoupXmlrpcResponse *response;
1420 SoupXmlrpcValue *value;
1421 gint id = 0;
1423 IRRECO_ENTER
1425 msg = soup_xmlrpc_message_new (IRRECO_WEBDB_URL);
1426 soup_xmlrpc_message_start_call (msg, "getThemeIdByNameAndDate");
1427 soup_xmlrpc_message_start_param (msg);
1428 soup_xmlrpc_message_write_string(msg, name);
1429 soup_xmlrpc_message_write_string(msg, date);
1430 soup_xmlrpc_message_end_param (msg);
1431 soup_xmlrpc_message_end_call (msg);
1433 irreco_webdb_client_reset_env(self);
1435 response = (SoupXmlrpcResponse*)do_xmlrpc(msg,
1436 SOUP_XMLRPC_VALUE_TYPE_INT,
1437 self);
1439 /* Check response exists */
1440 if(!response) {
1441 IRRECO_DEBUG(" No response, failed at do_xmlrpc\n");
1442 goto end;
1445 value = soup_xmlrpc_response_get_value(response);
1447 /* Try to get integer out of value */
1448 if(!soup_xmlrpc_value_get_int(value, (glong *) &id)) {
1449 id = 0;
1452 end:
1453 g_object_unref (response);
1454 IRRECO_RETURN_INT(id);
1457 gint irreco_webdb_client_add_bg_to_theme(IrrecoWebdbClient *self,
1458 const gchar *name,
1459 const gchar *image_hash,
1460 const gchar *image_name,
1461 const guchar *image,
1462 gint image_len,
1463 const gchar *folder,
1464 gint theme_id,
1465 const gchar *user,
1466 const gchar *password)
1468 SoupXmlrpcMessage *msg;
1469 SoupXmlrpcResponse *response;
1470 SoupXmlrpcValue *value;
1471 gint bg_id;
1472 gchar *base64_image;
1473 IRRECO_ENTER
1475 base64_image = g_base64_encode(image, image_len);
1477 msg = soup_xmlrpc_message_new (IRRECO_WEBDB_URL);
1478 soup_xmlrpc_message_start_call (msg, "addBgToTheme");
1479 soup_xmlrpc_message_start_param (msg);
1480 soup_xmlrpc_message_write_string(msg, name);
1481 soup_xmlrpc_message_write_string(msg, image_hash);
1482 soup_xmlrpc_message_write_string(msg, image_name);
1483 soup_xmlrpc_message_write_string(msg, base64_image);
1484 soup_xmlrpc_message_write_string(msg, folder);
1485 soup_xmlrpc_message_write_int(msg, theme_id);
1486 soup_xmlrpc_message_write_string(msg, user);
1487 soup_xmlrpc_message_write_string(msg, password);
1488 soup_xmlrpc_message_end_param (msg);
1489 soup_xmlrpc_message_end_call (msg);
1491 g_free(base64_image);
1493 irreco_webdb_client_reset_env(self);
1495 response = (SoupXmlrpcResponse*) do_xmlrpc (msg,
1496 SOUP_XMLRPC_VALUE_TYPE_INT, self);
1498 /* Check response exists */
1499 if(!response) {
1500 IRRECO_DEBUG(" No response, failed at do_xmlrpc\n");
1501 IRRECO_RETURN_BOOL(FALSE);
1504 value = soup_xmlrpc_response_get_value (response);
1506 /* Try to get integer out of value */
1507 if(soup_xmlrpc_value_get_int(value, (glong *) &bg_id)){
1508 g_object_unref (response);
1509 IRRECO_RETURN_INT(bg_id);
1512 g_string_printf(self->error_msg,
1513 "ERROR: Not proper return value\n");
1514 g_object_unref (response);
1515 IRRECO_RETURN_INT(0);
1518 gboolean irreco_webdb_client_get_backgrounds(IrrecoWebdbClient *self,
1519 gint theme_id,
1520 IrrecoStringTable **bg_list)
1522 gboolean rvalue = FALSE;
1523 SoupXmlrpcMessage *msg;
1524 SoupXmlrpcResponse *response;
1525 SoupXmlrpcValueArrayIterator *iter;
1526 SoupXmlrpcValue *value;
1527 SoupXmlrpcValue *array_val;
1528 gint ret;
1529 IRRECO_ENTER
1531 irreco_webdb_client_reset_env(self);
1533 *bg_list = irreco_string_table_new(NULL, NULL);
1535 irreco_webdb_client_reset_env(self);
1537 msg = soup_xmlrpc_message_new (IRRECO_WEBDB_URL);
1538 soup_xmlrpc_message_start_call (msg, "getBackgrounds");
1539 soup_xmlrpc_message_start_param (msg);
1540 soup_xmlrpc_message_write_int(msg, theme_id);
1541 soup_xmlrpc_message_end_param (msg);
1542 soup_xmlrpc_message_end_call (msg);
1544 response = (SoupXmlrpcResponse*) do_xmlrpc (msg,
1545 SOUP_XMLRPC_VALUE_TYPE_ARRAY, self);
1546 if(!response) {
1547 IRRECO_DEBUG(" No response, failed something\n");
1548 IRRECO_RETURN_BOOL(rvalue);
1551 value = soup_xmlrpc_response_get_value (response);
1553 soup_xmlrpc_value_array_get_iterator(value, &iter);
1555 while (iter) {
1556 gchar *id;
1557 soup_xmlrpc_value_array_iterator_get_value(iter, &array_val);
1559 if (!soup_xmlrpc_value_get_int(array_val, (glong *)&ret)) {
1560 IRRECO_DEBUG ("NO value\n");
1561 goto end;
1563 IRRECO_DEBUG("%d\n", ret);
1565 id = g_strdup_printf ("%d", ret);
1567 irreco_string_table_add(*bg_list, id, NULL);
1568 g_free(id);
1570 iter = soup_xmlrpc_value_array_iterator_next(iter);
1573 rvalue = TRUE;
1574 end:
1575 if(rvalue == FALSE) {
1576 irreco_string_table_free (*bg_list);
1577 *bg_list = NULL;
1579 g_object_unref (response);
1581 IRRECO_RETURN_BOOL(rvalue);
1585 gboolean irreco_webdb_client_get_bg_by_id(IrrecoWebdbClient *self,
1586 gint bg_id,
1587 const char *theme_bg_dir)
1589 gboolean rvalue = FALSE;
1590 gchar *name = NULL;
1591 gchar *image_hash = NULL;
1592 gchar *image_name = NULL;
1593 gchar *image_data = NULL;
1594 gchar *base64_image = NULL;
1595 gchar *folder = NULL;
1596 GHashTable *tmp = NULL;
1597 SoupXmlrpcValue *hash = NULL;
1598 SoupXmlrpcMessage *msg;
1599 SoupXmlrpcResponse *response;
1600 SoupXmlrpcValue *value;
1601 GString *keyfile_path = g_string_new(theme_bg_dir);
1602 GString *image_path = g_string_new(theme_bg_dir);
1603 GKeyFile *keyfile = g_key_file_new();
1604 gsize base64_len;
1605 IRRECO_ENTER
1607 irreco_webdb_client_reset_env(self);
1609 /* Build query */
1610 msg = soup_xmlrpc_message_new (IRRECO_WEBDB_URL);
1611 soup_xmlrpc_message_start_call (msg, "getBgById");
1612 soup_xmlrpc_message_start_param (msg);
1613 soup_xmlrpc_message_write_int(msg, (glong) bg_id);
1614 soup_xmlrpc_message_end_param (msg);
1615 soup_xmlrpc_message_end_call (msg);
1617 /* Execute XML-RPC call. */
1618 response = (SoupXmlrpcResponse*) do_xmlrpc (msg,
1619 SOUP_XMLRPC_VALUE_TYPE_STRUCT, self);
1621 /* Check response */
1622 if(!response) {
1623 IRRECO_DEBUG(" No response, failed something\n");
1624 goto end;
1627 /* Get array out from response */
1628 value = soup_xmlrpc_response_get_value (response);
1630 if(!soup_xmlrpc_value_get_struct(value, &tmp)){
1631 g_string_printf(self->error_msg,
1632 "ERROR: Not proper return value\n");
1633 goto end;
1636 /* Seek data */
1637 hash = g_hash_table_lookup(tmp, "name");
1638 if (!soup_xmlrpc_value_get_string(hash, &name)) {
1639 IRRECO_DEBUG("No value in response\n");
1640 goto end;
1643 hash = g_hash_table_lookup(tmp, "image_hash");
1644 if (!soup_xmlrpc_value_get_string(hash, &image_hash)) {
1645 IRRECO_DEBUG("No value in response\n");
1646 goto end;
1649 hash = g_hash_table_lookup(tmp, "image_name");
1650 if (!soup_xmlrpc_value_get_string(hash, &image_name)) {
1651 IRRECO_DEBUG("No value in response\n");
1652 goto end;
1655 hash = g_hash_table_lookup(tmp, "image_data");
1656 if (!soup_xmlrpc_value_get_string(hash, &base64_image)) {
1657 IRRECO_DEBUG("No value in response\n");
1658 goto end;
1661 hash = g_hash_table_lookup(tmp, "folder");
1662 if (!soup_xmlrpc_value_get_string(hash, &folder)) {
1663 IRRECO_DEBUG("No value in response\n");
1664 goto end;
1667 /* Create Folder */
1668 g_string_append_printf(image_path, "/%s", folder);
1669 IRRECO_DEBUG("mkdir %s\n",image_path->str);
1670 g_mkdir(image_path->str, 0777);
1672 /* Save image to folder */
1673 image_data = (gchar*) g_base64_decode(base64_image, &base64_len);
1674 g_string_append_printf(image_path, "/%s", image_name);
1675 irreco_write_file(image_path->str, image_data, base64_len);
1677 /* Create keyfile and save it to folder*/
1678 irreco_gkeyfile_set_string(keyfile, "theme-bg" , "name", name);
1679 irreco_gkeyfile_set_string(keyfile, "theme-bg", "image", image_name);
1680 g_string_append_printf(keyfile_path, "/%s/bg.conf", folder);
1681 irreco_write_keyfile(keyfile, keyfile_path->str);
1683 /* No error occured. */
1684 rvalue = TRUE;
1686 end:
1687 g_object_unref (response);
1688 if (tmp != NULL) g_hash_table_destroy (tmp);
1689 if (name != NULL) g_free(name);
1690 if (image_hash != NULL) g_free(image_hash);
1691 if (image_name != NULL) g_free(image_name);
1692 if (image_data != NULL) g_free(image_data);
1693 if (base64_image != NULL) g_free(base64_image);
1694 if (folder != NULL) g_free(folder);
1696 g_key_file_free(keyfile);
1697 g_string_free(keyfile_path, TRUE);
1698 g_string_free(image_path, TRUE);
1700 IRRECO_RETURN_BOOL(rvalue);
1703 gint irreco_webdb_client_add_button_to_theme(IrrecoWebdbClient *self,
1704 const gchar *name,
1705 gboolean allow_text,
1706 const gchar *text_format_up,
1707 const gchar *text_format_down,
1708 gint text_padding,
1709 gfloat text_h_align,
1710 gfloat text_v_align,
1711 const gchar *image_up_hash,
1712 const gchar *image_up_name,
1713 const guchar *image_up,
1714 gint image_up_len,
1715 const gchar *image_down_hash,
1716 const gchar *image_down_name,
1717 const guchar *image_down,
1718 gint image_down_len,
1719 const gchar *folder,
1720 gint theme_id,
1721 const gchar *user,
1722 const gchar *password)
1724 SoupXmlrpcMessage *msg;
1725 SoupXmlrpcResponse *response;
1726 SoupXmlrpcValue *value;
1727 gint button_id;
1728 gchar *base64_image_up;
1729 gchar *base64_image_down;
1730 IRRECO_ENTER
1732 base64_image_up = g_base64_encode(image_up, image_up_len);
1733 base64_image_down = g_base64_encode(image_down, image_down_len);
1735 msg = soup_xmlrpc_message_new (IRRECO_WEBDB_URL);
1736 soup_xmlrpc_message_start_call (msg, "addButtonToTheme");
1737 soup_xmlrpc_message_start_param (msg);
1738 soup_xmlrpc_message_write_string(msg, name);
1739 soup_xmlrpc_message_write_boolean(msg, allow_text);
1740 soup_xmlrpc_message_write_string(msg, text_format_up);
1741 soup_xmlrpc_message_write_string(msg, text_format_down);
1742 soup_xmlrpc_message_write_int(msg, text_padding);
1743 soup_xmlrpc_message_write_double(msg, (gdouble)text_h_align);
1744 soup_xmlrpc_message_write_double(msg, (gdouble)text_v_align);
1745 soup_xmlrpc_message_write_string(msg, image_up_hash);
1746 soup_xmlrpc_message_write_string(msg, image_up_name);
1747 soup_xmlrpc_message_write_string(msg, base64_image_up);
1748 soup_xmlrpc_message_write_string(msg, image_down_hash);
1749 soup_xmlrpc_message_write_string(msg, image_down_name);
1750 soup_xmlrpc_message_write_string(msg, base64_image_down);
1751 soup_xmlrpc_message_write_string(msg, folder);
1752 soup_xmlrpc_message_write_int(msg, theme_id);
1753 soup_xmlrpc_message_write_string(msg, user);
1754 soup_xmlrpc_message_write_string(msg, password);
1755 soup_xmlrpc_message_end_param (msg);
1756 soup_xmlrpc_message_end_call (msg);
1758 g_free(base64_image_up);
1759 g_free(base64_image_down);
1761 irreco_webdb_client_reset_env(self);
1763 response = (SoupXmlrpcResponse*) do_xmlrpc (msg,
1764 SOUP_XMLRPC_VALUE_TYPE_INT, self);
1766 /* Check response exists */
1767 if(!response) {
1768 IRRECO_DEBUG(" No response, failed at do_xmlrpc\n");
1769 IRRECO_RETURN_BOOL(FALSE);
1772 value = soup_xmlrpc_response_get_value (response);
1774 /* Try to get integer out of value */
1775 if(soup_xmlrpc_value_get_int(value, (glong *) &button_id)){
1776 g_object_unref (response);
1777 IRRECO_RETURN_INT(button_id);
1780 g_string_printf(self->error_msg,
1781 "ERROR: Not proper return value\n");
1782 g_object_unref (response);
1783 IRRECO_RETURN_INT(0);
1786 gboolean irreco_webdb_client_get_buttons(IrrecoWebdbClient *self,
1787 gint theme_id,
1788 IrrecoStringTable **button_list)
1790 gboolean rvalue = FALSE;
1791 SoupXmlrpcMessage *msg;
1792 SoupXmlrpcResponse *response;
1793 SoupXmlrpcValueArrayIterator *iter;
1794 SoupXmlrpcValue *value;
1795 SoupXmlrpcValue *array_val;
1796 gint ret;
1797 IRRECO_ENTER
1799 irreco_webdb_client_reset_env(self);
1801 *button_list = irreco_string_table_new(NULL, NULL);
1803 irreco_webdb_client_reset_env(self);
1805 msg = soup_xmlrpc_message_new (IRRECO_WEBDB_URL);
1806 soup_xmlrpc_message_start_call (msg, "getButtons");
1807 soup_xmlrpc_message_start_param (msg);
1808 soup_xmlrpc_message_write_int(msg, theme_id);
1809 soup_xmlrpc_message_end_param (msg);
1810 soup_xmlrpc_message_end_call (msg);
1812 response = (SoupXmlrpcResponse*) do_xmlrpc (msg,
1813 SOUP_XMLRPC_VALUE_TYPE_ARRAY, self);
1814 if(!response) {
1815 IRRECO_DEBUG(" No response, failed something\n");
1816 IRRECO_RETURN_BOOL(rvalue);
1819 value = soup_xmlrpc_response_get_value (response);
1821 soup_xmlrpc_value_array_get_iterator(value, &iter);
1823 while (iter) {
1824 gchar *id;
1825 soup_xmlrpc_value_array_iterator_get_value(iter, &array_val);
1827 if (!soup_xmlrpc_value_get_int(array_val, (glong *) &ret)) {
1828 IRRECO_DEBUG ("NO value\n");
1829 goto end;
1831 IRRECO_DEBUG("%d\n", ret);
1833 id = g_strdup_printf("%d", ret);
1834 irreco_string_table_add(*button_list, id, NULL);
1835 g_free(id);
1837 iter = soup_xmlrpc_value_array_iterator_next(iter);
1840 rvalue = TRUE;
1841 end:
1842 if(rvalue == FALSE) {
1843 irreco_string_table_free (*button_list);
1844 *button_list = NULL;
1846 g_object_unref (response);
1848 IRRECO_RETURN_BOOL(rvalue);
1852 gboolean irreco_webdb_client_get_button_by_id(IrrecoWebdbClient *self,
1853 gint button_id,
1854 const char *theme_button_dir)
1856 gboolean rvalue = FALSE;
1857 gchar *name = NULL;
1858 gboolean allow_text = FALSE;
1859 gchar *text_format_up = NULL;
1860 gchar *text_format_down = NULL;
1861 gint text_padding;
1862 gdouble text_h_align;
1863 gdouble text_v_align;
1864 gchar *image_up_hash = NULL;
1865 gchar *image_up_name = NULL;
1866 gchar *image_up = NULL;
1867 gchar *base64_image_up = NULL;
1868 gchar *image_down_hash = NULL;
1869 gchar *image_down_name = NULL;
1870 gchar *image_down = NULL;
1871 gchar *base64_image_down = NULL;
1872 gchar *folder = NULL;
1873 gchar *image_down_hash_tmp = NULL;
1874 GHashTable *tmp = NULL;
1875 SoupXmlrpcValue *hash = NULL;
1876 SoupXmlrpcMessage *msg;
1877 SoupXmlrpcResponse *response;
1878 SoupXmlrpcValue *value;
1879 GString *file_path = g_string_new("");
1880 GKeyFile *keyfile = g_key_file_new();
1881 gsize image_down_len;
1882 gsize image_up_len;
1883 IRRECO_ENTER
1885 irreco_webdb_client_reset_env(self);
1887 /* Build query */
1888 msg = soup_xmlrpc_message_new (IRRECO_WEBDB_URL);
1889 soup_xmlrpc_message_start_call (msg, "getButtonById");
1890 soup_xmlrpc_message_start_param (msg);
1891 soup_xmlrpc_message_write_int(msg, (glong) button_id);
1892 soup_xmlrpc_message_end_param (msg);
1893 soup_xmlrpc_message_end_call (msg);
1895 /* Execute XML-RPC call. */
1896 response = (SoupXmlrpcResponse*) do_xmlrpc (msg,
1897 SOUP_XMLRPC_VALUE_TYPE_STRUCT, self);
1899 /* Check response */
1900 if(!response) {
1901 IRRECO_DEBUG(" No response, failed something\n");
1902 goto end;
1905 /* Get array out from response */
1906 value = soup_xmlrpc_response_get_value (response);
1908 if(!soup_xmlrpc_value_get_struct(value, &tmp)){
1909 g_string_printf(self->error_msg,
1910 "ERROR: Not proper return value\n");
1911 goto end;
1914 /* Seek data */
1915 hash = g_hash_table_lookup(tmp, "name");
1916 if (!soup_xmlrpc_value_get_string(hash, &name)) {
1917 IRRECO_DEBUG("No value in response\n");
1918 goto end;
1921 hash = g_hash_table_lookup(tmp, "allow_text");
1922 if (!soup_xmlrpc_value_get_boolean(hash, &allow_text)) {
1923 IRRECO_DEBUG("No value in response\n");
1924 goto end;
1927 hash = g_hash_table_lookup(tmp, "text_format_up");
1928 soup_xmlrpc_value_get_string(hash, &text_format_up);
1930 hash = g_hash_table_lookup(tmp, "text_format_down");
1931 soup_xmlrpc_value_get_string(hash, &text_format_down);
1933 hash = g_hash_table_lookup(tmp, "text_padding");
1934 if (!soup_xmlrpc_value_get_int(hash, (glong *) &text_padding)) {
1935 IRRECO_DEBUG("No value in response\n");
1936 goto end;
1939 hash = g_hash_table_lookup(tmp, "text_h_align");
1940 if (!soup_xmlrpc_value_get_double(hash, &text_h_align)) {
1941 IRRECO_DEBUG("No value in response\n");
1942 goto end;
1944 hash = g_hash_table_lookup(tmp, "text_v_align");
1945 if (!soup_xmlrpc_value_get_double(hash, &text_v_align)) {
1946 IRRECO_DEBUG("No value in response\n");
1947 goto end;
1950 hash = g_hash_table_lookup(tmp, "image_up_hash");
1951 if (!soup_xmlrpc_value_get_string(hash, &image_up_hash)) {
1952 IRRECO_DEBUG("No value in response\n");
1953 goto end;
1956 hash = g_hash_table_lookup(tmp, "image_up_name");
1957 if (!soup_xmlrpc_value_get_string(hash, &image_up_name)) {
1958 IRRECO_DEBUG("No value in response\n");
1959 goto end;
1962 hash = g_hash_table_lookup(tmp, "image_up");
1963 if (!soup_xmlrpc_value_get_string(hash, &base64_image_up)) {
1964 IRRECO_DEBUG("No value in response\n");
1965 goto end;
1968 hash = g_hash_table_lookup(tmp, "image_down_hash");
1969 if (!soup_xmlrpc_value_get_string(hash, &image_down_hash)) {
1970 IRRECO_DEBUG("No value in response\n");
1971 goto end;
1974 hash = g_hash_table_lookup(tmp, "image_down_name");
1975 if (!soup_xmlrpc_value_get_string(hash, &image_down_name)) {
1976 IRRECO_DEBUG("No value in response\n");
1977 IRRECO_LINE
1978 goto end;
1981 hash = g_hash_table_lookup(tmp, "image_down");
1982 if (!soup_xmlrpc_value_get_string(hash, &base64_image_down)) {
1983 IRRECO_DEBUG("No value in response\n");
1984 goto end;
1987 hash = g_hash_table_lookup(tmp, "folder");
1988 if (!soup_xmlrpc_value_get_string(hash, &folder)) {
1989 IRRECO_DEBUG("No value in response\n");
1990 goto end;
1993 /* Create Folder */
1994 g_string_printf(file_path, "%s/%s", theme_button_dir, folder);
1995 IRRECO_DEBUG("mkdir %s\n",file_path->str);
1996 g_mkdir(file_path->str, 0777);
1998 /* Save image_up to folder */
1999 g_string_printf(file_path, "%s/%s/%s", theme_button_dir, folder,
2000 image_up_name);
2001 image_up = (gchar*) g_base64_decode(base64_image_up, &image_up_len);
2002 irreco_write_file(file_path->str, image_up, image_up_len);
2004 /* Save image_down to folder */
2005 g_string_printf(file_path, "%s/%s/%s", theme_button_dir, folder,
2006 image_down_name);
2008 /*Check image hash data*/
2009 image_down = (gchar*) g_base64_decode(base64_image_down,
2010 &image_down_len);
2011 irreco_write_file(file_path->str, image_down, image_down_len);
2012 image_down_hash_tmp = sha_compute_checksum_for_string(G_CHECKSUM_SHA1,
2013 image_down,
2014 image_down_len);
2016 if (!g_str_equal(image_down_hash, image_down_hash_tmp)) {
2018 g_string_printf(self->error_msg,
2019 "ERROR: Button data is corrupted\n");
2020 goto end;
2023 /* Create keyfile and save it to folder*/
2024 irreco_gkeyfile_set_string(keyfile, "theme-button" , "name", name);
2026 if (allow_text) {
2027 irreco_gkeyfile_set_string(keyfile, "theme-button",
2028 "allow-text", "true");
2029 } else {
2030 irreco_gkeyfile_set_string(keyfile, "theme-button",
2031 "allow-text", "false");
2034 irreco_gkeyfile_set_string(keyfile, "theme-button",
2035 "up", image_up_name);
2037 irreco_gkeyfile_set_string(keyfile, "theme-button",
2038 "down", image_down_name);
2040 if (text_format_up != NULL && strlen(text_format_up) > 0) {
2041 irreco_gkeyfile_set_string(keyfile, "theme-button",
2042 "text-format-up", text_format_up);
2045 if (text_format_down != NULL && strlen(text_format_down) > 0) {
2046 irreco_gkeyfile_set_string(keyfile, "theme-button",
2047 "text-format-down", text_format_down);
2050 irreco_gkeyfile_set_glong(keyfile, "theme-button",
2051 "text-padding", (glong)text_padding);
2053 irreco_gkeyfile_set_gfloat(keyfile,
2054 "theme-button",
2055 "text-h-align",
2056 (gfloat) text_h_align);
2058 irreco_gkeyfile_set_gfloat(keyfile,
2059 "theme-button",
2060 "text-v-align",
2061 (gfloat) text_v_align);
2063 g_string_printf(file_path, "%s/%s/button.conf",
2064 theme_button_dir, folder);
2065 irreco_write_keyfile(keyfile, file_path->str);
2067 /* No error occured. */
2068 rvalue = TRUE;
2070 end:
2072 g_object_unref (response);
2073 if (tmp != NULL) g_hash_table_destroy (tmp);
2074 if (name != NULL) g_free(name);
2075 if (text_format_up != NULL) g_free(text_format_up);
2076 if (text_format_down != NULL) g_free(text_format_down);
2077 if (image_up_hash != NULL) g_free(image_up_hash);
2078 if (image_up_name != NULL) g_free(image_up_name);
2079 if (image_up != NULL) g_free(image_up);
2080 if (base64_image_up != NULL) g_free(base64_image_up);
2081 if (image_down_hash != NULL) g_free(image_down_hash);
2082 if (image_down_name != NULL) g_free(image_down_name);
2083 if (image_down != NULL) g_free(image_down);
2084 if (image_down_hash_tmp != NULL) g_free(image_down_hash_tmp);
2085 if (base64_image_down != NULL) g_free(base64_image_down);
2086 if (folder != NULL) g_free(folder);
2088 g_key_file_free(keyfile);
2089 g_string_free(file_path, TRUE);
2091 IRRECO_RETURN_BOOL(rvalue);
2094 gboolean irreco_webdb_client_get_preview_button(IrrecoWebdbClient *self,
2095 gint theme_id,
2096 GdkPixbuf **preview_button)
2098 gboolean rvalue = FALSE;
2099 SoupXmlrpcMessage *msg;
2100 SoupXmlrpcResponse *response;
2101 SoupXmlrpcValue *value;
2102 char *base64_data = NULL;
2103 guchar *data;
2104 gsize len;
2105 GdkPixbufLoader *pl;
2106 GError *error = NULL;
2107 IRRECO_ENTER
2109 msg = soup_xmlrpc_message_new (IRRECO_WEBDB_URL);
2110 soup_xmlrpc_message_start_call (msg, "getPreviewButton");
2111 soup_xmlrpc_message_start_param (msg);
2112 soup_xmlrpc_message_write_int(msg, theme_id);
2113 soup_xmlrpc_message_end_param (msg);
2114 soup_xmlrpc_message_end_call (msg);
2116 irreco_webdb_client_reset_env(self);
2118 response = (SoupXmlrpcResponse*) do_xmlrpc (msg,
2119 SOUP_XMLRPC_VALUE_TYPE_STRING, self);
2121 /* Check response exists */
2122 if(!response) {
2123 IRRECO_DEBUG(" No response, failed at do_xmlrpc\n");
2124 goto end;
2127 value = soup_xmlrpc_response_get_value (response);
2129 /* Try to get string out of value */
2130 if(!soup_xmlrpc_value_get_string(value, &base64_data)){
2131 g_string_printf(self->error_msg,
2132 "ERROR: Not proper return value\n");
2133 goto end;
2136 data = g_base64_decode(base64_data, &len);
2138 pl = gdk_pixbuf_loader_new();
2140 gdk_pixbuf_loader_write(pl, data, len, &error);
2142 if(error != NULL)
2144 g_string_printf(self->error_msg, "ERROR: %s", error->message);
2145 IRRECO_DEBUG("%s\n", error->message);
2146 goto end;
2149 gdk_pixbuf_loader_close(pl, NULL);
2150 *preview_button = gdk_pixbuf_loader_get_pixbuf(pl);
2152 rvalue = TRUE;
2154 end:
2155 g_object_unref (response);
2156 if (base64_data != NULL) g_free(base64_data);
2158 IRRECO_RETURN_BOOL(rvalue);
2161 static SoupXmlrpcResponse *do_xmlrpc(SoupXmlrpcMessage *xmsg,
2162 SoupXmlrpcValueType type,
2163 IrrecoWebdbClient *self)
2165 SoupSession *session;
2166 int status; /* Status of sent message */
2167 SoupMessage *spmsg = NULL; /* Soupmessage */
2168 SoupXmlrpcResponse *response = NULL; /* Response */
2169 SoupXmlrpcValue *value = NULL; /* Value from response */
2170 gchar *resbodykeeper; /* Tmp response holder */
2171 gboolean error = FALSE;
2173 IRRECO_ENTER
2175 session = soup_session_sync_new(); /* Init new synchronous session */
2177 soup_xmlrpc_message_persist (xmsg); /* Lock message */
2179 spmsg = SOUP_MESSAGE(xmsg); /* soup XMLRPC msg to soup msg */
2181 /* Add irreco version to message header */
2182 soup_message_add_header(spmsg->request_headers,
2183 "User-Agent", PACKAGE_NAME "/" VERSION);
2185 IRRECO_DEBUG("Send soup message\n");
2186 status = soup_session_send_message (session, spmsg); /* Send msg */
2188 soup_session_abort (session); /* Session cleanup */
2190 g_object_unref (session);
2192 /* Print request length and response */
2193 /*IRRECO_DEBUG("\n%.*s\n%d %s\n%.*s\n",
2194 spmsg->request.length, spmsg->request.body,
2195 spmsg->status_code, spmsg->reason_phrase,
2196 spmsg->response.length, spmsg->response.body);*/
2197 IRRECO_DEBUG("\nRequest length: %d\nStatus code: %d %s\n",
2198 spmsg->request.length,
2199 spmsg->status_code, spmsg->reason_phrase);
2201 /* Check status of sent message */
2202 if (g_strrstr(spmsg->response.body, "faultCode") != NULL) {
2204 gchar *errmsg; /* error message */
2205 IRRECO_DEBUG("Found faultCode, parse response\n");
2206 IRRECO_DEBUG("%s\n",spmsg->response.body);
2208 errmsg = g_malloc0(strlen(spmsg->response.body)*sizeof(gchar));
2211 /** @todo
2212 * Error code and message could be combined to be Error: <num> <msg>
2213 * if thats possible to do easily
2215 strcpy(errmsg, "Error code: ");
2217 /* Parse spmsgrspbd to start "<int>" */
2218 spmsg->response.body = g_strrstr(spmsg->response.body, "<int>");
2220 resbodykeeper = g_strdup( spmsg->response.body );
2222 /* Copy part of response to errmsg */
2223 strcpy(&errmsg[12], &resbodykeeper[5]);
2225 /* Calc errorcode length and insert ", Error Message: " */
2226 /* in place of "</int>" */
2227 strcpy(&errmsg[strlen(errmsg)-strlen(g_strrstr(errmsg,
2228 "</int>"))], ", Error Message: ");
2230 /* Cut 'til "<string>" */
2231 resbodykeeper = g_strrstr(resbodykeeper, "<string>");
2233 /* Copy error message from after "<string>" into errmsg */
2234 strcpy(&errmsg[strlen(errmsg)], &resbodykeeper[8]);
2236 /* Cut "</string>" and everything after it */
2237 strcpy(&errmsg[strlen(errmsg)-strlen(g_strrstr(errmsg, "</string>"))], "");
2239 /* Parsed error message to right variable */
2240 g_string_printf(self->error_msg, "%s\n", errmsg);
2242 /* Free errmsg resource */
2243 g_free(errmsg);
2244 errmsg = NULL;
2246 error = TRUE;
2247 goto cleanup;
2249 IRRECO_LINE
2250 /* Handle http failures, eg. 404 */
2251 if (!SOUP_STATUS_IS_SUCCESSFUL (status)) {
2252 IRRECO_DEBUG("HTTP failure\n");
2253 g_string_printf(self->error_msg, "%d %s\n",
2254 status, spmsg->reason_phrase);
2256 error = TRUE;
2257 goto cleanup;
2260 /* Parse response */
2261 response = soup_xmlrpc_response_new();
2262 response = soup_xmlrpc_message_parse_response (xmsg);
2264 /* Handle fault responses */
2265 if (!response) {
2266 IRRECO_DEBUG("ERROR: no response\n");
2267 g_string_printf(self->error_msg, "ERROR: no response\n");
2268 error = TRUE;
2269 goto cleanup;
2272 if (soup_xmlrpc_response_is_fault (response)) {
2273 IRRECO_DEBUG("ERROR: response is fault\n");
2274 g_string_printf(self->error_msg, "ERROR: response is fault\n");
2275 error = TRUE;
2276 goto cleanup;
2279 /* Get value(s) from response */
2280 value = soup_xmlrpc_response_get_value(response);
2282 /* Handle wrong type and no value situations */
2283 if (!value) {
2284 IRRECO_DEBUG("ERROR: no value\n");
2285 g_string_printf(self->error_msg, "ERROR: no value\n");
2286 error = TRUE;
2287 goto cleanup;
2290 if (soup_xmlrpc_value_get_type (value) != type) {
2291 IRRECO_DEBUG("ERROR: wrong value type\nexpected %s, got %s\n",
2292 value_type[type],
2293 value_type[soup_xmlrpc_value_get_type (value)]);
2295 g_string_printf(self->error_msg,
2296 "ERROR: wrong value type\nexpected %s, got %s\n",
2297 value_type[type],
2298 value_type[soup_xmlrpc_value_get_type (value)]);
2300 error = TRUE;
2301 goto cleanup;
2304 cleanup:
2305 /* Unref soupmessage */
2306 if (spmsg != NULL && !error) {
2307 g_object_unref(spmsg);
2308 spmsg = NULL;
2311 if(error) {
2312 if (response != NULL) g_object_unref(response);
2313 response = NULL;
2316 IRRECO_RETURN_PTR(response);
2319 gboolean irreco_webdb_client_add_user(IrrecoWebdbClient *self,
2320 const gchar *name,
2321 const gchar *email,
2322 const gchar *passwd)
2324 gboolean rvalue = TRUE;
2326 SoupXmlrpcMessage *msg;
2327 SoupXmlrpcResponse *response;
2328 SoupXmlrpcValue *value;
2329 /*gboolean result;*/
2331 IRRECO_ENTER
2333 /* Init msg with URI and other data */
2334 msg = soup_xmlrpc_message_new (IRRECO_WEBDB_URL);
2335 soup_xmlrpc_message_start_call (msg, "addUser");
2337 soup_xmlrpc_message_start_param (msg);
2338 soup_xmlrpc_message_write_string(msg, name);
2339 soup_xmlrpc_message_end_param (msg);
2341 soup_xmlrpc_message_start_param (msg);
2342 soup_xmlrpc_message_write_string(msg, email);
2343 soup_xmlrpc_message_end_param (msg);
2345 soup_xmlrpc_message_start_param (msg);
2346 soup_xmlrpc_message_write_string(msg, passwd);
2347 soup_xmlrpc_message_end_param (msg);
2349 soup_xmlrpc_message_end_call (msg);
2351 /* Reset error params */
2352 irreco_webdb_client_reset_env(self);
2354 /* Execute XML-RPC call. */
2355 response = (SoupXmlrpcResponse*) do_xmlrpc (msg,
2356 SOUP_XMLRPC_VALUE_TYPE_BOOLEAN, self);
2358 /* Check response exists */
2359 if(!response) {
2360 IRRECO_DEBUG(" No response, failed something\n");
2361 IRRECO_RETURN_BOOL(FALSE);
2364 value = soup_xmlrpc_response_get_value (response);
2366 g_object_unref (response);
2368 /* Everything went fine, return TRUE */
2369 IRRECO_RETURN_BOOL(rvalue);
2373 * Login user to WebDB.
2376 gboolean irreco_webdb_client_login(IrrecoWebdbClient *self,
2377 const gchar *user,
2378 const gchar *password)
2380 gboolean rvalue = TRUE;
2381 SoupXmlrpcMessage *msg;
2382 SoupXmlrpcResponse *response;
2383 SoupXmlrpcValue *value;
2384 IRRECO_ENTER
2386 /* Init msg with URI and other data */
2387 msg = soup_xmlrpc_message_new (IRRECO_WEBDB_URL);
2388 soup_xmlrpc_message_start_call (msg, "loginToDB");
2389 soup_xmlrpc_message_start_param (msg);
2390 soup_xmlrpc_message_write_string(msg, user);
2391 soup_xmlrpc_message_end_param (msg);
2392 soup_xmlrpc_message_start_param (msg);
2393 soup_xmlrpc_message_write_string(msg, password);
2394 soup_xmlrpc_message_end_param (msg);
2395 soup_xmlrpc_message_end_call (msg);
2397 irreco_webdb_client_reset_env(self);
2399 /* Execute XML-RPC call. */
2400 response = (SoupXmlrpcResponse*) do_xmlrpc (msg,
2401 SOUP_XMLRPC_VALUE_TYPE_BOOLEAN, self);
2403 /* Check response exists */
2404 if(!response) {
2405 IRRECO_DEBUG(" No response, failed something\n");
2406 IRRECO_RETURN_BOOL(FALSE);
2409 value = soup_xmlrpc_response_get_value (response);
2411 g_object_unref (response);
2413 /* Everything went fine, return TRUE */
2414 IRRECO_RETURN_BOOL(rvalue);
2420 #if 0
2424 gboolean irreco_webdb_client_get_category_list(GHashTable **category_list)
2426 gint i;
2427 IRRECO_ENTER
2429 *category_list = NULL;
2431 /* Execute XML-RPC call. */
2432 irreco_webdb_client_reset_env();
2433 self->result = xmlrpc_client_call_server(self->error_env, self->server,
2434 "getCategoryList", "()");
2435 if (!irreco_webdb_client_is_ok()) IRRECO_RETURN_BOOL(FALSE);
2437 /* Get structure size. */
2438 i = xmlrpc_struct_size(self->error_env, self->result);
2439 if (!irreco_webdb_client_is_ok()) IRRECO_RETURN_BOOL(FALSE);
2441 /* Create hashtable. */
2442 *category_list = g_hash_table_new_full(g_int_hash, g_int_equal,
2443 NULL, g_free);
2445 /* Parse structure. */
2446 while (i--) {
2447 xmlrpc_value *xml_key;
2448 xmlrpc_value *xml_value;
2449 const gchar * str_key;
2450 const gchar * str_value;
2452 xmlrpc_struct_read_member(self->error_env, self->result, i,
2453 &xml_key, &xml_value);
2454 if (!irreco_webdb_client_is_ok()) goto error;
2456 xmlrpc_read_string(self->error_env, xml_key, &str_key);
2457 if (!irreco_webdb_client_is_ok()) goto error;
2459 xmlrpc_read_string(self->error_env, xml_value, &str_value);
2460 if (!irreco_webdb_client_is_ok()) goto error;
2462 IRRECO_PRINTF("Key: %s, Val: %s\n", str_key, str_value);
2463 /*g_hash_table_add();*/
2465 xmlrpc_DECREF(xml_key);
2466 xmlrpc_DECREF(xml_value);
2469 IRRECO_RETURN_BOOL(TRUE);
2471 error:
2472 g_hash_table_destroy(*category_list);
2473 *category_list = NULL;
2474 IRRECO_RETURN_BOOL(FALSE);
2476 #endif
2478 gint irreco_webdb_client_create_new_remote(IrrecoWebdbClient *self,
2479 const gchar *comment,
2480 const gchar *category,
2481 const gchar *manufacturer,
2482 const gchar *model,
2483 const gchar *file_name,
2484 const gchar *file_data,
2485 const gchar *user,
2486 const gchar *password)
2488 SoupXmlrpcMessage *msg;
2489 SoupXmlrpcResponse *response;
2490 SoupXmlrpcValue *value;
2491 gint remote_id;
2492 gchar *file_hash;
2494 IRRECO_ENTER
2495 file_hash = sha_compute_checksum_for_string(G_CHECKSUM_SHA1,
2496 file_data, -1);
2497 msg = soup_xmlrpc_message_new (IRRECO_WEBDB_URL);
2498 soup_xmlrpc_message_start_call (msg, "createNewRemote");
2499 soup_xmlrpc_message_start_param (msg);
2500 soup_xmlrpc_message_write_string(msg, comment);
2501 soup_xmlrpc_message_write_string(msg, category);
2502 soup_xmlrpc_message_write_string(msg, manufacturer);
2503 soup_xmlrpc_message_write_string(msg, model);
2504 soup_xmlrpc_message_write_string(msg, file_hash);
2505 soup_xmlrpc_message_write_string(msg, file_name);
2506 soup_xmlrpc_message_write_string(msg, file_data);
2507 soup_xmlrpc_message_write_string(msg, user);
2508 soup_xmlrpc_message_write_string(msg, password);
2509 soup_xmlrpc_message_end_param (msg);
2510 soup_xmlrpc_message_end_call (msg);
2512 irreco_webdb_client_reset_env(self);
2514 response = (SoupXmlrpcResponse*) do_xmlrpc (msg,
2515 SOUP_XMLRPC_VALUE_TYPE_INT, self);
2517 /* Check response exists */
2518 if(!response) {
2519 IRRECO_DEBUG(" No response, failed at do_xmlrpc\n");
2520 IRRECO_RETURN_INT(0);
2523 value = soup_xmlrpc_response_get_value (response);
2525 /* Try to get integer out of value */
2526 if(soup_xmlrpc_value_get_int(value, (glong *) &remote_id)){
2527 g_object_unref (response);
2528 IRRECO_RETURN_INT(remote_id);
2531 g_string_printf(self->error_msg, "ERROR: Not proper return value\n");
2532 g_object_unref (response);
2533 IRRECO_RETURN_INT(0);
2536 gboolean irreco_webdb_client_set_remote_downloadable(IrrecoWebdbClient *self,
2537 gint id,
2538 gboolean downloadable,
2539 const gchar *user,
2540 const gchar *password)
2542 SoupXmlrpcMessage *msg;
2543 SoupXmlrpcResponse *response;
2544 SoupXmlrpcValue *value;
2545 gboolean rvalue = FALSE;
2547 IRRECO_ENTER
2548 msg = soup_xmlrpc_message_new (IRRECO_WEBDB_URL);
2549 soup_xmlrpc_message_start_call (msg, "setRemoteDownloadable");
2550 soup_xmlrpc_message_start_param (msg);
2551 soup_xmlrpc_message_write_int(msg, id);
2552 soup_xmlrpc_message_write_boolean(msg, downloadable);
2553 soup_xmlrpc_message_write_string(msg, user);
2554 soup_xmlrpc_message_write_string(msg, password);
2555 soup_xmlrpc_message_end_param (msg);
2556 soup_xmlrpc_message_end_call (msg);
2558 irreco_webdb_client_reset_env(self);
2560 response = (SoupXmlrpcResponse*) do_xmlrpc (msg,
2561 SOUP_XMLRPC_VALUE_TYPE_BOOLEAN, self);
2563 /* Check response exists */
2564 if(!response) {
2565 IRRECO_DEBUG(" No response, failed at do_xmlrpc\n");
2566 IRRECO_RETURN_BOOL(FALSE);
2569 value = soup_xmlrpc_response_get_value (response);
2571 /* Try to get boolean out of value */
2572 soup_xmlrpc_value_get_boolean(value, &rvalue);
2574 g_object_unref (response);
2575 IRRECO_RETURN_BOOL(rvalue);
2578 gboolean irreco_webdb_client_add_configuration_to_remote(
2579 IrrecoWebdbClient *self,
2580 gint remote_id,
2581 gint configuration_id,
2582 const gchar *user,
2583 const gchar *password)
2585 SoupXmlrpcMessage *msg;
2586 SoupXmlrpcResponse *response;
2587 SoupXmlrpcValue *value;
2588 gboolean rvalue = FALSE;
2590 IRRECO_ENTER
2591 msg = soup_xmlrpc_message_new (IRRECO_WEBDB_URL);
2592 soup_xmlrpc_message_start_call (msg, "addConfigurationToRemote");
2593 soup_xmlrpc_message_start_param (msg);
2594 soup_xmlrpc_message_write_int(msg, remote_id);
2595 soup_xmlrpc_message_write_int(msg, configuration_id);
2596 soup_xmlrpc_message_write_string(msg, user);
2597 soup_xmlrpc_message_write_string(msg, password);
2598 soup_xmlrpc_message_end_param (msg);
2599 soup_xmlrpc_message_end_call (msg);
2601 irreco_webdb_client_reset_env(self);
2603 response = (SoupXmlrpcResponse*) do_xmlrpc (msg,
2604 SOUP_XMLRPC_VALUE_TYPE_BOOLEAN, self);
2606 /* Check response exists */
2607 if(!response) {
2608 IRRECO_DEBUG(" No response, failed at do_xmlrpc\n");
2609 IRRECO_RETURN_BOOL(FALSE);
2612 value = soup_xmlrpc_response_get_value (response);
2614 /* Try to get boolean out of value */
2615 soup_xmlrpc_value_get_boolean(value, &rvalue);
2617 g_object_unref (response);
2618 IRRECO_RETURN_BOOL(rvalue);
2621 gboolean irreco_webdb_client_add_theme_to_remote(IrrecoWebdbClient *self,
2622 gint remote_id,
2623 gint theme_id,
2624 const gchar *user,
2625 const gchar *password)
2627 SoupXmlrpcMessage *msg;
2628 SoupXmlrpcResponse *response;
2629 SoupXmlrpcValue *value;
2630 gboolean rvalue = FALSE;
2632 IRRECO_ENTER
2633 msg = soup_xmlrpc_message_new (IRRECO_WEBDB_URL);
2634 soup_xmlrpc_message_start_call (msg, "addThemeToRemote");
2635 soup_xmlrpc_message_start_param (msg);
2636 soup_xmlrpc_message_write_int(msg, remote_id);
2637 soup_xmlrpc_message_write_int(msg, theme_id);
2638 soup_xmlrpc_message_write_string(msg, user);
2639 soup_xmlrpc_message_write_string(msg, password);
2640 soup_xmlrpc_message_end_param (msg);
2641 soup_xmlrpc_message_end_call (msg);
2643 irreco_webdb_client_reset_env(self);
2645 response = (SoupXmlrpcResponse*) do_xmlrpc (msg,
2646 SOUP_XMLRPC_VALUE_TYPE_BOOLEAN, self);
2648 /* Check response exists */
2649 if(!response) {
2650 IRRECO_DEBUG(" No response, failed at do_xmlrpc\n");
2651 IRRECO_RETURN_BOOL(FALSE);
2654 value = soup_xmlrpc_response_get_value (response);
2656 /* Try to get boolean out of value */
2657 soup_xmlrpc_value_get_boolean(value, &rvalue);
2659 g_object_unref (response);
2660 IRRECO_RETURN_BOOL(rvalue);
2663 gboolean irreco_webdb_client_get_remote_categories(IrrecoWebdbClient *self,
2664 IrrecoStringTable **category_list)
2666 gboolean rvalue = FALSE;
2667 SoupXmlrpcMessage *msg;
2668 SoupXmlrpcResponse *response;
2669 SoupXmlrpcValueArrayIterator *iter;
2670 SoupXmlrpcValue *value;
2671 SoupXmlrpcValue *array_val;
2672 gchar *ret = NULL;
2674 IRRECO_ENTER
2676 irreco_webdb_client_reset_env(self);
2678 msg = soup_xmlrpc_message_new (IRRECO_WEBDB_URL);
2679 soup_xmlrpc_message_start_call (msg, "getRemoteCategories");
2680 soup_xmlrpc_message_end_call (msg);
2682 response = (SoupXmlrpcResponse*) do_xmlrpc (msg,
2683 SOUP_XMLRPC_VALUE_TYPE_ARRAY, self);
2684 if(!response) {
2685 IRRECO_DEBUG(" No response, failed something\n");
2686 IRRECO_RETURN_BOOL(rvalue);
2689 value = soup_xmlrpc_response_get_value (response);
2691 soup_xmlrpc_value_array_get_iterator(value, &iter);
2693 *category_list = irreco_string_table_new((GDestroyNotify)
2694 irreco_string_table_free,
2695 NULL);
2696 while (iter) {
2697 soup_xmlrpc_value_array_iterator_get_value(iter, &array_val);
2699 if (!soup_xmlrpc_value_get_string(array_val, &ret)) {
2700 IRRECO_DEBUG ("NO value\n");
2701 g_object_unref (response);
2702 irreco_string_table_free(*category_list);
2703 *category_list = NULL;
2704 IRRECO_RETURN_BOOL(rvalue);
2706 IRRECO_DEBUG("%s\n", ret);
2708 irreco_string_table_add(*category_list, ret, NULL);
2710 iter = soup_xmlrpc_value_array_iterator_next(iter);
2713 rvalue = TRUE;
2714 g_object_unref(response);
2716 IRRECO_RETURN_BOOL(rvalue);
2719 gboolean irreco_webdb_client_get_remote_manufacturers(IrrecoWebdbClient *self,
2720 const gchar *category,
2721 IrrecoStringTable **manufacturer_list)
2723 gboolean rvalue = FALSE;
2724 SoupXmlrpcMessage *msg;
2725 SoupXmlrpcResponse *response;
2726 SoupXmlrpcValueArrayIterator *iter;
2727 SoupXmlrpcValue *value;
2728 SoupXmlrpcValue *array_val;
2729 gchar *ret = NULL;
2731 IRRECO_ENTER
2733 irreco_webdb_client_reset_env(self);
2735 msg = soup_xmlrpc_message_new (IRRECO_WEBDB_URL);
2736 soup_xmlrpc_message_start_call (msg, "getRemoteManufacturers");
2737 soup_xmlrpc_message_start_param (msg);
2738 soup_xmlrpc_message_write_string(msg, category);
2739 soup_xmlrpc_message_end_param (msg);
2740 soup_xmlrpc_message_end_call (msg);
2742 response = (SoupXmlrpcResponse*) do_xmlrpc (msg,
2743 SOUP_XMLRPC_VALUE_TYPE_ARRAY, self);
2744 if(!response) {
2745 IRRECO_DEBUG(" No response, failed something\n");
2746 IRRECO_RETURN_BOOL(rvalue);
2749 value = soup_xmlrpc_response_get_value (response);
2751 soup_xmlrpc_value_array_get_iterator(value, &iter);
2753 *manufacturer_list = irreco_string_table_new((GDestroyNotify)
2754 irreco_string_table_free,
2755 NULL);
2757 while (iter) {
2758 soup_xmlrpc_value_array_iterator_get_value(iter, &array_val);
2760 if (!soup_xmlrpc_value_get_string(array_val, &ret)) {
2761 IRRECO_DEBUG ("NO value\n");
2762 g_object_unref (response);
2763 irreco_string_table_free(*manufacturer_list);
2764 *manufacturer_list = NULL;
2765 IRRECO_RETURN_BOOL(rvalue);
2767 IRRECO_DEBUG("%s\n", ret);
2769 irreco_string_table_add(*manufacturer_list, ret, NULL);
2771 iter = soup_xmlrpc_value_array_iterator_next(iter);
2774 rvalue = TRUE;
2775 g_object_unref(response);
2777 IRRECO_RETURN_BOOL(rvalue);
2780 gboolean irreco_webdb_client_get_remote_models(IrrecoWebdbClient *self,
2781 const gchar *category,
2782 const gchar *manufacturer,
2783 IrrecoStringTable **model_list)
2785 gboolean rvalue = FALSE;
2786 SoupXmlrpcMessage *msg;
2787 SoupXmlrpcResponse *response;
2788 SoupXmlrpcValueArrayIterator *iter;
2789 SoupXmlrpcValue *value;
2790 SoupXmlrpcValue *array_val;
2791 gchar *ret = NULL;
2793 IRRECO_ENTER
2795 irreco_webdb_client_reset_env(self);
2797 msg = soup_xmlrpc_message_new (IRRECO_WEBDB_URL);
2798 soup_xmlrpc_message_start_call (msg, "getRemoteModels");
2799 soup_xmlrpc_message_start_param (msg);
2800 soup_xmlrpc_message_write_string(msg, category);
2801 soup_xmlrpc_message_write_string(msg, manufacturer);
2802 soup_xmlrpc_message_end_param (msg);
2803 soup_xmlrpc_message_end_call (msg);
2805 response = (SoupXmlrpcResponse*) do_xmlrpc (msg,
2806 SOUP_XMLRPC_VALUE_TYPE_ARRAY, self);
2807 if(!response) {
2808 IRRECO_DEBUG(" No response, failed something\n");
2809 IRRECO_RETURN_BOOL(rvalue);
2812 value = soup_xmlrpc_response_get_value (response);
2814 soup_xmlrpc_value_array_get_iterator(value, &iter);
2816 *model_list = irreco_string_table_new((GDestroyNotify)
2817 irreco_string_table_free, NULL);
2818 while (iter) {
2819 soup_xmlrpc_value_array_iterator_get_value(iter, &array_val);
2821 if (!soup_xmlrpc_value_get_string(array_val, &ret)) {
2822 IRRECO_DEBUG ("No value\n");
2823 g_object_unref (response);
2824 irreco_string_table_free(*model_list);
2825 *model_list = NULL;
2826 IRRECO_RETURN_BOOL(rvalue);
2828 IRRECO_DEBUG("%s\n", ret);
2830 irreco_string_table_add(*model_list, ret, NULL);
2832 iter = soup_xmlrpc_value_array_iterator_next(iter);
2835 rvalue = TRUE;
2836 g_object_unref(response);
2838 IRRECO_RETURN_BOOL(rvalue);
2841 gboolean irreco_webdb_client_get_remote_creators(IrrecoWebdbClient *self,
2842 const gchar *category,
2843 const gchar *manufacturer,
2844 const gchar *model,
2845 IrrecoStringTable **creators)
2847 gboolean rvalue = FALSE;
2848 SoupXmlrpcMessage *msg;
2849 SoupXmlrpcResponse *response;
2850 SoupXmlrpcValueArrayIterator *iter;
2851 SoupXmlrpcValue *value;
2852 SoupXmlrpcValue *array_val;
2853 gchar *ret = NULL;
2855 IRRECO_ENTER
2857 irreco_webdb_client_reset_env(self);
2859 msg = soup_xmlrpc_message_new (IRRECO_WEBDB_URL);
2860 soup_xmlrpc_message_start_call (msg, "getRemoteCreators");
2861 soup_xmlrpc_message_start_param (msg);
2862 soup_xmlrpc_message_write_string(msg, category);
2863 soup_xmlrpc_message_write_string(msg, manufacturer);
2864 soup_xmlrpc_message_write_string(msg, model);
2865 soup_xmlrpc_message_end_param (msg);
2866 soup_xmlrpc_message_end_call (msg);
2868 response = (SoupXmlrpcResponse*) do_xmlrpc (msg,
2869 SOUP_XMLRPC_VALUE_TYPE_ARRAY, self);
2870 if(!response) {
2871 IRRECO_DEBUG(" No response, failed something\n");
2872 IRRECO_RETURN_BOOL(rvalue);
2875 value = soup_xmlrpc_response_get_value(response);
2877 soup_xmlrpc_value_array_get_iterator(value, &iter);
2879 *creators = irreco_string_table_new((GDestroyNotify) g_list_free, NULL);
2880 while (iter) {
2881 soup_xmlrpc_value_array_iterator_get_value(iter, &array_val);
2883 if (!soup_xmlrpc_value_get_string(array_val, &ret)) {
2884 IRRECO_DEBUG ("No value\n");
2885 g_object_unref(response);
2886 irreco_string_table_free(*creators);
2887 *creators = NULL;
2888 IRRECO_RETURN_BOOL(rvalue);
2890 IRRECO_DEBUG("%s\n", ret);
2892 irreco_string_table_add(*creators, ret, NULL);
2894 iter = soup_xmlrpc_value_array_iterator_next(iter);
2897 rvalue = TRUE;
2898 g_object_unref(response);
2900 IRRECO_RETURN_BOOL(rvalue);
2903 gboolean irreco_webdb_client_get_remotes(IrrecoWebdbClient *self,
2904 const gchar *category,
2905 const gchar *manufacturer,
2906 const gchar *model,
2907 const gchar *creator,
2908 GList **remote_list)
2910 gboolean rvalue = FALSE;
2911 SoupXmlrpcMessage *msg;
2912 SoupXmlrpcResponse *response;
2913 SoupXmlrpcValueArrayIterator *iter;
2914 SoupXmlrpcValue *value;
2915 SoupXmlrpcValue *array_val;
2916 gint ret;
2918 IRRECO_ENTER
2920 irreco_webdb_client_reset_env(self);
2922 msg = soup_xmlrpc_message_new (IRRECO_WEBDB_URL);
2923 soup_xmlrpc_message_start_call (msg, "getRemotes");
2924 soup_xmlrpc_message_start_param (msg);
2925 soup_xmlrpc_message_write_string(msg, category);
2926 soup_xmlrpc_message_write_string(msg, manufacturer);
2927 soup_xmlrpc_message_write_string(msg, model);
2928 soup_xmlrpc_message_write_string(msg, creator);
2929 soup_xmlrpc_message_end_param (msg);
2930 soup_xmlrpc_message_end_call (msg);
2932 response = (SoupXmlrpcResponse*) do_xmlrpc (msg,
2933 SOUP_XMLRPC_VALUE_TYPE_ARRAY, self);
2934 if(!response) {
2935 IRRECO_DEBUG(" No response, failed something\n");
2936 IRRECO_RETURN_BOOL(rvalue);
2939 value = soup_xmlrpc_response_get_value(response);
2941 soup_xmlrpc_value_array_get_iterator(value, &iter);
2943 *remote_list = NULL;
2944 while (iter) {
2945 soup_xmlrpc_value_array_iterator_get_value(iter, &array_val);
2947 if (!soup_xmlrpc_value_get_int(array_val, (glong *)&ret)) {
2948 IRRECO_DEBUG ("No value\n");
2949 g_object_unref(response);
2950 IRRECO_RETURN_BOOL(rvalue);
2952 IRRECO_DEBUG("%d\n", ret);
2954 *remote_list = g_list_append(*remote_list,
2955 GINT_TO_POINTER(ret));
2957 iter = soup_xmlrpc_value_array_iterator_next(iter);
2960 *remote_list = g_list_first(*remote_list);
2962 rvalue = TRUE;
2963 g_object_unref(response);
2965 IRRECO_RETURN_BOOL(rvalue);
2968 gboolean irreco_webdb_client_get_remote_by_id(IrrecoWebdbClient *self,
2969 gint id,
2970 IrrecoWebdbRemote **remote)
2972 gboolean rvalue = FALSE;
2973 gchar *user = NULL;
2974 gchar *comment = NULL;
2975 gchar *category = NULL;
2976 gchar *manufacturer = NULL;
2977 gchar *model = NULL;
2978 gchar *file_hash = NULL;
2979 gchar *file_name = NULL;
2980 gchar *uploaded = NULL;
2981 gchar *modified = NULL;
2982 gchar *downloaded = NULL;
2983 gint download_count;
2984 SoupXmlrpcMessage *msg = NULL;
2985 SoupXmlrpcResponse *response = NULL;
2986 SoupXmlrpcValue *value = NULL;
2987 GHashTable *tmp = NULL;
2988 SoupXmlrpcValue *hash = NULL;
2990 IRRECO_ENTER
2992 irreco_webdb_client_reset_env(self);
2994 /* Build query */
2995 msg = soup_xmlrpc_message_new (IRRECO_WEBDB_URL);
2996 soup_xmlrpc_message_start_call (msg, "getRemoteById");
2997 soup_xmlrpc_message_start_param (msg);
2998 soup_xmlrpc_message_write_int(msg, (glong) id);
2999 soup_xmlrpc_message_end_param (msg);
3000 soup_xmlrpc_message_end_call (msg);
3002 /* Execute XML-RPC call. */
3003 response = (SoupXmlrpcResponse*) do_xmlrpc (msg,
3004 SOUP_XMLRPC_VALUE_TYPE_STRUCT, self);
3006 /* Check response */
3007 if(!response) {
3008 IRRECO_DEBUG(" No response, failed something\n");
3009 goto end;
3012 /* Get array out from response */
3013 value = soup_xmlrpc_response_get_value (response);
3015 if(!soup_xmlrpc_value_get_struct(value, &tmp)){
3016 g_string_printf(self->error_msg,
3017 "ERROR: Not proper return value\n");
3018 goto end;
3021 /* Seek data */
3022 hash = g_hash_table_lookup (tmp, "user");
3023 if (!soup_xmlrpc_value_get_string(hash, &user)) {
3024 IRRECO_DEBUG("No value in response\n");
3025 goto end;
3028 hash = g_hash_table_lookup (tmp, "comment");
3029 if (!soup_xmlrpc_value_get_string(hash, &comment)) {
3030 IRRECO_DEBUG ("No value in response\n");
3031 goto end;
3034 hash = g_hash_table_lookup (tmp, "category");
3035 if (!soup_xmlrpc_value_get_string(hash, &category)) {
3036 IRRECO_DEBUG ("No value in response\n");
3037 goto end;
3040 hash = g_hash_table_lookup (tmp, "manufacturer");
3041 if (!soup_xmlrpc_value_get_string(hash, &manufacturer)) {
3042 IRRECO_DEBUG ("No value in response\n");
3043 goto end;
3046 hash = g_hash_table_lookup (tmp, "model");
3047 if (!soup_xmlrpc_value_get_string(hash, &model)) {
3048 IRRECO_DEBUG ("No value in response\n");
3049 goto end;
3052 hash = g_hash_table_lookup (tmp, "file_hash");
3053 if (!soup_xmlrpc_value_get_string(hash, &file_hash)) {
3054 IRRECO_DEBUG ("No value in response\n");
3055 goto end;
3058 hash = g_hash_table_lookup (tmp, "file_name");
3059 if (!soup_xmlrpc_value_get_string(hash, &file_name)) {
3060 IRRECO_DEBUG ("No value in response\n");
3061 goto end;
3064 hash = g_hash_table_lookup (tmp, "uploaded");
3065 if (!soup_xmlrpc_value_get_string(hash, &uploaded)) {
3066 IRRECO_DEBUG ("No value in response\n");
3067 goto end;
3070 hash = g_hash_table_lookup (tmp, "modified");
3071 if (!soup_xmlrpc_value_get_string(hash, &modified)) {
3072 IRRECO_DEBUG ("No value in response\n");
3073 goto end;
3076 hash = g_hash_table_lookup (tmp, "downloaded");
3077 if (!soup_xmlrpc_value_get_string(hash, &downloaded)) {
3078 IRRECO_DEBUG ("No value in response\n");
3079 goto end;
3082 hash = g_hash_table_lookup (tmp, "download_count");
3083 if (!soup_xmlrpc_value_get_int(hash, (glong *) &download_count)) {
3084 IRRECO_DEBUG ("No value in response\n");
3085 goto end;
3088 *remote = irreco_webdb_remote_new();
3089 irreco_webdb_remote_set(*remote, id, user, comment, category,
3090 manufacturer, model, file_hash, file_name,
3091 uploaded, modified, downloaded, download_count);
3093 /* No error occured. */
3094 rvalue = TRUE;
3096 end:
3097 if (response != NULL) g_object_unref(response);
3098 if (tmp != NULL) g_hash_table_destroy(tmp);
3099 if (user != NULL) g_free(user);
3100 if (comment != NULL) g_free(comment);
3101 if (category != NULL) g_free(category);
3102 if (manufacturer != NULL) g_free(manufacturer);
3103 if (model != NULL) g_free(model);
3104 if (file_hash != NULL) g_free(file_hash);
3105 if (file_name != NULL) g_free(file_name);
3106 if (uploaded != NULL) g_free(uploaded);
3107 if (modified != NULL) g_free(modified);
3108 if (downloaded != NULL) g_free(downloaded);
3110 IRRECO_RETURN_BOOL(rvalue);
3114 gboolean irreco_webdb_client_get_themes_of_remote(IrrecoWebdbClient *self,
3115 gint remote_id,
3116 GList **themes)
3118 gboolean rvalue = FALSE;
3119 SoupXmlrpcMessage *msg;
3120 SoupXmlrpcResponse *response;
3121 SoupXmlrpcValueArrayIterator *iter;
3122 SoupXmlrpcValue *value;
3123 SoupXmlrpcValue *array_val;
3124 gint ret;
3126 IRRECO_ENTER
3128 irreco_webdb_client_reset_env(self);
3130 msg = soup_xmlrpc_message_new (IRRECO_WEBDB_URL);
3131 soup_xmlrpc_message_start_call (msg, "getThemesOfRemote");
3132 soup_xmlrpc_message_start_param (msg);
3133 soup_xmlrpc_message_write_int(msg, (glong) remote_id);
3134 soup_xmlrpc_message_end_param (msg);
3135 soup_xmlrpc_message_end_call (msg);
3137 response = (SoupXmlrpcResponse*) do_xmlrpc (msg,
3138 SOUP_XMLRPC_VALUE_TYPE_ARRAY, self);
3139 if(!response) {
3140 IRRECO_DEBUG(" No response, failed something\n");
3141 IRRECO_RETURN_BOOL(rvalue);
3144 value = soup_xmlrpc_response_get_value (response);
3146 soup_xmlrpc_value_array_get_iterator(value, &iter);
3148 *themes = NULL;
3149 while (iter) {
3150 soup_xmlrpc_value_array_iterator_get_value(iter, &array_val);
3152 if (!soup_xmlrpc_value_get_int(array_val, (glong *) &ret)) {
3153 IRRECO_DEBUG ("NO value\n");
3154 g_object_unref (response);
3155 IRRECO_RETURN_BOOL(rvalue);
3157 IRRECO_DEBUG("%d\n", ret);
3159 *themes = g_list_append(*themes, GINT_TO_POINTER(ret));
3161 iter = soup_xmlrpc_value_array_iterator_next(iter);
3164 *themes = g_list_first(*themes);
3166 rvalue = TRUE;
3167 g_object_unref (response);
3169 IRRECO_RETURN_BOOL(rvalue);
3173 gboolean irreco_webdb_client_get_configurations_of_remote(
3174 IrrecoWebdbClient *self,
3175 gint remote_id,
3176 GList **configs)
3178 gboolean rvalue = FALSE;
3179 SoupXmlrpcMessage *msg;
3180 SoupXmlrpcResponse *response;
3181 SoupXmlrpcValueArrayIterator *iter;
3182 SoupXmlrpcValue *value;
3183 SoupXmlrpcValue *array_val;
3184 gint ret;
3186 IRRECO_ENTER
3188 irreco_webdb_client_reset_env(self);
3190 msg = soup_xmlrpc_message_new (IRRECO_WEBDB_URL);
3191 soup_xmlrpc_message_start_call (msg, "getConfigurationsOfRemote");
3192 soup_xmlrpc_message_start_param (msg);
3193 soup_xmlrpc_message_write_int(msg, (glong) remote_id);
3194 soup_xmlrpc_message_end_param (msg);
3195 soup_xmlrpc_message_end_call (msg);
3197 response = (SoupXmlrpcResponse*) do_xmlrpc (msg,
3198 SOUP_XMLRPC_VALUE_TYPE_ARRAY, self);
3199 if(!response) {
3200 IRRECO_DEBUG(" No response, failed something\n");
3201 IRRECO_RETURN_BOOL(rvalue);
3204 value = soup_xmlrpc_response_get_value (response);
3206 soup_xmlrpc_value_array_get_iterator(value, &iter);
3208 *configs = NULL;
3209 while (iter) {
3210 soup_xmlrpc_value_array_iterator_get_value(iter, &array_val);
3212 if (!soup_xmlrpc_value_get_int(array_val, (glong *) &ret)) {
3213 IRRECO_DEBUG ("NO value\n");
3214 g_object_unref (response);
3215 IRRECO_RETURN_BOOL(rvalue);
3217 IRRECO_DEBUG("%d\n", ret);
3219 *configs = g_list_append(*configs, GINT_TO_POINTER(ret));
3221 iter = soup_xmlrpc_value_array_iterator_next(iter);
3224 *configs = g_list_first(*configs);
3226 rvalue = TRUE;
3227 g_object_unref (response);
3229 IRRECO_RETURN_BOOL(rvalue);
3232 /** @} */
3235 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
3236 /* Events and Callbacks */
3237 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
3239 /** @} */