* xmlInputDefaultOpen: * @buf: input buffer to be filled * @filename: filename or URI * * Returns an xmlParserErrors code. */
| 1166 | * Returns an xmlParserErrors code. |
| 1167 | */ |
| 1168 | static int |
| 1169 | xmlInputDefaultOpen(xmlParserInputBufferPtr buf, const char *filename) { |
| 1170 | int ret; |
| 1171 | int fd; |
| 1172 | |
| 1173 | #ifdef LIBXML_FTP_ENABLED |
| 1174 | if (xmlIOFTPMatch(filename)) { |
| 1175 | buf->context = xmlIOFTPOpen(filename); |
| 1176 | |
| 1177 | if (buf->context != NULL) { |
| 1178 | buf->readcallback = xmlIOFTPRead; |
| 1179 | buf->closecallback = xmlIOFTPClose; |
| 1180 | return(XML_ERR_OK); |
| 1181 | } |
| 1182 | } |
| 1183 | #endif /* LIBXML_FTP_ENABLED */ |
| 1184 | |
| 1185 | #ifdef LIBXML_HTTP_ENABLED |
| 1186 | if (xmlIOHTTPMatch(filename)) { |
| 1187 | buf->context = xmlIOHTTPOpen(filename); |
| 1188 | |
| 1189 | if (buf->context != NULL) { |
| 1190 | buf->readcallback = xmlIOHTTPRead; |
| 1191 | buf->closecallback = xmlIOHTTPClose; |
| 1192 | return(XML_ERR_OK); |
| 1193 | } |
| 1194 | } |
| 1195 | #endif /* LIBXML_HTTP_ENABLED */ |
| 1196 | |
| 1197 | if (!xmlFileMatch(filename)) |
| 1198 | return(XML_IO_ENOENT); |
| 1199 | |
| 1200 | #ifdef LIBXML_LZMA_ENABLED |
| 1201 | { |
| 1202 | xzFile xzStream; |
| 1203 | |
| 1204 | ret = xmlFdOpen(filename, 0, &fd); |
| 1205 | if (ret != XML_ERR_OK) |
| 1206 | return(ret); |
| 1207 | |
| 1208 | xzStream = __libxml2_xzdopen(filename, fd, "rb"); |
| 1209 | |
| 1210 | if (xzStream == NULL) { |
| 1211 | close(fd); |
| 1212 | } else { |
| 1213 | /* |
| 1214 | * Non-regular files like pipes can't be reopened. |
| 1215 | * If a file isn't seekable, we pipe uncompressed |
| 1216 | * input through xzlib. |
| 1217 | */ |
| 1218 | if ((lseek(fd, 0, SEEK_CUR) < 0) || |
| 1219 | (__libxml2_xzcompressed(xzStream) > 0)) { |
| 1220 | buf->context = xzStream; |
| 1221 | buf->readcallback = xmlXzfileRead; |
| 1222 | buf->closecallback = xmlXzfileClose; |
| 1223 | buf->compressed = 1; |
| 1224 | |
| 1225 | return(XML_ERR_OK); |
no test coverage detected