Added alloc/stream options to fetcher test utility
This commit is contained in:
+32
-6
@@ -19,6 +19,18 @@
|
|||||||
#include <library.h>
|
#include <library.h>
|
||||||
#include <debug.h>
|
#include <debug.h>
|
||||||
|
|
||||||
|
static int count = 0;
|
||||||
|
|
||||||
|
static bool cb(void *userdata, chunk_t chunk)
|
||||||
|
{
|
||||||
|
if (write(1, chunk.ptr, chunk.len) == chunk.len)
|
||||||
|
{
|
||||||
|
count++;
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
int main(int argc, char *argv[])
|
int main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
chunk_t res;
|
chunk_t res;
|
||||||
@@ -27,15 +39,29 @@ int main(int argc, char *argv[])
|
|||||||
atexit(library_deinit);
|
atexit(library_deinit);
|
||||||
lib->plugins->load(lib->plugins, NULL, PLUGINS);
|
lib->plugins->load(lib->plugins, NULL, PLUGINS);
|
||||||
|
|
||||||
if (argc != 2)
|
if (argc != 3 || (!streq(argv[1], "a") && !streq(argv[1], "s")))
|
||||||
{
|
{
|
||||||
fprintf(stderr, "usage: %s <url>\n", argv[0]);
|
fprintf(stderr, "usage: %s a|s <url>\n", argv[0]);
|
||||||
|
return 1;
|
||||||
}
|
}
|
||||||
if (lib->fetcher->fetch(lib->fetcher, argv[1], &res, FETCH_END) == SUCCESS)
|
if (streq(argv[1], "a"))
|
||||||
{
|
{
|
||||||
ignore_result(write(1, res.ptr, res.len));
|
if (lib->fetcher->fetch(lib->fetcher, argv[2], &res,
|
||||||
free(res.ptr);
|
FETCH_END) == SUCCESS)
|
||||||
return 0;
|
{
|
||||||
|
ignore_result(write(1, res.ptr, res.len));
|
||||||
|
free(res.ptr);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (lib->fetcher->fetch(lib->fetcher, argv[2], NULL,
|
||||||
|
FETCH_CALLBACK, cb, FETCH_END) == SUCCESS)
|
||||||
|
{
|
||||||
|
fprintf(stderr, "received %d chunks\n", count);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user