summaryrefslogtreecommitdiffstats
path: root/krfb/kinetd/kinetd.h
blob: 9493f84a44d84decc8f488b889b68ea4429b1fde (plain)
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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203

/***************************************************************************
                                  kinetd.h
                                ------------
    begin                : Mon Feb 11 2002
    copyright            : (C) 2002 by Tim Jansen
    email                : tim@tjansen.de
 ***************************************************************************/

/***************************************************************************
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 ***************************************************************************/

#ifndef _KINETD_H_
#define _KINETD_H_

#include <kdedmodule.h>
#include <kservice.h>
#include <ksock.h>
#include <tdeprocess.h>
#include <tqstringlist.h>
#include <tqstring.h>
#include <tqdatetime.h>
#include <tqtimer.h>
#include <dnssd/publicservice.h>

#include "kserviceregistry.h"

class PortListener : public TQObject {
	TQ_OBJECT
//	

private:
	bool m_valid;
	TQString m_serviceName;
	TQString m_serviceURL, m_serviceAttributes;
	TQStringList m_registeredServiceURLs;
	TQString m_dnssdName, m_dnssdType;
	TQMap<TQString,TQString> m_dnssdData;
	int m_serviceLifetime;
	int m_port;
	int m_portBase, m_autoPortRange;
	int m_defaultPortBase, m_defaultAutoPortRange;
	bool m_multiInstance;
	TQString m_execPath;
	TQString m_argument;
	bool m_enabled;
	bool m_serviceRegistered, m_registerService;
	bool m_dnssdRegister, m_dnssdRegistered;
	TQDateTime m_expirationTime;
	TQDateTime m_slpLifetimeEnd;
	TQString m_uuid;

	TDEServerSocket *m_socket;
	TDEProcess m_process;

	TDEConfig *m_config;
	KServiceRegistry *m_srvreg;
	DNSSD::PublicService *m_dnssdreg;

	void freePort();
	void loadConfig(KService::Ptr s);
	void setEnabledInternal(bool e, const TQDateTime &ex);
	void dnssdRegister(bool enabled);
	void setServiceRegistrationEnabledInternal(bool enabled);

public:
	PortListener(KService::Ptr s, TDEConfig *c, KServiceRegistry *srvreg);
	~PortListener();

	bool acquirePort();
	bool isValid();
	TQString name();
	void setEnabled(bool enabled);
	void setEnabled(const TQDateTime &expiration);
	void setServiceRegistrationEnabled(bool enabled);
	bool isServiceRegistrationEnabled();
	TQDateTime expiration();
	TQDateTime serviceLifetimeEnd();
	bool isEnabled();
	int port();
	TQStringList processServiceTemplate(const TQString &a);
	bool setPort(int port = -1, int autoProbeRange = 1);
	void refreshRegistration();

private slots:
	void accepted(TDESocket*);
};

class KInetD : public KDEDModule {
	TQ_OBJECT
//	
	K_DCOP

k_dcop:
	/**
	 * Returns a list of all registered services in KInetd.
	 * To add a service you need to add a .desktop file with
	 * the servicetype "KInetDModule" into the services director
	 * (see kinetdmodule.desktop in servicetypes dir).
	 * @return a list with the names of all services
	 */
	TQStringList services();

	/**
	 * Returns true if the service exists and is available.
	 * @param service name of a service as specified in its .desktop file
	 * @return true if a service with the given name exists and is enabled
	 */
	bool isEnabled(TQString service);

	/**
	 * Enables or disabled the given service. Ignored if the given service
	 * does not exist.
	 * @param service name of a service as specified in its .desktop file
	 * @param enable true to enable, false to disable.
	 */
	void setEnabled(TQString service, bool enable);

	/**
	 * Enables the given service until the given time. Ignored if the given
	 * service does not exist.
	 * @param service name of a service as specified in its .desktop file
	 * @param expiration the time the service will be disabled at
	 */
	void setEnabled(TQString service, TQDateTime expiration);

	/**
	 * Returns the port of the service, or -1 if not listening.
	 * @param service name of a service as specified in its .desktop file
	 * @return the port or -1 if no port used or service does not exist
	 */
	int port(TQString service);

	/**
	 * Sets the port of the service, and possibly a range of ports to try.
	 * It will return true if a port could be found. If it didnt find one but is
	 * enabled it will start a timer that probes that port every 30s.
	 * @param service name of a service as specified in its .desktop file
	 * @param port the first port number to try or -1 to restore defaults
	 * @param autoPortRange the number of ports to try
	 * @return true if a port could be found or service is disabled, false 
	 *          otherwise. 
	 */
	bool setPort(TQString service, int port = -1, int autoPortRange = 1);

	/**
	 * Tests whether the given service is installed..
	 * @param service name of a service as specified in its .desktop file
	 * @return true if installed, false otherwise
	 */
	bool isInstalled(TQString service);

	/**
	 * Enables or disables the SLP registration. Ignored if the service does
	 * not have a service URL. If the service is disabled the service will
	 * registered as soon as it is enabled.
	 * @param service name of a service as specified in its .desktop file
	 * @param enable true to enable, false to disable.
	 */
	void setServiceRegistrationEnabled(TQString service, bool enabled);

	/**
	 * Returns true if service registration for the given service is enabled.
	 * Note that this does not mean that the service is currently registered,
	 * because the service may be disabled.
	 * @param service name of a service as specified in its .desktop file
	 * @return true if service registration is enabled
	 */
	bool isServiceRegistrationEnabled(TQString service);

 private:
	TQDateTime getNextExpirationTime();
	void setPortRetryTimer(bool retry);
	void setReregistrationTimer();

	TDEConfig *m_config;
	KServiceRegistry *m_srvreg;
	TQPtrList<PortListener> m_portListeners;
	TQTimer m_expirationTimer;
	TQTimer m_portRetryTimer;
	TQTimer m_reregistrationTimer;

 private slots:
	void setExpirationTimer();
	void expirationTimer();
	void portRetryTimer();
	void reregistrationTimer();

 public:
	KInetD(TQCString &n);
	virtual ~KInetD();
	void loadServiceList();
	PortListener *getListenerByName(TQString name);
};


#endif