Rename and update config. Update Makefile for this change.
[prosody.git] / util-src / encodings.c
index f99d3faff067163226e98ea144fd31948aeeded1..ac24ebcfcce2280087aa4f2a7cedd2b2042f33d3 100644 (file)
@@ -1,25 +1,17 @@
 /*\r
-* xxpath.c\r
-* An implementation of a subset of xpath for Lua 5.1\r
-* Waqas Hussain <waqas20@gmail.com>\r
-* 05 Oct 2008 15:28:15\r
+* encodings.c\r
+* Lua library for base64, stringprep and idna encodings\r
 */\r
 \r
+// Newer MSVC compilers deprecate strcpy as unsafe, but we use it in a safe way\r
+#define _CRT_SECURE_NO_DEPRECATE\r
+\r
 #include <string.h>\r
+#include <malloc.h>\r
 \r
 #include "lua.h"\r
 #include "lauxlib.h"\r
 \r
-/*const char* hex_tab = "0123456789abcdef";\r
-void toHex(const char* in, int length, char* out) {\r
-       int i;\r
-       for (i = 0; i < length; i++) {\r
-               out[i*2] = hex_tab[(in[i] >> 4) & 0xF];\r
-               out[i*2+1] = hex_tab[(in[i]) & 0xF];\r
-       }\r
-       //out[i*2] = 0;\r
-}*/\r
-\r
 /***************** BASE64 *****************/\r
 \r
 #define uint unsigned int\r
@@ -63,9 +55,9 @@ static void base64_decode(luaL_Buffer *b, int c1, int c2, int c3, int c4, int n)
        char s[3];\r
        switch (--n)\r
        {\r
-               case 3: s[2]=tuple;\r
-               case 2: s[1]=tuple >> 8;\r
-               case 1: s[0]=tuple >> 16;\r
+               case 3: s[2]=(char) tuple;\r
+               case 2: s[1]=(char) (tuple >> 8);\r
+               case 1: s[0]=(char) (tuple >> 16);\r
        }\r
        luaL_addlstring(b,s,n);\r
 }\r
@@ -86,7 +78,7 @@ static int Lbase64_decode(lua_State *L)               /** decode(s) */
                        const char *p;\r
                        default:\r
                                p=strchr(code,c); if (p==NULL) return 0;\r
-                               t[n++]= p-code;\r
+                               t[n++]= (char) (p-code);\r
                                if (n==4)\r
                                {\r
                                        base64_decode(&b,t[0],t[1],t[2],t[3],4);\r
@@ -211,7 +203,7 @@ static const luaL_Reg Reg[] =
        { NULL,         NULL    }\r
 };\r
 \r
-LUALIB_API int luaopen_encodings(lua_State *L)\r
+LUALIB_API int luaopen_util_encodings(lua_State *L)\r
 {\r
        luaL_register(L, "encodings", Reg);\r
 \r