Fixed 'xmlChar' signedness gcc(1) warnings.
[captive.git] / src / libcaptive / client / libxml.c
1 /* $Id$
2  * Supplementary captive utilities for libxml2
3  * Copyright (C) 2003 Jan Kratochvil <project-captive@jankratochvil.net>
4  * 
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; exactly version 2 of June 1991 is required
8  * 
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  * 
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
17  */
18
19
20 #include "config.h"
21
22 #include "captive/libxml.h"     /* self */
23 #include <glib/gmessages.h>
24 #include <glib/ghook.h>
25 #include <string.h>
26 #include "captive/macros.h"
27
28
29 struct captive_libxml_string_drop_stack {
30         GHookList g_hook_list;
31         };
32
33
34 gint64 captive_libxml_sscanf_gint64(const gchar *gint64_string)
35 {
36 int errint;
37 gint64 r;
38 int gint64_string_len;
39
40         g_return_val_if_fail(gint64_string!=NULL,0);
41
42         errint=sscanf(gint64_string,"%" G_GINT64_FORMAT "%n",&r,&gint64_string_len);
43         g_assert(errint==1 || errint==2 /* %n */);
44         g_assert(gint64_string_len==(int)strlen(gint64_string));
45
46         return r;
47 }
48
49
50 static void captive_libxml_string_drop_hook_func(const xmlChar *xml_string /* data */)
51 {
52         g_return_if_fail(xml_string!=NULL);
53
54         xmlFree((xmlChar *)xml_string);
55 }
56
57 G_CONST_RETURN gchar *captive_libxml_string_drop(struct captive_libxml_string_drop_stack **drop_stackp,const xmlChar *xml_string)
58 {
59 GHook *g_hook;
60
61         g_return_val_if_fail(drop_stackp!=NULL,NULL);
62
63         if (!xml_string)
64                 return NULL;
65
66         if (!*drop_stackp) {
67                 captive_new(*drop_stackp);
68                 g_hook_list_init(&(*drop_stackp)->g_hook_list,sizeof(GHook));
69                 }
70
71         g_hook=g_hook_alloc(&(*drop_stackp)->g_hook_list);
72         g_hook->func=(GHookFunc)captive_libxml_string_drop_hook_func;
73         g_hook->data=(xmlChar *)xml_string;
74         g_hook_append(&(*drop_stackp)->g_hook_list,g_hook);
75
76         return (const gchar *)xml_string;
77 }
78
79
80 void captive_libxml_string_drop_flush(struct captive_libxml_string_drop_stack **drop_stackp)
81 {
82 struct captive_libxml_string_drop_stack *drop_stack;
83
84         g_return_if_fail(drop_stackp!=NULL);
85
86         if (!(drop_stack=*drop_stackp))
87                 return;
88         *drop_stackp=NULL;
89
90         g_hook_list_invoke(&drop_stack->g_hook_list,
91                         FALSE); /* may_recurse */
92         g_hook_list_clear(&drop_stack->g_hook_list);
93
94         g_free(drop_stack);
95 }