44 { NULL, 0 }, // XXX |
44 { NULL, 0 }, // XXX |
45 }; |
45 }; |
46 |
46 |
47 /// ssl callback function |
47 /// ssl callback function |
48 /// User function, called when ssl error happens. |
48 /// User function, called when ssl error happens. |
49 /// XXX: add lm connection object to args? it is not in API, but can be useful, |
49 /// A: userdata (lm ssl object), argument enum field (ssl status) |
50 /// though, with upvalues it is not required. |
|
51 /// A: lm ssl object, ssl status |
|
52 /// R: boolean (false if connection process should be terminated) |
50 /// R: boolean (false if connection process should be terminated) |
53 LmSSLResponse callback_lm_ssl (LmSSL *ssl, LmSSLStatus status, llm_callback_t *cb) |
51 LmSSLResponse callback_lm_ssl (LmSSL *ssl, LmSSLStatus status, llm_callback_t *cb) |
54 { |
52 { |
55 int ret; |
53 int ret; |
56 lua_rawgeti (cb->L, LUA_REGISTRYINDEX, cb->reference); |
54 lua_rawgeti (cb->L, LUA_REGISTRYINDEX, cb->reference); |
57 bless_lm_ssl (cb->L, ssl); |
55 bless_lm_ssl (cb->L, ssl); |
58 // XXX lm_ssl_unref (ssl); |
56 // XXX lm_ssl_unref (ssl); |
59 luaL_pushenum (cb->L, status, status_lm_ssl); |
57 luaL_pushenum (cb->L, status, status_lm_ssl); |
60 if (lua_pcall (cb->L, 2, 0, 0)) { |
58 if (lua_pcall (cb->L, 2, 1, 0)) { |
61 W ("SSL callback error: %s", lua_tostring (cb->L, -1)); |
59 W ("SSL callback error: %s", lua_tostring (cb->L, -1)); |
62 lua_pop (cb->L, 1); |
60 lua_pop (cb->L, 1); |
63 return LM_SSL_RESPONSE_CONTINUE; |
61 return LM_SSL_RESPONSE_CONTINUE; |
64 } |
62 } |
65 ret = lua_toboolean (cb->L, -1); |
63 ret = lua_toboolean (cb->L, -1); |
84 /// Creates new ssl object for use with connection. |
82 /// Creates new ssl object for use with connection. |
85 /// You can specify server key fingerprint, callback function for error handling, |
83 /// You can specify server key fingerprint, callback function for error handling, |
86 /// both, or neither. Though, fingerprint should go before callback function. |
84 /// both, or neither. Though, fingerprint should go before callback function. |
87 /// SSL fingerprint is a string like '01:23:45:67:89:AB:CD:EF:FE:DC:BA:98:76:54:32:10'. |
85 /// SSL fingerprint is a string like '01:23:45:67:89:AB:CD:EF:FE:DC:BA:98:76:54:32:10'. |
88 /// A: string (optional ssl fingerprint), ssl callback function (optional) |
86 /// A: string (optional ssl fingerprint), ssl callback function (optional) |
89 /// R: lm ssl object |
87 /// R: userdata (lm ssl object) |
90 static int new_lm_ssl (lua_State *L) |
88 static int new_lm_ssl (lua_State *L) |
91 { |
89 { |
92 int args = lua_gettop (L); |
90 int args = lua_gettop (L); |
93 LmSSL *ssl; |
91 LmSSL *ssl; |
94 if (args == 0) |
92 if (args == 0) |
126 } |
124 } |
127 |
125 |
128 /// lm.ssl.bless |
126 /// lm.ssl.bless |
129 /// Blesses given pointer to lm ssl object. |
127 /// Blesses given pointer to lm ssl object. |
130 /// A: lightuserdata (C lm ssl object) |
128 /// A: lightuserdata (C lm ssl object) |
131 /// R: lm ssl object |
129 /// R: userdata (lm ssl object) |
132 static int bless_lua_lm_ssl (lua_State *L) |
130 static int bless_lua_lm_ssl (lua_State *L) |
133 { |
131 { |
134 luaL_argcheck (L, lua_islightuserdata (L, 1), 1, "lm ssl lightuserdata expected"); |
132 luaL_argcheck (L, lua_islightuserdata (L, 1), 1, "lm ssl lightuserdata expected"); |
135 bless_lm_ssl (L, lua_touserdata (L, 1)); |
133 bless_lm_ssl (L, lua_touserdata (L, 1)); |
136 return 1; |
134 return 1; |
166 lua_pushlstring (L, buffer, 47); |
164 lua_pushlstring (L, buffer, 47); |
167 } |
165 } |
168 return 1; |
166 return 1; |
169 } |
167 } |
170 |
168 |
|
169 /// ssl:tls |
|
170 /// Sets or returns use of starttls by this ssl object. |
|
171 /// A: boolean (use starttls), boolean (require starttls) |
|
172 /// or |
|
173 /// R: boolean (use starttls), boolean (require starttls) |
|
174 static int tls_lm_ssl (lua_State *L) |
|
175 { |
|
176 llm_ssl_t *object = luaL_checklm_ssl (L, 1); |
|
177 if (lua_gettop (L) > 1) { |
|
178 gboolean use = lua_toboolean (L, 2); |
|
179 gboolean require = lua_toboolean (L, 3); |
|
180 lm_ssl_use_starttls (object -> ssl, use, require); |
|
181 return 0; |
|
182 } else { |
|
183 lua_pushboolean (L, lm_ssl_get_use_starttls (object -> ssl)); |
|
184 lua_pushboolean (L, lm_ssl_get_require_starttls (object -> ssl)); |
|
185 return 2; |
|
186 } |
|
187 } |
|
188 |
171 /// ssl:pointer |
189 /// ssl:pointer |
172 /// Returns pointer to underlying C structure. |
190 /// Returns pointer to underlying C structure. |
173 /// R: lightuserdata |
191 /// R: lightuserdata |
174 static int pointer_lm_ssl (lua_State *L) |
192 static int pointer_lm_ssl (lua_State *L) |
175 { |
193 { |
193 { NULL, NULL }, |
211 { NULL, NULL }, |
194 }; |
212 }; |
195 |
213 |
196 const static luaL_Reg reg_m_lm_ssl[] = { |
214 const static luaL_Reg reg_m_lm_ssl[] = { |
197 { "fingerprint", fingerprint_lm_ssl }, |
215 { "fingerprint", fingerprint_lm_ssl }, |
|
216 { "tls", tls_lm_ssl }, |
198 { "pointer", pointer_lm_ssl }, |
217 { "pointer", pointer_lm_ssl }, |
199 { "__gc", gc_lm_ssl }, |
218 { "__gc", gc_lm_ssl }, |
200 { NULL, NULL }, |
219 { NULL, NULL }, |
201 }; |
220 }; |
202 |
221 |