1 /*
2  * Copyright (C) 2007 - 2011 Vivien Malerba <malerba@gnome-db.org>
3  * Copyright (C) 2010 David King <davidk@openismus.com>
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  * Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with this library; if not, write to the
17  * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
18  * Boston, MA  02110-1301, USA.
19  */
20 
21 #include <glib.h>
22 
23 #include <libxml/xpath.h>
24 #include <libxml/xpathInternals.h>
25 
26 #include <libxslt/transform.h>
27 #include <libxslt/xsltutils.h>
28 #include <libxslt/extensions.h>
29 
30 #include "libgda-xslt.h"
31 #include "sql_backend.h"
32 
33 /**
34  * gda_xslt_register
35  *
36  * Register the xslt extension to libxslt
37  */
38 void
gda_xslt_register(void)39 gda_xslt_register (void)
40 {
41 	static GMutex init_mutex;
42 	static int init = 0;
43 
44 	g_mutex_lock (&init_mutex);
45 	if (!init) {
46 		int init_res;
47 		init = 1;
48 		init_res =
49 			xsltRegisterExtModule (BAD_CAST GDA_XSLT_EXTENSION_URI,
50 					       _gda_xslt_extension_init,
51 					       _gda_xslt_extension_shutdown);
52 		if (init_res != 0) {
53 			g_error ("error, xsltRegisterExtModule = [%d]\n",
54 				 init_res);
55 		}
56 	}
57 	g_mutex_unlock (&init_mutex);
58 }
59 
60 /**
61  * gda_xslt_set_execution_context
62  *
63  * Set the internal gda-xslt context to the xsltTransformationContext.
64  */
65 void
gda_xslt_set_execution_context(xsltTransformContextPtr tcxt,GdaXsltExCont * exec)66 gda_xslt_set_execution_context (xsltTransformContextPtr tcxt,
67 				GdaXsltExCont * exec)
68 {
69 	tcxt->_private = (void *) exec;
70 }
71 
72 /**
73  * gda_xslt_create_context_simple
74  * @cnc: a #GdaConnection
75  * @error: a place to store errors, or %NULL
76  *
77  * create a gda-xslt context with the Gdaconnection and not predefined queries
78  *
79  * Returns:
80  */
81 GdaXsltExCont *
gda_xslt_create_context_simple(GdaConnection * cnc,G_GNUC_UNUSED GError ** error)82 gda_xslt_create_context_simple (GdaConnection *cnc, G_GNUC_UNUSED GError **error)
83 {
84 	GdaXsltExCont *local = NULL;
85 
86 	local = (GdaXsltExCont *) g_new0 (GdaXsltExCont, 1);
87 	local->init = 1;
88 	local->cnc = cnc;
89 	local->error = NULL;
90 	local->query_hash = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_free);
91 	return local;
92 }
93 
94 /**
95  * gda_xslt_finalize_context
96  *
97  * clear the gda-xslt context
98  *
99  * Returns:
100  */
101 int
gda_xslt_finalize_context(GdaXsltExCont * ctx)102 gda_xslt_finalize_context (GdaXsltExCont * ctx)
103 {
104 	g_free (ctx);
105 	return 0;
106 }
107