[vlc-commits] lua http: make string easier to translate
Rafaël Carré
git at videolan.org
Thu Jun 6 14:56:12 CEST 2013
vlc | branch: master | Rafaël Carré <funman at videolan.org> | Thu Jun 6 13:40:55 2013 +0200| [39c41fec23535c2d5ed72016a6a9d9f2fbf5852c] | committer: Rafaël Carré
lua http: make string easier to translate
> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=39c41fec23535c2d5ed72016a6a9d9f2fbf5852c
---
modules/lua/libs/httpd.c | 39 ++++++++++++++++++++++++++++-----------
1 file changed, 28 insertions(+), 11 deletions(-)
diff --git a/modules/lua/libs/httpd.c b/modules/lua/libs/httpd.c
index 82fb1f6..1205102 100644
--- a/modules/lua/libs/httpd.c
+++ b/modules/lua/libs/httpd.c
@@ -61,17 +61,23 @@ static const luaL_Reg vlclua_httpd_reg[] = {
{ NULL, NULL }
};
-static const char no_password[] = N_("<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">\n"
+static const char no_password_fmt[] = "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">\n"
"<html xmlns=\"http://www.w3.org/1999/xhtml\">"
"<head>"
"<meta http-equiv=\"Content-Type\" content=\"text/html;charset=utf-8\" />"
-"<title>VLC media player</title>"
+"<title>%s</title>"
"</head>"
"<body>"
+"%s"
+"<!-- VLC_PASSWORD_NOT_SET --></body></html>";
+
+static const char no_password_body[] = N_(
"<p>Password for Web interface has not been set.</p>"
"<p>Please use --http-password, or set a password in </p>"
"<p>Preferences > All > Main interfaces > Lua > Lua HTTP > Password.</p>"
-"<!-- VLC_PASSWORD_NOT_SET --></body></html>");
+);
+
+static const char no_password_title[] = N_("VLC media player");
static int vlclua_httpd_tls_host_new( lua_State *L )
{
@@ -154,13 +160,20 @@ static int vlclua_httpd_handler_callback(
if (!p_sys->password)
{
free(*pp_data);
- size_t s = strlen(_(no_password));
- if (asprintf((char**)pp_data, "Status: 403\n"
- "Content-Length: %zu\n"
- "Content-Type: text/html\n\n%s", s, _(no_password)) < 0)
+ char *no_password = NULL;
+ if (asprintf(&no_password, no_password_fmt,
+ _(no_password_title), _(no_password_body)) < 0) {
*pi_data = 0;
- else
- *pi_data = strlen((char*)*pp_data);
+ } else {
+ size_t s = strlen(no_password);
+ if (asprintf((char**)pp_data, "Status: 403\n"
+ "Content-Length: %zu\n"
+ "Content-Type: text/html\n\n%s", s, no_password) < 0)
+ *pi_data = 0;
+ else
+ *pi_data = strlen((char*)*pp_data);
+ free(no_password);
+ }
}
lua_pop( L, 1 );
/* function data */
@@ -257,8 +270,12 @@ static int vlclua_httpd_file_callback(
if (!p_sys->password)
{
free(*pp_data);
- *pp_data = (uint8_t*)strdup(_(no_password));
- *pi_data = strlen((char*)*pp_data);
+ if (asprintf((char**)pp_data, no_password_fmt,
+ _(no_password_title), _(no_password_body)) < 0) {
+ *pi_data = 0;
+ } else {
+ *pi_data = strlen((char*)*pp_data);
+ }
}
lua_pop( L, 1 );
/* function data */
More information about the vlc-commits
mailing list