コード例 #1
0
ファイル: test_uri.c プロジェクト: Stratoscale/lttng-tools
void test_uri_cmp()
{
	struct lttng_uri *uri1, *uri2;
	const char *s_uri1 = "net://localhost";
	const char *s_uri2 = "net://localhost:8989:4242";
	ssize_t size1, size2;
	int res;

	size1 = uri_parse(s_uri1, &uri1);

	/* Sanity checks */
	assert(size1 == 2);
	assert(uri1[0].dtype == LTTNG_DST_IPV4);
	assert(uri1[0].utype == LTTNG_URI_DST);
	assert(uri1[0].stype == 0);
	assert(uri1[0].port == 0);
	assert(strlen(uri1[0].subdir) == 0);
	assert(strcmp(uri1[0].dst.ipv4, "127.0.0.1") == 0);
	assert(uri1[1].dtype == LTTNG_DST_IPV4);
	assert(uri1[1].utype == LTTNG_URI_DST);
	assert(uri1[1].stype == 0);
	assert(uri1[1].port == 0);
	assert(strlen(uri1[1].subdir) == 0);
	assert(strcmp(uri1[1].dst.ipv4, "127.0.0.1") == 0);

	size2 = uri_parse(s_uri2, &uri2);

	assert(size2 == 2);
	assert(uri2[0].dtype == LTTNG_DST_IPV4);
	assert(uri2[0].utype == LTTNG_URI_DST);
	assert(uri2[0].stype == 0);
	assert(uri2[0].port == 8989);
	assert(strlen(uri2[0].subdir) == 0);
	assert(strcmp(uri2[0].dst.ipv4, "127.0.0.1") == 0);
	assert(uri2[1].dtype == LTTNG_DST_IPV4);
	assert(uri2[1].utype == LTTNG_URI_DST);
	assert(uri2[1].stype == 0);
	assert(uri2[1].port == 4242);
	assert(strlen(uri2[1].subdir) == 0);
	assert(strcmp(uri2[1].dst.ipv4, "127.0.0.1") == 0);

	res = uri_compare(uri1, uri1);

	ok(res == 0,
	   "URI compare net://localhost == net://localhost");

	res = uri_compare(uri1, uri2);

	ok(res != 0,
	   "URI compare net://localhost != net://localhost:8989:4242");

	uri_free(uri1);
	uri_free(uri2);
}
コード例 #2
0
ファイル: test-uri-parse.c プロジェクト: rupike/libguri
static void test_uri_parse_many(void) {
  uri_t *u = uri_new();

  const char uri1[] = "http://example.com/path/to/something?query=string#frag";
  g_assert(uri_parse(u, uri1, strlen(uri1), NULL));
  g_assert_cmpstr(u->scheme, ==, "http");
  g_assert_cmpstr(u->host, ==, "example.com");
  g_assert_cmpstr(u->path, ==, "/path/to/something");
  g_assert_cmpstr(u->query, ==, "?query=string");
  g_assert_cmpstr(u->fragment, ==, "#frag");
  uri_clear(u);

  const char uri2[] = "http://*****:*****@example.com:5555/path/to/";
  g_assert(uri_parse(u, uri2, strlen(uri2), NULL));
  g_assert_cmpstr(u->scheme, ==, "http");
  g_assert_cmpstr(u->userinfo, ==, "jason:password");
  g_assert_cmpstr(u->host, ==, "example.com");
  g_assert(u->port == 5555);
  g_assert_cmpstr(u->path, ==, "/path/to/");
  uri_clear(u);

  /* this should fail */
  const char uri3[] = "http://baduri;f[303fds";
  const char *error_at = NULL;
  g_assert(uri_parse(u, uri3, strlen(uri3), &error_at) == 0);
  g_assert(error_at != NULL);
  g_assert_cmpstr("[303fds", ==, error_at);
  uri_clear(u);

  const char uri4[] = "https://example.com:23999";
  g_assert(uri_parse(u, uri4, strlen(uri4), &error_at));
  g_assert_cmpstr(u->scheme, ==, "https");
  g_assert_cmpstr(u->host, ==, "example.com");
  g_assert(u->port == 23999);
  /* TODO: maybe make empty path == NULL? */
  g_assert_cmpstr(u->path, ==, "");
  g_assert(u->query == NULL);
  g_assert(u->fragment == NULL);
  g_assert(error_at == NULL);
  uri_clear(u);

  const char uri5[] = "svn+ssh://jason:[email protected]:22/thing/and/stuff";
  g_assert(uri_parse(u, uri5, strlen(uri5), &error_at));
  g_assert_cmpstr(u->scheme, ==, "svn+ssh");
  g_assert_cmpstr(u->userinfo, ==, "jason:password");
  g_assert_cmpstr(u->host, ==, "example.com");
  g_assert(u->port == 22);
  g_assert_cmpstr(u->path, ==, "/thing/and/stuff");
  g_assert(error_at == NULL);
  uri_clear(u);

  uri_free(u);
}
コード例 #3
0
ファイル: uri.c プロジェクト: DarkDare/tarantool
int
test_invalid()
{
	plan(2);

	/* Invalid */
	struct uri u;
	isnt(uri_parse(&u, ""), 0 , "empty is invalid");
	isnt(uri_parse(&u, "://"), 0 , ":// is invalid");

	return check_plan();
}
コード例 #4
0
void
test_uri_merge_paths1(CuTest *tc)
{
	char *bpath  = strdup("http://www.example.com/a/path/to/uri"),
	     *rpath  = strdup("path/to/uri"),
	     *expect = strdup("/a/path/to/path/to/uri");
	uriobj_t base,
		 rel;
	uri_parse(&base,re, bpath);
	uri_parse(&rel, re, rpath);
	CuAssertStrEquals(tc, uri_merge_paths(&base,&rel), expect);
}
コード例 #5
0
void
test_uri_merge_paths2(CuTest *tc)
{
        char *bpath = strdup("http://www.example.com"),
             *rpath = strdup("path/to/uri"),
             *expect = strdup("/path/to/uri");
        uriobj_t *base = uri_alloc(),
                 *rel  = uri_alloc();
        uri_parse(&base, re, bpath);
        uri_parse(&rel, re, rpath);
        CuAssertStrEquals(tc, uri_merge_paths(rel,base),expect);
}
コード例 #6
0
static int sip_register_check_to_domain(const struct sip_message_t* req)
{
	int r;
	struct uri_t* to;
	struct uri_t* uri;
	to = uri_parse(req->to.uri.host.p, req->to.uri.host.n);
	uri = uri_parse(req->u.c.uri.host.p, req->u.c.uri.host.n);

	r = (!uri || !uri->host || !to || !to->host || 0 != strcasecmp(to->host, uri->host)) ? 0 : 1;

	uri_free(to);
	uri_free(uri);
	return r;
}
コード例 #7
0
void
test_uri_trans_ref8(CuTest *tc)
{
	char *href  = strdup("http://www.example.com/"),
	     *href2 = strdup("path/to/uri.html");
	uriobj_t *uri = uri_alloc(),
	         *ref = uri_alloc(),
			 *trans;
	uri_parse(&uri,re,href);
	uri_parse_auth(&uri);	
	uri_parse(&ref,re,href2);
	trans = uri_trans_ref(ref,uri,false); 
	CuAssertPtrNotNull(tc, trans);
}
コード例 #8
0
void
test_uri_trans_ref10(CuTest *tc)
{
	char *href  = strdup("http://www.example.com/some/dir/to/path"),
	     *href2 = strdup("path/to/uri.htm");
	uriobj_t *uri = uri_alloc(),
	         *ref = uri_alloc(),
			 *trans;
	uri_parse(&uri,re,href);
	uri_parse_auth(&uri);	
	uri_parse(&ref,re,href2);
	trans = uri_trans_ref(ref,uri,false);
	CuAssertStrEquals(tc,trans->uri_path, "/some/dir/to/path/to/uri.htm");
}
コード例 #9
0
test_uri_norm_scheme_1(CuTest *tc)
{
	char *seed = strdup("hTTp://www.example.com/test/func.cgi?x=y&z=j");
	uriobj_t uri;
	uri_parse(&uri, re, seed);
	CuAssertIntEquals(tc, uri_norm_scheme(&uri), 0);
}
コード例 #10
0
ファイル: uri.c プロジェクト: DarkDare/tarantool
int
test(const char *s, const char *scheme, const char *login, const char *password,
     const char *host, const char *service, const char *path,
     const char *query, const char *fragment, int host_hint)
{
	plan(10);

	struct uri uri;
	is(uri_parse(&uri, s), 0, "%s: parse", s);
	/* fprintf(stdout, #key ": %p %d %.*s\n", uri.key,
	   (int) uri.key ## _len, (int) uri.key ## _len, uri.key); */

#define chk(key) do { \
	ok((key && uri.key && strlen(key) == uri.key ## _len && \
	   memcmp(key, uri.key, uri.key ## _len) == 0) || \
	   (!key && !uri.key), "%s: " #key, s); } while (0);

	chk(scheme);
	chk(login);
	chk(password);
	chk(host);
	chk(service);
	chk(path);
	chk(query);
	chk(fragment);
	is(uri.host_hint, host_hint, "%s: host_hint", s);

#undef chk
	return check_plan();
}
コード例 #11
0
/*=====================================================================================
 * Do use ref_alloc when using ref_resolve,  them memory allocation will be done by
 * ref_resolve, so be allocating twice a memory leak can ocur.
 * ====================================================================================
 */
void
test_ref_resolve_1(CuTest *tc)
{
	char *href = strdup("http://www.example.com/"),
         *result;
	uriobj_t *uri = uri_alloc(),
             *ref;
    int err = 0;
    
    uri_parse(&uri,re,href);
	uri_parse_auth(&uri);
	uri_resolve(&uri);
	err = ref_resolve(&ref, uri, "path/to/uri.html",re,false);
    if( err == 0){
        result = strdup(ref->uri_path);
        printf("path = '%s'\n", result);
        free(result);
    }
    else {
        /* 
         * Should be checking for DNS_ERROR flag here but 
         * as this is just a test don't bother. 
         *
         **/
        printf("errstr = '%s'\n", strerror(err));
    }
    uri_free(uri);
    uri_free(ref);
	CuAssertIntEquals(tc,err,0);
}
コード例 #12
0
void
test_ref_resolve_2(CuTest *tc)
{
	char *href = strdup("http://www.example.com/some/dir/to/path"),
         *result;
	uriobj_t *uri = uri_alloc(),
             *ref;
    int err = 0;
    
	uri_parse(&uri,re,href);
	uri_parse_auth(&uri);
	uri_resolve(&uri);
	err = ref_resolve(&ref, uri, "path/to/uri.html",re,false);
    if( err == 0 ){
        result = strdup(ref->uri_path);
        printf("ref_resolve test 2 is successful\n");
        printf("ref->uri_scheme = '%s'\n", ref->uri_scheme);
        printf("ref->uri_auth   = '%s'\n", ref->uri_auth);
        printf("ref->uri_path   = '%s'\n", ref->uri_path);
        printf("ip address      = '%s'\n", ref->uri_ip->ip_addr);
        uri_free(ref);
    }
    uri_free(uri);
    CuAssertStrEquals(tc,"/some/dir/to/path/to/uri.html",result);
}
コード例 #13
0
ファイル: vxhs.c プロジェクト: Mellanox/qemu
/*
 * Parse incoming URI and populate *options with the host
 * and device information
 */
static int vxhs_parse_uri(const char *filename, QDict *options)
{
    URI *uri = NULL;
    char *port;
    int ret = 0;

    trace_vxhs_parse_uri_filename(filename);
    uri = uri_parse(filename);
    if (!uri || !uri->server || !uri->path) {
        uri_free(uri);
        return -EINVAL;
    }

    qdict_put_str(options, VXHS_OPT_SERVER ".host", uri->server);

    if (uri->port) {
        port = g_strdup_printf("%d", uri->port);
        qdict_put_str(options, VXHS_OPT_SERVER ".port", port);
        g_free(port);
    }

    qdict_put_str(options, "vdisk-id", uri->path);

    trace_vxhs_parse_uri_hostinfo(uri->server, uri->port);
    uri_free(uri);

    return ret;
}
コード例 #14
0
static AVInputFormat * get_format_by_extension (const gchar * name)
{
    const gchar * ext0, * sub;
    uri_parse (name, NULL, & ext0, & sub, NULL);

    if (ext0 == sub)
        return NULL;

    gchar * ext = g_ascii_strdown (ext0 + 1, sub - ext0 - 1);

    AUDDBG ("Get format by extension: %s\n", name);
    pthread_mutex_lock (& data_mutex);

    if (! extension_dict)
        extension_dict = create_extension_dict ();

    AVInputFormat * f = g_hash_table_lookup (extension_dict, ext);
    pthread_mutex_unlock (& data_mutex);

    if (f)
        AUDDBG ("Format %s.\n", f->name);
    else
        AUDDBG ("Format unknown.\n");

    g_free (ext);
    return f;
}
コード例 #15
0
test_uri_comp_recomp_1(CuTest *tc)
{
        char *expect = strdup("http://www.example.com/test/func.cgi?x=y&z=j");
        uriobj_t *uri = uri_alloc();
        uri_parse(&uri, re, expect);
        CuAssertStrEquals(tc, expect, uri_comp_recomp( uri ));
}
コード例 #16
0
static
struct lttng_uri *uri_from_path(const char *path)
{
	struct lttng_uri *uris = NULL;
	ssize_t uri_count;
	char local_protocol_string[LTTNG_PATH_MAX + sizeof("file://")] =
			"file://";

	if (strlen(path) >= LTTNG_PATH_MAX) {
		goto end;
	}

	if (path[0] != '/') {
		/* Not an absolute path. */
		goto end;
	}

	strncat(local_protocol_string, path, LTTNG_PATH_MAX);
	uri_count = uri_parse(local_protocol_string, &uris);
	if (uri_count != 1) {
		goto error;
	}
	if (uris[0].dtype != LTTNG_DST_PATH) {
		goto error;
	}

end:
	return uris;
error:
	free(uris);
	return NULL;
}
コード例 #17
0
ファイル: test-uri-parse.c プロジェクト: rupike/libguri
static void test_uri_parse_long(void) {
  static const char uri1[] = "http://www.google.com/images?hl=en&client=firefox-a&hs=tldrls=org.mozilla:en-US:official&q=philippine+hijacked+bus+picturesum=1&ie=UTF-8&source=univ&ei=SC-_TLbjE5H2tgO70PHODA&sa=X&oi=image_result_group&ct=titleresnum=1&ved=0CCIQsAQwAAbiw=1239bih=622";
  uri_t *u = uri_new();

  g_assert(uri_parse(u, uri1, strlen(uri1), NULL));
  uri_free(u);
}
コード例 #18
0
ファイル: gluster.c プロジェクト: NormanM/qemu
/*
 * file=gluster[+transport]://[server[:port]]/volname/image[?socket=...]
 *
 * 'gluster' is the protocol.
 *
 * 'transport' specifies the transport type used to connect to gluster
 * management daemon (glusterd). Valid transport types are
 * tcp, unix and rdma. If a transport type isn't specified, then tcp
 * type is assumed.
 *
 * 'server' specifies the server where the volume file specification for
 * the given volume resides. This can be either hostname, ipv4 address
 * or ipv6 address. ipv6 address needs to be within square brackets [ ].
 * If transport type is 'unix', then 'server' field should not be specifed.
 * The 'socket' field needs to be populated with the path to unix domain
 * socket.
 *
 * 'port' is the port number on which glusterd is listening. This is optional
 * and if not specified, QEMU will send 0 which will make gluster to use the
 * default port. If the transport type is unix, then 'port' should not be
 * specified.
 *
 * 'volname' is the name of the gluster volume which contains the VM image.
 *
 * 'image' is the path to the actual VM image that resides on gluster volume.
 *
 * Examples:
 *
 * file=gluster://1.2.3.4/testvol/a.img
 * file=gluster+tcp://1.2.3.4/testvol/a.img
 * file=gluster+tcp://1.2.3.4:24007/testvol/dir/a.img
 * file=gluster+tcp://[1:2:3:4:5:6:7:8]/testvol/dir/a.img
 * file=gluster+tcp://[1:2:3:4:5:6:7:8]:24007/testvol/dir/a.img
 * file=gluster+tcp://server.domain.com:24007/testvol/dir/a.img
 * file=gluster+unix:///testvol/dir/a.img?socket=/tmp/glusterd.socket
 * file=gluster+rdma://1.2.3.4:24007/testvol/a.img
 */
static int qemu_gluster_parseuri(GlusterConf *gconf, const char *filename)
{
    URI *uri;
    QueryParams *qp = NULL;
    bool is_unix = false;
    int ret = 0;

    uri = uri_parse(filename);
    if (!uri) {
        return -EINVAL;
    }

    /* transport */
    if (!strcmp(uri->scheme, "gluster")) {
        gconf->transport = g_strdup("tcp");
    } else if (!strcmp(uri->scheme, "gluster+tcp")) {
        gconf->transport = g_strdup("tcp");
    } else if (!strcmp(uri->scheme, "gluster+unix")) {
        gconf->transport = g_strdup("unix");
        is_unix = true;
    } else if (!strcmp(uri->scheme, "gluster+rdma")) {
        gconf->transport = g_strdup("rdma");
    } else {
        ret = -EINVAL;
        goto out;
    }

    ret = parse_volume_options(gconf, uri->path);
    if (ret < 0) {
        goto out;
    }

    qp = query_params_parse(uri->query);
    if (qp->n > 1 || (is_unix && !qp->n) || (!is_unix && qp->n)) {
        ret = -EINVAL;
        goto out;
    }

    if (is_unix) {
        if (uri->server || uri->port) {
            ret = -EINVAL;
            goto out;
        }
        if (strcmp(qp->p[0].name, "socket")) {
            ret = -EINVAL;
            goto out;
        }
        gconf->server = g_strdup(qp->p[0].value);
    } else {
        gconf->server = g_strdup(uri->server);
        gconf->port = uri->port;
    }

out:
    if (qp) {
        query_params_free(qp);
    }
    uri_free(uri);
    return ret;
}
コード例 #19
0
ファイル: uri.cpp プロジェクト: genjix/libwallet
bool uri_decode(const std::string& uri, uri_decode_result& result)
{
    uri_parse_result raw_result;
    if (!uri_parse(uri, raw_result))
        return false;
    if (raw_result.address)
        result.address.reset(raw_result.address.get());
    for (const parameter_pair& pair: raw_result.parameters)
    {
        if (pair.key == "amount")
        {
            uint64_t amount = parse_amount(pair.value);
            if (amount == std::numeric_limits<uint64_t>::max())
                return false;
            result.amount.reset(amount);
        }
        else if (pair.key == "label")
            result.label.reset(pair.value);
        else if (pair.key == "message")
            result.message.reset(pair.value);
        else if (pair.key == "r")
            result.r.reset(pair.value);
        else if (!pair.key.compare(0, 4, "req-"))
            return false;
    }
    return true;
}
コード例 #20
0
test_uri_norm_scheme_2(CuTest *tc)
{
	char *seed = strdup("hTTp://www.example.com/test/func.cgi?x=y&z=j");
	uriobj_t uri;
	uri_parse(&uri, re, seed);
	uri_norm_scheme(&uri);
	CuAssertStrEquals(tc, *uri.uri_scheme, "http" );
}
コード例 #21
0
test_uri_norm_auth_1(CuTest *tc)
{
	char *expect = strdup("http://www.example.com/test/func.cgi?x=y&z=j");
	uriobj_t uri;
	uri_parse(&uri, re, expect);
	int err = uri_norm_auth(&uri);
	CuAssertIntEquals(tc,0,err);
}
コード例 #22
0
test_uri_normalize_2(CuTest *tc)
{
	char *expect = strdup("http://www.example.com/test/func.cgi?x=y&z=j");
	uriobj_t uri;
	uri_parse(&uri, re, expect);
	int err = uri_normalize(&uri);
	CuAssertStrEquals(tc,*uri.uri_host,"www.example.com");
}
コード例 #23
0
test_uri_normalize_1(CuTest *tc)
{
	char *expect = strdup("http://192.168.1.100:8080/test/func.cgi?x=y&z=j");
	uriobj_t uri;
	uri_parse(&uri, re, expect);
	int err = uri_normalize(&uri);
	CuAssertStrEquals(tc,*uri.uri_ip,"192.168.1.100");
}
コード例 #24
0
test_uri_norm_auth_4(CuTest *tc)
{
	char *expect = strdup("http://www.example.com:8080/test/func.cgi?x=y&z=j");
	uriobj_t uri;
	uri_parse(&uri, re, expect);
	int err = uri_norm_auth(&uri);
	CuAssertStrEquals(tc,*uri.uri_port,"8080");
}
コード例 #25
0
void
test_uri_trans_ref2(CuTest *tc)
{
	char *bpath = strdup("http://www.example.com"),
	     *rpath = strdup("http://www.new.com/../path/to/uri.html");
	uriobj_t base,
		 rel,
		*tran;
	int cmp = 0;
	uri_parse(&base, re, bpath);
	uri_parse(&rel, re, rpath);
	tran = uri_trans_ref(&base, &rel, true); 
	cmp  = strcmp("http", *tran->uri_scheme);
	cmp += strcmp("www.new.com",*tran->uri_auth);
	cmp += strcmp("/path/to/uri.html",*tran->uri_path);
	CuAssertIntEquals(tc,cmp,0);
}
コード例 #26
0
void
test_uri_trans_ref7(CuTest *tc)
{
        char *bpath = strdup("http://www.example.com/this/is/a/buf/old/path#fragment"),
             *rpath = strdup("www.example.com/../../new/path/uri.html");
        uriobj_t *base = uri_alloc(),
                 *rel  = uri_alloc(),
                 *tran;
        int cmp = 0;
        uri_parse(&base, re, bpath);
        uri_parse(&rel, re, rpath);
        tran = uri_trans_ref(rel, base, true);
        cmp  = strcmp("http", tran->uri_scheme);
        cmp += strcmp("www.example.com",tran->uri_auth);
        cmp += strcmp("/this/is/a/buf/new/path/uri.html", tran->uri_path);
        CuAssertIntEquals(tc,cmp,0);
}
コード例 #27
0
ファイル: test-uri-parse.c プロジェクト: rupike/libguri
static void test_uri_normalize_one_slash(void) {
  static const char uri1[] = "eXAMPLE://a";
  static const char uri2[] = "eXAMPLE://a/";

  uri_t *u = uri_new();

  g_assert(uri_parse(u, uri1, strlen(uri1), NULL));
  uri_normalize(u);
  g_assert_cmpstr("/", ==, u->path);

  uri_clear(u);

  g_assert(uri_parse(u, uri2, strlen(uri2), NULL));
  uri_normalize(u);
  g_assert_cmpstr("/", ==, u->path);

  uri_free(u);
}
コード例 #28
0
void
test_uri_trans_ref4(CuTest *tc)
{
        char *bpath = strdup("http://www.example.com/old/path"),
             *rpath = strdup("/new/path/uri.html?query&e=b");
        uriobj_t *base = uri_alloc(),
                 *rel  = uri_alloc(),
                 *tran;
        int cmp = 0;
        uri_parse(&base, re, bpath);
        uri_parse(&rel, re, rpath);
        tran = uri_trans_ref(rel,base,true);
        cmp  = strcmp("http", tran->uri_scheme);
        cmp += strcmp("www.example.com",tran->uri_auth);
        cmp += strcmp("/new/path/uri.html",tran->uri_path);
        cmp += strcmp("query&e=b",tran->uri_query);
        CuAssertIntEquals(tc,cmp,0);
}
コード例 #29
0
test_uri_norm_ipv4_4(CuTest *tc)
{
	char *expect = strdup("http://www.example.com/test/func.cgi?x=y&z=j");
	uriobj_t uri;
	uri_parse(&uri, re, expect);
	int err = 0;
	*(uri.uri_ip) = strdup("192.368.1.1");
	err = uri_norm_ipv4(&uri);
	CuAssertIntEquals(tc,EILSEQ,err);
}
コード例 #30
0
test_uri_norm_host_5(CuTest *tc)
{
	char *expect = strdup("http://www.example.com/test/func.cgi?x=y&z=j");
	uriobj_t uri;
	uri_parse(&uri, re, expect);
	int err = 0;
	*uri.uri_host = strdup("www.	eXamPle.com%20%20");
	err = uri_norm_host(&uri);
	CuAssertIntEquals(tc,EILSEQ,err);
}