• Skip to content
  • Skip to link menu
  • KDE API Reference
  • kdelibs-4.14.38 API Reference
  • KDE Home
  • Contact Us
 

KDECore

  • kdecore
  • auth
kauthhelpersupport.cpp
Go to the documentation of this file.
1/*
2* Copyright (C) 2008 Nicola Gigante <nicola.gigante@gmail.com>
3* Copyright (C) 2009 Dario Freddi <drf@kde.org>
4*
5* This program is free software; you can redistribute it and/or modify
6* it under the terms of the GNU Lesser General Public License as published by
7* the Free Software Foundation; either version 2.1 of the License, or
8* (at your option) any later version.
9*
10* This program is distributed in the hope that it will be useful,
11* but WITHOUT ANY WARRANTY; without even the implied warranty of
12* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13* GNU General Public License for more details.
14*
15* You should have received a copy of the GNU Lesser General Public License
16* along with this program; if not, write to the
17* Free Software Foundation, Inc.,
18* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA .
19*/
20
21#include "kauthhelpersupport.h"
22
23#include <cstdlib>
24#include <syslog.h>
25
26#ifdef Q_OS_UNIX
27#include <unistd.h>
28#include <sys/types.h>
29#include <pwd.h>
30#endif
31
32#include <QCoreApplication>
33#include <QTimer>
34
35#include "BackendsManager.h"
36
37Q_DECLARE_METATYPE(QTimer*)
38
39namespace KAuth
40{
41
42namespace HelperSupport
43{
44void helperDebugHandler(QtMsgType type, const char *msg);
45}
46
47static bool remote_dbg = false;
48
49#ifdef Q_OS_UNIX
50static void fixEnvironment()
51{
52 //try correct HOME
53 const char *home = "HOME";
54 if(getenv(home)==NULL)
55 {
56 struct passwd *pw = getpwuid(getuid());
57 int overwrite = 0;
58
59 if (pw!=NULL) setenv(home, pw->pw_dir, overwrite);
60 }
61}
62#endif
63
64int HelperSupport::helperMain(int argc, char **argv, const char *id, QObject *responder)
65{
66#ifdef Q_OS_UNIX
67 fixEnvironment();
68#endif
69
70 openlog(id, 0, LOG_USER);
71 qInstallMsgHandler(&HelperSupport::helperDebugHandler);
72
73 if (!BackendsManager::helperProxy()->initHelper(QString::fromLatin1(id))) {
74 syslog(LOG_DEBUG, "Helper initialization failed");
75 return -1;
76 }
77
78 //closelog();
79 remote_dbg = true;
80
81 BackendsManager::helperProxy()->setHelperResponder(responder);
82
83 QCoreApplication app(argc, argv);
84 // Attach the timer
85 QTimer *timer = new QTimer(0);
86 responder->setProperty("__KAuth_Helper_Shutdown_Timer", QVariant::fromValue(timer));
87 timer->setInterval(10000);
88 timer->start();
89 QObject::connect(timer, SIGNAL(timeout()), &app, SLOT(quit()));
90 app.exec(); //krazy:exclude=crashy
91
92 return 0;
93}
94
95void HelperSupport::helperDebugHandler(QtMsgType type, const char *msg)
96{
97 if (!remote_dbg) {
98 int level = LOG_DEBUG;
99 switch (type) {
100 case QtDebugMsg:
101 level = LOG_DEBUG;
102 break;
103 case QtWarningMsg:
104 level = LOG_WARNING;
105 break;
106 case QtCriticalMsg:
107 case QtFatalMsg:
108 level = LOG_ERR;
109 break;
110 }
111 syslog(level, "%s", msg);
112 } else {
113 BackendsManager::helperProxy()->sendDebugMessage(type, msg);
114 }
115
116 // Anyway I should follow the rule:
117 if (type == QtFatalMsg) {
118 exit(-1);
119 }
120}
121
122void HelperSupport::progressStep(int step)
123{
124 BackendsManager::helperProxy()->sendProgressStep(step);
125}
126
127void HelperSupport::progressStep(const QVariantMap &data)
128{
129 BackendsManager::helperProxy()->sendProgressStep(data);
130}
131
132bool HelperSupport::isStopped()
133{
134 return BackendsManager::helperProxy()->hasToStopAction();
135}
136
137} // namespace Auth
BackendsManager.h
KAuth::BackendsManager::helperProxy
static HelperProxy * helperProxy()
Definition: BackendsManager.cpp:129
KAuth::HelperProxy::sendProgressStep
virtual void sendProgressStep(int step)=0
KAuth::HelperProxy::hasToStopAction
virtual bool hasToStopAction()=0
KAuth::HelperProxy::setHelperResponder
virtual void setHelperResponder(QObject *o)=0
KAuth::HelperProxy::sendDebugMessage
virtual void sendDebugMessage(int level, const char *msg)=0
QObject
kauthhelpersupport.h
timeout
int timeout
Definition: kkernel_mac.cpp:46
KAuth::HelperSupport::progressStep
void progressStep(int step)
Send a progressStep signal to the caller application.
Definition: kauthhelpersupport.cpp:122
KAuth::HelperSupport::helperDebugHandler
void helperDebugHandler(QtMsgType type, const char *msg)
Definition: kauthhelpersupport.cpp:95
KAuth::HelperSupport::isStopped
bool isStopped()
Check if the caller asked the helper to stop the execution.
Definition: kauthhelpersupport.cpp:132
KAuth::HelperSupport::helperMain
int helperMain(int argc, char **argv, const char *id, QObject *responder)
Method that implements the main function of the helper tool.
Definition: kauthhelpersupport.cpp:64
KAuth
Definition: AuthBackend.cpp:24
KAuth::remote_dbg
static bool remote_dbg
Definition: kauthhelpersupport.cpp:47
KAuth::fixEnvironment
static void fixEnvironment()
Definition: kauthhelpersupport.cpp:50
This file is part of the KDE documentation.
Documentation copyright © 1996-2023 The KDE developers.
Generated on Mon Feb 20 2023 00:00:00 by doxygen 1.9.6 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

KDECore

Skip menu "KDECore"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • Modules
  • Related Pages

kdelibs-4.14.38 API Reference

Skip menu "kdelibs-4.14.38 API Reference"
  • DNSSD
  • Interfaces
  •   KHexEdit
  •   KMediaPlayer
  •   KSpeech
  •   KTextEditor
  • kconf_update
  • KDE3Support
  •   KUnitTest
  • KDECore
  • KDED
  • KDEsu
  • KDEUI
  • KDEWebKit
  • KDocTools
  • KFile
  • KHTML
  • KImgIO
  • KInit
  • kio
  • KIOSlave
  • KJS
  •   KJS-API
  •   WTF
  • kjsembed
  • KNewStuff
  • KParts
  • KPty
  • Kross
  • KUnitConversion
  • KUtils
  • Nepomuk
  • Plasma
  • Solid
  • Sonnet
  • ThreadWeaver
Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal