mirror of
https://github.com/moonlight-stream/moonlight-common-c.git
synced 2026-06-17 22:31:21 +00:00
Add RTSP parser
This commit is contained in:
@@ -0,0 +1,63 @@
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#define TYPE_REQUEST 0
|
||||
#define TYPE_RESPONSE 1
|
||||
|
||||
#define TOKEN_OPTION 0
|
||||
|
||||
#define RTSP_ERROR_SUCCESS 0
|
||||
#define RTSP_ERROR_NO_MEMORY -1
|
||||
#define RTSP_ERROR_MALFORMED -2
|
||||
|
||||
#define SEQ_INVALID -1
|
||||
|
||||
#define FLAG_ALLOCATED_OPTION_FIELDS 0x1
|
||||
#define FLAG_ALLOCATED_MESSAGE_BUFFER 0x2
|
||||
#define FLAG_ALLOCATED_OPTION_ITEMS 0x4
|
||||
|
||||
/* Linked List to store the options */
|
||||
typedef struct _OPTION_ITEM {
|
||||
char flags;
|
||||
char *option;
|
||||
char *content;
|
||||
struct _OPTION_ITEM *next;
|
||||
} OPTION_ITEM, *POPTION_ITEM;
|
||||
|
||||
/* RTSP Message *
|
||||
* In this implementation, a flag indicates the message type:
|
||||
* TYPE_REQUEST = 0
|
||||
* TYPE_RESPONSE = 1 */
|
||||
typedef struct _RTSP_MESSAGE {
|
||||
char type;
|
||||
char flags;
|
||||
int sequenceNumber;
|
||||
char *protocol;
|
||||
POPTION_ITEM options;
|
||||
char *payload;
|
||||
|
||||
char* messageBuffer;
|
||||
|
||||
union {
|
||||
struct {
|
||||
/* Request fields */
|
||||
char *command;
|
||||
char *target;
|
||||
} request;
|
||||
struct {
|
||||
/* Response fields */
|
||||
char *statusString;
|
||||
int statusCode;
|
||||
} response;
|
||||
} message;
|
||||
} RTSP_MESSAGE, *PRTSP_MESSAGE;
|
||||
|
||||
int parseRtspMessage(PRTSP_MESSAGE msg, char *rtspMessage);
|
||||
void freeMessage(PRTSP_MESSAGE msg);
|
||||
void createRtspResponse(PRTSP_MESSAGE msg, char* messageBuffer, int flags, char *protocol, int statusCode, char *statusString, int sequenceNumber, POPTION_ITEM optionsHead, char *payload);
|
||||
void createRtspRequest(PRTSP_MESSAGE msg, char* messageBuffer, int flags, char *command, char *target, char *protocol, int sequenceNumber, POPTION_ITEM optionsHead, char *payload);
|
||||
char *getOptionContent(POPTION_ITEM optionsHead, char *option);
|
||||
void insertOption(POPTION_ITEM *optionsHead, POPTION_ITEM opt);
|
||||
void freeOptionList(POPTION_ITEM optionsHead);
|
||||
char *serializeRtspMessage(PRTSP_MESSAGE msg, int *serializedLength);
|
||||
Reference in New Issue
Block a user