直接上代码:源码
void doRtspParse(char *b) {
std::vector<std::string> res;
char *ptr = b, *ptr1 = nullptr;
while ((ptr1 = strstr(ptr, "\r\n"))) {
res.push_back(std::string(ptr, ptr1 - ptr));
ptr = ptr1 + 2;
}
int len = ptr - b;
b[len - 1] = '\0';
Debug("%d read --> \n%s", len, b);
switch (cmd_) {
case OPTIONS: {
auto it = std::find_if(res.begin(), res.end(), [&](std::string &s) {
return s.find("WWW-Authenticate") != std::string::npos;
});
if (it == res.end()) {
doWriteCmd(DESCRIBE, seq_++, url_.GetAuth("DESCRIBE").c_str());
} else {
url_.SetAuth(it->c_str());
doWriteCmd(OPTIONS, seq_++, url_.GetAuth("OPTIONS").c_str());
}