2015-03-12 17:00:51 -04:00
|
|
|
/*
|
2025-01-07 16:39:02 -05:00
|
|
|
* Copyright (C) 2004-2025 Savoir-faire Linux Inc.
|
2015-09-21 12:44:55 -04:00
|
|
|
*
|
2024-11-04 11:09:53 -05:00
|
|
|
* This program is free software: you can redistribute it and/or modify
|
2015-03-12 17:00:51 -04:00
|
|
|
* it under the terms of the GNU General Public License as published by
|
2024-11-04 11:09:53 -05:00
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
2015-03-12 17:00:51 -04:00
|
|
|
* (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
|
2024-11-04 11:09:53 -05:00
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
2015-03-12 17:00:51 -04:00
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
2024-11-04 11:09:53 -05:00
|
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
2015-03-12 17:00:51 -04:00
|
|
|
*/
|
|
|
|
#include <iostream>
|
|
|
|
#include <thread>
|
|
|
|
#include <cstring>
|
|
|
|
#include <signal.h>
|
|
|
|
#include <getopt.h>
|
|
|
|
#include <string>
|
2024-04-12 16:54:30 -04:00
|
|
|
#include <filesystem>
|
2015-03-12 17:00:51 -04:00
|
|
|
|
daemon: Rename dring occurrences in code and file names to jamid.
Automated using the following commands:
$ mv src/{dring,jami}
$ git grep -l src/dring | xargs sed -i 's,src/dring,src/jami,g'
$ git grep -l '#include "dring/' | \
xargs sed -i 's,#include "dring/,#include "jami/,g'
$ git grep -l 'dring.h' | xargs sed -i 's,dring.h,jami.h,g'
And finally,
$ git grep -l 'dring' | xargs sed -i 's,dring,jami,g'
$ files=$(find -name '*dring*' | sort)
$ for f in $files; do mkdir -p "$(dirname "$f")"; \
mv "$f" "$(echo $f | sed 's/dring/jami/g')"; done
To resolve a bad renaming favorably:
$ git grep -l -i AlsaCarjami | \
xargs sed -i -E 's/([Aa])lsaCarjami/\1lsaCardRingtone/g'
The above renaming command is not perfect, so some hand-tuning was
required to complete it.
* src/manager.cpp (Manager::ManagerPimpl::retrieveConfigPath):
Preserve the dring.yml configuration file name, until we add something
to migrate (rename) it to jami.yml.
* man/dring.pod: Delete.
* bin/dbus/jamid.pod: Move to ...
* man/jamid.pod: here.
* bin/dbus/meson.build (jamid_targets): Normalize man section to the
pre-existing 1 and adjust accordingly.
* src/jami/def.h (dring_EXPORTS): Rename to ...
(jami_EXPORTS): ... this.
change-Id: I9828be6da9c711ab2f22c4d1b9539fea89d7b6fb
2021-06-15 11:03:11 -04:00
|
|
|
#include "jami.h"
|
2015-03-12 17:00:51 -04:00
|
|
|
#include "callmanager_interface.h"
|
|
|
|
#include "configurationmanager_interface.h"
|
|
|
|
#include "presencemanager_interface.h"
|
2019-04-02 17:10:48 -04:00
|
|
|
#ifdef ENABLE_VIDEO
|
2015-03-12 17:00:51 -04:00
|
|
|
#include "videomanager_interface.h"
|
|
|
|
#endif
|
|
|
|
#include "fileutils.h"
|
|
|
|
|
|
|
|
#include <windows.h>
|
|
|
|
|
|
|
|
using namespace std::placeholders;
|
|
|
|
|
|
|
|
bool isActive = false;
|
2024-11-04 11:09:53 -05:00
|
|
|
static int initFlags = 0;
|
2015-03-12 17:00:51 -04:00
|
|
|
bool loop = true;
|
|
|
|
|
|
|
|
static void
|
|
|
|
print_title()
|
|
|
|
{
|
|
|
|
std::cout
|
2024-11-04 11:09:53 -05:00
|
|
|
<< "Jami Core " << libjami::version()
|
2025-01-07 16:39:02 -05:00
|
|
|
<< ", by Savoir-faire Linux Inc. Copyright (C) 2004-2025" << std::endl
|
2018-11-30 11:42:42 -05:00
|
|
|
<< "https://jami.net/" << std::endl
|
2019-04-02 17:10:48 -04:00
|
|
|
#ifdef ENABLE_VIDEO
|
2015-08-17 11:56:21 -04:00
|
|
|
<< "[Video support enabled]" << std::endl
|
2020-05-29 16:36:45 -04:00
|
|
|
#endif
|
|
|
|
#ifdef ENABLE_PLUGIN
|
|
|
|
<< "[Plugins support enabled]" << std::endl
|
2015-08-17 11:56:21 -04:00
|
|
|
#endif
|
|
|
|
<< std::endl;
|
2015-03-12 17:00:51 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
print_usage()
|
|
|
|
{
|
|
|
|
std::cout << std::endl <<
|
|
|
|
"-c, --console \t- Log in console (instead of syslog)" << std::endl <<
|
|
|
|
"-d, --debug \t- Debug mode (more verbose)" << std::endl <<
|
|
|
|
"-p, --persistent \t- Stay alive after client quits" << std::endl <<
|
2016-02-25 16:30:54 -05:00
|
|
|
"--auto-answer \t- Force automatic answer to incoming calls" << std::endl <<
|
2015-03-12 17:00:51 -04:00
|
|
|
"-h, --help \t- Print help" << std::endl;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Parse command line arguments, setting debug options or printing a help
|
|
|
|
// message accordingly.
|
|
|
|
// returns true if we should quit (i.e. help was printed), false otherwise
|
|
|
|
static bool
|
|
|
|
parse_args(int argc, char *argv[], bool& persistent)
|
|
|
|
{
|
2016-02-25 16:30:54 -05:00
|
|
|
int consoleFlag = false;
|
|
|
|
int debugFlag = false;
|
|
|
|
int helpFlag = false;
|
|
|
|
int versionFlag = false;
|
|
|
|
int autoAnswer = false;
|
|
|
|
|
|
|
|
const struct option long_options[] = {
|
2015-03-12 17:00:51 -04:00
|
|
|
/* These options set a flag. */
|
|
|
|
{"debug", no_argument, NULL, 'd'},
|
|
|
|
{"console", no_argument, NULL, 'c'},
|
|
|
|
{"persistent", no_argument, NULL, 'p'},
|
|
|
|
{"help", no_argument, NULL, 'h'},
|
|
|
|
{"version", no_argument, NULL, 'v'},
|
2016-02-25 16:30:54 -05:00
|
|
|
{"auto-answer", no_argument, &autoAnswer, true},
|
2015-03-12 17:00:51 -04:00
|
|
|
{0, 0, 0, 0} /* Sentinel */
|
|
|
|
};
|
|
|
|
|
|
|
|
while (true) {
|
|
|
|
/* getopt_long stores the option index here. */
|
|
|
|
int option_index = 0;
|
|
|
|
|
|
|
|
auto c = getopt_long(argc, argv, "dcphv", long_options, &option_index);
|
|
|
|
|
|
|
|
// end of the options
|
|
|
|
if (c == -1)
|
|
|
|
break;
|
|
|
|
|
|
|
|
switch (c) {
|
|
|
|
case 'd':
|
|
|
|
debugFlag = true;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'c':
|
|
|
|
consoleFlag = true;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'p':
|
|
|
|
persistent = true;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'h':
|
|
|
|
case '?':
|
|
|
|
helpFlag = true;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'v':
|
|
|
|
versionFlag = true;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (helpFlag) {
|
|
|
|
print_usage();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (versionFlag) {
|
|
|
|
// We've always print the title/version, so we can just exit
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (consoleFlag)
|
2024-11-04 11:09:53 -05:00
|
|
|
initFlags |= libjami::LIBJAMI_FLAG_CONSOLE_LOG;
|
2015-03-12 17:00:51 -04:00
|
|
|
|
|
|
|
if (debugFlag)
|
2024-11-04 11:09:53 -05:00
|
|
|
initFlags |= libjami::LIBJAMI_FLAG_DEBUG;
|
2015-03-12 17:00:51 -04:00
|
|
|
|
2016-02-25 16:30:54 -05:00
|
|
|
if (autoAnswer)
|
2024-11-04 11:09:53 -05:00
|
|
|
initFlags |= libjami::LIBJAMI_FLAG_AUTOANSWER;
|
2016-02-25 16:30:54 -05:00
|
|
|
|
2015-03-12 17:00:51 -04:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
IncomingCall(const std::string& accountId,
|
|
|
|
const std::string& callId, const std::string& message)
|
|
|
|
{
|
2016-02-15 13:05:38 -05:00
|
|
|
(void) accountId;
|
|
|
|
(void) message;
|
2015-03-12 17:00:51 -04:00
|
|
|
if (not isActive) {
|
2022-10-27 16:00:41 -04:00
|
|
|
libjami::accept(callId);
|
2015-03-12 17:00:51 -04:00
|
|
|
isActive = true;
|
|
|
|
} else
|
2022-10-27 16:00:41 -04:00
|
|
|
libjami::refuse(callId);
|
2015-03-12 17:00:51 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
run()
|
|
|
|
{
|
2022-10-27 16:00:41 -04:00
|
|
|
using SharedCallback = std::shared_ptr<libjami::CallbackWrapperBase>;
|
2015-03-12 17:00:51 -04:00
|
|
|
|
2024-11-04 11:09:53 -05:00
|
|
|
libjami::init(static_cast<libjami::InitFlag>(initFlags));
|
2015-03-12 17:00:51 -04:00
|
|
|
|
|
|
|
std::map<std::string, SharedCallback> callHandlers;
|
2022-10-27 16:00:41 -04:00
|
|
|
callHandlers.insert(libjami::exportable_callback<libjami::CallSignal::IncomingCall>
|
2015-03-12 17:00:51 -04:00
|
|
|
(std::bind(&IncomingCall, _1, _2, _3)));
|
|
|
|
|
2018-08-13 17:57:06 -04:00
|
|
|
registerSignalHandlers(callHandlers);
|
2015-03-12 17:00:51 -04:00
|
|
|
|
2022-10-27 16:00:41 -04:00
|
|
|
if (!libjami::start())
|
2015-03-12 17:00:51 -04:00
|
|
|
return -1;
|
|
|
|
|
|
|
|
while (loop) {
|
|
|
|
Sleep(1000); // milliseconds
|
|
|
|
}
|
|
|
|
|
2022-10-27 16:00:41 -04:00
|
|
|
libjami::fini();
|
2016-02-15 13:05:38 -05:00
|
|
|
|
|
|
|
return 0;
|
2015-03-12 17:00:51 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
interrupt()
|
2014-11-13 16:09:50 -05:00
|
|
|
{
|
2015-03-12 17:00:51 -04:00
|
|
|
loop = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
signal_handler(int code)
|
|
|
|
{
|
|
|
|
std::cerr << "Caught signal " << code
|
|
|
|
<< ", terminating..." << std::endl;
|
|
|
|
// Unset signal handlers
|
|
|
|
signal(SIGINT, SIG_DFL);
|
|
|
|
signal(SIGTERM, SIG_DFL);
|
|
|
|
|
|
|
|
interrupt();
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
main(int argc, char *argv [])
|
|
|
|
{
|
2024-04-12 16:54:30 -04:00
|
|
|
// Set the program's directory path as the resource directory path.
|
|
|
|
std::filesystem::path programPath(argv[0]);
|
|
|
|
jami::fileutils::set_resource_dir_path(programPath.parent_path());
|
2015-03-12 17:00:51 -04:00
|
|
|
|
|
|
|
print_title();
|
|
|
|
|
|
|
|
bool persistent = false;
|
|
|
|
if (parse_args(argc, argv, persistent))
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
// TODO: Block signals for all threads but the main thread, decide how/if we should
|
|
|
|
// handle other signals
|
|
|
|
signal(SIGINT, signal_handler);
|
|
|
|
signal(SIGTERM, signal_handler);
|
|
|
|
|
|
|
|
return run();
|
2014-11-13 16:09:50 -05:00
|
|
|
}
|