about summary refs log tree commit diff
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--parsing.c58
1 files changed, 58 insertions, 0 deletions
diff --git a/parsing.c b/parsing.c
index 16b4db7..f156c12 100644
--- a/parsing.c
+++ b/parsing.c
@@ -6,6 +6,8 @@
  *   (see COPYING for full license text)
  */
 
+#include <iconv.h>
+
 #include "cgit.h"
 
 int next_char(FILE *f)
@@ -176,6 +178,62 @@ void cgit_parse_url(const char *url)
 	}
 }
 
+static char *iconv_msg(char *msg, const char *encoding)
+{
+	iconv_t msg_conv = iconv_open(PAGE_ENCODING, encoding);
+	size_t inlen = strlen(msg);
+	char *in;
+	char *out;
+	size_t inleft;
+	size_t outleft;
+	char *buf;
+	char *ret;
+	size_t buf_sz;
+	int again, fail;
+
+	if(msg_conv == (iconv_t)-1)
+		return NULL;
+
+	buf_sz = inlen * 2;
+	buf = xmalloc(buf_sz+1);
+	do {
+		in = msg;
+		inleft = inlen;
+
+		out = buf;
+		outleft = buf_sz;
+		iconv(msg_conv, &in, &inleft, &out, &outleft);
+
+		if(inleft == 0) {
+			fail = 0;
+			again = 0;
+		} else if(inleft != 0 && errno == E2BIG) {
+			fail = 0;
+			again = 1;
+
+			buf_sz *= 2;
+			free(buf);
+			buf = xmalloc(buf_sz+1);
+		} else {
+			fail = 1;
+			again = 0;
+		}
+	} while(again && !fail);
+
+	if(fail) {
+		free(buf);
+		ret = NULL;
+	} else {
+		buf = xrealloc(buf, out - buf);
+		*out = 0;
+		ret = buf;
+	}
+
+	iconv_close(msg_conv);
+
+	return ret;
+}
+
 char *substr(const char *head, const char *tail)
 {
 	char *buf;
-08-20Replace verbose colors with two types of arrowsJune McEnroe 2021-08-20Explicitly clear TLS secrets after handshakeJune McEnroe 2021-08-20Handle TLS_WANT_POLL{IN,OUT} from tls_handshake(3) with serverJune McEnroe 2021-08-20Use "secure" libtls ciphersJune McEnroe 2021-07-08Use seprintf to build final 005June McEnroe 2021-06-19Fix LDADD.crypt on DarwinJune McEnroe 2021-06-18Add -m mode option to set user modesJune McEnroe 2021-06-18Document channel keys in join optionJune McEnroe 2021-06-18Use | to separate flags from config optionsJune McEnroe 2021-06-18Stop referring to server-time as IRCv3.2June McEnroe 2021-06-17Add mailing list archive to READMEJune McEnroe 2021-06-10Stop accumulating ISUPPORT tokens once MOTD startsJune McEnroe 2021-06-09Use seprintf for snip, removing strlcpynJune McEnroe 2021-06-09Use seprintf for reserializeJune McEnroe 2021-06-09Use seprintf for capListJune McEnroe 2021-06-09Add seprintfJune McEnroe 2021-05-27Add pounce-notify to README 2.4June McEnroe 2021-05-27Fix ENVIRONMENT formatting in pounce-notify(1)June McEnroe 2021-05-27Add note about Libera.Chat SASL-only rangesJune McEnroe 2021-05-25Add QUIRKS fileJune McEnroe 2021-05-19Replace freenode with tilde.chatJune McEnroe 2021-05-04notify: Reword pounce-notify manualJune McEnroe 2021-05-02Clean up Makefiles, configure scriptsJune McEnroe 2021-04-30palaver: Exit on getopt failureJune McEnroe 2021-04-30notify: Implement pounce-notifyJune McEnroe