Skip to content

Commit 7f3bd8b

Browse files
authored
Merge pull request #110 from moteus/master
Add. get certinfo for easy handle.
2 parents 9d27c94 + 1475e5c commit 7f3bd8b

File tree

2 files changed

+39
-1
lines changed

2 files changed

+39
-1
lines changed

src/lceasy.c

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -841,6 +841,39 @@ static int lcurl_info_get_slist_(lua_State *L, int opt){
841841
return 1;
842842
}
843843

844+
static int lcurl_info_get_certinfo_(lua_State *L, int opt){
845+
lcurl_easy_t *p = lcurl_geteasy(L);
846+
int decode = lua_toboolean(L, 2);
847+
struct curl_certinfo * val; CURLcode code;
848+
849+
code = curl_easy_getinfo(p->curl, opt, &val);
850+
if(code != CURLE_OK){
851+
return lcurl_fail_ex(L, p->err_mode, LCURL_ERROR_EASY, code);
852+
}
853+
854+
lua_newtable(L);
855+
{ int i = 0; for(;i<val->num_of_certs; ++i){
856+
struct curl_slist *slist = val->certinfo[i];
857+
if (decode) {
858+
lua_newtable(L);
859+
for(;slist; slist = slist->next){
860+
const char *ptr = strchr(slist->data, ':');
861+
if(ptr){
862+
lua_pushlstring(L, slist->data, ptr - slist->data);
863+
lua_pushstring(L, ptr + 1);
864+
lua_rawset(L, -3);
865+
}
866+
}
867+
}
868+
else{
869+
lcurl_util_slist_to_table(L, slist);
870+
}
871+
lua_rawseti(L, -2, i + 1);
872+
}}
873+
874+
return 1;
875+
}
876+
844877
#define LCURL_STR_INFO(N, S) static int lcurl_easy_get_##N(lua_State *L){\
845878
return lcurl_info_get_string_(L, CURLINFO_##N); \
846879
}
@@ -857,6 +890,10 @@ static int lcurl_info_get_slist_(lua_State *L, int opt){
857890
return lcurl_info_get_double_(L, CURLINFO_##N);\
858891
}
859892

893+
#define LCURL_CERTINFO_INFO(N, S) static int lcurl_easy_get_##N(lua_State *L){\
894+
return lcurl_info_get_certinfo_(L, CURLINFO_##N);\
895+
}
896+
860897
#define OPT_ENTRY(L, N, T, S) LCURL_##T##_INFO(N, S)
861898

862899
#include "lcinfoeasy.h"

src/lcinfoeasy.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ OPT_ENTRY( proxyauth_avail, PROXYAUTH_AVAIL, LNG, 0)
2727
OPT_ENTRY( os_errno, OS_ERRNO, LNG, 0)
2828
OPT_ENTRY( num_connects, NUM_CONNECTS, LNG, 0)
2929
OPT_ENTRY( primary_ip, PRIMARY_IP, STR, 0)
30+
OPT_ENTRY( certinfo, CERTINFO, CERTINFO, 0)
3031
#if LCURL_CURL_VER_GE(7,21,0)
3132
OPT_ENTRY( primary_port, PRIMARY_PORT, LNG, 0)
3233
OPT_ENTRY( local_ip, LOCAL_IP, STR, 0)
@@ -54,5 +55,5 @@ OPT_ENTRY( scheme, SCHEME, STR, 0)
5455
#endif
5556

5657
// OPT_ENTRY( PRIVATE, void )
57-
// OPT_ENTRY( CERTINFO, struct curl_certinfo *
58+
// OPT_ENTRY( TLS_SSL_PTR, struct curl_tlssessioninfo **
5859
// OPT_ENTRY( TLS_SESSION, struct curl_tlssessioninfo *

0 commit comments

Comments
 (0)