summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKostyantyn Ovechko <fastinetserver@gmail.com>2010-08-07 19:47:16 +0300
committerKostyantyn Ovechko <fastinetserver@gmail.com>2010-08-07 19:47:16 +0300
commitf92f202c2e641551fb85ecf07459b7803b40a8a8 (patch)
tree94536b2ea4a696c7883b132ef0c073666c57e7b9
parentAdd WebUI support (diff)
downloadidfetch-f92f202c2e641551fb85ecf07459b7803b40a8a8.tar.gz
idfetch-f92f202c2e641551fb85ecf07459b7803b40a8a8.tar.bz2
idfetch-f92f202c2e641551fb85ecf07459b7803b40a8a8.zip
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
-rw-r--r--segget/distfile.cpp2
-rw-r--r--segget/log.cpp30
-rw-r--r--segget/log.h5
-rw-r--r--segget/segget.conf25
-rw-r--r--segget/settings.cpp8
-rw-r--r--segget/settings.h8
-rw-r--r--segget/ui_server.cpp88
-rw-r--r--segget/ui_server.h1
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<string> rss_distfile_lines;
+vector<ulong> rss_size_lines;
+vector<string> rss_time_lines;
vector<string> log_lines;
vector<string> 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<string> rss_distfile_lines;
+extern vector<ulong> rss_size_lines;
+extern vector<string> rss_time_lines;
extern vector<string> log_lines;
extern vector<string> 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+"</table></center>";
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)"<?xml version=\"1.0\" encoding=\"UTF-8\"?><rss version=\"2.0\"> "
+ "<channel>"
+ +"<title>"+settings.rss_title+"</title>"
+ +"<description>"+settings.rss_description+"</description>"
+ +"<link>"+settings.provide_mirror_to_others_url+"</link>"
+ +"<pubDate>"+get_time(settings.general_log_time_format)+"</pubDate>"
+ +"<ttl>5</ttl>"
+ +"<image>"
+ +"<title>"+"settings.rss_title"+"</title>"
+ +"<url>/img/segget_feed.jpg</url>"
+ +"<link>http://simsim/forum/index.php</link>"
+ +"</image>";
+ for (uint rss_line_num=0; rss_line_num<rss_distfile_lines.size(); rss_line_num++){
+ rss_result=rss_result+
+ "<item>"
+ +"<title>"+rss_distfile_lines[rss_line_num]+"</title>"
+ +"<link><![CDATA["+settings.provide_mirror_to_others_url+"/"+rss_distfile_lines[rss_line_num]+"]]></link> "
+// +"<starter>"+"settings.rss_starter"+"</starter>"
+ +"<author>seggetd</author>"
+ +"<description><![CDATA[Downloaded distfile "+rss_distfile_lines[rss_line_num]
+ +" (size: "+toString(rss_size_lines[rss_line_num])+" B)]]></description>"
+ +"<pubDate>"+rss_time_lines[rss_line_num]+"</pubDate>"
+ +"<guid isPermaLink=\"false\">"+toString(rss_line_num)+"</guid>"
+ +"</item>";
+ }
+ rss_result=rss_result+"</channel></rss>";
+ 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)"<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
+ +"<feed xmlns=\"http://www.w3.org/2005/Atom\">"
+ +"<title>"+settings.rss_title+"</title>"
+ +"<subtitle>"+settings.rss_description+"</subtitle>"
+ +"<link rel=\"alternate\" type=\"text/html\" href=\""+settings.provide_mirror_to_others_url+"\" />"
+ +"<link rel=\"self\" type=\"application/atom+xml\" href=\"/rss.xml\" />"
+ +"<id>/rss.xml</id>"
+ +"<author><name>seggetd</name></author>"
+ +"<icon>/img/segget_feed.jpg</icon>"
+ +"<logo>segget_feed.jpg</logo>"
+ +"<updated>2010-08-06T21:43:52Z</updated>"
+// +"<updated>"+get_time(settings.general_log_time_format)+"</updated>"
+ +"<generator version=\"1.0\">seggetd</generator>";
+ for (uint rss_line_num=0; rss_line_num<rss_distfile_lines.size(); rss_line_num++){
+ rss_result=rss_result+
+ "<entry>"
+ +"<title type=\"html\">"+rss_distfile_lines[rss_line_num]+"</title>"
+ +"<updated>2010-08-06T21:43:52Z</updated>"
+// +"<updated>"+rss_time_lines[rss_line_num]+"</updated>"
+ +"<author><name>seggetd</name>"
+// <email>fastinetserver@gmail.com</email>
+ +"</author>"
+// <contributor>
+// <name>Kostyantyn Ovechko</name>
+// <email>fastinetserver@gmail.com</email>
+// </contributor>
+// +"<published>"+rss_time_lines[rss_line_num]+"</published>"
+ +"<published>2010-08-06T21:43:52Z</published>"
+ +"<link rel=\"alternate\" type=\"text/html\" href=\""+settings.provide_mirror_to_others_url+"/"+rss_distfile_lines[rss_line_num]+"\" />"
+ +"<id>"+toString(rss_line_num)+"</id>"
+ +"<content type=\"xhtml\" xml:base=\""+settings.provide_mirror_to_others_url+"/"+"\">"
+ +"<div xmlns=\"http://www.w3.org/1999/xhtml\">"
+ +"Downloaded distfile "+rss_distfile_lines[rss_line_num]
+ +"</div></content></entry>";
+ }
+ rss_result=rss_result+"</feed>";
+ 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,"<center><table border=\"1\" width=\"100%\">");
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);
};