Updated TODO comments to use @todo tag.
[irreco.git] / irreco / src / webdb / irreco_webdb_client.c
blob0f514bed68843d5ebb2aa92b945ec5ac19cbdd62
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);
1368 gint irreco_webdb_client_add_bg_to_theme(IrrecoWebdbClient *self,
1369 const gchar *name,
1370 const gchar *image_hash,
1371 const gchar *image_name,
1372 const guchar *image,
1373 gint image_len,
1374 const gchar *folder,
1375 gint theme_id,
1376 const gchar *user,
1377 const gchar *password)
1379 SoupXmlrpcMessage *msg;
1380 SoupXmlrpcResponse *response;
1381 SoupXmlrpcValue *value;
1382 gint bg_id;
1383 gchar *base64_image;
1384 IRRECO_ENTER
1386 base64_image = g_base64_encode(image, image_len);
1388 msg = soup_xmlrpc_message_new (IRRECO_WEBDB_URL);
1389 soup_xmlrpc_message_start_call (msg, "addBgToTheme");
1390 soup_xmlrpc_message_start_param (msg);
1391 soup_xmlrpc_message_write_string(msg, name);
1392 soup_xmlrpc_message_write_string(msg, image_hash);
1393 soup_xmlrpc_message_write_string(msg, image_name);
1394 soup_xmlrpc_message_write_string(msg, base64_image);
1395 soup_xmlrpc_message_write_string(msg, folder);
1396 soup_xmlrpc_message_write_int(msg, theme_id);
1397 soup_xmlrpc_message_write_string(msg, user);
1398 soup_xmlrpc_message_write_string(msg, password);
1399 soup_xmlrpc_message_end_param (msg);
1400 soup_xmlrpc_message_end_call (msg);
1402 g_free(base64_image);
1404 irreco_webdb_client_reset_env(self);
1406 response = (SoupXmlrpcResponse*) do_xmlrpc (msg,
1407 SOUP_XMLRPC_VALUE_TYPE_INT, self);
1409 /* Check response exists */
1410 if(!response) {
1411 IRRECO_DEBUG(" No response, failed at do_xmlrpc\n");
1412 IRRECO_RETURN_BOOL(FALSE);
1415 value = soup_xmlrpc_response_get_value (response);
1417 /* Try to get integer out of value */
1418 if(soup_xmlrpc_value_get_int(value, (glong *) &bg_id)){
1419 g_object_unref (response);
1420 IRRECO_RETURN_INT(bg_id);
1423 g_string_printf(self->error_msg,
1424 "ERROR: Not proper return value\n");
1425 g_object_unref (response);
1426 IRRECO_RETURN_INT(0);
1429 gboolean irreco_webdb_client_get_backgrounds(IrrecoWebdbClient *self,
1430 gint theme_id,
1431 IrrecoStringTable **bg_list)
1433 gboolean rvalue = FALSE;
1434 SoupXmlrpcMessage *msg;
1435 SoupXmlrpcResponse *response;
1436 SoupXmlrpcValueArrayIterator *iter;
1437 SoupXmlrpcValue *value;
1438 SoupXmlrpcValue *array_val;
1439 gint ret;
1440 IRRECO_ENTER
1442 irreco_webdb_client_reset_env(self);
1444 *bg_list = irreco_string_table_new(NULL, NULL);
1446 irreco_webdb_client_reset_env(self);
1448 msg = soup_xmlrpc_message_new (IRRECO_WEBDB_URL);
1449 soup_xmlrpc_message_start_call (msg, "getBackgrounds");
1450 soup_xmlrpc_message_start_param (msg);
1451 soup_xmlrpc_message_write_int(msg, theme_id);
1452 soup_xmlrpc_message_end_param (msg);
1453 soup_xmlrpc_message_end_call (msg);
1455 response = (SoupXmlrpcResponse*) do_xmlrpc (msg,
1456 SOUP_XMLRPC_VALUE_TYPE_ARRAY, self);
1457 if(!response) {
1458 IRRECO_DEBUG(" No response, failed something\n");
1459 IRRECO_RETURN_BOOL(rvalue);
1462 value = soup_xmlrpc_response_get_value (response);
1464 soup_xmlrpc_value_array_get_iterator(value, &iter);
1466 while (iter) {
1467 gchar *id;
1468 soup_xmlrpc_value_array_iterator_get_value(iter, &array_val);
1470 if (!soup_xmlrpc_value_get_int(array_val, (glong *)&ret)) {
1471 IRRECO_DEBUG ("NO value\n");
1472 goto end;
1474 IRRECO_DEBUG("%d\n", ret);
1476 id = g_strdup_printf ("%d", ret);
1478 irreco_string_table_add(*bg_list, id, NULL);
1479 g_free(id);
1481 iter = soup_xmlrpc_value_array_iterator_next(iter);
1484 rvalue = TRUE;
1485 end:
1486 if(rvalue == FALSE) {
1487 irreco_string_table_free (*bg_list);
1488 *bg_list = NULL;
1490 g_object_unref (response);
1492 IRRECO_RETURN_BOOL(rvalue);
1496 gboolean irreco_webdb_client_get_bg_by_id(IrrecoWebdbClient *self,
1497 gint bg_id,
1498 const char *theme_bg_dir)
1500 gboolean rvalue = FALSE;
1501 gchar *name = NULL;
1502 gchar *image_hash = NULL;
1503 gchar *image_name = NULL;
1504 gchar *image_data = NULL;
1505 gchar *base64_image = NULL;
1506 gchar *folder = NULL;
1507 GHashTable *tmp = NULL;
1508 SoupXmlrpcValue *hash = NULL;
1509 SoupXmlrpcMessage *msg;
1510 SoupXmlrpcResponse *response;
1511 SoupXmlrpcValue *value;
1512 GString *keyfile_path = g_string_new(theme_bg_dir);
1513 GString *image_path = g_string_new(theme_bg_dir);
1514 GKeyFile *keyfile = g_key_file_new();
1515 gsize base64_len;
1516 IRRECO_ENTER
1518 irreco_webdb_client_reset_env(self);
1520 /* Build query */
1521 msg = soup_xmlrpc_message_new (IRRECO_WEBDB_URL);
1522 soup_xmlrpc_message_start_call (msg, "getBgById");
1523 soup_xmlrpc_message_start_param (msg);
1524 soup_xmlrpc_message_write_int(msg, (glong) bg_id);
1525 soup_xmlrpc_message_end_param (msg);
1526 soup_xmlrpc_message_end_call (msg);
1528 /* Execute XML-RPC call. */
1529 response = (SoupXmlrpcResponse*) do_xmlrpc (msg,
1530 SOUP_XMLRPC_VALUE_TYPE_STRUCT, self);
1532 /* Check response */
1533 if(!response) {
1534 IRRECO_DEBUG(" No response, failed something\n");
1535 goto end;
1538 /* Get array out from response */
1539 value = soup_xmlrpc_response_get_value (response);
1541 if(!soup_xmlrpc_value_get_struct(value, &tmp)){
1542 g_string_printf(self->error_msg,
1543 "ERROR: Not proper return value\n");
1544 goto end;
1547 /* Seek data */
1548 hash = g_hash_table_lookup(tmp, "name");
1549 if (!soup_xmlrpc_value_get_string(hash, &name)) {
1550 IRRECO_DEBUG("No value in response\n");
1551 goto end;
1554 hash = g_hash_table_lookup(tmp, "image_hash");
1555 if (!soup_xmlrpc_value_get_string(hash, &image_hash)) {
1556 IRRECO_DEBUG("No value in response\n");
1557 goto end;
1560 hash = g_hash_table_lookup(tmp, "image_name");
1561 if (!soup_xmlrpc_value_get_string(hash, &image_name)) {
1562 IRRECO_DEBUG("No value in response\n");
1563 goto end;
1566 hash = g_hash_table_lookup(tmp, "image_data");
1567 if (!soup_xmlrpc_value_get_string(hash, &base64_image)) {
1568 IRRECO_DEBUG("No value in response\n");
1569 goto end;
1572 hash = g_hash_table_lookup(tmp, "folder");
1573 if (!soup_xmlrpc_value_get_string(hash, &folder)) {
1574 IRRECO_DEBUG("No value in response\n");
1575 goto end;
1578 /* Create Folder */
1579 g_string_append_printf(image_path, "/%s", folder);
1580 IRRECO_DEBUG("mkdir %s\n",image_path->str);
1581 g_mkdir(image_path->str, 0777);
1583 /* Save image to folder */
1584 image_data = (gchar*) g_base64_decode(base64_image, &base64_len);
1585 g_string_append_printf(image_path, "/%s", image_name);
1586 irreco_write_file(image_path->str, image_data, base64_len);
1588 /* Create keyfile and save it to folder*/
1589 irreco_gkeyfile_set_string(keyfile, "theme-bg" , "name", name);
1590 irreco_gkeyfile_set_string(keyfile, "theme-bg", "image", image_name);
1591 g_string_append_printf(keyfile_path, "/%s/bg.conf", folder);
1592 irreco_write_keyfile(keyfile, keyfile_path->str);
1594 /* No error occured. */
1595 rvalue = TRUE;
1597 end:
1598 g_object_unref (response);
1599 if (tmp != NULL) g_hash_table_destroy (tmp);
1600 if (name != NULL) g_free(name);
1601 if (image_hash != NULL) g_free(image_hash);
1602 if (image_name != NULL) g_free(image_name);
1603 if (image_data != NULL) g_free(image_data);
1604 if (base64_image != NULL) g_free(base64_image);
1605 if (folder != NULL) g_free(folder);
1607 g_key_file_free(keyfile);
1608 g_string_free(keyfile_path, TRUE);
1609 g_string_free(image_path, TRUE);
1611 IRRECO_RETURN_BOOL(rvalue);
1614 gint irreco_webdb_client_add_button_to_theme(IrrecoWebdbClient *self,
1615 const gchar *name,
1616 gboolean allow_text,
1617 const gchar *text_format_up,
1618 const gchar *text_format_down,
1619 gint text_padding,
1620 gfloat text_h_align,
1621 gfloat text_v_align,
1622 const gchar *image_up_hash,
1623 const gchar *image_up_name,
1624 const guchar *image_up,
1625 gint image_up_len,
1626 const gchar *image_down_hash,
1627 const gchar *image_down_name,
1628 const guchar *image_down,
1629 gint image_down_len,
1630 const gchar *folder,
1631 gint theme_id,
1632 const gchar *user,
1633 const gchar *password)
1635 SoupXmlrpcMessage *msg;
1636 SoupXmlrpcResponse *response;
1637 SoupXmlrpcValue *value;
1638 gint button_id;
1639 gchar *base64_image_up;
1640 gchar *base64_image_down;
1641 IRRECO_ENTER
1643 base64_image_up = g_base64_encode(image_up, image_up_len);
1644 base64_image_down = g_base64_encode(image_down, image_down_len);
1646 msg = soup_xmlrpc_message_new (IRRECO_WEBDB_URL);
1647 soup_xmlrpc_message_start_call (msg, "addButtonToTheme");
1648 soup_xmlrpc_message_start_param (msg);
1649 soup_xmlrpc_message_write_string(msg, name);
1650 soup_xmlrpc_message_write_boolean(msg, allow_text);
1651 soup_xmlrpc_message_write_string(msg, text_format_up);
1652 soup_xmlrpc_message_write_string(msg, text_format_down);
1653 soup_xmlrpc_message_write_int(msg, text_padding);
1654 soup_xmlrpc_message_write_double(msg, (gdouble)text_h_align);
1655 soup_xmlrpc_message_write_double(msg, (gdouble)text_v_align);
1656 soup_xmlrpc_message_write_string(msg, image_up_hash);
1657 soup_xmlrpc_message_write_string(msg, image_up_name);
1658 soup_xmlrpc_message_write_string(msg, base64_image_up);
1659 soup_xmlrpc_message_write_string(msg, image_down_hash);
1660 soup_xmlrpc_message_write_string(msg, image_down_name);
1661 soup_xmlrpc_message_write_string(msg, base64_image_down);
1662 soup_xmlrpc_message_write_string(msg, folder);
1663 soup_xmlrpc_message_write_int(msg, theme_id);
1664 soup_xmlrpc_message_write_string(msg, user);
1665 soup_xmlrpc_message_write_string(msg, password);
1666 soup_xmlrpc_message_end_param (msg);
1667 soup_xmlrpc_message_end_call (msg);
1669 g_free(base64_image_up);
1670 g_free(base64_image_down);
1672 irreco_webdb_client_reset_env(self);
1674 response = (SoupXmlrpcResponse*) do_xmlrpc (msg,
1675 SOUP_XMLRPC_VALUE_TYPE_INT, self);
1677 /* Check response exists */
1678 if(!response) {
1679 IRRECO_DEBUG(" No response, failed at do_xmlrpc\n");
1680 IRRECO_RETURN_BOOL(FALSE);
1683 value = soup_xmlrpc_response_get_value (response);
1685 /* Try to get integer out of value */
1686 if(soup_xmlrpc_value_get_int(value, (glong *) &button_id)){
1687 g_object_unref (response);
1688 IRRECO_RETURN_INT(button_id);
1691 g_string_printf(self->error_msg,
1692 "ERROR: Not proper return value\n");
1693 g_object_unref (response);
1694 IRRECO_RETURN_INT(0);
1697 gboolean irreco_webdb_client_get_buttons(IrrecoWebdbClient *self,
1698 gint theme_id,
1699 IrrecoStringTable **button_list)
1701 gboolean rvalue = FALSE;
1702 SoupXmlrpcMessage *msg;
1703 SoupXmlrpcResponse *response;
1704 SoupXmlrpcValueArrayIterator *iter;
1705 SoupXmlrpcValue *value;
1706 SoupXmlrpcValue *array_val;
1707 gint ret;
1708 IRRECO_ENTER
1710 irreco_webdb_client_reset_env(self);
1712 *button_list = irreco_string_table_new(NULL, NULL);
1714 irreco_webdb_client_reset_env(self);
1716 msg = soup_xmlrpc_message_new (IRRECO_WEBDB_URL);
1717 soup_xmlrpc_message_start_call (msg, "getButtons");
1718 soup_xmlrpc_message_start_param (msg);
1719 soup_xmlrpc_message_write_int(msg, theme_id);
1720 soup_xmlrpc_message_end_param (msg);
1721 soup_xmlrpc_message_end_call (msg);
1723 response = (SoupXmlrpcResponse*) do_xmlrpc (msg,
1724 SOUP_XMLRPC_VALUE_TYPE_ARRAY, self);
1725 if(!response) {
1726 IRRECO_DEBUG(" No response, failed something\n");
1727 IRRECO_RETURN_BOOL(rvalue);
1730 value = soup_xmlrpc_response_get_value (response);
1732 soup_xmlrpc_value_array_get_iterator(value, &iter);
1734 while (iter) {
1735 gchar *id;
1736 soup_xmlrpc_value_array_iterator_get_value(iter, &array_val);
1738 if (!soup_xmlrpc_value_get_int(array_val, (glong *) &ret)) {
1739 IRRECO_DEBUG ("NO value\n");
1740 goto end;
1742 IRRECO_DEBUG("%d\n", ret);
1744 id = g_strdup_printf("%d", ret);
1745 irreco_string_table_add(*button_list, id, NULL);
1746 g_free(id);
1748 iter = soup_xmlrpc_value_array_iterator_next(iter);
1751 rvalue = TRUE;
1752 end:
1753 if(rvalue == FALSE) {
1754 irreco_string_table_free (*button_list);
1755 *button_list = NULL;
1757 g_object_unref (response);
1759 IRRECO_RETURN_BOOL(rvalue);
1763 gboolean irreco_webdb_client_get_button_by_id(IrrecoWebdbClient *self,
1764 gint button_id,
1765 const char *theme_button_dir)
1767 gboolean rvalue = FALSE;
1768 gchar *name = NULL;
1769 gboolean allow_text = FALSE;
1770 gchar *text_format_up = NULL;
1771 gchar *text_format_down = NULL;
1772 gint text_padding;
1773 gdouble text_h_align;
1774 gdouble text_v_align;
1775 gchar *image_up_hash = NULL;
1776 gchar *image_up_name = NULL;
1777 gchar *image_up = NULL;
1778 gchar *base64_image_up = NULL;
1779 gchar *image_down_hash = NULL;
1780 gchar *image_down_name = NULL;
1781 gchar *image_down = NULL;
1782 gchar *base64_image_down = NULL;
1783 gchar *folder = NULL;
1784 gchar *image_down_hash_tmp = NULL;
1785 GHashTable *tmp = NULL;
1786 SoupXmlrpcValue *hash = NULL;
1787 SoupXmlrpcMessage *msg;
1788 SoupXmlrpcResponse *response;
1789 SoupXmlrpcValue *value;
1790 GString *file_path = g_string_new("");
1791 GKeyFile *keyfile = g_key_file_new();
1792 gsize image_down_len;
1793 gsize image_up_len;
1794 IRRECO_ENTER
1796 irreco_webdb_client_reset_env(self);
1798 /* Build query */
1799 msg = soup_xmlrpc_message_new (IRRECO_WEBDB_URL);
1800 soup_xmlrpc_message_start_call (msg, "getButtonById");
1801 soup_xmlrpc_message_start_param (msg);
1802 soup_xmlrpc_message_write_int(msg, (glong) button_id);
1803 soup_xmlrpc_message_end_param (msg);
1804 soup_xmlrpc_message_end_call (msg);
1806 /* Execute XML-RPC call. */
1807 response = (SoupXmlrpcResponse*) do_xmlrpc (msg,
1808 SOUP_XMLRPC_VALUE_TYPE_STRUCT, self);
1810 /* Check response */
1811 if(!response) {
1812 IRRECO_DEBUG(" No response, failed something\n");
1813 goto end;
1816 /* Get array out from response */
1817 value = soup_xmlrpc_response_get_value (response);
1819 if(!soup_xmlrpc_value_get_struct(value, &tmp)){
1820 g_string_printf(self->error_msg,
1821 "ERROR: Not proper return value\n");
1822 goto end;
1825 /* Seek data */
1826 hash = g_hash_table_lookup(tmp, "name");
1827 if (!soup_xmlrpc_value_get_string(hash, &name)) {
1828 IRRECO_DEBUG("No value in response\n");
1829 goto end;
1832 hash = g_hash_table_lookup(tmp, "allow_text");
1833 if (!soup_xmlrpc_value_get_boolean(hash, &allow_text)) {
1834 IRRECO_DEBUG("No value in response\n");
1835 goto end;
1838 hash = g_hash_table_lookup(tmp, "text_format_up");
1839 soup_xmlrpc_value_get_string(hash, &text_format_up);
1841 hash = g_hash_table_lookup(tmp, "text_format_down");
1842 soup_xmlrpc_value_get_string(hash, &text_format_down);
1844 hash = g_hash_table_lookup(tmp, "text_padding");
1845 if (!soup_xmlrpc_value_get_int(hash, (glong *) &text_padding)) {
1846 IRRECO_DEBUG("No value in response\n");
1847 goto end;
1850 hash = g_hash_table_lookup(tmp, "text_h_align");
1851 if (!soup_xmlrpc_value_get_double(hash, &text_h_align)) {
1852 IRRECO_DEBUG("No value in response\n");
1853 goto end;
1855 hash = g_hash_table_lookup(tmp, "text_v_align");
1856 if (!soup_xmlrpc_value_get_double(hash, &text_v_align)) {
1857 IRRECO_DEBUG("No value in response\n");
1858 goto end;
1861 hash = g_hash_table_lookup(tmp, "image_up_hash");
1862 if (!soup_xmlrpc_value_get_string(hash, &image_up_hash)) {
1863 IRRECO_DEBUG("No value in response\n");
1864 goto end;
1867 hash = g_hash_table_lookup(tmp, "image_up_name");
1868 if (!soup_xmlrpc_value_get_string(hash, &image_up_name)) {
1869 IRRECO_DEBUG("No value in response\n");
1870 goto end;
1873 hash = g_hash_table_lookup(tmp, "image_up");
1874 if (!soup_xmlrpc_value_get_string(hash, &base64_image_up)) {
1875 IRRECO_DEBUG("No value in response\n");
1876 goto end;
1879 hash = g_hash_table_lookup(tmp, "image_down_hash");
1880 if (!soup_xmlrpc_value_get_string(hash, &image_down_hash)) {
1881 IRRECO_DEBUG("No value in response\n");
1882 goto end;
1885 hash = g_hash_table_lookup(tmp, "image_down_name");
1886 if (!soup_xmlrpc_value_get_string(hash, &image_down_name)) {
1887 IRRECO_DEBUG("No value in response\n");
1888 IRRECO_LINE
1889 goto end;
1892 hash = g_hash_table_lookup(tmp, "image_down");
1893 if (!soup_xmlrpc_value_get_string(hash, &base64_image_down)) {
1894 IRRECO_DEBUG("No value in response\n");
1895 goto end;
1898 hash = g_hash_table_lookup(tmp, "folder");
1899 if (!soup_xmlrpc_value_get_string(hash, &folder)) {
1900 IRRECO_DEBUG("No value in response\n");
1901 goto end;
1904 /* Create Folder */
1905 g_string_printf(file_path, "%s/%s", theme_button_dir, folder);
1906 IRRECO_DEBUG("mkdir %s\n",file_path->str);
1907 g_mkdir(file_path->str, 0777);
1909 /* Save image_up to folder */
1910 g_string_printf(file_path, "%s/%s/%s", theme_button_dir, folder,
1911 image_up_name);
1912 image_up = (gchar*) g_base64_decode(base64_image_up, &image_up_len);
1913 irreco_write_file(file_path->str, image_up, image_up_len);
1915 /* Save image_down to folder */
1916 g_string_printf(file_path, "%s/%s/%s", theme_button_dir, folder,
1917 image_down_name);
1919 /*Check image hash data*/
1920 image_down = (gchar*) g_base64_decode(base64_image_down,
1921 &image_down_len);
1922 irreco_write_file(file_path->str, image_down, image_down_len);
1923 image_down_hash_tmp = sha_compute_checksum_for_string(G_CHECKSUM_SHA1,
1924 image_down,
1925 image_down_len);
1927 if (!g_str_equal(image_down_hash, image_down_hash_tmp)) {
1929 g_string_printf(self->error_msg,
1930 "ERROR: Button data is corrupted\n");
1931 goto end;
1934 /* Create keyfile and save it to folder*/
1935 irreco_gkeyfile_set_string(keyfile, "theme-button" , "name", name);
1937 if (allow_text) {
1938 irreco_gkeyfile_set_string(keyfile, "theme-button",
1939 "allow-text", "true");
1940 } else {
1941 irreco_gkeyfile_set_string(keyfile, "theme-button",
1942 "allow-text", "false");
1945 irreco_gkeyfile_set_string(keyfile, "theme-button",
1946 "up", image_up_name);
1948 irreco_gkeyfile_set_string(keyfile, "theme-button",
1949 "down", image_down_name);
1951 if (text_format_up != NULL && strlen(text_format_up) > 0) {
1952 irreco_gkeyfile_set_string(keyfile, "theme-button",
1953 "text-format-up", text_format_up);
1956 if (text_format_down != NULL && strlen(text_format_down) > 0) {
1957 irreco_gkeyfile_set_string(keyfile, "theme-button",
1958 "text-format-down", text_format_down);
1961 irreco_gkeyfile_set_glong(keyfile, "theme-button",
1962 "text-padding", (glong)text_padding);
1964 irreco_gkeyfile_set_gfloat(keyfile,
1965 "theme-button",
1966 "text-h-align",
1967 (gfloat) text_h_align);
1969 irreco_gkeyfile_set_gfloat(keyfile,
1970 "theme-button",
1971 "text-v-align",
1972 (gfloat) text_v_align);
1974 g_string_printf(file_path, "%s/%s/button.conf",
1975 theme_button_dir, folder);
1976 irreco_write_keyfile(keyfile, file_path->str);
1978 /* No error occured. */
1979 rvalue = TRUE;
1981 end:
1983 g_object_unref (response);
1984 if (tmp != NULL) g_hash_table_destroy (tmp);
1985 if (name != NULL) g_free(name);
1986 if (text_format_up != NULL) g_free(text_format_up);
1987 if (text_format_down != NULL) g_free(text_format_down);
1988 if (image_up_hash != NULL) g_free(image_up_hash);
1989 if (image_up_name != NULL) g_free(image_up_name);
1990 if (image_up != NULL) g_free(image_up);
1991 if (base64_image_up != NULL) g_free(base64_image_up);
1992 if (image_down_hash != NULL) g_free(image_down_hash);
1993 if (image_down_name != NULL) g_free(image_down_name);
1994 if (image_down != NULL) g_free(image_down);
1995 if (image_down_hash_tmp != NULL) g_free(image_down_hash_tmp);
1996 if (base64_image_down != NULL) g_free(base64_image_down);
1997 if (folder != NULL) g_free(folder);
1999 g_key_file_free(keyfile);
2000 g_string_free(file_path, TRUE);
2002 IRRECO_RETURN_BOOL(rvalue);
2005 gboolean irreco_webdb_client_get_preview_button(IrrecoWebdbClient *self,
2006 gint theme_id,
2007 GdkPixbuf **preview_button)
2009 gboolean rvalue = FALSE;
2010 SoupXmlrpcMessage *msg;
2011 SoupXmlrpcResponse *response;
2012 SoupXmlrpcValue *value;
2013 char *base64_data = NULL;
2014 guchar *data;
2015 gsize len;
2016 GdkPixbufLoader *pl;
2017 GError *error = NULL;
2018 IRRECO_ENTER
2020 msg = soup_xmlrpc_message_new (IRRECO_WEBDB_URL);
2021 soup_xmlrpc_message_start_call (msg, "getPreviewButton");
2022 soup_xmlrpc_message_start_param (msg);
2023 soup_xmlrpc_message_write_int(msg, theme_id);
2024 soup_xmlrpc_message_end_param (msg);
2025 soup_xmlrpc_message_end_call (msg);
2027 irreco_webdb_client_reset_env(self);
2029 response = (SoupXmlrpcResponse*) do_xmlrpc (msg,
2030 SOUP_XMLRPC_VALUE_TYPE_STRING, self);
2032 /* Check response exists */
2033 if(!response) {
2034 IRRECO_DEBUG(" No response, failed at do_xmlrpc\n");
2035 goto end;
2038 value = soup_xmlrpc_response_get_value (response);
2040 /* Try to get string out of value */
2041 if(!soup_xmlrpc_value_get_string(value, &base64_data)){
2042 g_string_printf(self->error_msg,
2043 "ERROR: Not proper return value\n");
2044 goto end;
2047 data = g_base64_decode(base64_data, &len);
2049 pl = gdk_pixbuf_loader_new();
2051 gdk_pixbuf_loader_write(pl, data, len, &error);
2053 if(error != NULL)
2055 g_string_printf(self->error_msg, "ERROR: %s", error->message);
2056 IRRECO_DEBUG("%s\n", error->message);
2057 goto end;
2060 gdk_pixbuf_loader_close(pl, NULL);
2061 *preview_button = gdk_pixbuf_loader_get_pixbuf(pl);
2063 rvalue = TRUE;
2065 end:
2066 g_object_unref (response);
2067 if (base64_data != NULL) g_free(base64_data);
2069 IRRECO_RETURN_BOOL(rvalue);
2072 static SoupXmlrpcResponse *do_xmlrpc(SoupXmlrpcMessage *xmsg,
2073 SoupXmlrpcValueType type,
2074 IrrecoWebdbClient *self)
2076 SoupSession *session;
2077 int status; /* Status of sent message */
2078 SoupMessage *spmsg = NULL; /* Soupmessage */
2079 SoupXmlrpcResponse *response = NULL; /* Response */
2080 SoupXmlrpcValue *value = NULL; /* Value from response */
2081 gchar *resbodykeeper; /* Tmp response holder */
2082 gboolean error = FALSE;
2084 IRRECO_ENTER
2086 session = soup_session_sync_new(); /* Init new synchronous session */
2088 soup_xmlrpc_message_persist (xmsg); /* Lock message */
2090 spmsg = SOUP_MESSAGE(xmsg); /* soup XMLRPC msg to soup msg */
2092 /* Add irreco version to message header */
2093 soup_message_add_header(spmsg->request_headers,
2094 "User-Agent", PACKAGE_NAME "/" VERSION);
2096 IRRECO_DEBUG("Send soup message\n");
2097 status = soup_session_send_message (session, spmsg); /* Send msg */
2099 soup_session_abort (session); /* Session cleanup */
2101 g_object_unref (session);
2103 /* Print request length and response */
2104 /*IRRECO_DEBUG("\n%.*s\n%d %s\n%.*s\n",
2105 spmsg->request.length, spmsg->request.body,
2106 spmsg->status_code, spmsg->reason_phrase,
2107 spmsg->response.length, spmsg->response.body);*/
2108 IRRECO_DEBUG("\nRequest length: %d\nStatus code: %d %s\n",
2109 spmsg->request.length,
2110 spmsg->status_code, spmsg->reason_phrase);
2112 /* Check status of sent message */
2113 if (g_strrstr(spmsg->response.body, "faultCode") != NULL) {
2115 gchar *errmsg; /* error message */
2116 IRRECO_DEBUG("Found faultCode, parse response\n");
2117 IRRECO_DEBUG("%s\n",spmsg->response.body);
2119 errmsg = g_malloc0(strlen(spmsg->response.body)*sizeof(gchar));
2122 /** @todo
2123 * Error code and message could be combined to be Error: <num> <msg>
2124 * if thats possible to do easily
2126 strcpy(errmsg, "Error code: ");
2128 /* Parse spmsgrspbd to start "<int>" */
2129 spmsg->response.body = g_strrstr(spmsg->response.body, "<int>");
2131 resbodykeeper = g_strdup( spmsg->response.body );
2133 /* Copy part of response to errmsg */
2134 strcpy(&errmsg[12], &resbodykeeper[5]);
2136 /* Calc errorcode length and insert ", Error Message: " */
2137 /* in place of "</int>" */
2138 strcpy(&errmsg[strlen(errmsg)-strlen(g_strrstr(errmsg,
2139 "</int>"))], ", Error Message: ");
2141 /* Cut 'til "<string>" */
2142 resbodykeeper = g_strrstr(resbodykeeper, "<string>");
2144 /* Copy error message from after "<string>" into errmsg */
2145 strcpy(&errmsg[strlen(errmsg)], &resbodykeeper[8]);
2147 /* Cut "</string>" and everything after it */
2148 strcpy(&errmsg[strlen(errmsg)-strlen(g_strrstr(errmsg, "</string>"))], "");
2150 /* Parsed error message to right variable */
2151 g_string_printf(self->error_msg, "%s\n", errmsg);
2153 /* Free errmsg resource */
2154 g_free(errmsg);
2155 errmsg = NULL;
2157 error = TRUE;
2158 goto cleanup;
2160 IRRECO_LINE
2161 /* Handle http failures, eg. 404 */
2162 if (!SOUP_STATUS_IS_SUCCESSFUL (status)) {
2163 IRRECO_DEBUG("HTTP failure\n");
2164 g_string_printf(self->error_msg, "%d %s\n",
2165 status, spmsg->reason_phrase);
2167 error = TRUE;
2168 goto cleanup;
2171 /* Parse response */
2172 response = soup_xmlrpc_response_new();
2173 response = soup_xmlrpc_message_parse_response (xmsg);
2175 /* Handle fault responses */
2176 if (!response) {
2177 IRRECO_DEBUG("ERROR: no response\n");
2178 g_string_printf(self->error_msg, "ERROR: no response\n");
2179 error = TRUE;
2180 goto cleanup;
2183 if (soup_xmlrpc_response_is_fault (response)) {
2184 IRRECO_DEBUG("ERROR: response is fault\n");
2185 g_string_printf(self->error_msg, "ERROR: response is fault\n");
2186 error = TRUE;
2187 goto cleanup;
2190 /* Get value(s) from response */
2191 value = soup_xmlrpc_response_get_value(response);
2193 /* Handle wrong type and no value situations */
2194 if (!value) {
2195 IRRECO_DEBUG("ERROR: no value\n");
2196 g_string_printf(self->error_msg, "ERROR: no value\n");
2197 error = TRUE;
2198 goto cleanup;
2201 if (soup_xmlrpc_value_get_type (value) != type) {
2202 IRRECO_DEBUG("ERROR: wrong value type\nexpected %s, got %s\n",
2203 value_type[type],
2204 value_type[soup_xmlrpc_value_get_type (value)]);
2206 g_string_printf(self->error_msg,
2207 "ERROR: wrong value type\nexpected %s, got %s\n",
2208 value_type[type],
2209 value_type[soup_xmlrpc_value_get_type (value)]);
2211 error = TRUE;
2212 goto cleanup;
2215 cleanup:
2216 /* Unref soupmessage */
2217 if (spmsg != NULL && !error) {
2218 g_object_unref(spmsg);
2219 spmsg = NULL;
2222 if(error) {
2223 if (response != NULL) g_object_unref(response);
2224 response = NULL;
2227 IRRECO_RETURN_PTR(response);
2230 gboolean irreco_webdb_client_add_user(IrrecoWebdbClient *self,
2231 const gchar *name,
2232 const gchar *email,
2233 const gchar *passwd)
2235 gboolean rvalue = TRUE;
2237 SoupXmlrpcMessage *msg;
2238 SoupXmlrpcResponse *response;
2239 SoupXmlrpcValue *value;
2240 /*gboolean result;*/
2242 IRRECO_ENTER
2244 /* Init msg with URI and other data */
2245 msg = soup_xmlrpc_message_new (IRRECO_WEBDB_URL);
2246 soup_xmlrpc_message_start_call (msg, "addUser");
2248 soup_xmlrpc_message_start_param (msg);
2249 soup_xmlrpc_message_write_string(msg, name);
2250 soup_xmlrpc_message_end_param (msg);
2252 soup_xmlrpc_message_start_param (msg);
2253 soup_xmlrpc_message_write_string(msg, email);
2254 soup_xmlrpc_message_end_param (msg);
2256 soup_xmlrpc_message_start_param (msg);
2257 soup_xmlrpc_message_write_string(msg, passwd);
2258 soup_xmlrpc_message_end_param (msg);
2260 soup_xmlrpc_message_end_call (msg);
2262 /* Reset error params */
2263 irreco_webdb_client_reset_env(self);
2265 /* Execute XML-RPC call. */
2266 response = (SoupXmlrpcResponse*) do_xmlrpc (msg,
2267 SOUP_XMLRPC_VALUE_TYPE_BOOLEAN, self);
2269 /* Check response exists */
2270 if(!response) {
2271 IRRECO_DEBUG(" No response, failed something\n");
2272 IRRECO_RETURN_BOOL(FALSE);
2275 value = soup_xmlrpc_response_get_value (response);
2277 g_object_unref (response);
2279 /* Everything went fine, return TRUE */
2280 IRRECO_RETURN_BOOL(rvalue);
2284 * Login user to WebDB.
2287 gboolean irreco_webdb_client_login(IrrecoWebdbClient *self,
2288 const gchar *user,
2289 const gchar *password)
2291 gboolean rvalue = TRUE;
2292 SoupXmlrpcMessage *msg;
2293 SoupXmlrpcResponse *response;
2294 SoupXmlrpcValue *value;
2295 IRRECO_ENTER
2297 /* Init msg with URI and other data */
2298 msg = soup_xmlrpc_message_new (IRRECO_WEBDB_URL);
2299 soup_xmlrpc_message_start_call (msg, "loginToDB");
2300 soup_xmlrpc_message_start_param (msg);
2301 soup_xmlrpc_message_write_string(msg, user);
2302 soup_xmlrpc_message_end_param (msg);
2303 soup_xmlrpc_message_start_param (msg);
2304 soup_xmlrpc_message_write_string(msg, password);
2305 soup_xmlrpc_message_end_param (msg);
2306 soup_xmlrpc_message_end_call (msg);
2308 irreco_webdb_client_reset_env(self);
2310 /* Execute XML-RPC call. */
2311 response = (SoupXmlrpcResponse*) do_xmlrpc (msg,
2312 SOUP_XMLRPC_VALUE_TYPE_BOOLEAN, self);
2314 /* Check response exists */
2315 if(!response) {
2316 IRRECO_DEBUG(" No response, failed something\n");
2317 IRRECO_RETURN_BOOL(FALSE);
2320 value = soup_xmlrpc_response_get_value (response);
2322 g_object_unref (response);
2324 /* Everything went fine, return TRUE */
2325 IRRECO_RETURN_BOOL(rvalue);
2331 #if 0
2335 gboolean irreco_webdb_client_get_category_list(GHashTable **category_list)
2337 gint i;
2338 IRRECO_ENTER
2340 *category_list = NULL;
2342 /* Execute XML-RPC call. */
2343 irreco_webdb_client_reset_env();
2344 self->result = xmlrpc_client_call_server(self->error_env, self->server,
2345 "getCategoryList", "()");
2346 if (!irreco_webdb_client_is_ok()) IRRECO_RETURN_BOOL(FALSE);
2348 /* Get structure size. */
2349 i = xmlrpc_struct_size(self->error_env, self->result);
2350 if (!irreco_webdb_client_is_ok()) IRRECO_RETURN_BOOL(FALSE);
2352 /* Create hashtable. */
2353 *category_list = g_hash_table_new_full(g_int_hash, g_int_equal,
2354 NULL, g_free);
2356 /* Parse structure. */
2357 while (i--) {
2358 xmlrpc_value *xml_key;
2359 xmlrpc_value *xml_value;
2360 const gchar * str_key;
2361 const gchar * str_value;
2363 xmlrpc_struct_read_member(self->error_env, self->result, i,
2364 &xml_key, &xml_value);
2365 if (!irreco_webdb_client_is_ok()) goto error;
2367 xmlrpc_read_string(self->error_env, xml_key, &str_key);
2368 if (!irreco_webdb_client_is_ok()) goto error;
2370 xmlrpc_read_string(self->error_env, xml_value, &str_value);
2371 if (!irreco_webdb_client_is_ok()) goto error;
2373 IRRECO_PRINTF("Key: %s, Val: %s\n", str_key, str_value);
2374 /*g_hash_table_add();*/
2376 xmlrpc_DECREF(xml_key);
2377 xmlrpc_DECREF(xml_value);
2380 IRRECO_RETURN_BOOL(TRUE);
2382 error:
2383 g_hash_table_destroy(*category_list);
2384 *category_list = NULL;
2385 IRRECO_RETURN_BOOL(FALSE);
2387 #endif
2389 /** @} */
2392 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
2393 /* Events and Callbacks */
2394 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
2396 /** @} */