|
|
|
@ -39,6 +39,8 @@
|
|
|
|
|
#include <sys/types.h> |
|
|
|
|
|
|
|
|
|
#include <ctime> |
|
|
|
|
#include <regex> |
|
|
|
|
|
|
|
|
|
#include <rak/algorithm.h> |
|
|
|
|
#include <rak/functional.h> |
|
|
|
|
#include <rak/functional_fun.h> |
|
|
|
@ -369,6 +371,53 @@ apply_compare(rpc::target_type target, const torrent::Object::list_type& args) {
|
|
|
|
|
return (int64_t) (target.second < target.third); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// Regexp based 'match' function.
|
|
|
|
|
// arg1: the text to match.
|
|
|
|
|
// arg2: the regexp pattern.
|
|
|
|
|
// eg: match{d.name=,.*linux.*iso}
|
|
|
|
|
torrent::Object apply_match(rpc::target_type target, const torrent::Object::list_type& args) { |
|
|
|
|
if (args.size() != 2) |
|
|
|
|
throw torrent::input_error("Wrong argument count for 'match': 2 arguments needed."); |
|
|
|
|
|
|
|
|
|
// This really should be converted to using args flagged as
|
|
|
|
|
// commands, so that we can compare commands and statics values.
|
|
|
|
|
|
|
|
|
|
torrent::Object result1; |
|
|
|
|
torrent::Object result2; |
|
|
|
|
|
|
|
|
|
rpc::target_type target1 = rpc::is_target_pair(target) ? rpc::get_target_left(target) : target; |
|
|
|
|
rpc::target_type target2 = rpc::is_target_pair(target) ? rpc::get_target_right(target) : target; |
|
|
|
|
|
|
|
|
|
if (args.front().is_dict_key()) |
|
|
|
|
result1 = rpc::commands.call_command(args.front().as_dict_key().c_str(), args.front().as_dict_obj(), target1); |
|
|
|
|
else |
|
|
|
|
result1 = rpc::parse_command_single(target1, args.front().as_string()); |
|
|
|
|
|
|
|
|
|
if (args.back().is_dict_key()) |
|
|
|
|
result2 = rpc::commands.call_command(args.back().as_dict_key().c_str(), args.back().as_dict_obj(), target2); |
|
|
|
|
else |
|
|
|
|
result2 = args.back().as_string(); |
|
|
|
|
|
|
|
|
|
if (result1.type() != result2.type()) |
|
|
|
|
throw torrent::input_error("Type mismatch for 'match' arguments."); |
|
|
|
|
|
|
|
|
|
std::string text = result1.as_string(); |
|
|
|
|
std::string pattern = result2.as_string(); |
|
|
|
|
|
|
|
|
|
std::transform(text.begin(), text.end(), text.begin(), ::tolower); |
|
|
|
|
std::transform(pattern.begin(), pattern.end(), pattern.begin(), ::tolower); |
|
|
|
|
|
|
|
|
|
bool isAMatch = false; |
|
|
|
|
try { |
|
|
|
|
std::regex re(pattern); |
|
|
|
|
isAMatch = std::regex_match(text, re); |
|
|
|
|
} catch (const std::regex_error& exc) { |
|
|
|
|
control->core()->push_log_std("regex_error: " + std::string(exc.what())); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
return isAMatch ? (int64_t)true : (int64_t)false; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
torrent::Object |
|
|
|
|
apply_to_time(const torrent::Object& rawArgs, int flags) { |
|
|
|
|
std::tm *u; |
|
|
|
@ -737,8 +786,11 @@ initialize_command_ui() {
|
|
|
|
|
CMD2_ANY_L ("view.list", std::bind(&apply_view_list)); |
|
|
|
|
CMD2_ANY_LIST("view.set", std::bind(&apply_view_set, std::placeholders::_2)); |
|
|
|
|
|
|
|
|
|
CMD2_ANY_LIST("view.filter", std::bind(&apply_view_event, &core::ViewManager::set_filter, std::placeholders::_2)); |
|
|
|
|
CMD2_ANY_LIST("view.filter_on", std::bind(&apply_view_filter_on, std::placeholders::_2)); |
|
|
|
|
CMD2_ANY_LIST ("view.filter", std::bind(&apply_view_event, &core::ViewManager::set_filter, std::placeholders::_2)); |
|
|
|
|
CMD2_ANY_LIST ("view.filter_on", std::bind(&apply_view_filter_on, std::placeholders::_2)); |
|
|
|
|
CMD2_ANY_LIST ("view.filter.temp", std::bind(&apply_view_event, &core::ViewManager::set_filter_temp, std::placeholders::_2)); |
|
|
|
|
CMD2_VAR_STRING("view.filter.temp.excluded", "default,started,stopped"); |
|
|
|
|
CMD2_VAR_BOOL ("view.filter.temp.log", 0); |
|
|
|
|
|
|
|
|
|
CMD2_ANY_LIST("view.sort", std::bind(&apply_view_sort, std::placeholders::_2)); |
|
|
|
|
CMD2_ANY_LIST("view.sort_new", std::bind(&apply_view_event, &core::ViewManager::set_sort_new, std::placeholders::_2)); |
|
|
|
@ -794,6 +846,7 @@ initialize_command_ui() {
|
|
|
|
|
CMD2_ANY_LIST("greater", &apply_greater); |
|
|
|
|
CMD2_ANY_LIST("equal", &apply_equal); |
|
|
|
|
CMD2_ANY_LIST("compare", &apply_compare); |
|
|
|
|
CMD2_ANY_LIST("match", &apply_match); |
|
|
|
|
|
|
|
|
|
CMD2_ANY_VALUE("convert.gm_time", std::bind(&apply_to_time, std::placeholders::_2, 0)); |
|
|
|
|
CMD2_ANY_VALUE("convert.gm_date", std::bind(&apply_to_time, std::placeholders::_2, 0x2)); |
|
|
|
|