diff options
author | Jo-Philipp Wich <jo@mein.io> | 2018-04-09 09:47:40 +0200 |
---|---|---|
committer | Jo-Philipp Wich <jo@mein.io> | 2018-04-10 11:41:32 +0200 |
commit | ad7dc4a4928e77ae142d0fe040f9e9e64b530e82 (patch) | |
tree | 231c94708ba29b19386c608d6b9f34f3938fbbde /modules/luci-base/src/template_utils.h | |
parent | edd1fab34eaa98be624bbba17f60a8ae63744a98 (diff) |
luci-base: add urldecode() and urlencode() C implementations
The C implementations of urlencode and urldecode are considerably faster
than their current Lua counterparts.
On an AMD Geode system, the C variant is up to ten times faster when
decoding strings and up to four times faster when encoding them.
The functions are also designed to only allocate new strings when any
actual changes are required, otherwise they reuse the existing input
strings, reducing the overal memory usage somewhat.
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
Diffstat (limited to 'modules/luci-base/src/template_utils.h')
-rw-r--r-- | modules/luci-base/src/template_utils.h | 6 |
1 files changed, 5 insertions, 1 deletions
diff --git a/modules/luci-base/src/template_utils.h b/modules/luci-base/src/template_utils.h index 32a79f93bc..872ecb072f 100644 --- a/modules/luci-base/src/template_utils.h +++ b/modules/luci-base/src/template_utils.h @@ -1,7 +1,7 @@ /* * LuCI Template - Utility header * - * Copyright (C) 2010-2012 Jo-Philipp Wich <jow@openwrt.org> + * Copyright (C) 2010-2018 Jo-Philipp Wich <jo@mein.io> * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -22,6 +22,8 @@ #include <stdlib.h> #include <stdio.h> #include <string.h> +#include <stdbool.h> +#include <ctype.h> /* buffer object */ @@ -42,6 +44,8 @@ char * buf_destroy(struct template_buffer *buf); char * utf8(const char *s, unsigned int l); char * pcdata(const char *s, unsigned int l); char * striptags(const char *s, unsigned int l); +char * urlencode(const char *s, size_t *encoded_len); +char * urldecode(const char *s, size_t *decoded_len, bool keep_plus); void luastr_escape(struct template_buffer *out, const char *s, unsigned int l, int escape_xml); void luastr_translate(struct template_buffer *out, const char *s, unsigned int l, int escape_xml); |