[omapd] r188 committed - merged performance improvement branch (branches/lfu)

0 views
Skip to first unread message

om...@googlecode.com

unread,
Jun 26, 2013, 8:03:23 PM6/26/13
to omapd...@googlegroups.com
Revision: 188
Author: fu...@asguardnetworks.com
Date: Wed Jun 26 17:02:49 2013
Log: merged performance improvement branch (branches/lfu)
http://code.google.com/p/omapd/source/detail?r=188

Modified:
/trunk
/trunk/clientconfiguration.cpp
/trunk/clientconfiguration.h
/trunk/clienthandler.cpp
/trunk/clienthandler.h
/trunk/clientparser.cpp
/trunk/clientparser.h
/trunk/identifier.cpp
/trunk/identifier.h
/trunk/main.cpp
/trunk/mapclient.cpp
/trunk/mapclient.h
/trunk/maprequest.cpp
/trunk/maprequest.h
/trunk/mapresponse.cpp
/trunk/mapresponse.h
/trunk/mapsessions.cpp
/trunk/mapsessions.h
/trunk/metadata.cpp
/trunk/metadata.h
/trunk/omapdconfig.cpp
/trunk/omapdconfig.h
/trunk/server.cpp
/trunk/server.h
/trunk/subscription.cpp
/trunk/subscription.h

=======================================
--- /trunk/clientconfiguration.cpp Thu May 23 16:56:04 2013
+++ /trunk/clientconfiguration.cpp Wed Jun 26 17:02:49 2013
@@ -28,7 +28,7 @@
_authz = OmapdConfig::DenyAll;
}

-void ClientConfiguration::createBasicAuthClient(QString clientName,
QString username, QString password, OmapdConfig::AuthzOptions authz,
QString metadataPolicy)
+void ClientConfiguration::createBasicAuthClient(const QString& clientName,
const QString& username, const QString& password, OmapdConfig::AuthzOptions
authz, const QString& metadataPolicy)
{
_authType = MapRequest::AuthBasic;
_authz = authz;
@@ -38,7 +38,7 @@
_metadataPolicy = metadataPolicy;
}

-void ClientConfiguration::createCertAuthClient(QString clientName, QString
certFile, QString caCertFile, OmapdConfig::AuthzOptions authz, QString
metadataPolicy)
+void ClientConfiguration::createCertAuthClient(const QString& clientName,
const QString& certFile, const QString& caCertFile,
OmapdConfig::AuthzOptions authz, const QString& metadataPolicy)
{
_authType = MapRequest::AuthCert;
_authz = authz;
@@ -49,7 +49,7 @@
_metadataPolicy = metadataPolicy;
}

-void ClientConfiguration::createCAAuthClient(QString clientPrefix, QString
issuingCACertFile, QString caCertFile, OmapdConfig::AuthzOptions authz,
QString metadataPolicy, QString blacklistDir)
+void ClientConfiguration::createCAAuthClient(const QString& clientPrefix,
const QString& issuingCACertFile, const QString& caCertFile,
OmapdConfig::AuthzOptions authz, const QString& metadataPolicy, const
QString& blacklistDir)
{
_authType = MapRequest::AuthCACert;
_authz = authz;
=======================================
--- /trunk/clientconfiguration.h Thu May 23 16:56:04 2013
+++ /trunk/clientconfiguration.h Wed Jun 26 17:02:49 2013
@@ -29,20 +29,20 @@
{
public:
ClientConfiguration();
- void createBasicAuthClient(QString clientName, QString username,
QString password, OmapdConfig::AuthzOptions authz, QString metadataPolicy);
- void createCertAuthClient(QString clientName, QString certFile,
QString caCertFile, OmapdConfig::AuthzOptions authz, QString
metadataPolicy);
- void createCAAuthClient(QString clientPrefix, QString
issuingCACertFile, QString caCertFile, OmapdConfig::AuthzOptions authz,
QString metadataPolicy, QString blacklistDir = QString());
+ void createBasicAuthClient(const QString& clientName, const QString&
username, const QString& password, OmapdConfig::AuthzOptions authz, const
QString& metadataPolicy);
+ void createCertAuthClient(const QString& clientName, const QString&
certFile, const QString& caCertFile, OmapdConfig::AuthzOptions authz, const
QString& metadataPolicy);
+ void createCAAuthClient(const QString& clientPrefix, const QString&
issuingCACertFile, const QString& caCertFile, OmapdConfig::AuthzOptions
authz, const QString& metadataPolicy, const QString& blacklistDir = "");

- QString metadataPolicy() { return _metadataPolicy; }
- QString name() { return _name; }
- QString username() { return _username; }
- QString password() { return _password; }
- QString certFileName() { return _certFileName; }
- QString caCertFileName() { return _caCertFileName; }
- QString blacklistDirectory() { return _blacklistDirectory; }
- bool haveClientCert() { return _haveClientCert; }
- MapRequest::AuthenticationType authType() { return _authType; }
- OmapdConfig::AuthzOptions authz() { return _authz; }
+ const QString& metadataPolicy() const { return _metadataPolicy; }
+ const QString& name() const { return _name; }
+ const QString& username() const { return _username; }
+ const QString& password() const { return _password; }
+ const QString& certFileName() const { return _certFileName; }
+ const QString& caCertFileName() const { return _caCertFileName; }
+ const QString& blacklistDirectory() { return _blacklistDirectory; }
+ bool haveClientCert() const { return _haveClientCert; }
+ MapRequest::AuthenticationType authType() const { return _authType; }
+ OmapdConfig::AuthzOptions authz() const { return _authz; }

private:
QString _metadataPolicy;
=======================================
--- /trunk/clienthandler.cpp Tue Mar 19 11:59:00 2013
+++ /trunk/clienthandler.cpp Wed Jun 26 17:02:49 2013
@@ -30,7 +30,7 @@
#include "mapsessions.h"
#include "clientconfiguration.h"

-QString ClientHandler::buildDN(QSslCertificate cert,
ClientHandler::CertInfoTarget target)
+QString ClientHandler::buildDN(const QSslCertificate& cert, const
ClientHandler::CertInfoTarget& target)
{
QStringList dnElements;
QString certDN;
@@ -79,7 +79,7 @@

}

-ClientHandler::ClientHandler(MapGraphInterface *mapGraph, QString
authToken, QObject *parent) :
+ClientHandler::ClientHandler(MapGraphInterface *mapGraph, const QString&
authToken, QObject *parent) :
QSslSocket(parent), _mapGraph(mapGraph), _authToken(authToken)
{
_omapdConfig = OmapdConfig::getInstance();
@@ -95,7 +95,7 @@
QString publisherId = _mapSessions->pubIdForAuthToken(_authToken);

if (!publisherId.isEmpty()) {
- if
(_mapSessions->removeSubscriptionListForClient(_authToken).size() > 0) {
+ if (_mapSessions->removeSubscriptionListForClient(_authToken) > 0)
{
if
(_omapdConfig->valueFor("debug_level").value<OmapdConfig::IfmapDebugOptions>().testFlag(OmapdConfig::ShowClientOps))
{
qDebug() << __PRETTY_FUNCTION__ << ":" << "Removing
subscriptions for publisherId:"
<< publisherId;
@@ -112,7 +112,7 @@
if (_parser) delete _parser;
}

-void ClientHandler::clientSocketError(QAbstractSocket::SocketError
socketError)
+void ClientHandler::clientSocketError(const QAbstractSocket::SocketError&
socketError)
{
qDebug() << __PRETTY_FUNCTION__ << ":" << "Socket error:" <<
socketError
<< errorString()
@@ -190,7 +190,7 @@
<< "------------->:" << sState;
}

-void ClientHandler::processHeader(QNetworkRequest requestHdrs)
+void ClientHandler::processHeader(const QNetworkRequest& requestHdrs)
{
// TODO: Improve http protocol support
if (requestHdrs.hasRawHeader(QByteArray("Expect"))) {
@@ -252,7 +252,7 @@

}

-void ClientHandler::sendHttpResponse(int hdrNumber, QString hdrText)
+void ClientHandler::sendHttpResponse(int hdrNumber, const QString& hdrText)
{
if
(_omapdConfig->valueFor("debug_level").value<OmapdConfig::IfmapDebugOptions>().testFlag(OmapdConfig::ShowRawSocketData))
qDebug() << __PRETTY_FUNCTION__ << ":" << "Sending Http Response:"
<< hdrNumber << hdrText;
@@ -361,22 +361,22 @@
this, SLOT(processHeader(QNetworkRequest)));
}

-void ClientHandler::sendPollResponse(QByteArray response,
MapRequest::RequestVersion reqVersion)
+void ClientHandler::sendPollResponse(const QByteArray& response, const
MapRequest::RequestVersion& reqVersion)
{
this->sendResponse(response, reqVersion);
}

-void ClientHandler::sendMapResponse(MapResponse &mapResponse)
+void ClientHandler::sendMapResponse(const MapResponse &mapResponse)
{
this->sendResponse(mapResponse.responseData(),
mapResponse.requestVersion());
}

-void ClientHandler::sendResponse(QByteArray response,
MapRequest::RequestVersion reqVersion)
+void ClientHandler::sendResponse(const QByteArray& response, const
MapRequest::RequestVersion& reqVersion)
{
QByteArray compResponse;
QHttpResponseHeader header(200,"OK");
if (_useCompression) {
- compResponse = compressResponse(response);
+ compressResponse(response, compResponse);
header.setValue("Content-Encoding", "gzip");
header.setValue("Transfer-Encoding","chunked");
header.setContentLength(compResponse.size());
@@ -418,10 +418,8 @@
}
}

-QByteArray ClientHandler::compressResponse(QByteArray uncompressed)
+void ClientHandler::compressResponse(const QByteArray& uncompressed,
QByteArray& deflated )
{
- QByteArray deflated;
-
deflated = qCompress(uncompressed);

// eliminate qCompress size on first 4 bytes and 2 byte header
@@ -460,14 +458,12 @@
footer[4] = (isize & 0x000000ff);

deflated.append(footer);
-
- return deflated;
}

void ClientHandler::processClientRequest()
{
MapRequest::RequestType reqType = _parser->requestType();
- QVariant clientRequest = _parser->request();
+ const QVariant& clientRequest = _parser->request();

MapResponse *clientFaultResponse;

@@ -496,8 +492,14 @@
processPurgePublisher(clientRequest);
break;
case MapRequest::Publish:
+ {
+ // LFu - remove this
+ // QTime timer;
+ // timer.start();
processPublish(clientRequest);
+ // qDebug() << "~~processing publish request took " <<
timer.elapsed() << " ms";
break;
+ }
case MapRequest::Subscribe:
processSubscribe(clientRequest);
break;
@@ -511,7 +513,7 @@

}

-void ClientHandler::processNewSession(QVariant clientRequest)
+void ClientHandler::processNewSession(const QVariant& clientRequest)
{
NewSessionRequest nsReq = clientRequest.value<NewSessionRequest>();
MapResponse nsResp(nsReq.requestVersion());
@@ -549,7 +551,7 @@
sendMapResponse(nsResp);
}

-void ClientHandler::processRenewSession(QVariant clientRequest)
+void ClientHandler::processRenewSession(const QVariant& clientRequest)
{
/* IFMAP20: 4.4: In order to keep an IF-MAP session from timing out,
a MAP Client MUST either keep the underlying TCP connection
associated
@@ -569,7 +571,7 @@
sendMapResponse(rsResp);
}

-void ClientHandler::processEndSession(QVariant clientRequest)
+void ClientHandler::processEndSession(const QVariant& clientRequest)
{
EndSessionRequest esReq = clientRequest.value<EndSessionRequest>();

@@ -593,7 +595,7 @@
sendMapResponse(esResp);
}

-void ClientHandler::processAttachSession(QVariant clientRequest)
+void ClientHandler::processAttachSession(const QVariant& clientRequest)
{
AttachSessionRequest asReq =
clientRequest.value<AttachSessionRequest>();
MapResponse asResp(asReq.requestVersion());
@@ -656,7 +658,8 @@
QList<PublishOperation> publishOperations = pubReq.publishOperations();
QMutableListIterator<PublishOperation> pubOperIt(publishOperations);
while (pubOperIt.hasNext()) {
- PublishOperation pubOperCheck = pubOperIt.next();
+ // LFu: use reference here to avoid copy
+ PublishOperation& pubOperCheck = pubOperIt.next();

// Only check operations that come later in the request against
the current one
for (int i=pubOperCheck._operationNumber;
i<publishOperations.size(); i++) {
@@ -720,7 +723,8 @@
<< "to number of metadata elements:"
<< keepMetaList.size();
}
pubOperCheck._metadata = keepMetaList;
- pubOperIt.setValue(pubOperCheck);
+ // LFu: no need to setValue since we're
manipulating the list element directly
+ // pubOperIt.setValue(pubOperCheck);
}

} else if (pubOperCheck._publishType ==
PublishOperation::Update &&
@@ -753,7 +757,8 @@
<< "to number of metadata
elements:" << keepMetaList.size();
}
pubOperCheck._metadata = keepMetaList;
- pubOperIt.setValue(pubOperCheck);
+ // LFu: no need to setValue since we're
manipulating the list element directly
+ // pubOperIt.setValue(pubOperCheck);
}
}

@@ -789,7 +794,7 @@
pubReq.setPublishOperations(publishOperations);
}

-void ClientHandler::processPublish(QVariant clientRequest)
+void ClientHandler::processPublish(const QVariant& clientRequest)
{
PublishRequest pubReq = clientRequest.value<PublishRequest>();

@@ -805,19 +810,28 @@
an errorResult element with an errorCode attribute indicating the
cause of the
failure.
*/
- QList<PublishOperation> publishOperations = pubReq.publishOperations();
+ const QList<PublishOperation>& publishOperations =
pubReq.publishOperations();
QListIterator<PublishOperation> pubOperIt(publishOperations);
while (pubOperIt.hasNext() && !requestError) {
- PublishOperation pubOper = pubOperIt.next();
+ const PublishOperation& pubOper = pubOperIt.next();

if (pubOper._publishType == PublishOperation::Update
|| pubOper._publishType == PublishOperation::Notify) {

if (pubOper._publishType == PublishOperation::Update) {
+ // LFu - remove
+ // QTime timer;
+ // timer.start();
_mapGraph->addMeta(pubOper._link, pubOper._isLink,
pubOper._metadata, publisherId);
+ // qDebug() << "~~processing addMeta() took " <<
timer.elapsed() << " ms (meta = " <<
pubOper._metadata.first().elementName() << ")";
+
+ // timer.restart();
+
// TODO: Move this outside of while loop for major
performance boost!
// update subscriptions
updateSubscriptions(pubOper._link, pubOper._isLink,
pubOper._metadata, Meta::PublishUpdate);
+ // qDebug() << "~~processing updateSubscriptions() took "
<< timer.elapsed() << " ms";
+
} else if (pubOper._publishType == PublishOperation::Notify) {
// Deal with notify
updateSubscriptionsWithNotify(pubOper._link,
pubOper._isLink, pubOper._metadata);
@@ -874,7 +888,13 @@
}

if (metadataDeleted && !requestError) {
+
+ // LFu - remove
+ // QTime timer;
+ // timer.start();
updateSubscriptions(pubOper._link, pubOper._isLink,
deleteMetaList, Meta::PublishDelete);
+ // qDebug() << "~~processing updateSubscriptions() took "
<< timer.elapsed() << " ms";
+
}

}
@@ -903,14 +923,14 @@
sendMapResponse(pubResp);
}

-QPair< QList<Meta>, QList<Meta> >
ClientHandler::applyDeleteFilterToMeta(QList<Meta> existingMetaList,
PublishOperation pubOper, MapRequest::RequestError &requestError, bool
*metadataDeleted)
+QPair< QList<Meta>, QList<Meta> >
ClientHandler::applyDeleteFilterToMeta(const QList<Meta>& existingMetaList,
const PublishOperation& pubOper, MapRequest::RequestError &requestError,
bool *metadataDeleted)
{
QList<Meta> keepMetaList;
QList<Meta> deleteMetaList;

QPair< QList<Meta>, QList<Meta> > result;

- QString filter = Subscription::translateFilter(pubOper._deleteFilter);
+ MetadataFilter filter(pubOper._deleteFilter);

QListIterator<Meta> metaListIt(existingMetaList);
while (metaListIt.hasNext() && !requestError) {
@@ -920,6 +940,7 @@
active subscribers.
*/
QString delMeta = filteredMetadata(aMeta, filter,
pubOper._filterNamespaceDefinitions, requestError);
+
if (! requestError) {
if (delMeta.isEmpty()) {
// Keep this metadata (delete filter did not match)
@@ -952,7 +973,7 @@

}

-void ClientHandler::processSubscribe(QVariant clientRequest)
+void ClientHandler::processSubscribe(const QVariant& clientRequest)
{
SubscribeRequest subReq = clientRequest.value<SubscribeRequest>();

@@ -970,33 +991,39 @@
SubscribeOperation subOper = subOperIt.next();

if (subOper.subscribeType() == SubscribeOperation::Update) {
- Subscription sub(subReq.requestVersion());
- sub._name = subOper.name();
- sub._search = subOper.search();
+ Subscription* sub = new Subscription(subReq.requestVersion());
+ sub->_name = subOper.name();
+ sub->_search = subOper.search();
+ sub->_authToken = _authToken;
int currentDepth = -1;
- buildSearchGraph(sub, sub._search.startId(), currentDepth);
+ buildSearchGraph(*sub, sub->_search.startId(), currentDepth);
+
+ // add all identifiers to the index.
+ const QSet<Id> sub_ids(sub->identifiers());
+ QSetIterator<Id> setIt(sub_ids);
+ while(setIt.hasNext()) {
+ MapSessions::getInstance()->addToIndex(setIt.next(), sub);
+ }

if
(_omapdConfig->valueFor("debug_level").value<OmapdConfig::IfmapDebugOptions>().testFlag(OmapdConfig::ShowSearchAlgorithm))
{
qDebug() << __PRETTY_FUNCTION__ << ":" << "Subscription:"
<< subOper.name();
- qDebug() << __PRETTY_FUNCTION__ << ":" << " idList
size:" << sub._idList.size();
- qDebug() << __PRETTY_FUNCTION__ << ":" << " linkList
size:" << sub._linkList.size();
+ qDebug() << __PRETTY_FUNCTION__ << ":" << " idList
size:" << sub->_ids.size();
+ qDebug() << __PRETTY_FUNCTION__ << ":" << " linkList
size:" << sub->_linkList.size();
}

- QList<Subscription> subList =
_mapSessions->subscriptionListForClient(_authToken);
- if (subList.isEmpty()) {
- subList << sub;
- } else {
- // Replace any existing subscriptions with the same name
with removeOne
- subList.removeOne(sub);
- subList << sub;
- }
+ // LFu:
+ // instead of changing a local copy of the subs list and then
writing it back,
+ // change the list in place?
+ _mapSessions->insertSubscriptionForClient(sub, _authToken);
+
if
(_omapdConfig->valueFor("debug_level").value<OmapdConfig::IfmapDebugOptions>().testFlag(OmapdConfig::ShowClientOps))
{
- qDebug() << __PRETTY_FUNCTION__ << ":" << "subList size:"
<< subList.size();
+ qDebug() << __PRETTY_FUNCTION__ << ":" << "subList size:"
<< _mapSessions->subscriptionListForClient(_authToken).size();
}

- _mapSessions->setSubscriptionListForClient(_authToken,
subList);
+ // LFu: this is no longer necessary:
+ // _mapSessions->setSubscriptionListForClient(_authToken,
subList);
if
(_omapdConfig->valueFor("debug_level").value<OmapdConfig::IfmapDebugOptions>().testFlag(OmapdConfig::ShowClientOps))
{
- qDebug() << __PRETTY_FUNCTION__ << ":" << "Adding
SearchGraph to subscription lists with name:" << sub._name;
+ qDebug() << __PRETTY_FUNCTION__ << ":" << "Adding
SearchGraph to subscription lists with name:" << sub->_name;
}

if (_mapSessions->haveActivePollForClient(_authToken)) {
@@ -1005,28 +1032,38 @@
}

} else if (subOper.subscribeType() == SubscribeOperation::Delete) {
- Subscription delSub(subReq.requestVersion());
- delSub._name = subOper.name();

- QList<Subscription> subList =
_mapSessions->removeSubscriptionListForClient(_authToken);
- if (! subList.isEmpty()) {
- // remove delSub from list with same name
- subList.removeOne(delSub);
- if
(_omapdConfig->valueFor("debug_level").value<OmapdConfig::IfmapDebugOptions>().testFlag(OmapdConfig::ShowClientOps))
{
- qDebug() << __PRETTY_FUNCTION__ << ":" << "Removing
subscription from subList with name:" << delSub._name;
- }
- } else {
- if
(_omapdConfig->valueFor("debug_level").value<OmapdConfig::IfmapDebugOptions>().testFlag(OmapdConfig::ShowClientOps))
{
- qDebug() << __PRETTY_FUNCTION__ << ":" << "No
subscriptions to delete for publisher:" << publisherId;
- }
+ if
(_omapdConfig->valueFor("debug_level").value<OmapdConfig::IfmapDebugOptions>().testFlag(OmapdConfig::ShowClientOps))
{
+ qDebug() << __PRETTY_FUNCTION__ << ":" << "Removing
subscription from subList with name:" << subOper.name();
}

- if (! subList.isEmpty()) {
- _mapSessions->setSubscriptionListForClient(_authToken,
subList);
- }
+ _mapSessions->removeSubscriptionForClient(subOper.name(),
_authToken);
+
+// Subscription delSub(subReq.requestVersion());
+// delSub._name = subOper.name();
+
+// // LFu: change subscription list in-place
+// QList<Subscription>& subList =
_mapSessions->subscriptionListForClient(_authToken);
+// // _mapSessions->removeSubscriptionListForClient(_authToken);
+// if (! subList.isEmpty()) {
+// // remove delSub from list with same name
+// subList.removeOne(delSub);
+// if
(_omapdConfig->valueFor("debug_level").value<OmapdConfig::IfmapDebugOptions>().testFlag(OmapdConfig::ShowClientOps))
{
+// qDebug() << __PRETTY_FUNCTION__ << ":" << "Removing
subscription from subList with name:" << delSub._name;
+// }
+// } else {
+// if
(_omapdConfig->valueFor("debug_level").value<OmapdConfig::IfmapDebugOptions>().testFlag(OmapdConfig::ShowClientOps))
{
+// qDebug() << __PRETTY_FUNCTION__ << ":" << "No
subscriptions to delete for publisher:" << publisherId;
+// }
+// }
+
+ // (LFu) no longer need to save back list
+ // if (! subList.isEmpty()) {
+ // _mapSessions->setSubscriptionListForClient(_authToken,
subList);
+ // }

if
(_omapdConfig->valueFor("debug_level").value<OmapdConfig::IfmapDebugOptions>().testFlag(OmapdConfig::ShowClientOps))
{
- qDebug() << __PRETTY_FUNCTION__ << ":" << "subList size:"
<< subList.size();
+ qDebug() << __PRETTY_FUNCTION__ << ":" << "subList size:"
<< _mapSessions->subscriptionListForClient(_authToken).size();
}

}
@@ -1041,7 +1078,7 @@
sendMapResponse(subResp);
}

-void ClientHandler::processSearch(QVariant clientRequest)
+void ClientHandler::processSearch(const QVariant& clientRequest)
{
SearchRequest searchReq = clientRequest.value<SearchRequest>();
MapResponse searchResp(searchReq.requestVersion());
@@ -1051,6 +1088,8 @@

if (!requestError) {
Subscription tempSub(searchReq.requestVersion());
+ // don't include this subscription in the subscription index:
+ tempSub._indexed = false;
tempSub._search = searchReq.search();

int currentDepth = -1;
@@ -1059,7 +1098,7 @@
if
(_omapdConfig->valueFor("debug_level").value<OmapdConfig::IfmapDebugOptions>().testFlag(OmapdConfig::ShowClientOps))
{
qDebug() << __PRETTY_FUNCTION__ << ":" << "Search Lists";
// NB: idList size should be 1 or more, because we always
include the starting identifier
- qDebug() << __PRETTY_FUNCTION__ << ":" << " idList size:"
<< tempSub._idList.size();
+ qDebug() << __PRETTY_FUNCTION__ << ":" << " ids size:" <<
tempSub._ids.size();
qDebug() << __PRETTY_FUNCTION__ << ":" << " linkList size:"
<< tempSub._linkList.size();
}

@@ -1079,7 +1118,7 @@
sendMapResponse(searchResp);
}

-void ClientHandler::processPurgePublisher(QVariant clientRequest)
+void ClientHandler::processPurgePublisher(const QVariant& clientRequest)
{
PurgePublisherRequest ppReq =
clientRequest.value<PurgePublisherRequest>();

@@ -1114,7 +1153,7 @@
sendMapResponse(ppResp);
}

-void ClientHandler::processPoll(QVariant clientRequest)
+void ClientHandler::processPoll(const QVariant& clientRequest)
{
PollRequest pollReq = clientRequest.value<PollRequest>();

@@ -1191,7 +1230,7 @@
server.
*/
if (requestError) {
- if
(_mapSessions->removeSubscriptionListForClient(_authToken).size() > 0) {
+ if (_mapSessions->removeSubscriptionListForClient(_authToken) > 0)
{
if
(_omapdConfig->valueFor("debug_level").value<OmapdConfig::IfmapDebugOptions>().testFlag(OmapdConfig::ShowClientOps))
{
qDebug() << __PRETTY_FUNCTION__ << ":" << "Removing
subscriptions for publisherId:" << publisherId;
}
@@ -1203,7 +1242,7 @@
}
}

-bool ClientHandler::terminateSession(QString sessionId,
MapRequest::RequestVersion requestVersion)
+bool ClientHandler::terminateSession(const QString& sessionId,
MapRequest::RequestVersion requestVersion)
{
bool hadExistingSSRCSession =
_mapSessions->haveActiveSSRCForClient(_authToken);
if (hadExistingSSRCSession) {
@@ -1217,7 +1256,7 @@
delete any previous subscriptions corresponding to the MAP
Client. In
other words, subscription lists are only valid for a single MAP
Client session.
*/
- if
(_mapSessions->removeSubscriptionListForClient(_authToken).size() > 0) {
+ if (_mapSessions->removeSubscriptionListForClient(_authToken) > 0)
{
if
(_omapdConfig->valueFor("debug_level").value<OmapdConfig::IfmapDebugOptions>().testFlag(OmapdConfig::ShowClientOps))
{
qDebug() << __PRETTY_FUNCTION__ << ":" << "Removing
subscriptions for publisherId:"
<< publisherId;
@@ -1245,7 +1284,7 @@
return hadExistingSSRCSession;
}

-bool ClientHandler::terminateARCSession(QString sessionId,
MapRequest::RequestVersion requestVersion)
+bool ClientHandler::terminateARCSession(const QString& sessionId,
MapRequest::RequestVersion requestVersion)
{
bool hadExistingARCSession =
_mapSessions->haveActiveARCForClient(_authToken);

@@ -1281,7 +1320,7 @@
return hadExistingARCSession;
}

-bool ClientHandler::purgePublisher(QString publisherId, bool
sessionMetadataOnly)
+bool ClientHandler::purgePublisher(const QString& publisherId, bool
sessionMetadataOnly)
{
bool haveChanges = false;
bool haveChange = true;
@@ -1307,14 +1346,14 @@
return haveChanges;
}

-QString ClientHandler::filteredMetadata(Meta meta, QString filter,
QMap<QString, QString> searchNamespaces, MapRequest::RequestError &error)
+QString ClientHandler::filteredMetadata(const Meta& meta, const
MetadataFilter& filter, const QMap<QString, QString>& searchNamespaces,
MapRequest::RequestError &error)
{
QList<Meta> singleMetaList;
singleMetaList.append(meta);
return filteredMetadata(singleMetaList, filter, searchNamespaces,
error);
}

-QString ClientHandler::filteredMetadata(QList<Meta>metaList, QString
filter, QMap<QString, QString>searchNamespaces, MapRequest::RequestError
&error)
+QString ClientHandler::filteredMetadata(const QList<Meta>& metaList, const
MetadataFilter& filter, const QMap<QString, QString>& searchNamespaces,
MapRequest::RequestError &error)
{
QString resultString("");
bool matchAll = false;
@@ -1344,69 +1383,106 @@
matchAll = true;
}

- QString qString;
- QTextStream queryStream(&qString);
+ if(filter.isSimple())
+ {
+ // the simplified filter will never be empty
+ const SimplifiedFilter* simFilter = filter.getSimplifiedFilter();

- if (!matchAll) {
- QMapIterator<QString, QString> nsIt(searchNamespaces);
- while (nsIt.hasNext()) {
- nsIt.next();
- queryStream << "declare namespace "
- << nsIt.key()
- << " = \""
- << nsIt.value()
- << "\";";
+ // go through each metadata item
+ QListIterator<Meta> metaIt(metaList);
+ while (metaIt.hasNext()) {
+ const Meta& meta = metaIt.next();
+ // and iterate through each filter disjunction element
+ QListIterator<QPair<QString, QString> > filterIt(*simFilter);
+ while (filterIt.hasNext()) {
+ const QPair<QString, QString>& pair = filterIt.next();
+ // element name must match as well as namespace
+ if(pair.second == meta.elementName() &&
searchNamespaces[pair.first] == meta.elementNS())
+ {
+ // qDebug() << "~~ filter " << pair.first << ':' <<
pair.second << " matches " << meta.metaXML();
+ resultString.append(meta.metaXML());
+ break;
+ }
+ }
}

- queryStream << "<metadata>";
- }
+ // If there are no query results, we won't add <metadata>
enclosing element
+ if (! resultString.isEmpty()) {
+ if
(_omapdConfig->valueFor("debug_level").value<OmapdConfig::IfmapDebugOptions>().testFlag(OmapdConfig::ShowXMLFilterResults))
+ qDebug() << __PRETTY_FUNCTION__ << ":" << "Query Result:"
<< endl << resultString;

- QListIterator<Meta> metaIt(metaList);
- while (metaIt.hasNext()) {
- queryStream << metaIt.next().metaXML();
+ resultString.prepend("<metadata>");
+ resultString.append("</metadata>");
+ }
}
+ else
+ {
+ // run XMLQuery
+ QString qString;
+ QTextStream queryStream(&qString);

- if (!matchAll) {
- queryStream << "</metadata>";
- queryStream << "//"
- << filter;
- }
+ if (!matchAll) {
+ QMapIterator<QString, QString> nsIt(searchNamespaces);
+ while (nsIt.hasNext()) {
+ nsIt.next();
+ queryStream << "declare namespace "
+ << nsIt.key()
+ << " = \""
+ << nsIt.value()
+ << "\";";
+ }

- if
(_omapdConfig->valueFor("debug_level").value<OmapdConfig::IfmapDebugOptions>().testFlag(OmapdConfig::ShowXMLFilterStatements))
- qDebug() << __PRETTY_FUNCTION__ << ":" << "Query Statement:" <<
endl << qString;
+ queryStream << "<metadata>";
+ }

- QXmlQuery query;
- bool qrc;
+ QListIterator<Meta> metaIt(metaList);
+ while (metaIt.hasNext()) {
+ queryStream << metaIt.next().metaXML();
+ }

- if (!matchAll) {
- query.setQuery(qString);
- qrc = query.evaluateTo(&resultString);
- } else {
- resultString = qString;
- qrc = true;
- }
+ if (!matchAll) {
+ queryStream << "</metadata>";
+ queryStream << "//"
+ << filter.str();
+ }

- // Make sure (resultString.size() == 0) is true for checking if we
have results
- resultString = resultString.trimmed();
+ if
(_omapdConfig->valueFor("debug_level").value<OmapdConfig::IfmapDebugOptions>().testFlag(OmapdConfig::ShowXMLFilterStatements))
+ qDebug() << __PRETTY_FUNCTION__ << ":" << "Query Statement:"
<< endl << qString;

- if (! qrc) {
- qDebug() << __PRETTY_FUNCTION__ << ":" << "ERROR: Error running
query with filter:" << filter;
- error = MapRequest::IfmapSystemError;
- } else {
- // If there are no query results, we won't add <metadata>
enclosing element
- if (! resultString.isEmpty()) {
- if
(_omapdConfig->valueFor("debug_level").value<OmapdConfig::IfmapDebugOptions>().testFlag(OmapdConfig::ShowXMLFilterResults))
- qDebug() << __PRETTY_FUNCTION__ << ":" << "Query Result:"
<< endl << resultString;
+ QXmlQuery query;
+ bool qrc;

- resultString.prepend("<metadata>");
- resultString.append("</metadata>");
+ if (!matchAll) {
+ query.setQuery(qString);
+ qrc = query.evaluateTo(&resultString);
+ } else {
+ resultString = qString;
+ qrc = true;
+ }
+
+ // Make sure (resultString.size() == 0) is true for checking if we
have results
+ resultString = resultString.trimmed();
+
+ if (! qrc) {
+ qDebug() << __PRETTY_FUNCTION__ << ":" << "ERROR: Error
running query with filter:" << filter.str();
+ error = MapRequest::IfmapSystemError;
+ } else {
+ // If there are no query results, we won't add <metadata>
enclosing element
+ if (! resultString.isEmpty()) {
+ if
(_omapdConfig->valueFor("debug_level").value<OmapdConfig::IfmapDebugOptions>().testFlag(OmapdConfig::ShowXMLFilterResults))
+ qDebug() << __PRETTY_FUNCTION__ << ":" << "Query
Result:" << endl << resultString;
+
+ resultString.prepend("<metadata>");
+ resultString.append("</metadata>");
+ }
}
}

return resultString;
}

-void ClientHandler::addIdentifierResult(Subscription &sub, Identifier id,
QList<Meta> metaList, SearchResult::ResultType resultType,
MapRequest::RequestError &operationError)
+
+void ClientHandler::addIdentifierResult(Subscription &sub, const
Identifier& id, const QList<Meta>& metaList, SearchResult::ResultType
resultType, MapRequest::RequestError &operationError)
{

SearchResult *searchResult = new SearchResult(resultType,
SearchResult::IdentifierResult);
@@ -1433,18 +1509,20 @@
}
}

-void ClientHandler::addLinkResult(Subscription &sub, Link link,
QList<Meta> metaList, SearchResult::ResultType resultType,
MapRequest::RequestError &operationError)
+void ClientHandler::addLinkResult(Subscription &sub, const Link& link,
const QList<Meta>& metaList, SearchResult::ResultType resultType,
MapRequest::RequestError &operationError)
{

SearchResult *searchResult = new SearchResult(resultType,
SearchResult::LinkResult);
searchResult->_link = link;

if (!metaList.isEmpty() && ! sub._search.resultFilter().isEmpty()) {
- QString combinedFilter = sub._search.matchLinks();
- if (sub._search.resultFilter().compare("*") != 0) {
- combinedFilter =
Subscription::intersectFilter(sub._search.matchLinks(),
sub._search.resultFilter());
- }
- QString metaString = filteredMetadata(metaList, combinedFilter,
sub._search.filterNamespaceDefinitions(), operationError);
+ // (LFu) - only match result against result filter
+// QString combinedFilter = sub._search.matchLinks();
+// if (sub._search.resultFilter().compare("*") != 0) {
+// combinedFilter =
Subscription::intersectFilter(sub._search.matchLinks(),
sub._search.resultFilter());
+// }
+// QString metaString = filteredMetadata(metaList, combinedFilter,
sub._search.filterNamespaceDefinitions(), operationError);
+ QString metaString = filteredMetadata(metaList,
sub._search.resultFilter(), sub._search.filterNamespaceDefinitions(),
operationError);

if (! metaString.isEmpty()) {
searchResult->_metadata = metaString;
@@ -1473,16 +1551,30 @@
case, the MAP Server MUST return the identifier with no metadata or
links attached to it.
*/
- QSetIterator<Id> idIt(sub._idList);
- while (idIt.hasNext() && !operationError) {
- Id id = idIt.next();
- QList<Meta> idMetaList = _mapGraph->metaForId(id);
- if
(_omapdConfig->valueFor("debug_level").value<OmapdConfig::IfmapDebugOptions>().testFlag(OmapdConfig::ShowSearchAlgorithm))
{
- qDebug() << __PRETTY_FUNCTION__ << ":" << "idMetaList size for
id:" << id << "-->" << idMetaList.size();
+
+ QMapIterator<Id, int> idIt(sub._ids);
+ while (idIt.hasNext() && !operationError) {
+ Id id = idIt.next().key();
+ QList<Meta> idMetaList = _mapGraph->metaForId(id);
+ if
(_omapdConfig->valueFor("debug_level").value<OmapdConfig::IfmapDebugOptions>().testFlag(OmapdConfig::ShowSearchAlgorithm))
{
+ qDebug() << __PRETTY_FUNCTION__ << ":" << "idMetaList size
for id:" << id << "-->" << idMetaList.size();
+ }
+ // TODO: Should the identifier be added if there is no
metadata at all?
+ addIdentifierResult(sub, id, idMetaList, resultType,
operationError);
}
- // TODO: Should the identifier be added if there is no metadata at
all?
- addIdentifierResult(sub, id, idMetaList, resultType,
operationError);
- }
+
+
+// (LFu) was:
+// QSetIterator<Id> idIt(sub._idList);
+// while (idIt.hasNext() && !operationError) {
+// Id id = idIt.next();
+// QList<Meta> idMetaList = _mapGraph->metaForId(id);
+// if
(_omapdConfig->valueFor("debug_level").value<OmapdConfig::IfmapDebugOptions>().testFlag(OmapdConfig::ShowSearchAlgorithm))
{
+// qDebug() << __PRETTY_FUNCTION__ << ":" << "idMetaList size
for id:" << id << "-->" << idMetaList.size();
+// }
+// // TODO: Should the identifier be added if there is no metadata
at all?
+// addIdentifierResult(sub, id, idMetaList, resultType,
operationError);
+// }

QSetIterator<Link> linkIt(sub._linkList);
while (linkIt.hasNext() && !operationError) {
@@ -1495,7 +1587,7 @@
}
}

-void ClientHandler::addUpdateAndDeleteMetadata(Subscription &sub,
SearchResult::ResultType resultType, QSet<Id>idList, QSet<Link>linkList,
MapRequest::RequestError &operationError)
+void ClientHandler::addUpdateAndDeleteMetadata(Subscription &sub,
SearchResult::ResultType resultType, const QSet<Id>& idList, const
QSet<Link>& linkList, MapRequest::RequestError &operationError)
{
QSetIterator<Id> idIt(idList);
while (idIt.hasNext() && !operationError) {
@@ -1528,7 +1620,7 @@
}

// currentDepth is pass by value! Must initially be -1.
-void ClientHandler::buildSearchGraph(Subscription &sub, Id startId, int
currentDepth)
+void ClientHandler::buildSearchGraph(Subscription &sub, const Id& startId,
int currentDepth)
{
/* IFMAP20: 3.7.2.8: Recursive Algorithm is from spec */
// 1. Current id, current results, current depth
@@ -1540,7 +1632,10 @@

// 2. Save current identifier in list of traversed identifiers
// so we can later gather metadata from these identifiers.
- sub._idList.insert(startId);
+
+ sub.addId(startId, currentDepth);
+ // LFu - was:
+ // sub._idList.insert(startId);

// 3. If the current identifiers type is contained within
// terminal-identifier-type, return current results.
@@ -1606,14 +1701,17 @@
Link link = linkIter.next();
Id linkedId = Identifier::otherIdForLink(link, startId);
// linkedId becomes startId in recursion
- buildSearchGraph(sub, linkedId, currentDepth);
+ // LFu - filter out IDs in the recursion if we have visited
them already
+ int linkedIdDepth = sub.getDepth(linkedId); // returns -1 if
linkedId not in sub
+ if(linkedIdDepth == -1 || linkedIdDepth > currentDepth + 1)
+ buildSearchGraph(sub, linkedId, currentDepth);
}
}


}

-void ClientHandler::updateSubscriptions(QHash<Id, QList<Meta> >
idMetaDeleted, QHash<Link, QList<Meta> > linkMetaDeleted)
+void ClientHandler::updateSubscriptions(const QHash<Id, QList<Meta> >&
idMetaDeleted, const QHash<Link, QList<Meta> >& linkMetaDeleted)
{
QHashIterator<Id, QList<Meta> > idIter(idMetaDeleted);
while (idIter.hasNext()) {
@@ -1637,7 +1735,7 @@
// the SearchGraphs. If a subscription results in a changed SearchGraph
that
// matches the subscription, build the appropriate metadata results, so
that we
// can send out pollResults.
-void ClientHandler::updateSubscriptions(Link link, bool isLink,
QList<Meta> metaChanges, Meta::PublishOperationType publishType)
+void ClientHandler::updateSubscriptions(const Link link, bool isLink,
const QList<Meta>& metaChanges, Meta::PublishOperationType publishType)
{
// An existing subscription becomes dirty in 4 cases:
// 1. metadata is added to or removed from an identifier already in
the SearchGraph
@@ -1652,176 +1750,319 @@
// new link could link two separate sub-graphs together or a
deleted link
// could prune a graph into two separate sub-graphs.

- QHashIterator<QString,QList<Subscription> >
allSubsIt(_mapSessions->subscriptionLists());
+ // QHash<QString, QList<Subscription*> >
allSubLists(_mapSessions->subscriptionLists());
+ // LFu - only consider subscriptions that include the new/deleted
Id(s):
+ QSet<Subscription*> allSubLists =
MapSessions::getInstance()->getSubscriptionsForIdentifier(link.first);
+ if (isLink)
+ allSubLists +=
MapSessions::getInstance()->getSubscriptionsForIdentifier(link.second);
+
+ // QMutableHashIterator<QString,QList<Subscription*> >
allSubsIt(allSubLists);
+ QMutableSetIterator<Subscription*> allSubsIt(allSubLists);
+
while (allSubsIt.hasNext()) {
- allSubsIt.next();
- QString authToken = allSubsIt.key();
+ Subscription* sub = allSubsIt.next();
+ const QString& authToken = sub->_authToken;
QString pubId = _mapSessions->pubIdForAuthToken(authToken);
- QList<Subscription> subList = allSubsIt.value();
+ // QList<Subscription*>& subList = allSubsIt.value();
+ // if
(_omapdConfig->valueFor("debug_level").value<OmapdConfig::IfmapDebugOptions>().testFlag(OmapdConfig::ShowSearchAlgorithm))
{
+ // qDebug() << __PRETTY_FUNCTION__ << ":" << "publisher:" <<
pubId << "has num subscriptions:" << subList.size();
+ // }
+
+ // bool publisherHasDirtySub = false;
+ // QMutableListIterator<Subscription*> subIt(subList);
+ // while (subIt.hasNext()) {
+
if
(_omapdConfig->valueFor("debug_level").value<OmapdConfig::IfmapDebugOptions>().testFlag(OmapdConfig::ShowSearchAlgorithm))
{
- qDebug() << __PRETTY_FUNCTION__ << ":" << "publisher:" <<
pubId << "has num subscriptions:" << subList.size();
+ qDebug() << __PRETTY_FUNCTION__ << ":" << "--checking
subscription named:" << sub->_name;
}

- bool publisherHasDirtySub = false;
- QMutableListIterator<Subscription> subIt(subList);
- while (subIt.hasNext()) {
- Subscription sub = subIt.next();
- if
(_omapdConfig->valueFor("debug_level").value<OmapdConfig::IfmapDebugOptions>().testFlag(OmapdConfig::ShowSearchAlgorithm))
{
- qDebug() << __PRETTY_FUNCTION__ << ":" << "--checking
subscription named:" << sub._name;
+ QSet<Id> idsWithConnectedGraphUpdates,
idsWithConnectedGraphDeletes;
+ QSet<Link> linksWithConnectedGraphUpdates,
linksWithConnectedGraphDeletes;
+ bool modifiedSearchGraph = false;
+ bool subIsDirty = false;
+
+ if (! isLink) {
+ if (sub->_ids.contains(link.first)) {
+ // Case 1.
+ subIsDirty = true;
+ if
(_omapdConfig->valueFor("debug_level").value<OmapdConfig::IfmapDebugOptions>().testFlag(OmapdConfig::ShowSearchAlgorithm))
{
+ qDebug() << __PRETTY_FUNCTION__ << ":"
<< "----subscription is dirty with id in SearchGraph:" << link.first;
+ }
}
+ } else {

- QSet<Id> idsWithConnectedGraphUpdates,
idsWithConnectedGraphDeletes;
- QSet<Link> linksWithConnectedGraphUpdates,
linksWithConnectedGraphDeletes;
- bool modifiedSearchGraph = false;
- bool subIsDirty = false;
+ // is this link already in the search graph?
+ bool isLinkInSub = sub->_linkList.contains(link);
+ // at least one of the IDs is in the sub search graph ?
+ bool oneIdInSub = (sub->_ids.contains(link.first) ||
sub->_ids.contains(link.second));
+// qDebug() << "~~handling link " << (publishType ==
Meta::PublishDelete ? "DELETE" : "UPDATE") << " in sub " << sub->_name;
+// qDebug() << "~~ids in sub:";
+// QMapIterator<Id, int> idit(sub->_ids);
+// while(idit.hasNext()) qDebug() << "\t" <<
idit.next().key().value();
+// qDebug() << "~~isLinkInSub: " <<
(isLinkInSub ? "true" : "false") << ", oneIdInSub: " <<
(oneIdInSub ? "true" : "false");
+// qDebug() << "~~sub->_ids.contains(link.first): " <<
(sub->_ids.contains(link.first) ? "true" : "false")
+// << ", sub->_ids.contains(link.second): " <<
(sub->_ids.contains(link.second) ? "true" : "false");

- if (! isLink) {
- if (sub._idList.contains(link.first)) {
- // Case 1.
- subIsDirty = true;
- if
(_omapdConfig->valueFor("debug_level").value<OmapdConfig::IfmapDebugOptions>().testFlag(OmapdConfig::ShowSearchAlgorithm))
{
- qDebug() << __PRETTY_FUNCTION__ << ":"
<< "----subscription is dirty with id in SearchGraph:" << link.first;
+ bool needsBuildSearchGraph = true; // must call
buildSearchGraph when true
+ bool needFullRebuild = true; // if
needsBuildSearchGraph: full rebuild or extend
+ bool deleteSingleLink = false; // can delete be optimized
to a simple link deletion
+ int deleteId = 0; // if deleteSingleLink:
which one of the link IDs is going away? (0 means none)
+
+ if (isLinkInSub && publishType == Meta::PublishDelete) {
+ // Case 3.
+ subIsDirty = true;
+ if
(_omapdConfig->valueFor("debug_level").value<OmapdConfig::IfmapDebugOptions>().testFlag(OmapdConfig::ShowSearchAlgorithm))
{
+ qDebug() << __PRETTY_FUNCTION__ << ":"
<< "----subscription is dirty with link in SearchGraph:" << link;
+ }
+
+ // for deletes, we check if the removal of metadata makes
the link go away
+ QList<Meta> curLinkMeta = _mapGraph->metaForLink(link);
+ MapRequest::RequestError error = MapRequest::ErrorNone;
+ QString matchLinkMeta = filteredMetadata(curLinkMeta,
sub->_search.matchLinks(), sub->_search.filterNamespaceDefinitions(),
error);
+ if (! matchLinkMeta.isEmpty()) {
+ // the link isn't going away, so the search graph will
remain the same
+ needsBuildSearchGraph = false;
+ }
+ else {
+ // the link is going away. However, if the link forms
a leaf in the search
+ // graph then the removal will not have a ripple
effect and we can also save a full rebuild
+ int d1 = sub->_ids[link.first];
+ int d2 = sub->_ids[link.second];
+ if(d1 == d2)
+ {
+ // both identifiers have the same depth means we
can always remove this link without
+ // any other part of the search graph breaking away
+ needsBuildSearchGraph = false;
+ deleteSingleLink = true;
+ needFullRebuild = false;
}
+ else if(d1 < d2 && sub->linksContaining(link.second)
== 1) // 1 means this id is only used in the link we're deleting
+ {
+ needsBuildSearchGraph = false;
+ deleteSingleLink = true;
+ needFullRebuild = false;
+ deleteId = 2;
+ }
+ else if(d2 < d1 && sub->linksContaining(link.second)
== 1)
+ {
+ needsBuildSearchGraph = false;
+ deleteSingleLink = true;
+ needFullRebuild = false;
+ deleteId = 1;
+ }
+ // in all other cases make a full search graph rebuild
}
- } else {
- if (sub._linkList.contains(link) && publishType ==
Meta::PublishDelete) {
- // Case 3.
- subIsDirty = true;
- if
(_omapdConfig->valueFor("debug_level").value<OmapdConfig::IfmapDebugOptions>().testFlag(OmapdConfig::ShowSearchAlgorithm))
{
- qDebug() << __PRETTY_FUNCTION__ << ":"
<< "----subscription is dirty with link in SearchGraph:" << link;
+ }
+
+ if (isLinkInSub && publishType == Meta::PublishUpdate) {
+ // Case 2.
+ subIsDirty = true;
+ // qDebug() << "~~oneIdInSub: case 2";
+ } else if(subIsDirty || (oneIdInSub && publishType ==
Meta::PublishUpdate)) {
+ // (LFu) - the way this else was written before, it also
covered the case:
+ // !sub._linkList.contains(link) && publishType ==
Meta::PublishDelete, which we should ignore
+
+ // Case 4. (and search graph rebuild for case 3)
+
+ // (LFu) Changes:
+ // - when adding a link that contributes to the
subscription's search graph, extend the search graph
+ // rather than rebuilding it completely. This will cause
non-matching links or links attached to an
+ // identifier at max search depth to become noops
+
+ if (publishType == Meta::PublishUpdate) needFullRebuild =
false;
+
+ // TODO: we should also be able to optimize removal of a
link, e.g. any link that ends in an identifier
+ // of max subs search depth can be removed in isolation
(i.e. no subs graph must be calculated)
+
+ QMap<Id, int> existingIdList = sub->_ids;
+ QSet<Link> existingLinkList = sub->_linkList;
+ int currentDepth = -1;
+ Id startId;
+// qDebug() << "~~case 3: needsBuildSearchGraph = " <<
(needsBuildSearchGraph ? "true" : "false")
+// << ", needFullRebuild = " <<
(needFullRebuild ? "true" : "false")
+// << ", deleteSingleLink = " <<
(deleteSingleLink ? "true" : "false");
+ if(needFullRebuild) // full search graph rebuild
+ {
+ sub->_ids.clear();
+ sub->_linkList.clear();
+ startId = sub->_search.startId();
+ // qDebug() << "~~making full search graph rebuild for
sub " << sub->_name;
+ }
+ else if(publishType == Meta::PublishUpdate) // extend the
search graph
+ {
+ // determine the identifier with the lowest depth to
start the graph expansion:
+ int depth1 = sub->getDepth(link.first);
+ int depth2 = sub->getDepth(link.second);
+
+ if(-1 == depth2 || (depth1 >= 0 && depth1 <= depth2))
+ {
+ startId = link.first;
+ currentDepth = depth1;
}
+ else
+ {
+ startId = link.second;
+ currentDepth = depth2;
+ }
+ // qDebug() << "~~making search graph exension for
sub " << sub->_name;
+ }
+ else if (deleteSingleLink)
+ {
+ // only delete a single link
+ sub->_linkList.remove(link);
+ // delete
+ if(deleteId == 2)
+ sub->_ids.remove(link.second);
+ else if(deleteId == 1)
+ sub->_ids.remove(link.first);
}

- if (sub._linkList.contains(link) && publishType ==
Meta::PublishUpdate) {
- // Case 2.
+ // qDebug() << "~~making full search graph rebuild for
sub " << sub->_name;
+
+ // LFu - remove
+ // QTime buildSearchGraphTimer;
+ // buildSearchGraphTimer.start();
+
+ if(needsBuildSearchGraph)
+ buildSearchGraph(*sub, startId, (needFullRebuild ?
currentDepth : currentDepth - 1));
+ // qDebug() << "~~processing buildSearchGraph() took " <<
buildSearchGraphTimer.elapsed() << " ms for sub " << sub->_name;
+
+ if (sub->_ids != existingIdList) {
subIsDirty = true;
- } else {
- // Case 4. (and search graph rebuild for case 3)
- QSet<Id> existingIdList = sub._idList;
- QSet<Link> existingLinkList = sub._linkList;
- sub._idList.clear();
- sub._linkList.clear();
- int currentDepth = -1;
- buildSearchGraph(sub, sub._search.startId(),
currentDepth);
+ modifiedSearchGraph = true;

- if (sub._idList != existingIdList) {
***The diff for this file has been truncated for email.***
=======================================
--- /trunk/clienthandler.h Thu Feb 21 17:10:53 2013
+++ /trunk/clienthandler.h Wed Jun 26 17:02:49 2013
@@ -41,20 +41,20 @@
};

explicit ClientHandler(MapGraphInterface *mapGraph, QObject *parent =
0);
- explicit ClientHandler(MapGraphInterface *mapGraph, QString authToken,
QObject *parent = 0);
+ explicit ClientHandler(MapGraphInterface *mapGraph, const QString&
authToken, QObject *parent = 0);
~ClientHandler();

- static QString buildDN(QSslCertificate cert,
ClientHandler::CertInfoTarget target);
+ static QString buildDN(const QSslCertificate& cert, const
ClientHandler::CertInfoTarget& target);

void sessionMetadataTimeout();
- void sendPollResponse(QByteArray response, MapRequest::RequestVersion
reqVersion);
- QString authToken() { return _authToken; }
+ void sendPollResponse(const QByteArray& response, const
MapRequest::RequestVersion& reqVersion);
+ const QString& authToken() { return _authToken; }
bool useCompression() { return _useCompression; }

signals:
- void needToSendPollResponse(ClientHandler *client, QByteArray
response, MapRequest::RequestVersion reqVersion);
- void receivedNewSession(QString authToken);
- void receivedRenewSession(QString authToken);
+ void needToSendPollResponse(ClientHandler *client, const QByteArray&
response, MapRequest::RequestVersion reqVersion);
+ void receivedNewSession(const QString& authToken);
+ void receivedRenewSession(const QString& authToken);
void receivedEndSession();
void receivedMigratedSession(ClientHandler *client);

@@ -62,51 +62,51 @@
void handleParseComplete();

private slots:
- void clientSocketError(QAbstractSocket::SocketError socketError);
+ void clientSocketError(const QAbstractSocket::SocketError&
socketError);
void processReadyRead();
void socketReady();
void clientSSLErrors(const QList<QSslError> & errors);
void clientConnState(QAbstractSocket::SocketState sState);
- void processHeader(QNetworkRequest requestHdrs);
+ void processHeader(const QNetworkRequest& requestHdrs);

private:
void registerCert();
- QByteArray compressResponse(QByteArray uncompressed);
- void sendHttpResponse(int hdrNumber, QString hdrText);
- void sendMapResponse(MapResponse &mapResponse);
- void sendResponse(QByteArray response, MapRequest::RequestVersion
reqVersion);
+ void compressResponse(const QByteArray& uncompressed, QByteArray&
deflated);
+ void sendHttpResponse(int hdrNumber, const QString& hdrText);
+ void sendMapResponse(const MapResponse &mapResponse);
+ void sendResponse(const QByteArray& response, const
MapRequest::RequestVersion& reqVersion);
void processClientRequest();
void sendResultsOnActivePolls();

- QString filteredMetadata(QList<Meta> metaList, QString filter,
QMap<QString, QString> searchNamespaces, MapRequest::RequestError &error);
- QString filteredMetadata(Meta meta, QString filter, QMap<QString,
QString> searchNamespaces, MapRequest::RequestError &error);
+ QString filteredMetadata(const QList<Meta>& metaList, const
MetadataFilter& filter, const QMap<QString, QString>& searchNamespaces,
MapRequest::RequestError &error);
+ QString filteredMetadata(const Meta& meta, const MetadataFilter&
filter, const QMap<QString, QString>& searchNamespaces,
MapRequest::RequestError &error);

void collectSearchGraphMetadata(Subscription &sub,
SearchResult::ResultType resultType, MapRequest::RequestError
&operationError);
- void addUpdateAndDeleteMetadata(Subscription &sub,
SearchResult::ResultType resultType, QSet<Id> idList, QSet<Link> linkList,
MapRequest::RequestError &operationError);
- void buildSearchGraph(Subscription &sub, Id startId, int currentDepth);
- void addIdentifierResult(Subscription &sub, Identifier id, QList<Meta>
metaList, SearchResult::ResultType resultType, MapRequest::RequestError
&operationError);
- void addLinkResult(Subscription &sub, Link link, QList<Meta> metaList,
SearchResult::ResultType resultType, MapRequest::RequestError
&operationError);
+ void addUpdateAndDeleteMetadata(Subscription &sub,
SearchResult::ResultType resultType, const QSet<Id>& idList, const
QSet<Link>& linkList, MapRequest::RequestError &operationError);
+ void buildSearchGraph(Subscription &sub, const Id& startId, int
currentDepth);
+ void addIdentifierResult(Subscription &sub, const Identifier& id,
const QList<Meta>& metaList, SearchResult::ResultType resultType,
MapRequest::RequestError &operationError);
+ void addLinkResult(Subscription &sub, const Link& link, const
QList<Meta>& metaList, SearchResult::ResultType resultType,
MapRequest::RequestError &operationError);

- void updateSubscriptionsWithNotify(Link link, bool isLink, QList<Meta>
metaChanges);
- void updateSubscriptions(QHash<Id, QList<Meta> > idMetaDeleted,
QHash<Link, QList<Meta> > linkMetaDeleted);
- void updateSubscriptions(Link link, bool isLink, QList<Meta>
metaChanges, Meta::PublishOperationType publishType);
+ void updateSubscriptionsWithNotify(const Link& link, bool isLink,
const QList<Meta>& metaChanges);
+ void updateSubscriptions(const QHash<Id, QList<Meta> >& idMetaDeleted,
const QHash<Link, QList<Meta> >& linkMetaDeleted);
+ void updateSubscriptions(const Link link, bool isLink, const
QList<Meta>& metaChanges, Meta::PublishOperationType publishType);

- void processNewSession(QVariant clientRequest);
- void processRenewSession(QVariant clientRequest);
- void processEndSession(QVariant clientRequest);
- void processAttachSession(QVariant clientRequest);
- void processPublish(QVariant clientRequest);
- void processSubscribe(QVariant clientRequest);
- void processSearch(QVariant clientRequest);
- void processPurgePublisher(QVariant clientRequest);
- void processPoll(QVariant clientRequest);
+ void processNewSession(const QVariant& clientRequest);
+ void processRenewSession(const QVariant& clientRequest);
+ void processEndSession(const QVariant& clientRequest);
+ void processAttachSession(const QVariant& clientRequest);
+ void processPublish(const QVariant& clientRequest);
+ void processSubscribe(const QVariant& clientRequest);
+ void processSearch(const QVariant& clientRequest);
+ void processPurgePublisher(const QVariant& clientRequest);
+ void processPoll(const QVariant& clientRequest);

void checkPublishAtomicity(PublishRequest &pubReq,
MapRequest::RequestError &requestError);
- QPair< QList<Meta>, QList<Meta> > applyDeleteFilterToMeta(QList<Meta>
existingMetaList, PublishOperation pubOper, MapRequest::RequestError
&requestError, bool *metadataDeleted = 0);
+ QPair< QList<Meta>, QList<Meta> > applyDeleteFilterToMeta(const
QList<Meta>& existingMetaList, const PublishOperation& pubOper,
MapRequest::RequestError &requestError, bool *metadataDeleted = 0);

- bool terminateSession(QString sessionId, MapRequest::RequestVersion
requestVersion);
- bool terminateARCSession(QString sessionId, MapRequest::RequestVersion
requestVersion);
- bool purgePublisher(QString publisherId, bool sessionMetadataOnly);
+ bool terminateSession(const QString& sessionId,
MapRequest::RequestVersion requestVersion);
+ bool terminateARCSession(const QString& sessionId,
MapRequest::RequestVersion requestVersion);
+ bool purgePublisher(const QString& publisherId, bool
sessionMetadataOnly);

private:
OmapdConfig* _omapdConfig;
=======================================
--- /trunk/clientparser.cpp Sun Feb 24 14:35:44 2013
+++ /trunk/clientparser.cpp Wed Jun 26 17:02:49 2013
@@ -543,7 +543,7 @@
}

if (_requestError == MapRequest::ErrorNone) {
- QString authToken = ((ClientHandler*)this->parent())->authToken();
+ const QString& authToken =
((ClientHandler*)this->parent())->authToken();
QString clientPubId =
MapSessions::getInstance()->pubIdForAuthToken(authToken);
OmapdConfig::AuthzOptions authz =
MapSessions::getInstance()->authzForAuthToken(authToken);

@@ -569,7 +569,7 @@
pubReq.setRequestVersion(_requestVersion);
_requestType = MapRequest::Publish;
setSessionId(pubReq);
- QString authToken = ((ClientHandler*)this->parent())->authToken();
+ const QString& authToken =
((ClientHandler*)this->parent())->authToken();

pubReq.setPublisherId(MapSessions::getInstance()->pubIdForAuthToken(authToken));

OmapdConfig::AuthzOptions authz =
MapSessions::getInstance()->authzForAuthToken(authToken);
@@ -801,11 +801,11 @@
specifies a max-size that exceeds what the MAP Server can support,
the MAP Server MUST enforce its own maximum size constraints.
*/
- long maxSize = IFMAP_MAX_SIZE;
+ long long maxSize = IFMAP_MAX_SIZE;
if (attrs.hasAttribute("max-size")) {
QString ms = attrs.value("max-size").toString();
bool ok;
- maxSize = ms.toLong(&ok);
+ maxSize = ms.toLongLong(&ok);
if (ok) {
if
(_omapdConfig->valueFor("debug_level").value<OmapdConfig::IfmapDebugOptions>().testFlag(OmapdConfig::ShowXMLParsing))
{
qDebug() << __PRETTY_FUNCTION__ << ":" << "Got search
parameter max-size:" << maxSize;
@@ -837,10 +837,10 @@
if
(_omapdConfig->valueFor("debug_level").value<OmapdConfig::IfmapDebugOptions>().testFlag(OmapdConfig::ShowXMLParsing))
{
qDebug() << __PRETTY_FUNCTION__ << ":" << "Got search
parameter match-links:" << matchLinks;
}
- search.setMatchLinks(Subscription::translateFilter(matchLinks));
+ search.setMatchLinks(matchLinks);
} else {
if
(_omapdConfig->valueFor("debug_level").value<OmapdConfig::IfmapDebugOptions>().testFlag(OmapdConfig::ShowXMLParsing))
{
- qDebug() << __PRETTY_FUNCTION__ << ":" << "Using default
search parameter match-links:" << search.matchLinks();
+ qDebug() << __PRETTY_FUNCTION__ << ":" << "Using default
search parameter match-links:" << search.matchLinks().str();
}
}

@@ -849,10 +849,10 @@
if
(_omapdConfig->valueFor("debug_level").value<OmapdConfig::IfmapDebugOptions>().testFlag(OmapdConfig::ShowXMLParsing))
{
qDebug() << __PRETTY_FUNCTION__ << ":" << "Got search
parameter result-filter:" << resultFilter;
}
-
search.setResultFilter(Subscription::translateFilter(resultFilter));
+ search.setResultFilter(resultFilter);
} else {
if
(_omapdConfig->valueFor("debug_level").value<OmapdConfig::IfmapDebugOptions>().testFlag(OmapdConfig::ShowXMLParsing))
{
- qDebug() << __PRETTY_FUNCTION__ << ":" << "Using default
search parameter result-filter:" << search.resultFilter();
+ qDebug() << __PRETTY_FUNCTION__ << ":" << "Using default
search parameter result-filter:" << search.resultFilter().str();
}
}

@@ -1283,7 +1283,7 @@
_xml.raiseError("Metadata did not pass validation test");
}

- QString authToken = ((ClientHandler*)this->parent())->authToken();
+ const QString& authToken =
((ClientHandler*)this->parent())->authToken();
bool metaPolicy =
MapSessions::getInstance()->metadataAuthorizationForAuthToken(authToken,
metaName, metaNS);
if (!metaPolicy) {
pubReq.setRequestError(MapRequest::IfmapAccessDenied);
=======================================
--- /trunk/clientparser.h Thu Oct 6 14:28:02 2011
+++ /trunk/clientparser.h Wed Jun 26 17:02:49 2013
@@ -44,15 +44,15 @@
public:
ClientParser(QIODevice *parent = 0);
~ClientParser();
- QString clientXML() { return _clientRequestXml; }
+ const QString& clientXML() { return _clientRequestXml; }
QString errorString() const { return _xml.errorString(); }
QXmlStreamReader::Error error() const { return _xml.error(); }

- QVariant request() const { return _mapRequest; }
- MapRequest::RequestError requestError() const { return _requestError; }
- MapRequest::RequestVersion requestVersion() const { return
_requestVersion; }
+ const QVariant& request() const { return _mapRequest; }
+ const MapRequest::RequestError& requestError() const { return
_requestError; }
+ const MapRequest::RequestVersion& requestVersion() const { return
_requestVersion; }
MapRequest::RequestType requestType() const { return _requestType; }
- QString sessionId() const { return _sessionId; }
+ const QString& sessionId() const { return _sessionId; }


signals:
=======================================
--- /trunk/identifier.cpp Sun Sep 25 13:51:15 2011
+++ /trunk/identifier.cpp Wed Jun 26 17:02:49 2013
@@ -122,7 +122,7 @@

}

-Link Identifier::makeLinkFromIds(Id id1, Id id2)
+Link Identifier::makeLinkFromIds(const Id& id1, const Id& id2)
{
Link link;
// Make identifier ordering independent of received order
@@ -138,7 +138,7 @@
return link;
}

-Id Identifier::otherIdForLink(Link link, Id targetId)
+Id Identifier::otherIdForLink(const Link& link, const Id& targetId)
{
if (link.first == targetId)
return link.second;
@@ -151,7 +151,7 @@
{
}

-Identifier::Identifier(Identifier::IdType type, QString value, QString ad,
QString other)
+Identifier::Identifier(Identifier::IdType type, const QString& value,
const QString& ad, const QString& other)
: _type(type), _value(value), _ad(ad), _other(other)
{
}
=======================================
--- /trunk/identifier.h Sun Sep 25 13:51:15 2011
+++ /trunk/identifier.h Wed Jun 26 17:02:49 2013
@@ -55,28 +55,29 @@
};

Identifier(Identifier::IdType type = Identifier::IdNone);
- Identifier(Identifier::IdType type, QString value, QString ad =
QString(), QString other = QString());
+ Identifier(Identifier::IdType type, const QString& value, const
QString& ad = QString(), const QString& other = QString());

static QString idStringForType(Identifier::IdType idType);
static QString idBaseStringForType(Identifier::IdType idType);
- static Link makeLinkFromIds(Id id1, Id id2);
- static Id otherIdForLink(Link link, Id targetId);
+ static Link makeLinkFromIds(const Id& id1, const Id& id2);
+ static Id otherIdForLink(const Link& link, const Id& targetId);

// Two Identifier objects are equal iff their type, namespace, value,
and other members are the same
bool operator==(const Identifier &other) const;
+ bool operator< (const Id& other) const { return hashString() <
other.hashString(); }
//QDataStream & operator<< ( QDataStream & stream, const Identifier &
id );

Identifier::IdType type() const { return _type; }
- QString value() const { return _value; }
- QString ad() const { return _ad; }
- QString other() const { return _other; }
+ const QString& value() const { return _value; }
+ const QString& ad() const { return _ad; }
+ const QString& other() const { return _other; }

QString hashString() const;

void setType(Identifier::IdType type) { _type = type; }
- void setValue(QString value) { _value = value; }
- void setAd(QString ad) { _ad = ad; }
- void setOther(QString other) { _other = other; }
+ void setValue(const QString& value) { _value = value; }
+ void setAd(const QString& ad) { _ad = ad; }
+ void setOther(const QString& other) { _other = other; }

private:
Identifier::IdType _type;
=======================================
--- /trunk/main.cpp Thu Jan 3 16:50:42 2013
+++ /trunk/main.cpp Wed Jun 26 17:02:49 2013
@@ -221,5 +221,9 @@
qDebug() << "Started management server";
}

- return a.exec();
+ int exitCode = a.exec();
+
+ OmapdConfig::destroy();
+
+ return exitCode;
}
=======================================
--- /trunk/mapclient.cpp Sun Feb 24 14:35:44 2013
+++ /trunk/mapclient.cpp Wed Jun 26 17:02:49 2013
@@ -30,7 +30,7 @@
_hasActivePoll = false;
}

-MapClient::MapClient(QString authToken, MapRequest::AuthenticationType
authType, OmapdConfig::AuthzOptions authz, QString pubId, QString
metadataPolicy)
+MapClient::MapClient(const QString& authToken,
MapRequest::AuthenticationType authType, OmapdConfig::AuthzOptions authz,
const QString& pubId, const QString& metadataPolicy)
{
_hasActiveSSRC = false;
_hasActiveARC = false;
@@ -41,3 +41,56 @@
_pubId = pubId;
_metadataPolicy = metadataPolicy;
}
+
+MapClient::~MapClient()
+{
+ clearSubscriptionList();
+}
+
+void MapClient::clearSubscriptionList()
+{
+ QListIterator<Subscription*> it(_subscriptionList);
+ while(it.hasNext())
+ {
+ delete it.next();
+ }
+ _subscriptionList.clear();
+}
+
+void MapClient::insertSubscription(Subscription* sub)
+{
+ // we need to check if a subscription with this name
+ // exists already and replace it with the new one if found
+ QMutableListIterator<Subscription*> it(_subscriptionList);
+ while(it.hasNext())
+ {
+ Subscription* s = it.next();
+ if(*s == *sub)
+ {
+ delete s;
+ it.setValue(sub);
+ return;
+ }
+ }
+
+ // otherwise just add the new one:
+ _subscriptionList << sub;
+
+}
+
+void MapClient::removeSubscription(const QString& name)
+{
+ // we need to check if a subscription with this name
+ // exists already and replace it with the new one if found
+ QMutableListIterator<Subscription*> it(_subscriptionList);
+ while(it.hasNext())
+ {
+ Subscription* s = it.next();
+ if(s->_name == name)
+ {
+ delete s;
+ it.remove();
+ return;
+ }
+ }
+}
=======================================
--- /trunk/mapclient.h Sun Feb 24 14:35:44 2013
+++ /trunk/mapclient.h Wed Jun 26 17:02:49 2013
@@ -32,31 +32,37 @@
// that return a default constructed value
MapClient();

- MapClient(QString authToken,
+ MapClient(const QString& authToken,
MapRequest::AuthenticationType authType,
OmapdConfig::AuthzOptions authz,
- QString pubId,
- QString metadataPolicy);
+ const QString& pubId,
+ const QString& metadataPolicy);

- QString pubId() const { return _pubId; }
- QString authToken() const { return _authToken; }
+ ~MapClient();
+
+ const QString& pubId() const { return _pubId; }
+ const QString& authToken() const { return _authToken; }
MapRequest::AuthenticationType authType() const { return _authType; }
OmapdConfig::AuthzOptions authz() const { return _authz; }
- QString metadataPolicy() const { return _metadataPolicy; }
+ const QString& metadataPolicy() const { return _metadataPolicy; }

- QString sessId() const { return _sessId; }
+ const QString& sessId() const { return _sessId; }
bool hasActiveSSRC() const { return _hasActiveSSRC; }
bool hasActiveARC() const { return _hasActiveARC; }
bool hasActivePoll() const { return _hasActivePoll; }
- QList<Subscription> subscriptionList() const { return
_subscriptionList; }
+ const QList<Subscription*>& subscriptionList() const { return
_subscriptionList; }
+ QList<Subscription*>& subscriptionList() { return _subscriptionList; }

- void setSessId(QString sessId) { _sessId = sessId; }
- void clearSessId() { _sessId = QString(); }
+ void setSessId(const QString& sessId) { _sessId = sessId; }
+ void clearSessId() { _sessId.clear(); }
void setHasActiveSSRC(bool hasActiveSSRC) { _hasActiveSSRC =
hasActiveSSRC; }
void setHasActiveARC(bool hasActiveARC) { _hasActiveARC =
hasActiveARC; }
void setHasActivePoll(bool hasActivePoll) { _hasActivePoll =
hasActivePoll; }
- void setSubscriptionList(QList<Subscription> subList) {
_subscriptionList = subList; }
- void emptySubscriptionList() { _subscriptionList.clear(); }
+
+ // void setSubscriptionList(const QList<Subscription>& subList) {
_subscriptionList = subList; }
+ void insertSubscription(Subscription* sub);
+ void removeSubscription(const QString& name);
+ void clearSubscriptionList();

private:
QString _pubId;
@@ -69,7 +75,7 @@
bool _hasActiveSSRC;
bool _hasActiveARC;
bool _hasActivePoll;
- QList<Subscription> _subscriptionList;
+ QList<Subscription*> _subscriptionList;
};

#endif // MAPCLIENT_H
=======================================
--- /trunk/maprequest.cpp Fri Sep 30 14:51:53 2011
+++ /trunk/maprequest.cpp Wed Jun 26 17:02:49 2013
@@ -250,16 +250,111 @@
this->_publishOperations = other._publishOperations;
}

-SearchType::SearchType()
+MetadataFilter::MetadataFilter(const QString& filterStr)
+ : _filter(""), _simFilter(NULL)
+{
+ setFilter(filterStr);
+}
+
+MetadataFilter::MetadataFilter(const MetadataFilter& other)
+{
+ _simFilter = NULL;
+ *this = other;
+}
+
+MetadataFilter::~MetadataFilter()
+{
+ if(_simFilter != NULL) delete _simFilter;
+}
+
+MetadataFilter& MetadataFilter::operator=(const MetadataFilter& other)
+{
+ _filter = other._filter;
+ if(_simFilter != NULL) delete(_simFilter);
+
+ if(other._simFilter != NULL)
+ {
+ _simFilter = new SimplifiedFilter(*other._simFilter);
+ }
+ else
+ {
+ _simFilter = NULL;
+ }
+
+ return *this;
+}
+
+bool MetadataFilter::operator==(const MetadataFilter& other) const
+{
+ return _filter == other._filter &&
+ (_simFilter == NULL
+ ? other._simFilter == NULL
+ : other._simFilter != NULL && *_simFilter ==
*other._simFilter);
+}
+
+bool MetadataFilter::operator==(const QString& filterStr) const
+{
+ return _filter == filterStr;
+}
+
+// (LFu) this code used be the translateFilter() method in class
Subscription
+void MetadataFilter::setFilter(const QString& ifmapFilter)
+{
+ //const char *fnName = "MetadataFilter::setFilter:";
+
+ /* non-predicate expressions joined by "or" need to be translated
+ into a parenthesized expression separated by "|".
+
+ Examples:
+ meta:ip-mac or scada:node
+ --> (meta:ip-mac | scada:node)
+
+ meta:role[@publisher-id = "myPubId" or name="myRole"] or meta:ip-mac
+ --> (meta:role[@publisher-id = "myPubId" or name="myRole"] |
meta:ip-mac)
+
+ standard XPath does not support predicate expressions that begin
with [; need to add *
+ */
+
+ if(!ifmapFilter.isEmpty() && ifmapFilter != "*")
+ {
+ // (LFu) - determine if the filter looks like "ns-1:elem-1 or ...
or ns-n:elem-n"
+ // and provide simplified metadata matching in this case:
+ QRegExp rx("((\\w|-)+:(\\w|-)+)(\\s+(or|OR)\\s+((\\w|-)+:(\\w|
-)+))*");
+ if(rx.exactMatch(ifmapFilter))
+ {
+ _simFilter = new SimplifiedFilter();
+ // qDebug() << "~~regex matches filter: " << ifmapFilter;
+ int pos = 0;
+ QRegExp rx2("((\\w|-)+):((\\w|-)+)(\\s+(or|OR))?");
+ while ((pos = rx2.indexIn(ifmapFilter, pos)) != -1) {
+ _simFilter->append(QPair<QString, QString>(rx2.cap(1),
rx2.cap(3)));
+ // qDebug() << "~~\tns:" << rx2.cap(1) << " elem:" <<
rx2.cap(3);
+ pos += rx2.matchedLength();
+ }
+ }
+ }
+
+ // TODO: Do this with QRegExp
+ _filter = ifmapFilter;
+ if (ifmapFilter.contains(" or ", Qt::CaseInsensitive)) {
+ //qDebug() << fnName << "WARNING! filter translation is woefully
incomplete!";
+ //qDebug() << fnName << "filter before translation:" <<
ifmapFilter;
+ _filter.replace(" or "," | ");
+ _filter.prepend("(");
+ _filter.append(")");
+ //qDebug() << fnName << "filter after translation:" << qtFilter;
+ }
+}
+
+
+SearchType::SearchType()
+ : _resultFilter("*"), _matchLinks("*") // Intepretation of the spec is
that no match-links attribute matches all links
{
_clientSetMaxDepth = false;
_clientSetMaxSize = false;
_clientSetResultFilter = false;
_clientSetMatchLinks = false;
_clientSetTerminalId = false;
- // Intepretation of the spec is that no match-links attribute matches
all links
- _matchLinks = "*";
- _resultFilter = "*";
_terminalId = "";
}

=======================================
--- /trunk/maprequest.h Thu Jul 12 22:55:18 2012
+++ /trunk/maprequest.h Wed Jun 26 17:02:49 2013
@@ -105,18 +105,18 @@
MapRequest::RequestError requestError() const { return _requestError; }
MapRequest::RequestVersion requestVersion() const { return
_requestVersion; }
MapRequest::RequestType requestType() const { return _requestType; }
- QString sessionId() const { return _sessionId; }
+ const QString& sessionId() const { return _sessionId; }
bool clientSetSessionId() const { return _clientSetSessionId; }
MapRequest::AuthenticationType authType() const { return _authType; }
- QString authToken() const { return _authValue; }
+ const QString& authToken() const { return _authValue; }

void setRequestError(MapRequest::RequestError requestError) {
_requestError = requestError; }
void setRequestType(MapRequest::RequestType requestType) {
_requestType = requestType; }
void setRequestVersion(MapRequest::RequestVersion requestVersion) {
_requestVersion = requestVersion; }
- void setSessionId(QString sessionId) { _sessionId = sessionId; }
+ void setSessionId(const QString& sessionId) { _sessionId = sessionId; }
void setClientSetSessionId(bool set) { _clientSetSessionId = set; }
void setAuthType(MapRequest::AuthenticationType type) { _authType =
type; }
- void setAuthValue(QString value) { _authValue = value; }
+ void setAuthValue(const QString& value) { _authValue = value; }

protected:
MapRequest::RequestError _requestError;
@@ -179,11 +179,12 @@
PurgePublisherRequest();
PurgePublisherRequest(const PurgePublisherRequest&);
~PurgePublisherRequest() {;}
+ // FIXME LFu: this seems wrong (const return value)
const PurgePublisherRequest& operator= (const PurgePublisherRequest&
rhs);

- QString publisherId() const { return _publisherId; }
+ const QString& publisherId() const { return _publisherId; }
bool clientSetPublisherId() const { return _clientSetPublisherId; }
- void setPublisherId(QString pubId) { _publisherId = pubId; }
+ void setPublisherId(const QString& pubId) { _publisherId = pubId; }
void setClientSetPublisherId(bool set) { _clientSetPublisherId = set; }
private:
QString _publisherId;
@@ -226,29 +227,54 @@
PublishRequest(const PublishRequest&);
~PublishRequest() { _publishOperations.clear();}

- QString publisherId() const { return _publisherId; }
- void setPublisherId(QString pubId) { _publisherId = pubId; }
- void setPublishOperations(QList<PublishOperation> operations) {
_publishOperations = operations; }
- QList<PublishOperation> publishOperations() const { return
_publishOperations; }
- void addPublishOperation(PublishOperation pubOper) {
_publishOperations.append(pubOper); }
+ const QString& publisherId() const { return _publisherId; }
+ void setPublisherId(const QString& pubId) { _publisherId = pubId; }
+ void setPublishOperations(const QList<PublishOperation>& operations) {
_publishOperations = operations; }
+ const QList<PublishOperation>& publishOperations() const { return
_publishOperations; }
+ void addPublishOperation(const PublishOperation& pubOper) {
_publishOperations.append(pubOper); }
private:
QList<PublishOperation> _publishOperations;
QString _publisherId;
};
Q_DECLARE_METATYPE(PublishRequest)

+typedef QList<QPair<QString, QString> > SimplifiedFilter;
+
+class MetadataFilter
+{
+public:
+ MetadataFilter(const QString& filterStr);
+ MetadataFilter(const MetadataFilter& other);
+ ~MetadataFilter();
+
+ MetadataFilter& operator=(const MetadataFilter& other);
+ bool operator==(const MetadataFilter& other) const;
+ bool operator==(const QString& filterStr) const;
+
+ bool isEmpty() const { return _filter.isEmpty(); }
+ bool isSimple() const { return _simFilter != NULL; }
+ const QString& str() const { return _filter; }
+
+ const SimplifiedFilter* getSimplifiedFilter() const { return
_simFilter; }
+ void setFilter(const QString& ifmapFilter);
+
+
+private:
+ QString _filter;
+ SimplifiedFilter* _simFilter;
+};
+
class SearchType
{
public:
SearchType();
int maxDepth() const { return _maxDepth; }
int maxSize() const { return _maxSize; }
- QString resultFilter() const { return _resultFilter; }
- QString matchLinks() const { return _matchLinks; }
- QString terminalId() const { return _terminalId; }
- Id startId() const { return _startId; }
- QMap<QString, QString> filterNamespaceDefinitions() const { return
_filterNamespaceDefinitions; }
-
+ const MetadataFilter& resultFilter() const { return _resultFilter; }
+ const MetadataFilter& matchLinks() const { return _matchLinks; }
+ const QString& terminalId() const { return _terminalId; }
+ const Id& startId() const { return _startId; }
+ const QMap<QString, QString>& filterNamespaceDefinitions() const {
return _filterNamespaceDefinitions; }
bool clientSetMaxDepth() const { return _clientSetMaxDepth; }
bool clientSetMaxSize() const { return _clientSetMaxSize; }
bool clientSetResultFilter() const { return _clientSetResultFilter; }
@@ -257,19 +283,19 @@

void setMaxDepth(int maxDepth) { _maxDepth = maxDepth;
_clientSetMaxDepth = true; }
void setMaxSize(int maxSize) { _maxSize = maxSize; _clientSetMaxSize =
true; }
- void setResultFilter(QString resultFilter) { _resultFilter =
resultFilter; _clientSetResultFilter = true; }
- void setMatchLinks(QString matchLinks) { _matchLinks = matchLinks;
_clientSetMatchLinks = true; }
- void setTerminalId(QString terminalId) { _terminalId = terminalId;
_clientSetTerminalId = true; }
+ void setResultFilter(const QString& resultFilter) {
_resultFilter.setFilter(resultFilter); _clientSetResultFilter = true; }
+ void setMatchLinks(const QString& matchLinks) {
_matchLinks.setFilter(matchLinks); _clientSetMatchLinks = true; }
+ void setTerminalId(const QString& terminalId) { _terminalId =
terminalId; _clientSetTerminalId = true; }
void setStartId(Id id) { _startId = id; }
- void setFilterNamespaceDefinitions(QMap<QString,QString> nsDefs)
{_filterNamespaceDefinitions = nsDefs; }
+ void setFilterNamespaceDefinitions(const QMap<QString,QString>&
nsDefs) {_filterNamespaceDefinitions = nsDefs; }
protected:
int _maxDepth;
bool _clientSetMaxDepth;
int _maxSize;
bool _clientSetMaxSize;
- QString _resultFilter;
+ MetadataFilter _resultFilter;
bool _clientSetResultFilter;
- QString _matchLinks;
+ MetadataFilter _matchLinks;
bool _clientSetMatchLinks;
QString _terminalId;
bool _clientSetTerminalId;
@@ -287,14 +313,14 @@

SubscribeOperation();

- void setName(QString name) { _name = name; }
- QString name() const { return _name; }
+ void setName(const QString& name) { _name = name; }
+ const QString& name() const { return _name; }

SubscribeOperation::SubscribeType subscribeType() const { return
_subscribeType; }
void setSubscribeType(SubscribeOperation::SubscribeType subType) {
_subscribeType = subType; }

- SearchType search() const { return _search; }
- void setSearch(SearchType search) { _search = search; }
+ const SearchType& search() const { return _search; }
+ void setSearch(const SearchType& search) { _search = search; }
private:
QString _name;
SubscribeOperation::SubscribeType _subscribeType;
@@ -308,8 +334,8 @@
SearchRequest(const SearchRequest&);
~SearchRequest() {;}

- SearchType search() const { return _search; }
- void setSearch(SearchType search) { _search = search; }
+ const SearchType& search() const { return _search; }
+ void setSearch(const SearchType& search) { _search = search; }
private:
SearchType _search;
};
@@ -323,7 +349,7 @@
~SubscribeRequest() { _subscribeOperations.clear();}

QList<SubscribeOperation> subscribeOperations() const { return
_subscribeOperations; }
- void addSubscribeOperation(SubscribeOperation subOper) {
_subscribeOperations.append(subOper); }
+ void addSubscribeOperation(const SubscribeOperation& subOper) {
_subscribeOperations.append(subOper); }
private:
QList<SubscribeOperation> _subscribeOperations;
};
=======================================
--- /trunk/mapresponse.cpp Tue Sep 27 20:40:47 2011
+++ /trunk/mapresponse.cpp Wed Jun 26 17:02:49 2013
@@ -77,7 +77,7 @@
_xmlWriter.writeEndElement(); // </SOAP-ENV:Body>
}

-void MapResponse::checkAddSessionId(QString sessionId)
+void MapResponse::checkAddSessionId(const QString& sessionId)
{
if (_requestVersion == MapRequest::IFMAPv11) {
_xmlWriter.writeStartElement(_soap_envelope, "Header");
@@ -86,7 +86,7 @@
}
}

-void MapResponse::writeIdentifier(Identifier id)
+void MapResponse::writeIdentifier(const Identifier& id)
{
if (_requestVersion == MapRequest::IFMAPv11) {
_xmlWriter.writeStartElement("identifier");
@@ -192,7 +192,7 @@
}
}

-void MapResponse::setClientFault(QString faultString)
+void MapResponse::setClientFault(const QString& faultString)
{
_xmlWriter.writeStartElement(_soap_envelope, "Body");
_xmlWriter.writeStartElement(_soap_envelope, "Fault");
@@ -203,7 +203,7 @@
finishEnvelope();
}

-void MapResponse::setErrorResponse(MapRequest::RequestError requestError,
QString sessionId, QString errorString, QString name)
+void MapResponse::setErrorResponse(const MapRequest::RequestError&
requestError, const QString& sessionId, const QString& errorString, const
QString& name)
{
checkAddSessionId(sessionId);
startResponse();
@@ -220,7 +220,7 @@
finishEnvelope();
}

-void MapResponse::setNewSessionResponse(QString sessionId, QString
publisherId, bool mprsSet, unsigned int mprs)
+void MapResponse::setNewSessionResponse(const QString& sessionId, const
QString& publisherId, bool mprsSet, unsigned int mprs)
{
if (_requestVersion == MapRequest::IFMAPv11) {
_xmlWriter.writeStartElement(_soap_envelope, "Header");
@@ -249,7 +249,7 @@
finishEnvelope();
}

-void MapResponse::setRenewSessionResponse(QString sessionId)
+void MapResponse::setRenewSessionResponse(const QString& sessionId)
{
startResponse();
_xmlWriter.writeEmptyElement("renewSessionResult");
@@ -258,7 +258,7 @@
finishEnvelope();
}

-void MapResponse::setEndSessionResponse(QString sessionId)
+void MapResponse::setEndSessionResponse(const QString& sessionId)
{
startResponse();
_xmlWriter.writeEmptyElement("endSessionResult");
@@ -267,7 +267,7 @@
finishEnvelope();
}

-void MapResponse::setAttachSessionResponse(QString sessionId, QString
publisherId)
+void MapResponse::setAttachSessionResponse(const QString& sessionId, const
QString& publisherId)
{
_xmlWriter.writeStartElement(_soap_envelope, "Header");
_xmlWriter.writeTextElement(IFMAP_NS_1, "session-id", sessionId);
@@ -281,7 +281,7 @@
finishEnvelope();
}

-void MapResponse::setPublishResponse(QString sessionId)
+void MapResponse::setPublishResponse(const QString& sessionId)
{
checkAddSessionId(sessionId);
startResponse();
@@ -290,7 +290,7 @@
finishEnvelope();
}

-void MapResponse::setSubscribeResponse(QString sessionId)
+void MapResponse::setSubscribeResponse(const QString& sessionId)
{
checkAddSessionId(sessionId);
startResponse();
@@ -299,7 +299,7 @@
finishEnvelope();
}

-void MapResponse::setPurgePublisherResponse(QString sessionId)
+void MapResponse::setPurgePublisherResponse(const QString& sessionId)
{
checkAddSessionId(sessionId);
startResponse();
@@ -308,7 +308,7 @@
finishEnvelope();
}

-void MapResponse::setSearchResults(QString sessionId, QList<SearchResult
*> searchResults)
+void MapResponse::setSearchResults(const QString& sessionId, const
QList<SearchResult *>& searchResults)
{
checkAddSessionId(sessionId);
startResponse();
@@ -334,7 +334,7 @@
finishEnvelope();
}

-void MapResponse::addLinkResult(Link link, QString metaXML)
+void MapResponse::addLinkResult(const Link& link, const QString& metaXML)
{
if (_requestVersion == MapRequest::IFMAPv11) {
_xmlWriter.writeStartElement("linkResult");
@@ -357,7 +357,7 @@
}
}

-void MapResponse::addIdentifierResult(Identifier id, QString metaXML)
+void MapResponse::addIdentifierResult(const Identifier& id, const QString&
metaXML)
{
if (_requestVersion == MapRequest::IFMAPv11) {
_xmlWriter.writeStartElement("identifierResult");
@@ -376,7 +376,7 @@
}
}

-void MapResponse::addMetadataResult(QString metaXML)
+void MapResponse::addMetadataResult(const QString& metaXML)
{
// TODO: It would be cleaner to just write the <metadata> tags here
// instead of adding them in Server::filteredMetadata(), but if I do
that
@@ -410,14 +410,14 @@
//_xmlWriter.writeEndElement(); // </metadata>
}

-void MapResponse::startPollResponse(QString sessionId)
+void MapResponse::startPollResponse(const QString& sessionId)
{
checkAddSessionId(sessionId);
startResponse();
_xmlWriter.writeStartElement("pollResult");
}

-void MapResponse::addPollErrorResult(QString subName,
MapRequest::RequestError error, QString errorString)
+void MapResponse::addPollErrorResult(const QString& subName, const
MapRequest::RequestError& error, const QString& errorString)
{
_xmlWriter.writeStartElement("errorResult");
_xmlWriter.writeAttribute("errorCode",
MapRequest::requestErrorString(error));
@@ -428,7 +428,7 @@
_xmlWriter.writeEndElement(); // </errorResult>
}

-void MapResponse::addPollResults(QList<SearchResult *> results, QString
subName)
+void MapResponse::addPollResults(const QList<SearchResult *>& results,
const QString& subName)
{
QListIterator<SearchResult *> srIt(results);

@@ -494,7 +494,7 @@
finishEnvelope();
}

-void MapResponse::startSearchResult(SearchResult::ResultType resultType,
QString subName)
+void MapResponse::startSearchResult(SearchResult::ResultType resultType,
const QString& subName)
{
QString tagName = "";
switch (resultType) {
=======================================
--- /trunk/mapresponse.h Tue Sep 27 20:40:47 2011
+++ /trunk/mapresponse.h Wed Jun 26 17:02:49 2013
@@ -56,41 +56,41 @@
MapResponse(MapRequest::RequestVersion reqVersion);
~MapResponse();

- QByteArray responseData() const { return _responseBuffer.data(); }
+ const QByteArray& responseData() const { return
_responseBuffer.data(); }
MapRequest::RequestVersion requestVersion() const { return
_requestVersion; }

- void setClientFault(QString faultString);
+ void setClientFault(const QString &faultString);

- void setErrorResponse(MapRequest::RequestError requestError, QString
sessionId, QString errorString = "", QString name = "");
- void setNewSessionResponse(QString sessiondId, QString publisherId,
bool mprsSet = false, unsigned int mprs = 0);
- void setRenewSessionResponse(QString sessiondId);
- void setEndSessionResponse(QString sessiondId);
- void setAttachSessionResponse(QString sessionId, QString publisherId);
- void setPublishResponse(QString sessionId);
- void setSubscribeResponse(QString sessionId);
- void setPurgePublisherResponse(QString sessionId);
+ void setErrorResponse(const MapRequest::RequestError& requestError,
const QString& sessionId, const QString& errorString = "", const QString&
name = "");
+ void setNewSessionResponse(const QString& sessiondId, const QString&
publisherId, bool mprsSet = false, unsigned int mprs = 0);
+ void setRenewSessionResponse(const QString& sessiondId);
+ void setEndSessionResponse(const QString& sessiondId);
+ void setAttachSessionResponse(const QString& sessionId, const QString&
publisherId);
+ void setPublishResponse(const QString& sessionId);
+ void setSubscribeResponse(const QString& sessionId);
+ void setPurgePublisherResponse(const QString& sessionId);

- void setSearchResults(QString sessionId, QList<SearchResult *>
searchResults);
+ void setSearchResults(const QString& sessionId, const
QList<SearchResult *>& searchResults);

- void startPollResponse(QString sessionId);
- void addPollErrorResult(QString subName, MapRequest::RequestError
error, QString errorString = "");
- void addPollResults(QList<SearchResult *> results, QString subName);
+ void startPollResponse(const QString& sessionId);
+ void addPollErrorResult(const QString& subName, const
MapRequest::RequestError& error, const QString& errorString = "");
+ void addPollResults(const QList<SearchResult *>& results, const
QString& subName);
void endPollResponse();

private:
MapResponse(); // Don't use

- void checkAddSessionId(QString sessionId);
+ void checkAddSessionId(const QString& sessionId);
void finishEnvelope();
void startResponse();
void endResponse();
- void writeIdentifier(Identifier id);
+ void writeIdentifier(const Identifier& id);

- void addLinkResult(Link link, QString metaXML);
- void addIdentifierResult(Identifier id, QString metaXML);
- void addMetadataResult(QString metaXML);
+ void addLinkResult(const Link& link, const QString& metaXML);
+ void addIdentifierResult(const Identifier& id, const QString& metaXML);
+ void addMetadataResult(const QString& metaXML);

- void startSearchResult(SearchResult::ResultType resultType, QString
subName);
+ void startSearchResult(SearchResult::ResultType resultType, const
QString& subName);
void endSearchResult();
private:
const char *_soap_envelope;
=======================================
--- /trunk/mapsessions.cpp Thu May 23 16:56:04 2013
+++ /trunk/mapsessions.cpp Wed Jun 26 17:02:49 2013
@@ -71,7 +71,7 @@

void MapSessions::loadClientConfigurations()
{
- QList<ClientConfiguration *> clientConfigurations =
_omapdConfig->clientConfigurations();
+ const QList<ClientConfiguration *>& clientConfigurations =
_omapdConfig->clientConfigurations();

QListIterator<ClientConfiguration *> clientIt(clientConfigurations);
while (clientIt.hasNext()) {
@@ -80,7 +80,7 @@
}
}

-bool MapSessions::loadClientConfiguration(ClientConfiguration *client)
+bool MapSessions::loadClientConfiguration(const ClientConfiguration
*client)
{
bool clientConfigOk = false;

@@ -141,7 +141,7 @@

if (clientConfigOk) {
if (client->authType() == MapRequest::AuthCACert) {
- MapClient mapClient(authToken, client->authType(),
client->authz(), "", client->metadataPolicy());
+ MapClient* mapClient = new MapClient(authToken,
client->authType(), client->authz(), "", client->metadataPolicy());
_mapClientCAs.insert(authToken, mapClient);

if (!client->blacklistDirectory().isEmpty()) {
@@ -159,13 +159,13 @@
QString pubId;
if (_mapClients.contains(authToken)) {
// Don't create new publisher-id if replacing client config
- pubId = _mapClients.value(authToken).pubId();
+ pubId = _mapClients.value(authToken)->pubId();
} else {
// Create a new publisher-id for this client
pubId.setNum(_pubIdIndex++);
}

- MapClient mapClient(authToken, client->authType(),
client->authz(), pubId, client->metadataPolicy());
+ MapClient* mapClient = new MapClient(authToken,
client->authType(), client->authz(), pubId, client->metadataPolicy());
_mapClients.insert(authToken, mapClient);
if
(_omapdConfig->valueFor("debug_level").value<OmapdConfig::IfmapDebugOptions>().testFlag(OmapdConfig::ShowClientOps))
{
qDebug() << __PRETTY_FUNCTION__ << ":" << "Created
MapClient for client configuration named:" << client->name()
@@ -226,12 +226,12 @@

if (clientConfigOk) {
if (client->authType() == MapRequest::AuthCACert) {
- _mapClientCAs.remove(authToken);
+ removeMapClientCA(authToken);
if
(_omapdConfig->valueFor("debug_level").value<OmapdConfig::IfmapDebugOptions>().testFlag(OmapdConfig::ShowClientOps))
{
qDebug() << __PRETTY_FUNCTION__ << ":" << "Removed CA
Authentication MapClient with authToken" << authToken;
}
} else {
- _mapClients.remove(authToken);
+ removeMapClient(authToken);
if
(_omapdConfig->valueFor("debug_level").value<OmapdConfig::IfmapDebugOptions>().testFlag(OmapdConfig::ShowClientOps))
{
qDebug() << __PRETTY_FUNCTION__ << ":" << "Removed
MapClient with authToken" << authToken;
}
@@ -350,15 +350,13 @@
_activePollConnections.remove(authToken);

if (_mapClients.contains(authToken)) {
- MapClient client = _mapClients.take(authToken);
- client.setHasActiveARC(false);
- client.setHasActivePoll(false);
- _mapClients.insert(authToken, client);
+ _mapClients[authToken]->setHasActiveARC(false);
+ _mapClients[authToken]->setHasActivePoll(false);
}
}
}

-QString MapSessions::registerMapClient(ClientHandler *clientHandler,
MapRequest::AuthenticationType authType, QString authToken)
+QString MapSessions::registerMapClient(ClientHandler *clientHandler,
MapRequest::AuthenticationType authType, const QString& authToken)
{
QString pubId;
bool registered = false;
@@ -371,7 +369,7 @@
}
} else if (_mapClients.contains(authToken)) {
// Already have a publisher-id for this client
- pubId = _mapClients.value(authToken).pubId();
+ pubId = _mapClients[authToken]->pubId();
if
(_omapdConfig->valueFor("debug_level").value<OmapdConfig::IfmapDebugOptions>().testFlag(OmapdConfig::ShowClientOps))
{
qDebug() << __PRETTY_FUNCTION__ << ":" << "Already have
client configuration with pub-id:" << pubId;
}
@@ -383,9 +381,9 @@
// Create a new publisher-id for this client
pubId.setNum(_pubIdIndex++);
// Set the client authorization as determined by CA Cert
setting
- OmapdConfig::AuthzOptions authz =
_mapClientCAs.value(compToken.last()).authz();
- QString metadataPolicy =
_mapClientCAs.value(compToken.last()).metadataPolicy();
- MapClient client(authToken, authType, authz, pubId,
metadataPolicy);
+ OmapdConfig::AuthzOptions authz =
_mapClientCAs[compToken.last()]->authz();
+ QString metadataPolicy =
_mapClientCAs[compToken.last()]->metadataPolicy();
+ MapClient* client = new MapClient(authToken, authType,
authz, pubId, metadataPolicy);
_mapClients.insert(authToken, client);

registered = true;
@@ -398,7 +396,7 @@
pubId.setNum(_pubIdIndex++);
OmapdConfig::AuthzOptions authz =
_omapdConfig->valueFor("default_authorization").value<OmapdConfig::AuthzOptions>();
// TODO: Allow application of metadataPolicy to clients
created this way
- MapClient client(authToken, authType, authz, pubId, "");
+ MapClient* client = new MapClient(authToken, authType, authz,
pubId, "");
_mapClients.insert(authToken, client);

registered = true;
@@ -421,56 +419,91 @@
return pubId;
}

-bool MapSessions::haveActiveSSRCForClient(QString authToken)
+void MapSessions::removeMapClient(const QString& authToken)
+{
+ if(_mapClients.contains(authToken))
+ {
+ delete _mapClients[authToken];
+ _mapClients.remove(authToken);
+ }
+}
+
+void MapSessions::removeMapClientCA(const QString& authToken)
+{
+ if(_mapClientCAs.contains(authToken))
+ {
+ delete _mapClientCAs[authToken];
+ _mapClientCAs.remove(authToken);
+ }
+}
+
+
+bool MapSessions::haveActiveSSRCForClient(const QString& authToken)
{
bool haveSSRC = false;

if (_mapClients.contains(authToken)) {
- haveSSRC = ! _mapClients.value(authToken).sessId().isEmpty();
+
+ // LFu: access hash element in-place
+ haveSSRC = ! _mapClients[authToken]->sessId().isEmpty();
}
return haveSSRC;
}

-void MapSessions::removeActiveSSRCForClient(QString authToken)
+void MapSessions::removeActiveSSRCForClient(const QString& authToken)
{
if (_mapClients.contains(authToken) &&
- _mapClients.value(authToken).hasActiveSSRC()) {
- MapClient client = _mapClients.take(authToken);
- client.setHasActiveSSRC(false);
- client.clearSessId();
- _mapClients.insert(authToken, client);
+ _mapClients[authToken]->hasActiveSSRC()) {
+ // LFu: manipulate hash element in-place
+ MapClient* client = _mapClients[authToken];
+ client->setHasActiveSSRC(false);
+ client->clearSessId();

_ssrcConnections.remove(authToken);
}
}

-QString MapSessions::sessIdForClient(QString authToken)
+QString MapSessions::sessIdForClient(const QString& authToken)
{
QString sessId;
if (_mapClients.contains(authToken)) {
- sessId = _mapClients.value(authToken).sessId();
+ // LFu: access hash element in-place
+ sessId = _mapClients[authToken]->sessId();
}
return sessId;
}

-QString MapSessions::pubIdForSessId(QString sessId)
+QString MapSessions::pubIdForSessId(const QString& sessId)
{
QString pubId;
- QList<MapClient> clientList = _mapClients.values();
- bool done = false;
- int i=0;
+
+ QHash<QString, MapClient*>::const_iterator i =
_mapClients.constBegin();
+ while (i != _mapClients.constEnd()) {

- while (!done && i<clientList.size()) {
- if (clientList[i].sessId().compare(sessId, Qt::CaseSensitive) ==
0) {
- done = true;
- pubId = clientList[i].pubId();
+ const MapClient* client = i.value();
+ if (client->sessId() == sessId) {
+ pubId = client->pubId();
+ break;
}
- i++;
+ ++i;
}
+
+// (LFu) was:
+// QList<MapClient> clientList = _mapClients.values();
+// bool done = false;
+// int i=0;
+
+// while (!done && i<clientList.size()) {
+// if (clientList[i].sessId().compare(sessId, Qt::CaseSensitive) ==
0) {
+// done = true;
+// pubId = clientList[i].pubId();
+// }
+// i++;
+// }
return pubId;
}

-QString MapSessions::addActiveSSRCForClient(ClientHandler *clientHandler,
QString authToken)
+QString MapSessions::addActiveSSRCForClient(ClientHandler *clientHandler,
const QString& authToken)
{
QString sessId;
if (_mapClients.contains(authToken)) {
@@ -478,63 +511,63 @@
if
(_omapdConfig->valueFor("debug_level").value<OmapdConfig::IfmapDebugOptions>().testFlag(OmapdConfig::ShowClientOps))
qDebug() << __PRETTY_FUNCTION__ << ":" << "Got session-id to
use:" << sessId;

- MapClient client = _mapClients.take(authToken);
- client.setSessId(sessId);
- client.setHasActiveSSRC(true);
- _mapClients.insert(authToken, client);
+ // LFu: code changed to modify MapClient in-place
+ MapClient* client = _mapClients[authToken];
+ client->setSessId(sessId);
+ client->setHasActiveSSRC(true);

_ssrcConnections.insert(authToken, clientHandler);
}
return sessId;
}

-bool MapSessions::validateSessionId(QString sessId, QString authToken)
+bool MapSessions::validateSessionId(const QString& sessId, const QString&
authToken)
{
bool rc = false;
if (_mapClients.contains(authToken) &&
- _mapClients.value(authToken).hasActiveSSRC() &&
- _mapClients.value(authToken).sessId().compare(sessId,
Qt::CaseSensitive) == 0) {
+ _mapClients[authToken]->hasActiveSSRC() &&
+ _mapClients[authToken]->sessId() == sessId) {
rc = true;
}
return rc;
}

-QString MapSessions::pubIdForAuthToken(QString authToken)
+QString MapSessions::pubIdForAuthToken(const QString& authToken)
{
QString pubId;
if (_mapClients.contains(authToken)) {
- pubId = _mapClients.value(authToken).pubId();
+ pubId = _mapClients[authToken]->pubId();
}
return pubId;
}

-OmapdConfig::AuthzOptions MapSessions::authzForAuthToken(QString authToken)
+OmapdConfig::AuthzOptions MapSessions::authzForAuthToken(const QString&
authToken)
{
OmapdConfig::AuthzOptions authz =
_omapdConfig->valueFor("default_authorization").value<OmapdConfig::AuthzOptions>();
if (_mapClients.contains(authToken)) {
- authz = _mapClients.value(authToken).authz();
+ authz = _mapClients[authToken]->authz();
}
return authz;
}

-bool MapSessions::metadataAuthorizationForAuthToken(QString authToken,
QString metaName, QString metaNamespace)
+bool MapSessions::metadataAuthorizationForAuthToken(const QString&
authToken, const QString& metaName, const QString& metaNamespace)
{
bool clientAuthorized = false;
if (_mapClients.contains(authToken)) {
- QString policyName = _mapClients.value(authToken).metadataPolicy();
+ const QString& policyName =
_mapClients[authToken]->metadataPolicy();

if (policyName.isEmpty()) {
// No policy defined for client
clientAuthorized = true;
} else {
- QList<VSM> metaAllowed =
_omapdConfig->metadataPolicies().values(policyName);
- QListIterator<VSM> i(metaAllowed);
- while (i.hasNext() && !clientAuthorized) {
- VSM metaAllowed = i.next();
- if (metaAllowed.first == metaName && metaAllowed.second ==
metaNamespace) {
- clientAuthorized = true;
- }
- }
+ QList<VSM> metaAllowed =
_omapdConfig->metadataPolicies().values(policyName);
+ QListIterator<VSM> i(metaAllowed);
+ while (i.hasNext() && !clientAuthorized) {
+ VSM metaAllowed = i.next();
+ if (metaAllowed.first == metaName && metaAllowed.second
== metaNamespace) {
+ clientAuthorized = true;
+ }
+ }
}

if
(_omapdConfig->valueFor("debug_level").value<OmapdConfig::IfmapDebugOptions>().testFlag(OmapdConfig::ShowClientOps))
{
@@ -547,157 +580,173 @@
return clientAuthorized;
}

-bool MapSessions::haveActivePollForClient(QString authToken)
+bool MapSessions::haveActivePollForClient(const QString& authToken)
{
bool rc = false;
if (_mapClients.contains(authToken)) {
- rc = _mapClients.value(authToken).hasActivePoll();
+ rc = _mapClients[authToken]->hasActivePoll();
}
return rc;
}

-void MapSessions::setActivePollForClient(QString authToken, ClientHandler
*pollClientHandler)
+void MapSessions::setActivePollForClient(const QString& authToken,
ClientHandler *pollClientHandler)
{
if (_mapClients.contains(authToken)) {
- MapClient client = _mapClients.take(authToken);
- client.setHasActivePoll(true);
- _mapClients.insert(authToken, client);
+
+ MapClient* client = _mapClients[authToken];
+ client->setHasActivePoll(true);

_activePollConnections.insert(authToken, pollClientHandler);
}
}

-void MapSessions::removeActivePollForClient(QString authToken)
+void MapSessions::removeActivePollForClient(const QString& authToken)
{
if (_mapClients.contains(authToken) &&
- _mapClients.value(authToken).hasActivePoll()) {
- MapClient client = _mapClients.take(authToken);
- client.setHasActivePoll(false);
- _mapClients.insert(authToken, client);
+ _mapClients[authToken]->hasActivePoll()) {

+ _mapClients[authToken]->setHasActivePoll(false);
_activePollConnections.remove(authToken);
}
}

-ClientHandler* MapSessions::pollConnectionForClient(QString authToken)
+ClientHandler* MapSessions::pollConnectionForClient(const QString&
authToken)
{
ClientHandler* clientHandler = 0;
if (_mapClients.contains(authToken) &&
- _mapClients.value(authToken).hasActiveARC() &&
- _mapClients.value(authToken).hasActivePoll()) {
+ _mapClients[authToken]->hasActiveARC() &&
+ _mapClients[authToken]->hasActivePoll()) {
clientHandler = _activePollConnections.value(authToken, 0);
}
return clientHandler;
}

-ClientHandler* MapSessions::ssrcForClient(QString authToken)
+ClientHandler* MapSessions::ssrcForClient(const QString& authToken)
{
ClientHandler* clientHandler = 0;
if (_mapClients.contains(authToken) &&
- _mapClients.value(authToken).hasActiveSSRC()) {
+ _mapClients[authToken]->hasActiveSSRC()) {
clientHandler = _ssrcConnections.value(authToken, 0);
}
return clientHandler;
}

-void MapSessions::migrateSSRCForClient(QString authToken, ClientHandler
*newSSRCClientHandler)
+void MapSessions::migrateSSRCForClient(const QString& authToken,
ClientHandler *newSSRCClientHandler)
{
if (_mapClients.contains(authToken) &&
- _mapClients.value(authToken).hasActiveSSRC()) {
+ _mapClients[authToken]->hasActiveSSRC()) {
ClientHandler *oldConnection = _ssrcConnections.take(authToken);
_ssrcConnections.insert(authToken, newSSRCClientHandler);
oldConnection->disconnectFromHost();
}
}

-void MapSessions::setActiveARCForClient(QString authToken, ClientHandler
*arcClientHandler)
+void MapSessions::setActiveARCForClient(const QString& authToken,
ClientHandler *arcClientHandler)
{
if (_mapClients.contains(authToken) &&
- _mapClients.value(authToken).hasActiveSSRC()) {
- MapClient client = _mapClients.take(authToken);
- client.setHasActiveARC(true);
- _mapClients.insert(authToken, client);
+ _mapClients[authToken]->hasActiveSSRC()) {
+
+ _mapClients[authToken]->setHasActiveARC(true);

_arcConnections.insert(authToken, arcClientHandler);
}
}

-bool MapSessions::haveActiveARCForClient(QString authToken)
+bool MapSessions::haveActiveARCForClient(const QString& authToken)
{
bool rc = false;
if (_mapClients.contains(authToken) &&
- _mapClients.value(authToken).hasActiveARC()) {
+ _mapClients[authToken]->hasActiveARC()) {
rc = true;
}
return rc;
}

-void MapSessions::removeActiveARCForClient(QString authToken)
+void MapSessions::removeActiveARCForClient(const QString& authToken)
{
if (_mapClients.contains(authToken) &&
- _mapClients.value(authToken).hasActiveARC()) {
- MapClient client = _mapClients.take(authToken);
- client.setHasActiveARC(false);
- _mapClients.insert(authToken, client);
+ _mapClients[authToken]->hasActiveARC()) {

+ _mapClients[authToken]->setHasActiveARC(false);
_arcConnections.remove(authToken);
}
}

-ClientHandler* MapSessions::arcForClient(QString authToken)
+ClientHandler* MapSessions::arcForClient(const QString& authToken)
{
ClientHandler* clientHandler = 0;
if (_mapClients.contains(authToken) &&
- _mapClients.value(authToken).hasActiveARC()) {
+ _mapClients[authToken]->hasActiveARC()) {
clientHandler = _arcConnections.value(authToken, 0);
}
- return clientHandler;}
+ return clientHandler;
+}

-QList<Subscription> MapSessions::subscriptionListForClient(QString
authToken)
+QList<Subscription*>& MapSessions::subscriptionListForClient(const
QString& authToken)
{
- QList<Subscription> subList;
+ // LFu: changed this to return a reference to the client subscriptions
and
+ // changed usage of the method to make changes in-place. Before, the
caller
+ // retrieved a copy of the list, changed that list and then had to
restore
+ // the whole list back in order to make changes
+
+ return _mapClients[authToken]->subscriptionList();
+
+// was:
+// QList<Subscription> subList;
+// if (_mapClients.contains(authToken)) {
+// subList = _mapClients[authToken].subscriptionList();
+// }
+// return subList;
+}
+
+void MapSessions::insertSubscriptionForClient(Subscription* sub, const
QString& authToken)
+{
if (_mapClients.contains(authToken)) {
- subList = _mapClients.value(authToken).subscriptionList();
+ _mapClients[authToken]->insertSubscription(sub);
}
- return subList;
}

-QList<Subscription> MapSessions::removeSubscriptionListForClient(QString
authToken)
+void MapSessions::removeSubscriptionForClient(const QString& name, const
QString& authToken)
{
- QList<Subscription> subList;
if (_mapClients.contains(authToken)) {
- MapClient client = _mapClients.take(authToken);
- subList = client.subscriptionList();
- client.emptySubscriptionList();
- _mapClients.insert(authToken, client);
+ _mapClients[authToken]->removeSubscription(name);
}
- return subList;
+
}

-void MapSessions::setSubscriptionListForClient(QString authToken,
QList<Subscription> subList)
+int MapSessions::removeSubscriptionListForClient(const QString& authToken)
{
+ int result = 0;
if (_mapClients.contains(authToken)) {
- MapClient client = _mapClients.take(authToken);
- client.setSubscriptionList(subList);
- _mapClients.insert(authToken, client);
+ MapClient* client = _mapClients[authToken];
+ result = client->subscriptionList().size();
+ client->clearSubscriptionList();
}
+ return result;
}

-QHash<QString, QList<Subscription> > MapSessions::subscriptionLists()
+//void MapSessions::setSubscriptionListForClient(const QString& authToken,
const QList<Subscription>& subList)
+//{
+// if (_mapClients.contains(authToken)) {
+// _mapClients[authToken].setSubscriptionList(subList);
+// }
+//}
+
+QHash<QString, QList<Subscription*> > MapSessions::subscriptionLists()
{
- QHash<QString, QList<Subscription> > allSubLists;
+ QHash<QString, QList<Subscription*> > allSubLists;

- QHashIterator<QString, MapClient> clientIt(_mapClients);
+ QHashIterator<QString, MapClient*> clientIt(_mapClients);
while (clientIt.hasNext()) {
clientIt.next();
- if (clientIt.value().subscriptionList().size() > 0) {
- allSubLists.insert(clientIt.key(),
clientIt.value().subscriptionList());
+ if (clientIt.value()->subscriptionList().size() > 0) {
+ allSubLists.insert(clientIt.key(),
clientIt.value()->subscriptionList());
}
}
return allSubLists;
}

-bool MapSessions::validateMetadata(Meta aMeta)
+bool MapSessions::validateMetadata(const Meta& aMeta)
{
bool isValid = false;

@@ -766,3 +815,18 @@

return isValid;
}
+
+QSet<Subscription*> MapSessions::getSubscriptionsForIdentifier(const Id&
id)
+{
+ return _subs[id];
+}
+
+void MapSessions::addToIndex(const Id& id, Subscription* sub)
+{
+ _subs[id].insert(sub);
+}
+
+void MapSessions::removeFromIndex(const Id& id, Subscription* sub)
+{
+ _subs[id].remove(sub);
+}
=======================================
--- /trunk/mapsessions.h Thu May 23 16:56:04 2013
+++ /trunk/mapsessions.h Wed Jun 26 17:02:49 2013
@@ -45,43 +45,45 @@

static MapSessions* getInstance();

- QString registerMapClient(ClientHandler *socket,
MapRequest::AuthenticationType authType, QString authToken);
- QString sessIdForClient(QString authToken);
- QString addActiveSSRCForClient(ClientHandler *clientHandler, QString
authToken);
+ QString registerMapClient(ClientHandler *socket,
MapRequest::AuthenticationType authType, const QString& authToken);
+ QString sessIdForClient(const QString& authToken);
+ QString addActiveSSRCForClient(ClientHandler *clientHandler, const
QString& authToken);

- bool haveActiveSSRCForClient(QString authToken);
- void removeActiveSSRCForClient(QString authToken);
+ bool haveActiveSSRCForClient(const QString& authToken);
+ void removeActiveSSRCForClient(const QString& authToken);

- bool haveActivePollForClient(QString authToken);
- void setActivePollForClient(QString authToken, ClientHandler
*pollClientHandler);
- void removeActivePollForClient(QString authToken);
- ClientHandler* pollConnectionForClient(QString authToken);
- ClientHandler* ssrcForClient(QString authToken);
- void migrateSSRCForClient(QString authToken, ClientHandler
*newSSRCClientHandler);
+ bool haveActivePollForClient(const QString& authToken);
+ void setActivePollForClient(const QString& authToken, ClientHandler
*pollClientHandler);
+ void removeActivePollForClient(const QString& authToken);
+ ClientHandler* pollConnectionForClient(const QString& authToken);
+ ClientHandler* ssrcForClient(const QString& authToken);
+ void migrateSSRCForClient(const QString& authToken, ClientHandler
*newSSRCClientHandler);

- void setActiveARCForClient(QString authToken, ClientHandler
*arcClientHandler);
- bool haveActiveARCForClient(QString authToken);
- void removeActiveARCForClient(QString authToken);
- ClientHandler* arcForClient(QString authToken);
+ void setActiveARCForClient(const QString& authToken, ClientHandler
*arcClientHandler);
+ bool haveActiveARCForClient(const QString& authToken);
+ void removeActiveARCForClient(const QString& authToken);
+ ClientHandler* arcForClient(const QString& authToken);

void removeClientConnections(ClientHandler *clientHandler);
- bool validateSessionId(QString sessId, QString authToken);
+ bool validateSessionId(const QString& sessId, const QString&
authToken);

- QString pubIdForAuthToken(QString authToken);
- QString pubIdForSessId(QString sessId);
- OmapdConfig::AuthzOptions authzForAuthToken(QString authToken);
- bool metadataAuthorizationForAuthToken(QString authToken, QString
metaName, QString metaNamespace);
+ QString pubIdForAuthToken(const QString& authToken);
+ QString pubIdForSessId(const QString& sessId);
+ OmapdConfig::AuthzOptions authzForAuthToken(const QString& authToken);
+ bool metadataAuthorizationForAuthToken(const QString& authToken, const
QString& metaName, const QString& metaNamespace);

- QList<Subscription> subscriptionListForClient(QString authToken);
- QList<Subscription> removeSubscriptionListForClient(QString authToken);
- void setSubscriptionListForClient(QString authToken,
QList<Subscription> subList);
- QHash<QString, QList<Subscription> > subscriptionLists(); // authToken
--> subscriptionList for authToken
+ QList<Subscription*>& subscriptionListForClient(const QString&
authToken);
+ void insertSubscriptionForClient(Subscription* sub, const
QString&_authToken);
+ void removeSubscriptionForClient(const QString& name, const
QString&_authToken);
+ int removeSubscriptionListForClient(const QString& authToken);
+ // void setSubscriptionListForClient(const QString& authToken, const
QList<Subscription>& subList);
+ QHash<QString, QList<Subscription*> > subscriptionLists(); //
authToken --> subscriptionList for authToken

- bool validateMetadata(Meta aMeta);
+ bool validateMetadata(const Meta& aMeta);

QString generateSessionId();

- bool loadClientConfiguration(ClientConfiguration *client);
+ bool loadClientConfiguration(const ClientConfiguration *client);
bool removeClientConfiguration(ClientConfiguration *client);

void loadBlacklistedClients(QString blacklistDirectory, QString
caCertFile);
@@ -89,6 +91,15 @@
bool addBlacklistClientConfiguration(ClientConfiguration *client);
bool removeBlacklistClientConfiguration(ClientConfiguration *client);

+ void removeMapClient(const QString& authToken);
+ void removeMapClientCA(const QString& authToken);
+
+ QSet<Subscription*> getSubscriptionsForIdentifier(const Id& id); //
return list of all subscriptions that
+ //
include id in their search graph
+ void addToIndex(const Id& id, Subscription* sub);
+ void removeFromIndex(const Id& id, Subscription* sub);
+
+
private:
MapSessions(QObject *parent = 0);
~MapSessions();
@@ -98,8 +109,9 @@

OmapdConfig *_omapdConfig;

- QHash<QString, MapClient> _mapClients; // authToken --> MapClient
- QHash<QString, MapClient> _mapClientCAs; // CA AuthToken --> MapClient
+ QHash<QString, MapClient*> _mapClients; // authToken --> MapClient
+ QHash<QString, MapClient*> _mapClientCAs; // CA AuthToken --> MapClient
+ QHash<Id, QSet<Subscription*> > _subs; // Identifier --> list of
referenced subscriptions
QSet<QString> _blacklistedClients; // blacklisted client authToken
// Registry for published vendor specific metadata cardinalities
QHash<VSM, Meta::Cardinality> _vsmRegistry;
=======================================
--- /trunk/metadata.cpp Sun Oct 28 22:12:29 2012
+++ /trunk/metadata.cpp Wed Jun 26 17:02:49 2013
@@ -26,7 +26,7 @@
{
}

-QString Meta::lifetimeString()
+QString Meta::lifetimeString() const
{
QString str("");
switch (_lifetime) {
=======================================
--- /trunk/metadata.h Sun Oct 28 22:12:29 2012
+++ /trunk/metadata.h Wed Jun 26 17:02:49 2013
@@ -47,20 +47,20 @@
Meta(Meta::Cardinality cardinality = Meta::SingleValue,
Meta::Lifetime lifetime = Meta::LifetimeSession);

- Meta::Cardinality cardinality() { return _cardinality; }
+ Meta::Cardinality cardinality() const { return _cardinality; }
Meta::Lifetime lifetime() const { return _lifetime; }
- QString lifetimeString();
+ QString lifetimeString() const;

- QString publisherId() const { return _publisherId; }
- QString elementName() const { return _elementName; }
- QString elementNS() const { return _elementNS; }
- QString metaXML() const { return _metaXML; }
+ const QString& publisherId() const { return _publisherId; }
+ const QString& elementName() const { return _elementName; }
+ const QString& elementNS() const { return _elementNS; }
+ const QString& metaXML() const { return _metaXML; }

void setLifetime(Meta::Lifetime lifetime) { _lifetime = lifetime; }
- void setPublisherId(QString pubId) { _publisherId = pubId; }
- void setElementName(QString elementName) { _elementName = elementName;
}
- void setElementNS(QString elementNS) { _elementNS = elementNS; }
- void setMetaXML(QString metaXML) {_metaXML = metaXML; }
+ void setPublisherId(const QString& pubId) { _publisherId = pubId; }
+ void setElementName(const QString& elementName) { _elementName =
elementName; }
+ void setElementNS(const QString& elementNS) { _elementNS = elementNS; }
+ void setMetaXML(const QString& metaXML) {_metaXML = metaXML; }

// Two Meta objects are equal iff their elementName and namespace
members are the same
bool operator==(const Meta &other) const;
=======================================
--- /trunk/omapdconfig.cpp Thu May 23 16:56:04 2013
+++ /trunk/omapdconfig.cpp Wed Jun 26 17:02:49 2013
@@ -33,6 +33,14 @@
}
return _instance;
}
+
+void OmapdConfig::destroy()
+{
+ if (_instance != 0) {
+ delete _instance;
+ _instance = NULL;
+ }
+}

OmapdConfig::IfmapDebugOptions OmapdConfig::debugOptions(unsigned int
dbgValue)
{
@@ -189,9 +197,16 @@
{
const char *fnName = "OmapdConfig::~OmapdConfig():";
qDebug() << fnName;
+
+ QListIterator<ClientConfiguration *> it(_clientConfigurations);
+ while(it.hasNext())
+ {
+ delete it.next();
+ }
+ _clientConfigurations.clear();
}

-void OmapdConfig::addConfigItem(QString key, QVariant value)
+void OmapdConfig::addConfigItem(const QString& key, const QVariant& value)
{
_omapdConfig.insert(key,value);
}
@@ -622,7 +637,7 @@
return !xmlReader.error();
}

-int OmapdConfig::readConfigFile(QString configFileName)
+int OmapdConfig::readConfigFile(const QString& configFileName)
{
const char *fnName = "ConfigFile::readConfigFile:";
int rc = 0;
@@ -646,8 +661,7 @@
return rc;
}

-QVariant OmapdConfig::valueFor(QString key)
+const QVariant& OmapdConfig::valueFor(const QString& key)
{
- QVariant value = _omapdConfig.value(key);
- return value;
+ return _omapdConfig[key];
}
=======================================
--- /trunk/omapdconfig.h Sun Feb 24 14:35:44 2013
+++ /trunk/omapdconfig.h Wed Jun 26 17:02:49 2013
@@ -72,21 +72,24 @@
AllowAll = 0x3F // Convenience enum "or" of all allow options
};
Q_DECLARE_FLAGS(AuthzOptions, Authz);
+
+ static void destroy();
+
static AuthzOptions authzOptions(unsigned int authzValue);
static QString authzOptionsString(OmapdConfig::AuthzOptions option);

static OmapdConfig* getInstance();

- bool isSet(QString key) { return _omapdConfig.contains(key); }
- QVariant valueFor(QString key);
+ bool isSet(const QString& key) { return _omapdConfig.contains(key); }
+ const QVariant& valueFor(const QString& key);
void showConfigValues();

- QList<ClientConfiguration *> clientConfigurations() { return
_clientConfigurations; }
- QMultiHash<QString, VSM> metadataPolicies() { return
_metadataPolicies; }
+ const QList<ClientConfiguration *>& clientConfigurations() { return
_clientConfigurations; }
+ const QMultiHash<QString, VSM>& metadataPolicies() { return
_metadataPolicies; }

- int readConfigFile(QString configFileName = "omapd.conf");
+ int readConfigFile(const QString& configFileName = "omapd.conf");

- void addConfigItem(QString key, QVariant value);
+ void addConfigItem(const QString& key, const QVariant& value);
private:
OmapdConfig(QObject * parent = 0);
~OmapdConfig();
=======================================
--- /trunk/server.cpp Wed Dec 26 15:49:29 2012
+++ /trunk/server.cpp Wed Jun 26 17:02:49 2013
@@ -118,7 +118,7 @@
client->deleteLater();
}

-void Server::addClientToTimeout(QString authToken)
+void Server::addClientToTimeout(const QString& authToken)
{
ClientHandler *client = (ClientHandler*)sender();
_clientAuthTokens.insert(client, authToken);
@@ -136,7 +136,7 @@
_clientAuthTokens.remove(client);
}

-void Server::removeTimerForClient(QString authToken)
+void Server::removeTimerForClient(const QString& authToken)
{
if (_clientTimeouts.contains(authToken)) {
QTimer *timer = _clientTimeouts.take(authToken);
@@ -157,9 +157,9 @@
qDebug() << __PRETTY_FUNCTION__ << ":" << "Time to remove
session metadata for client with authToken:" << authToken;
ClientHandler client(_mapGraph, authToken, this);
connect(&client,
-
SIGNAL(needToSendPollResponse(ClientHandler*,QByteArray,MapRequest::RequestVersion)),
+ SIGNAL(needToSendPollResponse(ClientHandler*, const
QByteArray&,MapRequest::RequestVersion)),
this,
-
SLOT(sendPollResponseToClient(ClientHandler*,QByteArray,MapRequest::RequestVersion)));
+ SLOT(sendPollResponseToClient(ClientHandler*,const
QByteArray&,MapRequest::RequestVersion)));
client.sessionMetadataTimeout();

removeTimerForClient(authToken);
@@ -169,7 +169,7 @@

}

-void Server::sendPollResponseToClient(ClientHandler *client, QByteArray
response, MapRequest::RequestVersion reqVersion)
+void Server::sendPollResponseToClient(ClientHandler *client, const
QByteArray& response, MapRequest::RequestVersion reqVersion)
{
if (client) {
if
(_omapdConfig->valueFor("debug_level").value<OmapdConfig::IfmapDebugOptions>().testFlag(OmapdConfig::ShowClientOps))
=======================================
--- /trunk/server.h Tue Oct 30 13:09:45 2012
+++ /trunk/server.h Wed Jun 26 17:02:49 2013
@@ -43,8 +43,8 @@
signals:

public slots:
- void sendPollResponseToClient(ClientHandler *client, QByteArray
response, MapRequest::RequestVersion reqVersion);
- void addClientToTimeout(QString authToken);
+ void sendPollResponseToClient(ClientHandler *client, const QByteArray&
response, MapRequest::RequestVersion reqVersion);
+ void addClientToTimeout(const QString& authToken);
void removeClientFromTimeout();
void removeClientConnectionFromTimeout(ClientHandler *client);

@@ -54,7 +54,7 @@

private:
void incomingConnection(int socketDescriptor);
- void removeTimerForClient(QString authToken);
+ void removeTimerForClient(const QString& authToken);

private:
OmapdConfig* _omapdConfig;
=======================================
--- /trunk/subscription.cpp Sun Oct 28 22:13:22 2012
+++ /trunk/subscription.cpp Wed Jun 26 17:02:49 2013
@@ -20,6 +20,8 @@
*/

#include "subscription.h"
+#include "mapsessions.h"
+#include <QRegExp>

SearchResult::ResultType
SearchResult::resultTypeForPublishType(Meta::PublishOperationType
publishType)
{
@@ -53,11 +55,82 @@
_sentFirstResult = false;
_curSize = 0;
_subscriptionError = MapRequest::ErrorNone;
+ _indexed = true;
}

Subscription::~Subscription()
{
// TODO: Do I need to clearSearchResults() to avoid leaking memory?
+
+ // (LFu) You bet:
+ clearSearchResults();
+
+ // also remove this Subscription from the index
+ if(_indexed)
+ {
+ MapSessions* ms = MapSessions::getInstance();
+ QMapIterator<Id, int> mapIt(_ids);
+ while(mapIt.hasNext())
+ {
+ ms->removeFromIndex(mapIt.next().key(), this);
+ }
+ }
+}
+
+QSet<Id> Subscription::identifiers() const
+{
+ QSet<Id> resultSet;
+
+ QMapIterator<Id, int> mapIt(_ids);
+ while(mapIt.hasNext())
+ {
+ mapIt.next();
+ resultSet << mapIt.key();
+ }
+
+ return resultSet;
+}
+
+QSet<Id> Subscription::identifiersWithout(const QMap<Id, int>& others)
const
+{
+ QSet<Id> resultSet;
+ QMapIterator<Id, int> mapIt(_ids);
+ while(mapIt.hasNext())
+ {
+ mapIt.next();
+ if(!others.contains(mapIt.key()))
+ resultSet << mapIt.key();
+ }
+
+ return resultSet;
+}
+
+QSet<Id> Subscription::subtractFrom(const QMap<Id, int>& others) const
+{
+ QSet<Id> resultSet;
+ QMapIterator<Id, int> mapIt(others);
+ while(mapIt.hasNext())
+ {
+ mapIt.next();
+ if(!_ids.contains(mapIt.key()))
+ resultSet << mapIt.key();
+ }
+
+ return resultSet;
+}
+
+unsigned int Subscription::linksContaining(const Id& id) const
+{
+ unsigned int result = 0;
+ QSetIterator<Link> it(_linkList);
+ while(it.hasNext())
+ {
+ const Link& link = it.next();
+ if(link.first == id || link.second == id)
+ result++;
+ }
+
+ return result;
}

void Subscription::clearSearchResults()
@@ -81,77 +154,98 @@
return false;
}

-QString Subscription::translateFilter(QString ifmapFilter)
-{
- //const char *fnName = "SearchGraph::translateFilter:";
+// (LFu) this code is now in MetadataFilter::setFilter()
+//QString Subscription::translateFilter(const QString& ifmapFilter,
SimplifiedFilter& simFilter, bool& canSimplifyMatching)
+//{
+// //const char *fnName = "SearchGraph::translateFilter:";

- /* non-predicate expressions joined by "or" need to be translated
- into a parenthesized expression separated by "|".
+// /* non-predicate expressions joined by "or" need to be translated
+// into a parenthesized expression separated by "|".

- Examples:
- meta:ip-mac or scada:node
- --> (meta:ip-mac | scada:node)
+// Examples:
+// meta:ip-mac or scada:node
+// --> (meta:ip-mac | scada:node)

- meta:role[@publisher-id = "myPubId" or name="myRole"] or meta:ip-mac
- --> (meta:role[@publisher-id = "myPubId" or name="myRole"] |
meta:ip-mac)
+// meta:role[@publisher-id = "myPubId" or name="myRole"] or
meta:ip-mac
+// --> (meta:role[@publisher-id = "myPubId" or name="myRole"] |
meta:ip-mac)

- standard XPath does not support predicate expressions that begin
with [; need to add *
- */
+// standard XPath does not support predicate expressions that begin
with [; need to add *
+// */

- // TODO: Do this with QRegExp
+// // (LFu) - determine if the filter looks like "ns-1:elem-1 or ... or
ns-n:elem-n"
+// // and provide simplified metadata matching in this case:
+// QRegExp rx("((\\w|-)+:(\\w|-)+)(\\s+(or|OR)\\s+((\\w|-)+:(\\w|
-)+))*");
+// if(rx.exactMatch(ifmapFilter))
+// {
+// canSimplifyMatching = true;
+// qDebug() << "~~regex matches filter: " << ifmapFilter;
+// int pos = 0;
+// QRegExp rx2("((\\w|-)+):((\\w|-)+)(\\s+(or|OR))?");
+// while ((pos = rx2.indexIn(ifmapFilter, pos)) != -1) {
+// simFilter.append(QPair<QString, QString>(rx2.cap(1),
rx2.cap(3)));
+// qDebug() << "~~\tns:" << rx2.cap(1) << " elem:" <<
rx2.cap(3);
+// pos += rx2.matchedLength();
+// }
+// }
+// else
+// qDebug() << "~~regex does not match filter: " << ifmapFilter;
+

- QString qtFilter = ifmapFilter;
- if (ifmapFilter.contains(" or ", Qt::CaseInsensitive)) {
- //qDebug() << fnName << "WARNING! filter translation is woefully
incomplete!";
- //qDebug() << fnName << "filter before translation:" <<
ifmapFilter;
- qtFilter = ifmapFilter.replace(" or "," | ");
- qtFilter.prepend("(");
- qtFilter.append(")");
- //qDebug() << fnName << "filter after translation:" << qtFilter;
- }
+// // TODO: Do this with QRegExp
+// QString qtFilter = ifmapFilter;
+// if (ifmapFilter.contains(" or ", Qt::CaseInsensitive)) {
+// //qDebug() << fnName << "WARNING! filter translation is woefully
incomplete!";
+// //qDebug() << fnName << "filter before translation:" <<
ifmapFilter;
+// qtFilter.replace(" or "," | ");
+// qtFilter.prepend("(");
+// qtFilter.append(")");
+// //qDebug() << fnName << "filter after translation:" << qtFilter;
+// }

- return qtFilter;
-}
+// return qtFilter;
+//}

-QString Subscription::intersectFilter(QString matchLinksFilter, QString
resultFilter)
-{
- /* This method creates an intersect filter for XPath
- as the logical AND combination of the match-links
- filter and the result-filter.
+// (LFu) unused:
+//QString Subscription::intersectFilter(const QString& matchLinksFilter,
const QString& resultFilter)
+//{
+// /* This method creates an intersect filter for XPath
+// as the logical AND combination of the match-links
+// filter and the result-filter.

- The passed-in filters MUST first individually be translated
- using SearchGraph::translateFilter().
- */
- QString qtFilter = "(";
- qtFilter += matchLinksFilter;
- qtFilter += " intersect ";
- qtFilter += resultFilter;
- qtFilter += ")";
+// The passed-in filters MUST first individually be translated
+// using SearchGraph::translateFilter().
+// */
+// QString qtFilter = "(";
+// qtFilter += matchLinksFilter;
+// qtFilter += " intersect ";
+// qtFilter += resultFilter;
+// qtFilter += ")";

- return qtFilter;
-}
+// return qtFilter;
+//}

-QStringList Subscription::filterPrefixes(QString filter)
-{
- // TODO: Improve RegExp to not include colons inside quotes
- // For example: vend:ike-policy[@gateway=1.2.3.4 and
meta:phase1/@identity=name:joe]
- // should not capture the `name' prefix. However, it's only a slight
performance hit
- // to capture these false prefixes, because they won't map to a
declared namespace
- // in the document, or if they do, that's ok too.
- // Here's a possibility for a RegExp that excludes colons inside
quotes, but not quite
- //QRegExp rx("([^\"{0}]\\b\\w+:)");
+// (LFu) unused:
+//QStringList Subscription::filterPrefixes(const QString& filter)
+//{
+// // TODO: Improve RegExp to not include colons inside quotes
+// // For example: vend:ike-policy[@gateway=1.2.3.4 and
meta:phase1/@identity=name:joe]
+// // should not capture the `name' prefix. However, it's only a
slight performance hit
+// // to capture these false prefixes, because they won't map to a
declared namespace
+// // in the document, or if they do, that's ok too.
+// // Here's a possibility for a RegExp that excludes colons inside
quotes, but not quite
+// //QRegExp rx("([^\"{0}]\\b\\w+:)");

- // Look for a word boundary followed by 1 or more word characters up
to a colon
- QRegExp rx("(\\b\\w+:)");
- QStringList prefixes;
+// // Look for a word boundary followed by 1 or more word characters up
to a colon
+// QRegExp rx("(\\b\\w+:)");
+// QStringList prefixes;

- int pos = 0;
- while ((pos = rx.indexIn(filter, pos)) != -1) {
- QString prefix = rx.cap(1);
- prefixes << prefix.left(prefix.length()-1);
- pos += rx.matchedLength();
- }
- //qDebug() << "prefixes:" << prefixes.join("|");
+// int pos = 0;
+// while ((pos = rx.indexIn(filter, pos)) != -1) {
+// QString prefix = rx.cap(1);
+// prefixes << prefix.left(prefix.length()-1);
+// pos += rx.matchedLength();
+// }
+// //qDebug() << "prefixes:" << prefixes.join("|");

- return prefixes;
-}
+// return prefixes;
+//}
=======================================
--- /trunk/subscription.h Sun Sep 25 13:51:15 2011
+++ /trunk/subscription.h Wed Jun 26 17:02:49 2013
@@ -55,6 +55,7 @@
MapRequest::RequestError _error;
};

+
class Subscription
{
public:
@@ -63,8 +64,22 @@

QString _name;
SearchType _search;
+ bool _indexed; // this is set to false for temporary subscriptions
used in search requests

- QSet<Id> _idList;
+ QString _authToken;
+
+ QMap<Id, int> _ids; // id --> search depth
+ QSet<Id> identifiers() const;
+ inline void addId(const Id& id, int depth) { if(!_ids.contains(id) ||
_ids[id] > depth) _ids[id] = depth; }
+ inline int getDepth(const Id& id) const { return (_ids.contains(id) ?
_ids[id] : -1); }
+ // calculates the set difference between this subscription's
identifiers and others
+ QSet<Id> identifiersWithout(const QMap<Id, int>& others) const;
+ // subtracts this subscription's identifiers form others
+ QSet<Id> subtractFrom(const QMap<Id, int>& others) const;
+ // count the number of links that contain an Id.
+ unsigned int linksContaining(const Id& id) const;
+
+ // QSet<Id> _idList;
QSet<Link> _linkList;

QList<SearchResult *> _searchResults;
@@ -77,11 +92,16 @@
// Two SearchGraphs are equal iff their names are equal
bool operator==(const Subscription &other) const;

- void clearSearchResults();
+ void clearSearchResults();

- static QString translateFilter(QString ifmapFilter);
- static QString intersectFilter(QString matchLinksFilter, QString
resultFilter);
- static QStringList filterPrefixes(QString filter);
+ // translates the filter to use with Qt xmlpattern matching
+ // (LFu) the method now determines if the filter is a simple
disjunction of qual. metadata element names
+ // and if so the method will set canSimplifyMatching to true and fills
simFilter with the list of
+ // (namespace prefix/element name) pairs that the filter contains. In
this case the method returns
+ // the empty string.
+// static QString translateFilter(const QString& ifmapFilter,
SimplifiedFilter& simFilter, bool& canSimplifyMatching);
+// static QString intersectFilter(const QString& matchLinksFilter,
const QString& resultFilter);
+// static QStringList filterPrefixes(const QString& filter);
};

#endif // SUBSCRIPTION_H
Reply all
Reply to author
Forward
0 new messages