|
@@ -43,6 +43,7 @@ enum {
|
|
|
|
|
|
|
|
|
|
|
|
|
typedef void (*http_fn_t)(void *arg);
|
|
typedef void (*http_fn_t)(void *arg);
|
|
|
|
|
+typedef struct mg_tls_opts mg_tls_t;
|
|
|
|
|
|
|
|
typedef struct {
|
|
typedef struct {
|
|
|
struct mg_connection *c;
|
|
struct mg_connection *c;
|
|
@@ -57,6 +58,7 @@ typedef struct {
|
|
|
int cnt;
|
|
int cnt;
|
|
|
mg_fn_t fn[FN_MAX];
|
|
mg_fn_t fn[FN_MAX];
|
|
|
char rootDir[MG_PATH_MAX];
|
|
char rootDir[MG_PATH_MAX];
|
|
|
|
|
+ mg_tls_t tls;
|
|
|
|
|
|
|
|
pthread_t tid;
|
|
pthread_t tid;
|
|
|
}mg_handle_t;
|
|
}mg_handle_t;
|
|
@@ -398,14 +400,10 @@ static void http_mg_cb(struct mg_connection *c, int ev, void *ev_data)
|
|
|
mg_http_serve_dir(c, ev_data, &opts);
|
|
mg_http_serve_dir(c, ev_data, &opts);
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
- else if(ev == MG_EV_CONNECT) {
|
|
|
|
|
- #if 0
|
|
|
|
|
- if (mg_url_is_ssl(url)) {
|
|
|
|
|
- struct mg_tls_opts opts = {.ca = mg_unpacked("/certs/ca.pem"),
|
|
|
|
|
- .name = host};
|
|
|
|
|
- mg_tls_init(c, &opts);
|
|
|
|
|
|
|
+ else if(ev == MG_EV_ACCEPT) {
|
|
|
|
|
+ if (c->is_tls) {
|
|
|
|
|
+ mg_tls_init(c, &h->tls);
|
|
|
}
|
|
}
|
|
|
- #endif
|
|
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
void *web_thread(void *arg)
|
|
void *web_thread(void *arg)
|
|
@@ -414,8 +412,8 @@ void *web_thread(void *arg)
|
|
|
struct mg_connection *c;
|
|
struct mg_connection *c;
|
|
|
mg_handle_t *mh=&webHandle.mg;
|
|
mg_handle_t *mh=&webHandle.mg;
|
|
|
thread_handle_t *h=(thread_handle_t*)arg;
|
|
thread_handle_t *h=(thread_handle_t*)arg;
|
|
|
- const char *listen_addr1="http://[::]:80";
|
|
|
|
|
- const char *listen_addr2="http://[::]:443";
|
|
|
|
|
|
|
+ const char *http_addr="http://[::]:80";
|
|
|
|
|
+ const char *https_addr="https://[::]:443";
|
|
|
|
|
|
|
|
//mg_log_set(MG_LL_DEBUG);
|
|
//mg_log_set(MG_LL_DEBUG);
|
|
|
mg_mgr_init(&mgr);
|
|
mg_mgr_init(&mgr);
|
|
@@ -423,19 +421,22 @@ void *web_thread(void *arg)
|
|
|
//sys_get_path(h->rootDir, WEB_ROOT);
|
|
//sys_get_path(h->rootDir, WEB_ROOT);
|
|
|
strcpy(mh->rootDir, "/root/run/web");
|
|
strcpy(mh->rootDir, "/root/run/web");
|
|
|
|
|
|
|
|
- if ((c = mg_http_listen(&mgr, listen_addr1, http_mg_cb, NULL)) == NULL) {
|
|
|
|
|
- MG_ERROR(("cannot listen on %s. use http://address:port or :port\n", listen_addr1));
|
|
|
|
|
|
|
+ if ((c = mg_http_listen(&mgr, http_addr, http_mg_cb, NULL)) == NULL) {
|
|
|
|
|
+ MG_ERROR(("cannot listen on %s. use http://address:port or :port\n", http_addr));
|
|
|
return NULL;
|
|
return NULL;
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
- if ((c = mg_http_listen(&mgr, listen_addr2, http_mg_cb, NULL)) == NULL) {
|
|
|
|
|
- MG_ERROR(("cannot listen on %s. use http://address:port or :port\n", listen_addr2));
|
|
|
|
|
|
|
+
|
|
|
|
|
+ if ((c = mg_http_listen(&mgr, https_addr, http_mg_cb, NULL)) == NULL) {
|
|
|
|
|
+ MG_ERROR(("cannot listen on %s. use https://address:port or :port\n", https_addr));
|
|
|
return NULL;
|
|
return NULL;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
webSetCallback();
|
|
webSetCallback();
|
|
|
printf("_____mgHandle.cnt: %d, rootdir: %s\n", mh->cnt, mh->rootDir);
|
|
printf("_____mgHandle.cnt: %d, rootdir: %s\n", mh->cnt, mh->rootDir);
|
|
|
|
|
|
|
|
|
|
+ mh->tls.cert = mg_str(file_load2("/root/run/app/cert/server.crt"));
|
|
|
|
|
+ mh->tls.key = mg_str(file_load2("/root/run/app/cert/server.key"));
|
|
|
|
|
+ mh->tls.name = mg_url_host(https_addr);
|
|
|
while(h->quit==0) {
|
|
while(h->quit==0) {
|
|
|
mg_mgr_poll(&mgr, 200);
|
|
mg_mgr_poll(&mgr, 200);
|
|
|
}
|
|
}
|