#include <iostream>
#include <regex>
#include <string>
#include <iostream>
#include <sstream>
#include <iomanip>
#include <chrono>
#include <map>
using namespace std;
void ParseAuthenticateInfo(string test,map<string, string>& keyValues)
{
const std::string strValueReg = "\"(.*)\"";
smatch result;
int nPos = test.find("Authenticate:");
if (nPos != string::npos) {
string subStr = test.substr(nPos + string("Authenticate:").length(), test.length() - nPos);
stringstream subStrSplit(subStr);
string temp;
vector<string>v;
while (getline(subStrSplit, temp, ',')) {
v.push_back(temp);
}
for (auto& it : v) {
nPos = it.find("=");
if (nPos != string::npos) {
string strLeft = it.substr(0, nPos);
string strRight = it.substr(nPos + 1, it.length() - nPos);
regex reg_Realm(strValueReg);
if (regex_search(strRight, result, reg_Realm)) {
keyValues[strLeft] = result[1].str();
}
}
}
}
}
int main()
{
string test = "WWW-Authenticate: Digest realm=\"IP Camera(C7120)\", nonce=\"d4af7cb16c273d93c77ccbbcc27165dc\", stale=\"FALSE\"\r\n";
map<string, string> keyValues;
ParseAuthenticateInfo(test, keyValues);
#if 0
smatch result;
const std::string strRealm = "Digest realm = \"(.*)\,";
regex reg_Realm(strRealm);
if (regex_search(test, result, reg_Realm))
{
for (int i = 1; i < result.size(); i++)
{
}
}
string a = "rtsp://(.*):(.*)@(\\d{1,3}).(\\d{1,3}).(\\d{1,3}).(\\d{1,3}):(\\d+)";
string sName = "rtsp://admin:admin123@172.21.35.99:554/Streaming/Channels/102";
regex reg_containport("(\\d{1,3}).(\\d{1,3}).(\\d{1,3}).(\\d{1,3}):(\\d+)");
if (regex_search(sName, result, reg_containport))
{
for (int i = 1; i < result.size(); i++)
{
}
string a = result.prefix().str() + "aaaaaaaaaa" + result.suffix().str();
}
else
{
regex reg0("(\\d{1,3}).(\\d{1,3}).(\\d{1,3}).(\\d{1,3})");
if (regex_search(sName, result, reg0))
{
for (int i = 1; i < result.size(); i++)
{
}
}
}
std::cout << "Hello World!\n";
#endif
}