📄 mpitems.cxx
字号:
{ if(mp_Separator == 0 || mp_NVal == 1) { mp_Value[0] = str; mp_Value[0].atrim(); } std::string::size_type start = 0; std::mstring tmp; std::mstring sep; unsigned i = 0; sep += mp_Separator; while((start = toktrim(str, &tmp, start, sep, std::mstring::sep_multiple)) != std::string::npos) { if(mp_Quoted[i]) { tmp.atrims(QuoteSymb); tmp.del_pair(QPairSymb); } mp_Value[i++] = tmp; if(i >= 15) break; } if(chk_syntax_flag) checkSyntax(); } //--------------------------------------------------------------------------------------- MpParseItem & MpValue::operator [] (const char * name) { throw MpAccessError(std::mstring("MpValParm: Illegal nested name: ") + name); } //--------------------------------------------------------------------------------------- std::mstring & MpValue::val(const char * name) { unsigned i; for(i = 0; i < mp_NVal; i++) { if(strcmp(name, mp_Name[i]) == 0) return mp_Value[i]; } throw MpAccessError(std::mstring("MpValue: Illegal Parameter: ") + name); } //--------------------------------------------------------------------------------------- void MpValue::get(unsigned i, std::mstring *name, std::mstring *value) const { if(i < mp_NVal) { if(name) *name = mp_Name[i]; if(value) *value = mp_Value[i]; return; } throw MpAccessError("MpValue: Out of index"); } //======================================================================================= //MpAllow Implementation //--------------------------------------------------------------------------------------- void MpAllow::checkSyntax() const { std::mstring value; get(0, 0, &value); ValAssistant::check(mpiUrlParm, mpnMethod, value); }/* //======================================================================================= //MpCallID Implementation //--------------------------------------------------------------------------------------- std::mstring MpCallID::encode(bool chk_syntax_flag) const { std::mstring ret; if(!empty()) { if(chk_syntax_flag) checkSyntax(); ret = mp_CallID; ret += '@'; ret += mp_HostPort.encode(false); } return ret; } //--------------------------------------------------------------------------------------- void MpCallID::decode(const std::mstring & str, bool chk_syntax_flag) { erase(); std::string::size_type start = 0; std::mstring host; start = toktrim(str, &mp_CallID, 0, "@"); start = toktrim(str, &host, start, "@"); mp_HostPort.decode(host, false); if(chk_syntax_flag) checkSyntax(); } //--------------------------------------------------------------------------------------- void MpCallID::checkSyntax() const { ValAssistant::check(mpiCallID, mpnValue, mp_CallID); mp_HostPort.checkSyntax(); } //--------------------------------------------------------------------------------------- MpParseItem & MpCallID::operator [] (const char * name) { if(strcmp(name, mpiHostPort) == 0) return mp_HostPort; throw MpAccessError(std::mstring("MpCallID: Illegal nested name: ") + name); } //--------------------------------------------------------------------------------------- std::mstring & MpCallID::val(const char * name) { if(strcmp(name, mpnValue) == 0) return mp_CallID; throw MpAccessError("MpCallID: No parameters"); } //--------------------------------------------------------------------------------------- void MpCallID::get(unsigned i, std::mstring *name, std::mstring *value) const { if(i == 0) { if(name) *name = mpnValue; if(value) *value = mp_CallID; return; } throw MpAccessError("MpCallID: No parameters"); } //--------------------------------------------------------------------------------------- MpParseItem & MpCallID::item(unsigned i, std::mstring *name) { if(i == 0) { if(name) *name = mpiHostPort; return mp_HostPort; } throw MpAccessError("MpCallID: Out of item index"); }*/ //======================================================================================= //MpNameAddrParm Implementation //--------------------------------------------------------------------------------------- std::mstring MpNameAddrParm::encode(bool chk_syntax_flag) const { std::mstring ret; if(!empty()) { std::mstring url; std::mstring disp; std::mstring comment; if(chk_syntax_flag) checkSyntax(); disp = mp_DispName; disp.atrims("\" "); if(!disp.empty()) { disp.ins_pair("\"", '\\'); disp.quote("\"", "\" "); } comment = mp_Comment; comment.atrims("() "); if(!comment.empty()) { comment.quote(" (", ")"); } url = mp_Url.encode(false); if(!disp.empty() || !comment.empty() || !mp_Parm.empty() || !mp_Url[mpiUrlParm].empty() || !mp_Url[mpiUrlHdr].empty()) { url.quote("<", ">"); } ret = disp + url + mp_Parm.encode(false) + comment; } return ret; } //--------------------------------------------------------------------------------------- void MpNameAddrParm::decode(const std::mstring & str, bool chk_syntax_flag) { erase(); if(!str.empty()) { int balance = 0; std::mstring ts = str; std::mstring url; std::mstring parm; std::mstring comment; std::string::size_type start = 0, end = 0; //Comment end = ts.brtok(&comment, &start, &balance, '(', ')', QuoteSymb, QPairSymb); if(balance != 0) { throw MpAccessError("MpNameAddrParm: Parenthesis balance"); } if(end != std::string::npos) { mp_Comment = comment; ts.erase(start, std::string::npos); } //Url <> start = 0; end = ts.brtok(&url, &start, &balance, '<', '>', QuoteSymb, QPairSymb); if(balance != 0) { throw MpAccessError("MpNameAddrParm: Angle brackets balance"); } if(end != std::string::npos) { ts.erase(start, end - start); ts.atrim(); if(!ts.empty()) { start = ts.next_token(0, ";", QuoteSymb, QPairSymb, std::mstring::sep_single); if(start != std::string::npos) { parm.assign(ts, start + 1, std::string::npos); mp_DispName.assign(ts, 0, start); parm.atrim(); } else { mp_DispName = ts; } mp_DispName.atrims("\" \t"); if(!parm.empty()) { mp_Parm.decode(parm, false); } } } else { url = ts; } mp_Url.decode(url, false); if(chk_syntax_flag) checkSyntax(); } } //--------------------------------------------------------------------------------------- void MpNameAddrParm::checkSyntax() const { mp_Url.checkSyntax(); mp_Parm.checkSyntax(); } //--------------------------------------------------------------------------------------- void MpNameAddrParm::erase() { mp_DispName.erase(); mp_Comment.erase(); mp_Url.erase(); mp_Parm.erase(); } //--------------------------------------------------------------------------------------- MpParseItem & MpNameAddrParm::operator [] (const char * name) { if(strcmp(name, mpiUrl) == 0) return mp_Url; if(strcmp(name, mpiParm) == 0) return mp_Parm; throw MpAccessError(std::mstring("MpNameAddrParm: Illegal nested name: ") + name); } //--------------------------------------------------------------------------------------- std::mstring & MpNameAddrParm::val(const char * name) { if(strcmp(name, mpnDispName) == 0) return mp_DispName; if(strcmp(name, mpnComment) == 0) return mp_Comment; throw MpAccessError(std::mstring("MpStartLine: Illegal Parameter: ") + name); } //--------------------------------------------------------------------------------------- void MpNameAddrParm::get(unsigned i, std::mstring *name, std::mstring *value) const { if(i == 0) { if(name) *name = mpnDispName; if(value) *value = mp_DispName; return; } if(i == 1) { if(name) *name = mpnComment; if(value) *value = mp_Comment; return; } throw MpAccessError("MpNameAddrParm: Out of index"); } //--------------------------------------------------------------------------------------- MpParseItem & MpNameAddrParm::item(unsigned i, std::mstring *name) { if(i == 0) { if(name) *name = mpiUrl; return mp_Url; } if(i == 1) { if(name) *name = mpiParm; return mp_Parm; } throw MpAccessError("MpNameAddrParm: Out of item index"); } //======================================================================================= //MpContentLen Implementation //--------------------------------------------------------------------------------------- void MpContentLength::checkSyntax() const { std::mstring value; get(0, 0, &value); ValAssistant::check(mpiParm, mpnContentLen, value); } //======================================================================================= //MpCSeq Implementation //--------------------------------------------------------------------------------------- MpCSeq::MpCSeq() : MpValue(' ') { setHeaderInfo(hdrnCSeq, false, false); set_val_name(0, mpnCSeq); set_val_name(1, mpnMethod); } //--------------------------------------------------------------------------------------- void MpCSeq::checkSyntax() const { std::mstring value; get(0, 0, &value); ValAssistant::check(mpiParm, mpnCSeq, value); get(1, 0, &value); ValAssistant::check(mpiUrlParm, mpnMethod, value); } //======================================================================================= //MpDate Implementation //--------------------------------------------------------------------------------------- void MpDate::checkSyntax() const { //!!! } //======================================================================================= //MpHide Implementation //--------------------------------------------------------------------------------------- void MpHide::checkSyntax() const { std::mstring value; get(0, 0, &value); ValAssistant::check(mpiParm, mpnHide, value); } //======================================================================================= //MpMaxForwards Implementation
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -