Licensing/version updates for some files (forgot to commit, doh...)
authorMatthew Wild <mwild1@gmail.com>
Mon, 2 Feb 2009 18:03:18 +0000 (18:03 +0000)
committerMatthew Wild <mwild1@gmail.com>
Mon, 2 Feb 2009 18:03:18 +0000 (18:03 +0000)
util-src/encodings.c
util-src/hashes.c
util-src/pposix.c

index 6697fc2f665f67943f2e3c0352ed276c952df8aa..ef45f4d43cd77cc42104786634d681152fab6713 100644 (file)
-/* Prosody IM v0.1
--- Copyright (C) 2008 Matthew Wild
--- Copyright (C) 2008 Waqas Hussain
+/* Prosody IM v0.3
+-- Copyright (C) 2008-2009 Matthew Wild
+-- Copyright (C) 2008-2009 Waqas Hussain
 -- 
--- This program is free software; you can redistribute it and/or
--- modify it under the terms of the GNU General Public License
--- as published by the Free Software Foundation; either version 2
--- of the License, or (at your option) any later version.
--- 
--- This program is distributed in the hope that it will be useful,
--- but WITHOUT ANY WARRANTY; without even the implied warranty of
--- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
--- GNU General Public License for more details.
--- 
--- You should have received a copy of the GNU General Public License
--- along with this program; if not, write to the Free Software
--- Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+-- This project is MIT/X11 licensed. Please see the
+-- COPYING file in the source package for more information.
+--
+*/
+
+/*
+* encodings.c
+* Lua library for base64, stringprep and idna encodings
 */
 
+// Newer MSVC compilers deprecate strcpy as unsafe, but we use it in a safe way
+#define _CRT_SECURE_NO_DEPRECATE
+
+#include <string.h>
+#include <stdlib.h>
+
+#include "lua.h"
+#include "lauxlib.h"
+
+/***************** BASE64 *****************/
+
+static const char code[]=
+"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
 
-/*\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 <stdlib.h>\r
-\r
-#include "lua.h"\r
-#include "lauxlib.h"\r
-\r
-/***************** BASE64 *****************/\r
-\r
-static const char code[]=\r
-"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";\r
-\r
-static void base64_encode(luaL_Buffer *b, unsigned int c1, unsigned int c2, unsigned int c3, int n)\r
-{\r
-       unsigned long tuple=c3+256UL*(c2+256UL*c1);\r
-       int i;\r
-       char s[4];\r
-       for (i=0; i<4; i++) {\r
-               s[3-i] = code[tuple % 64];\r
-               tuple /= 64;\r
-       }\r
-       for (i=n+1; i<4; i++) s[i]='=';\r
-       luaL_addlstring(b,s,4);\r
-}\r
-\r
-static int Lbase64_encode(lua_State *L)                /** encode(s) */\r
-{\r
-       size_t l;\r
-       const unsigned char *s=(const unsigned char*)luaL_checklstring(L,1,&l);\r
-       luaL_Buffer b;\r
-       int n;\r
-       luaL_buffinit(L,&b);\r
-       for (n=l/3; n--; s+=3) base64_encode(&b,s[0],s[1],s[2],3);\r
-       switch (l%3)\r
-       {\r
-               case 1: base64_encode(&b,s[0],0,0,1);           break;\r
-               case 2: base64_encode(&b,s[0],s[1],0,2);                break;\r
-       }\r
-       luaL_pushresult(&b);\r
-       return 1;\r
-}\r
-\r
-static void base64_decode(luaL_Buffer *b, int c1, int c2, int c3, int c4, int n)\r
-{\r
-       unsigned long tuple=c4+64L*(c3+64L*(c2+64L*c1));\r
-       char s[3];\r
-       switch (--n)\r
-       {\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
-\r
-static int Lbase64_decode(lua_State *L)                /** decode(s) */\r
-{\r
-       size_t l;\r
-       const char *s=luaL_checklstring(L,1,&l);\r
-       luaL_Buffer b;\r
-       int n=0;\r
-       char t[4];\r
-       luaL_buffinit(L,&b);\r
-       for (;;)\r
-       {\r
+static void base64_encode(luaL_Buffer *b, unsigned int c1, unsigned int c2, unsigned int c3, int n)
+{
+       unsigned long tuple=c3+256UL*(c2+256UL*c1);
+       int i;
+       char s[4];
+       for (i=0; i<4; i++) {
+               s[3-i] = code[tuple % 64];
+               tuple /= 64;
+       }
+       for (i=n+1; i<4; i++) s[i]='=';
+       luaL_addlstring(b,s,4);
+}
+
+static int Lbase64_encode(lua_State *L)                /** encode(s) */
+{
+       size_t l;
+       const unsigned char *s=(const unsigned char*)luaL_checklstring(L,1,&l);
+       luaL_Buffer b;
+       int n;
+       luaL_buffinit(L,&b);
+       for (n=l/3; n--; s+=3) base64_encode(&b,s[0],s[1],s[2],3);
+       switch (l%3)
+       {
+               case 1: base64_encode(&b,s[0],0,0,1);           break;
+               case 2: base64_encode(&b,s[0],s[1],0,2);                break;
+       }
+       luaL_pushresult(&b);
+       return 1;
+}
+
+static void base64_decode(luaL_Buffer *b, int c1, int c2, int c3, int c4, int n)
+{
+       unsigned long tuple=c4+64L*(c3+64L*(c2+64L*c1));
+       char s[3];
+       switch (--n)
+       {
+               case 3: s[2]=(char) tuple;
+               case 2: s[1]=(char) (tuple >> 8);
+               case 1: s[0]=(char) (tuple >> 16);
+       }
+       luaL_addlstring(b,s,n);
+}
+
+static int Lbase64_decode(lua_State *L)                /** decode(s) */
+{
+       size_t l;
+       const char *s=luaL_checklstring(L,1,&l);
+       luaL_Buffer b;
+       int n=0;
+       char t[4];
+       luaL_buffinit(L,&b);
+       for (;;)
+       {
                int c=*s++;
-               switch (c)\r
-               {\r
-                       const char *p;\r
-                       default:\r
-                               p=strchr(code,c); if (p==NULL) return 0;\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
-                                       n=0;\r
-                               }\r
-                               break;\r
-                       case '=':\r
-                               switch (n)\r
-                               {\r
-                                       case 1: base64_decode(&b,t[0],0,0,0,1);         break;\r
-                                       case 2: base64_decode(&b,t[0],t[1],0,0,2);      break;\r
+               switch (c)
+               {
+                       const char *p;
+                       default:
+                               p=strchr(code,c); if (p==NULL) return 0;
+                               t[n++]= (char) (p-code);
+                               if (n==4)
+                               {
+                                       base64_decode(&b,t[0],t[1],t[2],t[3],4);
+                                       n=0;
+                               }
+                               break;
+                       case '=':
+                               switch (n)
+                               {
+                                       case 1: base64_decode(&b,t[0],0,0,0,1);         break;
+                                       case 2: base64_decode(&b,t[0],t[1],0,0,2);      break;
                                        case 3: base64_decode(&b,t[0],t[1],t[2],0,3);   break;
                                }
                                n=0;
-                               break;\r
-                       case 0:\r
-                               luaL_pushresult(&b);\r
-                               return 1;\r
-                       case '\n': case '\r': case '\t': case ' ': case '\f': case '\b':\r
-                               break;\r
-               }\r
-       }\r
-       return 0;\r
-}\r
-\r
-static const luaL_Reg Reg_base64[] =\r
-{\r
-       { "encode",     Lbase64_encode  },\r
-       { "decode",     Lbase64_decode  },\r
-       { NULL,         NULL    }\r
-};\r
-\r
-/***************** STRINGPREP *****************/\r
-\r
-#include <stringprep.h>\r
-\r
-static int stringprep_prep(lua_State *L, const Stringprep_profile *profile)\r
-{\r
-       size_t len;\r
-       const char *s = luaL_checklstring(L, 1, &len);\r
-       char string[1024];\r
-       int ret;\r
-       if (len >= 1024) {\r
-               lua_pushnil(L);\r
-               return 1; // TODO return error message\r
-       }\r
-       strcpy(string, s);\r
-       ret = stringprep(string, 1024, 0, profile);\r
-       if (ret == STRINGPREP_OK) {\r
-               lua_pushstring(L, string);\r
-               return 1;\r
-       } else {\r
-               lua_pushnil(L);\r
-               return 1; // TODO return error message\r
-       }\r
-}\r
-\r
-#define MAKE_PREP_FUNC(myFunc, prep) \\r
-static int myFunc(lua_State *L) { return stringprep_prep(L, prep); }\r
-\r
-MAKE_PREP_FUNC(Lstringprep_nameprep, stringprep_nameprep)              /** stringprep.nameprep(s) */\r
-MAKE_PREP_FUNC(Lstringprep_nodeprep, stringprep_xmpp_nodeprep)         /** stringprep.nodeprep(s) */\r
-MAKE_PREP_FUNC(Lstringprep_resourceprep, stringprep_xmpp_resourceprep)         /** stringprep.resourceprep(s) */\r
-MAKE_PREP_FUNC(Lstringprep_saslprep, stringprep_saslprep)              /** stringprep.saslprep(s) */\r
-\r
-static const luaL_Reg Reg_stringprep[] =\r
-{\r
-       { "nameprep",   Lstringprep_nameprep    },\r
-       { "nodeprep",   Lstringprep_nodeprep    },\r
-       { "resourceprep",       Lstringprep_resourceprep        },\r
-       { "saslprep",   Lstringprep_saslprep    },\r
-       { NULL,         NULL    }\r
-};\r
-\r
-/***************** IDNA *****************/\r
-\r
-#include <idna.h>\r
-\r
-static int Lidna_to_ascii(lua_State *L)                /** idna.to_ascii(s) */\r
-{\r
-       size_t len;\r
-       const char *s = luaL_checklstring(L, 1, &len);\r
-       char* output = NULL;\r
-       int ret = idna_to_ascii_8z(s, &output, 0);\r
-       if (ret == IDNA_SUCCESS) {\r
-               lua_pushstring(L, output);\r
-               if (output) free(output);\r
-               return 1;\r
-       } else {\r
-               lua_pushnil(L);\r
-               if (output) free(output);\r
-               return 1; // TODO return error message\r
-       }\r
-}\r
-\r
-static int Lidna_to_unicode(lua_State *L)              /** idna.to_unicode(s) */\r
-{\r
-       size_t len;\r
-       const char *s = luaL_checklstring(L, 1, &len);\r
-       char* output = NULL;\r
-       int ret = idna_to_unicode_8z8z(s, &output, 0);\r
-       if (ret == IDNA_SUCCESS) {\r
-               lua_pushstring(L, output);\r
-               if (output) free(output);\r
-               return 1;\r
-       } else {\r
-               lua_pushnil(L);\r
-               if (output) free(output);\r
-               return 1; // TODO return error message\r
-       }\r
-}\r
-\r
-static const luaL_Reg Reg_idna[] =\r
-{\r
-       { "to_ascii",   Lidna_to_ascii  },\r
-       { "to_unicode", Lidna_to_unicode        },\r
-       { NULL,         NULL    }\r
-};\r
-\r
-/***************** end *****************/\r
-\r
-static const luaL_Reg Reg[] =\r
-{\r
-       { NULL,         NULL    }\r
-};\r
-\r
-LUALIB_API int luaopen_util_encodings(lua_State *L)\r
-{\r
-       luaL_register(L, "encodings", Reg);\r
-\r
-       lua_pushliteral(L, "base64");\r
-       lua_newtable(L);\r
-       luaL_register(L, NULL, Reg_base64);\r
-       lua_settable(L,-3);\r
-\r
-       lua_pushliteral(L, "stringprep");\r
-       lua_newtable(L);\r
-       luaL_register(L, NULL, Reg_stringprep);\r
-       lua_settable(L,-3);\r
-\r
-       lua_pushliteral(L, "idna");\r
-       lua_newtable(L);\r
-       luaL_register(L, NULL, Reg_idna);\r
-       lua_settable(L,-3);\r
-\r
-       lua_pushliteral(L, "version");                  /** version */\r
-       lua_pushliteral(L, "-3.14");\r
-       lua_settable(L,-3);\r
-       return 1;\r
-}\r
+                               break;
+                       case 0:
+                               luaL_pushresult(&b);
+                               return 1;
+                       case '\n': case '\r': case '\t': case ' ': case '\f': case '\b':
+                               break;
+               }
+       }
+       return 0;
+}
+
+static const luaL_Reg Reg_base64[] =
+{
+       { "encode",     Lbase64_encode  },
+       { "decode",     Lbase64_decode  },
+       { NULL,         NULL    }
+};
+
+/***************** STRINGPREP *****************/
+
+#include <stringprep.h>
+
+static int stringprep_prep(lua_State *L, const Stringprep_profile *profile)
+{
+       size_t len;
+       const char *s = luaL_checklstring(L, 1, &len);
+       char string[1024];
+       int ret;
+       if (len >= 1024) {
+               lua_pushnil(L);
+               return 1; // TODO return error message
+       }
+       strcpy(string, s);
+       ret = stringprep(string, 1024, 0, profile);
+       if (ret == STRINGPREP_OK) {
+               lua_pushstring(L, string);
+               return 1;
+       } else {
+               lua_pushnil(L);
+               return 1; // TODO return error message
+       }
+}
+
+#define MAKE_PREP_FUNC(myFunc, prep) \
+static int myFunc(lua_State *L) { return stringprep_prep(L, prep); }
+
+MAKE_PREP_FUNC(Lstringprep_nameprep, stringprep_nameprep)              /** stringprep.nameprep(s) */
+MAKE_PREP_FUNC(Lstringprep_nodeprep, stringprep_xmpp_nodeprep)         /** stringprep.nodeprep(s) */
+MAKE_PREP_FUNC(Lstringprep_resourceprep, stringprep_xmpp_resourceprep)         /** stringprep.resourceprep(s) */
+MAKE_PREP_FUNC(Lstringprep_saslprep, stringprep_saslprep)              /** stringprep.saslprep(s) */
+
+static const luaL_Reg Reg_stringprep[] =
+{
+       { "nameprep",   Lstringprep_nameprep    },
+       { "nodeprep",   Lstringprep_nodeprep    },
+       { "resourceprep",       Lstringprep_resourceprep        },
+       { "saslprep",   Lstringprep_saslprep    },
+       { NULL,         NULL    }
+};
+
+/***************** IDNA *****************/
+
+#include <idna.h>
+
+static int Lidna_to_ascii(lua_State *L)                /** idna.to_ascii(s) */
+{
+       size_t len;
+       const char *s = luaL_checklstring(L, 1, &len);
+       char* output = NULL;
+       int ret = idna_to_ascii_8z(s, &output, 0);
+       if (ret == IDNA_SUCCESS) {
+               lua_pushstring(L, output);
+               if (output) free(output);
+               return 1;
+       } else {
+               lua_pushnil(L);
+               if (output) free(output);
+               return 1; // TODO return error message
+       }
+}
+
+static int Lidna_to_unicode(lua_State *L)              /** idna.to_unicode(s) */
+{
+       size_t len;
+       const char *s = luaL_checklstring(L, 1, &len);
+       char* output = NULL;
+       int ret = idna_to_unicode_8z8z(s, &output, 0);
+       if (ret == IDNA_SUCCESS) {
+               lua_pushstring(L, output);
+               if (output) free(output);
+               return 1;
+       } else {
+               lua_pushnil(L);
+               if (output) free(output);
+               return 1; // TODO return error message
+       }
+}
+
+static const luaL_Reg Reg_idna[] =
+{
+       { "to_ascii",   Lidna_to_ascii  },
+       { "to_unicode", Lidna_to_unicode        },
+       { NULL,         NULL    }
+};
+
+/***************** end *****************/
+
+static const luaL_Reg Reg[] =
+{
+       { NULL,         NULL    }
+};
+
+LUALIB_API int luaopen_util_encodings(lua_State *L)
+{
+       luaL_register(L, "encodings", Reg);
+
+       lua_pushliteral(L, "base64");
+       lua_newtable(L);
+       luaL_register(L, NULL, Reg_base64);
+       lua_settable(L,-3);
+
+       lua_pushliteral(L, "stringprep");
+       lua_newtable(L);
+       luaL_register(L, NULL, Reg_stringprep);
+       lua_settable(L,-3);
+
+       lua_pushliteral(L, "idna");
+       lua_newtable(L);
+       luaL_register(L, NULL, Reg_idna);
+       lua_settable(L,-3);
+
+       lua_pushliteral(L, "version");                  /** version */
+       lua_pushliteral(L, "-3.14");
+       lua_settable(L,-3);
+       return 1;
+}
index ec045c1d86b9fd51ca87fb7f8c4248823692599c..79ef227f70360dfb6147913dddd09e0ba6a13b69 100644 (file)
@@ -1,78 +1,68 @@
-/* Prosody IM v0.1
+/* Prosody IM v0.3
 -- Copyright (C) 2008 Matthew Wild
 -- Copyright (C) 2008 Waqas Hussain
 -- 
--- This program is free software; you can redistribute it and/or
--- modify it under the terms of the GNU General Public License
--- as published by the Free Software Foundation; either version 2
--- of the License, or (at your option) any later version.
--- 
--- This program is distributed in the hope that it will be useful,
--- but WITHOUT ANY WARRANTY; without even the implied warranty of
--- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
--- GNU General Public License for more details.
--- 
--- You should have received a copy of the GNU General Public License
--- along with this program; if not, write to the Free Software
--- Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+-- This project is MIT/X11 licensed. Please see the
+-- COPYING file in the source package for more information.
+--
+*/
+
+
+/*
+* hashes.c
+* Lua library for sha1, sha256 and md5 hashes
 */
 
+#include <string.h>
+
+#include "lua.h"
+#include "lauxlib.h"
+#include <openssl/sha.h>
+#include <openssl/md5.h>
+
+const char* hex_tab = "0123456789abcdef";
+void toHex(const char* in, int length, char* out) {
+       int i;
+       for (i = 0; i < length; i++) {
+               out[i*2] = hex_tab[(in[i] >> 4) & 0xF];
+               out[i*2+1] = hex_tab[(in[i]) & 0xF];
+       }
+}
+
+#define MAKE_HASH_FUNCTION(myFunc, func, size) \
+static int myFunc(lua_State *L) { \
+       size_t len; \
+       const char *s = luaL_checklstring(L, 1, &len); \
+       int hex_out = lua_toboolean(L, 2); \
+       char hash[size]; \
+       char result[size*2]; \
+       func((const unsigned char*)s, len, (unsigned char*)hash);  \
+       if (hex_out) { \
+               toHex(hash, size, result); \
+               lua_pushlstring(L, result, size*2); \
+       } else { \
+               lua_pushlstring(L, hash, size);\
+       } \
+       return 1; \
+}
+
+MAKE_HASH_FUNCTION(Lsha1, SHA1, 20)
+MAKE_HASH_FUNCTION(Lsha256, SHA256, 32)
+MAKE_HASH_FUNCTION(Lmd5, MD5, 16)
+
+static const luaL_Reg Reg[] =
+{
+       { "sha1",       Lsha1   },
+       { "sha256",     Lsha256 },
+       { "md5",        Lmd5    },
+       { NULL,         NULL    }
+};
 
-/*\r
-* hashes.c\r
-* Lua library for sha1, sha256 and md5 hashes\r
-*/\r
-\r
-#include <string.h>\r
-\r
-#include "lua.h"\r
-#include "lauxlib.h"\r
-#include <openssl/sha.h>\r
-#include <openssl/md5.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
-}\r
-\r
-#define MAKE_HASH_FUNCTION(myFunc, func, size) \\r
-static int myFunc(lua_State *L) { \\r
-       size_t len; \\r
-       const char *s = luaL_checklstring(L, 1, &len); \\r
-       int hex_out = lua_toboolean(L, 2); \\r
-       char hash[size]; \\r
-       char result[size*2]; \\r
-       func((const unsigned char*)s, len, (unsigned char*)hash);  \\r
-       if (hex_out) { \\r
-               toHex(hash, size, result); \\r
-               lua_pushlstring(L, result, size*2); \\r
-       } else { \\r
-               lua_pushlstring(L, hash, size);\\r
-       } \\r
-       return 1; \\r
-}\r
-\r
-MAKE_HASH_FUNCTION(Lsha1, SHA1, 20)\r
-MAKE_HASH_FUNCTION(Lsha256, SHA256, 32)\r
-MAKE_HASH_FUNCTION(Lmd5, MD5, 16)\r
-\r
-static const luaL_Reg Reg[] =\r
-{\r
-       { "sha1",       Lsha1   },\r
-       { "sha256",     Lsha256 },\r
-       { "md5",        Lmd5    },\r
-       { NULL,         NULL    }\r
-};\r
-\r
-LUALIB_API int luaopen_util_hashes(lua_State *L)\r
-{\r
-       luaL_register(L, "hashes", Reg);\r
-       lua_pushliteral(L, "version");                  /** version */\r
-       lua_pushliteral(L, "-3.14");\r
-       lua_settable(L,-3);\r
-       return 1;\r
-}\r
+LUALIB_API int luaopen_util_hashes(lua_State *L)
+{
+       luaL_register(L, "hashes", Reg);
+       lua_pushliteral(L, "version");                  /** version */
+       lua_pushliteral(L, "-3.14");
+       lua_settable(L,-3);
+       return 1;
+}
index 9d10ec7ef0d16762290599209bb0862b7427e75f..1257fa8c3ad332411213705621f5a9c1f83966e9 100644 (file)
@@ -1,24 +1,15 @@
-/* Prosody IM v0.1
--- Copyright (C) 2008 Matthew Wild
--- Copyright (C) 2008 Waqas Hussain
+/* Prosody IM v0.3
+-- Copyright (C) 2008-2009 Matthew Wild
+-- Copyright (C) 2008-2009 Waqas Hussain
 -- 
--- This program is free software; you can redistribute it and/or
--- modify it under the terms of the GNU General Public License
--- as published by the Free Software Foundation; either version 2
--- of the License, or (at your option) any later version.
--- 
--- This program is distributed in the hope that it will be useful,
--- but WITHOUT ANY WARRANTY; without even the implied warranty of
--- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
--- GNU General Public License for more details.
--- 
--- You should have received a copy of the GNU General Public License
--- along with this program; if not, write to the Free Software
--- Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+-- This project is MIT/X11 licensed. Please see the
+-- COPYING file in the source package for more information.
+--
 */
 
-/* pposix.c
-   POSIX support functions for Lua
+/*
+* pposix.c
+* POSIX support functions for Lua
 */
 
 #define MODULE_VERSION "0.3.0"