summaryrefslogtreecommitdiffstats
path: root/src/client_request.h
blob: ca6ee95b980cd4df5787b20658004d8c76dad8c1 (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
/*
    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
*/

/** @file
 * Bind request with TU and transaction
 */

#ifndef _CLIENT_REQUEST_H
#define _CLIENT_REQUEST_H

#include "protocol.h"
#include "redirect.h"
#include "user.h"
#include "transaction_layer.h"
#include "threads/mutex.h"
#include "parser/request.h"
#include "stun/stun.h"

using namespace std;

/** Object for storing a request together with its Transaction User id and transaction id. */
class t_client_request {
private:
	static t_mutex	mtx_next_tuid; 	/**< Protect updates on @ref next_tuid */
	static t_tuid	next_tuid;     	/**< Next transaction user id to handout. */

	// A client request is either a SIP or a STUN request
	t_request	*request;	/**< SIP request. */
	StunMessage	*stun_request;	/**< STUN request. */
	
	t_tuid		tuid;		/**< Transaction user id. */
	t_tid		tid;		/**< Transaction id. */

	/** Number of references to this object (#dialogs). */
	int		ref_count;

public:
	/** Redirector for 3XX redirections. */
	t_redirector	redirector;

	/**
	 * Constructor.
	 * A copy of the request is stored in the client_request object.
	 * @param user The user profile of the user sending the request.
	 * @param r SIP request.
	 * @param _tid Transaction id.
	 */
	t_client_request(t_user *user, t_request *r, const t_tid _tid);
	
	/**
	 * Constructor.
	 * A copy of the request is stored in the client_request object.
	 * @param user The user profile of the user sending the request.
	 * @param r STUN request.
	 * @param _tid Transaction id.
	 */	
	t_client_request(t_user *user, StunMessage *r, const t_tid _tid);
	
	/** Destructor. */
	~t_client_request();

	/**
	 * Create a copy of the client request.
	 * @return Copy of the client request.
	 * @note: The request inside the client request is copied.
	 */
	t_client_request *copy(void);

	/**
	 * Get a pointer to the SIP request.
	 * @return Pointer to the SIP request.
	 */
	t_request *get_request(void) const;
	
	/**
	 * Get a pointer to the STUN request.
	 * @return Pointer to the STUN request.
	 */
	StunMessage *get_stun_request(void) const;

	/** Get the transaction user id. */
	t_tuid get_tuid(void) const;
	
	/** Get the transaction id. */
	t_tid get_tid(void) const;
	
	/** Set the transaction id. */
	void set_tid(t_tid _tid);

	/** 
	 * Create a new tuid and set tid.
	 * @param _tid The new tid to set.
	 */
	void renew(t_tid _tid);

	/** Get the reference count. */
	int get_ref_count(void) const;

	/**
	 * Increment reference count. 
	 * @return The reference count after increment.
	 */
	int inc_ref_count(void);

	/**
	 * Decrement reference count. 
	 * @returns The reference count after decrement.
	 */
	int dec_ref_count(void);
};

#endif