Annotate

util-src/encodings.c @ 3769:9338d0785277

util-src/Makefile, util-src/encodings.c{,pp}: Port ICU code to C, rename encodings.cpp back to .c and amend the Makefile accordingly
author Matthew Wild <mwild1@gmail.com>
date Fri, 17 Dec 2010 22:32:21 +0000
parent 3764:util-src/encodings.cpp@323169f229fa
child 3965:4ae4b2c0e99d
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
2923
b7049746bd29 Update copyright headers for 2010
Matthew Wild <mwild1@gmail.com>
parents: 2572
diff changeset
1 /* Prosody IM
b7049746bd29 Update copyright headers for 2010
Matthew Wild <mwild1@gmail.com>
parents: 2572
diff changeset
2 -- Copyright (C) 2008-2010 Matthew Wild
b7049746bd29 Update copyright headers for 2010
Matthew Wild <mwild1@gmail.com>
parents: 2572
diff changeset
3 -- Copyright (C) 2008-2010 Waqas Hussain
520
e96ac4bb6dd8 and the C files too
Matthew Wild <mwild1@gmail.com>
parents: 474
diff changeset
4 --
766
433a5226267f Licensing/version updates for some files (forgot to commit, doh...)
Matthew Wild <mwild1@gmail.com>
parents: 601
diff changeset
5 -- This project is MIT/X11 licensed. Please see the
433a5226267f Licensing/version updates for some files (forgot to commit, doh...)
Matthew Wild <mwild1@gmail.com>
parents: 601
diff changeset
6 -- COPYING file in the source package for more information.
433a5226267f Licensing/version updates for some files (forgot to commit, doh...)
Matthew Wild <mwild1@gmail.com>
parents: 601
diff changeset
7 --
433a5226267f Licensing/version updates for some files (forgot to commit, doh...)
Matthew Wild <mwild1@gmail.com>
parents: 601
diff changeset
8 */
433a5226267f Licensing/version updates for some files (forgot to commit, doh...)
Matthew Wild <mwild1@gmail.com>
parents: 601
diff changeset
9
433a5226267f Licensing/version updates for some files (forgot to commit, doh...)
Matthew Wild <mwild1@gmail.com>
parents: 601
diff changeset
10 /*
433a5226267f Licensing/version updates for some files (forgot to commit, doh...)
Matthew Wild <mwild1@gmail.com>
parents: 601
diff changeset
11 * encodings.c
433a5226267f Licensing/version updates for some files (forgot to commit, doh...)
Matthew Wild <mwild1@gmail.com>
parents: 601
diff changeset
12 * Lua library for base64, stringprep and idna encodings
520
e96ac4bb6dd8 and the C files too
Matthew Wild <mwild1@gmail.com>
parents: 474
diff changeset
13 */
e96ac4bb6dd8 and the C files too
Matthew Wild <mwild1@gmail.com>
parents: 474
diff changeset
14
766
433a5226267f Licensing/version updates for some files (forgot to commit, doh...)
Matthew Wild <mwild1@gmail.com>
parents: 601
diff changeset
15 // Newer MSVC compilers deprecate strcpy as unsafe, but we use it in a safe way
433a5226267f Licensing/version updates for some files (forgot to commit, doh...)
Matthew Wild <mwild1@gmail.com>
parents: 601
diff changeset
16 #define _CRT_SECURE_NO_DEPRECATE
520
e96ac4bb6dd8 and the C files too
Matthew Wild <mwild1@gmail.com>
parents: 474
diff changeset
17
766
433a5226267f Licensing/version updates for some files (forgot to commit, doh...)
Matthew Wild <mwild1@gmail.com>
parents: 601
diff changeset
18 #include <string.h>
433a5226267f Licensing/version updates for some files (forgot to commit, doh...)
Matthew Wild <mwild1@gmail.com>
parents: 601
diff changeset
19 #include <stdlib.h>
433a5226267f Licensing/version updates for some files (forgot to commit, doh...)
Matthew Wild <mwild1@gmail.com>
parents: 601
diff changeset
20 #include "lua.h"
433a5226267f Licensing/version updates for some files (forgot to commit, doh...)
Matthew Wild <mwild1@gmail.com>
parents: 601
diff changeset
21 #include "lauxlib.h"
3769
9338d0785277 util-src/Makefile, util-src/encodings.c{,pp}: Port ICU code to C, rename encodings.cpp back to .c and amend the Makefile accordingly
Matthew Wild <mwild1@gmail.com>
parents: 3764
diff changeset
22
3762
f02bac902a1e util.encodings: Support for ICU for IDNA operations.
Tobias Markmann <tm@ayena.de>
parents: 2923
diff changeset
23 /***************** BASE64 *****************/
766
433a5226267f Licensing/version updates for some files (forgot to commit, doh...)
Matthew Wild <mwild1@gmail.com>
parents: 601
diff changeset
24
433a5226267f Licensing/version updates for some files (forgot to commit, doh...)
Matthew Wild <mwild1@gmail.com>
parents: 601
diff changeset
25 static const char code[]=
433a5226267f Licensing/version updates for some files (forgot to commit, doh...)
Matthew Wild <mwild1@gmail.com>
parents: 601
diff changeset
26 "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
433a5226267f Licensing/version updates for some files (forgot to commit, doh...)
Matthew Wild <mwild1@gmail.com>
parents: 601
diff changeset
27
433a5226267f Licensing/version updates for some files (forgot to commit, doh...)
Matthew Wild <mwild1@gmail.com>
parents: 601
diff changeset
28 static void base64_encode(luaL_Buffer *b, unsigned int c1, unsigned int c2, unsigned int c3, int n)
433a5226267f Licensing/version updates for some files (forgot to commit, doh...)
Matthew Wild <mwild1@gmail.com>
parents: 601
diff changeset
29 {
433a5226267f Licensing/version updates for some files (forgot to commit, doh...)
Matthew Wild <mwild1@gmail.com>
parents: 601
diff changeset
30 unsigned long tuple=c3+256UL*(c2+256UL*c1);
433a5226267f Licensing/version updates for some files (forgot to commit, doh...)
Matthew Wild <mwild1@gmail.com>
parents: 601
diff changeset
31 int i;
433a5226267f Licensing/version updates for some files (forgot to commit, doh...)
Matthew Wild <mwild1@gmail.com>
parents: 601
diff changeset
32 char s[4];
433a5226267f Licensing/version updates for some files (forgot to commit, doh...)
Matthew Wild <mwild1@gmail.com>
parents: 601
diff changeset
33 for (i=0; i<4; i++) {
433a5226267f Licensing/version updates for some files (forgot to commit, doh...)
Matthew Wild <mwild1@gmail.com>
parents: 601
diff changeset
34 s[3-i] = code[tuple % 64];
433a5226267f Licensing/version updates for some files (forgot to commit, doh...)
Matthew Wild <mwild1@gmail.com>
parents: 601
diff changeset
35 tuple /= 64;
433a5226267f Licensing/version updates for some files (forgot to commit, doh...)
Matthew Wild <mwild1@gmail.com>
parents: 601
diff changeset
36 }
433a5226267f Licensing/version updates for some files (forgot to commit, doh...)
Matthew Wild <mwild1@gmail.com>
parents: 601
diff changeset
37 for (i=n+1; i<4; i++) s[i]='=';
433a5226267f Licensing/version updates for some files (forgot to commit, doh...)
Matthew Wild <mwild1@gmail.com>
parents: 601
diff changeset
38 luaL_addlstring(b,s,4);
433a5226267f Licensing/version updates for some files (forgot to commit, doh...)
Matthew Wild <mwild1@gmail.com>
parents: 601
diff changeset
39 }
433a5226267f Licensing/version updates for some files (forgot to commit, doh...)
Matthew Wild <mwild1@gmail.com>
parents: 601
diff changeset
40
433a5226267f Licensing/version updates for some files (forgot to commit, doh...)
Matthew Wild <mwild1@gmail.com>
parents: 601
diff changeset
41 static int Lbase64_encode(lua_State *L) /** encode(s) */
433a5226267f Licensing/version updates for some files (forgot to commit, doh...)
Matthew Wild <mwild1@gmail.com>
parents: 601
diff changeset
42 {
433a5226267f Licensing/version updates for some files (forgot to commit, doh...)
Matthew Wild <mwild1@gmail.com>
parents: 601
diff changeset
43 size_t l;
433a5226267f Licensing/version updates for some files (forgot to commit, doh...)
Matthew Wild <mwild1@gmail.com>
parents: 601
diff changeset
44 const unsigned char *s=(const unsigned char*)luaL_checklstring(L,1,&l);
433a5226267f Licensing/version updates for some files (forgot to commit, doh...)
Matthew Wild <mwild1@gmail.com>
parents: 601
diff changeset
45 luaL_Buffer b;
433a5226267f Licensing/version updates for some files (forgot to commit, doh...)
Matthew Wild <mwild1@gmail.com>
parents: 601
diff changeset
46 int n;
433a5226267f Licensing/version updates for some files (forgot to commit, doh...)
Matthew Wild <mwild1@gmail.com>
parents: 601
diff changeset
47 luaL_buffinit(L,&b);
433a5226267f Licensing/version updates for some files (forgot to commit, doh...)
Matthew Wild <mwild1@gmail.com>
parents: 601
diff changeset
48 for (n=l/3; n--; s+=3) base64_encode(&b,s[0],s[1],s[2],3);
433a5226267f Licensing/version updates for some files (forgot to commit, doh...)
Matthew Wild <mwild1@gmail.com>
parents: 601
diff changeset
49 switch (l%3)
433a5226267f Licensing/version updates for some files (forgot to commit, doh...)
Matthew Wild <mwild1@gmail.com>
parents: 601
diff changeset
50 {
433a5226267f Licensing/version updates for some files (forgot to commit, doh...)
Matthew Wild <mwild1@gmail.com>
parents: 601
diff changeset
51 case 1: base64_encode(&b,s[0],0,0,1); break;
433a5226267f Licensing/version updates for some files (forgot to commit, doh...)
Matthew Wild <mwild1@gmail.com>
parents: 601
diff changeset
52 case 2: base64_encode(&b,s[0],s[1],0,2); break;
433a5226267f Licensing/version updates for some files (forgot to commit, doh...)
Matthew Wild <mwild1@gmail.com>
parents: 601
diff changeset
53 }
433a5226267f Licensing/version updates for some files (forgot to commit, doh...)
Matthew Wild <mwild1@gmail.com>
parents: 601
diff changeset
54 luaL_pushresult(&b);
433a5226267f Licensing/version updates for some files (forgot to commit, doh...)
Matthew Wild <mwild1@gmail.com>
parents: 601
diff changeset
55 return 1;
433a5226267f Licensing/version updates for some files (forgot to commit, doh...)
Matthew Wild <mwild1@gmail.com>
parents: 601
diff changeset
56 }
433a5226267f Licensing/version updates for some files (forgot to commit, doh...)
Matthew Wild <mwild1@gmail.com>
parents: 601
diff changeset
57
433a5226267f Licensing/version updates for some files (forgot to commit, doh...)
Matthew Wild <mwild1@gmail.com>
parents: 601
diff changeset
58 static void base64_decode(luaL_Buffer *b, int c1, int c2, int c3, int c4, int n)
433a5226267f Licensing/version updates for some files (forgot to commit, doh...)
Matthew Wild <mwild1@gmail.com>
parents: 601
diff changeset
59 {
433a5226267f Licensing/version updates for some files (forgot to commit, doh...)
Matthew Wild <mwild1@gmail.com>
parents: 601
diff changeset
60 unsigned long tuple=c4+64L*(c3+64L*(c2+64L*c1));
433a5226267f Licensing/version updates for some files (forgot to commit, doh...)
Matthew Wild <mwild1@gmail.com>
parents: 601
diff changeset
61 char s[3];
433a5226267f Licensing/version updates for some files (forgot to commit, doh...)
Matthew Wild <mwild1@gmail.com>
parents: 601
diff changeset
62 switch (--n)
433a5226267f Licensing/version updates for some files (forgot to commit, doh...)
Matthew Wild <mwild1@gmail.com>
parents: 601
diff changeset
63 {
433a5226267f Licensing/version updates for some files (forgot to commit, doh...)
Matthew Wild <mwild1@gmail.com>
parents: 601
diff changeset
64 case 3: s[2]=(char) tuple;
433a5226267f Licensing/version updates for some files (forgot to commit, doh...)
Matthew Wild <mwild1@gmail.com>
parents: 601
diff changeset
65 case 2: s[1]=(char) (tuple >> 8);
433a5226267f Licensing/version updates for some files (forgot to commit, doh...)
Matthew Wild <mwild1@gmail.com>
parents: 601
diff changeset
66 case 1: s[0]=(char) (tuple >> 16);
433a5226267f Licensing/version updates for some files (forgot to commit, doh...)
Matthew Wild <mwild1@gmail.com>
parents: 601
diff changeset
67 }
433a5226267f Licensing/version updates for some files (forgot to commit, doh...)
Matthew Wild <mwild1@gmail.com>
parents: 601
diff changeset
68 luaL_addlstring(b,s,n);
433a5226267f Licensing/version updates for some files (forgot to commit, doh...)
Matthew Wild <mwild1@gmail.com>
parents: 601
diff changeset
69 }
433a5226267f Licensing/version updates for some files (forgot to commit, doh...)
Matthew Wild <mwild1@gmail.com>
parents: 601
diff changeset
70
433a5226267f Licensing/version updates for some files (forgot to commit, doh...)
Matthew Wild <mwild1@gmail.com>
parents: 601
diff changeset
71 static int Lbase64_decode(lua_State *L) /** decode(s) */
433a5226267f Licensing/version updates for some files (forgot to commit, doh...)
Matthew Wild <mwild1@gmail.com>
parents: 601
diff changeset
72 {
433a5226267f Licensing/version updates for some files (forgot to commit, doh...)
Matthew Wild <mwild1@gmail.com>
parents: 601
diff changeset
73 size_t l;
433a5226267f Licensing/version updates for some files (forgot to commit, doh...)
Matthew Wild <mwild1@gmail.com>
parents: 601
diff changeset
74 const char *s=luaL_checklstring(L,1,&l);
433a5226267f Licensing/version updates for some files (forgot to commit, doh...)
Matthew Wild <mwild1@gmail.com>
parents: 601
diff changeset
75 luaL_Buffer b;
433a5226267f Licensing/version updates for some files (forgot to commit, doh...)
Matthew Wild <mwild1@gmail.com>
parents: 601
diff changeset
76 int n=0;
433a5226267f Licensing/version updates for some files (forgot to commit, doh...)
Matthew Wild <mwild1@gmail.com>
parents: 601
diff changeset
77 char t[4];
433a5226267f Licensing/version updates for some files (forgot to commit, doh...)
Matthew Wild <mwild1@gmail.com>
parents: 601
diff changeset
78 luaL_buffinit(L,&b);
433a5226267f Licensing/version updates for some files (forgot to commit, doh...)
Matthew Wild <mwild1@gmail.com>
parents: 601
diff changeset
79 for (;;)
433a5226267f Licensing/version updates for some files (forgot to commit, doh...)
Matthew Wild <mwild1@gmail.com>
parents: 601
diff changeset
80 {
601
6cb908ef01c8 Fixed util.encodings.base64.decode to not truncate results when encountering an '=' before the end of the given input.
Waqas Hussain <waqas20@gmail.com>
parents: 520
diff changeset
81 int c=*s++;
766
433a5226267f Licensing/version updates for some files (forgot to commit, doh...)
Matthew Wild <mwild1@gmail.com>
parents: 601
diff changeset
82 switch (c)
433a5226267f Licensing/version updates for some files (forgot to commit, doh...)
Matthew Wild <mwild1@gmail.com>
parents: 601
diff changeset
83 {
433a5226267f Licensing/version updates for some files (forgot to commit, doh...)
Matthew Wild <mwild1@gmail.com>
parents: 601
diff changeset
84 const char *p;
433a5226267f Licensing/version updates for some files (forgot to commit, doh...)
Matthew Wild <mwild1@gmail.com>
parents: 601
diff changeset
85 default:
433a5226267f Licensing/version updates for some files (forgot to commit, doh...)
Matthew Wild <mwild1@gmail.com>
parents: 601
diff changeset
86 p=strchr(code,c); if (p==NULL) return 0;
433a5226267f Licensing/version updates for some files (forgot to commit, doh...)
Matthew Wild <mwild1@gmail.com>
parents: 601
diff changeset
87 t[n++]= (char) (p-code);
433a5226267f Licensing/version updates for some files (forgot to commit, doh...)
Matthew Wild <mwild1@gmail.com>
parents: 601
diff changeset
88 if (n==4)
433a5226267f Licensing/version updates for some files (forgot to commit, doh...)
Matthew Wild <mwild1@gmail.com>
parents: 601
diff changeset
89 {
433a5226267f Licensing/version updates for some files (forgot to commit, doh...)
Matthew Wild <mwild1@gmail.com>
parents: 601
diff changeset
90 base64_decode(&b,t[0],t[1],t[2],t[3],4);
433a5226267f Licensing/version updates for some files (forgot to commit, doh...)
Matthew Wild <mwild1@gmail.com>
parents: 601
diff changeset
91 n=0;
433a5226267f Licensing/version updates for some files (forgot to commit, doh...)
Matthew Wild <mwild1@gmail.com>
parents: 601
diff changeset
92 }
433a5226267f Licensing/version updates for some files (forgot to commit, doh...)
Matthew Wild <mwild1@gmail.com>
parents: 601
diff changeset
93 break;
433a5226267f Licensing/version updates for some files (forgot to commit, doh...)
Matthew Wild <mwild1@gmail.com>
parents: 601
diff changeset
94 case '=':
433a5226267f Licensing/version updates for some files (forgot to commit, doh...)
Matthew Wild <mwild1@gmail.com>
parents: 601
diff changeset
95 switch (n)
433a5226267f Licensing/version updates for some files (forgot to commit, doh...)
Matthew Wild <mwild1@gmail.com>
parents: 601
diff changeset
96 {
433a5226267f Licensing/version updates for some files (forgot to commit, doh...)
Matthew Wild <mwild1@gmail.com>
parents: 601
diff changeset
97 case 1: base64_decode(&b,t[0],0,0,0,1); break;
433a5226267f Licensing/version updates for some files (forgot to commit, doh...)
Matthew Wild <mwild1@gmail.com>
parents: 601
diff changeset
98 case 2: base64_decode(&b,t[0],t[1],0,0,2); break;
601
6cb908ef01c8 Fixed util.encodings.base64.decode to not truncate results when encountering an '=' before the end of the given input.
Waqas Hussain <waqas20@gmail.com>
parents: 520
diff changeset
99 case 3: base64_decode(&b,t[0],t[1],t[2],0,3); break;
6cb908ef01c8 Fixed util.encodings.base64.decode to not truncate results when encountering an '=' before the end of the given input.
Waqas Hussain <waqas20@gmail.com>
parents: 520
diff changeset
100 }
6cb908ef01c8 Fixed util.encodings.base64.decode to not truncate results when encountering an '=' before the end of the given input.
Waqas Hussain <waqas20@gmail.com>
parents: 520
diff changeset
101 n=0;
766
433a5226267f Licensing/version updates for some files (forgot to commit, doh...)
Matthew Wild <mwild1@gmail.com>
parents: 601
diff changeset
102 break;
433a5226267f Licensing/version updates for some files (forgot to commit, doh...)
Matthew Wild <mwild1@gmail.com>
parents: 601
diff changeset
103 case 0:
433a5226267f Licensing/version updates for some files (forgot to commit, doh...)
Matthew Wild <mwild1@gmail.com>
parents: 601
diff changeset
104 luaL_pushresult(&b);
433a5226267f Licensing/version updates for some files (forgot to commit, doh...)
Matthew Wild <mwild1@gmail.com>
parents: 601
diff changeset
105 return 1;
433a5226267f Licensing/version updates for some files (forgot to commit, doh...)
Matthew Wild <mwild1@gmail.com>
parents: 601
diff changeset
106 case '\n': case '\r': case '\t': case ' ': case '\f': case '\b':
433a5226267f Licensing/version updates for some files (forgot to commit, doh...)
Matthew Wild <mwild1@gmail.com>
parents: 601
diff changeset
107 break;
433a5226267f Licensing/version updates for some files (forgot to commit, doh...)
Matthew Wild <mwild1@gmail.com>
parents: 601
diff changeset
108 }
433a5226267f Licensing/version updates for some files (forgot to commit, doh...)
Matthew Wild <mwild1@gmail.com>
parents: 601
diff changeset
109 }
433a5226267f Licensing/version updates for some files (forgot to commit, doh...)
Matthew Wild <mwild1@gmail.com>
parents: 601
diff changeset
110 }
433a5226267f Licensing/version updates for some files (forgot to commit, doh...)
Matthew Wild <mwild1@gmail.com>
parents: 601
diff changeset
111
433a5226267f Licensing/version updates for some files (forgot to commit, doh...)
Matthew Wild <mwild1@gmail.com>
parents: 601
diff changeset
112 static const luaL_Reg Reg_base64[] =
433a5226267f Licensing/version updates for some files (forgot to commit, doh...)
Matthew Wild <mwild1@gmail.com>
parents: 601
diff changeset
113 {
433a5226267f Licensing/version updates for some files (forgot to commit, doh...)
Matthew Wild <mwild1@gmail.com>
parents: 601
diff changeset
114 { "encode", Lbase64_encode },
433a5226267f Licensing/version updates for some files (forgot to commit, doh...)
Matthew Wild <mwild1@gmail.com>
parents: 601
diff changeset
115 { "decode", Lbase64_decode },
433a5226267f Licensing/version updates for some files (forgot to commit, doh...)
Matthew Wild <mwild1@gmail.com>
parents: 601
diff changeset
116 { NULL, NULL }
433a5226267f Licensing/version updates for some files (forgot to commit, doh...)
Matthew Wild <mwild1@gmail.com>
parents: 601
diff changeset
117 };
433a5226267f Licensing/version updates for some files (forgot to commit, doh...)
Matthew Wild <mwild1@gmail.com>
parents: 601
diff changeset
118
433a5226267f Licensing/version updates for some files (forgot to commit, doh...)
Matthew Wild <mwild1@gmail.com>
parents: 601
diff changeset
119 /***************** STRINGPREP *****************/
3762
f02bac902a1e util.encodings: Support for ICU for IDNA operations.
Tobias Markmann <tm@ayena.de>
parents: 2923
diff changeset
120 #ifndef USE_STRINGPREP_ICU
f02bac902a1e util.encodings: Support for ICU for IDNA operations.
Tobias Markmann <tm@ayena.de>
parents: 2923
diff changeset
121 /****************** libidn ********************/
3769
9338d0785277 util-src/Makefile, util-src/encodings.c{,pp}: Port ICU code to C, rename encodings.cpp back to .c and amend the Makefile accordingly
Matthew Wild <mwild1@gmail.com>
parents: 3764
diff changeset
122
766
433a5226267f Licensing/version updates for some files (forgot to commit, doh...)
Matthew Wild <mwild1@gmail.com>
parents: 601
diff changeset
123 #include <stringprep.h>
3769
9338d0785277 util-src/Makefile, util-src/encodings.c{,pp}: Port ICU code to C, rename encodings.cpp back to .c and amend the Makefile accordingly
Matthew Wild <mwild1@gmail.com>
parents: 3764
diff changeset
124
766
433a5226267f Licensing/version updates for some files (forgot to commit, doh...)
Matthew Wild <mwild1@gmail.com>
parents: 601
diff changeset
125 static int stringprep_prep(lua_State *L, const Stringprep_profile *profile)
433a5226267f Licensing/version updates for some files (forgot to commit, doh...)
Matthew Wild <mwild1@gmail.com>
parents: 601
diff changeset
126 {
433a5226267f Licensing/version updates for some files (forgot to commit, doh...)
Matthew Wild <mwild1@gmail.com>
parents: 601
diff changeset
127 size_t len;
1854
7e055cc6bc90 util.encodings: Fixed: Last change was not ANSI C compatible.
Waqas Hussain <waqas20@gmail.com>
parents: 1829
diff changeset
128 const char *s;
766
433a5226267f Licensing/version updates for some files (forgot to commit, doh...)
Matthew Wild <mwild1@gmail.com>
parents: 601
diff changeset
129 char string[1024];
433a5226267f Licensing/version updates for some files (forgot to commit, doh...)
Matthew Wild <mwild1@gmail.com>
parents: 601
diff changeset
130 int ret;
1844
a4a8fe2a560c util.encodings: Don't throw an error but return nil when passed nil or a non-string value
Matthew Wild <mwild1@gmail.com>
parents: 1829
diff changeset
131 if(!lua_isstring(L, 1)) {
a4a8fe2a560c util.encodings: Don't throw an error but return nil when passed nil or a non-string value
Matthew Wild <mwild1@gmail.com>
parents: 1829
diff changeset
132 lua_pushnil(L);
a4a8fe2a560c util.encodings: Don't throw an error but return nil when passed nil or a non-string value
Matthew Wild <mwild1@gmail.com>
parents: 1829
diff changeset
133 return 1;
a4a8fe2a560c util.encodings: Don't throw an error but return nil when passed nil or a non-string value
Matthew Wild <mwild1@gmail.com>
parents: 1829
diff changeset
134 }
1854
7e055cc6bc90 util.encodings: Fixed: Last change was not ANSI C compatible.
Waqas Hussain <waqas20@gmail.com>
parents: 1829
diff changeset
135 s = lua_tolstring(L, 1, &len);
766
433a5226267f Licensing/version updates for some files (forgot to commit, doh...)
Matthew Wild <mwild1@gmail.com>
parents: 601
diff changeset
136 if (len >= 1024) {
433a5226267f Licensing/version updates for some files (forgot to commit, doh...)
Matthew Wild <mwild1@gmail.com>
parents: 601
diff changeset
137 lua_pushnil(L);
433a5226267f Licensing/version updates for some files (forgot to commit, doh...)
Matthew Wild <mwild1@gmail.com>
parents: 601
diff changeset
138 return 1; // TODO return error message
433a5226267f Licensing/version updates for some files (forgot to commit, doh...)
Matthew Wild <mwild1@gmail.com>
parents: 601
diff changeset
139 }
433a5226267f Licensing/version updates for some files (forgot to commit, doh...)
Matthew Wild <mwild1@gmail.com>
parents: 601
diff changeset
140 strcpy(string, s);
3764
323169f229fa Make libidn default when not specifiying a IDN lib.
Tobias Markmann <tm@ayena.de>
parents: 3762
diff changeset
141 ret = stringprep(string, 1024, (Stringprep_profile_flags)0, profile);
766
433a5226267f Licensing/version updates for some files (forgot to commit, doh...)
Matthew Wild <mwild1@gmail.com>
parents: 601
diff changeset
142 if (ret == STRINGPREP_OK) {
433a5226267f Licensing/version updates for some files (forgot to commit, doh...)
Matthew Wild <mwild1@gmail.com>
parents: 601
diff changeset
143 lua_pushstring(L, string);
433a5226267f Licensing/version updates for some files (forgot to commit, doh...)
Matthew Wild <mwild1@gmail.com>
parents: 601
diff changeset
144 return 1;
433a5226267f Licensing/version updates for some files (forgot to commit, doh...)
Matthew Wild <mwild1@gmail.com>
parents: 601
diff changeset
145 } else {
433a5226267f Licensing/version updates for some files (forgot to commit, doh...)
Matthew Wild <mwild1@gmail.com>
parents: 601
diff changeset
146 lua_pushnil(L);
433a5226267f Licensing/version updates for some files (forgot to commit, doh...)
Matthew Wild <mwild1@gmail.com>
parents: 601
diff changeset
147 return 1; // TODO return error message
433a5226267f Licensing/version updates for some files (forgot to commit, doh...)
Matthew Wild <mwild1@gmail.com>
parents: 601
diff changeset
148 }
433a5226267f Licensing/version updates for some files (forgot to commit, doh...)
Matthew Wild <mwild1@gmail.com>
parents: 601
diff changeset
149 }
433a5226267f Licensing/version updates for some files (forgot to commit, doh...)
Matthew Wild <mwild1@gmail.com>
parents: 601
diff changeset
150
433a5226267f Licensing/version updates for some files (forgot to commit, doh...)
Matthew Wild <mwild1@gmail.com>
parents: 601
diff changeset
151 #define MAKE_PREP_FUNC(myFunc, prep) \
433a5226267f Licensing/version updates for some files (forgot to commit, doh...)
Matthew Wild <mwild1@gmail.com>
parents: 601
diff changeset
152 static int myFunc(lua_State *L) { return stringprep_prep(L, prep); }
433a5226267f Licensing/version updates for some files (forgot to commit, doh...)
Matthew Wild <mwild1@gmail.com>
parents: 601
diff changeset
153
433a5226267f Licensing/version updates for some files (forgot to commit, doh...)
Matthew Wild <mwild1@gmail.com>
parents: 601
diff changeset
154 MAKE_PREP_FUNC(Lstringprep_nameprep, stringprep_nameprep) /** stringprep.nameprep(s) */
433a5226267f Licensing/version updates for some files (forgot to commit, doh...)
Matthew Wild <mwild1@gmail.com>
parents: 601
diff changeset
155 MAKE_PREP_FUNC(Lstringprep_nodeprep, stringprep_xmpp_nodeprep) /** stringprep.nodeprep(s) */
433a5226267f Licensing/version updates for some files (forgot to commit, doh...)
Matthew Wild <mwild1@gmail.com>
parents: 601
diff changeset
156 MAKE_PREP_FUNC(Lstringprep_resourceprep, stringprep_xmpp_resourceprep) /** stringprep.resourceprep(s) */
433a5226267f Licensing/version updates for some files (forgot to commit, doh...)
Matthew Wild <mwild1@gmail.com>
parents: 601
diff changeset
157 MAKE_PREP_FUNC(Lstringprep_saslprep, stringprep_saslprep) /** stringprep.saslprep(s) */
433a5226267f Licensing/version updates for some files (forgot to commit, doh...)
Matthew Wild <mwild1@gmail.com>
parents: 601
diff changeset
158
433a5226267f Licensing/version updates for some files (forgot to commit, doh...)
Matthew Wild <mwild1@gmail.com>
parents: 601
diff changeset
159 static const luaL_Reg Reg_stringprep[] =
433a5226267f Licensing/version updates for some files (forgot to commit, doh...)
Matthew Wild <mwild1@gmail.com>
parents: 601
diff changeset
160 {
433a5226267f Licensing/version updates for some files (forgot to commit, doh...)
Matthew Wild <mwild1@gmail.com>
parents: 601
diff changeset
161 { "nameprep", Lstringprep_nameprep },
433a5226267f Licensing/version updates for some files (forgot to commit, doh...)
Matthew Wild <mwild1@gmail.com>
parents: 601
diff changeset
162 { "nodeprep", Lstringprep_nodeprep },
433a5226267f Licensing/version updates for some files (forgot to commit, doh...)
Matthew Wild <mwild1@gmail.com>
parents: 601
diff changeset
163 { "resourceprep", Lstringprep_resourceprep },
433a5226267f Licensing/version updates for some files (forgot to commit, doh...)
Matthew Wild <mwild1@gmail.com>
parents: 601
diff changeset
164 { "saslprep", Lstringprep_saslprep },
433a5226267f Licensing/version updates for some files (forgot to commit, doh...)
Matthew Wild <mwild1@gmail.com>
parents: 601
diff changeset
165 { NULL, NULL }
433a5226267f Licensing/version updates for some files (forgot to commit, doh...)
Matthew Wild <mwild1@gmail.com>
parents: 601
diff changeset
166 };
433a5226267f Licensing/version updates for some files (forgot to commit, doh...)
Matthew Wild <mwild1@gmail.com>
parents: 601
diff changeset
167
3762
f02bac902a1e util.encodings: Support for ICU for IDNA operations.
Tobias Markmann <tm@ayena.de>
parents: 2923
diff changeset
168 #else
f02bac902a1e util.encodings: Support for ICU for IDNA operations.
Tobias Markmann <tm@ayena.de>
parents: 2923
diff changeset
169 #include <unicode/usprep.h>
3769
9338d0785277 util-src/Makefile, util-src/encodings.c{,pp}: Port ICU code to C, rename encodings.cpp back to .c and amend the Makefile accordingly
Matthew Wild <mwild1@gmail.com>
parents: 3764
diff changeset
170 #include <unicode/ustring.h>
3762
f02bac902a1e util.encodings: Support for ICU for IDNA operations.
Tobias Markmann <tm@ayena.de>
parents: 2923
diff changeset
171 #include <unicode/utrace.h>
f02bac902a1e util.encodings: Support for ICU for IDNA operations.
Tobias Markmann <tm@ayena.de>
parents: 2923
diff changeset
172
f02bac902a1e util.encodings: Support for ICU for IDNA operations.
Tobias Markmann <tm@ayena.de>
parents: 2923
diff changeset
173 static int icu_stringprep_prep(lua_State *L, const UStringPrepProfile *profile)
f02bac902a1e util.encodings: Support for ICU for IDNA operations.
Tobias Markmann <tm@ayena.de>
parents: 2923
diff changeset
174 {
3769
9338d0785277 util-src/Makefile, util-src/encodings.c{,pp}: Port ICU code to C, rename encodings.cpp back to .c and amend the Makefile accordingly
Matthew Wild <mwild1@gmail.com>
parents: 3764
diff changeset
175 size_t input_len;
9338d0785277 util-src/Makefile, util-src/encodings.c{,pp}: Port ICU code to C, rename encodings.cpp back to .c and amend the Makefile accordingly
Matthew Wild <mwild1@gmail.com>
parents: 3764
diff changeset
176 int32_t unprepped_len, prepped_len, output_len;
9338d0785277 util-src/Makefile, util-src/encodings.c{,pp}: Port ICU code to C, rename encodings.cpp back to .c and amend the Makefile accordingly
Matthew Wild <mwild1@gmail.com>
parents: 3764
diff changeset
177 const char *input;
9338d0785277 util-src/Makefile, util-src/encodings.c{,pp}: Port ICU code to C, rename encodings.cpp back to .c and amend the Makefile accordingly
Matthew Wild <mwild1@gmail.com>
parents: 3764
diff changeset
178 char output[1024];
9338d0785277 util-src/Makefile, util-src/encodings.c{,pp}: Port ICU code to C, rename encodings.cpp back to .c and amend the Makefile accordingly
Matthew Wild <mwild1@gmail.com>
parents: 3764
diff changeset
179
9338d0785277 util-src/Makefile, util-src/encodings.c{,pp}: Port ICU code to C, rename encodings.cpp back to .c and amend the Makefile accordingly
Matthew Wild <mwild1@gmail.com>
parents: 3764
diff changeset
180 UChar unprepped[1024]; /* Temporary unicode buffer (1024 characters) */
9338d0785277 util-src/Makefile, util-src/encodings.c{,pp}: Port ICU code to C, rename encodings.cpp back to .c and amend the Makefile accordingly
Matthew Wild <mwild1@gmail.com>
parents: 3764
diff changeset
181 UChar prepped[1024];
9338d0785277 util-src/Makefile, util-src/encodings.c{,pp}: Port ICU code to C, rename encodings.cpp back to .c and amend the Makefile accordingly
Matthew Wild <mwild1@gmail.com>
parents: 3764
diff changeset
182
3762
f02bac902a1e util.encodings: Support for ICU for IDNA operations.
Tobias Markmann <tm@ayena.de>
parents: 2923
diff changeset
183 UErrorCode err = U_ZERO_ERROR;
3769
9338d0785277 util-src/Makefile, util-src/encodings.c{,pp}: Port ICU code to C, rename encodings.cpp back to .c and amend the Makefile accordingly
Matthew Wild <mwild1@gmail.com>
parents: 3764
diff changeset
184
3762
f02bac902a1e util.encodings: Support for ICU for IDNA operations.
Tobias Markmann <tm@ayena.de>
parents: 2923
diff changeset
185 if(!lua_isstring(L, 1)) {
f02bac902a1e util.encodings: Support for ICU for IDNA operations.
Tobias Markmann <tm@ayena.de>
parents: 2923
diff changeset
186 lua_pushnil(L);
f02bac902a1e util.encodings: Support for ICU for IDNA operations.
Tobias Markmann <tm@ayena.de>
parents: 2923
diff changeset
187 return 1;
f02bac902a1e util.encodings: Support for ICU for IDNA operations.
Tobias Markmann <tm@ayena.de>
parents: 2923
diff changeset
188 }
3769
9338d0785277 util-src/Makefile, util-src/encodings.c{,pp}: Port ICU code to C, rename encodings.cpp back to .c and amend the Makefile accordingly
Matthew Wild <mwild1@gmail.com>
parents: 3764
diff changeset
189 input = lua_tolstring(L, 1, &input_len);
9338d0785277 util-src/Makefile, util-src/encodings.c{,pp}: Port ICU code to C, rename encodings.cpp back to .c and amend the Makefile accordingly
Matthew Wild <mwild1@gmail.com>
parents: 3764
diff changeset
190 if (input_len >= 1024) {
3762
f02bac902a1e util.encodings: Support for ICU for IDNA operations.
Tobias Markmann <tm@ayena.de>
parents: 2923
diff changeset
191 lua_pushnil(L);
3769
9338d0785277 util-src/Makefile, util-src/encodings.c{,pp}: Port ICU code to C, rename encodings.cpp back to .c and amend the Makefile accordingly
Matthew Wild <mwild1@gmail.com>
parents: 3764
diff changeset
192 return 1;
3762
f02bac902a1e util.encodings: Support for ICU for IDNA operations.
Tobias Markmann <tm@ayena.de>
parents: 2923
diff changeset
193 }
3769
9338d0785277 util-src/Makefile, util-src/encodings.c{,pp}: Port ICU code to C, rename encodings.cpp back to .c and amend the Makefile accordingly
Matthew Wild <mwild1@gmail.com>
parents: 3764
diff changeset
194 u_strFromUTF8(unprepped, 1024, &unprepped_len, input, input_len, &err);
9338d0785277 util-src/Makefile, util-src/encodings.c{,pp}: Port ICU code to C, rename encodings.cpp back to .c and amend the Makefile accordingly
Matthew Wild <mwild1@gmail.com>
parents: 3764
diff changeset
195 prepped_len = usprep_prepare(profile, unprepped, unprepped_len, prepped, 1024, 0, NULL, &err);
3762
f02bac902a1e util.encodings: Support for ICU for IDNA operations.
Tobias Markmann <tm@ayena.de>
parents: 2923
diff changeset
196 if (U_FAILURE(err)) {
f02bac902a1e util.encodings: Support for ICU for IDNA operations.
Tobias Markmann <tm@ayena.de>
parents: 2923
diff changeset
197 lua_pushnil(L);
f02bac902a1e util.encodings: Support for ICU for IDNA operations.
Tobias Markmann <tm@ayena.de>
parents: 2923
diff changeset
198 return 1;
f02bac902a1e util.encodings: Support for ICU for IDNA operations.
Tobias Markmann <tm@ayena.de>
parents: 2923
diff changeset
199 } else {
3769
9338d0785277 util-src/Makefile, util-src/encodings.c{,pp}: Port ICU code to C, rename encodings.cpp back to .c and amend the Makefile accordingly
Matthew Wild <mwild1@gmail.com>
parents: 3764
diff changeset
200 u_strToUTF8(output, 1024, &output_len, prepped, prepped_len, &err);
9338d0785277 util-src/Makefile, util-src/encodings.c{,pp}: Port ICU code to C, rename encodings.cpp back to .c and amend the Makefile accordingly
Matthew Wild <mwild1@gmail.com>
parents: 3764
diff changeset
201 if(output_len < 1024)
9338d0785277 util-src/Makefile, util-src/encodings.c{,pp}: Port ICU code to C, rename encodings.cpp back to .c and amend the Makefile accordingly
Matthew Wild <mwild1@gmail.com>
parents: 3764
diff changeset
202 lua_pushlstring(L, output, output_len);
9338d0785277 util-src/Makefile, util-src/encodings.c{,pp}: Port ICU code to C, rename encodings.cpp back to .c and amend the Makefile accordingly
Matthew Wild <mwild1@gmail.com>
parents: 3764
diff changeset
203 else
9338d0785277 util-src/Makefile, util-src/encodings.c{,pp}: Port ICU code to C, rename encodings.cpp back to .c and amend the Makefile accordingly
Matthew Wild <mwild1@gmail.com>
parents: 3764
diff changeset
204 lua_pushnil(L);
3762
f02bac902a1e util.encodings: Support for ICU for IDNA operations.
Tobias Markmann <tm@ayena.de>
parents: 2923
diff changeset
205 return 1;
f02bac902a1e util.encodings: Support for ICU for IDNA operations.
Tobias Markmann <tm@ayena.de>
parents: 2923
diff changeset
206 }
f02bac902a1e util.encodings: Support for ICU for IDNA operations.
Tobias Markmann <tm@ayena.de>
parents: 2923
diff changeset
207 }
f02bac902a1e util.encodings: Support for ICU for IDNA operations.
Tobias Markmann <tm@ayena.de>
parents: 2923
diff changeset
208
f02bac902a1e util.encodings: Support for ICU for IDNA operations.
Tobias Markmann <tm@ayena.de>
parents: 2923
diff changeset
209 UStringPrepProfile *icu_nameprep;
f02bac902a1e util.encodings: Support for ICU for IDNA operations.
Tobias Markmann <tm@ayena.de>
parents: 2923
diff changeset
210 UStringPrepProfile *icu_nodeprep;
f02bac902a1e util.encodings: Support for ICU for IDNA operations.
Tobias Markmann <tm@ayena.de>
parents: 2923
diff changeset
211 UStringPrepProfile *icu_resourceprep;
f02bac902a1e util.encodings: Support for ICU for IDNA operations.
Tobias Markmann <tm@ayena.de>
parents: 2923
diff changeset
212 UStringPrepProfile *icu_saslprep;
f02bac902a1e util.encodings: Support for ICU for IDNA operations.
Tobias Markmann <tm@ayena.de>
parents: 2923
diff changeset
213
f02bac902a1e util.encodings: Support for ICU for IDNA operations.
Tobias Markmann <tm@ayena.de>
parents: 2923
diff changeset
214 /* initialize global ICU stringprep profiles */
f02bac902a1e util.encodings: Support for ICU for IDNA operations.
Tobias Markmann <tm@ayena.de>
parents: 2923
diff changeset
215 void init_icu()
f02bac902a1e util.encodings: Support for ICU for IDNA operations.
Tobias Markmann <tm@ayena.de>
parents: 2923
diff changeset
216 {
f02bac902a1e util.encodings: Support for ICU for IDNA operations.
Tobias Markmann <tm@ayena.de>
parents: 2923
diff changeset
217 UErrorCode err = U_ZERO_ERROR;
f02bac902a1e util.encodings: Support for ICU for IDNA operations.
Tobias Markmann <tm@ayena.de>
parents: 2923
diff changeset
218 utrace_setLevel(UTRACE_VERBOSE);
f02bac902a1e util.encodings: Support for ICU for IDNA operations.
Tobias Markmann <tm@ayena.de>
parents: 2923
diff changeset
219 icu_nameprep = usprep_openByType(USPREP_RFC3491_NAMEPREP, &err);
f02bac902a1e util.encodings: Support for ICU for IDNA operations.
Tobias Markmann <tm@ayena.de>
parents: 2923
diff changeset
220 icu_nodeprep = usprep_openByType(USPREP_RFC3920_NODEPREP, &err);
f02bac902a1e util.encodings: Support for ICU for IDNA operations.
Tobias Markmann <tm@ayena.de>
parents: 2923
diff changeset
221 icu_resourceprep = usprep_openByType(USPREP_RFC3920_RESOURCEPREP, &err);
f02bac902a1e util.encodings: Support for ICU for IDNA operations.
Tobias Markmann <tm@ayena.de>
parents: 2923
diff changeset
222 icu_saslprep = usprep_openByType(USPREP_RFC4013_SASLPREP, &err);
f02bac902a1e util.encodings: Support for ICU for IDNA operations.
Tobias Markmann <tm@ayena.de>
parents: 2923
diff changeset
223 if (U_FAILURE(err)) fprintf(stderr, "[c] util.encodings: error: %s\n", u_errorName((UErrorCode)err));
f02bac902a1e util.encodings: Support for ICU for IDNA operations.
Tobias Markmann <tm@ayena.de>
parents: 2923
diff changeset
224 }
f02bac902a1e util.encodings: Support for ICU for IDNA operations.
Tobias Markmann <tm@ayena.de>
parents: 2923
diff changeset
225
f02bac902a1e util.encodings: Support for ICU for IDNA operations.
Tobias Markmann <tm@ayena.de>
parents: 2923
diff changeset
226 #define MAKE_PREP_FUNC(myFunc, prep) \
f02bac902a1e util.encodings: Support for ICU for IDNA operations.
Tobias Markmann <tm@ayena.de>
parents: 2923
diff changeset
227 static int myFunc(lua_State *L) { return icu_stringprep_prep(L, prep); }
f02bac902a1e util.encodings: Support for ICU for IDNA operations.
Tobias Markmann <tm@ayena.de>
parents: 2923
diff changeset
228
f02bac902a1e util.encodings: Support for ICU for IDNA operations.
Tobias Markmann <tm@ayena.de>
parents: 2923
diff changeset
229 MAKE_PREP_FUNC(Lstringprep_nameprep, icu_nameprep) /** stringprep.nameprep(s) */
f02bac902a1e util.encodings: Support for ICU for IDNA operations.
Tobias Markmann <tm@ayena.de>
parents: 2923
diff changeset
230 MAKE_PREP_FUNC(Lstringprep_nodeprep, icu_nodeprep) /** stringprep.nodeprep(s) */
f02bac902a1e util.encodings: Support for ICU for IDNA operations.
Tobias Markmann <tm@ayena.de>
parents: 2923
diff changeset
231 MAKE_PREP_FUNC(Lstringprep_resourceprep, icu_resourceprep) /** stringprep.resourceprep(s) */
f02bac902a1e util.encodings: Support for ICU for IDNA operations.
Tobias Markmann <tm@ayena.de>
parents: 2923
diff changeset
232 MAKE_PREP_FUNC(Lstringprep_saslprep, icu_saslprep) /** stringprep.saslprep(s) */
f02bac902a1e util.encodings: Support for ICU for IDNA operations.
Tobias Markmann <tm@ayena.de>
parents: 2923
diff changeset
233
f02bac902a1e util.encodings: Support for ICU for IDNA operations.
Tobias Markmann <tm@ayena.de>
parents: 2923
diff changeset
234 static const luaL_Reg Reg_stringprep[] =
f02bac902a1e util.encodings: Support for ICU for IDNA operations.
Tobias Markmann <tm@ayena.de>
parents: 2923
diff changeset
235 {
f02bac902a1e util.encodings: Support for ICU for IDNA operations.
Tobias Markmann <tm@ayena.de>
parents: 2923
diff changeset
236 { "nameprep", Lstringprep_nameprep },
f02bac902a1e util.encodings: Support for ICU for IDNA operations.
Tobias Markmann <tm@ayena.de>
parents: 2923
diff changeset
237 { "nodeprep", Lstringprep_nodeprep },
f02bac902a1e util.encodings: Support for ICU for IDNA operations.
Tobias Markmann <tm@ayena.de>
parents: 2923
diff changeset
238 { "resourceprep", Lstringprep_resourceprep },
f02bac902a1e util.encodings: Support for ICU for IDNA operations.
Tobias Markmann <tm@ayena.de>
parents: 2923
diff changeset
239 { "saslprep", Lstringprep_saslprep },
f02bac902a1e util.encodings: Support for ICU for IDNA operations.
Tobias Markmann <tm@ayena.de>
parents: 2923
diff changeset
240 { NULL, NULL }
f02bac902a1e util.encodings: Support for ICU for IDNA operations.
Tobias Markmann <tm@ayena.de>
parents: 2923
diff changeset
241 };
f02bac902a1e util.encodings: Support for ICU for IDNA operations.
Tobias Markmann <tm@ayena.de>
parents: 2923
diff changeset
242 #endif
f02bac902a1e util.encodings: Support for ICU for IDNA operations.
Tobias Markmann <tm@ayena.de>
parents: 2923
diff changeset
243
766
433a5226267f Licensing/version updates for some files (forgot to commit, doh...)
Matthew Wild <mwild1@gmail.com>
parents: 601
diff changeset
244 /***************** IDNA *****************/
3762
f02bac902a1e util.encodings: Support for ICU for IDNA operations.
Tobias Markmann <tm@ayena.de>
parents: 2923
diff changeset
245 #ifndef USE_STRINGPREP_ICU
f02bac902a1e util.encodings: Support for ICU for IDNA operations.
Tobias Markmann <tm@ayena.de>
parents: 2923
diff changeset
246 /****************** libidn ********************/
3769
9338d0785277 util-src/Makefile, util-src/encodings.c{,pp}: Port ICU code to C, rename encodings.cpp back to .c and amend the Makefile accordingly
Matthew Wild <mwild1@gmail.com>
parents: 3764
diff changeset
247
766
433a5226267f Licensing/version updates for some files (forgot to commit, doh...)
Matthew Wild <mwild1@gmail.com>
parents: 601
diff changeset
248 #include <idna.h>
1855
63b5e7ec6840 util.encodings: Included idn-free.h, which explicitly declares the idn_free function.
Waqas Hussain <waqas20@gmail.com>
parents: 1854
diff changeset
249 #include <idn-free.h>
3769
9338d0785277 util-src/Makefile, util-src/encodings.c{,pp}: Port ICU code to C, rename encodings.cpp back to .c and amend the Makefile accordingly
Matthew Wild <mwild1@gmail.com>
parents: 3764
diff changeset
250
766
433a5226267f Licensing/version updates for some files (forgot to commit, doh...)
Matthew Wild <mwild1@gmail.com>
parents: 601
diff changeset
251 static int Lidna_to_ascii(lua_State *L) /** idna.to_ascii(s) */
433a5226267f Licensing/version updates for some files (forgot to commit, doh...)
Matthew Wild <mwild1@gmail.com>
parents: 601
diff changeset
252 {
433a5226267f Licensing/version updates for some files (forgot to commit, doh...)
Matthew Wild <mwild1@gmail.com>
parents: 601
diff changeset
253 size_t len;
433a5226267f Licensing/version updates for some files (forgot to commit, doh...)
Matthew Wild <mwild1@gmail.com>
parents: 601
diff changeset
254 const char *s = luaL_checklstring(L, 1, &len);
433a5226267f Licensing/version updates for some files (forgot to commit, doh...)
Matthew Wild <mwild1@gmail.com>
parents: 601
diff changeset
255 char* output = NULL;
2572
0584e157f073 util.encodings: Use STD3 ASCII rules for idna.to_ascii.
Waqas Hussain <waqas20@gmail.com>
parents: 1860
diff changeset
256 int ret = idna_to_ascii_8z(s, &output, IDNA_USE_STD3_ASCII_RULES);
766
433a5226267f Licensing/version updates for some files (forgot to commit, doh...)
Matthew Wild <mwild1@gmail.com>
parents: 601
diff changeset
257 if (ret == IDNA_SUCCESS) {
433a5226267f Licensing/version updates for some files (forgot to commit, doh...)
Matthew Wild <mwild1@gmail.com>
parents: 601
diff changeset
258 lua_pushstring(L, output);
1829
3d0db768be2f util.encodings: Fixed an issue with cross-module memory deallocation (crashes on some windows versions).
Waqas Hussain <waqas20@gmail.com>
parents: 896
diff changeset
259 idn_free(output);
766
433a5226267f Licensing/version updates for some files (forgot to commit, doh...)
Matthew Wild <mwild1@gmail.com>
parents: 601
diff changeset
260 return 1;
433a5226267f Licensing/version updates for some files (forgot to commit, doh...)
Matthew Wild <mwild1@gmail.com>
parents: 601
diff changeset
261 } else {
433a5226267f Licensing/version updates for some files (forgot to commit, doh...)
Matthew Wild <mwild1@gmail.com>
parents: 601
diff changeset
262 lua_pushnil(L);
1829
3d0db768be2f util.encodings: Fixed an issue with cross-module memory deallocation (crashes on some windows versions).
Waqas Hussain <waqas20@gmail.com>
parents: 896
diff changeset
263 idn_free(output);
766
433a5226267f Licensing/version updates for some files (forgot to commit, doh...)
Matthew Wild <mwild1@gmail.com>
parents: 601
diff changeset
264 return 1; // TODO return error message
433a5226267f Licensing/version updates for some files (forgot to commit, doh...)
Matthew Wild <mwild1@gmail.com>
parents: 601
diff changeset
265 }
433a5226267f Licensing/version updates for some files (forgot to commit, doh...)
Matthew Wild <mwild1@gmail.com>
parents: 601
diff changeset
266 }
433a5226267f Licensing/version updates for some files (forgot to commit, doh...)
Matthew Wild <mwild1@gmail.com>
parents: 601
diff changeset
267
433a5226267f Licensing/version updates for some files (forgot to commit, doh...)
Matthew Wild <mwild1@gmail.com>
parents: 601
diff changeset
268 static int Lidna_to_unicode(lua_State *L) /** idna.to_unicode(s) */
433a5226267f Licensing/version updates for some files (forgot to commit, doh...)
Matthew Wild <mwild1@gmail.com>
parents: 601
diff changeset
269 {
433a5226267f Licensing/version updates for some files (forgot to commit, doh...)
Matthew Wild <mwild1@gmail.com>
parents: 601
diff changeset
270 size_t len;
433a5226267f Licensing/version updates for some files (forgot to commit, doh...)
Matthew Wild <mwild1@gmail.com>
parents: 601
diff changeset
271 const char *s = luaL_checklstring(L, 1, &len);
433a5226267f Licensing/version updates for some files (forgot to commit, doh...)
Matthew Wild <mwild1@gmail.com>
parents: 601
diff changeset
272 char* output = NULL;
433a5226267f Licensing/version updates for some files (forgot to commit, doh...)
Matthew Wild <mwild1@gmail.com>
parents: 601
diff changeset
273 int ret = idna_to_unicode_8z8z(s, &output, 0);
433a5226267f Licensing/version updates for some files (forgot to commit, doh...)
Matthew Wild <mwild1@gmail.com>
parents: 601
diff changeset
274 if (ret == IDNA_SUCCESS) {
433a5226267f Licensing/version updates for some files (forgot to commit, doh...)
Matthew Wild <mwild1@gmail.com>
parents: 601
diff changeset
275 lua_pushstring(L, output);
1829
3d0db768be2f util.encodings: Fixed an issue with cross-module memory deallocation (crashes on some windows versions).
Waqas Hussain <waqas20@gmail.com>
parents: 896
diff changeset
276 idn_free(output);
766
433a5226267f Licensing/version updates for some files (forgot to commit, doh...)
Matthew Wild <mwild1@gmail.com>
parents: 601
diff changeset
277 return 1;
433a5226267f Licensing/version updates for some files (forgot to commit, doh...)
Matthew Wild <mwild1@gmail.com>
parents: 601
diff changeset
278 } else {
433a5226267f Licensing/version updates for some files (forgot to commit, doh...)
Matthew Wild <mwild1@gmail.com>
parents: 601
diff changeset
279 lua_pushnil(L);
1829
3d0db768be2f util.encodings: Fixed an issue with cross-module memory deallocation (crashes on some windows versions).
Waqas Hussain <waqas20@gmail.com>
parents: 896
diff changeset
280 idn_free(output);
766
433a5226267f Licensing/version updates for some files (forgot to commit, doh...)
Matthew Wild <mwild1@gmail.com>
parents: 601
diff changeset
281 return 1; // TODO return error message
433a5226267f Licensing/version updates for some files (forgot to commit, doh...)
Matthew Wild <mwild1@gmail.com>
parents: 601
diff changeset
282 }
433a5226267f Licensing/version updates for some files (forgot to commit, doh...)
Matthew Wild <mwild1@gmail.com>
parents: 601
diff changeset
283 }
3762
f02bac902a1e util.encodings: Support for ICU for IDNA operations.
Tobias Markmann <tm@ayena.de>
parents: 2923
diff changeset
284 #else
f02bac902a1e util.encodings: Support for ICU for IDNA operations.
Tobias Markmann <tm@ayena.de>
parents: 2923
diff changeset
285 #include <unicode/ustdio.h>
f02bac902a1e util.encodings: Support for ICU for IDNA operations.
Tobias Markmann <tm@ayena.de>
parents: 2923
diff changeset
286 #include <unicode/uidna.h>
f02bac902a1e util.encodings: Support for ICU for IDNA operations.
Tobias Markmann <tm@ayena.de>
parents: 2923
diff changeset
287 /* IDNA2003 or IDNA2008 ? ? ? */
f02bac902a1e util.encodings: Support for ICU for IDNA operations.
Tobias Markmann <tm@ayena.de>
parents: 2923
diff changeset
288 static int Lidna_to_ascii(lua_State *L) /** idna.to_ascii(s) */
f02bac902a1e util.encodings: Support for ICU for IDNA operations.
Tobias Markmann <tm@ayena.de>
parents: 2923
diff changeset
289 {
f02bac902a1e util.encodings: Support for ICU for IDNA operations.
Tobias Markmann <tm@ayena.de>
parents: 2923
diff changeset
290 size_t len;
3769
9338d0785277 util-src/Makefile, util-src/encodings.c{,pp}: Port ICU code to C, rename encodings.cpp back to .c and amend the Makefile accordingly
Matthew Wild <mwild1@gmail.com>
parents: 3764
diff changeset
291 int32_t ulen, dest_len, output_len;
3762
f02bac902a1e util.encodings: Support for ICU for IDNA operations.
Tobias Markmann <tm@ayena.de>
parents: 2923
diff changeset
292 const char *s = luaL_checklstring(L, 1, &len);
3769
9338d0785277 util-src/Makefile, util-src/encodings.c{,pp}: Port ICU code to C, rename encodings.cpp back to .c and amend the Makefile accordingly
Matthew Wild <mwild1@gmail.com>
parents: 3764
diff changeset
293 UChar ustr[1024];
3762
f02bac902a1e util.encodings: Support for ICU for IDNA operations.
Tobias Markmann <tm@ayena.de>
parents: 2923
diff changeset
294 UErrorCode err = U_ZERO_ERROR;
f02bac902a1e util.encodings: Support for ICU for IDNA operations.
Tobias Markmann <tm@ayena.de>
parents: 2923
diff changeset
295 UChar dest[1024];
f02bac902a1e util.encodings: Support for ICU for IDNA operations.
Tobias Markmann <tm@ayena.de>
parents: 2923
diff changeset
296 char output[1024];
f02bac902a1e util.encodings: Support for ICU for IDNA operations.
Tobias Markmann <tm@ayena.de>
parents: 2923
diff changeset
297
3769
9338d0785277 util-src/Makefile, util-src/encodings.c{,pp}: Port ICU code to C, rename encodings.cpp back to .c and amend the Makefile accordingly
Matthew Wild <mwild1@gmail.com>
parents: 3764
diff changeset
298 u_strFromUTF8(ustr, 1024, &ulen, s, len, &err);
9338d0785277 util-src/Makefile, util-src/encodings.c{,pp}: Port ICU code to C, rename encodings.cpp back to .c and amend the Makefile accordingly
Matthew Wild <mwild1@gmail.com>
parents: 3764
diff changeset
299 dest_len = uidna_IDNToASCII(ustr, ulen, dest, 1024, UIDNA_USE_STD3_RULES, NULL, &err);
3762
f02bac902a1e util.encodings: Support for ICU for IDNA operations.
Tobias Markmann <tm@ayena.de>
parents: 2923
diff changeset
300 if (U_FAILURE(err)) {
f02bac902a1e util.encodings: Support for ICU for IDNA operations.
Tobias Markmann <tm@ayena.de>
parents: 2923
diff changeset
301 lua_pushnil(L);
f02bac902a1e util.encodings: Support for ICU for IDNA operations.
Tobias Markmann <tm@ayena.de>
parents: 2923
diff changeset
302 return 1;
f02bac902a1e util.encodings: Support for ICU for IDNA operations.
Tobias Markmann <tm@ayena.de>
parents: 2923
diff changeset
303 } else {
3769
9338d0785277 util-src/Makefile, util-src/encodings.c{,pp}: Port ICU code to C, rename encodings.cpp back to .c and amend the Makefile accordingly
Matthew Wild <mwild1@gmail.com>
parents: 3764
diff changeset
304 u_strToUTF8(output, 1024, &output_len, dest, dest_len, &err);
9338d0785277 util-src/Makefile, util-src/encodings.c{,pp}: Port ICU code to C, rename encodings.cpp back to .c and amend the Makefile accordingly
Matthew Wild <mwild1@gmail.com>
parents: 3764
diff changeset
305 if(output_len < 1024)
9338d0785277 util-src/Makefile, util-src/encodings.c{,pp}: Port ICU code to C, rename encodings.cpp back to .c and amend the Makefile accordingly
Matthew Wild <mwild1@gmail.com>
parents: 3764
diff changeset
306 lua_pushlstring(L, output, output_len);
9338d0785277 util-src/Makefile, util-src/encodings.c{,pp}: Port ICU code to C, rename encodings.cpp back to .c and amend the Makefile accordingly
Matthew Wild <mwild1@gmail.com>
parents: 3764
diff changeset
307 else
9338d0785277 util-src/Makefile, util-src/encodings.c{,pp}: Port ICU code to C, rename encodings.cpp back to .c and amend the Makefile accordingly
Matthew Wild <mwild1@gmail.com>
parents: 3764
diff changeset
308 lua_pushnil(L);
3762
f02bac902a1e util.encodings: Support for ICU for IDNA operations.
Tobias Markmann <tm@ayena.de>
parents: 2923
diff changeset
309 return 1;
f02bac902a1e util.encodings: Support for ICU for IDNA operations.
Tobias Markmann <tm@ayena.de>
parents: 2923
diff changeset
310 }
f02bac902a1e util.encodings: Support for ICU for IDNA operations.
Tobias Markmann <tm@ayena.de>
parents: 2923
diff changeset
311 }
f02bac902a1e util.encodings: Support for ICU for IDNA operations.
Tobias Markmann <tm@ayena.de>
parents: 2923
diff changeset
312
f02bac902a1e util.encodings: Support for ICU for IDNA operations.
Tobias Markmann <tm@ayena.de>
parents: 2923
diff changeset
313 static int Lidna_to_unicode(lua_State *L) /** idna.to_unicode(s) */
f02bac902a1e util.encodings: Support for ICU for IDNA operations.
Tobias Markmann <tm@ayena.de>
parents: 2923
diff changeset
314 {
f02bac902a1e util.encodings: Support for ICU for IDNA operations.
Tobias Markmann <tm@ayena.de>
parents: 2923
diff changeset
315 size_t len;
3769
9338d0785277 util-src/Makefile, util-src/encodings.c{,pp}: Port ICU code to C, rename encodings.cpp back to .c and amend the Makefile accordingly
Matthew Wild <mwild1@gmail.com>
parents: 3764
diff changeset
316 int32_t ulen, dest_len, output_len;
3762
f02bac902a1e util.encodings: Support for ICU for IDNA operations.
Tobias Markmann <tm@ayena.de>
parents: 2923
diff changeset
317 const char *s = luaL_checklstring(L, 1, &len);
3769
9338d0785277 util-src/Makefile, util-src/encodings.c{,pp}: Port ICU code to C, rename encodings.cpp back to .c and amend the Makefile accordingly
Matthew Wild <mwild1@gmail.com>
parents: 3764
diff changeset
318 UChar* ustr;
3762
f02bac902a1e util.encodings: Support for ICU for IDNA operations.
Tobias Markmann <tm@ayena.de>
parents: 2923
diff changeset
319 UErrorCode err = U_ZERO_ERROR;
f02bac902a1e util.encodings: Support for ICU for IDNA operations.
Tobias Markmann <tm@ayena.de>
parents: 2923
diff changeset
320 UChar dest[1024];
f02bac902a1e util.encodings: Support for ICU for IDNA operations.
Tobias Markmann <tm@ayena.de>
parents: 2923
diff changeset
321 char output[1024];
f02bac902a1e util.encodings: Support for ICU for IDNA operations.
Tobias Markmann <tm@ayena.de>
parents: 2923
diff changeset
322
3769
9338d0785277 util-src/Makefile, util-src/encodings.c{,pp}: Port ICU code to C, rename encodings.cpp back to .c and amend the Makefile accordingly
Matthew Wild <mwild1@gmail.com>
parents: 3764
diff changeset
323 u_strFromUTF8(ustr, 1024, &ulen, s, len, &err);
9338d0785277 util-src/Makefile, util-src/encodings.c{,pp}: Port ICU code to C, rename encodings.cpp back to .c and amend the Makefile accordingly
Matthew Wild <mwild1@gmail.com>
parents: 3764
diff changeset
324 dest_len = uidna_IDNToUnicode(ustr, ulen, dest, 1024, UIDNA_USE_STD3_RULES, NULL, &err);
3762
f02bac902a1e util.encodings: Support for ICU for IDNA operations.
Tobias Markmann <tm@ayena.de>
parents: 2923
diff changeset
325 if (U_FAILURE(err)) {
f02bac902a1e util.encodings: Support for ICU for IDNA operations.
Tobias Markmann <tm@ayena.de>
parents: 2923
diff changeset
326 lua_pushnil(L);
f02bac902a1e util.encodings: Support for ICU for IDNA operations.
Tobias Markmann <tm@ayena.de>
parents: 2923
diff changeset
327 return 1;
f02bac902a1e util.encodings: Support for ICU for IDNA operations.
Tobias Markmann <tm@ayena.de>
parents: 2923
diff changeset
328 } else {
3769
9338d0785277 util-src/Makefile, util-src/encodings.c{,pp}: Port ICU code to C, rename encodings.cpp back to .c and amend the Makefile accordingly
Matthew Wild <mwild1@gmail.com>
parents: 3764
diff changeset
329 u_strToUTF8(output, 1024, &output_len, dest, dest_len, &err);
9338d0785277 util-src/Makefile, util-src/encodings.c{,pp}: Port ICU code to C, rename encodings.cpp back to .c and amend the Makefile accordingly
Matthew Wild <mwild1@gmail.com>
parents: 3764
diff changeset
330 if(output_len < 1024)
9338d0785277 util-src/Makefile, util-src/encodings.c{,pp}: Port ICU code to C, rename encodings.cpp back to .c and amend the Makefile accordingly
Matthew Wild <mwild1@gmail.com>
parents: 3764
diff changeset
331 lua_pushlstring(L, output, output_len);
9338d0785277 util-src/Makefile, util-src/encodings.c{,pp}: Port ICU code to C, rename encodings.cpp back to .c and amend the Makefile accordingly
Matthew Wild <mwild1@gmail.com>
parents: 3764
diff changeset
332 else
9338d0785277 util-src/Makefile, util-src/encodings.c{,pp}: Port ICU code to C, rename encodings.cpp back to .c and amend the Makefile accordingly
Matthew Wild <mwild1@gmail.com>
parents: 3764
diff changeset
333 lua_pushnil(L);
3762
f02bac902a1e util.encodings: Support for ICU for IDNA operations.
Tobias Markmann <tm@ayena.de>
parents: 2923
diff changeset
334 return 1;
f02bac902a1e util.encodings: Support for ICU for IDNA operations.
Tobias Markmann <tm@ayena.de>
parents: 2923
diff changeset
335 }
f02bac902a1e util.encodings: Support for ICU for IDNA operations.
Tobias Markmann <tm@ayena.de>
parents: 2923
diff changeset
336 }
f02bac902a1e util.encodings: Support for ICU for IDNA operations.
Tobias Markmann <tm@ayena.de>
parents: 2923
diff changeset
337 #endif
766
433a5226267f Licensing/version updates for some files (forgot to commit, doh...)
Matthew Wild <mwild1@gmail.com>
parents: 601
diff changeset
338
433a5226267f Licensing/version updates for some files (forgot to commit, doh...)
Matthew Wild <mwild1@gmail.com>
parents: 601
diff changeset
339 static const luaL_Reg Reg_idna[] =
433a5226267f Licensing/version updates for some files (forgot to commit, doh...)
Matthew Wild <mwild1@gmail.com>
parents: 601
diff changeset
340 {
433a5226267f Licensing/version updates for some files (forgot to commit, doh...)
Matthew Wild <mwild1@gmail.com>
parents: 601
diff changeset
341 { "to_ascii", Lidna_to_ascii },
433a5226267f Licensing/version updates for some files (forgot to commit, doh...)
Matthew Wild <mwild1@gmail.com>
parents: 601
diff changeset
342 { "to_unicode", Lidna_to_unicode },
433a5226267f Licensing/version updates for some files (forgot to commit, doh...)
Matthew Wild <mwild1@gmail.com>
parents: 601
diff changeset
343 { NULL, NULL }
433a5226267f Licensing/version updates for some files (forgot to commit, doh...)
Matthew Wild <mwild1@gmail.com>
parents: 601
diff changeset
344 };
433a5226267f Licensing/version updates for some files (forgot to commit, doh...)
Matthew Wild <mwild1@gmail.com>
parents: 601
diff changeset
345
433a5226267f Licensing/version updates for some files (forgot to commit, doh...)
Matthew Wild <mwild1@gmail.com>
parents: 601
diff changeset
346 /***************** end *****************/
433a5226267f Licensing/version updates for some files (forgot to commit, doh...)
Matthew Wild <mwild1@gmail.com>
parents: 601
diff changeset
347
433a5226267f Licensing/version updates for some files (forgot to commit, doh...)
Matthew Wild <mwild1@gmail.com>
parents: 601
diff changeset
348 static const luaL_Reg Reg[] =
433a5226267f Licensing/version updates for some files (forgot to commit, doh...)
Matthew Wild <mwild1@gmail.com>
parents: 601
diff changeset
349 {
433a5226267f Licensing/version updates for some files (forgot to commit, doh...)
Matthew Wild <mwild1@gmail.com>
parents: 601
diff changeset
350 { NULL, NULL }
433a5226267f Licensing/version updates for some files (forgot to commit, doh...)
Matthew Wild <mwild1@gmail.com>
parents: 601
diff changeset
351 };
433a5226267f Licensing/version updates for some files (forgot to commit, doh...)
Matthew Wild <mwild1@gmail.com>
parents: 601
diff changeset
352
433a5226267f Licensing/version updates for some files (forgot to commit, doh...)
Matthew Wild <mwild1@gmail.com>
parents: 601
diff changeset
353 LUALIB_API int luaopen_util_encodings(lua_State *L)
433a5226267f Licensing/version updates for some files (forgot to commit, doh...)
Matthew Wild <mwild1@gmail.com>
parents: 601
diff changeset
354 {
3762
f02bac902a1e util.encodings: Support for ICU for IDNA operations.
Tobias Markmann <tm@ayena.de>
parents: 2923
diff changeset
355 #ifdef USE_STRINGPREP_ICU
f02bac902a1e util.encodings: Support for ICU for IDNA operations.
Tobias Markmann <tm@ayena.de>
parents: 2923
diff changeset
356 init_icu();
f02bac902a1e util.encodings: Support for ICU for IDNA operations.
Tobias Markmann <tm@ayena.de>
parents: 2923
diff changeset
357 #endif
766
433a5226267f Licensing/version updates for some files (forgot to commit, doh...)
Matthew Wild <mwild1@gmail.com>
parents: 601
diff changeset
358 luaL_register(L, "encodings", Reg);
433a5226267f Licensing/version updates for some files (forgot to commit, doh...)
Matthew Wild <mwild1@gmail.com>
parents: 601
diff changeset
359
433a5226267f Licensing/version updates for some files (forgot to commit, doh...)
Matthew Wild <mwild1@gmail.com>
parents: 601
diff changeset
360 lua_pushliteral(L, "base64");
433a5226267f Licensing/version updates for some files (forgot to commit, doh...)
Matthew Wild <mwild1@gmail.com>
parents: 601
diff changeset
361 lua_newtable(L);
433a5226267f Licensing/version updates for some files (forgot to commit, doh...)
Matthew Wild <mwild1@gmail.com>
parents: 601
diff changeset
362 luaL_register(L, NULL, Reg_base64);
433a5226267f Licensing/version updates for some files (forgot to commit, doh...)
Matthew Wild <mwild1@gmail.com>
parents: 601
diff changeset
363 lua_settable(L,-3);
433a5226267f Licensing/version updates for some files (forgot to commit, doh...)
Matthew Wild <mwild1@gmail.com>
parents: 601
diff changeset
364
433a5226267f Licensing/version updates for some files (forgot to commit, doh...)
Matthew Wild <mwild1@gmail.com>
parents: 601
diff changeset
365 lua_pushliteral(L, "stringprep");
433a5226267f Licensing/version updates for some files (forgot to commit, doh...)
Matthew Wild <mwild1@gmail.com>
parents: 601
diff changeset
366 lua_newtable(L);
433a5226267f Licensing/version updates for some files (forgot to commit, doh...)
Matthew Wild <mwild1@gmail.com>
parents: 601
diff changeset
367 luaL_register(L, NULL, Reg_stringprep);
433a5226267f Licensing/version updates for some files (forgot to commit, doh...)
Matthew Wild <mwild1@gmail.com>
parents: 601
diff changeset
368 lua_settable(L,-3);
433a5226267f Licensing/version updates for some files (forgot to commit, doh...)
Matthew Wild <mwild1@gmail.com>
parents: 601
diff changeset
369
433a5226267f Licensing/version updates for some files (forgot to commit, doh...)
Matthew Wild <mwild1@gmail.com>
parents: 601
diff changeset
370 lua_pushliteral(L, "idna");
433a5226267f Licensing/version updates for some files (forgot to commit, doh...)
Matthew Wild <mwild1@gmail.com>
parents: 601
diff changeset
371 lua_newtable(L);
433a5226267f Licensing/version updates for some files (forgot to commit, doh...)
Matthew Wild <mwild1@gmail.com>
parents: 601
diff changeset
372 luaL_register(L, NULL, Reg_idna);
433a5226267f Licensing/version updates for some files (forgot to commit, doh...)
Matthew Wild <mwild1@gmail.com>
parents: 601
diff changeset
373 lua_settable(L,-3);
433a5226267f Licensing/version updates for some files (forgot to commit, doh...)
Matthew Wild <mwild1@gmail.com>
parents: 601
diff changeset
374
433a5226267f Licensing/version updates for some files (forgot to commit, doh...)
Matthew Wild <mwild1@gmail.com>
parents: 601
diff changeset
375 lua_pushliteral(L, "version"); /** version */
433a5226267f Licensing/version updates for some files (forgot to commit, doh...)
Matthew Wild <mwild1@gmail.com>
parents: 601
diff changeset
376 lua_pushliteral(L, "-3.14");
433a5226267f Licensing/version updates for some files (forgot to commit, doh...)
Matthew Wild <mwild1@gmail.com>
parents: 601
diff changeset
377 lua_settable(L,-3);
433a5226267f Licensing/version updates for some files (forgot to commit, doh...)
Matthew Wild <mwild1@gmail.com>
parents: 601
diff changeset
378 return 1;
433a5226267f Licensing/version updates for some files (forgot to commit, doh...)
Matthew Wild <mwild1@gmail.com>
parents: 601
diff changeset
379 }