1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100
|
/**
* Copyright (c) 2020-2026 Governikus GmbH & Co. KG, Germany
*/
#include "AusweisApp_p.h"
#include "QtHooks.h"
#include <cstring>
#include <iostream>
#include <thread>
static int cExitCode = -1;
void cb(const char* pMessage)
{
std::cout << "\x1b[1m";
std::cout << "**** Callback thread id: " << std::this_thread::get_id() << std::endl;
if (pMessage == nullptr)
{
std::cout << "**** AusweisApp is initialized" << "\x1b[0m" << std::endl;
ausweisapp_send(R"({"cmd": "GET_INFO"})");
ausweisapp_send(R"({"cmd": "RUN_AUTH", "tcTokenURL": "https://test.governikus-eid.de/AusweisAuskunft/WebServiceRequesterServlet?mode=json"})");
return;
}
const std::string s(pMessage);
std::cout << "**** Callback msg: " << s << std::endl;
if (s.find(R"("msg":"ACCESS_RIGHTS")") != std::string::npos)
{
ausweisapp_send(R"({"cmd": "ACCEPT"})");
}
if (s.find(R"("msg":"INSERT_CARD")") != std::string::npos || s.find(R"("msg":"ENTER_)") != std::string::npos)
{
ausweisapp_send(R"({"cmd": "CANCEL"})");
}
if (s.find(R"("msg":"AUTH")") != std::string::npos && s.find(R"(sal#cancellationByUser)") != std::string::npos)
{
std::cout << "**** Finished" << std::endl;
ausweisapp_shutdown();
cExitCode = 0;
}
std::cout << "\x1b[0m" << std::endl;
}
void start_ausweisapp(const char* pParameter)
{
ausweisapp_init(&cb, pParameter);
std::cout << "Let's wait here..." << std::endl;
governikus::ausweisapp_join_thread_internal();
if (ausweisapp_is_running())
{
ausweisapp_shutdown();
}
}
int main()
{
if (!governikus::QtHooks::init())
{
std::cout << "Cannot initialize QtHooks" << std::endl;
return -2;
}
#if defined(LIBS_GOVERNIKUS)
start_ausweisapp(nullptr);
#else
start_ausweisapp("--no-proxy");
#endif
const int livingDeadCount = static_cast<int>(governikus::QtHooks::getQObjects().size());
if (livingDeadCount > 0)
{
governikus::QtHooks::setPrint();
governikus::QtHooks::printAlive();
std::cout << "There are zombies behind you: " << livingDeadCount << std::endl;
#ifdef LIBS_GOVERNIKUS
return livingDeadCount;
#endif
}
if (cExitCode == 0)
{
cExitCode = -1;
start_ausweisapp("--no-loghandler");
}
return cExitCode;
}
|