summaryrefslogtreecommitdiffstats
path: root/src/parser/hdr_contact.h
blob: 4742cdf554ff1250cae964a8ce6c458da1dfa2e7 (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
/*
    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/>.
*/

// Contact header

#ifndef _HDR_CONTACT
#define _HDR_CONTACT

#include <list>
#include <string>
#include "header.h"
#include "parameter.h"
#include "sockets/url.h"

using namespace std;

class t_contact_param {
private:
	bool			expires_present;
	unsigned long		expires;
	bool			qvalue_present;
	float			qvalue;
	
public:
	string			display; // display name
	t_url			uri;
	list<t_parameter>	extensions;

	t_contact_param();
	void add_extension(const t_parameter &p);
	string encode(void) const;
	bool is_expires_present(void) const;
	unsigned long get_expires(void) const;
	void set_expires(unsigned long e);
	float get_qvalue(void) const;
	void set_qvalue(float q);

	// Compare contacts on q-value.
	// The contacts with the highest q-value comes first in the order
	bool operator<(const t_contact_param &c) const;
};

class t_hdr_contact : public t_header {
public:
	bool			any_flag; // true if Contact: *
	list<t_contact_param>	contact_list;

	t_hdr_contact();
	void add_contact(const t_contact_param &contact);
	void add_contacts(const list<t_contact_param> &l);
	void set_contacts(const list<t_contact_param> &l);
	
	/**
	 * Set the contact list to a sequence of URI's with display names.
	 * The URI's are give a descending q-value starting at 0.9
	 * Each subsequent URI gets a q-value 0.1 less than the previous
	 * URI. If more than 9 URI's are passed then the tail of URI's all
	 * get a q-value of 0.1.
	 *
	 * @param l [in] The list of URI's to be put in the contact list.
	 */	
	void set_contacts(const list<t_url> &l);
	
	/**
	 * Set the contact list to a sequence of URI's with display names.
	 * The URI's are give a descending q-value starting at 0.9
	 * Each subsequent URI gets a q-value 0.1 less than the previous
	 * URI. If more than 9 URI's are passed then the tail of URI's all
	 * get a q-value of 0.1.
	 *
	 * @param l [in] The list of URI's to be put in the contact list.
	 */
	void set_contacts(const list<t_display_url> &l);

	// Set contact to any, eg. Contact: *
	void set_any(void);

	// Find contact with uri u. If no contact is found, then
	// NULL is returned.
	t_contact_param *find_contact(const t_url &u);

	string encode_value(void) const;
};

#endif