From f92f202c2e641551fb85ecf07459b7803b40a8a8 Mon Sep 17 00:00:00 2001 From: Kostyantyn Ovechko Date: Sat, 7 Aug 2010 19:47:16 +0300 Subject: Add RSS feed to seggetd PROVIDE_MIRROR_TO_OTHERS_URL Specify url to the provided mirror. This option is used to generate rss feed. By default UI_IP is used for this. Default: provide_mirror_to_others_url=ui_ip [rss] RSS feed provides information on the files added (symlinked) to PROVIDE_MIRROR_DIR and can be accessed from feedreader via http://ui_ip:ui_port/rss.xml RSS_TITLE Specify a title for the RSS feed Default: rss_title=Seggetd feed RSS_DESCRIPTION Specify description for the RSS feed Default: rss_description=Files downloaded by seggetd and provided in the local mirror --- segget/distfile.cpp | 2 ++ segget/log.cpp | 30 +++++++++++++++--- segget/log.h | 5 +++ segget/segget.conf | 25 +++++++++++++++ segget/settings.cpp | 8 +++++ segget/settings.h | 8 +++++ segget/ui_server.cpp | 88 +++++++++++++++++++++++++++++++++++++++++++++++++++- segget/ui_server.h | 1 + 8 files changed, 162 insertions(+), 5 deletions(-) diff --git a/segget/distfile.cpp b/segget/distfile.cpp index 5f5c525..552e1ef 100644 --- a/segget/distfile.cpp +++ b/segget/distfile.cpp @@ -803,6 +803,7 @@ void Tdistfile::symlink_distfile_to_provide_mirror_dir(){ char current_path[FILENAME_MAX]; if (!GetCurrentDir(current_path, sizeof(current_path))) { + error_log("Error in distfile.cpp: symlink_distile_to_provide_mirror_dir(): can't get current dir"); return; } if (settings.distfiles_dir.find("./",0)==0){ @@ -815,6 +816,7 @@ void Tdistfile::symlink_distfile_to_provide_mirror_dir(){ try{ if (!symlink(old_distfile_name.c_str(), new_mirror_name.c_str())){ log("Distfile:"+old_distfile_path+" was symlinked to the mirror dir:"); + rss_log(name,size); }; }catch(uint errno){ switch (errno){ diff --git a/segget/log.cpp b/segget/log.cpp index 9c62719..b1a3648 100644 --- a/segget/log.cpp +++ b/segget/log.cpp @@ -26,6 +26,9 @@ #include "log.h" +vector rss_distfile_lines; +vector rss_size_lines; +vector rss_time_lines; vector log_lines; vector error_log_lines; @@ -70,14 +73,32 @@ void log_no_msg(string log_msg_text){ } } +void rss_log(string distfile_name, ulong distfile_size){ +// save to file here +// log_no_msg(log_msg_text); + try{ + rss_distfile_lines.push_back(distfile_name); + rss_size_lines.push_back(distfile_size); + rss_time_lines.push_back(get_time(settings.general_log_time_format)); + if (rss_distfile_lines.size()>LOG_LINES_MAX_NUM){ + rss_distfile_lines.erase(rss_distfile_lines.begin(),rss_distfile_lines.begin()+rss_distfile_lines.size()-LOG_LINES_MAX_NUM); + rss_size_lines.erase(rss_size_lines.begin(),rss_size_lines.begin()+rss_size_lines.size()-LOG_LINES_MAX_NUM); + rss_time_lines.erase(rss_time_lines.begin(),rss_time_lines.begin()+rss_time_lines.size()-LOG_LINES_MAX_NUM); + } + }catch(...){ + error_log("Error in log.cpp: rss_log()"); + } +} + void log(string log_msg_text){ log_no_msg(log_msg_text); try{ - log_lines.push_back(log_msg_text); + string time_str=get_time(settings.general_log_time_format); + log_lines.push_back(time_str+log_msg_text); if (log_lines.size()>LOG_LINES_MAX_NUM){ log_lines.erase(log_lines.begin(),log_lines.begin()+log_lines.size()-LOG_LINES_MAX_NUM); } - msg_log(get_time(settings.general_log_time_format)+log_msg_text); + msg_log(time_str+log_msg_text); }catch(...){ error_log("Error in log.cpp: log()"); } @@ -134,11 +155,12 @@ void error_log_no_msg(string error_msg_text){ void error_log(string error_msg_text){ error_log_no_msg(error_msg_text); try{ - error_log_lines.push_back(error_msg_text); + string time_str=get_time(settings.error_log_time_format); + error_log_lines.push_back(time_str+error_msg_text); if (error_log_lines.size()>LOG_LINES_MAX_NUM){ error_log_lines.erase(error_log_lines.begin(),error_log_lines.begin()+error_log_lines.size()-LOG_LINES_MAX_NUM); } - msg_error_log(get_time(settings.error_log_time_format)+error_msg_text); + msg_error_log(time_str+error_msg_text); }catch(...){ error_log_no_msg("Error in log.cpp: error_log()"); } diff --git a/segget/log.h b/segget/log.h index fb3f078..e6a98cc 100644 --- a/segget/log.h +++ b/segget/log.h @@ -31,13 +31,18 @@ #define LOG_LINES_MAX_NUM 200 using namespace std; +extern vector rss_distfile_lines; +extern vector rss_size_lines; +extern vector rss_time_lines; extern vector log_lines; extern vector error_log_lines; +void rss_log(string distfile_name, ulong distfile_size); void log_no_msg(string log_msg_text); void log(string log_msg_text); void debug_no_msg(string debug_msg_text); void debug(string debug_msg_text); void error_log_no_msg(string error_msg_text); void error_log(string error_msg_text); +string get_time(string time_format); #endif \ No newline at end of file diff --git a/segget/segget.conf b/segget/segget.conf index a7bccc9..3cc9bb9 100644 --- a/segget/segget.conf +++ b/segget/segget.conf @@ -174,6 +174,14 @@ provide_mirror_dir=./provide_mirror_dir # provide_mirror_files_restrict_list_on=0 provide_mirror_files_restrict_list_on=0 +# PROVIDE_MIRROR_TO_OTHERS_URL +# Specify url to the provided mirror. +# This option is used to generate rss feed. +# By default UI_IP is used for this. +# Default: +# provide_mirror_to_others_url=ui_ip +provide_mirror_to_others_url=ui_ip + [provide_proxy_fetcher_to_others] # PROVIDE_PROXY_FETCHER_IP # Define an ip address segget will use to provide access for tuiclients. @@ -261,6 +269,23 @@ ui_ip=127.0.0.1 # ui_port=9999 ui_port=9999 +[rss] +# RSS feed provides information on the files added (symlinked) +# to PROVIDE_MIRROR_DIR and can be accessed from feedreader +# via http://ui_ip:ui_port/rss.xml + +# RSS_TITLE +# Specify a title for the RSS feed +# Default: +# rss_title=Seggetd feed +rss_title=Seggetd feed + +# RSS_DESCRIPTION +# Specify description for the RSS feed +# Default: +# rss_description=Files downloaded by seggetd and provided in the local mirror +rss_description=Files downloaded by seggetd and provided in the local mirror + [request_server] # request application adds distfiles to segget daemon queue by establishing tcp connection # with segget daemon (request_server part of it). diff --git a/segget/settings.cpp b/segget/settings.cpp index 5789a03..8637261 100644 --- a/segget/settings.cpp +++ b/segget/settings.cpp @@ -127,6 +127,14 @@ void Tsettings::init(){ conf.set("ui_server","ui_ip",ui_ip); conf.set("ui_server","ui_port",ui_port,1,65535); + conf.set("provide_mirror_to_others","provide_mirror_to_others_url",provide_mirror_to_others_url); + if (provide_mirror_to_others_url=="ui_ip"){ + provide_mirror_to_others_url="http://"+ui_ip; + } + + conf.set("rss","rss_title",rss_title); + conf.set("rss","rss_description",rss_description); + conf.set("request_server","request_ip",request_ip); conf.set("request_server","request_port",request_port,1,65535); diff --git a/segget/settings.h b/segget/settings.h index 4f36850..dea56c8 100644 --- a/segget/settings.h +++ b/segget/settings.h @@ -78,6 +78,10 @@ class Tsettings{ //ui_server string ui_ip; ulong ui_port; + //rss + string provide_mirror_to_others_url; + string rss_title; + string rss_description; //request_server string request_ip; ulong request_port; @@ -133,6 +137,10 @@ class Tsettings{ //ui_server ui_ip("127.0.0.1"), ui_port(9999), + //rss + provide_mirror_to_others_url("http://"+ui_ip), // init after ui_ip + rss_title("Seggetd feed"), + rss_description("Files downloaded by seggetd and provided in the local mirror"), //request_server request_ip("127.0.0.1"), request_port(10000), diff --git a/segget/ui_server.cpp b/segget/ui_server.cpp index dbc7af9..c54fd1a 100644 --- a/segget/ui_server.cpp +++ b/segget/ui_server.cpp @@ -332,10 +332,94 @@ string Tui_server::get_connections_info(){ result=result+""; return result; }catch(...){ - error_log("Error: ui_server.cpp: serve_browser_distfile_progress()"); + error_log("Error: ui_server.cpp: get_connections_info()"); return ""; } } + +string Tui_server::get_rss_info(){ + try{ + string rss_result= + (string)" " + "" + +""+settings.rss_title+"" + +""+settings.rss_description+"" + +""+settings.provide_mirror_to_others_url+"" + +""+get_time(settings.general_log_time_format)+"" + +"5" + +"" + +""+"settings.rss_title"+"" + +"/img/segget_feed.jpg" + +"http://simsim/forum/index.php" + +""; + for (uint rss_line_num=0; rss_line_num" + +""+rss_distfile_lines[rss_line_num]+"" + +" " +// +""+"settings.rss_starter"+"" + +"seggetd" + +"" + +""+rss_time_lines[rss_line_num]+"" + +""+toString(rss_line_num)+"" + +""; + } + rss_result=rss_result+""; + return rss_result; + }catch(...){ + error_log("Error: ui_server.cpp: get_rss_info()"); + return ""; + } +} + +/* +string Tui_server::get_rss_info(){ + try{ + string rss_result= + (string)"" + +"" + +""+settings.rss_title+"" + +""+settings.rss_description+"" + +"" + +"" + +"/rss.xml" + +"seggetd" + +"/img/segget_feed.jpg" + +"segget_feed.jpg" + +"2010-08-06T21:43:52Z" +// +""+get_time(settings.general_log_time_format)+"" + +"seggetd"; + for (uint rss_line_num=0; rss_line_num" + +""+rss_distfile_lines[rss_line_num]+"" + +"2010-08-06T21:43:52Z" +// +""+rss_time_lines[rss_line_num]+"" + +"seggetd" +// fastinetserver@gmail.com + +"" +// +// Kostyantyn Ovechko +// fastinetserver@gmail.com +// +// +""+rss_time_lines[rss_line_num]+"" + +"2010-08-06T21:43:52Z" + +"" + +""+toString(rss_line_num)+"" + +"" + +"
" + +"Downloaded distfile "+rss_distfile_lines[rss_line_num] + +"
"; + } + rss_result=rss_result+"
"; + return rss_result; + }catch(...){ + error_log("Error: ui_server.cpp: get_rss_info()"); + return ""; + } +} +*/ void Tui_server::serve_browser(uint fd, string msg){ try{ debug("Web browser connected"); @@ -350,6 +434,8 @@ void Tui_server::serve_browser(uint fd, string msg){ send_to_fd(fd,get_header("Connections")); send_to_fd(fd,get_connections_info()); send_to_fd(fd,get_footer()); + }else if ((uri=="/rss") or (uri=="/rss.rss") or (uri=="/rss.xml")){ + send_to_fd(fd,get_rss_info()); }else if (uri=="/log"){ ui_server.send_to_fd(fd,get_header("Log")); ui_server.send_to_fd(fd,"
"); diff --git a/segget/ui_server.h b/segget/ui_server.h index 38c12f2..1de8761 100644 --- a/segget/ui_server.h +++ b/segget/ui_server.h @@ -68,6 +68,7 @@ class Tui_server{ string get_footer(); string serve_browser_distfile_progress(Tdistfile * a_distfile); string get_connections_info(); + string get_rss_info(); void serve_browser(uint fd, string msg); }; -- cgit v1.2.3-65-gdbad