Skip to content
This repository was archived by the owner on Aug 31, 2021. It is now read-only.

Commit 0ed8029

Browse files
committed
failsafe xslt ids
1 parent cf6050d commit 0ed8029

File tree

2 files changed

+63
-13
lines changed

2 files changed

+63
-13
lines changed

revxml/src/cxml.h

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@ along with LiveCode. If not see <http://www.gnu.org/licenses/>. */
1919
#include <libxml/HTMLparser.h>
2020
// MDW-2013-07-09: [[ RevXmlXPath ]]
2121
#include <libxml/xpath.h>
22+
// MDW-2013-09-03: [[ RevXmlXslt ]]
23+
#include <xsltInternals.h>
24+
#include <xsltutils.h>
2225

2326
#include <errno.h>
2427
#include <stdio.h>
@@ -61,7 +64,7 @@ extern void CB_elementData(const char *data, int length);
6164
class CXMLDocument
6265
{
6366
public:
64-
CXMLDocument() {id = ++idcounter; doc = NULL;}
67+
CXMLDocument() {id = ++idcounter; doc = NULL; xpathContext = NULL; xsltID = NULL;}
6568
~CXMLDocument() {Free();}
6669
inline Bool isinited() {return doc != NULL;}
6770
Bool Read(char *data, unsigned long tlength, Bool wellformed);
@@ -77,6 +80,9 @@ xmlDocPtr GetDocPtr() {return doc;}
7780
// MDW-2013-07-09: [[ RevXmlXPath ]]
7881
xmlXPathContextPtr GetXPathContext() {return xpathContext;}
7982
void SetXPathContext(xmlXPathContextPtr ctx) {xpathContext=ctx;}
83+
// MDW-2013-09-03: [[ RevXmlXslt ]]
84+
xsltStylesheetPtr GetXsltContext() {return xsltID;}
85+
void SetXsltContext(xsltStylesheetPtr ctx) {xsltID=ctx;}
8086
Bool AddDTD(char *data, unsigned long tlength);
8187
Bool ValidateDTD(char *data, unsigned long tlength);
8288
char *GetError() {return errorbuf;}
@@ -100,6 +106,8 @@ static char errorbuf[256];
100106
xmlDocPtr doc;
101107
// MDW-2013-07-09: [[ RevXmlXPath ]]
102108
xmlXPathContextPtr xpathContext;
109+
// MDW-2013-09-03: [[ RevXmlXslt ]]
110+
xsltStylesheetPtr xsltID;
103111
};
104112

105113
class CXMLElement

revxml/src/revxml.cpp

Lines changed: 54 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2701,20 +2701,27 @@ void XML_xsltLoadStylesheet(char *args[], int nargs, char **retstring, Bool *pas
27012701
*pass = False;
27022702
*error = False;
27032703
xsltStylesheetPtr cur = NULL;
2704+
CXMLDocument *newdoc = new CXMLDocument;
27042705
char *result;
27052706

27062707
if (1 == nargs)
27072708
{
27082709
int docID = atoi(args[0]);
2709-
CXMLDocument *xmlDocument = doclist.find(docID);
2710-
if (NULL != xmlDocument)
2710+
CXMLDocument *xsltDocument = doclist.find(docID);
2711+
if (NULL != xsltDocument)
27112712
{
2712-
xmlDocPtr xmlDoc = xmlDocument->GetDocPtr();
2713+
xmlDocPtr xmlDoc = xsltDocument->GetDocPtr();
27132714
if (NULL != xmlDoc)
27142715
{
27152716
cur = xsltParseStylesheetDoc(xmlDoc);
2717+
2718+
newdoc->SetXsltContext(cur);
2719+
doclist.add(newdoc);
2720+
unsigned int docid = newdoc->GetID();
2721+
27162722
result = (char *)malloc(INTSTRSIZE);
2717-
sprintf(result,"%d",cur);
2723+
sprintf(result,"%d",docid);
2724+
27182725
*retstring = istrdup(result);
27192726
free(result);
27202727
}
@@ -2745,15 +2752,26 @@ void XML_xsltLoadStylesheetFromFile(char *args[], int nargs, char **retstring, B
27452752
*pass = False;
27462753
*error = False;
27472754
xsltStylesheetPtr cur = NULL;
2755+
CXMLDocument *newdoc = new CXMLDocument;
27482756
char *result;
27492757

27502758
if (1 == nargs)
27512759
{
27522760
cur = xsltParseStylesheetFile((const xmlChar *)args[0]);
2753-
result = (char *)malloc(INTSTRSIZE);
2754-
sprintf(result,"%d",cur);
2755-
*retstring = istrdup(result);
2756-
free(result);
2761+
if (NULL != cur)
2762+
{
2763+
newdoc->SetXsltContext(cur);
2764+
doclist.add(newdoc);
2765+
unsigned int docid = newdoc->GetID();
2766+
result = (char *)malloc(INTSTRSIZE);
2767+
sprintf(result,"%d",docid);
2768+
*retstring = istrdup(result);
2769+
free(result);
2770+
}
2771+
else
2772+
{
2773+
*retstring = istrdup(xmlerrors[XPATHERR_BADDOCPOINTER]);
2774+
}
27572775
}
27582776
// only one argument permitted
27592777
else
@@ -2776,9 +2794,26 @@ void XML_xsltFreeStylesheet(char *args[], int nargs, char **retstring, Bool *pas
27762794

27772795
if (1 == nargs)
27782796
{
2779-
cur = (xsltStylesheetPtr)atoi(args[0]);
2780-
xsltFreeStylesheet(cur);
2781-
*retstring = (char *)calloc(1,1);
2797+
int docID = atoi(args[0]);
2798+
CXMLDocument *xsltDocument = doclist.find(docID);
2799+
if (NULL != xsltDocument)
2800+
{
2801+
cur = xsltDocument->GetXsltContext();
2802+
if (NULL != cur)
2803+
{
2804+
xsltFreeStylesheet(cur);
2805+
*retstring = (char *)calloc(1,1);
2806+
}
2807+
else
2808+
{
2809+
*retstring = istrdup(xmlerrors[XPATHERR_BADDOCPOINTER]);
2810+
}
2811+
}
2812+
else
2813+
{
2814+
// couldn't dereference the xml id
2815+
*retstring = istrdup(xmlerrors[XMLERR_BADDOCID]);
2816+
}
27822817
}
27832818
// only one argument permitted
27842819
else
@@ -2819,11 +2854,16 @@ void XML_xsltApplyStylesheet(char *args[], int nargs, char **retstring, Bool *pa
28192854
xmlDocPtr xmlDoc = xmlDocument->GetDocPtr();
28202855
if (NULL != xmlDoc)
28212856
{
2822-
cur = (xsltStylesheetPtr)atoi(args[1]);
2857+
int docID = atoi(args[1]);
2858+
CXMLDocument *xsltDocument = doclist.find(docID);
2859+
2860+
cur = xsltDocument->GetXsltContext();
28232861
if (NULL != cur)
28242862
{
28252863
if (nargs > 2)
28262864
{
2865+
// no parameter support yet
2866+
params[nbparams] = NULL;
28272867
}
28282868
else
28292869
{
@@ -2891,6 +2931,8 @@ void XML_xsltApplyStylesheetFile(char *args[], int nargs, char **retstring, Bool
28912931
{
28922932
if (nargs > 2)
28932933
{
2934+
// no parameter support yet
2935+
params[nbparams] = NULL;
28942936
}
28952937
else
28962938
{

0 commit comments

Comments
 (0)