/*---------------------------------------------------------------------------*/
/* ice_stun.h                                                                */
/* copyright (c) innovaphone 2013                                            */
/*                                                                           */
/*---------------------------------------------------------------------------*/

#define BINDING_REQUEST             0x0001
#define BINDING_RESPONSE            0x0101
#define BINDING_ERROR_RESPONSE      0x0111
#define STUN_ERROR_BAD_REQUEST      0x400
#define STUN_ERROR_UNAUTHORIZED     0x401
#define STUN_ERROR_ROLE_CONFLICT    0x457

class IceStun {
public:
    static bool isStun(char * buf, int len);
    static void createId(OS_GUID * id);
    static char * writeRequest(OS_GUID * id, int & len);
    static char * writeRequest(OS_GUID * id, const char * lfrag, const char * rfrag, const char * password, dword priority, bool controlling, ulong64 tiebreaker, bool nominated, int & len, bool draft2 = false, const char * microsoftCandidateId = 0, dword microsoftImplementationVersion = 0);
    static char * writeResponse(OS_GUID * id, const char * password, IPaddr addr, word port, int & len, bool draft2 = false, dword microsoftImplementationVersion = 0, const char * lfrag = 0, const char * rfrag = 0);
    static char * writeResponse(OS_GUID * id, word error_code, const char * password, int & len, bool draft2 = false);
    static int readRequest(char * data, int len, const char * lfrag, const char * rfrag, const char * password, OS_GUID * id, dword * priority, bool * controlling, ulong64 * tiebreaker, bool * nominated, bool allowDraft2 = true, char ** microsoftCandidateId = 0, dword * microsoftImplementationVersion = 0);
    static bool readResponse(char * data, int len, const char * password, OS_GUID * id, IPaddr * addr, word * port, bool allowDraft2 = true, dword * microsoftImplementationVersion = 0);
    static bool readResponse(char * data, int len, OS_GUID * id, const char * password, word * errorCode, bool allowDraft2 = true);
    static const char * getErrorPhrase(word code);
    static const char * getMessageType(char * data);
};

