summaryrefslogtreecommitdiffstats
path: root/kdecore/network/kreverseresolver.h
blob: 1f26f4a2a9dd7bf452de3daee58a3b45b4ae0e13 (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
/*  -*- C++ -*-
 *  Copyright (C) 2003 Thiago Macieira <thiago.macieira@kdemail.net>
 *
 *
 *  Permission is hereby granted, free of charge, to any person obtaining
 *  a copy of this software and associated documentation files (the
 *  "Software"), to deal in the Software without restriction, including
 *  without limitation the rights to use, copy, modify, merge, publish,
 *  distribute, sublicense, and/or sell copies of the Software, and to
 *  permit persons to whom the Software is furnished to do so, subject to
 *  the following conditions:
 *
 *  The above copyright notice and this permission notice shall be included 
 *  in all copies or substantial portions of the Software.
 *
 *  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
 *  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
 *  MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
 *  NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
 *  LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
 *  OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
 *  WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 */

#ifndef KREVERSERESOLVER_H
#define KREVERSERESOLVER_H

//////////////////
// Needed includes
#include <tqobject.h>
#include <tqstring.h>

#include "ksocketaddress.h"

namespace KNetwork {

class KReverseResolverPrivate;
/** @class KReverseResolver kreverseresolver.h kreverseresolver.h
 *  @brief Run a reverse-resolution on a socket address.
 *
 * This class is provided as a counterpart to KResolver in such a way
 * as it produces a reverse resolution: it resolves a socket address
 * from its binary representations into a textual representation.
 *
 * Most users will use the static functions @ref resolve, which work
 * both synchronously (blocking) and asynchronously (non-blocking).
 *
 * @author Thiago Macieira <thiago.macieira@kdemail.net>
 */
class KDECORE_EXPORT KReverseResolver: public TQObject
{
  Q_OBJECT
  TQ_OBJECT

public:
  /**
   * Flags for the reverse resolution.
   *
   * These flags are used by the reverse resolution functions for
   * setting resolution parameters. The possible values are:
   * @li NumericHost: don't try to resolve the host address to a text form.
   *		Instead, convert the address to its numeric textual representation.
   * @li NumericService: the same as NumericHost, but for the service name
   * @li NodeNameOnly: returns the node name only (i.e., not the Fully
   *		Qualified Domain Name)
   * @li Datagram: in case of ambiguity in the service name, prefer the
   *		name associated with the datagram protocol
   * @li NumericScope: for those addresses which have the concept of scope,
   *            resolve using the numeric value instead of the proper scope name.
   * @li ResolutionRequired: normally, when resolving, if the name resolution
   *            fails, the process normally converts the numeric address into its
   *            presentation forms. This flag causes the function to return
   *            with error instead.
   */
  enum Flags
    {
      NumericHost = 0x01,
      NumericService = 0x02,
      NodeNameOnly = 0x04,
      Datagram = 0x08,
      NumericScope = 0x10,
      ResolutionRequired = 0x20
    };

  /**
   * Constructs this object to resolve the given socket address.
   *
   * @param addr	the address to resolve
   * @param flags	the flags to use, see @ref Flags
   */
  KReverseResolver(const KSocketAddress& addr, int flags = 0,
		   TQObject * = 0L, const char * = 0L);

  /**
   * Destructor.
   */
  virtual ~KReverseResolver();

  /**
   * This function returns 'true' if the processing is still running.
   */
  bool isRunning() const;

  /**
   * This function returns true if the processing has finished with
   * success, false if it's still running or failed.
   */
  bool success() const;

  /**
   * This function returns true if the processing has finished with
   * failure, false if it's still running or succeeded.
   */
  bool failure() const;

  /**
   * Returns the resolved node name, if the resolution has finished 
   * successfully, or TQString::null otherwise.
   */
  TQString node() const;

  /**
   * Returns the resolved service name, if the resolution has finished
   * successfully, or TQString::null otherwise.
   */
  TQString service() const;

  /**
   * Returns the socket address which was subject to resolution.
   */
  const KSocketAddress& address() const;

  /**
   * Starts the resolution. This function returns 'true'
   * if the resolution has started successfully.
   */
  bool start();

  /**
   * Overrides event handling
   */
  virtual bool event(TQEvent* );

signals:
  /**
   * This signal is emitted when the resolution has finished.
   *
   * @param obj		this class, which contains the results
   */
  void finished(const KReverseResolver& obj);

public:
  /**
   * Resolves a socket address to its textual representation
   *
   * FIXME!! How can we do this in a non-blocking manner!?
   *
   * This function is used to resolve a socket address from its
   * binary representation to a textual form, even if numeric only.
   *
   * @param addr	the socket address to be resolved
   * @param node	the TQString where we will store the resolved node
   * @param serv	the TQString where we will store the resolved service
   * @param flags	flags to be used for this resolution.
   * @return true if the resolution succeeded, false if not
   * @see ReverseFlags for the possible values for @p flags
   */
  static bool resolve(const KSocketAddress& addr, TQString& node, 
		      TQString& serv, int flags = 0);

  /**
   * Resolves a socket address to its textual representation
   *
   * FIXME!! How can we do this in a non-blocking manner!?
   *
   * This function behaves just like the above one, except it takes
   * a sockaddr structure and its size as parameters.
   *
   * @param sa	the sockaddr structure containing the address to be resolved
   * @param salen	the length of the sockaddr structure
   * @param node	the TQString where we will store the resolved node
   * @param serv	the TQString where we will store the resolved service
   * @param flags	flags to be used for this resolution.
   * @return true if the resolution succeeded, false if not
   * @see ReverseFlags for the possible values for @p flags
   */
  static bool resolve(const struct sockaddr* sa, TQ_UINT16 salen, 
		      TQString& node, TQString& serv, int flags = 0);

private:
  KReverseResolverPrivate* d;
};

}				// namespace KNetwork

#endif