response-value set to NULL and it will be freed if it is not NULL
[irreco.git] / irreco / src / webdb / irreco_webdb_client.c
blob9efe214f3d3683eb7159ce1ccc62567911a39136
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 (t5masa02@students.oamk.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 /*#define IRRECO_WEBDB_URL "http://mercury.wipsl.com/irreco/webdb/"*/
27 /*#define IRRECO_WEBDB_URL "http://127.0.0.1/irreco/webdb/"*/
30 for php files
31 svn co svn+irreco:///irreco/irreco/database/trunk/php /var/www/irreco/webdb
35 /**
36 * @typedef IrrecoWebdbClient
38 * Irreco Web Database API implementation. These functions connect to the
39 * IrrecoWebdbClient trough XML-RPC connection, pass arguments, and decode return
40 * values.
43 static const char *const value_type[] = {
44 "BAD",
45 "int",
46 "boolean",
47 "string",
48 "double",
49 "datetime",
50 "base64",
51 "struct",
52 "array"
55 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
56 /* Prototypes */
57 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
59 static void irreco_webdb_client_reset_env();
60 static SoupXmlrpcResponse *do_xmlrpc(SoupXmlrpcMessage *xmsg,
61 SoupXmlrpcValueType type,
62 IrrecoWebdbClient *self);
65 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
66 /* Construction & Destruction */
67 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
69 /**
70 * Create new IrrecoWebdbClient Object
72 IrrecoWebdbClient *irreco_webdb_client_new()
74 IrrecoWebdbClient *self;
75 IRRECO_ENTER
77 self = g_slice_new0(IrrecoWebdbClient);
79 /* Allocate 1000 characters to soup error message */
80 /*self->error_msg = g_malloc0(1000*sizeof(*self->error_msg));*/
81 /* TODO do same to do_xmlrpc errormsg gchar */
82 /* use GString->str if that can grow on it own*/
83 self->error_msg = g_string_new(NULL);
85 IRRECO_RETURN_PTR(self);
88 void irreco_webdb_client_free(IrrecoWebdbClient *self)
90 IRRECO_ENTER
92 g_assert(self != NULL);
94 /* Free self->error_msg resource */
95 g_string_free(self->error_msg, TRUE);
96 self->error_msg = NULL;
98 g_slice_free(IrrecoWebdbClient, self);
99 self = NULL;
101 IRRECO_RETURN
105 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
106 /* Private Functions */
107 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
110 * Release of RPC results and errors.
112 static void irreco_webdb_client_reset_env(IrrecoWebdbClient *self)
114 IRRECO_ENTER
116 self->error_msg = g_string_erase(self->error_msg, 0, -1);
118 IRRECO_RETURN
121 /* TODO Funcs return bool wether they succeeded, so this could be removed. */
123 * Check if the previous call to XMLRPC-C succeeded.
125 * @return TRUE if error occured, FALSE otherwise.
127 /*static gboolean irreco_webdb_client_check_error(IrrecoWebdbClient *self)
129 IRRECO_ENTER
130 if(self->error_env->fault_occurred) {
131 IRRECO_ERROR("%d: %s\n", self->error_env->fault_code,
132 self->error_env->fault_string);
133 IRRECO_RETURN_BOOL(TRUE);
135 IRRECO_RETURN_BOOL(FALSE);
140 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
141 /* Functions */
142 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
145 * Get error message.
147 * @param msg GString object to recieve the error message.
149 void irreco_webdb_client_get_error_msg(IrrecoWebdbClient *self, GString *msg)
151 IRRECO_ENTER
153 /* Clear and set msg */
154 msg = g_string_erase(msg, 0, -1);
155 msg = g_string_insert(msg, 0, self->error_msg->str);
157 IRRECO_RETURN
161 * Ask WebDB to sum two numbers.
163 * @param num_a First number.
164 * @param num_b Second number.
165 * @param sum Variable to receive the result.
166 * @return TRUE on successfull XML-RPC call, FALSE otherwise.
168 gboolean irreco_webdb_client_sum(IrrecoWebdbClient *self,
169 gint num_a,
170 gint num_b,
171 gint *sum)
173 gboolean rvalue = TRUE;
174 SoupXmlrpcMessage *msg;
175 SoupXmlrpcResponse *response;
176 SoupXmlrpcValue *value;
177 IRRECO_ENTER
179 irreco_webdb_client_reset_env(self);
181 msg = soup_xmlrpc_message_new (IRRECO_WEBDB_URL);
182 soup_xmlrpc_message_start_call (msg, "sum");
183 soup_xmlrpc_message_start_param (msg);
184 soup_xmlrpc_message_write_int(msg, num_a);
185 soup_xmlrpc_message_end_param (msg);
186 soup_xmlrpc_message_start_param (msg);
187 soup_xmlrpc_message_write_int(msg, num_b);
188 soup_xmlrpc_message_end_param (msg);
189 soup_xmlrpc_message_end_call (msg);
191 /* Execute XML-RPC call. */
192 response = (SoupXmlrpcResponse*) do_xmlrpc (msg,
193 SOUP_XMLRPC_VALUE_TYPE_INT, self);
194 /* Check response exists */
195 if(!response) {
196 IRRECO_DEBUG(" No response, failed something\n");
197 IRRECO_RETURN_BOOL(FALSE);
200 value = soup_xmlrpc_response_get_value (response);
202 /* Get gint (as glong) out of value */
203 if(!soup_xmlrpc_value_get_int(value, (glong*)sum)){
204 IRRECO_DEBUG("ERROR: Not proper return value\n");
205 g_string_printf(self->error_msg, "ERROR: Not proper return value\n");
206 g_object_unref (response);
207 IRRECO_RETURN_BOOL(FALSE);
210 g_object_unref (response);
212 /* Everything went fine, return TRUE */
213 IRRECO_RETURN_BOOL(rvalue);
216 gboolean irreco_webdb_client_upload_configuration(IrrecoWebdbClient *self,
217 const gchar *backend,
218 const gchar *category,
219 const gchar *file_hash,
220 const gchar *file_name,
221 const gchar *manufacturer,
222 const gchar *model,
223 const gchar *password,
224 const gchar *user,
225 const gchar *data)
227 gboolean rvalue = TRUE;
228 SoupXmlrpcMessage *msg;
229 SoupXmlrpcResponse *response;
230 SoupXmlrpcValue *value;
231 IRRECO_ENTER
233 /* Init msg with URI and other data */
234 msg = soup_xmlrpc_message_new (IRRECO_WEBDB_URL);
235 soup_xmlrpc_message_start_call (msg, "uploadConfiguration");
236 soup_xmlrpc_message_start_param (msg);
237 soup_xmlrpc_message_write_string(msg, backend);
238 soup_xmlrpc_message_end_param (msg);
239 soup_xmlrpc_message_start_param (msg);
240 soup_xmlrpc_message_write_string(msg, category);
241 soup_xmlrpc_message_end_param (msg);
242 soup_xmlrpc_message_start_param (msg);
243 soup_xmlrpc_message_write_string(msg, manufacturer);
244 soup_xmlrpc_message_end_param (msg);
245 soup_xmlrpc_message_start_param (msg);
246 soup_xmlrpc_message_write_string(msg, model);
247 soup_xmlrpc_message_end_param (msg);
248 soup_xmlrpc_message_start_param (msg);
249 soup_xmlrpc_message_write_string(msg, user);
250 soup_xmlrpc_message_end_param (msg);
251 soup_xmlrpc_message_start_param (msg);
252 soup_xmlrpc_message_write_string(msg, password);
253 soup_xmlrpc_message_end_param (msg);
254 soup_xmlrpc_message_start_param (msg);
255 soup_xmlrpc_message_write_string(msg, file_hash);
256 soup_xmlrpc_message_end_param (msg);
257 soup_xmlrpc_message_start_param (msg);
258 soup_xmlrpc_message_write_string(msg, file_name);
259 soup_xmlrpc_message_end_param (msg);
260 soup_xmlrpc_message_start_param (msg);
261 soup_xmlrpc_message_write_string(msg, data);
262 soup_xmlrpc_message_end_param (msg);
263 soup_xmlrpc_message_end_call (msg);
265 irreco_webdb_client_reset_env(self);
267 /* Execute XML-RPC call. */
268 response = (SoupXmlrpcResponse*) do_xmlrpc (msg,
269 SOUP_XMLRPC_VALUE_TYPE_STRING, self);
271 /* Check response exists */
272 if(!response) {
273 IRRECO_DEBUG(" No response, failed something\n");
274 IRRECO_RETURN_BOOL(FALSE);
277 value = soup_xmlrpc_response_get_value (response);
279 g_object_unref (response);
281 /* Everything went fine, return TRUE */
282 IRRECO_RETURN_BOOL(rvalue);
286 gboolean irreco_webdb_client_get_categories(IrrecoWebdbClient *self,
287 IrrecoStringTable **category_list)
289 gboolean rvalue = FALSE;
290 SoupXmlrpcMessage *msg;
291 SoupXmlrpcResponse *response;
292 SoupXmlrpcValueArrayIterator *iter;
293 SoupXmlrpcValue *value;
294 SoupXmlrpcValue *array_val;
295 gchar *ret = NULL;
297 IRRECO_ENTER
299 irreco_webdb_client_reset_env(self);
301 *category_list = irreco_string_table_new(NULL, NULL);
303 irreco_webdb_client_reset_env(self);
305 msg = soup_xmlrpc_message_new (IRRECO_WEBDB_URL);
306 soup_xmlrpc_message_start_call (msg, "getCategories");
307 soup_xmlrpc_message_end_call (msg);
309 response = (SoupXmlrpcResponse*) do_xmlrpc (msg,
310 SOUP_XMLRPC_VALUE_TYPE_ARRAY, self);
311 if(!response) {
312 IRRECO_DEBUG(" No response, failed something\n");
313 IRRECO_RETURN_BOOL(rvalue);
316 value = soup_xmlrpc_response_get_value (response);
318 soup_xmlrpc_value_array_get_iterator(value, &iter);
320 while (iter) {
321 soup_xmlrpc_value_array_iterator_get_value(iter, &array_val);
323 if (!soup_xmlrpc_value_get_string(array_val, &ret)) {
324 IRRECO_DEBUG ("NO value\n");
325 g_object_unref (response);
326 IRRECO_RETURN_BOOL(rvalue);
328 IRRECO_DEBUG("%s\n", ret);
330 irreco_string_table_add(*category_list, ret, NULL);
332 iter = soup_xmlrpc_value_array_iterator_next(iter);
335 rvalue = TRUE;
337 IRRECO_RETURN_BOOL(rvalue);
340 gboolean irreco_webdb_client_get_all_categories(IrrecoWebdbClient *self,
341 IrrecoStringTable **category_list)
343 gboolean rvalue = FALSE;
344 SoupXmlrpcMessage *msg;
345 SoupXmlrpcResponse *response;
346 SoupXmlrpcValueArrayIterator *iter;
347 SoupXmlrpcValue *value;
348 SoupXmlrpcValue *array_val;
349 gchar *ret = NULL;
351 IRRECO_ENTER
353 *category_list = NULL;
354 irreco_webdb_client_reset_env(self);
356 *category_list = NULL;
357 *category_list = irreco_string_table_new(NULL, NULL);
359 irreco_webdb_client_reset_env(self);
361 msg = soup_xmlrpc_message_new (IRRECO_WEBDB_URL);
362 soup_xmlrpc_message_start_call (msg, "getAllCategories");
363 soup_xmlrpc_message_end_call (msg);
365 /* TODO */
366 /* Upload device dialog also shows category named category */
367 /* That comes from where and why? */
368 /* Don't think there should be such */
369 /* Same thing with manufacturer field */
371 response = (SoupXmlrpcResponse*) do_xmlrpc (msg,
372 SOUP_XMLRPC_VALUE_TYPE_ARRAY, self);
373 if(!response) {
374 IRRECO_DEBUG(" No response, failed something\n");
375 IRRECO_RETURN_BOOL(rvalue);
378 value = soup_xmlrpc_response_get_value (response);
380 soup_xmlrpc_value_array_get_iterator(value, &iter);
382 while (iter) {
383 soup_xmlrpc_value_array_iterator_get_value(iter, &array_val);
385 if (!soup_xmlrpc_value_get_string(array_val, &ret)) {
386 IRRECO_DEBUG ("NO value\n");
387 g_object_unref (response);
388 IRRECO_RETURN_BOOL(rvalue);
390 IRRECO_DEBUG("%s\n", ret);
392 irreco_string_table_add(*category_list, ret, NULL);
394 iter = soup_xmlrpc_value_array_iterator_next(iter);
397 rvalue = TRUE;
399 IRRECO_RETURN_BOOL(rvalue);
401 gboolean irreco_webdb_client_get_manufacturers(IrrecoWebdbClient *self,
402 const gchar *category,
403 IrrecoStringTable **manufacturer_list)
405 gboolean rvalue = FALSE;
406 SoupXmlrpcMessage *msg;
407 SoupXmlrpcResponse *response;
408 SoupXmlrpcValueArrayIterator *iter;
409 SoupXmlrpcValue *value;
410 SoupXmlrpcValue *array_val;
411 gchar *ret = NULL;
413 IRRECO_ENTER
415 *manufacturer_list = NULL;
416 irreco_webdb_client_reset_env(self);
418 *manufacturer_list = NULL;
419 *manufacturer_list = irreco_string_table_new(NULL, NULL);
421 irreco_webdb_client_reset_env(self);
423 msg = soup_xmlrpc_message_new (IRRECO_WEBDB_URL);
424 soup_xmlrpc_message_start_call (msg, "getManufacturers");
425 soup_xmlrpc_message_start_param (msg);
426 soup_xmlrpc_message_write_string(msg, category);
427 soup_xmlrpc_message_end_param (msg);
428 soup_xmlrpc_message_end_call (msg);
430 response = (SoupXmlrpcResponse*) do_xmlrpc (msg,
431 SOUP_XMLRPC_VALUE_TYPE_ARRAY, self);
432 if(!response) {
433 IRRECO_DEBUG(" No response, failed something\n");
434 IRRECO_RETURN_BOOL(rvalue);
437 value = soup_xmlrpc_response_get_value (response);
439 soup_xmlrpc_value_array_get_iterator(value, &iter);
441 while (iter) {
442 soup_xmlrpc_value_array_iterator_get_value(iter, &array_val);
444 if (!soup_xmlrpc_value_get_string(array_val, &ret)) {
445 IRRECO_DEBUG ("NO value\n");
446 g_object_unref (response);
447 IRRECO_RETURN_BOOL(rvalue);
449 IRRECO_DEBUG("%s\n", ret);
451 irreco_string_table_add(*manufacturer_list, ret, NULL);
453 iter = soup_xmlrpc_value_array_iterator_next(iter);
456 rvalue = TRUE;
458 IRRECO_RETURN_BOOL(rvalue);
461 gboolean irreco_webdb_client_get_all_manufacturers(IrrecoWebdbClient *self,
462 IrrecoStringTable **manufacturer_list)
464 gboolean rvalue = FALSE;
465 SoupXmlrpcMessage *msg;
466 SoupXmlrpcResponse *response;
467 SoupXmlrpcValueArrayIterator *iter;
468 SoupXmlrpcValue *value;
469 SoupXmlrpcValue *array_val;
470 gchar *ret = NULL;
472 IRRECO_ENTER
474 *manufacturer_list = NULL;
475 irreco_webdb_client_reset_env(self);
477 *manufacturer_list = NULL;
478 *manufacturer_list = irreco_string_table_new(NULL, NULL);
480 irreco_webdb_client_reset_env(self);
482 msg = soup_xmlrpc_message_new (IRRECO_WEBDB_URL);
483 soup_xmlrpc_message_start_call (msg, "getAllManufacturers");
484 soup_xmlrpc_message_end_call (msg);
486 response = (SoupXmlrpcResponse*) do_xmlrpc (msg,
487 SOUP_XMLRPC_VALUE_TYPE_ARRAY, self);
488 if(!response) {
489 IRRECO_DEBUG(" No response, failed something\n");
490 IRRECO_RETURN_BOOL(rvalue);
493 value = soup_xmlrpc_response_get_value (response);
495 soup_xmlrpc_value_array_get_iterator(value, &iter);
497 while (iter) {
498 soup_xmlrpc_value_array_iterator_get_value(iter, &array_val);
500 if (!soup_xmlrpc_value_get_string(array_val, &ret)) {
501 IRRECO_DEBUG ("No value\n");
502 g_object_unref (response);
503 IRRECO_RETURN_BOOL(rvalue);
505 IRRECO_DEBUG("%s\n", ret);
507 irreco_string_table_add(*manufacturer_list, ret, NULL);
509 iter = soup_xmlrpc_value_array_iterator_next(iter);
512 rvalue = TRUE;
514 IRRECO_RETURN_BOOL(rvalue);
517 gboolean irreco_webdb_client_get_models(IrrecoWebdbClient *self,
518 const gchar *category,
519 const gchar *manufacturer,
520 IrrecoStringTable **model_list)
522 gboolean rvalue = FALSE;
523 SoupXmlrpcMessage *msg;
524 SoupXmlrpcResponse *response;
525 SoupXmlrpcValueArrayIterator *iter;
526 SoupXmlrpcValue *value;
527 SoupXmlrpcValue *array_val;
528 gchar *ret = NULL;
530 IRRECO_ENTER
532 *model_list = NULL;
533 irreco_webdb_client_reset_env(self);
535 *model_list = NULL;
536 *model_list = irreco_string_table_new(NULL, NULL);
538 irreco_webdb_client_reset_env(self);
540 msg = soup_xmlrpc_message_new (IRRECO_WEBDB_URL);
541 soup_xmlrpc_message_start_call (msg, "getModels");
542 soup_xmlrpc_message_start_param (msg);
543 soup_xmlrpc_message_write_string(msg, category);
544 soup_xmlrpc_message_end_param (msg);
545 soup_xmlrpc_message_start_param (msg);
546 soup_xmlrpc_message_write_string(msg, manufacturer);
547 soup_xmlrpc_message_end_param (msg);
548 soup_xmlrpc_message_end_call (msg);
550 response = (SoupXmlrpcResponse*) do_xmlrpc (msg,
551 SOUP_XMLRPC_VALUE_TYPE_ARRAY, self);
552 if(!response) {
553 IRRECO_DEBUG(" No response, failed something\n");
554 IRRECO_RETURN_BOOL(rvalue);
557 value = soup_xmlrpc_response_get_value (response);
559 soup_xmlrpc_value_array_get_iterator(value, &iter);
561 while (iter) {
562 soup_xmlrpc_value_array_iterator_get_value(iter, &array_val);
564 if (!soup_xmlrpc_value_get_string(array_val, &ret)) {
565 IRRECO_DEBUG ("No value\n");
566 g_object_unref (response);
567 IRRECO_RETURN_BOOL(rvalue);
569 IRRECO_DEBUG("%s\n", ret);
571 irreco_string_table_add(*model_list, ret, NULL);
573 iter = soup_xmlrpc_value_array_iterator_next(iter);
576 rvalue = TRUE;
578 IRRECO_RETURN_BOOL(rvalue);
582 gboolean irreco_webdb_client_get_configs(IrrecoWebdbClient *self,
583 const gchar *category,
584 const gchar *manufacturer,
585 const gchar *model,
586 IrrecoStringTable **config_list)
588 gboolean rvalue = FALSE;
589 SoupXmlrpcMessage *msg;
590 SoupXmlrpcResponse *response;
591 SoupXmlrpcValueArrayIterator *iter;
592 SoupXmlrpcValue *value;
593 SoupXmlrpcValue *array_val;
594 gchar *ret = NULL;
596 IRRECO_ENTER
598 *config_list = NULL;
599 *config_list = irreco_string_table_new(NULL, NULL);
601 irreco_webdb_client_reset_env(self);
603 msg = soup_xmlrpc_message_new (IRRECO_WEBDB_URL);
604 soup_xmlrpc_message_start_call (msg, "getConfigurations");
605 soup_xmlrpc_message_start_param (msg);
606 soup_xmlrpc_message_write_string(msg, manufacturer);
607 soup_xmlrpc_message_end_param (msg);
608 soup_xmlrpc_message_start_param (msg);
609 soup_xmlrpc_message_write_string(msg, model);
610 soup_xmlrpc_message_end_param (msg);
611 soup_xmlrpc_message_end_call (msg);
613 response = (SoupXmlrpcResponse*) do_xmlrpc (msg,
614 SOUP_XMLRPC_VALUE_TYPE_ARRAY, self);
615 if(!response) {
616 IRRECO_DEBUG(" No response, failed something\n");
617 IRRECO_RETURN_BOOL(rvalue);
620 value = soup_xmlrpc_response_get_value (response);
622 soup_xmlrpc_value_array_get_iterator(value, &iter);
624 while (iter) {
625 soup_xmlrpc_value_array_iterator_get_value(iter, &array_val);
627 if (!soup_xmlrpc_value_get_string(array_val, &ret)) {
628 IRRECO_DEBUG ("No value\n");
629 g_object_unref (response);
630 IRRECO_RETURN_BOOL(rvalue);
632 IRRECO_DEBUG("Config: %s\n", ret);
634 irreco_string_table_add(*config_list, ret, NULL);
636 iter = soup_xmlrpc_value_array_iterator_next(iter);
639 /* No error occured. */
640 rvalue = TRUE;
642 IRRECO_RETURN_BOOL(rvalue);
646 gboolean irreco_webdb_client_get_configuration(IrrecoWebdbClient *self,
647 gint id,
648 IrrecoWebdbConf **configuration)
650 gboolean rvalue = FALSE;
651 const gchar *user = NULL;
652 const gchar *backend;
653 const gchar *category;
654 const gchar *manufacturer;
655 const gchar *model;
656 const gchar *file_hash;
657 const gchar *file_name;
658 const gchar *uploaded;
659 const gchar *download_count;
660 SoupXmlrpcMessage *msg;
661 SoupXmlrpcResponse *response;
662 SoupXmlrpcValue *value;
663 GHashTable *tmp = NULL;
664 gchar *ret = NULL;
665 SoupXmlrpcValue *hash = NULL;
667 IRRECO_ENTER
669 *configuration = irreco_webdb_conf_new();
671 irreco_webdb_client_reset_env(self);
673 /* Build query */
674 msg = soup_xmlrpc_message_new (IRRECO_WEBDB_URL);
675 soup_xmlrpc_message_start_call (msg, "getConfigurationById");
676 soup_xmlrpc_message_start_param (msg);
677 soup_xmlrpc_message_write_int(msg, (long) id);
678 soup_xmlrpc_message_end_param (msg);
679 soup_xmlrpc_message_end_call (msg);
681 /* Execute XML-RPC call. */
682 response = (SoupXmlrpcResponse*) do_xmlrpc (msg,
683 SOUP_XMLRPC_VALUE_TYPE_STRUCT, self);
685 /* Check response */
686 if(!response) {
687 IRRECO_DEBUG(" No response, failed something\n");
688 IRRECO_RETURN_BOOL(rvalue);
691 /* Get array out from response */
692 value = soup_xmlrpc_response_get_value (response);
694 if(!soup_xmlrpc_value_get_struct(value, &tmp)){
695 g_string_printf(self->error_msg,
696 "ERROR: Not proper return value\n");
697 g_object_unref (response);
698 IRRECO_RETURN_BOOL(FALSE);
701 /* Seek data */
702 hash = g_hash_table_lookup (tmp, "user");
703 if (!soup_xmlrpc_value_get_string(hash, &ret)) {
704 IRRECO_DEBUG("No value in response\n");
705 g_hash_table_destroy (tmp);
706 g_object_unref (response);
707 IRRECO_RETURN_BOOL(FALSE);
709 user = ret;
711 hash = g_hash_table_lookup (tmp, "backend");
712 if (!soup_xmlrpc_value_get_string(hash, &ret)) {
713 IRRECO_DEBUG ("No value in response\n");
714 g_hash_table_destroy (tmp);
715 g_object_unref (response);
716 IRRECO_RETURN_BOOL(FALSE);
718 backend = ret;
720 hash = g_hash_table_lookup (tmp, "category");
721 if (!soup_xmlrpc_value_get_string(hash, &ret)) {
722 IRRECO_DEBUG ("No value in response\n");
723 g_hash_table_destroy (tmp);
724 g_object_unref (response);
725 IRRECO_RETURN_BOOL(FALSE);
727 category = ret;
729 hash = g_hash_table_lookup (tmp, "manufacturer");
730 if (!soup_xmlrpc_value_get_string(hash, &ret)) {
731 IRRECO_DEBUG ("No value in response\n");
732 g_hash_table_destroy (tmp);
733 g_object_unref (response);
734 IRRECO_RETURN_BOOL(FALSE);
736 manufacturer = ret;
738 hash = g_hash_table_lookup (tmp, "model");
739 if (!soup_xmlrpc_value_get_string(hash, &ret)) {
740 IRRECO_DEBUG ("No value in response\n");
741 g_hash_table_destroy (tmp);
742 g_object_unref (response);
743 IRRECO_RETURN_BOOL(FALSE);
745 model = ret;
747 hash = g_hash_table_lookup (tmp, "file_hash");
748 if (!soup_xmlrpc_value_get_string(hash, &ret)) {
749 IRRECO_DEBUG ("No value in response\n");
750 g_hash_table_destroy (tmp);
751 g_object_unref (response);
752 IRRECO_RETURN_BOOL(FALSE);
754 file_hash = ret;
756 hash = g_hash_table_lookup (tmp, "file_name");
757 if (!soup_xmlrpc_value_get_string(hash, &ret)) {
758 IRRECO_DEBUG ("No value in response\n");
759 g_hash_table_destroy (tmp);
760 g_object_unref (response);
761 IRRECO_RETURN_BOOL(FALSE);
763 file_name = ret;
765 hash = g_hash_table_lookup (tmp, "uploaded");
766 if (!soup_xmlrpc_value_get_string(hash, &ret)) {
767 IRRECO_DEBUG ("No value in response\n");
768 g_hash_table_destroy (tmp);
769 g_object_unref (response);
770 IRRECO_RETURN_BOOL(FALSE);
772 uploaded = ret;
774 hash = g_hash_table_lookup (tmp, "download_count");
775 if (!soup_xmlrpc_value_get_string(hash, &ret)) {
776 IRRECO_DEBUG ("No value in response\n");
777 g_hash_table_destroy (tmp);
778 g_object_unref (response);
779 IRRECO_RETURN_BOOL(FALSE);
781 download_count = ret;
783 IRRECO_DEBUG("Configuration: %d %s %s %s %s %s %s %s %s %s\n",
784 id, user, backend, category, manufacturer,
785 model, file_hash, file_name, uploaded, download_count);
787 irreco_webdb_conf_set(*configuration, id, user, backend, category,
788 manufacturer, model, file_hash, file_name,
789 uploaded, download_count);
791 /* No error occured. */
792 rvalue = TRUE;
794 IRRECO_RETURN_BOOL(rvalue);
797 gboolean irreco_webdb_client_get_file(IrrecoWebdbClient *self,
798 const gchar *file_hash,
799 const gchar *file_name,
800 GString **file_data)
802 gboolean rvalue = FALSE;
803 SoupXmlrpcMessage *msg;
804 SoupXmlrpcResponse *response;
805 SoupXmlrpcValue *value;
806 GHashTable *tmp = NULL;
807 gchar *ret = NULL;
808 SoupXmlrpcValue *hash = NULL;
810 IRRECO_ENTER
812 irreco_webdb_client_reset_env(self);
814 IRRECO_LINE
816 /* Build query */
817 msg = soup_xmlrpc_message_new (IRRECO_WEBDB_URL);
818 soup_xmlrpc_message_start_call (msg, "getFile");
819 soup_xmlrpc_message_start_param (msg);
820 soup_xmlrpc_message_write_string(msg, file_hash);
821 soup_xmlrpc_message_end_param (msg);
822 soup_xmlrpc_message_start_param (msg);
823 soup_xmlrpc_message_write_string(msg, file_name);
824 soup_xmlrpc_message_end_param (msg);
825 soup_xmlrpc_message_end_call (msg);
827 /* Execute XML-RPC call. */
828 response = (SoupXmlrpcResponse*) do_xmlrpc (msg,
829 SOUP_XMLRPC_VALUE_TYPE_STRUCT, self);
831 /* Check response */
832 if(!response) {
833 IRRECO_DEBUG(" No response, failed at do_xmlrpc\n");
834 IRRECO_RETURN_BOOL(FALSE);
837 /* Get array out from response */
838 value = soup_xmlrpc_response_get_value (response);
840 /* Get string out from array */
841 if(!soup_xmlrpc_value_get_struct(value, &tmp)){
842 g_string_printf(self->error_msg,
843 "ERROR: Not proper return value\n");
844 g_object_unref (response);
845 IRRECO_RETURN_BOOL(FALSE);
848 /* Seek data */
849 hash = g_hash_table_lookup (tmp, "data");
851 if (!soup_xmlrpc_value_get_string(hash, &ret)) {
852 IRRECO_DEBUG ("No value in response\n");
853 g_hash_table_destroy (tmp);
854 g_object_unref (response);
855 IRRECO_RETURN_BOOL(FALSE);
858 IRRECO_DEBUG("File data:\n%s\n",ret);
860 *file_data = g_string_new(ret);
862 g_hash_table_destroy (tmp);
863 g_object_unref (response);
865 rvalue = TRUE;
867 IRRECO_RETURN_BOOL(rvalue);
871 gboolean irreco_webdb_client_get_user_exists(IrrecoWebdbClient *self,
872 const gchar *name,
873 gboolean *user_exists)
875 SoupXmlrpcMessage *msg;
876 SoupXmlrpcResponse *response;
877 SoupXmlrpcValue *value;
879 IRRECO_ENTER
881 msg = soup_xmlrpc_message_new (IRRECO_WEBDB_URL);
882 soup_xmlrpc_message_start_call (msg, "getUserExists");
883 soup_xmlrpc_message_start_param (msg);
884 soup_xmlrpc_message_write_string(msg, name);
885 soup_xmlrpc_message_end_param (msg);
886 soup_xmlrpc_message_end_call (msg);
888 irreco_webdb_client_reset_env(self);
890 response = (SoupXmlrpcResponse*) do_xmlrpc (msg,
891 SOUP_XMLRPC_VALUE_TYPE_BOOLEAN, self);
893 /* Check response exists */
894 if(!response) {
895 IRRECO_DEBUG(" No response, failed at do_xmlrpc\n");
896 IRRECO_RETURN_BOOL(FALSE);
899 value = soup_xmlrpc_response_get_value (response);
901 /* Try to get gboolean out of value */
902 if(!soup_xmlrpc_value_get_boolean(value, user_exists)){
903 g_string_printf(self->error_msg,
904 "ERROR: Not proper return value\n");
905 g_object_unref (response);
906 IRRECO_RETURN_BOOL(FALSE);
909 g_object_unref (response);
910 IRRECO_RETURN_BOOL(TRUE);
913 gint irreco_webdb_client_get_max_image_size(IrrecoWebdbClient *self)
915 SoupXmlrpcMessage *msg;
916 SoupXmlrpcResponse *response;
917 SoupXmlrpcValue *value;
918 gint max_image_size = 0;
920 IRRECO_ENTER
922 msg = soup_xmlrpc_message_new (IRRECO_WEBDB_URL);
923 soup_xmlrpc_message_start_call (msg, "getMaxImageSize");
924 soup_xmlrpc_message_start_param (msg);
925 soup_xmlrpc_message_end_param (msg);
926 soup_xmlrpc_message_end_call (msg);
928 irreco_webdb_client_reset_env(self);
930 response = (SoupXmlrpcResponse*) do_xmlrpc(msg,
931 SOUP_XMLRPC_VALUE_TYPE_INT,
932 self);
934 /* Check response exists */
935 if(!response) {
936 IRRECO_DEBUG(" No response, failed at do_xmlrpc\n");
937 goto end;
940 value = soup_xmlrpc_response_get_value (response);
942 /* Try to get integer out of value */
943 if(!soup_xmlrpc_value_get_int(value, (glong *) &max_image_size)) {
944 max_image_size = 0;
947 end:
948 g_object_unref (response);
949 IRRECO_RETURN_INT(max_image_size);
952 gint irreco_webdb_client_create_theme(IrrecoWebdbClient *self,
953 const gchar *name,
954 const gchar *comment,
955 const gchar *preview_button,
956 const gchar *folder,
957 const gchar *user,
958 const gchar *password)
960 SoupXmlrpcMessage *msg;
961 SoupXmlrpcResponse *response;
962 SoupXmlrpcValue *value;
963 gint theme_id;
965 IRRECO_ENTER
966 msg = soup_xmlrpc_message_new (IRRECO_WEBDB_URL);
967 soup_xmlrpc_message_start_call (msg, "createNewTheme");
968 soup_xmlrpc_message_start_param (msg);
969 soup_xmlrpc_message_write_string(msg, name);
970 soup_xmlrpc_message_write_string(msg, comment);
971 soup_xmlrpc_message_write_string(msg, preview_button);
972 soup_xmlrpc_message_write_string(msg, folder);
973 soup_xmlrpc_message_write_string(msg, user);
974 soup_xmlrpc_message_write_string(msg, password);
975 soup_xmlrpc_message_end_param (msg);
976 soup_xmlrpc_message_end_call (msg);
978 irreco_webdb_client_reset_env(self);
980 response = (SoupXmlrpcResponse*) do_xmlrpc (msg,
981 SOUP_XMLRPC_VALUE_TYPE_INT, self);
983 /* Check response exists */
984 if(!response) {
985 IRRECO_DEBUG(" No response, failed at do_xmlrpc\n");
986 IRRECO_RETURN_BOOL(FALSE);
989 value = soup_xmlrpc_response_get_value (response);
991 /* Try to get integer out of value */
992 if(soup_xmlrpc_value_get_int(value, (glong *) &theme_id)){
993 g_object_unref (response);
994 IRRECO_RETURN_INT(theme_id);
997 g_string_printf(self->error_msg,
998 "ERROR: Not proper return value\n");
999 g_object_unref (response);
1000 IRRECO_RETURN_INT(0);
1003 gboolean irreco_webdb_client_set_theme_downloadable(IrrecoWebdbClient *self,
1004 gint id,
1005 gboolean downloadable,
1006 const gchar *user,
1007 const gchar *password)
1009 SoupXmlrpcMessage *msg;
1010 SoupXmlrpcResponse *response;
1011 SoupXmlrpcValue *value;
1012 gboolean rvalue = FALSE;
1014 IRRECO_ENTER
1015 msg = soup_xmlrpc_message_new (IRRECO_WEBDB_URL);
1016 soup_xmlrpc_message_start_call (msg, "setThemeDownloadable");
1017 soup_xmlrpc_message_start_param (msg);
1018 soup_xmlrpc_message_write_int(msg, id);
1019 soup_xmlrpc_message_write_boolean(msg, downloadable);
1020 soup_xmlrpc_message_write_string(msg, user);
1021 soup_xmlrpc_message_write_string(msg, password);
1022 soup_xmlrpc_message_end_param (msg);
1023 soup_xmlrpc_message_end_call (msg);
1025 irreco_webdb_client_reset_env(self);
1027 response = (SoupXmlrpcResponse*) do_xmlrpc (msg,
1028 SOUP_XMLRPC_VALUE_TYPE_BOOLEAN, self);
1030 /* Check response exists */
1031 if(!response) {
1032 IRRECO_DEBUG(" No response, failed at do_xmlrpc\n");
1033 IRRECO_RETURN_BOOL(FALSE);
1036 value = soup_xmlrpc_response_get_value (response);
1038 /* Try to get boolean out of value */
1039 soup_xmlrpc_value_get_boolean(value, &rvalue);
1041 g_object_unref (response);
1042 IRRECO_RETURN_BOOL(rvalue);
1045 gboolean irreco_webdb_client_get_themes(IrrecoWebdbClient *self,
1046 IrrecoStringTable **theme_list)
1048 gboolean rvalue = FALSE;
1049 SoupXmlrpcMessage *msg;
1050 SoupXmlrpcResponse *response;
1051 SoupXmlrpcValueArrayIterator *iter;
1052 SoupXmlrpcValue *value;
1053 SoupXmlrpcValue *array_val;
1054 gchar *ret = NULL;
1055 IRRECO_ENTER
1057 irreco_webdb_client_reset_env(self);
1059 *theme_list = irreco_string_table_new(NULL, NULL);
1061 irreco_webdb_client_reset_env(self);
1063 msg = soup_xmlrpc_message_new (IRRECO_WEBDB_URL);
1064 soup_xmlrpc_message_start_call (msg, "getThemes");
1065 soup_xmlrpc_message_end_call (msg);
1067 response = (SoupXmlrpcResponse*) do_xmlrpc (msg,
1068 SOUP_XMLRPC_VALUE_TYPE_ARRAY, self);
1069 if(!response) {
1070 IRRECO_DEBUG(" No response, failed something\n");
1071 IRRECO_RETURN_BOOL(rvalue);
1074 value = soup_xmlrpc_response_get_value (response);
1076 soup_xmlrpc_value_array_get_iterator(value, &iter);
1078 while (iter) {
1079 soup_xmlrpc_value_array_iterator_get_value(iter, &array_val);
1081 if (!soup_xmlrpc_value_get_string(array_val, &ret)) {
1082 IRRECO_DEBUG ("NO value\n");
1083 g_object_unref (response);
1084 IRRECO_RETURN_BOOL(rvalue);
1086 IRRECO_DEBUG("%s\n", ret);
1088 irreco_string_table_add(*theme_list, ret, NULL);
1090 iter = soup_xmlrpc_value_array_iterator_next(iter);
1093 rvalue = TRUE;
1095 IRRECO_RETURN_BOOL(rvalue);
1098 gboolean irreco_webdb_client_get_theme_by_id(IrrecoWebdbClient *self,
1099 gint theme_id,
1100 IrrecoWebdbTheme **theme)
1102 gboolean rvalue = FALSE;
1103 gchar *name = NULL;
1104 gchar *user = NULL;
1105 gchar *comment = NULL;
1106 gchar *preview_button = NULL;
1107 gchar *folder = NULL;
1108 gchar *uploaded = NULL;
1109 gchar *modified = NULL;
1110 gchar *downloaded = NULL;
1111 gint download_count;
1112 GHashTable *tmp = NULL;
1113 SoupXmlrpcValue *hash = NULL;
1114 SoupXmlrpcMessage *msg;
1115 SoupXmlrpcResponse *response = NULL;
1116 SoupXmlrpcValue *value;
1117 IRRECO_ENTER
1119 irreco_webdb_client_reset_env(self);
1121 /* Build query */
1122 msg = soup_xmlrpc_message_new (IRRECO_WEBDB_URL);
1123 soup_xmlrpc_message_start_call (msg, "getThemeById");
1124 soup_xmlrpc_message_start_param (msg);
1125 soup_xmlrpc_message_write_int(msg, (glong) theme_id);
1126 soup_xmlrpc_message_end_param (msg);
1127 soup_xmlrpc_message_end_call (msg);
1129 /* Execute XML-RPC call. */
1130 response = (SoupXmlrpcResponse*) do_xmlrpc (msg,
1131 SOUP_XMLRPC_VALUE_TYPE_STRUCT, self);
1133 /* Check response */
1134 if(!response) {
1135 IRRECO_DEBUG(" No response, failed something\n");
1136 goto end;
1139 /* Get array out from response */
1140 value = soup_xmlrpc_response_get_value (response);
1142 if(!soup_xmlrpc_value_get_struct(value, &tmp)){
1143 g_string_printf(self->error_msg,
1144 "ERROR: Not proper return value\n");
1145 goto end;
1148 /* Seek data */
1149 hash = g_hash_table_lookup(tmp, "name");
1150 if (!soup_xmlrpc_value_get_string(hash, &name)) {
1151 IRRECO_DEBUG("No value in response\n");
1152 goto end;
1155 hash = g_hash_table_lookup(tmp, "user");
1156 if (!soup_xmlrpc_value_get_string(hash, &user)) {
1157 IRRECO_DEBUG("No value in response\n");
1158 goto end;
1161 hash = g_hash_table_lookup(tmp, "comment");
1162 if (!soup_xmlrpc_value_get_string(hash, &comment)) {
1163 IRRECO_DEBUG("No value in response\n");
1164 goto end;
1167 hash = g_hash_table_lookup(tmp, "preview_button");
1168 if (!soup_xmlrpc_value_get_string(hash, &preview_button)) {
1169 IRRECO_DEBUG("No value in response\n");
1170 goto end;
1173 hash = g_hash_table_lookup(tmp, "folder");
1174 if (!soup_xmlrpc_value_get_string(hash, &folder)) {
1175 IRRECO_DEBUG("No value in response\n");
1176 goto end;
1179 hash = g_hash_table_lookup(tmp, "uploaded");
1180 if (!soup_xmlrpc_value_get_string(hash, &uploaded)) {
1181 IRRECO_DEBUG("No value in response\n");
1182 goto end;
1185 hash = g_hash_table_lookup(tmp, "modified");
1186 if (!soup_xmlrpc_value_get_string(hash, &modified)) {
1187 IRRECO_DEBUG("No value in response\n");
1188 goto end;
1191 hash = g_hash_table_lookup(tmp, "downloaded");
1192 if (!soup_xmlrpc_value_get_string(hash, &downloaded)) {
1193 IRRECO_DEBUG("No value in response\n");
1194 goto end;
1197 hash = g_hash_table_lookup(tmp, "download_count");
1198 if (!soup_xmlrpc_value_get_int(hash, (glong *) &download_count)) {
1199 IRRECO_DEBUG("No value in response\n");
1200 goto end;
1203 *theme = irreco_webdb_theme_new();
1205 irreco_webdb_theme_set(*theme, theme_id, name, user, comment,
1206 preview_button, NULL, folder, uploaded, modified,
1207 downloaded, download_count);
1209 irreco_webdb_client_get_theme_versions_by_name(self, name,
1210 &(*theme)->versions);
1212 /* Get dates for versions */
1213 if ((*theme)->versions != NULL)
1215 IRRECO_STRING_TABLE_FOREACH_KEY((*theme)->versions, key)
1216 gchar *date = irreco_webdb_client_get_theme_date_by_id(
1217 self, atoi(key));
1219 irreco_string_table_change_data ((*theme)->versions,
1220 key, (gpointer) date);
1221 IRRECO_STRING_TABLE_FOREACH_END
1224 /* No error occured. */
1225 rvalue = TRUE;
1227 end:
1228 if (response != NULL) g_object_unref(response);
1229 if (tmp != NULL) g_hash_table_destroy(tmp);
1230 if (name != NULL) g_free(name);
1231 if (user != NULL) g_free(user);
1232 if (comment != NULL) g_free(comment);
1233 if (preview_button != NULL) g_free(preview_button);
1234 if (folder != NULL) g_free(folder);
1235 if (uploaded != NULL) g_free(uploaded);
1236 if (modified != NULL) g_free(modified);
1237 if (downloaded != NULL) g_free(downloaded);
1239 IRRECO_RETURN_BOOL(rvalue);
1242 gboolean irreco_webdb_client_get_theme_versions_by_name(IrrecoWebdbClient *self,
1243 const char *name,
1244 IrrecoStringTable **theme_list)
1246 gboolean rvalue = FALSE;
1247 SoupXmlrpcMessage *msg;
1248 SoupXmlrpcResponse *response;
1249 SoupXmlrpcValueArrayIterator *iter;
1250 SoupXmlrpcValue *value;
1251 SoupXmlrpcValue *array_val;
1252 gchar *ret = NULL;
1253 IRRECO_ENTER
1255 irreco_webdb_client_reset_env(self);
1257 *theme_list = irreco_string_table_new(NULL, NULL);
1259 irreco_webdb_client_reset_env(self);
1261 msg = soup_xmlrpc_message_new (IRRECO_WEBDB_URL);
1262 soup_xmlrpc_message_start_call (msg, "getThemeVersionsByName");
1263 soup_xmlrpc_message_start_param (msg);
1264 soup_xmlrpc_message_write_string(msg, name);
1265 soup_xmlrpc_message_end_param (msg);
1266 soup_xmlrpc_message_end_call (msg);
1268 response = (SoupXmlrpcResponse*) do_xmlrpc (msg,
1269 SOUP_XMLRPC_VALUE_TYPE_ARRAY, self);
1270 if(!response) {
1271 IRRECO_DEBUG(" No response, failed something\n");
1272 goto end;
1275 value = soup_xmlrpc_response_get_value (response);
1277 soup_xmlrpc_value_array_get_iterator(value, &iter);
1279 while (iter) {
1280 soup_xmlrpc_value_array_iterator_get_value(iter, &array_val);
1282 if (!soup_xmlrpc_value_get_string(array_val, &ret)) {
1283 IRRECO_DEBUG ("NO value\n");
1284 goto end;
1286 IRRECO_DEBUG("%s\n", ret);
1288 irreco_string_table_add(*theme_list, ret, NULL);
1290 iter = soup_xmlrpc_value_array_iterator_next(iter);
1293 rvalue = TRUE;
1295 end:
1296 if (rvalue == FALSE) irreco_string_table_free(*theme_list);
1297 g_object_unref (response);
1299 IRRECO_RETURN_BOOL(rvalue);
1302 gchar *irreco_webdb_client_get_theme_date_by_id(IrrecoWebdbClient *self,
1303 gint theme_id)
1305 SoupXmlrpcMessage *msg;
1306 SoupXmlrpcResponse *response;
1307 SoupXmlrpcValue *value;
1308 gchar *date = NULL;
1310 IRRECO_ENTER
1312 msg = soup_xmlrpc_message_new (IRRECO_WEBDB_URL);
1313 soup_xmlrpc_message_start_call (msg, "getThemeDateById");
1314 soup_xmlrpc_message_start_param (msg);
1315 soup_xmlrpc_message_write_int(msg, theme_id);
1316 soup_xmlrpc_message_end_param (msg);
1317 soup_xmlrpc_message_end_call (msg);
1319 irreco_webdb_client_reset_env(self);
1321 response = (SoupXmlrpcResponse*)do_xmlrpc(msg,
1322 SOUP_XMLRPC_VALUE_TYPE_STRING,
1323 self);
1325 /* Check response exists */
1326 if(!response) {
1327 IRRECO_DEBUG(" No response, failed at do_xmlrpc\n");
1328 goto end;
1331 value = soup_xmlrpc_response_get_value (response);
1333 /* Try to get integer out of value */
1334 if(!soup_xmlrpc_value_get_string(value, &date)) {
1335 date = NULL;
1338 end:
1339 g_object_unref (response);
1340 IRRECO_RETURN_PTR(date);
1342 gint irreco_webdb_client_add_bg_to_theme(IrrecoWebdbClient *self,
1343 const gchar *name,
1344 const gchar *image_hash,
1345 const gchar *image_name,
1346 const guchar *image,
1347 gint image_len,
1348 const gchar *folder,
1349 gint theme_id,
1350 const gchar *user,
1351 const gchar *password)
1353 SoupXmlrpcMessage *msg;
1354 SoupXmlrpcResponse *response;
1355 SoupXmlrpcValue *value;
1356 gint bg_id;
1357 gchar *base64_image;
1358 IRRECO_ENTER
1360 base64_image = g_base64_encode(image, image_len);
1362 msg = soup_xmlrpc_message_new (IRRECO_WEBDB_URL);
1363 soup_xmlrpc_message_start_call (msg, "addBgToTheme");
1364 soup_xmlrpc_message_start_param (msg);
1365 soup_xmlrpc_message_write_string(msg, name);
1366 soup_xmlrpc_message_write_string(msg, image_hash);
1367 soup_xmlrpc_message_write_string(msg, image_name);
1368 soup_xmlrpc_message_write_string(msg, base64_image);
1369 soup_xmlrpc_message_write_string(msg, folder);
1370 soup_xmlrpc_message_write_int(msg, theme_id);
1371 soup_xmlrpc_message_write_string(msg, user);
1372 soup_xmlrpc_message_write_string(msg, password);
1373 soup_xmlrpc_message_end_param (msg);
1374 soup_xmlrpc_message_end_call (msg);
1376 g_free(base64_image);
1378 irreco_webdb_client_reset_env(self);
1380 response = (SoupXmlrpcResponse*) do_xmlrpc (msg,
1381 SOUP_XMLRPC_VALUE_TYPE_INT, self);
1383 /* Check response exists */
1384 if(!response) {
1385 IRRECO_DEBUG(" No response, failed at do_xmlrpc\n");
1386 IRRECO_RETURN_BOOL(FALSE);
1389 value = soup_xmlrpc_response_get_value (response);
1391 /* Try to get integer out of value */
1392 if(soup_xmlrpc_value_get_int(value, (glong *) &bg_id)){
1393 g_object_unref (response);
1394 IRRECO_RETURN_INT(bg_id);
1397 g_string_printf(self->error_msg,
1398 "ERROR: Not proper return value\n");
1399 g_object_unref (response);
1400 IRRECO_RETURN_INT(0);
1403 gboolean irreco_webdb_client_get_backgrounds(IrrecoWebdbClient *self,
1404 gint theme_id,
1405 IrrecoStringTable **bg_list)
1407 gboolean rvalue = FALSE;
1408 SoupXmlrpcMessage *msg;
1409 SoupXmlrpcResponse *response;
1410 SoupXmlrpcValueArrayIterator *iter;
1411 SoupXmlrpcValue *value;
1412 SoupXmlrpcValue *array_val;
1413 gchar *ret = NULL;
1414 IRRECO_ENTER
1416 irreco_webdb_client_reset_env(self);
1418 *bg_list = irreco_string_table_new(NULL, NULL);
1420 irreco_webdb_client_reset_env(self);
1422 msg = soup_xmlrpc_message_new (IRRECO_WEBDB_URL);
1423 soup_xmlrpc_message_start_call (msg, "getBackgrounds");
1424 soup_xmlrpc_message_start_param (msg);
1425 soup_xmlrpc_message_write_int(msg, theme_id);
1426 soup_xmlrpc_message_end_param (msg);
1427 soup_xmlrpc_message_end_call (msg);
1429 response = (SoupXmlrpcResponse*) do_xmlrpc (msg,
1430 SOUP_XMLRPC_VALUE_TYPE_ARRAY, self);
1431 if(!response) {
1432 IRRECO_DEBUG(" No response, failed something\n");
1433 IRRECO_RETURN_BOOL(rvalue);
1436 value = soup_xmlrpc_response_get_value (response);
1438 soup_xmlrpc_value_array_get_iterator(value, &iter);
1440 while (iter) {
1441 soup_xmlrpc_value_array_iterator_get_value(iter, &array_val);
1443 if (!soup_xmlrpc_value_get_string(array_val, &ret)) {
1444 IRRECO_DEBUG ("NO value\n");
1445 goto end;
1447 IRRECO_DEBUG("%s\n", ret);
1449 irreco_string_table_add(*bg_list, ret, NULL);
1450 g_free(ret);
1452 iter = soup_xmlrpc_value_array_iterator_next(iter);
1455 rvalue = TRUE;
1456 end:
1457 if(rvalue == FALSE) {
1458 irreco_string_table_free (*bg_list);
1459 *bg_list = NULL;
1461 g_object_unref (response);
1463 IRRECO_RETURN_BOOL(rvalue);
1467 gboolean irreco_webdb_client_get_bg_by_id(IrrecoWebdbClient *self,
1468 gint bg_id,
1469 const char *theme_bg_dir)
1471 gboolean rvalue = FALSE;
1472 gchar *name = NULL;
1473 gchar *image_hash = NULL;
1474 gchar *image_name = NULL;
1475 gchar *image_data = NULL;
1476 gchar *base64_image = NULL;
1477 gchar *folder = NULL;
1478 GHashTable *tmp = NULL;
1479 SoupXmlrpcValue *hash = NULL;
1480 SoupXmlrpcMessage *msg;
1481 SoupXmlrpcResponse *response;
1482 SoupXmlrpcValue *value;
1483 GString *keyfile_path = g_string_new(theme_bg_dir);
1484 GString *image_path = g_string_new(theme_bg_dir);
1485 GKeyFile *keyfile = g_key_file_new();
1486 gsize base64_len;
1487 IRRECO_ENTER
1489 irreco_webdb_client_reset_env(self);
1491 /* Build query */
1492 msg = soup_xmlrpc_message_new (IRRECO_WEBDB_URL);
1493 soup_xmlrpc_message_start_call (msg, "getBgById");
1494 soup_xmlrpc_message_start_param (msg);
1495 soup_xmlrpc_message_write_int(msg, (glong) bg_id);
1496 soup_xmlrpc_message_end_param (msg);
1497 soup_xmlrpc_message_end_call (msg);
1499 /* Execute XML-RPC call. */
1500 response = (SoupXmlrpcResponse*) do_xmlrpc (msg,
1501 SOUP_XMLRPC_VALUE_TYPE_STRUCT, self);
1503 /* Check response */
1504 if(!response) {
1505 IRRECO_DEBUG(" No response, failed something\n");
1506 goto end;
1509 /* Get array out from response */
1510 value = soup_xmlrpc_response_get_value (response);
1512 if(!soup_xmlrpc_value_get_struct(value, &tmp)){
1513 g_string_printf(self->error_msg,
1514 "ERROR: Not proper return value\n");
1515 goto end;
1518 /* Seek data */
1519 hash = g_hash_table_lookup(tmp, "name");
1520 if (!soup_xmlrpc_value_get_string(hash, &name)) {
1521 IRRECO_DEBUG("No value in response\n");
1522 goto end;
1525 hash = g_hash_table_lookup(tmp, "image_hash");
1526 if (!soup_xmlrpc_value_get_string(hash, &image_hash)) {
1527 IRRECO_DEBUG("No value in response\n");
1528 goto end;
1531 hash = g_hash_table_lookup(tmp, "image_name");
1532 if (!soup_xmlrpc_value_get_string(hash, &image_name)) {
1533 IRRECO_DEBUG("No value in response\n");
1534 goto end;
1537 hash = g_hash_table_lookup(tmp, "image_data");
1538 if (!soup_xmlrpc_value_get_string(hash, &base64_image)) {
1539 IRRECO_DEBUG("No value in response\n");
1540 goto end;
1543 hash = g_hash_table_lookup(tmp, "folder");
1544 if (!soup_xmlrpc_value_get_string(hash, &folder)) {
1545 IRRECO_DEBUG("No value in response\n");
1546 goto end;
1549 /* Create Folder */
1550 g_string_append_printf(image_path, "/%s", folder);
1551 IRRECO_DEBUG("mkdir %s\n",image_path->str);
1552 g_mkdir(image_path->str, 0777);
1554 /* Save image to folder */
1555 image_data = (gchar*) g_base64_decode(base64_image, &base64_len);
1556 g_string_append_printf(image_path, "/%s", image_name);
1557 irreco_write_file(image_path->str, image_data, base64_len);
1559 /* Create keyfile and save it to folder*/
1560 irreco_gkeyfile_set_string(keyfile, "theme-bg" , "name", name);
1561 irreco_gkeyfile_set_string(keyfile, "theme-bg", "image", image_name);
1562 g_string_append_printf(keyfile_path, "/%s/bg.conf", folder);
1563 irreco_write_keyfile(keyfile, keyfile_path->str);
1565 /* No error occured. */
1566 rvalue = TRUE;
1568 end:
1569 g_object_unref (response);
1570 if (tmp != NULL) g_hash_table_destroy (tmp);
1571 if (name != NULL) g_free(name);
1572 if (image_hash != NULL) g_free(image_hash);
1573 if (image_name != NULL) g_free(image_name);
1574 if (image_data != NULL) g_free(image_data);
1575 if (base64_image != NULL) g_free(base64_image);
1576 if (folder != NULL) g_free(folder);
1578 g_key_file_free(keyfile);
1579 g_string_free(keyfile_path, TRUE);
1580 g_string_free(image_path, TRUE);
1582 IRRECO_RETURN_BOOL(rvalue);
1585 gint irreco_webdb_client_add_button_to_theme(IrrecoWebdbClient *self,
1586 const gchar *name,
1587 gboolean allow_text,
1588 const gchar *text_format_up,
1589 const gchar *text_format_down,
1590 gint text_padding,
1591 const gchar *image_up_hash,
1592 const gchar *image_up_name,
1593 const guchar *image_up,
1594 gint image_up_len,
1595 const gchar *image_down_hash,
1596 const gchar *image_down_name,
1597 const guchar *image_down,
1598 gint image_down_len,
1599 const gchar *folder,
1600 gint theme_id,
1601 const gchar *user,
1602 const gchar *password)
1604 SoupXmlrpcMessage *msg;
1605 SoupXmlrpcResponse *response;
1606 SoupXmlrpcValue *value;
1607 gint button_id;
1608 gchar *base64_image_up;
1609 gchar *base64_image_down;
1610 IRRECO_ENTER
1612 base64_image_up = g_base64_encode(image_up, image_up_len);
1613 base64_image_down = g_base64_encode(image_down, image_down_len);
1615 msg = soup_xmlrpc_message_new (IRRECO_WEBDB_URL);
1616 soup_xmlrpc_message_start_call (msg, "addButtonToTheme");
1617 soup_xmlrpc_message_start_param (msg);
1618 soup_xmlrpc_message_write_string(msg, name);
1619 soup_xmlrpc_message_write_boolean(msg, allow_text);
1620 soup_xmlrpc_message_write_string(msg, text_format_up);
1621 soup_xmlrpc_message_write_string(msg, text_format_down);
1622 soup_xmlrpc_message_write_int(msg, text_padding);
1623 soup_xmlrpc_message_write_string(msg, image_up_hash);
1624 soup_xmlrpc_message_write_string(msg, image_up_name);
1625 soup_xmlrpc_message_write_string(msg, base64_image_up);
1626 soup_xmlrpc_message_write_string(msg, image_down_hash);
1627 soup_xmlrpc_message_write_string(msg, image_down_name);
1628 soup_xmlrpc_message_write_string(msg, base64_image_down);
1629 soup_xmlrpc_message_write_string(msg, folder);
1630 soup_xmlrpc_message_write_int(msg, theme_id);
1631 soup_xmlrpc_message_write_string(msg, user);
1632 soup_xmlrpc_message_write_string(msg, password);
1633 soup_xmlrpc_message_end_param (msg);
1634 soup_xmlrpc_message_end_call (msg);
1636 g_free(base64_image_up);
1637 g_free(base64_image_down);
1639 irreco_webdb_client_reset_env(self);
1641 response = (SoupXmlrpcResponse*) do_xmlrpc (msg,
1642 SOUP_XMLRPC_VALUE_TYPE_INT, self);
1644 /* Check response exists */
1645 if(!response) {
1646 IRRECO_DEBUG(" No response, failed at do_xmlrpc\n");
1647 IRRECO_RETURN_BOOL(FALSE);
1650 value = soup_xmlrpc_response_get_value (response);
1652 /* Try to get integer out of value */
1653 if(soup_xmlrpc_value_get_int(value, (glong *) &button_id)){
1654 g_object_unref (response);
1655 IRRECO_RETURN_INT(button_id);
1658 g_string_printf(self->error_msg,
1659 "ERROR: Not proper return value\n");
1660 g_object_unref (response);
1661 IRRECO_RETURN_INT(0);
1664 gboolean irreco_webdb_client_get_buttons(IrrecoWebdbClient *self,
1665 gint theme_id,
1666 IrrecoStringTable **button_list)
1668 gboolean rvalue = FALSE;
1669 SoupXmlrpcMessage *msg;
1670 SoupXmlrpcResponse *response;
1671 SoupXmlrpcValueArrayIterator *iter;
1672 SoupXmlrpcValue *value;
1673 SoupXmlrpcValue *array_val;
1674 gchar *ret = NULL;
1675 IRRECO_ENTER
1677 irreco_webdb_client_reset_env(self);
1679 *button_list = irreco_string_table_new(NULL, NULL);
1681 irreco_webdb_client_reset_env(self);
1683 msg = soup_xmlrpc_message_new (IRRECO_WEBDB_URL);
1684 soup_xmlrpc_message_start_call (msg, "getButtons");
1685 soup_xmlrpc_message_start_param (msg);
1686 soup_xmlrpc_message_write_int(msg, theme_id);
1687 soup_xmlrpc_message_end_param (msg);
1688 soup_xmlrpc_message_end_call (msg);
1690 response = (SoupXmlrpcResponse*) do_xmlrpc (msg,
1691 SOUP_XMLRPC_VALUE_TYPE_ARRAY, self);
1692 if(!response) {
1693 IRRECO_DEBUG(" No response, failed something\n");
1694 IRRECO_RETURN_BOOL(rvalue);
1697 value = soup_xmlrpc_response_get_value (response);
1699 soup_xmlrpc_value_array_get_iterator(value, &iter);
1701 while (iter) {
1702 soup_xmlrpc_value_array_iterator_get_value(iter, &array_val);
1704 if (!soup_xmlrpc_value_get_string(array_val, &ret)) {
1705 IRRECO_DEBUG ("NO value\n");
1706 goto end;
1708 IRRECO_DEBUG("%s\n", ret);
1710 irreco_string_table_add(*button_list, ret, NULL);
1711 g_free(ret);
1713 iter = soup_xmlrpc_value_array_iterator_next(iter);
1716 rvalue = TRUE;
1717 end:
1718 if(rvalue == FALSE) {
1719 irreco_string_table_free (*button_list);
1720 *button_list = NULL;
1722 g_object_unref (response);
1724 IRRECO_RETURN_BOOL(rvalue);
1728 gboolean irreco_webdb_client_get_button_by_id(IrrecoWebdbClient *self,
1729 gint button_id,
1730 const char *theme_button_dir)
1732 gboolean rvalue = FALSE;
1733 gchar *name = NULL;
1734 gboolean allow_text = FALSE;
1735 gchar *text_format_up = NULL;
1736 gchar *text_format_down = NULL;
1737 gint text_padding;
1738 gchar *image_up_hash = NULL;
1739 gchar *image_up_name = NULL;
1740 gchar *image_up = NULL;
1741 gchar *base64_image_up = NULL;
1742 gchar *image_down_hash = NULL;
1743 gchar *image_down_name = NULL;
1744 gchar *image_down = NULL;
1745 gchar *base64_image_down = NULL;
1746 gchar *folder = NULL;
1747 gchar *image_down_hash_tmp = NULL;
1748 GHashTable *tmp = NULL;
1749 SoupXmlrpcValue *hash = NULL;
1750 SoupXmlrpcMessage *msg;
1751 SoupXmlrpcResponse *response;
1752 SoupXmlrpcValue *value;
1753 GString *file_path = g_string_new("");
1754 GKeyFile *keyfile = g_key_file_new();
1755 gsize image_down_len;
1756 gsize image_up_len;
1757 IRRECO_ENTER
1759 irreco_webdb_client_reset_env(self);
1761 /* Build query */
1762 msg = soup_xmlrpc_message_new (IRRECO_WEBDB_URL);
1763 soup_xmlrpc_message_start_call (msg, "getButtonById");
1764 soup_xmlrpc_message_start_param (msg);
1765 soup_xmlrpc_message_write_int(msg, (glong) button_id);
1766 soup_xmlrpc_message_end_param (msg);
1767 soup_xmlrpc_message_end_call (msg);
1769 /* Execute XML-RPC call. */
1770 response = (SoupXmlrpcResponse*) do_xmlrpc (msg,
1771 SOUP_XMLRPC_VALUE_TYPE_STRUCT, self);
1773 /* Check response */
1774 if(!response) {
1775 IRRECO_DEBUG(" No response, failed something\n");
1776 goto end;
1779 /* Get array out from response */
1780 value = soup_xmlrpc_response_get_value (response);
1782 if(!soup_xmlrpc_value_get_struct(value, &tmp)){
1783 g_string_printf(self->error_msg,
1784 "ERROR: Not proper return value\n");
1785 goto end;
1788 /* Seek data */
1789 hash = g_hash_table_lookup(tmp, "name");
1790 if (!soup_xmlrpc_value_get_string(hash, &name)) {
1791 IRRECO_DEBUG("No value in response\n");
1792 goto end;
1795 hash = g_hash_table_lookup(tmp, "allow_text");
1796 if (!soup_xmlrpc_value_get_boolean(hash, &allow_text)) {
1797 IRRECO_DEBUG("No value in response\n");
1798 goto end;
1801 hash = g_hash_table_lookup(tmp, "text_format_up");
1802 soup_xmlrpc_value_get_string(hash, &text_format_up);
1804 hash = g_hash_table_lookup(tmp, "text_format_down");
1805 soup_xmlrpc_value_get_string(hash, &text_format_down);
1807 hash = g_hash_table_lookup(tmp, "text_padding");
1808 if (!soup_xmlrpc_value_get_int(hash, (glong *) &text_padding)) {
1809 IRRECO_DEBUG("No value in response\n");
1810 goto end;
1813 hash = g_hash_table_lookup(tmp, "image_up_hash");
1814 if (!soup_xmlrpc_value_get_string(hash, &image_up_hash)) {
1815 IRRECO_DEBUG("No value in response\n");
1816 goto end;
1819 hash = g_hash_table_lookup(tmp, "image_up_name");
1820 if (!soup_xmlrpc_value_get_string(hash, &image_up_name)) {
1821 IRRECO_DEBUG("No value in response\n");
1822 goto end;
1825 hash = g_hash_table_lookup(tmp, "image_up");
1826 if (!soup_xmlrpc_value_get_string(hash, &base64_image_up)) {
1827 IRRECO_DEBUG("No value in response\n");
1828 goto end;
1831 hash = g_hash_table_lookup(tmp, "image_down_hash");
1832 if (!soup_xmlrpc_value_get_string(hash, &image_down_hash)) {
1833 IRRECO_DEBUG("No value in response\n");
1834 goto end;
1837 hash = g_hash_table_lookup(tmp, "image_down_name");
1838 if (!soup_xmlrpc_value_get_string(hash, &image_down_name)) {
1839 IRRECO_DEBUG("No value in response\n");
1840 IRRECO_LINE
1841 goto end;
1844 hash = g_hash_table_lookup(tmp, "image_down");
1845 if (!soup_xmlrpc_value_get_string(hash, &base64_image_down)) {
1846 IRRECO_DEBUG("No value in response\n");
1847 goto end;
1850 hash = g_hash_table_lookup(tmp, "folder");
1851 if (!soup_xmlrpc_value_get_string(hash, &folder)) {
1852 IRRECO_DEBUG("No value in response\n");
1853 goto end;
1856 /* Create Folder */
1857 g_string_printf(file_path, "%s/%s", theme_button_dir, folder);
1858 IRRECO_DEBUG("mkdir %s\n",file_path->str);
1859 g_mkdir(file_path->str, 0777);
1861 /* Save image_up to folder */
1862 g_string_printf(file_path, "%s/%s/%s", theme_button_dir, folder,
1863 image_up_name);
1864 image_up = (gchar*) g_base64_decode(base64_image_up, &image_up_len);
1865 irreco_write_file(file_path->str, image_up, image_up_len);
1867 /* Save image_down to folder */
1868 g_string_printf(file_path, "%s/%s/%s", theme_button_dir, folder,
1869 image_down_name);
1871 /*Check image hash data*/
1872 image_down = (gchar*) g_base64_decode(base64_image_down,
1873 &image_down_len);
1874 irreco_write_file(file_path->str, image_down, image_down_len);
1875 image_down_hash_tmp = sha_compute_checksum_for_string(G_CHECKSUM_SHA1,
1876 image_down,
1877 image_down_len);
1879 if (!g_str_equal(image_down_hash, image_down_hash_tmp)) {
1881 g_string_printf(self->error_msg,
1882 "ERROR: Button's data are corrupt\n");
1883 goto end;
1886 /* Create keyfile and save it to folder*/
1887 irreco_gkeyfile_set_string(keyfile, "theme-button" , "name", name);
1889 if (allow_text) {
1890 irreco_gkeyfile_set_string(keyfile, "theme-button",
1891 "allow-text", "true");
1892 } else {
1893 irreco_gkeyfile_set_string(keyfile, "theme-button",
1894 "allow-text", "false");
1897 irreco_gkeyfile_set_string(keyfile, "theme-button",
1898 "up", image_up_name);
1900 irreco_gkeyfile_set_string(keyfile, "theme-button",
1901 "down", image_down_name);
1903 if (text_format_up != NULL && strlen(text_format_up) > 0) {
1904 irreco_gkeyfile_set_string(keyfile, "theme-button",
1905 "text-format-up", text_format_up);
1908 if (text_format_down != NULL && strlen(text_format_down) > 0) {
1909 irreco_gkeyfile_set_string(keyfile, "theme-button",
1910 "text-format-down", text_format_down);
1913 irreco_gkeyfile_set_glong(keyfile, "theme-button",
1914 "text-padding", (glong)text_padding);
1916 g_string_printf(file_path, "%s/%s/button.conf",
1917 theme_button_dir, folder);
1918 irreco_write_keyfile(keyfile, file_path->str);
1920 /* No error occured. */
1921 rvalue = TRUE;
1923 end:
1925 g_object_unref (response);
1926 if (tmp != NULL) g_hash_table_destroy (tmp);
1927 if (name != NULL) g_free(name);
1928 if (text_format_up != NULL) g_free(text_format_up);
1929 if (text_format_down != NULL) g_free(text_format_down);
1930 if (image_up_hash != NULL) g_free(image_up_hash);
1931 if (image_up_name != NULL) g_free(image_up_name);
1932 if (image_up != NULL) g_free(image_up);
1933 if (base64_image_up != NULL) g_free(base64_image_up);
1934 if (image_down_hash != NULL) g_free(image_down_hash);
1935 if (image_down_name != NULL) g_free(image_down_name);
1936 if (image_down != NULL) g_free(image_down);
1937 if (image_down_hash_tmp != NULL) g_free(image_down_hash_tmp);
1938 if (base64_image_down != NULL) g_free(base64_image_down);
1939 if (folder != NULL) g_free(folder);
1941 g_key_file_free(keyfile);
1942 g_string_free(file_path, TRUE);
1944 IRRECO_RETURN_BOOL(rvalue);
1947 gboolean irreco_webdb_client_get_preview_button(IrrecoWebdbClient *self,
1948 gint theme_id,
1949 GdkPixbuf **preview_button)
1951 gboolean rvalue = FALSE;
1952 SoupXmlrpcMessage *msg;
1953 SoupXmlrpcResponse *response;
1954 SoupXmlrpcValue *value;
1955 char *base64_data = NULL;
1956 guchar *data;
1957 gsize len;
1958 GdkPixbufLoader *pl;
1959 GError *error = NULL;
1960 IRRECO_ENTER
1962 msg = soup_xmlrpc_message_new (IRRECO_WEBDB_URL);
1963 soup_xmlrpc_message_start_call (msg, "getPreviewButton");
1964 soup_xmlrpc_message_start_param (msg);
1965 soup_xmlrpc_message_write_int(msg, theme_id);
1966 soup_xmlrpc_message_end_param (msg);
1967 soup_xmlrpc_message_end_call (msg);
1969 irreco_webdb_client_reset_env(self);
1971 response = (SoupXmlrpcResponse*) do_xmlrpc (msg,
1972 SOUP_XMLRPC_VALUE_TYPE_STRING, self);
1974 /* Check response exists */
1975 if(!response) {
1976 IRRECO_DEBUG(" No response, failed at do_xmlrpc\n");
1977 goto end;
1980 value = soup_xmlrpc_response_get_value (response);
1982 /* Try to get string out of value */
1983 if(!soup_xmlrpc_value_get_string(value, &base64_data)){
1984 g_string_printf(self->error_msg,
1985 "ERROR: Not proper return value\n");
1986 goto end;
1989 data = g_base64_decode(base64_data, &len);
1991 pl = gdk_pixbuf_loader_new();
1993 gdk_pixbuf_loader_write(pl, data, len, &error);
1995 if(error != NULL)
1997 g_string_printf(self->error_msg, "ERROR: %s", error->message);
1998 IRRECO_DEBUG("%s\n", error->message);
1999 goto end;
2002 gdk_pixbuf_loader_close(pl, NULL);
2003 *preview_button = gdk_pixbuf_loader_get_pixbuf(pl);
2005 rvalue = TRUE;
2007 end:
2008 g_object_unref (response);
2009 if (base64_data != NULL) g_free(base64_data);
2011 IRRECO_RETURN_BOOL(rvalue);
2014 static SoupXmlrpcResponse *do_xmlrpc(SoupXmlrpcMessage *xmsg,
2015 SoupXmlrpcValueType type,
2016 IrrecoWebdbClient *self)
2018 SoupSession *session;
2019 int status; /* Status of sent message */
2020 SoupMessage *spmsg = NULL; /* Soupmessage */
2021 SoupXmlrpcResponse *response = NULL; /* Response */
2022 SoupXmlrpcValue *value = NULL; /* Value from response */
2023 gchar *resbodykeeper; /* Tmp response holder */
2024 gboolean error = FALSE;
2026 IRRECO_ENTER
2028 session = soup_session_sync_new(); /* Init new synchronous session */
2030 soup_xmlrpc_message_persist (xmsg); /* Lock message */
2032 spmsg = SOUP_MESSAGE(xmsg); /* soup XMLRPC msg to soup msg */
2034 /* Add irreco version to message header */
2035 soup_message_add_header(spmsg->request_headers,
2036 "User-Agent", PACKAGE_NAME "/" VERSION);
2038 IRRECO_DEBUG("Send soup message\n");
2039 status = soup_session_send_message (session, spmsg); /* Send msg */
2041 soup_session_abort (session); /* Session cleanup */
2043 g_object_unref (session);
2045 /* Print request length and response */
2046 /*IRRECO_DEBUG("\n%.*s\n%d %s\n%.*s\n",
2047 spmsg->request.length, spmsg->request.body,
2048 spmsg->status_code, spmsg->reason_phrase,
2049 spmsg->response.length, spmsg->response.body);*/
2050 IRRECO_DEBUG("\nRequest length: %d\nStatus code: %d %s\nResponse: %.*s\n",
2051 spmsg->request.length,
2052 spmsg->status_code, spmsg->reason_phrase,
2053 spmsg->response.length, spmsg->response.body);
2055 /* Check status of sent message */
2056 if (g_strrstr(spmsg->response.body, "faultCode") != NULL) {
2058 gchar *errmsg; /* error message */
2059 IRRECO_DEBUG("Found faultCode, parse response\n");
2060 IRRECO_DEBUG("%s\n",spmsg->response.body);
2062 errmsg = g_malloc0(strlen(spmsg->response.body)*sizeof(gchar));
2065 /* TODO */
2066 /* Error code and message could be combined to be Error: <num> <msg> */
2067 /* if thats possible to do easily */
2068 strcpy(errmsg, "Error code: ");
2070 /* Parse spmsgrspbd to start "<int>" */
2071 spmsg->response.body = g_strrstr(spmsg->response.body, "<int>");
2073 resbodykeeper = g_strdup( spmsg->response.body );
2075 /* Copy part of response to errmsg */
2076 strcpy(&errmsg[12], &resbodykeeper[5]);
2078 /* Calc errorcode length and insert ", Error Message: " */
2079 /* in place of "</int>" */
2080 strcpy(&errmsg[strlen(errmsg)-strlen(g_strrstr(errmsg,
2081 "</int>"))], ", Error Message: ");
2083 /* Cut 'til "<string>" */
2084 resbodykeeper = g_strrstr(resbodykeeper, "<string>");
2086 /* Copy error message from after "<string>" into errmsg */
2087 strcpy(&errmsg[strlen(errmsg)], &resbodykeeper[8]);
2089 /* Cut "</string>" and everything after it */
2090 strcpy(&errmsg[strlen(errmsg)-strlen(g_strrstr(errmsg, "</string>"))], "");
2092 /* Parsed error message to right variable */
2093 g_string_printf(self->error_msg, "%s\n", errmsg);
2095 /* Free errmsg resource */
2096 g_free(errmsg);
2097 errmsg = NULL;
2099 error = TRUE;
2100 goto cleanup;
2102 IRRECO_LINE
2103 /* Handle http failures, eg. 404 */
2104 if (!SOUP_STATUS_IS_SUCCESSFUL (status)) {
2105 IRRECO_DEBUG("HTTP failure\n");
2106 g_string_printf(self->error_msg, "%d %s\n",
2107 status, spmsg->reason_phrase);
2109 error = TRUE;
2110 goto cleanup;
2113 /* Parse response */
2114 response = soup_xmlrpc_response_new();
2115 response = soup_xmlrpc_message_parse_response (xmsg);
2117 /* Handle fault responses */
2118 if (!response) {
2119 IRRECO_DEBUG("ERROR: no response\n");
2120 g_string_printf(self->error_msg, "ERROR: no response\n");
2121 error = TRUE;
2122 goto cleanup;
2125 if (soup_xmlrpc_response_is_fault (response)) {
2126 IRRECO_DEBUG("ERROR: response is fault\n");
2127 g_string_printf(self->error_msg, "ERROR: response is fault\n");
2128 error = TRUE;
2129 goto cleanup;
2132 /* Get value(s) from response */
2133 value = soup_xmlrpc_response_get_value(response);
2135 /* Handle wrong type and no value situations */
2136 if (!value) {
2137 IRRECO_DEBUG("ERROR: no value\n");
2138 g_string_printf(self->error_msg, "ERROR: no value\n");
2139 error = TRUE;
2140 goto cleanup;
2143 if (soup_xmlrpc_value_get_type (value) != type) {
2144 IRRECO_DEBUG("ERROR: wrong value type\nexpected %s, got %s\n",
2145 value_type[type],
2146 value_type[soup_xmlrpc_value_get_type (value)]);
2148 g_string_printf(self->error_msg,
2149 "ERROR: wrong value type\nexpected %s, got %s\n",
2150 value_type[type],
2151 value_type[soup_xmlrpc_value_get_type (value)]);
2153 error = TRUE;
2154 goto cleanup;
2157 cleanup:
2158 /* Unref soupmessage */
2159 if (spmsg != NULL && !error) {
2160 g_object_unref(spmsg);
2161 spmsg = NULL;
2164 if(error) {
2165 if (response != NULL) g_object_unref(response);
2166 response = NULL;
2169 IRRECO_RETURN_PTR(response);
2172 gboolean irreco_webdb_client_add_user(IrrecoWebdbClient *self,
2173 const gchar *name,
2174 const gchar *email,
2175 const gchar *passwd)
2177 gboolean rvalue = TRUE;
2179 SoupXmlrpcMessage *msg;
2180 SoupXmlrpcResponse *response;
2181 SoupXmlrpcValue *value;
2182 /*gboolean result;*/
2184 IRRECO_ENTER
2186 /* Init msg with URI and other data */
2187 msg = soup_xmlrpc_message_new (IRRECO_WEBDB_URL);
2188 soup_xmlrpc_message_start_call (msg, "addUser");
2190 soup_xmlrpc_message_start_param (msg);
2191 soup_xmlrpc_message_write_string(msg, name);
2192 soup_xmlrpc_message_end_param (msg);
2194 soup_xmlrpc_message_start_param (msg);
2195 soup_xmlrpc_message_write_string(msg, email);
2196 soup_xmlrpc_message_end_param (msg);
2198 soup_xmlrpc_message_start_param (msg);
2199 soup_xmlrpc_message_write_string(msg, passwd);
2200 soup_xmlrpc_message_end_param (msg);
2202 soup_xmlrpc_message_end_call (msg);
2204 /* Reset error params */
2205 irreco_webdb_client_reset_env(self);
2207 /* Execute XML-RPC call. */
2208 response = (SoupXmlrpcResponse*) do_xmlrpc (msg,
2209 SOUP_XMLRPC_VALUE_TYPE_BOOLEAN, self);
2211 /* Check response exists */
2212 if(!response) {
2213 IRRECO_DEBUG(" No response, failed something\n");
2214 IRRECO_RETURN_BOOL(FALSE);
2217 value = soup_xmlrpc_response_get_value (response);
2219 g_object_unref (response);
2221 /* Everything went fine, return TRUE */
2222 IRRECO_RETURN_BOOL(rvalue);
2226 * Login user to WebDB.
2229 gboolean irreco_webdb_client_login(IrrecoWebdbClient *self,
2230 const gchar *user,
2231 const gchar *password)
2233 gboolean rvalue = TRUE;
2234 SoupXmlrpcMessage *msg;
2235 SoupXmlrpcResponse *response;
2236 SoupXmlrpcValue *value;
2237 IRRECO_ENTER
2239 /* Init msg with URI and other data */
2240 msg = soup_xmlrpc_message_new (IRRECO_WEBDB_URL);
2241 soup_xmlrpc_message_start_call (msg, "loginToDB");
2242 soup_xmlrpc_message_start_param (msg);
2243 soup_xmlrpc_message_write_string(msg, user);
2244 soup_xmlrpc_message_end_param (msg);
2245 soup_xmlrpc_message_start_param (msg);
2246 soup_xmlrpc_message_write_string(msg, password);
2247 soup_xmlrpc_message_end_param (msg);
2248 soup_xmlrpc_message_end_call (msg);
2250 irreco_webdb_client_reset_env(self);
2252 /* Execute XML-RPC call. */
2253 response = (SoupXmlrpcResponse*) do_xmlrpc (msg,
2254 SOUP_XMLRPC_VALUE_TYPE_BOOLEAN, self);
2256 /* Check response exists */
2257 if(!response) {
2258 IRRECO_DEBUG(" No response, failed something\n");
2259 IRRECO_RETURN_BOOL(FALSE);
2262 value = soup_xmlrpc_response_get_value (response);
2264 g_object_unref (response);
2266 /* Everything went fine, return TRUE */
2267 IRRECO_RETURN_BOOL(rvalue);
2273 #if 0
2277 gboolean irreco_webdb_client_get_category_list(GHashTable **category_list)
2279 gint i;
2280 IRRECO_ENTER
2282 *category_list = NULL;
2284 /* Execute XML-RPC call. */
2285 irreco_webdb_client_reset_env();
2286 self->result = xmlrpc_client_call_server(self->error_env, self->server,
2287 "getCategoryList", "()");
2288 if (!irreco_webdb_client_is_ok()) IRRECO_RETURN_BOOL(FALSE);
2290 /* Get structure size. */
2291 i = xmlrpc_struct_size(self->error_env, self->result);
2292 if (!irreco_webdb_client_is_ok()) IRRECO_RETURN_BOOL(FALSE);
2294 /* Create hashtable. */
2295 *category_list = g_hash_table_new_full(g_int_hash, g_int_equal,
2296 NULL, g_free);
2298 /* Parse structure. */
2299 while (i--) {
2300 xmlrpc_value *xml_key;
2301 xmlrpc_value *xml_value;
2302 const gchar * str_key;
2303 const gchar * str_value;
2305 xmlrpc_struct_read_member(self->error_env, self->result, i,
2306 &xml_key, &xml_value);
2307 if (!irreco_webdb_client_is_ok()) goto error;
2309 xmlrpc_read_string(self->error_env, xml_key, &str_key);
2310 if (!irreco_webdb_client_is_ok()) goto error;
2312 xmlrpc_read_string(self->error_env, xml_value, &str_value);
2313 if (!irreco_webdb_client_is_ok()) goto error;
2315 IRRECO_PRINTF("Key: %s, Val: %s\n", str_key, str_value);
2316 /*g_hash_table_add();*/
2318 xmlrpc_DECREF(xml_key);
2319 xmlrpc_DECREF(xml_value);
2322 IRRECO_RETURN_BOOL(TRUE);
2324 error:
2325 g_hash_table_destroy(*category_list);
2326 *category_list = NULL;
2327 IRRECO_RETURN_BOOL(FALSE);
2329 #endif
2332 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
2333 /* Events and Callbacks */
2334 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/