Update of /cvsroot/aolserver/knutil/include/knutil In directory sc8-pr-cvs11.sourceforge.net:/tmp/cvs-serv6393/include/knutil Added Files: atomicint.h counter.h kncircularmapping.h knconsistenthash.h kncrashhandler.h kncrypt.h knerror.h knexportlibraryknutil.h knhash.h knlog.h knmarkuputil.h knmemory.h knmutex.h knnetwork.h knnewdelete.h knpattern.h knperfstatistics.h knregex.h knrwlock.h knrwlogginglock.h knset.h knsett.h knsleep.h knsmartref.h knstring.h knstringtokenizer.h knstrops.h knsysutility.h kntclargs.h kntclerrors.h kntclfile.h kntclinterp.h kntemplateuri.h kntime.h kntypes.h knurl.h mtrand.h randomnumber.h shahash.h simplecache.h simpleheap.h simpleiterator.h simplelist.h simplemap.h simplenull.h simplequeue.h simpleset.h simplesynccache.h simplesyncmap.h simplesyncvector.h simpletraits.h simplevector.h uuidgenerator.h Log Message: Added this library to the AOLServer.com repository. It contains a number of C/C++ utilities, some of which integrate into AOLServer, and many of which standalone. A portion of the library is required for the knregistration module, which will be checked in next. I believe this compiles fine in "native" AOLServer, but it has not been tested recently. --- NEW FILE: atomicint.h --- #ifndef ATOMICINT_H #define ATOMICINT_H /** * Copyright (c) 2001 KnowNow, Inc. All rights reserved. * * @KNOWNOW_LICENSE_START@ * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * 3. The name "KnowNow" is a trademark of KnowNow, Inc. and may not * be used to endorse or promote any product without prior written * permission from KnowNow, Inc. * * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. * IN NO EVENT SHALL KNOWNOW, INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * @KNOWNOW_LICENSE_END@ **/ /* * Object supporting atomic integer operations. */ #include "knutil/knexportlibraryknutil.h" #include "knutil/kntypes.h" class EXPORT_LIBRARY_KNUTIL AtomicInt { public: /* * Constructors/destructor. */ inline AtomicInt(int cnt=0) : m_cnt(cnt){}; inline AtomicInt(const AtomicInt &atom):m_cnt(atom.m_cnt){}; inline ~AtomicInt(){}; /* * Set the object to an arbitrary value. */ inline AtomicInt &operator=(const AtomicInt &atom) {m_cnt = atom.m_cnt;return *this;}; inline AtomicInt &operator=(int cnt) {m_cnt = cnt;return *this;} /* * Increment/decrement the object by an arbitrary value. */ int operator+=(int cnt); int operator-=(int cnt); /* * Prefix and postfix increment. */ int operator++(); int operator++(int); /* * Prefix and postfix decrement. */ int operator--(); int operator--(int); /* * Object returned as an integer. */ inline operator int() const { return m_cnt; } /* * Decrement the object, and return true if the result is 0. */ bool decrementAndTest(); /* * Increment the object, without returning the result. */ void increment(); private: int m_cnt; }; #endif /* ATOMICINT_H */ --- NEW FILE: counter.h --- #ifndef COUNTER_H /** * (c) Copyright 2008 KnowNow, Inc., Sunnyvale CA * * @KNOWNOW_LICENSE_START@ * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * 3. The name "KnowNow" is a trademark of KnowNow, Inc. and may not * be used to endorse or promote any product without prior written * permission from KnowNow, Inc. * * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. * IN NO EVENT SHALL KNOWNOW, INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * @KNOWNOW_LICENSE_END@ **/ #define COUNTER_H #include "knutil/knexportlibraryknutil.h" #include "knutil/atomicint.h" #include "knutil/knmutex.h" class EXPORT_LIBRARY_KNUTIL Counter { public: Counter(int c = 1); ~Counter(); AtomicInt count; }; #endif /* COUNTER_H */ --- NEW FILE: kncircularmapping.h --- #ifndef KN_CIRCULAR_MAPPING_H #define KN_CIRCULAR_MAPPING_H /** * Copyright (c) 2001 KnowNow, Inc. All rights reserved. * * @KNOWNOW_LICENSE_START@ * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * 3. The name "KnowNow" is a trademark of KnowNow, Inc. and may not * be used to endorse or promote any product without prior written * permission from KnowNow, Inc. * * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. * IN NO EVENT SHALL KNOWNOW, INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * @KNOWNOW_LICENSE_END@ **/ #include <limits.h> #include <map> #include <string> #include <vector> #include "knutil/knexportlibraryknutil.h" #include "knutil/knset.h" class Bucket; class ReplicaPoint; class EXPORT_LIBRARY_KNUTIL KnCircularMapping { public: KnCircularMapping(); virtual ~KnCircularMapping(); typedef unsigned int PointT; // Add a bucket bool addBucket(const char* bucketName, std::vector<PointT>& points, double weight); bool addBucketsFromSet(const KnSet& bucketSet); // Remove a bucket by name bool removeBucket(const char* bucketName); // Remove all buckets void removeAllBuckets(); // Compute the bucket where the point should go // and return the bucket's name std::string assignPointToBucket(PointT point); int bucketCount(); double getWeight(const std::string& bucketName); double getTotalWeight(); bool existsBucket(const std::string& bucketName); private: typedef std::map<std::string, Bucket*> BucketMap; typedef BucketMap::iterator BucketMapIterator; typedef std::map<PointT, ReplicaPoint*> ReplicaMap; typedef ReplicaMap::iterator ReplicaMapIterator; typedef std::pair<ReplicaMapIterator, ReplicaMapIterator> ReplicaMapRange; ReplicaPoint* findOrAddReplicaPoint(PointT point); ReplicaPoint* findReplicaPoint(PointT point); bool removeReplicaPoint(PointT point, Bucket* bucket); Bucket* findBucketForPoint(PointT point); BucketMap m_buckets; ReplicaMap m_replicaMap; double m_totalWeight; }; #endif --- NEW FILE: knconsistenthash.h --- #ifndef KN_CONSISTENT_HASH_H #define KN_CONSISTENT_HASH_H /** * Copyright (c) 2001 KnowNow, Inc. All rights reserved. * * @KNOWNOW_LICENSE_START@ * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * 3. The name "KnowNow" is a trademark of KnowNow, Inc. and may not * be used to endorse or promote any product without prior written * permission from KnowNow, Inc. * * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. * IN NO EVENT SHALL KNOWNOW, INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * @KNOWNOW_LICENSE_END@ **/ #include <limits.h> #include <string> #include <map> #include "knutil/knexportlibraryknutil.h" #include "knutil/knset.h" #include "knutil/knrwlock.h" #include "knutil/kncircularmapping.h" #define DEFAULT_REPLICAS_PER_BUCKET 200 class EXPORT_LIBRARY_KNUTIL KnConsistentHash { public: KnConsistentHash(int replicasPerBucket = DEFAULT_REPLICAS_PER_BUCKET, KnCircularMapping::PointT pointInterval = UINT_MAX); virtual ~KnConsistentHash(); typedef unsigned int IDHash; // Compute the hash for a bucket virtual IDHash computeHash(const char* identifier); // Add a bucket given a hash computed from some unique data virtual bool addBucket(const char* bucketName, IDHash bucketHash, double weight); // or by the computing hash from bucket name bool addBucket(const char* bucketName, double weight); // Remove a bucket by name bool removeBucket(const char* bucketName); // Remove all buckets void removeAllBuckets(); // Add buckets from a set where the keys are bucket names and the values are weights bool addBucketsFromSet(const KnSet& bucketSet); bool setBucketsFromSet(const KnSet& bucketSet); int bucketCount(); // Given a resource identifier find the point on the circle it belongs to virtual KnCircularMapping::PointT computePointForResource(const char* identifier); // Compute the bucket where the point should go and return the bucket's name std::string assignPointToBucket(KnCircularMapping::PointT point); // Calculate the point and then assign the point to a bucket for a resource std::string assignResourceToBucket(const char* identifier); double getTotalWeight(); private: bool addBucketUnsafe(const char* bucketName, IDHash bucketHash, double weight); bool addBucketsFromSetUnsafe(const KnSet& bucketSet); KnCircularMapping m_mapping; KnRWLock m_bucketLock; int m_replicasPerBucket; KnCircularMapping::PointT m_pointInterval; }; #endif --- NEW FILE: kncrashhandler.h --- #ifndef KNCRASHHANDLER_H #define KNCRASHHANDLER_H /** * Copyright (c) 2001 KnowNow, Inc. All rights reserved. * * @KNOWNOW_LICENSE_START@ * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * 3. The name "KnowNow" is a trademark of KnowNow, Inc. and may not * be used to endorse or promote any product without prior written * permission from KnowNow, Inc. * * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. * IN NO EVENT SHALL KNOWNOW, INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * @KNOWNOW_LICENSE_END@ **/ #include "knutil/knexportlibraryknutil.h" /** * Register the KnowNow standard crash handler for this module * (no-op under Unix or Linux right now). Returns false if could * not register. Logs any error itself. */ extern EXPORT_LIBRARY_KNUTIL bool KnSetCrashHandler() ; /** * Set the crash handler's dump location and severity */ extern EXPORT_LIBRARY_KNUTIL bool KnSetCrashInfo(const char* location, const char* level) ; #endif /* KNCRASHHANDLER_H */ --- NEW FILE: kncrypt.h --- #ifndef KNCRYPT_H /** * (c) Copyright 2008 KnowNow, Inc., Sunnyvale CA * * @KNOWNOW_LICENSE_START@ * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * 3. The name "KnowNow" is a trademark of KnowNow, Inc. and may not * be used to endorse or promote any product without prior written * permission from KnowNow, Inc. * * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. * IN NO EVENT SHALL KNOWNOW, INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * @KNOWNOW_LICENSE_END@ **/ #define KNCRYPT_H #include "knutil/knexportlibraryknutil.h" #include "knutil/knstring.h" /** * (c) Copyright 2008 KnowNow, Inc., Sunnyvale CA * * Encrypt the specified key, perturbed by salt, into buf. */ EXPORT_LIBRARY_KNUTIL KnError KnCrypt(KnString &buf, const KnString &key, const KnString &salt); #endif /* KNCRYPT_H */ --- NEW FILE: knerror.h --- #ifndef KNERROR_H #define KNERROR_H /** * Copyright (c) 2001 KnowNow, Inc. All rights reserved. * * @KNOWNOW_LICENSE_START@ * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * 3. The name "KnowNow" is a trademark of KnowNow, Inc. and may not * be used to endorse or promote any product without prior written * permission from KnowNow, Inc. * * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. * IN NO EVENT SHALL KNOWNOW, INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * @KNOWNOW_LICENSE_END@ **/ #include "knutil/knexportlibraryknutil.h" #include "knutil/kntypes.h" /** * Error state, and preferred return type. */ /** * In 3.1.9, experimenting with moving to an Apache-style set of * codes. All codes come from the HTTP error space, with 6xx codes below * 655 reserved for KnowNow errors. * * We shift them left 8 bits, then add in any subcodes we care about. * This assumes that enums are represented as at least 16 bit unsigned ints. * To get an HTTP error code, shift right 8. To get a nice string, look * them up as-is. * * This check-in requires recompiling the Modules to get the new constants * * Use KnError_Is(constant, code) to do comparisons; we'll figure out how * to get it inlined, yet available to C modules, yet. * * I.e., if you just care if it's found or not, use * KnError_Is(KnErrorNotFound, status) * so you don't have to know the encodings. */ enum KnError { KnErrorSuccess = (200 << 8), ///< Operation succeeded KnErrorUnauthorized = (401 << 8), ///< Operation requires credentials (401) KnErrorForbidden = (403 << 8), ///< Credentials are not authorized (403) KnErrorNotFound = (404 << 8), ///< Something (page) not found KnErrorNotFound_Event = (404 << 8) + 1, KnErrorNotFound_Route = (404 << 8) + 2, KnErrorNotFound_Topic = (404 << 8) + 3, KnErrorNotFound_Journal = (404 << 8) + 4, KnErrorNotFound_Parent = (404 << 8) + 5, KnErrorNotFound_SubTopic = (404 << 8) + 6, KnErrorNotFound_Filter = (404 << 8) + 7, KnErrorNotFound_User = (404 << 8) + 10, KnErrorNotFound_Group = (404 << 8) + 11, KnErrorFailure = (500 << 8) ///< Operation failed (500) }; extern EXPORT_LIBRARY_KNUTIL const int KnError_AsHTTP( const KnError code ) ; #ifdef __cplusplus inline int KnError_Is(const KnError constant, const KnError code ) { return (static_cast<unsigned int>(constant) & static_cast<unsigned int>(code)) == static_cast<unsigned int>(constant); } #else #define KnError_Is(c,s) (c == (c & s)) #endif #endif /* KNERROR_H */ --- NEW FILE: knexportlibraryknutil.h --- /* /** * (c) Copyright 2008 KnowNow, Inc., Sunnyvale CA * * @KNOWNOW_LICENSE_START@ * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * 3. The name "KnowNow" is a trademark of KnowNow, Inc. and may not * be used to endorse or promote any product without prior written * permission from KnowNow, Inc. * * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. * IN NO EVENT SHALL KNOWNOW, INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * @KNOWNOW_LICENSE_END@ **/ * Defines export/import declarations for windows interfaces for this dll. * It is important to declare this as export when compiling modules in the dll * and import for modules not in the dll. */ #ifndef KNEXPORTLIBRARYKNUTIL_H #define KNEXPORTLIBRARYKNUTIL_H #ifdef WIN32 #ifdef EXPORT_LIBRARY_KNUTIL_MODULE #define EXPORT_LIBRARY_KNUTIL __declspec(dllexport) #else #define EXPORT_LIBRARY_KNUTIL __declspec(dllimport) #endif #else #define EXPORT_LIBRARY_KNUTIL #endif #endif /* KNEXPORTLIBRARYKNUTIL_H */ --- NEW FILE: knhash.h --- #ifndef KNHASH_H #define KNHASH_H /** * Copyright (c) 2001 KnowNow, Inc. All rights reserved. * * @KNOWNOW_LICENSE_START@ * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * 3. The name "KnowNow" is a trademark of KnowNow, Inc. and may not * be used to endorse or promote any product without prior written * permission from KnowNow, Inc. * * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. * IN NO EVENT SHALL KNOWNOW, INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * @KNOWNOW_LICENSE_END@ **/ #include "knutil/knexportlibraryknutil.h" #include "knutil/kntypes.h" #ifdef __cplusplus extern "C" { #endif /* * General purpose hashing routine. The seed parameter can be * any value, such as the previous hash result. Please see * http://burtleburtle.net/bob/hash/evahash.html for theory. */ extern EXPORT_LIBRARY_KNUTIL uint32_t hash32(const void *buf, uint32_t len, uint32_t seed); extern EXPORT_LIBRARY_KNUTIL uint64_t hash64(const void *buf, uint64_t len, uint64_t seed); #ifdef __cplusplus } // extern "C" #endif #endif /* KNHASH_H */ --- NEW FILE: knlog.h --- #ifndef KNLOG_H /** * (c) Copyright 2008 KnowNow, Inc., Sunnyvale CA * * @KNOWNOW_LICENSE_START@ * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * 3. The name "KnowNow" is a trademark of KnowNow, Inc. and may not * be used to endorse or promote any product without prior written * permission from KnowNow, Inc. * * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. * IN NO EVENT SHALL KNOWNOW, INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * @KNOWNOW_LICENSE_END@ **/ #define KNLOG_H #include "knutil/knexportlibraryknutil.h" #include "knutil/knerror.h" #include "knutil/knstring.h" /***************************************************************/ * (c) Copyright 2008 KnowNow, Inc., Sunnyvale CA * /**@defgroup loggingAPI Logging API * (c) Copyright 2008 KnowNow, Inc., Sunnyvale CA * * * Log to the server.log file. * @{ ****************************************************************/ /** * (c) Copyright 2008 KnowNow, Inc., Sunnyvale CA * * Logging levels. See KnLog for details on their use. */ enum KnLogSeverity { KnLogNotice, ///< Something somebody might care about KnLogWarning, ///< Something somebody should do something about KnLogError, ///< Something somebody should call KnowNow about KnLogFatal, ///< Something that will cause a non-recoverable crash KnLogBug, ///< Something that "asserts" a fault in the code KnLogDebug, ///< Something only printed when Log_Debug is enabled KnLogDev ///< Something conditional on a specific debug flag }; /** * (c) Copyright 2008 KnowNow, Inc., Sunnyvale CA * * Log a message to the router. */ extern EXPORT_LIBRARY_KNUTIL KnError KnLog(KnLogSeverity severity, const KnString &msg); /** * (c) Copyright 2008 KnowNow, Inc., Sunnyvale CA * * Log a printf-style message to the router. */ extern EXPORT_LIBRARY_KNUTIL KnError KnLog(KnLogSeverity severity, const char *fmt, ...) __attribute__ ((format (printf, 2, 3))); #endif --- NEW FILE: knmarkuputil.h --- ////////////////////////////////////////////////////// /** * (c) Copyright 2008 KnowNow, Inc., Sunnyvale CA * * @KNOWNOW_LICENSE_START@ * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * 3. The name "KnowNow" is a trademark of KnowNow, Inc. and may not * be used to endorse or promote any product without prior written * permission from KnowNow, Inc. * * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. * IN NO EVENT SHALL KNOWNOW, INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * @KNOWNOW_LICENSE_END@ **/ // knmarkuputil.h // // (c)2002-2006, KnowNow, Inc. All Rights Reserved. #ifndef KNMARKUPUTIL_H #define KNMARKUPUTIL_H #include "knutil/knexportlibraryknutil.h" #include "knutil/knstring.h" #include "knutil/simplemap.h" typedef SimpleMap<char*, char*> EntityMap; class EXPORT_LIBRARY_KNUTIL KnMarkupUtil { public: KnMarkupUtil(); ~KnMarkupUtil(); /** * (c) Copyright 2008 KnowNow, Inc., Sunnyvale CA * * This expands whitespaces HTML tags from the source string and strip all other tags */ bool expandTagsAndStrip(const KnString& source, KnString& transformed); /** * (c) Copyright 2008 KnowNow, Inc., Sunnyvale CA * * This expands HTML entities from the source string */ bool expandHtmlEntities(const KnString& source, KnString& transformed); /** * (c) Copyright 2008 KnowNow, Inc., Sunnyvale CA * * This removes XML tags from the source string */ void stripTags(const KnString& source, KnString& transformed); /** * (c) Copyright 2008 KnowNow, Inc., Sunnyvale CA * * This removes all tags and HTML expands entities from the source string */ bool stripTagsAndExpandEntities(const KnString& source, KnString& transformed); /** * (c) Copyright 2008 KnowNow, Inc., Sunnyvale CA * * This expands HTML whitespaces tags, removes all other tags and expands HTML entities from the source string */ bool expandTagsAndEntities(const KnString& source, KnString& transformed); // to enable this you will have to add some headers to .cpp and xalan\xerces libraries // bool renderXmlHtml(const KnString* source, KnString* transformed); private: void buildHtlmEntity(); void buildHtlmTags(); EntityMap entityMap; EntityMap tagMap; }; #endif /* KNMARKUPUTIL_H */ --- NEW FILE: knmemory.h --- #ifndef __KNMEMORY_H__ /** * @KNOWNOW_LICENSE_START@ * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * 3. The name "KnowNow" is a trademark of KnowNow, Inc. and may not * be used to endorse or promote any product without prior written * permission from KnowNow, Inc. * * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. * IN NO EVENT SHALL KNOWNOW, INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * @KNOWNOW_LICENSE_END@ **/ #define __KNMEMORY_H__ /* Copyright (c) 2003 KnowNow, Inc. All rights reserved */ #include "knutil/knexportlibraryknutil.h" #include "knutil/kntypes.h" #include "knutil/knlog.h" /** * The KnMemory module retains memory allocation statistics for C++ code * linked into the KnowNow server. * * Used as a very elementary "leak detector": we count on new and * decrement on delete, so if everything is wrapped in objects that * know how to unallocate themselves, we should get zero as we * exit the KnowNow modules. * * Behind the scenes, this module integrates C++ memory allocation * with the ns_malloc() / ns_free() memory allocation of AOLServer * by implementing operator new() and operator delete(). */ class EXPORT_LIBRARY_KNUTIL KnMemory { public: static void increment(); static void decrement(); /** Get the amount of available virtual memory for * this process (volatile). Expressed in bytes */ static size_t getMemoryAvail() ; /** Get the balance of news against deletes * May always return 0 in high-performance release configurations */ static size_t getBalance(); /** Log memory statistics * * If in high-performance release configuration, will print * a message saying that allocations were not tracked. */ static void logStatistics( KnLogSeverity severity = KnLogNotice //- What severity to log with ); private: // Not implemented; makes this a global routine container, since // the class itself can not be instantiated. KnMemory(); KnMemory(const KnMemory &); ~KnMemory(); KnMemory &operator=(const KnMemory &); }; #endif // __KNMEMORY_H__ --- NEW FILE: knmutex.h --- #ifndef KNMUTEX_H #define KNMUTEX_H /** * Copyright (c) 2001 KnowNow, Inc. All rights reserved. * * @KNOWNOW_LICENSE_START@ * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * 3. The name "KnowNow" is a trademark of KnowNow, Inc. and may not * be used to endorse or promote any product without prior written * permission from KnowNow, Inc. * * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. * IN NO EVENT SHALL KNOWNOW, INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * @KNOWNOW_LICENSE_END@ **/ #include "knutil/knexportlibraryknutil.h" #include "knutil/kntypes.h" /* * Mutual exclusion abstraction. */ class EXPORT_LIBRARY_KNUTIL KnMutex { public: KnMutex(); ~KnMutex(); /* * Controls locking/unlocking scope through object lifetime. * If blocking is false, the object will not attempt to wait * for an owned lock. */ class EXPORT_LIBRARY_KNUTIL KnLock { public: KnLock(KnMutex &mutex, bool blocking=true); ~KnLock(); bool owner() const; private: // Not implemented KnLock(); KnLock(const KnLock &); KnLock &operator=(const KnLock &); KnMutex &m_mutex; bool m_owner; }; friend class KnMutex::KnLock; private: // Not implemented KnMutex(const KnMutex &); KnMutex &operator=(const KnMutex &); bool lock(); bool trylock(); bool unlock(); void *m_impl; }; #endif /* KNMUTEX_H */ --- NEW FILE: knnetwork.h --- #ifndef KNNETWORK_H #define KNNETWORK_H /** * Copyright (c) 2001 KnowNow, Inc. All rights reserved. * * @KNOWNOW_LICENSE_START@ * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * 3. The name "KnowNow" is a trademark of KnowNow, Inc. and may not * be used to endorse or promote any product without prior written * permission from KnowNow, Inc. * * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. * IN NO EVENT SHALL KNOWNOW, INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * @KNOWNOW_LICENSE_END@ **/ #include <vector> #include <stack> #include <algorithm> #include "knutil/knexportlibraryknutil.h" #include "knutil/knsmartref.h" #include "knutil/knstring.h" #include "knutil/simplemap.h" #include "knutil/knerror.h" #include "knutil/knlog.h" #include "knutil/knurl.h" #include "knutil/knstrops.h" #include "knutil/kntclinterp.h" #include "knutil/knstringtokenizer.h" /* Maintains a registered sets of URL urlspaces that can be used to * normalize & manage URLs, DNS names, or addresses, comparing them for * membership in particular sets. Sets are arranged in a forest for * comparison, so, e.g., we can have: * * corpnet * + extranet * + liveserver federation * + cluster * + node * <name> * <name>... * * We do our own declarations of these so an individual node that * belongs to more than one domain can still be recognized as having * its own topicspace. We have to do this because our API supports * operations over fully-qualified URIs -- and those URIs might be * for any reachable name for the hosts in the cluster. */ /* These are the reserved network names. We also use the word * "local" to mean "cluster", but this is somewhat more precise. */ class EXPORT_LIBRARY_KNUTIL KnNetworkClassName { public: static const KnString localhost ; static const KnString node ; static const KnString cluster ; static const KnString federation ; }; class EXPORT_LIBRARY_KNUTIL KnUrlSpaceName { public: static const KnString topic ; }; /* Violation of our normal lexical convention: * I'm directly marking each method with whether it's public * etc., because I think that makes it easier to maintain the code. * Follows Wilson (Imperfect C++) * * It's really irritating; in the end, I just hid the singleton * behind static methods, so this could have just as easily just * been a namespace, instead of a class. Did that because the * easier-to-write edition (with lots of inlines & templates) * literally blew up the VS7 compiler. OTOH, now we can * more gradually expose the internal classes if we need them. */ class EXPORT_LIBRARY_KNUTIL KnNetwork { // --------------------- // Process initialization // --------------------- public: static KnError configure(const KnSet& configSet, const KnString& urlSpace = KnStringConstants::slash_kn) ; // --------------------- // Network class queries // --------------------- public: static bool isNode( const std::string& address ) { KnString addr(address.c_str(),address.length()); return isNode(addr); } public: static bool isNode( const KnString& address ) { KnUrl url(address); return isNode(url); } public: static bool isNode( const KnUrl& url ) { return isMember(url,KnNetworkClassName::node); } public: static bool isLocal( const std::string& address ) { KnString addr(address.c_str(),address.length()); return isLocal(addr); } public: static bool isLocal( const KnString& address ) { KnUrl url(address); return isLocal(url); } public: static bool isLocal( const KnUrl& url ) ; public: static bool isMember( const KnUrl& url, const KnString& network ) ; public: static KnError getHttpUri(KnString& root, const KnString& netName); public: static KnError getHttpsUri(KnString& root, const KnString& netName) ; public: static Tcl_Obj* listNetworks(Tcl_Interp *interp); public: /* Should take string for matching with */ static Tcl_Obj* listHosts(Tcl_Interp *interp); // ------------------------- // Network class management // ------------------------- public: static KnError addNetwork(const KnString& newClass, const KnString& inClass, bool hasURI) ; public: static KnError addUrlToClass(const KnString& url, const KnString& netName) ; /* --------------------- * urlspace query * -------------------- */ public: static KnError inSpace( bool& yesno, const std::string& url, const KnString& space = KnUrlSpaceName::topic); /* --------------------- * urlspace management * -------------------- */ public: static Tcl_Obj* listUrlSpaces(Tcl_Interp *interp) ; public: // urlRoot must be relative, single initial /. Should *not* end // in '/'. Considered adding KnUrlSpace class; seemed to heavy. // Currently think there's no need to have lookup; urlspace name should == urlroot. // but coded this way for another level of indirection. Hmm. static KnError addUrlSpace(const KnString& urlSpace, const KnString& urlRoot) ; public: static const KnString* getUrlRoot(KnString& urlSpace) ; public: // Add just the prefix to the set of URL mappings; don't add the host. // This is used for "mappings", where // a reverse proxy has said that it is mapped to a specific prefix, but // we don't know that the host part is actually reachable, nor that // it is shared with any of the rest of our URLspace. E.g. // // proxy @ http://www.example.com maps // /ess to locally name http://xyz.ex.com/kness/live // /topics to local name http://xyz.ex.com/kn // We want several things: // is_topic http://xyz.ex.com/topics/foobar => true // is_local http://xyz.ex.com/topics/foobar => true // is_local http://xyz.ex.com/ess/foobar => true // is_local http://xyz.ex.com/something/else => false // normalize_topic http://xyz.ex.com/topics/foobar => /kn/foobar // relative_path http://xyz.ex.com/ess/foobar => /kness/live/foobar // relative_path http://xyz.ex.com/something/else => // http://xyz.ex.com/something/else static KnError addMapping(const KnString& urlSpace, const KnString& prefix) ; // ------------------------------ // Combined operations. // // Use these as the normal ways to record // things we learn about how we're accessed // ------------------------------ public: // Topicspace should call this with urlspace == its urlroot. Perms and other // AOLServer filters (as opposed to procs) usually should leave it null, since they // don't necessarily know the root of the pattern they're manageing. // should keep it 0, since it doesn't know what U static KnError KnNetwork::addHostAlias(Ns_Conn *conn, const KnString *urlspace = 0) ; public: // Adds the location as a mapping for the urlspace name "urlspace", // Also adds the host & port component of the URL to the network class class. // Used as the replacement for typical // KnProperties::addHostAlias(KnString prefix); it's a convenience entry point in // the case where you know scheme & host part of the URL address this server. // // It's convenient, but not always correct; in some mapping scenarios, it's // perfectly possible, for example, for us to want: // is_local http://xyz.ex.com/kn/foobar => true // is_local http://xyz.ex.com/some/thing => false // We do this by only registering the mapping. See "addMapping" static KnError addUrl( const KnString& urlspace, const KnString& prefix, const KnString& network = KnNetworkClassName::cluster ) ; public: // This is like addUrl, but it takes an url with no path, and extends it with the // urlroot for the given urlspace before registering it as a mapping. Useful // during configuration, where we know the addresses and want to factor the basic // urlroot across all those addresses. Adds to the default network if none specified. static KnError addHostWithPrefix( const KnString& urlSpace, const KnString& url, const KnString& network = KnStringConstants::empty) ; /* ----------------------------------------*/ /* URL normalization & relativization */ /* ----------------------------------------*/ // Creates *canonicalized*, *normalized*, // path-absolute URI IFF the given URL is known // to be cluster-local & in some prefix associated // with the urlspace. As part of canonicalizing, // any matching prefix is _replaced_ with the first prefix // registered for that urlspace. If no matching // prefix is given, the canonical prefix is prepended. // // Note that KnProperties::formatLocation contains // additional logic associated with any event replicated // by the clustering code. I hope that can be deleted // now (but see GS' comment regarding TD3095). // // Could certainly be made faster by removing some // KnString uses and using std::string. But I'm out of time. public: static KnError formatTopicLocation( KnString& location, const KnString& urlSpace = KnUrlSpaceName::topic ); public: static KnError formatNonNetworkRelativeRef(KnString& location,size_t inputPfxLen) ; // Accepts a string that should be a "path" (and tail and query & fragment) part // with no "network" component (recall that there are "network relative refs" which // look like '//user:info@host:port/pathpart'; those won't work here). // // Normalizes just the path & tail part, but treats '?' & '#' as legal // characters inside components, rather than the termination of the path part. // This is required for topicnames, since they've always worked that way // and we have lots of existing topics with un-escaped '?' in their names. // // Treats the first inputPfxLen chars as "can't touch these". public: static KnError formatTopicRelativeRef(KnString& location,size_t inputPfxLen); }; #endif /* KNNETWORK_H */ --- NEW FILE: knnewdelete.h --- #ifndef KNNEWDELETE_H /** * (c) Copyright 2008 KnowNow, Inc., Sunnyvale CA * * @KNOWNOW_LICENSE_START@ * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * 3. The name "KnowNow" is a trademark of KnowNow, Inc. and may not * be used to endorse or promote any product without prior written * permission from KnowNow, Inc. * * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. * IN NO EVENT SHALL KNOWNOW, INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * @KNOWNOW_LICENSE_END@ **/ #define KNNEWDELETE_H #ifndef KNMODULE /* You should define your module name before including this file. * Right now, it's unused, but we may really want it in future. */ static unsigned int foo ( unsigned int bar ) { return 0 ; } ; // Generate a warning #endif /** * (c) Copyright 2008 KnowNow, Inc., Sunnyvale CA * * This is some wierd code. * * Operator new & operator delete have single linkage scope. * * That means they only get as big as one DLL or one .so; you can't * ensure that the same one is used in all dynamic libraries easily. * See Matthew Wilson, Imperfect C++, p. 130 * * So to get a global counter, we need to have (a) global counters * (defined in knmemory.cpp), but local routines. * * This is now a pretty fair amount of CPU overhead per allocation. * (though still constant time). * We may need to optimize things a bit better in future. * * To do that, we #include this file once in all our modules. * Yuck!!! * * -- ReC 05/08/03, updated 7 Apr 06 */ #include "knutil/knexportlibraryknutil.h" #include "knutil/kntypes.h" #include "knutil/atomicint.h" #include "knutil/knmemory.h" /** * (c) Copyright 2008 KnowNow, Inc., Sunnyvale CA * * C++ wrapper for ns_malloc * * To get the benefits of using the ns_malloc routine (integrated error * messages, clearing cache memory when approaching fullness), we override * the C++ memory allocation system to use ns_malloc. Of course, ns_malloc * eventually uses malloc underneath it, which gives us the opportunity to * use ATS, Purify, or other allocation systems. * * We need to link this into all our C++ DLLs. We also need to examine our * topic & event API; if we support new & deletion of refcounted structures * in customer-written filters, we'll want to encourage them to use these * wrappers. */ void * operator new ( size_t size ) { #if 0 if (0 == nAllocs) KnLog(KnLogNotice,"Registering KnowNow ns_malloc wrapper"); #endif KnMemory::increment() ; return ns_malloc(size) ; } void * operator new[] (size_t size) { KnMemory::increment() ; return ns_malloc(size); } /** * (c) Copyright 2008 KnowNow, Inc., Sunnyvale CA * * C++ wrapper for ns_free * * To get the benefits of using the ns_malloc routine (integrated error * messages, clearing cache memory when approaching fullness), we override * the C++ memory allocation system to use ns_malloc. Of course, ns_malloc * eventually uses malloc underneath it, which gives us the opportunity to * use ATS, Purify, or other allocation systems. */ void operator delete( void *pFreeThis ) { ns_free(pFreeThis); KnMemory::decrement() ; } void operator delete[]( void *pFreeThis ) { ns_free(pFreeThis); KnMemory::decrement() ; } #endif /* KNNEWDELETE_H */ --- NEW FILE: knpattern.h --- #ifndef KN_PATTERN_H /** * (c) Copyright 2008 KnowNow, Inc., Sunnyvale CA * * @KNOWNOW_LICENSE_START@ * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * 3. The name "KnowNow" is a trademark of KnowNow, Inc. and may not * be used to endorse or promote any product without prior written * permission from KnowNow, Inc. * * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. * IN NO EVENT SHALL KNOWNOW, INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * @KNOWNOW_LICENSE_END@ **/ #define KN_PATTERN_H #include "knutil/knexportlibraryknutil.h" #include "knutil/knlog.h" #include "knutil/knregex.h" #include "knutil/knrwlock.h" #include "knutil/knset.h" #include "knutil/knsmartref.h" #include "knutil/knstring.h" #include <vector> #include <list> #include <map> class EXPORT_LIBRARY_KNUTIL KnMatcher { public: KnMatcher(const char* string); ~KnMatcher(); Tcl_Obj* getTclObj(); private: Tcl_Obj* m_obj; }; class EXPORT_LIBRARY_KNUTIL KnPattern { public: KnPattern(); KnPattern( const KnString& name ); virtual ~KnPattern() {}; bool isValidRegex() const; virtual bool match(const char* string) const; virtual bool match(KnMatcher& matchObj) const; virtual int getSubCount() const; virtual bool matchSubs(const char *str, KnSet& result); bool setRegexPattern(const char* pattern); bool setRegexPattern(const KnString& pattern); const KnString& getName() const; const KnString& getRegexPattern() const; const KnRegEx& getRegexMatcher() const; protected: bool lessSpecificThan(const KnPattern& rhs) const; KnRegEx m_regex; KnString m_name; KnString m_regexPattern; }; template<class Pattern, class Info> class IKnPatterns { public: IKnPatterns() {} virtual ~IKnPatterns() {} virtual bool findBestMatch( const char* string, KnSmartRef<Pattern>& pattern, KnSmartRef<Info>& info) const = 0; virtual bool findAllMatches( const char* string, std::vector<std::pair<KnSmartRef<Pattern>, KnSmartRef<Info> > >& matches) const = 0; virtual bool findBestMatchSubs( const char* string, KnSet& subs, KnSmartRef<Pattern>& pattern, KnSmartRef<Info>& info) const = 0; virtual bool findAllMatchesSubs( const char* string, std::vector<std::pair< KnSet*, KnSmartRef<Info> > >& matches) const = 0; virtual bool findByName( const KnString& name, KnSmartRef<Pattern>& pattern, KnSmartRef<Info>& info) const = 0; virtual bool removeByName( const KnString& name) = 0; virtual void dump(KnLogSeverity severity = KnLogDev) = 0; virtual void put(Pattern* pattern, Info* info) = 0; virtual bool isEmpty() = 0; }; // MapValue must be a subclass of IKnPatterns template<class MapKey, class MapValue, class Pattern, class Info> class KnPatternFinder { public: class ScopedWriteable { public: ScopedWriteable(KnPatternFinder<MapKey,MapValue,Pattern,Info>& pf) : m_writeLock(pf.m_rwlock) { }; private: KnRWLock::KnWriteLock m_writeLock; }; friend class KnPatternFinder<MapKey,MapValue,Pattern,Info>::ScopedWriteable; class ScopedReadable { public: ScopedReadable(KnPatternFinder<MapKey,MapValue,Pattern,Info>& pf) : m_readLock(pf.m_rwlock) { }; private: KnRWLock::KnReadLock m_readLock; }; friend class KnPatternFinder<MapKey,MapValue,Pattern,Info>::ScopedWriteable; MapValue* get( const MapKey& mk) const { MapTypeIteratorConst it = m_map.find(mk); if(it != m_map.end()) return it->second; return NULL; } bool findBestMatch( const MapKey& mk, const char* string, KnSmartRef<Pattern>& pattern, KnSmartRef<Info>& info) const { MapValue* mv = get(mk); if(!mv) return false; return mv->findBestMatch(string,pattern,info); } bool findAllMatches( const MapKey& mk, const char* string, std::vector<std::pair<KnSmartRef<Pattern>, KnSmartRef<Info> > >& matches) const { MapValue* mv = get(mk); if(!mv) return false; return mv->findAllMatches(string,matches); } bool findBestMatchSubs( const MapKey& mk, const char* string, KnSet& subs, KnSmartRef<Pattern>& pattern, KnSmartRef<Info>& info) const { MapValue* mv = get(mk); if(!mv) return false; return mv->findBestMatchSubs(string,subs,pattern,info); } virtual bool findAllMatchesSubs( const MapKey& mk, const char* string, std::vector<std::pair< KnSet*, KnSmartRef<Info> > >& matches) const { MapValue* mv = get(mk); if(!mv) return false; return mv->findAllMatchesSubs(string,matches); } bool findByName( const MapKey& mk, const KnString& name, KnSmartRef<Pattern>& pattern, KnSmartRef<Info>& info) const { MapValue* mv = get(mk); if(!mv) return false; return mv->findByName(name,pattern,info); } // remove first found with that name bool removeByName( const KnString& name) { MapValue* value; bool result = false; for(MapTypeIterator it = m_map.begin(); it != m_map.end(); ) { value = it->second; result = result || (value->removeByName(name)); if(value->isEmpty()) { m_map.erase(it); return result; } } return re... [truncated message content] |