summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKostyantyn Ovechko <fastinetserver@gmail.com>2010-08-14 00:27:57 +0300
committerKostyantyn Ovechko <fastinetserver@gmail.com>2010-08-14 00:27:57 +0300
commit9742523295396e1fc9c376a678375994ff057d8b (patch)
tree0e47337b2188f1454de18fe8bfedb9063c34518d
parentAdd install option to Makefiles (diff)
downloadidfetch-9742523295396e1fc9c376a678375994ff057d8b.tar.gz
idfetch-9742523295396e1fc9c376a678375994ff057d8b.tar.bz2
idfetch-9742523295396e1fc9c376a678375994ff057d8b.zip
Add arguments to request tool: --help, --keep-pkglist-file.
--help Show the help. --keep-pkglist-file Do NOT delete pkg.list file after sending request to segget daemon.
-rw-r--r--request/Makefile2
-rw-r--r--request/config.cpp50
-rw-r--r--request/request.cpp88
-rw-r--r--request/request.h7
-rw-r--r--request/settings.h8
-rw-r--r--request/utils.cpp8
-rw-r--r--request/utils.h2
7 files changed, 92 insertions, 73 deletions
diff --git a/request/Makefile b/request/Makefile
index 81df7a3..ca5c5dd 100644
--- a/request/Makefile
+++ b/request/Makefile
@@ -30,7 +30,7 @@ install:
-mkdir -p /etc/seggetd
-cp *.conf /etc/seggetd
-cp request /usr/bin
- -mkdir -p /tmp/seggetd
+ -mkdir -p /var/tmp/seggetd
-mkdir -p /var/log/seggetd
.PRECIOUS: %.o
diff --git a/request/config.cpp b/request/config.cpp
index 3e0a2eb..afae8b4 100644
--- a/request/config.cpp
+++ b/request/config.cpp
@@ -34,7 +34,7 @@ void Tconfig::load_settings_from_config_file(){
file.open(config_file_name.c_str());
}
catch(...){
- merror("Error opening settings file: "+config_file_name+". Default settings will be used. Check if config file: "+config_file_name+" exists and segget has rights to access it.");
+ printout("Error opening settings file: "+config_file_name+". Default settings will be used. Check if config file: "+config_file_name+" exists and segget has rights to access it.");
return;
}
try{
@@ -61,14 +61,14 @@ void Tconfig::load_settings_from_config_file(){
}
}catch(ifstream::failure e){
if (!file.eof()){
- merror("Settings file: "+config_file_name+" was opened, but an error occured while reading it.");
+ printout("Settings file: "+config_file_name+" was opened, but an error occured while reading it.");
return;
}
}catch(...){
- merror("Settings file: "+config_file_name+" was opened, but an error occured while reading settings from it.");
+ printout("Settings file: "+config_file_name+" was opened, but an error occured while reading settings from it.");
}
}catch(...){
- merror("Error in config.cpp: load_settings_from_config_file()");
+ printout("Error in config.cpp: load_settings_from_config_file()");
}
}
@@ -76,17 +76,17 @@ int Tconfig::set(string const& section, string const& entry, string &dst) const
try{
map<string,string>::const_iterator ci = content_.find(section + '/' + entry);
if (ci == content_.end()){
- merror("! Settings in file:"+config_file_name+" ["+section+"]."+entry+" has not been set.");
- merror("! Settings in file:"+config_file_name+" ["+section+"]."+entry+"="+dst+". Default value forced.");
+ printout("! Settings in file:"+config_file_name+" ["+section+"]."+entry+" has not been set.");
+ printout("! Settings in file:"+config_file_name+" ["+section+"]."+entry+"="+dst+". Default value forced.");
return 1;
}
else{
dst=ci->second;
- merror("Settings in file:"+config_file_name+" ["+section+"]."+entry+"="+dst);
+ printout("Settings in file:"+config_file_name+" ["+section+"]."+entry+"="+dst);
return 0;
}
}catch(...){
- merror("Error in config.cpp: set(string &dst, string const& section, string const& entry)");
+ printout("Error in config.cpp: set(string &dst, string const& section, string const& entry)");
return 1;
}
}
@@ -95,37 +95,37 @@ int Tconfig::set(string const& section, string const& entry, ulong &dst, uint co
uint return_value;
map<string,string>::const_iterator ci = content_.find(section + '/' + entry);
if (ci == content_.end()){
- merror("! Settings in file:"+config_file_name+" ["+section+"]."+entry+" has not been set.");
- merror("! Settings in file:"+config_file_name+" ["+section+"]."+entry+"="+toString(dst)+". Default value forced.");
+ printout("! Settings in file:"+config_file_name+" ["+section+"]."+entry+" has not been set.");
+ printout("! Settings in file:"+config_file_name+" ["+section+"]."+entry+"="+toString(dst)+". Default value forced.");
return 1;
}
else{
return_value=atoi(ci->second.c_str());
if (return_value==0)
if (toString(return_value)!=ci->second){
- merror("! Settings in file:"+config_file_name+" ["+section+"]."+entry
+ printout("! Settings in file:"+config_file_name+" ["+section+"]."+entry
+" must have an integer value in range from "+toString(min_limit)
+" to "+toString(max_limit)
+". Can't convert "+ci->second
+" to integer. ");
- merror("! Settings in file:"+config_file_name+" ["+section+"]."+entry+"="+toString(dst)+". Default value forced.");
+ printout("! Settings in file:"+config_file_name+" ["+section+"]."+entry+"="+toString(dst)+". Default value forced.");
return 1;
}
if ((return_value>=min_limit) and (return_value<=max_limit)){
//everything is ok
- merror("Settings in file:"+config_file_name+" ["+section+"]."+entry+"="+toString(return_value));
+ printout("Settings in file:"+config_file_name+" ["+section+"]."+entry+"="+toString(return_value));
dst=return_value;
return 0;
}else{
- merror("! Settings in file:"+config_file_name+" ["+section+"]."+entry
+ printout("! Settings in file:"+config_file_name+" ["+section+"]."+entry
+" must have an integer value in range from "+toString(min_limit)
+" to "+toString(max_limit)+".");
- merror("! Settings in file:"+config_file_name+" ["+section+"]."+entry+"="+toString(dst)+". Default value forced.");
+ printout("! Settings in file:"+config_file_name+" ["+section+"]."+entry+"="+toString(dst)+". Default value forced.");
return 1;
}
}
}catch(...){
- merror("Error in config.cpp: set(ulong &dst, string const& section, string const& entry, uint const& min_limit, uint const& max_limit)");
+ printout("Error in config.cpp: set(ulong &dst, string const& section, string const& entry, uint const& min_limit, uint const& max_limit)");
return 1;
}
}
@@ -135,35 +135,35 @@ int Tconfig::set(string const& section, string const& entry, bool &dst) const {
uint return_value;
map<std::string,string>::const_iterator ci = content_.find(section + '/' + entry);
if (ci == content_.end()){
- merror("! Settings in file:"+config_file_name+" ["+section+"]."+entry+" has not been set.");
- merror("! Settings in file:"+config_file_name+" ["+section+"]."+entry+"="+toString(dst)+". Default value forced.");
+ printout("! Settings in file:"+config_file_name+" ["+section+"]."+entry+" has not been set.");
+ printout("! Settings in file:"+config_file_name+" ["+section+"]."+entry+"="+toString(dst)+". Default value forced.");
return 1;
}
else{
return_value=atoi(ci->second.c_str());
if (return_value==0)
if (toString(return_value)!=ci->second){
- merror("! Settings in file:"+config_file_name+" ["+section+"]."+entry
+ printout("! Settings in file:"+config_file_name+" ["+section+"]."+entry
+" must have a boolean value: 0 or 1"
+". Can't convert "+ci->second
+" to 0 or 1. ");
- merror("! Settings in file:"+config_file_name+" ["+section+"]."+entry+"="+toString(dst)+". Default value forced.");
+ printout("! Settings in file:"+config_file_name+" ["+section+"]."+entry+"="+toString(dst)+". Default value forced.");
return 1;
}
if ((return_value==0) or (return_value==1)){
//everything is ok
- merror("Settings in file:"+config_file_name+" ["+section+"]."+entry+"="+toString(return_value));
+ printout("Settings in file:"+config_file_name+" ["+section+"]."+entry+"="+toString(return_value));
dst=return_value;
return 0;
}else{
- merror("! Settings in file:"+config_file_name+" ["+section+"]."+entry
+ printout("! Settings in file:"+config_file_name+" ["+section+"]."+entry
+" must have a boolean value: 0 or 1");
- merror("! Settings in file:"+config_file_name+" ["+section+"]."+entry+"="+toString(dst)+". Default value forced.");
+ printout("! Settings in file:"+config_file_name+" ["+section+"]."+entry+"="+toString(dst)+". Default value forced.");
return 1;
}
}
}catch(...){
- merror("Error in config.cpp: set(bool &dst, string const& section, string const& entry)");
+ printout("Error in config.cpp: set(bool &dst, string const& section, string const& entry)");
return 1;
}
}
@@ -172,6 +172,6 @@ void Tconfig::clear(){
try{
content_.clear();
}catch(...){
- merror("Error in config.cpp: clear()");
+ printout("Error in config.cpp: clear()");
}
} \ No newline at end of file
diff --git a/request/request.cpp b/request/request.cpp
index 68ba6f5..b5a400b 100644
--- a/request/request.cpp
+++ b/request/request.cpp
@@ -27,7 +27,6 @@
#include "request.h"
int request(string msg){
-// gettimeofday(&network_distfile_brokers_array[network_num].last_request_time, NULL);
int len;
struct sockaddr_in address;
int result;
@@ -43,16 +42,16 @@ int request(string msg){
//Connect your socket to the server’s socket:
result = connect(sockfd, (struct sockaddr *)&address, len);
if(result == -1) {
- merror("Can't connect to segget daemon");
+ printout("Can't connect to segget daemon");
return R_PF_ERROR_ADDING_TO_PROXY_QUEUE;
}
if (msg.length()>90000){return R_PF_ERROR_ADDING_TO_PROXY_QUEUE;};
char send_buffer[100000];
- // char recv_buffer[256];
+
strcpy(send_buffer,msg.c_str());
//You can now read and write via sockfd:
if (write(sockfd, send_buffer, strlen(send_buffer))!=(int)msg.length()){
- merror("Error in request.cpp: request(): request msg size and sent data size are different.");
+ printout("Error in request.cpp: request(): request msg size and sent data size are different.");
};
fd_set readfds, testfds;
@@ -74,15 +73,15 @@ int request(string msg){
char recv_buffer[1000];
if(nread == 0) {
close(sockfd);
- merror("Error in request.cpp: request(): no response from segget daemon");
+ printout("Error in request.cpp: request(): no response from segget daemon");
}else{
if (nread!=read(sockfd, recv_buffer, nread)){
- merror("Error in request.cpp: request(): response msg size and received data size are different.");
+ printout("Error in request.cpp: request(): response msg size and received data size are different.");
};
return decode_server_response(recv_buffer);
}
}else{
- merror("Error in request.cpp: request(): zero size response from segget daemon");
+ printout("Error in request.cpp: request(): zero size response from segget daemon");
}
close(sockfd);
return R_PF_ERROR_ADDING_TO_PROXY_QUEUE;
@@ -93,9 +92,9 @@ int load_pkgs(){
ifstream json_pkg_list_file;
json_pkg_list_file.exceptions (ofstream::failbit | ofstream::badbit);
try{
- json_pkg_list_file.open(settings.pkg_list_file.c_str());
+ json_pkg_list_file.open(settings.pkg_list_file_name.c_str());
}catch(...){
- merror("Error: Can't open distfile list file: "+settings.pkg_list_file);
+ printout("Error: Can't open distfile list file: "+settings.pkg_list_file_name);
return 1;
}
string buff((std::istreambuf_iterator<char>(json_pkg_list_file)), std::istreambuf_iterator<char>());
@@ -103,23 +102,23 @@ int load_pkgs(){
json_pkg_list_file>>buff;
}catch(std::ifstream::failure e){
if (!json_pkg_list_file.eof()){
- merror("Error: Can't read pkg.list file: "+(string)e.what());
+ printout("Error: Can't read pkg.list file: "+(string)e.what());
return 1;
}
}catch(...){
- perror("Unknown Error: Can't read pkg.list file");
+ printout("Unknown Error: Can't read pkg.list file");
return 1;
}
try{
json_pkg_list_file.close();
}catch(...){
- perror("Error: Can't close pkg.list file");
+ printout("Error: Can't close pkg.list file");
}
try{
json_object *json_array_pkg_list;
json_array_pkg_list = json_tokener_parse(buff.c_str());
if (is_error(json_array_pkg_list))
- merror("error parsing json:"+toString(json_tokener_errors[-(unsigned long)json_array_pkg_list]));
+ printout("error parsing json:"+toString(json_tokener_errors[-(unsigned long)json_array_pkg_list]));
else {
uint pkg_count=json_object_array_length(json_array_pkg_list);
// create 0 pkg for distfiles to provide proxy-fetcher
@@ -134,13 +133,21 @@ int load_pkgs(){
}
}
}
- return 0;
}catch(...){
- perror("Error: Can't parse json data from pkg.list file");
+ printout("Error: Can't parse json data from pkg.list file");
return 1;
}
+ if (settings.keep_pkg_list_file){
+ printout(settings.pkg_list_file_name+" will NOT be deleted");
+ }else{
+ if(remove(settings.pkg_list_file_name.c_str()) != 0 )
+ printout("Error in request.cpp: load_pkgs(): can't delete:"+settings.pkg_list_file_name);
+ else
+ printout(settings.pkg_list_file_name+" deleted" );
+ }
+ return 0;
}catch(...){
- perror("Error in segget.cpp: load_pkgs()");
+ printout("Error in request.cpp: load_pkgs()");
return 1;
}
}
@@ -162,7 +169,7 @@ void show_pkgs(){
}
*/
-void segget_exit(int sig){
+void _exit(int sig){
try{
// for(uint fd = 0; fd <= ui_server.max_fd_num; fd++) {
// close(fd);
@@ -179,10 +186,9 @@ void segget_exit(int sig){
int routine(){
try{
- signal(SIGABRT,segget_exit);//If program aborts go to assigned function "segget_exit".
- signal(SIGTERM,segget_exit);//If program terminates go to assigned function "segget_exit".
- signal(SIGINT,segget_exit);//If program terminates go to assigned function "segget_exit".
-// prev_time=time((time_t *)NULL);
+ signal(SIGABRT,_exit);//If program aborts go to assigned function "segget_exit".
+ signal(SIGTERM,_exit);//If program terminates go to assigned function "segget_exit".
+ signal(SIGINT,_exit);//If program terminates go to assigned function "segget_exit".
try{
//load settings
settings.init();
@@ -196,41 +202,57 @@ int routine(){
}catch(...){
//error while loading pkgs
}
+/*
try{
//show_pkgs();
-// stats.show_totals();
}catch(...){
//error while showing stats
}
- try{
-// download_pkgs();
- }catch(...){
- //error while downloading_pkgs
- }
+*/
return 0;
}catch(...)
{
- perror("Error in segget.cpp: routine()");
+ printout("Error in segget.cpp: routine()");
}
return 1;
}
+
+void show_help(){
+ try{
+ printout("Usage: request [OPTIONS]");
+ printout("Options:");
+ printout("--conf-dir=PATH_TO_CONFIG_DIR Specify path to a dir containing segget.conf file. By default it's /etc/seggetd");
+ printout("--help Show this help.");
+ printout("--keep-pkglist-file Do NOT delete pkg.list file after sending request to segget daemon.");
+ printout("--pkglist-file=PATH_TO_PKGLIST_FILE Specify path to pkg.list file. By default it's /var/tmp/seggetd/pkg.list");
+ printout("");
+ }catch(...){
+ printout("Error in segget.cpp: init_curses()");
+ }
+}
+
int parse_cli_arguments(int argc, char* argv[]){
try{
string option,name,value;
- cout << "argc = " << argc << endl;
+// cout << "argc = " << argc << endl;
int posEqual;
+// for(int i = 0; i < argc; i++){
+// cout << "argv[" << i << "] = " << argv[i] << endl;
+// }
+// printout("");
for(int i = 0; i < argc; i++){
- cout << "argv[" << i << "] = " << argv[i] << endl;
option=argv[i];
posEqual=option.find('=');
name = trim(option.substr(0,posEqual));
value = trim(option.substr(posEqual+1));
if (name=="--conf-dir") {settings.conf_dir=value; continue;};
- if (name=="--pkglist-file") {settings.pkg_list_file=value; continue;};
+ if (name=="--pkglist-file") {settings.pkg_list_file_name=value; continue;};
+ if (name=="--keep-pkglist-file") {settings.keep_pkg_list_file=true; continue;};
+ if (name=="--help") {show_help(); _exit(0);};
}
return 0;
}catch(...){
- perror("Error in segget.cpp: init_curses()");
+ printout("Error in segget.cpp: init_curses()");
}
return 1;
}
@@ -242,7 +264,7 @@ int main(int argc, char* argv[])
routine();
exit (0);
}catch(...){
- perror("Error in segget.cpp main()");
+ printout("Error in segget.cpp main()");
}
exit(1);
} \ No newline at end of file
diff --git a/request/request.h b/request/request.h
index 1be6ff3..fb35a2e 100644
--- a/request/request.h
+++ b/request/request.h
@@ -63,14 +63,9 @@ using namespace std;
int sockfd;
int routine();
-void start_daemon_mode();
int parse_cli_arguments(int argc, char* argv[]);
-int init_curses();
int load_pkgs();
-void show_pkgs();
-int choose_segment(uint connection_num);
-int download_pkgs();
+//void show_pkgs();
int main(int argc, char* argv[]);
-void *print_message_function( void *);
#endif \ No newline at end of file
diff --git a/request/settings.h b/request/settings.h
index 1ded0a7..183d544 100644
--- a/request/settings.h
+++ b/request/settings.h
@@ -37,9 +37,9 @@ using namespace std;
class Tsettings{
public:
string conf_dir;
- bool no_daemon_flag;
//pkg_list
- string pkg_list_file;
+ string pkg_list_file_name;
+ bool keep_pkg_list_file;
//request_server
string request_ip;
ulong request_port;
@@ -51,9 +51,9 @@ class Tsettings{
Tsettings():
conf_dir("/etc/seggetd"),
- no_daemon_flag(false),
//pkg_list
- pkg_list_file("/tmp/seggetd/pkg.list"),
+ pkg_list_file_name("/var/tmp/seggetd/pkg.list"),
+ keep_pkg_list_file(false),
//request_server
request_ip("127.0.0.1"),
request_port(10000)
diff --git a/request/utils.cpp b/request/utils.cpp
index bb9b3bf..f60c6d2 100644
--- a/request/utils.cpp
+++ b/request/utils.cpp
@@ -25,8 +25,10 @@
*/
#include "utils.h"
-void merror(string error_msg){
- perror(error_msg.c_str());
+#include <iostream>
+
+void printout(string error_msg){
+ cout<<error_msg<< endl;
}
ulong time_left_from(timeval from_time){
@@ -38,7 +40,7 @@ ulong time_left_from(timeval from_time){
timeleft=1;
return timeleft;
}catch(...){
- merror("Error in utils.cpp: time_left_from()");
+ printout("Error in utils.cpp: time_left_from()");
return 1;
}
} \ No newline at end of file
diff --git a/request/utils.h b/request/utils.h
index 5e29a20..87440e1 100644
--- a/request/utils.h
+++ b/request/utils.h
@@ -34,6 +34,6 @@
#include <cstdlib>
using namespace std;
-void merror(string error_msg);
+void printout(string error_msg);
ulong time_left_from(timeval from_time);
#endif \ No newline at end of file