aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/linden/indra/llplugin/llplugincookiestore.h
diff options
context:
space:
mode:
Diffstat (limited to 'linden/indra/llplugin/llplugincookiestore.h')
-rw-r--r--linden/indra/llplugin/llplugincookiestore.h127
1 files changed, 127 insertions, 0 deletions
diff --git a/linden/indra/llplugin/llplugincookiestore.h b/linden/indra/llplugin/llplugincookiestore.h
new file mode 100644
index 0000000..69f0cf1
--- /dev/null
+++ b/linden/indra/llplugin/llplugincookiestore.h
@@ -0,0 +1,127 @@
1/**
2 * @file llplugincookiestore.h
3 * @brief LLPluginCookieStore provides central storage for http cookies used by plugins
4 *
5 * @cond
6 * $LicenseInfo:firstyear=2010&license=viewergpl$
7 *
8 * Copyright (c) 2010, Linden Research, Inc.
9 *
10 * Second Life Viewer Source Code
11 * The source code in this file ("Source Code") is provided by Linden Lab
12 * to you under the terms of the GNU General Public License, version 2.0
13 * ("GPL"), unless you have obtained a separate licensing agreement
14 * ("Other License"), formally executed by you and Linden Lab. Terms of
15 * the GPL can be found in doc/GPL-license.txt in this distribution, or
16 * online at http://secondlife.com/developers/opensource/gplv2
17 *
18 * There are special exceptions to the terms and conditions of the GPL as
19 * it is applied to this Source Code. View the full text of the exception
20 * in the file doc/FLOSS-exception.txt in this software distribution, or
21 * online at
22 * http://secondlife.com/developers/opensource/flossexception
23 *
24 * By copying, modifying or distributing this software, you acknowledge
25 * that you have read and understood your obligations described above,
26 * and agree to abide by those obligations.
27 *
28 * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO
29 * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY,
30 * COMPLETENESS OR PERFORMANCE.
31 * $/LicenseInfo$
32 *
33 * @endcond
34 */
35
36#ifndef LL_LLPLUGINCOOKIESTORE_H
37#define LL_LLPLUGINCOOKIESTORE_H
38
39#include "lldate.h"
40#include <map>
41#include <string>
42#include <iostream>
43
44class LLPluginCookieStore
45{
46 LOG_CLASS(LLPluginCookieStore);
47public:
48 LLPluginCookieStore();
49 ~LLPluginCookieStore();
50
51 // gets all cookies currently in storage -- use when initializing a plugin
52 std::string getAllCookies();
53 void writeAllCookies(std::ostream& s);
54
55 // gets only persistent cookies (i.e. not session cookies) -- use when writing cookies to a file
56 std::string getPersistentCookies();
57 void writePersistentCookies(std::ostream& s);
58
59 // gets cookies which are marked as "changed" -- use when sending periodic updates to plugins
60 std::string getChangedCookies(bool clear_changed = true);
61 void writeChangedCookies(std::ostream& s, bool clear_changed = true);
62
63 // (re)initializes internal data structures and bulk-sets cookies -- use when reading cookies from a file
64 void setAllCookies(const std::string &cookies, bool mark_changed = false);
65 void readAllCookies(std::istream& s, bool mark_changed = false);
66
67 // sets one or more cookies (without reinitializing anything) -- use when receiving cookies from a plugin
68 void setCookies(const std::string &cookies, bool mark_changed = true);
69 void readCookies(std::istream& s, bool mark_changed = true);
70
71 // sets one or more cookies (without reinitializing anything), supplying a hostname the cookies came from -- use when setting a cookie manually
72 void setCookiesFromHost(const std::string &cookies, const std::string &host, bool mark_changed = true);
73
74 // quote or unquote a string as per the definition of 'quoted-string' in rfc2616
75 static std::string quoteString(const std::string &s);
76 static std::string unquoteString(const std::string &s);
77
78private:
79
80 void setOneCookie(const std::string &s, std::string::size_type cookie_start, std::string::size_type cookie_end, bool mark_changed, const std::string &host = LLStringUtil::null);
81
82 class Cookie
83 {
84 public:
85 static Cookie *createFromString(const std::string &s, std::string::size_type cookie_start = 0, std::string::size_type cookie_end = std::string::npos, const std::string &host = LLStringUtil::null);
86
87 // Construct a string from the cookie that uniquely represents it, to be used as a key in a std::map.
88 std::string getKey() const;
89
90 const std::string &getCookie() const { return mCookie; };
91 bool isSessionCookie() const { return mDate.isNull(); };
92
93 bool isDead() const { return mDead; };
94 void setDead(bool dead) { mDead = dead; };
95
96 bool isChanged() const { return mChanged; };
97 void setChanged(bool changed) { mChanged = changed; };
98
99 const LLDate &getDate() const { return mDate; };
100
101 private:
102 Cookie(const std::string &s, std::string::size_type cookie_start = 0, std::string::size_type cookie_end = std::string::npos);
103 bool parse(const std::string &host);
104 std::string::size_type findFieldEnd(std::string::size_type start = 0, std::string::size_type end = std::string::npos);
105 bool matchName(std::string::size_type start, std::string::size_type end, const char *name);
106
107 std::string mCookie; // The full cookie, in RFC 2109 string format
108 LLDate mDate; // The expiration date of the cookie. For session cookies, this will be a null date (mDate.isNull() is true).
109 // Start/end indices of various parts of the cookie string. Stored as indices into the string to save space and time.
110 std::string::size_type mNameStart, mNameEnd;
111 std::string::size_type mValueStart, mValueEnd;
112 std::string::size_type mDomainStart, mDomainEnd;
113 std::string::size_type mPathStart, mPathEnd;
114 bool mDead;
115 bool mChanged;
116 };
117
118 typedef std::map<std::string, Cookie*> cookie_map_t;
119
120 cookie_map_t mCookies;
121 bool mHasChangedCookies;
122
123 void clearCookies();
124 void removeCookie(const std::string &key);
125};
126
127#endif // LL_LLPLUGINCOOKIESTORE_H