RTSP code style cleanup - comments

This commit is contained in:
Michelle Bergeron 2016-02-13 12:53:49 -06:00
parent 21ec3f0270
commit baa8106dd8
3 changed files with 142 additions and 144 deletions

View File

@ -18,7 +18,6 @@
#define FLAG_ALLOCATED_OPTION_ITEMS 0x4 #define FLAG_ALLOCATED_OPTION_ITEMS 0x4
#define FLAG_ALLOCATED_PAYLOAD 0x8 #define FLAG_ALLOCATED_PAYLOAD 0x8
/* Linked List to store the options */
typedef struct _OPTION_ITEM { typedef struct _OPTION_ITEM {
char flags; char flags;
char* option; char* option;
@ -26,10 +25,9 @@ typedef struct _OPTION_ITEM {
struct _OPTION_ITEM *next; struct _OPTION_ITEM *next;
} OPTION_ITEM, *POPTION_ITEM; } OPTION_ITEM, *POPTION_ITEM;
/* RTSP Message * // In this implementation, a flag indicates the message type:
* In this implementation, a flag indicates the message type: // TYPE_REQUEST = 0
* TYPE_REQUEST = 0 // TYPE_RESPONSE = 1
* TYPE_RESPONSE = 1 */
typedef struct _RTSP_MESSAGE { typedef struct _RTSP_MESSAGE {
char type; char type;
char flags; char flags;
@ -43,12 +41,12 @@ typedef struct _RTSP_MESSAGE {
union { union {
struct { struct {
/* Request fields */ // Request fields
char* command; char* command;
char* target; char* target;
} request; } request;
struct { struct {
/* Response fields */ // Response fields
char* statusString; char* statusString;
int statusCode; int statusCode;
} response; } response;

View File

@ -11,7 +11,7 @@ static int hasSessionId;
static char responseBuffer[RTSP_MAX_RESP_SIZE]; static char responseBuffer[RTSP_MAX_RESP_SIZE];
static int rtspClientVersion; static int rtspClientVersion;
/* Create RTSP Option */ // Create RTSP Option
static POPTION_ITEM createOptionItem(char* option, char* content) static POPTION_ITEM createOptionItem(char* option, char* content)
{ {
POPTION_ITEM item = malloc(sizeof(*item)); POPTION_ITEM item = malloc(sizeof(*item));
@ -42,7 +42,7 @@ static POPTION_ITEM createOptionItem(char* option, char* content)
return item; return item;
} }
/* Add an option to the RTSP Message */ // Add an option to the RTSP Message
static int addOption(PRTSP_MESSAGE msg, char* option, char* content) static int addOption(PRTSP_MESSAGE msg, char* option, char* content)
{ {
POPTION_ITEM item = createOptionItem(option, content); POPTION_ITEM item = createOptionItem(option, content);
@ -56,7 +56,7 @@ static int addOption(PRTSP_MESSAGE msg, char* option, char* content)
return 1; return 1;
} }
/* Create an RTSP Request */ // Create an RTSP Request
static int initializeRtspRequest(PRTSP_MESSAGE msg, char* command, char* target) static int initializeRtspRequest(PRTSP_MESSAGE msg, char* command, char* target)
{ {
char sequenceNumberStr[16]; char sequenceNumberStr[16];
@ -77,7 +77,7 @@ static int initializeRtspRequest(PRTSP_MESSAGE msg, char* command, char* target)
return 1; return 1;
} }
/* Send RTSP message and get response */ // Send RTSP message and get response
static int transactRtspMessage(PRTSP_MESSAGE request, PRTSP_MESSAGE response, int* error) { static int transactRtspMessage(PRTSP_MESSAGE request, PRTSP_MESSAGE response, int* error) {
SOCK_RET err; SOCK_RET err;
int ret = 0; int ret = 0;
@ -144,7 +144,7 @@ Exit:
return ret; return ret;
} }
/* Terminate the RTSP Handshake process by closing the socket */ // Terminate the RTSP Handshake process by closing the socket
void terminateRtspHandshake(void) { void terminateRtspHandshake(void) {
if (sock != INVALID_SOCKET) { if (sock != INVALID_SOCKET) {
closesocket(sock); closesocket(sock);
@ -152,7 +152,7 @@ void terminateRtspHandshake(void) {
} }
} }
/* Send RTSP OPTIONS request */ // Send RTSP OPTIONS request
static int requestOptions(PRTSP_MESSAGE response, int* error) { static int requestOptions(PRTSP_MESSAGE response, int* error) {
RTSP_MESSAGE request; RTSP_MESSAGE request;
int ret; int ret;
@ -168,7 +168,7 @@ static int requestOptions(PRTSP_MESSAGE response, int* error) {
return ret; return ret;
} }
/* Send RTSP DESCRIBE request */ // Send RTSP DESCRIBE request
static int requestDescribe(PRTSP_MESSAGE response, int* error) { static int requestDescribe(PRTSP_MESSAGE response, int* error) {
RTSP_MESSAGE request; RTSP_MESSAGE request;
int ret; int ret;
@ -192,7 +192,7 @@ static int requestDescribe(PRTSP_MESSAGE response, int* error) {
return ret; return ret;
} }
/* Send RTSP SETUP request */ // Send RTSP SETUP request
static int setupStream(PRTSP_MESSAGE response, char* target, int* error) { static int setupStream(PRTSP_MESSAGE response, char* target, int* error) {
RTSP_MESSAGE request; RTSP_MESSAGE request;
int ret; int ret;
@ -224,7 +224,7 @@ static int setupStream(PRTSP_MESSAGE response, char* target, int* error) {
return ret; return ret;
} }
/* Send RTSP PLAY request*/ // Send RTSP PLAY request
static int playStream(PRTSP_MESSAGE response, char* target, int* error) { static int playStream(PRTSP_MESSAGE response, char* target, int* error) {
RTSP_MESSAGE request; RTSP_MESSAGE request;
int ret; int ret;
@ -245,7 +245,7 @@ static int playStream(PRTSP_MESSAGE response, char* target, int* error) {
return ret; return ret;
} }
/* Send RTSP ANNOUNCE message */ // Send RTSP ANNOUNCE message
static int sendVideoAnnounce(PRTSP_MESSAGE response, int* error) { static int sendVideoAnnounce(PRTSP_MESSAGE response, int* error) {
RTSP_MESSAGE request; RTSP_MESSAGE request;
int ret; int ret;
@ -284,7 +284,7 @@ static int sendVideoAnnounce(PRTSP_MESSAGE response, int* error) {
return ret; return ret;
} }
/* Perform RTSP Handshake with the streaming server machine as part of the connection process */ // Perform RTSP Handshake with the streaming server machine as part of the connection process
int performRtspHandshake(void) { int performRtspHandshake(void) {
char urlAddr[URLSAFESTRING_LEN]; char urlAddr[URLSAFESTRING_LEN];

View File

@ -1,7 +1,8 @@
#include "Rtsp.h" #include "Rtsp.h"
/* Check if String s begins with the given prefix */ // Check if String s begins with the given prefix
static int startsWith(const char* s, const char* prefix) { static int startsWith(const char* s, const char* prefix) {
if (strncmp(s, prefix, strlen(prefix)) == 0) { if (strncmp(s, prefix, strlen(prefix)) == 0) {
return 1; return 1;
} }
@ -10,50 +11,52 @@ static int startsWith(const char *s, const char *prefix) {
} }
} }
/* Gets the length of the message */ // Gets the length of the message
static int getMessageLength(PRTSP_MESSAGE msg) { static int getMessageLength(PRTSP_MESSAGE msg) {
POPTION_ITEM current; POPTION_ITEM current;
/* Initialize to 1 for null terminator */ // Initialize to 1 for null terminator
size_t count = 1; size_t count = 1;
/* Add the length of the protocol */
// Add the length of the protocol
count += strlen(msg->protocol); count += strlen(msg->protocol);
/* Add length of request-specific strings */ // Add length of request-specific strings
if (msg->type == TYPE_REQUEST) { if (msg->type == TYPE_REQUEST) {
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*/
// Add 4 for the two spaces and \r\n
count += 4; count += 4;
} }
/* Add length of response-specific strings */ // Add length of response-specific strings
else { else {
char statusCodeStr[16]; char statusCodeStr[16];
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 */ // Add 4 for two spaces and \r\n
count += 4; count += 4;
} }
/* Count the size of the options */ // Count the size of the options
current = msg->options; current = msg->options;
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 */ // Add 4 because of :[space] and \r\n
count += 4; count += 4;
current = current->next; current = current->next;
} }
/* Add 2 more for extra /r/n ending */ // Add 2 more for extra /r/n ending
count += 2; count += 2;
/* Add the length of the payload, if any */
count += msg->payloadLength; count += msg->payloadLength;
return (int)count; return (int)count;
} }
/* Given an RTSP message string rtspMessage, parse it into an RTSP_MESSAGE struct msg */ // Given an RTSP message string rtspMessage, parse it into an RTSP_MESSAGE struct 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;
@ -61,13 +64,13 @@ int parseRtspMessage(PRTSP_MESSAGE msg, char *rtspMessage, int length) {
POPTION_ITEM options = NULL; POPTION_ITEM options = NULL;
POPTION_ITEM newOpt; POPTION_ITEM newOpt;
/* Delimeter sets for strtok() */ // Delimeter sets for strtok()
char* delim = " \r\n"; char* delim = " \r\n";
char* end = "\r\n"; char* end = "\r\n";
char* optDelim = " :\r\n"; char* optDelim = " :\r\n";
char typeFlag = TOKEN_OPTION; char typeFlag = TOKEN_OPTION;
/* Put the raw message into a string we can use */ // Put the raw message into a string we can use
char* messageBuffer = malloc(length + 1); char* messageBuffer = malloc(length + 1);
if (messageBuffer == NULL) { if (messageBuffer == NULL) {
exitCode = RTSP_ERROR_NO_MEMORY; exitCode = RTSP_ERROR_NO_MEMORY;
@ -78,20 +81,20 @@ int parseRtspMessage(PRTSP_MESSAGE msg, char *rtspMessage, int length) {
// The payload logic depends on a null-terminator at the end // The payload logic depends on a null-terminator at the end
messageBuffer[length] = 0; messageBuffer[length] = 0;
/* Get the first token of the message*/ // Get the first token of the message
token = strtok(messageBuffer, delim); token = strtok(messageBuffer, delim);
if (token == NULL) { if (token == NULL) {
exitCode = RTSP_ERROR_MALFORMED; exitCode = RTSP_ERROR_MALFORMED;
goto ExitFailure; goto ExitFailure;
} }
/* The message is a response */ // The message is a response
if (startsWith(token, "RTSP")) { if (startsWith(token, "RTSP")) {
flag = TYPE_RESPONSE; flag = TYPE_RESPONSE;
/* The current token is the protocol */ // The current token is the protocol
protocol = token; protocol = token;
/* Get the status code */ // Get the status code
token = strtok(NULL, delim); token = strtok(NULL, delim);
statusCode = atoi(token); statusCode = atoi(token);
if (token == NULL) { if (token == NULL) {
@ -99,54 +102,51 @@ int parseRtspMessage(PRTSP_MESSAGE msg, char *rtspMessage, int length) {
goto ExitFailure; goto ExitFailure;
} }
/* Get the status string */ // Get the status string
statusStr = strtok(NULL, end); statusStr = strtok(NULL, end);
if (statusStr == NULL) { if (statusStr == NULL) {
exitCode = RTSP_ERROR_MALFORMED; exitCode = RTSP_ERROR_MALFORMED;
goto ExitFailure; goto ExitFailure;
} }
/* Request fields - we don't care about them here */ // Request fields - we don't care about them here
target = NULL; target = NULL;
command = NULL; command = NULL;
} }
/* The message is a request */
// The message is a request
else { else {
flag = TYPE_REQUEST; flag = TYPE_REQUEST;
/* The current token is the command */
command = token; command = token;
/* Get the target */
target = strtok(NULL, delim); target = strtok(NULL, delim);
if (target == NULL) { if (target == NULL) {
exitCode = RTSP_ERROR_MALFORMED; exitCode = RTSP_ERROR_MALFORMED;
goto ExitFailure; goto ExitFailure;
} }
/* Get the protocol */
protocol = strtok(NULL, delim); protocol = strtok(NULL, delim);
if (protocol == NULL) { if (protocol == NULL) {
exitCode = RTSP_ERROR_MALFORMED; exitCode = RTSP_ERROR_MALFORMED;
goto ExitFailure; goto ExitFailure;
} }
/* Response field - we don't care about it here */ // Response field - we don't care about it here
statusStr = NULL; statusStr = NULL;
} }
/* Check that the protocol is valid */
if (strcmp(protocol, "RTSP/1.0")) { if (strcmp(protocol, "RTSP/1.0")) {
exitCode = RTSP_ERROR_MALFORMED; exitCode = RTSP_ERROR_MALFORMED;
goto ExitFailure; goto ExitFailure;
} }
/* Parse remaining options */ // Parse remaining options
while (token != NULL){ while (token != NULL)
{
token = strtok(NULL, typeFlag == TOKEN_OPTION ? optDelim : end); token = strtok(NULL, typeFlag == TOKEN_OPTION ? optDelim : end);
if (token != NULL) { if (token != NULL) {
/* The token is an option */
if (typeFlag == TOKEN_OPTION) { if (typeFlag == TOKEN_OPTION) {
opt = token; opt = token;
} }
/* The token is content */ // The token is content
else { else {
/* Create a new node containing the option and content */ // Create a new node containing the option and content
newOpt = (POPTION_ITEM)malloc(sizeof(OPTION_ITEM)); newOpt = (POPTION_ITEM)malloc(sizeof(OPTION_ITEM));
if (newOpt == NULL) { if (newOpt == NULL) {
freeOptionList(options); freeOptionList(options);
@ -159,17 +159,17 @@ int parseRtspMessage(PRTSP_MESSAGE msg, char *rtspMessage, int length) {
newOpt->next = NULL; newOpt->next = NULL;
insertOption(&options, newOpt); insertOption(&options, newOpt);
/* Check if we're at the end of the message portion marked by \r\n\r\n // Check if we're at the end of the message portion marked by \r\n\r\n
* endCheck points to the remainder of messageBuffer after the token */ //endCheck points to the remainder of messageBuffer after the token
endCheck = &token[0] + strlen(token) + 1; endCheck = &token[0] + strlen(token) + 1;
/* See if we've hit the end of the message. The first \r is missing because it's been tokenized */ // See if we've hit the end of the message. The first \r is missing because it's been tokenized
if (startsWith(endCheck, "\n\r\n")) { if (startsWith(endCheck, "\n\r\n")) {
/* We've encountered the end of the message - mark it thus */ // We've encountered the end of the message - mark it thus
messageEnded = 1; messageEnded = 1;
/* The payload is the remainder of messageBuffer. If none, then payload = null */ // The payload is the remainder of messageBuffer. If none, then payload = null
if (endCheck[3] != '\0') if (endCheck[3] != '\0')
payload = &endCheck[3]; payload = &endCheck[3];
@ -179,13 +179,13 @@ int parseRtspMessage(PRTSP_MESSAGE msg, char *rtspMessage, int length) {
} }
typeFlag ^= 1; // flip the flag typeFlag ^= 1; // flip the flag
} }
/* If we never encountered the double CRLF, then the message is malformed! */ // If we never encountered the double CRLF, then the message is malformed!
if (!messageEnded) { if (!messageEnded) {
exitCode = RTSP_ERROR_MALFORMED; exitCode = RTSP_ERROR_MALFORMED;
goto ExitFailure; goto ExitFailure;
} }
/* Get sequence number as an integer */ // Get sequence number as an integer
sequence = getOptionContent(options, "CSeq"); sequence = getOptionContent(options, "CSeq");
if (sequence != NULL) { if (sequence != NULL) {
sequenceNum = atoi(sequence); sequenceNum = atoi(sequence);
@ -193,7 +193,7 @@ int parseRtspMessage(PRTSP_MESSAGE msg, char *rtspMessage, int length) {
else { else {
sequenceNum = SEQ_INVALID; sequenceNum = SEQ_INVALID;
} }
/* Package the new parsed message into the struct */ // Package the new parsed message into the struct
if (flag == TYPE_REQUEST) { if (flag == TYPE_REQUEST) {
createRtspRequest(msg, messageBuffer, FLAG_ALLOCATED_MESSAGE_BUFFER | FLAG_ALLOCATED_OPTION_ITEMS, command, target, createRtspRequest(msg, messageBuffer, FLAG_ALLOCATED_MESSAGE_BUFFER | FLAG_ALLOCATED_OPTION_ITEMS, command, target,
protocol, sequenceNum, options, payload, payload ? length - (int)(messageBuffer - payload) : 0); protocol, sequenceNum, options, payload, payload ? length - (int)(messageBuffer - payload) : 0);
@ -204,7 +204,6 @@ int parseRtspMessage(PRTSP_MESSAGE msg, char *rtspMessage, int length) {
} }
return RTSP_ERROR_SUCCESS; return RTSP_ERROR_SUCCESS;
/* Cleanup in failure condition */
ExitFailure: ExitFailure:
if (options) { if (options) {
free(options); free(options);
@ -215,7 +214,7 @@ ExitFailure:
return exitCode; return exitCode;
} }
/* Create new RTSP message struct with response data */ // Create new RTSP message struct with response data
void createRtspResponse(PRTSP_MESSAGE msg, char* message, int flags, char* protocol, void createRtspResponse(PRTSP_MESSAGE msg, char* message, int flags, char* protocol,
int statusCode, char* statusString, int sequenceNumber, POPTION_ITEM optionsHead, char* payload, int payloadLength) { int statusCode, char* statusString, int sequenceNumber, POPTION_ITEM optionsHead, char* payload, int payloadLength) {
msg->type = TYPE_RESPONSE; msg->type = TYPE_RESPONSE;
@ -230,7 +229,7 @@ void createRtspResponse(PRTSP_MESSAGE msg, char *message, int flags, char *proto
msg->message.response.statusCode = statusCode; msg->message.response.statusCode = statusCode;
} }
/* Create new RTSP message struct with request data */ // Create new RTSP message struct with request data
void createRtspRequest(PRTSP_MESSAGE msg, char* message, int flags, void createRtspRequest(PRTSP_MESSAGE msg, char* message, int flags,
char* command, char* target, char* protocol, int sequenceNumber, POPTION_ITEM optionsHead, char* payload, int payloadLength) { char* command, char* target, char* protocol, int sequenceNumber, POPTION_ITEM optionsHead, char* payload, int payloadLength) {
msg->type = TYPE_REQUEST; msg->type = TYPE_REQUEST;
@ -245,33 +244,34 @@ void createRtspRequest(PRTSP_MESSAGE msg, char *message, int flags,
msg->message.request.target = target; msg->message.request.target = target;
} }
/* 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; OPTION_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)) {
return current->content; return current->content;
} }
current = current->next; current = current->next;
} }
/* Not found */ // Not found
return NULL; return NULL;
} }
/* 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; OPTION_ITEM *current = *optionsHead;
opt->next = NULL; opt->next = NULL;
/* Empty options list */ // Empty options list
if (*optionsHead == NULL) { if (*optionsHead == NULL) {
*optionsHead = opt; *optionsHead = opt;
return; return;
} }
/* Traverse the list and insert the new option at the end */
// Traverse the list and insert the new option at the end
while (current != NULL) { while (current != NULL) {
/* Check for duplicate option; if so, replace the option currently there */ // Check for duplicate option; if so, replace the option currently there
if (!strcmp(current->option, opt->option)) { if (!strcmp(current->option, opt->option)) {
current->content = opt->content; current->content = opt->content;
return; return;
@ -284,7 +284,7 @@ void insertOption(POPTION_ITEM *optionsHead, POPTION_ITEM opt){
} }
} }
/* Free every node in the message's option list */ // Free every node in the message's option list
void freeOptionList(POPTION_ITEM optionsHead) { void freeOptionList(POPTION_ITEM optionsHead) {
POPTION_ITEM current = optionsHead; POPTION_ITEM current = optionsHead;
POPTION_ITEM temp; POPTION_ITEM temp;
@ -299,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;
@ -312,29 +312,29 @@ char *serializeRtspMessage(PRTSP_MESSAGE msg, int *serializedLength){
} }
if (msg->type == TYPE_REQUEST) { if (msg->type == TYPE_REQUEST) {
/* command [space] */ // command [space]
strcpy(serializedMessage, msg->message.request.command); strcpy(serializedMessage, msg->message.request.command);
strcat(serializedMessage, " "); strcat(serializedMessage, " ");
/* target [space] */ // target [space]
strcat(serializedMessage, msg->message.request.target); strcat(serializedMessage, msg->message.request.target);
strcat(serializedMessage, " "); strcat(serializedMessage, " ");
/* protocol \r\n */ // protocol \r\n
strcat(serializedMessage, msg->protocol); strcat(serializedMessage, msg->protocol);
strcat(serializedMessage, "\r\n"); strcat(serializedMessage, "\r\n");
} }
else { else {
/* protocol [space] */ // protocol [space]
strcpy(serializedMessage, msg->protocol); strcpy(serializedMessage, msg->protocol);
strcat(serializedMessage, " "); strcat(serializedMessage, " ");
/* status code [space] */ // status code [space]
sprintf(statusCodeStr, "%d", msg->message.response.statusCode); sprintf(statusCodeStr, "%d", msg->message.response.statusCode);
strcat(serializedMessage, statusCodeStr); strcat(serializedMessage, statusCodeStr);
strcat(serializedMessage, " "); strcat(serializedMessage, " ");
/* status str\r\n */ // status str\r\n
strcat(serializedMessage, msg->message.response.statusString); strcat(serializedMessage, msg->message.response.statusString);
strcat(serializedMessage, "\r\n"); strcat(serializedMessage, "\r\n");
} }
/* option content\r\n */ // option content\r\n
while (current != NULL) { while (current != NULL) {
strcat(serializedMessage, current->option); strcat(serializedMessage, current->option);
strcat(serializedMessage, ": "); strcat(serializedMessage, ": ");
@ -342,10 +342,10 @@ char *serializeRtspMessage(PRTSP_MESSAGE msg, int *serializedLength){
strcat(serializedMessage, "\r\n"); strcat(serializedMessage, "\r\n");
current = current->next; current = current->next;
} }
/* Final \r\n */ // Final \r\n
strcat(serializedMessage, "\r\n"); strcat(serializedMessage, "\r\n");
/* payload */ // payload
if (msg->payload != NULL) { if (msg->payload != NULL) {
int offset; int offset;
@ -364,19 +364,19 @@ char *serializeRtspMessage(PRTSP_MESSAGE msg, int *serializedLength){
return serializedMessage; return serializedMessage;
} }
/* Free everything in a msg struct */ // Free everything in a msg struct
void freeMessage(PRTSP_MESSAGE msg) { void freeMessage(PRTSP_MESSAGE msg) {
/* If we've allocated the message buffer */ // If we've allocated the message buffer
if (msg->flags & FLAG_ALLOCATED_MESSAGE_BUFFER) { if (msg->flags & FLAG_ALLOCATED_MESSAGE_BUFFER) {
free(msg->messageBuffer); free(msg->messageBuffer);
} }
/* If we've allocated any option items */ // If we've allocated any option items
if (msg->flags & FLAG_ALLOCATED_OPTION_ITEMS) { if (msg->flags & FLAG_ALLOCATED_OPTION_ITEMS) {
freeOptionList(msg->options); freeOptionList(msg->options);
} }
/* If we've allocated the payload */ // If we've allocated the payload
if (msg->flags & FLAG_ALLOCATED_PAYLOAD) { if (msg->flags & FLAG_ALLOCATED_PAYLOAD) {
free(msg->payload); free(msg->payload);
} }