-
Notifications
You must be signed in to change notification settings - Fork 90
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
hack to handle incoming files which come as an absolute path #255
Open
dexterlb
wants to merge
8
commits into
SpectrumIM:master
Choose a base branch
from
dexterlb:absolute_path_hack
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
e4b3454
hack to handle incoming files which come as an absolute path
dexterlb 4985b6c
Merge branch 'master' into absolute_path_hack
dexterlb 28b481a
Merge branch 'master' of github.com:SpectrumIM/spectrum2 into absolut…
dexterlb 2a16c55
Merge branch 'master' into absolute_path_hack
dexterlb 55a9c86
Merge branch 'master' of github.com:SpectrumIM/spectrum2 into absolut…
dexterlb 5cc7275
Merge branch 'master' of github.com:SpectrumIM/spectrum2 into absolut…
dexterlb b70e97f
fix weird characters in URLs of uploaded files
dexterlb 1fc7ec0
fix broken file extensions when uploading file via libpurple
dexterlb File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -27,6 +27,8 @@ | |
#include <boost/locale.hpp> | ||
#include <boost/locale/conversion.hpp> | ||
#include <boost/thread/mutex.hpp> | ||
#include <boost/regex.hpp> | ||
#include <boost/filesystem.hpp> | ||
|
||
#ifdef WITH_LIBEVENT | ||
#include <event.h> | ||
|
@@ -1268,22 +1270,80 @@ static char *calculate_data_hash(guchar *data, size_t len, | |
return g_strdup(digest); | ||
} | ||
|
||
static std::string check_incoming_document(const char *msg) { | ||
/* | ||
Sometimes, when a user sends a file, we receive a link with an absolute | ||
path to the saved file in the backend's directory. This is a hack | ||
which matches those links, moves the file to the web directory | ||
and sends a proper link to the user. | ||
|
||
This has to be fixed in the backend. | ||
*/ | ||
if (strstr(msg, "[document") == NULL) { | ||
return ""; | ||
} | ||
|
||
static boost::regex document_expr("\[[a-z]+ <a href=[\"']file:///([^\"']+/download_([0-9]+)[^\"']+)[\"']>(.*)</a>[ ]*(.*)]"); | ||
boost::smatch match; | ||
std::string plain; | ||
|
||
if (!boost::regex_search(std::string(msg), match, document_expr)) { | ||
return ""; | ||
} | ||
|
||
std::string target_dir = CONFIG_STRING(config, "service.web_directory"); | ||
std::string local_file = match[1]; | ||
std::string hash = match[2]; | ||
std::string basename = match[3]; | ||
std::string file_type = match[4]; | ||
|
||
static boost::regex bad_symbol_expr("[^0-9a-zA-Z._]"); | ||
basename = boost::regex_replace(basename, bad_symbol_expr, "_"); | ||
|
||
if (!target_dir.empty()) { | ||
target_dir += "/" + hash; // todo: escape | ||
std::string target_file = target_dir + "/" + basename; | ||
std::string link = CONFIG_STRING(config, "service.web_url") + "/" + hash + "/" + basename; | ||
|
||
boost::filesystem::create_directories( | ||
boost::filesystem::path(target_dir) | ||
); | ||
|
||
boost::filesystem::rename( | ||
boost::filesystem::path(local_file), | ||
boost::filesystem::path(target_file) | ||
); | ||
|
||
plain | ||
= std::string("file ") | ||
+ "\"" + basename + "\"" | ||
+ " of type [" | ||
+ file_type | ||
+ "]: " | ||
+ link; | ||
} else { | ||
plain = "[received a file]"; | ||
} | ||
|
||
return plain; | ||
} | ||
|
||
static void conv_write_im(PurpleConversation *conv, const char *who, const char *msg, PurpleMessageFlags flags, time_t mtime) { | ||
LOG4CXX_INFO(logger, "conv_write_im()"); | ||
bool isCarbon = false; | ||
|
||
if (purple_conversation_get_type_wrapped(conv) == PURPLE_CONV_TYPE_IM) { | ||
//Don't forwards our own messages, but do forward messages "from=us" which originated elsewhere | ||
//(such as carbons of our messages from other legacy network clients) | ||
if (flags & PURPLE_MESSAGE_SPECTRUM2_ORIGINATED) { | ||
LOG4CXX_INFO(logger, "conv_write_im(): ignoring a message generated by us"); | ||
return; | ||
} | ||
|
||
//If this is a carbon of a message from us, mark it as such | ||
if(flags & PURPLE_MESSAGE_SEND) | ||
isCarbon = true; | ||
|
||
//Originally the transport had this filter too, I'm leaving it in for now: | ||
if (flags & PURPLE_MESSAGE_SYSTEM) { | ||
LOG4CXX_INFO(logger, "conv_write_im(): ignoring a system message"); | ||
|
@@ -1360,15 +1420,26 @@ static void conv_write_im(PurpleConversation *conv, const char *who, const char | |
g_free(strip); | ||
} | ||
else { | ||
// Escape HTML characters. | ||
char *newline = purple_strdup_withhtml_wrapped(msg); | ||
char *strip, *xhtml; | ||
purple_markup_html_to_xhtml_wrapped(newline, &xhtml, &strip); | ||
message_ = strip; | ||
xhtml_ = xhtml; | ||
g_free(newline); | ||
g_free(xhtml); | ||
g_free(strip); | ||
std::string file_link = check_incoming_document(msg); | ||
|
||
if (!file_link.empty()) { | ||
char *strip, *xhtml; | ||
purple_markup_html_to_xhtml_wrapped(file_link.c_str(), &xhtml, &strip); | ||
message_ = strip; | ||
xhtml_ = xhtml; | ||
g_free(xhtml); | ||
g_free(strip); | ||
} else { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add a line break:
|
||
// Escape HTML characters. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This whole section is not properly indented? |
||
char *newline = purple_strdup_withhtml_wrapped(msg); | ||
char *strip, *xhtml; | ||
purple_markup_html_to_xhtml_wrapped(newline, &xhtml, &strip); | ||
message_ = strip; | ||
xhtml_ = xhtml; | ||
g_free(newline); | ||
g_free(xhtml); | ||
g_free(strip); | ||
} | ||
} | ||
|
||
// AIM and XMPP adds <body>...</body> here... | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please remove newline