Skip to contentSkip to conversation

util/uri: Simplify the code, remove unused functions

PATCH In review Thomas Huth 3 participants 7 messages Jan 23, 2024 – Jan 24, 2024

lore
Share & tools
lore
#0 lore raw

v2 cover util/uri: Simplify the code, remove unused functions

The URI function uri_string_unescape() is pretty much the same as the function g_uri_unescape_segment() from the glib, so we can simplify our code here quite a bit.
While at it, I also noticed that there are many other unused functions in here which we likely can drop, too.

v2:
- Replace uri_string_unescape() with g_uri_unescape_segment(), so we can remove uri_string_unescape() completely now

Thomas Huth (4):
util/uri: Remove uri_string_unescape()
util/uri: Remove unused functions uri_resolve() and
uri_resolve_relative()
util/uri: Remove the uri_string_escape() function util/uri: Remove unused macros ISA_RESERVED() and ISA_GEN_DELIM()

 include/qemu/uri.h |   4 -
 util/uri.c         | 869 +--------------------------------------------
 2 files changed, 11 insertions(+), 862 deletions(-)
Signature · 1 line
2.43.0
#1 lore raw

PATCH v2 1/4 util/uri: Remove uri_string_unescape()

uri_string_unescape() basically does the same as the glib function g_uri_unescape_segment(). So we can get rid of our implementation completely by simply using the glib function instead.

---
 include/qemu/uri.h |  1 -
 util/uri.c         | 97 ++++++----------------------------------------
 2 files changed, 11 insertions(+), 87 deletions(-)
include/qemu/uri.h +0 -1
index 1855b764f2..f0722b75da 100644
@@ -79,7 +79,6 @@ URI *uri_parse_raw(const char *str, int raw);
 int uri_parse_into(URI *uri, const char *str);
 char *uri_to_string(URI *uri);
 char *uri_string_escape(const char *str, const char *list);
-char *uri_string_unescape(const char *str, int len, char *target);
 void uri_free(URI *uri);
 
 /* Single web service query parameter 'name=value'. */
util/uri.c +11 -86

163 lines not on this page · raw message

Signature · 1 line
2.43.0
Reviewed-by Stefan Weil on v2 1/4
#2 lore raw

Re: [PATCH v2 1/4] util/uri: Remove uri_string_unescape()

Am 23.01.24 um 19:22 schrieb Thomas Huth:

Quoted 4 lines

uri_string_unescape() basically does the same as the glib function g_uri_unescape_segment(). So we can get rid of our implementation completely by simply using the glib function instead.

Quoted 8 lines
---
  include/qemu/uri.h |  1 -
  util/uri.c         | 97 ++++++----------------------------------------
  2 files changed, 11 insertions(+), 87 deletions(-)

Thank you, Thomas and Paolo.

#3 lore raw

PATCH v2 2/4 util/uri: Remove unused functions uri_resolve() and uri_resolve_relative()

In reply to 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.

---
 include/qemu/uri.h |   2 -
 util/uri.c         | 689 ---------------------------------------------
 2 files changed, 691 deletions(-)
include/qemu/uri.h +0 -2
index f0722b75da..899ce852f5 100644
@@ -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);
util/uri.c +0 -689

701 lines not on this page · raw message

Signature · 1 line
2.43.0
#4 lore raw

PATCH v2 3/4 util/uri: Remove the uri_string_escape() function

In reply to Thomas Huth

Now that uri_resolve_relative() has been removed, this function is not used in QEMU anymore - and if somebody needs this functionality, they can simply use g_uri_escape_string() from the glib instead.

---
 include/qemu/uri.h |  1 -
 util/uri.c         | 70 ----------------------------------------------
 2 files changed, 71 deletions(-)
include/qemu/uri.h +0 -1
index 899ce852f5..255e61f452 100644
@@ -76,7 +76,6 @@ URI *uri_parse(const char *str);
 URI *uri_parse_raw(const char *str, int raw);
 int uri_parse_into(URI *uri, const char *str);
 char *uri_to_string(URI *uri);
-char *uri_string_escape(const char *str, const char *list);
 void uri_free(URI *uri);
 
 /* Single web service query parameter 'name=value'. */
util/uri.c +0 -70

76 lines not on this page · raw message

Signature · 1 line
2.43.0
#5 lore raw

PATCH v2 4/4 util/uri: Remove unused macros ISA_RESERVED() and ISA_GEN_DELIM()

In reply to Thomas Huth

They are not used anywhere, so there's no need to keep them around.

Message-ID: <[email protected]>

---
 util/uri.c | 13 -------------
 1 file changed, 13 deletions(-)
util/uri.c +0 -13
index 350835b03f..573174bf47 100644
@@ -163,19 +163,6 @@ static void uri_clean(URI *uri);
      ((*(p) == '+')) || ((*(p) == ',')) || ((*(p) == ';')) ||                  \
      ((*(p) == '=')) || ((*(p) == '\'')))
 
-/*
- *    gen-delims    = ":" / "/" / "?" / "#" / "[" / "]" / "@"
- */
-#define ISA_GEN_DELIM(p)                                                       \
-    (((*(p) == ':')) || ((*(p) == '/')) || ((*(p) == '?')) ||                  \
-     ((*(p) == '#')) || ((*(p) == '[')) || ((*(p) == ']')) ||                  \
-     ((*(p) == '@')))
-
-/*
- *    reserved      = gen-delims / sub-delims
- */
-#define ISA_RESERVED(p) (ISA_GEN_DELIM(p) || (ISA_SUB_DELIM(p)))
-
 /*
  *    unreserved    = ALPHA / DIGIT / "-" / "." / "_" / "~"
  */
Signature · 1 line
2.43.0