aboutsummaryrefslogtreecommitdiff
path: root/src/ssl.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/ssl.c')
-rw-r--r--src/ssl.c70
1 files changed, 70 insertions, 0 deletions
diff --git a/src/ssl.c b/src/ssl.c
new file mode 100644
index 0000000..8e2ce00
--- /dev/null
+++ b/src/ssl.c
@@ -0,0 +1,70 @@
1/*=========================================================================*\
2* Simple client SSL support
3* LuaSocket toolkit
4*
5* RCS ID: $Id$
6\*=========================================================================*/
7#include <lua.h>
8#include <lauxlib.h>
9
10#include "ssl.h"
11
12/*=========================================================================*\
13* Internal function prototypes
14\*=========================================================================*/
15static int global_wrap(lua_State *L);
16
17/* functions in library namespace */
18static luaL_reg func[] = {
19 {"wrap", global_create},
20 {NULL, NULL}
21};
22
23static luaL_reg wrap[] = {
24 {"__tostring", aux_tostring},
25 {"__gc", meth_close},
26 {"close", meth_close},
27 {"receive", meth_receive},
28 {"send", meth_send},
29 {NULL, NULL}
30};
31
32static luaL_reg owned[] = {
33 {"__tostring", aux_tostring},
34 {NULL, NULL}
35};
36
37/*-------------------------------------------------------------------------*\
38* Initializes module
39\*-------------------------------------------------------------------------*/
40int ssl_open(lua_State *L)
41{
42 aux_newclass(L, "ssl{wraper}", wrap);
43 aux_newclass(L, "ssl{owned}", owned);
44 lua_pushstring(L, "ssl")
45 lua_newtable(L);
46 luaL_openlib(L, NULL, func, 0);
47 lua_settable(L, -3);
48 return 0;
49}
50
51/*=========================================================================*\
52* Library functions
53\*=========================================================================*/
54/*-------------------------------------------------------------------------*\
55* Wraps a tcp object into an SSL object
56\*-------------------------------------------------------------------------*/
57static int global_wrap(lua_State *L) {
58 p_tcp tcp = (p_tcp) aux_checkclass(L, "tcp{client}", 1);
59 /* change class of tcp object */
60 aux_setclass(L, "ssl{owned}", 1);
61 /* create wrapper */
62 p_wrap wrap = (p_wrap) lua_newuserdata(L, sizeof(t_wrap));
63 /* lock reference */
64 lua_pushvalue(L, 1);
65 wrap->ref = lua_ref(L, 1);
66 /* initialize wrapper */
67 wrap->tcp = tcp;
68 io_init(&tcp->io, wrap_send, wrap_recv, wrap);
69 return 1;
70}