Re: [PATCH 4/5] util/uri: Remove unused functions uri_resolve() and uri_resolve_relative()

2024-01-22 Thread Stefan Weil via

Am 22.01.24 um 20:17 schrieb Thomas Huth:


These rather complex functions have never been used since they've been
introduced in 2012, so looks like they are not really useful for QEMU.
And since the static normalize_uri_path() function is also only used by
uri_resolve(), we can remove that function now, too.

Signed-off-by: Thomas Huth 
---
  include/qemu/uri.h |   2 -
  util/uri.c | 689 -
  2 files changed, 691 deletions(-)



This patch should be applied before patch 3 (so switch the order of the 
patches 3 and 4). With this change:


Reviewed-by: Stefan Weil 




[PATCH 4/5] util/uri: Remove unused functions uri_resolve() and uri_resolve_relative()

2024-01-22 Thread Thomas Huth
These rather complex functions have never been used since they've been
introduced in 2012, so looks like they are not really useful for QEMU.
And since the static normalize_uri_path() function is also only used by
uri_resolve(), we can remove that function now, too.

Signed-off-by: Thomas Huth 
---
 include/qemu/uri.h |   2 -
 util/uri.c | 689 -
 2 files changed, 691 deletions(-)

diff --git a/include/qemu/uri.h b/include/qemu/uri.h
index c1734d28c3..93538b7578 100644
--- a/include/qemu/uri.h
+++ b/include/qemu/uri.h
@@ -72,8 +72,6 @@ typedef struct URI {
 } URI;
 
 URI *uri_new(void);
-char *uri_resolve(const char *URI, const char *base);
-char *uri_resolve_relative(const char *URI, const char *base);
 URI *uri_parse(const char *str);
 URI *uri_parse_raw(const char *str, int raw);
 int uri_parse_into(URI *uri, const char *str);
diff --git a/util/uri.c b/util/uri.c
index 912e406523..5f5ca79792 100644
--- a/util/uri.c
+++ b/util/uri.c
@@ -1355,212 +1355,6 @@ void uri_free(URI *uri)
  *  *
  /
 
-/**
- * normalize_uri_path:
- * @path:  pointer to the path string
- *
- * Applies the 5 normalization steps to a path string--that is, RFC 2396
- * Section 5.2, steps 6.c through 6.g.
- *
- * Normalization occurs directly on the string, no new allocation is done
- *
- * Returns 0 or an error code
- */
-static int normalize_uri_path(char *path)
-{
-char *cur, *out;
-
-if (path == NULL) {
-return -1;
-}
-
-/* Skip all initial "/" chars.  We want to get to the beginning of the
- * first non-empty segment.
- */
-cur = path;
-while (cur[0] == '/') {
-++cur;
-}
-if (cur[0] == '\0') {
-return 0;
-}
-
-/* Keep everything we've seen so far.  */
-out = cur;
-
-/*
- * Analyze each segment in sequence for cases (c) and (d).
- */
-while (cur[0] != '\0') {
-/*
- * c) All occurrences of "./", where "." is a complete path segment,
- *are removed from the buffer string.
- */
-if ((cur[0] == '.') && (cur[1] == '/')) {
-cur += 2;
-/* '//' normalization should be done at this point too */
-while (cur[0] == '/') {
-cur++;
-}
-continue;
-}
-
-/*
- * d) If the buffer string ends with "." as a complete path segment,
- *that "." is removed.
- */
-if ((cur[0] == '.') && (cur[1] == '\0')) {
-break;
-}
-
-/* Otherwise keep the segment.  */
-while (cur[0] != '/') {
-if (cur[0] == '\0') {
-goto done_cd;
-}
-(out++)[0] = (cur++)[0];
-}
-/* nomalize // */
-while ((cur[0] == '/') && (cur[1] == '/')) {
-cur++;
-}
-
-(out++)[0] = (cur++)[0];
-}
-done_cd:
-out[0] = '\0';
-
-/* Reset to the beginning of the first segment for the next sequence.  */
-cur = path;
-while (cur[0] == '/') {
-++cur;
-}
-if (cur[0] == '\0') {
-return 0;
-}
-
-/*
- * Analyze each segment in sequence for cases (e) and (f).
- *
- * e) All occurrences of "/../", where  is a
- *complete path segment not equal to "..", are removed from the
- *buffer string.  Removal of these path segments is performed
- *iteratively, removing the leftmost matching pattern on each
- *iteration, until no matching pattern remains.
- *
- * f) If the buffer string ends with "/..", where 
- *is a complete path segment not equal to "..", that
- *"/.." is removed.
- *
- * To satisfy the "iterative" clause in (e), we need to collapse the
- * string every time we find something that needs to be removed.  Thus,
- * we don't need to keep two pointers into the string: we only need a
- * "current position" pointer.
- */
-while (1) {
-char *segp, *tmp;
-
-/* At the beginning of each iteration of this loop, "cur" points to
- * the first character of the segment we want to examine.
- */
-
-/* Find the end of the current segment.  */
-segp = cur;
-while ((segp[0] != '/') && (segp[0] != '\0')) {
-++segp;
-}
-
-/* If this is the last segment, we're done (we need at least two
- * segments to meet the criteria for the (e) and (f) cases).
- */
-if (segp[0] == '\0') {
-break;
-}
-
-/* If the first segment is "..", or if the next segment _isn't_ "..",
- * keep this segment and try the next one.
- */
-++segp;
-if (((cur[0] == '.') && (cur[1] == '.') && (segp == cur + 3)) ||
-((segp[0] != '.') || (segp[1] != '.') ||
-