Kaydet (Commit) af19a3cc authored tarafından Arkadiy Illarionov's avatar Arkadiy Illarionov Kaydeden (comit) Stephan Bergmann

Resolves: tdf#122114 remove support for ~/.recently-used file

Change-Id: Ie91f0bf21e6f5c3f7a7aa4ae3d1dff6cc8e15a86
Reviewed-on: https://gerrit.libreoffice.org/69597
Tested-by: Jenkins
Reviewed-by: 's avatarStephan Bergmann <sbergman@redhat.com>
üst 87f262da
......@@ -622,7 +622,6 @@ $(eval $(call gb_Helper_register_libraries_for_install,PLAINLIBS_OOO,ooo, \
) \
emboleobj \
package2 \
$(if $(USING_X11),recentfile) \
$(call gb_Helper_optional,SCRIPTING,scriptframe) \
sdbc2 \
sofficeapp \
......
......@@ -240,7 +240,6 @@ merge frm::ITextSelectionListener with frm::ORichTextPeer
merge frm::OFormComponents with frm::ODatabaseForm
merge ftp::CurlInput with InsertData
merge gio::Seekable with gio::OutputStream
merge i_xml_parser_event_handler with (anonymous namespace)::recently_used_file_filter
merge oglcanvas::IBufferContext with oglcanvas::(anonymous namespace)::BufferContextImpl
merge old_SdrDownCompat with SdIOCompat
merge oox::SequenceSeekableStream with oox::SequenceInputStream
......
......@@ -109,12 +109,6 @@ bool StaticMethods::TraverseCXXMethodDecl(const CXXMethodDecl * pCXXMethodDecl)
if (cdc.Class("BitmapInfoAccess").GlobalNamespace()) {
return true;
}
// in this case, the code is taking the address of the member function
// shell/source/unix/sysshell/recently_used_file_handler.cxx
if (cdc.Struct("recently_used_item").AnonymousNamespace().GlobalNamespace())
{
return true;
}
// the unotools and svl config code stuff is doing weird stuff with a reference-counted statically allocated pImpl class
if (loplugin::hasPathnamePrefix(aFilename, SRCDIR "/include/unotools/")) {
return true;
......
......@@ -171,10 +171,6 @@ bool ConstantFunction::VisitFunctionDecl(const FunctionDecl * pFunctionDecl) {
if (aFunctionName == "osl_thread_priority_init_Impl") {
return true;
}
// a pointer to this function is taken and passed to an underlying API, shell/source/unix/sysshell/recently_used_file_handler.cxx
if (aFunctionName == "(anonymous namespace)::recently_used_item::set_nothing") {
return true;
}
// a pointer to this function is taken and passed to an underlying API, cppu/source/uno/lbenv.cxx
if (aFunctionName == "defenv_dispose") {
return true;
......
# -*- Mode: makefile-gmake; tab-width: 4; indent-tabs-mode: t -*-
#
# This file is part of the LibreOffice project.
#
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
#
$(eval $(call gb_Library_Library,recentfile))
$(eval $(call gb_Library_set_include,recentfile,\
-I$(SRCDIR)/shell/inc \
$$(INCLUDE) \
))
$(eval $(call gb_Library_use_externals,recentfile,\
boost_headers \
expat \
))
$(eval $(call gb_Library_use_libraries,recentfile,\
sal \
))
$(eval $(call gb_Library_use_static_libraries,recentfile,\
shell_xmlparser \
))
$(eval $(call gb_Library_add_exception_objects,recentfile,\
shell/source/unix/sysshell/recently_used_file \
shell/source/unix/sysshell/recently_used_file_handler \
))
# vim: set shiftwidth=4 tabstop=4 noexpandtab:
......@@ -91,12 +91,6 @@ $(eval $(call gb_Module_add_targets,shell,\
Library_syssh \
))
ifeq ($(USING_X11),TRUE)
$(eval $(call gb_Module_add_targets,shell,\
Library_recentfile \
))
endif
ifneq ($(OS),WNT)
$(eval $(call gb_Module_add_targets,shell,\
......
System helpers - launching URI, recently used files, system integration, external mailer support etc.
System helpers - launching URI, system integration, external mailer support etc.
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
* This file is part of the LibreOffice project.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*
* This file incorporates work covered by the following license notice:
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed
* with this work for additional information regarding copyright
* ownership. The ASF licenses this file to you under the Apache
* License, Version 2.0 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/
#include "recently_used_file.hxx"
#include <rtl/ustring.hxx>
#include <sal/log.hxx>
#include <osl/process.h>
#include <osl/security.hxx>
#include <osl/thread.h>
#include <osl/file.hxx>
#include <sys/file.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
const char SLASH[] = "/";
namespace {
void ensure_final_slash(/*inout*/ OUString& path)
{
if (!path.isEmpty() &&
(SLASH[0] != path.pData->buffer[path.getLength() - 1]))
path += SLASH;
}
} // namespace private
recently_used_file::recently_used_file() :
file_(nullptr)
{
osl::Security sec;
OUString homedir_url;
if (!sec.getHomeDir(homedir_url))
throw "Cannot determine user home directory";
OUString homedir;
osl::FileBase::getSystemPathFromFileURL(homedir_url, homedir);
OUString rufn = homedir;
ensure_final_slash(rufn);
rufn += ".recently-used";
OString tmp =
OUStringToOString(rufn, osl_getThreadTextEncoding());
int fd = open(tmp.getStr(), O_RDWR | O_CREAT, S_IRUSR | S_IWUSR);
if (fd != -1) {
file_ = fdopen(fd, "w+");
if (file_ == nullptr) {
close(fd);
}
}
if (nullptr == file_)
throw "I/O error opening ~/.recently-used";
if (lockf(fileno(file_), F_LOCK, 0) != 0)
{
fclose(file_);
throw "Cannot lock ~/.recently-used";
}
}
recently_used_file::~recently_used_file()
{
int ret = lockf(fileno(file_), F_ULOCK, 0);
SAL_WARN_IF(ret != 0, "shell", "cannot unlock recently unused file");
fclose(file_);
}
void recently_used_file::reset() const
{
rewind(file_);
}
void recently_used_file::truncate()
{
if (ftruncate(fileno(file_), 0) == -1)
throw "I/O error: ftruncate failed";
}
size_t recently_used_file::read(char* buffer, size_t size) const
{
size_t r = fread(buffer, sizeof(char), size, file_);
if ((r < size) && ferror(file_))
throw "I/O error: read failed";
return r;
}
void recently_used_file::write(const char* buffer, size_t size) const
{
if (size != fwrite(buffer, sizeof(char), size, file_))
throw "I/O error: write failed";
}
bool recently_used_file::eof() const
{
return feof(file_);
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
* This file is part of the LibreOffice project.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*
* This file incorporates work covered by the following license notice:
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed
* with this work for additional information regarding copyright
* ownership. The ASF licenses this file to you under the Apache
* License, Version 2.0 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/
#ifndef INCLUDED_SHELL_SOURCE_UNIX_SYSSHELL_RECENTLY_USED_FILE_HXX
#define INCLUDED_SHELL_SOURCE_UNIX_SYSSHELL_RECENTLY_USED_FILE_HXX
#include <stdio.h>
#include <unistd.h>
// simple wrapper around the recently_used_file
class recently_used_file
{
public:
recently_used_file();
~recently_used_file();
// set file pointer to the start of file
void reset() const;
void truncate();
size_t read(
char* buffer,
size_t size) const;
void write(const char* buffer, size_t size) const;
bool eof() const;
private:
FILE* file_;
};
#endif // INCLUDED_SHELL_SOURCE_UNIX_SYSSHELL_RECENTLY_USED_FILE_HXX
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
* This file is part of the LibreOffice project.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*
* This file incorporates work covered by the following license notice:
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed
* with this work for additional information regarding copyright
* ownership. The ASF licenses this file to you under the Apache
* License, Version 2.0 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/
#include <sal/config.h>
#include <osl/process.h>
#include <rtl/ustring.hxx>
#include <rtl/string.hxx>
#include <rtl/strbuf.hxx>
#include <osl/thread.h>
#include <osl/diagnose.h>
#include "recently_used_file.hxx"
#include <xml_parser.hxx>
#include <i_xml_parser_event_handler.hxx>
#include <map>
#include <memory>
#include <vector>
#include <algorithm>
#include <string.h>
#include <time.h>
namespace /* private */ {
#define TAG_RECENT_FILES "RecentFiles"
#define TAG_RECENT_ITEM "RecentItem"
#define TAG_URI "URI"
#define TAG_MIME_TYPE "Mime-Type"
#define TAG_TIMESTAMP "Timestamp"
#define TAG_PRIVATE "Private"
#define TAG_GROUPS "Groups"
#define TAG_GROUP "Group"
struct recently_used_item
{
recently_used_item()
: timestamp_(-1)
, is_private_(false)
{}
recently_used_item(
const string_t& uri,
const string_t& mime_type,
const std::vector<string_t>& groups) :
uri_(uri),
mime_type_(mime_type),
is_private_(false),
groups_(groups)
{
timestamp_ = time(nullptr);
}
void set_uri(const string_t& character)
{ uri_ = character; }
void set_mime_type(const string_t& character)
{ mime_type_ = character; }
void set_timestamp(const string_t& character)
{
long t;
if (sscanf(character.c_str(), "%ld", &t) != 1)
timestamp_ = -1;
else
timestamp_ = static_cast<time_t>(t);
}
void set_is_private(SAL_UNUSED_PARAMETER const string_t& /*character*/)
{ is_private_ = true; }
void set_groups(const string_t& character)
{ groups_.push_back(character); }
void set_nothing(SAL_UNUSED_PARAMETER const string_t& /*character*/)
{}
bool has_groups() const
{
return !groups_.empty();
}
bool has_group(const string_t& name) const
{
return (has_groups() &&
std::any_of(groups_.cbegin(), groups_.cend(),
[&name](const string_t& s)
{ return (0 == strcasecmp(s.c_str(), name.c_str())); })
// compare two string_t's case insensitive
);
}
void write_xml(const recently_used_file& file) const
{
write_xml_start_tag(TAG_RECENT_ITEM, file, true);
write_xml_tag(TAG_URI, uri_, file);
write_xml_tag(TAG_MIME_TYPE, mime_type_, file);
OString ts = OString::number(timestamp_);
write_xml_tag(TAG_TIMESTAMP, ts.getStr(), file);
if (is_private_)
write_xml_tag(TAG_PRIVATE, file);
if (has_groups())
{
write_xml_start_tag(TAG_GROUPS, file, true);
for (auto& group : groups_)
write_xml_tag(TAG_GROUP, group, file);
write_xml_end_tag(TAG_GROUPS, file);
}
write_xml_end_tag(TAG_RECENT_ITEM, file);
}
static OString escape_content(const string_t &text)
{
OStringBuffer aBuf;
for (auto i : text)
{
switch (i)
{
case '&': aBuf.append("&amp;"); break;
case '<': aBuf.append("&lt;"); break;
case '>': aBuf.append("&gt;"); break;
case '\'': aBuf.append("&apos;"); break;
case '"': aBuf.append("&quot;"); break;
default: aBuf.append(i); break;
}
}
return aBuf.makeStringAndClear();
}
void write_xml_tag(const string_t& name, const string_t& value, const recently_used_file& file) const
{
write_xml_start_tag(name, file, false);
OString escaped = escape_content (value);
file.write(escaped.getStr(), escaped.getLength());
write_xml_end_tag(name, file);
}
void write_xml_tag(const string_t& name, const recently_used_file& file) const
{
file.write("<", 1);
file.write(name.c_str(), name.length());
file.write("/>\n", 3);
}
void write_xml_start_tag(const string_t& name, const recently_used_file& file, bool linefeed) const
{
file.write("<", 1);
file.write(name.c_str(), name.length());
if (linefeed)
file.write(">\n", 2);
else
file.write(">", 1);
}
void write_xml_end_tag(const string_t& name, const recently_used_file& file) const
{
file.write("</", 2);
file.write(name.c_str(), name.length());
file.write(">\n", 2);
}
string_t uri_;
string_t mime_type_;
time_t timestamp_;
bool is_private_;
std::vector<string_t> groups_;
};
typedef std::vector<std::unique_ptr<recently_used_item>> recently_used_item_list_t;
typedef void (recently_used_item::* SET_COMMAND)(const string_t&);
// thrown if we encounter xml tags that we do not know
class unknown_xml_format_exception {};
class recently_used_file_filter:
public i_xml_parser_event_handler
{
public:
explicit recently_used_file_filter(recently_used_item_list_t& item_list) :
item_list_(item_list)
{
named_command_map_[TAG_RECENT_FILES] = &recently_used_item::set_nothing;
named_command_map_[TAG_RECENT_ITEM] = &recently_used_item::set_nothing;
named_command_map_[TAG_URI] = &recently_used_item::set_uri;
named_command_map_[TAG_MIME_TYPE] = &recently_used_item::set_mime_type;
named_command_map_[TAG_TIMESTAMP] = &recently_used_item::set_timestamp;
named_command_map_[TAG_PRIVATE] = &recently_used_item::set_is_private;
named_command_map_[TAG_GROUPS] = &recently_used_item::set_nothing;
named_command_map_[TAG_GROUP] = &recently_used_item::set_groups;
}
recently_used_file_filter(const recently_used_file_filter&) = delete;
recently_used_file_filter& operator=(const recently_used_file_filter&) = delete;
virtual void start_element(
const string_t& /*raw_name*/,
const string_t& local_name,
const xml_tag_attribute_container_t& /*attributes*/) override
{
if ((local_name == TAG_RECENT_ITEM) && (nullptr == item_))
item_.reset(new recently_used_item);
}
virtual void end_element(const string_t& /*raw_name*/, const string_t& local_name) override
{
// check for end tags w/o start tag
if( local_name != TAG_RECENT_FILES && nullptr == item_ )
return; // will result in an XML parser error anyway
if (named_command_map_.find(local_name) != named_command_map_.end())
(item_.get()->*named_command_map_[local_name])(current_element_);
else
{
item_.reset();
throw unknown_xml_format_exception();
}
if (local_name == TAG_RECENT_ITEM)
{
item_list_.push_back(std::move(item_));
}
current_element_.clear();
}
virtual void characters(const string_t& character) override
{
if (character != "\n")
current_element_ += character;
}
virtual void ignore_whitespace(const string_t& /*whitespaces*/) override
{}
virtual void comment(const string_t& /*comment*/) override
{}
private:
std::unique_ptr<recently_used_item> item_;
std::map<string_t, SET_COMMAND> named_command_map_;
string_t current_element_;
recently_used_item_list_t& item_list_;
};
void read_recently_used_items(
recently_used_file const & file,
recently_used_item_list_t& item_list)
{
xml_parser xparser;
recently_used_file_filter ruff(item_list);
xparser.set_document_handler(&ruff);
char buff[16384];
while (!file.eof())
{
if (size_t length = file.read(buff, sizeof(buff)))
xparser.parse(buff, length, file.eof());
}
}
// The file ~/.recently_used shall not contain more than 500
// entries (see www.freedesktop.org)
const int MAX_RECENTLY_USED_ITEMS = 500;
class recent_item_writer
{
public:
explicit recent_item_writer( recently_used_file& file ) :
file_(file),
items_written_(0)
{}
void operator() (const std::unique_ptr<recently_used_item> & item)
{
if (items_written_++ < MAX_RECENTLY_USED_ITEMS)
item->write_xml(file_);
}
private:
recently_used_file& file_;
int items_written_;
};
const char* const XML_HEADER = "<?xml version=\"1.0\"?>\n<RecentFiles>\n";
const char* const XML_FOOTER = "</RecentFiles>";
// assumes that the list is ordered decreasing
void write_recently_used_items(
recently_used_file& file,
recently_used_item_list_t& item_list)
{
if (item_list.empty())
return;
file.truncate();
file.reset();
file.write(XML_HEADER, strlen(XML_HEADER));
std::for_each(
item_list.begin(),
item_list.end(),
recent_item_writer(file));
file.write(XML_FOOTER, strlen(XML_FOOTER));
}
class find_item_predicate
{
public:
explicit find_item_predicate(const string_t& uri) :
uri_(uri)
{}
bool operator() (const std::unique_ptr<recently_used_item> & item) const
{ return (item->uri_ == uri_); }
private:
string_t const uri_;
};
struct greater_recently_used_item
{
bool operator ()(const std::unique_ptr<recently_used_item> & lhs, const std::unique_ptr<recently_used_item> & rhs) const
{ return (lhs->timestamp_ > rhs->timestamp_); }
};
const char* const GROUP_OOO = "openoffice.org";
const char* const GROUP_STAR_OFFICE = "staroffice";
const char* const GROUP_STAR_SUITE = "starsuite";
void recently_used_item_list_add(
recently_used_item_list_t& item_list, const OUString& file_url, const OUString& mime_type)
{
OString f = OUStringToOString(file_url, RTL_TEXTENCODING_UTF8);
recently_used_item_list_t::iterator iter =
std::find_if(
item_list.begin(),
item_list.end(),
find_item_predicate(f.getStr()));
if (iter != item_list.end())
{
(*iter)->timestamp_ = time(nullptr);
if (!(*iter)->has_group(GROUP_OOO))
(*iter)->groups_.push_back(GROUP_OOO);
if (!(*iter)->has_group(GROUP_STAR_OFFICE))
(*iter)->groups_.push_back(GROUP_STAR_OFFICE);
if (!(*iter)->has_group(GROUP_STAR_SUITE))
(*iter)->groups_.push_back(GROUP_STAR_SUITE);
}
else
{
std::vector<string_t> groups;
groups.push_back(GROUP_OOO);
groups.push_back(GROUP_STAR_OFFICE);
groups.push_back(GROUP_STAR_SUITE);
string_t uri(f.getStr());
string_t mimetype(OUStringToOString(mime_type, osl_getThreadTextEncoding()).getStr());
if (mimetype.length() == 0)
mimetype = "application/octet-stream";
item_list.emplace_back(new recently_used_item(uri, mimetype, groups));
}
// sort decreasing after the timestamp
// so that the newest items appear first
std::sort(
item_list.begin(),
item_list.end(),
greater_recently_used_item());
}
struct cleanup_guard
{
explicit cleanup_guard(recently_used_item_list_t& item_list) :
item_list_(item_list)
{}
~cleanup_guard()
{ item_list_.clear(); }
recently_used_item_list_t& item_list_;
};
} // namespace private
/*
example (see http::www.freedesktop.org):
<?xml version="1.0"?>
<RecentFiles>
<RecentItem>
<URI>file:///home/federico/gedit.txt</URI>
<Mime-Type>text/plain</Mime-Type>
<Timestamp>1046485966</Timestamp>
<Groups>
<Group>gedit</Group>
</Groups>
</RecentItem>
<RecentItem>
<URI>file:///home/federico/gedit-2.2.0.tar.bz2</URI>
<Mime-Type>application/x-bzip</Mime-Type>
<Timestamp>1046209851</Timestamp>
<Private/>
<Groups>
</Groups>
</RecentItem>
</RecentFiles>
*/
extern "C" SAL_DLLPUBLIC_EXPORT
void add_to_recently_used_file_list(const OUString& file_url,
const OUString& mime_type)
{
try
{
recently_used_file ruf;
recently_used_item_list_t item_list;
cleanup_guard guard(item_list);
read_recently_used_items(ruf, item_list);
recently_used_item_list_add(item_list, file_url, mime_type);
write_recently_used_items(ruf, item_list);
}
catch(const char* ex)
{
OSL_FAIL(ex);
}
catch(const xml_parser_exception&)
{
OSL_FAIL("XML parser error");
}
catch(const unknown_xml_format_exception&)
{
OSL_FAIL("XML format unknown");
}
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
......@@ -12977,9 +12977,6 @@ shell/source/unix/exec/shellexec.cxx
shell/source/unix/exec/shellexec.hxx
shell/source/unix/exec/shellexecentry.cxx
shell/source/unix/misc/uri-encode.c
shell/source/unix/sysshell/recently_used_file.cxx
shell/source/unix/sysshell/recently_used_file.hxx
shell/source/unix/sysshell/recently_used_file_handler.cxx
shell/source/win32/SysShExec.cxx
shell/source/win32/SysShExec.hxx
shell/source/win32/SysShentry.cxx
......
......@@ -118,7 +118,6 @@ profile libreoffice-soffice INSTDIR-program/soffice.bin {
owner @{HOME}/.config/soffice.binrc.lock rwk,
owner @{HOME}/.cache/fontconfig/** rw,
owner @{HOME}/.config/gtk-???/bookmarks r, #Make bookmarks work
owner @{HOME}/.recently-used rwk,
owner /tmp/psp[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]* rw, #/tmp/psp1534203998 (printing to file)
owner /{,var/}run/user/*/dconf/user rw,
......
......@@ -206,21 +206,7 @@ void X11SalInstance::AfterAppInit()
pSalDisplay->SetupInput();
}
extern "C" { static void thisModule() {} }
void X11SalInstance::AddToRecentDocumentList(const OUString& rFileUrl, const OUString& rMimeType, const OUString& rDocumentService)
{
typedef void (*PFUNC_ADD_TO_RECENTLY_USED_LIST)(const OUString&, const OUString&, const OUString&);
PFUNC_ADD_TO_RECENTLY_USED_LIST add_to_recently_used_file_list = nullptr;
osl::Module module;
module.loadRelative( &thisModule, "librecentfile.so" );
if (module.is())
add_to_recently_used_file_list = reinterpret_cast<PFUNC_ADD_TO_RECENTLY_USED_LIST>(module.getFunctionSymbol("add_to_recently_used_file_list"));
if (add_to_recently_used_file_list)
add_to_recently_used_file_list(rFileUrl, rMimeType, rDocumentService);
}
void X11SalInstance::AddToRecentDocumentList(const OUString&, const OUString&, const OUString&) {}
void X11SalInstance::PostPrintersChanged()
{
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment