summaryrefslogtreecommitdiffstats
path: root/src/mwi/simple_msg_sum_body.h
blob: 3c83170b8d805313a2be4c2be70ff9572ddafbf7 (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
/*
    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/>.
*/

/**
 * @file
 * RFC 3842 simple-message-summary body
 */

#ifndef SIMPLE_MSG_SUM_BODY_HH
#define SIMPLE_MSG_SUM_BODY_HH

#include <string>
#include <map>
#include "parser/sip_body.h"
#include "sockets/url.h"

// RFC 3458 6.2
// Message contexts
#define MSG_CONTEXT_VOICE	"voice-message"
#define MSG_CONTEXT_FAX		"fax-message"
#define MSG_CONTEXT_MULTIMEDIA	"multimedia-message"
#define MSG_CONTEXT_TEXT	"text-message"
#define MSG_CONTEXT_NONE	"none"

using namespace std;

/** Message summary counters */
struct t_msg_summary {
	uint32		newmsgs;
	uint32		newmsgs_urgent;
	uint32		oldmsgs;
	uint32		oldmsgs_urgent;

	t_msg_summary();
	
	/**
	 * Parse a text representation of a message summary.
	 * @param s [in] The text to parse.
	 * @return false if parsing fails, true if it succeeds.
	 */
	bool parse(const string &s);

	/** Set all counters to zero */
	void clear(void);
};

typedef string t_msg_context;
typedef map<t_msg_context, t_msg_summary>::const_iterator t_msg_sum_const_iter;

class t_simple_msg_sum_body : public t_sip_body {
private:
	bool			msg_waiting;
	t_url			msg_account;
	map<t_msg_context, t_msg_summary> msg_summary;
	
	// Returns true if string is a valid message context
	bool is_context(const string &s);
		
public:
	t_simple_msg_sum_body();

	// Return text encoded body
	virtual string encode(void) const;

	// Create a copy of the body
	virtual t_sip_body *copy(void) const;

	// Get type of body
	virtual t_body_type get_type(void) const;
	
	virtual t_media get_media(void) const;
	
	// Add a message summary
	void add_msg_summary(const string &context, const t_msg_summary summary);
	
	bool get_msg_waiting(void) const;
	t_url get_msg_account(void) const;
	
	// Get the message summary for a particular context
	// If the context is not present, then false is returned
	bool get_msg_summary(const string &context, t_msg_summary &summary) const;
	
	// Parse a text representation of the body.
	bool parse(const string &s);
};

#endif