00001
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029 #include <config.h>
00030
00031 #ifndef HAVE_LIBCURL
00032
00033 #include <assert.h>
00034 #include <expat.h>
00035
00036 #include "load-url.h"
00037
00038 #ifdef HAVE_ZLIB
00039 #include <zlib.h>
00040 #define stdio_file gzFile
00041 #define fopen gzopen
00042 #define STDIO_READ fread
00043 #define fclose gzclose
00044 #else
00045 #include <stdio.h>
00046 typedef FILE *stdio_file;
00047 #define STDIO_READ(f, buf, len) fread(buf, 1, len, f)
00048 #endif
00049
00050 #include <string.h>
00051
00052 int
00053 _discover_load_url(const char *url, XML_Parser parser)
00054 {
00055 const char *file_path;
00056 stdio_file url_file;
00057 char buf[4096];
00058 char *tmp;
00059 size_t len;
00060 int parse_result;
00061
00062 assert(url != NULL);
00063
00064 if (strncmp(url, "file:", 5))
00065 return 0;
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076 file_path = strchr(url + 7, '/');
00077 if (!file_path) {
00078 file_path = url + 7;
00079 }
00080
00081 if (*file_path == '\0')
00082 return 0;
00083
00084 url_file = fopen(file_path, "r");
00085 if (url_file == NULL)
00086 return 0;
00087
00088 do
00089 {
00090 len = STDIO_READ(url_file, buf, sizeof(buf));
00091 if (len > 0)
00092 parse_result = XML_Parse(parser, buf, len, 0);
00093 } while ((len > 0) && (parse_result != 0));
00094
00095 fclose(url_file);
00096
00097 if (parse_result != 0)
00098 parse_result = XML_Parse(parser, buf, 0, 1);
00099
00100 return (parse_result != 0);
00101 }
00102
00103 #endif