Beispiel #1
0
int main(void)
{
	char *empty = (char *)"";

	wget_info_printf("%d\n", wget_base64_is_string("")); // base64.c
	wget_buffer_alloc(0); // buffer.c
	wget_buffer_printf((wget_buffer_t *)1, "%s", ""); // buffer_printf.c
	strlcpy((char *)"", "", 0); // strlcpy.c
	wget_css_parse_buffer((const char *)1, 0, NULL, NULL, NULL); // css.c
	wget_decompress_close(NULL); // decompressor.c
	wget_hashmap_create(0, 0, NULL, NULL); // hashmap.c
	wget_fdgetline(&empty, (size_t *)1, 0); // io.c
	wget_iri_parse("", NULL); // iri.c
	wget_list_free((wget_list_t **)1); // list.c
	wget_debug_write("", 0); // log.c
	wget_logger_set_file(NULL, ""); // logger.c
	wget_tcp_set_connect_timeout(NULL, 0); // net.c
	wget_netrc_deinit(NULL); // netrc.c
	wget_strdup(""); // mem.c
//	wget_popenf("r", "%s", ""); // pipe.c
//	wget_bsprintf(NULL, NULL, "%s", ""); // printf.c
	wget_ssl_set_config_int(0, 0); // ssl_[gnutls].c
	wget_stringmap_create(0); // stringmap.c
	if (wget_strcmp("", "")) {}; // utils.c
	wget_vector_set_destructor(NULL, NULL); // vector.c
	wget_malloc(1); // xalloc.c
	wget_xml_parse_buffer("", NULL, NULL, 0); // xml.c
}
Beispiel #2
0
void wget_css_parse_file(
	const char *fname,
	void(*callback_uri)(void *user_ctx, const char *url, size_t len, size_t pos),
	void(*callback_encoding)(void *user_ctx, const char *url, size_t len),
	void *user_ctx)
{
	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
					wget_css_parse_buffer(buf, callback_uri, callback_encoding, user_ctx);
				}

#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;
		wget_buffer_t *buf = wget_buffer_alloc(4096);

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

		if (buf->length)
			wget_css_parse_buffer(buf->data, callback_uri, callback_encoding, user_ctx);

		wget_buffer_free(&buf);
	}
}
Beispiel #3
0
int main(int argc G_GNUC_WGET_UNUSED, const char *const *argv G_GNUC_WGET_UNUSED)
{
	wget_http_connection_t *conn = NULL;
	wget_http_response_t *resp;

	// set up libwget global configuration
	wget_global_init(
		// WGET_DEBUG_STREAM, stderr,
		WGET_ERROR_STREAM, stderr,
		WGET_INFO_STREAM, stdout,
		NULL);

	// This is the text that we want to convert into a GFX
	const char *text = "alice->bob: authentication request\nbob-->alice: response";
	const char *style = "qsd";
	wget_buffer_t *url = wget_buffer_alloc(128);
	wget_buffer_t *body = wget_buffer_alloc(128);


	wget_buffer_strcpy(body, "message=");
	wget_iri_escape_query(text, body);
	wget_buffer_printf_append(body, "&style=%s&apiVersion=1", style);

	resp = wget_http_get(
		WGET_HTTP_URL, "https://www.websequencediagrams.com",
		WGET_HTTP_SCHEME, "POST",
		WGET_HTTP_HEADER_ADD, "Content-Type", "application/x-www-form-urlencoded",
		WGET_HTTP_BODY, body->data, body->length,
		WGET_HTTP_CONNECTION_PTR, &conn,
		NULL);
Beispiel #4
0
static void test_buffer(void)
{
	char sbuf[16];
	wget_buffer_t buf, *bufp;

	// testing buffer on stack, using initial stack memory
	// without resizing

	wget_buffer_init(&buf, sbuf, sizeof(sbuf));
	wget_buffer_deinit(&buf);

	// testing buffer on stack, using initial stack memory
	// with resizing

	wget_buffer_init(&buf, sbuf, sizeof(sbuf));
	_test_buffer(&buf, "Test 1");
	wget_buffer_deinit(&buf);

	// testing buffer on stack, using initial heap memory
	// without resizing

	wget_buffer_init(&buf, NULL, 16);
	wget_buffer_deinit(&buf);

	// testing buffer on stack, using initial heap memory
	// with resizing

	wget_buffer_init(&buf, NULL, 16);
	_test_buffer(&buf, "Test 2");
	wget_buffer_deinit(&buf);

	// testing buffer on heap, using initial stack memory
	// without resizing

	bufp = wget_buffer_init(NULL, sbuf, sizeof(sbuf));
	wget_buffer_deinit(bufp);

	bufp = wget_buffer_init(NULL, sbuf, sizeof(sbuf));
	wget_buffer_free(&bufp);

	// testing buffer on heap, using initial stack memory
	// with resizing

	bufp = wget_buffer_init(NULL, sbuf, sizeof(sbuf));
	_test_buffer(bufp, "Test 3");
	wget_buffer_deinit(bufp);

	bufp = wget_buffer_init(NULL, sbuf, sizeof(sbuf));
	_test_buffer(bufp, "Test 4");
	wget_buffer_free(&bufp);

	// testing buffer on heap, using initial heap memory
	// without resizing

	bufp = wget_buffer_alloc(16);
	wget_buffer_free(&bufp);

	// testing buffer on heap, using initial heap memory
	// with resizing

	bufp = wget_buffer_alloc(16);
	_test_buffer(bufp, "Test 5");
	wget_buffer_free(&bufp);

	// check that appending works

	wget_buffer_init(&buf, sbuf, sizeof(sbuf));
	wget_buffer_strcpy(&buf, "A");
	wget_buffer_strcat(&buf, "B");
	wget_buffer_memcat(&buf, "C", 1);
	wget_buffer_memset_append(&buf, 'D', 1);
	wget_buffer_printf_append(&buf, "%s", "E");
	if (!strcmp(buf.data, "ABCDE"))
		ok++;
	else {
		failed++;
		info_printf("test_buffer.append: got %s (expected %s)\n", buf.data, "ABCDE");
	}
	wget_buffer_deinit(&buf);

	// test wget_buffer_trim()

	wget_buffer_init(&buf, sbuf, sizeof(sbuf));
	for (int mid_ws = 0; mid_ws <= 2; mid_ws++) {
		char expected[16];
		snprintf(expected, sizeof(expected), "x%.*sy", mid_ws, "  ");

		for (int lead_ws = 0; lead_ws <= 2; lead_ws++) {
			for (int trail_ws = 0; trail_ws <= 2; trail_ws++) {
				wget_buffer_printf(&buf, "%.*sx%.*sy%.*s", lead_ws, "  ", mid_ws, "  ", trail_ws, "  ");
				wget_buffer_trim(&buf);
				if (!strcmp(buf.data, expected))
					ok++;
				else {
					failed++;
					info_printf("test_buffer_trim: got '%s' (expected '%s') (%d, %d, %d)\n", buf.data, expected, lead_ws, mid_ws, trail_ws);
				}
			}
		}
	}
	wget_buffer_deinit(&buf);
}