@@ -94,10 +94,13 @@ int lcurl_easy_create(lua_State *L, int error_mode){
94
94
p -> match .cb_ref = p -> match .ud_ref = LUA_NOREF ;
95
95
p -> chunk_bgn .cb_ref = p -> chunk_bgn .ud_ref = LUA_NOREF ;
96
96
p -> chunk_end .cb_ref = p -> chunk_end .ud_ref = LUA_NOREF ;
97
+ #if LCURL_CURL_VER_GE (7 ,19 ,6 )
98
+ p -> ssh_key .cb_ref = p -> ssh_key .ud_ref = LUA_NOREF ;
99
+ #endif
97
100
#if LCURL_CURL_VER_GE (7 ,64 ,0 )
98
101
p -> trailer .cb_ref = p -> trailer .ud_ref = LUA_NOREF ;
99
102
#endif
100
- #if LCURL_CURL_VER_GE (7 ,74 ,0 )
103
+ #if LCURL_CURL_VER_GE (7 ,74 ,0 ) && LCURL_USE_HSTS
101
104
p -> hstsread .cb_ref = p -> hstsread .ud_ref = LUA_NOREF ;
102
105
p -> hstswrite .cb_ref = p -> hstswrite .ud_ref = LUA_NOREF ;
103
106
#endif
@@ -155,11 +158,15 @@ static int lcurl_easy_cleanup_storage(lua_State *L, lcurl_easy_t *p){
155
158
luaL_unref (L , LCURL_LUA_REGISTRY , p -> chunk_bgn .ud_ref );
156
159
luaL_unref (L , LCURL_LUA_REGISTRY , p -> chunk_end .cb_ref );
157
160
luaL_unref (L , LCURL_LUA_REGISTRY , p -> chunk_end .ud_ref );
161
+ #if LCURL_CURL_VER_GE (7 ,19 ,6 )
162
+ luaL_unref (L , LCURL_LUA_REGISTRY , p -> ssh_key .cb_ref );
163
+ luaL_unref (L , LCURL_LUA_REGISTRY , p -> ssh_key .ud_ref );
164
+ #endif
158
165
#if LCURL_CURL_VER_GE (7 ,64 ,0 )
159
166
luaL_unref (L , LCURL_LUA_REGISTRY , p -> trailer .cb_ref );
160
167
luaL_unref (L , LCURL_LUA_REGISTRY , p -> trailer .ud_ref );
161
168
#endif
162
- #if LCURL_CURL_VER_GE (7 ,74 ,0 )
169
+ #if LCURL_CURL_VER_GE (7 ,74 ,0 ) && LCURL_USE_HSTS
163
170
luaL_unref (L , LCURL_LUA_REGISTRY , p -> hstsread .cb_ref );
164
171
luaL_unref (L , LCURL_LUA_REGISTRY , p -> hstsread .ud_ref );
165
172
luaL_unref (L , LCURL_LUA_REGISTRY , p -> hstswrite .cb_ref );
@@ -178,10 +185,13 @@ static int lcurl_easy_cleanup_storage(lua_State *L, lcurl_easy_t *p){
178
185
p -> match .cb_ref = p -> match .ud_ref = LUA_NOREF ;
179
186
p -> chunk_bgn .cb_ref = p -> chunk_bgn .ud_ref = LUA_NOREF ;
180
187
p -> chunk_end .cb_ref = p -> chunk_end .ud_ref = LUA_NOREF ;
188
+ #if LCURL_CURL_VER_GE (7 ,19 ,6 )
189
+ p -> ssh_key .cb_ref = p -> ssh_key .ud_ref = LUA_NOREF ;
190
+ #endif
181
191
#if LCURL_CURL_VER_GE (7 ,64 ,0 )
182
192
p -> trailer .cb_ref = p -> trailer .ud_ref = LUA_NOREF ;
183
193
#endif
184
- #if LCURL_CURL_VER_GE (7 ,74 ,0 )
194
+ #if LCURL_CURL_VER_GE (7 ,74 ,0 ) && LCURL_USE_HSTS
185
195
p -> hstsread .cb_ref = p -> hstsread .ud_ref = LUA_NOREF ;
186
196
p -> hstswrite .cb_ref = p -> hstswrite .ud_ref = LUA_NOREF ;
187
197
#endif
@@ -897,6 +907,27 @@ static int lcurl_easy_unset_DEBUGFUNCTION(lua_State *L){
897
907
return 1 ;
898
908
}
899
909
910
+ #if LCURL_CURL_VER_GE (7 ,19 ,6 )
911
+
912
+ static int lcurl_easy_unset_SSH_KEYFUNCTION (lua_State * L ){
913
+ lcurl_easy_t * p = lcurl_geteasy (L );
914
+
915
+ CURLcode code = curl_easy_setopt (p -> curl , CURLOPT_SSH_KEYFUNCTION , NULL );
916
+ if (code != CURLE_OK ){
917
+ return lcurl_fail_ex (L , p -> err_mode , LCURL_ERROR_EASY , code );
918
+ }
919
+ curl_easy_setopt (p -> curl , CURLOPT_SSH_KEYDATA , NULL );
920
+
921
+ luaL_unref (L , LCURL_LUA_REGISTRY , p -> ssh_key .cb_ref );
922
+ luaL_unref (L , LCURL_LUA_REGISTRY , p -> ssh_key .ud_ref );
923
+ p -> ssh_key .cb_ref = p -> ssh_key .ud_ref = LUA_NOREF ;
924
+
925
+ lua_settop (L , 1 );
926
+ return 1 ;
927
+ }
928
+
929
+ #endif
930
+
900
931
#if LCURL_CURL_VER_GE (7 ,21 ,0 )
901
932
902
933
static int lcurl_easy_unset_FNMATCH_FUNCTION (lua_State * L ){
@@ -935,6 +966,7 @@ static int lcurl_easy_unset_CHUNK_BGN_FUNCTION(lua_State *L){
935
966
lua_settop (L , 1 );
936
967
return 1 ;
937
968
}
969
+
938
970
static int lcurl_easy_unset_CHUNK_END_FUNCTION (lua_State * L ){
939
971
lcurl_easy_t * p = lcurl_geteasy (L );
940
972
@@ -1046,7 +1078,7 @@ static int lcurl_easy_unset_TRAILERFUNCTION(lua_State *L){
1046
1078
1047
1079
#endif
1048
1080
1049
- #if LCURL_CURL_VER_GE (7 ,74 ,0 )
1081
+ #if LCURL_CURL_VER_GE (7 ,74 ,0 ) && LCURL_USE_HSTS
1050
1082
1051
1083
static int lcurl_easy_unset_HSTSREADFUNCTION (lua_State * L ){
1052
1084
lcurl_easy_t * p = lcurl_geteasy (L );
@@ -1818,7 +1850,7 @@ static int lcurl_easy_set_TRAILERFUNCTION (lua_State *L){
1818
1850
1819
1851
//{ HSTS Reader
1820
1852
1821
- #if LCURL_CURL_VER_GE (7 ,74 ,0 )
1853
+ #if LCURL_CURL_VER_GE (7 ,74 ,0 ) && LCURL_USE_HSTS
1822
1854
1823
1855
#define LCURL_HSTS_EXPIRE_LEN 18
1824
1856
@@ -1924,7 +1956,7 @@ static int lcurl_easy_set_HSTSREADFUNCTION(lua_State *L){
1924
1956
1925
1957
//{ HSTS Writer
1926
1958
1927
- #if LCURL_CURL_VER_GE (7 ,74 ,0 )
1959
+ #if LCURL_CURL_VER_GE (7 ,74 ,0 ) && LCURL_USE_HSTS
1928
1960
1929
1961
static int lcurl_hstswrite_callback (CURL * easy , struct curl_hstsentry * sts , struct curl_index * count , void * arg ) {
1930
1962
lcurl_easy_t * p = arg ;
@@ -1996,6 +2028,87 @@ static int lcurl_easy_set_HSTSWRITEFUNCTION(lua_State *L){
1996
2028
1997
2029
//}
1998
2030
2031
+ //{ SSH key
2032
+
2033
+ #if LCURL_CURL_VER_GE (7 ,19 ,6 )
2034
+
2035
+ static void lcurl_ssh_key_push (lua_State * L , const struct curl_khkey * key ){
2036
+ if (!key ) {
2037
+ lua_pushnil (L );
2038
+ return ;
2039
+ }
2040
+
2041
+ lua_newtable (L );
2042
+
2043
+ if (key -> len ){
2044
+ lua_pushliteral (L , "raw" );
2045
+ lua_pushlstring (L , key -> key , key -> len );
2046
+ } else {
2047
+ lua_pushliteral (L , "base64" );
2048
+ lua_pushstring (L , key -> key );
2049
+ }
2050
+ lua_rawset (L , -3 );
2051
+
2052
+ lua_pushliteral (L , "type" );
2053
+ lutil_pushuint (L , key -> keytype );
2054
+ lua_rawset (L , -3 );
2055
+ }
2056
+
2057
+ static int lcurl_ssh_key_callback (
2058
+ CURL * easy ,
2059
+ const struct curl_khkey * knownkey ,
2060
+ const struct curl_khkey * foundkey ,
2061
+ enum curl_khmatch khmatch ,
2062
+ void * arg
2063
+ ) {
2064
+ lcurl_easy_t * p = arg ;
2065
+ lua_State * L = p -> L ;
2066
+ int top = lua_gettop (L );
2067
+ int n = lcurl_util_push_cb (L , & p -> ssh_key );
2068
+
2069
+ assert (NULL != p -> L );
2070
+
2071
+ lcurl_ssh_key_push (L , knownkey );
2072
+ lcurl_ssh_key_push (L , foundkey );
2073
+ lutil_pushuint (L , khmatch );
2074
+
2075
+ if (lua_pcall (L , n + 2 , LUA_MULTRET , 0 )) {
2076
+ assert (lua_gettop (L ) >= top );
2077
+ lua_pushlightuserdata (L , (void * )LCURL_ERROR_TAG );
2078
+ lua_insert (L , top + 1 );
2079
+ return CURLKHSTAT_REJECT ;
2080
+ }
2081
+
2082
+ if (lua_gettop (L ) > top ) {
2083
+ int ret = lua_tointeger (L , top + 1 );
2084
+ lua_settop (L , top );
2085
+
2086
+ switch (ret )
2087
+ #if LCURL_CURL_VER_GE (7 ,73 ,0 )
2088
+ case CURLKHSTAT_FINE_REPLACE :
2089
+ #endif
2090
+ case CURLKHSTAT_FINE_ADD_TO_FILE :
2091
+ case CURLKHSTAT_FINE :
2092
+ case CURLKHSTAT_REJECT :
2093
+ case CURLKHSTAT_DEFER :
2094
+ return ret ;
2095
+ }
2096
+
2097
+ return CURLKHSTAT_REJECT ;
2098
+ }
2099
+
2100
+ static int lcurl_easy_set_SSH_KEYFUNCTION (lua_State * L ){
2101
+ lcurl_easy_t * p = lcurl_geteasy (L );
2102
+ return lcurl_easy_set_callback (L , p , & p -> ssh_key ,
2103
+ CURLOPT_SSH_KEYFUNCTION , CURLOPT_SSH_KEYDATA ,
2104
+ "ssh_key" , lcurl_ssh_key_callback
2105
+ );
2106
+ }
2107
+
2108
+ #endif
2109
+
2110
+ //}
2111
+
1999
2112
static int lcurl_easy_setopt (lua_State * L ){
2000
2113
lcurl_easy_t * p = lcurl_geteasy (L );
2001
2114
long opt ;
@@ -2023,8 +2136,11 @@ static int lcurl_easy_setopt(lua_State *L){
2023
2136
OPT_ENTRY (progressfunction , PROGRESSFUNCTION , TTT , 0 , 0 )
2024
2137
OPT_ENTRY (seekfunction , SEEKFUNCTION , TTT , 0 , 0 )
2025
2138
OPT_ENTRY (debugfunction , DEBUGFUNCTION , TTT , 0 , 0 )
2139
+ #if LCURL_CURL_VER_GE (7 ,19 ,6 )
2140
+ OPT_ENTRY (ssh_keyfunction , SSH_KEYFUNCTION , TTT , 0 , 0 )
2141
+ #endif
2026
2142
#if LCURL_CURL_VER_GE (7 ,21 ,0 )
2027
- OPT_ENTRY (fnmatch_function , FNMATCH_FUNCTION , TTT , 0 , 0 )
2143
+ OPT_ENTRY (fnmatch_function , FNMATCH_FUNCTION , TTT , 0 , 0 )
2028
2144
OPT_ENTRY (chunk_bgn_function , CHUNK_BGN_FUNCTION , TTT , 0 , 0 )
2029
2145
OPT_ENTRY (chunk_end_function , CHUNK_END_FUNCTION , TTT , 0 , 0 )
2030
2146
#endif
@@ -2034,6 +2150,16 @@ static int lcurl_easy_setopt(lua_State *L){
2034
2150
#endif
2035
2151
#if LCURL_CURL_VER_GE (7 ,56 ,0 )
2036
2152
OPT_ENTRY (mimepost , MIMEPOST , TTT , 0 , 0 )
2153
+ #endif
2154
+ #if LCURL_CURL_VER_GE (7 ,63 ,0 )
2155
+ OPT_ENTRY (curlu , CURLU , TTT , 0 , 0 )
2156
+ #endif
2157
+ #if LCURL_CURL_VER_GE (7 ,64 ,0 )
2158
+ OPT_ENTRY (trailerfunction , TRAILERFUNCTION , TTT , 0 , 0 )
2159
+ #endif
2160
+ #if LCURL_CURL_VER_GE (7 ,74 ,0 ) && LCURL_USE_HSTS
2161
+ OPT_ENTRY (hstsreadfunction , HSTSREADFUNCTION , TTT , 0 , 0 )
2162
+ OPT_ENTRY (hstswritefunction , HSTSWRITEFUNCTION ,TTT , 0 , 0 )
2037
2163
#endif
2038
2164
}
2039
2165
#undef OPT_ENTRY
@@ -2060,8 +2186,11 @@ static int lcurl_easy_unsetopt(lua_State *L){
2060
2186
OPT_ENTRY (progressfunction , PROGRESSFUNCTION , TTT , 0 , 0 )
2061
2187
OPT_ENTRY (seekfunction , SEEKFUNCTION , TTT , 0 , 0 )
2062
2188
OPT_ENTRY (debugfunction , DEBUGFUNCTION , TTT , 0 , 0 )
2189
+ #if LCURL_CURL_VER_GE (7 ,19 ,6 )
2190
+ OPT_ENTRY (ssh_keyfunction , SSH_KEYFUNCTION , TTT , 0 , 0 )
2191
+ #endif
2063
2192
#if LCURL_CURL_VER_GE (7 ,21 ,0 )
2064
- OPT_ENTRY (fnmatch_function , FNMATCH_FUNCTION , TTT , 0 , 0 )
2193
+ OPT_ENTRY (fnmatch_function , FNMATCH_FUNCTION , TTT , 0 , 0 )
2065
2194
OPT_ENTRY (chunk_bgn_function , CHUNK_BGN_FUNCTION , TTT , 0 , 0 )
2066
2195
OPT_ENTRY (chunk_end_function , CHUNK_END_FUNCTION , TTT , 0 , 0 )
2067
2196
#endif
@@ -2071,6 +2200,16 @@ static int lcurl_easy_unsetopt(lua_State *L){
2071
2200
#endif
2072
2201
#if LCURL_CURL_VER_GE (7 ,56 ,0 )
2073
2202
OPT_ENTRY (mimepost , MIMEPOST , TTT , 0 , 0 )
2203
+ #endif
2204
+ #if LCURL_CURL_VER_GE (7 ,63 ,0 )
2205
+ OPT_ENTRY (curlu , CURLU , TTT , 0 , 0 )
2206
+ #endif
2207
+ #if LCURL_CURL_VER_GE (7 ,64 ,0 )
2208
+ OPT_ENTRY (trailerfunction , TRAILERFUNCTION , TTT , 0 , 0 )
2209
+ #endif
2210
+ #if LCURL_CURL_VER_GE (7 ,74 ,0 ) && LCURL_USE_HSTS
2211
+ OPT_ENTRY (hstsreadfunction , HSTSREADFUNCTION , TTT , 0 , 0 )
2212
+ OPT_ENTRY (hstswritefunction , HSTSWRITEFUNCTION ,TTT , 0 , 0 )
2074
2213
#endif
2075
2214
}
2076
2215
#undef OPT_ENTRY
@@ -2141,6 +2280,9 @@ static const struct luaL_Reg lcurl_easy_methods[] = {
2141
2280
OPT_ENTRY (progressfunction , PROGRESSFUNCTION , TTT , 0 , 0 )
2142
2281
OPT_ENTRY (seekfunction , SEEKFUNCTION , TTT , 0 , 0 )
2143
2282
OPT_ENTRY (debugfunction , DEBUGFUNCTION , TTT , 0 , 0 )
2283
+ #if LCURL_CURL_VER_GE (7 ,19 ,6 )
2284
+ OPT_ENTRY (ssh_keyfunction , SSH_KEYFUNCTION , TTT , 0 , 0 )
2285
+ #endif
2144
2286
#if LCURL_CURL_VER_GE (7 ,21 ,0 )
2145
2287
OPT_ENTRY (fnmatch_function , FNMATCH_FUNCTION , TTT , 0 , 0 )
2146
2288
OPT_ENTRY (chunk_bgn_function , CHUNK_BGN_FUNCTION , TTT , 0 , 0 )
@@ -2159,7 +2301,7 @@ static const struct luaL_Reg lcurl_easy_methods[] = {
2159
2301
#if LCURL_CURL_VER_GE (7 ,64 ,0 )
2160
2302
OPT_ENTRY (trailerfunction , TRAILERFUNCTION , TTT , 0 , 0 )
2161
2303
#endif
2162
- #if LCURL_CURL_VER_GE (7 ,74 ,0 )
2304
+ #if LCURL_CURL_VER_GE (7 ,74 ,0 ) && LCURL_USE_HSTS
2163
2305
OPT_ENTRY (hstsreadfunction , HSTSREADFUNCTION , TTT , 0 , 0 )
2164
2306
OPT_ENTRY (hstswritefunction , HSTSWRITEFUNCTION ,TTT , 0 , 0 )
2165
2307
#endif
@@ -2176,6 +2318,9 @@ static const struct luaL_Reg lcurl_easy_methods[] = {
2176
2318
OPT_ENTRY (progressfunction , PROGRESSFUNCTION , TTT , 0 , 0 )
2177
2319
OPT_ENTRY (seekfunction , SEEKFUNCTION , TTT , 0 , 0 )
2178
2320
OPT_ENTRY (debugfunction , DEBUGFUNCTION , TTT , 0 , 0 )
2321
+ #if LCURL_CURL_VER_GE (7 ,19 ,6 )
2322
+ OPT_ENTRY (ssh_keyfunction , SSH_KEYFUNCTION , TTT , 0 , 0 )
2323
+ #endif
2179
2324
#if LCURL_CURL_VER_GE (7 ,21 ,0 )
2180
2325
OPT_ENTRY (fnmatch_function , FNMATCH_FUNCTION , TTT , 0 , 0 )
2181
2326
OPT_ENTRY (chunk_bgn_function , CHUNK_BGN_FUNCTION , TTT , 0 , 0 )
@@ -2194,7 +2339,7 @@ static const struct luaL_Reg lcurl_easy_methods[] = {
2194
2339
#if LCURL_CURL_VER_GE (7 ,64 ,0 )
2195
2340
OPT_ENTRY (trailerfunction , TRAILERFUNCTION , TTT , 0 , 0 )
2196
2341
#endif
2197
- #if LCURL_CURL_VER_GE (7 ,74 ,0 )
2342
+ #if LCURL_CURL_VER_GE (7 ,74 ,0 ) && LCURL_USE_HSTS
2198
2343
OPT_ENTRY (hstsreadfunction , HSTSREADFUNCTION , TTT , 0 , 0 )
2199
2344
OPT_ENTRY (hstswritefunction , HSTSWRITEFUNCTION ,TTT , 0 , 0 )
2200
2345
#endif
@@ -2243,8 +2388,11 @@ static const lcurl_const_t lcurl_easy_opt[] = {
2243
2388
OPT_ENTRY (progressfunction , PROGRESSFUNCTION , TTT , 0 , 0 )
2244
2389
OPT_ENTRY (seekfunction , SEEKFUNCTION , TTT , 0 , 0 )
2245
2390
OPT_ENTRY (debugfunction , DEBUGFUNCTION , TTT , 0 , 0 )
2391
+ #if LCURL_CURL_VER_GE (7 ,19 ,6 )
2392
+ OPT_ENTRY (ssh_keyfunction , SSH_KEYFUNCTION , TTT , 0 , 0 )
2393
+ #endif
2246
2394
#if LCURL_CURL_VER_GE (7 ,21 ,0 )
2247
- OPT_ENTRY (fnmatch_function , FNMATCH_FUNCTION , TTT , 0 , 0 )
2395
+ OPT_ENTRY (fnmatch_function , FNMATCH_FUNCTION , TTT , 0 , 0 )
2248
2396
OPT_ENTRY (chunk_bgn_function , CHUNK_BGN_FUNCTION , TTT , 0 , 0 )
2249
2397
OPT_ENTRY (chunk_end_function , CHUNK_END_FUNCTION , TTT , 0 , 0 )
2250
2398
#endif
@@ -2261,7 +2409,7 @@ static const lcurl_const_t lcurl_easy_opt[] = {
2261
2409
#if LCURL_CURL_VER_GE (7 ,64 ,0 )
2262
2410
OPT_ENTRY (trailerfunction , TRAILERFUNCTION , TTT , 0 , 0 )
2263
2411
#endif
2264
- #if LCURL_CURL_VER_GE (7 ,74 ,0 )
2412
+ #if LCURL_CURL_VER_GE (7 ,74 ,0 ) && LCURL_USE_HSTS
2265
2413
OPT_ENTRY (hstsreadfunction , HSTSREADFUNCTION , TTT , 0 , 0 )
2266
2414
OPT_ENTRY (hstswritefunction , HSTSWRITEFUNCTION ,TTT , 0 , 0 )
2267
2415
#endif
0 commit comments