📄 warurl.cpp
字号:
} }skip_hostname: if (mUrlType.IsHostscanRequiered() && (*p == '/')) ++p; #ifdef WIN32 else if (!url_len && (p[0] == '\\') && (p[1] == '\\') && (p[2] != '\\') && (p[2] != 0)) { // UNC path. Convert to URL pseg1 = pp; p += 2; while(!WarSysSlash::IsSlash(*p)) *pp++ = *p++; mHaveHostName = true; if (*pseg1) mHostName = pseg1; if (*p) ++p; }#endif fetch_path: // Until now, we have decoded the URL type, and the user@host part. // We now have to decode the url-path and command if (*p) { switch(mUrlType.GetStyle()) { case WarUrlType::S_HTTP: ParseHttp(p); break; case WarUrlType::S_FTP: ParseFtp(p); break; case WarUrlType::S_GENERIC: ParseGeneric(p); break; } } BuildUrl();}void WarUrl::BuildUrl() throw(WarException){ string TmpBuf; mUrl = GetTypeName(); if (mHaveUserName) { if (!mUserName.empty()) mUrl << Encode(TmpBuf, mUserName.c_str()); } if (mHavePassword) { mUrl << ':'; if (!mPassword.GetValue().empty()) mUrl << Encode(TmpBuf, mPassword.GetValue().c_str()); } if (mHaveUserName || mHavePassword) mUrl << '@'; if (mHaveHostName) { if (!mHostName.empty()) mUrl << Encode(TmpBuf, mHostName.c_str()); } if (mHavePort) { mUrl << ':'; WarItoa(mUrl.mString, (unsigned)mPort); } mUrl << '/'; if (mHaveUrlPath && !mUrlPath.empty()) { switch(mUrlType.GetStyle()) { case WarUrlType::S_HTTP: { war_ccstr_t p = mUrlPath.c_str(); if (*p == '/') ++p; mUrl << Encode(TmpBuf, p, ENC_DEFAULT); } break; default: mUrl << Encode(TmpBuf, mUrlPath.c_str(), ENC_PATH); } } switch(mUrlType.GetStyle()) { case WarUrlType::S_HTTP: { int count = 0; for(query_list_t::const_iterator P = mQueryList.begin() ; P != mQueryList.end() ; ++P) { if (count++ == 0) mUrl << '?'; else mUrl << '&'; string tmp_buf; mUrl << Encode(tmp_buf, P->c_str(), ENC_DEFAULT); } } if (mHaveCommand) { string tmp_buf; mUrl << '#' << Encode(tmp_buf, mCommand.c_str(), ENC_DEFAULT);; } break; case WarUrlType::S_FTP: if (mHaveCommand) { string tmp_buf; mUrl << ';' << Encode(tmp_buf, mCommand.c_str(), ENC_DEFAULT);; } break; case WarUrlType::S_GENERIC: break; } if (mUrlType.IsFilePathRequired()) { // Make a system file path! mFilePath.Reset(); if (mHaveHostName && !mHostName.empty()) { mFilePath << WAR_DSYSSLASH << WarUtf8(mHostName).GetUnicode() << WAR_SYSSLASH; } if (mHaveUrlPath && !mUrlPath.empty()) { war_ccstr_t my_path = mUrlPath.c_str(); bool start_is_slash = mFilePath.IsSlash(*my_path); if (start_is_slash && mFilePath.IsEmpty() && mFilePath.IsSlash(mFilePath.GetLastCh())) ++my_path; else if (!start_is_slash) {#ifdef WIN32 // Avoid ./ prefix on C:\ ... if (!(isalpha(my_path[0]) && (':' == my_path[1])))#endif { mFilePath << WAR_CDIR; } }#ifdef WIN32 // Windows don't like paths like "\\server\\share\blah", // so we have to strip off the leading path if it // exist... if (mHaveHostName && *my_path && mFilePath.IsSlash(*my_path)) ++my_path;#endif if (*my_path) { mFilePath << WarUtf8(my_path).GetUnicode(); } } else mFilePath << WAR_CDIR; mFilePath.Deparse(); mFilePath.Normalize(); } if (!mHavePassword || GetPassword().empty()) { mSafeUrl = mUrl.GetValue(); } else { // Hide the password war_ccstr_t p = mUrl.GetValue().c_str(); char *buf = (char *)alloca(mUrl.GetValue().size() + 8); char *pp = buf; while(*p && (*p != ':')) *pp++ = *p++; if (*p == ':') *pp++ = *p++; if (*p == '/') *pp++ = *p++; if (*p == '/') *pp++ = *p++; while(*p && (*p != ':')) *pp++ = *p++; if (*p == ':') *pp++ = *p++; while(*p && (*p != '@')) +p++; *pp++ = '*'; *pp++ = '*'; *pp++ = '*'; *pp++ = '*'; while(*p) *pp++ = *p++; *pp = 0; mSafeUrl = buf; }}std::string& WarUrl::Encode(std::string& Dst, war_ccstr_t Src, const EncodeModeE encMode){ war_ccstr_t p = Src; size_t max_len = (strlen(Src) * 3)+ 1; war_cstr_t buffer = (war_cstr_t)alloca(max_len); war_cstr_t pp = buffer; while(*p) { if (*p == '/') { if ((encMode == ENC_PATH) && (p == Src)) goto do_encode; // First WAR_SLASH in a path. Must be encoded goto do_add; } else if (!isalnum(*p) && (*p != '-') && (*p != '_') && (*p != '\\') && (*p != '/') && (*p != ':') && (*p != '=') && (*p != '.')) {do_encode: *pp++ = '%';#if defined(HAVE_ITOA) ::itoa((unsigned)((unsigned char)*p++), pp, 16);#else ::sprintf(pp,"%02x", (unsigned)((unsigned char)*p++));#endif pp += 2; } else {do_add: *pp++ = *p++; } } *pp = 0; Dst = buffer; return Dst;}void WarUrl::ParseHttp(war_ccstr_t str){ war_ccstr_t p = str; while(*p && (*p != '?') && (*p != '#')) ++p; if (*p == 0) { // Clean path Decode(mUrlPath, str); mHaveUrlPath = true; return; } size_t path_len = p - str; string buffer; buffer.resize(path_len); memcpy(&buffer[0], str, path_len); Decode(mUrlPath, str); mHaveUrlPath = true; if ((*p == '?') && *++p) { do { war_ccstr_t start_ofs = p; string decoded_str; while(*p && (*p != '&') && (*p != '#')) { path_len = p - start_ofs; buffer.resize(path_len); memcpy(&buffer[0], start_ofs, path_len); decoded_str = ""; Decode(decoded_str, buffer.c_str()); mQueryList.push_back(decoded_str); } } while(*p && (*p == '&')); } if ((*p == '#') && *++p) { mHaveCommand = true; Decode(mCommand, p); }} void WarUrl::ParseFtp(war_ccstr_t str){ vector<char> buf(strlen(str) +1); char *p = &buf[0]; while(*str && (';' != *str)) *p++ = *str++; *p = 0; Decode(mUrlPath, str); mHaveUrlPath = !mUrlPath.empty(); if (*str && *++str) { Decode(mCommand, str); mHaveCommand = true; }}void WarUrl::ParseGeneric(war_ccstr_t str){ if (*str) { Decode(mUrlPath, str); mHaveUrlPath = true; }}void WarUrl::SetFlagsFromValues(){ if (mPort) mHavePort = true; if (!mUserName.empty()) mHaveUserName = true; if (!mPassword.GetValue().empty()) mHavePassword = true; if (!mUrlPath.empty()) mHaveUrlPath = true; if (!mCommand.empty()) mHaveCommand = true; if (!mHostName.empty()) mHaveHostName = true;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -