📄 mpitems.cxx
字号:
//--------------------------------------------------------------------------------------- void MpMaxForwards::checkSyntax() const { std::mstring value; get(0, 0, &value); ValAssistant::check(mpiParm, mpnMaxForw, value); } //======================================================================================= //MpPriority Implementation //--------------------------------------------------------------------------------------- void MpPriority::checkSyntax() const { std::mstring value; get(0, 0, &value); ValAssistant::check(mpiParm, mpnPriority, value); } //======================================================================================= //MpRoute Implementation //--------------------------------------------------------------------------------------- std::mstring MpRoute::encode(bool chk_syntax_flag) const { std::mstring ret = mp_Url.encode(chk_syntax_flag); ret.quote("<", ">"); return ret; } //--------------------------------------------------------------------------------------- void MpRoute::decode(const std::mstring & str, bool chk_syntax_flag) { std::mstring ts = str; ts.atrims("<> \t"); mp_Url.decode(ts, chk_syntax_flag); } //======================================================================================= //MpRetryAfter Implementation //--------------------------------------------------------------------------------------- std::mstring MpRetryAfter::encode(bool chk_syntax_flag) const { std::mstring ret; if(!empty()) { if(chk_syntax_flag) checkSyntax(); if(mp_Date.empty() && !mp_Seconds.empty()) { ret += mp_Seconds + " "; } else { ret += mp_Date + " "; } if(!mp_Comment.empty()) { std::mstring ts = mp_Comment; ts.atrims("() \t"); ts.quote("(", ")"); ret += ts; } if(!mp_Duration.empty()) { ret += ";duration=" + mp_Duration; } } return ret; } //--------------------------------------------------------------------------------------- void MpRetryAfter::decode(const std::mstring & str, bool chk_syntax_flag) { erase(); if(!str.empty()) { int balance = 0; std::mstring ts = str; std::mstring date; 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("MpRetryAfter: Parenthesis balance"); } if(end != std::string::npos) { mp_Comment = comment; ts.erase(start, end - start); } //duration start = ts.find("duration="); if(start != std::string::npos) { mp_Duration = ts.c_str() + start + 9; mp_Duration.atrim(); ts.erase(start, std::string::npos); } ts.rtrims(" ;\t"); if(atoi(ts.c_str()) != 0) { mp_Seconds = ts; } else { mp_Date = ts; } if(chk_syntax_flag) checkSyntax(); } } //--------------------------------------------------------------------------------------- void MpRetryAfter::checkSyntax() const { ValAssistant::check(mpiRetryAfter, mpnDate, mp_Date); ValAssistant::check(mpiRetryAfter, mpnSeconds, mp_Seconds); ValAssistant::check(mpiRetryAfter, mpnDuration, mp_Duration); if(!mp_Date.empty() && !mp_Seconds.empty()) { throw MpSyntaxError("MpRetryAfter: Only one of values allowed: mpnDate or mpnSeconds"); } } //--------------------------------------------------------------------------------------- void MpRetryAfter::erase() { mp_Date.erase(); mp_Seconds.erase(); mp_Duration.erase(); mp_Comment.erase(); } //--------------------------------------------------------------------------------------- MpParseItem & MpRetryAfter::operator [] (const char * name) { throw MpAccessError("MpRetryAfter: No nested items"); } //--------------------------------------------------------------------------------------- std::mstring & MpRetryAfter::val(const char * name) { if(strcmp(name, mpnDate) == 0) return mp_Date; if(strcmp(name, mpnSeconds) == 0) return mp_Seconds; if(strcmp(name, mpnDuration) == 0) return mp_Duration; if(strcmp(name, mpnComment) == 0) return mp_Comment; throw MpAccessError(std::mstring("MpRetryAfter: Illegal Parameter: ") + name); } //--------------------------------------------------------------------------------------- void MpRetryAfter::get(unsigned i, std::mstring *name, std::mstring *value) const { switch(i) { case 0: if(name) *name = mpnDate; if(value) *value = mp_Date; return; case 1: if(name) *name = mpnSeconds; if(value) *value = mp_Seconds; return; case 2: if(name) *name = mpnDuration; if(value) *value = mp_Duration; return; case 3: if(name) *name = mpnComment; if(value) *value = mp_Comment; return; } throw MpAccessError("MpRetryAfter: Out of index"); } //======================================================================================= //MpTimestamp Implementation //--------------------------------------------------------------------------------------- MpTimestamp::MpTimestamp() : MpValue(' ') { setHeaderInfo(hdrnTimestamp, false, false); set_val_name(0, mpnValue); set_val_name(1, mpnDelay); } //--------------------------------------------------------------------------------------- void MpTimestamp::checkSyntax() const { std::mstring value; get(0, 0, &value); ValAssistant::check(mpiTimestamp, mpnValue, value); get(1, 0, &value); ValAssistant::check(mpiTimestamp, mpnValue, value); } //======================================================================================= //MpVia Implementation //--------------------------------------------------------------------------------------- MpVia::MpVia() : MpValue('/') { setHeaderInfo(hdrnVia, true, false); set_val_name(0, mpnProto); set_val_name(1, mpnVersion); set_val_name(2, mpnTransport); } //--------------------------------------------------------------------------------------- std::mstring MpVia::encode(bool chk_syntax_flag) const { std::mstring ret; if(!empty()) { std::mstring comment; if(chk_syntax_flag) checkSyntax(); ret += MpValue::encode(false); if(!mp_HostPort.empty()) { ret += ' '; ret += mp_HostPort.encode(false); } ret += mp_UrlParm.encode(false); comment = mp_Comment; comment.atrims("() \t"); if(!comment.empty()) { comment.quote(" (", ")"); ret += comment; } } return ret; } //--------------------------------------------------------------------------------------- void MpVia::decode(const std::mstring & str, bool chk_syntax_flag) { erase(); if(!str.empty()) { int balance = 0; std::mstring ts = str; std::mstring hostport; std::mstring parm; std::mstring comment; std::string::size_type start = 0, end = 0; ts.ltrim(); //Comment end = ts.brtok(&comment, &start, &balance, '(', ')', QuoteSymb, QPairSymb); if(balance != 0) { throw MpAccessError("MpVia: Parenthesis balance"); } if(end != std::string::npos) { mp_Comment = comment; ts.erase(start, std::string::npos); ts.rtrim(); } //Parm start = ts.next_token(0, ";", QuoteSymb, QPairSymb); if(start != std::string::npos) { parm.assign(ts, start+1, std::string::npos); mp_UrlParm.decode(parm, false); ts.erase(start, std::string::npos); ts.rtrim(); } //HostPort start = ts.next_token(0, " ", QuoteSymb, QPairSymb); if(start != std::string::npos) { hostport.assign(ts, start+1, std::string::npos); mp_HostPort.decode(hostport, false); ts.erase(start, std::string::npos); ts.rtrim(); } MpValue::decode(ts, false); if(chk_syntax_flag) checkSyntax(); } } //--------------------------------------------------------------------------------------- void MpVia::checkSyntax() const { std::mstring value; get(0, 0, &value); ValAssistant::check(mpiVia, mpnProto, value); get(1, 0, &value); ValAssistant::check(mpiVia, mpnVersion, value); get(2, 0, &value); ValAssistant::check(mpiVia, mpnTransport, value); mp_HostPort.checkSyntax(); mp_UrlParm.checkSyntax(); } //--------------------------------------------------------------------------------------- MpParseItem & MpVia::operator [] (const char * name) { if(strcmp(name, mpiSentBy) == 0) return mp_HostPort; if(strcmp(name, mpiUrlParm) == 0) return mp_UrlParm; throw MpAccessError(std::mstring("MpVia: Illegal nested name: ") + name); } //--------------------------------------------------------------------------------------- std::mstring & MpVia::val(const char * name) { if(strcmp(name, mpnComment) == 0) return mp_Comment; return MpValue::val(name); } //--------------------------------------------------------------------------------------- void MpVia::get(unsigned i, std::mstring *name, std::mstring *value) const { if(i == 3) { if(name) *name = mpnComment; if(value) *value = mp_Comment; return; } MpValue::get(i, name, value); } //--------------------------------------------------------------------------------------- MpParseItem & MpVia::item(unsigned i, std::mstring *name) { if(i == 0) { if(name) *name = mpiSentBy; return mp_HostPort; } if(i == 1) { if(name) *name = mpiUrlParm; return mp_UrlParm; } throw MpAccessError("MpValParm: Out of item index"); } //======================================================================================= //MpWarning Implementation //--------------------------------------------------------------------------------------- MpWarning::MpWarning() : MpValue(' ') { setHeaderInfo(hdrnWarning, true, false); set_val_name(0, mpnCode); set_val_name(1, mpnAgent); set_val_name(2, mpnText, true); } //--------------------------------------------------------------------------------------- void MpWarning::checkSyntax() const { std::mstring value; get(0, 0, &value); ValAssistant::check(mpiWarning, mpnCode, value); get(1, 0, &value); ValAssistant::check(mpiWarning, mpnAgent, value); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -