-
Notifications
You must be signed in to change notification settings - Fork 189
/
sip_msg.h
202 lines (182 loc) · 4.97 KB
/
sip_msg.h
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
/**************************************************************************
**
** sngrep - SIP Messages flow viewer
**
** Copyright (C) 2013-2018 Ivan Alonso (Kaian)
** Copyright (C) 2013-2018 Irontec SL. All rights reserved.
**
** 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 3 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 <http://www.gnu.org/licenses/>.
**
****************************************************************************/
/**
* @file sip_msg.h
* @author Ivan Alonso [aka Kaian] <kaian@irontec.com>
*
* @brief Functions to manage sip messages
*
*/
#ifndef __SNGREP_SIP_MSG_H
#define __SNGREP_SIP_MSG_H
#include "config.h"
#include <stdarg.h>
#include "vector.h"
#include "media.h"
#include "sip_attr.h"
#include "util.h"
//! Shorter declaration of sip_msg structure
typedef struct sip_msg sip_msg_t;
/**
* @brief Information of a single message withing a dialog.
*
* Most of the data is just stored to be displayed in the UI so
* the formats may be no the best, but the simplest for this
* purpose. It also works as a linked lists of messages in a
* call.
*/
struct sip_call;
struct sip_msg {
//! Request Method or Response Code @see sip_methods
int reqresp;
//! Response text if it doesn't matches an standard
char *resp_str;
//! Message Cseq
uint32_t cseq;
//! SIP From Header
char *sip_from;
//! SIP To Header
char *sip_to;
//! SDP payload information (sdp_media_t *)
vector_t *medias;
//! Captured packet for this message
packet_t *packet;
//! Index of this message in call
uint32_t index;
//! Message owner
struct sip_call *call;
//! Message is a retransmission from other message
sip_msg_t *retrans;
};
/**
* @brief Create a new message from the readed header and payload
*
* Allocate required memory for a new SIP message. This function
* will only store the given information, but wont parse it until
* needed.
*
* @param payload Raw payload content
* @return a new allocated message
*/
sip_msg_t *
msg_create();
/**
* @brief Destroy a SIP message and free its memory
*
* Deallocate memory of an existing SIP Message.
* This function will remove the message from the call and the
* passed pointer will be NULL.
*
* @param nsg SIP message to be deleted
*/
void
msg_destroy(sip_msg_t *msg);
/**
* @brief Wrapper around Message destroyer to clear msg vectors
*/
void
msg_destroyer(void *msg);
/**
* @brief Return the call owner of this message
*/
struct sip_call *
msg_get_call(const sip_msg_t *msg);
/**
* @brief Getter for media of given messages
*
* Return the number of media structures of given msg
* stored in this call.
*
* @param msg SIP message structure
* @return how many media structures are in the msg
*/
int
msg_media_count(sip_msg_t *msg);
/**
* @brief Check if given message has spd content
*/
int
msg_has_sdp(void *item);
/**
* @brief Add a media structure to a msg
*
* @param cmsg SIP Message to be updated
* @param media Media structure to be added
*/
void
msg_add_media(sip_msg_t *msg, sdp_media_t *media);
/**
* @brief Check if a message is a Request or response
*
* @param msg SIP message that will be checked
* @return 1 if the message is a request, 0 if a response
*/
int
msg_is_request(sip_msg_t *msg);
/**
* @brief Add a new media for given message
*
* A SIP message can have multiple media description in
* the SIP payload content
*
* @param msg SIP message that will store this packet
* @param media parsed media structure from payload
*/
void
msg_add_media(sip_msg_t *msg, sdp_media_t *media);
/**
* @brief Get SIP Message payload
*/
const char *
msg_get_payload(sip_msg_t *msg);
/**
* @brief Get Time of message from packet header
*
* @param msg SIP message
* @return timeval structure with message first packet time
*/
struct timeval
msg_get_time(sip_msg_t *msg);
/**
* @brief Return a message attribute value
*
* This function will be used to avoid accessing call structure
* fields directly.
*
* @param msg SIP message structure
* @param id Attribute id
* @param out Buffer to store attribute value
* @return Attribute value or NULL if not found
*/
const char *
msg_get_attribute(struct sip_msg *msg, int id, char *value);
/**
* @brief Check if a message is older than other
*
* @param one SIP message pointer
* @param two SIP message pointer
* @return 1 if one is older than two
* @return 0 if equal or two is older than one
*/
int
msg_is_older(sip_msg_t *one, sip_msg_t *two);
#endif /* __SNGREP_SIP_MSG_H */