[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-core-devel
Subject:    KPGP patch: pgp auto detection
From:       Christian Gebauer <gebauer () bigfoot ! com>
Date:       2001-06-02 18:47:05
[Download RAW message or body]

Hi,

KPGP currently uses auto detection of the pgp version as default setting,
which is probably a good idea. Unfortunally the auto detection code will
start the external pgp binary on every start of KMail/KNode, if you have 
pgp 2.x or 6.x installed.

Therefore I would like to apply the attached patch to KPGP. 
With this patch the KPgpBase instance will be created when it
is first needed, not on startup. Unfortunally I had to make
a bunch of methods in KPGP non-const, but IHMO starting external
application during startup is way to costly, so I see no
alternative.

Opinions?

Greetings
Christian
-- 
>><< Christian Gebauer >><< gebauer@bigfoot.com >><< ICQ 14916141 >><<
["kpgp.patch" (text/plain)]

Index: kpgp.cpp
===================================================================
RCS file: /home/kde/kdenetwork/libkdenetwork/kpgp.cpp,v
retrieving revision 1.10
diff -u -3 -p -r1.10 kpgp.cpp
--- kpgp.cpp	2001/05/29 19:16:35	1.10
+++ kpgp.cpp	2001/06/02 18:36:42
@@ -43,7 +43,7 @@ Kpgp::Kpgp()
     kdDebug(5100) << "creating new pgp object" << endl;
   }
   kpgpObject=kpgpod.setObject(this);
-  pgp = NULL;
+  pgp = 0;
 
   config = new KSimpleConfig("kpgprc" );
 
@@ -70,7 +70,12 @@ Kpgp::init()
 
   // do we have a pgp executable
   checkForPGP();
-  assignPGPBase();
+  // create the KpgpBase object later when it is
+  // needed to avoid the costly check done for
+  // the autodetection of PGP 2/6
+  //assignPGPBase();
+  delete pgp;
+  pgp=0;
 
   // get public keys
   // No! This takes time since pgp takes some ridicules
@@ -93,6 +98,8 @@ Kpgp::readConfig()
 void
 Kpgp::writeConfig(bool sync)
 {
+  if (0 == pgp) assignPGPBase();
+
   config->writeEntry("storePass",storePass);
   config->writeEntry("showEncryptionResult", showEncryptionResult);
   config->writeEntry("pgpType",(int) pgpType);
@@ -102,30 +109,39 @@ Kpgp::writeConfig(bool sync)
   if(sync)
     config->sync();
 
-  assignPGPBase();
+  delete pgp;
+  pgp = 0;
 }
 
 void
 Kpgp::setUser(const QString aUser)
 {
+  if (0 == pgp) assignPGPBase();
+
   pgp->setUser(aUser);
 }
 
 const QString
-Kpgp::user(void) const
+Kpgp::user(void)
 {
+  if (0 == pgp) assignPGPBase();
+
   return pgp->user();
 }
 
 void
 Kpgp::setEncryptToSelf(bool flag)
 {
+  if (0 == pgp) assignPGPBase();
+
   pgp->setEncryptToSelf(flag);
 }
 
 bool
-Kpgp::encryptToSelf(void) const
+Kpgp::encryptToSelf(void)
 {
+  if (0 == pgp) assignPGPBase();
+
   return pgp->encryptToSelf();
 }
 
@@ -148,6 +164,8 @@ Kpgp::setMessage(const QCString mess)
   int index;
   int retval = 0;
 
+  if (0 == pgp) assignPGPBase();
+
   clear();
 
   if(havePgp)
@@ -206,14 +224,18 @@ Kpgp::backmatter(void) const
 }
 
 const QCString
-Kpgp::message(void) const
+Kpgp::message(void)
 {
+  if (0 == pgp) assignPGPBase();
+
   return pgp->message();
 }
 
 bool
 Kpgp::prepare(bool needPassPhrase)
 {
+  if (0 == pgp) assignPGPBase();
+
   if(!havePgp)
   {
     errMsg = i18n("Couldn't find PGP executable.\n"
@@ -256,6 +278,8 @@ Kpgp::decrypt(void)
 {
   int retval;
 
+  if (0 == pgp) assignPGPBase();
+
   // do we need to do anything?
   if(!pgp->isEncrypted()) return TRUE;
   // everything ready
@@ -295,6 +319,8 @@ Kpgp::encryptFor(const QStrList& aPers, 
   int ret;
   QString aStr;
 
+  if (0 == pgp) assignPGPBase();
+
   persons.clear();
   noKeyFor.clear();
 
@@ -307,7 +333,7 @@ Kpgp::encryptFor(const QStrList& aPers, 
       if(!aStr.isEmpty())
         persons.append(aStr);
       else
-	noKeyFor.append(pers);
+        noKeyFor.append(pers);
       ++it;
     }
     if(persons.isEmpty())
@@ -330,14 +356,14 @@ Kpgp::encryptFor(const QStrList& aPers, 
       ++it;
       while((pers = it.current()))
       {
-	aStr += ",\n";
-	aStr += pers;
-	++it;
+        aStr += ",\n";
+        aStr += pers;
+        ++it;
       }
       if(it.count() > 1)
-	aStr += i18n("These persons will not be able to decrypt the message.\n");
+        aStr += i18n("These persons will not be able to decrypt the message.\n");
       else
-	aStr += i18n("This person will not be able to decrypt the message.\n");
+        aStr += i18n("This person will not be able to decrypt the message.\n");
 
       int n = 0;
       while (this->isBusy()) { n++; this->idle(); }
@@ -433,6 +459,8 @@ Kpgp::doEncSign(QStrList persons, bool s
 {
   int retval;
 
+  if (0 == pgp) assignPGPBase();
+
   // to avoid error messages in case pgp is not installed
   if(!havePgp)
     return KpgpBase::OK;
@@ -456,6 +484,8 @@ Kpgp::doEncSign(QStrList persons, bool s
 bool
 Kpgp::signKey(QString _key)
 {
+  if (0 == pgp) assignPGPBase();
+
   if (!prepare(TRUE)) return FALSE;
   if(pgp->signKey(_key, passphrase) & KpgpBase::ERROR)
   {
@@ -469,6 +499,8 @@ Kpgp::signKey(QString _key)
 const QStrList*
 Kpgp::keys(void)
 {
+  if (0 == pgp) assignPGPBase();
+
   if (!prepare()) return NULL;
 
   if(publicKeys.isEmpty()) publicKeys = pgp->pubKeys();
@@ -478,6 +510,8 @@ Kpgp::keys(void)
 bool
 Kpgp::havePublicKey(QString _person)
 {
+  if (0 == pgp) assignPGPBase();
+
   if(!havePgp) return true;
   if (needPublicKeys)
   {
@@ -510,6 +544,8 @@ Kpgp::havePublicKey(QString _person)
 QString
 Kpgp::getPublicKey(QString _person)
 {
+  if (0 == pgp) assignPGPBase();
+
   // just to avoid some error messages
   if(!havePgp) return QString::null;
   if (needPublicKeys)
@@ -552,48 +588,64 @@ Kpgp::getPublicKey(QString _person)
 QString
 Kpgp::getAsciiPublicKey(QString _person)
 {
+  if (0 == pgp) assignPGPBase();
+
   return pgp->getAsciiPublicKey(_person);
 }
 
 bool
-Kpgp::isEncrypted(void) const
+Kpgp::isEncrypted(void)
 {
+  if (0 == pgp) assignPGPBase();
+
   return pgp->isEncrypted();
 }
 
 const QStrList*
-Kpgp::receivers(void) const
+Kpgp::receivers(void)
 {
+  if (0 == pgp) assignPGPBase();
+
   return pgp->receivers();
 }
 
 const QString
-Kpgp::KeyToDecrypt(void) const
+Kpgp::KeyToDecrypt(void)
 {
+  if (0 == pgp) assignPGPBase();
+
   return pgp->encryptedFor();
 }
 
 bool
-Kpgp::isSigned(void) const
+Kpgp::isSigned(void)
 {
+  if (0 == pgp) assignPGPBase();
+
   return pgp->isSigned();
 }
 
 QString
-Kpgp::signedBy(void) const
+Kpgp::signedBy(void)
 {
+  if (0 == pgp) assignPGPBase();
+
   return pgp->signedBy();
 }
 
 QString
-Kpgp::signedByKey(void) const
+Kpgp::signedByKey(void)
 {
+  if (0 == pgp) assignPGPBase();
+
   return pgp->signedByKey();
 }
 
 bool
-Kpgp::goodSignature(void) const
+Kpgp::goodSignature(void)
 {
+  if (0 == pgp) assignPGPBase();
+
   return pgp->isSigGood();
 }
 
Index: kpgp.h
===================================================================
RCS file: /home/kde/kdenetwork/libkdenetwork/kpgp.h,v
retrieving revision 1.1
diff -u -3 -p -r1.1 kpgp.h
--- kpgp.h	2001/04/08 12:26:53	1.1
+++ kpgp.h	2001/06/02 18:36:42
@@ -70,7 +70,7 @@ public:
     */
   virtual bool setMessage(const QCString mess);
   /** gets the de- (or en)crypted message */
-  virtual const QCString message(void) const;
+  virtual const QCString message(void);
   /** gets the part before the decrypted message */
   virtual const QString frontmatter(void) const;
   /** gets the part after the decrypted message */
@@ -100,21 +100,21 @@ public:
   QString getAsciiPublicKey(QString _person);
 
   /** is the message encrypted ? */
-  bool isEncrypted(void) const;
+  bool isEncrypted(void);
   /** the persons who can decrypt the message */
-  const QStrList* receivers(void) const;
+  const QStrList* receivers(void);
   /** shows the secret key which is needed
     to decrypt the message */
-  const QString KeyToDecrypt(void) const;
+  const QString KeyToDecrypt(void);
 
   /** is the message signed by someone */
-  bool isSigned(void) const;
+  bool isSigned(void);
   /** it is signed by ... */
-  QString signedBy(void) const;
+  QString signedBy(void);
   /** keyID of signer */
-  QString signedByKey(void) const;
+  QString signedByKey(void);
   /** is the signature good ? */
-  bool goodSignature(void) const;
+  bool goodSignature(void);
 
   /** change the passphrase of the actual secret key */
   bool changePassPhrase(const QString oldPass, const QString newPass);
@@ -126,11 +126,11 @@ public:
    * by default, pgp uses the identity which was generated last. */
   void setUser(const QString user);
   /** Returns the actual user identity. */
-  const QString user(void) const;
+  const QString user(void);
 
   /** always encrypt message to oneself? */
   void setEncryptToSelf(bool flag);
-  bool encryptToSelf(void) const;
+  bool encryptToSelf(void);
 
   /** store passphrase in pgp object
     Problem: passphrase stays in memory.


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic