result_t Url::parse(exlib::string url, bool parseQueryString, bool slashesDenoteHost) { bool bHost; clear(); m_slashes = false; trimUrl(url, url); const char* c_str = url.c_str(); bool hasHash = qstrchr(c_str, '#') != NULL; if (!slashesDenoteHost && !hasHash && isUrlSlash(*c_str)) { parsePath(c_str); parseQuery(c_str); parseHash(c_str); if (parseQueryString) { m_queryParsed = new HttpCollection(); m_queryParsed->parse(m_query); } return 0; } parseProtocol(c_str); bHost = checkHost(c_str); if (slashesDenoteHost || m_protocol.length() > 0 || bHost) m_slashes = ((isUrlSlash(*c_str) && isUrlSlash(c_str[1])) && (m_protocol.length() <= 0 || m_protocol.compare("javascript:"))); if (m_protocol.compare("javascript:") && m_slashes) { c_str += 2; parseAuth(c_str); parseHost(c_str); } parsePath(c_str); parseQuery(c_str); parseHash(c_str); if (parseQueryString) { m_queryParsed = new HttpCollection(); m_queryParsed->parse(m_query); } return 0; }
// Defined by the WebCrypto spec as: // // dictionary RsaHashedImportParams { // AlgorithmIdentifier hash; // }; bool parseRsaHashedImportParams(const Dictionary& raw, OwnPtr<blink::WebCryptoAlgorithmParams>& params, const ErrorContext& context, String& errorDetails) { blink::WebCryptoAlgorithm hash; if (!parseHash(raw, hash, context, errorDetails)) return false; params = adoptPtr(new blink::WebCryptoRsaHashedImportParams(hash)); return true; }
// Defined by the WebCrypto spec as: // // dictionary RsaHashedKeyGenParams : RsaKeyGenParams { // AlgorithmIdentifier hash; // }; bool parseRsaHashedKeyGenParams(const Dictionary& raw, OwnPtr<blink::WebCryptoAlgorithmParams>& params, const ErrorContext& context, String& errorDetails) { uint32_t modulusLength; RefPtr<Uint8Array> publicExponent; if (!parseRsaKeyGenParams(raw, modulusLength, publicExponent, context, errorDetails)) return false; blink::WebCryptoAlgorithm hash; if (!parseHash(raw, hash, context, errorDetails)) return false; params = adoptPtr(new blink::WebCryptoRsaHashedKeyGenParams(hash, modulusLength, static_cast<const unsigned char*>(publicExponent->baseAddress()), publicExponent->byteLength())); return true; }
// Defined by the WebCrypto spec as: // // dictionary HmacKeyGenParams : Algorithm { // AlgorithmIdentifier hash; // // The length (in bits) of the key to generate. If unspecified, the // // recommended length will be used, which is the size of the associated hash function's block // // size. // unsigned long length; // }; bool parseHmacKeyGenParams(const Dictionary& raw, OwnPtr<blink::WebCryptoAlgorithmParams>& params, const ErrorContext& context, String& errorDetails) { blink::WebCryptoAlgorithm hash; if (!parseHash(raw, hash, context, errorDetails)) return false; bool hasLength; uint32_t length = 0; if (!getOptionalUint32(raw, "length", hasLength, length, context, errorDetails)) return false; params = adoptPtr(new blink::WebCryptoHmacKeyGenParams(hash, hasLength, length)); return true; }
Object Parser::parse(const std::string & str) { if(str == "null") return Object(Object::Null); if(str == "true" || str == "false") return Object(Object::Bool, str); if(str[0] == '"') return Object(Object::String, str.substr(1, str.length() - 2)); if((str[0] >= 48 && str[0] <= 57) || str[0] == '-') return Object(Object::Number, str); if(str[0] == '[') return parseArray(str); if(str[0] == '{') return parseHash(str); throw Error((boost::format("Не удалось распознать тип: `%1%'") % str).str()); return Object(); }
// source = scheme ":" // / ( [ scheme "://" ] host [ port ] [ path ] ) // / "'self'" bool CSPSourceList::parseSource(const UChar* begin, const UChar* end, String& scheme, String& host, int& port, String& path, CSPSource::WildcardDisposition& hostWildcard, CSPSource::WildcardDisposition& portWildcard) { if (begin == end) return false; if (equalIgnoringCase("'none'", begin, end - begin)) return false; if (end - begin == 1 && *begin == '*') { addSourceStar(); return true; } if (equalIgnoringCase("'self'", begin, end - begin)) { addSourceSelf(); return true; } if (equalIgnoringCase("'unsafe-inline'", begin, end - begin)) { addSourceUnsafeInline(); return true; } if (equalIgnoringCase("'unsafe-eval'", begin, end - begin)) { addSourceUnsafeEval(); return true; } String nonce; if (!parseNonce(begin, end, nonce)) return false; if (!nonce.isNull()) { addSourceNonce(nonce); return true; } DigestValue hash; ContentSecurityPolicyHashAlgorithm algorithm = ContentSecurityPolicyHashAlgorithmNone; if (!parseHash(begin, end, hash, algorithm)) return false; if (hash.size() > 0) { addSourceHash(algorithm, hash); return true; } const UChar* position = begin; const UChar* beginHost = begin; const UChar* beginPath = end; const UChar* beginPort = 0; skipWhile<UChar, isNotColonOrSlash>(position, end); if (position == end) { // host // ^ return parseHost(beginHost, position, host, hostWildcard); } if (position < end && *position == '/') { // host/path || host/ || / // ^ ^ ^ return parseHost(beginHost, position, host, hostWildcard) && parsePath(position, end, path); } if (position < end && *position == ':') { if (end - position == 1) { // scheme: // ^ return parseScheme(begin, position, scheme); } if (position[1] == '/') { // scheme://host || scheme:// // ^ ^ if (!parseScheme(begin, position, scheme) || !skipExactly<UChar>(position, end, ':') || !skipExactly<UChar>(position, end, '/') || !skipExactly<UChar>(position, end, '/')) return false; if (position == end) return false; beginHost = position; skipWhile<UChar, isNotColonOrSlash>(position, end); } if (position < end && *position == ':') { // host:port || scheme://host:port // ^ ^ beginPort = position; skipUntil<UChar>(position, end, '/'); } } if (position < end && *position == '/') { // scheme://host/path || scheme://host:port/path // ^ ^ if (position == beginHost) return false; beginPath = position; } if (!parseHost(beginHost, beginPort ? beginPort : beginPath, host, hostWildcard)) return false; if (beginPort) { if (!parsePort(beginPort, beginPath, port, portWildcard)) return false; } else { port = 0; } if (beginPath != end) { if (!parsePath(beginPath, end, path)) return false; } return true; }