コード例 #1
0
ファイル: xml.c プロジェクト: BIllli/mget
void mget_xml_parse_file(
	const char *fname,
	mget_xml_callback_t *callback,
	void *user_ctx,
	int hints)
{
	int fd;

	if (strcmp(fname,"-")) {
		if ((fd = open(fname, O_RDONLY)) != -1) {
			struct stat st;
			if (fstat(fd, &st) == 0) {
#ifdef HAVE_MMAP
				size_t nread = st.st_size;
				char *buf = mmap(NULL, nread + 1, PROT_READ|PROT_WRITE, MAP_PRIVATE, fd, 0);
#else
				char *buf=xmalloc(st.st_size + 1);
				size_t nread=read(fd, buf, st.st_size);
#endif

				if (nread > 0) {
					buf[nread] = 0; // PROT_WRITE allows this write, MAP_PRIVATE prevents changes in underlying file system
					mget_xml_parse_buffer(buf, callback, user_ctx, hints);
				}

#ifdef HAVE_MMAP
				munmap(buf, nread);
#else
				xfree(buf);
#endif
			}
			close(fd);
		} else
			error_printf(_("Failed to open %s\n"), fname);
	} else {
		// read data from STDIN.
		// maybe should use yy_scan_bytes instead of buffering into memory.
		char tmp[4096];
		ssize_t nbytes;
		mget_buffer_t *buf = mget_buffer_alloc(4096);

		while ((nbytes = read(STDIN_FILENO, tmp, sizeof(tmp))) > 0) {
			mget_buffer_memcat(buf, tmp, nbytes);
		}

		if (buf->length)
			mget_xml_parse_buffer(buf->data, callback, user_ctx, hints);

		mget_buffer_free(&buf);
	}
}
コード例 #2
0
ファイル: rss_url.c プロジェクト: BIllli/mget
void mget_rss_get_urls_inline(const char *rss, mget_vector_t **urls)
{
	struct rss_context context = { .urls = NULL };

	mget_xml_parse_buffer(rss, _rss_get_url, &context, XML_HINT_REMOVE_EMPTY_CONTENT);

	*urls = context.urls;
}
コード例 #3
0
ファイル: xml.c プロジェクト: BIllli/mget
void mget_html_parse_buffer(
	const char *buf,
	mget_xml_callback_t *callback,
	void *user_ctx,
	int hints)
{
	mget_xml_parse_buffer(buf, callback, user_ctx, hints | XML_HINT_HTML);
}
コード例 #4
0
ファイル: metalink.c プロジェクト: bge-kernel-panic/mget
void metalink4_parse(int sockfd, MGET_HTTP_RESPONSE *resp)
{
	struct metalink_context ctx;

	ctx.sockfd = sockfd;
	ctx.priority = 999999;
	*ctx.hash = 0,
		*ctx.hash_type = 0,
		ctx.length = 0;
	strcpy(ctx.location, "-");

	mget_xml_parse_buffer(resp->body->data, _metalink4_parse, &ctx, 0);
}