static void free_connman_wispr_portal_context( struct connman_wispr_portal_context *wp_context) { DBG("context %p", wp_context); if (!wp_context) return; if (wp_context->wispr_portal) { if (wp_context->wispr_portal->ipv4_context == wp_context) wp_context->wispr_portal->ipv4_context = NULL; if (wp_context->wispr_portal->ipv6_context == wp_context) wp_context->wispr_portal->ipv6_context = NULL; } if (wp_context->token > 0) connman_proxy_lookup_cancel(wp_context->token); if (wp_context->request_id > 0) g_web_cancel_request(wp_context->web, wp_context->request_id); if (wp_context->timeout > 0) g_source_remove(wp_context->timeout); if (wp_context->web) g_web_unref(wp_context->web); g_free(wp_context->redirect_url); if (wp_context->wispr_parser) g_web_parser_unref(wp_context->wispr_parser); connman_wispr_message_init(&wp_context->wispr_msg); g_free(wp_context->wispr_username); g_free(wp_context->wispr_password); g_free(wp_context->wispr_formdata); free_wispr_routes(wp_context); connman_service_unref(wp_context->service); g_free(wp_context); }
int main(int argc, char *argv[]) { GOptionContext *context; GError *error = NULL; struct sigaction sa; struct wispr_session wispr; int index = 0; context = g_option_context_new(NULL); g_option_context_add_main_entries(context, options, NULL); if (g_option_context_parse(context, &argc, &argv, &error) == FALSE) { if (error != NULL) { g_printerr("%s\n", error->message); g_error_free(error); } else g_printerr("An unknown error occurred\n"); return 1; } g_option_context_free(context); memset(&wispr, 0, sizeof(wispr)); wispr_msg_init(&wispr.msg); wispr.web = g_web_new(index); if (wispr.web == NULL) { fprintf(stderr, "Failed to create web service\n"); return 1; } if (option_debug == TRUE) g_web_set_debug(wispr.web, web_debug, "WEB"); main_loop = g_main_loop_new(NULL, FALSE); if (option_nameserver != NULL) { g_web_add_nameserver(wispr.web, option_nameserver); g_free(option_nameserver); } g_web_set_accept(wispr.web, NULL); g_web_set_user_agent(wispr.web, "SmartClient/%s wispr", VERSION); g_web_set_close_connection(wispr.web, TRUE); if (option_url == NULL) option_url = g_strdup(DEFAULT_URL); wispr.username = option_username; wispr.password = option_password; wispr.originurl = option_url; timer = g_timer_new(); wispr.parser = g_web_parser_new("<WISPAccessGatewayParam", "WISPAccessGatewayParam>", parser_callback, &wispr); wispr.request = g_web_request_get(wispr.web, option_url, wispr_result, &wispr); if (wispr.request == 0) { fprintf(stderr, "Failed to start request\n"); return 1; } memset(&sa, 0, sizeof(sa)); sa.sa_handler = sig_term; sigaction(SIGINT, &sa, NULL); sigaction(SIGTERM, &sa, NULL); g_main_loop_run(main_loop); g_timer_destroy(timer); if (wispr.request > 0) g_web_cancel_request(wispr.web, wispr.request); g_web_parser_unref(wispr.parser); g_web_unref(wispr.web); g_main_loop_unref(main_loop); g_free(wispr.username); g_free(wispr.password); g_free(wispr.originurl); return 0; }