version 1.21, 2000/04/03 18:45:48
|
version 1.22, 2000/04/07 13:17:40
|
Line 51
|
Line 51
|
#define MINLEN 4000 |
#define MINLEN 4000 |
#endif |
#endif |
|
|
|
/* |
|
* Input I/O callback sets |
|
*/ |
|
typedef struct _xmlInputCallback { |
|
xmlInputMatchCallback matchcallback; |
|
xmlInputOpenCallback opencallback; |
|
xmlInputReadCallback readcallback; |
|
xmlInputCloseCallback closecallback; |
|
} xmlInputCallback; |
|
|
|
extern xmlInputCallback fileInputCallback; |
|
extern xmlInputCallback fdInputCallback; |
|
|
|
extern xmlInputCallback *xmlInputCallbackTable; |
|
|
|
/** |
|
* fdMatch: |
|
* @filename: the URI for matching |
|
* |
|
* input from file descriptor |
|
* |
|
* Returns 1 if matches, 0 otherwise |
|
*/ |
|
static int fdMatch (const char *filename) { |
|
if (!strncmp(filename, "file://localhost", 16)) |
|
return(1); |
|
if (!strncmp(filename, "file:///", 8)) |
|
return(1); |
|
if (filename[0] = '/') |
|
return(1); |
|
return(0); |
|
} |
|
/** |
|
* fdOpen: |
|
* @filename: the URI for matching |
|
* |
|
* input from file descriptor |
|
* |
|
* Returns 1 if matches, 0 otherwise |
|
*/ |
|
static void * fdOpen (const char *filename) { |
|
int fd = -1; |
|
const char *path = NULL; |
|
|
|
if (!strncmp(filename, "file://localhost", 16)) |
|
path = &filename[16]; |
|
else if (!strncmp(filename, "file:///", 8)) |
|
path = &filename[16]; |
|
else if (filename[0] = '/') |
|
path = filename; |
|
if (path == NULL) |
|
return(NULL |
|
#ifdef WIN32 |
|
fd = _open (path, O_RDONLY | _O_BINARY); |
|
#else |
|
fd = open (path, O_RDONLY); |
|
#endif |
|
return (void *) fd; |
|
} |
|
|
|
int fdRead (void * context, char * buffer, int len) { |
|
int fd = (int) context; |
|
return read (fd, &buffer[0], len); |
|
} |
|
void fdClose (void * context) { |
|
int fd = (int) context; |
|
close (fd); |
|
} |
|
xmlInputCallback fdInputCallback = {fdMatch, fdOpen, fdRead, fdClose}; |
|
|
|
/* input from file descriptor */ |
|
int fileMatch (const char *filename) { |
|
return strstr (filename, ":") == 0; |
|
} |
|
void * fileOpen (const char *filename) { |
|
FILE *file = fopen (filename, "r"); |
|
return file; |
|
} |
|
int fileRead (void * context, char * buffer, int len) { |
|
FILE *file = context; |
|
return fread(&buffer[0], 1, len, file); |
|
} |
|
void fileClose (void * context) { |
|
FILE *file = context; |
|
fclose (file); |
|
} |
|
xmlInputCallback fileInputCallback = {fileMatch, fileOpen, fdRead, fileClose}; |
|
|
|
/* default input method table */ |
|
xmlInputCallback defaultInputCallbackTable [] = { |
|
{fdMatch, fdOpen, fdRead, fdClose}, |
|
{fileMatch, fileOpen, fdRead, fileClose}, |
|
{0, 0, 0, 0} |
|
}; |
|
xmlInputCallback *xmlInputCallbackTable = defaultInputCallbackTable; |
|
|
/** |
/** |
* xmlAllocParserInputBuffer: |
* xmlAllocParserInputBuffer: |
* @enc: the charset encoding if known |
* @enc: the charset encoding if known |