summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: c9b217f)
raw | patch | inline | side by side (parent: c9b217f)
author | Florian Forster <ff@octo.it> | |
Wed, 9 Jun 2010 17:01:25 +0000 (19:01 +0200) | ||
committer | Florian Forster <octo@leeloo.lan.home.verplant.org> | |
Wed, 9 Jun 2010 17:01:25 +0000 (19:01 +0200) |
utils_params.c | patch | blob | history | |
utils_params.h | patch | blob | history |
diff --git a/utils_params.c b/utils_params.c
index ec943b56eaa8746435a0d9d32a48b9aa589382d7..6e5dc892e377a43fb8b619772767dd1d13e02854 100644 (file)
--- a/utils_params.c
+++ b/utils_params.c
return (parameter_lookup (key));
} /* }}} const char *param */
+int uri_escape (char *dst, const char *src, size_t size) /* {{{ */
+{
+ size_t in;
+ size_t out;
+
+ in = 0;
+ out = 0;
+ while (42)
+ {
+ if (src[in] == 0)
+ {
+ dst[out] = 0;
+ return (0);
+ }
+ else if ((src[in] < 32)
+ || (src[in] == '&')
+ || (src[in] == ';')
+ || (src[in] >= 128))
+ {
+ char esc[4];
+
+ if ((size - out) < 4)
+ break;
+
+ snprintf (esc, sizeof (esc), "%%%02x", (unsigned int) src[in]);
+ dst[out] = esc[0];
+ dst[out+1] = esc[1];
+ dst[out+2] = esc[2];
+
+ out += 3;
+ in++;
+ }
+ else
+ {
+ dst[out] = src[in];
+ out++;
+ in++;
+ }
+ } /* while (42) */
+} /* }}} int uri_escape */
+
/* vim: set sw=2 sts=2 et fdm=marker : */
diff --git a/utils_params.h b/utils_params.h
index b68ad4db8cd3d52126ee48fce42326001a5406ee..3c7ea0a2091df2211659ed721f9ead6038af590f 100644 (file)
--- a/utils_params.h
+++ b/utils_params.h
const char *param (const char *key);
+int uri_escape (char *dst, const char *src, size_t size);
+
#endif /* UTILS_PARAMS_H */