⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 httpsvc.cxx

📁 mgcp协议源代码。支持多种编码:g711
💻 CXX
📖 第 1 页 / 共 3 页
字号:
                                         const PURL & url,                                         const PHTTPAuthority & auth,                                         const PString & prefix,                                         const PString & valueName,                                         const PURL & editSection,                                         const PURL & newSection,                                         const PString & newTitle,                                         PHTML & heading)  : PHTTPConfigSectionList(url, auth, prefix, valueName,                           editSection, newSection, newTitle, heading),    process(app){}void PConfigSectionsPage::OnLoadedText(PHTTPRequest & request, PString & text){  PServiceHTML::ProcessMacros(request, text,                              baseURL.AsString(PURL::PathOnly).Mid(1),                              PServiceHTML::LoadFromFile);  PHTTPConfigSectionList::OnLoadedText(request, text);}BOOL PConfigSectionsPage::OnPOST(PHTTPServer & server,                                 const PURL & url,                                 const PMIMEInfo & info,                                 const PStringToString & data,                                 const PHTTPConnectionInfo & connectInfo){  PHTTPConfigSectionList::OnPOST(server, url, info, data, connectInfo);  return FALSE;    // Make sure we break any persistent connections}BOOL PConfigSectionsPage::Post(PHTTPRequest & request,                               const PStringToString & data,                               PHTML & reply){  BOOL retval = PHTTPConfigSectionList::Post(request, data, reply);  if (request.code == PHTTP::OK)    process.BeginRestartSystem();  return retval;}BOOL PConfigSectionsPage::GetExpirationDate(PTime & when){  // Well and truly before now....  when = PTime(0, 0, 0, 1, 1, 1980);  return TRUE;}//////////////////////////////////////////////////////////////PRegisterPage::PRegisterPage(PHTTPServiceProcess & app,                             const PHTTPAuthority & auth)  : PConfigPage(app, "register.html", "Secured Options", auth),    process(app){}PString PRegisterPage::LoadText(PHTTPRequest & request){  if (fields.GetSize() > 0)    return PConfigPage::LoadText(request);  PString mailURL = "mailto:" + process.GetEMailAddress();  PString orderURL = mailURL;  PString tempURL = mailURL;  if (process.GetHomePage() == HOME_PAGE) {    orderURL = "https://home.equival.com.au/purchase.html";    tempURL = "http://www.equival.com/" + process.GetName().ToLower() + "/register.html";    tempURL.Replace(" ", "", TRUE);  }  PServiceHTML regPage(process.GetName() & "Registration", NULL);  regPage << "<!--#registration start Permanent-->"             "Your registration key is permanent.<p>"             "Do not change your registration details or your key will not "             "operate correctly.<p>"             "If you need to "          << PHTML::HotLink(orderURL)          << "upgrade"          << PHTML::HotLink()          << " or "          << PHTML::HotLink(mailURL)          << "change"          << PHTML::HotLink()          << " your registration, then you may enter the new values sent "          << " to you from "          << process.GetManufacturer()          << " into the fields "             "below, and then press the Accept button.<p>"          << PHTML::HRule()          << "<!--#registration end Permanent-->"             "<!--#registration start Temporary-->"             "Your registration key is temporary and will expire on "             "<!--#registration ExpiryDate-->.<p>"             "Do not change your registration details or your key will not "             "operate correctly.<p>"             "You may "          << PHTML::HotLink(orderURL)          << "order a permanent key"          << PHTML::HotLink()          << " and enter the new values sent to you from "          << process.GetManufacturer()          << " into the fields below, and then press the Accept button.<p>"          << PHTML::HRule()          << "<!--#registration end Temporary-->"             "<!--#registration start Expired-->"             "Your temporary registration key has expired.<p>"             "You may "          << PHTML::HotLink(orderURL)          << "order a permanent key"          << PHTML::HotLink()          << " and enter the new values sent to you from "          << process.GetManufacturer()          << " into the fields below, and then press the Accept button.<P>"          << PHTML::HRule()          << "<!--#registration end Expired-->";  PSecureConfig securedConf(process.GetProductKey(), process.GetSecuredKeys());  PString prefix;  if (securedConf.GetValidation() != PSecureConfig::IsValid)     prefix = securedConf.GetPendingPrefix();  AddFields(prefix);  Add(new PHTTPStringField("Validation", 40));  BuildHTML(regPage, InsertIntoHTML);  regPage << "<!--#registration start Invalid-->"             "You have entered the values sent to you from "          << process.GetManufacturer()          << " incorrectly. Please enter them again. Note, "          << PHTML::Emphasis() << PHTML::Strong() << "all" << PHTML::Strong() << PHTML::Emphasis()          << "the fields must be entered "          << PHTML::Emphasis() << PHTML::Strong() << "exactly" << PHTML::Strong() << PHTML::Emphasis()          << " as they appear in the e-mail from "          << process.GetManufacturer()          << ". We strongly recommend using copy and paste of all the fields, and then "             "press the Accept button."             "<!--#registration end Invalid-->"             "<!--#registration start Default-->"             "You may "          << PHTML::HotLink(orderURL)          << "order a permanent key"          << PHTML::HotLink()          << " or "          << PHTML::HotLink(tempURL)          << "obtain a temporary key"          << PHTML::HotLink()          << " and enter the values sent to you from "          << process.GetManufacturer()          << " into the fields above, and then press the Accept button.<p>"             "<!--#registration end Default-->"          << PHTML::HRule()          << PHTML::Heading(3) << "Disclaimer" << PHTML::Heading(3)          << PHTML::Paragraph() << PHTML::Bold()          << "The information and code herein is provided \"as is\" "             "without warranty of any kind, either expressed or implied, "             "including but not limited to the implied warrenties of "             "merchantability and fitness for a particular purpose. In "             "no event shall " << process.GetManufacturer() << " be liable "             "for any damages whatsoever including direct, indirect, "             "incidental, consequential, loss of business profits or special "             "damages, even if " << process.GetManufacturer() << " has been "             "advised of the possibility of such damages."          << PHTML::Bold() << PHTML::Paragraph()          << process.GetCopyrightText()          << PHTML::Body();  SetString(regPage);  return PConfigPage::LoadText(request);}static BOOL FindSpliceBlock(const PRegularExpression & regex,                            const PString & text,                            PINDEX & pos,                            PINDEX & len,                            PINDEX & start,                            PINDEX & finish){  if (!text.FindRegEx(regex, pos, len, 0))    return FALSE;  PINDEX endpos, endlen;  static PRegularExpression EndBlock("<?!--#registration[ \t\n]*end[ \t\n]*[a-z]*[ \t\n]*-->?",                                     PRegularExpression::Extended|PRegularExpression::IgnoreCase);  if (text.FindRegEx(EndBlock, endpos, endlen, pos)) {    start = pos+len;    finish = endpos-1;    len = endpos - pos + endlen;  }  return TRUE;}void PRegisterPage::OnLoadedText(PHTTPRequest & request, PString & text){  PString block;  PINDEX pos, len, start = 0, finish = 0;  PSecureConfig securedConf(process.GetProductKey(), process.GetSecuredKeys());  PTime expiry = securedConf.GetTime(securedConf.GetExpiryDateKey());  static PRegularExpression Default("<?!--#registration[ \t\n]*start[ \t\n]*Default[ \t\n]*-->?",                                    PRegularExpression::Extended|PRegularExpression::IgnoreCase);  static PRegularExpression Permanent("<?!--#registration[ \t\n]*start[ \t\n]*Permanent[ \t\n]*-->?",                                      PRegularExpression::Extended|PRegularExpression::IgnoreCase);  static PRegularExpression Temporary("<?!--#registration[ \t\n]*start[ \t\n]*Temporary[ \t\n]*-->?",                                      PRegularExpression::Extended|PRegularExpression::IgnoreCase);  static PRegularExpression Expired("<?!--#registration[ \t\n]*start[ \t\n]*Expired[ \t\n]*-->?",                                    PRegularExpression::Extended|PRegularExpression::IgnoreCase);  static PRegularExpression Invalid("<?!--#registration[ \t\n]*start[ \t\n]*Invalid[ \t\n]*-->?",                                    PRegularExpression::Extended|PRegularExpression::IgnoreCase);  static PRegularExpression Pending("name[ \t\n]*=[ \t\n]*\"" +                                    securedConf.GetPendingPrefix() +                                    "[^\"]+\"",                                    PRegularExpression::Extended|PRegularExpression::IgnoreCase);  PServiceHTML::ProcessMacros(request, text,                              baseURL.AsString(PURL::PathOnly).Mid(1),                              PServiceHTML::LoadFromFile);  switch (securedConf.GetValidation()) {    case PSecureConfig::Defaults :      while (FindSpliceBlock(Default, text, pos, len, start, finish))        text.Splice(text(start, finish), pos, len);      while (FindSpliceBlock(Permanent, text, pos, len, start, finish))        text.Delete(pos, len);      while (FindSpliceBlock(Temporary, text, pos, len, start, finish))        text.Delete(pos, len);      while (FindSpliceBlock(Expired, text, pos, len, start, finish))        text.Delete(pos, len);      while (FindSpliceBlock(Invalid, text, pos, len, start, finish))        text.Delete(pos, len);      break;    case PSecureConfig::Invalid :    case PSecureConfig::Pending :      while (FindSpliceBlock(Default, text, pos, len, start, finish))        text.Delete(pos, len);      while (FindSpliceBlock(Permanent, text, pos, len, start, finish))        text.Delete(pos, len);      while (FindSpliceBlock(Temporary, text, pos, len, start, finish))        text.Delete(pos, len);      while (FindSpliceBlock(Expired, text, pos, len, start, finish))        text.Delete(pos, len);      while (FindSpliceBlock(Invalid, text, pos, len, start, finish))        text.Splice(text(start, finish), pos, len);      break;    case PSecureConfig::Expired :      while (FindSpliceBlock(Default, text, pos, len, start, finish))        text.Delete(pos, len);      while (FindSpliceBlock(Permanent, text, pos, len, start, finish))        text.Delete(pos, len);      while (FindSpliceBlock(Temporary, text, pos, len, start, finish))        text.Delete(pos, len);      while (FindSpliceBlock(Expired, text, pos, len, start, finish))        text.Splice(text(start, finish), pos, len);      while (FindSpliceBlock(Invalid, text, pos, len, start, finish))        text.Delete(pos, len);      break;    case PSecureConfig::IsValid :      while (text.FindRegEx(Pending, pos, len)) {        static PINDEX pendingLength = securedConf.GetPendingPrefix().GetLength();        text.Delete(text.Find('"', pos)+1, pendingLength);        start = pos + len - pendingLength;      }      if (expiry.GetYear() < 2011) {        while (FindSpliceBlock(Default, text, pos, len, start, finish))          text.Delete(pos, len);        while (FindSpliceBlock(Permanent, text, pos, len, start, finish))          text.Delete(pos, len);        while (FindSpliceBlock(Temporary, text, pos, len, start, finish))          text.Splice(text(start, finish), pos, len);        while (FindSpliceBlock(Expired, text, pos, len, start, finish))          text.Delete(pos, len);        while (FindSpliceBlock(Invalid, text, pos, len, start, finish))          text.Delete(pos, len);      }      else {        while (FindSpliceBlock(Default, text, pos, len, start, finish))          text.Delete(pos, len);        while (FindSpliceBlock(Permanent, text, pos, len, start, finish))          text.Splice(text(start, finish), pos, len);        while (FindSpliceBlock(Temporary, text, pos, len, start, finish))          text.Delete(pos, len);        while (FindSpliceBlock(Expired, text, pos, len, start, finish))          text.Delete(pos, len);        while (FindSpliceBlock(Invalid, text, pos, len, start, finish))          text.Delete(pos, len);      }  }  static PRegularExpression ExpiryDate("<?!--#registration[ \t\n]*ExpiryDate[ \t\n]*-->?",                                       PRegularExpression::Extended|PRegularExpression::IgnoreCase);  while (text.FindRegEx(ExpiryDate, pos, len, 0))    text.Splice(expiry.AsString(PTime::LongDate), pos, len);  PHTTPConfig::OnLoadedText(request, text);  PServiceHTML::ProcessMacros(request, text, "", PServiceHTML::NoOptions);}BOOL PRegisterPage::Post(PHTTPRequest & request,                         const PStringToString & data,                         PHTML & reply){  if (fields.GetSize() == 0)    LoadText(request);  BOOL retval = PHTTPConfig::Post(request, data, reply);  if (request.code != PHTTP::OK)    return FALSE;  PSecureConfig sconf(process.GetProductKey(), process.GetSecuredKeys());  switch (sconf.GetValidation()) {    case PSecureConfig::Defaults :      sconf.ResetPending();      break;    case PSecureConfig::IsValid :      break;    case PSecureConfig::Pending :      sconf.ValidatePending();      break;    default :      sconf.ResetPending();  }  RemoveAllFields();  LoadText(request);  OnLoadedText(request, reply);  return retval;}///////////////////////////////////////////////////////////////////static void DigestSecuredKeys(PHTTPServiceProcess & process,                              PString & reginfo,                              PHTML * html){  const PStringArray & securedKeys = process.GetSecuredKeys();  PSecureConfig sconf(process.GetProductKey(), securedKeys);  PString prefix;  if (sconf.GetValidation() != PSecureConfig::IsValid)     prefix = sconf.GetPendingPrefix();  PMessageDigest5 digestor;  PStringStream info;  info << '"' << process.GetName() << "\" ===";  PINDEX i;  for (i = 0; i < securedKeys.GetSize(); i++) {    PString val = sconf.GetString(prefix + securedKeys[i]).Trim();    info << " \"" << val << '"';    if (html != NULL)      *html << PHTML::HiddenField(securedKeys[i], val);    digestor.Process(val);  }  PString digest = digestor.Complete();  if (html != NULL)    *html << PHTML::HiddenField("digest", digest);  info.Replace("===", digest);  reginfo = info;}///////////////////////////////////////////////////////////////////PServiceHTML::PServiceHTML(const char * title, const char * help, const char * helpGif){  PHTTPServiceProcess::Current().GetPageHeader(*this, title);  *this << PHTML::Heading(1) << title;    if (help != NULL)    *this << "&nbsp;"          << PHTML::HotLink(help)          << PHTML::Image(helpGif, "Help", 48, 23, "align=absmiddle")          << PHTML::HotLink();  *this << PHTML::Heading(1) << PHTML::Paragraph();}PString PServiceHTML::ExtractSignature(PString & out){  return ExtractSignature(*this, out);}PString PServiceHTML::ExtractSignature(const PString & html,                                       PString & out,                                       const char * keyword){  PString signature;  out = PString();  // search for all comment blocks  PINDEX  lastPos = 0, endPos = 0;  PINDEX  pos;  while ((pos    = html.Find("<!--", lastPos)) != P_MAX_INDEX &&         (endPos = html.Find("-->", pos))      != P_MAX_INDEX) {    // add in the text before the comment and move the ptr to the end of    // the comment    if (pos > lastPos)      out += html(lastPos, pos-1);    lastPos = endPos+3;    // tokenise the text inside the comment    PStringArray tokens = html(pos+4, endPos-1).Trim().Tokenise(" \n", FALSE);    // if this is a signature, then retreive it    if (tokens[0] *= keyword) {      PINDEX len = tokens.GetSize();      if (tokens[1] != "signature" || len != 3)        out += html(pos, endPos+2);      else        signature = tokens[2];    }  }  out += html(lastPos, P_MAX_INDEX);  return signature;}PString PServiceHTML::CalculateSignature(){  return CalculateSignature(*this);}PString PServiceHTML::CalculateSignature(const PString & out){  return CalculateSignature(out, PHTTPServiceProcess::Current().GetSignatureKey());}PString PServiceHTML::CalculateSignature(const PString & out,                                         const PTEACypher::Key & sig){  // calculate the MD5 digest of the HTML data  PMessageDigest5 digestor;  PINDEX p1 = 0;  PINDEX p2;  while ((p2 = out.FindOneOf("\r\n", p1)) != P_MAX_INDEX) {    if (p2 > p1)      digestor.Process(out(p1, p2-1));    digestor.Process("\r\n", 2);    p1 = p2 + 1;    if (out[p2] == '\r' && out[p1] == '\n') // CR LF pair      p1++;  }  digestor.Process(out(p1, P_MAX_INDEX));  PMessageDigest5::Code md5;  digestor.Complete(md5);  // encode it  PTEACypher cypher(sig);  return cypher.Encode(&md5, sizeof(md5));}BOOL PServiceHTML::CheckSignature(){  return CheckSignature(*this);}BOOL PServiceHTML::CheckSignature(const PString & html){  // extract the signature from the file  PString out;  PString signature = ExtractSignature(html, out);  // calculate the signature on the data  PString checkSignature = CalculateSignature(out);  // return TRUE or FALSE  return checkSignature == signature;}static BOOL FindBrackets(const PString & args, PINDEX & open, PINDEX & close){  open = args.FindOneOf("[{(", close);  if (open == P_MAX_INDEX)    return FALSE;  switch (args[open]) {    case '[' :      close = args.Find(']', open+1);      break;    case '{' :      close = args.Find('}', open+1);      break;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -