From 875137914ae06e091274078cc9c58dcad6dfad8f Mon Sep 17 00:00:00 2001 From: niansa Date: Thu, 13 Apr 2023 09:32:48 +0200 Subject: [PATCH] Restructured Makefile --- Makefile | 15 +++++++++++---- common.cpp | 37 ++++++++++++++++++++++++++++++++++++- common.h | 1 + nss.c | 9 --------- 4 files changed, 48 insertions(+), 14 deletions(-) diff --git a/Makefile b/Makefile index 30c92da..507e40c 100644 --- a/Makefile +++ b/Makefile @@ -1,7 +1,14 @@ -libnosni.so: nss.c common.c common.cpp common.h - g++ -c common.cpp -o cpp.o - gcc -g -fPIC -shared -I /usr/include/nspr/ nss.c common.c cpp.o -o libnosni.so - rm -f cpp.o +libnosni.so: nss.o common.o common_cpp.o + g++ -g -fPIC -shared -ldl -lcurl -lcurlpp *.o -o libnosni.so + +nss.o: nss.c + gcc -c -fPIC -I /usr/include/nspr/ nss.c -o nss.o + +common.o: common.c common.h + gcc -c -fPIC common.c -o common.o + +common_cpp.o: common.cpp common.h + g++ -c -fPIC -std=c++17 common.cpp -o common_cpp.o clean: rm -f *.so *.o diff --git a/common.cpp b/common.cpp index 8d1c8b6..011db5b 100644 --- a/common.cpp +++ b/common.cpp @@ -1 +1,36 @@ - +#include +#include +#include +#include +#include +#include +#include + + +static +std::unordered_map cache; + + + +static +std::optional cached_is_domain_blocked(const char *hostname) { + auto fres = cache.find(hostname); + if (fres != cache.end()) { + return fres->second; + } + return {}; +} + +extern "C" +bool is_domain_blocked(const char *hostname) { + // Check cache first + { + auto fres = cached_is_domain_blocked(hostname); + if (fres.has_value()) { + return fres.value(); + } + } + + // Use curlpp to check for HTTP != 200 + +} diff --git a/common.h b/common.h index f79026e..fa475cf 100644 --- a/common.h +++ b/common.h @@ -1 +1,2 @@ const char *resolve_hostname_to_str(const char *hostname); +_Bool is_domain_blocked(const char *hostname); diff --git a/nss.c b/nss.c index 4a8444e..f5313d9 100644 --- a/nss.c +++ b/nss.c @@ -3,7 +3,6 @@ #include #include #include -#include @@ -37,11 +36,3 @@ SECStatus SSL_SetURL(PRFileDesc *fd, const char *url) { // Report success return SECSuccess; } - -extern char * -NSS_CMSSignerInfo_GetSignerCommonName(NSSCMSSignerInfo *sinfo) { - printf("Interrupted common signer name getter; returning debug domain.\n"); - fflush(stdout); - - return strdup("hello.com"); -}