├── .gitignore.in ├── LICENSE ├── Makefile.in ├── README ├── build-setup ├── configs └── apps │ ├── js.config.in │ ├── pong.config.in │ ├── rdfa2jsonld.config.in │ └── test.config.in ├── cpp ├── 3rdparty │ ├── Makefile.in │ ├── expat │ │ ├── include │ │ │ ├── expat.h │ │ │ └── expat_external.h │ │ ├── libexpat.a │ │ └── libexpat.dll │ ├── iconv │ │ ├── include │ │ │ └── iconv.h │ │ ├── libcharset1.dll │ │ └── libiconv2.dll │ ├── mysql │ │ ├── howto.txt │ │ ├── include │ │ │ └── mysql │ │ │ │ ├── config-win.h │ │ │ │ ├── decimal.h │ │ │ │ ├── errmsg.h │ │ │ │ ├── keycache.h │ │ │ │ ├── libmysql.def │ │ │ │ ├── m_ctype.h │ │ │ │ ├── m_string.h │ │ │ │ ├── my_alloc.h │ │ │ │ ├── my_attribute.h │ │ │ │ ├── my_dbug.h │ │ │ │ ├── my_dir.h │ │ │ │ ├── my_getopt.h │ │ │ │ ├── my_global.h │ │ │ │ ├── my_list.h │ │ │ │ ├── my_net.h │ │ │ │ ├── my_no_pthread.h │ │ │ │ ├── my_pthread.h │ │ │ │ ├── my_sys.h │ │ │ │ ├── my_xml.h │ │ │ │ ├── mysql.h │ │ │ │ ├── mysql_com.h │ │ │ │ ├── mysql_embed.h │ │ │ │ ├── mysql_time.h │ │ │ │ ├── mysql_version.h │ │ │ │ ├── mysqld_ername.h │ │ │ │ ├── mysqld_error.h │ │ │ │ ├── raid.h │ │ │ │ ├── sql_common.h │ │ │ │ ├── sql_state.h │ │ │ │ ├── sslopt-case.h │ │ │ │ ├── sslopt-longopts.h │ │ │ │ ├── sslopt-vars.h │ │ │ │ └── typelib.h │ │ ├── libmysql.a │ │ ├── libmysql.def │ │ ├── libmysql.dll │ │ ├── libmysql.lib │ │ ├── mysys.lib │ │ ├── regex.lib │ │ ├── strings.lib │ │ └── zlib.lib │ ├── openssl │ │ ├── include │ │ │ └── openssl │ │ │ │ ├── aes.h │ │ │ │ ├── applink.c │ │ │ │ ├── asn1.h │ │ │ │ ├── asn1_mac.h │ │ │ │ ├── asn1t.h │ │ │ │ ├── bio.h │ │ │ │ ├── blowfish.h │ │ │ │ ├── bn.h │ │ │ │ ├── buffer.h │ │ │ │ ├── cast.h │ │ │ │ ├── comp.h │ │ │ │ ├── conf.h │ │ │ │ ├── conf_api.h │ │ │ │ ├── crypto.h │ │ │ │ ├── des.h │ │ │ │ ├── des_old.h │ │ │ │ ├── dh.h │ │ │ │ ├── dsa.h │ │ │ │ ├── dso.h │ │ │ │ ├── dtls1.h │ │ │ │ ├── e_os2.h │ │ │ │ ├── ebcdic.h │ │ │ │ ├── ec.h │ │ │ │ ├── ecdh.h │ │ │ │ ├── ecdsa.h │ │ │ │ ├── engine.h │ │ │ │ ├── err.h │ │ │ │ ├── evp.h │ │ │ │ ├── hmac.h │ │ │ │ ├── idea.h │ │ │ │ ├── krb5_asn.h │ │ │ │ ├── kssl.h │ │ │ │ ├── lhash.h │ │ │ │ ├── md2.h │ │ │ │ ├── md4.h │ │ │ │ ├── md5.h │ │ │ │ ├── obj_mac.h │ │ │ │ ├── objects.h │ │ │ │ ├── ocsp.h │ │ │ │ ├── opensslconf.h │ │ │ │ ├── opensslv.h │ │ │ │ ├── ossl_typ.h │ │ │ │ ├── pem.h │ │ │ │ ├── pem2.h │ │ │ │ ├── pkcs12.h │ │ │ │ ├── pkcs7.h │ │ │ │ ├── pq_compat.h │ │ │ │ ├── pqueue.h │ │ │ │ ├── rand.h │ │ │ │ ├── rc2.h │ │ │ │ ├── rc4.h │ │ │ │ ├── ripemd.h │ │ │ │ ├── rsa.h │ │ │ │ ├── safestack.h │ │ │ │ ├── sha.h │ │ │ │ ├── ssl.h │ │ │ │ ├── ssl2.h │ │ │ │ ├── ssl23.h │ │ │ │ ├── ssl3.h │ │ │ │ ├── stack.h │ │ │ │ ├── store.h │ │ │ │ ├── symhacks.h │ │ │ │ ├── tls1.h │ │ │ │ ├── tmdiff.h │ │ │ │ ├── txt_db.h │ │ │ │ ├── ui.h │ │ │ │ ├── ui_compat.h │ │ │ │ ├── x509.h │ │ │ │ ├── x509_vfy.h │ │ │ │ └── x509v3.h │ │ ├── libeay32.dll │ │ └── ssleay32.dll │ ├── pthread │ │ ├── include │ │ │ ├── pthread.h │ │ │ ├── sched.h │ │ │ └── semaphore.h │ │ ├── libpthreadGC2.a │ │ ├── libpthreadGCE2.a │ │ ├── pthreadGC2.dll │ │ ├── pthreadGCE2.dll │ │ ├── pthreadVC2.dll │ │ ├── pthreadVC2.lib │ │ ├── pthreadVCE2.dll │ │ ├── pthreadVCE2.lib │ │ ├── pthreadVSE2.dll │ │ └── pthreadVSE2.lib │ ├── regex │ │ ├── include │ │ │ └── regex.h │ │ ├── libgnurx-0.dll │ │ └── libregex.a │ ├── sqlite3 │ │ ├── include │ │ │ └── sqlite3.h │ │ ├── sqlite3.def │ │ └── sqlite3.dll │ └── zlib │ │ ├── include │ │ ├── zconf.h │ │ └── zlib.h │ │ ├── libz.a │ │ ├── libz.dll.a │ │ └── mgwz.dll ├── app │ ├── App.cpp │ ├── App.h │ ├── AppConfig.cpp │ ├── AppConfig.h │ ├── AppFactory.cpp │ ├── AppFactory.h │ ├── AppRunner.cpp │ ├── AppRunner.h │ ├── AppTools.cpp │ ├── AppTools.h │ ├── CmdLineParser.cpp │ ├── CmdLineParser.h │ └── Makefile.in ├── apps │ ├── js │ │ ├── Makefile.in │ │ └── js.cpp │ ├── monarch │ │ ├── Makefile.in │ │ └── monarch.cpp │ ├── portmap │ │ ├── Makefile.in │ │ └── portmap.cpp │ ├── rdfa2jsonld │ │ ├── Makefile.in │ │ └── rdfa2jsonld.cpp │ └── tester │ │ ├── Makefile.in │ │ ├── Tester.cpp │ │ └── Tester.h ├── compress │ ├── Makefile.in │ ├── deflate │ │ ├── Deflater.cpp │ │ └── Deflater.h │ ├── gzip │ │ ├── Gzipper.cpp │ │ ├── Gzipper.h │ │ ├── Header.cpp │ │ ├── Header.h │ │ ├── Trailer.cpp │ │ └── Trailer.h │ └── zip │ │ ├── ZipEntry.cpp │ │ ├── ZipEntry.h │ │ ├── Zipper.cpp │ │ └── Zipper.h ├── config │ ├── ConfigChangeListener.h │ ├── ConfigManager.cpp │ ├── ConfigManager.h │ └── Makefile.in ├── crypto │ ├── AbstractBlockCipher.cpp │ ├── AbstractBlockCipher.h │ ├── AsymmetricKey.cpp │ ├── AsymmetricKey.h │ ├── AsymmetricKeyFactory.cpp │ ├── AsymmetricKeyFactory.h │ ├── BigDecimal.cpp │ ├── BigDecimal.h │ ├── BigInteger.cpp │ ├── BigInteger.h │ ├── BlockCipher.cpp │ ├── BlockCipher.h │ ├── BlockCipherInputStream.cpp │ ├── BlockCipherInputStream.h │ ├── CryptoHashAlgorithm.cpp │ ├── CryptoHashAlgorithm.h │ ├── DefaultBlockCipher.cpp │ ├── DefaultBlockCipher.h │ ├── DigitalEnvelope.cpp │ ├── DigitalEnvelope.h │ ├── DigitalSignature.cpp │ ├── DigitalSignature.h │ ├── DigitalSignatureInputStream.cpp │ ├── DigitalSignatureInputStream.h │ ├── DigitalSignatureOutputStream.cpp │ ├── DigitalSignatureOutputStream.h │ ├── HashMac.cpp │ ├── HashMac.h │ ├── Makefile.in │ ├── MessageDigest.cpp │ ├── MessageDigest.h │ ├── PrivateKey.cpp │ ├── PrivateKey.h │ ├── PublicKey.cpp │ ├── PublicKey.h │ ├── SymmetricKey.cpp │ ├── SymmetricKey.h │ ├── SymmetricKeyFactory.cpp │ ├── SymmetricKeyFactory.h │ ├── X509Certificate.cpp │ └── X509Certificate.h ├── data │ ├── AbstractDataFormatInspector.cpp │ ├── AbstractDataFormatInspector.h │ ├── CharacterSetMutator.cpp │ ├── CharacterSetMutator.h │ ├── Data.h │ ├── DataFormatInspector.h │ ├── DataInspector.h │ ├── DynamicObjectInputStream.cpp │ ├── DynamicObjectInputStream.h │ ├── DynamicObjectOutputStream.cpp │ ├── DynamicObjectOutputStream.h │ ├── DynamicObjectReader.h │ ├── DynamicObjectWriter.h │ ├── InspectorInputStream.cpp │ ├── InspectorInputStream.h │ ├── Makefile.in │ ├── TemplateCache.cpp │ ├── TemplateCache.h │ ├── TemplateInputStream.cpp │ ├── TemplateInputStream.h │ ├── avi │ │ ├── AviHeader.cpp │ │ ├── AviHeader.h │ │ ├── AviHeaderList.cpp │ │ ├── AviHeaderList.h │ │ ├── AviStreamFormat.cpp │ │ ├── AviStreamFormat.h │ │ ├── AviStreamHeader.cpp │ │ ├── AviStreamHeader.h │ │ ├── AviStreamHeaderList.cpp │ │ ├── AviStreamHeaderList.h │ │ ├── OdmlHeader.cpp │ │ └── OdmlHeader.h │ ├── id3v2 │ │ ├── FrameHeader.cpp │ │ ├── FrameHeader.h │ │ ├── FrameSink.h │ │ ├── FrameSource.h │ │ ├── Tag.cpp │ │ ├── Tag.h │ │ ├── TagHeader.cpp │ │ └── TagHeader.h │ ├── json │ │ ├── JsonLd.cpp │ │ ├── JsonLd.h │ │ ├── JsonReader.cpp │ │ ├── JsonReader.h │ │ ├── JsonWriter.cpp │ │ └── JsonWriter.h │ ├── mpeg │ │ ├── AudioBitrateTable.cpp │ │ ├── AudioBitrateTable.h │ │ ├── AudioCharacteristics.h │ │ ├── AudioCrc16.cpp │ │ ├── AudioCrc16.h │ │ ├── AudioFrameHeader.cpp │ │ ├── AudioFrameHeader.h │ │ ├── AudioSamplingRateTable.cpp │ │ └── AudioSamplingRateTable.h │ ├── rdfa │ │ ├── RdfaReader.cpp │ │ └── RdfaReader.h │ ├── riff │ │ ├── RiffChunkHeader.cpp │ │ ├── RiffChunkHeader.h │ │ ├── RiffFormHeader.cpp │ │ ├── RiffFormHeader.h │ │ ├── RiffListHeader.cpp │ │ └── RiffListHeader.h │ └── xml │ │ ├── DomReader.cpp │ │ ├── DomReader.h │ │ ├── DomTypes.h │ │ ├── DomWriter.cpp │ │ ├── DomWriter.h │ │ ├── XmlReader.cpp │ │ ├── XmlReader.h │ │ ├── XmlWriter.cpp │ │ └── XmlWriter.h ├── event │ ├── Event.h │ ├── EventController.cpp │ ├── EventController.h │ ├── EventDaemon.cpp │ ├── EventDaemon.h │ ├── EventWaiter.cpp │ ├── EventWaiter.h │ ├── Makefile.in │ ├── Observable.cpp │ ├── Observable.h │ ├── Observer.h │ ├── ObserverDelegate.h │ ├── ObserverList.cpp │ └── ObserverList.h ├── fiber │ ├── Fiber.cpp │ ├── Fiber.h │ ├── FiberContext.cpp │ ├── FiberContext.h │ ├── FiberMessageCenter.cpp │ ├── FiberMessageCenter.h │ ├── FiberScheduler.cpp │ ├── FiberScheduler.h │ ├── Makefile.in │ ├── MessagableFiber.cpp │ ├── MessagableFiber.h │ ├── PortableUContext.cpp │ ├── PortableUContext.h │ ├── PortableUContext386.h │ ├── PortableUContextAsm.S │ ├── PortableUContextPPC.h │ ├── WindowsSupport.cpp │ └── WindowsSupport.h ├── http │ ├── CookieJar.cpp │ ├── CookieJar.h │ ├── HttpBodyInputStream.cpp │ ├── HttpBodyInputStream.h │ ├── HttpBodyOutputStream.cpp │ ├── HttpBodyOutputStream.h │ ├── HttpChunkedTransferInputStream.cpp │ ├── HttpChunkedTransferInputStream.h │ ├── HttpChunkedTransferOutputStream.cpp │ ├── HttpChunkedTransferOutputStream.h │ ├── HttpClient.cpp │ ├── HttpClient.h │ ├── HttpConnection.cpp │ ├── HttpConnection.h │ ├── HttpConnectionMonitor.cpp │ ├── HttpConnectionMonitor.h │ ├── HttpConnectionPool.cpp │ ├── HttpConnectionPool.h │ ├── HttpConnectionServicer.cpp │ ├── HttpConnectionServicer.h │ ├── HttpHeader.cpp │ ├── HttpHeader.h │ ├── HttpPathRewriter.cpp │ ├── HttpPathRewriter.h │ ├── HttpRequest.cpp │ ├── HttpRequest.h │ ├── HttpRequestHeader.cpp │ ├── HttpRequestHeader.h │ ├── HttpRequestModifier.cpp │ ├── HttpRequestModifier.h │ ├── HttpRequestServicer.cpp │ ├── HttpRequestServicer.h │ ├── HttpRequestState.cpp │ ├── HttpRequestState.h │ ├── HttpResponse.cpp │ ├── HttpResponse.h │ ├── HttpResponseHeader.cpp │ ├── HttpResponseHeader.h │ ├── HttpTrailer.cpp │ ├── HttpTrailer.h │ └── Makefile.in ├── io │ ├── BitStream.cpp │ ├── BitStream.h │ ├── BufferedOutputStream.cpp │ ├── BufferedOutputStream.h │ ├── ByteArrayInputStream.cpp │ ├── ByteArrayInputStream.h │ ├── ByteArrayOutputStream.cpp │ ├── ByteArrayOutputStream.h │ ├── ByteBuffer.cpp │ ├── ByteBuffer.h │ ├── File.cpp │ ├── File.h │ ├── FileFunctions.h │ ├── FileInputStream.cpp │ ├── FileInputStream.h │ ├── FileList.h │ ├── FileOutputStream.cpp │ ├── FileOutputStream.h │ ├── FilterInputStream.cpp │ ├── FilterInputStream.h │ ├── FilterOutputStream.cpp │ ├── FilterOutputStream.h │ ├── IOEventDelegate.h │ ├── IOException.cpp │ ├── IOException.h │ ├── IOMonitor.cpp │ ├── IOMonitor.h │ ├── IOWatcher.h │ ├── IgnoreOutputStream.cpp │ ├── IgnoreOutputStream.h │ ├── InputStream.cpp │ ├── InputStream.h │ ├── Makefile.in │ ├── MutationAlgorithm.h │ ├── MutatorInputStream.cpp │ ├── MutatorInputStream.h │ ├── MutatorOutputStream.cpp │ ├── MutatorOutputStream.h │ ├── NullOutputStream.h │ ├── OStreamOutputStream.cpp │ ├── OStreamOutputStream.h │ ├── OutputStream.cpp │ ├── OutputStream.h │ ├── PeekInputStream.cpp │ ├── PeekInputStream.h │ ├── TruncateInputStream.cpp │ └── TruncateInputStream.h ├── kernel │ ├── Makefile.in │ ├── MicroKernel.cpp │ ├── MicroKernel.h │ ├── MicroKernelModule.cpp │ ├── MicroKernelModule.h │ └── MicroKernelModuleApi.h ├── logging │ ├── Category.cpp │ ├── Category.h │ ├── FileLogger.cpp │ ├── FileLogger.h │ ├── Logger.cpp │ ├── Logger.h │ ├── Logging.cpp │ ├── Logging.h │ ├── LoggingCategories.cpp │ ├── LoggingCategories.h │ ├── Makefile.in │ ├── OutputStreamLogger.cpp │ └── OutputStreamLogger.h ├── mail │ ├── Mail.cpp │ ├── Mail.h │ ├── MailSpool.cpp │ ├── MailSpool.h │ ├── MailTemplateParser.cpp │ ├── MailTemplateParser.h │ ├── Makefile.in │ ├── SmtpClient.cpp │ └── SmtpClient.h ├── modest │ ├── Engine.cpp │ ├── Engine.h │ ├── Kernel.cpp │ ├── Kernel.h │ ├── Makefile.in │ ├── Module.h │ ├── ModuleInterface.h │ ├── ModuleLibrary.cpp │ ├── ModuleLibrary.h │ ├── ModuleLoader.cpp │ ├── ModuleLoader.h │ ├── Operation.cpp │ ├── Operation.h │ ├── OperationGuard.h │ ├── OperationGuardChain.cpp │ ├── OperationGuardChain.h │ ├── OperationImpl.cpp │ ├── OperationImpl.h │ ├── OperationList.cpp │ ├── OperationList.h │ ├── OperationRunner.h │ ├── StateMutator.h │ ├── StateMutatorChain.cpp │ └── StateMutatorChain.h ├── mysql │ ├── Makefile.in │ ├── MySqlConnection.cpp │ ├── MySqlConnection.h │ ├── MySqlConnectionPool.cpp │ ├── MySqlConnectionPool.h │ ├── MySqlDatabaseClient.cpp │ ├── MySqlDatabaseClient.h │ ├── MySqlRow.cpp │ ├── MySqlRow.h │ ├── MySqlStatement.cpp │ └── MySqlStatement.h ├── net │ ├── AbstractSocket.cpp │ ├── AbstractSocket.h │ ├── BandwidthThrottler.h │ ├── BandwidthThrottlerChain.cpp │ ├── BandwidthThrottlerChain.h │ ├── Connection.cpp │ ├── Connection.h │ ├── ConnectionInputStream.cpp │ ├── ConnectionInputStream.h │ ├── ConnectionOutputStream.cpp │ ├── ConnectionOutputStream.h │ ├── ConnectionService.cpp │ ├── ConnectionService.h │ ├── ConnectionServicer.h │ ├── ConnectionWrapper.cpp │ ├── ConnectionWrapper.h │ ├── Datagram.cpp │ ├── Datagram.h │ ├── DatagramService.cpp │ ├── DatagramService.h │ ├── DatagramServicer.h │ ├── DatagramSocket.cpp │ ├── DatagramSocket.h │ ├── DefaultBandwidthThrottler.cpp │ ├── DefaultBandwidthThrottler.h │ ├── Internet6Address.cpp │ ├── Internet6Address.h │ ├── InternetAddress.cpp │ ├── InternetAddress.h │ ├── Makefile.in │ ├── NullSocketDataPresenter.h │ ├── PortService.cpp │ ├── PortService.h │ ├── Server.cpp │ ├── Server.h │ ├── Socket.h │ ├── SocketAddress.cpp │ ├── SocketAddress.h │ ├── SocketDataPresenter.h │ ├── SocketDataPresenterList.cpp │ ├── SocketDataPresenterList.h │ ├── SocketDefinitions.h │ ├── SocketInputStream.cpp │ ├── SocketInputStream.h │ ├── SocketOutputStream.cpp │ ├── SocketOutputStream.h │ ├── SocketTools.cpp │ ├── SocketTools.h │ ├── SocketWrapper.cpp │ ├── SocketWrapper.h │ ├── SslContext.cpp │ ├── SslContext.h │ ├── SslSession.h │ ├── SslSessionCache.cpp │ ├── SslSessionCache.h │ ├── SslSocket.cpp │ ├── SslSocket.h │ ├── SslSocketDataPresenter.cpp │ ├── SslSocketDataPresenter.h │ ├── TcpSocket.cpp │ ├── TcpSocket.h │ ├── UdpSocket.cpp │ ├── UdpSocket.h │ ├── WindowsSupport.cpp │ └── WindowsSupport.h ├── rt │ ├── Atomic.cpp │ ├── Atomic.h │ ├── Collectable.h │ ├── DynamicLibrary.h │ ├── DynamicObject.cpp │ ├── DynamicObject.h │ ├── DynamicObjectImpl.cpp │ ├── DynamicObjectImpl.h │ ├── DynamicObjectIterator.cpp │ ├── DynamicObjectIterator.h │ ├── DynamicObjectIterators.cpp │ ├── DynamicObjectIterators.h │ ├── Exception.cpp │ ├── Exception.h │ ├── ExclusiveLock.cpp │ ├── ExclusiveLock.h │ ├── HashTable.h │ ├── HazardPtrList.cpp │ ├── HazardPtrList.h │ ├── Iterator.h │ ├── JobDispatcher.cpp │ ├── JobDispatcher.h │ ├── ListIterator.h │ ├── Makefile.in │ ├── Monitor.cpp │ ├── Monitor.h │ ├── Platform.cpp │ ├── Platform.h │ ├── PooledThread.cpp │ ├── PooledThread.h │ ├── Runnable.h │ ├── RunnableDelegate.h │ ├── Semaphore.cpp │ ├── Semaphore.h │ ├── SharedLock.cpp │ ├── SharedLock.h │ ├── System.cpp │ ├── System.h │ ├── Thread.cpp │ ├── Thread.h │ ├── ThreadPool.cpp │ ├── ThreadPool.h │ ├── TimeFunctions.cpp │ └── TimeFunctions.h ├── sphinx │ ├── Makefile.in │ ├── SphinxClient.cpp │ └── SphinxClient.h ├── sql │ ├── AbstractConnection.cpp │ ├── AbstractConnection.h │ ├── AbstractConnectionPool.cpp │ ├── AbstractConnectionPool.h │ ├── Connection.h │ ├── ConnectionPool.h │ ├── DatabaseClient.cpp │ ├── DatabaseClient.h │ ├── Makefile.in │ ├── PooledConnection.cpp │ ├── PooledConnection.h │ ├── Row.cpp │ ├── Row.h │ ├── SqlStatementBuilder.cpp │ ├── SqlStatementBuilder.h │ ├── Statement.cpp │ ├── Statement.h │ └── StatementBuilder.h ├── sqlite3 │ ├── Makefile.in │ ├── Sqlite3Connection.cpp │ ├── Sqlite3Connection.h │ ├── Sqlite3ConnectionPool.cpp │ ├── Sqlite3ConnectionPool.h │ ├── Sqlite3DatabaseClient.cpp │ ├── Sqlite3DatabaseClient.h │ ├── Sqlite3Row.cpp │ ├── Sqlite3Row.h │ ├── Sqlite3Statement.cpp │ └── Sqlite3Statement.h ├── test │ ├── Makefile.in │ ├── Test.cpp │ ├── Test.h │ ├── TestLoader.cpp │ ├── TestLoader.h │ ├── TestModule.cpp │ ├── TestModule.h │ ├── TestRunner.cpp │ ├── TestRunner.h │ └── Testable.h ├── tests │ ├── Makefile.in │ ├── run-unit-tests.py.in │ ├── scripts │ │ ├── tf-gen.sh │ │ └── tf-graph.py │ ├── test-compress.cpp │ ├── test-config.cpp │ ├── test-configmanager.cpp │ ├── test-crypto.cpp │ ├── test-data.cpp │ ├── test-dyno-perf.cpp │ ├── test-event.cpp │ ├── test-fiber-yield.cpp │ ├── test-fiber.cpp │ ├── test-hashtable.cpp │ ├── test-http.cpp │ ├── test-io.cpp │ ├── test-jsonld.cpp │ ├── test-logging.cpp │ ├── test-mail.cpp │ ├── test-mmap.cpp │ ├── test-modest.cpp │ ├── test-modexp.cpp │ ├── test-mysql.cpp │ ├── test-mysql.h.template │ ├── test-net.cpp │ ├── test-pong.cpp │ ├── test-random.cpp │ ├── test-rdfa.cpp │ ├── test-rt.cpp │ ├── test-sharedlock-deadlock.cpp │ ├── test-sphinx.cpp │ ├── test-sqlite3.cpp │ ├── test-template.cpp │ ├── test-ucontext.cpp │ ├── test-upnp.cpp │ ├── test-util.cpp │ ├── test-v8-ws.js │ ├── test-v8.cpp │ ├── test-validation.cpp │ └── test-ws.cpp ├── upnp │ ├── ControlPoint.cpp │ ├── ControlPoint.h │ ├── DeviceDiscoverer.cpp │ ├── DeviceDiscoverer.h │ ├── Makefile.in │ ├── SoapEnvelope.cpp │ ├── SoapEnvelope.h │ └── TypeDefinitions.h ├── util │ ├── AnsiEscapeCodes.h │ ├── Base64Codec.cpp │ ├── Base64Codec.h │ ├── Convert.cpp │ ├── Convert.h │ ├── Crc16.cpp │ ├── Crc16.h │ ├── Data.h │ ├── Date.cpp │ ├── Date.h │ ├── HashAlgorithm.h │ ├── Macros.h │ ├── Makefile.in │ ├── Math.h │ ├── PathFormatter.cpp │ ├── PathFormatter.h │ ├── Pattern.cpp │ ├── Pattern.h │ ├── Random.cpp │ ├── Random.h │ ├── RateAverager.cpp │ ├── RateAverager.h │ ├── RateWindow.cpp │ ├── RateWindow.h │ ├── StringTokenizer.cpp │ ├── StringTokenizer.h │ ├── StringTools.cpp │ ├── StringTools.h │ ├── TimeZone.cpp │ ├── TimeZone.h │ ├── Timer.cpp │ ├── Timer.h │ ├── UniqueList.h │ ├── Url.cpp │ └── Url.h ├── v8 │ ├── Makefile.in │ ├── V8Controller.cpp │ ├── V8Controller.h │ ├── V8Engine.cpp │ ├── V8Engine.h │ ├── V8EngineApi.h │ ├── V8Module.cpp │ ├── V8Module.h │ ├── V8ModuleApi.h │ └── V8Wrapper.h ├── validation │ ├── All.cpp │ ├── All.h │ ├── Any.cpp │ ├── Any.h │ ├── Array.cpp │ ├── Array.h │ ├── Compare.cpp │ ├── Compare.h │ ├── CompareText.cpp │ ├── CompareText.h │ ├── Contains.cpp │ ├── Contains.h │ ├── Each.cpp │ ├── Each.h │ ├── Equals.cpp │ ├── Equals.h │ ├── In.cpp │ ├── In.h │ ├── Int.cpp │ ├── Int.h │ ├── Makefile.in │ ├── Map.cpp │ ├── Map.h │ ├── Max.cpp │ ├── Max.h │ ├── Member.cpp │ ├── Member.h │ ├── Min.cpp │ ├── Min.h │ ├── Not.cpp │ ├── Not.h │ ├── NotCompare.cpp │ ├── NotCompare.h │ ├── NotValid.cpp │ ├── NotValid.h │ ├── Null.cpp │ ├── Null.h │ ├── Optional.cpp │ ├── Optional.h │ ├── Regex.cpp │ ├── Regex.h │ ├── Type.cpp │ ├── Type.h │ ├── Valid.cpp │ ├── Valid.h │ ├── Validation.h │ ├── Validator.cpp │ ├── Validator.h │ ├── ValidatorContext.cpp │ ├── ValidatorContext.h │ ├── ValidatorFactory.cpp │ ├── ValidatorFactory.h │ ├── ValidatorList.cpp │ └── ValidatorList.h └── ws │ ├── ChannelExceptionHandler.cpp │ ├── ChannelExceptionHandler.h │ ├── IpAuthenticator.cpp │ ├── IpAuthenticator.h │ ├── Makefile.in │ ├── Message.cpp │ ├── Message.h │ ├── PathHandler.cpp │ ├── PathHandler.h │ ├── PathHandlerDelegate.h │ ├── ProxyPathHandler.cpp │ ├── ProxyPathHandler.h │ ├── RequestAuthenticator.cpp │ ├── RequestAuthenticator.h │ ├── RequestAuthenticatorDelegate.h │ ├── RestfulHandler.cpp │ ├── RestfulHandler.h │ ├── ServiceChannel.cpp │ ├── ServiceChannel.h │ ├── WebServer.cpp │ ├── WebServer.h │ ├── WebService.cpp │ ├── WebService.h │ ├── WebServiceContainer.cpp │ └── WebServiceContainer.h ├── installers └── debian │ ├── changelog.in │ ├── compat │ ├── control │ ├── copyright │ └── rules ├── monarch-run.in ├── monarch3.pc.in ├── python └── crypto │ └── cppwrapper │ ├── dbcrypto.i │ ├── dbcryptoWrapper.cpp │ ├── dbcryptoWrapper.h │ └── test.py └── setup ├── Makefile.base.in ├── baserules.mk ├── config.guess ├── config.sub ├── configure.ac ├── docs.doxygen.in ├── install-sh ├── m4 ├── as-compiler-flag.m4 ├── as-python.m4 ├── mo-args.m4 ├── mo-compiler.m4 ├── mo-platform.m4 └── mo-util.m4 ├── monarch.supp └── support ├── config.guess └── config.sub /.gitignore.in: -------------------------------------------------------------------------------- 1 | # 2 | # Generated by configure from .gitignore.in 3 | # 4 | *~ 5 | *.sw[nop] 6 | .project 7 | .cdtproject 8 | .classpath 9 | .cproject 10 | .settings 11 | TAGS 12 | aclocal.m4 13 | autom4te.cache 14 | build 15 | config.log 16 | config.status 17 | configure 18 | dist 19 | setup/config.h.in 20 | setup/config.h 21 | @CONFIGURE_GENERATED_FILES@ 22 | -------------------------------------------------------------------------------- /build-setup: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # 3 | # This shell script sets up the software to be built using 'make'. In 4 | # order to perform a build from a fresh source tree, do the following: 5 | # 6 | # 1. ./build-setup 7 | # 2. make 8 | # 9 | # If you don't want ./configure to be run automatically, you can do 10 | # the following: ./build-setup -s 11 | 12 | # Process command line options 13 | SKIP_CONFIGURE=0 14 | for arg in "$*" 15 | do 16 | case $arg in 17 | "-s" | "--setup-only" ) SKIP_CONFIGURE=1 ;; 18 | esac 19 | done 20 | 21 | # Check and add potential aclocal dirs 22 | MAYBE_AC_DIRS=" 23 | /usr/local/share/aclocal 24 | /opt/local/share/aclocal 25 | /sw/share/aclocal 26 | " 27 | ACDIRS="-I m4" 28 | for dir in $MAYBE_AC_DIRS; do 29 | if test -d $dir; then 30 | ACDIRS="$ACDIRS -I $dir" 31 | fi 32 | done 33 | 34 | # Run aclocal on the set of local ac scripts 35 | cd setup 36 | aclocal $ACDIRS 37 | # Generate the configure script 38 | autoconf && mv configure .. 39 | cd .. 40 | 41 | autoheader -I setup setup/configure.ac 42 | 43 | # Run the configure script if "-s" isn't a command line option 44 | if [ $SKIP_CONFIGURE -eq 0 ]; then 45 | # Run the configure script in default development mode 46 | ./configure $* 47 | fi 48 | 49 | -------------------------------------------------------------------------------- /configs/apps/js.config.in: -------------------------------------------------------------------------------- 1 | { 2 | "_id_": "monarch.apps.js", 3 | "_version_": "Monarch Config 3.0", 4 | "_group_": "main", 5 | "_append_": { 6 | "monarch.app.Kernel": { 7 | "appPath": "@MONARCH_DIR@/dist/modules/apps/@LIB_PREFIX@mojs.@DYNAMIC_LIB_EXT@", 8 | "modulePath": [ 9 | "@MONARCH_DIR@/dist/modules/ext" 10 | ] 11 | } 12 | }, 13 | "_merge_": { 14 | "monarch.tests.v8": { 15 | "scriptPath": "@MONARCH_DIR@/js" 16 | } 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /configs/apps/pong.config.in: -------------------------------------------------------------------------------- 1 | { 2 | "_id_": "monarch.apps.test.pong", 3 | "_version_": "Monarch Config 3.0", 4 | "_group_": "after defaults", 5 | "_append_": { 6 | "monarch.app.Kernel": { 7 | "appPath": "@MONARCH_DIR@/dist/modules/apps/@LIB_PREFIX@motester.@DYNAMIC_LIB_EXT@", 8 | "modulePath": [ 9 | "@MONARCH_DIR@/dist/modules/tests/@LIB_PREFIX@motest-pong.@DYNAMIC_LIB_EXT@" 10 | ] 11 | }, 12 | "monarch.apps.tester.Tester": { 13 | "tests": [ 14 | "pong" 15 | ] 16 | } 17 | }, 18 | "_merge_": { 19 | "monarch.apps.tester.Tester": { 20 | "level": 0 21 | }, 22 | "pong": { 23 | "chunked": false, 24 | "dynoStats": false, 25 | "num": 0, 26 | "port": 19500, 27 | "ssl": false, 28 | "time": 0, 29 | "threadStackSize": 131072, 30 | "threads": 10, 31 | "maxConnections": 10000, 32 | "backlog": 2500 33 | } 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /configs/apps/rdfa2jsonld.config.in: -------------------------------------------------------------------------------- 1 | { 2 | "_id_": "monarch.apps.test", 3 | "_version_": "Monarch Config 3.0", 4 | "_group_": "main", 5 | "_append_": { 6 | "monarch.app.Kernel": { 7 | "appPath": "@MONARCH_DIR@/dist/modules/apps/@LIB_PREFIX@mordfa2jsonld.@DYNAMIC_LIB_EXT@" 8 | } 9 | }, 10 | "_merge_": { 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /configs/apps/test.config.in: -------------------------------------------------------------------------------- 1 | { 2 | "_id_": "monarch.apps.test", 3 | "_version_": "Monarch Config 3.0", 4 | "_group_": "main", 5 | "_append_": { 6 | "monarch.app.Kernel": { 7 | "appPath": "@MONARCH_DIR@/dist/modules/apps/@LIB_PREFIX@motester.@DYNAMIC_LIB_EXT@", 8 | "modulePath": [ 9 | "@MONARCH_DIR@/dist/modules/ext", 10 | "@MONARCH_DIR@/dist/modules/tests" 11 | ] 12 | } 13 | }, 14 | "_merge_": { 15 | "monarch.tests.v8": { 16 | "scriptPath": "@MONARCH_DIR@/cpp/tests" 17 | } 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /cpp/3rdparty/Makefile.in: -------------------------------------------------------------------------------- 1 | # Makefile to compile the module in this directory 2 | 3 | include @MONARCH_DIR@/setup/Makefile.base 4 | 5 | ifeq ($(BUILD_FOR_WINDOWS),yes) 6 | build-libraries: 7 | @mkdir -p $(LIB_DIR) 8 | @ln -sf $(CWD)/pthread/pthreadGCE2.dll $(LIB_DIR)/pthreadGCE2.dll 9 | @ln -sf $(CWD)/openssl/libeay32.dll $(LIB_DIR)/libeay32.dll 10 | @ln -sf $(CWD)/openssl/ssleay32.dll $(LIB_DIR)/ssleay32.dll 11 | @ln -sf $(CWD)/expat/libexpat.dll $(LIB_DIR)/libexpat.dll 12 | @ln -sf $(CWD)/iconv/libiconv2.dll $(LIB_DIR)/iconv2.dll 13 | @ln -sf $(CWD)/iconv/libiconv2.dll $(LIB_DIR)/libiconv2.dll 14 | @ln -sf $(CWD)/iconv/libcharset1.dll $(LIB_DIR)/charset1.dll 15 | @ln -sf $(CWD)/regex/libgnurx-0.dll $(LIB_DIR)/libgnurx-0.dll 16 | @ln -sf $(CWD)/sqlite3/sqlite3.dll $(LIB_DIR)/sqlite3.dll 17 | @ln -sf $(CWD)/zlib/mgwz.dll $(LIB_DIR)/mgwz.dll 18 | @zcat /usr/share/doc/mingw32-runtime/mingwm10.dll.gz > $(LIB_DIR)/mingwm10.dll 19 | endif 20 | -------------------------------------------------------------------------------- /cpp/3rdparty/expat/libexpat.a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/digitalbazaar/monarch/59ddda30fd462778b97379be36bb76f391967a46/cpp/3rdparty/expat/libexpat.a -------------------------------------------------------------------------------- /cpp/3rdparty/expat/libexpat.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/digitalbazaar/monarch/59ddda30fd462778b97379be36bb76f391967a46/cpp/3rdparty/expat/libexpat.dll -------------------------------------------------------------------------------- /cpp/3rdparty/iconv/libcharset1.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/digitalbazaar/monarch/59ddda30fd462778b97379be36bb76f391967a46/cpp/3rdparty/iconv/libcharset1.dll -------------------------------------------------------------------------------- /cpp/3rdparty/iconv/libiconv2.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/digitalbazaar/monarch/59ddda30fd462778b97379be36bb76f391967a46/cpp/3rdparty/iconv/libiconv2.dll -------------------------------------------------------------------------------- /cpp/3rdparty/mysql/howto.txt: -------------------------------------------------------------------------------- 1 | To convert the windows libmysql.lib file to a mingw .a library 2 | do the following: 3 | 4 | echo EXPORTS > libmysql.def 5 | nm libmysql.lib | grep ' T _' | sed 's/.* T _//' >> libmysql.def 6 | dlltool -k -d libmysql.def -l libmysql.a 7 | -------------------------------------------------------------------------------- /cpp/3rdparty/mysql/include/mysql/my_list.h: -------------------------------------------------------------------------------- 1 | /* Copyright (C) 2000 MySQL AB 2 | 3 | This program is free software; you can redistribute it and/or modify 4 | it under the terms of the GNU General Public License as published by 5 | the Free Software Foundation; version 2 of the License. 6 | 7 | This program is distributed in the hope that it will be useful, 8 | but WITHOUT ANY WARRANTY; without even the implied warranty of 9 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 10 | GNU General Public License for more details. 11 | 12 | You should have received a copy of the GNU General Public License 13 | along with this program; if not, write to the Free Software 14 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ 15 | 16 | #ifndef _list_h_ 17 | #define _list_h_ 18 | 19 | #ifdef __cplusplus 20 | extern "C" { 21 | #endif 22 | 23 | typedef struct st_list { 24 | struct st_list *prev,*next; 25 | void *data; 26 | } LIST; 27 | 28 | typedef int (*list_walk_action)(void *,void *); 29 | 30 | extern LIST *list_add(LIST *root,LIST *element); 31 | extern LIST *list_delete(LIST *root,LIST *element); 32 | extern LIST *list_cons(void *data,LIST *root); 33 | extern LIST *list_reverse(LIST *root); 34 | extern void list_free(LIST *root,unsigned int free_data); 35 | extern unsigned int list_length(LIST *); 36 | extern int list_walk(LIST *,list_walk_action action,gptr argument); 37 | 38 | #define list_rest(a) ((a)->next) 39 | #define list_push(a,b) (a)=list_cons((b),(a)) 40 | #define list_pop(A) {LIST *old=(A); (A)=list_delete(old,old) ; my_free((gptr) old,MYF(MY_FAE)); } 41 | 42 | #ifdef __cplusplus 43 | } 44 | #endif 45 | #endif 46 | -------------------------------------------------------------------------------- /cpp/3rdparty/mysql/include/mysql/mysql_embed.h: -------------------------------------------------------------------------------- 1 | /* Copyright (C) 2000 MySQL AB 2 | 3 | This program is free software; you can redistribute it and/or modify 4 | it under the terms of the GNU General Public License as published by 5 | the Free Software Foundation; version 2 of the License. 6 | 7 | This program is distributed in the hope that it will be useful, 8 | but WITHOUT ANY WARRANTY; without even the implied warranty of 9 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 10 | GNU General Public License for more details. 11 | 12 | You should have received a copy of the GNU General Public License 13 | along with this program; if not, write to the Free Software 14 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ 15 | 16 | /* Defines that are unique to the embedded version of MySQL */ 17 | 18 | #ifdef EMBEDDED_LIBRARY 19 | 20 | /* Things we don't need in the embedded version of MySQL */ 21 | /* TODO HF add #undef HAVE_VIO if we don't want client in embedded library */ 22 | 23 | #undef HAVE_PSTACK /* No stacktrace */ 24 | #undef HAVE_DLOPEN /* No udf functions */ 25 | #undef HAVE_OPENSSL 26 | #undef HAVE_SMEM /* No shared memory */ 27 | #undef HAVE_NDBCLUSTER_DB /* No NDB cluster */ 28 | 29 | #define DONT_USE_RAID 30 | 31 | #endif /* EMBEDDED_LIBRARY */ 32 | -------------------------------------------------------------------------------- /cpp/3rdparty/mysql/include/mysql/mysql_version.h: -------------------------------------------------------------------------------- 1 | /* Copyright Abandoned 1996, 1999, 2001 MySQL AB 2 | This file is public domain and comes with NO WARRANTY of any kind */ 3 | 4 | /* Version numbers for protocol & mysqld */ 5 | 6 | #ifndef _mysql_version_h 7 | #define _mysql_version_h 8 | #ifdef _CUSTOMCONFIG_ 9 | #include 10 | #else 11 | #define PROTOCOL_VERSION 10 12 | #define MYSQL_SERVER_VERSION "5.0.45" 13 | #define MYSQL_BASE_VERSION "mysqld-5.0" 14 | #define MYSQL_SERVER_SUFFIX_DEF "-community-nt" 15 | #define FRM_VER 6 16 | #define MYSQL_VERSION_ID 50045 17 | #define MYSQL_PORT 3306 18 | #define MYSQL_UNIX_ADDR "/tmp/mysql.sock" 19 | #define MYSQL_CONFIG_NAME "my" 20 | #define MYSQL_COMPILATION_COMMENT "MySQL Community Edition (GPL)" 21 | 22 | /* mysqld compile time options */ 23 | #endif /* _CUSTOMCONFIG_ */ 24 | 25 | #ifndef LICENSE 26 | #define LICENSE GPL 27 | #endif /* LICENSE */ 28 | 29 | #endif /* _mysql_version_h */ 30 | -------------------------------------------------------------------------------- /cpp/3rdparty/mysql/include/mysql/sslopt-case.h: -------------------------------------------------------------------------------- 1 | /* Copyright (C) 2000 MySQL AB 2 | 3 | This program is free software; you can redistribute it and/or modify 4 | it under the terms of the GNU General Public License as published by 5 | the Free Software Foundation; version 2 of the License. 6 | 7 | This program is distributed in the hope that it will be useful, 8 | but WITHOUT ANY WARRANTY; without even the implied warranty of 9 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 10 | GNU General Public License for more details. 11 | 12 | You should have received a copy of the GNU General Public License 13 | along with this program; if not, write to the Free Software 14 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ 15 | 16 | #ifdef HAVE_OPENSSL 17 | case OPT_SSL_KEY: 18 | case OPT_SSL_CERT: 19 | case OPT_SSL_CA: 20 | case OPT_SSL_CAPATH: 21 | case OPT_SSL_CIPHER: 22 | /* 23 | Enable use of SSL if we are using any ssl option 24 | One can disable SSL later by using --skip-ssl or --ssl=0 25 | */ 26 | opt_use_ssl= 1; 27 | break; 28 | #endif 29 | -------------------------------------------------------------------------------- /cpp/3rdparty/mysql/include/mysql/sslopt-vars.h: -------------------------------------------------------------------------------- 1 | /* Copyright (C) 2000 MySQL AB 2 | 3 | This program is free software; you can redistribute it and/or modify 4 | it under the terms of the GNU General Public License as published by 5 | the Free Software Foundation; version 2 of the License. 6 | 7 | This program is distributed in the hope that it will be useful, 8 | but WITHOUT ANY WARRANTY; without even the implied warranty of 9 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 10 | GNU General Public License for more details. 11 | 12 | You should have received a copy of the GNU General Public License 13 | along with this program; if not, write to the Free Software 14 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ 15 | 16 | #ifdef HAVE_OPENSSL 17 | #ifdef SSL_VARS_NOT_STATIC 18 | #define SSL_STATIC 19 | #else 20 | #define SSL_STATIC static 21 | #endif 22 | SSL_STATIC my_bool opt_use_ssl = 0; 23 | SSL_STATIC char *opt_ssl_ca = 0; 24 | SSL_STATIC char *opt_ssl_capath = 0; 25 | SSL_STATIC char *opt_ssl_cert = 0; 26 | SSL_STATIC char *opt_ssl_cipher = 0; 27 | SSL_STATIC char *opt_ssl_key = 0; 28 | #ifdef MYSQL_CLIENT 29 | SSL_STATIC my_bool opt_ssl_verify_server_cert= 0; 30 | #endif 31 | #endif 32 | -------------------------------------------------------------------------------- /cpp/3rdparty/mysql/include/mysql/typelib.h: -------------------------------------------------------------------------------- 1 | /* Copyright (C) 2000 MySQL AB 2 | 3 | This program is free software; you can redistribute it and/or modify 4 | it under the terms of the GNU General Public License as published by 5 | the Free Software Foundation; version 2 of the License. 6 | 7 | This program is distributed in the hope that it will be useful, 8 | but WITHOUT ANY WARRANTY; without even the implied warranty of 9 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 10 | GNU General Public License for more details. 11 | 12 | You should have received a copy of the GNU General Public License 13 | along with this program; if not, write to the Free Software 14 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ 15 | 16 | 17 | #ifndef _typelib_h 18 | #define _typelib_h 19 | 20 | #include "my_alloc.h" 21 | 22 | typedef struct st_typelib { /* Different types saved here */ 23 | unsigned int count; /* How many types */ 24 | const char *name; /* Name of typelib */ 25 | const char **type_names; 26 | unsigned int *type_lengths; 27 | } TYPELIB; 28 | 29 | extern int find_type(char *x,TYPELIB *typelib,unsigned int full_name); 30 | extern void make_type(char *to,unsigned int nr,TYPELIB *typelib); 31 | extern const char *get_type(TYPELIB *typelib,unsigned int nr); 32 | extern TYPELIB *copy_typelib(MEM_ROOT *root, TYPELIB *from); 33 | 34 | extern TYPELIB sql_protocol_typelib; 35 | 36 | #endif /* _typelib_h */ 37 | -------------------------------------------------------------------------------- /cpp/3rdparty/mysql/libmysql.a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/digitalbazaar/monarch/59ddda30fd462778b97379be36bb76f391967a46/cpp/3rdparty/mysql/libmysql.a -------------------------------------------------------------------------------- /cpp/3rdparty/mysql/libmysql.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/digitalbazaar/monarch/59ddda30fd462778b97379be36bb76f391967a46/cpp/3rdparty/mysql/libmysql.dll -------------------------------------------------------------------------------- /cpp/3rdparty/mysql/libmysql.lib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/digitalbazaar/monarch/59ddda30fd462778b97379be36bb76f391967a46/cpp/3rdparty/mysql/libmysql.lib -------------------------------------------------------------------------------- /cpp/3rdparty/mysql/mysys.lib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/digitalbazaar/monarch/59ddda30fd462778b97379be36bb76f391967a46/cpp/3rdparty/mysql/mysys.lib -------------------------------------------------------------------------------- /cpp/3rdparty/mysql/regex.lib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/digitalbazaar/monarch/59ddda30fd462778b97379be36bb76f391967a46/cpp/3rdparty/mysql/regex.lib -------------------------------------------------------------------------------- /cpp/3rdparty/mysql/strings.lib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/digitalbazaar/monarch/59ddda30fd462778b97379be36bb76f391967a46/cpp/3rdparty/mysql/strings.lib -------------------------------------------------------------------------------- /cpp/3rdparty/mysql/zlib.lib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/digitalbazaar/monarch/59ddda30fd462778b97379be36bb76f391967a46/cpp/3rdparty/mysql/zlib.lib -------------------------------------------------------------------------------- /cpp/3rdparty/openssl/include/openssl/ebcdic.h: -------------------------------------------------------------------------------- 1 | /* crypto/ebcdic.h */ 2 | 3 | #ifndef HEADER_EBCDIC_H 4 | #define HEADER_EBCDIC_H 5 | 6 | #include 7 | 8 | /* Avoid name clashes with other applications */ 9 | #define os_toascii _openssl_os_toascii 10 | #define os_toebcdic _openssl_os_toebcdic 11 | #define ebcdic2ascii _openssl_ebcdic2ascii 12 | #define ascii2ebcdic _openssl_ascii2ebcdic 13 | 14 | extern const unsigned char os_toascii[256]; 15 | extern const unsigned char os_toebcdic[256]; 16 | void *ebcdic2ascii(void *dest, const void *srce, size_t count); 17 | void *ascii2ebcdic(void *dest, const void *srce, size_t count); 18 | 19 | #endif 20 | -------------------------------------------------------------------------------- /cpp/3rdparty/openssl/libeay32.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/digitalbazaar/monarch/59ddda30fd462778b97379be36bb76f391967a46/cpp/3rdparty/openssl/libeay32.dll -------------------------------------------------------------------------------- /cpp/3rdparty/openssl/ssleay32.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/digitalbazaar/monarch/59ddda30fd462778b97379be36bb76f391967a46/cpp/3rdparty/openssl/ssleay32.dll -------------------------------------------------------------------------------- /cpp/3rdparty/pthread/libpthreadGC2.a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/digitalbazaar/monarch/59ddda30fd462778b97379be36bb76f391967a46/cpp/3rdparty/pthread/libpthreadGC2.a -------------------------------------------------------------------------------- /cpp/3rdparty/pthread/libpthreadGCE2.a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/digitalbazaar/monarch/59ddda30fd462778b97379be36bb76f391967a46/cpp/3rdparty/pthread/libpthreadGCE2.a -------------------------------------------------------------------------------- /cpp/3rdparty/pthread/pthreadGC2.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/digitalbazaar/monarch/59ddda30fd462778b97379be36bb76f391967a46/cpp/3rdparty/pthread/pthreadGC2.dll -------------------------------------------------------------------------------- /cpp/3rdparty/pthread/pthreadGCE2.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/digitalbazaar/monarch/59ddda30fd462778b97379be36bb76f391967a46/cpp/3rdparty/pthread/pthreadGCE2.dll -------------------------------------------------------------------------------- /cpp/3rdparty/pthread/pthreadVC2.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/digitalbazaar/monarch/59ddda30fd462778b97379be36bb76f391967a46/cpp/3rdparty/pthread/pthreadVC2.dll -------------------------------------------------------------------------------- /cpp/3rdparty/pthread/pthreadVC2.lib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/digitalbazaar/monarch/59ddda30fd462778b97379be36bb76f391967a46/cpp/3rdparty/pthread/pthreadVC2.lib -------------------------------------------------------------------------------- /cpp/3rdparty/pthread/pthreadVCE2.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/digitalbazaar/monarch/59ddda30fd462778b97379be36bb76f391967a46/cpp/3rdparty/pthread/pthreadVCE2.dll -------------------------------------------------------------------------------- /cpp/3rdparty/pthread/pthreadVCE2.lib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/digitalbazaar/monarch/59ddda30fd462778b97379be36bb76f391967a46/cpp/3rdparty/pthread/pthreadVCE2.lib -------------------------------------------------------------------------------- /cpp/3rdparty/pthread/pthreadVSE2.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/digitalbazaar/monarch/59ddda30fd462778b97379be36bb76f391967a46/cpp/3rdparty/pthread/pthreadVSE2.dll -------------------------------------------------------------------------------- /cpp/3rdparty/pthread/pthreadVSE2.lib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/digitalbazaar/monarch/59ddda30fd462778b97379be36bb76f391967a46/cpp/3rdparty/pthread/pthreadVSE2.lib -------------------------------------------------------------------------------- /cpp/3rdparty/regex/libgnurx-0.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/digitalbazaar/monarch/59ddda30fd462778b97379be36bb76f391967a46/cpp/3rdparty/regex/libgnurx-0.dll -------------------------------------------------------------------------------- /cpp/3rdparty/regex/libregex.a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/digitalbazaar/monarch/59ddda30fd462778b97379be36bb76f391967a46/cpp/3rdparty/regex/libregex.a -------------------------------------------------------------------------------- /cpp/3rdparty/sqlite3/sqlite3.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/digitalbazaar/monarch/59ddda30fd462778b97379be36bb76f391967a46/cpp/3rdparty/sqlite3/sqlite3.dll -------------------------------------------------------------------------------- /cpp/3rdparty/zlib/libz.a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/digitalbazaar/monarch/59ddda30fd462778b97379be36bb76f391967a46/cpp/3rdparty/zlib/libz.a -------------------------------------------------------------------------------- /cpp/3rdparty/zlib/libz.dll.a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/digitalbazaar/monarch/59ddda30fd462778b97379be36bb76f391967a46/cpp/3rdparty/zlib/libz.dll.a -------------------------------------------------------------------------------- /cpp/3rdparty/zlib/mgwz.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/digitalbazaar/monarch/59ddda30fd462778b97379be36bb76f391967a46/cpp/3rdparty/zlib/mgwz.dll -------------------------------------------------------------------------------- /cpp/app/AppFactory.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2010 Digital Bazaar, Inc. All rights reserved. 3 | */ 4 | #include "monarch/app/AppFactory.h" 5 | 6 | using namespace std; 7 | using namespace monarch::app; 8 | using namespace monarch::config; 9 | using namespace monarch::kernel; 10 | using namespace monarch::modest; 11 | using namespace monarch::rt; 12 | 13 | AppFactory::AppFactory(const char* name, const char* version) : 14 | MicroKernelModule(name, version), 15 | mMicroKernel(NULL) 16 | { 17 | mInfo["name"] = name; 18 | mInfo["version"] = version; 19 | mInfo["type"] = "monarch.app.AppFactory"; 20 | mInfo["dependencies"]->setType(Array); 21 | } 22 | 23 | AppFactory::~AppFactory() 24 | { 25 | } 26 | 27 | void AppFactory::addDependency(const char* name, const char* version) 28 | { 29 | DynamicObject dep; 30 | dep["name"] = name; 31 | dep["version"] = version; 32 | mInfo["dependencies"]->append(dep); 33 | } 34 | 35 | DynamicObject AppFactory::getDependencyInfo() 36 | { 37 | return mInfo; 38 | } 39 | 40 | bool AppFactory::initialize(MicroKernel* k) 41 | { 42 | mMicroKernel = k; 43 | return true; 44 | } 45 | 46 | void AppFactory::cleanup(MicroKernel* k) 47 | { 48 | } 49 | 50 | MicroKernelModuleApi* AppFactory::getApi(MicroKernel* k) 51 | { 52 | return this; 53 | } 54 | 55 | void AppFactory::destroyApp(App* app) 56 | { 57 | delete app; 58 | } 59 | 60 | void monarch::app::freeAppFactory(Module* m) 61 | { 62 | delete m; 63 | } 64 | -------------------------------------------------------------------------------- /cpp/app/Makefile.in: -------------------------------------------------------------------------------- 1 | # Makefile to compile the module in this directory 2 | 3 | LIBRARIES = moapp 4 | moapp_HEADERS = $(wildcard *.h) 5 | moapp_SOURCES = $(wildcard *.cpp) 6 | 7 | DYNAMIC_LINK_LIBRARIES = mort mologging moio mocrypto monet modata moutil moconfig mokernel moevent mofiber 8 | 9 | DYNAMIC_MACOS_LINK_LIBRARIES = crypto ssl momodest mocompress movalidation 10 | DYNAMIC_WINDOWS_LINK_LIBRARIES = pthreadGCE2 mgwz libgnurx-0 libeay32 ssleay32 ws2_32 momodest mocompress movalidation 11 | 12 | # ----------- Standard Makefile 13 | include @MONARCH_DIR@/setup/Makefile.base 14 | -------------------------------------------------------------------------------- /cpp/apps/js/Makefile.in: -------------------------------------------------------------------------------- 1 | # Makefile to compile the module in this directory 2 | 3 | ifeq (@BUILD_V8@,yes) 4 | MODULES = mojs 5 | mojs_HEADERS = $(wildcard *.h) 6 | mojs_SOURCES = $(wildcard *.cpp) 7 | mojs_MOD_DIR = apps 8 | 9 | HEADER_DIST_DIR = dist/include/monarch/apps/js 10 | 11 | DYNAMIC_LINK_LIBRARIES = mort modata moapp moconfig 12 | 13 | DYNAMIC_MACOS_LINK_LIBRARIES = mofiber moio moutil mologging monet mocompress momodest moevent mocrypto movalidation mokernel moapp 14 | DYNAMIC_WINDOWS_LINK_LIBRARIES = mofiber moio moutil mologging monet mocompress momodest moevent mocrypto movalidation mokernel moapp 15 | 16 | endif 17 | 18 | # ----------- Standard Makefile 19 | include @MONARCH_DIR@/setup/Makefile.base 20 | -------------------------------------------------------------------------------- /cpp/apps/monarch/Makefile.in: -------------------------------------------------------------------------------- 1 | # Makefile to compile the module in this directory 2 | 3 | EXECUTABLES = monarch 4 | 5 | DYNAMIC_LINK_LIBRARIES = mort momodest moutil moio mologging mocrypto monet mohttp modata moevent mofiber mosql mosqlite3 moconfig mocompress movalidation moapp moupnp mokernel 6 | 7 | DYNAMIC_LINUX_LINK_LIBRARIES = pthread crypto ssl expat sqlite3 8 | DYNAMIC_WINDOWS_LINK_LIBRARIES = sqlite3 9 | DYNAMIC_WINDOWS_EXECUTABLE_LIBRARIES = pthreadGCE2 libeay32 ssleay32 libexpat ws2_32 10 | 11 | # ----------- Standard Makefile 12 | include @MONARCH_DIR@/setup/Makefile.base 13 | -------------------------------------------------------------------------------- /cpp/apps/monarch/monarch.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2010 Digital Bazaar, Inc. All rights reserved. 3 | */ 4 | #include "monarch/app/AppRunner.h" 5 | 6 | /** 7 | * Runs the Top-level Monarch AppRunner. 8 | * 9 | * @param argc number of command line args. 10 | * @param argv command line args. 11 | * 12 | * @return exit status. 0 for success. 13 | */ 14 | int main(int argc, const char* argv[]) 15 | { 16 | return monarch::app::AppRunner::main(argc, argv); 17 | } 18 | -------------------------------------------------------------------------------- /cpp/apps/portmap/Makefile.in: -------------------------------------------------------------------------------- 1 | # Makefile to compile the module in this directory 2 | 3 | MODULES = moportmap 4 | moportmap_HEADERS = $(wildcard *.h) 5 | moportmap_SOURCES = $(wildcard *.cpp) 6 | moportmap_MOD_DIR = apps 7 | 8 | DYNAMIC_LINK_LIBRARIES = mort moutil 9 | 10 | DYNAMIC_MACOS_LINK_LIBRARIES = momodest mofiber moio moevent moconfig mocrypto mocompress monet mohttp mologging movalidation mokernel modata moupnp moapp 11 | DYNAMIC_WINDOWS_LINK_LIBRARIES = momodest mofiber moio moevent moconfig mocrypto mocompress monet mohttp mologging movalidation mokernel modata moupnp moapp 12 | 13 | # ----------- Standard Makefile 14 | include @MONARCH_DIR@/setup/Makefile.base 15 | -------------------------------------------------------------------------------- /cpp/apps/rdfa2jsonld/Makefile.in: -------------------------------------------------------------------------------- 1 | # Makefile to compile the module in this directory 2 | 3 | ifeq (@HAVE_LIBRDFA@,yes) 4 | MODULES = mordfa2jsonld 5 | mordfa2jsonld_HEADERS = $(wildcard *.h) 6 | mordfa2jsonld_SOURCES = $(wildcard *.cpp) 7 | mordfa2jsonld_MOD_DIR = apps 8 | 9 | DYNAMIC_LINK_LIBRARIES = mort moutil modata mocrypto mologging 10 | 11 | DYNAMIC_MACOS_LINK_LIBRARIES = momodest mofiber moio moconfig mokernel moapp 12 | DYNAMIC_WINDOWS_LINK_LIBRARIES = momodest mofiber moio moconfig mokernel moapp 13 | endif 14 | 15 | # ----------- Standard Makefile 16 | include @MONARCH_DIR@/setup/Makefile.base 17 | -------------------------------------------------------------------------------- /cpp/apps/tester/Makefile.in: -------------------------------------------------------------------------------- 1 | # Makefile to compile the module in this directory 2 | 3 | MODULES = motester 4 | motester_HEADERS = $(wildcard *.h) 5 | motester_SOURCES = $(wildcard *.cpp) 6 | motester_MOD_DIR = apps 7 | 8 | HEADER_DIST_DIR = dist/include/monarch/apps/tester 9 | 10 | DYNAMIC_LINK_LIBRARIES = mort modata moapp moconfig motest 11 | 12 | DYNAMIC_MACOS_LINK_LIBRARIES = mofiber moio moutil mologging monet mocompress momodest moevent mocrypto movalidation mokernel moapp 13 | DYNAMIC_WINDOWS_LINK_LIBRARIES = mofiber moio moutil mologging monet mocompress momodest moevent mocrypto movalidation mokernel moapp 14 | 15 | # ----------- Standard Makefile 16 | include @MONARCH_DIR@/setup/Makefile.base 17 | -------------------------------------------------------------------------------- /cpp/compress/Makefile.in: -------------------------------------------------------------------------------- 1 | # Makefile to compile the module in this directory 2 | 3 | LIBRARIES = mocompress 4 | mocompress_HEADERS = \ 5 | $(wildcard *.h) \ 6 | $(wildcard deflate/*.h) \ 7 | $(wildcard gzip/*.h) \ 8 | $(wildcard zip/*.h) 9 | mocompress_SOURCES = \ 10 | $(wildcard *.cpp) \ 11 | $(wildcard deflate/*.cpp) \ 12 | $(wildcard gzip/*.cpp) \ 13 | $(wildcard zip/*.cpp) 14 | 15 | DYNAMIC_LINK_LIBRARIES = mort moio moutil 16 | 17 | DYNAMIC_LINUX_LINK_LIBRARIES = z 18 | DYNAMIC_MACOS_LINK_LIBRARIES = z 19 | DYNAMIC_WINDOWS_LINK_LIBRARIES = mgwz 20 | 21 | # ----------- Standard Makefile 22 | include @MONARCH_DIR@/setup/Makefile.base 23 | -------------------------------------------------------------------------------- /cpp/compress/gzip/Trailer.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2008-2009 Digital Bazaar, Inc. All rights reserved. 3 | */ 4 | #define __STDC_CONSTANT_MACROS 5 | 6 | #include "monarch/compress/gzip/Trailer.h" 7 | 8 | #include "monarch/util/Data.h" 9 | #include 10 | 11 | using namespace monarch::compress::gzip; 12 | using namespace monarch::io; 13 | 14 | Trailer::Trailer() 15 | { 16 | mCrc32 = 0; 17 | mInputSize = 0; 18 | } 19 | 20 | Trailer::~Trailer() 21 | { 22 | } 23 | 24 | int Trailer::convertFromBytes(char* b, int length) 25 | { 26 | int rval = 0; 27 | 28 | // make sure there are at least 8 bytes available -- the trailer size 29 | if(length < 8) 30 | { 31 | rval = 8 - length; 32 | } 33 | else 34 | { 35 | // wrap input in a ByteBuffer 36 | ByteBuffer bb(b, 0, length, length, false); 37 | 38 | // read crc-32 39 | bb.get((char*)&mCrc32, 4); 40 | mCrc32 = MO_UINT32_FROM_LE(mCrc32); 41 | 42 | // read input size 43 | bb.get((char*)&mInputSize, 4); 44 | mInputSize = MO_UINT32_FROM_LE(mInputSize); 45 | } 46 | 47 | return rval; 48 | } 49 | 50 | void Trailer::convertToBytes(ByteBuffer* b) 51 | { 52 | // write crc-32 and input size 53 | uint32_t crc32 = MO_UINT32_TO_LE(mCrc32); 54 | uint32_t isize = MO_UINT32_TO_LE(mInputSize); 55 | b->put((char*)&crc32, 4, true); 56 | b->put((char*)&isize, 4, true); 57 | } 58 | 59 | void Trailer::setCrc32(unsigned int crc) 60 | { 61 | mCrc32 = crc; 62 | } 63 | 64 | unsigned int Trailer::getCrc32() 65 | { 66 | return mCrc32; 67 | } 68 | 69 | void Trailer::setInputSize(unsigned int iSize) 70 | { 71 | mInputSize = iSize; 72 | } 73 | 74 | unsigned int Trailer::getInputSize() 75 | { 76 | return mInputSize; 77 | } 78 | -------------------------------------------------------------------------------- /cpp/config/Makefile.in: -------------------------------------------------------------------------------- 1 | # Makefile to compile the module in this directory 2 | 3 | LIBRARIES = moconfig 4 | moconfig_HEADERS = $(wildcard *.h) 5 | moconfig_SOURCES = $(wildcard *.cpp) 6 | 7 | DYNAMIC_LINK_LIBRARIES = mort moutil moio modata mologging 8 | 9 | DYNAMIC_MACOS_LINK_LIBRARIES = mocompress monet momodest mocrypto 10 | 11 | # ----------- Standard Makefile 12 | include @MONARCH_DIR@/setup/Makefile.base 13 | 14 | -------------------------------------------------------------------------------- /cpp/crypto/AbstractBlockCipher.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2007-2011 Digital Bazaar, Inc. All rights reserved. 3 | */ 4 | #include "monarch/crypto/AbstractBlockCipher.h" 5 | 6 | #include "monarch/rt/Exception.h" 7 | 8 | #include 9 | 10 | using namespace monarch::crypto; 11 | using namespace monarch::rt; 12 | 13 | AbstractBlockCipher::AbstractBlockCipher(bool encrypt) : 14 | mEncryptMode(encrypt), 15 | mInputBytes(0), 16 | mOutputBytes(0), 17 | mCipherFunction(NULL) 18 | { 19 | // initialize the cipher context 20 | EVP_CIPHER_CTX_init(&mCipherContext); 21 | } 22 | 23 | AbstractBlockCipher::~AbstractBlockCipher() 24 | { 25 | // clean up the cipher context 26 | EVP_CIPHER_CTX_cleanup(&mCipherContext); 27 | } 28 | 29 | const EVP_CIPHER* AbstractBlockCipher::getCipherFunction(const char* algorithm) 30 | { 31 | const EVP_CIPHER* rval = NULL; 32 | 33 | if(strcmp(algorithm, "AES") == 0 || strcmp(algorithm, "AES256") == 0) 34 | { 35 | rval = EVP_aes_256_cbc(); 36 | } 37 | else if(strcmp(algorithm, "AES128") == 0) 38 | { 39 | rval = EVP_aes_128_cbc(); 40 | } 41 | else if(strcmp(algorithm, "3DES") == 0) 42 | { 43 | rval = EVP_des_ede3_cbc(); 44 | } 45 | else 46 | { 47 | ExceptionRef e = new Exception( 48 | "Unsupported key algorithm", "monarch.crypto.UnsupportedAlgorithm"); 49 | e->getDetails()["algorithm"] = algorithm; 50 | Exception::set(e); 51 | } 52 | 53 | return rval; 54 | } 55 | 56 | unsigned int AbstractBlockCipher::getBlockSize() 57 | { 58 | return EVP_CIPHER_CTX_block_size(&mCipherContext); 59 | } 60 | 61 | bool AbstractBlockCipher::isEncryptEnabled() 62 | { 63 | return mEncryptMode; 64 | } 65 | -------------------------------------------------------------------------------- /cpp/crypto/AsymmetricKey.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2007-2009 Digital Bazaar, Inc. All rights reserved. 3 | */ 4 | #include "monarch/crypto/AsymmetricKey.h" 5 | 6 | using namespace std; 7 | using namespace monarch::crypto; 8 | 9 | AsymmetricKey::AsymmetricKey(EVP_PKEY* pkey) : 10 | mKey(pkey) 11 | { 12 | } 13 | 14 | AsymmetricKey::~AsymmetricKey() 15 | { 16 | // free the public/private key structure 17 | EVP_PKEY_free(mKey); 18 | } 19 | 20 | EVP_PKEY* AsymmetricKey::getPKEY() 21 | { 22 | return mKey; 23 | } 24 | 25 | const char* AsymmetricKey::getAlgorithm() 26 | { 27 | const char* rval; 28 | 29 | switch(EVP_PKEY_type(getPKEY()->type)) 30 | { 31 | case EVP_PKEY_DSA: 32 | rval = "DSA"; 33 | break; 34 | case EVP_PKEY_RSA: 35 | rval = "RSA"; 36 | break; 37 | default: 38 | rval = "UNKNOWN"; 39 | } 40 | 41 | return rval; 42 | } 43 | 44 | unsigned int AsymmetricKey::getOutputSize() 45 | { 46 | return EVP_PKEY_size(getPKEY()); 47 | } 48 | -------------------------------------------------------------------------------- /cpp/crypto/BlockCipher.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2007-2009 Digital Bazaar, Inc. All rights reserved. 3 | */ 4 | #include "monarch/crypto/BlockCipher.h" 5 | 6 | using namespace monarch::io; 7 | using namespace monarch::crypto; 8 | 9 | BlockCipher::BlockCipher() 10 | { 11 | } 12 | 13 | BlockCipher::~BlockCipher() 14 | { 15 | } 16 | 17 | bool BlockCipher::update( 18 | const char* in, int inLength, ByteBuffer* out, bool resize) 19 | { 20 | bool rval = false; 21 | 22 | // allocate space for data 23 | out->allocateSpace(inLength + getBlockSize(), resize); 24 | 25 | // do update 26 | int length; 27 | if(update(in, inLength, out->end(), length)) 28 | { 29 | // extend buffer length 30 | out->extend(length); 31 | rval = true; 32 | } 33 | 34 | return rval; 35 | } 36 | 37 | bool BlockCipher::finish(ByteBuffer* out, bool resize) 38 | { 39 | bool rval = false; 40 | 41 | // allocate space for data 42 | out->allocateSpace(getBlockSize(), resize); 43 | 44 | // do finish 45 | int length; 46 | if(finish(out->end(), length)) 47 | { 48 | // extend buffer length 49 | out->extend(length); 50 | rval = true; 51 | } 52 | 53 | return rval; 54 | } 55 | -------------------------------------------------------------------------------- /cpp/crypto/CryptoHashAlgorithm.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2007-2009 Digital Bazaar, Inc. All rights reserved. 3 | */ 4 | #include "monarch/crypto/CryptoHashAlgorithm.h" 5 | 6 | using namespace monarch::crypto; 7 | 8 | CryptoHashAlgorithm::CryptoHashAlgorithm() : 9 | mHashFunction(NULL) 10 | { 11 | // initialize the message digest context 12 | EVP_MD_CTX_init(&mMessageDigestContext); 13 | } 14 | 15 | CryptoHashAlgorithm::~CryptoHashAlgorithm() 16 | { 17 | // clean up the message digest context 18 | EVP_MD_CTX_cleanup(&mMessageDigestContext); 19 | } 20 | -------------------------------------------------------------------------------- /cpp/crypto/CryptoHashAlgorithm.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2007-2010 Digital Bazaar, Inc. All rights reserved. 3 | */ 4 | #ifndef monarch_crypto_CryptoHashAlgorithm_H 5 | #define monarch_crypto_CryptoHashAlgorithm_H 6 | 7 | #include "monarch/util/HashAlgorithm.h" 8 | 9 | #include 10 | 11 | namespace monarch 12 | { 13 | namespace crypto 14 | { 15 | 16 | /** 17 | * The CryptoHashAlgorithm class provides an abstract base class for 18 | * cryptographic HashAlgorithms. It uses OpenSSL's implementations for 19 | * crypographic hash algorithms. 20 | * 21 | * @author Dave Longley 22 | */ 23 | class CryptoHashAlgorithm : public monarch::util::HashAlgorithm 24 | { 25 | protected: 26 | /** 27 | * The message digest context. 28 | */ 29 | EVP_MD_CTX mMessageDigestContext; 30 | 31 | /** 32 | * A pointer to the hash function. 33 | */ 34 | const EVP_MD* mHashFunction; 35 | 36 | public: 37 | /** 38 | * Creates a new CryptoHashAlgorithm. 39 | */ 40 | CryptoHashAlgorithm(); 41 | 42 | /** 43 | * Destructs this CryptoHashAlgorithm. 44 | */ 45 | virtual ~CryptoHashAlgorithm(); 46 | 47 | protected: 48 | /** 49 | * Gets the hash function for this algorithm. 50 | * 51 | * @return the hash function to use. 52 | */ 53 | virtual const EVP_MD* getHashFunction() = 0; 54 | }; 55 | 56 | } // end namespace crypto 57 | } // end namespace monarch 58 | #endif 59 | -------------------------------------------------------------------------------- /cpp/crypto/DigitalSignatureInputStream.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2007-2011 Digital Bazaar, Inc. All rights reserved. 3 | */ 4 | #include "monarch/crypto/DigitalSignatureInputStream.h" 5 | 6 | using namespace monarch::crypto; 7 | using namespace monarch::io; 8 | 9 | DigitalSignatureInputStream::DigitalSignatureInputStream( 10 | DigitalSignature* ds, bool cleanupSignature, 11 | InputStream* os, bool cleanupStream) : 12 | FilterInputStream(os, cleanupStream), 13 | mSignature(ds), 14 | mCleanupSignature(cleanupSignature) 15 | { 16 | } 17 | 18 | DigitalSignatureInputStream::~DigitalSignatureInputStream() 19 | { 20 | if(mCleanupSignature) 21 | { 22 | delete mSignature; 23 | } 24 | } 25 | 26 | int DigitalSignatureInputStream::read(char* b, int length) 27 | { 28 | // read from underlying stream 29 | int rval = FilterInputStream::read(b, length); 30 | 31 | if(rval > 0 && mSignature != NULL) 32 | { 33 | // update digital signature 34 | mSignature->update(b, rval); 35 | } 36 | 37 | return rval; 38 | } 39 | 40 | void DigitalSignatureInputStream::setSignature( 41 | DigitalSignature* ds, bool cleanup) 42 | { 43 | if(mCleanupSignature) 44 | { 45 | delete mSignature; 46 | } 47 | 48 | mSignature = ds; 49 | mCleanupSignature = cleanup; 50 | } 51 | 52 | DigitalSignature* DigitalSignatureInputStream::getSignature() 53 | { 54 | return mSignature; 55 | } 56 | -------------------------------------------------------------------------------- /cpp/crypto/DigitalSignatureOutputStream.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2007-2011 Digital Bazaar, Inc. All rights reserved. 3 | */ 4 | #include "monarch/crypto/DigitalSignatureOutputStream.h" 5 | 6 | using namespace monarch::crypto; 7 | using namespace monarch::io; 8 | 9 | DigitalSignatureOutputStream::DigitalSignatureOutputStream( 10 | DigitalSignature* ds, bool cleanupSignature, 11 | OutputStream* os, bool cleanupStream) : 12 | FilterOutputStream(os, cleanupStream), 13 | mSignature(ds), 14 | mCleanupSignature(cleanupSignature) 15 | { 16 | } 17 | 18 | DigitalSignatureOutputStream::~DigitalSignatureOutputStream() 19 | { 20 | if(mCleanupSignature) 21 | { 22 | delete mSignature; 23 | } 24 | } 25 | 26 | bool DigitalSignatureOutputStream::write(const char* b, int length) 27 | { 28 | if(mSignature != NULL) 29 | { 30 | // update digital signature 31 | mSignature->update(b, length); 32 | } 33 | 34 | // write to underlying stream 35 | return FilterOutputStream::write(b, length); 36 | } 37 | 38 | void DigitalSignatureOutputStream::setSignature( 39 | DigitalSignature* ds, bool cleanup) 40 | { 41 | if(mCleanupSignature) 42 | { 43 | delete mSignature; 44 | } 45 | 46 | mSignature = ds; 47 | mCleanupSignature = cleanup; 48 | } 49 | 50 | DigitalSignature* DigitalSignatureOutputStream::getSignature() 51 | { 52 | return mSignature; 53 | } 54 | -------------------------------------------------------------------------------- /cpp/crypto/Makefile.in: -------------------------------------------------------------------------------- 1 | # Makefile to compile the module in this directory 2 | 3 | LIBRARIES = mocrypto 4 | mocrypto_HEADERS = $(wildcard *.h) 5 | mocrypto_SOURCES = $(wildcard *.cpp) 6 | 7 | DYNAMIC_LINK_LIBRARIES = mort moutil moio 8 | 9 | DYNAMIC_LINUX_LINK_LIBRARIES = crypto 10 | DYNAMIC_MACOS_LINK_LIBRARIES = crypto ssl 11 | DYNAMIC_WINDOWS_LINK_LIBRARIES = libeay32 12 | 13 | # ----------- Standard Makefile 14 | include @MONARCH_DIR@/setup/Makefile.base 15 | 16 | -------------------------------------------------------------------------------- /cpp/crypto/SymmetricKeyFactory.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2007-2009 Digital Bazaar, Inc. All rights reserved. 3 | */ 4 | #ifndef monarch_crypto_SymmetricKeyFactory_H 5 | #define monarch_crypto_SymmetricKeyFactory_H 6 | 7 | #include "monarch/crypto/SymmetricKey.h" 8 | 9 | namespace monarch 10 | { 11 | namespace crypto 12 | { 13 | 14 | /** 15 | * A SymmetricKeyFactory is used to create symmetric cryptographic keys. 16 | * 17 | * @author Dave Longley 18 | */ 19 | class SymmetricKeyFactory 20 | { 21 | protected: 22 | /** 23 | * Creates a random key using the passed algorithm. 24 | * 25 | * @param algorithm the algorithm for the key. 26 | * @param key a pointer to a SymmetricKey to populate. 27 | * 28 | * @return true if no exception occurred, false if not. 29 | */ 30 | bool createRandomKey(const char* algorithm, SymmetricKey* key); 31 | 32 | public: 33 | /** 34 | * Creates a new SymmetricKeyFactory. 35 | */ 36 | SymmetricKeyFactory(); 37 | 38 | /** 39 | * Destructs this SymmetricKeyFactory. 40 | */ 41 | virtual ~SymmetricKeyFactory(); 42 | 43 | /** 44 | * Creates a new random key using the given algorithm. 45 | * 46 | * @param algorithm the algorithm to use. 47 | * @param key a pointer to a SymmetricKey to populate. 48 | * 49 | * @return true if no exception occurred, false if not. 50 | */ 51 | bool createKey(const char* algorithm, SymmetricKey* key); 52 | }; 53 | 54 | } // end namespace crypto 55 | } // end namespace monarch 56 | #endif 57 | -------------------------------------------------------------------------------- /cpp/data/DynamicObjectInputStream.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2008-2011 Digital Bazaar, Inc. All rights reserved. 3 | */ 4 | #include "monarch/data/DynamicObjectInputStream.h" 5 | 6 | #include "monarch/io/ByteArrayOutputStream.h" 7 | 8 | using namespace monarch::data; 9 | using namespace monarch::io; 10 | using namespace monarch::rt; 11 | 12 | DynamicObjectInputStream::DynamicObjectInputStream( 13 | DynamicObject& dyno, DynamicObjectWriter* writer, bool cleanup) : 14 | mHasData(false), 15 | mDyno(dyno), 16 | mWriter(writer), 17 | mCleanupWriter(cleanup), 18 | mBufferInputStream(NULL, 0) 19 | { 20 | } 21 | 22 | DynamicObjectInputStream::~DynamicObjectInputStream() 23 | { 24 | if(mCleanupWriter) 25 | { 26 | delete mWriter; 27 | } 28 | } 29 | 30 | int DynamicObjectInputStream::read(char* b, int length) 31 | { 32 | int rval = 0; 33 | 34 | if(!mHasData) 35 | { 36 | // do full serialization into buffer 37 | ByteArrayOutputStream baos(&mBuffer, true); 38 | if(mWriter->write(mDyno, &baos)) 39 | { 40 | mBufferInputStream.setByteArray(mBuffer.data(), mBuffer.length()); 41 | mHasData = true; 42 | } 43 | else 44 | { 45 | rval = -1; 46 | } 47 | } 48 | 49 | if(rval == 0) 50 | { 51 | // Conversion done, just feed more data out 52 | rval = mBufferInputStream.read(b, length); 53 | } 54 | 55 | return rval; 56 | } 57 | 58 | DynamicObjectWriter* DynamicObjectInputStream::getWriter() 59 | { 60 | return mWriter; 61 | } 62 | -------------------------------------------------------------------------------- /cpp/data/DynamicObjectOutputStream.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2008-2011 Digital Bazaar, Inc. All rights reserved. 3 | */ 4 | #include "monarch/data/DynamicObjectOutputStream.h" 5 | 6 | using namespace monarch::data; 7 | using namespace monarch::io; 8 | using namespace monarch::rt; 9 | 10 | DynamicObjectOutputStream::DynamicObjectOutputStream( 11 | DynamicObject& dyno, DynamicObjectReader* reader, bool cleanup) : 12 | mReader(reader), 13 | mCleanupReader(cleanup), 14 | mInputStream(NULL, 0) 15 | { 16 | // start DynamicObjectReader 17 | mReader->start(dyno); 18 | } 19 | 20 | DynamicObjectOutputStream::~DynamicObjectOutputStream() 21 | { 22 | if(mCleanupReader) 23 | { 24 | delete mReader; 25 | } 26 | } 27 | 28 | bool DynamicObjectOutputStream::write(const char* b, int length) 29 | { 30 | // set input stream byte array 31 | mInputStream.setByteArray(b, length); 32 | 33 | // use reader 34 | return mReader->read(&mInputStream); 35 | } 36 | 37 | void DynamicObjectOutputStream::close() 38 | { 39 | // finish reader 40 | mReader->finish(); 41 | } 42 | -------------------------------------------------------------------------------- /cpp/data/DynamicObjectWriter.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2007-2009 Digital Bazaar, Inc. All rights reserved. 3 | */ 4 | #ifndef monarch_data_DynamicObjectWriter_H 5 | #define monarch_data_DynamicObjectWriter_H 6 | 7 | #include "monarch/io/OutputStream.h" 8 | #include "monarch/rt/DynamicObject.h" 9 | 10 | namespace monarch 11 | { 12 | namespace data 13 | { 14 | 15 | /** 16 | * A DynamicObjectWriter writes a DynamicObject to an OutputStream in a 17 | * particular data format. 18 | * 19 | * @author Dave Longley 20 | */ 21 | class DynamicObjectWriter 22 | { 23 | public: 24 | /** 25 | * Creates a new DynamicObjectWriter. 26 | */ 27 | DynamicObjectWriter() {}; 28 | 29 | /** 30 | * Destructs this DynamicObjectWriter. 31 | */ 32 | virtual ~DynamicObjectWriter() {}; 33 | 34 | /** 35 | * Serializes the passed DynamicObject. 36 | * 37 | * @param dyno the DynamicObject to serialize. 38 | * @param os the OutputStream to write the serialized data to. 39 | * 40 | * @return true if successful, false if an exception occurred. 41 | */ 42 | virtual bool write( 43 | monarch::rt::DynamicObject& dyno, monarch::io::OutputStream* os) = 0; 44 | 45 | /** 46 | * Sets the starting indentation level and the number of spaces 47 | * per indentation level. 48 | * 49 | * @param level the starting indentation level. 50 | * @param spaces the number of spaces per indentation level. 51 | */ 52 | virtual void setIndentation(int level, int spaces) = 0; 53 | 54 | /** 55 | * Sets option to minimize whitespace. 56 | * 57 | * @param compact minimize whitespace. 58 | */ 59 | virtual void setCompact(bool compact) = 0; 60 | }; 61 | 62 | } // end namespace data 63 | } // end namespace monarch 64 | #endif 65 | -------------------------------------------------------------------------------- /cpp/data/Makefile.in: -------------------------------------------------------------------------------- 1 | # Makefile to compile the module in this directory 2 | 3 | LIBRARIES = modata 4 | 5 | ifeq (@HAVE_LIBRDFA@,yes) 6 | rdfa_HEADERS = $(wildcard rdfa/*.h) 7 | rdfa_SOURCES = $(wildcard rdfa/*.cpp) 8 | endif 9 | 10 | modata_HEADERS = \ 11 | $(wildcard *.h) \ 12 | $(wildcard avi/*.h) \ 13 | $(wildcard id3v2/*.h) \ 14 | $(wildcard json/*.h) \ 15 | $(wildcard mpeg/*.h) \ 16 | $(wildcard pdf/*.h) \ 17 | $(rdfa_HEADERS) \ 18 | $(wildcard riff/*.h) \ 19 | $(wildcard xml/*.h) 20 | modata_SOURCES = \ 21 | $(wildcard *.cpp) \ 22 | $(wildcard avi/*.cpp) \ 23 | $(wildcard id3v2/*.cpp) \ 24 | $(wildcard json/*.cpp) \ 25 | $(wildcard mpeg/*.cpp) \ 26 | $(wildcard pdf/*.cpp) \ 27 | $(rdfa_SOURCES) \ 28 | $(wildcard riff/*.cpp) \ 29 | $(wildcard xml/*.cpp) 30 | 31 | DYNAMIC_LINK_LIBRARIES = moio moutil mort mologging mocrypto expat 32 | 33 | DYNAMIC_MACOS_LINK_LIBRARIES = iconv charset expat mocompress 34 | DYNAMIC_WINDOWS_LINK_LIBRARIES = libexpat iconv2 charset1 35 | 36 | CXX_FLAGS += @LIBRDFA_CFLAGS@ 37 | 38 | ifeq (@HAVE_LIBRDFA@,yes) 39 | DYNAMIC_LINK_LIBRARIES += rdfa 40 | endif 41 | 42 | # ----------- Standard Makefile 43 | include @MONARCH_DIR@/setup/Makefile.base 44 | -------------------------------------------------------------------------------- /cpp/data/id3v2/FrameSink.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2007-2009 Digital Bazaar, Inc. All rights reserved. 3 | */ 4 | #ifndef monarch_data_id3v2_FrameSink_H 5 | #define monarch_data_id3v2_FrameSink_H 6 | 7 | #include "monarch/data/id3v2/FrameHeader.h" 8 | #include "monarch/io/ByteBuffer.h" 9 | 10 | namespace monarch 11 | { 12 | namespace data 13 | { 14 | namespace id3v2 15 | { 16 | 17 | /** 18 | * A FrameSink is a destination to write id3v2 tag frame data to. 19 | * 20 | * @author Dave Longley 21 | */ 22 | class FrameSink 23 | { 24 | public: 25 | /** 26 | * Creates a new FrameSink. 27 | */ 28 | FrameSink() {}; 29 | 30 | /** 31 | * Destructs this FrameSink. 32 | */ 33 | virtual ~FrameSink() {}; 34 | 35 | /** 36 | * Prepares this frame sink to receive frame data for the given header. 37 | * 38 | * @param header the id3v2 tag frame header to receive data for. 39 | * 40 | * @return true if successful, false if an exception occurred. 41 | */ 42 | virtual bool startFrame(monarch::data::id3v2::FrameHeader* header) = 0; 43 | 44 | /** 45 | * Writes frame data to this sink for the current frame header. The source 46 | * should begin at the start of the frame data, after the frame header. 47 | * 48 | * @param src the ByteBuffer with frame data bytes to read. 49 | * 50 | * @return true if successful, false if an exception occurred. 51 | */ 52 | virtual bool putFrameData(monarch::io::ByteBuffer* src) = 0; 53 | }; 54 | 55 | } // end namespace id3v2 56 | } // end namespace data 57 | } // end namespace monarch 58 | #endif 59 | -------------------------------------------------------------------------------- /cpp/data/riff/RiffFormHeader.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2005-2009 Digital Bazaar, Inc. All rights reserved. 3 | */ 4 | #include "monarch/data/riff/RiffFormHeader.h" 5 | 6 | using namespace monarch::data; 7 | using namespace monarch::data::riff; 8 | 9 | RiffFormHeader::RiffFormHeader(fourcc_t form, uint32_t fileSize) : 10 | RiffListHeader(form, fileSize) 11 | { 12 | mChunkHeader.setIdentifier(CHUNK_ID); 13 | } 14 | 15 | RiffFormHeader::~RiffFormHeader() 16 | { 17 | } 18 | 19 | bool RiffFormHeader::convertFromBytes(const char* b, int length) 20 | { 21 | bool rval = false; 22 | 23 | if(b != NULL && length >= HEADER_SIZE) 24 | { 25 | if(mChunkHeader.convertFromBytes(b, length)) 26 | { 27 | // make sure chunk identifier is LIST 28 | if(mChunkHeader.getIdentifier() == CHUNK_ID) 29 | { 30 | mId = MO_FOURCC_FROM_STR(b + RiffChunkHeader::HEADER_SIZE); 31 | rval = true; 32 | } 33 | } 34 | } 35 | 36 | setValid(rval); 37 | 38 | return rval; 39 | } 40 | 41 | void RiffFormHeader::setFileSize(uint32_t fileSize) 42 | { 43 | setChunkSize(fileSize); 44 | } 45 | 46 | uint32_t RiffFormHeader::getFileSize() 47 | { 48 | return getChunkSize(); 49 | } 50 | 51 | uint32_t RiffFormHeader::getHeaderSize() 52 | { 53 | return RiffListHeader::HEADER_SIZE; 54 | } 55 | -------------------------------------------------------------------------------- /cpp/data/xml/DomTypes.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2008-2009 Digital Bazaar, Inc. All rights reserved. 3 | */ 4 | #ifndef monarch_data_xml_DomTypes_H 5 | #define monarch_data_xml_DomTypes_H 6 | 7 | #include "monarch/rt/DynamicObject.h" 8 | #include "monarch/rt/DynamicObjectIterator.h" 9 | 10 | namespace monarch 11 | { 12 | namespace data 13 | { 14 | namespace xml 15 | { 16 | 17 | /** 18 | * An Element has a name, attributes, data, and children. 19 | * 20 | * Element 21 | * { 22 | * "name" : string, 23 | * "namespace" : string, 24 | * "attributes" : Map, 25 | * "data" : string, 26 | * "children" : Map of Arrays 27 | * } 28 | * 29 | * @member name the name of the element. 30 | * @member namespace the namespace for the element. 31 | * @member attributes a map of attribute names to attributes. 32 | * @member data the data for the element. 33 | * @member children the children for the element, in Arrays keyed by name. 34 | */ 35 | typedef monarch::rt::DynamicObject Element; 36 | typedef monarch::rt::DynamicObjectIterator ElementIterator; 37 | 38 | /** 39 | * An Attribute has a value and a namespace. 40 | * 41 | * Attribute 42 | * { 43 | * "name" : string, 44 | * "namespace" : string, 45 | * "value" : string 46 | * } 47 | * 48 | * @member name the name of the attribute. 49 | * @member value the value of the attribute. 50 | * @member namespace the namespace for the attribute. 51 | */ 52 | typedef monarch::rt::DynamicObject Attribute; 53 | typedef monarch::rt::DynamicObjectIterator AttributeIterator; 54 | 55 | } // end namespace xml 56 | } // end namespace data 57 | } // end namespace monarch 58 | #endif 59 | -------------------------------------------------------------------------------- /cpp/event/Event.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2007-2009 Digital Bazaar, Inc. All rights reserved. 3 | */ 4 | #ifndef monarch_event_Event_H 5 | #define monarch_event_Event_H 6 | 7 | #include "monarch/rt/DynamicObject.h" 8 | 9 | namespace monarch 10 | { 11 | namespace event 12 | { 13 | 14 | /** 15 | * An Event is an object that is generated by an Observable when something 16 | * significant occurs. An Event may be dispatched to the Observable's 17 | * registered Observers so they can take whatever action they deem appropriate. 18 | * 19 | * Reserved fields: 20 | * 21 | * Event["id"]: 22 | * Refers to an EventId for the Event's type. 23 | * Event["sequenceId"]: 24 | * Refers to a global sequence in which an event occurred on a given 25 | * Observable -- it increases by 1 per event. 26 | * Event["serial"]: 27 | * Used to determine if an event must be distributed before 28 | * events that follow it. 29 | * Event["parallel"]: 30 | * Used to determine if an event can be distributed at any moment, 31 | * regardless of other events. 32 | * Event["details"]: 33 | * A map that should contain any user details for the event. 34 | * 35 | * @author Dave Longley 36 | */ 37 | typedef monarch::rt::DynamicObject Event; 38 | typedef uint64_t EventId; 39 | 40 | /** 41 | * An EventFilter can be used to filter events that are received by an 42 | * Observer. It is a DynamicObject map that is a subset of data that must 43 | * be present in an Event in order for an Observer to receive it. 44 | * 45 | * @author Dave Longley 46 | */ 47 | typedef monarch::rt::DynamicObject EventFilter; 48 | 49 | } // end namespace event 50 | } // end namespace monarch 51 | #endif 52 | -------------------------------------------------------------------------------- /cpp/event/Makefile.in: -------------------------------------------------------------------------------- 1 | # Makefile to compile the module in this directory 2 | 3 | LIBRARIES = moevent 4 | moevent_HEADERS = $(wildcard *.h) 5 | moevent_SOURCES = $(wildcard *.cpp) 6 | 7 | DYNAMIC_LINK_LIBRARIES = mort moutil momodest 8 | 9 | # ----------- Standard Makefile 10 | include @MONARCH_DIR@/setup/Makefile.base 11 | 12 | -------------------------------------------------------------------------------- /cpp/event/Observer.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2007-2009 Digital Bazaar, Inc. All rights reserved. 3 | */ 4 | #ifndef monarch_event_Observer_H 5 | #define monarch_event_Observer_H 6 | 7 | #include "monarch/event/Event.h" 8 | 9 | namespace monarch 10 | { 11 | namespace event 12 | { 13 | 14 | /** 15 | * An Observer can register with an Observable to receive the events it 16 | * generates. 17 | * 18 | * @author Dave Longley 19 | */ 20 | class Observer 21 | { 22 | public: 23 | /** 24 | * Creates a new Observer. 25 | */ 26 | Observer() {}; 27 | 28 | /** 29 | * Destructs this Observer. 30 | */ 31 | virtual ~Observer() {}; 32 | 33 | /** 34 | * Called when an Event occurs on an Observable that this Observer is 35 | * registered with. 36 | * 37 | * @param e the Event that occurred. 38 | */ 39 | virtual void eventOccurred(Event& e) = 0; 40 | }; 41 | 42 | // type definition for a reference-counted Observer 43 | typedef monarch::rt::Collectable ObserverRef; 44 | 45 | } // end namespace event 46 | } // end namespace monarch 47 | #endif 48 | -------------------------------------------------------------------------------- /cpp/fiber/Fiber.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2009 Digital Bazaar, Inc. All rights reserved. 3 | */ 4 | #include "monarch/fiber/Fiber.h" 5 | 6 | #include "monarch/fiber/FiberScheduler.h" 7 | 8 | using namespace monarch::fiber; 9 | using namespace monarch::rt; 10 | 11 | #define DEFAULT_STACK_SIZE 0x2000 // 8k 12 | 13 | Fiber::Fiber(size_t stackSize) : 14 | mId(0), 15 | mState(Fiber::New) 16 | { 17 | mStackSize = (stackSize == 0 ? DEFAULT_STACK_SIZE : stackSize); 18 | } 19 | 20 | Fiber::~Fiber() 21 | { 22 | } 23 | 24 | void Fiber::start() 25 | { 26 | // run custom fiber code 27 | run(); 28 | 29 | // fiber now exited 30 | mScheduler->exit(this); 31 | } 32 | 33 | inline void Fiber::yield() 34 | { 35 | mScheduler->yield(this); 36 | } 37 | 38 | inline void Fiber::sleep() 39 | { 40 | mScheduler->sleep(this); 41 | } 42 | 43 | inline void Fiber::wakeup() 44 | { 45 | mScheduler->wakeupSelf(this); 46 | } 47 | 48 | void Fiber::setScheduler(FiberId id, FiberScheduler* scheduler) 49 | { 50 | mId = id; 51 | mScheduler = scheduler; 52 | } 53 | 54 | inline FiberId Fiber::getId() 55 | { 56 | return mId; 57 | } 58 | 59 | inline void Fiber::setState(State state) 60 | { 61 | mState = state; 62 | } 63 | 64 | inline Fiber::State Fiber::getState() 65 | { 66 | return mState; 67 | } 68 | 69 | inline size_t Fiber::getStackSize() 70 | { 71 | return mStackSize; 72 | } 73 | 74 | inline FiberContext* Fiber::getContext() 75 | { 76 | return &mContext; 77 | } 78 | 79 | inline bool Fiber::canSleep() 80 | { 81 | return false; 82 | } 83 | -------------------------------------------------------------------------------- /cpp/fiber/FiberMessageCenter.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2009 Digital Bazaar, Inc. All rights reserved. 3 | */ 4 | #include "monarch/fiber/FiberMessageCenter.h" 5 | 6 | #include 7 | 8 | using namespace std; 9 | using namespace monarch::fiber; 10 | using namespace monarch::rt; 11 | 12 | FiberMessageCenter::FiberMessageCenter() 13 | { 14 | } 15 | 16 | FiberMessageCenter::~FiberMessageCenter() 17 | { 18 | } 19 | 20 | void FiberMessageCenter::registerFiber(MessagableFiber* fiber) 21 | { 22 | // lock to add fiber to map 23 | mMessageLock.lockExclusive(); 24 | { 25 | mFibers.insert(make_pair(fiber->getId(), fiber)); 26 | } 27 | mMessageLock.unlockExclusive(); 28 | } 29 | 30 | void FiberMessageCenter::unregisterFiber(MessagableFiber* fiber) 31 | { 32 | // lock to remove fiber from map 33 | mMessageLock.lockExclusive(); 34 | { 35 | mFibers.erase(fiber->getId()); 36 | } 37 | mMessageLock.unlockExclusive(); 38 | } 39 | 40 | bool FiberMessageCenter::sendMessage(FiberId id, DynamicObject& msg) 41 | { 42 | bool rval = false; 43 | 44 | // get shared lock to deliver message 45 | mMessageLock.lockShared(); 46 | { 47 | FiberMap::iterator i = mFibers.find(id); 48 | if(i != mFibers.end()) 49 | { 50 | i->second->addMessage(msg); 51 | rval = true; 52 | } 53 | } 54 | mMessageLock.unlockShared(); 55 | 56 | return rval; 57 | } 58 | -------------------------------------------------------------------------------- /cpp/fiber/Makefile.in: -------------------------------------------------------------------------------- 1 | # Makefile to compile the module in this directory 2 | 3 | LIBRARIES = mofiber 4 | mofiber_HEADERS = $(wildcard *.h) 5 | mofiber_SOURCES = $(wildcard *.cpp) 6 | 7 | # If we're building on MacOS, include the get/setcontext assembler files 8 | ifeq (@BUILD_FOR_MACOS@,yes) 9 | mofiber_SOURCES += PortableUContextAsm.S 10 | endif 11 | 12 | DYNAMIC_LINK_LIBRARIES = mort momodest 13 | 14 | # ----------- Standard Makefile 15 | include @MONARCH_DIR@/setup/Makefile.base 16 | 17 | -------------------------------------------------------------------------------- /cpp/http/HttpRequest.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2007-2009 Digital Bazaar, Inc. All rights reserved. 3 | */ 4 | #include "monarch/http/HttpRequest.h" 5 | 6 | #include "monarch/http/HttpConnection.h" 7 | #include "monarch/http/HttpResponse.h" 8 | 9 | using namespace monarch::io; 10 | using namespace monarch::http; 11 | 12 | HttpRequest::HttpRequest(HttpConnection* hc) 13 | { 14 | mConnection = hc; 15 | } 16 | 17 | HttpRequest::~HttpRequest() 18 | { 19 | } 20 | 21 | inline HttpResponse* HttpRequest::createResponse() 22 | { 23 | return new HttpResponse(this); 24 | } 25 | 26 | inline bool HttpRequest::sendHeader() 27 | { 28 | return getConnection()->sendHeader(getHeader()); 29 | } 30 | 31 | inline bool HttpRequest::receiveHeader() 32 | { 33 | return getConnection()->receiveHeader(getHeader()); 34 | } 35 | 36 | inline bool HttpRequest::sendBody(InputStream* is, HttpTrailer* trailer) 37 | { 38 | return getConnection()->sendBody(getHeader(), is, trailer); 39 | } 40 | 41 | inline OutputStream* HttpRequest::getBodyOutputStream(HttpTrailer* trailer) 42 | { 43 | return getConnection()->getBodyOutputStream(getHeader(), trailer); 44 | } 45 | 46 | inline bool HttpRequest::receiveBody(OutputStream* os, HttpTrailer* trailer) 47 | { 48 | return getConnection()->receiveBody(getHeader(), os, trailer); 49 | } 50 | 51 | inline InputStream* HttpRequest::getBodyInputStream(HttpTrailer* trailer) 52 | { 53 | return getConnection()->getBodyInputStream(getHeader(), trailer); 54 | } 55 | 56 | inline HttpRequestHeader* HttpRequest::getHeader() 57 | { 58 | return &mHeader; 59 | } 60 | 61 | inline HttpConnection* HttpRequest::getConnection() 62 | { 63 | return mConnection; 64 | } 65 | -------------------------------------------------------------------------------- /cpp/http/HttpRequestModifier.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2010 Digital Bazaar, Inc. All rights reserved. 3 | */ 4 | #include "monarch/http/HttpRequestModifier.h" 5 | 6 | using namespace monarch::http; 7 | 8 | HttpRequestModifier::HttpRequestModifier() 9 | { 10 | } 11 | 12 | HttpRequestModifier::~HttpRequestModifier() 13 | { 14 | } 15 | -------------------------------------------------------------------------------- /cpp/http/HttpRequestModifier.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2010 Digital Bazaar, Inc. All rights reserved. 3 | */ 4 | #ifndef monarch_http_HttpRequestModifier_H 5 | #define monarch_http_HttpRequestModifier_H 6 | 7 | #include "monarch/http/HttpRequest.h" 8 | 9 | namespace monarch 10 | { 11 | namespace http 12 | { 13 | 14 | /** 15 | * An HttpRequestModifier is used to modify HttpRequests received over an 16 | * HttpConnection. For instance, a modifier may rewrite the path in the 17 | * request header. 18 | * 19 | * It implements modifyRequest(HttpRequest* request). 20 | * 21 | * @author Dave Longley 22 | */ 23 | class HttpRequestModifier 24 | { 25 | public: 26 | /** 27 | * Creates a new HttpRequestModifier. 28 | */ 29 | HttpRequestModifier(); 30 | 31 | /** 32 | * Destructs this HttpRequestModifier. 33 | */ 34 | virtual ~HttpRequestModifier(); 35 | 36 | /** 37 | * Modifies the passed HttpRequest. The header for the request has already 38 | * been received, but the body has not. 39 | * 40 | * @param request the HttpRequest to modify. 41 | */ 42 | virtual void modifyRequest(HttpRequest* request) = 0; 43 | }; 44 | 45 | } // end namespace http 46 | } // end namespace monarch 47 | #endif 48 | -------------------------------------------------------------------------------- /cpp/http/HttpRequestState.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2011 Digital Bazaar, Inc. All rights reserved. 3 | */ 4 | #include "monarch/http/HttpRequestState.h" 5 | 6 | using namespace std; 7 | using namespace monarch::http; 8 | using namespace monarch::rt; 9 | using namespace monarch::util; 10 | 11 | HttpRequestState::HttpRequestState() 12 | { 13 | } 14 | 15 | HttpRequestState::~HttpRequestState() 16 | { 17 | } 18 | 19 | void HttpRequestState::beginRequest() 20 | { 21 | mDetails = new DynamicObject(); 22 | mDetails->setType(Map); 23 | mTimer.start(); 24 | } 25 | 26 | Timer* HttpRequestState::getTimer() 27 | { 28 | return &mTimer; 29 | } 30 | 31 | DynamicObject& HttpRequestState::getDetails() 32 | { 33 | return mDetails; 34 | } 35 | -------------------------------------------------------------------------------- /cpp/http/HttpRequestState.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2011 Digital Bazaar, Inc. All rights reserved. 3 | */ 4 | #ifndef monarch_http_HttpRequestState_h 5 | #define monarch_http_HttpRequestState_h 6 | 7 | #include "monarch/rt/DynamicObject.h" 8 | #include "monarch/util/Timer.h" 9 | 10 | namespace monarch 11 | { 12 | namespace http 13 | { 14 | 15 | /** 16 | * A HttpRequestState holds state of a connection. 17 | * 18 | * Provides a common DynamicObject to store request state details. Also 19 | * provides a timer for each request. beginRequest() should be called when 20 | * starting to handle a request to clear state and start the timer. 21 | * 22 | * @author David I. Lehn 23 | */ 24 | class HttpRequestState 25 | { 26 | protected: 27 | /** 28 | * Request timer. 29 | */ 30 | monarch::util::Timer mTimer; 31 | 32 | /** 33 | * Storage for connection state. 34 | */ 35 | monarch::rt::DynamicObject mDetails; 36 | 37 | public: 38 | /** 39 | * Creates a new HttpRequestState. 40 | */ 41 | HttpRequestState(); 42 | 43 | /** 44 | * Destructs this HttpRequestState. 45 | */ 46 | virtual ~HttpRequestState(); 47 | 48 | /** 49 | * Begin handling a new request by clearing state and starting the request 50 | * timer. 51 | */ 52 | virtual void beginRequest(); 53 | 54 | /** 55 | * Get the request timer. 56 | * 57 | * @return the request timer. 58 | */ 59 | virtual monarch::util::Timer* getTimer(); 60 | 61 | /** 62 | * Get the details stored in this state. 63 | * 64 | * @return a DynamicObject with connection state details. 65 | */ 66 | virtual monarch::rt::DynamicObject& getDetails(); 67 | }; 68 | 69 | } // end namespace http 70 | } // end namespace monarch 71 | #endif 72 | -------------------------------------------------------------------------------- /cpp/http/HttpResponse.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2007-2009 Digital Bazaar, Inc. All rights reserved. 3 | */ 4 | #include "monarch/http/HttpResponse.h" 5 | 6 | #include "monarch/http/HttpRequest.h" 7 | 8 | using namespace monarch::io; 9 | using namespace monarch::http; 10 | 11 | HttpResponse::HttpResponse(HttpRequest* request) 12 | { 13 | mRequest = request; 14 | } 15 | 16 | HttpResponse::~HttpResponse() 17 | { 18 | } 19 | 20 | inline bool HttpResponse::sendHeader() 21 | { 22 | return getConnection()->sendHeader(getHeader()); 23 | } 24 | 25 | inline bool HttpResponse::receiveHeader() 26 | { 27 | return getConnection()->receiveHeader(getHeader()); 28 | } 29 | 30 | inline bool HttpResponse::sendBody(InputStream* is, HttpTrailer* trailer) 31 | { 32 | return getConnection()->sendBody(getHeader(), is, trailer); 33 | } 34 | 35 | inline OutputStream* HttpResponse::getBodyOutputStream(HttpTrailer* trailer) 36 | { 37 | return getConnection()->getBodyOutputStream(getHeader(), trailer); 38 | } 39 | 40 | inline bool HttpResponse::receiveBody(OutputStream* os, HttpTrailer* trailer) 41 | { 42 | return getConnection()->receiveBody(getHeader(), os, trailer); 43 | } 44 | 45 | inline InputStream* HttpResponse::getBodyInputStream(HttpTrailer* trailer) 46 | { 47 | return getConnection()->getBodyInputStream(getHeader(), trailer); 48 | } 49 | 50 | inline HttpResponseHeader* HttpResponse::getHeader() 51 | { 52 | return &mHeader; 53 | } 54 | 55 | inline HttpConnection* HttpResponse::getConnection() 56 | { 57 | return mRequest->getConnection(); 58 | } 59 | 60 | inline HttpRequest* HttpResponse::getRequest() 61 | { 62 | return mRequest; 63 | } 64 | -------------------------------------------------------------------------------- /cpp/http/HttpTrailer.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2007-2010 Digital Bazaar, Inc. All rights reserved. 3 | */ 4 | #include "monarch/http/HttpTrailer.h" 5 | 6 | using namespace monarch::http; 7 | 8 | HttpTrailer::HttpTrailer() : 9 | mContentLength(0) 10 | { 11 | } 12 | 13 | HttpTrailer::~HttpTrailer() 14 | { 15 | } 16 | 17 | inline void HttpTrailer::update(int64_t contentLength) 18 | { 19 | // save content length 20 | setContentLength(contentLength); 21 | } 22 | 23 | inline void HttpTrailer::setContentLength(int64_t contentLength) 24 | { 25 | mContentLength = contentLength; 26 | } 27 | 28 | inline int64_t HttpTrailer::getContentLength() 29 | { 30 | return mContentLength; 31 | } 32 | 33 | inline HttpHeader::Type HttpTrailer::getType() 34 | { 35 | return HttpHeader::Trailer; 36 | } 37 | -------------------------------------------------------------------------------- /cpp/http/Makefile.in: -------------------------------------------------------------------------------- 1 | # Makefile to compile the module in this directory 2 | 3 | LIBRARIES = mohttp 4 | mohttp_HEADERS = $(wildcard *.h) 5 | mohttp_SOURCES = $(wildcard *.cpp) 6 | 7 | DYNAMIC_LINK_LIBRARIES = mort moutil momodest moio mocrypto mologging monet 8 | 9 | DYNAMIC_MACOS_LINK_LIBRARIES = crypto ssl mocompress 10 | DYNAMIC_WINDOWS_LINK_LIBRARIES = libeay32 ssleay32 ws2_32 11 | 12 | # ----------- Standard Makefile 13 | include @MONARCH_DIR@/setup/Makefile.base 14 | -------------------------------------------------------------------------------- /cpp/io/BufferedOutputStream.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2007-2009 Digital Bazaar, Inc. All rights reserved. 3 | */ 4 | #include "monarch/io/BufferedOutputStream.h" 5 | 6 | using namespace monarch::io; 7 | 8 | BufferedOutputStream::BufferedOutputStream( 9 | ByteBuffer* b, OutputStream* os, bool cleanup) : 10 | FilterOutputStream(os, cleanup), 11 | mBuffer(b) 12 | { 13 | } 14 | 15 | BufferedOutputStream::~BufferedOutputStream() 16 | { 17 | } 18 | 19 | bool BufferedOutputStream::write(const char* b, int length) 20 | { 21 | bool rval = true; 22 | 23 | int written = 0; 24 | while(rval && written < length) 25 | { 26 | // put bytes into buffer 27 | written += mBuffer->put(b + written, length - written, false); 28 | 29 | // flush buffer if full 30 | if(mBuffer->isFull()) 31 | { 32 | rval = flush(); 33 | } 34 | } 35 | 36 | return rval; 37 | } 38 | 39 | bool BufferedOutputStream::flush() 40 | { 41 | bool rval = mOutputStream->write(mBuffer->data(), mBuffer->length()); 42 | mBuffer->clear(); 43 | return rval; 44 | } 45 | 46 | void BufferedOutputStream::close() 47 | { 48 | // make sure to flush ;) 49 | flush(); 50 | mOutputStream->close(); 51 | } 52 | 53 | void BufferedOutputStream::setBuffer(ByteBuffer* b) 54 | { 55 | mBuffer = b; 56 | } 57 | -------------------------------------------------------------------------------- /cpp/io/ByteArrayOutputStream.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2007-2011 Digital Bazaar, Inc. All rights reserved. 3 | */ 4 | #include "monarch/io/ByteArrayOutputStream.h" 5 | 6 | #include "monarch/io/IOException.h" 7 | 8 | using namespace std; 9 | using namespace monarch::io; 10 | using namespace monarch::rt; 11 | 12 | ByteArrayOutputStream::ByteArrayOutputStream() : 13 | mBuffer(new ByteBuffer()), 14 | mResize(true), 15 | mCleanup(true) 16 | { 17 | } 18 | 19 | ByteArrayOutputStream::ByteArrayOutputStream(ByteBuffer* b, bool resize) : 20 | mBuffer(b), 21 | mResize(resize), 22 | mCleanup(false) 23 | { 24 | } 25 | 26 | ByteArrayOutputStream::~ByteArrayOutputStream() 27 | { 28 | if(mCleanup) 29 | { 30 | delete mBuffer; 31 | } 32 | } 33 | 34 | bool ByteArrayOutputStream::write(const char* b, int length) 35 | { 36 | bool rval = true; 37 | 38 | // put bytes in byte buffer 39 | int written = mBuffer->put(b, length, getResize()); 40 | if(written != length) 41 | { 42 | IOException* e = new IOException( 43 | "Could not write all data, ByteBuffer is full."); 44 | e->setUsedBytes(written); 45 | e->setUnusedBytes(length - written); 46 | ExceptionRef ref = e; 47 | Exception::set(ref); 48 | rval = false; 49 | } 50 | 51 | return rval; 52 | } 53 | 54 | ByteBuffer* ByteArrayOutputStream::getByteArray() 55 | { 56 | return mBuffer; 57 | } 58 | 59 | string ByteArrayOutputStream::str() 60 | { 61 | return string(mBuffer->data(), mBuffer->length()); 62 | } 63 | 64 | void ByteArrayOutputStream::setResize(bool resize) 65 | { 66 | mResize = resize; 67 | } 68 | 69 | bool ByteArrayOutputStream::getResize() 70 | { 71 | return mResize; 72 | } 73 | -------------------------------------------------------------------------------- /cpp/io/FileList.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2007-2009 Digital Bazaar, Inc. All rights reserved. 3 | */ 4 | #ifndef monarch_io_FileList_H 5 | #define monarch_io_FileList_H 6 | 7 | #include "monarch/util/UniqueList.h" 8 | #include "monarch/io/File.h" 9 | 10 | namespace monarch 11 | { 12 | namespace io 13 | { 14 | 15 | /** 16 | * A FileList consists of a list of unique Files. The Files will be 17 | * compared on their equality operator: operator==. 18 | * 19 | * @author Dave Longley 20 | */ 21 | class FileList : public monarch::rt::Collectable< monarch::util::UniqueList > 22 | { 23 | public: 24 | /** 25 | * Creates a new FileList. 26 | */ 27 | FileList( 28 | monarch::util::UniqueList* ptr = new monarch::util::UniqueList()) : 29 | monarch::rt::Collectable< monarch::util::UniqueList >(ptr) {}; 30 | 31 | /** 32 | * Destructs this FileList. 33 | */ 34 | virtual ~FileList() {}; 35 | }; 36 | 37 | } // end namespace io 38 | } // end namespace monarch 39 | #endif 40 | -------------------------------------------------------------------------------- /cpp/io/FilterInputStream.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2007-2011 Digital Bazaar, Inc. All rights reserved. 3 | */ 4 | #include "monarch/io/FilterInputStream.h" 5 | 6 | using namespace monarch::io; 7 | 8 | FilterInputStream::FilterInputStream(InputStream* is, bool cleanup) : 9 | mInputStream(NULL), 10 | mCleanupInputStream(false) 11 | { 12 | setInputStream(is, cleanup); 13 | } 14 | 15 | FilterInputStream::~FilterInputStream() 16 | { 17 | setInputStream(NULL, false); 18 | } 19 | 20 | void FilterInputStream::setInputStream(InputStream* is, bool cleanup) 21 | { 22 | if(mCleanupInputStream) 23 | { 24 | delete mInputStream; 25 | } 26 | mInputStream = is; 27 | mCleanupInputStream = cleanup; 28 | } 29 | 30 | inline int FilterInputStream::read(char* b, int length) 31 | { 32 | return mInputStream->read(b, length); 33 | } 34 | 35 | inline int FilterInputStream::peek(char* b, int length, bool block) 36 | { 37 | return mInputStream->peek(b, length, block); 38 | } 39 | 40 | inline int64_t FilterInputStream::skip(int64_t count) 41 | { 42 | return InputStream::skip(count); 43 | } 44 | 45 | inline void FilterInputStream::close() 46 | { 47 | mInputStream->close(); 48 | } 49 | -------------------------------------------------------------------------------- /cpp/io/FilterOutputStream.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2007-2011 Digital Bazaar, Inc. All rights reserved. 3 | */ 4 | #include "monarch/io/FilterOutputStream.h" 5 | 6 | using namespace monarch::io; 7 | 8 | FilterOutputStream::FilterOutputStream(OutputStream* os, bool cleanup) : 9 | mOutputStream(os), 10 | mCleanupOutputStream(cleanup) 11 | { 12 | } 13 | 14 | FilterOutputStream::~FilterOutputStream() 15 | { 16 | if(mCleanupOutputStream) 17 | { 18 | delete mOutputStream; 19 | } 20 | } 21 | 22 | inline bool FilterOutputStream::write(const char* b, int length) 23 | { 24 | return mOutputStream->write(b, length); 25 | } 26 | 27 | inline bool FilterOutputStream::flush() 28 | { 29 | return mOutputStream->flush(); 30 | } 31 | 32 | inline bool FilterOutputStream::finish() 33 | { 34 | return mOutputStream->finish(); 35 | } 36 | 37 | inline void FilterOutputStream::close() 38 | { 39 | mOutputStream->close(); 40 | } 41 | -------------------------------------------------------------------------------- /cpp/io/IOException.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2007-2011 Digital Bazaar, Inc. All rights reserved. 3 | */ 4 | #include "monarch/io/IOException.h" 5 | 6 | using namespace monarch::io; 7 | using namespace monarch::rt; 8 | 9 | IOException::IOException(const char* message, const char* type) : 10 | Exception(message, type) 11 | { 12 | } 13 | 14 | IOException::~IOException() 15 | { 16 | } 17 | 18 | void IOException::setUsedBytes(int used) 19 | { 20 | getDetails()["usedBytes"] = used; 21 | } 22 | 23 | int IOException::getUsedBytes() 24 | { 25 | return getDetails()["usedBytes"]->getInt32(); 26 | } 27 | 28 | void IOException::setUnusedBytes(int unused) 29 | { 30 | getDetails()["unusedBytes"] = unused; 31 | } 32 | 33 | int IOException::getUnusedBytes() 34 | { 35 | return getDetails()["unusedBytes"]->getInt32(); 36 | } 37 | -------------------------------------------------------------------------------- /cpp/io/IOMonitor.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2008-2009 Digital Bazaar, Inc. All rights reserved. 3 | */ 4 | #include "monarch/io/IOMonitor.h" 5 | 6 | using namespace monarch::io; 7 | 8 | IOMonitor::IOMonitor() 9 | { 10 | } 11 | 12 | IOMonitor::~IOMonitor() 13 | { 14 | } 15 | 16 | void IOMonitor::addWatcher(int fd, int events, IOWatcherRef& w) 17 | { 18 | // FIXME: 19 | 20 | // FIXME: remove this 21 | w->fdUpdated(fd, events); 22 | } 23 | 24 | void IOMonitor::removeWatcher(IOWatcherRef& w) 25 | { 26 | // FIXME: 27 | } 28 | -------------------------------------------------------------------------------- /cpp/io/IOMonitor.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2008-2009 Digital Bazaar, Inc. All rights reserved. 3 | */ 4 | #ifndef monarch_io_IOMonitor_H 5 | #define monarch_io_IOMonitor_H 6 | 7 | #include "monarch/io/IOEventDelegate.h" 8 | 9 | namespace monarch 10 | { 11 | namespace io 12 | { 13 | 14 | /** 15 | * An IOMonitor is used to notify IOWatchers when a file descriptor is ready 16 | * to be read from or written to. 17 | * 18 | * @author Dave Longley 19 | */ 20 | class IOMonitor 21 | { 22 | protected: 23 | 24 | public: 25 | /** 26 | * Creates a new IOMonitor. 27 | */ 28 | IOMonitor(); 29 | 30 | /** 31 | * Destructs this IOMonitor. 32 | */ 33 | virtual ~IOMonitor(); 34 | 35 | /** 36 | * Adds an IOWatcher for the passed file descriptor and events. 37 | * 38 | * @param fd the file descriptor to watch. 39 | * @param events a bit flag describing what events (read/write) to monitor. 40 | * @param w the IOWatcher to notify when an event occurs. 41 | */ 42 | virtual void addWatcher(int fd, int events, IOWatcherRef& w); 43 | 44 | /** 45 | * Removes the passed IOWatcher. 46 | * 47 | * @param w the IOWatcher to remove. 48 | */ 49 | virtual void removeWatcher(IOWatcherRef& w); 50 | }; 51 | 52 | } // end namespace io 53 | } // end namespace monarch 54 | #endif 55 | -------------------------------------------------------------------------------- /cpp/io/IOWatcher.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2008-2009 Digital Bazaar, Inc. All rights reserved. 3 | */ 4 | #ifndef monarch_io_IOWatcher_H 5 | #define monarch_io_IOWatcher_H 6 | 7 | #include "monarch/rt/Collectable.h" 8 | 9 | namespace monarch 10 | { 11 | namespace io 12 | { 13 | 14 | /** 15 | * An IOWatcher is an interface that is used by an IOMonitor to notify an 16 | * object that certain IO events have occurred. 17 | * 18 | * @author Dave Longley 19 | */ 20 | class IOWatcher 21 | { 22 | public: 23 | /** 24 | * Creates a new IOWatcher. 25 | */ 26 | IOWatcher() {}; 27 | 28 | /** 29 | * Destructs this IOWatcher. 30 | */ 31 | virtual ~IOWatcher() {}; 32 | 33 | /** 34 | * Called when a file descriptor is updated. 35 | * 36 | * @param fd the file descriptor that was updated. 37 | * @param events a bit flag describing what events (read/write) occurred. 38 | */ 39 | virtual void fdUpdated(int fd, int events) = 0; 40 | }; 41 | 42 | // typedef for a reference-counted IOWatcher 43 | typedef monarch::rt::Collectable IOWatcherRef; 44 | 45 | } // end namespace io 46 | } // end namespace monarch 47 | #endif 48 | -------------------------------------------------------------------------------- /cpp/io/IgnoreOutputStream.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2007-2011 Digital Bazaar, Inc. All rights reserved. 3 | */ 4 | #include "monarch/io/IgnoreOutputStream.h" 5 | 6 | #include "monarch/io/IOException.h" 7 | 8 | using namespace monarch::io; 9 | using namespace monarch::rt; 10 | 11 | IgnoreOutputStream::IgnoreOutputStream(OutputStream* os, bool cleanup) : 12 | FilterOutputStream(os, cleanup), 13 | mIgnoreCount(0) 14 | { 15 | } 16 | 17 | IgnoreOutputStream::~IgnoreOutputStream() 18 | { 19 | } 20 | 21 | bool IgnoreOutputStream::write(const char* b, int length) 22 | { 23 | bool rval = true; 24 | 25 | // determine the length to write out and new ignore count 26 | int ignored = mIgnoreCount; 27 | if(mIgnoreCount > length) 28 | { 29 | length = 0; 30 | mIgnoreCount -= length; 31 | } 32 | else 33 | { 34 | length -= mIgnoreCount; 35 | mIgnoreCount = 0; 36 | } 37 | 38 | if(length > 0) 39 | { 40 | rval = mOutputStream->write(b + ignored, length); 41 | if(!rval) 42 | { 43 | ExceptionRef ref = Exception::get(); 44 | IOException* e = dynamic_cast(&(*ref)); 45 | if(e != NULL) 46 | { 47 | // update used bytes to include ignored bytes 48 | e->setUsedBytes(ignored + e->getUsedBytes()); 49 | } 50 | } 51 | } 52 | 53 | return rval; 54 | } 55 | 56 | void IgnoreOutputStream::setIgnoreCount(int count) 57 | { 58 | mIgnoreCount = count; 59 | } 60 | 61 | int IgnoreOutputStream::getIgnoreCount() 62 | { 63 | return mIgnoreCount; 64 | } 65 | -------------------------------------------------------------------------------- /cpp/io/InputStream.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2009-2010 Digital Bazaar, Inc. All rights reserved. 3 | */ 4 | #include "monarch/io/InputStream.h" 5 | 6 | #include "monarch/rt/Exception.h" 7 | 8 | using namespace monarch::io; 9 | using namespace monarch::rt; 10 | 11 | #define INPUT_BUFFER_SIZE 2048 12 | 13 | InputStream::InputStream() 14 | { 15 | } 16 | 17 | InputStream::~InputStream() 18 | { 19 | } 20 | 21 | int InputStream::peek(char* b, int length, bool block) 22 | { 23 | // extending classes must implement this method if they want support 24 | ExceptionRef e = new Exception( 25 | "InputStream::peek() is not implemented.", 26 | "monarch.io.NotImplemented."); 27 | Exception::set(e); 28 | return -1; 29 | } 30 | 31 | int64_t InputStream::skip(int64_t count) 32 | { 33 | int64_t skipped = 0; 34 | 35 | // read and discard bytes 36 | char b[INPUT_BUFFER_SIZE]; 37 | int numBytes = 0; 38 | int length = (count < INPUT_BUFFER_SIZE) ? count : INPUT_BUFFER_SIZE; 39 | while(count > 0 && (numBytes = read(b, length)) > 0) 40 | { 41 | skipped += numBytes; 42 | count -= numBytes; 43 | length = (count < INPUT_BUFFER_SIZE) ? count : INPUT_BUFFER_SIZE; 44 | } 45 | 46 | if(skipped == 0 && numBytes == -1) 47 | { 48 | skipped = -1; 49 | } 50 | 51 | return skipped; 52 | } 53 | -------------------------------------------------------------------------------- /cpp/io/Makefile.in: -------------------------------------------------------------------------------- 1 | # Makefile to compile the module in this directory 2 | 3 | LIBRARIES = moio 4 | moio_HEADERS = $(wildcard *.h) 5 | moio_SOURCES = $(wildcard *.cpp) 6 | 7 | DYNAMIC_LINK_LIBRARIES = mort moutil 8 | 9 | # ----------- Standard Makefile 10 | include @MONARCH_DIR@/setup/Makefile.base 11 | 12 | -------------------------------------------------------------------------------- /cpp/io/NullOutputStream.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2008-2009 Digital Bazaar, Inc. All rights reserved. 3 | */ 4 | #ifndef monarch_io_NullOutputStream_H 5 | #define monarch_io_NullOutputStream_H 6 | 7 | #include "monarch/io/OutputStream.h" 8 | 9 | namespace monarch 10 | { 11 | namespace io 12 | { 13 | 14 | /** 15 | * A NullOutputStream silently consumes any data written to it, such that 16 | * nothing is written out. 17 | * 18 | * @author Dave Longley 19 | */ 20 | class NullOutputStream : public OutputStream 21 | { 22 | public: 23 | /** 24 | * Creates a new NullOutputStream. 25 | */ 26 | NullOutputStream() {}; 27 | 28 | /** 29 | * Destructs this NullOutputStream. 30 | */ 31 | virtual ~NullOutputStream() {}; 32 | 33 | /** 34 | * Writes some bytes to the stream. 35 | * 36 | * @param b the array of bytes to write. 37 | * @param length the number of bytes to write to the stream. 38 | * 39 | * @return true if the write was successful, false if an IO exception 40 | * occurred. 41 | */ 42 | virtual bool write(const char* b, int length) { return true; }; 43 | }; 44 | 45 | } // end namespace io 46 | } // end namespace monarch 47 | #endif 48 | -------------------------------------------------------------------------------- /cpp/io/OStreamOutputStream.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2007-2009 Digital Bazaar, Inc. All rights reserved. 3 | */ 4 | #include "monarch/io/OStreamOutputStream.h" 5 | 6 | #include "monarch/rt/Exception.h" 7 | 8 | using namespace std; 9 | using namespace monarch::io; 10 | using namespace monarch::rt; 11 | 12 | OStreamOutputStream::OStreamOutputStream(ostream* stream) 13 | { 14 | // store ostream 15 | mStream = stream; 16 | } 17 | 18 | OStreamOutputStream::~OStreamOutputStream() 19 | { 20 | } 21 | 22 | bool OStreamOutputStream::write(const char* b, int length) 23 | { 24 | bool rval = false; 25 | 26 | // do write 27 | mStream->write(b, length); 28 | 29 | // see if a failure has occurred 30 | if(!(rval = !mStream->fail())) 31 | { 32 | ExceptionRef e = new Exception( 33 | "Could not write to ostream.", "monarch.io.IO"); 34 | Exception::set(e); 35 | } 36 | 37 | return rval; 38 | } 39 | -------------------------------------------------------------------------------- /cpp/io/OStreamOutputStream.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2007-2009 Digital Bazaar, Inc. All rights reserved. 3 | */ 4 | #ifndef monarch_io_OStreamOutputStream_H 5 | #define monarch_io_OStreamOutputStream_H 6 | 7 | #include "monarch/io/OutputStream.h" 8 | 9 | #include 10 | 11 | namespace monarch 12 | { 13 | namespace io 14 | { 15 | 16 | /** 17 | * An OStreamOutputStream is used to write bytes with an ostream. 18 | * 19 | * @author Dave Longley 20 | */ 21 | class OStreamOutputStream : public OutputStream 22 | { 23 | protected: 24 | /** 25 | * The ostream to write with. 26 | */ 27 | std::ostream* mStream; 28 | 29 | public: 30 | /** 31 | * Creates a new OStreamOutputStream that writes with the passed ostream. 32 | * 33 | * @param stream the ostream to write with. 34 | */ 35 | OStreamOutputStream(std::ostream* stream); 36 | 37 | /** 38 | * Destructs this OStreamOutputStream. 39 | */ 40 | virtual ~OStreamOutputStream(); 41 | 42 | /** 43 | * Writes some bytes to the stream. 44 | * 45 | * @param b the array of bytes to write. 46 | * @param length the number of bytes to write to the stream. 47 | * 48 | * @return true if the write was successful, false if an IO exception 49 | * occurred. 50 | */ 51 | virtual bool write(const char* b, int length); 52 | }; 53 | 54 | } // end namespace io 55 | } // end namespace monarch 56 | #endif 57 | -------------------------------------------------------------------------------- /cpp/io/OutputStream.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2009 Digital Bazaar, Inc. All rights reserved. 3 | */ 4 | #include "monarch/io/OutputStream.h" 5 | 6 | #include "monarch/rt/Exception.h" 7 | 8 | using namespace monarch::io; 9 | using namespace monarch::rt; 10 | 11 | OutputStream::OutputStream() 12 | { 13 | } 14 | 15 | OutputStream::~OutputStream() 16 | { 17 | } 18 | 19 | bool OutputStream::flush() 20 | { 21 | return true; 22 | } 23 | 24 | bool OutputStream::finish() 25 | { 26 | return true; 27 | } 28 | 29 | void OutputStream::close() 30 | { 31 | } 32 | -------------------------------------------------------------------------------- /cpp/io/PeekInputStream.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2007-2009 Digital Bazaar, Inc. All rights reserved. 3 | */ 4 | #include "monarch/io/PeekInputStream.h" 5 | 6 | using namespace monarch::io; 7 | 8 | PeekInputStream::PeekInputStream(InputStream* is, bool cleanup) : 9 | FilterInputStream(is, cleanup), 10 | mPeekBuffer(0) 11 | { 12 | } 13 | 14 | PeekInputStream::~PeekInputStream() 15 | { 16 | } 17 | 18 | int PeekInputStream::read(char* b, int length) 19 | { 20 | int rval = 0; 21 | 22 | if(!mPeekBuffer.isEmpty()) 23 | { 24 | // read from the peek buffer first 25 | rval = mPeekBuffer.get(b, length); 26 | } 27 | else 28 | { 29 | // read from the underlying stream 30 | rval = mInputStream->read(b, length); 31 | } 32 | 33 | return rval; 34 | } 35 | 36 | int PeekInputStream::peek(char* b, int length, bool block) 37 | { 38 | int rval = 0; 39 | 40 | // see if more data needs to be read 41 | if(block && length > mPeekBuffer.length()) 42 | { 43 | // allocate enough space in the peek buffer 44 | mPeekBuffer.allocateSpace(length, true); 45 | 46 | // read into the peek buffer from the underlying stream 47 | rval = mPeekBuffer.put(mInputStream); 48 | } 49 | 50 | // check for peeked bytes 51 | if(!mPeekBuffer.isEmpty() && rval != -1) 52 | { 53 | // read from the peek buffer 54 | rval = mPeekBuffer.get(b, length); 55 | 56 | // reset peek buffer so that data will be read again 57 | mPeekBuffer.reset(rval); 58 | } 59 | 60 | return rval; 61 | } 62 | -------------------------------------------------------------------------------- /cpp/io/TruncateInputStream.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2008-2009 Digital Bazaar, Inc. All rights reserved. 3 | */ 4 | #include "monarch/io/TruncateInputStream.h" 5 | 6 | using namespace monarch::io; 7 | 8 | TruncateInputStream::TruncateInputStream( 9 | uint64_t max, InputStream* is, bool cleanup) : 10 | FilterInputStream(is, cleanup) 11 | { 12 | mMax = max; 13 | mTotal = 0; 14 | } 15 | 16 | TruncateInputStream::~TruncateInputStream() 17 | { 18 | } 19 | 20 | int TruncateInputStream::read(char* b, int length) 21 | { 22 | int rval = 0; 23 | 24 | // only read up to max amount, truncate rest 25 | if(mTotal < mMax) 26 | { 27 | // allow maximum amount of data to be read 28 | int remaining = (int)(mMax - mTotal); 29 | length = (length > remaining ? remaining : length); 30 | rval = FilterInputStream::read(b, length); 31 | if(rval > 0) 32 | { 33 | mTotal += rval; 34 | } 35 | } 36 | 37 | return rval; 38 | } 39 | -------------------------------------------------------------------------------- /cpp/kernel/Makefile.in: -------------------------------------------------------------------------------- 1 | # Makefile to compile the module in this directory 2 | 3 | LIBRARIES = mokernel 4 | mokernel_HEADERS = $(wildcard *.h) 5 | mokernel_SOURCES = $(wildcard *.cpp) 6 | 7 | DYNAMIC_LINK_LIBRARIES = mort moutil momodest mofiber moconfig moio mocrypto moevent mologging monet modata movalidation 8 | 9 | DYNAMIC_MACOS_LINK_LIBRARIES = crypto ssl mocompress 10 | DYNAMIC_WINDOWS_LINK_LIBRARIES = libeay32 ssleay32 11 | 12 | # ----------- Standard Makefile 13 | include @MONARCH_DIR@/setup/Makefile.base 14 | -------------------------------------------------------------------------------- /cpp/kernel/MicroKernelModule.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2009 Digital Bazaar, Inc. All rights reserved. 3 | */ 4 | #include "monarch/kernel/MicroKernelModule.h" 5 | 6 | #include "monarch/kernel/MicroKernel.h" 7 | 8 | using namespace monarch::kernel; 9 | using namespace monarch::modest; 10 | using namespace monarch::rt; 11 | 12 | MicroKernelModule::MicroKernelModule(const char* name, const char* version) 13 | { 14 | mId.name = name; 15 | mId.version = version; 16 | } 17 | 18 | MicroKernelModule::~MicroKernelModule() 19 | { 20 | } 21 | 22 | const ModuleId& MicroKernelModule::getId() 23 | { 24 | return mId; 25 | } 26 | 27 | bool MicroKernelModule::initialize(Kernel* k) 28 | { 29 | // FIXME: consider renaming initialize/cleanup() here or in modest or both 30 | // to help eliminate confusion over what gets call when 31 | 32 | // nothing to do for modest initialization 33 | return true; 34 | } 35 | 36 | void MicroKernelModule::cleanup(Kernel* k) 37 | { 38 | // no modest clean up to do 39 | } 40 | 41 | ModuleInterface* MicroKernelModule::getInterface() 42 | { 43 | return NULL; 44 | } 45 | -------------------------------------------------------------------------------- /cpp/kernel/MicroKernelModuleApi.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2009 Digital Bazaar, Inc. All rights reserved. 3 | */ 4 | #ifndef monarch_kernel_MicroKernelModuleApi_H 5 | #define monarch_kernel_MicroKernelModuleApi_H 6 | 7 | namespace monarch 8 | { 9 | namespace kernel 10 | { 11 | 12 | /** 13 | * A MicroKernelModuleApi is the base class for the API for a MicroKernelModule. 14 | * 15 | * @author Dave Longley 16 | */ 17 | class MicroKernelModuleApi 18 | { 19 | public: 20 | /** 21 | * Creates a new MicroKernelModuleApi for a MicroKernelModule. 22 | */ 23 | MicroKernelModuleApi() {}; 24 | 25 | /** 26 | * Destructs this MicroKernelModuleApi. 27 | */ 28 | virtual ~MicroKernelModuleApi() {}; 29 | }; 30 | 31 | } // end namespace kernel 32 | } // end namespace monarch 33 | #endif 34 | -------------------------------------------------------------------------------- /cpp/logging/Logging.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2008-2009 Digital Bazaar, Inc. All rights reserved. 3 | */ 4 | #include "monarch/logging/Logging.h" 5 | 6 | using namespace monarch::logging; 7 | 8 | bool Logging::initialize() 9 | { 10 | Category::initialize(); 11 | LoggingCategories::initialize(); 12 | Logger::initialize(); 13 | 14 | return true; 15 | } 16 | 17 | void Logging::cleanup() 18 | { 19 | Logger::cleanup(); 20 | LoggingCategories::cleanup(); 21 | Category::cleanup(); 22 | } 23 | -------------------------------------------------------------------------------- /cpp/logging/Makefile.in: -------------------------------------------------------------------------------- 1 | # Makefile to compile the module in this directory 2 | 3 | LIBRARIES = mologging 4 | mologging_HEADERS = $(wildcard *.h) 5 | mologging_SOURCES = $(wildcard *.cpp) 6 | 7 | DYNAMIC_LINK_LIBRARIES = mort moutil moio mocompress 8 | 9 | # ----------- Standard Makefile 10 | include @MONARCH_DIR@/setup/Makefile.base 11 | 12 | -------------------------------------------------------------------------------- /cpp/logging/OutputStreamLogger.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2007-2009 Digital Bazaar, Inc. All rights reserved. 3 | */ 4 | #include "monarch/logging/OutputStreamLogger.h" 5 | 6 | #include 7 | 8 | using namespace monarch::io; 9 | using namespace monarch::logging; 10 | 11 | OutputStreamLogger::OutputStreamLogger(OutputStream* stream, bool cleanup) : 12 | Logger() 13 | { 14 | setOutputStream(stream, cleanup, false); 15 | } 16 | 17 | OutputStreamLogger::~OutputStreamLogger() 18 | { 19 | close(); 20 | } 21 | 22 | void OutputStreamLogger::close() 23 | { 24 | mLock.lock(); 25 | { 26 | if(mStream != NULL) 27 | { 28 | mStream->close(); 29 | 30 | if(mCleanup) 31 | { 32 | delete mStream; 33 | mStream = NULL; 34 | } 35 | } 36 | } 37 | mLock.unlock(); 38 | } 39 | 40 | OutputStream* OutputStreamLogger::getOutputStream() 41 | { 42 | return mStream; 43 | } 44 | 45 | void OutputStreamLogger::setOutputStream(OutputStream* os, 46 | bool cleanup, bool closeCurrent) 47 | { 48 | mLock.lock(); 49 | { 50 | if(closeCurrent) 51 | { 52 | close(); 53 | } 54 | mStream = os; 55 | mCleanup = cleanup; 56 | } 57 | mLock.unlock(); 58 | } 59 | 60 | void OutputStreamLogger::log(const char* message, size_t length) 61 | { 62 | mLock.lock(); 63 | { 64 | if(mStream != NULL) 65 | { 66 | mStream->write(message, length); 67 | } 68 | } 69 | mLock.unlock(); 70 | } 71 | 72 | void OutputStreamLogger::flush() 73 | { 74 | mLock.lock(); 75 | { 76 | if(mStream != NULL) 77 | { 78 | mStream->flush(); 79 | } 80 | } 81 | mLock.unlock(); 82 | } 83 | -------------------------------------------------------------------------------- /cpp/mail/Makefile.in: -------------------------------------------------------------------------------- 1 | # Makefile to compile the module in this directory 2 | 3 | LIBRARIES = momail 4 | momail_HEADERS = $(wildcard *.h) 5 | momail_SOURCES = $(wildcard *.cpp) 6 | 7 | DYNAMIC_LINK_LIBRARIES = mort moio monet moutil modata mosql mosqlite3 8 | 9 | DYNAMIC_MACOS_LINK_LIBRARIES = mologging momodest mocrypto mocompress movalidation 10 | 11 | # ----------- Standard Makefile 12 | include @MONARCH_DIR@/setup/Makefile.base 13 | -------------------------------------------------------------------------------- /cpp/modest/Kernel.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2007-2009 Digital Bazaar, Inc. All rights reserved. 3 | */ 4 | #include "monarch/modest/Kernel.h" 5 | 6 | using namespace monarch::modest; 7 | using namespace monarch::rt; 8 | 9 | Kernel::Kernel() 10 | { 11 | // create engine and module library 12 | mEngine = new Engine(); 13 | mModuleLibrary = new ModuleLibrary(this); 14 | mVersion = "1.0"; 15 | } 16 | 17 | Kernel::~Kernel() 18 | { 19 | delete mEngine; 20 | delete mModuleLibrary; 21 | } 22 | 23 | void Kernel::runOperation(Operation& op) 24 | { 25 | // queue operation with engine 26 | getEngine()->queue(op); 27 | } 28 | 29 | Engine* Kernel::getEngine() 30 | { 31 | return mEngine; 32 | } 33 | 34 | ModuleLibrary* Kernel::getModuleLibrary() 35 | { 36 | return mModuleLibrary; 37 | } 38 | 39 | const char* Kernel::getVersion() 40 | { 41 | return mVersion; 42 | } 43 | 44 | Kernel* createModestKernel() 45 | { 46 | return new monarch::modest::Kernel(); 47 | } 48 | 49 | void freeModestKernel(Kernel* k) 50 | { 51 | delete k; 52 | } 53 | -------------------------------------------------------------------------------- /cpp/modest/Makefile.in: -------------------------------------------------------------------------------- 1 | # Makefile to compile the module in this directory 2 | 3 | LIBRARIES = momodest 4 | momodest_HEADERS = $(wildcard *.h) 5 | momodest_SOURCES = $(wildcard *.cpp) 6 | 7 | DYNAMIC_LINK_LIBRARIES = dl mort 8 | 9 | # ----------- Standard Makefile 10 | include @MONARCH_DIR@/setup/Makefile.base 11 | 12 | -------------------------------------------------------------------------------- /cpp/modest/ModuleInterface.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2007-2009 Digital Bazaar, Inc. All rights reserved. 3 | */ 4 | #ifndef monarch_modest_ModuleInterface_H 5 | #define monarch_modest_ModuleInterface_H 6 | 7 | namespace monarch 8 | { 9 | namespace modest 10 | { 11 | 12 | /** 13 | * A ModuleInterface defines the interface through which an application can 14 | * access a Module. This class should be extended to provide whatever interface 15 | * is available for interacting with a specific Module. 16 | * 17 | * @author Dave Longley 18 | */ 19 | class ModuleInterface 20 | { 21 | public: 22 | /** 23 | * Creates a new ModuleInterface. 24 | */ 25 | ModuleInterface() {}; 26 | 27 | /** 28 | * Destructs this ModuleInterface. 29 | */ 30 | virtual ~ModuleInterface() {}; 31 | }; 32 | 33 | } // end namespace modest 34 | } // end namespace monarch 35 | #endif 36 | -------------------------------------------------------------------------------- /cpp/modest/Operation.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2007-2009 Digital Bazaar, Inc. All rights reserved. 3 | */ 4 | #include "monarch/modest/Operation.h" 5 | 6 | using namespace monarch::modest; 7 | using namespace monarch::rt; 8 | 9 | Operation::Operation(Runnable& r) : 10 | Collectable(new OperationImpl(r)) 11 | { 12 | } 13 | 14 | Operation::Operation(RunnableRef& r) : 15 | Collectable(new OperationImpl(r)) 16 | { 17 | } 18 | 19 | Operation::Operation(OperationImpl* impl) : 20 | Collectable(impl) 21 | { 22 | } 23 | 24 | Operation::~Operation() 25 | { 26 | } 27 | -------------------------------------------------------------------------------- /cpp/modest/OperationGuardChain.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2007-2010 Digital Bazaar, Inc. All rights reserved. 3 | */ 4 | #include "monarch/modest/OperationGuardChain.h" 5 | 6 | #include "monarch/modest/Operation.h" 7 | 8 | using namespace monarch::modest; 9 | 10 | OperationGuardChain::OperationGuardChain( 11 | OperationGuard* g1, OperationGuard* g2) : 12 | mGuard1(g1), 13 | mGuard2(g2) 14 | { 15 | } 16 | 17 | OperationGuardChain::OperationGuardChain( 18 | OperationGuardRef& g1, OperationGuard* g2) : 19 | mGuard1(&(*g1)), 20 | mGuardReference1(g1), 21 | mGuard2(g2) 22 | { 23 | } 24 | 25 | OperationGuardChain::OperationGuardChain( 26 | OperationGuard* g1, OperationGuardRef& g2) : 27 | mGuard1(g1), 28 | mGuard2(&(*g2)), 29 | mGuardReference2(g2) 30 | { 31 | } 32 | 33 | OperationGuardChain::OperationGuardChain( 34 | OperationGuardRef& g1, OperationGuardRef& g2) : 35 | mGuard1(&(*g1)), 36 | mGuardReference1(g1), 37 | mGuard2(&(*g2)), 38 | mGuardReference2(g2) 39 | { 40 | } 41 | 42 | OperationGuardChain::~OperationGuardChain() 43 | { 44 | } 45 | 46 | bool OperationGuardChain::canExecuteOperation(Operation &op) 47 | { 48 | return 49 | mGuard1->canExecuteOperation(op) && 50 | (mGuard2 == NULL || mGuard2->canExecuteOperation(op)); 51 | } 52 | 53 | bool OperationGuardChain::mustCancelOperation(Operation &op) 54 | { 55 | return 56 | mGuard1->mustCancelOperation(op) || 57 | (mGuard2 != NULL && mGuard2->canExecuteOperation(op)); 58 | } 59 | -------------------------------------------------------------------------------- /cpp/modest/OperationRunner.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2007-2009 Digital Bazaar, Inc. All rights reserved. 3 | */ 4 | #ifndef monarch_modest_OperationRunner_H 5 | #define monarch_modest_OperationRunner_H 6 | 7 | #include "monarch/rt/Runnable.h" 8 | #include "monarch/modest/Operation.h" 9 | #include "monarch/modest/OperationGuard.h" 10 | #include "monarch/modest/StateMutator.h" 11 | 12 | namespace monarch 13 | { 14 | namespace modest 15 | { 16 | 17 | /** 18 | * An OperationRunner is an interface that provides a method for running 19 | * Operations. Any passed Operation may have OperationGuards or StateMutators 20 | * added to it in order to provide additional logic that is specific to 21 | * the OperationRunner's implementation. 22 | * 23 | * @author Dave Longley 24 | */ 25 | class OperationRunner 26 | { 27 | public: 28 | /** 29 | * Creates a new OperationRunner. 30 | */ 31 | OperationRunner() {}; 32 | 33 | /** 34 | * Destructs this OperationRunner. 35 | */ 36 | virtual ~OperationRunner() {}; 37 | 38 | /** 39 | * Queues the passed Operation with an appropriate modest engine for 40 | * execution. OperationGuards and/or StateMutators may be added to the 41 | * Operation. 42 | * 43 | * @param op the Operation to queue with a modest engine for execution. 44 | */ 45 | virtual void runOperation(Operation& op) = 0; 46 | }; 47 | 48 | } // end namespace modest 49 | } // end namespace monarch 50 | #endif 51 | -------------------------------------------------------------------------------- /cpp/modest/StateMutator.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2007-2010 Digital Bazaar, Inc. All rights reserved. 3 | */ 4 | #ifndef monarch_modest_StateMutator_H 5 | #define monarch_modest_StateMutator_H 6 | 7 | #include "monarch/rt/Collectable.h" 8 | 9 | namespace monarch 10 | { 11 | namespace modest 12 | { 13 | 14 | // forward declare Operation 15 | class Operation; 16 | 17 | /** 18 | * A StateMutator is an interface used by an Operation to alter the current 19 | * state directly before and/or after the Operation's execution. 20 | * 21 | * The state to alter should be accessible by the class that implements this 22 | * interface or made accessible via the user data attribute of the Operation. 23 | * 24 | * @author Dave Longley 25 | */ 26 | class StateMutator 27 | { 28 | public: 29 | /** 30 | * Creates a new StateMutator. 31 | */ 32 | StateMutator() {}; 33 | 34 | /** 35 | * Destructs this StateMutator. 36 | */ 37 | virtual ~StateMutator() {}; 38 | 39 | /** 40 | * Alters the current state directly before an Operation executes. 41 | * 42 | * @param op the Operation to be executed. 43 | */ 44 | virtual void mutatePreExecutionState(Operation& op) {}; 45 | 46 | /** 47 | * Alters the current state directly after an Operation finishes or 48 | * was canceled. 49 | * 50 | * The passed Operation may be checked to see if it finished or was 51 | * canceled, etc. 52 | * 53 | * @param op the Operation that finished or was canceled. 54 | */ 55 | virtual void mutatePostExecutionState(Operation& op) {}; 56 | }; 57 | 58 | // define a reference counted StateMutator type 59 | typedef monarch::rt::Collectable StateMutatorRef; 60 | 61 | } // end namespace modest 62 | } // end namespace monarch 63 | #endif 64 | -------------------------------------------------------------------------------- /cpp/modest/StateMutatorChain.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2007-2011 Digital Bazaar, Inc. All rights reserved. 3 | */ 4 | #include "monarch/modest/StateMutatorChain.h" 5 | 6 | using namespace monarch::modest; 7 | 8 | StateMutatorChain::StateMutatorChain( 9 | StateMutator* g1, StateMutator* g2) : 10 | mMutator1(g1), 11 | mMutator2(g2) 12 | { 13 | } 14 | 15 | StateMutatorChain::StateMutatorChain( 16 | StateMutatorRef& g1, StateMutator* g2) : 17 | mMutator1(&(*g1)), 18 | mMutatorReference1(g1), 19 | mMutator2(g2) 20 | { 21 | } 22 | 23 | StateMutatorChain::StateMutatorChain( 24 | StateMutator* g1, StateMutatorRef& g2) : 25 | mMutator1(g1), 26 | mMutator2(&(*g2)), 27 | mMutatorReference2(g2) 28 | { 29 | } 30 | 31 | StateMutatorChain::StateMutatorChain( 32 | StateMutatorRef& g1, StateMutatorRef& g2) : 33 | mMutator1(&(*g1)), 34 | mMutatorReference1(g1), 35 | mMutator2(&(*g2)), 36 | mMutatorReference2(g2) 37 | { 38 | } 39 | 40 | StateMutatorChain::~StateMutatorChain() 41 | { 42 | } 43 | 44 | void StateMutatorChain::mutatePreExecutionState(Operation& op) 45 | { 46 | mMutator1->mutatePreExecutionState(op); 47 | if(mMutator2 != NULL) 48 | { 49 | mMutator2->mutatePreExecutionState(op); 50 | } 51 | } 52 | 53 | void StateMutatorChain::mutatePostExecutionState(Operation& op) 54 | { 55 | mMutator1->mutatePostExecutionState(op); 56 | if(mMutator2 != NULL) 57 | { 58 | mMutator2->mutatePostExecutionState(op); 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /cpp/mysql/Makefile.in: -------------------------------------------------------------------------------- 1 | # Makefile to compile the module in this directory 2 | 3 | ifeq (@BUILD_MYSQL@,yes) 4 | LIBRARIES = momysql 5 | momysql_HEADERS = $(wildcard *.h) 6 | momysql_SOURCES = $(wildcard *.cpp) 7 | 8 | DYNAMIC_LINK_LIBRARIES = mort mosql mysqlclient 9 | HEADER_DIST_DIR = dist/include/monarch/sql/mysql 10 | 11 | DYNAMIC_MACOS_LINK_LIBRARIES += moutil momodest moio mologging mocompress modata movalidation 12 | DYNAMIC_WINDOWS_LINK_LIBRARIES += moutil momodest moio mologging mocompress modata movalidation 13 | 14 | CXX_FLAGS += @MYSQL_CFLAGS@ 15 | LD_FLAGS += -rdynamic -L/usr/lib/mysql 16 | 17 | endif 18 | 19 | # ----------- Standard Makefile 20 | include @MONARCH_DIR@/setup/Makefile.base 21 | -------------------------------------------------------------------------------- /cpp/mysql/MySqlConnectionPool.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2007-2011 Digital Bazaar, Inc. All rights reserved. 3 | */ 4 | #include "monarch/sql/mysql/MySqlConnectionPool.h" 5 | 6 | using namespace monarch::sql; 7 | using namespace monarch::sql::mysql; 8 | 9 | MySqlConnectionPool::MySqlConnectionPool( 10 | const char* url, unsigned int poolSize) : 11 | AbstractConnectionPool(url, poolSize), 12 | mNoEngineSubstitution(true), 13 | mTimeZone(NULL) 14 | { 15 | } 16 | 17 | MySqlConnectionPool::~MySqlConnectionPool() 18 | { 19 | free(mTimeZone); 20 | } 21 | 22 | PooledConnection* MySqlConnectionPool::createConnection() 23 | { 24 | PooledConnection* rval = NULL; 25 | 26 | // create and connect connection 27 | MySqlConnection* c = new MySqlConnection(); 28 | if(c->connect(&mUrl)) 29 | { 30 | // handle engine substitution flag 31 | bool pass = true; 32 | if(mNoEngineSubstitution) 33 | { 34 | pass = c->setSqlMode("NO_ENGINE_SUBSTITUTION"); 35 | } 36 | 37 | // handle timezone 38 | if(pass) 39 | { 40 | // default to UTC 41 | pass = c->setTimeZone(mTimeZone); 42 | } 43 | 44 | if(pass) 45 | { 46 | // wrap in a pooled connection 47 | rval = new PooledConnection(this, c); 48 | } 49 | } 50 | 51 | if(rval == NULL) 52 | { 53 | delete c; 54 | } 55 | 56 | return rval; 57 | } 58 | 59 | void MySqlConnectionPool::setNoEngineSubstitution(bool on) 60 | { 61 | mNoEngineSubstitution = on; 62 | } 63 | 64 | void MySqlConnectionPool::setTimeZone(const char* tz) 65 | { 66 | free(mTimeZone); 67 | mTimeZone = (tz == NULL) ? NULL : strdup(tz); 68 | } 69 | -------------------------------------------------------------------------------- /cpp/net/ConnectionServicer.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2007-2009 Digital Bazaar, Inc. All rights reserved. 3 | */ 4 | #ifndef monarch_net_ConnectionServicer_H 5 | #define monarch_net_ConnectionServicer_H 6 | 7 | #include "monarch/net/ConnectionService.h" 8 | 9 | namespace monarch 10 | { 11 | namespace net 12 | { 13 | 14 | /** 15 | * A ConnectionServicer services a Connection in some implementation specific 16 | * fashion. 17 | * 18 | * @author Dave Longley 19 | */ 20 | class ConnectionServicer 21 | { 22 | public: 23 | /** 24 | * Creates a new ConnectionServicer. 25 | */ 26 | ConnectionServicer() {}; 27 | 28 | /** 29 | * Destructs this ConnectionServicer. 30 | */ 31 | virtual ~ConnectionServicer() {}; 32 | 33 | /** 34 | * Services the passed Connection. This method should end by closing the 35 | * passed Connection. After this method returns, the Connection will be 36 | * automatically closed, if necessary, and cleaned up. 37 | * 38 | * @param c the Connection to service. 39 | */ 40 | virtual void serviceConnection(Connection* c) = 0; 41 | }; 42 | 43 | } // end namespace net 44 | } // end namespace monarch 45 | #endif 46 | -------------------------------------------------------------------------------- /cpp/net/Datagram.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2007-2009 Digital Bazaar, Inc. All rights reserved. 3 | */ 4 | #include "monarch/net/Datagram.h" 5 | 6 | #include 7 | #include 8 | 9 | using namespace std; 10 | using namespace monarch::io; 11 | using namespace monarch::net; 12 | 13 | Datagram::Datagram(int capacity) : 14 | mAddress(NULL), 15 | mBuffer(capacity) 16 | { 17 | } 18 | 19 | Datagram::Datagram(InternetAddressRef& address, int capacity) : 20 | mAddress(address), 21 | mBuffer(capacity) 22 | { 23 | } 24 | 25 | Datagram::~Datagram() 26 | { 27 | } 28 | 29 | void Datagram::setAddress(InternetAddressRef& address) 30 | { 31 | mAddress = address; 32 | } 33 | 34 | InternetAddressRef& Datagram::getAddress() 35 | { 36 | return mAddress; 37 | } 38 | 39 | ByteBuffer* Datagram::getBuffer() 40 | { 41 | return &mBuffer; 42 | } 43 | 44 | void Datagram::assignString(const string& str) 45 | { 46 | mBuffer.reAllocate(str.length()); 47 | mBuffer.put(str.c_str(), str.length(), false); 48 | } 49 | 50 | string Datagram::getString() 51 | { 52 | return (mBuffer.length() > 0) ? 53 | string(mBuffer.data(), mBuffer.length()) : ""; 54 | } 55 | -------------------------------------------------------------------------------- /cpp/net/DatagramService.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2007-2011 Digital Bazaar, Inc. All rights reserved. 3 | */ 4 | #include "monarch/net/DatagramService.h" 5 | 6 | #include "monarch/net/Server.h" 7 | 8 | using namespace monarch::modest; 9 | using namespace monarch::net; 10 | 11 | DatagramService::DatagramService( 12 | Server* server, InternetAddress* address, DatagramServicer* servicer, 13 | const char* name) : 14 | PortService(server, address, name), 15 | mServicer(servicer), 16 | mSocket(NULL) 17 | { 18 | } 19 | 20 | DatagramService::~DatagramService() 21 | { 22 | // ensure service is stopped 23 | DatagramService::stop(); 24 | } 25 | 26 | void DatagramService::run() 27 | { 28 | // service datagrams 29 | mServicer->serviceDatagrams(mSocket, mOperation); 30 | 31 | // close socket 32 | mSocket->close(); 33 | } 34 | 35 | Operation DatagramService::initialize() 36 | { 37 | Operation rval(NULL); 38 | 39 | // create datagram socket 40 | mSocket = new DatagramSocket(); 41 | 42 | // bind socket to the address 43 | if(mSocket->bind(getAddress()) && mServicer->initialize(mSocket)) 44 | { 45 | // create Operation for running service 46 | rval = *this; 47 | } 48 | 49 | return rval; 50 | } 51 | 52 | void DatagramService::cleanup() 53 | { 54 | delete mSocket; 55 | mSocket = NULL; 56 | } 57 | -------------------------------------------------------------------------------- /cpp/net/DatagramServicer.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2007-2010 Digital Bazaar, Inc. All rights reserved. 3 | */ 4 | #ifndef monarch_net_DatagramServicer_H 5 | #define monarch_net_DatagramServicer_H 6 | 7 | #include "monarch/modest/Operation.h" 8 | #include "monarch/net/DatagramSocket.h" 9 | 10 | namespace monarch 11 | { 12 | namespace net 13 | { 14 | 15 | /** 16 | * A DatagramServicer receives Datagrams from the passed DatagramSocket and 17 | * services them in some implementation specific fashion. 18 | * 19 | * @author Dave Longley 20 | */ 21 | class DatagramServicer 22 | { 23 | public: 24 | /** 25 | * Creates a new DatagramServicer. 26 | */ 27 | DatagramServicer() {}; 28 | 29 | /** 30 | * Destructs this DatagramServicer. 31 | */ 32 | virtual ~DatagramServicer() {}; 33 | 34 | /** 35 | * Performs initialization work on the DatagramSocket once it is 36 | * bound, if any is necessary, and returns false if an exception occurs. 37 | * 38 | * @param s the DatagramSocket to be serviced. 39 | * 40 | * @return true if successful, false if an exception occurred. 41 | */ 42 | virtual bool initialize(DatagramSocket* s) { return true; }; 43 | 44 | /** 45 | * Receives Datagrams from the passed DatagramSocket and services them. 46 | * 47 | * @param s the DatagramSocket with Datagrams to service. 48 | * @param op the current Operation, to be checked for interruptions. 49 | */ 50 | virtual void serviceDatagrams( 51 | DatagramSocket* s, monarch::modest::Operation& op) = 0; 52 | }; 53 | 54 | } // end namespace net 55 | } // end namespace monarch 56 | #endif 57 | -------------------------------------------------------------------------------- /cpp/net/DatagramSocket.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2007-2009 Digital Bazaar, Inc. All rights reserved. 3 | */ 4 | #include "monarch/net/DatagramSocket.h" 5 | 6 | using namespace monarch::io; 7 | using namespace monarch::net; 8 | 9 | DatagramSocket::DatagramSocket() 10 | { 11 | } 12 | 13 | DatagramSocket::~DatagramSocket() 14 | { 15 | } 16 | 17 | bool DatagramSocket::send(DatagramRef& datagram) 18 | { 19 | ByteBuffer* buffer = datagram->getBuffer(); 20 | return UdpSocket::sendDatagram( 21 | buffer->data(), buffer->length(), &(*datagram->getAddress())); 22 | } 23 | 24 | bool DatagramSocket::receive(DatagramRef& datagram) 25 | { 26 | bool rval = false; 27 | 28 | // clear buffer and receive datagram 29 | ByteBuffer* buffer = datagram->getBuffer(); 30 | buffer->clear(); 31 | int size = UdpSocket::receiveDatagram( 32 | buffer->data(), buffer->freeSpace(), &(*datagram->getAddress())); 33 | if(size != -1) 34 | { 35 | // extend buffer to fill size of received datagram 36 | datagram->getBuffer()->extend(size); 37 | rval = true; 38 | } 39 | 40 | return rval; 41 | } 42 | -------------------------------------------------------------------------------- /cpp/net/Makefile.in: -------------------------------------------------------------------------------- 1 | # Makefile to compile the module in this directory 2 | 3 | LIBRARIES = monet 4 | monet_HEADERS = $(wildcard *.h) 5 | monet_SOURCES = $(wildcard *.cpp) 6 | 7 | DYNAMIC_LINK_LIBRARIES = mort moutil momodest moio mocrypto mologging 8 | 9 | DYNAMIC_LINUX_LINK_LIBRARIES = ssl 10 | DYNAMIC_MACOS_LINK_LIBRARIES = crypto ssl mocompress 11 | DYNAMIC_WINDOWS_LINK_LIBRARIES = libeay32 ssleay32 ws2_32 12 | 13 | # ----------- Standard Makefile 14 | include @MONARCH_DIR@/setup/Makefile.base 15 | -------------------------------------------------------------------------------- /cpp/net/NullSocketDataPresenter.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2007-2009 Digital Bazaar, Inc. All rights reserved. 3 | */ 4 | #ifndef monarch_net_NullSocketDataPresenter_H 5 | #define monarch_net_NullSocketDataPresenter_H 6 | 7 | #include "monarch/net/SocketDataPresenter.h" 8 | 9 | namespace monarch 10 | { 11 | namespace net 12 | { 13 | 14 | /** 15 | * A NullSocketDataPresenter provides no wrapper for transforming 16 | * incoming data for presentation and outgoing data for transmission, but 17 | * instead returns any Socket it is passed as-is. 18 | * 19 | * @author Dave Longley 20 | */ 21 | class NullSocketDataPresenter : public SocketDataPresenter 22 | { 23 | public: 24 | /** 25 | * Creates a new NullSocketDataPresenter. 26 | */ 27 | NullSocketDataPresenter() {}; 28 | 29 | /** 30 | * Destructs this NullSocketDataPresenter. 31 | */ 32 | virtual ~NullSocketDataPresenter() {}; 33 | 34 | /** 35 | * Wraps the passed Socket if this presenter can provide the presentation 36 | * layer for its data. The created Socket should cleanup the passed Socket 37 | * when it is freed. 38 | * 39 | * @param s the Socket to wrap. 40 | * @param secure true if the wrapper is considered a secure protocol, 41 | * like SSL, false if not. 42 | * 43 | * @return the wrapped Socket or NULL if this presenter cannot provide 44 | * the presentation layer for the socket data. 45 | */ 46 | virtual Socket* createPresentationWrapper(Socket* s, bool& secure); 47 | }; 48 | 49 | inline Socket* NullSocketDataPresenter::createPresentationWrapper( 50 | Socket* s, bool& secure) 51 | { 52 | secure = false; 53 | return s; 54 | } 55 | 56 | } // end namespace net 57 | } // end namespace monarch 58 | #endif 59 | -------------------------------------------------------------------------------- /cpp/net/SocketDataPresenterList.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2007-2010 Digital Bazaar, Inc. All rights reserved. 3 | */ 4 | #include "monarch/net/SocketDataPresenterList.h" 5 | 6 | using namespace std; 7 | using namespace monarch::net; 8 | 9 | SocketDataPresenterList::SocketDataPresenterList(bool cleanup) : 10 | mCleanup(cleanup) 11 | { 12 | } 13 | 14 | SocketDataPresenterList::~SocketDataPresenterList() 15 | { 16 | if(mCleanup) 17 | { 18 | // clean up data presenters 19 | for(vector::iterator i = mDataPresenters.begin(); 20 | i != mDataPresenters.end(); ++i) 21 | { 22 | delete *i; 23 | } 24 | } 25 | } 26 | 27 | void SocketDataPresenterList::add(SocketDataPresenter* sdp) 28 | { 29 | mLock.lockExclusive(); 30 | { 31 | mDataPresenters.push_back(sdp); 32 | } 33 | mLock.unlockExclusive(); 34 | } 35 | 36 | Socket* SocketDataPresenterList::createPresentationWrapper( 37 | Socket* s, bool& secure) 38 | { 39 | Socket* rval = NULL; 40 | 41 | mLock.lockShared(); 42 | { 43 | // use data presenters to create a socket wrapper 44 | for(vector::iterator i = mDataPresenters.begin(); 45 | i != mDataPresenters.end() && rval == NULL; ++i) 46 | { 47 | rval = (*i)->createPresentationWrapper(s, secure); 48 | } 49 | } 50 | mLock.unlockShared(); 51 | 52 | return rval; 53 | } 54 | -------------------------------------------------------------------------------- /cpp/net/SocketInputStream.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2007-2011 Digital Bazaar, Inc. All rights reserved. 3 | */ 4 | #include "monarch/net/SocketInputStream.h" 5 | 6 | using namespace monarch::io; 7 | using namespace monarch::net; 8 | 9 | SocketInputStream::SocketInputStream(Socket* s) : 10 | mSocket(s) 11 | { 12 | } 13 | 14 | SocketInputStream::~SocketInputStream() 15 | { 16 | } 17 | 18 | int SocketInputStream::read(char* b, int length) 19 | { 20 | // read from the socket 21 | return mSocket->receive(b, length); 22 | } 23 | -------------------------------------------------------------------------------- /cpp/net/SocketInputStream.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2007-2009 Digital Bazaar, Inc. All rights reserved. 3 | */ 4 | #ifndef monarch_net_SocketInputStream_H 5 | #define monarch_net_SocketInputStream_H 6 | 7 | #include "monarch/io/InputStream.h" 8 | #include "monarch/net/Socket.h" 9 | 10 | namespace monarch 11 | { 12 | namespace net 13 | { 14 | 15 | /** 16 | * A SocketInputStream is used to read bytes from a Socket. 17 | * 18 | * @author Dave Longley 19 | */ 20 | class SocketInputStream : public monarch::io::InputStream 21 | { 22 | protected: 23 | /** 24 | * The Socket to read from. 25 | */ 26 | Socket* mSocket; 27 | 28 | public: 29 | /** 30 | * Creates a new SocketInputStream. 31 | * 32 | * @param s the Socket to read from. 33 | */ 34 | SocketInputStream(Socket* s); 35 | 36 | /** 37 | * Destructs this SocketInputStream. 38 | */ 39 | virtual ~SocketInputStream(); 40 | 41 | /** 42 | * Reads some bytes from the stream. This method will block until at least 43 | * one byte can be read or until the end of the stream is reached. A 44 | * value of 0 will be returned if the end of the stream has been reached, 45 | * a value of -1 will be returned if an IO exception occurred, otherwise 46 | * the number of bytes read will be returned. 47 | * 48 | * @param b the array of bytes to fill. 49 | * @param length the maximum number of bytes to read into the buffer. 50 | * 51 | * @return the number of bytes read from the stream or 0 if the end of the 52 | * stream has been reached or -1 if an IO exception occurred. 53 | */ 54 | virtual int read(char* b, int length); 55 | }; 56 | 57 | } // end namespace net 58 | } // end namespace monarch 59 | #endif 60 | -------------------------------------------------------------------------------- /cpp/net/SocketOutputStream.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2007-2011 Digital Bazaar, Inc. All rights reserved. 3 | */ 4 | #include "monarch/net/SocketOutputStream.h" 5 | 6 | using namespace monarch::io; 7 | using namespace monarch::net; 8 | 9 | SocketOutputStream::SocketOutputStream(Socket* s) : 10 | mSocket(s) 11 | { 12 | } 13 | 14 | SocketOutputStream::~SocketOutputStream() 15 | { 16 | } 17 | 18 | inline bool SocketOutputStream::write(const char* b, int length) 19 | { 20 | // send data through the socket 21 | return mSocket->send(b, length); 22 | } 23 | -------------------------------------------------------------------------------- /cpp/net/SocketOutputStream.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2007-2009 Digital Bazaar, Inc. All rights reserved. 3 | */ 4 | #ifndef monarch_net_SocketOutputStream_H 5 | #define monarch_net_SocketOutputStream_H 6 | 7 | #include "monarch/io/OutputStream.h" 8 | #include "monarch/net/Socket.h" 9 | 10 | namespace monarch 11 | { 12 | namespace net 13 | { 14 | 15 | /** 16 | * A SocketOutputStream is used to write bytes to a Socket. 17 | * 18 | * @author Dave Longley 19 | */ 20 | class SocketOutputStream : public monarch::io::OutputStream 21 | { 22 | protected: 23 | /** 24 | * The Socket to write to. 25 | */ 26 | Socket* mSocket; 27 | 28 | public: 29 | /** 30 | * Creates a new SocketOutputStream. 31 | * 32 | * @param s the Socket to write to. 33 | */ 34 | SocketOutputStream(Socket* s); 35 | 36 | /** 37 | * Destructs this SocketOutputStream. 38 | */ 39 | virtual ~SocketOutputStream(); 40 | 41 | /** 42 | * Writes some bytes to the stream. 43 | * 44 | * @param b the array of bytes to write. 45 | * @param length the number of bytes to write to the stream. 46 | * 47 | * @return true if the write was successful, false if an IO exception 48 | * occurred. 49 | */ 50 | virtual bool write(const char* b, int length); 51 | }; 52 | 53 | } // end namespace net 54 | } // end namespace monarch 55 | #endif 56 | -------------------------------------------------------------------------------- /cpp/net/SslSession.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2008-2009 Digital Bazaar, Inc. All rights reserved. 3 | */ 4 | #ifndef monarch_net_SslSession_H 5 | #define monarch_net_SslSession_H 6 | 7 | #include "monarch/rt/Collectable.h" 8 | 9 | #include 10 | 11 | namespace monarch 12 | { 13 | namespace net 14 | { 15 | 16 | /** 17 | * The SslSessionImpl is a simple container that will store an 18 | * SSL_SESSION and free it when it is destructed. 19 | * 20 | * @author Dave Longley 21 | */ 22 | class SslSessionImpl 23 | { 24 | public: 25 | SSL_SESSION* session; 26 | SslSessionImpl(SSL_SESSION* s = NULL) 27 | { 28 | session = s; 29 | } 30 | 31 | virtual ~SslSessionImpl() 32 | { 33 | SSL_SESSION_free(session); 34 | } 35 | }; 36 | 37 | /** 38 | * The SslSession type is a reference counted container for an SSL_SESSION. 39 | */ 40 | typedef monarch::rt::Collectable SslSession; 41 | 42 | } // end namespace net 43 | } // end namespace monarch 44 | #endif 45 | -------------------------------------------------------------------------------- /cpp/net/TcpSocket.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2007-2010 Digital Bazaar, Inc. All rights reserved. 3 | */ 4 | #include "monarch/net/TcpSocket.h" 5 | 6 | #include "monarch/net/SocketDefinitions.h" 7 | #include "monarch/io/PeekInputStream.h" 8 | #include "monarch/net/SocketInputStream.h" 9 | #include "monarch/net/SocketOutputStream.h" 10 | 11 | #include 12 | 13 | using namespace monarch::io; 14 | using namespace monarch::net; 15 | 16 | TcpSocket::TcpSocket() 17 | { 18 | } 19 | 20 | TcpSocket::~TcpSocket() 21 | { 22 | } 23 | 24 | bool TcpSocket::acquireFileDescriptor(SocketAddress::CommunicationDomain domain) 25 | { 26 | bool rval = true; 27 | 28 | if(mFileDescriptor == -1) 29 | { 30 | // use PF_INET = "protocol family internet" (which just so happens to 31 | // have the same value as AF_INET but that's only because different 32 | // protocols were never used with the same address family 33 | if(domain == SocketAddress::IPv6) 34 | { 35 | // use IPv6 36 | rval = create(PF_INET6, SOCK_STREAM, IPPROTO_TCP); 37 | } 38 | else 39 | { 40 | // default to IPv4 41 | rval = create(PF_INET, SOCK_STREAM, IPPROTO_TCP); 42 | } 43 | } 44 | 45 | return rval; 46 | } 47 | 48 | Socket* TcpSocket::createConnectedSocket(int fd) 49 | { 50 | // create a new TcpSocket 51 | TcpSocket* socket = new TcpSocket(); 52 | socket->mFileDescriptor = fd; 53 | socket->mBound = true; 54 | socket->mConnected = true; 55 | 56 | // initialize input and output 57 | socket->initializeInput(); 58 | socket->initializeOutput(); 59 | 60 | return socket; 61 | } 62 | -------------------------------------------------------------------------------- /cpp/net/TcpSocket.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2007-2010 Digital Bazaar, Inc. All rights reserved. 3 | */ 4 | #ifndef monarch_net_TcpSocket_H 5 | #define monarch_net_TcpSocket_H 6 | 7 | #include "monarch/net/AbstractSocket.h" 8 | 9 | namespace monarch 10 | { 11 | namespace net 12 | { 13 | 14 | /** 15 | * A TcpSocket is a Socket that uses the TCP/IP protocol. 16 | * 17 | * @author Dave Longley 18 | */ 19 | class TcpSocket : public AbstractSocket 20 | { 21 | public: 22 | /** 23 | * Creates a new TcpSocket. 24 | */ 25 | TcpSocket(); 26 | 27 | /** 28 | * Destructs this TcpSocket. 29 | */ 30 | virtual ~TcpSocket(); 31 | 32 | protected: 33 | /** 34 | * Acquiring a file descriptor for this Socket. This method must be called 35 | * before trying to use this Socket. 36 | * 37 | * This method is called automatically by the default implementation. 38 | * 39 | * @param domain the communication domain for this Socket (i.e. IPv4, IPv6). 40 | * 41 | * @return true if the file descriptor could be acquired, false if 42 | * an exception occurred. 43 | */ 44 | virtual bool acquireFileDescriptor( 45 | SocketAddress::CommunicationDomain domain); 46 | 47 | /** 48 | * Creates a new Socket with the given file descriptor that points to 49 | * the socket for an accepted connection. 50 | * 51 | * @param fd the file descriptor for the socket. 52 | * 53 | * @return the allocated Socket. 54 | */ 55 | virtual Socket* createConnectedSocket(int fd); 56 | }; 57 | 58 | } // end namespace net 59 | } // end namespace monarch 60 | #endif 61 | -------------------------------------------------------------------------------- /cpp/rt/Atomic.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2009-2011 Digital Bazaar, Inc. All rights reserved. 3 | */ 4 | #include "monarch/rt/Atomic.h" 5 | 6 | // include NULL 7 | #include 8 | 9 | #ifdef WIN32 10 | #include 11 | #include 12 | #endif 13 | 14 | using namespace monarch::rt; 15 | 16 | void* Atomic::mallocAligned(size_t size) 17 | { 18 | #if 0//def WIN32 19 | // FIXME: _aligned_malloc is defined by msvcrXX.dll ... which is giving 20 | // us headaches figuring out with mingw32 ... for now, since we build with 21 | // gcc, memory should already be aligned on the proper boundaries 22 | // automatically ... but should we do some strange packing or other funny 23 | // business like compiling using MSVC, we might want to revisit this 24 | 25 | // must align on a 32-bit boundary for windows 26 | return _aligned_malloc(size, ALIGN_BITS); 27 | #else 28 | return malloc(size); 29 | #endif 30 | } 31 | 32 | void Atomic::freeAligned(void* ptr) 33 | { 34 | #if 0//def WIN32 35 | _aligned_free(ptr); 36 | #else 37 | free(ptr); 38 | #endif 39 | } 40 | -------------------------------------------------------------------------------- /cpp/rt/DynamicObjectIterator.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2007-2009 Digital Bazaar, Inc. All rights reserved. 3 | */ 4 | #include "monarch/rt/DynamicObjectIterator.h" 5 | 6 | #include 7 | 8 | using namespace monarch::rt; 9 | 10 | DynamicObjectIteratorImpl::DynamicObjectIteratorImpl(DynamicObject& dyno) : 11 | mObject(dyno), 12 | mIndex(-1) 13 | { 14 | } 15 | 16 | DynamicObjectIteratorImpl::~DynamicObjectIteratorImpl() 17 | { 18 | } 19 | 20 | void DynamicObjectIteratorImpl::remove() 21 | { 22 | } 23 | 24 | const char* DynamicObjectIteratorImpl::getName() 25 | { 26 | return NULL; 27 | } 28 | 29 | int DynamicObjectIteratorImpl::getIndex() 30 | { 31 | return mIndex; 32 | } 33 | 34 | DynamicObjectIterator::DynamicObjectIterator(DynamicObjectIteratorImpl* impl) : 35 | Collectable(impl) 36 | { 37 | } 38 | 39 | DynamicObjectIterator::~DynamicObjectIterator() 40 | { 41 | } 42 | -------------------------------------------------------------------------------- /cpp/rt/ExclusiveLock.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2007-2010 Digital Bazaar, Inc. All rights reserved. 3 | */ 4 | #include "monarch/rt/ExclusiveLock.h" 5 | 6 | #include "monarch/rt/System.h" 7 | #include "monarch/rt/Thread.h" 8 | 9 | using namespace monarch::rt; 10 | 11 | ExclusiveLock::ExclusiveLock() 12 | { 13 | } 14 | 15 | ExclusiveLock::~ExclusiveLock() 16 | { 17 | } 18 | 19 | inline void ExclusiveLock::lock() 20 | { 21 | mMonitor.enter(); 22 | } 23 | 24 | inline bool ExclusiveLock::tryLock() 25 | { 26 | return mMonitor.tryEnter(); 27 | } 28 | 29 | inline void ExclusiveLock::unlock() 30 | { 31 | mMonitor.exit(); 32 | } 33 | 34 | inline void ExclusiveLock::notify() 35 | { 36 | mMonitor.notify(); 37 | } 38 | 39 | inline void ExclusiveLock::notifyAll() 40 | { 41 | mMonitor.notifyAll(); 42 | } 43 | 44 | inline bool ExclusiveLock::wait(uint32_t timeout) 45 | { 46 | // instruct the current thread to wait to enter this Object's monitor 47 | return Thread::waitToEnter(&mMonitor, timeout); 48 | } 49 | 50 | bool ExclusiveLock::wait(uint32_t& timeout, bool* condition, bool stop) 51 | { 52 | bool rval = true; 53 | 54 | uint32_t remaining = timeout; 55 | uint64_t st = System::getCurrentMilliseconds(); 56 | uint64_t et; 57 | uint64_t dt; 58 | while(rval && (*condition != stop) && (timeout == 0 || remaining > 0)) 59 | { 60 | rval = wait(remaining); 61 | if(rval && timeout > 0) 62 | { 63 | // decrement remaining time 64 | et = System::getCurrentMilliseconds(); 65 | dt = et - st; 66 | remaining = (dt > remaining ? 0 : remaining - dt); 67 | st = et; 68 | } 69 | } 70 | timeout = remaining; 71 | 72 | return rval; 73 | } 74 | -------------------------------------------------------------------------------- /cpp/rt/Iterator.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2007-2009 Digital Bazaar, Inc. All rights reserved. 3 | */ 4 | #ifndef monarch_rt_Iterator_H 5 | #define monarch_rt_Iterator_H 6 | 7 | #include "monarch/rt/Collectable.h" 8 | 9 | namespace monarch 10 | { 11 | namespace rt 12 | { 13 | 14 | /** 15 | * A Iterator provides an interface for enumerating over the objects of 16 | * some collection. 17 | * 18 | * @author Dave Longley 19 | */ 20 | template 21 | class Iterator 22 | { 23 | public: 24 | /** 25 | * Creates a new Iterator. 26 | */ 27 | Iterator() {}; 28 | 29 | /** 30 | * Destructs this Iterator. 31 | */ 32 | virtual ~Iterator() {}; 33 | 34 | /** 35 | * Gets the next object and advances the Iterator. 36 | * 37 | * @return the next object. 38 | */ 39 | virtual T& next() = 0; 40 | 41 | /** 42 | * Returns true if this Iterator has more objects. 43 | * 44 | * @return true if this Iterator has more objects, false if not. 45 | */ 46 | virtual bool hasNext() = 0; 47 | 48 | /** 49 | * Removes the current object and advances the Iterator. 50 | */ 51 | virtual void remove() = 0; 52 | }; 53 | 54 | // define counted reference Iterator type 55 | template 56 | class IteratorRef : public Collectable< Iterator > 57 | { 58 | public: 59 | IteratorRef(Iterator* ptr = NULL) : 60 | Collectable< Iterator >(ptr) {}; 61 | virtual ~IteratorRef() {}; 62 | }; 63 | 64 | } // end namespace rt 65 | } // end namespace monarch 66 | #endif 67 | -------------------------------------------------------------------------------- /cpp/rt/Makefile.in: -------------------------------------------------------------------------------- 1 | # Makefile to compile the module in this directory 2 | 3 | LIBRARIES = mort 4 | mort_HEADERS = $(wildcard *.h) 5 | mort_SOURCES = $(wildcard *.cpp) 6 | 7 | DYNAMIC_LINUX_LINK_LIBRARIES = pthread 8 | DYNAMIC_WINDOWS_LINK_LIBRARIES = pthreadGCE2 9 | 10 | # ----------- Standard Makefile 11 | include @MONARCH_DIR@/setup/Makefile.base 12 | -------------------------------------------------------------------------------- /cpp/rt/Runnable.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2007-2009 Digital Bazaar, Inc. All rights reserved. 3 | */ 4 | #ifndef monarch_rt_Runnable_H 5 | #define monarch_rt_Runnable_H 6 | 7 | #include "monarch/rt/Collectable.h" 8 | 9 | namespace monarch 10 | { 11 | namespace rt 12 | { 13 | 14 | /** 15 | * An object is Runnable if it implements the run() method. 16 | * 17 | * @author Dave Longley 18 | */ 19 | class Runnable 20 | { 21 | public: 22 | /** 23 | * Constructs this Runnable. 24 | */ 25 | Runnable() {}; 26 | 27 | /** 28 | * Destructs this Runnable. 29 | */ 30 | virtual ~Runnable() {}; 31 | 32 | /** 33 | * Runs some implementation specific operation. 34 | */ 35 | virtual void run() = 0; 36 | }; 37 | 38 | // define a counted reference Runnable type 39 | typedef Collectable RunnableRef; 40 | 41 | } // end namespace rt 42 | } // end namespace monarch 43 | #endif 44 | -------------------------------------------------------------------------------- /cpp/rt/System.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2007-2009 Digital Bazaar, Inc. All rights reserved. 3 | */ 4 | #define __STDC_CONSTANT_MACROS 5 | 6 | #include "monarch/rt/System.h" 7 | 8 | // include NULL 9 | #include 10 | 11 | #ifdef WIN32 12 | #include 13 | #elif MACOS 14 | #include 15 | #include 16 | #else 17 | #include 18 | #endif 19 | 20 | using namespace monarch::rt; 21 | 22 | uint64_t System::getCurrentMilliseconds() 23 | { 24 | uint64_t rval = 0; 25 | 26 | // FIXME: consider using clock_gettime(), at least on *nix 27 | // get the current time of day 28 | struct timeval now; 29 | gettimeofday(&now, NULL); 30 | 31 | // get total number of milliseconds 32 | // 1 millisecond is 1000 microseconds 33 | rval = now.tv_sec * UINT64_C(1000) + (uint64_t)(now.tv_usec / 1000.0); 34 | 35 | return rval; 36 | } 37 | 38 | uint32_t System::getCpuCoreCount() 39 | { 40 | #ifdef WIN32 41 | SYSTEM_INFO sysinfo; 42 | GetSystemInfo(&sysinfo); 43 | return sysinfo.dwNumberOfProcessors; 44 | #elif MACOS 45 | int nm[2]; 46 | size_t len = 4; 47 | uint32_t count; 48 | 49 | // names to look up 50 | nm[0] = CTL_HW; 51 | nm[1] = HW_AVAILCPU; 52 | sysctl(nm, 2, &count, &len, NULL, 0); 53 | 54 | // handle error case 55 | if(count < 1) 56 | { 57 | // look up HW_NCPU instead 58 | nm[1] = HW_NCPU; 59 | sysctl(nm, 2, &count, &len, NULL, 0); 60 | if(count < 1) 61 | { 62 | // default to 1 cpu/core 63 | count = 1; 64 | } 65 | } 66 | 67 | return count; 68 | #else 69 | return sysconf(_SC_NPROCESSORS_ONLN); 70 | #endif 71 | } 72 | -------------------------------------------------------------------------------- /cpp/rt/System.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2007-2009 Digital Bazaar, Inc. All rights reserved. 3 | */ 4 | #ifndef monarch_rt_System_H 5 | #define monarch_rt_System_H 6 | 7 | #include "monarch/rt/TimeFunctions.h" 8 | 9 | #include 10 | 11 | namespace monarch 12 | { 13 | namespace rt 14 | { 15 | 16 | /** 17 | * The System class has methods for obtaining information or interacting 18 | * with the system a program is running on. 19 | * 20 | * @author Dave Longley 21 | */ 22 | class System 23 | { 24 | public: 25 | /** 26 | * Gets the current time in milliseconds. 27 | * 28 | * @return the current time in milliseconds. 29 | */ 30 | static uint64_t getCurrentMilliseconds(); 31 | 32 | /** 33 | * Gets the number of cores/cpus. 34 | * 35 | * @return the number of cores/cpus. 36 | */ 37 | static uint32_t getCpuCoreCount(); 38 | }; 39 | 40 | } // end namespace rt 41 | } // end namespace monarch 42 | #endif 43 | -------------------------------------------------------------------------------- /cpp/sphinx/Makefile.in: -------------------------------------------------------------------------------- 1 | # Makefile to compile the module in this directory 2 | 3 | ifeq (@BUILD_SPHINX@,yes) 4 | LIBRARIES = mosphinx 5 | mosphinx_HEADERS = $(wildcard *.h) 6 | mosphinx_SOURCES = $(wildcard *.cpp) 7 | 8 | DYNAMIC_LINK_LIBRARIES = mort moutil mocrypto moio monet 9 | 10 | DYNAMIC_MACOS_LINK_LIBRARIES = momodest mologging mocompress 11 | 12 | endif 13 | 14 | # ----------- Standard Makefile 15 | include @MONARCH_DIR@/setup/Makefile.base 16 | -------------------------------------------------------------------------------- /cpp/sql/Makefile.in: -------------------------------------------------------------------------------- 1 | # Makefile to compile the module in this directory 2 | 3 | LIBRARIES = mosql 4 | mosql_HEADERS = $(wildcard *.h) 5 | mosql_SOURCES = $(wildcard *.cpp) 6 | 7 | DYNAMIC_LINK_LIBRARIES = mort moutil mologging modata movalidation 8 | 9 | DYNAMIC_WINDOWS_LINK_LIBRARIES = moio momodest mocompress 10 | DYNAMIC_MACOS_LINK_LIBRARIES = moio momodest mocompress 11 | 12 | # ----------- Standard Makefile 13 | include @MONARCH_DIR@/setup/Makefile.base 14 | -------------------------------------------------------------------------------- /cpp/sql/Row.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2007-2009 Digital Bazaar, Inc. All rights reserved. 3 | */ 4 | #include "monarch/sql/Row.h" 5 | 6 | using namespace monarch::sql; 7 | 8 | Row::Row(Statement* s) 9 | { 10 | mStatement = s; 11 | } 12 | 13 | Row::~Row() 14 | { 15 | } 16 | 17 | inline Statement* Row::getStatement() 18 | { 19 | return mStatement; 20 | } 21 | -------------------------------------------------------------------------------- /cpp/sql/Statement.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2007-2009 Digital Bazaar, Inc. All rights reserved. 3 | */ 4 | #include "monarch/sql/Statement.h" 5 | 6 | #include 7 | 8 | using namespace monarch::sql; 9 | 10 | Statement::Statement(const char* sql) : 11 | mSql(strdup(sql)) 12 | { 13 | } 14 | 15 | Statement::~Statement() 16 | { 17 | free(mSql); 18 | } 19 | 20 | inline const char* Statement::getSql() 21 | { 22 | return mSql; 23 | } 24 | -------------------------------------------------------------------------------- /cpp/sqlite3/Makefile.in: -------------------------------------------------------------------------------- 1 | # Makefile to compile the module in this directory 2 | 3 | LIBRARIES = mosqlite3 4 | mosqlite3_HEADERS = $(wildcard *.h) 5 | mosqlite3_SOURCES = $(wildcard *.cpp) 6 | 7 | DYNAMIC_LINK_LIBRARIES = mort momodest moutil moio mosql sqlite3 8 | HEADER_DIST_DIR = dist/include/monarch/sql/sqlite3 9 | 10 | DYNAMIC_MACOS_LINK_LIBRARIES = mologging mocompress modata movalidation 11 | #DYNAMIC_WINDOWS_LINK_LIBRARIES = 12 | 13 | # ----------- Standard Makefile 14 | include @MONARCH_DIR@/setup/Makefile.base 15 | -------------------------------------------------------------------------------- /cpp/sqlite3/Sqlite3ConnectionPool.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2007-2009 Digital Bazaar, Inc. All rights reserved. 3 | */ 4 | #include "monarch/sql/sqlite3/Sqlite3ConnectionPool.h" 5 | 6 | using namespace monarch::sql; 7 | using namespace monarch::sql::sqlite3; 8 | 9 | Sqlite3ConnectionPool::Sqlite3ConnectionPool( 10 | const char* url, unsigned int poolSize) : 11 | AbstractConnectionPool(url, poolSize) 12 | { 13 | } 14 | 15 | Sqlite3ConnectionPool::~Sqlite3ConnectionPool() 16 | { 17 | } 18 | 19 | PooledConnection* Sqlite3ConnectionPool::createConnection() 20 | { 21 | PooledConnection* rval = NULL; 22 | 23 | // create and connect connection 24 | Connection* c = new Sqlite3Connection(); 25 | if(c->connect(&mUrl)) 26 | { 27 | // wrap in a pooled connection 28 | rval = new PooledConnection(this, c); 29 | } 30 | else 31 | { 32 | delete c; 33 | } 34 | 35 | return rval; 36 | } 37 | -------------------------------------------------------------------------------- /cpp/sqlite3/Sqlite3ConnectionPool.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2007-2009 Digital Bazaar, Inc. All rights reserved. 3 | */ 4 | #ifndef monarch_sql_sqlite3_Sqlite3ConnectionPool_H 5 | #define monarch_sql_sqlite3_Sqlite3ConnectionPool_H 6 | 7 | #include "monarch/sql/AbstractConnectionPool.h" 8 | #include "monarch/sql/sqlite3/Sqlite3Connection.h" 9 | 10 | namespace monarch 11 | { 12 | namespace sql 13 | { 14 | namespace sqlite3 15 | { 16 | 17 | /** 18 | * The Sqlite3 connection pool manages active, idle and expired Sqlite3 19 | * database connections. 20 | * 21 | * @author Mike Johnson 22 | */ 23 | class Sqlite3ConnectionPool : public AbstractConnectionPool 24 | { 25 | protected: 26 | /** 27 | * Creates a new sqlite3 database connection, connects it, and wraps it 28 | * with a PooledConnection. 29 | * 30 | * @return the PooledConnection or NULL if an exception occurred. 31 | */ 32 | virtual PooledConnection* createConnection(); 33 | 34 | public: 35 | /** 36 | * Creates a new Sqlite3ConnectionPool with the specified number of 37 | * database connections available. 38 | * 39 | * @param url the url for the database connections, including driver 40 | * specific parameters. 41 | * @param poolSize the size of the pool (number of database connections), 42 | * 0 specifies an unlimited number of threads. 43 | */ 44 | Sqlite3ConnectionPool(const char* url, unsigned int poolSize = 10); 45 | 46 | /** 47 | * Destructs this Sqlite3ConnectionPool. 48 | */ 49 | virtual ~Sqlite3ConnectionPool(); 50 | }; 51 | 52 | } // end namespace sqlite3 53 | } // end namespace sql 54 | } // end namespace monarch 55 | 56 | #endif 57 | -------------------------------------------------------------------------------- /cpp/test/Makefile.in: -------------------------------------------------------------------------------- 1 | # Makefile to compile the module in this directory 2 | 3 | LIBRARIES = motest 4 | motest_HEADERS = $(wildcard *.h) 5 | motest_SOURCES = $(wildcard *.cpp) 6 | 7 | DYNAMIC_LINK_LIBRARIES = mort modata mokernel moapp moconfig 8 | 9 | DYNAMIC_MACOS_LINK_LIBRARIES = moio moutil mologging monet mocompress momodest mofiber moevent mocrypto movalidation 10 | 11 | # ----------- Standard Makefile 12 | include @MONARCH_DIR@/setup/Makefile.base 13 | -------------------------------------------------------------------------------- /cpp/test/TestModule.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2010 Digital Bazaar, Inc. All rights reserved. 3 | */ 4 | #include "monarch/test/TestModule.h" 5 | 6 | using namespace std; 7 | using namespace monarch::app; 8 | using namespace monarch::config; 9 | using namespace monarch::kernel; 10 | using namespace monarch::modest; 11 | using namespace monarch::rt; 12 | using namespace monarch::test; 13 | 14 | TestModule::TestModule(const char* name, const char* version) : 15 | MicroKernelModule(name, version), 16 | mRun(NULL) 17 | { 18 | mInfo["name"] = name; 19 | mInfo["version"] = version; 20 | mInfo["type"] = "monarch.test.TestModule"; 21 | mInfo["dependencies"]->setType(Array); 22 | } 23 | 24 | TestModule::~TestModule() 25 | { 26 | } 27 | 28 | void TestModule::addDependency(const char* name, const char* version) 29 | { 30 | DynamicObject dep; 31 | dep["name"] = name; 32 | dep["version"] = version; 33 | mInfo["dependencies"]->append(dep); 34 | } 35 | 36 | DynamicObject TestModule::getDependencyInfo() 37 | { 38 | return mInfo; 39 | } 40 | 41 | bool TestModule::initialize(MicroKernel* k) 42 | { 43 | return true; 44 | } 45 | 46 | void TestModule::cleanup(MicroKernel* k) 47 | { 48 | } 49 | 50 | MicroKernelModuleApi* TestModule::getApi(MicroKernel* k) 51 | { 52 | return this; 53 | } 54 | 55 | void TestModule::setTestFunction(RunTestRunnerFn fn) 56 | { 57 | mRun = fn; 58 | } 59 | 60 | bool TestModule::run(TestRunner& tr) 61 | { 62 | return (mRun != NULL) ? mRun(tr) : true; 63 | } 64 | -------------------------------------------------------------------------------- /cpp/test/Testable.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2010 Digital Bazaar, Inc. All rights reserved. 3 | */ 4 | #ifndef monarch_test_Testable_h 5 | #define monarch_test_Testable_h 6 | 7 | #include "monarch/test/TestRunner.h" 8 | 9 | namespace monarch 10 | { 11 | namespace test 12 | { 13 | 14 | /** 15 | * A class implemention the Testable interface can be used to run tests with a 16 | * TestRunner. 17 | * 18 | * @author David I. Lehn 19 | */ 20 | class Testable 21 | { 22 | public: 23 | /** 24 | * Create an Testable instance. 25 | */ 26 | Testable() {}; 27 | 28 | /** 29 | * Deconstruct this Testable instance. 30 | */ 31 | virtual ~Testable() {}; 32 | 33 | /** 34 | * Run tests with the given TestRunner. Note that tests may successfully 35 | * record failures with the TestRunner and return true. If run() returns 36 | * false the testing framework itself may stop running further tests. 37 | * 38 | * @param tr a TestRunner to use for testing. 39 | * 40 | * @return true if successful, false if an exception occurred. 41 | */ 42 | virtual bool run(monarch::test::TestRunner& tr) = 0; 43 | }; 44 | 45 | } // end namespace test 46 | } // end namespace monarch 47 | 48 | #endif 49 | -------------------------------------------------------------------------------- /cpp/tests/test-mysql.h.template: -------------------------------------------------------------------------------- 1 | /** 2 | * You must rename this file to "test-mysql.h" and fill in the values for 3 | * the MySQL database server that you are using in order for the test to 4 | * work. 5 | */ 6 | #define MYSQL_HOST "" 7 | #define MYSQL_READ_USER "" 8 | #define MYSQL_WRITE_USER "" 9 | #define MYSQL_PASSWORD "" 10 | 11 | -------------------------------------------------------------------------------- /cpp/tests/test-random.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2009-2010 Digital Bazaar, Inc. All rights reserved. 3 | */ 4 | #define __STDC_FORMAT_MACROS 5 | 6 | #include "monarch/util/Random.h" 7 | #include "monarch/util/Math.h" 8 | #include "monarch/rt/Thread.h" 9 | 10 | #include 11 | #include 12 | 13 | using namespace monarch::rt; 14 | using namespace monarch::util; 15 | 16 | class RandomRunnable : public Runnable 17 | { 18 | public: 19 | RandomRunnable() {} 20 | virtual ~RandomRunnable() {} 21 | virtual void run() 22 | { 23 | int count = 20; 24 | printf("Generating %i random numbers between 1 and 1000000000:\n", count); 25 | 26 | for(int i = 1; i <= count; ++i) 27 | { 28 | printf("%i: %" PRIu64 "\n", i, Random::next(1, 1000000000)); 29 | } 30 | 31 | printf("Done. Total:1 Passed:1 Failed:0 Warnings:0 Unknown:0."); 32 | } 33 | }; 34 | 35 | int main() 36 | { 37 | printf("Testing Random...\n"); 38 | 39 | Random::seed(); 40 | for(int i = 0; i < 10; ++i) 41 | { 42 | RandomRunnable r; 43 | Thread t(&r); 44 | t.start(); 45 | t.join(); 46 | } 47 | 48 | exit(0); 49 | } 50 | -------------------------------------------------------------------------------- /cpp/upnp/DeviceDiscoverer.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2009 Digital Bazaar, Inc. All rights reserved. 3 | */ 4 | #ifndef monarch_upnp_DeviceDiscoverer_H 5 | #define monarch_upnp_DeviceDiscoverer_H 6 | 7 | #include "monarch/upnp/TypeDefinitions.h" 8 | 9 | namespace monarch 10 | { 11 | namespace upnp 12 | { 13 | 14 | /** 15 | * A DeviceDiscoverer is used to discover UPnP devices on the network. 16 | * 17 | * @author Dave Longley 18 | */ 19 | class DeviceDiscoverer 20 | { 21 | public: 22 | /** 23 | * Creates a new DeviceDiscoverer. 24 | */ 25 | DeviceDiscoverer(); 26 | 27 | /** 28 | * Destructs this DeviceDiscoverer. 29 | */ 30 | virtual ~DeviceDiscoverer(); 31 | 32 | /** 33 | * Discovers UPnP devices on the network during the specified timeout. 34 | * 35 | * An SSDP message will be sent to discover UPnP devices of a specific 36 | * type. The passed search target URI can be "ssdb:all", "upnp:rootdevice", 37 | * or a device type or UDN. 38 | * 39 | * @param devices a list to populate with devices. 40 | * @param searchTarget the search target URI that specifies the type of 41 | * devices to look for. 42 | * @param timeout how long this discoverer should wait to find devices, 43 | * in milliseconds. 44 | * @param count the maximum number of devices to find before returning, 45 | * 0 to wait until until the timeout is reached. 46 | * 47 | * @return the number of devices found, -1 if an exception occurred. 48 | */ 49 | virtual int discover( 50 | DeviceList& devices, 51 | const char* searchTarget, uint32_t timeout, int count); 52 | }; 53 | 54 | } // end namespace upnp 55 | } // end namespace monarch 56 | #endif 57 | -------------------------------------------------------------------------------- /cpp/upnp/Makefile.in: -------------------------------------------------------------------------------- 1 | # Makefile to compile the module in this directory 2 | 3 | LIBRARIES = moupnp 4 | moupnp_HEADERS = $(wildcard *.h) 5 | moupnp_SOURCES = $(wildcard *.cpp) 6 | 7 | DYNAMIC_LINK_LIBRARIES = mort moutil momodest moio mocrypto monet mohttp mologging modata 8 | 9 | DYNAMIC_MACOS_LINK_LIBRARIES = mocompress 10 | DYNAMIC_WINDOWS_LINK_LIBRARIES = libgnurx-0 11 | 12 | # ----------- Standard Makefile 13 | include @MONARCH_DIR@/setup/Makefile.base 14 | 15 | -------------------------------------------------------------------------------- /cpp/util/Macros.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2008-2010 Digital Bazaar, Inc. All rights reserved. 3 | */ 4 | #ifndef monarch_util_Macros_H 5 | #define monarch_util_Macros_H 6 | 7 | /** 8 | * Miscellaneous general use macros. 9 | */ 10 | 11 | /** 12 | * Macro statement wrapper. Adapted from glib. 13 | * Use: 14 | * if(x) MO_STMT_START { ... } MO_STMT_END; else ... 15 | */ 16 | #define MO_STMT_START do 17 | #define MO_STMT_END while (0) 18 | 19 | /** 20 | * Macro to do nothing, useful to disable debug macros. 21 | */ 22 | #define MO_STMT_EMPTY MO_STMT_START {} MO_STMT_END; 23 | 24 | /** 25 | * Convert argument to a string 26 | */ 27 | #define MO_STRINGIFY_ARG(arg) #arg 28 | #define MO_STRINGIFY(arg) MO_STRINGIFY_ARG(arg) 29 | 30 | /** 31 | * String representing the current code location. 32 | */ 33 | #define MO_STRLOC __FILE__ ":" MO_STRINGIFY(__LINE__) 34 | 35 | /** 36 | * Static assertion. 37 | */ 38 | #define MO_STATIC_ASSERT(expr, msg) \ 39 | do { \ 40 | enum { assert_static__ = 1/(expr) }; \ 41 | } while (0) 42 | 43 | #endif 44 | -------------------------------------------------------------------------------- /cpp/util/Makefile.in: -------------------------------------------------------------------------------- 1 | # Makefile to compile the module in this directory 2 | 3 | LIBRARIES = moutil 4 | moutil_HEADERS = \ 5 | $(wildcard *.h) 6 | moutil_SOURCES = \ 7 | $(wildcard *.cpp) 8 | 9 | DYNAMIC_LINK_LIBRARIES = mort 10 | 11 | DYNAMIC_WINDOWS_LINK_LIBRARIES = libgnurx-0 12 | 13 | ifeq (@HAVE_LIBPCREPOSIX@,yes) 14 | DYNAMIC_LINK_LIBRARIES += pcreposix 15 | endif 16 | 17 | # ----------- Standard Makefile 18 | include @MONARCH_DIR@/setup/Makefile.base 19 | 20 | -------------------------------------------------------------------------------- /cpp/util/PathFormatter.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2008-2010 Digital Bazaar, Inc. All rights reserved. 3 | */ 4 | #include "monarch/util/PathFormatter.h" 5 | 6 | #include 7 | 8 | using namespace std; 9 | using namespace monarch::util; 10 | 11 | string& PathFormatter::formatFilename(string& str) 12 | { 13 | string correctedString; 14 | 15 | // Go through the entire string and clean up any character that is not 16 | // a universally accepted filename character. 17 | string::iterator i; 18 | for(i = str.begin(); i != str.end(); ++i) 19 | { 20 | char c = *i; 21 | 22 | // This list was taken from http://en.wikipedia.org/wiki/Filename, we 23 | // care most about Windows, Linux and Mac OS X. By default all 24 | // ASCII characters are allowed except for characters that are 25 | // disallowed on any one of the previously mentioned systems. 26 | if((c >= ' ') && (c <= '~') && strchr("?/\\*:|\"<>+[]", c) == NULL) 27 | { 28 | correctedString.push_back(c); 29 | } 30 | else 31 | { 32 | correctedString.push_back('_'); 33 | } 34 | } 35 | 36 | str = correctedString; 37 | 38 | return str; 39 | } 40 | -------------------------------------------------------------------------------- /cpp/util/PathFormatter.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2007-2009 Digital Bazaar, Inc. All rights reserved. 3 | */ 4 | #ifndef monarch_util_PathFormatter_H 5 | #define monarch_util_PathFormatter_H 6 | 7 | #include 8 | 9 | namespace monarch 10 | { 11 | namespace util 12 | { 13 | 14 | /** 15 | * The PathFormatter class provides methods for formatting pathnames and 16 | * filenames. 17 | * 18 | * @author Manu Sporny 19 | */ 20 | class PathFormatter 21 | { 22 | private: 23 | /** 24 | * Creates a new PathFormatter object. 25 | */ 26 | PathFormatter() {}; 27 | 28 | public: 29 | /** 30 | * Removes invalid characters from a given file path. 31 | * 32 | * @param filename the name of the file to format. 33 | * 34 | * @return a reference to the correctly formatted string. 35 | */ 36 | static std::string& formatFilename(std::string& str); 37 | }; 38 | 39 | } // end namespace util 40 | } // end namespace monarch 41 | #endif 42 | -------------------------------------------------------------------------------- /cpp/util/Random.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2008-2009 Digital Bazaar, Inc. All rights reserved. 3 | */ 4 | #ifndef monarch_util_Random_H 5 | #define monarch_util_Random_H 6 | 7 | #include 8 | 9 | namespace monarch 10 | { 11 | namespace util 12 | { 13 | 14 | /** 15 | * The Random class is used to obtain pseudo-random (non-secure) numbers. 16 | * 17 | * @author Dave Longley 18 | */ 19 | class Random 20 | { 21 | public: 22 | /** 23 | * Destructs this Random. 24 | */ 25 | virtual ~Random() {}; 26 | 27 | /** 28 | * Must be called once at application start up to seed RNG. 29 | */ 30 | static void seed(); 31 | 32 | /** 33 | * Gets the next pseudo-random (non-secure) number between "low" and "high". 34 | * 35 | * @param low the lowest possible number to return. 36 | * @param high the highest possible number to return. 37 | * 38 | * @return a pseduo-random (non-secure) number between "low" and "high". 39 | */ 40 | static uint64_t next(uint64_t low, uint64_t high); 41 | 42 | protected: 43 | /** 44 | * Creates a new Random. 45 | */ 46 | Random() {}; 47 | }; 48 | 49 | } // end namespace util 50 | } // end namespace monarch 51 | #endif 52 | -------------------------------------------------------------------------------- /cpp/util/TimeZone.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2007-2011 Digital Bazaar, Inc. All rights reserved. 3 | */ 4 | #include "monarch/util/TimeZone.h" 5 | 6 | #include "monarch/rt/System.h" 7 | 8 | #include 9 | 10 | using namespace std; 11 | using namespace monarch::rt; 12 | using namespace monarch::util; 13 | 14 | TimeZone::TimeZone(time_t minutesWest) : 15 | mMinutesWest(minutesWest) 16 | { 17 | } 18 | 19 | TimeZone::~TimeZone() 20 | { 21 | } 22 | 23 | inline time_t TimeZone::getMinutesWest() 24 | { 25 | return mMinutesWest; 26 | } 27 | 28 | TimeZone TimeZone::getTimeZone(const char* tz, time_t* t) 29 | { 30 | TimeZone rval; 31 | 32 | if(tz == NULL) 33 | { 34 | rval.mMinutesWest = gGetTimeZoneMinutesWest(t); 35 | } 36 | else if(strcasecmp(tz, "GMT") == 0 || strcasecmp(tz, "UTC") == 0) 37 | { 38 | rval.mMinutesWest = 0; 39 | } 40 | else if(strcasecmp(tz, "EDT") == 0) 41 | { 42 | // 4 hours west 43 | rval.mMinutesWest = 240; 44 | } 45 | else if(strcasecmp(tz, "EST") == 0) 46 | { 47 | // 5 hours west 48 | rval.mMinutesWest = 300; 49 | } 50 | else if(strcasecmp(tz, "PDT") == 0) 51 | { 52 | // 7 hours west 53 | rval.mMinutesWest = 420; 54 | } 55 | else if(strcasecmp(tz, "PST") == 0) 56 | { 57 | // 8 hours west 58 | rval.mMinutesWest = 480; 59 | } 60 | else 61 | { 62 | rval.mMinutesWest = gGetTimeZoneMinutesWest(t); 63 | } 64 | 65 | return rval; 66 | } 67 | -------------------------------------------------------------------------------- /cpp/util/TimeZone.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2007-2011 Digital Bazaar, Inc. All rights reserved. 3 | */ 4 | #ifndef monarch_util_TimeZone_H 5 | #define monarch_util_TimeZone_H 6 | 7 | #include 8 | 9 | namespace monarch 10 | { 11 | namespace util 12 | { 13 | 14 | /** 15 | * A TimeZone represents an offset from GMT time. 16 | * 17 | * @author Dave Longley 18 | */ 19 | class TimeZone 20 | { 21 | protected: 22 | /** 23 | * The number of minutes west of GMT. 24 | */ 25 | time_t mMinutesWest; 26 | 27 | public: 28 | /** 29 | * Creates a new TimeZone with the given number of minutes west of GMT. 30 | * 31 | * @param minutesWest the number of minutes west of GMT. 32 | */ 33 | TimeZone(time_t minutesWest = 0); 34 | 35 | /** 36 | * Destructs this TimeZone. 37 | */ 38 | virtual ~TimeZone(); 39 | 40 | /** 41 | * Gets the number of minutes west of GMT this TimeZone is. 42 | * 43 | * @return the number of minutes west of GMT. 44 | */ 45 | virtual time_t getMinutesWest(); 46 | 47 | /** 48 | * Gets a TimeZone from its abbreviation. 49 | * 50 | * @param tz the abbreviation for the time zone to retrieve (blank for 51 | * the local time zone). 52 | * @param t the time to use to get the local time zone (NULL to use now). 53 | * 54 | * @return the TimeZone for the given abbreviation. 55 | */ 56 | static TimeZone getTimeZone(const char* tz = NULL, time_t* t = NULL); 57 | }; 58 | 59 | } // end namespace util 60 | } // end namespace monarch 61 | #endif 62 | -------------------------------------------------------------------------------- /cpp/util/Timer.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2008-2009 Digital Bazaar, Inc. All rights reserved. 3 | */ 4 | #include "monarch/util/Timer.h" 5 | 6 | #include "monarch/rt/System.h" 7 | 8 | using namespace monarch::rt; 9 | using namespace monarch::util; 10 | 11 | Timer::Timer() : 12 | mStartTime(0) 13 | { 14 | } 15 | 16 | Timer::~Timer() 17 | { 18 | } 19 | 20 | uint64_t Timer::start() 21 | { 22 | mStartTime = System::getCurrentMilliseconds(); 23 | return mStartTime; 24 | } 25 | 26 | uint64_t Timer::getStartTime() 27 | { 28 | return mStartTime; 29 | } 30 | 31 | uint64_t Timer::getElapsedMilliseconds() 32 | { 33 | return System::getCurrentMilliseconds() - mStartTime; 34 | } 35 | 36 | double Timer::getElapsedSeconds() 37 | { 38 | return getElapsedMilliseconds() / 1000.; 39 | } 40 | 41 | uint64_t Timer::getRemainingMilliseconds(uint64_t until) 42 | { 43 | uint64_t rval = 0; 44 | 45 | uint64_t now = System::getCurrentMilliseconds(); 46 | uint64_t then = mStartTime + until; 47 | if(now > then) 48 | { 49 | rval = now - then; 50 | } 51 | 52 | return rval; 53 | } 54 | 55 | double Timer::getRemainingSeconds(uint64_t until) 56 | { 57 | return getRemainingMilliseconds(until) / 1000.; 58 | } 59 | 60 | // FIXME: remove the static methods below: 61 | 62 | uint64_t Timer::startTiming() 63 | { 64 | return System::getCurrentMilliseconds(); 65 | } 66 | 67 | uint64_t Timer::getMilliseconds(uint64_t startTime) 68 | { 69 | return System::getCurrentMilliseconds() - startTime; 70 | } 71 | 72 | double Timer::getSeconds(uint64_t startTime) 73 | { 74 | return (System::getCurrentMilliseconds() - startTime) / 1000.; 75 | } 76 | -------------------------------------------------------------------------------- /cpp/v8/Makefile.in: -------------------------------------------------------------------------------- 1 | # Makefile to compile the module in this directory 2 | 3 | # conditional build of v8 support 4 | ifeq (@BUILD_V8@,yes) 5 | 6 | MODULES = mov8 7 | mov8_HEADERS = $(wildcard *.h) 8 | mov8_SOURCES = $(wildcard *.cpp) 9 | mov8_MOD_DIR = ext 10 | 11 | DYNAMIC_LINK_LIBRARIES = mort moutil mows v8 12 | 13 | # conditional build of v8 support 14 | endif 15 | 16 | # ----------- Standard Makefile 17 | include @MONARCH_DIR@/setup/Makefile.base 18 | -------------------------------------------------------------------------------- /cpp/v8/V8Engine.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2010 Digital Bazaar, Inc. All rights reserved. 3 | */ 4 | #ifndef monarch_v8_V8Engine_h 5 | #define monarch_v8_V8Engine_h 6 | 7 | #include "monarch/v8/V8EngineApi.h" 8 | #include "monarch/v8/V8Controller.h" 9 | 10 | #include 11 | 12 | namespace monarch 13 | { 14 | namespace v8 15 | { 16 | 17 | /** 18 | * A V8Engine can run JavaScript using the V8 engine. 19 | * 20 | * @author David I. Lehn 21 | */ 22 | class V8Engine : public V8EngineApi 23 | { 24 | protected: 25 | /** 26 | * Controller for this engine. 27 | */ 28 | V8Controller* mController; 29 | 30 | /** 31 | * Persistent context for this engine. 32 | */ 33 | ::v8::Persistent< ::v8::Context> mContext; 34 | 35 | public: 36 | /** 37 | * Creates a new V8Engine. 38 | */ 39 | V8Engine(); 40 | 41 | /** 42 | * Destructs this V8Engine. 43 | */ 44 | virtual ~V8Engine(); 45 | 46 | /** 47 | * Initialize this engine. 48 | * 49 | * @param c the V8Controller for this engine. 50 | * 51 | * @return true on success, false with exception set on failure. 52 | */ 53 | virtual bool initialize(V8Controller* c); 54 | 55 | /** 56 | * {@inheritDoc} 57 | */ 58 | virtual bool setDynamicObject( 59 | const char* name, monarch::rt::DynamicObject& dyno); 60 | 61 | /** 62 | * {@inheritDoc} 63 | */ 64 | virtual bool getDynamicObject( 65 | const char* name, monarch::rt::DynamicObject& dyno); 66 | 67 | /** 68 | * {@inheritDoc} 69 | */ 70 | virtual bool runScript(const char* js, std::string& result); 71 | }; 72 | 73 | } // end namespace v8 74 | } // end namespace monarch 75 | #endif 76 | -------------------------------------------------------------------------------- /cpp/v8/V8ModuleApi.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2010 Digital Bazaar, Inc. All rights reserved. 3 | */ 4 | #ifndef monarch_v8_V8ModuleApi_h 5 | #define monarch_v8_V8ModuleApi_h 6 | 7 | #include "monarch/kernel/MicroKernelModuleApi.h" 8 | #include "monarch/v8/V8EngineApi.h" 9 | 10 | namespace monarch 11 | { 12 | namespace v8 13 | { 14 | 15 | /** 16 | * A V8ModuleApi provides the application programming interface for the 17 | * V8Module. 18 | * 19 | * @author David I. Lehn 20 | */ 21 | class V8ModuleApi : public monarch::kernel::MicroKernelModuleApi 22 | { 23 | public: 24 | /** 25 | * Creates a new V8ModuleApi. 26 | */ 27 | V8ModuleApi() {}; 28 | 29 | /** 30 | * Destructs this V8ModuleApi. 31 | */ 32 | virtual ~V8ModuleApi() {}; 33 | 34 | /** 35 | * Create a V8Engine object. Call initialize(...) on the returned 36 | * object to perform futher setup. 37 | * 38 | * @param v8Engine new V8Engine object to set. 39 | * 40 | * @return true on success, false and exception set on failure. 41 | */ 42 | virtual bool createEngine(V8EngineRef& v8Engine) = 0; 43 | }; 44 | 45 | } // end namespace v8 46 | } // end namespace monarch 47 | #endif 48 | -------------------------------------------------------------------------------- /cpp/validation/All.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2008-2010 Digital Bazaar, Inc. All rights reserved. 3 | */ 4 | #include "monarch/validation/All.h" 5 | 6 | using namespace monarch::rt; 7 | using namespace monarch::validation; 8 | 9 | All::All(Validator* validator, ...) : 10 | mMaskType(ValidatorContext::MaskNone) 11 | { 12 | va_list ap; 13 | 14 | va_start(ap, validator); 15 | addValidators(validator, ap); 16 | va_end(ap); 17 | } 18 | 19 | All::All(ValidatorContext::MaskType mt, Validator* validator, ...) : 20 | mMaskType(mt) 21 | { 22 | va_list ap; 23 | 24 | va_start(ap, validator); 25 | addValidators(validator, ap); 26 | va_end(ap); 27 | } 28 | 29 | All::~All() 30 | { 31 | } 32 | 33 | bool All::isValid( 34 | monarch::rt::DynamicObject& obj, 35 | ValidatorContext* context) 36 | { 37 | bool rval = true; 38 | 39 | // save mask type for context 40 | ValidatorContext::MaskType mt = context->getMaskType(); 41 | 42 | // set mask type for context 43 | context->setMaskType(mMaskType); 44 | 45 | // make sure all validators are tested, do not short-circuit 46 | std::vector::iterator i; 47 | for(i = mValidators.begin(); i != mValidators.end(); ++i) 48 | { 49 | if(!(*i)->isValid(obj, context)) 50 | { 51 | rval = false; 52 | } 53 | } 54 | 55 | if(rval) 56 | { 57 | context->addSuccess(); 58 | } 59 | 60 | // restore mask type 61 | context->setMaskType(mt); 62 | 63 | return rval; 64 | } 65 | -------------------------------------------------------------------------------- /cpp/validation/All.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2008-2009 Digital Bazaar, Inc. All rights reserved. 3 | */ 4 | #ifndef monarch_validation_All_H 5 | #define monarch_validation_All_H 6 | 7 | #include "monarch/validation/ValidatorList.h" 8 | 9 | namespace monarch 10 | { 11 | namespace validation 12 | { 13 | 14 | /** 15 | * Validates a list of Validators such that all sub-validators must be valid. 16 | * Validation checking short circuits if a sub-validator returns false. 17 | * 18 | * This validator can also be used to mask invalid data in its sub-validators, 19 | * which is particularly important when validating secure data fields like 20 | * passwords. 21 | * 22 | * @author David I. Lehn 23 | */ 24 | class All : public ValidatorList 25 | { 26 | protected: 27 | /** 28 | * The mask type for this validator. 29 | */ 30 | ValidatorContext::MaskType mMaskType; 31 | 32 | public: 33 | /** 34 | * Creates a new validator. 35 | */ 36 | All(Validator* validator, ...); 37 | 38 | /** 39 | * Creates a new validator. 40 | * 41 | * @param mt the type of error data to mask. 42 | */ 43 | All(ValidatorContext::MaskType mt, Validator* validator, ...); 44 | 45 | /** 46 | * Destructs this validator. 47 | */ 48 | virtual ~All(); 49 | 50 | /** 51 | * Checks if an object is valid. 52 | * 53 | * @param obj the object to validate. 54 | * @param context context to use during validation. 55 | * 56 | * @return true if obj is valid, false and exception set otherwise. 57 | */ 58 | virtual bool isValid( 59 | monarch::rt::DynamicObject& obj, 60 | ValidatorContext* context); 61 | using Validator::isValid; 62 | }; 63 | 64 | } // end namespace validation 65 | } // end namespace monarch 66 | #endif 67 | -------------------------------------------------------------------------------- /cpp/validation/Any.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2008-2009 Digital Bazaar, Inc. All rights reserved. 3 | */ 4 | #ifndef monarch_validation_Any_H 5 | #define monarch_validation_Any_H 6 | 7 | #include "monarch/validation/ValidatorList.h" 8 | 9 | namespace monarch 10 | { 11 | namespace validation 12 | { 13 | 14 | /** 15 | * Validates a list of Validators such that at least one sub-validators must be 16 | * valid. Validation checking short circuits if a sub-validator returns true. 17 | * 18 | * @author David I. Lehn 19 | */ 20 | class Any : public ValidatorList 21 | { 22 | public: 23 | /** 24 | * Creates a new validator. 25 | */ 26 | Any(Validator* validator, ...); 27 | 28 | /** 29 | * Destructs this validator. 30 | */ 31 | virtual ~Any(); 32 | 33 | /** 34 | * Checks if an object is valid. 35 | * 36 | * @param obj the object to validate. 37 | * @param context context to use during validation. 38 | * 39 | * @return true if obj is valid, false and exception set otherwise. 40 | */ 41 | virtual bool isValid( 42 | monarch::rt::DynamicObject& obj, 43 | ValidatorContext* context); 44 | using Validator::isValid; 45 | }; 46 | 47 | } // end namespace validation 48 | } // end namespace monarch 49 | #endif 50 | -------------------------------------------------------------------------------- /cpp/validation/Compare.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2008-2011 Digital Bazaar, Inc. All rights reserved. 3 | */ 4 | #ifndef monarch_validation_Compare_H 5 | #define monarch_validation_Compare_H 6 | 7 | #include "monarch/validation/Validator.h" 8 | # 9 | namespace monarch 10 | { 11 | namespace validation 12 | { 13 | 14 | /** 15 | * Validates equality of the values for two keys of a DynamicObject Map. 16 | * 17 | * d => { "aKey": aValue, "bKey": bValue } 18 | * 19 | * Validate aValue and bValue are the same (via ==) with: 20 | * 21 | * Compare c("aKey", "bKey"); 22 | * c.isValid(d) 23 | * 24 | * @author David I. Lehn 25 | */ 26 | class Compare : public Validator 27 | { 28 | protected: 29 | /* First key to use */ 30 | char* mKey0; 31 | 32 | /* Second key to use */ 33 | char* mKey1; 34 | 35 | public: 36 | /** 37 | * Creates a new validator. 38 | * 39 | * @param key0 first key to use 40 | * @param key1 second key to use 41 | * @param errorMessage custom error message 42 | */ 43 | Compare(const char* key0, const char* key2, const char* errorMessage = NULL); 44 | 45 | /** 46 | * Destructs this validator. 47 | */ 48 | virtual ~Compare(); 49 | 50 | /** 51 | * Checks if an object is valid. 52 | * 53 | * @param obj the object to validate. 54 | * @param context context to use during validation. 55 | * 56 | * @return true if obj is valid, false and exception set otherwise. 57 | */ 58 | virtual bool isValid( 59 | monarch::rt::DynamicObject& obj, 60 | ValidatorContext* context); 61 | using Validator::isValid; 62 | }; 63 | 64 | } // end namespace validation 65 | } // end namespace monarch 66 | #endif 67 | -------------------------------------------------------------------------------- /cpp/validation/CompareText.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2008-2009 Digital Bazaar, Inc. All rights reserved. 3 | */ 4 | #include "monarch/validation/CompareText.h" 5 | 6 | #include "monarch/util/StringTools.h" 7 | 8 | using namespace monarch::rt; 9 | using namespace monarch::util; 10 | using namespace monarch::validation; 11 | 12 | CompareText::CompareText(const char* text, const char* errorMessage) : 13 | Validator(errorMessage), 14 | mText(text) 15 | { 16 | // replace all CRLF with LF 17 | StringTools::replaceAll(mText, "\r\n", "\n"); 18 | StringTools::replaceAll(mText, "\r", "\n"); 19 | } 20 | 21 | CompareText::~CompareText() 22 | { 23 | } 24 | 25 | bool CompareText::isValid(DynamicObject& obj, ValidatorContext* context) 26 | { 27 | bool rval = !obj.isNull(); 28 | 29 | if(rval) 30 | { 31 | // replace all CRLF with LF 32 | std::string compare = obj->getString(); 33 | StringTools::replaceAll(compare, "\r\n", "\n"); 34 | StringTools::replaceAll(compare, "\r", "\n"); 35 | 36 | rval = (strcmp(compare.c_str(), mText.c_str()) == 0); 37 | if(!rval) 38 | { 39 | DynamicObject detail = context->addError( 40 | "monarch.validation.CompareTextFailure", &obj); 41 | detail["validator"] = "monarch.validator.CompareText"; 42 | detail["message"] = (mErrorMessage != NULL ? 43 | mErrorMessage : 44 | "The two text strings that were given are required " 45 | "to be equivalent, but they are different."); 46 | detail["expectedValue"] = mText.c_str(); 47 | } 48 | } 49 | 50 | if(rval) 51 | { 52 | context->addSuccess(); 53 | } 54 | 55 | return rval; 56 | } 57 | -------------------------------------------------------------------------------- /cpp/validation/CompareText.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2008-2009 Digital Bazaar, Inc. All rights reserved. 3 | */ 4 | #ifndef monarch_validation_CompareText_H 5 | #define monarch_validation_CompareText_H 6 | 7 | #include "monarch/validation/Validator.h" 8 | 9 | namespace monarch 10 | { 11 | namespace validation 12 | { 13 | 14 | /** 15 | * Validates a text string. All CRLF's will be converted to LF's and then all 16 | * CR's will be converted to LF's to make end of line characters uniform. 17 | * 18 | * d => "Apples\r\nAnd\rOranges\n" 19 | * 20 | * CompareText ctt("Apples\nAnd\nOranges\n"); 21 | * ctt.isValid(d) => true 22 | * 23 | * CompareText ctf("ApplesAndOranges\n"); 24 | * ctf.isValid(d) => false 25 | * 26 | * @author Dave Longley 27 | */ 28 | class CompareText : public Validator 29 | { 30 | protected: 31 | /** 32 | * The text to compare against. 33 | */ 34 | std::string mText; 35 | 36 | public: 37 | /** 38 | * Creates a new validator. 39 | * 40 | * @param text the text to compare against. 41 | * @param errorMessage a custom error message. 42 | */ 43 | CompareText(const char* text, const char* errorMessage = NULL); 44 | 45 | /** 46 | * Destructs this validator. 47 | */ 48 | virtual ~CompareText(); 49 | 50 | /** 51 | * Checks if an object is valid. 52 | * 53 | * @param obj the object to validate. 54 | * @param context context to use during validation. 55 | * 56 | * @return true if obj is valid, false and exception set otherwise. 57 | */ 58 | virtual bool isValid( 59 | monarch::rt::DynamicObject& obj, ValidatorContext* context); 60 | using Validator::isValid; 61 | }; 62 | 63 | } // end namespace validation 64 | } // end namespace monarch 65 | #endif 66 | -------------------------------------------------------------------------------- /cpp/validation/Contains.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2012 Digital Bazaar, Inc. All rights reserved. 3 | */ 4 | #include "monarch/validation/Contains.h" 5 | 6 | #include "monarch/rt/DynamicObjectIterator.h" 7 | 8 | using namespace monarch::rt; 9 | using namespace monarch::validation; 10 | 11 | Contains::Contains(DynamicObject& object, const char* errorMessage) : 12 | Validator(errorMessage), 13 | mObject(object) 14 | { 15 | } 16 | 17 | Contains::~Contains() 18 | { 19 | } 20 | 21 | bool Contains::isValid( 22 | DynamicObject& obj, 23 | ValidatorContext* context) 24 | { 25 | bool rval = false; 26 | 27 | // check if objects are equal 28 | rval = (obj == mObject); 29 | 30 | // if not equal, check if target contains the validation object 31 | if(!rval && !obj.isNull() && 32 | (obj->getType() == Array || obj->getType() == Map)) 33 | { 34 | DynamicObjectIterator i = obj.getIterator(); 35 | while(!rval && i->hasNext()) 36 | { 37 | DynamicObject& next = i->next(); 38 | rval = (next == mObject); 39 | } 40 | } 41 | 42 | if(!rval) 43 | { 44 | DynamicObject detail = 45 | context->addError("monarch.validation.NotFound", &obj); 46 | detail["validator"] = "monarch.validator.Contains"; 47 | detail["expectedValue"] = mObject; 48 | detail["message"] = mErrorMessage ? mErrorMessage : 49 | "The input object was not equal to or found in the validator."; 50 | } 51 | 52 | if(rval) 53 | { 54 | context->addSuccess(); 55 | } 56 | 57 | return rval; 58 | } 59 | -------------------------------------------------------------------------------- /cpp/validation/Contains.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2012 Digital Bazaar, Inc. All rights reserved. 3 | */ 4 | #ifndef monarch_validation_Contains_h 5 | #define monarch_validation_Contains_h 6 | 7 | #include "monarch/validation/Validator.h" 8 | 9 | namespace monarch 10 | { 11 | namespace validation 12 | { 13 | 14 | /** 15 | * Validates if either a target object equals a validation object or if the 16 | * target is an array or map and contains the validation object. 17 | * 18 | * @author David I. Lehn 19 | */ 20 | class Contains : public Validator 21 | { 22 | protected: 23 | /* Object with valid object */ 24 | monarch::rt::DynamicObject mObject; 25 | 26 | public: 27 | /** 28 | * Creates a new validator. 29 | * 30 | * @param errorMessage custom error message 31 | */ 32 | Contains( 33 | monarch::rt::DynamicObject& object, const char* errorMessage = NULL); 34 | 35 | /** 36 | * Destructs this validator. 37 | */ 38 | virtual ~Contains(); 39 | 40 | /** 41 | * Checks if an object is valid. 42 | * 43 | * @param obj the object to validate. 44 | * @param context context to use during validation. 45 | * 46 | * @return true if obj is valid, false and exception set otherwise. 47 | */ 48 | virtual bool isValid( 49 | monarch::rt::DynamicObject& obj, 50 | ValidatorContext* context); 51 | using Validator::isValid; 52 | }; 53 | 54 | } // end namespace validation 55 | } // end namespace monarch 56 | #endif 57 | -------------------------------------------------------------------------------- /cpp/validation/Equals.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2008-2009 Digital Bazaar, Inc. All rights reserved. 3 | */ 4 | #include "monarch/validation/Equals.h" 5 | 6 | using namespace monarch::rt; 7 | using namespace monarch::validation; 8 | 9 | Equals::Equals(monarch::rt::DynamicObject& object, const char* errorMessage) : 10 | Validator(errorMessage), 11 | mObject(object) 12 | { 13 | } 14 | 15 | Equals::Equals(const char* str, const char* errorMessage) : 16 | Validator(errorMessage) 17 | { 18 | mObject = str; 19 | } 20 | 21 | Equals::Equals(bool b, const char* errorMessage) : 22 | Validator(errorMessage) 23 | { 24 | mObject = b; 25 | } 26 | 27 | Equals::~Equals() 28 | { 29 | } 30 | 31 | bool Equals::isValid( 32 | monarch::rt::DynamicObject& obj, 33 | ValidatorContext* context) 34 | { 35 | bool rval = (obj == mObject); 36 | if(!rval) 37 | { 38 | DynamicObject detail = 39 | context->addError("monarch.validation.EqualityFailure", &obj); 40 | detail["validator"] = "monarch.validator.Equals"; 41 | detail["expectedValue"] = mObject; 42 | if(mErrorMessage) 43 | { 44 | detail["message"] = mErrorMessage; 45 | } 46 | // FIXME: add expected value to error detail? 47 | } 48 | else 49 | { 50 | context->addSuccess(); 51 | } 52 | 53 | return rval; 54 | } 55 | -------------------------------------------------------------------------------- /cpp/validation/In.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2008-2009 Digital Bazaar, Inc. All rights reserved. 3 | */ 4 | #ifndef monarch_validation_In_H 5 | #define monarch_validation_In_H 6 | 7 | #include "monarch/validation/Validator.h" 8 | 9 | namespace monarch 10 | { 11 | namespace validation 12 | { 13 | 14 | /** 15 | * Validates an object is in an array or is a key in a map. 16 | * 17 | * @author David I. Lehn 18 | */ 19 | class In : public Validator 20 | { 21 | protected: 22 | /* Object with valid contents */ 23 | monarch::rt::DynamicObject mContents; 24 | 25 | public: 26 | /** 27 | * Creates a new validator. 28 | * 29 | * @param errorMessage custom error message 30 | */ 31 | In(monarch::rt::DynamicObject& contents, const char* errorMessage = NULL); 32 | 33 | /** 34 | * Destructs this validator. 35 | */ 36 | virtual ~In(); 37 | 38 | /** 39 | * Checks if an object is valid. 40 | * 41 | * @param obj the object to validate. 42 | * @param context context to use during validation. 43 | * 44 | * @return true if obj is valid, false and exception set otherwise. 45 | */ 46 | virtual bool isValid( 47 | monarch::rt::DynamicObject& obj, 48 | ValidatorContext* context); 49 | using Validator::isValid; 50 | }; 51 | 52 | } // end namespace validation 53 | } // end namespace monarch 54 | #endif 55 | -------------------------------------------------------------------------------- /cpp/validation/Makefile.in: -------------------------------------------------------------------------------- 1 | # Makefile to compile the module in this directory 2 | 3 | LIBRARIES = movalidation 4 | movalidation_HEADERS = $(wildcard *.h) 5 | movalidation_SOURCES = $(wildcard *.cpp) 6 | 7 | DYNAMIC_LINK_LIBRARIES = mort moutil moio modata 8 | 9 | # ----------- Standard Makefile 10 | include @MONARCH_DIR@/setup/Makefile.base 11 | 12 | -------------------------------------------------------------------------------- /cpp/validation/Max.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2008-2009 Digital Bazaar, Inc. All rights reserved. 3 | */ 4 | #include "monarch/validation/Max.h" 5 | 6 | using namespace monarch::rt; 7 | using namespace monarch::validation; 8 | 9 | Max::Max(int size, const char* errorMessage) : 10 | Validator(errorMessage), 11 | mSize(size) 12 | { 13 | } 14 | 15 | Max::~Max() 16 | { 17 | } 18 | 19 | bool Max::isValid( 20 | DynamicObject& obj, 21 | ValidatorContext* context) 22 | { 23 | bool rval = (!obj.isNull() && obj->length() <= mSize); 24 | 25 | if(!rval) 26 | { 27 | DynamicObject detail = context->addError("monarch.validation.MaxError", &obj); 28 | detail["validator"] = "monarch.validator.Max"; 29 | if(mErrorMessage) 30 | { 31 | detail["message"] = mErrorMessage; 32 | } 33 | detail["expectedMax"] = mSize; 34 | } 35 | else 36 | { 37 | context->addSuccess(); 38 | } 39 | 40 | return rval; 41 | } 42 | -------------------------------------------------------------------------------- /cpp/validation/Max.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2008-2009 Digital Bazaar, Inc. All rights reserved. 3 | */ 4 | #ifndef monarch_validation_Max_H 5 | #define monarch_validation_Max_H 6 | 7 | #include "monarch/validation/Validator.h" 8 | 9 | namespace monarch 10 | { 11 | namespace validation 12 | { 13 | 14 | /** 15 | * Validates the maximum size of a string, array, or map. 16 | * 17 | * NOTE: For numeric types this checks against the storage size. 18 | * 19 | * @author David I. Lehn 20 | */ 21 | class Max : public Validator 22 | { 23 | protected: 24 | /* Size limit */ 25 | int mSize; 26 | 27 | public: 28 | /** 29 | * Creates a new validator. 30 | * 31 | * @param errorMessage custom error message 32 | */ 33 | Max(int size, const char* errorMessage = NULL); 34 | 35 | /** 36 | * Destructs this validator. 37 | */ 38 | virtual ~Max(); 39 | 40 | /** 41 | * Checks if an object is valid. 42 | * 43 | * @param obj the object to validate. 44 | * @param context context to use during validation. 45 | * 46 | * @return true if obj is valid, false and exception set otherwise. 47 | */ 48 | virtual bool isValid( 49 | monarch::rt::DynamicObject& obj, 50 | ValidatorContext* context); 51 | using Validator::isValid; 52 | }; 53 | 54 | } // end namespace validation 55 | } // end namespace monarch 56 | #endif 57 | -------------------------------------------------------------------------------- /cpp/validation/Member.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2010 Digital Bazaar, Inc. All rights reserved. 3 | */ 4 | #include "monarch/validation/Member.h" 5 | 6 | using namespace monarch::rt; 7 | using namespace monarch::validation; 8 | 9 | Member::Member(const char* key, const char* errorMessage) : 10 | Validator(errorMessage), 11 | mKey(strdup(key)) 12 | { 13 | } 14 | 15 | Member::~Member() 16 | { 17 | free(mKey); 18 | } 19 | 20 | bool Member::isValid( 21 | DynamicObject& obj, 22 | ValidatorContext* context) 23 | { 24 | bool rval = true; 25 | 26 | if(!obj.isNull() && obj->getType() == monarch::rt::Map) 27 | { 28 | if(!obj->hasMember(mKey)) 29 | { 30 | // only add a "." if this is not a root map 31 | if(context->getDepth() != 0) 32 | { 33 | context->pushPath("."); 34 | } 35 | context->pushPath(mKey); 36 | DynamicObject detail = 37 | context->addError("monarch.validation.MissingField", &obj); 38 | detail["validator"] = "monarch.validator.Member"; 39 | detail["message"] = (mErrorMessage == NULL) ? 40 | "A required field has not been specified." : 41 | mErrorMessage; 42 | detail["key"] = mKey; 43 | rval = false; 44 | context->popPath(); 45 | if(context->getDepth() > 0) 46 | { 47 | context->popPath(); 48 | } 49 | } 50 | } 51 | else 52 | { 53 | rval = false; 54 | DynamicObject detail = 55 | context->addError("monarch.validation.TypeError", &obj); 56 | detail["validator"] = "monarch.validator.Member"; 57 | detail["message"] = "The given object type must a mapping (Map) type"; 58 | } 59 | 60 | return rval; 61 | } 62 | -------------------------------------------------------------------------------- /cpp/validation/Min.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2008-2009 Digital Bazaar, Inc. All rights reserved. 3 | */ 4 | #include "monarch/validation/Min.h" 5 | 6 | using namespace monarch::rt; 7 | using namespace monarch::validation; 8 | 9 | Min::Min(int size, const char* errorMessage) : 10 | Validator(errorMessage), 11 | mSize(size) 12 | { 13 | } 14 | 15 | Min::~Min() 16 | { 17 | } 18 | 19 | bool Min::isValid( 20 | DynamicObject& obj, 21 | ValidatorContext* context) 22 | { 23 | bool rval = (!obj.isNull() && obj->length() >= mSize); 24 | 25 | if(!rval) 26 | { 27 | DynamicObject detail = context->addError("monarch.validation.MinError", &obj); 28 | detail["validator"] = "monarch.validator.Min"; 29 | if(mErrorMessage) 30 | { 31 | detail["message"] = mErrorMessage; 32 | } 33 | detail["expectedMin"] = mSize; 34 | } 35 | else 36 | { 37 | context->addSuccess(); 38 | } 39 | 40 | return rval; 41 | } 42 | -------------------------------------------------------------------------------- /cpp/validation/Min.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2008-2009 Digital Bazaar, Inc. All rights reserved. 3 | */ 4 | #ifndef monarch_validation_Min_H 5 | #define monarch_validation_Min_H 6 | 7 | #include "monarch/validation/Validator.h" 8 | 9 | namespace monarch 10 | { 11 | namespace validation 12 | { 13 | 14 | /** 15 | * Validates the minimum size of a string, array, or map. 16 | * 17 | * NOTE: For numeric types this checks against the storage size. 18 | * 19 | * @author David I. Lehn 20 | */ 21 | class Min : public Validator 22 | { 23 | protected: 24 | /* Size limit */ 25 | int mSize; 26 | 27 | public: 28 | /** 29 | * Creates a new validator. 30 | * 31 | * @param errorMessage custom error message 32 | */ 33 | Min(int size, const char* errorMessage = NULL); 34 | 35 | /** 36 | * Destructs this validator. 37 | */ 38 | virtual ~Min(); 39 | 40 | /** 41 | * Checks if an object is valid. 42 | * 43 | * @param obj the object to validate. 44 | * @param context context to use during validation. 45 | * 46 | * @return true if obj is valid, false and exception set otherwise. 47 | */ 48 | virtual bool isValid( 49 | monarch::rt::DynamicObject& obj, 50 | ValidatorContext* context); 51 | using Validator::isValid; 52 | }; 53 | 54 | } // end namespace validation 55 | } // end namespace monarch 56 | #endif 57 | -------------------------------------------------------------------------------- /cpp/validation/Not.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2008-2011 Digital Bazaar, Inc. All rights reserved. 3 | */ 4 | #include "monarch/validation/Not.h" 5 | 6 | using namespace monarch::rt; 7 | using namespace monarch::validation; 8 | 9 | Not::Not(Validator* validator, const char* errorMessage) : 10 | Validator(errorMessage), 11 | mValidator(validator), 12 | mValidatorRef(NULL) 13 | { 14 | } 15 | 16 | Not::Not(ValidatorRef& validator, const char* errorMessage) : 17 | Validator(errorMessage), 18 | mValidator(&(*validator)), 19 | mValidatorRef(validator) 20 | { 21 | } 22 | 23 | Not::~Not() 24 | { 25 | if(mValidatorRef.isNull()) 26 | { 27 | delete mValidator; 28 | } 29 | } 30 | 31 | bool Not::isValid( 32 | monarch::rt::DynamicObject& obj, 33 | ValidatorContext* context) 34 | { 35 | // save state, ignore sub-validator results 36 | bool setExceptions = context->setExceptions(false); 37 | context->pushResults(); 38 | // check sub-validator 39 | bool rval = !mValidator->isValid(obj, context); 40 | // restore state and results 41 | context->setExceptions(setExceptions); 42 | context->popResults(); 43 | 44 | if(!rval) 45 | { 46 | DynamicObject detail = 47 | context->addError("monarch.validation.ValueError", &obj); 48 | detail["validator"] = "monarch.validator.Not"; 49 | if(mErrorMessage) 50 | { 51 | detail["message"] = mErrorMessage; 52 | } 53 | } 54 | else 55 | { 56 | context->addSuccess(); 57 | } 58 | 59 | return rval; 60 | } 61 | -------------------------------------------------------------------------------- /cpp/validation/Not.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2008-2011 Digital Bazaar, Inc. All rights reserved. 3 | */ 4 | #ifndef monarch_validation_Not_H 5 | #define monarch_validation_Not_H 6 | 7 | #include "monarch/validation/Validator.h" 8 | 9 | namespace monarch 10 | { 11 | namespace validation 12 | { 13 | 14 | /** 15 | * Negates the result of a sub-validator. Exceptions from the sub-validator 16 | * are supressed. 17 | * 18 | * @author David I. Lehn 19 | */ 20 | class Not : public Validator 21 | { 22 | protected: 23 | /* sub-validator to use */ 24 | Validator* mValidator; 25 | ValidatorRef mValidatorRef; 26 | 27 | public: 28 | /** 29 | * Creates a new validator. 30 | */ 31 | Not(Validator* validator, const char* errorMessage = NULL); 32 | 33 | /** 34 | * Creates a new validator. 35 | */ 36 | Not(ValidatorRef& validator, const char* errorMessage = NULL); 37 | 38 | /** 39 | * Destructs this validator. 40 | */ 41 | virtual ~Not(); 42 | 43 | /** 44 | * Checks if an object is invalid. 45 | * 46 | * @param obj the object to validate. Must be an Array or Map. 47 | * @param context context to use during validation. 48 | * 49 | * @return true if obj is valid, false and exception set otherwise. 50 | */ 51 | virtual bool isValid( 52 | monarch::rt::DynamicObject& obj, 53 | ValidatorContext* context); 54 | using Validator::isValid; 55 | }; 56 | 57 | } // end namespace validation 58 | } // end namespace monarch 59 | #endif 60 | -------------------------------------------------------------------------------- /cpp/validation/NotCompare.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2008-2011 Digital Bazaar, Inc. All rights reserved. 3 | */ 4 | #ifndef monarch_validation_NotCompare_H 5 | #define monarch_validation_NotCompare_H 6 | 7 | #include "monarch/validation/Validator.h" 8 | # 9 | namespace monarch 10 | { 11 | namespace validation 12 | { 13 | 14 | /** 15 | * Validates equality of the values for two keys of a DynamicObject Map. 16 | * 17 | * d => { "aKey": aValue, "bKey": bValue } 18 | * 19 | * Validate aValue and bValue are the same (via ==) with: 20 | * 21 | * NotCompare c("aKey", "bKey"); 22 | * c.isValid(d) 23 | * 24 | * @author David I. Lehn 25 | */ 26 | class NotCompare : public Validator 27 | { 28 | protected: 29 | /* First key to use */ 30 | char* mKey0; 31 | 32 | /* Second key to use */ 33 | char* mKey1; 34 | 35 | public: 36 | /** 37 | * Creates a new validator. 38 | * 39 | * @param key0 first key to use 40 | * @param key1 second key to use 41 | * @param errorMessage custom error message 42 | */ 43 | NotCompare( 44 | const char* key0, const char* key2, const char* errorMessage = NULL); 45 | 46 | /** 47 | * Destructs this validator. 48 | */ 49 | virtual ~NotCompare(); 50 | 51 | /** 52 | * Checks if an object is valid. 53 | * 54 | * @param obj the object to validate. 55 | * @param context context to use during validation. 56 | * 57 | * @return true if obj is valid, false and exception set otherwise. 58 | */ 59 | virtual bool isValid( 60 | monarch::rt::DynamicObject& obj, 61 | ValidatorContext* context); 62 | using Validator::isValid; 63 | }; 64 | 65 | } // end namespace validation 66 | } // end namespace monarch 67 | #endif 68 | -------------------------------------------------------------------------------- /cpp/validation/NotValid.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2008-2009 Digital Bazaar, Inc. All rights reserved. 3 | */ 4 | #include "monarch/validation/NotValid.h" 5 | 6 | using namespace monarch::rt; 7 | using namespace monarch::validation; 8 | 9 | NotValid::NotValid(const char* errorMessage) : 10 | Validator(errorMessage) 11 | { 12 | } 13 | 14 | NotValid::~NotValid() 15 | { 16 | } 17 | 18 | bool NotValid::isValid( 19 | DynamicObject& obj, 20 | ValidatorContext* context) 21 | { 22 | DynamicObject detail = context->addError("monarch.validation.NotValid", &obj); 23 | detail["validator"] = "monarch.validator.NotValid"; 24 | if(mErrorMessage) 25 | { 26 | detail["message"] = mErrorMessage; 27 | } 28 | return false; 29 | } 30 | -------------------------------------------------------------------------------- /cpp/validation/NotValid.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2008-2009 Digital Bazaar, Inc. All rights reserved. 3 | */ 4 | #ifndef monarch_validation_NotValid_H 5 | #define monarch_validation_NotValid_H 6 | 7 | #include "monarch/validation/Validator.h" 8 | 9 | namespace monarch 10 | { 11 | namespace validation 12 | { 13 | 14 | /** 15 | * A validator that always fails. 16 | * 17 | * @author David I. Lehn 18 | */ 19 | class NotValid : public Validator 20 | { 21 | public: 22 | /** 23 | * Creates a new validator. 24 | * 25 | * @param errorMessage custom error message 26 | */ 27 | NotValid(const char* errorMessage = NULL); 28 | 29 | /** 30 | * Destructs this validator. 31 | */ 32 | virtual ~NotValid(); 33 | 34 | /** 35 | * Checks if an object is valid. 36 | * 37 | * @param obj the object to validate. 38 | * @param context context to use during validation. 39 | * 40 | * @return true if obj is valid, false and exception set otherwise. 41 | */ 42 | virtual bool isValid( 43 | monarch::rt::DynamicObject& obj, 44 | ValidatorContext* context); 45 | using Validator::isValid; 46 | }; 47 | 48 | } // end namespace validation 49 | } // end namespace monarch 50 | #endif 51 | -------------------------------------------------------------------------------- /cpp/validation/Null.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2008-2009 Digital Bazaar, Inc. All rights reserved. 3 | */ 4 | #include "monarch/validation/Null.h" 5 | 6 | using namespace monarch::rt; 7 | using namespace monarch::validation; 8 | 9 | Null::Null(const char* errorMessage) : 10 | Validator(errorMessage) 11 | { 12 | } 13 | 14 | Null::~Null() 15 | { 16 | } 17 | 18 | bool Null::isValid( 19 | monarch::rt::DynamicObject& obj, 20 | ValidatorContext* context) 21 | { 22 | bool rval = obj.isNull(); 23 | 24 | if(!rval) 25 | { 26 | DynamicObject detail = 27 | context->addError("monarch.validation.NotNullError", &obj); 28 | detail["validator"] = "monarch.validator.Null"; 29 | detail["expectedValue"] = "null"; 30 | if(mErrorMessage) 31 | { 32 | detail["message"] = mErrorMessage; 33 | } 34 | // FIXME: add expected value to error detail? 35 | } 36 | else 37 | { 38 | context->addSuccess(); 39 | } 40 | 41 | return rval; 42 | } 43 | -------------------------------------------------------------------------------- /cpp/validation/Null.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2008-2009 Digital Bazaar, Inc. All rights reserved. 3 | */ 4 | #ifndef monarch_validation_Null_H 5 | #define monarch_validation_Null_H 6 | 7 | #include "monarch/validation/Validator.h" 8 | 9 | namespace monarch 10 | { 11 | namespace validation 12 | { 13 | 14 | /** 15 | * Validates the target object as being null. 16 | * 17 | * @author Dave Longley 18 | */ 19 | class Null : public Validator 20 | { 21 | public: 22 | /** 23 | * Creates a new validator. 24 | * 25 | * @param errorMessage custom error message. 26 | */ 27 | Null(const char* errorMessage = NULL); 28 | 29 | /** 30 | * Destructs this validator. 31 | */ 32 | virtual ~Null(); 33 | 34 | /** 35 | * Checks if an object is valid. 36 | * 37 | * @param obj the object to validate. 38 | * @param context context to use during validation. 39 | * 40 | * @return true if obj is valid, false and exception set otherwise. 41 | */ 42 | virtual bool isValid( 43 | monarch::rt::DynamicObject& obj, 44 | ValidatorContext* context); 45 | using Validator::isValid; 46 | }; 47 | 48 | } // end namespace validation 49 | } // end namespace monarch 50 | #endif 51 | -------------------------------------------------------------------------------- /cpp/validation/Optional.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2008-2011 Digital Bazaar, Inc. All rights reserved. 3 | */ 4 | #include "monarch/validation/Optional.h" 5 | 6 | using namespace monarch::rt; 7 | using namespace monarch::validation; 8 | 9 | Optional::Optional(Validator* validator) : 10 | mValidator(validator), 11 | mValidatorRef(NULL) 12 | { 13 | } 14 | 15 | Optional::Optional(ValidatorRef& validator) : 16 | mValidator(&(*validator)), 17 | mValidatorRef(validator) 18 | { 19 | } 20 | 21 | Optional::~Optional() 22 | { 23 | if(mValidatorRef.isNull()) 24 | { 25 | delete mValidator; 26 | } 27 | } 28 | 29 | bool Optional::isValid( 30 | DynamicObject& obj, 31 | ValidatorContext* context) 32 | { 33 | return mValidator->isValid(obj, context); 34 | } 35 | 36 | bool Optional::isOptional(ValidatorContext* context) 37 | { 38 | return true; 39 | } 40 | -------------------------------------------------------------------------------- /cpp/validation/Regex.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2008-2011 Digital Bazaar, Inc. All rights reserved. 3 | */ 4 | #include "monarch/validation/Regex.h" 5 | 6 | #include "monarch/util/Pattern.h" 7 | #include "monarch/validation/Type.h" 8 | 9 | #include 10 | 11 | using namespace monarch::rt; 12 | using namespace monarch::util; 13 | using namespace monarch::validation; 14 | 15 | Regex::Regex(const char* regex, const char* errorMessage) : 16 | Validator(errorMessage) 17 | { 18 | mRegex = regex ? strdup(regex) : strdup("^$"); 19 | mStringValidator = new Type(String); 20 | } 21 | 22 | Regex::~Regex() 23 | { 24 | free(mRegex); 25 | delete mStringValidator; 26 | } 27 | 28 | bool Regex::isValid( 29 | monarch::rt::DynamicObject& obj, 30 | ValidatorContext* context) 31 | { 32 | bool rval = mStringValidator->isValid(obj, context); 33 | 34 | if(rval) 35 | { 36 | // FIXME compile the regex 37 | rval = Pattern::match(mRegex, obj->getString()); 38 | if(!rval) 39 | { 40 | DynamicObject detail = 41 | context->addError("monarch.validation.ValueError", &obj); 42 | detail["validator"] = "monarch.validator.Regex"; 43 | if(mErrorMessage) 44 | { 45 | detail["message"] = mErrorMessage; 46 | } 47 | } 48 | else 49 | { 50 | context->addSuccess(); 51 | } 52 | } 53 | 54 | return rval; 55 | } 56 | -------------------------------------------------------------------------------- /cpp/validation/Regex.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2008-2009 Digital Bazaar, Inc. All rights reserved. 3 | */ 4 | #ifndef monarch_validation_Regex_H 5 | #define monarch_validation_Regex_H 6 | 7 | #include "monarch/validation/Validator.h" 8 | 9 | namespace monarch 10 | { 11 | namespace validation 12 | { 13 | 14 | /** 15 | * Validates the target object with a regular expression. The target must be a 16 | * string and an automatic Type(String) validator is applied to test for this 17 | * pre-condition. 18 | * 19 | * @author David I. Lehn 20 | */ 21 | class Regex : public Validator 22 | { 23 | protected: 24 | /* regex string */ 25 | char* mRegex; 26 | 27 | /* automatic string validator */ 28 | Validator* mStringValidator; 29 | 30 | public: 31 | /** 32 | * Creates a new validator. If regex is NULL will match against the pattern 33 | * "^$". 34 | * 35 | * @param regex the regular expression to use 36 | * @param errorMessage custom error message 37 | */ 38 | Regex(const char* regex, const char* errorMessage = NULL); 39 | 40 | /** 41 | * Destructs this validator. 42 | */ 43 | virtual ~Regex(); 44 | 45 | /** 46 | * Checks if an object is valid. Object must be a string. 47 | * 48 | * @param obj the object to validate. 49 | * @param context context to use during validation. 50 | * 51 | * @return true if obj is valid, false and exception set otherwise. 52 | */ 53 | virtual bool isValid( 54 | monarch::rt::DynamicObject& obj, 55 | ValidatorContext* context); 56 | using Validator::isValid; 57 | }; 58 | 59 | } // end namespace validation 60 | } // end namespace monarch 61 | #endif 62 | -------------------------------------------------------------------------------- /cpp/validation/Type.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2008-2009 Digital Bazaar, Inc. All rights reserved. 3 | */ 4 | #include "monarch/validation/Type.h" 5 | 6 | using namespace monarch::rt; 7 | using namespace monarch::validation; 8 | 9 | Type::Type(monarch::rt::DynamicObjectType type, const char* errorMessage) : 10 | Validator(errorMessage), 11 | mType(type) 12 | { 13 | } 14 | 15 | Type::~Type() 16 | { 17 | } 18 | 19 | bool Type::isValid(DynamicObject& obj, ValidatorContext* context) 20 | { 21 | bool rval = (!obj.isNull() && obj->getType() == mType); 22 | 23 | if(!rval) 24 | { 25 | const char* strType = 26 | obj.isNull() ? 27 | "null" : 28 | DynamicObject::descriptionForType(obj->getType()); 29 | 30 | DynamicObject detail = context->addError("monarch.validation.TypeError", &obj); 31 | detail["validator"] = "monarch.validator.Type"; 32 | // FIXME: localize -- lehn 33 | // FIXME: really? do we need to mention this, because we'd have to 34 | // do this for every string in the system.. -- manu 35 | detail["message"] = mErrorMessage ? mErrorMessage : 36 | "The given object type is different from the " \ 37 | "required object type."; 38 | detail["givenType"] = strType; 39 | detail["requiredType"] = DynamicObject::descriptionForType(mType); 40 | } 41 | else 42 | { 43 | context->addSuccess(); 44 | } 45 | 46 | return rval; 47 | } 48 | -------------------------------------------------------------------------------- /cpp/validation/Type.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2008-2009 Digital Bazaar, Inc. All rights reserved. 3 | */ 4 | #ifndef monarch_validation_Type_H 5 | #define monarch_validation_Type_H 6 | 7 | #include "monarch/validation/Validator.h" 8 | 9 | namespace monarch 10 | { 11 | namespace validation 12 | { 13 | 14 | /** 15 | * Validates the type of an object. 16 | * 17 | * d => 0 18 | * 19 | * Type ti(Int32); 20 | * ti.isValid(d) => true 21 | * 22 | * Type ts(String); 23 | * ts.isValid(d) => false 24 | * 25 | * @author David I. Lehn 26 | */ 27 | class Type : public Validator 28 | { 29 | protected: 30 | monarch::rt::DynamicObjectType mType; 31 | 32 | public: 33 | /** 34 | * Creates a new validator. 35 | * 36 | * @param errorMessage custom error message 37 | */ 38 | Type(monarch::rt::DynamicObjectType type, const char* errorMessage = NULL); 39 | 40 | /** 41 | * Destructs this validator. 42 | */ 43 | virtual ~Type(); 44 | 45 | /** 46 | * Checks if an object is valid. 47 | * 48 | * @param obj the object to validate. 49 | * @param context context to use during validation. 50 | * 51 | * @return true if obj is valid, false and exception set otherwise. 52 | */ 53 | virtual bool isValid( 54 | monarch::rt::DynamicObject& obj, 55 | ValidatorContext* context); 56 | using Validator::isValid; 57 | }; 58 | 59 | } // end namespace validation 60 | } // end namespace monarch 61 | #endif 62 | -------------------------------------------------------------------------------- /cpp/validation/Valid.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2008-2009 Digital Bazaar, Inc. All rights reserved. 3 | */ 4 | #include "monarch/validation/Valid.h" 5 | 6 | using namespace monarch::rt; 7 | using namespace monarch::validation; 8 | 9 | Valid::Valid() 10 | { 11 | } 12 | 13 | Valid::~Valid() 14 | { 15 | } 16 | 17 | bool Valid::isValid( 18 | DynamicObject& obj, 19 | ValidatorContext* context) 20 | { 21 | return true; 22 | } 23 | -------------------------------------------------------------------------------- /cpp/validation/Valid.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2008-2009 Digital Bazaar, Inc. All rights reserved. 3 | */ 4 | #ifndef monarch_validation_Valid_H 5 | #define monarch_validation_Valid_H 6 | 7 | #include "monarch/validation/Validator.h" 8 | 9 | namespace monarch 10 | { 11 | namespace validation 12 | { 13 | 14 | /** 15 | * A validator which always succeeds. 16 | * 17 | * @author David I. Lehn 18 | */ 19 | class Valid : public Validator 20 | { 21 | public: 22 | /** 23 | * Creates a new validator. 24 | */ 25 | Valid(); 26 | 27 | /** 28 | * Destructs this validator. 29 | */ 30 | virtual ~Valid(); 31 | 32 | /** 33 | * Checks if an object is valid. 34 | * 35 | * @param obj the object to validate. 36 | * @param context context to use during validation. 37 | * 38 | * @return true if obj is valid, false and exception set otherwise. 39 | */ 40 | virtual bool isValid( 41 | monarch::rt::DynamicObject& obj, 42 | ValidatorContext* context); 43 | using Validator::isValid; 44 | }; 45 | 46 | } // end namespace validation 47 | } // end namespace monarch 48 | #endif 49 | -------------------------------------------------------------------------------- /cpp/validation/Validation.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2008-2012 Digital Bazaar, Inc. All rights reserved. 3 | */ 4 | #ifndef monarch_validation_Validation_H 5 | #define monarch_validation_Validation_H 6 | 7 | /* Top-level include for all the standard Validators */ 8 | 9 | #include "monarch/validation/All.h" 10 | #include "monarch/validation/Any.h" 11 | #include "monarch/validation/Array.h" 12 | #include "monarch/validation/Compare.h" 13 | #include "monarch/validation/CompareText.h" 14 | #include "monarch/validation/Contains.h" 15 | #include "monarch/validation/Each.h" 16 | #include "monarch/validation/Equals.h" 17 | #include "monarch/validation/In.h" 18 | #include "monarch/validation/Int.h" 19 | #include "monarch/validation/Map.h" 20 | #include "monarch/validation/Max.h" 21 | #include "monarch/validation/Member.h" 22 | #include "monarch/validation/Min.h" 23 | #include "monarch/validation/Not.h" 24 | #include "monarch/validation/NotCompare.h" 25 | #include "monarch/validation/NotValid.h" 26 | #include "monarch/validation/Null.h" 27 | #include "monarch/validation/Optional.h" 28 | #include "monarch/validation/Regex.h" 29 | #include "monarch/validation/Type.h" 30 | #include "monarch/validation/Valid.h" 31 | #include "monarch/validation/ValidatorList.h" 32 | #include "monarch/validation/ValidatorContext.h" 33 | #include "monarch/validation/ValidatorFactory.h" 34 | 35 | #endif 36 | -------------------------------------------------------------------------------- /cpp/validation/Validator.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2008-2011 Digital Bazaar, Inc. All rights reserved. 3 | */ 4 | #include "monarch/validation/Validator.h" 5 | 6 | #include 7 | 8 | using namespace monarch::rt; 9 | using namespace monarch::validation; 10 | 11 | Validator::Validator(const char* errorMessage) 12 | { 13 | mErrorMessage = errorMessage ? strdup(errorMessage) : NULL; 14 | } 15 | 16 | Validator::~Validator() 17 | { 18 | free(mErrorMessage); 19 | } 20 | 21 | bool Validator::isValid( 22 | monarch::rt::DynamicObject& obj, 23 | ValidatorContext* context) 24 | { 25 | context->addSuccess(); 26 | return true; 27 | } 28 | 29 | bool Validator::isValid(monarch::rt::DynamicObject& obj) 30 | { 31 | bool rval; 32 | ValidatorContext* ctx = new ValidatorContext(); 33 | rval = isValid(obj, ctx); 34 | delete ctx; 35 | return rval; 36 | } 37 | 38 | bool Validator::isOptional(ValidatorContext* context) 39 | { 40 | return false; 41 | } 42 | 43 | size_t Validator::length() 44 | { 45 | return 1; 46 | } 47 | -------------------------------------------------------------------------------- /cpp/ws/ChannelExceptionHandler.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2011 Digital Bazaar, Inc. All rights reserved. 3 | */ 4 | #include "monarch/ws/ChannelExceptionHandler.h" 5 | 6 | using namespace monarch::rt; 7 | using namespace monarch::ws; 8 | 9 | ChannelExceptionHandler::ChannelExceptionHandler() 10 | { 11 | } 12 | 13 | ChannelExceptionHandler::~ChannelExceptionHandler() 14 | { 15 | } 16 | 17 | void ChannelExceptionHandler::handleChannelException( 18 | ServiceChannel* ch, ExceptionRef& e) 19 | { 20 | // exception will only be null if a developer has failed to set an 21 | // exception in a service 22 | if(e.isNull()) 23 | { 24 | e = new monarch::rt::Exception( 25 | "An unspecified error occurred. " 26 | "No exception was set detailing the error.", 27 | "monarch.ws.WebServiceError"); 28 | e->getDetails()["httpStatusCode"] = 500; 29 | e->getDetails()["path"] = ch->getPath(); 30 | monarch::rt::Exception::set(e); 31 | } 32 | 33 | // send exception (client's fault if code < 500) 34 | bool clientsFault = 35 | e->getDetails()->hasMember("httpStatusCode") && 36 | e->getDetails()["httpStatusCode"]->getInt32() < 500; 37 | ch->sendException(e, clientsFault); 38 | } 39 | -------------------------------------------------------------------------------- /cpp/ws/Makefile.in: -------------------------------------------------------------------------------- 1 | # Makefile to compile the module in this directory 2 | 3 | LIBRARIES = mows 4 | mows_HEADERS = $(wildcard *.h) 5 | mows_SOURCES = $(wildcard *.cpp) 6 | 7 | DYNAMIC_LINK_LIBRARIES = mort moutil momodest moio mocrypto mologging monet mohttp moconfig 8 | 9 | DYNAMIC_MACOS_LINK_LIBRARIES = crypto ssl mocompress modata 10 | DYNAMIC_WINDOWS_LINK_LIBRARIES = libeay32 ssleay32 ws2_32 mocompress modata 11 | 12 | # ----------- Standard Makefile 13 | include @MONARCH_DIR@/setup/Makefile.base 14 | -------------------------------------------------------------------------------- /cpp/ws/RequestAuthenticator.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2011 Digital Bazaar, Inc. All rights reserved. 3 | */ 4 | #include "monarch/ws/RequestAuthenticator.h" 5 | 6 | using namespace monarch::rt; 7 | using namespace monarch::ws; 8 | 9 | RequestAuthenticator::RequestAuthenticator() 10 | { 11 | } 12 | 13 | RequestAuthenticator::~RequestAuthenticator() 14 | { 15 | } 16 | 17 | RequestAuthenticator::Result 18 | RequestAuthenticator::checkAuthentication(ServiceChannel* ch) 19 | { 20 | // anonymous authentication, nothing to set, always passes 21 | return Success; 22 | } 23 | -------------------------------------------------------------------------------- /installers/debian/changelog.in: -------------------------------------------------------------------------------- 1 | monarch3 (@FULL_DOTTED_VERSION@-1) stable; urgency=low 2 | 3 | * Latest release. 4 | 5 | -- Digital Bazaar, Inc. @DATE_RFC_2822@ 6 | -------------------------------------------------------------------------------- /installers/debian/compat: -------------------------------------------------------------------------------- 1 | 9 2 | -------------------------------------------------------------------------------- /installers/debian/control: -------------------------------------------------------------------------------- 1 | Source: monarch3 2 | Section: libs 3 | Priority: optional 4 | Maintainer: Digital Bazaar, Inc. 5 | Homepage: http://digitalbazaar.com/ 6 | Build-Depends: debhelper (>= 9), autotools-dev, pkg-config, libsqlite3-dev (>= 3.6.17), libmysqlclient-dev, libssl-dev, libexpat-dev 7 | Standards-Version: 3.8.0 8 | 9 | Package: monarch3 10 | Architecture: any 11 | Depends: ${shlibs:Depends}, libssl0.9.8 (>= 0.9.8g), libexpat1 (>= 1.95.8), libsqlite3-0 (>= 3.6.17) 12 | Description: Modular Networking Architecture (Monarch) Libraries 13 | The Monarch libraries support a variety of features required by 14 | modular, highly-scalable networking applications. These libraries provide 15 | basic software support for compression, configuration, cryptography, 16 | data I/O, events, logging, mail, networking, dynamic run-time objects, 17 | sphinx search indexer interaction, MySQL/SQLite3 interaction, test framework, 18 | and input validation. Together they constitute a suite of tools that enable 19 | developers to write blindingly fast web service APIs based on JSON message 20 | passing. The suite of libraries also includes the 21 | MODEST (MODular Extensible STate) engine, which is designed to 22 | provide a simple, lightweight, extensible state machine engine suited for 23 | performing heavily multi-threaded network I/O and data processing. 24 | -------------------------------------------------------------------------------- /installers/debian/copyright: -------------------------------------------------------------------------------- 1 | This package was debianized by Digital Bazaar, Inc. 2 | on June 19th, 2008. 3 | 4 | It was downloaded from http://wiki.digitalbazaar.com/ 5 | 6 | Upstream Author: Digital Bazaar, Inc. 7 | 8 | Copyright: 9 | 10 | Copyright (c) 2007-2008 Digital Bazaar, Inc. All rights reserved. 11 | -------------------------------------------------------------------------------- /installers/debian/rules: -------------------------------------------------------------------------------- 1 | #!/usr/bin/make -f 2 | %: 3 | dh $@ 4 | 5 | override_dh_auto_configure: 6 | dh_auto_configure -- \ 7 | --disable-log-line-numbers \ 8 | --disable-tests 9 | 10 | # FIXME: re-enable dh_strip when dbg package is generated 11 | override_dh_strip: 12 | -------------------------------------------------------------------------------- /monarch3.pc.in: -------------------------------------------------------------------------------- 1 | Name: MONARCH 2 | Description: Monarch - The Modular Networking Architecture 3 | Version: 0.0.0 4 | Cflags: @@CFLAGS@@ 5 | Libs: @@LIBS@@ -lpthread -lcrypto -lssl -lexpat -lsqlite3 6 | -------------------------------------------------------------------------------- /python/crypto/cppwrapper/dbcrypto.i: -------------------------------------------------------------------------------- 1 | %module mocrypto 2 | 3 | %{ 4 | #include "mocryptoWrapper.h" 5 | #include 6 | #include 7 | #include 8 | #include 9 | %} 10 | 11 | %include std_string.i 12 | %include "mocryptoWrapper.h" 13 | 14 | %inline %{ 15 | void mocrypto_init() 16 | { 17 | ERR_load_crypto_strings(); 18 | OpenSSL_add_all_algorithms(); 19 | } 20 | 21 | void mocrypto_cleanup() 22 | { 23 | // clean up SSL 24 | ERR_remove_state(0); 25 | ENGINE_cleanup(); 26 | ERR_free_strings(); 27 | EVP_cleanup(); 28 | CRYPTO_cleanup_all_ex_data(); 29 | } 30 | 31 | %} 32 | -------------------------------------------------------------------------------- /python/crypto/cppwrapper/test.py: -------------------------------------------------------------------------------- 1 | import mocrypto 2 | from mocrypto import * 3 | 4 | mocrypto_init() 5 | 6 | kf = KeyFactory() 7 | privateKey = PrivateKey() 8 | publicKey = PublicKey() 9 | result = kf.createKeyPair("DSA", privateKey, publicKey) 10 | print result 11 | print kf.writePrivateKeyToPem(privateKey, "password") 12 | print kf.writePublicKeyToPem(publicKey) 13 | print privateKey.getAlgorithm() 14 | print publicKey.getAlgorithm() 15 | 16 | md5 = MessageDigest("MD5") 17 | md5.update("THIS ") 18 | md5.update("IS A") 19 | md5.update(" MESSAGE") 20 | digest = md5.getDigest() 21 | print "calculated: " + digest 22 | print "correct: 78eebfd9d42958e3f31244f116ab7bbe" 23 | 24 | sha1 = MessageDigest("SHA1") 25 | sha1.update("THIS IS A") 26 | sha1.update(" MESSAGE") 27 | digest = sha1.getDigest() 28 | print "calculated: " + digest 29 | print "correct: 5f24f4d6499fd2d44df6c6e94be8b14a796c071d" 30 | 31 | ds = privateKey.createSignature() 32 | ds.update(digest) 33 | sig = ds.getValue() 34 | print "length=%s" % len(sig) 35 | b64 = sig.encode("base64") 36 | print b64 37 | 38 | ds = publicKey.createSignature() 39 | ds.update(digest) 40 | verified = ds.verify(sig) 41 | 42 | print "verified=%s" % verified 43 | keyFile = open("/work/src/dbcpp/monarch/trunk/crypto/python/cppwrapper/storedkey.pem") 44 | pem = keyFile.read(); 45 | loaded = kf.loadPrivateKeyFromPem(privateKey, pem, "password") 46 | print "loaded: %s" % loaded 47 | 48 | mocrypto_cleanup() 49 | -------------------------------------------------------------------------------- /setup/config.guess: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # 3 | # Wrapper for standard autotools config.guess. 4 | # Currently just a placeholder to match the config.sub wrapper and keep the 5 | # standard autotools support files together in a single location. 6 | # 7 | # Copyright (c) 2010 Digital Bazaar, Inc. 8 | 9 | `dirname $0`/support/config.guess $@ 10 | -------------------------------------------------------------------------------- /setup/config.sub: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # 3 | # Wrapper for standard autotools config.sub to provide extra aliases for 4 | # Monarch based products. Uses the real config.sub to resolve these 5 | # aliases and unknown aliases. 6 | # 7 | # Copyright (c) 2010 Digital Bazaar, Inc. 8 | 9 | CONFIG_SUB=`dirname $0`/support/config.sub 10 | CS_ARGS=$@ 11 | 12 | # Rewrite args for known aliases, else passthrough. 13 | if test $# -eq 1 ; then 14 | case $1 in 15 | linux) CS_ARGS=i686-linux ;; 16 | macos) CS_ARGS=i686-darwin ;; 17 | windows) CS_ARGS=i586-mingw32msvc ;; 18 | esac 19 | fi 20 | 21 | $CONFIG_SUB $CS_ARGS 22 | -------------------------------------------------------------------------------- /setup/m4/as-compiler-flag.m4: -------------------------------------------------------------------------------- 1 | dnl as-compiler-flag.m4 0.1.0 2 | 3 | dnl autostars m4 macro for detection of compiler flags 4 | 5 | dnl David Schleef 6 | dnl Tim-Philipp Müller 7 | 8 | dnl AS_COMPILER_FLAG(CFLAGS, ACTION-IF-ACCEPTED, [ACTION-IF-NOT-ACCEPTED]) 9 | dnl Tries to compile with the given CFLAGS. 10 | dnl Runs ACTION-IF-ACCEPTED if the compiler can compile with the flags, 11 | dnl and ACTION-IF-NOT-ACCEPTED otherwise. 12 | 13 | AC_DEFUN([AS_COMPILER_FLAG], 14 | [ 15 | AC_MSG_CHECKING([to see if compiler understands $1]) 16 | 17 | save_CFLAGS="$CFLAGS" 18 | CFLAGS="$CFLAGS $1" 19 | 20 | AC_TRY_COMPILE([ ], [], [flag_ok=yes], [flag_ok=no]) 21 | CFLAGS="$save_CFLAGS" 22 | 23 | if test "X$flag_ok" = Xyes ; then 24 | $2 25 | true 26 | else 27 | $3 28 | true 29 | fi 30 | AC_MSG_RESULT([$flag_ok]) 31 | ]) 32 | 33 | dnl AS_CXX_COMPILER_FLAG(CXXFLAGS, ACTION-IF-ACCEPTED, [ACTION-IF-NOT-ACCEPTED]) 34 | dnl Tries to compile with the given CXXFLAGS. 35 | dnl Runs ACTION-IF-ACCEPTED if the compiler can compile with the flags, 36 | dnl and ACTION-IF-NOT-ACCEPTED otherwise. 37 | 38 | AC_DEFUN([AS_CXX_COMPILER_FLAG], 39 | [ 40 | AC_REQUIRE([AC_PROG_CXX]) 41 | 42 | AC_MSG_CHECKING([to see if C++ compiler understands $1]) 43 | 44 | save_CXXFLAGS="$CXXFLAGS" 45 | CXXFLAGS="$CXXFLAGS $1" 46 | 47 | AC_LANG_PUSH(C++) 48 | 49 | AC_TRY_COMPILE([ ], [], [flag_ok=yes], [flag_ok=no]) 50 | CXXFLAGS="$save_CXXFLAGS" 51 | 52 | if test "X$flag_ok" = Xyes ; then 53 | $2 54 | true 55 | else 56 | $3 57 | true 58 | fi 59 | 60 | AC_LANG_POP(C++) 61 | 62 | AC_MSG_RESULT([$flag_ok]) 63 | ]) 64 | 65 | --------------------------------------------------------------------------------