#ifndef _SIP__H
#define	_SIP__H

#include "sip_pub.h"

// SIP general constant
#define SIP_MAX_USER_NAME_LEN				64//128
#define SIP_MAX_PASSWORD_LEN				16
#define SIP_MAX_DOMAIN_NAME_LEN			128//256
#define SIP_MAX_REASON_PHRASE_LEN		128
#define SIP_MAX_HDR_FLAG_NUM				2
#define SIP_MAX_BODY_LEN					1500
#define SIP_MAX_DISPLAY_NAME_LEN			64
#define SIP_MAX_CALL_ID_LEN				128
#define SIP_MAX_GEN_PARA_NUM				8
#define SIP_MAX_PARA_STRING_LEN			64//128
#define SIP_MAX_PARA_VAL_LEN				4
#define SIP_MAX_PARA_NUM					4//8
#define SIP_MAX_NUM_OF_TRANS				4096//8192
#define SIP_MAX_NUM_OF_VIAS				8//32
#define SIP_MAX_NUM_OF_CONTACTS			4
#define SIP_MAX_NUM_OF_RECORD_ROUTES	8//32
#define SIP_MAX_NUM_OF_ROUTES			8//32
#define SIP_MAX_NUM_OF_ALLOW				8//32
#define SIP_MAX_NUM_OF_ACCEPT				8
#define SIP_MAX_NUM_OF_ACCEPT_ENCODING	4
#define SIP_MAX_NUM_OF_ACCEPT_LANGUAGE	8
#define SIP_MAX_LENGTH_OF_EVENT			32
#define SIP_MAX_LENGTH_OF_USER_AGENT	64
#define SIP_MAX_LENGTH_OF_SUBJECT			128
#define SIP_MAX_LENGTH_OF_SUB_STATE		128
#define SIP_MAX_VIA_DOMAIN_NAME_LEN		64

#define SIP_MAX_NUM_OF_SIP_SUB_BODY		2			

#define SIP_URI_TYPE_SIP				1
#define SIP_URI_TYPE_SIPS				2
#define SIP_URI_TYPE_TEL				3

#define SIP_API_TYPE_REQUEST			1
#define SIP_API_TYPE_RESPONSE			2
#define SIP_API_TYPE_MANAGEMENT		3

#define SIP_API_PNAME_TAG				1
#define SIP_API_PNAME_BRANCH			2
#define SIP_API_PNAME_EXPIRES			3
#define SIP_API_PNAME_USER				4
#define SIP_API_PNAME_LR				5
#define SIP_API_PNAME_BOUNDARY		6
#define SIP_API_PNAME_HANDLING		7
#define SIP_API_PNAME_TRANSPORT		8
#define SIP_API_PNAME_RPOTR			9
#define SIP_API_PNAME_VERSION			10
#define SIP_API_PNAME_BASE				11

#define SIP_API_PTYPE_STRING			1
#define SIP_API_PTYPE_VALUE			2
#define SIP_API_PTYPE_TAG				3

#define SIP_API_PROTO_UDP				1
#define SIP_API_PROTO_TCP				2
#define SIP_API_PROTO_SCTP				3

#define SIP_NULL_TRANS_ID				0xFFFF
#define SIP_NULL_UP_PORT				0xFFFF

#define SIP_TRANSPORT_LAYER				1
#define SIP_TRANSACTION_LAYER				2

#define SIP_API_REQ_MSG					1
#define SIP_API_RES_MSG					2
#define SIP_API_MANAGE_MSG				3

#define	SIP_TRANS_CLIENT				1
#define	SIP_TRANS_SERVER				2

#define	SIP_TRANS_INVITE				1
#define	SIP_TRANS_NON_INVITE			2

#define SIP_ACCEPT_TYPE_APPLICATION			1
#define SIP_ACCEPT_TYPE_MULTIPART				2
#define SIP_ACCEPT_TYPE_WILDCARD				3

#define SIP_ACCEPT_SUB_TYPE_SDP				1
#define SIP_ACCEPT_SUB_TYPE_ISUP				2
#define SIP_ACCEPT_SUB_TYPE_MIXED				3
#define SIP_ACCEPT_SUB_TYPE_WILDCARD			4

#define SIP_ACCEPT_ENCODING_IDENTITY			1
#define SIP_ACCEPT_ENCODING_GZIP				2
#define SIP_ACCEPT_ENCODING_TAR				3

#define SIP_ACCEPT_LANGUAGE_EN				1

#define SIP_CONTENT_TYPE_APPLICATION			1
#define SIP_CONTENT_TYPE_MULTIPART			2
#define SIP_CONTENT_TYPE_TEXT					3
#define SIP_CONTENT_TYPE_IMAGE				4
#define SIP_CONTENT_TYPE_AUDIO				5
#define SIP_CONTENT_TYPE_VEDIO				6

#define SIP_CONTENT_SUB_TYPE_SDP				1
#define SIP_CONTENT_SUB_TYPE_ISUP				2
#define SIP_CONTENT_SUB_TYPE_MIXED			3
#define SIP_CONTENT_SUB_TYPE_MESSAGE			4
#define SIP_CONTENT_SUB_TYPE_SIGNED			5
#define SIP_CONTENT_SUB_TYPE_PKCS7_MIME		6

#define SIP_CONTENT_DISPOSITION_SIGNAL		1

#define SIP_CONTENT_ENCODING_IDENTITY		1
#define SIP_CONTENT_ENCODING_GZIP				2
#define SIP_CONTENT_ENCODING_TAR				3

#define SIP_CONTENT_LANGUAGE_EN				1

#define SIP_DATE_TYPE_GMT						1

#define SIP_DATE_WEEK_DAY_SUN				1
#define SIP_DATE_WEEK_DAY_MON				2
#define SIP_DATE_WEEK_DAY_TUE					3
#define SIP_DATE_WEEK_DAY_WED				4
#define SIP_DATE_WEEK_DAY_THU				5
#define SIP_DATE_WEEK_DAY_FRI					6
#define SIP_DATE_WEEK_DAY_SAT					7

#define SIP_DATE_MONTH_JAN					1
#define SIP_DATE_MONTH_FEB					2
#define SIP_DATE_MONTH_MAR					3
#define SIP_DATE_MONTH_APR					4
#define SIP_DATE_MONTH_MAY					5
#define SIP_DATE_MONTH_JUN					6
#define SIP_DATE_MONTH_JUL						7
#define SIP_DATE_MONTH_AUG					8
#define SIP_DATE_MONTH_SEP					9
#define SIP_DATE_MONTH_OCT					10
#define SIP_DATE_MONTH_NOV					11
#define SIP_DATE_MONTH_DEC					12

#define SIP_OPTION_TAG_100_REL				1
#define SIP_OPTION_TAG_FOO						2

#define SIP_TRANSACTION_TIMEOUT			99
#define SIP_TRANSPORT_ERROR				98

// SIP general headers mask
#define SIP_HDR_ACCEPT_MASK					0x00000001
#define SIP_HDR_ACCEPT_ENCODING_MASK			0x00000002
#define SIP_HDR_ACCEPT_LANGUAGE_MASK		0x00000004
#define SIP_HDR_ALLOW_MASK					0x00000008
#define SIP_HDR_CALL_ID_MASK					0x00000010
#define SIP_HDR_CONTACT_MASK					0x00000020
#define SIP_HDR_CSEQ_MASK						0x00000040
#define SIP_HDR_DATE_MASK						0x00000080
#define SIP_HDR_EXPIRES_MASK					0x00000100
#define SIP_HDR_FROM_MASK						0x00000200
#define SIP_HDR_TO_MASK						0x00000400
#define SIP_HDR_VIA_MASK						0x00000800
#define SIP_HDR_CONTENT_DISPOSITION_MASK	0x00001000
#define SIP_HDR_CONTENT_TYPE_MASK			0x00002000
#define SIP_HDR_CONTENT_ENCODING_MASK		0x00004000
#define SIP_HDR_CONTENT_LANGUAGE_MASK		0x00008000
#define SIP_HDR_CONTENT_LENGTH_MASK			0x00010000
#define SIP_HDR_RECORD_ROUTE_MASK			0x00020000
#define SIP_HDR_TIMESTAMP_MASK				0x00040000
#define SIP_HDR_MIME_VERSION_MASK			0x00080000
#define SIP_HDR_SUPPORTED_MASK				0x00100000
#define SIP_HDR_USER_AGENT_MASK             		0x00200000

// SIP request headers mask
#define SIP_HDR_MAX_FORWARDS_MASK           		0x00000001
#define SIP_HDR_ROUTE_MASK                  			0x00000002
#define SIP_HDR_PROXY_REQUIRE_MASK          		0x00000004
#define SIP_HDR_SUBJECT_MASK               	 		0x00000008
#define SIP_HDR_REQUIRE_MASK                			0x00000010
#define SIP_HDR_REFER_TO_MASK               		0x00000020
#define SIP_HDR_EVENT_MASK                  			0x00000040
#define SIP_HDR_SUBSCRIPTION_STATE_MASK     	0x00000080

//SIP response headers mask
#define SIP_HDR_UNSUPPORTED_MASK				0x00000001//just used in 420 response
#define SIP_HDR_SERVER_MASK					0x00000002

#define SIP_METHOD_REGISTER			1
#define SIP_METHOD_INVITE				2
#define SIP_METHOD_ACK					3
#define SIP_METHOD_CANCEL				4
#define SIP_METHOD_BYE					5
#define SIP_METHOD_OPTIONS			6
#define SIP_METHOD_INFO				7
#define SIP_METHOD_PRACK				8
#define SIP_METHOD_UPDATE				9
#define SIP_METHOD_REFER				10
#define SIP_METHOD_NOTIFY				11
#define SIP_METHOD_RE_INVITE			12

#define SIP_METHOD_RESPONSE_INV_RINGING				30
#define SIP_METHOD_RESPONSE_INV_PROGRESS			31
#define SIP_METHOD_RESPONSE_INV_CONFIRM				32
#define SIP_METHOD_RESPONSE_INV_REDIR				33
#define SIP_METHOD_RESPONSE_INV_REL					34
#define SIP_METHOD_RESPONSE_CANCEL					35
#define SIP_METHOD_RESPONSE_BYE						36
#define SIP_METHOD_RESPONSE_CONFIRM					37//just for other method response
#define SIP_METHOD_RESPONSE_REL						38//just for other method response
#define SIP_METHOD_RESPONSE_TIMEOUT					39
#define SIP_METHOD_RESPONSE_RE_INV_RINGING			40
#define SIP_METHOD_RESPONSE_RE_INV_PROGRESS			41
#define SIP_METHOD_RESPONSE_RE_INV_CONFIRM			43
#define SIP_METHOD_RESPONSE_RE_INV_RETRANSMIT		44
#define SIP_METHOD_RESPONSE_RE_INV_FAILED			45
#define SIP_METHOD_RESPONSE_RE_INV_RELEASE			46
#define SIP_METHOD_RESPONSE_UPDATE_CONFIRM			47
#define SIP_METHOD_RESPONSE_UPDATE_FAILED			48

#define SIP_PROXY_TYPE_NONE				0
#define SIP_PROXY_TYPE_STATEFUL			1
#define SIP_PROXY_TYPE_STATELESS			2

// SIP general parameters struct

typedef struct _SIP_GEN_PARA
{
	BYTE	paraName;
	BYTE	paraType;
//	char		paraStr[SIP_MAX_PARA_STRING_LEN];
//	DWORD	paraVal[SIP_MAX_PARA_VAL_LEN];
	union
	{
		char		paraStr[SIP_MAX_PARA_STRING_LEN];
		DWORD	paraVal[SIP_MAX_PARA_VAL_LEN];
	}para;
	
}SIP_GEN_PARA;

typedef struct _SIP_GEN_PARAMS
{
	BYTE			paraNum;
	SIP_GEN_PARA	para[SIP_MAX_PARA_NUM];
}SIP_GEN_PARAMS;

// SIP URI struct
typedef struct _SIP_URI
{
	BYTE		uriType;
	char			userName[SIP_MAX_USER_NAME_LEN];
	char			password[SIP_MAX_PASSWORD_LEN];
	struct
	{
		BYTE		type;
		union
		{
			DWORD	ipV4;
			DWORD	ipV6[4];
			char		domain[SIP_MAX_DOMAIN_NAME_LEN];
		}addr;
	}host;
	WORD			port;
	BYTE			transport;
	SIP_GEN_PARAMS	params;
}SIP_URI;

typedef struct _SIP_VIA_URI
{
	char				domain[SIP_MAX_VIA_DOMAIN_NAME_LEN];
	WORD			port;
//	SIP_GEN_PARAMS	params;
}SIP_VIA_URI;

// SIP general header struct

typedef struct _SIP_HDR_ACCEPT
{
	BYTE				type;
	BYTE				subType;
	SIP_GEN_PARAMS		params;
}SIP_HDR_ACCEPT;

typedef struct _SIP_HDR_ACCEPT_ENCODING
{
	BYTE				acceptEncoding;
	SIP_GEN_PARAMS		params;
}SIP_HDR_ACCEPT_ENCODING;

typedef struct _SIP_HDR_ACCEPT_LANGUAGE
{
	BYTE				acceptLanguage;
	SIP_GEN_PARAMS		params;
}SIP_HDR_ACCEPT_LANGUAGE;

typedef struct _SIP_HDR_CALL_ID
{
	char	value[SIP_MAX_CALL_ID_LEN];
	char	host[SIP_MAX_DOMAIN_NAME_LEN];
}SIP_HDR_CALL_ID;

typedef struct _SIP_HDR_CONTACT
{
	char 			dispName[SIP_MAX_DISPLAY_NAME_LEN];
	SIP_URI			url;
	SIP_GEN_PARAMS	params;
}SIP_HDR_CONTACT;

typedef struct _SIP_HDR_CONTACTS
{
	BYTE				num;
	BYTE				head;
	SIP_HDR_CONTACT	contacts[SIP_MAX_NUM_OF_CONTACTS];
}SIP_HDR_CONTACTS;

typedef struct _SIP_HDR_CSEQ
{
	DWORD	value;
	BYTE	method;
}SIP_HDR_CSEQ;

typedef struct _SIP_HDR_DATE
{
	BYTE	wkDay;
	BYTE	mDay;
	BYTE	mon;
	DWORD	year;
	BYTE	hour;
	BYTE	min;
	BYTE	sec;
	BYTE	dateType;
	
}SIP_HDR_DATE;

typedef struct _SIP_HDR_MIME_VERSION
{
	BYTE	mimeVersion;
}SIP_HDR_MIME_VERSION;

typedef struct _SIP_HDR_ENCRYPTION
{
}SIP_HDR_ENCRYPTION;

typedef struct _SIP_HDR_EXPIRES
{
	DWORD	value;
}SIP_HDR_EXPIRES;

typedef struct _SIP_HDR_FROM
{
	char 			dispName[SIP_MAX_DISPLAY_NAME_LEN];
	SIP_URI			url;
	SIP_GEN_PARAMS	params;
}SIP_HDR_FROM;

typedef struct _SIP_HDR_ORGANIZATION
{
}SIP_HDR_ORGANIZATION;

typedef struct _SIP_HDR_RECORD_ROUTE
{
	char 				dispName[SIP_MAX_DISPLAY_NAME_LEN];
	SIP_URI				url;
	SIP_GEN_PARAMS		params;
}SIP_HDR_RECORD_ROUTE;

typedef struct _SIP_HDR_RECORD_ROUTES
{
	BYTE					num;
	BYTE					head;
	SIP_HDR_RECORD_ROUTE	recRoutes[SIP_MAX_NUM_OF_RECORD_ROUTES];
}SIP_HDR_RECORD_ROUTES;

typedef struct _SIP_HDR_TIMESTAMP
{
	DWORD		timeStamp;
}SIP_HDR_TIMESTAMP;

typedef struct _SIP_HDR_TO
{
	char 			dispName[SIP_MAX_DISPLAY_NAME_LEN];
	SIP_URI			url;
	SIP_GEN_PARAMS	params;
}SIP_HDR_TO;

typedef struct _SIP_HDR_USER_AGENT
{
	BYTE	agent[SIP_MAX_LENGTH_OF_USER_AGENT];
}SIP_HDR_USER_AGENT;

typedef struct _SIP_HDR_VIA
{
	BYTE			version;
	BYTE			protocol;
//	SIP_URI			url;
	SIP_VIA_URI		url;
	SIP_GEN_PARAMS	params;
}SIP_HDR_VIA;

typedef struct _SIP_HDR_VIAS
{
	BYTE			num;
	BYTE			head;
	SIP_HDR_VIA		vias[SIP_MAX_NUM_OF_VIAS];
}SIP_HDR_VIAS;

// SIP request header struct
typedef struct _SIP_HDR_AUTHORIZATION
{
}SIP_HDR_AUTHORIZATION;

typedef struct _SIP_HDR_HIDE
{
}SIP_HDR_HIDE;

typedef struct _SIP_HDR_MAX_FORWARDS
{
	WORD	value;
}SIP_HDR_MAX_FORWARDS;

typedef struct _SIP_HDR_PRIORITY
{
}SIP_HDR_PRIORITY;

typedef struct _SIP_HDR_PROXY_AUTHORIZATION
{
}SIP_HDR_PROXY_AUTHORIZATION;

typedef struct _SIP_HDR_PROXY_REQUIRE
{
	BYTE	optionTag;
}SIP_HDR_PROXY_REQUIRE;

typedef struct _SIP_HDR_ROUTE
{
	char 				dispName[SIP_MAX_DISPLAY_NAME_LEN];
	SIP_URI				url;
	SIP_GEN_PARAMS		params;
}SIP_HDR_ROUTE;

typedef struct _SIP_HDR_ROUTES
{
	BYTE				num;
	BYTE				head;
	SIP_HDR_ROUTE		routes[SIP_MAX_NUM_OF_ROUTES];
}SIP_HDR_ROUTES;

typedef struct _SIP_HDR_REFER_TO
{
	char 			dispName[SIP_MAX_DISPLAY_NAME_LEN];
	SIP_URI			url;
	SIP_GEN_PARAMS	params;
}SIP_HDR_REFER_TO;

typedef struct _SIP_HDR_SUBSCRIPTION_STATE
{
	char    subscriptionState[SIP_MAX_LENGTH_OF_SUB_STATE];
}SIP_HDR_SUBSCRIPTION_STATE;

typedef struct _SIP_HDR_EVENT
{
    char    event[SIP_MAX_LENGTH_OF_EVENT];
}SIP_HDR_EVENT;

typedef struct _SIP_HDR_REQUIRE
{
	BYTE	optionTag;
}SIP_HDR_REQUIRE;

typedef struct _SIP_HDR_RESPONSE_KEY
{
}SIP_HDR_RESPONSE_KEY;

typedef struct _SIP_HDR_SUBJECT
{
	BYTE	subject[SIP_MAX_LENGTH_OF_SUBJECT];
}SIP_HDR_SUBJECT;

typedef struct _SIP_HDR_SUPPORTED
{
	BYTE	optionTag;
}SIP_HDR_SUPPORTED;

// SIP response header struct
typedef struct _SIP_HDR_ALLOW
{
	BYTE	num;
	BYTE	allowMethod[SIP_MAX_NUM_OF_ALLOW];
}SIP_HDR_ALLOW;

typedef struct _SIP_HDR_PROXY_AUTHENTICATE
{
}SIP_HDR_PROXY_AUTHENTICATE;

typedef struct _SIP_HDR_RETRY_AFTER
{
}SIP_HDR_RETRY_AFTER;

typedef struct _SIP_HDR_SERVER
{
	BYTE	server[64];
}SIP_HDR_SERVER;

typedef struct _SIP_HDR_UNSUPPORTED
{
	BYTE	optionTag;
}SIP_HDR_UNSUPPORTED;

typedef struct _SIP_HDR_WARNING
{
}SIP_HDR_WARNING;

typedef struct _SIP_HDR_WWW_AUTHENTICATE
{
}SIP_HDR_WWW_AUTHENTICATE;

// SIP message struct
typedef struct _SIP_START_LINE
{
	BYTE		sipVersion;									// Public
	
	BYTE		sipMethod;									// Request
	SIP_URI		requestUri;
	
	int			statusCode;									// Response
	char		reasonPhrase[SIP_MAX_REASON_PHRASE_LEN];
}SIP_START_LINE;

typedef struct _SIP_CONTENT_TYPE
{
	BYTE				type;
	BYTE				subType;
	SIP_GEN_PARAMS		params;
}SIP_CONTENT_TYPE;

typedef struct _SIP_CONTENT_DISPOSITION
{
	BYTE				contentDisposition;
	SIP_GEN_PARAMS		params;
}SIP_CONTENT_DISPOSITION;

typedef struct _SIP_MESSAGE_BODY
{
	DWORD						sipBodyHdrFlg[SIP_MAX_HDR_FLAG_NUM];
	SIP_CONTENT_TYPE			sipBodyContentType;
	SIP_CONTENT_DISPOSITION	sipBodyContentDisposition;
	BYTE 						msgBody[SIP_MAX_BODY_LEN];
}SIP_MESSAGE_BODY;

typedef struct _SIP_MESSAGE_BODYS
{
	BYTE					sipBodyNum;
	SIP_MESSAGE_BODY		sipBody[SIP_MAX_NUM_OF_SIP_SUB_BODY];
}SIP_MESSAGE_BODYS;

typedef struct _SIP_ENTITY
{
	DWORD							sipEntityHdrFlag[SIP_MAX_HDR_FLAG_NUM];						
	BYTE							sipHdrContentEncoding;
	SIP_CONTENT_DISPOSITION		sipHdrContentDisposition;
	WORD							sipHdrContentLength;
	SIP_CONTENT_TYPE				sipHdrContentType;
	BYTE							sipHdrContentLanguage;
//	BYTE 						sipBody[SIP_MAX_BODY_LEN];
	SIP_MESSAGE_BODYS				sipBodys;
}SIP_ENTITY;

typedef struct _SIP_REQUEST_HDR
{
    SIP_HDR_AUTHORIZATION		sipHdrAuthorization;
    SIP_HDR_HIDE				sipHdrHide;
    SIP_HDR_MAX_FORWARDS		sipHdrMaxForwards;
    SIP_HDR_PRIORITY			sipHdrPriority;
    SIP_HDR_PROXY_AUTHORIZATION	sipHdrProxyAuthorization;
    SIP_HDR_PROXY_REQUIRE		sipHdrProxyRequire;
    SIP_HDR_ROUTES				sipHdrRoutes;
    SIP_HDR_REQUIRE				sipHdrRequire;
    SIP_HDR_RESPONSE_KEY		sipHdrResKey;
	SIP_HDR_SUBJECT				sipHdrSubject;
	SIP_HDR_REFER_TO            sipHdrReferTo;
	SIP_HDR_SUBSCRIPTION_STATE  sipHdrSubscriptionState;
	SIP_HDR_EVENT               sipHdrEvent;
}SIP_REQUEST_HDR;

typedef struct _SIP_RESPONSE_HDR
{
    SIP_HDR_PROXY_AUTHENTICATE	sipHdrProxyAuthenticate;
    SIP_HDR_RETRY_AFTER			sipHdrRetryAfter;
    SIP_HDR_SERVER				sipHdrServer;
    SIP_HDR_UNSUPPORTED			sipHdrUnsupported;
    SIP_HDR_WARNING				sipHdrWarning;
    SIP_HDR_WWW_AUTHENTICATE	sipHdrWWWAuthenticate;
}SIP_RESPONSE_HDR;

typedef struct _SIP_MSG
{
	SIP_START_LINE				sipStartLine;
	
	// General Headers
	DWORD						sipGenHdrFlag[SIP_MAX_HDR_FLAG_NUM];
	SIP_HDR_ACCEPT				sipHdrAccept;
	SIP_HDR_ALLOW				sipHdrAllow;
	SIP_HDR_ACCEPT_ENCODING		sipHdrAcceptEncoding;
	SIP_HDR_ACCEPT_LANGUAGE		sipHdrAcceptLanguage;
	SIP_HDR_CALL_ID				sipHdrCallId;
	SIP_HDR_CONTACTS			sipHdrContacts;
	SIP_HDR_CSEQ				sipHdrCseq;
	SIP_HDR_DATE				sipHdrDate;
	SIP_HDR_MIME_VERSION		sipHdrMimeVer;
	SIP_HDR_ENCRYPTION			sipHdrEncryption;
	SIP_HDR_EXPIRES				sipHdrExpires;
	SIP_HDR_FROM				sipHdrFrom;
	SIP_HDR_ORGANIZATION		sipHdrOrganization;
	SIP_HDR_RECORD_ROUTES		sipHdrRecordRoutes;
	SIP_HDR_TIMESTAMP			sipHdrStamp;
	SIP_HDR_SUPPORTED			sipHdrSupported;
	SIP_HDR_TO					sipHdrTo;
	SIP_HDR_VIAS				sipHdrVias;
	SIP_HDR_USER_AGENT			sipHdrUserAgent;
	
	struct
	{
        DWORD    sipReHdrFlag[SIP_MAX_HDR_FLAG_NUM];
	    union
	    {
            SIP_REQUEST_HDR    sipReqHdr;
            SIP_RESPONSE_HDR   sipRspHdr;
	    }sipReHdr;
	}sipReStruct;
	
	SIP_ENTITY					sipEntity;
}SIP_MSG;

typedef struct _SIP_MANAGE
{
	BYTE	cmd;
}SIP_MANAGE;

typedef struct _SIP_TRANSPORT_ADDR
{
	BYTE	type;
	WORD	port;
	union
	{
		DWORD	ipV4;
		DWORD	ipV6[4];
	}addr;
}SIP_TRANSPORT_ADDR;

typedef struct _SIP_API_STRUCT
{
	BYTE 				sipApiType;		// SIP_API_REQ_MSG/SIP_API_RES_MSG/SIP_API_MANAGE_MSG
	SIP_TRANSPORT_ADDR	sipTransAddr;	// Transport address of the SIP message
	union
	{
		SIP_MSG			sipMsg;			// Including request and response
		SIP_MANAGE		sipManage;
	}sipApiMsg;
}SIP_API_STRUCT;

typedef struct _SIP_CR_MSG
{
    SIP_TRANSPORT_ADDR	sipTransAddr;
	SIP_START_LINE    sipCrStartLine;
    SIP_HDR_VIA       sipCrHdrVia;
	SIP_HDR_CSEQ      sipCrHdrCseq;
	SIP_HDR_TO        sipCrHdrTo;
	SIP_HDR_FROM      sipCrHdrFrom;
	SIP_HDR_CALL_ID   sipCrHdrCallId;
}SIP_CR_MSG;

// SIP USER struct
/* 	The upper layer register recv_proc call-back function to receive sip messages
	upPort: destination UP port the message will be sent to, if unknown, it should be set to 0xFFFF.
	sipPort: source SIP port the UP message is sent from, if no sip_port is maintained, it's set to 0xFFFF
	transFlag: indicates whether this message sent from SIP transport layer directly or sent from SIP transaction layer.
	sipApiMsg: a pointer to the message pointer that is pointing to the message struct of the upper layer, so the received message can be accessed at that address
	returns 0 if succeeds, otherwise returns -1
*/
typedef struct _SIP_USER
{
	BYTE	proxyType;
	char	userName[16];
	char	domain[SIP_MAX_DOMAIN_NAME_LEN];
	int 	(*recv_proc)(WORD sipPort, WORD upPort, BYTE transFlag, SIP_API_STRUCT *sipApiMsg);
}SIP_USER;

/*typedef struct _SIP_SIP_UA_USER
{
    char    domain[SIP_MAX_DOMAIN_NAME_LEN];
}SIP_SIP_UA_USER;*/

// Should be called in the main program when system starts up,
// Returns 0 if succeeds, otherwise returns -1
int sip_init();

// Should be called every 10 ms in the platform section of the main program
void sip_timer();
void sip_t10ms();

/* 	The upper layer uses this function to send sip message to the peer
 	sipTransId: destination SIP port the UP message will be sent to, if unknown, it should be set to 0xFFFF
 	upPort: source UP port the message is sent from
 	transFlag: indicates whether this message will be sent within SIP transaction layer (stateful proxy or user agent),
 				or directly goes to the SIP transport layer (stateless proxy)
 	sipApiMsg: a pointer pointing to the actual struct of the message to be sent to the SIP module
 	if succeeds, returns sip_port, otherwise return a negative value
 	if succeeds, and no sip_port is maintained for this message, returns 0xFFFF
*/
int sip_send_msg(WORD sipTransId, WORD upPort, BYTE transFlag, SIP_API_STRUCT *sipApiMsg);

/*	The upper layer register its domain name and message receive callback function to the SIP module
	if succeeds, returns 0, otherwise returns -1
*/
int sip_register_user(SIP_USER *sipUser);

/*	The upper layer use this function to create trascation
	client: clent/server
	method: invite/non-invite
*/
int sip_create_transaction(BYTE client, BYTE method, BYTE userIndex, WORD upPort, SIP_API_STRUCT *msg);

int sip_create_trans_branch(WORD transId, SIP_GEN_PARA *branch);

#endif
