Wexus2 0.20
wexus2.src/wexus/Cookies.h
00001 
00002 /*
00003  * Copyright (c) 2011 Aleksander B. Demko
00004  * This source code is distributed under the MIT license.
00005  * See the accompanying file LICENSE.MIT.txt for details.
00006  */
00007 
00008 #ifndef __INCLUDED_WEXUS_COOKIES_H__
00009 #define __INCLUDED_WEXUS_COOKIES_H__
00010 
00011 #include <wexus/HTTP.h>
00012 
00013 namespace wexus
00014 {
00015   class Cookies;
00016 }
00017 
00018 /**
00019  * This is collection of cookies, string values
00020  * mapped by string keys.
00021  * Internally, it uses the ClientCookies and ServerCookies
00022  * of HTTPRequest and HTTPReply.
00023  *
00024  * @author Aleksander Demko
00025  */ 
00026 class wexus::Cookies
00027 {
00028   public:
00029     class CookieNotFoundException : public wexus::HTTPHandler::Exception   // TODO should this really decend from HTTPHandler::Exception?
00030     {
00031       public:
00032         CookieNotFoundException(const QString &cookieName);
00033     };
00034 
00035   public:
00036     /**
00037      * Constructor
00038      * TODO future, add Site so the domain/expires/path
00039      * can be set.
00040      *
00041      * @author Aleksander Demko
00042      */ 
00043     Cookies(wexus::HTTPRequest *req, wexus::HTTPReply *rep);
00044 
00045     /**
00046      * Does this have a cookie with the given name?
00047      *
00048      * @author Aleksander Demko
00049      */ 
00050     bool contains(const QString &cookieName);
00051 
00052     /**
00053      * Gets a cookie.
00054      * Throws CookieNotFoundException on not found.
00055      *
00056      * @author Aleksander Demko
00057      */ 
00058     const QVariant & operator[](const QString &cookieName) const;
00059 
00060     /**
00061      * Gets a cookie.
00062      * Never fails, as it'll create the cookie if need be.
00063      *
00064      * @author Aleksander Demko
00065      */ 
00066     QVariant & operator[](const QString &cookieName);
00067 
00068   private:
00069     wexus::HTTPRequest *dm_req;
00070     wexus::HTTPReply *dm_reply;
00071 };
00072 
00073 #endif
00074 
 All Classes Namespaces Functions Variables Enumerations Enumerator