?? gloab.h
字號:
#ifndef _GLOAB_H
#define _GLOAB_H
#include "stdio.h"
#include "Nucleus.h"
#include "string.h"
#include "stdlib.h"
#include "time.h"
#include <assert.h>
#define BUFFER_LEN 100
#define OPTIONS 1000
#define SETUP 1001
#define PLAY 1002
#define TEARDOWN 1003
#define SET_PARAMETER 1004
#define DESCRIBE 1005
extern NU_MEMORY_POOL dm_memory;
extern HANDLE Con_Apl;
CHAR request[100];
CHAR response[100];
typedef struct RtspRequest_struct
{
char *Method;
char *FilePath;
char *Ver;
char *Cseq;
char *SessionId;
} RtspRequest;
INT ParseRequestLine(RtspRequest* rtspreq, INT* len)
{
STATUS isEnd = 0; //RequestLine是否結束
CHAR request_line[BUFFER_LEN]; //臨時存儲Request_line
CHAR buf[BUFFER_LEN];
INT req_line_idx = 0;
INT req_idx = 0;
INT idx;
INT wi;
INT method_Type;
assert(rtspreq != NULL);
if (request[0] <= 'A' || request[0] >= 'Z')
{//方法的第一個字符不是大寫字母,不能解析
return -1;
}
//開始解析RequestLine
while (!isEnd)
{//首先拷貝RequestLine到緩存request_line中
if (request[req_idx] == '\r' && request[req_idx + 1] == '\n')
{//Request Line結束
isEnd = 1;
req_idx += 2;
break;
}
request_line[req_line_idx++] = request[req_idx++];
}
*len = req_idx;
//首先提取Method
idx = 0;
wi = 0;
while (wi < req_line_idx && request_line[wi] != ' ')
{
buf[idx++] = request_line[wi++];
}
buf[idx] = '\0';
NU_Allocate_Memory(&dm_memory, &rtspreq->Method, idx, NU_NO_SUSPEND);
//判斷Method的類型
/*
if (strcmp(buf, "OPTIONS") == 0)
{
*method_type = OPTIONS;
}
else if (strcmp(buf, "SETUP") == 0)
{
*method_type = SETUP;
}
else if (strcmp(buf, "PLAY") == 0)
{
*method_type = PLAY;
}
else if (strcmp(buf, "TEARDOWN") == 0)
{
*method_type = TEARDOWN;
}
else if (strcmp(buf, "SET_PARAMETER") == 0)
{
*method_type = SET_PARAMETER;
}
else if (strcmp(buf, "DESCRIBE") == 0)
{
*method_type = DESCRIBE;
}*/
if (rtspreq->Method != NULL)
{
if (strcmp(buf, "OPTIONS") == 0)
{
strcpy(rtspreq->Method, "OPTIONS");
method_Type = OPTIONS;
}
else if (strcmp(buf, "SETUP") == 0)
{
strcpy(rtspreq->Method, "SETUP");
method_Type = SETUP;
}
else if (strcmp(buf, "PLAY") == 0)
{
strcpy(rtspreq->Method, "PLAY");
method_Type = PLAY;
}
else if (strcmp(buf, "TEARDOWN") == 0)
{
strcpy(rtspreq->Method, "TEARDOWN");
method_Type = TEARDOWN;
}
else if (strcmp(buf, "SET_PARAMETER") == 0)
{
strcpy(rtspreq->Method, "SET_PARAMETER");
method_Type = SET_PARAMETER;
}
else if (strcmp(buf, "DESCRIBE") == 0)
{
strcpy(rtspreq->Method, "DESCRIBE");
method_Type = DESCRIBE;
}
else
{
return -1;
}
}
//提取Path
idx = 0;
wi++;
while (wi < req_line_idx && request_line[wi] != ' ')
{
buf[idx++] = request_line[wi++];
}
buf[idx] = '\0';
NU_Allocate_Memory(&dm_memory, &rtspreq->FilePath, idx, NU_NO_SUSPEND);
if (rtspreq->FilePath != NULL)
{
strcpy(rtspreq->FilePath, buf);
}
//提取版本
idx = 0;
wi++;
while (wi < req_line_idx && request_line[wi] != ' ' && request_line[wi] != '\r')
{
buf[idx++] = request_line[wi++];
}
buf[idx] = '\0';
NU_Allocate_Memory(&dm_memory, &rtspreq->Ver, idx, NU_NO_SUSPEND);
if (rtspreq->FilePath != NULL)
{
strcpy(rtspreq->Ver, buf);
}
return method_Type;
}
INT ParaseRequestHeader(RtspRequest* rtspreq, INT startIdx)
{
INT isEnd = 0;
INT newLine = 0;
INT index = startIdx;
INT bufIdx = 0;
CHAR tmpc;
CHAR buf[BUFFER_LEN];
// DWORD NumWritten;
assert(startIdx > 0 && startIdx < BUFFER_LEN - 1 && rtspreq != NULL);
//開始解析頭,循環一次解析一行
while (!isEnd && index < BUFFER_LEN - 1)
{
//一行的開頭就是回車換行符,結束解析
if (request[index] == '\r' && request[index + 1] == '\n' && newLine == 1)
{
break;
}
newLine = 0;
bufIdx = 0;
//解析Header
while ((tmpc = request[index++]) != ':')
{
buf[bufIdx++] = tmpc;
}
buf[bufIdx] = '\0';
index++;
if (strcmp(buf, "CSeq") == 0)
{//解析頭CSeq
bufIdx = 0;
while (request[index] != '\r' && request[index + 1] != '\n')
{
buf[bufIdx++] = request[index++];
}
buf[bufIdx] = '\0';
NU_Allocate_Memory(&dm_memory, &rtspreq->Cseq, bufIdx, NU_NO_SUSPEND);
//存儲CSeq頭
if (rtspreq->Cseq != NULL)
{
strcpy(rtspreq->Cseq, buf);
}
newLine = 1;
index += 2;
continue;
}
else if (strcmp(buf, "Session") == 0)
{
bufIdx = 0;
while (request[index] != '\r' && request[index + 1] != '\n')
{
buf[bufIdx++] = request[index++];
}
buf[bufIdx] = '\0';
NU_Allocate_Memory(&dm_memory, &rtspreq->SessionId, bufIdx, NU_NO_SUSPEND);
//存儲CSeq頭
if (rtspreq->SessionId != NULL)
{
strcpy(rtspreq->SessionId, buf);
}
newLine = 1;
index += 2;
continue;
}
}
return 1;
}
char Method_Code[6][15]={"OPTIONS","SETUP","PLAY","TEARDOWN","SET_PARAMETER","DESCRIBE"};
/*rtsp消息包結構*/
///*應答狀態代碼,不全*/
//#define RTSP_200_STATUS 200;
//#define RTSP_201_STATUS 201;
#endif
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -