├── CONTRIBUTORS ├── src ├── .gitignore ├── examples │ └── hello │ │ ├── CMakeLists.txt │ │ ├── xmppthread.h │ │ ├── xmpptasks.h │ │ ├── main.cc │ │ ├── xmpppump.h │ │ └── xmppthread.cc ├── config.h.in ├── md5.h ├── messagehandler.cc ├── basicdefs.h ├── proxyinfo.cc ├── win32socketinit.h ├── messagehandler.h ├── checks.cc ├── checks.h ├── xmlprinter.h ├── proxydetect.h ├── stringdigest.h ├── stringdigest.cc ├── socketfactory.h ├── proxyinfo.h ├── helpers.h ├── asyncfile.h ├── win32socketinit.cc ├── saslhandler.h ├── event.h ├── saslmechanism.cc ├── xmlconstants.cc ├── xmlnsstack.h ├── macutils.h ├── common.cc ├── sslidentity.cc ├── saslplainmechanism.h ├── sslstreamadapter.cc ├── constructormagic.h ├── macconversion.h ├── socketserver.h ├── win32securityerrors.cc ├── asyncudpsocket.h ├── xmlconstants.h ├── prexmppauthimpl.cc ├── urlencode.h ├── nethelpers.h ├── xmlbuilder.h ├── winfirewall.h ├── asyncpacketsocket.h ├── win32window.h ├── asynctcpsocket.h ├── prexmppauthimpl.h ├── saslmechanism.h ├── bytebuffer.h ├── plainsaslhandler.h ├── asyncudpsocket.cc ├── asyncpacketsocket.cc ├── time.h ├── ssladapter.h ├── taskparent.h ├── autodetectproxy.h ├── prexmppauth.h ├── ssladapter.cc ├── qname.h ├── xmppasyncsocketimpl.h ├── xmppstanzaparser.cc ├── ratelimitmanager.cc ├── linux.h ├── saslcookiemechanism.h ├── xmppasyncsocket.h ├── xmpplogintask.h ├── taskparent.cc ├── schanneladapter.h ├── base64.h ├── winping.h ├── xmppstanzaparser.h ├── sslsocketfactory.h ├── Equifax_Secure_Global_eBusiness_CA-1.h └── sslidentity.h ├── .gitignore ├── CHANGELOG ├── README.md ├── COPYING.Google ├── LICENSE └── CMakeLists.txt /CONTRIBUTORS: -------------------------------------------------------------------------------- 1 | Google Inc. 2 | Silas Sewell 3 | -------------------------------------------------------------------------------- /src/.gitignore: -------------------------------------------------------------------------------- 1 | base 2 | xmllite 3 | xmpp 4 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *.backup 2 | *.dylib 3 | *.log 4 | *.o 5 | *.os 6 | *.so 7 | .*.swp 8 | .scon* 9 | config.h 10 | hello-example 11 | -------------------------------------------------------------------------------- /CHANGELOG: -------------------------------------------------------------------------------- 1 | 0.0.3 -- ????-??-?? 2 | * Upstream revisions 22-27 3 | 4 | 0.0.2 -- 2010-07-02 5 | * Add compiler optimizations 6 | * Fix compiler warnings (OS X) 7 | * Fix installer (OS X) 8 | 9 | 0.0.1 -- 2010-06-15 10 | * Initial release 11 | -------------------------------------------------------------------------------- /src/examples/hello/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | set(SOURCES 2 | main.cc 3 | xmpppump.cc 4 | xmpppump.h 5 | xmpptasks.cc 6 | xmpptasks.h 7 | xmppthread.cc 8 | xmppthread.h) 9 | 10 | add_executable(hello ${SOURCES}) 11 | target_link_libraries(hello txmpp) 12 | -------------------------------------------------------------------------------- /src/config.h.in: -------------------------------------------------------------------------------- 1 | #ifndef _TXMPP_CONFIG_H_ 2 | #define _TXMPP_CONFIG_H_ 3 | 4 | // Platforms: the checks are "#ifdef" 5 | #cmakedefine OSX 1 6 | #cmakedefine LINUX 1 7 | #cmakedefine WIN32 1 8 | #cmakedefine ANDROID 1 9 | 10 | // Configuration: the checks are "#if" 11 | #cmakedefine POSIX 1 12 | 13 | #cmakedefine FEATURE_ENABLE_SSL 1 14 | #cmakedefine HAVE_OPENSSL_SSL_H 1 15 | #cmakedefine SSL_USE_OPENSSL 1 16 | #cmakedefine USE_SSLSTREAM 1 17 | 18 | #cmakedefine COMPILER_MSVC 1 19 | 20 | #endif 21 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | txmpp 2 | ===== 3 | 4 | ### Project Status 5 | 6 | This was one patch Rylie made on top of a [third-party upstream project][motivating-factor] that appears to be unmaintained as well. 7 | I have moved on, no longer use this, and have no capacity to meaningfully maintain it. 8 | 9 | **Unmaintained** 10 | 11 | ### Intro 12 | 13 | _txmpp_ is a C++ XMPP library created from the non-[XEP-0166][xep0166] portions 14 | of [libjingle][libjingle] with various bits removed and tweaked. 15 | 16 | The [motivating factor][motivating-factor] for "creating" _txmpp_ was the lack 17 | of [permissively licenced alternatives][permissive]. 18 | 19 | If you don't mind a library with a [copyleft][copyleft] license you might also 20 | try [gloox][gloox]. 21 | 22 | ### Build 23 | 24 | scons --with-examples 25 | 26 | ### Getting Started 27 | 28 | See the `src/examples` directory. 29 | 30 | ### License 31 | 32 | This work is licensed under the New BSD License (see the LICENSE file). 33 | 34 | [xep0166]: http://xmpp.org/extensions/xep-0166.html 35 | [motivating-factor]: http://www.silassewell.com/blog/2010/06/16/txmpp-a-bsd-licensed-cpp-xmpp-library/ 36 | [libjingle]: http://code.google.com/p/libjingle/ 37 | [permissive]: http://en.wikipedia.org/wiki/Permissive_license 38 | [copyleft]: http://en.wikipedia.org/wiki/Copyleft 39 | [gloox]: http://camaya.net/gloox/ 40 | -------------------------------------------------------------------------------- /src/md5.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This is the header file for the MD5 message-digest algorithm. 3 | * The algorithm is due to Ron Rivest. This code was 4 | * written by Colin Plumb in 1993, no copyright is claimed. 5 | * This code is in the public domain; do with it what you wish. 6 | * 7 | * Equivalent code is available from RSA Data Security, Inc. 8 | * This code has been tested against that, and is equivalent, 9 | * except that you don't need to include two pages of legalese 10 | * with every copy. 11 | * To compute the message digest of a chunk of bytes, declare an 12 | * MD5Context structure, pass it to MD5Init, call MD5Update as 13 | * needed on buffers full of bytes, and then call MD5Final, which 14 | * will fill a supplied 16-byte array with the digest. 15 | * 16 | */ 17 | 18 | #ifndef _TXMPP_MD5_H_ 19 | #define _TXMPP_MD5_H_ 20 | 21 | #ifndef NO_CONFIG_H 22 | #include "config.h" 23 | #endif 24 | 25 | #ifdef __cplusplus 26 | extern "C" { 27 | #endif 28 | 29 | typedef long unsigned int uint32; 30 | typedef struct MD5Context MD5_CTX; 31 | 32 | #define md5byte unsigned char 33 | 34 | struct MD5Context { 35 | uint32 buf[4]; 36 | uint32 bits[2]; 37 | uint32 in[16]; 38 | }; 39 | 40 | void MD5Init(struct MD5Context *context); 41 | void MD5Update(struct MD5Context *context, md5byte const *buf, unsigned len); 42 | void MD5Final(unsigned char digest[16], struct MD5Context *context); 43 | void MD5Transform(uint32 buf[4], uint32 const in[16]); 44 | 45 | #ifdef __cplusplus 46 | }; 47 | #endif 48 | 49 | #endif // _TXMPP_MD5_H_ 50 | -------------------------------------------------------------------------------- /COPYING.Google: -------------------------------------------------------------------------------- 1 | Copyright (c) 2004--2005, Google Inc. 2 | All rights reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without modification, 5 | are permitted provided that the following conditions are met: 6 | 7 | * Redistributions of source code must retain the above copyright notice, 8 | this list of conditions and the following disclaimer. 9 | * Redistributions in binary form must reproduce the above copyright notice, 10 | this list of conditions and the following disclaimer in the documentation 11 | and/or other materials provided with the distribution. 12 | * The name of the author may not be used to endorse or promote products 13 | derived from this software without specific prior written permission. 14 | 15 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 16 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 17 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 18 | ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 19 | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 20 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE 21 | GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 22 | HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 23 | STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY 24 | WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 25 | SUCH DAMAGE. 26 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2004-2010, Google Inc. 2 | All rights reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without 5 | modification, are permitted provided that the following conditions are met: 6 | 7 | * Redistributions of source code must retain the above copyright 8 | notice, this list of conditions and the following disclaimer. 9 | 10 | * Redistributions in binary form must reproduce the above copyright 11 | notice, this list of conditions and the following disclaimer in the 12 | documentation and/or other materials provided with the distribution. 13 | 14 | * Neither the name of Google Inc. nor the names of its contributors may be 15 | used to endorse or promote products derived from this software without 16 | specific prior written permission. 17 | 18 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 19 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 20 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 21 | DISCLAIMED. IN NO EVENT SHALL BE LIABLE FOR ANY 22 | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 23 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 24 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 25 | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 27 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | -------------------------------------------------------------------------------- /src/messagehandler.cc: -------------------------------------------------------------------------------- 1 | /* 2 | * libjingle 3 | * Copyright 2004--2005, Google Inc. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions are met: 7 | * 8 | * 1. Redistributions of source code must retain the above copyright notice, 9 | * this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright notice, 11 | * this list of conditions and the following disclaimer in the documentation 12 | * and/or other materials provided with the distribution. 13 | * 3. The name of the author may not be used to endorse or promote products 14 | * derived from this software without specific prior written permission. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED 17 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 18 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO 19 | * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 20 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 21 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 22 | * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 23 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 24 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 25 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | */ 27 | 28 | #include "messagehandler.h" 29 | 30 | #include "messagequeue.h" 31 | 32 | namespace txmpp { 33 | 34 | MessageHandler::~MessageHandler() { 35 | MessageQueueManager::Instance()->Clear(this); 36 | } 37 | 38 | } // namespace txmpp 39 | -------------------------------------------------------------------------------- /src/basicdefs.h: -------------------------------------------------------------------------------- 1 | /* 2 | * libjingle 3 | * Copyright 2004--2005, Google Inc. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions are met: 7 | * 8 | * 1. Redistributions of source code must retain the above copyright notice, 9 | * this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright notice, 11 | * this list of conditions and the following disclaimer in the documentation 12 | * and/or other materials provided with the distribution. 13 | * 3. The name of the author may not be used to endorse or promote products 14 | * derived from this software without specific prior written permission. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED 17 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 18 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO 19 | * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 20 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 21 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 22 | * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 23 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 24 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 25 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | */ 27 | 28 | #ifndef _TXMPP_BASICDEFS_H_ 29 | #define _TXMPP_BASICDEFS_H_ 30 | 31 | #ifndef NO_CONFIG_H 32 | #include "config.h" 33 | #endif 34 | 35 | #define ARRAY_SIZE(x) (static_cast((sizeof(x)/sizeof(x[0])))) 36 | 37 | #endif // _TXMPP_BASICDEFS_H_ 38 | -------------------------------------------------------------------------------- /src/proxyinfo.cc: -------------------------------------------------------------------------------- 1 | /* 2 | * libjingle 3 | * Copyright 2004--2005, Google Inc. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions are met: 7 | * 8 | * 1. Redistributions of source code must retain the above copyright notice, 9 | * this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright notice, 11 | * this list of conditions and the following disclaimer in the documentation 12 | * and/or other materials provided with the distribution. 13 | * 3. The name of the author may not be used to endorse or promote products 14 | * derived from this software without specific prior written permission. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED 17 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 18 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO 19 | * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 20 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 21 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 22 | * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 23 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 24 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 25 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | */ 27 | 28 | #include "proxyinfo.h" 29 | 30 | namespace txmpp { 31 | 32 | const char * ProxyToString(ProxyType proxy) { 33 | const char * const PROXY_NAMES[] = { "none", "https", "socks5", "unknown" }; 34 | return PROXY_NAMES[proxy]; 35 | } 36 | 37 | } // namespace txmpp 38 | -------------------------------------------------------------------------------- /src/win32socketinit.h: -------------------------------------------------------------------------------- 1 | /* 2 | * libjingle 3 | * Copyright 2009, Google Inc. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions are met: 7 | * 8 | * 1. Redistributions of source code must retain the above copyright notice, 9 | * this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright notice, 11 | * this list of conditions and the following disclaimer in the documentation 12 | * and/or other materials provided with the distribution. 13 | * 3. The name of the author may not be used to endorse or promote products 14 | * derived from this software without specific prior written permission. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED 17 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 18 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO 19 | * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 20 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 21 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 22 | * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 23 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 24 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 25 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | */ 27 | 28 | #ifndef _TXMPP_WIN32SOCKETINIT_H_ 29 | #define _TXMPP_WIN32SOCKETINIT_H_ 30 | 31 | #ifndef NO_CONFIG_H 32 | #include "config.h" 33 | #endif 34 | 35 | namespace txmpp { 36 | 37 | void EnsureWinsockInit(); 38 | 39 | } // namespace txmpp 40 | 41 | #endif // TALK_BASE_WIN32SOCKETINIT_H_ 42 | -------------------------------------------------------------------------------- /src/messagehandler.h: -------------------------------------------------------------------------------- 1 | /* 2 | * libjingle 3 | * Copyright 2004--2005, Google Inc. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions are met: 7 | * 8 | * 1. Redistributions of source code must retain the above copyright notice, 9 | * this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright notice, 11 | * this list of conditions and the following disclaimer in the documentation 12 | * and/or other materials provided with the distribution. 13 | * 3. The name of the author may not be used to endorse or promote products 14 | * derived from this software without specific prior written permission. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED 17 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 18 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO 19 | * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 20 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 21 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 22 | * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 23 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 24 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 25 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | */ 27 | 28 | #ifndef _TXMPP_MESSAGEHANDLER_H_ 29 | #define _TXMPP_MESSAGEHANDLER_H_ 30 | 31 | #ifndef NO_CONFIG_H 32 | #include "config.h" 33 | #endif 34 | 35 | namespace txmpp { 36 | 37 | struct Message; 38 | 39 | // Messages get dispatched to a MessageHandler 40 | 41 | class MessageHandler { 42 | public: 43 | virtual ~MessageHandler(); 44 | 45 | virtual void OnMessage(Message* msg) = 0; 46 | }; 47 | 48 | } // namespace txmpp 49 | 50 | #endif // _TXMPP_MESSAGEHANDLER_H_ 51 | -------------------------------------------------------------------------------- /src/checks.cc: -------------------------------------------------------------------------------- 1 | /* 2 | * libjingle 3 | * Copyright 2006, Google Inc. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions are met: 7 | * 8 | * 1. Redistributions of source code must retain the above copyright notice, 9 | * this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright notice, 11 | * this list of conditions and the following disclaimer in the documentation 12 | * and/or other materials provided with the distribution. 13 | * 3. The name of the author may not be used to endorse or promote products 14 | * derived from this software without specific prior written permission. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED 17 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 18 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO 19 | * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 20 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 21 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 22 | * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 23 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 24 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 25 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | */ 27 | 28 | #include "checks.h" 29 | 30 | #include 31 | #include 32 | #include 33 | 34 | #include "logging.h" 35 | 36 | void Fatal(const char* file, int line, const char* format, ...) { 37 | char msg[256]; 38 | 39 | va_list arguments; 40 | va_start(arguments, format); 41 | vsnprintf(msg, sizeof(msg), format, arguments); 42 | va_end(arguments); 43 | 44 | LOG(LS_ERROR) << "\n\n#\n# Fatal error in " << file 45 | << ", line " << line << "\n#" << msg 46 | << "\n#\n"; 47 | abort(); 48 | } 49 | -------------------------------------------------------------------------------- /src/checks.h: -------------------------------------------------------------------------------- 1 | /* 2 | * libjingle 3 | * Copyright 2006, Google Inc. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions are met: 7 | * 8 | * 1. Redistributions of source code must retain the above copyright notice, 9 | * this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright notice, 11 | * this list of conditions and the following disclaimer in the documentation 12 | * and/or other materials provided with the distribution. 13 | * 3. The name of the author may not be used to endorse or promote products 14 | * derived from this software without specific prior written permission. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED 17 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 18 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO 19 | * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 20 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 21 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 22 | * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 23 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 24 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 25 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | */ 27 | 28 | // This module contains some basic debugging facilities. 29 | 30 | #ifndef _TXMPP_CHECKS_H_ 31 | #define _TXMPP_CHECKS_H_ 32 | 33 | #ifndef NO_CONFIG_H 34 | #include "config.h" 35 | #endif 36 | 37 | #include 38 | 39 | // Prints an error message to stderr and aborts execution. 40 | void Fatal(const char* file, int line, const char* format, ...); 41 | 42 | 43 | // The UNREACHABLE macro is very useful during development. 44 | #define UNREACHABLE() \ 45 | Fatal(__FILE__, __LINE__, "unreachable code") 46 | 47 | #endif // _TXMPP_CHECKS_H_ 48 | -------------------------------------------------------------------------------- /src/xmlprinter.h: -------------------------------------------------------------------------------- 1 | /* 2 | * libjingle 3 | * Copyright 2004--2005, Google Inc. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions are met: 7 | * 8 | * 1. Redistributions of source code must retain the above copyright notice, 9 | * this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright notice, 11 | * this list of conditions and the following disclaimer in the documentation 12 | * and/or other materials provided with the distribution. 13 | * 3. The name of the author may not be used to endorse or promote products 14 | * derived from this software without specific prior written permission. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED 17 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 18 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO 19 | * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 20 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 21 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 22 | * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 23 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 24 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 25 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | */ 27 | 28 | #ifndef _TXMPP_XMLPRINTER_H_ 29 | #define _TXMPP_XMLPRINTER_H_ 30 | 31 | #ifndef NO_CONFIG_H 32 | #include "config.h" 33 | #endif 34 | 35 | #include 36 | #include 37 | #include "scoped_ptr.h" 38 | 39 | namespace txmpp { 40 | 41 | class XmlElement; 42 | 43 | class XmlPrinter { 44 | public: 45 | static void PrintXml(std::ostream * pout, const XmlElement * pelt); 46 | 47 | static void PrintXml(std::ostream * pout, const XmlElement * pelt, 48 | const std::string * const xmlns, int xmlnsCount); 49 | }; 50 | 51 | } // namespace txmpp 52 | 53 | #endif // _TXMPP_XMLPRINTER_H_ 54 | -------------------------------------------------------------------------------- /src/proxydetect.h: -------------------------------------------------------------------------------- 1 | /* 2 | * libjingle 3 | * Copyright 2007, Google Inc. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions are met: 7 | * 8 | * 1. Redistributions of source code must retain the above copyright notice, 9 | * this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright notice, 11 | * this list of conditions and the following disclaimer in the documentation 12 | * and/or other materials provided with the distribution. 13 | * 3. The name of the author may not be used to endorse or promote products 14 | * derived from this software without specific prior written permission. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED 17 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 18 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO 19 | * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 20 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 21 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 22 | * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 23 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 24 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 25 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | */ 27 | 28 | #ifndef _TXMPP_PROXYDETECT_H_ 29 | #define _TXMPP_PROXYDETECT_H_ 30 | 31 | #ifndef NO_CONFIG_H 32 | #include "config.h" 33 | #endif 34 | 35 | #include "proxyinfo.h" 36 | 37 | namespace txmpp { 38 | // Auto-detect the proxy server. Returns true if a proxy is configured, 39 | // although hostname may be empty if the proxy is not required for 40 | // the given URL. 41 | 42 | bool GetProxySettingsForUrl(const char* agent, const char* url, 43 | txmpp::ProxyInfo& proxy, 44 | bool long_operation = false); 45 | 46 | } // namespace txmpp 47 | 48 | #endif // _TXMPP_PROXYDETECT_H_ 49 | -------------------------------------------------------------------------------- /src/stringdigest.h: -------------------------------------------------------------------------------- 1 | /* 2 | * libjingle 3 | * Copyright 2004--2005, Google Inc. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions are met: 7 | * 8 | * 1. Redistributions of source code must retain the above copyright notice, 9 | * this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright notice, 11 | * this list of conditions and the following disclaimer in the documentation 12 | * and/or other materials provided with the distribution. 13 | * 3. The name of the author may not be used to endorse or promote products 14 | * derived from this software without specific prior written permission. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED 17 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 18 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO 19 | * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 20 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 21 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 22 | * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 23 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 24 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 25 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | */ 27 | 28 | #ifndef _TXMPP_STRINGDIGEST_H_ 29 | #define _TXMPP_STRINGDIGEST_H_ 30 | 31 | #ifndef NO_CONFIG_H 32 | #include "config.h" 33 | #endif 34 | 35 | #include 36 | 37 | namespace txmpp { 38 | 39 | ////////////////////////////////////////////////////////////////////// 40 | // Message Digest Utilities 41 | ////////////////////////////////////////////////////////////////////// 42 | 43 | // Compute the MD5 message digest of data, and return it in 44 | std::string MD5(const std::string& data); 45 | 46 | ////////////////////////////////////////////////////////////////////// 47 | 48 | } // namespace txmpp 49 | 50 | #endif // _TXMPP_STRINGDIGEST_H__ 51 | -------------------------------------------------------------------------------- /src/stringdigest.cc: -------------------------------------------------------------------------------- 1 | /* 2 | * libjingle 3 | * Copyright 2004--2005, Google Inc. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions are met: 7 | * 8 | * 1. Redistributions of source code must retain the above copyright notice, 9 | * this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright notice, 11 | * this list of conditions and the following disclaimer in the documentation 12 | * and/or other materials provided with the distribution. 13 | * 3. The name of the author may not be used to endorse or promote products 14 | * derived from this software without specific prior written permission. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED 17 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 18 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO 19 | * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 20 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 21 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 22 | * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 23 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 24 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 25 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | */ 27 | 28 | 29 | #include "stringdigest.h" 30 | 31 | #include "md5.h" 32 | #include "stringencode.h" 33 | 34 | namespace txmpp { 35 | 36 | std::string MD5(const std::string& data) { 37 | MD5_CTX ctx; 38 | MD5Init(&ctx); 39 | MD5Update(&ctx, const_cast(reinterpret_cast(data.data())), static_cast(data.size())); 40 | unsigned char digest[16]; 41 | MD5Final(digest, &ctx); 42 | std::string hex_digest; 43 | for (int i=0; i<16; ++i) { 44 | hex_digest += hex_encode(digest[i] >> 4); 45 | hex_digest += hex_encode(digest[i] & 0xf); 46 | } 47 | return hex_digest; 48 | } 49 | 50 | } // namespace txmpp 51 | -------------------------------------------------------------------------------- /src/socketfactory.h: -------------------------------------------------------------------------------- 1 | /* 2 | * libjingle 3 | * Copyright 2004--2005, Google Inc. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions are met: 7 | * 8 | * 1. Redistributions of source code must retain the above copyright notice, 9 | * this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright notice, 11 | * this list of conditions and the following disclaimer in the documentation 12 | * and/or other materials provided with the distribution. 13 | * 3. The name of the author may not be used to endorse or promote products 14 | * derived from this software without specific prior written permission. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED 17 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 18 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO 19 | * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 20 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 21 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 22 | * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 23 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 24 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 25 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | */ 27 | 28 | #ifndef _TXMPP_SOCKETFACTORY_H__ 29 | #define _TXMPP_SOCKETFACTORY_H__ 30 | 31 | #ifndef NO_CONFIG_H 32 | #include "config.h" 33 | #endif 34 | 35 | #include "socket.h" 36 | #include "asyncsocket.h" 37 | 38 | namespace txmpp { 39 | 40 | class SocketFactory { 41 | public: 42 | virtual ~SocketFactory() {} 43 | 44 | // Returns a new socket for blocking communication. The type can be 45 | // SOCK_DGRAM and SOCK_STREAM. 46 | virtual Socket* CreateSocket(int type) = 0; 47 | 48 | // Returns a new socket for nonblocking communication. The type can be 49 | // SOCK_DGRAM and SOCK_STREAM. 50 | virtual AsyncSocket* CreateAsyncSocket(int type) = 0; 51 | }; 52 | 53 | } // namespace txmpp 54 | 55 | #endif // _TXMPP_SOCKETFACTORY_H__ 56 | -------------------------------------------------------------------------------- /src/proxyinfo.h: -------------------------------------------------------------------------------- 1 | /* 2 | * libjingle 3 | * Copyright 2004--2005, Google Inc. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions are met: 7 | * 8 | * 1. Redistributions of source code must retain the above copyright notice, 9 | * this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright notice, 11 | * this list of conditions and the following disclaimer in the documentation 12 | * and/or other materials provided with the distribution. 13 | * 3. The name of the author may not be used to endorse or promote products 14 | * derived from this software without specific prior written permission. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED 17 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 18 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO 19 | * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 20 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 21 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 22 | * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 23 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 24 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 25 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | */ 27 | 28 | #ifndef _TXMPP_PROXYINFO_H_ 29 | #define _TXMPP_PROXYINFO_H_ 30 | 31 | #ifndef NO_CONFIG_H 32 | #include "config.h" 33 | #endif 34 | 35 | #include 36 | #include "socketaddress.h" 37 | #include "cryptstring.h" 38 | 39 | namespace txmpp { 40 | 41 | enum ProxyType { 42 | PROXY_NONE, 43 | PROXY_HTTPS, 44 | PROXY_SOCKS5, 45 | PROXY_UNKNOWN 46 | }; 47 | const char * ProxyToString(ProxyType proxy); 48 | 49 | struct ProxyInfo { 50 | ProxyType type; 51 | SocketAddress address; 52 | std::string autoconfig_url; 53 | bool autodetect; 54 | std::string bypass_list; 55 | std::string username; 56 | CryptString password; 57 | 58 | ProxyInfo() : type(PROXY_NONE), autodetect(false) { } 59 | }; 60 | 61 | } // namespace txmpp 62 | 63 | #endif // _TXMPP_PROXYINFO_H__ 64 | -------------------------------------------------------------------------------- /src/examples/hello/xmppthread.h: -------------------------------------------------------------------------------- 1 | /* 2 | * libjingle 3 | * Copyright 2004--2005, Google Inc. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions are met: 7 | * 8 | * 1. Redistributions of source code must retain the above copyright notice, 9 | * this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright notice, 11 | * this list of conditions and the following disclaimer in the documentation 12 | * and/or other materials provided with the distribution. 13 | * 3. The name of the author may not be used to endorse or promote products 14 | * derived from this software without specific prior written permission. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED 17 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 18 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO 19 | * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 20 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 21 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 22 | * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 23 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 24 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 25 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | */ 27 | 28 | #ifndef _HELLO_XMPPTHREAD_H_ 29 | #define _HELLO_XMPPTHREAD_H_ 30 | 31 | #include "../../thread.h" 32 | #include "../../xmppclientsettings.h" 33 | #include "xmpppump.h" 34 | 35 | namespace hello { 36 | 37 | class XmppThread: public txmpp::Thread, XmppPumpNotify, txmpp::MessageHandler { 38 | public: 39 | XmppThread(); 40 | ~XmppThread(); 41 | 42 | txmpp::XmppClient* client() { return pump_->client(); } 43 | 44 | void ProcessMessages(int cms); 45 | void Login(const txmpp::XmppClientSettings & xcs); 46 | void Disconnect(); 47 | 48 | private: 49 | XmppPump* pump_; 50 | 51 | void OnStateChange(txmpp::XmppEngine::State state); 52 | void OnMessage(txmpp::Message* pmsg); 53 | }; 54 | 55 | } // namespace hello 56 | 57 | #endif // _HELLO_XMPPTHREAD_H_ 58 | -------------------------------------------------------------------------------- /src/helpers.h: -------------------------------------------------------------------------------- 1 | /* 2 | * libjingle 3 | * Copyright 2004--2005, Google Inc. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions are met: 7 | * 8 | * 1. Redistributions of source code must retain the above copyright notice, 9 | * this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright notice, 11 | * this list of conditions and the following disclaimer in the documentation 12 | * and/or other materials provided with the distribution. 13 | * 3. The name of the author may not be used to endorse or promote products 14 | * derived from this software without specific prior written permission. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED 17 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 18 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO 19 | * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 20 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 21 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 22 | * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 23 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 24 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 25 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | */ 27 | 28 | #ifndef _TXMPP_HELPERS_H_ 29 | #define _TXMPP_HELPERS_H_ 30 | 31 | #ifndef NO_CONFIG_H 32 | #include "config.h" 33 | #endif 34 | 35 | #include 36 | #include "basictypes.h" 37 | 38 | namespace txmpp { 39 | 40 | // For testing, we can return predictable data. 41 | void SetRandomTestMode(bool test); 42 | 43 | // Initializes the RNG, and seeds it with the specified entropy. 44 | bool InitRandom(int seed); 45 | bool InitRandom(const char* seed, size_t len); 46 | 47 | // Generates a (cryptographically) random string of the given length. 48 | // We generate base64 values so that they will be printable. 49 | std::string CreateRandomString(size_t length); 50 | 51 | // Generates a random id. 52 | uint32 CreateRandomId(); 53 | 54 | // Generates a random id > 0. 55 | uint32 CreateRandomNonZeroId(); 56 | 57 | } // namespace txmpp 58 | 59 | #endif // _TXMPP_HELPERS_H_ 60 | -------------------------------------------------------------------------------- /src/asyncfile.h: -------------------------------------------------------------------------------- 1 | /* 2 | * libjingle 3 | * Copyright 2004--2005, Google Inc. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions are met: 7 | * 8 | * 1. Redistributions of source code must retain the above copyright notice, 9 | * this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright notice, 11 | * this list of conditions and the following disclaimer in the documentation 12 | * and/or other materials provided with the distribution. 13 | * 3. The name of the author may not be used to endorse or promote products 14 | * derived from this software without specific prior written permission. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED 17 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 18 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO 19 | * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 20 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 21 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 22 | * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 23 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 24 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 25 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | */ 27 | 28 | #ifndef TXMPP_ASYNCFILE_H_ 29 | #define TXMPP_ASYNCFILE_H_ 30 | 31 | #ifndef NO_CONFIG_H 32 | #include "config.h" 33 | #endif 34 | 35 | #include "sigslot.h" 36 | 37 | namespace txmpp { 38 | 39 | // Provides the ability to perform file I/O asynchronously. 40 | // TODO: Create a common base class with AsyncSocket. 41 | class AsyncFile { 42 | public: 43 | virtual ~AsyncFile() {} 44 | 45 | // Determines whether the file will receive read events. 46 | virtual bool readable() = 0; 47 | virtual void set_readable(bool value) = 0; 48 | 49 | // Determines whether the file will receive write events. 50 | virtual bool writable() = 0; 51 | virtual void set_writable(bool value) = 0; 52 | 53 | signal1 SignalReadEvent; 54 | signal1 SignalWriteEvent; 55 | signal2 SignalCloseEvent; 56 | }; 57 | 58 | } // namespace txmpp 59 | 60 | #endif // TXMPP_ASYNCFILE_H_ 61 | -------------------------------------------------------------------------------- /src/win32socketinit.cc: -------------------------------------------------------------------------------- 1 | /* 2 | * libjingle 3 | * Copyright 2009, Google Inc. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions are met: 7 | * 8 | * 1. Redistributions of source code must retain the above copyright notice, 9 | * this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright notice, 11 | * this list of conditions and the following disclaimer in the documentation 12 | * and/or other materials provided with the distribution. 13 | * 3. The name of the author may not be used to endorse or promote products 14 | * derived from this software without specific prior written permission. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED 17 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 18 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO 19 | * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 20 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 21 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 22 | * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 23 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 24 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 25 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | */ 27 | 28 | #include "win32socketinit.h" 29 | 30 | #include "win32.h" 31 | 32 | namespace txmpp { 33 | 34 | // Please don't remove this function. 35 | void EnsureWinsockInit() { 36 | // The default implementation uses a global initializer, so WSAStartup 37 | // happens at module load time. Thus we don't need to do anything here. 38 | // The hook is provided so that a client that statically links with 39 | // libjingle can override it, to provide its own initialization. 40 | } 41 | 42 | #ifdef WIN32 43 | class WinsockInitializer { 44 | public: 45 | WinsockInitializer() { 46 | WSADATA wsaData; 47 | WORD wVersionRequested = MAKEWORD(1, 0); 48 | err_ = WSAStartup(wVersionRequested, &wsaData); 49 | } 50 | ~WinsockInitializer() { 51 | if (!err_) 52 | WSACleanup(); 53 | } 54 | int error() { 55 | return err_; 56 | } 57 | private: 58 | int err_; 59 | }; 60 | WinsockInitializer g_winsockinit; 61 | #endif 62 | 63 | } // namespace txmpp 64 | -------------------------------------------------------------------------------- /src/saslhandler.h: -------------------------------------------------------------------------------- 1 | /* 2 | * libjingle 3 | * Copyright 2004--2005, Google Inc. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions are met: 7 | * 8 | * 1. Redistributions of source code must retain the above copyright notice, 9 | * this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright notice, 11 | * this list of conditions and the following disclaimer in the documentation 12 | * and/or other materials provided with the distribution. 13 | * 3. The name of the author may not be used to endorse or promote products 14 | * derived from this software without specific prior written permission. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED 17 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 18 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO 19 | * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 20 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 21 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 22 | * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 23 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 24 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 25 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | */ 27 | 28 | #ifndef _TXMPP_SASLHANDLER_H_ 29 | #define _TXMPP_SASLHANDLER_H_ 30 | 31 | #ifndef NO_CONFIG_H 32 | #include "config.h" 33 | #endif 34 | 35 | #include 36 | #include 37 | 38 | namespace txmpp { 39 | 40 | class XmlElement; 41 | class SaslMechanism; 42 | 43 | // Creates mechanisms to deal with a given mechanism 44 | class SaslHandler { 45 | 46 | public: 47 | 48 | // Intended to be subclassed 49 | virtual ~SaslHandler() {} 50 | 51 | // Should pick the best method according to this handler 52 | // returns the empty string if none are suitable 53 | virtual std::string ChooseBestSaslMechanism(const std::vector & mechanisms, bool encrypted) = 0; 54 | 55 | // Creates a SaslMechanism for the given mechanism name (you own it 56 | // once you get it). 57 | // If not handled, return NULL. 58 | virtual SaslMechanism * CreateSaslMechanism(const std::string & mechanism) = 0; 59 | }; 60 | 61 | } // namespace txmpp 62 | 63 | #endif // _TXMPP_SASLHANDLER_H_ 64 | -------------------------------------------------------------------------------- /src/event.h: -------------------------------------------------------------------------------- 1 | /* 2 | * libjingle 3 | * Copyright 2004--2008, Google Inc. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions are met: 7 | * 8 | * 1. Redistributions of source code must retain the above copyright notice, 9 | * this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright notice, 11 | * this list of conditions and the following disclaimer in the documentation 12 | * and/or other materials provided with the distribution. 13 | * 3. The name of the author may not be used to endorse or promote products 14 | * derived from this software without specific prior written permission. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED 17 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 18 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO 19 | * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 20 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 21 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 22 | * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 23 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 24 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 25 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | */ 27 | 28 | #ifndef _TXMPP_EVENT_H_ 29 | #define _TXMPP_EVENT_H_ 30 | 31 | #ifndef NO_CONFIG_H 32 | #include "config.h" 33 | #endif 34 | 35 | #if defined(WIN32) 36 | #include "win32.h" // NOLINT: consider this a system header. 37 | #elif defined(POSIX) 38 | #include 39 | #else 40 | #error "Must define either WIN32 or POSIX." 41 | #endif 42 | 43 | #include "basictypes.h" 44 | 45 | namespace txmpp { 46 | 47 | class Event { 48 | public: 49 | Event(bool manual_reset, bool initially_signaled); 50 | ~Event(); 51 | 52 | bool Set(); 53 | bool Reset(); 54 | bool Wait(int cms); 55 | 56 | private: 57 | bool EnsureInitialized(); 58 | 59 | bool is_manual_reset_; 60 | 61 | #if defined(WIN32) 62 | bool is_initially_signaled_; 63 | HANDLE event_handle_; 64 | #elif defined(POSIX) 65 | bool event_status_; 66 | bool event_mutex_initialized_; 67 | pthread_mutex_t event_mutex_; 68 | bool event_cond_initialized_; 69 | pthread_cond_t event_cond_; 70 | #endif 71 | }; 72 | 73 | } // namespace txmpp 74 | 75 | #endif // _TXMPP_EVENT_H_ 76 | -------------------------------------------------------------------------------- /src/saslmechanism.cc: -------------------------------------------------------------------------------- 1 | /* 2 | * libjingle 3 | * Copyright 2004--2005, Google Inc. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions are met: 7 | * 8 | * 1. Redistributions of source code must retain the above copyright notice, 9 | * this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright notice, 11 | * this list of conditions and the following disclaimer in the documentation 12 | * and/or other materials provided with the distribution. 13 | * 3. The name of the author may not be used to endorse or promote products 14 | * derived from this software without specific prior written permission. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED 17 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 18 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO 19 | * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 20 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 21 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 22 | * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 23 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 24 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 25 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | */ 27 | 28 | #include "saslmechanism.h" 29 | 30 | #include "base64.h" 31 | #include "constants.h" 32 | #include "xmlelement.h" 33 | 34 | namespace txmpp { 35 | 36 | XmlElement * 37 | SaslMechanism::StartSaslAuth() { 38 | return new XmlElement(QN_SASL_AUTH, true); 39 | } 40 | 41 | XmlElement * 42 | SaslMechanism::HandleSaslChallenge(const XmlElement * challenge) { 43 | return new XmlElement(QN_SASL_ABORT, true); 44 | } 45 | 46 | void 47 | SaslMechanism::HandleSaslSuccess(const XmlElement * success) { 48 | } 49 | 50 | void 51 | SaslMechanism::HandleSaslFailure(const XmlElement * failure) { 52 | } 53 | 54 | std::string 55 | SaslMechanism::Base64Encode(const std::string & plain) { 56 | return Base64::Encode(plain); 57 | } 58 | 59 | std::string 60 | SaslMechanism::Base64Decode(const std::string & encoded) { 61 | return Base64::Decode(encoded, Base64::DO_LAX); 62 | } 63 | 64 | std::string 65 | SaslMechanism::Base64EncodeFromArray(const char * plain, size_t length) { 66 | std::string result; 67 | Base64::EncodeFromArray(plain, length, &result); 68 | return result; 69 | } 70 | 71 | } // namespace txmpp 72 | -------------------------------------------------------------------------------- /src/xmlconstants.cc: -------------------------------------------------------------------------------- 1 | /* 2 | * libjingle 3 | * Copyright 2004--2005, Google Inc. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions are met: 7 | * 8 | * 1. Redistributions of source code must retain the above copyright notice, 9 | * this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright notice, 11 | * this list of conditions and the following disclaimer in the documentation 12 | * and/or other materials provided with the distribution. 13 | * 3. The name of the author may not be used to endorse or promote products 14 | * derived from this software without specific prior written permission. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED 17 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 18 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO 19 | * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 20 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 21 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 22 | * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 23 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 24 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 25 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | */ 27 | 28 | #include "xmlconstants.h" 29 | 30 | namespace txmpp { 31 | 32 | const std::string & XmlConstants::str_empty() { 33 | static const std::string str_empty_; 34 | return str_empty_; 35 | } 36 | 37 | const std::string & XmlConstants::ns_xml() { 38 | static const std::string ns_xml_("http://www.w3.org/XML/1998/namespace"); 39 | return ns_xml_; 40 | } 41 | 42 | const std::string & XmlConstants::ns_xmlns() { 43 | static const std::string ns_xmlns_("http://www.w3.org/2000/xmlns/"); 44 | return ns_xmlns_; 45 | } 46 | 47 | const std::string & XmlConstants::str_xmlns() { 48 | static const std::string str_xmlns_("xmlns"); 49 | return str_xmlns_; 50 | } 51 | 52 | const std::string & XmlConstants::str_xml() { 53 | static const std::string str_xml_("xml"); 54 | return str_xml_; 55 | } 56 | 57 | const std::string & XmlConstants::str_version() { 58 | static const std::string str_version_("version"); 59 | return str_version_; 60 | } 61 | 62 | const std::string & XmlConstants::str_encoding() { 63 | static const std::string str_encoding_("encoding"); 64 | return str_encoding_; 65 | } 66 | 67 | } 68 | -------------------------------------------------------------------------------- /src/xmlnsstack.h: -------------------------------------------------------------------------------- 1 | /* 2 | * libjingle 3 | * Copyright 2004--2005, Google Inc. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions are met: 7 | * 8 | * 1. Redistributions of source code must retain the above copyright notice, 9 | * this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright notice, 11 | * this list of conditions and the following disclaimer in the documentation 12 | * and/or other materials provided with the distribution. 13 | * 3. The name of the author may not be used to endorse or promote products 14 | * derived from this software without specific prior written permission. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED 17 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 18 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO 19 | * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 20 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 21 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 22 | * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 23 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 24 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 25 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | */ 27 | 28 | #ifndef _TXMPP_XMLNSSTACK_H_ 29 | #define _TXMPP_XMLNSSTACK_H_ 30 | 31 | #ifndef NO_CONFIG_H 32 | #include "config.h" 33 | #endif 34 | 35 | #include 36 | #include 37 | #include "scoped_ptr.h" 38 | #include "qname.h" 39 | 40 | namespace txmpp { 41 | 42 | class XmlnsStack { 43 | public: 44 | XmlnsStack(); 45 | ~XmlnsStack(); 46 | 47 | void AddXmlns(const std::string & prefix, const std::string & ns); 48 | void RemoveXmlns(); 49 | void PushFrame(); 50 | void PopFrame(); 51 | void Reset(); 52 | 53 | const std::string * NsForPrefix(const std::string & prefix); 54 | bool PrefixMatchesNs(const std::string & prefix, const std::string & ns); 55 | std::pair PrefixForNs(const std::string & ns, bool isAttr); 56 | std::pair AddNewPrefix(const std::string & ns, bool isAttr); 57 | std::string FormatQName(const QName & name, bool isAttr); 58 | 59 | private: 60 | 61 | scoped_ptr > pxmlnsStack_; 62 | scoped_ptr > pxmlnsDepthStack_; 63 | }; 64 | 65 | } // namespace txmpp 66 | 67 | #endif // _TXMPP_XMLNSSTACK_H_ 68 | -------------------------------------------------------------------------------- /src/macutils.h: -------------------------------------------------------------------------------- 1 | /* 2 | * libjingle 3 | * Copyright 2007--2009, Google Inc. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions are met: 7 | * 8 | * 1. Redistributions of source code must retain the above copyright notice, 9 | * this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright notice, 11 | * this list of conditions and the following disclaimer in the documentation 12 | * and/or other materials provided with the distribution. 13 | * 3. The name of the author may not be used to endorse or promote products 14 | * derived from this software without specific prior written permission. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED 17 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 18 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO 19 | * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 20 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 21 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 22 | * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 23 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 24 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 25 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | */ 27 | 28 | #ifndef _TXMPP_MACUTILS_H_ 29 | #define _TXMPP_MACUTILS_H_ 30 | 31 | #ifndef NO_CONFIG_H 32 | #include "config.h" 33 | #endif 34 | 35 | #include 36 | #include 37 | #include 38 | 39 | namespace txmpp { 40 | 41 | /////////////////////////////////////////////////////////////////////////////// 42 | 43 | bool ToUtf8(const CFStringRef str16, std::string* str8); 44 | bool ToUtf16(const std::string& str8, CFStringRef* str16); 45 | 46 | void DecodeFourChar(UInt32 fc, std::string* out); 47 | std::string DecodeEvent(EventRef event); 48 | 49 | enum MacOSVersionName { 50 | kMacOSUnknown, // ??? 51 | kMacOSOlder, // 10.2- 52 | kMacOSPanther, // 10.3 53 | kMacOSTiger, // 10.4 54 | kMacOSLeopard, // 10.5 55 | kMacOSNewer, // 10.6+ 56 | }; 57 | 58 | bool GetOSVersion(int* major, int* minor, int* bugfix); 59 | MacOSVersionName GetOSVersionName(); 60 | bool GetQuickTimeVersion(std::string* version); 61 | 62 | /////////////////////////////////////////////////////////////////////////////// 63 | 64 | } // namespace txmpp 65 | 66 | #endif // _TXMPP_MACUTILS_H__ 67 | -------------------------------------------------------------------------------- /src/common.cc: -------------------------------------------------------------------------------- 1 | /* 2 | * libjingle 3 | * Copyright 2004--2005, Google Inc. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions are met: 7 | * 8 | * 1. Redistributions of source code must retain the above copyright notice, 9 | * this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright notice, 11 | * this list of conditions and the following disclaimer in the documentation 12 | * and/or other materials provided with the distribution. 13 | * 3. The name of the author may not be used to endorse or promote products 14 | * derived from this software without specific prior written permission. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED 17 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 18 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO 19 | * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 20 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 21 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 22 | * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 23 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 24 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 25 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | */ 27 | 28 | #include "common.h" 29 | 30 | #include 31 | #include 32 | #include 33 | 34 | #if WIN32 35 | #define WIN32_LEAN_AND_MEAN 36 | #include 37 | #endif // WIN32 38 | 39 | #if OSX 40 | #include 41 | #endif // OSX 42 | 43 | #include 44 | #include "logging.h" 45 | 46 | ////////////////////////////////////////////////////////////////////// 47 | // Assertions 48 | ////////////////////////////////////////////////////////////////////// 49 | 50 | namespace txmpp { 51 | 52 | void Break() { 53 | #if WIN32 54 | ::DebugBreak(); 55 | #elif OSX // !WIN32 56 | ::Debugger(); 57 | #else // !OSX && !WIN32 58 | #if _DEBUG_HAVE_BACKTRACE 59 | OutputTrace(); 60 | #endif 61 | abort(); 62 | #endif // !OSX && !WIN32 63 | } 64 | 65 | void LogAssert(const char * function, const char * file, int line, 66 | const char * expression) { 67 | // TODO - if we put hooks in here, we can do a lot fancier logging 68 | LOG(LS_ERROR) << file << "(" << line << ")" << ": ASSERT FAILED: " 69 | << expression << " @ " << function; 70 | } 71 | 72 | } // namespace txmpp 73 | -------------------------------------------------------------------------------- /src/examples/hello/xmpptasks.h: -------------------------------------------------------------------------------- 1 | /* 2 | * txmpp 3 | * Copyright 2010, Silas Sewell 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions are met: 7 | * 8 | * 1. Redistributions of source code must retain the above copyright notice, 9 | * this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright notice, 11 | * this list of conditions and the following disclaimer in the documentation 12 | * and/or other materials provided with the distribution. 13 | * 3. The name of the author may not be used to endorse or promote products 14 | * derived from this software without specific prior written permission. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED 17 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 18 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO 19 | * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 20 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 21 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 22 | * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 23 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 24 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 25 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | */ 27 | 28 | #ifndef _HELLO_XMPPTASKS_H_ 29 | #define _HELLO_XMPPTASKS_H_ 30 | 31 | #include "../../taskparent.h" 32 | #include "../../xmpptask.h" 33 | 34 | namespace hello { 35 | 36 | class XmppTaskMessage : public txmpp::XmppTask { 37 | public: 38 | explicit XmppTaskMessage(txmpp::TaskParent *parent); 39 | virtual ~XmppTaskMessage(); 40 | virtual int ProcessStart(); 41 | virtual int ProcessResponse(); 42 | bool HandleStanza(const txmpp::XmlElement *stanza); 43 | }; 44 | 45 | class XmppTaskPresence : public txmpp::XmppTask { 46 | public: 47 | explicit XmppTaskPresence(txmpp::TaskParent *parent); 48 | virtual ~XmppTaskPresence(); 49 | virtual int ProcessStart(); 50 | virtual int ProcessResponse(); 51 | bool HandleStanza(const txmpp::XmlElement *stanza); 52 | }; 53 | 54 | class XmppTaskIq : public txmpp::XmppTask { 55 | public: 56 | explicit XmppTaskIq(txmpp::TaskParent *parent); 57 | virtual ~XmppTaskIq(); 58 | virtual int ProcessStart(); 59 | virtual int ProcessResponse(); 60 | bool HandleStanza(const txmpp::XmlElement *stanza); 61 | }; 62 | 63 | } // namespace hello 64 | 65 | #endif // _HELLO_XMPPTASK_H_ 66 | -------------------------------------------------------------------------------- /src/sslidentity.cc: -------------------------------------------------------------------------------- 1 | /* 2 | * libjingle 3 | * Copyright 2004--2008, Google Inc. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions are met: 7 | * 8 | * 1. Redistributions of source code must retain the above copyright notice, 9 | * this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright notice, 11 | * this list of conditions and the following disclaimer in the documentation 12 | * and/or other materials provided with the distribution. 13 | * 3. The name of the author may not be used to endorse or promote products 14 | * derived from this software without specific prior written permission. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED 17 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 18 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO 19 | * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 20 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 21 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 22 | * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 23 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 24 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 25 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | */ 27 | 28 | // Handling of certificates and keypairs for SSLStreamAdapter's peer mode. 29 | 30 | #include "sslidentity.h" 31 | 32 | #include 33 | 34 | // Decide which (if any) implementation of SSL we will use. 35 | #if !defined(SSL_USE_SCHANNEL) && !defined(SSL_USE_OPENSSL) 36 | #ifdef WIN32 37 | #define SSL_USE_SCHANNEL 1 38 | #else // !WIN32 39 | #define SSL_USE_OPENSSL HAVE_OPENSSL_SSL_H 40 | #endif // !WIN32 41 | #endif 42 | 43 | #if SSL_USE_SCHANNEL 44 | 45 | #error "Not implemented yet" 46 | 47 | #elif SSL_USE_OPENSSL // && !SSL_USE_SCHANNEL 48 | 49 | #include "opensslidentity.h" 50 | 51 | namespace txmpp { 52 | 53 | SSLCertificate* SSLCertificate::FromPEMString(const std::string& pem_string, 54 | int* pem_length) { 55 | return OpenSSLCertificate::FromPEMString(pem_string, pem_length); 56 | } 57 | 58 | SSLIdentity* SSLIdentity::Generate(const std::string& common_name) { 59 | return OpenSSLIdentity::Generate(common_name); 60 | } 61 | 62 | } // namespace txmpp 63 | 64 | #else // !SSL_USE_OPENSSL && !SSL_USE_SCHANNEL 65 | 66 | #error "No SSL implementation" 67 | 68 | #endif // SSL_USE_OPENSSL/!SSL_USE_SCHANNEL 69 | -------------------------------------------------------------------------------- /src/saslplainmechanism.h: -------------------------------------------------------------------------------- 1 | /* 2 | * libjingle 3 | * Copyright 2004--2005, Google Inc. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions are met: 7 | * 8 | * 1. Redistributions of source code must retain the above copyright notice, 9 | * this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright notice, 11 | * this list of conditions and the following disclaimer in the documentation 12 | * and/or other materials provided with the distribution. 13 | * 3. The name of the author may not be used to endorse or promote products 14 | * derived from this software without specific prior written permission. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED 17 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 18 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO 19 | * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 20 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 21 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 22 | * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 23 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 24 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 25 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | */ 27 | 28 | #ifndef _TXMPP_SASLPLAINMECHANISM_H_ 29 | #define _TXMPP_SASLPLAINMECHANISM_H_ 30 | 31 | #ifndef NO_CONFIG_H 32 | #include "config.h" 33 | #endif 34 | 35 | #include "cryptstring.h" 36 | #include "saslmechanism.h" 37 | 38 | namespace txmpp { 39 | 40 | class SaslPlainMechanism : public SaslMechanism { 41 | 42 | public: 43 | SaslPlainMechanism(const Jid user_jid, const CryptString & password) : 44 | user_jid_(user_jid), password_(password) {} 45 | 46 | virtual std::string GetMechanismName() { return "PLAIN"; } 47 | 48 | virtual XmlElement * StartSaslAuth() { 49 | // send initial request 50 | XmlElement * el = new XmlElement(QN_SASL_AUTH, true); 51 | el->AddAttr(QN_MECHANISM, "PLAIN"); 52 | 53 | FormatCryptString credential; 54 | credential.Append("\0", 1); 55 | credential.Append(user_jid_.node()); 56 | credential.Append("\0", 1); 57 | credential.Append(&password_); 58 | el->AddText(Base64EncodeFromArray(credential.GetData(), credential.GetLength())); 59 | return el; 60 | } 61 | 62 | private: 63 | Jid user_jid_; 64 | CryptString password_; 65 | }; 66 | 67 | } // namespace txmpp 68 | 69 | #endif // _TXMPP_SASLPLAINMECHANISM_H_ 70 | -------------------------------------------------------------------------------- /src/sslstreamadapter.cc: -------------------------------------------------------------------------------- 1 | /* 2 | * libjingle 3 | * Copyright 2004--2008, Google Inc. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions are met: 7 | * 8 | * 1. Redistributions of source code must retain the above copyright notice, 9 | * this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright notice, 11 | * this list of conditions and the following disclaimer in the documentation 12 | * and/or other materials provided with the distribution. 13 | * 3. The name of the author may not be used to endorse or promote products 14 | * derived from this software without specific prior written permission. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED 17 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 18 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO 19 | * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 20 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 21 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 22 | * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 23 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 24 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 25 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | */ 27 | 28 | #include "sslstreamadapter.h" 29 | 30 | // Decide which (if any) implementation of SSL we will use. 31 | #if !defined(SSL_USE_SCHANNEL) && !defined(SSL_USE_OPENSSL) 32 | #ifdef WIN32 33 | #define SSL_USE_SCHANNEL 1 34 | #else // !WIN32 35 | #define SSL_USE_OPENSSL HAVE_OPENSSL_SSL_H 36 | #endif // !WIN32 37 | #endif 38 | 39 | #if SSL_USE_SCHANNEL 40 | 41 | #error "Not implemented yet" 42 | 43 | #elif SSL_USE_OPENSSL // && !SSL_USE_SCHANNEL 44 | 45 | #include "opensslstreamadapter.h" 46 | 47 | #endif // SSL_USE_OPENSSL && !SSL_USE_SCHANNEL 48 | 49 | /////////////////////////////////////////////////////////////////////////////// 50 | 51 | namespace txmpp { 52 | 53 | SSLStreamAdapter* SSLStreamAdapter::Create(StreamInterface* stream) { 54 | #if SSL_USE_SCHANNEL 55 | // not implemented yet 56 | // return new SChannelStreamAdapter(stream); 57 | #elif SSL_USE_OPENSSL // && !SSL_USE_SCHANNEL 58 | return new OpenSSLStreamAdapter(stream); 59 | #else // !SSL_USE_OPENSSL && !SSL_USE_SCHANNEL 60 | return NULL; 61 | #endif // !SSL_USE_OPENSSL && !SSL_USE_SCHANNEL 62 | } 63 | 64 | /////////////////////////////////////////////////////////////////////////////// 65 | 66 | } // namespace txmpp 67 | -------------------------------------------------------------------------------- /src/constructormagic.h: -------------------------------------------------------------------------------- 1 | /* 2 | * libjingle 3 | * Copyright 2004--2005, Google Inc. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions are met: 7 | * 8 | * 1. Redistributions of source code must retain the above copyright notice, 9 | * this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright notice, 11 | * this list of conditions and the following disclaimer in the documentation 12 | * and/or other materials provided with the distribution. 13 | * 3. The name of the author may not be used to endorse or promote products 14 | * derived from this software without specific prior written permission. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED 17 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 18 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO 19 | * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 20 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 21 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 22 | * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 23 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 24 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 25 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | */ 27 | 28 | #ifndef _TXMPP_CONSTRUCTORMAGIC_H_ 29 | #define _TXMPP_CONSTRUCTORMAGIC_H_ 30 | 31 | #ifndef NO_CONFIG_H 32 | #include "config.h" 33 | #endif 34 | 35 | #define DISALLOW_ASSIGN(TypeName) \ 36 | void operator=(const TypeName&) 37 | 38 | // A macro to disallow the evil copy constructor and operator= functions 39 | // This should be used in the private: declarations for a class 40 | #define DISALLOW_COPY_AND_ASSIGN(TypeName) \ 41 | TypeName(const TypeName&); \ 42 | DISALLOW_ASSIGN(TypeName) 43 | 44 | // Alternative, less-accurate legacy name. 45 | #define DISALLOW_EVIL_CONSTRUCTORS(TypeName) \ 46 | DISALLOW_COPY_AND_ASSIGN(TypeName) 47 | 48 | // A macro to disallow all the implicit constructors, namely the 49 | // default constructor, copy constructor and operator= functions. 50 | // 51 | // This should be used in the private: declarations for a class 52 | // that wants to prevent anyone from instantiating it. This is 53 | // especially useful for classes containing only static methods. 54 | #define DISALLOW_IMPLICIT_CONSTRUCTORS(TypeName) \ 55 | TypeName(); \ 56 | DISALLOW_EVIL_CONSTRUCTORS(TypeName) 57 | 58 | 59 | #endif // _TXMPP_CONSTRUCTORMAGIC_H_ 60 | -------------------------------------------------------------------------------- /src/macconversion.h: -------------------------------------------------------------------------------- 1 | /* 2 | * libjingle 3 | * Copyright 2004--2009, Google Inc. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions are met: 7 | * 8 | * 1. Redistributions of source code must retain the above copyright notice, 9 | * this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright notice, 11 | * this list of conditions and the following disclaimer in the documentation 12 | * and/or other materials provided with the distribution. 13 | * 3. The name of the author may not be used to endorse or promote products 14 | * derived from this software without specific prior written permission. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED 17 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 18 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO 19 | * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 20 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 21 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 22 | * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 23 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 24 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 25 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | */ 27 | 28 | #ifndef _TXMPP_MACCONVERSION_H_ 29 | #define _TXMPP_MACCONVERSION_H_ 30 | 31 | #ifndef NO_CONFIG_H 32 | #include "config.h" 33 | #endif 34 | 35 | #ifdef OSX 36 | 37 | #include 38 | 39 | #include 40 | 41 | // given a CFStringRef, attempt to convert it to a C++ string. 42 | // returns true if it succeeds, false otherwise. 43 | // We can safely assume, given our context, that the string is 44 | // going to be in ASCII, because it will either be an IP address, 45 | // or a domain name, which is guaranteed to be ASCII-representable. 46 | bool p_convertHostCFStringRefToCPPString(const CFStringRef cfstr, 47 | std::string& cppstr); 48 | 49 | // Convert the CFNumber to an integer, putting the integer in the location 50 | // given, and returhing true, if the conversion succeeds. 51 | // If given a NULL or a non-CFNumber, returns false. 52 | // This is pretty aggresive about trying to convert to int. 53 | bool p_convertCFNumberToInt(CFNumberRef cfn, int* i); 54 | 55 | // given a CFNumberRef, determine if it represents a true value. 56 | bool p_isCFNumberTrue(CFNumberRef cfn); 57 | 58 | #endif // OSX 59 | 60 | #endif // _TXMPP_MACCONVERSION_H_ 61 | -------------------------------------------------------------------------------- /src/examples/hello/main.cc: -------------------------------------------------------------------------------- 1 | /* 2 | * libjingle 3 | * Copyright 2004--2005, Google Inc. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions are met: 7 | * 8 | * 1. Redistributions of source code must retain the above copyright notice, 9 | * this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright notice, 11 | * this list of conditions and the following disclaimer in the documentation 12 | * and/or other materials provided with the distribution. 13 | * 3. The name of the author may not be used to endorse or promote products 14 | * derived from this software without specific prior written permission. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED 17 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 18 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO 19 | * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 20 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 21 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 22 | * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 23 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 24 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 25 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | */ 27 | 28 | #include 29 | #include "../../cryptstring.h" 30 | #include "../../logging.h" 31 | #include "../../xmppclientsettings.h" 32 | #include "xmppthread.h" 33 | 34 | int main(int argc, char* argv[]) { 35 | 36 | bool reconnect = true; 37 | 38 | txmpp::LogMessage::LogToDebug(txmpp::LS_SENSITIVE); 39 | 40 | txmpp::InsecureCryptStringImpl password; 41 | password.password() = "test"; 42 | 43 | while (reconnect) { 44 | 45 | // Start xmpp on a different thread 46 | hello::XmppThread thread; 47 | thread.Start(); 48 | 49 | // Create client settings 50 | txmpp::XmppClientSettings xcs; 51 | xcs.set_user("test"); 52 | xcs.set_pass(txmpp::CryptString(password)); 53 | xcs.set_host("example.org"); 54 | xcs.set_resource("resource"); 55 | xcs.set_use_tls(true); 56 | xcs.set_server(txmpp::SocketAddress("example.org", 5222)); 57 | 58 | thread.Login(xcs); 59 | 60 | // Use main thread for console input 61 | std::string line; 62 | while (std::getline(std::cin, line)) { 63 | if (line == "quit") 64 | reconnect = false; 65 | if (line == "continue" || line == "quit") 66 | break; 67 | } 68 | 69 | thread.Disconnect(); 70 | thread.Stop(); 71 | } 72 | 73 | return 0; 74 | } 75 | -------------------------------------------------------------------------------- /src/socketserver.h: -------------------------------------------------------------------------------- 1 | /* 2 | * libjingle 3 | * Copyright 2004--2005, Google Inc. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions are met: 7 | * 8 | * 1. Redistributions of source code must retain the above copyright notice, 9 | * this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright notice, 11 | * this list of conditions and the following disclaimer in the documentation 12 | * and/or other materials provided with the distribution. 13 | * 3. The name of the author may not be used to endorse or promote products 14 | * derived from this software without specific prior written permission. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED 17 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 18 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO 19 | * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 20 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 21 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 22 | * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 23 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 24 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 25 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | */ 27 | 28 | #ifndef _TXMPP_SOCKETSERVER_H_ 29 | #define _TXMPP_SOCKETSERVER_H_ 30 | 31 | #ifndef NO_CONFIG_H 32 | #include "config.h" 33 | #endif 34 | 35 | #include "socketfactory.h" 36 | 37 | namespace txmpp { 38 | 39 | class MessageQueue; 40 | 41 | // Provides the ability to wait for activity on a set of sockets. The Thread 42 | // class provides a nice wrapper on a socket server. 43 | // 44 | // The server is also a socket factory. The sockets it creates will be 45 | // notified of asynchronous I/O from this server's Wait method. 46 | class SocketServer : public SocketFactory { 47 | public: 48 | // When the socket server is installed into a Thread, this function is 49 | // called to allow the socket server to use the thread's message queue for 50 | // any messaging that it might need to perform. 51 | virtual void SetMessageQueue(MessageQueue* queue) {} 52 | 53 | // Sleeps until: 54 | // 1) cms milliseconds have elapsed (unless cms == kForever) 55 | // 2) WakeUp() is called 56 | // While sleeping, I/O is performed if process_io is true. 57 | virtual bool Wait(int cms, bool process_io) = 0; 58 | 59 | // Causes the current wait (if one is in progress) to wake up. 60 | virtual void WakeUp() = 0; 61 | }; 62 | 63 | } // namespace txmpp 64 | 65 | #endif // _TXMPP_SOCKETSERVER_H_ 66 | -------------------------------------------------------------------------------- /src/win32securityerrors.cc: -------------------------------------------------------------------------------- 1 | /* 2 | * libjingle 3 | * Copyright 2004--2005, Google Inc. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions are met: 7 | * 8 | * 1. Redistributions of source code must retain the above copyright notice, 9 | * this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright notice, 11 | * this list of conditions and the following disclaimer in the documentation 12 | * and/or other materials provided with the distribution. 13 | * 3. The name of the author may not be used to endorse or promote products 14 | * derived from this software without specific prior written permission. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED 17 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 18 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO 19 | * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 20 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 21 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 22 | * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 23 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 24 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 25 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | */ 27 | 28 | #include "win32.h" 29 | #include "logging.h" 30 | 31 | namespace txmpp { 32 | 33 | /////////////////////////////////////////////////////////////////////////////// 34 | 35 | extern const ConstantLabel SECURITY_ERRORS[]; 36 | 37 | const ConstantLabel SECURITY_ERRORS[] = { 38 | KLABEL(SEC_I_COMPLETE_AND_CONTINUE), 39 | KLABEL(SEC_I_COMPLETE_NEEDED), 40 | KLABEL(SEC_I_CONTEXT_EXPIRED), 41 | KLABEL(SEC_I_CONTINUE_NEEDED), 42 | KLABEL(SEC_I_INCOMPLETE_CREDENTIALS), 43 | KLABEL(SEC_I_RENEGOTIATE), 44 | KLABEL(SEC_E_CERT_EXPIRED), 45 | KLABEL(SEC_E_INCOMPLETE_MESSAGE), 46 | KLABEL(SEC_E_INSUFFICIENT_MEMORY), 47 | KLABEL(SEC_E_INTERNAL_ERROR), 48 | KLABEL(SEC_E_INVALID_HANDLE), 49 | KLABEL(SEC_E_INVALID_TOKEN), 50 | KLABEL(SEC_E_LOGON_DENIED), 51 | KLABEL(SEC_E_NO_AUTHENTICATING_AUTHORITY), 52 | KLABEL(SEC_E_NO_CREDENTIALS), 53 | KLABEL(SEC_E_NOT_OWNER), 54 | KLABEL(SEC_E_OK), 55 | KLABEL(SEC_E_SECPKG_NOT_FOUND), 56 | KLABEL(SEC_E_TARGET_UNKNOWN), 57 | KLABEL(SEC_E_UNKNOWN_CREDENTIALS), 58 | KLABEL(SEC_E_UNSUPPORTED_FUNCTION), 59 | KLABEL(SEC_E_UNTRUSTED_ROOT), 60 | KLABEL(SEC_E_WRONG_PRINCIPAL), 61 | LASTLABEL 62 | }; 63 | 64 | /////////////////////////////////////////////////////////////////////////////// 65 | 66 | } // namespace txmpp 67 | -------------------------------------------------------------------------------- /src/asyncudpsocket.h: -------------------------------------------------------------------------------- 1 | /* 2 | * libjingle 3 | * Copyright 2004--2005, Google Inc. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions are met: 7 | * 8 | * 1. Redistributions of source code must retain the above copyright notice, 9 | * this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright notice, 11 | * this list of conditions and the following disclaimer in the documentation 12 | * and/or other materials provided with the distribution. 13 | * 3. The name of the author may not be used to endorse or promote products 14 | * derived from this software without specific prior written permission. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED 17 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 18 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO 19 | * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 20 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 21 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 22 | * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 23 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 24 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 25 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | */ 27 | 28 | #ifndef TXMPP_ASYNCUDPSOCKET_H_ 29 | #define TXMPP_ASYNCUDPSOCKET_H_ 30 | 31 | #ifndef NO_CONFIG_H 32 | #include "config.h" 33 | #endif 34 | 35 | #include "asyncpacketsocket.h" 36 | #include "socketfactory.h" 37 | 38 | namespace txmpp { 39 | 40 | // Provides the ability to receive packets asynchronously. Sends are not 41 | // buffered since it is acceptable to drop packets under high load. 42 | class AsyncUDPSocket : public AsyncPacketSocket { 43 | public: 44 | // Creates a new socket for sending asynchronous UDP packets using an 45 | // asynchronous socket from the given factory. 46 | static AsyncUDPSocket* Create(SocketFactory* factory) { 47 | AsyncSocket* sock = factory->CreateAsyncSocket(SOCK_DGRAM); 48 | return (sock) ? new AsyncUDPSocket(sock) : NULL; 49 | } 50 | explicit AsyncUDPSocket(AsyncSocket* socket); 51 | virtual ~AsyncUDPSocket(); 52 | 53 | private: 54 | // Called when the underlying socket is ready to be read from. 55 | void OnReadEvent(AsyncSocket* socket); 56 | 57 | char* buf_; 58 | size_t size_; 59 | }; 60 | 61 | // TODO(juberti): This is now deprecated. Remove it. 62 | inline AsyncUDPSocket* CreateAsyncUDPSocket(SocketFactory* factory) { 63 | return AsyncUDPSocket::Create(factory); 64 | } 65 | 66 | } // namespace txmpp 67 | 68 | #endif // TXMPP_ASYNCUDPSOCKET_H_ 69 | -------------------------------------------------------------------------------- /CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Full-featured Build System Sample 2 | # CMake cross-platform build system recipe 3 | # 2009 Ryan Pavlik 4 | # http://academic.cleardefinition.com/ 5 | # Iowa State University HCI Graduate Program/VRAC 6 | 7 | cmake_minimum_required(VERSION 2.6) 8 | 9 | # Set package properties 10 | project(txmpp) 11 | 12 | set(CPACK_PACKAGE_VENDOR "Ryan Pavlik") 13 | set(CPACK_PACKAGE_VERSION_MAJOR "0") 14 | set(CPACK_PACKAGE_VERSION_MINOR "0") 15 | set(CPACK_PACKAGE_VERSION_PATCH "2") 16 | set(CPACK_PACKAGE_VERSION 17 | "${CPACK_PACKAGE_VERSION_MAJOR}.${CPACK_PACKAGE_VERSION_MINOR}.${CPACK_PACKAGE_VERSION_PATCH}") 18 | set(CPACK_PACKAGE_FILE_NAME "${PROJECT_NAME}-${CPACK_PACKAGE_VERSION}-binary") 19 | set(CPACK_SOURCE_PACKAGE_FILE_NAME "${PROJECT_NAME}-${CPACK_PACKAGE_VERSION}-src") 20 | 21 | ### 22 | # Set up options 23 | ### 24 | 25 | if(CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR) 26 | # Then we are our own project, not embedded 27 | option(INSTALL_TXMPP "Install the TXMPP headers and library." ON) 28 | 29 | option(BUILD_EXAMPLE "Build the example application." ON) 30 | endif() 31 | 32 | ### 33 | # Perform build configuration of dependencies 34 | ### 35 | 36 | set(EXTRA_LIBS) 37 | 38 | # Threading 39 | if(UNIX AND NOT WIN32) 40 | find_package(Threads REQUIRED) 41 | list(APPEND EXTRA_LIBS ${CMAKE_THREAD_LIBS_INIT}) 42 | endif() 43 | 44 | # Expat 45 | find_package(EXPAT REQUIRED) 46 | list(APPEND EXTRA_LIBS ${EXPAT_LIBRARIES}) 47 | include_directories(${EXPAT_INCLUDE_DIRS}) 48 | 49 | # OpenSSL 50 | find_package(OpenSSL) 51 | if(OPENSSL_FOUND) 52 | option(BUILD_WITH_OPENSSL "Build with SSL support using OpenSSL" ON) 53 | if(BUILD_WITH_OPENSSL) 54 | list(APPEND EXTRA_LIBS ${OPENSSL_LIBRARIES}) 55 | include_directories(${OPENSSL_INCLUDE_DIRS}) 56 | set(FEATURE_ENABLE_SSL 1) 57 | set(HAVE_OPENSSL_SSL_H 1) 58 | set(SSL_USE_OPENSSL 1) 59 | set(USE_SSLSTREAM 1) # what does this do? 60 | endif() 61 | endif() 62 | 63 | # Apple Frameworks 64 | if(APPLE) 65 | foreach(framework CoreServices Carbon Security SystemConfiguration) 66 | find_library(MACOSX_${framework} ${framework}) 67 | list(APPEND EXTRA_LIBS ${MACOSX_${framework}}) 68 | endforeach() 69 | endif() 70 | 71 | 72 | # Platform Defines for the configuration file 73 | if(CMAKE_SYSTEM_NAME MATCHES "Linux") 74 | set(LINUX 1) 75 | elseif(APPLE) 76 | set(OSX 1) 77 | endif() 78 | 79 | if(WIN32) 80 | set(WIN32 1) 81 | elseif(UNIX) 82 | set(POSIX 1) 83 | endif() 84 | 85 | if(MSVC) 86 | set(COMPILER_MSVC 1) 87 | endif() 88 | 89 | ### 90 | # Build the project 91 | ### 92 | 93 | # The app is in the "src" subdirectory 94 | add_subdirectory(src) 95 | 96 | ### 97 | # Set packaging options (for CPack) 98 | ### 99 | 100 | # Include the packaging system now that we have it all set up 101 | include(CPack) 102 | 103 | -------------------------------------------------------------------------------- /src/xmlconstants.h: -------------------------------------------------------------------------------- 1 | /* 2 | * libjingle 3 | * Copyright 2004--2005, Google Inc. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions are met: 7 | * 8 | * 1. Redistributions of source code must retain the above copyright notice, 9 | * this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright notice, 11 | * this list of conditions and the following disclaimer in the documentation 12 | * and/or other materials provided with the distribution. 13 | * 3. The name of the author may not be used to endorse or promote products 14 | * derived from this software without specific prior written permission. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED 17 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 18 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO 19 | * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 20 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 21 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 22 | * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 23 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 24 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 25 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | */ 27 | 28 | // Because global constant initialization order is undefined 29 | // globals cannot depend on other objects to be instantiated. 30 | // This class creates string objects within static methods 31 | // such that globals may refer to these constants by the 32 | // accessor function and they are guaranteed to be initialized. 33 | 34 | #ifndef _TXMPP_XMLCONSTANTS_H_ 35 | #define _TXMPP_XMLCONSTANTS_H_ 36 | 37 | #ifndef NO_CONFIG_H 38 | #include "config.h" 39 | #endif 40 | 41 | #include 42 | 43 | #define STR_EMPTY XmlConstants::str_empty() 44 | #define NS_XML XmlConstants::ns_xml() 45 | #define NS_XMLNS XmlConstants::ns_xmlns() 46 | #define STR_XMLNS XmlConstants::str_xmlns() 47 | #define STR_XML XmlConstants::str_xml() 48 | #define STR_VERSION XmlConstants::str_version() 49 | #define STR_ENCODING XmlConstants::str_encoding() 50 | 51 | namespace txmpp { 52 | 53 | class XmlConstants { 54 | public: 55 | static const std::string & str_empty(); 56 | static const std::string & ns_xml(); 57 | static const std::string & ns_xmlns(); 58 | static const std::string & str_xmlns(); 59 | static const std::string & str_xml(); 60 | static const std::string & str_version(); 61 | static const std::string & str_encoding(); 62 | }; 63 | 64 | } // namespace txmpp 65 | 66 | #endif // _TXMPP_XMLCONSTANTS_H_ 67 | -------------------------------------------------------------------------------- /src/examples/hello/xmpppump.h: -------------------------------------------------------------------------------- 1 | /* 2 | * libjingle 3 | * Copyright 2004--2005, Google Inc. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions are met: 7 | * 8 | * 1. Redistributions of source code must retain the above copyright notice, 9 | * this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright notice, 11 | * this list of conditions and the following disclaimer in the documentation 12 | * and/or other materials provided with the distribution. 13 | * 3. The name of the author may not be used to endorse or promote products 14 | * derived from this software without specific prior written permission. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED 17 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 18 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO 19 | * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 20 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 21 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 22 | * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 23 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 24 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 25 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | */ 27 | 28 | #ifndef _HELLO_XMPPPUMP_H_ 29 | #define _HELLO_XMPPPUMP_H_ 30 | 31 | #include "../../messagequeue.h" 32 | #include "../../taskrunner.h" 33 | #include "../../thread.h" 34 | #include "../../time.h" 35 | #include "../../xmppclient.h" 36 | #include "../../xmppengine.h" 37 | #include "../../xmpptask.h" 38 | 39 | namespace hello { 40 | 41 | class XmppPumpNotify { 42 | public: 43 | virtual ~XmppPumpNotify() {} 44 | virtual void OnStateChange(txmpp::XmppEngine::State state) = 0; 45 | }; 46 | 47 | class XmppPump : public txmpp::MessageHandler, public txmpp::TaskRunner { 48 | public: 49 | XmppPump(XmppPumpNotify * notify = NULL); 50 | 51 | txmpp::XmppClient *client() { return client_; } 52 | txmpp::XmppReturnStatus SendStanza(const txmpp::XmlElement *stanza); 53 | int64 CurrentTime(); 54 | 55 | void DoLogin(const txmpp::XmppClientSettings & xcs, 56 | txmpp::XmppAsyncSocket* socket, 57 | txmpp::PreXmppAuth* auth); 58 | void DoDisconnect(); 59 | void WakeTasks(); 60 | 61 | void OnStateChange(txmpp::XmppEngine::State state); 62 | void OnMessage(txmpp::Message *pmsg); 63 | 64 | private: 65 | txmpp::XmppClient *client_; 66 | txmpp::XmppEngine::State state_; 67 | XmppPumpNotify *notify_; 68 | }; 69 | 70 | } // namespace hello 71 | 72 | #endif // _HELLO_XMPPPUMP_H_ 73 | -------------------------------------------------------------------------------- /src/prexmppauthimpl.cc: -------------------------------------------------------------------------------- 1 | /* 2 | * libjingle 3 | * Copyright 2004--2005, Google Inc. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions are met: 7 | * 8 | * 1. Redistributions of source code must retain the above copyright notice, 9 | * this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright notice, 11 | * this list of conditions and the following disclaimer in the documentation 12 | * and/or other materials provided with the distribution. 13 | * 3. The name of the author may not be used to endorse or promote products 14 | * derived from this software without specific prior written permission. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED 17 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 18 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO 19 | * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 20 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 21 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 22 | * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 23 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 24 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 25 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | */ 27 | 28 | #include "prexmppauthimpl.h" 29 | 30 | #include 31 | #include "saslcookiemechanism.h" 32 | #include "saslplainmechanism.h" 33 | 34 | namespace txmpp { 35 | 36 | PreXmppAuthImpl::PreXmppAuthImpl() : done_(false) { 37 | } 38 | 39 | PreXmppAuthImpl::~PreXmppAuthImpl() { 40 | } 41 | 42 | void PreXmppAuthImpl::StartPreXmppAuth(const Jid & jid, 43 | const SocketAddress & server, 44 | const CryptString & pass, 45 | const std::string & auth_cookie) { 46 | jid_ = jid; 47 | passwd_ = pass; 48 | auth_cookie_ = auth_cookie; 49 | done_ = true; 50 | 51 | SignalAuthDone(); 52 | } 53 | 54 | std::string PreXmppAuthImpl::ChooseBestSaslMechanism( 55 | const std::vector & mechanisms, 56 | bool encrypted) { 57 | std::vector::const_iterator it; 58 | 59 | it = std::find(mechanisms.begin(), mechanisms.end(), "PLAIN"); 60 | if (it != mechanisms.end()) { 61 | return "PLAIN"; 62 | } 63 | 64 | return ""; // No good mechanism found 65 | } 66 | 67 | SaslMechanism* PreXmppAuthImpl::CreateSaslMechanism( 68 | const std::string & mechanism) { 69 | if (mechanism == "PLAIN") { 70 | return new SaslPlainMechanism(jid_, passwd_); 71 | } else { 72 | return NULL; 73 | } 74 | } 75 | 76 | } // namespace txmpp 77 | -------------------------------------------------------------------------------- /src/urlencode.h: -------------------------------------------------------------------------------- 1 | /* 2 | * libjingle 3 | * Copyright 2008, Google Inc. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions are met: 7 | * 8 | * 1. Redistributions of source code must retain the above copyright notice, 9 | * this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright notice, 11 | * this list of conditions and the following disclaimer in the documentation 12 | * and/or other materials provided with the distribution. 13 | * 3. The name of the author may not be used to endorse or promote products 14 | * derived from this software without specific prior written permission. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED 17 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 18 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO 19 | * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 20 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 21 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 22 | * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 23 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 24 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 25 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | */ 27 | 28 | #ifndef _TXMPP_URLENCODE_H_ 29 | #define _TXMPP_URLENCODE_H_ 30 | 31 | #ifndef NO_CONFIG_H 32 | #include "config.h" 33 | #endif 34 | 35 | #include 36 | 37 | // Decode all encoded characters. Also decode + as space. 38 | int UrlDecode(const char *source, char *dest); 39 | 40 | // Decode all encoded characters. 41 | int UrlDecodeWithoutEncodingSpaceAsPlus(const char *source, char *dest); 42 | 43 | // Encode all characters except alphas, numbers, and -_.!~*'() 44 | // Also encode space as +. 45 | int UrlEncode(const char *source, char *dest, unsigned max); 46 | 47 | // Encode all characters except alphas, numbers, and -_.!~*'() 48 | int UrlEncodeWithoutEncodingSpaceAsPlus(const char *source, char *dest, 49 | unsigned max); 50 | 51 | // Encode only unsafe chars, including \ "^&`<>[]{} 52 | // Also encode space as %20, instead of + 53 | int UrlEncodeOnlyUnsafeChars(const char *source, char *dest, unsigned max); 54 | 55 | std::string UrlDecodeString(const std::string & encoded); 56 | std::string UrlDecodeStringWithoutEncodingSpaceAsPlus( 57 | const std::string & encoded); 58 | std::string UrlEncodeString(const std::string & decoded); 59 | std::string UrlEncodeStringWithoutEncodingSpaceAsPlus( 60 | const std::string & decoded); 61 | std::string UrlEncodeStringForOnlyUnsafeChars(const std::string & decoded); 62 | 63 | #endif // _TXMPP_URLENCODE_H_ 64 | -------------------------------------------------------------------------------- /src/nethelpers.h: -------------------------------------------------------------------------------- 1 | /* 2 | * libjingle 3 | * Copyright 2008, Google Inc. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions are met: 7 | * 8 | * 1. Redistributions of source code must retain the above copyright notice, 9 | * this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright notice, 11 | * this list of conditions and the following disclaimer in the documentation 12 | * and/or other materials provided with the distribution. 13 | * 3. The name of the author may not be used to endorse or promote products 14 | * derived from this software without specific prior written permission. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED 17 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 18 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO 19 | * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 20 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 21 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 22 | * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 23 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 24 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 25 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | */ 27 | 28 | #ifndef _TXMPP_NETHELPERS_H_ 29 | #define _TXMPP_NETHELPERS_H_ 30 | 31 | #ifndef NO_CONFIG_H 32 | #include "config.h" 33 | #endif 34 | 35 | #ifdef POSIX 36 | #include 37 | #include 38 | #elif WIN32 39 | #include // NOLINT 40 | #endif 41 | 42 | #include 43 | 44 | #include "signalthread.h" 45 | #include "sigslot.h" 46 | #include "socketaddress.h" 47 | 48 | namespace txmpp { 49 | 50 | // AsyncResolver will perform async DNS resolution, signaling the result on 51 | // the inherited SignalWorkDone when the operation completes. 52 | class AsyncResolver : public SignalThread { 53 | public: 54 | AsyncResolver(); 55 | 56 | const SocketAddress& address() const { return addr_; } 57 | void set_address(const SocketAddress& addr) { addr_ = addr; } 58 | int error() const { return error_; } 59 | void set_error(int error) { error_ = error; } 60 | 61 | protected: 62 | ~AsyncResolver(); 63 | virtual void DoWork(); 64 | virtual void OnWorkDone(); 65 | 66 | private: 67 | SocketAddress addr_; 68 | hostent* result_; 69 | int error_; 70 | }; 71 | 72 | // SafeGetHostByName functions allocate and return their result, instead of 73 | // using a static variable like the normal gethostbyname. 74 | // FreeHostEnt frees the memory allocated by SafeGetHostByName. 75 | hostent* SafeGetHostByName(const char* hostname, int* herrno); 76 | void FreeHostEnt(hostent* host); 77 | 78 | } // namespace txmpp 79 | 80 | #endif // _TXMPP_NETHELPERS_H_ 81 | -------------------------------------------------------------------------------- /src/xmlbuilder.h: -------------------------------------------------------------------------------- 1 | /* 2 | * libjingle 3 | * Copyright 2004--2005, Google Inc. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions are met: 7 | * 8 | * 1. Redistributions of source code must retain the above copyright notice, 9 | * this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright notice, 11 | * this list of conditions and the following disclaimer in the documentation 12 | * and/or other materials provided with the distribution. 13 | * 3. The name of the author may not be used to endorse or promote products 14 | * derived from this software without specific prior written permission. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED 17 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 18 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO 19 | * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 20 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 21 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 22 | * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 23 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 24 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 25 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | */ 27 | 28 | #ifndef _TXMPP_XMLBUILDER_H_ 29 | #define _TXMPP_XMLBUILDER_H_ 30 | 31 | #ifndef NO_CONFIG_H 32 | #include "config.h" 33 | #endif 34 | 35 | #include 36 | #include 37 | #include "scoped_ptr.h" 38 | #include "xmlparser.h" 39 | #include 40 | 41 | namespace txmpp { 42 | 43 | class XmlElement; 44 | class XmlParseContext; 45 | 46 | 47 | class XmlBuilder : public XmlParseHandler { 48 | public: 49 | XmlBuilder(); 50 | 51 | static XmlElement * BuildElement(XmlParseContext * pctx, 52 | const char * name, const char ** atts); 53 | virtual void StartElement(XmlParseContext * pctx, 54 | const char * name, const char ** atts); 55 | virtual void EndElement(XmlParseContext * pctx, const char * name); 56 | virtual void CharacterData(XmlParseContext * pctx, 57 | const char * text, int len); 58 | virtual void Error(XmlParseContext * pctx, XML_Error); 59 | virtual ~XmlBuilder(); 60 | 61 | void Reset(); 62 | 63 | // Take ownership of the built element; second call returns NULL 64 | XmlElement * CreateElement(); 65 | 66 | // Peek at the built element without taking ownership 67 | XmlElement * BuiltElement(); 68 | 69 | private: 70 | XmlElement * pelCurrent_; 71 | txmpp::scoped_ptr pelRoot_; 72 | txmpp::scoped_ptr > pvParents_; 73 | }; 74 | 75 | } // namespace txmpp 76 | 77 | #endif // _TXMPP_XMLBUILDER_H_ 78 | -------------------------------------------------------------------------------- /src/winfirewall.h: -------------------------------------------------------------------------------- 1 | /* 2 | * libjingle 3 | * Copyright 2004--2005, Google Inc. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions are met: 7 | * 8 | * 1. Redistributions of source code must retain the above copyright notice, 9 | * this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright notice, 11 | * this list of conditions and the following disclaimer in the documentation 12 | * and/or other materials provided with the distribution. 13 | * 3. The name of the author may not be used to endorse or promote products 14 | * derived from this software without specific prior written permission. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED 17 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 18 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO 19 | * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 20 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 21 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 22 | * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 23 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 24 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 25 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | */ 27 | 28 | #ifndef _TXMPP_WINFIREWALL_H_ 29 | #define _TXMPP_WINFIREWALL_H_ 30 | 31 | #ifndef NO_CONFIG_H 32 | #include "config.h" 33 | #endif 34 | 35 | #ifndef _HRESULT_DEFINED 36 | #define _HRESULT_DEFINED 37 | typedef long HRESULT; // Can't forward declare typedef, but don't need all win 38 | #endif // !_HRESULT_DEFINED 39 | 40 | struct INetFwMgr; 41 | struct INetFwPolicy; 42 | struct INetFwProfile; 43 | 44 | namespace txmpp { 45 | 46 | ////////////////////////////////////////////////////////////////////// 47 | // WinFirewall 48 | ////////////////////////////////////////////////////////////////////// 49 | 50 | class WinFirewall { 51 | public: 52 | WinFirewall(); 53 | ~WinFirewall(); 54 | 55 | bool Initialize(HRESULT* result); 56 | void Shutdown(); 57 | 58 | bool Enabled() const; 59 | bool QueryAuthorized(const char* filename, bool* authorized) const; 60 | bool QueryAuthorizedW(const wchar_t* filename, bool* authorized) const; 61 | 62 | bool AddApplication(const char* filename, const char* friendly_name, 63 | bool authorized, HRESULT* result); 64 | bool AddApplicationW(const wchar_t* filename, const wchar_t* friendly_name, 65 | bool authorized, HRESULT* result); 66 | 67 | private: 68 | INetFwMgr* mgr_; 69 | INetFwPolicy* policy_; 70 | INetFwProfile* profile_; 71 | }; 72 | 73 | ////////////////////////////////////////////////////////////////////// 74 | 75 | } // namespace txmpp 76 | 77 | #endif // _TXMPP_WINFIREWALL_H_ 78 | -------------------------------------------------------------------------------- /src/asyncpacketsocket.h: -------------------------------------------------------------------------------- 1 | /* 2 | * libjingle 3 | * Copyright 2004--2005, Google Inc. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions are met: 7 | * 8 | * 1. Redistributions of source code must retain the above copyright notice, 9 | * this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright notice, 11 | * this list of conditions and the following disclaimer in the documentation 12 | * and/or other materials provided with the distribution. 13 | * 3. The name of the author may not be used to endorse or promote products 14 | * derived from this software without specific prior written permission. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED 17 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 18 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO 19 | * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 20 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 21 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 22 | * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 23 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 24 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 25 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | */ 27 | 28 | #ifndef TXMPP_ASYNCPACKETSOCKET_H_ 29 | #define TXMPP_ASYNCPACKETSOCKET_H_ 30 | 31 | #ifndef NO_CONFIG_H 32 | #include "config.h" 33 | #endif 34 | 35 | #include "asyncsocket.h" 36 | 37 | namespace txmpp { 38 | 39 | // Provides the ability to receive packets asynchronously. Sends are not 40 | // buffered since it is acceptable to drop packets under high load. 41 | class AsyncPacketSocket : public txmpp::has_slots<> { 42 | public: 43 | explicit AsyncPacketSocket(AsyncSocket* socket); 44 | virtual ~AsyncPacketSocket(); 45 | 46 | // Relevant socket methods: 47 | virtual SocketAddress GetLocalAddress() const; 48 | virtual SocketAddress GetRemoteAddress() const; 49 | virtual int Bind(const SocketAddress& addr); 50 | virtual int Connect(const SocketAddress& addr); 51 | virtual int Send(const void *pv, size_t cb); 52 | virtual int SendTo(const void *pv, size_t cb, const SocketAddress& addr); 53 | virtual int Close(); 54 | 55 | virtual Socket::ConnState GetState() const; 56 | virtual int GetOption(Socket::Option opt, int* value); 57 | virtual int SetOption(Socket::Option opt, int value); 58 | virtual int GetError() const; 59 | virtual void SetError(int error); 60 | 61 | // Emitted each time a packet is read. 62 | txmpp::signal4 SignalReadPacket; 64 | 65 | protected: 66 | AsyncSocket* socket_; 67 | DISALLOW_EVIL_CONSTRUCTORS(AsyncPacketSocket); 68 | }; 69 | 70 | } // namespace txmpp 71 | 72 | #endif // TXMPP_ASYNCPACKETSOCKET_H_ 73 | -------------------------------------------------------------------------------- /src/win32window.h: -------------------------------------------------------------------------------- 1 | /* 2 | * libjingle 3 | * Copyright 2004--2005, Google Inc. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions are met: 7 | * 8 | * 1. Redistributions of source code must retain the above copyright notice, 9 | * this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright notice, 11 | * this list of conditions and the following disclaimer in the documentation 12 | * and/or other materials provided with the distribution. 13 | * 3. The name of the author may not be used to endorse or promote products 14 | * derived from this software without specific prior written permission. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED 17 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 18 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO 19 | * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 20 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 21 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 22 | * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 23 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 24 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 25 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | */ 27 | 28 | #ifndef _TXMPP_WIN32WINDOW_H_ 29 | #define _TXMPP_WIN32WINDOW_H_ 30 | 31 | #ifndef NO_CONFIG_H 32 | #include "config.h" 33 | #endif 34 | 35 | #ifdef WIN32 36 | 37 | #include "win32.h" 38 | 39 | namespace txmpp { 40 | 41 | /////////////////////////////////////////////////////////////////////////////// 42 | // Win32Window 43 | /////////////////////////////////////////////////////////////////////////////// 44 | 45 | class Win32Window { 46 | public: 47 | Win32Window(); 48 | virtual ~Win32Window(); 49 | 50 | HWND handle() const { return wnd_; } 51 | 52 | bool Create(HWND parent, const wchar_t* title, DWORD style, DWORD exstyle, 53 | int x, int y, int cx, int cy); 54 | void Destroy(); 55 | 56 | // Call this first if you are running inside a DLL. 57 | static void SetInstance(HINSTANCE instance); 58 | // Call this when your DLL unloads. 59 | static void Shutdown(); 60 | 61 | protected: 62 | virtual bool OnMessage(UINT uMsg, WPARAM wParam, LPARAM lParam, 63 | LRESULT& result); 64 | 65 | virtual bool OnClose() { return true; } 66 | virtual void OnDestroyed() { } 67 | 68 | private: 69 | static LRESULT CALLBACK WndProc(HWND hwnd, UINT uMsg, WPARAM wParam, 70 | LPARAM lParam); 71 | 72 | HWND wnd_; 73 | static HINSTANCE instance_; 74 | static ATOM window_class_; 75 | }; 76 | 77 | /////////////////////////////////////////////////////////////////////////////// 78 | 79 | } // namespace txmpp 80 | 81 | #endif // WIN32 82 | 83 | #endif // _TXMPP_WIN32WINDOW_H_ 84 | -------------------------------------------------------------------------------- /src/asynctcpsocket.h: -------------------------------------------------------------------------------- 1 | /* 2 | * libjingle 3 | * Copyright 2004--2005, Google Inc. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions are met: 7 | * 8 | * 1. Redistributions of source code must retain the above copyright notice, 9 | * this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright notice, 11 | * this list of conditions and the following disclaimer in the documentation 12 | * and/or other materials provided with the distribution. 13 | * 3. The name of the author may not be used to endorse or promote products 14 | * derived from this software without specific prior written permission. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED 17 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 18 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO 19 | * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 20 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 21 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 22 | * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 23 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 24 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 25 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | */ 27 | 28 | #ifndef TXMPP_ASYNCTCPSOCKET_H_ 29 | #define TXMPP_ASYNCTCPSOCKET_H_ 30 | 31 | #ifndef NO_CONFIG_H 32 | #include "config.h" 33 | #endif 34 | 35 | #include "asyncpacketsocket.h" 36 | #include "socketfactory.h" 37 | 38 | namespace txmpp { 39 | 40 | // Simulates UDP semantics over TCP. Send and Recv packet sizes 41 | // are preserved, and drops packets silently on Send, rather than 42 | // buffer them in user space. 43 | class AsyncTCPSocket : public AsyncPacketSocket { 44 | public: 45 | static AsyncTCPSocket* Create(SocketFactory* factory) { 46 | AsyncSocket* sock = factory->CreateAsyncSocket(SOCK_STREAM); 47 | return (sock) ? new AsyncTCPSocket(sock) : NULL; 48 | } 49 | explicit AsyncTCPSocket(AsyncSocket* socket); 50 | virtual ~AsyncTCPSocket(); 51 | 52 | virtual int Send(const void* pv, size_t cb); 53 | virtual int SendTo(const void* pv, size_t cb, const SocketAddress& addr); 54 | 55 | txmpp::signal1 SignalConnect; 56 | txmpp::signal2 SignalClose; 57 | 58 | protected: 59 | int SendRaw(const void* pv, size_t cb); 60 | virtual void ProcessInput(char* data, size_t& len); 61 | 62 | private: 63 | int Flush(); 64 | 65 | // Called by the underlying socket 66 | void OnConnectEvent(AsyncSocket* socket); 67 | void OnReadEvent(AsyncSocket* socket); 68 | void OnWriteEvent(AsyncSocket* socket); 69 | void OnCloseEvent(AsyncSocket* socket, int error); 70 | 71 | char* inbuf_, * outbuf_; 72 | size_t insize_, inpos_, outsize_, outpos_; 73 | }; 74 | 75 | } // namespace txmpp 76 | 77 | #endif // TXMPP_ASYNCTCPSOCKET_H_ 78 | -------------------------------------------------------------------------------- /src/prexmppauthimpl.h: -------------------------------------------------------------------------------- 1 | /* 2 | * libjingle 3 | * Copyright 2004--2005, Google Inc. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions are met: 7 | * 8 | * 1. Redistributions of source code must retain the above copyright notice, 9 | * this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright notice, 11 | * this list of conditions and the following disclaimer in the documentation 12 | * and/or other materials provided with the distribution. 13 | * 3. The name of the author may not be used to endorse or promote products 14 | * derived from this software without specific prior written permission. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED 17 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 18 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO 19 | * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 20 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 21 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 22 | * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 23 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 24 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 25 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | */ 27 | 28 | #ifndef _TXMPP_PREXMPPAUTHIMPL_H_ 29 | #define _TXMPP_PREXMPPAUTHIMPL_H_ 30 | 31 | #ifndef NO_CONFIG_H 32 | #include "config.h" 33 | #endif 34 | 35 | #include 36 | #include "cryptstring.h" 37 | #include "sigslot.h" 38 | #include "jid.h" 39 | #include "saslhandler.h" 40 | #include "prexmppauth.h" 41 | 42 | namespace txmpp { 43 | 44 | class PreXmppAuthImpl : public PreXmppAuth { 45 | public: 46 | PreXmppAuthImpl(); 47 | virtual ~PreXmppAuthImpl(); 48 | 49 | virtual void StartPreXmppAuth(const Jid & jid, 50 | const SocketAddress & server, 51 | const CryptString & pass, 52 | const std::string & auth_cookie); 53 | 54 | virtual bool IsAuthDone() const { return done_; } 55 | virtual bool IsAuthorized() const { return true; } 56 | virtual bool HadError() const { return false; } 57 | virtual int GetError() const { return 0; } 58 | 59 | virtual CaptchaChallenge GetCaptchaChallenge() const { 60 | return CaptchaChallenge(); 61 | } 62 | virtual std::string GetAuthCookie() const { return auth_cookie_; } 63 | 64 | virtual std::string ChooseBestSaslMechanism( 65 | const std::vector & mechanisms, 66 | bool encrypted); 67 | 68 | virtual SaslMechanism * CreateSaslMechanism( 69 | const std::string & mechanism); 70 | 71 | private: 72 | Jid jid_; 73 | CryptString passwd_; 74 | std::string auth_cookie_; 75 | bool done_; 76 | }; 77 | 78 | } // namespace txmpp 79 | 80 | #endif // _TXMPP_PREXMPPAUTHIMPL_H_ 81 | -------------------------------------------------------------------------------- /src/examples/hello/xmppthread.cc: -------------------------------------------------------------------------------- 1 | /* 2 | * libjingle 3 | * Copyright 2004--2005, Google Inc. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions are met: 7 | * 8 | * 1. Redistributions of source code must retain the above copyright notice, 9 | * this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright notice, 11 | * this list of conditions and the following disclaimer in the documentation 12 | * and/or other materials provided with the distribution. 13 | * 3. The name of the author may not be used to endorse or promote products 14 | * derived from this software without specific prior written permission. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED 17 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 18 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO 19 | * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 20 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 21 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 22 | * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 23 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 24 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 25 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | */ 27 | 28 | #include "xmppthread.h" 29 | 30 | #include "../../prexmppauthimpl.h" 31 | #include "../../xmppasyncsocketimpl.h" 32 | #include "../../xmppclientsettings.h" 33 | 34 | namespace hello { 35 | namespace { 36 | 37 | const uint32 MSG_LOGIN = 1; 38 | const uint32 MSG_DISCONNECT = 2; 39 | 40 | struct LoginData : public txmpp::MessageData { 41 | LoginData(const txmpp::XmppClientSettings& s) : xcs(s) {} 42 | virtual ~LoginData() {} 43 | txmpp::XmppClientSettings xcs; 44 | }; 45 | 46 | } // namespace 47 | 48 | XmppThread::XmppThread() { 49 | pump_ = new XmppPump(this); 50 | } 51 | 52 | XmppThread::~XmppThread() { 53 | delete pump_; 54 | } 55 | 56 | void XmppThread::ProcessMessages(int cms) { 57 | txmpp::Thread::ProcessMessages(cms); 58 | } 59 | 60 | void XmppThread::Login(const txmpp::XmppClientSettings& xcs) { 61 | Post(this, MSG_LOGIN, new LoginData(xcs)); 62 | } 63 | 64 | void XmppThread::Disconnect() { 65 | Post(this, MSG_DISCONNECT); 66 | } 67 | 68 | void XmppThread::OnStateChange(txmpp::XmppEngine::State state) { 69 | } 70 | 71 | void XmppThread::OnMessage(txmpp::Message* pmsg) { 72 | switch (pmsg->message_id) { 73 | case MSG_LOGIN: { 74 | assert(pmsg->pdata); 75 | LoginData* data = reinterpret_cast(pmsg->pdata); 76 | pump_->DoLogin(data->xcs, new txmpp::XmppAsyncSocketImpl(true), 77 | new txmpp::PreXmppAuthImpl()); 78 | delete data; 79 | } 80 | break; 81 | case MSG_DISCONNECT: 82 | pump_->DoDisconnect(); 83 | break; 84 | default: 85 | assert(false); 86 | } 87 | } 88 | 89 | } // namespace hello 90 | -------------------------------------------------------------------------------- /src/saslmechanism.h: -------------------------------------------------------------------------------- 1 | /* 2 | * libjingle 3 | * Copyright 2004--2005, Google Inc. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions are met: 7 | * 8 | * 1. Redistributions of source code must retain the above copyright notice, 9 | * this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright notice, 11 | * this list of conditions and the following disclaimer in the documentation 12 | * and/or other materials provided with the distribution. 13 | * 3. The name of the author may not be used to endorse or promote products 14 | * derived from this software without specific prior written permission. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED 17 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 18 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO 19 | * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 20 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 21 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 22 | * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 23 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 24 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 25 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | */ 27 | 28 | #ifndef _TXMPP_SASLMECHANISM_H_ 29 | #define _TXMPP_SASLMECHANISM_H_ 30 | 31 | #ifndef NO_CONFIG_H 32 | #include "config.h" 33 | #endif 34 | 35 | #include 36 | 37 | namespace txmpp { 38 | 39 | class XmlElement; 40 | 41 | // Defines a mechnanism to do SASL authentication. 42 | // Subclass instances should have a self-contained way to present 43 | // credentials. 44 | class SaslMechanism { 45 | 46 | public: 47 | 48 | // Intended to be subclassed 49 | virtual ~SaslMechanism() {} 50 | 51 | // Should return the name of the SASL mechanism, e.g., "PLAIN" 52 | virtual std::string GetMechanismName() = 0; 53 | 54 | // Should generate the initial "auth" request. Default is just . 55 | virtual XmlElement * StartSaslAuth(); 56 | 57 | // Should respond to a SASL "" request. Default is 58 | // to abort (for mechanisms that do not do challenge-response) 59 | virtual XmlElement * HandleSaslChallenge(const XmlElement * challenge); 60 | 61 | // Notification of a SASL "". Sometimes information 62 | // is passed on success. 63 | virtual void HandleSaslSuccess(const XmlElement * success); 64 | 65 | // Notification of a SASL "". Sometimes information 66 | // for the user is passed on failure. 67 | virtual void HandleSaslFailure(const XmlElement * failure); 68 | 69 | protected: 70 | static std::string Base64Encode(const std::string & plain); 71 | static std::string Base64Decode(const std::string & encoded); 72 | static std::string Base64EncodeFromArray(const char * plain, size_t length); 73 | }; 74 | 75 | } // namespace txmpp 76 | 77 | #endif // _TXMPP_SASLMECHANISM_H_ 78 | -------------------------------------------------------------------------------- /src/bytebuffer.h: -------------------------------------------------------------------------------- 1 | /* 2 | * libjingle 3 | * Copyright 2004--2005, Google Inc. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions are met: 7 | * 8 | * 1. Redistributions of source code must retain the above copyright notice, 9 | * this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright notice, 11 | * this list of conditions and the following disclaimer in the documentation 12 | * and/or other materials provided with the distribution. 13 | * 3. The name of the author may not be used to endorse or promote products 14 | * derived from this software without specific prior written permission. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED 17 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 18 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO 19 | * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 20 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 21 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 22 | * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 23 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 24 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 25 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | */ 27 | 28 | #ifndef _TXMPP_BYTEBUFFER_H_ 29 | #define _TXMPP_BYTEBUFFER_H_ 30 | 31 | #ifndef NO_CONFIG_H 32 | #include "config.h" 33 | #endif 34 | 35 | #include 36 | 37 | #include "basictypes.h" 38 | #include "constructormagic.h" 39 | 40 | namespace txmpp { 41 | 42 | class ByteBuffer { 43 | public: 44 | ByteBuffer(); 45 | ByteBuffer(const char* bytes, size_t len); 46 | explicit ByteBuffer(const char* bytes); // uses strlen 47 | ~ByteBuffer(); 48 | 49 | const char* Data() const { return bytes_ + start_; } 50 | size_t Length() const { return end_ - start_; } 51 | size_t Capacity() const { return size_ - start_; } 52 | 53 | bool ReadUInt8(uint8* val); 54 | bool ReadUInt16(uint16* val); 55 | bool ReadUInt24(uint32* val); 56 | bool ReadUInt32(uint32* val); 57 | bool ReadUInt64(uint64* val); 58 | bool ReadString(std::string* val, size_t len); // append to val 59 | bool ReadBytes(char* val, size_t len); 60 | 61 | void WriteUInt8(uint8 val); 62 | void WriteUInt16(uint16 val); 63 | void WriteUInt24(uint32 val); 64 | void WriteUInt32(uint32 val); 65 | void WriteUInt64(uint64 val); 66 | void WriteString(const std::string& val); 67 | void WriteBytes(const char* val, size_t len); 68 | 69 | void Resize(size_t size); 70 | void Consume(size_t size); 71 | void Shift(size_t size); 72 | 73 | private: 74 | char* bytes_; 75 | size_t size_; 76 | size_t start_; 77 | size_t end_; 78 | 79 | // There are sensible ways to define these, but they aren't needed in our code 80 | // base. 81 | DISALLOW_COPY_AND_ASSIGN(ByteBuffer); 82 | }; 83 | 84 | } // namespace txmpp 85 | 86 | #endif // _TXMPP_BYTEBUFFER_H_ 87 | -------------------------------------------------------------------------------- /src/plainsaslhandler.h: -------------------------------------------------------------------------------- 1 | /* 2 | * libjingle 3 | * Copyright 2004--2005, Google Inc. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions are met: 7 | * 8 | * 1. Redistributions of source code must retain the above copyright notice, 9 | * this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright notice, 11 | * this list of conditions and the following disclaimer in the documentation 12 | * and/or other materials provided with the distribution. 13 | * 3. The name of the author may not be used to endorse or promote products 14 | * derived from this software without specific prior written permission. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED 17 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 18 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO 19 | * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 20 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 21 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 22 | * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 23 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 24 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 25 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | */ 27 | 28 | #ifndef _TXMPP_PLAINSASLHANDLER_H_ 29 | #define _TXMPP_PLAINSASLHANDLER_H_ 30 | 31 | #ifndef NO_CONFIG_H 32 | #include "config.h" 33 | #endif 34 | 35 | #include 36 | #include "saslhandler.h" 37 | 38 | namespace txmpp { 39 | 40 | class PlainSaslHandler : public SaslHandler { 41 | public: 42 | PlainSaslHandler(const Jid & jid, const CryptString & password, 43 | bool allow_plain) : jid_(jid), password_(password), 44 | allow_plain_(allow_plain) {} 45 | 46 | virtual ~PlainSaslHandler() {} 47 | 48 | // Should pick the best method according to this handler 49 | // returns the empty string if none are suitable 50 | virtual std::string ChooseBestSaslMechanism(const std::vector & mechanisms, bool encrypted) { 51 | 52 | if (!encrypted && !allow_plain_) { 53 | return ""; 54 | } 55 | 56 | std::vector::const_iterator it = std::find(mechanisms.begin(), mechanisms.end(), "PLAIN"); 57 | if (it == mechanisms.end()) { 58 | return ""; 59 | } 60 | else { 61 | return "PLAIN"; 62 | } 63 | } 64 | 65 | // Creates a SaslMechanism for the given mechanism name (you own it 66 | // once you get it). If not handled, return NULL. 67 | virtual SaslMechanism * CreateSaslMechanism(const std::string & mechanism) { 68 | if (mechanism == "PLAIN") { 69 | return new SaslPlainMechanism(jid_, password_); 70 | } 71 | return NULL; 72 | } 73 | 74 | private: 75 | Jid jid_; 76 | CryptString password_; 77 | bool allow_plain_; 78 | }; 79 | 80 | } // namespace txmpp 81 | 82 | #endif // _TXMPP_PLAINSASLHANDLER_H_ 83 | -------------------------------------------------------------------------------- /src/asyncudpsocket.cc: -------------------------------------------------------------------------------- 1 | /* 2 | * libjingle 3 | * Copyright 2004--2005, Google Inc. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions are met: 7 | * 8 | * 1. Redistributions of source code must retain the above copyright notice, 9 | * this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright notice, 11 | * this list of conditions and the following disclaimer in the documentation 12 | * and/or other materials provided with the distribution. 13 | * 3. The name of the author may not be used to endorse or promote products 14 | * derived from this software without specific prior written permission. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED 17 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 18 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO 19 | * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 20 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 21 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 22 | * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 23 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 24 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 25 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | */ 27 | 28 | #include "asyncudpsocket.h" 29 | 30 | #if defined(_MSC_VER) && _MSC_VER < 1300 31 | #pragma warning(disable:4786) 32 | #endif 33 | 34 | #include "logging.h" 35 | 36 | namespace txmpp { 37 | 38 | const int BUF_SIZE = 64 * 1024; 39 | 40 | AsyncUDPSocket::AsyncUDPSocket(AsyncSocket* socket) 41 | : AsyncPacketSocket(socket) { 42 | ASSERT(socket_ != NULL); 43 | size_ = BUF_SIZE; 44 | buf_ = new char[size_]; 45 | 46 | // The socket should start out readable but not writable. 47 | socket_->SignalReadEvent.connect(this, &AsyncUDPSocket::OnReadEvent); 48 | } 49 | 50 | AsyncUDPSocket::~AsyncUDPSocket() { 51 | delete [] buf_; 52 | } 53 | 54 | void AsyncUDPSocket::OnReadEvent(AsyncSocket* socket) { 55 | ASSERT(socket == socket_); 56 | 57 | SocketAddress remote_addr; 58 | int len = socket_->RecvFrom(buf_, size_, &remote_addr); 59 | if (len < 0) { 60 | // An error here typically means we got an ICMP error in response to our 61 | // send datagram, indicating the remote address was unreachable. 62 | // When doing ICE, this kind of thing will often happen. 63 | // TODO(juberti): Do something better like forwarding the error to the user. 64 | SocketAddress local_addr = socket_->GetLocalAddress(); 65 | LOG(LS_INFO) << "AsyncUDPSocket[" << local_addr.ToString() << "] " 66 | << "receive failed with error " << socket_->GetError(); 67 | return; 68 | } 69 | 70 | // TODO(juberti): Make sure that we got all of the packet. 71 | // If we did not, then we should resize our buffer to be large enough. 72 | SignalReadPacket(buf_, (size_t)len, remote_addr, this); 73 | } 74 | 75 | } // namespace txmpp 76 | -------------------------------------------------------------------------------- /src/asyncpacketsocket.cc: -------------------------------------------------------------------------------- 1 | /* 2 | * libjingle 3 | * Copyright 2004--2005, Google Inc. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions are met: 7 | * 8 | * 1. Redistributions of source code must retain the above copyright notice, 9 | * this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright notice, 11 | * this list of conditions and the following disclaimer in the documentation 12 | * and/or other materials provided with the distribution. 13 | * 3. The name of the author may not be used to endorse or promote products 14 | * derived from this software without specific prior written permission. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED 17 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 18 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO 19 | * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 20 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 21 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 22 | * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 23 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 24 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 25 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | */ 27 | 28 | #include "asyncpacketsocket.h" 29 | 30 | #if defined(_MSC_VER) && _MSC_VER < 1300 31 | #pragma warning(disable:4786) 32 | #endif 33 | 34 | namespace txmpp { 35 | 36 | AsyncPacketSocket::AsyncPacketSocket(AsyncSocket* socket) : socket_(socket) { 37 | } 38 | 39 | AsyncPacketSocket::~AsyncPacketSocket() { 40 | delete socket_; 41 | } 42 | 43 | SocketAddress AsyncPacketSocket::GetLocalAddress() const { 44 | return socket_->GetLocalAddress(); 45 | } 46 | 47 | SocketAddress AsyncPacketSocket::GetRemoteAddress() const { 48 | return socket_->GetRemoteAddress(); 49 | } 50 | 51 | int AsyncPacketSocket::Bind(const SocketAddress& addr) { 52 | return socket_->Bind(addr); 53 | } 54 | 55 | int AsyncPacketSocket::Connect(const SocketAddress& addr) { 56 | return socket_->Connect(addr); 57 | } 58 | 59 | int AsyncPacketSocket::Send(const void *pv, size_t cb) { 60 | return socket_->Send(pv, cb); 61 | } 62 | 63 | int AsyncPacketSocket::SendTo( 64 | const void *pv, size_t cb, const SocketAddress& addr) { 65 | return socket_->SendTo(pv, cb, addr); 66 | } 67 | 68 | int AsyncPacketSocket::Close() { 69 | return socket_->Close(); 70 | } 71 | 72 | Socket::ConnState AsyncPacketSocket::GetState() const { 73 | return socket_->GetState(); 74 | } 75 | 76 | int AsyncPacketSocket::GetOption(Socket::Option opt, int* value) { 77 | return socket_->GetOption(opt, value); 78 | } 79 | 80 | int AsyncPacketSocket::SetOption(Socket::Option opt, int value) { 81 | return socket_->SetOption(opt, value); 82 | } 83 | 84 | int AsyncPacketSocket::GetError() const { 85 | return socket_->GetError(); 86 | } 87 | 88 | void AsyncPacketSocket::SetError(int error) { 89 | return socket_->SetError(error); 90 | } 91 | 92 | } // namespace txmpp 93 | -------------------------------------------------------------------------------- /src/time.h: -------------------------------------------------------------------------------- 1 | /* 2 | * libjingle 3 | * Copyright 2004--2005, Google Inc. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions are met: 7 | * 8 | * 1. Redistributions of source code must retain the above copyright notice, 9 | * this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright notice, 11 | * this list of conditions and the following disclaimer in the documentation 12 | * and/or other materials provided with the distribution. 13 | * 3. The name of the author may not be used to endorse or promote products 14 | * derived from this software without specific prior written permission. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED 17 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 18 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO 19 | * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 20 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 21 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 22 | * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 23 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 24 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 25 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | */ 27 | 28 | #ifndef _TXMPP_TIME_H_ 29 | #define _TXMPP_TIME_H_ 30 | 31 | #ifndef NO_CONFIG_H 32 | #include "config.h" 33 | #endif 34 | 35 | #ifndef WIN32 36 | #include_next 37 | #endif 38 | 39 | #include "basictypes.h" 40 | 41 | namespace txmpp { 42 | 43 | typedef uint32 TimeStamp; 44 | 45 | // Returns the current time in milliseconds. 46 | uint32 Time(); 47 | 48 | // Approximate time when the program started. 49 | uint32 StartTime(); 50 | 51 | // Returns a future timestamp, 'elapsed' milliseconds from now. 52 | uint32 TimeAfter(int32 elapsed); 53 | 54 | // Comparisons between time values, which can wrap around. 55 | bool TimeIsBetween(uint32 earlier, uint32 middle, uint32 later); // Inclusive 56 | bool TimeIsLaterOrEqual(uint32 earlier, uint32 later); // Inclusive 57 | bool TimeIsLater(uint32 earlier, uint32 later); // Exclusive 58 | 59 | // Returns the later of two timestamps. 60 | inline uint32 TimeMax(uint32 ts1, uint32 ts2) { 61 | return TimeIsLaterOrEqual(ts1, ts2) ? ts2 : ts1; 62 | } 63 | 64 | // Returns the earlier of two timestamps. 65 | inline uint32 TimeMin(uint32 ts1, uint32 ts2) { 66 | return TimeIsLaterOrEqual(ts1, ts2) ? ts1 : ts2; 67 | } 68 | 69 | // Number of milliseconds that would elapse between 'earlier' and 'later' 70 | // timestamps. The value is negative if 'later' occurs before 'earlier'. 71 | int32 TimeDiff(uint32 later, uint32 earlier); 72 | 73 | // The number of milliseconds that have elapsed since 'earlier'. 74 | inline int32 TimeSince(uint32 earlier) { 75 | return TimeDiff(Time(), earlier); 76 | } 77 | 78 | // The number of milliseconds that will elapse between now and 'later'. 79 | inline int32 TimeUntil(uint32 later) { 80 | return TimeDiff(later, Time()); 81 | } 82 | 83 | } // namespace txmpp 84 | 85 | #endif // _TXMPP_TIME_H_ 86 | -------------------------------------------------------------------------------- /src/ssladapter.h: -------------------------------------------------------------------------------- 1 | /* 2 | * libjingle 3 | * Copyright 2004--2005, Google Inc. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions are met: 7 | * 8 | * 1. Redistributions of source code must retain the above copyright notice, 9 | * this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright notice, 11 | * this list of conditions and the following disclaimer in the documentation 12 | * and/or other materials provided with the distribution. 13 | * 3. The name of the author may not be used to endorse or promote products 14 | * derived from this software without specific prior written permission. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED 17 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 18 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO 19 | * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 20 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 21 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 22 | * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 23 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 24 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 25 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | */ 27 | 28 | #ifndef _TXMPP_SSLADAPTER_H_ 29 | #define _TXMPP_SSLADAPTER_H_ 30 | 31 | #ifndef NO_CONFIG_H 32 | #include "config.h" 33 | #endif 34 | 35 | #include "asyncsocket.h" 36 | 37 | namespace txmpp { 38 | 39 | /////////////////////////////////////////////////////////////////////////////// 40 | 41 | class SSLAdapter : public AsyncSocketAdapter { 42 | public: 43 | SSLAdapter(AsyncSocket* socket) 44 | : AsyncSocketAdapter(socket), ignore_bad_cert_(false) { } 45 | 46 | bool ignore_bad_cert() const { return ignore_bad_cert_; } 47 | void set_ignore_bad_cert(bool ignore) { ignore_bad_cert_ = ignore; } 48 | 49 | // StartSSL returns 0 if successful. 50 | // If StartSSL is called while the socket is closed or connecting, the SSL 51 | // negotiation will begin as soon as the socket connects. 52 | virtual int StartSSL(const char* hostname, bool restartable) = 0; 53 | 54 | // Create the default SSL adapter for this platform 55 | static SSLAdapter* Create(AsyncSocket* socket); 56 | 57 | private: 58 | // If true, the server certificate need not match the configured hostname. 59 | bool ignore_bad_cert_; 60 | }; 61 | 62 | /////////////////////////////////////////////////////////////////////////////// 63 | 64 | typedef bool (*VerificationCallback)(void* cert); 65 | 66 | // Call this on the main thread, before using SSL. 67 | // Call CleanupSSLThread when finished with SSL. 68 | bool InitializeSSL(VerificationCallback callback = NULL); 69 | 70 | // Call to initialize additional threads. 71 | bool InitializeSSLThread(); 72 | 73 | // Call to cleanup additional threads, and also the main thread. 74 | bool CleanupSSL(); 75 | 76 | /////////////////////////////////////////////////////////////////////////////// 77 | 78 | } // namespace txmpp 79 | 80 | #endif // _TXMPP_SSLADAPTER_H_ 81 | -------------------------------------------------------------------------------- /src/taskparent.h: -------------------------------------------------------------------------------- 1 | /* 2 | * libjingle 3 | * Copyright 2004--2006, Google Inc. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions are met: 7 | * 8 | * 1. Redistributions of source code must retain the above copyright notice, 9 | * this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright notice, 11 | * this list of conditions and the following disclaimer in the documentation 12 | * and/or other materials provided with the distribution. 13 | * 3. The name of the author may not be used to endorse or promote products 14 | * derived from this software without specific prior written permission. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED 17 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 18 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO 19 | * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 20 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 21 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 22 | * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 23 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 24 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 25 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | */ 27 | 28 | #ifndef _TXMPP_TASKPARENT_H_ 29 | #define _TXMPP_TASKPARENT_H_ 30 | 31 | #ifndef NO_CONFIG_H 32 | #include "config.h" 33 | #endif 34 | 35 | #include 36 | 37 | #include "basictypes.h" 38 | #include "scoped_ptr.h" 39 | 40 | namespace txmpp { 41 | 42 | class Task; 43 | class TaskRunner; 44 | 45 | class TaskParent { 46 | public: 47 | TaskParent(Task *derived_instance, TaskParent *parent); 48 | explicit TaskParent(TaskRunner *derived_instance); 49 | virtual ~TaskParent() { } 50 | 51 | TaskParent *GetParent() { return parent_; } 52 | TaskRunner *GetRunner() { return runner_; } 53 | 54 | // Retrieves a parent that corresponds to the given "code". The code 55 | // should be defined in a unique manner for the given subtree. This 56 | // method will crash (when the parent_ is NULL) if there is no corresponding 57 | // parent. 58 | // 59 | // Example use: 60 | // XmppClient* client = 61 | // static_cast(parent->GetParent(XMPP_CLIENT_TASK_CODE)); 62 | virtual TaskParent *GetParent(int code) { return parent_->GetParent(code); } 63 | 64 | bool AllChildrenDone(); 65 | bool AnyChildError(); 66 | #ifdef _DEBUG 67 | bool IsChildTask(Task *task); 68 | #endif 69 | 70 | protected: 71 | void OnStopped(Task *task); 72 | void AbortAllChildren(); 73 | TaskParent *parent() { 74 | return parent_; 75 | } 76 | 77 | private: 78 | void Initialize(); 79 | void OnChildStopped(Task *child); 80 | void AddChild(Task *child); 81 | 82 | TaskParent *parent_; 83 | TaskRunner *runner_; 84 | bool child_error_; 85 | typedef std::set ChildSet; 86 | scoped_ptr children_; 87 | DISALLOW_EVIL_CONSTRUCTORS(TaskParent); 88 | }; 89 | 90 | 91 | } // namespace txmpp 92 | 93 | #endif // _TXMPP_TASKPARENT_H_ 94 | -------------------------------------------------------------------------------- /src/autodetectproxy.h: -------------------------------------------------------------------------------- 1 | /* 2 | * libjingle 3 | * Copyright 2004--2005, Google Inc. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions are met: 7 | * 8 | * 1. Redistributions of source code must retain the above copyright notice, 9 | * this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright notice, 11 | * this list of conditions and the following disclaimer in the documentation 12 | * and/or other materials provided with the distribution. 13 | * 3. The name of the author may not be used to endorse or promote products 14 | * derived from this software without specific prior written permission. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED 17 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 18 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO 19 | * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 20 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 21 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 22 | * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 23 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 24 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 25 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | */ 27 | 28 | #ifndef TXMPP_AUTODETECTPROXY_H_ 29 | #define TXMPP_AUTODETECTPROXY_H_ 30 | 31 | #ifndef NO_CONFIG_H 32 | #include "config.h" 33 | #endif 34 | 35 | #include 36 | 37 | #include "cryptstring.h" 38 | #include "proxyinfo.h" 39 | #include "signalthread.h" 40 | 41 | namespace txmpp { 42 | 43 | /////////////////////////////////////////////////////////////////////////////// 44 | // AutoDetectProxy 45 | /////////////////////////////////////////////////////////////////////////////// 46 | 47 | class AsyncSocket; 48 | 49 | class AutoDetectProxy : public SignalThread { 50 | public: 51 | explicit AutoDetectProxy(const std::string& user_agent); 52 | 53 | const ProxyInfo& proxy() const { return proxy_; } 54 | 55 | void set_server_url(const std::string& url) { 56 | server_url_ = url; 57 | } 58 | void set_proxy(const SocketAddress& proxy) { 59 | proxy_.type = PROXY_UNKNOWN; 60 | proxy_.address = proxy; 61 | } 62 | void set_auth_info(bool use_auth, const std::string& username, 63 | const CryptString& password) { 64 | if (use_auth) { 65 | proxy_.username = username; 66 | proxy_.password = password; 67 | } 68 | } 69 | 70 | protected: 71 | virtual ~AutoDetectProxy(); 72 | 73 | // SignalThread Interface 74 | virtual void DoWork(); 75 | virtual void OnMessage(Message *msg); 76 | 77 | void Next(); 78 | void Complete(ProxyType type); 79 | 80 | void OnConnectEvent(AsyncSocket * socket); 81 | void OnReadEvent(AsyncSocket * socket); 82 | void OnCloseEvent(AsyncSocket * socket, int error); 83 | 84 | private: 85 | std::string agent_; 86 | std::string server_url_; 87 | ProxyInfo proxy_; 88 | AsyncSocket* socket_; 89 | int next_; 90 | }; 91 | 92 | } // namespace txmpp 93 | 94 | #endif // TXMPP_AUTODETECTPROXY_H_ 95 | -------------------------------------------------------------------------------- /src/prexmppauth.h: -------------------------------------------------------------------------------- 1 | /* 2 | * libjingle 3 | * Copyright 2004--2005, Google Inc. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions are met: 7 | * 8 | * 1. Redistributions of source code must retain the above copyright notice, 9 | * this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright notice, 11 | * this list of conditions and the following disclaimer in the documentation 12 | * and/or other materials provided with the distribution. 13 | * 3. The name of the author may not be used to endorse or promote products 14 | * derived from this software without specific prior written permission. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED 17 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 18 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO 19 | * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 20 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 21 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 22 | * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 23 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 24 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 25 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | */ 27 | 28 | #ifndef _TXMPP_PREXMPPAUTH_H_ 29 | #define _TXMPP_PREXMPPAUTH_H_ 30 | 31 | #ifndef NO_CONFIG_H 32 | #include "config.h" 33 | #endif 34 | 35 | #include "cryptstring.h" 36 | #include "saslhandler.h" 37 | #include "sigslot.h" 38 | 39 | namespace txmpp { 40 | 41 | class SocketAddress; 42 | 43 | class Jid; 44 | class SaslMechanism; 45 | 46 | class CaptchaChallenge { 47 | public: 48 | CaptchaChallenge() : captcha_needed_(false) {} 49 | CaptchaChallenge(const std::string& token, const std::string& url) 50 | : captcha_needed_(true), captcha_token_(token), captcha_image_url_(url) { 51 | } 52 | 53 | bool captcha_needed() const { return captcha_needed_; } 54 | const std::string& captcha_token() const { return captcha_token_; } 55 | 56 | // This url is relative to the gaia server. Once we have better tools 57 | // for cracking URLs, we should probably make this a full URL 58 | const std::string& captcha_image_url() const { return captcha_image_url_; } 59 | 60 | private: 61 | bool captcha_needed_; 62 | std::string captcha_token_; 63 | std::string captcha_image_url_; 64 | }; 65 | 66 | class PreXmppAuth : public SaslHandler { 67 | public: 68 | virtual ~PreXmppAuth() {} 69 | 70 | virtual void StartPreXmppAuth( 71 | const Jid & jid, 72 | const SocketAddress & server, 73 | const CryptString & pass, 74 | const std::string & auth_cookie) = 0; 75 | 76 | signal0<> SignalAuthDone; 77 | 78 | virtual bool IsAuthDone() const = 0; 79 | virtual bool IsAuthorized() const = 0; 80 | virtual bool HadError() const = 0; 81 | virtual int GetError() const = 0; 82 | virtual CaptchaChallenge GetCaptchaChallenge() const = 0; 83 | virtual std::string GetAuthCookie() const = 0; 84 | }; 85 | 86 | } // namespace txmpp 87 | 88 | #endif // _TXMPP_PREXMPPAUTH_H_ 89 | -------------------------------------------------------------------------------- /src/ssladapter.cc: -------------------------------------------------------------------------------- 1 | /* 2 | * libjingle 3 | * Copyright 2004--2005, Google Inc. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions are met: 7 | * 8 | * 1. Redistributions of source code must retain the above copyright notice, 9 | * this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright notice, 11 | * this list of conditions and the following disclaimer in the documentation 12 | * and/or other materials provided with the distribution. 13 | * 3. The name of the author may not be used to endorse or promote products 14 | * derived from this software without specific prior written permission. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED 17 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 18 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO 19 | * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 20 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 21 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 22 | * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 23 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 24 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 25 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | */ 27 | 28 | #include "ssladapter.h" 29 | 30 | // Decide which (if any) implementation of SSL we will use. 31 | #if !defined(SSL_USE_SCHANNEL) && !defined(SSL_USE_OPENSSL) 32 | #ifdef WIN32 33 | #define SSL_USE_SCHANNEL 1 34 | #else // !WIN32 35 | #define SSL_USE_OPENSSL HAVE_OPENSSL_SSL_H 36 | #endif // !WIN32 37 | #endif 38 | 39 | #if SSL_USE_SCHANNEL 40 | 41 | #include "schanneladapter.h" 42 | 43 | #elif SSL_USE_OPENSSL // && !SSL_USE_SCHANNEL 44 | 45 | #include "openssladapter.h" 46 | 47 | #endif // SSL_USE_OPENSSL && !SSL_USE_SCHANNEL 48 | 49 | /////////////////////////////////////////////////////////////////////////////// 50 | 51 | namespace txmpp { 52 | 53 | SSLAdapter* 54 | SSLAdapter::Create(AsyncSocket* socket) { 55 | #if SSL_USE_SCHANNEL 56 | return new SChannelAdapter(socket); 57 | #elif SSL_USE_OPENSSL // && !SSL_USE_SCHANNEL 58 | return new OpenSSLAdapter(socket); 59 | #else // !SSL_USE_OPENSSL && !SSL_USE_SCHANNEL 60 | return NULL; 61 | #endif // !SSL_USE_OPENSSL && !SSL_USE_SCHANNEL 62 | } 63 | 64 | /////////////////////////////////////////////////////////////////////////////// 65 | 66 | #if SSL_USE_OPENSSL 67 | 68 | bool InitializeSSL(VerificationCallback callback) { 69 | return OpenSSLAdapter::InitializeSSL(callback); 70 | } 71 | 72 | bool InitializeSSLThread() { 73 | return OpenSSLAdapter::InitializeSSLThread(); 74 | } 75 | 76 | bool CleanupSSL() { 77 | return OpenSSLAdapter::CleanupSSL(); 78 | } 79 | 80 | #else // !SSL_USE_OPENSSL 81 | 82 | bool InitializeSSL(VerificationCallback callback) { 83 | return true; 84 | } 85 | 86 | bool InitializeSSLThread() { 87 | return true; 88 | } 89 | 90 | bool CleanupSSL() { 91 | return true; 92 | } 93 | 94 | #endif // !SSL_USE_OPENSSL 95 | 96 | /////////////////////////////////////////////////////////////////////////////// 97 | 98 | } // namespace txmpp 99 | -------------------------------------------------------------------------------- /src/qname.h: -------------------------------------------------------------------------------- 1 | /* 2 | * libjingle 3 | * Copyright 2004--2005, Google Inc. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions are met: 7 | * 8 | * 1. Redistributions of source code must retain the above copyright notice, 9 | * this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright notice, 11 | * this list of conditions and the following disclaimer in the documentation 12 | * and/or other materials provided with the distribution. 13 | * 3. The name of the author may not be used to endorse or promote products 14 | * derived from this software without specific prior written permission. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED 17 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 18 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO 19 | * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 20 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 21 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 22 | * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 23 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 24 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 25 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | */ 27 | 28 | #ifndef _TXMPP_QNAME_H_ 29 | #define _TXMPP_QNAME_H_ 30 | 31 | #ifndef NO_CONFIG_H 32 | #include "config.h" 33 | #endif 34 | 35 | #include 36 | 37 | namespace txmpp { 38 | 39 | 40 | class QName 41 | { 42 | public: 43 | explicit QName(); 44 | QName(const QName & qname) : data_(qname.data_) { data_->AddRef(); } 45 | explicit QName(bool add, const std::string & ns, const char * local); 46 | explicit QName(bool add, const std::string & ns, const std::string & local); 47 | explicit QName(const std::string & ns, const char * local); 48 | explicit QName(const std::string & mergedOrLocal); 49 | QName & operator=(const QName & qn) { 50 | qn.data_->AddRef(); 51 | data_->Release(); 52 | data_ = qn.data_; 53 | return *this; 54 | } 55 | ~QName(); 56 | 57 | const std::string & Namespace() const { return data_->namespace_; } 58 | const std::string & LocalPart() const { return data_->localPart_; } 59 | std::string Merged() const; 60 | int Compare(const QName & other) const; 61 | bool operator==(const QName & other) const; 62 | bool operator!=(const QName & other) const { return !operator==(other); } 63 | bool operator<(const QName & other) const { return Compare(other) < 0; } 64 | 65 | class Data { 66 | public: 67 | Data(const std::string & ns, const std::string & local) : 68 | namespace_(ns), 69 | localPart_(local), 70 | refcount_(1) {} 71 | 72 | Data() : refcount_(0) {} 73 | 74 | std::string namespace_; 75 | std::string localPart_; 76 | void AddRef() { refcount_++; } 77 | void Release() { if (!--refcount_) { delete this; } } 78 | bool Occupied() { return !!refcount_; } 79 | 80 | private: 81 | int refcount_; 82 | }; 83 | 84 | private: 85 | Data * data_; 86 | }; 87 | 88 | 89 | } // namespace txmpp 90 | 91 | #endif // _TXMPP_QNAME_H_ 92 | -------------------------------------------------------------------------------- /src/xmppasyncsocketimpl.h: -------------------------------------------------------------------------------- 1 | /* 2 | * libjingle 3 | * Copyright 2004--2005, Google Inc. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions are met: 7 | * 8 | * 1. Redistributions of source code must retain the above copyright notice, 9 | * this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright notice, 11 | * this list of conditions and the following disclaimer in the documentation 12 | * and/or other materials provided with the distribution. 13 | * 3. The name of the author may not be used to endorse or promote products 14 | * derived from this software without specific prior written permission. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED 17 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 18 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO 19 | * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 20 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 21 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 22 | * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 23 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 24 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 25 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | */ 27 | 28 | #ifndef _TXMPP_XMPPASYNCSOCKETIMPL_H_ 29 | #define _TXMPP_XMPPASYNCSOCKETIMPL_H_ 30 | 31 | #ifndef NO_CONFIG_H 32 | #include "config.h" 33 | #endif 34 | 35 | #include "asyncsocket.h" 36 | #include "bytebuffer.h" 37 | #include "sigslot.h" 38 | #include "xmppasyncsocket.h" 39 | 40 | // The below define selects the SSLStreamAdapter implementation for 41 | // SSL, as opposed to the SSLAdapter socket adapter. 42 | // #define USE_SSLSTREAM 43 | 44 | namespace txmpp { 45 | 46 | class StreamInterface; 47 | 48 | extern AsyncSocket* cricket_socket_; 49 | 50 | class XmppAsyncSocketImpl : public XmppAsyncSocket, public has_slots<> { 51 | public: 52 | XmppAsyncSocketImpl(bool tls); 53 | ~XmppAsyncSocketImpl(); 54 | 55 | virtual XmppAsyncSocket::State state(); 56 | virtual XmppAsyncSocket::Error error(); 57 | virtual int GetError(); 58 | 59 | virtual bool Connect(const SocketAddress& addr); 60 | virtual bool Read(char * data, size_t len, size_t* len_read); 61 | virtual bool Write(const char * data, size_t len); 62 | virtual bool Close(); 63 | virtual bool StartTls(const std::string & domainname); 64 | 65 | signal1 SignalCloseEvent; 66 | 67 | private: 68 | #ifndef USE_SSLSTREAM 69 | void OnReadEvent(AsyncSocket * socket); 70 | void OnWriteEvent(AsyncSocket * socket); 71 | void OnConnectEvent(AsyncSocket * socket); 72 | void OnCloseEvent(AsyncSocket * socket, int error); 73 | #else // USE_SSLSTREAM 74 | void OnEvent(StreamInterface* stream, int events, int err); 75 | #endif // USE_SSLSTREAM 76 | 77 | AsyncSocket * cricket_socket_; 78 | #ifdef USE_SSLSTREAM 79 | StreamInterface *stream_; 80 | #endif // USE_SSLSTREAM 81 | XmppAsyncSocket::State state_; 82 | ByteBuffer buffer_; 83 | bool tls_; 84 | }; 85 | 86 | } // namespace txmpp 87 | 88 | #endif // _TXMPP_XMPPASYNCSOCKETIMPL_H_ 89 | -------------------------------------------------------------------------------- /src/xmppstanzaparser.cc: -------------------------------------------------------------------------------- 1 | /* 2 | * libjingle 3 | * Copyright 2004--2005, Google Inc. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions are met: 7 | * 8 | * 1. Redistributions of source code must retain the above copyright notice, 9 | * this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright notice, 11 | * this list of conditions and the following disclaimer in the documentation 12 | * and/or other materials provided with the distribution. 13 | * 3. The name of the author may not be used to endorse or promote products 14 | * derived from this software without specific prior written permission. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED 17 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 18 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO 19 | * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 20 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 21 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 22 | * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 23 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 24 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 25 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | */ 27 | 28 | #include "xmppstanzaparser.h" 29 | 30 | #include "xmlelement.h" 31 | #include "common.h" 32 | #include "constants.h" 33 | #include 34 | 35 | namespace txmpp { 36 | 37 | XmppStanzaParser::XmppStanzaParser(XmppStanzaParseHandler *psph) : 38 | psph_(psph), 39 | innerHandler_(this), 40 | parser_(&innerHandler_), 41 | depth_(0), 42 | builder_() { 43 | } 44 | 45 | void 46 | XmppStanzaParser::Reset() { 47 | parser_.Reset(); 48 | depth_ = 0; 49 | builder_.Reset(); 50 | } 51 | 52 | void 53 | XmppStanzaParser::IncomingStartElement( 54 | XmlParseContext * pctx, const char * name, const char ** atts) { 55 | if (depth_++ == 0) { 56 | XmlElement * pelStream = XmlBuilder::BuildElement(pctx, name, atts); 57 | if (pelStream == NULL) { 58 | pctx->RaiseError(XML_ERROR_SYNTAX); 59 | return; 60 | } 61 | psph_->StartStream(pelStream); 62 | delete pelStream; 63 | return; 64 | } 65 | 66 | builder_.StartElement(pctx, name, atts); 67 | } 68 | 69 | void 70 | XmppStanzaParser::IncomingCharacterData( 71 | XmlParseContext * pctx, const char * text, int len) { 72 | if (depth_ > 1) { 73 | builder_.CharacterData(pctx, text, len); 74 | } 75 | } 76 | 77 | void 78 | XmppStanzaParser::IncomingEndElement( 79 | XmlParseContext * pctx, const char * name) { 80 | if (--depth_ == 0) { 81 | psph_->EndStream(); 82 | return; 83 | } 84 | 85 | builder_.EndElement(pctx, name); 86 | 87 | if (depth_ == 1) { 88 | XmlElement *element = builder_.CreateElement(); 89 | psph_->Stanza(element); 90 | delete element; 91 | } 92 | } 93 | 94 | void 95 | XmppStanzaParser::IncomingError( 96 | XmlParseContext * pctx, XML_Error errCode) { 97 | UNUSED(pctx); 98 | UNUSED(errCode); 99 | psph_->XmlError(); 100 | } 101 | 102 | } // namespace txmpp 103 | -------------------------------------------------------------------------------- /src/ratelimitmanager.cc: -------------------------------------------------------------------------------- 1 | /* 2 | * libjingle 3 | * Copyright 2004--2006, Google Inc. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions are met: 7 | * 8 | * 1. Redistributions of source code must retain the above copyright notice, 9 | * this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright notice, 11 | * this list of conditions and the following disclaimer in the documentation 12 | * and/or other materials provided with the distribution. 13 | * 3. The name of the author may not be used to endorse or promote products 14 | * derived from this software without specific prior written permission. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED 17 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 18 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO 19 | * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 20 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 21 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 22 | * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 23 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 24 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 25 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | */ 27 | 28 | #include "ratelimitmanager.h" 29 | 30 | #include 31 | 32 | namespace txmpp { 33 | 34 | RateLimitManager::RateLimit* RateLimitManager::GetRateLimit( 35 | const std::string event_name) { 36 | RateLimitMap::iterator it = rate_limits_.find(event_name); 37 | if (it != rate_limits_.end()) { 38 | return it->second; 39 | } 40 | return NULL; 41 | } 42 | 43 | bool RateLimitManager::IsWithinRateLimit(const std::string event_name) { 44 | RateLimit* current_rate = GetRateLimit(event_name); 45 | if (current_rate) { 46 | return current_rate->IsWithinRateLimit(); 47 | } 48 | return true; // If no rate limit is set, then you must be under the limit 49 | } 50 | 51 | void RateLimitManager::UpdateRateLimit(const std::string event_name, 52 | int max_count, 53 | int per_x_seconds) { 54 | RateLimit* current_rate = GetRateLimit(event_name); 55 | if (!current_rate) { 56 | current_rate = new RateLimit(max_count, per_x_seconds); 57 | rate_limits_[event_name] = current_rate; 58 | } 59 | current_rate->UpdateRateLimit(); 60 | } 61 | 62 | bool RateLimitManager::VerifyRateLimit(const std::string event_name, 63 | int max_count, 64 | int per_x_seconds) { 65 | return VerifyRateLimit(event_name, max_count, per_x_seconds, false); 66 | } 67 | 68 | bool RateLimitManager::VerifyRateLimit(const std::string event_name, 69 | int max_count, 70 | int per_x_seconds, 71 | bool always_update) { 72 | bool within_rate_limit = IsWithinRateLimit(event_name); 73 | if (within_rate_limit || always_update) { 74 | UpdateRateLimit(event_name, max_count, per_x_seconds); 75 | } 76 | return within_rate_limit; 77 | } 78 | 79 | } // namespace txmpp 80 | -------------------------------------------------------------------------------- /src/linux.h: -------------------------------------------------------------------------------- 1 | // Copyright 2008 Google Inc. All Rights Reserved. 2 | // Author: araju@google.com (Avanish Raju) 3 | 4 | #ifndef _TXMPP_LINUX_H_ 5 | #define _TXMPP_LINUX_H_ 6 | 7 | #ifndef NO_CONFIG_H 8 | #include "config.h" 9 | #endif 10 | 11 | #ifdef LINUX 12 | #include 13 | #include 14 | #include 15 | #include "stream.h" 16 | 17 | namespace txmpp { 18 | 19 | ////////////////////////////////////////////////////////////////////////////// 20 | // ConfigParser parses a FileStream of an ".ini."-type format into a map. 21 | ////////////////////////////////////////////////////////////////////////////// 22 | 23 | // Sample Usage: 24 | // ConfigParser parser; 25 | // ConfigParser::MapVector key_val_pairs; 26 | // if (parser.Open(inifile) && parser.Parse(&key_val_pairs)) { 27 | // for (int section_num=0; i < key_val_pairs.size(); ++section_num) { 28 | // std::string val1 = key_val_pairs[section_num][key1]; 29 | // std::string val2 = key_val_pairs[section_num][key2]; 30 | // // Do something with valn; 31 | // } 32 | // } 33 | 34 | class ConfigParser { 35 | public: 36 | typedef std::map SimpleMap; 37 | typedef std::vector MapVector; 38 | 39 | ConfigParser(); 40 | virtual ~ConfigParser(); 41 | 42 | virtual bool Open(const std::string& filename); 43 | virtual void Attach(StreamInterface* stream); 44 | virtual bool Parse(MapVector *key_val_pairs); 45 | virtual bool ParseSection(SimpleMap *key_val_pair); 46 | virtual bool ParseLine(std::string *key, std::string *value); 47 | 48 | private: 49 | scoped_ptr instream_; 50 | }; 51 | 52 | ////////////////////////////////////////////////////////////////////////////// 53 | // ProcCpuInfo reads CPU info from the /proc subsystem on any *NIX platform. 54 | ////////////////////////////////////////////////////////////////////////////// 55 | 56 | // Sample Usage: 57 | // ProcCpuInfo proc_info; 58 | // int no_of_cpu; 59 | // if (proc_info.LoadFromSystem()) { 60 | // std::string out_str; 61 | // proc_info.GetNumCpus(&no_of_cpu); 62 | // proc_info.GetCpuStringValue(0, "vendor_id", &out_str); 63 | // } 64 | // } 65 | 66 | class ProcCpuInfo { 67 | public: 68 | ProcCpuInfo(); 69 | virtual ~ProcCpuInfo(); 70 | 71 | // Reads the proc subsystem's cpu info into memory. If this fails, this 72 | // returns false; if it succeeds, it returns true. 73 | virtual bool LoadFromSystem(); 74 | 75 | // Obtains the number of CPUs and places the value num. 76 | virtual bool GetNumCpus(int *num); 77 | 78 | // Looks for the CPU proc item with the given name for the given CPU number 79 | // and places the string value in result. 80 | virtual bool GetCpuStringValue(int cpu_id, const std::string& key, 81 | std::string *result); 82 | 83 | // Looks for the CPU proc item with the given name for the given CPU number 84 | // and places the int value in result. 85 | virtual bool GetCpuIntValue(int cpu_id, const std::string& key, 86 | int *result); 87 | 88 | private: 89 | ConfigParser::MapVector cpu_info_; 90 | }; 91 | 92 | // Builds a string containing the info from lsb_release on a single line. 93 | std::string ReadLinuxLsbRelease(); 94 | 95 | // Returns the output of "uname". 96 | std::string ReadLinuxUname(); 97 | 98 | } // namespace txmpp 99 | 100 | #endif // LINUX 101 | #endif // _TXMPP_LINUX_H_ 102 | -------------------------------------------------------------------------------- /src/saslcookiemechanism.h: -------------------------------------------------------------------------------- 1 | /* 2 | * libjingle 3 | * Copyright 2004--2005, Google Inc. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions are met: 7 | * 8 | * 1. Redistributions of source code must retain the above copyright notice, 9 | * this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright notice, 11 | * this list of conditions and the following disclaimer in the documentation 12 | * and/or other materials provided with the distribution. 13 | * 3. The name of the author may not be used to endorse or promote products 14 | * derived from this software without specific prior written permission. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED 17 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 18 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO 19 | * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 20 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 21 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 22 | * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 23 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 24 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 25 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | */ 27 | 28 | #ifndef _TXMPP_SASLCOOKIEMECHANISM_H_ 29 | #define _TXMPP_SASLCOOKIEMECHANISM_H_ 30 | 31 | #ifndef NO_CONFIG_H 32 | #include "config.h" 33 | #endif 34 | 35 | #include "constants.h" 36 | #include "qname.h" 37 | #include "saslmechanism.h" 38 | #include "xmlelement.h" 39 | 40 | namespace txmpp { 41 | 42 | class SaslCookieMechanism : public SaslMechanism { 43 | 44 | public: 45 | SaslCookieMechanism(const std::string & mechanism, 46 | const std::string & username, 47 | const std::string & cookie, 48 | const std::string & token_service) 49 | : mechanism_(mechanism), 50 | username_(username), 51 | cookie_(cookie), 52 | token_service_(token_service) {} 53 | 54 | SaslCookieMechanism(const std::string & mechanism, 55 | const std::string & username, 56 | const std::string & cookie) 57 | : mechanism_(mechanism), 58 | username_(username), 59 | cookie_(cookie), 60 | token_service_("") {} 61 | 62 | virtual std::string GetMechanismName() { return mechanism_; } 63 | 64 | virtual XmlElement * StartSaslAuth() { 65 | // send initial request 66 | XmlElement * el = new XmlElement(QN_SASL_AUTH, true); 67 | el->AddAttr(QN_MECHANISM, mechanism_); 68 | if (!token_service_.empty()) { 69 | el->AddAttr( 70 | QName(true, "http://www.google.com/talk/protocol/auth", "service"), 71 | token_service_); 72 | } 73 | 74 | std::string credential; 75 | credential.append("\0", 1); 76 | credential.append(username_); 77 | credential.append("\0", 1); 78 | credential.append(cookie_); 79 | el->AddText(Base64Encode(credential)); 80 | return el; 81 | } 82 | 83 | private: 84 | std::string mechanism_; 85 | std::string username_; 86 | std::string cookie_; 87 | std::string token_service_; 88 | }; 89 | 90 | } // txmpp 91 | 92 | #endif // _TXMPP_SASLCOOKIEMECHANISM_H_ 93 | -------------------------------------------------------------------------------- /src/xmppasyncsocket.h: -------------------------------------------------------------------------------- 1 | /* 2 | * libjingle 3 | * Copyright 2004--2005, Google Inc. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions are met: 7 | * 8 | * 1. Redistributions of source code must retain the above copyright notice, 9 | * this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright notice, 11 | * this list of conditions and the following disclaimer in the documentation 12 | * and/or other materials provided with the distribution. 13 | * 3. The name of the author may not be used to endorse or promote products 14 | * derived from this software without specific prior written permission. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED 17 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 18 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO 19 | * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 20 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 21 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 22 | * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 23 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 24 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 25 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | */ 27 | 28 | #ifndef _TXMPP_XMPPASYNCSOCKET_H_ 29 | #define _TXMPP_XMPPASYNCSOCKET_H_ 30 | 31 | #ifndef NO_CONFIG_H 32 | #include "config.h" 33 | #endif 34 | 35 | #include "sigslot.h" 36 | 37 | namespace txmpp { 38 | 39 | class SocketAddress; 40 | 41 | class XmppAsyncSocket { 42 | public: 43 | enum State { 44 | STATE_CLOSED = 0, //!< Socket is not open. 45 | STATE_CLOSING, //!< Socket is closing but can have buffered data 46 | STATE_CONNECTING, //!< In the process of 47 | STATE_OPEN, //!< Socket is connected 48 | #if defined(FEATURE_ENABLE_SSL) 49 | STATE_TLS_CONNECTING, //!< Establishing TLS connection 50 | STATE_TLS_OPEN, //!< TLS connected 51 | #endif 52 | }; 53 | 54 | enum Error { 55 | ERROR_NONE = 0, //!< No error 56 | ERROR_WINSOCK, //!< Winsock error 57 | ERROR_DNS, //!< Couldn't resolve host name 58 | ERROR_WRONGSTATE, //!< Call made while socket is in the wrong state 59 | #if defined(FEATURE_ENABLE_SSL) 60 | ERROR_SSL, //!< Something went wrong with OpenSSL 61 | #endif 62 | }; 63 | 64 | virtual ~XmppAsyncSocket() {} 65 | virtual State state() = 0; 66 | virtual Error error() = 0; 67 | virtual int GetError() = 0; // winsock error code 68 | 69 | virtual bool Connect(const SocketAddress& addr) = 0; 70 | virtual bool Read(char * data, size_t len, size_t* len_read) = 0; 71 | virtual bool Write(const char * data, size_t len) = 0; 72 | virtual bool Close() = 0; 73 | #if defined(FEATURE_ENABLE_SSL) 74 | // We allow matching any passed domain. 75 | // If both names are passed as empty, we do not require a match. 76 | virtual bool StartTls(const std::string & domainname) = 0; 77 | #endif 78 | 79 | signal0<> SignalConnected; 80 | signal0<> SignalSSLConnected; 81 | signal0<> SignalClosed; 82 | signal0<> SignalRead; 83 | signal0<> SignalError; 84 | }; 85 | 86 | } // namespace txmpp 87 | 88 | #endif // _TXMPP_XMPPASYNCSOCKET_H_ 89 | -------------------------------------------------------------------------------- /src/xmpplogintask.h: -------------------------------------------------------------------------------- 1 | /* 2 | * libjingle 3 | * Copyright 2004--2005, Google Inc. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions are met: 7 | * 8 | * 1. Redistributions of source code must retain the above copyright notice, 9 | * this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright notice, 11 | * this list of conditions and the following disclaimer in the documentation 12 | * and/or other materials provided with the distribution. 13 | * 3. The name of the author may not be used to endorse or promote products 14 | * derived from this software without specific prior written permission. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED 17 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 18 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO 19 | * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 20 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 21 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 22 | * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 23 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 24 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 25 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | */ 27 | 28 | #ifndef _TXMPP_XMPPLOGINTASLK_H_ 29 | #define _TXMPP_XMPPLOGINTASLK_H_ 30 | 31 | #ifndef NO_CONFIG_H 32 | #include "config.h" 33 | #endif 34 | 35 | #include 36 | #include 37 | #include "jid.h" 38 | #include "logging.h" 39 | #include "scoped_ptr.h" 40 | #include "xmppengine.h" 41 | 42 | namespace txmpp { 43 | 44 | class XmlElement; 45 | class XmppEngineImpl; 46 | class SaslMechanism; 47 | 48 | class XmppLoginTask { 49 | 50 | public: 51 | XmppLoginTask(XmppEngineImpl *pctx); 52 | ~XmppLoginTask(); 53 | 54 | bool IsDone() 55 | { return state_ == LOGINSTATE_DONE; } 56 | void IncomingStanza(const XmlElement * element, bool isStart); 57 | void OutgoingStanza(const XmlElement *element); 58 | 59 | private: 60 | enum LoginTaskState { 61 | LOGINSTATE_INIT = 0, 62 | LOGINSTATE_STREAMSTART_SENT, 63 | LOGINSTATE_STARTED_XMPP, 64 | LOGINSTATE_TLS_INIT, 65 | LOGINSTATE_AUTH_INIT, 66 | LOGINSTATE_BIND_INIT, 67 | LOGINSTATE_TLS_REQUESTED, 68 | LOGINSTATE_SASL_RUNNING, 69 | LOGINSTATE_BIND_REQUESTED, 70 | LOGINSTATE_SESSION_REQUESTED, 71 | LOGINSTATE_DONE, 72 | }; 73 | 74 | const XmlElement * NextStanza(); 75 | bool Advance(); 76 | bool HandleStartStream(const XmlElement * element); 77 | bool HandleFeatures(const XmlElement * element); 78 | const XmlElement * GetFeature(const QName & name); 79 | bool Failure(XmppEngine::Error reason); 80 | void FlushQueuedStanzas(); 81 | 82 | XmppEngineImpl * pctx_; 83 | bool authNeeded_; 84 | LoginTaskState state_; 85 | const XmlElement * pelStanza_; 86 | bool isStart_; 87 | std::string iqId_; 88 | scoped_ptr pelFeatures_; 89 | Jid fullJid_; 90 | std::string streamId_; 91 | scoped_ptr > pvecQueuedStanzas_; 92 | 93 | scoped_ptr sasl_mech_; 94 | 95 | #ifdef _DEBUG 96 | static const ConstantLabel LOGINTASK_STATES[]; 97 | #endif // _DEBUG 98 | }; 99 | 100 | } // namespace txmpp 101 | 102 | #endif // _TXMPP_XMPPLOGINTASLK_H_ 103 | -------------------------------------------------------------------------------- /src/taskparent.cc: -------------------------------------------------------------------------------- 1 | /* 2 | * libjingle 3 | * Copyright 2004--2006, Google Inc. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions are met: 7 | * 8 | * 1. Redistributions of source code must retain the above copyright notice, 9 | * this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright notice, 11 | * this list of conditions and the following disclaimer in the documentation 12 | * and/or other materials provided with the distribution. 13 | * 3. The name of the author may not be used to endorse or promote products 14 | * derived from this software without specific prior written permission. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED 17 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 18 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO 19 | * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 20 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 21 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 22 | * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 23 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 24 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 25 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | */ 27 | 28 | #include "taskparent.h" 29 | 30 | #include 31 | 32 | #include "task.h" 33 | #include "taskrunner.h" 34 | 35 | namespace txmpp { 36 | 37 | TaskParent::TaskParent(Task* derived_instance, TaskParent *parent) 38 | : parent_(parent) { 39 | assert(derived_instance); 40 | assert(parent); 41 | runner_ = parent->GetRunner(); 42 | parent_->AddChild(derived_instance); 43 | Initialize(); 44 | } 45 | 46 | TaskParent::TaskParent(TaskRunner *derived_instance) 47 | : parent_(NULL), 48 | runner_(derived_instance) { 49 | assert(derived_instance); 50 | Initialize(); 51 | } 52 | 53 | // Does common initialization of member variables 54 | void TaskParent::Initialize() { 55 | children_.reset(new ChildSet()); 56 | child_error_ = false; 57 | } 58 | 59 | void TaskParent::AddChild(Task *child) { 60 | children_->insert(child); 61 | } 62 | 63 | #ifdef _DEBUG 64 | bool TaskParent::IsChildTask(Task *task) { 65 | assert(task); 66 | return task->parent_ == this && children_->find(task) != children_->end(); 67 | } 68 | #endif 69 | 70 | bool TaskParent::AllChildrenDone() { 71 | for (ChildSet::iterator it = children_->begin(); 72 | it != children_->end(); 73 | ++it) { 74 | if (!(*it)->IsDone()) 75 | return false; 76 | } 77 | return true; 78 | } 79 | 80 | bool TaskParent::AnyChildError() { 81 | return child_error_; 82 | } 83 | 84 | void TaskParent::AbortAllChildren() { 85 | if (children_->size() > 0) { 86 | #ifdef _DEBUG 87 | runner_->IncrementAbortCount(); 88 | #endif 89 | 90 | ChildSet copy = *children_; 91 | for (ChildSet::iterator it = copy.begin(); it != copy.end(); ++it) { 92 | (*it)->Abort(true); // Note we do not wake 93 | } 94 | 95 | #ifdef _DEBUG 96 | runner_->DecrementAbortCount(); 97 | #endif 98 | } 99 | } 100 | 101 | void TaskParent::OnStopped(Task *task) { 102 | AbortAllChildren(); 103 | parent_->OnChildStopped(task); 104 | } 105 | 106 | void TaskParent::OnChildStopped(Task *child) { 107 | if (child->HasError()) 108 | child_error_ = true; 109 | children_->erase(child); 110 | } 111 | 112 | } // namespace txmpp 113 | -------------------------------------------------------------------------------- /src/schanneladapter.h: -------------------------------------------------------------------------------- 1 | /* 2 | * libjingle 3 | * Copyright 2004--2005, Google Inc. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions are met: 7 | * 8 | * 1. Redistributions of source code must retain the above copyright notice, 9 | * this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright notice, 11 | * this list of conditions and the following disclaimer in the documentation 12 | * and/or other materials provided with the distribution. 13 | * 3. The name of the author may not be used to endorse or promote products 14 | * derived from this software without specific prior written permission. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED 17 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 18 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO 19 | * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 20 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 21 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 22 | * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 23 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 24 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 25 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | */ 27 | 28 | #ifndef _TXMPP_SCHANNELADAPTER_H_ 29 | #define _TXMPP_SCHANNELADAPTER_H_ 30 | 31 | #ifndef NO_CONFIG_H 32 | #include "config.h" 33 | #endif 34 | 35 | #include 36 | #include "ssladapter.h" 37 | #include "messagequeue.h" 38 | 39 | struct _SecBufferDesc; 40 | 41 | namespace txmpp { 42 | 43 | /////////////////////////////////////////////////////////////////////////////// 44 | 45 | class SChannelAdapter : public SSLAdapter, public MessageHandler { 46 | public: 47 | SChannelAdapter(AsyncSocket* socket); 48 | virtual ~SChannelAdapter(); 49 | 50 | virtual int StartSSL(const char* hostname, bool restartable); 51 | virtual int Send(const void* pv, size_t cb); 52 | virtual int Recv(void* pv, size_t cb); 53 | virtual int Close(); 54 | 55 | // Note that the socket returns ST_CONNECTING while SSL is being negotiated. 56 | virtual ConnState GetState() const; 57 | 58 | protected: 59 | enum SSLState { 60 | SSL_NONE, SSL_WAIT, SSL_CONNECTING, SSL_CONNECTED, SSL_ERROR 61 | }; 62 | struct SSLImpl; 63 | 64 | virtual void OnConnectEvent(AsyncSocket* socket); 65 | virtual void OnReadEvent(AsyncSocket* socket); 66 | virtual void OnWriteEvent(AsyncSocket* socket); 67 | virtual void OnCloseEvent(AsyncSocket* socket, int err); 68 | virtual void OnMessage(Message* pmsg); 69 | 70 | int BeginSSL(); 71 | int ContinueSSL(); 72 | int ProcessContext(long int status, _SecBufferDesc* sbd_in, 73 | _SecBufferDesc* sbd_out); 74 | int DecryptData(); 75 | 76 | int Read(); 77 | int Flush(); 78 | void Error(const char* context, int err, bool signal = true); 79 | void Cleanup(); 80 | 81 | void PostEvent(); 82 | 83 | private: 84 | SSLState state_; 85 | std::string ssl_host_name_; 86 | // If true, socket will retain SSL configuration after Close. 87 | bool restartable_; 88 | // If true, we are delaying signalling close until all data is read. 89 | bool signal_close_; 90 | // If true, we are waiting to be woken up to signal readability or closure. 91 | bool message_pending_; 92 | SSLImpl* impl_; 93 | }; 94 | 95 | ///////////////////////////////////////////////////////////////////////////// 96 | 97 | } // namespace txmpp 98 | 99 | #endif // _TXMPP_SCHANNELADAPTER_H__ 100 | -------------------------------------------------------------------------------- /src/base64.h: -------------------------------------------------------------------------------- 1 | 2 | //********************************************************************* 3 | //* C_Base64 - a simple base64 encoder and decoder. 4 | //* 5 | //* Copyright (c) 1999, Bob Withers - bwit@pobox.com 6 | //* 7 | //* This code may be freely used for any purpose, either personal 8 | //* or commercial, provided the authors copyright notice remains 9 | //* intact. 10 | //********************************************************************* 11 | 12 | #ifndef TXMPP_BASE64_H__ 13 | #define TXMPP_BASE64_H__ 14 | 15 | #ifndef NO_CONFIG_H 16 | #include "config.h" 17 | #endif 18 | 19 | #include 20 | #include 21 | 22 | namespace txmpp { 23 | 24 | class Base64 25 | { 26 | public: 27 | enum DecodeOption { 28 | DO_PARSE_STRICT = 1, // Parse only base64 characters 29 | DO_PARSE_WHITE = 2, // Parse only base64 and whitespace characters 30 | DO_PARSE_ANY = 3, // Parse all characters 31 | DO_PARSE_MASK = 3, 32 | 33 | DO_PAD_YES = 4, // Padding is required 34 | DO_PAD_ANY = 8, // Padding is optional 35 | DO_PAD_NO = 12, // Padding is disallowed 36 | DO_PAD_MASK = 12, 37 | 38 | DO_TERM_BUFFER = 16, // Must termiante at end of buffer 39 | DO_TERM_CHAR = 32, // May terminate at any character boundary 40 | DO_TERM_ANY = 48, // May terminate at a sub-character bit offset 41 | DO_TERM_MASK = 48, 42 | 43 | // Strictest interpretation 44 | DO_STRICT = DO_PARSE_STRICT | DO_PAD_YES | DO_TERM_BUFFER, 45 | 46 | DO_LAX = DO_PARSE_ANY | DO_PAD_ANY | DO_TERM_CHAR, 47 | }; 48 | typedef int DecodeFlags; 49 | 50 | static bool IsBase64Char(char ch); 51 | 52 | // Determines whether the given string consists entirely of valid base64 53 | // encoded characters. 54 | static bool IsBase64Encoded(const std::string& str); 55 | 56 | static void EncodeFromArray(const void* data, size_t len, 57 | std::string* result); 58 | static bool DecodeFromArray(const char* data, size_t len, DecodeFlags flags, 59 | std::string* result, size_t* data_used); 60 | static bool DecodeFromArray(const char* data, size_t len, DecodeFlags flags, 61 | std::vector* result, size_t* data_used); 62 | 63 | // Convenience Methods 64 | static inline std::string Encode(const std::string& data) { 65 | std::string result; 66 | EncodeFromArray(data.data(), data.size(), &result); 67 | return result; 68 | } 69 | static inline std::string Decode(const std::string& data, DecodeFlags flags) { 70 | std::string result; 71 | DecodeFromArray(data.data(), data.size(), flags, &result, NULL); 72 | return result; 73 | } 74 | static inline bool Decode(const std::string& data, DecodeFlags flags, 75 | std::string* result, size_t* data_used) 76 | { 77 | return DecodeFromArray(data.data(), data.size(), flags, result, data_used); 78 | } 79 | static inline bool Decode(const std::string& data, DecodeFlags flags, 80 | std::vector* result, size_t* data_used) 81 | { 82 | return DecodeFromArray(data.data(), data.size(), flags, result, data_used); 83 | } 84 | 85 | private: 86 | static const std::string Base64Table; 87 | static const unsigned char DecodeTable[]; 88 | 89 | static size_t GetNextQuantum(DecodeFlags parse_flags, bool illegal_pads, 90 | const char* data, size_t len, size_t* dpos, 91 | unsigned char qbuf[4], bool* padded); 92 | template 93 | static bool DecodeFromArrayTemplate(const char* data, size_t len, 94 | DecodeFlags flags, T* result, 95 | size_t* data_used); 96 | }; 97 | 98 | } // namespace txmpp 99 | 100 | #endif // TXMPP_BASE64_H_ 101 | -------------------------------------------------------------------------------- /src/winping.h: -------------------------------------------------------------------------------- 1 | /* 2 | * libjingle 3 | * Copyright 2004--2005, Google Inc. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions are met: 7 | * 8 | * 1. Redistributions of source code must retain the above copyright notice, 9 | * this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright notice, 11 | * this list of conditions and the following disclaimer in the documentation 12 | * and/or other materials provided with the distribution. 13 | * 3. The name of the author may not be used to endorse or promote products 14 | * derived from this software without specific prior written permission. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED 17 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 18 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO 19 | * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 20 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 21 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 22 | * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 23 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 24 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 25 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | */ 27 | 28 | #ifndef _TXMPP_WINPING_H_ 29 | #define _TXMPP_WINPING_H_ 30 | 31 | #ifndef NO_CONFIG_H 32 | #include "config.h" 33 | #endif 34 | 35 | #ifdef WIN32 36 | 37 | #include "win32.h" 38 | #include "basictypes.h" 39 | 40 | namespace txmpp { 41 | 42 | // This class wraps a Win32 API for doing ICMP pinging. This API, unlike the 43 | // the normal socket APIs (as implemented on Win9x), will return an error if 44 | // an ICMP packet with the dont-fragment bit set is too large. This means this 45 | // class can be used to detect the MTU to a given address. 46 | 47 | typedef struct ip_option_information { 48 | UCHAR Ttl; // Time To Live 49 | UCHAR Tos; // Type Of Service 50 | UCHAR Flags; // IP header flags 51 | UCHAR OptionsSize; // Size in bytes of options data 52 | PUCHAR OptionsData; // Pointer to options data 53 | } IP_OPTION_INFORMATION, * PIP_OPTION_INFORMATION; 54 | 55 | typedef HANDLE (WINAPI *PIcmpCreateFile)(); 56 | 57 | typedef BOOL (WINAPI *PIcmpCloseHandle)(HANDLE icmp_handle); 58 | 59 | typedef DWORD (WINAPI *PIcmpSendEcho)( 60 | HANDLE IcmpHandle, 61 | ULONG DestinationAddress, 62 | LPVOID RequestData, 63 | WORD RequestSize, 64 | PIP_OPTION_INFORMATION RequestOptions, 65 | LPVOID ReplyBuffer, 66 | DWORD ReplySize, 67 | DWORD Timeout); 68 | 69 | class WinPing { 70 | public: 71 | WinPing(); 72 | ~WinPing(); 73 | 74 | // Determines whether the class was initialized correctly. 75 | bool IsValid() { return valid_; } 76 | 77 | // Attempts to send a ping with the given parameters. 78 | enum PingResult { PING_FAIL, PING_TOO_LARGE, PING_TIMEOUT, PING_SUCCESS }; 79 | PingResult Ping( 80 | uint32 ip, uint32 data_size, uint32 timeout_millis, uint8 ttl, 81 | bool allow_fragments); 82 | 83 | private: 84 | HMODULE dll_; 85 | HANDLE hping_; 86 | PIcmpCreateFile create_; 87 | PIcmpCloseHandle close_; 88 | PIcmpSendEcho send_; 89 | char* data_; 90 | uint32 dlen_; 91 | char* reply_; 92 | uint32 rlen_; 93 | bool valid_; 94 | }; 95 | 96 | } // namespace txmpp 97 | 98 | #endif // WIN32 99 | 100 | #endif // _TXMPP_WINPING_H_ 101 | -------------------------------------------------------------------------------- /src/xmppstanzaparser.h: -------------------------------------------------------------------------------- 1 | /* 2 | * libjingle 3 | * Copyright 2004--2005, Google Inc. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions are met: 7 | * 8 | * 1. Redistributions of source code must retain the above copyright notice, 9 | * this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright notice, 11 | * this list of conditions and the following disclaimer in the documentation 12 | * and/or other materials provided with the distribution. 13 | * 3. The name of the author may not be used to endorse or promote products 14 | * derived from this software without specific prior written permission. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED 17 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 18 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO 19 | * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 20 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 21 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 22 | * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 23 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 24 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 25 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | */ 27 | 28 | #ifndef _TXMPP_XMPPSTANZAPARSER_H_ 29 | #define _TXMPP_XMPPSTANZAPARSER_H_ 30 | 31 | #ifndef NO_CONFIG_H 32 | #include "config.h" 33 | #endif 34 | 35 | #include "xmlbuilder.h" 36 | #include "xmlparser.h" 37 | 38 | namespace txmpp { 39 | 40 | class XmlElement; 41 | 42 | class XmppStanzaParseHandler { 43 | public: 44 | virtual ~XmppStanzaParseHandler() {} 45 | virtual void StartStream(const XmlElement * pelStream) = 0; 46 | virtual void Stanza(const XmlElement * pelStanza) = 0; 47 | virtual void EndStream() = 0; 48 | virtual void XmlError() = 0; 49 | }; 50 | 51 | class XmppStanzaParser { 52 | public: 53 | XmppStanzaParser(XmppStanzaParseHandler *psph); 54 | bool Parse(const char * data, size_t len, bool isFinal) 55 | { return parser_.Parse(data, len, isFinal); } 56 | void Reset(); 57 | 58 | private: 59 | class ParseHandler : public XmlParseHandler { 60 | public: 61 | ParseHandler(XmppStanzaParser * outer) : outer_(outer) {} 62 | virtual void StartElement(XmlParseContext * pctx, 63 | const char * name, const char ** atts) 64 | { outer_->IncomingStartElement(pctx, name, atts); } 65 | virtual void EndElement(XmlParseContext * pctx, 66 | const char * name) 67 | { outer_->IncomingEndElement(pctx, name); } 68 | virtual void CharacterData(XmlParseContext * pctx, 69 | const char * text, int len) 70 | { outer_->IncomingCharacterData(pctx, text, len); } 71 | virtual void Error(XmlParseContext * pctx, 72 | XML_Error errCode) 73 | { outer_->IncomingError(pctx, errCode); } 74 | private: 75 | XmppStanzaParser * const outer_; 76 | }; 77 | 78 | friend class ParseHandler; 79 | 80 | void IncomingStartElement(XmlParseContext * pctx, 81 | const char * name, const char ** atts); 82 | void IncomingEndElement(XmlParseContext * pctx, 83 | const char * name); 84 | void IncomingCharacterData(XmlParseContext * pctx, 85 | const char * text, int len); 86 | void IncomingError(XmlParseContext * pctx, 87 | XML_Error errCode); 88 | 89 | XmppStanzaParseHandler * psph_; 90 | ParseHandler innerHandler_; 91 | XmlParser parser_; 92 | int depth_; 93 | XmlBuilder builder_; 94 | 95 | }; 96 | 97 | } // namespace txmpp 98 | 99 | #endif // _TXMPP_XMPPSTANZAPARSER_H_ 100 | -------------------------------------------------------------------------------- /src/sslsocketfactory.h: -------------------------------------------------------------------------------- 1 | /* 2 | * libjingle 3 | * Copyright 2007, Google Inc. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions are met: 7 | * 8 | * 1. Redistributions of source code must retain the above copyright notice, 9 | * this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright notice, 11 | * this list of conditions and the following disclaimer in the documentation 12 | * and/or other materials provided with the distribution. 13 | * 3. The name of the author may not be used to endorse or promote products 14 | * derived from this software without specific prior written permission. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED 17 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 18 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO 19 | * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 20 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 21 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 22 | * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 23 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 24 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 25 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | */ 27 | 28 | #ifndef _TXMPP_SSLSOCKETFACTORY_H_ 29 | #define _TXMPP_SSLSOCKETFACTORY_H_ 30 | 31 | #ifndef NO_CONFIG_H 32 | #include "config.h" 33 | #endif 34 | 35 | #include "logging.h" 36 | #include "proxyinfo.h" 37 | #include "socketserver.h" 38 | 39 | namespace txmpp { 40 | 41 | /////////////////////////////////////////////////////////////////////////////// 42 | // SslSocketFactory 43 | /////////////////////////////////////////////////////////////////////////////// 44 | 45 | class SslSocketFactory : public SocketFactory { 46 | public: 47 | SslSocketFactory(SocketFactory* factory, const std::string& user_agent) 48 | : factory_(factory), agent_(user_agent), autodetect_proxy_(true), 49 | force_connect_(false), logging_level_(LS_VERBOSE), binary_mode_(false) { 50 | } 51 | 52 | void SetAutoDetectProxy() { 53 | autodetect_proxy_ = true; 54 | } 55 | void SetForceConnect(bool force) { 56 | force_connect_ = force; 57 | } 58 | void SetProxy(const ProxyInfo& proxy) { 59 | autodetect_proxy_ = false; 60 | proxy_ = proxy; 61 | } 62 | bool autodetect_proxy() const { return autodetect_proxy_; } 63 | const ProxyInfo& proxy() const { return proxy_; } 64 | 65 | void UseSSL(const char* hostname) { hostname_ = hostname; } 66 | void DisableSSL() { hostname_.clear(); } 67 | void SetIgnoreBadCert(bool ignore) { ignore_bad_cert_ = ignore; } 68 | bool ignore_bad_cert() const { return ignore_bad_cert_; } 69 | 70 | void SetLogging(LoggingSeverity level, const std::string& label, 71 | bool binary_mode = false) { 72 | logging_level_ = level; 73 | logging_label_ = label; 74 | binary_mode_ = binary_mode; 75 | } 76 | 77 | // SocketFactory Interface 78 | virtual Socket* CreateSocket(int type); 79 | virtual AsyncSocket* CreateAsyncSocket(int type); 80 | 81 | private: 82 | friend class ProxySocketAdapter; 83 | AsyncSocket* CreateProxySocket(const ProxyInfo& proxy, int type); 84 | 85 | SocketFactory* factory_; 86 | std::string agent_; 87 | bool autodetect_proxy_, force_connect_; 88 | ProxyInfo proxy_; 89 | std::string hostname_, logging_label_; 90 | LoggingSeverity logging_level_; 91 | bool binary_mode_; 92 | bool ignore_bad_cert_; 93 | }; 94 | 95 | /////////////////////////////////////////////////////////////////////////////// 96 | 97 | } // namespace txmpp 98 | 99 | #endif // _TXMPP_SSLSOCKETFACTORY_H_ 100 | -------------------------------------------------------------------------------- /src/Equifax_Secure_Global_eBusiness_CA-1.h: -------------------------------------------------------------------------------- 1 | // This file is the Equifax Secure global eBusiness CA-1 certificate 2 | // in C form. 3 | 4 | // It was generated with the following command line: 5 | // > openssl x509 -in Equifax_Secure_Global_eBusiness_CA-1.cer -noout -C 6 | 7 | // The certificate was retrieved from: 8 | // http://www.geotrust.com/resources/root_certificates/certificates/Equifax_Secure_Global_eBusiness_CA-1.cer 9 | 10 | /* subject:/C=US/O=Equifax Secure Inc./CN=Equifax Secure Global eBusiness CA-1 */ 11 | /* issuer :/C=US/O=Equifax Secure Inc./CN=Equifax Secure Global eBusiness CA-1 */ 12 | unsigned char EquifaxSecureGlobalEBusinessCA1_certificate[660]={ 13 | 0x30,0x82,0x02,0x90,0x30,0x82,0x01,0xF9,0xA0,0x03,0x02,0x01,0x02,0x02,0x01,0x01, 14 | 0x30,0x0D,0x06,0x09,0x2A,0x86,0x48,0x86,0xF7,0x0D,0x01,0x01,0x04,0x05,0x00,0x30, 15 | 0x5A,0x31,0x0B,0x30,0x09,0x06,0x03,0x55,0x04,0x06,0x13,0x02,0x55,0x53,0x31,0x1C, 16 | 0x30,0x1A,0x06,0x03,0x55,0x04,0x0A,0x13,0x13,0x45,0x71,0x75,0x69,0x66,0x61,0x78, 17 | 0x20,0x53,0x65,0x63,0x75,0x72,0x65,0x20,0x49,0x6E,0x63,0x2E,0x31,0x2D,0x30,0x2B, 18 | 0x06,0x03,0x55,0x04,0x03,0x13,0x24,0x45,0x71,0x75,0x69,0x66,0x61,0x78,0x20,0x53, 19 | 0x65,0x63,0x75,0x72,0x65,0x20,0x47,0x6C,0x6F,0x62,0x61,0x6C,0x20,0x65,0x42,0x75, 20 | 0x73,0x69,0x6E,0x65,0x73,0x73,0x20,0x43,0x41,0x2D,0x31,0x30,0x1E,0x17,0x0D,0x39, 21 | 0x39,0x30,0x36,0x32,0x31,0x30,0x34,0x30,0x30,0x30,0x30,0x5A,0x17,0x0D,0x32,0x30, 22 | 0x30,0x36,0x32,0x31,0x30,0x34,0x30,0x30,0x30,0x30,0x5A,0x30,0x5A,0x31,0x0B,0x30, 23 | 0x09,0x06,0x03,0x55,0x04,0x06,0x13,0x02,0x55,0x53,0x31,0x1C,0x30,0x1A,0x06,0x03, 24 | 0x55,0x04,0x0A,0x13,0x13,0x45,0x71,0x75,0x69,0x66,0x61,0x78,0x20,0x53,0x65,0x63, 25 | 0x75,0x72,0x65,0x20,0x49,0x6E,0x63,0x2E,0x31,0x2D,0x30,0x2B,0x06,0x03,0x55,0x04, 26 | 0x03,0x13,0x24,0x45,0x71,0x75,0x69,0x66,0x61,0x78,0x20,0x53,0x65,0x63,0x75,0x72, 27 | 0x65,0x20,0x47,0x6C,0x6F,0x62,0x61,0x6C,0x20,0x65,0x42,0x75,0x73,0x69,0x6E,0x65, 28 | 0x73,0x73,0x20,0x43,0x41,0x2D,0x31,0x30,0x81,0x9F,0x30,0x0D,0x06,0x09,0x2A,0x86, 29 | 0x48,0x86,0xF7,0x0D,0x01,0x01,0x01,0x05,0x00,0x03,0x81,0x8D,0x00,0x30,0x81,0x89, 30 | 0x02,0x81,0x81,0x00,0xBA,0xE7,0x17,0x90,0x02,0x65,0xB1,0x34,0x55,0x3C,0x49,0xC2, 31 | 0x51,0xD5,0xDF,0xA7,0xD1,0x37,0x8F,0xD1,0xE7,0x81,0x73,0x41,0x52,0x60,0x9B,0x9D, 32 | 0xA1,0x17,0x26,0x78,0xAD,0xC7,0xB1,0xE8,0x26,0x94,0x32,0xB5,0xDE,0x33,0x8D,0x3A, 33 | 0x2F,0xDB,0xF2,0x9A,0x7A,0x5A,0x73,0x98,0xA3,0x5C,0xE9,0xFB,0x8A,0x73,0x1B,0x5C, 34 | 0xE7,0xC3,0xBF,0x80,0x6C,0xCD,0xA9,0xF4,0xD6,0x2B,0xC0,0xF7,0xF9,0x99,0xAA,0x63, 35 | 0xA2,0xB1,0x47,0x02,0x0F,0xD4,0xE4,0x51,0x3A,0x12,0x3C,0x6C,0x8A,0x5A,0x54,0x84, 36 | 0x70,0xDB,0xC1,0xC5,0x90,0xCF,0x72,0x45,0xCB,0xA8,0x59,0xC0,0xCD,0x33,0x9D,0x3F, 37 | 0xA3,0x96,0xEB,0x85,0x33,0x21,0x1C,0x3E,0x1E,0x3E,0x60,0x6E,0x76,0x9C,0x67,0x85, 38 | 0xC5,0xC8,0xC3,0x61,0x02,0x03,0x01,0x00,0x01,0xA3,0x66,0x30,0x64,0x30,0x11,0x06, 39 | 0x09,0x60,0x86,0x48,0x01,0x86,0xF8,0x42,0x01,0x01,0x04,0x04,0x03,0x02,0x00,0x07, 40 | 0x30,0x0F,0x06,0x03,0x55,0x1D,0x13,0x01,0x01,0xFF,0x04,0x05,0x30,0x03,0x01,0x01, 41 | 0xFF,0x30,0x1F,0x06,0x03,0x55,0x1D,0x23,0x04,0x18,0x30,0x16,0x80,0x14,0xBE,0xA8, 42 | 0xA0,0x74,0x72,0x50,0x6B,0x44,0xB7,0xC9,0x23,0xD8,0xFB,0xA8,0xFF,0xB3,0x57,0x6B, 43 | 0x68,0x6C,0x30,0x1D,0x06,0x03,0x55,0x1D,0x0E,0x04,0x16,0x04,0x14,0xBE,0xA8,0xA0, 44 | 0x74,0x72,0x50,0x6B,0x44,0xB7,0xC9,0x23,0xD8,0xFB,0xA8,0xFF,0xB3,0x57,0x6B,0x68, 45 | 0x6C,0x30,0x0D,0x06,0x09,0x2A,0x86,0x48,0x86,0xF7,0x0D,0x01,0x01,0x04,0x05,0x00, 46 | 0x03,0x81,0x81,0x00,0x30,0xE2,0x01,0x51,0xAA,0xC7,0xEA,0x5F,0xDA,0xB9,0xD0,0x65, 47 | 0x0F,0x30,0xD6,0x3E,0xDA,0x0D,0x14,0x49,0x6E,0x91,0x93,0x27,0x14,0x31,0xEF,0xC4, 48 | 0xF7,0x2D,0x45,0xF8,0xEC,0xC7,0xBF,0xA2,0x41,0x0D,0x23,0xB4,0x92,0xF9,0x19,0x00, 49 | 0x67,0xBD,0x01,0xAF,0xCD,0xE0,0x71,0xFC,0x5A,0xCF,0x64,0xC4,0xE0,0x96,0x98,0xD0, 50 | 0xA3,0x40,0xE2,0x01,0x8A,0xEF,0x27,0x07,0xF1,0x65,0x01,0x8A,0x44,0x2D,0x06,0x65, 51 | 0x75,0x52,0xC0,0x86,0x10,0x20,0x21,0x5F,0x6C,0x6B,0x0F,0x6C,0xAE,0x09,0x1C,0xAF, 52 | 0xF2,0xA2,0x18,0x34,0xC4,0x75,0xA4,0x73,0x1C,0xF1,0x8D,0xDC,0xEF,0xAD,0xF9,0xB3, 53 | 0x76,0xB4,0x92,0xBF,0xDC,0x95,0x10,0x1E,0xBE,0xCB,0xC8,0x3B,0x5A,0x84,0x60,0x19, 54 | 0x56,0x94,0xA9,0x55, 55 | }; 56 | -------------------------------------------------------------------------------- /src/sslidentity.h: -------------------------------------------------------------------------------- 1 | /* 2 | * libjingle 3 | * Copyright 2004--2008, Google Inc. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions are met: 7 | * 8 | * 1. Redistributions of source code must retain the above copyright notice, 9 | * this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright notice, 11 | * this list of conditions and the following disclaimer in the documentation 12 | * and/or other materials provided with the distribution. 13 | * 3. The name of the author may not be used to endorse or promote products 14 | * derived from this software without specific prior written permission. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED 17 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 18 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO 19 | * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 20 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 21 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 22 | * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 23 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 24 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 25 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | */ 27 | 28 | // Handling of certificates and keypairs for SSLStreamAdapter's peer mode. 29 | 30 | #ifndef _TXMPP_SSLIDENTITY_H_ 31 | #define _TXMPP_SSLIDENTITY_H_ 32 | 33 | #ifndef NO_CONFIG_H 34 | #include "config.h" 35 | #endif 36 | 37 | #include 38 | 39 | namespace txmpp { 40 | 41 | // Abstract interface overridden by SSL library specific 42 | // implementations. 43 | 44 | // A somewhat opaque type used to encapsulate a certificate. 45 | // Wraps the SSL library's notion of a certificate, with reference counting. 46 | // The SSLCertificate object is pretty much immutable once created. 47 | // (The OpenSSL implementation only does reference counting and 48 | // possibly caching of intermediate results.) 49 | class SSLCertificate { 50 | public: 51 | // Parses and build a certificate from a PEM encoded string. 52 | // Returns NULL on failure. 53 | // The length of the string representation of the certificate is 54 | // stored in *pem_length if it is non-NULL, and only if 55 | // parsing was successful. 56 | // Caller is responsible for freeing the returned object. 57 | static SSLCertificate* FromPEMString(const std::string& pem_string, 58 | int* pem_length); 59 | virtual ~SSLCertificate() {} 60 | 61 | // Returns a new SSLCertificate object instance wrapping the same 62 | // underlying certificate. 63 | // Caller is responsible for freeing the returned object. 64 | virtual SSLCertificate* GetReference() = 0; 65 | 66 | // Returns a PEM encoded string representation of the certificate. 67 | virtual std::string ToPEMString() const = 0; 68 | }; 69 | 70 | // Our identity in an SSL negotiation: a keypair and certificate (both 71 | // with the same public key). 72 | // This too is pretty much immutable once created. 73 | class SSLIdentity { 74 | public: 75 | // Generates an identity (keypair and self-signed certificate). If 76 | // common_name is non-empty, it will be used for the certificate's 77 | // subject and issuer name, otherwise a random string will be used. 78 | // Returns NULL on failure. 79 | // Caller is responsible for freeing the returned object. 80 | static SSLIdentity* Generate(const std::string& common_name); 81 | 82 | virtual ~SSLIdentity() {} 83 | 84 | // Returns a new SSLIdentity object instance wrapping the same 85 | // identity information. 86 | // Caller is responsible for freeing the returned object. 87 | virtual SSLIdentity* GetReference() = 0; 88 | 89 | // Returns a temporary reference to the certificate. 90 | virtual SSLCertificate& certificate() const = 0; 91 | }; 92 | 93 | } // namespace txmpp 94 | 95 | #endif // _TXMPP_SSLIDENTITY_H_ 96 | --------------------------------------------------------------------------------