mirror of
https://github.com/cesanta/mongoose.git
synced 2025-08-06 05:26:15 +08:00
Make mg_tun_bind take separate user+pass
PUBLISHED_FROM=3ee9478275c4b9253b1dd4f98a69cecc89290bce
This commit is contained in:
parent
5045dfab74
commit
5934846852
@ -2,7 +2,8 @@
|
|||||||
|
|
||||||
static const char *s_local_port = ":8001";
|
static const char *s_local_port = ":8001";
|
||||||
static const char *s_dispatcher = "ws://localhost:8000";
|
static const char *s_dispatcher = "ws://localhost:8000";
|
||||||
static const char *s_auth = "foo:bar";
|
static const char *s_user = "foo";
|
||||||
|
static const char *s_pass = "bar";
|
||||||
|
|
||||||
void ev_handler(struct mg_connection *nc, int ev, void *ev_data) {
|
void ev_handler(struct mg_connection *nc, int ev, void *ev_data) {
|
||||||
struct http_message *hm = (struct http_message *) ev_data;
|
struct http_message *hm = (struct http_message *) ev_data;
|
||||||
@ -36,16 +37,19 @@ int main(int argc, char **argv) {
|
|||||||
for (i = 1; i < argc; i++) {
|
for (i = 1; i < argc; i++) {
|
||||||
if (strcmp(argv[i], "-D") == 0) {
|
if (strcmp(argv[i], "-D") == 0) {
|
||||||
mgr.hexdump_file = argv[++i];
|
mgr.hexdump_file = argv[++i];
|
||||||
} else if (strcmp(argv[i], "-p") == 0) {
|
} else if (strcmp(argv[i], "-l") == 0) {
|
||||||
s_local_port = argv[++i];
|
s_local_port = argv[++i];
|
||||||
} else if (strcmp(argv[i], "-d") == 0) {
|
} else if (strcmp(argv[i], "-d") == 0) {
|
||||||
s_dispatcher = argv[++i];
|
s_dispatcher = argv[++i];
|
||||||
} else if (strcmp(argv[i], "-u") == 0) {
|
} else if (strcmp(argv[i], "-u") == 0) {
|
||||||
s_auth = argv[++i];
|
s_user = argv[++i];
|
||||||
|
} else if (strcmp(argv[i], "-p") == 0) {
|
||||||
|
s_pass = argv[++i];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((nc = mg_tuna_bind(&mgr, ev_handler, s_dispatcher, s_auth)) == NULL) {
|
if ((nc = mg_tuna_bind(&mgr, ev_handler, s_dispatcher, s_user, s_pass)) ==
|
||||||
|
NULL) {
|
||||||
fprintf(stderr, "Cannot create tunneled listening socket on [%s]\n",
|
fprintf(stderr, "Cannot create tunneled listening socket on [%s]\n",
|
||||||
s_dispatcher);
|
s_dispatcher);
|
||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
|
18
mongoose.c
18
mongoose.c
@ -10557,11 +10557,12 @@ static void mg_tun_reconnect(struct mg_tun_client *client);
|
|||||||
|
|
||||||
static void mg_tun_init_client(struct mg_tun_client *client, struct mg_mgr *mgr,
|
static void mg_tun_init_client(struct mg_tun_client *client, struct mg_mgr *mgr,
|
||||||
struct mg_iface *iface, const char *dispatcher,
|
struct mg_iface *iface, const char *dispatcher,
|
||||||
const char *auth) {
|
const char *user, const char *pass) {
|
||||||
client->mgr = mgr;
|
client->mgr = mgr;
|
||||||
client->iface = iface;
|
client->iface = iface;
|
||||||
client->disp_url = dispatcher;
|
client->disp_url = dispatcher;
|
||||||
client->auth = auth;
|
client->user = user;
|
||||||
|
client->pass = pass;
|
||||||
client->last_stream_id = 0;
|
client->last_stream_id = 0;
|
||||||
|
|
||||||
client->disp = NULL; /* will be set by mg_tun_reconnect */
|
client->disp = NULL; /* will be set by mg_tun_reconnect */
|
||||||
@ -10671,7 +10672,7 @@ static void mg_tun_do_reconnect(struct mg_tun_client *client) {
|
|||||||
mbuf_init(&headers, 0);
|
mbuf_init(&headers, 0);
|
||||||
|
|
||||||
/* HTTP/Websocket listener */
|
/* HTTP/Websocket listener */
|
||||||
mg_basic_auth_header(client->auth, NULL, &headers);
|
mg_basic_auth_header(client->user, client->pass, &headers);
|
||||||
mbuf_append(&headers, "", 1); /* nul terminate */
|
mbuf_append(&headers, "", 1); /* nul terminate */
|
||||||
if ((dc = mg_connect_ws(client->mgr, mg_tun_client_handler, client->disp_url,
|
if ((dc = mg_connect_ws(client->mgr, mg_tun_client_handler, client->disp_url,
|
||||||
"mg_tun", headers.buf)) == NULL) {
|
"mg_tun", headers.buf)) == NULL) {
|
||||||
@ -10709,7 +10710,8 @@ static void mg_tun_reconnect(struct mg_tun_client *client) {
|
|||||||
|
|
||||||
static struct mg_tun_client *mg_tun_create_client(struct mg_mgr *mgr,
|
static struct mg_tun_client *mg_tun_create_client(struct mg_mgr *mgr,
|
||||||
const char *dispatcher,
|
const char *dispatcher,
|
||||||
const char *auth) {
|
const char *user,
|
||||||
|
const char *pass) {
|
||||||
struct mg_tun_client *client = NULL;
|
struct mg_tun_client *client = NULL;
|
||||||
struct mg_iface *iface = mg_find_iface(mgr, &mg_tun_iface_vtable, NULL);
|
struct mg_iface *iface = mg_find_iface(mgr, &mg_tun_iface_vtable, NULL);
|
||||||
if (iface == NULL) {
|
if (iface == NULL) {
|
||||||
@ -10719,7 +10721,7 @@ static struct mg_tun_client *mg_tun_create_client(struct mg_mgr *mgr,
|
|||||||
}
|
}
|
||||||
|
|
||||||
client = (struct mg_tun_client *) MG_MALLOC(sizeof(*client));
|
client = (struct mg_tun_client *) MG_MALLOC(sizeof(*client));
|
||||||
mg_tun_init_client(client, mgr, iface, dispatcher, auth);
|
mg_tun_init_client(client, mgr, iface, dispatcher, user, pass);
|
||||||
iface->data = client;
|
iface->data = client;
|
||||||
|
|
||||||
mg_tun_do_reconnect(client);
|
mg_tun_do_reconnect(client);
|
||||||
@ -10744,8 +10746,10 @@ static struct mg_connection *mg_tuna_do_bind(struct mg_tun_client *client,
|
|||||||
|
|
||||||
struct mg_connection *mg_tuna_bind(struct mg_mgr *mgr,
|
struct mg_connection *mg_tuna_bind(struct mg_mgr *mgr,
|
||||||
mg_event_handler_t handler,
|
mg_event_handler_t handler,
|
||||||
const char *dispatcher, const char *auth) {
|
const char *dispatcher, const char *user,
|
||||||
struct mg_tun_client *client = mg_tun_create_client(mgr, dispatcher, auth);
|
const char *pass) {
|
||||||
|
struct mg_tun_client *client =
|
||||||
|
mg_tun_create_client(mgr, dispatcher, user, pass);
|
||||||
if (client == NULL) {
|
if (client == NULL) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
@ -5560,7 +5560,9 @@ struct mg_tun_client {
|
|||||||
struct mg_mgr *mgr;
|
struct mg_mgr *mgr;
|
||||||
struct mg_iface *iface;
|
struct mg_iface *iface;
|
||||||
const char *disp_url;
|
const char *disp_url;
|
||||||
const char *auth;
|
const char *user;
|
||||||
|
const char *pass;
|
||||||
|
|
||||||
uint32_t last_stream_id; /* stream id of most recently accepted connection */
|
uint32_t last_stream_id; /* stream id of most recently accepted connection */
|
||||||
|
|
||||||
struct mg_connection *disp;
|
struct mg_connection *disp;
|
||||||
@ -5573,7 +5575,8 @@ extern "C" {
|
|||||||
|
|
||||||
struct mg_connection *mg_tuna_bind(struct mg_mgr *mgr,
|
struct mg_connection *mg_tuna_bind(struct mg_mgr *mgr,
|
||||||
mg_event_handler_t handler,
|
mg_event_handler_t handler,
|
||||||
const char *dispatcher, const char *auth);
|
const char *dispatcher, const char *user,
|
||||||
|
const char *pass);
|
||||||
|
|
||||||
int mg_tun_parse_frame(void *data, size_t len, struct mg_tun_frame *frame);
|
int mg_tun_parse_frame(void *data, size_t len, struct mg_tun_frame *frame);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user