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

CONST SSE_MIME_TYPE = "text/event-stream"
CONST SSE_FIELD_EVENT = "event"
CONST SSE_FIELD_DATA = "data"
CONST SSE_FIELD_ID = "id"
CONST SSE_FIELD_RETRY = "retry"
CONST SSE_EVENT_MESSAGE = "message"
CONST SSE_EVENT_ENDPOINT = "endpoint"
CONST SSE_EVENT_PING = "ping"
CONST SSE_EVENT_ERROR = "error"
CONST SSE_LINE_ENDING = "\r\n"
CONST SSE_DEFAULT_RETRY_MS = 3000
CONST SSE_FLAG_ALLOW_COMMENTS = &H00000001
CONST 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
