X-Git-Url: https://the.earth.li/gitweb/?p=onak.git;a=blobdiff_plain;f=keyindex.c;fp=keyindex.c;h=fbd32c710959ebc0ce6c30fa8543e2d92bf9d3a1;hp=e8d569a45b22de0d04e4ab4a9eae82af3acf1839;hb=f6d38365b7e7e1e88ba02136ffe6f0fb08903ef0;hpb=b767e3e90280a1222fc4404cbd4c832342c9382d diff --git a/keyindex.c b/keyindex.c index e8d569a..fbd32c7 100644 --- a/keyindex.c +++ b/keyindex.c @@ -24,7 +24,6 @@ #include #include "decodekey.h" -#include "getcgi.h" #include "keydb.h" #include "keyid.h" #include "keyindex.h" @@ -74,6 +73,54 @@ char pkalgo2char(uint8_t algo) return typech; } +/** + * txt2html - Takes a string and converts it to HTML. + * @string: The string to HTMLize. + * + * Takes a string and escapes any HTML entities. + */ +const char *txt2html(const char *string) +{ + static char buf[1024]; + char *ptr = NULL; + char *nextptr = NULL; + + if (strlen(string) > 1000) { + return string; + } + + memset(buf, 0, 1024); + + ptr = strchr(string, '<'); + if (ptr != NULL) { + nextptr = ptr + 1; + *ptr = 0; + strncpy(buf, string, 1023); + strncat(buf, "<", 1023 - strlen(buf)); + string = nextptr; + } + + ptr = strchr(string, '>'); + if (ptr != NULL) { + nextptr = ptr + 1; + *ptr = 0; + strncat(buf, string, 1023 - strlen(buf)); + strncat(buf, ">", 1023 - strlen(buf)); + string = nextptr; + } + + /* + * TODO: We need to while() this really as each entity may appear more + * than once. We need to start with & and ; as we replace with those + * throughout. Fuck it for the moment though; it's Easter and < & > are + * the most common and tend to only appear once. + */ + + strncat(buf, string, 1023 - strlen(buf)); + + return buf; +} + /* * Given a public key/subkey packet return the key length. */