tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

test-export.c (2170B)


      1 #include <event2/event.h>
      2 #if defined(EVENT_EXPORT_TEST_COMPONENT_EXTRA)
      3 #include "event2/http.h"
      4 #include "event2/rpc.h"
      5 #include <event2/dns.h>
      6 #elif defined(EVENT_EXPORT_TEST_COMPONENT_PTHREADS)
      7 #include <event2/thread.h>
      8 #elif defined(EVENT_EXPORT_TEST_COMPONENT_OPENSSL)
      9 #include <openssl/ssl.h>
     10 #include <openssl/err.h>
     11 #include <event2/bufferevent_ssl.h>
     12 #endif
     13 
     14 #if defined(EVENT_EXPORT_TEST_COMPONENT_EXTRA)
     15 static int
     16 test()
     17 {
     18 struct event_base *base = NULL;
     19 struct evhttp *http = NULL;
     20 struct evdns_base *dns_base = NULL;
     21 struct evrpc_base *rpc_base = NULL;
     22 
     23 base = event_base_new();
     24 if (base) {
     25 	http = evhttp_new(base);
     26 	dns_base = evdns_base_new(base,
     27 		EVDNS_BASE_DISABLE_WHEN_INACTIVE);
     28 }
     29 if (http)
     30 	rpc_base = evrpc_init(http);
     31 
     32 if (base)
     33 	event_base_free(base);
     34 if (http)
     35 	evhttp_free(http);
     36 if (rpc_base)
     37 	evrpc_free(rpc_base);
     38 if (dns_base)
     39 	evdns_base_free(dns_base, 0);
     40 
     41 return 0;
     42 }
     43 #elif defined(EVENT_EXPORT_TEST_COMPONENT_PTHREADS)
     44 static int
     45 test()
     46 {
     47 return evthread_use_pthreads();
     48 }
     49 #elif defined(EVENT_EXPORT_TEST_COMPONENT_OPENSSL)
     50 static int
     51 test()
     52 {
     53 struct event_base *base = NULL;
     54 SSL_CTX *ssl_ctx = NULL;
     55 SSL *ssl = NULL;
     56 struct bufferevent *bev;
     57 int r = 1;
     58 
     59 SSL_library_init();
     60 ERR_load_crypto_strings();
     61 SSL_load_error_strings();
     62 OpenSSL_add_all_algorithms();
     63 
     64 base = event_base_new();
     65 if (!base) {
     66 	goto error;
     67 }
     68 
     69 ssl_ctx = SSL_CTX_new(SSLv23_method());
     70 if (!ssl_ctx) {
     71 	goto error;
     72 }
     73 ssl = SSL_new(ssl_ctx);
     74 if (ssl == NULL) {
     75 	goto error;
     76 }
     77 bev = bufferevent_openssl_socket_new(base, -1, ssl,
     78 	BUFFEREVENT_SSL_CONNECTING,
     79 	BEV_OPT_CLOSE_ON_FREE | BEV_OPT_DEFER_CALLBACKS);
     80 if (bev == NULL) {
     81 	goto error;
     82 }
     83 r = 0;
     84 error:
     85 if (base)
     86 	event_base_free(base);
     87 if (ssl_ctx)
     88 	SSL_CTX_free(ssl_ctx);
     89 if (ssl)
     90 	SSL_free(ssl);
     91 return r;
     92 }
     93 #else
     94 static int
     95 test()
     96 {
     97 struct event_base *base = NULL;
     98 
     99 base = event_base_new();
    100 if (base)
    101 	event_base_free(base);
    102 
    103 return 0;
    104 }
    105 #endif
    106 
    107 int
    108 main(int argc, char const *argv[])
    109 {
    110 int r = 0;
    111 #ifdef _WIN32
    112 {
    113 	WSADATA wsaData;
    114 	WSAStartup(MAKEWORD(2, 2), &wsaData);
    115 }
    116 #endif
    117 r = test();
    118 #ifdef _WIN32
    119 WSACleanup();
    120 #endif
    121 return r;
    122 }