Re: [PATCH 2/5] connectivity: Add libxml2 as a dependency

2013-02-19 Thread Jonh Wendell
One note: The original patch was supposed to handle 511 http status code,
not wispr. see http://tools.ietf.org/html/rfc6585


2013/2/19 Marcel Holtmann 

> Hi Dan,
>
> > > > Plus, as I stated earlier, libxml will be required to handle Wispr
> > > > responses (and hotspot 2.0), which are legitimate XML trees. So, why
> not
> > > > just add it as a dependency right now?
> > >
> > > that is a funny comment since within ConnMan, we are using GMarkup to
> > > handle the WISPr login. And actually if you are looking at anything of
> > > the HTML except the WISPr XML you are doing something wrong. Do not
> > > bother parsing the HTML page. Either operators add the WISPr XML
> > > somewhere or they end up hiding it in comment section.
> > >
> > > I am also confused what Hotspot 2.0 has to do with XML. Am I reading a
> > > different specification than you are?
> >
> > Yeah I think GMarkup can handle most of the XML stuff.  But if we want
> > to better handle random hotspots in the future (like my hotel one) we
> > may need to do some HTML parsing.  I don't necessarily think that would
> > require XML though, perhaps just regex.
>
> if your hotel does not support WISPr you are most certainly on the
> loosing end with trying to figure out anything. We have never bothered
> to try to handle these. They just trigger the opening of a browser.
>
> There exists in theory another protocol besides WISPr that early Boingo
> hotspots used, but I have not seen it in a long time. I think the last
> one was Swisscom and they also support WISPr. So rather pointless trying
> to chase that one down.
>
> Only trick part is the the XML from WISPr is not always present on the
> first page the hostpot returns. Sometimes it is on the second or later.
> One example for such a setup is Orange in France. However all the
> hotspot do use a proper HTTP Location header and thus no need to parse
> HTML ever.
>
> Regards
>
> Marcel
>
>
>


-- 
Jonh Wendell
http://www.bani.com.br
___
networkmanager-list mailing list
networkmanager-list@gnome.org
https://mail.gnome.org/mailman/listinfo/networkmanager-list


Re: [PATCH 2/5] connectivity: Add libxml2 as a dependency

2013-02-13 Thread Jonh Wendell
Hi Dan.

2013/2/11 Dan Williams 

> On Mon, 2013-02-11 at 15:30 -0200, Jonh Wendell wrote:
> > In these patches I want to fix the 511-http-status. As it's something
> > new, of course most hotspots don't use that (including my employer).
> >
> > Almost all of them rely on 30X Moved with help of the Wispr
> > 'pseudo-protocol'. It's on my TODO list to work on those scenarios.
> > That would touch only code in NMConnectivity object.
> >
> >
> > Indeed, for that cases, we would use xml parsing as wispr is xml.
>
> Thanks for the clarification.  In any case, would a regex be possible
> here instead of the XML for now?  It might be less code and would
> certainly be less error-prone when checking broken HTML which is quite
> common.
>

I'm not sure if parsing a HTML with regex is less error-prone. There are
lots of traps in mal-formed HTML, or even if legitimate HTML structs like



So, I'd prefer to rely on libxml which is supposed to be more smart than a
simple regex.
In the patch, I'm using the flags 'HTML_PARSE_NOERROR |
HTML_PARSE_NOWARNING' so that libxml doesn't complain about broken HTML. In
fact, I've tested here some broken HTML and it was parsed successfully by
libxml.

Plus, as I stated earlier, libxml will be required to handle Wispr
responses (and hotspot 2.0), which are legitimate XML trees. So, why not
just add it as a dependency right now?


> Dan
>
> >
> >
> > 2013/2/11 Dan Williams 
> > On Mon, 2013-02-11 at 17:10 +0100, Bastien Nocera wrote:
> >     > On Mon, 2013-02-11 at 10:06 -0600, Dan Williams wrote:
> > > > On Mon, 2013-02-11 at 12:09 -0200, Jonh Wendell wrote:
> > > > > From: Jonh Wendell 
> > > > >
> > > > > libsoup already depends on libxml2 but we need to
> > explicitly link
> > > > > to it.
> > > >
> > > > At least we already theoretically required it; though is
> > it possible to
> > > > use GMarkup here instead of libxml2?  GMarkup would be
> > somewhat simpler,
> > > > though it's only a subset.
> > >
> > > Given how it's used, there's probably little reason this
> > couldn't be a
> > > regexp. Both GMarkup and libxml2 would choke on broken,
> > slightly broken,
> > > and very very broken HTML files.
> >
> >
> > Yeah, and I've heard that for example, some hotspots literally
> > just
> > append raw XML to the end of the HTTP request outside the
> > XML.  I think
> > we need to be somewhat more robust here and XML parsing may
> > not be the
> > way to get there?  Also, we may need to add special cases for
> > various
> > hotspots, which might require regex and not just XML parsing.
> >
> > Dan
> >
> >
> >
> >
> > --
> > Jonh Wendell
> > http://www.bani.com.br
> >
>
>
>


-- 
Jonh Wendell
http://www.bani.com.br
___
networkmanager-list mailing list
networkmanager-list@gnome.org
https://mail.gnome.org/mailman/listinfo/networkmanager-list


Re: [PATCH 5/5] api: Added the method CaptivePortalState()

2013-02-11 Thread Jonh Wendell
2013/2/11 Dan Williams 

> On Mon, 2013-02-11 at 12:09 -0200, Jonh Wendell wrote:
> > From: Jonh Wendell 
> >
> > It returns whether we are behind a captive portal and, if we are,
> > also returns the url to login at the hotspot.
>
> Any particular reason this is a method and not a property?  Also I think
> we may want more properties available later in which case it might be
> better to have a dict instead of a hard method signature.  There are a
> number of different portal types, and I think in the future we may want
> to have NM store some of the credentials for user login too.  Also,
> stuff like Hotspot 2.0 can use a SIM card on your WWAN modem to perform
> authentication and log into the hotspot automatically; we might need to
> pass more information to whatever actually handles the login stuff.
>

No, there's no strong reason to choose a method over a property. So, what's
more appropriate here? A method returning a dict or individual properties?
or both? :)


> Dan
>
> > Signed-off-by: Jonh Wendell 
> > ---
> >  introspection/nm-manager.xml | 20 
> >  src/nm-manager.c | 18 ++
> >  2 files changed, 38 insertions(+)
> >
> > diff --git a/introspection/nm-manager.xml b/introspection/nm-manager.xml
> > index 6f3c8ca..cd3c902 100644
> > --- a/introspection/nm-manager.xml
> > +++ b/introspection/nm-manager.xml
> > @@ -253,6 +253,26 @@
> >
> >  
> >
> > +
> > +  
> > +Indicates whether we are behind a captive portal. If we are, it
> also gives
> > +the login URL supplied by the captive portal. It only makes
> sense to call
> > +this method when the State is NM_STATE_CONNECTED_SITE.
> > +  
> > +   value="impl_manager_get_captive_portal_state"/>
> > +  
> > +
> > +  The boolean value indicating whether we are behind a captive
> portal.
> > +
> > +  
> > +  
> > +
> > +  If we are behind a captive portal, this contains the URL used
> to login on it.
> > +  A NULL value is valid here, meaning we couldn't guess the
> login URL.
> > +
> > +  
> > +
> > +
> >  
> >
> >  Indicates if overall networking is currently enabled or not.
>  See the
> > diff --git a/src/nm-manager.c b/src/nm-manager.c
> > index eb7eb9a..feb618d 100644
> > --- a/src/nm-manager.c
> > +++ b/src/nm-manager.c
> > @@ -120,6 +120,10 @@ static gboolean impl_manager_get_state (NMManager
> *manager,
> >  guint32 *state,
> >  GError **error);
> >
> > +static gboolean impl_manager_get_captive_portal_state (NMManager
> *manager,
> > +   gboolean
> *behind_captive_portal,
> > +   char
> **login_url);
> > +
> >  static gboolean impl_manager_set_logging (NMManager *manager,
> >const char *level,
> >const char *domains,
> > @@ -3691,6 +3695,20 @@ impl_manager_get_state (NMManager *manager,
> guint32 *state, GError **error)
> >  }
> >
> >  static gboolean
> > +impl_manager_get_captive_portal_state (NMManager *manager, gboolean
> *behind_captive_portal, char **login_url)
> > +{
> > +#if WITH_CONCHECK
> > + NMManagerPrivate *priv = NM_MANAGER_GET_PRIVATE (manager);
> > + *behind_captive_portal = nm_connectivity_get_state
> (priv->connectivity) == NM_CONNECTIVITY_STATE_BEHIND_CAPTIVE_PORTAL;
> > + *login_url = g_strdup (nm_connectivity_get_login_url
> (priv->connectivity));
> > +#else
> > + *behind_captive_portal = FALSE;
> > + *login_url = NULL;
> > +#endif
> > + return TRUE;
> > +}
> > +
> > +static gboolean
> >  impl_manager_set_logging (NMManager *manager,
> >const char *level,
> >const char *domains,
>
>
>


-- 
Jonh Wendell
http://www.bani.com.br
___
networkmanager-list mailing list
networkmanager-list@gnome.org
https://mail.gnome.org/mailman/listinfo/networkmanager-list


Re: [PATCH 0/5] Handle HTTP error 511

2013-02-11 Thread Jonh Wendell
2013/2/11 Dan Williams 

> On Mon, 2013-02-11 at 12:09 -0200, Jonh Wendell wrote:
> > From: Jonh Wendell 
> >
> > This series of patches fixes (on the NM side) bug #670394.
>
> Thanks for working on this!
>
> One thing I'm wondering is how we'd more quickly see whether the portal
> login was successful or not so we could change our NM state to show
> "online connected" instead of behind a portal.  There's two options
> here:
>
> 1) check every 5 or 10 seconds for connectivity until connectivity is
> successful; but this might make some portals angry
>

That's what I'm doing right now. It does *not* make portals angry. That's
what happen in real life, when someone joins the WiFi and thousands of user
programs try to reach the internet. What the hotspot do is just redirect
them and reply the http requests with a 302 Moved.

This leads to a discussion which I was expecting to have far later :) :
should we make connectivity code mandatory (right now it's compile-time
optional) and use some global machine (something like status.gnome.org) to
do the check.


> 2) have some mechanism for whatever handles the portal login to indicate
> to NetworkManager that login was successful, or that NM should
> reconnect/retry DHCP.  If this is what we want to do, we could move the
> captive portal stuff into the Agent interface since those processes are
> somewhat authenticated (as we already ask them for secrets) and they'd
> theoretically also have access to any portal auto-login credentials.
>

I didn't understand this point. Do we have something already authenticated?
I guess not. Even if the user already supplied the WiFi credentials (WPA,
etc) he's still behind a captive portal, and will still be redirected.


> Also, I got some captures of a portal in a hotel I was in recently, and
> for any HTTP request it returned (1) 305 Found with a Location header
> pointing to the next location, then (2) 302 Moved with another Location
> header pointing to the actual login page.  In this schemed we'd somehow
> detect this and then stuff the #2 Location URL into the login-url
> property I guess?
>

That would be certainly great to have. I'll think on that when implementing
the 'Moved 30x' thing.


> Dan
>
> > Basically we added a new method in the API: CaptivePortalState (), which
> > returns a boolean indicating whether we are behind a captive portal, and
> a
> > string that contains the login url, as supplied by the captive portal.
> >
> > The main change is in the internals of NMConnectivity object: We check
> if the
> > http status is 511 and the try to discover the login url. Currently we
> only check
> > for the url in the  html tag. There's room to improve this in the
> future.
> >
> > Next step will be to patch gnome-shell to make use of this new API and
> show to
> > the user a nice UI.
> >
> > For convenience, these patches are also hosted on github:
> > git://github.com/jwendell/NetworkManager.git (branch rfc6585)
> >
> > Jonh Wendell (5):
> >   connectivity: change the "connected" member for a more generic one
> >   connectivity: Add libxml2 as a dependency
> >   connectivity: Add the private member login_url
> >   connectivity: check for http response code 511
> >   api: Added the method CaptivePortalState()
> >
> >  configure.ac |  14 +++-
> >  introspection/nm-manager.xml |  20 +
> >  src/Makefile.am  |   4 +-
> >  src/nm-connectivity.c| 190
> ++-
> >  src/nm-connectivity.h|  22 +++--
> >  src/nm-manager.c |  43 --
> >  6 files changed, 234 insertions(+), 59 deletions(-)
> >
>
>
>


-- 
Jonh Wendell
http://www.bani.com.br
___
networkmanager-list mailing list
networkmanager-list@gnome.org
https://mail.gnome.org/mailman/listinfo/networkmanager-list


Re: [PATCH 2/5] connectivity: Add libxml2 as a dependency

2013-02-11 Thread Jonh Wendell
In these patches I want to fix the 511-http-status. As it's something new,
of course most hotspots don't use that (including my employer).

Almost all of them rely on 30X Moved with help of the Wispr
'pseudo-protocol'. It's on my TODO list to work on those scenarios. That
would touch only code in NMConnectivity object.

Indeed, for that cases, we would use xml parsing as wispr is xml.


2013/2/11 Dan Williams 

> On Mon, 2013-02-11 at 17:10 +0100, Bastien Nocera wrote:
> > On Mon, 2013-02-11 at 10:06 -0600, Dan Williams wrote:
> > > On Mon, 2013-02-11 at 12:09 -0200, Jonh Wendell wrote:
> > > > From: Jonh Wendell 
> > > >
> > > > libsoup already depends on libxml2 but we need to explicitly link
> > > > to it.
> > >
> > > At least we already theoretically required it; though is it possible to
> > > use GMarkup here instead of libxml2?  GMarkup would be somewhat
> simpler,
> > > though it's only a subset.
> >
> > Given how it's used, there's probably little reason this couldn't be a
> > regexp. Both GMarkup and libxml2 would choke on broken, slightly broken,
> > and very very broken HTML files.
>
> Yeah, and I've heard that for example, some hotspots literally just
> append raw XML to the end of the HTTP request outside the XML.  I think
> we need to be somewhat more robust here and XML parsing may not be the
> way to get there?  Also, we may need to add special cases for various
> hotspots, which might require regex and not just XML parsing.
>
> Dan
>
>


-- 
Jonh Wendell
http://www.bani.com.br
___
networkmanager-list mailing list
networkmanager-list@gnome.org
https://mail.gnome.org/mailman/listinfo/networkmanager-list


[PATCH 5/5] api: Added the method CaptivePortalState()

2013-02-11 Thread Jonh Wendell
From: Jonh Wendell 

It returns whether we are behind a captive portal and, if we are,
also returns the url to login at the hotspot.

Signed-off-by: Jonh Wendell 
---
 introspection/nm-manager.xml | 20 
 src/nm-manager.c | 18 ++
 2 files changed, 38 insertions(+)

diff --git a/introspection/nm-manager.xml b/introspection/nm-manager.xml
index 6f3c8ca..cd3c902 100644
--- a/introspection/nm-manager.xml
+++ b/introspection/nm-manager.xml
@@ -253,6 +253,26 @@
   
 
 
+
+  
+Indicates whether we are behind a captive portal. If we are, it also 
gives
+the login URL supplied by the captive portal. It only makes sense to 
call
+this method when the State is NM_STATE_CONNECTED_SITE.
+  
+  
+  
+
+  The boolean value indicating whether we are behind a captive portal.
+
+  
+  
+
+  If we are behind a captive portal, this contains the URL used to 
login on it.
+  A NULL value is valid here, meaning we couldn't guess the login URL.
+
+  
+
+
 
   
 Indicates if overall networking is currently enabled or not.  See the
diff --git a/src/nm-manager.c b/src/nm-manager.c
index eb7eb9a..feb618d 100644
--- a/src/nm-manager.c
+++ b/src/nm-manager.c
@@ -120,6 +120,10 @@ static gboolean impl_manager_get_state (NMManager *manager,
 guint32 *state,
 GError **error);
 
+static gboolean impl_manager_get_captive_portal_state (NMManager *manager,
+   gboolean 
*behind_captive_portal,
+   char **login_url);
+
 static gboolean impl_manager_set_logging (NMManager *manager,
   const char *level,
   const char *domains,
@@ -3691,6 +3695,20 @@ impl_manager_get_state (NMManager *manager, guint32 
*state, GError **error)
 }
 
 static gboolean
+impl_manager_get_captive_portal_state (NMManager *manager, gboolean 
*behind_captive_portal, char **login_url)
+{
+#if WITH_CONCHECK
+   NMManagerPrivate *priv = NM_MANAGER_GET_PRIVATE (manager);
+   *behind_captive_portal = nm_connectivity_get_state (priv->connectivity) 
== NM_CONNECTIVITY_STATE_BEHIND_CAPTIVE_PORTAL;
+   *login_url = g_strdup (nm_connectivity_get_login_url 
(priv->connectivity));
+#else
+   *behind_captive_portal = FALSE;
+   *login_url = NULL;
+#endif
+   return TRUE;
+}
+
+static gboolean
 impl_manager_set_logging (NMManager *manager,
   const char *level,
   const char *domains,
-- 
1.8.1.2

___
networkmanager-list mailing list
networkmanager-list@gnome.org
https://mail.gnome.org/mailman/listinfo/networkmanager-list


[PATCH 4/5] connectivity: check for http response code 511

2013-02-11 Thread Jonh Wendell
From: Jonh Wendell 

If 511 code is returned, try to find the URL for the captive portal
login. Currently it searches only in the 
tag.

Signed-off-by: Jonh Wendell 
---
 src/nm-connectivity.c | 111 +-
 1 file changed, 100 insertions(+), 11 deletions(-)

diff --git a/src/nm-connectivity.c b/src/nm-connectivity.c
index 6f63670..cb72aad 100644
--- a/src/nm-connectivity.c
+++ b/src/nm-connectivity.c
@@ -23,6 +23,8 @@
 
 #include 
 #include 
+#include 
+#include 
 
 #include "nm-connectivity.h"
 #include "nm-logging.h"
@@ -99,6 +101,82 @@ update_state (NMConnectivity *self, NMConnectivityState 
state)
g_object_notify (G_OBJECT (self), NM_CONNECTIVITY_STATE);
 }
 
+static xmlXPathObjectPtr
+getnodeset (xmlDocPtr doc, xmlChar *xpath)
+{
+   xmlXPathContextPtr context;
+   xmlXPathObjectPtr result;
+
+   context = xmlXPathNewContext(doc);
+   if (context == NULL)
+   return NULL;
+
+   result = xmlXPathEvalExpression (xpath, context);
+   xmlXPathFreeContext (context);
+   if (result == NULL)
+   return NULL;
+
+   if (xmlXPathNodeSetIsEmpty (result->nodesetval)) {
+   xmlXPathFreeObject (result);
+   return NULL;
+   }
+
+  return result;
+}
+
+static void
+nm_connectivity_find_login_url (NMConnectivity *self, SoupMessage *msg)
+{
+   NMConnectivityPrivate *priv = NM_CONNECTIVITY_GET_PRIVATE (self);
+   htmlDocPtr doc;
+   xmlNodeSetPtr nodeset;
+   xmlXPathObjectPtr result;
+   xmlChar *keyword;
+   int i;
+   gboolean found;
+
+   doc = htmlReadDoc ((xmlChar *) msg->response_body->data,
+  NULL,
+  NULL,
+  HTML_PARSE_NOERROR | 
HTML_PARSE_NOWARNING);
+   if (!doc) {
+   nm_log_dbg (LOGD_CORE, "Connectivity failed to discover the URL 
of the captive portal");
+   return;
+   }
+
+   result = getnodeset (doc, BAD_CAST "//meta");
+   if (!result) {
+   xmlFreeDoc (doc);
+   nm_log_dbg (LOGD_CORE, "Connectivity failed to discover the URL 
of the captive portal");
+   return;
+   }
+
+   nodeset = result->nodesetval;
+   for (i = 0, found = FALSE; i < nodeset->nodeNr && !found; i++) {
+   keyword = xmlGetProp (nodeset->nodeTab[i], BAD_CAST 
"http-equiv");
+   if (!xmlStrncmp (keyword, BAD_CAST "refresh", sizeof 
("refresh"))) {
+   xmlChar *prop = xmlGetProp (nodeset->nodeTab[i], 
BAD_CAST "content");
+   if (prop) {
+   gchar **url = g_strsplit ((const char *) prop, 
"=", 2);
+   if (g_strv_length (url) == 2) {
+   priv->login_url = g_strdup (url[1]);
+   nm_log_dbg (LOGD_CORE, "Connectivity: 
URL of the captive portal found: %s", url[1]);
+   found = TRUE;
+   }
+   g_strfreev (url);
+   xmlFree (prop);
+   }
+   }
+   xmlFree(keyword);
+   }
+
+   xmlXPathFreeObject (result);
+   xmlFreeDoc (doc);
+
+   if (!found)
+   nm_log_dbg (LOGD_CORE, "Connectivity failed to discover the URL 
of the captive portal");
+}
+
 static void
 nm_connectivity_check_cb (SoupSession *session, SoupMessage *msg, gpointer 
user_data)
 {
@@ -112,20 +190,31 @@ nm_connectivity_check_cb (SoupSession *session, 
SoupMessage *msg, gpointer user_
soup_uri = soup_message_get_uri (msg);
uri_string = soup_uri_to_string (soup_uri, FALSE);
 
-   /* Check headers; if we find the NM-specific one we're done */
-   nm_header = soup_message_headers_get_one (msg->response_headers, 
"X-NetworkManager-Status");
-   if (g_strcmp0 (nm_header, "online") == 0) {
-   nm_log_dbg (LOGD_CORE, "Connectivity check for uri '%s' with 
Status header successful.", uri_string);
-   state_new = NM_CONNECTIVITY_STATE_CONNECTED;
+   g_free (priv->login_url);
+   priv->login_url = NULL;
+
+   /* Check for the 511 status code (captive portals, rfc 6585) */
+   if (msg->status_code == 511) {
+   nm_connectivity_find_login_url (self, msg);
+   nm_log_dbg (LOGD_CORE, "Connectivity check for uri '%s' 
indicates we are behind a captive portal (status %d). Authentication URL: '%s'",
+   uri_string, msg->status_code, priv->login_url ? 
priv->login_ur

[PATCH 3/5] connectivity: Add the private member login_url

2013-02-11 Thread Jonh Wendell
From: Jonh Wendell 

It will contain, in the case we are behind a captive portal,
the url to login at the captive portal.

Signed-off-by: Jonh Wendell 
---
 src/nm-connectivity.c | 22 ++
 src/nm-connectivity.h | 15 +--
 2 files changed, 31 insertions(+), 6 deletions(-)

diff --git a/src/nm-connectivity.c b/src/nm-connectivity.c
index 51c1a5e..6f63670 100644
--- a/src/nm-connectivity.c
+++ b/src/nm-connectivity.c
@@ -51,6 +51,8 @@ typedef struct {
NMConnectivityState state;
/* the source id for the periodic check */
guint check_id;
+   /* if we are behind a captive portal, this is the url it redirects us */
+   char *login_url;
 } NMConnectivityPrivate;
 
 enum {
@@ -60,6 +62,7 @@ enum {
PROP_INTERVAL,
PROP_RESPONSE,
PROP_STATE,
+   PROP_LOGIN_URL,
LAST_PROP
 };
 
@@ -72,6 +75,14 @@ nm_connectivity_get_state (NMConnectivity *connectivity)
return NM_CONNECTIVITY_GET_PRIVATE (connectivity)->state;
 }
 
+const char *
+nm_connectivity_get_login_url (NMConnectivity *connectivity)
+{
+   g_return_val_if_fail (NM_IS_CONNECTIVITY (connectivity), NULL);
+
+   return NM_CONNECTIVITY_GET_PRIVATE (connectivity)->login_url;
+}
+
 static void
 update_state (NMConnectivity *self, NMConnectivityState state)
 {
@@ -273,6 +284,9 @@ get_property (GObject *object, guint property_id,
case PROP_STATE:
g_value_set_enum (value, priv->state);
break;
+   case PROP_LOGIN_URL:
+   g_value_set_string (value, priv->login_url);
+   break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
break;
@@ -363,5 +377,13 @@ nm_connectivity_class_init (NMConnectivityClass *klass)
NM_TYPE_CONNECTIVITY_STATE,
NM_CONNECTIVITY_STATE_NOT_CONNECTED,
G_PARAM_READABLE));
+
+   g_object_class_install_property
+   (object_class, PROP_LOGIN_URL,
+g_param_spec_string (NM_CONNECTIVITY_LOGIN_URL,
+ "Login URL",
+ "URL for login as supplied by the captive 
portal",
+ NULL,
+ G_PARAM_READABLE));
 }
 
diff --git a/src/nm-connectivity.h b/src/nm-connectivity.h
index c5ca692..1d62a67 100644
--- a/src/nm-connectivity.h
+++ b/src/nm-connectivity.h
@@ -40,6 +40,7 @@
 #define NM_CONNECTIVITY_INTERVAL  "interval"
 #define NM_CONNECTIVITY_RESPONSE  "response"
 #define NM_CONNECTIVITY_STATE "state"
+#define NM_CONNECTIVITY_LOGIN_URL "login-url"
 
 typedef enum {
NM_CONNECTIVITY_STATE_NOT_CONNECTED,
@@ -58,14 +59,16 @@ typedef struct {
 GType nm_connectivity_get_type (void);
 
 
-NMConnectivity *nm_connectivity_new   (const gchar *check_uri,
-   guint check_interval,
-   const gchar *check_response);
+NMConnectivity *nm_connectivity_new   (const gchar *check_uri,
+   guint check_interval,
+   const gchar 
*check_response);
 
-voidnm_connectivity_start_check (NMConnectivity *connectivity);
+voidnm_connectivity_start_check   (NMConnectivity 
*connectivity);
 
-voidnm_connectivity_stop_check  (NMConnectivity *connectivity);
+voidnm_connectivity_stop_check(NMConnectivity 
*connectivity);
 
-NMConnectivityState nm_connectivity_get_state   (NMConnectivity *connectivity);
+NMConnectivityState nm_connectivity_get_state (NMConnectivity 
*connectivity);
+
+const char *nm_connectivity_get_login_url (NMConnectivity 
*connectivity);
 
 #endif /* NM_CONNECTIVITY_H */
-- 
1.8.1.2

___
networkmanager-list mailing list
networkmanager-list@gnome.org
https://mail.gnome.org/mailman/listinfo/networkmanager-list


[PATCH 2/5] connectivity: Add libxml2 as a dependency

2013-02-11 Thread Jonh Wendell
From: Jonh Wendell 

libsoup already depends on libxml2 but we need to explicitly link
to it.

Signed-off-by: Jonh Wendell 
---
 configure.ac| 14 +++---
 src/Makefile.am |  4 ++--
 2 files changed, 13 insertions(+), 5 deletions(-)

diff --git a/configure.ac b/configure.ac
index 916561a..49a6203 100644
--- a/configure.ac
+++ b/configure.ac
@@ -573,15 +573,23 @@ fi
 AC_DEFINE_UNQUOTED(KERNEL_FIRMWARE_DIR, "$KERNEL_FIRMWARE_DIR", [Define to 
path of the kernel firmware directory])
 AC_SUBST(KERNEL_FIRMWARE_DIR)
 
+PKG_CHECK_MODULES(LIBXML, [libxml-2.0], [have_libxml=yes],[have_libxml=no])
 PKG_CHECK_MODULES(LIBSOUP, [libsoup-2.4 >= 2.26], 
[have_libsoup=yes],[have_libsoup=no])
+if test x"$have_libsoup" = x"yes" -a x"$have_libxml" = x"yes"; then
+can_have_connectivity="yes"
+else
+can_have_connectivity="no"
+fi
 AC_ARG_ENABLE(concheck, AS_HELP_STRING([--enable-concheck], [enable 
connectivity checking support]),
- [enable_concheck=${enableval}], 
[enable_concheck=${have_libsoup}])
+ [enable_concheck=${enableval}], 
[enable_concheck=${can_have_connectivity}])
 if (test "${enable_concheck}" = "yes"); then
-   if test x"$have_libsoup" = x"no"; then
-   AC_MSG_ERROR(Connectivity checking requires libsoup development 
headers)
+   if test x"$can_have_connectivity" = x"no"; then
+   AC_MSG_ERROR(Connectivity checking requires libsoup and libxml2 
development headers)
fi
AC_SUBST(LIBSOUP_CFLAGS)
AC_SUBST(LIBSOUP_LIBS)
+   AC_SUBST(LIBXML_CFLAGS)
+   AC_SUBST(LIBXML_LIBS)
AC_DEFINE(WITH_CONCHECK, 1, [Define if you want connectivity checking 
support])
 else
AC_DEFINE(WITH_CONCHECK, 0, [Define if you want connectivity checking 
support])
diff --git a/src/Makefile.am b/src/Makefile.am
index 9d306a7..54eaea9 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -316,7 +316,7 @@ NetworkManager_CPPFLAGS = \
-DARP_DEBUG
 
 if WITH_CONCHECK
-NetworkManager_CPPFLAGS += $(LIBSOUP_CFLAGS)
+NetworkManager_CPPFLAGS += $(LIBSOUP_CFLAGS) $(LIBXML_CFLAGS)
 endif
 
 if SESSION_TRACKING_CK
@@ -350,7 +350,7 @@ NetworkManager_LDADD = \
$(LIBDL)
 
 if WITH_CONCHECK
-NetworkManager_LDADD += $(LIBSOUP_LIBS)
+NetworkManager_LDADD += $(LIBSOUP_LIBS) $(LIBXML_LIBS)
 endif
 
 NetworkManager_LDFLAGS = -rdynamic
-- 
1.8.1.2

___
networkmanager-list mailing list
networkmanager-list@gnome.org
https://mail.gnome.org/mailman/listinfo/networkmanager-list


[PATCH 1/5] connectivity: change the "connected" member for a more generic one

2013-02-11 Thread Jonh Wendell
From: Jonh Wendell 

use now the enum "State", adding the "Behind Captive Portal" value.

Signed-off-by: Jonh Wendell 
---
 src/nm-connectivity.c | 59 +--
 src/nm-connectivity.h | 13 
 src/nm-manager.c  | 25 --
 3 files changed, 56 insertions(+), 41 deletions(-)

diff --git a/src/nm-connectivity.c b/src/nm-connectivity.c
index 7e0de2c..51c1a5e 100644
--- a/src/nm-connectivity.c
+++ b/src/nm-connectivity.c
@@ -27,6 +27,7 @@
 #include "nm-connectivity.h"
 #include "nm-logging.h"
 #include "nm-manager.h"
+#include "nm-enum-types.h"
 
 G_DEFINE_TYPE (NMConnectivity, nm_connectivity, G_TYPE_OBJECT)
 
@@ -46,8 +47,8 @@ typedef struct {
guint interval;
/* the expected response for the connectivity check */
char *response;
-   /* indicates if the last connection check was successful */
-   gboolean connected;
+   /* indicates the state of the last connection */
+   NMConnectivityState state;
/* the source id for the periodic check */
guint check_id;
 } NMConnectivityPrivate;
@@ -58,33 +59,33 @@ enum {
PROP_URI,
PROP_INTERVAL,
PROP_RESPONSE,
-   PROP_CONNECTED,
+   PROP_STATE,
LAST_PROP
 };
 
 
-gboolean
-nm_connectivity_get_connected (NMConnectivity *connectivity)
+NMConnectivityState
+nm_connectivity_get_state (NMConnectivity *connectivity)
 {
-   g_return_val_if_fail (NM_IS_CONNECTIVITY (connectivity), FALSE);
+   g_return_val_if_fail (NM_IS_CONNECTIVITY (connectivity), 
NM_CONNECTIVITY_STATE_NOT_CONNECTED);
 
-   return NM_CONNECTIVITY_GET_PRIVATE (connectivity)->connected;
+   return NM_CONNECTIVITY_GET_PRIVATE (connectivity)->state;
 }
 
 static void
-update_connected (NMConnectivity *self, gboolean connected)
+update_state (NMConnectivity *self, NMConnectivityState state)
 {
NMConnectivityPrivate *priv = NM_CONNECTIVITY_GET_PRIVATE (self);
-   gboolean old_connected = priv->connected;
+   NMConnectivityState old_state = priv->state;
 
if (priv->uri == NULL || priv->interval == 0) {
/* Default to connected if no checks are to be run */
-   priv->connected = TRUE;
+   priv->state = NM_CONNECTIVITY_STATE_CONNECTED;
} else
-   priv->connected = connected;
+   priv->state = state;
 
-   if (priv->connected != old_connected)
-   g_object_notify (G_OBJECT (self), NM_CONNECTIVITY_CONNECTED);
+   if (priv->state != old_state)
+   g_object_notify (G_OBJECT (self), NM_CONNECTIVITY_STATE);
 }
 
 static void
@@ -93,7 +94,7 @@ nm_connectivity_check_cb (SoupSession *session, SoupMessage 
*msg, gpointer user_
NMConnectivity *self = NM_CONNECTIVITY (user_data);
NMConnectivityPrivate *priv = NM_CONNECTIVITY_GET_PRIVATE (self);
SoupURI *soup_uri;
-   gboolean connected_new = FALSE;
+   NMConnectivityState state_new = NM_CONNECTIVITY_STATE_NOT_CONNECTED;
const char *nm_header;
char *uri_string;
 
@@ -104,13 +105,13 @@ nm_connectivity_check_cb (SoupSession *session, 
SoupMessage *msg, gpointer user_
nm_header = soup_message_headers_get_one (msg->response_headers, 
"X-NetworkManager-Status");
if (g_strcmp0 (nm_header, "online") == 0) {
nm_log_dbg (LOGD_CORE, "Connectivity check for uri '%s' with 
Status header successful.", uri_string);
-   connected_new = TRUE;
+   state_new = NM_CONNECTIVITY_STATE_CONNECTED;
} else {
/* check response */
if (msg->response_body->data && (g_str_has_prefix 
(msg->response_body->data, priv->response))) {
nm_log_dbg (LOGD_CORE, "Connectivity check for uri '%s' 
with expected response '%s' successful.",
uri_string, priv->response);
-   connected_new = TRUE;
+   state_new = NM_CONNECTIVITY_STATE_CONNECTED;
} else {
nm_log_dbg (LOGD_CORE, "Connectivity check for uri '%s' 
with expected response '%s' failed (status %d).",
uri_string, priv->response, 
msg->status_code);
@@ -119,7 +120,7 @@ nm_connectivity_check_cb (SoupSession *session, SoupMessage 
*msg, gpointer user_
g_free (uri_string);
 
/* update connectivity and emit signal */
-   update_connected (self, connected_new);
+   update_state (self, state_new);
 
priv->running = FALSE;
g_object_notify (G_OBJECT (self), NM_CONNECTIVITY_RUNNING);
@@ -186,7 +187,7 @@ nm_connectivity_stop_check (NMConnectivity *self)
  

[PATCH 0/5] Handle HTTP error 511

2013-02-11 Thread Jonh Wendell
From: Jonh Wendell 

This series of patches fixes (on the NM side) bug #670394.

Basically we added a new method in the API: CaptivePortalState (), which
returns a boolean indicating whether we are behind a captive portal, and a
string that contains the login url, as supplied by the captive portal.

The main change is in the internals of NMConnectivity object: We check if the
http status is 511 and the try to discover the login url. Currently we only 
check
for the url in the  html tag. There's room to improve this in the future.

Next step will be to patch gnome-shell to make use of this new API and show to
the user a nice UI.

For convenience, these patches are also hosted on github:
git://github.com/jwendell/NetworkManager.git (branch rfc6585)

Jonh Wendell (5):
  connectivity: change the "connected" member for a more generic one
  connectivity: Add libxml2 as a dependency
  connectivity: Add the private member login_url
  connectivity: check for http response code 511
  api: Added the method CaptivePortalState()

 configure.ac |  14 +++-
 introspection/nm-manager.xml |  20 +
 src/Makefile.am  |   4 +-
 src/nm-connectivity.c| 190 ++-
 src/nm-connectivity.h|  22 +++--
 src/nm-manager.c |  43 --
 6 files changed, 234 insertions(+), 59 deletions(-)

-- 
1.8.1.2

___
networkmanager-list mailing list
networkmanager-list@gnome.org
https://mail.gnome.org/mailman/listinfo/networkmanager-list


[PATCH] core: Honor CLI arguments when config file is not found

2013-01-29 Thread Jonh Wendell
If the config file is not present, the Config object is
returned empty, even if some configs were passed as command
line arguments.

This patch honor these arguments in that case.

Signed-off-by: Jonh Wendell 
---
 src/nm-config.c |   19 +++
 1 file changed, 19 insertions(+)

diff --git a/src/nm-config.c b/src/nm-config.c
index 6e801d3..f96eeed 100644
--- a/src/nm-config.c
+++ b/src/nm-config.c
@@ -268,6 +268,25 @@ nm_config_new (const char *cli_config_path,
 config->path = g_strdup (NM_DEFAULT_SYSTEM_CONF_FILE);
 fprintf (stderr, "No config file found or given; using %s\n",
  NM_DEFAULT_SYSTEM_CONF_FILE);
+
+/* Honor CLI parameters */
+if (cli_plugins && *cli_plugins)
+config->plugins = g_strsplit_set (cli_plugins, ",", 0);
+
+if (cli_log_level && *cli_log_level)
+config->log_level = g_strdup (cli_log_level);
+
+if (cli_log_domains && *cli_log_domains)
+config->log_domains = g_strdup (cli_log_domains);
+
+if (cli_connectivity_uri && *cli_connectivity_uri)
+config->connectivity_uri = g_strdup (cli_connectivity_uri);
+
+if (cli_connectivity_interval >= 0)
+config->connectivity_interval = cli_connectivity_interval;
+
+if (cli_connectivity_response && *cli_connectivity_response)
+config->connectivity_response = g_strdup
(cli_connectivity_response);
 }

 /* ignore error if config file not found */
-- 
1.7.10.4


-- 
Jonh Wendell
http://www.bani.com.br
___
networkmanager-list mailing list
networkmanager-list@gnome.org
https://mail.gnome.org/mailman/listinfo/networkmanager-list