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); }
/* Give it a path segment, it returns non-zero if child is * a child of parent. */ int uri_childof(const char *parent, const char *child) { char *root = ne_strdup(child); int ret; if (strlen(parent) >= strlen(child)) { ret = 0; } else { /* root is the first of child, equal to length of parent */ root[strlen(parent)] = '\0'; ret = (uri_compare(parent, root) == 0); } free(root); return ret; }
int bpd_bind_list_find_by_bp_endpoint_id(struct URI* bp_endpoint_id_ptr) { struct BIND_STRUCT* bind_struct_ptr; int i; for (i = 0; i < bpd_bind_list.nr; i++){ bind_struct_ptr = &bpd_bind_list.bind_structs[i]; // if (bind_struct_ptr->valid == 0){ // continue; // } if (uri_compare(bp_endpoint_id_ptr, &bind_struct_ptr->bp_endpoint_id) == 0){ return i; } } return -1; }
int main(int argc, char *argv[]) { char *tmp; if (argc<2 || argc>3) { printf("Usage:\nuritest uria [urib]\n" "e.g. uritest \"/this/is/a silly<filename>/but/hey\"\n"); exit(-1); } if (argv[2]) { printf("uri_compare: %s with %s: %s\n", argv[1], argv[2], uri_compare(argv[1], argv[2])==0?"true":"false"); } else { printf("Input URI: %s\n", argv[1]); tmp = uri_abspath_escape(argv[1]); printf("Encoded: %s\n", tmp); printf("Decoded: %s\n", uri_unescape(tmp)); } return 0; }