If it detects a WISPr 2.0 enabled AP which supports both versions,
it will try the usual method from WISPr 1.0.
---
 tools/wispr.c |   73 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++-
 1 files changed, 72 insertions(+), 1 deletions(-)

diff --git a/tools/wispr.c b/tools/wispr.c
index 9732c3c..ff29dc7 100644
--- a/tools/wispr.c
+++ b/tools/wispr.c
@@ -115,9 +115,17 @@ static const char *response_code_to_string(int 
response_code)
        return NULL;
 }
 
+enum wispr_version {
+       WISPR_VERSION_UNKNOWN = 0,
+       WISPR_VERSION_1_0     = 1,
+       WISPR_VERSION_2_0     = 2,
+};
+
 struct wispr_msg {
        gboolean has_error;
        const char *current_element;
+       enum wispr_version version_low;
+       enum wispr_version version_high;
        int message_type;
        int response_code;
        char *login_url;
@@ -133,6 +141,8 @@ static inline void wispr_msg_init(struct wispr_msg *msg)
        msg->has_error = FALSE;
        msg->current_element = NULL;
 
+       msg->version_low = WISPR_VERSION_UNKNOWN;
+       msg->version_high = WISPR_VERSION_UNKNOWN;
        msg->message_type = -1;
        msg->response_code = -1;
 
@@ -158,6 +168,8 @@ static inline void wispr_msg_init(struct wispr_msg *msg)
 struct wispr_session {
        GWeb *web;
        GWebParser *parser;
+       enum wispr_version version;
+       gboolean retro_compatible;
        guint request;
        struct wispr_msg msg;
        char *username;
@@ -184,6 +196,8 @@ static struct {
                WISPR_ELEMENT_REPLY_MESSAGE,
                WISPR_ELEMENT_LOGIN_RESULTS_URL,
                WISPR_ELEMENT_LOGOFF_URL,
+               WISPR_ELEMENT_VERSION_LOW,
+               WISPR_ELEMENT_VERSION_HIGH,
        } element;
 } wispr_element_map[] = {
        { "AccessProcedure",    WISPR_ELEMENT_ACCESS_PROCEDURE  },
@@ -198,6 +212,8 @@ static struct {
        { "ReplyMessage",       WISPR_ELEMENT_REPLY_MESSAGE     },
        { "LoginResultsURL",    WISPR_ELEMENT_LOGIN_RESULTS_URL },
        { "LogoffURL",          WISPR_ELEMENT_LOGOFF_URL        },
+       { "VersionLow",         WISPR_ELEMENT_VERSION_LOW       },
+       { "VersionHigh",        WISPR_ELEMENT_VERSION_HIGH      },
        { NULL,                 WISPR_ELEMENT_NONE              },
 };
 
@@ -221,6 +237,16 @@ static void end_element_handler(GMarkupParseContext 
*context,
        msg->current_element = NULL;
 }
 
+static enum wispr_version version_element_parser(const char *text)
+{
+       if (g_str_has_prefix(text, "1.") == TRUE)
+               return WISPR_VERSION_1_0;
+       if (g_str_has_prefix(text, "2.") == TRUE)
+               return WISPR_VERSION_2_0;
+
+       return WISPR_VERSION_UNKNOWN;
+}
+
 static void text_handler(GMarkupParseContext *context,
                                        const gchar *text, gsize text_len,
                                        gpointer user_data, GError **error)
@@ -273,6 +299,12 @@ static void text_handler(GMarkupParseContext *context,
                        g_free(msg->logoff_url);
                        msg->logoff_url = g_strdup(text);
                        break;
+               case WISPR_ELEMENT_VERSION_LOW:
+                       msg->version_low = version_element_parser(text);
+                       break;
+               case WISPR_ELEMENT_VERSION_HIGH:
+                       msg->version_high = version_element_parser(text);
+                       break;
                }
        }
 }
@@ -472,7 +504,11 @@ static gboolean wispr_input(const guint8 **data, gsize 
*length,
        GString *buf;
        gsize count;
 
-       buf = g_string_sized_new(100);
+       buf = g_string_sized_new(128);
+
+       if (wispr->version == WISPR_VERSION_2_0 &&
+                                       wispr->retro_compatible == TRUE)
+               g_string_append(buf, "WISPrVersion=1.0&");
 
        g_string_append(buf, "button=Login&UserName=");
        g_string_append_uri_escaped(buf, wispr->username, NULL, FALSE);
@@ -510,6 +546,29 @@ static gboolean wispr_route(const char *addr, int 
ai_family, int if_index,
        return TRUE;
 }
 
+static void interpret_wispr_version(struct wispr_session *wispr)
+{
+       struct wispr_msg *msg = &wispr->msg;
+
+       if (msg->version_low == WISPR_VERSION_UNKNOWN &&
+                       msg->version_high == WISPR_VERSION_UNKNOWN)
+               return;
+
+       if (msg->version_low == WISPR_VERSION_1_0 &&
+                       msg->version_high == WISPR_VERSION_2_0) {
+               wispr->version = WISPR_VERSION_2_0;
+               wispr->retro_compatible = TRUE;
+
+               return;
+       }
+
+       if (msg->version_low == WISPR_VERSION_2_0 &&
+                       msg->version_high == WISPR_VERSION_2_0) {
+               wispr->version = WISPR_VERSION_2_0;
+               wispr->retro_compatible = FALSE;
+       }
+}
+
 static gboolean wispr_result(GWebResult *result, gpointer user_data)
 {
        struct wispr_session *wispr = user_data;
@@ -579,6 +638,14 @@ static gboolean wispr_result(GWebResult *result, gpointer 
user_data)
                goto done;
 
        if (wispr->msg.message_type == 100) {
+               interpret_wispr_version(wispr);
+
+               if (wispr->version == WISPR_VERSION_2_0 &&
+                               wispr->retro_compatible == FALSE) {
+                       printf("WISPr 2.0 only is not supported!\n");
+                       goto done;
+               }
+
                if (wispr->username == NULL) {
                        user_input("Username", FALSE, username_callback, wispr);
                        return FALSE;
@@ -677,6 +744,10 @@ int main(int argc, char *argv[])
        g_option_context_free(context);
 
        memset(&wispr, 0, sizeof(wispr));
+
+       /* By default we use version 1.0 */
+       wispr.version = WISPR_VERSION_1_0;
+
        wispr_msg_init(&wispr.msg);
 
        wispr.web = g_web_new(index);
-- 
1.7.8.5

_______________________________________________
connman mailing list
[email protected]
http://lists.connman.net/listinfo/connman

Reply via email to