├── .dockerignore ├── .github ├── dependabot.yml ├── gcc.json └── workflows │ ├── main.yml │ └── publish.yml ├── .gitignore ├── CMakeLists.txt ├── ChangeLog.md ├── Dockerfile ├── Dockerfile.trixie ├── README.md ├── backends ├── CMakeLists.txt ├── frotz │ ├── CMakeLists.txt │ ├── dfrotz │ │ ├── CMakeLists.txt │ │ ├── README │ │ ├── common │ │ │ ├── buffer.c │ │ │ ├── err.c │ │ │ ├── fastmem.c │ │ │ ├── files.c │ │ │ ├── frotz.h │ │ │ ├── getopt.c │ │ │ ├── hotkey.c │ │ │ ├── input.c │ │ │ ├── main.c │ │ │ ├── math.c │ │ │ ├── object.c │ │ │ ├── process.c │ │ │ ├── quetzal.c │ │ │ ├── random.c │ │ │ ├── redirect.c │ │ │ ├── screen.c │ │ │ ├── setup.h │ │ │ ├── sound.c │ │ │ ├── stream.c │ │ │ ├── table.c │ │ │ ├── text.c │ │ │ └── variable.c │ │ └── dumb │ │ │ ├── dumb_frotz.h │ │ │ ├── dumb_init.c │ │ │ ├── dumb_input.c │ │ │ ├── dumb_output.c │ │ │ └── dumb_pic.c │ └── main.cpp ├── libcommuni │ ├── CMakeLists.txt │ ├── backports.h │ ├── ircnetworkplugin.cpp │ ├── ircnetworkplugin.h │ ├── main.cpp │ ├── session.cpp │ └── session.h ├── libpurple │ ├── CMakeLists.txt │ ├── gen_dynamic_purple.py │ ├── geventloop.cpp │ ├── geventloop.h │ ├── main.cpp │ ├── purple_defs.cpp │ ├── purple_defs.h │ ├── sample_client.cfg │ ├── utils.cpp │ └── utils.h ├── smstools3 │ ├── CMakeLists.txt │ └── main.cpp ├── swiften │ ├── CMakeLists.txt │ └── main.cpp └── template │ ├── CMakeLists.txt │ ├── README.md │ ├── main.cpp │ ├── plugin.cpp │ └── plugin.h ├── cmake_modules ├── FindBoost.cmake ├── FindCommuni.cmake ├── FindCppUnit.cmake ├── FindGLIB2.cmake ├── FindJsonCpp.cmake ├── FindPROTOBUF.cmake ├── FindSwiften.cmake ├── Findevent.cmake ├── Findlog4cxx.cmake ├── Findmysql.cmake ├── Findopenssl.cmake ├── Findpopt.cmake ├── Findpqxx.cmake ├── Findpurple.cmake └── Findsqlite3.cmake ├── docker-compose.yml ├── docs ├── CMakeLists.txt └── api │ ├── CMakeLists.txt │ └── Doxyfile.in ├── include ├── CMakeLists.txt ├── Swiften │ ├── Elements │ │ ├── AttentionPayload.cpp │ │ ├── AttentionPayload.h │ │ ├── GatewayPayload.cpp │ │ ├── GatewayPayload.h │ │ ├── HintPayload.cpp │ │ ├── HintPayload.h │ │ ├── InvisiblePayload.cpp │ │ ├── InvisiblePayload.h │ │ ├── Privilege.cpp │ │ ├── Privilege.h │ │ ├── SpectrumErrorPayload.cpp │ │ ├── SpectrumErrorPayload.h │ │ ├── StatsPayload.cpp │ │ ├── StatsPayload.h │ │ ├── XHTMLIMPayload.cpp │ │ └── XHTMLIMPayload.h │ ├── Network │ │ ├── DummyConnectionServer.cpp │ │ ├── DummyConnectionServer.h │ │ ├── DummyConnectionServerFactory.cpp │ │ ├── DummyConnectionServerFactory.h │ │ ├── DummyNetworkFactories.cpp │ │ └── DummyNetworkFactories.h │ ├── Parser │ │ ├── PayloadParsers │ │ │ ├── AttentionParser.cpp │ │ │ ├── AttentionParser.h │ │ │ ├── GatewayPayloadParser.cpp │ │ │ ├── GatewayPayloadParser.h │ │ │ ├── HintPayloadParser.cpp │ │ │ ├── HintPayloadParser.h │ │ │ ├── InvisibleParser.cpp │ │ │ ├── InvisibleParser.h │ │ │ ├── MUCPayloadParser.cpp │ │ │ ├── MUCPayloadParser.h │ │ │ ├── PrivilegeParser.cpp │ │ │ ├── PrivilegeParser.h │ │ │ ├── StatsParser.cpp │ │ │ ├── StatsParser.h │ │ │ ├── XHTMLIMParser.cpp │ │ │ └── XHTMLIMParser.h │ │ ├── StringTreeParser.cpp │ │ └── StringTreeParser.h │ ├── Serializer │ │ └── PayloadSerializers │ │ │ ├── AttentionSerializer.cpp │ │ │ ├── AttentionSerializer.h │ │ │ ├── GatewayPayloadSerializer.cpp │ │ │ ├── GatewayPayloadSerializer.h │ │ │ ├── HintPayloadSerializer.cpp │ │ │ ├── HintPayloadSerializer.h │ │ │ ├── InvisibleSerializer.cpp │ │ │ ├── InvisibleSerializer.h │ │ │ ├── PrivilegeSerializer.cpp │ │ │ ├── PrivilegeSerializer.h │ │ │ ├── SpectrumErrorSerializer.cpp │ │ │ ├── SpectrumErrorSerializer.h │ │ │ ├── StatsSerializer.cpp │ │ │ ├── StatsSerializer.h │ │ │ ├── XHTMLIMSerializer.cpp │ │ │ └── XHTMLIMSerializer.h │ ├── Server │ │ ├── Server.cpp │ │ ├── Server.h │ │ ├── ServerFromClientSession.cpp │ │ ├── ServerFromClientSession.h │ │ ├── ServerSession.cpp │ │ ├── ServerSession.h │ │ ├── ServerStanzaChannel.cpp │ │ ├── ServerStanzaChannel.h │ │ ├── ServerStanzaRouter.cpp │ │ ├── ServerStanzaRouter.h │ │ ├── SimpleUserRegistry.cpp │ │ ├── SimpleUserRegistry.h │ │ ├── UserRegistry.cpp │ │ └── UserRegistry.h │ ├── StreamStack │ │ ├── TLSServerLayer.cpp │ │ └── TLSServerLayer.h │ └── TLS │ │ ├── OpenSSL │ │ ├── OpenSSLServerContext.cpp │ │ ├── OpenSSLServerContext.h │ │ ├── OpenSSLServerContextFactory.cpp │ │ └── OpenSSLServerContextFactory.h │ │ ├── Schannel │ │ ├── SchannelServerContext.cpp │ │ ├── SchannelServerContext.h │ │ ├── SchannelServerContextFactory.cpp │ │ └── SchannelServerContextFactory.h │ │ ├── SecureTransport │ │ ├── SecureTransportServerContext.h │ │ └── SecureTransportServerContext.mm │ │ ├── TLSServerContext.cpp │ │ ├── TLSServerContext.h │ │ ├── TLSServerContextFactory.cpp │ │ └── TLSServerContextFactory.h └── transport │ ├── AdminInterface.h │ ├── AdminInterfaceCommand.h │ ├── Buddy.h │ ├── CMakeLists.txt │ ├── Config.h │ ├── Conversation.h │ ├── ConversationManager.h │ ├── Factory.h │ ├── Frontend.h │ ├── HTTPRequest.h │ ├── HTTPRequestQueue.h │ ├── LocalBuddy.h │ ├── Logging.h │ ├── MemoryUsage.h │ ├── MySQLBackend.h │ ├── NetworkPlugin.h │ ├── NetworkPluginServer.h │ ├── OAuth2.h │ ├── PQXXBackend.h │ ├── PresenceOracle.h │ ├── RosterManager.h │ ├── RosterStorage.h │ ├── SQLite3Backend.h │ ├── StorageBackend.h │ ├── ThreadPool.h │ ├── Transport.h │ ├── User.h │ ├── UserManager.h │ ├── UserRegistration.h │ ├── UserRegistry.h │ ├── UsersReconnecter.h │ ├── Util.h │ ├── WebSocketClient.h │ ├── protocol.proto │ ├── utf8.h │ └── utf8 │ ├── checked.h │ ├── core.h │ └── unchecked.h ├── libtransport ├── AdminInterface.cpp ├── AdminInterfaceCommand.cpp ├── Buddy.cpp ├── CMakeLists.txt ├── Conversation.cpp ├── ConversationManager.cpp ├── HTTPRequest.cpp ├── HTTPRequestQueue.cpp ├── LocalBuddy.cpp ├── MySQLBackend.cpp ├── NetworkPluginServer.cpp ├── OAuth2.cpp ├── PQXXBackend.cpp ├── PresenceOracle.cpp ├── RosterManager.cpp ├── RosterStorage.cpp ├── SQLite3Backend.cpp ├── StorageBackend.cpp ├── ThreadPool.cpp ├── Transport.cpp ├── User.cpp ├── UserManager.cpp ├── UserRegistration.cpp ├── UserRegistry.cpp ├── UsersReconnecter.cpp ├── WebSocketClient.cpp └── transport.pc.in ├── munin └── spectrum2_ ├── packaging ├── debian │ ├── build_spectrum2.sh │ └── debian │ │ ├── README.Debian │ │ ├── changelog │ │ ├── compat │ │ ├── control │ │ ├── copyright │ │ ├── libtransport-dev.install │ │ ├── libtransport-plugin2.0.install │ │ ├── libtransport2.0.install │ │ ├── rules │ │ ├── source │ │ └── format │ │ ├── spectrum2-backend-frotz.install │ │ ├── spectrum2-backend-frotz.links │ │ ├── spectrum2-backend-libcommuni.install │ │ ├── spectrum2-backend-libcommuni.links │ │ ├── spectrum2-backend-libpurple.install │ │ ├── spectrum2-backend-libpurple.links │ │ ├── spectrum2-backend-smstools3.install │ │ ├── spectrum2-backend-smstools3.links │ │ ├── spectrum2-backend-swiften.install │ │ ├── spectrum2-backend-swiften.links │ │ ├── spectrum2.init │ │ ├── spectrum2.install │ │ └── spectrum2.service ├── docker │ ├── Dockerfile.alpine │ └── run.sh ├── fedora │ ├── build_rpm.sh │ ├── build_tarball.sh │ ├── spectrum2.init │ └── spectrum2.spec └── logo │ ├── logo.png │ ├── logo.svg │ ├── logo128.png │ ├── logo512.png │ ├── logo64.png │ └── logo_black.png ├── plugin ├── CMakeLists.txt ├── cpp │ ├── CMakeLists.txt │ ├── Config.cpp │ ├── Logging.cpp │ ├── MemoryUsage.cpp │ ├── Util.cpp │ └── networkplugin.cpp └── python │ ├── CMakeLists.txt │ └── NetworkPlugin.py ├── spectrum ├── CMakeLists.txt └── src │ ├── CMakeLists.txt │ ├── backend-logging.cfg │ ├── frontends │ ├── CMakeLists.txt │ ├── slack │ │ ├── CMakeLists.txt │ │ ├── SlackAPI.cpp │ │ ├── SlackAPI.h │ │ ├── SlackFrontend.cpp │ │ ├── SlackFrontend.h │ │ ├── SlackFrontendPlugin.cpp │ │ ├── SlackFrontendPlugin.h │ │ ├── SlackIdManager.cpp │ │ ├── SlackIdManager.h │ │ ├── SlackRTM.cpp │ │ ├── SlackRTM.h │ │ ├── SlackRosterManager.cpp │ │ ├── SlackRosterManager.h │ │ ├── SlackSession.cpp │ │ ├── SlackSession.h │ │ ├── SlackUser.cpp │ │ ├── SlackUser.h │ │ ├── SlackUserManager.cpp │ │ ├── SlackUserManager.h │ │ ├── SlackUserRegistration.cpp │ │ └── SlackUserRegistration.h │ └── xmpp │ │ ├── CMakeLists.txt │ │ ├── RosterResponder.h │ │ ├── XMPPFrontend.cpp │ │ ├── XMPPFrontend.h │ │ ├── XMPPFrontendPlugin.cpp │ │ ├── XMPPFrontendPlugin.h │ │ ├── XMPPRosterManager.cpp │ │ ├── XMPPRosterManager.h │ │ ├── XMPPUser.cpp │ │ ├── XMPPUser.h │ │ ├── XMPPUserManager.cpp │ │ ├── XMPPUserManager.h │ │ ├── XMPPUserRegistration.cpp │ │ ├── XMPPUserRegistration.h │ │ ├── adhoccommand.cpp │ │ ├── adhoccommand.h │ │ ├── adhoccommandfactory.h │ │ ├── adhocmanager.cpp │ │ ├── adhocmanager.h │ │ ├── blockresponder.cpp │ │ ├── blockresponder.h │ │ ├── carbonresponder.cpp │ │ ├── carbonresponder.h │ │ ├── discoinforesponder.cpp │ │ ├── discoinforesponder.h │ │ ├── discoitemsresponder.cpp │ │ ├── discoitemsresponder.h │ │ ├── formutils.cpp │ │ ├── formutils.h │ │ ├── gatewayresponder.cpp │ │ ├── gatewayresponder.h │ │ ├── rosterresponder.cpp │ │ ├── settingsadhoccommand.cpp │ │ ├── settingsadhoccommand.h │ │ ├── statsresponder.cpp │ │ ├── statsresponder.h │ │ ├── storageparser.cpp │ │ ├── storageparser.h │ │ ├── storageresponder.cpp │ │ ├── storageresponder.h │ │ ├── vcardresponder.cpp │ │ └── vcardresponder.h │ ├── logging.cfg │ ├── main.cpp │ ├── manager-logging.cfg │ ├── sample.cfg │ ├── sample2.cfg │ ├── sample2_gateway.cfg │ ├── server.p12 │ └── win32 │ ├── ServiceWrapper.cpp │ └── ServiceWrapper.h ├── spectrum_manager ├── CMakeLists.txt └── src │ ├── CMakeLists.txt │ ├── html │ ├── bootstrap.min.css │ ├── footer.shtml │ ├── form.css │ ├── header.shtml │ ├── instances │ │ ├── index.shtml │ │ └── instance.shtml │ ├── js │ │ ├── app.js │ │ └── config.js │ ├── login │ │ └── index.shtml │ ├── logo.png │ ├── style.css │ └── users │ │ ├── list.shtml │ │ └── register.shtml │ ├── main.cpp │ ├── managerconfig.cpp │ ├── managerconfig.h │ ├── methods.cpp │ ├── methods.h │ ├── server │ ├── APIServer.cpp │ ├── APIServer.h │ ├── mongoose.c │ ├── mongoose.h │ ├── server.cpp │ └── server.h │ └── spectrum_manager.cfg └── tests ├── CMakeLists.txt ├── libcommuni ├── irc_test.cfg ├── irc_test2.cfg ├── muc_away.py ├── muc_change_topic.py ├── muc_echo.py ├── muc_join_leave.py ├── muc_join_nickname_used.py ├── muc_pm.py ├── muc_whois.py └── ngircd.conf ├── libpurple_jabber ├── avatar.py ├── carbons.py ├── jabber_test.cfg ├── logging-backend.cfg ├── logging.cfg ├── manager.conf ├── muc_echo.py ├── muc_join_leave.py ├── muc_pm.py ├── muc_topic.py ├── prefs.xml └── prosody.cfg.lua ├── libtransport ├── AdminInterface.cpp ├── BasicSlackTest.cpp ├── BasicSlackTest.h ├── CMakeLists.txt ├── HTTPRequest.cpp ├── SlackRTM.cpp ├── VCardResponder.cpp ├── basictest.cpp ├── basictest.h ├── component.cpp ├── config.cpp ├── conversationmanager.cpp ├── discoitemsresponder.cpp ├── gatewayresponder.cpp ├── localbuddy.cpp ├── main.cpp ├── main.h ├── networkpluginserver.cpp ├── rostermanager.cpp ├── rosterresponder.cpp ├── settingsadhoccommand.cpp ├── stringtreeparser.cpp ├── user.cpp ├── usermanager.cpp ├── userregistration.cpp ├── userregistry.cpp └── util.cpp ├── prosody ├── configuration │ └── prosody.cfg.lua └── data │ └── .gitignore ├── slack_jabber ├── bad_password.py ├── jabber_slack_test.cfg ├── muc_echo.py ├── prosody.cfg.lua └── slack.sql ├── start.py ├── tests_output └── localhost │ ├── accounts │ ├── client.dat │ └── responder.dat │ ├── roster │ ├── client.dat │ └── responder.dat │ └── vcard │ └── client.dat └── xmpp ├── configuration ├── backend-logging.cfg ├── logging.cfg ├── manager-logging.cfg ├── spectrum_manager.cfg └── transports │ ├── irc.cfg │ ├── tg.cfg │ └── wa.cfg ├── data └── .gitignore └── media └── .gitignore /.dockerignore: -------------------------------------------------------------------------------- 1 | tests/xmpp/data 2 | tests/prosody/data 3 | -------------------------------------------------------------------------------- /.github/dependabot.yml: -------------------------------------------------------------------------------- 1 | version: 2 2 | updates: 3 | - package-ecosystem: "github-actions" 4 | directory: "/" 5 | schedule: 6 | interval: "weekly" 7 | labels: 8 | - "dependencies" 9 | - "automerge" 10 | -------------------------------------------------------------------------------- /.github/gcc.json: -------------------------------------------------------------------------------- 1 | { 2 | "problemMatcher": [ 3 | { 4 | "owner": "gcc", 5 | "pattern": [ 6 | { 7 | "regexp": "^(.*):(\\d+):(\\d+):\\s+(?:fatal\\s+)?(warning|error):\\s+(.*)$", 8 | "file": 1, 9 | "line": 2, 10 | "column": 3, 11 | "severity": 4, 12 | "message": 5 13 | } 14 | ] 15 | } 16 | ] 17 | } 18 | -------------------------------------------------------------------------------- /.github/workflows/publish.yml: -------------------------------------------------------------------------------- 1 | name: Publish 2 | 3 | on: 4 | push: 5 | branches: 6 | - master 7 | tags: 8 | - '*.*.*' 9 | 10 | jobs: 11 | build: 12 | runs-on: ubuntu-20.04 13 | 14 | steps: 15 | - uses: actions/checkout@v4 16 | - name: Docker meta 17 | id: docker_meta 18 | uses: crazy-max/ghaction-docker-meta@v5 19 | with: 20 | images: ghcr.io/spectrumim/spectrum 21 | tag-semver: | 22 | {{version}} 23 | tag-latest: ${{ endsWith(github.ref, github.repository.default_branch) || startsWith(github.ref, 'refs/tags/') }} 24 | - name: Set up QEMU 25 | uses: docker/setup-qemu-action@v3 26 | - name: Set up Docker Buildx 27 | uses: docker/setup-buildx-action@v3 28 | - name: Login to the container registry 29 | if: github.event_name != 'pull_request' 30 | uses: docker/login-action@v3 31 | with: 32 | registry: ghcr.io 33 | username: ${{ github.actor }} 34 | password: ${{ secrets.GITHUB_TOKEN }} 35 | - name: Build and push 36 | uses: docker/build-push-action@v6 37 | with: 38 | context: . 39 | file: ./Dockerfile 40 | platforms: linux/amd64,linux/arm64 41 | target: production 42 | cache-from: type=registry,ref=ghcr.io/spectrumim/spectrum:buildcache 43 | cache-to: type=registry,ref=ghcr.io/spectrumim/spectrum:buildcache 44 | push: ${{ github.event_name != 'pull_request' }} 45 | tags: ${{ steps.docker_meta.outputs.tags }} 46 | labels: ${{ steps.docker_meta.outputs.labels }} 47 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | *.pb.cc 3 | *.pb.h 4 | plugin/python/protocol_pb2.py 5 | Makefile 6 | cmake_install.cmake 7 | *.so 8 | *.so.* 9 | *.log 10 | libtransport_test 11 | CMakeFiles 12 | CMakeScripts 13 | cmake_install.cmake 14 | CPackConfig.cmake 15 | CPackSourceConfig.cmake 16 | **/*build/** 17 | **/Debug/** 18 | libtransport.xcodeproj 19 | spectrum2 20 | transport_config.h 21 | Doxyfile 22 | moc_* 23 | CMakeCache.txt 24 | CPackConfig.cmake 25 | CPackSourceConfig.cmake 26 | *.patch 27 | *.orig 28 | spectrum2_manager 29 | dfrotz 30 | spectrum2_frotz_backend 31 | spectrum2_libcommuni_backend 32 | spectrum2_libpurple_backend 33 | spectrum2_skype_backend 34 | spectrum2_smstools3_backend 35 | spectrum2_swiften_backend 36 | spectrum2_template_backend 37 | spectrum2_twitter_backend 38 | install_manifest.txt 39 | slack.cfg 40 | *.sqlite 41 | localhost.port 42 | *.a 43 | core.* 44 | *.pyc 45 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ![](http://spectrum.im/animation.gif) 2 | 3 | Spectrum 2 is an open source instant messaging transport. 4 | 5 | It allows users to chat together even when they are using different IM networks. 6 | 7 | It acts as a transport layer between the users as showed in the animation above. 8 | -------------------------------------------------------------------------------- /backends/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | if(PROTOBUF_FOUND) 2 | add_subdirectory(template) 3 | 4 | if(PURPLE_FOUND) 5 | add_subdirectory(libpurple) 6 | endif() 7 | 8 | if(IRC_FOUND) 9 | add_subdirectory(libcommuni) 10 | endif() 11 | 12 | if(ENABLE_XMPP) 13 | add_subdirectory(swiften) 14 | endif() 15 | 16 | if(NOT WIN32) 17 | if(ENABLE_SMSTOOLS3) 18 | add_subdirectory(smstools3) 19 | endif() 20 | if(ENABLE_FROTZ) 21 | add_subdirectory(frotz) 22 | endif() 23 | endif() 24 | endif() 25 | -------------------------------------------------------------------------------- /backends/frotz/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_subdirectory(dfrotz) 2 | 3 | file(GLOB SRC *.c *.cpp) 4 | 5 | add_executable(spectrum2_frotz_backend ${SRC}) 6 | target_compile_features(spectrum2_frotz_backend PUBLIC cxx_std_11) 7 | 8 | target_link_libraries(spectrum2_frotz_backend transport pthread ${Boost_LIBRARIES} ${SWIFTEN_LIBRARY} ${LOG4CXX_LIBRARIES}) 9 | 10 | install(TARGETS spectrum2_frotz_backend RUNTIME DESTINATION ${CMAKE_INSTALL_LIBEXECDIR}) 11 | -------------------------------------------------------------------------------- /backends/frotz/dfrotz/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | file(GLOB SRC common/*.c dumb/*.c) 2 | 3 | add_executable(dfrotz ${SRC}) 4 | 5 | set_target_properties(dfrotz PROPERTIES UNITY_BUILD OFF) 6 | 7 | # target_link_libraries(dfrotz) 8 | 9 | install(TARGETS dfrotz RUNTIME DESTINATION ${CMAKE_INSTALL_LIBEXECDIR}) 10 | 11 | -------------------------------------------------------------------------------- /backends/frotz/dfrotz/README: -------------------------------------------------------------------------------- 1 | This is patched version of dfrotz. frotz_backend won't work with dfrotz from 2 | your distribution. -------------------------------------------------------------------------------- /backends/frotz/dfrotz/common/getopt.c: -------------------------------------------------------------------------------- 1 | /* 2 | * getopt.c 3 | * 4 | * Replacement for a Unix style getopt function 5 | * 6 | * Quick, clean, and portable to funky systems that don't have getopt() 7 | * for whatever reason. 8 | * 9 | */ 10 | 11 | #include 12 | #include 13 | 14 | #ifndef MSDOS_16BIT 15 | #define cdecl 16 | #endif 17 | 18 | int optind = 1; 19 | int optopt = 0; 20 | 21 | const char *optarg = NULL; 22 | 23 | int cdecl getopt (int argc, char *argv[], const char *options) 24 | { 25 | static int pos = 1; 26 | 27 | const char *p; 28 | 29 | if (optind >= argc || argv[optind][0] != '-' || argv[optind][1] == 0) 30 | return EOF; 31 | 32 | optopt = argv[optind][pos++]; 33 | optarg = NULL; 34 | 35 | if (argv[optind][pos] == 0) 36 | { pos = 1; optind++; } 37 | 38 | p = strchr (options, optopt); 39 | 40 | if (optopt == ':' || p == NULL) { 41 | 42 | fputs ("illegal option -- ", stdout); 43 | goto error; 44 | 45 | } else if (p[1] == ':') { 46 | 47 | if (optind >= argc) { 48 | 49 | fputs ("option requires an argument -- ", stdout); 50 | goto error; 51 | 52 | } else { 53 | 54 | optarg = argv[optind]; 55 | 56 | if (pos != 1) 57 | optarg += pos; 58 | 59 | pos = 1; optind++; 60 | 61 | } 62 | } 63 | return optopt; 64 | 65 | error: 66 | 67 | fputc (optopt, stdout); 68 | fputc ('\n', stdout); 69 | 70 | return '?'; 71 | 72 | }/* getopt */ 73 | -------------------------------------------------------------------------------- /backends/frotz/dfrotz/common/setup.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Various status thingies for the interpreter and interface. 3 | * 4 | */ 5 | 6 | typedef struct frotz_setup_struct { 7 | int attribute_assignment; /* done */ 8 | int attribute_testing; /* done */ 9 | int context_lines; /* done */ 10 | int object_locating; /* done */ 11 | int object_movement; /* done */ 12 | int left_margin; /* done */ 13 | int right_margin; /* done */ 14 | int ignore_errors; /* done */ 15 | int interpreter_number; /* Just dumb frotz now */ 16 | int piracy; /* done */ 17 | int undo_slots; /* done */ 18 | int expand_abbreviations; /* done */ 19 | int script_cols; /* done */ 20 | int save_quetzal; /* done */ 21 | int sound; /* done */ 22 | int err_report_mode; /* done */ 23 | } f_setup_t; 24 | 25 | extern f_setup_t f_setup; 26 | 27 | 28 | typedef struct zcode_header_struct { 29 | zbyte h_version; 30 | zbyte h_config; 31 | zword h_release; 32 | zword h_resident_size; 33 | zword h_start_pc; 34 | zword h_dictionary; 35 | zword h_objects; 36 | zword h_globals; 37 | zword h_dynamic_size; 38 | zword h_flags; 39 | zbyte h_serial[6]; 40 | zword h_abbreviations; 41 | zword h_file_size; 42 | zword h_checksum; 43 | zbyte h_interpreter_number; 44 | zbyte h_interpreter_version; 45 | zbyte h_screen_rows; 46 | zbyte h_screen_cols; 47 | zword h_screen_width; 48 | zword h_screen_height; 49 | zbyte h_font_height; 50 | zbyte h_font_width; 51 | zword h_functions_offset; 52 | zword h_strings_offset; 53 | zbyte h_default_background; 54 | zbyte h_default_foreground; 55 | zword h_terminating_keys; 56 | zword h_line_width; 57 | zbyte h_standard_high; 58 | zbyte h_standard_low; 59 | zword h_alphabet; 60 | zword h_extension_table; 61 | zbyte h_user_name[8]; 62 | 63 | zword hx_table_size; 64 | zword hx_mouse_x; 65 | zword hx_mouse_y; 66 | zword hx_unicode_table; 67 | } z_header_t; 68 | -------------------------------------------------------------------------------- /backends/frotz/dfrotz/dumb/dumb_frotz.h: -------------------------------------------------------------------------------- 1 | /* dumb-frotz.h 2 | * $Id: dumb-frotz.h,v 1.1.1.1 2002/03/26 22:38:34 feedle Exp $ 3 | * Frotz os functions for a standard C library and a dumb terminal. 4 | * Now you can finally play Zork Zero on your Teletype. 5 | * 6 | * Copyright 1997, 1998 Alembic Petrofsky . 7 | * Any use permitted provided this notice stays intact. 8 | */ 9 | #include "../common/frotz.h" 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | 17 | #define VERSION "1.0" 18 | 19 | /* from ../common/setup.h */ 20 | extern f_setup_t f_setup; 21 | 22 | /* From input.c. */ 23 | bool is_terminator (zchar); 24 | 25 | /* dumb-input.c */ 26 | bool dumb_handle_setting(const char *setting, bool show_cursor, bool startup); 27 | void dumb_init_input(void); 28 | 29 | /* dumb-output.c */ 30 | void dumb_init_output(void); 31 | bool dumb_output_handle_setting(const char *setting, bool show_cursor, 32 | bool startup); 33 | void dumb_show_screen(bool show_cursor); 34 | void dumb_show_prompt(bool show_cursor, char line_type); 35 | void dumb_dump_screen(void); 36 | void dumb_display_user_input(char *); 37 | void dumb_discard_old_input(int num_chars); 38 | void dumb_elide_more_prompt(void); 39 | void dumb_set_picture_cell(int row, int col, char c); 40 | 41 | /* dumb-pic.c */ 42 | void dumb_init_pictures(char *graphics_filename); 43 | -------------------------------------------------------------------------------- /backends/libcommuni/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | file(GLOB SRC *.cpp) 2 | file(GLOB HEADERS *.h) 3 | 4 | if(ENABLE_QT4) 5 | QT4_WRAP_CPP(SRC ${HEADERS} OPTIONS -DBOOST_TT_HAS_OPERATOR_HPP_INCLUDED) 6 | else() 7 | QT5_WRAP_CPP(SRC ${HEADERS} OPTIONS -DBOOST_TT_HAS_OPERATOR_HPP_INCLUDED) 8 | include_directories(${Qt5Core_INCLUDE_DIRS} ${Qt5Network_INCLUDE_DIRS}) 9 | endif() 10 | 11 | add_definitions(-DQT_NO_KEYWORDS) 12 | add_executable(spectrum2_libcommuni_backend ${SRC}) 13 | target_compile_features(spectrum2_libcommuni_backend PUBLIC cxx_std_11) 14 | 15 | if(NOT WIN32) 16 | if(ENABLE_QT4) 17 | target_link_libraries(spectrum2_libcommuni_backend ${IRC_LIBRARY} Qt4::QtNetwork Qt4::QtCore transport pthread) 18 | else() 19 | target_link_libraries(spectrum2_libcommuni_backend ${IRC_LIBRARY} Qt5::Network Qt5::Core transport pthread) 20 | endif() 21 | else() 22 | if(ENABLE_QT4) 23 | target_link_libraries(spectrum2_libcommuni_backend ${IRC_LIBRARY} Qt4::QtNetwork Qt4::QtCore transport) 24 | else() 25 | target_link_libraries(spectrum2_libcommuni_backend ${IRC_LIBRARY} Qt5::Network Qt5::Core transport) 26 | endif() 27 | endif() 28 | 29 | install(TARGETS spectrum2_libcommuni_backend RUNTIME DESTINATION ${CMAKE_INSTALL_LIBEXECDIR}) 30 | -------------------------------------------------------------------------------- /backends/libcommuni/backports.h: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | 6 | namespace CommuniBackport { 7 | 8 | bool parseColors(const QString& message, int pos, int* len, int* fg = 0, int* bg = 0) 9 | { 10 | // fg(,bg) 11 | *len = 0; 12 | if (fg) 13 | *fg = -1; 14 | if (bg) 15 | *bg = -1; 16 | QRegExp rx(QLatin1String("(\\d{1,2})(?:,(\\d{1,2}))?")); 17 | int idx = rx.indexIn(message, pos); 18 | if (idx == pos) { 19 | *len = rx.matchedLength(); 20 | if (fg) 21 | *fg = rx.cap(1).toInt(); 22 | if (bg) { 23 | bool ok = false; 24 | int tmp = rx.cap(2).toInt(&ok); 25 | if (ok) 26 | *bg = tmp; 27 | } 28 | } 29 | return *len > 0; 30 | } 31 | 32 | /*! 33 | Converts \a text to plain text. This function parses the text and 34 | strips away IRC-style formatting like colors, bold and underline. 35 | 36 | \sa toHtml() 37 | */ 38 | void toPlainText(QString& processed) 39 | { 40 | 41 | int pos = 0; 42 | int len = 0; 43 | while (pos < processed.size()) { 44 | switch (processed.at(pos).unicode()) { 45 | case '\x02': // bold 46 | case '\x0f': // none 47 | case '\x13': // strike-through 48 | case '\x15': // underline 49 | case '\x16': // inverse 50 | case '\x1d': // italic 51 | case '\x1f': // underline 52 | processed.remove(pos, 1); 53 | break; 54 | 55 | case '\x03': // color 56 | if (parseColors(processed, pos + 1, &len)) 57 | processed.remove(pos, len + 1); 58 | else 59 | processed.remove(pos, 1); 60 | break; 61 | 62 | default: 63 | ++pos; 64 | break; 65 | } 66 | } 67 | 68 | } 69 | 70 | } 71 | -------------------------------------------------------------------------------- /backends/libcommuni/main.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * XMPP - libpurple transport 3 | * 4 | * Copyright (C) 2013, Jan Kaluza 5 | * 6 | * This program is free software; you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation; either version 2 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program; if not, write to the Free Software 18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA 19 | */ 20 | #include 21 | #include 22 | #include "transport/Config.h" 23 | #include "transport/NetworkPlugin.h" 24 | #include "transport/Logging.h" 25 | #include "Swiften/EventLoop/Qt/QtEventLoop.h" 26 | #include "ircnetworkplugin.h" 27 | 28 | using namespace boost::program_options; 29 | using namespace Transport; 30 | 31 | NetworkPlugin * np = NULL; 32 | 33 | int main (int argc, char* argv[]) { 34 | std::string host; 35 | int port; 36 | 37 | std::string error; 38 | Config *cfg = Config::createFromArgs(argc, argv, error, host, port); 39 | if (cfg == NULL) { 40 | std::cerr << error; 41 | return 1; 42 | } 43 | 44 | Logging::initBackendLogging(cfg); 45 | 46 | QCoreApplication app(argc, argv); 47 | 48 | Swift::QtEventLoop eventLoop; 49 | 50 | 51 | np = new IRCNetworkPlugin(cfg, &eventLoop, host, port); 52 | return app.exec(); 53 | } 54 | -------------------------------------------------------------------------------- /backends/libpurple/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | file(GLOB SRC *.cpp) 2 | 3 | add_executable(spectrum2_libpurple_backend ${SRC}) 4 | target_compile_features(spectrum2_libpurple_backend PUBLIC cxx_std_11) 5 | 6 | target_link_libraries(spectrum2_libpurple_backend transport-plugin ${PURPLE_LIBRARY} ${GLIB2_LIBRARIES} ${EVENT_LIBRARIES}) 7 | 8 | install(TARGETS spectrum2_libpurple_backend RUNTIME DESTINATION ${CMAKE_INSTALL_LIBEXECDIR}) 9 | -------------------------------------------------------------------------------- /backends/libpurple/geventloop.h: -------------------------------------------------------------------------------- 1 | /** 2 | * XMPP - libpurple transport 3 | * 4 | * Copyright (C) 2009, Jan Kaluza 5 | * 6 | * This program is free software; you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation; either version 2 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program; if not, write to the Free Software 18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA 19 | */ 20 | 21 | #ifndef _HI_EVENTLOOP_H 22 | #define _HI_EVENTLOOP_H 23 | 24 | #include 25 | #include "purple.h" 26 | #include "eventloop.h" 27 | 28 | #define READ_COND (G_IO_IN | G_IO_HUP | G_IO_ERR) 29 | #define WRITE_COND (G_IO_OUT | G_IO_HUP | G_IO_ERR | G_IO_NVAL) 30 | 31 | PurpleEventLoopUiOps * getEventLoopUiOps(bool libev); 32 | 33 | #endif 34 | -------------------------------------------------------------------------------- /backends/libpurple/sample_client.cfg: -------------------------------------------------------------------------------- 1 | [service] 2 | jid = icq.localhost 3 | password = secret 4 | server = 127.0.0.1 5 | port = 5347 6 | protocol=prpl-jabber 7 | #server_mode=1 8 | 9 | [database] 10 | database = test.sql 11 | prefix=icq 12 | -------------------------------------------------------------------------------- /backends/libpurple/utils.h: -------------------------------------------------------------------------------- 1 | /** 2 | * libtransport -- C++ library for easy XMPP Transports development 3 | * 4 | * Copyright (C) 2011, Jan Kaluza 5 | * 6 | * This program is free software; you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation; either version 2 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program; if not, write to the Free Software 18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA 19 | */ 20 | 21 | #pragma once 22 | 23 | #include "purple.h" 24 | #include 25 | 26 | #ifndef WIN32 27 | void spectrum_sigchld_handler(int sig); 28 | #endif 29 | 30 | int create_socket(const char *host, int portno); 31 | GHashTable *spectrum_ui_get_info(void); 32 | 33 | void execute_purple_plugin_action(PurpleConnection *gc, const std::string &name); 34 | 35 | #ifdef _WIN32 36 | std::wstring utf8ToUtf16(const std::string& str); 37 | #endif 38 | -------------------------------------------------------------------------------- /backends/smstools3/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | file(GLOB SRC *.c *.cpp) 2 | 3 | add_executable(spectrum2_smstools3_backend ${SRC}) 4 | target_compile_features(spectrum2_smstools3_backend PUBLIC cxx_std_11) 5 | 6 | target_link_libraries(spectrum2_smstools3_backend transport pthread ${Boost_LIBRARIES} ${SWIFTEN_LIBRARY} ${LOG4CXX_LIBRARIES}) 7 | 8 | install(TARGETS spectrum2_smstools3_backend RUNTIME DESTINATION ${CMAKE_INSTALL_LIBEXECDIR}) 9 | -------------------------------------------------------------------------------- /backends/swiften/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | file(GLOB SRC *.cpp) 2 | 3 | add_executable(spectrum2_swiften_backend ${SRC}) 4 | target_compile_features(spectrum2_swiften_backend PUBLIC cxx_std_11) 5 | 6 | 7 | if(NOT WIN32) 8 | target_link_libraries(spectrum2_swiften_backend transport pthread ${Boost_LIBRARIES} ${SWIFTEN_LIBRARY} ${LOG4CXX_LIBRARIES}) 9 | else() 10 | target_link_libraries(spectrum2_swiften_backend transport ${Boost_LIBRARIES} ${SWIFTEN_LIBRARY} ${LOG4CXX_LIBRARIES}) 11 | endif() 12 | 13 | install(TARGETS spectrum2_swiften_backend RUNTIME DESTINATION ${CMAKE_INSTALL_LIBEXECDIR}) 14 | -------------------------------------------------------------------------------- /backends/template/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | file(GLOB SRC *.c *.cpp) 2 | 3 | add_executable(spectrum2_template_backend ${SRC}) 4 | target_compile_features(spectrum2_template_backend PUBLIC cxx_std_11) 5 | 6 | if(CMAKE_COMPILER_IS_GNUCXX) 7 | if(NOT WIN32) 8 | target_link_libraries(spectrum2_template_backend transport pthread ${Boost_LIBRARIES} ${SWIFTEN_LIBRARY} ${LOG4CXX_LIBRARIES}) 9 | else() 10 | target_link_libraries(spectrum2_template_backend transport ${Boost_LIBRARIES} ${SWIFTEN_LIBRARY} ${LOG4CXX_LIBRARIES}) 11 | endif() 12 | else() 13 | target_link_libraries(spectrum2_template_backend transport ${Boost_LIBRARIES} ${SWIFTEN_LIBRARY} ${LOG4CXX_LIBRARIES}) 14 | endif() 15 | 16 | #install(TARGETS spectrum2_template_backend RUNTIME DESTINATION bin) 17 | -------------------------------------------------------------------------------- /backends/template/README.md: -------------------------------------------------------------------------------- 1 | # Spectrum2 Backend Templates 2 | 3 | For details, please see: 4 | 5 | - https://spectrum.im/documentation/development/protocol.html 6 | - http://pypi.org/project/pyspectrum2/ 7 | -------------------------------------------------------------------------------- /backends/template/main.cpp: -------------------------------------------------------------------------------- 1 | #include "plugin.h" 2 | 3 | // Transport includes 4 | #include "transport/Config.h" 5 | #include "transport/NetworkPlugin.h" 6 | #include "transport/Logging.h" 7 | 8 | // Swiften 9 | #include "Swiften/Swiften.h" 10 | 11 | #ifndef _WIN32 12 | // for signal handler 13 | #include "unistd.h" 14 | #include "signal.h" 15 | #include "sys/wait.h" 16 | #include "sys/signal.h" 17 | #endif 18 | // Boost 19 | #include 20 | using namespace boost::filesystem; 21 | using namespace boost::program_options; 22 | using namespace Transport; 23 | 24 | #ifndef _WIN32 25 | 26 | static void spectrum_sigchld_handler(int sig) 27 | { 28 | int status; 29 | pid_t pid; 30 | 31 | do { 32 | pid = waitpid(-1, &status, WNOHANG); 33 | } while (pid != 0 && pid != (pid_t)-1); 34 | 35 | if ((pid == (pid_t) - 1) && (errno != ECHILD)) { 36 | char errmsg[BUFSIZ]; 37 | snprintf(errmsg, BUFSIZ, "Warning: waitpid() returned %d", pid); 38 | perror(errmsg); 39 | } 40 | } 41 | #endif 42 | 43 | int main (int argc, char* argv[]) { 44 | std::string host; 45 | int port; 46 | 47 | #ifndef _WIN32 48 | if (signal(SIGCHLD, spectrum_sigchld_handler) == SIG_ERR) { 49 | std::cout << "SIGCHLD handler can't be set\n"; 50 | return -1; 51 | } 52 | #endif 53 | 54 | std::string error; 55 | Config *cfg = Config::createFromArgs(argc, argv, error, host, port); 56 | if (cfg == NULL) { 57 | std::cerr << error; 58 | return 1; 59 | } 60 | 61 | Logging::initBackendLogging(cfg); 62 | 63 | Swift::SimpleEventLoop eventLoop; 64 | Plugin p(cfg, &eventLoop, host, port); 65 | eventLoop.run(); 66 | 67 | return 0; 68 | } 69 | -------------------------------------------------------------------------------- /backends/template/plugin.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "Swiften/Swiften.h" 4 | 5 | #include "transport/Config.h" 6 | #include "transport/NetworkPlugin.h" 7 | 8 | class Plugin : public Transport::NetworkPlugin { 9 | public: 10 | Plugin(Transport::Config *config, Swift::SimpleEventLoop *loop, const std::string &host, int port); 11 | 12 | // NetworkPlugin uses this method to send the data to networkplugin server 13 | void sendData(const std::string &string); 14 | 15 | void handleLoginRequest(const std::string &user, const std::string &legacyName, const std::string &password, const std::map &settings); 16 | 17 | void handleLogoutRequest(const std::string &user, const std::string &legacyName); 18 | 19 | void handleMessageSendRequest(const std::string &user, const std::string &legacyName, const std::string &message, const std::string &xhtml = "", const std::string &id = ""); 20 | 21 | void handleBuddyUpdatedRequest(const std::string &user, const std::string &buddyName, const std::string &alias, const std::vector &groups); 22 | 23 | void handleBuddyRemovedRequest(const std::string &user, const std::string &buddyName, const std::vector &groups); 24 | 25 | private: 26 | // This method has to call handleDataRead with all received data from network plugin server 27 | void _handleDataRead(std::shared_ptr data); 28 | 29 | private: 30 | Swift::BoostNetworkFactories *m_factories; 31 | Swift::BoostIOServiceThread m_boostIOServiceThread; 32 | std::shared_ptr m_conn; 33 | Transport::Config *config; 34 | }; 35 | -------------------------------------------------------------------------------- /cmake_modules/FindCommuni.cmake: -------------------------------------------------------------------------------- 1 | if( ENABLE_QT4 ) 2 | find_package(Qt4) 3 | include( ${QT_USE_FILE} ) 4 | else() 5 | find_package(Qt5Network) 6 | endif() 7 | 8 | FIND_LIBRARY(IRC_LIBRARY NAMES IrcCore PATHS ${QT_LIBRARY_DIR}) 9 | if( ENABLE_QT4 ) 10 | FIND_PATH(IRC_INCLUDE_DIR NAMES "IrcCore/ircglobal.h" PATHS ${QT_INCLUDE_DIR} PATH_SUFFIXES Communi) 11 | else() 12 | FIND_PATH(IRC_INCLUDE_DIR NAMES "IrcCore/ircglobal.h" PATHS ${Qt5Core_INCLUDE_DIRS} ${Qt5Core_INCLUDE_DIRS}"/.." PATH_SUFFIXES Communi) 13 | endif() 14 | 15 | # message( STATUS ${IRC_LIBRARY}) 16 | if( IRC_LIBRARY AND IRC_INCLUDE_DIR ) 17 | FIND_LIBRARY(IRC_MODEL_LIBRARY NAMES IrcModel PATHS ${QT_LIBRARY_DIR}) 18 | if (IRC_MODEL_LIBRARY) 19 | set(IRC_LIBRARY ${IRC_LIBRARY} ${IRC_MODEL_LIBRARY}) 20 | set(IRC_INCLUDE_DIR ${IRC_INCLUDE_DIR}/IrcCore ${IRC_INCLUDE_DIR}/IrcUtil ${IRC_INCLUDE_DIR}/IrcModel) 21 | message( STATUS "Found libCommuni ${IRC_LIBRARY}, ${IRC_INCLUDE_DIR}") 22 | set( IRC_FOUND 1 ) 23 | else() 24 | message( STATUS "Could NOT find libCommuni - IrcModel library" ) 25 | endif() 26 | else() 27 | message( STATUS "Could NOT find libCommuni - IrcCore library" ) 28 | endif() 29 | -------------------------------------------------------------------------------- /cmake_modules/FindCppUnit.cmake: -------------------------------------------------------------------------------- 1 | # - Find cppunit 2 | # Find the native cppunit includes and library 3 | # 4 | # CPPUNIT_INCLUDE_DIR - where to find cppunit/Test.h, etc. 5 | # CPPUNIT_LIBRARIES - List of libraries when using cppunit. 6 | # CPPUNIT_FOUND - True if cppunit found. 7 | 8 | 9 | IF (CPPUNIT_INCLUDE_DIR) 10 | # Already in cache, be silent 11 | SET(CPPUNIT_FIND_QUIETLY TRUE) 12 | ENDIF (CPPUNIT_INCLUDE_DIR) 13 | 14 | FIND_PATH(CPPUNIT_INCLUDE_DIR cppunit/Test.h) 15 | 16 | SET(CPPUNIT_NAMES cppunit) 17 | FIND_LIBRARY(CPPUNIT_LIBRARY NAMES ${CPPUNIT_NAMES} ) 18 | 19 | # handle the QUIETLY and REQUIRED arguments and set CPPUNIT_FOUND to TRUE if 20 | # all listed variables are TRUE 21 | INCLUDE(FindPackageHandleStandardArgs) 22 | FIND_PACKAGE_HANDLE_STANDARD_ARGS(CppUnit DEFAULT_MSG CPPUNIT_LIBRARY CPPUNIT_INCLUDE_DIR) 23 | 24 | IF(CPPUNIT_FOUND) 25 | SET( CPPUNIT_LIBRARIES ${CPPUNIT_LIBRARY} ) 26 | ELSE(CPPUNIT_FOUND) 27 | SET( CPPUNIT_LIBRARIES ) 28 | ENDIF(CPPUNIT_FOUND) 29 | 30 | MARK_AS_ADVANCED( CPPUNIT_LIBRARY CPPUNIT_INCLUDE_DIR ) 31 | -------------------------------------------------------------------------------- /cmake_modules/FindSwiften.cmake: -------------------------------------------------------------------------------- 1 | FIND_LIBRARY(SWIFTEN_LIBRARY NAMES Swiften Swiften4 HINTS ../lib) 2 | FIND_PATH(SWIFTEN_INCLUDE_DIR NAMES "Swiften/Swiften.h" PATH_SUFFIXES libSwiften Swiften HINTS ../include) 3 | 4 | if( SWIFTEN_LIBRARY AND SWIFTEN_INCLUDE_DIR ) 5 | find_program(SWIFTEN_CONFIG_EXECUTABLE NAMES swiften-config DOC "swiften-config executable" HINTS ../bin) 6 | set( SWIFTEN_CFLAGS "" ) 7 | if (SWIFTEN_CONFIG_EXECUTABLE) 8 | # Libs 9 | execute_process( 10 | COMMAND ${SWIFTEN_CONFIG_EXECUTABLE} --libs 11 | OUTPUT_VARIABLE SWIFTEN_LIB) 12 | string(REGEX REPLACE "[\r\n]" " " SWIFTEN_LIB "${SWIFTEN_LIB}") 13 | string(REGEX REPLACE " +$" "" SWIFTEN_LIB "${SWIFTEN_LIB}") 14 | set(SWIFTEN_LIBRARY "") 15 | if (APPLE) 16 | string(REGEX MATCHALL "-framework [A-Za-z]+" APPLE_FRAMEWORKS "${SWIFTEN_LIB}") 17 | foreach(framework ${APPLE_FRAMEWORKS}) 18 | list(APPEND SWIFTEN_LIBRARY ${framework} ) 19 | endforeach(framework) 20 | string(REGEX REPLACE "-framework [A-Za-z]+" "" SWIFTEN_LIB "${SWIFTEN_LIB}") 21 | endif(APPLE) 22 | string(REGEX REPLACE " " ";" SWIFTEN_LIB "${SWIFTEN_LIB}") 23 | foreach(f ${SWIFTEN_LIB}) 24 | STRING(SUBSTRING ${f} 0 2 f_out) 25 | STRING(COMPARE EQUAL ${f_out} "/L" IS_PATH) 26 | if(${IS_PATH}) 27 | string(REGEX REPLACE "/LIBPATH:" "" f_replaced "${f}") 28 | message("Added link directory: ${f_replaced}") 29 | link_directories(${f_replaced}) 30 | else() 31 | list(APPEND SWIFTEN_LIBRARY ${f}) 32 | endif() 33 | endforeach(f) 34 | 35 | set( SWIFTEN_FOUND 1 ) 36 | else() 37 | message( STATUS "Could NOT find swiften-config" ) 38 | endif() 39 | 40 | if (SWIFTEN_FOUND) 41 | set( SWIFTEN_INCLUDE_DIR ${SWIFTEN_INCLUDE_DIR} ) 42 | message( STATUS "Found libSwiften: ${SWIFTEN_LIBRARY}, ${SWIFTEN_INCLUDE_DIR}") 43 | endif() 44 | 45 | else( SWIFTEN_LIBRARY AND SWIFTEN_INCLUDE_DIR ) 46 | message( STATUS "Could NOT find libSwiften" ) 47 | endif( SWIFTEN_LIBRARY AND SWIFTEN_INCLUDE_DIR ) 48 | -------------------------------------------------------------------------------- /cmake_modules/Findevent.cmake: -------------------------------------------------------------------------------- 1 | FIND_PATH(EVENT_INCLUDE_DIRS event.h ev.h PATH_SUFFIXES libev) 2 | 3 | SET(EVENT_NAMES ${EVENT_NAMES} ev libev) 4 | FIND_LIBRARY(EVENT_LIBRARIES NAMES ${EVENT_NAMES} PATH) 5 | 6 | IF(EVENT_INCLUDE_DIRS AND EVENT_LIBRARIES) 7 | SET(HAVE_EVENT TRUE) 8 | file(APPEND libtransport/transport_config.h "#define WITH_LIBEVENT 1\n") 9 | ELSE(EVENT_INCLUDE_DIRS AND EVENT_LIBRARIES) 10 | SET (EVENT_INCLUDE_DIRS "") 11 | SET (EVENT_LIBRARIES "") 12 | ENDIF(EVENT_INCLUDE_DIRS AND EVENT_LIBRARIES) 13 | 14 | IF(HAVE_EVENT) 15 | MESSAGE(STATUS "Found Event: ${EVENT_LIBRARIES} ${EVENT_INCLUDE_DIRS}") 16 | ENDIF(HAVE_EVENT) 17 | -------------------------------------------------------------------------------- /cmake_modules/Findlog4cxx.cmake: -------------------------------------------------------------------------------- 1 | # LOG4CXX_FOUND - system has liblog4cxx 2 | # LOG4CXX_INCLUDE_DIR - the liblog4cxx include directory 3 | # LOG4CXX_LIBRARIES - liblog4cxx library 4 | 5 | FIND_PATH(LOG4CXX_INCLUDE_DIR log4cxx/logger.h PATHS /include /usr/include /usr/local/include ) 6 | FIND_LIBRARY(LOG4CXX_LIBRARIES NAMES log4cxx log4cxxd PATHS /lib /usr/lib /usr/local/lib ) 7 | 8 | IF(LOG4CXX_INCLUDE_DIR AND LOG4CXX_LIBRARIES) 9 | SET(LOG4CXX_FOUND 1) 10 | #remove last /log4cxx string 11 | STRING(REGEX REPLACE "/log4cxx" " " LOG4CXX_INCLUDE_DIR_SUP_LEVEL ${LOG4CXX_INCLUDE_DIR}) 12 | SET (LOG4CXX_INCLUDE_DIR ${LOG4CXX_INCLUDE_DIR_SUP_LEVEL} ${LOG4CXX_INCLUDE_DIR} ) 13 | if(NOT Log4cxx_FIND_QUIETLY) 14 | message(STATUS "Found log4cxx: ${LOG4CXX_LIBRARIES}" ", " ${LOG4CXX_INCLUDE_DIR}) 15 | endif(NOT Log4cxx_FIND_QUIETLY) 16 | ELSE(LOG4CXX_INCLUDE_DIR AND LOG4CXX_LIBRARIES) 17 | SET(LOG4CXX_FOUND 0 CACHE BOOL "Not found log4cxx library") 18 | message(STATUS "NOT Found log4cxx, disabling it") 19 | ENDIF(LOG4CXX_INCLUDE_DIR AND LOG4CXX_LIBRARIES) 20 | 21 | MARK_AS_ADVANCED(LOG4CXX_INCLUDE_DIR LOG4CXX_LIBRARIES) 22 | -------------------------------------------------------------------------------- /cmake_modules/Findmysql.cmake: -------------------------------------------------------------------------------- 1 | # - Find mysqlclient 2 | # Find the native MySQL includes and library 3 | # 4 | # MYSQL_INCLUDE_DIR - where to find mysql.h, etc. 5 | # MYSQL_LIBRARIES - List of libraries when using MySQL. 6 | # MYSQL_FOUND - True if MySQL found. 7 | # 8 | # Based on: http://www.itk.org/Wiki/CMakeUserFindMySQL 9 | 10 | find_path( MYSQL_INCLUDE_DIR "mysql.h" 11 | PATH_SUFFIXES "mysql" ) 12 | 13 | set( MYSQL_NAMES mysqlclient mysqlclient_r ) 14 | find_library( MYSQL_LIBRARY 15 | NAMES ${MYSQL_NAMES} 16 | PATH_SUFFIXES "mysql" ) 17 | mark_as_advanced( MYSQL_LIBRARY MYSQL_INCLUDE_DIR ) 18 | 19 | if( MYSQL_INCLUDE_DIR AND EXISTS "${MYSQL_INCLUDE_DIR}/mysql_version.h" ) 20 | file( STRINGS "${MYSQL_INCLUDE_DIR}/mysql_version.h" MYSQL_VERSION_H REGEX "^#define[ \t]+MYSQL_SERVER_VERSION[ \t]+\"[^\"]+\".*$" ) 21 | string( REGEX REPLACE "^.*MYSQL_SERVER_VERSION[ \t]+\"([^\"]+)\".*$" "\\1" MYSQL_VERSION_STRING "${MYSQL_VERSION_H}" ) 22 | endif() 23 | 24 | # handle the QUIETLY and REQUIRED arguments and set MYSQL_FOUND to TRUE if 25 | # all listed variables are TRUE 26 | # include( FindPackageHandleStandardArgs ) 27 | # FIND_PACKAGE_HANDLE_STANDARD_ARGS( MYSQL 28 | # REQUIRED_VARS MYSQL_LIBRARY MYSQL_INCLUDE_DIR 29 | # VERSION_VAR MYSQL_VERSION_STRING ) 30 | 31 | if(MYSQL_LIBRARY AND MYSQL_INCLUDE_DIR) 32 | set(MYSQL_FOUND TRUE) 33 | set( MYSQL_LIBRARIES ${MYSQL_LIBRARY} ) 34 | set( MYSQL_INCLUDE_DIRS ${PCRE_INCLUDE_DIR} ) 35 | message( STATUS "Found MySQL: ${MYSQL_LIBRARY}, ${MYSQL_INCLUDE_DIR}") 36 | endif() 37 | -------------------------------------------------------------------------------- /cmake_modules/Findpopt.cmake: -------------------------------------------------------------------------------- 1 | FIND_LIBRARY(POPT_LIBRARY NAMES popt) 2 | FIND_PATH(POPT_INCLUDE_DIR NAMES "popt.h") 3 | 4 | 5 | if( POPT_LIBRARY AND POPT_INCLUDE_DIR ) 6 | message( STATUS "Found popt: ${POPT_LIBRARY}, ${POPT_INCLUDE_DIR}") 7 | set( POPT_FOUND 1 ) 8 | else( POPT_LIBRARY AND POPT_INCLUDE_DIR ) 9 | message( STATUS "Could NOT find popt" ) 10 | endif( POPT_LIBRARY AND POPT_INCLUDE_DIR ) 11 | -------------------------------------------------------------------------------- /cmake_modules/Findpqxx.cmake: -------------------------------------------------------------------------------- 1 | if (NOT WIN32) 2 | find_package(PkgConfig) 3 | if (PKG_CONFIG_FOUND) 4 | pkg_check_modules(PQXX libpqxx) 5 | if (PQXX_FOUND) 6 | if (PQXX_VERSION STRGREATER "7") 7 | message(STATUS "libpqxx version ${PQXX_VERSION}, requesting c++17") 8 | set (CMAKE_CXX_STANDARD 17) 9 | endif() 10 | endif() 11 | endif() 12 | else() 13 | 14 | FIND_PATH(PQXX_INCLUDE_DIR pqxx/pqxx PATHS) 15 | MARK_AS_ADVANCED(PQXX_INCLUDE_DIR) 16 | 17 | FIND_LIBRARY(PQXX_LIBRARIES pqxx ) 18 | MARK_AS_ADVANCED(PQXX_LIBRARIES) 19 | 20 | FIND_LIBRARY(PQ_LIBRARY pq ) 21 | MARK_AS_ADVANCED(PQ_LIBRARY) 22 | 23 | if(PQXX_LIBRARY AND PQ_LIBRARY AND PQXX_INCLUDE_DIR) 24 | set( PQXX_FOUND 1 ) 25 | message( STATUS "Found pqxx: ${PQXX_LIBRARIES}, ${PQ_LIBRARY}, ${PQXX_INCLUDE_DIR}") 26 | if (PQXX_VERSION STRGREATER "7") 27 | message(STATUS "libpqxx version ${PQXX_VERSION}, requesting c++17") 28 | set (CMAKE_CXX_STANDARD 17) 29 | endif() 30 | else() 31 | message(STATUS "Could NOT find pqxx and pq library") 32 | endif() 33 | endif() 34 | -------------------------------------------------------------------------------- /cmake_modules/Findpurple.cmake: -------------------------------------------------------------------------------- 1 | FIND_LIBRARY(PURPLE_LIBRARY NAMES purple) 2 | FIND_PATH(PURPLE_INCLUDE_DIR NAMES "purple.h" PATH_SUFFIXES libpurple ) 3 | 4 | if(WIN32 AND PURPLE_INCLUDE_DIR ) 5 | if (NOT PURPLE_NOT_RUNTIME) 6 | set(PURPLE_LIBRARY "") 7 | endif(NOT PURPLE_NOT_RUNTIME) 8 | set(PURPLE_FOUND 1) 9 | message(STATUS "Using purple: ${PURPLE_INCLUDE_DIR} ${PURPLE_LIBRARY}") 10 | else() 11 | 12 | if( PURPLE_LIBRARY AND PURPLE_INCLUDE_DIR ) 13 | message( STATUS "Found libpurple: ${PURPLE_LIBRARY}, ${PURPLE_INCLUDE_DIR}") 14 | set( PURPLE_FOUND 1 ) 15 | else( PURPLE_LIBRARY AND PURPLE_INCLUDE_DIR ) 16 | message( STATUS "Could NOT find libpurple" ) 17 | endif( PURPLE_LIBRARY AND PURPLE_INCLUDE_DIR ) 18 | 19 | endif() 20 | -------------------------------------------------------------------------------- /docker-compose.yml: -------------------------------------------------------------------------------- 1 | version: '3.4' 2 | services: 3 | spectrum: 4 | image: spectrum2/spectrum:master 5 | restart: unless-stopped 6 | container_name: spectrum 7 | ports: 8 | - 8080:8080 9 | volumes: 10 | - ./tests/xmpp/configuration:/etc/spectrum2:ro 11 | - ./tests/xmpp/configuration/transports:/etc/spectrum2/transports:ro 12 | - ./tests/xmpp/data:/var/lib/spectrum2 13 | - ./tests/xmpp/media:/var/lib/spectrum2/media 14 | depends_on: 15 | prosody: 16 | condition: service_started 17 | nginx: 18 | condition: service_started 19 | prosody: 20 | image: spectrum2/prosody:latest 21 | restart: unless-stopped 22 | container_name: prosody 23 | ports: 24 | - 5222:5222 25 | - 5347:5347 26 | environment: 27 | - LOCAL=admin 28 | - DOMAIN=localhost 29 | - PASSWORD=secret 30 | volumes: 31 | - ./tests/prosody/configuration:/etc/prosody:ro 32 | - ./tests/prosody/data:/var/lib/prosody 33 | nginx: 34 | image: spectrum2/nginx:latest 35 | restart: unless-stopped 36 | container_name: nginx 37 | ports: 38 | - 8081:80 39 | volumes: 40 | - ./tests/xmpp/media:/var/www/html:ro 41 | -------------------------------------------------------------------------------- /docs/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_subdirectory(api) 2 | -------------------------------------------------------------------------------- /docs/api/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | configure_file(${CMAKE_CURRENT_SOURCE_DIR}/Doxyfile.in ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile @ONLY) 2 | add_custom_target(docs doxygen ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} COMMENT "Generating API documentation with Doxygen" VERBATIM) 3 | -------------------------------------------------------------------------------- /include/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_subdirectory(transport) 2 | -------------------------------------------------------------------------------- /include/Swiften/Elements/AttentionPayload.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2011 Jan Kaluza 3 | * Licensed under the Simplified BSD license. 4 | * See Documentation/Licenses/BSD-simplified.txt for more information. 5 | */ 6 | 7 | #include 8 | 9 | namespace Swift { 10 | 11 | AttentionPayload::AttentionPayload() { 12 | } 13 | 14 | } 15 | -------------------------------------------------------------------------------- /include/Swiften/Elements/AttentionPayload.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2011 Jan Kaluza 3 | * Licensed under the Simplified BSD license. 4 | * See Documentation/Licenses/BSD-simplified.txt for more information. 5 | */ 6 | 7 | #pragma once 8 | 9 | #include 10 | #include 11 | 12 | #include 13 | 14 | namespace Swift { 15 | class AttentionPayload : public Payload { 16 | public: 17 | typedef std::shared_ptr ref; 18 | 19 | public: 20 | AttentionPayload(); 21 | }; 22 | } 23 | -------------------------------------------------------------------------------- /include/Swiften/Elements/GatewayPayload.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2011 Jan Kaluza 3 | * Licensed under the Simplified BSD license. 4 | * See Documentation/Licenses/BSD-simplified.txt for more information. 5 | */ 6 | 7 | #include 8 | 9 | namespace Swift { 10 | 11 | GatewayPayload::GatewayPayload(const JID &jid, const std::string &desc, const std::string &prompt) : 12 | jid(jid), desc(desc), prompt(prompt) { 13 | 14 | } 15 | 16 | } 17 | -------------------------------------------------------------------------------- /include/Swiften/Elements/GatewayPayload.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2011 Jan Kaluza 3 | * Licensed under the Simplified BSD license. 4 | * See Documentation/Licenses/BSD-simplified.txt for more information. 5 | */ 6 | 7 | #pragma once 8 | 9 | #include 10 | 11 | #include 12 | #include 13 | #include 14 | 15 | namespace Swift { 16 | class GatewayPayload : public Payload { 17 | public: 18 | GatewayPayload(const JID &jid = JID(), const std::string &desc = "", const std::string &prompt = ""); 19 | 20 | void setJID(const JID &jid) { 21 | this->jid = jid; 22 | } 23 | 24 | const JID &getJID() const { 25 | return jid; 26 | } 27 | 28 | void setDesc(const std::string &desc) { 29 | this->desc = desc; 30 | } 31 | 32 | const std::string &getDesc() const { 33 | return desc; 34 | } 35 | 36 | void setPrompt(const std::string &prompt) { 37 | this->prompt = prompt; 38 | } 39 | 40 | const std::string &getPrompt() const { 41 | return prompt; 42 | } 43 | 44 | private: 45 | JID jid; 46 | std::string desc; 47 | std::string prompt; 48 | }; 49 | } 50 | -------------------------------------------------------------------------------- /include/Swiften/Elements/HintPayload.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Implements XEP-0334: Message Processing Hints 3 | * Licensed under the Simplified BSD license. 4 | * See Documentation/Licenses/BSD-simplified.txt for more information. 5 | */ 6 | 7 | #include 8 | 9 | namespace Swift { 10 | 11 | HintPayload::HintPayload(Type type) 12 | : type_(type) { 13 | } 14 | 15 | } 16 | -------------------------------------------------------------------------------- /include/Swiften/Elements/HintPayload.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Implements XEP-0334: Message Processing Hints 3 | * Licensed under the Simplified BSD license. 4 | * See Documentation/Licenses/BSD-simplified.txt for more information. 5 | */ 6 | 7 | #pragma once 8 | 9 | #include 10 | #include 11 | 12 | #include 13 | 14 | namespace Swift { 15 | class HintPayload : public Payload { 16 | public: 17 | typedef std::shared_ptr ref; 18 | 19 | enum Type { NoPermanentStore, NoStore, NoCopy, Store }; 20 | 21 | public: 22 | HintPayload(Type type = NoCopy); 23 | 24 | void setType(Type type) { type_ = type; } 25 | const Type getType() { return type_; } 26 | 27 | private: 28 | Type type_; 29 | }; 30 | } 31 | -------------------------------------------------------------------------------- /include/Swiften/Elements/InvisiblePayload.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2011 Jan Kaluza 3 | * Licensed under the Simplified BSD license. 4 | * See Documentation/Licenses/BSD-simplified.txt for more information. 5 | */ 6 | 7 | #include 8 | 9 | namespace Swift { 10 | 11 | // This payload is NOT part of ANY XEP and it is only 12 | // libtransport related extension. 13 | InvisiblePayload::InvisiblePayload() { 14 | 15 | } 16 | 17 | } 18 | -------------------------------------------------------------------------------- /include/Swiften/Elements/InvisiblePayload.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2011 Jan Kaluza 3 | * Licensed under the Simplified BSD license. 4 | * See Documentation/Licenses/BSD-simplified.txt for more information. 5 | */ 6 | 7 | #pragma once 8 | 9 | #include 10 | #include 11 | #include 12 | #include 13 | 14 | 15 | // This payload is NOT part of ANY XEP and it is only 16 | // libtransport related extension. 17 | namespace Swift { 18 | class InvisiblePayload : public Payload { 19 | public: 20 | typedef std::shared_ptr ref; 21 | 22 | public: 23 | InvisiblePayload(); 24 | }; 25 | } 26 | -------------------------------------------------------------------------------- /include/Swiften/Elements/Privilege.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Implements Privilege tag for XEP-0356: Privileged Entity 3 | * Licensed under the Simplified BSD license. 4 | * See Documentation/Licenses/BSD-simplified.txt for more information. 5 | */ 6 | 7 | #include 8 | 9 | namespace Swift { 10 | 11 | Privilege::Privilege() { 12 | } 13 | 14 | } 15 | -------------------------------------------------------------------------------- /include/Swiften/Elements/Privilege.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Implements Privilege tag for XEP-0356: Privileged Entity 3 | * Licensed under the Simplified BSD license. 4 | * See Documentation/Licenses/BSD-simplified.txt for more information. 5 | */ 6 | 7 | #pragma once 8 | 9 | #include 10 | #include 11 | 12 | #include 13 | #include 14 | 15 | #include 16 | #include 17 | 18 | namespace Swift { 19 | class Stanza; 20 | 21 | class Privilege : public Payload { 22 | public: 23 | typedef std::shared_ptr ref; 24 | typedef Swift::Forwarded Forwarded; 25 | 26 | public: 27 | Privilege(); 28 | 29 | void setForwarded(std::shared_ptr forwarded) { forwarded_ = forwarded; } 30 | const std::shared_ptr& getForwarded() const { return forwarded_; } 31 | 32 | private: 33 | std::shared_ptr forwarded_; 34 | }; 35 | } 36 | -------------------------------------------------------------------------------- /include/Swiften/Elements/SpectrumErrorPayload.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2011 Jan Kaluza 3 | * Licensed under the Simplified BSD license. 4 | * See Documentation/Licenses/BSD-simplified.txt for more information. 5 | */ 6 | 7 | #include 8 | 9 | namespace Swift { 10 | 11 | SpectrumErrorPayload::SpectrumErrorPayload(Error error) : error_(error) { } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /include/Swiften/Elements/SpectrumErrorPayload.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2011 Jan Kaluza 3 | * Licensed under the Simplified BSD license. 4 | * See Documentation/Licenses/BSD-simplified.txt for more information. 5 | */ 6 | 7 | #pragma once 8 | 9 | #include 10 | 11 | #include 12 | #include 13 | 14 | namespace Swift { 15 | class SpectrumErrorPayload : public Payload { 16 | public: 17 | enum Error { 18 | CONNECTION_ERROR_NETWORK_ERROR = 0, 19 | CONNECTION_ERROR_INVALID_USERNAME = 1, 20 | CONNECTION_ERROR_AUTHENTICATION_FAILED = 2, 21 | CONNECTION_ERROR_AUTHENTICATION_IMPOSSIBLE = 3, 22 | CONNECTION_ERROR_NO_SSL_SUPPORT = 4, 23 | CONNECTION_ERROR_ENCRYPTION_ERROR = 5, 24 | CONNECTION_ERROR_NAME_IN_USE = 6, 25 | CONNECTION_ERROR_INVALID_SETTINGS = 7, 26 | CONNECTION_ERROR_CERT_NOT_PROVIDED = 8, 27 | CONNECTION_ERROR_CERT_UNTRUSTED = 9, 28 | CONNECTION_ERROR_CERT_EXPIRED = 10, 29 | CONNECTION_ERROR_CERT_NOT_ACTIVATED = 11, 30 | CONNECTION_ERROR_CERT_HOSTNAME_MISMATCH = 12, 31 | CONNECTION_ERROR_CERT_FINGERPRINT_MISMATCH = 13, 32 | CONNECTION_ERROR_CERT_SELF_SIGNED = 14, 33 | CONNECTION_ERROR_CERT_OTHER_ERROR = 15, 34 | CONNECTION_ERROR_OTHER_ERROR = 16 35 | }; 36 | 37 | SpectrumErrorPayload(Error error = CONNECTION_ERROR_OTHER_ERROR); 38 | 39 | Error getError() const { 40 | return error_; 41 | } 42 | 43 | void setError(Error error) { 44 | error_ = error; 45 | } 46 | 47 | private: 48 | Error error_; 49 | }; 50 | } 51 | -------------------------------------------------------------------------------- /include/Swiften/Elements/StatsPayload.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2011 Jan Kaluza 3 | * Licensed under the Simplified BSD license. 4 | * See Documentation/Licenses/BSD-simplified.txt for more information. 5 | */ 6 | 7 | #include 8 | 9 | namespace Swift { 10 | 11 | StatsPayload::StatsPayload() { 12 | } 13 | 14 | } 15 | -------------------------------------------------------------------------------- /include/Swiften/Elements/StatsPayload.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2011 Jan Kaluza 3 | * Licensed under the Simplified BSD license. 4 | * See Documentation/Licenses/BSD-simplified.txt for more information. 5 | */ 6 | 7 | #pragma once 8 | 9 | #include 10 | 11 | #include 12 | #include 13 | 14 | namespace Swift { 15 | class StatsPayload : public Payload { 16 | public: 17 | class Item { 18 | public: 19 | Item(const std::string &name = "", const std::string &units = "", const std::string &value = "") : 20 | name(name), units(units), value(value) { } 21 | 22 | void setName(const std::string &name) { 23 | this->name = name; 24 | } 25 | 26 | const std::string &getName() const { 27 | return name; 28 | } 29 | 30 | void setUnits(const std::string &units) { 31 | this->units = units; 32 | } 33 | 34 | const std::string &getUnits() const { 35 | return units; 36 | } 37 | 38 | void setValue(const std::string &value) { 39 | this->value = value; 40 | } 41 | 42 | const std::string &getValue() const { 43 | return value; 44 | } 45 | 46 | private: 47 | std::string name; 48 | std::string units; 49 | std::string value; 50 | }; 51 | 52 | typedef std::vector StatsPayloadItems; 53 | 54 | StatsPayload(); 55 | 56 | void addItem(const StatsPayload::Item &item) { 57 | items.push_back(item); 58 | } 59 | 60 | const StatsPayloadItems &getItems() const { 61 | return items; 62 | } 63 | 64 | private: 65 | StatsPayloadItems items; 66 | }; 67 | } 68 | -------------------------------------------------------------------------------- /include/Swiften/Elements/XHTMLIMPayload.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2011 Jan Kaluza 3 | * Licensed under the Simplified BSD license. 4 | * See Documentation/Licenses/BSD-simplified.txt for more information. 5 | */ 6 | 7 | #include 8 | 9 | namespace Swift { 10 | 11 | XHTMLIMPayload::XHTMLIMPayload(const std::string &body) : body_(body) { 12 | } 13 | 14 | } 15 | -------------------------------------------------------------------------------- /include/Swiften/Elements/XHTMLIMPayload.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2011 Jan Kaluza 3 | * Licensed under the Simplified BSD license. 4 | * See Documentation/Licenses/BSD-simplified.txt for more information. 5 | */ 6 | 7 | #pragma once 8 | 9 | #include 10 | 11 | #include 12 | #include 13 | 14 | namespace Swift { 15 | class XHTMLIMPayload : public Payload { 16 | public: 17 | XHTMLIMPayload(const std::string &body = ""); 18 | 19 | const std::string& getBody() const { return body_; } 20 | 21 | void setBody(const std::string& body) { 22 | body_ = body; 23 | } 24 | 25 | private: 26 | std::string body_; 27 | }; 28 | } 29 | -------------------------------------------------------------------------------- /include/Swiften/Network/DummyConnectionServer.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2010 Remko Tronçon 3 | * Licensed under the GNU General Public License v3. 4 | * See Documentation/Licenses/GPLv3.txt for more information. 5 | */ 6 | 7 | #include 8 | 9 | #include 10 | #include 11 | #include 12 | 13 | #include 14 | 15 | namespace Swift { 16 | 17 | DummyConnectionServer::DummyConnectionServer(EventLoop* eventLoop) : eventLoop(eventLoop) { 18 | } 19 | 20 | void DummyConnectionServer::start() { 21 | } 22 | 23 | 24 | void DummyConnectionServer::stop() { 25 | 26 | } 27 | 28 | void DummyConnectionServer::acceptConnection(std::shared_ptr connection) { 29 | eventLoop->postEvent( 30 | boost::bind(boost::ref(onNewConnection), connection)); 31 | // connection->listen(); 32 | } 33 | 34 | 35 | HostAddressPort DummyConnectionServer::getAddressPort() const { 36 | return HostAddressPort(); 37 | } 38 | 39 | } 40 | -------------------------------------------------------------------------------- /include/Swiften/Network/DummyConnectionServer.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2010 Remko Tronçon 3 | * Licensed under the GNU General Public License v3. 4 | * See Documentation/Licenses/GPLv3.txt for more information. 5 | */ 6 | 7 | #pragma once 8 | 9 | #include 10 | #include 11 | #include 12 | #include 13 | 14 | #include 15 | #include 16 | #include 17 | #include 18 | 19 | namespace Swift { 20 | class DummyConnectionServer : public ConnectionServer { 21 | public: 22 | enum Error { 23 | Conflict, 24 | UnknownError 25 | }; 26 | 27 | static std::shared_ptr create(EventLoop* eventLoop) { 28 | return std::shared_ptr(new DummyConnectionServer(eventLoop)); 29 | } 30 | 31 | void acceptConnection(std::shared_ptr connection); 32 | 33 | virtual boost::optional tryStart() { 34 | return boost::optional(); 35 | } 36 | 37 | virtual void start(); 38 | virtual void stop(); 39 | 40 | virtual HostAddressPort getAddressPort() const; 41 | 42 | 43 | private: 44 | DummyConnectionServer(EventLoop* eventLoop); 45 | 46 | 47 | private: 48 | HostAddress address_; 49 | EventLoop* eventLoop; 50 | }; 51 | } 52 | -------------------------------------------------------------------------------- /include/Swiften/Network/DummyConnectionServerFactory.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2011 Jan Kaluza 3 | * Licensed under the Simplified BSD license. 4 | * See Documentation/Licenses/BSD-simplified.txt for more information. 5 | */ 6 | 7 | #include 8 | #include 9 | 10 | namespace Swift { 11 | 12 | DummyConnectionServerFactory::DummyConnectionServerFactory(EventLoop* eventLoop) : eventLoop(eventLoop) { 13 | } 14 | 15 | std::shared_ptr DummyConnectionServerFactory::createConnectionServer(int port) { 16 | return DummyConnectionServer::create(eventLoop); 17 | } 18 | 19 | std::shared_ptr DummyConnectionServerFactory::createConnectionServer(const Swift::HostAddress &hostAddress, int port) { 20 | return DummyConnectionServer::create(eventLoop); 21 | } 22 | 23 | } 24 | -------------------------------------------------------------------------------- /include/Swiften/Network/DummyConnectionServerFactory.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2011 Jan Kaluza 3 | * Licensed under the Simplified BSD license. 4 | * See Documentation/Licenses/BSD-simplified.txt for more information. 5 | */ 6 | 7 | #pragma once 8 | 9 | #include 10 | 11 | #include 12 | #include 13 | 14 | namespace Swift { 15 | class ConnectionServer; 16 | 17 | class DummyConnectionServerFactory : public ConnectionServerFactory { 18 | public: 19 | DummyConnectionServerFactory(EventLoop* eventLoop); 20 | 21 | virtual std::shared_ptr createConnectionServer(int port); 22 | 23 | virtual std::shared_ptr createConnectionServer(const Swift::HostAddress &hostAddress, int port); 24 | 25 | private: 26 | EventLoop* eventLoop; 27 | }; 28 | } 29 | -------------------------------------------------------------------------------- /include/Swiften/Network/DummyNetworkFactories.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2010 Remko Tronçon 3 | * Licensed under the GNU General Public License v3. 4 | * See Documentation/Licenses/GPLv3.txt for more information. 5 | */ 6 | 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | 17 | namespace Swift { 18 | 19 | DummyNetworkFactories::DummyNetworkFactories(EventLoop* eventLoop) { 20 | timerFactory = new DummyTimerFactory(); 21 | connectionFactory = new DummyConnectionFactory(eventLoop); 22 | idnConverter = std::shared_ptr(PlatformIDNConverter::create()); 23 | domainNameResolver = new PlatformDomainNameResolver(idnConverter.get(), eventLoop); 24 | cryptoProvider = PlatformCryptoProvider::create(); 25 | networkEnvironment = new PlatformNetworkEnvironment(); 26 | connectionServerFactory = new DummyConnectionServerFactory(eventLoop); 27 | m_platformXMLParserFactory = new PlatformXMLParserFactory(); 28 | this->eventLoop = eventLoop; 29 | } 30 | 31 | DummyNetworkFactories::~DummyNetworkFactories() { 32 | delete connectionServerFactory; 33 | delete domainNameResolver; 34 | delete connectionFactory; 35 | delete timerFactory; 36 | delete m_platformXMLParserFactory; 37 | delete cryptoProvider; 38 | delete networkEnvironment; 39 | } 40 | 41 | } 42 | -------------------------------------------------------------------------------- /include/Swiften/Parser/PayloadParsers/AttentionParser.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2011 Jan Kaluza 3 | * Licensed under the Simplified BSD license. 4 | * See Documentation/Licenses/BSD-simplified.txt for more information. 5 | */ 6 | 7 | #include 8 | 9 | namespace Swift { 10 | 11 | AttentionParser::AttentionParser() /*: level_(0)*/ { 12 | } 13 | 14 | void AttentionParser::handleStartElement(const std::string& /*element*/, const std::string& /*ns*/, const AttributeMap& /*attributes*/) { 15 | } 16 | 17 | void AttentionParser::handleEndElement(const std::string&, const std::string&) { 18 | } 19 | 20 | void AttentionParser::handleCharacterData(const std::string&) { 21 | 22 | } 23 | 24 | } 25 | -------------------------------------------------------------------------------- /include/Swiften/Parser/PayloadParsers/AttentionParser.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2011 Jan Kaluza 3 | * Licensed under the Simplified BSD license. 4 | * See Documentation/Licenses/BSD-simplified.txt for more information. 5 | */ 6 | 7 | #pragma once 8 | 9 | #include 10 | #include 11 | 12 | namespace Swift { 13 | class AttentionParser : public GenericPayloadParser { 14 | public: 15 | AttentionParser(); 16 | 17 | virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes); 18 | virtual void handleEndElement(const std::string& element, const std::string&); 19 | virtual void handleCharacterData(const std::string& data); 20 | 21 | // private: 22 | // int level_; 23 | }; 24 | } 25 | -------------------------------------------------------------------------------- /include/Swiften/Parser/PayloadParsers/GatewayPayloadParser.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2012 Jan Kaluza 3 | * Licensed under the Simplified BSD license. 4 | * See Documentation/Licenses/BSD-simplified.txt for more information. 5 | */ 6 | 7 | #include 8 | 9 | #include 10 | #include 11 | 12 | #include 13 | #include 14 | #include 15 | #include 16 | 17 | namespace Swift { 18 | 19 | void GatewayPayloadParser::handleTree(ParserElement::ref root) { 20 | BOOST_FOREACH (ParserElement::ref child, root->getAllChildren()) { 21 | if (child->getName() == "desc") { 22 | getPayloadInternal()->setDesc(child->getText()); 23 | } 24 | else if (child->getName() == "prompt") { 25 | getPayloadInternal()->setPrompt(child->getText()); 26 | } 27 | else if (child->getName() == "jid") { 28 | getPayloadInternal()->setJID(child->getText()); 29 | } 30 | } 31 | } 32 | 33 | } 34 | -------------------------------------------------------------------------------- /include/Swiften/Parser/PayloadParsers/GatewayPayloadParser.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2012 Jan Kaluza 3 | * Licensed under the Simplified BSD license. 4 | * See Documentation/Licenses/BSD-simplified.txt for more information. 5 | */ 6 | 7 | #pragma once 8 | 9 | #include 10 | 11 | #include 12 | #include 13 | #include 14 | 15 | namespace Swift { 16 | class GatewayPayloadParser : public GenericPayloadTreeParser { 17 | public: 18 | GatewayPayloadParser() {} 19 | virtual void handleTree(ParserElement::ref root); 20 | }; 21 | } 22 | -------------------------------------------------------------------------------- /include/Swiften/Parser/PayloadParsers/HintPayloadParser.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Implements XEP-0334: Message Processing Hints 3 | * Licensed under the Simplified BSD license. 4 | * See Documentation/Licenses/BSD-simplified.txt for more information. 5 | */ 6 | 7 | #include 8 | 9 | namespace Swift { 10 | 11 | HintPayloadParser::HintPayloadParser() : level_(0) { 12 | } 13 | 14 | void HintPayloadParser::handleStartElement(const std::string& element, const std::string& /*ns*/, const AttributeMap& /*attributes*/) { 15 | if (level_ == 0) { 16 | HintPayload::Type type = HintPayload::NoCopy; 17 | if (element == "no-permanent-store") { 18 | type = HintPayload::NoPermanentStore; 19 | } else if (element == "no-store") { 20 | type = HintPayload::NoStore; 21 | } else if (element == "no-copy") { 22 | type = HintPayload::NoCopy; 23 | } else if (element == "store") { 24 | type = HintPayload::Store; 25 | } 26 | getPayloadInternal()->setType(type); 27 | } 28 | ++level_; 29 | } 30 | 31 | void HintPayloadParser::handleEndElement(const std::string&, const std::string&) { 32 | --level_; 33 | } 34 | 35 | void HintPayloadParser::handleCharacterData(const std::string&) { 36 | } 37 | 38 | } 39 | -------------------------------------------------------------------------------- /include/Swiften/Parser/PayloadParsers/HintPayloadParser.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Implements XEP-0334: Message Processing Hints 3 | * Licensed under the Simplified BSD license. 4 | * See Documentation/Licenses/BSD-simplified.txt for more information. 5 | */ 6 | 7 | #pragma once 8 | 9 | #include 10 | #include 11 | 12 | namespace Swift { 13 | class HintPayloadParser : public GenericPayloadParser { 14 | public: 15 | HintPayloadParser(); 16 | 17 | virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes); 18 | virtual void handleEndElement(const std::string& element, const std::string&); 19 | virtual void handleCharacterData(const std::string& data); 20 | 21 | private: 22 | int level_; 23 | }; 24 | } 25 | -------------------------------------------------------------------------------- /include/Swiften/Parser/PayloadParsers/InvisibleParser.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2011 Jan Kaluza 3 | * Licensed under the Simplified BSD license. 4 | * See Documentation/Licenses/BSD-simplified.txt for more information. 5 | */ 6 | 7 | #include 8 | 9 | namespace Swift { 10 | 11 | // This payload is NOT part of ANY XEP and it is only 12 | // libtransport related extension. 13 | InvisibleParser::InvisibleParser() /*: level_(0)*/ { 14 | } 15 | 16 | void InvisibleParser::handleStartElement(const std::string& /*element*/, const std::string& /*ns*/, const AttributeMap& /*attributes*/) { 17 | } 18 | 19 | void InvisibleParser::handleEndElement(const std::string&, const std::string&) { 20 | } 21 | 22 | void InvisibleParser::handleCharacterData(const std::string&) { 23 | 24 | } 25 | 26 | } 27 | -------------------------------------------------------------------------------- /include/Swiften/Parser/PayloadParsers/InvisibleParser.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2011 Jan Kaluza 3 | * Licensed under the Simplified BSD license. 4 | * See Documentation/Licenses/BSD-simplified.txt for more information. 5 | */ 6 | 7 | #pragma once 8 | 9 | #include 10 | #include 11 | 12 | // This payload is NOT part of ANY XEP and it is only 13 | // libtransport related extension. 14 | namespace Swift { 15 | class InvisibleParser : public GenericPayloadParser { 16 | public: 17 | InvisibleParser(); 18 | 19 | virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes); 20 | virtual void handleEndElement(const std::string& element, const std::string&); 21 | virtual void handleCharacterData(const std::string& data); 22 | 23 | // private: 24 | // int level_; 25 | }; 26 | } 27 | -------------------------------------------------------------------------------- /include/Swiften/Parser/PayloadParsers/MUCPayloadParser.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2010 Kevin Smith 3 | * Licensed under the GNU General Public License v3. 4 | * See Documentation/Licenses/GPLv3.txt for more information. 5 | */ 6 | 7 | #include 8 | 9 | #include 10 | #include 11 | 12 | #include 13 | #include 14 | #include 15 | #include 16 | 17 | namespace Swift { 18 | 19 | void MUCPayloadParser::handleTree(ParserElement::ref root) { 20 | BOOST_FOREACH (ParserElement::ref child, root->getAllChildren()) { 21 | if (child->getName() == "password" && child->getNamespace() == root->getNamespace()) { 22 | getPayloadInternal()->setPassword(child->getText()); 23 | } 24 | } 25 | } 26 | 27 | } 28 | -------------------------------------------------------------------------------- /include/Swiften/Parser/PayloadParsers/MUCPayloadParser.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2010 Kevin Smith 3 | * Licensed under the GNU General Public License v3. 4 | * See Documentation/Licenses/GPLv3.txt for more information. 5 | */ 6 | 7 | #pragma once 8 | 9 | #include 10 | 11 | #include 12 | #include 13 | #include 14 | 15 | namespace Swift { 16 | class PayloadParserFactoryCollection; 17 | class MUCPayloadParser : public GenericPayloadTreeParser { 18 | public: 19 | MUCPayloadParser(){} 20 | virtual void handleTree(ParserElement::ref root); 21 | }; 22 | } 23 | -------------------------------------------------------------------------------- /include/Swiften/Parser/PayloadParsers/PrivilegeParser.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Implements Privilege tag for XEP-0356: Privileged Entity 3 | * Licensed under the Simplified BSD license. 4 | * See Documentation/Licenses/BSD-simplified.txt for more information. 5 | */ 6 | 7 | #include 8 | #include 9 | 10 | namespace Swift { 11 | 12 | PrivilegeParser::PrivilegeParser(PayloadParserFactoryCollection* factories) : factories_(factories), level_(TopLevel) { 13 | } 14 | 15 | void PrivilegeParser::handleStartElement(const std::string& element, const std::string& ns, const AttributeMap& attributes) { 16 | if (level_ == PayloadLevel) { 17 | if (element == "forwarded" && ns == "urn:xmpp:forward:0") { 18 | childParser_ = std::dynamic_pointer_cast(std::make_shared(factories_)); 19 | }; 20 | } 21 | if (childParser_) { 22 | childParser_->handleStartElement(element, ns, attributes); 23 | } 24 | ++level_; 25 | } 26 | 27 | void PrivilegeParser::handleEndElement(const std::string& element, const std::string& ns) { 28 | --level_; 29 | if (childParser_ && level_ >= PayloadLevel) { 30 | childParser_->handleEndElement(element, ns); 31 | } 32 | if (childParser_ && level_ == PayloadLevel) { 33 | getPayloadInternal()->setForwarded(std::dynamic_pointer_cast(childParser_->getPayload())); 34 | childParser_.reset(); 35 | } 36 | } 37 | 38 | void PrivilegeParser::handleCharacterData(const std::string& data) { 39 | if (childParser_) { 40 | childParser_->handleCharacterData(data); 41 | } 42 | } 43 | 44 | } 45 | -------------------------------------------------------------------------------- /include/Swiften/Parser/PayloadParsers/PrivilegeParser.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Implements Privilege tag for XEP-0356: Privileged Entity 3 | * Licensed under the Simplified BSD license. 4 | * See Documentation/Licenses/BSD-simplified.txt for more information. 5 | */ 6 | 7 | #pragma once 8 | 9 | #include 10 | #include 11 | #include 12 | 13 | namespace Swift { 14 | class PayloadParserFactoryCollection; 15 | class PayloadParser; 16 | 17 | class PrivilegeParser : public GenericPayloadParser { 18 | public: 19 | PrivilegeParser(PayloadParserFactoryCollection* factories); 20 | 21 | virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes); 22 | virtual void handleEndElement(const std::string& element, const std::string&); 23 | virtual void handleCharacterData(const std::string& data); 24 | 25 | enum Level { 26 | TopLevel = 0, 27 | PayloadLevel = 1 28 | }; 29 | 30 | private: 31 | PayloadParserFactoryCollection* factories_; 32 | std::shared_ptr childParser_; 33 | int level_; 34 | }; 35 | } 36 | -------------------------------------------------------------------------------- /include/Swiften/Parser/PayloadParsers/StatsParser.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2011 Jan Kaluza 3 | * Licensed under the Simplified BSD license. 4 | * See Documentation/Licenses/BSD-simplified.txt for more information. 5 | */ 6 | 7 | #include 8 | #include 9 | 10 | namespace Swift { 11 | 12 | StatsParser::StatsParser() : level_(TopLevel), inItem_(false) { 13 | } 14 | 15 | void StatsParser::handleStartElement(const std::string& element, const std::string& /*ns*/, const AttributeMap& attributes) { 16 | if (level_ == PayloadLevel) { 17 | if (element == "stat") { 18 | inItem_ = true; 19 | 20 | currentItem_ = StatsPayload::Item(); 21 | 22 | currentItem_.setName(attributes.getAttribute("name")); 23 | currentItem_.setValue(attributes.getAttribute("value")); 24 | currentItem_.setUnits(attributes.getAttribute("units")); 25 | } 26 | } 27 | ++level_; 28 | } 29 | 30 | void StatsParser::handleEndElement(const std::string& element, const std::string& /*ns*/) { 31 | --level_; 32 | if (level_ == PayloadLevel) { 33 | if (inItem_) { 34 | getPayloadInternal()->addItem(currentItem_); 35 | inItem_ = false; 36 | } 37 | } 38 | } 39 | 40 | void StatsParser::handleCharacterData(const std::string& data) { 41 | } 42 | 43 | } 44 | -------------------------------------------------------------------------------- /include/Swiften/Parser/PayloadParsers/StatsParser.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2011 Jan Kaluza 3 | * Licensed under the Simplified BSD license. 4 | * See Documentation/Licenses/BSD-simplified.txt for more information. 5 | */ 6 | 7 | #pragma once 8 | 9 | #include 10 | #include 11 | 12 | namespace Swift { 13 | class SerializingParser; 14 | 15 | class StatsParser : public GenericPayloadParser { 16 | public: 17 | StatsParser(); 18 | 19 | virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes); 20 | virtual void handleEndElement(const std::string& element, const std::string&); 21 | virtual void handleCharacterData(const std::string& data); 22 | 23 | private: 24 | enum Level { 25 | TopLevel = 0, 26 | PayloadLevel = 1, 27 | ItemLevel = 2 28 | }; 29 | int level_; 30 | bool inItem_; 31 | StatsPayload::Item currentItem_; 32 | }; 33 | } 34 | -------------------------------------------------------------------------------- /include/Swiften/Parser/PayloadParsers/XHTMLIMParser.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2011 Jan Kaluza 3 | * Licensed under the Simplified BSD license. 4 | * See Documentation/Licenses/BSD-simplified.txt for more information. 5 | */ 6 | 7 | #include 8 | #include 9 | #include 10 | 11 | namespace Swift { 12 | 13 | XHTMLIMParser::XHTMLIMParser() : level_(TopLevel), bodyParser_(0) { 14 | } 15 | 16 | void XHTMLIMParser::handleStartElement(const std::string& element, const std::string& ns, const AttributeMap& attributes) { 17 | ++level_; 18 | if (level_ == BodyLevel) { 19 | if (element == "body") { 20 | assert(!bodyParser_); 21 | bodyParser_ = new SerializingParser(); 22 | } 23 | } 24 | else if (level_ >= InsideBodyLevel && bodyParser_) { 25 | bodyParser_->handleStartElement(element, "", attributes); 26 | } 27 | } 28 | 29 | void XHTMLIMParser::handleEndElement(const std::string& element, const std::string& ns) { 30 | if (level_ == BodyLevel) { 31 | if (bodyParser_) { 32 | if (element == "body") { 33 | getPayloadInternal()->setBody(bodyParser_->getResult()); 34 | } 35 | delete bodyParser_; 36 | bodyParser_ = 0; 37 | } 38 | } 39 | else if (bodyParser_ && level_ >= InsideBodyLevel) { 40 | bodyParser_->handleEndElement(element, ns); 41 | } 42 | --level_; 43 | } 44 | 45 | void XHTMLIMParser::handleCharacterData(const std::string& data) { 46 | if (bodyParser_) { 47 | bodyParser_->handleCharacterData(data); 48 | } 49 | else { 50 | currentText_ += data; 51 | } 52 | } 53 | 54 | std::shared_ptr XHTMLIMParser::getLabelPayload() const { 55 | return getPayloadInternal(); 56 | } 57 | 58 | } 59 | -------------------------------------------------------------------------------- /include/Swiften/Parser/PayloadParsers/XHTMLIMParser.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2011 Jan Kaluza 3 | * Licensed under the Simplified BSD license. 4 | * See Documentation/Licenses/BSD-simplified.txt for more information. 5 | */ 6 | 7 | #pragma once 8 | 9 | #include 10 | #include 11 | 12 | namespace Swift { 13 | class SerializingParser; 14 | 15 | class XHTMLIMParser : public GenericPayloadParser { 16 | public: 17 | XHTMLIMParser(); 18 | 19 | virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes); 20 | virtual void handleEndElement(const std::string& element, const std::string&); 21 | virtual void handleCharacterData(const std::string& data); 22 | std::shared_ptr getLabelPayload() const; 23 | private: 24 | enum Level { 25 | TopLevel = 0, 26 | PayloadLevel = 1, 27 | BodyLevel = 2, 28 | InsideBodyLevel = 3 29 | }; 30 | int level_; 31 | SerializingParser* bodyParser_; 32 | std::string currentText_; 33 | }; 34 | } 35 | -------------------------------------------------------------------------------- /include/Swiften/Parser/StringTreeParser.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2011 Jan Kaluza 3 | * Licensed under the Simplified BSD license. 4 | * See Documentation/Licenses/BSD-simplified.txt for more information. 5 | */ 6 | 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | 13 | namespace Swift { 14 | 15 | class DefaultStringTreeParser : public StringTreeParser { 16 | public: 17 | void handleTree(ParserElement::ref root) { 18 | root_ = root; 19 | } 20 | 21 | ParserElement::ref getRoot() { 22 | return root_; 23 | } 24 | 25 | private: 26 | ParserElement::ref root_; 27 | }; 28 | 29 | ParserElement::ref StringTreeParser::parse(const std::string &xml) { 30 | PlatformXMLParserFactory factory; 31 | DefaultStringTreeParser client; 32 | std::unique_ptr parser = factory.createXMLParser(&client); 33 | 34 | parser->parse(xml); 35 | ParserElement::ref root = client.getRoot(); 36 | return root; 37 | } 38 | 39 | } 40 | -------------------------------------------------------------------------------- /include/Swiften/Parser/StringTreeParser.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2011 Jan Kaluza 3 | * Licensed under the Simplified BSD license. 4 | * See Documentation/Licenses/BSD-simplified.txt for more information. 5 | */ 6 | 7 | #pragma once 8 | 9 | #include 10 | 11 | #include 12 | #include 13 | 14 | namespace Swift { 15 | /** 16 | * Generics parser offering something a bit like a DOM to work with. 17 | */ 18 | class StringTreeParser : public XMLParserClient { 19 | public: 20 | StringTreeParser() : XMLParserClient() {} 21 | 22 | virtual void handleStartElement(const std::string& element, const std::string& xmlns, const AttributeMap& attributes) { 23 | if (!root_) { 24 | root_ = std::make_shared(element, xmlns, attributes); 25 | elementStack_.push_back(root_); 26 | } 27 | else { 28 | ParserElement::ref current = *elementStack_.rbegin(); 29 | elementStack_.push_back(current->addChild(element, xmlns, attributes)); 30 | } 31 | } 32 | 33 | virtual void handleEndElement(const std::string& /*element*/, const std::string&) { 34 | elementStack_.pop_back(); 35 | if (elementStack_.empty()) { 36 | handleTree(root_); 37 | } 38 | } 39 | 40 | virtual void handleCharacterData(const std::string& data) { 41 | ParserElement::ref current = *elementStack_.rbegin(); 42 | current->appendCharacterData(data); 43 | } 44 | 45 | virtual void handleTree(ParserElement::ref root) = 0; 46 | 47 | static ParserElement::ref parse(const std::string &xml); 48 | 49 | private: 50 | std::deque elementStack_; 51 | ParserElement::ref root_; 52 | }; 53 | } 54 | -------------------------------------------------------------------------------- /include/Swiften/Serializer/PayloadSerializers/AttentionSerializer.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2011 Jan Kaluza 3 | * Licensed under the Simplified BSD license. 4 | * See Documentation/Licenses/BSD-simplified.txt for more information. 5 | */ 6 | 7 | #include 8 | 9 | #include 10 | 11 | #include 12 | #include 13 | #include 14 | 15 | namespace Swift { 16 | 17 | AttentionSerializer::AttentionSerializer() : GenericPayloadSerializer() { 18 | } 19 | 20 | std::string AttentionSerializer::serializePayload(std::shared_ptr attention) const { 21 | XMLElement attentionElement("attention", "urn:xmpp:attention:0"); 22 | 23 | return attentionElement.serialize(); 24 | } 25 | 26 | } 27 | -------------------------------------------------------------------------------- /include/Swiften/Serializer/PayloadSerializers/AttentionSerializer.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2011 Jan Kaluza 3 | * Licensed under the Simplified BSD license. 4 | * See Documentation/Licenses/BSD-simplified.txt for more information. 5 | */ 6 | 7 | #pragma once 8 | 9 | #include 10 | #include 11 | 12 | namespace Swift { 13 | class AttentionSerializer : public GenericPayloadSerializer { 14 | public: 15 | AttentionSerializer(); 16 | 17 | virtual std::string serializePayload(std::shared_ptr) const; 18 | }; 19 | } 20 | -------------------------------------------------------------------------------- /include/Swiften/Serializer/PayloadSerializers/GatewayPayloadSerializer.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2011 Jan Kaluza 3 | * Licensed under the Simplified BSD license. 4 | * See Documentation/Licenses/BSD-simplified.txt for more information. 5 | */ 6 | 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | 13 | namespace Swift { 14 | 15 | GatewayPayloadSerializer::GatewayPayloadSerializer() 16 | : GenericPayloadSerializer() { 17 | } 18 | 19 | std::string GatewayPayloadSerializer::serializePayload(std::shared_ptr payload) const { 20 | XMLElement query("query", "jabber:iq:gateway"); 21 | 22 | if (payload->getJID().isValid()) { 23 | std::shared_ptr jid(new XMLElement("jid", "", payload->getJID().toBare().toString())); 24 | query.addNode(jid); 25 | } 26 | 27 | if (!payload->getDesc().empty()) { 28 | std::shared_ptr desc(new XMLElement("desc", "", payload->getDesc())); 29 | query.addNode(desc); 30 | } 31 | 32 | if (!payload->getPrompt().empty()) { 33 | std::shared_ptr prompt(new XMLElement("prompt", "", payload->getPrompt())); 34 | query.addNode(prompt); 35 | } 36 | 37 | return query.serialize(); 38 | } 39 | 40 | } 41 | -------------------------------------------------------------------------------- /include/Swiften/Serializer/PayloadSerializers/GatewayPayloadSerializer.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2011 Jan Kaluza 3 | * Licensed under the Simplified BSD license. 4 | * See Documentation/Licenses/BSD-simplified.txt for more information. 5 | */ 6 | 7 | #pragma once 8 | 9 | #include 10 | #include 11 | 12 | namespace Swift { 13 | class GatewayPayloadSerializer : public GenericPayloadSerializer { 14 | public: 15 | GatewayPayloadSerializer(); 16 | 17 | virtual std::string serializePayload(std::shared_ptr item) const; 18 | }; 19 | } 20 | -------------------------------------------------------------------------------- /include/Swiften/Serializer/PayloadSerializers/HintPayloadSerializer.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Implements XEP-0334: Message Processing Hints 3 | * Licensed under the Simplified BSD license. 4 | * See Documentation/Licenses/BSD-simplified.txt for more information. 5 | */ 6 | 7 | #include 8 | 9 | #include 10 | 11 | #include 12 | 13 | #include 14 | #include 15 | #include 16 | 17 | namespace Swift { 18 | 19 | HintPayloadSerializer::HintPayloadSerializer() : GenericPayloadSerializer() { 20 | } 21 | 22 | std::string HintPayloadSerializer::serializePayload(std::shared_ptr hint) const { 23 | std::string tagname = ""; 24 | switch(hint->getType()) { 25 | case HintPayload::NoPermanentStore: tagname = "no-permanent-store"; break; 26 | case HintPayload::NoStore: tagname = "no-store"; break; 27 | case HintPayload::NoCopy: tagname = "no-copy"; break; 28 | case HintPayload::Store: tagname = "store"; break; 29 | } 30 | 31 | return XMLElement(tagname, "urn:xmpp:hints").serialize(); 32 | } 33 | 34 | } 35 | -------------------------------------------------------------------------------- /include/Swiften/Serializer/PayloadSerializers/HintPayloadSerializer.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Implements XEP-0334: Message Processing Hints 3 | * Licensed under the Simplified BSD license. 4 | * See Documentation/Licenses/BSD-simplified.txt for more information. 5 | */ 6 | 7 | #pragma once 8 | 9 | #include 10 | #include 11 | 12 | namespace Swift { 13 | class HintPayloadSerializer : public GenericPayloadSerializer { 14 | public: 15 | HintPayloadSerializer(); 16 | 17 | virtual std::string serializePayload(std::shared_ptr) const; 18 | }; 19 | } 20 | -------------------------------------------------------------------------------- /include/Swiften/Serializer/PayloadSerializers/InvisibleSerializer.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2011 Jan Kaluza 3 | * Licensed under the Simplified BSD license. 4 | * See Documentation/Licenses/BSD-simplified.txt for more information. 5 | */ 6 | 7 | #include 8 | 9 | #include 10 | 11 | #include 12 | #include 13 | #include 14 | 15 | namespace Swift { 16 | 17 | // This payload is NOT part of ANY XEP and it is only 18 | // libtransport related extension. 19 | InvisibleSerializer::InvisibleSerializer() : GenericPayloadSerializer() { 20 | } 21 | 22 | std::string InvisibleSerializer::serializePayload(std::shared_ptr attention) const { 23 | XMLElement attentionElement("invisible", "urn:xmpp:invisible:0"); 24 | 25 | return attentionElement.serialize(); 26 | } 27 | 28 | } 29 | -------------------------------------------------------------------------------- /include/Swiften/Serializer/PayloadSerializers/InvisibleSerializer.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2011 Jan Kaluza 3 | * Licensed under the Simplified BSD license. 4 | * See Documentation/Licenses/BSD-simplified.txt for more information. 5 | */ 6 | 7 | #pragma once 8 | 9 | #include 10 | #include 11 | 12 | // This payload is NOT part of ANY XEP and it is only 13 | // libtransport related extension. 14 | namespace Swift { 15 | class InvisibleSerializer : public GenericPayloadSerializer { 16 | public: 17 | InvisibleSerializer(); 18 | 19 | virtual std::string serializePayload(std::shared_ptr) const; 20 | }; 21 | } 22 | -------------------------------------------------------------------------------- /include/Swiften/Serializer/PayloadSerializers/PrivilegeSerializer.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Implements Privilege tag for XEP-0356: Privileged Entity 3 | * Licensed under the Simplified BSD license. 4 | * See Documentation/Licenses/BSD-simplified.txt for more information. 5 | */ 6 | 7 | #include 8 | 9 | #include 10 | 11 | #include 12 | #include 13 | #include 14 | 15 | #include 16 | #include 17 | 18 | namespace Swift { 19 | 20 | PrivilegeSerializer::PrivilegeSerializer(PayloadSerializerCollection* serializers) : GenericPayloadSerializer(), serializers_(serializers) { 21 | } 22 | 23 | PrivilegeSerializer::~PrivilegeSerializer() { 24 | } 25 | 26 | std::string PrivilegeSerializer::serializePayload(std::shared_ptr payload) const { 27 | if (!payload) { 28 | return ""; 29 | } 30 | 31 | XMLElement element("privilege", "urn:xmpp:privilege:1"); 32 | 33 | std::shared_ptr forwarded(payload->getForwarded()); 34 | if (forwarded) { 35 | std::string forwardedStr = ""; 36 | forwardedStr = ForwardedSerializer(serializers_).serialize(forwarded); 37 | element.addNode(std::make_shared(forwardedStr)); 38 | } 39 | 40 | return element.serialize(); 41 | } 42 | 43 | } 44 | -------------------------------------------------------------------------------- /include/Swiften/Serializer/PayloadSerializers/PrivilegeSerializer.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Implements Privilege tag for XEP-0356: Privileged Entity 3 | * Licensed under the Simplified BSD license. 4 | * See Documentation/Licenses/BSD-simplified.txt for more information. 5 | */ 6 | 7 | #pragma once 8 | 9 | #include 10 | #include 11 | 12 | namespace Swift { 13 | class PayloadSerializerCollection; 14 | 15 | class PrivilegeSerializer : public GenericPayloadSerializer { 16 | public: 17 | PrivilegeSerializer(PayloadSerializerCollection* serializers); 18 | virtual ~PrivilegeSerializer(); 19 | 20 | virtual std::string serializePayload(std::shared_ptr) const; 21 | 22 | private: 23 | PayloadSerializerCollection* serializers_; 24 | }; 25 | } 26 | -------------------------------------------------------------------------------- /include/Swiften/Serializer/PayloadSerializers/SpectrumErrorSerializer.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2011 Jan Kaluza 3 | * Licensed under the Simplified BSD license. 4 | * See Documentation/Licenses/BSD-simplified.txt for more information. 5 | */ 6 | 7 | #pragma once 8 | 9 | #include 10 | #include 11 | 12 | namespace Swift { 13 | class SpectrumErrorSerializer : public GenericPayloadSerializer { 14 | public: 15 | SpectrumErrorSerializer(); 16 | 17 | virtual std::string serializePayload(std::shared_ptr) const; 18 | }; 19 | } 20 | -------------------------------------------------------------------------------- /include/Swiften/Serializer/PayloadSerializers/StatsSerializer.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2011 Jan Kaluza 3 | * Licensed under the Simplified BSD license. 4 | * See Documentation/Licenses/BSD-simplified.txt for more information. 5 | */ 6 | 7 | #include 8 | 9 | #include 10 | 11 | #include 12 | #include 13 | #include 14 | 15 | namespace Swift { 16 | 17 | StatsSerializer::StatsSerializer() : GenericPayloadSerializer() { 18 | } 19 | 20 | std::string StatsSerializer::serializePayload(std::shared_ptr stats) const { 21 | XMLElement queryElement("query", "http://jabber.org/protocol/stats"); 22 | BOOST_FOREACH(const StatsPayload::Item& item, stats->getItems()) { 23 | std::shared_ptr statElement = std::make_shared("stat"); 24 | statElement->setAttribute("name", item.getName()); 25 | if (!item.getUnits().empty()) { 26 | statElement->setAttribute("units", item.getUnits()); 27 | } 28 | if (!item.getValue().empty()) { 29 | statElement->setAttribute("value", item.getValue()); 30 | } 31 | 32 | queryElement.addNode(statElement); 33 | } 34 | 35 | return queryElement.serialize(); 36 | } 37 | 38 | } 39 | -------------------------------------------------------------------------------- /include/Swiften/Serializer/PayloadSerializers/StatsSerializer.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2011 Jan Kaluza 3 | * Licensed under the Simplified BSD license. 4 | * See Documentation/Licenses/BSD-simplified.txt for more information. 5 | */ 6 | 7 | #pragma once 8 | 9 | #include 10 | #include 11 | 12 | namespace Swift { 13 | class StatsSerializer : public GenericPayloadSerializer { 14 | public: 15 | StatsSerializer(); 16 | 17 | virtual std::string serializePayload(std::shared_ptr) const; 18 | }; 19 | } 20 | -------------------------------------------------------------------------------- /include/Swiften/Serializer/PayloadSerializers/XHTMLIMSerializer.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2011 Jan Kaluza 3 | * Licensed under the Simplified BSD license. 4 | * See Documentation/Licenses/BSD-simplified.txt for more information. 5 | */ 6 | 7 | #include 8 | #include 9 | #include 10 | #include 11 | 12 | namespace Swift { 13 | 14 | XHTMLIMSerializer::XHTMLIMSerializer() : GenericPayloadSerializer() { 15 | } 16 | 17 | std::string XHTMLIMSerializer::serializePayload(std::shared_ptr payload) const { 18 | XMLElement html("html", "http://jabber.org/protocol/xhtml-im"); 19 | 20 | std::shared_ptr body = std::make_shared("body", "http://www.w3.org/1999/xhtml"); 21 | body->addNode(std::shared_ptr(new XMLRawTextNode(payload->getBody()))); 22 | html.addNode(body); 23 | 24 | return html.serialize(); 25 | } 26 | 27 | } 28 | -------------------------------------------------------------------------------- /include/Swiften/Serializer/PayloadSerializers/XHTMLIMSerializer.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2011 Jan Kaluza 3 | * Licensed under the Simplified BSD license. 4 | * See Documentation/Licenses/BSD-simplified.txt for more information. 5 | */ 6 | 7 | #pragma once 8 | 9 | #include 10 | #include 11 | 12 | namespace Swift { 13 | class XHTMLIMSerializer : public GenericPayloadSerializer { 14 | public: 15 | XHTMLIMSerializer(); 16 | 17 | virtual std::string serializePayload(std::shared_ptr xhtml) const; 18 | }; 19 | } 20 | -------------------------------------------------------------------------------- /include/Swiften/Server/ServerSession.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2010 Remko Tronçon 3 | * Licensed under the GNU General Public License v3. 4 | * See Documentation/Licenses/GPLv3.txt for more information. 5 | */ 6 | 7 | #include 8 | 9 | namespace Swift { 10 | 11 | ServerSession::~ServerSession() { 12 | } 13 | 14 | } 15 | -------------------------------------------------------------------------------- /include/Swiften/Server/ServerSession.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2010 Remko Tronçon 3 | * Licensed under the GNU General Public License v3. 4 | * See Documentation/Licenses/GPLv3.txt for more information. 5 | */ 6 | 7 | #pragma once 8 | 9 | #include 10 | 11 | #include 12 | 13 | namespace Swift { 14 | class ServerSession { 15 | public: 16 | virtual ~ServerSession(); 17 | 18 | virtual const JID& getJID() const = 0; 19 | virtual int getPriority() const = 0; 20 | 21 | virtual void sendStanza(std::shared_ptr) = 0; 22 | }; 23 | } 24 | -------------------------------------------------------------------------------- /include/Swiften/Server/ServerStanzaRouter.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2010 Remko Tronçon 3 | * Licensed under the GNU General Public License v3. 4 | * See Documentation/Licenses/GPLv3.txt for more information. 5 | */ 6 | 7 | #pragma once 8 | 9 | #include 10 | 11 | #include 12 | #include 13 | 14 | namespace Swift { 15 | class ServerSession; 16 | 17 | class ServerStanzaRouter { 18 | public: 19 | ServerStanzaRouter(); 20 | 21 | bool routeStanza(std::shared_ptr); 22 | 23 | void addClientSession(ServerSession*); 24 | void removeClientSession(ServerSession*); 25 | 26 | private: 27 | std::vector clientSessions_; 28 | }; 29 | } 30 | -------------------------------------------------------------------------------- /include/Swiften/Server/SimpleUserRegistry.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2010 Remko Tronçon 3 | * Licensed under the GNU General Public License v3. 4 | * See Documentation/Licenses/GPLv3.txt for more information. 5 | */ 6 | 7 | #include 8 | 9 | namespace Swift { 10 | 11 | SimpleUserRegistry::SimpleUserRegistry() { 12 | } 13 | 14 | void SimpleUserRegistry::isValidUserPassword(const JID& user, ServerFromClientSession *session, const SafeByteArray& password) { 15 | std::map::const_iterator i = users.find(user); 16 | 17 | 18 | if (i != users.end() && i->second == password) { 19 | session->handlePasswordValid(); 20 | } 21 | else { 22 | session->handlePasswordInvalid(); 23 | } 24 | } 25 | 26 | void SimpleUserRegistry::addUser(const JID& user, const std::string& password) { 27 | users.insert(std::make_pair(user, createSafeByteArray(password))); 28 | } 29 | 30 | } 31 | -------------------------------------------------------------------------------- /include/Swiften/Server/SimpleUserRegistry.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2010 Remko Tronçon 3 | * Licensed under the GNU General Public License v3. 4 | * See Documentation/Licenses/GPLv3.txt for more information. 5 | */ 6 | 7 | #pragma once 8 | 9 | #include 10 | 11 | #include 12 | #include 13 | #include 14 | 15 | namespace Swift { 16 | 17 | 18 | class SimpleUserRegistry : public UserRegistry { 19 | public: 20 | SimpleUserRegistry(); 21 | 22 | virtual void isValidUserPassword(const JID& user, ServerFromClientSession *session, const SafeByteArray& password); 23 | void addUser(const JID& user, const std::string& password); 24 | 25 | private: 26 | std::map users; 27 | }; 28 | } 29 | -------------------------------------------------------------------------------- /include/Swiften/Server/UserRegistry.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2010 Remko Tronçon 3 | * Licensed under the GNU General Public License v3. 4 | * See Documentation/Licenses/GPLv3.txt for more information. 5 | */ 6 | 7 | #include 8 | 9 | namespace Swift { 10 | 11 | UserRegistry::~UserRegistry() { 12 | } 13 | 14 | } 15 | -------------------------------------------------------------------------------- /include/Swiften/Server/UserRegistry.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2010 Remko Tronçon 3 | * Licensed under the GNU General Public License v3. 4 | * See Documentation/Licenses/GPLv3.txt for more information. 5 | */ 6 | 7 | #pragma once 8 | 9 | #include 10 | #include 11 | #include "Swiften/Server/ServerFromClientSession.h" 12 | 13 | namespace Swift { 14 | class JID; 15 | 16 | class UserRegistry { 17 | public: 18 | virtual ~UserRegistry(); 19 | 20 | virtual void isValidUserPassword(const JID& user, ServerFromClientSession *session, const SafeByteArray& password) = 0; 21 | 22 | virtual void stopLogin(const JID &/*user*/, ServerFromClientSession *) {}; 23 | }; 24 | } 25 | -------------------------------------------------------------------------------- /include/Swiften/StreamStack/TLSServerLayer.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2010 Remko Tronçon 3 | * Licensed under the GNU General Public License v3. 4 | * See Documentation/Licenses/GPLv3.txt for more information. 5 | */ 6 | 7 | #include "Swiften/StreamStack/TLSServerLayer.h" 8 | 9 | #include 10 | 11 | #include "Swiften/TLS/TLSServerContextFactory.h" 12 | #include "Swiften/TLS/TLSServerContext.h" 13 | 14 | namespace Swift { 15 | 16 | TLSServerLayer::TLSServerLayer(TLSServerContextFactory* factory) { 17 | context = factory->createTLSServerContext(); 18 | context->onDataForNetwork.connect(boost::bind(&TLSServerLayer::writeDataToChildLayer, this, _1)); 19 | context->onDataForApplication.connect(boost::bind(&TLSServerLayer::writeDataToParentLayer, this, _1)); 20 | context->onConnected.connect(onConnected); 21 | context->onError.connect(onError); 22 | } 23 | 24 | TLSServerLayer::~TLSServerLayer() { 25 | delete context; 26 | } 27 | 28 | void TLSServerLayer::connect() { 29 | context->connect(); 30 | } 31 | 32 | void TLSServerLayer::writeData(const SafeByteArray& data) { 33 | context->handleDataFromApplication(data); 34 | } 35 | 36 | void TLSServerLayer::handleDataRead(const SafeByteArray& data) { 37 | context->handleDataFromNetwork(data); 38 | } 39 | 40 | bool TLSServerLayer::setServerCertificate(CertificateWithKey::ref certificate) { 41 | return context->setServerCertificate(certificate); 42 | } 43 | 44 | Certificate::ref TLSServerLayer::getPeerCertificate() const { 45 | return context->getPeerCertificate(); 46 | } 47 | 48 | std::shared_ptr TLSServerLayer::getPeerCertificateVerificationError() const { 49 | return context->getPeerCertificateVerificationError(); 50 | } 51 | 52 | } 53 | -------------------------------------------------------------------------------- /include/Swiften/StreamStack/TLSServerLayer.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2010 Remko Tronçon 3 | * Licensed under the GNU General Public License v3. 4 | * See Documentation/Licenses/GPLv3.txt for more information. 5 | */ 6 | 7 | #pragma once 8 | 9 | #include 10 | 11 | #include "Swiften/Base/SafeByteArray.h" 12 | #include "Swiften/StreamStack/StreamLayer.h" 13 | #include "Swiften/TLS/Certificate.h" 14 | #include 15 | #include "Swiften/TLS/CertificateVerificationError.h" 16 | 17 | namespace Swift { 18 | class TLSServerContext; 19 | class TLSServerContextFactory; 20 | class PKCS12Certificate; 21 | 22 | class TLSServerLayer : public StreamLayer { 23 | public: 24 | TLSServerLayer(TLSServerContextFactory*); 25 | ~TLSServerLayer(); 26 | 27 | void connect(); 28 | bool setServerCertificate(CertificateWithKey::ref cert); 29 | 30 | Certificate::ref getPeerCertificate() const; 31 | std::shared_ptr getPeerCertificateVerificationError() const; 32 | 33 | void writeData(const SafeByteArray& data); 34 | void handleDataRead(const SafeByteArray& data); 35 | 36 | TLSServerContext* getContext() const { 37 | return context; 38 | } 39 | 40 | public: 41 | boost::signals2::signal onError; 42 | boost::signals2::signal onConnected; 43 | 44 | private: 45 | TLSServerContext* context; 46 | }; 47 | } 48 | -------------------------------------------------------------------------------- /include/Swiften/TLS/OpenSSL/OpenSSLServerContext.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2010 Remko Tronçon 3 | * Licensed under the GNU General Public License v3. 4 | * See Documentation/Licenses/GPLv3.txt for more information. 5 | */ 6 | 7 | #pragma once 8 | 9 | #include 10 | #include 11 | 12 | #include "Swiften/TLS/TLSServerContext.h" 13 | #include "Swiften/Base/ByteArray.h" 14 | #include 15 | 16 | namespace Swift { 17 | class PKCS12Certificate; 18 | 19 | class OpenSSLServerContext : public TLSServerContext, boost::noncopyable { 20 | public: 21 | OpenSSLServerContext(); 22 | ~OpenSSLServerContext(); 23 | 24 | void connect(); 25 | bool setServerCertificate(CertificateWithKey::ref cert); 26 | 27 | void handleDataFromNetwork(const SafeByteArray&); 28 | void handleDataFromApplication(const SafeByteArray&); 29 | 30 | Certificate::ref getPeerCertificate() const; 31 | std::shared_ptr getPeerCertificateVerificationError() const; 32 | 33 | virtual ByteArray getFinishMessage() const; 34 | 35 | private: 36 | static void ensureLibraryInitialized(); 37 | 38 | static CertificateVerificationError::Type getVerificationErrorTypeForResult(int); 39 | 40 | void doConnect(); 41 | void sendPendingDataToNetwork(); 42 | void sendPendingDataToApplication(); 43 | 44 | private: 45 | enum State { Start, Connecting, Connected, Error }; 46 | 47 | State state_; 48 | SSL_CTX* context_; 49 | SSL* handle_; 50 | BIO* readBIO_; 51 | BIO* writeBIO_; 52 | }; 53 | } 54 | -------------------------------------------------------------------------------- /include/Swiften/TLS/OpenSSL/OpenSSLServerContextFactory.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2010 Remko Tronçon 3 | * Licensed under the GNU General Public License v3. 4 | * See Documentation/Licenses/GPLv3.txt for more information. 5 | */ 6 | 7 | #include "Swiften/TLS/OpenSSL/OpenSSLServerContextFactory.h" 8 | #include "Swiften/TLS/OpenSSL/OpenSSLServerContext.h" 9 | 10 | namespace Swift { 11 | 12 | bool OpenSSLServerContextFactory::canCreate() const { 13 | return true; 14 | } 15 | 16 | TLSServerContext* OpenSSLServerContextFactory::createTLSServerContext() { 17 | return new OpenSSLServerContext(); 18 | } 19 | 20 | } 21 | -------------------------------------------------------------------------------- /include/Swiften/TLS/OpenSSL/OpenSSLServerContextFactory.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2010 Remko Tronçon 3 | * Licensed under the GNU General Public License v3. 4 | * See Documentation/Licenses/GPLv3.txt for more information. 5 | */ 6 | 7 | #pragma once 8 | 9 | #include "Swiften/TLS/TLSServerContextFactory.h" 10 | 11 | namespace Swift { 12 | class OpenSSLServerContextFactory : public TLSServerContextFactory { 13 | public: 14 | bool canCreate() const; 15 | virtual TLSServerContext* createTLSServerContext(); 16 | }; 17 | } 18 | -------------------------------------------------------------------------------- /include/Swiften/TLS/Schannel/SchannelServerContextFactory.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2011 Soren Dreijer 3 | * Licensed under the simplified BSD license. 4 | * See Documentation/Licenses/BSD-simplified.txt for more information. 5 | */ 6 | 7 | #include "Swiften/TLS/Schannel/SchannelServerContextFactory.h" 8 | #include "Swiften/TLS/Schannel/SchannelServerContext.h" 9 | 10 | namespace Swift { 11 | 12 | bool SchannelServerContextFactory::canCreate() const { 13 | return true; 14 | } 15 | 16 | TLSServerContext* SchannelServerContextFactory::createTLSServerContext() { 17 | return new SchannelServerContext(); 18 | } 19 | 20 | } 21 | -------------------------------------------------------------------------------- /include/Swiften/TLS/Schannel/SchannelServerContextFactory.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2011 Soren Dreijer 3 | * Licensed under the simplified BSD license. 4 | * See Documentation/Licenses/BSD-simplified.txt for more information. 5 | */ 6 | 7 | #pragma once 8 | 9 | #include "Swiften/TLS/TLSServerContextFactory.h" 10 | 11 | namespace Swift { 12 | class SchannelServerContextFactory : public TLSServerContextFactory { 13 | public: 14 | bool canCreate() const; 15 | virtual TLSServerContext* createTLSServerContext(); 16 | }; 17 | } 18 | -------------------------------------------------------------------------------- /include/Swiften/TLS/TLSServerContext.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2010 Remko Tronçon 3 | * Licensed under the GNU General Public License v3. 4 | * See Documentation/Licenses/GPLv3.txt for more information. 5 | */ 6 | 7 | #include "Swiften/TLS/TLSServerContext.h" 8 | 9 | namespace Swift { 10 | 11 | TLSServerContext::~TLSServerContext() { 12 | } 13 | 14 | } 15 | -------------------------------------------------------------------------------- /include/Swiften/TLS/TLSServerContext.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2010 Remko Tronçon 3 | * Licensed under the GNU General Public License v3. 4 | * See Documentation/Licenses/GPLv3.txt for more information. 5 | */ 6 | 7 | #pragma once 8 | 9 | #include 10 | 11 | #include "Swiften/Base/SafeByteArray.h" 12 | #include "Swiften/TLS/Certificate.h" 13 | #include 14 | #include "Swiften/TLS/CertificateVerificationError.h" 15 | 16 | namespace Swift { 17 | class PKCS12Certificate; 18 | 19 | class TLSServerContext { 20 | public: 21 | virtual ~TLSServerContext(); 22 | 23 | virtual void connect() = 0; 24 | 25 | virtual bool setServerCertificate(CertificateWithKey::ref cert) = 0; 26 | 27 | virtual void handleDataFromNetwork(const SafeByteArray&) = 0; 28 | virtual void handleDataFromApplication(const SafeByteArray&) = 0; 29 | 30 | virtual Certificate::ref getPeerCertificate() const = 0; 31 | virtual CertificateVerificationError::ref getPeerCertificateVerificationError() const = 0; 32 | 33 | virtual ByteArray getFinishMessage() const = 0; 34 | 35 | public: 36 | boost::signals2::signal onDataForNetwork; 37 | boost::signals2::signal onDataForApplication; 38 | boost::signals2::signal onError; 39 | boost::signals2::signal onConnected; 40 | }; 41 | } 42 | -------------------------------------------------------------------------------- /include/Swiften/TLS/TLSServerContextFactory.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2010 Remko Tronçon 3 | * Licensed under the GNU General Public License v3. 4 | * See Documentation/Licenses/GPLv3.txt for more information. 5 | */ 6 | 7 | #include "Swiften/TLS/TLSServerContextFactory.h" 8 | 9 | namespace Swift { 10 | 11 | TLSServerContextFactory::~TLSServerContextFactory() { 12 | } 13 | 14 | } 15 | -------------------------------------------------------------------------------- /include/Swiften/TLS/TLSServerContextFactory.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2010 Remko Tronçon 3 | * Licensed under the GNU General Public License v3. 4 | * See Documentation/Licenses/GPLv3.txt for more information. 5 | */ 6 | 7 | #pragma once 8 | 9 | namespace Swift { 10 | class TLSServerContext; 11 | 12 | class TLSServerContextFactory { 13 | public: 14 | virtual ~TLSServerContextFactory(); 15 | 16 | virtual bool canCreate() const = 0; 17 | 18 | virtual TLSServerContext* createTLSServerContext() = 0; 19 | }; 20 | } 21 | -------------------------------------------------------------------------------- /include/transport/AdminInterface.h: -------------------------------------------------------------------------------- 1 | /** 2 | * libtransport -- C++ library for easy XMPP Transports development 3 | * 4 | * Copyright (C) 2011, Jan Kaluza 5 | * 6 | * This program is free software; you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation; either version 2 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program; if not, write to the Free Software 18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA 19 | */ 20 | 21 | #pragma once 22 | 23 | #include 24 | #include 25 | 26 | #include "Swiften/Elements/Message.h" 27 | 28 | namespace Transport { 29 | 30 | class Component; 31 | class StorageBackend; 32 | class UserManager; 33 | class NetworkPluginServer; 34 | class UserRegistration; 35 | class AdminInterfaceCommand; 36 | 37 | class AdminInterface { 38 | public: 39 | AdminInterface(Component *component, UserManager *userManager, NetworkPluginServer *server = NULL, StorageBackend *storageBackend = NULL, UserRegistration *userRegistration = NULL); 40 | 41 | ~AdminInterface(); 42 | 43 | void handleQuery(Swift::Message::ref message); 44 | 45 | void addCommand(AdminInterfaceCommand *command); 46 | 47 | void handleMessageReceived(Swift::Message::ref message); 48 | 49 | private: 50 | 51 | Component *m_component; 52 | StorageBackend *m_storageBackend; 53 | UserManager *m_userManager; 54 | NetworkPluginServer *m_server; 55 | UserRegistration *m_userRegistration; 56 | std::map m_commands; 57 | }; 58 | 59 | } 60 | -------------------------------------------------------------------------------- /include/transport/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | if(PROTOBUF_FOUND) 2 | add_custom_command( 3 | OUTPUT ${CMAKE_CURRENT_SOURCE_DIR}/protocol.pb.cc ${CMAKE_CURRENT_SOURCE_DIR}/protocol.pb.h 4 | COMMAND ${PROTOBUF_PROTOC_EXECUTABLE} --cpp_out ${CMAKE_CURRENT_SOURCE_DIR} --proto_path ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/protocol.proto 5 | COMMENT "Running C++ protocol buffer compiler on protocol.proto" 6 | DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/protocol.proto 7 | ) 8 | add_custom_target(pb DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/protocol.pb.cc) 9 | endif() 10 | 11 | file(GLOB HEADERS *.h protocol.h) 12 | 13 | install(FILES ${HEADERS} DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/transport COMPONENT headers) 14 | -------------------------------------------------------------------------------- /include/transport/Factory.h: -------------------------------------------------------------------------------- 1 | /** 2 | * XMPP - libpurple transport 3 | * 4 | * Copyright (C) 2009, Jan Kaluza 5 | * 6 | * This program is free software; you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation; either version 2 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program; if not, write to the Free Software 18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA 19 | */ 20 | 21 | #pragma once 22 | 23 | #include 24 | #include 25 | #include "Swiften/Elements/Message.h" 26 | 27 | namespace Transport { 28 | 29 | class Conversation; 30 | class Buddy; 31 | class ConversationManager; 32 | class RosterManager; 33 | struct BuddyInfo; 34 | 35 | class Factory { 36 | public: 37 | 38 | virtual Conversation *createConversation(ConversationManager *conversationManager, const std::string &legacyName, bool isMuc = false) = 0; 39 | 40 | virtual Buddy *createBuddy(RosterManager *rosterManager, const BuddyInfo &buddyInfo) = 0; 41 | 42 | virtual ~Factory() 43 | { } 44 | }; 45 | 46 | } 47 | -------------------------------------------------------------------------------- /include/transport/HTTPRequest.h: -------------------------------------------------------------------------------- 1 | 2 | #pragma once 3 | 4 | #include 5 | #include 6 | #include "transport/Logging.h" 7 | #include "transport/ThreadPool.h" 8 | #include 9 | #include 10 | #include 11 | #include 12 | 13 | namespace Transport { 14 | 15 | class HTTPRequest : public Thread { 16 | public: 17 | typedef enum { Get } Type; 18 | typedef boost::function< void (HTTPRequest *, bool, Json::Value &json, const std::string &data) > Callback; 19 | 20 | HTTPRequest(ThreadPool *tp, Type type, const std::string &url, Callback callback); 21 | HTTPRequest(Type type, const std::string &url); 22 | 23 | virtual ~HTTPRequest(); 24 | 25 | void setProxy(std::string, std::string, std::string, std::string); 26 | bool execute(); 27 | bool execute(Json::Value &json); 28 | std::string getError() {return std::string(curl_errorbuffer);} 29 | const std::string &getRawData() { 30 | return m_data; 31 | } 32 | 33 | void run(); 34 | void finalize(); 35 | 36 | const std::string &getURL() { 37 | return m_url; 38 | } 39 | 40 | boost::signals2::signal onRequestFinished; 41 | 42 | static void globalInit() { 43 | curl_global_init(CURL_GLOBAL_ALL); 44 | } 45 | 46 | static void globalCleanup() { 47 | curl_global_cleanup(); 48 | } 49 | 50 | private: 51 | bool init(); 52 | bool GET(std::string url, std::string &output); 53 | bool GET(std::string url, Json::Value &json); 54 | 55 | 56 | CURL *curlhandle; 57 | char curl_errorbuffer[1024]; 58 | std::string error; 59 | std::string callbackdata; 60 | ThreadPool *m_tp; 61 | std::string m_url; 62 | bool m_ok; 63 | Json::Value m_json; 64 | std::string m_data; 65 | Callback m_callback; 66 | Type m_type; 67 | 68 | static int curlCallBack(char* data, size_t size, size_t nmemb, HTTPRequest *obj); 69 | 70 | }; 71 | 72 | } 73 | 74 | -------------------------------------------------------------------------------- /include/transport/HTTPRequestQueue.h: -------------------------------------------------------------------------------- 1 | 2 | #pragma once 3 | 4 | #include "curl/curl.h" 5 | #include "transport/Logging.h" 6 | #include "transport/ThreadPool.h" 7 | #include 8 | #include 9 | #include 10 | 11 | #include "Swiften/Network/Timer.h" 12 | 13 | namespace Transport { 14 | 15 | class HTTPRequest; 16 | class Component; 17 | 18 | class HTTPRequestQueue { 19 | public: 20 | HTTPRequestQueue(Component *component, const std::string &user, int delayBetweenRequests = 1); 21 | 22 | virtual ~HTTPRequestQueue(); 23 | 24 | void queueRequest(HTTPRequest *req); 25 | 26 | void sendNextRequest(); 27 | 28 | private: 29 | void handleRequestFinished(); 30 | 31 | private: 32 | int m_delay; 33 | std::queue m_queue; 34 | HTTPRequest *m_req; 35 | Swift::Timer::ref m_queueTimer; 36 | std::string m_user; 37 | }; 38 | 39 | } 40 | 41 | -------------------------------------------------------------------------------- /include/transport/MemoryUsage.h: -------------------------------------------------------------------------------- 1 | /** 2 | * libtransport -- C++ library for easy XMPP Transports development 3 | * 4 | * Copyright (C) 2011, Jan Kaluza 5 | * 6 | * This program is free software; you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation; either version 2 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program; if not, write to the Free Software 18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA 19 | */ 20 | 21 | #pragma once 22 | 23 | #include 24 | 25 | #ifndef WIN32 26 | #include "signal.h" 27 | #else 28 | #define pid_t void* 29 | #endif 30 | 31 | namespace Transport { 32 | void process_mem_usage(double& shared, double& resident_set, pid_t pid = 0); 33 | } 34 | -------------------------------------------------------------------------------- /include/transport/OAuth2.h: -------------------------------------------------------------------------------- 1 | /** 2 | * libtransport -- C++ library for easy XMPP Transports development 3 | * 4 | * Copyright (C) 2015, Jan Kaluza 5 | * 6 | * This program is free software; you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation; either version 2 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program; if not, write to the Free Software 18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA 19 | */ 20 | 21 | #pragma once 22 | 23 | #include 24 | 25 | namespace Transport { 26 | 27 | class OAuth2 { 28 | public: 29 | 30 | OAuth2(const std::string &clientId, const std::string &clientSecret, 31 | const std::string &authURL, const std::string &tokenURL, 32 | const std::string &redirectURL = "", const std::string &scope = ""); 33 | 34 | virtual ~OAuth2(); 35 | 36 | std::string generateAuthURL(); 37 | 38 | const std::string &getState() { 39 | return m_state; 40 | } 41 | 42 | std::string requestToken(const std::string &code, std::string &token, std::string &bot_token); 43 | 44 | private: 45 | std::string m_clientId; 46 | std::string m_clientSecret; 47 | std::string m_authURL; 48 | std::string m_tokenURL; 49 | std::string m_redirectURL; 50 | std::string m_scope; 51 | std::string m_state; 52 | }; 53 | 54 | } 55 | -------------------------------------------------------------------------------- /include/transport/RosterStorage.h: -------------------------------------------------------------------------------- 1 | /** 2 | * XMPP - libpurple transport 3 | * 4 | * Copyright (C) 2009, Jan Kaluza 5 | * 6 | * This program is free software; you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation; either version 2 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program; if not, write to the Free Software 18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA 19 | */ 20 | 21 | #pragma once 22 | 23 | #include 24 | #include 25 | #include 26 | 27 | #include "Swiften/Network/Timer.h" 28 | 29 | namespace Transport { 30 | 31 | class User; 32 | class StorageBackend; 33 | class Buddy; 34 | 35 | // Stores buddies into DB Backend. 36 | class RosterStorage { 37 | public: 38 | RosterStorage(User *user, StorageBackend *storageBackend); 39 | virtual ~RosterStorage(); 40 | 41 | // Add buddy to store queue and store it in future. Nothing 42 | // will happen if buddy is already added. 43 | void storeBuddy(Buddy *buddy); 44 | 45 | void removeBuddy(Buddy *buddy); 46 | 47 | // Store all buddies from queue immediately. Returns true 48 | // if some buddies were stored. 49 | bool storeBuddies(); 50 | 51 | // Remove buddy from storage queue. 52 | void removeBuddyFromQueue(Buddy *buddy); 53 | 54 | private: 55 | User *m_user; 56 | StorageBackend *m_storageBackend; 57 | std::map m_buddies; 58 | Swift::Timer::ref m_storageTimer; 59 | }; 60 | 61 | } 62 | -------------------------------------------------------------------------------- /include/transport/UsersReconnecter.h: -------------------------------------------------------------------------------- 1 | /** 2 | * XMPP - libpurple transport 3 | * 4 | * Copyright (C) 2009, Jan Kaluza 5 | * 6 | * This program is free software; you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation; either version 2 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program; if not, write to the Free Software 18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA 19 | */ 20 | 21 | #pragma once 22 | 23 | #include 24 | #include 25 | #include 26 | 27 | #include "Swiften/Network/Timer.h" 28 | 29 | namespace Transport { 30 | 31 | class StorageBackend; 32 | class Component; 33 | 34 | /// Tries to reconnect users who have been online before crash/restart. 35 | class UsersReconnecter { 36 | public: 37 | /// Creates new UsersReconnecter. 38 | /// \param component Transport instance associated with this roster. 39 | /// \param storageBackend StorageBackend from which the users will be fetched. 40 | UsersReconnecter(Component *component, StorageBackend *storageBackend); 41 | 42 | /// Destructor. 43 | virtual ~UsersReconnecter(); 44 | 45 | void reconnectNextUser(); 46 | 47 | private: 48 | void handleConnected(); 49 | 50 | Component *m_component; 51 | StorageBackend *m_storageBackend; 52 | bool m_started; 53 | std::vector m_users; 54 | Swift::Timer::ref m_nextUserTimer; 55 | }; 56 | 57 | } 58 | -------------------------------------------------------------------------------- /include/transport/Util.h: -------------------------------------------------------------------------------- 1 | /** 2 | * libtransport -- C++ library for easy XMPP Transports development 3 | * 4 | * Copyright (C) 2011, Jan Kaluza 5 | * 6 | * This program is free software; you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation; either version 2 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program; if not, write to the Free Software 18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA 19 | */ 20 | 21 | #pragma once 22 | 23 | #include 24 | #include 25 | #include 26 | #include 27 | #include "Swiften/StringCodecs/Base64.h" 28 | 29 | #include 30 | 31 | namespace Transport { 32 | 33 | class Config; 34 | 35 | namespace Util { 36 | 37 | void createDirectories(Transport::Config *config, const boost::filesystem::path& ph); 38 | 39 | void removeEverythingOlderThan(const std::vector &dirs, time_t t); 40 | 41 | int getRandomPort(const std::string &s); 42 | 43 | std::string char2hex( char dec ); 44 | std::string urlencode( const std::string &c ); 45 | 46 | #ifdef _WIN32 47 | std::wstring utf8ToUtf16(const std::string& str); 48 | #endif 49 | 50 | } 51 | 52 | } 53 | -------------------------------------------------------------------------------- /include/transport/utf8.h: -------------------------------------------------------------------------------- 1 | // Copyright 2006 Nemanja Trifunovic 2 | 3 | /* 4 | Permission is hereby granted, free of charge, to any person or organization 5 | obtaining a copy of the software and accompanying documentation covered by 6 | this license (the "Software") to use, reproduce, display, distribute, 7 | execute, and transmit the Software, and to prepare derivative works of the 8 | Software, and to permit third-parties to whom the Software is furnished to 9 | do so, all subject to the following: 10 | 11 | The copyright notices in the Software and this entire statement, including 12 | the above license grant, this restriction and the following disclaimer, 13 | must be included in all copies of the Software, in whole or in part, and 14 | all derivative works of the Software, unless such copies or derivative 15 | works are solely in the form of machine-executable object code generated by 16 | a source language processor. 17 | 18 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 | FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT 21 | SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE 22 | FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, 23 | ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 24 | DEALINGS IN THE SOFTWARE. 25 | */ 26 | 27 | 28 | #ifndef UTF8_FOR_CPP_2675DCD0_9480_4c0c_B92A_CC14C027B731 29 | #define UTF8_FOR_CPP_2675DCD0_9480_4c0c_B92A_CC14C027B731 30 | 31 | #include "utf8/checked.h" 32 | #include "utf8/unchecked.h" 33 | 34 | #endif // header guard 35 | -------------------------------------------------------------------------------- /libtransport/HTTPRequestQueue.cpp: -------------------------------------------------------------------------------- 1 | #include "transport/HTTPRequestQueue.h" 2 | #include "transport/HTTPRequest.h" 3 | #include "transport/Transport.h" 4 | 5 | namespace Transport { 6 | 7 | DEFINE_LOGGER(httpRequestQueueLogger, "HTTPRequestQueue") 8 | 9 | HTTPRequestQueue::HTTPRequestQueue(Component *component, const std::string &user, int delay) { 10 | m_delay = delay; 11 | m_req = NULL; 12 | m_user = user; 13 | 14 | m_queueTimer = component->getNetworkFactories()->getTimerFactory()->createTimer(500); 15 | m_queueTimer->onTick.connect(boost::bind(&HTTPRequestQueue::sendNextRequest, this)); 16 | } 17 | 18 | HTTPRequestQueue::~HTTPRequestQueue() { 19 | m_queueTimer->stop(); 20 | 21 | if (m_req) { 22 | m_req->onRequestFinished.disconnect(boost::bind(&HTTPRequestQueue::handleRequestFinished, this)); 23 | } 24 | } 25 | 26 | void HTTPRequestQueue::handleRequestFinished() { 27 | m_req = NULL; 28 | m_queueTimer->start(); 29 | } 30 | 31 | void HTTPRequestQueue::sendNextRequest() { 32 | if (m_queue.empty()) { 33 | LOG4CXX_INFO(httpRequestQueueLogger, m_user << ": Queue is empty."); 34 | m_req = NULL; 35 | m_queueTimer->stop(); 36 | return; 37 | } 38 | 39 | if (m_req) { 40 | LOG4CXX_INFO(httpRequestQueueLogger, m_user << ": There is already a request being handled."); 41 | return; 42 | } 43 | 44 | m_req = m_queue.front(); 45 | m_queue.pop(); 46 | 47 | LOG4CXX_INFO(httpRequestQueueLogger, m_user << ": Starting request '" << m_req->getURL() << "'."); 48 | m_req->onRequestFinished.connect(boost::bind(&HTTPRequestQueue::handleRequestFinished, this)); 49 | m_req->execute(); 50 | } 51 | 52 | void HTTPRequestQueue::queueRequest(HTTPRequest *req) { 53 | m_queue.push(req); 54 | 55 | if (!m_req) { 56 | sendNextRequest(); 57 | } 58 | else { 59 | LOG4CXX_INFO(httpRequestQueueLogger, m_user << ": Request '" << req->getURL() << "' queued."); 60 | } 61 | } 62 | 63 | 64 | } 65 | -------------------------------------------------------------------------------- /libtransport/transport.pc.in: -------------------------------------------------------------------------------- 1 | prefix=@prefix@ 2 | exec_prefix=@exec_prefix@ 3 | libdir=@libdir@ 4 | includedir=@includedir@ 5 | 6 | Name: transport 7 | Version: @TRANSPORT_VERSION@ 8 | Description: NeL @TRANSPORT_VERSION@ 9 | Reqiures: 10 | Libs: -L${libdir} 11 | Libs.private: @LIBS@ -lc 12 | Cflags: -I${includedir} 13 | -------------------------------------------------------------------------------- /packaging/debian/build_spectrum2.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | set -xe 4 | 5 | #Check functions required 6 | hash debuild 2>/dev/null || ( echo >&2 "apt-get install devscripts"; exit 1; ) 7 | 8 | 9 | 10 | vercount=$(git rev-list --all | wc -l) 11 | gitrev=$(git rev-parse --short HEAD | sed 's/\(^[0-9\.]*\)-/\1~/') 12 | version=$vercount-$gitrev 13 | 14 | sed -i "1s/\((.*)\)/(1:$version-1)/" debian/changelog 15 | 16 | rm -rf spectrum2_* 17 | 18 | git clone ../../.git spectrum2-$version 19 | 20 | tar -czf spectrum2_$version.orig.tar.gz spectrum2-$version 21 | 22 | cp -r debian spectrum2-$version/debian 23 | 24 | cd spectrum2-$version 25 | DEB_BUILD_OPTIONS=nocheck debuild -i -us -uc 26 | 27 | cd .. 28 | 29 | rm -rf spectrum2-$version 30 | -------------------------------------------------------------------------------- /packaging/debian/debian/README.Debian: -------------------------------------------------------------------------------- 1 | Spectrum2 for Debian 2 | -------------------- 3 | -------------------------------------------------------------------------------- /packaging/debian/debian/changelog: -------------------------------------------------------------------------------- 1 | spectrum2 (1:2.0.11-2) unstable; urgency=low 2 | 3 | * Move package to git-buildpackage format 4 | * remove the -git suffix from package names 5 | * Change dependency from libswiften2-dev to libswiften-dev 6 | * remove some old cruft (debian/source/options, lintian-overrides, ...) 7 | * Add libevent-dev as build-dependency 8 | 9 | -- Mathias Ertl Thu, 28 Jun 2012 21:39:27 +0200 10 | 11 | spectrum2-git (2.0.0~beta+47-gdd8627b-1) unstable; urgency=low 12 | 13 | * Upstream development snapshot 14 | 15 | -- Mathias Ertl Tue, 20 Sep 2011 11:06:50 +0200 16 | -------------------------------------------------------------------------------- /packaging/debian/debian/compat: -------------------------------------------------------------------------------- 1 | 10 2 | -------------------------------------------------------------------------------- /packaging/debian/debian/copyright: -------------------------------------------------------------------------------- 1 | This package was debianized by the Mathias Ertl 2 | 3 | License: 4 | 5 | Copyright (C) 2010 Kevin Smith and Remko Tronçon 6 | 7 | You are free to distribute this software under the terms of 8 | the GNU General Public License version 3. 9 | The complete text of the GNU General Public License can be 10 | found in /usr/share/common-licenses/GPL-3 file. 11 | 12 | This software is subject to the OpenSSL license exception. 13 | -------------------------------------------------------------------------------- /packaging/debian/debian/libtransport-dev.install: -------------------------------------------------------------------------------- 1 | /usr/lib/*/libtransport.so 2 | /usr/include 3 | -------------------------------------------------------------------------------- /packaging/debian/debian/libtransport-plugin2.0.install: -------------------------------------------------------------------------------- 1 | /usr/lib/*/libtransport-plugin.so.2.0 2 | -------------------------------------------------------------------------------- /packaging/debian/debian/libtransport2.0.install: -------------------------------------------------------------------------------- 1 | /usr/lib/*/libtransport.so.2.0 2 | -------------------------------------------------------------------------------- /packaging/debian/debian/rules: -------------------------------------------------------------------------------- 1 | #!/usr/bin/make -f 2 | 3 | #export DH_VERBOSE=1 4 | 5 | DEB_UPSTREAM_VERSION = $(shell dpkg-parsechangelog -ldebian/changelog \ 6 | | grep '^Version' \ 7 | | sed -e 's/Version: *//;s/^[^:]*://;s/-[^-]*$$//') 8 | 9 | override_dh_auto_configure: 10 | dh_auto_configure -- -DCMAKE_BUILD_TYPE=RelWithDebInfo -DCMAKE_INSTALL_PREFIX=/usr -DENABLE_QT4=OFF -DSPECTRUM_VERSION=${DEB_UPSTREAM_VERSION} -DCMAKE_UNITY_BUILD=ON 11 | 12 | override_dh_strip: 13 | dh_strip -pspectrum2 --dbg-package=spectrum2-dbg 14 | dh_strip -pspectrum2-backend-libpurple --dbg-package=spectrum2-backend-libpurple-dbg 15 | dh_strip -pspectrum2-backend-frotz --dbg-package=spectrum2-backend-frotz-dbg 16 | dh_strip -pspectrum2-backend-swiften --dbg-package=spectrum2-backend-swiften-dbg 17 | dh_strip -pspectrum2-backend-libcommuni --dbg-package=spectrum2-backend-libcommuni-dbg 18 | dh_strip -pspectrum2-backend-smstools3 --dbg-package=spectrum2-backend-smstools3-dbg 19 | dh_strip -plibtransport2.0 --dbg-package=libtransport-dbg 20 | dh_strip -plibtransport-plugin2.0 --dbg-package=libtransport-plugin-dbg 21 | 22 | %: 23 | dh $@ --buildsystem=cmake 24 | -------------------------------------------------------------------------------- /packaging/debian/debian/source/format: -------------------------------------------------------------------------------- 1 | 3.0 (quilt) 2 | -------------------------------------------------------------------------------- /packaging/debian/debian/spectrum2-backend-frotz.install: -------------------------------------------------------------------------------- 1 | /usr/libexec/spectrum2_frotz_backend 2 | /usr/libexec/dfrotz 3 | -------------------------------------------------------------------------------- /packaging/debian/debian/spectrum2-backend-frotz.links: -------------------------------------------------------------------------------- 1 | /usr/libexec/spectrum2_frotz_backend /usr/bin/spectrum2_frotz_backend 2 | 3 | -------------------------------------------------------------------------------- /packaging/debian/debian/spectrum2-backend-libcommuni.install: -------------------------------------------------------------------------------- 1 | /usr/libexec/spectrum2_libcommuni_backend 2 | -------------------------------------------------------------------------------- /packaging/debian/debian/spectrum2-backend-libcommuni.links: -------------------------------------------------------------------------------- 1 | /usr/libexec/spectrum2_libcommuni_backend /usr/bin/spectrum2_libcommuni_backend 2 | 3 | -------------------------------------------------------------------------------- /packaging/debian/debian/spectrum2-backend-libpurple.install: -------------------------------------------------------------------------------- 1 | /usr/libexec/spectrum2_libpurple_backend 2 | -------------------------------------------------------------------------------- /packaging/debian/debian/spectrum2-backend-libpurple.links: -------------------------------------------------------------------------------- 1 | /usr/libexec/spectrum2_libpurple_backend /usr/bin/spectrum2_libpurple_backend 2 | 3 | -------------------------------------------------------------------------------- /packaging/debian/debian/spectrum2-backend-smstools3.install: -------------------------------------------------------------------------------- 1 | /usr/libexec/spectrum2_smstools3_backend 2 | -------------------------------------------------------------------------------- /packaging/debian/debian/spectrum2-backend-smstools3.links: -------------------------------------------------------------------------------- 1 | /usr/libexec/spectrum2_smstools3_backend /usr/bin/spectrum2_smstools3_backend 2 | 3 | -------------------------------------------------------------------------------- /packaging/debian/debian/spectrum2-backend-swiften.install: -------------------------------------------------------------------------------- 1 | /usr/libexec/spectrum2_swiften_backend 2 | -------------------------------------------------------------------------------- /packaging/debian/debian/spectrum2-backend-swiften.links: -------------------------------------------------------------------------------- 1 | /usr/libexec/spectrum2_swiften_backend /usr/bin/spectrum2_swiften_backend 2 | 3 | -------------------------------------------------------------------------------- /packaging/debian/debian/spectrum2.install: -------------------------------------------------------------------------------- 1 | /etc/spectrum2 2 | /usr/bin/spectrum2 3 | /usr/bin/spectrum2_manager 4 | /var/lib/spectrum2_manager 5 | -------------------------------------------------------------------------------- /packaging/debian/debian/spectrum2.service: -------------------------------------------------------------------------------- 1 | [Unit] 2 | Description=spectrum2 3 | Wants=network-online.target 4 | After=network.target network-online.target 5 | 6 | [Service] 7 | Type=forking 8 | ExecStart=/usr/bin/spectrum2_manager start 9 | TimeoutStopSec=3 10 | ExecStop=/usr/bin/spectrum2_manager stop 11 | ExecReload=/usr/bin/spectrum2_manager restart 12 | 13 | [Install] 14 | WantedBy=multi-user.target 15 | -------------------------------------------------------------------------------- /packaging/docker/Dockerfile.alpine: -------------------------------------------------------------------------------- 1 | FROM alpine:3.12.0 2 | 3 | RUN apk add --no-cache ca-certificates && \ 4 | apk add --no-cache --virtual .build-deps cmake make gcc g++ musl-dev boost-dev protobuf-dev mariadb-dev sqlite-dev postgresql-dev pidgin-dev libev-dev qt5-qtbase-dev qt5-qtdeclarative-dev apr-util-dev automake autoconf libtool git popt-dev curl-dev openssl libevent-dev jsoncpp-dev cppunit-dev python2 5 | 6 | WORKDIR /usr/src/ 7 | 8 | RUN wget https://github.com/communi/libcommuni/archive/v3.5.0.tar.gz -O libcommuni-3.5.0.tar.gz && \ 9 | tar xfz libcommuni-*.tar.gz && \ 10 | cd libcommuni-* && \ 11 | ./configure --prefix=/usr && \ 12 | make && \ 13 | make install && \ 14 | cd .. && \ 15 | rm -rf libcommuni-* 16 | 17 | RUN git clone https://github.com/apache/logging-log4cxx.git && \ 18 | cd logging-log4cxx && \ 19 | git checkout v0.11.0 && \ 20 | ./autogen.sh && \ 21 | ./configure --prefix=/usr && \ 22 | make && \ 23 | make install && \ 24 | cd .. && \ 25 | rm -rf logging-log4cxx 26 | 27 | RUN git clone git://swift.im/swift && \ 28 | cd swift && \ 29 | git checkout swift-4.x && \ 30 | ./scons Swiften swiften_dll=yes optimize=yes debug=no SWIFTEN_INSTALLDIR=/usr /usr -j5 31 | 32 | RUN git clone https://github.com/jtv/libpqxx.git && \ 33 | cd libpqxx && \ 34 | git checkout 7.1.2 && \ 35 | cmake . -DCMAKE_INSTALL_PREFIX=/usr -DCMAKE_INSTALL_LIBDIR=/usr/lib -DBUILD_SHARED_LIBS=ON -DBUILD_TEST=OFF -DCMAKE_BUILD_TYPE=RelWithDebInfo && \ 36 | make && \ 37 | make install 38 | -------------------------------------------------------------------------------- /packaging/docker/run.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash -e 2 | set -e 3 | 4 | web_dir=/var/lib/spectrum2/media 5 | 6 | if [ -d "$web_dir" ]; then 7 | web_dir_owner="$(stat -c %u "$web_dir")" 8 | if [[ "$(id -u www-data)" != "$web_dir_owner" ]]; then 9 | usermod -u "$web_dir_owner" www-data 10 | fi 11 | fi 12 | 13 | echo "Trying to start Spectrum 2 instances." 14 | echo "You should mount the directory with configuration files to /etc/spectrum2/transports/." 15 | echo "Check the http://spectrum.im/documentation for more information." 16 | spectrum2_manager start 17 | spectrum2_manager server & 18 | tail -f /var/log/spectrum2/*/* 2>/dev/null 19 | -------------------------------------------------------------------------------- /packaging/fedora/build_rpm.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | set -eu 3 | 4 | sh $(readlink -f $(dirname $0))/build_tarball.sh 5 | 6 | echo "Building package" 7 | rpmbuild -ta spectrum2.tar.gz 8 | -------------------------------------------------------------------------------- /packaging/fedora/build_tarball.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | set -eu 3 | 4 | DIRNAME=spectrum2 5 | REPODIR=$(readlink -f $(dirname $0)/../../.git) 6 | 7 | echo "Cleaning up old sources ..." 8 | rm -rf spectrum2-* 9 | 10 | echo "Checking out a fresh copy ..." 11 | rm -rf $DIRNAME 12 | git clone $REPODIR $DIRNAME && rm -rf $DIRNAME/.git 13 | 14 | echo "Creating tarball ..." 15 | tar czf $DIRNAME.tar.gz $DIRNAME && rm -rf $DIRNAME 16 | -------------------------------------------------------------------------------- /packaging/fedora/spectrum2.init: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # spectrum2 Start and stop spectrum 2. 4 | 5 | # chkconfig: - 80 20 6 | # description: spectrum2 7 | # processname: spectrum2 8 | 9 | ### BEGIN INIT INFO 10 | # Provides: spectrum2 11 | # Required-Start: network 12 | # Required-Stop: network 13 | # Default-Start: 14 | # Default-Stop: 0 1 6 15 | # Short-Description: Start and stop spectrum 2 16 | # Description: Spectrum is an XMPP transport/gateway. 17 | ### END INIT INFO 18 | 19 | # Source function library. 20 | . /etc/init.d/functions 21 | 22 | prog=$"Spectrum 2 server" 23 | 24 | RETVAL=0 25 | 26 | start() { 27 | [ "$EUID" != "0" ] && exit 4 28 | 29 | # echo -n $"Starting $prog: " 30 | RETVAL=0 31 | 32 | export PURPLE_LEAKCHECK_HELP=1; 33 | export G_SLICE=always-malloc; 34 | export PURPLE_VERBOSE_DEBUG=1; 35 | ulimit -c unlimited; 36 | spectrum2_manager start 37 | # echo_success 38 | 39 | return "$RETVAL" 40 | } 41 | 42 | stop() { 43 | [ "$EUID" != "0" ] && exit 4 44 | 45 | spectrum2_manager stop 46 | return "$RETVAL" 47 | } 48 | 49 | # See how we were called. 50 | case "$1" in 51 | start) 52 | start 53 | ;; 54 | stop) 55 | stop 56 | ;; 57 | restart|force-reload) 58 | stop 59 | sleep 3 60 | start 61 | ;; 62 | condrestart) 63 | ;; 64 | try-restart) 65 | ;; 66 | status) 67 | spectrum2_manager status 68 | RETVAL=$? 69 | ;; 70 | reload) 71 | exit 3 72 | ;; 73 | *) 74 | echo $"Usage: $0 {start|stop|restart|try-restart|status|force-reload}" 75 | exit 2 76 | esac 77 | 78 | exit "$RETVAL" 79 | 80 | -------------------------------------------------------------------------------- /packaging/logo/logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SpectrumIM/spectrum2/f547a2158bc90302ddfe09915a557d2e4ac4dfe8/packaging/logo/logo.png -------------------------------------------------------------------------------- /packaging/logo/logo128.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SpectrumIM/spectrum2/f547a2158bc90302ddfe09915a557d2e4ac4dfe8/packaging/logo/logo128.png -------------------------------------------------------------------------------- /packaging/logo/logo512.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SpectrumIM/spectrum2/f547a2158bc90302ddfe09915a557d2e4ac4dfe8/packaging/logo/logo512.png -------------------------------------------------------------------------------- /packaging/logo/logo64.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SpectrumIM/spectrum2/f547a2158bc90302ddfe09915a557d2e4ac4dfe8/packaging/logo/logo64.png -------------------------------------------------------------------------------- /packaging/logo/logo_black.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SpectrumIM/spectrum2/f547a2158bc90302ddfe09915a557d2e4ac4dfe8/packaging/logo/logo_black.png -------------------------------------------------------------------------------- /plugin/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_subdirectory(cpp) 2 | add_subdirectory(python) 3 | -------------------------------------------------------------------------------- /plugin/cpp/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | file(GLOB SRC *.cpp *.h) 2 | file(GLOB HEADERS ../include/transport/*.h) 3 | 4 | set(EXTRA_SOURCES ${EXTRA_SOURCES} ${CMAKE_CURRENT_SOURCE_DIR}/../../include/transport/protocol.pb.cc) 5 | 6 | if(NOT WIN32) 7 | add_library(transport-plugin SHARED ${HEADERS} ${SRC} ${PROTOBUF_SRC} ${PROTOBUF_HDRS} ${EXTRA_SOURCES}) 8 | else() 9 | add_library(transport-plugin STATIC ${HEADERS} ${SRC} ${EXTRA_SOURCES} ) 10 | endif() 11 | 12 | add_dependencies(transport-plugin pb) 13 | set_source_files_properties(${CMAKE_CURRENT_SOURCE_DIR}/../../include/transport/protocol.pb.cc PROPERTIES GENERATED 1) 14 | target_compile_features(transport-plugin PUBLIC cxx_std_11) 15 | 16 | if(CMAKE_COMPILER_IS_GNUCXX) 17 | if(NOT WIN32) 18 | add_definitions(-fPIC) 19 | endif() 20 | endif() 21 | 22 | if(NOT WIN32) 23 | target_link_libraries(transport-plugin ${PROTOBUF_LIBRARY} ${LOG4CXX_LIBRARIES} ${Boost_LIBRARIES}) 24 | else() 25 | target_link_libraries(transport-plugin ${PROTOBUF_LIBRARY} ${LOG4CXX_LIBRARIES} ${Boost_LIBRARIES} ws2_32.lib) 26 | endif() 27 | 28 | set_target_properties(transport-plugin PROPERTIES 29 | VERSION ${TRANSPORT_VERSION} SOVERSION ${TRANSPORT_VERSION} 30 | ) 31 | 32 | install(TARGETS transport-plugin LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT libraries) 33 | 34 | #configure_file(transport.pc.in "${CMAKE_CURRENT_SOURCE_DIR}/transport.pc") 35 | #install(FILES "${CMAKE_CURRENT_SOURCE_DIR}/transport.pc" DESTINATION lib/pkgconfig) 36 | -------------------------------------------------------------------------------- /plugin/python/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | if(PROTOBUF_FOUND) 2 | add_custom_command( 3 | OUTPUT ${CMAKE_CURRENT_SOURCE_DIR}/protocol_pb2.py 4 | COMMAND ${PROTOBUF_PROTOC_EXECUTABLE} --python_out ${CMAKE_CURRENT_SOURCE_DIR} --proto_path ${CMAKE_CURRENT_SOURCE_DIR}/../../include/transport/ ${CMAKE_CURRENT_SOURCE_DIR}/../../include/transport/protocol.proto 5 | COMMENT "Running Python protocol buffer compiler on protocol.proto" 6 | DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/../../include/transport/protocol.proto 7 | ) 8 | add_custom_target(pb-python ALL DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/protocol_pb2.py) 9 | endif() 10 | -------------------------------------------------------------------------------- /spectrum/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_subdirectory(src) 2 | -------------------------------------------------------------------------------- /spectrum/src/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | file(GLOB SRC *.cpp) 2 | #include_directories(frontends/xmpp) 3 | 4 | add_subdirectory(frontends) 5 | 6 | if(WIN32) 7 | file(GLOB WIN_SRC win32/*.cpp) 8 | include_directories(win32) 9 | include_directories("${CMAKE_SOURCE_DIR}/msvc-deps/sqlite3") 10 | add_executable(spectrum2 ${SRC} ${WIN_SRC}) 11 | else() 12 | add_executable(spectrum2 ${SRC}) 13 | endif() 14 | 15 | if (ENABLE_PURPLE AND PURPLE_FOUND) 16 | add_dependencies(spectrum2 spectrum2_libpurple_backend) 17 | endif() 18 | 19 | target_link_libraries(spectrum2 transport spectrum2-xmpp-frontend spectrum2-slack-frontend ${SWIFTEN_LIBRARY} ${LOG4CXX_LIBRARIES} ${PROTOBUF_LIBRARY}) 20 | target_compile_features(spectrum2 PUBLIC cxx_std_11) 21 | 22 | if(NOT MSVC AND NOT APPLE) 23 | # export all symbols (used for loading frontends) 24 | set(CMAKE_EXE_LINKER_FLAGS "-Wl,-export-dynamic") 25 | endif() 26 | 27 | install(TARGETS spectrum2 RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) 28 | 29 | install(FILES 30 | sample2_gateway.cfg 31 | RENAME spectrum.cfg.example 32 | DESTINATION ${CMAKE_INSTALL_SYSCONFDIR}/spectrum2/transports 33 | ) 34 | 35 | install(FILES 36 | sample2.cfg 37 | RENAME spectrum_server_mode.cfg.example 38 | DESTINATION ${CMAKE_INSTALL_SYSCONFDIR}/spectrum2/transports 39 | ) 40 | 41 | install(FILES 42 | backend-logging.cfg 43 | DESTINATION ${CMAKE_INSTALL_SYSCONFDIR}/spectrum2 44 | ) 45 | 46 | install(FILES 47 | logging.cfg 48 | DESTINATION ${CMAKE_INSTALL_SYSCONFDIR}/spectrum2 49 | ) 50 | 51 | install(FILES 52 | manager-logging.cfg 53 | DESTINATION ${CMAKE_INSTALL_SYSCONFDIR}/spectrum2 54 | ) 55 | -------------------------------------------------------------------------------- /spectrum/src/backend-logging.cfg: -------------------------------------------------------------------------------- 1 | log4j.rootLogger=debug, R 2 | 3 | log4j.appender.R=org.apache.log4j.RollingFileAppender 4 | log4j.appender.R.File=/var/log/spectrum2/${jid}/backends/backend-${id}.log 5 | 6 | log4j.appender.R.MaxFileSize=10000KB 7 | # Keep one backup file 8 | log4j.appender.R.MaxBackupIndex=1 9 | 10 | log4j.appender.R.layout=org.apache.log4j.PatternLayout 11 | log4j.appender.R.layout.ConversionPattern=${pid}: %d %-5p %c: %m%n 12 | -------------------------------------------------------------------------------- /spectrum/src/frontends/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_subdirectory(xmpp) 2 | add_subdirectory(slack) 3 | -------------------------------------------------------------------------------- /spectrum/src/frontends/slack/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | file(GLOB SRC *.cpp *.h) 2 | file(GLOB HEADERS ${CMAKE_SOURCE_DIR}/include/transport/*.h) 3 | 4 | include_directories(${CMAKE_SOURCE_DIR}/spectrum/src/frontends/slack) 5 | 6 | if(NOT WIN32) 7 | add_library(spectrum2-slack-frontend STATIC ${HEADERS} ${SRC} ${EXTRA_SOURCES}) 8 | else() 9 | add_library(spectrum2-slack-frontend STATIC ${HEADERS} ${SRC} ${EXTRA_SOURCES} ) 10 | endif() 11 | 12 | add_dependencies(spectrum2-slack-frontend transport) 13 | target_compile_features(spectrum2-slack-frontend PUBLIC cxx_std_11) 14 | 15 | if(CMAKE_COMPILER_IS_GNUCXX) 16 | if(NOT WIN32) 17 | add_definitions(-fPIC) 18 | endif() 19 | endif() 20 | 21 | target_link_libraries(spectrum2-slack-frontend transport ${LOG4CXX_LIBRARIES} ${Boost_LIBRARIES} ${SWIFTEN_LIBRARY}) 22 | 23 | #set_target_properties(transport-plugin PROPERTIES 24 | # VERSION ${TRANSPORT_VERSION} SOVERSION ${TRANSPORT_VERSION} 25 | #) 26 | 27 | # install(TARGETS transport-plugin LIBRARY DESTINATION ${LIB_INSTALL_DIR} ARCHIVE DESTINATION ${LIB_INSTALL_DIR} COMPONENT libraries) 28 | -------------------------------------------------------------------------------- /spectrum/src/frontends/slack/SlackFrontendPlugin.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * libtransport -- C++ library for easy XMPP Transports development 3 | * 4 | * Copyright (C) 2011, Jan Kaluza 5 | * 6 | * This program is free software; you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation; either version 2 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program; if not, write to the Free Software 18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA 19 | */ 20 | 21 | #include "SlackFrontendPlugin.h" 22 | #include "SlackFrontend.h" 23 | 24 | #include 25 | 26 | namespace Transport { 27 | 28 | SlackFrontendPlugin::SlackFrontendPlugin() { 29 | 30 | } 31 | 32 | SlackFrontendPlugin::~SlackFrontendPlugin() { 33 | 34 | } 35 | 36 | std::string SlackFrontendPlugin::name() const { 37 | return "slack"; 38 | } 39 | 40 | Frontend *SlackFrontendPlugin::createFrontend() { 41 | return new SlackFrontend(); 42 | } 43 | 44 | // SlackFrontendPlugin plugin; 45 | 46 | std::shared_ptr get_slack_frontend_plugin() { 47 | return std::make_shared(); 48 | } 49 | 50 | // BOOST_DLL_AUTO_ALIAS(plugin) 51 | 52 | } 53 | -------------------------------------------------------------------------------- /spectrum/src/frontends/slack/SlackFrontendPlugin.h: -------------------------------------------------------------------------------- 1 | /** 2 | * libtransport -- C++ library for easy XMPP Transports development 3 | * 4 | * Copyright (C) 2011, Jan Kaluza 5 | * 6 | * This program is free software; you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation; either version 2 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program; if not, write to the Free Software 18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA 19 | */ 20 | 21 | #pragma once 22 | 23 | #include "transport/Frontend.h" 24 | 25 | #include 26 | #include 27 | 28 | namespace Transport { 29 | 30 | class SlackFrontendPlugin : public FrontendPlugin { 31 | public: 32 | SlackFrontendPlugin(); 33 | virtual ~SlackFrontendPlugin(); 34 | 35 | std::string name() const; 36 | Frontend *createFrontend(); 37 | }; 38 | 39 | std::shared_ptr get_slack_frontend_plugin(); 40 | 41 | 42 | } 43 | 44 | BOOST_DLL_ALIAS(Transport::get_slack_frontend_plugin, create_slack_frontend_plugin) 45 | -------------------------------------------------------------------------------- /spectrum/src/frontends/slack/SlackRosterManager.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Spectrum 2 Slack Frontend 3 | * 4 | * Copyright (C) 2015, Jan Kaluza 5 | * 6 | * This program is free software; you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation; either version 2 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program; if not, write to the Free Software 18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA 19 | */ 20 | 21 | #pragma once 22 | 23 | #include "transport/RosterManager.h" 24 | 25 | #include 26 | #include 27 | #include 28 | 29 | #include "Swiften/Network/Timer.h" 30 | 31 | namespace Transport { 32 | 33 | class Buddy; 34 | class User; 35 | class Component; 36 | class StorageBackend; 37 | class RosterStorage; 38 | 39 | class SlackRosterManager : public RosterManager { 40 | public: 41 | SlackRosterManager(User *user, Component *component); 42 | 43 | virtual ~SlackRosterManager(); 44 | 45 | virtual void doRemoveBuddy(Buddy *buddy); 46 | virtual void doAddBuddy(Buddy *buddy); 47 | virtual void doUpdateBuddy(Buddy *buddy); 48 | 49 | void sendOnlineBuddies(); 50 | 51 | private: 52 | RosterStorage *m_rosterStorage; 53 | User *m_user; 54 | Component *m_component; 55 | Swift::Timer::ref m_onlineBuddiesTimer; 56 | std::string m_onlineBuddies; 57 | }; 58 | 59 | } 60 | -------------------------------------------------------------------------------- /spectrum/src/frontends/slack/SlackUser.h: -------------------------------------------------------------------------------- 1 | /** 2 | * libtransport -- C++ library for easy XMPP Transports development 3 | * 4 | * Copyright (C) 2011, Jan Kaluza 5 | * 6 | * This program is free software; you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation; either version 2 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program; if not, write to the Free Software 18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA 19 | */ 20 | 21 | #pragma once 22 | 23 | #include "transport/User.h" 24 | 25 | #include 26 | 27 | namespace Transport { 28 | 29 | class Component; 30 | class RosterManager; 31 | class ConversationManager; 32 | class UserManager; 33 | class PresenceOracle; 34 | struct UserInfo; 35 | class SlackSession; 36 | 37 | class SlackUser : public User { 38 | public: 39 | SlackUser(const Swift::JID &jid, UserInfo &userInfo, Component * component, UserManager *userManager); 40 | 41 | virtual ~SlackUser(); 42 | 43 | void disconnectUser(const std::string &error, Swift::SpectrumErrorPayload::Error e); 44 | 45 | SlackSession *getSession() { 46 | return m_session; 47 | } 48 | 49 | private: 50 | Swift::JID m_jid; 51 | Component *m_component; 52 | UserManager *m_userManager; 53 | UserInfo m_userInfo; 54 | SlackSession *m_session; 55 | }; 56 | 57 | } 58 | -------------------------------------------------------------------------------- /spectrum/src/frontends/xmpp/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | file(GLOB SRC *.cpp *.h) 2 | file(GLOB HEADERS ${CMAKE_SOURCE_DIR}/include/transport/*.h) 3 | 4 | include_directories(${CMAKE_SOURCE_DIR}/spectrum/src/frontends/xmpp) 5 | 6 | if(NOT WIN32) 7 | add_library(spectrum2-xmpp-frontend STATIC ${HEADERS} ${SRC} ${EXTRA_SOURCES}) 8 | else() 9 | add_library(spectrum2-xmpp-frontend STATIC ${HEADERS} ${SRC} ${EXTRA_SOURCES} ) 10 | endif() 11 | 12 | add_dependencies(spectrum2-xmpp-frontend transport) 13 | target_compile_features(spectrum2-xmpp-frontend PUBLIC cxx_std_11) 14 | 15 | if(CMAKE_COMPILER_IS_GNUCXX) 16 | if(NOT WIN32) 17 | add_definitions(-fPIC) 18 | endif() 19 | endif() 20 | 21 | target_link_libraries(spectrum2-xmpp-frontend transport ${LOG4CXX_LIBRARIES} ${Boost_LIBRARIES} ${SWIFTEN_LIBRARY}) 22 | 23 | # set_target_properties(transport-plugin PROPERTIES 24 | # VERSION ${TRANSPORT_VERSION} SOVERSION ${TRANSPORT_VERSION} 25 | # ) 26 | 27 | # install(TARGETS transport-plugin LIBRARY DESTINATION ${LIB_INSTALL_DIR} ARCHIVE DESTINATION ${LIB_INSTALL_DIR} COMPONENT libraries) 28 | -------------------------------------------------------------------------------- /spectrum/src/frontends/xmpp/XMPPFrontendPlugin.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * libtransport -- C++ library for easy XMPP Transports development 3 | * 4 | * Copyright (C) 2011, Jan Kaluza 5 | * 6 | * This program is free software; you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation; either version 2 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program; if not, write to the Free Software 18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA 19 | */ 20 | 21 | #include "XMPPFrontendPlugin.h" 22 | #include "XMPPFrontend.h" 23 | 24 | #include 25 | 26 | namespace Transport { 27 | 28 | XMPPFrontendPlugin::XMPPFrontendPlugin() { 29 | 30 | } 31 | 32 | XMPPFrontendPlugin::~XMPPFrontendPlugin() { 33 | 34 | } 35 | 36 | std::string XMPPFrontendPlugin::name() const { 37 | return "xmpp"; 38 | } 39 | 40 | Frontend *XMPPFrontendPlugin::createFrontend() { 41 | return new XMPPFrontend(); 42 | } 43 | 44 | // XMPPFrontendPlugin plugin; 45 | 46 | std::shared_ptr get_xmpp_frontend_plugin() { 47 | return std::make_shared(); 48 | } 49 | 50 | // BOOST_DLL_AUTO_ALIAS(plugin) 51 | 52 | } 53 | -------------------------------------------------------------------------------- /spectrum/src/frontends/xmpp/XMPPFrontendPlugin.h: -------------------------------------------------------------------------------- 1 | /** 2 | * libtransport -- C++ library for easy XMPP Transports development 3 | * 4 | * Copyright (C) 2011, Jan Kaluza 5 | * 6 | * This program is free software; you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation; either version 2 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program; if not, write to the Free Software 18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA 19 | */ 20 | 21 | #pragma once 22 | 23 | #include "transport/Frontend.h" 24 | 25 | #include 26 | #include 27 | 28 | namespace Transport { 29 | 30 | class XMPPFrontendPlugin : public FrontendPlugin { 31 | public: 32 | XMPPFrontendPlugin(); 33 | virtual ~XMPPFrontendPlugin(); 34 | 35 | std::string name() const; 36 | Frontend *createFrontend(); 37 | }; 38 | 39 | std::shared_ptr get_xmpp_frontend_plugin(); 40 | 41 | 42 | } 43 | 44 | BOOST_DLL_ALIAS(Transport::get_xmpp_frontend_plugin, create_xmpp_frontend_plugin) 45 | -------------------------------------------------------------------------------- /spectrum/src/frontends/xmpp/adhoccommand.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * XMPP - libpurple transport 3 | * 4 | * Copyright (C) 2012, Jan Kaluza 5 | * 6 | * This program is free software; you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation; either version 2 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program; if not, write to the Free Software 18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA 19 | */ 20 | 21 | #include "adhoccommand.h" 22 | #include "adhoccommandfactory.h" 23 | #include "transport/UserManager.h" 24 | #include "transport/StorageBackend.h" 25 | #include "transport/Logging.h" 26 | 27 | namespace Transport { 28 | 29 | DEFINE_LOGGER(adHocCommandLogger, "AdHocCommand"); 30 | 31 | AdHocCommand::AdHocCommand(Component *component, UserManager *userManager, StorageBackend *storageBackend, const Swift::JID &initiator, const Swift::JID &to) { 32 | m_component = component; 33 | m_userManager = userManager; 34 | m_storageBackend = storageBackend; 35 | m_initiator = initiator; 36 | m_to = to; 37 | 38 | std::string bucket = "abcdefghijklmnopqrstuvwxyz"; 39 | for (int i = 0; i < 32; i++) { 40 | m_id += bucket[rand() % bucket.size()]; 41 | } 42 | } 43 | 44 | AdHocCommand::~AdHocCommand() { 45 | } 46 | 47 | } 48 | -------------------------------------------------------------------------------- /spectrum/src/frontends/xmpp/adhoccommandfactory.h: -------------------------------------------------------------------------------- 1 | /** 2 | * XMPP - libpurple transport 3 | * 4 | * Copyright (C) 2009, Jan Kaluza 5 | * 6 | * This program is free software; you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation; either version 2 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program; if not, write to the Free Software 18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA 19 | */ 20 | 21 | #pragma once 22 | 23 | #include 24 | #include 25 | #include 26 | #include "adhoccommand.h" 27 | 28 | namespace Transport { 29 | 30 | class Component; 31 | class UserManager; 32 | class StorageBackend; 33 | 34 | class AdHocCommandFactory { 35 | public: 36 | AdHocCommandFactory() {} 37 | 38 | /// Destructor. 39 | virtual ~AdHocCommandFactory() {} 40 | 41 | virtual AdHocCommand *createAdHocCommand(Component *component, UserManager *userManager, StorageBackend *storageBackend, const Swift::JID &initiator, const Swift::JID &to) = 0; 42 | 43 | virtual std::string getNode() = 0; 44 | 45 | virtual std::string getName() = 0; 46 | 47 | virtual std::map &getUserSettings() { 48 | return m_userSettings; 49 | } 50 | 51 | protected: 52 | std::map m_userSettings; 53 | }; 54 | 55 | } 56 | -------------------------------------------------------------------------------- /spectrum/src/frontends/xmpp/blockresponder.h: -------------------------------------------------------------------------------- 1 | /** 2 | * libtransport -- C++ library for easy XMPP Transports development 3 | * 4 | * Copyright (C) 2011, Jan Kaluza 5 | * 6 | * This program is free software; you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation; either version 2 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program; if not, write to the Free Software 18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA 19 | */ 20 | 21 | #pragma once 22 | 23 | #include 24 | 25 | #include 26 | 27 | #include 28 | #include 29 | 30 | 31 | namespace Transport { 32 | 33 | class UserManager; 34 | class Buddy; 35 | 36 | class BlockResponder : public Swift::SetResponder { 37 | public: 38 | BlockResponder(Swift::IQRouter *router, UserManager *userManager); 39 | ~BlockResponder(); 40 | 41 | boost::signals2::signal onBlockToggled; 42 | 43 | private: 44 | virtual bool handleSetRequest(const Swift::JID& from, const Swift::JID& to, const std::string& id, std::shared_ptr payload); 45 | 46 | UserManager *m_userManager; 47 | }; 48 | 49 | } 50 | -------------------------------------------------------------------------------- /spectrum/src/frontends/xmpp/carbonresponder.cpp: -------------------------------------------------------------------------------- 1 | #include "carbonresponder.h" 2 | 3 | #include 4 | #include 5 | #include "Swiften/Queries/IQRouter.h" 6 | #include "Swiften/Elements/ErrorPayload.h" 7 | #include "transport/Logging.h" 8 | 9 | using namespace Swift; 10 | 11 | namespace Transport { 12 | 13 | DEFINE_LOGGER(carbonResponderLogger, "CarbonResponder"); 14 | 15 | CarbonResponder::CarbonResponder(Swift::IQRouter *router) 16 | : Swift::SetResponder(router), 17 | Swift::SetResponder(router) 18 | { 19 | LOG4CXX_TRACE(carbonResponderLogger, "Initialized"); 20 | } 21 | 22 | CarbonResponder::~CarbonResponder() { 23 | } 24 | 25 | void CarbonResponder::start() { 26 | LOG4CXX_TRACE(carbonResponderLogger, "start()"); 27 | CarbonsEnableResponder::start(); 28 | CarbonsDisableResponder::start(); 29 | } 30 | 31 | //Call when DiscoInfoResponder is available 32 | void CarbonResponder::setDiscoInfoResponder(DiscoInfoResponder *discoInfoResponder) { 33 | LOG4CXX_TRACE(carbonResponderLogger, "Registering disco#info features"); 34 | discoInfoResponder->addTransportFeature("urn:xmpp:carbons:2"); 35 | } 36 | 37 | bool CarbonResponder::handleSetRequest(const Swift::JID& from, const Swift::JID& to, const std::string& id, std::shared_ptr payload) { 38 | LOG4CXX_TRACE(carbonResponderLogger, "handle(CarbonsEnable) -> Confirm"); 39 | //Always confirm 40 | CarbonsEnableResponder::getIQRouter()->sendIQ(Swift::IQ::createResult(from, to, id)); 41 | return true; 42 | } 43 | 44 | bool CarbonResponder::handleSetRequest(const Swift::JID& from, const Swift::JID& to, const std::string& id, std::shared_ptr payload) { 45 | LOG4CXX_TRACE(carbonResponderLogger, "handle(CarbonsDisable) -> NotImplemented"); 46 | //Never allow 47 | CarbonsDisableResponder::sendError(from, id, Swift::ErrorPayload::FeatureNotImplemented, Swift::ErrorPayload::Cancel); 48 | return true; 49 | } 50 | 51 | } 52 | -------------------------------------------------------------------------------- /spectrum/src/frontends/xmpp/carbonresponder.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include "Swiften/Queries/SetResponder.h" 5 | #include "Swiften/Elements/CarbonsEnable.h" 6 | #include "Swiften/Elements/CarbonsDisable.h" 7 | 8 | #include "discoinforesponder.h" 9 | 10 | namespace Transport { 11 | 12 | typedef Swift::SetResponder CarbonsEnableResponder; 13 | typedef Swift::SetResponder CarbonsDisableResponder; 14 | 15 | class CarbonResponder : public CarbonsEnableResponder, public CarbonsDisableResponder { 16 | public: 17 | CarbonResponder(Swift::IQRouter *router); 18 | ~CarbonResponder(); 19 | void start(); 20 | void setDiscoInfoResponder(DiscoInfoResponder *discoInfoResponder); //can be after start() 21 | 22 | private: 23 | virtual bool handleSetRequest(const Swift::JID& from, const Swift::JID& to, const std::string& id, std::shared_ptr payload); 24 | virtual bool handleSetRequest(const Swift::JID& from, const Swift::JID& to, const std::string& id, std::shared_ptr payload); 25 | }; 26 | 27 | } 28 | -------------------------------------------------------------------------------- /spectrum/src/frontends/xmpp/gatewayresponder.h: -------------------------------------------------------------------------------- 1 | /** 2 | * libtransport -- C++ library for easy XMPP Transports development 3 | * 4 | * Copyright (C) 2011, Jan Kaluza 5 | * 6 | * This program is free software; you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation; either version 2 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program; if not, write to the Free Software 18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA 19 | */ 20 | 21 | #pragma once 22 | 23 | #include 24 | #include "Swiften/Queries/Responder.h" 25 | #include "Swiften/Elements/GatewayPayload.h" 26 | 27 | namespace Transport { 28 | 29 | class UserManager; 30 | 31 | class GatewayResponder : public Swift::Responder { 32 | public: 33 | GatewayResponder(Swift::IQRouter *router, UserManager *userManager); 34 | ~GatewayResponder(); 35 | 36 | private: 37 | virtual bool handleGetRequest(const Swift::JID& from, const Swift::JID& to, const std::string& id, std::shared_ptr payload); 38 | virtual bool handleSetRequest(const Swift::JID& from, const Swift::JID& to, const std::string& id, std::shared_ptr payload); 39 | UserManager *m_userManager; 40 | }; 41 | 42 | } 43 | -------------------------------------------------------------------------------- /spectrum/src/frontends/xmpp/statsresponder.h: -------------------------------------------------------------------------------- 1 | /** 2 | * libtransport -- C++ library for easy XMPP Transports development 3 | * 4 | * Copyright (C) 2011, Jan Kaluza 5 | * 6 | * This program is free software; you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation; either version 2 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program; if not, write to the Free Software 18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA 19 | */ 20 | 21 | #pragma once 22 | 23 | #include 24 | #include "Swiften/Queries/SetResponder.h" 25 | #include "Swiften/Elements/StatsPayload.h" 26 | 27 | namespace Transport { 28 | 29 | class Component; 30 | class UserManager; 31 | class NetworkPluginServer; 32 | class StorageBackend; 33 | 34 | class StatsResponder : public Swift::Responder { 35 | public: 36 | StatsResponder(Component *component, UserManager *userManager, NetworkPluginServer *server, StorageBackend *storageBackend); 37 | ~StatsResponder(); 38 | 39 | private: 40 | virtual bool handleGetRequest(const Swift::JID& from, const Swift::JID& to, const std::string& id, std::shared_ptr payload); 41 | virtual bool handleSetRequest(const Swift::JID& from, const Swift::JID& to, const std::string& id, std::shared_ptr payload); 42 | 43 | unsigned long usedMemory(); 44 | 45 | Component *m_component; 46 | UserManager *m_userManager; 47 | NetworkPluginServer *m_server; 48 | StorageBackend *m_storageBackend; 49 | time_t m_start; 50 | }; 51 | 52 | } 53 | -------------------------------------------------------------------------------- /spectrum/src/frontends/xmpp/storageparser.cpp: -------------------------------------------------------------------------------- 1 | #include "storageparser.h" 2 | #include "Swiften/Parser/PayloadParsers/RawXMLPayloadParser.h" 3 | 4 | using namespace Swift; 5 | 6 | namespace Transport { 7 | 8 | StorageParser::StorageParser() : level(0) { 9 | } 10 | 11 | void StorageParser::handleStartElement(const std::string& element, const std::string& ns, const AttributeMap& attributes) { 12 | if (level == 1) { 13 | currentPayloadParser.reset(new RawXMLPayloadParser()); 14 | } 15 | 16 | if (level >= 1 && currentPayloadParser.get()) { 17 | currentPayloadParser->handleStartElement(element, ns, attributes); 18 | } 19 | ++level; 20 | } 21 | 22 | void StorageParser::handleEndElement(const std::string& element, const std::string& ns) { 23 | --level; 24 | if (currentPayloadParser.get()) { 25 | if (level >= 1) { 26 | currentPayloadParser->handleEndElement(element, ns); 27 | } 28 | 29 | if (level == 1) { 30 | getPayloadInternal()->setPayload(currentPayloadParser->getPayload()); 31 | } 32 | } 33 | } 34 | 35 | void StorageParser::handleCharacterData(const std::string& data) { 36 | if (level > 1 && currentPayloadParser.get()) { 37 | currentPayloadParser->handleCharacterData(data); 38 | } 39 | } 40 | 41 | } 42 | -------------------------------------------------------------------------------- /spectrum/src/frontends/xmpp/storageparser.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | #include "Swiften/Elements/PrivateStorage.h" 6 | #include "Swiften/Parser/GenericPayloadParser.h" 7 | 8 | namespace Transport { 9 | 10 | class StorageParser : public Swift::GenericPayloadParser { 11 | public: 12 | StorageParser(); 13 | 14 | private: 15 | virtual void handleStartElement(const std::string& element, const std::string&, const Swift::AttributeMap& attributes); 16 | virtual void handleEndElement(const std::string& element, const std::string&); 17 | virtual void handleCharacterData(const std::string& data); 18 | 19 | private: 20 | int level; 21 | std::unique_ptr currentPayloadParser; 22 | }; 23 | } 24 | -------------------------------------------------------------------------------- /spectrum/src/frontends/xmpp/storageresponder.h: -------------------------------------------------------------------------------- 1 | /** 2 | * libtransport -- C++ library for easy XMPP Transports development 3 | * 4 | * Copyright (C) 2011, Jan Kaluza 5 | * 6 | * This program is free software; you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation; either version 2 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program; if not, write to the Free Software 18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA 19 | */ 20 | 21 | #pragma once 22 | 23 | #include 24 | #include "Swiften/Queries/Responder.h" 25 | #include "Swiften/Elements/RosterPayload.h" 26 | #include "Swiften/Elements/PrivateStorage.h" 27 | 28 | namespace Transport { 29 | 30 | class StorageBackend; 31 | class UserManager; 32 | 33 | class StorageResponder : public Swift::Responder { 34 | public: 35 | StorageResponder(Swift::IQRouter *router, StorageBackend *storageBackend, UserManager *userManager); 36 | ~StorageResponder(); 37 | 38 | private: 39 | virtual bool handleGetRequest(const Swift::JID& from, const Swift::JID& to, const std::string& id, std::shared_ptr payload); 40 | virtual bool handleSetRequest(const Swift::JID& from, const Swift::JID& to, const std::string& id, std::shared_ptr payload); 41 | StorageBackend *m_storageBackend; 42 | UserManager *m_userManager; 43 | }; 44 | 45 | } 46 | -------------------------------------------------------------------------------- /spectrum/src/logging.cfg: -------------------------------------------------------------------------------- 1 | log4j.rootLogger=debug, R 2 | 3 | log4j.appender.R=org.apache.log4j.RollingFileAppender 4 | log4j.appender.R.File=/var/log/spectrum2/${jid}/spectrum2.log 5 | 6 | log4j.appender.R.MaxFileSize=10000KB 7 | # Keep one backup file 8 | log4j.appender.R.MaxBackupIndex=1 9 | 10 | log4j.appender.R.layout=org.apache.log4j.PatternLayout 11 | log4j.appender.R.layout.ConversionPattern=%d %-5p %c: %m%n 12 | 13 | # Disable XML category 14 | log4j.category.Component.XML = OFF 15 | -------------------------------------------------------------------------------- /spectrum/src/manager-logging.cfg: -------------------------------------------------------------------------------- 1 | log4j.rootLogger=debug, R 2 | 3 | log4j.appender.R=org.apache.log4j.RollingFileAppender 4 | log4j.appender.R.File=/var/log/spectrum2/spectrum_manager.log 5 | 6 | log4j.appender.R.MaxFileSize=10000KB 7 | # Keep one backup file 8 | log4j.appender.R.MaxBackupIndex=1 9 | 10 | log4j.appender.R.layout=org.apache.log4j.PatternLayout 11 | log4j.appender.R.layout.ConversionPattern=%d %-5p %c: %m%n 12 | -------------------------------------------------------------------------------- /spectrum/src/sample.cfg: -------------------------------------------------------------------------------- 1 | [service] 2 | jid = gateway.localhost 3 | password = secret 4 | server = 127.0.0.1 5 | port = 5347 6 | server_mode = 0 7 | backend_host=127.0.0.1 8 | pidfile=./test.pid 9 | # < this option doesn't work yet 10 | #backend_port=10001 11 | #admin_jid=admin@localhost 12 | admin_password=test 13 | #cert=server.pfx #patch to PKCS#12 certificate 14 | #cert_password=test #password to that certificate if any 15 | users_per_backend=10 16 | backend=../..//backends/libpurple/spectrum2_libpurple_backend 17 | #backend=../../backends/twitter/spectrum2_twitter_backend 18 | #backend=/home/hanzz/code/libtransport/backends/libcommuni/spectrum2_libcommuni_backend 19 | protocol=prpl-telegram 20 | #protocol=prpl-msn 21 | #protocol=any 22 | #protocol=prpl-icq 23 | working_dir=./ 24 | portfile=./$jid.port 25 | irc_server=irc.freenode.org 26 | 27 | [backend] 28 | #default_avatar=catmelonhead.jpg 29 | #no_vcard_fetch=true 30 | 31 | [logging] 32 | #config=logging.cfg # log4cxx/log4j logging configuration file 33 | #backend_config=/home/hanzz/code/libtransport/spectrum/src/backend-logging.cfg # log4cxx/log4j logging configuration file for backends 34 | 35 | [database] 36 | type=sqlite3 # or "none" without database backend 37 | database=users.sqlite 38 | prefix=twitter8 39 | #type = mysql # or "none" without database backend....................................................................................................................... 40 | #database = test 41 | #prefix= 42 | #user=root 43 | #password=yourrootsqlpassword 44 | #encryption_key=hanzzik 45 | -------------------------------------------------------------------------------- /spectrum/src/server.p12: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SpectrumIM/spectrum2/f547a2158bc90302ddfe09915a557d2e4ac4dfe8/spectrum/src/server.p12 -------------------------------------------------------------------------------- /spectrum/src/win32/ServiceWrapper.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "transport/config.h" 3 | #include 4 | #include 5 | 6 | class ServiceWrapper 7 | { 8 | public: 9 | ServiceWrapper(LPSTR serviceName); 10 | ~ServiceWrapper(void); 11 | bool Install(LPSTR commandLine); 12 | bool UnInstall(); 13 | bool IsInstalled(); 14 | void RunService(); 15 | }; 16 | 17 | int mainloop(); 18 | BOOL spectrum_control_handler( DWORD fdwCtrlType ); 19 | 20 | -------------------------------------------------------------------------------- /spectrum_manager/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_subdirectory(src) 2 | -------------------------------------------------------------------------------- /spectrum_manager/src/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | file(GLOB SRC *.cpp *.c) 2 | 3 | add_executable(spectrum2_manager ${SRC}) 4 | add_dependencies(spectrum2_manager pb) 5 | set_source_files_properties(${CMAKE_CURRENT_SOURCE_DIR}/../../include/transport/protocol.pb.cc PROPERTIES GENERATED 1) 6 | 7 | target_include_directories(spectrum2_manager PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}) 8 | target_link_libraries(spectrum2_manager transport ${SWIFTEN_LIBRARY} ${PROTOBUF_LIBRARIES}) 9 | target_compile_features(spectrum2_manager PUBLIC cxx_std_11) 10 | 11 | if (ENABLE_WEBUI) 12 | add_definitions(-DENABLE_WEBUI) 13 | file(GLOB SERVER_SRC ${CMAKE_CURRENT_SOURCE_DIR}/server/*.cpp ${CMAKE_CURRENT_SOURCE_DIR}/server/*.c) 14 | target_sources(spectrum2_manager PRIVATE ${SERVER_SRC}) 15 | if(${OPENSSL_FOUND}) 16 | add_definitions(-DMG_ENABLE_SSL) 17 | endif() 18 | endif() 19 | 20 | if(CMAKE_COMPILER_IS_GNUCXX) 21 | target_link_libraries(spectrum2_manager ${OPENSSL_LIBRARIES}) 22 | endif() 23 | 24 | if(APPLE) 25 | target_link_libraries(spectrum2_manager transport ${APPLE_FRAMEWORKS}) 26 | endif() 27 | 28 | install(TARGETS spectrum2_manager RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) 29 | 30 | # if(NOT EXISTS "/etc/spectrum2/spectrum_manager.cfg") 31 | # install(FILES 32 | # spectrum_manager.cfg 33 | # DESTINATION /etc/spectrum2 34 | # ) 35 | # endif() 36 | 37 | install(CODE " 38 | if(NOT EXISTS \"$ENV{DESTDIR}/${CMAKE_INSTALL_SYSCONFDIR}/spectrum2/spectrum_manager.cfg\") 39 | file(INSTALL DESTINATION \"${CMAKE_INSTALL_SYSCONFDIR}/spectrum2\" TYPE FILES \"${CMAKE_CURRENT_SOURCE_DIR}/spectrum_manager.cfg\") 40 | endif() 41 | ") 42 | 43 | if (ENABLE_WEBUI) 44 | install(DIRECTORY 45 | html 46 | DESTINATION ${CMAKE_INSTALL_LOCALSTATEDIR}/lib/spectrum2_manager 47 | ) 48 | endif() 49 | -------------------------------------------------------------------------------- /spectrum_manager/src/html/footer.shtml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /spectrum_manager/src/html/instances/index.shtml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /spectrum_manager/src/html/instances/instance.shtml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /spectrum_manager/src/html/js/config.js: -------------------------------------------------------------------------------- 1 | var BaseLocation = "/spectrum/"; 2 | -------------------------------------------------------------------------------- /spectrum_manager/src/html/logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SpectrumIM/spectrum2/f547a2158bc90302ddfe09915a557d2e4ac4dfe8/spectrum_manager/src/html/logo.png -------------------------------------------------------------------------------- /spectrum_manager/src/html/users/list.shtml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /spectrum_manager/src/html/users/register.shtml: -------------------------------------------------------------------------------- 1 | 2 | 3 |

Register new Spectrum 2 manager account

4 |
5 |
6 |

Register user 7 | Register new user to Spectrum 2 manager web interface. 8 |

9 | 13 | 16 | 20 |

21 | 22 | 27 | 28 | 29 | -------------------------------------------------------------------------------- /spectrum_manager/src/spectrum_manager.cfg: -------------------------------------------------------------------------------- 1 | [service] 2 | config_directory=/etc/spectrum2/transports/ 3 | 4 | # Username and password of admin for Web interface 5 | # Note: The server will reject: 6 | # - an empty password, 7 | # - "test" as password (used in previous versions as default password.) 8 | admin_username=admin 9 | admin_password= 10 | 11 | # Bind web interface to this IP only. If empty or undefined it will listen on all interfaces. 12 | # defaults to localhost. Set to empty string to listen on all interfaces. 13 | #bind=localhost 14 | # Port on which the Web interface is listening on 15 | port=8080 16 | 17 | # Base location (directory) on which the Web interface is served. It must ends 18 | # up with slash character (/). If you for example set it to "/spectrum/", then 19 | # the Web interface will be served on http://localhost:$port/spectrum/. 20 | base_location=/ 21 | 22 | [database] 23 | type=sqlite3 24 | database=/var/lib/spectrum2_manager/database.sql 25 | 26 | [servers] 27 | server=localhost 28 | #server=icq.spectrum.im 29 | #server=msn.spectrum.im -------------------------------------------------------------------------------- /tests/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_subdirectory(libtransport) 2 | 3 | if(ENABLE_TESTS) 4 | 5 | add_custom_target(test 6 | COMMAND ${CMAKE_CURRENT_BINARY_DIR}/libtransport/libtransport_test 7 | WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/tests_output 8 | ) 9 | 10 | add_custom_target(extended_test 11 | COMMAND ${CMAKE_CURRENT_BINARY_DIR}/libtransport/libtransport_test 12 | COMMAND python3 ${CMAKE_CURRENT_SOURCE_DIR}/start.py 13 | WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/tests_output 14 | ) 15 | 16 | endif() 17 | 18 | -------------------------------------------------------------------------------- /tests/libcommuni/irc_test.cfg: -------------------------------------------------------------------------------- 1 | [service] 2 | jid = localhost 3 | password = secret 4 | server = 127.0.0.1 5 | port = 5223 6 | server_mode = 1 7 | backend_host=127.0.0.1 8 | pidfile=./test.pid 9 | # < this option doesn't work yet 10 | #backend_port=10001 11 | #admin_jid=admin@localhost 12 | admin_password=test 13 | #cert=server.pfx #patch to PKCS#12 certificate 14 | #cert_password=test #password to that certificate if any 15 | users_per_backend=10 16 | #backend=../..//backends/swiften/spectrum2_swiften_backend 17 | #backend=../../../backends/twitter/spectrum2_twitter_backend 18 | backend=../../backends/libcommuni/spectrum2_libcommuni_backend 19 | protocol=prpl-jabber 20 | #protocol=prpl-msn 21 | #protocol=any 22 | #protocol=prpl-icq 23 | working_dir=./ 24 | portfile=./$jid.port 25 | irc_server=localhost 26 | irc_away_timeout=2 27 | 28 | [backend] 29 | #default_avatar=catmelonhead.jpg 30 | #no_vcard_fetch=true 31 | 32 | [logging] 33 | config=../libpurple_jabber/logging.cfg 34 | backend_config=../libpurple_jabber/logging-backend.cfg 35 | 36 | [database] 37 | type=sqlite3 # or "none" without database backend 38 | database=users.sqlite 39 | prefix=twitter 40 | #type = mysql # or "none" without database backend....................................................................................................................... 41 | #database = test 42 | #prefix= 43 | #user=root 44 | #password=yourrootsqlpassword 45 | #encryption_key=hanzzik 46 | -------------------------------------------------------------------------------- /tests/libcommuni/irc_test2.cfg: -------------------------------------------------------------------------------- 1 | [service] 2 | jid = localhost 3 | password = secret 4 | server = 127.0.0.1 5 | port = 5223 6 | server_mode = 1 7 | backend_host=127.0.0.1 8 | pidfile=./test.pid 9 | # < this option doesn't work yet 10 | #backend_port=10001 11 | #admin_jid=admin@localhost 12 | admin_password=test 13 | #cert=server.pfx #patch to PKCS#12 certificate 14 | #cert_password=test #password to that certificate if any 15 | users_per_backend=10 16 | #backend=../..//backends/swiften/spectrum2_swiften_backend 17 | #backend=../../../backends/twitter/spectrum2_twitter_backend 18 | backend=../../backends/libcommuni/spectrum2_libcommuni_backend 19 | protocol=prpl-jabber 20 | #protocol=prpl-msn 21 | #protocol=any 22 | #protocol=prpl-icq 23 | working_dir=./ 24 | portfile=./$jid.port 25 | irc_away_timeout=2 26 | 27 | [backend] 28 | #default_avatar=catmelonhead.jpg 29 | #no_vcard_fetch=true 30 | 31 | [logging] 32 | config=../libpurple_jabber/logging.cfg 33 | backend_config=../libpurple_jabber/logging-backend.cfg 34 | 35 | [database] 36 | type=sqlite3 # or "none" without database backend 37 | database=users.sqlite 38 | prefix=twitter 39 | #type = mysql # or "none" without database backend....................................................................................................................... 40 | #database = test 41 | #prefix= 42 | #user=root 43 | #password=yourrootsqlpassword 44 | #encryption_key=hanzzik 45 | -------------------------------------------------------------------------------- /tests/libcommuni/muc_away.py: -------------------------------------------------------------------------------- 1 | import optparse 2 | import sys 3 | import time 4 | import subprocess 5 | import os 6 | 7 | import sleekxmpp 8 | 9 | 10 | class Responder(sleekxmpp.ClientXMPP): 11 | def __init__(self, jid, password, room, room_password, nick): 12 | sleekxmpp.ClientXMPP.__init__(self, jid, password) 13 | self.room = room 14 | self.room_password = room_password 15 | self.nick = nick 16 | self.finished = False 17 | self.add_event_handler("session_start", self.start) 18 | self.add_event_handler("muc::" + room + "::presence", self.muc_got_online) 19 | 20 | self.tests = {} 21 | self.tests["online_received"] = ["libcommuni: Received away presence from 'client'", False] 22 | 23 | def muc_got_online(self, presence): 24 | if presence['muc']['nick'] == "client" and presence['show'] == "away": 25 | self.tests["online_received"][1] = True 26 | self.finished = True 27 | 28 | def start(self, event): 29 | self.plugin['xep_0045'].joinMUC(self.room, self.nick, password=self.room_password, wait=True) 30 | 31 | class Client(sleekxmpp.ClientXMPP): 32 | def __init__(self, jid, password, room, nick): 33 | sleekxmpp.ClientXMPP.__init__(self, jid, password) 34 | self.room = room 35 | self.nick = nick 36 | self.add_event_handler("session_start", self.start) 37 | self.finished = False 38 | 39 | self.tests = {} 40 | 41 | def start(self, event): 42 | self.getRoster() 43 | self.sendPresence() 44 | self.plugin['xep_0045'].joinMUC(self.room, self.nick, wait=True) 45 | self.sendPresence(ptype = "away") 46 | 47 | -------------------------------------------------------------------------------- /tests/libcommuni/muc_change_topic.py: -------------------------------------------------------------------------------- 1 | import optparse 2 | import sys 3 | import time 4 | import subprocess 5 | import os 6 | 7 | import sleekxmpp 8 | 9 | 10 | class Responder(sleekxmpp.ClientXMPP): 11 | def __init__(self, jid, password, room, room_password, nick): 12 | sleekxmpp.ClientXMPP.__init__(self, jid, password) 13 | self.room = room 14 | self.nick = nick 15 | self.finished = False 16 | self.room_password = room_password 17 | self.add_event_handler("session_start", self.start) 18 | self.add_event_handler("groupchat_message", self.muc_message) 19 | 20 | self.tests = {} 21 | 22 | def muc_message(self, msg): 23 | if msg['body'] == "ready": 24 | self.send_message(mto=self.room, mbody=None, msubject='The new subject', mtype='groupchat') 25 | 26 | def start(self, event): 27 | self.plugin['xep_0045'].joinMUC(self.room, self.nick, password=self.room_password, wait=True) 28 | 29 | class Client(sleekxmpp.ClientXMPP): 30 | def __init__(self, jid, password, room, nick): 31 | sleekxmpp.ClientXMPP.__init__(self, jid, password) 32 | self.room = room 33 | self.nick = nick 34 | self.add_event_handler("session_start", self.start) 35 | self.add_event_handler("groupchat_subject", self.muc_subject) 36 | self.finished = False 37 | 38 | self.tests = {} 39 | self.tests["subject_changed"] = ["libcommuni: Change topic", False] 40 | 41 | def muc_subject(self, msg): 42 | if msg['subject'] == "The new subject": 43 | self.tests["subject_changed"][1] = True 44 | self.finished = True 45 | 46 | def start(self, event): 47 | self.getRoster() 48 | self.sendPresence() 49 | self.plugin['xep_0045'].joinMUC(self.room, self.nick, wait=True) 50 | self.send_message(mto=self.room, mbody="ready", mtype='groupchat') 51 | -------------------------------------------------------------------------------- /tests/libcommuni/muc_echo.py: -------------------------------------------------------------------------------- 1 | import optparse 2 | import sys 3 | import time 4 | import subprocess 5 | import os 6 | 7 | import sleekxmpp 8 | 9 | 10 | class Responder(sleekxmpp.ClientXMPP): 11 | def __init__(self, jid, password, room, room_password, nick): 12 | sleekxmpp.ClientXMPP.__init__(self, jid, password) 13 | self.room = room 14 | self.nick = nick 15 | self.room_password = room_password 16 | self.finished = False 17 | self.add_event_handler("session_start", self.start) 18 | self.add_event_handler("groupchat_message", self.muc_message) 19 | 20 | self.tests = {} 21 | 22 | def muc_message(self, msg): 23 | if msg['mucnick'] != self.nick: 24 | self.send_message(mto=msg['from'].bare, 25 | mbody="echo %s" % msg['body'], 26 | mtype='groupchat') 27 | 28 | def start(self, event): 29 | self.plugin['xep_0045'].joinMUC(self.room, self.nick, password=self.room_password, wait=True) 30 | 31 | class Client(sleekxmpp.ClientXMPP): 32 | def __init__(self, jid, password, room, nick): 33 | sleekxmpp.ClientXMPP.__init__(self, jid, password) 34 | self.room = room 35 | self.nick = nick 36 | self.add_event_handler("session_start", self.start) 37 | self.add_event_handler("groupchat_message", self.muc_message) 38 | self.finished = False 39 | 40 | self.tests = {} 41 | self.tests["echo_received"] = ["libcommuni: Send and receive messages", False] 42 | 43 | def muc_message(self, msg): 44 | if msg['mucnick'] != self.nick: 45 | if msg['body'] == "echo abc" or msg['body'] == " echo abc": 46 | self.tests["echo_received"][1] = True 47 | self.finished = True 48 | 49 | def start(self, event): 50 | self.getRoster() 51 | self.sendPresence() 52 | self.plugin['xep_0045'].joinMUC(self.room, self.nick, wait=True) 53 | self.send_message(mto=self.room, mbody="abc", mtype='groupchat') 54 | -------------------------------------------------------------------------------- /tests/libcommuni/muc_whois.py: -------------------------------------------------------------------------------- 1 | import optparse 2 | import sys 3 | import time 4 | import subprocess 5 | import os 6 | 7 | import sleekxmpp 8 | 9 | 10 | class Responder(sleekxmpp.ClientXMPP): 11 | def __init__(self, jid, password, room, room_password, nick): 12 | sleekxmpp.ClientXMPP.__init__(self, jid, password) 13 | self.room = room 14 | self.nick = nick 15 | self.finished = False 16 | self.room_password = room_password 17 | self.add_event_handler("session_start", self.start) 18 | self.tests = {} 19 | 20 | def start(self, event): 21 | self.plugin['xep_0045'].joinMUC(self.room, self.nick, password=self.room_password, wait=True) 22 | 23 | class Client(sleekxmpp.ClientXMPP): 24 | def __init__(self, jid, password, room, nick): 25 | sleekxmpp.ClientXMPP.__init__(self, jid, password) 26 | self.room = room 27 | self.nick = nick 28 | self.add_event_handler("session_start", self.start) 29 | self.add_event_handler("groupchat_message", self.muc_message) 30 | self.finished = False 31 | 32 | self.tests = {} 33 | self.tests["whois1_received"] = ["libcommuni: Receive /whois command response", False] 34 | self.tests["whois2_received"] = ["libcommuni: Receive /whois command response for invalid nickname", False] 35 | 36 | def muc_message(self, msg): 37 | if msg['mucnick'] != self.nick: 38 | if msg["body"] == "responder is connected to irc.example.net (responder)\nresponder is a user on channels: @#channel": 39 | self.tests["whois1_received"][1] = True 40 | elif msg["body"] == "nonexisting: No such client": 41 | self.tests["whois2_received"][1] = True 42 | self.finished = True 43 | 44 | def start(self, event): 45 | self.getRoster() 46 | self.sendPresence() 47 | self.plugin['xep_0045'].joinMUC(self.room, self.nick, wait=True) 48 | self.send_message(mto=self.room, mbody="/whois responder", mtype='groupchat') 49 | self.send_message(mto=self.room, mbody="/whois nonexisting", mtype='groupchat') 50 | -------------------------------------------------------------------------------- /tests/libpurple_jabber/avatar.py: -------------------------------------------------------------------------------- 1 | import optparse 2 | import sys 3 | import time 4 | import subprocess 5 | import os 6 | 7 | import sleekxmpp 8 | 9 | import struct 10 | import zlib 11 | def chunk(t, data): 12 | return struct.pack('>I', len(data)) + t + data 13 | #+ struct.pack('>I', zlib.crc32(t + data)) 14 | png = b'\x89PNG\r\n\x1A\n' + chunk(b'IHDR', struct.pack('>IIBBBBB', 1, 1, 1, 0, 0, 0, 0)) + chunk(b'IDAT', zlib.compress(struct.pack('>BB', 0, 0))) + chunk(b'IEND', b'') 15 | 16 | 17 | class Responder(sleekxmpp.ClientXMPP): 18 | def __init__(self, jid, password, room, room_password, nick): 19 | sleekxmpp.ClientXMPP.__init__(self, jid, password) 20 | self.room = room 21 | self.room_password = room_password 22 | self.nick = nick 23 | self.finished = False 24 | self.register_plugin('xep_0153') # vCard-based avatars 25 | self.add_event_handler("session_start", self.start) 26 | self.add_event_handler("vcard_avatar_update", self.vcard_avatar_update) 27 | 28 | self.tests = {} 29 | self.tests["photohash"] = ["libpurple: Photo hash received in Presence", False] 30 | 31 | def vcard_avatar_update(self, presence): 32 | self.tests["photohash"][1] = True 33 | self.finished = True 34 | 35 | def start(self, event): 36 | self.getRoster() 37 | self.sendPresence() 38 | 39 | class Client(sleekxmpp.ClientXMPP): 40 | def __init__(self, jid, password, room, nick): 41 | sleekxmpp.ClientXMPP.__init__(self, jid, password) 42 | self.room = room 43 | self.nick = nick 44 | self.register_plugin('xep_0153') # vCard-based avatars 45 | self.add_event_handler("session_start", self.start) 46 | self.finished = False 47 | 48 | self.tests = {} 49 | 50 | def start(self, event): 51 | self.getRoster() 52 | self.sendPresence() 53 | self['xep_0153'].set_avatar(avatar=png, mtype='image/png') 54 | self.finished = True 55 | -------------------------------------------------------------------------------- /tests/libpurple_jabber/jabber_test.cfg: -------------------------------------------------------------------------------- 1 | [service] 2 | jid = localhostxmpp 3 | password = secret 4 | server = 0.0.0.0 5 | port = 5223 6 | server_mode = 1 7 | backend_host=127.0.0.1 8 | pidfile=./test.pid 9 | # < this option doesn't work yet 10 | #backend_port=10001 11 | admin_jid=admin 12 | admin_password=test 13 | #cert=server.pfx #patch to PKCS#12 certificate 14 | #cert_password=test #password to that certificate if any 15 | users_per_backend=10 16 | backend=../../backends/libpurple/spectrum2_libpurple_backend 17 | protocol=prpl-jabber 18 | #protocol=prpl-msn 19 | #protocol=any 20 | #protocol=prpl-icq 21 | working_dir=./ 22 | portfile=./$jid.port 23 | irc_server=localhost 24 | 25 | [backend] 26 | #default_avatar=catmelonhead.jpg 27 | #no_vcard_fetch=true 28 | 29 | [logging] 30 | # Paths have to be relative to the working dir 31 | config=../libpurple_jabber/logging.cfg 32 | backend_config=../libpurple_jabber/logging-backend.cfg 33 | 34 | [database] 35 | type=sqlite3 # or "none" without database backend 36 | database=users.sqlite 37 | prefix=twitter 38 | #type = mysql # or "none" without database backend....................................................................................................................... 39 | #database = test 40 | #prefix= 41 | #user=root 42 | #password=yourrootsqlpassword 43 | #encryption_key=hanzzik 44 | [purple] 45 | auth_plain_in_clear=1 46 | connection_security=opportunistic_tls -------------------------------------------------------------------------------- /tests/libpurple_jabber/logging-backend.cfg: -------------------------------------------------------------------------------- 1 | log4j.rootLogger=debug, R 2 | log4j.appender.R=org.apache.log4j.SyslogAppender 3 | log4j.appender.R.layout=org.apache.log4j.PatternLayout 4 | log4j.appender.R.layout.ConversionPattern=${pid}: %d %-5p %c: %m%n 5 | -------------------------------------------------------------------------------- /tests/libpurple_jabber/logging.cfg: -------------------------------------------------------------------------------- 1 | log4j.rootLogger=debug, R 2 | log4j.appender.R=org.apache.log4j.SyslogAppender 3 | log4j.appender.R.layout=org.apache.log4j.PatternLayout 4 | log4j.appender.R.layout.ConversionPattern=%d %-5p %c: %m%n 5 | -------------------------------------------------------------------------------- /tests/libpurple_jabber/manager.conf: -------------------------------------------------------------------------------- 1 | [service] 2 | admin_username=admin 3 | admin_password=test 4 | config_directory=../libpurple_jabber/ 5 | 6 | [servers] 7 | server=localhostxmpp 8 | #server=icq.spectrum.im 9 | #server=msn.spectrum.im -------------------------------------------------------------------------------- /tests/libpurple_jabber/muc_join_leave.py: -------------------------------------------------------------------------------- 1 | import optparse 2 | import sys 3 | import time 4 | import subprocess 5 | import os 6 | 7 | import sleekxmpp 8 | 9 | 10 | class Responder(sleekxmpp.ClientXMPP): 11 | def __init__(self, jid, password, room, room_password, nick): 12 | sleekxmpp.ClientXMPP.__init__(self, jid, password) 13 | self.room = room 14 | self.room_password = room_password 15 | self.nick = nick 16 | self.finished = False 17 | self.add_event_handler("session_start", self.start) 18 | self.add_event_handler("muc::" + room + "::got_online", self.muc_got_online) 19 | self.add_event_handler("muc::" + room + "::got_offline", self.muc_got_offline) 20 | 21 | self.tests = {} 22 | self.tests["online_received"] = ["MUC: Received available presence", False] 23 | self.tests["offline_received"] = ["MUC: Received unavailable presence", False] 24 | 25 | def muc_got_online(self, presence): 26 | if presence['muc']['nick'] == "client": 27 | self.tests["online_received"][1] = True 28 | 29 | def muc_got_offline(self, presence): 30 | if presence['muc']['nick'] == "client": 31 | self.tests["offline_received"][1] = True 32 | self.finished = True 33 | 34 | def start(self, event): 35 | self.plugin['xep_0045'].joinMUC(self.room, self.nick, password=self.room_password, wait=True) 36 | 37 | class Client(sleekxmpp.ClientXMPP): 38 | def __init__(self, jid, password, room, nick): 39 | sleekxmpp.ClientXMPP.__init__(self, jid, password) 40 | self.room = room 41 | self.nick = nick 42 | self.add_event_handler("session_start", self.start) 43 | self.finished = False 44 | 45 | self.tests = {} 46 | 47 | def start(self, event): 48 | self.getRoster() 49 | self.sendPresence() 50 | self.plugin['xep_0045'].joinMUC(self.room, self.nick, wait=True) 51 | self.plugin['xep_0045'].leaveMUC(self.room, self.nick) 52 | self.finished = True 53 | -------------------------------------------------------------------------------- /tests/libpurple_jabber/muc_topic.py: -------------------------------------------------------------------------------- 1 | import optparse 2 | import sys 3 | import time 4 | import subprocess 5 | import os 6 | 7 | import sleekxmpp 8 | 9 | 10 | class Responder(sleekxmpp.ClientXMPP): 11 | def __init__(self, jid, password, room, room_password, nick): 12 | sleekxmpp.ClientXMPP.__init__(self, jid, password) 13 | self.room = room 14 | self.room_password = room_password 15 | self.nick = nick 16 | self.finished = False 17 | self.add_event_handler("session_start", self.start) 18 | self.add_event_handler("groupchat_subject", self.message) 19 | 20 | self.tests = {} 21 | self.tests["subject_set1"] = ["libpurple: Set subject", False] 22 | 23 | def message(self, msg): 24 | if msg['subject'] == "New subject": 25 | self.tests["subject_set1"][1] = True 26 | self.finished = True 27 | 28 | def start(self, event): 29 | self.plugin['xep_0045'].joinMUC(self.room, self.nick, password=self.room_password, wait=True) 30 | self.send_message(mto=self.room, mbody=None, msubject="New subject", mtype='groupchat') 31 | 32 | class Client(sleekxmpp.ClientXMPP): 33 | def __init__(self, jid, password, room, nick): 34 | sleekxmpp.ClientXMPP.__init__(self, jid, password) 35 | self.room = room 36 | self.nick = nick 37 | self.add_event_handler("session_start", self.start) 38 | self.add_event_handler("groupchat_subject", self.message) 39 | self.finished = False 40 | 41 | self.tests = {} 42 | self.tests["subject_set2"] = ["libpurple: Receive subject", False] 43 | 44 | def message(self, msg): 45 | if msg['subject'] == "New subject": 46 | self.tests["subject_set2"][1] = True 47 | self.finished = True 48 | 49 | def start(self, event): 50 | self.getRoster() 51 | self.sendPresence() 52 | self.plugin['xep_0045'].joinMUC(self.room, self.nick, wait=True) 53 | -------------------------------------------------------------------------------- /tests/libpurple_jabber/prefs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /tests/libtransport/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | file(GLOB SRC *.cpp *.h) 2 | file(GLOB_RECURSE SWIFTEN_SRC ../include/Swiften/*.cpp) 3 | 4 | # Build without openssl on msvc 5 | if(NOT MSVC) 6 | if(APPLE) 7 | string(REGEX REPLACE "[^;]+;?/Schannel/[^;]+;?" "" SWIFTEN_SRC "${SWIFTEN_SRC}") 8 | string(REGEX REPLACE "[^;]+;?/OpenSSL/[^;]+;?" "" SWIFTEN_SRC "${SWIFTEN_SRC}") 9 | else() 10 | string(REGEX REPLACE "[^;]+;?/Schannel/[^;]+;?" "" SWIFTEN_SRC "${SWIFTEN_SRC}") 11 | string(REGEX REPLACE "[^;]+;?/SecureTransport/[^;]+;?" "" SWIFTEN_SRC "${SWIFTEN_SRC}") 12 | endif() 13 | else() 14 | string(REGEX REPLACE "[^;]+;?/OpenSSL/[^;]+;?" "" SWIFTEN_SRC "${SWIFTEN_SRC}") 15 | string(REGEX REPLACE "[^;]+;?/SecureTransport/[^;]+;?" "" SWIFTEN_SRC "${SWIFTEN_SRC}") 16 | endif() 17 | 18 | file(GLOB HEADERS ../../include/transport/*.h) 19 | include_directories(../../spectrum/src/frontends/xmpp/) 20 | include_directories(../../spectrum/src/frontends/slack/) 21 | 22 | if(CPPUNIT_FOUND) 23 | file(GLOB SRC_TEST *.cpp) 24 | file(GLOB SRC_TEST_FRONTEND_XMPP ../../spectrum/src/frontends/xmpp/*.cpp) 25 | file(GLOB SRC_TEST_FRONTEND_SLACK ../../spectrum/src/frontends/slack/*.cpp) 26 | 27 | add_executable(libtransport_test ${SRC_TEST} ${SRC_TEST_FRONTEND_XMPP} ${SRC_TEST_FRONTEND_SLACK}) 28 | target_compile_features(libtransport_test PUBLIC cxx_std_11) 29 | set_target_properties(libtransport_test PROPERTIES COMPILE_DEFINITIONS LIBTRANSPORT_TEST=1) 30 | 31 | 32 | target_link_libraries(libtransport_test transport ${CPPUNIT_LIBRARY} ${Boost_LIBRARIES}) 33 | endif() 34 | -------------------------------------------------------------------------------- /tests/libtransport/main.h: -------------------------------------------------------------------------------- 1 | #ifndef TESTS_MAIN_H 2 | #define TESTS_MAIN_H 3 | #include 4 | #include 5 | 6 | #endif 7 | -------------------------------------------------------------------------------- /tests/libtransport/stringtreeparser.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include "Swiften/Server/ServerStanzaChannel.h" 10 | #include "Swiften/Server/ServerFromClientSession.h" 11 | #include "Swiften/Parser/PayloadParsers/FullPayloadParserFactoryCollection.h" 12 | #include "basictest.h" 13 | 14 | #include "transport/Util.h" 15 | 16 | using namespace Transport; 17 | 18 | class StringTreeParserTest : public CPPUNIT_NS :: TestFixture{ 19 | CPPUNIT_TEST_SUITE(StringTreeParserTest); 20 | CPPUNIT_TEST(parseEscapedCharacters); 21 | CPPUNIT_TEST_SUITE_END(); 22 | 23 | public: 24 | void setUp (void) { 25 | } 26 | 27 | void tearDown (void) { 28 | 29 | } 30 | 31 | void parseEscapedCharacters() { 32 | Swift::ParserElement::ref root = Swift::StringTreeParser::parse("<test>"); 33 | CPPUNIT_ASSERT_EQUAL(std::string(""), root->getText()); 34 | } 35 | 36 | }; 37 | 38 | CPPUNIT_TEST_SUITE_REGISTRATION (StringTreeParserTest); 39 | -------------------------------------------------------------------------------- /tests/prosody/data/.gitignore: -------------------------------------------------------------------------------- 1 | * 2 | !.gitignore 3 | -------------------------------------------------------------------------------- /tests/slack_jabber/jabber_slack_test.cfg: -------------------------------------------------------------------------------- 1 | [service] 2 | frontend=slack 3 | jid = localhostxmpp 4 | password = secret 5 | server = 0.0.0.0 6 | port = 5223 7 | server_mode = 0 8 | backend_host=127.0.0.1 9 | pidfile=./test.pid 10 | # < this option doesn't work yet 11 | #backend_port=10001 12 | admin_jid=admin 13 | admin_password=test 14 | #cert=server.pfx #patch to PKCS#12 certificate 15 | #cert_password=test #password to that certificate if any 16 | users_per_backend=10 17 | #backend=../..//backends/swiften/spectrum2_swiften_backend 18 | #backend=../../../backends/twitter/spectrum2_twitter_backend 19 | backend=../../backends/libpurple/spectrum2_libpurple_backend 20 | protocol=prpl-jabber 21 | #protocol=prpl-msn 22 | #protocol=any 23 | #protocol=prpl-icq 24 | working_dir=./ 25 | portfile=./$jid.port 26 | irc_server=localhost 27 | 28 | [backend] 29 | #default_avatar=catmelonhead.jpg 30 | #no_vcard_fetch=true 31 | 32 | [logging] 33 | #config=logging.cfg # log4cxx/log4j logging configuration file 34 | #backend_config=/home/hanzz/code/libtransport/spectrum/src/backend-logging.cfg # log4cxx/log4j logging configuration file for backends 35 | 36 | [database] 37 | type=sqlite3 # or "none" without database backend 38 | database=slack.sql 39 | #prefix=twitter 40 | #type = mysql # or "none" without database backend....................................................................................................................... 41 | #database = test 42 | #prefix= 43 | #user=root 44 | #password=yourrootsqlpassword 45 | #encryption_key=hanzzik 46 | [purple] 47 | auth_plain_in_clear=1 48 | connection_security=opportunistic_tls -------------------------------------------------------------------------------- /tests/slack_jabber/muc_echo.py: -------------------------------------------------------------------------------- 1 | import optparse 2 | import sys 3 | import time 4 | import subprocess 5 | import os 6 | 7 | import sleekxmpp 8 | 9 | 10 | class Responder(sleekxmpp.ClientXMPP): 11 | def __init__(self, jid, password, room, room_password, nick): 12 | sleekxmpp.ClientXMPP.__init__(self, jid, password) 13 | self.room = room 14 | self.nick = nick 15 | self.room_password = room_password 16 | self.finished = False 17 | self.add_event_handler("session_start", self.start) 18 | self.add_event_handler("groupchat_message", self.muc_message) 19 | 20 | self.tests = {} 21 | 22 | def muc_message(self, msg): 23 | if msg['mucnick'] != self.nick: 24 | self.send_message(mto=msg['from'].bare, 25 | mbody="echo %s" % msg['body'], 26 | mtype='groupchat') 27 | 28 | def start(self, event): 29 | self.plugin['xep_0045'].joinMUC(self.room, self.nick, password=self.room_password, wait=True) 30 | 31 | class Client(sleekxmpp.ClientXMPP): 32 | def __init__(self, jid, password, room, nick): 33 | sleekxmpp.ClientXMPP.__init__(self, jid, password) 34 | self.room = room 35 | self.nick = nick 36 | self.add_event_handler("session_start", self.start) 37 | self.add_event_handler("groupchat_message", self.muc_message) 38 | self.finished = False 39 | 40 | self.tests = {} 41 | self.tests["echo_received"] = ["libcommuni: Send and receive messages", False] 42 | 43 | def muc_message(self, msg): 44 | if msg['mucnick'] != self.nick: 45 | if msg['body'] == "echo abc" or msg['body'] == " echo abc": 46 | self.tests["echo_received"][1] = True 47 | self.finished = True 48 | 49 | def start(self, event): 50 | self.getRoster() 51 | self.sendPresence() 52 | self.plugin['xep_0045'].joinMUC(self.room, self.nick, wait=True) 53 | self.send_message(mto=self.room, mbody="abc", mtype='groupchat') 54 | -------------------------------------------------------------------------------- /tests/slack_jabber/slack.sql: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SpectrumIM/spectrum2/f547a2158bc90302ddfe09915a557d2e4ac4dfe8/tests/slack_jabber/slack.sql -------------------------------------------------------------------------------- /tests/tests_output/localhost/accounts/client.dat: -------------------------------------------------------------------------------- 1 | return { 2 | ["password"] = "password"; 3 | }; 4 | -------------------------------------------------------------------------------- /tests/tests_output/localhost/accounts/responder.dat: -------------------------------------------------------------------------------- 1 | return { 2 | ["password"] = "password"; 3 | }; 4 | -------------------------------------------------------------------------------- /tests/tests_output/localhost/roster/client.dat: -------------------------------------------------------------------------------- 1 | return { 2 | ["responder@localhost"] = { 3 | ["groups"] = { 4 | ["Buddies"] = true; 5 | }; 6 | ["name"] = "responder"; 7 | ["subscription"] = "both"; 8 | }; 9 | }; 10 | -------------------------------------------------------------------------------- /tests/tests_output/localhost/roster/responder.dat: -------------------------------------------------------------------------------- 1 | return { 2 | ["client@localhost"] = { 3 | ["groups"] = { 4 | ["Buddies"] = true; 5 | }; 6 | ["name"] = "client"; 7 | ["subscription"] = "both"; 8 | }; 9 | }; 10 | -------------------------------------------------------------------------------- /tests/tests_output/localhost/vcard/client.dat: -------------------------------------------------------------------------------- 1 | return { 2 | [1] = { 3 | [1] = { 4 | [1] = "image/png"; 5 | ["attr"] = { 6 | ["xmlns"] = "vcard-temp"; 7 | }; 8 | ["name"] = "TYPE"; 9 | }; 10 | [2] = { 11 | [1] = "iVBORw0KGgoAAAANSUhEUgAAAAEAAAABAQAAAAAAAAAKSURBVHicY2AAAAACAAEAAAAASUVORA=="; 12 | ["attr"] = { 13 | ["xmlns"] = "vcard-temp"; 14 | }; 15 | ["name"] = "BINVAL"; 16 | }; 17 | ["name"] = "PHOTO"; 18 | ["attr"] = { 19 | ["xmlns"] = "vcard-temp"; 20 | }; 21 | }; 22 | ["attr"] = { 23 | ["prodid"] = "-//HandGen//NONSGML vGen v1.0//EN"; 24 | ["version"] = "2.0"; 25 | ["xmlns"] = "vcard-temp"; 26 | }; 27 | ["name"] = "vCard"; 28 | }; 29 | -------------------------------------------------------------------------------- /tests/xmpp/configuration/backend-logging.cfg: -------------------------------------------------------------------------------- 1 | log4j.rootLogger=debug, R 2 | 3 | log4j.appender.R=org.apache.log4j.RollingFileAppender 4 | log4j.appender.R.File=/var/log/spectrum2/${jid}/backends/backend-${id}.log 5 | 6 | log4j.appender.R.MaxFileSize=10000KB 7 | # Keep one backup file 8 | log4j.appender.R.MaxBackupIndex=1 9 | 10 | log4j.appender.R.layout=org.apache.log4j.PatternLayout 11 | log4j.appender.R.layout.ConversionPattern=${pid}: %d %-5p %c: %m%n 12 | -------------------------------------------------------------------------------- /tests/xmpp/configuration/logging.cfg: -------------------------------------------------------------------------------- 1 | log4j.rootLogger=debug, R 2 | 3 | log4j.appender.R=org.apache.log4j.RollingFileAppender 4 | log4j.appender.R.File=/var/log/spectrum2/${jid}/spectrum2.log 5 | 6 | log4j.appender.R.MaxFileSize=10000KB 7 | # Keep one backup file 8 | log4j.appender.R.MaxBackupIndex=1 9 | 10 | log4j.appender.R.layout=org.apache.log4j.PatternLayout 11 | log4j.appender.R.layout.ConversionPattern=%d %-5p %c: %m%n 12 | 13 | # Disable XML category 14 | log4j.category.Component.XML = ON 15 | -------------------------------------------------------------------------------- /tests/xmpp/configuration/manager-logging.cfg: -------------------------------------------------------------------------------- 1 | log4j.rootLogger=debug, R 2 | 3 | log4j.appender.R=org.apache.log4j.RollingFileAppender 4 | log4j.appender.R.File=/var/log/spectrum2/spectrum_manager.log 5 | 6 | log4j.appender.R.MaxFileSize=10000KB 7 | # Keep one backup file 8 | log4j.appender.R.MaxBackupIndex=1 9 | 10 | log4j.appender.R.layout=org.apache.log4j.PatternLayout 11 | log4j.appender.R.layout.ConversionPattern=%d %-5p %c: %m%n 12 | -------------------------------------------------------------------------------- /tests/xmpp/configuration/spectrum_manager.cfg: -------------------------------------------------------------------------------- 1 | [service] 2 | config_directory=/etc/spectrum2/transports/ 3 | 4 | # Username and password of admin for Web interface 5 | admin_username=admin 6 | admin_password=test 7 | 8 | # Port on which the Web interface is listening on 9 | port=8080 10 | 11 | # Base location (directory) on which the Web interface is served. It must ends 12 | # up with slash character (/). If you for example set it to "/spectrum/", then 13 | # the Web interface will be served on http://localhost:$port/spectrum/. 14 | base_location=/ 15 | 16 | [database] 17 | type=sqlite3 18 | database=/var/lib/spectrum2_manager/database.sql 19 | 20 | [servers] 21 | server=localhost 22 | #server=icq.spectrum.im 23 | #server=msn.spectrum.im -------------------------------------------------------------------------------- /tests/xmpp/configuration/transports/irc.cfg: -------------------------------------------------------------------------------- 1 | [service] 2 | jid = irc.localhost 3 | password = password 4 | server = prosody 5 | port = 5347 6 | backend_host = 127.0.0.1 7 | users_per_backend=10 8 | backend=/usr/libexec/spectrum2_libcommuni_backend 9 | web_directory=/var/lib/spectrum2/media 10 | web_url=http://localhost/media 11 | user=www-data 12 | group=www-data 13 | [identity] 14 | name=Spectrum IRC Transport 15 | type=irc 16 | 17 | [logging] 18 | config = /etc/spectrum2/logging.cfg 19 | backend_config = /etc/spectrum2/backend-logging.cfg 20 | 21 | [database] 22 | type = sqlite3 23 | 24 | [registration] 25 | enable_public_registration=1 26 | 27 | -------------------------------------------------------------------------------- /tests/xmpp/configuration/transports/tg.cfg: -------------------------------------------------------------------------------- 1 | [service] 2 | jid = tg.localhost 3 | password = password 4 | server = prosody 5 | port = 5347 6 | backend_host = 127.0.0.1 7 | users_per_backend=10 8 | backend=/usr/libexec/spectrum2_libpurple_backend 9 | protocol=telegram-tdlib 10 | web_directory=/var/lib/spectrum2/media 11 | web_url=http://localhost/media 12 | user=www-data 13 | group=www-data 14 | [identity] 15 | name=Spectrum Telegram Transport 16 | type=telegram 17 | 18 | [logging] 19 | config = /etc/spectrum2/logging.cfg 20 | backend_config = /etc/spectrum2/backend-logging.cfg 21 | 22 | [database] 23 | type = sqlite3 24 | 25 | [registration] 26 | enable_public_registration=1 27 | 28 | -------------------------------------------------------------------------------- /tests/xmpp/configuration/transports/wa.cfg: -------------------------------------------------------------------------------- 1 | [service] 2 | jid = wa.localhost 3 | password = password 4 | server = prosody 5 | port = 5347 6 | backend_host = 127.0.0.1 7 | users_per_backend=10 8 | backend=/usr/libexec/spectrum2_libpurple_backend 9 | protocol=prpl-hehoe-whatsmeow 10 | web_directory=/var/lib/spectrum2/media 11 | web_url=http://localhost:8081 12 | user=www-data 13 | group=www-data 14 | [identity] 15 | name=Spectrum Whatsapp Transport 16 | type=whatsapp 17 | 18 | [logging] 19 | config = /etc/spectrum2/logging.cfg 20 | backend_config = /etc/spectrum2/backend-logging.cfg 21 | 22 | [database] 23 | type = sqlite3 24 | 25 | [registration] 26 | enable_public_registration=1 27 | [purple] 28 | spectrum-compatibility=true 29 | -------------------------------------------------------------------------------- /tests/xmpp/data/.gitignore: -------------------------------------------------------------------------------- 1 | * 2 | !.gitignore 3 | -------------------------------------------------------------------------------- /tests/xmpp/media/.gitignore: -------------------------------------------------------------------------------- 1 | * 2 | !.gitignore 3 | --------------------------------------------------------------------------------