Annotate

util-src/encodings.c @ 4847:7a7cc4d98faf

mod_dialback: Fix logic bug - we should have both a to and from at this point
author Matthew Wild <mwild1@gmail.com>
date Fri, 11 May 2012 01:54:36 +0100
parent 4302:bbb0bf0a09f5
child 6411:6c8f6364bc48
child 6591:fe3018a2f187
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
3965
4ae4b2c0e99d util.encodings: Switch comment styles to build ok as ANSI C
Matthew Wild <mwild1@gmail.com>
parents: 3769
diff changeset
15 /* Newer MSVC compilers deprecate strcpy as unsafe, but we use it in a safe way */
766
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 *****************/
4272
0a4ce2086a88 util.encodings: Swap code order ("ifndef" bugs me)
Paul Aurich <paul@darkrain42.org>
parents: 4271
diff changeset
120 #ifdef USE_STRINGPREP_ICU
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
121
3762
f02bac902a1e util.encodings: Support for ICU for IDNA operations.
Tobias Markmann <tm@ayena.de>
parents: 2923
diff changeset
122 #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
123 #include <unicode/ustring.h>
3762
f02bac902a1e util.encodings: Support for ICU for IDNA operations.
Tobias Markmann <tm@ayena.de>
parents: 2923
diff changeset
124 #include <unicode/utrace.h>
f02bac902a1e util.encodings: Support for ICU for IDNA operations.
Tobias Markmann <tm@ayena.de>
parents: 2923
diff changeset
125
f02bac902a1e util.encodings: Support for ICU for IDNA operations.
Tobias Markmann <tm@ayena.de>
parents: 2923
diff changeset
126 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
127 {
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
128 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
129 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
130 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
131 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
132
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
133 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
134 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
135
3762
f02bac902a1e util.encodings: Support for ICU for IDNA operations.
Tobias Markmann <tm@ayena.de>
parents: 2923
diff changeset
136 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
137
3762
f02bac902a1e util.encodings: Support for ICU for IDNA operations.
Tobias Markmann <tm@ayena.de>
parents: 2923
diff changeset
138 if(!lua_isstring(L, 1)) {
f02bac902a1e util.encodings: Support for ICU for IDNA operations.
Tobias Markmann <tm@ayena.de>
parents: 2923
diff changeset
139 lua_pushnil(L);
f02bac902a1e util.encodings: Support for ICU for IDNA operations.
Tobias Markmann <tm@ayena.de>
parents: 2923
diff changeset
140 return 1;
f02bac902a1e util.encodings: Support for ICU for IDNA operations.
Tobias Markmann <tm@ayena.de>
parents: 2923
diff changeset
141 }
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
142 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
143 if (input_len >= 1024) {
3762
f02bac902a1e util.encodings: Support for ICU for IDNA operations.
Tobias Markmann <tm@ayena.de>
parents: 2923
diff changeset
144 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
145 return 1;
3762
f02bac902a1e util.encodings: Support for ICU for IDNA operations.
Tobias Markmann <tm@ayena.de>
parents: 2923
diff changeset
146 }
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
147 u_strFromUTF8(unprepped, 1024, &unprepped_len, input, input_len, &err);
4273
7f789266b741 util.encodings: Check return values before proceeding
Paul Aurich <paul@darkrain42.org>
parents: 4272
diff changeset
148 if (U_FAILURE(err)) {
4302
bbb0bf0a09f5 util.encodings: Fix small typo introduced in 7f789266b741
Matthew Wild <mwild1@gmail.com>
parents: 4273
diff changeset
149 lua_pushnil(L);
4273
7f789266b741 util.encodings: Check return values before proceeding
Paul Aurich <paul@darkrain42.org>
parents: 4272
diff changeset
150 return 1;
7f789266b741 util.encodings: Check return values before proceeding
Paul Aurich <paul@darkrain42.org>
parents: 4272
diff changeset
151 }
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
152 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
153 if (U_FAILURE(err)) {
f02bac902a1e util.encodings: Support for ICU for IDNA operations.
Tobias Markmann <tm@ayena.de>
parents: 2923
diff changeset
154 lua_pushnil(L);
f02bac902a1e util.encodings: Support for ICU for IDNA operations.
Tobias Markmann <tm@ayena.de>
parents: 2923
diff changeset
155 return 1;
f02bac902a1e util.encodings: Support for ICU for IDNA operations.
Tobias Markmann <tm@ayena.de>
parents: 2923
diff changeset
156 } 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
157 u_strToUTF8(output, 1024, &output_len, prepped, prepped_len, &err);
4273
7f789266b741 util.encodings: Check return values before proceeding
Paul Aurich <paul@darkrain42.org>
parents: 4272
diff changeset
158 if (U_SUCCESS(err) && output_len < 1024)
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
159 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
160 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
161 lua_pushnil(L);
3762
f02bac902a1e util.encodings: Support for ICU for IDNA operations.
Tobias Markmann <tm@ayena.de>
parents: 2923
diff changeset
162 return 1;
f02bac902a1e util.encodings: Support for ICU for IDNA operations.
Tobias Markmann <tm@ayena.de>
parents: 2923
diff changeset
163 }
f02bac902a1e util.encodings: Support for ICU for IDNA operations.
Tobias Markmann <tm@ayena.de>
parents: 2923
diff changeset
164 }
f02bac902a1e util.encodings: Support for ICU for IDNA operations.
Tobias Markmann <tm@ayena.de>
parents: 2923
diff changeset
165
f02bac902a1e util.encodings: Support for ICU for IDNA operations.
Tobias Markmann <tm@ayena.de>
parents: 2923
diff changeset
166 UStringPrepProfile *icu_nameprep;
f02bac902a1e util.encodings: Support for ICU for IDNA operations.
Tobias Markmann <tm@ayena.de>
parents: 2923
diff changeset
167 UStringPrepProfile *icu_nodeprep;
f02bac902a1e util.encodings: Support for ICU for IDNA operations.
Tobias Markmann <tm@ayena.de>
parents: 2923
diff changeset
168 UStringPrepProfile *icu_resourceprep;
f02bac902a1e util.encodings: Support for ICU for IDNA operations.
Tobias Markmann <tm@ayena.de>
parents: 2923
diff changeset
169 UStringPrepProfile *icu_saslprep;
f02bac902a1e util.encodings: Support for ICU for IDNA operations.
Tobias Markmann <tm@ayena.de>
parents: 2923
diff changeset
170
f02bac902a1e util.encodings: Support for ICU for IDNA operations.
Tobias Markmann <tm@ayena.de>
parents: 2923
diff changeset
171 /* initialize global ICU stringprep profiles */
f02bac902a1e util.encodings: Support for ICU for IDNA operations.
Tobias Markmann <tm@ayena.de>
parents: 2923
diff changeset
172 void init_icu()
f02bac902a1e util.encodings: Support for ICU for IDNA operations.
Tobias Markmann <tm@ayena.de>
parents: 2923
diff changeset
173 {
f02bac902a1e util.encodings: Support for ICU for IDNA operations.
Tobias Markmann <tm@ayena.de>
parents: 2923
diff changeset
174 UErrorCode err = U_ZERO_ERROR;
f02bac902a1e util.encodings: Support for ICU for IDNA operations.
Tobias Markmann <tm@ayena.de>
parents: 2923
diff changeset
175 utrace_setLevel(UTRACE_VERBOSE);
f02bac902a1e util.encodings: Support for ICU for IDNA operations.
Tobias Markmann <tm@ayena.de>
parents: 2923
diff changeset
176 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
177 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
178 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
179 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
180 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
181 }
f02bac902a1e util.encodings: Support for ICU for IDNA operations.
Tobias Markmann <tm@ayena.de>
parents: 2923
diff changeset
182
f02bac902a1e util.encodings: Support for ICU for IDNA operations.
Tobias Markmann <tm@ayena.de>
parents: 2923
diff changeset
183 #define MAKE_PREP_FUNC(myFunc, prep) \
f02bac902a1e util.encodings: Support for ICU for IDNA operations.
Tobias Markmann <tm@ayena.de>
parents: 2923
diff changeset
184 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
185
f02bac902a1e util.encodings: Support for ICU for IDNA operations.
Tobias Markmann <tm@ayena.de>
parents: 2923
diff changeset
186 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
187 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
188 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
189 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
190
f02bac902a1e util.encodings: Support for ICU for IDNA operations.
Tobias Markmann <tm@ayena.de>
parents: 2923
diff changeset
191 static const luaL_Reg Reg_stringprep[] =
f02bac902a1e util.encodings: Support for ICU for IDNA operations.
Tobias Markmann <tm@ayena.de>
parents: 2923
diff changeset
192 {
f02bac902a1e util.encodings: Support for ICU for IDNA operations.
Tobias Markmann <tm@ayena.de>
parents: 2923
diff changeset
193 { "nameprep", Lstringprep_nameprep },
f02bac902a1e util.encodings: Support for ICU for IDNA operations.
Tobias Markmann <tm@ayena.de>
parents: 2923
diff changeset
194 { "nodeprep", Lstringprep_nodeprep },
f02bac902a1e util.encodings: Support for ICU for IDNA operations.
Tobias Markmann <tm@ayena.de>
parents: 2923
diff changeset
195 { "resourceprep", Lstringprep_resourceprep },
f02bac902a1e util.encodings: Support for ICU for IDNA operations.
Tobias Markmann <tm@ayena.de>
parents: 2923
diff changeset
196 { "saslprep", Lstringprep_saslprep },
f02bac902a1e util.encodings: Support for ICU for IDNA operations.
Tobias Markmann <tm@ayena.de>
parents: 2923
diff changeset
197 { NULL, NULL }
f02bac902a1e util.encodings: Support for ICU for IDNA operations.
Tobias Markmann <tm@ayena.de>
parents: 2923
diff changeset
198 };
4272
0a4ce2086a88 util.encodings: Swap code order ("ifndef" bugs me)
Paul Aurich <paul@darkrain42.org>
parents: 4271
diff changeset
199 #else /* USE_STRINGPREP_ICU */
3762
f02bac902a1e util.encodings: Support for ICU for IDNA operations.
Tobias Markmann <tm@ayena.de>
parents: 2923
diff changeset
200
f02bac902a1e util.encodings: Support for ICU for IDNA operations.
Tobias Markmann <tm@ayena.de>
parents: 2923
diff changeset
201 /****************** 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
202
4272
0a4ce2086a88 util.encodings: Swap code order ("ifndef" bugs me)
Paul Aurich <paul@darkrain42.org>
parents: 4271
diff changeset
203 #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
204
4272
0a4ce2086a88 util.encodings: Swap code order ("ifndef" bugs me)
Paul Aurich <paul@darkrain42.org>
parents: 4271
diff changeset
205 static int stringprep_prep(lua_State *L, const Stringprep_profile *profile)
766
433a5226267f Licensing/version updates for some files (forgot to commit, doh...)
Matthew Wild <mwild1@gmail.com>
parents: 601
diff changeset
206 {
433a5226267f Licensing/version updates for some files (forgot to commit, doh...)
Matthew Wild <mwild1@gmail.com>
parents: 601
diff changeset
207 size_t len;
4272
0a4ce2086a88 util.encodings: Swap code order ("ifndef" bugs me)
Paul Aurich <paul@darkrain42.org>
parents: 4271
diff changeset
208 const char *s;
0a4ce2086a88 util.encodings: Swap code order ("ifndef" bugs me)
Paul Aurich <paul@darkrain42.org>
parents: 4271
diff changeset
209 char string[1024];
0a4ce2086a88 util.encodings: Swap code order ("ifndef" bugs me)
Paul Aurich <paul@darkrain42.org>
parents: 4271
diff changeset
210 int ret;
0a4ce2086a88 util.encodings: Swap code order ("ifndef" bugs me)
Paul Aurich <paul@darkrain42.org>
parents: 4271
diff changeset
211 if(!lua_isstring(L, 1)) {
0a4ce2086a88 util.encodings: Swap code order ("ifndef" bugs me)
Paul Aurich <paul@darkrain42.org>
parents: 4271
diff changeset
212 lua_pushnil(L);
0a4ce2086a88 util.encodings: Swap code order ("ifndef" bugs me)
Paul Aurich <paul@darkrain42.org>
parents: 4271
diff changeset
213 return 1;
0a4ce2086a88 util.encodings: Swap code order ("ifndef" bugs me)
Paul Aurich <paul@darkrain42.org>
parents: 4271
diff changeset
214 }
0a4ce2086a88 util.encodings: Swap code order ("ifndef" bugs me)
Paul Aurich <paul@darkrain42.org>
parents: 4271
diff changeset
215 s = lua_tolstring(L, 1, &len);
0a4ce2086a88 util.encodings: Swap code order ("ifndef" bugs me)
Paul Aurich <paul@darkrain42.org>
parents: 4271
diff changeset
216 if (len >= 1024) {
0a4ce2086a88 util.encodings: Swap code order ("ifndef" bugs me)
Paul Aurich <paul@darkrain42.org>
parents: 4271
diff changeset
217 lua_pushnil(L);
0a4ce2086a88 util.encodings: Swap code order ("ifndef" bugs me)
Paul Aurich <paul@darkrain42.org>
parents: 4271
diff changeset
218 return 1; /* TODO return error message */
0a4ce2086a88 util.encodings: Swap code order ("ifndef" bugs me)
Paul Aurich <paul@darkrain42.org>
parents: 4271
diff changeset
219 }
0a4ce2086a88 util.encodings: Swap code order ("ifndef" bugs me)
Paul Aurich <paul@darkrain42.org>
parents: 4271
diff changeset
220 strcpy(string, s);
0a4ce2086a88 util.encodings: Swap code order ("ifndef" bugs me)
Paul Aurich <paul@darkrain42.org>
parents: 4271
diff changeset
221 ret = stringprep(string, 1024, (Stringprep_profile_flags)0, profile);
0a4ce2086a88 util.encodings: Swap code order ("ifndef" bugs me)
Paul Aurich <paul@darkrain42.org>
parents: 4271
diff changeset
222 if (ret == STRINGPREP_OK) {
0a4ce2086a88 util.encodings: Swap code order ("ifndef" bugs me)
Paul Aurich <paul@darkrain42.org>
parents: 4271
diff changeset
223 lua_pushstring(L, string);
766
433a5226267f Licensing/version updates for some files (forgot to commit, doh...)
Matthew Wild <mwild1@gmail.com>
parents: 601
diff changeset
224 return 1;
433a5226267f Licensing/version updates for some files (forgot to commit, doh...)
Matthew Wild <mwild1@gmail.com>
parents: 601
diff changeset
225 } else {
433a5226267f Licensing/version updates for some files (forgot to commit, doh...)
Matthew Wild <mwild1@gmail.com>
parents: 601
diff changeset
226 lua_pushnil(L);
3965
4ae4b2c0e99d util.encodings: Switch comment styles to build ok as ANSI C
Matthew Wild <mwild1@gmail.com>
parents: 3769
diff changeset
227 return 1; /* TODO return error message */
766
433a5226267f Licensing/version updates for some files (forgot to commit, doh...)
Matthew Wild <mwild1@gmail.com>
parents: 601
diff changeset
228 }
433a5226267f Licensing/version updates for some files (forgot to commit, doh...)
Matthew Wild <mwild1@gmail.com>
parents: 601
diff changeset
229 }
433a5226267f Licensing/version updates for some files (forgot to commit, doh...)
Matthew Wild <mwild1@gmail.com>
parents: 601
diff changeset
230
4272
0a4ce2086a88 util.encodings: Swap code order ("ifndef" bugs me)
Paul Aurich <paul@darkrain42.org>
parents: 4271
diff changeset
231 #define MAKE_PREP_FUNC(myFunc, prep) \
0a4ce2086a88 util.encodings: Swap code order ("ifndef" bugs me)
Paul Aurich <paul@darkrain42.org>
parents: 4271
diff changeset
232 static int myFunc(lua_State *L) { return stringprep_prep(L, prep); }
0a4ce2086a88 util.encodings: Swap code order ("ifndef" bugs me)
Paul Aurich <paul@darkrain42.org>
parents: 4271
diff changeset
233
0a4ce2086a88 util.encodings: Swap code order ("ifndef" bugs me)
Paul Aurich <paul@darkrain42.org>
parents: 4271
diff changeset
234 MAKE_PREP_FUNC(Lstringprep_nameprep, stringprep_nameprep) /** stringprep.nameprep(s) */
0a4ce2086a88 util.encodings: Swap code order ("ifndef" bugs me)
Paul Aurich <paul@darkrain42.org>
parents: 4271
diff changeset
235 MAKE_PREP_FUNC(Lstringprep_nodeprep, stringprep_xmpp_nodeprep) /** stringprep.nodeprep(s) */
0a4ce2086a88 util.encodings: Swap code order ("ifndef" bugs me)
Paul Aurich <paul@darkrain42.org>
parents: 4271
diff changeset
236 MAKE_PREP_FUNC(Lstringprep_resourceprep, stringprep_xmpp_resourceprep) /** stringprep.resourceprep(s) */
0a4ce2086a88 util.encodings: Swap code order ("ifndef" bugs me)
Paul Aurich <paul@darkrain42.org>
parents: 4271
diff changeset
237 MAKE_PREP_FUNC(Lstringprep_saslprep, stringprep_saslprep) /** stringprep.saslprep(s) */
0a4ce2086a88 util.encodings: Swap code order ("ifndef" bugs me)
Paul Aurich <paul@darkrain42.org>
parents: 4271
diff changeset
238
0a4ce2086a88 util.encodings: Swap code order ("ifndef" bugs me)
Paul Aurich <paul@darkrain42.org>
parents: 4271
diff changeset
239 static const luaL_Reg Reg_stringprep[] =
766
433a5226267f Licensing/version updates for some files (forgot to commit, doh...)
Matthew Wild <mwild1@gmail.com>
parents: 601
diff changeset
240 {
4272
0a4ce2086a88 util.encodings: Swap code order ("ifndef" bugs me)
Paul Aurich <paul@darkrain42.org>
parents: 4271
diff changeset
241 { "nameprep", Lstringprep_nameprep },
0a4ce2086a88 util.encodings: Swap code order ("ifndef" bugs me)
Paul Aurich <paul@darkrain42.org>
parents: 4271
diff changeset
242 { "nodeprep", Lstringprep_nodeprep },
0a4ce2086a88 util.encodings: Swap code order ("ifndef" bugs me)
Paul Aurich <paul@darkrain42.org>
parents: 4271
diff changeset
243 { "resourceprep", Lstringprep_resourceprep },
0a4ce2086a88 util.encodings: Swap code order ("ifndef" bugs me)
Paul Aurich <paul@darkrain42.org>
parents: 4271
diff changeset
244 { "saslprep", Lstringprep_saslprep },
0a4ce2086a88 util.encodings: Swap code order ("ifndef" bugs me)
Paul Aurich <paul@darkrain42.org>
parents: 4271
diff changeset
245 { NULL, NULL }
0a4ce2086a88 util.encodings: Swap code order ("ifndef" bugs me)
Paul Aurich <paul@darkrain42.org>
parents: 4271
diff changeset
246 };
0a4ce2086a88 util.encodings: Swap code order ("ifndef" bugs me)
Paul Aurich <paul@darkrain42.org>
parents: 4271
diff changeset
247 #endif
0a4ce2086a88 util.encodings: Swap code order ("ifndef" bugs me)
Paul Aurich <paul@darkrain42.org>
parents: 4271
diff changeset
248
0a4ce2086a88 util.encodings: Swap code order ("ifndef" bugs me)
Paul Aurich <paul@darkrain42.org>
parents: 4271
diff changeset
249 /***************** IDNA *****************/
0a4ce2086a88 util.encodings: Swap code order ("ifndef" bugs me)
Paul Aurich <paul@darkrain42.org>
parents: 4271
diff changeset
250 #ifdef USE_STRINGPREP_ICU
3762
f02bac902a1e util.encodings: Support for ICU for IDNA operations.
Tobias Markmann <tm@ayena.de>
parents: 2923
diff changeset
251 #include <unicode/ustdio.h>
f02bac902a1e util.encodings: Support for ICU for IDNA operations.
Tobias Markmann <tm@ayena.de>
parents: 2923
diff changeset
252 #include <unicode/uidna.h>
f02bac902a1e util.encodings: Support for ICU for IDNA operations.
Tobias Markmann <tm@ayena.de>
parents: 2923
diff changeset
253 /* IDNA2003 or IDNA2008 ? ? ? */
f02bac902a1e util.encodings: Support for ICU for IDNA operations.
Tobias Markmann <tm@ayena.de>
parents: 2923
diff changeset
254 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
255 {
f02bac902a1e util.encodings: Support for ICU for IDNA operations.
Tobias Markmann <tm@ayena.de>
parents: 2923
diff changeset
256 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
257 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
258 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
259 UChar ustr[1024];
3762
f02bac902a1e util.encodings: Support for ICU for IDNA operations.
Tobias Markmann <tm@ayena.de>
parents: 2923
diff changeset
260 UErrorCode err = U_ZERO_ERROR;
f02bac902a1e util.encodings: Support for ICU for IDNA operations.
Tobias Markmann <tm@ayena.de>
parents: 2923
diff changeset
261 UChar dest[1024];
f02bac902a1e util.encodings: Support for ICU for IDNA operations.
Tobias Markmann <tm@ayena.de>
parents: 2923
diff changeset
262 char output[1024];
f02bac902a1e util.encodings: Support for ICU for IDNA operations.
Tobias Markmann <tm@ayena.de>
parents: 2923
diff changeset
263
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
264 u_strFromUTF8(ustr, 1024, &ulen, s, len, &err);
4273
7f789266b741 util.encodings: Check return values before proceeding
Paul Aurich <paul@darkrain42.org>
parents: 4272
diff changeset
265 if (U_FAILURE(err)) {
7f789266b741 util.encodings: Check return values before proceeding
Paul Aurich <paul@darkrain42.org>
parents: 4272
diff changeset
266 lua_pushnil(L);
7f789266b741 util.encodings: Check return values before proceeding
Paul Aurich <paul@darkrain42.org>
parents: 4272
diff changeset
267 return 1;
7f789266b741 util.encodings: Check return values before proceeding
Paul Aurich <paul@darkrain42.org>
parents: 4272
diff changeset
268 }
7f789266b741 util.encodings: Check return values before proceeding
Paul Aurich <paul@darkrain42.org>
parents: 4272
diff changeset
269
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
270 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
271 if (U_FAILURE(err)) {
f02bac902a1e util.encodings: Support for ICU for IDNA operations.
Tobias Markmann <tm@ayena.de>
parents: 2923
diff changeset
272 lua_pushnil(L);
f02bac902a1e util.encodings: Support for ICU for IDNA operations.
Tobias Markmann <tm@ayena.de>
parents: 2923
diff changeset
273 return 1;
f02bac902a1e util.encodings: Support for ICU for IDNA operations.
Tobias Markmann <tm@ayena.de>
parents: 2923
diff changeset
274 } 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
275 u_strToUTF8(output, 1024, &output_len, dest, dest_len, &err);
4273
7f789266b741 util.encodings: Check return values before proceeding
Paul Aurich <paul@darkrain42.org>
parents: 4272
diff changeset
276 if (U_SUCCESS(err) && output_len < 1024)
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
277 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
278 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
279 lua_pushnil(L);
3762
f02bac902a1e util.encodings: Support for ICU for IDNA operations.
Tobias Markmann <tm@ayena.de>
parents: 2923
diff changeset
280 return 1;
f02bac902a1e util.encodings: Support for ICU for IDNA operations.
Tobias Markmann <tm@ayena.de>
parents: 2923
diff changeset
281 }
f02bac902a1e util.encodings: Support for ICU for IDNA operations.
Tobias Markmann <tm@ayena.de>
parents: 2923
diff changeset
282 }
f02bac902a1e util.encodings: Support for ICU for IDNA operations.
Tobias Markmann <tm@ayena.de>
parents: 2923
diff changeset
283
f02bac902a1e util.encodings: Support for ICU for IDNA operations.
Tobias Markmann <tm@ayena.de>
parents: 2923
diff changeset
284 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
285 {
f02bac902a1e util.encodings: Support for ICU for IDNA operations.
Tobias Markmann <tm@ayena.de>
parents: 2923
diff changeset
286 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
287 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
288 const char *s = luaL_checklstring(L, 1, &len);
4271
18d888c8c12d util.encodings: Fix idna.to_unicode
Paul Aurich <paul@darkrain42.org>
parents: 3965
diff changeset
289 UChar ustr[1024];
3762
f02bac902a1e util.encodings: Support for ICU for IDNA operations.
Tobias Markmann <tm@ayena.de>
parents: 2923
diff changeset
290 UErrorCode err = U_ZERO_ERROR;
f02bac902a1e util.encodings: Support for ICU for IDNA operations.
Tobias Markmann <tm@ayena.de>
parents: 2923
diff changeset
291 UChar dest[1024];
f02bac902a1e util.encodings: Support for ICU for IDNA operations.
Tobias Markmann <tm@ayena.de>
parents: 2923
diff changeset
292 char output[1024];
f02bac902a1e util.encodings: Support for ICU for IDNA operations.
Tobias Markmann <tm@ayena.de>
parents: 2923
diff changeset
293
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
294 u_strFromUTF8(ustr, 1024, &ulen, s, len, &err);
4273
7f789266b741 util.encodings: Check return values before proceeding
Paul Aurich <paul@darkrain42.org>
parents: 4272
diff changeset
295 if (U_FAILURE(err)) {
7f789266b741 util.encodings: Check return values before proceeding
Paul Aurich <paul@darkrain42.org>
parents: 4272
diff changeset
296 lua_pushnil(L);
7f789266b741 util.encodings: Check return values before proceeding
Paul Aurich <paul@darkrain42.org>
parents: 4272
diff changeset
297 return 1;
7f789266b741 util.encodings: Check return values before proceeding
Paul Aurich <paul@darkrain42.org>
parents: 4272
diff changeset
298 }
7f789266b741 util.encodings: Check return values before proceeding
Paul Aurich <paul@darkrain42.org>
parents: 4272
diff changeset
299
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
300 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
301 if (U_FAILURE(err)) {
f02bac902a1e util.encodings: Support for ICU for IDNA operations.
Tobias Markmann <tm@ayena.de>
parents: 2923
diff changeset
302 lua_pushnil(L);
f02bac902a1e util.encodings: Support for ICU for IDNA operations.
Tobias Markmann <tm@ayena.de>
parents: 2923
diff changeset
303 return 1;
f02bac902a1e util.encodings: Support for ICU for IDNA operations.
Tobias Markmann <tm@ayena.de>
parents: 2923
diff changeset
304 } 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
305 u_strToUTF8(output, 1024, &output_len, dest, dest_len, &err);
4273
7f789266b741 util.encodings: Check return values before proceeding
Paul Aurich <paul@darkrain42.org>
parents: 4272
diff changeset
306 if (U_SUCCESS(err) && output_len < 1024)
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
307 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
308 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
309 lua_pushnil(L);
3762
f02bac902a1e util.encodings: Support for ICU for IDNA operations.
Tobias Markmann <tm@ayena.de>
parents: 2923
diff changeset
310 return 1;
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 }
4272
0a4ce2086a88 util.encodings: Swap code order ("ifndef" bugs me)
Paul Aurich <paul@darkrain42.org>
parents: 4271
diff changeset
313
0a4ce2086a88 util.encodings: Swap code order ("ifndef" bugs me)
Paul Aurich <paul@darkrain42.org>
parents: 4271
diff changeset
314 #else /* USE_STRINGPREP_ICU */
0a4ce2086a88 util.encodings: Swap code order ("ifndef" bugs me)
Paul Aurich <paul@darkrain42.org>
parents: 4271
diff changeset
315 /****************** libidn ********************/
0a4ce2086a88 util.encodings: Swap code order ("ifndef" bugs me)
Paul Aurich <paul@darkrain42.org>
parents: 4271
diff changeset
316
0a4ce2086a88 util.encodings: Swap code order ("ifndef" bugs me)
Paul Aurich <paul@darkrain42.org>
parents: 4271
diff changeset
317 #include <idna.h>
0a4ce2086a88 util.encodings: Swap code order ("ifndef" bugs me)
Paul Aurich <paul@darkrain42.org>
parents: 4271
diff changeset
318 #include <idn-free.h>
0a4ce2086a88 util.encodings: Swap code order ("ifndef" bugs me)
Paul Aurich <paul@darkrain42.org>
parents: 4271
diff changeset
319
0a4ce2086a88 util.encodings: Swap code order ("ifndef" bugs me)
Paul Aurich <paul@darkrain42.org>
parents: 4271
diff changeset
320 static int Lidna_to_ascii(lua_State *L) /** idna.to_ascii(s) */
0a4ce2086a88 util.encodings: Swap code order ("ifndef" bugs me)
Paul Aurich <paul@darkrain42.org>
parents: 4271
diff changeset
321 {
0a4ce2086a88 util.encodings: Swap code order ("ifndef" bugs me)
Paul Aurich <paul@darkrain42.org>
parents: 4271
diff changeset
322 size_t len;
0a4ce2086a88 util.encodings: Swap code order ("ifndef" bugs me)
Paul Aurich <paul@darkrain42.org>
parents: 4271
diff changeset
323 const char *s = luaL_checklstring(L, 1, &len);
0a4ce2086a88 util.encodings: Swap code order ("ifndef" bugs me)
Paul Aurich <paul@darkrain42.org>
parents: 4271
diff changeset
324 char* output = NULL;
0a4ce2086a88 util.encodings: Swap code order ("ifndef" bugs me)
Paul Aurich <paul@darkrain42.org>
parents: 4271
diff changeset
325 int ret = idna_to_ascii_8z(s, &output, IDNA_USE_STD3_ASCII_RULES);
0a4ce2086a88 util.encodings: Swap code order ("ifndef" bugs me)
Paul Aurich <paul@darkrain42.org>
parents: 4271
diff changeset
326 if (ret == IDNA_SUCCESS) {
0a4ce2086a88 util.encodings: Swap code order ("ifndef" bugs me)
Paul Aurich <paul@darkrain42.org>
parents: 4271
diff changeset
327 lua_pushstring(L, output);
0a4ce2086a88 util.encodings: Swap code order ("ifndef" bugs me)
Paul Aurich <paul@darkrain42.org>
parents: 4271
diff changeset
328 idn_free(output);
0a4ce2086a88 util.encodings: Swap code order ("ifndef" bugs me)
Paul Aurich <paul@darkrain42.org>
parents: 4271
diff changeset
329 return 1;
0a4ce2086a88 util.encodings: Swap code order ("ifndef" bugs me)
Paul Aurich <paul@darkrain42.org>
parents: 4271
diff changeset
330 } else {
0a4ce2086a88 util.encodings: Swap code order ("ifndef" bugs me)
Paul Aurich <paul@darkrain42.org>
parents: 4271
diff changeset
331 lua_pushnil(L);
0a4ce2086a88 util.encodings: Swap code order ("ifndef" bugs me)
Paul Aurich <paul@darkrain42.org>
parents: 4271
diff changeset
332 idn_free(output);
0a4ce2086a88 util.encodings: Swap code order ("ifndef" bugs me)
Paul Aurich <paul@darkrain42.org>
parents: 4271
diff changeset
333 return 1; /* TODO return error message */
0a4ce2086a88 util.encodings: Swap code order ("ifndef" bugs me)
Paul Aurich <paul@darkrain42.org>
parents: 4271
diff changeset
334 }
0a4ce2086a88 util.encodings: Swap code order ("ifndef" bugs me)
Paul Aurich <paul@darkrain42.org>
parents: 4271
diff changeset
335 }
0a4ce2086a88 util.encodings: Swap code order ("ifndef" bugs me)
Paul Aurich <paul@darkrain42.org>
parents: 4271
diff changeset
336
0a4ce2086a88 util.encodings: Swap code order ("ifndef" bugs me)
Paul Aurich <paul@darkrain42.org>
parents: 4271
diff changeset
337 static int Lidna_to_unicode(lua_State *L) /** idna.to_unicode(s) */
0a4ce2086a88 util.encodings: Swap code order ("ifndef" bugs me)
Paul Aurich <paul@darkrain42.org>
parents: 4271
diff changeset
338 {
0a4ce2086a88 util.encodings: Swap code order ("ifndef" bugs me)
Paul Aurich <paul@darkrain42.org>
parents: 4271
diff changeset
339 size_t len;
0a4ce2086a88 util.encodings: Swap code order ("ifndef" bugs me)
Paul Aurich <paul@darkrain42.org>
parents: 4271
diff changeset
340 const char *s = luaL_checklstring(L, 1, &len);
0a4ce2086a88 util.encodings: Swap code order ("ifndef" bugs me)
Paul Aurich <paul@darkrain42.org>
parents: 4271
diff changeset
341 char* output = NULL;
0a4ce2086a88 util.encodings: Swap code order ("ifndef" bugs me)
Paul Aurich <paul@darkrain42.org>
parents: 4271
diff changeset
342 int ret = idna_to_unicode_8z8z(s, &output, 0);
0a4ce2086a88 util.encodings: Swap code order ("ifndef" bugs me)
Paul Aurich <paul@darkrain42.org>
parents: 4271
diff changeset
343 if (ret == IDNA_SUCCESS) {
0a4ce2086a88 util.encodings: Swap code order ("ifndef" bugs me)
Paul Aurich <paul@darkrain42.org>
parents: 4271
diff changeset
344 lua_pushstring(L, output);
0a4ce2086a88 util.encodings: Swap code order ("ifndef" bugs me)
Paul Aurich <paul@darkrain42.org>
parents: 4271
diff changeset
345 idn_free(output);
0a4ce2086a88 util.encodings: Swap code order ("ifndef" bugs me)
Paul Aurich <paul@darkrain42.org>
parents: 4271
diff changeset
346 return 1;
0a4ce2086a88 util.encodings: Swap code order ("ifndef" bugs me)
Paul Aurich <paul@darkrain42.org>
parents: 4271
diff changeset
347 } else {
0a4ce2086a88 util.encodings: Swap code order ("ifndef" bugs me)
Paul Aurich <paul@darkrain42.org>
parents: 4271
diff changeset
348 lua_pushnil(L);
0a4ce2086a88 util.encodings: Swap code order ("ifndef" bugs me)
Paul Aurich <paul@darkrain42.org>
parents: 4271
diff changeset
349 idn_free(output);
0a4ce2086a88 util.encodings: Swap code order ("ifndef" bugs me)
Paul Aurich <paul@darkrain42.org>
parents: 4271
diff changeset
350 return 1; /* TODO return error message */
0a4ce2086a88 util.encodings: Swap code order ("ifndef" bugs me)
Paul Aurich <paul@darkrain42.org>
parents: 4271
diff changeset
351 }
0a4ce2086a88 util.encodings: Swap code order ("ifndef" bugs me)
Paul Aurich <paul@darkrain42.org>
parents: 4271
diff changeset
352 }
3762
f02bac902a1e util.encodings: Support for ICU for IDNA operations.
Tobias Markmann <tm@ayena.de>
parents: 2923
diff changeset
353 #endif
766
433a5226267f Licensing/version updates for some files (forgot to commit, doh...)
Matthew Wild <mwild1@gmail.com>
parents: 601
diff changeset
354
433a5226267f Licensing/version updates for some files (forgot to commit, doh...)
Matthew Wild <mwild1@gmail.com>
parents: 601
diff changeset
355 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
356 {
433a5226267f Licensing/version updates for some files (forgot to commit, doh...)
Matthew Wild <mwild1@gmail.com>
parents: 601
diff changeset
357 { "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
358 { "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
359 { NULL, NULL }
433a5226267f Licensing/version updates for some files (forgot to commit, doh...)
Matthew Wild <mwild1@gmail.com>
parents: 601
diff changeset
360 };
433a5226267f Licensing/version updates for some files (forgot to commit, doh...)
Matthew Wild <mwild1@gmail.com>
parents: 601
diff changeset
361
433a5226267f Licensing/version updates for some files (forgot to commit, doh...)
Matthew Wild <mwild1@gmail.com>
parents: 601
diff changeset
362 /***************** end *****************/
433a5226267f Licensing/version updates for some files (forgot to commit, doh...)
Matthew Wild <mwild1@gmail.com>
parents: 601
diff changeset
363
433a5226267f Licensing/version updates for some files (forgot to commit, doh...)
Matthew Wild <mwild1@gmail.com>
parents: 601
diff changeset
364 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
365 {
433a5226267f Licensing/version updates for some files (forgot to commit, doh...)
Matthew Wild <mwild1@gmail.com>
parents: 601
diff changeset
366 { NULL, NULL }
433a5226267f Licensing/version updates for some files (forgot to commit, doh...)
Matthew Wild <mwild1@gmail.com>
parents: 601
diff changeset
367 };
433a5226267f Licensing/version updates for some files (forgot to commit, doh...)
Matthew Wild <mwild1@gmail.com>
parents: 601
diff changeset
368
433a5226267f Licensing/version updates for some files (forgot to commit, doh...)
Matthew Wild <mwild1@gmail.com>
parents: 601
diff changeset
369 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
370 {
3762
f02bac902a1e util.encodings: Support for ICU for IDNA operations.
Tobias Markmann <tm@ayena.de>
parents: 2923
diff changeset
371 #ifdef USE_STRINGPREP_ICU
f02bac902a1e util.encodings: Support for ICU for IDNA operations.
Tobias Markmann <tm@ayena.de>
parents: 2923
diff changeset
372 init_icu();
f02bac902a1e util.encodings: Support for ICU for IDNA operations.
Tobias Markmann <tm@ayena.de>
parents: 2923
diff changeset
373 #endif
766
433a5226267f Licensing/version updates for some files (forgot to commit, doh...)
Matthew Wild <mwild1@gmail.com>
parents: 601
diff changeset
374 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
375
433a5226267f Licensing/version updates for some files (forgot to commit, doh...)
Matthew Wild <mwild1@gmail.com>
parents: 601
diff changeset
376 lua_pushliteral(L, "base64");
433a5226267f Licensing/version updates for some files (forgot to commit, doh...)
Matthew Wild <mwild1@gmail.com>
parents: 601
diff changeset
377 lua_newtable(L);
433a5226267f Licensing/version updates for some files (forgot to commit, doh...)
Matthew Wild <mwild1@gmail.com>
parents: 601
diff changeset
378 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
379 lua_settable(L,-3);
433a5226267f Licensing/version updates for some files (forgot to commit, doh...)
Matthew Wild <mwild1@gmail.com>
parents: 601
diff changeset
380
433a5226267f Licensing/version updates for some files (forgot to commit, doh...)
Matthew Wild <mwild1@gmail.com>
parents: 601
diff changeset
381 lua_pushliteral(L, "stringprep");
433a5226267f Licensing/version updates for some files (forgot to commit, doh...)
Matthew Wild <mwild1@gmail.com>
parents: 601
diff changeset
382 lua_newtable(L);
433a5226267f Licensing/version updates for some files (forgot to commit, doh...)
Matthew Wild <mwild1@gmail.com>
parents: 601
diff changeset
383 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
384 lua_settable(L,-3);
433a5226267f Licensing/version updates for some files (forgot to commit, doh...)
Matthew Wild <mwild1@gmail.com>
parents: 601
diff changeset
385
433a5226267f Licensing/version updates for some files (forgot to commit, doh...)
Matthew Wild <mwild1@gmail.com>
parents: 601
diff changeset
386 lua_pushliteral(L, "idna");
433a5226267f Licensing/version updates for some files (forgot to commit, doh...)
Matthew Wild <mwild1@gmail.com>
parents: 601
diff changeset
387 lua_newtable(L);
433a5226267f Licensing/version updates for some files (forgot to commit, doh...)
Matthew Wild <mwild1@gmail.com>
parents: 601
diff changeset
388 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
389 lua_settable(L,-3);
433a5226267f Licensing/version updates for some files (forgot to commit, doh...)
Matthew Wild <mwild1@gmail.com>
parents: 601
diff changeset
390
433a5226267f Licensing/version updates for some files (forgot to commit, doh...)
Matthew Wild <mwild1@gmail.com>
parents: 601
diff changeset
391 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
392 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
393 lua_settable(L,-3);
433a5226267f Licensing/version updates for some files (forgot to commit, doh...)
Matthew Wild <mwild1@gmail.com>
parents: 601
diff changeset
394 return 1;
433a5226267f Licensing/version updates for some files (forgot to commit, doh...)
Matthew Wild <mwild1@gmail.com>
parents: 601
diff changeset
395 }