[Sugar-devel] [PATCH v3 Browse] Store web session cookies in SQlite database, for SL #3456

Manuel Quiñones manuq at laptop.org
Thu Apr 19 12:51:57 EDT 2012


El día 19 de abril de 2012 13:45, Manuel Quiñones <manuq at laptop.org> escribió:
> There was code in Browse to create a SQlite database under data
> directory in the activity profile.  This was for creating a cookie to
> authenticate the laptop with a schoolserver.
>
> Now we use the same database via the Soup library to store all cookies
> so they are persistent between sessions.  A Soup cookie jar is being
> attached to the WebKit session, cookies are stored in a Mozilla
> compatible SQLite format.
>
> The schoolserver function has been changed to use the Soup API.
>
> The code is based in Epiphany, embed/ephy-embed-single.c .
>
> ------
>
> v1->v2: let Soup take care of database creation, use Soup API in
> schoolserver cookie seed function
>
> v2->v3: use proper constructors for PyGI instead of new()
>
> Signed-off-by: Manuel Quiñones <manuq at laptop.org>
> ---
>  webactivity.py |   79 ++++++++++++++++++++++++-------------------------------
>  1 files changed, 35 insertions(+), 44 deletions(-)
>
> diff --git a/webactivity.py b/webactivity.py
> index aadc29a..611e3b2 100644
> --- a/webactivity.py
> +++ b/webactivity.py
> @@ -28,6 +28,8 @@ from gi.repository import Gtk
>  from gi.repository import Gdk
>  from gi.repository import GdkPixbuf
>  from gi.repository import WebKit
> +from gi.repository import Soup
> +from gi.repository import SoupGNOME
>
>  import base64
>  import time
> @@ -58,6 +60,7 @@ PROFILE_VERSION = 2
>  _profile_version = 0
>  _profile_path = os.path.join(activity.get_activity_root(), 'data/gecko')
>  _version_file = os.path.join(_profile_path, 'version')
> +_cookies_db_path = os.path.join(_profile_path, 'cookies.sqlite')
>
>  if os.path.exists(_version_file):
>     f = open(_version_file)
> @@ -76,15 +79,25 @@ if _profile_version < PROFILE_VERSION:
>     f.close()
>
>
> -def _seed_xs_cookie():
> -    ''' Create a HTTP Cookie to authenticate with the Schoolserver
> -    '''
> +def _seed_xs_cookie(cookie_jar):
> +    """Create a HTTP Cookie to authenticate with the Schoolserver.
> +
> +    Do nothing if the laptop is not registered with Schoolserver, or
> +    if the cookie already exists.
> +
> +    """
>     client = GConf.Client.get_default()
>     backup_url = client.get_string('/desktop/sugar/backup_url')
> -    if not backup_url:
> +    if backup_url == '':
>         _logger.debug('seed_xs_cookie: Not registered with Schoolserver')
>         return
>
> +    soup_uri = Soup.URI.new(uri_string=backup_url)
> +    xs_cookie = cookie_jar.get_cookies(soup_uri, for_http=False)
> +    if xs_cookie is not None:
> +        _logger.debug('seed_xs_cookie: Cookie exists already')
> +        return

Daniel, above is the only new() constructor pending, I cannot find a
replacement for it,  Soup.URI(uri_string=backup_url) gives error,
there's no method in Soup.URI to setup with a uri string.  I can do
uri.set_host() and uri.set_scheme(), but I have to split backup_url
for that, and I don't know what kind of url is it.

Someone should try this in a School Server before commiting

-- 
.. manuq ..


More information about the Sugar-devel mailing list