summaryrefslogtreecommitdiffstats
path: root/smb4k/core/smb4knetworkitems.h
blob: 7d43ee57921b6fa2df0f4ad3be5883789653469f (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
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
/***************************************************************************
    smb4knetworkitems  -  Network items used by the Smb4KScanner class
    to pass and store data.
                             -------------------
    begin                : Mi Jun 2 2004
    copyright            : (C) 2004 by Alexander Reinholdt
    email                : dustpuppy@mail.berlios.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.                                   *
 *                                                                         *
 *   This program is distributed in the hope that it will be useful, but   *
 *   WITHOUT ANY WARRANTY; without even the implied warranty of            *
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU     *
 *   General Public License for more details.                              *
 *                                                                         *
 *   You should have received a copy of the GNU General Public License     *
 *   along with this program; if not, write to the                         *
 *   Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,   *
 *   MA  02110-1301 USA                                                    *
 ***************************************************************************/

#ifndef SMB4KNETWORKITEMS_H
#define SMB4KNETWORKITEMS_H

#ifdef HAVE_CONFIG_H
#include <config.h>
#endif

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

#include <kdemacros.h>

/**
 * This class provides a container for a workgroup/domain found in the network
 * neighborhood.
 */

class TDE_EXPORT Smb4KWorkgroupItem
{
  public:
    /**
     * The constructor.
     *
     * @param name        The name of the workgroup/domain.
     *
     * @param master      The master browser of the workgroup.
     *
     * @param masterIP    The IP address of the workgroup master browser.
     */
    Smb4KWorkgroupItem( const TQString &name,
                        const TQString &master,
                        const TQString &masterIP = TQString() );

    /**
     * Empty constructor.
     */
    Smb4KWorkgroupItem() {}

    /**
     * The destructor.
     */
    ~Smb4KWorkgroupItem();

    /**
     * Returns the workgroup name.
     */
    const TQString &name() const { return m_name; }

    /**
     * Returns the name of the master browser.
     */
    const TQString &master() const { return m_master; }

    /**
     * Returns the IP address of the master browser. If it is not a valid
     * IPv4 or IPv6 address, TQString() is returned.
     *
     * @returns the valid IP v4 or v6 address of the workgroup master browser
     * or TQString().
     */
    const TQString &masterIP() const { return m_ip; }

    /**
     * You can mark the master as 'pseudo' with this function. That means that
     * this master was not reported as being the master browser of this
     * workgroup, but it's the only one found (e.g. by a custom search).
     */
    void setPseudoMaster();

    /**
     * Returns TRUE, if the master is a 'pseudo' master. @see setPseudoMaster()
     * for further information.
     */
    bool hasPseudoMaster() const { return m_pseudo; }

    /**
     * This function sets the IP address of the master browser.
     *
     * @param ip            The IP address of the master browser
     */
    void setMasterIP( const TQString &ip );

    /**
     * This function sets the master browser.
     *
     * @param name          The name of the master browser
     *
     * @param ip            The IP address of the master browser
     *
     * @param pseudo        Determines if this is a real master browser or if
     *                      it is a faked one, i.e. a pseudo master.
     */
    void setMaster( const TQString &name,
                    const TQString &ip,
                    bool pseudo = false );

  private:
    /**
     * The name of the workgroup.
     */
    TQString m_name;

    /**
     * The name of the workgroup master.
     */
    TQString m_master;

    /**
     * The IP address of the master.
     */
    TQString m_ip;

    /**
     * Determines whether the master is a 'pseudo'-master.
     */
    bool m_pseudo;

    /**
     * This function checks if the IP address is valid, i.e. the
     * IP address is either IP v4 or IP v6. It returns either TRUE
     * or FALSE.
     *
     * @param ip            The IP address that's going to be checked.
     *
     * @returns TRUE if the IP address is valid and FALSE otherwise.
     */
    bool ipIsValid( const TQString &ip );
};


/**
 * This class provides a container for a host found in the network
 * neighborhood.
 */

class TDE_EXPORT Smb4KHostItem
{
  public:
    /**
     * The default constructor.
     *
     * @param workgroup     The workgroup/domain of the host
     *
     * @param name          The name of the host
     *
     * @param comment       The comment that describes the host. May be empty.
     *
     * @param ip            The IP address of the host
     */
    Smb4KHostItem( const TQString &workgroup,
                   const TQString &name,
                   const TQString &comment = TQString(),
                   const TQString &ip = TQString() );

    /**
     * The copy constructor.
     *
     * @param host          A Smb4KHostItem representing a host.
     */
    Smb4KHostItem( const Smb4KHostItem &host );

    /**
     * The empty constructor.
     */
    Smb4KHostItem() {}

    /**
     * The destructor.
     */
    ~Smb4KHostItem();

    /**
     * Returns the workgroup the host is in.
     */
    const TQString &workgroup() const { return m_workgroup; }

    /**
     * Returns the name of the host.
     */
    const TQString &name() const { return m_name; }

    /**
     * Returns the IP address of the host.
     */
    const TQString &ip() const { return m_ip; }

    /**
     * Returns the comment for this host.
     */
    const TQString &comment() const { return m_comment; }

    /**
     * Sets the Server string that is reported by the host.
     */
    void setServerString( const TQString &server );

    /**
     * Returns the Server string.
     */
    const TQString &serverString() const { return m_server_string; }

    /**
     * Sets the OS string that is reported by the host.
     */
    void setOSString( const TQString &os );

    /**
     * Returns the OS string.
     */
    const TQString &osString() const { return m_os_string; }

    /**
     * This functions determines whether this host should be
     * registered as a master browser.
     *
     * @param master        Set this to TRUE if the host is a master browser.
     */
    void setMaster( bool master );

    /**
     * This function tells you if the host is a master or not.
     *
     * @returns             TRUE if the host is a master browser.
     */
    const bool isMaster() const { return m_master; }

    /**
     * This function sets the IP address of a host.
     *
     * @param ip            The IP address of a host
     */
    void setIPAddress( const TQString &ip );

    /**
     * This function sets the command for a host.
     *
     * @param comment       The comment
     */
    void setComment( const TQString &comment );

    /**
     * This function is used to tell the host item, if a
     * check for the IP address has already been performed.
     *
     * @param yes           Should be set to TRUE if a check was performed.
     */
    void setIPAddressChecked( bool yes );

    /**
     * Tells if a check for the IP address has already been performed.
     *
     * @returns             TRUE if a check was performed, and FALSE otherwise.
     */
    const bool ipAddressChecked() const { return m_ip_checked; }

    /**
     * This function is used to tell the host item, if a
     * check for the information (OS and Server string ) has already been performed.
     *
     * @param yes           Should be set to TRUE if a check was performed.
     */
    void setInfoChecked( bool yes );

    /**
     * Tells if a check for the information (OS and Server string) has already
     * been performed.
     *
     * @returns             TRUE is the check was performed previously.
     */
    const bool infoChecked() const { return m_info_checked; }

  private:
    /**
     * The name of the workgroup.
     */
    TQString m_workgroup;

    /**
     * The name of the host.
     */
    TQString m_name;

    /**
     * The comment for this host.
     */
    TQString m_comment;

    /**
     * The IP address of the host.
     */
    TQString m_ip;

    /**
     * The Server string as reported by the host.
     */
    TQString m_server_string;

    /**
     * The operating system string as reported by the host.
     */
    TQString m_os_string;

    /**
     * This boolian determines if the host is a master browser
     * or not.
     */
    bool m_master;

    /**
     * This boolean tells if a check for the IP address was already
     * performed.
     */
    bool m_ip_checked;

    /**
     * This boolean tells if a check for the information (OS and server string)
     * was already performed.
     */
    bool m_info_checked;

    /**
     * This function checks if the IP address is valid, i.e. the
     * IP address is either IP v4 or IP v6. It returns either TRUE
     * or FALSE.
     *
     * @param ip            The IP address that's going to be checked.
     *
     * @returns TRUE if the IP address is valid and FALSE otherwise.
     */
    bool ipIsValid( const TQString &ip );
};


/**
 * This class provides a container for a share found in the
 * network neighborhood.
 */

class TDE_EXPORT Smb4KShareItem
{
  public:
    /**
     * The constructor.
     *
     * @param workgroup         The workgroup/domain name.
     *
     * @param host              The name of the host where the share is located.
     *
     * @param name              The name of the share.
     *
     * @param type              The type of the share as returned by the Samba programs, i.e.
     *                          "Disk", "Printer", "IPC$" or "ADMIN$".
     *
     * @param comment           The comment of the share.
     */
    Smb4KShareItem( const TQString &workgroup,
                    const TQString &host,
                    const TQString &name,
                    const TQString &type,
                    const TQString &comment );

    /**
     * Empty constructor.
     */
    Smb4KShareItem() {}

    /**
     * The destructor.
     */
    ~Smb4KShareItem();

    /**
     * Returns the workgroup of the host where the share is located.
     */
    const TQString &workgroup() const { return m_workgroup; }

    /**
     * Returns the name of the host where the share is located.
     */
    const TQString &host() const { return m_host; }

    /**
     * Returns the name of the share.
     */
    const TQString &name() const { return m_name; }

    /**
     * Returns the type of the share.
     */
    const TQString &plainType() const { return m_type; }

    /**
     * Returns a translated version of the type of the share.
     *
     * @returns           The translated share type
     */
    const TQString translatedType() const;

    /**
     * Returns the comment for this share.
     */
    const TQString &comment() const { return m_comment; }

    /**
     * This function tells if the share is a hidden one.
     *
     * @returns           TRUE is the share is a hidden one and FALSE otherwise.
     */
    bool isHidden() const;

    /**
     * This function is TRUE if the share is a printer and
     * FALSE otherwise.
     *
     * @returns	          TRUE if the share is a printer
     */
    bool isPrinter() const;

    /**
     * This function returns TRUE if the share is an IPC$
     * share and FALSE otherwise.
     *
     * @returns           TRUE if the share is an IPC$ share
     */
    bool isIPC() const;

    /**
     * This function returns TRUE if the share is an ADMIN$
     * share and FALSE otherwise.
     *
     * @returns           TRUE if the share is an ADMIN$ share
     */
    bool isADMIN() const;

  private:
    /**
     * The workgroup object.
     */
    TQString m_workgroup;

    /**
     * The host name.
     */
    TQString m_host;

    /**
     * The name of the share.
     */
    TQString m_name;

    /**
     * The type of the share.
     */
    TQString m_type;

    /**
     * The comment for this share.
     */
    TQString m_comment;
};

#endif