From 1475e5cd60791bf33b056d49e5974999e0d8a5ff Mon Sep 17 00:00:00 2001 From: Alexey Melnichuk Date: Tue, 15 Aug 2017 17:40:16 +0300 Subject: [PATCH] Add. get certinfo for easy handle. --- src/lceasy.c | 37 +++++++++++++++++++++++++++++++++++++ src/lcinfoeasy.h | 3 ++- 2 files changed, 39 insertions(+), 1 deletion(-) diff --git a/src/lceasy.c b/src/lceasy.c index 55d4003..03ef367 100644 --- a/src/lceasy.c +++ b/src/lceasy.c @@ -841,6 +841,39 @@ static int lcurl_info_get_slist_(lua_State *L, int opt){ return 1; } +static int lcurl_info_get_certinfo_(lua_State *L, int opt){ + lcurl_easy_t *p = lcurl_geteasy(L); + int decode = lua_toboolean(L, 2); + struct curl_certinfo * val; CURLcode code; + + code = curl_easy_getinfo(p->curl, opt, &val); + if(code != CURLE_OK){ + return lcurl_fail_ex(L, p->err_mode, LCURL_ERROR_EASY, code); + } + + lua_newtable(L); + { int i = 0; for(;inum_of_certs; ++i){ + struct curl_slist *slist = val->certinfo[i]; + if (decode) { + lua_newtable(L); + for(;slist; slist = slist->next){ + const char *ptr = strchr(slist->data, ':'); + if(ptr){ + lua_pushlstring(L, slist->data, ptr - slist->data); + lua_pushstring(L, ptr + 1); + lua_rawset(L, -3); + } + } + } + else{ + lcurl_util_slist_to_table(L, slist); + } + lua_rawseti(L, -2, i + 1); + }} + + return 1; +} + #define LCURL_STR_INFO(N, S) static int lcurl_easy_get_##N(lua_State *L){\ return lcurl_info_get_string_(L, CURLINFO_##N); \ } @@ -857,6 +890,10 @@ static int lcurl_info_get_slist_(lua_State *L, int opt){ return lcurl_info_get_double_(L, CURLINFO_##N);\ } +#define LCURL_CERTINFO_INFO(N, S) static int lcurl_easy_get_##N(lua_State *L){\ + return lcurl_info_get_certinfo_(L, CURLINFO_##N);\ +} + #define OPT_ENTRY(L, N, T, S) LCURL_##T##_INFO(N, S) #include "lcinfoeasy.h" diff --git a/src/lcinfoeasy.h b/src/lcinfoeasy.h index d5b6558..3a4581d 100644 --- a/src/lcinfoeasy.h +++ b/src/lcinfoeasy.h @@ -27,6 +27,7 @@ OPT_ENTRY( proxyauth_avail, PROXYAUTH_AVAIL, LNG, 0) OPT_ENTRY( os_errno, OS_ERRNO, LNG, 0) OPT_ENTRY( num_connects, NUM_CONNECTS, LNG, 0) OPT_ENTRY( primary_ip, PRIMARY_IP, STR, 0) +OPT_ENTRY( certinfo, CERTINFO, CERTINFO, 0) #if LCURL_CURL_VER_GE(7,21,0) OPT_ENTRY( primary_port, PRIMARY_PORT, LNG, 0) OPT_ENTRY( local_ip, LOCAL_IP, STR, 0) @@ -54,5 +55,5 @@ OPT_ENTRY( scheme, SCHEME, STR, 0) #endif // OPT_ENTRY( PRIVATE, void ) -// OPT_ENTRY( CERTINFO, struct curl_certinfo * +// OPT_ENTRY( TLS_SSL_PTR, struct curl_tlssessioninfo ** // OPT_ENTRY( TLS_SESSION, struct curl_tlssessioninfo *