|
@@ -491,6 +491,28 @@ static int lsp_md5(lua_State *L)
|
|
|
return 1;
|
|
|
}
|
|
|
|
|
|
+/* mg.url_encode */
|
|
|
+static int lsp_url_encode(lua_State *L)
|
|
|
+{
|
|
|
+ int num_args = lua_gettop(L);
|
|
|
+ const char *text;
|
|
|
+ size_t text_len;
|
|
|
+ char dst[512];
|
|
|
+
|
|
|
+ if (num_args==1) {
|
|
|
+ text = lua_tolstring(L, 1, &text_len);
|
|
|
+ if (text) {
|
|
|
+ mg_url_encode(text, dst, sizeof(dst));
|
|
|
+ lua_pushstring(L, dst);
|
|
|
+ } else {
|
|
|
+ lua_pushnil(L);
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ /* Syntax error */
|
|
|
+ return luaL_error(L, "invalid get_mime_type() call");
|
|
|
+ }
|
|
|
+ return 1;
|
|
|
+}
|
|
|
|
|
|
/* TODO: Other functions in civetweb.h that should be available to Lua too:
|
|
|
mg_url_decode
|
|
@@ -611,6 +633,7 @@ static void prepare_lua_environment(struct mg_connection *conn, lua_State *L, co
|
|
|
reg_function(L, "get_mime_type", lsp_get_mime_type, conn);
|
|
|
reg_function(L, "get_cookie", lsp_get_cookie, conn);
|
|
|
reg_function(L, "md5", lsp_md5, conn);
|
|
|
+ reg_function(L, "url_encode", lsp_url_encode, conn);
|
|
|
|
|
|
reg_string(L, "version", CIVETWEB_VERSION);
|
|
|
reg_string(L, "document_root", conn->ctx->config[DOCUMENT_ROOT]);
|