X-Git-Url: http://git.efficios.com/?p=lttng-tools.git;a=blobdiff_plain;f=src%2Fcommon%2Furi.c;h=ec5d426630b9300e925df81fa8d794b2ed282c94;hp=e686f7c5d788b2676a49c9b4746c846a63fc5aba;hb=ad20f4747b375cf21623ece9f76c9a9b54c493bb;hpb=8d3113b21fe5ed84af58fbfdff9ad7742db507d5 diff --git a/src/common/uri.c b/src/common/uri.c index e686f7c5d..ec5d42663 100644 --- a/src/common/uri.c +++ b/src/common/uri.c @@ -137,6 +137,40 @@ error: return -1; } +/* + * Build a string URL from a lttng_uri object. + */ +int uri_to_str_url(struct lttng_uri *uri, char *dst, size_t size) +{ + int ipver, ret; + const char *addr; + char proto[4], port[7]; + + assert(uri); + assert(dst); + + if (uri->dtype == LTTNG_DST_PATH) { + ipver = 0; + addr = uri->dst.path; + (void) snprintf(proto, sizeof(proto), "file"); + (void) snprintf(port, sizeof(port), "%s", ""); + } else { + ipver = (uri->dtype == LTTNG_DST_IPV4) ? 4 : 6; + addr = (ipver == 4) ? uri->dst.ipv4 : uri->dst.ipv6; + (void) snprintf(proto, sizeof(proto), "net%d", ipver); + (void) snprintf(port, sizeof(port), ":%d", uri->port); + } + + ret = snprintf(dst, size, "%s://%s%s%s%s/%s", proto, + (ipver == 6) ? "[" : "", addr, (ipver == 6) ? "]" : "", + port, uri->subdir); + if (ret < 0) { + PERROR("snprintf uri to url"); + } + + return ret; +} + /* * Compare two URIs. *