@@ -94,10 +94,13 @@ int lcurl_easy_create(lua_State *L, int error_mode){
9494 p -> match .cb_ref = p -> match .ud_ref = LUA_NOREF ;
9595 p -> chunk_bgn .cb_ref = p -> chunk_bgn .ud_ref = LUA_NOREF ;
9696 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
97100#if LCURL_CURL_VER_GE (7 ,64 ,0 )
98101 p -> trailer .cb_ref = p -> trailer .ud_ref = LUA_NOREF ;
99102#endif
100- #if LCURL_CURL_VER_GE (7 ,74 ,0 )
103+ #if LCURL_CURL_VER_GE (7 ,74 ,0 ) && LCURL_USE_HSTS
101104 p -> hstsread .cb_ref = p -> hstsread .ud_ref = LUA_NOREF ;
102105 p -> hstswrite .cb_ref = p -> hstswrite .ud_ref = LUA_NOREF ;
103106#endif
@@ -155,11 +158,15 @@ static int lcurl_easy_cleanup_storage(lua_State *L, lcurl_easy_t *p){
155158 luaL_unref (L , LCURL_LUA_REGISTRY , p -> chunk_bgn .ud_ref );
156159 luaL_unref (L , LCURL_LUA_REGISTRY , p -> chunk_end .cb_ref );
157160 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
158165#if LCURL_CURL_VER_GE (7 ,64 ,0 )
159166 luaL_unref (L , LCURL_LUA_REGISTRY , p -> trailer .cb_ref );
160167 luaL_unref (L , LCURL_LUA_REGISTRY , p -> trailer .ud_ref );
161168#endif
162- #if LCURL_CURL_VER_GE (7 ,74 ,0 )
169+ #if LCURL_CURL_VER_GE (7 ,74 ,0 ) && LCURL_USE_HSTS
163170 luaL_unref (L , LCURL_LUA_REGISTRY , p -> hstsread .cb_ref );
164171 luaL_unref (L , LCURL_LUA_REGISTRY , p -> hstsread .ud_ref );
165172 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){
178185 p -> match .cb_ref = p -> match .ud_ref = LUA_NOREF ;
179186 p -> chunk_bgn .cb_ref = p -> chunk_bgn .ud_ref = LUA_NOREF ;
180187 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
181191#if LCURL_CURL_VER_GE (7 ,64 ,0 )
182192 p -> trailer .cb_ref = p -> trailer .ud_ref = LUA_NOREF ;
183193#endif
184- #if LCURL_CURL_VER_GE (7 ,74 ,0 )
194+ #if LCURL_CURL_VER_GE (7 ,74 ,0 ) && LCURL_USE_HSTS
185195 p -> hstsread .cb_ref = p -> hstsread .ud_ref = LUA_NOREF ;
186196 p -> hstswrite .cb_ref = p -> hstswrite .ud_ref = LUA_NOREF ;
187197#endif
@@ -897,6 +907,27 @@ static int lcurl_easy_unset_DEBUGFUNCTION(lua_State *L){
897907 return 1 ;
898908}
899909
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+
900931#if LCURL_CURL_VER_GE (7 ,21 ,0 )
901932
902933static int lcurl_easy_unset_FNMATCH_FUNCTION (lua_State * L ){
@@ -935,6 +966,7 @@ static int lcurl_easy_unset_CHUNK_BGN_FUNCTION(lua_State *L){
935966 lua_settop (L , 1 );
936967 return 1 ;
937968}
969+
938970static int lcurl_easy_unset_CHUNK_END_FUNCTION (lua_State * L ){
939971 lcurl_easy_t * p = lcurl_geteasy (L );
940972
@@ -1046,7 +1078,7 @@ static int lcurl_easy_unset_TRAILERFUNCTION(lua_State *L){
10461078
10471079#endif
10481080
1049- #if LCURL_CURL_VER_GE (7 ,74 ,0 )
1081+ #if LCURL_CURL_VER_GE (7 ,74 ,0 ) && LCURL_USE_HSTS
10501082
10511083static int lcurl_easy_unset_HSTSREADFUNCTION (lua_State * L ){
10521084 lcurl_easy_t * p = lcurl_geteasy (L );
@@ -1818,7 +1850,7 @@ static int lcurl_easy_set_TRAILERFUNCTION (lua_State *L){
18181850
18191851//{ HSTS Reader
18201852
1821- #if LCURL_CURL_VER_GE (7 ,74 ,0 )
1853+ #if LCURL_CURL_VER_GE (7 ,74 ,0 ) && LCURL_USE_HSTS
18221854
18231855#define LCURL_HSTS_EXPIRE_LEN 18
18241856
@@ -1924,7 +1956,7 @@ static int lcurl_easy_set_HSTSREADFUNCTION(lua_State *L){
19241956
19251957//{ HSTS Writer
19261958
1927- #if LCURL_CURL_VER_GE (7 ,74 ,0 )
1959+ #if LCURL_CURL_VER_GE (7 ,74 ,0 ) && LCURL_USE_HSTS
19281960
19291961static int lcurl_hstswrite_callback (CURL * easy , struct curl_hstsentry * sts , struct curl_index * count , void * arg ) {
19301962 lcurl_easy_t * p = arg ;
@@ -1996,6 +2028,87 @@ static int lcurl_easy_set_HSTSWRITEFUNCTION(lua_State *L){
19962028
19972029//}
19982030
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+
19992112static int lcurl_easy_setopt (lua_State * L ){
20002113 lcurl_easy_t * p = lcurl_geteasy (L );
20012114 long opt ;
@@ -2023,8 +2136,11 @@ static int lcurl_easy_setopt(lua_State *L){
20232136 OPT_ENTRY (progressfunction , PROGRESSFUNCTION , TTT , 0 , 0 )
20242137 OPT_ENTRY (seekfunction , SEEKFUNCTION , TTT , 0 , 0 )
20252138 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
20262142#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 )
20282144 OPT_ENTRY (chunk_bgn_function , CHUNK_BGN_FUNCTION , TTT , 0 , 0 )
20292145 OPT_ENTRY (chunk_end_function , CHUNK_END_FUNCTION , TTT , 0 , 0 )
20302146#endif
@@ -2034,6 +2150,16 @@ static int lcurl_easy_setopt(lua_State *L){
20342150#endif
20352151#if LCURL_CURL_VER_GE (7 ,56 ,0 )
20362152 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 )
20372163#endif
20382164 }
20392165#undef OPT_ENTRY
@@ -2060,8 +2186,11 @@ static int lcurl_easy_unsetopt(lua_State *L){
20602186 OPT_ENTRY (progressfunction , PROGRESSFUNCTION , TTT , 0 , 0 )
20612187 OPT_ENTRY (seekfunction , SEEKFUNCTION , TTT , 0 , 0 )
20622188 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
20632192#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 )
20652194 OPT_ENTRY (chunk_bgn_function , CHUNK_BGN_FUNCTION , TTT , 0 , 0 )
20662195 OPT_ENTRY (chunk_end_function , CHUNK_END_FUNCTION , TTT , 0 , 0 )
20672196#endif
@@ -2071,6 +2200,16 @@ static int lcurl_easy_unsetopt(lua_State *L){
20712200#endif
20722201#if LCURL_CURL_VER_GE (7 ,56 ,0 )
20732202 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 )
20742213#endif
20752214 }
20762215#undef OPT_ENTRY
@@ -2141,6 +2280,9 @@ static const struct luaL_Reg lcurl_easy_methods[] = {
21412280 OPT_ENTRY (progressfunction , PROGRESSFUNCTION , TTT , 0 , 0 )
21422281 OPT_ENTRY (seekfunction , SEEKFUNCTION , TTT , 0 , 0 )
21432282 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
21442286#if LCURL_CURL_VER_GE (7 ,21 ,0 )
21452287 OPT_ENTRY (fnmatch_function , FNMATCH_FUNCTION , TTT , 0 , 0 )
21462288 OPT_ENTRY (chunk_bgn_function , CHUNK_BGN_FUNCTION , TTT , 0 , 0 )
@@ -2159,7 +2301,7 @@ static const struct luaL_Reg lcurl_easy_methods[] = {
21592301#if LCURL_CURL_VER_GE (7 ,64 ,0 )
21602302 OPT_ENTRY (trailerfunction , TRAILERFUNCTION , TTT , 0 , 0 )
21612303#endif
2162- #if LCURL_CURL_VER_GE (7 ,74 ,0 )
2304+ #if LCURL_CURL_VER_GE (7 ,74 ,0 ) && LCURL_USE_HSTS
21632305 OPT_ENTRY (hstsreadfunction , HSTSREADFUNCTION , TTT , 0 , 0 )
21642306 OPT_ENTRY (hstswritefunction , HSTSWRITEFUNCTION ,TTT , 0 , 0 )
21652307#endif
@@ -2176,6 +2318,9 @@ static const struct luaL_Reg lcurl_easy_methods[] = {
21762318 OPT_ENTRY (progressfunction , PROGRESSFUNCTION , TTT , 0 , 0 )
21772319 OPT_ENTRY (seekfunction , SEEKFUNCTION , TTT , 0 , 0 )
21782320 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
21792324#if LCURL_CURL_VER_GE (7 ,21 ,0 )
21802325 OPT_ENTRY (fnmatch_function , FNMATCH_FUNCTION , TTT , 0 , 0 )
21812326 OPT_ENTRY (chunk_bgn_function , CHUNK_BGN_FUNCTION , TTT , 0 , 0 )
@@ -2194,7 +2339,7 @@ static const struct luaL_Reg lcurl_easy_methods[] = {
21942339#if LCURL_CURL_VER_GE (7 ,64 ,0 )
21952340 OPT_ENTRY (trailerfunction , TRAILERFUNCTION , TTT , 0 , 0 )
21962341#endif
2197- #if LCURL_CURL_VER_GE (7 ,74 ,0 )
2342+ #if LCURL_CURL_VER_GE (7 ,74 ,0 ) && LCURL_USE_HSTS
21982343 OPT_ENTRY (hstsreadfunction , HSTSREADFUNCTION , TTT , 0 , 0 )
21992344 OPT_ENTRY (hstswritefunction , HSTSWRITEFUNCTION ,TTT , 0 , 0 )
22002345#endif
@@ -2243,8 +2388,11 @@ static const lcurl_const_t lcurl_easy_opt[] = {
22432388 OPT_ENTRY (progressfunction , PROGRESSFUNCTION , TTT , 0 , 0 )
22442389 OPT_ENTRY (seekfunction , SEEKFUNCTION , TTT , 0 , 0 )
22452390 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
22462394#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 )
22482396 OPT_ENTRY (chunk_bgn_function , CHUNK_BGN_FUNCTION , TTT , 0 , 0 )
22492397 OPT_ENTRY (chunk_end_function , CHUNK_END_FUNCTION , TTT , 0 , 0 )
22502398#endif
@@ -2261,7 +2409,7 @@ static const lcurl_const_t lcurl_easy_opt[] = {
22612409#if LCURL_CURL_VER_GE (7 ,64 ,0 )
22622410 OPT_ENTRY (trailerfunction , TRAILERFUNCTION , TTT , 0 , 0 )
22632411#endif
2264- #if LCURL_CURL_VER_GE (7 ,74 ,0 )
2412+ #if LCURL_CURL_VER_GE (7 ,74 ,0 ) && LCURL_USE_HSTS
22652413 OPT_ENTRY (hstsreadfunction , HSTSREADFUNCTION , TTT , 0 , 0 )
22662414 OPT_ENTRY (hstswritefunction , HSTSWRITEFUNCTION ,TTT , 0 , 0 )
22672415#endif
0 commit comments