remote name deleted from database
[irreco.git] / irreco / src / webdb / irreco_webdb_client.c
blob8fb2ca1b059a8b30ea6fd364bdde3f144dee9418
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 gboolean irreco_webdb_client_get_file(IrrecoWebdbClient *self,
824 const gchar *file_hash,
825 const gchar *file_name,
826 GString **file_data)
828 gboolean rvalue = FALSE;
829 SoupXmlrpcMessage *msg;
830 SoupXmlrpcResponse *response;
831 SoupXmlrpcValue *value;
832 GHashTable *tmp = NULL;
833 gchar *ret = NULL;
834 SoupXmlrpcValue *hash = NULL;
836 IRRECO_ENTER
838 irreco_webdb_client_reset_env(self);
840 IRRECO_LINE
842 /* Build query */
843 msg = soup_xmlrpc_message_new (IRRECO_WEBDB_URL);
844 soup_xmlrpc_message_start_call (msg, "getFile");
845 soup_xmlrpc_message_start_param (msg);
846 soup_xmlrpc_message_write_string(msg, file_hash);
847 soup_xmlrpc_message_end_param (msg);
848 soup_xmlrpc_message_start_param (msg);
849 soup_xmlrpc_message_write_string(msg, file_name);
850 soup_xmlrpc_message_end_param (msg);
851 soup_xmlrpc_message_end_call (msg);
853 /* Execute XML-RPC call. */
854 response = (SoupXmlrpcResponse*) do_xmlrpc (msg,
855 SOUP_XMLRPC_VALUE_TYPE_STRUCT, self);
857 /* Check response */
858 if(!response) {
859 IRRECO_DEBUG(" No response, failed at do_xmlrpc\n");
860 IRRECO_RETURN_BOOL(FALSE);
863 /* Get array out from response */
864 value = soup_xmlrpc_response_get_value (response);
866 /* Get string out from array */
867 if(!soup_xmlrpc_value_get_struct(value, &tmp)){
868 g_string_printf(self->error_msg,
869 "ERROR: Not proper return value\n");
870 g_object_unref (response);
871 IRRECO_RETURN_BOOL(FALSE);
874 /* Seek data */
875 hash = g_hash_table_lookup (tmp, "data");
877 if (!soup_xmlrpc_value_get_string(hash, &ret)) {
878 IRRECO_DEBUG ("No value in response\n");
879 g_hash_table_destroy (tmp);
880 g_object_unref (response);
881 IRRECO_RETURN_BOOL(FALSE);
884 IRRECO_DEBUG("File data:\n%s\n",ret);
886 *file_data = g_string_new(ret);
888 g_hash_table_destroy (tmp);
889 g_object_unref (response);
891 rvalue = TRUE;
893 IRRECO_RETURN_BOOL(rvalue);
897 gboolean irreco_webdb_client_get_user_exists(IrrecoWebdbClient *self,
898 const gchar *name,
899 gboolean *user_exists)
901 SoupXmlrpcMessage *msg;
902 SoupXmlrpcResponse *response;
903 SoupXmlrpcValue *value;
905 IRRECO_ENTER
907 msg = soup_xmlrpc_message_new (IRRECO_WEBDB_URL);
908 soup_xmlrpc_message_start_call (msg, "getUserExists");
909 soup_xmlrpc_message_start_param (msg);
910 soup_xmlrpc_message_write_string(msg, name);
911 soup_xmlrpc_message_end_param (msg);
912 soup_xmlrpc_message_end_call (msg);
914 irreco_webdb_client_reset_env(self);
916 response = (SoupXmlrpcResponse*) do_xmlrpc (msg,
917 SOUP_XMLRPC_VALUE_TYPE_BOOLEAN, self);
919 /* Check response exists */
920 if(!response) {
921 IRRECO_DEBUG(" No response, failed at do_xmlrpc\n");
922 IRRECO_RETURN_BOOL(FALSE);
925 value = soup_xmlrpc_response_get_value (response);
927 /* Try to get gboolean out of value */
928 if(!soup_xmlrpc_value_get_boolean(value, user_exists)){
929 g_string_printf(self->error_msg,
930 "ERROR: Not proper return value\n");
931 g_object_unref (response);
932 IRRECO_RETURN_BOOL(FALSE);
935 g_object_unref (response);
936 IRRECO_RETURN_BOOL(TRUE);
939 gint irreco_webdb_client_get_max_image_size(IrrecoWebdbClient *self)
941 SoupXmlrpcMessage *msg;
942 SoupXmlrpcResponse *response;
943 SoupXmlrpcValue *value;
944 gint max_image_size = 0;
946 IRRECO_ENTER
948 msg = soup_xmlrpc_message_new (IRRECO_WEBDB_URL);
949 soup_xmlrpc_message_start_call (msg, "getMaxImageSize");
950 soup_xmlrpc_message_start_param (msg);
951 soup_xmlrpc_message_end_param (msg);
952 soup_xmlrpc_message_end_call (msg);
954 irreco_webdb_client_reset_env(self);
956 response = (SoupXmlrpcResponse*) do_xmlrpc(msg,
957 SOUP_XMLRPC_VALUE_TYPE_INT,
958 self);
960 /* Check response exists */
961 if(!response) {
962 IRRECO_DEBUG(" No response, failed at do_xmlrpc\n");
963 goto end;
966 value = soup_xmlrpc_response_get_value (response);
968 /* Try to get integer out of value */
969 if(!soup_xmlrpc_value_get_int(value, (glong *) &max_image_size)) {
970 max_image_size = 0;
973 end:
974 g_object_unref (response);
975 IRRECO_RETURN_INT(max_image_size);
978 gint irreco_webdb_client_create_theme(IrrecoWebdbClient *self,
979 const gchar *name,
980 const gchar *comment,
981 const gchar *preview_button,
982 const gchar *folder,
983 const gchar *user,
984 const gchar *password)
986 SoupXmlrpcMessage *msg;
987 SoupXmlrpcResponse *response;
988 SoupXmlrpcValue *value;
989 gint theme_id;
991 IRRECO_ENTER
992 msg = soup_xmlrpc_message_new (IRRECO_WEBDB_URL);
993 soup_xmlrpc_message_start_call (msg, "createNewTheme");
994 soup_xmlrpc_message_start_param (msg);
995 soup_xmlrpc_message_write_string(msg, name);
996 soup_xmlrpc_message_write_string(msg, comment);
997 soup_xmlrpc_message_write_string(msg, preview_button);
998 soup_xmlrpc_message_write_string(msg, folder);
999 soup_xmlrpc_message_write_string(msg, user);
1000 soup_xmlrpc_message_write_string(msg, password);
1001 soup_xmlrpc_message_end_param (msg);
1002 soup_xmlrpc_message_end_call (msg);
1004 irreco_webdb_client_reset_env(self);
1006 response = (SoupXmlrpcResponse*) do_xmlrpc (msg,
1007 SOUP_XMLRPC_VALUE_TYPE_INT, self);
1009 /* Check response exists */
1010 if(!response) {
1011 IRRECO_DEBUG(" No response, failed at do_xmlrpc\n");
1012 IRRECO_RETURN_BOOL(FALSE);
1015 value = soup_xmlrpc_response_get_value (response);
1017 /* Try to get integer out of value */
1018 if(soup_xmlrpc_value_get_int(value, (glong *) &theme_id)){
1019 g_object_unref (response);
1020 IRRECO_RETURN_INT(theme_id);
1023 g_string_printf(self->error_msg,
1024 "ERROR: Not proper return value\n");
1025 g_object_unref (response);
1026 IRRECO_RETURN_INT(0);
1029 gboolean irreco_webdb_client_set_theme_downloadable(IrrecoWebdbClient *self,
1030 gint id,
1031 gboolean downloadable,
1032 const gchar *user,
1033 const gchar *password)
1035 SoupXmlrpcMessage *msg;
1036 SoupXmlrpcResponse *response;
1037 SoupXmlrpcValue *value;
1038 gboolean rvalue = FALSE;
1040 IRRECO_ENTER
1041 msg = soup_xmlrpc_message_new (IRRECO_WEBDB_URL);
1042 soup_xmlrpc_message_start_call (msg, "setThemeDownloadable");
1043 soup_xmlrpc_message_start_param (msg);
1044 soup_xmlrpc_message_write_int(msg, id);
1045 soup_xmlrpc_message_write_boolean(msg, downloadable);
1046 soup_xmlrpc_message_write_string(msg, user);
1047 soup_xmlrpc_message_write_string(msg, password);
1048 soup_xmlrpc_message_end_param (msg);
1049 soup_xmlrpc_message_end_call (msg);
1051 irreco_webdb_client_reset_env(self);
1053 response = (SoupXmlrpcResponse*) do_xmlrpc (msg,
1054 SOUP_XMLRPC_VALUE_TYPE_BOOLEAN, self);
1056 /* Check response exists */
1057 if(!response) {
1058 IRRECO_DEBUG(" No response, failed at do_xmlrpc\n");
1059 IRRECO_RETURN_BOOL(FALSE);
1062 value = soup_xmlrpc_response_get_value (response);
1064 /* Try to get boolean out of value */
1065 soup_xmlrpc_value_get_boolean(value, &rvalue);
1067 g_object_unref (response);
1068 IRRECO_RETURN_BOOL(rvalue);
1071 gboolean irreco_webdb_client_get_themes(IrrecoWebdbClient *self,
1072 IrrecoStringTable **theme_list)
1074 gboolean rvalue = FALSE;
1075 SoupXmlrpcMessage *msg;
1076 SoupXmlrpcResponse *response;
1077 SoupXmlrpcValueArrayIterator *iter;
1078 SoupXmlrpcValue *value;
1079 SoupXmlrpcValue *array_val;
1080 gchar *ret = NULL;
1081 IRRECO_ENTER
1083 irreco_webdb_client_reset_env(self);
1085 *theme_list = irreco_string_table_new(NULL, NULL);
1087 irreco_webdb_client_reset_env(self);
1089 msg = soup_xmlrpc_message_new (IRRECO_WEBDB_URL);
1090 soup_xmlrpc_message_start_call (msg, "getThemes");
1091 soup_xmlrpc_message_end_call (msg);
1093 response = (SoupXmlrpcResponse*) do_xmlrpc (msg,
1094 SOUP_XMLRPC_VALUE_TYPE_ARRAY, self);
1095 if(!response) {
1096 IRRECO_DEBUG(" No response, failed something\n");
1097 IRRECO_RETURN_BOOL(rvalue);
1100 value = soup_xmlrpc_response_get_value (response);
1102 soup_xmlrpc_value_array_get_iterator(value, &iter);
1104 while (iter) {
1105 soup_xmlrpc_value_array_iterator_get_value(iter, &array_val);
1107 if (!soup_xmlrpc_value_get_string(array_val, &ret)) {
1108 IRRECO_DEBUG ("NO value\n");
1109 g_object_unref (response);
1110 IRRECO_RETURN_BOOL(rvalue);
1112 IRRECO_DEBUG("%s\n", ret);
1114 irreco_string_table_add(*theme_list, ret, NULL);
1116 iter = soup_xmlrpc_value_array_iterator_next(iter);
1119 rvalue = TRUE;
1121 IRRECO_RETURN_BOOL(rvalue);
1124 gboolean irreco_webdb_client_get_theme_by_id(IrrecoWebdbClient *self,
1125 gint theme_id,
1126 IrrecoWebdbTheme **theme)
1128 gboolean rvalue = FALSE;
1129 gchar *name = NULL;
1130 gchar *user = NULL;
1131 gchar *comment = NULL;
1132 gchar *preview_button = NULL;
1133 gchar *folder = NULL;
1134 gchar *uploaded = NULL;
1135 gchar *modified = NULL;
1136 gchar *downloaded = NULL;
1137 gint download_count;
1138 GHashTable *tmp = NULL;
1139 SoupXmlrpcValue *hash = NULL;
1140 SoupXmlrpcMessage *msg;
1141 SoupXmlrpcResponse *response = NULL;
1142 SoupXmlrpcValue *value;
1143 IRRECO_ENTER
1145 irreco_webdb_client_reset_env(self);
1147 /* Build query */
1148 msg = soup_xmlrpc_message_new (IRRECO_WEBDB_URL);
1149 soup_xmlrpc_message_start_call (msg, "getThemeById");
1150 soup_xmlrpc_message_start_param (msg);
1151 soup_xmlrpc_message_write_int(msg, (glong) theme_id);
1152 soup_xmlrpc_message_end_param (msg);
1153 soup_xmlrpc_message_end_call (msg);
1155 /* Execute XML-RPC call. */
1156 response = (SoupXmlrpcResponse*) do_xmlrpc (msg,
1157 SOUP_XMLRPC_VALUE_TYPE_STRUCT, self);
1159 /* Check response */
1160 if(!response) {
1161 IRRECO_DEBUG(" No response, failed something\n");
1162 goto end;
1165 /* Get array out from response */
1166 value = soup_xmlrpc_response_get_value (response);
1168 if(!soup_xmlrpc_value_get_struct(value, &tmp)){
1169 g_string_printf(self->error_msg,
1170 "ERROR: Not proper return value\n");
1171 goto end;
1174 /* Seek data */
1175 hash = g_hash_table_lookup(tmp, "name");
1176 if (!soup_xmlrpc_value_get_string(hash, &name)) {
1177 IRRECO_DEBUG("No value in response\n");
1178 goto end;
1181 hash = g_hash_table_lookup(tmp, "user");
1182 if (!soup_xmlrpc_value_get_string(hash, &user)) {
1183 IRRECO_DEBUG("No value in response\n");
1184 goto end;
1187 hash = g_hash_table_lookup(tmp, "comment");
1188 if (!soup_xmlrpc_value_get_string(hash, &comment)) {
1189 IRRECO_DEBUG("No value in response\n");
1190 goto end;
1193 hash = g_hash_table_lookup(tmp, "preview_button");
1194 if (!soup_xmlrpc_value_get_string(hash, &preview_button)) {
1195 IRRECO_DEBUG("No value in response\n");
1196 goto end;
1199 hash = g_hash_table_lookup(tmp, "folder");
1200 if (!soup_xmlrpc_value_get_string(hash, &folder)) {
1201 IRRECO_DEBUG("No value in response\n");
1202 goto end;
1205 hash = g_hash_table_lookup(tmp, "uploaded");
1206 if (!soup_xmlrpc_value_get_string(hash, &uploaded)) {
1207 IRRECO_DEBUG("No value in response\n");
1208 goto end;
1211 hash = g_hash_table_lookup(tmp, "modified");
1212 if (!soup_xmlrpc_value_get_string(hash, &modified)) {
1213 IRRECO_DEBUG("No value in response\n");
1214 goto end;
1217 hash = g_hash_table_lookup(tmp, "downloaded");
1218 if (!soup_xmlrpc_value_get_string(hash, &downloaded)) {
1219 IRRECO_DEBUG("No value in response\n");
1220 goto end;
1223 hash = g_hash_table_lookup(tmp, "download_count");
1224 if (!soup_xmlrpc_value_get_int(hash, (glong *) &download_count)) {
1225 IRRECO_DEBUG("No value in response\n");
1226 goto end;
1229 *theme = irreco_webdb_theme_new();
1231 irreco_webdb_theme_set(*theme, theme_id, name, user, comment,
1232 preview_button, NULL, folder, uploaded, modified,
1233 downloaded, download_count);
1235 irreco_webdb_client_get_theme_versions_by_name(self, name,
1236 &(*theme)->versions);
1238 /* Get dates for versions */
1239 if ((*theme)->versions != NULL)
1241 IRRECO_STRING_TABLE_FOREACH_KEY((*theme)->versions, key)
1242 gchar *date = irreco_webdb_client_get_theme_date_by_id(
1243 self, atoi(key));
1245 irreco_string_table_change_data ((*theme)->versions,
1246 key, (gpointer) date);
1247 IRRECO_STRING_TABLE_FOREACH_END
1250 /* No error occured. */
1251 rvalue = TRUE;
1253 end:
1254 if (response != NULL) g_object_unref(response);
1255 if (tmp != NULL) g_hash_table_destroy(tmp);
1256 if (name != NULL) g_free(name);
1257 if (user != NULL) g_free(user);
1258 if (comment != NULL) g_free(comment);
1259 if (preview_button != NULL) g_free(preview_button);
1260 if (folder != NULL) g_free(folder);
1261 if (uploaded != NULL) g_free(uploaded);
1262 if (modified != NULL) g_free(modified);
1263 if (downloaded != NULL) g_free(downloaded);
1265 IRRECO_RETURN_BOOL(rvalue);
1268 gboolean irreco_webdb_client_get_theme_versions_by_name(IrrecoWebdbClient *self,
1269 const char *name,
1270 IrrecoStringTable **theme_list)
1272 gboolean rvalue = FALSE;
1273 SoupXmlrpcMessage *msg;
1274 SoupXmlrpcResponse *response;
1275 SoupXmlrpcValueArrayIterator *iter;
1276 SoupXmlrpcValue *value;
1277 SoupXmlrpcValue *array_val;
1278 gchar *ret = NULL;
1279 IRRECO_ENTER
1281 irreco_webdb_client_reset_env(self);
1283 *theme_list = irreco_string_table_new(NULL, NULL);
1285 irreco_webdb_client_reset_env(self);
1287 msg = soup_xmlrpc_message_new (IRRECO_WEBDB_URL);
1288 soup_xmlrpc_message_start_call (msg, "getThemeVersionsByName");
1289 soup_xmlrpc_message_start_param (msg);
1290 soup_xmlrpc_message_write_string(msg, name);
1291 soup_xmlrpc_message_end_param (msg);
1292 soup_xmlrpc_message_end_call (msg);
1294 response = (SoupXmlrpcResponse*) do_xmlrpc (msg,
1295 SOUP_XMLRPC_VALUE_TYPE_ARRAY, self);
1296 if(!response) {
1297 IRRECO_DEBUG(" No response, failed something\n");
1298 goto end;
1301 value = soup_xmlrpc_response_get_value (response);
1303 soup_xmlrpc_value_array_get_iterator(value, &iter);
1305 while (iter) {
1306 soup_xmlrpc_value_array_iterator_get_value(iter, &array_val);
1308 if (!soup_xmlrpc_value_get_string(array_val, &ret)) {
1309 IRRECO_DEBUG ("NO value\n");
1310 goto end;
1312 IRRECO_DEBUG("%s\n", ret);
1314 irreco_string_table_add(*theme_list, ret, NULL);
1316 iter = soup_xmlrpc_value_array_iterator_next(iter);
1319 rvalue = TRUE;
1321 end:
1322 if (rvalue == FALSE) irreco_string_table_free(*theme_list);
1323 g_object_unref (response);
1325 IRRECO_RETURN_BOOL(rvalue);
1328 gchar *irreco_webdb_client_get_theme_date_by_id(IrrecoWebdbClient *self,
1329 gint theme_id)
1331 SoupXmlrpcMessage *msg;
1332 SoupXmlrpcResponse *response;
1333 SoupXmlrpcValue *value;
1334 gchar *date = NULL;
1336 IRRECO_ENTER
1338 msg = soup_xmlrpc_message_new (IRRECO_WEBDB_URL);
1339 soup_xmlrpc_message_start_call (msg, "getThemeDateById");
1340 soup_xmlrpc_message_start_param (msg);
1341 soup_xmlrpc_message_write_int(msg, theme_id);
1342 soup_xmlrpc_message_end_param (msg);
1343 soup_xmlrpc_message_end_call (msg);
1345 irreco_webdb_client_reset_env(self);
1347 response = (SoupXmlrpcResponse*)do_xmlrpc(msg,
1348 SOUP_XMLRPC_VALUE_TYPE_STRING,
1349 self);
1351 /* Check response exists */
1352 if(!response) {
1353 IRRECO_DEBUG(" No response, failed at do_xmlrpc\n");
1354 goto end;
1357 value = soup_xmlrpc_response_get_value (response);
1359 /* Try to get integer out of value */
1360 if(!soup_xmlrpc_value_get_string(value, &date)) {
1361 date = NULL;
1364 end:
1365 g_object_unref (response);
1366 IRRECO_RETURN_PTR(date);
1369 gint irreco_webdb_client_get_theme_id_by_name_and_date(IrrecoWebdbClient *self,
1370 const gchar *name,
1371 const gchar *date)
1373 SoupXmlrpcMessage *msg;
1374 SoupXmlrpcResponse *response;
1375 SoupXmlrpcValue *value;
1376 gint id = 0;
1378 IRRECO_ENTER
1380 msg = soup_xmlrpc_message_new (IRRECO_WEBDB_URL);
1381 soup_xmlrpc_message_start_call (msg, "getThemeIdByNameAndDate");
1382 soup_xmlrpc_message_start_param (msg);
1383 soup_xmlrpc_message_write_string(msg, name);
1384 soup_xmlrpc_message_write_string(msg, date);
1385 soup_xmlrpc_message_end_param (msg);
1386 soup_xmlrpc_message_end_call (msg);
1388 irreco_webdb_client_reset_env(self);
1390 response = (SoupXmlrpcResponse*)do_xmlrpc(msg,
1391 SOUP_XMLRPC_VALUE_TYPE_INT,
1392 self);
1394 /* Check response exists */
1395 if(!response) {
1396 IRRECO_DEBUG(" No response, failed at do_xmlrpc\n");
1397 goto end;
1400 value = soup_xmlrpc_response_get_value(response);
1402 /* Try to get integer out of value */
1403 if(!soup_xmlrpc_value_get_int(value, (glong *) &id)) {
1404 id = 0;
1407 end:
1408 g_object_unref (response);
1409 IRRECO_RETURN_INT(id);
1412 gint irreco_webdb_client_add_bg_to_theme(IrrecoWebdbClient *self,
1413 const gchar *name,
1414 const gchar *image_hash,
1415 const gchar *image_name,
1416 const guchar *image,
1417 gint image_len,
1418 const gchar *folder,
1419 gint theme_id,
1420 const gchar *user,
1421 const gchar *password)
1423 SoupXmlrpcMessage *msg;
1424 SoupXmlrpcResponse *response;
1425 SoupXmlrpcValue *value;
1426 gint bg_id;
1427 gchar *base64_image;
1428 IRRECO_ENTER
1430 base64_image = g_base64_encode(image, image_len);
1432 msg = soup_xmlrpc_message_new (IRRECO_WEBDB_URL);
1433 soup_xmlrpc_message_start_call (msg, "addBgToTheme");
1434 soup_xmlrpc_message_start_param (msg);
1435 soup_xmlrpc_message_write_string(msg, name);
1436 soup_xmlrpc_message_write_string(msg, image_hash);
1437 soup_xmlrpc_message_write_string(msg, image_name);
1438 soup_xmlrpc_message_write_string(msg, base64_image);
1439 soup_xmlrpc_message_write_string(msg, folder);
1440 soup_xmlrpc_message_write_int(msg, theme_id);
1441 soup_xmlrpc_message_write_string(msg, user);
1442 soup_xmlrpc_message_write_string(msg, password);
1443 soup_xmlrpc_message_end_param (msg);
1444 soup_xmlrpc_message_end_call (msg);
1446 g_free(base64_image);
1448 irreco_webdb_client_reset_env(self);
1450 response = (SoupXmlrpcResponse*) do_xmlrpc (msg,
1451 SOUP_XMLRPC_VALUE_TYPE_INT, self);
1453 /* Check response exists */
1454 if(!response) {
1455 IRRECO_DEBUG(" No response, failed at do_xmlrpc\n");
1456 IRRECO_RETURN_BOOL(FALSE);
1459 value = soup_xmlrpc_response_get_value (response);
1461 /* Try to get integer out of value */
1462 if(soup_xmlrpc_value_get_int(value, (glong *) &bg_id)){
1463 g_object_unref (response);
1464 IRRECO_RETURN_INT(bg_id);
1467 g_string_printf(self->error_msg,
1468 "ERROR: Not proper return value\n");
1469 g_object_unref (response);
1470 IRRECO_RETURN_INT(0);
1473 gboolean irreco_webdb_client_get_backgrounds(IrrecoWebdbClient *self,
1474 gint theme_id,
1475 IrrecoStringTable **bg_list)
1477 gboolean rvalue = FALSE;
1478 SoupXmlrpcMessage *msg;
1479 SoupXmlrpcResponse *response;
1480 SoupXmlrpcValueArrayIterator *iter;
1481 SoupXmlrpcValue *value;
1482 SoupXmlrpcValue *array_val;
1483 gint ret;
1484 IRRECO_ENTER
1486 irreco_webdb_client_reset_env(self);
1488 *bg_list = irreco_string_table_new(NULL, NULL);
1490 irreco_webdb_client_reset_env(self);
1492 msg = soup_xmlrpc_message_new (IRRECO_WEBDB_URL);
1493 soup_xmlrpc_message_start_call (msg, "getBackgrounds");
1494 soup_xmlrpc_message_start_param (msg);
1495 soup_xmlrpc_message_write_int(msg, theme_id);
1496 soup_xmlrpc_message_end_param (msg);
1497 soup_xmlrpc_message_end_call (msg);
1499 response = (SoupXmlrpcResponse*) do_xmlrpc (msg,
1500 SOUP_XMLRPC_VALUE_TYPE_ARRAY, self);
1501 if(!response) {
1502 IRRECO_DEBUG(" No response, failed something\n");
1503 IRRECO_RETURN_BOOL(rvalue);
1506 value = soup_xmlrpc_response_get_value (response);
1508 soup_xmlrpc_value_array_get_iterator(value, &iter);
1510 while (iter) {
1511 gchar *id;
1512 soup_xmlrpc_value_array_iterator_get_value(iter, &array_val);
1514 if (!soup_xmlrpc_value_get_int(array_val, (glong *)&ret)) {
1515 IRRECO_DEBUG ("NO value\n");
1516 goto end;
1518 IRRECO_DEBUG("%d\n", ret);
1520 id = g_strdup_printf ("%d", ret);
1522 irreco_string_table_add(*bg_list, id, NULL);
1523 g_free(id);
1525 iter = soup_xmlrpc_value_array_iterator_next(iter);
1528 rvalue = TRUE;
1529 end:
1530 if(rvalue == FALSE) {
1531 irreco_string_table_free (*bg_list);
1532 *bg_list = NULL;
1534 g_object_unref (response);
1536 IRRECO_RETURN_BOOL(rvalue);
1540 gboolean irreco_webdb_client_get_bg_by_id(IrrecoWebdbClient *self,
1541 gint bg_id,
1542 const char *theme_bg_dir)
1544 gboolean rvalue = FALSE;
1545 gchar *name = NULL;
1546 gchar *image_hash = NULL;
1547 gchar *image_name = NULL;
1548 gchar *image_data = NULL;
1549 gchar *base64_image = NULL;
1550 gchar *folder = NULL;
1551 GHashTable *tmp = NULL;
1552 SoupXmlrpcValue *hash = NULL;
1553 SoupXmlrpcMessage *msg;
1554 SoupXmlrpcResponse *response;
1555 SoupXmlrpcValue *value;
1556 GString *keyfile_path = g_string_new(theme_bg_dir);
1557 GString *image_path = g_string_new(theme_bg_dir);
1558 GKeyFile *keyfile = g_key_file_new();
1559 gsize base64_len;
1560 IRRECO_ENTER
1562 irreco_webdb_client_reset_env(self);
1564 /* Build query */
1565 msg = soup_xmlrpc_message_new (IRRECO_WEBDB_URL);
1566 soup_xmlrpc_message_start_call (msg, "getBgById");
1567 soup_xmlrpc_message_start_param (msg);
1568 soup_xmlrpc_message_write_int(msg, (glong) bg_id);
1569 soup_xmlrpc_message_end_param (msg);
1570 soup_xmlrpc_message_end_call (msg);
1572 /* Execute XML-RPC call. */
1573 response = (SoupXmlrpcResponse*) do_xmlrpc (msg,
1574 SOUP_XMLRPC_VALUE_TYPE_STRUCT, self);
1576 /* Check response */
1577 if(!response) {
1578 IRRECO_DEBUG(" No response, failed something\n");
1579 goto end;
1582 /* Get array out from response */
1583 value = soup_xmlrpc_response_get_value (response);
1585 if(!soup_xmlrpc_value_get_struct(value, &tmp)){
1586 g_string_printf(self->error_msg,
1587 "ERROR: Not proper return value\n");
1588 goto end;
1591 /* Seek data */
1592 hash = g_hash_table_lookup(tmp, "name");
1593 if (!soup_xmlrpc_value_get_string(hash, &name)) {
1594 IRRECO_DEBUG("No value in response\n");
1595 goto end;
1598 hash = g_hash_table_lookup(tmp, "image_hash");
1599 if (!soup_xmlrpc_value_get_string(hash, &image_hash)) {
1600 IRRECO_DEBUG("No value in response\n");
1601 goto end;
1604 hash = g_hash_table_lookup(tmp, "image_name");
1605 if (!soup_xmlrpc_value_get_string(hash, &image_name)) {
1606 IRRECO_DEBUG("No value in response\n");
1607 goto end;
1610 hash = g_hash_table_lookup(tmp, "image_data");
1611 if (!soup_xmlrpc_value_get_string(hash, &base64_image)) {
1612 IRRECO_DEBUG("No value in response\n");
1613 goto end;
1616 hash = g_hash_table_lookup(tmp, "folder");
1617 if (!soup_xmlrpc_value_get_string(hash, &folder)) {
1618 IRRECO_DEBUG("No value in response\n");
1619 goto end;
1622 /* Create Folder */
1623 g_string_append_printf(image_path, "/%s", folder);
1624 IRRECO_DEBUG("mkdir %s\n",image_path->str);
1625 g_mkdir(image_path->str, 0777);
1627 /* Save image to folder */
1628 image_data = (gchar*) g_base64_decode(base64_image, &base64_len);
1629 g_string_append_printf(image_path, "/%s", image_name);
1630 irreco_write_file(image_path->str, image_data, base64_len);
1632 /* Create keyfile and save it to folder*/
1633 irreco_gkeyfile_set_string(keyfile, "theme-bg" , "name", name);
1634 irreco_gkeyfile_set_string(keyfile, "theme-bg", "image", image_name);
1635 g_string_append_printf(keyfile_path, "/%s/bg.conf", folder);
1636 irreco_write_keyfile(keyfile, keyfile_path->str);
1638 /* No error occured. */
1639 rvalue = TRUE;
1641 end:
1642 g_object_unref (response);
1643 if (tmp != NULL) g_hash_table_destroy (tmp);
1644 if (name != NULL) g_free(name);
1645 if (image_hash != NULL) g_free(image_hash);
1646 if (image_name != NULL) g_free(image_name);
1647 if (image_data != NULL) g_free(image_data);
1648 if (base64_image != NULL) g_free(base64_image);
1649 if (folder != NULL) g_free(folder);
1651 g_key_file_free(keyfile);
1652 g_string_free(keyfile_path, TRUE);
1653 g_string_free(image_path, TRUE);
1655 IRRECO_RETURN_BOOL(rvalue);
1658 gint irreco_webdb_client_add_button_to_theme(IrrecoWebdbClient *self,
1659 const gchar *name,
1660 gboolean allow_text,
1661 const gchar *text_format_up,
1662 const gchar *text_format_down,
1663 gint text_padding,
1664 gfloat text_h_align,
1665 gfloat text_v_align,
1666 const gchar *image_up_hash,
1667 const gchar *image_up_name,
1668 const guchar *image_up,
1669 gint image_up_len,
1670 const gchar *image_down_hash,
1671 const gchar *image_down_name,
1672 const guchar *image_down,
1673 gint image_down_len,
1674 const gchar *folder,
1675 gint theme_id,
1676 const gchar *user,
1677 const gchar *password)
1679 SoupXmlrpcMessage *msg;
1680 SoupXmlrpcResponse *response;
1681 SoupXmlrpcValue *value;
1682 gint button_id;
1683 gchar *base64_image_up;
1684 gchar *base64_image_down;
1685 IRRECO_ENTER
1687 base64_image_up = g_base64_encode(image_up, image_up_len);
1688 base64_image_down = g_base64_encode(image_down, image_down_len);
1690 msg = soup_xmlrpc_message_new (IRRECO_WEBDB_URL);
1691 soup_xmlrpc_message_start_call (msg, "addButtonToTheme");
1692 soup_xmlrpc_message_start_param (msg);
1693 soup_xmlrpc_message_write_string(msg, name);
1694 soup_xmlrpc_message_write_boolean(msg, allow_text);
1695 soup_xmlrpc_message_write_string(msg, text_format_up);
1696 soup_xmlrpc_message_write_string(msg, text_format_down);
1697 soup_xmlrpc_message_write_int(msg, text_padding);
1698 soup_xmlrpc_message_write_double(msg, (gdouble)text_h_align);
1699 soup_xmlrpc_message_write_double(msg, (gdouble)text_v_align);
1700 soup_xmlrpc_message_write_string(msg, image_up_hash);
1701 soup_xmlrpc_message_write_string(msg, image_up_name);
1702 soup_xmlrpc_message_write_string(msg, base64_image_up);
1703 soup_xmlrpc_message_write_string(msg, image_down_hash);
1704 soup_xmlrpc_message_write_string(msg, image_down_name);
1705 soup_xmlrpc_message_write_string(msg, base64_image_down);
1706 soup_xmlrpc_message_write_string(msg, folder);
1707 soup_xmlrpc_message_write_int(msg, theme_id);
1708 soup_xmlrpc_message_write_string(msg, user);
1709 soup_xmlrpc_message_write_string(msg, password);
1710 soup_xmlrpc_message_end_param (msg);
1711 soup_xmlrpc_message_end_call (msg);
1713 g_free(base64_image_up);
1714 g_free(base64_image_down);
1716 irreco_webdb_client_reset_env(self);
1718 response = (SoupXmlrpcResponse*) do_xmlrpc (msg,
1719 SOUP_XMLRPC_VALUE_TYPE_INT, self);
1721 /* Check response exists */
1722 if(!response) {
1723 IRRECO_DEBUG(" No response, failed at do_xmlrpc\n");
1724 IRRECO_RETURN_BOOL(FALSE);
1727 value = soup_xmlrpc_response_get_value (response);
1729 /* Try to get integer out of value */
1730 if(soup_xmlrpc_value_get_int(value, (glong *) &button_id)){
1731 g_object_unref (response);
1732 IRRECO_RETURN_INT(button_id);
1735 g_string_printf(self->error_msg,
1736 "ERROR: Not proper return value\n");
1737 g_object_unref (response);
1738 IRRECO_RETURN_INT(0);
1741 gboolean irreco_webdb_client_get_buttons(IrrecoWebdbClient *self,
1742 gint theme_id,
1743 IrrecoStringTable **button_list)
1745 gboolean rvalue = FALSE;
1746 SoupXmlrpcMessage *msg;
1747 SoupXmlrpcResponse *response;
1748 SoupXmlrpcValueArrayIterator *iter;
1749 SoupXmlrpcValue *value;
1750 SoupXmlrpcValue *array_val;
1751 gint ret;
1752 IRRECO_ENTER
1754 irreco_webdb_client_reset_env(self);
1756 *button_list = irreco_string_table_new(NULL, NULL);
1758 irreco_webdb_client_reset_env(self);
1760 msg = soup_xmlrpc_message_new (IRRECO_WEBDB_URL);
1761 soup_xmlrpc_message_start_call (msg, "getButtons");
1762 soup_xmlrpc_message_start_param (msg);
1763 soup_xmlrpc_message_write_int(msg, theme_id);
1764 soup_xmlrpc_message_end_param (msg);
1765 soup_xmlrpc_message_end_call (msg);
1767 response = (SoupXmlrpcResponse*) do_xmlrpc (msg,
1768 SOUP_XMLRPC_VALUE_TYPE_ARRAY, self);
1769 if(!response) {
1770 IRRECO_DEBUG(" No response, failed something\n");
1771 IRRECO_RETURN_BOOL(rvalue);
1774 value = soup_xmlrpc_response_get_value (response);
1776 soup_xmlrpc_value_array_get_iterator(value, &iter);
1778 while (iter) {
1779 gchar *id;
1780 soup_xmlrpc_value_array_iterator_get_value(iter, &array_val);
1782 if (!soup_xmlrpc_value_get_int(array_val, (glong *) &ret)) {
1783 IRRECO_DEBUG ("NO value\n");
1784 goto end;
1786 IRRECO_DEBUG("%d\n", ret);
1788 id = g_strdup_printf("%d", ret);
1789 irreco_string_table_add(*button_list, id, NULL);
1790 g_free(id);
1792 iter = soup_xmlrpc_value_array_iterator_next(iter);
1795 rvalue = TRUE;
1796 end:
1797 if(rvalue == FALSE) {
1798 irreco_string_table_free (*button_list);
1799 *button_list = NULL;
1801 g_object_unref (response);
1803 IRRECO_RETURN_BOOL(rvalue);
1807 gboolean irreco_webdb_client_get_button_by_id(IrrecoWebdbClient *self,
1808 gint button_id,
1809 const char *theme_button_dir)
1811 gboolean rvalue = FALSE;
1812 gchar *name = NULL;
1813 gboolean allow_text = FALSE;
1814 gchar *text_format_up = NULL;
1815 gchar *text_format_down = NULL;
1816 gint text_padding;
1817 gdouble text_h_align;
1818 gdouble text_v_align;
1819 gchar *image_up_hash = NULL;
1820 gchar *image_up_name = NULL;
1821 gchar *image_up = NULL;
1822 gchar *base64_image_up = NULL;
1823 gchar *image_down_hash = NULL;
1824 gchar *image_down_name = NULL;
1825 gchar *image_down = NULL;
1826 gchar *base64_image_down = NULL;
1827 gchar *folder = NULL;
1828 gchar *image_down_hash_tmp = NULL;
1829 GHashTable *tmp = NULL;
1830 SoupXmlrpcValue *hash = NULL;
1831 SoupXmlrpcMessage *msg;
1832 SoupXmlrpcResponse *response;
1833 SoupXmlrpcValue *value;
1834 GString *file_path = g_string_new("");
1835 GKeyFile *keyfile = g_key_file_new();
1836 gsize image_down_len;
1837 gsize image_up_len;
1838 IRRECO_ENTER
1840 irreco_webdb_client_reset_env(self);
1842 /* Build query */
1843 msg = soup_xmlrpc_message_new (IRRECO_WEBDB_URL);
1844 soup_xmlrpc_message_start_call (msg, "getButtonById");
1845 soup_xmlrpc_message_start_param (msg);
1846 soup_xmlrpc_message_write_int(msg, (glong) button_id);
1847 soup_xmlrpc_message_end_param (msg);
1848 soup_xmlrpc_message_end_call (msg);
1850 /* Execute XML-RPC call. */
1851 response = (SoupXmlrpcResponse*) do_xmlrpc (msg,
1852 SOUP_XMLRPC_VALUE_TYPE_STRUCT, self);
1854 /* Check response */
1855 if(!response) {
1856 IRRECO_DEBUG(" No response, failed something\n");
1857 goto end;
1860 /* Get array out from response */
1861 value = soup_xmlrpc_response_get_value (response);
1863 if(!soup_xmlrpc_value_get_struct(value, &tmp)){
1864 g_string_printf(self->error_msg,
1865 "ERROR: Not proper return value\n");
1866 goto end;
1869 /* Seek data */
1870 hash = g_hash_table_lookup(tmp, "name");
1871 if (!soup_xmlrpc_value_get_string(hash, &name)) {
1872 IRRECO_DEBUG("No value in response\n");
1873 goto end;
1876 hash = g_hash_table_lookup(tmp, "allow_text");
1877 if (!soup_xmlrpc_value_get_boolean(hash, &allow_text)) {
1878 IRRECO_DEBUG("No value in response\n");
1879 goto end;
1882 hash = g_hash_table_lookup(tmp, "text_format_up");
1883 soup_xmlrpc_value_get_string(hash, &text_format_up);
1885 hash = g_hash_table_lookup(tmp, "text_format_down");
1886 soup_xmlrpc_value_get_string(hash, &text_format_down);
1888 hash = g_hash_table_lookup(tmp, "text_padding");
1889 if (!soup_xmlrpc_value_get_int(hash, (glong *) &text_padding)) {
1890 IRRECO_DEBUG("No value in response\n");
1891 goto end;
1894 hash = g_hash_table_lookup(tmp, "text_h_align");
1895 if (!soup_xmlrpc_value_get_double(hash, &text_h_align)) {
1896 IRRECO_DEBUG("No value in response\n");
1897 goto end;
1899 hash = g_hash_table_lookup(tmp, "text_v_align");
1900 if (!soup_xmlrpc_value_get_double(hash, &text_v_align)) {
1901 IRRECO_DEBUG("No value in response\n");
1902 goto end;
1905 hash = g_hash_table_lookup(tmp, "image_up_hash");
1906 if (!soup_xmlrpc_value_get_string(hash, &image_up_hash)) {
1907 IRRECO_DEBUG("No value in response\n");
1908 goto end;
1911 hash = g_hash_table_lookup(tmp, "image_up_name");
1912 if (!soup_xmlrpc_value_get_string(hash, &image_up_name)) {
1913 IRRECO_DEBUG("No value in response\n");
1914 goto end;
1917 hash = g_hash_table_lookup(tmp, "image_up");
1918 if (!soup_xmlrpc_value_get_string(hash, &base64_image_up)) {
1919 IRRECO_DEBUG("No value in response\n");
1920 goto end;
1923 hash = g_hash_table_lookup(tmp, "image_down_hash");
1924 if (!soup_xmlrpc_value_get_string(hash, &image_down_hash)) {
1925 IRRECO_DEBUG("No value in response\n");
1926 goto end;
1929 hash = g_hash_table_lookup(tmp, "image_down_name");
1930 if (!soup_xmlrpc_value_get_string(hash, &image_down_name)) {
1931 IRRECO_DEBUG("No value in response\n");
1932 IRRECO_LINE
1933 goto end;
1936 hash = g_hash_table_lookup(tmp, "image_down");
1937 if (!soup_xmlrpc_value_get_string(hash, &base64_image_down)) {
1938 IRRECO_DEBUG("No value in response\n");
1939 goto end;
1942 hash = g_hash_table_lookup(tmp, "folder");
1943 if (!soup_xmlrpc_value_get_string(hash, &folder)) {
1944 IRRECO_DEBUG("No value in response\n");
1945 goto end;
1948 /* Create Folder */
1949 g_string_printf(file_path, "%s/%s", theme_button_dir, folder);
1950 IRRECO_DEBUG("mkdir %s\n",file_path->str);
1951 g_mkdir(file_path->str, 0777);
1953 /* Save image_up to folder */
1954 g_string_printf(file_path, "%s/%s/%s", theme_button_dir, folder,
1955 image_up_name);
1956 image_up = (gchar*) g_base64_decode(base64_image_up, &image_up_len);
1957 irreco_write_file(file_path->str, image_up, image_up_len);
1959 /* Save image_down to folder */
1960 g_string_printf(file_path, "%s/%s/%s", theme_button_dir, folder,
1961 image_down_name);
1963 /*Check image hash data*/
1964 image_down = (gchar*) g_base64_decode(base64_image_down,
1965 &image_down_len);
1966 irreco_write_file(file_path->str, image_down, image_down_len);
1967 image_down_hash_tmp = sha_compute_checksum_for_string(G_CHECKSUM_SHA1,
1968 image_down,
1969 image_down_len);
1971 if (!g_str_equal(image_down_hash, image_down_hash_tmp)) {
1973 g_string_printf(self->error_msg,
1974 "ERROR: Button data is corrupted\n");
1975 goto end;
1978 /* Create keyfile and save it to folder*/
1979 irreco_gkeyfile_set_string(keyfile, "theme-button" , "name", name);
1981 if (allow_text) {
1982 irreco_gkeyfile_set_string(keyfile, "theme-button",
1983 "allow-text", "true");
1984 } else {
1985 irreco_gkeyfile_set_string(keyfile, "theme-button",
1986 "allow-text", "false");
1989 irreco_gkeyfile_set_string(keyfile, "theme-button",
1990 "up", image_up_name);
1992 irreco_gkeyfile_set_string(keyfile, "theme-button",
1993 "down", image_down_name);
1995 if (text_format_up != NULL && strlen(text_format_up) > 0) {
1996 irreco_gkeyfile_set_string(keyfile, "theme-button",
1997 "text-format-up", text_format_up);
2000 if (text_format_down != NULL && strlen(text_format_down) > 0) {
2001 irreco_gkeyfile_set_string(keyfile, "theme-button",
2002 "text-format-down", text_format_down);
2005 irreco_gkeyfile_set_glong(keyfile, "theme-button",
2006 "text-padding", (glong)text_padding);
2008 irreco_gkeyfile_set_gfloat(keyfile,
2009 "theme-button",
2010 "text-h-align",
2011 (gfloat) text_h_align);
2013 irreco_gkeyfile_set_gfloat(keyfile,
2014 "theme-button",
2015 "text-v-align",
2016 (gfloat) text_v_align);
2018 g_string_printf(file_path, "%s/%s/button.conf",
2019 theme_button_dir, folder);
2020 irreco_write_keyfile(keyfile, file_path->str);
2022 /* No error occured. */
2023 rvalue = TRUE;
2025 end:
2027 g_object_unref (response);
2028 if (tmp != NULL) g_hash_table_destroy (tmp);
2029 if (name != NULL) g_free(name);
2030 if (text_format_up != NULL) g_free(text_format_up);
2031 if (text_format_down != NULL) g_free(text_format_down);
2032 if (image_up_hash != NULL) g_free(image_up_hash);
2033 if (image_up_name != NULL) g_free(image_up_name);
2034 if (image_up != NULL) g_free(image_up);
2035 if (base64_image_up != NULL) g_free(base64_image_up);
2036 if (image_down_hash != NULL) g_free(image_down_hash);
2037 if (image_down_name != NULL) g_free(image_down_name);
2038 if (image_down != NULL) g_free(image_down);
2039 if (image_down_hash_tmp != NULL) g_free(image_down_hash_tmp);
2040 if (base64_image_down != NULL) g_free(base64_image_down);
2041 if (folder != NULL) g_free(folder);
2043 g_key_file_free(keyfile);
2044 g_string_free(file_path, TRUE);
2046 IRRECO_RETURN_BOOL(rvalue);
2049 gboolean irreco_webdb_client_get_preview_button(IrrecoWebdbClient *self,
2050 gint theme_id,
2051 GdkPixbuf **preview_button)
2053 gboolean rvalue = FALSE;
2054 SoupXmlrpcMessage *msg;
2055 SoupXmlrpcResponse *response;
2056 SoupXmlrpcValue *value;
2057 char *base64_data = NULL;
2058 guchar *data;
2059 gsize len;
2060 GdkPixbufLoader *pl;
2061 GError *error = NULL;
2062 IRRECO_ENTER
2064 msg = soup_xmlrpc_message_new (IRRECO_WEBDB_URL);
2065 soup_xmlrpc_message_start_call (msg, "getPreviewButton");
2066 soup_xmlrpc_message_start_param (msg);
2067 soup_xmlrpc_message_write_int(msg, theme_id);
2068 soup_xmlrpc_message_end_param (msg);
2069 soup_xmlrpc_message_end_call (msg);
2071 irreco_webdb_client_reset_env(self);
2073 response = (SoupXmlrpcResponse*) do_xmlrpc (msg,
2074 SOUP_XMLRPC_VALUE_TYPE_STRING, self);
2076 /* Check response exists */
2077 if(!response) {
2078 IRRECO_DEBUG(" No response, failed at do_xmlrpc\n");
2079 goto end;
2082 value = soup_xmlrpc_response_get_value (response);
2084 /* Try to get string out of value */
2085 if(!soup_xmlrpc_value_get_string(value, &base64_data)){
2086 g_string_printf(self->error_msg,
2087 "ERROR: Not proper return value\n");
2088 goto end;
2091 data = g_base64_decode(base64_data, &len);
2093 pl = gdk_pixbuf_loader_new();
2095 gdk_pixbuf_loader_write(pl, data, len, &error);
2097 if(error != NULL)
2099 g_string_printf(self->error_msg, "ERROR: %s", error->message);
2100 IRRECO_DEBUG("%s\n", error->message);
2101 goto end;
2104 gdk_pixbuf_loader_close(pl, NULL);
2105 *preview_button = gdk_pixbuf_loader_get_pixbuf(pl);
2107 rvalue = TRUE;
2109 end:
2110 g_object_unref (response);
2111 if (base64_data != NULL) g_free(base64_data);
2113 IRRECO_RETURN_BOOL(rvalue);
2116 static SoupXmlrpcResponse *do_xmlrpc(SoupXmlrpcMessage *xmsg,
2117 SoupXmlrpcValueType type,
2118 IrrecoWebdbClient *self)
2120 SoupSession *session;
2121 int status; /* Status of sent message */
2122 SoupMessage *spmsg = NULL; /* Soupmessage */
2123 SoupXmlrpcResponse *response = NULL; /* Response */
2124 SoupXmlrpcValue *value = NULL; /* Value from response */
2125 gchar *resbodykeeper; /* Tmp response holder */
2126 gboolean error = FALSE;
2128 IRRECO_ENTER
2130 session = soup_session_sync_new(); /* Init new synchronous session */
2132 soup_xmlrpc_message_persist (xmsg); /* Lock message */
2134 spmsg = SOUP_MESSAGE(xmsg); /* soup XMLRPC msg to soup msg */
2136 /* Add irreco version to message header */
2137 soup_message_add_header(spmsg->request_headers,
2138 "User-Agent", PACKAGE_NAME "/" VERSION);
2140 IRRECO_DEBUG("Send soup message\n");
2141 status = soup_session_send_message (session, spmsg); /* Send msg */
2143 soup_session_abort (session); /* Session cleanup */
2145 g_object_unref (session);
2147 /* Print request length and response */
2148 /*IRRECO_DEBUG("\n%.*s\n%d %s\n%.*s\n",
2149 spmsg->request.length, spmsg->request.body,
2150 spmsg->status_code, spmsg->reason_phrase,
2151 spmsg->response.length, spmsg->response.body);*/
2152 IRRECO_DEBUG("\nRequest length: %d\nStatus code: %d %s\n",
2153 spmsg->request.length,
2154 spmsg->status_code, spmsg->reason_phrase);
2156 /* Check status of sent message */
2157 if (g_strrstr(spmsg->response.body, "faultCode") != NULL) {
2159 gchar *errmsg; /* error message */
2160 IRRECO_DEBUG("Found faultCode, parse response\n");
2161 IRRECO_DEBUG("%s\n",spmsg->response.body);
2163 errmsg = g_malloc0(strlen(spmsg->response.body)*sizeof(gchar));
2166 /** @todo
2167 * Error code and message could be combined to be Error: <num> <msg>
2168 * if thats possible to do easily
2170 strcpy(errmsg, "Error code: ");
2172 /* Parse spmsgrspbd to start "<int>" */
2173 spmsg->response.body = g_strrstr(spmsg->response.body, "<int>");
2175 resbodykeeper = g_strdup( spmsg->response.body );
2177 /* Copy part of response to errmsg */
2178 strcpy(&errmsg[12], &resbodykeeper[5]);
2180 /* Calc errorcode length and insert ", Error Message: " */
2181 /* in place of "</int>" */
2182 strcpy(&errmsg[strlen(errmsg)-strlen(g_strrstr(errmsg,
2183 "</int>"))], ", Error Message: ");
2185 /* Cut 'til "<string>" */
2186 resbodykeeper = g_strrstr(resbodykeeper, "<string>");
2188 /* Copy error message from after "<string>" into errmsg */
2189 strcpy(&errmsg[strlen(errmsg)], &resbodykeeper[8]);
2191 /* Cut "</string>" and everything after it */
2192 strcpy(&errmsg[strlen(errmsg)-strlen(g_strrstr(errmsg, "</string>"))], "");
2194 /* Parsed error message to right variable */
2195 g_string_printf(self->error_msg, "%s\n", errmsg);
2197 /* Free errmsg resource */
2198 g_free(errmsg);
2199 errmsg = NULL;
2201 error = TRUE;
2202 goto cleanup;
2204 IRRECO_LINE
2205 /* Handle http failures, eg. 404 */
2206 if (!SOUP_STATUS_IS_SUCCESSFUL (status)) {
2207 IRRECO_DEBUG("HTTP failure\n");
2208 g_string_printf(self->error_msg, "%d %s\n",
2209 status, spmsg->reason_phrase);
2211 error = TRUE;
2212 goto cleanup;
2215 /* Parse response */
2216 response = soup_xmlrpc_response_new();
2217 response = soup_xmlrpc_message_parse_response (xmsg);
2219 /* Handle fault responses */
2220 if (!response) {
2221 IRRECO_DEBUG("ERROR: no response\n");
2222 g_string_printf(self->error_msg, "ERROR: no response\n");
2223 error = TRUE;
2224 goto cleanup;
2227 if (soup_xmlrpc_response_is_fault (response)) {
2228 IRRECO_DEBUG("ERROR: response is fault\n");
2229 g_string_printf(self->error_msg, "ERROR: response is fault\n");
2230 error = TRUE;
2231 goto cleanup;
2234 /* Get value(s) from response */
2235 value = soup_xmlrpc_response_get_value(response);
2237 /* Handle wrong type and no value situations */
2238 if (!value) {
2239 IRRECO_DEBUG("ERROR: no value\n");
2240 g_string_printf(self->error_msg, "ERROR: no value\n");
2241 error = TRUE;
2242 goto cleanup;
2245 if (soup_xmlrpc_value_get_type (value) != type) {
2246 IRRECO_DEBUG("ERROR: wrong value type\nexpected %s, got %s\n",
2247 value_type[type],
2248 value_type[soup_xmlrpc_value_get_type (value)]);
2250 g_string_printf(self->error_msg,
2251 "ERROR: wrong value type\nexpected %s, got %s\n",
2252 value_type[type],
2253 value_type[soup_xmlrpc_value_get_type (value)]);
2255 error = TRUE;
2256 goto cleanup;
2259 cleanup:
2260 /* Unref soupmessage */
2261 if (spmsg != NULL && !error) {
2262 g_object_unref(spmsg);
2263 spmsg = NULL;
2266 if(error) {
2267 if (response != NULL) g_object_unref(response);
2268 response = NULL;
2271 IRRECO_RETURN_PTR(response);
2274 gboolean irreco_webdb_client_add_user(IrrecoWebdbClient *self,
2275 const gchar *name,
2276 const gchar *email,
2277 const gchar *passwd)
2279 gboolean rvalue = TRUE;
2281 SoupXmlrpcMessage *msg;
2282 SoupXmlrpcResponse *response;
2283 SoupXmlrpcValue *value;
2284 /*gboolean result;*/
2286 IRRECO_ENTER
2288 /* Init msg with URI and other data */
2289 msg = soup_xmlrpc_message_new (IRRECO_WEBDB_URL);
2290 soup_xmlrpc_message_start_call (msg, "addUser");
2292 soup_xmlrpc_message_start_param (msg);
2293 soup_xmlrpc_message_write_string(msg, name);
2294 soup_xmlrpc_message_end_param (msg);
2296 soup_xmlrpc_message_start_param (msg);
2297 soup_xmlrpc_message_write_string(msg, email);
2298 soup_xmlrpc_message_end_param (msg);
2300 soup_xmlrpc_message_start_param (msg);
2301 soup_xmlrpc_message_write_string(msg, passwd);
2302 soup_xmlrpc_message_end_param (msg);
2304 soup_xmlrpc_message_end_call (msg);
2306 /* Reset error params */
2307 irreco_webdb_client_reset_env(self);
2309 /* Execute XML-RPC call. */
2310 response = (SoupXmlrpcResponse*) do_xmlrpc (msg,
2311 SOUP_XMLRPC_VALUE_TYPE_BOOLEAN, self);
2313 /* Check response exists */
2314 if(!response) {
2315 IRRECO_DEBUG(" No response, failed something\n");
2316 IRRECO_RETURN_BOOL(FALSE);
2319 value = soup_xmlrpc_response_get_value (response);
2321 g_object_unref (response);
2323 /* Everything went fine, return TRUE */
2324 IRRECO_RETURN_BOOL(rvalue);
2328 * Login user to WebDB.
2331 gboolean irreco_webdb_client_login(IrrecoWebdbClient *self,
2332 const gchar *user,
2333 const gchar *password)
2335 gboolean rvalue = TRUE;
2336 SoupXmlrpcMessage *msg;
2337 SoupXmlrpcResponse *response;
2338 SoupXmlrpcValue *value;
2339 IRRECO_ENTER
2341 /* Init msg with URI and other data */
2342 msg = soup_xmlrpc_message_new (IRRECO_WEBDB_URL);
2343 soup_xmlrpc_message_start_call (msg, "loginToDB");
2344 soup_xmlrpc_message_start_param (msg);
2345 soup_xmlrpc_message_write_string(msg, user);
2346 soup_xmlrpc_message_end_param (msg);
2347 soup_xmlrpc_message_start_param (msg);
2348 soup_xmlrpc_message_write_string(msg, password);
2349 soup_xmlrpc_message_end_param (msg);
2350 soup_xmlrpc_message_end_call (msg);
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);
2375 #if 0
2379 gboolean irreco_webdb_client_get_category_list(GHashTable **category_list)
2381 gint i;
2382 IRRECO_ENTER
2384 *category_list = NULL;
2386 /* Execute XML-RPC call. */
2387 irreco_webdb_client_reset_env();
2388 self->result = xmlrpc_client_call_server(self->error_env, self->server,
2389 "getCategoryList", "()");
2390 if (!irreco_webdb_client_is_ok()) IRRECO_RETURN_BOOL(FALSE);
2392 /* Get structure size. */
2393 i = xmlrpc_struct_size(self->error_env, self->result);
2394 if (!irreco_webdb_client_is_ok()) IRRECO_RETURN_BOOL(FALSE);
2396 /* Create hashtable. */
2397 *category_list = g_hash_table_new_full(g_int_hash, g_int_equal,
2398 NULL, g_free);
2400 /* Parse structure. */
2401 while (i--) {
2402 xmlrpc_value *xml_key;
2403 xmlrpc_value *xml_value;
2404 const gchar * str_key;
2405 const gchar * str_value;
2407 xmlrpc_struct_read_member(self->error_env, self->result, i,
2408 &xml_key, &xml_value);
2409 if (!irreco_webdb_client_is_ok()) goto error;
2411 xmlrpc_read_string(self->error_env, xml_key, &str_key);
2412 if (!irreco_webdb_client_is_ok()) goto error;
2414 xmlrpc_read_string(self->error_env, xml_value, &str_value);
2415 if (!irreco_webdb_client_is_ok()) goto error;
2417 IRRECO_PRINTF("Key: %s, Val: %s\n", str_key, str_value);
2418 /*g_hash_table_add();*/
2420 xmlrpc_DECREF(xml_key);
2421 xmlrpc_DECREF(xml_value);
2424 IRRECO_RETURN_BOOL(TRUE);
2426 error:
2427 g_hash_table_destroy(*category_list);
2428 *category_list = NULL;
2429 IRRECO_RETURN_BOOL(FALSE);
2431 #endif
2433 gint irreco_webdb_client_create_new_remote(IrrecoWebdbClient *self,
2434 const gchar *comment,
2435 const gchar *category,
2436 const gchar *manufacturer,
2437 const gchar *model,
2438 const gchar *file_name,
2439 const gchar *file_data,
2440 const gchar *user,
2441 const gchar *password)
2443 SoupXmlrpcMessage *msg;
2444 SoupXmlrpcResponse *response;
2445 SoupXmlrpcValue *value;
2446 gint remote_id;
2447 gchar *file_hash;
2449 IRRECO_ENTER
2450 file_hash = sha_compute_checksum_for_string(G_CHECKSUM_SHA1,
2451 file_data, -1);
2452 msg = soup_xmlrpc_message_new (IRRECO_WEBDB_URL);
2453 soup_xmlrpc_message_start_call (msg, "createNewRemote");
2454 soup_xmlrpc_message_start_param (msg);
2455 soup_xmlrpc_message_write_string(msg, comment);
2456 soup_xmlrpc_message_write_string(msg, category);
2457 soup_xmlrpc_message_write_string(msg, manufacturer);
2458 soup_xmlrpc_message_write_string(msg, model);
2459 soup_xmlrpc_message_write_string(msg, file_hash);
2460 soup_xmlrpc_message_write_string(msg, file_name);
2461 soup_xmlrpc_message_write_string(msg, file_data);
2462 soup_xmlrpc_message_write_string(msg, user);
2463 soup_xmlrpc_message_write_string(msg, password);
2464 soup_xmlrpc_message_end_param (msg);
2465 soup_xmlrpc_message_end_call (msg);
2467 irreco_webdb_client_reset_env(self);
2469 response = (SoupXmlrpcResponse*) do_xmlrpc (msg,
2470 SOUP_XMLRPC_VALUE_TYPE_INT, self);
2472 /* Check response exists */
2473 if(!response) {
2474 IRRECO_DEBUG(" No response, failed at do_xmlrpc\n");
2475 IRRECO_RETURN_INT(0);
2478 value = soup_xmlrpc_response_get_value (response);
2480 /* Try to get integer out of value */
2481 if(soup_xmlrpc_value_get_int(value, (glong *) &remote_id)){
2482 g_object_unref (response);
2483 IRRECO_RETURN_INT(remote_id);
2486 g_string_printf(self->error_msg, "ERROR: Not proper return value\n");
2487 g_object_unref (response);
2488 IRRECO_RETURN_INT(0);
2491 gboolean irreco_webdb_client_set_remote_downloadable(IrrecoWebdbClient *self,
2492 gint id,
2493 gboolean downloadable,
2494 const gchar *user,
2495 const gchar *password)
2497 SoupXmlrpcMessage *msg;
2498 SoupXmlrpcResponse *response;
2499 SoupXmlrpcValue *value;
2500 gboolean rvalue = FALSE;
2502 IRRECO_ENTER
2503 msg = soup_xmlrpc_message_new (IRRECO_WEBDB_URL);
2504 soup_xmlrpc_message_start_call (msg, "setRemoteDownloadable");
2505 soup_xmlrpc_message_start_param (msg);
2506 soup_xmlrpc_message_write_int(msg, id);
2507 soup_xmlrpc_message_write_boolean(msg, downloadable);
2508 soup_xmlrpc_message_write_string(msg, user);
2509 soup_xmlrpc_message_write_string(msg, password);
2510 soup_xmlrpc_message_end_param (msg);
2511 soup_xmlrpc_message_end_call (msg);
2513 irreco_webdb_client_reset_env(self);
2515 response = (SoupXmlrpcResponse*) do_xmlrpc (msg,
2516 SOUP_XMLRPC_VALUE_TYPE_BOOLEAN, self);
2518 /* Check response exists */
2519 if(!response) {
2520 IRRECO_DEBUG(" No response, failed at do_xmlrpc\n");
2521 IRRECO_RETURN_BOOL(FALSE);
2524 value = soup_xmlrpc_response_get_value (response);
2526 /* Try to get boolean out of value */
2527 soup_xmlrpc_value_get_boolean(value, &rvalue);
2529 g_object_unref (response);
2530 IRRECO_RETURN_BOOL(rvalue);
2533 gboolean irreco_webdb_client_add_configuration_to_remote(
2534 IrrecoWebdbClient *self,
2535 gint remote_id,
2536 gint configuration_id,
2537 const gchar *user,
2538 const gchar *password)
2540 SoupXmlrpcMessage *msg;
2541 SoupXmlrpcResponse *response;
2542 SoupXmlrpcValue *value;
2543 gboolean rvalue = FALSE;
2545 IRRECO_ENTER
2546 msg = soup_xmlrpc_message_new (IRRECO_WEBDB_URL);
2547 soup_xmlrpc_message_start_call (msg, "addConfigurationToRemote");
2548 soup_xmlrpc_message_start_param (msg);
2549 soup_xmlrpc_message_write_int(msg, remote_id);
2550 soup_xmlrpc_message_write_int(msg, configuration_id);
2551 soup_xmlrpc_message_write_string(msg, user);
2552 soup_xmlrpc_message_write_string(msg, password);
2553 soup_xmlrpc_message_end_param (msg);
2554 soup_xmlrpc_message_end_call (msg);
2556 irreco_webdb_client_reset_env(self);
2558 response = (SoupXmlrpcResponse*) do_xmlrpc (msg,
2559 SOUP_XMLRPC_VALUE_TYPE_BOOLEAN, self);
2561 /* Check response exists */
2562 if(!response) {
2563 IRRECO_DEBUG(" No response, failed at do_xmlrpc\n");
2564 IRRECO_RETURN_BOOL(FALSE);
2567 value = soup_xmlrpc_response_get_value (response);
2569 /* Try to get boolean out of value */
2570 soup_xmlrpc_value_get_boolean(value, &rvalue);
2572 g_object_unref (response);
2573 IRRECO_RETURN_BOOL(rvalue);
2576 gboolean irreco_webdb_client_add_theme_to_remote(IrrecoWebdbClient *self,
2577 gint remote_id,
2578 gint theme_id,
2579 const gchar *user,
2580 const gchar *password)
2582 SoupXmlrpcMessage *msg;
2583 SoupXmlrpcResponse *response;
2584 SoupXmlrpcValue *value;
2585 gboolean rvalue = FALSE;
2587 IRRECO_ENTER
2588 msg = soup_xmlrpc_message_new (IRRECO_WEBDB_URL);
2589 soup_xmlrpc_message_start_call (msg, "addThemeToRemote");
2590 soup_xmlrpc_message_start_param (msg);
2591 soup_xmlrpc_message_write_int(msg, remote_id);
2592 soup_xmlrpc_message_write_int(msg, theme_id);
2593 soup_xmlrpc_message_write_string(msg, user);
2594 soup_xmlrpc_message_write_string(msg, password);
2595 soup_xmlrpc_message_end_param (msg);
2596 soup_xmlrpc_message_end_call (msg);
2598 irreco_webdb_client_reset_env(self);
2600 response = (SoupXmlrpcResponse*) do_xmlrpc (msg,
2601 SOUP_XMLRPC_VALUE_TYPE_BOOLEAN, self);
2603 /* Check response exists */
2604 if(!response) {
2605 IRRECO_DEBUG(" No response, failed at do_xmlrpc\n");
2606 IRRECO_RETURN_BOOL(FALSE);
2609 value = soup_xmlrpc_response_get_value (response);
2611 /* Try to get boolean out of value */
2612 soup_xmlrpc_value_get_boolean(value, &rvalue);
2614 g_object_unref (response);
2615 IRRECO_RETURN_BOOL(rvalue);
2618 gboolean irreco_webdb_client_get_remote_categories(IrrecoWebdbClient *self,
2619 IrrecoStringTable **category_list)
2621 gboolean rvalue = FALSE;
2622 SoupXmlrpcMessage *msg;
2623 SoupXmlrpcResponse *response;
2624 SoupXmlrpcValueArrayIterator *iter;
2625 SoupXmlrpcValue *value;
2626 SoupXmlrpcValue *array_val;
2627 gchar *ret = NULL;
2629 IRRECO_ENTER
2631 irreco_webdb_client_reset_env(self);
2633 msg = soup_xmlrpc_message_new (IRRECO_WEBDB_URL);
2634 soup_xmlrpc_message_start_call (msg, "getRemoteCategories");
2635 soup_xmlrpc_message_end_call (msg);
2637 response = (SoupXmlrpcResponse*) do_xmlrpc (msg,
2638 SOUP_XMLRPC_VALUE_TYPE_ARRAY, self);
2639 if(!response) {
2640 IRRECO_DEBUG(" No response, failed something\n");
2641 IRRECO_RETURN_BOOL(rvalue);
2644 value = soup_xmlrpc_response_get_value (response);
2646 soup_xmlrpc_value_array_get_iterator(value, &iter);
2648 *category_list = irreco_string_table_new((GDestroyNotify)
2649 irreco_string_table_free,
2650 NULL);
2651 while (iter) {
2652 soup_xmlrpc_value_array_iterator_get_value(iter, &array_val);
2654 if (!soup_xmlrpc_value_get_string(array_val, &ret)) {
2655 IRRECO_DEBUG ("NO value\n");
2656 g_object_unref (response);
2657 irreco_string_table_free(*category_list);
2658 *category_list = NULL;
2659 IRRECO_RETURN_BOOL(rvalue);
2661 IRRECO_DEBUG("%s\n", ret);
2663 irreco_string_table_add(*category_list, ret, NULL);
2665 iter = soup_xmlrpc_value_array_iterator_next(iter);
2668 rvalue = TRUE;
2669 g_object_unref(response);
2671 IRRECO_RETURN_BOOL(rvalue);
2674 gboolean irreco_webdb_client_get_remote_manufacturers(IrrecoWebdbClient *self,
2675 const gchar *category,
2676 IrrecoStringTable **manufacturer_list)
2678 gboolean rvalue = FALSE;
2679 SoupXmlrpcMessage *msg;
2680 SoupXmlrpcResponse *response;
2681 SoupXmlrpcValueArrayIterator *iter;
2682 SoupXmlrpcValue *value;
2683 SoupXmlrpcValue *array_val;
2684 gchar *ret = NULL;
2686 IRRECO_ENTER
2688 irreco_webdb_client_reset_env(self);
2690 msg = soup_xmlrpc_message_new (IRRECO_WEBDB_URL);
2691 soup_xmlrpc_message_start_call (msg, "getRemoteManufacturers");
2692 soup_xmlrpc_message_start_param (msg);
2693 soup_xmlrpc_message_write_string(msg, category);
2694 soup_xmlrpc_message_end_param (msg);
2695 soup_xmlrpc_message_end_call (msg);
2697 response = (SoupXmlrpcResponse*) do_xmlrpc (msg,
2698 SOUP_XMLRPC_VALUE_TYPE_ARRAY, self);
2699 if(!response) {
2700 IRRECO_DEBUG(" No response, failed something\n");
2701 IRRECO_RETURN_BOOL(rvalue);
2704 value = soup_xmlrpc_response_get_value (response);
2706 soup_xmlrpc_value_array_get_iterator(value, &iter);
2708 *manufacturer_list = irreco_string_table_new((GDestroyNotify)
2709 irreco_string_table_free,
2710 NULL);
2712 while (iter) {
2713 soup_xmlrpc_value_array_iterator_get_value(iter, &array_val);
2715 if (!soup_xmlrpc_value_get_string(array_val, &ret)) {
2716 IRRECO_DEBUG ("NO value\n");
2717 g_object_unref (response);
2718 irreco_string_table_free(*manufacturer_list);
2719 *manufacturer_list = NULL;
2720 IRRECO_RETURN_BOOL(rvalue);
2722 IRRECO_DEBUG("%s\n", ret);
2724 irreco_string_table_add(*manufacturer_list, ret, NULL);
2726 iter = soup_xmlrpc_value_array_iterator_next(iter);
2729 rvalue = TRUE;
2730 g_object_unref(response);
2732 IRRECO_RETURN_BOOL(rvalue);
2735 gboolean irreco_webdb_client_get_remote_models(IrrecoWebdbClient *self,
2736 const gchar *category,
2737 const gchar *manufacturer,
2738 IrrecoStringTable **model_list)
2740 gboolean rvalue = FALSE;
2741 SoupXmlrpcMessage *msg;
2742 SoupXmlrpcResponse *response;
2743 SoupXmlrpcValueArrayIterator *iter;
2744 SoupXmlrpcValue *value;
2745 SoupXmlrpcValue *array_val;
2746 gchar *ret = NULL;
2748 IRRECO_ENTER
2750 irreco_webdb_client_reset_env(self);
2752 msg = soup_xmlrpc_message_new (IRRECO_WEBDB_URL);
2753 soup_xmlrpc_message_start_call (msg, "getRemoteModels");
2754 soup_xmlrpc_message_start_param (msg);
2755 soup_xmlrpc_message_write_string(msg, category);
2756 soup_xmlrpc_message_write_string(msg, manufacturer);
2757 soup_xmlrpc_message_end_param (msg);
2758 soup_xmlrpc_message_end_call (msg);
2760 response = (SoupXmlrpcResponse*) do_xmlrpc (msg,
2761 SOUP_XMLRPC_VALUE_TYPE_ARRAY, self);
2762 if(!response) {
2763 IRRECO_DEBUG(" No response, failed something\n");
2764 IRRECO_RETURN_BOOL(rvalue);
2767 value = soup_xmlrpc_response_get_value (response);
2769 soup_xmlrpc_value_array_get_iterator(value, &iter);
2771 *model_list = irreco_string_table_new((GDestroyNotify)
2772 irreco_string_table_free, NULL);
2773 while (iter) {
2774 soup_xmlrpc_value_array_iterator_get_value(iter, &array_val);
2776 if (!soup_xmlrpc_value_get_string(array_val, &ret)) {
2777 IRRECO_DEBUG ("No value\n");
2778 g_object_unref (response);
2779 irreco_string_table_free(*model_list);
2780 *model_list = NULL;
2781 IRRECO_RETURN_BOOL(rvalue);
2783 IRRECO_DEBUG("%s\n", ret);
2785 irreco_string_table_add(*model_list, ret, NULL);
2787 iter = soup_xmlrpc_value_array_iterator_next(iter);
2790 rvalue = TRUE;
2791 g_object_unref(response);
2793 IRRECO_RETURN_BOOL(rvalue);
2796 gboolean irreco_webdb_client_get_remote_creators(IrrecoWebdbClient *self,
2797 const gchar *category,
2798 const gchar *manufacturer,
2799 const gchar *model,
2800 IrrecoStringTable **creators)
2802 gboolean rvalue = FALSE;
2803 SoupXmlrpcMessage *msg;
2804 SoupXmlrpcResponse *response;
2805 SoupXmlrpcValueArrayIterator *iter;
2806 SoupXmlrpcValue *value;
2807 SoupXmlrpcValue *array_val;
2808 gchar *ret = NULL;
2810 IRRECO_ENTER
2812 irreco_webdb_client_reset_env(self);
2814 msg = soup_xmlrpc_message_new (IRRECO_WEBDB_URL);
2815 soup_xmlrpc_message_start_call (msg, "getRemoteCreators");
2816 soup_xmlrpc_message_start_param (msg);
2817 soup_xmlrpc_message_write_string(msg, category);
2818 soup_xmlrpc_message_write_string(msg, manufacturer);
2819 soup_xmlrpc_message_write_string(msg, model);
2820 soup_xmlrpc_message_end_param (msg);
2821 soup_xmlrpc_message_end_call (msg);
2823 response = (SoupXmlrpcResponse*) do_xmlrpc (msg,
2824 SOUP_XMLRPC_VALUE_TYPE_ARRAY, self);
2825 if(!response) {
2826 IRRECO_DEBUG(" No response, failed something\n");
2827 IRRECO_RETURN_BOOL(rvalue);
2830 value = soup_xmlrpc_response_get_value(response);
2832 soup_xmlrpc_value_array_get_iterator(value, &iter);
2834 *creators = irreco_string_table_new((GDestroyNotify) g_list_free, NULL);
2835 while (iter) {
2836 soup_xmlrpc_value_array_iterator_get_value(iter, &array_val);
2838 if (!soup_xmlrpc_value_get_string(array_val, &ret)) {
2839 IRRECO_DEBUG ("No value\n");
2840 g_object_unref(response);
2841 irreco_string_table_free(*creators);
2842 *creators = NULL;
2843 IRRECO_RETURN_BOOL(rvalue);
2845 IRRECO_DEBUG("%s\n", ret);
2847 irreco_string_table_add(*creators, ret, NULL);
2849 iter = soup_xmlrpc_value_array_iterator_next(iter);
2852 rvalue = TRUE;
2853 g_object_unref(response);
2855 IRRECO_RETURN_BOOL(rvalue);
2858 gboolean irreco_webdb_client_get_remotes(IrrecoWebdbClient *self,
2859 const gchar *category,
2860 const gchar *manufacturer,
2861 const gchar *model,
2862 const gchar *creator,
2863 GList **remote_list)
2865 gboolean rvalue = FALSE;
2866 SoupXmlrpcMessage *msg;
2867 SoupXmlrpcResponse *response;
2868 SoupXmlrpcValueArrayIterator *iter;
2869 SoupXmlrpcValue *value;
2870 SoupXmlrpcValue *array_val;
2871 gint ret;
2873 IRRECO_ENTER
2875 irreco_webdb_client_reset_env(self);
2877 msg = soup_xmlrpc_message_new (IRRECO_WEBDB_URL);
2878 soup_xmlrpc_message_start_call (msg, "getRemotes");
2879 soup_xmlrpc_message_start_param (msg);
2880 soup_xmlrpc_message_write_string(msg, category);
2881 soup_xmlrpc_message_write_string(msg, manufacturer);
2882 soup_xmlrpc_message_write_string(msg, model);
2883 soup_xmlrpc_message_write_string(msg, creator);
2884 soup_xmlrpc_message_end_param (msg);
2885 soup_xmlrpc_message_end_call (msg);
2887 response = (SoupXmlrpcResponse*) do_xmlrpc (msg,
2888 SOUP_XMLRPC_VALUE_TYPE_ARRAY, self);
2889 if(!response) {
2890 IRRECO_DEBUG(" No response, failed something\n");
2891 IRRECO_RETURN_BOOL(rvalue);
2894 value = soup_xmlrpc_response_get_value(response);
2896 soup_xmlrpc_value_array_get_iterator(value, &iter);
2898 *remote_list = NULL;
2899 while (iter) {
2900 soup_xmlrpc_value_array_iterator_get_value(iter, &array_val);
2902 if (!soup_xmlrpc_value_get_int(array_val, (glong *)&ret)) {
2903 IRRECO_DEBUG ("No value\n");
2904 g_object_unref(response);
2905 IRRECO_RETURN_BOOL(rvalue);
2907 IRRECO_DEBUG("%d\n", ret);
2909 *remote_list = g_list_append(*remote_list,
2910 GINT_TO_POINTER(ret));
2912 iter = soup_xmlrpc_value_array_iterator_next(iter);
2915 *remote_list = g_list_first(*remote_list);
2917 rvalue = TRUE;
2918 g_object_unref(response);
2920 IRRECO_RETURN_BOOL(rvalue);
2923 gboolean irreco_webdb_client_get_remote_by_id(IrrecoWebdbClient *self,
2924 gint id,
2925 IrrecoWebdbRemote **remote)
2927 gboolean rvalue = FALSE;
2928 gchar *user = NULL;
2929 gchar *comment = NULL;
2930 gchar *category = NULL;
2931 gchar *manufacturer = NULL;
2932 gchar *model = NULL;
2933 gchar *file_hash = NULL;
2934 gchar *file_name = NULL;
2935 gchar *uploaded = NULL;
2936 gchar *modified = NULL;
2937 gchar *downloaded = NULL;
2938 gint download_count;
2939 SoupXmlrpcMessage *msg = NULL;
2940 SoupXmlrpcResponse *response = NULL;
2941 SoupXmlrpcValue *value = NULL;
2942 GHashTable *tmp = NULL;
2943 SoupXmlrpcValue *hash = NULL;
2945 IRRECO_ENTER
2947 irreco_webdb_client_reset_env(self);
2949 /* Build query */
2950 msg = soup_xmlrpc_message_new (IRRECO_WEBDB_URL);
2951 soup_xmlrpc_message_start_call (msg, "getRemoteById");
2952 soup_xmlrpc_message_start_param (msg);
2953 soup_xmlrpc_message_write_int(msg, (glong) id);
2954 soup_xmlrpc_message_end_param (msg);
2955 soup_xmlrpc_message_end_call (msg);
2957 /* Execute XML-RPC call. */
2958 response = (SoupXmlrpcResponse*) do_xmlrpc (msg,
2959 SOUP_XMLRPC_VALUE_TYPE_STRUCT, self);
2961 /* Check response */
2962 if(!response) {
2963 IRRECO_DEBUG(" No response, failed something\n");
2964 goto end;
2967 /* Get array out from response */
2968 value = soup_xmlrpc_response_get_value (response);
2970 if(!soup_xmlrpc_value_get_struct(value, &tmp)){
2971 g_string_printf(self->error_msg,
2972 "ERROR: Not proper return value\n");
2973 goto end;
2976 /* Seek data */
2977 hash = g_hash_table_lookup (tmp, "user");
2978 if (!soup_xmlrpc_value_get_string(hash, &user)) {
2979 IRRECO_DEBUG("No value in response\n");
2980 goto end;
2983 hash = g_hash_table_lookup (tmp, "comment");
2984 if (!soup_xmlrpc_value_get_string(hash, &comment)) {
2985 IRRECO_DEBUG ("No value in response\n");
2986 goto end;
2989 hash = g_hash_table_lookup (tmp, "category");
2990 if (!soup_xmlrpc_value_get_string(hash, &category)) {
2991 IRRECO_DEBUG ("No value in response\n");
2992 goto end;
2995 hash = g_hash_table_lookup (tmp, "manufacturer");
2996 if (!soup_xmlrpc_value_get_string(hash, &manufacturer)) {
2997 IRRECO_DEBUG ("No value in response\n");
2998 goto end;
3001 hash = g_hash_table_lookup (tmp, "model");
3002 if (!soup_xmlrpc_value_get_string(hash, &model)) {
3003 IRRECO_DEBUG ("No value in response\n");
3004 goto end;
3007 hash = g_hash_table_lookup (tmp, "file_hash");
3008 if (!soup_xmlrpc_value_get_string(hash, &file_hash)) {
3009 IRRECO_DEBUG ("No value in response\n");
3010 goto end;
3013 hash = g_hash_table_lookup (tmp, "file_name");
3014 if (!soup_xmlrpc_value_get_string(hash, &file_name)) {
3015 IRRECO_DEBUG ("No value in response\n");
3016 goto end;
3019 hash = g_hash_table_lookup (tmp, "uploaded");
3020 if (!soup_xmlrpc_value_get_string(hash, &uploaded)) {
3021 IRRECO_DEBUG ("No value in response\n");
3022 goto end;
3025 hash = g_hash_table_lookup (tmp, "modified");
3026 if (!soup_xmlrpc_value_get_string(hash, &modified)) {
3027 IRRECO_DEBUG ("No value in response\n");
3028 goto end;
3031 hash = g_hash_table_lookup (tmp, "downloaded");
3032 if (!soup_xmlrpc_value_get_string(hash, &downloaded)) {
3033 IRRECO_DEBUG ("No value in response\n");
3034 goto end;
3037 hash = g_hash_table_lookup (tmp, "download_count");
3038 if (!soup_xmlrpc_value_get_int(hash, (glong *) &download_count)) {
3039 IRRECO_DEBUG ("No value in response\n");
3040 goto end;
3043 *remote = irreco_webdb_remote_new();
3044 irreco_webdb_remote_set(*remote, id, user, comment, category,
3045 manufacturer, model, file_hash, file_name,
3046 uploaded, modified, downloaded, download_count);
3048 /* No error occured. */
3049 rvalue = TRUE;
3051 end:
3052 if (response != NULL) g_object_unref(response);
3053 if (tmp != NULL) g_hash_table_destroy(tmp);
3054 if (user != NULL) g_free(user);
3055 if (comment != NULL) g_free(comment);
3056 if (category != NULL) g_free(category);
3057 if (manufacturer != NULL) g_free(manufacturer);
3058 if (model != NULL) g_free(model);
3059 if (file_hash != NULL) g_free(file_hash);
3060 if (file_name != NULL) g_free(file_name);
3061 if (uploaded != NULL) g_free(uploaded);
3062 if (modified != NULL) g_free(modified);
3063 if (downloaded != NULL) g_free(downloaded);
3065 IRRECO_RETURN_BOOL(rvalue);
3069 gboolean irreco_webdb_client_get_themes_of_remote(IrrecoWebdbClient *self,
3070 gint remote_id,
3071 GList **themes)
3073 gboolean rvalue = FALSE;
3074 SoupXmlrpcMessage *msg;
3075 SoupXmlrpcResponse *response;
3076 SoupXmlrpcValueArrayIterator *iter;
3077 SoupXmlrpcValue *value;
3078 SoupXmlrpcValue *array_val;
3079 gint ret;
3081 IRRECO_ENTER
3083 irreco_webdb_client_reset_env(self);
3085 msg = soup_xmlrpc_message_new (IRRECO_WEBDB_URL);
3086 soup_xmlrpc_message_start_call (msg, "getThemesOfRemote");
3087 soup_xmlrpc_message_start_param (msg);
3088 soup_xmlrpc_message_write_int(msg, (glong) remote_id);
3089 soup_xmlrpc_message_end_param (msg);
3090 soup_xmlrpc_message_end_call (msg);
3092 response = (SoupXmlrpcResponse*) do_xmlrpc (msg,
3093 SOUP_XMLRPC_VALUE_TYPE_ARRAY, self);
3094 if(!response) {
3095 IRRECO_DEBUG(" No response, failed something\n");
3096 IRRECO_RETURN_BOOL(rvalue);
3099 value = soup_xmlrpc_response_get_value (response);
3101 soup_xmlrpc_value_array_get_iterator(value, &iter);
3103 *themes = NULL;
3104 while (iter) {
3105 soup_xmlrpc_value_array_iterator_get_value(iter, &array_val);
3107 if (!soup_xmlrpc_value_get_int(array_val, (glong *) &ret)) {
3108 IRRECO_DEBUG ("NO value\n");
3109 g_object_unref (response);
3110 IRRECO_RETURN_BOOL(rvalue);
3112 IRRECO_DEBUG("%d\n", ret);
3114 *themes = g_list_append(*themes, GINT_TO_POINTER(ret));
3116 iter = soup_xmlrpc_value_array_iterator_next(iter);
3119 *themes = g_list_first(*themes);
3121 rvalue = TRUE;
3122 g_object_unref (response);
3124 IRRECO_RETURN_BOOL(rvalue);
3128 gboolean irreco_webdb_client_get_configurations_of_remote(
3129 IrrecoWebdbClient *self,
3130 gint remote_id,
3131 GList **configs)
3133 gboolean rvalue = FALSE;
3134 SoupXmlrpcMessage *msg;
3135 SoupXmlrpcResponse *response;
3136 SoupXmlrpcValueArrayIterator *iter;
3137 SoupXmlrpcValue *value;
3138 SoupXmlrpcValue *array_val;
3139 gint ret;
3141 IRRECO_ENTER
3143 irreco_webdb_client_reset_env(self);
3145 msg = soup_xmlrpc_message_new (IRRECO_WEBDB_URL);
3146 soup_xmlrpc_message_start_call (msg, "getConfigurationsOfRemote");
3147 soup_xmlrpc_message_start_param (msg);
3148 soup_xmlrpc_message_write_int(msg, (glong) remote_id);
3149 soup_xmlrpc_message_end_param (msg);
3150 soup_xmlrpc_message_end_call (msg);
3152 response = (SoupXmlrpcResponse*) do_xmlrpc (msg,
3153 SOUP_XMLRPC_VALUE_TYPE_ARRAY, self);
3154 if(!response) {
3155 IRRECO_DEBUG(" No response, failed something\n");
3156 IRRECO_RETURN_BOOL(rvalue);
3159 value = soup_xmlrpc_response_get_value (response);
3161 soup_xmlrpc_value_array_get_iterator(value, &iter);
3163 *configs = NULL;
3164 while (iter) {
3165 soup_xmlrpc_value_array_iterator_get_value(iter, &array_val);
3167 if (!soup_xmlrpc_value_get_int(array_val, (glong *) &ret)) {
3168 IRRECO_DEBUG ("NO value\n");
3169 g_object_unref (response);
3170 IRRECO_RETURN_BOOL(rvalue);
3172 IRRECO_DEBUG("%d\n", ret);
3174 *configs = g_list_append(*configs, GINT_TO_POINTER(ret));
3176 iter = soup_xmlrpc_value_array_iterator_next(iter);
3179 *configs = g_list_first(*configs);
3181 rvalue = TRUE;
3182 g_object_unref (response);
3184 IRRECO_RETURN_BOOL(rvalue);
3187 /** @} */
3190 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
3191 /* Events and Callbacks */
3192 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
3194 /** @} */