mg_download and ssl initialization

63 views
Skip to first unread message

Matteo Fiorito

unread,
Oct 2, 2018, 5:27:59 AM10/2/18
to civetweb
Dear all,
I am looking for sample code on mg_download.

I would like to create an embedded proxy for my app. 
My current issue is: when I request the download of a SSL page I get "SSL initialization error".

My code sequence:

// function init
...
unsigned int res = mg_init_library( MG_FEATURES_SSL ); // returns 0

memset(&callbacks, 0, sizeof(callbacks));
callbacks.init_ssl = init_ssl; // it is an empty function returning 0
callbacks.log_message = log_message;

ctx= mg_start(&callbacks, 0, NULL);
a = mg_check_feature( MG_FEATURES_SSL );  // returns 2


// function download
...
char host[] = "google.com";
int port = 80, ssl = 1; // 0
char uri[] = "/";
char errBuf[1000];

struct mg_connection* conn = mg_download(host, port, ssl, errBuf, 1000, "GET %s HTTP/1.0\r\nHost: %s\r\n\r\n", uri, host);

// RETURNS conn = NULL
// errBuf = "SSL is not initialized"

Thanks for you patience and help,
Matteo

bel

unread,
Oct 7, 2018, 2:29:43 PM10/7/18
to civetweb
Sorry for the late reply, I was abroad for some days.

You don't need this: callbacks.init_ssl = init_ssl;
But you need some options for the server:
ctx= mg_start(&callbacks, 0, options);

options must at least contain "ssl_certificate"

(Just ignore the ck_*, test_* and mark_point calls - these are pure test functions)

There is a test client as well (just look for "minimal")
Reply all
Reply to author
Forward
0 new messages