2018-09-28 18:15:10 -04:00
|
|
|
/*
|
|
|
|
* RetroShare Service
|
|
|
|
* Copyright (C) 2016-2018 Gioacchino Mazzurco <gio@eigenlab.org>
|
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU Affero General Public License as
|
|
|
|
* published by the Free Software Foundation, either version 3 of the
|
|
|
|
* License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU Affero General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Affero General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
2018-11-04 18:19:45 -05:00
|
|
|
#include "util/stacktrace.h"
|
|
|
|
|
|
|
|
CrashStackTrace gCrashStackTrace;
|
|
|
|
|
2018-09-28 18:15:10 -04:00
|
|
|
#include <csignal>
|
2019-08-27 15:54:17 -04:00
|
|
|
|
|
|
|
#ifndef __ANDROID__
|
|
|
|
#include <termios.h>
|
|
|
|
#endif
|
2018-09-28 18:15:10 -04:00
|
|
|
|
2018-10-05 16:29:49 -04:00
|
|
|
#ifdef __ANDROID__
|
|
|
|
# include <QAndroidService>
|
2019-08-27 15:54:17 -04:00
|
|
|
# include <QCoreApplication>
|
|
|
|
# include <QObject>
|
|
|
|
# include <QStringList>
|
|
|
|
|
|
|
|
# include "util/androiddebug.h"
|
2018-10-05 16:29:49 -04:00
|
|
|
#endif // def __ANDROID__
|
|
|
|
|
2018-09-28 18:15:10 -04:00
|
|
|
#include "retroshare/rsinit.h"
|
|
|
|
#include "retroshare/rsiface.h"
|
|
|
|
|
|
|
|
#ifndef RS_JSONAPI
|
|
|
|
# error Inconsistent build configuration retroshare_service needs rs_jsonapi
|
|
|
|
#endif
|
|
|
|
|
2019-08-27 15:54:17 -04:00
|
|
|
int getch() {
|
|
|
|
int ch;
|
|
|
|
struct termios t_old, t_new;
|
|
|
|
|
|
|
|
tcgetattr(STDIN_FILENO, &t_old);
|
|
|
|
t_new = t_old;
|
|
|
|
t_new.c_lflag &= ~(ICANON | ECHO);
|
|
|
|
tcsetattr(STDIN_FILENO, TCSANOW, &t_new);
|
|
|
|
|
|
|
|
ch = getchar();
|
|
|
|
|
|
|
|
tcsetattr(STDIN_FILENO, TCSANOW, &t_old);
|
|
|
|
return ch;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string readStringFromKeyboard(const char *prompt, bool show_asterisk=true)
|
|
|
|
{
|
|
|
|
const char BACKSPACE=127;
|
|
|
|
const char RETURN=10;
|
|
|
|
|
|
|
|
std::string password;
|
|
|
|
unsigned char ch=0;
|
|
|
|
|
|
|
|
std::cout <<prompt; std::cout.flush();
|
|
|
|
|
|
|
|
while((ch=getch())!=RETURN)
|
|
|
|
{
|
|
|
|
if(ch==BACKSPACE)
|
|
|
|
{
|
|
|
|
if(password.length()!=0)
|
|
|
|
{
|
|
|
|
if(show_asterisk)
|
|
|
|
std::cout <<"\b \b";
|
|
|
|
password.resize(password.length()-1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
password+=ch;
|
|
|
|
if(show_asterisk)
|
|
|
|
std::cout <<'*';
|
|
|
|
else
|
|
|
|
std::cout << ch,std::cout.flush();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
std::cout <<std::endl;
|
|
|
|
return password;
|
|
|
|
}
|
|
|
|
|
|
|
|
class NotifyTxt: public NotifyClient
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
NotifyTxt(){}
|
|
|
|
virtual ~NotifyTxt() {}
|
|
|
|
|
|
|
|
virtual bool askForPassword(const std::string& title, const std::string& question, bool prev_is_bad, std::string& password,bool& cancel)
|
|
|
|
{
|
|
|
|
std::string question1=title + "\nPlease enter your PGP password for key:\n " + question + " :";
|
|
|
|
password = readStringFromKeyboard(question1.c_str()) ;
|
|
|
|
cancel = false ;
|
|
|
|
|
|
|
|
return !password.empty();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2018-09-28 18:15:10 -04:00
|
|
|
int main(int argc, char* argv[])
|
|
|
|
{
|
|
|
|
#ifdef __ANDROID__
|
|
|
|
AndroidStdIOCatcher dbg; (void) dbg;
|
2018-10-05 16:29:49 -04:00
|
|
|
QAndroidService app(argc, argv);
|
2018-09-28 18:15:10 -04:00
|
|
|
|
|
|
|
signal(SIGINT, QCoreApplication::exit);
|
|
|
|
signal(SIGTERM, QCoreApplication::exit);
|
|
|
|
#ifdef SIGBREAK
|
|
|
|
signal(SIGBREAK, QCoreApplication::exit);
|
|
|
|
#endif // ifdef SIGBREAK
|
|
|
|
|
2019-08-27 15:54:17 -04:00
|
|
|
#endif // def __ANDROID__
|
|
|
|
|
2018-09-28 18:15:10 -04:00
|
|
|
RsInit::InitRsConfig();
|
2019-08-27 15:54:17 -04:00
|
|
|
RsControl::earlyInitNotificationSystem();
|
2018-09-28 18:15:10 -04:00
|
|
|
|
2019-08-27 15:54:17 -04:00
|
|
|
#ifndef __ANDROID__
|
|
|
|
NotifyTxt *notify = new NotifyTxt();
|
|
|
|
rsNotify->registerNotifyClient(notify);
|
|
|
|
#endif
|
2018-09-28 18:15:10 -04:00
|
|
|
|
2019-08-27 15:54:17 -04:00
|
|
|
if(RsInit::InitRetroShare(argc, argv, true))
|
|
|
|
{
|
|
|
|
std::cerr << "Could not properly init Retroshare core." << std::endl;
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
#ifdef __ANDROID__
|
2018-09-28 18:15:10 -04:00
|
|
|
rsControl->setShutdownCallback(QCoreApplication::exit);
|
2019-08-27 15:54:17 -04:00
|
|
|
|
2018-09-28 18:15:10 -04:00
|
|
|
QObject::connect(
|
|
|
|
&app, &QCoreApplication::aboutToQuit,
|
|
|
|
[](){
|
|
|
|
if(RsControl::instance()->isReady())
|
|
|
|
RsControl::instance()->rsGlobalShutDown(); } );
|
|
|
|
|
|
|
|
return app.exec();
|
2019-08-27 15:54:17 -04:00
|
|
|
#else
|
|
|
|
while(true)
|
|
|
|
sleep(1);
|
|
|
|
#endif
|
|
|
|
|
2018-09-28 18:15:10 -04:00
|
|
|
}
|