summaryrefslogtreecommitdiffstats
path: root/src/parser/hdr_warning.cpp
blob: e77ef3518899d3eaf7847a3b0befe3a3eca4a8c6 (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
/*
    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, write to the Free Software
    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
*/

#include "definitions.h"
#include "hdr_warning.h"
#include "util.h"

t_warning::t_warning() {
	code = 0;
	port = 0;
}

t_warning::t_warning(const string &_host, int _port, int _code, string _text) {
	host = _host;
	port = _port;
	code = _code;

	switch(code) {
	case 300: text = WARNING_300; break;
	case 301: text = WARNING_301; break;
	case 302: text = WARNING_302; break;
	case 303: text = WARNING_303; break;
	case 304: text = WARNING_304; break;
	case 305: text = WARNING_305; break;
	case 306: text = WARNING_306; break;
	case 307: text = WARNING_307; break;
	case 330: text = WARNING_330; break;
	case 331: text = WARNING_331; break;
	case 370: text = WARNING_370; break;
	case 399: text = WARNING_399; break;
	default: text = "Warning";
	}

	if (_text != "") {
		text += ": ";
		text += _text;
	}
}

string t_warning::encode(void) const {
	string s;

	s = int2str(code, "%3d");
	s += ' ';
	s += host;
	if (port > 0) s += int2str(port, ":%d");
	s += ' ';
	s += '"';
	s += text;
	s += '"';
	return s;
}

t_hdr_warning::t_hdr_warning() : t_header("Warning") {}

void t_hdr_warning::add_warning(const t_warning &w) {
	populated = true;
	warnings.push_back(w);
}

string t_hdr_warning::encode_value(void) const {
	string s;

	if (!populated) return s;

	for (list<t_warning>::const_iterator i = warnings.begin();
	     i != warnings.end(); i++)
	{
		if (i != warnings.begin()) s += ", ";
		s += i->encode();
	}

	return s;
}