Change service name from org.moblin.connman to net.connman
[framework/connectivity/connman.git] / tools / wispr.c
index 2b44288..e43208d 100644 (file)
@@ -103,6 +103,7 @@ struct wispr_msg {
        int message_type;
        int response_code;
        char *login_url;
+       char *abort_login_url;
        char *logoff_url;
        char *access_procedure;
        char *access_location;
@@ -120,6 +121,9 @@ static inline void wispr_msg_init(struct wispr_msg *msg)
        g_free(msg->login_url);
        msg->login_url = NULL;
 
+       g_free(msg->abort_login_url);
+       msg->abort_login_url = NULL;
+
        g_free(msg->logoff_url);
        msg->logoff_url = NULL;
 
@@ -144,7 +148,7 @@ struct wispr_session {
        char *formdata;
 };
 
-static void execute_login(struct wispr_session *wispr);
+static gboolean execute_login(gpointer user_data);
 
 static struct {
        const char *str;
@@ -219,9 +223,11 @@ static void text_handler(GMarkupParseContext *context,
                case WISPR_ELEMENT_ACCESS_PROCEDURE:
                        g_free(msg->access_procedure);
                        msg->access_procedure = g_strdup(text);
+                       break;
                case WISPR_ELEMENT_ACCESS_LOCATION:
                        g_free(msg->access_location);
                        msg->access_location = g_strdup(text);
+                       break;
                case WISPR_ELEMENT_LOCATION_NAME:
                        g_free(msg->location_name);
                        msg->location_name = g_strdup(text);
@@ -231,6 +237,8 @@ static void text_handler(GMarkupParseContext *context,
                        msg->login_url = g_strdup(text);
                        break;
                case WISPR_ELEMENT_ABORT_LOGIN_URL:
+                       g_free(msg->abort_login_url);
+                       msg->abort_login_url = g_strdup(text);
                        break;
                case WISPR_ELEMENT_MESSAGE_TYPE:
                        msg->message_type = atoi(text);
@@ -361,7 +369,7 @@ static gboolean user_input(const char *label, gboolean hidden,
        data->user_data = user_data;
        data->hidden = hidden;
 
-       data->fd = open("/dev/tty", O_RDWR | O_NOCTTY | O_CLOEXEC);
+       data->fd = open("/dev/tty", O_RDWR | O_NOCTTY);
        if (data->fd < 0)
                goto error;
 
@@ -434,14 +442,25 @@ static gboolean wispr_input(const guint8 **data, gsize *length,
                                                gpointer user_data)
 {
        struct wispr_session *wispr = user_data;
+       GString *buf;
+       gsize count;
+
+       buf = g_string_sized_new(100);
+
+       g_string_append(buf, "button=Login&UserName=");
+       g_string_append_uri_escaped(buf, wispr->username, NULL, FALSE);
+       g_string_append(buf, "&Password=");
+       g_string_append_uri_escaped(buf, wispr->password, NULL, FALSE);
+       g_string_append(buf, "&FNAME=0&OriginatingServer=");
+       g_string_append_uri_escaped(buf, wispr->originurl, NULL, FALSE);
+
+       count = buf->len;
 
        g_free(wispr->formdata);
-       wispr->formdata = g_strdup_printf("button=Login&UserName=%s&"
-                       "Password=%s&FNAME=0&OriginatingServer=%s",
-                       wispr->username, wispr->password, wispr->originurl);
+       wispr->formdata = g_string_free(buf, FALSE);
 
        *data = (guint8 *) wispr->formdata;
-       *length = strlen(wispr->formdata);
+       *length = count;
 
        return FALSE;
 }
@@ -489,6 +508,8 @@ static gboolean wispr_result(GWebResult *result, gpointer user_data)
                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");
@@ -504,7 +525,7 @@ static gboolean wispr_result(GWebResult *result, gpointer user_data)
                        return FALSE;
                }
 
-               execute_login(wispr);
+               g_idle_add(execute_login, wispr);
                return FALSE;
        } else if (status == 200 && wispr->msg.message_type == 120) {
                int code = wispr->msg.response_code;
@@ -518,13 +539,17 @@ done:
        return FALSE;
 }
 
-static void execute_login(struct wispr_session *wispr)
+static gboolean execute_login(gpointer user_data)
 {
+       struct wispr_session *wispr = user_data;
+
        wispr->request = g_web_request_post(wispr->web, wispr->msg.login_url,
                                        "application/x-www-form-urlencoded",
                                        wispr_input, wispr_result, wispr);
 
        wispr_msg_init(&wispr->msg);
+
+       return FALSE;
 }
 
 static gboolean option_debug = FALSE;