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; }
static int wispr_portal_detect(struct connman_wispr_portal_context *wp_context) { enum connman_service_proxy_method proxy_method; enum connman_service_type service_type; char *interface = NULL; char **nameservers = NULL; int if_index; int err = 0; int i; DBG("wispr/portal context %p service %p", wp_context, wp_context->service); service_type = connman_service_get_type(wp_context->service); switch (service_type) { case CONNMAN_SERVICE_TYPE_ETHERNET: case CONNMAN_SERVICE_TYPE_WIFI: case CONNMAN_SERVICE_TYPE_BLUETOOTH: case CONNMAN_SERVICE_TYPE_CELLULAR: case CONNMAN_SERVICE_TYPE_GADGET: break; case CONNMAN_SERVICE_TYPE_UNKNOWN: case CONNMAN_SERVICE_TYPE_SYSTEM: case CONNMAN_SERVICE_TYPE_GPS: case CONNMAN_SERVICE_TYPE_VPN: case CONNMAN_SERVICE_TYPE_P2P: return -EOPNOTSUPP; } interface = connman_service_get_interface(wp_context->service); if (!interface) return -EINVAL; DBG("interface %s", interface); if_index = connman_inet_ifindex(interface); if (if_index < 0) { DBG("Could not get ifindex"); err = -EINVAL; goto done; } nameservers = connman_service_get_nameservers(wp_context->service); if (!nameservers) { DBG("Could not get nameservers"); err = -EINVAL; goto done; } wp_context->web = g_web_new(if_index); if (!wp_context->web) { DBG("Could not set up GWeb"); err = -ENOMEM; goto done; } if (getenv("CONNMAN_WEB_DEBUG")) g_web_set_debug(wp_context->web, web_debug, "WEB"); if (wp_context->type == CONNMAN_IPCONFIG_TYPE_IPV4) { g_web_set_address_family(wp_context->web, AF_INET); wp_context->status_url = STATUS_URL_IPV4; } else { g_web_set_address_family(wp_context->web, AF_INET6); wp_context->status_url = STATUS_URL_IPV6; } for (i = 0; nameservers[i]; i++) g_web_add_nameserver(wp_context->web, nameservers[i]); proxy_method = connman_service_get_proxy_method(wp_context->service); if (proxy_method != CONNMAN_SERVICE_PROXY_METHOD_DIRECT) { wp_context->token = connman_proxy_lookup(interface, wp_context->status_url, wp_context->service, proxy_callback, wp_context); if (wp_context->token == 0) { err = -EINVAL; free_connman_wispr_portal_context(wp_context); } } else if (wp_context->timeout == 0) { wp_context->timeout = g_idle_add(no_proxy_callback, wp_context); } done: g_strfreev(nameservers); g_free(interface); return err; }