Panda3D
httpCookie.h
1 // Filename: httpCookie.h
2 // Created by: drose (26Aug04)
3 //
4 ////////////////////////////////////////////////////////////////////
5 //
6 // PANDA 3D SOFTWARE
7 // Copyright (c) Carnegie Mellon University. All rights reserved.
8 //
9 // All use of this software is subject to the terms of the revised BSD
10 // license. You should have received a copy of this license along
11 // with this source code in a file named "LICENSE."
12 //
13 ////////////////////////////////////////////////////////////////////
14 
15 #ifndef HTTPCOOKIE_H
16 #define HTTPCOOKIE_H
17 
18 #include "pandabase.h"
19 
20 // This module requires OpenSSL to compile, even if you do not intend
21 // to use this to establish https connections; this is because it uses
22 // the OpenSSL library to portably handle all of the socket
23 // communications.
24 
25 #ifdef HAVE_OPENSSL
26 
27 #include "httpDate.h"
28 #include "urlSpec.h"
29 
30 ////////////////////////////////////////////////////////////////////
31 // Class : HTTPCookie
32 // Description : A cookie sent from an HTTP server to be stored on the
33 // client and returned when the path and/or domain
34 // matches.
35 ////////////////////////////////////////////////////////////////////
36 class EXPCL_PANDAEXPRESS HTTPCookie {
37 PUBLISHED:
38  INLINE HTTPCookie();
39  INLINE HTTPCookie(const string &format, const URLSpec &url);
40  INLINE HTTPCookie(const string &name, const string &path, const string &domain);
41  INLINE ~HTTPCookie();
42 
43  INLINE void set_name(const string &name);
44  INLINE const string &get_name() const;
45 
46  INLINE void set_value(const string &value);
47  INLINE const string &get_value() const;
48 
49  INLINE void set_domain(const string &domain);
50  INLINE const string &get_domain() const;
51 
52  INLINE void set_path(const string &path);
53  INLINE const string &get_path() const;
54 
55  INLINE void set_expires(const HTTPDate &expires);
56  INLINE void clear_expires();
57  INLINE bool has_expires() const;
58  INLINE HTTPDate get_expires() const;
59 
60  INLINE void set_secure(bool flag);
61  INLINE bool get_secure() const;
62 
63  bool operator < (const HTTPCookie &other) const;
64  void update_from(const HTTPCookie &other);
65 
66  bool parse_set_cookie(const string &format, const URLSpec &url);
67  INLINE bool is_expired(const HTTPDate &now = HTTPDate::now()) const;
68  bool matches_url(const URLSpec &url) const;
69 
70  void output(ostream &out) const;
71 
72 private:
73  bool parse_cookie_param(const string &param, bool first_param);
74 
75  string _name;
76  string _value;
77  string _path;
78  string _domain;
79  HTTPDate _expires;
80  bool _secure;
81 };
82 
83 INLINE ostream &operator << (ostream &out, const HTTPCookie &cookie);
84 
85 #include "httpCookie.I"
86 
87 #endif // HAVE_OPENSSL
88 
89 #endif
A container for a URL, e.g.
Definition: urlSpec.h:29
A container for an HTTP-legal time/date indication.
Definition: httpDate.h:30
static HTTPDate now()
Returns an HTTPDate that represents the current time and date.
Definition: httpDate.I:60