' Server-Sent Events constants and optional parser/builder declarations.
#IF NOT %DEF(PBX_SSE_PBI)
#DEFINE PBX_SSE_PBI
#INCLUDE ONCE "Legacy/Network/rest_http.inc"

%EQUATE `SSE_MIME_TYPE = "text/event-stream"
%EQUATE `SSE_FIELD_EVENT = "event"
%EQUATE `SSE_FIELD_DATA = "data"
%EQUATE `SSE_FIELD_ID = "id"
%EQUATE `SSE_FIELD_RETRY = "retry"
%EQUATE `SSE_EVENT_MESSAGE = "message"
%EQUATE `SSE_EVENT_ENDPOINT = "endpoint"
%EQUATE `SSE_EVENT_PING = "ping"
%EQUATE `SSE_EVENT_ERROR = "error"
%EQUATE `SSE_LINE_ENDING = "\r\n"
%EQUATE `SSE_DEFAULT_RETRY_MS = 3000
%EQUATE `SSE_FLAG_ALLOW_COMMENTS = &H00000001
%EQUATE `SSE_FLAG_MERGE_MULTILINE_DATA = &H00000002

TYPE SSE_EVENT_INFO
    eventPtr AS QUAD
    eventLen AS QUAD
    dataPtr AS QUAD
    dataLen AS QUAD
    idPtr AS QUAD
    idLen AS QUAD
    retryMs AS DWORD
END TYPE

DECLARE FUNCTION PBXSse_ParseEvent LIB "pbxapi64.dll" ALIAS "PBXSse_ParseEvent" (BYVAL pText AS QUAD, BYVAL cbText AS QUAD, BYVAL flags AS DWORD, BYVAL pInfo AS QUAD) AS LONG
DECLARE FUNCTION PBXSse_BuildEvent LIB "pbxapi64.dll" ALIAS "PBXSse_BuildEvent" (BYVAL pEvent AS QUAD, BYVAL cbEvent AS QUAD, BYVAL pData AS QUAD, BYVAL cbData AS QUAD, BYVAL ppOut AS QUAD, BYVAL pcbOut AS QUAD) AS LONG
DECLARE FUNCTION PBXSse_FreeBuffer LIB "pbxapi64.dll" ALIAS "PBXSse_FreeBuffer" (BYVAL pBuffer AS QUAD) AS LONG

#ENDIF
