Skip to content

Commit

Permalink
debug: add some info
Browse files Browse the repository at this point in the history
Signed-off-by: Dengfeng Liu <[email protected]>
  • Loading branch information
liudf0716 committed Jul 10, 2024
1 parent 9d541df commit 2553631
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 7 deletions.
6 changes: 6 additions & 0 deletions src/gateway.c
Original file line number Diff line number Diff line change
Expand Up @@ -477,6 +477,9 @@ http_redir_loop(s_config *config)
if (!request_ctx) termination_handler(0);

wd_signals_init(base);

setbuf(stdout, NULL);
setbuf(stderr, NULL);

evhttp_set_cb(http, "/wifidog", ev_http_callback_wifidog, NULL);
//evhttp_set_cb(http, "/wifidog/status", ev_http_callback_status, NULL);
Expand All @@ -489,6 +492,9 @@ http_redir_loop(s_config *config)
evhttp_bind_socket_with_handle(http, config->gw_address, config->gw_port);

event_base_dispatch(base);

evhttp_free(http);
event_base_free(base);
}

/**@internal
Expand Down
10 changes: 7 additions & 3 deletions src/http.c
Original file line number Diff line number Diff line change
Expand Up @@ -155,18 +155,20 @@ process_apple_wisper(struct evhttp_request *req, const char *mac, const char *re
*
* @param req The http request
* @param type 1: internet not online
* other: auth server ont online
* other: auth server offline
*/
void
ev_http_reply_client_error(struct evhttp_request *req, enum reply_client_error_type type)
{
switch(type) {
case INTERNET_OFFLINE:
evhttp_send_reply(req, 200, "OK", evb_internet_offline_page);
//evhttp_send_reply(req, 200, "OK", evb_internet_offline_page);
evhttp_send_error(req, 200, "Internet is offline");
break;
case AUTHSERVER_OFFLINE:
default:
evhttp_send_reply(req, 200, "OK", evb_authserver_offline_page);
//evhttp_send_reply(req, 200, "OK", evb_authserver_offline_page);
evhttp_send_error(req, 200, "Auth server is offline");
break;
}
}
Expand Down Expand Up @@ -239,11 +241,13 @@ void
ev_http_callback_404(struct evhttp_request *req, void *arg)
{
if (!is_online()) {
debug(LOG_INFO, "Internet is offline");
ev_http_reply_client_error(req, INTERNET_OFFLINE);
return;
}

if (!is_auth_online()) {
debug(LOG_INFO, "Auth server is offline");
ev_http_reply_client_error(req, AUTHSERVER_OFFLINE);
return;
}
Expand Down
10 changes: 7 additions & 3 deletions src/ping_thread.c
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,11 @@ ping_work_cb(evutil_socket_t fd, short event, void *arg) {
struct sys_info info;
memset(&info, 0, sizeof(info));

if (wd_make_request(request_ctx, &evcon, &req, process_ping_response)) return;

if (wd_make_request(request_ctx, &evcon, &req, process_ping_response)) {
debug(LOG_ERR, "Failed to make request to auth server");
return;
}

get_sys_info(&info);
char *uri = get_ping_uri(&info);
if (!uri) return; // impossibe
Expand Down Expand Up @@ -285,7 +288,8 @@ process_ping_response(struct evhttp_request *req, void *ctx)
}
} else if (strstr(buffer, "Pong") == 0) {
mark_auth_offline();
debug(LOG_WARNING, "Auth server did NOT say Pong!");
debug(LOG_WARNING, "Auth server did NOT say Pong! the response [%s], error: %s",
buffer, strerror(errno));
if (!authdown) {
fw_set_authdown();
authdown = 1;
Expand Down
3 changes: 2 additions & 1 deletion src/wd_client.c
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,8 @@ wd_make_request(struct wd_request_context *request_ctx,
struct bufferevent *bev = request_ctx->bev;
struct event_base *base = request_ctx->base;
t_auth_serv *auth_server = get_auth_server();


debug(LOG_DEBUG, "auth_server->authserv_use_ssl: %d", auth_server->authserv_use_ssl);
if (!auth_server->authserv_use_ssl) {
*evcon = evhttp_connection_base_bufferevent_new(base, NULL, bev,
auth_server->authserv_hostname, auth_server->authserv_http_port);
Expand Down

0 comments on commit 2553631

Please sign in to comment.