#define magic RTSP length values

This commit is contained in:
Michelle Bergeron 2016-02-13 13:21:00 -06:00
parent c8bad4ed2f
commit b7ca62190c
2 changed files with 20 additions and 15 deletions

View File

@ -18,11 +18,14 @@
#define FLAG_ALLOCATED_OPTION_ITEMS 0x4 #define FLAG_ALLOCATED_OPTION_ITEMS 0x4
#define FLAG_ALLOCATED_PAYLOAD 0x8 #define FLAG_ALLOCATED_PAYLOAD 0x8
#define CRLF_LENGTH 2
#define MESSAGE_END_LENGTH (2 + CRLF_LENGTH)
typedef struct _OPTION_ITEM { typedef struct _OPTION_ITEM {
char flags; char flags;
char* option; char* option;
char* content; char* content;
struct _OPTION_ITEM *next; struct _OPTION_ITEM* next;
} OPTION_ITEM, *POPTION_ITEM; } OPTION_ITEM, *POPTION_ITEM;
// In this implementation, a flag indicates the message type: // In this implementation, a flag indicates the message type:
@ -60,4 +63,4 @@ void createRtspRequest(PRTSP_MESSAGE msg, char* messageBuffer, int flags, char*
char* getOptionContent(POPTION_ITEM optionsHead, char* option); char* getOptionContent(POPTION_ITEM optionsHead, char* option);
void insertOption(POPTION_ITEM* optionsHead, POPTION_ITEM opt); void insertOption(POPTION_ITEM* optionsHead, POPTION_ITEM opt);
void freeOptionList(POPTION_ITEM optionsHead); void freeOptionList(POPTION_ITEM optionsHead);
char* serializeRtspMessage(PRTSP_MESSAGE msg, int *serializedLength); char* serializeRtspMessage(PRTSP_MESSAGE msg, int* serializedLength);

View File

@ -25,8 +25,8 @@ static int getMessageLength(PRTSP_MESSAGE msg) {
count += strlen(msg->message.request.command); count += strlen(msg->message.request.command);
count += strlen(msg->message.request.target); count += strlen(msg->message.request.target);
// Add 4 for the two spaces and \r\n // two spaces and \r\n
count += 4; count += MESSAGE_END_LENGTH;
} }
// Add length of response-specific strings // Add length of response-specific strings
else { else {
@ -34,8 +34,8 @@ static int getMessageLength(PRTSP_MESSAGE msg) {
sprintf(statusCodeStr, "%d", msg->message.response.statusCode); sprintf(statusCodeStr, "%d", msg->message.response.statusCode);
count += strlen(statusCodeStr); count += strlen(statusCodeStr);
count += strlen(msg->message.response.statusString); count += strlen(msg->message.response.statusString);
// Add 4 for two spaces and \r\n // two spaces and \r\n
count += 4; count += MESSAGE_END_LENGTH;
} }
// Count the size of the options // Count the size of the options
current = msg->options; current = msg->options;
@ -43,12 +43,12 @@ static int getMessageLength(PRTSP_MESSAGE msg) {
while (current != NULL) { while (current != NULL) {
count += strlen(current->option); count += strlen(current->option);
count += strlen(current->content); count += strlen(current->content);
// Add 4 because of :[space] and \r\n // :[space] and \r\n
count += 4; count += MESSAGE_END_LENGTH;
current = current->next; current = current->next;
} }
// Add 2 more for extra /r/n ending // /r/n ending
count += 2; count += CRLF_LENGTH;
count += msg->payloadLength; count += msg->payloadLength;
@ -59,7 +59,9 @@ static int getMessageLength(PRTSP_MESSAGE msg) {
int parseRtspMessage(PRTSP_MESSAGE msg, char* rtspMessage, int length) { int parseRtspMessage(PRTSP_MESSAGE msg, char* rtspMessage, int length) {
char* token, *protocol, *endCheck, *target, *statusStr, *command, *sequence, flag; char* token, *protocol, *endCheck, *target, *statusStr, *command, *sequence, flag;
char messageEnded = 0, *payload = NULL, *opt = NULL; char messageEnded = 0, *payload = NULL, *opt = NULL;
int statusCode = 0, sequenceNum, exitCode; int statusCode = 0;
int sequenceNum;
int exitCode;
POPTION_ITEM options = NULL; POPTION_ITEM options = NULL;
POPTION_ITEM newOpt; POPTION_ITEM newOpt;
@ -243,7 +245,7 @@ void createRtspRequest(PRTSP_MESSAGE msg, char* message, int flags,
// Retrieves option content from the linked list given the option title // Retrieves option content from the linked list given the option title
char* getOptionContent(POPTION_ITEM optionsHead, char* option) { char* getOptionContent(POPTION_ITEM optionsHead, char* option) {
OPTION_ITEM *current = optionsHead; POPTION_ITEM current = optionsHead;
while (current != NULL) { while (current != NULL) {
// Check if current node is what we're looking for // Check if current node is what we're looking for
if (!strcmp(current->option, option)) { if (!strcmp(current->option, option)) {
@ -256,8 +258,8 @@ char* getOptionContent(POPTION_ITEM optionsHead, char* option) {
} }
// Adds new option opt to the struct's option list // Adds new option opt to the struct's option list
void insertOption(POPTION_ITEM *optionsHead, POPTION_ITEM opt) { void insertOption(POPTION_ITEM* optionsHead, POPTION_ITEM opt) {
OPTION_ITEM *current = *optionsHead; POPTION_ITEM current = *optionsHead;
opt->next = NULL; opt->next = NULL;
// Empty options list // Empty options list
@ -297,7 +299,7 @@ void freeOptionList(POPTION_ITEM optionsHead) {
} }
// Serialize the message struct into a string containing the RTSP message // Serialize the message struct into a string containing the RTSP message
char* serializeRtspMessage(PRTSP_MESSAGE msg, int *serializedLength) { char* serializeRtspMessage(PRTSP_MESSAGE msg, int* serializedLength) {
int size = getMessageLength(msg); int size = getMessageLength(msg);
char* serializedMessage; char* serializedMessage;
POPTION_ITEM current = msg->options; POPTION_ITEM current = msg->options;