Browse Source

[core] Add li-prefix to structs, enums and function names for encoding helpers

personal/stbuehler/wip
Thomas Porzelt 12 years ago
parent
commit
6cb5af487f
  1. 12
      include/lighttpd/encoding.h
  2. 18
      src/common/encoding.c
  3. 8
      src/modules/mod_dirlist.c
  4. 2
      src/modules/mod_redirect.c
  5. 2
      src/modules/mod_rewrite.c

12
include/lighttpd/encoding.h

@ -4,14 +4,14 @@
#include <lighttpd/settings.h>
typedef enum {
ENCODING_HEX, /* a => 61 */
ENCODING_HTML, /* HTML special chars. & => &amp; e.g. */
ENCODING_URI /* relative URI */
} encoding_t;
LI_ENCODING_HEX, /* a => 61 */
LI_ENCODING_HTML, /* HTML special chars. & => &amp; e.g. */
LI_ENCODING_URI /* relative URI */
} liEncoding;
/* encodes special characters in a string and returns the new string */
GString *string_encode_append(const gchar *str, GString *dest, encoding_t encoding);
GString *string_encode(const gchar *str, GString *dest, encoding_t encoding);
LI_API GString *li_string_encode_append(const gchar *str, GString *dest, liEncoding encoding);
LI_API GString *li_string_encode(const gchar *str, GString *dest, liEncoding encoding);
#endif

18
src/common/encoding.c

@ -72,7 +72,7 @@ static const gchar encode_map_uri[] = {
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, /* F0 - FF */
};
GString *string_encode_append(const gchar *str, GString *dest, encoding_t encoding) {
GString *li_string_encode_append(const gchar *str, GString *dest, liEncoding encoding) {
GString *result;
guchar *c;
guchar *pos = NULL;
@ -81,16 +81,16 @@ GString *string_encode_append(const gchar *str, GString *dest, encoding_t encodi
const gchar *map = NULL;
switch (encoding) {
case ENCODING_HTML:
case LI_ENCODING_HTML:
/* replace html chars with &#xHH; */
map = encode_map_html;
encoded_len = 6;
break;
case ENCODING_HEX:
case LI_ENCODING_HEX:
map = encode_map_hex;
encoded_len = 2;
break;
case ENCODING_URI:
case LI_ENCODING_URI:
/* ? => %HH */
map = encode_map_uri;
encoded_len = 3;
@ -116,7 +116,7 @@ GString *string_encode_append(const gchar *str, GString *dest, encoding_t encodi
}
switch (encoding) {
case ENCODING_HTML:
case LI_ENCODING_HTML:
for (c = (guchar*)str; *c != '\0'; c++) {
if (map[*c]) {
/* char needs to be encoded */
@ -133,7 +133,7 @@ GString *string_encode_append(const gchar *str, GString *dest, encoding_t encodi
}
}
break;
case ENCODING_HEX:
case LI_ENCODING_HEX:
for (c = (guchar*)str; *c != '\0'; c++) {
if (map[*c]) {
/* char needs to be encoded */
@ -145,7 +145,7 @@ GString *string_encode_append(const gchar *str, GString *dest, encoding_t encodi
}
}
break;
case ENCODING_URI:
case LI_ENCODING_URI:
for (c = (guchar*)str; *c != '\0'; c++) {
if (map[*c]) {
/* char needs to be encoded */
@ -165,7 +165,7 @@ GString *string_encode_append(const gchar *str, GString *dest, encoding_t encodi
return result;
}
GString *string_encode(const gchar *str, GString *dest, encoding_t encoding) {
GString *li_string_encode(const gchar *str, GString *dest, liEncoding encoding) {
if (dest) g_string_truncate(dest, 0);
return string_encode_append(str, dest, encoding);
return li_string_encode_append(str, dest, encoding);
}

8
src/modules/mod_dirlist.c

@ -337,10 +337,10 @@ static liHandlerResult dirlist(liVRequest *vr, gpointer param, gpointer *context
datebuf[datebuflen] = '\0';
g_string_append_len(listing, CONST_STR_LEN(" <tr><td><a href=\""));
string_encode(sced->path->str, encoded, ENCODING_URI);
li_string_encode(sced->path->str, encoded, LI_ENCODING_URI);
g_string_append_len(listing, GSTR_LEN(encoded));
g_string_append_len(listing, CONST_STR_LEN("/\">"));
string_encode(sced->path->str, encoded, ENCODING_HTML);
li_string_encode(sced->path->str, encoded, LI_ENCODING_HTML);
g_string_append_len(listing, GSTR_LEN(encoded));
g_string_append_len(listing, CONST_STR_LEN("</a></td><td class=\"modified\" val=\""));
li_string_append_int(listing, sced->st.st_mtime);
@ -366,10 +366,10 @@ static liHandlerResult dirlist(liVRequest *vr, gpointer param, gpointer *context
dirlist_format_size(sizebuf, sced->st.st_size);
g_string_append_len(listing, CONST_STR_LEN(" <tr><td><a href=\""));
string_encode(sced->path->str, encoded, ENCODING_URI);
li_string_encode(sced->path->str, encoded, LI_ENCODING_URI);
g_string_append_len(listing, GSTR_LEN(encoded));
g_string_append_len(listing, CONST_STR_LEN("\">"));
string_encode(sced->path->str, encoded, ENCODING_HTML);
li_string_encode(sced->path->str, encoded, LI_ENCODING_HTML);
g_string_append_len(listing, GSTR_LEN(encoded));
g_string_append_len(listing, CONST_STR_LEN(
"</a></td>"

2
src/modules/mod_redirect.c

@ -318,7 +318,7 @@ static gboolean redirect_internal(liVRequest *vr, GString *dest, redirect_rule *
g_string_append_len(dest, CONST_STR_LEN("http"));
} else {
if (encoded)
string_encode_append(str->str, dest, ENCODING_URI);
li_string_encode_append(str->str, dest, LI_ENCODING_URI);
else
g_string_append_len(dest, GSTR_LEN(str));
}

2
src/modules/mod_rewrite.c

@ -302,7 +302,7 @@ static gboolean rewrite_internal(liVRequest *vr, GString *dest_path, GString *de
g_string_append_len(dest, CONST_STR_LEN("http"));
} else {
if (encoded)
string_encode_append(str->str, dest, ENCODING_URI);
li_string_encode_append(str->str, dest, LI_ENCODING_URI);
else
g_string_append_len(dest, GSTR_LEN(str));
}

Loading…
Cancel
Save