mirror of
https://github.com/cesanta/mongoose.git
synced 2025-08-05 21:18:32 +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_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) {
|
||||
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++) {
|
||||
if (strcmp(argv[i], "-D") == 0) {
|
||||
mgr.hexdump_file = argv[++i];
|
||||
} else if (strcmp(argv[i], "-p") == 0) {
|
||||
} else if (strcmp(argv[i], "-l") == 0) {
|
||||
s_local_port = argv[++i];
|
||||
} else if (strcmp(argv[i], "-d") == 0) {
|
||||
s_dispatcher = argv[++i];
|
||||
} 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",
|
||||
s_dispatcher);
|
||||
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,
|
||||
struct mg_iface *iface, const char *dispatcher,
|
||||
const char *auth) {
|
||||
const char *user, const char *pass) {
|
||||
client->mgr = mgr;
|
||||
client->iface = iface;
|
||||
client->disp_url = dispatcher;
|
||||
client->auth = auth;
|
||||
client->user = user;
|
||||
client->pass = pass;
|
||||
client->last_stream_id = 0;
|
||||
|
||||
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);
|
||||
|
||||
/* 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 */
|
||||
if ((dc = mg_connect_ws(client->mgr, mg_tun_client_handler, client->disp_url,
|
||||
"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,
|
||||
const char *dispatcher,
|
||||
const char *auth) {
|
||||
const char *user,
|
||||
const char *pass) {
|
||||
struct mg_tun_client *client = NULL;
|
||||
struct mg_iface *iface = mg_find_iface(mgr, &mg_tun_iface_vtable, 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));
|
||||
mg_tun_init_client(client, mgr, iface, dispatcher, auth);
|
||||
mg_tun_init_client(client, mgr, iface, dispatcher, user, pass);
|
||||
iface->data = 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,
|
||||
mg_event_handler_t handler,
|
||||
const char *dispatcher, const char *auth) {
|
||||
struct mg_tun_client *client = mg_tun_create_client(mgr, dispatcher, auth);
|
||||
const char *dispatcher, const char *user,
|
||||
const char *pass) {
|
||||
struct mg_tun_client *client =
|
||||
mg_tun_create_client(mgr, dispatcher, user, pass);
|
||||
if (client == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
|
@ -5560,7 +5560,9 @@ struct mg_tun_client {
|
||||
struct mg_mgr *mgr;
|
||||
struct mg_iface *iface;
|
||||
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 */
|
||||
|
||||
struct mg_connection *disp;
|
||||
@ -5573,7 +5575,8 @@ extern "C" {
|
||||
|
||||
struct mg_connection *mg_tuna_bind(struct mg_mgr *mgr,
|
||||
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);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user