summaryrefslogtreecommitdiff
path: root/src/wispr.c
diff options
context:
space:
mode:
authorTomasz Bursztyka <tomasz.bursztyka@linux.intel.com>2011-08-29 18:25:07 +0300
committerSamuel Ortiz <sameo@linux.intel.com>2011-09-12 19:45:54 +0200
commit3b89d5171aaff25dbd8f813f2e64f60067f7df4d (patch)
tree820e42807a8130389599f00a12627ff147b05c11 /src/wispr.c
parentb5c92ef3e1b00bc2c49b3d12632284ac3c4ba156 (diff)
downloadconnman-3b89d5171aaff25dbd8f813f2e64f60067f7df4d.tar.gz
connman-3b89d5171aaff25dbd8f813f2e64f60067f7df4d.tar.bz2
connman-3b89d5171aaff25dbd8f813f2e64f60067f7df4d.zip
wispr: Requesting login input through the agent
Diffstat (limited to 'src/wispr.c')
-rw-r--r--src/wispr.c76
1 files changed, 76 insertions, 0 deletions
diff --git a/src/wispr.c b/src/wispr.c
index dd093bc7..05c3ec66 100644
--- a/src/wispr.c
+++ b/src/wispr.c
@@ -65,6 +65,10 @@ struct connman_wispr_portal_context {
GWebParser *wispr_parser;
struct connman_wispr_message wispr_msg;
+ char *wispr_username;
+ char *wispr_password;
+ char *wispr_formdata;
+
enum connman_wispr_result wispr_result;
};
@@ -124,6 +128,10 @@ static void free_connman_wispr_portal_context(struct connman_wispr_portal_contex
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);
+
g_free(wp_context);
}
@@ -383,6 +391,60 @@ static void wispr_portal_request_portal(struct connman_wispr_portal_context *wp_
wispr_portal_error(wp_context);
}
+static gboolean wispr_input(const guint8 **data, gsize *length,
+ gpointer user_data)
+{
+ struct connman_wispr_portal_context *wp_context = user_data;
+ GString *buf;
+ gsize count;
+
+ DBG("");
+
+ buf = g_string_sized_new(100);
+
+ g_string_append(buf, "button=Login&UserName=");
+ g_string_append_uri_escaped(buf, wp_context->wispr_username,
+ NULL, FALSE);
+ g_string_append(buf, "&Password=");
+ g_string_append_uri_escaped(buf, wp_context->wispr_password,
+ NULL, FALSE);
+ g_string_append(buf, "&FNAME=0&OriginatingServer=");
+ g_string_append_uri_escaped(buf, STATUS_URL, NULL, FALSE);
+
+ count = buf->len;
+
+ g_free(wp_context->wispr_formdata);
+ wp_context->wispr_formdata = g_string_free(buf, FALSE);
+
+ *data = (guint8 *) wp_context->wispr_formdata;
+ *length = count;
+
+ return FALSE;
+}
+
+static void wispr_portal_request_wispr_login(struct connman_service *service,
+ const char *username, const char *password,
+ void *user_data)
+{
+ struct connman_wispr_portal_context *wp_context = user_data;
+
+ DBG("");
+
+ g_free(wp_context->wispr_username);
+ wp_context->wispr_username = g_strdup(username);
+
+ g_free(wp_context->wispr_password);
+ wp_context->wispr_password = g_strdup(password);
+
+ wp_context->request_id = g_web_request_post(wp_context->web,
+ wp_context->wispr_msg.login_url,
+ "application/x-www-form-urlencoded",
+ wispr_input, wispr_portal_web_result,
+ wp_context);
+
+ connman_wispr_message_init(&wp_context->wispr_msg);
+}
+
static gboolean wispr_manage_message(GWebResult *result,
struct connman_wispr_portal_context *wp_context)
{
@@ -416,12 +478,24 @@ static gboolean wispr_manage_message(GWebResult *result,
wp_context->wispr_result = CONNMAN_WISPR_RESULT_LOGIN;
+ __connman_agent_request_login_input(wp_context->service,
+ wispr_portal_request_wispr_login,
+ wp_context);
break;
case 120: /* Falling down */
case 140:
if (wp_context->wispr_msg.response_code == 50) {
wp_context->wispr_result = CONNMAN_WISPR_RESULT_ONLINE;
+ g_free(wp_context->wispr_username);
+ wp_context->wispr_username = NULL;
+
+ g_free(wp_context->wispr_password);
+ wp_context->wispr_password = NULL;
+
+ g_free(wp_context->wispr_formdata);
+ wp_context->wispr_formdata = NULL;
+
wispr_portal_request_portal(wp_context);
return TRUE;
@@ -479,6 +553,8 @@ static gboolean wispr_portal_web_result(GWebResult *result, gpointer user_data)
if (g_web_result_get_header(result, "X-ConnMan-Status",
&str) == TRUE)
portal_manage_status(result, wp_context);
+ else
+ __connman_service_request_login(wp_context->service);
break;
case 302: