2010-01-10 20:38:43 +00:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2009 Mamadou Diop.
|
|
|
|
*
|
2010-04-06 00:57:03 +00:00
|
|
|
* Contact: Mamadou Diop <diopmamadou(at)doubango.org>
|
2010-01-10 20:38:43 +00:00
|
|
|
*
|
|
|
|
* This file is part of Open Source Doubango Framework.
|
|
|
|
*
|
|
|
|
* DOUBANGO 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.
|
|
|
|
*
|
|
|
|
* DOUBANGO 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
|
2010-02-17 19:48:35 +00:00
|
|
|
* GNU General Public License for more details.
|
2010-01-10 20:38:43 +00:00
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with DOUBANGO.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**@file tsip_message.h
|
|
|
|
* @brief Represents a SIP message. A SIP message is either a request from a client to a server, or a
|
|
|
|
* response from a server to a client. See RFC 3261 suc-bclause 7.
|
|
|
|
*
|
2010-04-06 00:57:03 +00:00
|
|
|
* @author Mamadou Diop <diopmamadou(at)doubango.org>
|
2010-01-10 20:38:43 +00:00
|
|
|
*
|
|
|
|
* @date Created: Sat Nov 8 16:54:58 2009 mdiop
|
|
|
|
*/
|
|
|
|
#ifndef TSIP_MESSAGE_H
|
|
|
|
#define TSIP_MESSAGE_H
|
|
|
|
|
2010-03-13 06:22:28 +00:00
|
|
|
#include "tinySIP_config.h"
|
|
|
|
|
|
|
|
#include "tinySIP/headers/tsip_header_Call_ID.h"
|
|
|
|
#include "tinySIP/headers/tsip_header_Contact.h"
|
|
|
|
#include "tinySIP/headers/tsip_header_Content_Length.h"
|
|
|
|
#include "tinySIP/headers/tsip_header_Content_Type.h"
|
|
|
|
#include "tinySIP/headers/tsip_header_CSeq.h"
|
|
|
|
#include "tinySIP/headers/tsip_header_Expires.h"
|
|
|
|
#include "tinySIP/headers/tsip_header_From.h"
|
|
|
|
#include "tinySIP/headers/tsip_header_P_Access_Network_Info.h"
|
|
|
|
#include "tinySIP/headers/tsip_header_To.h"
|
|
|
|
#include "tinySIP/headers/tsip_header_Via.h"
|
2010-01-10 20:38:43 +00:00
|
|
|
|
|
|
|
#include "tnet_types.h"
|
|
|
|
|
|
|
|
#include "tsk_object.h"
|
|
|
|
#include "tsk_buffer.h"
|
|
|
|
|
|
|
|
TSIP_BEGIN_DECLS
|
|
|
|
|
|
|
|
#define TSIP_MESSAGE_VERSION_10 "SIP/1.0"
|
|
|
|
#define TSIP_MESSAGE_VERSION_20 "SIP/2.0"
|
|
|
|
#define TSIP_MESSAGE_VERSION_DEFAULT TSIP_MESSAGE_VERSION_20
|
|
|
|
|
2010-03-29 00:38:58 +00:00
|
|
|
#define TSIP_MESSAGE_IS_REQUEST(self) ((self) ? (self)->type == tsip_request : tsk_false)
|
|
|
|
#define TSIP_MESSAGE_IS_RESPONSE(self) ((self) ? (self)->type == tsip_response : tsk_false)
|
2010-01-10 20:38:43 +00:00
|
|
|
|
|
|
|
#define TSIP_MESSAGE(self) ((tsip_message_t*)(self))
|
|
|
|
#define TSIP_MESSAGE_AS_RESPONSE(self) ((tsip_response_t*)(self))
|
|
|
|
#define TSIP_MESSAGE_AS_REQUEST(self) ((tsip_request_t*)(self))
|
|
|
|
|
|
|
|
|
2010-03-10 18:05:59 +00:00
|
|
|
#define TSIP_RESPONSE_CODE(self) (TSIP_MESSAGE_IS_RESPONSE((self)) ? (self)->status_code : 0)
|
2010-03-29 00:38:58 +00:00
|
|
|
#define TSIP_RESPONSE_PHRASE(self) (TSIP_MESSAGE_IS_RESPONSE((self)) ? (self)->reason_phrase : tsk_null)
|
2010-01-10 20:38:43 +00:00
|
|
|
|
2010-01-11 02:02:29 +00:00
|
|
|
#define TSIP_REQUEST_METHOD(self) ((self)->method)
|
|
|
|
#define TSIP_REQUEST_URI(self) ((self)->uri)
|
2010-01-10 20:38:43 +00:00
|
|
|
|
2010-03-24 01:57:57 +00:00
|
|
|
#define TSIP_MESSAGE_CSEQ_METHOD(self) ((self)->CSeq ? (self)->CSeq->method : tsk_null)
|
|
|
|
#define TSIP_MESSAGE_HAS_CONTENT(self) ((self) && (self)->Content && (self)->Content->data)
|
|
|
|
#define TSIP_MESSAGE_CONTENT_LENGTH(self) (uint32_t)(((self) && (self)->Content_Length) ? (self)->Content_Length->length : 0)
|
2010-04-27 17:14:20 +00:00
|
|
|
#define TSIP_MESSAGE_CONTENT_DATA(self) (TSIP_MESSAGE_HAS_CONTENT(self) ? (self)->Content->data : tsk_null)
|
|
|
|
#define TSIP_MESSAGE_CONTENT(self) (TSIP_MESSAGE_HAS_CONTENT(self) ? (self)->Content : tsk_null)
|
|
|
|
#define TSIP_MESSAGE_CONTENT_TYPE(self) (((self) && (self)->Content_Type) ? (self)->Content_Type->type : tsk_null)
|
2010-02-18 18:37:57 +00:00
|
|
|
|
2010-03-17 01:20:38 +00:00
|
|
|
#define TSIP_REQUEST_IS_ACK(self) ((self) &&((self)->request_type==tsip_ACK))
|
|
|
|
#define TSIP_REQUEST_IS_BYE(self) ((self) &&((self)->request_type==tsip_BYE))
|
|
|
|
#define TSIP_REQUEST_IS_CANCEL(self) ((self) &&((self)->request_type==tsip_CANCEL))
|
|
|
|
#define TSIP_REQUEST_IS_INVITE(self) ((self) &&((self)->request_type==tsip_INVITE))
|
|
|
|
#define TSIP_REQUEST_IS_OPTIONS(self) ((self) &&((self)->request_type==tsip_OPTIONS))
|
|
|
|
#define TSIP_REQUEST_IS_REGISTER(self) ((self) &&((self)->request_type==tsip_REGISTER))
|
|
|
|
#define TSIP_REQUEST_IS_SUBSCRIBE(self) ((self) &&((self)->request_type==tsip_SUBSCRIBE))
|
|
|
|
#define TSIP_REQUEST_IS_NOTIFY(self) ((self) &&((self)->request_type==tsip_NOTIFY))
|
|
|
|
#define TSIP_REQUEST_IS_REFER(self) ((self) &&((self)->request_type==tsip_REFER))
|
|
|
|
#define TSIP_REQUEST_IS_INFO(self) ((self) &&((self)->request_type==tsip_INFO))
|
|
|
|
#define TSIP_REQUEST_IS_UPDATE(self) ((self) &&((self)->request_type==tsip_UPDATE))
|
|
|
|
#define TSIP_REQUEST_IS_MESSAGE(self) ((self) &&((self)->request_type==tsip_MESSAGE))
|
|
|
|
#define TSIP_REQUEST_IS_PUBLISH(self) ((self) &&((self)->request_type==tsip_PUBLISH))
|
|
|
|
#define TSIP_REQUEST_IS_PRACK(self) ((self) &&((self)->request_type==tsip_PRACK))
|
2010-01-10 20:38:43 +00:00
|
|
|
|
|
|
|
#define TSIP_RESPONSE_IS(self, code) (TSIP_RESPONSE_CODE((self)) == code)
|
2010-02-18 18:37:57 +00:00
|
|
|
#define TSIP_RESPONSE_IS_NXX(self, N) (TSIP_MESSAGE_IS_RESPONSE((self)) && N##00<= TSIP_RESPONSE_CODE((self)) && TSIP_RESPONSE_CODE((self)) <= N##99)
|
2010-01-10 20:38:43 +00:00
|
|
|
#define TSIP_RESPONSE_IS_1XX(self) TSIP_RESPONSE_IS_NXX(self, 1)
|
|
|
|
#define TSIP_RESPONSE_IS_2XX(self) TSIP_RESPONSE_IS_NXX(self, 2)
|
|
|
|
#define TSIP_RESPONSE_IS_3XX(self) TSIP_RESPONSE_IS_NXX(self, 3)
|
|
|
|
#define TSIP_RESPONSE_IS_4XX(self) TSIP_RESPONSE_IS_NXX(self, 4)
|
|
|
|
#define TSIP_RESPONSE_IS_5XX(self) TSIP_RESPONSE_IS_NXX(self, 5)
|
|
|
|
#define TSIP_RESPONSE_IS_6XX(self) TSIP_RESPONSE_IS_NXX(self, 6)
|
2010-02-18 18:37:57 +00:00
|
|
|
#define TSIP_RESPONSE_IS_23456(self) (TSIP_MESSAGE_IS_RESPONSE((self)) && 200<= TSIP_RESPONSE_CODE((self)) && TSIP_RESPONSE_CODE((self)) <= 699)
|
2010-03-17 01:20:38 +00:00
|
|
|
#define TSIP_RESPONSE_IS_3456(self) (TSIP_MESSAGE_IS_RESPONSE((self)) && 300<= TSIP_RESPONSE_CODE((self)) && TSIP_RESPONSE_CODE((self)) <= 699)
|
2010-01-10 20:38:43 +00:00
|
|
|
|
2010-05-03 07:57:48 +00:00
|
|
|
/** Defines the message type (Request or Response).
|
2010-01-10 20:38:43 +00:00
|
|
|
**/
|
|
|
|
typedef enum tsip_message_type_e
|
|
|
|
{
|
|
|
|
tsip_unknown,
|
|
|
|
tsip_request,
|
|
|
|
tsip_response
|
|
|
|
}
|
|
|
|
tsip_message_type_t;
|
|
|
|
|
2010-02-23 17:58:42 +00:00
|
|
|
typedef enum tsip_request_type_e
|
|
|
|
{
|
2010-03-26 17:56:55 +00:00
|
|
|
tsip_NONE = 0,
|
2010-02-23 17:58:42 +00:00
|
|
|
|
|
|
|
tsip_ACK,
|
|
|
|
tsip_BYE,
|
2010-03-04 19:06:51 +00:00
|
|
|
tsip_CANCEL,
|
2010-02-23 17:58:42 +00:00
|
|
|
tsip_INVITE,
|
|
|
|
tsip_OPTIONS,
|
|
|
|
tsip_REGISTER,
|
|
|
|
tsip_SUBSCRIBE,
|
|
|
|
tsip_NOTIFY,
|
|
|
|
tsip_REFER,
|
|
|
|
tsip_INFO,
|
|
|
|
tsip_UPDATE,
|
|
|
|
tsip_MESSAGE,
|
|
|
|
tsip_PUBLISH,
|
|
|
|
tsip_PRACK
|
|
|
|
}
|
|
|
|
tsip_request_type_t;
|
|
|
|
|
|
|
|
|
2010-01-11 02:02:29 +00:00
|
|
|
///**
|
|
|
|
// * @struct tsip_request_line_t
|
|
|
|
// *
|
|
|
|
// * @brief Defines SIP request header line.
|
|
|
|
// * ABNF: Request-Line = Method SP Request-URI SP SIP-Version CRLF
|
|
|
|
// * Ref: RFC 3261 subclause 7.1.
|
|
|
|
// * @sa tsip_status_line_t.
|
|
|
|
// *
|
|
|
|
// * @author Mamadou
|
|
|
|
// * @date 12/3/2009
|
|
|
|
//**/
|
|
|
|
//typedef struct tsip_request_line_s
|
|
|
|
//{
|
|
|
|
// char *method; /**< SIP method name. e.g REGISTER, ACK or INVITE.*/
|
|
|
|
// tsip_uri_t *uri; /**< The Request-URI is a SIP or SIPS URI as described in Section 19.1 or a general URI (RFC 2396 [5]). It indicates
|
|
|
|
// the user or service to which this request is being addressed. The Request-URI MUST NOT contain unescaped spaces or control
|
|
|
|
// characters and MUST NOT be enclosed in "<>". */
|
|
|
|
//}
|
|
|
|
//tsip_request_line_t;
|
|
|
|
//
|
|
|
|
///**
|
|
|
|
// * @struct tsip_status_line_t
|
|
|
|
// *
|
|
|
|
// * @brief Defines SIP response status line.
|
|
|
|
// * ABNF: Status-Line = SIP-Version SP Status-Code SP Reason-Phrase CRLF
|
|
|
|
// * Ref: RFC 3261 subclause 7.2.
|
|
|
|
// * @sa tsip_request_line_t.
|
|
|
|
// *
|
|
|
|
// * @author Mamadou
|
|
|
|
// * @date 12/3/2009
|
|
|
|
//**/
|
|
|
|
//typedef struct tsip_status_line_s
|
|
|
|
//{
|
|
|
|
// short status_code; /**< 3-digit integer result code that indicates the outcome of an attempt to understand and satisfy a request. */
|
|
|
|
// char *reason_phrase; /**< Textual description related to the status code. */
|
|
|
|
//}
|
|
|
|
//tsip_status_line_t;
|
2010-01-10 20:38:43 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @struct tsip_message_t
|
|
|
|
*
|
|
|
|
* @brief Represents a SIP message. A SIP message is either a request from a client to a server,
|
|
|
|
* or a response from a server to a client. See RFC 3261 suc-bclause 7.
|
2010-04-21 17:33:32 +00:00
|
|
|
* You must call @ref tsip_message_create to create a sip message and TSK_OBJECT_SAFE_FREE to free the message.
|
2010-01-10 20:38:43 +00:00
|
|
|
*
|
|
|
|
* @author Mamadou
|
|
|
|
* @date 12/2/2009
|
|
|
|
**/
|
|
|
|
typedef struct tsip_message_s
|
|
|
|
{
|
|
|
|
TSK_DECLARE_OBJECT;
|
|
|
|
|
|
|
|
char *sip_version; /**< The SIP version. Only 'SIP/2.0' is supported. */
|
|
|
|
tsip_message_type_t type; /**< The type of this SIP message. */
|
|
|
|
|
2010-01-11 23:39:53 +00:00
|
|
|
#if !defined(__C99__) /* C99 does not allow unnamed structs/unions */
|
2010-01-10 20:38:43 +00:00
|
|
|
union
|
|
|
|
{
|
2010-01-11 02:02:29 +00:00
|
|
|
struct
|
|
|
|
{
|
2010-01-11 23:39:53 +00:00
|
|
|
#endif
|
2010-01-11 02:02:29 +00:00
|
|
|
char *method; /**< SIP method name. e.g REGISTER, ACK or INVITE.*/
|
|
|
|
tsip_uri_t *uri; /**< The Request-URI is a SIP or SIPS URI as described in Section 19.1 or a general URI (RFC 2396 [5]). It indicates
|
|
|
|
the user or service to which this request is being addressed. The Request-URI MUST NOT contain unescaped spaces or control
|
|
|
|
characters and MUST NOT be enclosed in "<>". */
|
2010-02-23 17:58:42 +00:00
|
|
|
tsip_request_type_t request_type;
|
2010-01-11 23:39:53 +00:00
|
|
|
#if !defined(__C99__)
|
2010-01-11 02:02:29 +00:00
|
|
|
};
|
|
|
|
struct
|
|
|
|
{
|
2010-01-11 23:39:53 +00:00
|
|
|
#endif
|
2010-01-11 02:02:29 +00:00
|
|
|
short status_code; /**< 3-digit integer result code that indicates the outcome of an attempt to understand and satisfy a request. */
|
|
|
|
char *reason_phrase; /**< Textual description related to the status code. */
|
2010-01-11 23:39:53 +00:00
|
|
|
#if !defined(__C99__)
|
2010-01-11 02:02:29 +00:00
|
|
|
};
|
2010-01-10 20:38:43 +00:00
|
|
|
};
|
|
|
|
|
2010-01-11 23:39:53 +00:00
|
|
|
#endif
|
2010-01-10 20:38:43 +00:00
|
|
|
/*== MOST COMMON HEADERS. */
|
|
|
|
tsip_header_Via_t *firstVia; /**< First Via header. */
|
|
|
|
tsip_header_From_t *From;
|
|
|
|
tsip_header_To_t *To;
|
|
|
|
tsip_header_Contact_t *Contact;
|
|
|
|
tsip_header_Call_ID_t *Call_ID;
|
|
|
|
tsip_header_CSeq_t *CSeq;
|
|
|
|
tsip_header_Expires_t *Expires;
|
|
|
|
|
|
|
|
tsip_header_Content_Type_t *Content_Type;
|
|
|
|
tsip_header_Content_Length_t *Content_Length;
|
|
|
|
tsk_buffer_t *Content;
|
|
|
|
|
|
|
|
/*== OTHER HEADERS*/
|
|
|
|
tsip_headers_L_t *headers;
|
|
|
|
|
|
|
|
/*== */
|
|
|
|
tnet_fd_t sockfd;
|
2010-02-25 19:03:32 +00:00
|
|
|
unsigned update:1;
|
2010-01-10 20:38:43 +00:00
|
|
|
}
|
|
|
|
tsip_message_t;
|
|
|
|
|
|
|
|
typedef tsip_message_t tsip_request_t; /**< SIP request message. */
|
|
|
|
typedef tsip_message_t tsip_response_t; /**< SIP response message. */
|
|
|
|
|
|
|
|
|
|
|
|
TINYSIP_API int tsip_message_add_header(tsip_message_t *self, const tsip_header_t *hdr);
|
2010-03-22 01:56:49 +00:00
|
|
|
TINYSIP_API int tsip_message_add_headers(tsip_message_t *self, ...);
|
2010-02-18 18:37:57 +00:00
|
|
|
TINYSIP_API int tsip_message_add_content(tsip_message_t *self, const char* content_type, const void* content, size_t size);
|
2010-01-10 20:38:43 +00:00
|
|
|
|
|
|
|
#if !defined(_MSC_VER) || defined(__GNUC__)
|
|
|
|
static void TSIP_MESSAGE_ADD_HEADER(tsip_message_t *self, ...)
|
|
|
|
{
|
|
|
|
va_list ap;
|
|
|
|
tsip_header_t *header;
|
|
|
|
const tsk_object_def_t *objdef;
|
|
|
|
|
|
|
|
va_start(ap, self);
|
|
|
|
objdef = va_arg(ap, const tsk_object_def_t*);
|
2010-03-29 00:38:58 +00:00
|
|
|
header = tsk_object_new_2(objdef, &ap);
|
2010-01-10 20:38:43 +00:00
|
|
|
va_end(ap);
|
|
|
|
|
|
|
|
tsip_message_add_header(self, header);
|
|
|
|
tsk_object_unref(header);
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
#define TSIP_MESSAGE_ADD_HEADER(self, objdef, ...) \
|
|
|
|
{ \
|
|
|
|
tsip_header_t *header = tsk_object_new(objdef, __VA_ARGS__); \
|
|
|
|
tsip_message_add_header(self, header); \
|
|
|
|
tsk_object_unref(header); \
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
TINYSIP_API const tsip_header_t *tsip_message_get_headerAt(const tsip_message_t *self, tsip_header_type_t type, size_t index);
|
|
|
|
TINYSIP_API const tsip_header_t *tsip_message_get_header(const tsip_message_t *self, tsip_header_type_t type);
|
2010-03-22 01:56:49 +00:00
|
|
|
TINYSIP_API tsk_bool_t tsip_message_allowed(const tsip_message_t *self, const char* method);
|
|
|
|
TINYSIP_API tsk_bool_t tsip_message_supported(const tsip_message_t *self, const char* option);
|
|
|
|
TINYSIP_API tsk_bool_t tsip_message_required(const tsip_message_t *self, const char* option);
|
2010-01-10 20:38:43 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
2010-04-23 16:54:45 +00:00
|
|
|
TINYSIP_API int64_t tsip_message_getExpires(const tsip_message_t *message);
|
2010-01-10 20:38:43 +00:00
|
|
|
TINYSIP_API uint32_t tsip_message_getContent_length(const tsip_message_t *message);
|
|
|
|
TINYSIP_API int32_t tsip_message_getCSeq(const tsip_message_t *message);
|
|
|
|
|
|
|
|
TINYSIP_API int tsip_message_tostring(const tsip_message_t *self, tsk_buffer_t *output);
|
|
|
|
|
2010-02-23 17:58:42 +00:00
|
|
|
TINYSIP_API tsip_request_type_t tsip_request_get_type(const char* method);
|
2010-01-10 20:38:43 +00:00
|
|
|
TINYSIP_API tsip_request_t *tsip_request_new(const char* method, const tsip_uri_t *request_uri, const tsip_uri_t *from, const tsip_uri_t *to, const char *call_id, int32_t cseq);
|
|
|
|
TINYSIP_API tsip_response_t *tsip_response_new(short status_code, const char* reason_phrase, const tsip_request_t *request);
|
|
|
|
|
2010-04-21 17:33:32 +00:00
|
|
|
TINYSIP_API tsip_message_t* tsip_message_create();
|
|
|
|
TINYSIP_API tsip_request_t* tsip_request_create(const char* method, const tsip_uri_t* uri);
|
|
|
|
TINYSIP_API tsip_response_t* tsip_response_create(const tsip_request_t* request, short status_code, const char* reason_phrase);
|
|
|
|
|
|
|
|
TINYSIP_GEXTERN const tsk_object_def_t *tsip_message_def_t;
|
2010-01-10 20:38:43 +00:00
|
|
|
|
|
|
|
TSIP_END_DECLS
|
|
|
|
|
|
|
|
#endif /* TSIP_MESSAGE_H */
|
|
|
|
|