summaryrefslogtreecommitdiffstats
path: root/tdeio/kpasswdserver/kpasswdserver.h
blob: c31e644496ce55d3cea662876604783b02efe9d1 (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
/*
    This file is part of the KDE Password Server

    Copyright (C) 2002 Waldo Bastian (bastian@kde.org)

    This library is free software; you can redistribute it and/or
    modify it under the terms of the GNU General Public License
    version 2 as published by the Free Software Foundation.

    This software 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 library; see the file COPYING. If not, write to
    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
    Boston, MA 02110-1301, USA.
*/
//----------------------------------------------------------------------------
//
// KDE Password Server
// $Id$

#ifndef KPASSWDSERVER_H
#define KPASSWDSERVER_H

#include <tqdict.h>
#include <tqintdict.h>

#include <dcopclient.h>
#include <tdeio/authinfo.h>
#include <kded/kdedmodule.h>

namespace TDEWallet {
    class Wallet;
}

class KPasswdServer : public KDEDModule
{
  TQ_OBJECT
  K_DCOP
public:
  KPasswdServer(const TQCString &);
  ~KPasswdServer();

k_dcop:
  // KDE4 merge
  TDEIO::AuthInfo checkAuthInfo(TDEIO::AuthInfo, long, unsigned long);
  TDEIO::AuthInfo checkAuthInfo(TDEIO::AuthInfo, long);
  TDEIO::AuthInfo queryAuthInfo(TDEIO::AuthInfo, TQString, long, long, unsigned long);
  TDEIO::AuthInfo queryAuthInfo(TDEIO::AuthInfo, TQString, long, long);
  void addAuthInfo(TDEIO::AuthInfo, long);

public slots:
  void processRequest();
  // Remove all authentication info associated with windowId
  void removeAuthForWindowId(long windowId);

protected:
  struct AuthInfo;

  TQString createCacheKey( const TDEIO::AuthInfo &info );
  const AuthInfo *findAuthInfoItem(const TQString &key, const TDEIO::AuthInfo &info);
  void removeAuthInfoItem(const TQString &key, const TDEIO::AuthInfo &info);
  void addAuthInfoItem(const TQString &key, const TDEIO::AuthInfo &info, long windowId, long seqNr, bool canceled);
  TDEIO::AuthInfo copyAuthInfo(const AuthInfo *);
  void updateAuthExpire(const TQString &key, const AuthInfo *, long windowId, bool keep);
  int findWalletEntry( const TQMap<TQString,TQString>& map, const TQString& username );
  bool openWallet( WId windowId );

  struct AuthInfo {
    AuthInfo() { expire = expNever; isCanceled = false; seqNr = 0; }

    KURL url;
    TQString directory;
    TQString username;
    TQString password;
    TQString realmValue;
    TQString digestInfo;

    enum { expNever, expWindowClose, expTime } expire;
    TQValueList<long> windowList;
    unsigned long expireTime;
    long seqNr;

    bool isCanceled;
  };

  class AuthInfoList : public TQPtrList<AuthInfo>
  {
    public:
      AuthInfoList() { setAutoDelete(true); }
      int compareItems(TQPtrCollection::Item n1, TQPtrCollection::Item n2);
  };

  TQDict< AuthInfoList > m_authDict;

  struct Request {
     DCOPClient *client;
     DCOPClientTransaction *transaction;
     TQString key;
     TDEIO::AuthInfo info;
     TQString errorMsg;
     long windowId;
     long seqNr;
     bool prompt;
  };

  TQPtrList< Request > m_authPending;
  TQPtrList< Request > m_authWait;
  TQIntDict<TQStringList> mWindowIdList;
  DCOPClient *m_dcopClient;
  TDEWallet::Wallet* m_wallet;
  long m_seqNr;
};

#endif