LCOV - code coverage report
Current view: top level - snapwebsites - http_cookie.h (source / functions) Hit Total Coverage
Test: coverage.info Lines: 0 7 0.0 %
Date: 2019-12-15 17:13:15 Functions: 0 11 0.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : // Snap Websites Servers -- HTTP cookie handling (outgoing)
       2             : // Copyright (c) 2013-2019  Made to Order Software Corp.  All Rights Reserved
       3             : //
       4             : // This program is free software; you can redistribute it and/or modify
       5             : // it under the terms of the GNU General Public License as published by
       6             : // the Free Software Foundation; either version 2 of the License, or
       7             : // (at your option) any later version.
       8             : //
       9             : // This program is distributed in the hope that it will be useful,
      10             : // but WITHOUT ANY WARRANTY; without even the implied warranty of
      11             : // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      12             : // GNU General Public License for more details.
      13             : //
      14             : // You should have received a copy of the GNU General Public License
      15             : // along with this program; if not, write to the Free Software
      16             : // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
      17             : #pragma once
      18             : 
      19             : #include "snapwebsites/snap_exception.h"
      20             : 
      21             : #include <QDateTime>
      22             : 
      23             : namespace snap
      24             : {
      25             : 
      26           0 : class http_cookie_exception : public snap_exception
      27             : {
      28             : public:
      29           0 :     http_cookie_exception(char const *        what_msg) : snap_exception("http_cookie", what_msg) {}
      30             :     http_cookie_exception(std::string const & what_msg) : snap_exception("http_cookie", what_msg) {}
      31           0 :     http_cookie_exception(QString const &     what_msg) : snap_exception("http_cookie", what_msg) {}
      32             : };
      33             : 
      34             : 
      35           0 : class http_cookie_parse_exception : public http_cookie_exception
      36             : {
      37             : public:
      38           0 :     http_cookie_parse_exception(char const *        what_msg) : http_cookie_exception(what_msg) {}
      39             :     http_cookie_parse_exception(std::string const & what_msg) : http_cookie_exception(what_msg) {}
      40           0 :     http_cookie_parse_exception(QString const &     what_msg) : http_cookie_exception(what_msg) {}
      41             : };
      42             : 
      43             : 
      44             : 
      45             : class snap_child;
      46             : 
      47             : #pragma GCC diagnostic push
      48             : #pragma GCC diagnostic ignored "-Weffc++"
      49           0 : class http_cookie
      50             : {
      51             : public:
      52             :     enum class http_cookie_type_t
      53             :     {
      54             :         HTTP_COOKIE_TYPE_PERMANENT,
      55             :         HTTP_COOKIE_TYPE_SESSION,
      56             :         HTTP_COOKIE_TYPE_DELETE
      57             :     };
      58             : 
      59             :                         http_cookie(); // for QMap to work; DO NOT USE!
      60             :                         http_cookie(snap_child * snap, QString const & name, QString const & value = "");
      61             : 
      62             :     void                set_value(QString const & value);
      63             :     void                set_value(QByteArray const & value);
      64             :     void                set_domain(QString const & domain);
      65             :     void                set_path(QString const & path);
      66             :     void                set_delete();
      67             :     void                set_session();
      68             :     void                set_expire(QDateTime const & date_time);
      69             :     void                set_expire_in(int64_t seconds);
      70             :     void                set_secure(bool secure = true);
      71             :     void                set_http_only(bool http_only = true);
      72             :     void                set_comment(QString const & comment);
      73             :     void                set_comment_url(QString const & comment_url);
      74             : 
      75             :     QString const &     get_name() const;
      76             :     QByteArray const &  get_value() const;
      77             :     http_cookie_type_t  get_type() const;
      78             :     QString const &     get_domain() const;
      79             :     QString const &     get_path() const;
      80             :     QDateTime const &   get_expire() const;
      81             :     bool                get_secure() const;
      82             :     bool                get_http_only() const;
      83             :     QString const &     get_comment() const;
      84             :     QString const &     get_comment_url() const;
      85             : 
      86             :     QString             to_http_header() const;
      87             : 
      88             : private:
      89             :     snap_child *        f_snap = nullptr;           // the snap child that created this cookie
      90             :     QString             f_name = QString();         // name of the cookie
      91             :     QByteArray          f_value = QByteArray();     // the cookie value (binary buffer)
      92             :     QString             f_domain = QString();       // domain for which the cookie is valid
      93             :     QString             f_path = QString();         // path under which the cookie is valid
      94             :     QDateTime           f_expire = QDateTime();     // when to expire the cookie (if null, session, if past delete)
      95             :     bool                f_secure = false;           // only valid on HTTPS
      96             :     bool                f_http_only = false;        // JavaScript cannot access this cookie
      97             :     QString             f_comment = QString();      // verbatim comment
      98             :     QString             f_comment_url = QString();  // verbatim comment
      99             : };
     100             : #pragma GCC diagnostic pop
     101             : 
     102             : 
     103             : 
     104             : } // namespace snap
     105             : // vim: ts=4 sw=4 et

Generated by: LCOV version 1.13