summaryrefslogtreecommitdiffstats
path: root/src/parser/hdr_request_disposition.cpp
blob: f9f0013cfff9562f4ee0dbef17e6113e2f3b7231 (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
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
/*
    Copyright (C) 2005-2009  Michel de Boer <michel@twinklephone.com>

    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 2 of the License, or
    (at your option) any later version.

    This program 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 General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <https://www.gnu.org/licenses/>.
*/

#include "hdr_request_disposition.h"

#include <vector>
#include "util.h"

t_hdr_request_disposition::t_hdr_request_disposition() : 
	t_header("Request-Disposition", "d"),
	proxy_directive(PROXY_NULL),
	cancel_directive(CANCEL_NULL),
	fork_directive(FORK_NULL),
	recurse_directive(RECURSE_NULL),
	parallel_directive(PARALLEL_NULL),
	queue_directive(QUEUE_NULL)
{}

void t_hdr_request_disposition::set_proxy_directive(t_proxy_directive directive) {
	populated = true;
	proxy_directive = directive;
}

void t_hdr_request_disposition::set_cancel_directive(t_cancel_directive directive) {
	populated = true;
	cancel_directive = directive;
}

void t_hdr_request_disposition::set_fork_directive(t_fork_directive directive) {
	populated = true;
	fork_directive = directive;
}

void t_hdr_request_disposition::set_recurse_directive(t_recurse_directive directive) {
	populated = true;
	recurse_directive = directive;
}

void t_hdr_request_disposition::set_parallel_directive(t_parallel_directive directive) {
	populated = true;
	parallel_directive = directive;
}

void t_hdr_request_disposition::set_queue_directive(t_queue_directive directive) {
	populated = true;
	queue_directive = directive;
}

bool t_hdr_request_disposition::set_directive(const string &s) {
	if (s == REQDIS_PROXY) {
		if (proxy_directive == REDIRECT) return false;
		set_proxy_directive(PROXY);
		return true;
	}
	
	if (s == REQDIS_REDIRECT) {
		if (proxy_directive == PROXY) return false;
		set_proxy_directive(REDIRECT);
		return true;
	}
	
	if (s == REQDIS_CANCEL) {
		if (cancel_directive == NO_CANCEL) return false;
		set_cancel_directive(CANCEL);
		return true;
	}
	
	if (s == REQDIS_NO_CANCEL) {
		if (cancel_directive == CANCEL) return false;
		set_cancel_directive(NO_CANCEL);
		return true;
	}
	
	if (s == REQDIS_FORK) {
		if (fork_directive == NO_FORK) return false;
		set_fork_directive(FORK);
		return true;
	}
	
	if (s == REQDIS_NO_FORK) {
		if (fork_directive == FORK) return false;
		set_fork_directive(NO_FORK);
		return true;
	}
	
	if (s == REQDIS_RECURSE) {
		if (recurse_directive == NO_RECURSE) return false;
		set_recurse_directive(RECURSE);
		return true;
	}
	
	if (s == REQDIS_NO_RECURSE) {
		if (recurse_directive == RECURSE) return false;
		set_recurse_directive(NO_RECURSE);
		return true;
	}
	
	if (s == REQDIS_PARALLEL) {
		if (parallel_directive == SEQUENTIAL) return false;
		set_parallel_directive(PARALLEL);
		return true;
	}
	
	if (s == REQDIS_SEQUENTIAL) {
		if (parallel_directive == PARALLEL) return false;
		set_parallel_directive(SEQUENTIAL);
		return true;
	}
	
	if (s == REQDIS_QUEUE) {
		if (queue_directive == NO_QUEUE) return false;
		set_queue_directive(QUEUE);
		return true;
	}
	
	if (s == REQDIS_NO_QUEUE) {
		if (queue_directive == QUEUE) return false;
		set_queue_directive(NO_QUEUE);
		return true;
	}
	
	return false;
}

string t_hdr_request_disposition::encode_value(void) const {
	if (!populated) return "";
	
	vector<string> v;
	
	switch (proxy_directive) {
	case PROXY:
		v.push_back(REQDIS_PROXY);
		break;
	case REDIRECT:
		v.push_back(REQDIS_REDIRECT);
		break;
	default:
		break;
	}
	
	switch (cancel_directive) {
	case CANCEL:
		v.push_back(REQDIS_CANCEL);
		break;
	case NO_CANCEL:
		v.push_back(REQDIS_NO_CANCEL);
		break;
	default:
		break;
	}
	
	switch (fork_directive) {
	case FORK:
		v.push_back(REQDIS_FORK);
		break;
	case NO_FORK:
		v.push_back(REQDIS_NO_FORK);
		break;
	default:
		break;
	}
	
	switch (recurse_directive) {
	case RECURSE:
		v.push_back(REQDIS_RECURSE);
		break;
	case NO_RECURSE:
		v.push_back(REQDIS_NO_RECURSE);
		break;
	default:
		break;
	}
	
	switch (parallel_directive) {
	case PARALLEL:
		v.push_back(REQDIS_PARALLEL);
		break;
	case SEQUENTIAL:
		v.push_back(REQDIS_SEQUENTIAL);
		break;
	default:
		break;
	}
	
	switch (queue_directive) {
	case QUEUE:
		v.push_back(REQDIS_QUEUE);
		break;
	case NO_QUEUE:
		v.push_back(REQDIS_NO_QUEUE);
		break;
	default:
		break;
	}
	
	string s = join_strings(v, ",");
	return s;
}