Software /
code /
prosody
Comparison
util-src/encodings.c @ 4033:17e299137287
util.encodings: Switch comment styles to build ok as ANSI C
author | Matthew Wild <mwild1@gmail.com> |
---|---|
date | Sun, 26 Dec 2010 05:45:35 +0000 |
parent | 3888:8e98ad57fcbb |
child | 4271:18d888c8c12d |
comparison
equal
deleted
inserted
replaced
4032:ee7f2aa5dc3b | 4033:17e299137287 |
---|---|
10 /* | 10 /* |
11 * encodings.c | 11 * encodings.c |
12 * Lua library for base64, stringprep and idna encodings | 12 * Lua library for base64, stringprep and idna encodings |
13 */ | 13 */ |
14 | 14 |
15 // Newer MSVC compilers deprecate strcpy as unsafe, but we use it in a safe way | 15 /* Newer MSVC compilers deprecate strcpy as unsafe, but we use it in a safe way */ |
16 #define _CRT_SECURE_NO_DEPRECATE | 16 #define _CRT_SECURE_NO_DEPRECATE |
17 | 17 |
18 #include <string.h> | 18 #include <string.h> |
19 #include <stdlib.h> | 19 #include <stdlib.h> |
20 #include "lua.h" | 20 #include "lua.h" |
133 return 1; | 133 return 1; |
134 } | 134 } |
135 s = lua_tolstring(L, 1, &len); | 135 s = lua_tolstring(L, 1, &len); |
136 if (len >= 1024) { | 136 if (len >= 1024) { |
137 lua_pushnil(L); | 137 lua_pushnil(L); |
138 return 1; // TODO return error message | 138 return 1; /* TODO return error message */ |
139 } | 139 } |
140 strcpy(string, s); | 140 strcpy(string, s); |
141 ret = stringprep(string, 1024, (Stringprep_profile_flags)0, profile); | 141 ret = stringprep(string, 1024, (Stringprep_profile_flags)0, profile); |
142 if (ret == STRINGPREP_OK) { | 142 if (ret == STRINGPREP_OK) { |
143 lua_pushstring(L, string); | 143 lua_pushstring(L, string); |
144 return 1; | 144 return 1; |
145 } else { | 145 } else { |
146 lua_pushnil(L); | 146 lua_pushnil(L); |
147 return 1; // TODO return error message | 147 return 1; /* TODO return error message */ |
148 } | 148 } |
149 } | 149 } |
150 | 150 |
151 #define MAKE_PREP_FUNC(myFunc, prep) \ | 151 #define MAKE_PREP_FUNC(myFunc, prep) \ |
152 static int myFunc(lua_State *L) { return stringprep_prep(L, prep); } | 152 static int myFunc(lua_State *L) { return stringprep_prep(L, prep); } |
259 idn_free(output); | 259 idn_free(output); |
260 return 1; | 260 return 1; |
261 } else { | 261 } else { |
262 lua_pushnil(L); | 262 lua_pushnil(L); |
263 idn_free(output); | 263 idn_free(output); |
264 return 1; // TODO return error message | 264 return 1; /* TODO return error message */ |
265 } | 265 } |
266 } | 266 } |
267 | 267 |
268 static int Lidna_to_unicode(lua_State *L) /** idna.to_unicode(s) */ | 268 static int Lidna_to_unicode(lua_State *L) /** idna.to_unicode(s) */ |
269 { | 269 { |
276 idn_free(output); | 276 idn_free(output); |
277 return 1; | 277 return 1; |
278 } else { | 278 } else { |
279 lua_pushnil(L); | 279 lua_pushnil(L); |
280 idn_free(output); | 280 idn_free(output); |
281 return 1; // TODO return error message | 281 return 1; /* TODO return error message */ |
282 } | 282 } |
283 } | 283 } |
284 #else | 284 #else |
285 #include <unicode/ustdio.h> | 285 #include <unicode/ustdio.h> |
286 #include <unicode/uidna.h> | 286 #include <unicode/uidna.h> |