void nsGnomeVFSProtocolHandler::InitSupportedProtocolsPref(nsIPrefBranch *prefs) { // read preferences nsresult rv = prefs->GetCharPref(MOZ_GNOMEVFS_SUPPORTED_PROTOCOLS, getter_Copies(mSupportedProtocols)); if (NS_SUCCEEDED(rv)) { mSupportedProtocols.StripWhitespace(); ToLowerCase(mSupportedProtocols); } else mSupportedProtocols.Assign("smb:,sftp:"); // use defaults LOG(("gnomevfs: supported protocols \"%s\"\n", mSupportedProtocols.get())); }
void nsGIOProtocolHandler::InitSupportedProtocolsPref(nsIPrefBranch *prefs) { // Get user preferences to determine which protocol is supported. // Gvfs/GIO has a set of supported protocols like obex, network, archive, // computer, dav, cdda, gphoto2, trash, etc. Some of these seems to be // irrelevant to process by browser. By default accept only smb and sftp // protocols so far. nsresult rv = prefs->GetCharPref(MOZ_GIO_SUPPORTED_PROTOCOLS, getter_Copies(mSupportedProtocols)); if (NS_SUCCEEDED(rv)) { mSupportedProtocols.StripWhitespace(); ToLowerCase(mSupportedProtocols); } else mSupportedProtocols.AssignLiteral("smb:,sftp:"); // use defaults LOG(("gio: supported protocols \"%s\"\n", mSupportedProtocols.get())); }
nsresult nsDataHandler::ParseURI(nsCString& spec, nsCString& contentType, nsCString& contentCharset, bool& isBase64, nsCString& dataBuffer, nsCString& hashRef) { isBase64 = false; // move past "data:" char *buffer = (char *) PL_strcasestr(spec.BeginWriting(), "data:"); if (!buffer) { // malformed uri return NS_ERROR_MALFORMED_URI; } buffer += 5; // First, find the start of the data char *comma = strchr(buffer, ','); if (!comma) return NS_ERROR_MALFORMED_URI; *comma = '\0'; // determine if the data is base64 encoded. char *base64 = PL_strcasestr(buffer, ";base64"); if (base64) { isBase64 = true; *base64 = '\0'; } if (comma == buffer) { // nothing but data contentType.AssignLiteral("text/plain"); contentCharset.AssignLiteral("US-ASCII"); } else { // everything else is content type char *semiColon = (char *) strchr(buffer, ';'); if (semiColon) *semiColon = '\0'; if (semiColon == buffer || base64 == buffer) { // there is no content type, but there are other parameters contentType.AssignLiteral("text/plain"); } else { contentType = buffer; ToLowerCase(contentType); } if (semiColon) { char *charset = PL_strcasestr(semiColon + 1, "charset="); if (charset) contentCharset = charset + sizeof("charset=") - 1; *semiColon = ';'; } } *comma = ','; if (isBase64) *base64 = ';'; contentType.StripWhitespace(); contentCharset.StripWhitespace(); // Split encoded data from terminal "#ref" (if present) char *data = comma + 1; char *hash = strchr(data, '#'); if (!hash) { dataBuffer.Assign(data); hashRef.Truncate(); } else { dataBuffer.Assign(data, hash - data); hashRef.Assign(hash); } return NS_OK; }
nsresult nsDataHandler::ParseURI(nsCString& spec, nsCString& contentType, nsCString& contentCharset, bool& isBase64, nsCString& dataBuffer, nsCString& hashRef) { isBase64 = false; // move past "data:" char *buffer = (char *) PL_strcasestr(spec.BeginWriting(), "data:"); if (!buffer) { // malformed uri return NS_ERROR_MALFORMED_URI; } buffer += 5; // First, find the start of the data char *comma = strchr(buffer, ','); char *hash = strchr(buffer, '#'); if (!comma || (hash && hash < comma)) return NS_ERROR_MALFORMED_URI; *comma = '\0'; // determine if the data is base64 encoded. char *base64 = PL_strcasestr(buffer, BASE64_EXTENSION); if (base64) { char *beyond = base64 + strlen(BASE64_EXTENSION); // per the RFC 2397 grammar, "base64" MUST be followed by a comma // previously substituted by '\0', but we also allow it in between // parameters so a subsequent ";" is ok as well (this deals with // *broken* data URIs, see bug 781693 for an example) if (*beyond == '\0' || *beyond == ';') { isBase64 = true; *base64 = '\0'; } } if (comma == buffer) { // nothing but data contentType.AssignLiteral("text/plain"); contentCharset.AssignLiteral("US-ASCII"); } else { // everything else is content type char *semiColon = (char *) strchr(buffer, ';'); if (semiColon) *semiColon = '\0'; if (semiColon == buffer || base64 == buffer) { // there is no content type, but there are other parameters contentType.AssignLiteral("text/plain"); } else { contentType = buffer; ToLowerCase(contentType); } if (semiColon) { char *charset = PL_strcasestr(semiColon + 1, "charset="); if (charset) contentCharset = charset + sizeof("charset=") - 1; *semiColon = ';'; } } *comma = ','; if (isBase64) *base64 = ';'; contentType.StripWhitespace(); contentCharset.StripWhitespace(); // Split encoded data from terminal "#ref" (if present) char *data = comma + 1; if (!hash) { dataBuffer.Assign(data); hashRef.Truncate(); } else { dataBuffer.Assign(data, hash - data); hashRef.Assign(hash); } return NS_OK; }
nsresult nsDataHandler::ParseURI(nsCString& spec, nsCString& contentType, nsCString* contentCharset, bool& isBase64, nsCString* dataBuffer) { isBase64 = false; // move past "data:" const char* roBuffer = (const char*) PL_strcasestr(spec.get(), "data:"); if (!roBuffer) { // malformed uri return NS_ERROR_MALFORMED_URI; } roBuffer += sizeof("data:") - 1; // First, find the start of the data const char* roComma = strchr(roBuffer, ','); const char* roHash = strchr(roBuffer, '#'); if (!roComma || (roHash && roHash < roComma)) { return NS_ERROR_MALFORMED_URI; } if (roComma == roBuffer) { // nothing but data contentType.AssignLiteral("text/plain"); if (contentCharset) { contentCharset->AssignLiteral("US-ASCII"); } } else { // Make a copy of the non-data part so we can null out parts of it as // we go. This copy will be a small number of chars, in contrast to the // data which may be large. char* buffer = PL_strndup(roBuffer, roComma - roBuffer); // determine if the data is base64 encoded. char* base64 = PL_strcasestr(buffer, BASE64_EXTENSION); if (base64) { char *beyond = base64 + sizeof(BASE64_EXTENSION) - 1; // Per the RFC 2397 grammar, "base64" MUST be at the end of the // non-data part. // // But we also allow it in between parameters so a subsequent ";" // is ok as well (this deals with *broken* data URIs, see bug // 781693 for an example). Anything after "base64" in the non-data // part will be discarded in this case, however. if (*beyond == '\0' || *beyond == ';') { isBase64 = true; *base64 = '\0'; } } // everything else is content type char *semiColon = (char *) strchr(buffer, ';'); if (semiColon) *semiColon = '\0'; if (semiColon == buffer || base64 == buffer) { // there is no content type, but there are other parameters contentType.AssignLiteral("text/plain"); } else { contentType.Assign(buffer); ToLowerCase(contentType); contentType.StripWhitespace(); } if (semiColon && contentCharset) { char *charset = PL_strcasestr(semiColon + 1, "charset="); if (charset) { contentCharset->Assign(charset + sizeof("charset=") - 1); contentCharset->StripWhitespace(); } } free(buffer); } if (dataBuffer) { // Split encoded data from terminal "#ref" (if present) const char* roData = roComma + 1; bool ok = !roHash ? dataBuffer->Assign(roData, mozilla::fallible) : dataBuffer->Assign(roData, roHash - roData, mozilla::fallible); if (!ok) { return NS_ERROR_OUT_OF_MEMORY; } } return NS_OK; }