[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-commits
Subject: kdesupport/qca
From: Justin Karneges <infiniti () affinix ! com>
Date: 2006-04-02 5:16:36
Message-ID: 1143954996.082497.23321.nullmailer () svn ! kde ! org
[Download RAW message or body]
SVN commit 525453 by infiniti:
support changing security mode on-the-fly. more functions: release, finalizeAndRelease, takeBytesToWrite
M +10 -3 include/QtCrypto/qpipe.h
M +82 -21 src/support/qpipe.cpp
--- trunk/kdesupport/qca/include/QtCrypto/qpipe.h #525452:525453
@@ -101,18 +101,19 @@
Q_PIPE_ID id() const;
QString idAsString() const;
+ void take(Q_PIPE_ID id, QPipeDevice::Type t);
#ifdef QPIPE_SECURE
- void take(Q_PIPE_ID id, QPipeDevice::Type t, bool secure = false);
-#else
- void take(Q_PIPE_ID id, QPipeDevice::Type t);
+ void setSecurityEnabled(bool secure);
#endif
void enable();
void close();
+ void release();
#ifdef Q_OS_WIN
bool winDupHandle();
#endif
void finalize(); // do an immediate read, and invalidate
+ void finalizeAndRelease(); // same as above, but don't close pipe
int bytesAvailable() const;
int bytesToWrite() const;
@@ -127,6 +128,12 @@
void writeSecure(const QSecureArray &a);
#endif
+ QByteArray takeBytesToWrite();
+
+#ifdef QPIPE_SECURE
+ QSecureArray takeBytesToWriteSecure();
+#endif
+
signals:
void readyRead();
void bytesWritten(int bytes);
--- trunk/kdesupport/qca/src/support/qpipe.cpp #525452:525453
@@ -908,11 +908,11 @@
closing = false;
curWrite.clear();
#ifdef QPIPE_SECURE
+ secure = false;
sec_curWrite.clear();
#endif
- // always clear the write buffers, no sense in keeping them
- if(mode >= ResetSessionAndData || type == QPipeDevice::Write)
+ if(mode >= ResetSessionAndData)
{
buf.clear();
#ifdef QPIPE_SECURE
@@ -941,10 +941,10 @@
{
#ifdef QPIPE_SECURE
if(secure)
- return PIPEEND_READBUF_SEC - sec_buf.size();
+ return qMax(PIPEEND_READBUF_SEC - sec_buf.size(), 0);
else
#endif
- return PIPEEND_READBUF - buf.size();
+ return qMax(PIPEEND_READBUF - buf.size(), 0);
}
void appendArray(QByteArray *a, const QByteArray &b)
@@ -1060,17 +1060,20 @@
if(secure)
{
takeArray(&sec_buf, lastWrite);
- sec_curWrite.clear();
moreData = !sec_buf.isEmpty();
}
else
#endif
{
takeArray(&buf, lastWrite);
- curWrite.clear();
moreData = !buf.isEmpty();
}
+#ifdef QPIPE_SECURE
+ sec_curWrite.clear();
+#endif
+ curWrite.clear();
+
int x = lastWrite;
lastWrite = 0;
@@ -1222,18 +1225,33 @@
return QString::number(d->pipe.idAsInt());
}
-#ifdef QPIPE_SECURE
-void QPipeEnd::take(Q_PIPE_ID id, QPipeDevice::Type t, bool secure)
-#else
void QPipeEnd::take(Q_PIPE_ID id, QPipeDevice::Type t)
-#endif
{
reset();
+ d->setup(id, t);
+}
+
#ifdef QPIPE_SECURE
+void QPipeEnd::setSecurityEnabled(bool secure)
+{
+ // no change
+ if(d->secure == secure)
+ return;
+
+ if(secure)
+ {
+ d->sec_buf = d->buf;
+ d->buf.clear();
+ }
+ else
+ {
+ d->buf = d->sec_buf.toByteArray();
+ d->sec_buf.clear();
+ }
+
d->secure = secure;
+}
#endif
- d->setup(id, t);
-}
void QPipeEnd::enable()
{
@@ -1253,6 +1271,15 @@
d->closeTrigger.start(0);
}
+void QPipeEnd::release()
+{
+ if(!isValid())
+ return;
+
+ d->pipe.release();
+ d->reset(ResetSession);
+}
+
#ifdef Q_OS_WIN
bool QPipeEnd::winDupHandle()
{
@@ -1262,11 +1289,25 @@
void QPipeEnd::finalize()
{
+ if(!isValid())
+ return;
+
if(d->pipe.bytesAvailable())
d->doReadActual(false);
d->reset(ResetSession);
}
+void QPipeEnd::finalizeAndRelease()
+{
+ if(!isValid())
+ return;
+
+ if(d->pipe.bytesAvailable())
+ d->doReadActual(false);
+ d->pipe.release();
+ d->reset(ResetSession);
+}
+
int QPipeEnd::bytesAvailable() const
{
return d->pendingSize();
@@ -1319,6 +1360,30 @@
}
#endif
+QByteArray QPipeEnd::takeBytesToWrite()
+{
+ // only call this on inactive sessions
+ if(isValid())
+ return QByteArray();
+
+ QByteArray a = d->buf;
+ d->buf.clear();
+ return a;
+}
+
+#ifdef QPIPE_SECURE
+QSecureArray QPipeEnd::takeBytesToWriteSecure()
+{
+ // only call this on inactive sessions
+ if(isValid())
+ return QSecureArray();
+
+ QSecureArray a = d->sec_buf;
+ d->sec_buf.clear();
+ return a;
+}
+#endif
+
//----------------------------------------------------------------------------
// QPipe
//----------------------------------------------------------------------------
@@ -1354,25 +1419,21 @@
HANDLE r, w;
if(!CreatePipe(&r, &w, &secAttr, 0))
return false;
-#ifdef QPIPE_SECURE
- i.take(r, QPipeDevice::Read, secure);
- o.take(w, QPipeDevice::Write, secure);
-#else
i.take(r, QPipeDevice::Read);
o.take(w, QPipeDevice::Write);
#endif
-#endif
+
#ifdef Q_OS_UNIX
int p[2];
if(pipe(p) == -1)
return false;
-#ifdef QPIPE_SECURE
- i.take(p[0], QPipeDevice::Read, secure);
- o.take(p[1], QPipeDevice::Write, secure);
-#else
i.take(p[0], QPipeDevice::Read);
o.take(p[1], QPipeDevice::Write);
#endif
+
+#ifdef QPIPE_SECURE
+ i.setSecurityEnabled(secure);
+ o.setSecurityEnabled(secure);
#endif
return true;
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic