summaryrefslogtreecommitdiff
path: root/indra/llcorehttp/_httppolicyglobal.cpp
blob: 6b1de38fd64a5347fd250c9401694f73850832cb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
/**
 * @file _httppolicyglobal.cpp
 * @brief Definitions for internal class defining global policy option.
 *
 * $LicenseInfo:firstyear=2012&license=viewerlgpl$
 * Second Life Viewer Source Code
 * Copyright (C) 2012, Linden Research, Inc.
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation;
 * version 2.1 of the License only.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 *
 * Linden Research, Inc., 945 Battery Street, San Francisco, CA  94111  USA
 * $/LicenseInfo$
 */

#include "_httppolicyglobal.h"


namespace LLCore
{


HttpPolicyGlobal::HttpPolicyGlobal()
	: mSetMask(0UL),
	  mConnectionLimit(32L),
	  mTrace(0),
	  mUseLLProxy(0)
{}


HttpPolicyGlobal::~HttpPolicyGlobal()
{}


HttpPolicyGlobal & HttpPolicyGlobal::operator=(const HttpPolicyGlobal & other)
{
	if (this != &other)
	{
		mSetMask = other.mSetMask;
		mConnectionLimit = other.mConnectionLimit;
		mCAPath = other.mCAPath;
		mCAFile = other.mCAFile;
		mHttpProxy = other.mHttpProxy;
		mTrace = other.mTrace;
		mUseLLProxy = other.mUseLLProxy;
	}
	return *this;
}


HttpStatus HttpPolicyGlobal::set(HttpRequest::EGlobalPolicy opt, long value)
{
	switch (opt)
	{
	case HttpRequest::GP_CONNECTION_LIMIT:
		mConnectionLimit = value;
		break;

	case HttpRequest::GP_TRACE:
		mTrace = llclamp(value, 0L, 3L);
		break;

	case HttpRequest::GP_LLPROXY:
		mUseLLProxy = llclamp(value, 0L, 1L);
		break;

	default:
		return HttpStatus(HttpStatus::LLCORE, HE_INVALID_ARG);
	}

	mSetMask |= 1UL << int(opt);
	return HttpStatus();
}


HttpStatus HttpPolicyGlobal::set(HttpRequest::EGlobalPolicy opt, const std::string & value)
{
	switch (opt)
	{
	case HttpRequest::GP_CA_PATH:
		mCAPath = value;
		break;

	case HttpRequest::GP_CA_FILE:
		mCAFile = value;
		break;

	case HttpRequest::GP_HTTP_PROXY:
		mCAFile = value;
		break;

	default:
		return HttpStatus(HttpStatus::LLCORE, HE_INVALID_ARG);
	}
	
	mSetMask |= 1UL << int(opt);
	return HttpStatus();
}


HttpStatus HttpPolicyGlobal::get(HttpRequest::EGlobalPolicy opt, long * value)
{
	static const HttpStatus not_set(HttpStatus::LLCORE, HE_OPT_NOT_SET);
	long * src(NULL);
	
	switch (opt)
	{
	case HttpRequest::GP_CONNECTION_LIMIT:
		src = &mConnectionLimit;
		break;

	case HttpRequest::GP_TRACE:
		src = &mTrace;
		break;

	case HttpRequest::GP_LLPROXY:
		src = &mUseLLProxy;
		break;

	default:
		return HttpStatus(HttpStatus::LLCORE, HE_INVALID_ARG);
	}

	if (! (mSetMask & (1UL << int(opt))))
		return not_set;

	*value = *src;
	return HttpStatus();
}


HttpStatus HttpPolicyGlobal::get(HttpRequest::EGlobalPolicy opt, const std::string ** value)
{
	static const HttpStatus not_set(HttpStatus::LLCORE, HE_OPT_NOT_SET);
	const std::string * src(NULL);

	switch (opt)
	{
	case HttpRequest::GP_CA_PATH:
		src = &mCAPath;
		break;

	case HttpRequest::GP_CA_FILE:
		src = &mCAFile;
		break;

	case HttpRequest::GP_HTTP_PROXY:
		src = &mHttpProxy;
		break;

	default:
		return HttpStatus(HttpStatus::LLCORE, HE_INVALID_ARG);
	}
	
	if (! (mSetMask & (1UL << int(opt))))
		return not_set;

	*value = src;
	return HttpStatus();
}

}  // end namespace LLCore