Example #1
0
File: wispr.c Project: igaw/connman
static bool wispr_portal_web_result(GWebResult *result, gpointer user_data)
{
	struct connman_wispr_portal_context *wp_context = user_data;
	const char *redirect = NULL;
	const guint8 *chunk = NULL;
	const char *str = NULL;
	guint16 status;
	gsize length;

	DBG("");

	if (wp_context->wispr_result != CONNMAN_WISPR_RESULT_ONLINE) {
		g_web_result_get_chunk(result, &chunk, &length);

		if (length > 0) {
			g_web_parser_feed_data(wp_context->wispr_parser,
								chunk, length);
			return true;
		}

		g_web_parser_end_data(wp_context->wispr_parser);

		if (wp_context->wispr_msg.message_type >= 0) {
			if (wispr_manage_message(result, wp_context))
				goto done;
		}
	}

	status = g_web_result_get_status(result);

	DBG("status: %03u", status);

	switch (status) {
	case 000:
		__connman_agent_request_browser(wp_context->service,
				wispr_portal_browser_reply_cb,
				wp_context->status_url, wp_context);
		break;
	case 200:
		if (wp_context->wispr_msg.message_type >= 0)
			break;

		if (g_web_result_get_header(result, "X-ConnMan-Status",
						&str)) {
			portal_manage_status(result, wp_context);
			return false;
		} else
			__connman_agent_request_browser(wp_context->service,
					wispr_portal_browser_reply_cb,
					wp_context->redirect_url, wp_context);

		break;
	case 302:
		if (!g_web_supports_tls() ||
			!g_web_result_get_header(result, "Location",
							&redirect)) {

			__connman_agent_request_browser(wp_context->service,
					wispr_portal_browser_reply_cb,
					wp_context->status_url, wp_context);
			break;
		}

		DBG("Redirect URL: %s", redirect);

		wp_context->redirect_url = g_strdup(redirect);

		wp_context->request_id = g_web_request_get(wp_context->web,
				redirect, wispr_portal_web_result,
				wispr_route_request, wp_context);

		goto done;
	case 400:
	case 404:
		if (__connman_service_online_check_failed(wp_context->service,
						wp_context->type) == 0) {
			wispr_portal_error(wp_context);
			free_connman_wispr_portal_context(wp_context);
			return false;
		}

		break;
	case 505:
		__connman_agent_request_browser(wp_context->service,
				wispr_portal_browser_reply_cb,
				wp_context->status_url, wp_context);
		break;
	default:
		break;
	}

	free_wispr_routes(wp_context);
	wp_context->request_id = 0;
done:
	wp_context->wispr_msg.message_type = -1;
	return false;
}
Example #2
0
static gboolean wispr_result(GWebResult *result, gpointer user_data)
{
	struct wispr_session *wispr = user_data;
	const guint8 *chunk;
	gsize length;
	guint16 status;
	gdouble elapsed;

	g_web_result_get_chunk(result, &chunk, &length);

	if (length > 0) {
		//printf("%s\n", (char *) chunk);
		g_web_parser_feed_data(wispr->parser, chunk, length);
		return TRUE;
	}

	g_web_parser_end_data(wispr->parser);

	status = g_web_result_get_status(result);

	g_print("status: %03u\n", status);

	elapsed = g_timer_elapsed(timer, NULL);

	g_print("elapse: %f seconds\n", elapsed);

	if (wispr->msg.message_type < 0) {
		const char *redirect;

		if (status != 302)
			goto done;

		if (g_web_result_get_header(result, "Location",
							&redirect) == FALSE)
			goto done;

		printf("Redirect URL: %s\n", redirect);
		printf("\n");

		wispr->request = g_web_request_get(wispr->web, redirect,
							wispr_result, wispr);

		return FALSE;
	}

	printf("Message type: %s (%d)\n",
			message_type_to_string(wispr->msg.message_type),
						wispr->msg.message_type);
	printf("Response code: %s (%d)\n",
			response_code_to_string(wispr->msg.response_code),
						wispr->msg.response_code);
	if (wispr->msg.access_procedure != NULL)
		printf("Access procedure: %s\n", wispr->msg.access_procedure);
	if (wispr->msg.access_location != NULL)
		printf("Access location: %s\n", wispr->msg.access_location);
	if (wispr->msg.location_name != NULL)
		printf("Location name: %s\n", wispr->msg.location_name);
	if (wispr->msg.login_url != NULL)
		printf("Login URL: %s\n", wispr->msg.login_url);
	if (wispr->msg.abort_login_url != NULL)
		printf("Abort login URL: %s\n", wispr->msg.abort_login_url);
	if (wispr->msg.logoff_url != NULL)
		printf("Logoff URL: %s\n", wispr->msg.logoff_url);
	printf("\n");

	if (status != 200 && status != 302 && status != 404)
		goto done;

	if (wispr->msg.message_type == 100) {
		if (wispr->username == NULL) {
			user_input("Username", FALSE, username_callback, wispr);
			return FALSE;
		}

		if (wispr->password == NULL) {
			user_input("Password", TRUE, password_callback, wispr);
			return FALSE;
		}

		g_idle_add(execute_login, wispr);
		return FALSE;
	} else if (wispr->msg.message_type == 120 ||
					wispr->msg.message_type == 140) {
		int code = wispr->msg.response_code;
		printf("Login process: %s\n",
					code == 50 ? "SUCCESS" : "FAILURE");
	}

	if (status == 302) {
		const char *redirect;

		if (g_web_result_get_header(result, "Location",
							&redirect) == FALSE)
			goto done;

		printf("\n");
		printf("Redirect URL: %s\n", redirect);
		printf("\n");

		wispr->request = g_web_request_get(wispr->web, redirect,
							wispr_result, wispr);

		return FALSE;
	}

done:
	g_main_loop_quit(main_loop);

	return FALSE;
}
Example #3
0
static bool wispr_portal_web_result(GWebResult *result, gpointer user_data)
{
	struct connman_wispr_portal_context *wp_context = user_data;
	const char *redirect = NULL;
	const guint8 *chunk = NULL;
	const char *str = NULL;
	guint16 status;
	gsize length;
	bool skip_failed = false;

	DBG("");

	if (wp_context->wispr_result != CONNMAN_WISPR_RESULT_ONLINE) {
		g_web_result_get_chunk(result, &chunk, &length);

		if (length > 0) {
			g_web_parser_feed_data(wp_context->wispr_parser,
								chunk, length);
			return true;
		}

		g_web_parser_end_data(wp_context->wispr_parser);

//		if (wp_context->wispr_msg.message_type >= 0) {
//			if (wispr_manage_message(result, wp_context))
//				goto done;
//		}
	}

	status = g_web_result_get_status(result);

	DBG("status: %03u", status);

	switch (status) {
	case 200:
//		if (wp_context->wispr_msg.message_type >= 0)
//			break;

		if (g_web_result_get_header(result, "X-ConnMan-Status",
						&str)) {
			// Cancel browser requests if useragent has not returned anything
			connman_agent_cancel(wp_context->service);
			portal_manage_status(result, wp_context);
			return false;
		} else
			__connman_agent_request_browser(wp_context->service,
					wispr_portal_browser_reply_cb,
					wp_context->redirect_url, wp_context);
		break;
	case 204:
		// Cancel browser requests if useragent has not returned anything
		connman_agent_cancel(wp_context->service);
		portal_manage_status(result, wp_context);
		return false;
	case 302:
	DBG("tls %d, Location header %d",(!g_web_supports_tls() ), (!g_web_result_get_header(result, "Location",
										&redirect)));
		if (!g_web_supports_tls() ||
			!g_web_result_get_header(result, "Location",
							&redirect)) {

			__connman_agent_request_browser(wp_context->service,
					wispr_portal_browser_reply_cb,
					wp_context->status_url, wp_context);
			break;
		}

		DBG("Redirect URL: %s", redirect);
		DBG("Status url URL: %s", wp_context->status_url);

		wp_context->redirect_url = g_strdup(redirect);
		wp_context->request_id = g_web_request_get(wp_context->web,
				redirect, wispr_portal_web_result,
				wispr_route_request, wp_context);
		skip_failed = true;

		break;
	case 000:
		DBG("Redirect URL: %s", redirect);
		DBG("Status url URL: %s", wp_context->status_url);

		__connman_agent_request_browser(wp_context->service,
										wispr_portal_browser_reply_cb,
										wp_context->status_url, wp_context);
		break;
	case 400:
	case 404:

		break;
	case 505:
		DBG("HTTP version not supported, handling over to the browser");
		DBG("Redirect URL: %s", redirect);
		DBG("Status url URL: %s", wp_context->status_url);

		__connman_agent_request_browser(wp_context->service,
					wispr_portal_browser_reply_cb,
					wp_context->status_url, wp_context);
		break;
	default:
		break;
	}
	if (!skip_failed && __connman_service_online_check_failed(wp_context->service,
		wp_context->type) == 0) {
		wispr_portal_error(wp_context);
		free_connman_wispr_portal_context(wp_context);
		return false;
	}

	free_wispr_routes(wp_context);
	wp_context->request_id = 0;
	wp_context->wispr_msg.message_type = -1;
	return false;
}