<html><head></head><body>Hi,<br><br>Since when we require the vlc prefix for (new) private APIs?<br><br>And it's not through review because I've had enough of getting blatant filibuster on the previous versions of the same patchset.<br><br>I did send all the core changes for review. I don't like how I'm being singled out for sending non-core non-lib changes, when I'm evidently not the only one to do do. Especially not when I did in fact send patches for review to a large extent.<br><br><div class="gmail_quote">Le 28 septembre 2020 11:20:06 GMT+03:00, Thomas Guillem <thomas@gllm.fr> a écrit :<blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">
<pre class="k9mail"><br><br>On Sun, Sep 27, 2020, at 15:16, Rémi Denis-Courmont wrote:<br><blockquote class="gmail_quote" style="margin: 0pt 0pt 1ex 0.8ex; border-left: 1px solid #729fcf; padding-left: 1ex;">vlc | branch: master | Rémi Denis-Courmont <remi@remlab.net> | Sun Sep <br>27 15:19:42 2020 +0300| [c4c1bc81e819cee65f673a10f58e40f56eab9704] | <br>committer: Rémi Denis-Courmont<br><br>JSON representation and Javascript unescaping<br><br><blockquote class="gmail_quote" style="margin: 0pt 0pt 1ex 0.8ex; border-left: 1px solid #ad7fa8; padding-left: 1ex;"><a href="http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=c4c1bc81e819cee65f673a10f58e40f56eab9704">http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=c4c1bc81e819cee65f673a10f58e40f56eab9704</a><br></blockquote><hr> modules/demux/Makefile.am | 7 +++<br> modules/demux/json/json.c | 145 ++++++++++++++++++++++++++++++++++++++++++++++<br> modules/demux/json/json.h | 73 +++++++++++++++++++++++<br> 3 files changed, 225 insertions(+)<br><br>diff --git a/modules/demux/Makefile.am b/modules/demux/Makefile.am<br>index 675b2d10af..f46fcdb92e 100644<br>--- a/modules/demux/Makefile.am<br>+++ b/modules/demux/Makefile.am<br>@@ -512,3 +512,10 @@ libdemux_mock_plugin_la_SOURCES = demux/mock.c<br> libdemux_mock_plugin_la_LDFLAGS = $(AM_LDFLAGS) -rpath '$(demuxdir)'<br> libdemux_mock_plugin_la_LIBADD = $(LIBM)<br> noinst_LTLIBRARIES += libdemux_mock_plugin.la<br>+<br>+libvlc_json_la_SOURCES = \<br>+ demux/json/json.c demux/json/json.h<br>+libvlc_json_la_CPPFLAGS = $(AM_CPPFLAGS) -I$(srcdir)/demux/json<br>+libvlc_json_la_LIBADD = $(LTLIBVLCCORE) ../compat/libcompat.la<br>+libvlc_json_la_LDFLAGS = -static<br>+noinst_LTLIBRARIES += libvlc_json.la<br>diff --git a/modules/demux/json/json.c b/modules/demux/json/json.c<br>new file mode 100644<br>index 0000000000..d0ab86120a<br>--- /dev/null<br>+++ b/modules/demux/json/json.c<br>@@ -0,0 +1,145 @@<br>+/*****************************************************************************<br>+ * json/json.c: JSON parsing library<br>+ *****************************************************************************<br>+ * Copyright © 2020 Rémi Denis-Courmont<br>+ *<br>+ * This program is free software; you can redistribute it and/or modify it<br>+ * under the terms of the GNU Lesser General Public License as published by<br>+ * the Free Software Foundation; either version 2.1 of the License, or<br>+ * (at your option) any later version.<br>+ *<br>+ * This program is distributed in the hope that it will be useful,<br>+ * but WITHOUT ANY WARRANTY; without even the implied warranty of<br>+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the<br>+ * GNU Lesser General Public License for more details.<br>+ *<br>+ * You should have received a copy of the GNU Lesser General Public License<br>+ * along with this program; if not, write to the Free Software Foundation,<br>+ * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.<br>+ *****************************************************************************/<br>+<br>+#ifdef HAVE_CONFIG_H<br>+# include <config.h><br>+#endif<br>+<br>+#include <assert.h><br>+#include <math.h><br>+#include <stdint.h><br>+#include <stdlib.h><br>+#include <string.h><br>+#include <vlc_common.h><br>+#include <vlc_charset.h><br>+#include "json.h"<br>+<br>+#ifdef WORDS_BIGENDIAN<br>+# define ENDIAN(x) x "BE"<br>+#else<br>+# define ENDIAN(x) x "LE"<br>+#endif<br>+<br>+char *json_unescape(const char *in, size_t inlen)<br>+{<br>+ /* 1) Convert UTF-8 to UTF-16.<br>+ * This will catch any invalid UTF-8 byte sequence.<br>+ */<br>+ size_t buflen = 2 * (inlen + 1);<br>+ void *buf = malloc(buflen);<br>+<br>+ if (unlikely(buf == NULL))<br>+ return NULL;<br>+<br>+ vlc_iconv_t hd = vlc_iconv_open(ENDIAN("UTF-16") , "UTF-8");<br>+<br>+ if (unlikely(hd == (vlc_iconv_t)-1)) {<br>+ free(buf);<br>+ return NULL;<br>+ }<br>+<br>+ char *out = buf;<br>+ size_t outlen = buflen;<br>+ size_t val = vlc_iconv(hd, &in, &inlen, &out, &outlen);<br>+<br>+ vlc_iconv_close(hd);<br>+<br>+ if (val == (size_t)-1) {<br>+ free(buf);<br>+ return NULL;<br>+ }<br>+<br>+ /* 2) Unescape in UTF-16 (in place).<br>+ */<br>+ const uint16_t *in2 = buf, *end2 = in2 + ((buflen - outlen) / 2);<br>+ uint16_t *out2 = buf;<br>+<br>+ while (in2 < end2) {<br>+ uint16_t c = *(in2++);<br>+<br>+ if (c == '\\') {<br>+ switch (*(in2++)) {<br>+ case 'b':<br>+ c = '\b';<br>+ break;<br>+ case 'f':<br>+ c = '\f';<br>+ break;<br>+ case 'n':<br>+ c = '\n';<br>+ break;<br>+ case 'r':<br>+ c = '\r';<br>+ break;<br>+ case 't':<br>+ c = '\t';<br>+ break;<br>+ case 'u': {<br>+ char hex[5] = { in2[0], in2[1], in2[2], in2[3], 0 };<br>+<br>+ /* Tokeniser requires 4 hex-digits, so this cannot fail. */<br>+ if (sscanf(hex, "%4"SCNx16, &c) != 1)<br>+ vlc_assert_unreachable();<br>+<br>+ in2 += 4;<br>+ break;<br>+ }<br>+ default:<br>+ /* Invalid escape is not allowed by tokeniser. */<br>+ vlc_assert_unreachable();<br>+ }<br>+ }<br>+<br>+ assert(out2 < in2); /* Safely in place */<br>+ *(out2++) = c;<br>+ }<br>+<br>+ /* 3) Convert back to UTF-8.<br>+ * This will catch any invalid sequence of escaped UTF-16 surrogates.<br>+ */<br>+ char *ret = FromCharset(ENDIAN("UTF-16"), buf, (char *)out2 - (char *)buf);<br>+<br>+ free(buf);<br>+ return ret;<br>+}<br>+<br>+const struct json_value *json_get(const struct json_object *obj,<br>+ const char *name)<br>+{<br>+ for (size_t i = 0; i < obj->count; i++)<br>+ if (!strcmp(obj->members[i].name, name))<br>+ return &obj->members[i].value;<br>+<br>+ return NULL;<br>+}<br>+<br>+const char *json_get_str(const struct json_object *obj, const char *name)<br>+{<br>+ const struct json_value *v = json_get(obj, name);<br>+<br>+ return (v != NULL && v->type == JSON_STRING) ? v->string : NULL;<br>+}<br>+<br>+double json_get_num(const struct json_object *obj, const char *name)<br>+{<br>+ const struct json_value *v = json_get(obj, name);<br>+<br>+ return (v != NULL && v->type == JSON_NUMBER) ? v->number : NAN;<br>+}<br>diff --git a/modules/demux/json/json.h b/modules/demux/json/json.h<br>new file mode 100644<br>index 0000000000..e468ec871f<br>--- /dev/null<br>+++ b/modules/demux/json/json.h<br>@@ -0,0 +1,73 @@<br>+/*****************************************************************************<br>+ * json/json.h:<br>+ *****************************************************************************<br>+ * Copyright © 2020 Rémi Denis-Courmont<br>+ *<br>+ * This program is free software; you can redistribute it and/or modify it<br>+ * under the terms of the GNU Lesser General Public License as published by<br>+ * the Free Software Foundation; either version 2.1 of the License, or<br>+ * (at your option) any later version.<br>+ *<br>+ * This program is distributed in the hope that it will be useful,<br>+ * but WITHOUT ANY WARRANTY; without even the implied warranty of<br>+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the<br>+ * GNU Lesser General Public License for more details.<br>+ *<br>+ * You should have received a copy of the GNU Lesser General Public License<br>+ * along with this program; if not, write to the Free Software Foundation,<br>+ * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.<br>+ *****************************************************************************/<br>+<br>+#ifndef JSON_H<br>+#define JSON_H<br>+<br>+#include <stdbool.h><br>+#include <stdio.h><br>+<br>+enum json_type {<br>+ JSON_NULL,<br>+ JSON_BOOLEAN,<br>+ JSON_NUMBER,<br>+ JSON_STRING,<br>+ JSON_ARRAY,<br>+ JSON_OBJECT,<br>+};<br>+<br>+struct json_array {<br>+ size_t size;<br>+ struct json_value *entries;<br>+};<br>+<br>+struct json_object {<br>+ size_t count;<br>+ struct json_member *members;<br>+};<br>+<br>+struct json_value {<br>+ enum json_type type;<br>+ union {<br>+ bool boolean;<br>+ double number;<br>+ char *string;<br>+ struct json_array array;<br>+ struct json_object object;<br>+ };<br>+};<br>+<br>+struct json_member {<br>+ char *name;<br>+ struct json_value value;<br>+};<br>+<br>+void json_parse_error(void *log, const char *msg);<br>+char *json_unescape(const char *, size_t);<br>+<br>+int json_parse(void *log, FILE *in, struct json_object *result);<br>+void json_free(struct json_object *);<br>+<br>+const struct json_value *json_get(const struct json_object *obj,<br>+ const char *name);<br>+const char *json_get_str(const struct json_object *obj, const char *name);<br>+double json_get_num(const struct json_object *obj, const char *name);<br></blockquote><br>Please prefix with *vlc_* for new APIs (even module-only ones).<br><br>Also: Why not passing by the mailing list?<br><br><blockquote class="gmail_quote" style="margin: 0pt 0pt 1ex 0.8ex; border-left: 1px solid #729fcf; padding-left: 1ex;"> +<br> +#endif<hr> vlc-commits mailing list<br> vlc-commits@videolan.org<br> <a href="https://mailman.videolan.org/listinfo/vlc-commits">https://mailman.videolan.org/listinfo/vlc-commits</a><br><br></blockquote><hr>vlc-devel mailing list<br>To unsubscribe or modify your subscription options:<br><a href="https://mailman.videolan.org/listinfo/vlc-devel">https://mailman.videolan.org/listinfo/vlc-devel</a></pre></blockquote></div><br>-- <br>Envoyé de mon appareil Android avec Courriel K-9 Mail. Veuillez excuser ma brièveté.</body></html>