#ifndef _SIP_UA_DIALOG_H
#define _SIP_UA_DIALOG_H

#include "sip_ua_pub.h"
#include "sip.h"
#include "sip_ua_const.h"

#define SIP_CALLEE                  1
#define SIP_CALLER                  2

#define SIP_UA_DIALOG_IDLE						0
#define SIP_UA_DIALOG_EARLY					1
#define SIP_UA_DIALOG_WAIT_ACK_FOR_200		2
#define SIP_UA_DIALOG_CONFIRMED				3
#define SIP_UA_DIALOG_DESTROY					4

#define SIP_UA_DIALOG_REMOTE_TARGET_FLAG		0x0001
#define SIP_UA_DIALOG_RECORD_ROUTE_SEND_FLAG	0x0002

typedef struct _SIP_UA_URI
{
    BYTE            uriType;
    char            userName[SIP_MAX_USER_NAME_LEN];
    char            password[SIP_MAX_PASSWORD_LEN];

    char    domain[SIP_MAX_DOMAIN_NAME_LEN];

}SIP_UA_URI;

typedef struct _SIP_DIALOG
{
    BYTE                        flag;
    BYTE                        cgId;//BYTE                        userIndex;
    WORD                      usrPort;
    BYTE                        type;
    BYTE                        state;

    union
    {
        WORD                  rvInvUaPort;
        WORD                  sdInvUaPort;
    }invUaPort;

    WORD                      sipUaPort;

    WORD                      uaPort;//only used to store the ua port of sending invite rsp
    WORD                      uaAckPort;//only used to store the ua port of sending ACK for invite 200
    DWORD                    invCSeq;
    DWORD                    remoteInvCseq;

    char                         invBranch[SIP_UA_MAX_BRANCH_LEN];

    WORD				paramFlag;
    SIP_HDR_CALL_ID    callId;
    char                         localTag[SIP_UA_MAX_TAG_LEN];
    char                         remoteTag[SIP_UA_MAX_TAG_LEN];
    SIP_HDR_CSEQ        localCseq;
    SIP_HDR_CSEQ        remoteCseq;
    SIP_UA_URI              localURI;
    SIP_UA_URI              remoteURI;
    SIP_UA_URI              remoteTarget;
    SIP_HDR_RECORD_ROUTES   routeSets;
    int                     secure;
}SIP_DIALOG;

int sip_ua_update_dialog_with_req(WORD dialogId, SIP_API_STRUCT *sipApiMsg);

int sip_ua_init_dialog_as_client_with_inv(BYTE cgId, WORD usrPort, SIP_MSG *sipMsg);//BYTE sapIndex
int sip_ua_init_dialog_as_server_with_inv(BYTE cgId, WORD hdlPort, WORD usrPort, SIP_MSG *sipMsg);//BYTE cgId

int sip_ua_free_dialog(DWORD usrPort, WORD dialogId);
#endif
