bool IsResumableURL(const URL& url) { OP_ASSERT(url.GetAttribute(URL::KMultimedia) != FALSE); // Not using URL::KResumeSupported as it is set to Probably_Resumable // when the Accept-Ranges: bytes header is present. Since we always // make byte range requests, the response code is a better indicator. int response = url.GetAttribute(URL::KHTTP_Response_Code, URL::KFollowRedirect); return response == HTTP_PARTIAL_CONTENT; }
/** * Check if the given file: URL is an allowed stylesheet import inside the * generated document for an XML parse error. Only allowed if it is * equal to the underlying pref or that of the 'standard' opera.css. * * @param the target URL being loaded inline. * @return OpBoolean::IS_TRUE if allowed, OpBoolean::IS_FALSE. * OpStatus::ERR_NO_MEMORY on OOM. */ static OP_BOOLEAN IsAllowedStyleFileImport(const URL &url) { OpString file_path; RETURN_IF_ERROR(url.GetAttribute(URL::KUniName, file_path)); OpString xmlerror_css; RETURN_IF_LEAVE(g_pcfiles->GetFileURLL(PrefsCollectionFiles::StyleErrorFile, &xmlerror_css)); if (file_path.Compare(xmlerror_css) == 0) return OpBoolean::IS_TRUE; /* This is not complete, but we do also allow the importing of the style folder's opera.css. Clearly someone could provide a custom error.css that has an arbitrary collection of imports. This will not work for generated XML error pages. */ OpFile opera_css; RETURN_IF_ERROR(opera_css.Construct(UNI_L("opera.css"), OPFILE_STYLE_FOLDER)); const uni_char *path = opera_css.GetFullPath(); TempBuffer escaped_path; RETURN_IF_ERROR(escaped_path.Expand(uni_strlen(path) * 3 + 1)); UriEscape::Escape(escaped_path.GetStorage(), path, UriEscape::Filename); OpString opera_css_file; RETURN_IF_LEAVE(g_url_api->ResolveUrlNameL(escaped_path.GetStorage(), opera_css_file)); if (file_path.Compare(opera_css_file) == 0) return OpBoolean::IS_TRUE; return OpBoolean::IS_FALSE; }
URL MediaSourceManagerImpl::GetUrlWithMediaContext(const URL& url) { // Don't override anything but the default context for now. if (url.GetContextId() != 0) return url; // Create new context manager if it doesn't exists already. if (!m_url_context_id) { m_url_context_id = urlManager->GetNewContextID(); OpFileFolder media_cache_folder; if (OpStatus::IsError(g_folder_manager->AddFolder(OPFILE_CACHE_FOLDER, UNI_L("media"), &media_cache_folder))) { OP_ASSERT(!"Failed to create folder for dedicated media cache. Falling back to default"); return url; } Context_Manager_Multimedia::CreateManager(m_url_context_id, media_cache_folder, media_cache_folder, FALSE, PrefsCollectionNetwork::MediaCacheSize); } // Create new url with the media context. const OpStringC tmp_url_str = url.GetAttribute(URL::KUniName_With_Fragment_Username_Password_NOT_FOR_UI, URL::KNoRedirect); return g_url_api->GetURL(tmp_url_str, m_url_context_id); }
bool IsSuccessURL(const URL& url) { if (url.IsEmpty()) return false; switch (url.Type()) { case URL_HTTP: case URL_HTTPS: switch (url.GetAttribute(URL::KHTTP_Response_Code)) { case HTTP_OK: case HTTP_PARTIAL_CONTENT: case HTTP_NOT_MODIFIED: return true; default: return false; } case URL_FTP: case URL_FILE: case URL_DATA: case URL_WIDGET: return true; default: return false; } }
/* virtual */ BOOL DocumentInteractionContext::HasCachedBGImageData() { if (m_doc) { URL url = m_doc->GetBGImageURL(); return !url.IsEmpty() && url.GetAttribute(URL::KIsImage, TRUE); } return FALSE; }
virtual BOOL Redirected(XMLParser *parser) { URL url = parser->GetURL().GetAttribute(URL::KMovedToURL, FALSE); while (!url.IsEmpty()) if (!DOM_XSLTAllowAccess(OpSecurityManager::XSLT_IMPORT_OR_INCLUDE, thread->GetScheduler()->GetFramesDocument(), url)) return FALSE; else url = url.GetAttribute(URL::KMovedToURL, FALSE); return TRUE; }
void TransfersPanel::OnDragDrop(OpWidget* widget, OpDragObject* op_drag_object, INT32 pos, INT32 x, INT32 y) { DesktopDragObject* drag_object = static_cast<DesktopDragObject *>(op_drag_object); if( KioskManager::GetInstance()->GetNoDownload() ) { return; } if (drag_object->GetURL()) { // start download to download directory // We could also check on url-type here, if it was a directory it could be traversed // and the whole directory tree could be put into the transferqueue. We should have // a better queueing system before this is added though. (Max simultaneous transfers, // with a stack on the side.) OpTransferItem* item; OpString filename; URL durl = g_url_api->GetURL(drag_object->GetURL()); OpString tmp_storage; const OpStringC downloaddirectory = g_folder_manager->GetFolderPathIgnoreErrors(OPFILE_DOWNLOAD_FOLDER, tmp_storage); filename.Set(downloaddirectory); OpString tmp; TRAPD(op_err, durl.GetAttribute(URL::KSuggestedFileName_L, tmp, TRUE)); filename.Append(tmp); durl.LoadToFile(filename.CStr()); // need to set the timestamp, this is used for expiry in list when read from rescuefile time_t loaded = (time_t) (g_op_time_info->GetTimeUTC()/1000.0); durl.SetAttribute(URL::KVLocalTimeLoaded, &loaded); if(OpStatus::IsError(((TransferManager*)g_transferManager)->AddTransferItem(durl, filename.CStr()))) { return; } ((TransferManager*)g_transferManager)->GetTransferItem(&item, drag_object->GetURL()); item->Continue(); } }
OP_STATUS SpeedDialConfigController::UpdateExtensionView(unsigned pos, const OpStringC& name, const URL& download_url, const URL& screenshot_url) { OP_NEW_DBG("SpeedDialConfigController::UpdateExtensionView", "speeddial"); OP_DBG(("pos = ") << pos); OP_DBG(("download URL = ") << download_url.GetAttribute(URL::KUniName_Username_Password_NOT_FOR_UI)); OP_DBG(("screenshot URL = ") << screenshot_url.GetAttribute(URL::KUniName_Username_Password_NOT_FOR_UI)); OP_ASSERT(pos < ARRAY_SIZE(m_extension_views)); if (OpStatus::IsError(m_extension_views[pos].m_image_downloader.Init(screenshot_url))) m_extension_views[pos].DownloadFailed(); m_extension_views[pos].m_button->GetOpWidget()->GetAction()->SetActionDataString( download_url.GetAttribute(URL::KUniName_Username_Password_NOT_FOR_UI)); RETURN_IF_ERROR(m_extension_views[pos].m_name->SetText(name)); // Invisible, but useful for Watir tests. RETURN_IF_ERROR(m_extension_views[pos].m_button->GetOpWidget()->SetText(name)); return OpStatus::OK; }
/* static */ void ES_ImportedAPI::PostToConsole(const uni_char* message, FramesDocument* fd) { if (!g_console->IsLogging()) return; URL* url = NULL; const uni_char *url_name = UNI_L("Script of unknown origin"); if (fd != NULL) { url = &fd->GetURL(); url_name = url->GetAttribute(URL::KUniName_Username_Password_Hidden).CStr(); } OpConsoleEngine::Message cmessage(OpConsoleEngine::EcmaScript, OpConsoleEngine::Error); OP_STATUS rc1, rc2, rc3; rc1 = cmessage.message.Set(message); if (url) { if (0 == uni_strcmp(url_name, UNI_L("POSTED"))) { // Message from opera.postError() cmessage.url.Empty(); cmessage.severity = OpConsoleEngine::Information; rc2 = OpStatus::OK; } else rc2 = cmessage.url.Set(url_name); } else rc2 = cmessage.url.Set(url_name); if (fd && fd->GetWindow()) cmessage.window = fd->GetWindow()->Id(); if (fd && fd->GetESScheduler()) rc3 = cmessage.context.Set(fd->GetESScheduler()->GetThreadInfoString()); else rc3 = cmessage.context.Set("Unknown thread"); if (OpStatus::IsSuccess(rc1) && OpStatus::IsSuccess(rc2) && OpStatus::IsSuccess(rc3)) { TRAPD(rc, g_console->PostMessageL(&cmessage)); OpStatus::Ignore(rc); // FIXME:OOM } }
virtual BOOL Redirected(XMLParser *parser) { if (FramesDocument *doc = GetFramesDocument()) { URL url = parser->GetURL().GetAttribute(URL::KMovedToURL, FALSE); while (!url.IsEmpty()) if (!DOM_XSLTAllowAccess(OpSecurityManager::XSLT_DOCUMENT, doc, url)) return FALSE; else url = url.GetAttribute(URL::KMovedToURL, FALSE); return TRUE; } else return FALSE; }
void TransfersPanel::ExecuteTransferItem(TransferItem * t_item) { if(!t_item) return; OpString filename; if(t_item->GetType() == TransferItem::TRANSFERTYPE_PEER2PEER_DOWNLOAD) { t_item->GetDownloadDirectory(filename); UINT32 idx = filename.FindLastOf(PATHSEPCHAR); if(idx + 1 != 0) { filename.Append(PATHSEP); } filename.Append(*(t_item->GetStorageFilename())); } else { filename.Set(*(t_item->GetStorageFilename())); } if(!filename.IsEmpty()) { #ifdef MSWIN Execute(filename.CStr(), NULL); #else OpString handler; OpString content_type; URL* url = t_item->GetURL(); if(url) { content_type.Set(url->GetAttribute(URL::KMIME_Type)); } g_op_system_info->GetFileHandler(&filename, content_type, handler); static_cast<DesktopOpSystemInfo*>(g_op_system_info)->OpenFileInApplication( handler.CStr(), filename.CStr()); #endif } }
OP_STATUS URL_DynamicUIntAttributeDescriptor::OnSetValue(URL &url, URL_DataStorage *url_ds, uint32 &in_out_value, BOOL &set_value) const { set_value = FALSE; if(handler.get() != NULL) { OP_STATUS op_err = handler->OnSetValue(url, in_out_value, set_value); if(OpStatus::IsSuccess(op_err) && is_flag && set_value) { uint32 mask_set = 0; if(in_out_value != 0) { in_out_value = TRUE; mask_set = flag_mask; } uint32 current_flags; #ifdef SELFTEST // Hack to allow selftests to test directly */ if(url_ds == NULL) current_flags = url.GetAttribute(flag_attribute_id); else #endif current_flags = url_ds->GetAttribute(flag_attribute_id); current_flags = (current_flags & (~flag_mask)) | mask_set; #ifdef SELFTEST // Hack to allow selftests to test directly */ if(url_ds == NULL) op_err = url.SetAttribute(flag_attribute_id, current_flags); else #endif op_err = url_ds->SetAttribute(flag_attribute_id, current_flags); set_value = FALSE; } return op_err; } return OpStatus::OK; }
OP_STATUS URL_DynamicUIntAttributeDescriptor::OnGetValue(URL &url, uint32 &in_out_value) const { if(handler.get() != NULL) { if(is_flag) { uint32 current_flags = url.GetAttribute(flag_attribute_id); in_out_value = ((current_flags & flag_mask) != 0 ? TRUE : FALSE); } OP_STATUS op_err = handler->OnGetValue(url, in_out_value); if(OpStatus::IsSuccess(op_err) && is_flag && in_out_value) in_out_value = TRUE; return op_err; } return OpStatus::OK; }
void WidgetCreator::DoWidgetSpecificHacks(OpHelpTooltip* tooltip) { if (OpStatus::IsSuccess(tooltip->Init())) { if (m_action && m_action->HasActionDataString()) { URL url = g_url_api->GetURL(m_action->GetActionDataString()); OpString8 host_name; if (OpStatus::IsSuccess(url.GetAttribute(URL::KHostName, host_name)) && host_name.HasContent()) { tooltip->SetHelpUrl(m_action->GetActionDataString()); } else { tooltip->SetHelpTopic(m_action->GetActionDataString()); } } tooltip->SetVisibility(FALSE); } }
OP_STATUS SpeedDialGenericHandler::GetButtonInfo(GenericThumbnailContent::ButtonInfo& info) const { info.m_name.Empty(); RETURN_IF_ERROR(info.m_name.AppendFormat("Speed Dial %d", GetNumber())); info.m_accessibility_text.Empty(); RETURN_IF_ERROR(info.m_accessibility_text.AppendFormat( UNI_L("Thumbnail %d"), GetNumber())); info.m_action = OpInputAction::ACTION_GOTO_SPEEDDIAL; info.m_action_data = g_speeddial_manager->GetSpeedDialActionData(m_entry); OpString tooltip_format; RETURN_IF_ERROR(g_languageManager->GetString(Str::S_CLICK_TO_GO_TO_SPEED_DIAL_ENTRY, tooltip_format)); const URL url = urlManager->GetURL(m_entry->GetDisplayURL()); OpString url_string; RETURN_IF_ERROR(url.GetAttribute(URL::KUniName_With_Fragment_Username, url_string)); RETURN_IF_ERROR(info.m_tooltip_text.AppendFormat(tooltip_format.CStr(), url_string.CStr())); return OpStatus::OK; }
void BasicWindowListener::ReportFailure(URL &url, const char *format, ...) { OpString8 tempstring; va_list args; va_start(args, format); if(format == NULL) format = ""; OP_STATUS op_err = url.GetAttribute(URL::KName_Escaped, tempstring); if(OpStatus::IsSuccess(op_err)) op_err = tempstring.Append(" :"); if(OpStatus::IsSuccess(op_err)) tempstring.AppendVFormat(format, args); if(test_manager) test_manager->ReportTheFailure(OpStatus::IsSuccess(op_err) ? tempstring.CStr() : format); else ST_failed(OpStatus::IsSuccess(op_err) ? tempstring.CStr() : format); va_end(args); }
OP_STATUS SpeedDialGenericHandler::HandleMidClick() { const INT32 key_state = g_op_system_info->GetShiftKeyState(); if (key_state == SHIFTKEY_SHIFT) { MidClickDialog::Create(g_application->GetActiveDesktopWindow()); return OpStatus::OK; } if (key_state != 0) return OpStatus::OK; const int action = g_pcui->GetIntegerPref(PrefsCollectionUI::CenterMouseButtonAction); if (0 <= action && action <= 4) { const URL url = urlManager->GetURL(m_entry->GetURL()); OpString url_string; RETURN_IF_ERROR(url.GetAttribute(URL::KUniName_With_Fragment_Username, url_string)); OpenURLSetting setting; setting.m_address.Set(url_string); setting.m_src_commander = NULL; setting.m_document = NULL; setting.m_new_window = action == 3 || action == 4 ? YES : NO; setting.m_new_page = action == 1 || action == 2 ? YES : NO; setting.m_in_background = action == 2 || action == 4 ? YES : NO; DocumentDesktopWindow* document_desktop_window = g_application->GetActiveDocumentDesktopWindow(); if (document_desktop_window) setting.m_is_privacy_mode = document_desktop_window->PrivacyMode(); if (!g_application->OpenURL(setting)) return OpStatus::ERR; } return OpStatus::OK; }
/** Verify checksum * The function will return FALSE if verification fails or if any errors occur, * * @param signed_file URL containing the file to be verified. MUST be loaded, * which can be accomplished with signed_file.QuickLoad(TRUE) * @param checksum Base64 encoded checksum * * @param alg Algorithm used to calculate checksum. Default SSL_SHA * * @return TRUE if the verification succeded, FALSE if there was any error. */ BOOL VerifyChecksum(URL &signed_file, const OpStringC8 &checksum, SSL_HashAlgorithmType alg) { if(signed_file.IsEmpty() || (URLStatus) signed_file.GetAttribute(URL::KLoadStatus) != URL_LOADED) return FALSE; // Get The raw data OpAutoPtr<URL_DataDescriptor> desc(signed_file.GetDescriptor(NULL, TRUE, TRUE, TRUE)); if(!desc.get()) return FALSE; BOOL more = FALSE; unsigned long buf_len; if(desc->RetrieveData(more) == 0 || desc->GetBuffer() == NULL) return FALSE; if(desc->GetBufSize() == 0) return FALSE; SSL_Hash_Pointer digester(alg); if(digester.Error()) return FALSE; digester->InitHash(); do { more = FALSE; buf_len = desc->RetrieveData(more); digester->CalculateHash((unsigned char *)desc->GetBuffer(), buf_len); desc->ConsumeData(buf_len); } while(more); SSL_varvector32 signature_out; digester->ExtractHash(signature_out); if(digester->Error() || signature_out.Error()) return FALSE; #ifdef _DEBUG OpString8 s8; OP_STATUS retval = ByteToHexStr(signature_out.GetDirect(), signature_out.GetLength(), s8); OP_ASSERT(retval == OpStatus::OK); #endif byte* byte_buffer = NULL; unsigned int buffer_len = 0; OP_STATUS ret = HexStrToByte(checksum, byte_buffer, buffer_len); if(OpStatus::IsError(ret)) return FALSE; SSL_varvector32 signature_in; signature_in.Set(byte_buffer, buffer_len); OP_DELETEA(byte_buffer); return signature_in == signature_out; }
OP_STATUS ContentBlockFilterCreation::CreateFilterFromURL(URL& homeurl, const uni_char *url, OpString& result) { if(uni_stristr(url, (const char *)"*")) { return result.Set(url); } /* ** Start of code to create patterned URLs to block */ // handle flash: http://flash.vg.no/annonser/startour/startour_restplass.swf const uni_char *swf = NULL; swf = uni_stristr(url, (const char *)"swf"); if(swf == NULL) { swf = url + uni_strlen(url); } if(swf) { while(swf-- != url) { // search back to the last slash if(*swf == '/') { swf++; break; } } if(swf != url) { // we should now have http://flash.vg.no/annonser/startour/* // let's see if we can shorten it down a bit int count = CountCharacters(url, '/', swf - url); if(count > 4) { swf--; // too long path, let's shorten it down to 2 levels (after http://) while(swf-- != url) { // search back to the last slash if(*swf == '/') { if(--count == 4) { swf++; break; } } } } result.Empty(); if(count < 4) { if(OpStatus::IsError(result.Append(url))) { return OpStatus::ERR_NO_MEMORY; } } else { if(OpStatus::IsError(result.Append(url, swf - url))) { return OpStatus::ERR_NO_MEMORY; } } BOOL go_on = TRUE; while(go_on) { OpString homeurl_string; RETURN_IF_ERROR(homeurl.GetAttribute(URL::KUniName_Username_Password_Hidden, homeurl_string)); if(result.Compare(homeurl_string.CStr(), result.Length()) == 0) { BOOL slash_found = FALSE; // matches main page url, we can't have that while(*swf++) { // search back to the last slash if(*swf == '/') { swf++; result.Empty(); if(OpStatus::IsError(result.Append(url, swf - url))) { return OpStatus::ERR_NO_MEMORY; } slash_found = TRUE; break; } } if(!slash_found) { result.Empty(); if(OpStatus::IsError(result.Append(url, swf - url))) { return OpStatus::ERR_NO_MEMORY; } go_on = FALSE; } } else { go_on = FALSE; } } } } if(result[result.Length() - 1] != '*') { result.Append(UNI_L("*")); } return OpStatus::OK; }
OP_STATUS ChatFileTransferManager::AddTransferItem( ChatFileTransfer& chat_transfer, TransferMethod transfer_method, const OpString& file_name, OpFileLength& resume_position) { OP_ASSERT(GetTransferItem(chat_transfer) == 0); OpString file_path_and_name; RETURN_IF_ERROR(file_path_and_name.Set(file_name)); // Fetch some information about the transfer. OpString other_party; OpString protocol_name; RETURN_IF_ERROR(chat_transfer.GetOtherParty(other_party)); RETURN_IF_ERROR(chat_transfer.GetProtocolName(protocol_name)); // Create a somewhat unique url name. OpString unique_url; unique_url.AppendFormat(UNI_L("%s://%s:%s"), protocol_name.CStr(), other_party.CStr(), file_path_and_name.CStr()); URL url = g_url_api->GetURL(unique_url.CStr(), NULL, TRUE); // Create a transfer item and initialize it. OpTransferItem* op_transfer_item = 0; OpString url_with_rel; RETURN_IF_ERROR(url.GetAttribute(URL::KUniName_With_Fragment_Escaped, url_with_rel)); BOOL already_created = FALSE; RETURN_IF_ERROR(g_transferManager->GetTransferItem(&op_transfer_item, url_with_rel.CStr(), &already_created)); if (!already_created) { TransferManager* transfer_manager = (TransferManager *)(g_transferManager); RETURN_IF_ERROR(transfer_manager->AddTransferItem(url, file_path_and_name.CStr(), OpTransferItem::ACTION_UNKNOWN, FALSE, 0, transfer_method == SEND ? TransferItem::TRANSFERTYPE_CHAT_UPLOAD : TransferItem::TRANSFERTYPE_CHAT_DOWNLOAD)); if (file_path_and_name.HasContent()) RETURN_IF_ERROR(op_transfer_item->SetFileName(file_path_and_name.CStr())); } // Add item to internal list of transfer items if needed. INT32 id = GetTransferId(op_transfer_item); if (id == -1) { id = NewTransferId(); RETURN_IF_ERROR(m_transfer_items.Add(id, op_transfer_item)); } chat_transfer.SetTransferId(id); // Initialize the tranfer item. if (transfer_method == SEND) { TransferItem* transfer_item = (TransferItem *)(op_transfer_item); OP_ASSERT(transfer_item != 0); transfer_item->SetType(TransferItem::TRANSFERTYPE_CHAT_UPLOAD); transfer_item->Clear(); transfer_item->SetCompleteSize(OpFileLength(chat_transfer.GetFileSize())); RETURN_IF_ERROR(transfer_item->GetURL()->SetAttribute(URL::KLoadStatus, URL_LOADING_WAITING)); } else if (transfer_method == RECEIVE) { TransferItem* transfer_item = (TransferItem *)(op_transfer_item); OP_ASSERT(transfer_item != 0); transfer_item->SetType(TransferItem::TRANSFERTYPE_CHAT_DOWNLOAD); transfer_item->Clear(); // If the content loaded is equal or higher to the file size, we want // to clear the storage and retransfer. transfer_item->GetURL()->Unload(); RETURN_IF_ERROR(transfer_item->GetURL()->LoadToFile(file_path_and_name.CStr())); OpFileLength content_loaded = transfer_item->GetURL()->GetContentLoaded(); const OpFileLength file_size = chat_transfer.GetFileSize(); if (content_loaded == 0 || content_loaded >= file_size) { transfer_item->GetURL()->Unload(); } else { resume_position = content_loaded; } RETURN_IF_ERROR(transfer_item->GetURL()->SetAttribute(URL::KContentSize, &file_size)); RETURN_IF_ERROR(transfer_item->GetURL()->SetAttribute(URL::KLoadStatus, URL_LOADING_WAITING)); RETURN_IF_ERROR(transfer_item->GetURL()->LoadToFile(file_path_and_name.CStr())); } // Start to listen on the transfer manager if needed. if (!m_is_transfer_manager_listener) { RETURN_IF_ERROR(g_transferManager->AddTransferManagerListener(this)); m_is_transfer_manager_listener = TRUE; } return OpStatus::OK; }
/* virtual */ ES_GetState JS_Location::GetName(OpAtom property_name, ES_Value* value, ES_Runtime* origining_runtime) { TempBuffer *buffer = GetEmptyTempBuf(); URL url; if (fakewindow) url = fakewindow->GetURL(); #ifdef SELFTEST else if (!do_navigation) url = current_url; #endif // SELFTEST else if (FramesDocument *frames_doc = GetFramesDocument()) { url = frames_doc->GetURL(); // The anchors (hash) might be better in DocumentManager URL doc_man_url = frames_doc->GetDocManager()->GetCurrentURL(); if (doc_man_url == url) // Doesn't compare anchors url = doc_man_url; } #ifdef DOM_WEBWORKERS_SUPPORT /* No FramesDocument to query, so consult the origin DocumentManager for the Worker */ if (!GetFramesDocument()) { DOM_WebWorkerController *web_workers = GetEnvironment()->GetWorkerController(); if (DOM_WebWorker *ww = web_workers->GetWorkerObject()) url = ww->GetLocationURL(); else if (DocumentManager *doc = web_workers->GetWorkerDocManager()) url = doc->GetCurrentURL(); OP_ASSERT(!url.IsEmpty()); } #endif // DOM_WEBWORKERS_SUPPORT switch (property_name) { case OP_ATOM_href: DOMSetString(value, url.GetAttribute(URL::KUniName_With_Fragment_Escaped).CStr()); return GET_SUCCESS; case OP_ATOM_protocol: if (value) { const char *protocol = url.GetAttribute(URL::KProtocolName).CStr(); if (protocol) { GET_FAILED_IF_ERROR(buffer->Append(protocol)); GET_FAILED_IF_ERROR(buffer->Append(":")); } DOMSetString(value, buffer); } return GET_SUCCESS; case OP_ATOM_host: case OP_ATOM_hostname: if (value) { const uni_char *name = url.GetServerName() ? url.GetServerName()->UniName() : NULL; if (property_name == OP_ATOM_host) { unsigned short port = url.GetServerPort(); if (port) { GET_FAILED_IF_ERROR(buffer->Append(name)); GET_FAILED_IF_ERROR(buffer->Append(":")); GET_FAILED_IF_ERROR(buffer->AppendUnsignedLong(port)); name = buffer->GetStorage(); } } DOMSetString(value, name); } return GET_SUCCESS; case OP_ATOM_port: if (value) { unsigned short port = url.GetServerPort(); if (port) GET_FAILED_IF_ERROR(buffer->AppendUnsignedLong(port)); DOMSetString(value, buffer); } return GET_SUCCESS; case OP_ATOM_pathname: if (value) { const uni_char *path = url.GetAttribute(URL::KUniPath).CStr(); if (path) { GET_FAILED_IF_ERROR(buffer->Append(path)); uni_char *path_tmp = buffer->GetStorage(); /* It isn't obvious from the JS spec and the relevant RFC, but in Javascript the 'pathname' excludes any arguments passed to the page. */ if (uni_char *query_start = uni_strchr(path_tmp, '?')) { path = path_tmp; *query_start = 0; } } DOMSetString(value, path); } return GET_SUCCESS; case OP_ATOM_search: if (value) { const uni_char *name = url.GetAttribute(URL::KUniName).CStr(); if (name) name = uni_strchr(name, '?'); DOMSetString(value, name); } return GET_SUCCESS; case OP_ATOM_hash: if (value) { const uni_char *fragment = url.UniRelName(); // MSIE emits "#" for the empty fragment (as in http://www.opera.com/# ) but no other // browser does that and neither will we. if (fragment && *fragment) { GET_FAILED_IF_ERROR(buffer->Append('#')); GET_FAILED_IF_ERROR(buffer->Append(fragment)); fragment = buffer->GetStorage(); } DOMSetString(value, fragment); } return GET_SUCCESS; } return GET_FAILED; }
/** Verify signed file * The function will return FALSE if signature fails or if any errors occur, * * @param signed_file URL containing the file to be verified. MUST be loaded, * which can be accomplished with signed_file.QuickLoad(TRUE) * @param signature Base64 encoded signature * * @param key Pointer to buffer containing the DER encoded public key associated * with the private key used to generate the signature, MUST be an * X509_PUBKEY structure (openssl rsa -pubout ... command result) * @param key_len Length of the public key buffer * * @param alg Algorithm used to calculate signature. Default SSL_SHA * * @return TRUE if the verification succeded, FALSE if there was any error. */ BOOL VerifySignedFile(URL &signed_file, const OpStringC8 &signature, const unsigned char *key, unsigned long key_len, SSL_HashAlgorithmType alg) { if(signed_file.IsEmpty() || (URLStatus) signed_file.GetAttribute(URL::KLoadStatus) != URL_LOADED || key == NULL || key_len == 0) return FALSE; // Get The raw data OpAutoPtr<URL_DataDescriptor> desc(signed_file.GetDescriptor(NULL, TRUE, TRUE, TRUE)); if(!desc.get()) return FALSE; BOOL more = FALSE; unsigned long buf_len; if(desc->RetrieveData(more) == 0 || desc->GetBuffer() == NULL) return FALSE; if(desc->GetBufSize() == 0) return FALSE; if(signature.Length() <= 0) return FALSE; unsigned long signature_len = signature.Length(); SSL_varvector32 signature_in; signature_in.Resize(signature_len); if(signature_in.Error()) return FALSE; unsigned long read_len=0; BOOL warning= FALSE; buf_len = GeneralDecodeBase64((unsigned char *)signature.CStr(), signature_len, read_len, signature_in.GetDirect(), warning); if(warning || read_len != signature_len || buf_len == 0) return FALSE; signature_in.Resize(buf_len); SSL_Hash_Pointer digester(alg); if(digester.Error()) return FALSE; digester->InitHash(); do { more = FALSE; buf_len = desc->RetrieveData(more); digester->CalculateHash((unsigned char *)desc->GetBuffer(), buf_len); desc->ConsumeData(buf_len); } while(more); SSL_varvector32 signature_out; digester->ExtractHash(signature_out); if(digester->Error() || signature_out.Error()) return FALSE; OpAutoPtr<SSL_PublicKeyCipher> signature_checker; OP_STATUS op_err = OpStatus::OK; signature_checker.reset(g_ssl_api->CreatePublicKeyCipher(SSL_RSA, op_err)); if(OpStatus::IsError(op_err) || signature_checker.get() == NULL) return FALSE; SSL_varvector32 pubkey_bin_ex; pubkey_bin_ex.SetExternal((unsigned char *) key); pubkey_bin_ex.Resize(key_len); signature_checker->LoadAllKeys(pubkey_bin_ex); if(signature_checker->Error()) return FALSE; if(alg == SSL_SHA) { if(!signature_checker->Verify(signature_out.GetDirect(), signature_out.GetLength(), signature_in.GetDirect(), signature_in.GetLength())) return FALSE; } #ifdef USE_SSL_ASN1_SIGNING else { if(!signature_checker->VerifyASN1(digester, signature_in.GetDirect(), signature_in.GetLength())) return FALSE; } #endif if(signature_checker->Error()) return FALSE; return TRUE; }