SIP Witch 1.9.15
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
osip_message.h
Go to the documentation of this file.
1 /*
2  The oSIP library implements the Session Initiation Protocol (SIP -rfc3261-)
3  Copyright (C) 2001-2015 Aymeric MOIZARD amoizard@antisip.com
4 
5  This library is free software; you can redistribute it and/or
6  modify it under the terms of the GNU Lesser General Public
7  License as published by the Free Software Foundation; either
8  version 2.1 of the License, or (at your option) any later version.
9 
10  This library is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  Lesser General Public License for more details.
14 
15  You should have received a copy of the GNU Lesser General Public
16  License along with this library; if not, write to the Free Software
17  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 */
19 
20 
21 #ifndef _OSIP_MESSAGE_H_
22 #define _OSIP_MESSAGE_H_
23 
24 #include <osipparser2/osip_const.h>
26 #include <osipparser2/osip_body.h>
27 
41 #ifdef __cplusplus
42 extern "C" {
43 #endif
44 
49  typedef struct osip_message osip_message_t;
50 
55  struct osip_message {
56  char *sip_version;
58  char *sip_method;
61  char *reason_phrase;
63 #ifndef MINISIZE
70 #endif
75 #ifndef MINISIZE
77 #endif
81 #ifndef MINISIZE
83 #endif
87 #ifndef MINISIZE
89 #endif
101  /*
102  1: structure and buffer "message" are identical.
103  2: buffer "message" is not up to date with the structure info (call osip_message_to_str to update it).
104  */
106  char *message;
107  size_t message_length;
110  };
111 
112 #ifndef SIP_MESSAGE_MAX_LENGTH
113 
116 #define SIP_MESSAGE_MAX_LENGTH 8000
117 #endif
118 
119 #ifndef BODY_MESSAGE_MAX_SIZE
120 
123 #define BODY_MESSAGE_MAX_SIZE 4000
124 #endif
125 
130  int osip_message_init (osip_message_t ** sip);
135  void osip_message_free (osip_message_t * sip);
142  int osip_message_parse (osip_message_t * sip, const char *buf, size_t length);
149  int osip_message_parse_sipfrag (osip_message_t * sip, const char *buf, size_t length);
158  int osip_message_to_str (osip_message_t * sip, char **dest, size_t * message_length);
168  int osip_message_to_str_sipfrag (osip_message_t * sip, char **dest, size_t * message_length);
174  int osip_message_clone (const osip_message_t * sip, osip_message_t ** dest);
175 
181  void osip_message_set_reason_phrase (osip_message_t * sip, char *reason);
192  void osip_message_set_status_code (osip_message_t * sip, int statuscode);
203  void osip_message_set_method (osip_message_t * sip, char *method);
208  char *osip_message_get_method (const osip_message_t * sip);
214  void osip_message_set_version (osip_message_t * sip, char *version);
219  char *osip_message_get_version (const osip_message_t * sip);
225  void osip_message_set_uri (osip_message_t * sip, osip_uri_t * uri);
231 
232 
233 /*
234  * These are helpfull MACROs to test messages type.
235  */
240 #define MSG_IS_RESPONSE(msg) ((msg)->status_code!=0)
241 
245 #define MSG_IS_REQUEST(msg) ((msg)->status_code==0)
246 
251 #define MSG_IS_INVITE(msg) (MSG_IS_REQUEST(msg) && \
252  0==strcmp((msg)->sip_method,"INVITE"))
253 
257 #define MSG_IS_ACK(msg) (MSG_IS_REQUEST(msg) && \
258  0==strcmp((msg)->sip_method,"ACK"))
259 
263 #define MSG_IS_REGISTER(msg) (MSG_IS_REQUEST(msg) && \
264  0==strcmp((msg)->sip_method,"REGISTER"))
265 
269 #define MSG_IS_BYE(msg) (MSG_IS_REQUEST(msg) && \
270  0==strcmp((msg)->sip_method,"BYE"))
271 
275 #define MSG_IS_OPTIONS(msg) (MSG_IS_REQUEST(msg) && \
276  0==strcmp((msg)->sip_method,"OPTIONS"))
277 
281 #define MSG_IS_INFO(msg) (MSG_IS_REQUEST(msg) && \
282  0==strcmp((msg)->sip_method,"INFO"))
283 
287 #define MSG_IS_CANCEL(msg) (MSG_IS_REQUEST(msg) && \
288  0==strcmp((msg)->sip_method,"CANCEL"))
289 
293 #define MSG_IS_REFER(msg) (MSG_IS_REQUEST(msg) && \
294  0==strcmp((msg)->sip_method,"REFER"))
295 
299 #define MSG_IS_NOTIFY(msg) (MSG_IS_REQUEST(msg) && \
300  0==strcmp((msg)->sip_method,"NOTIFY"))
301 
306 #define MSG_IS_SUBSCRIBE(msg) (MSG_IS_REQUEST(msg) && \
307  0==strcmp((msg)->sip_method,"SUBSCRIBE"))
308 
312 #define MSG_IS_MESSAGE(msg) (MSG_IS_REQUEST(msg) && \
313  0==strcmp((msg)->sip_method,"MESSAGE"))
314 
318 #define MSG_IS_PRACK(msg) (MSG_IS_REQUEST(msg) && \
319  0==strcmp((msg)->sip_method,"PRACK"))
320 
321 
326 #define MSG_IS_UPDATE(msg) (MSG_IS_REQUEST(msg) && \
327  0==strcmp((msg)->sip_method,"UPDATE"))
328 
333 #define MSG_IS_PUBLISH(msg) (MSG_IS_REQUEST(msg) && \
334  0==strcmp((msg)->sip_method,"PUBLISH"))
335 
336 
341 #define MSG_IS_STATUS_1XX(msg) ((msg)->status_code >= 100 && \
342  (msg)->status_code < 200)
343 
347 #define MSG_IS_STATUS_2XX(msg) ((msg)->status_code >= 200 && \
348  (msg)->status_code < 300)
349 
353 #define MSG_IS_STATUS_3XX(msg) ((msg)->status_code >= 300 && \
354  (msg)->status_code < 400)
355 
359 #define MSG_IS_STATUS_4XX(msg) ((msg)->status_code >= 400 && \
360  (msg)->status_code < 500)
361 
365 #define MSG_IS_STATUS_5XX(msg) ((msg)->status_code >= 500 && \
366  (msg)->status_code < 600)
367 
371 #define MSG_IS_STATUS_6XX(msg) ((msg)->status_code >= 600 && \
372  (msg)->status_code < 700)
373 
378 #define MSG_TEST_CODE(msg,code) (MSG_IS_RESPONSE(msg) && \
379  (code)==(msg)->status_code)
380 
385 #define MSG_IS_RESPONSE_FOR(msg,requestname) (MSG_IS_RESPONSE(msg) && \
386  0==strcmp((msg)->cseq->method,(requestname)))
387 
388 
393 #define osip_generic_param_init(GP) osip_uri_param_init(GP)
394 
398 #define osip_generic_param_free(GP) osip_uri_param_free(GP)
399 
405 #define osip_generic_param_set(GP, NAME, VALUE) osip_uri_param_set(GP, NAME, VALUE)
406 
411 #define osip_generic_param_clone osip_uri_param_clone
412 #ifndef DOXYGEN
413 /*
414  * Free a list of a generic parameter element.
415  * @param LIST The list of generic parameter element to free.
416  */
417 #define osip_generic_param_freelist(LIST) osip_uri_param_freelist(LIST)
418 #endif
419 
425 #define osip_generic_param_add(LIST,NAME,VALUE) osip_uri_param_add(LIST,NAME,VALUE)
426 
432 #define osip_generic_param_get_byname(LIST,NAME,DEST) osip_uri_param_get_byname(LIST,NAME,DEST)
433 
439  void osip_generic_param_set_name (osip_generic_param_t * generic_param, char *name);
444  char *osip_generic_param_get_name (const osip_generic_param_t * generic_param);
450  void osip_generic_param_set_value (osip_generic_param_t * generic_param, char *value);
455  char *osip_generic_param_get_value (const osip_generic_param_t * generic_param);
456 
457 
464  int osip_message_get_knownheaderlist (osip_list_t * header_list, int pos, void **dest);
465 
469 #ifdef __cplusplus
470 }
471 #endif
472 #endif
Structure for referencing a list of elements.
Definition: osip_list.h:82
Structure for SIP Message (REQUEST and RESPONSE).
Definition: osip_message.h:55
void osip_message_set_method(osip_message_t *sip, char *method)
Set the method.
oSIP osip_headers definition.
osip_list_t contacts
Contacts headers.
Definition: osip_message.h:74
Definition of the CSeq header.
Definition: osip_cseq.h:45
osip_list_t routes
Route headers.
Definition: osip_message.h:92
osip_list_t content_encodings
Content-Encodings headers.
Definition: osip_message.h:76
char * osip_message_get_version(const osip_message_t *sip)
Get the SIP version.
osip_list_t allows
Allows headers.
Definition: osip_message.h:68
Definition of the Content-Length header.
char * reason_phrase
Reason Phrase (SIP answer only)
Definition: osip_message.h:61
char * osip_message_get_reason_phrase(const osip_message_t *sip)
Get the reason phrase.
oSIP SIP Message Body Routines
void osip_message_set_version(osip_message_t *sip, char *version)
Set the SIP version used.
osip_content_length_t * content_length
Content-Length header.
Definition: osip_message.h:78
osip_list_t record_routes
Record-Route headers.
Definition: osip_message.h:91
size_t message_length
internal value
Definition: osip_message.h:107
void * application_data
can be used by upper layer
Definition: osip_message.h:109
void osip_generic_param_set_value(osip_generic_param_t *generic_param, char *value)
Set the value of a generic parameter element.
osip_from_t * from
From header.
Definition: osip_message.h:84
int osip_message_get_knownheaderlist(osip_list_t *header_list, int pos, void **dest)
Get the a known header from a list of known header.
osip_list_t accept_languages
Accept-Language headers.
Definition: osip_message.h:66
osip_content_type_t * content_type
Content-Type header.
Definition: osip_message.h:79
Definition of the Content-Type header.
int osip_message_get_status_code(const osip_message_t *sip)
Get the status code.
osip_list_t authorizations
Authorizations headers.
Definition: osip_message.h:71
int message_property
internal value
Definition: osip_message.h:105
char * osip_message_get_method(const osip_message_t *sip)
Get the method name.
void osip_message_free(osip_message_t *sip)
Free all resource in a osip_message_t element.
void osip_message_set_reason_phrase(osip_message_t *sip, char *reason)
Set the reason phrase.
osip_uri_t * req_uri
Request-Uri (SIP request only)
Definition: osip_message.h:57
osip_cseq_t * cseq
CSeq header.
Definition: osip_message.h:80
void osip_generic_param_set_name(osip_generic_param_t *generic_param, char *name)
Set the name of a generic parameter element.
osip_list_t proxy_authorizations
Proxy-authorization headers.
Definition: osip_message.h:90
osip_uri_t * osip_message_get_uri(const osip_message_t *sip)
Get the Request-URI.
int osip_message_clone(const osip_message_t *sip, osip_message_t **dest)
Clone a osip_message_t element.
char * message
internal value
Definition: osip_message.h:106
Definition of the From header.
Definition: osip_from.h:48
int osip_message_parse(osip_message_t *sip, const char *buf, size_t length)
Parse a osip_message_t element.
char * sip_version
SIP version (SIP request only)
Definition: osip_message.h:56
void osip_message_set_uri(osip_message_t *sip, osip_uri_t *uri)
Set the Request-URI.
osip_list_t www_authenticates
WWW-Authenticate headers.
Definition: osip_message.h:95
osip_list_t accept_encodings
Accept-Encoding headers.
Definition: osip_message.h:65
int osip_message_to_str(osip_message_t *sip, char **dest, size_t *message_length)
Get a string representation of a osip_message_t element.
char * name[96]
Definition: cgiserver.cpp:88
int osip_message_parse_sipfrag(osip_message_t *sip, const char *buf, size_t length)
Parse a message/sipfrag part and store it in an osip_message_t element.
osip_list_t accepts
Accept headers.
Definition: osip_message.h:64
char * value[96]
Definition: cgiserver.cpp:90
char * osip_generic_param_get_value(const osip_generic_param_t *generic_param)
Get the value of a generic parameter element.
osip_list_t proxy_authentication_infos
P-Authentication-Info headers.
Definition: osip_message.h:88
osip_list_t vias
Vias headers.
Definition: osip_message.h:94
void osip_message_set_status_code(osip_message_t *sip, int statuscode)
Set the status code.
osip_list_t proxy_authenticates
Proxy-Authenticate headers.
Definition: osip_message.h:86
osip_list_t alert_infos
Alert-Info headers.
Definition: osip_message.h:67
int osip_message_to_str_sipfrag(osip_message_t *sip, char **dest, size_t *message_length)
Get a string representation of a message/sipfrag part stored in an osip_message_t element...
int status_code
Status Code (SIP answer only)
Definition: osip_message.h:60
osip_mime_version_t * mime_version
Mime-Version header.
Definition: osip_message.h:85
Definition of the Call-Id header.
Definition: osip_call_id.h:45
Structure for referencing url parameters.
Definition: osip_uri.h:55
char * sip_method
METHOD (SIP request only)
Definition: osip_message.h:58
osip_to_t * to
To header.
Definition: osip_message.h:93
osip_call_id_t * call_id
Call-ID header.
Definition: osip_message.h:72
Structure for referencing SIP urls.
Definition: osip_uri.h:167
char * osip_generic_param_get_name(const osip_generic_param_t *generic_param)
Get the name of a generic parameter element.
int osip_message_init(osip_message_t **sip)
Allocate a osip_message_t element.
osip_list_t call_infos
Call-Infos header.
Definition: osip_message.h:73
osip_list_t bodies
List of attachements.
Definition: osip_message.h:99
osip_list_t authentication_infos
authentication_info headers
Definition: osip_message.h:69
osip_list_t headers
Other headers.
Definition: osip_message.h:97
osip_list_t error_infos
Error-Info headers.
Definition: osip_message.h:82