1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
|
diff -u /var/tmp/portage/libfwbuilder-1.0.1/work/libfwbuilder-1.0.1/src/fwbuilder/Resources.cc ./Resources.cc
--- src/fwbuilder/Resources.cc 2003-03-03 08:18:03.000000000 +0000
+++ src/fwbuilderResources.cc 2003-11-13 09:21:17.815706848 +0000
@@ -6,7 +6,7 @@
Author: Vadim Kurland vadim@vk.crocodile.org
- $Id: libfwbuilder-1.0.1-libxml2.patch,v 1.1 2003/11/13 09:36:22 aliz Exp $
+ $Id: libfwbuilder-1.0.1-libxml2.patch,v 1.1 2003/11/13 09:36:22 aliz Exp $
This program is free software which we release under the GNU General Public
@@ -117,18 +117,15 @@
void Resources::loadRes(const std::string &rfile ) throw(FWException)
{
- if(access(rfile.c_str() , R_OK )!=0)
- throw FWException("Could not load resources: "+rfile);
- doc = xmlParseFile(rfile.c_str());
-
- if(!doc)
- throw FWException("Error parsing "+rfile);
+// doc = xmlParseFile(rfile.c_str());
+ doc = XMLTools::loadAndParseFile(rfile);
+
+ if(!doc) throw FWException("Error parsing "+rfile);
root=xmlDocGetRootElement(doc);
-
- if(!root || !root->name ||
- strcmp(FROMXMLCAST(root->name), "FWBuilderResources")!=0)
+
+ if(!root || !root->name || strcmp(FROMXMLCAST(root->name), "FWBuilderResources")!=0)
{
xmlFreeDoc(doc);
throw FWException("Invalid resources file "+rfile);
diff -u /var/tmp/portage/libfwbuilder-1.0.1/work/libfwbuilder-1.0.1/src/fwbuilder/XMLTools.cc ./XMLTools.cc
--- src/fwbuilder/XMLTools.cc 2003-07-06 06:12:20.000000000 +0000
+++ src/fwbuilder/XMLTools.cc 2003-11-13 09:21:17.829704720 +0000
@@ -6,7 +6,7 @@
Author: Vadim Kurland vadim@vk.crocodile.org
- $Id: libfwbuilder-1.0.1-libxml2.patch,v 1.1 2003/11/13 09:36:22 aliz Exp $
+ $Id: libfwbuilder-1.0.1-libxml2.patch,v 1.1 2003/11/13 09:36:22 aliz Exp $
This program is free software which we release under the GNU General Public
@@ -31,6 +31,11 @@
#include <string.h>
#include <unistd.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <unistd.h>
+#include <errno.h>
+#include <assert.h>
#ifdef HAVE_LIBXSLT_XSLTCONFIG_H
# include <libxslt/xsltconfig.h>
@@ -43,8 +48,6 @@
#include <glib.h>
-#include <assert.h>
-
#include <iostream>
#undef FW_XMLTOOLS_VERBOSE
@@ -202,6 +205,41 @@
xmlSetExternalEntityLoader(fwbExternalEntityLoader);
}
+/*
+ * I use xmlParseMemory because libxml2 v2.6.2 broke xmlParseFile. If
+ * file name had a full path in it, it won't load and gave an error
+ * like this:
+ *
+ * I/O warning : failed to load external entity "/resources.xml"
+ *
+ * I do not check if xmlParseMemory succeeded in this method because
+ * I may need to throw different exceptions in different method using
+ * loadAndParseFile. loadAndParseFile just returns whatever
+ * xmlParseMemory returned, this works better in a sense that
+ * loadAndParseFile should be just a wrapper for xmlParseMemory and
+ * should replicate its behavior.
+ *
+ */
+xmlDocPtr XMLTools::loadAndParseFile(const std::string &rfile) throw(FWException)
+{
+ struct stat stt;
+ int fd;
+
+ if (stat( rfile.c_str() , &stt )!=0 || (fd=open(rfile.c_str(),O_RDONLY))<0)
+ throw FWException("Could not read file "+rfile);
+
+ char *buf=(char*)malloc(stt.st_size);
+
+ read(fd,buf,stt.st_size);
+ close(fd);
+
+ xmlDocPtr doc = xmlParseMemory(buf, stt.st_size);
+ memset(buf,0,stt.st_size);
+ free(buf);
+
+ return doc;
+}
+
xmlDocPtr XMLTools::parseFile(const string &file_name,
bool use_dtd, const string &template_dir) throw(FWException)
{
@@ -215,7 +253,8 @@
string errors;
xmlSetGenericErrorFunc (&errors, xslt_error_handler);
- xmlDocPtr doc = xmlParseFile(file_name.c_str());
+// xmlDocPtr doc = xmlParseFile(file_name.c_str());
+ xmlDocPtr doc = loadAndParseFile(file_name);
xmlSetGenericErrorFunc (NULL, NULL);
g_mutex_unlock(xml_parser_mutex);
@@ -415,7 +454,9 @@
}
- doc = xmlParseFile(src_file.c_str());
+// doc = xmlParseFile(src_file.c_str());
+ doc = loadAndParseFile(src_file);
+
res = xsltApplyStylesheet(ss, doc, params);
xsltSaveResultToFilename(dst_file.c_str(), res, ss, 0);
diff -u /var/tmp/portage/libfwbuilder-1.0.1/work/libfwbuilder-1.0.1/src/fwbuilder/XMLTools.hh ./XMLTools.hh
--- src/fwbuilder/XMLTools.hh 2003-07-06 06:12:20.000000000 +0000
+++ src/fwbuilder/XMLTools.hh 2003-11-13 09:21:17.835703808 +0000
@@ -6,7 +6,7 @@
Author: Vadim Kurland vadim@vk.crocodile.org
- $Id: libfwbuilder-1.0.1-libxml2.patch,v 1.1 2003/11/13 09:36:22 aliz Exp $
+ $Id: libfwbuilder-1.0.1-libxml2.patch,v 1.1 2003/11/13 09:36:22 aliz Exp $
This program is free software which we release under the GNU General Public
@@ -64,6 +64,15 @@
static void initXMLTools();
+ /**
+ * a wrapper for xmlParseMemory. Returns a pointer to the document
+ * structure or NULL in case of failure. This wrapper allows us to
+ * use xmlParseFile or xmlParseMemory, whatever works. I used to
+ * use xmlParseFile just fine unitl libxml2 v2.6.2, in which it
+ * broke and I had to start using xmlParseMemory instead.
+ */
+ static xmlDocPtr loadAndParseFile(const std::string &file_name)
+ throw(FWException);
class UpgradePredicate
{
|