Skip to content

Commit 968646f

Browse files
authored
reorder IO callbacks lookup (#175)
1 parent 1bcd4ed commit 968646f

File tree

1 file changed

+22
-13
lines changed

1 file changed

+22
-13
lines changed

src/io.c

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -119,9 +119,10 @@ xmlSecIOCallbackPtrListFind(xmlSecPtrListPtr list, const char* uri) {
119119
xmlSecAssert2(xmlSecPtrListCheckId(list, xmlSecIOCallbackPtrListId), NULL);
120120
xmlSecAssert2(uri != NULL, NULL);
121121

122+
/* Search from the end of the list to ensure the newly added entries are picked up first */
122123
size = xmlSecPtrListGetSize(list);
123-
for(i = 0; i < size; ++i) {
124-
callbacks = (xmlSecIOCallbackPtr)xmlSecPtrListGetItem(list, i);
124+
for(i = size; i > 0; --i) {
125+
callbacks = (xmlSecIOCallbackPtr)xmlSecPtrListGetItem(list, i - 1);
125126
xmlSecAssert2(callbacks != NULL, NULL);
126127
xmlSecAssert2(callbacks->matchcallback != NULL, NULL);
127128

@@ -152,15 +153,21 @@ xmlSecIOInit(void) {
152153
return(-1);
153154
}
154155

156+
#ifdef LIBXML_FTP_ENABLED
157+
xmlNanoFTPInit();
158+
#endif /* LIBXML_FTP_ENABLED */
159+
155160
#ifdef LIBXML_HTTP_ENABLED
156161
xmlNanoHTTPInit();
157162
#endif /* LIBXML_HTTP_ENABLED */
158163

159-
#ifdef LIBXML_FTP_ENABLED
160-
xmlNanoFTPInit();
161-
#endif /* LIBXML_FTP_ENABLED */
164+
ret = xmlSecIORegisterDefaultCallbacks();
165+
if(ret < 0) {
166+
xmlSecInternalError("xmlSecIORegisterDefaultCallbacks", NULL);
167+
return(-1);
168+
}
162169

163-
return(xmlSecIORegisterDefaultCallbacks());
170+
return(0);
164171
}
165172

166173
/**
@@ -241,6 +248,14 @@ int
241248
xmlSecIORegisterDefaultCallbacks(void) {
242249
int ret;
243250

251+
/* Callbacks added later are picked up first */
252+
ret = xmlSecIORegisterCallbacks(xmlFileMatch, xmlFileOpen,
253+
xmlFileRead, xmlFileClose);
254+
if(ret < 0) {
255+
xmlSecInternalError("xmlSecIORegisterCallbacks(file)", NULL);
256+
return(-1);
257+
}
258+
244259
#ifdef LIBXML_HTTP_ENABLED
245260
ret = xmlSecIORegisterCallbacks(xmlIOHTTPMatch, xmlIOHTTPOpen,
246261
xmlIOHTTPRead, xmlIOHTTPClose);
@@ -259,13 +274,7 @@ xmlSecIORegisterDefaultCallbacks(void) {
259274
}
260275
#endif /* LIBXML_FTP_ENABLED */
261276

262-
ret = xmlSecIORegisterCallbacks(xmlFileMatch, xmlFileOpen,
263-
xmlFileRead, xmlFileClose);
264-
if(ret < 0) {
265-
xmlSecInternalError("xmlSecIORegisterCallbacks(file)", NULL);
266-
return(-1);
267-
}
268-
277+
/* done */
269278
return(0);
270279
}
271280

0 commit comments

Comments
 (0)