diff options
1195 files changed, 11892 insertions, 3882 deletions
@@ -21,6 +21,7 @@ *.ilk *.res *.moc +*.patch *~ _CL_* *.manifest diff --git a/3rdParty/Boost/SConscript b/3rdParty/Boost/SConscript index 562b1b0..fc53b45 100644 --- a/3rdParty/Boost/SConscript +++ b/3rdParty/Boost/SConscript @@ -90,7 +90,6 @@ elif env.get("BOOST_BUNDLED", False) : "src/libs/program_options/src/config_file.cpp", "src/libs/program_options/src/convert.cpp", "src/libs/program_options/src/options_description.cpp", - "src/libs/program_options/src/parsers.cpp", "src/libs/program_options/src/positional_options.cpp", "src/libs/program_options/src/split.cpp", "src/libs/program_options/src/program_options_utf8_codecvt_facet.cpp", @@ -98,6 +97,11 @@ elif env.get("BOOST_BUNDLED", False) : "src/libs/program_options/src/variables_map.cpp", "src/libs/program_options/src/winmain.cpp"] + if env["PLATFORM"] != "darwin" or env["target"] == "native" : + sources += [ + "src/libs/program_options/src/parsers.cpp", + ] + if env["PLATFORM"] != "win32" : sources += [ "src/libs/thread/src/pthread/once.cpp", diff --git a/3rdParty/Lua/SConscript b/3rdParty/Lua/SConscript index 3baa2d8..68f4e36 100644 --- a/3rdParty/Lua/SConscript +++ b/3rdParty/Lua/SConscript @@ -30,6 +30,10 @@ if env.get("LUA_BUNDLED", False) : if env["SCONS_STAGE"] == "build" : myenv = env.Clone() + if env["PLATFORM"] == "win32" : + myenv.Append(CFLAGS = ["/TP"]) + else : + myenv.Append(CFLAGS = ["-x", "c++"]) # Remove warn flags myenv.Replace(CCFLAGS = [flag for flag in env["CCFLAGS"] if flag not in ["-W", "-Wall"]]) diff --git a/BuildTools/CLang/.gitignore b/BuildTools/CLang/.gitignore new file mode 100644 index 0000000..df682c0 --- /dev/null +++ b/BuildTools/CLang/.gitignore @@ -0,0 +1,4 @@ +CLangDiagnosticsFlags +CLangDiagnosticsFlagsTool.sh +CLangDiagnosticsFlagsTool +clang-diagnostics-overview.* diff --git a/BuildTools/CLang/CLangDiagnosticsFlagsTool.cpp b/BuildTools/CLang/CLangDiagnosticsFlagsTool.cpp new file mode 100644 index 0000000..82cc902 --- /dev/null +++ b/BuildTools/CLang/CLangDiagnosticsFlagsTool.cpp @@ -0,0 +1,228 @@ +/* + * Copyright (c) 2011 Remko Tronçon + * Licensed under the GNU General Public License v3. + * See Documentation/Licenses/GPLv3.txt for more information. + */ + +#include <iostream> +#include <set> +#include <vector> +#include <cassert> +#include <boost/algorithm/string/predicate.hpp> +#include <boost/graph/graph_traits.hpp> +#include <boost/graph/adjacency_list.hpp> +#include <boost/graph/topological_sort.hpp> +#include <boost/graph/topological_sort.hpp> +#include <boost/graph/graphviz.hpp> + +// ----------------------------------------------------------------------------- +// Include diagnostics data from CLang +// ----------------------------------------------------------------------------- + +#define DIAG(name, a, b, c, d, e, f, g) name, + +namespace diag { + enum LexKinds { +#include <clang/Basic/DiagnosticLexKinds.inc> +#include <clang/Basic/DiagnosticParseKinds.inc> +#include <clang/Basic/DiagnosticCommonKinds.inc> +#include <clang/Basic/DiagnosticDriverKinds.inc> +#include <clang/Basic/DiagnosticFrontendKinds.inc> +#include <clang/Basic/DiagnosticSemaKinds.inc> + }; +} + +#define GET_DIAG_ARRAYS +#include <clang/Basic/DiagnosticGroups.inc> +#undef GET_DIAG_ARRAYS + +struct DiagTableEntry { + const char* name; + const short* array; + const short* group; +}; + +static const DiagTableEntry diagnostics[] = { +#define GET_DIAG_TABLE +#include <clang/Basic/DiagnosticGroups.inc> +#undef GET_DIAG_TABLE +}; +static const size_t diagnostics_count = sizeof(diagnostics) / sizeof(diagnostics[0]); + +// ----------------------------------------------------------------------------- + +using namespace boost; + +struct Properties { + Properties() : missing(false), redundant(false) { + } + + std::string name; + bool have; + bool implicitHave; + bool dontWant; + bool implicitDontWant; + bool ignored; + bool available; + bool missing; + bool redundant; + bool alreadyCovered; +}; + +class GraphVizLabelWriter { + public: + GraphVizLabelWriter(const std::vector<Properties>& properties) : properties(properties) { + } + + template <class VertexOrEdge> + void operator()(std::ostream& out, const VertexOrEdge& v) const { + std::string color; + if (properties[v].missing) { + color = "orange"; + } + else if (properties[v].redundant) { + color = "lightblue"; + } + else if (properties[v].have) { + color = "darkgreen"; + } + else if (properties[v].implicitHave) { + color = "green"; + } + else if (properties[v].dontWant) { + color = "red"; + } + else if (properties[v].implicitDontWant) { + color = "pink"; + } + else if (properties[v].ignored) { + color = "white"; + } + else if (properties[v].available) { + color = "yellow"; + } + else { + assert(false); + } + out << "[label=" << escape_dot_string(properties[v].name) << " fillcolor=\"" << color << "\" style=filled]"; + } + + private: + const std::vector<Properties> properties; +}; + +int main(int argc, char* argv[]) { + // Parse command-line arguments + std::set<std::string> have; + std::set<std::string> dontWant; + std::string outputDir; + for (int i = 1; i < argc; ++i) { + std::string arg(argv[i]); + if (starts_with(arg, "-W")) { + have.insert(arg.substr(2, arg.npos)); + } + else if (starts_with(arg, "-w")) { + dontWant.insert(arg.substr(2, arg.npos)); + } + else if (starts_with(arg, "-O")) { + outputDir = arg.substr(2, arg.npos) + "/"; + } + } + + // Build the graph and initialize properties + typedef adjacency_list<vecS, vecS, bidirectionalS> Graph; + typedef graph_traits<Graph>::vertex_descriptor Vertex; + Graph g(diagnostics_count); + std::vector<Properties> properties(num_vertices(g)); + for (size_t i = 0; i < diagnostics_count; ++i) { + std::string name(diagnostics[i].name); + properties[i].name = name; + properties[i].implicitHave = properties[i].have = have.find(name) != have.end(); + properties[i].implicitDontWant = properties[i].dontWant = dontWant.find(name) != dontWant.end(); + properties[i].ignored = diagnostics[i].group == 0 && diagnostics[i].array == 0; + properties[i].alreadyCovered = false; + properties[i].available = true; + for (const short* j = diagnostics[i].group; j && *j != -1; ++j) { + add_edge(i, *j, g); + } + } + + // Sort the diagnostics + std::list<Vertex> sortedDiagnostics; + boost::topological_sort(g, std::front_inserter(sortedDiagnostics)); + + // Propagate dontWant and have properties down + for(std::list<Vertex>::const_iterator i = sortedDiagnostics.begin(); i != sortedDiagnostics.end(); ++i) { + graph_traits<Graph>::adjacency_iterator adjacentIt, adjacentEnd; + for (tie(adjacentIt, adjacentEnd) = adjacent_vertices(*i, g); adjacentIt != adjacentEnd; ++adjacentIt) { + properties[*adjacentIt].implicitDontWant = properties[*i].implicitDontWant || properties[*adjacentIt].implicitDontWant; + properties[*adjacentIt].implicitHave = properties[*i].implicitHave || properties[*adjacentIt].implicitHave; + } + } + + // Propagate 'available' property upwards + for(std::list<Vertex>::const_reverse_iterator i = sortedDiagnostics.rbegin(); i != sortedDiagnostics.rend(); ++i) { + properties[*i].available = properties[*i].available && !properties[*i].implicitDontWant; + graph_traits<Graph>::in_edge_iterator edgesIt, edgesEnd; + graph_traits<Graph>::edge_descriptor edge; + for (tie(edgesIt, edgesEnd) = in_edges(*i, g); edgesIt != edgesEnd; ++edgesIt) { + properties[source(*edgesIt, g)].available = properties[source(*edgesIt, g)].available && properties[*i].available; + } + } + + // Collect missing & redundant flags + std::set<std::string> missing; + std::set<std::string> redundant; + for(std::list<Vertex>::const_iterator i = sortedDiagnostics.begin(); i != sortedDiagnostics.end(); ++i) { + bool markChildrenCovered = true; + if (properties[*i].alreadyCovered) { + if (properties[*i].have) { + properties[*i].redundant = true; + redundant.insert(properties[*i].name); + } + } + else { + if (properties[*i].available) { + if (!properties[*i].implicitHave && !properties[*i].ignored) { + properties[*i].missing = true; + missing.insert(properties[*i].name); + } + } + else { + markChildrenCovered = false; + } + } + if (markChildrenCovered) { + graph_traits<Graph>::adjacency_iterator adjacentIt, adjacentEnd; + for (tie(adjacentIt, adjacentEnd) = adjacent_vertices(*i, g); adjacentIt != adjacentEnd; ++adjacentIt) { + properties[*adjacentIt].alreadyCovered = true; + } + } + } + + // Write information + if (!missing.empty()) { + std::cout << "Missing diagnostic flags: "; + for(std::set<std::string>::const_iterator i = missing.begin(); i != missing.end(); ++i) { + std::cout << "-W" << *i << " "; + } + std::cout<< std::endl; + } + + if (!redundant.empty()) { + std::cout << "Redundant diagnostic flags: "; + for(std::set<std::string>::const_iterator i = redundant.begin(); i != redundant.end(); ++i) { + std::cout << "-W" << *i << " "; + } + std::cout<< std::endl; + } + + // Write graphviz file + if (!outputDir.empty()) { + std::ofstream f((outputDir + "clang-diagnostics-overview.dot").c_str()); + write_graphviz(f, g, GraphVizLabelWriter(properties)); + f.close(); + } + + return 0; +} diff --git a/BuildTools/CLang/SConscript b/BuildTools/CLang/SConscript new file mode 100644 index 0000000..850c35c --- /dev/null +++ b/BuildTools/CLang/SConscript @@ -0,0 +1,15 @@ +Import("env") + +#myenv = Environment() +#myenv.Append(CPPPATH = ["."]) +#myenv.Program("CLangDiagnosticsFlagsTool", ["CLangDiagnosticsFlagsTool.cpp"]) +# +#disabledDiagnostics = ["-wunreachable-code", "-wunused-macros", "-wmissing-noreturn", "-wlong-long", "-wcast-align", "-wglobal-constructors", "-wmissing-prototypes", "-wpadded", "-wshadow"] +#clangDiagnosticsFlagsToolCommand = "BuildTools/CLang/CLangDiagnosticsFlagsTool -O" + env.Dir(".").abspath + " " + " ".join(disabledDiagnostics) + " " +#clangDiagnosticsFlagsToolCommand += " ".join([flag for flag in env["CXXFLAGS"] if flag.startswith("-W")]) +#clangDiagnosticsFlagsToolCommand += "\n" +#clangDiagnosticsFlagsToolCommand += "dot -Tpng " + env.Dir(".").abspath + "/clang-diagnostics-overview.dot > " + env.Dir(".").abspath + "/clang-diagnostics-overview.png\n" +#v = env.WriteVal("#/BuildTools/CLang/CLangDiagnosticsFlagsTool.sh", env.Value(clangDiagnosticsFlagsToolCommand)) +#env.AddPostAction(v, Chmod(v[0], 0755)) +# +# diff --git a/BuildTools/CheckHeaders.py b/BuildTools/CheckHeaders.py new file mode 100755 index 0000000..73f49db --- /dev/null +++ b/BuildTools/CheckHeaders.py @@ -0,0 +1,21 @@ +#!/usr/bin/env python + +import os, sys + +foundBadHeaders = False + +for (path, dirs, files) in os.walk(".") : + if "3rdParty" in path or ".sconf" in path or ".framework" in path : + continue + if not "Swiften" in path : + continue + + for filename in [os.path.join(path, file) for file in files if file.endswith(".h")] : + file = open(filename, "r") + for line in file.readlines() : + for include in ["iostream", "algorithm", "cassert", "boost/bind.hpp", "boost/filesystem.hpp", "Base/foreach.h", "Base/Log.h", "boost/date_time/date_time.hpp", "boost/filesystem/filesystem.hpp"] : + if "#include" in line and include in line and not "Base/Log" in filename : + print "Found " + include + " include in " + filename + foundBadHeaders = True + +sys.exit(foundBadHeaders) diff --git a/BuildTools/Copyrighter.py b/BuildTools/Copyrighter.py index a768f0d..8916316 100755 --- a/BuildTools/Copyrighter.py +++ b/BuildTools/Copyrighter.py @@ -136,7 +136,7 @@ elif sys.argv[1] == "check-all-copyrights" : for (path, dirs, files) in os.walk(".") : if "3rdParty" in path or ".sconf" in path or "Swift.app" in path : continue - for filename in [os.path.join(path, file) for file in files if (file.endswith(".cpp") or file.endswith(".h")) and not "ui_" in file and not "moc_" in file and not "qrc_" in file and not "BuildVersion.h" in file and not "Swiften.h" in file and not "Version.h" in file and not "swiften-config.h" in file] : + for filename in [os.path.join(path, file) for file in files if (file.endswith(".cpp") or file.endswith(".h")) and not "ui_" in file and not "moc_" in file and not "qrc_" in file and not "BuildVersion.h" in file and not "Swiften.h" in file and not "Version.h" in file and not "swiften-config.h" in file and not "linit.cpp" in file ] : ok &= check_copyright(filename) if not ok : sys.exit(-1) diff --git a/BuildTools/SCons/SConstruct b/BuildTools/SCons/SConstruct index bc7781b..c8459e1 100644 --- a/BuildTools/SCons/SConstruct +++ b/BuildTools/SCons/SConstruct @@ -42,6 +42,9 @@ vars.Add("expat_libname", "Expat library name", "libexpat" if os.name == "nt" el vars.Add(PathVariable("libidn_includedir", "LibIDN headers location", None, PathVariable.PathAccept)) vars.Add(PathVariable("libidn_libdir", "LibIDN library location", None, PathVariable.PathAccept)) vars.Add("libidn_libname", "LibIDN library name", "libidn" if os.name == "nt" else "idn") +vars.Add(PathVariable("sqlite_includedir", "SQLite headers location", None, PathVariable.PathAccept)) +vars.Add(PathVariable("sqlite_libdir", "SQLite library location", None, PathVariable.PathAccept)) +vars.Add("sqlite_libname", "SQLite library name", "libsqlite3" if os.name == "nt" else "sqlite3") vars.Add(PathVariable("avahi_includedir", "Avahi headers location", None, PathVariable.PathAccept)) vars.Add(PathVariable("avahi_libdir", "Avahi library location", None, PathVariable.PathAccept)) vars.Add(PathVariable("qt", "Qt location", "", PathVariable.PathAccept)) @@ -90,6 +93,8 @@ if env["max_jobs"] : SetOption("num_jobs", multiprocessing.cpu_count()) except NotImplementedError : pass + except ImportError : + pass # Default compiler flags if env.get("distcc", False) : @@ -178,7 +183,14 @@ else : env.Append(CXXFLAGS = ["-Werror"]) gccVersion = env["CCVERSION"].split(".") if gccVersion >= ["4", "5", "0"] : - env.Append(CCFLAGS = ["-Wlogical-op"]) + env.Append(CXXFLAGS = ["-Wlogical-op"]) + if "clang" in env["CC"] : + env.Append(CXXFLAGS = ["-W#warnings", "-W-Wc++0x-compat", "-Wc++0x-compat", "-Waddress-of-temporary", "-Wambiguous-member-template", "-Warray-bounds", "-Watomic-properties", "-Wbind-to-temporary-copy", "-Wbuiltin-macro-redefined", "-Wc++-compat", "-Wc++0x-extensions", "-Wcomments", "-Wconditional-uninitialized", "-Wconstant-logical-operand", "-Wdeclaration-after-statement", "-Wdeprecated", "-Wdeprecated-implementations", "-Wdeprecated-writable-strings", "-Wduplicate-method-arg", "-Wempty-body", "-Wendif-labels", "-Wenum-compare", "-Wformat=2", "-Wfour-char-constants", "-Wgnu", "-Wincomplete-implementation", "-Winvalid-noreturn", "-Winvalid-offsetof", "-Winvalid-token-paste", "-Wlocal-type-template-args", "-Wmethod-signatures", "-Wmicrosoft", "-Wmissing-declarations", "-Wnon-pod-varargs", "-Wnonfragile-abi2", "-Wnull-dereference", "-Wout-of-line-declaration", "-Woverlength-strings", "-Wpacked", "-Wpointer-arith", "-Wpointer-sign", "-Wprotocol", "-Wreadonly-setter-attrs", "-Wselector", "-Wshift-overflow", "-Wshift-sign-overflow", "-Wstrict-selector-match", "-Wsuper-class-method-mismatch", "-Wtautological-compare", "-Wtypedef-redefinition", "-Wundeclared-selector", "-Wunknown-attributes", "-Wunknown-warning-option", "-Wunnamed-type-template-args", "-Wunused-exception-parameter", "-Wunused-member-function", "-Wused-but-marked-unused", "-Wvariadic-macros"]) +# To enable: +# "-Wheader-hygiene" +# "-Wnon-gcc", +# "-Wweak-vtables", +# "-Wlarge-by-value-copy", if env.get("coverage", 0) : assert(env["PLATFORM"] != "win32") @@ -186,7 +198,7 @@ if env.get("coverage", 0) : env.Append(LINKFLAGS = ["-fprofile-arcs", "-ftest-coverage"]) if env["PLATFORM"] == "win32" : - env.Append(LIBS = ["user32", "crypt32", "dnsapi", "ws2_32", "wsock32"]) + env.Append(LIBS = ["user32", "crypt32", "dnsapi", "ws2_32", "wsock32", "Advapi32"]) env.Append(CCFLAGS = ["/EHsc", "/nologo"]) # FIXME: We should find a decent solution for MSVS 10 if int(env["MSVS_VERSION"].split(".")[0]) < 10 : @@ -194,7 +206,7 @@ if env["PLATFORM"] == "win32" : env["SHLINKCOM"] = [env["SHLINKCOM"], 'mt.exe -nologo -manifest ${TARGET}.manifest -outputresource:$TARGET;2'] if env["PLATFORM"] == "darwin" and not env["target"] in ["iphone-device", "iphone-simulator", "xcode"] : - env.Append(FRAMEWORKS = ["IOKit", "AppKit"]) + env.Append(FRAMEWORKS = ["IOKit", "AppKit", "SystemConfiguration"]) # Testing env["TEST_TYPE"] = env["test"] @@ -205,6 +217,7 @@ env["TEST"] = (env["TEST_TYPE"] != "none") or env.GetOption("clean") if env.get("valgrind", 0) : env["TEST_RUNNER"] = "valgrind --suppressions=QA/valgrind.supp -q --leak-check=full --track-origins=yes " env["TEST_IGNORE_RESULT"] = "ignore_test_result" in ARGUMENTS +env["TEST_CREATE_LIBRARIES"] = "create_test_libraries" in ARGUMENTS # Packaging env["DIST"] = "dist" in ARGUMENTS or env.GetOption("clean") @@ -231,12 +244,12 @@ if target in ["iphone-device", "iphone-simulator", "xcode"] : # Hard code values env["XCODE_PLATFORM_DEVELOPER_BIN_DIR"] = "/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin" if target == "iphone-device": - env["XCODE_ARCH_FLAGS"] = ["-arch", "armv6"] + env["XCODE_ARCH_FLAGS"] = ["-arch", "armv6", "-arch", "armv7"] sdkPart = "iPhoneOS" else : env["XCODE_ARCH_FLAGS"] = ["-arch", "i386"] sdkPart = "iPhoneSimulator" - sdkVer = "4.0" + sdkVer = "4.3" env["XCODE_SDKROOT"] = "/Developer/Platforms/" + sdkPart + ".platform/Developer/SDKs/" + sdkPart + sdkVer + ".sdk" # Set the build flags @@ -244,7 +257,7 @@ if target in ["iphone-device", "iphone-simulator", "xcode"] : env["CXX"] = "$XCODE_PLATFORM_DEVELOPER_BIN_DIR/g++" env["OBJCCFLAGS"] = ["-fobjc-abi-version=2", "-fobjc-legacy-dispatch"] env["LD"] = env["CC"] - env.Append(CCFLAGS = env["XCODE_ARCH_FLAGS"]) + env.Append(CCFLAGS = env["XCODE_ARCH_FLAGS"] + ["-fvisibility=hidden"]) env.Append(LINKFLAGS = env["XCODE_ARCH_FLAGS"]) env.Append(CPPFLAGS = ["-isysroot", "$XCODE_SDKROOT"]) env.Append(FRAMEWORKS = ["CoreFoundation", "Foundation", "UIKit", "CoreGraphics"]) @@ -320,6 +333,12 @@ def checkObjCHeader(context, header) : if ARGUMENTS.get("force-configure", 0) : SCons.SConf.SetCacheMode("force") +def CheckPKG(context, name): + context.Message( 'Checking for package %s... ' % name ) + ret = context.TryAction('pkg-config --exists \'%s\'' % name)[0] + context.Result( ret ) + return ret + conf = Configure(conf_env) if not conf.CheckCXX() or not conf.CheckCC() : @@ -414,6 +433,31 @@ if env["PLATFORM"] != "win32" and env["PLATFORM"] != "darwin" : env["XSS_FLAGS"] = xss_flags conf.Finish() +# GConf +env["HAVE_GCONF"] = 0 +if env["PLATFORM"] != "win32" and env["PLATFORM"] != "darwin" : + gconf_env = conf_env.Clone() + conf = Configure(gconf_env, custom_tests = {"CheckPKG": CheckPKG}) + if conf.CheckPKG("gconf-2.0") : + gconf_bare_env = Environment() + gconf_bare_env.ParseConfig('pkg-config --cflags gconf-2.0 --libs gconf-2.0') + gconf_flags = { + "LIBS": gconf_bare_env["LIBS"], + "CCFLAGS": gconf_bare_env["CCFLAGS"], + "CPPPATH": gconf_bare_env["CPPPATH"], + "CPPDEFINES": gconf_bare_env["CPPDEFINES"], + } + gconf_env.MergeFlags(gconf_flags) + if conf.CheckCHeader("gconf/gconf-client.h") and conf.CheckLib("gconf-2") : + env["HAVE_GCONF"] = 1 + env["GCONF_FLAGS"] = { + "LIBS": gconf_env["LIBS"], + "CCFLAGS": gconf_env["CCFLAGS"], + "CPPPATH": gconf_env["CPPPATH"], + "CPPDEFINES": gconf_env["CPPDEFINES"], + } + conf.Finish() + # Sparkle env["HAVE_SPARKLE"] = 0 if env["PLATFORM"] == "darwin" : @@ -507,6 +551,23 @@ else : env["LIBIDN_BUNDLED"] = 1 conf.Finish() +# SQLite +sqlite_conf_env = conf_env.Clone() +sqlite_flags = {} +if env.get("sqlite_libdir", None) : + sqlite_flags["LIBPATH"] = [env["sqlite_libdir"]] +if env.get("sqlite_includedir", None) : + sqlite_flags["CPPPATH"] = [env["sqlite_includedir"]] +sqlite_conf_env.MergeFlags(sqlite_flags) +conf = Configure(sqlite_conf_env) +if conf.CheckCHeader("sqlite3.h") and conf.CheckLib(env["sqlite_libname"]) : + env["HAVE_SQLITE"] = 1 + env["SQLITE_FLAGS"] = { "LIBS": [env["sqlite_libname"]] } + env["SQLITE_FLAGS"].update(sqlite_flags) +else : + env["SQLITE_BUNDLED"] = 1 +conf.Finish() + # Lua env["LUA_BUNDLED"] = 1 @@ -621,6 +682,9 @@ if env.Dir("#/.git").exists() : # Project files ################################################################################ +# Build tools +env.SConscript(dirs = ["#/BuildTools/CLang"]) + # Modules modules = [] for dir in os.listdir(Dir("#/3rdParty").abspath) : diff --git a/BuildTools/SCons/Tools/AppBundle.py b/BuildTools/SCons/Tools/AppBundle.py index c271575..6a343f6 100644 --- a/BuildTools/SCons/Tools/AppBundle.py +++ b/BuildTools/SCons/Tools/AppBundle.py @@ -1,7 +1,7 @@ import SCons.Util, os.path def generate(env) : - def createAppBundle(env, bundle, version = "1.0", resources = [], frameworks = [], info = {}) : + def createAppBundle(env, bundle, version = "1.0", resources = [], frameworks = [], info = {}, handlesXMPPURIs = False) : bundleDir = bundle + ".app" bundleContentsDir = bundleDir + "/Contents" resourcesDir = bundleContentsDir + "/Resources" @@ -32,6 +32,18 @@ def generate(env) : for key, value in infoDict.items() : plist += "<key>" + key + "</key>\n" plist += "<string>" + value.encode("utf-8") + "</string>\n" + if handlesXMPPURIs : + plist += """<key>CFBundleURLTypes</key> +<array> + <dict> + <key>CFBundleURLName</key> + <string>XMPP URL</string> + <key>CFBundleURLSchemes</key> + <array> + <string>xmpp</string> + </array> + </dict> +</array>\n""" plist += """</dict> </plist> """ @@ -825,6 +825,7 @@ Swift contains some code contributed under the BSD License, under the following --- START OF BSD LICENSE Copyright (c) 2011, Arnt Gulbrandsen Copyright (c) 2011, Thilo Cestonaro +Copyright (c) 2011, Vlad Voicu All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: diff --git a/Documentation/BuildingOnUnix.txt b/Documentation/BuildingOnUnix.txt index 8de73c8..fa5759e 100644 --- a/Documentation/BuildingOnUnix.txt +++ b/Documentation/BuildingOnUnix.txt @@ -20,6 +20,9 @@ Running tests ------------- - Run ./scons test=unit - for running the unit tests, or - ./scons test=all - for running all tests. + for running the unit tests. + +Installing +---------- +- To install swift in /usr/local, run + ./scons SWIFT_INSTALLDIR=/usr/local /usr/local diff --git a/Documentation/SwiftenDevelopersGuide/Examples/EchoBot/EchoBot0x.cpp b/Documentation/SwiftenDevelopersGuide/Examples/EchoBot/EchoBot0x.cpp index b4ccc21..11773ae 100644 --- a/Documentation/SwiftenDevelopersGuide/Examples/EchoBot/EchoBot0x.cpp +++ b/Documentation/SwiftenDevelopersGuide/Examples/EchoBot/EchoBot0x.cpp @@ -13,25 +13,19 @@ int main(int, char**) { SimpleEventLoop eventLoop; BoostNetworkFactories networkFactories(&eventLoop); - // Initialize the client with the JID and password Client client("echobot@wonderland.lit", "mypass", &networkFactories); - - // When the client is convnected, send out initial presence + client.setAlwaysTrustCertificates(); client.onConnected.connect([&] { - client.sendPresence(Presence::create("Send me a message")); + std::cout << "Connected" << std::endl; }); - - // When the client receives an incoming message, echo it back client.onMessageReceived.connect([&] (Message::ref message) { message->setTo(message->getFrom()); message->setFrom(JID()); client.sendMessage(message); }); - - // Start the client client.connect(); - // Run the event loop to start processing incoming network events eventLoop.run(); + return 0; } diff --git a/Documentation/SwiftenDevelopersGuide/Examples/EchoBot/EchoBot1.cpp b/Documentation/SwiftenDevelopersGuide/Examples/EchoBot/EchoBot1.cpp index 4736494..8a64b56 100644 --- a/Documentation/SwiftenDevelopersGuide/Examples/EchoBot/EchoBot1.cpp +++ b/Documentation/SwiftenDevelopersGuide/Examples/EchoBot/EchoBot1.cpp @@ -13,6 +13,7 @@ int main(int, char**) { BoostNetworkFactories networkFactories(&eventLoop); Client client("echobot@wonderland.lit", "mypass", &networkFactories); + client.setAlwaysTrustCertificates(); client.connect(); eventLoop.run(); diff --git a/Documentation/SwiftenDevelopersGuide/Examples/EchoBot/EchoBot2.cpp b/Documentation/SwiftenDevelopersGuide/Examples/EchoBot/EchoBot2.cpp index f431245..deeb852 100644 --- a/Documentation/SwiftenDevelopersGuide/Examples/EchoBot/EchoBot2.cpp +++ b/Documentation/SwiftenDevelopersGuide/Examples/EchoBot/EchoBot2.cpp @@ -22,6 +22,7 @@ int main(int, char**) { BoostNetworkFactories networkFactories(&eventLoop); client = new Client("echobot@wonderland.lit", "mypass", &networkFactories); + client->setAlwaysTrustCertificates(); client->onConnected.connect(&handleConnected); client->onMessageReceived.connect(bind(&handleMessageReceived, _1)); client->connect(); diff --git a/Documentation/SwiftenDevelopersGuide/Examples/EchoBot/EchoBot3.cpp b/Documentation/SwiftenDevelopersGuide/Examples/EchoBot/EchoBot3.cpp index cd95b91..e3e3560 100644 --- a/Documentation/SwiftenDevelopersGuide/Examples/EchoBot/EchoBot3.cpp +++ b/Documentation/SwiftenDevelopersGuide/Examples/EchoBot/EchoBot3.cpp @@ -16,6 +16,7 @@ class EchoBot { public: EchoBot(NetworkFactories* networkFactories) { client = new Client("echobot@wonderland.lit", "mypass", networkFactories); + client->setAlwaysTrustCertificates(); client->onConnected.connect(bind(&EchoBot::handleConnected, this)); client->onMessageReceived.connect( bind(&EchoBot::handleMessageReceived, this, _1)); diff --git a/Documentation/SwiftenDevelopersGuide/Examples/EchoBot/EchoBot4.cpp b/Documentation/SwiftenDevelopersGuide/Examples/EchoBot/EchoBot4.cpp index c2f555c..c8d8c84 100644 --- a/Documentation/SwiftenDevelopersGuide/Examples/EchoBot/EchoBot4.cpp +++ b/Documentation/SwiftenDevelopersGuide/Examples/EchoBot/EchoBot4.cpp @@ -18,6 +18,7 @@ class EchoBot { EchoBot(NetworkFactories* networkFactories) { //... client = new Client("echobot@wonderland.lit", "mypass", networkFactories); + client->setAlwaysTrustCertificates(); client->onConnected.connect(bind(&EchoBot::handleConnected, this)); client->onMessageReceived.connect( bind(&EchoBot::handleMessageReceived, this, _1)); diff --git a/Documentation/SwiftenDevelopersGuide/Examples/EchoBot/EchoBot5.cpp b/Documentation/SwiftenDevelopersGuide/Examples/EchoBot/EchoBot5.cpp index 0b00330..810424c 100644 --- a/Documentation/SwiftenDevelopersGuide/Examples/EchoBot/EchoBot5.cpp +++ b/Documentation/SwiftenDevelopersGuide/Examples/EchoBot/EchoBot5.cpp @@ -18,6 +18,7 @@ class EchoBot { EchoBot(NetworkFactories* networkFactories) { //... client = new Client("echobot@wonderland.lit", "mypass", networkFactories); + client->setAlwaysTrustCertificates(); client->onConnected.connect(bind(&EchoBot::handleConnected, this)); client->onMessageReceived.connect( bind(&EchoBot::handleMessageReceived, this, _1)); diff --git a/Documentation/SwiftenDevelopersGuide/Examples/EchoBot/EchoBot6.cpp b/Documentation/SwiftenDevelopersGuide/Examples/EchoBot/EchoBot6.cpp index d3587e9..92a2ab6 100644 --- a/Documentation/SwiftenDevelopersGuide/Examples/EchoBot/EchoBot6.cpp +++ b/Documentation/SwiftenDevelopersGuide/Examples/EchoBot/EchoBot6.cpp @@ -23,6 +23,7 @@ class EchoBot { EchoBot(NetworkFactories* networkFactories) { //... client = new Client("echobot@wonderland.lit", "mypass", networkFactories); + client->setAlwaysTrustCertificates(); client->onConnected.connect(bind(&EchoBot::handleConnected, this)); client->onMessageReceived.connect( bind(&EchoBot::handleMessageReceived, this, _1)); diff --git a/Documentation/SwiftenDevelopersGuide/Examples/EchoBot/EchoPayload.h b/Documentation/SwiftenDevelopersGuide/Examples/EchoBot/EchoPayload.h index 7533a1e..62ea495 100644 --- a/Documentation/SwiftenDevelopersGuide/Examples/EchoBot/EchoPayload.h +++ b/Documentation/SwiftenDevelopersGuide/Examples/EchoBot/EchoPayload.h @@ -8,9 +8,8 @@ #include <Swiften/Swiften.h> -using namespace Swift; //... -class EchoPayload : public Payload { +class EchoPayload : public Swift::Payload { public: EchoPayload() {} diff --git a/Documentation/SwiftenDevelopersGuide/Examples/EchoBot/EchoPayloadParserFactory.h b/Documentation/SwiftenDevelopersGuide/Examples/EchoBot/EchoPayloadParserFactory.h index 9cbb795..33a8c41 100644 --- a/Documentation/SwiftenDevelopersGuide/Examples/EchoBot/EchoPayloadParserFactory.h +++ b/Documentation/SwiftenDevelopersGuide/Examples/EchoBot/EchoPayloadParserFactory.h @@ -9,9 +9,7 @@ #include <Swiften/Swiften.h> #include "EchoPayload.h" -using namespace Swift; - -class EchoPayloadParser : public GenericPayloadParser<EchoPayload> { +class EchoPayloadParser : public Swift::GenericPayloadParser<EchoPayload> { public: EchoPayloadParser() : currentDepth(0) {} @@ -36,7 +34,7 @@ class EchoPayloadParser : public GenericPayloadParser<EchoPayload> { std::string currentText; }; -class EchoPayloadParserFactory : public GenericPayloadParserFactory<EchoPayloadParser> { +class EchoPayloadParserFactory : public Swift::GenericPayloadParserFactory<EchoPayloadParser> { public: EchoPayloadParserFactory() : GenericPayloadParserFactory<EchoPayloadParser>("echo", "http://swift.im/echo") {} diff --git a/Documentation/SwiftenDevelopersGuide/Examples/EchoBot/EchoPayloadSerializer.h b/Documentation/SwiftenDevelopersGuide/Examples/EchoBot/EchoPayloadSerializer.h index 85e8e67..068113c 100644 --- a/Documentation/SwiftenDevelopersGuide/Examples/EchoBot/EchoPayloadSerializer.h +++ b/Documentation/SwiftenDevelopersGuide/Examples/EchoBot/EchoPayloadSerializer.h @@ -9,9 +9,7 @@ #include <Swiften/Swiften.h> #include "EchoPayload.h" -using namespace Swift; - -class EchoPayloadSerializer : public GenericPayloadSerializer<EchoPayload> { +class EchoPayloadSerializer : public Swift::GenericPayloadSerializer<EchoPayload> { public: std::string serializePayload(boost::shared_ptr<EchoPayload> payload) const { XMLElement element("echo", "http://swift.im/protocol/echo"); diff --git a/Documentation/SwiftenDevelopersGuide/Examples/EchoBot/SConscript b/Documentation/SwiftenDevelopersGuide/Examples/EchoBot/SConscript index 1960609..c6349bd 100644 --- a/Documentation/SwiftenDevelopersGuide/Examples/EchoBot/SConscript +++ b/Documentation/SwiftenDevelopersGuide/Examples/EchoBot/SConscript @@ -15,11 +15,11 @@ if env["PLATFORM"] == "win32" : if int(env["MSVS_VERSION"].split(".")[0]) >= 10 : cpp0x = True else : - pass -# Disabling C++0x compilation, because older boosts are not compliant yet -# if env["CCVERSION"].split(".") >= ["4", "5", "0"] : -# cpp0x = True -# cpp0x_env.Replace(CXXFLAGS = [flag for flag in env["CXXFLAGS"] if flag != "-Werror"]) -# cpp0x_env.Append(CXXFLAGS = ["-std=c++0x"]) + if env["CCVERSION"].split(".") >= ["4", "5", "0"] : + # Temporarily disabling c++0x mode because of problems with boost::thread + # on some platforms + #cpp0x = True + cpp0x_env.Replace(CXXFLAGS = [flag for flag in env["CXXFLAGS"] if flag != "-Werror"]) + cpp0x_env.Append(CXXFLAGS = ["-std=c++0x"]) if cpp0x : cpp0x_env.Program("EchoBot0x", "EchoBot0x.cpp") diff --git a/Documentation/SwiftenDevelopersGuide/SConscript b/Documentation/SwiftenDevelopersGuide/SConscript index e000ac2..c50641f 100644 --- a/Documentation/SwiftenDevelopersGuide/SConscript +++ b/Documentation/SwiftenDevelopersGuide/SConscript @@ -87,6 +87,7 @@ if "doc" in ARGUMENTS : sources = [] for i in range(1, 7) : sources.append("Examples/EchoBot/EchoBot" + str(i) + ".cpp") +sources.append("Examples/EchoBot/EchoBot0x.cpp") sources += ["Examples/EchoBot/" + i for i in ["EchoPayloadParserFactory.h", "EchoPayloadSerializer.h", "EchoPayload.h", "EchoComponent.cpp"]] for source in sources : env.Command(source + ".xml", source, Action(generateDocBookCode, cmdstr = "$GENCOMSTR")) diff --git a/Documentation/SwiftenDevelopersGuide/Swiften Developers Guide.xml b/Documentation/SwiftenDevelopersGuide/Swiften Developers Guide.xml index e0daff3..fae79e4 100644 --- a/Documentation/SwiftenDevelopersGuide/Swiften Developers Guide.xml +++ b/Documentation/SwiftenDevelopersGuide/Swiften Developers Guide.xml @@ -94,7 +94,12 @@ <literal>connect()</literal> to instruct the client to connect to the XMPP server with the given credentials. Note that this call returns immediately; it is only when starting the event loop that network - the actual connection process will start. + the actual connection process will start. The call to + <literal>setAlwaysTrustCertificates()</literal> before connecting + avoids checks for certificate validity; this is convenient for + the examples in this guide (because not all servers have trusted + certificates), but for production software, you should + not call this. </para> </sect1> @@ -177,8 +182,20 @@ </para> <para> + If you use a C++ compiler that supports C++0x lambda expressions (such as + GCC 4.5 or Microsoft Visual Studio 2010), you can write this example in a more + concise way, as illustrated in <xref linkend="Example-EchoBot0x"/>. However, + for the remainder of this guide, we will not use this functionality. + </para> + <example id="Example-EchoBot0x"> + <title>EchoBot using C++0x lambda expressions. This is currently only possible with a limited set of C++compilers.</title> + <include xmlns="http://www.w3.org/2001/XInclude" href="Examples/EchoBot/EchoBot0x.cpp.xml" xpointer="xpointer(//programlisting|//calloutlist)"/> + </example> + + <para> Before moving on to the next step, we are going to rearrange our - code a bit, to make it a bit cleaner. Instead of using global + code from <xref linkend="Example-EchoBot2"/> a bit, to make it a bit cleaner. + Instead of using global variables, we are going to create an <literal>EchoBot</literal> class with the current code in it. The resulting code can be found in <xref linkend="Example-EchoBot3"/>. diff --git a/Limber/main.cpp b/Limber/main.cpp index 6db623e..988177a 100644 --- a/Limber/main.cpp +++ b/Limber/main.cpp @@ -8,22 +8,22 @@ #include <boost/bind.hpp> #include <boost/shared_ptr.hpp> -#include "Swiften/Elements/IQ.h" -#include "Swiften/Elements/RosterPayload.h" -#include "Swiften/Elements/VCard.h" -#include "Swiften/Server/SimpleUserRegistry.h" -#include "Swiften/Base/IDGenerator.h" -#include "Swiften/EventLoop/EventLoop.h" -#include "Swiften/EventLoop/SimpleEventLoop.h" -#include "Swiften/EventLoop/EventOwner.h" -#include "Swiften/Elements/Stanza.h" -#include "Swiften/Network/ConnectionServer.h" -#include "Swiften/Network/BoostConnection.h" -#include "Swiften/Network/BoostIOServiceThread.h" -#include "Swiften/Network/BoostConnectionServer.h" -#include "Swiften/Server/ServerFromClientSession.h" -#include "Swiften/Parser/PayloadParsers/FullPayloadParserFactoryCollection.h" -#include "Swiften/Serializer/PayloadSerializers/FullPayloadSerializerCollection.h" +#include <Swiften/Elements/IQ.h> +#include <Swiften/Elements/RosterPayload.h> +#include <Swiften/Elements/VCard.h> +#include <Swiften/Server/SimpleUserRegistry.h> +#include <Swiften/Base/IDGenerator.h> +#include <Swiften/EventLoop/EventLoop.h> +#include <Swiften/EventLoop/SimpleEventLoop.h> +#include <Swiften/EventLoop/EventOwner.h> +#include <Swiften/Elements/Stanza.h> +#include <Swiften/Network/ConnectionServer.h> +#include <Swiften/Network/BoostConnection.h> +#include <Swiften/Network/BoostIOServiceThread.h> +#include <Swiften/Network/BoostConnectionServer.h> +#include <Swiften/Server/ServerFromClientSession.h> +#include <Swiften/Parser/PayloadParsers/FullPayloadParserFactoryCollection.h> +#include <Swiften/Serializer/PayloadSerializers/FullPayloadSerializerCollection.h> using namespace Swift; diff --git a/QA/UnitTest/SConscript b/QA/UnitTest/SConscript index 25e9b05..e5923ce 100644 --- a/QA/UnitTest/SConscript +++ b/QA/UnitTest/SConscript @@ -26,8 +26,12 @@ if env["TEST"] : myenv.Append(CPPDEFINES = ["HAVE_LIBXML"]) if env.get("HAVE_EXPAT") : myenv.Append(CPPDEFINES = ["HAVE_EXPAT"]) - checker = myenv.Program("checker", env["UNITTEST_SOURCES"] + env["UNITTEST_OBJECTS"]) - for i in ["HOME", "USERPROFILE", "APPDATA"]: - if os.environ.get(i, "") : - myenv["ENV"][i] = os.environ[i] - myenv.Test(checker, is_checker = True) + if env["TEST_CREATE_LIBRARIES"] : + lib = myenv.StaticLibrary("Swift_UnitTests", env["UNITTEST_SOURCES"] + env["UNITTEST_OBJECTS"]) + myenv.Program("checker", lib) + else : + checker = myenv.Program("checker", env["UNITTEST_SOURCES"] + env["UNITTEST_OBJECTS"]) + for i in ["HOME", "USERPROFILE", "APPDATA"]: + if os.environ.get(i, "") : + myenv["ENV"][i] = os.environ[i] + myenv.Test(checker, is_checker = True) diff --git a/Slimber/CLI/main.cpp b/Slimber/CLI/main.cpp index 5252373..3dd59a6 100644 --- a/Slimber/CLI/main.cpp +++ b/Slimber/CLI/main.cpp @@ -4,7 +4,7 @@ * See Documentation/Licenses/GPLv3.txt for more information. */ -#include "Swiften/EventLoop/SimpleEventLoop.h" +#include <Swiften/EventLoop/SimpleEventLoop.h> #include "Slimber/CLI/DummyMenulet.h" #include "Slimber/MainController.h" diff --git a/Slimber/Cocoa/CocoaMenulet.h b/Slimber/Cocoa/CocoaMenulet.h index 7f2758b..5c7c33e 100644 --- a/Slimber/Cocoa/CocoaMenulet.h +++ b/Slimber/Cocoa/CocoaMenulet.h @@ -9,7 +9,7 @@ #include <Cocoa/Cocoa.h> #include "Slimber/Menulet.h" -#include "Slimber/Cocoa/CocoaAction.h" +#include <SwifTools/Cocoa/CocoaAction.h> class CocoaMenulet : public Menulet { public: diff --git a/Slimber/Cocoa/SConscript b/Slimber/Cocoa/SConscript index e2d8221..d664846 100644 --- a/Slimber/Cocoa/SConscript +++ b/Slimber/Cocoa/SConscript @@ -16,7 +16,6 @@ myenv.Program("Slimber", [ "main.mm", "CocoaController.mm", "CocoaMenulet.mm", - "CocoaAction.mm" ]) myenv.Nib("MainMenu") diff --git a/Slimber/Cocoa/main.h b/Slimber/Cocoa/main.h index 681139d..0f686ad 100644 --- a/Slimber/Cocoa/main.h +++ b/Slimber/Cocoa/main.h @@ -6,6 +6,6 @@ #pragma once -#include "Swiften/EventLoop/Cocoa/CocoaEventLoop.h" +#include <Swiften/EventLoop/Cocoa/CocoaEventLoop.h> extern Swift::CocoaEventLoop* eventLoop; diff --git a/Slimber/Cocoa/main.mm b/Slimber/Cocoa/main.mm index fc051e0..167c1ab 100644 --- a/Slimber/Cocoa/main.mm +++ b/Slimber/Cocoa/main.mm @@ -1,7 +1,7 @@ #include <Cocoa/Cocoa.h> #include "Slimber/Cocoa/main.h" -#include "Swiften/EventLoop/Cocoa/CocoaEventLoop.h" +#include <Swiften/EventLoop/Cocoa/CocoaEventLoop.h> Swift::CocoaEventLoop* eventLoop; diff --git a/Slimber/FileVCardCollection.cpp b/Slimber/FileVCardCollection.cpp index 960cd84..c6984c7 100644 --- a/Slimber/FileVCardCollection.cpp +++ b/Slimber/FileVCardCollection.cpp @@ -8,11 +8,11 @@ #include <boost/filesystem/fstream.hpp> -#include "Swiften/Base/ByteArray.h" -#include "Swiften/Elements/VCard.h" -#include "Swiften/Serializer/PayloadSerializers/VCardSerializer.h" -#include "Swiften/Parser/PayloadParsers/UnitTest/PayloadParserTester.h" -#include "Swiften/Parser/PayloadParsers/VCardParser.h" +#include <Swiften/Base/ByteArray.h> +#include <Swiften/Elements/VCard.h> +#include <Swiften/Serializer/PayloadSerializers/VCardSerializer.h> +#include <Swiften/Parser/PayloadParsers/UnitTest/PayloadParserTester.h> +#include <Swiften/Parser/PayloadParsers/VCardParser.h> namespace Swift { diff --git a/Slimber/LinkLocalPresenceManager.cpp b/Slimber/LinkLocalPresenceManager.cpp index edb7e91..708327e 100644 --- a/Slimber/LinkLocalPresenceManager.cpp +++ b/Slimber/LinkLocalPresenceManager.cpp @@ -8,10 +8,10 @@ #include <boost/bind.hpp> -#include "Swiften/Base/foreach.h" -#include "Swiften/LinkLocal/LinkLocalServiceBrowser.h" -#include "Swiften/Elements/RosterPayload.h" -#include "Swiften/Elements/Presence.h" +#include <Swiften/Base/foreach.h> +#include <Swiften/LinkLocal/LinkLocalServiceBrowser.h> +#include <Swiften/Elements/RosterPayload.h> +#include <Swiften/Elements/Presence.h> namespace Swift { diff --git a/Slimber/LinkLocalPresenceManager.h b/Slimber/LinkLocalPresenceManager.h index 26bb7ce..5613448 100644 --- a/Slimber/LinkLocalPresenceManager.h +++ b/Slimber/LinkLocalPresenceManager.h @@ -7,11 +7,11 @@ #pragma once #include <boost/shared_ptr.hpp> -#include "Swiften/Base/boost_bsignals.h" +#include <Swiften/Base/boost_bsignals.h> -#include "Swiften/Elements/RosterItemPayload.h" +#include <Swiften/Elements/RosterItemPayload.h> #include <string> -#include "Swiften/JID/JID.h" +#include <Swiften/JID/JID.h> namespace Swift { class LinkLocalService; diff --git a/Slimber/MainController.cpp b/Slimber/MainController.cpp index e39a660..c2bbb40 100644 --- a/Slimber/MainController.cpp +++ b/Slimber/MainController.cpp @@ -10,11 +10,11 @@ #include <boost/lexical_cast.hpp> #include <iostream> -#include "Swiften/Base/foreach.h" -#include "SwifTools/Application/PlatformApplicationPathProvider.h" -#include "Swiften/LinkLocal/LinkLocalService.h" -#include "Swiften/LinkLocal/LinkLocalServiceBrowser.h" -#include "Swiften/LinkLocal/DNSSD/PlatformDNSSDQuerierFactory.h" +#include <Swiften/Base/foreach.h> +#include <SwifTools/Application/PlatformApplicationPathProvider.h> +#include <Swiften/LinkLocal/LinkLocalService.h> +#include <Swiften/LinkLocal/LinkLocalServiceBrowser.h> +#include <Swiften/LinkLocal/DNSSD/PlatformDNSSDQuerierFactory.h> #include "Slimber/Server.h" #include "Slimber/FileVCardCollection.h" #include "Slimber/MenuletController.h" diff --git a/Slimber/Menulet.h b/Slimber/Menulet.h index df3c32c..f734b18 100644 --- a/Slimber/Menulet.h +++ b/Slimber/Menulet.h @@ -7,7 +7,7 @@ #pragma once #include <string> -#include "Swiften/Base/boost_bsignals.h" +#include <Swiften/Base/boost_bsignals.h> class Menulet { public: diff --git a/Slimber/MenuletController.cpp b/Slimber/MenuletController.cpp index 351db21..03b9187 100644 --- a/Slimber/MenuletController.cpp +++ b/Slimber/MenuletController.cpp @@ -6,7 +6,7 @@ #include "Slimber/MenuletController.h" -#include "Swiften/Base/foreach.h" +#include <Swiften/Base/foreach.h> #include <string> #include "Slimber/Menulet.h" diff --git a/Slimber/Qt/main.cpp b/Slimber/Qt/main.cpp index 0971eca..9885aec 100644 --- a/Slimber/Qt/main.cpp +++ b/Slimber/Qt/main.cpp @@ -11,7 +11,7 @@ #include "QtMenulet.h" #include "Slimber/MainController.h" -#include "Swiften/EventLoop/Qt/QtEventLoop.h" +#include <Swiften/EventLoop/Qt/QtEventLoop.h> #include "Slimber/Qt/BuildVersion.h" int main(int argc, char* argv[]) { diff --git a/Slimber/Server.cpp b/Slimber/Server.cpp index 380ce6a..fb9318e 100644 --- a/Slimber/Server.cpp +++ b/Slimber/Server.cpp @@ -8,29 +8,31 @@ #include <string> #include <boost/bind.hpp> - -#include "Swiften/Base/String.h" -#include "Swiften/LinkLocal/LinkLocalConnector.h" -#include "Swiften/Network/Connection.h" -#include "Swiften/Session/SessionTracer.h" -#include "Swiften/Elements/Element.h" -#include "Swiften/Elements/Presence.h" -#include "Swiften/Elements/RosterPayload.h" -#include "Swiften/Network/BoostConnection.h" -#include "Swiften/Network/BoostConnectionServer.h" -#include "Swiften/Session/SessionTracer.h" -#include "Swiften/Elements/IQ.h" -#include "Swiften/Elements/VCard.h" -#include "Swiften/Server/UserRegistry.h" +#include <iostream> + +#include <Swiften/Base/foreach.h> +#include <Swiften/Base/String.h> +#include <Swiften/LinkLocal/LinkLocalConnector.h> +#include <Swiften/Network/Connection.h> +#include <Swiften/Session/SessionTracer.h> +#include <Swiften/Elements/Element.h> +#include <Swiften/Elements/Presence.h> +#include <Swiften/Elements/RosterPayload.h> +#include <Swiften/Network/BoostConnection.h> +#include <Swiften/Network/BoostConnectionServer.h> +#include <Swiften/Session/SessionTracer.h> +#include <Swiften/Elements/IQ.h> +#include <Swiften/Elements/VCard.h> +#include <Swiften/Server/UserRegistry.h> #include <string> -#include "Swiften/LinkLocal/LinkLocalServiceInfo.h" -#include "Swiften/LinkLocal/OutgoingLinkLocalSession.h" -#include "Swiften/LinkLocal/IncomingLinkLocalSession.h" -#include "Swiften/LinkLocal/LinkLocalServiceBrowser.h" -#include "Swiften/Network/ConnectionServer.h" +#include <Swiften/LinkLocal/LinkLocalServiceInfo.h> +#include <Swiften/LinkLocal/OutgoingLinkLocalSession.h> +#include <Swiften/LinkLocal/IncomingLinkLocalSession.h> +#include <Swiften/LinkLocal/LinkLocalServiceBrowser.h> +#include <Swiften/Network/ConnectionServer.h> #include "Slimber/VCardCollection.h" #include "Slimber/LinkLocalPresenceManager.h" -#include "Swiften/Server/ServerFromClientSession.h" +#include <Swiften/Server/ServerFromClientSession.h> namespace Swift { diff --git a/Slimber/Server.h b/Slimber/Server.h index 98332fd..365fedf 100644 --- a/Slimber/Server.h +++ b/Slimber/Server.h @@ -10,15 +10,15 @@ #include <boost/optional.hpp> #include <vector> -#include "Swiften/Network/BoostIOServiceThread.h" -#include "Swiften/Network/BoostConnectionServer.h" -#include "Swiften/Server/UserRegistry.h" -#include "Swiften/Base/IDGenerator.h" -#include "Swiften/Server/ServerFromClientSession.h" -#include "Swiften/JID/JID.h" -#include "Swiften/Parser/PayloadParsers/FullPayloadParserFactoryCollection.h" -#include "Swiften/Serializer/PayloadSerializers/FullPayloadSerializerCollection.h" -#include "Swiften/LinkLocal/LinkLocalServiceInfo.h" +#include <Swiften/Network/BoostIOServiceThread.h> +#include <Swiften/Network/BoostConnectionServer.h> +#include <Swiften/Server/UserRegistry.h> +#include <Swiften/Base/IDGenerator.h> +#include <Swiften/Server/ServerFromClientSession.h> +#include <Swiften/JID/JID.h> +#include <Swiften/Parser/PayloadParsers/FullPayloadParserFactoryCollection.h> +#include <Swiften/Serializer/PayloadSerializers/FullPayloadSerializerCollection.h> +#include <Swiften/LinkLocal/LinkLocalServiceInfo.h> #include "Slimber/ServerError.h" namespace Swift { diff --git a/Slimber/UnitTest/LinkLocalPresenceManagerTest.cpp b/Slimber/UnitTest/LinkLocalPresenceManagerTest.cpp index 47eb05c..1f41c55 100644 --- a/Slimber/UnitTest/LinkLocalPresenceManagerTest.cpp +++ b/Slimber/UnitTest/LinkLocalPresenceManagerTest.cpp @@ -9,16 +9,16 @@ #include <boost/bind.hpp> #include <map> -#include "Swiften/Elements/Presence.h" -#include "Swiften/Elements/RosterPayload.h" -#include "Swiften/Elements/RosterItemPayload.h" +#include <Swiften/Elements/Presence.h> +#include <Swiften/Elements/RosterPayload.h> +#include <Swiften/Elements/RosterItemPayload.h> #include "Slimber/LinkLocalPresenceManager.h" -#include "Swiften/LinkLocal/LinkLocalServiceInfo.h" -#include "Swiften/LinkLocal/LinkLocalServiceBrowser.h" -#include "Swiften/LinkLocal/DNSSD/DNSSDServiceID.h" -#include "Swiften/LinkLocal/DNSSD/DNSSDResolveServiceQuery.h" -#include "Swiften/LinkLocal/DNSSD/Fake/FakeDNSSDQuerier.h" -#include "Swiften/EventLoop/DummyEventLoop.h" +#include <Swiften/LinkLocal/LinkLocalServiceInfo.h> +#include <Swiften/LinkLocal/LinkLocalServiceBrowser.h> +#include <Swiften/LinkLocal/DNSSD/DNSSDServiceID.h> +#include <Swiften/LinkLocal/DNSSD/DNSSDResolveServiceQuery.h> +#include <Swiften/LinkLocal/DNSSD/Fake/FakeDNSSDQuerier.h> +#include <Swiften/EventLoop/DummyEventLoop.h> using namespace Swift; diff --git a/Slimber/VCardCollection.h b/Slimber/VCardCollection.h index 2203444..4e50848 100644 --- a/Slimber/VCardCollection.h +++ b/Slimber/VCardCollection.h @@ -8,7 +8,7 @@ #include <boost/shared_ptr.hpp> -#include "Swiften/Elements/VCard.h" +#include <Swiften/Elements/VCard.h> namespace Swift { class VCardCollection { diff --git a/Sluift/Lua/Value.cpp b/Sluift/Lua/Value.cpp index c03e633..3164ec6 100644 --- a/Sluift/Lua/Value.cpp +++ b/Sluift/Lua/Value.cpp @@ -6,9 +6,7 @@ #include "Value.h" -extern "C" { - #include <lualib.h> -} +#include <lualib.h> #include <boost/variant/apply_visitor.hpp> #include <Swiften/Base/foreach.h> diff --git a/Sluift/SConscript b/Sluift/SConscript index 576eae5..7c434de 100644 --- a/Sluift/SConscript +++ b/Sluift/SConscript @@ -22,6 +22,10 @@ if env["SCONS_STAGE"] == "build" : myenv.Append(CPPDEFINES = ["SLUIFT_BUILD_DLL"]) elif myenv["PLATFORM"] == "darwin" : myenv["SHLIBSUFFIX"] = ".so" + if env["PLATFORM"] == "win32" : + myenv.Append(CFLAGS = ["/TP"]) + else : + myenv.Append(CFLAGS = ["-x", "c++"]) myenv["SLUIFT_VERSION"] = Version.getBuildVersion(env.Dir("#").abspath, "sluift") def patchLua(env, target, source) : diff --git a/Sluift/sluift.cpp b/Sluift/sluift.cpp index 49cfec4..b911772 100644 --- a/Sluift/sluift.cpp +++ b/Sluift/sluift.cpp @@ -4,16 +4,15 @@ * See Documentation/Licenses/GPLv3.txt for more information. */ -extern "C" { - #include "sluift.h" - #include <lauxlib.h> -} +#include "sluift.h" +#include <lauxlib.h> #include <iostream> #include <string> #include <deque> #include <boost/assign/list_of.hpp> +#include <Swiften/Base/foreach.h> #include <Swiften/Swiften.h> #include "Watchdog.h" @@ -63,6 +62,10 @@ class SluiftClient { return client; } + ClientOptions& getOptions() { + return options; + } + void connect() { rosterReceived = false; client->connect(); @@ -179,6 +182,7 @@ class SluiftClient { private: Client* client; + ClientOptions options; ClientXMLTracer* tracer; bool rosterReceived; std::deque<Stanza::ref> pendingEvents; @@ -453,12 +457,12 @@ static int sluift_client_set_options(lua_State* L) { luaL_checktype(L, 2, LUA_TTABLE); lua_getfield(L, 2, "compress"); if (!lua_isnil(L, -1)) { - client->getClient()->setUseStreamCompression(lua_toboolean(L, -1)); + client->getOptions().useStreamCompression = lua_toboolean(L, -1); } lua_getfield(L, 2, "tls"); if (!lua_isnil(L, -1)) { bool useTLS = lua_toboolean(L, -1); - client->getClient()->setUseTLS(useTLS ? Client::UseTLSWhenAvailable : Client::NeverUseTLS); + client->getOptions().useTLS = (useTLS ? ClientOptions::UseTLSWhenAvailable : ClientOptions::NeverUseTLS); } lua_pushvalue(L, 1); return 0; diff --git a/SwifTools/Application/ApplicationPathProvider.cpp b/SwifTools/Application/ApplicationPathProvider.cpp index e683563..aa7e609 100644 --- a/SwifTools/Application/ApplicationPathProvider.cpp +++ b/SwifTools/Application/ApplicationPathProvider.cpp @@ -7,9 +7,9 @@ #include <boost/filesystem.hpp> #include <iostream> -#include "SwifTools/Application/ApplicationPathProvider.h" -#include "Swiften/Base/foreach.h" -#include "Swiften/Base/Paths.h" +#include <SwifTools/Application/ApplicationPathProvider.h> +#include <Swiften/Base/foreach.h> +#include <Swiften/Base/Paths.h> namespace Swift { diff --git a/SwifTools/Application/CocoaApplication.mm b/SwifTools/Application/CocoaApplication.mm index edfdc25..cbb5f2e 100644 --- a/SwifTools/Application/CocoaApplication.mm +++ b/SwifTools/Application/CocoaApplication.mm @@ -1,4 +1,4 @@ -#include "SwifTools/Application/CocoaApplication.h" +#include <SwifTools/Application/CocoaApplication.h> #include <AppKit/AppKit.h> #include <Cocoa/Cocoa.h> diff --git a/SwifTools/Application/MacOSXApplicationPathProvider.cpp b/SwifTools/Application/MacOSXApplicationPathProvider.cpp index 085eb33..41b0e4c 100644 --- a/SwifTools/Application/MacOSXApplicationPathProvider.cpp +++ b/SwifTools/Application/MacOSXApplicationPathProvider.cpp @@ -4,7 +4,7 @@ * See Documentation/Licenses/GPLv3.txt for more information. */ -#include "SwifTools/Application/MacOSXApplicationPathProvider.h" +#include <SwifTools/Application/MacOSXApplicationPathProvider.h> #include <iostream> #include <mach-o/dyld.h> diff --git a/SwifTools/Application/MacOSXApplicationPathProvider.h b/SwifTools/Application/MacOSXApplicationPathProvider.h index fec1944..760ea9b 100644 --- a/SwifTools/Application/MacOSXApplicationPathProvider.h +++ b/SwifTools/Application/MacOSXApplicationPathProvider.h @@ -6,7 +6,7 @@ #pragma once -#include "SwifTools/Application/ApplicationPathProvider.h" +#include <SwifTools/Application/ApplicationPathProvider.h> namespace Swift { class MacOSXApplicationPathProvider : public ApplicationPathProvider { diff --git a/SwifTools/Application/PlatformApplicationPathProvider.h b/SwifTools/Application/PlatformApplicationPathProvider.h index bb9bfa9..7ea4b35 100644 --- a/SwifTools/Application/PlatformApplicationPathProvider.h +++ b/SwifTools/Application/PlatformApplicationPathProvider.h @@ -6,20 +6,20 @@ #pragma once -#include "Swiften/Base/Platform.h" +#include <Swiften/Base/Platform.h> #if defined(SWIFTEN_PLATFORM_MACOSX) -#include "SwifTools/Application/MacOSXApplicationPathProvider.h" +#include <SwifTools/Application/MacOSXApplicationPathProvider.h> namespace Swift { typedef MacOSXApplicationPathProvider PlatformApplicationPathProvider; } #elif defined(SWIFTEN_PLATFORM_WIN32) -#include "SwifTools/Application/WindowsApplicationPathProvider.h" +#include <SwifTools/Application/WindowsApplicationPathProvider.h> namespace Swift { typedef WindowsApplicationPathProvider PlatformApplicationPathProvider; } #else -#include "SwifTools/Application/UnixApplicationPathProvider.h" +#include <SwifTools/Application/UnixApplicationPathProvider.h> namespace Swift { typedef UnixApplicationPathProvider PlatformApplicationPathProvider; } diff --git a/SwifTools/Application/SConscript b/SwifTools/Application/SConscript index 0097bca..32924fc 100644 --- a/SwifTools/Application/SConscript +++ b/SwifTools/Application/SConscript @@ -21,6 +21,7 @@ else : objects = swiftools_env.StaticObject(sources) swiftools_env.Append(SWIFTOOLS_OBJECTS = [objects]) -env.Append(UNITTEST_SOURCES = [ - File("UnitTest/ApplicationPathProviderTest.cpp") - ]) +if swiftools_env["PLATFORM"] != "darwin" or swiftools_env["target"] == "native" : + env.Append(UNITTEST_SOURCES = [ + File("UnitTest/ApplicationPathProviderTest.cpp") + ]) diff --git a/SwifTools/Application/UnitTest/ApplicationPathProviderTest.cpp b/SwifTools/Application/UnitTest/ApplicationPathProviderTest.cpp index a418bc2..5eb0e16 100644 --- a/SwifTools/Application/UnitTest/ApplicationPathProviderTest.cpp +++ b/SwifTools/Application/UnitTest/ApplicationPathProviderTest.cpp @@ -9,7 +9,7 @@ #include <string> #include <boost/algorithm/string.hpp> -#include "SwifTools/Application/PlatformApplicationPathProvider.h" +#include <SwifTools/Application/PlatformApplicationPathProvider.h> using namespace Swift; diff --git a/SwifTools/Application/UnixApplicationPathProvider.cpp b/SwifTools/Application/UnixApplicationPathProvider.cpp index d5a2f58..784256f 100644 --- a/SwifTools/Application/UnixApplicationPathProvider.cpp +++ b/SwifTools/Application/UnixApplicationPathProvider.cpp @@ -4,7 +4,7 @@ * See Documentation/Licenses/GPLv3.txt for more information. */ -#include "SwifTools/Application/UnixApplicationPathProvider.h" +#include <SwifTools/Application/UnixApplicationPathProvider.h> #include <unistd.h> #include <boost/algorithm/string.hpp> diff --git a/SwifTools/Application/UnixApplicationPathProvider.h b/SwifTools/Application/UnixApplicationPathProvider.h index 7ca64c3..198e4ee 100644 --- a/SwifTools/Application/UnixApplicationPathProvider.h +++ b/SwifTools/Application/UnixApplicationPathProvider.h @@ -6,7 +6,7 @@ #pragma once -#include "SwifTools/Application/ApplicationPathProvider.h" +#include <SwifTools/Application/ApplicationPathProvider.h> namespace Swift { class UnixApplicationPathProvider : public ApplicationPathProvider { diff --git a/SwifTools/Application/WindowsApplicationPathProvider.cpp b/SwifTools/Application/WindowsApplicationPathProvider.cpp index afcdea2..8514fa7 100644 --- a/SwifTools/Application/WindowsApplicationPathProvider.cpp +++ b/SwifTools/Application/WindowsApplicationPathProvider.cpp @@ -4,7 +4,7 @@ * See Documentation/Licenses/GPLv3.txt for more information. */ -#include "SwifTools/Application/WindowsApplicationPathProvider.h" +#include <SwifTools/Application/WindowsApplicationPathProvider.h> #include <windows.h> diff --git a/SwifTools/Application/WindowsApplicationPathProvider.h b/SwifTools/Application/WindowsApplicationPathProvider.h index 9428908..f288326 100644 --- a/SwifTools/Application/WindowsApplicationPathProvider.h +++ b/SwifTools/Application/WindowsApplicationPathProvider.h @@ -6,7 +6,7 @@ #pragma once -#include "SwifTools/Application/ApplicationPathProvider.h" +#include <SwifTools/Application/ApplicationPathProvider.h> namespace Swift { class WindowsApplicationPathProvider : public ApplicationPathProvider { diff --git a/SwifTools/AutoUpdater/AutoUpdater.cpp b/SwifTools/AutoUpdater/AutoUpdater.cpp index f4e462b..e424f3b 100644 --- a/SwifTools/AutoUpdater/AutoUpdater.cpp +++ b/SwifTools/AutoUpdater/AutoUpdater.cpp @@ -4,7 +4,7 @@ * See Documentation/Licenses/GPLv3.txt for more information. */ -#include "SwifTools/AutoUpdater/AutoUpdater.h" +#include <SwifTools/AutoUpdater/AutoUpdater.h> namespace Swift { diff --git a/SwifTools/AutoUpdater/PlatformAutoUpdaterFactory.cpp b/SwifTools/AutoUpdater/PlatformAutoUpdaterFactory.cpp index 4dd06c7..d2e89ac 100644 --- a/SwifTools/AutoUpdater/PlatformAutoUpdaterFactory.cpp +++ b/SwifTools/AutoUpdater/PlatformAutoUpdaterFactory.cpp @@ -4,12 +4,12 @@ * See Documentation/Licenses/GPLv3.txt for more information. */ -#include "SwifTools/AutoUpdater/PlatformAutoUpdaterFactory.h" +#include <SwifTools/AutoUpdater/PlatformAutoUpdaterFactory.h> #include <cassert> #ifdef HAVE_SPARKLE -#include "SwifTools/AutoUpdater/SparkleAutoUpdater.h" +#include <SwifTools/AutoUpdater/SparkleAutoUpdater.h> #endif namespace Swift { diff --git a/SwifTools/AutoUpdater/SparkleAutoUpdater.h b/SwifTools/AutoUpdater/SparkleAutoUpdater.h index fc08975..f367945 100644 --- a/SwifTools/AutoUpdater/SparkleAutoUpdater.h +++ b/SwifTools/AutoUpdater/SparkleAutoUpdater.h @@ -7,7 +7,7 @@ #pragma once #include <string> -#include "SwifTools/AutoUpdater/AutoUpdater.h" +#include <SwifTools/AutoUpdater/AutoUpdater.h> namespace Swift { class SparkleAutoUpdater : public AutoUpdater { diff --git a/SwifTools/AutoUpdater/SparkleAutoUpdater.mm b/SwifTools/AutoUpdater/SparkleAutoUpdater.mm index 440e178..c35abc8 100644 --- a/SwifTools/AutoUpdater/SparkleAutoUpdater.mm +++ b/SwifTools/AutoUpdater/SparkleAutoUpdater.mm @@ -1,4 +1,4 @@ -#include "SwifTools/AutoUpdater/SparkleAutoUpdater.h" +#include <SwifTools/AutoUpdater/SparkleAutoUpdater.h> #include <Cocoa/Cocoa.h> #include <Sparkle/Sparkle.h> diff --git a/Slimber/Cocoa/CocoaAction.h b/SwifTools/Cocoa/CocoaAction.h index a46ef7c..a46ef7c 100644 --- a/Slimber/Cocoa/CocoaAction.h +++ b/SwifTools/Cocoa/CocoaAction.h diff --git a/Slimber/Cocoa/CocoaAction.mm b/SwifTools/Cocoa/CocoaAction.mm index 15498a1..d560787 100644 --- a/Slimber/Cocoa/CocoaAction.mm +++ b/SwifTools/Cocoa/CocoaAction.mm @@ -1,4 +1,10 @@ -#include "Slimber/Cocoa/CocoaAction.h" +/* + * Copyright (c) 2010 Remko Tronçon + * Licensed under the GNU General Public License v3. + * See Documentation/Licenses/GPLv3.txt for more information. + */ + +#include <SwifTools/Cocoa/CocoaAction.h> @implementation CocoaAction diff --git a/SwifTools/Cocoa/SConscript b/SwifTools/Cocoa/SConscript new file mode 100644 index 0000000..4ae4a07 --- /dev/null +++ b/SwifTools/Cocoa/SConscript @@ -0,0 +1,8 @@ +Import("swiftools_env", "env") + +sources = [] +if swiftools_env["PLATFORM"] == "darwin" and swiftools_env["target"] == "native" : + sources += ["CocoaAction.mm"] + +objects = swiftools_env.StaticObject(sources) +swiftools_env.Append(SWIFTOOLS_OBJECTS = [objects]) diff --git a/SwifTools/Dock/Dock.cpp b/SwifTools/Dock/Dock.cpp index 77bcd84..e159b8d 100644 --- a/SwifTools/Dock/Dock.cpp +++ b/SwifTools/Dock/Dock.cpp @@ -4,7 +4,7 @@ * See Documentation/Licenses/GPLv3.txt for more information. */ -#include "SwifTools/Dock/Dock.h" +#include <SwifTools/Dock/Dock.h> namespace Swift { diff --git a/SwifTools/Dock/MacOSXDock.h b/SwifTools/Dock/MacOSXDock.h index 64cc737..df2686f 100644 --- a/SwifTools/Dock/MacOSXDock.h +++ b/SwifTools/Dock/MacOSXDock.h @@ -6,7 +6,7 @@ #pragma once -#include "SwifTools/Dock/Dock.h" +#include <SwifTools/Dock/Dock.h> namespace Swift { diff --git a/SwifTools/Dock/MacOSXDock.mm b/SwifTools/Dock/MacOSXDock.mm index a7a3d55..b8374fa 100644 --- a/SwifTools/Dock/MacOSXDock.mm +++ b/SwifTools/Dock/MacOSXDock.mm @@ -1,10 +1,10 @@ -#include "SwifTools/Dock/MacOSXDock.h" +#include <SwifTools/Dock/MacOSXDock.h> #include <AppKit/AppKit.h> #include <Cocoa/Cocoa.h> #include <boost/lexical_cast.hpp> -#include "Swiften/Base/String.h" +#include <Swiften/Base/String.h> namespace Swift { diff --git a/SwifTools/Dock/NullDock.h b/SwifTools/Dock/NullDock.h index a1655a4..b015770 100644 --- a/SwifTools/Dock/NullDock.h +++ b/SwifTools/Dock/NullDock.h @@ -6,7 +6,7 @@ #pragma once -#include "SwifTools/Dock/Dock.h" +#include <SwifTools/Dock/Dock.h> namespace Swift { class NullDock : public Dock { diff --git a/SwifTools/Dock/WindowsDock.h b/SwifTools/Dock/WindowsDock.h index dc298da..0254617 100644 --- a/SwifTools/Dock/WindowsDock.h +++ b/SwifTools/Dock/WindowsDock.h @@ -9,8 +9,8 @@ #include <QSystemTrayIcon> #include <boost/lexical_cast.hpp> -#include "SwifTools/Dock/Dock.h" -#include "SwifTools/Notifier/Notifier.h" +#include <SwifTools/Dock/Dock.h> +#include <SwifTools/Notifier/Notifier.h> namespace Swift { class WindowsDock : public Dock { diff --git a/SwifTools/Idle/ActualIdleDetector.cpp b/SwifTools/Idle/ActualIdleDetector.cpp index 59df632..2a99e1a 100644 --- a/SwifTools/Idle/ActualIdleDetector.cpp +++ b/SwifTools/Idle/ActualIdleDetector.cpp @@ -4,14 +4,14 @@ * See Documentation/Licenses/GPLv3.txt for more information. */ -#include "SwifTools/Idle/ActualIdleDetector.h" +#include <SwifTools/Idle/ActualIdleDetector.h> #include <boost/bind.hpp> #include <iostream> -#include "SwifTools/Idle/IdleQuerier.h" -#include "Swiften/Network/Timer.h" -#include "Swiften/Network/TimerFactory.h" +#include <SwifTools/Idle/IdleQuerier.h> +#include <Swiften/Network/Timer.h> +#include <Swiften/Network/TimerFactory.h> namespace Swift { diff --git a/SwifTools/Idle/ActualIdleDetector.h b/SwifTools/Idle/ActualIdleDetector.h index 3a355cc..7845398 100644 --- a/SwifTools/Idle/ActualIdleDetector.h +++ b/SwifTools/Idle/ActualIdleDetector.h @@ -8,7 +8,7 @@ #include <boost/shared_ptr.hpp> -#include "SwifTools/Idle/IdleDetector.h" +#include <SwifTools/Idle/IdleDetector.h> namespace Swift { class IdleQuerier; diff --git a/SwifTools/Idle/DummyIdleQuerier.h b/SwifTools/Idle/DummyIdleQuerier.h index 0c40643..162d8f6 100644 --- a/SwifTools/Idle/DummyIdleQuerier.h +++ b/SwifTools/Idle/DummyIdleQuerier.h @@ -6,7 +6,7 @@ #pragma once -#include "SwifTools/Idle/IdleQuerier.h" +#include <SwifTools/Idle/IdleQuerier.h> namespace Swift { class DummyIdleQuerier : public IdleQuerier { diff --git a/SwifTools/Idle/IdleDetector.cpp b/SwifTools/Idle/IdleDetector.cpp index f29be01..66ec4a5 100644 --- a/SwifTools/Idle/IdleDetector.cpp +++ b/SwifTools/Idle/IdleDetector.cpp @@ -4,7 +4,7 @@ * See Documentation/Licenses/GPLv3.txt for more information. */ -#include "SwifTools/Idle/IdleDetector.h" +#include <SwifTools/Idle/IdleDetector.h> namespace Swift { diff --git a/SwifTools/Idle/IdleDetector.h b/SwifTools/Idle/IdleDetector.h index 746e281..4b54801 100644 --- a/SwifTools/Idle/IdleDetector.h +++ b/SwifTools/Idle/IdleDetector.h @@ -6,7 +6,7 @@ #pragma once -#include "Swiften/Base/boost_bsignals.h" +#include <Swiften/Base/boost_bsignals.h> #include <boost/shared_ptr.hpp> namespace Swift { diff --git a/SwifTools/Idle/IdleQuerier.cpp b/SwifTools/Idle/IdleQuerier.cpp index d8c01ca..f553252 100644 --- a/SwifTools/Idle/IdleQuerier.cpp +++ b/SwifTools/Idle/IdleQuerier.cpp @@ -4,7 +4,7 @@ * See Documentation/Licenses/GPLv3.txt for more information. */ -#include "SwifTools/Idle/IdleQuerier.h" +#include <SwifTools/Idle/IdleQuerier.h> namespace Swift { diff --git a/SwifTools/Idle/IdleQuerierTest/IdleQuerierTest.cpp b/SwifTools/Idle/IdleQuerierTest/IdleQuerierTest.cpp index 5ae4a4d..df233a2 100644 --- a/SwifTools/Idle/IdleQuerierTest/IdleQuerierTest.cpp +++ b/SwifTools/Idle/IdleQuerierTest/IdleQuerierTest.cpp @@ -6,8 +6,8 @@ #include <iostream> -#include "SwifTools/Idle/PlatformIdleQuerier.h" -#include "Swiften/Base/sleep.h" +#include <SwifTools/Idle/PlatformIdleQuerier.h> +#include <Swiften/Base/sleep.h> using namespace Swift; diff --git a/SwifTools/Idle/MacOSXIdleQuerier.cpp b/SwifTools/Idle/MacOSXIdleQuerier.cpp index 4760285..64e010b 100644 --- a/SwifTools/Idle/MacOSXIdleQuerier.cpp +++ b/SwifTools/Idle/MacOSXIdleQuerier.cpp @@ -4,7 +4,7 @@ * See Documentation/Licenses/GPLv3.txt for more information. */ -#include "SwifTools/Idle/MacOSXIdleQuerier.h" +#include <SwifTools/Idle/MacOSXIdleQuerier.h> #pragma GCC diagnostic ignored "-Wold-style-cast" diff --git a/SwifTools/Idle/MacOSXIdleQuerier.h b/SwifTools/Idle/MacOSXIdleQuerier.h index ebd4656..fbbd448 100644 --- a/SwifTools/Idle/MacOSXIdleQuerier.h +++ b/SwifTools/Idle/MacOSXIdleQuerier.h @@ -8,7 +8,7 @@ #include <IOKit/IOKitLib.h> -#include "SwifTools/Idle/IdleQuerier.h" +#include <SwifTools/Idle/IdleQuerier.h> namespace Swift { class MacOSXIdleQuerier : public IdleQuerier { diff --git a/SwifTools/Idle/PlatformIdleQuerier.cpp b/SwifTools/Idle/PlatformIdleQuerier.cpp index a28e701..34bcedd 100644 --- a/SwifTools/Idle/PlatformIdleQuerier.cpp +++ b/SwifTools/Idle/PlatformIdleQuerier.cpp @@ -4,17 +4,17 @@ * See Documentation/Licenses/GPLv3.txt for more information. */ -#include "SwifTools/Idle/PlatformIdleQuerier.h" -#include "Swiften/Base/Platform.h" +#include <SwifTools/Idle/PlatformIdleQuerier.h> +#include <Swiften/Base/Platform.h> -#if defined(SWIFTEN_PLATFORM_MACOSX) && defined(HAVE_IOKIT) -#include "SwifTools/Idle/MacOSXIdleQuerier.h" +#if defined(SWIFTEN_PLATFORM_MACOSX) && defined(HAVE_IOKIT) && !defined(SWIFTEN_PLATFORM_IPHONE) +#include <SwifTools/Idle/MacOSXIdleQuerier.h> #elif defined(SWIFTEN_PLATFORM_WINDOWS) -#include "SwifTools/Idle/WindowsIdleQuerier.h" +#include <SwifTools/Idle/WindowsIdleQuerier.h> #elif defined(HAVE_XSS) -#include "SwifTools/Idle/XSSIdleQuerier.h" +#include <SwifTools/Idle/XSSIdleQuerier.h> #endif -#include "SwifTools/Idle/DummyIdleQuerier.h" +#include <SwifTools/Idle/DummyIdleQuerier.h> #include <cassert> #include <iostream> @@ -23,7 +23,7 @@ namespace Swift { PlatformIdleQuerier::PlatformIdleQuerier() : querier(NULL) { #if defined(SWIFTEN_PLATFORM_MACOSX) -#if defined(HAVE_IOKIT) +#if defined(HAVE_IOKIT) && !defined(SWIFTEN_PLATFORM_IPHONE) querier = new MacOSXIdleQuerier(); #else querier = new DummyIdleQuerier(); diff --git a/SwifTools/Idle/PlatformIdleQuerier.h b/SwifTools/Idle/PlatformIdleQuerier.h index 30c4bb7..2679e39 100644 --- a/SwifTools/Idle/PlatformIdleQuerier.h +++ b/SwifTools/Idle/PlatformIdleQuerier.h @@ -6,7 +6,7 @@ #pragma once -#include "SwifTools/Idle/IdleQuerier.h" +#include <SwifTools/Idle/IdleQuerier.h> namespace Swift { class PlatformIdleQuerier : public IdleQuerier { diff --git a/SwifTools/Idle/UnitTest/ActualIdleDetectorTest.cpp b/SwifTools/Idle/UnitTest/ActualIdleDetectorTest.cpp index 3fa7136..686b7a0 100644 --- a/SwifTools/Idle/UnitTest/ActualIdleDetectorTest.cpp +++ b/SwifTools/Idle/UnitTest/ActualIdleDetectorTest.cpp @@ -8,11 +8,11 @@ #include <cppunit/extensions/TestFactoryRegistry.h> #include <boost/bind.hpp> -#include "SwifTools/Idle/ActualIdleDetector.h" -#include "SwifTools/Idle/IdleQuerier.h" -#include "Swiften/Base/foreach.h" -#include "Swiften/Network/TimerFactory.h" -#include "Swiften/Network/Timer.h" +#include <SwifTools/Idle/ActualIdleDetector.h> +#include <SwifTools/Idle/IdleQuerier.h> +#include <Swiften/Base/foreach.h> +#include <Swiften/Network/TimerFactory.h> +#include <Swiften/Network/Timer.h> using namespace Swift; diff --git a/SwifTools/Idle/WindowsIdleQuerier.cpp b/SwifTools/Idle/WindowsIdleQuerier.cpp index 904fd6d..4b9a5a1 100644 --- a/SwifTools/Idle/WindowsIdleQuerier.cpp +++ b/SwifTools/Idle/WindowsIdleQuerier.cpp @@ -4,7 +4,7 @@ * See Documentation/Licenses/GPLv3.txt for more information. */ -#include "SwifTools/Idle/WindowsIdleQuerier.h" +#include <SwifTools/Idle/WindowsIdleQuerier.h> #include <windows.h> diff --git a/SwifTools/Idle/WindowsIdleQuerier.h b/SwifTools/Idle/WindowsIdleQuerier.h index 8297c77..4a219e5 100644 --- a/SwifTools/Idle/WindowsIdleQuerier.h +++ b/SwifTools/Idle/WindowsIdleQuerier.h @@ -6,7 +6,7 @@ #pragma once -#include "SwifTools/Idle/IdleQuerier.h" +#include <SwifTools/Idle/IdleQuerier.h> namespace Swift { class WindowsIdleQuerier : public IdleQuerier { diff --git a/SwifTools/Idle/XSSIdleQuerier.cpp b/SwifTools/Idle/XSSIdleQuerier.cpp index 39a3cef..74e1eda 100644 --- a/SwifTools/Idle/XSSIdleQuerier.cpp +++ b/SwifTools/Idle/XSSIdleQuerier.cpp @@ -4,7 +4,7 @@ * See Documentation/Licenses/GPLv3.txt for more information. */ -#include "SwifTools/Idle/XSSIdleQuerier.h" +#include <SwifTools/Idle/XSSIdleQuerier.h> #include <cassert> #include <iostream> diff --git a/SwifTools/Idle/XSSIdleQuerier.h b/SwifTools/Idle/XSSIdleQuerier.h index b00c702..29569a3 100644 --- a/SwifTools/Idle/XSSIdleQuerier.h +++ b/SwifTools/Idle/XSSIdleQuerier.h @@ -9,7 +9,7 @@ #include <X11/Xlib.h> #include <X11/extensions/scrnsaver.h> -#include "SwifTools/Idle/IdleQuerier.h" +#include <SwifTools/Idle/IdleQuerier.h> namespace Swift { class XSSIdleQuerier : public IdleQuerier { diff --git a/SwifTools/LastLineTracker.cpp b/SwifTools/LastLineTracker.cpp new file mode 100644 index 0000000..a7360a8 --- /dev/null +++ b/SwifTools/LastLineTracker.cpp @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2011 Vlad Voicu + * Licensed under the Simplified BSD license. + * See Documentation/Licenses/BSD-simplified.txt for more information. + */ + +#include "LastLineTracker.h" + +using namespace Swift; + +LastLineTracker::LastLineTracker() { + lastFocus = true; + shouldMove = false; +} + +void LastLineTracker::setHasFocus(bool focus) { + if (!focus && lastFocus) { + shouldMove = true; + lastFocus = focus; + return; + } + shouldMove = false; + lastFocus = focus; +} + +bool LastLineTracker::getShouldMoveLastLine() { + bool ret = shouldMove; + shouldMove = false; + return ret; +} diff --git a/SwifTools/LastLineTracker.h b/SwifTools/LastLineTracker.h new file mode 100644 index 0000000..b7c9a3b --- /dev/null +++ b/SwifTools/LastLineTracker.h @@ -0,0 +1,19 @@ +/* + * Copyright (c) 2011 Vlad Voicu + * Licensed under the Simplified BSD license. + * See Documentation/Licenses/BSD-simplified.txt for more information. + */ + +#pragma once + +namespace Swift { + class LastLineTracker { + public: + LastLineTracker(); + void setHasFocus(bool focus); + bool getShouldMoveLastLine(); + private: + bool lastFocus; + bool shouldMove; + }; +} diff --git a/SwifTools/Linkify.cpp b/SwifTools/Linkify.cpp index 91c713f..15fd9a5 100644 --- a/SwifTools/Linkify.cpp +++ b/SwifTools/Linkify.cpp @@ -4,7 +4,7 @@ * See Documentation/Licenses/GPLv3.txt for more information. */ -#include "SwifTools/Linkify.h" +#include <SwifTools/Linkify.h> #include <boost/regex.hpp> #include <sstream> @@ -12,7 +12,7 @@ namespace Swift { -static boost::regex linkifyRegexp("^https?://.*"); +static boost::regex linkifyRegexp("^(https?://|xmpp:).*"); std::string Linkify::linkify(const std::string& input) { std::ostringstream result; diff --git a/SwifTools/Notifier/GNTPNotifier.cpp b/SwifTools/Notifier/GNTPNotifier.cpp index 9a20c33..9bc05bd 100644 --- a/SwifTools/Notifier/GNTPNotifier.cpp +++ b/SwifTools/Notifier/GNTPNotifier.cpp @@ -6,15 +6,15 @@ // FIXME: This notifier needs finishing (handling callbacks etc.) -#include "SwifTools/Notifier/GNTPNotifier.h" +#include <SwifTools/Notifier/GNTPNotifier.h> #include <cassert> #include <iostream> #include <boost/bind.hpp> #include <sstream> -#include "Swiften/Base/foreach.h" -#include "Swiften/Network/ConnectionFactory.h" +#include <Swiften/Base/foreach.h> +#include <Swiften/Network/ConnectionFactory.h> namespace Swift { diff --git a/SwifTools/Notifier/GNTPNotifier.h b/SwifTools/Notifier/GNTPNotifier.h index a740c27..2cba044 100644 --- a/SwifTools/Notifier/GNTPNotifier.h +++ b/SwifTools/Notifier/GNTPNotifier.h @@ -8,8 +8,8 @@ #include <boost/filesystem.hpp> -#include "SwifTools/Notifier/Notifier.h" -#include "Swiften/Network/Connection.h" +#include <SwifTools/Notifier/Notifier.h> +#include <Swiften/Network/Connection.h> namespace Swift { class ConnectionFactory; diff --git a/SwifTools/Notifier/GrowlNotifier.cpp b/SwifTools/Notifier/GrowlNotifier.cpp index e289313..46355e9 100644 --- a/SwifTools/Notifier/GrowlNotifier.cpp +++ b/SwifTools/Notifier/GrowlNotifier.cpp @@ -8,10 +8,10 @@ #include <cassert> -#include "Swiften/Base/String.h" -#include "Swiften/Base/ByteArray.h" -#include "SwifTools/Notifier/GrowlNotifier.h" -#include "Swiften/Base/foreach.h" +#include <Swiften/Base/String.h> +#include <Swiften/Base/ByteArray.h> +#include <SwifTools/Notifier/GrowlNotifier.h> +#include <Swiften/Base/foreach.h> #pragma GCC diagnostic ignored "-Wold-style-cast" #pragma GCC diagnostic ignored "-Wdeprecated-declarations" diff --git a/SwifTools/Notifier/GrowlNotifier.h b/SwifTools/Notifier/GrowlNotifier.h index d4a6178..e2686e8 100644 --- a/SwifTools/Notifier/GrowlNotifier.h +++ b/SwifTools/Notifier/GrowlNotifier.h @@ -10,7 +10,7 @@ #include <Growl/Growl.h> #include <boost/filesystem/fstream.hpp> -#include "SwifTools/Notifier/Notifier.h" +#include <SwifTools/Notifier/Notifier.h> namespace Swift { /** diff --git a/SwifTools/Notifier/LoggingNotifier.h b/SwifTools/Notifier/LoggingNotifier.h index 18ae0e2..32e0610 100644 --- a/SwifTools/Notifier/LoggingNotifier.h +++ b/SwifTools/Notifier/LoggingNotifier.h @@ -6,8 +6,8 @@ #pragma once -#include "SwifTools/Notifier/Notifier.h" -#include "Swiften/Base/ByteArray.h" +#include <SwifTools/Notifier/Notifier.h> +#include <Swiften/Base/ByteArray.h> namespace Swift { class LoggingNotifier : public Notifier { diff --git a/SwifTools/Notifier/Notifier.cpp b/SwifTools/Notifier/Notifier.cpp index 1673400..5cd9c50 100644 --- a/SwifTools/Notifier/Notifier.cpp +++ b/SwifTools/Notifier/Notifier.cpp @@ -4,7 +4,7 @@ * See Documentation/Licenses/GPLv3.txt for more information. */ -#include "SwifTools/Notifier/Notifier.h" +#include <SwifTools/Notifier/Notifier.h> namespace Swift { diff --git a/SwifTools/Notifier/NullNotifier.h b/SwifTools/Notifier/NullNotifier.h index 24b4476..2fa9c11 100644 --- a/SwifTools/Notifier/NullNotifier.h +++ b/SwifTools/Notifier/NullNotifier.h @@ -6,7 +6,7 @@ #pragma once -#include "SwifTools/Notifier/Notifier.h" +#include <SwifTools/Notifier/Notifier.h> namespace Swift { class NullNotifier : public Notifier { diff --git a/SwifTools/Notifier/SnarlNotifier.cpp b/SwifTools/Notifier/SnarlNotifier.cpp index d891e7d..19d3622 100644 --- a/SwifTools/Notifier/SnarlNotifier.cpp +++ b/SwifTools/Notifier/SnarlNotifier.cpp @@ -4,14 +4,14 @@ * See Documentation/Licenses/GPLv3.txt for more information. */ -#include "SwifTools/Notifier/SnarlNotifier.h" +#include <SwifTools/Notifier/SnarlNotifier.h> #include <cassert> #include <iostream> #include <boost/bind.hpp> -#include "Swiften/Base/foreach.h" -#include "SwifTools/Notifier/Win32NotifierWindow.h" +#include <Swiften/Base/foreach.h> +#include <SwifTools/Notifier/Win32NotifierWindow.h> #define SWIFT_SNARLNOTIFIER_MESSAGE_ID 0x4567 // Sounds sick to pick a number, but this is windows diff --git a/SwifTools/Notifier/SnarlNotifier.h b/SwifTools/Notifier/SnarlNotifier.h index 9e2cddf..065c9ec 100644 --- a/SwifTools/Notifier/SnarlNotifier.h +++ b/SwifTools/Notifier/SnarlNotifier.h @@ -8,7 +8,7 @@ #include <map> -#include "SwifTools/Notifier/Notifier.h" +#include <SwifTools/Notifier/Notifier.h> #include "SnarlInterface.h" namespace Swift { diff --git a/SwifTools/Notifier/TogglableNotifier.h b/SwifTools/Notifier/TogglableNotifier.h index 415caf6..e8de5de 100644 --- a/SwifTools/Notifier/TogglableNotifier.h +++ b/SwifTools/Notifier/TogglableNotifier.h @@ -6,7 +6,7 @@ #pragma once -#include "SwifTools/Notifier/Notifier.h" +#include <SwifTools/Notifier/Notifier.h> namespace Swift { class TogglableNotifier : public Notifier { diff --git a/SwifTools/Notifier/Win32NotifierWindow.h b/SwifTools/Notifier/Win32NotifierWindow.h index 7ac149b..2279b0b 100644 --- a/SwifTools/Notifier/Win32NotifierWindow.h +++ b/SwifTools/Notifier/Win32NotifierWindow.h @@ -8,7 +8,7 @@ //#include <windows.h> -#include "Swiften/Base/boost_bsignals.h" +#include <Swiften/Base/boost_bsignals.h> namespace Swift { class Win32NotifierWindow { diff --git a/SwifTools/SConscript b/SwifTools/SConscript index d4747db..e5085cc 100644 --- a/SwifTools/SConscript +++ b/SwifTools/SConscript @@ -27,6 +27,7 @@ if env["SCONS_STAGE"] == "build" : "AutoUpdater/PlatformAutoUpdaterFactory.cpp", "Linkify.cpp", "TabComplete.cpp", + "LastLineTracker.cpp", ] if swiftools_env.get("HAVE_SPARKLE", 0) : @@ -50,8 +51,10 @@ if env["SCONS_STAGE"] == "build" : "Application", "Dock", "Notifier", + "URIHandler", "Idle/IdleQuerierTest", "Idle/UnitTest", + "Cocoa", "UnitTest" ]) diff --git a/SwifTools/TabComplete.cpp b/SwifTools/TabComplete.cpp index b123360..4c295ab 100644 --- a/SwifTools/TabComplete.cpp +++ b/SwifTools/TabComplete.cpp @@ -4,12 +4,12 @@ * See Documentation/Licenses/GPLv3.txt for more information. */ -#include "SwifTools/TabComplete.h" +#include <SwifTools/TabComplete.h> #include <algorithm> #include <boost/algorithm/string.hpp> -#include "Swiften/Base/foreach.h" +#include <Swiften/Base/foreach.h> namespace Swift { diff --git a/SwifTools/URIHandler/MacOSXURIHandler.h b/SwifTools/URIHandler/MacOSXURIHandler.h new file mode 100644 index 0000000..f803420 --- /dev/null +++ b/SwifTools/URIHandler/MacOSXURIHandler.h @@ -0,0 +1,24 @@ +/* + * Copyright (c) 2011 Remko Tronçon + * Licensed under the GNU General Public License v3. + * See Documentation/Licenses/GPLv3.txt for more information. + */ + +#pragma once + +#include <SwifTools/URIHandler/URIHandler.h> + +namespace Swift { + class MacOSXURIHandler : public URIHandler { + public: + MacOSXURIHandler(); + virtual ~MacOSXURIHandler(); + + virtual void start(); + virtual void stop(); + + private: + class Private; + Private* p; + }; +} diff --git a/SwifTools/URIHandler/MacOSXURIHandler.mm b/SwifTools/URIHandler/MacOSXURIHandler.mm new file mode 100644 index 0000000..3542e2f --- /dev/null +++ b/SwifTools/URIHandler/MacOSXURIHandler.mm @@ -0,0 +1,59 @@ +/* + * Copyright (c) 2011 Remko Tronçon + * Licensed under the GNU General Public License v3. + * See Documentation/Licenses/GPLv3.txt for more information. + */ + +#include <SwifTools/URIHandler/MacOSXURIHandler.h> + +#include <Cocoa/Cocoa.h> +#include <iostream> + +using namespace Swift; + +@interface MacOSXURIEventHandler : NSObject { + URIHandler* handler; +} +- (id) initWithHandler: (URIHandler*) handler; +- (void) getUrl: (NSAppleEventDescriptor*) event withReplyEvent: (NSAppleEventDescriptor*) replyEvent; + +@end +@implementation MacOSXURIEventHandler + - (id) initWithHandler: (URIHandler*) h { + if ([super init]) { + handler = h; + } + return self; + } + + - (void) getUrl: (NSAppleEventDescriptor*) event withReplyEvent: (NSAppleEventDescriptor*) replyEvent { + (void) replyEvent; + NSString* url = [[event paramDescriptorForKeyword:keyDirectObject] stringValue]; + handler->onURI(std::string([url UTF8String])); + } +@end + +class MacOSXURIHandler::Private { + public: + MacOSXURIEventHandler* eventHandler; +}; + +MacOSXURIHandler::MacOSXURIHandler() { + p = new Private(); + p->eventHandler = [[MacOSXURIEventHandler alloc] initWithHandler: this]; +} + +MacOSXURIHandler::~MacOSXURIHandler() { + [p->eventHandler release]; + delete p; +} + +void MacOSXURIHandler::start() { + [[NSAppleEventManager sharedAppleEventManager] setEventHandler:p->eventHandler andSelector:@selector(getUrl:withReplyEvent:) forEventClass:kInternetEventClass andEventID:kAEGetURL]; + NSString* bundleID = [[NSBundle mainBundle] bundleIdentifier]; + LSSetDefaultHandlerForURLScheme((CFStringRef)@"xmpp", (CFStringRef)bundleID); +} + +void MacOSXURIHandler::stop() { + [[NSAppleEventManager sharedAppleEventManager] removeEventHandlerForEventClass:kInternetEventClass andEventID:kAEGetURL]; +} diff --git a/Swiften/Elements/JingleTransport.h b/SwifTools/URIHandler/MacOSXURIHandlerHelpers.h index ecd2a34..5a2db7a 100644 --- a/Swiften/Elements/JingleTransport.h +++ b/SwifTools/URIHandler/MacOSXURIHandlerHelpers.h @@ -6,9 +6,6 @@ #pragma once -#include <Swiften/Elements/Payload.h> - namespace Swift { - class JingleTransport : public Payload { - }; + void registerAppAsDefaultXMPPURIHandler(); } diff --git a/SwifTools/URIHandler/MacOSXURIHandlerHelpers.mm b/SwifTools/URIHandler/MacOSXURIHandlerHelpers.mm new file mode 100644 index 0000000..dca91b8 --- /dev/null +++ b/SwifTools/URIHandler/MacOSXURIHandlerHelpers.mm @@ -0,0 +1,16 @@ +/* + * Copyright (c) 2011 Remko Tronçon + * Licensed under the GNU General Public License v3. + * See Documentation/Licenses/GPLv3.txt for more information. + */ + +#include <SwifTools/URIHandler/MacOSXURIHandlerHelpers.h> + +#include <Cocoa/Cocoa.h> + +namespace Swift { + void registerAppAsDefaultXMPPURIHandler() { + NSString* bundleID = [[NSBundle mainBundle] bundleIdentifier]; + LSSetDefaultHandlerForURLScheme((CFStringRef)@"xmpp", (CFStringRef)bundleID); + } +} diff --git a/SwifTools/URIHandler/NullURIHandler.h b/SwifTools/URIHandler/NullURIHandler.h new file mode 100644 index 0000000..28c35bb --- /dev/null +++ b/SwifTools/URIHandler/NullURIHandler.h @@ -0,0 +1,20 @@ +/* + * Copyright (c) 2011 Remko Tronçon + * Licensed under the GNU General Public License v3. + * See Documentation/Licenses/GPLv3.txt for more information. + */ + +#pragma once + +#include <SwifTools/URIHandler/URIHandler.h> + +namespace Swift { + class NullURIHandler : public URIHandler { + public: + virtual void start() { + } + + virtual void stop() { + } + }; +} diff --git a/SwifTools/URIHandler/SConscript b/SwifTools/URIHandler/SConscript new file mode 100644 index 0000000..42c6ca8 --- /dev/null +++ b/SwifTools/URIHandler/SConscript @@ -0,0 +1,23 @@ +Import("swiftools_env", "env") + +sources = [ + "XMPPURI.cpp", + "URIHandler.cpp", + ] + +if swiftools_env["PLATFORM"] == "darwin" and swiftools_env["target"] == "native" : + sources += [ + "MacOSXURIHandler.mm", + "MacOSXURIHandlerHelpers.mm", + ] +elif swiftools_env["PLATFORM"] == "win32" : + sources += [] +else : + sources += [] + +objects = swiftools_env.StaticObject(sources) +swiftools_env.Append(SWIFTOOLS_OBJECTS = [objects]) + +env.Append(UNITTEST_SOURCES = [ + File("UnitTest/XMPPURITest.cpp"), + ]) diff --git a/SwifTools/URIHandler/URIHandler.cpp b/SwifTools/URIHandler/URIHandler.cpp new file mode 100644 index 0000000..91e54e5 --- /dev/null +++ b/SwifTools/URIHandler/URIHandler.cpp @@ -0,0 +1,15 @@ +/* + * Copyright (c) 2011 Remko Tronçon + * Licensed under the GNU General Public License v3. + * See Documentation/Licenses/GPLv3.txt for more information. + */ + +#include <SwifTools/URIHandler/URIHandler.h> + +using namespace Swift; + +URIHandler::URIHandler() { +} + +URIHandler::~URIHandler() { +} diff --git a/SwifTools/URIHandler/URIHandler.h b/SwifTools/URIHandler/URIHandler.h new file mode 100644 index 0000000..9dd13a8 --- /dev/null +++ b/SwifTools/URIHandler/URIHandler.h @@ -0,0 +1,20 @@ +/* + * Copyright (c) 2011 Remko Tronçon + * Licensed under the GNU General Public License v3. + * See Documentation/Licenses/GPLv3.txt for more information. + */ + +#pragma once + +#include <string> +#include <Swiften/Base/boost_bsignals.h> + +namespace Swift { + class URIHandler { + public: + URIHandler(); + virtual ~URIHandler(); + + boost::signal<void (const std::string&)> onURI; + }; +} diff --git a/SwifTools/URIHandler/UnitTest/XMPPURITest.cpp b/SwifTools/URIHandler/UnitTest/XMPPURITest.cpp new file mode 100644 index 0000000..8d03b60 --- /dev/null +++ b/SwifTools/URIHandler/UnitTest/XMPPURITest.cpp @@ -0,0 +1,191 @@ +/* + * Copyright (c) 2011 Remko Tronçon + * Licensed under the GNU General Public License v3. + * See Documentation/Licenses/GPLv3.txt for more information. + */ + +#include <cppunit/extensions/HelperMacros.h> +#include <cppunit/extensions/TestFactoryRegistry.h> + +#include <SwifTools/URIHandler/XMPPURI.h> + +using namespace Swift; + +class XMPPURITest : public CppUnit::TestFixture { + CPPUNIT_TEST_SUITE(XMPPURITest); + CPPUNIT_TEST(testFromString_Authority); + CPPUNIT_TEST(testFromString_AuthorityWithPath); + CPPUNIT_TEST(testFromString_AuthorityWithFragment); + CPPUNIT_TEST(testFromString_AuthorityWithPathAndFragment); + CPPUNIT_TEST(testFromString_AuthorityWithIntlChars); + CPPUNIT_TEST(testFromString_AuthorityWithQueryWithoutParameters); + CPPUNIT_TEST(testFromString_AuthorityWithQueryWithParameters); + CPPUNIT_TEST(testFromString_AuthorityWithQueryWithoutParametersWithFragment); + CPPUNIT_TEST(testFromString_AuthorityWithQueryWithParametersWithFragment); + CPPUNIT_TEST(testFromString_Path); + CPPUNIT_TEST(testFromString_PathWithFragment); + CPPUNIT_TEST(testFromString_PathWithIntlChars); + CPPUNIT_TEST(testFromString_PathWithInvalidEscapedChar); + CPPUNIT_TEST(testFromString_PathWithIncompleteEscapedChar); + CPPUNIT_TEST(testFromString_PathWithIncompleteEscapedChar2); + CPPUNIT_TEST(testFromString_PathWithQueryWithoutParameters); + CPPUNIT_TEST(testFromString_PathWithQueryWithParameters); + CPPUNIT_TEST(testFromString_PathWithQueryWithoutParametersWithFragment); + CPPUNIT_TEST(testFromString_PathWithQueryWithParametersWithFragment); + CPPUNIT_TEST(testFromString_NoPrefix); + CPPUNIT_TEST_SUITE_END(); + + public: + void testFromString_Authority() { + XMPPURI testling = XMPPURI::fromString("xmpp://foo@bar.com"); + + CPPUNIT_ASSERT_EQUAL(JID("foo@bar.com"), testling.getAuthority()); + } + + void testFromString_AuthorityWithPath() { + XMPPURI testling = XMPPURI::fromString("xmpp://foo@bar.com/baz@example.com"); + + CPPUNIT_ASSERT_EQUAL(JID("foo@bar.com"), testling.getAuthority()); + CPPUNIT_ASSERT_EQUAL(JID("baz@example.com"), testling.getPath()); + } + + void testFromString_AuthorityWithFragment() { + XMPPURI testling = XMPPURI::fromString("xmpp://foo@bar.com#myfragment"); + + CPPUNIT_ASSERT_EQUAL(JID("foo@bar.com"), testling.getAuthority()); + CPPUNIT_ASSERT_EQUAL(std::string("myfragment"), testling.getFragment()); + } + + void testFromString_AuthorityWithPathAndFragment() { + XMPPURI testling = XMPPURI::fromString("xmpp://foo@bar.com/baz@example.com#myfragment"); + + CPPUNIT_ASSERT_EQUAL(JID("foo@bar.com"), testling.getAuthority()); + CPPUNIT_ASSERT_EQUAL(JID("baz@example.com"), testling.getPath()); + CPPUNIT_ASSERT_EQUAL(std::string("myfragment"), testling.getFragment()); + } + + void testFromString_AuthorityWithIntlChars() { + XMPPURI testling = XMPPURI::fromString("xmpp://nasty!%23$%25()*+,-.;=\%3F\%5B\%5C\%5D\%5E_\%60\%7B\%7C\%7D~node@example.com"); + + CPPUNIT_ASSERT_EQUAL(JID("nasty!#$\%()*+,-.;=?[\\]^_`{|}~node@example.com"), testling.getAuthority()); + } + + void testFromString_AuthorityWithQueryWithoutParameters() { + XMPPURI testling = XMPPURI::fromString("xmpp://test@example.com?message"); + + CPPUNIT_ASSERT_EQUAL(JID("test@example.com"), testling.getAuthority()); + CPPUNIT_ASSERT_EQUAL(std::string("message"), testling.getQueryType()); + } + + void testFromString_AuthorityWithQueryWithParameters() { + XMPPURI testling = XMPPURI::fromString("xmpp://test@example.com?message;subject=Test%20Message;body=Here%27s%20a%20test%20message"); + + CPPUNIT_ASSERT_EQUAL(JID("test@example.com"), testling.getAuthority()); + CPPUNIT_ASSERT_EQUAL(std::string("message"), testling.getQueryType()); + CPPUNIT_ASSERT_EQUAL(std::string("Test Message"), get(testling.getQueryParameters(), "subject")); + CPPUNIT_ASSERT_EQUAL(std::string("Here's a test message"), get(testling.getQueryParameters(), "body")); + } + + void testFromString_AuthorityWithQueryWithoutParametersWithFragment() { + XMPPURI testling = XMPPURI::fromString("xmpp://test@example.com?message#myfragment"); + + CPPUNIT_ASSERT_EQUAL(JID("test@example.com"), testling.getAuthority()); + CPPUNIT_ASSERT_EQUAL(std::string("message"), testling.getQueryType()); + CPPUNIT_ASSERT_EQUAL(std::string("myfragment"), testling.getFragment()); + } + + void testFromString_AuthorityWithQueryWithParametersWithFragment() { + XMPPURI testling = XMPPURI::fromString("xmpp://test@example.com?message;subject=Test%20Message;body=Here%27s%20a%20test%20message#myfragment"); + + CPPUNIT_ASSERT_EQUAL(JID("test@example.com"), testling.getAuthority()); + CPPUNIT_ASSERT_EQUAL(std::string("message"), testling.getQueryType()); + CPPUNIT_ASSERT_EQUAL(std::string("Test Message"), get(testling.getQueryParameters(), "subject")); + CPPUNIT_ASSERT_EQUAL(std::string("Here's a test message"), get(testling.getQueryParameters(), "body")); + CPPUNIT_ASSERT_EQUAL(std::string("myfragment"), testling.getFragment()); + } + + void testFromString_Path() { + XMPPURI testling = XMPPURI::fromString("xmpp:baz@example.com"); + + CPPUNIT_ASSERT_EQUAL(JID("baz@example.com"), testling.getPath()); + } + + void testFromString_PathWithFragment() { + XMPPURI testling = XMPPURI::fromString("xmpp:baz@example.com#myfragment"); + + CPPUNIT_ASSERT_EQUAL(JID("baz@example.com"), testling.getPath()); + CPPUNIT_ASSERT_EQUAL(std::string("myfragment"), testling.getFragment()); + } + + void testFromString_PathWithIntlChars() { + XMPPURI testling = XMPPURI::fromString("xmpp:nasty!%23$%25()*+,-.;=\%3F\%5B\%5C\%5D\%5E_\%60\%7B\%7C\%7D~node@example.com"); + + CPPUNIT_ASSERT_EQUAL(JID("nasty!#$\%()*+,-.;=?[\\]^_`{|}~node@example.com"), testling.getPath()); + } + + void testFromString_PathWithInvalidEscapedChar() { + XMPPURI testling = XMPPURI::fromString("xmpp:test%%@example.com"); + + CPPUNIT_ASSERT_EQUAL(JID(), testling.getPath()); + } + + void testFromString_PathWithIncompleteEscapedChar() { + XMPPURI testling = XMPPURI::fromString("xmpp:test@example.com%"); + + CPPUNIT_ASSERT_EQUAL(JID(), testling.getPath()); + } + + void testFromString_PathWithIncompleteEscapedChar2() { + XMPPURI testling = XMPPURI::fromString("xmpp:test@example.com%1"); + + CPPUNIT_ASSERT_EQUAL(JID(), testling.getPath()); + } + + void testFromString_PathWithQueryWithoutParameters() { + XMPPURI testling = XMPPURI::fromString("xmpp:test@example.com?message"); + + CPPUNIT_ASSERT_EQUAL(JID("test@example.com"), testling.getPath()); + CPPUNIT_ASSERT_EQUAL(std::string("message"), testling.getQueryType()); + } + + void testFromString_PathWithQueryWithParameters() { + XMPPURI testling = XMPPURI::fromString("xmpp:test@example.com?message;subject=Test%20Message;body=Here%27s%20a%20test%20message"); + + CPPUNIT_ASSERT_EQUAL(JID("test@example.com"), testling.getPath()); + CPPUNIT_ASSERT_EQUAL(std::string("message"), testling.getQueryType()); + CPPUNIT_ASSERT_EQUAL(std::string("Test Message"), get(testling.getQueryParameters(), "subject")); + CPPUNIT_ASSERT_EQUAL(std::string("Here's a test message"), get(testling.getQueryParameters(), "body")); + } + + void testFromString_PathWithQueryWithoutParametersWithFragment() { + XMPPURI testling = XMPPURI::fromString("xmpp:test@example.com?message#myfragment"); + + CPPUNIT_ASSERT_EQUAL(JID("test@example.com"), testling.getPath()); + CPPUNIT_ASSERT_EQUAL(std::string("message"), testling.getQueryType()); + CPPUNIT_ASSERT_EQUAL(std::string("myfragment"), testling.getFragment()); + } + + void testFromString_PathWithQueryWithParametersWithFragment() { + XMPPURI testling = XMPPURI::fromString("xmpp:test@example.com?message;subject=Test%20Message;body=Here%27s%20a%20test%20message#myfragment"); + + CPPUNIT_ASSERT_EQUAL(JID("test@example.com"), testling.getPath()); + CPPUNIT_ASSERT_EQUAL(std::string("message"), testling.getQueryType()); + CPPUNIT_ASSERT_EQUAL(std::string("Test Message"), get(testling.getQueryParameters(), "subject")); + CPPUNIT_ASSERT_EQUAL(std::string("Here's a test message"), get(testling.getQueryParameters(), "body")); + CPPUNIT_ASSERT_EQUAL(std::string("myfragment"), testling.getFragment()); + } + + void testFromString_NoPrefix() { + XMPPURI testling = XMPPURI::fromString("baz@example.com"); + + CPPUNIT_ASSERT(testling.isNull()); + } + + private: + std::string get(const std::map<std::string, std::string>& m, const std::string& k) { + std::map<std::string, std::string>::const_iterator i = m.find(k); + return i == m.end() ? "" : i->second; + } +}; + +CPPUNIT_TEST_SUITE_REGISTRATION(XMPPURITest); diff --git a/SwifTools/URIHandler/XMPPURI.cpp b/SwifTools/URIHandler/XMPPURI.cpp new file mode 100644 index 0000000..de83ac2 --- /dev/null +++ b/SwifTools/URIHandler/XMPPURI.cpp @@ -0,0 +1,144 @@ +/* + * Copyright (c) 2011 Remko Tronçon + * Licensed under the GNU General Public License v3. + * See Documentation/Licenses/GPLv3.txt for more information. + */ + +#include <SwifTools/URIHandler/XMPPURI.h> + +#include <boost/algorithm/string/predicate.hpp> +#include <boost/algorithm/string/find_format.hpp> +#include <boost/algorithm/string/formatter.hpp> +#include <boost/algorithm/string/find_iterator.hpp> +#include <boost/algorithm/string/split.hpp> +#include <boost/algorithm/string/classification.hpp> +#include <sstream> +#include <stdexcept> +#include <vector> + +using namespace Swift; + +// Should be in anonymous namespace, but older GCCs complain if we do that +struct PercentEncodedCharacterFinder { + template<typename Iterator> + boost::iterator_range<Iterator> operator()(Iterator begin, Iterator end) { + boost::iterator_range<Iterator> r = boost::first_finder("%")(begin, end); + if (r.end() == end) { + return r; + } + else { + if (r.end() + 1 == end || r.end() + 2 == end) { + throw std::runtime_error("Incomplete escape character"); + } + else { + r.advance_end(2); + return r; + } + } + } +}; + +struct PercentUnencodeFormatter { + template<typename FindResult> + std::string operator()(const FindResult& match) const { + std::stringstream s; + s << std::hex << std::string(match.begin() + 1, match.end()); + unsigned int value; + s >> value; + if (s.fail() || s.bad()) { + throw std::runtime_error("Invalid escape character"); + } + unsigned char charValue = static_cast<unsigned char>(value); + return std::string(reinterpret_cast<const char*>(&charValue), 1); + } +}; + +namespace { + std::string unescape(const std::string& s) { + try { + return boost::find_format_all_copy(s, PercentEncodedCharacterFinder(), PercentUnencodeFormatter()); + } + catch (const std::exception&) { + return ""; + } + } +} + +XMPPURI::XMPPURI() { +} + +XMPPURI XMPPURI::fromString(const std::string& s) { + XMPPURI result; + if (boost::starts_with(s, "xmpp:")) { + std::string uri = s.substr(5, s.npos); + bool parsePath = true; + bool parseQuery = true; + bool parseFragment = true; + + // Parse authority + if (boost::starts_with(uri, "//")) { + size_t i = uri.find_first_of("/#?", 2); + result.setAuthority(JID(unescape(uri.substr(2, i - 2)))); + if (i == uri.npos) { + uri = ""; + parsePath = parseQuery = parseFragment = false; + } + else { + if (uri[i] == '?') { + parsePath = false; + } + else if (uri[i] == '#') { + parseQuery = parsePath = false; + } + uri = uri.substr(i + 1, uri.npos); + } + } + + // Parse path + if (parsePath) { + size_t i = uri.find_first_of("#?"); + result.setPath(JID(unescape(uri.substr(0, i)))); + if (i == uri.npos) { + uri = ""; + parseQuery = parseFragment = false; + } + else { + if (uri[i] == '#') { + parseQuery = false; + } + uri = uri.substr(i + 1, uri.npos); + } + } + + // Parse query + if (parseQuery) { + size_t end = uri.find_first_of("#"); + std::string query = uri.substr(0, end); + bool haveType = false; + typedef boost::split_iterator<std::string::iterator> split_iterator; + for (split_iterator it = boost::make_split_iterator(query, boost::first_finder(";")); it != split_iterator(); ++it) { + if (haveType) { + std::vector<std::string> keyValue; + boost::split(keyValue, *it, boost::is_any_of("=")); + if (keyValue.size() == 1) { + result.addQueryParameter(unescape(keyValue[0]), ""); + } + else if (keyValue.size() >= 2) { + result.addQueryParameter(unescape(keyValue[0]), unescape(keyValue[1])); + } + } + else { + result.setQueryType(unescape(boost::copy_range<std::string>(*it))); + haveType = true; + } + } + uri = (end == uri.npos ? "" : uri.substr(end + 1, uri.npos)); + } + + // Parse fragment + if (parseFragment) { + result.setFragment(unescape(uri)); + } + } + return result; +} diff --git a/SwifTools/URIHandler/XMPPURI.h b/SwifTools/URIHandler/XMPPURI.h new file mode 100644 index 0000000..266b79b --- /dev/null +++ b/SwifTools/URIHandler/XMPPURI.h @@ -0,0 +1,72 @@ +/* + * Copyright (c) 2011 Remko Tronçon + * Licensed under the GNU General Public License v3. + * See Documentation/Licenses/GPLv3.txt for more information. + */ + +#pragma once + +#include <string> +#include <map> + +#include <Swiften/JID/JID.h> + +namespace Swift { + class XMPPURI { + public: + XMPPURI(); + + const JID& getAuthority() const { + return authority; + } + + void setAuthority(const JID& j) { + authority = j; + } + + const JID& getPath() const { + return path; + } + + void setPath(const JID& j) { + path = j; + } + + const std::string& getQueryType() const { + return queryType; + } + + void setQueryType(const std::string& q) { + queryType = q; + } + + const std::map<std::string, std::string>& getQueryParameters() const { + return queryParameters; + } + + void addQueryParameter(const std::string& key, const std::string& path) { + queryParameters[key] = path; + } + + const std::string& getFragment() const { + return fragment; + } + + void setFragment(const std::string& f) { + fragment = f; + } + + bool isNull() const { + return !authority.isValid() && !path.isValid(); + } + + static XMPPURI fromString(const std::string&); + + private: + JID authority; + JID path; + std::string fragment; + std::string queryType; + std::map<std::string, std::string> queryParameters; + }; +} diff --git a/SwifTools/UnitTest/LastLineTrackerTest.cpp b/SwifTools/UnitTest/LastLineTrackerTest.cpp new file mode 100644 index 0000000..a7046ed --- /dev/null +++ b/SwifTools/UnitTest/LastLineTrackerTest.cpp @@ -0,0 +1,64 @@ +/* + * Copyright (c) 2011 Vlad Voicu + * Licensed under the Simplified BSD license. + * See Documentation/Licenses/BSD-simplified.txt for more information. + */ + +#include <cppunit/extensions/HelperMacros.h> +#include <cppunit/extensions/TestFactoryRegistry.h> + +#include <SwifTools/LastLineTracker.h> + +using namespace Swift; + +class LastLineTrackerTest : public CppUnit::TestFixture { + CPPUNIT_TEST_SUITE(LastLineTrackerTest); + CPPUNIT_TEST(testFocusNormal); + CPPUNIT_TEST(testFocusOut); + CPPUNIT_TEST(testFocusOtherTab); + CPPUNIT_TEST(testRepeatedFocusOut); + CPPUNIT_TEST(testRepeatedFocusIn); + CPPUNIT_TEST_SUITE_END(); + public: + LastLineTrackerTest () { + }; + void testFocusNormal() { + LastLineTracker testling; + testling.setHasFocus(true); + CPPUNIT_ASSERT_EQUAL(false, testling.getShouldMoveLastLine()); + } + void testFocusOut() { + LastLineTracker testling; + testling.setHasFocus(false); + CPPUNIT_ASSERT_EQUAL(true, testling.getShouldMoveLastLine()); + CPPUNIT_ASSERT_EQUAL(false, testling.getShouldMoveLastLine()); + CPPUNIT_ASSERT_EQUAL(false, testling.getShouldMoveLastLine()); + } + void testFocusOtherTab() { + LastLineTracker testling; + testling.setHasFocus(true); + testling.setHasFocus(false); + CPPUNIT_ASSERT_EQUAL(true, testling.getShouldMoveLastLine()); + CPPUNIT_ASSERT_EQUAL(false, testling.getShouldMoveLastLine()); + } + + void testRepeatedFocusOut() { + LastLineTracker testling; + testling.setHasFocus(true); + CPPUNIT_ASSERT_EQUAL(false, testling.getShouldMoveLastLine()); + testling.setHasFocus(false); + CPPUNIT_ASSERT_EQUAL(true, testling.getShouldMoveLastLine()); + testling.setHasFocus(false); + CPPUNIT_ASSERT_EQUAL(false, testling.getShouldMoveLastLine()); + } + void testRepeatedFocusIn() { + LastLineTracker testling; + testling.setHasFocus(false); + CPPUNIT_ASSERT_EQUAL(true, testling.getShouldMoveLastLine()); + testling.setHasFocus(true); + testling.setHasFocus(false); + CPPUNIT_ASSERT_EQUAL(true, testling.getShouldMoveLastLine()); + } +}; + +CPPUNIT_TEST_SUITE_REGISTRATION(LastLineTrackerTest); diff --git a/SwifTools/UnitTest/LinkifyTest.cpp b/SwifTools/UnitTest/LinkifyTest.cpp index f7e2a37..3d0ce00 100644 --- a/SwifTools/UnitTest/LinkifyTest.cpp +++ b/SwifTools/UnitTest/LinkifyTest.cpp @@ -7,7 +7,7 @@ #include <cppunit/extensions/HelperMacros.h> #include <cppunit/extensions/TestFactoryRegistry.h> -#include "SwifTools/Linkify.h" +#include <SwifTools/Linkify.h> using namespace Swift; diff --git a/SwifTools/UnitTest/SConscript b/SwifTools/UnitTest/SConscript index 8034905..e469deb 100644 --- a/SwifTools/UnitTest/SConscript +++ b/SwifTools/UnitTest/SConscript @@ -2,5 +2,6 @@ Import("env") env.Append(UNITTEST_SOURCES = [ File("LinkifyTest.cpp"), - File("TabCompleteTest.cpp") + File("TabCompleteTest.cpp"), + File("LastLineTrackerTest.cpp"), ]) diff --git a/SwifTools/UnitTest/TabCompleteTest.cpp b/SwifTools/UnitTest/TabCompleteTest.cpp index 2224839..0466484 100644 --- a/SwifTools/UnitTest/TabCompleteTest.cpp +++ b/SwifTools/UnitTest/TabCompleteTest.cpp @@ -7,7 +7,7 @@ #include <cppunit/extensions/HelperMacros.h> #include <cppunit/extensions/TestFactoryRegistry.h> -#include "SwifTools/TabComplete.h" +#include <SwifTools/TabComplete.h> using namespace Swift; diff --git a/Swift/Controllers/AdHocManager.cpp b/Swift/Controllers/AdHocManager.cpp new file mode 100644 index 0000000..0fa63a1 --- /dev/null +++ b/Swift/Controllers/AdHocManager.cpp @@ -0,0 +1,69 @@ +/* + * Copyright (c) 2010-2011 Kevin Smith + * Licensed under the GNU General Public License v3. + * See Documentation/Licenses/GPLv3.txt for more information. + */ + +#include <Swift/Controllers/AdHocManager.h> + +#include <boost/bind.hpp> +#include <boost/shared_ptr.hpp> + +#include <Swiften/Base/foreach.h> +#include <Swiften/Queries/IQRouter.h> +#include <Swiften/AdHoc/OutgoingAdHocCommandSession.h> +#include <Swift/Controllers/UIInterfaces/MainWindow.h> +#include <Swift/Controllers/UIInterfaces/AdHocCommandWindowFactory.h> +#include <Swift/Controllers/UIEvents/UIEventStream.h> +#include <Swift/Controllers/UIEvents/RequestAdHocUIEvent.h> + +namespace Swift { + +AdHocManager::AdHocManager(const JID& jid, AdHocCommandWindowFactory* factory, IQRouter* iqRouter, UIEventStream* uiEventStream, MainWindow* mainWindow) : jid_(jid) { + iqRouter_ = iqRouter; + uiEventStream_ = uiEventStream; + mainWindow_ = mainWindow; + factory_ = factory; + + uiEventStream_->onUIEvent.connect(boost::bind(&AdHocManager::handleUIEvent, this, _1)); +} + +AdHocManager::~AdHocManager() { + uiEventStream_->onUIEvent.disconnect(boost::bind(&AdHocManager::handleUIEvent, this, _1)); +} + +void AdHocManager::setServerDiscoInfo(boost::shared_ptr<DiscoInfo> info) { + if (iqRouter_->isAvailable() && info->hasFeature(DiscoInfo::CommandsFeature)) { + if (discoItemsRequest_) { + discoItemsRequest_->onResponse.disconnect(boost::bind(&AdHocManager::handleServerDiscoItemsResponse, this, _1, _2)); + discoItemsRequest_.reset(); + } + discoItemsRequest_ = GetDiscoItemsRequest::create(JID(jid_.getDomain()), DiscoInfo::CommandsFeature, iqRouter_); + discoItemsRequest_->onResponse.connect(boost::bind(&AdHocManager::handleServerDiscoItemsResponse, this, _1, _2)); + discoItemsRequest_->send(); + } else { + mainWindow_->setAvailableAdHocCommands(std::vector<DiscoItems::Item>()); + } + +} + +void AdHocManager::handleServerDiscoItemsResponse(boost::shared_ptr<DiscoItems> items, ErrorPayload::ref error) { + std::vector<DiscoItems::Item> commands; + if (!error) { + foreach (DiscoItems::Item item, items->getItems()) { + if (item.getNode() != "http://isode.com/xmpp/commands#test") { + commands.push_back(item); + } + } + } + mainWindow_->setAvailableAdHocCommands(commands); +} + +void AdHocManager::handleUIEvent(boost::shared_ptr<UIEvent> event) { + boost::shared_ptr<RequestAdHocUIEvent> adHocEvent = boost::dynamic_pointer_cast<RequestAdHocUIEvent>(event); + if (adHocEvent) { + factory_->createAdHocCommandWindow(boost::shared_ptr<OutgoingAdHocCommandSession>(new OutgoingAdHocCommandSession(adHocEvent->getCommand(), factory_, iqRouter_))); + } +} + +} diff --git a/Swift/Controllers/AdHocManager.h b/Swift/Controllers/AdHocManager.h new file mode 100644 index 0000000..47b03cd --- /dev/null +++ b/Swift/Controllers/AdHocManager.h @@ -0,0 +1,40 @@ +/* + * Copyright (c) 2010-2011 Kevin Smith + * Licensed under the GNU General Public License v3. + * See Documentation/Licenses/GPLv3.txt for more information. + */ + +#pragma once + +#include <boost/shared_ptr.hpp> +#include <vector> + +#include <Swiften/Base/boost_bsignals.h> +#include <Swiften/JID/JID.h> +#include <Swiften/Elements/DiscoInfo.h> +#include <Swiften/Elements/DiscoItems.h> +#include <Swiften/Elements/ErrorPayload.h> +#include <Swiften/Disco/GetDiscoItemsRequest.h> +#include <Swift/Controllers/UIEvents/UIEvent.h> + +namespace Swift { + class IQRouter; + class MainWindow; + class UIEventStream; + class AdHocCommandWindowFactory; + class AdHocManager { + public: + AdHocManager(const JID& jid, AdHocCommandWindowFactory* factory, IQRouter* iqRouter, UIEventStream* uiEventStream, MainWindow* mainWindow); + ~AdHocManager(); + void setServerDiscoInfo(boost::shared_ptr<DiscoInfo> info); + private: + void handleUIEvent(boost::shared_ptr<UIEvent> event); + void handleServerDiscoItemsResponse(boost::shared_ptr<DiscoItems>, ErrorPayload::ref error); + JID jid_; + IQRouter* iqRouter_; + UIEventStream* uiEventStream_; + MainWindow* mainWindow_; + AdHocCommandWindowFactory* factory_; + GetDiscoItemsRequest::ref discoItemsRequest_; + }; +} diff --git a/Swift/Controllers/CertificateMemoryStorageFactory.h b/Swift/Controllers/CertificateMemoryStorageFactory.h new file mode 100644 index 0000000..adbce80 --- /dev/null +++ b/Swift/Controllers/CertificateMemoryStorageFactory.h @@ -0,0 +1,28 @@ +/* + * Copyright (c) 2011 Remko Tronçon + * Licensed under the GNU General Public License v3. + * See Documentation/Licenses/GPLv3.txt for more information. + */ + +#pragma once + +#include <Swift/Controllers/Storages/CertificateStorageFactory.h> +#include <Swift/Controllers/Storages/CertificateMemoryStorage.h> + +namespace Swift { + class CertificateFactory; + + class CertificateMemoryStorageFactory : public CertificateStorageFactory { + public: + CertificateMemoryStorageFactory() { + } + + virtual CertificateStorage* createCertificateStorage(const JID&) const { + return new CertificateMemoryStorage(); + } + + private: + boost::filesystem::path basePath; + CertificateFactory* certificateFactory; + }; +} diff --git a/Swift/Controllers/Chat/ChatController.cpp b/Swift/Controllers/Chat/ChatController.cpp index 22ef68d..9767f8d 100644 --- a/Swift/Controllers/Chat/ChatController.cpp +++ b/Swift/Controllers/Chat/ChatController.cpp @@ -102,8 +102,23 @@ void ChatController::preHandleIncomingMessage(boost::shared_ptr<MessageEvent> me setToJID(from); } } - chatStateNotifier_->receivedMessageFromContact(message->getPayload<ChatState>()); + boost::shared_ptr<Replace> replace = message->getPayload<Replace>(); + if (replace) { + // Determine the timestamp + boost::posix_time::ptime timeStamp = boost::posix_time::microsec_clock::universal_time(); + boost::optional<boost::posix_time::ptime> messageTimeStamp = getMessageTimestamp(message); + if (messageTimeStamp) { + timeStamp = *messageTimeStamp; + } + std::string body = message->getBody(); + chatWindow_->replaceMessage(body, lastMessageUIID_, timeStamp); + replacedMessage_ = true; + } + else { + replacedMessage_ = false; + } chatStateTracker_->handleMessageReceived(message); + chatStateNotifier_->receivedMessageFromContact(message->getPayload<ChatState>()); } void ChatController::postHandleIncomingMessage(boost::shared_ptr<MessageEvent> messageEvent) { @@ -116,21 +131,30 @@ void ChatController::preSendMessageRequest(boost::shared_ptr<Message> message) { } void ChatController::postSendMessage(const std::string& body, boost::shared_ptr<Stanza> sentStanza) { - std::string id = addMessage(body, QT_TRANSLATE_NOOP("", "me"), true, labelsEnabled_ ? chatWindow_->getSelectedSecurityLabel().getLabel() : boost::shared_ptr<SecurityLabel>(), std::string(avatarManager_->getAvatarPath(selfJID_).string()), boost::posix_time::microsec_clock::universal_time()); - if (stanzaChannel_->getStreamManagementEnabled()) { - chatWindow_->setAckState(id, ChatWindow::Pending); - unackedStanzas_[sentStanza] = id; + if (stanzaChannel_->getStreamManagementEnabled() && !myLastMessageUIID_.empty()) { + chatWindow_->setAckState(myLastMessageUIID_, ChatWindow::Pending); + unackedStanzas_[sentStanza] = myLastMessageUIID_; + } + boost::shared_ptr<Replace> replace = sentStanza->getPayload<Replace>(); + if (replace) { + chatWindow_->replaceMessage(body, myLastMessageUIID_, boost::posix_time::microsec_clock::universal_time()); + } else { + myLastMessageUIID_ = addMessage(body, QT_TRANSLATE_NOOP("", "me"), true, labelsEnabled_ ? chatWindow_->getSelectedSecurityLabel().getLabel() : boost::shared_ptr<SecurityLabel>(), std::string(avatarManager_->getAvatarPath(selfJID_).string()), boost::posix_time::microsec_clock::universal_time()); + if (stanzaChannel_->getStreamManagementEnabled()) { + chatWindow_->setAckState(myLastMessageUIID_, ChatWindow::Pending); + unackedStanzas_[sentStanza] = myLastMessageUIID_; + } } lastWasPresence_ = false; chatStateNotifier_->userSentMessage(); } void ChatController::handleStanzaAcked(boost::shared_ptr<Stanza> stanza) { - std::string id = unackedStanzas_[stanza]; - if (id != "") { - chatWindow_->setAckState(id, ChatWindow::Received); + std::map<boost::shared_ptr<Stanza>, std::string>::iterator unackedStanza = unackedStanzas_.find(stanza); + if (unackedStanza != unackedStanzas_.end()) { + chatWindow_->setAckState(unackedStanza->second, ChatWindow::Received); + unackedStanzas_.erase(unackedStanza); } - unackedStanzas_.erase(unackedStanzas_.find(stanza)); } void ChatController::setOnline(bool online) { diff --git a/Swift/Controllers/Chat/ChatController.h b/Swift/Controllers/Chat/ChatController.h index dd4bf90..4fafb44 100644 --- a/Swift/Controllers/Chat/ChatController.h +++ b/Swift/Controllers/Chat/ChatController.h @@ -40,6 +40,7 @@ namespace Swift { NickResolver* nickResolver_; ChatStateNotifier* chatStateNotifier_; ChatStateTracker* chatStateTracker_; + std::string myLastMessageUIID_; bool isInMUC_; bool lastWasPresence_; std::string lastStatusChangeString_; diff --git a/Swift/Controllers/Chat/ChatControllerBase.cpp b/Swift/Controllers/Chat/ChatControllerBase.cpp index 281d968..14e17cd 100644 --- a/Swift/Controllers/Chat/ChatControllerBase.cpp +++ b/Swift/Controllers/Chat/ChatControllerBase.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2010 Kevin Smith + * Copyright (c) 2010-2011 Kevin Smith * Licensed under the GNU General Public License v3. * See Documentation/Licenses/GPLv3.txt for more information. */ @@ -30,9 +30,10 @@ namespace Swift { ChatControllerBase::ChatControllerBase(const JID& self, StanzaChannel* stanzaChannel, IQRouter* iqRouter, ChatWindowFactory* chatWindowFactory, const JID &toJID, PresenceOracle* presenceOracle, AvatarManager* avatarManager, bool useDelayForLatency, UIEventStream* eventStream, EventController* eventController, TimerFactory* timerFactory) : selfJID_(self), stanzaChannel_(stanzaChannel), iqRouter_(iqRouter), chatWindowFactory_(chatWindowFactory), toJID_(toJID), labelsEnabled_(false), presenceOracle_(presenceOracle), avatarManager_(avatarManager), useDelayForLatency_(useDelayForLatency), eventController_(eventController), timerFactory_(timerFactory) { chatWindow_ = chatWindowFactory_->createChatWindow(toJID, eventStream); chatWindow_->onAllMessagesRead.connect(boost::bind(&ChatControllerBase::handleAllMessagesRead, this)); - chatWindow_->onSendMessageRequest.connect(boost::bind(&ChatControllerBase::handleSendMessageRequest, this, _1)); + chatWindow_->onSendMessageRequest.connect(boost::bind(&ChatControllerBase::handleSendMessageRequest, this, _1, _2)); setOnline(stanzaChannel->isAvailable() && iqRouter->isAvailable()); createDayChangeTimer(); + replacedMessage_ = false; } ChatControllerBase::~ChatControllerBase() { @@ -88,7 +89,7 @@ void ChatControllerBase::handleAllMessagesRead() { chatWindow_->setUnreadMessageCount(0); } -void ChatControllerBase::handleSendMessageRequest(const std::string &body) { +void ChatControllerBase::handleSendMessageRequest(const std::string &body, bool isCorrectionMessage) { if (!stanzaChannel_->isAvailable() || body.empty()) { return; } @@ -104,8 +105,13 @@ void ChatControllerBase::handleSendMessageRequest(const std::string &body) { boost::posix_time::ptime now = boost::posix_time::microsec_clock::universal_time(); message->addPayload(boost::shared_ptr<Delay>(new Delay(now, selfJID_))); } + if (isCorrectionMessage) { + message->addPayload(boost::shared_ptr<Replace> (new Replace(lastSentMessageStanzaID_))); + } + message->setID(lastSentMessageStanzaID_ = idGenerator_.generateID()); stanzaChannel_->sendMessage(message); postSendMessage(message->getBody(), boost::dynamic_pointer_cast<Stanza>(message)); + onActivity(message->getBody()); } void ChatControllerBase::handleSecurityLabelsCatalogResponse(boost::shared_ptr<SecurityLabelsCatalog> catalog, ErrorPayload::ref error) { @@ -163,7 +169,7 @@ void ChatControllerBase::handleIncomingMessage(boost::shared_ptr<MessageEvent> m JID from = message->getFrom(); std::vector<boost::shared_ptr<Delay> > delayPayloads = message->getPayloads<Delay>(); for (size_t i = 0; useDelayForLatency_ && i < delayPayloads.size(); i++) { - if (!delayPayloads[i]->getFrom()) { + if (!delayPayloads[i]->getFrom()) { continue; } boost::posix_time::ptime now = boost::posix_time::microsec_clock::universal_time(); @@ -179,8 +185,10 @@ void ChatControllerBase::handleIncomingMessage(boost::shared_ptr<MessageEvent> m if (messageTimeStamp) { timeStamp = *messageTimeStamp; } - - addMessage(body, senderDisplayNameFromMessage(from), isIncomingMessageFromMe(message), label, std::string(avatarManager_->getAvatarPath(from).string()), timeStamp); + onActivity(body); + if (!replacedMessage_) { + lastMessageUIID_ = addMessage(body, senderDisplayNameFromMessage(from), isIncomingMessageFromMe(message), label, std::string(avatarManager_->getAvatarPath(from).string()), timeStamp); + } } chatWindow_->show(); chatWindow_->setUnreadMessageCount(unreadMessages_.size()); diff --git a/Swift/Controllers/Chat/ChatControllerBase.h b/Swift/Controllers/Chat/ChatControllerBase.h index 9573b1b..e0f1b94 100644 --- a/Swift/Controllers/Chat/ChatControllerBase.h +++ b/Swift/Controllers/Chat/ChatControllerBase.h @@ -26,6 +26,7 @@ #include "Swiften/Elements/ErrorPayload.h" #include "Swiften/Presence/PresenceOracle.h" #include "Swiften/Queries/IQRouter.h" +#include "Swiften/Base/IDGenerator.h" namespace Swift { class IQRouter; @@ -47,6 +48,8 @@ namespace Swift { virtual void setOnline(bool online); virtual void setEnabled(bool enabled); virtual void setToJID(const JID& jid) {toJID_ = jid;}; + /** Used for determining when something is recent.*/ + boost::signal<void (const std::string& /*activity*/)> onActivity; protected: ChatControllerBase(const JID& self, StanzaChannel* stanzaChannel, IQRouter* iqRouter, ChatWindowFactory* chatWindowFactory, const JID &toJID, PresenceOracle* presenceOracle, AvatarManager* avatarManager, bool useDelayForLatency, UIEventStream* eventStream, EventController* eventController, TimerFactory* timerFactory); @@ -64,8 +67,10 @@ namespace Swift { virtual void dayTicked() {}; private: + IDGenerator idGenerator_; + std::string lastSentMessageStanzaID_; void createDayChangeTimer(); - void handleSendMessageRequest(const std::string &body); + void handleSendMessageRequest(const std::string &body, bool isCorrectionMessage); void handleAllMessagesRead(); void handleSecurityLabelsCatalogResponse(boost::shared_ptr<SecurityLabelsCatalog>, ErrorPayload::ref error); std::string getErrorMessage(boost::shared_ptr<ErrorPayload>); @@ -80,6 +85,8 @@ namespace Swift { ChatWindow* chatWindow_; JID toJID_; bool labelsEnabled_; + bool replacedMessage_; + std::string lastMessageUIID_; PresenceOracle* presenceOracle_; AvatarManager* avatarManager_; bool useDelayForLatency_; diff --git a/Swift/Controllers/Chat/ChatsManager.cpp b/Swift/Controllers/Chat/ChatsManager.cpp index 94d4b9a..b60f9a3 100644 --- a/Swift/Controllers/Chat/ChatsManager.cpp +++ b/Swift/Controllers/Chat/ChatsManager.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2010 Kevin Smith + * Copyright (c) 2010-2011 Kevin Smith * Licensed under the GNU General Public License v3. * See Documentation/Licenses/GPLv3.txt for more information. */ @@ -7,7 +7,9 @@ #include "Swift/Controllers/Chat/ChatsManager.h" #include <boost/bind.hpp> +#include <boost/algorithm/string.hpp> +#include <Swiften/Base/foreach.h> #include "Swift/Controllers/Chat/ChatController.h" #include "Swift/Controllers/Chat/MUCSearchController.h" #include "Swift/Controllers/XMPPEvents/EventController.h" @@ -26,12 +28,15 @@ #include "Swiften/MUC/MUCManager.h" #include "Swiften/Elements/ChatState.h" #include "Swiften/MUC/MUCBookmarkManager.h" +#include <Swift/Controllers/ProfileSettingsProvider.h> namespace Swift { typedef std::pair<JID, ChatController*> JIDChatControllerPair; typedef std::pair<JID, MUCController*> JIDMUCControllerPair; +#define RECENT_CHATS "recent_chats" + ChatsManager::ChatsManager( JID jid, StanzaChannel* stanzaChannel, IQRouter* iqRouter, @@ -49,7 +54,7 @@ ChatsManager::ChatsManager( EntityCapsProvider* entityCapsProvider, MUCManager* mucManager, MUCSearchWindowFactory* mucSearchWindowFactory, - SettingsProvider* settings) : + ProfileSettingsProvider* settings) : jid_(jid), joinMUCWindowFactory_(joinMUCWindowFactory), useDelayForLatency_(useDelayForLatency), @@ -68,6 +73,7 @@ ChatsManager::ChatsManager( presenceSender_ = presenceSender; uiEventStream_ = uiEventStream; mucBookmarkManager_ = NULL; + profileSettings_ = settings; presenceOracle_->onPresenceChange.connect(boost::bind(&ChatsManager::handlePresenceChange, this, _1)); uiEventConnection_ = uiEventStream_->onUIEvent.connect(boost::bind(&ChatsManager::handleUIEvent, this, _1)); chatListWindow_ = chatListWindowFactory->createChatListWindow(uiEventStream_); @@ -75,6 +81,7 @@ ChatsManager::ChatsManager( mucSearchController_ = new MUCSearchController(jid_, mucSearchWindowFactory, iqRouter, settings); mucSearchController_->onMUCSelected.connect(boost::bind(&ChatsManager::handleMUCSelectedAfterSearch, this, _1)); setupBookmarks(); + loadRecents(); } ChatsManager::~ChatsManager() { @@ -89,6 +96,44 @@ ChatsManager::~ChatsManager() { delete mucSearchController_; } +void ChatsManager::saveRecents() { + std::string recents; + foreach (ChatListWindow::Chat chat, recentChats_) { + std::vector<std::string> activity; + boost::split(activity, chat.activity, boost::is_any_of("\t\n")); + std::string recent = chat.jid.toString() + "\t" + activity[0] + "\t" + (chat.isMUC ? "true" : "false") + "\t" + chat.nick; + recents += recent + "\n"; + } + profileSettings_->storeString(RECENT_CHATS, recents); +} + +void ChatsManager::loadRecents() { + std::string recentsString(profileSettings_->getStringSetting(RECENT_CHATS)); + std::vector<std::string> recents; + boost::split(recents, recentsString, boost::is_any_of("\n")); + int i = 0; + foreach (std::string recentString, recents) { + if (i++ > 30) { + break; + } + std::vector<std::string> recent; + boost::split(recent, recentString, boost::is_any_of("\t")); + if (recent.size() < 4) { + continue; + } + JID jid(recent[0]); + if (!jid.isValid()) { + continue; + } + std::string activity(recent[1]); + bool isMUC = recent[2] == "true"; + std::string nick(recent[3]); + ChatListWindow::Chat chat(jid, nickResolver_->jidToNick(jid), activity, isMUC, nick); + recentChats_.push_back(chat); + chatListWindow_->setRecents(recentChats_); + } +} + void ChatsManager::setupBookmarks() { if (!mucBookmarkManager_) { mucBookmarkManager_ = new MUCBookmarkManager(iqRouter_); @@ -98,7 +143,7 @@ void ChatsManager::setupBookmarks() { if (chatListWindow_) { chatListWindow_->setBookmarksEnabled(false); - chatListWindow_->clear(); + chatListWindow_->clearBookmarks(); } } } @@ -122,6 +167,16 @@ void ChatsManager::handleMUCBookmarkRemoved(const MUCBookmark& bookmark) { chatListWindow_->removeMUCBookmark(bookmark); } +void ChatsManager::handleChatActivity(const JID& jid, const std::string& activity) { + /* FIXME: MUC use requires changes here. */ + ChatListWindow::Chat chat(jid, nickResolver_->jidToNick(jid), activity, false); + /* FIXME: handle nick changes */ + recentChats_.erase(std::remove(recentChats_.begin(), recentChats_.end(), chat), recentChats_.end()); + recentChats_.push_front(chat); + chatListWindow_->setRecents(recentChats_); + saveRecents(); +} + void ChatsManager::handleUserLeftMUC(MUCController* mucController) { std::map<JID, MUCController*>::iterator it; for (it = mucControllers_.begin(); it != mucControllers_.end(); it++) { @@ -157,13 +212,13 @@ void ChatsManager::handleUIEvent(boost::shared_ptr<UIEvent> event) { else if (JoinMUCUIEvent::ref joinEvent = boost::dynamic_pointer_cast<JoinMUCUIEvent>(event)) { handleJoinMUCRequest(joinEvent->getJID(), joinEvent->getNick(), false); } - else if (boost::dynamic_pointer_cast<RequestJoinMUCUIEvent>(event)) { + else if (boost::shared_ptr<RequestJoinMUCUIEvent> joinEvent = boost::dynamic_pointer_cast<RequestJoinMUCUIEvent>(event)) { if (!joinMUCWindow_) { joinMUCWindow_ = joinMUCWindowFactory_->createJoinMUCWindow(); joinMUCWindow_->onJoinMUC.connect(boost::bind(&ChatsManager::handleJoinMUCRequest, this, _1, _2, _3)); joinMUCWindow_->onSearchMUC.connect(boost::bind(&ChatsManager::handleSearchMUCRequest, this)); } - joinMUCWindow_->setMUC(""); + joinMUCWindow_->setMUC(joinEvent->getRoom()); joinMUCWindow_->setNick(nickResolver_->jidToNick(jid_)); joinMUCWindow_->show(); } @@ -244,6 +299,7 @@ ChatController* ChatsManager::createNewChatController(const JID& contact) { ChatController* controller = new ChatController(jid_, stanzaChannel_, iqRouter_, chatWindowFactory_, contact, nickResolver_, presenceOracle_, avatarManager_, mucRegistry_->isMUC(contact.toBare()), useDelayForLatency_, uiEventStream_, eventController_, timerFactory_, entityCapsProvider_); chatControllers_[contact] = controller; controller->setAvailableServerFeatures(serverDiscoInfo_); + controller->onActivity.connect(boost::bind(&ChatsManager::handleChatActivity, this, contact, _1)); return controller; } @@ -302,6 +358,7 @@ void ChatsManager::handleJoinMUCRequest(const JID &mucJID, const boost::optional controller->onUserLeft.connect(boost::bind(&ChatsManager::handleUserLeftMUC, this, controller)); } mucControllers_[mucJID]->activateChatWindow(); + /* FIXME: handleChatActivity connection for recents, and changes to that method.*/ } void ChatsManager::handleSearchMUCRequest() { diff --git a/Swift/Controllers/Chat/ChatsManager.h b/Swift/Controllers/Chat/ChatsManager.h index 3740186..f489034 100644 --- a/Swift/Controllers/Chat/ChatsManager.h +++ b/Swift/Controllers/Chat/ChatsManager.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2010 Kevin Smith + * Copyright (c) 2010-2011 Kevin Smith * Licensed under the GNU General Public License v3. * See Documentation/Licenses/GPLv3.txt for more information. */ @@ -11,13 +11,14 @@ #include <boost/shared_ptr.hpp> #include <string> -#include "Swiften/Elements/DiscoInfo.h" -#include "Swiften/Elements/Message.h" -#include "Swiften/Elements/Presence.h" -#include "Swiften/JID/JID.h" -#include "Swiften/MUC/MUCRegistry.h" -#include "Swift/Controllers/UIEvents/UIEventStream.h" -#include "Swiften/MUC/MUCBookmark.h" +#include <Swiften/Elements/DiscoInfo.h> +#include <Swiften/Elements/Message.h> +#include <Swiften/Elements/Presence.h> +#include <Swiften/JID/JID.h> +#include <Swiften/MUC/MUCRegistry.h> +#include <Swift/Controllers/UIEvents/UIEventStream.h> +#include <Swift/Controllers/UIInterfaces/ChatListWindow.h> +#include <Swiften/MUC/MUCBookmark.h> namespace Swift { class EventController; @@ -34,18 +35,17 @@ namespace Swift { class IQRouter; class PresenceSender; class MUCBookmarkManager; - class ChatListWindow; class ChatListWindowFactory; class TimerFactory; class EntityCapsProvider; class DirectedPresenceSender; class MUCSearchWindowFactory; - class SettingsProvider; + class ProfileSettingsProvider; class MUCSearchController; class ChatsManager { public: - ChatsManager(JID jid, StanzaChannel* stanzaChannel, IQRouter* iqRouter, EventController* eventController, ChatWindowFactory* chatWindowFactory, JoinMUCWindowFactory* joinMUCWindowFactory, NickResolver* nickResolver, PresenceOracle* presenceOracle, PresenceSender* presenceSender, UIEventStream* uiEventStream, ChatListWindowFactory* chatListWindowFactory, bool useDelayForLatency, TimerFactory* timerFactory, MUCRegistry* mucRegistry, EntityCapsProvider* entityCapsProvider, MUCManager* mucManager, MUCSearchWindowFactory* mucSearchWindowFactory, SettingsProvider* settings); + ChatsManager(JID jid, StanzaChannel* stanzaChannel, IQRouter* iqRouter, EventController* eventController, ChatWindowFactory* chatWindowFactory, JoinMUCWindowFactory* joinMUCWindowFactory, NickResolver* nickResolver, PresenceOracle* presenceOracle, PresenceSender* presenceSender, UIEventStream* uiEventStream, ChatListWindowFactory* chatListWindowFactory, bool useDelayForLatency, TimerFactory* timerFactory, MUCRegistry* mucRegistry, EntityCapsProvider* entityCapsProvider, MUCManager* mucManager, MUCSearchWindowFactory* mucSearchWindowFactory, ProfileSettingsProvider* settings); virtual ~ChatsManager(); void setAvatarManager(AvatarManager* avatarManager); void setOnline(bool enabled); @@ -63,7 +63,11 @@ namespace Swift { void handleMUCBookmarkRemoved(const MUCBookmark& bookmark); void handleUserLeftMUC(MUCController* mucController); void handleBookmarksReady(); + void handleChatActivity(const JID& jid, const std::string& activity); void setupBookmarks(); + void loadRecents(); + void saveRecents(); + void handleChatMadeRecent(); ChatController* getChatControllerOrFindAnother(const JID &contact); ChatController* createNewChatController(const JID &contact); ChatController* getChatControllerOrCreate(const JID &contact); @@ -92,5 +96,7 @@ namespace Swift { EntityCapsProvider* entityCapsProvider_; MUCManager* mucManager; MUCSearchController* mucSearchController_; + std::list<ChatListWindow::Chat> recentChats_; + ProfileSettingsProvider* profileSettings_; }; } diff --git a/Swift/Controllers/Chat/MUCController.cpp b/Swift/Controllers/Chat/MUCController.cpp index 2914116..3c6f965 100644 --- a/Swift/Controllers/Chat/MUCController.cpp +++ b/Swift/Controllers/Chat/MUCController.cpp @@ -4,7 +4,7 @@ * See Documentation/Licenses/GPLv3.txt for more information. */ -#include "Swift/Controllers/Chat/MUCController.h" +#include <Swift/Controllers/Chat/MUCController.h> #include <boost/bind.hpp> #include <boost/regex.hpp> @@ -12,23 +12,24 @@ #include <Swift/Controllers/Intl.h> #include <Swiften/Base/format.h> -#include "Swiften/Network/Timer.h" -#include "Swiften/Network/TimerFactory.h" -#include "Swiften/Base/foreach.h" -#include "SwifTools/TabComplete.h" -#include "Swiften/Base/foreach.h" -#include "Swift/Controllers/XMPPEvents/EventController.h" -#include "Swift/Controllers/UIInterfaces/ChatWindow.h" -#include "Swift/Controllers/UIInterfaces/ChatWindowFactory.h" -#include "Swift/Controllers/UIEvents/UIEventStream.h" -#include "Swift/Controllers/UIEvents/RequestChatUIEvent.h" -#include "Swiften/Avatars/AvatarManager.h" -#include "Swiften/Elements/Delay.h" -#include "Swiften/MUC/MUC.h" -#include "Swiften/Client/StanzaChannel.h" -#include "Swift/Controllers/Roster/Roster.h" -#include "Swift/Controllers/Roster/SetAvatar.h" -#include "Swift/Controllers/Roster/SetPresence.h" +#include <Swiften/Network/Timer.h> +#include <Swiften/Network/TimerFactory.h> +#include <Swiften/Base/foreach.h> +#include <SwifTools/TabComplete.h> +#include <Swiften/Base/foreach.h> +#include <Swift/Controllers/XMPPEvents/EventController.h> +#include <Swift/Controllers/UIInterfaces/ChatWindow.h> +#include <Swift/Controllers/UIInterfaces/ChatWindowFactory.h> +#include <Swift/Controllers/UIEvents/UIEventStream.h> +#include <Swift/Controllers/UIEvents/RequestChatUIEvent.h> +#include <Swift/Controllers/Roster/GroupRosterItem.h> +#include <Swiften/Avatars/AvatarManager.h> +#include <Swiften/Elements/Delay.h> +#include <Swiften/MUC/MUC.h> +#include <Swiften/Client/StanzaChannel.h> +#include <Swift/Controllers/Roster/Roster.h> +#include <Swift/Controllers/Roster/SetAvatar.h> +#include <Swift/Controllers/Roster/SetPresence.h> #define MUC_JOIN_WARNING_TIMEOUT_MILLISECONDS 60000 @@ -206,7 +207,9 @@ void MUCController::handleOccupantJoined(const MUCOccupant& occupant) { currentOccupants_.insert(occupant.getNick()); NickJoinPart event(occupant.getNick(), Join); appendToJoinParts(joinParts_, event); - roster_->addContact(jid, realJID, occupant.getNick(), roleToGroupName(occupant.getRole()), avatarManager_->getAvatarPath(jid).string()); + std::string groupName(roleToGroupName(occupant.getRole())); + roster_->addContact(jid, realJID, occupant.getNick(), groupName, avatarManager_->getAvatarPath(jid).string()); + roster_->getGroup(groupName)->setManualSort(roleToSortName(occupant.getRole())); if (joined_) { std::string joinString; MUCOccupant::Role role = occupant.getRole(); @@ -248,6 +251,16 @@ std::string MUCController::roleToFriendlyName(MUCOccupant::Role role) { return ""; } +std::string MUCController::roleToSortName(MUCOccupant::Role role) { + switch (role) { + case MUCOccupant::Moderator: return "1"; + case MUCOccupant::Participant: return "2"; + case MUCOccupant::Visitor: return "3"; + case MUCOccupant::NoRole: return "4"; + } + return "5"; +} + JID MUCController::nickToJID(const std::string& nick) { return JID(toJID_.getNode(), toJID_.getDomain(), nick); } @@ -309,7 +322,9 @@ void MUCController::handleOccupantRoleChanged(const std::string& nick, const MUC if (occupant.getRealJID()) { realJID = occupant.getRealJID().get(); } - roster_->addContact(jid, realJID, nick, roleToGroupName(occupant.getRole()), avatarManager_->getAvatarPath(jid).string()); + std::string group(roleToGroupName(occupant.getRole())); + roster_->addContact(jid, realJID, nick, group, avatarManager_->getAvatarPath(jid).string()); + roster_->getGroup(group)->setManualSort(roleToSortName(occupant.getRole())); chatWindow_->addSystemMessage(str(format(QT_TRANSLATE_NOOP("", "%1% is now a %2%")) % nick % roleToFriendlyName(occupant.getRole()))); } diff --git a/Swift/Controllers/Chat/MUCController.h b/Swift/Controllers/Chat/MUCController.h index ebdd6cd..6b05a8e 100644 --- a/Swift/Controllers/Chat/MUCController.h +++ b/Swift/Controllers/Chat/MUCController.h @@ -7,18 +7,18 @@ #pragma once #include <boost/shared_ptr.hpp> -#include "Swiften/Base/boost_bsignals.h" +#include <Swiften/Base/boost_bsignals.h> #include <boost/signals/connection.hpp> -#include <set> +#include <set> #include <string> -#include "Swiften/Network/Timer.h" -#include "Swift/Controllers/Chat/ChatControllerBase.h" -#include "Swiften/Elements/Message.h" -#include "Swiften/Elements/DiscoInfo.h" -#include "Swiften/JID/JID.h" -#include "Swiften/MUC/MUC.h" -#include "Swiften/Elements/MUCOccupant.h" +#include <Swiften/Network/Timer.h> +#include <Swift/Controllers/Chat/ChatControllerBase.h> +#include <Swiften/Elements/Message.h> +#include <Swiften/Elements/DiscoInfo.h> +#include <Swiften/JID/JID.h> +#include <Swiften/MUC/MUC.h> +#include <Swiften/Elements/MUCOccupant.h> namespace Swift { class StanzaChannel; @@ -71,6 +71,7 @@ namespace Swift { void handleJoinFailed(boost::shared_ptr<ErrorPayload> error); void handleJoinTimeoutTick(); std::string roleToGroupName(MUCOccupant::Role role); + std::string roleToSortName(MUCOccupant::Role role); JID nickToJID(const std::string& nick); std::string roleToFriendlyName(MUCOccupant::Role role); void receivedActivity(); diff --git a/Swift/Controllers/Chat/MUCSearchController.cpp b/Swift/Controllers/Chat/MUCSearchController.cpp index 743aabb..2cb89b4 100644 --- a/Swift/Controllers/Chat/MUCSearchController.cpp +++ b/Swift/Controllers/Chat/MUCSearchController.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2010 Kevin Smith + * Copyright (c) 2010-2011 Kevin Smith * Licensed under the GNU General Public License v3. * See Documentation/Licenses/GPLv3.txt for more information. */ @@ -11,6 +11,7 @@ #include <boost/bind.hpp> #include <boost/shared_ptr.hpp> +#include <Swiften/Base/foreach.h> #include <Swiften/Disco/GetDiscoItemsRequest.h> #include <Swiften/Base/Log.h> #include <Swiften/Base/String.h> @@ -23,7 +24,7 @@ namespace Swift { static const std::string SEARCHED_SERVICES = "searchedServices"; -MUCSearchController::MUCSearchController(const JID& jid, MUCSearchWindowFactory* factory, IQRouter* iqRouter, SettingsProvider* settings) : jid_(jid), factory_(factory), iqRouter_(iqRouter), settings_(settings), window_(NULL), walker_(NULL) { +MUCSearchController::MUCSearchController(const JID& jid, MUCSearchWindowFactory* factory, IQRouter* iqRouter, ProfileSettingsProvider* settings) : jid_(jid), factory_(factory), iqRouter_(iqRouter), settings_(settings), window_(NULL), walker_(NULL) { itemsInProgress_ = 0; loadSavedServices(); } diff --git a/Swift/Controllers/Chat/MUCSearchController.h b/Swift/Controllers/Chat/MUCSearchController.h index c8040ed..f90e4a7 100644 --- a/Swift/Controllers/Chat/MUCSearchController.h +++ b/Swift/Controllers/Chat/MUCSearchController.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2010 Kevin Smith + * Copyright (c) 2010-2011 Kevin Smith * Licensed under the GNU General Public License v3. * See Documentation/Licenses/GPLv3.txt for more information. */ @@ -16,7 +16,7 @@ #include "Swiften/JID/JID.h" #include "Swift/Controllers/UIEvents/UIEvent.h" -#include "Swift/Controllers/Settings/SettingsProvider.h" +#include "Swift/Controllers/ProfileSettingsProvider.h" #include "Swiften/Elements/DiscoInfo.h" #include "Swiften/Elements/DiscoItems.h" #include "Swiften/Elements/ErrorPayload.h" @@ -87,7 +87,7 @@ namespace Swift { class MUCSearchController { public: - MUCSearchController(const JID& jid, MUCSearchWindowFactory* mucSearchWindowFactory, IQRouter* iqRouter, SettingsProvider* settings); + MUCSearchController(const JID& jid, MUCSearchWindowFactory* mucSearchWindowFactory, IQRouter* iqRouter, ProfileSettingsProvider* settings); ~MUCSearchController(); void openSearchWindow(); @@ -112,7 +112,7 @@ namespace Swift { JID jid_; MUCSearchWindowFactory* factory_; IQRouter* iqRouter_; - SettingsProvider* settings_; + ProfileSettingsProvider* settings_; MUCSearchWindow* window_; DiscoServiceWalker* walker_; std::list<JID> services_; diff --git a/Swift/Controllers/Chat/UnitTest/ChatsManagerTest.cpp b/Swift/Controllers/Chat/UnitTest/ChatsManagerTest.cpp index 40f7445..f8fda9a 100644 --- a/Swift/Controllers/Chat/UnitTest/ChatsManagerTest.cpp +++ b/Swift/Controllers/Chat/UnitTest/ChatsManagerTest.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2010 Kevin Smith + * Copyright (c) 2010-2011 Kevin Smith * Licensed under the GNU General Public License v3. * See Documentation/Licenses/GPLv3.txt for more information. */ @@ -10,6 +10,7 @@ #include "Swift/Controllers/Chat/ChatsManager.h" +#include "Swift/Controllers/Chat/UnitTest/MockChatListWindow.h" #include "Swift/Controllers/UIInterfaces/ChatWindow.h" #include "Swift/Controllers/Settings/DummySettingsProvider.h" #include "Swift/Controllers/UIInterfaces/ChatWindowFactory.h" @@ -38,6 +39,7 @@ #include "Swift/Controllers/UIEvents/RequestChatUIEvent.h" #include "Swift/Controllers/UIEvents/JoinMUCUIEvent.h" #include "Swift/Controllers/UIEvents/UIEventStream.h" +#include <Swift/Controllers/ProfileSettingsProvider.h> using namespace Swift; @@ -82,8 +84,10 @@ public: chatListWindowFactory_ = mocks_->InterfaceMock<ChatListWindowFactory>(); mucSearchWindowFactory_ = mocks_->InterfaceMock<MUCSearchWindowFactory>(); settings_ = new DummySettingsProvider(); - mocks_->ExpectCall(chatListWindowFactory_, ChatListWindowFactory::createChatListWindow).With(uiEventStream_).Return(NULL); - manager_ = new ChatsManager(jid_, stanzaChannel_, iqRouter_, eventController_, chatWindowFactory_, joinMUCWindowFactory_, nickResolver_, presenceOracle_, directedPresenceSender_, uiEventStream_, chatListWindowFactory_, true, NULL, mucRegistry_, entityCapsManager_, mucManager_, mucSearchWindowFactory_, settings_); + profileSettings_ = new ProfileSettingsProvider("a", settings_); + chatListWindow_ = new MockChatListWindow(); + mocks_->ExpectCall(chatListWindowFactory_, ChatListWindowFactory::createChatListWindow).With(uiEventStream_).Return(chatListWindow_); + manager_ = new ChatsManager(jid_, stanzaChannel_, iqRouter_, eventController_, chatWindowFactory_, joinMUCWindowFactory_, nickResolver_, presenceOracle_, directedPresenceSender_, uiEventStream_, chatListWindowFactory_, true, NULL, mucRegistry_, entityCapsManager_, mucManager_, mucSearchWindowFactory_, profileSettings_); avatarManager_ = new NullAvatarManager(); manager_->setAvatarManager(avatarManager_); @@ -92,6 +96,7 @@ public: void tearDown() { //delete chatListWindowFactory_; delete settings_; + delete profileSettings_; delete mocks_; delete avatarManager_; delete manager_; @@ -109,6 +114,7 @@ public: delete xmppRoster_; delete entityCapsManager_; delete capsProvider_; + delete chatListWindow_; } void testFirstOpenWindowIncoming() { @@ -346,6 +352,8 @@ private: CapsProvider* capsProvider_; MUCManager* mucManager_; DummySettingsProvider* settings_; + ProfileSettingsProvider* profileSettings_; + ChatListWindow* chatListWindow_; }; CPPUNIT_TEST_SUITE_REGISTRATION(ChatsManagerTest); diff --git a/Swift/Controllers/Chat/UnitTest/MockChatListWindow.h b/Swift/Controllers/Chat/UnitTest/MockChatListWindow.h new file mode 100644 index 0000000..408a490 --- /dev/null +++ b/Swift/Controllers/Chat/UnitTest/MockChatListWindow.h @@ -0,0 +1,24 @@ +/* + * Copyright (c) 2011 Kevin Smith + * Licensed under the GNU General Public License v3. + * See Documentation/Licenses/GPLv3.txt for more information. + */ + +#pragma once + +#include "Swift/Controllers/UIInterfaces/ChatListWindow.h" + +namespace Swift { + + class MockChatListWindow : public ChatListWindow { + public: + MockChatListWindow() {}; + virtual ~MockChatListWindow() {}; + void addMUCBookmark(const MUCBookmark& /*bookmark*/) {} + void removeMUCBookmark(const MUCBookmark& /*bookmark*/) {} + void setBookmarksEnabled(bool /*enabled*/) {} + void setRecents(const std::list<ChatListWindow::Chat>& /*recents*/) {} + void clearBookmarks() {} + }; + +} diff --git a/Swift/Controllers/Chat/UserSearchController.cpp b/Swift/Controllers/Chat/UserSearchController.cpp index b3403d7..deac2f9 100644 --- a/Swift/Controllers/Chat/UserSearchController.cpp +++ b/Swift/Controllers/Chat/UserSearchController.cpp @@ -9,9 +9,9 @@ #include <boost/bind.hpp> #include <boost/shared_ptr.hpp> +#include <Swiften/Base/foreach.h> #include <Swiften/Disco/GetDiscoInfoRequest.h> #include <Swiften/Disco/GetDiscoItemsRequest.h> - #include <Swift/Controllers/DiscoServiceWalker.h> #include <Swift/Controllers/UIEvents/UIEventStream.h> #include <Swift/Controllers/UIEvents/RequestChatWithUserDialogUIEvent.h> diff --git a/Swift/Controllers/ChatMessageSummarizer.cpp b/Swift/Controllers/ChatMessageSummarizer.cpp new file mode 100644 index 0000000..682d88b --- /dev/null +++ b/Swift/Controllers/ChatMessageSummarizer.cpp @@ -0,0 +1,45 @@ +/* + * Copyright (c) 2011 Kevin Smith + * Licensed under the GNU General Public License v3. + * See Documentation/Licenses/GPLv3.txt for more information. + */ + +#include <Swift/Controllers/ChatMessageSummarizer.h> + +#include <Swiften/Base/format.h> +#include <Swift/Controllers/Intl.h> +#include <Swiften/Base/foreach.h> + +using namespace Swift; +using namespace std; + +string ChatMessageSummarizer::getSummary(const string& current, const vector<UnreadPair>& unreads) { + vector<UnreadPair> others; + int currentUnread = 0; + int otherCount = 0; + foreach (UnreadPair unread, unreads) { + if (unread.first == current) { + currentUnread += unread.second; + } else { + if (unread.second > 0) { + otherCount += unread.second; + others.push_back(unread); + } + } + } + string myString(current); + + if (currentUnread > 0) { + string result(QT_TRANSLATE_NOOP("", "%1% (%2%)")); + myString = str(format(result) % current % currentUnread); + } + + if (others.size() > 1) { + string result(QT_TRANSLATE_NOOP("", "%1% and %2% others (%3%)")); + myString = str(format(result) % myString % others.size() % otherCount); + } else if (others.size() > 0) { + string result(QT_TRANSLATE_NOOP("", "%1%, %2% (%3%)")); + myString = str(format(result) % myString % others[0].first % otherCount); + } + return myString; +} diff --git a/Swift/Controllers/ChatMessageSummarizer.h b/Swift/Controllers/ChatMessageSummarizer.h new file mode 100644 index 0000000..d4ff188 --- /dev/null +++ b/Swift/Controllers/ChatMessageSummarizer.h @@ -0,0 +1,20 @@ +/* + * Copyright (c) 2011 Kevin Smith + * Licensed under the GNU General Public License v3. + * See Documentation/Licenses/GPLv3.txt for more information. + */ + +#pragma once + +#include <vector> +#include <utility> +#include <string> + +namespace Swift { +typedef std::pair<std::string, int> UnreadPair; + + class ChatMessageSummarizer { + public: + std::string getSummary(const std::string& current, const std::vector<UnreadPair>& unreads); + }; +} diff --git a/Swift/Controllers/DiscoServiceWalker.cpp b/Swift/Controllers/DiscoServiceWalker.cpp index ce29927..6aed6eb 100644 --- a/Swift/Controllers/DiscoServiceWalker.cpp +++ b/Swift/Controllers/DiscoServiceWalker.cpp @@ -6,6 +6,7 @@ #include <Swift/Controllers/DiscoServiceWalker.h> #include <Swiften/Base/Log.h> +#include <Swiften/Base/foreach.h> #include <boost/bind.hpp> diff --git a/Swift/Controllers/MainController.cpp b/Swift/Controllers/MainController.cpp index 9a35cc1..c00c080 100644 --- a/Swift/Controllers/MainController.cpp +++ b/Swift/Controllers/MainController.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2010 Kevin Smith + * Copyright (c) 2010-2011 Kevin Smith * Licensed under the GNU General Public License v3. * See Documentation/Licenses/GPLv3.txt for more information. */ @@ -18,10 +18,8 @@ #include <Swift/Controllers/UIInterfaces/UIFactory.h> #include "Swiften/Network/TimerFactory.h" #include "Swift/Controllers/BuildVersion.h" -#include "Swift/Controllers/StoragesFactory.h" #include "Swiften/Client/Storages.h" #include "Swiften/VCards/VCardManager.h" -#include "Swift/Controllers/Chat/MUCSearchController.h" #include "Swift/Controllers/Chat/UserSearchController.h" #include "Swift/Controllers/Chat/ChatsManager.h" #include "Swift/Controllers/XMPPEvents/EventController.h" @@ -41,6 +39,7 @@ #include "Swift/Controllers/UIEvents/UIEventStream.h" #include "Swift/Controllers/PresenceNotifier.h" #include "Swift/Controllers/EventNotifier.h" +#include "Swift/Controllers/Storages/StoragesFactory.h" #include "SwifTools/Dock/Dock.h" #include "SwifTools/Notifier/TogglableNotifier.h" #include "Swiften/Base/foreach.h" @@ -60,11 +59,13 @@ #include "Swift/Controllers/UIEvents/RequestChatUIEvent.h" #include "Swift/Controllers/UIEvents/ToggleNotificationsUIEvent.h" #include "Swift/Controllers/UIEvents/JoinMUCUIEvent.h" -#include "Swift/Controllers/CertificateStorageFactory.h" -#include "Swift/Controllers/CertificateStorageTrustChecker.h" +#include "Swift/Controllers/Storages/CertificateStorageFactory.h" +#include "Swift/Controllers/Storages/CertificateStorageTrustChecker.h" #include "Swiften/Network/NetworkFactories.h" #include <Swift/Controllers/ProfileController.h> #include <Swift/Controllers/ContactEditController.h> +#include <Swift/Controllers/XMPPURIController.h> +#include "Swift/Controllers/AdHocManager.h" namespace Swift { @@ -84,6 +85,7 @@ MainController::MainController( CertificateStorageFactory* certificateStorageFactory, Dock* dock, Notifier* notifier, + URIHandler* uriHandler, bool useDelayForLatency) : eventLoop_(eventLoop), networkFactories_(networkFactories), @@ -92,6 +94,7 @@ MainController::MainController( storagesFactory_(storagesFactory), certificateStorageFactory_(certificateStorageFactory), settings_(settings), + uriHandler_(uriHandler), loginWindow_(NULL) , useDelayForLatency_(useDelayForLatency) { storages_ = NULL; @@ -121,6 +124,8 @@ MainController::MainController( loginWindow_ = uiFactory_->createLoginWindow(uiEventStream_); soundEventController_ = new SoundEventController(eventController_, soundPlayer, settings, uiEventStream_); + xmppURIController_ = new XMPPURIController(uriHandler_, uiEventStream_); + std::string selectedLoginJID = settings_->getStringSetting("lastLoginJID"); bool loginAutomatically = settings_->getBoolSetting("loginAutomatically", false); std::string cachedPassword; @@ -167,6 +172,7 @@ MainController::~MainController() { resetClient(); delete xmlConsoleController_; + delete xmppURIController_; delete soundEventController_; delete systemTrayController_; delete eventController_; @@ -247,7 +253,7 @@ void MainController::handleConnected() { contactEditController_ = new ContactEditController(rosterController_, uiFactory_, uiEventStream_); - chatsManager_ = new ChatsManager(jid_, client_->getStanzaChannel(), client_->getIQRouter(), eventController_, uiFactory_, uiFactory_, client_->getNickResolver(), client_->getPresenceOracle(), client_->getPresenceSender(), uiEventStream_, uiFactory_, useDelayForLatency_, networkFactories_->getTimerFactory(), client_->getMUCRegistry(), client_->getEntityCapsProvider(), client_->getMUCManager(), uiFactory_, settings_); + chatsManager_ = new ChatsManager(jid_, client_->getStanzaChannel(), client_->getIQRouter(), eventController_, uiFactory_, uiFactory_, client_->getNickResolver(), client_->getPresenceOracle(), client_->getPresenceSender(), uiEventStream_, uiFactory_, useDelayForLatency_, networkFactories_->getTimerFactory(), client_->getMUCRegistry(), client_->getEntityCapsProvider(), client_->getMUCManager(), uiFactory_, profileSettings_); client_->onMessageReceived.connect(boost::bind(&ChatsManager::handleIncomingMessage, chatsManager_, _1)); chatsManager_->setAvatarManager(client_->getAvatarManager()); @@ -262,14 +268,14 @@ void MainController::handleConnected() { client_->getDiscoManager()->setCapsNode(CLIENT_NODE); client_->getDiscoManager()->setDiscoInfo(discoInfo); - userSearchControllerChat_ = new UserSearchController(UserSearchController::StartChat, jid_, uiEventStream_, uiFactory_, client_->getIQRouter(), rosterController_); userSearchControllerAdd_ = new UserSearchController(UserSearchController::AddContact, jid_, uiEventStream_, uiFactory_, client_->getIQRouter(), rosterController_); + adHocManager_ = new AdHocManager(boundJID_, uiFactory_, client_->getIQRouter(), uiEventStream_, rosterController_->getWindow()); } client_->requestRoster(); - GetDiscoInfoRequest::ref discoInfoRequest = GetDiscoInfoRequest::create(JID(), client_->getIQRouter()); + GetDiscoInfoRequest::ref discoInfoRequest = GetDiscoInfoRequest::create(boundJID_.toBare(), client_->getIQRouter()); discoInfoRequest->onResponse.connect(boost::bind(&MainController::handleServerDiscoInfoResponse, this, _1, _2)); discoInfoRequest->send(); @@ -356,19 +362,25 @@ void MainController::handleInputIdleChanged(bool idle) { } void MainController::handleLoginRequest(const std::string &username, const std::string &password, const std::string& certificateFile, bool remember, bool loginAutomatically) { - loginWindow_->setMessage(""); - loginWindow_->setIsLoggingIn(true); - profileSettings_ = new ProfileSettingsProvider(username, settings_); - profileSettings_->storeString("jid", username); - profileSettings_->storeString("certificate", certificateFile); - profileSettings_->storeString("pass", (remember || loginAutomatically) ? password : ""); - settings_->storeString("lastLoginJID", username); - settings_->storeBool("loginAutomatically", loginAutomatically); - loginWindow_->addAvailableAccount(profileSettings_->getStringSetting("jid"), profileSettings_->getStringSetting("pass"), profileSettings_->getStringSetting("certificate")); jid_ = JID(username); - password_ = password; - certificateFile_ = certificateFile; - performLoginFromCachedCredentials(); + if (!jid_.isValid() || jid_.getNode().empty()) { + loginWindow_->setMessage(QT_TRANSLATE_NOOP("", "User address invalid. User address should be of the form 'alice@wonderland.lit'")); + loginWindow_->setIsLoggingIn(false); + } else { + loginWindow_->setMessage(""); + loginWindow_->setIsLoggingIn(true); + profileSettings_ = new ProfileSettingsProvider(username, settings_); + profileSettings_->storeString("jid", username); + profileSettings_->storeString("certificate", certificateFile); + profileSettings_->storeString("pass", (remember || loginAutomatically) ? password : ""); + settings_->storeString("lastLoginJID", username); + settings_->storeBool("loginAutomatically", loginAutomatically); + loginWindow_->addAvailableAccount(profileSettings_->getStringSetting("jid"), profileSettings_->getStringSetting("pass"), profileSettings_->getStringSetting("certificate")); + + password_ = password; + certificateFile_ = certificateFile; + performLoginFromCachedCredentials(); + } } void MainController::handlePurgeSavedLoginRequest(const std::string& username) { @@ -483,6 +495,7 @@ void MainController::handleDisconnected(const boost::optional<ClientError>& erro else if (!rosterController_) { //hasn't been logged in yet signOut(); loginWindow_->setMessage(message); + loginWindow_->setIsLoggingIn(false); } else { logout(); setReconnectTimer(); @@ -496,6 +509,9 @@ void MainController::handleDisconnected(const boost::optional<ClientError>& erro eventController_->handleIncomingEvent(lastDisconnectError_); } } + else if (!rosterController_) { //hasn't been logged in yet + loginWindow_->setIsLoggingIn(false); + } } void MainController::setReconnectTimer() { @@ -554,6 +570,7 @@ void MainController::setManagersOffline() { void MainController::handleServerDiscoInfoResponse(boost::shared_ptr<DiscoInfo> info, ErrorPayload::ref error) { if (!error) { chatsManager_->setServerDiscoInfo(info); + adHocManager_->setServerDiscoInfo(info); } } diff --git a/Swift/Controllers/MainController.h b/Swift/Controllers/MainController.h index f402f8f..757abb8 100644 --- a/Swift/Controllers/MainController.h +++ b/Swift/Controllers/MainController.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2010 Kevin Smith + * Copyright (c) 2010-2011 Kevin Smith * Licensed under the GNU General Public License v3. * See Documentation/Licenses/GPLv3.txt for more information. */ @@ -62,6 +62,10 @@ namespace Swift { class Storages; class StoragesFactory; class NetworkFactories; + class URIHandler; + class XMPPURIController; + class AdHocManager; + class AdHocCommandWindowFactory; class MainController { public: @@ -76,6 +80,7 @@ namespace Swift { CertificateStorageFactory* certificateStorageFactory, Dock* dock, Notifier* notifier, + URIHandler* uriHandler, bool useDelayForLatency); ~MainController(); @@ -123,12 +128,14 @@ namespace Swift { SettingsProvider *settings_; ProfileSettingsProvider* profileSettings_; Dock* dock_; + URIHandler* uriHandler_; TogglableNotifier* notifier_; PresenceNotifier* presenceNotifier_; EventNotifier* eventNotifier_; RosterController* rosterController_; EventController* eventController_; EventWindowController* eventWindowController_; + AdHocManager* adHocManager_; LoginWindow* loginWindow_; UIEventStream* uiEventStream_; XMLConsoleController* xmlConsoleController_; @@ -139,6 +146,7 @@ namespace Swift { JID boundJID_; SystemTrayController* systemTrayController_; SoundEventController* soundEventController_; + XMPPURIController* xmppURIController_; std::string vCardPhotoHash_; std::string password_; std::string certificateFile_; diff --git a/Swift/Controllers/ProfileSettingsProvider.h b/Swift/Controllers/ProfileSettingsProvider.h index 74bcd12..8ba250c 100644 --- a/Swift/Controllers/ProfileSettingsProvider.h +++ b/Swift/Controllers/ProfileSettingsProvider.h @@ -7,6 +7,7 @@ #pragma once #include "Swift/Controllers/Settings/SettingsProvider.h" +#include <Swiften/Base/foreach.h> namespace Swift { diff --git a/Swift/Controllers/Roster/ContactRosterItem.cpp b/Swift/Controllers/Roster/ContactRosterItem.cpp index 0fe88aa..894f64b 100644 --- a/Swift/Controllers/Roster/ContactRosterItem.cpp +++ b/Swift/Controllers/Roster/ContactRosterItem.cpp @@ -7,6 +7,8 @@ #include "Swift/Controllers/Roster/ContactRosterItem.h" #include "Swift/Controllers/Roster/GroupRosterItem.h" +#include <Swiften/Base/foreach.h> + namespace Swift { diff --git a/Swift/Controllers/Roster/GroupRosterItem.cpp b/Swift/Controllers/Roster/GroupRosterItem.cpp index f0a377a..2b56d1f 100644 --- a/Swift/Controllers/Roster/GroupRosterItem.cpp +++ b/Swift/Controllers/Roster/GroupRosterItem.cpp @@ -12,7 +12,7 @@ namespace Swift { -GroupRosterItem::GroupRosterItem(const std::string& name, GroupRosterItem* parent, bool sortByStatus) : RosterItem(name, parent), sortByStatus_(sortByStatus) { +GroupRosterItem::GroupRosterItem(const std::string& name, GroupRosterItem* parent, bool sortByStatus) : RosterItem(name, parent), sortByStatus_(sortByStatus), manualSort_(false) { expanded_ = true; } @@ -20,6 +20,20 @@ GroupRosterItem::~GroupRosterItem() { } +void GroupRosterItem::setManualSort(const std::string& manualSortValue) { + manualSort_ = true; + bool changed = manualSortValue_ != manualSortValue; + manualSortValue_ = manualSortValue; + if (changed) { + onChildrenChanged(); + onDataChanged(); + } +} + +const std::string& GroupRosterItem::getSortableDisplayName() const { + return manualSort_ ? manualSortValue_ : RosterItem::getSortableDisplayName(); +} + bool GroupRosterItem::isExpanded() const { return expanded_; } @@ -210,7 +224,8 @@ void GroupRosterItem::handleChildrenChanged(GroupRosterItem* group) { } else { displayedChildren_.erase(std::remove(displayedChildren_.begin(), displayedChildren_.end(), group), displayedChildren_.end()); } - if (oldSize != getDisplayedChildren().size()) { + + if (oldSize != getDisplayedChildren().size() || sortDisplayed()) { onChildrenChanged(); onDataChanged(); } diff --git a/Swift/Controllers/Roster/GroupRosterItem.h b/Swift/Controllers/Roster/GroupRosterItem.h index 57fa9fa..beb7705 100644 --- a/Swift/Controllers/Roster/GroupRosterItem.h +++ b/Swift/Controllers/Roster/GroupRosterItem.h @@ -31,6 +31,8 @@ class GroupRosterItem : public RosterItem { void setExpanded(bool expanded); bool isExpanded() const; boost::signal<void (bool)> onExpandedChanged; + void setManualSort(const std::string& manualSortValue); + virtual const std::string& getSortableDisplayName() const; private: void handleChildrenChanged(GroupRosterItem* group); void handleDataChanged(RosterItem* item); @@ -40,6 +42,8 @@ class GroupRosterItem : public RosterItem { std::vector<RosterItem*> children_; std::vector<RosterItem*> displayedChildren_; bool sortByStatus_; + bool manualSort_; + std::string manualSortValue_; }; } diff --git a/Swift/Controllers/Roster/RosterGroupExpandinessPersister.cpp b/Swift/Controllers/Roster/RosterGroupExpandinessPersister.cpp index c1045ee..0a242ae 100644 --- a/Swift/Controllers/Roster/RosterGroupExpandinessPersister.cpp +++ b/Swift/Controllers/Roster/RosterGroupExpandinessPersister.cpp @@ -9,6 +9,7 @@ #include <boost/bind.hpp> #include <vector> +#include <Swiften/Base/foreach.h> #include "Swiften/Base/String.h" #include "Swift/Controllers/Roster/GroupRosterItem.h" diff --git a/Swift/Controllers/Roster/RosterItem.cpp b/Swift/Controllers/Roster/RosterItem.cpp index 3f130bb..77db8a3 100644 --- a/Swift/Controllers/Roster/RosterItem.cpp +++ b/Swift/Controllers/Roster/RosterItem.cpp @@ -33,11 +33,11 @@ void RosterItem::setDisplayName(const std::string& name) { onDataChanged(); } -std::string RosterItem::getDisplayName() const { +const std::string& RosterItem::getDisplayName() const { return name_; } -std::string RosterItem::getSortableDisplayName() const { +const std::string& RosterItem::getSortableDisplayName() const { return sortableDisplayName_; } diff --git a/Swift/Controllers/Roster/RosterItem.h b/Swift/Controllers/Roster/RosterItem.h index ed8cb16..769f72d 100644 --- a/Swift/Controllers/Roster/RosterItem.h +++ b/Swift/Controllers/Roster/RosterItem.h @@ -20,8 +20,8 @@ class RosterItem { boost::signal<void ()> onDataChanged; GroupRosterItem* getParent() const; void setDisplayName(const std::string& name); - std::string getDisplayName() const; - std::string getSortableDisplayName() const; + const std::string& getDisplayName() const; + virtual const std::string& getSortableDisplayName() const; private: std::string name_; std::string sortableDisplayName_; diff --git a/Swift/Controllers/Roster/UnitTest/RosterControllerTest.cpp b/Swift/Controllers/Roster/UnitTest/RosterControllerTest.cpp index 16f2745..ca74dbb 100644 --- a/Swift/Controllers/Roster/UnitTest/RosterControllerTest.cpp +++ b/Swift/Controllers/Roster/UnitTest/RosterControllerTest.cpp @@ -8,6 +8,7 @@ #include <cppunit/extensions/HelperMacros.h> #include <cppunit/extensions/TestFactoryRegistry.h> +#include <Swiften/Base/foreach.h> #include "Swift/Controllers/Roster/RosterController.h" #include "Swift/Controllers/UnitTest/MockMainWindowFactory.h" // #include "Swiften/Elements/Payload.h" diff --git a/Swift/Controllers/Roster/UnitTest/RosterTest.cpp b/Swift/Controllers/Roster/UnitTest/RosterTest.cpp index cbef787..4444e8a 100644 --- a/Swift/Controllers/Roster/UnitTest/RosterTest.cpp +++ b/Swift/Controllers/Roster/UnitTest/RosterTest.cpp @@ -21,6 +21,7 @@ class RosterTest : public CppUnit::TestFixture { CPPUNIT_TEST(testRemoveSecondContact); CPPUNIT_TEST(testRemoveSecondContactSameBare); CPPUNIT_TEST(testApplyPresenceLikeMUC); + CPPUNIT_TEST(testReSortLikeMUC); CPPUNIT_TEST_SUITE_END(); public: @@ -117,6 +118,22 @@ class RosterTest : public CppUnit::TestFixture { } + void testReSortLikeMUC() { + JID jid4a("a@b/c"); + JID jid4b("a@b/d"); + JID jid4c("a@b/e"); + roster_->addContact(jid4a, JID(), "Bird", "group1", ""); + roster_->addContact(jid4b, JID(), "Cookie", "group2", ""); + roster_->addContact(jid4b, JID(), "Ernie", "group1", ""); + roster_->getGroup("group1")->setManualSort("2"); + roster_->getGroup("group2")->setManualSort("1"); + GroupRosterItem* root = roster_->getRoot(); + const std::vector<RosterItem*> kids = root->getDisplayedChildren(); + CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(2), kids.size()); + CPPUNIT_ASSERT_EQUAL(std::string("group2"), kids[0]->getDisplayName()); + CPPUNIT_ASSERT_EQUAL(std::string("group1"), kids[1]->getDisplayName()); + } + private: Roster *roster_; JID jid1_; diff --git a/Swift/Controllers/SConscript b/Swift/Controllers/SConscript index 61da9fb..eed1f4d 100644 --- a/Swift/Controllers/SConscript +++ b/Swift/Controllers/SConscript @@ -44,16 +44,25 @@ if env["SCONS_STAGE"] == "build" : "StatusTracker.cpp", "PresenceNotifier.cpp", "EventNotifier.cpp", + "AdHocManager.cpp", "XMPPEvents/EventController.cpp", "UIEvents/UIEvent.cpp", "UIInterfaces/XMLConsoleWidget.cpp", "UIInterfaces/ChatListWindow.cpp", "PreviousStatusStore.cpp", - "CertificateStorageFactory.cpp", - "CertificateStorage.cpp", - "CertificateFileStorage.cpp", + "Storages/CertificateStorageFactory.cpp", + "Storages/CertificateStorage.cpp", + "Storages/CertificateFileStorage.cpp", + "Storages/CertificateMemoryStorage.cpp", + "Storages/AvatarFileStorage.cpp", + "Storages/FileStorages.cpp", + "Storages/RosterFileStorage.cpp", + "Storages/CapsFileStorage.cpp", + "Storages/VCardFileStorage.cpp", "StatusUtil.cpp", "Translator.cpp", + "XMPPURIController.cpp", + "ChatMessageSummarizer.cpp", ]) env.Append(UNITTEST_SOURCES = [ @@ -64,4 +73,5 @@ if env["SCONS_STAGE"] == "build" : File("Chat/UnitTest/ChatsManagerTest.cpp"), File("Chat/UnitTest/MUCControllerTest.cpp"), File("UnitTest/MockChatWindow.cpp"), + File("UnitTest/ChatMessageSummarizerTest.cpp"), ]) diff --git a/Swiften/Avatars/AvatarFileStorage.cpp b/Swift/Controllers/Storages/AvatarFileStorage.cpp index 4f76c80..288f6fd 100644 --- a/Swiften/Avatars/AvatarFileStorage.cpp +++ b/Swift/Controllers/Storages/AvatarFileStorage.cpp @@ -4,10 +4,11 @@ * See Documentation/Licenses/GPLv3.txt for more information. */ -#include <Swiften/Avatars/AvatarFileStorage.h> +#include <Swift/Controllers/Storages/AvatarFileStorage.h> #include <iostream> #include <boost/filesystem/fstream.hpp> +#include <boost/filesystem.hpp> #include <Swiften/Base/foreach.h> #include <Swiften/Base/String.h> @@ -58,7 +59,7 @@ void AvatarFileStorage::addAvatar(const std::string& hash, const ByteArray& avat } } boost::filesystem::ofstream file(avatarPath, boost::filesystem::ofstream::binary|boost::filesystem::ofstream::out); - file.write(reinterpret_cast<const char*>(avatar.getData()), avatar.getSize()); + file.write(reinterpret_cast<const char*>(avatar.getData()), static_cast<std::streamsize>(avatar.getSize())); file.close(); } diff --git a/Swiften/Avatars/AvatarFileStorage.h b/Swift/Controllers/Storages/AvatarFileStorage.h index e736230..b7e73f5 100644 --- a/Swiften/Avatars/AvatarFileStorage.h +++ b/Swift/Controllers/Storages/AvatarFileStorage.h @@ -8,7 +8,7 @@ #include <map> #include <string> -#include <boost/filesystem.hpp> +#include <boost/filesystem/path.hpp> #include <Swiften/JID/JID.h> #include "Swiften/Base/ByteArray.h" diff --git a/Swift/Controllers/Storages/CapsFileStorage.cpp b/Swift/Controllers/Storages/CapsFileStorage.cpp new file mode 100644 index 0000000..b7593fd --- /dev/null +++ b/Swift/Controllers/Storages/CapsFileStorage.cpp @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2010 Remko Tronçon + * Licensed under the GNU General Public License v3. + * See Documentation/Licenses/GPLv3.txt for more information. + */ + +#include "Swift/Controllers/Storages/CapsFileStorage.h" + +#include <Swiften/Entity/GenericPayloadPersister.h> +#include "Swiften/Serializer/PayloadSerializers/DiscoInfoSerializer.h" +#include "Swiften/Parser/PayloadParsers/DiscoInfoParser.h" +#include "Swiften/StringCodecs/Hexify.h" +#include "Swiften/StringCodecs/Base64.h" + +using namespace Swift; + +typedef GenericPayloadPersister<DiscoInfo, DiscoInfoParser, DiscoInfoSerializer> DiscoInfoPersister; + +CapsFileStorage::CapsFileStorage(const boost::filesystem::path& path) : path(path) { +} + +DiscoInfo::ref CapsFileStorage::getDiscoInfo(const std::string& hash) const { + return DiscoInfoPersister().loadPayloadGeneric(getCapsPath(hash)); +} + +void CapsFileStorage::setDiscoInfo(const std::string& hash, DiscoInfo::ref discoInfo) { + DiscoInfo::ref bareDiscoInfo(new DiscoInfo(*discoInfo.get())); + bareDiscoInfo->setNode(""); + DiscoInfoPersister().savePayload(bareDiscoInfo, getCapsPath(hash)); +} + +boost::filesystem::path CapsFileStorage::getCapsPath(const std::string& hash) const { + return path / (Hexify::hexify(Base64::decode(hash)) + ".xml"); +} diff --git a/Swiften/Disco/CapsFileStorage.h b/Swift/Controllers/Storages/CapsFileStorage.h index 5faf08b..b3757e0 100644 --- a/Swiften/Disco/CapsFileStorage.h +++ b/Swift/Controllers/Storages/CapsFileStorage.h @@ -6,7 +6,7 @@ #pragma once -#include <boost/filesystem.hpp> +#include <boost/filesystem/path.hpp> #include "Swiften/Disco/CapsStorage.h" #include <string> diff --git a/Swift/Controllers/CertificateFileStorage.cpp b/Swift/Controllers/Storages/CertificateFileStorage.cpp index cf924ee..31af949 100644 --- a/Swift/Controllers/CertificateFileStorage.cpp +++ b/Swift/Controllers/Storages/CertificateFileStorage.cpp @@ -4,7 +4,7 @@ * See Documentation/Licenses/GPLv3.txt for more information. */ -#include <Swift/Controllers/CertificateFileStorage.h> +#include <Swift/Controllers/Storages/CertificateFileStorage.h> #include <iostream> #include <boost/filesystem/fstream.hpp> diff --git a/Swift/Controllers/CertificateFileStorage.h b/Swift/Controllers/Storages/CertificateFileStorage.h index 2b853ed..f7a60b9 100644 --- a/Swift/Controllers/CertificateFileStorage.h +++ b/Swift/Controllers/Storages/CertificateFileStorage.h @@ -8,7 +8,7 @@ #include <boost/filesystem.hpp> -#include "Swift/Controllers/CertificateStorage.h" +#include "Swift/Controllers/Storages/CertificateStorage.h" namespace Swift { class CertificateFactory; diff --git a/Swift/Controllers/CertificateFileStorageFactory.h b/Swift/Controllers/Storages/CertificateFileStorageFactory.h index 7ed8287..b215165 100644 --- a/Swift/Controllers/CertificateFileStorageFactory.h +++ b/Swift/Controllers/Storages/CertificateFileStorageFactory.h @@ -6,8 +6,8 @@ #pragma once -#include <Swift/Controllers/CertificateStorageFactory.h> -#include <Swift/Controllers/CertificateFileStorage.h> +#include <Swift/Controllers/Storages/CertificateStorageFactory.h> +#include <Swift/Controllers/Storages/CertificateFileStorage.h> namespace Swift { class CertificateFactory; diff --git a/Swift/Controllers/Storages/CertificateMemoryStorage.cpp b/Swift/Controllers/Storages/CertificateMemoryStorage.cpp new file mode 100644 index 0000000..71d7c4a --- /dev/null +++ b/Swift/Controllers/Storages/CertificateMemoryStorage.cpp @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2011 Remko Tronçon + * Licensed under the GNU General Public License v3. + * See Documentation/Licenses/GPLv3.txt for more information. + */ + +#include <Swift/Controllers/Storages/CertificateMemoryStorage.h> + +#include <Swiften/Base/foreach.h> + +using namespace Swift; + +CertificateMemoryStorage::CertificateMemoryStorage() { +} + +bool CertificateMemoryStorage::hasCertificate(Certificate::ref certificate) const { + foreach(Certificate::ref storedCert, certificates) { + if (storedCert->toDER() == certificate->toDER()) { + return true; + } + } + return false; +} + +void CertificateMemoryStorage::addCertificate(Certificate::ref certificate) { + certificates.push_back(certificate); +} diff --git a/Swift/Controllers/Storages/CertificateMemoryStorage.h b/Swift/Controllers/Storages/CertificateMemoryStorage.h new file mode 100644 index 0000000..5c0333d --- /dev/null +++ b/Swift/Controllers/Storages/CertificateMemoryStorage.h @@ -0,0 +1,25 @@ +/* + * Copyright (c) 2011 Remko Tronçon + * Licensed under the GNU General Public License v3. + * See Documentation/Licenses/GPLv3.txt for more information. + */ + +#pragma once + +#include <vector> + +#include <Swift/Controllers/Storages/CertificateStorage.h> + +namespace Swift { + class CertificateMemoryStorage : public CertificateStorage { + public: + CertificateMemoryStorage(); + + virtual bool hasCertificate(Certificate::ref certificate) const; + virtual void addCertificate(Certificate::ref certificate); + + private: + std::vector<Certificate::ref> certificates; + }; + +} diff --git a/Swift/Controllers/CertificateStorage.cpp b/Swift/Controllers/Storages/CertificateStorage.cpp index 343fccd..ee942c0 100644 --- a/Swift/Controllers/CertificateStorage.cpp +++ b/Swift/Controllers/Storages/CertificateStorage.cpp @@ -4,7 +4,7 @@ * See Documentation/Licenses/GPLv3.txt for more information. */ -#include "Swift/Controllers/CertificateStorage.h" +#include "Swift/Controllers/Storages/CertificateStorage.h" namespace Swift { diff --git a/Swift/Controllers/CertificateStorage.h b/Swift/Controllers/Storages/CertificateStorage.h index f8c6fb5..f8c6fb5 100644 --- a/Swift/Controllers/CertificateStorage.h +++ b/Swift/Controllers/Storages/CertificateStorage.h diff --git a/Swift/Controllers/CertificateStorageFactory.cpp b/Swift/Controllers/Storages/CertificateStorageFactory.cpp index 613a8c3..ba0179a 100644 --- a/Swift/Controllers/CertificateStorageFactory.cpp +++ b/Swift/Controllers/Storages/CertificateStorageFactory.cpp @@ -4,7 +4,7 @@ * See Documentation/Licenses/GPLv3.txt for more information. */ -#include <Swift/Controllers/CertificateStorageFactory.h> +#include <Swift/Controllers/Storages/CertificateStorageFactory.h> namespace Swift { diff --git a/Swift/Controllers/CertificateStorageFactory.h b/Swift/Controllers/Storages/CertificateStorageFactory.h index 5b85757..5b85757 100644 --- a/Swift/Controllers/CertificateStorageFactory.h +++ b/Swift/Controllers/Storages/CertificateStorageFactory.h diff --git a/Swift/Controllers/CertificateStorageTrustChecker.h b/Swift/Controllers/Storages/CertificateStorageTrustChecker.h index f33287c..40838dd 100644 --- a/Swift/Controllers/CertificateStorageTrustChecker.h +++ b/Swift/Controllers/Storages/CertificateStorageTrustChecker.h @@ -7,7 +7,7 @@ #pragma once #include <Swiften/TLS/CertificateTrustChecker.h> -#include <Swift/Controllers/CertificateStorage.h> +#include <Swift/Controllers/Storages/CertificateStorage.h> namespace Swift { /** diff --git a/Swiften/Client/FileStorages.cpp b/Swift/Controllers/Storages/FileStorages.cpp index 3c76c46..6447099 100644 --- a/Swiften/Client/FileStorages.cpp +++ b/Swift/Controllers/Storages/FileStorages.cpp @@ -4,10 +4,11 @@ * See Documentation/Licenses/GPLv3.txt for more information. */ -#include "Swiften/Client/FileStorages.h" -#include "Swiften/VCards/VCardFileStorage.h" -#include "Swiften/Avatars/AvatarFileStorage.h" -#include "Swiften/Disco/CapsFileStorage.h" +#include "Swift/Controllers/Storages/FileStorages.h" +#include "Swift/Controllers/Storages/VCardFileStorage.h" +#include "Swift/Controllers/Storages/AvatarFileStorage.h" +#include "Swift/Controllers/Storages/CapsFileStorage.h" +#include "Swift/Controllers/Storages/RosterFileStorage.h" namespace Swift { @@ -16,9 +17,11 @@ FileStorages::FileStorages(const boost::filesystem::path& baseDir, const JID& ji vcardStorage = new VCardFileStorage(baseDir / profile / "vcards"); capsStorage = new CapsFileStorage(baseDir / "caps"); avatarStorage = new AvatarFileStorage(baseDir / "avatars", baseDir / profile / "avatars"); + rosterStorage = new RosterFileStorage(baseDir / profile / "roster.xml"); } FileStorages::~FileStorages() { + delete rosterStorage; delete avatarStorage; delete capsStorage; delete vcardStorage; @@ -36,4 +39,8 @@ AvatarStorage* FileStorages::getAvatarStorage() const { return avatarStorage; } +RosterStorage* FileStorages::getRosterStorage() const { + return rosterStorage; +} + } diff --git a/Swiften/Client/FileStorages.h b/Swift/Controllers/Storages/FileStorages.h index 451105f..28df314 100644 --- a/Swiften/Client/FileStorages.h +++ b/Swift/Controllers/Storages/FileStorages.h @@ -6,7 +6,7 @@ #pragma once -#include <boost/filesystem.hpp> +#include <boost/filesystem/path.hpp> #include "Swiften/Client/Storages.h" @@ -14,6 +14,7 @@ namespace Swift { class VCardFileStorage; class AvatarFileStorage; class CapsFileStorage; + class RosterFileStorage; class JID; /** @@ -41,10 +42,12 @@ namespace Swift { virtual VCardStorage* getVCardStorage() const; virtual AvatarStorage* getAvatarStorage() const; virtual CapsStorage* getCapsStorage() const; + virtual RosterStorage* getRosterStorage() const; private: VCardFileStorage* vcardStorage; AvatarFileStorage* avatarStorage; CapsFileStorage* capsStorage; + RosterFileStorage* rosterStorage; }; } diff --git a/Swift/Controllers/FileStoragesFactory.h b/Swift/Controllers/Storages/FileStoragesFactory.h index bd7cdfb..0676bc3 100644 --- a/Swift/Controllers/FileStoragesFactory.h +++ b/Swift/Controllers/Storages/FileStoragesFactory.h @@ -6,8 +6,8 @@ #pragma once -#include "Swift/Controllers/StoragesFactory.h" -#include "Swiften/Client/FileStorages.h" +#include "Swift/Controllers/Storages/StoragesFactory.h" +#include "Swift/Controllers/Storages/FileStorages.h" namespace Swift { class FileStoragesFactory : public StoragesFactory { diff --git a/Swift/Controllers/MemoryStoragesFactory.h b/Swift/Controllers/Storages/MemoryStoragesFactory.h index 8408e10..0dea349 100644 --- a/Swift/Controllers/MemoryStoragesFactory.h +++ b/Swift/Controllers/Storages/MemoryStoragesFactory.h @@ -6,10 +6,12 @@ #pragma once -#include "Swift/Controllers/StoragesFactory.h" +#include "Swift/Controllers/Storages/StoragesFactory.h" #include "Swiften/Client/MemoryStorages.h" namespace Swift { + class JID; + class MemoryStoragesFactory : public StoragesFactory { public: MemoryStoragesFactory() {} diff --git a/Swift/Controllers/Storages/RosterFileStorage.cpp b/Swift/Controllers/Storages/RosterFileStorage.cpp new file mode 100644 index 0000000..73e582f --- /dev/null +++ b/Swift/Controllers/Storages/RosterFileStorage.cpp @@ -0,0 +1,26 @@ +/* + * Copyright (c) 2011 Remko Tronçon + * Licensed under the GNU General Public License v3. + * See Documentation/Licenses/GPLv3.txt for more information. + */ + +#include <Swift/Controllers/Storages/RosterFileStorage.h> + +#include <Swiften/Entity/GenericPayloadPersister.h> +#include <Swiften/Serializer/PayloadSerializers/RosterSerializer.h> +#include <Swiften/Parser/PayloadParsers/RosterParser.h> + +using namespace Swift; + +typedef GenericPayloadPersister<RosterPayload, RosterParser, RosterSerializer> RosterPersister; + +RosterFileStorage::RosterFileStorage(const boost::filesystem::path& path) : path(path) { +} + +boost::shared_ptr<RosterPayload> RosterFileStorage::getRoster() const { + return RosterPersister().loadPayloadGeneric(path); +} + +void RosterFileStorage::setRoster(boost::shared_ptr<RosterPayload> roster) { + RosterPersister().savePayload(roster, path); +} diff --git a/Swift/Controllers/Storages/RosterFileStorage.h b/Swift/Controllers/Storages/RosterFileStorage.h new file mode 100644 index 0000000..cb00969 --- /dev/null +++ b/Swift/Controllers/Storages/RosterFileStorage.h @@ -0,0 +1,24 @@ +/* + * Copyright (c) 2011 Remko Tronçon + * Licensed under the GNU General Public License v3. + * See Documentation/Licenses/GPLv3.txt for more information. + */ + +#pragma once + +#include <boost/filesystem/path.hpp> + +#include <Swiften/Roster/RosterStorage.h> + +namespace Swift { + class RosterFileStorage : public RosterStorage { + public: + RosterFileStorage(const boost::filesystem::path& path); + + virtual boost::shared_ptr<RosterPayload> getRoster() const; + virtual void setRoster(boost::shared_ptr<RosterPayload>); + + private: + boost::filesystem::path path; + }; +} diff --git a/Swift/Controllers/StoragesFactory.h b/Swift/Controllers/Storages/StoragesFactory.h index 441a4e9..203f9c9 100644 --- a/Swift/Controllers/StoragesFactory.h +++ b/Swift/Controllers/Storages/StoragesFactory.h @@ -8,6 +8,7 @@ namespace Swift { class Storages; + class JID; class StoragesFactory { public: diff --git a/Swiften/VCards/VCardFileStorage.cpp b/Swift/Controllers/Storages/VCardFileStorage.cpp index a246838..4933d0c 100644 --- a/Swiften/VCards/VCardFileStorage.cpp +++ b/Swift/Controllers/Storages/VCardFileStorage.cpp @@ -4,22 +4,26 @@ * See Documentation/Licenses/GPLv3.txt for more information. */ -#include "Swiften/VCards/VCardFileStorage.h" +#include "Swift/Controllers/Storages/VCardFileStorage.h" #include <boost/filesystem/fstream.hpp> +#include <boost/filesystem.hpp> +#include <iostream> +#include <Swiften/Entity/GenericPayloadPersister.h> #include <Swiften/Base/String.h> #include <Swiften/StringCodecs/Hexify.h> #include <Swiften/StringCodecs/SHA1.h> #include <Swiften/Base/foreach.h> #include "Swiften/JID/JID.h" -#include "Swiften/Base/ByteArray.h" #include "Swiften/Elements/VCard.h" #include "Swiften/Serializer/PayloadSerializers/VCardSerializer.h" #include "Swiften/Parser/PayloadParsers/UnitTest/PayloadParserTester.h" #include "Swiften/Parser/PayloadParsers/VCardParser.h" -namespace Swift { +using namespace Swift; + +typedef GenericPayloadPersister<VCard, VCardParser, VCardSerializer> VCardPersister; VCardFileStorage::VCardFileStorage(boost::filesystem::path dir) : vcardsPath(dir) { cacheFile = vcardsPath / "phashes"; @@ -48,34 +52,11 @@ VCardFileStorage::VCardFileStorage(boost::filesystem::path dir) : vcardsPath(dir } boost::shared_ptr<VCard> VCardFileStorage::getVCard(const JID& jid) const { - boost::filesystem::path vcardPath(getVCardPath(jid)); - if (boost::filesystem::exists(vcardPath)) { - ByteArray data; - data.readFromFile(vcardPath.string()); - - VCardParser parser; - PayloadParserTester tester(&parser); - tester.parse(data.toString()); - return boost::dynamic_pointer_cast<VCard>(parser.getPayload()); - } - else { - return boost::shared_ptr<VCard>(); - } + return VCardPersister().loadPayloadGeneric(getVCardPath(jid)); } void VCardFileStorage::setVCard(const JID& jid, VCard::ref v) { - boost::filesystem::path vcardPath(getVCardPath(jid)); - if (!boost::filesystem::exists(vcardPath.parent_path())) { - try { - boost::filesystem::create_directories(vcardPath.parent_path()); - } - catch (const boost::filesystem::filesystem_error& e) { - std::cerr << "ERROR: " << e.what() << std::endl; - } - } - boost::filesystem::ofstream file(getVCardPath(jid)); - file << VCardSerializer().serializePayload(v); - file.close(); + VCardPersister().savePayload(v, getVCardPath(jid)); getAndUpdatePhotoHash(jid, v); } @@ -124,6 +105,3 @@ void VCardFileStorage::savePhotoHashes() const { std::cerr << "Error writing vcards file" << std::endl; } } - - -} diff --git a/Swiften/VCards/VCardFileStorage.h b/Swift/Controllers/Storages/VCardFileStorage.h index 26bf4b2..ba422f4 100644 --- a/Swiften/VCards/VCardFileStorage.h +++ b/Swift/Controllers/Storages/VCardFileStorage.h @@ -7,7 +7,7 @@ #pragma once #include <boost/shared_ptr.hpp> -#include <boost/filesystem.hpp> +#include <boost/filesystem/path.hpp> #include <string> #include <map> diff --git a/Swift/Controllers/UIEvents/RequestAdHocUIEvent.h b/Swift/Controllers/UIEvents/RequestAdHocUIEvent.h new file mode 100644 index 0000000..c3b4b49 --- /dev/null +++ b/Swift/Controllers/UIEvents/RequestAdHocUIEvent.h @@ -0,0 +1,21 @@ +/* + * Copyright (c) 2010 Kevin Smith + * Licensed under the GNU General Public License v3. + * See Documentation/Licenses/GPLv3.txt for more information. + */ + +#pragma once + +#include <Swift/Controllers/UIInterfaces/MainWindow.h> + +#include <Swift/Controllers/UIEvents/UIEvent.h> + +namespace Swift { + class RequestAdHocUIEvent : public UIEvent { + public: + RequestAdHocUIEvent(const DiscoItems::Item& command) : command_(command) {}; + const DiscoItems::Item& getCommand() const {return command_;} + private: + DiscoItems::Item command_; + }; +} diff --git a/Swift/Controllers/UIEvents/RequestJoinMUCUIEvent.h b/Swift/Controllers/UIEvents/RequestJoinMUCUIEvent.h index dd2ff6c..2c7b105 100644 --- a/Swift/Controllers/UIEvents/RequestJoinMUCUIEvent.h +++ b/Swift/Controllers/UIEvents/RequestJoinMUCUIEvent.h @@ -6,18 +6,25 @@ #pragma once -#include <boost/optional.hpp> #include <boost/shared_ptr.hpp> - #include <string> + #include <Swift/Controllers/UIEvents/UIEvent.h> +#include <Swiften/JID/JID.h> namespace Swift { class RequestJoinMUCUIEvent : public UIEvent { public: typedef boost::shared_ptr<RequestJoinMUCUIEvent> ref; - RequestJoinMUCUIEvent() { + RequestJoinMUCUIEvent(const JID& room = JID()) : room(room) { } + + const JID& getRoom() const { + return room; + } + + private: + JID room; }; } diff --git a/Swift/Controllers/UIInterfaces/AdHocCommandWindow.h b/Swift/Controllers/UIInterfaces/AdHocCommandWindow.h new file mode 100644 index 0000000..f7a5d39 --- /dev/null +++ b/Swift/Controllers/UIInterfaces/AdHocCommandWindow.h @@ -0,0 +1,14 @@ +/* + * Copyright (c) 2010 Kevin Smith + * Licensed under the GNU General Public License v3. + * See Documentation/Licenses/GPLv3.txt for more information. + */ + +#pragma once + +namespace Swift { + class AdHocCommandWindow { + public: + virtual ~AdHocCommandWindow() {}; + }; +} diff --git a/Swift/Controllers/UIInterfaces/AdHocCommandWindowFactory.h b/Swift/Controllers/UIInterfaces/AdHocCommandWindowFactory.h new file mode 100644 index 0000000..ae77180 --- /dev/null +++ b/Swift/Controllers/UIInterfaces/AdHocCommandWindowFactory.h @@ -0,0 +1,22 @@ +/* + * Copyright (c) 2010-2011 Kevin Smith + * Licensed under the GNU General Public License v3. + * See Documentation/Licenses/GPLv3.txt for more information. + */ + +#pragma once + +#include <Swift/Controllers/UIInterfaces/AdHocCommandWindow.h> +#include <Swiften/AdHoc/OutgoingAdHocCommandSession.h> + +namespace Swift { + class AdHocCommandWindowFactory { + public: + virtual ~AdHocCommandWindowFactory() {} + /** + * The UI should deal with the lifetime of this window (i.e. DeleteOnClose), + * so the result isn't returned. + */ + virtual void createAdHocCommandWindow(boost::shared_ptr<OutgoingAdHocCommandSession> command) = 0; + }; +} diff --git a/Swift/Controllers/UIInterfaces/ChatListWindow.h b/Swift/Controllers/UIInterfaces/ChatListWindow.h index a2a0874..f717684 100644 --- a/Swift/Controllers/UIInterfaces/ChatListWindow.h +++ b/Swift/Controllers/UIInterfaces/ChatListWindow.h @@ -1,23 +1,35 @@ /* - * Copyright (c) 2010 Kevin Smith + * Copyright (c) 2010-2011 Kevin Smith * Licensed under the GNU General Public License v3. * See Documentation/Licenses/GPLv3.txt for more information. */ #pragma once +#include <list> #include <boost/shared_ptr.hpp> - -#include "Swiften/MUC/MUCBookmark.h" +#include <Swiften/MUC/MUCBookmark.h> namespace Swift { class ChatListWindow { public: + class Chat { + public: + Chat(const JID& jid, const std::string& chatName, const std::string& activity, bool isMUC, const std::string& nick = "") : jid(jid), chatName(chatName), activity(activity), isMUC(isMUC), nick(nick) {} + /** Assume that nicks aren't important for equality */ + bool operator==(const Chat& other) const {return jid == other.jid && isMUC == other.isMUC;}; + JID jid; + std::string chatName; + std::string activity; + bool isMUC; + std::string nick; + }; virtual ~ChatListWindow(); virtual void setBookmarksEnabled(bool enabled) = 0; virtual void addMUCBookmark(const MUCBookmark& bookmark) = 0; virtual void removeMUCBookmark(const MUCBookmark& bookmark) = 0; - virtual void clear() = 0; + virtual void setRecents(const std::list<Chat>& recents) = 0; + virtual void clearBookmarks() = 0; }; } diff --git a/Swift/Controllers/UIInterfaces/ChatWindow.h b/Swift/Controllers/UIInterfaces/ChatWindow.h index c7bcf1e..aa4416b 100644 --- a/Swift/Controllers/UIInterfaces/ChatWindow.h +++ b/Swift/Controllers/UIInterfaces/ChatWindow.h @@ -40,6 +40,7 @@ namespace Swift { virtual void addSystemMessage(const std::string& message) = 0; virtual void addPresenceMessage(const std::string& message) = 0; virtual void addErrorMessage(const std::string& message) = 0; + virtual void replaceMessage(const std::string& message, const std::string& id, const boost::posix_time::ptime& time) = 0; virtual void setContactChatState(ChatState::ChatStateType state) = 0; virtual void setName(const std::string& name) = 0; @@ -61,9 +62,11 @@ namespace Swift { boost::signal<void ()> onClosed; boost::signal<void ()> onAllMessagesRead; - boost::signal<void (const std::string&)> onSendMessageRequest; + boost::signal<void (const std::string&, bool isCorrection)> onSendMessageRequest; + boost::signal<void ()> onSendCorrectionMessageRequest; boost::signal<void ()> onUserTyping; boost::signal<void ()> onUserCancelsTyping; + boost::signal<void (bool correction)> onSendMessageCorrection; }; } #endif diff --git a/Swift/Controllers/UIInterfaces/MainWindow.h b/Swift/Controllers/UIInterfaces/MainWindow.h index 2fd463b..93584e7 100644 --- a/Swift/Controllers/UIInterfaces/MainWindow.h +++ b/Swift/Controllers/UIInterfaces/MainWindow.h @@ -9,6 +9,7 @@ #include <string> #include "Swiften/JID/JID.h" #include "Swiften/Elements/StatusShow.h" +#include "Swiften/Elements/DiscoItems.h" #include "Swiften/Base/boost_bsignals.h" #include <boost/shared_ptr.hpp> @@ -33,6 +34,7 @@ namespace Swift { /** Must be able to cope with NULL to clear the roster */ virtual void setRosterModel(Roster* roster) = 0; virtual void setConnecting() = 0; + virtual void setAvailableAdHocCommands(const std::vector<DiscoItems::Item>& commands) = 0; boost::signal<void (StatusShow::Type, const std::string&)> onChangeStatusRequest; boost::signal<void ()> onSignOutRequest; diff --git a/Swift/Controllers/UIInterfaces/UIFactory.h b/Swift/Controllers/UIInterfaces/UIFactory.h index 9b36ac5..57f55d0 100644 --- a/Swift/Controllers/UIInterfaces/UIFactory.h +++ b/Swift/Controllers/UIInterfaces/UIFactory.h @@ -17,6 +17,7 @@ #include <Swift/Controllers/UIInterfaces/XMLConsoleWidgetFactory.h> #include <Swift/Controllers/UIInterfaces/ProfileWindowFactory.h> #include <Swift/Controllers/UIInterfaces/ContactEditWindowFactory.h> +#include <Swift/Controllers/UIInterfaces/AdHocCommandWindowFactory.h> namespace Swift { class UIFactory : @@ -30,7 +31,8 @@ namespace Swift { public UserSearchWindowFactory, public JoinMUCWindowFactory, public ProfileWindowFactory, - public ContactEditWindowFactory { + public ContactEditWindowFactory, + public AdHocCommandWindowFactory { public: virtual ~UIFactory() {} }; diff --git a/Swift/Controllers/UnitTest/ChatMessageSummarizerTest.cpp b/Swift/Controllers/UnitTest/ChatMessageSummarizerTest.cpp new file mode 100644 index 0000000..ee0ee9f --- /dev/null +++ b/Swift/Controllers/UnitTest/ChatMessageSummarizerTest.cpp @@ -0,0 +1,122 @@ +/* + * Copyright (c) 2011 Kevin Smith + * Licensed under the GNU General Public License v3. + * See Documentation/Licenses/GPLv3.txt for more information. + */ + +#include <cppunit/extensions/HelperMacros.h> +#include <cppunit/extensions/TestFactoryRegistry.h> + +#include "Swift/Controllers/ChatMessageSummarizer.h" + +using namespace Swift; +using namespace std; + +class ChatMessageSummarizerTest : public CppUnit::TestFixture { + CPPUNIT_TEST_SUITE(ChatMessageSummarizerTest); + CPPUNIT_TEST(testEmpty); + CPPUNIT_TEST(testCurrentNone); + CPPUNIT_TEST(testCurrentCount); + CPPUNIT_TEST(testCurrentCountOthersNone); + CPPUNIT_TEST(testCurrentCountOtherCount); + CPPUNIT_TEST(testCurrentNoneOtherCount); + CPPUNIT_TEST(testCurrentCountOthersCount); + CPPUNIT_TEST(testCurrentNoneOthersCount); + CPPUNIT_TEST(testCurrentCountSomeOthersCount); + CPPUNIT_TEST_SUITE_END(); + +public: + ChatMessageSummarizerTest() {}; + + void setUp() { + + } + + void testEmpty() { + string current(""); + vector<UnreadPair> unreads; + ChatMessageSummarizer summary; + CPPUNIT_ASSERT_EQUAL(current, summary.getSummary(current, unreads)); + } + + void testCurrentNone() { + string current("Bob"); + vector<UnreadPair> unreads; + unreads.push_back(UnreadPair("Bob", 0)); + ChatMessageSummarizer summary; + CPPUNIT_ASSERT_EQUAL(current, summary.getSummary(current, unreads)); + } + + void testCurrentCount() { + string current("Bob"); + vector<UnreadPair> unreads; + unreads.push_back(UnreadPair("Bob", 3)); + ChatMessageSummarizer summary; + CPPUNIT_ASSERT_EQUAL(string("Bob (3)"), summary.getSummary(current, unreads)); + } + + void testCurrentCountOthersNone() { + string current("Bob"); + vector<UnreadPair> unreads; + unreads.push_back(UnreadPair("Bert", 0)); + unreads.push_back(UnreadPair("Bob", 3)); + unreads.push_back(UnreadPair("Betty", 0)); + ChatMessageSummarizer summary; + CPPUNIT_ASSERT_EQUAL(string("Bob (3)"), summary.getSummary(current, unreads)); + } + + void testCurrentCountOtherCount() { + string current("Bob"); + vector<UnreadPair> unreads; + unreads.push_back(UnreadPair("Bert", 0)); + unreads.push_back(UnreadPair("Bob", 3)); + unreads.push_back(UnreadPair("Betty", 7)); + ChatMessageSummarizer summary; + CPPUNIT_ASSERT_EQUAL(string("Bob (3), Betty (7)"), summary.getSummary(current, unreads)); + } + + void testCurrentNoneOtherCount() { + string current("Bob"); + vector<UnreadPair> unreads; + unreads.push_back(UnreadPair("Bert", 0)); + unreads.push_back(UnreadPair("Bob", 0)); + unreads.push_back(UnreadPair("Betty", 7)); + ChatMessageSummarizer summary; + CPPUNIT_ASSERT_EQUAL(string("Bob, Betty (7)"), summary.getSummary(current, unreads)); + } + + void testCurrentNoneOthersCount() { + string current("Bob"); + vector<UnreadPair> unreads; + unreads.push_back(UnreadPair("Bert", 2)); + unreads.push_back(UnreadPair("Bob", 0)); + unreads.push_back(UnreadPair("Betty", 7)); + ChatMessageSummarizer summary; + CPPUNIT_ASSERT_EQUAL(string("Bob and 2 others (9)"), summary.getSummary(current, unreads)); + } + + void testCurrentCountOthersCount() { + string current("Bob"); + vector<UnreadPair> unreads; + unreads.push_back(UnreadPair("Bert", 2)); + unreads.push_back(UnreadPair("Bob", 11)); + unreads.push_back(UnreadPair("Betty", 7)); + ChatMessageSummarizer summary; + CPPUNIT_ASSERT_EQUAL(string("Bob (11) and 2 others (9)"), summary.getSummary(current, unreads)); + } + + void testCurrentCountSomeOthersCount() { + string current("Bob"); + vector<UnreadPair> unreads; + unreads.push_back(UnreadPair("Bert", 2)); + unreads.push_back(UnreadPair("Beverly", 0)); + unreads.push_back(UnreadPair("Bob", 11)); + unreads.push_back(UnreadPair("Beatrice", 0)); + unreads.push_back(UnreadPair("Betty", 7)); + ChatMessageSummarizer summary; + CPPUNIT_ASSERT_EQUAL(string("Bob (11) and 2 others (9)"), summary.getSummary(current, unreads)); + } + +}; + +CPPUNIT_TEST_SUITE_REGISTRATION(ChatMessageSummarizerTest); diff --git a/Swift/Controllers/UnitTest/MockChatWindow.h b/Swift/Controllers/UnitTest/MockChatWindow.h index 53a90a7..82c5b52 100644 --- a/Swift/Controllers/UnitTest/MockChatWindow.h +++ b/Swift/Controllers/UnitTest/MockChatWindow.h @@ -34,12 +34,13 @@ namespace Swift { virtual void setRosterModel(Roster* /*roster*/) {}; virtual void setTabComplete(TabComplete*) {}; virtual void replaceLastMessage(const std::string&) {}; + virtual void replaceMessage(const std::string&, const std::string&, const boost::posix_time::ptime&) {}; void setAckState(const std::string& /*id*/, AckState /*state*/) {}; virtual void flash() {}; boost::signal<void ()> onClosed; boost::signal<void ()> onAllMessagesRead; - boost::signal<void (const std::string&)> onSendMessageRequest; + boost::signal<void (const std::string&, bool isCorrection)> onSendMessageRequest; std::string name_; std::string lastMessageBody_; diff --git a/Swift/Controllers/UnitTest/MockMainWindow.h b/Swift/Controllers/UnitTest/MockMainWindow.h index afa5c2a..f773062 100644 --- a/Swift/Controllers/UnitTest/MockMainWindow.h +++ b/Swift/Controllers/UnitTest/MockMainWindow.h @@ -20,6 +20,7 @@ namespace Swift { virtual void setMyAvatarPath(const std::string& /*path*/) {}; virtual void setMyStatusText(const std::string& /*status*/) {}; virtual void setMyStatusType(StatusShow::Type /*type*/) {}; + virtual void setAvailableAdHocCommands(const std::vector<DiscoItems::Item>& /*commands*/) {}; virtual void setConnecting() {}; Roster* roster; diff --git a/Swift/Controllers/XMPPEvents/EventController.cpp b/Swift/Controllers/XMPPEvents/EventController.cpp index 7f8f216..98fd634 100644 --- a/Swift/Controllers/XMPPEvents/EventController.cpp +++ b/Swift/Controllers/XMPPEvents/EventController.cpp @@ -9,6 +9,7 @@ #include <boost/bind.hpp> #include <algorithm> +#include <Swiften/Base/foreach.h> #include "Swift/Controllers/XMPPEvents/MessageEvent.h" #include "Swift/Controllers/XMPPEvents/ErrorEvent.h" #include "Swift/Controllers/XMPPEvents/SubscriptionRequestEvent.h" diff --git a/Swift/Controllers/XMPPURIController.cpp b/Swift/Controllers/XMPPURIController.cpp new file mode 100644 index 0000000..00759b8 --- /dev/null +++ b/Swift/Controllers/XMPPURIController.cpp @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2011 Remko Tronçon + * Licensed under the GNU General Public License v3. + * See Documentation/Licenses/GPLv3.txt for more information. + */ + +#include <Swift/Controllers/XMPPURIController.h> + +#include <boost/bind.hpp> +#include <boost/smart_ptr/make_shared.hpp> + +#include <SwifTools/URIHandler/URIHandler.h> +#include <SwifTools/URIHandler/XMPPURI.h> +#include <Swift/Controllers/UIEvents/UIEventStream.h> +#include <Swift/Controllers/UIEvents/RequestJoinMUCUIEvent.h> +#include <Swift/Controllers/UIEvents/RequestChatUIEvent.h> + +using namespace Swift; + +XMPPURIController::XMPPURIController(URIHandler* uriHandler, UIEventStream* uiEventStream) : uriHandler(uriHandler), uiEventStream(uiEventStream) { + uriHandler->onURI.connect(boost::bind(&XMPPURIController::handleURI, this, _1)); +} + +XMPPURIController::~XMPPURIController() { + uriHandler->onURI.disconnect(boost::bind(&XMPPURIController::handleURI, this, _1)); +} + +void XMPPURIController::handleURI(const std::string& s) { + XMPPURI uri = XMPPURI::fromString(s); + if (!uri.isNull()) { + if (uri.getQueryType() == "join") { + uiEventStream->send(boost::make_shared<RequestJoinMUCUIEvent>(uri.getPath())); + } + else { + uiEventStream->send(boost::make_shared<RequestChatUIEvent>(uri.getPath())); + } + } +} diff --git a/Swift/Controllers/XMPPURIController.h b/Swift/Controllers/XMPPURIController.h new file mode 100644 index 0000000..54534d4 --- /dev/null +++ b/Swift/Controllers/XMPPURIController.h @@ -0,0 +1,32 @@ +/* + * Copyright (c) 2011 Remko Tronçon + * Licensed under the GNU General Public License v3. + * See Documentation/Licenses/GPLv3.txt for more information. + */ + +#pragma once + +#include <string> +#include <Swiften/Base/boost_bsignals.h> + +namespace Swift { + class URIHandler; + class JID; + class UIEventStream; + + class XMPPURIController { + public: + XMPPURIController(URIHandler* uriHandler, UIEventStream* uiEventStream); + ~XMPPURIController(); + + boost::signal<void (const JID&)> onStartChat; + boost::signal<void (const JID&)> onJoinMUC; + + private: + void handleURI(const std::string&); + + private: + URIHandler* uriHandler; + UIEventStream* uiEventStream; + }; +} diff --git a/Swift/QtUI/.gitignore b/Swift/QtUI/.gitignore index f539e86..53acb9f 100644 --- a/Swift/QtUI/.gitignore +++ b/Swift/QtUI/.gitignore @@ -1,3 +1,4 @@ Swift BuildVersion.h *.dmg +swift-open-uri diff --git a/Swift/QtUI/ChatList/ChatListDelegate.cpp b/Swift/QtUI/ChatList/ChatListDelegate.cpp index 274a10a..b2bfe0a 100644 --- a/Swift/QtUI/ChatList/ChatListDelegate.cpp +++ b/Swift/QtUI/ChatList/ChatListDelegate.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2010 Kevin Smith + * Copyright (c) 2010-2011 Kevin Smith * Licensed under the GNU General Public License v3. * See Documentation/Licenses/GPLv3.txt for more information. */ @@ -11,6 +11,7 @@ #include "Swift/QtUI/Roster/GroupItemDelegate.h" #include "Swift/QtUI/ChatList/ChatListItem.h" #include "Swift/QtUI/ChatList/ChatListMUCItem.h" +#include "Swift/QtUI/ChatList/ChatListRecentItem.h" #include "Swift/QtUI/ChatList/ChatListGroupItem.h" namespace Swift { @@ -27,7 +28,11 @@ QSize ChatListDelegate::sizeHint(const QStyleOptionViewItem& option, const QMode ChatListItem* item = static_cast<ChatListItem*>(index.internalPointer()); if (item && dynamic_cast<ChatListMUCItem*>(item)) { return mucSizeHint(option, index); - } else if (item && dynamic_cast<ChatListGroupItem*>(item)) { + } + else if (item && dynamic_cast<ChatListRecentItem*>(item)) { + return recentSizeHint(option, index); + } + else if (item && dynamic_cast<ChatListGroupItem*>(item)) { return groupDelegate_->sizeHint(option, index); } return QStyledItemDelegate::sizeHint(option, index); @@ -40,14 +45,23 @@ QSize ChatListDelegate::mucSizeHint(const QStyleOptionViewItem& /*option*/, cons return QSize(150, sizeByText); } +QSize ChatListDelegate::recentSizeHint(const QStyleOptionViewItem& option, const QModelIndex& index) const { + return mucSizeHint(option, index); +} + void ChatListDelegate::paint(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const { ChatListItem* item = static_cast<ChatListItem*>(index.internalPointer()); if (item && dynamic_cast<ChatListMUCItem*>(item)) { paintMUC(painter, option, dynamic_cast<ChatListMUCItem*>(item)); - } else if (item && dynamic_cast<ChatListGroupItem*>(item)) { + } + else if (item && dynamic_cast<ChatListRecentItem*>(item)) { + paintRecent(painter, option, dynamic_cast<ChatListRecentItem*>(item)); + } + else if (item && dynamic_cast<ChatListGroupItem*>(item)) { ChatListGroupItem* group = dynamic_cast<ChatListGroupItem*>(item); groupDelegate_->paint(painter, option, group->data(Qt::DisplayRole).toString(), group->rowCount(), option.state & QStyle::State_Open); - } else { + } + else { QStyledItemDelegate::paint(painter, option, index); } } @@ -78,9 +92,40 @@ void ChatListDelegate::paintMUC(QPainter* painter, const QStyleOptionViewItem& o painter->setPen(QPen(QColor(160,160,160))); QRect detailRegion(textRegion.adjusted(0, nameHeight, 0, 0)); - DelegateCommons::drawElidedText(painter, detailRegion, item->data(DetailTextRole).toString()); + DelegateCommons::drawElidedText(painter, detailRegion, item->data(ChatListMUCItem::DetailTextRole).toString()); painter->restore(); } +void ChatListDelegate::paintRecent(QPainter* painter, const QStyleOptionViewItem& option, ChatListRecentItem* item) const { + painter->save(); + QRect fullRegion(option.rect); + if ( option.state & QStyle::State_Selected ) { + painter->fillRect(fullRegion, option.palette.highlight()); + painter->setPen(option.palette.highlightedText().color()); + } else { + QColor nameColor = item->data(Qt::TextColorRole).value<QColor>(); + painter->setPen(QPen(nameColor)); + } + + QFontMetrics nameMetrics(common_.nameFont); + painter->setFont(common_.nameFont); + int extraFontWidth = nameMetrics.width("H"); + int leftOffset = common_.horizontalMargin * 2 + extraFontWidth / 2; + QRect textRegion(fullRegion.adjusted(leftOffset, 0, 0, 0)); + + int nameHeight = nameMetrics.height() + common_.verticalMargin; + QRect nameRegion(textRegion.adjusted(0, common_.verticalMargin, 0, 0)); + + DelegateCommons::drawElidedText(painter, nameRegion, item->data(Qt::DisplayRole).toString()); + + painter->setFont(common_.detailFont); + painter->setPen(QPen(QColor(160,160,160))); + + QRect detailRegion(textRegion.adjusted(0, nameHeight, 0, 0)); + DelegateCommons::drawElidedText(painter, detailRegion, item->data(ChatListRecentItem::DetailTextRole).toString()); + + painter->restore(); +} + } diff --git a/Swift/QtUI/ChatList/ChatListDelegate.h b/Swift/QtUI/ChatList/ChatListDelegate.h index f6c6c40..a898df4 100644 --- a/Swift/QtUI/ChatList/ChatListDelegate.h +++ b/Swift/QtUI/ChatList/ChatListDelegate.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2010 Kevin Smith + * Copyright (c) 2010-2011 Kevin Smith * Licensed under the GNU General Public License v3. * See Documentation/Licenses/GPLv3.txt for more information. */ @@ -12,6 +12,7 @@ namespace Swift { class ChatListMUCItem; + class ChatListRecentItem; class ChatListDelegate : public QStyledItemDelegate { public: ChatListDelegate(); @@ -20,7 +21,9 @@ namespace Swift { void paint(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const; private: void paintMUC(QPainter* painter, const QStyleOptionViewItem& option, ChatListMUCItem* item) const; + void paintRecent(QPainter* painter, const QStyleOptionViewItem& option, ChatListRecentItem* item) const; QSize mucSizeHint(const QStyleOptionViewItem& /*option*/, const QModelIndex& /*index*/ ) const; + QSize recentSizeHint(const QStyleOptionViewItem& /*option*/, const QModelIndex& /*index*/ ) const; DelegateCommons common_; GroupItemDelegate* groupDelegate_; diff --git a/Swift/QtUI/ChatList/ChatListGroupItem.h b/Swift/QtUI/ChatList/ChatListGroupItem.h index cc4d4af..a1e479f 100644 --- a/Swift/QtUI/ChatList/ChatListGroupItem.h +++ b/Swift/QtUI/ChatList/ChatListGroupItem.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2010 Kevin Smith + * Copyright (c) 2010-2011 Kevin Smith * Licensed under the GNU General Public License v3. * See Documentation/Licenses/GPLv3.txt for more information. */ @@ -13,8 +13,8 @@ namespace Swift { class ChatListGroupItem : public ChatListItem { public: - ChatListGroupItem(const QString& name, ChatListGroupItem* parent) : ChatListItem(parent), name_(name) {}; - void addItem(ChatListItem* item) {items_.push_back(item); qStableSort(items_.begin(), items_.end(), pointerItemLessThan);}; + ChatListGroupItem(const QString& name, ChatListGroupItem* parent, bool sorted = true) : ChatListItem(parent), name_(name), sorted_(sorted) {}; + void addItem(ChatListItem* item) {items_.push_back(item); if (sorted_) {qStableSort(items_.begin(), items_.end(), pointerItemLessThan);}}; void remove(int index) {items_.removeAt(index);}; int rowCount() {return items_.size();}; ChatListItem* item(int i) {return items_[i];}; @@ -30,5 +30,6 @@ namespace Swift { QString name_; QList<ChatListItem*> items_; + bool sorted_; }; } diff --git a/Swift/QtUI/ChatList/ChatListMUCItem.h b/Swift/QtUI/ChatList/ChatListMUCItem.h index 068f5d6..f26aa67 100644 --- a/Swift/QtUI/ChatList/ChatListMUCItem.h +++ b/Swift/QtUI/ChatList/ChatListMUCItem.h @@ -15,14 +15,14 @@ #include "Swift/QtUI/ChatList/ChatListItem.h" namespace Swift { - enum MUCItemRoles { - DetailTextRole = Qt::UserRole/*, - AvatarRole = Qt::UserRole + 1, - PresenceIconRole = Qt::UserRole + 2, - StatusShowTypeRole = Qt::UserRole + 3*/ - }; class ChatListMUCItem : public ChatListItem { public: + enum MUCItemRoles { + DetailTextRole = Qt::UserRole/*, + AvatarRole = Qt::UserRole + 1, + PresenceIconRole = Qt::UserRole + 2, + StatusShowTypeRole = Qt::UserRole + 3*/ + }; ChatListMUCItem(const MUCBookmark& bookmark, ChatListGroupItem* parent); const MUCBookmark& getBookmark(); QVariant data(int role) const; diff --git a/Swift/QtUI/ChatList/ChatListModel.cpp b/Swift/QtUI/ChatList/ChatListModel.cpp index ba7b766..681c1c2 100644 --- a/Swift/QtUI/ChatList/ChatListModel.cpp +++ b/Swift/QtUI/ChatList/ChatListModel.cpp @@ -1,22 +1,25 @@ /* - * Copyright (c) 2010 Kevin Smith + * Copyright (c) 2010-2011 Kevin Smith * Licensed under the GNU General Public License v3. * See Documentation/Licenses/GPLv3.txt for more information. */ -#include "Swift/QtUI/ChatList/ChatListModel.h" +#include <Swift/QtUI/ChatList/ChatListModel.h> -#include "Swift/QtUI/ChatList/ChatListMUCItem.h" +#include <Swift/QtUI/ChatList/ChatListMUCItem.h> +#include <Swift/QtUI/ChatList/ChatListRecentItem.h> namespace Swift { ChatListModel::ChatListModel() { - root_ = new ChatListGroupItem("", NULL); + root_ = new ChatListGroupItem("", NULL, false); mucBookmarks_ = new ChatListGroupItem(tr("Bookmarked Rooms"), root_); + recents_ = new ChatListGroupItem(tr("Recent Chats"), root_, false); + root_->addItem(recents_); root_->addItem(mucBookmarks_); } -void ChatListModel::clear() { +void ChatListModel::clearBookmarks() { emit layoutAboutToBeChanged(); mucBookmarks_->clear(); emit layoutChanged(); @@ -43,6 +46,15 @@ void ChatListModel::removeMUCBookmark(const Swift::MUCBookmark& bookmark) { } } +void ChatListModel::setRecents(const std::list<ChatListWindow::Chat>& recents) { + emit layoutAboutToBeChanged(); + recents_->clear(); + foreach (const ChatListWindow::Chat chat, recents) { + recents_->addItem(new ChatListRecentItem(chat, recents_)); + } + emit layoutChanged(); +} + int ChatListModel::columnCount(const QModelIndex& /*parent*/) const { return 1; } diff --git a/Swift/QtUI/ChatList/ChatListModel.h b/Swift/QtUI/ChatList/ChatListModel.h index adde148..8e7828c 100644 --- a/Swift/QtUI/ChatList/ChatListModel.h +++ b/Swift/QtUI/ChatList/ChatListModel.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2010 Kevin Smith + * Copyright (c) 2010-2011 Kevin Smith * Licensed under the GNU General Public License v3. * See Documentation/Licenses/GPLv3.txt for more information. */ @@ -11,9 +11,10 @@ #include <QAbstractItemModel> #include <QList> -#include "Swiften/MUC/MUCBookmark.h" +#include <Swiften/MUC/MUCBookmark.h> +#include <Swift/Controllers/UIInterfaces/ChatListWindow.h> -#include "Swift/QtUI/ChatList/ChatListGroupItem.h" +#include <Swift/QtUI/ChatList/ChatListGroupItem.h> namespace Swift { class ChatListModel : public QAbstractItemModel { @@ -28,9 +29,11 @@ namespace Swift { QModelIndex parent(const QModelIndex& index) const; int rowCount(const QModelIndex& parent = QModelIndex()) const; ChatListItem* getItemForIndex(const QModelIndex& index) const; - void clear(); + void clearBookmarks(); + void setRecents(const std::list<ChatListWindow::Chat>& recents); private: ChatListGroupItem* mucBookmarks_; + ChatListGroupItem* recents_; ChatListGroupItem* root_; }; diff --git a/Swift/QtUI/ChatList/ChatListRecentItem.cpp b/Swift/QtUI/ChatList/ChatListRecentItem.cpp new file mode 100644 index 0000000..8b6707c --- /dev/null +++ b/Swift/QtUI/ChatList/ChatListRecentItem.cpp @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2011 Kevin Smith + * Licensed under the GNU General Public License v3. + * See Documentation/Licenses/GPLv3.txt for more information. + */ + +#include <Swift/QtUI/ChatList/ChatListRecentItem.h> + +#include <Swift/QtUI/QtSwiftUtil.h> + +namespace Swift { +ChatListRecentItem::ChatListRecentItem(const ChatListWindow::Chat& chat, ChatListGroupItem* parent) : ChatListItem(parent), chat_(chat) { + +} + +const ChatListWindow::Chat& ChatListRecentItem::getChat() { + return chat_; +} + +QVariant ChatListRecentItem::data(int role) const { + switch (role) { + case Qt::DisplayRole: return P2QSTRING(chat_.chatName); + case DetailTextRole: return P2QSTRING(chat_.activity); + /*case Qt::TextColorRole: return textColor_; + case Qt::BackgroundColorRole: return backgroundColor_; + case Qt::ToolTipRole: return isContact() ? toolTipString() : QVariant(); + case StatusTextRole: return statusText_; + case AvatarRole: return avatar_; + case PresenceIconRole: return getPresenceIcon();*/ + default: return QVariant(); + } +} + +} diff --git a/Swift/QtUI/ChatList/ChatListRecentItem.h b/Swift/QtUI/ChatList/ChatListRecentItem.h new file mode 100644 index 0000000..c2646cc --- /dev/null +++ b/Swift/QtUI/ChatList/ChatListRecentItem.h @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2011 Kevin Smith + * Licensed under the GNU General Public License v3. + * See Documentation/Licenses/GPLv3.txt for more information. + */ + +#pragma once + +#include <QList> + +#include <boost/shared_ptr.hpp> + +#include <Swiften/MUC/MUCBookmark.h> +#include <Swift/Controllers/UIInterfaces/ChatListWindow.h> + +#include <Swift/QtUI/ChatList/ChatListItem.h> + +namespace Swift { + class ChatListRecentItem : public ChatListItem { + public: + enum RecentItemRoles { + DetailTextRole = Qt::UserRole/*, + AvatarRole = Qt::UserRole + 1, + PresenceIconRole = Qt::UserRole + 2, + StatusShowTypeRole = Qt::UserRole + 3*/ + }; + ChatListRecentItem(const ChatListWindow::Chat& chat, ChatListGroupItem* parent); + const ChatListWindow::Chat& getChat(); + QVariant data(int role) const; + private: + ChatListWindow::Chat chat_; + }; +} diff --git a/Swift/QtUI/ChatList/QtChatListWindow.cpp b/Swift/QtUI/ChatList/QtChatListWindow.cpp index b532cdb..d71563d 100644 --- a/Swift/QtUI/ChatList/QtChatListWindow.cpp +++ b/Swift/QtUI/ChatList/QtChatListWindow.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2010 Kevin Smith + * Copyright (c) 2010-2011 Kevin Smith * Licensed under the GNU General Public License v3. * See Documentation/Licenses/GPLv3.txt for more information. */ @@ -10,9 +10,11 @@ #include <QContextMenuEvent> #include "Swift/QtUI/ChatList/ChatListMUCItem.h" +#include "Swift/QtUI/ChatList/ChatListRecentItem.h" #include "Swift/QtUI/QtAddBookmarkWindow.h" #include "Swift/QtUI/QtEditBookmarkWindow.h" #include "Swift/Controllers/UIEvents/JoinMUCUIEvent.h" +#include "Swift/Controllers/UIEvents/RequestChatUIEvent.h" #include "Swift/Controllers/UIEvents/AddMUCBookmarkUIEvent.h" #include "Swift/Controllers/UIEvents/RemoveMUCBookmarkUIEvent.h" #include "Swift/Controllers/UIEvents/EditMUCBookmarkUIEvent.h" @@ -68,19 +70,30 @@ void QtChatListWindow::setupContextMenus() { } void QtChatListWindow::handleItemActivated(const QModelIndex& index) { - if (!bookmarksEnabled_) { - return; - } ChatListItem* item = model_->getItemForIndex(index); ChatListMUCItem* mucItem = dynamic_cast<ChatListMUCItem*>(item); - if (mucItem) { + if (bookmarksEnabled_ && mucItem) { boost::shared_ptr<UIEvent> event(new JoinMUCUIEvent(mucItem->getBookmark().getRoom(), mucItem->getBookmark().getNick())); eventStream_->send(event); } + ChatListRecentItem* recentItem = dynamic_cast<ChatListRecentItem*>(item); + if (recentItem) { + boost::shared_ptr<UIEvent> event; + if (recentItem->getChat().isMUC) { + if (!bookmarksEnabled_) { + return; + } + return; + } + else { + event = boost::shared_ptr<UIEvent>(new RequestChatUIEvent(recentItem->getChat().jid)); + } + eventStream_->send(event); + } } -void QtChatListWindow::clear() { - model_->clear(); +void QtChatListWindow::clearBookmarks() { + model_->clearBookmarks(); } void QtChatListWindow::addMUCBookmark(const MUCBookmark& bookmark) { @@ -91,6 +104,10 @@ void QtChatListWindow::removeMUCBookmark(const MUCBookmark& bookmark) { model_->removeMUCBookmark(bookmark); } +void QtChatListWindow::setRecents(const std::list<ChatListWindow::Chat>& recents) { + model_->setRecents(recents); +} + void QtChatListWindow::handleRemoveBookmark() { ChatListMUCItem* mucItem = dynamic_cast<ChatListMUCItem*>(contextMenuItem_); if (!mucItem) return; diff --git a/Swift/QtUI/ChatList/QtChatListWindow.h b/Swift/QtUI/ChatList/QtChatListWindow.h index 3a3e95f..f5c12f6 100644 --- a/Swift/QtUI/ChatList/QtChatListWindow.h +++ b/Swift/QtUI/ChatList/QtChatListWindow.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2010 Kevin Smith + * Copyright (c) 2010-2011 Kevin Smith * Licensed under the GNU General Public License v3. * See Documentation/Licenses/GPLv3.txt for more information. */ @@ -23,7 +23,8 @@ namespace Swift { void addMUCBookmark(const MUCBookmark& bookmark); void removeMUCBookmark(const MUCBookmark& bookmark); void setBookmarksEnabled(bool enabled); - void clear(); + void setRecents(const std::list<ChatListWindow::Chat>& recents); + void clearBookmarks(); private slots: void handleItemActivated(const QModelIndex&); void handleAddBookmark(); diff --git a/Swift/QtUI/ChatSnippet.h b/Swift/QtUI/ChatSnippet.h index 3aa5fcc..7cbb3b3 100644 --- a/Swift/QtUI/ChatSnippet.h +++ b/Swift/QtUI/ChatSnippet.h @@ -17,7 +17,7 @@ namespace Swift { public: ChatSnippet(bool appendToPrevious); virtual ~ChatSnippet(); - + virtual const QString& getContent() const = 0; virtual QString getContinuationElementID() const { return ""; } @@ -26,7 +26,7 @@ namespace Swift { bool getAppendToPrevious() const { return appendToPrevious_; } - + static QString escape(const QString& original) { QString result(original); result.replace("%message%", "%message%"); @@ -37,11 +37,12 @@ namespace Swift { return result; } + static QString timeToEscapedString(const QDateTime& time); + protected: void setContinuationFallbackSnippet(boost::shared_ptr<ChatSnippet> continuationFallback) { continuationFallback_ = continuationFallback; } - static QString timeToEscapedString(const QDateTime& time); private: bool appendToPrevious_; boost::shared_ptr<ChatSnippet> continuationFallback_; diff --git a/Swift/QtUI/QtAdHocCommandWindow.cpp b/Swift/QtUI/QtAdHocCommandWindow.cpp new file mode 100644 index 0000000..a3bb077 --- /dev/null +++ b/Swift/QtUI/QtAdHocCommandWindow.cpp @@ -0,0 +1,137 @@ +/* + * Copyright (c) 2010-2011 Kevin Smith + * Licensed under the GNU General Public License v3. + * See Documentation/Licenses/GPLv3.txt for more information. + */ + +#include <Swift/QtUI/QtAdHocCommandWindow.h> + +#include <boost/bind.hpp> +#include <QBoxLayout> +#include <Swift/QtUI/QtFormWidget.h> +#include <Swiften/Elements/Command.h> + +namespace Swift { +QtAdHocCommandWindow::QtAdHocCommandWindow(boost::shared_ptr<OutgoingAdHocCommandSession> command) : command_(command) { + + formWidget_ = NULL; + + setAttribute(Qt::WA_DeleteOnClose); + command->onNextStageReceived.connect(boost::bind(&QtAdHocCommandWindow::handleNextStageReceived, this, _1)); + command->onError.connect(boost::bind(&QtAdHocCommandWindow::handleError, this, _1)); + command->start(); + + QBoxLayout* layout = new QBoxLayout(QBoxLayout::TopToBottom, this); + layout->setContentsMargins(0,0,0,0); + layout->setSpacing(2); + label_ = new QLabel(this); + layout->addWidget(label_); + QWidget* formContainer = new QWidget(this); + layout->addWidget(formContainer); + formLayout_ = new QBoxLayout(QBoxLayout::TopToBottom, formContainer); + QWidget* buttonsWidget = new QWidget(this); + layout->addWidget(buttonsWidget); + + QBoxLayout* buttonsLayout = new QBoxLayout(QBoxLayout::LeftToRight, buttonsWidget); + cancelButton_ = new QPushButton(tr("Cancel"), buttonsWidget); + buttonsLayout->addWidget(cancelButton_); + connect(cancelButton_, SIGNAL(clicked()), this, SLOT(handleCancelClicked())); + backButton_ = new QPushButton(tr("Back"), buttonsWidget); + buttonsLayout->addWidget(backButton_); + connect(backButton_, SIGNAL(clicked()), this, SLOT(handlePrevClicked())); + nextButton_ = new QPushButton(tr("Next"), buttonsWidget); + buttonsLayout->addWidget(nextButton_); + connect(nextButton_, SIGNAL(clicked()), this, SLOT(handleNextClicked())); + completeButton_ = new QPushButton(tr("Complete"), buttonsWidget); + buttonsLayout->addWidget(completeButton_); + connect(completeButton_, SIGNAL(clicked()), this, SLOT(handleCompleteClicked())); + nextButton_->setEnabled(false); + backButton_->setEnabled(false); + completeButton_->setEnabled(false); + actions_[Command::Next] = nextButton_; + actions_[Command::Prev] = backButton_; + actions_[Command::Complete] = completeButton_; + actions_[Command::Cancel] = cancelButton_; + show(); +} + +QtAdHocCommandWindow::~QtAdHocCommandWindow() { + +} + +void QtAdHocCommandWindow::handleCancelClicked() { + command_->cancel(); +} + +void QtAdHocCommandWindow::handlePrevClicked() { + command_->goBack(); +} + +void QtAdHocCommandWindow::handleNextClicked() { + command_->goNext(formWidget_ ? formWidget_->getCompletedForm() : Form::ref()); +} + +void QtAdHocCommandWindow::handleCompleteClicked() { + command_->complete(formWidget_ ? formWidget_->getCompletedForm() : Form::ref()); +} + +void QtAdHocCommandWindow::handleNextStageReceived(Command::ref command) { + if (command->getForm()) { + setForm(command->getForm()); + } else { + setNoForm(); + } + QString notes; + foreach (Command::Note note, command->getNotes()) { + if (!notes.isEmpty()) { + notes += "\n"; + QString qNote(note.note.c_str()); + switch (note.type) { + case Command::Note::Error: notes += tr("Error: %1").arg(qNote); break; + case Command::Note::Warn: notes += tr("Warning: %1").arg(qNote); break; + case Command::Note::Info: notes += qNote; break; + } + } + } + label_->setText(notes); + setAvailableActions(command); +} + +void QtAdHocCommandWindow::handleError(ErrorPayload::ref /*error*/) { + nextButton_->setEnabled(false); + backButton_->setEnabled(false); + completeButton_->setEnabled(false); + label_->setText(tr("Error executing command")); +} + +void QtAdHocCommandWindow::setForm(Form::ref form) { + delete formWidget_; + formWidget_ = new QtFormWidget(form, this); + formLayout_->addWidget(formWidget_); +} + +void QtAdHocCommandWindow::setNoForm() { + delete formWidget_; +} + +typedef std::pair<Command::Action, QPushButton*> ActionButton; + +void QtAdHocCommandWindow::setAvailableActions(Command::ref /*commandResult*/) { + foreach (ActionButton pair, actions_) { + OutgoingAdHocCommandSession::ActionState state = command_->getActionState(pair.first); + if (state & OutgoingAdHocCommandSession::Present) { + pair.second->show(); + } + else { + pair.second->hide(); + } + if (state & OutgoingAdHocCommandSession::Enabled) { + pair.second->setEnabled(true); + } + else { + pair.second->setEnabled(false); + } + } +} + +} diff --git a/Swift/QtUI/QtAdHocCommandWindow.h b/Swift/QtUI/QtAdHocCommandWindow.h new file mode 100644 index 0000000..adeb3e6 --- /dev/null +++ b/Swift/QtUI/QtAdHocCommandWindow.h @@ -0,0 +1,48 @@ +/* + * Copyright (c) 2010-2011 Kevin Smith + * Licensed under the GNU General Public License v3. + * See Documentation/Licenses/GPLv3.txt for more information. + */ + +#pragma once + +#include <QWidget> +#include <QPushButton> +#include <QLabel> + +#include <Swift/Controllers/UIInterfaces/AdHocCommandWindow.h> +#include <Swiften/AdHoc/OutgoingAdHocCommandSession.h> + +class QBoxLayout; + +namespace Swift { + class QtFormWidget; + class QtAdHocCommandWindow : public QWidget, public AdHocCommandWindow { + Q_OBJECT + public: + QtAdHocCommandWindow(boost::shared_ptr<OutgoingAdHocCommandSession> command); + virtual ~QtAdHocCommandWindow(); + private: + void handleNextStageReceived(Command::ref command); + void handleError(ErrorPayload::ref error); + void setForm(Form::ref); + void setNoForm(); + void setAvailableActions(Command::ref commandResult); + private slots: + void handleCancelClicked(); + void handlePrevClicked(); + void handleNextClicked(); + void handleCompleteClicked(); + private: + boost::shared_ptr<OutgoingAdHocCommandSession> command_; + QtFormWidget* formWidget_; + QBoxLayout* formLayout_; + Form::ref form_; + QLabel* label_; + QPushButton* backButton_; + QPushButton* nextButton_; + QPushButton* completeButton_; + QPushButton* cancelButton_; + std::map<Command::Action, QPushButton*> actions_; + }; +} diff --git a/Swift/QtUI/QtChatTabs.cpp b/Swift/QtUI/QtChatTabs.cpp index 25c7ca2..249080b 100644 --- a/Swift/QtUI/QtChatTabs.cpp +++ b/Swift/QtUI/QtChatTabs.cpp @@ -7,6 +7,10 @@ #include "QtChatTabs.h" #include <algorithm> +#include <vector> + +#include <Swift/Controllers/ChatMessageSummarizer.h> +#include <Swift/QtUI/QtSwiftUtil.h> #include <QCloseEvent> #include <QDesktopWidget> @@ -236,16 +240,18 @@ void QtChatTabs::handleTabTitleUpdated(QWidget* widget) { default : tabTextColor = QColor(); } tabs_->tabBar()->setTabTextColor(index, tabTextColor); - int unread = 0; + + std::vector<std::pair<std::string, int> > unreads; for (int i = 0; i < tabs_->count(); i++) { QtTabbable* tab = qobject_cast<QtTabbable*>(tabs_->widget(i)); if (tab) { - unread += tab->getCount(); + unreads.push_back(std::pair<std::string, int>(Q2PSTRING(tab->windowTitle()), tab->getCount())); } } - QtTabbable* current = qobject_cast<QtTabbable*>(tabs_->currentWidget()); - setWindowTitle(unread > 0 ? QString("(%1) %2").arg(unread).arg(current->windowTitle()) : current->windowTitle()); + std::string current(Q2PSTRING(qobject_cast<QtTabbable*>(tabs_->currentWidget())->windowTitle())); + ChatMessageSummarizer summary; + setWindowTitle(summary.getSummary(current, unreads).c_str()); } void QtChatTabs::flash() { diff --git a/Swift/QtUI/QtChatView.cpp b/Swift/QtUI/QtChatView.cpp index 521b072..eab6d91 100644 --- a/Swift/QtUI/QtChatView.cpp +++ b/Swift/QtUI/QtChatView.cpp @@ -106,6 +106,19 @@ void QtChatView::addToDOM(boost::shared_ptr<ChatSnippet> snippet) { //qApp->processEvents(); } +void QtChatView::addLastSeenLine() { + if (lineSeparator_.isNull()) { + lineSeparator_ = newInsertPoint_.clone(); + lineSeparator_.setInnerXml(QString("<hr/>")); + newInsertPoint_.prependOutside(lineSeparator_); + } + else { + QWebElement lineSeparatorC = lineSeparator_.clone(); + lineSeparatorC.removeFromDocument(); + } + newInsertPoint_.prependOutside(lineSeparator_); +} + void QtChatView::replaceLastMessage(const QString& newMessage) { assert(viewReady_); /* FIXME: must be queued? */ @@ -125,6 +138,25 @@ void QtChatView::replaceLastMessage(const QString& newMessage, const QString& no replace.setInnerXml(ChatSnippet::escape(note)); } +QString QtChatView::getLastSentMessage() { + return lastElement_.toPlainText(); +} + +void QtChatView::replaceMessage(const QString& newMessage, const QString& id, const QDateTime& editTime) { + rememberScrolledToBottom(); + QWebElement message = document_.findFirst("#" + id); + if (!message.isNull()) { + QWebElement replaceContent = message.findFirst("span.swift_message"); + assert(!replaceContent.isNull()); + QString old = replaceContent.toOuterXml(); + replaceContent.setInnerXml(ChatSnippet::escape(newMessage)); + QWebElement replaceTime = message.findFirst("span.swift_time"); + assert(!replaceTime.isNull()); + old = replaceTime.toOuterXml(); + replaceTime.setInnerXml(ChatSnippet::escape(tr("%1 edited").arg(ChatSnippet::timeToEscapedString(editTime)))); + } +} + void QtChatView::copySelectionToClipboard() { if (!webPage_->selectedText().isEmpty()) { webPage_->triggerAction(QWebPage::Copy); diff --git a/Swift/QtUI/QtChatView.h b/Swift/QtUI/QtChatView.h index 58b33df..32741f4 100644 --- a/Swift/QtUI/QtChatView.h +++ b/Swift/QtUI/QtChatView.h @@ -26,12 +26,14 @@ namespace Swift { Q_OBJECT public: QtChatView(QtChatTheme* theme, QWidget* parent); - void addMessage(boost::shared_ptr<ChatSnippet> snippet); + void addLastSeenLine(); void replaceLastMessage(const QString& newMessage); void replaceLastMessage(const QString& newMessage, const QString& note); + void replaceMessage(const QString& newMessage, const QString& id, const QDateTime& time); void rememberScrolledToBottom(); void setAckXML(const QString& id, const QString& xml); + QString getLastSentMessage(); signals: void gotFocus(); @@ -63,6 +65,7 @@ namespace Swift { QtChatTheme* theme_; QWebElement newInsertPoint_; + QWebElement lineSeparator_; QWebElement lastElement_; QWebElement document_; }; diff --git a/Swift/QtUI/QtChatWindow.cpp b/Swift/QtUI/QtChatWindow.cpp index 1a909fd..326660f 100644 --- a/Swift/QtUI/QtChatWindow.cpp +++ b/Swift/QtUI/QtChatWindow.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2010 Kevin Smith + * Copyright (c) 2010-2011 Kevin Smith * Licensed under the GNU General Public License v3. * See Documentation/Licenses/GPLv3.txt for more information. */ @@ -17,6 +17,7 @@ #include "SwifTools/TabComplete.h" +#include <QLabel> #include <QApplication> #include <QBoxLayout> #include <QCloseEvent> @@ -35,12 +36,13 @@ QtChatWindow::QtChatWindow(const QString &contact, QtChatTheme* theme, UIEventSt inputEnabled_ = true; completer_ = NULL; theme_ = theme; + isCorrection_ = false; updateTitleWithUnreadCount(); QBoxLayout *layout = new QBoxLayout(QBoxLayout::TopToBottom, this); layout->setContentsMargins(0,0,0,0); layout->setSpacing(2); - + QSplitter *logRosterSplitter = new QSplitter(this); logRosterSplitter->setAutoFillBackground(true); @@ -69,10 +71,18 @@ QtChatWindow::QtChatWindow(const QString &contact, QtChatTheme* theme, UIEventSt labelsWidget_->setSizeAdjustPolicy(QComboBox::AdjustToContents); midBarLayout->addWidget(labelsWidget_,0); + QWidget* inputBar = new QWidget(this); + layout->addWidget(inputBar); + QHBoxLayout* inputBarLayout = new QHBoxLayout(inputBar); + inputBarLayout->setContentsMargins(0,0,0,0); + inputBarLayout->setSpacing(2); input_ = new QtTextEdit(this); input_->setAcceptRichText(false); - layout->addWidget(input_); - + inputBarLayout->addWidget(input_); + correctingLabel_ = new QLabel(tr("Correcting"), this); + inputBarLayout->addWidget(correctingLabel_); + correctingLabel_->hide(); + inputClearing_ = false; contactIsTyping_ = false; @@ -118,11 +128,33 @@ void QtChatWindow::handleKeyPressEvent(QKeyEvent* event) { emit requestActiveTab(); } else if (key == Qt::Key_Tab) { tabComplete(); + } else if ((key == Qt::Key_Up) && input_->toPlainText().isEmpty() && !(lastSentMessage_.isEmpty())) { + beginCorrection(); + } else if (key == Qt::Key_Down && isCorrection_ && input_->textCursor().atBlockEnd()) { + cancelCorrection(); } else { messageLog_->handleKeyPressEvent(event); } } +void QtChatWindow::beginCorrection() { + QTextCursor cursor = input_->textCursor(); + cursor.select(QTextCursor::Document); + cursor.beginEditBlock(); + cursor.insertText(QString(lastSentMessage_)); + cursor.endEditBlock(); + isCorrection_ = true; + correctingLabel_->show(); +} + +void QtChatWindow::cancelCorrection() { + QTextCursor cursor = input_->textCursor(); + cursor.select(QTextCursor::Document); + cursor.removeSelectedText(); + isCorrection_ = false; + correctingLabel_->hide(); +} + void QtChatWindow::tabComplete() { if (!completer_) { return; @@ -150,7 +182,7 @@ void QtChatWindow::tabComplete() { } void QtChatWindow::setRosterModel(Roster* roster) { - treeWidget_->setRosterModel(roster); + treeWidget_->setRosterModel(roster); } void QtChatWindow::setAvailableSecurityLabels(const std::vector<SecurityLabelsCatalog::Item>& labels) { @@ -204,10 +236,13 @@ void QtChatWindow::qAppFocusChanged(QWidget *old, QWidget *now) { Q_UNUSED(old); Q_UNUSED(now); if (isWidgetSelected()) { + lastLineTracker_.setHasFocus(true); input_->setFocus(); onAllMessagesRead(); } - + else { + lastLineTracker_.setHasFocus(false); + } } void QtChatWindow::setInputEnabled(bool enabled) { @@ -236,7 +271,7 @@ void QtChatWindow::setContactChatState(ChatState::ChatStateType state) { QtTabbable::AlertType QtChatWindow::getWidgetAlertState() { if (contactIsTyping_) { return ImpendingActivity; - } + } if (unreadCount_ > 0) { return WaitingActivity; } @@ -265,7 +300,6 @@ std::string QtChatWindow::addMessage(const std::string &message, const std::stri if (isWidgetSelected()) { onAllMessagesRead(); } - QString scaledAvatarPath = QtScaledAvatarCache(32).getScaledAvatarPath(avatarPath.c_str()); QString htmlString; @@ -281,6 +315,12 @@ std::string QtChatWindow::addMessage(const std::string &message, const std::stri htmlString += styleSpanStart + messageHTML + styleSpanEnd; bool appendToPrevious = !previousMessageWasSystem_ && !previousMessageWasPresence_ && ((senderIsSelf && previousMessageWasSelf_) || (!senderIsSelf && !previousMessageWasSelf_ && previousSenderName_ == P2QSTRING(senderName))); + if (lastLineTracker_.getShouldMoveLastLine()) { + /* should this be queued? */ + messageLog_->addLastSeenLine(); + /* if the line is added we should break the snippet */ + appendToPrevious = false; + } QString qAvatarPath = scaledAvatarPath.isEmpty() ? "qrc:/icons/avatar.png" : QUrl::fromLocalFile(scaledAvatarPath).toEncoded(); std::string id = id_.generateID(); messageLog_->addMessage(boost::shared_ptr<ChatSnippet>(new MessageSnippet(htmlString, Qt::escape(P2QSTRING(senderName)), B2QDATE(time), qAvatarPath, senderIsSelf, appendToPrevious, theme_, P2QSTRING(id)))); @@ -343,6 +383,15 @@ void QtChatWindow::addSystemMessage(const std::string& message) { previousMessageWasPresence_ = false; } +void QtChatWindow::replaceMessage(const std::string& message, const std::string& id, const boost::posix_time::ptime& time) { + if (!id.empty()) { + QString messageHTML(Qt::escape(P2QSTRING(message))); + messageHTML = P2QSTRING(Linkify::linkify(Q2PSTRING(messageHTML))); + messageHTML.replace("\n","<br/>"); + messageLog_->replaceMessage(messageHTML, P2QSTRING(id), B2QDATE(time)); + } +} + void QtChatWindow::addPresenceMessage(const std::string& message) { if (isWidgetSelected()) { onAllMessagesRead(); @@ -364,9 +413,11 @@ void QtChatWindow::returnPressed() { return; } messageLog_->scrollToBottom(); - onSendMessageRequest(Q2PSTRING(input_->toPlainText())); + lastSentMessage_ = QString(input_->toPlainText()); + onSendMessageRequest(Q2PSTRING(input_->toPlainText()), isCorrection_); inputClearing_ = true; input_->clear(); + cancelCorrection(); inputClearing_ = false; } @@ -382,7 +433,9 @@ void QtChatWindow::handleInputChanged() { } void QtChatWindow::show() { - QWidget::show(); + if (parentWidget() == NULL) { + QWidget::show(); + } emit windowOpening(); } @@ -399,7 +452,7 @@ void QtChatWindow::resizeEvent(QResizeEvent*) { } void QtChatWindow::moveEvent(QMoveEvent*) { - emit geometryChanged(); + emit geometryChanged(); } void QtChatWindow::replaceLastMessage(const std::string& message) { diff --git a/Swift/QtUI/QtChatWindow.h b/Swift/QtUI/QtChatWindow.h index 910019b..a95041e 100644 --- a/Swift/QtUI/QtChatWindow.h +++ b/Swift/QtUI/QtChatWindow.h @@ -1,21 +1,23 @@ /* - * Copyright (c) 2010 Kevin Smith + * Copyright (c) 2010-2011 Kevin Smith * Licensed under the GNU General Public License v3. * See Documentation/Licenses/GPLv3.txt for more information. */ -#ifndef SWIFT_QtChatWindow_H -#define SWIFT_QtChatWindow_H +#pragma once #include "Swift/Controllers/UIInterfaces/ChatWindow.h" #include "QtTabbable.h" +#include "SwifTools/LastLineTracker.h" + #include "Swiften/Base/IDGenerator.h" class QTextEdit; class QLineEdit; class QComboBox; +class QLabel; namespace Swift { class QtChatView; @@ -35,6 +37,7 @@ namespace Swift { void addSystemMessage(const std::string& message); void addPresenceMessage(const std::string& message); void addErrorMessage(const std::string& errorMessage); + void replaceMessage(const std::string& message, const std::string& id, const boost::posix_time::ptime& time); void show(); void activate(); void setUnreadMessageCount(int count); @@ -75,18 +78,24 @@ namespace Swift { private: void updateTitleWithUnreadCount(); void tabComplete(); + void beginCorrection(); + void cancelCorrection(); std::string addMessage(const std::string &message, const std::string &senderName, bool senderIsSelf, boost::shared_ptr<SecurityLabel> label, const std::string& avatarPath, const QString& style, const boost::posix_time::ptime& time); int unreadCount_; bool contactIsTyping_; + LastLineTracker lastLineTracker_; QString contact_; + QString lastSentMessage_; QtChatView* messageLog_; QtChatTheme* theme_; QtTextEdit* input_; QComboBox* labelsWidget_; QtTreeWidget* treeWidget_; + QLabel* correctingLabel_; TabComplete* completer_; std::vector<SecurityLabelsCatalog::Item> availableLabels_; + bool isCorrection_; bool previousMessageWasSelf_; bool previousMessageWasSystem_; bool previousMessageWasPresence_; @@ -97,5 +106,3 @@ namespace Swift { IDGenerator id_; }; } - -#endif diff --git a/Swift/QtUI/QtDBUSURIHandler.cpp b/Swift/QtUI/QtDBUSURIHandler.cpp new file mode 100644 index 0000000..9b69ca6 --- /dev/null +++ b/Swift/QtUI/QtDBUSURIHandler.cpp @@ -0,0 +1,41 @@ +/* + * Copyright (c) 2011 Remko Tronçon + * Licensed under the GNU General Public License v3. + * See Documentation/Licenses/GPLv3.txt for more information. + */ + +#include "QtDBUSURIHandler.h" + +#include <QDBusAbstractAdaptor> +#include <QDBusConnection> + +#include "QtSwiftUtil.h" + +using namespace Swift; + +namespace { + class DBUSAdaptor: public QDBusAbstractAdaptor { + Q_OBJECT + Q_CLASSINFO("D-Bus Interface", "im.swift.Swift.URIHandler"); + public: + DBUSAdaptor(QtDBUSURIHandler* uriHandler) : QDBusAbstractAdaptor(uriHandler), uriHandler(uriHandler) { + } + + public slots: + void openURI(const QString& uri) { + uriHandler->onURI(Q2PSTRING(uri)); + } + + private: + QtDBUSURIHandler* uriHandler; + }; +} + +QtDBUSURIHandler::QtDBUSURIHandler() { + new DBUSAdaptor(this); + QDBusConnection connection = QDBusConnection::sessionBus(); + connection.registerService("im.swift.Swift.URIHandler"); + connection.registerObject("/", this); +} + +#include "QtDBUSURIHandler.moc" diff --git a/Swift/QtUI/QtDBUSURIHandler.h b/Swift/QtUI/QtDBUSURIHandler.h new file mode 100644 index 0000000..be1872e --- /dev/null +++ b/Swift/QtUI/QtDBUSURIHandler.h @@ -0,0 +1,17 @@ +/* + * Copyright (c) 2011 Remko Tronçon + * Licensed under the GNU General Public License v3. + * See Documentation/Licenses/GPLv3.txt for more information. + */ + +#pragma once + +#include <QObject> +#include <SwifTools/URIHandler/URIHandler.h> + +namespace Swift { + class QtDBUSURIHandler : public QObject, public URIHandler { + public: + QtDBUSURIHandler(); + }; +} diff --git a/Swift/QtUI/QtFormWidget.cpp b/Swift/QtUI/QtFormWidget.cpp new file mode 100644 index 0000000..050ff27 --- /dev/null +++ b/Swift/QtUI/QtFormWidget.cpp @@ -0,0 +1,242 @@ +/* + * Copyright (c) 2010-2011 Kevin Smith + * Licensed under the GNU General Public License v3. + * See Documentation/Licenses/GPLv3.txt for more information. + */ + +#include <Swift/QtUI/QtFormWidget.h> + +#include <QGridLayout> +#include <QLabel> +#include <QListWidget> +#include <QLineEdit> +#include <QTextEdit> +#include <QCheckBox> +#include <QScrollArea> + +#include <Swift/QtUI/QtSwiftUtil.h> +#include <Swiften/Base/foreach.h> + +namespace Swift { + +QtFormWidget::QtFormWidget(Form::ref form, QWidget* parent) : QWidget(parent), form_(form) { + QGridLayout* thisLayout = new QGridLayout(this); + int row = 0; + if (!form->getTitle().empty()) { + QLabel* instructions = new QLabel(("<b>" + form->getTitle() + "</b>").c_str(), this); + thisLayout->addWidget(instructions, row++, 0, 1, 2); + } + if (!form->getInstructions().empty()) { + QLabel* instructions = new QLabel(form->getInstructions().c_str(), this); + thisLayout->addWidget(instructions, row++, 0, 1, 2); + } + QScrollArea* scrollArea = new QScrollArea(this); + thisLayout->addWidget(scrollArea); + QWidget* scroll = new QWidget(this); + QGridLayout* layout = new QGridLayout(scroll); + foreach (boost::shared_ptr<FormField> field, form->getFields()) { + QWidget* widget = createWidget(field); + if (widget) { + layout->addWidget(new QLabel(field->getLabel().c_str(), this), row, 0); + layout->addWidget(widget, row++, 1); + } + } + scrollArea->setWidget(scroll); + scrollArea->setWidgetResizable(true); +} + +QtFormWidget::~QtFormWidget() { + +} + +QListWidget* QtFormWidget::createList(FormField::ref field) { + QListWidget* listWidget = new QListWidget(this); + listWidget->setSortingEnabled(false); + listWidget->setSelectionMode(boost::dynamic_pointer_cast<ListMultiFormField>(field) ? QAbstractItemView::MultiSelection : QAbstractItemView::SingleSelection); + foreach (FormField::Option option, field->getOptions()) { + listWidget->addItem(option.label.c_str()); + } + boost::shared_ptr<ListMultiFormField> listMultiField = boost::dynamic_pointer_cast<ListMultiFormField>(field); + boost::shared_ptr<ListSingleFormField> listSingleField = boost::dynamic_pointer_cast<ListSingleFormField>(field); + for (int i = 0; i < listWidget->count(); i++) { + QListWidgetItem* item = listWidget->item(i); + bool selected = false; + if (listSingleField) { + selected = (item->text() == QString(listSingleField->getValue().c_str())); + } + else if (listMultiField) { + std::string text = Q2PSTRING(item->text()); + selected = (std::find(listMultiField->getValue().begin(), listMultiField->getValue().end(), text) != listMultiField->getValue().end()); + } + item->setSelected(selected); + } + return listWidget; +} + +QWidget* QtFormWidget::createWidget(FormField::ref field) { + QWidget* widget = NULL; + boost::shared_ptr<BooleanFormField> booleanField = boost::dynamic_pointer_cast<BooleanFormField>(field); + if (booleanField) { + QCheckBox* checkWidget = new QCheckBox(this); + checkWidget->setCheckState(booleanField->getValue() ? Qt::Checked : Qt::Unchecked); + widget = checkWidget; + } + boost::shared_ptr<FixedFormField> fixedField = boost::dynamic_pointer_cast<FixedFormField>(field); + if (fixedField) { + QString value = fixedField->getValue().c_str(); + widget = new QLabel(value, this); + } + boost::shared_ptr<ListSingleFormField> listSingleField = boost::dynamic_pointer_cast<ListSingleFormField>(field); + if (listSingleField) { + widget = createList(field); + } + boost::shared_ptr<TextMultiFormField> textMultiField = boost::dynamic_pointer_cast<TextMultiFormField>(field); + if (textMultiField) { + QString value = textMultiField->getValue().c_str(); + widget = new QTextEdit(value, this); + } + boost::shared_ptr<TextPrivateFormField> textPrivateField = boost::dynamic_pointer_cast<TextPrivateFormField>(field); + if (textPrivateField) { + QString value = textPrivateField->getValue().c_str(); + QLineEdit* lineWidget = new QLineEdit(value, this); + lineWidget->setEchoMode(QLineEdit::Password); + widget = lineWidget; + } + boost::shared_ptr<TextSingleFormField> textSingleField = boost::dynamic_pointer_cast<TextSingleFormField>(field); + if (textSingleField) { + QString value = textSingleField->getValue().c_str(); + widget = new QLineEdit(value, this); + } + boost::shared_ptr<JIDSingleFormField> jidSingleField = boost::dynamic_pointer_cast<JIDSingleFormField>(field); + if (jidSingleField) { + QString value = jidSingleField->getValue().toString().c_str(); + widget = new QLineEdit(value, this); + } + boost::shared_ptr<JIDMultiFormField> jidMultiField = boost::dynamic_pointer_cast<JIDMultiFormField>(field); + if (jidMultiField) { + QString text; + bool prev = false; + foreach (JID line, jidMultiField->getValue()) { + if (prev) { + text += "\n"; + } + prev = true; + text += line.toString().c_str(); + } + widget = new QTextEdit(text, this); + } + boost::shared_ptr<ListMultiFormField> listMultiField = boost::dynamic_pointer_cast<ListMultiFormField>(field); + if (listMultiField) { + widget = createList(field); + } + boost::shared_ptr<HiddenFormField> hiddenField = boost::dynamic_pointer_cast<HiddenFormField>(field); + if (hiddenField) { + } + fields_[field->getName()] = widget; + return widget; +} + +Form::ref QtFormWidget::getCompletedForm() { + Form::ref result(new Form(Form::SubmitType)); + foreach (boost::shared_ptr<FormField> field, form_->getFields()) { + boost::shared_ptr<FormField> resultField; + boost::shared_ptr<BooleanFormField> booleanField = boost::dynamic_pointer_cast<BooleanFormField>(field); + if (booleanField) { + resultField = FormField::ref(BooleanFormField::create(qobject_cast<QCheckBox*>(fields_[field->getName()])->checkState() == Qt::Checked)); + } + boost::shared_ptr<FixedFormField> fixedField = boost::dynamic_pointer_cast<FixedFormField>(field); + if (fixedField) { + resultField = FormField::ref(FixedFormField::create(fixedField->getValue())); + } + boost::shared_ptr<ListSingleFormField> listSingleField = boost::dynamic_pointer_cast<ListSingleFormField>(field); + if (listSingleField) { + QListWidget* listWidget = qobject_cast<QListWidget*>(fields_[field->getName()]); + if (listWidget->selectedItems().size() > 0) { + int i = listWidget->row(listWidget->selectedItems()[0]); + resultField = FormField::ref(ListSingleFormField::create(field->getOptions()[i].value)); + } + else { + resultField = FormField::ref(ListSingleFormField::create()); + } + } + boost::shared_ptr<TextMultiFormField> textMultiField = boost::dynamic_pointer_cast<TextMultiFormField>(field); + if (textMultiField) { + QTextEdit* widget = qobject_cast<QTextEdit*>(fields_[field->getName()]); + QString string = widget->toPlainText(); + if (string.isEmpty()) { + resultField = FormField::ref(TextMultiFormField::create()); + } + else { + resultField = FormField::ref(TextMultiFormField::create(Q2PSTRING(string))); + } + } + boost::shared_ptr<TextPrivateFormField> textPrivateField = boost::dynamic_pointer_cast<TextPrivateFormField>(field); + if (textPrivateField) { + QLineEdit* widget = qobject_cast<QLineEdit*>(fields_[field->getName()]); + QString string = widget->text(); + if (string.isEmpty()) { + resultField = FormField::ref(TextPrivateFormField::create()); + } + else { + resultField = FormField::ref(TextPrivateFormField::create(Q2PSTRING(string))); + } + } + boost::shared_ptr<TextSingleFormField> textSingleField = boost::dynamic_pointer_cast<TextSingleFormField>(field); + if (textSingleField) { + QLineEdit* widget = qobject_cast<QLineEdit*>(fields_[field->getName()]); + QString string = widget->text(); + if (string.isEmpty()) { + resultField = FormField::ref(TextSingleFormField::create()); + } + else { + resultField = FormField::ref(TextSingleFormField::create(Q2PSTRING(string))); + } + } + boost::shared_ptr<JIDSingleFormField> jidSingleField = boost::dynamic_pointer_cast<JIDSingleFormField>(field); + if (jidSingleField) { + QLineEdit* widget = qobject_cast<QLineEdit*>(fields_[field->getName()]); + QString string = widget->text(); + JID jid(Q2PSTRING(string)); + if (string.isEmpty()) { + resultField = FormField::ref(JIDSingleFormField::create()); + } + else { + resultField = FormField::ref(JIDSingleFormField::create(jid)); + } + } + boost::shared_ptr<JIDMultiFormField> jidMultiField = boost::dynamic_pointer_cast<JIDMultiFormField>(field); + if (jidMultiField) { + QTextEdit* widget = qobject_cast<QTextEdit*>(fields_[field->getName()]); + QString string = widget->toPlainText(); + if (string.isEmpty()) { + resultField = FormField::ref(JIDMultiFormField::create()); + } + else { + QStringList lines = string.split("\n"); + std::vector<JID> value; + foreach (QString line, lines) { + value.push_back(JID(Q2PSTRING(line))); + } + resultField = FormField::ref(JIDMultiFormField::create(value)); + } + } + boost::shared_ptr<ListMultiFormField> listMultiField = boost::dynamic_pointer_cast<ListMultiFormField>(field); + if (listMultiField) { + QListWidget* listWidget = qobject_cast<QListWidget*>(fields_[field->getName()]); + std::vector<std::string> values; + foreach (QListWidgetItem* item, listWidget->selectedItems()) { + values.push_back(field->getOptions()[listWidget->row(item)].value); + } + resultField = FormField::ref(ListMultiFormField::create(values)); + } + boost::shared_ptr<HiddenFormField> hiddenField = boost::dynamic_pointer_cast<HiddenFormField>(field); + if (hiddenField) { + resultField = FormField::ref(HiddenFormField::create(hiddenField->getValue())); + } + resultField->setName(field->getName()); + result->addField(resultField); + } + return result; +} + +} diff --git a/Swift/QtUI/QtFormWidget.h b/Swift/QtUI/QtFormWidget.h new file mode 100644 index 0000000..2fb7b98 --- /dev/null +++ b/Swift/QtUI/QtFormWidget.h @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2011 Kevin Smith + * Licensed under the GNU General Public License v3. + * See Documentation/Licenses/GPLv3.txt for more information. + */ + +#pragma once + +#include <QWidget> + +#include <map> +#include <Swiften/Elements/Form.h> + +class QListWidget; + +namespace Swift { + +class QtFormWidget : public QWidget { + Q_OBJECT + public: + QtFormWidget(Form::ref form, QWidget* parent = NULL); + virtual ~QtFormWidget(); + Form::ref getCompletedForm(); + private: + QWidget* createWidget(FormField::ref field); + QListWidget* createList(FormField::ref field); + std::map<std::string, QWidget*> fields_; + Form::ref form_; +}; + +} diff --git a/Swift/QtUI/QtLoginWindow.cpp b/Swift/QtUI/QtLoginWindow.cpp index d0ab61e..4302c10 100644 --- a/Swift/QtUI/QtLoginWindow.cpp +++ b/Swift/QtUI/QtLoginWindow.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2010 Kevin Smith + * Copyright (c) 2010-2011 Kevin Smith * Licensed under the GNU General Public License v3. * See Documentation/Licenses/GPLv3.txt for more information. */ @@ -56,9 +56,9 @@ QtLoginWindow::QtLoginWindow(UIEventStream* uiEventStream) : QMainWindow() { stack_ = new QStackedWidget(centralWidget); topLayout->addWidget(stack_); topLayout->setMargin(0); - QWidget *wrapperWidget = new QWidget(this); - wrapperWidget->setSizePolicy(QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding)); - QBoxLayout *layout = new QBoxLayout(QBoxLayout::TopToBottom, wrapperWidget); + loginWidgetWrapper_ = new QWidget(this); + loginWidgetWrapper_->setSizePolicy(QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding)); + QBoxLayout *layout = new QBoxLayout(QBoxLayout::TopToBottom, loginWidgetWrapper_); layout->addStretch(2); QLabel* logo = new QLabel(this); @@ -139,7 +139,7 @@ QtLoginWindow::QtLoginWindow(UIEventStream* uiEventStream) : QMainWindow() { layout->addWidget(loginAutomatically_); connect(loginButton_, SIGNAL(clicked()), SLOT(loginClicked())); - stack_->addWidget(wrapperWidget); + stack_->addWidget(loginWidgetWrapper_); #ifdef SWIFTEN_PLATFORM_MACOSX menuBar_ = new QMenuBar(NULL); #else @@ -284,11 +284,9 @@ void QtLoginWindow::handleUsernameTextChanged() { } void QtLoginWindow::loggedOut() { - if (stack_->count() > 1) { - QWidget* current = stack_->currentWidget(); - stack_->setCurrentIndex(0); - stack_->removeWidget(current); - } + stack_->removeWidget(stack_->currentWidget()); + stack_->addWidget(loginWidgetWrapper_); + stack_->setCurrentWidget(loginWidgetWrapper_); setInitialMenus(); setIsLoggingIn(false); } @@ -370,6 +368,7 @@ void QtLoginWindow::setInitialMenus() { void QtLoginWindow::morphInto(MainWindow *mainWindow) { QtMainWindow *qtMainWindow = dynamic_cast<QtMainWindow*>(mainWindow); assert(qtMainWindow); + stack_->removeWidget(loginWidgetWrapper_); stack_->addWidget(qtMainWindow); stack_->setCurrentWidget(qtMainWindow); setEnabled(true); diff --git a/Swift/QtUI/QtLoginWindow.h b/Swift/QtUI/QtLoginWindow.h index 3f3b5f8..b667a4b 100644 --- a/Swift/QtUI/QtLoginWindow.h +++ b/Swift/QtUI/QtLoginWindow.h @@ -1,11 +1,10 @@ /* - * Copyright (c) 2010 Kevin Smith + * Copyright (c) 2010-2011 Kevin Smith * Licensed under the GNU General Public License v3. * See Documentation/Licenses/GPLv3.txt for more information. */ -#ifndef SWIFT_QtLoginWindow_H -#define SWIFT_QtLoginWindow_H +#pragma once #include <QMainWindow> #include <QPointer> @@ -65,6 +64,7 @@ namespace Swift { private: void setInitialMenus(); + QWidget* loginWidgetWrapper_; QStringList usernames_; QStringList passwords_; QStringList certificateFiles_; @@ -87,5 +87,3 @@ namespace Swift { QPointer<QtAboutWidget> aboutDialog_; }; } - -#endif diff --git a/Swift/QtUI/QtMainWindow.cpp b/Swift/QtUI/QtMainWindow.cpp index 6391961..0c959d6 100644 --- a/Swift/QtUI/QtMainWindow.cpp +++ b/Swift/QtUI/QtMainWindow.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2010 Kevin Smith + * Copyright (c) 2010-2011 Kevin Smith * Licensed under the GNU General Public License v3. * See Documentation/Licenses/GPLv3.txt for more information. */ @@ -21,20 +21,25 @@ #include <QAction> #include <QTabWidget> -#include "QtSwiftUtil.h" -#include "QtTabWidget.h" -#include "Roster/QtTreeWidget.h" -#include "Swift/Controllers/UIEvents/RequestJoinMUCUIEvent.h" -#include "Swift/Controllers/UIEvents/RequestAddUserDialogUIEvent.h" -#include "Swift/Controllers/UIEvents/RequestChatWithUserDialogUIEvent.h" -#include "Swift/Controllers/UIEvents/RequestProfileEditorUIEvent.h" -#include "Swift/Controllers/UIEvents/JoinMUCUIEvent.h" -#include "Swift/Controllers/UIEvents/ToggleShowOfflineUIEvent.h" +#include <Swift/QtUI/QtSwiftUtil.h> +#include <Swift/QtUI/QtTabWidget.h> +#include <Swift/QtUI/QtSettingsProvider.h> +#include <Roster/QtTreeWidget.h> +#include <Swift/Controllers/UIEvents/RequestJoinMUCUIEvent.h> +#include <Swift/Controllers/UIEvents/RequestAddUserDialogUIEvent.h> +#include <Swift/Controllers/UIEvents/RequestChatWithUserDialogUIEvent.h> +#include <Swift/Controllers/UIEvents/RequestProfileEditorUIEvent.h> +#include <Swift/Controllers/UIEvents/JoinMUCUIEvent.h> +#include <Swift/Controllers/UIEvents/ToggleShowOfflineUIEvent.h> +#include <Swift/Controllers/UIEvents/RequestAdHocUIEvent.h> namespace Swift { +#define CURRENT_ROSTER_TAB "current_roster_tab" + QtMainWindow::QtMainWindow(QtSettingsProvider* settings, UIEventStream* uiEventStream) : QWidget(), MainWindow(false) { uiEventStream_ = uiEventStream; + settings_ = settings; setSizePolicy(QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding)); QBoxLayout *mainLayout = new QBoxLayout(QBoxLayout::TopToBottom, this); mainLayout->setContentsMargins(0,0,0,0); @@ -68,8 +73,12 @@ QtMainWindow::QtMainWindow(QtSettingsProvider* settings, UIEventStream* uiEventS chatListWindow_ = new QtChatListWindow(uiEventStream_); - tabs_->addTab(eventWindow_, tr("&Notices")); tabs_->addTab(chatListWindow_, tr("C&hats")); + tabs_->addTab(eventWindow_, tr("&Notices")); + + tabs_->setCurrentIndex(settings_->getIntSetting(CURRENT_ROSTER_TAB, 0)); + + connect(tabs_, SIGNAL(currentChanged(int)), this, SLOT(handleTabChanged(int))); this->setLayout(mainLayout); @@ -99,6 +108,8 @@ QtMainWindow::QtMainWindow(QtSettingsProvider* settings, UIEventStream* uiEventS chatUserAction_ = new QAction(tr("Start &Chat"), this); connect(chatUserAction_, SIGNAL(triggered(bool)), this, SLOT(handleChatUserActionTriggered(bool))); actionsMenu->addAction(chatUserAction_); + serverAdHocMenu_ = new QMenu(tr("Run Server Command"), this); + actionsMenu->addMenu(serverAdHocMenu_); actionsMenu->addSeparator(); QAction* signOutAction = new QAction(tr("&Sign Out"), this); connect(signOutAction, SIGNAL(triggered()), SLOT(handleSignOutAction())); @@ -106,6 +117,12 @@ QtMainWindow::QtMainWindow(QtSettingsProvider* settings, UIEventStream* uiEventS connect(treeWidget_, SIGNAL(onSomethingSelectedChanged(bool)), editUserAction_, SLOT(setEnabled(bool))); + setAvailableAdHocCommands(std::vector<DiscoItems::Item>()); + QAction* adHocAction = new QAction(tr("Collecting commands..."), this); + adHocAction->setEnabled(false); + serverAdHocMenu_->addAction(adHocAction); + serverAdHocCommandActions_.append(adHocAction); + lastOfflineState_ = false; uiEventStream_->onUIEvent.connect(boost::bind(&QtMainWindow::handleUIEvent, this, _1)); } @@ -114,6 +131,10 @@ QtMainWindow::~QtMainWindow() { uiEventStream_->onUIEvent.disconnect(boost::bind(&QtMainWindow::handleUIEvent, this, _1)); } +void QtMainWindow::handleTabChanged(int index) { + settings_->storeInt(CURRENT_ROSTER_TAB, index); +} + QtEventWindow* QtMainWindow::getEventWindow() { return eventWindow_; } @@ -132,7 +153,7 @@ void QtMainWindow::handleEditProfileRequest() { void QtMainWindow::handleEventCountUpdated(int count) { QColor eventTabColor = (count == 0) ? QColor() : QColor(255, 0, 0); // invalid resets to default - int eventIndex = 1; + int eventIndex = 2; tabs_->tabBar()->setTabTextColor(eventIndex, eventTabColor); QString text = tr("&Notices"); if (count > 0) { @@ -206,6 +227,33 @@ void QtMainWindow::setConnecting() { meView_->setConnecting(); } +void QtMainWindow::handleAdHocActionTriggered(bool /*checked*/) { + QAction* action = qobject_cast<QAction*>(sender()); + assert(action); + DiscoItems::Item command = serverAdHocCommands_[serverAdHocCommandActions_.indexOf(action)]; + uiEventStream_->send(boost::shared_ptr<UIEvent>(new RequestAdHocUIEvent(command))); +} + +void QtMainWindow::setAvailableAdHocCommands(const std::vector<DiscoItems::Item>& commands) { + serverAdHocCommands_ = commands; + foreach (QAction* action, serverAdHocCommandActions_) { + delete action; + } + serverAdHocMenu_->clear(); + serverAdHocCommandActions_.clear(); + foreach (DiscoItems::Item command, commands) { + QAction* action = new QAction(P2QSTRING(command.getName()), this); + connect(action, SIGNAL(triggered(bool)), this, SLOT(handleAdHocActionTriggered(bool))); + serverAdHocMenu_->addAction(action); + serverAdHocCommandActions_.append(action); + } + if (serverAdHocCommandActions_.isEmpty()) { + QAction* action = new QAction(tr("No Available Commands"), this); + action->setEnabled(false); + serverAdHocMenu_->addAction(action); + serverAdHocCommandActions_.append(action); + } +} } diff --git a/Swift/QtUI/QtMainWindow.h b/Swift/QtUI/QtMainWindow.h index 3462bb0..5c29f6d 100644 --- a/Swift/QtUI/QtMainWindow.h +++ b/Swift/QtUI/QtMainWindow.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2010 Kevin Smith + * Copyright (c) 2010-2011 Kevin Smith * Licensed under the GNU General Public License v3. * See Documentation/Licenses/GPLv3.txt for more information. */ @@ -8,6 +8,7 @@ #include <QWidget> #include <QMenu> +#include <QList> #include "Swift/Controllers/UIInterfaces/MainWindow.h" #include "Swift/QtUI/QtRosterHeader.h" #include "Swift/QtUI/EventViewer/QtEventWindow.h" @@ -20,7 +21,7 @@ class QLineEdit; class QPushButton; class QToolBar; class QAction; - +class QMenu; class QTabWidget; namespace Swift { @@ -46,6 +47,7 @@ namespace Swift { QtEventWindow* getEventWindow(); QtChatListWindow* getChatListWindow(); void setRosterModel(Roster* roster); + void setAvailableAdHocCommands(const std::vector<DiscoItems::Item>& commands); private slots: void handleStatusChanged(StatusShow::Type showType, const QString &statusMessage); void handleUIEvent(boost::shared_ptr<UIEvent> event); @@ -55,10 +57,13 @@ namespace Swift { void handleEditProfileAction(); void handleAddUserActionTriggered(bool checked); void handleChatUserActionTriggered(bool checked); + void handleAdHocActionTriggered(bool checked); void handleEventCountUpdated(int count); void handleEditProfileRequest(); + void handleTabChanged(int index); private: + QtSettingsProvider* settings_; std::vector<QMenu*> menus_; QtTreeWidget* treeWidget_; QtRosterHeader* meView_; @@ -66,6 +71,7 @@ namespace Swift { QAction* editUserAction_; QAction* chatUserAction_; QAction* showOfflineAction_; + QMenu* serverAdHocMenu_; QtTabWidget* tabs_; QWidget* contactsTabWidget_; QWidget* eventsTabWidget_; @@ -73,5 +79,7 @@ namespace Swift { QtChatListWindow* chatListWindow_; UIEventStream* uiEventStream_; bool lastOfflineState_; + std::vector<DiscoItems::Item> serverAdHocCommands_; + QList<QAction*> serverAdHocCommandActions_; }; } diff --git a/Swift/QtUI/QtSwift.cpp b/Swift/QtUI/QtSwift.cpp index d4c306f..d7a1f78 100644 --- a/Swift/QtUI/QtSwift.cpp +++ b/Swift/QtUI/QtSwift.cpp @@ -18,13 +18,11 @@ #include "QtUIFactory.h" #include "QtChatWindowFactory.h" #include <Swiften/Base/Log.h> -#include <Swift/Controllers/CertificateFileStorageFactory.h> +#include <Swift/Controllers/Storages/CertificateFileStorageFactory.h> +#include "Swift/Controllers/Storages/FileStoragesFactory.h" #include "SwifTools/Application/PlatformApplicationPathProvider.h" -#include "Swiften/Avatars/AvatarFileStorage.h" -#include "Swiften/Disco/CapsFileStorage.h" #include <string> #include "Swiften/Base/Platform.h" -#include "Swift/Controllers/FileStoragesFactory.h" #include "Swiften/Elements/Presence.h" #include "Swiften/Client/Client.h" #include "Swift/Controllers/MainController.h" @@ -32,20 +30,30 @@ #include "Swift/Controllers/BuildVersion.h" #include "SwifTools/AutoUpdater/AutoUpdater.h" #include "SwifTools/AutoUpdater/PlatformAutoUpdaterFactory.h" + #if defined(SWIFTEN_PLATFORM_WINDOWS) #include "WindowsNotifier.h" -#endif -#if defined(HAVE_GROWL) +#elif defined(HAVE_GROWL) #include "SwifTools/Notifier/GrowlNotifier.h" #elif defined(SWIFTEN_PLATFORM_LINUX) #include "FreeDesktopNotifier.h" #else #include "SwifTools/Notifier/NullNotifier.h" #endif + #if defined(SWIFTEN_PLATFORM_MACOSX) #include "SwifTools/Dock/MacOSXDock.h" -#endif +#else #include "SwifTools/Dock/NullDock.h" +#endif + +#if defined(SWIFTEN_PLATFORM_MACOSX) +#include "QtURIHandler.h" +#elif defined(SWIFTEN_PLATFORM_WIN32) +#include <SwifTools/URIHandler/NullURIHandler.h> +#else +#include "QtDBUSURIHandler.h" +#endif namespace Swift{ @@ -123,6 +131,14 @@ QtSwift::QtSwift(const po::variables_map& options) : networkFactories_(&clientMa dock_ = new NullDock(); #endif +#if defined(SWIFTEN_PLATFORM_MACOSX) + uriHandler_ = new QtURIHandler(); +#elif defined(SWIFTEN_PLATFORM_WIN32) + uriHandler_ = new NullURIHandler(); +#else + uriHandler_ = new QtDBUSURIHandler(); +#endif + if (splitter_) { splitter_->show(); } @@ -145,6 +161,7 @@ QtSwift::QtSwift(const po::variables_map& options) : networkFactories_(&clientMa certificateStorageFactory_, dock_, notifier_, + uriHandler_, options.count("latency-debug") > 0); mainControllers_.push_back(mainController); } @@ -172,6 +189,7 @@ QtSwift::~QtSwift() { } delete tabs_; delete splitter_; + delete uriHandler_; delete dock_; delete soundPlayer_; delete chatWindowFactory_; diff --git a/Swift/QtUI/QtSwift.h b/Swift/QtUI/QtSwift.h index 978fa14..4bf5c97 100644 --- a/Swift/QtUI/QtSwift.h +++ b/Swift/QtUI/QtSwift.h @@ -44,6 +44,7 @@ namespace Swift { class QtMUCSearchWindowFactory; class QtUserSearchWindowFactory; class EventLoop; + class URIHandler; class QtSwift : public QObject { Q_OBJECT @@ -63,6 +64,7 @@ namespace Swift { QSplitter* splitter_; QtSoundPlayer* soundPlayer_; Dock* dock_; + URIHandler* uriHandler_; QtChatTabs* tabs_; ApplicationPathProvider* applicationPathProvider_; StoragesFactory* storagesFactory_; diff --git a/Swift/QtUI/QtTextEdit.cpp b/Swift/QtUI/QtTextEdit.cpp index 3668220..3a62325 100644 --- a/Swift/QtUI/QtTextEdit.cpp +++ b/Swift/QtUI/QtTextEdit.cpp @@ -4,7 +4,7 @@ * See Documentation/Licenses/GPLv3.txt for more information. */ -#include "QtTextEdit.h" +#include <Swift/QtUI/QtTextEdit.h> #include <QFontMetrics> #include <QKeyEvent> @@ -22,19 +22,25 @@ void QtTextEdit::keyPressEvent(QKeyEvent* event) { if ((key == Qt::Key_Enter || key == Qt::Key_Return) && (modifiers == Qt::NoModifier || modifiers == Qt::KeypadModifier)) { emit returnPressed(); - } else if (((key == Qt::Key_PageUp || key == Qt::Key_PageDown) && modifiers == Qt::ShiftModifier) + } + else if (((key == Qt::Key_PageUp || key == Qt::Key_PageDown) && modifiers == Qt::ShiftModifier) || (key == Qt::Key_C && modifiers == Qt::ControlModifier && textCursor().selectedText().isEmpty()) || (key == Qt::Key_W && modifiers == Qt::ControlModifier) || (key == Qt::Key_PageUp && modifiers == Qt::ControlModifier) || (key == Qt::Key_PageDown && modifiers == Qt::ControlModifier) -// || (key == Qt::Key_Left && modifiers == (Qt::ControlModifier | Qt::ShiftModifier)) -// || (key == Qt::Key_Right && modifiers == (Qt::ControlModifier | Qt::ShiftModifier)) || (key == Qt::Key_Tab && modifiers == Qt::ControlModifier) || (key == Qt::Key_A && modifiers == Qt::AltModifier) || (key == Qt::Key_Tab) ) { emit unhandledKeyPressEvent(event); - } else { + } + else if ((key == Qt::Key_Up) + || (key == Qt::Key_Down) + ){ + emit unhandledKeyPressEvent(event); + QTextEdit::keyPressEvent(event); + } + else { QTextEdit::keyPressEvent(event); } } diff --git a/Swift/QtUI/QtUIFactory.cpp b/Swift/QtUI/QtUIFactory.cpp index 35fbfcd..5c1f78d 100644 --- a/Swift/QtUI/QtUIFactory.cpp +++ b/Swift/QtUI/QtUIFactory.cpp @@ -23,6 +23,7 @@ #include "UserSearch/QtUserSearchWindow.h" #include "QtProfileWindow.h" #include "QtContactEditWindow.h" +#include "QtAdHocCommandWindow.h" namespace Swift { @@ -99,5 +100,8 @@ ContactEditWindow* QtUIFactory::createContactEditWindow() { return new QtContactEditWindow(); } +void QtUIFactory::createAdHocCommandWindow(boost::shared_ptr<OutgoingAdHocCommandSession> command) { + new QtAdHocCommandWindow(command); +} } diff --git a/Swift/QtUI/QtUIFactory.h b/Swift/QtUI/QtUIFactory.h index ddaaf6e..9ef228a 100644 --- a/Swift/QtUI/QtUIFactory.h +++ b/Swift/QtUI/QtUIFactory.h @@ -37,6 +37,7 @@ namespace Swift { virtual JoinMUCWindow* createJoinMUCWindow(); virtual ProfileWindow* createProfileWindow(); virtual ContactEditWindow* createContactEditWindow(); + virtual void createAdHocCommandWindow(boost::shared_ptr<OutgoingAdHocCommandSession> command); private slots: void handleLoginWindowGeometryChanged(); diff --git a/Swift/QtUI/QtURIHandler.cpp b/Swift/QtUI/QtURIHandler.cpp new file mode 100644 index 0000000..43f3ed1 --- /dev/null +++ b/Swift/QtUI/QtURIHandler.cpp @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2011 Remko Tronçon + * Licensed under the GNU General Public License v3. + * See Documentation/Licenses/GPLv3.txt for more information. + */ + +#include "QtURIHandler.h" + +#include <QCoreApplication> +#include <QFileOpenEvent> +#include <QUrl> + +#include "QtSwiftUtil.h" +#ifdef Q_WS_MAC +#include <SwifTools/URIHandler/MacOSXURIHandlerHelpers.h> +#endif + +using namespace Swift; + +QtURIHandler::QtURIHandler() { + qApp->installEventFilter(this); +#ifdef Q_WS_MAC + registerAppAsDefaultXMPPURIHandler(); +#endif +} + +bool QtURIHandler::eventFilter(QObject*, QEvent* event) { + if (event->type() == QEvent::FileOpen) { + QFileOpenEvent* fileOpenEvent = static_cast<QFileOpenEvent*>(event); + if (fileOpenEvent->url().scheme() == "xmpp") { + onURI(Q2PSTRING(fileOpenEvent->url().toString())); + return true; + } + } + return false; +} diff --git a/Swift/QtUI/QtURIHandler.h b/Swift/QtUI/QtURIHandler.h new file mode 100644 index 0000000..a02114a --- /dev/null +++ b/Swift/QtUI/QtURIHandler.h @@ -0,0 +1,22 @@ +/* + * Copyright (c) 2011 Remko Tronçon + * Licensed under the GNU General Public License v3. + * See Documentation/Licenses/GPLv3.txt for more information. + */ + +#pragma once + +#include <QObject> +#include <SwifTools/URIHandler/URIHandler.h> + +class QUrl; + +namespace Swift { + class QtURIHandler : public QObject, public URIHandler { + public: + QtURIHandler(); + + private: + bool eventFilter(QObject* obj, QEvent* event); + }; +} diff --git a/Swift/QtUI/SConscript b/Swift/QtUI/SConscript index 494731c..ef4f744 100644 --- a/Swift/QtUI/SConscript +++ b/Swift/QtUI/SConscript @@ -77,6 +77,7 @@ sources = [ "QtStatusWidget.cpp", "QtScaledAvatarCache.cpp", "QtSwift.cpp", + "QtURIHandler.cpp", "QtChatView.cpp", "QtChatTheme.cpp", "QtChatTabs.cpp", @@ -87,6 +88,7 @@ sources = [ "QtTabWidget.cpp", "QtTextEdit.cpp", "QtXMLConsoleWidget.cpp", + "QtAdHocCommandWindow.cpp", "QtUtilities.cpp", "QtBookmarkDetailWindow.cpp", "QtAddBookmarkWindow.cpp", @@ -97,6 +99,7 @@ sources = [ "MessageSnippet.cpp", "SystemMessageSnippet.cpp", "QtElidingLabel.cpp", + "QtFormWidget.cpp", "QtLineEdit.cpp", "QtJoinMUCWindow.cpp", "Roster/RosterModel.cpp", @@ -114,6 +117,7 @@ sources = [ "ChatList/ChatListModel.cpp", "ChatList/ChatListDelegate.cpp", "ChatList/ChatListMUCItem.cpp", + "ChatList/ChatListRecentItem.cpp", "MUCSearch/QtMUCSearchWindow.cpp", "MUCSearch/MUCSearchModel.cpp", "MUCSearch/MUCSearchRoomItem.cpp", @@ -136,20 +140,31 @@ sources = [ myenv["SWIFT_VERSION"] = Version.getBuildVersion(env.Dir("#").abspath, "swift") if env["PLATFORM"] == "win32" : - myenv.RES("../resources/Windows/Swift.rc") + res = myenv.RES("../resources/Windows/Swift.rc") + # For some reason, SCons isn't picking up the dependency correctly + # Adding it explicitly until i figure out why + myenv.Depends(res, "../Controllers/BuildVersion.h") sources += [ "WindowsNotifier.cpp", "../resources/Windows/Swift.res" ] if env["PLATFORM"] == "posix" : - sources += ["FreeDesktopNotifier.cpp"] + sources += [ + "FreeDesktopNotifier.cpp", + "QtDBUSURIHandler.cpp", + ] if env["PLATFORM"] == "darwin" or env["PLATFORM"] == "win32" : swiftProgram = myenv.Program("Swift", sources) else : swiftProgram = myenv.Program("swift", sources) +if env["PLATFORM"] != "darwin" and env["PLATFORM"] != "win32" : + openURIProgram = myenv.Program("swift-open-uri", "swift-open-uri.cpp") +else : + openURIProgram = [] + myenv.Uic4("MUCSearch/QtMUCSearchWindow.ui") myenv.Uic4("UserSearch/QtUserSearchWizard.ui") myenv.Uic4("UserSearch/QtUserSearchFirstPage.ui") @@ -215,12 +230,12 @@ if env["PLATFORM"] == "darwin" : if env["HAVE_GROWL"] : frameworks.append(env["GROWL_FRAMEWORK"]) commonResources[""] = commonResources.get("", []) + ["../resources/MacOSX/Swift.icns"] - app = myenv.AppBundle("Swift", version = myenv["SWIFT_VERSION"], resources = commonResources, frameworks = frameworks) + app = myenv.AppBundle("Swift", version = myenv["SWIFT_VERSION"], resources = commonResources, frameworks = frameworks, handlesXMPPURIs = True) if env["DIST"] : myenv.Command(["Swift-${SWIFT_VERSION}.dmg"], [app], ["Swift/Packaging/MacOSX/package.sh " + app.path + " Swift/Packaging/MacOSX/Swift.dmg.gz $TARGET $QTDIR"]) if env.get("SWIFT_INSTALLDIR", "") : - env.Install(os.path.join(env["SWIFT_INSTALLDIR"], "bin"), swiftProgram) + env.Install(os.path.join(env["SWIFT_INSTALLDIR"], "bin"), swiftProgram + openURIProgram) env.InstallAs(os.path.join(env["SWIFT_INSTALLDIR"], "share", "pixmaps", "swift.xpm"), "../resources/logo/logo-icon-32.xpm") icons_path = os.path.join(env["SWIFT_INSTALLDIR"], "share", "icons", "hicolor") env.InstallAs(os.path.join(icons_path, "32x32", "apps", "swift.xpm"), "../resources/logo/logo-icon-32.xpm") diff --git a/Swift/QtUI/swift-open-uri.cpp b/Swift/QtUI/swift-open-uri.cpp new file mode 100644 index 0000000..2d5ef19 --- /dev/null +++ b/Swift/QtUI/swift-open-uri.cpp @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2011 Remko Tronçon + * Licensed under the GNU General Public License v3. + * See Documentation/Licenses/GPLv3.txt for more information. + */ + +#include <QCoreApplication> +#include <QDBusConnection> +#include <QDBusMessage> +#include <iostream> + +int main(int argc, char* argv[]) { + QCoreApplication app(argc, argv); + + QDBusConnection bus = QDBusConnection::sessionBus(); + if (!bus.isConnected()) { + return -1; + } + if (argc != 2) { + std::cerr << "Usage: " << argv[0] << " uri" << std::endl; + return -1; + } + + QDBusMessage msg = QDBusMessage::createMethodCall("im.swift.Swift.URIHandler", "/", "im.swift.Swift.URIHandler", "openURI"); + msg << argv[1]; + + bus.call(msg); + + return 0; +} diff --git a/Swift/Translations/swift_nl.ts b/Swift/Translations/swift_nl.ts index 0683260..7e8bfbd 100644 --- a/Swift/Translations/swift_nl.ts +++ b/Swift/Translations/swift_nl.ts @@ -416,6 +416,22 @@ <source>There was an error publishing your profile data</source> <translation>Er is een fout opgetreden bij het publiceren van uw profiel</translation> </message> + <message> + <source>%1% (%2%)</source> + <translation>%1% (%2%)</translation> + </message> + <message> + <source>%1% and %2% others (%3%)</source> + <translation>%1% en %2% anderen (%3%)</translation> + </message> + <message> + <source>%1%, %2% (%3%)</source> + <translation>%1%, %2% (%3%)</translation> + </message> + <message> + <source>User address invalid. User address should be of the form 'alice@wonderland.lit'</source> + <translation>Gebruikersadres ongeldig. Gebruikersadres moet van de vorm 'alice@wonderland.lit' zijn</translation> + </message> </context> <context> <name>CloseButton</name> @@ -835,6 +851,10 @@ <source>Bookmarked Rooms</source> <translation>Bladwijzers</translation> </message> + <message> + <source>Recent Chats</source> + <translation>Recente conversaties</translation> + </message> </context> <context> <name>Swift::QtAboutWidget</name> @@ -866,6 +886,37 @@ </message> </context> <context> + <name>Swift::QtAdHocCommandWindow</name> + <message> + <source>Cancel</source> + <translation>Annuleren</translation> + </message> + <message> + <source>Back</source> + <translation>Terug</translation> + </message> + <message> + <source>Next</source> + <translation>Volgende</translation> + </message> + <message> + <source>Complete</source> + <translation>Voltooien</translation> + </message> + <message> + <source>Error: %1</source> + <translation>Fout: %1</translation> + </message> + <message> + <source>Warning: %1</source> + <translation>Waarschuwing: %1</translation> + </message> + <message> + <source>Error executing command</source> + <translation>Fout bij het uitvoeren van de opdracht</translation> + </message> +</context> +<context> <name>Swift::QtAvatarWidget</name> <message> <source>No picture</source> @@ -1161,6 +1212,18 @@ afbeelding</translation> <source>Enter &Room</source> <translation>&Kamer betreden</translation> </message> + <message> + <source>Run Server Command</source> + <translation>Voer opdracht op server uit</translation> + </message> + <message> + <source>Collecting commands...</source> + <translation>Opdrachten aan het verzamelen...</translation> + </message> + <message> + <source>No Available Commands</source> + <translation>Geen beschikbare opdrachten</translation> + </message> </context> <context> <name>Swift::QtNameWidget</name> diff --git a/Swiften/AdHoc/OutgoingAdHocCommandSession.cpp b/Swiften/AdHoc/OutgoingAdHocCommandSession.cpp new file mode 100644 index 0000000..da7f042 --- /dev/null +++ b/Swiften/AdHoc/OutgoingAdHocCommandSession.cpp @@ -0,0 +1,102 @@ +/* + * Copyright (c) 2010-2011 Kevin Smith + * Licensed under the GNU General Public License v3. + * See Documentation/Licenses/GPLv3.txt for more information. + */ + +#include <Swiften/AdHoc/OutgoingAdHocCommandSession.h> + +#include <boost/bind.hpp> + +#include <Swiften/Queries/GenericRequest.h> + +namespace Swift { +OutgoingAdHocCommandSession::OutgoingAdHocCommandSession(const DiscoItems::Item& command, AdHocCommandWindowFactory* /*factory*/, IQRouter* iqRouter) : command_(command), iqRouter_(iqRouter), isMultiStage_(false) { + +} + +void OutgoingAdHocCommandSession::handleResponse(boost::shared_ptr<Command> payload, ErrorPayload::ref error) { + if (error) { + onError(error); + } else { + const std::vector<Command::Action> actions = payload->getAvailableActions(); + actionStates_.clear(); + if (payload->getStatus() == Command::Executing ) { + actionStates_[Command::Cancel] = EnabledAndPresent; + actionStates_[Command::Complete] = Present; + if (std::find(actions.begin(), actions.end(), Command::Complete) != actions.end()) { + actionStates_[Command::Complete] = EnabledAndPresent; + } + + if (getIsMultiStage()) { + actionStates_[Command::Next] = Present; + actionStates_[Command::Prev] = Present; + } + + if (std::find(actions.begin(), actions.end(), Command::Next) != actions.end()) { + actionStates_[Command::Next] = EnabledAndPresent; + } + if (std::find(actions.begin(), actions.end(), Command::Prev) != actions.end()) { + actionStates_[Command::Prev] = EnabledAndPresent; + } + } + + sessionID_ = payload->getSessionID(); + if (std::find(actions.begin(), actions.end(), Command::Next) != actions.end() + || std::find(actions.begin(), actions.end(), Command::Prev) != actions.end()) { + isMultiStage_ = true; + } + onNextStageReceived(payload); + } +} + +bool OutgoingAdHocCommandSession::getIsMultiStage() { + return isMultiStage_; +} + +void OutgoingAdHocCommandSession::start() { + boost::shared_ptr<Payload> commandPayload(new Command(command_.getNode())); + boost::shared_ptr<GenericRequest<Command> > commandRequest(new GenericRequest<Command>(IQ::Set, command_.getJID(), commandPayload, iqRouter_)); + commandRequest->onResponse.connect(boost::bind(&OutgoingAdHocCommandSession::handleResponse, this, _1, _2)); + commandRequest->send(); +} + +void OutgoingAdHocCommandSession::cancel() { + if (!sessionID_.empty()) { + boost::shared_ptr<Payload> commandPayload(new Command(command_.getNode(), sessionID_, Command::Cancel)); + boost::shared_ptr<GenericRequest<Command> > commandRequest(new GenericRequest<Command>(IQ::Set, command_.getJID(), commandPayload, iqRouter_)); + commandRequest->onResponse.connect(boost::bind(&OutgoingAdHocCommandSession::handleResponse, this, _1, _2)); + commandRequest->send(); + } +} + +void OutgoingAdHocCommandSession::goBack() { + boost::shared_ptr<Payload> commandPayload(new Command(command_.getNode(), sessionID_, Command::Prev)); + boost::shared_ptr<GenericRequest<Command> > commandRequest(new GenericRequest<Command>(IQ::Set, command_.getJID(), commandPayload, iqRouter_)); + commandRequest->onResponse.connect(boost::bind(&OutgoingAdHocCommandSession::handleResponse, this, _1, _2)); + commandRequest->send(); +} + +void OutgoingAdHocCommandSession::complete(Form::ref form) { + Command* command = new Command(command_.getNode(), sessionID_, Command::Complete); + boost::shared_ptr<Payload> commandPayload(command); + command->setForm(form); + boost::shared_ptr<GenericRequest<Command> > commandRequest(new GenericRequest<Command>(IQ::Set, command_.getJID(), commandPayload, iqRouter_)); + commandRequest->onResponse.connect(boost::bind(&OutgoingAdHocCommandSession::handleResponse, this, _1, _2)); + commandRequest->send(); +} + +void OutgoingAdHocCommandSession::goNext(Form::ref form) { + Command* command = new Command(command_.getNode(), sessionID_, Command::Next); + boost::shared_ptr<Payload> commandPayload(command); + command->setForm(form); + boost::shared_ptr<GenericRequest<Command> > commandRequest(new GenericRequest<Command>(IQ::Set, command_.getJID(), commandPayload, iqRouter_)); + commandRequest->onResponse.connect(boost::bind(&OutgoingAdHocCommandSession::handleResponse, this, _1, _2)); + commandRequest->send(); +} + +OutgoingAdHocCommandSession::ActionState OutgoingAdHocCommandSession::getActionState(Command::Action action) { + return actionStates_[action]; +} + +} diff --git a/Swiften/AdHoc/OutgoingAdHocCommandSession.h b/Swiften/AdHoc/OutgoingAdHocCommandSession.h new file mode 100644 index 0000000..f4b5242 --- /dev/null +++ b/Swiften/AdHoc/OutgoingAdHocCommandSession.h @@ -0,0 +1,88 @@ +/* + * Copyright (c) 2010-2011 Kevin Smith + * Licensed under the GNU General Public License v3. + * See Documentation/Licenses/GPLv3.txt for more information. + */ + +#pragma once + +#include <Swiften/Base/boost_bsignals.h> +#include <boost/shared_ptr.hpp> +#include <Swiften/Elements/DiscoItems.h> +#include <Swiften/Elements/Command.h> +#include <Swiften/Elements/ErrorPayload.h> + +namespace Swift { + class IQRouter; + class MainWindow; + class UIEventStream; + class AdHocCommandWindowFactory; + class OutgoingAdHocCommandSession { + public: + + /** + * Availability of action. + */ + enum ActionState { + Absent /** Action isn't applicable to this command. */ = 0, + Present /** Action is applicable to this command */= 1, + Enabled /** Action is applicable and currently available */ = 2, + EnabledAndPresent = 3}; + + OutgoingAdHocCommandSession(const DiscoItems::Item& command, AdHocCommandWindowFactory* factory, IQRouter* iqRouter); + /** + * Send initial request to the target. + */ + void start(); + /** + * Cancel command session with the target. + */ + void cancel(); + /** + * Return to the previous stage. + */ + void goBack(); + /** + * Send the form to complete the command. + * \param form Form for submission - if missing the command will be submitted with no form. + */ + void complete(Form::ref form); + /** + * Send the form to advance to the next stage of the command. + * \param form Form for submission - if missing the command will be submitted with no form. + */ + void goNext(Form::ref form); + + /** + * Is the form multi-stage? + */ + bool getIsMultiStage(); + + /** + * Emitted when the form for the next stage is available. + */ + boost::signal<void (Command::ref)> onNextStageReceived; + + /** + * Emitted on error. + */ + boost::signal<void (ErrorPayload::ref)> onError; + + /** + * Get the state of a given action. + * This is useful for a UI to determine which buttons should be visible, + * and which enabled. + * Use for Next, Prev, Cancel and Complete only. + * If no actions are available, the command has completed. + */ + ActionState getActionState(Command::Action action); + private: + void handleResponse(boost::shared_ptr<Command> payload, ErrorPayload::ref error); + private: + DiscoItems::Item command_; + IQRouter* iqRouter_; + bool isMultiStage_; + std::string sessionID_; + std::map<Command::Action, ActionState> actionStates_; + }; +} diff --git a/Swiften/AdHoc/SConscript b/Swiften/AdHoc/SConscript new file mode 100644 index 0000000..69c9083 --- /dev/null +++ b/Swiften/AdHoc/SConscript @@ -0,0 +1,6 @@ +Import("swiften_env") + +objects = swiften_env.SwiftenObject([ + "OutgoingAdHocCommandSession.cpp", + ]) +swiften_env.Append(SWIFTEN_OBJECTS = [objects]) diff --git a/Swiften/Avatars/AvatarManager.h b/Swiften/Avatars/AvatarManager.h index e1af451..3461973 100644 --- a/Swiften/Avatars/AvatarManager.h +++ b/Swiften/Avatars/AvatarManager.h @@ -6,7 +6,7 @@ #pragma once -#include <boost/filesystem.hpp> +#include <boost/filesystem/path.hpp> #include <Swiften/Base/boost_bsignals.h> #include <Swiften/Base/ByteArray.h> diff --git a/Swiften/Avatars/AvatarManagerImpl.cpp b/Swiften/Avatars/AvatarManagerImpl.cpp index 509ff47..78d94dc 100644 --- a/Swiften/Avatars/AvatarManagerImpl.cpp +++ b/Swiften/Avatars/AvatarManagerImpl.cpp @@ -4,15 +4,15 @@ * See Documentation/Licenses/GPLv3.txt for more information. */ -#include "Swiften/Avatars/AvatarManagerImpl.h" +#include <Swiften/Avatars/AvatarManagerImpl.h> #include <boost/bind.hpp> -#include "Swiften/Avatars/VCardUpdateAvatarManager.h" -#include "Swiften/Avatars/VCardAvatarManager.h" -#include "Swiften/Avatars/AvatarStorage.h" +#include <Swiften/Avatars/VCardUpdateAvatarManager.h> +#include <Swiften/Avatars/VCardAvatarManager.h> +#include <Swiften/Avatars/AvatarStorage.h> #include <Swiften/Avatars/OfflineAvatarManager.h> -#include "Swiften/Base/ByteArray.h" +#include <Swiften/Base/ByteArray.h> namespace Swift { diff --git a/Swiften/Avatars/AvatarProvider.cpp b/Swiften/Avatars/AvatarProvider.cpp index 680b58d..44c89d5 100644 --- a/Swiften/Avatars/AvatarProvider.cpp +++ b/Swiften/Avatars/AvatarProvider.cpp @@ -4,7 +4,7 @@ * See Documentation/Licenses/GPLv3.txt for more information. */ -#include "Swiften/Avatars/AvatarProvider.h" +#include <Swiften/Avatars/AvatarProvider.h> namespace Swift { diff --git a/Swiften/Avatars/AvatarProvider.h b/Swiften/Avatars/AvatarProvider.h index 0f66904..d2d408e 100644 --- a/Swiften/Avatars/AvatarProvider.h +++ b/Swiften/Avatars/AvatarProvider.h @@ -6,9 +6,10 @@ #pragma once -#include "Swiften/Base/boost_bsignals.h" #include <string> +#include <Swiften/Base/boost_bsignals.h> + namespace Swift { class JID; diff --git a/Swiften/Avatars/AvatarStorage.cpp b/Swiften/Avatars/AvatarStorage.cpp index 1bf71e1..8bb1126 100644 --- a/Swiften/Avatars/AvatarStorage.cpp +++ b/Swiften/Avatars/AvatarStorage.cpp @@ -4,7 +4,7 @@ * See Documentation/Licenses/GPLv3.txt for more information. */ -#include "Swiften/Avatars/AvatarStorage.h" +#include <Swiften/Avatars/AvatarStorage.h> namespace Swift { diff --git a/Swiften/Avatars/AvatarStorage.h b/Swiften/Avatars/AvatarStorage.h index 48fc885..d1aff39 100644 --- a/Swiften/Avatars/AvatarStorage.h +++ b/Swiften/Avatars/AvatarStorage.h @@ -6,7 +6,7 @@ #pragma once -#include <boost/filesystem.hpp> +#include <boost/filesystem/path.hpp> #include <string> namespace Swift { diff --git a/Swiften/Avatars/CombinedAvatarProvider.cpp b/Swiften/Avatars/CombinedAvatarProvider.cpp index eea0b89..d283664 100644 --- a/Swiften/Avatars/CombinedAvatarProvider.cpp +++ b/Swiften/Avatars/CombinedAvatarProvider.cpp @@ -4,7 +4,7 @@ * See Documentation/Licenses/GPLv3.txt for more information. */ -#include "Swiften/Avatars/CombinedAvatarProvider.h" +#include <Swiften/Avatars/CombinedAvatarProvider.h> #include <algorithm> #include <boost/bind.hpp> diff --git a/Swiften/Avatars/CombinedAvatarProvider.h b/Swiften/Avatars/CombinedAvatarProvider.h index 72e67cf..7b29efc 100644 --- a/Swiften/Avatars/CombinedAvatarProvider.h +++ b/Swiften/Avatars/CombinedAvatarProvider.h @@ -9,8 +9,8 @@ #include <vector> #include <map> -#include "Swiften/Avatars/AvatarProvider.h" -#include "Swiften/JID/JID.h" +#include <Swiften/Avatars/AvatarProvider.h> +#include <Swiften/JID/JID.h> namespace Swift { class CombinedAvatarProvider : public AvatarProvider { diff --git a/Swiften/Avatars/NullAvatarManager.h b/Swiften/Avatars/NullAvatarManager.h index e96ed7a..3f5b9f5 100644 --- a/Swiften/Avatars/NullAvatarManager.h +++ b/Swiften/Avatars/NullAvatarManager.h @@ -6,7 +6,7 @@ #pragma once -#include "Swiften/Avatars/AvatarManager.h" +#include <Swiften/Avatars/AvatarManager.h> namespace Swift { class NullAvatarManager : public AvatarManager { diff --git a/Swiften/Avatars/SConscript b/Swiften/Avatars/SConscript index 46ae897..9c219a4 100644 --- a/Swiften/Avatars/SConscript +++ b/Swiften/Avatars/SConscript @@ -1,7 +1,6 @@ Import("swiften_env") objects = swiften_env.SwiftenObject([ - "AvatarFileStorage.cpp", "VCardUpdateAvatarManager.cpp", "VCardAvatarManager.cpp", "OfflineAvatarManager.cpp", diff --git a/Swiften/Avatars/UnitTest/CombinedAvatarProviderTest.cpp b/Swiften/Avatars/UnitTest/CombinedAvatarProviderTest.cpp index 4894e14..422610d 100644 --- a/Swiften/Avatars/UnitTest/CombinedAvatarProviderTest.cpp +++ b/Swiften/Avatars/UnitTest/CombinedAvatarProviderTest.cpp @@ -8,9 +8,9 @@ #include <cppunit/extensions/TestFactoryRegistry.h> #include <boost/bind.hpp> -#include "Swiften/JID/JID.h" +#include <Swiften/JID/JID.h> #include <string> -#include "Swiften/Avatars/CombinedAvatarProvider.h" +#include <Swiften/Avatars/CombinedAvatarProvider.h> using namespace Swift; diff --git a/Swiften/Avatars/UnitTest/VCardAvatarManagerTest.cpp b/Swiften/Avatars/UnitTest/VCardAvatarManagerTest.cpp index be5eaea..6e7bdca 100644 --- a/Swiften/Avatars/UnitTest/VCardAvatarManagerTest.cpp +++ b/Swiften/Avatars/UnitTest/VCardAvatarManagerTest.cpp @@ -4,22 +4,22 @@ * See Documentation/Licenses/GPLv3.txt for more information. */ -#include "Swiften/Base/ByteArray.h" +#include <Swiften/Base/ByteArray.h> #include <cppunit/extensions/HelperMacros.h> #include <cppunit/extensions/TestFactoryRegistry.h> #include <boost/bind.hpp> -#include "Swiften/Elements/VCard.h" -#include "Swiften/Avatars/VCardAvatarManager.h" -#include "Swiften/Avatars/AvatarMemoryStorage.h" -#include "Swiften/VCards/VCardMemoryStorage.h" -#include "Swiften/VCards/VCardManager.h" -#include "Swiften/MUC/MUCRegistry.h" -#include "Swiften/Queries/IQRouter.h" -#include "Swiften/Client/DummyStanzaChannel.h" -#include "Swiften/StringCodecs/SHA1.h" -#include "Swiften/StringCodecs/Hexify.h" +#include <Swiften/Elements/VCard.h> +#include <Swiften/Avatars/VCardAvatarManager.h> +#include <Swiften/Avatars/AvatarMemoryStorage.h> +#include <Swiften/VCards/VCardMemoryStorage.h> +#include <Swiften/VCards/VCardManager.h> +#include <Swiften/MUC/MUCRegistry.h> +#include <Swiften/Queries/IQRouter.h> +#include <Swiften/Client/DummyStanzaChannel.h> +#include <Swiften/StringCodecs/SHA1.h> +#include <Swiften/StringCodecs/Hexify.h> using namespace Swift; diff --git a/Swiften/Avatars/UnitTest/VCardUpdateAvatarManagerTest.cpp b/Swiften/Avatars/UnitTest/VCardUpdateAvatarManagerTest.cpp index cde4a45..23c70e5 100644 --- a/Swiften/Avatars/UnitTest/VCardUpdateAvatarManagerTest.cpp +++ b/Swiften/Avatars/UnitTest/VCardUpdateAvatarManagerTest.cpp @@ -4,22 +4,22 @@ * See Documentation/Licenses/GPLv3.txt for more information. */ -#include "Swiften/Base/ByteArray.h" +#include <Swiften/Base/ByteArray.h> #include <cppunit/extensions/HelperMacros.h> #include <cppunit/extensions/TestFactoryRegistry.h> #include <boost/bind.hpp> -#include "Swiften/Elements/VCardUpdate.h" -#include "Swiften/Avatars/VCardUpdateAvatarManager.h" -#include "Swiften/Avatars/AvatarMemoryStorage.h" -#include "Swiften/VCards/VCardMemoryStorage.h" -#include "Swiften/VCards/VCardManager.h" -#include "Swiften/MUC/MUCRegistry.h" -#include "Swiften/Queries/IQRouter.h" -#include "Swiften/Client/DummyStanzaChannel.h" -#include "Swiften/StringCodecs/SHA1.h" -#include "Swiften/StringCodecs/Hexify.h" +#include <Swiften/Elements/VCardUpdate.h> +#include <Swiften/Avatars/VCardUpdateAvatarManager.h> +#include <Swiften/Avatars/AvatarMemoryStorage.h> +#include <Swiften/VCards/VCardMemoryStorage.h> +#include <Swiften/VCards/VCardManager.h> +#include <Swiften/MUC/MUCRegistry.h> +#include <Swiften/Queries/IQRouter.h> +#include <Swiften/Client/DummyStanzaChannel.h> +#include <Swiften/StringCodecs/SHA1.h> +#include <Swiften/StringCodecs/Hexify.h> using namespace Swift; diff --git a/Swiften/Avatars/VCardAvatarManager.cpp b/Swiften/Avatars/VCardAvatarManager.cpp index 046e6f3..84f94d5 100644 --- a/Swiften/Avatars/VCardAvatarManager.cpp +++ b/Swiften/Avatars/VCardAvatarManager.cpp @@ -4,16 +4,16 @@ * See Documentation/Licenses/GPLv3.txt for more information. */ -#include "Swiften/Avatars/VCardAvatarManager.h" +#include <Swiften/Avatars/VCardAvatarManager.h> #include <boost/bind.hpp> -#include "Swiften/Elements/VCard.h" -#include "Swiften/StringCodecs/SHA1.h" -#include "Swiften/StringCodecs/Hexify.h" -#include "Swiften/Avatars/AvatarStorage.h" -#include "Swiften/MUC/MUCRegistry.h" -#include "Swiften/VCards/VCardManager.h" +#include <Swiften/Elements/VCard.h> +#include <Swiften/StringCodecs/SHA1.h> +#include <Swiften/StringCodecs/Hexify.h> +#include <Swiften/Avatars/AvatarStorage.h> +#include <Swiften/MUC/MUCRegistry.h> +#include <Swiften/VCards/VCardManager.h> namespace Swift { diff --git a/Swiften/Avatars/VCardAvatarManager.h b/Swiften/Avatars/VCardAvatarManager.h index 3f99dad..cb3945d 100644 --- a/Swiften/Avatars/VCardAvatarManager.h +++ b/Swiften/Avatars/VCardAvatarManager.h @@ -6,11 +6,8 @@ #pragma once -#include <map> - -#include "Swiften/Avatars/AvatarProvider.h" -#include "Swiften/JID/JID.h" -#include "Swiften/Elements/VCard.h" +#include <Swiften/Avatars/AvatarProvider.h> +#include <Swiften/JID/JID.h> namespace Swift { class MUCRegistry; diff --git a/Swiften/Avatars/VCardUpdateAvatarManager.cpp b/Swiften/Avatars/VCardUpdateAvatarManager.cpp index ea074cc..26665c1 100644 --- a/Swiften/Avatars/VCardUpdateAvatarManager.cpp +++ b/Swiften/Avatars/VCardUpdateAvatarManager.cpp @@ -4,18 +4,18 @@ * See Documentation/Licenses/GPLv3.txt for more information. */ -#include "Swiften/Avatars/VCardUpdateAvatarManager.h" +#include <Swiften/Avatars/VCardUpdateAvatarManager.h> #include <boost/bind.hpp> -#include "Swiften/Client/StanzaChannel.h" -#include "Swiften/Elements/VCardUpdate.h" -#include "Swiften/VCards/GetVCardRequest.h" -#include "Swiften/StringCodecs/SHA1.h" -#include "Swiften/StringCodecs/Hexify.h" -#include "Swiften/Avatars/AvatarStorage.h" -#include "Swiften/MUC/MUCRegistry.h" -#include "Swiften/VCards/VCardManager.h" +#include <Swiften/Client/StanzaChannel.h> +#include <Swiften/Elements/VCardUpdate.h> +#include <Swiften/VCards/GetVCardRequest.h> +#include <Swiften/StringCodecs/SHA1.h> +#include <Swiften/StringCodecs/Hexify.h> +#include <Swiften/Avatars/AvatarStorage.h> +#include <Swiften/MUC/MUCRegistry.h> +#include <Swiften/VCards/VCardManager.h> #include <Swiften/Base/Log.h> namespace Swift { diff --git a/Swiften/Avatars/VCardUpdateAvatarManager.h b/Swiften/Avatars/VCardUpdateAvatarManager.h index 1f03898..de68672 100644 --- a/Swiften/Avatars/VCardUpdateAvatarManager.h +++ b/Swiften/Avatars/VCardUpdateAvatarManager.h @@ -9,11 +9,11 @@ #include <boost/shared_ptr.hpp> #include <map> -#include "Swiften/Avatars/AvatarProvider.h" -#include "Swiften/JID/JID.h" -#include "Swiften/Elements/Presence.h" -#include "Swiften/Elements/VCard.h" -#include "Swiften/Elements/ErrorPayload.h" +#include <Swiften/Avatars/AvatarProvider.h> +#include <Swiften/JID/JID.h> +#include <Swiften/Elements/Presence.h> +#include <Swiften/Elements/VCard.h> +#include <Swiften/Elements/ErrorPayload.h> namespace Swift { class MUCRegistry; diff --git a/Swiften/Base/ByteArray.cpp b/Swiften/Base/ByteArray.cpp index 928e145..8c8b215 100644 --- a/Swiften/Base/ByteArray.cpp +++ b/Swiften/Base/ByteArray.cpp @@ -4,11 +4,15 @@ * See Documentation/Licenses/GPLv3.txt for more information. */ -#include "Swiften/Base/ByteArray.h" +#include <Swiften/Base/ByteArray.h> #include <fstream> std::ostream& operator<<(std::ostream& os, const Swift::ByteArray& s) { + return operator<<(os, s.getDataVector()); +} + +std::ostream& operator<<(std::ostream& os, const std::vector<unsigned char>& s) { std::ios::fmtflags oldFlags = os.flags(); os << std::hex; for (Swift::ByteArray::const_iterator i = s.begin(); i != s.end(); ++i) { @@ -37,4 +41,45 @@ void ByteArray::readFromFile(const std::string& file) { input.close(); } +std::vector<unsigned char> ByteArray::create(const std::string& s) { + return std::vector<unsigned char>(s.begin(), s.end()); +} + +std::vector<unsigned char> ByteArray::create(const char* c) { + std::vector<unsigned char> data; + while (*c) { + data.push_back(static_cast<unsigned char>(*c)); + ++c; + } + return data; +} + +std::vector<unsigned char> ByteArray::create(const char* c, size_t n) { + std::vector<unsigned char> data; + if (n > 0) { + data.resize(n); + memcpy(&data[0], c, n); + } + return data; +} + +std::vector<unsigned char> ByteArray::create(const unsigned char* c, size_t n) { + std::vector<unsigned char> data; + if (n > 0) { + data.resize(n); + memcpy(&data[0], c, n); + } + return data; +} + +std::string ByteArray::toString() const { + size_t i; + for (i = data_.size(); i > 0; --i) { + if (data_[i - 1] != 0) { + break; + } + } + return i > 0 ? std::string(reinterpret_cast<const char*>(getData()), i) : ""; +} + } diff --git a/Swiften/Base/ByteArray.h b/Swiften/Base/ByteArray.h index ad2c1e5..ebc22d8 100644 --- a/Swiften/Base/ByteArray.h +++ b/Swiften/Base/ByteArray.h @@ -6,11 +6,9 @@ #pragma once -#include <cstring> #include <vector> -#include <iostream> - #include <string> +#include <cstring> // for memcpy namespace Swift { class ByteArray @@ -24,7 +22,7 @@ namespace Swift { ByteArray(const char* c) { while (*c) { - data_.push_back(*c); + data_.push_back(static_cast<unsigned char>(*c)); ++c; } } @@ -75,7 +73,7 @@ namespace Swift { } void resize(size_t size, char c) { - return data_.resize(size, c); + return data_.resize(size, static_cast<unsigned char>(c)); } friend ByteArray operator+(const ByteArray& a, const ByteArray&b) { @@ -87,7 +85,7 @@ namespace Swift { friend ByteArray operator+(const ByteArray& a, char b) { ByteArray x; x.resize(1); - x[0] = b; + x[0] = static_cast<unsigned char>(b); return a + x; } @@ -97,7 +95,7 @@ namespace Swift { } ByteArray& operator+=(char c) { - data_.push_back(c); + data_.push_back(static_cast<unsigned char>(c)); return *this; } @@ -122,9 +120,7 @@ namespace Swift { return data_.end(); } - std::string toString() const { - return std::string(reinterpret_cast<const char*>(getData()), getSize()); - } + std::string toString() const; void readFromFile(const std::string& file); @@ -132,9 +128,27 @@ namespace Swift { data_.clear(); } + const std::vector<unsigned char>& getDataVector() const { + return data_; + } + + static std::vector<unsigned char> create(const std::string& s); + static std::vector<unsigned char> create(const char* c); + static std::vector<unsigned char> create(const unsigned char* c, size_t n); + static std::vector<unsigned char> create(const char* c, size_t n); + + static const unsigned char* data(const std::vector<unsigned char>& v) { + return v.empty() ? NULL : &v[0]; + } + + static const char* charData(const std::vector<unsigned char>& v) { + return v.empty() ? NULL : reinterpret_cast<const char*>(&v[0]); + } + private: std::vector<unsigned char> data_; }; } std::ostream& operator<<(std::ostream& os, const Swift::ByteArray& s); +std::ostream& operator<<(std::ostream& os, const std::vector<unsigned char>& s); diff --git a/Swiften/Base/Error.cpp b/Swiften/Base/Error.cpp index dd127a6..60ad7ac 100644 --- a/Swiften/Base/Error.cpp +++ b/Swiften/Base/Error.cpp @@ -4,7 +4,7 @@ * See Documentation/Licenses/GPLv3.txt for more information. */ -#include "Swiften/Base/Error.h" +#include <Swiften/Base/Error.h> namespace Swift { diff --git a/Swiften/Base/IDGenerator.cpp b/Swiften/Base/IDGenerator.cpp index 74a0f65..80ed34d 100644 --- a/Swiften/Base/IDGenerator.cpp +++ b/Swiften/Base/IDGenerator.cpp @@ -4,7 +4,7 @@ * See Documentation/Licenses/GPLv3.txt for more information. */ -#include "Swiften/Base/IDGenerator.h" +#include <Swiften/Base/IDGenerator.h> namespace Swift { diff --git a/Swiften/Base/IDGenerator.h b/Swiften/Base/IDGenerator.h index 4b6289b..d536dcc 100644 --- a/Swiften/Base/IDGenerator.h +++ b/Swiften/Base/IDGenerator.h @@ -4,8 +4,7 @@ * See Documentation/Licenses/GPLv3.txt for more information. */ -#ifndef SWIFTEN_IDGenerator_H -#define SWIFTEN_IDGenerator_H +#pragma once #include <string> @@ -20,5 +19,3 @@ namespace Swift { std::string currentID_; }; } - -#endif diff --git a/Swiften/Base/Log.cpp b/Swiften/Base/Log.cpp index 2041013..4132353 100644 --- a/Swiften/Base/Log.cpp +++ b/Swiften/Base/Log.cpp @@ -4,7 +4,7 @@ * See Documentation/Licenses/GPLv3.txt for more information. */ -#include "Swiften/Base/Log.h" +#include <Swiften/Base/Log.h> namespace Swift { diff --git a/Swiften/Base/Paths.cpp b/Swiften/Base/Paths.cpp index 43eee57..d901ff9 100644 --- a/Swiften/Base/Paths.cpp +++ b/Swiften/Base/Paths.cpp @@ -25,7 +25,7 @@ boost::filesystem::path Paths::getExecutablePath() { uint32_t size = 4096; path.resize(size); if (_NSGetExecutablePath(reinterpret_cast<char*>(path.getData()), &size) == 0) { - return boost::filesystem::path(path.toString().c_str()).parent_path(); + return boost::filesystem::path(std::string(reinterpret_cast<const char*>(path.getData()), path.getSize()).c_str()).parent_path(); } #elif defined(SWIFTEN_PLATFORM_LINUX) ByteArray path; @@ -33,13 +33,13 @@ boost::filesystem::path Paths::getExecutablePath() { size_t size = readlink("/proc/self/exe", reinterpret_cast<char*>(path.getData()), path.getSize()); if (size > 0) { path.resize(size); - return boost::filesystem::path(path.toString().c_str()).parent_path(); + return boost::filesystem::path(std::string(reinterpret_cast<const char*>(path.getData()), path.getSize()).c_str()).parent_path(); } #elif defined(SWIFTEN_PLATFORM_WINDOWS) ByteArray data; data.resize(2048); GetModuleFileName(NULL, reinterpret_cast<char*>(data.getData()), data.getSize()); - return boost::filesystem::path(data.toString().c_str()).parent_path(); + return boost::filesystem::path(std::string(reinterpret_cast<const char*>(data.getData()), data.getSize()).c_str()).parent_path(); #endif return boost::filesystem::path(); } diff --git a/Swiften/Base/Paths.h b/Swiften/Base/Paths.h index 06c6aeb..8ac4640 100644 --- a/Swiften/Base/Paths.h +++ b/Swiften/Base/Paths.h @@ -6,7 +6,7 @@ #pragma once -#include <boost/filesystem.hpp> +#include <boost/filesystem/path.hpp> namespace Swift { class Paths { diff --git a/Swiften/Base/Platform.h b/Swiften/Base/Platform.h index 32e2671..395747c 100644 --- a/Swiften/Base/Platform.h +++ b/Swiften/Base/Platform.h @@ -4,8 +4,7 @@ * See Documentation/Licenses/GPLv3.txt for more information. */ -#ifndef SWIFTEN_Platform_H -#define SWIFTEN_Platform_H +#pragma once // Base platforms #if defined(linux) || defined(__linux) || defined(__linux__) @@ -26,6 +25,10 @@ #define SWIFTEN_PLATFORM_BEOS #elif defined(macintosh) || defined(__APPLE__) || defined(__APPLE_CC__) #define SWIFTEN_PLATFORM_MACOSX +#include <TargetConditionals.h> +# if defined(TARGET_OS_IPHONE) +# define SWIFTEN_PLATFORM_IPHONE +# endif #elif defined(__IBMCPP__) || defined(_AIX) #define SWIFTEN_PLATFORM_AIX #elif defined(__amigaos__) @@ -46,5 +49,3 @@ #elif defined(BOOST_BIG_ENDIAN) #define SWIFTEN_BIG_ENDIAN #endif - -#endif diff --git a/Swiften/Base/String.h b/Swiften/Base/String.h index 192d53b..0de6cac 100644 --- a/Swiften/Base/String.h +++ b/Swiften/Base/String.h @@ -6,7 +6,6 @@ #pragma once -#include <map> #include <string> #include <vector> diff --git a/Swiften/Base/UnitTest/ByteArrayTest.cpp b/Swiften/Base/UnitTest/ByteArrayTest.cpp index cb10dd4..b663166 100644 --- a/Swiften/Base/UnitTest/ByteArrayTest.cpp +++ b/Swiften/Base/UnitTest/ByteArrayTest.cpp @@ -7,13 +7,18 @@ #include <cppunit/extensions/HelperMacros.h> #include <cppunit/extensions/TestFactoryRegistry.h> -#include "Swiften/Base/ByteArray.h" +#include <Swiften/Base/ByteArray.h> +#include <boost/lexical_cast.hpp> using namespace Swift; class ByteArrayTest : public CppUnit::TestFixture { CPPUNIT_TEST_SUITE(ByteArrayTest); CPPUNIT_TEST(testGetData_NoData); + CPPUNIT_TEST(testToString); + CPPUNIT_TEST(testToString_NullTerminated); + CPPUNIT_TEST(testToString_TwoNullTerminated); + CPPUNIT_TEST(testToString_AllNull); CPPUNIT_TEST_SUITE_END(); public: @@ -22,6 +27,30 @@ class ByteArrayTest : public CppUnit::TestFixture { CPPUNIT_ASSERT_EQUAL(reinterpret_cast<const char*>(NULL), reinterpret_cast<const char*>(testling.getData())); } + + void testToString() { + ByteArray testling(ByteArray::create("abcde")); + + CPPUNIT_ASSERT_EQUAL(std::string("abcde"), testling.toString()); + } + + void testToString_NullTerminated() { + ByteArray testling(ByteArray::create("abcde\0", 6)); + + CPPUNIT_ASSERT_EQUAL(std::string("abcde"), testling.toString()); + } + + void testToString_TwoNullTerminated() { + ByteArray testling(ByteArray::create("abcde\0\0", 7)); + + CPPUNIT_ASSERT_EQUAL(std::string("abcde"), testling.toString()); + } + + void testToString_AllNull() { + ByteArray testling(ByteArray::create("\0\0", 2)); + + CPPUNIT_ASSERT_EQUAL(std::string(""), testling.toString()); + } }; CPPUNIT_TEST_SUITE_REGISTRATION(ByteArrayTest); diff --git a/Swiften/Base/UnitTest/IDGeneratorTest.cpp b/Swiften/Base/UnitTest/IDGeneratorTest.cpp index 4874684..610138f 100644 --- a/Swiften/Base/UnitTest/IDGeneratorTest.cpp +++ b/Swiften/Base/UnitTest/IDGeneratorTest.cpp @@ -8,7 +8,7 @@ #include <cppunit/extensions/TestFactoryRegistry.h> #include <set> -#include "Swiften/Base/IDGenerator.h" +#include <Swiften/Base/IDGenerator.h> using namespace Swift; diff --git a/Swiften/Base/foreach.h b/Swiften/Base/foreach.h index 05366d6..87f6147 100644 --- a/Swiften/Base/foreach.h +++ b/Swiften/Base/foreach.h @@ -4,12 +4,9 @@ * See Documentation/Licenses/GPLv3.txt for more information. */ -#ifndef SWIFTEN_FOREACH_H -#define SWIFTEN_FOREACH_H +#pragma once #include <boost/foreach.hpp> #undef foreach #define foreach BOOST_FOREACH - -#endif diff --git a/Swiften/Base/format.h b/Swiften/Base/format.h index 4591827..0e49eaa 100644 --- a/Swiften/Base/format.h +++ b/Swiften/Base/format.h @@ -7,6 +7,7 @@ #pragma once #include <boost/format.hpp> +#include <iostream> namespace Swift { inline boost::format format(const std::string& s) { diff --git a/Swiften/Base/sleep.cpp b/Swiften/Base/sleep.cpp index 892a3ba..7161217 100644 --- a/Swiften/Base/sleep.cpp +++ b/Swiften/Base/sleep.cpp @@ -4,7 +4,7 @@ * See Documentation/Licenses/GPLv3.txt for more information. */ -#include "Swiften/Base/sleep.h" +#include <Swiften/Base/sleep.h> #include <boost/thread.hpp> diff --git a/Swiften/Base/sleep.h b/Swiften/Base/sleep.h index c2bc601..a95e907 100644 --- a/Swiften/Base/sleep.h +++ b/Swiften/Base/sleep.h @@ -4,11 +4,8 @@ * See Documentation/Licenses/GPLv3.txt for more information. */ -#ifndef SWIFTEN_sleep_H -#define SWIFTEN_sleep_H +#pragma once namespace Swift { void sleep(unsigned int msecs); } - -#endif diff --git a/Swiften/Chat/ChatStateNotifier.cpp b/Swiften/Chat/ChatStateNotifier.cpp index 6e0f458..498c76d 100644 --- a/Swiften/Chat/ChatStateNotifier.cpp +++ b/Swiften/Chat/ChatStateNotifier.cpp @@ -4,14 +4,14 @@ * See Documentation/Licenses/GPLv3.txt for more information. */ -#include "Swiften/Chat/ChatStateNotifier.h" +#include <Swiften/Chat/ChatStateNotifier.h> #include <boost/bind.hpp> -#include "Swiften/Elements/Message.h" -#include "Swiften/Elements/ChatState.h" -#include "Swiften/Client/StanzaChannel.h" -#include "Swiften/Disco/EntityCapsProvider.h" +#include <Swiften/Elements/Message.h> +#include <Swiften/Elements/ChatState.h> +#include <Swiften/Client/StanzaChannel.h> +#include <Swiften/Disco/EntityCapsProvider.h> namespace Swift { diff --git a/Swiften/Chat/ChatStateNotifier.h b/Swiften/Chat/ChatStateNotifier.h index 1185ed0..c691092 100644 --- a/Swiften/Chat/ChatStateNotifier.h +++ b/Swiften/Chat/ChatStateNotifier.h @@ -6,12 +6,12 @@ #pragma once -#include "Swiften/Base/boost_bsignals.h" +#include <Swiften/Base/boost_bsignals.h> #include <boost/shared_ptr.hpp> -#include "Swiften/Elements/Message.h" -#include "Swiften/Elements/ChatState.h" -#include "Swiften/JID/JID.h" +#include <Swiften/Elements/Message.h> +#include <Swiften/Elements/ChatState.h> +#include <Swiften/JID/JID.h> namespace Swift { class StanzaChannel; diff --git a/Swiften/Chat/ChatStateTracker.cpp b/Swiften/Chat/ChatStateTracker.cpp index 2afcf67..27be86c 100644 --- a/Swiften/Chat/ChatStateTracker.cpp +++ b/Swiften/Chat/ChatStateTracker.cpp @@ -4,7 +4,7 @@ * See Documentation/Licenses/GPLv3.txt for more information. */ -#include "Swiften/Chat/ChatStateTracker.h" +#include <Swiften/Chat/ChatStateTracker.h> namespace Swift { ChatStateTracker::ChatStateTracker() { diff --git a/Swiften/Chat/ChatStateTracker.h b/Swiften/Chat/ChatStateTracker.h index 343d828..b356644 100644 --- a/Swiften/Chat/ChatStateTracker.h +++ b/Swiften/Chat/ChatStateTracker.h @@ -6,12 +6,12 @@ #pragma once -#include "Swiften/Base/boost_bsignals.h" +#include <Swiften/Base/boost_bsignals.h> #include <boost/shared_ptr.hpp> -#include "Swiften/Elements/Message.h" -#include "Swiften/Elements/Presence.h" -#include "Swiften/Elements/ChatState.h" +#include <Swiften/Elements/Message.h> +#include <Swiften/Elements/Presence.h> +#include <Swiften/Elements/ChatState.h> namespace Swift { class ChatStateTracker { diff --git a/Swiften/Chat/UnitTest/ChatStateNotifierTest.cpp b/Swiften/Chat/UnitTest/ChatStateNotifierTest.cpp index 5d7961b..1b91076 100644 --- a/Swiften/Chat/UnitTest/ChatStateNotifierTest.cpp +++ b/Swiften/Chat/UnitTest/ChatStateNotifierTest.cpp @@ -8,9 +8,10 @@ #include <cppunit/extensions/TestFactoryRegistry.h> #include <boost/bind.hpp> -#include "Swiften/Chat/ChatStateNotifier.h" -#include "Swiften/Client/DummyStanzaChannel.h" -#include "Swiften/Disco/DummyEntityCapsProvider.h" +#include <Swiften/Base/foreach.h> +#include <Swiften/Chat/ChatStateNotifier.h> +#include <Swiften/Client/DummyStanzaChannel.h> +#include <Swiften/Disco/DummyEntityCapsProvider.h> using namespace Swift; diff --git a/Swiften/Client/Client.cpp b/Swiften/Client/Client.cpp index 7918c46..13071ac 100644 --- a/Swiften/Client/Client.cpp +++ b/Swiften/Client/Client.cpp @@ -4,27 +4,28 @@ * See Documentation/Licenses/GPLv3.txt for more information. */ -#include "Swiften/Client/Client.h" - -#include "Swiften/Queries/Responders/SoftwareVersionResponder.h" -#include "Swiften/Roster/XMPPRosterImpl.h" -#include "Swiften/Roster/XMPPRosterController.h" -#include "Swiften/Presence/PresenceOracle.h" -#include "Swiften/Presence/StanzaChannelPresenceSender.h" -#include "Swiften/Presence/DirectedPresenceSender.h" -#include "Swiften/MUC/MUCRegistry.h" -#include "Swiften/MUC/MUCManager.h" -#include "Swiften/Client/MemoryStorages.h" -#include "Swiften/VCards/VCardManager.h" -#include "Swiften/VCards/VCardManager.h" -#include "Swiften/Avatars/AvatarManagerImpl.h" -#include "Swiften/Disco/CapsManager.h" -#include "Swiften/Disco/EntityCapsManager.h" -#include "Swiften/Disco/ClientDiscoManager.h" -#include "Swiften/Client/NickResolver.h" -#include "Swiften/Presence/SubscriptionManager.h" -#include "Swiften/TLS/BlindCertificateTrustChecker.h" +#include <Swiften/Client/Client.h> + +#include <Swiften/Queries/Responders/SoftwareVersionResponder.h> +#include <Swiften/Roster/XMPPRosterImpl.h> +#include <Swiften/Roster/XMPPRosterController.h> +#include <Swiften/Presence/PresenceOracle.h> +#include <Swiften/Presence/StanzaChannelPresenceSender.h> +#include <Swiften/Presence/DirectedPresenceSender.h> +#include <Swiften/MUC/MUCRegistry.h> +#include <Swiften/MUC/MUCManager.h> +#include <Swiften/Client/MemoryStorages.h> +#include <Swiften/VCards/VCardManager.h> +#include <Swiften/VCards/VCardManager.h> +#include <Swiften/Avatars/AvatarManagerImpl.h> +#include <Swiften/Disco/CapsManager.h> +#include <Swiften/Disco/EntityCapsManager.h> +#include <Swiften/Disco/ClientDiscoManager.h> +#include <Swiften/Client/NickResolver.h> +#include <Swiften/Presence/SubscriptionManager.h> +#include <Swiften/TLS/BlindCertificateTrustChecker.h> #include <Swiften/Client/NickManagerImpl.h> +#include <Swiften/Client/ClientSession.h> namespace Swift { @@ -35,7 +36,7 @@ Client::Client(const JID& jid, const std::string& password, NetworkFactories* ne softwareVersionResponder->start(); roster = new XMPPRosterImpl(); - rosterController = new XMPPRosterController(getIQRouter(), roster); + rosterController = new XMPPRosterController(getIQRouter(), roster, getStorages()->getRosterStorage()); subscriptionManager = new SubscriptionManager(getStanzaChannel()); @@ -98,6 +99,11 @@ void Client::setSoftwareVersion(const std::string& name, const std::string& vers } void Client::requestRoster() { + // FIXME: We should set this once when the session is finished, but there + // is currently no callback for this + if (getSession()) { + rosterController->setUseVersioning(getSession()->getRosterVersioningSupported()); + } rosterController->requestRoster(); } diff --git a/Swiften/Client/Client.h b/Swiften/Client/Client.h index 083b8a0..05c1e6e 100644 --- a/Swiften/Client/Client.h +++ b/Swiften/Client/Client.h @@ -6,7 +6,7 @@ #pragma once -#include "Swiften/Client/CoreClient.h" +#include <Swiften/Client/CoreClient.h> namespace Swift { class SoftwareVersionResponder; @@ -85,12 +85,12 @@ namespace Swift { /** * Returns the last received presence for the given (full) JID. */ - Presence::ref getLastPresence(const JID& jid) const; + boost::shared_ptr<Presence> getLastPresence(const JID& jid) const; /** * Returns the presence with the highest priority received for the given JID. */ - Presence::ref getHighestPriorityPresence(const JID& bareJID) const; + boost::shared_ptr<Presence> getHighestPriorityPresence(const JID& bareJID) const; PresenceOracle* getPresenceOracle() const { return presenceOracle; @@ -142,7 +142,7 @@ namespace Swift { /** * This signal is emitted when a JID changes presence. */ - boost::signal<void (Presence::ref)> onPresenceChange; + boost::signal<void (boost::shared_ptr<Presence>)> onPresenceChange; private: Storages* getStorages() const; diff --git a/Swiften/Client/ClientOptions.h b/Swiften/Client/ClientOptions.h new file mode 100644 index 0000000..1155b46 --- /dev/null +++ b/Swiften/Client/ClientOptions.h @@ -0,0 +1,39 @@ +/* + * Copyright (c) 2011 Remko Tronçon + * Licensed under the GNU General Public License v3. + * See Documentation/Licenses/GPLv3.txt for more information. + */ + +#pragma once + +struct ClientOptions { + enum UseTLS { + NeverUseTLS, + UseTLSWhenAvailable + }; + + ClientOptions() : useStreamCompression(true), useTLS(UseTLSWhenAvailable), useStreamResumption(false) { + } + + /** + * Whether ZLib stream compression should be used when available. + * + * Default: true + */ + bool useStreamCompression; + + /** + * Sets whether TLS encryption should be used. + * + * Default: UseTLSWhenAvailable + */ + UseTLS useTLS; + + /** + * Use XEP-196 stream resumption when available. + * + * Default: false + */ + bool useStreamResumption; +}; + diff --git a/Swiften/Client/ClientSession.cpp b/Swiften/Client/ClientSession.cpp index e1c1d8e..a2f6a70 100644 --- a/Swiften/Client/ClientSession.cpp +++ b/Swiften/Client/ClientSession.cpp @@ -4,41 +4,41 @@ * See Documentation/Licenses/GPLv3.txt for more information. */ -#include "Swiften/Client/ClientSession.h" +#include <Swiften/Client/ClientSession.h> #include <boost/bind.hpp> #include <boost/uuid/uuid.hpp> #include <boost/uuid/uuid_io.hpp> #include <boost/uuid/uuid_generators.hpp> -#include "Swiften/Elements/ProtocolHeader.h" -#include "Swiften/Elements/StreamFeatures.h" -#include "Swiften/Elements/StreamError.h" -#include "Swiften/Elements/StartTLSRequest.h" -#include "Swiften/Elements/StartTLSFailure.h" -#include "Swiften/Elements/TLSProceed.h" -#include "Swiften/Elements/AuthRequest.h" -#include "Swiften/Elements/AuthSuccess.h" -#include "Swiften/Elements/AuthFailure.h" -#include "Swiften/Elements/AuthChallenge.h" -#include "Swiften/Elements/AuthResponse.h" -#include "Swiften/Elements/Compressed.h" -#include "Swiften/Elements/CompressFailure.h" -#include "Swiften/Elements/CompressRequest.h" -#include "Swiften/Elements/EnableStreamManagement.h" -#include "Swiften/Elements/StreamManagementEnabled.h" -#include "Swiften/Elements/StreamManagementFailed.h" -#include "Swiften/Elements/StartSession.h" -#include "Swiften/Elements/StanzaAck.h" -#include "Swiften/Elements/StanzaAckRequest.h" -#include "Swiften/Elements/IQ.h" -#include "Swiften/Elements/ResourceBind.h" -#include "Swiften/SASL/PLAINClientAuthenticator.h" -#include "Swiften/SASL/SCRAMSHA1ClientAuthenticator.h" -#include "Swiften/SASL/DIGESTMD5ClientAuthenticator.h" -#include "Swiften/Session/SessionStream.h" -#include "Swiften/TLS/CertificateTrustChecker.h" -#include "Swiften/TLS/ServerIdentityVerifier.h" +#include <Swiften/Elements/ProtocolHeader.h> +#include <Swiften/Elements/StreamFeatures.h> +#include <Swiften/Elements/StreamError.h> +#include <Swiften/Elements/StartTLSRequest.h> +#include <Swiften/Elements/StartTLSFailure.h> +#include <Swiften/Elements/TLSProceed.h> +#include <Swiften/Elements/AuthRequest.h> +#include <Swiften/Elements/AuthSuccess.h> +#include <Swiften/Elements/AuthFailure.h> +#include <Swiften/Elements/AuthChallenge.h> +#include <Swiften/Elements/AuthResponse.h> +#include <Swiften/Elements/Compressed.h> +#include <Swiften/Elements/CompressFailure.h> +#include <Swiften/Elements/CompressRequest.h> +#include <Swiften/Elements/EnableStreamManagement.h> +#include <Swiften/Elements/StreamManagementEnabled.h> +#include <Swiften/Elements/StreamManagementFailed.h> +#include <Swiften/Elements/StartSession.h> +#include <Swiften/Elements/StanzaAck.h> +#include <Swiften/Elements/StanzaAckRequest.h> +#include <Swiften/Elements/IQ.h> +#include <Swiften/Elements/ResourceBind.h> +#include <Swiften/SASL/PLAINClientAuthenticator.h> +#include <Swiften/SASL/SCRAMSHA1ClientAuthenticator.h> +#include <Swiften/SASL/DIGESTMD5ClientAuthenticator.h> +#include <Swiften/Session/SessionStream.h> +#include <Swiften/TLS/CertificateTrustChecker.h> +#include <Swiften/TLS/ServerIdentityVerifier.h> namespace Swift { @@ -54,6 +54,7 @@ ClientSession::ClientSession( needSessionStart(false), needResourceBind(false), needAcking(false), + rosterVersioningSupported(false), authenticator(NULL), certificateTrustChecker(NULL) { } @@ -223,6 +224,7 @@ void ClientSession::handleElement(boost::shared_ptr<Element> element) { } else { // Start the session + rosterVersioningSupported = streamFeatures->hasRosterVersioning(); stream->setWhitespacePingEnabled(true); needSessionStart = streamFeatures->hasSession(); needResourceBind = streamFeatures->hasResourceBind(); diff --git a/Swiften/Client/ClientSession.h b/Swiften/Client/ClientSession.h index 25ee694..9022b16 100644 --- a/Swiften/Client/ClientSession.h +++ b/Swiften/Client/ClientSession.h @@ -6,17 +6,17 @@ #pragma once -#include "Swiften/Base/boost_bsignals.h" +#include <Swiften/Base/boost_bsignals.h> #include <boost/shared_ptr.hpp> #include <boost/enable_shared_from_this.hpp> -#include "Swiften/Base/Error.h" -#include "Swiften/Session/SessionStream.h" +#include <Swiften/Base/Error.h> +#include <Swiften/Session/SessionStream.h> #include <string> -#include "Swiften/JID/JID.h" -#include "Swiften/Elements/Element.h" -#include "Swiften/StreamManagement/StanzaAckRequester.h" -#include "Swiften/StreamManagement/StanzaAckResponder.h" +#include <Swiften/JID/JID.h> +#include <Swiften/Elements/Element.h> +#include <Swiften/StreamManagement/StanzaAckRequester.h> +#include <Swiften/StreamManagement/StanzaAckResponder.h> namespace Swift { class ClientAuthenticator; @@ -89,6 +89,10 @@ namespace Swift { return stanzaAckRequester_; } + bool getRosterVersioningSupported() const { + return rosterVersioningSupported; + } + const JID& getLocalJID() const { return localJID; } @@ -153,6 +157,7 @@ namespace Swift { bool needSessionStart; bool needResourceBind; bool needAcking; + bool rosterVersioningSupported; ClientAuthenticator* authenticator; boost::shared_ptr<StanzaAckRequester> stanzaAckRequester_; boost::shared_ptr<StanzaAckResponder> stanzaAckResponder_; diff --git a/Swiften/Client/ClientSessionStanzaChannel.cpp b/Swiften/Client/ClientSessionStanzaChannel.cpp index 6b32b3d..5dc0a42 100644 --- a/Swiften/Client/ClientSessionStanzaChannel.cpp +++ b/Swiften/Client/ClientSessionStanzaChannel.cpp @@ -4,9 +4,10 @@ * See Documentation/Licenses/GPLv3.txt for more information. */ -#include "Swiften/Client/ClientSessionStanzaChannel.h" +#include <Swiften/Client/ClientSessionStanzaChannel.h> #include <boost/bind.hpp> +#include <iostream> namespace Swift { diff --git a/Swiften/Client/ClientSessionStanzaChannel.h b/Swiften/Client/ClientSessionStanzaChannel.h index 8a56301..47fb50e 100644 --- a/Swiften/Client/ClientSessionStanzaChannel.h +++ b/Swiften/Client/ClientSessionStanzaChannel.h @@ -8,12 +8,12 @@ #include <boost/shared_ptr.hpp> -#include "Swiften/Base/IDGenerator.h" -#include "Swiften/Client/ClientSession.h" -#include "Swiften/Client/StanzaChannel.h" -#include "Swiften/Elements/Message.h" -#include "Swiften/Elements/IQ.h" -#include "Swiften/Elements/Presence.h" +#include <Swiften/Base/IDGenerator.h> +#include <Swiften/Client/ClientSession.h> +#include <Swiften/Client/StanzaChannel.h> +#include <Swiften/Elements/Message.h> +#include <Swiften/Elements/IQ.h> +#include <Swiften/Elements/Presence.h> namespace Swift { /** diff --git a/Swiften/Client/ClientXMLTracer.cpp b/Swiften/Client/ClientXMLTracer.cpp new file mode 100644 index 0000000..a26ce66 --- /dev/null +++ b/Swiften/Client/ClientXMLTracer.cpp @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2010 Remko Tronçon + * Licensed under the GNU General Public License v3. + * See Documentation/Licenses/GPLv3.txt for more information. + */ + +#include <Swiften/Client/ClientXMLTracer.h> + +#include <iostream> +#include <boost/bind.hpp> + +namespace Swift { + +ClientXMLTracer::ClientXMLTracer(CoreClient* client) { + client->onDataRead.connect(boost::bind(&ClientXMLTracer::printData, '<', _1)); + client->onDataWritten.connect(boost::bind(&ClientXMLTracer::printData, '>', _1)); +} + +void ClientXMLTracer::printData(char direction, const std::string& data) { + printLine(direction); + std::cerr << data << std::endl; +} + +void ClientXMLTracer::printLine(char c) { + for (unsigned int i = 0; i < 80; ++i) { + std::cerr << c; + } + std::cerr << std::endl; +} + +} diff --git a/Swiften/Client/ClientXMLTracer.h b/Swiften/Client/ClientXMLTracer.h index bca2a54..617c53f 100644 --- a/Swiften/Client/ClientXMLTracer.h +++ b/Swiften/Client/ClientXMLTracer.h @@ -6,29 +6,15 @@ #pragma once -#include <boost/bind.hpp> - #include <Swiften/Client/CoreClient.h> namespace Swift { class ClientXMLTracer { public: - ClientXMLTracer(CoreClient* client) { - client->onDataRead.connect(boost::bind(&ClientXMLTracer::printData, '<', _1)); - client->onDataWritten.connect(boost::bind(&ClientXMLTracer::printData, '>', _1)); - } + ClientXMLTracer(CoreClient* client); private: - static void printData(char direction, const std::string& data) { - printLine(direction); - std::cerr << data << std::endl; - } - - static void printLine(char c) { - for (unsigned int i = 0; i < 80; ++i) { - std::cerr << c; - } - std::cerr << std::endl; - } + static void printData(char direction, const std::string& data); + static void printLine(char c); }; } diff --git a/Swiften/Client/CoreClient.cpp b/Swiften/Client/CoreClient.cpp index f0c5333..b7500e5 100644 --- a/Swiften/Client/CoreClient.cpp +++ b/Swiften/Client/CoreClient.cpp @@ -4,25 +4,30 @@ * See Documentation/Licenses/GPLv3.txt for more information. */ -#include "Swiften/Client/CoreClient.h" +#include <Swiften/Client/CoreClient.h> #include <boost/bind.hpp> - -#include "Swiften/Client/ClientSession.h" -#include "Swiften/TLS/PlatformTLSFactories.h" -#include "Swiften/TLS/CertificateVerificationError.h" -#include "Swiften/Network/Connector.h" -#include "Swiften/Network/NetworkFactories.h" -#include "Swiften/TLS/PKCS12Certificate.h" -#include "Swiften/Session/BasicSessionStream.h" -#include "Swiften/Queries/IQRouter.h" -#include "Swiften/Base/IDGenerator.h" -#include "Swiften/Client/ClientSessionStanzaChannel.h" +#include <boost/smart_ptr/make_shared.hpp> + +#include <Swiften/Client/ClientSession.h> +#include <Swiften/TLS/PlatformTLSFactories.h> +#include <Swiften/TLS/CertificateVerificationError.h> +#include <Swiften/Network/ChainedConnector.h> +#include <Swiften/Network/NetworkFactories.h> +#include <Swiften/TLS/PKCS12Certificate.h> +#include <Swiften/Session/BasicSessionStream.h> +#include <Swiften/Queries/IQRouter.h> +#include <Swiften/Base/IDGenerator.h> +#include <Swiften/Client/ClientSessionStanzaChannel.h> #include <Swiften/Base/Log.h> +#include <Swiften/Base/foreach.h> +#include <Swiften/Network/PlatformProxyProvider.h> +#include <Swiften/Network/SOCKS5ProxiedConnectionFactory.h> +#include <Swiften/Network/HTTPConnectProxiedConnectionFactory.h> namespace Swift { -CoreClient::CoreClient(const JID& jid, const std::string& password, NetworkFactories* networkFactories) : jid_(jid), password_(password), networkFactories(networkFactories), useStreamCompression(true), useTLS(UseTLSWhenAvailable), disconnectRequested_(false), certificateTrustChecker(NULL) { +CoreClient::CoreClient(const JID& jid, const std::string& password, NetworkFactories* networkFactories) : jid_(jid), password_(password), networkFactories(networkFactories), disconnectRequested_(false), certificateTrustChecker(NULL) { stanzaChannel_ = new ClientSessionStanzaChannel(); stanzaChannel_->onMessageReceived.connect(boost::bind(&CoreClient::handleMessageReceived, this, _1)); stanzaChannel_->onPresenceReceived.connect(boost::bind(&CoreClient::handlePresenceReceived, this, _1)); @@ -47,8 +52,9 @@ CoreClient::~CoreClient() { delete stanzaChannel_; } -void CoreClient::connect() { +void CoreClient::connect(const ClientOptions& o) { SWIFT_LOG(debug) << "Connecting" << std::endl; + options = o; connect(jid_.getDomain()); } @@ -56,7 +62,19 @@ void CoreClient::connect(const std::string& host) { SWIFT_LOG(debug) << "Connecting to host " << host << std::endl; disconnectRequested_ = false; assert(!connector_); - connector_ = Connector::create(host, networkFactories->getDomainNameResolver(), networkFactories->getConnectionFactory(), networkFactories->getTimerFactory()); + + assert(proxyConnectionFactories.empty()); + PlatformProxyProvider proxyProvider; + if(proxyProvider.getSOCKS5Proxy().isValid()) { + proxyConnectionFactories.push_back(new SOCKS5ProxiedConnectionFactory(networkFactories->getConnectionFactory(), proxyProvider.getSOCKS5Proxy())); + } + if(proxyProvider.getHTTPConnectProxy().isValid()) { + proxyConnectionFactories.push_back(new HTTPConnectProxiedConnectionFactory(networkFactories->getConnectionFactory(), proxyProvider.getHTTPConnectProxy())); + } + std::vector<ConnectionFactory*> connectionFactories(proxyConnectionFactories); + connectionFactories.push_back(networkFactories->getConnectionFactory()); + + connector_ = boost::make_shared<ChainedConnector>(host, networkFactories->getDomainNameResolver(), connectionFactories, networkFactories->getTimerFactory()); connector_->onConnectFinished.connect(boost::bind(&CoreClient::handleConnectorFinished, this, _1)); connector_->setTimeoutMilliseconds(60*1000); connector_->start(); @@ -65,6 +83,10 @@ void CoreClient::connect(const std::string& host) { void CoreClient::handleConnectorFinished(boost::shared_ptr<Connection> connection) { connector_->onConnectFinished.disconnect(boost::bind(&CoreClient::handleConnectorFinished, this, _1)); connector_.reset(); + foreach(ConnectionFactory* f, proxyConnectionFactories) { + delete f; + } + if (!connection) { onDisconnected(disconnectRequested_ ? boost::optional<ClientError>() : boost::optional<ClientError>(ClientError::ConnectionError)); } @@ -82,12 +104,12 @@ void CoreClient::handleConnectorFinished(boost::shared_ptr<Connection> connectio session_ = ClientSession::create(jid_, sessionStream_); session_->setCertificateTrustChecker(certificateTrustChecker); - session_->setUseStreamCompression(useStreamCompression); - switch(useTLS) { - case UseTLSWhenAvailable: + session_->setUseStreamCompression(options.useStreamCompression); + switch(options.useTLS) { + case ClientOptions::UseTLSWhenAvailable: session_->setUseTLS(ClientSession::UseTLSWhenAvailable); break; - case NeverUseTLS: + case ClientOptions::NeverUseTLS: session_->setUseTLS(ClientSession::NeverUseTLS); break; } @@ -275,13 +297,25 @@ void CoreClient::handleStanzaAcked(Stanza::ref stanza) { onStanzaAcked(stanza); } -void CoreClient::setUseStreamCompression(bool b) { - useStreamCompression = b; +bool CoreClient::isAvailable() const { + return stanzaChannel_->isAvailable(); } -void CoreClient::setUseTLS(UseTLS b) { - useTLS = b; +bool CoreClient::getStreamManagementEnabled() const { + return stanzaChannel_->getStreamManagementEnabled(); } +StanzaChannel* CoreClient::getStanzaChannel() const { + return stanzaChannel_; +} + +const JID& CoreClient::getJID() const { + if (session_) { + return session_->getLocalJID(); + } + else { + return jid_; + } +} } diff --git a/Swiften/Client/CoreClient.h b/Swiften/Client/CoreClient.h index eb9c42c..7c46fe7 100644 --- a/Swiften/Client/CoreClient.h +++ b/Swiften/Client/CoreClient.h @@ -6,35 +6,33 @@ #pragma once -#include "Swiften/Base/boost_bsignals.h" +#include <string> #include <boost/shared_ptr.hpp> +#include <Swiften/Base/boost_bsignals.h> -#include "Swiften/Network/PlatformDomainNameResolver.h" -#include "Swiften/Network/Connector.h" -#include "Swiften/Base/Error.h" -#include "Swiften/Client/ClientSession.h" -#include "Swiften/Client/ClientError.h" -#include "Swiften/Elements/Presence.h" -#include "Swiften/Elements/Message.h" -#include "Swiften/JID/JID.h" -#include <string> -#include "Swiften/Client/StanzaChannel.h" -#include "Swiften/Parser/PayloadParsers/FullPayloadParserFactoryCollection.h" -#include "Swiften/Serializer/PayloadSerializers/FullPayloadSerializerCollection.h" #include <Swiften/Entity/Entity.h> - -#include "Swiften/Client/ClientSessionStanzaChannel.h" +#include <Swiften/JID/JID.h> +#include <Swiften/Client/ClientError.h> +#include <Swiften/Client/ClientOptions.h> namespace Swift { + class ChainedConnector; + class Message; + class Presence; + class Error; class IQRouter; class TLSContextFactory; class ConnectionFactory; + class Connection; class TimerFactory; class ClientSession; + class StanzaChannel; + class Stanza; class BasicSessionStream; class PlatformTLSFactories; class CertificateTrustChecker; class NetworkFactories; + class ClientSessionStanzaChannel; /** * The central class for communicating with an XMPP server. @@ -48,11 +46,6 @@ namespace Swift { */ class CoreClient : public Entity { public: - enum UseTLS { - NeverUseTLS, - UseTLSWhenAvailable - }; - /** * Constructs a client for the given JID with the given password. * The given eventLoop will be used to post events to. @@ -68,7 +61,7 @@ namespace Swift { * After the connection is established, the client will set * initialize the stream and authenticate. */ - void connect(); + void connect(const ClientOptions& = ClientOptions()); /** * Disconnects the client from the server. @@ -80,12 +73,12 @@ namespace Swift { /** * Sends a message. */ - void sendMessage(Message::ref); + void sendMessage(boost::shared_ptr<Message>); /** * Sends a presence stanza. */ - void sendPresence(Presence::ref); + void sendPresence(boost::shared_ptr<Presence>); /** * Sends raw, unchecked data. @@ -103,9 +96,7 @@ namespace Swift { * Checks whether the client is connected to the server, * and stanzas can be sent. */ - bool isAvailable() const { - return stanzaChannel_->isAvailable(); - } + bool isAvailable() const; /** * Checks whether the client is active. @@ -118,14 +109,7 @@ namespace Swift { * Returns the JID of the client. * After the session was initialized, this returns the bound JID. */ - const JID& getJID() const { - if (session_) { - return session_->getLocalJID(); - } - else { - return jid_; - } - } + const JID& getJID() const; /** * Checks whether stream management is enabled. @@ -135,13 +119,9 @@ namespace Swift { * * \see onStanzaAcked */ - bool getStreamManagementEnabled() const { - return stanzaChannel_->getStreamManagementEnabled(); - } + bool getStreamManagementEnabled() const; - StanzaChannel* getStanzaChannel() const { - return stanzaChannel_; - } + StanzaChannel* getStanzaChannel() const; /** * Sets the certificate trust checker. @@ -153,16 +133,6 @@ namespace Swift { */ void setCertificateTrustChecker(CertificateTrustChecker*); - /** - * Sets whether ZLib stream compression should be used when available. - */ - void setUseStreamCompression(bool b); - - /** - * Sets whether TLS encryption should be used. - */ - void setUseTLS(UseTLS useTLS); - public: /** * Emitted when the client was disconnected from the network. @@ -197,12 +167,12 @@ namespace Swift { /** * Emitted when a message is received. */ - boost::signal<void (Message::ref)> onMessageReceived; + boost::signal<void (boost::shared_ptr<Message>)> onMessageReceived; /** * Emitted when a presence stanza is received. */ - boost::signal<void (Presence::ref) > onPresenceReceived; + boost::signal<void (boost::shared_ptr<Presence>) > onPresenceReceived; /** * Emitted when the server acknowledges receipt of a @@ -210,7 +180,12 @@ namespace Swift { * * \see getStreamManagementEnabled() */ - boost::signal<void (Stanza::ref)> onStanzaAcked; + boost::signal<void (boost::shared_ptr<Stanza>)> onStanzaAcked; + + protected: + boost::shared_ptr<ClientSession> getSession() const { + return session_; + } private: void handleConnectorFinished(boost::shared_ptr<Connection>); @@ -219,19 +194,19 @@ namespace Swift { void handleNeedCredentials(); void handleDataRead(const std::string&); void handleDataWritten(const std::string&); - void handlePresenceReceived(Presence::ref); - void handleMessageReceived(Message::ref); - void handleStanzaAcked(Stanza::ref); + void handlePresenceReceived(boost::shared_ptr<Presence>); + void handleMessageReceived(boost::shared_ptr<Message>); + void handleStanzaAcked(boost::shared_ptr<Stanza>); private: JID jid_; std::string password_; NetworkFactories* networkFactories; - bool useStreamCompression; - UseTLS useTLS; ClientSessionStanzaChannel* stanzaChannel_; IQRouter* iqRouter_; - Connector::ref connector_; + ClientOptions options; + boost::shared_ptr<ChainedConnector> connector_; + std::vector<ConnectionFactory*> proxyConnectionFactories; PlatformTLSFactories* tlsFactories; boost::shared_ptr<Connection> connection_; boost::shared_ptr<BasicSessionStream> sessionStream_; diff --git a/Swiften/Client/DummyStanzaChannel.h b/Swiften/Client/DummyStanzaChannel.h index b9f05c3..c2f3919 100644 --- a/Swiften/Client/DummyStanzaChannel.h +++ b/Swiften/Client/DummyStanzaChannel.h @@ -8,7 +8,7 @@ #include <vector> -#include "Swiften/Client/StanzaChannel.h" +#include <Swiften/Client/StanzaChannel.h> namespace Swift { class DummyStanzaChannel : public StanzaChannel { @@ -56,6 +56,22 @@ namespace Swift { return iqStanza && iqStanza->getType() == type && iqStanza->getTo() == jid && iqStanza->getPayload<T>(); } + bool isResultAtIndex(size_t index, const std::string& id) { + if (index >= sentStanzas.size()) { + return false; + } + boost::shared_ptr<IQ> iqStanza = boost::dynamic_pointer_cast<IQ>(sentStanzas[index]); + return iqStanza && iqStanza->getType() == IQ::Result && iqStanza->getID() == id; + } + + bool isErrorAtIndex(size_t index, const std::string& id) { + if (index >= sentStanzas.size()) { + return false; + } + boost::shared_ptr<IQ> iqStanza = boost::dynamic_pointer_cast<IQ>(sentStanzas[index]); + return iqStanza && iqStanza->getType() == IQ::Error && iqStanza->getID() == id; + } + template<typename T> boost::shared_ptr<T> getStanzaAtIndex(size_t index) { if (sentStanzas.size() <= index) { return boost::shared_ptr<T>(); diff --git a/Swiften/Client/MemoryStorages.cpp b/Swiften/Client/MemoryStorages.cpp index 5f6371b..fe171f7 100644 --- a/Swiften/Client/MemoryStorages.cpp +++ b/Swiften/Client/MemoryStorages.cpp @@ -4,10 +4,11 @@ * See Documentation/Licenses/GPLv3.txt for more information. */ -#include "Swiften/Client/MemoryStorages.h" -#include "Swiften/VCards/VCardMemoryStorage.h" -#include "Swiften/Avatars/AvatarMemoryStorage.h" -#include "Swiften/Disco/CapsMemoryStorage.h" +#include <Swiften/Client/MemoryStorages.h> +#include <Swiften/VCards/VCardMemoryStorage.h> +#include <Swiften/Avatars/AvatarMemoryStorage.h> +#include <Swiften/Disco/CapsMemoryStorage.h> +#include <Swiften/Roster/RosterMemoryStorage.h> namespace Swift { @@ -15,9 +16,11 @@ MemoryStorages::MemoryStorages() { vcardStorage = new VCardMemoryStorage(); capsStorage = new CapsMemoryStorage(); avatarStorage = new AvatarMemoryStorage(); + rosterStorage = new RosterMemoryStorage(); } MemoryStorages::~MemoryStorages() { + delete rosterStorage; delete avatarStorage; delete capsStorage; delete vcardStorage; @@ -35,4 +38,9 @@ AvatarStorage* MemoryStorages::getAvatarStorage() const { return avatarStorage; } +RosterStorage* MemoryStorages::getRosterStorage() const { + return rosterStorage; +} + + } diff --git a/Swiften/Client/MemoryStorages.h b/Swiften/Client/MemoryStorages.h index 67025cd..ca01a7a 100644 --- a/Swiften/Client/MemoryStorages.h +++ b/Swiften/Client/MemoryStorages.h @@ -6,7 +6,7 @@ #pragma once -#include "Swiften/Client/Storages.h" +#include <Swiften/Client/Storages.h> namespace Swift { class VCardMemoryStorage; @@ -23,10 +23,12 @@ namespace Swift { virtual VCardStorage* getVCardStorage() const; virtual AvatarStorage* getAvatarStorage() const; virtual CapsStorage* getCapsStorage() const; + virtual RosterStorage* getRosterStorage() const; private: VCardMemoryStorage* vcardStorage; AvatarStorage* avatarStorage; CapsStorage* capsStorage; + RosterStorage* rosterStorage; }; } diff --git a/Swiften/Client/NickResolver.cpp b/Swiften/Client/NickResolver.cpp index 6d5e742..e6f2e41 100644 --- a/Swiften/Client/NickResolver.cpp +++ b/Swiften/Client/NickResolver.cpp @@ -4,14 +4,14 @@ * See Documentation/Licenses/GPLv3.txt for more information. */ -#include "Swiften/Client/NickResolver.h" +#include <Swiften/Client/NickResolver.h> #include <boost/shared_ptr.hpp> #include <boost/bind.hpp> -#include "Swiften/MUC/MUCRegistry.h" -#include "Swiften/Roster/XMPPRoster.h" -#include "Swiften/VCards/VCardManager.h" +#include <Swiften/MUC/MUCRegistry.h> +#include <Swiften/Roster/XMPPRoster.h> +#include <Swiften/VCards/VCardManager.h> // FIXME: The NickResolver currently relies on the vcard being requested by the client on login. // The VCardManager should get an onConnected() signal (which is signalled when the stanzachannel is available(, and each time this is emitted, diff --git a/Swiften/Client/NickResolver.h b/Swiften/Client/NickResolver.h index 881362a..584f2ce 100644 --- a/Swiften/Client/NickResolver.h +++ b/Swiften/Client/NickResolver.h @@ -5,12 +5,12 @@ */ #include <map> -#include <boost/signals.hpp> #include <boost/shared_ptr.hpp> +#include <Swiften/Base/boost_bsignals.h> #include <string> -#include "Swiften/JID/JID.h" -#include "Swiften/Elements/VCard.h" +#include <Swiften/JID/JID.h> +#include <Swiften/Elements/VCard.h> namespace Swift { class XMPPRoster; diff --git a/Swiften/Client/StanzaChannel.h b/Swiften/Client/StanzaChannel.h index 4d6392c..f1d76e0 100644 --- a/Swiften/Client/StanzaChannel.h +++ b/Swiften/Client/StanzaChannel.h @@ -6,12 +6,12 @@ #pragma once -#include "Swiften/Base/boost_bsignals.h" +#include <Swiften/Base/boost_bsignals.h> #include <boost/shared_ptr.hpp> -#include "Swiften/Queries/IQChannel.h" -#include "Swiften/Elements/Message.h" -#include "Swiften/Elements/Presence.h" +#include <Swiften/Queries/IQChannel.h> +#include <Swiften/Elements/Message.h> +#include <Swiften/Elements/Presence.h> namespace Swift { class StanzaChannel : public IQChannel { diff --git a/Swiften/Client/Storages.cpp b/Swiften/Client/Storages.cpp new file mode 100644 index 0000000..3c2dbc5 --- /dev/null +++ b/Swiften/Client/Storages.cpp @@ -0,0 +1,12 @@ +/* + * Copyright (c) 2010 Remko Tronçon + * Licensed under the GNU General Public License v3. + * See Documentation/Licenses/GPLv3.txt for more information. + */ + +#include <Swiften/Client/Storages.h> + +using namespace Swift; + +Storages::~Storages() { +} diff --git a/Swiften/Client/Storages.h b/Swiften/Client/Storages.h index e62f0a9..1c5bbe9 100644 --- a/Swiften/Client/Storages.h +++ b/Swiften/Client/Storages.h @@ -10,6 +10,7 @@ namespace Swift { class VCardStorage; class AvatarStorage; class CapsStorage; + class RosterStorage; /** * An interface to hold storage classes for different @@ -17,10 +18,11 @@ namespace Swift { */ class Storages { public: - virtual ~Storages() {} + virtual ~Storages(); virtual VCardStorage* getVCardStorage() const = 0; virtual AvatarStorage* getAvatarStorage() const = 0; virtual CapsStorage* getCapsStorage() const = 0; + virtual RosterStorage* getRosterStorage() const = 0; }; } diff --git a/Swiften/Client/UnitTest/ClientSessionTest.cpp b/Swiften/Client/UnitTest/ClientSessionTest.cpp index 756287c..61223fb 100644 --- a/Swiften/Client/UnitTest/ClientSessionTest.cpp +++ b/Swiften/Client/UnitTest/ClientSessionTest.cpp @@ -11,23 +11,23 @@ #include <boost/optional.hpp> #include <boost/smart_ptr/make_shared.hpp> -#include "Swiften/Session/SessionStream.h" -#include "Swiften/Client/ClientSession.h" -#include "Swiften/Elements/StartTLSRequest.h" -#include "Swiften/Elements/StreamFeatures.h" -#include "Swiften/Elements/StreamError.h" -#include "Swiften/Elements/TLSProceed.h" -#include "Swiften/Elements/StartTLSFailure.h" -#include "Swiften/Elements/AuthRequest.h" -#include "Swiften/Elements/AuthSuccess.h" -#include "Swiften/Elements/AuthFailure.h" -#include "Swiften/Elements/StreamManagementEnabled.h" -#include "Swiften/Elements/StreamManagementFailed.h" -#include "Swiften/Elements/EnableStreamManagement.h" -#include "Swiften/Elements/IQ.h" -#include "Swiften/Elements/ResourceBind.h" -#include "Swiften/TLS/SimpleCertificate.h" -#include "Swiften/TLS/BlindCertificateTrustChecker.h" +#include <Swiften/Session/SessionStream.h> +#include <Swiften/Client/ClientSession.h> +#include <Swiften/Elements/StartTLSRequest.h> +#include <Swiften/Elements/StreamFeatures.h> +#include <Swiften/Elements/StreamError.h> +#include <Swiften/Elements/TLSProceed.h> +#include <Swiften/Elements/StartTLSFailure.h> +#include <Swiften/Elements/AuthRequest.h> +#include <Swiften/Elements/AuthSuccess.h> +#include <Swiften/Elements/AuthFailure.h> +#include <Swiften/Elements/StreamManagementEnabled.h> +#include <Swiften/Elements/StreamManagementFailed.h> +#include <Swiften/Elements/EnableStreamManagement.h> +#include <Swiften/Elements/IQ.h> +#include <Swiften/Elements/ResourceBind.h> +#include <Swiften/TLS/SimpleCertificate.h> +#include <Swiften/TLS/BlindCertificateTrustChecker.h> using namespace Swift; diff --git a/Swiften/Client/UnitTest/NickResolverTest.cpp b/Swiften/Client/UnitTest/NickResolverTest.cpp index bd778d4..dfc90fe 100644 --- a/Swiften/Client/UnitTest/NickResolverTest.cpp +++ b/Swiften/Client/UnitTest/NickResolverTest.cpp @@ -7,13 +7,13 @@ #include <cppunit/extensions/HelperMacros.h> #include <cppunit/extensions/TestFactoryRegistry.h> -#include "Swiften/Client/NickResolver.h" -#include "Swiften/MUC/MUCRegistry.h" -#include "Swiften/Roster/XMPPRosterImpl.h" -#include "Swiften/VCards/VCardManager.h" -#include "Swiften/VCards/VCardMemoryStorage.h" -#include "Swiften/Queries/IQRouter.h" -#include "Swiften/Client/DummyStanzaChannel.h" +#include <Swiften/Client/NickResolver.h> +#include <Swiften/MUC/MUCRegistry.h> +#include <Swiften/Roster/XMPPRosterImpl.h> +#include <Swiften/VCards/VCardManager.h> +#include <Swiften/VCards/VCardMemoryStorage.h> +#include <Swiften/Queries/IQRouter.h> +#include <Swiften/Client/DummyStanzaChannel.h> using namespace Swift; diff --git a/Swiften/Component/Component.cpp b/Swiften/Component/Component.cpp index fb4ba4c..af378a7 100644 --- a/Swiften/Component/Component.cpp +++ b/Swiften/Component/Component.cpp @@ -4,9 +4,9 @@ * See Documentation/Licenses/GPLv3.txt for more information. */ -#include "Swiften/Component/Component.h" +#include <Swiften/Component/Component.h> -#include "Swiften/Queries/Responders/SoftwareVersionResponder.h" +#include <Swiften/Queries/Responders/SoftwareVersionResponder.h> namespace Swift { diff --git a/Swiften/Component/Component.h b/Swiften/Component/Component.h index 0119db0..0b29ff7 100644 --- a/Swiften/Component/Component.h +++ b/Swiften/Component/Component.h @@ -6,7 +6,7 @@ #pragma once -#include "Swiften/Component/CoreComponent.h" +#include <Swiften/Component/CoreComponent.h> namespace Swift { class SoftwareVersionResponder; diff --git a/Swiften/Component/ComponentConnector.cpp b/Swiften/Component/ComponentConnector.cpp index 2af45f6..b7bdd34 100644 --- a/Swiften/Component/ComponentConnector.cpp +++ b/Swiften/Component/ComponentConnector.cpp @@ -4,15 +4,15 @@ * See Documentation/Licenses/GPLv3.txt for more information. */ -#include "Swiften/Component/ComponentConnector.h" +#include <Swiften/Component/ComponentConnector.h> #include <boost/bind.hpp> #include <iostream> -#include "Swiften/Network/ConnectionFactory.h" -#include "Swiften/Network/DomainNameResolver.h" -#include "Swiften/Network/DomainNameAddressQuery.h" -#include "Swiften/Network/TimerFactory.h" +#include <Swiften/Network/ConnectionFactory.h> +#include <Swiften/Network/DomainNameResolver.h> +#include <Swiften/Network/DomainNameAddressQuery.h> +#include <Swiften/Network/TimerFactory.h> namespace Swift { diff --git a/Swiften/Component/ComponentConnector.h b/Swiften/Component/ComponentConnector.h index c5e8f80..34451d7 100644 --- a/Swiften/Component/ComponentConnector.h +++ b/Swiften/Component/ComponentConnector.h @@ -7,14 +7,14 @@ #pragma once #include <deque> -#include "Swiften/Base/boost_bsignals.h" +#include <Swiften/Base/boost_bsignals.h> #include <boost/shared_ptr.hpp> -#include "Swiften/Network/Connection.h" -#include "Swiften/Network/Timer.h" -#include "Swiften/Network/HostAddressPort.h" +#include <Swiften/Network/Connection.h> +#include <Swiften/Network/Timer.h> +#include <Swiften/Network/HostAddressPort.h> #include <string> -#include "Swiften/Network/DomainNameResolveError.h" +#include <Swiften/Network/DomainNameResolveError.h> namespace Swift { class DomainNameAddressQuery; diff --git a/Swiften/Component/ComponentHandshakeGenerator.cpp b/Swiften/Component/ComponentHandshakeGenerator.cpp index 4081420..fce71ac 100644 --- a/Swiften/Component/ComponentHandshakeGenerator.cpp +++ b/Swiften/Component/ComponentHandshakeGenerator.cpp @@ -4,9 +4,9 @@ * See Documentation/Licenses/GPLv3.txt for more information. */ -#include "Swiften/Component/ComponentHandshakeGenerator.h" -#include "Swiften/StringCodecs/Hexify.h" -#include "Swiften/StringCodecs/SHA1.h" +#include <Swiften/Component/ComponentHandshakeGenerator.h> +#include <Swiften/StringCodecs/Hexify.h> +#include <Swiften/StringCodecs/SHA1.h> #include <Swiften/Base/String.h> namespace Swift { diff --git a/Swiften/Component/ComponentSession.cpp b/Swiften/Component/ComponentSession.cpp index 17e0dfd..af11146 100644 --- a/Swiften/Component/ComponentSession.cpp +++ b/Swiften/Component/ComponentSession.cpp @@ -4,14 +4,14 @@ * See Documentation/Licenses/GPLv3.txt for more information. */ -#include "Swiften/Component/ComponentSession.h" +#include <Swiften/Component/ComponentSession.h> #include <boost/bind.hpp> -#include "Swiften/Elements/ProtocolHeader.h" -#include "Swiften/Elements/ComponentHandshake.h" -#include "Swiften/Session/SessionStream.h" -#include "Swiften/Component/ComponentHandshakeGenerator.h" +#include <Swiften/Elements/ProtocolHeader.h> +#include <Swiften/Elements/ComponentHandshake.h> +#include <Swiften/Session/SessionStream.h> +#include <Swiften/Component/ComponentHandshakeGenerator.h> namespace Swift { diff --git a/Swiften/Component/ComponentSession.h b/Swiften/Component/ComponentSession.h index 168e618..647bad7 100644 --- a/Swiften/Component/ComponentSession.h +++ b/Swiften/Component/ComponentSession.h @@ -9,13 +9,13 @@ #include <boost/shared_ptr.hpp> #include <boost/enable_shared_from_this.hpp> -#include "Swiften/JID/JID.h" -#include "Swiften/Base/boost_bsignals.h" -#include "Swiften/Base/Error.h" +#include <Swiften/JID/JID.h> +#include <Swiften/Base/boost_bsignals.h> +#include <Swiften/Base/Error.h> #include <string> -#include "Swiften/Elements/Element.h" -#include "Swiften/Elements/Stanza.h" -#include "Swiften/Session/SessionStream.h" +#include <Swiften/Elements/Element.h> +#include <Swiften/Elements/Stanza.h> +#include <Swiften/Session/SessionStream.h> namespace Swift { class ComponentAuthenticator; diff --git a/Swiften/Component/ComponentSessionStanzaChannel.cpp b/Swiften/Component/ComponentSessionStanzaChannel.cpp index b9fecb2..3e96dce 100644 --- a/Swiften/Component/ComponentSessionStanzaChannel.cpp +++ b/Swiften/Component/ComponentSessionStanzaChannel.cpp @@ -4,9 +4,10 @@ * See Documentation/Licenses/GPLv3.txt for more information. */ -#include "Swiften/Component/ComponentSessionStanzaChannel.h" +#include <Swiften/Component/ComponentSessionStanzaChannel.h> #include <boost/bind.hpp> +#include <iostream> namespace Swift { diff --git a/Swiften/Component/ComponentSessionStanzaChannel.h b/Swiften/Component/ComponentSessionStanzaChannel.h index 605c8dc..45f90b5 100644 --- a/Swiften/Component/ComponentSessionStanzaChannel.h +++ b/Swiften/Component/ComponentSessionStanzaChannel.h @@ -8,12 +8,12 @@ #include <boost/shared_ptr.hpp> -#include "Swiften/Base/IDGenerator.h" -#include "Swiften/Component/ComponentSession.h" -#include "Swiften/Client/StanzaChannel.h" -#include "Swiften/Elements/Message.h" -#include "Swiften/Elements/IQ.h" -#include "Swiften/Elements/Presence.h" +#include <Swiften/Base/IDGenerator.h> +#include <Swiften/Component/ComponentSession.h> +#include <Swiften/Client/StanzaChannel.h> +#include <Swiften/Elements/Message.h> +#include <Swiften/Elements/IQ.h> +#include <Swiften/Elements/Presence.h> namespace Swift { /** diff --git a/Swiften/Component/ComponentXMLTracer.cpp b/Swiften/Component/ComponentXMLTracer.cpp new file mode 100644 index 0000000..b952c29 --- /dev/null +++ b/Swiften/Component/ComponentXMLTracer.cpp @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2010 Remko Tronçon + * Licensed under the GNU General Public License v3. + * See Documentation/Licenses/GPLv3.txt for more information. + */ + +#include <Swiften/Component/ComponentXMLTracer.h> + +#include <iostream> +#include <boost/bind.hpp> + +namespace Swift { + +ComponentXMLTracer::ComponentXMLTracer(CoreComponent* client) { + client->onDataRead.connect(boost::bind(&ComponentXMLTracer::printData, '<', _1)); + client->onDataWritten.connect(boost::bind(&ComponentXMLTracer::printData, '>', _1)); +} + +void ComponentXMLTracer::printData(char direction, const std::string& data) { + printLine(direction); + std::cerr << data << std::endl; +} + +void ComponentXMLTracer::printLine(char c) { + for (unsigned int i = 0; i < 80; ++i) { + std::cerr << c; + } + std::cerr << std::endl; +} + +} diff --git a/Swiften/Component/ComponentXMLTracer.h b/Swiften/Component/ComponentXMLTracer.h index 70a617b..2db690f 100644 --- a/Swiften/Component/ComponentXMLTracer.h +++ b/Swiften/Component/ComponentXMLTracer.h @@ -6,29 +6,15 @@ #pragma once -#include <boost/bind.hpp> - -#include "Swiften/Component/Component.h" +#include <Swiften/Component/Component.h> namespace Swift { class ComponentXMLTracer { public: - ComponentXMLTracer(Component* component) { - component->onDataRead.connect(boost::bind(&ComponentXMLTracer::printData, '<', _1)); - component->onDataWritten.connect(boost::bind(&ComponentXMLTracer::printData, '>', _1)); - } + ComponentXMLTracer(CoreComponent* component); private: - static void printData(char direction, const std::string& data) { - printLine(direction); - std::cerr << data << std::endl; - } - - static void printLine(char c) { - for (unsigned int i = 0; i < 80; ++i) { - std::cerr << c; - } - std::cerr << std::endl; - } + static void printData(char direction, const std::string& data); + static void printLine(char c); }; } diff --git a/Swiften/Component/CoreComponent.cpp b/Swiften/Component/CoreComponent.cpp index e79d735..7f02768 100644 --- a/Swiften/Component/CoreComponent.cpp +++ b/Swiften/Component/CoreComponent.cpp @@ -4,18 +4,19 @@ * See Documentation/Licenses/GPLv3.txt for more information. */ -#include "Swiften/Component/CoreComponent.h" +#include <Swiften/Component/CoreComponent.h> #include <boost/bind.hpp> - -#include "Swiften/Component/ComponentSession.h" -#include "Swiften/Network/Connector.h" -#include "Swiften/Network/NetworkFactories.h" -#include "Swiften/TLS/PKCS12Certificate.h" -#include "Swiften/Session/BasicSessionStream.h" -#include "Swiften/Queries/IQRouter.h" -#include "Swiften/Base/IDGenerator.h" -#include "Swiften/Component/ComponentSessionStanzaChannel.h" +#include <iostream> + +#include <Swiften/Component/ComponentSession.h> +#include <Swiften/Network/Connector.h> +#include <Swiften/Network/NetworkFactories.h> +#include <Swiften/TLS/PKCS12Certificate.h> +#include <Swiften/Session/BasicSessionStream.h> +#include <Swiften/Queries/IQRouter.h> +#include <Swiften/Base/IDGenerator.h> +#include <Swiften/Component/ComponentSessionStanzaChannel.h> namespace Swift { diff --git a/Swiften/Component/CoreComponent.h b/Swiften/Component/CoreComponent.h index 64c9071..26f0024 100644 --- a/Swiften/Component/CoreComponent.h +++ b/Swiften/Component/CoreComponent.h @@ -8,19 +8,19 @@ #include <boost/shared_ptr.hpp> -#include "Swiften/Base/boost_bsignals.h" -#include "Swiften/Base/Error.h" -#include "Swiften/Network/PlatformDomainNameResolver.h" -#include "Swiften/Component/ComponentConnector.h" -#include "Swiften/Component/ComponentSession.h" -#include "Swiften/Component/ComponentError.h" -#include "Swiften/Elements/Presence.h" -#include "Swiften/Elements/Message.h" -#include "Swiften/JID/JID.h" +#include <Swiften/Base/boost_bsignals.h> +#include <Swiften/Base/Error.h> +#include <Swiften/Network/PlatformDomainNameResolver.h> +#include <Swiften/Component/ComponentConnector.h> +#include <Swiften/Component/ComponentSession.h> +#include <Swiften/Component/ComponentError.h> +#include <Swiften/Elements/Presence.h> +#include <Swiften/Elements/Message.h> +#include <Swiften/JID/JID.h> #include <string> -#include "Swiften/Parser/PayloadParsers/FullPayloadParserFactoryCollection.h" -#include "Swiften/Serializer/PayloadSerializers/FullPayloadSerializerCollection.h" -#include "Swiften/Component/ComponentSessionStanzaChannel.h" +#include <Swiften/Parser/PayloadParsers/FullPayloadParserFactoryCollection.h> +#include <Swiften/Serializer/PayloadSerializers/FullPayloadSerializerCollection.h> +#include <Swiften/Component/ComponentSessionStanzaChannel.h> #include <Swiften/Entity/Entity.h> namespace Swift { diff --git a/Swiften/Component/SConscript b/Swiften/Component/SConscript index 0a9f250..ef5700c 100644 --- a/Swiften/Component/SConscript +++ b/Swiften/Component/SConscript @@ -7,6 +7,7 @@ sources = [ "ComponentSessionStanzaChannel.cpp", "CoreComponent.cpp", "Component.cpp", + "ComponentXMLTracer.cpp", ] swiften_env.Append(SWIFTEN_OBJECTS = swiften_env.SwiftenObject(sources)) diff --git a/Swiften/Component/UnitTest/ComponentConnectorTest.cpp b/Swiften/Component/UnitTest/ComponentConnectorTest.cpp index 052b5de..22b8016 100644 --- a/Swiften/Component/UnitTest/ComponentConnectorTest.cpp +++ b/Swiften/Component/UnitTest/ComponentConnectorTest.cpp @@ -10,13 +10,13 @@ #include <boost/optional.hpp> #include <boost/bind.hpp> -#include "Swiften/Component/ComponentConnector.h" -#include "Swiften/Network/Connection.h" -#include "Swiften/Network/ConnectionFactory.h" -#include "Swiften/Network/HostAddressPort.h" -#include "Swiften/Network/StaticDomainNameResolver.h" -#include "Swiften/Network/DummyTimerFactory.h" -#include "Swiften/EventLoop/DummyEventLoop.h" +#include <Swiften/Component/ComponentConnector.h> +#include <Swiften/Network/Connection.h> +#include <Swiften/Network/ConnectionFactory.h> +#include <Swiften/Network/HostAddressPort.h> +#include <Swiften/Network/StaticDomainNameResolver.h> +#include <Swiften/Network/DummyTimerFactory.h> +#include <Swiften/EventLoop/DummyEventLoop.h> using namespace Swift; diff --git a/Swiften/Component/UnitTest/ComponentHandshakeGeneratorTest.cpp b/Swiften/Component/UnitTest/ComponentHandshakeGeneratorTest.cpp index 5366478..fd8f6fc 100644 --- a/Swiften/Component/UnitTest/ComponentHandshakeGeneratorTest.cpp +++ b/Swiften/Component/UnitTest/ComponentHandshakeGeneratorTest.cpp @@ -7,7 +7,7 @@ #include <cppunit/extensions/HelperMacros.h> #include <cppunit/extensions/TestFactoryRegistry.h> -#include "Swiften/Component/ComponentHandshakeGenerator.h" +#include <Swiften/Component/ComponentHandshakeGenerator.h> using namespace Swift; diff --git a/Swiften/Component/UnitTest/ComponentSessionTest.cpp b/Swiften/Component/UnitTest/ComponentSessionTest.cpp index 953973c..c486d6d 100644 --- a/Swiften/Component/UnitTest/ComponentSessionTest.cpp +++ b/Swiften/Component/UnitTest/ComponentSessionTest.cpp @@ -10,10 +10,10 @@ #include <boost/bind.hpp> #include <boost/optional.hpp> -#include "Swiften/Session/SessionStream.h" -#include "Swiften/Component/ComponentSession.h" -#include "Swiften/Elements/ComponentHandshake.h" -#include "Swiften/Elements/AuthFailure.h" +#include <Swiften/Session/SessionStream.h> +#include <Swiften/Component/ComponentSession.h> +#include <Swiften/Elements/ComponentHandshake.h> +#include <Swiften/Elements/AuthFailure.h> using namespace Swift; diff --git a/Swiften/Compress/UnitTest/ZLibCompressorTest.cpp b/Swiften/Compress/UnitTest/ZLibCompressorTest.cpp index 0b2fa5a..8b3a48b 100644 --- a/Swiften/Compress/UnitTest/ZLibCompressorTest.cpp +++ b/Swiften/Compress/UnitTest/ZLibCompressorTest.cpp @@ -4,12 +4,12 @@ * See Documentation/Licenses/GPLv3.txt for more information. */ -#include "Swiften/Base/ByteArray.h" +#include <Swiften/Base/ByteArray.h> #include <cppunit/extensions/HelperMacros.h> #include <cppunit/extensions/TestFactoryRegistry.h> -#include "Swiften/Compress/ZLibCompressor.h" +#include <Swiften/Compress/ZLibCompressor.h> using namespace Swift; diff --git a/Swiften/Compress/UnitTest/ZLibDecompressorTest.cpp b/Swiften/Compress/UnitTest/ZLibDecompressorTest.cpp index 3ee5c4f..7a26d50 100644 --- a/Swiften/Compress/UnitTest/ZLibDecompressorTest.cpp +++ b/Swiften/Compress/UnitTest/ZLibDecompressorTest.cpp @@ -4,14 +4,14 @@ * See Documentation/Licenses/GPLv3.txt for more information. */ -#include "Swiften/Base/ByteArray.h" +#include <Swiften/Base/ByteArray.h> #include <cppunit/extensions/HelperMacros.h> #include <cppunit/extensions/TestFactoryRegistry.h> -#include "Swiften/Compress/ZLibDecompressor.h" -#include "Swiften/Compress/ZLibCompressor.h" -#include "Swiften/Compress/ZLibException.h" +#include <Swiften/Compress/ZLibDecompressor.h> +#include <Swiften/Compress/ZLibCompressor.h> +#include <Swiften/Compress/ZLibException.h> using namespace Swift; diff --git a/Swiften/Compress/ZLibCodecompressor.cpp b/Swiften/Compress/ZLibCodecompressor.cpp index c093fb3..1fb3a94 100644 --- a/Swiften/Compress/ZLibCodecompressor.cpp +++ b/Swiften/Compress/ZLibCodecompressor.cpp @@ -4,11 +4,11 @@ * See Documentation/Licenses/GPLv3.txt for more information. */ -#include "Swiften/Compress/ZLibCodecompressor.h" +#include <Swiften/Compress/ZLibCodecompressor.h> #include <cassert> -#include "Swiften/Compress/ZLibException.h" +#include <Swiften/Compress/ZLibException.h> namespace Swift { diff --git a/Swiften/Compress/ZLibCodecompressor.h b/Swiften/Compress/ZLibCodecompressor.h index 289704d..959ecbf 100644 --- a/Swiften/Compress/ZLibCodecompressor.h +++ b/Swiften/Compress/ZLibCodecompressor.h @@ -9,7 +9,7 @@ #include <zlib.h> -#include "Swiften/Base/ByteArray.h" +#include <Swiften/Base/ByteArray.h> namespace Swift { class ZLibCodecompressor { diff --git a/Swiften/Compress/ZLibCompressor.cpp b/Swiften/Compress/ZLibCompressor.cpp index 7e3116e..5d98e38 100644 --- a/Swiften/Compress/ZLibCompressor.cpp +++ b/Swiften/Compress/ZLibCompressor.cpp @@ -4,7 +4,9 @@ * See Documentation/Licenses/GPLv3.txt for more information. */ -#include "Swiften/Compress/ZLibCompressor.h" +#include <Swiften/Compress/ZLibCompressor.h> + +#include <cassert> #pragma GCC diagnostic ignored "-Wold-style-cast" diff --git a/Swiften/Compress/ZLibCompressor.h b/Swiften/Compress/ZLibCompressor.h index 7fe5387..1add725 100644 --- a/Swiften/Compress/ZLibCompressor.h +++ b/Swiften/Compress/ZLibCompressor.h @@ -6,10 +6,8 @@ #pragma once -#include <cassert> - -#include "Swiften/Compress/ZLibCodecompressor.h" -#include "Swiften/Base/ByteArray.h" +#include <Swiften/Compress/ZLibCodecompressor.h> +#include <Swiften/Base/ByteArray.h> namespace Swift { class ZLibCompressor : public ZLibCodecompressor { diff --git a/Swiften/Compress/ZLibDecompressor.cpp b/Swiften/Compress/ZLibDecompressor.cpp index af7349b..ab954f4 100644 --- a/Swiften/Compress/ZLibDecompressor.cpp +++ b/Swiften/Compress/ZLibDecompressor.cpp @@ -4,7 +4,9 @@ * See Documentation/Licenses/GPLv3.txt for more information. */ -#include "Swiften/Compress/ZLibDecompressor.h" +#include <Swiften/Compress/ZLibDecompressor.h> + +#include <cassert> #pragma GCC diagnostic ignored "-Wold-style-cast" diff --git a/Swiften/Compress/ZLibDecompressor.h b/Swiften/Compress/ZLibDecompressor.h index ec08a4f..67994d1 100644 --- a/Swiften/Compress/ZLibDecompressor.h +++ b/Swiften/Compress/ZLibDecompressor.h @@ -6,10 +6,8 @@ #pragma once -#include <cassert> - -#include "Swiften/Compress/ZLibCodecompressor.h" -#include "Swiften/Base/ByteArray.h" +#include <Swiften/Compress/ZLibCodecompressor.h> +#include <Swiften/Base/ByteArray.h> namespace Swift { class ZLibDecompressor : public ZLibCodecompressor { diff --git a/Swiften/Config/swiften-config.cpp b/Swiften/Config/swiften-config.cpp index b3875cb..0c46cf0 100644 --- a/Swiften/Config/swiften-config.cpp +++ b/Swiften/Config/swiften-config.cpp @@ -11,6 +11,7 @@ #include <boost/program_options/variables_map.hpp> #include <boost/program_options.hpp> #include <boost/version.hpp> +#include <boost/filesystem.hpp> #include <string> #include <Swiften/Base/Platform.h> diff --git a/Swiften/Disco/CapsFileStorage.cpp b/Swiften/Disco/CapsFileStorage.cpp deleted file mode 100644 index 1e53854..0000000 --- a/Swiften/Disco/CapsFileStorage.cpp +++ /dev/null @@ -1,61 +0,0 @@ -/* - * Copyright (c) 2010 Remko Tronçon - * Licensed under the GNU General Public License v3. - * See Documentation/Licenses/GPLv3.txt for more information. - */ - -#include "Swiften/Disco/CapsFileStorage.h" - -#include <iostream> -#include <boost/filesystem/fstream.hpp> - -#include "Swiften/Base/ByteArray.h" -#include "Swiften/Serializer/PayloadSerializers/DiscoInfoSerializer.h" -#include "Swiften/Parser/PayloadParsers/UnitTest/PayloadParserTester.h" -#include "Swiften/Parser/PayloadParsers/DiscoInfoParser.h" -#include "Swiften/StringCodecs/Hexify.h" -#include "Swiften/StringCodecs/Base64.h" - -namespace Swift { - -CapsFileStorage::CapsFileStorage(const boost::filesystem::path& path) : path(path) { -} - -DiscoInfo::ref CapsFileStorage::getDiscoInfo(const std::string& hash) const { - boost::filesystem::path capsPath(getCapsPath(hash)); - if (boost::filesystem::exists(capsPath)) { - ByteArray data; - data.readFromFile(capsPath.string()); - - DiscoInfoParser parser; - PayloadParserTester tester(&parser); - tester.parse(data.toString()); - return boost::dynamic_pointer_cast<DiscoInfo>(parser.getPayload()); - } - else { - return DiscoInfo::ref(); - } -} - -void CapsFileStorage::setDiscoInfo(const std::string& hash, DiscoInfo::ref discoInfo) { - boost::filesystem::path capsPath(getCapsPath(hash)); - if (!boost::filesystem::exists(capsPath.parent_path())) { - try { - boost::filesystem::create_directories(capsPath.parent_path()); - } - catch (const boost::filesystem::filesystem_error& e) { - std::cerr << "ERROR: " << e.what() << std::endl; - } - } - DiscoInfo::ref bareDiscoInfo(new DiscoInfo(*discoInfo.get())); - bareDiscoInfo->setNode(""); - boost::filesystem::ofstream file(capsPath); - file << DiscoInfoSerializer().serializePayload(bareDiscoInfo); - file.close(); -} - -boost::filesystem::path CapsFileStorage::getCapsPath(const std::string& hash) const { - return path / (Hexify::hexify(Base64::decode(hash)) + ".xml"); -} - -} diff --git a/Swiften/Disco/CapsInfoGenerator.cpp b/Swiften/Disco/CapsInfoGenerator.cpp index 5c0e9a7..7992a06 100644 --- a/Swiften/Disco/CapsInfoGenerator.cpp +++ b/Swiften/Disco/CapsInfoGenerator.cpp @@ -4,15 +4,15 @@ * See Documentation/Licenses/GPLv3.txt for more information. */ -#include "Swiften/Disco/CapsInfoGenerator.h" +#include <Swiften/Disco/CapsInfoGenerator.h> #include <algorithm> -#include "Swiften/Base/foreach.h" -#include "Swiften/Elements/DiscoInfo.h" -#include "Swiften/Elements/FormField.h" -#include "Swiften/StringCodecs/SHA1.h" -#include "Swiften/StringCodecs/Base64.h" +#include <Swiften/Base/foreach.h> +#include <Swiften/Elements/DiscoInfo.h> +#include <Swiften/Elements/FormField.h> +#include <Swiften/StringCodecs/SHA1.h> +#include <Swiften/StringCodecs/Base64.h> namespace { bool compareFields(Swift::FormField::ref f1, Swift::FormField::ref f2) { diff --git a/Swiften/Disco/CapsInfoGenerator.h b/Swiften/Disco/CapsInfoGenerator.h index 41a1d94..d1b2663 100644 --- a/Swiften/Disco/CapsInfoGenerator.h +++ b/Swiften/Disco/CapsInfoGenerator.h @@ -7,7 +7,7 @@ #pragma once #include <string> -#include "Swiften/Elements/CapsInfo.h" +#include <Swiften/Elements/CapsInfo.h> namespace Swift { class DiscoInfo; diff --git a/Swiften/Disco/CapsManager.cpp b/Swiften/Disco/CapsManager.cpp index 63166e6..a24d88d 100644 --- a/Swiften/Disco/CapsManager.cpp +++ b/Swiften/Disco/CapsManager.cpp @@ -4,15 +4,16 @@ * See Documentation/Licenses/GPLv3.txt for more information. */ -#include "Swiften/Disco/CapsManager.h" +#include <Swiften/Disco/CapsManager.h> #include <boost/bind.hpp> +#include <iostream> -#include "Swiften/Client/StanzaChannel.h" -#include "Swiften/Disco/CapsStorage.h" -#include "Swiften/Disco/CapsInfoGenerator.h" -#include "Swiften/Elements/CapsInfo.h" -#include "Swiften/Disco/GetDiscoInfoRequest.h" +#include <Swiften/Client/StanzaChannel.h> +#include <Swiften/Disco/CapsStorage.h> +#include <Swiften/Disco/CapsInfoGenerator.h> +#include <Swiften/Elements/CapsInfo.h> +#include <Swiften/Disco/GetDiscoInfoRequest.h> namespace Swift { diff --git a/Swiften/Disco/CapsManager.h b/Swiften/Disco/CapsManager.h index 961dae8..ddc7997 100644 --- a/Swiften/Disco/CapsManager.h +++ b/Swiften/Disco/CapsManager.h @@ -9,12 +9,12 @@ #include <set> #include <map> -#include "Swiften/Base/boost_bsignals.h" -#include "Swiften/Elements/Presence.h" -#include "Swiften/Elements/DiscoInfo.h" -#include "Swiften/Elements/CapsInfo.h" -#include "Swiften/Elements/ErrorPayload.h" -#include "Swiften/Disco/CapsProvider.h" +#include <Swiften/Base/boost_bsignals.h> +#include <Swiften/Elements/Presence.h> +#include <Swiften/Elements/DiscoInfo.h> +#include <Swiften/Elements/CapsInfo.h> +#include <Swiften/Elements/ErrorPayload.h> +#include <Swiften/Disco/CapsProvider.h> namespace Swift { class StanzaChannel; diff --git a/Swiften/Disco/CapsMemoryStorage.h b/Swiften/Disco/CapsMemoryStorage.h index 1e2d7be..2503d7d 100644 --- a/Swiften/Disco/CapsMemoryStorage.h +++ b/Swiften/Disco/CapsMemoryStorage.h @@ -10,7 +10,7 @@ #include <map> #include <string> -#include "Swiften/Disco/CapsStorage.h" +#include <Swiften/Disco/CapsStorage.h> namespace Swift { class CapsMemoryStorage : public CapsStorage { diff --git a/Swiften/Disco/CapsProvider.h b/Swiften/Disco/CapsProvider.h index 71e2741..8bb3767 100644 --- a/Swiften/Disco/CapsProvider.h +++ b/Swiften/Disco/CapsProvider.h @@ -6,9 +6,9 @@ #pragma once -#include "Swiften/Base/boost_bsignals.h" -#include "Swiften/Elements/DiscoInfo.h" -#include "Swiften/Elements/CapsInfo.h" +#include <Swiften/Base/boost_bsignals.h> +#include <Swiften/Elements/DiscoInfo.h> +#include <Swiften/Elements/CapsInfo.h> namespace Swift { diff --git a/Swiften/Disco/CapsStorage.cpp b/Swiften/Disco/CapsStorage.cpp index acb58fe..fe4a6ac 100644 --- a/Swiften/Disco/CapsStorage.cpp +++ b/Swiften/Disco/CapsStorage.cpp @@ -4,7 +4,7 @@ * See Documentation/Licenses/GPLv3.txt for more information. */ -#include "Swiften/Disco/CapsStorage.h" +#include <Swiften/Disco/CapsStorage.h> namespace Swift { diff --git a/Swiften/Disco/CapsStorage.h b/Swiften/Disco/CapsStorage.h index f0a71a3..fb6e442 100644 --- a/Swiften/Disco/CapsStorage.h +++ b/Swiften/Disco/CapsStorage.h @@ -8,7 +8,7 @@ #include <boost/shared_ptr.hpp> -#include "Swiften/Elements/DiscoInfo.h" +#include <Swiften/Elements/DiscoInfo.h> namespace Swift { diff --git a/Swiften/Disco/ClientDiscoManager.cpp b/Swiften/Disco/ClientDiscoManager.cpp index fb7cce9..99c0175 100644 --- a/Swiften/Disco/ClientDiscoManager.cpp +++ b/Swiften/Disco/ClientDiscoManager.cpp @@ -4,11 +4,11 @@ * See Documentation/Licenses/GPLv3.txt for more information. */ -#include "Swiften/Disco/ClientDiscoManager.h" +#include <Swiften/Disco/ClientDiscoManager.h> -#include "Swiften/Disco/DiscoInfoResponder.h" -#include "Swiften/Disco/CapsInfoGenerator.h" -#include "Swiften/Presence/PayloadAddingPresenceSender.h" +#include <Swiften/Disco/DiscoInfoResponder.h> +#include <Swiften/Disco/CapsInfoGenerator.h> +#include <Swiften/Presence/PayloadAddingPresenceSender.h> namespace Swift { diff --git a/Swiften/Disco/ClientDiscoManager.h b/Swiften/Disco/ClientDiscoManager.h index 3771044..f8ba9ac 100644 --- a/Swiften/Disco/ClientDiscoManager.h +++ b/Swiften/Disco/ClientDiscoManager.h @@ -6,9 +6,9 @@ #pragma once -#include "Swiften/Elements/CapsInfo.h" -#include "Swiften/Elements/DiscoInfo.h" -#include "Swiften/Presence/PayloadAddingPresenceSender.h" +#include <Swiften/Elements/CapsInfo.h> +#include <Swiften/Elements/DiscoInfo.h> +#include <Swiften/Presence/PayloadAddingPresenceSender.h> namespace Swift { class IQRouter; diff --git a/Swiften/Disco/DiscoInfoResponder.cpp b/Swiften/Disco/DiscoInfoResponder.cpp index 7ba044e..a8dd9f0 100644 --- a/Swiften/Disco/DiscoInfoResponder.cpp +++ b/Swiften/Disco/DiscoInfoResponder.cpp @@ -4,9 +4,9 @@ * See Documentation/Licenses/GPLv3.txt for more information. */ -#include "Swiften/Disco/DiscoInfoResponder.h" -#include "Swiften/Queries/IQRouter.h" -#include "Swiften/Elements/DiscoInfo.h" +#include <Swiften/Disco/DiscoInfoResponder.h> +#include <Swiften/Queries/IQRouter.h> +#include <Swiften/Elements/DiscoInfo.h> namespace Swift { diff --git a/Swiften/Disco/DiscoInfoResponder.h b/Swiften/Disco/DiscoInfoResponder.h index f114a21..af9f48f 100644 --- a/Swiften/Disco/DiscoInfoResponder.h +++ b/Swiften/Disco/DiscoInfoResponder.h @@ -8,8 +8,8 @@ #include <map> -#include "Swiften/Queries/GetResponder.h" -#include "Swiften/Elements/DiscoInfo.h" +#include <Swiften/Queries/GetResponder.h> +#include <Swiften/Elements/DiscoInfo.h> namespace Swift { class IQRouter; diff --git a/Swiften/Disco/DummyEntityCapsProvider.cpp b/Swiften/Disco/DummyEntityCapsProvider.cpp new file mode 100644 index 0000000..a906652 --- /dev/null +++ b/Swiften/Disco/DummyEntityCapsProvider.cpp @@ -0,0 +1,21 @@ +/* + * Copyright (c) 2010 Remko Tronçon + * Licensed under the GNU General Public License v3. + * See Documentation/Licenses/GPLv3.txt for more information. + */ + +#include <Swiften/Disco/DummyEntityCapsProvider.h> + +#include <iostream> + +namespace Swift { + +DiscoInfo::ref DummyEntityCapsProvider::getCaps(const JID& jid) const { + std::map<JID, DiscoInfo::ref>::const_iterator i = caps.find(jid); + if (i != caps.end()) { + return i->second; + } + return DiscoInfo::ref(); +} + +} diff --git a/Swiften/Disco/DummyEntityCapsProvider.h b/Swiften/Disco/DummyEntityCapsProvider.h index 68cef2f..a1e3db6 100644 --- a/Swiften/Disco/DummyEntityCapsProvider.h +++ b/Swiften/Disco/DummyEntityCapsProvider.h @@ -7,8 +7,8 @@ #pragma once #include <map> -#include <iostream> -#include "Swiften/Disco/EntityCapsProvider.h" + +#include <Swiften/Disco/EntityCapsProvider.h> namespace Swift { class DummyEntityCapsProvider : public EntityCapsProvider { @@ -16,13 +16,7 @@ namespace Swift { DummyEntityCapsProvider() { } - DiscoInfo::ref getCaps(const JID& jid) const { - std::map<JID, DiscoInfo::ref>::const_iterator i = caps.find(jid); - if (i != caps.end()) { - return i->second; - } - return DiscoInfo::ref(); - } + DiscoInfo::ref getCaps(const JID& jid) const; std::map<JID, DiscoInfo::ref> caps; }; diff --git a/Swiften/Disco/EntityCapsManager.cpp b/Swiften/Disco/EntityCapsManager.cpp index 3f2e3d7..1a9f5fb 100644 --- a/Swiften/Disco/EntityCapsManager.cpp +++ b/Swiften/Disco/EntityCapsManager.cpp @@ -4,12 +4,12 @@ * See Documentation/Licenses/GPLv3.txt for more information. */ -#include "Swiften/Disco/EntityCapsManager.h" +#include <Swiften/Disco/EntityCapsManager.h> #include <boost/bind.hpp> -#include "Swiften/Disco/CapsProvider.h" -#include "Swiften/Client/StanzaChannel.h" +#include <Swiften/Disco/CapsProvider.h> +#include <Swiften/Client/StanzaChannel.h> namespace Swift { diff --git a/Swiften/Disco/EntityCapsManager.h b/Swiften/Disco/EntityCapsManager.h index 190f876..e41c15f 100644 --- a/Swiften/Disco/EntityCapsManager.h +++ b/Swiften/Disco/EntityCapsManager.h @@ -8,11 +8,11 @@ #include <map> -#include "Swiften/Base/boost_bsignals.h" -#include "Swiften/Elements/Presence.h" -#include "Swiften/Elements/DiscoInfo.h" -#include "Swiften/Elements/ErrorPayload.h" -#include "Swiften/Disco/EntityCapsProvider.h" +#include <Swiften/Base/boost_bsignals.h> +#include <Swiften/Elements/Presence.h> +#include <Swiften/Elements/DiscoInfo.h> +#include <Swiften/Elements/ErrorPayload.h> +#include <Swiften/Disco/EntityCapsProvider.h> namespace Swift { class StanzaChannel; diff --git a/Swiften/Disco/EntityCapsProvider.cpp b/Swiften/Disco/EntityCapsProvider.cpp index a337328..e3262b6 100644 --- a/Swiften/Disco/EntityCapsProvider.cpp +++ b/Swiften/Disco/EntityCapsProvider.cpp @@ -4,7 +4,7 @@ * See Documentation/Licenses/GPLv3.txt for more information. */ -#include "Swiften/Disco/EntityCapsProvider.h" +#include <Swiften/Disco/EntityCapsProvider.h> namespace Swift { diff --git a/Swiften/Disco/EntityCapsProvider.h b/Swiften/Disco/EntityCapsProvider.h index 07fa452..b38992c 100644 --- a/Swiften/Disco/EntityCapsProvider.h +++ b/Swiften/Disco/EntityCapsProvider.h @@ -6,9 +6,9 @@ #pragma once -#include "Swiften/Base/boost_bsignals.h" -#include "Swiften/JID/JID.h" -#include "Swiften/Elements/DiscoInfo.h" +#include <Swiften/Base/boost_bsignals.h> +#include <Swiften/JID/JID.h> +#include <Swiften/Elements/DiscoInfo.h> namespace Swift { /** diff --git a/Swiften/Disco/GetDiscoInfoRequest.h b/Swiften/Disco/GetDiscoInfoRequest.h index 5cec530..e211632 100644 --- a/Swiften/Disco/GetDiscoInfoRequest.h +++ b/Swiften/Disco/GetDiscoInfoRequest.h @@ -6,8 +6,8 @@ #pragma once -#include "Swiften/Queries/GenericRequest.h" -#include "Swiften/Elements/DiscoInfo.h" +#include <Swiften/Queries/GenericRequest.h> +#include <Swiften/Elements/DiscoInfo.h> namespace Swift { class GetDiscoInfoRequest : public GenericRequest<DiscoInfo> { diff --git a/Swiften/Disco/GetDiscoItemsRequest.h b/Swiften/Disco/GetDiscoItemsRequest.h index 0a94402..20d18f8 100644 --- a/Swiften/Disco/GetDiscoItemsRequest.h +++ b/Swiften/Disco/GetDiscoItemsRequest.h @@ -6,8 +6,8 @@ #pragma once -#include "Swiften/Queries/GenericRequest.h" -#include "Swiften/Elements/DiscoItems.h" +#include <Swiften/Queries/GenericRequest.h> +#include <Swiften/Elements/DiscoItems.h> namespace Swift { class GetDiscoItemsRequest : public GenericRequest<DiscoItems> { @@ -18,9 +18,18 @@ namespace Swift { return ref(new GetDiscoItemsRequest(jid, router)); } + static ref create(const JID& jid, const std::string& node, IQRouter* router) { + return ref(new GetDiscoItemsRequest(jid, node, router)); + } + private: GetDiscoItemsRequest(const JID& jid, IQRouter* router) : GenericRequest<DiscoItems>(IQ::Get, jid, boost::shared_ptr<DiscoItems>(new DiscoItems()), router) { } + + GetDiscoItemsRequest(const JID& jid, const std::string& node, IQRouter* router) : + GenericRequest<DiscoItems>(IQ::Get, jid, boost::shared_ptr<DiscoItems>(new DiscoItems()), router) { + getPayloadGeneric()->setNode(node); + } }; } diff --git a/Swiften/Disco/JIDDiscoInfoResponder.cpp b/Swiften/Disco/JIDDiscoInfoResponder.cpp index 1298e5a..0a25bef 100644 --- a/Swiften/Disco/JIDDiscoInfoResponder.cpp +++ b/Swiften/Disco/JIDDiscoInfoResponder.cpp @@ -4,9 +4,9 @@ * See Documentation/Licenses/GPLv3.txt for more information. */ -#include "Swiften/Disco/JIDDiscoInfoResponder.h" -#include "Swiften/Queries/IQRouter.h" -#include "Swiften/Elements/DiscoInfo.h" +#include <Swiften/Disco/JIDDiscoInfoResponder.h> +#include <Swiften/Queries/IQRouter.h> +#include <Swiften/Elements/DiscoInfo.h> namespace Swift { diff --git a/Swiften/Disco/JIDDiscoInfoResponder.h b/Swiften/Disco/JIDDiscoInfoResponder.h index d532d0f..ebc1452 100644 --- a/Swiften/Disco/JIDDiscoInfoResponder.h +++ b/Swiften/Disco/JIDDiscoInfoResponder.h @@ -8,9 +8,9 @@ #include <map> -#include "Swiften/Queries/GetResponder.h" -#include "Swiften/Elements/DiscoInfo.h" -#include "Swiften/JID/JID.h" +#include <Swiften/Queries/GetResponder.h> +#include <Swiften/Elements/DiscoInfo.h> +#include <Swiften/JID/JID.h> namespace Swift { class IQRouter; diff --git a/Swiften/Disco/SConscript b/Swiften/Disco/SConscript index 9982192..434018a 100644 --- a/Swiften/Disco/SConscript +++ b/Swiften/Disco/SConscript @@ -5,8 +5,8 @@ objects = swiften_env.SwiftenObject([ "CapsManager.cpp", "EntityCapsManager.cpp", "EntityCapsProvider.cpp", + "DummyEntityCapsProvider.cpp", "CapsStorage.cpp", - "CapsFileStorage.cpp", "ClientDiscoManager.cpp", "DiscoInfoResponder.cpp", "JIDDiscoInfoResponder.cpp", diff --git a/Swiften/Disco/UnitTest/CapsInfoGeneratorTest.cpp b/Swiften/Disco/UnitTest/CapsInfoGeneratorTest.cpp index d4cb331..52fdbaa 100644 --- a/Swiften/Disco/UnitTest/CapsInfoGeneratorTest.cpp +++ b/Swiften/Disco/UnitTest/CapsInfoGeneratorTest.cpp @@ -7,8 +7,8 @@ #include <cppunit/extensions/HelperMacros.h> #include <cppunit/extensions/TestFactoryRegistry.h> -#include "Swiften/Elements/DiscoInfo.h" -#include "Swiften/Disco/CapsInfoGenerator.h" +#include <Swiften/Elements/DiscoInfo.h> +#include <Swiften/Disco/CapsInfoGenerator.h> using namespace Swift; diff --git a/Swiften/Disco/UnitTest/CapsManagerTest.cpp b/Swiften/Disco/UnitTest/CapsManagerTest.cpp index d5b9896..c1d6312 100644 --- a/Swiften/Disco/UnitTest/CapsManagerTest.cpp +++ b/Swiften/Disco/UnitTest/CapsManagerTest.cpp @@ -9,13 +9,13 @@ #include <vector> #include <boost/bind.hpp> -#include "Swiften/Disco/CapsManager.h" -#include "Swiften/Disco/CapsMemoryStorage.h" -#include "Swiften/Disco/CapsInfoGenerator.h" -#include "Swiften/Queries/IQRouter.h" -#include "Swiften/Elements/CapsInfo.h" -#include "Swiften/Elements/DiscoInfo.h" -#include "Swiften/Client/DummyStanzaChannel.h" +#include <Swiften/Disco/CapsManager.h> +#include <Swiften/Disco/CapsMemoryStorage.h> +#include <Swiften/Disco/CapsInfoGenerator.h> +#include <Swiften/Queries/IQRouter.h> +#include <Swiften/Elements/CapsInfo.h> +#include <Swiften/Elements/DiscoInfo.h> +#include <Swiften/Client/DummyStanzaChannel.h> using namespace Swift; diff --git a/Swiften/Disco/UnitTest/DiscoInfoResponderTest.cpp b/Swiften/Disco/UnitTest/DiscoInfoResponderTest.cpp index bccf0d4..1477e23 100644 --- a/Swiften/Disco/UnitTest/DiscoInfoResponderTest.cpp +++ b/Swiften/Disco/UnitTest/DiscoInfoResponderTest.cpp @@ -8,9 +8,9 @@ #include <cppunit/extensions/TestFactoryRegistry.h> #include <typeinfo> -#include "Swiften/Disco/DiscoInfoResponder.h" -#include "Swiften/Queries/IQRouter.h" -#include "Swiften/Queries/DummyIQChannel.h" +#include <Swiften/Disco/DiscoInfoResponder.h> +#include <Swiften/Queries/IQRouter.h> +#include <Swiften/Queries/DummyIQChannel.h> using namespace Swift; diff --git a/Swiften/Disco/UnitTest/EntityCapsManagerTest.cpp b/Swiften/Disco/UnitTest/EntityCapsManagerTest.cpp index 544bdad..6c99a2e 100644 --- a/Swiften/Disco/UnitTest/EntityCapsManagerTest.cpp +++ b/Swiften/Disco/UnitTest/EntityCapsManagerTest.cpp @@ -9,11 +9,11 @@ #include <vector> #include <boost/bind.hpp> -#include "Swiften/Disco/EntityCapsManager.h" -#include "Swiften/Disco/CapsProvider.h" -#include "Swiften/Elements/CapsInfo.h" -#include "Swiften/Client/DummyStanzaChannel.h" -#include "Swiften/Disco/CapsInfoGenerator.h" +#include <Swiften/Disco/EntityCapsManager.h> +#include <Swiften/Disco/CapsProvider.h> +#include <Swiften/Elements/CapsInfo.h> +#include <Swiften/Client/DummyStanzaChannel.h> +#include <Swiften/Disco/CapsInfoGenerator.h> using namespace Swift; diff --git a/Swiften/Disco/UnitTest/JIDDiscoInfoResponderTest.cpp b/Swiften/Disco/UnitTest/JIDDiscoInfoResponderTest.cpp index ef61afa..7e2e3dd 100644 --- a/Swiften/Disco/UnitTest/JIDDiscoInfoResponderTest.cpp +++ b/Swiften/Disco/UnitTest/JIDDiscoInfoResponderTest.cpp @@ -8,9 +8,9 @@ #include <cppunit/extensions/TestFactoryRegistry.h> #include <typeinfo> -#include "Swiften/Disco/JIDDiscoInfoResponder.h" -#include "Swiften/Queries/IQRouter.h" -#include "Swiften/Queries/DummyIQChannel.h" +#include <Swiften/Disco/JIDDiscoInfoResponder.h> +#include <Swiften/Queries/IQRouter.h> +#include <Swiften/Queries/DummyIQChannel.h> using namespace Swift; diff --git a/Swiften/Elements/AuthChallenge.h b/Swiften/Elements/AuthChallenge.h index 74d7dba..124919c 100644 --- a/Swiften/Elements/AuthChallenge.h +++ b/Swiften/Elements/AuthChallenge.h @@ -8,8 +8,8 @@ #include <boost/optional.hpp> -#include "Swiften/Base/ByteArray.h" -#include "Swiften/Elements/Element.h" +#include <Swiften/Base/ByteArray.h> +#include <Swiften/Elements/Element.h> namespace Swift { class AuthChallenge : public Element { diff --git a/Swiften/Elements/AuthFailure.h b/Swiften/Elements/AuthFailure.h index 7ffc762..ac40956 100644 --- a/Swiften/Elements/AuthFailure.h +++ b/Swiften/Elements/AuthFailure.h @@ -8,7 +8,7 @@ #include <boost/shared_ptr.hpp> -#include "Swiften/Elements/Element.h" +#include <Swiften/Elements/Element.h> namespace Swift { class AuthFailure : public Element { diff --git a/Swiften/Elements/AuthRequest.h b/Swiften/Elements/AuthRequest.h index ba86900..3b3bd1a 100644 --- a/Swiften/Elements/AuthRequest.h +++ b/Swiften/Elements/AuthRequest.h @@ -8,8 +8,8 @@ #include <boost/optional.hpp> -#include "Swiften/Base/ByteArray.h" -#include "Swiften/Elements/Element.h" +#include <Swiften/Base/ByteArray.h> +#include <Swiften/Elements/Element.h> namespace Swift { class AuthRequest : public Element { diff --git a/Swiften/Elements/AuthResponse.h b/Swiften/Elements/AuthResponse.h index 96d1b13..30b76d3 100644 --- a/Swiften/Elements/AuthResponse.h +++ b/Swiften/Elements/AuthResponse.h @@ -8,8 +8,8 @@ #include <boost/optional.hpp> -#include "Swiften/Base/ByteArray.h" -#include "Swiften/Elements/Element.h" +#include <Swiften/Base/ByteArray.h> +#include <Swiften/Elements/Element.h> namespace Swift { class AuthResponse : public Element { diff --git a/Swiften/Elements/AuthSuccess.h b/Swiften/Elements/AuthSuccess.h index af5f9bb..85091e6 100644 --- a/Swiften/Elements/AuthSuccess.h +++ b/Swiften/Elements/AuthSuccess.h @@ -8,8 +8,8 @@ #include <boost/optional.hpp> -#include "Swiften/Elements/Element.h" -#include "Swiften/Base/ByteArray.h" +#include <Swiften/Elements/Element.h> +#include <Swiften/Base/ByteArray.h> namespace Swift { class AuthSuccess : public Element { diff --git a/Swiften/Elements/Body.h b/Swiften/Elements/Body.h index 2887390..a2497f7 100644 --- a/Swiften/Elements/Body.h +++ b/Swiften/Elements/Body.h @@ -6,14 +6,13 @@ #pragma once -#include "Swiften/Elements/Payload.h" #include <string> +#include <Swiften/Elements/Payload.h> + namespace Swift { class Body : public Payload { public: - typedef boost::shared_ptr<Body> ref; - Body(const std::string& text = "") : text_(text) { } diff --git a/Swiften/Elements/Bytestreams.h b/Swiften/Elements/Bytestreams.h index b493375..9724a54 100644 --- a/Swiften/Elements/Bytestreams.h +++ b/Swiften/Elements/Bytestreams.h @@ -9,10 +9,10 @@ #include <vector> #include <boost/optional.hpp> #include <boost/shared_ptr.hpp> - -#include "Swiften/JID/JID.h" #include <string> -#include "Swiften/Elements/Payload.h" + +#include <Swiften/JID/JID.h> +#include <Swiften/Elements/Payload.h> namespace Swift { class Bytestreams : public Payload { diff --git a/Swiften/Elements/CapsInfo.h b/Swiften/Elements/CapsInfo.h index ccad278..c6d3b64 100644 --- a/Swiften/Elements/CapsInfo.h +++ b/Swiften/Elements/CapsInfo.h @@ -7,9 +7,9 @@ #pragma once #include <boost/shared_ptr.hpp> - #include <string> -#include "Swiften/Elements/Payload.h" + +#include <Swiften/Elements/Payload.h> namespace Swift { class CapsInfo : public Payload { diff --git a/Swiften/Elements/ChatState.h b/Swiften/Elements/ChatState.h index 2896877..5c83318 100644 --- a/Swiften/Elements/ChatState.h +++ b/Swiften/Elements/ChatState.h @@ -7,7 +7,8 @@ #pragma once #include <string> -#include "Swiften/Elements/Payload.h" + +#include <Swiften/Elements/Payload.h> namespace Swift { class ChatState : public Payload { diff --git a/Swiften/Elements/Command.h b/Swiften/Elements/Command.h index f4059a8..91ae5a3 100644 --- a/Swiften/Elements/Command.h +++ b/Swiften/Elements/Command.h @@ -7,10 +7,10 @@ #pragma once #include <boost/shared_ptr.hpp> - #include <string> -#include "Swiften/Elements/Payload.h" -#include "Swiften/Elements/Form.h" + +#include <Swiften/Elements/Payload.h> +#include <Swiften/Elements/Form.h> namespace Swift { /** diff --git a/Swiften/Elements/ComponentHandshake.h b/Swiften/Elements/ComponentHandshake.h index 6047eab..5992b8c 100644 --- a/Swiften/Elements/ComponentHandshake.h +++ b/Swiften/Elements/ComponentHandshake.h @@ -7,10 +7,10 @@ #pragma once #include <boost/shared_ptr.hpp> - -#include "Swiften/Elements/Element.h" #include <string> +#include <Swiften/Elements/Element.h> + namespace Swift { class ComponentHandshake : public Element { public: diff --git a/Swiften/Elements/CompressFailure.h b/Swiften/Elements/CompressFailure.h index c0d5847..ab102ad 100644 --- a/Swiften/Elements/CompressFailure.h +++ b/Swiften/Elements/CompressFailure.h @@ -7,7 +7,7 @@ #ifndef SWIFTEN_CompressFailure_H #define SWIFTEN_CompressFailure_H -#include "Swiften/Elements/Element.h" +#include <Swiften/Elements/Element.h> namespace Swift { class CompressFailure : public Element { diff --git a/Swiften/Elements/CompressRequest.h b/Swiften/Elements/CompressRequest.h index 0eb302a..cb2f8d2 100644 --- a/Swiften/Elements/CompressRequest.h +++ b/Swiften/Elements/CompressRequest.h @@ -7,7 +7,7 @@ #ifndef SWIFTEN_CompressRequest_H #define SWIFTEN_CompressRequest_H -#include "Swiften/Elements/Element.h" +#include <Swiften/Elements/Element.h> namespace Swift { class CompressRequest : public Element diff --git a/Swiften/Elements/Compressed.h b/Swiften/Elements/Compressed.h index e50c17e..7154ac4 100644 --- a/Swiften/Elements/Compressed.h +++ b/Swiften/Elements/Compressed.h @@ -7,7 +7,7 @@ #ifndef SWIFTEN_COMPRESSED_H #define SWIFTEN_COMPRESSED_H -#include "Swiften/Elements/Element.h" +#include <Swiften/Elements/Element.h> namespace Swift { class Compressed : public Element diff --git a/Swiften/Elements/Delay.h b/Swiften/Elements/Delay.h index 3213037..f7c4570 100644 --- a/Swiften/Elements/Delay.h +++ b/Swiften/Elements/Delay.h @@ -6,11 +6,11 @@ #pragma once -#include <boost/date_time/posix_time/posix_time.hpp> +#include <boost/date_time/posix_time/posix_time_types.hpp> #include <boost/optional.hpp> -#include "Swiften/Elements/Payload.h" -#include "Swiften/JID/JID.h" +#include <Swiften/Elements/Payload.h> +#include <Swiften/JID/JID.h> namespace Swift { class Delay : public Payload { diff --git a/Swiften/Elements/DiscoInfo.cpp b/Swiften/Elements/DiscoInfo.cpp index f0e728e..d6afb2d 100644 --- a/Swiften/Elements/DiscoInfo.cpp +++ b/Swiften/Elements/DiscoInfo.cpp @@ -4,7 +4,9 @@ * See Documentation/Licenses/GPLv3.txt for more information. */ -#include "Swiften/Elements/DiscoInfo.h" +#include <Swiften/Elements/DiscoInfo.h> + +#include <algorithm> namespace Swift { @@ -12,6 +14,7 @@ const std::string DiscoInfo::ChatStatesFeature = std::string("http://jabber.org/ const std::string DiscoInfo::SecurityLabelsFeature = std::string("urn:xmpp:sec-label:0"); const std::string DiscoInfo::SecurityLabelsCatalogFeature = std::string("urn:xmpp:sec-label:catalog:2"); const std::string DiscoInfo::JabberSearchFeature = std::string("jabber:iq:search"); +const std::string DiscoInfo::CommandsFeature = std::string("http://jabber.org/protocol/commands"); bool DiscoInfo::Identity::operator<(const Identity& other) const { @@ -33,4 +36,8 @@ bool DiscoInfo::Identity::operator<(const Identity& other) const { } } +bool DiscoInfo::hasFeature(const std::string& feature) const { + return std::find(features_.begin(), features_.end(), feature) != features_.end(); +} + } diff --git a/Swiften/Elements/DiscoInfo.h b/Swiften/Elements/DiscoInfo.h index d5bf64a..cb6a446 100644 --- a/Swiften/Elements/DiscoInfo.h +++ b/Swiften/Elements/DiscoInfo.h @@ -7,12 +7,10 @@ #pragma once #include <vector> -#include <algorithm> - -#include "Swiften/Elements/Payload.h" #include <string> -#include "Swiften/Elements/Form.h" +#include <Swiften/Elements/Payload.h> +#include <Swiften/Elements/Form.h> namespace Swift { class DiscoInfo : public Payload { @@ -23,6 +21,7 @@ namespace Swift { static const std::string SecurityLabelsFeature; static const std::string SecurityLabelsCatalogFeature; static const std::string JabberSearchFeature; + static const std::string CommandsFeature; class Identity { public: @@ -82,9 +81,7 @@ namespace Swift { features_.push_back(feature); } - bool hasFeature(const std::string& feature) const { - return std::find(features_.begin(), features_.end(), feature) != features_.end(); - } + bool hasFeature(const std::string& feature) const; void addExtension(Form::ref form) { extensions_.push_back(form); diff --git a/Swiften/Elements/DiscoItems.h b/Swiften/Elements/DiscoItems.h index cc5a583..149e41c 100644 --- a/Swiften/Elements/DiscoItems.h +++ b/Swiften/Elements/DiscoItems.h @@ -7,11 +7,10 @@ #pragma once #include <vector> -#include <algorithm> - -#include "Swiften/Elements/Payload.h" #include <string> -#include "Swiften/JID/JID.h" + +#include <Swiften/Elements/Payload.h> +#include <Swiften/JID/JID.h> namespace Swift { class DiscoItems : public Payload { diff --git a/Swiften/Elements/Element.cpp b/Swiften/Elements/Element.cpp index 5407e89..94829ba 100644 --- a/Swiften/Elements/Element.cpp +++ b/Swiften/Elements/Element.cpp @@ -4,7 +4,7 @@ * See Documentation/Licenses/GPLv3.txt for more information. */ -#include "Swiften/Elements/Element.h" +#include <Swiften/Elements/Element.h> namespace Swift { diff --git a/Swiften/Elements/Element.h b/Swiften/Elements/Element.h index aded528..1e6a9d0 100644 --- a/Swiften/Elements/Element.h +++ b/Swiften/Elements/Element.h @@ -4,8 +4,7 @@ * See Documentation/Licenses/GPLv3.txt for more information. */ -#ifndef SWIFTEN_ELEMENT_H -#define SWIFTEN_ELEMENT_H +#pragma once namespace Swift { class Element { @@ -13,5 +12,3 @@ namespace Swift { virtual ~Element(); }; } - -#endif diff --git a/Swiften/Elements/EnableStreamManagement.h b/Swiften/Elements/EnableStreamManagement.h index 807db84..15a091e 100644 --- a/Swiften/Elements/EnableStreamManagement.h +++ b/Swiften/Elements/EnableStreamManagement.h @@ -6,7 +6,7 @@ #pragma once -#include "Swiften/Elements/Element.h" +#include <Swiften/Elements/Element.h> namespace Swift { diff --git a/Swiften/Elements/ErrorPayload.h b/Swiften/Elements/ErrorPayload.h index 12ad574..9245a83 100644 --- a/Swiften/Elements/ErrorPayload.h +++ b/Swiften/Elements/ErrorPayload.h @@ -7,10 +7,10 @@ #pragma once #include <boost/shared_ptr.hpp> - -#include "Swiften/Elements/Payload.h" #include <string> +#include <Swiften/Elements/Payload.h> + namespace Swift { class ErrorPayload : public Payload { public: diff --git a/Swiften/Elements/Form.cpp b/Swiften/Elements/Form.cpp index 03fd1a4..c34b868 100644 --- a/Swiften/Elements/Form.cpp +++ b/Swiften/Elements/Form.cpp @@ -4,8 +4,8 @@ * See Documentation/Licenses/GPLv3.txt for more information. */ -#include "Swiften/Elements/Form.h" -#include "Swiften/Base/foreach.h" +#include <Swiften/Elements/Form.h> +#include <Swiften/Base/foreach.h> namespace Swift { diff --git a/Swiften/Elements/Form.h b/Swiften/Elements/Form.h index 1c50f0c..3b93be4 100644 --- a/Swiften/Elements/Form.h +++ b/Swiften/Elements/Form.h @@ -7,12 +7,11 @@ #pragma once #include <vector> - -#include "Swiften/Elements/Payload.h" -#include "Swiften/Elements/FormField.h" #include <string> -#include "Swiften/JID/JID.h" +#include <Swiften/Elements/Payload.h> +#include <Swiften/Elements/FormField.h> +#include <Swiften/JID/JID.h> namespace Swift { /** diff --git a/Swiften/Elements/FormField.h b/Swiften/Elements/FormField.h index f455303..31e179d 100644 --- a/Swiften/Elements/FormField.h +++ b/Swiften/Elements/FormField.h @@ -11,9 +11,9 @@ #include <vector> #include <boost/shared_ptr.hpp> - #include <string> -#include "Swiften/JID/JID.h" + +#include <Swiften/JID/JID.h> namespace Swift { class FormField { @@ -111,5 +111,4 @@ namespace Swift { SWIFTEN_DECLARE_FORM_FIELD(JIDSingle, JID); SWIFTEN_DECLARE_FORM_FIELD(JIDMulti, std::vector<JID>); SWIFTEN_DECLARE_FORM_FIELD(ListMulti, std::vector<std::string>); - SWIFTEN_DECLARE_FORM_FIELD(Untyped, std::vector<std::string>); } diff --git a/Swiften/Elements/IBB.h b/Swiften/Elements/IBB.h index 55f2c4f..8138e83 100644 --- a/Swiften/Elements/IBB.h +++ b/Swiften/Elements/IBB.h @@ -6,11 +6,11 @@ #pragma once +#include <string> +#include <vector> #include <boost/shared_ptr.hpp> -#include <string> -#include "Swiften/Base/ByteArray.h" -#include "Swiften/Elements/Payload.h" +#include <Swiften/Elements/Payload.h> namespace Swift { class IBB : public Payload { @@ -36,7 +36,7 @@ namespace Swift { return result; } - static IBB::ref createIBBData(const std::string& streamID, int sequenceNumber, const ByteArray& data) { + static IBB::ref createIBBData(const std::string& streamID, int sequenceNumber, const std::vector<unsigned char>& data) { IBB::ref result(new IBB(Data, streamID)); result->setSequenceNumber(sequenceNumber); result->setData(data); @@ -71,11 +71,11 @@ namespace Swift { return streamID; } - const ByteArray& getData() const { + const std::vector<unsigned char>& getData() const { return data; } - void setData(const ByteArray& data) { + void setData(const std::vector<unsigned char>& data) { this->data = data; } @@ -98,7 +98,7 @@ namespace Swift { private: Action action; std::string streamID; - ByteArray data; + std::vector<unsigned char> data; StanzaType stanzaType; int blockSize; int sequenceNumber; diff --git a/Swiften/Elements/IQ.cpp b/Swiften/Elements/IQ.cpp index eb62ee4..2c9c763 100644 --- a/Swiften/Elements/IQ.cpp +++ b/Swiften/Elements/IQ.cpp @@ -4,7 +4,7 @@ * See Documentation/Licenses/GPLv3.txt for more information. */ -#include "Swiften/Elements/IQ.h" +#include <Swiften/Elements/IQ.h> namespace Swift { diff --git a/Swiften/Elements/IQ.h b/Swiften/Elements/IQ.h index 78a8bbd..05cd96a 100644 --- a/Swiften/Elements/IQ.h +++ b/Swiften/Elements/IQ.h @@ -8,8 +8,8 @@ #include <boost/shared_ptr.hpp> -#include "Swiften/Elements/Stanza.h" -#include "Swiften/Elements/ErrorPayload.h" +#include <Swiften/Elements/Stanza.h> +#include <Swiften/Elements/ErrorPayload.h> namespace Swift { class IQ : public Stanza { diff --git a/Swiften/Elements/InBandRegistrationPayload.h b/Swiften/Elements/InBandRegistrationPayload.h index e4e1e6f..8f6a9f1 100644 --- a/Swiften/Elements/InBandRegistrationPayload.h +++ b/Swiften/Elements/InBandRegistrationPayload.h @@ -8,11 +8,11 @@ #include <boost/shared_ptr.hpp> #include <boost/optional.hpp> - -#include "Swiften/Elements/Payload.h" -#include "Swiften/Elements/Form.h" #include <string> +#include <Swiften/Elements/Payload.h> +#include <Swiften/Elements/Form.h> + namespace Swift { class InBandRegistrationPayload : public Payload { public: diff --git a/Swiften/Elements/JingleContent.h b/Swiften/Elements/JingleContentPayload.h index 4ae908b..c44a806 100644 --- a/Swiften/Elements/JingleContent.h +++ b/Swiften/Elements/JingleContentPayload.h @@ -8,18 +8,17 @@ #include <vector> #include <boost/optional.hpp> - #include <string> + #include <Swiften/JID/JID.h> #include <Swiften/Elements/Payload.h> #include <Swiften/Elements/JingleDescription.h> -#include <Swiften/Elements/JingleTransport.h> -#include <Swiften/Base/foreach.h> +#include <Swiften/Elements/JingleTransportPayload.h> namespace Swift { - class JingleContent : public Payload { + class JingleContentPayload : public Payload { public: - typedef boost::shared_ptr<JingleContent> ref; + typedef boost::shared_ptr<JingleContentPayload> ref; enum Creator { InitiatorCreator, @@ -33,10 +32,18 @@ namespace Swift { BothSenders, };*/ + Creator getCreator() const { + return creator; + } + void setCreator(Creator creator) { this->creator = creator; } + const std::string& getName() const { + return name; + } + void setName(const std::string& name) { this->name = name; } @@ -49,18 +56,18 @@ namespace Swift { descriptions.push_back(description); } - const std::vector<JingleTransport::ref>& getTransports() const { + const std::vector<boost::shared_ptr<JingleTransportPayload> >& getTransports() const { return transports; } - void addTransport(JingleTransport::ref transport) { + void addTransport(boost::shared_ptr<JingleTransportPayload> transport) { transports.push_back(transport); } template<typename T> boost::shared_ptr<T> getDescription() const { - foreach (JingleDescription::ref i, descriptions) { - boost::shared_ptr<T> result(boost::dynamic_pointer_cast<T>(i)); + for (size_t i = 0; i < descriptions.size(); ++i) { + boost::shared_ptr<T> result(boost::dynamic_pointer_cast<T>(descriptions[i])); if (result) { return result; } @@ -70,8 +77,8 @@ namespace Swift { template<typename T> boost::shared_ptr<T> getTransport() const { - foreach (JingleTransport::ref i, transports) { - boost::shared_ptr<T> result(boost::dynamic_pointer_cast<T>(i)); + for (size_t i = 0; i < transports.size(); ++i) { + boost::shared_ptr<T> result(boost::dynamic_pointer_cast<T>(transports[i])); if (result) { return result; } @@ -84,6 +91,6 @@ namespace Swift { std::string name; //Senders senders; std::vector<JingleDescription::ref> descriptions; - std::vector<JingleTransport::ref> transports; + std::vector<boost::shared_ptr<JingleTransportPayload> > transports; }; } diff --git a/Swiften/Elements/JingleIBBTransport.h b/Swiften/Elements/JingleIBBTransportPayload.h index faa5af3..67aab09 100644 --- a/Swiften/Elements/JingleIBBTransport.h +++ b/Swiften/Elements/JingleIBBTransportPayload.h @@ -6,12 +6,16 @@ #pragma once +#include <boost/shared_ptr.hpp> #include <string> -#include <Swiften/Elements/JingleTransport.h> + +#include <Swiften/Elements/JingleTransportPayload.h> namespace Swift { - class JingleIBBTransport : public JingleTransport { + class JingleIBBTransportPayload : public JingleTransportPayload { public: + typedef boost::shared_ptr<JingleIBBTransportPayload> ref; + enum StanzaType { IQStanza, MessageStanza, diff --git a/Swiften/Elements/JinglePayload.h b/Swiften/Elements/JinglePayload.h index 59d3c99..be02543 100644 --- a/Swiften/Elements/JinglePayload.h +++ b/Swiften/Elements/JinglePayload.h @@ -12,7 +12,7 @@ #include <string> #include <Swiften/JID/JID.h> #include <Swiften/Elements/Payload.h> -#include <Swiften/Elements/JingleContent.h> +#include <Swiften/Elements/JingleContentPayload.h> namespace Swift { @@ -98,11 +98,11 @@ namespace Swift { return sessionID; } - void addContent(JingleContent::ref content) { + void addContent(JingleContentPayload::ref content) { this->contents.push_back(content); } - const std::vector<JingleContent::ref> getContents() const { + const std::vector<JingleContentPayload::ref> getContents() const { return contents; } @@ -119,7 +119,7 @@ namespace Swift { JID initiator; JID responder; std::string sessionID; - std::vector<JingleContent::ref> contents; + std::vector<JingleContentPayload::ref> contents; boost::optional<Reason> reason; }; } diff --git a/Swiften/Elements/JingleS5BTransport.h b/Swiften/Elements/JingleS5BTransportPayload.h index 4522417..7b3089f 100644 --- a/Swiften/Elements/JingleS5BTransport.h +++ b/Swiften/Elements/JingleS5BTransportPayload.h @@ -6,11 +6,13 @@ #pragma once -#include <Swiften/Elements/JingleTransport.h> +#include <Swiften/Elements/JingleTransportPayload.h> #include <Swiften/Elements/Bytestreams.h> +// FIXME: Remove Bytestreams, and replace by our own candidate + namespace Swift { - class JingleS5BTransport : public JingleTransport { + class JingleS5BTransportPayload : public JingleTransportPayload { public: const Bytestreams& getInfo() const { return info; diff --git a/Swiften/Elements/JingleTransportPayload.h b/Swiften/Elements/JingleTransportPayload.h new file mode 100644 index 0000000..7a9ea29 --- /dev/null +++ b/Swiften/Elements/JingleTransportPayload.h @@ -0,0 +1,18 @@ +/* + * Copyright (c) 2011 Remko Tronçon + * Licensed under the GNU General Public License v3. + * See Documentation/Licenses/GPLv3.txt for more information. + */ + +#pragma once + +#include <boost/shared_ptr.hpp> + +#include <Swiften/Elements/Payload.h> + +namespace Swift { + class JingleTransportPayload : public Payload { + public: + typedef boost::shared_ptr<JingleTransportPayload> ref; + }; +} diff --git a/Swiften/Elements/MUCOccupant.cpp b/Swiften/Elements/MUCOccupant.cpp index a5d8f0e..57034ad 100644 --- a/Swiften/Elements/MUCOccupant.cpp +++ b/Swiften/Elements/MUCOccupant.cpp @@ -4,7 +4,7 @@ * See Documentation/Licenses/GPLv3.txt for more information. */ -#include "Swiften/Elements/MUCOccupant.h" +#include <Swiften/Elements/MUCOccupant.h> namespace Swift { diff --git a/Swiften/Elements/MUCOccupant.h b/Swiften/Elements/MUCOccupant.h index b3ae4aa..931f544 100644 --- a/Swiften/Elements/MUCOccupant.h +++ b/Swiften/Elements/MUCOccupant.h @@ -9,7 +9,7 @@ #include <boost/optional.hpp> #include <string> -#include "Swiften/JID/JID.h" +#include <Swiften/JID/JID.h> namespace Swift { class Client; diff --git a/Swiften/Elements/MUCOwnerPayload.h b/Swiften/Elements/MUCOwnerPayload.h index 6c3e5f0..a3db05b 100644 --- a/Swiften/Elements/MUCOwnerPayload.h +++ b/Swiften/Elements/MUCOwnerPayload.h @@ -8,7 +8,7 @@ #include <boost/optional.hpp> -#include "Swiften/Elements/Payload.h" +#include <Swiften/Elements/Payload.h> namespace Swift { class MUCOwnerPayload : public Payload { diff --git a/Swiften/Elements/MUCPayload.h b/Swiften/Elements/MUCPayload.h index c372360..8b75bd4 100644 --- a/Swiften/Elements/MUCPayload.h +++ b/Swiften/Elements/MUCPayload.h @@ -7,11 +7,11 @@ #pragma once #include <boost/optional.hpp> -#include <boost/date_time/posix_time/posix_time.hpp> +#include <boost/date_time/posix_time/posix_time_types.hpp> -#include "Swiften/JID/JID.h" +#include <Swiften/JID/JID.h> #include <string> -#include "Swiften/Elements/Payload.h" +#include <Swiften/Elements/Payload.h> namespace Swift { class MUCPayload : public Payload { diff --git a/Swiften/Elements/MUCUserPayload.h b/Swiften/Elements/MUCUserPayload.h index fb6d4c4..b142a8d 100644 --- a/Swiften/Elements/MUCUserPayload.h +++ b/Swiften/Elements/MUCUserPayload.h @@ -11,9 +11,9 @@ #include <string> #include <vector> -#include "Swiften/JID/JID.h" -#include "Swiften/Elements/Payload.h" -#include "Swiften/Elements/MUCOccupant.h" +#include <Swiften/JID/JID.h> +#include <Swiften/Elements/Payload.h> +#include <Swiften/Elements/MUCOccupant.h> namespace Swift { class MUCUserPayload : public Payload { diff --git a/Swiften/Elements/Message.h b/Swiften/Elements/Message.h index a553eb3..dc2eaf1 100644 --- a/Swiften/Elements/Message.h +++ b/Swiften/Elements/Message.h @@ -10,10 +10,11 @@ #include <boost/shared_ptr.hpp> #include <string> -#include "Swiften/Elements/Body.h" -#include "Swiften/Elements/Subject.h" -#include "Swiften/Elements/ErrorPayload.h" -#include "Swiften/Elements/Stanza.h" +#include <Swiften/Elements/Body.h> +#include <Swiften/Elements/Subject.h> +#include <Swiften/Elements/ErrorPayload.h> +#include <Swiften/Elements/Stanza.h> +#include <Swiften/Elements/Replace.h> namespace Swift { class Message : public Stanza { diff --git a/Swiften/Elements/Nickname.h b/Swiften/Elements/Nickname.h index 540f6da..a244ce3 100644 --- a/Swiften/Elements/Nickname.h +++ b/Swiften/Elements/Nickname.h @@ -6,7 +6,7 @@ #pragma once -#include "Swiften/Elements/Payload.h" +#include <Swiften/Elements/Payload.h> #include <string> namespace Swift { diff --git a/Swiften/Elements/Payload.cpp b/Swiften/Elements/Payload.cpp index b66dcdb..b7c3ffe 100644 --- a/Swiften/Elements/Payload.cpp +++ b/Swiften/Elements/Payload.cpp @@ -4,7 +4,7 @@ * See Documentation/Licenses/GPLv3.txt for more information. */ -#include "Swiften/Elements/Payload.h" +#include <Swiften/Elements/Payload.h> namespace Swift { diff --git a/Swiften/Elements/Payload.h b/Swiften/Elements/Payload.h index c87b899..8b6d44a 100644 --- a/Swiften/Elements/Payload.h +++ b/Swiften/Elements/Payload.h @@ -6,13 +6,9 @@ #pragma once -#include <boost/shared_ptr.hpp> - namespace Swift { class Payload { public: - typedef boost::shared_ptr<Payload> ref; - virtual ~Payload(); }; } diff --git a/Swiften/Elements/Presence.cpp b/Swiften/Elements/Presence.cpp new file mode 100644 index 0000000..6cde567 --- /dev/null +++ b/Swiften/Elements/Presence.cpp @@ -0,0 +1,46 @@ +/* + * Copyright (c) 2010 Remko Tronçon + * Licensed under the GNU General Public License v3. + * See Documentation/Licenses/GPLv3.txt for more information. + */ + +#include <Swiften/Elements/Presence.h> + +#include <Swiften/Elements/Priority.h> +#include <Swiften/Elements/Status.h> + +namespace Swift { + +Presence::Presence() : type_(Available) /*, showType_(Online)*/ { +} + +Presence::Presence(const std::string& status) : type_(Available) { + setStatus(status); +} + +Presence::~Presence() { +} + +int Presence::getPriority() const { + boost::shared_ptr<Priority> priority(getPayload<Priority>()); + return (priority ? priority->getPriority() : 0); +} + +void Presence::setPriority(int priority) { + updatePayload(boost::shared_ptr<Priority>(new Priority(priority))); +} + +std::string Presence::getStatus() const { + boost::shared_ptr<Status> status(getPayload<Status>()); + if (status) { + return status->getText(); + } + return ""; +} + +void Presence::setStatus(const std::string& status) { + updatePayload(boost::shared_ptr<Status>(new Status(status))); +} + + +} diff --git a/Swiften/Elements/Presence.h b/Swiften/Elements/Presence.h index 7f957ba..5ae482b 100644 --- a/Swiften/Elements/Presence.h +++ b/Swiften/Elements/Presence.h @@ -6,11 +6,8 @@ #pragma once - -#include "Swiften/Elements/Stanza.h" -#include "Swiften/Elements/Status.h" -#include "Swiften/Elements/StatusShow.h" -#include "Swiften/Elements/Priority.h" +#include <Swiften/Elements/Stanza.h> +#include <Swiften/Elements/StatusShow.h> namespace Swift { class Presence : public Stanza { @@ -19,10 +16,9 @@ namespace Swift { enum Type { Available, Error, Probe, Subscribe, Subscribed, Unavailable, Unsubscribe, Unsubscribed }; - Presence() : type_(Available) /*, showType_(Online)*/ {} - Presence(const std::string& status) : type_(Available) { - setStatus(status); - } + Presence(); + Presence(const std::string& status); + virtual ~Presence(); static ref create() { return ref(new Presence()); @@ -51,26 +47,11 @@ namespace Swift { updatePayload(boost::shared_ptr<StatusShow>(new StatusShow(show))); } - std::string getStatus() const { - boost::shared_ptr<Status> status(getPayload<Status>()); - if (status) { - return status->getText(); - } - return ""; - } + std::string getStatus() const; + void setStatus(const std::string& status); - void setStatus(const std::string& status) { - updatePayload(boost::shared_ptr<Status>(new Status(status))); - } - - int getPriority() const { - boost::shared_ptr<Priority> priority(getPayload<Priority>()); - return (priority ? priority->getPriority() : 0); - } - - void setPriority(int priority) { - updatePayload(boost::shared_ptr<Priority>(new Priority(priority))); - } + int getPriority() const; + void setPriority(int priority); boost::shared_ptr<Presence> clone() const { return boost::shared_ptr<Presence>(new Presence(*this)); diff --git a/Swiften/Elements/Priority.h b/Swiften/Elements/Priority.h index 12181d4..2c0cb9b 100644 --- a/Swiften/Elements/Priority.h +++ b/Swiften/Elements/Priority.h @@ -6,13 +6,11 @@ #pragma once -#include "Swiften/Elements/Payload.h" +#include <Swiften/Elements/Payload.h> namespace Swift { class Priority : public Payload { public: - typedef boost::shared_ptr<Priority> ref; - Priority(int priority = 0) : priority_(priority) { } diff --git a/Swiften/Elements/PrivateStorage.h b/Swiften/Elements/PrivateStorage.h index 34d9185..a8e1b74 100644 --- a/Swiften/Elements/PrivateStorage.h +++ b/Swiften/Elements/PrivateStorage.h @@ -8,7 +8,7 @@ #include <boost/shared_ptr.hpp> -#include "Swiften/Elements/Payload.h" +#include <Swiften/Elements/Payload.h> namespace Swift { class PrivateStorage : public Payload { diff --git a/Swiften/Elements/Replace.h b/Swiften/Elements/Replace.h new file mode 100644 index 0000000..230bce7 --- /dev/null +++ b/Swiften/Elements/Replace.h @@ -0,0 +1,28 @@ +/* + * Copyright (c) 2011 Vlad Voicu + * Licensed under the Simplified BSD license. + * See Documentation/Licenses/BSD-simplified.txt for more information. + */ + +#pragma once + +#include <boost/shared_ptr.hpp> +#include <string> + +#include <Swiften/Elements/Payload.h> + +namespace Swift { + class Replace : public Payload { + public: + typedef boost::shared_ptr<Replace> ref; + Replace(const std::string& id = std::string()) : replaceID_(id) {}; + const std::string& getID() const { + return replaceID_; + } + void setID(const std::string& id) { + replaceID_ = id; + } + private: + std::string replaceID_; + }; +} diff --git a/Swiften/Elements/ResourceBind.h b/Swiften/Elements/ResourceBind.h index 3569eb3..36d07f6 100644 --- a/Swiften/Elements/ResourceBind.h +++ b/Swiften/Elements/ResourceBind.h @@ -8,8 +8,8 @@ #define SWIFTEN_ResourceBind_H #include <string> -#include "Swiften/Elements/Payload.h" -#include "Swiften/JID/JID.h" +#include <Swiften/Elements/Payload.h> +#include <Swiften/JID/JID.h> namespace Swift { class ResourceBind : public Payload diff --git a/Swiften/Elements/RosterItemExchangePayload.cpp b/Swiften/Elements/RosterItemExchangePayload.cpp new file mode 100644 index 0000000..a425551 --- /dev/null +++ b/Swiften/Elements/RosterItemExchangePayload.cpp @@ -0,0 +1,18 @@ +/* + * Copyright (c) 2011 Jan Kaluza + * Licensed under the Simplified BSD license. + * See Documentation/Licenses/BSD-simplified.txt for more information. + */ + +#include <Swiften/Elements/RosterItemExchangePayload.h> +#include <Swiften/Base/foreach.h> + +namespace Swift { + +RosterItemExchangePayload::Item::Item() { +} + +RosterItemExchangePayload::RosterItemExchangePayload() { +} + +} diff --git a/Swiften/Elements/RosterItemExchangePayload.h b/Swiften/Elements/RosterItemExchangePayload.h new file mode 100644 index 0000000..cbe9ffa --- /dev/null +++ b/Swiften/Elements/RosterItemExchangePayload.h @@ -0,0 +1,83 @@ +/* + * Copyright (c) 2011 Jan Kaluza + * Licensed under the Simplified BSD license. + * See Documentation/Licenses/BSD-simplified.txt for more information. + */ + +#pragma once + +#include <vector> +#include <string> +#include <boost/shared_ptr.hpp> + +#include <Swiften/Elements/Payload.h> +#include <Swiften/JID/JID.h> + + +namespace Swift { + class RosterItemExchangePayload : public Payload { + public: + typedef boost::shared_ptr<RosterItemExchangePayload> ref; + + class Item { + public: + enum Action { Add, Modify, Delete }; + + Item(); + + Action getAction() const { + return action; + } + + void setAction(Action action) { + this->action = action; + } + + const JID& getJID() const { + return jid; + } + + void setJID(const JID& jid) { + this->jid = jid; + } + + const std::string& getName() const { + return name; + } + + void setName(const std::string& name) { + this->name = name; + } + + const std::vector<std::string>& getGroups() const { + return groups; + } + + void addGroup(const std::string& group) { + groups.push_back(group); + } + + private: + Action action; + JID jid; + std::string name; + std::vector<std::string> groups; + }; + + typedef std::vector<RosterItemExchangePayload::Item> RosterItemExchangePayloadItems; + + public: + RosterItemExchangePayload(); + + void addItem(const RosterItemExchangePayload::Item& item) { + items_.push_back(item); + } + + const RosterItemExchangePayloadItems& getItems() const { + return items_; + } + + private: + RosterItemExchangePayloadItems items_; + }; +} diff --git a/Swiften/Elements/RosterItemPayload.h b/Swiften/Elements/RosterItemPayload.h index b8a1b10..915ae31 100644 --- a/Swiften/Elements/RosterItemPayload.h +++ b/Swiften/Elements/RosterItemPayload.h @@ -4,22 +4,20 @@ * See Documentation/Licenses/GPLv3.txt for more information. */ -#ifndef SWIFTEN_RosterItemPayloadPayload_H -#define SWIFTEN_RosterItemPayloadPayload_H +#pragma once #include <vector> - -#include "Swiften/JID/JID.h" #include <string> +#include <Swiften/JID/JID.h> + namespace Swift { - class RosterItemPayload - { + class RosterItemPayload { public: enum Subscription { None, To, From, Both, Remove }; RosterItemPayload() : subscription_(None), ask_(false) {} - RosterItemPayload(const JID& jid, const std::string& name, Subscription subscription) : jid_(jid), name_(name), subscription_(subscription), ask_(false) { } + RosterItemPayload(const JID& jid, const std::string& name, Subscription subscription, const std::vector<std::string>& groups = std::vector<std::string>()) : jid_(jid), name_(name), subscription_(subscription), groups_(groups), ask_(false) { } void setJID(const JID& jid) { jid_ = jid; } const JID& getJID() const { return jid_; } @@ -51,5 +49,3 @@ namespace Swift { std::string unknownContent_; }; } - -#endif diff --git a/Swiften/Elements/RosterPayload.cpp b/Swiften/Elements/RosterPayload.cpp index 5453ae8..6071cbc 100644 --- a/Swiften/Elements/RosterPayload.cpp +++ b/Swiften/Elements/RosterPayload.cpp @@ -4,8 +4,8 @@ * See Documentation/Licenses/GPLv3.txt for more information. */ -#include "Swiften/Elements/RosterPayload.h" -#include "Swiften/Base/foreach.h" +#include <Swiften/Elements/RosterPayload.h> +#include <Swiften/Base/foreach.h> namespace Swift { diff --git a/Swiften/Elements/RosterPayload.h b/Swiften/Elements/RosterPayload.h index b46b384..c4907cb 100644 --- a/Swiften/Elements/RosterPayload.h +++ b/Swiften/Elements/RosterPayload.h @@ -10,8 +10,8 @@ #include <boost/optional.hpp> #include <boost/shared_ptr.hpp> -#include "Swiften/Elements/RosterItemPayload.h" -#include "Swiften/Elements/Payload.h" +#include <Swiften/Elements/RosterItemPayload.h> +#include <Swiften/Elements/Payload.h> namespace Swift { @@ -33,7 +33,16 @@ namespace Swift { return items_; } + const boost::optional<std::string>& getVersion() const { + return version_; + } + + void setVersion(const std::string& version) { + version_ = version; + } + private: RosterItemPayloads items_; + boost::optional<std::string> version_; }; } diff --git a/Swiften/Elements/SearchPayload.h b/Swiften/Elements/SearchPayload.h index 3a484cc..fe5b09a 100644 --- a/Swiften/Elements/SearchPayload.h +++ b/Swiften/Elements/SearchPayload.h @@ -9,8 +9,8 @@ #include <boost/shared_ptr.hpp> #include <boost/optional.hpp> -#include "Swiften/Elements/Payload.h" -#include "Swiften/Elements/Form.h" +#include <Swiften/Elements/Payload.h> +#include <Swiften/Elements/Form.h> #include <string> namespace Swift { diff --git a/Swiften/Elements/SecurityLabel.h b/Swiften/Elements/SecurityLabel.h index ca38e32..11952c3 100644 --- a/Swiften/Elements/SecurityLabel.h +++ b/Swiften/Elements/SecurityLabel.h @@ -10,7 +10,7 @@ #include <vector> #include <string> -#include "Swiften/Elements/Payload.h" +#include <Swiften/Elements/Payload.h> namespace Swift { class SecurityLabel : public Payload { diff --git a/Swiften/Elements/SecurityLabelsCatalog.h b/Swiften/Elements/SecurityLabelsCatalog.h index 10ef459..0f40c13 100644 --- a/Swiften/Elements/SecurityLabelsCatalog.h +++ b/Swiften/Elements/SecurityLabelsCatalog.h @@ -4,15 +4,15 @@ * See Documentation/Licenses/GPLv3.txt for more information. */ -#ifndef SWIFTEN_SecurityLabelsCatalog_H -#define SWIFTEN_SecurityLabelsCatalog_H +#pragma once #include <vector> - -#include "Swiften/JID/JID.h" #include <string> -#include "Swiften/Elements/Payload.h" -#include "Swiften/Elements/SecurityLabel.h" +#include <boost/shared_ptr.hpp> + +#include <Swiften/JID/JID.h> +#include <Swiften/Elements/Payload.h> +#include <Swiften/Elements/SecurityLabel.h> namespace Swift { class SecurityLabelsCatalog : public Payload { @@ -85,5 +85,3 @@ namespace Swift { std::vector<Item> items_; }; } - -#endif diff --git a/Swiften/Elements/SoftwareVersion.h b/Swiften/Elements/SoftwareVersion.h index 5863b38..c49b47b 100644 --- a/Swiften/Elements/SoftwareVersion.h +++ b/Swiften/Elements/SoftwareVersion.h @@ -6,8 +6,10 @@ #pragma once -#include "Swiften/Elements/Payload.h" #include <string> +#include <boost/shared_ptr.hpp> + +#include <Swiften/Elements/Payload.h> namespace Swift { class SoftwareVersion : public Payload { diff --git a/Swiften/Elements/Stanza.cpp b/Swiften/Elements/Stanza.cpp index d15d778..23f2d89 100644 --- a/Swiften/Elements/Stanza.cpp +++ b/Swiften/Elements/Stanza.cpp @@ -4,13 +4,18 @@ * See Documentation/Licenses/GPLv3.txt for more information. */ -#include "Swiften/Elements/Stanza.h" -#include "Swiften/Elements/Delay.h" +#include <Swiften/Elements/Stanza.h> +#include <Swiften/Elements/Delay.h> #include <typeinfo> +#include <Swiften/Base/foreach.h> + namespace Swift { +Stanza::Stanza() { +} + Stanza::~Stanza() { payloads_.clear(); } diff --git a/Swiften/Elements/Stanza.h b/Swiften/Elements/Stanza.h index 9b934e4..9e082cc 100644 --- a/Swiften/Elements/Stanza.h +++ b/Swiften/Elements/Stanza.h @@ -7,27 +7,28 @@ #pragma once #include <vector> +#include <string> #include <boost/shared_ptr.hpp> -#include <boost/optional.hpp> -#include <boost/date_time/posix_time/posix_time.hpp> +#include <boost/optional/optional_fwd.hpp> +#include <boost/date_time/posix_time/ptime.hpp> -#include "Swiften/Elements/Element.h" -#include "Swiften/Elements/Payload.h" -#include <string> -#include "Swiften/Base/foreach.h" -#include "Swiften/JID/JID.h" +#include <Swiften/Elements/Element.h> +#include <Swiften/JID/JID.h> namespace Swift { + class Payload; + class Stanza : public Element { public: typedef boost::shared_ptr<Stanza> ref; + Stanza(); virtual ~Stanza(); template<typename T> boost::shared_ptr<T> getPayload() const { - foreach (const boost::shared_ptr<Payload>& i, payloads_) { - boost::shared_ptr<T> result(boost::dynamic_pointer_cast<T>(i)); + for (size_t i = 0; i < payloads_.size(); ++i) { + boost::shared_ptr<T> result(boost::dynamic_pointer_cast<T>(payloads_[i])); if (result) { return result; } @@ -38,8 +39,8 @@ namespace Swift { template<typename T> std::vector< boost::shared_ptr<T> > getPayloads() const { std::vector< boost::shared_ptr<T> > results; - foreach (const boost::shared_ptr<Payload>& i, payloads_) { - boost::shared_ptr<T> result(boost::dynamic_pointer_cast<T>(i)); + for (size_t i = 0; i < payloads_.size(); ++i) { + boost::shared_ptr<T> result(boost::dynamic_pointer_cast<T>(payloads_[i])); if (result) { results.push_back(result); } @@ -78,8 +79,6 @@ namespace Swift { std::string id_; JID from_; JID to_; - - typedef std::vector< boost::shared_ptr<Payload> > Payloads; - Payloads payloads_; + std::vector< boost::shared_ptr<Payload> > payloads_; }; } diff --git a/Swiften/Elements/StanzaAck.h b/Swiften/Elements/StanzaAck.h index 8a57442..3aa2dfd 100644 --- a/Swiften/Elements/StanzaAck.h +++ b/Swiften/Elements/StanzaAck.h @@ -6,7 +6,7 @@ #pragma once -#include "Swiften/Elements/Element.h" +#include <Swiften/Elements/Element.h> namespace Swift { diff --git a/Swiften/Elements/StanzaAckRequest.h b/Swiften/Elements/StanzaAckRequest.h index 024ebc9..81b3871 100644 --- a/Swiften/Elements/StanzaAckRequest.h +++ b/Swiften/Elements/StanzaAckRequest.h @@ -6,7 +6,7 @@ #pragma once -#include "Swiften/Elements/Element.h" +#include <Swiften/Elements/Element.h> namespace Swift { diff --git a/Swiften/Elements/StartSession.h b/Swiften/Elements/StartSession.h index 0586f40..d7a18c1 100644 --- a/Swiften/Elements/StartSession.h +++ b/Swiften/Elements/StartSession.h @@ -8,7 +8,7 @@ #define SWIFTEN_StartSession_H #include <string> -#include "Swiften/Elements/Payload.h" +#include <Swiften/Elements/Payload.h> namespace Swift { class StartSession : public Payload { diff --git a/Swiften/Elements/StartTLSFailure.h b/Swiften/Elements/StartTLSFailure.h index bb70204..38aace4 100644 --- a/Swiften/Elements/StartTLSFailure.h +++ b/Swiften/Elements/StartTLSFailure.h @@ -7,7 +7,7 @@ #ifndef SWIFTEN_StartTLSFailure_H #define SWIFTEN_StartTLSFailure_H -#include "Swiften/Elements/Element.h" +#include <Swiften/Elements/Element.h> namespace Swift { class StartTLSFailure : public Element { diff --git a/Swiften/Elements/StartTLSRequest.h b/Swiften/Elements/StartTLSRequest.h index 8ce40ec..f4144a7 100644 --- a/Swiften/Elements/StartTLSRequest.h +++ b/Swiften/Elements/StartTLSRequest.h @@ -7,7 +7,7 @@ #ifndef SWIFTEN_StartTLSRequest_H #define SWIFTEN_StartTLSRequest_H -#include "Swiften/Elements/Element.h" +#include <Swiften/Elements/Element.h> namespace Swift { class StartTLSRequest : public Element diff --git a/Swiften/Elements/Status.h b/Swiften/Elements/Status.h index 3ef6401..956f33d 100644 --- a/Swiften/Elements/Status.h +++ b/Swiften/Elements/Status.h @@ -4,10 +4,9 @@ * See Documentation/Licenses/GPLv3.txt for more information. */ -#ifndef SWIFTEN_Status_H -#define SWIFTEN_Status_H +#pragma once -#include "Swiften/Elements/Payload.h" +#include <Swiften/Elements/Payload.h> #include <string> namespace Swift { @@ -28,5 +27,3 @@ namespace Swift { std::string text_; }; } - -#endif diff --git a/Swiften/Elements/StatusShow.cpp b/Swiften/Elements/StatusShow.cpp new file mode 100644 index 0000000..656e5c4 --- /dev/null +++ b/Swiften/Elements/StatusShow.cpp @@ -0,0 +1,12 @@ +/* + * Copyright (c) 2010 Remko Tronçon + * Licensed under the GNU General Public License v3. + * See Documentation/Licenses/GPLv3.txt for more information. + */ + +#include <Swiften/Elements/StatusShow.h> + +using namespace Swift; + +StatusShow::StatusShow(const Type& type) : type_(type) { +} diff --git a/Swiften/Elements/StatusShow.h b/Swiften/Elements/StatusShow.h index a158239..cd3477e 100644 --- a/Swiften/Elements/StatusShow.h +++ b/Swiften/Elements/StatusShow.h @@ -4,19 +4,16 @@ * See Documentation/Licenses/GPLv3.txt for more information. */ -#ifndef SWIFTEN_StatusShow_H -#define SWIFTEN_StatusShow_H +#pragma once -#include "Swiften/Elements/Payload.h" -#include <string> +#include <Swiften/Elements/Payload.h> namespace Swift { class StatusShow : public Payload { public: enum Type { Online, Away, FFC, XA, DND, None }; - StatusShow(const Type& type = Online) : type_(type) { - } + StatusShow(const Type& type = Online); void setType(const Type& type) { type_ = type; @@ -32,19 +29,17 @@ namespace Swift { */ static int typeToAvailabilityOrdering(Type type) { switch (type) { - case Online: return 4; - case FFC: return 5; - case Away: return 2; - case XA: return 1; - case DND: return 3; - case None: return 0; + case Online: return 4; + case FFC: return 5; + case Away: return 2; + case XA: return 1; + case DND: return 3; + case None: return 0; } - return -1; + return 0; } private: Type type_; }; } - -#endif diff --git a/Swiften/Elements/Storage.h b/Swiften/Elements/Storage.h index a2f244c..8118b3b 100644 --- a/Swiften/Elements/Storage.h +++ b/Swiften/Elements/Storage.h @@ -8,9 +8,9 @@ #include <vector> -#include "Swiften/Elements/Payload.h" +#include <Swiften/Elements/Payload.h> #include <string> -#include "Swiften/JID/JID.h" +#include <Swiften/JID/JID.h> namespace Swift { class Storage : public Payload { diff --git a/Swiften/Elements/StreamFeatures.cpp b/Swiften/Elements/StreamFeatures.cpp new file mode 100644 index 0000000..c6f6c04 --- /dev/null +++ b/Swiften/Elements/StreamFeatures.cpp @@ -0,0 +1,21 @@ +/* + * Copyright (c) 2010 Remko Tronçon + * Licensed under the GNU General Public License v3. + * See Documentation/Licenses/GPLv3.txt for more information. + */ + +#include <Swiften/Elements/StreamFeatures.h> + +#include <algorithm> + +namespace Swift { + +bool StreamFeatures::hasCompressionMethod(const std::string& mechanism) const { + return std::find(compressionMethods_.begin(), compressionMethods_.end(), mechanism) != compressionMethods_.end(); +} + +bool StreamFeatures::hasAuthenticationMechanism(const std::string& mechanism) const { + return std::find(authenticationMechanisms_.begin(), authenticationMechanisms_.end(), mechanism) != authenticationMechanisms_.end(); +} + +} diff --git a/Swiften/Elements/StreamFeatures.h b/Swiften/Elements/StreamFeatures.h index fbc0bb8..cae5532 100644 --- a/Swiften/Elements/StreamFeatures.h +++ b/Swiften/Elements/StreamFeatures.h @@ -7,17 +7,17 @@ #pragma once #include <vector> -#include <algorithm> - #include <string> -#include "Swiften/Elements/Element.h" +#include <boost/shared_ptr.hpp> + +#include <Swiften/Elements/Element.h> namespace Swift { class StreamFeatures : public Element { public: typedef boost::shared_ptr<StreamFeatures> ref; - StreamFeatures() : hasStartTLS_(false), hasResourceBind_(false), hasSession_(false), hasStreamManagement_(false) {} + StreamFeatures() : hasStartTLS_(false), hasResourceBind_(false), hasSession_(false), hasStreamManagement_(false), hasRosterVersioning_(false) {} void setHasStartTLS() { hasStartTLS_ = true; @@ -51,9 +51,7 @@ namespace Swift { compressionMethods_.push_back(mechanism); } - bool hasCompressionMethod(const std::string& mechanism) const { - return std::find(compressionMethods_.begin(), compressionMethods_.end(), mechanism) != compressionMethods_.end(); - } + bool hasCompressionMethod(const std::string& mechanism) const; const std::vector<std::string>& getAuthenticationMechanisms() const { return authenticationMechanisms_; @@ -63,9 +61,7 @@ namespace Swift { authenticationMechanisms_.push_back(mechanism); } - bool hasAuthenticationMechanism(const std::string& mechanism) const { - return std::find(authenticationMechanisms_.begin(), authenticationMechanisms_.end(), mechanism) != authenticationMechanisms_.end(); - } + bool hasAuthenticationMechanism(const std::string& mechanism) const; bool hasAuthenticationMechanisms() const { return !authenticationMechanisms_.empty(); @@ -79,6 +75,14 @@ namespace Swift { hasStreamManagement_ = true; } + bool hasRosterVersioning() const { + return hasRosterVersioning_; + } + + void setHasRosterVersioning() { + hasRosterVersioning_ = true; + } + private: bool hasStartTLS_; std::vector<std::string> compressionMethods_; @@ -86,5 +90,6 @@ namespace Swift { bool hasResourceBind_; bool hasSession_; bool hasStreamManagement_; + bool hasRosterVersioning_; }; } diff --git a/Swiften/Elements/StreamInitiation.h b/Swiften/Elements/StreamInitiation.h index 6217cbb..c1f0b4d 100644 --- a/Swiften/Elements/StreamInitiation.h +++ b/Swiften/Elements/StreamInitiation.h @@ -11,7 +11,7 @@ #include <boost/shared_ptr.hpp> #include <string> -#include "Swiften/Elements/Payload.h" +#include <Swiften/Elements/Payload.h> #include <Swiften/Elements/StreamInitiationFileInfo.h> namespace Swift { diff --git a/Swiften/Elements/StreamManagementEnabled.cpp b/Swiften/Elements/StreamManagementEnabled.cpp new file mode 100644 index 0000000..bab7516 --- /dev/null +++ b/Swiften/Elements/StreamManagementEnabled.cpp @@ -0,0 +1,15 @@ +/* + * Copyright (c) 2011 Remko Tronçon + * Licensed under the GNU General Public License v3. + * See Documentation/Licenses/GPLv3.txt for more information. + */ + +#include <Swiften/Elements/StreamManagementEnabled.h> + +using namespace Swift; + +StreamManagementEnabled::StreamManagementEnabled() { +} + +StreamManagementEnabled::~StreamManagementEnabled() { +} diff --git a/Swiften/Elements/StreamManagementEnabled.h b/Swiften/Elements/StreamManagementEnabled.h index 0c72b84..02e77f3 100644 --- a/Swiften/Elements/StreamManagementEnabled.h +++ b/Swiften/Elements/StreamManagementEnabled.h @@ -1,17 +1,39 @@ /* - * Copyright (c) 2010 Remko Tronçon + * Copyright (c) 2010-2011 Remko Tronçon * Licensed under the GNU General Public License v3. * See Documentation/Licenses/GPLv3.txt for more information. */ #pragma once -#include "Swiften/Elements/Element.h" +#include <string> +#include <Swiften/Elements/Element.h> namespace Swift { class StreamManagementEnabled : public Element { public: - StreamManagementEnabled() {} + StreamManagementEnabled(); + ~StreamManagementEnabled(); + + void setResumeSupported() { + resumeSupported = true; + } + + bool getResumeSupported() const { + return resumeSupported; + } + + void setResumeID(const std::string& id) { + resumeID = id; + } + + const std::string& getResumeID() const { + return resumeID; + } + + private: + bool resumeSupported; + std::string resumeID; }; } diff --git a/Swiften/Elements/StreamManagementFailed.h b/Swiften/Elements/StreamManagementFailed.h index 8302c94..7c6d1b7 100644 --- a/Swiften/Elements/StreamManagementFailed.h +++ b/Swiften/Elements/StreamManagementFailed.h @@ -6,7 +6,7 @@ #pragma once -#include "Swiften/Elements/Element.h" +#include <Swiften/Elements/Element.h> namespace Swift { diff --git a/Swiften/Elements/StreamResume.cpp b/Swiften/Elements/StreamResume.cpp new file mode 100644 index 0000000..d55ef78 --- /dev/null +++ b/Swiften/Elements/StreamResume.cpp @@ -0,0 +1,15 @@ +/* + * Copyright (c) 2011 Remko Tronçon + * Licensed under the GNU General Public License v3. + * See Documentation/Licenses/GPLv3.txt for more information. + */ + +#include <Swiften/Elements/StreamResume.h> + +using namespace Swift; + +StreamResume::StreamResume() { +} + +StreamResume::~StreamResume() { +} diff --git a/Swiften/Elements/StreamResume.h b/Swiften/Elements/StreamResume.h new file mode 100644 index 0000000..652182a --- /dev/null +++ b/Swiften/Elements/StreamResume.h @@ -0,0 +1,40 @@ +/* + * Copyright (c) 2011 Remko Tronçon + * Licensed under the GNU General Public License v3. + * See Documentation/Licenses/GPLv3.txt for more information. + */ + +#pragma once + +#include <string> +#include <boost/optional.hpp> + +#include <Swiften/Elements/Element.h> + +namespace Swift { + class StreamResume : public Element { + public: + StreamResume(); + ~StreamResume(); + + void setResumeID(const std::string& id) { + resumeID = id; + } + + const std::string& getResumeID() const { + return resumeID; + } + + const boost::optional<int> getHandledStanzasCount() const { + return handledStanzasCount; + } + + void setHandledStanzasCount(int i) { + handledStanzasCount = i; + } + + private: + std::string resumeID; + boost::optional<int> handledStanzasCount; + }; +} diff --git a/Swiften/Elements/StreamResumed.cpp b/Swiften/Elements/StreamResumed.cpp new file mode 100644 index 0000000..552e654 --- /dev/null +++ b/Swiften/Elements/StreamResumed.cpp @@ -0,0 +1,15 @@ +/* + * Copyright (c) 2011 Remko Tronçon + * Licensed under the GNU General Public License v3. + * See Documentation/Licenses/GPLv3.txt for more information. + */ + +#include <Swiften/Elements/StreamResumed.h> + +using namespace Swift; + +StreamResumed::StreamResumed() { +} + +StreamResumed::~StreamResumed() { +} diff --git a/Swiften/Elements/StreamResumed.h b/Swiften/Elements/StreamResumed.h new file mode 100644 index 0000000..cc42895 --- /dev/null +++ b/Swiften/Elements/StreamResumed.h @@ -0,0 +1,40 @@ +/* + * Copyright (c) 2011 Remko Tronçon + * Licensed under the GNU General Public License v3. + * See Documentation/Licenses/GPLv3.txt for more information. + */ + +#pragma once + +#include <string> +#include <boost/optional.hpp> + +#include <Swiften/Elements/Element.h> + +namespace Swift { + class StreamResumed : public Element { + public: + StreamResumed(); + ~StreamResumed(); + + void setResumeID(const std::string& id) { + resumeID = id; + } + + const std::string& getResumeID() const { + return resumeID; + } + + const boost::optional<int> getHandledStanzasCount() const { + return handledStanzasCount; + } + + void setHandledStanzasCount(int i) { + handledStanzasCount = i; + } + + private: + std::string resumeID; + boost::optional<int> handledStanzasCount; + }; +} diff --git a/Swiften/Elements/Subject.h b/Swiften/Elements/Subject.h index 6b5a916..bc757af 100644 --- a/Swiften/Elements/Subject.h +++ b/Swiften/Elements/Subject.h @@ -6,7 +6,7 @@ #pragma once -#include "Swiften/Elements/Payload.h" +#include <Swiften/Elements/Payload.h> #include <string> namespace Swift { diff --git a/Swiften/Elements/TLSProceed.h b/Swiften/Elements/TLSProceed.h index fbcab04..91f2844 100644 --- a/Swiften/Elements/TLSProceed.h +++ b/Swiften/Elements/TLSProceed.h @@ -7,7 +7,7 @@ #ifndef SWIFTEN_TLSProceed_H #define SWIFTEN_TLSProceed_H -#include "Swiften/Elements/Element.h" +#include <Swiften/Elements/Element.h> namespace Swift { class TLSProceed : public Element diff --git a/Swiften/Elements/UnitTest/FormTest.cpp b/Swiften/Elements/UnitTest/FormTest.cpp index de92d70..1134182 100644 --- a/Swiften/Elements/UnitTest/FormTest.cpp +++ b/Swiften/Elements/UnitTest/FormTest.cpp @@ -8,7 +8,7 @@ #include <cppunit/extensions/TestFactoryRegistry.h> #include <boost/shared_ptr.hpp> -#include "Swiften/Elements/Form.h" +#include <Swiften/Elements/Form.h> using namespace Swift; diff --git a/Swiften/Elements/UnitTest/IQTest.cpp b/Swiften/Elements/UnitTest/IQTest.cpp index c170d61..23255b8 100644 --- a/Swiften/Elements/UnitTest/IQTest.cpp +++ b/Swiften/Elements/UnitTest/IQTest.cpp @@ -8,8 +8,8 @@ #include <cppunit/extensions/TestFactoryRegistry.h> #include <boost/shared_ptr.hpp> -#include "Swiften/Elements/IQ.h" -#include "Swiften/Elements/SoftwareVersion.h" +#include <Swiften/Elements/IQ.h> +#include <Swiften/Elements/SoftwareVersion.h> using namespace Swift; diff --git a/Swiften/Elements/UnitTest/StanzaTest.cpp b/Swiften/Elements/UnitTest/StanzaTest.cpp index 4020f8b..0319b52 100644 --- a/Swiften/Elements/UnitTest/StanzaTest.cpp +++ b/Swiften/Elements/UnitTest/StanzaTest.cpp @@ -7,11 +7,12 @@ #include <cppunit/extensions/HelperMacros.h> #include <cppunit/extensions/TestFactoryRegistry.h> #include <boost/shared_ptr.hpp> +#include <boost/date_time/posix_time/posix_time.hpp> -#include "Swiften/Elements/Stanza.h" -#include "Swiften/Elements/Payload.h" -#include "Swiften/Elements/Message.h" -#include "Swiften/Elements/Delay.h" +#include <Swiften/Elements/Stanza.h> +#include <Swiften/Elements/Payload.h> +#include <Swiften/Elements/Message.h> +#include <Swiften/Elements/Delay.h> using namespace Swift; diff --git a/Swiften/Elements/UnknownElement.h b/Swiften/Elements/UnknownElement.h index 549a922..1b27b88 100644 --- a/Swiften/Elements/UnknownElement.h +++ b/Swiften/Elements/UnknownElement.h @@ -7,7 +7,7 @@ #ifndef SWIFTEN_UnknownElement_H #define SWIFTEN_UnknownElement_H -#include "Swiften/Elements/Element.h" +#include <Swiften/Elements/Element.h> namespace Swift { class UnknownElement : public Element { diff --git a/Swiften/Elements/VCard.cpp b/Swiften/Elements/VCard.cpp index 8262e07..4f7700e 100644 --- a/Swiften/Elements/VCard.cpp +++ b/Swiften/Elements/VCard.cpp @@ -4,9 +4,9 @@ * See Documentation/Licenses/GPLv3.txt for more information. */ -#include "Swiften/Elements/VCard.h" +#include <Swiften/Elements/VCard.h> -#include "Swiften/Base/foreach.h" +#include <Swiften/Base/foreach.h> namespace Swift { diff --git a/Swiften/Elements/VCard.h b/Swiften/Elements/VCard.h index d2423e1..cb05056 100644 --- a/Swiften/Elements/VCard.h +++ b/Swiften/Elements/VCard.h @@ -9,8 +9,8 @@ #include <boost/shared_ptr.hpp> #include <string> -#include "Swiften/Base/ByteArray.h" -#include "Swiften/Elements/Payload.h" +#include <Swiften/Base/ByteArray.h> +#include <Swiften/Elements/Payload.h> namespace Swift { class VCard : public Payload { diff --git a/Swiften/Elements/VCardUpdate.h b/Swiften/Elements/VCardUpdate.h index bbfd31e..e225a4a 100644 --- a/Swiften/Elements/VCardUpdate.h +++ b/Swiften/Elements/VCardUpdate.h @@ -7,7 +7,7 @@ #pragma once #include <string> -#include "Swiften/Elements/Payload.h" +#include <Swiften/Elements/Payload.h> namespace Swift { class VCardUpdate : public Payload { diff --git a/Swiften/Elements/Version.h b/Swiften/Elements/Version.h index 0a65573..a7be325 100644 --- a/Swiften/Elements/Version.h +++ b/Swiften/Elements/Version.h @@ -8,7 +8,7 @@ #define SWIFTEN_STANZAS_VERSION_H #include <string> -#include "Swiften/Elements/Payload.h" +#include <Swiften/Elements/Payload.h> namespace Swift { class Version : public Payload diff --git a/Swiften/Entity/Entity.cpp b/Swiften/Entity/Entity.cpp index da2ecaf..44f9fbf 100644 --- a/Swiften/Entity/Entity.cpp +++ b/Swiften/Entity/Entity.cpp @@ -4,28 +4,47 @@ * See Documentation/Licenses/GPLv3.txt for more information. */ -#include "Swiften/Entity/Entity.h" +#include <Swiften/Entity/Entity.h> + +#include <Swiften/Parser/PayloadParsers/FullPayloadParserFactoryCollection.h> +#include <Swiften/Serializer/PayloadSerializers/FullPayloadSerializerCollection.h> + namespace Swift { +Entity::Entity() { + payloadParserFactories = new FullPayloadParserFactoryCollection(); + payloadSerializers = new FullPayloadSerializerCollection(); +} + Entity::~Entity() { + delete payloadSerializers; + delete payloadParserFactories; } void Entity::addPayloadParserFactory(PayloadParserFactory* payloadParserFactory) { - payloadParserFactories.addFactory(payloadParserFactory); + payloadParserFactories->addFactory(payloadParserFactory); } void Entity::removePayloadParserFactory(PayloadParserFactory* payloadParserFactory) { - payloadParserFactories.removeFactory(payloadParserFactory); + payloadParserFactories->removeFactory(payloadParserFactory); } void Entity::addPayloadSerializer(PayloadSerializer* payloadSerializer) { - payloadSerializers.addSerializer(payloadSerializer); + payloadSerializers->addSerializer(payloadSerializer); } void Entity::removePayloadSerializer(PayloadSerializer* payloadSerializer) { - payloadSerializers.removeSerializer(payloadSerializer); + payloadSerializers->removeSerializer(payloadSerializer); +} + +PayloadParserFactoryCollection* Entity::getPayloadParserFactories() { + return payloadParserFactories; +} + +PayloadSerializerCollection* Entity::getPayloadSerializers() { + return payloadSerializers; } } diff --git a/Swiften/Entity/Entity.h b/Swiften/Entity/Entity.h index 20d02ba..65480d0 100644 --- a/Swiften/Entity/Entity.h +++ b/Swiften/Entity/Entity.h @@ -6,21 +6,20 @@ #pragma once -#include <Swiften/Base/boost_bsignals.h> -#include <boost/shared_ptr.hpp> - -#include "Swiften/Parser/PayloadParsers/FullPayloadParserFactoryCollection.h" -#include "Swiften/Serializer/PayloadSerializers/FullPayloadSerializerCollection.h" - namespace Swift { class PayloadParserFactory; class PayloadSerializer; + class FullPayloadParserFactoryCollection; + class FullPayloadSerializerCollection; + class PayloadParserFactoryCollection; + class PayloadSerializerCollection; /** * The base class for XMPP entities (Clients, Components). */ class Entity { public: + Entity(); virtual ~Entity(); void addPayloadParserFactory(PayloadParserFactory* payloadParserFactory); @@ -30,16 +29,11 @@ namespace Swift { void removePayloadSerializer(PayloadSerializer* payloadSerializer); protected: - PayloadParserFactoryCollection* getPayloadParserFactories() { - return &payloadParserFactories; - } - - PayloadSerializerCollection* getPayloadSerializers() { - return &payloadSerializers; - } + PayloadParserFactoryCollection* getPayloadParserFactories(); + PayloadSerializerCollection* getPayloadSerializers(); private: - FullPayloadParserFactoryCollection payloadParserFactories; - FullPayloadSerializerCollection payloadSerializers; + FullPayloadParserFactoryCollection* payloadParserFactories; + FullPayloadSerializerCollection* payloadSerializers; }; } diff --git a/Swiften/Entity/GenericPayloadPersister.h b/Swiften/Entity/GenericPayloadPersister.h new file mode 100644 index 0000000..63553de --- /dev/null +++ b/Swiften/Entity/GenericPayloadPersister.h @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2011 Remko Tronçon + * Licensed under the GNU General Public License v3. + * See Documentation/Licenses/GPLv3.txt for more information. + */ + +#pragma once + +#include <Swiften/Entity/PayloadPersister.h> +#include <Swiften/Parser/GenericPayloadParserFactory.h> + +namespace Swift { + template<typename PAYLOAD, typename PARSER, typename SERIALIZER> + class GenericPayloadPersister : public PayloadPersister { + public: + GenericPayloadPersister() { + } + + public: + boost::shared_ptr<PAYLOAD> loadPayloadGeneric(const boost::filesystem::path& path) { + return boost::dynamic_pointer_cast<PAYLOAD>(loadPayload(path)); + } + + protected: + virtual const PayloadSerializer* getSerializer() const { + return &serializer; + } + + virtual PayloadParser* createParser() const { + return new PARSER(); + } + + private: + SERIALIZER serializer; + }; +} diff --git a/Swiften/Entity/PayloadPersister.cpp b/Swiften/Entity/PayloadPersister.cpp new file mode 100644 index 0000000..f7278cc --- /dev/null +++ b/Swiften/Entity/PayloadPersister.cpp @@ -0,0 +1,53 @@ +/* + * Copyright (c) 2011 Remko Tronçon + * Licensed under the GNU General Public License v3. + * See Documentation/Licenses/GPLv3.txt for more information. + */ + +#include <Swiften/Entity/PayloadPersister.h> + +#include <boost/filesystem/fstream.hpp> +#include <boost/filesystem.hpp> +#include <iostream> + +#include <Swiften/Parser/PayloadParsers/UnitTest/PayloadParserTester.h> +#include <Swiften/Base/ByteArray.h> +#include <Swiften/Parser/PayloadParser.h> +#include <Swiften/Parser/PayloadParserFactory.h> +#include <Swiften/Serializer/PayloadSerializer.h> + +using namespace Swift; + +PayloadPersister::PayloadPersister() { +} + +PayloadPersister::~PayloadPersister() { +} + +void PayloadPersister::savePayload(boost::shared_ptr<Payload> payload, const boost::filesystem::path& path) { + if (!boost::filesystem::exists(path.parent_path())) { + try { + boost::filesystem::create_directories(path.parent_path()); + } + catch (const boost::filesystem::filesystem_error& e) { + std::cerr << "ERROR: " << e.what() << std::endl; + } + } + boost::filesystem::ofstream file(path); + file << getSerializer()->serialize(payload); + file.close(); +} + +boost::shared_ptr<Payload> PayloadPersister::loadPayload(const boost::filesystem::path& path) { + if (boost::filesystem::exists(path)) { + ByteArray data; + data.readFromFile(path.string()); + std::auto_ptr<PayloadParser> parser(createParser()); + PayloadParserTester tester(parser.get()); + tester.parse(data.toString()); + return parser->getPayload(); + } + else { + return boost::shared_ptr<Payload>(); + } +} diff --git a/Swiften/Entity/PayloadPersister.h b/Swiften/Entity/PayloadPersister.h new file mode 100644 index 0000000..ea7c74c --- /dev/null +++ b/Swiften/Entity/PayloadPersister.h @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2011 Remko Tronçon + * Licensed under the GNU General Public License v3. + * See Documentation/Licenses/GPLv3.txt for more information. + */ + +#pragma once + +#include <boost/shared_ptr.hpp> +#include <boost/filesystem/path.hpp> + +namespace Swift { + class Payload; + class PayloadSerializer; + class PayloadParser; + + class PayloadPersister { + public: + PayloadPersister(); + virtual ~PayloadPersister(); + + void savePayload(boost::shared_ptr<Payload>, const boost::filesystem::path&); + boost::shared_ptr<Payload> loadPayload(const boost::filesystem::path&); + + protected: + + virtual const PayloadSerializer* getSerializer() const = 0; + virtual PayloadParser* createParser() const = 0; + }; +} diff --git a/Swiften/EventLoop/Cocoa/CocoaEvent.mm b/Swiften/EventLoop/Cocoa/CocoaEvent.mm index 8a90983..049e3b6 100644 --- a/Swiften/EventLoop/Cocoa/CocoaEvent.mm +++ b/Swiften/EventLoop/Cocoa/CocoaEvent.mm @@ -1,6 +1,6 @@ -#include "Swiften/EventLoop/Cocoa/CocoaEvent.h" -#include "Swiften/EventLoop/Event.h" -#include "Swiften/EventLoop/Cocoa/CocoaEventLoop.h" +#include <Swiften/EventLoop/Cocoa/CocoaEvent.h> +#include <Swiften/EventLoop/Event.h> +#include <Swiften/EventLoop/Cocoa/CocoaEventLoop.h> @implementation CocoaEvent diff --git a/Swiften/EventLoop/Cocoa/CocoaEventLoop.h b/Swiften/EventLoop/Cocoa/CocoaEventLoop.h index 2b60741..60ef32b 100644 --- a/Swiften/EventLoop/Cocoa/CocoaEventLoop.h +++ b/Swiften/EventLoop/Cocoa/CocoaEventLoop.h @@ -6,7 +6,7 @@ #pragma once -#include "Swiften/EventLoop/EventLoop.h" +#include <Swiften/EventLoop/EventLoop.h> namespace Swift { class CocoaEventLoop : public EventLoop { diff --git a/Swiften/EventLoop/Cocoa/CocoaEventLoop.mm b/Swiften/EventLoop/Cocoa/CocoaEventLoop.mm index b90f3c6..ba73884 100644 --- a/Swiften/EventLoop/Cocoa/CocoaEventLoop.mm +++ b/Swiften/EventLoop/Cocoa/CocoaEventLoop.mm @@ -1,5 +1,5 @@ -#include "Swiften/EventLoop/Cocoa/CocoaEventLoop.h" -#include "Swiften/EventLoop/Cocoa/CocoaEvent.h" +#include <Swiften/EventLoop/Cocoa/CocoaEventLoop.h> +#include <Swiften/EventLoop/Cocoa/CocoaEvent.h> #pragma GCC diagnostic ignored "-Wold-style-cast" diff --git a/Swiften/EventLoop/DummyEventLoop.cpp b/Swiften/EventLoop/DummyEventLoop.cpp new file mode 100644 index 0000000..3741eec --- /dev/null +++ b/Swiften/EventLoop/DummyEventLoop.cpp @@ -0,0 +1,24 @@ +/* + * Copyright (c) 2010 Remko Tronçon + * Licensed under the GNU General Public License v3. + * See Documentation/Licenses/GPLv3.txt for more information. + */ + +#include <Swiften/EventLoop/DummyEventLoop.h> + +#include <iostream> + +namespace Swift { + +DummyEventLoop::DummyEventLoop() { +} + +DummyEventLoop::~DummyEventLoop() { + if (!events_.empty()) { + std::cerr << "DummyEventLoop: Unhandled events at destruction time" << std::endl; + } + events_.clear(); +} + + +} diff --git a/Swiften/EventLoop/DummyEventLoop.h b/Swiften/EventLoop/DummyEventLoop.h index b7ef516..f814ed9 100644 --- a/Swiften/EventLoop/DummyEventLoop.h +++ b/Swiften/EventLoop/DummyEventLoop.h @@ -7,24 +7,14 @@ #pragma once #include <deque> -#include <iostream> -#include <boost/function.hpp> -#include "Swiften/EventLoop/EventLoop.h" -#include "Swiften/Base/foreach.h" +#include <Swiften/EventLoop/EventLoop.h> namespace Swift { class DummyEventLoop : public EventLoop { public: - DummyEventLoop() { - } - - ~DummyEventLoop() { - if (!events_.empty()) { - std::cerr << "DummyEventLoop: Unhandled events at destruction time" << std::endl; - } - events_.clear(); - } + DummyEventLoop(); + ~DummyEventLoop(); void processEvents() { while (!events_.empty()) { diff --git a/Swiften/EventLoop/Event.h b/Swiften/EventLoop/Event.h index 6f5a9e5..b1d7cac 100644 --- a/Swiften/EventLoop/Event.h +++ b/Swiften/EventLoop/Event.h @@ -9,7 +9,7 @@ #include <boost/shared_ptr.hpp> #include <boost/function.hpp> -#include "Swiften/EventLoop/EventOwner.h" +#include <Swiften/EventLoop/EventOwner.h> namespace Swift { class Event { diff --git a/Swiften/EventLoop/EventLoop.cpp b/Swiften/EventLoop/EventLoop.cpp index 56bb6ac..2b8f00d 100644 --- a/Swiften/EventLoop/EventLoop.cpp +++ b/Swiften/EventLoop/EventLoop.cpp @@ -4,11 +4,12 @@ * See Documentation/Licenses/GPLv3.txt for more information. */ -#include "Swiften/EventLoop/EventLoop.h" +#include <Swiften/EventLoop/EventLoop.h> #include <algorithm> #include <boost/bind.hpp> #include <iostream> +#include <cassert> #include <Swiften/Base/Log.h> @@ -17,6 +18,7 @@ namespace Swift { inline void invokeCallback(const Event& event) { try { + assert(!event.callback.empty()); event.callback(); } catch (const std::exception& e) { diff --git a/Swiften/EventLoop/EventLoop.h b/Swiften/EventLoop/EventLoop.h index ab58ffc..69ec68e 100644 --- a/Swiften/EventLoop/EventLoop.h +++ b/Swiften/EventLoop/EventLoop.h @@ -11,7 +11,7 @@ #include <list> #include <deque> -#include "Swiften/EventLoop/Event.h" +#include <Swiften/EventLoop/Event.h> namespace Swift { class EventOwner; diff --git a/Swiften/EventLoop/EventOwner.cpp b/Swiften/EventLoop/EventOwner.cpp index 275f1d1..9970499 100644 --- a/Swiften/EventLoop/EventOwner.cpp +++ b/Swiften/EventLoop/EventOwner.cpp @@ -4,7 +4,7 @@ * See Documentation/Licenses/GPLv3.txt for more information. */ -#include "Swiften/EventLoop/EventOwner.h" +#include <Swiften/EventLoop/EventOwner.h> namespace Swift { diff --git a/Swiften/EventLoop/Qt/QtEventLoop.h b/Swiften/EventLoop/Qt/QtEventLoop.h index 8f6c709..0097cf9 100644 --- a/Swiften/EventLoop/Qt/QtEventLoop.h +++ b/Swiften/EventLoop/Qt/QtEventLoop.h @@ -10,7 +10,7 @@ #include <QEvent> #include <QCoreApplication> -#include "Swiften/EventLoop/EventLoop.h" +#include <Swiften/EventLoop/EventLoop.h> namespace Swift { class QtEventLoop : public QObject, public EventLoop { diff --git a/Swiften/EventLoop/SConscript b/Swiften/EventLoop/SConscript index 21ae8b9..e448f43 100644 --- a/Swiften/EventLoop/SConscript +++ b/Swiften/EventLoop/SConscript @@ -5,6 +5,7 @@ sources = [ "EventOwner.cpp", "Event.cpp", "SimpleEventLoop.cpp", + "DummyEventLoop.cpp", ] objects = swiften_env.SwiftenObject(sources) diff --git a/Swiften/EventLoop/SimpleEventLoop.cpp b/Swiften/EventLoop/SimpleEventLoop.cpp index b77639c..74fea01 100644 --- a/Swiften/EventLoop/SimpleEventLoop.cpp +++ b/Swiften/EventLoop/SimpleEventLoop.cpp @@ -4,12 +4,12 @@ * See Documentation/Licenses/GPLv3.txt for more information. */ -#include "Swiften/EventLoop/SimpleEventLoop.h" +#include <Swiften/EventLoop/SimpleEventLoop.h> #include <boost/bind.hpp> #include <iostream> -#include "Swiften/Base/foreach.h" +#include <Swiften/Base/foreach.h> namespace Swift { diff --git a/Swiften/EventLoop/SimpleEventLoop.h b/Swiften/EventLoop/SimpleEventLoop.h index 6fb3f53..72bd6a6 100644 --- a/Swiften/EventLoop/SimpleEventLoop.h +++ b/Swiften/EventLoop/SimpleEventLoop.h @@ -11,7 +11,7 @@ #include <boost/thread/mutex.hpp> #include <boost/thread/condition_variable.hpp> -#include "Swiften/EventLoop/EventLoop.h" +#include <Swiften/EventLoop/EventLoop.h> namespace Swift { class SimpleEventLoop : public EventLoop { diff --git a/Swiften/EventLoop/UnitTest/EventLoopTest.cpp b/Swiften/EventLoop/UnitTest/EventLoopTest.cpp index b777c1b..58396e6 100644 --- a/Swiften/EventLoop/UnitTest/EventLoopTest.cpp +++ b/Swiften/EventLoop/UnitTest/EventLoopTest.cpp @@ -9,10 +9,10 @@ #include <boost/thread.hpp> #include <boost/bind.hpp> -#include "Swiften/EventLoop/EventOwner.h" -#include "Swiften/EventLoop/SimpleEventLoop.h" -#include "Swiften/EventLoop/DummyEventLoop.h" -#include "Swiften/Base/sleep.h" +#include <Swiften/EventLoop/EventOwner.h> +#include <Swiften/EventLoop/SimpleEventLoop.h> +#include <Swiften/EventLoop/DummyEventLoop.h> +#include <Swiften/Base/sleep.h> using namespace Swift; diff --git a/Swiften/EventLoop/UnitTest/SimpleEventLoopTest.cpp b/Swiften/EventLoop/UnitTest/SimpleEventLoopTest.cpp index b779bed..475b6b5 100644 --- a/Swiften/EventLoop/UnitTest/SimpleEventLoopTest.cpp +++ b/Swiften/EventLoop/UnitTest/SimpleEventLoopTest.cpp @@ -9,8 +9,8 @@ #include <boost/thread.hpp> #include <boost/bind.hpp> -#include "Swiften/EventLoop/SimpleEventLoop.h" -#include "Swiften/Base/sleep.h" +#include <Swiften/EventLoop/SimpleEventLoop.h> +#include <Swiften/Base/sleep.h> using namespace Swift; diff --git a/Swiften/Examples/BenchTool/BenchTool.cpp b/Swiften/Examples/BenchTool/BenchTool.cpp index 9e54ed9..a440148 100644 --- a/Swiften/Examples/BenchTool/BenchTool.cpp +++ b/Swiften/Examples/BenchTool/BenchTool.cpp @@ -6,14 +6,15 @@ #include <boost/bind.hpp> #include <boost/thread.hpp> +#include <iostream> -#include "Swiften/Client/Client.h" -#include "Swiften/Network/TimerFactory.h" -#include "Swiften/Network/BoostNetworkFactories.h" -#include "Swiften/EventLoop/EventLoop.h" -#include "Swiften/EventLoop/SimpleEventLoop.h" -#include "Swiften/Roster/GetRosterRequest.h" -#include "Swiften/Client/ClientXMLTracer.h" +#include <Swiften/Client/Client.h> +#include <Swiften/Network/TimerFactory.h> +#include <Swiften/Network/BoostNetworkFactories.h> +#include <Swiften/EventLoop/EventLoop.h> +#include <Swiften/EventLoop/SimpleEventLoop.h> +#include <Swiften/Roster/GetRosterRequest.h> +#include <Swiften/Client/ClientXMLTracer.h> #include <Swiften/Base/sleep.h> #include <Swiften/TLS/BlindCertificateTrustChecker.h> diff --git a/Swiften/Examples/ConnectivityTest/ConnectivityTest.cpp b/Swiften/Examples/ConnectivityTest/ConnectivityTest.cpp index fda203a..3564433 100644 --- a/Swiften/Examples/ConnectivityTest/ConnectivityTest.cpp +++ b/Swiften/Examples/ConnectivityTest/ConnectivityTest.cpp @@ -6,15 +6,16 @@ #include <boost/bind.hpp> #include <boost/thread.hpp> - -#include "Swiften/Client/Client.h" -#include "Swiften/Network/Timer.h" -#include "Swiften/Network/TimerFactory.h" -#include "Swiften/Network/BoostNetworkFactories.h" -#include "Swiften/EventLoop/EventLoop.h" -#include "Swiften/Client/ClientXMLTracer.h" -#include "Swiften/EventLoop/SimpleEventLoop.h" -#include "Swiften/Disco/GetDiscoInfoRequest.h" +#include <iostream> + +#include <Swiften/Client/Client.h> +#include <Swiften/Network/Timer.h> +#include <Swiften/Network/TimerFactory.h> +#include <Swiften/Network/BoostNetworkFactories.h> +#include <Swiften/EventLoop/EventLoop.h> +#include <Swiften/Client/ClientXMLTracer.h> +#include <Swiften/EventLoop/SimpleEventLoop.h> +#include <Swiften/Disco/GetDiscoInfoRequest.h> using namespace Swift; diff --git a/Swiften/Examples/LinkLocalTool/main.cpp b/Swiften/Examples/LinkLocalTool/main.cpp index d63ef53..18e282b 100644 --- a/Swiften/Examples/LinkLocalTool/main.cpp +++ b/Swiften/Examples/LinkLocalTool/main.cpp @@ -8,11 +8,11 @@ #include <iostream> -#include "Swiften/EventLoop/SimpleEventLoop.h" -#include "Swiften/LinkLocal/DNSSD/PlatformDNSSDQuerierFactory.h" -#include "Swiften/LinkLocal/DNSSD/DNSSDQuerier.h" -#include "Swiften/LinkLocal/DNSSD/DNSSDBrowseQuery.h" -#include "Swiften/LinkLocal/DNSSD/DNSSDResolveServiceQuery.h" +#include <Swiften/EventLoop/SimpleEventLoop.h> +#include <Swiften/LinkLocal/DNSSD/PlatformDNSSDQuerierFactory.h> +#include <Swiften/LinkLocal/DNSSD/DNSSDQuerier.h> +#include <Swiften/LinkLocal/DNSSD/DNSSDBrowseQuery.h> +#include <Swiften/LinkLocal/DNSSD/DNSSDResolveServiceQuery.h> using namespace Swift; diff --git a/Swiften/Examples/ParserTester/ParserTester.cpp b/Swiften/Examples/ParserTester/ParserTester.cpp index 61c0eae..211d44f 100644 --- a/Swiften/Examples/ParserTester/ParserTester.cpp +++ b/Swiften/Examples/ParserTester/ParserTester.cpp @@ -8,10 +8,10 @@ #include <fstream> #include <typeinfo> -#include "Swiften/Parser/UnitTest/ParserTester.h" -#include "Swiften/Parser/XMPPParser.h" -#include "Swiften/Parser/XMPPParserClient.h" -#include "Swiften/Parser/PayloadParsers/FullPayloadParserFactoryCollection.h" +#include <Swiften/Parser/UnitTest/ParserTester.h> +#include <Swiften/Parser/XMPPParser.h> +#include <Swiften/Parser/XMPPParserClient.h> +#include <Swiften/Parser/PayloadParsers/FullPayloadParserFactoryCollection.h> using namespace Swift; diff --git a/Swiften/Examples/SendFile/ReceiveFile.cpp b/Swiften/Examples/SendFile/ReceiveFile.cpp index b46d790..effa1b7 100644 --- a/Swiften/Examples/SendFile/ReceiveFile.cpp +++ b/Swiften/Examples/SendFile/ReceiveFile.cpp @@ -7,7 +7,10 @@ #include <boost/bind.hpp> #include <boost/filesystem.hpp> #include <boost/smart_ptr/make_shared.hpp> +#include <iostream> +#include <Swiften/Elements/Presence.h> +#include <Swiften/Base/foreach.h> #include <Swiften/Client/Client.h> #include <Swiften/Network/BoostNetworkFactories.h> #include <Swiften/EventLoop/SimpleEventLoop.h> diff --git a/Swiften/Examples/SendFile/SendFile.cpp b/Swiften/Examples/SendFile/SendFile.cpp index 5ec00a9..205b442 100644 --- a/Swiften/Examples/SendFile/SendFile.cpp +++ b/Swiften/Examples/SendFile/SendFile.cpp @@ -6,18 +6,20 @@ #include <boost/bind.hpp> #include <boost/filesystem.hpp> - -#include "Swiften/Client/Client.h" -#include "Swiften/Network/BoostTimer.h" -#include "Swiften/Network/TimerFactory.h" -#include "Swiften/Network/BoostNetworkFactories.h" -#include "Swiften/EventLoop/EventLoop.h" -#include "Swiften/Client/ClientXMLTracer.h" -#include "Swiften/EventLoop/SimpleEventLoop.h" -#include "Swiften/FileTransfer/OutgoingFileTransfer.h" -#include "Swiften/FileTransfer/FileReadBytestream.h" -#include "Swiften/FileTransfer/SOCKS5BytestreamServer.h" -#include "Swiften/Network/BoostConnectionServer.h" +#include <iostream> + +#include <Swiften/Client/Client.h> +#include <Swiften/Elements/Presence.h> +#include <Swiften/Network/BoostTimer.h> +#include <Swiften/Network/TimerFactory.h> +#include <Swiften/Network/BoostNetworkFactories.h> +#include <Swiften/EventLoop/EventLoop.h> +#include <Swiften/Client/ClientXMLTracer.h> +#include <Swiften/EventLoop/SimpleEventLoop.h> +#include <Swiften/FileTransfer/OutgoingSIFileTransfer.h> +#include <Swiften/FileTransfer/FileReadBytestream.h> +#include <Swiften/FileTransfer/SOCKS5BytestreamServer.h> +#include <Swiften/Network/BoostConnectionServer.h> using namespace Swift; @@ -64,7 +66,7 @@ class FileSender { private: void handleConnected() { client->sendPresence(Presence::create()); - transfer = new OutgoingFileTransfer("myid", client->getJID(), recipient, file.filename(), boost::filesystem::file_size(file), "A file", boost::shared_ptr<FileReadBytestream>(new FileReadBytestream(file)), client->getIQRouter(), socksBytestreamServer); + transfer = new OutgoingSIFileTransfer("myid", client->getJID(), recipient, file.filename(), boost::filesystem::file_size(file), "A file", boost::shared_ptr<FileReadBytestream>(new FileReadBytestream(file)), client->getIQRouter(), socksBytestreamServer); transfer->onFinished.connect(boost::bind(&FileSender::handleFileTransferFinished, this, _1)); transfer->start(); } @@ -99,7 +101,7 @@ class FileSender { boost::filesystem::path file; Client* client; ClientXMLTracer* tracer; - OutgoingFileTransfer* transfer; + OutgoingSIFileTransfer* transfer; }; diff --git a/Swiften/Examples/SendMessage/SendMessage.cpp b/Swiften/Examples/SendMessage/SendMessage.cpp index d7f7333..f4dbf53 100644 --- a/Swiften/Examples/SendMessage/SendMessage.cpp +++ b/Swiften/Examples/SendMessage/SendMessage.cpp @@ -6,13 +6,15 @@ #include <boost/bind.hpp> #include <boost/thread.hpp> - -#include "Swiften/Client/Client.h" -#include "Swiften/Network/BoostNetworkFactories.h" -#include "Swiften/Network/TimerFactory.h" -#include "Swiften/EventLoop/EventLoop.h" -#include "Swiften/Client/ClientXMLTracer.h" -#include "Swiften/EventLoop/SimpleEventLoop.h" +#include <iostream> + +#include <Swiften/Client/Client.h> +#include <Swiften/Elements/Message.h> +#include <Swiften/Network/BoostNetworkFactories.h> +#include <Swiften/Network/TimerFactory.h> +#include <Swiften/EventLoop/EventLoop.h> +#include <Swiften/Client/ClientXMLTracer.h> +#include <Swiften/EventLoop/SimpleEventLoop.h> using namespace Swift; diff --git a/Swiften/FileTransfer/ByteArrayReadBytestream.h b/Swiften/FileTransfer/ByteArrayReadBytestream.h index d459658..4704db6 100644 --- a/Swiften/FileTransfer/ByteArrayReadBytestream.h +++ b/Swiften/FileTransfer/ByteArrayReadBytestream.h @@ -6,31 +6,32 @@ #pragma once -#include "Swiften/FileTransfer/ReadBytestream.h" -#include "Swiften/Base/ByteArray.h" +#include <vector> + +#include <Swiften/FileTransfer/ReadBytestream.h> namespace Swift { class ByteArrayReadBytestream : public ReadBytestream { public: - ByteArrayReadBytestream(const ByteArray& data) : data(data), position(0) { + ByteArrayReadBytestream(const std::vector<unsigned char>& data) : data(data), position(0) { } - virtual ByteArray read(size_t size) { + virtual std::vector<unsigned char> read(size_t size) { size_t readSize = size; - if (position + readSize > data.getSize()) { - readSize = data.getSize() - position; + if (position + readSize > data.size()) { + readSize = data.size() - position; } - ByteArray result(data.getData() + position, readSize); + std::vector<unsigned char> result(data.begin() + position, data.begin() + position + readSize); position += readSize; return result; } virtual bool isFinished() const { - return position >= data.getSize(); + return position >= data.size(); } private: - ByteArray data; + std::vector<unsigned char> data; size_t position; }; } diff --git a/Swiften/FileTransfer/ByteArrayWriteBytestream.h b/Swiften/FileTransfer/ByteArrayWriteBytestream.h new file mode 100644 index 0000000..6c360e6 --- /dev/null +++ b/Swiften/FileTransfer/ByteArrayWriteBytestream.h @@ -0,0 +1,28 @@ +/* + * Copyright (c) 2010 Remko Tronçon + * Licensed under the GNU General Public License v3. + * See Documentation/Licenses/GPLv3.txt for more information. + */ + +#pragma once + +#include <Swiften/FileTransfer/WriteBytestream.h> + +namespace Swift { + class ByteArrayWriteBytestream : public WriteBytestream { + public: + ByteArrayWriteBytestream() { + } + + virtual void write(const std::vector<unsigned char>& bytes) { + data.insert(data.end(), bytes.begin(), bytes.end()); + } + + const std::vector<unsigned char>& getData() const { + return data; + } + + private: + std::vector<unsigned char> data; + }; +} diff --git a/Swiften/FileTransfer/BytestreamsRequest.h b/Swiften/FileTransfer/BytestreamsRequest.h index 9757bfa..0e97b5c 100644 --- a/Swiften/FileTransfer/BytestreamsRequest.h +++ b/Swiften/FileTransfer/BytestreamsRequest.h @@ -8,8 +8,8 @@ #include <boost/shared_ptr.hpp> -#include "Swiften/Queries/GenericRequest.h" -#include "Swiften/Elements/Bytestreams.h" +#include <Swiften/Queries/GenericRequest.h> +#include <Swiften/Elements/Bytestreams.h> namespace Swift { class BytestreamsRequest : public GenericRequest<Bytestreams> { diff --git a/Swiften/FileTransfer/FileReadBytestream.cpp b/Swiften/FileTransfer/FileReadBytestream.cpp index c08747b..84d6490 100644 --- a/Swiften/FileTransfer/FileReadBytestream.cpp +++ b/Swiften/FileTransfer/FileReadBytestream.cpp @@ -7,7 +7,7 @@ #include <boost/filesystem/fstream.hpp> #include <cassert> -#include "Swiften/FileTransfer/FileReadBytestream.h" +#include <Swiften/FileTransfer/FileReadBytestream.h> namespace Swift { @@ -21,14 +21,14 @@ FileReadBytestream::~FileReadBytestream() { } } -ByteArray FileReadBytestream::read(size_t size) { +std::vector<unsigned char> FileReadBytestream::read(size_t size) { if (!stream) { stream = new boost::filesystem::ifstream(file, std::ios_base::in|std::ios_base::binary); } - ByteArray result; + std::vector<unsigned char> result; result.resize(size); assert(stream->good()); - stream->read(reinterpret_cast<char*>(result.getData()), size); + stream->read(reinterpret_cast<char*>(&result[0]), size); result.resize(stream->gcount()); return result; } diff --git a/Swiften/FileTransfer/FileReadBytestream.h b/Swiften/FileTransfer/FileReadBytestream.h index 055e194..bb24879 100644 --- a/Swiften/FileTransfer/FileReadBytestream.h +++ b/Swiften/FileTransfer/FileReadBytestream.h @@ -6,10 +6,10 @@ #pragma once -#include <boost/filesystem.hpp> +#include <boost/filesystem/path.hpp> #include <boost/filesystem/fstream.hpp> -#include "Swiften/FileTransfer/ReadBytestream.h" +#include <Swiften/FileTransfer/ReadBytestream.h> namespace Swift { class FileReadBytestream : public ReadBytestream { @@ -17,7 +17,7 @@ namespace Swift { FileReadBytestream(const boost::filesystem::path& file); ~FileReadBytestream(); - virtual ByteArray read(size_t size) ; + virtual std::vector<unsigned char> read(size_t size); virtual bool isFinished() const; private: diff --git a/Swiften/FileTransfer/FileWriteBytestream.cpp b/Swiften/FileTransfer/FileWriteBytestream.cpp index 4d29bd1..c38338a 100644 --- a/Swiften/FileTransfer/FileWriteBytestream.cpp +++ b/Swiften/FileTransfer/FileWriteBytestream.cpp @@ -7,7 +7,7 @@ #include <boost/filesystem/fstream.hpp> #include <cassert> -#include "Swiften/FileTransfer/FileWriteBytestream.h" +#include <Swiften/FileTransfer/FileWriteBytestream.h> namespace Swift { @@ -21,12 +21,12 @@ FileWriteBytestream::~FileWriteBytestream() { } } -void FileWriteBytestream::write(const ByteArray& data) { +void FileWriteBytestream::write(const std::vector<unsigned char>& data) { if (!stream) { stream = new boost::filesystem::ofstream(file, std::ios_base::out|std::ios_base::binary); } assert(stream->good()); - stream->write(reinterpret_cast<const char*>(data.getData()), data.getSize()); + stream->write(reinterpret_cast<const char*>(&data[0]), data.size()); } } diff --git a/Swiften/FileTransfer/FileWriteBytestream.h b/Swiften/FileTransfer/FileWriteBytestream.h index c6f7b39..8cfa718 100644 --- a/Swiften/FileTransfer/FileWriteBytestream.h +++ b/Swiften/FileTransfer/FileWriteBytestream.h @@ -6,10 +6,10 @@ #pragma once -#include <boost/filesystem.hpp> +#include <boost/filesystem/path.hpp> #include <boost/filesystem/fstream.hpp> -#include "Swiften/FileTransfer/WriteBytestream.h" +#include <Swiften/FileTransfer/WriteBytestream.h> namespace Swift { class FileWriteBytestream : public WriteBytestream { @@ -17,7 +17,7 @@ namespace Swift { FileWriteBytestream(const boost::filesystem::path& file); ~FileWriteBytestream(); - virtual void write(const ByteArray&); + virtual void write(const std::vector<unsigned char>&); private: boost::filesystem::path file; diff --git a/Swiften/FileTransfer/IBBReceiveSession.cpp b/Swiften/FileTransfer/IBBReceiveSession.cpp index 5c90757..566dcca 100644 --- a/Swiften/FileTransfer/IBBReceiveSession.cpp +++ b/Swiften/FileTransfer/IBBReceiveSession.cpp @@ -4,31 +4,96 @@ * See Documentation/Licenses/GPLv3.txt for more information. */ -#include "Swiften/FileTransfer/IBBReceiveSession.h" +#include <Swiften/FileTransfer/IBBReceiveSession.h> #include <boost/bind.hpp> -#include "Swiften/Queries/IQRouter.h" -#include "Swiften/FileTransfer/IBBRequest.h" -#include "Swiften/FileTransfer/BytestreamException.h" +#include <Swiften/Base/Log.h> +#include <Swiften/Queries/IQRouter.h> +#include <Swiften/FileTransfer/IBBRequest.h> +#include <Swiften/FileTransfer/BytestreamException.h> +#include <Swiften/Queries/SetResponder.h> namespace Swift { -IBBReceiveSession::IBBReceiveSession(const std::string& id, const JID& from, size_t size, WriteBytestream::ref bytestream, IQRouter* router) : SetResponder<IBB>(router), id(id), from(from), size(size), bytestream(bytestream), router(router), sequenceNumber(0), active(false), receivedSize(0) { +class IBBReceiveSession::IBBResponder : public SetResponder<IBB> { + public: + IBBResponder(IBBReceiveSession* session, IQRouter* router) : SetResponder<IBB>(router), session(session), sequenceNumber(0), receivedSize(0) { + } + + virtual bool handleSetRequest(const JID& from, const JID&, const std::string& id, IBB::ref ibb) { + if (from == session->from && ibb->getStreamID() == session->id) { + if (ibb->getAction() == IBB::Data) { + if (sequenceNumber == ibb->getSequenceNumber()) { + session->onDataReceived(ibb->getData()); + receivedSize += ibb->getData().size(); + sequenceNumber++; + sendResponse(from, id, IBB::ref()); + if (receivedSize >= session->size) { + if (receivedSize > session->size) { + std::cerr << "Warning: Received more data than expected" << std::endl; + } + session->finish(boost::optional<FileTransferError>()); + } + } + else { + SWIFT_LOG(warning) << "Received data out of order" << std::endl; + sendError(from, id, ErrorPayload::NotAcceptable, ErrorPayload::Cancel); + session->finish(FileTransferError(FileTransferError::ClosedError)); + } + } + else if (ibb->getAction() == IBB::Open) { + sendResponse(from, id, IBB::ref()); + } + else if (ibb->getAction() == IBB::Close) { + sendResponse(from, id, IBB::ref()); + session->finish(FileTransferError(FileTransferError::ClosedError)); + } + return true; + } + return false; + } + + private: + IBBReceiveSession* session; + int sequenceNumber; + size_t receivedSize; +}; + + +IBBReceiveSession::IBBReceiveSession( + const std::string& id, + const JID& from, + size_t size, + IQRouter* router) : + id(id), + from(from), + size(size), + router(router), + active(false) { + responder = new IBBResponder(this, router); } IBBReceiveSession::~IBBReceiveSession() { + if (active) { + SWIFT_LOG(warning) << "Session still active" << std::endl; + } + delete responder; } void IBBReceiveSession::start() { active = true; + responder->start(); } void IBBReceiveSession::stop() { - if (active && router->isAvailable()) { - IBBRequest::create(from, IBB::createIBBClose(id), router)->send(); + responder->stop(); + if (active) { + if (router->isAvailable()) { + IBBRequest::create(from, IBB::createIBBClose(id), router)->send(); + } + finish(boost::optional<FileTransferError>()); } - finish(boost::optional<FileTransferError>()); } void IBBReceiveSession::finish(boost::optional<FileTransferError> error) { @@ -36,34 +101,4 @@ void IBBReceiveSession::finish(boost::optional<FileTransferError> error) { onFinished(error); } -bool IBBReceiveSession::handleSetRequest(const JID& from, const JID&, const std::string& id, IBB::ref ibb) { - if (from == this->from && ibb->getStreamID() == id) { - if (ibb->getAction() == IBB::Data) { - if (sequenceNumber == ibb->getSequenceNumber()) { - bytestream->write(ibb->getData()); - receivedSize += ibb->getData().getSize(); - if (receivedSize >= size) { - if (receivedSize > size) { - std::cerr << "Warning: Received more data than expected" << std::endl; - } - finish(boost::optional<FileTransferError>()); - } - } - else { - sendError(from, id, ErrorPayload::NotAcceptable, ErrorPayload::Cancel); - finish(FileTransferError(FileTransferError::ClosedError)); - } - } - else if (ibb->getAction() == IBB::Open) { - sendResponse(from, id, IBB::ref()); - } - else if (ibb->getAction() == IBB::Close) { - sendResponse(from, id, IBB::ref()); - finish(FileTransferError(FileTransferError::ClosedError)); - } - return true; - } - return false; -} - } diff --git a/Swiften/FileTransfer/IBBReceiveSession.h b/Swiften/FileTransfer/IBBReceiveSession.h index 6d936de..02d5ab8 100644 --- a/Swiften/FileTransfer/IBBReceiveSession.h +++ b/Swiften/FileTransfer/IBBReceiveSession.h @@ -7,27 +7,30 @@ #pragma once #include <boost/shared_ptr.hpp> -#include <boost/optional.hpp> +#include <boost/optional/optional_fwd.hpp> -#include "Swiften/Base/boost_bsignals.h" -#include "Swiften/FileTransfer/WriteBytestream.h" -#include "Swiften/JID/JID.h" -#include "Swiften/Elements/IBB.h" -#include "Swiften/Elements/ErrorPayload.h" -#include "Swiften/FileTransfer/FileTransferError.h" -#include "Swiften/Queries/SetResponder.h" +#include <Swiften/Base/boost_bsignals.h> +#include <Swiften/FileTransfer/WriteBytestream.h> +#include <Swiften/JID/JID.h> +#include <Swiften/Elements/IBB.h> +#include <Swiften/FileTransfer/FileTransferError.h> namespace Swift { class IQRouter; - class IBBReceiveSession : public SetResponder<IBB> { + class IBBReceiveSession { public: - IBBReceiveSession(const std::string& id, const JID& from, size_t size, WriteBytestream::ref bytestream, IQRouter* router); + IBBReceiveSession( + const std::string& id, + const JID& from, + size_t size, + IQRouter* router); ~IBBReceiveSession(); void start(); void stop(); + boost::signal<void (const std::vector<unsigned char>&)> onDataReceived; boost::signal<void (boost::optional<FileTransferError>)> onFinished; private: @@ -35,13 +38,14 @@ namespace Swift { void finish(boost::optional<FileTransferError>); private: + class IBBResponder; + friend class IBBResponder; + std::string id; JID from; size_t size; - WriteBytestream::ref bytestream; IQRouter* router; - int sequenceNumber; + IBBResponder* responder; bool active; - size_t receivedSize; }; } diff --git a/Swiften/FileTransfer/IBBRequest.h b/Swiften/FileTransfer/IBBRequest.h index f104277..828027c 100644 --- a/Swiften/FileTransfer/IBBRequest.h +++ b/Swiften/FileTransfer/IBBRequest.h @@ -6,8 +6,8 @@ #pragma once -#include "Swiften/Queries/GenericRequest.h" -#include "Swiften/Elements/IBB.h" +#include <Swiften/Queries/GenericRequest.h> +#include <Swiften/Elements/IBB.h> namespace Swift { diff --git a/Swiften/FileTransfer/IBBSendSession.cpp b/Swiften/FileTransfer/IBBSendSession.cpp index 0fb47d3..5376276 100644 --- a/Swiften/FileTransfer/IBBSendSession.cpp +++ b/Swiften/FileTransfer/IBBSendSession.cpp @@ -4,13 +4,13 @@ * See Documentation/Licenses/GPLv3.txt for more information. */ -#include "Swiften/FileTransfer/IBBSendSession.h" +#include <Swiften/FileTransfer/IBBSendSession.h> #include <boost/bind.hpp> -#include "Swiften/Queries/IQRouter.h" -#include "Swiften/FileTransfer/IBBRequest.h" -#include "Swiften/FileTransfer/BytestreamException.h" +#include <Swiften/Queries/IQRouter.h> +#include <Swiften/FileTransfer/IBBRequest.h> +#include <Swiften/FileTransfer/BytestreamException.h> namespace Swift { @@ -38,13 +38,13 @@ void IBBSendSession::handleIBBResponse(IBB::ref, ErrorPayload::ref error) { if (!error) { if (!bytestream->isFinished()) { try { - ByteArray data = bytestream->read(blockSize); + std::vector<unsigned char> data = bytestream->read(blockSize); IBBRequest::ref request = IBBRequest::create(to, IBB::createIBBData(id, sequenceNumber, data), router); sequenceNumber++; request->onResponse.connect(boost::bind(&IBBSendSession::handleIBBResponse, this, _1, _2)); request->send(); } - catch (const BytestreamException& e) { + catch (const BytestreamException&) { finish(FileTransferError(FileTransferError::ReadError)); } } diff --git a/Swiften/FileTransfer/IBBSendSession.h b/Swiften/FileTransfer/IBBSendSession.h index bef7bec..6c741cf 100644 --- a/Swiften/FileTransfer/IBBSendSession.h +++ b/Swiften/FileTransfer/IBBSendSession.h @@ -9,12 +9,12 @@ #include <boost/shared_ptr.hpp> #include <boost/optional.hpp> -#include "Swiften/Base/boost_bsignals.h" -#include "Swiften/FileTransfer/ReadBytestream.h" -#include "Swiften/JID/JID.h" -#include "Swiften/Elements/IBB.h" -#include "Swiften/Elements/ErrorPayload.h" -#include "Swiften/FileTransfer/FileTransferError.h" +#include <Swiften/Base/boost_bsignals.h> +#include <Swiften/FileTransfer/ReadBytestream.h> +#include <Swiften/JID/JID.h> +#include <Swiften/Elements/IBB.h> +#include <Swiften/Elements/ErrorPayload.h> +#include <Swiften/FileTransfer/FileTransferError.h> namespace Swift { class IQRouter; diff --git a/Swiften/FileTransfer/IncomingFileTransfer.cpp b/Swiften/FileTransfer/IncomingFileTransfer.cpp index 238ccce..7c97e4d 100644 --- a/Swiften/FileTransfer/IncomingFileTransfer.cpp +++ b/Swiften/FileTransfer/IncomingFileTransfer.cpp @@ -4,20 +4,11 @@ * See Documentation/Licenses/GPLv3.txt for more information. */ -#include "Swiften/FileTransfer/IncomingFileTransfer.h" +#include <Swiften/FileTransfer/IncomingFileTransfer.h> namespace Swift { IncomingFileTransfer::~IncomingFileTransfer() { - -} - -/*void IncomingFileTransfer::accept(WriteBytestream::ref) { - } -void IncomingFileTransfer::stop() { - -}*/ - } diff --git a/Swiften/FileTransfer/IncomingFileTransfer.h b/Swiften/FileTransfer/IncomingFileTransfer.h index 4286ef0..1ccd76c 100644 --- a/Swiften/FileTransfer/IncomingFileTransfer.h +++ b/Swiften/FileTransfer/IncomingFileTransfer.h @@ -8,8 +8,8 @@ #include <boost/shared_ptr.hpp> -#include "Swiften/Base/boost_bsignals.h" -#include "Swiften/FileTransfer/WriteBytestream.h" +#include <Swiften/Base/boost_bsignals.h> +#include <Swiften/FileTransfer/WriteBytestream.h> namespace Swift { class IncomingFileTransfer { diff --git a/Swiften/FileTransfer/IncomingFileTransferManager.cpp b/Swiften/FileTransfer/IncomingFileTransferManager.cpp index 5535840..79d2391 100644 --- a/Swiften/FileTransfer/IncomingFileTransferManager.cpp +++ b/Swiften/FileTransfer/IncomingFileTransferManager.cpp @@ -10,8 +10,10 @@ #include <Swiften/Elements/JingleDescription.h> #include <Swiften/Elements/JingleFileTransferDescription.h> -#include <Swiften/Elements/JingleIBBTransport.h> +#include <Swiften/Elements/JingleIBBTransportPayload.h> +#include <Swiften/Elements/JingleS5BTransportPayload.h> #include <Swiften/Jingle/JingleSessionManager.h> +#include <Swiften/Jingle/Jingle.h> #include <Swiften/FileTransfer/IncomingJingleFileTransfer.h> namespace Swift { @@ -24,12 +26,12 @@ IncomingFileTransferManager::~IncomingFileTransferManager() { jingleSessionManager->removeIncomingSessionHandler(this); } -bool IncomingFileTransferManager::handleIncomingJingleSession(IncomingJingleSession::ref session) { - JingleContent::ref content = session->getContentWithDescription<JingleFileTransferDescription>(); - if (content) { - // Check for supported transports - if (content->getTransport<JingleIBBTransport>()) { - IncomingJingleFileTransfer::ref transfer = boost::make_shared<IncomingJingleFileTransfer>(session); +bool IncomingFileTransferManager::handleIncomingJingleSession(JingleSession::ref session, const std::vector<JingleContentPayload::ref>& contents) { + if (JingleContentPayload::ref content = Jingle::getContentWithDescription<JingleFileTransferDescription>(contents)) { + if (content->getTransport<JingleIBBTransportPayload>() || content->getTransport<JingleS5BTransportPayload>()) { + RemoteJingleTransportCandidateSelectorFactory* a; + LocalJingleTransportCandidateGeneratorFactory* b; + IncomingJingleFileTransfer::ref transfer = boost::make_shared<IncomingJingleFileTransfer>(session, content, a, b, router); onIncomingFileTransfer(transfer); } else { diff --git a/Swiften/FileTransfer/IncomingFileTransferManager.h b/Swiften/FileTransfer/IncomingFileTransferManager.h index a54b5cd..428a838 100644 --- a/Swiften/FileTransfer/IncomingFileTransferManager.h +++ b/Swiften/FileTransfer/IncomingFileTransferManager.h @@ -15,6 +15,8 @@ namespace Swift { class IQRouter; class JingleSessionManager; + class RemoteJingleTransportCandidateSelectorFactory; + class LocalJingleTransportCandidateGeneratorFactory; class IncomingFileTransferManager : public IncomingJingleSessionHandler { public: @@ -24,7 +26,7 @@ namespace Swift { boost::signal<void (IncomingFileTransfer::ref)> onIncomingFileTransfer; private: - bool handleIncomingJingleSession(IncomingJingleSession::ref session); + bool handleIncomingJingleSession(JingleSession::ref session, const std::vector<JingleContentPayload::ref>& contents); private: JingleSessionManager* jingleSessionManager; diff --git a/Swiften/FileTransfer/IncomingJingleFileTransfer.cpp b/Swiften/FileTransfer/IncomingJingleFileTransfer.cpp index cb2f65c..904b53e 100644 --- a/Swiften/FileTransfer/IncomingJingleFileTransfer.cpp +++ b/Swiften/FileTransfer/IncomingJingleFileTransfer.cpp @@ -6,14 +6,164 @@ #include <Swiften/FileTransfer/IncomingJingleFileTransfer.h> +#include <boost/bind.hpp> +#include <boost/smart_ptr/make_shared.hpp> + +#include <Swiften/FileTransfer/RemoteJingleTransportCandidateSelectorFactory.h> +#include <Swiften/FileTransfer/LocalJingleTransportCandidateGeneratorFactory.h> +#include <Swiften/FileTransfer/JingleIncomingIBBTransport.h> +#include <Swiften/Elements/JingleIBBTransportPayload.h> +#include <Swiften/Elements/JingleS5BTransportPayload.h> +#include <Swiften/FileTransfer/RemoteJingleTransportCandidateSelector.h> +#include <Swiften/FileTransfer/LocalJingleTransportCandidateGenerator.h> + namespace Swift { -IncomingJingleFileTransfer::IncomingJingleFileTransfer(IncomingJingleSession::ref session) : session(session) { +IncomingJingleFileTransfer::IncomingJingleFileTransfer( + JingleSession::ref session, + JingleContentPayload::ref content, + RemoteJingleTransportCandidateSelectorFactory* candidateSelectorFactory, + LocalJingleTransportCandidateGeneratorFactory* candidateGeneratorFactory, + IQRouter* router) : + session(session), + router(router), + initialContent(content), + contentID(content->getName(), content->getCreator()), + state(Initial), + remoteTransportCandidateSelectFinished(false), + localTransportCandidateSelectFinished(false) { + + candidateSelector = candidateSelectorFactory->createCandidateSelector(); + candidateSelector->onRemoteTransportCandidateSelectFinished.connect(boost::bind(&IncomingJingleFileTransfer::handleRemoteTransportCandidateSelectFinished, this, _1)); + + candidateGenerator = candidateGeneratorFactory->createCandidateGenerator(); + candidateGenerator->onLocalTransportCandidatesGenerated.connect(boost::bind(&IncomingJingleFileTransfer::handleLocalTransportCandidatesGenerated, this, _1)); + + session->onTransportInfoReceived.connect(boost::bind(&IncomingJingleFileTransfer::handleTransportInfoReceived, this, _1, _2)); + session->onTransportReplaceReceived.connect(boost::bind(&IncomingJingleFileTransfer::handleTransportReplaceReceived, this, _1, _2)); + session->onSessionTerminateReceived.connect(boost::bind(&IncomingJingleFileTransfer::handleSessionTerminateReceived, this)); + + description = initialContent->getDescription<JingleFileTransferDescription>(); + assert(description); +} + +IncomingJingleFileTransfer::~IncomingJingleFileTransfer() { + session->onSessionTerminateReceived.disconnect(boost::bind(&IncomingJingleFileTransfer::handleSessionTerminateReceived, this)); + session->onTransportReplaceReceived.disconnect(boost::bind(&IncomingJingleFileTransfer::handleTransportReplaceReceived, this, _1, _2)); + session->onTransportInfoReceived.disconnect(boost::bind(&IncomingJingleFileTransfer::handleTransportInfoReceived, this, _1, _2)); + + candidateGenerator->onLocalTransportCandidatesGenerated.disconnect(boost::bind(&IncomingJingleFileTransfer::handleLocalTransportCandidatesGenerated, this, _1)); + delete candidateGenerator; + candidateSelector->onRemoteTransportCandidateSelectFinished.disconnect(boost::bind(&IncomingJingleFileTransfer::handleRemoteTransportCandidateSelectFinished, this, _1)); + delete candidateSelector; } void IncomingJingleFileTransfer::accept(WriteBytestream::ref stream) { + assert(!stream); this->stream = stream; + + if (JingleIBBTransportPayload::ref ibbTransport = initialContent->getTransport<JingleIBBTransportPayload>()) { + setActiveTransport(createIBBTransport(ibbTransport)); + session->accept(); + } + else if (JingleS5BTransportPayload::ref s5bTransport = initialContent->getTransport<JingleS5BTransportPayload>()) { + state = CreatingInitialTransports; + candidateSelector->addRemoteTransportCandidates(s5bTransport); + candidateGenerator->generateLocalTransportCandidates(); + } + else { + assert(false); + } +} + + +void IncomingJingleFileTransfer::handleLocalTransportCandidatesGenerated(JingleTransportPayload::ref candidates) { + if (state == CreatingInitialTransports) { + if (!candidates) { + localTransportCandidateSelectFinished = true; + } + session->accept(candidates); + state = NegotiatingTransport; + candidateSelector->selectCandidate(); + } +} + + +void IncomingJingleFileTransfer::handleRemoteTransportCandidateSelectFinished(JingleTransportPayload::ref transport) { + remoteTransportCandidateSelectFinished = true; + selectedRemoteTransportCandidate = transport; + session->sendTransportInfo(contentID, transport); + checkCandidateSelected(); +} + +void IncomingJingleFileTransfer::checkCandidateSelected() { + if (localTransportCandidateSelectFinished && remoteTransportCandidateSelectFinished) { + if (candidateGenerator->isActualCandidate(selectedLocalTransportCandidate) && candidateSelector->isActualCandidate(selectedRemoteTransportCandidate)) { + if (candidateGenerator->getPriority(selectedLocalTransportCandidate) > candidateSelector->getPriority(selectedRemoteTransportCandidate)) { + setActiveTransport(candidateGenerator->selectTransport(selectedLocalTransportCandidate)); + } + else { + setActiveTransport(candidateSelector->selectTransport(selectedRemoteTransportCandidate)); + } + } + else if (candidateSelector->isActualCandidate(selectedRemoteTransportCandidate)) { + setActiveTransport(candidateSelector->selectTransport(selectedRemoteTransportCandidate)); + } + else if (candidateGenerator->isActualCandidate(selectedLocalTransportCandidate)) { + setActiveTransport(candidateGenerator->selectTransport(selectedLocalTransportCandidate)); + } + else { + state = WaitingForFallbackOrTerminate; + } + } +} + +void IncomingJingleFileTransfer::setActiveTransport(JingleTransport::ref transport) { + state = Transferring; + activeTransport = transport; + activeTransport->onDataReceived.connect(boost::bind(&IncomingJingleFileTransfer::handleTransportDataReceived, this, _1)); + activeTransport->start(); +} + +void IncomingJingleFileTransfer::handleSessionTerminateReceived() { + // TODO + state = Terminated; +} + +void IncomingJingleFileTransfer::handleTransportDataReceived(const std::vector<unsigned char>& data) { + stream->write(data); +} + + +void IncomingJingleFileTransfer::handleTransportInfoReceived(const JingleContentID&, JingleTransportPayload::ref transport) { + localTransportCandidateSelectFinished = true; + selectedLocalTransportCandidate = transport; + if (candidateGenerator->isActualCandidate(transport)) { + candidateSelector->setMinimumPriority(candidateGenerator->getPriority(transport)); + } + checkCandidateSelected(); +} + +void IncomingJingleFileTransfer::handleTransportReplaceReceived(const JingleContentID& content, JingleTransportPayload::ref transport) { + if (JingleIBBTransportPayload::ref ibbTransport = boost::dynamic_pointer_cast<JingleIBBTransportPayload>(transport)) { + setActiveTransport(createIBBTransport(ibbTransport)); + session->acceptTransport(content, transport); + } + else { + session->rejectTransport(content, transport); + } +} + +void IncomingJingleFileTransfer::stopActiveTransport() { + if (activeTransport) { + activeTransport->stop(); + activeTransport->onDataReceived.disconnect(boost::bind(&IncomingJingleFileTransfer::handleTransportDataReceived, this, _1)); + } +} + +JingleIncomingIBBTransport::ref IncomingJingleFileTransfer::createIBBTransport(JingleIBBTransportPayload::ref ibbTransport) { + return boost::make_shared<JingleIncomingIBBTransport>(session->getInitiator(), ibbTransport->getSessionID(), description->getOffer()->size, router); } } diff --git a/Swiften/FileTransfer/IncomingJingleFileTransfer.h b/Swiften/FileTransfer/IncomingJingleFileTransfer.h index d69449e..164d868 100644 --- a/Swiften/FileTransfer/IncomingJingleFileTransfer.h +++ b/Swiften/FileTransfer/IncomingJingleFileTransfer.h @@ -8,20 +8,71 @@ #include <boost/shared_ptr.hpp> -#include <Swiften/Jingle/IncomingJingleSession.h> +#include <Swiften/Jingle/JingleSession.h> +#include <Swiften/Jingle/JingleContentID.h> #include <Swiften/FileTransfer/IncomingFileTransfer.h> +#include <Swiften/FileTransfer/JingleTransport.h> +#include <Swiften/FileTransfer/JingleIncomingIBBTransport.h> +#include <Swiften/Elements/JingleContentPayload.h> +#include <Swiften/Elements/JingleFileTransferDescription.h> +#include <Swiften/Elements/JingleIBBTransportPayload.h> namespace Swift { + class IQRouter; + class RemoteJingleTransportCandidateSelectorFactory; + class LocalJingleTransportCandidateGeneratorFactory; + class RemoteJingleTransportCandidateSelector; + class LocalJingleTransportCandidateGenerator; + class IncomingJingleFileTransfer : public IncomingFileTransfer { public: typedef boost::shared_ptr<IncomingJingleFileTransfer> ref; + enum State { + Initial, + CreatingInitialTransports, + NegotiatingTransport, + Transferring, + WaitingForFallbackOrTerminate, + Terminated + }; - IncomingJingleFileTransfer(IncomingJingleSession::ref session); + IncomingJingleFileTransfer( + JingleSession::ref, + JingleContentPayload::ref content, + RemoteJingleTransportCandidateSelectorFactory*, + LocalJingleTransportCandidateGeneratorFactory*, + IQRouter* router); + ~IncomingJingleFileTransfer(); virtual void accept(WriteBytestream::ref); private: - IncomingJingleSession::ref session; + void handleSessionTerminateReceived(); + void handleTransportReplaceReceived(const JingleContentID&, JingleTransportPayload::ref); + void handleTransportInfoReceived(const JingleContentID&, JingleTransportPayload::ref); + void handleLocalTransportCandidatesGenerated(JingleTransportPayload::ref candidates); + void handleRemoteTransportCandidateSelectFinished(JingleTransportPayload::ref candidate); + void setActiveTransport(JingleTransport::ref transport); + void handleTransportDataReceived(const std::vector<unsigned char>& data); + void stopActiveTransport(); + void checkCandidateSelected(); + JingleIncomingIBBTransport::ref createIBBTransport(JingleIBBTransportPayload::ref ibbTransport); + + private: + JingleSession::ref session; + IQRouter* router; + JingleContentPayload::ref initialContent; + JingleContentID contentID; + State state; + JingleFileTransferDescription::ref description; WriteBytestream::ref stream; + RemoteJingleTransportCandidateSelector* candidateSelector; + LocalJingleTransportCandidateGenerator* candidateGenerator; + bool remoteTransportCandidateSelectFinished; + JingleTransportPayload::ref selectedRemoteTransportCandidate; + bool localTransportCandidateSelectFinished; + JingleTransportPayload::ref selectedLocalTransportCandidate; + + JingleTransport::ref activeTransport; }; } diff --git a/Swiften/FileTransfer/JingleIncomingIBBTransport.cpp b/Swiften/FileTransfer/JingleIncomingIBBTransport.cpp new file mode 100644 index 0000000..0ca899f --- /dev/null +++ b/Swiften/FileTransfer/JingleIncomingIBBTransport.cpp @@ -0,0 +1,23 @@ +/* + * Copyright (c) 2011 Remko Tronçon + * Licensed under the GNU General Public License v3. + * See Documentation/Licenses/GPLv3.txt for more information. + */ + +#include <Swiften/FileTransfer/JingleIncomingIBBTransport.h> + +namespace Swift { + +JingleIncomingIBBTransport::JingleIncomingIBBTransport(const JID& from, const std::string& id, size_t size, IQRouter* router) : ibbSession(from, id, size, router) { + ibbSession.onDataReceived.connect(boost::ref(onDataReceived)); +} + +void JingleIncomingIBBTransport::start() { + ibbSession.start(); +} + +void JingleIncomingIBBTransport::stop() { + ibbSession.stop(); +} + +} diff --git a/Swiften/FileTransfer/JingleIncomingIBBTransport.h b/Swiften/FileTransfer/JingleIncomingIBBTransport.h new file mode 100644 index 0000000..e2fa485 --- /dev/null +++ b/Swiften/FileTransfer/JingleIncomingIBBTransport.h @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2011 Remko Tronçon + * Licensed under the GNU General Public License v3. + * See Documentation/Licenses/GPLv3.txt for more information. + */ + +#pragma once + +#include <boost/shared_ptr.hpp> + +#include <Swiften/FileTransfer/JingleTransport.h> +#include <Swiften/FileTransfer/IBBReceiveSession.h> + +namespace Swift { + class JingleIncomingIBBTransport : public JingleTransport { + public: + typedef boost::shared_ptr<JingleIncomingIBBTransport> ref; + + JingleIncomingIBBTransport(const JID& from, const std::string& id, size_t size, IQRouter* router); + + virtual void start(); + virtual void stop(); + + private: + IBBReceiveSession ibbSession; + }; +} diff --git a/Swiften/FileTransfer/JingleTransport.cpp b/Swiften/FileTransfer/JingleTransport.cpp new file mode 100644 index 0000000..c507922 --- /dev/null +++ b/Swiften/FileTransfer/JingleTransport.cpp @@ -0,0 +1,15 @@ +/* + * Copyright (c) 2011 Remko Tronçon + * Licensed under the GNU General Public License v3. + * See Documentation/Licenses/GPLv3.txt for more information. + */ + +#include <Swiften/FileTransfer/JingleTransport.h> + +namespace Swift { + +JingleTransport::~JingleTransport() { + +} + +} diff --git a/Swiften/FileTransfer/JingleTransport.h b/Swiften/FileTransfer/JingleTransport.h new file mode 100644 index 0000000..1d163d0 --- /dev/null +++ b/Swiften/FileTransfer/JingleTransport.h @@ -0,0 +1,25 @@ +/* + * Copyright (c) 2011 Remko Tronçon + * Licensed under the GNU General Public License v3. + * See Documentation/Licenses/GPLv3.txt for more information. + */ + +#pragma once + +#include <boost/shared_ptr.hpp> + +#include <Swiften/Base/boost_bsignals.h> + +namespace Swift { + class JingleTransport { + public: + typedef boost::shared_ptr<JingleTransport> ref; + + virtual ~JingleTransport(); + + virtual void start() = 0; + virtual void stop() = 0; + + boost::signal<void (const std::vector<unsigned char>&)> onDataReceived; + }; +} diff --git a/Swiften/FileTransfer/LocalJingleTransportCandidateGenerator.cpp b/Swiften/FileTransfer/LocalJingleTransportCandidateGenerator.cpp new file mode 100644 index 0000000..852902b --- /dev/null +++ b/Swiften/FileTransfer/LocalJingleTransportCandidateGenerator.cpp @@ -0,0 +1,14 @@ +/* + * Copyright (c) 2011 Remko Tronçon + * Licensed under the GNU General Public License v3. + * See Documentation/Licenses/GPLv3.txt for more information. + */ + +#include <Swiften/FileTransfer/LocalJingleTransportCandidateGenerator.h> + +namespace Swift { + +LocalJingleTransportCandidateGenerator::~LocalJingleTransportCandidateGenerator() { +} + +} diff --git a/Swiften/FileTransfer/LocalJingleTransportCandidateGenerator.h b/Swiften/FileTransfer/LocalJingleTransportCandidateGenerator.h new file mode 100644 index 0000000..c111005 --- /dev/null +++ b/Swiften/FileTransfer/LocalJingleTransportCandidateGenerator.h @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2011 Remko Tronçon + * Licensed under the GNU General Public License v3. + * See Documentation/Licenses/GPLv3.txt for more information. + */ + +#pragma once + +#include <Swiften/Base/boost_bsignals.h> + +#include <Swiften/Elements/JingleTransportPayload.h> +#include <Swiften/FileTransfer/JingleTransport.h> + +namespace Swift { + class LocalJingleTransportCandidateGenerator { + public: + virtual ~LocalJingleTransportCandidateGenerator(); + + virtual void generateLocalTransportCandidates() = 0; + + virtual bool isActualCandidate(JingleTransportPayload::ref) = 0; + virtual int getPriority(JingleTransportPayload::ref) = 0; + virtual JingleTransport::ref selectTransport(JingleTransportPayload::ref) = 0; + + boost::signal<void (JingleTransportPayload::ref)> onLocalTransportCandidatesGenerated; + }; +} diff --git a/Swiften/FileTransfer/LocalJingleTransportCandidateGeneratorFactory.cpp b/Swiften/FileTransfer/LocalJingleTransportCandidateGeneratorFactory.cpp new file mode 100644 index 0000000..a1e3874 --- /dev/null +++ b/Swiften/FileTransfer/LocalJingleTransportCandidateGeneratorFactory.cpp @@ -0,0 +1,14 @@ +/* + * Copyright (c) 2011 Remko Tronçon + * Licensed under the GNU General Public License v3. + * See Documentation/Licenses/GPLv3.txt for more information. + */ + +#include <Swiften/FileTransfer/LocalJingleTransportCandidateGeneratorFactory.h> + +namespace Swift { + +LocalJingleTransportCandidateGeneratorFactory::~LocalJingleTransportCandidateGeneratorFactory() { +} + +} diff --git a/Swiften/FileTransfer/LocalJingleTransportCandidateGeneratorFactory.h b/Swiften/FileTransfer/LocalJingleTransportCandidateGeneratorFactory.h new file mode 100644 index 0000000..c969fc7 --- /dev/null +++ b/Swiften/FileTransfer/LocalJingleTransportCandidateGeneratorFactory.h @@ -0,0 +1,18 @@ +/* + * Copyright (c) 2011 Remko Tronçon + * Licensed under the GNU General Public License v3. + * See Documentation/Licenses/GPLv3.txt for more information. + */ + +#pragma once + +namespace Swift { + class LocalJingleTransportCandidateGenerator; + + class LocalJingleTransportCandidateGeneratorFactory { + public: + virtual ~LocalJingleTransportCandidateGeneratorFactory(); + + virtual LocalJingleTransportCandidateGenerator* createCandidateGenerator() = 0; + }; +} diff --git a/Swiften/FileTransfer/OutgoingFileTransfer.cpp b/Swiften/FileTransfer/OutgoingFileTransfer.cpp index 32f7e17..94d4348 100644 --- a/Swiften/FileTransfer/OutgoingFileTransfer.cpp +++ b/Swiften/FileTransfer/OutgoingFileTransfer.cpp @@ -4,75 +4,11 @@ * See Documentation/Licenses/GPLv3.txt for more information. */ -#include "Swiften/FileTransfer/OutgoingFileTransfer.h" - -#include <boost/bind.hpp> - -#include "Swiften/FileTransfer/StreamInitiationRequest.h" -#include "Swiften/FileTransfer/BytestreamsRequest.h" -#include "Swiften/FileTransfer/SOCKS5BytestreamServer.h" -#include "Swiften/FileTransfer/IBBSendSession.h" +#include <Swiften/FileTransfer/OutgoingFileTransfer.h> namespace Swift { -OutgoingFileTransfer::OutgoingFileTransfer(const std::string& id, const JID& from, const JID& to, const std::string& name, int size, const std::string& description, boost::shared_ptr<ReadBytestream> bytestream, IQRouter* iqRouter, SOCKS5BytestreamServer* socksServer) : id(id), from(from), to(to), name(name), size(size), description(description), bytestream(bytestream), iqRouter(iqRouter), socksServer(socksServer) { -} - -void OutgoingFileTransfer::start() { - StreamInitiation::ref streamInitiation(new StreamInitiation()); - streamInitiation->setID(id); - streamInitiation->setFileInfo(StreamInitiationFileInfo(name, description, size)); - //streamInitiation->addProvidedMethod("http://jabber.org/protocol/bytestreams"); - streamInitiation->addProvidedMethod("http://jabber.org/protocol/ibb"); - StreamInitiationRequest::ref request = StreamInitiationRequest::create(to, streamInitiation, iqRouter); - request->onResponse.connect(boost::bind(&OutgoingFileTransfer::handleStreamInitiationRequestResponse, this, _1, _2)); - request->send(); -} - -void OutgoingFileTransfer::stop() { -} - -void OutgoingFileTransfer::handleStreamInitiationRequestResponse(StreamInitiation::ref response, ErrorPayload::ref error) { - if (error) { - finish(FileTransferError()); - } - else { - if (response->getRequestedMethod() == "http://jabber.org/protocol/bytestreams") { - socksServer->addBytestream(id, from, to, bytestream); - Bytestreams::ref bytestreams(new Bytestreams()); - bytestreams->setStreamID(id); - HostAddressPort addressPort = socksServer->getAddressPort(); - bytestreams->addStreamHost(Bytestreams::StreamHost(addressPort.getAddress().toString(), from, addressPort.getPort())); - BytestreamsRequest::ref request = BytestreamsRequest::create(to, bytestreams, iqRouter); - request->onResponse.connect(boost::bind(&OutgoingFileTransfer::handleBytestreamsRequestResponse, this, _1, _2)); - request->send(); - } - else if (response->getRequestedMethod() == "http://jabber.org/protocol/ibb") { - ibbSession = boost::shared_ptr<IBBSendSession>(new IBBSendSession(id, to, bytestream, iqRouter)); - ibbSession->onFinished.connect(boost::bind(&OutgoingFileTransfer::handleIBBSessionFinished, this, _1)); - ibbSession->start(); - } - } -} - -void OutgoingFileTransfer::handleBytestreamsRequestResponse(Bytestreams::ref, ErrorPayload::ref error) { - if (error) { - finish(FileTransferError()); - } - //socksServer->onTransferFinished.connect(); -} - -void OutgoingFileTransfer::finish(boost::optional<FileTransferError> error) { - if (ibbSession) { - ibbSession->onFinished.disconnect(boost::bind(&OutgoingFileTransfer::handleIBBSessionFinished, this, _1)); - ibbSession.reset(); - } - socksServer->removeBytestream(id, from, to); - onFinished(error); -} - -void OutgoingFileTransfer::handleIBBSessionFinished(boost::optional<FileTransferError> error) { - finish(error); +OutgoingFileTransfer::~OutgoingFileTransfer() { } } diff --git a/Swiften/FileTransfer/OutgoingFileTransfer.h b/Swiften/FileTransfer/OutgoingFileTransfer.h index a694c13..a8c1e81 100644 --- a/Swiften/FileTransfer/OutgoingFileTransfer.h +++ b/Swiften/FileTransfer/OutgoingFileTransfer.h @@ -6,47 +6,12 @@ #pragma once -#include <boost/shared_ptr.hpp> - -#include "Swiften/FileTransfer/ReadBytestream.h" -#include "Swiften/Base/boost_bsignals.h" -#include "Swiften/FileTransfer/FileTransferError.h" -#include "Swiften/FileTransfer/SOCKS5BytestreamServer.h" -#include "Swiften/JID/JID.h" -#include "Swiften/Elements/StreamInitiation.h" -#include "Swiften/Elements/Bytestreams.h" -#include "Swiften/Elements/ErrorPayload.h" -#include "Swiften/FileTransfer/IBBSendSession.h" - namespace Swift { - class IQRouter; - class SOCKS5BytestreamServer; - class OutgoingFileTransfer { public: - OutgoingFileTransfer(const std::string& id, const JID& from, const JID& to, const std::string& name, int size, const std::string& description, boost::shared_ptr<ReadBytestream> bytestream, IQRouter* iqRouter, SOCKS5BytestreamServer* socksServer); - - void start(); - void stop(); - - boost::signal<void (const boost::optional<FileTransferError>&)> onFinished; - - private: - void handleStreamInitiationRequestResponse(StreamInitiation::ref, ErrorPayload::ref); - void handleBytestreamsRequestResponse(Bytestreams::ref, ErrorPayload::ref); - void finish(boost::optional<FileTransferError> error); - void handleIBBSessionFinished(boost::optional<FileTransferError> error); + virtual ~OutgoingFileTransfer(); - private: - std::string id; - JID from; - JID to; - std::string name; - int size; - std::string description; - boost::shared_ptr<ReadBytestream> bytestream; - IQRouter* iqRouter; - SOCKS5BytestreamServer* socksServer; - boost::shared_ptr<IBBSendSession> ibbSession; + virtual void start() = 0; + virtual void stop() = 0; }; } diff --git a/Swiften/FileTransfer/OutgoingSIFileTransfer.cpp b/Swiften/FileTransfer/OutgoingSIFileTransfer.cpp new file mode 100644 index 0000000..85ac505 --- /dev/null +++ b/Swiften/FileTransfer/OutgoingSIFileTransfer.cpp @@ -0,0 +1,78 @@ +/* + * Copyright (c) 2010 Remko Tronçon + * Licensed under the GNU General Public License v3. + * See Documentation/Licenses/GPLv3.txt for more information. + */ + +#include <Swiften/FileTransfer/OutgoingSIFileTransfer.h> + +#include <boost/bind.hpp> + +#include <Swiften/FileTransfer/StreamInitiationRequest.h> +#include <Swiften/FileTransfer/BytestreamsRequest.h> +#include <Swiften/FileTransfer/SOCKS5BytestreamServer.h> +#include <Swiften/FileTransfer/IBBSendSession.h> + +namespace Swift { + +OutgoingSIFileTransfer::OutgoingSIFileTransfer(const std::string& id, const JID& from, const JID& to, const std::string& name, int size, const std::string& description, boost::shared_ptr<ReadBytestream> bytestream, IQRouter* iqRouter, SOCKS5BytestreamServer* socksServer) : id(id), from(from), to(to), name(name), size(size), description(description), bytestream(bytestream), iqRouter(iqRouter), socksServer(socksServer) { +} + +void OutgoingSIFileTransfer::start() { + StreamInitiation::ref streamInitiation(new StreamInitiation()); + streamInitiation->setID(id); + streamInitiation->setFileInfo(StreamInitiationFileInfo(name, description, size)); + //streamInitiation->addProvidedMethod("http://jabber.org/protocol/bytestreams"); + streamInitiation->addProvidedMethod("http://jabber.org/protocol/ibb"); + StreamInitiationRequest::ref request = StreamInitiationRequest::create(to, streamInitiation, iqRouter); + request->onResponse.connect(boost::bind(&OutgoingSIFileTransfer::handleStreamInitiationRequestResponse, this, _1, _2)); + request->send(); +} + +void OutgoingSIFileTransfer::stop() { +} + +void OutgoingSIFileTransfer::handleStreamInitiationRequestResponse(StreamInitiation::ref response, ErrorPayload::ref error) { + if (error) { + finish(FileTransferError()); + } + else { + if (response->getRequestedMethod() == "http://jabber.org/protocol/bytestreams") { + socksServer->addBytestream(id, from, to, bytestream); + Bytestreams::ref bytestreams(new Bytestreams()); + bytestreams->setStreamID(id); + HostAddressPort addressPort = socksServer->getAddressPort(); + bytestreams->addStreamHost(Bytestreams::StreamHost(addressPort.getAddress().toString(), from, addressPort.getPort())); + BytestreamsRequest::ref request = BytestreamsRequest::create(to, bytestreams, iqRouter); + request->onResponse.connect(boost::bind(&OutgoingSIFileTransfer::handleBytestreamsRequestResponse, this, _1, _2)); + request->send(); + } + else if (response->getRequestedMethod() == "http://jabber.org/protocol/ibb") { + ibbSession = boost::shared_ptr<IBBSendSession>(new IBBSendSession(id, to, bytestream, iqRouter)); + ibbSession->onFinished.connect(boost::bind(&OutgoingSIFileTransfer::handleIBBSessionFinished, this, _1)); + ibbSession->start(); + } + } +} + +void OutgoingSIFileTransfer::handleBytestreamsRequestResponse(Bytestreams::ref, ErrorPayload::ref error) { + if (error) { + finish(FileTransferError()); + } + //socksServer->onTransferFinished.connect(); +} + +void OutgoingSIFileTransfer::finish(boost::optional<FileTransferError> error) { + if (ibbSession) { + ibbSession->onFinished.disconnect(boost::bind(&OutgoingSIFileTransfer::handleIBBSessionFinished, this, _1)); + ibbSession.reset(); + } + socksServer->removeBytestream(id, from, to); + onFinished(error); +} + +void OutgoingSIFileTransfer::handleIBBSessionFinished(boost::optional<FileTransferError> error) { + finish(error); +} + +} diff --git a/Swiften/FileTransfer/OutgoingSIFileTransfer.h b/Swiften/FileTransfer/OutgoingSIFileTransfer.h new file mode 100644 index 0000000..584eb60 --- /dev/null +++ b/Swiften/FileTransfer/OutgoingSIFileTransfer.h @@ -0,0 +1,53 @@ +/* + * Copyright (c) 2010 Remko Tronçon + * Licensed under the GNU General Public License v3. + * See Documentation/Licenses/GPLv3.txt for more information. + */ + +#pragma once + +#include <boost/shared_ptr.hpp> + +#include <Swiften/FileTransfer/OutgoingFileTransfer.h> +#include <Swiften/FileTransfer/ReadBytestream.h> +#include <Swiften/Base/boost_bsignals.h> +#include <Swiften/FileTransfer/FileTransferError.h> +#include <Swiften/FileTransfer/SOCKS5BytestreamServer.h> +#include <Swiften/JID/JID.h> +#include <Swiften/Elements/StreamInitiation.h> +#include <Swiften/Elements/Bytestreams.h> +#include <Swiften/Elements/ErrorPayload.h> +#include <Swiften/FileTransfer/IBBSendSession.h> + +namespace Swift { + class IQRouter; + class SOCKS5BytestreamServer; + + class OutgoingSIFileTransfer : public OutgoingFileTransfer { + public: + OutgoingSIFileTransfer(const std::string& id, const JID& from, const JID& to, const std::string& name, int size, const std::string& description, boost::shared_ptr<ReadBytestream> bytestream, IQRouter* iqRouter, SOCKS5BytestreamServer* socksServer); + + virtual void start(); + virtual void stop(); + + boost::signal<void (const boost::optional<FileTransferError>&)> onFinished; + + private: + void handleStreamInitiationRequestResponse(StreamInitiation::ref, ErrorPayload::ref); + void handleBytestreamsRequestResponse(Bytestreams::ref, ErrorPayload::ref); + void finish(boost::optional<FileTransferError> error); + void handleIBBSessionFinished(boost::optional<FileTransferError> error); + + private: + std::string id; + JID from; + JID to; + std::string name; + int size; + std::string description; + boost::shared_ptr<ReadBytestream> bytestream; + IQRouter* iqRouter; + SOCKS5BytestreamServer* socksServer; + boost::shared_ptr<IBBSendSession> ibbSession; + }; +} diff --git a/Swiften/FileTransfer/ReadBytestream.cpp b/Swiften/FileTransfer/ReadBytestream.cpp index 705906c..5fa10d8 100644 --- a/Swiften/FileTransfer/ReadBytestream.cpp +++ b/Swiften/FileTransfer/ReadBytestream.cpp @@ -4,7 +4,7 @@ * See Documentation/Licenses/GPLv3.txt for more information. */ -#include "Swiften/FileTransfer/ReadBytestream.h" +#include <Swiften/FileTransfer/ReadBytestream.h> namespace Swift { diff --git a/Swiften/FileTransfer/ReadBytestream.h b/Swiften/FileTransfer/ReadBytestream.h index 4da2bc2..2601192 100644 --- a/Swiften/FileTransfer/ReadBytestream.h +++ b/Swiften/FileTransfer/ReadBytestream.h @@ -6,13 +6,14 @@ #pragma once -#include "Swiften/Base/ByteArray.h" +#include <vector> +#include <cstring> namespace Swift { class ReadBytestream { public: virtual ~ReadBytestream(); - virtual ByteArray read(size_t size) = 0; + virtual std::vector<unsigned char> read(size_t size) = 0; virtual bool isFinished() const = 0; }; } diff --git a/Swiften/FileTransfer/RemoteJingleTransportCandidateSelector.cpp b/Swiften/FileTransfer/RemoteJingleTransportCandidateSelector.cpp new file mode 100644 index 0000000..338f221 --- /dev/null +++ b/Swiften/FileTransfer/RemoteJingleTransportCandidateSelector.cpp @@ -0,0 +1,14 @@ +/* + * Copyright (c) 2011 Remko Tronçon + * Licensed under the GNU General Public License v3. + * See Documentation/Licenses/GPLv3.txt for more information. + */ + +#include <Swiften/FileTransfer/RemoteJingleTransportCandidateSelector.h> + +namespace Swift { + +RemoteJingleTransportCandidateSelector::~RemoteJingleTransportCandidateSelector() { +} + +} diff --git a/Swiften/FileTransfer/RemoteJingleTransportCandidateSelector.h b/Swiften/FileTransfer/RemoteJingleTransportCandidateSelector.h new file mode 100644 index 0000000..b12b06b --- /dev/null +++ b/Swiften/FileTransfer/RemoteJingleTransportCandidateSelector.h @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2011 Remko Tronçon + * Licensed under the GNU General Public License v3. + * See Documentation/Licenses/GPLv3.txt for more information. + */ + +#pragma once + +#include <Swiften/Base/boost_bsignals.h> + +#include <Swiften/Elements/JingleTransportPayload.h> +#include <Swiften/FileTransfer/JingleTransport.h> + +namespace Swift { + class RemoteJingleTransportCandidateSelector { + public: + virtual ~RemoteJingleTransportCandidateSelector(); + + virtual void addRemoteTransportCandidates(JingleTransportPayload::ref) = 0; + virtual void selectCandidate() = 0; + virtual void setMinimumPriority(int) = 0; + + virtual bool isActualCandidate(JingleTransportPayload::ref) = 0; + virtual int getPriority(JingleTransportPayload::ref) = 0; + virtual JingleTransport::ref selectTransport(JingleTransportPayload::ref) = 0; + + boost::signal<void (JingleTransportPayload::ref)> onRemoteTransportCandidateSelectFinished; + }; +} diff --git a/Swiften/FileTransfer/RemoteJingleTransportCandidateSelectorFactory.cpp b/Swiften/FileTransfer/RemoteJingleTransportCandidateSelectorFactory.cpp new file mode 100644 index 0000000..36b7cba --- /dev/null +++ b/Swiften/FileTransfer/RemoteJingleTransportCandidateSelectorFactory.cpp @@ -0,0 +1,14 @@ +/* + * Copyright (c) 2011 Remko Tronçon + * Licensed under the GNU General Public License v3. + * See Documentation/Licenses/GPLv3.txt for more information. + */ + +#include <Swiften/FileTransfer/RemoteJingleTransportCandidateSelectorFactory.h> + +namespace Swift { + +RemoteJingleTransportCandidateSelectorFactory::~RemoteJingleTransportCandidateSelectorFactory() { +} + +} diff --git a/Swiften/FileTransfer/RemoteJingleTransportCandidateSelectorFactory.h b/Swiften/FileTransfer/RemoteJingleTransportCandidateSelectorFactory.h new file mode 100644 index 0000000..caa3097 --- /dev/null +++ b/Swiften/FileTransfer/RemoteJingleTransportCandidateSelectorFactory.h @@ -0,0 +1,18 @@ +/* + * Copyright (c) 2011 Remko Tronçon + * Licensed under the GNU General Public License v3. + * See Documentation/Licenses/GPLv3.txt for more information. + */ + +#pragma once + +namespace Swift { + class RemoteJingleTransportCandidateSelector; + + class RemoteJingleTransportCandidateSelectorFactory { + public: + virtual ~RemoteJingleTransportCandidateSelectorFactory(); + + virtual RemoteJingleTransportCandidateSelector* createCandidateSelector() = 0; + }; +} diff --git a/Swiften/FileTransfer/SConscript b/Swiften/FileTransfer/SConscript index ea9e7bb..24fc9e8 100644 --- a/Swiften/FileTransfer/SConscript +++ b/Swiften/FileTransfer/SConscript @@ -1,10 +1,17 @@ -Import("swiften_env") +Import("swiften_env", "env") sources = [ "OutgoingFileTransfer.cpp", + "OutgoingSIFileTransfer.cpp", "IncomingFileTransfer.cpp", "IncomingJingleFileTransfer.cpp", - "IncomingFileTransferManager.cpp", + "IncomingFileTransferManager.cpp", + "RemoteJingleTransportCandidateSelector.cpp", + "RemoteJingleTransportCandidateSelectorFactory.cpp", + "LocalJingleTransportCandidateGenerator.cpp", + "LocalJingleTransportCandidateGeneratorFactory.cpp", + "JingleTransport.cpp", + "JingleIncomingIBBTransport.cpp", "ReadBytestream.cpp", "WriteBytestream.cpp", "FileReadBytestream.cpp", @@ -17,3 +24,9 @@ sources = [ ] swiften_env.Append(SWIFTEN_OBJECTS = swiften_env.SwiftenObject(sources)) + +env.Append(UNITTEST_SOURCES = [ + File("UnitTest/SOCKS5BytestreamServerSessionTest.cpp"), + File("UnitTest/IBBSendSessionTest.cpp"), + File("UnitTest/IBBReceiveSessionTest.cpp"), + ]) diff --git a/Swiften/FileTransfer/SOCKS5BytestreamRegistry.cpp b/Swiften/FileTransfer/SOCKS5BytestreamRegistry.cpp index 7f889b1..429c7f2 100644 --- a/Swiften/FileTransfer/SOCKS5BytestreamRegistry.cpp +++ b/Swiften/FileTransfer/SOCKS5BytestreamRegistry.cpp @@ -4,7 +4,7 @@ * See Documentation/Licenses/GPLv3.txt for more information. */ -#include "Swiften/FileTransfer/SOCKS5BytestreamRegistry.h" +#include <Swiften/FileTransfer/SOCKS5BytestreamRegistry.h> namespace Swift { diff --git a/Swiften/FileTransfer/SOCKS5BytestreamRegistry.h b/Swiften/FileTransfer/SOCKS5BytestreamRegistry.h index 7cee256..955b900 100644 --- a/Swiften/FileTransfer/SOCKS5BytestreamRegistry.h +++ b/Swiften/FileTransfer/SOCKS5BytestreamRegistry.h @@ -10,7 +10,7 @@ #include <map> #include <string> -#include "Swiften/FileTransfer/ReadBytestream.h" +#include <Swiften/FileTransfer/ReadBytestream.h> namespace Swift { class SOCKS5BytestreamRegistry { diff --git a/Swiften/FileTransfer/SOCKS5BytestreamServer.cpp b/Swiften/FileTransfer/SOCKS5BytestreamServer.cpp index 9bc49ae..bc2d259 100644 --- a/Swiften/FileTransfer/SOCKS5BytestreamServer.cpp +++ b/Swiften/FileTransfer/SOCKS5BytestreamServer.cpp @@ -4,13 +4,13 @@ * See Documentation/Licenses/GPLv3.txt for more information. */ -#include "Swiften/FileTransfer/SOCKS5BytestreamServer.h" +#include <Swiften/FileTransfer/SOCKS5BytestreamServer.h> #include <boost/bind.hpp> -#include "Swiften/StringCodecs/Hexify.h" -#include "Swiften/StringCodecs/SHA1.h" -#include "Swiften/FileTransfer/SOCKS5BytestreamServerSession.h" +#include <Swiften/StringCodecs/Hexify.h> +#include <Swiften/StringCodecs/SHA1.h> +#include <Swiften/FileTransfer/SOCKS5BytestreamServerSession.h> namespace Swift { diff --git a/Swiften/FileTransfer/SOCKS5BytestreamServer.h b/Swiften/FileTransfer/SOCKS5BytestreamServer.h index d5a62bb..7fa709e 100644 --- a/Swiften/FileTransfer/SOCKS5BytestreamServer.h +++ b/Swiften/FileTransfer/SOCKS5BytestreamServer.h @@ -9,11 +9,11 @@ #include <boost/shared_ptr.hpp> #include <map> -#include "Swiften/Network/ConnectionServer.h" +#include <Swiften/Network/ConnectionServer.h> #include <string> -#include "Swiften/JID/JID.h" -#include "Swiften/FileTransfer/ReadBytestream.h" -#include "Swiften/FileTransfer/SOCKS5BytestreamRegistry.h" +#include <Swiften/JID/JID.h> +#include <Swiften/FileTransfer/ReadBytestream.h> +#include <Swiften/FileTransfer/SOCKS5BytestreamRegistry.h> namespace Swift { class SOCKS5BytestreamServerSession; diff --git a/Swiften/FileTransfer/SOCKS5BytestreamServerSession.cpp b/Swiften/FileTransfer/SOCKS5BytestreamServerSession.cpp index 9951f7a..46cfb3a 100644 --- a/Swiften/FileTransfer/SOCKS5BytestreamServerSession.cpp +++ b/Swiften/FileTransfer/SOCKS5BytestreamServerSession.cpp @@ -4,13 +4,14 @@ * See Documentation/Licenses/GPLv3.txt for more information. */ -#include "Swiften/FileTransfer/SOCKS5BytestreamServerSession.h" +#include <Swiften/FileTransfer/SOCKS5BytestreamServerSession.h> #include <boost/bind.hpp> +#include <iostream> -#include "Swiften/Base/ByteArray.h" -#include "Swiften/FileTransfer/SOCKS5BytestreamRegistry.h" -#include "Swiften/FileTransfer/BytestreamException.h" +#include <Swiften/Base/ByteArray.h> +#include <Swiften/FileTransfer/SOCKS5BytestreamRegistry.h> +#include <Swiften/FileTransfer/BytestreamException.h> namespace Swift { @@ -98,7 +99,7 @@ void SOCKS5BytestreamServerSession::sendData() { try { connection->write(bytestream->read(chunkSize)); } - catch (const BytestreamException& e) { + catch (const BytestreamException&) { finish(true); } } diff --git a/Swiften/FileTransfer/SOCKS5BytestreamServerSession.h b/Swiften/FileTransfer/SOCKS5BytestreamServerSession.h index f430f5d..80965fb 100644 --- a/Swiften/FileTransfer/SOCKS5BytestreamServerSession.h +++ b/Swiften/FileTransfer/SOCKS5BytestreamServerSession.h @@ -8,9 +8,9 @@ #include <boost/shared_ptr.hpp> -#include "Swiften/Base/boost_bsignals.h" -#include "Swiften/Network/Connection.h" -#include "Swiften/FileTransfer/ReadBytestream.h" +#include <Swiften/Base/boost_bsignals.h> +#include <Swiften/Network/Connection.h> +#include <Swiften/FileTransfer/ReadBytestream.h> namespace Swift { class SOCKS5BytestreamRegistry; diff --git a/Swiften/FileTransfer/StreamInitiationRequest.h b/Swiften/FileTransfer/StreamInitiationRequest.h index f516d4b..40e38be 100644 --- a/Swiften/FileTransfer/StreamInitiationRequest.h +++ b/Swiften/FileTransfer/StreamInitiationRequest.h @@ -6,8 +6,8 @@ #pragma once -#include "Swiften/Queries/GenericRequest.h" -#include "Swiften/Elements/StreamInitiation.h" +#include <Swiften/Queries/GenericRequest.h> +#include <Swiften/Elements/StreamInitiation.h> namespace Swift { diff --git a/Swiften/FileTransfer/UnitTest/IBBReceiveSessionTest.cpp b/Swiften/FileTransfer/UnitTest/IBBReceiveSessionTest.cpp new file mode 100644 index 0000000..01f1355 --- /dev/null +++ b/Swiften/FileTransfer/UnitTest/IBBReceiveSessionTest.cpp @@ -0,0 +1,188 @@ +/* + * Copyright (c) 2010 Remko Tronçon + * Licensed under the GNU General Public License v3. + * See Documentation/Licenses/GPLv3.txt for more information. + */ + + +#include <cppunit/extensions/HelperMacros.h> +#include <cppunit/extensions/TestFactoryRegistry.h> +#include <vector> +#include <boost/bind.hpp> +#include <boost/smart_ptr/make_shared.hpp> + +#include <Swiften/Base/ByteArray.h> +#include <Swiften/FileTransfer/IBBReceiveSession.h> +#include <Swiften/Queries/IQRouter.h> +#include <Swiften/Client/DummyStanzaChannel.h> + +using namespace Swift; + +class IBBReceiveSessionTest : public CppUnit::TestFixture { + CPPUNIT_TEST_SUITE(IBBReceiveSessionTest); + CPPUNIT_TEST(testOpen); + CPPUNIT_TEST(testReceiveData); + CPPUNIT_TEST(testReceiveMultipleData); + CPPUNIT_TEST(testReceiveDataForOtherSession); + CPPUNIT_TEST(testReceiveDataOutOfOrder); + CPPUNIT_TEST(testReceiveLastData); + CPPUNIT_TEST(testReceiveClose); + CPPUNIT_TEST(testStopWhileActive); + CPPUNIT_TEST_SUITE_END(); + + public: + void setUp() { + stanzaChannel = new DummyStanzaChannel(); + iqRouter = new IQRouter(stanzaChannel); + finished = false; + } + + void tearDown() { + delete iqRouter; + delete stanzaChannel; + } + + void testOpen() { + std::auto_ptr<IBBReceiveSession> testling(createSession("foo@bar.com/baz", "mysession")); + testling->start(); + stanzaChannel->onIQReceived(createIBBRequest(IBB::createIBBOpen("mysession", 0x10), "foo@bar.com/baz", "id-open")); + + CPPUNIT_ASSERT(stanzaChannel->isResultAtIndex(0, "id-open")); + CPPUNIT_ASSERT(!finished); + + testling->stop(); + } + + void testReceiveData() { + std::auto_ptr<IBBReceiveSession> testling(createSession("foo@bar.com/baz", "mysession")); + testling->start(); + stanzaChannel->onIQReceived(createIBBRequest(IBB::createIBBOpen("mysession", 0x10), "foo@bar.com/baz", "id-open")); + + stanzaChannel->onIQReceived(createIBBRequest(IBB::createIBBData("mysession", 0, ByteArray::create("abc")), "foo@bar.com/baz", "id-a")); + + CPPUNIT_ASSERT(stanzaChannel->isResultAtIndex(1, "id-a")); + CPPUNIT_ASSERT(ByteArray::create("abc") == receivedData); + CPPUNIT_ASSERT(!finished); + + testling->stop(); + } + + void testReceiveMultipleData() { + std::auto_ptr<IBBReceiveSession> testling(createSession("foo@bar.com/baz", "mysession")); + testling->start(); + stanzaChannel->onIQReceived(createIBBRequest(IBB::createIBBOpen("mysession", 0x10), "foo@bar.com/baz", "id-open")); + + stanzaChannel->onIQReceived(createIBBRequest(IBB::createIBBData("mysession", 0, ByteArray::create("abc")), "foo@bar.com/baz", "id-a")); + stanzaChannel->onIQReceived(createIBBRequest(IBB::createIBBData("mysession", 1, ByteArray::create("def")), "foo@bar.com/baz", "id-b")); + + CPPUNIT_ASSERT(stanzaChannel->isResultAtIndex(2, "id-b")); + CPPUNIT_ASSERT(ByteArray::create("abcdef") == receivedData); + CPPUNIT_ASSERT(!finished); + + testling->stop(); + } + + void testReceiveDataForOtherSession() { + std::auto_ptr<IBBReceiveSession> testling(createSession("foo@bar.com/baz", "mysession")); + testling->start(); + stanzaChannel->onIQReceived(createIBBRequest(IBB::createIBBOpen("mysession", 0x10), "foo@bar.com/baz", "id-open")); + + stanzaChannel->onIQReceived(createIBBRequest(IBB::createIBBData("othersession", 0, ByteArray::create("abc")), "foo@bar.com/baz", "id-a")); + + CPPUNIT_ASSERT(stanzaChannel->isErrorAtIndex(1, "id-a")); + + testling->stop(); + } + + void testReceiveDataOutOfOrder() { + std::auto_ptr<IBBReceiveSession> testling(createSession("foo@bar.com/baz", "mysession")); + testling->start(); + stanzaChannel->onIQReceived(createIBBRequest(IBB::createIBBOpen("mysession", 0x10), "foo@bar.com/baz", "id-open")); + + stanzaChannel->onIQReceived(createIBBRequest(IBB::createIBBData("mysession", 0, ByteArray::create("abc")), "foo@bar.com/baz", "id-a")); + stanzaChannel->onIQReceived(createIBBRequest(IBB::createIBBData("mysession", 0, ByteArray::create("def")), "foo@bar.com/baz", "id-b")); + + CPPUNIT_ASSERT(stanzaChannel->isErrorAtIndex(2, "id-b")); + CPPUNIT_ASSERT(finished); + CPPUNIT_ASSERT(error); + + testling->stop(); + } + + void testReceiveLastData() { + std::auto_ptr<IBBReceiveSession> testling(createSession("foo@bar.com/baz", "mysession", 6)); + testling->start(); + stanzaChannel->onIQReceived(createIBBRequest(IBB::createIBBOpen("mysession", 0x10), "foo@bar.com/baz", "id-open")); + + stanzaChannel->onIQReceived(createIBBRequest(IBB::createIBBData("mysession", 0, ByteArray::create("abc")), "foo@bar.com/baz", "id-a")); + stanzaChannel->onIQReceived(createIBBRequest(IBB::createIBBData("mysession", 1, ByteArray::create("def")), "foo@bar.com/baz", "id-b")); + + CPPUNIT_ASSERT(stanzaChannel->isResultAtIndex(2, "id-b")); + CPPUNIT_ASSERT(ByteArray::create("abcdef") == receivedData); + CPPUNIT_ASSERT(finished); + CPPUNIT_ASSERT(!error); + + testling->stop(); + } + + void testReceiveClose() { + std::auto_ptr<IBBReceiveSession> testling(createSession("foo@bar.com/baz", "mysession")); + testling->start(); + stanzaChannel->onIQReceived(createIBBRequest(IBB::createIBBOpen("mysession", 0x10), "foo@bar.com/baz", "id-open")); + + stanzaChannel->onIQReceived(createIBBRequest(IBB::createIBBClose("mysession"), "foo@bar.com/baz", "id-close")); + + CPPUNIT_ASSERT(finished); + CPPUNIT_ASSERT(error); + + testling->stop(); + } + + void testStopWhileActive() { + std::auto_ptr<IBBReceiveSession> testling(createSession("foo@bar.com/baz", "mysession")); + testling->start(); + stanzaChannel->onIQReceived(createIBBRequest(IBB::createIBBOpen("mysession", 0x10), "foo@bar.com/baz", "id-open")); + + testling->stop(); + + CPPUNIT_ASSERT(stanzaChannel->isRequestAtIndex<IBB>(1, JID("foo@bar.com/baz"), IQ::Set)); + IBB::ref ibb = stanzaChannel->sentStanzas[1]->getPayload<IBB>(); + CPPUNIT_ASSERT_EQUAL(IBB::Close, ibb->getAction()); + CPPUNIT_ASSERT_EQUAL(std::string("mysession"), ibb->getStreamID()); + CPPUNIT_ASSERT(finished); + CPPUNIT_ASSERT(!error); + } + + private: + IQ::ref createIBBRequest(IBB::ref ibb, const JID& from, const std::string& id) { + IQ::ref request = IQ::createRequest(IQ::Set, JID("baz@fum.com/dum"), id, ibb); + request->setFrom(from); + return request; + } + + IBBReceiveSession* createSession(const std::string& from, const std::string& id, size_t size = 0x1000) { + IBBReceiveSession* session = new IBBReceiveSession(id, JID(from), size, iqRouter); + session->onDataReceived.connect(boost::bind(&IBBReceiveSessionTest::handleDataReceived, this, _1)); + session->onFinished.connect(boost::bind(&IBBReceiveSessionTest::handleFinished, this, _1)); + return session; + } + + + void handleFinished(boost::optional<FileTransferError> error) { + finished = true; + this->error = error; + } + + void handleDataReceived(const std::vector<unsigned char>& data) { + receivedData.insert(receivedData.end(), data.begin(), data.end()); + } + + private: + DummyStanzaChannel* stanzaChannel; + IQRouter* iqRouter; + bool finished; + boost::optional<FileTransferError> error; + std::vector<unsigned char> receivedData; +}; + +CPPUNIT_TEST_SUITE_REGISTRATION(IBBReceiveSessionTest); diff --git a/Swiften/FileTransfer/UnitTest/IBBSendSessionTest.cpp b/Swiften/FileTransfer/UnitTest/IBBSendSessionTest.cpp index 0cd273a..5c23887 100644 --- a/Swiften/FileTransfer/UnitTest/IBBSendSessionTest.cpp +++ b/Swiften/FileTransfer/UnitTest/IBBSendSessionTest.cpp @@ -4,17 +4,16 @@ * See Documentation/Licenses/GPLv3.txt for more information. */ -#include "Swiften/Base/ByteArray.h" - #include <cppunit/extensions/HelperMacros.h> #include <cppunit/extensions/TestFactoryRegistry.h> #include <vector> #include <boost/bind.hpp> -#include "Swiften/FileTransfer/IBBSendSession.h" -#include "Swiften/FileTransfer/ByteArrayReadBytestream.h" -#include "Swiften/Queries/IQRouter.h" -#include "Swiften/Client/DummyStanzaChannel.h" +#include <Swiften/Base/ByteArray.h> +#include <Swiften/FileTransfer/IBBSendSession.h> +#include <Swiften/FileTransfer/ByteArrayReadBytestream.h> +#include <Swiften/Queries/IQRouter.h> +#include <Swiften/Client/DummyStanzaChannel.h> using namespace Swift; @@ -33,7 +32,7 @@ class IBBSendSessionTest : public CppUnit::TestFixture { void setUp() { stanzaChannel = new DummyStanzaChannel(); iqRouter = new IQRouter(stanzaChannel); - bytestream = boost::shared_ptr<ByteArrayReadBytestream>(new ByteArrayReadBytestream(ByteArray("abcdefg"))); + bytestream = boost::shared_ptr<ByteArrayReadBytestream>(new ByteArrayReadBytestream(ByteArray::create("abcdefg"))); } void tearDown() { @@ -66,7 +65,7 @@ class IBBSendSessionTest : public CppUnit::TestFixture { CPPUNIT_ASSERT(stanzaChannel->isRequestAtIndex<IBB>(1, JID("foo@bar.com/baz"), IQ::Set)); IBB::ref ibb = stanzaChannel->sentStanzas[1]->getPayload<IBB>(); CPPUNIT_ASSERT_EQUAL(IBB::Data, ibb->getAction()); - CPPUNIT_ASSERT_EQUAL(ByteArray("abc"), ibb->getData()); + CPPUNIT_ASSERT(ByteArray::create("abc") == ibb->getData()); CPPUNIT_ASSERT_EQUAL(0, ibb->getSequenceNumber()); CPPUNIT_ASSERT_EQUAL(std::string("myid"), ibb->getStreamID()); } @@ -82,7 +81,7 @@ class IBBSendSessionTest : public CppUnit::TestFixture { CPPUNIT_ASSERT(stanzaChannel->isRequestAtIndex<IBB>(2, JID("foo@bar.com/baz"), IQ::Set)); IBB::ref ibb = stanzaChannel->sentStanzas[2]->getPayload<IBB>(); CPPUNIT_ASSERT_EQUAL(IBB::Data, ibb->getAction()); - CPPUNIT_ASSERT_EQUAL(ByteArray("def"), ibb->getData()); + CPPUNIT_ASSERT(ByteArray::create("def") == ibb->getData()); CPPUNIT_ASSERT_EQUAL(1, ibb->getSequenceNumber()); CPPUNIT_ASSERT_EQUAL(std::string("myid"), ibb->getStreamID()); } diff --git a/Swiften/FileTransfer/UnitTest/SOCKS5BytestreamServerSessionTest.cpp b/Swiften/FileTransfer/UnitTest/SOCKS5BytestreamServerSessionTest.cpp index c6d246d..9f3088c 100644 --- a/Swiften/FileTransfer/UnitTest/SOCKS5BytestreamServerSessionTest.cpp +++ b/Swiften/FileTransfer/UnitTest/SOCKS5BytestreamServerSessionTest.cpp @@ -4,18 +4,18 @@ * See Documentation/Licenses/GPLv3.txt for more information. */ -#include "Swiften/Base/ByteArray.h" +#include <Swiften/Base/ByteArray.h> #include <cppunit/extensions/HelperMacros.h> #include <cppunit/extensions/TestFactoryRegistry.h> #include <boost/bind.hpp> -#include "Swiften/FileTransfer/SOCKS5BytestreamServerSession.h" -#include "Swiften/FileTransfer/ByteArrayReadBytestream.h" -#include "Swiften/FileTransfer/SOCKS5BytestreamRegistry.h" -#include "Swiften/Network/DummyConnection.h" -#include "Swiften/EventLoop/DummyEventLoop.h" -#include "Swiften/Base/StartStopper.h" +#include <Swiften/FileTransfer/SOCKS5BytestreamServerSession.h> +#include <Swiften/FileTransfer/ByteArrayReadBytestream.h> +#include <Swiften/FileTransfer/SOCKS5BytestreamRegistry.h> +#include <Swiften/Network/DummyConnection.h> +#include <Swiften/EventLoop/DummyEventLoop.h> +#include <Swiften/Base/StartStopper.h> using namespace Swift; @@ -35,7 +35,7 @@ class SOCKS5BytestreamServerSessionTest : public CppUnit::TestFixture { eventLoop = new DummyEventLoop(); connection = boost::shared_ptr<DummyConnection>(new DummyConnection(eventLoop)); connection->onDataSent.connect(boost::bind(&SOCKS5BytestreamServerSessionTest::handleDataWritten, this, _1)); - stream1 = boost::shared_ptr<ByteArrayReadBytestream>(new ByteArrayReadBytestream(ByteArray("abcdefg"))); + stream1 = boost::shared_ptr<ByteArrayReadBytestream>(new ByteArrayReadBytestream(ByteArray::create("abcdefg"))); } void tearDown() { @@ -47,20 +47,20 @@ class SOCKS5BytestreamServerSessionTest : public CppUnit::TestFixture { std::auto_ptr<SOCKS5BytestreamServerSession> testling(createSession()); StartStopper<SOCKS5BytestreamServerSession> stopper(testling.get()); - receive(ByteArray("\x05\x02\x01\x02")); + receive(ByteArray::create("\x05\x02\x01\x02")); - CPPUNIT_ASSERT_EQUAL(ByteArray("\x05\x00", 2), receivedData); + CPPUNIT_ASSERT(ByteArray::create("\x05\x00", 2) == receivedData); } void testAuthenticate_Chunked() { std::auto_ptr<SOCKS5BytestreamServerSession> testling(createSession()); StartStopper<SOCKS5BytestreamServerSession> stopper(testling.get()); - receive(ByteArray("\x05\x02\x01")); + receive(ByteArray::create("\x05\x02\x01")); - CPPUNIT_ASSERT_EQUAL(0, static_cast<int>(receivedData.getSize())); - receive(ByteArray("\x01")); - CPPUNIT_ASSERT_EQUAL(ByteArray("\x05\x00", 2), receivedData); + CPPUNIT_ASSERT_EQUAL(0, static_cast<int>(receivedData.size())); + receive(ByteArray::create("\x01")); + CPPUNIT_ASSERT(ByteArray::create("\x05\x00", 2) == receivedData); } void testRequest() { @@ -70,8 +70,8 @@ class SOCKS5BytestreamServerSessionTest : public CppUnit::TestFixture { authenticate(); ByteArray hostname("abcdef"); - receive(ByteArray("\x05\x01\x00\x03", 4) + hostname.getSize() + hostname + ByteArray("\x00\x00", 2)); - CPPUNIT_ASSERT_EQUAL(ByteArray("\x05\x00\x00\x03\x06\x61\x62\x63\x64\x65\x66\x00\x00", 13), ByteArray(receivedData.getData(), 13)); + receive(ByteArray(ByteArray::create("\x05\x01\x00\x03", 4)) + hostname.getSize() + hostname + ByteArray::create("\x00\x00", 2)); + CPPUNIT_ASSERT(ByteArray::create("\x05\x00\x00\x03\x06\x61\x62\x63\x64\x65\x66\x00\x00", 13) == ByteArray::create(&receivedData[0], 13)); } void testRequest_UnknownBytestream() { @@ -80,8 +80,8 @@ class SOCKS5BytestreamServerSessionTest : public CppUnit::TestFixture { authenticate(); ByteArray hostname("abcdef"); - receive(ByteArray("\x05\x01\x00\x03", 4) + hostname.getSize() + hostname + ByteArray("\x00\x00", 2)); - CPPUNIT_ASSERT_EQUAL(ByteArray("\x05\x04\x00\x03\x06\x61\x62\x63\x64\x65\x66\x00\x00", 13), receivedData); + receive(ByteArray(ByteArray::create("\x05\x01\x00\x03", 4)) + hostname.getSize() + hostname + ByteArray::create("\x00\x00", 2)); + CPPUNIT_ASSERT(ByteArray::create("\x05\x04\x00\x03\x06\x61\x62\x63\x64\x65\x66\x00\x00", 13) == receivedData); } void testReceiveData() { @@ -93,7 +93,7 @@ class SOCKS5BytestreamServerSessionTest : public CppUnit::TestFixture { eventLoop->processEvents(); skipHeader("abcdef"); - CPPUNIT_ASSERT_EQUAL(ByteArray("abcdefg"), receivedData); + CPPUNIT_ASSERT(ByteArray::create("abcdefg") == receivedData); CPPUNIT_ASSERT_EQUAL(2, receivedDataChunks); } @@ -107,7 +107,7 @@ class SOCKS5BytestreamServerSessionTest : public CppUnit::TestFixture { eventLoop->processEvents(); skipHeader("abcdef"); - CPPUNIT_ASSERT_EQUAL(ByteArray("abcdefg"), receivedData); + CPPUNIT_ASSERT(ByteArray::create("abcdefg") == receivedData); CPPUNIT_ASSERT_EQUAL(4, receivedDataChunks); } @@ -118,23 +118,23 @@ class SOCKS5BytestreamServerSessionTest : public CppUnit::TestFixture { } void authenticate() { - receive(ByteArray("\x05\x02\x01\x02")); + receive(ByteArray::create("\x05\x02\x01\x02")); receivedData.clear(); receivedDataChunks = 0; } void request(const std::string& hostname) { - receive(ByteArray("\x05\x01\x00\x03", 4) + hostname.size() + hostname + ByteArray("\x00\x00", 2)); + receive(ByteArray(ByteArray::create("\x05\x01\x00\x03", 4)) + hostname.size() + hostname + ByteArray::create("\x00\x00", 2)); } void skipHeader(const std::string& hostname) { int headerSize = 7 + hostname.size(); - receivedData = ByteArray(receivedData.getData() + headerSize, receivedData.getSize() - headerSize); + receivedData = ByteArray::create(&receivedData[headerSize], receivedData.size() - headerSize); } void handleDataWritten(const ByteArray& data) { - receivedData += data; + receivedData.insert(receivedData.end(), data.begin(), data.end()); receivedDataChunks++; } @@ -148,7 +148,7 @@ class SOCKS5BytestreamServerSessionTest : public CppUnit::TestFixture { DummyEventLoop* eventLoop; SOCKS5BytestreamRegistry bytestreams; boost::shared_ptr<DummyConnection> connection; - ByteArray receivedData; + std::vector<unsigned char> receivedData; int receivedDataChunks; boost::shared_ptr<ByteArrayReadBytestream> stream1; }; diff --git a/Swiften/FileTransfer/WriteBytestream.cpp b/Swiften/FileTransfer/WriteBytestream.cpp index f1a5afc..8d10193 100644 --- a/Swiften/FileTransfer/WriteBytestream.cpp +++ b/Swiften/FileTransfer/WriteBytestream.cpp @@ -4,7 +4,7 @@ * See Documentation/Licenses/GPLv3.txt for more information. */ -#include "Swiften/FileTransfer/WriteBytestream.h" +#include <Swiften/FileTransfer/WriteBytestream.h> namespace Swift { diff --git a/Swiften/FileTransfer/WriteBytestream.h b/Swiften/FileTransfer/WriteBytestream.h index 1dc791c..c27aeff 100644 --- a/Swiften/FileTransfer/WriteBytestream.h +++ b/Swiften/FileTransfer/WriteBytestream.h @@ -7,8 +7,7 @@ #pragma once #include <boost/shared_ptr.hpp> - -#include "Swiften/Base/ByteArray.h" +#include <vector> namespace Swift { class WriteBytestream { @@ -17,6 +16,6 @@ namespace Swift { virtual ~WriteBytestream(); - virtual void write(const ByteArray&) = 0; + virtual void write(const std::vector<unsigned char>&) = 0; }; } diff --git a/Swiften/History/HistoryManager.cpp b/Swiften/History/HistoryManager.cpp index 7017899..7eb66ab 100644 --- a/Swiften/History/HistoryManager.cpp +++ b/Swiften/History/HistoryManager.cpp @@ -4,7 +4,7 @@ * See Documentation/Licenses/GPLv3.txt for more information. */ -#include "Swiften/History/HistoryManager.h" +#include <Swiften/History/HistoryManager.h> namespace Swift { diff --git a/Swiften/History/SQLiteHistoryManager.cpp b/Swiften/History/SQLiteHistoryManager.cpp index 9d5a000..8a809bd 100644 --- a/Swiften/History/SQLiteHistoryManager.cpp +++ b/Swiften/History/SQLiteHistoryManager.cpp @@ -8,7 +8,7 @@ #include <boost/lexical_cast.hpp> #include "sqlite3.h" -#include "Swiften/History/SQLiteHistoryManager.h" +#include <Swiften/History/SQLiteHistoryManager.h> namespace { diff --git a/Swiften/History/SQLiteHistoryManager.h b/Swiften/History/SQLiteHistoryManager.h index a2b89f4..ffd9492 100644 --- a/Swiften/History/SQLiteHistoryManager.h +++ b/Swiften/History/SQLiteHistoryManager.h @@ -8,7 +8,7 @@ #include <boost/optional.hpp> -#include "Swiften/History/HistoryManager.h" +#include <Swiften/History/HistoryManager.h> struct sqlite3; diff --git a/Swiften/History/UnitTest/SQLiteHistoryManagerTest.cpp b/Swiften/History/UnitTest/SQLiteHistoryManagerTest.cpp index 0092e0f..fe3fd7e 100644 --- a/Swiften/History/UnitTest/SQLiteHistoryManagerTest.cpp +++ b/Swiften/History/UnitTest/SQLiteHistoryManagerTest.cpp @@ -8,7 +8,7 @@ #include <cppunit/extensions/TestFactoryRegistry.h> #include <boost/date_time/posix_time/posix_time.hpp> -#include "Swiften/History/SQLiteHistoryManager.h" +#include <Swiften/History/SQLiteHistoryManager.h> using namespace Swift; diff --git a/Swiften/IDN/IDNA.cpp b/Swiften/IDN/IDNA.cpp index 6b6c7a4..16b4183 100644 --- a/Swiften/IDN/IDNA.cpp +++ b/Swiften/IDN/IDNA.cpp @@ -4,7 +4,7 @@ * See Documentation/Licenses/GPLv3.txt for more information. */ -#include "Swiften/IDN/IDNA.h" +#include <Swiften/IDN/IDNA.h> #include <stringprep.h> #include <vector> diff --git a/Swiften/IDN/StringPrep.cpp b/Swiften/IDN/StringPrep.cpp index ff01eed..95f294c 100644 --- a/Swiften/IDN/StringPrep.cpp +++ b/Swiften/IDN/StringPrep.cpp @@ -4,7 +4,7 @@ * See Documentation/Licenses/GPLv3.txt for more information. */ -#include "Swiften/IDN/StringPrep.h" +#include <Swiften/IDN/StringPrep.h> #include <stringprep.h> #include <vector> diff --git a/Swiften/JID/JID.cpp b/Swiften/JID/JID.cpp index e4611b3..bbc149c 100644 --- a/Swiften/JID/JID.cpp +++ b/Swiften/JID/JID.cpp @@ -7,17 +7,22 @@ #define SWIFTEN_CACHE_JID_PREP #include <vector> +#include <list> #include <iostream> #include <string> #ifdef SWIFTEN_CACHE_JID_PREP #include <boost/unordered_map.hpp> #endif +#include <boost/assign/list_of.hpp> +#include <boost/algorithm/string/find_format.hpp> +#include <boost/algorithm/string/finder.hpp> +#include <sstream> #include <stringprep.h> #include <Swiften/Base/String.h> -#include "Swiften/JID/JID.h" -#include "Swiften/IDN/StringPrep.h" +#include <Swiften/JID/JID.h> +#include <Swiften/IDN/StringPrep.h> #ifdef SWIFTEN_CACHE_JID_PREP typedef boost::unordered_map<std::string, std::string> PrepCache; @@ -27,6 +32,75 @@ static PrepCache domainPrepCache; static PrepCache resourcePrepCache; #endif +static const std::list<char> escapedChars = boost::assign::list_of(' ')('"')('&')('\'')('/')('<')('>')('@')(':'); + +bool getEscapeSequenceValue(const std::string& sequence, unsigned char& value) { + std::stringstream s; + unsigned int v; + s << std::hex << sequence; + s >> v; + value = static_cast<unsigned char>(v); + return (!s.fail() && !s.bad() && (value == 0x5C || std::find(escapedChars.begin(), escapedChars.end(), value) != escapedChars.end())); +} + +struct UnescapedCharacterFinder { + template<typename Iterator> boost::iterator_range<Iterator> operator()(Iterator begin, Iterator end) { + for (; begin != end; ++begin) { + if (std::find(escapedChars.begin(), escapedChars.end(), *begin) != escapedChars.end()) { + return boost::iterator_range<Iterator>(begin, begin + 1); + } + else if (*begin == '\\') { + // Check if we have an escaped dissalowed character sequence + Iterator innerBegin = begin + 1; + if (innerBegin != end && innerBegin + 1 != end) { + Iterator innerEnd = innerBegin + 2; + unsigned char value; + if (getEscapeSequenceValue(std::string(innerBegin, innerEnd), value)) { + return boost::iterator_range<Iterator>(begin, begin + 1); + } + } + } + } + return boost::iterator_range<Iterator>(end, end); + } +}; + +struct UnescapedCharacterFormatter { + template<typename FindResult> std::string operator()(const FindResult& match) const { + std::ostringstream s; + s << '\\' << std::hex << static_cast<int>(*match.begin()); + return s.str(); + } +}; + +struct EscapedCharacterFinder { + template<typename Iterator> boost::iterator_range<Iterator> operator()(Iterator begin, Iterator end) { + for (; begin != end; ++begin) { + if (*begin == '\\') { + Iterator innerEnd = begin + 1; + for (size_t i = 0; i < 2 && innerEnd != end; ++i, ++innerEnd) { + } + unsigned char value; + if (getEscapeSequenceValue(std::string(begin + 1, innerEnd), value)) { + return boost::iterator_range<Iterator>(begin, innerEnd); + } + } + } + return boost::iterator_range<Iterator>(end, end); + } +}; + +struct EscapedCharacterFormatter { + template<typename FindResult> std::string operator()(const FindResult& match) const { + unsigned char value; + if (getEscapeSequenceValue(std::string(match.begin() + 1, match.end()), value)) { + return std::string(reinterpret_cast<const char*>(&value), 1); + } + return boost::copy_range<std::string>(match); + } +}; + + namespace Swift { JID::JID(const char* jid) { @@ -126,5 +200,13 @@ int JID::compare(const Swift::JID& o, CompareType compareType) const { return 0; } +std::string JID::getEscapedNode(const std::string& node) { + return boost::find_format_all_copy(node, UnescapedCharacterFinder(), UnescapedCharacterFormatter()); +} + +std::string JID::getUnescapedNode() const { + return boost::find_format_all_copy(node_, EscapedCharacterFinder(), EscapedCharacterFormatter()); +} + } // namespace Swift diff --git a/Swiften/JID/JID.h b/Swiften/JID/JID.h index 63e063d..98b42da 100644 --- a/Swiften/JID/JID.h +++ b/Swiften/JID/JID.h @@ -7,7 +7,7 @@ #pragma once #include <string> -#include <ostream> +#include <iosfwd> namespace Swift { class JID { @@ -38,6 +38,18 @@ namespace Swift { return !hasResource_; } + /** + * Returns the given node, escaped according to XEP-0106. + * The resulting node is a valid node for a JID, whereas the input value can contain characters + * that are not allowed. + */ + static std::string getEscapedNode(const std::string& node); + + /** + * Returns the node of the current JID, unescaped according to XEP-0106. + */ + std::string getUnescapedNode() const; + JID toBare() const { JID result(*this); result.hasResource_ = false; diff --git a/Swiften/JID/UnitTest/JIDTest.cpp b/Swiften/JID/UnitTest/JIDTest.cpp index 0f22e15..6b5409f 100644 --- a/Swiften/JID/UnitTest/JIDTest.cpp +++ b/Swiften/JID/UnitTest/JIDTest.cpp @@ -7,7 +7,7 @@ #include <cppunit/extensions/HelperMacros.h> #include <cppunit/extensions/TestFactoryRegistry.h> -#include "Swiften/JID/JID.h" +#include <Swiften/JID/JID.h> using namespace Swift; @@ -51,6 +51,10 @@ class JIDTest : public CppUnit::TestFixture CPPUNIT_TEST(testSmallerThan_Larger); CPPUNIT_TEST(testHasResource); CPPUNIT_TEST(testHasResource_NoResource); + CPPUNIT_TEST(testGetEscapedNode); + CPPUNIT_TEST(testGetEscapedNode_XEP106Examples); + CPPUNIT_TEST(testGetUnescapedNode); + CPPUNIT_TEST(testGetUnescapedNode_XEP106Examples); CPPUNIT_TEST_SUITE_END(); public: @@ -311,6 +315,57 @@ class JIDTest : public CppUnit::TestFixture CPPUNIT_ASSERT(testling.isBare()); } + + void testGetEscapedNode() { + std::string escaped = JID::getEscapedNode("alice@wonderland.lit"); + CPPUNIT_ASSERT_EQUAL(std::string("alice\\40wonderland.lit"), escaped); + + escaped = JID::getEscapedNode("\\& \" ' / <\\\\> @ :\\3a\\40"); + CPPUNIT_ASSERT_EQUAL(std::string("\\\\26\\20\\22\\20\\27\\20\\2f\\20\\3c\\\\\\3e\\20\\40\\20\\3a\\5c3a\\5c40"), escaped); + } + + void testGetEscapedNode_XEP106Examples() { + CPPUNIT_ASSERT_EQUAL(std::string("\\2plus\\2is\\4"), JID::getEscapedNode("\\2plus\\2is\\4")); + CPPUNIT_ASSERT_EQUAL(std::string("foo\\bar"), JID::getEscapedNode("foo\\bar")); + CPPUNIT_ASSERT_EQUAL(std::string("foob\\41r"), JID::getEscapedNode("foob\\41r")); + CPPUNIT_ASSERT_EQUAL(JID::getEscapedNode("space cadet"), std::string("space\\20cadet")); + CPPUNIT_ASSERT_EQUAL(JID::getEscapedNode("call me \"ishmael\""), std::string("call\\20me\\20\\22ishmael\\22")); + CPPUNIT_ASSERT_EQUAL(JID::getEscapedNode("at&t guy"), std::string("at\\26t\\20guy")); + CPPUNIT_ASSERT_EQUAL(JID::getEscapedNode("d'artagnan"), std::string("d\\27artagnan")); + CPPUNIT_ASSERT_EQUAL(JID::getEscapedNode("/.fanboy"), std::string("\\2f.fanboy")); + CPPUNIT_ASSERT_EQUAL(JID::getEscapedNode("::foo::"), std::string("\\3a\\3afoo\\3a\\3a")); + CPPUNIT_ASSERT_EQUAL(JID::getEscapedNode("<foo>"), std::string("\\3cfoo\\3e")); + CPPUNIT_ASSERT_EQUAL(JID::getEscapedNode("user@host"), std::string("user\\40host")); + CPPUNIT_ASSERT_EQUAL(JID::getEscapedNode("c:\\net"), std::string("c\\3a\\net")); + CPPUNIT_ASSERT_EQUAL(JID::getEscapedNode("c:\\\\net"), std::string("c\\3a\\\\net")); + CPPUNIT_ASSERT_EQUAL(JID::getEscapedNode("c:\\cool stuff"), std::string("c\\3a\\cool\\20stuff")); + CPPUNIT_ASSERT_EQUAL(JID::getEscapedNode("c:\\5commas"), std::string("c\\3a\\5c5commas")); + } + + void testGetUnescapedNode() { + std::string input = "\\& \" ' / <\\\\> @ : \\5c\\40"; + JID testling(JID::getEscapedNode(input) + "@y"); + CPPUNIT_ASSERT(testling.isValid()); + CPPUNIT_ASSERT_EQUAL(input, testling.getUnescapedNode()); + } + + void testGetUnescapedNode_XEP106Examples() { + CPPUNIT_ASSERT_EQUAL(std::string("\\2plus\\2is\\4"), JID("\\2plus\\2is\\4@example.com").getUnescapedNode()); + CPPUNIT_ASSERT_EQUAL(std::string("foo\\bar"), JID("foo\\bar@example.com").getUnescapedNode()); + CPPUNIT_ASSERT_EQUAL(std::string("foob\\41r"), JID("foob\\41r@example.com").getUnescapedNode()); + CPPUNIT_ASSERT_EQUAL(std::string("space cadet"), JID("space\\20cadet@example.com").getUnescapedNode()); + CPPUNIT_ASSERT_EQUAL(std::string("call me \"ishmael\""), JID("call\\20me\\20\\22ishmael\\22@example.com").getUnescapedNode()); + CPPUNIT_ASSERT_EQUAL(std::string("at&t guy"), JID("at\\26t\\20guy@example.com").getUnescapedNode()); + CPPUNIT_ASSERT_EQUAL(std::string("d'artagnan"), JID("d\\27artagnan@example.com").getUnescapedNode()); + CPPUNIT_ASSERT_EQUAL(std::string("/.fanboy"), JID("\\2f.fanboy@example.com").getUnescapedNode()); + CPPUNIT_ASSERT_EQUAL(std::string("::foo::"), JID("\\3a\\3afoo\\3a\\3a@example.com").getUnescapedNode()); + CPPUNIT_ASSERT_EQUAL(std::string("<foo>"), JID("\\3cfoo\\3e@example.com").getUnescapedNode()); + CPPUNIT_ASSERT_EQUAL(std::string("user@host"), JID("user\\40host@example.com").getUnescapedNode()); + CPPUNIT_ASSERT_EQUAL(std::string("c:\\net"), JID("c\\3a\\net@example.com").getUnescapedNode()); + CPPUNIT_ASSERT_EQUAL(std::string("c:\\\\net"), JID("c\\3a\\\\net@example.com").getUnescapedNode()); + CPPUNIT_ASSERT_EQUAL(std::string("c:\\cool stuff"), JID("c\\3a\\cool\\20stuff@example.com").getUnescapedNode()); + CPPUNIT_ASSERT_EQUAL(std::string("c:\\5commas"), JID("c\\3a\\5c5commas@example.com").getUnescapedNode()); + } }; CPPUNIT_TEST_SUITE_REGISTRATION(JIDTest); diff --git a/Swiften/Jingle/IncomingJingleSession.cpp b/Swiften/Jingle/IncomingJingleSession.cpp deleted file mode 100644 index b18d9d3..0000000 --- a/Swiften/Jingle/IncomingJingleSession.cpp +++ /dev/null @@ -1,15 +0,0 @@ -/* - * Copyright (c) 2010 Remko Tronçon - * Licensed under the GNU General Public License v3. - * See Documentation/Licenses/GPLv3.txt for more information. - */ - -#include <Swiften/Jingle/IncomingJingleSession.h> - -namespace Swift { - -IncomingJingleSession::IncomingJingleSession(const std::string& id, const std::vector<JingleContent::ref>& contents) : JingleSession(id, contents) { - -} - -} diff --git a/Swiften/Jingle/IncomingJingleSession.h b/Swiften/Jingle/IncomingJingleSession.h deleted file mode 100644 index 64816f6..0000000 --- a/Swiften/Jingle/IncomingJingleSession.h +++ /dev/null @@ -1,20 +0,0 @@ -/* - * Copyright (c) 2011 Remko Tronçon - * Licensed under the GNU General Public License v3. - * See Documentation/Licenses/GPLv3.txt for more information. - */ - -#pragma once - -#include <boost/shared_ptr.hpp> - -#include <Swiften/Jingle/JingleSession.h> - -namespace Swift { - class IncomingJingleSession : public JingleSession { - public: - IncomingJingleSession(const std::string& id, const std::vector<JingleContent::ref>& contents); - - typedef boost::shared_ptr<IncomingJingleSession> ref; - }; -} diff --git a/Swiften/Jingle/IncomingJingleSessionHandler.h b/Swiften/Jingle/IncomingJingleSessionHandler.h index 5bf9237..4d22a4e 100644 --- a/Swiften/Jingle/IncomingJingleSessionHandler.h +++ b/Swiften/Jingle/IncomingJingleSessionHandler.h @@ -6,13 +6,13 @@ #pragma once -#include <Swiften/Jingle/IncomingJingleSession.h> +#include <Swiften/Jingle/JingleSession.h> namespace Swift { class IncomingJingleSessionHandler { public: virtual ~IncomingJingleSessionHandler(); - virtual bool handleIncomingJingleSession(IncomingJingleSession::ref) = 0; + virtual bool handleIncomingJingleSession(JingleSession::ref, const std::vector<JingleContentPayload::ref>& contents) = 0; }; } diff --git a/Swiften/Jingle/Jingle.h b/Swiften/Jingle/Jingle.h new file mode 100644 index 0000000..ba4dfe3 --- /dev/null +++ b/Swiften/Jingle/Jingle.h @@ -0,0 +1,25 @@ +/* + * Copyright (c) 2011 Remko Tronçon + * Licensed under the GNU General Public License v3. + * See Documentation/Licenses/GPLv3.txt for more information. + */ + +#pragma once + +#include <vector> + +#include <Swiften/Elements/JingleContentPayload.h> + +namespace Swift { + namespace Jingle { + template<typename T> + JingleContentPayload::ref getContentWithDescription(const std::vector<JingleContentPayload::ref>& contents) { + for (size_t i = 0; i < contents.size(); ++i) { + if (contents[i]->getDescription<T>()) { + return contents[i]; + } + } + return JingleContentPayload::ref(); + } + } +} diff --git a/Swiften/Jingle/JingleContentID.h b/Swiften/Jingle/JingleContentID.h new file mode 100644 index 0000000..8d75581 --- /dev/null +++ b/Swiften/Jingle/JingleContentID.h @@ -0,0 +1,23 @@ +/* + * Copyright (c) 2011 Remko Tronçon + * Licensed under the GNU General Public License v3. + * See Documentation/Licenses/GPLv3.txt for more information. + */ + +#pragma once + +#include <string> + +#include <Swiften/Elements/JingleContentPayload.h> + +namespace Swift { + class JingleContentID { + public: + JingleContentID(const std::string& name, JingleContentPayload::Creator creator) : name(name), creator(creator) { + } + + private: + std::string name; + JingleContentPayload::Creator creator; + }; +} diff --git a/Swiften/Jingle/JingleResponder.cpp b/Swiften/Jingle/JingleResponder.cpp index 2397e63..198f9a2 100644 --- a/Swiften/Jingle/JingleResponder.cpp +++ b/Swiften/Jingle/JingleResponder.cpp @@ -9,7 +9,7 @@ #include <boost/smart_ptr/make_shared.hpp> #include <Swiften/Jingle/JingleSessionManager.h> -#include <Swiften/Jingle/IncomingJingleSession.h> +#include <Swiften/Jingle/JingleSessionImpl.h> namespace Swift { @@ -24,12 +24,12 @@ bool JingleResponder::handleSetRequest(const JID& from, const JID&, const std::s } else { sendResponse(from, id, boost::shared_ptr<JinglePayload>()); - IncomingJingleSession::ref session = boost::make_shared<IncomingJingleSession>(id, payload->getContents()); - sessionManager->handleIncomingSession(from, session); + JingleSessionImpl::ref session = boost::make_shared<JingleSessionImpl>(payload->getInitiator(), payload->getSessionID()); + sessionManager->handleIncomingSession(from, session, payload->getContents()); } } else { - JingleSession::ref session = sessionManager->getSession(from, payload->getSessionID()); + JingleSessionImpl::ref session = sessionManager->getSession(from, payload->getSessionID()); if (session) { session->handleIncomingAction(payload); sendResponse(from, id, boost::shared_ptr<JinglePayload>()); diff --git a/Swiften/Jingle/JingleSession.cpp b/Swiften/Jingle/JingleSession.cpp index d255abd..1366191 100644 --- a/Swiften/Jingle/JingleSession.cpp +++ b/Swiften/Jingle/JingleSession.cpp @@ -10,21 +10,11 @@ namespace Swift { -JingleSession::JingleSession(const std::string& id, const std::vector<JingleContent::ref>& contents) : id(id), contents(contents) { +JingleSession::JingleSession(const JID& initiator, const std::string& id) : initiator(initiator), id(id) { } JingleSession::~JingleSession() { } -void JingleSession::handleIncomingAction(JinglePayload::ref) { -} - -void JingleSession::terminate(JinglePayload::Reason::Type reason) { - JinglePayload::ref payload = boost::make_shared<JinglePayload>(JinglePayload::SessionTerminate, id); - payload->setReason(JinglePayload::Reason(reason)); - //onAction(payload) -} - - } diff --git a/Swiften/Jingle/JingleSession.h b/Swiften/Jingle/JingleSession.h index c00492d..fa7da7e 100644 --- a/Swiften/Jingle/JingleSession.h +++ b/Swiften/Jingle/JingleSession.h @@ -7,47 +7,43 @@ #pragma once #include <boost/shared_ptr.hpp> +#include <string> #include <Swiften/Base/boost_bsignals.h> -#include <string> +#include <Swiften/JID/JID.h> #include <Swiften/Elements/JinglePayload.h> -#include <Swiften/Elements/JingleContent.h> -#include <Swiften/Base/foreach.h> namespace Swift { + class JingleContentID; + class JingleSession { - friend class JingleResponder; public: typedef boost::shared_ptr<JingleSession> ref; - JingleSession(const std::string& id, const std::vector<JingleContent::ref>& contents); + JingleSession(const JID& initiator, const std::string& id); virtual ~JingleSession(); - std::string getID() const { - return id; + const JID& getInitiator() const { + return initiator; } - template<typename T> - JingleContent::ref getContentWithDescription() const { - foreach (JingleContent::ref content, contents) { - if (content->getDescription<T>()) { - return content; - } - } - return JingleContent::ref(); - } - - const std::vector<JingleContent::ref> getContents() const { - return contents; + std::string getID() const { + return id; } - void terminate(JinglePayload::Reason::Type reason); + virtual void terminate(JinglePayload::Reason::Type reason) = 0; + virtual void accept(JingleTransportPayload::ref = JingleTransportPayload::ref()) = 0; + virtual void sendTransportInfo(const JingleContentID&, JingleTransportPayload::ref) = 0; + virtual void acceptTransport(const JingleContentID&, JingleTransportPayload::ref) = 0; + virtual void rejectTransport(const JingleContentID&, JingleTransportPayload::ref) = 0; - private: - void handleIncomingAction(JinglePayload::ref); + public: + boost::signal<void ()> onSessionTerminateReceived; + boost::signal<void (const JingleContentID&, JingleTransportPayload::ref)> onTransportInfoReceived; + boost::signal<void (const JingleContentID&, JingleTransportPayload::ref)> onTransportReplaceReceived; private: + JID initiator; std::string id; - std::vector<JingleContent::ref> contents; }; } diff --git a/Swiften/Jingle/JingleSessionImpl.cpp b/Swiften/Jingle/JingleSessionImpl.cpp new file mode 100644 index 0000000..cbb2b42 --- /dev/null +++ b/Swiften/Jingle/JingleSessionImpl.cpp @@ -0,0 +1,42 @@ +/* + * Copyright (c) 2010 Remko Tronçon + * Licensed under the GNU General Public License v3. + * See Documentation/Licenses/GPLv3.txt for more information. + */ + +#include <Swiften/Jingle/JingleSessionImpl.h> + +#include <boost/smart_ptr/make_shared.hpp> + +namespace Swift { + +JingleSessionImpl::JingleSessionImpl(const JID& initiator, const std::string& id) : JingleSession(initiator, id) { +} + +void JingleSessionImpl::handleIncomingAction(JinglePayload::ref) { +} + +void JingleSessionImpl::terminate(JinglePayload::Reason::Type reason) { + JinglePayload::ref payload = boost::make_shared<JinglePayload>(JinglePayload::SessionTerminate, getID()); + payload->setReason(JinglePayload::Reason(reason)); + //onAction(payload) +} + +void JingleSessionImpl::acceptTransport(const JingleContentID&, JingleTransportPayload::ref) { + +} + +void JingleSessionImpl::rejectTransport(const JingleContentID&, JingleTransportPayload::ref) { + +} + +void JingleSessionImpl::accept(JingleTransportPayload::ref) { +} + +void JingleSessionImpl::sendTransportInfo(const JingleContentID&, JingleTransportPayload::ref) { + +} + + + +} diff --git a/Swiften/Jingle/JingleSessionImpl.h b/Swiften/Jingle/JingleSessionImpl.h new file mode 100644 index 0000000..a254ead --- /dev/null +++ b/Swiften/Jingle/JingleSessionImpl.h @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2011 Remko Tronçon + * Licensed under the GNU General Public License v3. + * See Documentation/Licenses/GPLv3.txt for more information. + */ + +#pragma once + +#include <boost/shared_ptr.hpp> + +#include <Swiften/Jingle/JingleSession.h> + +namespace Swift { + class JingleSessionImpl : public JingleSession { + friend class JingleResponder; + public: + typedef boost::shared_ptr<JingleSessionImpl> ref; + + JingleSessionImpl(const JID& initiator, const std::string& id); + + virtual void terminate(JinglePayload::Reason::Type reason); + virtual void accept(JingleTransportPayload::ref); + virtual void sendTransportInfo(const JingleContentID&, JingleTransportPayload::ref); + virtual void acceptTransport(const JingleContentID&, JingleTransportPayload::ref); + virtual void rejectTransport(const JingleContentID&, JingleTransportPayload::ref); + + private: + void handleIncomingAction(JinglePayload::ref); + }; +} diff --git a/Swiften/Jingle/JingleSessionManager.cpp b/Swiften/Jingle/JingleSessionManager.cpp index e60449b..58e90c8 100644 --- a/Swiften/Jingle/JingleSessionManager.cpp +++ b/Swiften/Jingle/JingleSessionManager.cpp @@ -7,6 +7,7 @@ #include <Swiften/Jingle/JingleSessionManager.h> #include <Swiften/Jingle/JingleResponder.h> #include <Swiften/Jingle/IncomingJingleSessionHandler.h> +#include <Swiften/Base/foreach.h> namespace Swift { @@ -18,9 +19,9 @@ JingleSessionManager::~JingleSessionManager() { delete responder; } -JingleSession::ref JingleSessionManager::getSession(const JID& jid, const std::string& id) const { +JingleSessionImpl::ref JingleSessionManager::getSession(const JID& jid, const std::string& id) const { SessionMap::const_iterator i = incomingSessions.find(JIDSession(jid, id)); - return i != incomingSessions.end() ? i->second : JingleSession::ref(); + return i != incomingSessions.end() ? i->second : JingleSessionImpl::ref(); } void JingleSessionManager::addIncomingSessionHandler(IncomingJingleSessionHandler* handler) { @@ -31,10 +32,10 @@ void JingleSessionManager::removeIncomingSessionHandler(IncomingJingleSessionHan incomingSessionHandlers.erase(std::remove(incomingSessionHandlers.begin(), incomingSessionHandlers.end(), handler), incomingSessionHandlers.end()); } -void JingleSessionManager::handleIncomingSession(const JID& from, IncomingJingleSession::ref session) { +void JingleSessionManager::handleIncomingSession(const JID& from, JingleSessionImpl::ref session, const std::vector<JingleContentPayload::ref>& contents) { incomingSessions.insert(std::make_pair(JIDSession(from, session->getID()), session)); foreach (IncomingJingleSessionHandler* handler, incomingSessionHandlers) { - if (handler->handleIncomingJingleSession(session)) { + if (handler->handleIncomingJingleSession(session, contents)) { return; } } diff --git a/Swiften/Jingle/JingleSessionManager.h b/Swiften/Jingle/JingleSessionManager.h index 3e99656..3b23fb0 100644 --- a/Swiften/Jingle/JingleSessionManager.h +++ b/Swiften/Jingle/JingleSessionManager.h @@ -10,7 +10,7 @@ #include <map> #include <Swiften/Base/boost_bsignals.h> -#include <Swiften/Jingle/IncomingJingleSession.h> +#include <Swiften/Jingle/JingleSessionImpl.h> namespace Swift { class IQRouter; @@ -23,13 +23,13 @@ namespace Swift { JingleSessionManager(IQRouter* router); ~JingleSessionManager(); - JingleSession::ref getSession(const JID& jid, const std::string& id) const; + JingleSessionImpl::ref getSession(const JID& jid, const std::string& id) const; void addIncomingSessionHandler(IncomingJingleSessionHandler* handler); void removeIncomingSessionHandler(IncomingJingleSessionHandler* handler); protected: - void handleIncomingSession(const JID& from, IncomingJingleSession::ref); + void handleIncomingSession(const JID& from, JingleSessionImpl::ref, const std::vector<JingleContentPayload::ref>& contents); private: IQRouter* router; @@ -43,7 +43,7 @@ namespace Swift { JID jid; std::string session; }; - typedef std::map<JIDSession, JingleSession::ref> SessionMap; + typedef std::map<JIDSession, JingleSessionImpl::ref> SessionMap; SessionMap incomingSessions; }; } diff --git a/Swiften/Jingle/SConscript b/Swiften/Jingle/SConscript index a8890b7..6b3cfd3 100644 --- a/Swiften/Jingle/SConscript +++ b/Swiften/Jingle/SConscript @@ -1,11 +1,11 @@ Import("swiften_env") sources = [ - "IncomingJingleSession.cpp", + "JingleSession.cpp", + "JingleSessionImpl.cpp", "IncomingJingleSessionHandler.cpp", "JingleSessionManager.cpp", "JingleResponder.cpp", - "JingleSession.cpp", ] swiften_env.Append(SWIFTEN_OBJECTS = swiften_env.SwiftenObject(sources)) diff --git a/Swiften/LinkLocal/DNSSD/Avahi/AvahiBrowseQuery.cpp b/Swiften/LinkLocal/DNSSD/Avahi/AvahiBrowseQuery.cpp new file mode 100644 index 0000000..e31bf87 --- /dev/null +++ b/Swiften/LinkLocal/DNSSD/Avahi/AvahiBrowseQuery.cpp @@ -0,0 +1,60 @@ +/* + * Copyright (c) 2010 Remko Tronçon + * Licensed under the GNU General Public License v3. + * See Documentation/Licenses/GPLv3.txt for more information. + */ + +#include <Swiften/LinkLocal/DNSSD/Avahi/AvahiBrowseQuery.h> + +#include <boost/bind.hpp> +#include <iostream> + +#include <Swiften/LinkLocal/DNSSD/Avahi/AvahiQuerier.h> + +namespace Swift { + +void AvahiBrowseQuery::startBrowsing() { + std::cout << "Start browsing" << std::endl; + assert(!browser); + avahi_threaded_poll_lock(querier->getThreadedPoll()); + browser = avahi_service_browser_new(querier->getClient(), AVAHI_IF_UNSPEC, AVAHI_PROTO_UNSPEC, "_presence._tcp", NULL, static_cast<AvahiLookupFlags>(0), &handleServiceDiscoveredStatic, this); + if (!browser) { + std::cout << "Error" << std::endl; + eventLoop->postEvent(boost::bind(boost::ref(onError)), shared_from_this()); + } + avahi_threaded_poll_unlock(querier->getThreadedPoll()); +} + +void AvahiBrowseQuery::stopBrowsing() { + std::cout << "Stop browsing" << std::endl; + avahi_threaded_poll_lock(querier->getThreadedPoll()); + avahi_service_browser_free(browser); + browser = NULL; + avahi_threaded_poll_unlock(querier->getThreadedPoll()); +} + +void AvahiBrowseQuery::handleServiceDiscovered(AvahiServiceBrowser *, AvahiIfIndex interfaceIndex, AvahiProtocol, AvahiBrowserEvent event, const char *name, const char *type, const char *domain, AvahiLookupResultFlags) { + switch (event) { + case AVAHI_BROWSER_FAILURE: + std::cout << "Service browse error" << std::endl; + eventLoop->postEvent(boost::bind(boost::ref(onError)), shared_from_this()); + break; + case AVAHI_BROWSER_NEW: { + DNSSDServiceID service(name, domain, type, interfaceIndex); + std::cout << "Service discovered " << name << " " << domain << " " << type << " " << interfaceIndex << std::endl; + eventLoop->postEvent(boost::bind(boost::ref(onServiceAdded), service), shared_from_this()); + break; + } + case AVAHI_BROWSER_REMOVE: { + std::cout << "Service went away " << name << " " << domain << " " << type << " " << interfaceIndex << std::endl; + DNSSDServiceID service(name, domain, type, interfaceIndex); + eventLoop->postEvent(boost::bind(boost::ref(onServiceRemoved), service), shared_from_this()); + break; + } + case AVAHI_BROWSER_ALL_FOR_NOW: + case AVAHI_BROWSER_CACHE_EXHAUSTED: + break; + } +} + +} diff --git a/Swiften/LinkLocal/DNSSD/Avahi/AvahiBrowseQuery.h b/Swiften/LinkLocal/DNSSD/Avahi/AvahiBrowseQuery.h index 163a5f6..38e796d 100644 --- a/Swiften/LinkLocal/DNSSD/Avahi/AvahiBrowseQuery.h +++ b/Swiften/LinkLocal/DNSSD/Avahi/AvahiBrowseQuery.h @@ -6,11 +6,11 @@ #pragma once -#include <boost/bind.hpp> +#include <avahi-client/lookup.h> -#include "Swiften/LinkLocal/DNSSD/Avahi/AvahiQuery.h" -#include "Swiften/LinkLocal/DNSSD/DNSSDBrowseQuery.h" -#include "Swiften/EventLoop/EventLoop.h" +#include <Swiften/LinkLocal/DNSSD/Avahi/AvahiQuery.h> +#include <Swiften/LinkLocal/DNSSD/DNSSDBrowseQuery.h> +#include <Swiften/EventLoop/EventLoop.h> namespace Swift { class AvahiQuerier; @@ -20,54 +20,15 @@ namespace Swift { AvahiBrowseQuery(boost::shared_ptr<AvahiQuerier> q, EventLoop* eventLoop) : AvahiQuery(q, eventLoop), browser(NULL) { } - void startBrowsing() { - std::cout << "Start browsing" << std::endl; - assert(!browser); - avahi_threaded_poll_lock(querier->getThreadedPoll()); - browser = avahi_service_browser_new(querier->getClient(), AVAHI_IF_UNSPEC, AVAHI_PROTO_UNSPEC, "_presence._tcp", NULL, static_cast<AvahiLookupFlags>(0), &handleServiceDiscoveredStatic, this); - if (!browser) { - std::cout << "Error" << std::endl; - eventLoop->postEvent(boost::bind(boost::ref(onError)), shared_from_this()); - } - avahi_threaded_poll_unlock(querier->getThreadedPoll()); - } - - void stopBrowsing() { - std::cout << "Stop browsing" << std::endl; - avahi_threaded_poll_lock(querier->getThreadedPoll()); - avahi_service_browser_free(browser); - browser = NULL; - avahi_threaded_poll_unlock(querier->getThreadedPoll()); - } + void startBrowsing(); + void stopBrowsing(); private: static void handleServiceDiscoveredStatic(AvahiServiceBrowser *b, AvahiIfIndex interfaceIndex, AvahiProtocol protocol, AvahiBrowserEvent event, const char *name, const char *type, const char *domain, AvahiLookupResultFlags flags, void* context) { static_cast<AvahiBrowseQuery*>(context)->handleServiceDiscovered(b, interfaceIndex, protocol, event, name, type, domain, flags); } - void handleServiceDiscovered(AvahiServiceBrowser *, AvahiIfIndex interfaceIndex, AvahiProtocol, AvahiBrowserEvent event, const char *name, const char *type, const char *domain, AvahiLookupResultFlags) { - switch (event) { - case AVAHI_BROWSER_FAILURE: - std::cout << "Service browse error" << std::endl; - eventLoop->postEvent(boost::bind(boost::ref(onError)), shared_from_this()); - break; - case AVAHI_BROWSER_NEW: { - DNSSDServiceID service(name, domain, type, interfaceIndex); - std::cout << "Service discovered " << name << " " << domain << " " << type << " " << interfaceIndex << std::endl; - eventLoop->postEvent(boost::bind(boost::ref(onServiceAdded), service), shared_from_this()); - break; - } - case AVAHI_BROWSER_REMOVE: { - std::cout << "Service went away " << name << " " << domain << " " << type << " " << interfaceIndex << std::endl; - DNSSDServiceID service(name, domain, type, interfaceIndex); - eventLoop->postEvent(boost::bind(boost::ref(onServiceRemoved), service), shared_from_this()); - break; - } - case AVAHI_BROWSER_ALL_FOR_NOW: - case AVAHI_BROWSER_CACHE_EXHAUSTED: - break; - } - } + void handleServiceDiscovered(AvahiServiceBrowser *, AvahiIfIndex interfaceIndex, AvahiProtocol, AvahiBrowserEvent event, const char *name, const char *type, const char *domain, AvahiLookupResultFlags); private: AvahiServiceBrowser* browser; diff --git a/Swiften/LinkLocal/DNSSD/Avahi/AvahiQuerier.cpp b/Swiften/LinkLocal/DNSSD/Avahi/AvahiQuerier.cpp index dd189d9..e9f5564 100644 --- a/Swiften/LinkLocal/DNSSD/Avahi/AvahiQuerier.cpp +++ b/Swiften/LinkLocal/DNSSD/Avahi/AvahiQuerier.cpp @@ -4,14 +4,14 @@ * See Documentation/Licenses/GPLv3.txt for more information. */ -#include "Swiften/LinkLocal/DNSSD/Avahi/AvahiQuerier.h" +#include <Swiften/LinkLocal/DNSSD/Avahi/AvahiQuerier.h> #include <iostream> -#include "Swiften/LinkLocal/DNSSD/Avahi/AvahiBrowseQuery.h" -#include "Swiften/LinkLocal/DNSSD/Avahi/AvahiResolveServiceQuery.h" -#include "Swiften/LinkLocal/DNSSD/Avahi/AvahiResolveHostnameQuery.h" -#include "Swiften/LinkLocal/DNSSD/Avahi/AvahiRegisterQuery.h" +#include <Swiften/LinkLocal/DNSSD/Avahi/AvahiBrowseQuery.h> +#include <Swiften/LinkLocal/DNSSD/Avahi/AvahiResolveServiceQuery.h> +#include <Swiften/LinkLocal/DNSSD/Avahi/AvahiResolveHostnameQuery.h> +#include <Swiften/LinkLocal/DNSSD/Avahi/AvahiRegisterQuery.h> namespace Swift { diff --git a/Swiften/LinkLocal/DNSSD/Avahi/AvahiQuerier.h b/Swiften/LinkLocal/DNSSD/Avahi/AvahiQuerier.h index bfb017e..e76334d 100644 --- a/Swiften/LinkLocal/DNSSD/Avahi/AvahiQuerier.h +++ b/Swiften/LinkLocal/DNSSD/Avahi/AvahiQuerier.h @@ -15,7 +15,7 @@ #include <avahi-common/malloc.h> #include <avahi-common/error.h> -#include "Swiften/LinkLocal/DNSSD/DNSSDQuerier.h" +#include <Swiften/LinkLocal/DNSSD/DNSSDQuerier.h> namespace Swift { class ByteArray; diff --git a/Swiften/LinkLocal/DNSSD/Avahi/AvahiQuery.cpp b/Swiften/LinkLocal/DNSSD/Avahi/AvahiQuery.cpp index 1b40dfd..3b0e8da 100644 --- a/Swiften/LinkLocal/DNSSD/Avahi/AvahiQuery.cpp +++ b/Swiften/LinkLocal/DNSSD/Avahi/AvahiQuery.cpp @@ -4,8 +4,8 @@ * See Documentation/Licenses/GPLv3.txt for more information. */ -#include "Swiften/LinkLocal/DNSSD/Avahi/AvahiQuery.h" -#include "Swiften/LinkLocal/DNSSD/Avahi/AvahiQuerier.h" +#include <Swiften/LinkLocal/DNSSD/Avahi/AvahiQuery.h> +#include <Swiften/LinkLocal/DNSSD/Avahi/AvahiQuerier.h> namespace Swift { diff --git a/Swiften/LinkLocal/DNSSD/Avahi/AvahiQuery.h b/Swiften/LinkLocal/DNSSD/Avahi/AvahiQuery.h index f5df032..047e1cd 100644 --- a/Swiften/LinkLocal/DNSSD/Avahi/AvahiQuery.h +++ b/Swiften/LinkLocal/DNSSD/Avahi/AvahiQuery.h @@ -9,7 +9,7 @@ #include <boost/shared_ptr.hpp> #include <boost/enable_shared_from_this.hpp> -#include "Swiften/EventLoop/EventOwner.h" +#include <Swiften/EventLoop/EventOwner.h> namespace Swift { class AvahiQuerier; diff --git a/Swiften/LinkLocal/DNSSD/Avahi/AvahiRegisterQuery.cpp b/Swiften/LinkLocal/DNSSD/Avahi/AvahiRegisterQuery.cpp new file mode 100644 index 0000000..7975e7b --- /dev/null +++ b/Swiften/LinkLocal/DNSSD/Avahi/AvahiRegisterQuery.cpp @@ -0,0 +1,101 @@ +/* + * Copyright (c) 2010 Remko Tronçon + * Licensed under the GNU General Public License v3. + * See Documentation/Licenses/GPLv3.txt for more information. + */ + +#include <Swiften/LinkLocal/DNSSD/Avahi/AvahiRegisterQuery.h> + +#include <iostream> +#include <boost/bind.hpp> + +#include <Swiften/LinkLocal/DNSSD/Avahi/AvahiQuerier.h> + +namespace Swift { + +void AvahiRegisterQuery::registerService() { + std::cout << "Registering service " << name << ":" << port << std::endl; + avahi_threaded_poll_lock(querier->getThreadedPoll()); + if (!group) { + std::cout << "Creating entry group" << std::endl; + group = avahi_entry_group_new(querier->getClient(), handleEntryGroupChange, this); + if (!group) { + std::cout << "Error ceating entry group" << std::endl; + eventLoop->postEvent(boost::bind(boost::ref(onRegisterFinished), boost::optional<DNSSDServiceID>()), shared_from_this()); + } + } + + doRegisterService(); + avahi_threaded_poll_unlock(querier->getThreadedPoll()); +} + +void AvahiRegisterQuery::unregisterService() { + if (group) { + avahi_entry_group_free(group); + group = NULL; + } +} + +void AvahiRegisterQuery::updateServiceInfo(const ByteArray& txtRecord) { + this->txtRecord = txtRecord; + avahi_threaded_poll_lock(querier->getThreadedPoll()); + assert(group); + avahi_entry_group_reset(group); + doRegisterService(); + avahi_threaded_poll_unlock(querier->getThreadedPoll()); +} + +void AvahiRegisterQuery::doRegisterService() { + AvahiStringList* txtList; + avahi_string_list_parse(txtRecord.getData(), txtRecord.getSize(), &txtList); + + int result = avahi_entry_group_add_service_strlst(group, AVAHI_IF_UNSPEC, AVAHI_PROTO_UNSPEC, static_cast<AvahiPublishFlags>(0), name.c_str(), "_presence._tcp", NULL, NULL, port, txtList); + if (result < 0) { + std::cout << "Error registering service: " << avahi_strerror(result) << std::endl; + eventLoop->postEvent(boost::bind(boost::ref(onRegisterFinished), boost::optional<DNSSDServiceID>()), shared_from_this()); + } + result = avahi_entry_group_commit(group); + if (result < 0) { + std::cout << "Error registering service: " << avahi_strerror(result) << std::endl; + } +} + +void AvahiRegisterQuery::handleEntryGroupChange(AvahiEntryGroup* g, AvahiEntryGroupState state) { + std::cout << "ENtry group callback: " << state << std::endl; + switch (state) { + case AVAHI_ENTRY_GROUP_ESTABLISHED : + // Domain is a hack! + eventLoop->postEvent(boost::bind(boost::ref(onRegisterFinished), boost::optional<DNSSDServiceID>(DNSSDServiceID(name, "local", "_presence._tcp", 0))), shared_from_this()); + std::cout << "Entry group established" << std::endl; + break; + case AVAHI_ENTRY_GROUP_COLLISION : { + std::cout << "Entry group collision" << std::endl; + /*char *n; + n = avahi_alternative_service_name(name); + avahi_free(name); + name = n;*/ + break; + } + + case AVAHI_ENTRY_GROUP_FAILURE : + std::cout << "Entry group failure " << avahi_strerror(avahi_client_errno(avahi_entry_group_get_client(g))) << std::endl; + break; + + case AVAHI_ENTRY_GROUP_UNCOMMITED: + case AVAHI_ENTRY_GROUP_REGISTERING: + ; + + /* + DNSServiceErrorType result = DNSServiceRegister( + &sdRef, 0, 0, name.c_str(), "_presence._tcp", NULL, NULL, port, + txtRecord.getSize(), txtRecord.getData(), + &AvahiRegisterQuery::handleServiceRegisteredStatic, this); + if (result != kDNSServiceErr_NoError) { + sdRef = NULL; + }*/ + //eventLoop->postEvent(boost::bind(boost::ref(onRegisterFinished), boost::optional<DNSSDServiceID>()), shared_from_this()); + } +} + + +} diff --git a/Swiften/LinkLocal/DNSSD/Avahi/AvahiRegisterQuery.h b/Swiften/LinkLocal/DNSSD/Avahi/AvahiRegisterQuery.h index 07966af..b47ed12 100644 --- a/Swiften/LinkLocal/DNSSD/Avahi/AvahiRegisterQuery.h +++ b/Swiften/LinkLocal/DNSSD/Avahi/AvahiRegisterQuery.h @@ -8,10 +8,10 @@ #include <avahi-client/publish.h> -#include "Swiften/LinkLocal/DNSSD/Avahi/AvahiQuery.h" -#include "Swiften/LinkLocal/DNSSD/DNSSDRegisterQuery.h" -#include "Swiften/Base/ByteArray.h" -#include "Swiften/EventLoop/EventLoop.h" +#include <Swiften/LinkLocal/DNSSD/Avahi/AvahiQuery.h> +#include <Swiften/LinkLocal/DNSSD/DNSSDRegisterQuery.h> +#include <Swiften/Base/ByteArray.h> +#include <Swiften/EventLoop/EventLoop.h> namespace Swift { class AvahiQuerier; @@ -21,94 +21,18 @@ namespace Swift { AvahiRegisterQuery(const std::string& name, int port, const ByteArray& txtRecord, boost::shared_ptr<AvahiQuerier> querier, EventLoop* eventLoop) : AvahiQuery(querier, eventLoop), name(name), port(port), txtRecord(txtRecord), group(0) { } - void registerService() { - std::cout << "Registering service " << name << ":" << port << std::endl; - avahi_threaded_poll_lock(querier->getThreadedPoll()); - if (!group) { - std::cout << "Creating entry group" << std::endl; - group = avahi_entry_group_new(querier->getClient(), handleEntryGroupChange, this); - if (!group) { - std::cout << "Error ceating entry group" << std::endl; - eventLoop->postEvent(boost::bind(boost::ref(onRegisterFinished), boost::optional<DNSSDServiceID>()), shared_from_this()); - } - } - - doRegisterService(); - avahi_threaded_poll_unlock(querier->getThreadedPoll()); - } - - void unregisterService() { - if (group) { - avahi_entry_group_free(group); - group = NULL; - } - } - - void updateServiceInfo(const ByteArray& txtRecord) { - this->txtRecord = txtRecord; - avahi_threaded_poll_lock(querier->getThreadedPoll()); - assert(group); - avahi_entry_group_reset(group); - doRegisterService(); - avahi_threaded_poll_unlock(querier->getThreadedPoll()); - } + void registerService(); + void unregisterService(); + void updateServiceInfo(const ByteArray& txtRecord); private: - void doRegisterService() { - AvahiStringList* txtList; - avahi_string_list_parse(txtRecord.getData(), txtRecord.getSize(), &txtList); - - int result = avahi_entry_group_add_service_strlst(group, AVAHI_IF_UNSPEC, AVAHI_PROTO_UNSPEC, static_cast<AvahiPublishFlags>(0), name.c_str(), "_presence._tcp", NULL, NULL, port, txtList); - if (result < 0) { - std::cout << "Error registering service: " << avahi_strerror(result) << std::endl; - eventLoop->postEvent(boost::bind(boost::ref(onRegisterFinished), boost::optional<DNSSDServiceID>()), shared_from_this()); - } - result = avahi_entry_group_commit(group); - if (result < 0) { - std::cout << "Error registering service: " << avahi_strerror(result) << std::endl; - } - } + void doRegisterService(); static void handleEntryGroupChange(AvahiEntryGroup *g, AvahiEntryGroupState state, void *userdata) { static_cast<AvahiRegisterQuery*>(userdata)->handleEntryGroupChange(g, state); } - void handleEntryGroupChange(AvahiEntryGroup* g, AvahiEntryGroupState state) { - std::cout << "ENtry group callback: " << state << std::endl; - switch (state) { - case AVAHI_ENTRY_GROUP_ESTABLISHED : - // Domain is a hack! - eventLoop->postEvent(boost::bind(boost::ref(onRegisterFinished), boost::optional<DNSSDServiceID>(DNSSDServiceID(name, "local", "_presence._tcp", 0))), shared_from_this()); - std::cout << "Entry group established" << std::endl; - break; - case AVAHI_ENTRY_GROUP_COLLISION : { - std::cout << "Entry group collision" << std::endl; - /*char *n; - n = avahi_alternative_service_name(name); - avahi_free(name); - name = n;*/ - break; - } - - case AVAHI_ENTRY_GROUP_FAILURE : - std::cout << "Entry group failure " << avahi_strerror(avahi_client_errno(avahi_entry_group_get_client(g))) << std::endl; - break; - - case AVAHI_ENTRY_GROUP_UNCOMMITED: - case AVAHI_ENTRY_GROUP_REGISTERING: - ; - - /* - DNSServiceErrorType result = DNSServiceRegister( - &sdRef, 0, 0, name.c_str(), "_presence._tcp", NULL, NULL, port, - txtRecord.getSize(), txtRecord.getData(), - &AvahiRegisterQuery::handleServiceRegisteredStatic, this); - if (result != kDNSServiceErr_NoError) { - sdRef = NULL; - }*/ - //eventLoop->postEvent(boost::bind(boost::ref(onRegisterFinished), boost::optional<DNSSDServiceID>()), shared_from_this()); - } - } + void handleEntryGroupChange(AvahiEntryGroup* g, AvahiEntryGroupState state); /* static void handleServiceRegisteredStatic(DNSServiceRef, DNSServiceFlags, DNSServiceErrorType errorCode, const char *name, const char *regtype, const char *domain, void *context) { diff --git a/Swiften/LinkLocal/DNSSD/Avahi/AvahiResolveHostnameQuery.cpp b/Swiften/LinkLocal/DNSSD/Avahi/AvahiResolveHostnameQuery.cpp new file mode 100644 index 0000000..d9a1c5c --- /dev/null +++ b/Swiften/LinkLocal/DNSSD/Avahi/AvahiResolveHostnameQuery.cpp @@ -0,0 +1,22 @@ +/* + * Copyright (c) 2010 Remko Tronçon + * Licensed under the GNU General Public License v3. + * See Documentation/Licenses/GPLv3.txt for more information. + */ + +#include <Swiften/LinkLocal/DNSSD/Avahi/AvahiResolveHostnameQuery.h> + +#include <iostream> +#include <boost/bind.hpp> + +namespace Swift { + +AvahiResolveHostnameQuery::AvahiResolveHostnameQuery(const std::string& hostname, int, boost::shared_ptr<AvahiQuerier> querier, EventLoop* eventLoop) : AvahiQuery(querier, eventLoop), hostname(hostname) { + std::cout << "Resolving hostname " << hostname << std::endl; +} + +void AvahiResolveHostnameQuery::run() { + eventLoop->postEvent(boost::bind(boost::ref(onHostnameResolved), boost::optional<HostAddress>(HostAddress(hostname))), shared_from_this()); +} + +} diff --git a/Swiften/LinkLocal/DNSSD/Avahi/AvahiResolveHostnameQuery.h b/Swiften/LinkLocal/DNSSD/Avahi/AvahiResolveHostnameQuery.h index 00712f1..5ee6346 100644 --- a/Swiften/LinkLocal/DNSSD/Avahi/AvahiResolveHostnameQuery.h +++ b/Swiften/LinkLocal/DNSSD/Avahi/AvahiResolveHostnameQuery.h @@ -7,10 +7,10 @@ #pragma once #include <string> -#include "Swiften/LinkLocal/DNSSD/Avahi/AvahiQuery.h" -#include "Swiften/LinkLocal/DNSSD/DNSSDResolveHostnameQuery.h" -#include "Swiften/EventLoop/EventLoop.h" -#include "Swiften/Network/HostAddress.h" +#include <Swiften/LinkLocal/DNSSD/Avahi/AvahiQuery.h> +#include <Swiften/LinkLocal/DNSSD/DNSSDResolveHostnameQuery.h> +#include <Swiften/EventLoop/EventLoop.h> +#include <Swiften/Network/HostAddress.h> #include <netinet/in.h> @@ -19,13 +19,9 @@ namespace Swift { class AvahiResolveHostnameQuery : public DNSSDResolveHostnameQuery, public AvahiQuery { public: - AvahiResolveHostnameQuery(const std::string& hostname, int, boost::shared_ptr<AvahiQuerier> querier, EventLoop* eventLoop) : AvahiQuery(querier, eventLoop), hostname(hostname) { - std::cout << "Resolving hostname " << hostname << std::endl; - } + AvahiResolveHostnameQuery(const std::string& hostname, int, boost::shared_ptr<AvahiQuerier> querier, EventLoop* eventLoop); - void run() { - eventLoop->postEvent(boost::bind(boost::ref(onHostnameResolved), boost::optional<HostAddress>(HostAddress(hostname))), shared_from_this()); - } + void run(); void finish() { } diff --git a/Swiften/LinkLocal/DNSSD/Avahi/AvahiResolveServiceQuery.cpp b/Swiften/LinkLocal/DNSSD/Avahi/AvahiResolveServiceQuery.cpp new file mode 100644 index 0000000..24fe067 --- /dev/null +++ b/Swiften/LinkLocal/DNSSD/Avahi/AvahiResolveServiceQuery.cpp @@ -0,0 +1,65 @@ +/* + * Copyright (c) 2010 Remko Tronçon + * Licensed under the GNU General Public License v3. + * See Documentation/Licenses/GPLv3.txt for more information. + */ + +#include <Swiften/LinkLocal/DNSSD/Avahi/AvahiResolveServiceQuery.h> + +#include <boost/bind.hpp> +#include <iostream> + +#include <Swiften/LinkLocal/DNSSD/Avahi/AvahiQuerier.h> + +namespace Swift { + +void AvahiResolveServiceQuery::start() { + std::cout << "Start resolving " << service.getName() << " " << service.getType() << " " << service.getDomain() << std::endl; + avahi_threaded_poll_lock(querier->getThreadedPoll()); + assert(!resolver); + resolver = avahi_service_resolver_new(querier->getClient(), service.getNetworkInterfaceID(), AVAHI_PROTO_UNSPEC, service.getName().c_str(), service.getType().c_str(), service.getDomain().c_str(), AVAHI_PROTO_UNSPEC, static_cast<AvahiLookupFlags>(0), handleServiceResolvedStatic, this); + if (!resolver) { + std::cout << "Error starting resolver" << std::endl; + eventLoop->postEvent(boost::bind(boost::ref(onServiceResolved), boost::optional<Result>()), shared_from_this()); + } + avahi_threaded_poll_unlock(querier->getThreadedPoll()); +} + +void AvahiResolveServiceQuery::stop() { + std::cout << "Stop resolving" << std::endl; + avahi_threaded_poll_lock(querier->getThreadedPoll()); + avahi_service_resolver_free(resolver); + resolver = NULL; + avahi_threaded_poll_unlock(querier->getThreadedPoll()); +} + +void AvahiResolveServiceQuery::handleServiceResolved(AvahiServiceResolver* resolver, AvahiIfIndex, AvahiProtocol, AvahiResolverEvent event, const char *name, const char * type, const char* domain, const char * /*host_name*/, const AvahiAddress *address, uint16_t port, AvahiStringList *txt, AvahiLookupResultFlags) { + std::cout << "Resolve finished" << std::endl; + switch(event) { + case AVAHI_RESOLVER_FAILURE: + std::cout << "Resolve error " << avahi_strerror(avahi_client_errno(avahi_service_resolver_get_client(resolver))) << std::endl; + eventLoop->postEvent(boost::bind(boost::ref(onServiceResolved), boost::optional<Result>()), shared_from_this()); + break; + case AVAHI_RESOLVER_FOUND: { + std::cout << "Success" << std::endl; + char a[AVAHI_ADDRESS_STR_MAX]; + avahi_address_snprint(a, sizeof(a), address); + + ByteArray txtRecord; + txtRecord.resize(1024); + avahi_string_list_serialize(txt, txtRecord.getData(), txtRecord.getSize()); + + // FIXME: Probably not accurate + std::string fullname = std::string(name) + "." + std::string(type) + "." + std::string(domain) + "."; + std::cout << "Result: " << fullname << "->" << std::string(a) << ":" << port << std::endl; + eventLoop->postEvent( + boost::bind( + boost::ref(onServiceResolved), + Result(fullname, std::string(a), port, txtRecord)), + shared_from_this()); + break; + } + } +} + +} diff --git a/Swiften/LinkLocal/DNSSD/Avahi/AvahiResolveServiceQuery.h b/Swiften/LinkLocal/DNSSD/Avahi/AvahiResolveServiceQuery.h index e9c4db1..a39d732 100644 --- a/Swiften/LinkLocal/DNSSD/Avahi/AvahiResolveServiceQuery.h +++ b/Swiften/LinkLocal/DNSSD/Avahi/AvahiResolveServiceQuery.h @@ -6,11 +6,13 @@ #pragma once -#include "Swiften/LinkLocal/DNSSD/Avahi/AvahiQuery.h" -#include "Swiften/LinkLocal/DNSSD/DNSSDResolveServiceQuery.h" -#include "Swiften/LinkLocal/LinkLocalServiceInfo.h" -#include "Swiften/Base/ByteArray.h" -#include "Swiften/EventLoop/EventLoop.h" +#include <avahi-client/lookup.h> + +#include <Swiften/LinkLocal/DNSSD/Avahi/AvahiQuery.h> +#include <Swiften/LinkLocal/DNSSD/DNSSDResolveServiceQuery.h> +#include <Swiften/LinkLocal/LinkLocalServiceInfo.h> +#include <Swiften/Base/ByteArray.h> +#include <Swiften/EventLoop/EventLoop.h> namespace Swift { class AvahiQuerier; @@ -20,59 +22,15 @@ namespace Swift { AvahiResolveServiceQuery(const DNSSDServiceID& service, boost::shared_ptr<AvahiQuerier> querier, EventLoop* eventLoop) : AvahiQuery(querier, eventLoop), service(service), resolver(NULL) { } - void start() { - std::cout << "Start resolving " << service.getName() << " " << service.getType() << " " << service.getDomain() << std::endl; - avahi_threaded_poll_lock(querier->getThreadedPoll()); - assert(!resolver); - resolver = avahi_service_resolver_new(querier->getClient(), service.getNetworkInterfaceID(), AVAHI_PROTO_UNSPEC, service.getName().c_str(), service.getType().c_str(), service.getDomain().c_str(), AVAHI_PROTO_UNSPEC, static_cast<AvahiLookupFlags>(0), handleServiceResolvedStatic, this); - if (!resolver) { - std::cout << "Error starting resolver" << std::endl; - eventLoop->postEvent(boost::bind(boost::ref(onServiceResolved), boost::optional<Result>()), shared_from_this()); - } - avahi_threaded_poll_unlock(querier->getThreadedPoll()); - } - - void stop() { - std::cout << "Stop resolving" << std::endl; - avahi_threaded_poll_lock(querier->getThreadedPoll()); - avahi_service_resolver_free(resolver); - resolver = NULL; - avahi_threaded_poll_unlock(querier->getThreadedPoll()); - } + void start(); + void stop(); private: static void handleServiceResolvedStatic(AvahiServiceResolver* resolver, AvahiIfIndex interfaceIndex, AvahiProtocol protocol, AvahiResolverEvent event, const char *name, const char *type, const char *domain, const char *host_name, const AvahiAddress *address, uint16_t port, AvahiStringList *txt, AvahiLookupResultFlags flags, void* context) { static_cast<AvahiResolveServiceQuery*>(context)->handleServiceResolved(resolver, interfaceIndex, protocol, event, name, type, domain, host_name, address, port, txt, flags); } - void handleServiceResolved(AvahiServiceResolver* resolver, AvahiIfIndex, AvahiProtocol, AvahiResolverEvent event, const char *name, const char * type, const char* domain, const char * /*host_name*/, const AvahiAddress *address, uint16_t port, AvahiStringList *txt, AvahiLookupResultFlags) { - std::cout << "Resolve finished" << std::endl; - switch(event) { - case AVAHI_RESOLVER_FAILURE: - std::cout << "Resolve error " << avahi_strerror(avahi_client_errno(avahi_service_resolver_get_client(resolver))) << std::endl; - eventLoop->postEvent(boost::bind(boost::ref(onServiceResolved), boost::optional<Result>()), shared_from_this()); - break; - case AVAHI_RESOLVER_FOUND: { - std::cout << "Success" << std::endl; - char a[AVAHI_ADDRESS_STR_MAX]; - avahi_address_snprint(a, sizeof(a), address); - - ByteArray txtRecord; - txtRecord.resize(1024); - avahi_string_list_serialize(txt, txtRecord.getData(), txtRecord.getSize()); - - // FIXME: Probably not accurate - std::string fullname = std::string(name) + "." + std::string(type) + "." + std::string(domain) + "."; - std::cout << "Result: " << fullname << "->" << std::string(a) << ":" << port << std::endl; - eventLoop->postEvent( - boost::bind( - boost::ref(onServiceResolved), - Result(fullname, std::string(a), port, txtRecord)), - shared_from_this()); - break; - } - } - } + void handleServiceResolved(AvahiServiceResolver* resolver, AvahiIfIndex, AvahiProtocol, AvahiResolverEvent event, const char *name, const char * type, const char* domain, const char * /*host_name*/, const AvahiAddress *address, uint16_t port, AvahiStringList *txt, AvahiLookupResultFlags); private: DNSSDServiceID service; diff --git a/Swiften/LinkLocal/DNSSD/Bonjour/BonjourBrowseQuery.h b/Swiften/LinkLocal/DNSSD/Bonjour/BonjourBrowseQuery.h index 52c47d7..6e79290 100644 --- a/Swiften/LinkLocal/DNSSD/Bonjour/BonjourBrowseQuery.h +++ b/Swiften/LinkLocal/DNSSD/Bonjour/BonjourBrowseQuery.h @@ -6,9 +6,9 @@ #pragma once -#include "Swiften/LinkLocal/DNSSD/Bonjour/BonjourQuery.h" -#include "Swiften/LinkLocal/DNSSD/DNSSDBrowseQuery.h" -#include "Swiften/EventLoop/EventLoop.h" +#include <Swiften/LinkLocal/DNSSD/Bonjour/BonjourQuery.h> +#include <Swiften/LinkLocal/DNSSD/DNSSDBrowseQuery.h> +#include <Swiften/EventLoop/EventLoop.h> namespace Swift { class BonjourQuerier; diff --git a/Swiften/LinkLocal/DNSSD/Bonjour/BonjourQuerier.cpp b/Swiften/LinkLocal/DNSSD/Bonjour/BonjourQuerier.cpp index 2d346d9..06f175c 100644 --- a/Swiften/LinkLocal/DNSSD/Bonjour/BonjourQuerier.cpp +++ b/Swiften/LinkLocal/DNSSD/Bonjour/BonjourQuerier.cpp @@ -4,17 +4,17 @@ * See Documentation/Licenses/GPLv3.txt for more information. */ -#include "Swiften/LinkLocal/DNSSD/Bonjour/BonjourQuerier.h" +#include <Swiften/LinkLocal/DNSSD/Bonjour/BonjourQuerier.h> #include <unistd.h> #include <sys/socket.h> #include <fcntl.h> -#include "Swiften/LinkLocal/DNSSD/Bonjour/BonjourBrowseQuery.h" -#include "Swiften/LinkLocal/DNSSD/Bonjour/BonjourRegisterQuery.h" -#include "Swiften/LinkLocal/DNSSD/Bonjour/BonjourResolveServiceQuery.h" -#include "Swiften/LinkLocal/DNSSD/Bonjour/BonjourResolveHostnameQuery.h" -#include "Swiften/Base/foreach.h" +#include <Swiften/LinkLocal/DNSSD/Bonjour/BonjourBrowseQuery.h> +#include <Swiften/LinkLocal/DNSSD/Bonjour/BonjourRegisterQuery.h> +#include <Swiften/LinkLocal/DNSSD/Bonjour/BonjourResolveServiceQuery.h> +#include <Swiften/LinkLocal/DNSSD/Bonjour/BonjourResolveHostnameQuery.h> +#include <Swiften/Base/foreach.h> namespace Swift { diff --git a/Swiften/LinkLocal/DNSSD/Bonjour/BonjourQuerier.h b/Swiften/LinkLocal/DNSSD/Bonjour/BonjourQuerier.h index edd3056..1109fb7 100644 --- a/Swiften/LinkLocal/DNSSD/Bonjour/BonjourQuerier.h +++ b/Swiften/LinkLocal/DNSSD/Bonjour/BonjourQuerier.h @@ -9,11 +9,11 @@ #include <boost/shared_ptr.hpp> #include <boost/enable_shared_from_this.hpp> #include <list> -#include <boost/thread.hpp> +#include <boost/thread/thread.hpp> #include <boost/thread/mutex.hpp> -#include "Swiften/LinkLocal/DNSSD/DNSSDQuerier.h" -#include "Swiften/LinkLocal/DNSSD/Bonjour/BonjourQuery.h" +#include <Swiften/LinkLocal/DNSSD/DNSSDQuerier.h> +#include <Swiften/LinkLocal/DNSSD/Bonjour/BonjourQuery.h> namespace Swift { class ByteArray; diff --git a/Swiften/LinkLocal/DNSSD/Bonjour/BonjourQuery.cpp b/Swiften/LinkLocal/DNSSD/Bonjour/BonjourQuery.cpp index d7ff5d5..9ff4b9f 100644 --- a/Swiften/LinkLocal/DNSSD/Bonjour/BonjourQuery.cpp +++ b/Swiften/LinkLocal/DNSSD/Bonjour/BonjourQuery.cpp @@ -4,8 +4,8 @@ * See Documentation/Licenses/GPLv3.txt for more information. */ -#include "Swiften/LinkLocal/DNSSD/Bonjour/BonjourQuery.h" -#include "Swiften/LinkLocal/DNSSD/Bonjour/BonjourQuerier.h" +#include <Swiften/LinkLocal/DNSSD/Bonjour/BonjourQuery.h> +#include <Swiften/LinkLocal/DNSSD/Bonjour/BonjourQuerier.h> namespace Swift { diff --git a/Swiften/LinkLocal/DNSSD/Bonjour/BonjourQuery.h b/Swiften/LinkLocal/DNSSD/Bonjour/BonjourQuery.h index e3cd9a5..d91c57c 100644 --- a/Swiften/LinkLocal/DNSSD/Bonjour/BonjourQuery.h +++ b/Swiften/LinkLocal/DNSSD/Bonjour/BonjourQuery.h @@ -11,7 +11,7 @@ #include <boost/enable_shared_from_this.hpp> #include <boost/thread/mutex.hpp> -#include "Swiften/EventLoop/EventOwner.h" +#include <Swiften/EventLoop/EventOwner.h> namespace Swift { class BonjourQuerier; diff --git a/Swiften/LinkLocal/DNSSD/Bonjour/BonjourRegisterQuery.h b/Swiften/LinkLocal/DNSSD/Bonjour/BonjourRegisterQuery.h index 7eb7ae1..b31e441 100644 --- a/Swiften/LinkLocal/DNSSD/Bonjour/BonjourRegisterQuery.h +++ b/Swiften/LinkLocal/DNSSD/Bonjour/BonjourRegisterQuery.h @@ -6,10 +6,10 @@ #pragma once -#include "Swiften/LinkLocal/DNSSD/Bonjour/BonjourQuery.h" -#include "Swiften/LinkLocal/DNSSD/DNSSDRegisterQuery.h" -#include "Swiften/Base/ByteArray.h" -#include "Swiften/EventLoop/EventLoop.h" +#include <Swiften/LinkLocal/DNSSD/Bonjour/BonjourQuery.h> +#include <Swiften/LinkLocal/DNSSD/DNSSDRegisterQuery.h> +#include <Swiften/Base/ByteArray.h> +#include <Swiften/EventLoop/EventLoop.h> namespace Swift { class BonjourQuerier; diff --git a/Swiften/LinkLocal/DNSSD/Bonjour/BonjourResolveHostnameQuery.h b/Swiften/LinkLocal/DNSSD/Bonjour/BonjourResolveHostnameQuery.h index b08b0b7..9fdd3d5 100644 --- a/Swiften/LinkLocal/DNSSD/Bonjour/BonjourResolveHostnameQuery.h +++ b/Swiften/LinkLocal/DNSSD/Bonjour/BonjourResolveHostnameQuery.h @@ -9,10 +9,10 @@ #pragma GCC diagnostic ignored "-Wold-style-cast" #include <string> -#include "Swiften/LinkLocal/DNSSD/Bonjour/BonjourQuery.h" -#include "Swiften/LinkLocal/DNSSD/DNSSDResolveHostnameQuery.h" -#include "Swiften/EventLoop/EventLoop.h" -#include "Swiften/Network/HostAddress.h" +#include <Swiften/LinkLocal/DNSSD/Bonjour/BonjourQuery.h> +#include <Swiften/LinkLocal/DNSSD/DNSSDResolveHostnameQuery.h> +#include <Swiften/EventLoop/EventLoop.h> +#include <Swiften/Network/HostAddress.h> #include <netinet/in.h> diff --git a/Swiften/LinkLocal/DNSSD/Bonjour/BonjourResolveServiceQuery.h b/Swiften/LinkLocal/DNSSD/Bonjour/BonjourResolveServiceQuery.h index 0501b56..2d40e72 100644 --- a/Swiften/LinkLocal/DNSSD/Bonjour/BonjourResolveServiceQuery.h +++ b/Swiften/LinkLocal/DNSSD/Bonjour/BonjourResolveServiceQuery.h @@ -6,11 +6,11 @@ #pragma once -#include "Swiften/LinkLocal/DNSSD/Bonjour/BonjourQuery.h" -#include "Swiften/LinkLocal/DNSSD/DNSSDResolveServiceQuery.h" -#include "Swiften/LinkLocal/LinkLocalServiceInfo.h" -#include "Swiften/Base/ByteArray.h" -#include "Swiften/EventLoop/EventLoop.h" +#include <Swiften/LinkLocal/DNSSD/Bonjour/BonjourQuery.h> +#include <Swiften/LinkLocal/DNSSD/DNSSDResolveServiceQuery.h> +#include <Swiften/LinkLocal/LinkLocalServiceInfo.h> +#include <Swiften/Base/ByteArray.h> +#include <Swiften/EventLoop/EventLoop.h> namespace Swift { class BonjourQuerier; diff --git a/Swiften/LinkLocal/DNSSD/DNSSDBrowseQuery.cpp b/Swiften/LinkLocal/DNSSD/DNSSDBrowseQuery.cpp index 4e00692..10edb0c 100644 --- a/Swiften/LinkLocal/DNSSD/DNSSDBrowseQuery.cpp +++ b/Swiften/LinkLocal/DNSSD/DNSSDBrowseQuery.cpp @@ -4,7 +4,7 @@ * See Documentation/Licenses/GPLv3.txt for more information. */ -#include "Swiften/LinkLocal/DNSSD/DNSSDBrowseQuery.h" +#include <Swiften/LinkLocal/DNSSD/DNSSDBrowseQuery.h> namespace Swift { diff --git a/Swiften/LinkLocal/DNSSD/DNSSDBrowseQuery.h b/Swiften/LinkLocal/DNSSD/DNSSDBrowseQuery.h index 5871866..c2b3be7 100644 --- a/Swiften/LinkLocal/DNSSD/DNSSDBrowseQuery.h +++ b/Swiften/LinkLocal/DNSSD/DNSSDBrowseQuery.h @@ -6,9 +6,9 @@ #pragma once -#include "Swiften/Base/boost_bsignals.h" +#include <Swiften/Base/boost_bsignals.h> -#include "Swiften/LinkLocal/DNSSD/DNSSDServiceID.h" +#include <Swiften/LinkLocal/DNSSD/DNSSDServiceID.h> namespace Swift { class DNSSDBrowseQuery { diff --git a/Swiften/LinkLocal/DNSSD/DNSSDQuerier.cpp b/Swiften/LinkLocal/DNSSD/DNSSDQuerier.cpp index 3bc0cf6..0f32aa6 100644 --- a/Swiften/LinkLocal/DNSSD/DNSSDQuerier.cpp +++ b/Swiften/LinkLocal/DNSSD/DNSSDQuerier.cpp @@ -4,7 +4,7 @@ * See Documentation/Licenses/GPLv3.txt for more information. */ -#include "Swiften/LinkLocal/DNSSD/DNSSDQuerier.h" +#include <Swiften/LinkLocal/DNSSD/DNSSDQuerier.h> namespace Swift { diff --git a/Swiften/LinkLocal/DNSSD/DNSSDRegisterQuery.cpp b/Swiften/LinkLocal/DNSSD/DNSSDRegisterQuery.cpp index 2f931ed..9a807a4 100644 --- a/Swiften/LinkLocal/DNSSD/DNSSDRegisterQuery.cpp +++ b/Swiften/LinkLocal/DNSSD/DNSSDRegisterQuery.cpp @@ -4,7 +4,7 @@ * See Documentation/Licenses/GPLv3.txt for more information. */ -#include "Swiften/LinkLocal/DNSSD/DNSSDRegisterQuery.h" +#include <Swiften/LinkLocal/DNSSD/DNSSDRegisterQuery.h> namespace Swift { diff --git a/Swiften/LinkLocal/DNSSD/DNSSDRegisterQuery.h b/Swiften/LinkLocal/DNSSD/DNSSDRegisterQuery.h index ceff862..93555c2 100644 --- a/Swiften/LinkLocal/DNSSD/DNSSDRegisterQuery.h +++ b/Swiften/LinkLocal/DNSSD/DNSSDRegisterQuery.h @@ -6,10 +6,10 @@ #pragma once -#include "Swiften/Base/boost_bsignals.h" +#include <Swiften/Base/boost_bsignals.h> #include <boost/optional.hpp> -#include "Swiften/LinkLocal/DNSSD/DNSSDServiceID.h" +#include <Swiften/LinkLocal/DNSSD/DNSSDServiceID.h> namespace Swift { class ByteArray; diff --git a/Swiften/LinkLocal/DNSSD/DNSSDResolveHostnameQuery.cpp b/Swiften/LinkLocal/DNSSD/DNSSDResolveHostnameQuery.cpp index 0c072bb..dd34e3d 100644 --- a/Swiften/LinkLocal/DNSSD/DNSSDResolveHostnameQuery.cpp +++ b/Swiften/LinkLocal/DNSSD/DNSSDResolveHostnameQuery.cpp @@ -4,7 +4,7 @@ * See Documentation/Licenses/GPLv3.txt for more information. */ -#include "Swiften/LinkLocal/DNSSD/DNSSDResolveHostnameQuery.h" +#include <Swiften/LinkLocal/DNSSD/DNSSDResolveHostnameQuery.h> namespace Swift { diff --git a/Swiften/LinkLocal/DNSSD/DNSSDResolveHostnameQuery.h b/Swiften/LinkLocal/DNSSD/DNSSDResolveHostnameQuery.h index cfaf28f..ee8ffb9 100644 --- a/Swiften/LinkLocal/DNSSD/DNSSDResolveHostnameQuery.h +++ b/Swiften/LinkLocal/DNSSD/DNSSDResolveHostnameQuery.h @@ -6,10 +6,10 @@ #pragma once -#include "Swiften/Base/boost_bsignals.h" +#include <Swiften/Base/boost_bsignals.h> #include <boost/optional.hpp> -#include "Swiften/Network/HostAddress.h" +#include <Swiften/Network/HostAddress.h> namespace Swift { class DNSSDResolveHostnameQuery { diff --git a/Swiften/LinkLocal/DNSSD/DNSSDResolveServiceQuery.cpp b/Swiften/LinkLocal/DNSSD/DNSSDResolveServiceQuery.cpp index a2f18a6..feb1712 100644 --- a/Swiften/LinkLocal/DNSSD/DNSSDResolveServiceQuery.cpp +++ b/Swiften/LinkLocal/DNSSD/DNSSDResolveServiceQuery.cpp @@ -4,7 +4,7 @@ * See Documentation/Licenses/GPLv3.txt for more information. */ -#include "Swiften/LinkLocal/DNSSD/DNSSDResolveServiceQuery.h" +#include <Swiften/LinkLocal/DNSSD/DNSSDResolveServiceQuery.h> namespace Swift { diff --git a/Swiften/LinkLocal/DNSSD/DNSSDResolveServiceQuery.h b/Swiften/LinkLocal/DNSSD/DNSSDResolveServiceQuery.h index ad73663..c8d78aa 100644 --- a/Swiften/LinkLocal/DNSSD/DNSSDResolveServiceQuery.h +++ b/Swiften/LinkLocal/DNSSD/DNSSDResolveServiceQuery.h @@ -6,11 +6,11 @@ #pragma once -#include "Swiften/Base/boost_bsignals.h" +#include <Swiften/Base/boost_bsignals.h> #include <boost/optional.hpp> -#include "Swiften/LinkLocal/DNSSD/DNSSDServiceID.h" -#include "Swiften/Base/ByteArray.h" +#include <Swiften/LinkLocal/DNSSD/DNSSDServiceID.h> +#include <Swiften/Base/ByteArray.h> namespace Swift { class DNSSDResolveServiceQuery { diff --git a/Swiften/LinkLocal/DNSSD/DNSSDServiceID.cpp b/Swiften/LinkLocal/DNSSD/DNSSDServiceID.cpp index 76bd2b7..2f2784c 100644 --- a/Swiften/LinkLocal/DNSSD/DNSSDServiceID.cpp +++ b/Swiften/LinkLocal/DNSSD/DNSSDServiceID.cpp @@ -4,7 +4,7 @@ * See Documentation/Licenses/GPLv3.txt for more information. */ -#include "Swiften/LinkLocal/DNSSD/DNSSDServiceID.h" +#include <Swiften/LinkLocal/DNSSD/DNSSDServiceID.h> namespace Swift { diff --git a/Swiften/LinkLocal/DNSSD/Fake/FakeDNSSDBrowseQuery.h b/Swiften/LinkLocal/DNSSD/Fake/FakeDNSSDBrowseQuery.h index 462e471..b2a6d61 100644 --- a/Swiften/LinkLocal/DNSSD/Fake/FakeDNSSDBrowseQuery.h +++ b/Swiften/LinkLocal/DNSSD/Fake/FakeDNSSDBrowseQuery.h @@ -6,8 +6,8 @@ #pragma once -#include "Swiften/LinkLocal/DNSSD/Fake/FakeDNSSDQuery.h" -#include "Swiften/LinkLocal/DNSSD/DNSSDBrowseQuery.h" +#include <Swiften/LinkLocal/DNSSD/Fake/FakeDNSSDQuery.h> +#include <Swiften/LinkLocal/DNSSD/DNSSDBrowseQuery.h> namespace Swift { class FakeDNSSDQuerier; diff --git a/Swiften/LinkLocal/DNSSD/Fake/FakeDNSSDQuerier.cpp b/Swiften/LinkLocal/DNSSD/Fake/FakeDNSSDQuerier.cpp index d7d0228..ff2b03c 100644 --- a/Swiften/LinkLocal/DNSSD/Fake/FakeDNSSDQuerier.cpp +++ b/Swiften/LinkLocal/DNSSD/Fake/FakeDNSSDQuerier.cpp @@ -4,15 +4,17 @@ * See Documentation/Licenses/GPLv3.txt for more information. */ -#include "Swiften/LinkLocal/DNSSD/Fake/FakeDNSSDQuerier.h" +#include <Swiften/LinkLocal/DNSSD/Fake/FakeDNSSDQuerier.h> #include <boost/bind.hpp> - -#include "Swiften/LinkLocal/DNSSD/Fake/FakeDNSSDBrowseQuery.h" -#include "Swiften/LinkLocal/DNSSD/Fake/FakeDNSSDRegisterQuery.h" -#include "Swiften/LinkLocal/DNSSD/Fake/FakeDNSSDResolveServiceQuery.h" -#include "Swiften/LinkLocal/DNSSD/Fake/FakeDNSSDResolveHostnameQuery.h" -#include "Swiften/EventLoop/EventLoop.h" +#include <iostream> + +#include <Swiften/Base/foreach.h> +#include <Swiften/LinkLocal/DNSSD/Fake/FakeDNSSDBrowseQuery.h> +#include <Swiften/LinkLocal/DNSSD/Fake/FakeDNSSDRegisterQuery.h> +#include <Swiften/LinkLocal/DNSSD/Fake/FakeDNSSDResolveServiceQuery.h> +#include <Swiften/LinkLocal/DNSSD/Fake/FakeDNSSDResolveHostnameQuery.h> +#include <Swiften/EventLoop/EventLoop.h> namespace Swift { diff --git a/Swiften/LinkLocal/DNSSD/Fake/FakeDNSSDQuerier.h b/Swiften/LinkLocal/DNSSD/Fake/FakeDNSSDQuerier.h index b2871c9..97a2c6e 100644 --- a/Swiften/LinkLocal/DNSSD/Fake/FakeDNSSDQuerier.h +++ b/Swiften/LinkLocal/DNSSD/Fake/FakeDNSSDQuerier.h @@ -11,12 +11,11 @@ #include <list> #include <set> -#include "Swiften/Base/foreach.h" #include <string> -#include "Swiften/EventLoop/EventOwner.h" -#include "Swiften/LinkLocal/DNSSD/DNSSDQuerier.h" -#include "Swiften/LinkLocal/DNSSD/DNSSDResolveServiceQuery.h" -#include "Swiften/Network/HostAddress.h" +#include <Swiften/EventLoop/EventOwner.h> +#include <Swiften/LinkLocal/DNSSD/DNSSDQuerier.h> +#include <Swiften/LinkLocal/DNSSD/DNSSDResolveServiceQuery.h> +#include <Swiften/Network/HostAddress.h> namespace Swift { class ByteArray; @@ -63,8 +62,8 @@ namespace Swift { template<typename T> std::vector< boost::shared_ptr<T> > getAllQueriesEverRun() const { std::vector< boost::shared_ptr<T> > result; - foreach(const boost::shared_ptr<FakeDNSSDQuery>& query, allQueriesEverRun) { - if (boost::shared_ptr<T> resultQuery = boost::dynamic_pointer_cast<T>(query)) { + for (QueryList::const_iterator i = allQueriesEverRun.begin(); i != allQueriesEverRun.end(); ++i) { + if (boost::shared_ptr<T> resultQuery = boost::dynamic_pointer_cast<T>(*i)) { result.push_back(resultQuery); } } @@ -75,8 +74,8 @@ namespace Swift { template<typename T> std::vector< boost::shared_ptr<T> > getQueries() const { std::vector< boost::shared_ptr<T> > result; - foreach(const boost::shared_ptr<FakeDNSSDQuery>& query, runningQueries) { - if (boost::shared_ptr<T> resultQuery = boost::dynamic_pointer_cast<T>(query)) { + for (QueryList::const_iterator i = runningQueries.begin(); i != runningQueries.end(); ++i) { + if (boost::shared_ptr<T> resultQuery = boost::dynamic_pointer_cast<T>(*i)) { result.push_back(resultQuery); } } @@ -86,8 +85,9 @@ namespace Swift { private: std::string domain; EventLoop* eventLoop; - std::list< boost::shared_ptr<FakeDNSSDQuery> > runningQueries; - std::list< boost::shared_ptr<FakeDNSSDQuery> > allQueriesEverRun; + typedef std::list< boost::shared_ptr<FakeDNSSDQuery> > QueryList; + QueryList runningQueries; + QueryList allQueriesEverRun; std::set<DNSSDServiceID> services; typedef std::map<DNSSDServiceID,DNSSDResolveServiceQuery::Result> ServiceInfoMap; ServiceInfoMap serviceInfo; diff --git a/Swiften/LinkLocal/DNSSD/Fake/FakeDNSSDQuery.cpp b/Swiften/LinkLocal/DNSSD/Fake/FakeDNSSDQuery.cpp index a27f61c..99f55fa 100644 --- a/Swiften/LinkLocal/DNSSD/Fake/FakeDNSSDQuery.cpp +++ b/Swiften/LinkLocal/DNSSD/Fake/FakeDNSSDQuery.cpp @@ -4,8 +4,8 @@ * See Documentation/Licenses/GPLv3.txt for more information. */ -#include "Swiften/LinkLocal/DNSSD/Fake/FakeDNSSDQuery.h" -#include "Swiften/LinkLocal/DNSSD/Fake/FakeDNSSDQuerier.h" +#include <Swiften/LinkLocal/DNSSD/Fake/FakeDNSSDQuery.h> +#include <Swiften/LinkLocal/DNSSD/Fake/FakeDNSSDQuerier.h> namespace Swift { diff --git a/Swiften/LinkLocal/DNSSD/Fake/FakeDNSSDQuery.h b/Swiften/LinkLocal/DNSSD/Fake/FakeDNSSDQuery.h index 479c41f..b6d5c98 100644 --- a/Swiften/LinkLocal/DNSSD/Fake/FakeDNSSDQuery.h +++ b/Swiften/LinkLocal/DNSSD/Fake/FakeDNSSDQuery.h @@ -9,7 +9,7 @@ #include <boost/shared_ptr.hpp> #include <boost/enable_shared_from_this.hpp> -#include "Swiften/EventLoop/EventOwner.h" +#include <Swiften/EventLoop/EventOwner.h> namespace Swift { class FakeDNSSDQuerier; diff --git a/Swiften/LinkLocal/DNSSD/Fake/FakeDNSSDRegisterQuery.h b/Swiften/LinkLocal/DNSSD/Fake/FakeDNSSDRegisterQuery.h index a6ae17a..c568f5b 100644 --- a/Swiften/LinkLocal/DNSSD/Fake/FakeDNSSDRegisterQuery.h +++ b/Swiften/LinkLocal/DNSSD/Fake/FakeDNSSDRegisterQuery.h @@ -6,9 +6,9 @@ #pragma once -#include "Swiften/LinkLocal/DNSSD/Fake/FakeDNSSDQuery.h" -#include "Swiften/LinkLocal/DNSSD/DNSSDRegisterQuery.h" -#include "Swiften/Base/ByteArray.h" +#include <Swiften/LinkLocal/DNSSD/Fake/FakeDNSSDQuery.h> +#include <Swiften/LinkLocal/DNSSD/DNSSDRegisterQuery.h> +#include <Swiften/Base/ByteArray.h> #include <string> namespace Swift { diff --git a/Swiften/LinkLocal/DNSSD/Fake/FakeDNSSDResolveHostnameQuery.h b/Swiften/LinkLocal/DNSSD/Fake/FakeDNSSDResolveHostnameQuery.h index cbaa6e6..aa427cc 100644 --- a/Swiften/LinkLocal/DNSSD/Fake/FakeDNSSDResolveHostnameQuery.h +++ b/Swiften/LinkLocal/DNSSD/Fake/FakeDNSSDResolveHostnameQuery.h @@ -7,9 +7,9 @@ #pragma once #include <string> -#include "Swiften/LinkLocal/DNSSD/Fake/FakeDNSSDQuery.h" -#include "Swiften/LinkLocal/DNSSD/DNSSDResolveHostnameQuery.h" -#include "Swiften/Network/HostAddress.h" +#include <Swiften/LinkLocal/DNSSD/Fake/FakeDNSSDQuery.h> +#include <Swiften/LinkLocal/DNSSD/DNSSDResolveHostnameQuery.h> +#include <Swiften/Network/HostAddress.h> namespace Swift { class FakeDNSSDQuerier; diff --git a/Swiften/LinkLocal/DNSSD/Fake/FakeDNSSDResolveServiceQuery.h b/Swiften/LinkLocal/DNSSD/Fake/FakeDNSSDResolveServiceQuery.h index 3d4a3b9..5c69843 100644 --- a/Swiften/LinkLocal/DNSSD/Fake/FakeDNSSDResolveServiceQuery.h +++ b/Swiften/LinkLocal/DNSSD/Fake/FakeDNSSDResolveServiceQuery.h @@ -6,9 +6,9 @@ #pragma once -#include "Swiften/LinkLocal/DNSSD/Fake/FakeDNSSDQuery.h" -#include "Swiften/LinkLocal/DNSSD/DNSSDResolveServiceQuery.h" -#include "Swiften/LinkLocal/LinkLocalServiceInfo.h" +#include <Swiften/LinkLocal/DNSSD/Fake/FakeDNSSDQuery.h> +#include <Swiften/LinkLocal/DNSSD/DNSSDResolveServiceQuery.h> +#include <Swiften/LinkLocal/LinkLocalServiceInfo.h> namespace Swift { class FakeDNSSDQuerier; diff --git a/Swiften/LinkLocal/DNSSD/PlatformDNSSDQuerierFactory.cpp b/Swiften/LinkLocal/DNSSD/PlatformDNSSDQuerierFactory.cpp index 7a42129..cc12573 100644 --- a/Swiften/LinkLocal/DNSSD/PlatformDNSSDQuerierFactory.cpp +++ b/Swiften/LinkLocal/DNSSD/PlatformDNSSDQuerierFactory.cpp @@ -4,12 +4,12 @@ * See Documentation/Licenses/GPLv3.txt for more information. */ -#include "Swiften/LinkLocal/DNSSD/PlatformDNSSDQuerierFactory.h" +#include <Swiften/LinkLocal/DNSSD/PlatformDNSSDQuerierFactory.h> #if defined(HAVE_BONJOUR) -#include "Swiften/LinkLocal/DNSSD/Bonjour/BonjourQuerier.h" +#include <Swiften/LinkLocal/DNSSD/Bonjour/BonjourQuerier.h> #elif defined(HAVE_AVAHI) -#include "Swiften/LinkLocal/DNSSD/Avahi/AvahiQuerier.h" +#include <Swiften/LinkLocal/DNSSD/Avahi/AvahiQuerier.h> #endif diff --git a/Swiften/LinkLocal/IncomingLinkLocalSession.cpp b/Swiften/LinkLocal/IncomingLinkLocalSession.cpp index 3af6d4c..c4dea64 100644 --- a/Swiften/LinkLocal/IncomingLinkLocalSession.cpp +++ b/Swiften/LinkLocal/IncomingLinkLocalSession.cpp @@ -4,17 +4,17 @@ * See Documentation/Licenses/GPLv3.txt for more information. */ -#include "Swiften/LinkLocal/IncomingLinkLocalSession.h" +#include <Swiften/LinkLocal/IncomingLinkLocalSession.h> #include <boost/bind.hpp> -#include "Swiften/Elements/ProtocolHeader.h" -#include "Swiften/Network/Connection.h" -#include "Swiften/StreamStack/StreamStack.h" -#include "Swiften/StreamStack/ConnectionLayer.h" -#include "Swiften/StreamStack/XMPPLayer.h" -#include "Swiften/Elements/StreamFeatures.h" -#include "Swiften/Elements/IQ.h" +#include <Swiften/Elements/ProtocolHeader.h> +#include <Swiften/Network/Connection.h> +#include <Swiften/StreamStack/StreamStack.h> +#include <Swiften/StreamStack/ConnectionLayer.h> +#include <Swiften/StreamStack/XMPPLayer.h> +#include <Swiften/Elements/StreamFeatures.h> +#include <Swiften/Elements/IQ.h> namespace Swift { diff --git a/Swiften/LinkLocal/IncomingLinkLocalSession.h b/Swiften/LinkLocal/IncomingLinkLocalSession.h index a586a2e..68e21a5 100644 --- a/Swiften/LinkLocal/IncomingLinkLocalSession.h +++ b/Swiften/LinkLocal/IncomingLinkLocalSession.h @@ -7,11 +7,11 @@ #pragma once #include <boost/shared_ptr.hpp> -#include "Swiften/Base/boost_bsignals.h" +#include <Swiften/Base/boost_bsignals.h> -#include "Swiften/Session/Session.h" -#include "Swiften/JID/JID.h" -#include "Swiften/Network/Connection.h" +#include <Swiften/Session/Session.h> +#include <Swiften/JID/JID.h> +#include <Swiften/Network/Connection.h> namespace Swift { class ProtocolHeader; diff --git a/Swiften/LinkLocal/LinkLocalConnector.cpp b/Swiften/LinkLocal/LinkLocalConnector.cpp index 42366e8..af96e65 100644 --- a/Swiften/LinkLocal/LinkLocalConnector.cpp +++ b/Swiften/LinkLocal/LinkLocalConnector.cpp @@ -4,16 +4,16 @@ * See Documentation/Licenses/GPLv3.txt for more information. */ -#include "Swiften/LinkLocal/LinkLocalConnector.h" +#include <Swiften/LinkLocal/LinkLocalConnector.h> #include <boost/bind.hpp> -#include "Swiften/Network/Connection.h" -#include "Swiften/Network/ConnectionFactory.h" -#include "Swiften/Network/HostAddress.h" -#include "Swiften/Network/HostAddressPort.h" -#include "Swiften/LinkLocal/DNSSD/DNSSDQuerier.h" -#include "Swiften/LinkLocal/DNSSD/DNSSDResolveHostnameQuery.h" +#include <Swiften/Network/Connection.h> +#include <Swiften/Network/ConnectionFactory.h> +#include <Swiften/Network/HostAddress.h> +#include <Swiften/Network/HostAddressPort.h> +#include <Swiften/LinkLocal/DNSSD/DNSSDQuerier.h> +#include <Swiften/LinkLocal/DNSSD/DNSSDResolveHostnameQuery.h> namespace Swift { diff --git a/Swiften/LinkLocal/LinkLocalConnector.h b/Swiften/LinkLocal/LinkLocalConnector.h index 0fbb7ec..0acdc51 100644 --- a/Swiften/LinkLocal/LinkLocalConnector.h +++ b/Swiften/LinkLocal/LinkLocalConnector.h @@ -7,12 +7,12 @@ #pragma once #include <boost/shared_ptr.hpp> -#include "Swiften/Base/boost_bsignals.h" +#include <Swiften/Base/boost_bsignals.h> #include <boost/enable_shared_from_this.hpp> #include <vector> -#include "Swiften/Network/Connection.h" -#include "Swiften/LinkLocal/LinkLocalService.h" +#include <Swiften/Network/Connection.h> +#include <Swiften/LinkLocal/LinkLocalService.h> namespace Swift { class ConnectionFactory; diff --git a/Swiften/LinkLocal/LinkLocalService.cpp b/Swiften/LinkLocal/LinkLocalService.cpp index c8d707d..7c6538c 100644 --- a/Swiften/LinkLocal/LinkLocalService.cpp +++ b/Swiften/LinkLocal/LinkLocalService.cpp @@ -4,7 +4,7 @@ * See Documentation/Licenses/GPLv3.txt for more information. */ -#include "Swiften/LinkLocal/LinkLocalService.h" +#include <Swiften/LinkLocal/LinkLocalService.h> namespace Swift { diff --git a/Swiften/LinkLocal/LinkLocalService.h b/Swiften/LinkLocal/LinkLocalService.h index 2e74338..2b7f7b2 100644 --- a/Swiften/LinkLocal/LinkLocalService.h +++ b/Swiften/LinkLocal/LinkLocalService.h @@ -7,10 +7,10 @@ #pragma once #include <string> -#include "Swiften/JID/JID.h" -#include "Swiften/LinkLocal/DNSSD/DNSSDServiceID.h" -#include "Swiften/LinkLocal/DNSSD/DNSSDResolveServiceQuery.h" -#include "Swiften/LinkLocal/LinkLocalServiceInfo.h" +#include <Swiften/JID/JID.h> +#include <Swiften/LinkLocal/DNSSD/DNSSDServiceID.h> +#include <Swiften/LinkLocal/DNSSD/DNSSDResolveServiceQuery.h> +#include <Swiften/LinkLocal/LinkLocalServiceInfo.h> namespace Swift { class LinkLocalService { diff --git a/Swiften/LinkLocal/LinkLocalServiceBrowser.cpp b/Swiften/LinkLocal/LinkLocalServiceBrowser.cpp index 8393ade..4b68a33 100644 --- a/Swiften/LinkLocal/LinkLocalServiceBrowser.cpp +++ b/Swiften/LinkLocal/LinkLocalServiceBrowser.cpp @@ -7,9 +7,9 @@ #include <boost/bind.hpp> #include <iostream> -#include "Swiften/LinkLocal/LinkLocalServiceBrowser.h" -#include "Swiften/LinkLocal/DNSSD/DNSSDBrowseQuery.h" -#include "Swiften/Network/HostAddress.h" +#include <Swiften/LinkLocal/LinkLocalServiceBrowser.h> +#include <Swiften/LinkLocal/DNSSD/DNSSDBrowseQuery.h> +#include <Swiften/Network/HostAddress.h> namespace Swift { diff --git a/Swiften/LinkLocal/LinkLocalServiceBrowser.h b/Swiften/LinkLocal/LinkLocalServiceBrowser.h index 56b4aa4..57ed969 100644 --- a/Swiften/LinkLocal/LinkLocalServiceBrowser.h +++ b/Swiften/LinkLocal/LinkLocalServiceBrowser.h @@ -6,19 +6,19 @@ #pragma once -#include "Swiften/Base/boost_bsignals.h" +#include <Swiften/Base/boost_bsignals.h> #include <boost/shared_ptr.hpp> #include <boost/optional.hpp> #include <map> #include <vector> #include <string> -#include "Swiften/LinkLocal/DNSSD/DNSSDQuerier.h" -#include "Swiften/LinkLocal/DNSSD/DNSSDResolveServiceQuery.h" -#include "Swiften/LinkLocal/DNSSD/DNSSDRegisterQuery.h" -#include "Swiften/LinkLocal/DNSSD/DNSSDServiceID.h" -#include "Swiften/LinkLocal/LinkLocalService.h" -#include "Swiften/LinkLocal/LinkLocalServiceInfo.h" +#include <Swiften/LinkLocal/DNSSD/DNSSDQuerier.h> +#include <Swiften/LinkLocal/DNSSD/DNSSDResolveServiceQuery.h> +#include <Swiften/LinkLocal/DNSSD/DNSSDRegisterQuery.h> +#include <Swiften/LinkLocal/DNSSD/DNSSDServiceID.h> +#include <Swiften/LinkLocal/LinkLocalService.h> +#include <Swiften/LinkLocal/LinkLocalServiceInfo.h> namespace Swift { class LinkLocalServiceBrowser { diff --git a/Swiften/LinkLocal/LinkLocalServiceInfo.cpp b/Swiften/LinkLocal/LinkLocalServiceInfo.cpp index bec2e97..2be0049 100644 --- a/Swiften/LinkLocal/LinkLocalServiceInfo.cpp +++ b/Swiften/LinkLocal/LinkLocalServiceInfo.cpp @@ -4,7 +4,7 @@ * See Documentation/Licenses/GPLv3.txt for more information. */ -#include "Swiften/LinkLocal/LinkLocalServiceInfo.h" +#include <Swiften/LinkLocal/LinkLocalServiceInfo.h> #include <boost/lexical_cast.hpp> diff --git a/Swiften/LinkLocal/LinkLocalServiceInfo.h b/Swiften/LinkLocal/LinkLocalServiceInfo.h index a166c64..79a8cb8 100644 --- a/Swiften/LinkLocal/LinkLocalServiceInfo.h +++ b/Swiften/LinkLocal/LinkLocalServiceInfo.h @@ -8,9 +8,9 @@ #include <boost/optional.hpp> -#include "Swiften/Base/ByteArray.h" +#include <Swiften/Base/ByteArray.h> #include <string> -#include "Swiften/JID/JID.h" +#include <Swiften/JID/JID.h> namespace Swift { diff --git a/Swiften/LinkLocal/OutgoingLinkLocalSession.cpp b/Swiften/LinkLocal/OutgoingLinkLocalSession.cpp index 65542d2..9d712f8 100644 --- a/Swiften/LinkLocal/OutgoingLinkLocalSession.cpp +++ b/Swiften/LinkLocal/OutgoingLinkLocalSession.cpp @@ -4,14 +4,15 @@ * See Documentation/Licenses/GPLv3.txt for more information. */ -#include "Swiften/LinkLocal/OutgoingLinkLocalSession.h" +#include <Swiften/LinkLocal/OutgoingLinkLocalSession.h> #include <boost/bind.hpp> -#include "Swiften/StreamStack/XMPPLayer.h" -#include "Swiften/Elements/ProtocolHeader.h" -#include "Swiften/Elements/StreamFeatures.h" -#include "Swiften/Elements/IQ.h" +#include <Swiften/Base/foreach.h> +#include <Swiften/StreamStack/XMPPLayer.h> +#include <Swiften/Elements/ProtocolHeader.h> +#include <Swiften/Elements/StreamFeatures.h> +#include <Swiften/Elements/IQ.h> namespace Swift { diff --git a/Swiften/LinkLocal/OutgoingLinkLocalSession.h b/Swiften/LinkLocal/OutgoingLinkLocalSession.h index 34ea411..430c446 100644 --- a/Swiften/LinkLocal/OutgoingLinkLocalSession.h +++ b/Swiften/LinkLocal/OutgoingLinkLocalSession.h @@ -7,12 +7,12 @@ #pragma once #include <boost/shared_ptr.hpp> -#include "Swiften/Base/boost_bsignals.h" +#include <Swiften/Base/boost_bsignals.h> #include <boost/enable_shared_from_this.hpp> #include <vector> -#include "Swiften/Session/Session.h" -#include "Swiften/JID/JID.h" +#include <Swiften/Session/Session.h> +#include <Swiften/JID/JID.h> namespace Swift { class ConnectionFactory; diff --git a/Swiften/LinkLocal/SConscript b/Swiften/LinkLocal/SConscript index 6edf993..29ea692 100644 --- a/Swiften/LinkLocal/SConscript +++ b/Swiften/LinkLocal/SConscript @@ -31,7 +31,11 @@ elif myenv.get("HAVE_AVAHI", 0) : myenv.Append(CPPDEFINES = ["HAVE_AVAHI"]) sources += [ "DNSSD/Avahi/AvahiQuerier.cpp", - "DNSSD/Avahi/AvahiQuery.cpp" + "DNSSD/Avahi/AvahiQuery.cpp", + "DNSSD/Avahi/AvahiResolveHostnameQuery.cpp", + "DNSSD/Avahi/AvahiResolveServiceQuery.cpp", + "DNSSD/Avahi/AvahiRegisterQuery.cpp", + "DNSSD/Avahi/AvahiBrowseQuery.cpp", ] objects = myenv.SwiftenObject(sources) diff --git a/Swiften/LinkLocal/UnitTest/LinkLocalConnectorTest.cpp b/Swiften/LinkLocal/UnitTest/LinkLocalConnectorTest.cpp index 98deed1..474c772 100644 --- a/Swiften/LinkLocal/UnitTest/LinkLocalConnectorTest.cpp +++ b/Swiften/LinkLocal/UnitTest/LinkLocalConnectorTest.cpp @@ -7,13 +7,15 @@ #include <cppunit/extensions/HelperMacros.h> #include <cppunit/extensions/TestFactoryRegistry.h> -#include "Swiften/LinkLocal/LinkLocalConnector.h" -#include "Swiften/LinkLocal/LinkLocalService.h" -#include "Swiften/LinkLocal/DNSSD/DNSSDServiceID.h" -#include "Swiften/LinkLocal/DNSSD/DNSSDResolveHostnameQuery.h" -#include "Swiften/LinkLocal/DNSSD/Fake/FakeDNSSDQuerier.h" -#include "Swiften/EventLoop/DummyEventLoop.h" -#include "Swiften/Network/FakeConnection.h" +#include <boost/bind.hpp> + +#include <Swiften/LinkLocal/LinkLocalConnector.h> +#include <Swiften/LinkLocal/LinkLocalService.h> +#include <Swiften/LinkLocal/DNSSD/DNSSDServiceID.h> +#include <Swiften/LinkLocal/DNSSD/DNSSDResolveHostnameQuery.h> +#include <Swiften/LinkLocal/DNSSD/Fake/FakeDNSSDQuerier.h> +#include <Swiften/EventLoop/DummyEventLoop.h> +#include <Swiften/Network/FakeConnection.h> using namespace Swift; diff --git a/Swiften/LinkLocal/UnitTest/LinkLocalServiceBrowserTest.cpp b/Swiften/LinkLocal/UnitTest/LinkLocalServiceBrowserTest.cpp index 9c4c288..c0fd248 100644 --- a/Swiften/LinkLocal/UnitTest/LinkLocalServiceBrowserTest.cpp +++ b/Swiften/LinkLocal/UnitTest/LinkLocalServiceBrowserTest.cpp @@ -9,13 +9,13 @@ #include <boost/bind.hpp> #include <map> -#include "Swiften/LinkLocal/LinkLocalServiceBrowser.h" -#include "Swiften/LinkLocal/LinkLocalService.h" -#include "Swiften/LinkLocal/DNSSD/DNSSDServiceID.h" -#include "Swiften/LinkLocal/DNSSD/DNSSDResolveServiceQuery.h" -#include "Swiften/LinkLocal/DNSSD/Fake/FakeDNSSDQuerier.h" -#include "Swiften/LinkLocal/DNSSD/Fake/FakeDNSSDResolveServiceQuery.h" -#include "Swiften/EventLoop/DummyEventLoop.h" +#include <Swiften/LinkLocal/LinkLocalServiceBrowser.h> +#include <Swiften/LinkLocal/LinkLocalService.h> +#include <Swiften/LinkLocal/DNSSD/DNSSDServiceID.h> +#include <Swiften/LinkLocal/DNSSD/DNSSDResolveServiceQuery.h> +#include <Swiften/LinkLocal/DNSSD/Fake/FakeDNSSDQuerier.h> +#include <Swiften/LinkLocal/DNSSD/Fake/FakeDNSSDResolveServiceQuery.h> +#include <Swiften/EventLoop/DummyEventLoop.h> using namespace Swift; diff --git a/Swiften/LinkLocal/UnitTest/LinkLocalServiceInfoTest.cpp b/Swiften/LinkLocal/UnitTest/LinkLocalServiceInfoTest.cpp index 3943e31..1e69cd0 100644 --- a/Swiften/LinkLocal/UnitTest/LinkLocalServiceInfoTest.cpp +++ b/Swiften/LinkLocal/UnitTest/LinkLocalServiceInfoTest.cpp @@ -4,12 +4,12 @@ * See Documentation/Licenses/GPLv3.txt for more information. */ -#include "Swiften/Base/ByteArray.h" +#include <Swiften/Base/ByteArray.h> #include <cppunit/extensions/HelperMacros.h> #include <cppunit/extensions/TestFactoryRegistry.h> -#include "Swiften/LinkLocal/LinkLocalServiceInfo.h" +#include <Swiften/LinkLocal/LinkLocalServiceInfo.h> using namespace Swift; diff --git a/Swiften/LinkLocal/UnitTest/LinkLocalServiceTest.cpp b/Swiften/LinkLocal/UnitTest/LinkLocalServiceTest.cpp index 4835bde..2e3e1bb 100644 --- a/Swiften/LinkLocal/UnitTest/LinkLocalServiceTest.cpp +++ b/Swiften/LinkLocal/UnitTest/LinkLocalServiceTest.cpp @@ -7,7 +7,7 @@ #include <cppunit/extensions/HelperMacros.h> #include <cppunit/extensions/TestFactoryRegistry.h> -#include "Swiften/LinkLocal/LinkLocalService.h" +#include <Swiften/LinkLocal/LinkLocalService.h> using namespace Swift; diff --git a/Swiften/MUC/MUC.cpp b/Swiften/MUC/MUC.cpp index 68a5a86..1ade7e3 100644 --- a/Swiften/MUC/MUC.cpp +++ b/Swiften/MUC/MUC.cpp @@ -4,21 +4,22 @@ * See Documentation/Licenses/GPLv3.txt for more information. */ -#include "Swiften/MUC/MUC.h" +#include <Swiften/MUC/MUC.h> #include <boost/bind.hpp> #include <boost/shared_ptr.hpp> #include <boost/smart_ptr/make_shared.hpp> -#include "Swiften/Presence/DirectedPresenceSender.h" -#include "Swiften/Client/StanzaChannel.h" -#include "Swiften/Queries/IQRouter.h" -#include "Swiften/Elements/Form.h" -#include "Swiften/Elements/IQ.h" -#include "Swiften/Elements/MUCUserPayload.h" -#include "Swiften/Elements/MUCPayload.h" -#include "Swiften/MUC/MUCRegistry.h" -#include "Swiften/Queries/GenericRequest.h" +#include <Swiften/Base/foreach.h> +#include <Swiften/Presence/DirectedPresenceSender.h> +#include <Swiften/Client/StanzaChannel.h> +#include <Swiften/Queries/IQRouter.h> +#include <Swiften/Elements/Form.h> +#include <Swiften/Elements/IQ.h> +#include <Swiften/Elements/MUCUserPayload.h> +#include <Swiften/Elements/MUCPayload.h> +#include <Swiften/MUC/MUCRegistry.h> +#include <Swiften/Queries/GenericRequest.h> namespace Swift { diff --git a/Swiften/MUC/MUC.h b/Swiften/MUC/MUC.h index 278ef95..828a36f 100644 --- a/Swiften/MUC/MUC.h +++ b/Swiften/MUC/MUC.h @@ -6,16 +6,16 @@ #pragma once -#include "Swiften/JID/JID.h" +#include <Swiften/JID/JID.h> #include <string> -#include "Swiften/Elements/Message.h" -#include "Swiften/Elements/Presence.h" -#include "Swiften/Elements/MUCOccupant.h" -#include "Swiften/MUC/MUCRegistry.h" -#include "Swiften/Elements/MUCOwnerPayload.h" +#include <Swiften/Elements/Message.h> +#include <Swiften/Elements/Presence.h> +#include <Swiften/Elements/MUCOccupant.h> +#include <Swiften/MUC/MUCRegistry.h> +#include <Swiften/Elements/MUCOwnerPayload.h> #include <boost/shared_ptr.hpp> -#include "Swiften/Base/boost_bsignals.h" +#include <Swiften/Base/boost_bsignals.h> #include <boost/signals/connection.hpp> #include <map> diff --git a/Swiften/MUC/MUCBookmark.h b/Swiften/MUC/MUCBookmark.h index 10e1b78..3f612c4 100644 --- a/Swiften/MUC/MUCBookmark.h +++ b/Swiften/MUC/MUCBookmark.h @@ -9,8 +9,8 @@ #include <boost/optional.hpp> #include <string> -#include "Swiften/JID/JID.h" -#include "Swiften/Elements/Storage.h" +#include <Swiften/JID/JID.h> +#include <Swiften/Elements/Storage.h> namespace Swift { class MUCBookmark { diff --git a/Swiften/MUC/MUCBookmarkManager.cpp b/Swiften/MUC/MUCBookmarkManager.cpp index d0855cd..2e0b79e 100644 --- a/Swiften/MUC/MUCBookmarkManager.cpp +++ b/Swiften/MUC/MUCBookmarkManager.cpp @@ -9,9 +9,10 @@ #include <boost/bind.hpp> #include <iostream> -#include "Swiften/Queries/IQRouter.h" -#include "Swiften/Queries/Requests/GetPrivateStorageRequest.h" -#include "Swiften/Queries/Requests/SetPrivateStorageRequest.h" +#include <Swiften/Base/foreach.h> +#include <Swiften/Queries/IQRouter.h> +#include <Swiften/Queries/Requests/GetPrivateStorageRequest.h> +#include <Swiften/Queries/Requests/SetPrivateStorageRequest.h> namespace Swift { diff --git a/Swiften/MUC/MUCBookmarkManager.h b/Swiften/MUC/MUCBookmarkManager.h index 39699df..ccea46c 100644 --- a/Swiften/MUC/MUCBookmarkManager.h +++ b/Swiften/MUC/MUCBookmarkManager.h @@ -9,12 +9,12 @@ #include <vector> #include <boost/shared_ptr.hpp> -#include "Swiften/Base/boost_bsignals.h" +#include <Swiften/Base/boost_bsignals.h> #include <boost/optional.hpp> -#include "Swiften/MUC/MUCBookmark.h" -#include "Swiften/Elements/Storage.h" -#include "Swiften/Elements/ErrorPayload.h" +#include <Swiften/MUC/MUCBookmark.h> +#include <Swiften/Elements/Storage.h> +#include <Swiften/Elements/ErrorPayload.h> namespace Swift { class IQRouter; diff --git a/Swiften/MUC/MUCManager.cpp b/Swiften/MUC/MUCManager.cpp index 8950029..6e9b820 100644 --- a/Swiften/MUC/MUCManager.cpp +++ b/Swiften/MUC/MUCManager.cpp @@ -4,7 +4,7 @@ * See Documentation/Licenses/GPLv3.txt for more information. */ -#include "Swiften/MUC/MUCManager.h" +#include <Swiften/MUC/MUCManager.h> namespace Swift { diff --git a/Swiften/MUC/MUCManager.h b/Swiften/MUC/MUCManager.h index 0efdf9a..36ae61e 100644 --- a/Swiften/MUC/MUCManager.h +++ b/Swiften/MUC/MUCManager.h @@ -6,7 +6,7 @@ #pragma once -#include "Swiften/MUC/MUC.h" +#include <Swiften/MUC/MUC.h> namespace Swift { class IQRouter; diff --git a/Swiften/MUC/MUCRegistry.cpp b/Swiften/MUC/MUCRegistry.cpp index e433165..6776be9 100644 --- a/Swiften/MUC/MUCRegistry.cpp +++ b/Swiften/MUC/MUCRegistry.cpp @@ -4,7 +4,7 @@ * See Documentation/Licenses/GPLv3.txt for more information. */ -#include "Swiften/MUC/MUCRegistry.h" +#include <Swiften/MUC/MUCRegistry.h> #include <algorithm> diff --git a/Swiften/MUC/MUCRegistry.h b/Swiften/MUC/MUCRegistry.h index 6356931..0ed2d2e 100644 --- a/Swiften/MUC/MUCRegistry.h +++ b/Swiften/MUC/MUCRegistry.h @@ -8,7 +8,7 @@ #include <vector> -#include "Swiften/JID/JID.h" +#include <Swiften/JID/JID.h> namespace Swift { class JID; diff --git a/Swiften/Network/BoostConnection.cpp b/Swiften/Network/BoostConnection.cpp index f7ff8c4..2fdb468 100644 --- a/Swiften/Network/BoostConnection.cpp +++ b/Swiften/Network/BoostConnection.cpp @@ -4,18 +4,20 @@ * See Documentation/Licenses/GPLv3.txt for more information. */ -#include "Swiften/Network/BoostConnection.h" +#include <Swiften/Network/BoostConnection.h> #include <iostream> #include <boost/bind.hpp> #include <boost/thread.hpp> +#include <boost/asio/placeholders.hpp> +#include <boost/asio/write.hpp> #include <Swiften/Base/Log.h> -#include "Swiften/EventLoop/EventLoop.h" +#include <Swiften/EventLoop/EventLoop.h> #include <string> -#include "Swiften/Base/ByteArray.h" -#include "Swiften/Network/HostAddressPort.h" -#include "Swiften/Base/sleep.h" +#include <Swiften/Base/ByteArray.h> +#include <Swiften/Network/HostAddressPort.h> +#include <Swiften/Base/sleep.h> namespace Swift { diff --git a/Swiften/Network/BoostConnection.h b/Swiften/Network/BoostConnection.h index 506eedf..0e7624d 100644 --- a/Swiften/Network/BoostConnection.h +++ b/Swiften/Network/BoostConnection.h @@ -6,12 +6,13 @@ #pragma once -#include <boost/asio.hpp> +#include <boost/asio/io_service.hpp> +#include <boost/asio/ip/tcp.hpp> #include <boost/enable_shared_from_this.hpp> #include <boost/thread/mutex.hpp> -#include "Swiften/Network/Connection.h" -#include "Swiften/EventLoop/EventOwner.h" +#include <Swiften/Network/Connection.h> +#include <Swiften/EventLoop/EventOwner.h> namespace boost { class thread; diff --git a/Swiften/Network/BoostConnectionFactory.cpp b/Swiften/Network/BoostConnectionFactory.cpp index 743bb61..d5f9fad 100644 --- a/Swiften/Network/BoostConnectionFactory.cpp +++ b/Swiften/Network/BoostConnectionFactory.cpp @@ -4,8 +4,8 @@ * See Documentation/Licenses/GPLv3.txt for more information. */ -#include "Swiften/Network/BoostConnectionFactory.h" -#include "Swiften/Network/BoostConnection.h" +#include <Swiften/Network/BoostConnectionFactory.h> +#include <Swiften/Network/BoostConnection.h> namespace Swift { diff --git a/Swiften/Network/BoostConnectionFactory.h b/Swiften/Network/BoostConnectionFactory.h index ea9d656..c0a105b 100644 --- a/Swiften/Network/BoostConnectionFactory.h +++ b/Swiften/Network/BoostConnectionFactory.h @@ -6,10 +6,10 @@ #pragma once -#include <boost/asio.hpp> +#include <boost/asio/io_service.hpp> -#include "Swiften/Network/ConnectionFactory.h" -#include "Swiften/Network/BoostConnection.h" +#include <Swiften/Network/ConnectionFactory.h> +#include <Swiften/Network/BoostConnection.h> namespace Swift { class BoostConnection; diff --git a/Swiften/Network/BoostConnectionServer.cpp b/Swiften/Network/BoostConnectionServer.cpp index 4c6403c..9b2ed0d 100644 --- a/Swiften/Network/BoostConnectionServer.cpp +++ b/Swiften/Network/BoostConnectionServer.cpp @@ -4,12 +4,13 @@ * See Documentation/Licenses/GPLv3.txt for more information. */ -#include "Swiften/Network/BoostConnectionServer.h" +#include <Swiften/Network/BoostConnectionServer.h> #include <boost/bind.hpp> #include <boost/system/system_error.hpp> +#include <boost/asio/placeholders.hpp> -#include "Swiften/EventLoop/EventLoop.h" +#include <Swiften/EventLoop/EventLoop.h> namespace Swift { diff --git a/Swiften/Network/BoostConnectionServer.h b/Swiften/Network/BoostConnectionServer.h index a45e598..3e9e1e0 100644 --- a/Swiften/Network/BoostConnectionServer.h +++ b/Swiften/Network/BoostConnectionServer.h @@ -7,13 +7,14 @@ #pragma once #include <boost/shared_ptr.hpp> +#include <boost/asio/io_service.hpp> +#include <boost/asio/ip/tcp.hpp> #include <boost/enable_shared_from_this.hpp> -#include <boost/asio.hpp> -#include "Swiften/Base/boost_bsignals.h" +#include <Swiften/Base/boost_bsignals.h> -#include "Swiften/Network/BoostConnection.h" -#include "Swiften/Network/ConnectionServer.h" -#include "Swiften/EventLoop/EventOwner.h" +#include <Swiften/Network/BoostConnection.h> +#include <Swiften/Network/ConnectionServer.h> +#include <Swiften/EventLoop/EventOwner.h> namespace Swift { class BoostConnectionServer : public ConnectionServer, public EventOwner, public boost::enable_shared_from_this<BoostConnectionServer> { diff --git a/Swiften/Network/BoostIOServiceThread.cpp b/Swiften/Network/BoostIOServiceThread.cpp index 031e7b5..c98a653 100644 --- a/Swiften/Network/BoostIOServiceThread.cpp +++ b/Swiften/Network/BoostIOServiceThread.cpp @@ -4,7 +4,7 @@ * See Documentation/Licenses/GPLv3.txt for more information. */ -#include "Swiften/Network/BoostIOServiceThread.h" +#include <Swiften/Network/BoostIOServiceThread.h> #include <boost/smart_ptr/make_shared.hpp> diff --git a/Swiften/Network/BoostIOServiceThread.h b/Swiften/Network/BoostIOServiceThread.h index 1f72049..ea04b02 100644 --- a/Swiften/Network/BoostIOServiceThread.h +++ b/Swiften/Network/BoostIOServiceThread.h @@ -6,8 +6,8 @@ #pragma once -#include <boost/asio.hpp> -#include <boost/thread.hpp> +#include <boost/asio/io_service.hpp> +#include <boost/thread/thread.hpp> #include <boost/shared_ptr.hpp> namespace Swift { diff --git a/Swiften/Network/BoostNetworkFactories.cpp b/Swiften/Network/BoostNetworkFactories.cpp index a8e3d0a..92cbdb8 100644 --- a/Swiften/Network/BoostNetworkFactories.cpp +++ b/Swiften/Network/BoostNetworkFactories.cpp @@ -4,9 +4,9 @@ * See Documentation/Licenses/GPLv3.txt for more information. */ -#include "Swiften/Network/BoostNetworkFactories.h" -#include "Swiften/Network/BoostTimerFactory.h" -#include "Swiften/Network/BoostConnectionFactory.h" +#include <Swiften/Network/BoostNetworkFactories.h> +#include <Swiften/Network/BoostTimerFactory.h> +#include <Swiften/Network/BoostConnectionFactory.h> #include <Swiften/Network/PlatformDomainNameResolver.h> namespace Swift { diff --git a/Swiften/Network/BoostNetworkFactories.h b/Swiften/Network/BoostNetworkFactories.h index cb7e359..abb155c 100644 --- a/Swiften/Network/BoostNetworkFactories.h +++ b/Swiften/Network/BoostNetworkFactories.h @@ -6,8 +6,8 @@ #pragma once -#include "Swiften/Network/NetworkFactories.h" -#include "Swiften/Network/BoostIOServiceThread.h" +#include <Swiften/Network/NetworkFactories.h> +#include <Swiften/Network/BoostIOServiceThread.h> namespace Swift { class EventLoop; diff --git a/Swiften/Network/BoostTimer.cpp b/Swiften/Network/BoostTimer.cpp index 12d06c1..bf042d6 100644 --- a/Swiften/Network/BoostTimer.cpp +++ b/Swiften/Network/BoostTimer.cpp @@ -4,12 +4,13 @@ * See Documentation/Licenses/GPLv3.txt for more information. */ -#include "Swiften/Network/BoostTimer.h" +#include <Swiften/Network/BoostTimer.h> #include <boost/date_time/posix_time/posix_time.hpp> #include <boost/asio.hpp> +#include <boost/bind.hpp> -#include "Swiften/EventLoop/EventLoop.h" +#include <Swiften/EventLoop/EventLoop.h> namespace Swift { diff --git a/Swiften/Network/BoostTimer.h b/Swiften/Network/BoostTimer.h index 1139dcf..bfe631b 100644 --- a/Swiften/Network/BoostTimer.h +++ b/Swiften/Network/BoostTimer.h @@ -6,12 +6,12 @@ #pragma once -#include <boost/asio.hpp> -#include <boost/thread.hpp> +#include <boost/asio/io_service.hpp> +#include <boost/asio/deadline_timer.hpp> #include <boost/enable_shared_from_this.hpp> -#include "Swiften/EventLoop/EventOwner.h" -#include "Swiften/Network/Timer.h" +#include <Swiften/EventLoop/EventOwner.h> +#include <Swiften/Network/Timer.h> namespace Swift { class EventLoop; diff --git a/Swiften/Network/BoostTimerFactory.cpp b/Swiften/Network/BoostTimerFactory.cpp index b8e628f..c0bdb56 100644 --- a/Swiften/Network/BoostTimerFactory.cpp +++ b/Swiften/Network/BoostTimerFactory.cpp @@ -4,8 +4,8 @@ * See Documentation/Licenses/GPLv3.txt for more information. */ -#include "Swiften/Network/BoostTimerFactory.h" -#include "Swiften/Network/BoostTimer.h" +#include <Swiften/Network/BoostTimerFactory.h> +#include <Swiften/Network/BoostTimer.h> namespace Swift { diff --git a/Swiften/Network/BoostTimerFactory.h b/Swiften/Network/BoostTimerFactory.h index c0e9ef7..6093db0 100644 --- a/Swiften/Network/BoostTimerFactory.h +++ b/Swiften/Network/BoostTimerFactory.h @@ -6,10 +6,10 @@ #pragma once -#include <boost/asio.hpp> +#include <boost/asio/io_service.hpp> -#include "Swiften/Network/TimerFactory.h" -#include "Swiften/Network/BoostTimer.h" +#include <Swiften/Network/TimerFactory.h> +#include <Swiften/Network/BoostTimer.h> namespace Swift { class BoostTimer; diff --git a/Swiften/Network/CAresDomainNameResolver.cpp b/Swiften/Network/CAresDomainNameResolver.cpp index dd49139..da0f49e 100644 --- a/Swiften/Network/CAresDomainNameResolver.cpp +++ b/Swiften/Network/CAresDomainNameResolver.cpp @@ -7,8 +7,8 @@ // TODO: Check the second param of postEvent. We sometimes omit it. Same // goes for the PlatformDomainNameResolver. -#include "Swiften/Network/CAresDomainNameResolver.h" -#include "Swiften/Base/Platform.h" +#include <Swiften/Network/CAresDomainNameResolver.h> +#include <Swiften/Base/Platform.h> #ifndef SWIFTEN_PLATFORM_WINDOWS #include <netdb.h> @@ -16,11 +16,11 @@ #endif #include <algorithm> -#include "Swiften/Network/DomainNameServiceQuery.h" -#include "Swiften/Network/DomainNameAddressQuery.h" -#include "Swiften/Base/ByteArray.h" -#include "Swiften/EventLoop/EventLoop.h" -#include "Swiften/Base/foreach.h" +#include <Swiften/Network/DomainNameServiceQuery.h> +#include <Swiften/Network/DomainNameAddressQuery.h> +#include <Swiften/Base/ByteArray.h> +#include <Swiften/EventLoop/EventLoop.h> +#include <Swiften/Base/foreach.h> namespace Swift { diff --git a/Swiften/Network/CAresDomainNameResolver.h b/Swiften/Network/CAresDomainNameResolver.h index a630b61..d0ff82c 100644 --- a/Swiften/Network/CAresDomainNameResolver.h +++ b/Swiften/Network/CAresDomainNameResolver.h @@ -7,11 +7,11 @@ #pragma once #include <ares.h> -#include <boost/thread.hpp> +#include <boost/thread/thread.hpp> #include <boost/thread/mutex.hpp> #include <list> -#include "Swiften/Network/DomainNameResolver.h" +#include <Swiften/Network/DomainNameResolver.h> namespace Swift { class CAresQuery; diff --git a/Swiften/Network/ChainedConnector.cpp b/Swiften/Network/ChainedConnector.cpp new file mode 100644 index 0000000..1a38e53 --- /dev/null +++ b/Swiften/Network/ChainedConnector.cpp @@ -0,0 +1,82 @@ +/* + * Copyright (c) 2011 Remko Tronçon + * Licensed under the GNU General Public License v3. + * See Documentation/Licenses/GPLv3.txt for more information. + */ + +#include <Swiften/Network/ChainedConnector.h> + +#include <boost/bind.hpp> +#include <typeinfo> + +#include <Swiften/Base/Log.h> +#include <Swiften/Base/foreach.h> +#include <Swiften/Network/Connector.h> +#include <Swiften/Network/ConnectionFactory.h> + +using namespace Swift; + +ChainedConnector::ChainedConnector( + const std::string& hostname, + DomainNameResolver* resolver, + const std::vector<ConnectionFactory*>& connectionFactories, + TimerFactory* timerFactory) : + hostname(hostname), + resolver(resolver), + connectionFactories(connectionFactories), + timerFactory(timerFactory), + timeoutMilliseconds(0) { +} + +void ChainedConnector::setTimeoutMilliseconds(int milliseconds) { + timeoutMilliseconds = milliseconds; +} + +void ChainedConnector::start() { + SWIFT_LOG(debug) << "Starting queued connector for " << hostname << std::endl; + + connectionFactoryQueue = std::deque<ConnectionFactory*>(connectionFactories.begin(), connectionFactories.end()); + tryNextConnectionFactory(); +} + +void ChainedConnector::stop() { + if (currentConnector) { + currentConnector->onConnectFinished.disconnect(boost::bind(&ChainedConnector::handleConnectorFinished, this, _1)); + currentConnector->stop(); + currentConnector.reset(); + } + finish(boost::shared_ptr<Connection>()); +} + +void ChainedConnector::tryNextConnectionFactory() { + assert(!currentConnector); + if (connectionFactoryQueue.empty()) { + SWIFT_LOG(debug) << "No more connection factories" << std::endl; + finish(boost::shared_ptr<Connection>()); + } + else { + ConnectionFactory* connectionFactory = connectionFactoryQueue.front(); + SWIFT_LOG(debug) << "Trying next connection factory: " << typeid(*connectionFactory).name() << std::endl; + connectionFactoryQueue.pop_front(); + currentConnector = Connector::create(hostname, resolver, connectionFactory, timerFactory); + currentConnector->setTimeoutMilliseconds(timeoutMilliseconds); + currentConnector->onConnectFinished.connect(boost::bind(&ChainedConnector::handleConnectorFinished, this, _1)); + currentConnector->start(); + } +} + +void ChainedConnector::handleConnectorFinished(boost::shared_ptr<Connection> connection) { + SWIFT_LOG(debug) << "Connector finished" << std::endl; + currentConnector->onConnectFinished.disconnect(boost::bind(&ChainedConnector::handleConnectorFinished, this, _1)); + currentConnector.reset(); + if (connection) { + finish(connection); + } + else { + tryNextConnectionFactory(); + } +} + +void ChainedConnector::finish(boost::shared_ptr<Connection> connection) { + onConnectFinished(connection); +} diff --git a/Swiften/Network/ChainedConnector.h b/Swiften/Network/ChainedConnector.h new file mode 100644 index 0000000..15b17f3 --- /dev/null +++ b/Swiften/Network/ChainedConnector.h @@ -0,0 +1,47 @@ +/* + * Copyright (c) 2011 Remko Tronçon + * Licensed under the GNU General Public License v3. + * See Documentation/Licenses/GPLv3.txt for more information. + */ + +#pragma once + +#include <string> +#include <vector> +#include <deque> +#include <boost/shared_ptr.hpp> + +#include <Swiften/Base/boost_bsignals.h> + +namespace Swift { + class Connection; + class Connector; + class ConnectionFactory; + class TimerFactory; + class DomainNameResolver; + + class ChainedConnector { + public: + ChainedConnector(const std::string& hostname, DomainNameResolver*, const std::vector<ConnectionFactory*>&, TimerFactory*); + + void setTimeoutMilliseconds(int milliseconds); + void start(); + void stop(); + + boost::signal<void (boost::shared_ptr<Connection>)> onConnectFinished; + + private: + void finish(boost::shared_ptr<Connection> connection); + void tryNextConnectionFactory(); + void handleConnectorFinished(boost::shared_ptr<Connection>); + + private: + std::string hostname; + DomainNameResolver* resolver; + std::vector<ConnectionFactory*> connectionFactories; + TimerFactory* timerFactory; + int timeoutMilliseconds; + std::deque<ConnectionFactory*> connectionFactoryQueue; + boost::shared_ptr<Connector> currentConnector; + }; +}; diff --git a/Swiften/Network/Connection.cpp b/Swiften/Network/Connection.cpp new file mode 100644 index 0000000..9bb29e1 --- /dev/null +++ b/Swiften/Network/Connection.cpp @@ -0,0 +1,15 @@ +/* + * Copyright (c) 2010 Remko Tronçon + * Licensed under the GNU General Public License v3. + * See Documentation/Licenses/GPLv3.txt for more information. + */ + +#include <Swiften/Network/Connection.h> + +using namespace Swift; + +Connection::Connection() { +} + +Connection::~Connection() { +} diff --git a/Swiften/Network/Connection.h b/Swiften/Network/Connection.h index 529dd82..74d25aa 100644 --- a/Swiften/Network/Connection.h +++ b/Swiften/Network/Connection.h @@ -7,13 +7,13 @@ #pragma once #include <boost/shared_ptr.hpp> +#include <Swiften/Base/boost_bsignals.h> -#include "Swiften/Base/boost_bsignals.h" -#include "Swiften/Base/ByteArray.h" -#include <string> -#include "Swiften/Network/HostAddressPort.h" +#include <Swiften/Base/ByteArray.h> namespace Swift { + class HostAddressPort; + class Connection { public: typedef boost::shared_ptr<Connection> ref; @@ -23,8 +23,8 @@ namespace Swift { WriteError }; - Connection() {} - virtual ~Connection() {} + Connection(); + virtual ~Connection(); virtual void listen() = 0; virtual void connect(const HostAddressPort& address) = 0; diff --git a/Swiften/Network/ConnectionFactory.cpp b/Swiften/Network/ConnectionFactory.cpp index dc322a4..2e38b21 100644 --- a/Swiften/Network/ConnectionFactory.cpp +++ b/Swiften/Network/ConnectionFactory.cpp @@ -4,7 +4,7 @@ * See Documentation/Licenses/GPLv3.txt for more information. */ -#include "Swiften/Network/ConnectionFactory.h" +#include <Swiften/Network/ConnectionFactory.h> namespace Swift { diff --git a/Swiften/Network/ConnectionServer.cpp b/Swiften/Network/ConnectionServer.cpp index 9631efc..78312e7 100644 --- a/Swiften/Network/ConnectionServer.cpp +++ b/Swiften/Network/ConnectionServer.cpp @@ -4,7 +4,7 @@ * See Documentation/Licenses/GPLv3.txt for more information. */ -#include "Swiften/Network/ConnectionServer.h" +#include <Swiften/Network/ConnectionServer.h> namespace Swift { diff --git a/Swiften/Network/ConnectionServer.h b/Swiften/Network/ConnectionServer.h index 8129372..b19dbf6 100644 --- a/Swiften/Network/ConnectionServer.h +++ b/Swiften/Network/ConnectionServer.h @@ -7,10 +7,10 @@ #pragma once #include <boost/shared_ptr.hpp> -#include "Swiften/Base/boost_bsignals.h" +#include <Swiften/Base/boost_bsignals.h> -#include "Swiften/Network/Connection.h" -#include "Swiften/Network/HostAddressPort.h" +#include <Swiften/Network/Connection.h> +#include <Swiften/Network/HostAddressPort.h> namespace Swift { class ConnectionServer { diff --git a/Swiften/Network/Connector.cpp b/Swiften/Network/Connector.cpp index 868bd50..8f35aba 100644 --- a/Swiften/Network/Connector.cpp +++ b/Swiften/Network/Connector.cpp @@ -4,15 +4,15 @@ * See Documentation/Licenses/GPLv3.txt for more information. */ -#include "Swiften/Network/Connector.h" +#include <Swiften/Network/Connector.h> #include <boost/bind.hpp> #include <iostream> -#include "Swiften/Network/ConnectionFactory.h" -#include "Swiften/Network/DomainNameResolver.h" -#include "Swiften/Network/DomainNameAddressQuery.h" -#include "Swiften/Network/TimerFactory.h" +#include <Swiften/Network/ConnectionFactory.h> +#include <Swiften/Network/DomainNameResolver.h> +#include <Swiften/Network/DomainNameAddressQuery.h> +#include <Swiften/Network/TimerFactory.h> #include <Swiften/Base/Log.h> namespace Swift { diff --git a/Swiften/Network/Connector.h b/Swiften/Network/Connector.h index b3e7d83..42dca77 100644 --- a/Swiften/Network/Connector.h +++ b/Swiften/Network/Connector.h @@ -7,15 +7,15 @@ #pragma once #include <deque> -#include "Swiften/Base/boost_bsignals.h" +#include <Swiften/Base/boost_bsignals.h> #include <boost/shared_ptr.hpp> -#include "Swiften/Network/DomainNameServiceQuery.h" -#include "Swiften/Network/Connection.h" -#include "Swiften/Network/Timer.h" -#include "Swiften/Network/HostAddressPort.h" +#include <Swiften/Network/DomainNameServiceQuery.h> +#include <Swiften/Network/Connection.h> +#include <Swiften/Network/Timer.h> +#include <Swiften/Network/HostAddressPort.h> #include <string> -#include "Swiften/Network/DomainNameResolveError.h" +#include <Swiften/Network/DomainNameResolveError.h> namespace Swift { class DomainNameAddressQuery; diff --git a/Swiften/Network/DomainNameAddressQuery.cpp b/Swiften/Network/DomainNameAddressQuery.cpp index fd36964..856f301 100644 --- a/Swiften/Network/DomainNameAddressQuery.cpp +++ b/Swiften/Network/DomainNameAddressQuery.cpp @@ -4,7 +4,7 @@ * See Documentation/Licenses/GPLv3.txt for more information. */ -#include "Swiften/Network/DomainNameAddressQuery.h" +#include <Swiften/Network/DomainNameAddressQuery.h> namespace Swift { diff --git a/Swiften/Network/DomainNameAddressQuery.h b/Swiften/Network/DomainNameAddressQuery.h index 5bac350..c8ed981 100644 --- a/Swiften/Network/DomainNameAddressQuery.h +++ b/Swiften/Network/DomainNameAddressQuery.h @@ -6,12 +6,12 @@ #pragma once -#include "Swiften/Base/boost_bsignals.h" +#include <Swiften/Base/boost_bsignals.h> #include <boost/optional.hpp> #include <boost/shared_ptr.hpp> -#include "Swiften/Network/DomainNameResolveError.h" -#include "Swiften/Network/HostAddress.h" +#include <Swiften/Network/DomainNameResolveError.h> +#include <Swiften/Network/HostAddress.h> namespace Swift { class DomainNameAddressQuery { diff --git a/Swiften/Network/DomainNameResolveError.h b/Swiften/Network/DomainNameResolveError.h index 632ba77..aa4441d 100644 --- a/Swiften/Network/DomainNameResolveError.h +++ b/Swiften/Network/DomainNameResolveError.h @@ -6,7 +6,7 @@ #pragma once -#include "Swiften/Base/Error.h" +#include <Swiften/Base/Error.h> namespace Swift { class DomainNameResolveError : public Error { diff --git a/Swiften/Network/DomainNameResolver.cpp b/Swiften/Network/DomainNameResolver.cpp index 96c5165..56a9d72 100644 --- a/Swiften/Network/DomainNameResolver.cpp +++ b/Swiften/Network/DomainNameResolver.cpp @@ -4,7 +4,7 @@ * See Documentation/Licenses/GPLv3.txt for more information. */ -#include "Swiften/Network/DomainNameResolver.h" +#include <Swiften/Network/DomainNameResolver.h> namespace Swift { diff --git a/Swiften/Network/DomainNameServiceQuery.cpp b/Swiften/Network/DomainNameServiceQuery.cpp index 423330c..5713b63 100644 --- a/Swiften/Network/DomainNameServiceQuery.cpp +++ b/Swiften/Network/DomainNameServiceQuery.cpp @@ -4,7 +4,7 @@ * See Documentation/Licenses/GPLv3.txt for more information. */ -#include "Swiften/Network/DomainNameServiceQuery.h" +#include <Swiften/Network/DomainNameServiceQuery.h> namespace Swift { diff --git a/Swiften/Network/DomainNameServiceQuery.h b/Swiften/Network/DomainNameServiceQuery.h index 63d5841..0bd1569 100644 --- a/Swiften/Network/DomainNameServiceQuery.h +++ b/Swiften/Network/DomainNameServiceQuery.h @@ -6,13 +6,13 @@ #pragma once -#include "Swiften/Base/boost_bsignals.h" +#include <Swiften/Base/boost_bsignals.h> #include <boost/optional.hpp> #include <vector> #include <boost/shared_ptr.hpp> #include <string> -#include "Swiften/Network/DomainNameResolveError.h" +#include <Swiften/Network/DomainNameResolveError.h> namespace Swift { class DomainNameServiceQuery { diff --git a/Swiften/Network/DummyConnection.cpp b/Swiften/Network/DummyConnection.cpp new file mode 100644 index 0000000..ffc6dc2 --- /dev/null +++ b/Swiften/Network/DummyConnection.cpp @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2010 Remko Tronçon + * Licensed under the GNU General Public License v3. + * See Documentation/Licenses/GPLv3.txt for more information. + */ + +#include <Swiften/Network/DummyConnection.h> + +#include <boost/bind.hpp> +#include <cassert> + +namespace Swift { + +DummyConnection::DummyConnection(EventLoop* eventLoop) : eventLoop(eventLoop) { +} + +void DummyConnection::receive(const ByteArray& data) { + eventLoop->postEvent(boost::bind(boost::ref(onDataRead), ByteArray(data)), shared_from_this()); +} + +void DummyConnection::listen() { + assert(false); +} + +void DummyConnection::connect(const HostAddressPort&) { + assert(false); +} + + +} diff --git a/Swiften/Network/DummyConnection.h b/Swiften/Network/DummyConnection.h index 6b426b1..3024302 100644 --- a/Swiften/Network/DummyConnection.h +++ b/Swiften/Network/DummyConnection.h @@ -6,26 +6,20 @@ #pragma once -#include <cassert> -#include <boost/bind.hpp> #include <boost/enable_shared_from_this.hpp> -#include "Swiften/Network/Connection.h" -#include "Swiften/EventLoop/EventLoop.h" -#include "Swiften/EventLoop/EventOwner.h" +#include <Swiften/Network/Connection.h> +#include <Swiften/Network/HostAddressPort.h> +#include <Swiften/EventLoop/EventLoop.h> +#include <Swiften/EventLoop/EventOwner.h> namespace Swift { class DummyConnection : public Connection, public EventOwner, public boost::enable_shared_from_this<DummyConnection> { public: - DummyConnection(EventLoop* eventLoop) : eventLoop(eventLoop) {} + DummyConnection(EventLoop* eventLoop); - void listen() { - assert(false); - } - - void connect(const HostAddressPort&) { - assert(false); - } + void listen(); + void connect(const HostAddressPort&); void disconnect() { //assert(false); @@ -36,9 +30,7 @@ namespace Swift { onDataSent(data); } - void receive(const ByteArray& data) { - eventLoop->postEvent(boost::bind(boost::ref(onDataRead), ByteArray(data)), shared_from_this()); - } + void receive(const ByteArray& data); HostAddressPort getLocalAddress() const { return localAddress; diff --git a/Swiften/Network/DummyTimerFactory.cpp b/Swiften/Network/DummyTimerFactory.cpp index 105b103..16428b7 100644 --- a/Swiften/Network/DummyTimerFactory.cpp +++ b/Swiften/Network/DummyTimerFactory.cpp @@ -4,12 +4,12 @@ * See Documentation/Licenses/GPLv3.txt for more information. */ -#include "Swiften/Network/DummyTimerFactory.h" +#include <Swiften/Network/DummyTimerFactory.h> #include <algorithm> -#include "Swiften/Base/foreach.h" -#include "Swiften/Network/Timer.h" +#include <Swiften/Base/foreach.h> +#include <Swiften/Network/Timer.h> namespace Swift { diff --git a/Swiften/Network/DummyTimerFactory.h b/Swiften/Network/DummyTimerFactory.h index 408b647..0c49f3d 100644 --- a/Swiften/Network/DummyTimerFactory.h +++ b/Swiften/Network/DummyTimerFactory.h @@ -8,7 +8,7 @@ #include <list> -#include "Swiften/Network/TimerFactory.h" +#include <Swiften/Network/TimerFactory.h> namespace Swift { class DummyTimerFactory : public TimerFactory { diff --git a/Swiften/Network/EnvironmentProxyProvider.cpp b/Swiften/Network/EnvironmentProxyProvider.cpp new file mode 100644 index 0000000..7701da1 --- /dev/null +++ b/Swiften/Network/EnvironmentProxyProvider.cpp @@ -0,0 +1,48 @@ +/* + * Copyright (c) 2010-2011 Thilo Cestonaro + * Licensed under the simplified BSD license. + * See Documentation/Licenses/BSD-simplified.txt for more information. + */ + +#include <stdio.h> +#include <stdlib.h> +#include <iostream> + +#include <Swiften/Base/Log.h> +#include <Swiften/Network/EnvironmentProxyProvider.h> + +namespace Swift { + +EnvironmentProxyProvider::EnvironmentProxyProvider() { + socksProxy = getFromEnv("all_proxy", "socks"); + httpProxy = getFromEnv("http_proxy", "http"); + SWIFT_LOG(debug) << "Environment: SOCKS5 => " << socksProxy.toString() << "; HTTP Connect => " << httpProxy.toString() << std::endl; +} + +HostAddressPort EnvironmentProxyProvider::getHTTPConnectProxy() const { + return httpProxy; +} + +HostAddressPort EnvironmentProxyProvider::getSOCKS5Proxy() const { + return socksProxy; +} + +HostAddressPort EnvironmentProxyProvider::getFromEnv(const char* envVarName, std::string proxyProtocol) { + char* envVar = NULL; + std::string address; + int port = 0; + + envVar = getenv(envVarName); + + proxyProtocol += "://"; + address = envVar != NULL ? envVar : "0.0.0.0"; + if(envVar != NULL && address.compare(0, proxyProtocol.length(), proxyProtocol) == 0) { + address = address.substr(proxyProtocol.length(), address.length()); + port = atoi(address.substr(address.find(':') + 1, address.length()).c_str()); + address = address.substr(0, address.find(':')); + } + + return HostAddressPort(HostAddress(address), port); +} + +} diff --git a/Swiften/Network/EnvironmentProxyProvider.h b/Swiften/Network/EnvironmentProxyProvider.h new file mode 100644 index 0000000..224d301 --- /dev/null +++ b/Swiften/Network/EnvironmentProxyProvider.h @@ -0,0 +1,24 @@ +/* + * Copyright (c) 2010-2011 Thilo Cestonaro + * Licensed under the simplified BSD license. + * See Documentation/Licenses/BSD-simplified.txt for more information. + */ + +#pragma once + +#include <Swiften/Network/ProxyProvider.h> + +namespace Swift { + class EnvironmentProxyProvider : public ProxyProvider { + public: + EnvironmentProxyProvider(); + virtual HostAddressPort getHTTPConnectProxy() const; + virtual HostAddressPort getSOCKS5Proxy() const; + private: + HostAddressPort getFromEnv(const char* envVarName, std::string proxyProtocol); + HostAddressPort socksProxy; + HostAddressPort httpProxy; + }; +} + + diff --git a/Swiften/Network/FakeConnection.cpp b/Swiften/Network/FakeConnection.cpp new file mode 100644 index 0000000..be5555c --- /dev/null +++ b/Swiften/Network/FakeConnection.cpp @@ -0,0 +1,64 @@ +/* + * Copyright (c) 2010 Remko Tronçon + * Licensed under the GNU General Public License v3. + * See Documentation/Licenses/GPLv3.txt for more information. + */ + +#include <Swiften/Network/FakeConnection.h> + +#include <boost/bind.hpp> + +namespace Swift { + +FakeConnection::FakeConnection(EventLoop* eventLoop) : eventLoop(eventLoop), state(Initial), delayConnect(false) { +} + +FakeConnection::~FakeConnection() { +} + +void FakeConnection::listen() { + assert(false); +} + +void FakeConnection::setError(const Error& e) { + error = boost::optional<Error>(e); + state = DisconnectedWithError; + if (connectedTo) { + eventLoop->postEvent( + boost::bind(boost::ref(onDisconnected), error), + shared_from_this()); + } +} + +void FakeConnection::connect(const HostAddressPort& address) { + if (delayConnect) { + state = Connecting; + } + else { + if (!error) { + connectedTo = address; + state = Connected; + } + else { + state = DisconnectedWithError; + } + eventLoop->postEvent( + boost::bind(boost::ref(onConnectFinished), error), + shared_from_this()); + } +} + +void FakeConnection::disconnect() { + if (!error) { + state = Disconnected; + } + else { + state = DisconnectedWithError; + } + connectedTo.reset(); + eventLoop->postEvent( + boost::bind(boost::ref(onDisconnected), error), + shared_from_this()); +} + +} diff --git a/Swiften/Network/FakeConnection.h b/Swiften/Network/FakeConnection.h index 4e2e960..65f6650 100644 --- a/Swiften/Network/FakeConnection.h +++ b/Swiften/Network/FakeConnection.h @@ -7,14 +7,13 @@ #pragma once #include <boost/optional.hpp> -#include <boost/bind.hpp> #include <boost/enable_shared_from_this.hpp> #include <vector> -#include "Swiften/Network/Connection.h" -#include "Swiften/Network/HostAddressPort.h" -#include "Swiften/EventLoop/EventOwner.h" -#include "Swiften/EventLoop/EventLoop.h" +#include <Swiften/Network/Connection.h> +#include <Swiften/Network/HostAddressPort.h> +#include <Swiften/EventLoop/EventOwner.h> +#include <Swiften/EventLoop/EventLoop.h> namespace Swift { class FakeConnection : @@ -30,56 +29,17 @@ namespace Swift { DisconnectedWithError }; - FakeConnection(EventLoop* eventLoop) : eventLoop(eventLoop), state(Initial), delayConnect(false) {} - - virtual void listen() { - assert(false); - } + FakeConnection(EventLoop* eventLoop); + ~FakeConnection(); + virtual void listen(); virtual HostAddressPort getLocalAddress() const { return HostAddressPort(); } - void setError(const Error& e) { - error = boost::optional<Error>(e); - state = DisconnectedWithError; - if (connectedTo) { - eventLoop->postEvent( - boost::bind(boost::ref(onDisconnected), error), - shared_from_this()); - } - } - - virtual void connect(const HostAddressPort& address) { - if (delayConnect) { - state = Connecting; - } - else { - if (!error) { - connectedTo = address; - state = Connected; - } - else { - state = DisconnectedWithError; - } - eventLoop->postEvent( - boost::bind(boost::ref(onConnectFinished), error), - shared_from_this()); - } - } - - virtual void disconnect() { - if (!error) { - state = Disconnected; - } - else { - state = DisconnectedWithError; - } - connectedTo.reset(); - eventLoop->postEvent( - boost::bind(boost::ref(onDisconnected), error), - shared_from_this()); - } + void setError(const Error& e); + virtual void connect(const HostAddressPort& address); + virtual void disconnect(); virtual void write(const ByteArray& data) { dataWritten.push_back(data); diff --git a/Swiften/Network/GConfProxyProvider.cpp b/Swiften/Network/GConfProxyProvider.cpp new file mode 100644 index 0000000..26de4d8 --- /dev/null +++ b/Swiften/Network/GConfProxyProvider.cpp @@ -0,0 +1,51 @@ +/* + * Copyright (c) 2010-2011 Thilo Cestonaro + * Licensed under the simplified BSD license. + * See Documentation/Licenses/BSD-simplified.txt for more information. + */ + +#include <stdio.h> +#include <stdlib.h> +#include <iostream> + +#include <gconf/gconf-client.h> + +#include <Swiften/Base/Log.h> +#include <Swiften/Network/GConfProxyProvider.h> + +namespace Swift { + +GConfProxyProvider::GConfProxyProvider() { + socksProxy = getFromGConf("/system/proxy/socks_host", "/system/proxy/socks_port"); + httpProxy = getFromGConf("/system/http_proxy/host", "/system/http_proxy/port"); + SWIFT_LOG(debug) << "GConf: SOCKS5 => " << socksProxy.toString() << "; HTTP Connect => " << httpProxy.toString() << std::endl; +} + +HostAddressPort GConfProxyProvider::getHTTPConnectProxy() const { + return httpProxy; +} + +HostAddressPort GConfProxyProvider::getSOCKS5Proxy() const { + return socksProxy; +} + +HostAddressPort GConfProxyProvider::getFromGConf(const char* gcHost, const char* gcPort) { + std::string address; + int port = 0; + gchar* str; + + GConfClient* client = gconf_client_get_default(); + + str = gconf_client_get_string(client, gcHost, NULL); + port = static_cast<int> (gconf_client_get_int(client, gcPort, NULL)); + + if(str) { + address = static_cast<char*> (str); + g_free(str); + } + + g_object_unref(client); + return HostAddressPort(HostAddress(address), port); +} + +} diff --git a/Swiften/Network/GConfProxyProvider.h b/Swiften/Network/GConfProxyProvider.h new file mode 100644 index 0000000..31f38a9 --- /dev/null +++ b/Swiften/Network/GConfProxyProvider.h @@ -0,0 +1,24 @@ +/* + * Copyright (c) 2010-2011 Thilo Cestonaro + * Licensed under the simplified BSD license. + * See Documentation/Licenses/BSD-simplified.txt for more information. + */ + +#pragma once + +#include <Swiften/Network/ProxyProvider.h> + +namespace Swift { + class GConfProxyProvider : public ProxyProvider { + public: + GConfProxyProvider(); + virtual HostAddressPort getHTTPConnectProxy() const; + virtual HostAddressPort getSOCKS5Proxy() const; + private: + HostAddressPort getFromGConf(const char* gcHost, const char* gcPort); + HostAddressPort socksProxy; + HostAddressPort httpProxy; + }; +} + + diff --git a/Swiften/Network/HTTPConnectProxiedConnection.cpp b/Swiften/Network/HTTPConnectProxiedConnection.cpp new file mode 100644 index 0000000..dca08df --- /dev/null +++ b/Swiften/Network/HTTPConnectProxiedConnection.cpp @@ -0,0 +1,100 @@ +/* + * Copyright (c) 2010-2011 Thilo Cestonaro + * Licensed under the simplified BSD license. + * See Documentation/Licenses/BSD-simplified.txt for more information. + */ + +#include <Swiften/Network/HTTPConnectProxiedConnection.h> + +#include <iostream> +#include <boost/bind.hpp> +#include <boost/thread.hpp> +#include <boost/lexical_cast.hpp> + +#include <Swiften/Base/Log.h> +#include <Swiften/Base/String.h> +#include <Swiften/Base/ByteArray.h> +#include <Swiften/Network/HostAddressPort.h> +#include <Swiften/Network/ConnectionFactory.h> + +using namespace Swift; + +HTTPConnectProxiedConnection::HTTPConnectProxiedConnection(ConnectionFactory* connectionFactory, HostAddressPort proxy) : connectionFactory_(connectionFactory), proxy_(proxy), server_(HostAddressPort(HostAddress("0.0.0.0"), 0)) { + connected_ = false; +} + +HTTPConnectProxiedConnection::~HTTPConnectProxiedConnection() { + if (connection_) { + connection_->onDataRead.disconnect(boost::bind(&HTTPConnectProxiedConnection::handleDataRead, shared_from_this(), _1)); + connection_->onDisconnected.disconnect(boost::bind(&HTTPConnectProxiedConnection::handleDisconnected, shared_from_this(), _1)); + } + + if (connected_) { + std::cerr << "Warning: Connection was still established." << std::endl; + } +} + +void HTTPConnectProxiedConnection::connect(const HostAddressPort& server) { + server_ = server; + connection_ = connectionFactory_->createConnection(); + connection_->onConnectFinished.connect(boost::bind(&HTTPConnectProxiedConnection::handleConnectionConnectFinished, shared_from_this(), _1)); + connection_->onDataRead.connect(boost::bind(&HTTPConnectProxiedConnection::handleDataRead, shared_from_this(), _1)); + connection_->onDisconnected.connect(boost::bind(&HTTPConnectProxiedConnection::handleDisconnected, shared_from_this(), _1)); + connection_->connect(proxy_); +} + +void HTTPConnectProxiedConnection::listen() { + assert(false); + connection_->listen(); +} + +void HTTPConnectProxiedConnection::disconnect() { + connected_ = false; + connection_->disconnect(); +} + +void HTTPConnectProxiedConnection::handleDisconnected(const boost::optional<Error>& error) { + onDisconnected(error); +} + +void HTTPConnectProxiedConnection::write(const ByteArray& data) { + connection_->write(data); +} + +void HTTPConnectProxiedConnection::handleConnectionConnectFinished(bool error) { + connection_->onConnectFinished.disconnect(boost::bind(&HTTPConnectProxiedConnection::handleConnectionConnectFinished, shared_from_this(), _1)); + if (!error) { + std::stringstream connect; + connect << "CONNECT " << server_.getAddress().toString() << ":" << server_.getPort() << " HTTP/1.1\r\n\r\n"; + connection_->write(ByteArray(connect.str())); + } + else { + onConnectFinished(true); + } +} + +void HTTPConnectProxiedConnection::handleDataRead(const ByteArray& data) { + if (!connected_) { + SWIFT_LOG(debug) << data.toString() << std::endl; + std::vector<std::string> tmp = String::split(data.toString(), ' '); + if(tmp.size() > 1) { + int status = boost::lexical_cast<int> (tmp[1].c_str()); + SWIFT_LOG(debug) << "Proxy Status: " << status << std::endl; + if (status / 100 == 2) { // all 2XX states are OK + connected_ = true; + onConnectFinished(false); + return; + } + SWIFT_LOG(debug) << "HTTP Proxy returned an error: " << data.toString() << std::endl; + } + disconnect(); + onConnectFinished(true); + } + else { + onDataRead(data); + } +} + +HostAddressPort HTTPConnectProxiedConnection::getLocalAddress() const { + return connection_->getLocalAddress(); +} diff --git a/Swiften/Network/HTTPConnectProxiedConnection.h b/Swiften/Network/HTTPConnectProxiedConnection.h new file mode 100644 index 0000000..4719267 --- /dev/null +++ b/Swiften/Network/HTTPConnectProxiedConnection.h @@ -0,0 +1,54 @@ +/* + * Copyright (c) 2010-2011 Thilo Cestonaro + * Licensed under the simplified BSD license. + * See Documentation/Licenses/BSD-simplified.txt for more information. + */ + +#pragma once + +#include <boost/enable_shared_from_this.hpp> + +#include <Swiften/Network/Connection.h> +#include <Swiften/Network/HostAddressPort.h> + +namespace boost { + class thread; + namespace system { + class error_code; + } +} + +namespace Swift { + class ConnectionFactory; + + class HTTPConnectProxiedConnection : public Connection, public boost::enable_shared_from_this<HTTPConnectProxiedConnection> { + public: + typedef boost::shared_ptr<HTTPConnectProxiedConnection> ref; + + ~HTTPConnectProxiedConnection(); + + static ref create(ConnectionFactory* connectionFactory, HostAddressPort proxy) { + return ref(new HTTPConnectProxiedConnection(connectionFactory, proxy)); + } + + virtual void listen(); + virtual void connect(const HostAddressPort& address); + virtual void disconnect(); + virtual void write(const ByteArray& data); + + virtual HostAddressPort getLocalAddress() const; + private: + HTTPConnectProxiedConnection(ConnectionFactory* connectionFactory, HostAddressPort proxy); + + void handleConnectionConnectFinished(bool error); + void handleDataRead(const ByteArray& data); + void handleDisconnected(const boost::optional<Error>& error); + + private: + bool connected_; + ConnectionFactory* connectionFactory_; + HostAddressPort proxy_; + HostAddressPort server_; + boost::shared_ptr<Connection> connection_; + }; +} diff --git a/Swiften/Network/HTTPConnectProxiedConnectionFactory.cpp b/Swiften/Network/HTTPConnectProxiedConnectionFactory.cpp new file mode 100644 index 0000000..ab7f18e --- /dev/null +++ b/Swiften/Network/HTTPConnectProxiedConnectionFactory.cpp @@ -0,0 +1,20 @@ +/* + * Copyright (c) 2010-2011 Thilo Cestonaro + * Licensed under the simplified BSD license. + * See Documentation/Licenses/BSD-simplified.txt for more information. + */ + +#include <Swiften/Network/HTTPConnectProxiedConnectionFactory.h> + +#include <Swiften/Network/HTTPConnectProxiedConnection.h> + +namespace Swift { + +HTTPConnectProxiedConnectionFactory::HTTPConnectProxiedConnectionFactory(ConnectionFactory* connectionFactory, const HostAddressPort& proxy) : connectionFactory_(connectionFactory), proxy_(proxy) { +} + +boost::shared_ptr<Connection> HTTPConnectProxiedConnectionFactory::createConnection() { + return HTTPConnectProxiedConnection::create(connectionFactory_, proxy_); +} + +} diff --git a/Swiften/Network/HTTPConnectProxiedConnectionFactory.h b/Swiften/Network/HTTPConnectProxiedConnectionFactory.h new file mode 100644 index 0000000..b475586 --- /dev/null +++ b/Swiften/Network/HTTPConnectProxiedConnectionFactory.h @@ -0,0 +1,23 @@ +/* + * Copyright (c) 2010-2011 Thilo Cestonaro + * Licensed under the simplified BSD license. + * See Documentation/Licenses/BSD-simplified.txt for more information. + */ + +#pragma once + +#include <Swiften/Network/ConnectionFactory.h> +#include <Swiften/Network/HostAddressPort.h> + +namespace Swift { + class HTTPConnectProxiedConnectionFactory : public ConnectionFactory { + public: + HTTPConnectProxiedConnectionFactory(ConnectionFactory* connectionFactory, const HostAddressPort& proxy); + + virtual boost::shared_ptr<Connection> createConnection(); + + private: + ConnectionFactory* connectionFactory_; + HostAddressPort proxy_; + }; +} diff --git a/Swiften/Network/HostAddress.cpp b/Swiften/Network/HostAddress.cpp index 7acd407..7ba2a7f 100644 --- a/Swiften/Network/HostAddress.cpp +++ b/Swiften/Network/HostAddress.cpp @@ -4,7 +4,7 @@ * See Documentation/Licenses/GPLv3.txt for more information. */ -#include "Swiften/Network/HostAddress.h" +#include <Swiften/Network/HostAddress.h> #include <boost/numeric/conversion/cast.hpp> #include <boost/lexical_cast.hpp> @@ -12,7 +12,7 @@ #include <stdexcept> #include <boost/array.hpp> -#include "Swiften/Base/foreach.h" +#include <Swiften/Base/foreach.h> #include <string> namespace Swift { @@ -24,7 +24,7 @@ HostAddress::HostAddress(const std::string& address) { try { address_ = boost::asio::ip::address::from_string(address); } - catch (const std::exception& t) { + catch (const std::exception&) { } } @@ -57,4 +57,8 @@ bool HostAddress::isValid() const { return !(address_.is_v4() && address_.to_v4().to_ulong() == 0); } +boost::asio::ip::address HostAddress::getRawAddress() const { + return address_; +} + } diff --git a/Swiften/Network/HostAddress.h b/Swiften/Network/HostAddress.h index 34ccd24..0b3bdda 100644 --- a/Swiften/Network/HostAddress.h +++ b/Swiften/Network/HostAddress.h @@ -3,16 +3,12 @@ * Licensed under the GNU General Public License v3. * See Documentation/Licenses/GPLv3.txt for more information. */ - #pragma once #include <string> -#include <vector> -#include <boost/asio.hpp> +#include <boost/asio/ip/address.hpp> namespace Swift { - - class HostAddress { public: HostAddress(); @@ -21,6 +17,7 @@ namespace Swift { HostAddress(const boost::asio::ip::address& address); std::string toString() const; + boost::asio::ip::address getRawAddress() const; bool operator==(const HostAddress& o) const { return address_ == o.address_; diff --git a/Swiften/Network/HostAddressPort.cpp b/Swiften/Network/HostAddressPort.cpp new file mode 100644 index 0000000..e2e6012 --- /dev/null +++ b/Swiften/Network/HostAddressPort.cpp @@ -0,0 +1,23 @@ +/* + * Copyright (c) 2010 Remko Tronçon + * Licensed under the GNU General Public License v3. + * See Documentation/Licenses/GPLv3.txt for more information. + */ + +#include <Swiften/Network/HostAddressPort.h> + +#include <boost/lexical_cast.hpp> + +using namespace Swift; + +HostAddressPort::HostAddressPort(const HostAddress& address, int port) : address_(address), port_(port) { +} + +HostAddressPort::HostAddressPort(const boost::asio::ip::tcp::endpoint& endpoint) { + address_ = HostAddress(endpoint.address()); + port_ = endpoint.port(); +} + +std::string HostAddressPort::toString() const { + return getAddress().toString() + ":" + boost::lexical_cast<std::string>(getPort()); +} diff --git a/Swiften/Network/HostAddressPort.h b/Swiften/Network/HostAddressPort.h index 6883380..e3c0413 100644 --- a/Swiften/Network/HostAddressPort.h +++ b/Swiften/Network/HostAddressPort.h @@ -6,21 +6,15 @@ #pragma once -#include <boost/asio.hpp> +#include <boost/asio/ip/tcp.hpp> -#include "Swiften/Network/HostAddress.h" +#include <Swiften/Network/HostAddress.h> namespace Swift { class HostAddressPort { public: - HostAddressPort(const HostAddress& address = HostAddress(), int port = -1) : address_(address), port_(port) { - } - - HostAddressPort(const boost::asio::ip::tcp::endpoint& endpoint) { - address_ = HostAddress(endpoint.address()); - port_ = endpoint.port(); - } - + HostAddressPort(const HostAddress& address = HostAddress(), int port = -1); + HostAddressPort(const boost::asio::ip::tcp::endpoint& endpoint); const HostAddress& getAddress() const { return address_; @@ -37,6 +31,8 @@ namespace Swift { bool isValid() const { return address_.isValid() && port_ > 0; } + + std::string toString() const; private: HostAddress address_; diff --git a/Swiften/Network/MacOSXProxyProvider.cpp b/Swiften/Network/MacOSXProxyProvider.cpp new file mode 100644 index 0000000..dd44eff --- /dev/null +++ b/Swiften/Network/MacOSXProxyProvider.cpp @@ -0,0 +1,97 @@ +/* + * Copyright (c) 2010-2011 Thilo Cestonaro + * Licensed under the simplified BSD license. + * See Documentation/Licenses/BSD-simplified.txt for more information. + */ + +#include <Swiften/Base/Platform.h> +#include <Swiften/Network/MacOSXProxyProvider.h> + +#include <stdio.h> +#include <stdlib.h> +#include <iostream> +#include <utility> + +#ifndef SWIFTEN_PLATFORM_IPHONE +#include <SystemConfiguration/SystemConfiguration.h> +#endif + +using namespace Swift; + +#ifndef SWIFTEN_PLATFORM_IPHONE +static HostAddressPort getFromDictionary(CFDictionaryRef dict, CFStringRef enabledKey, CFStringRef hostKey, CFStringRef portKey) { + CFNumberRef numberValue = NULL; + HostAddressPort ret = HostAddressPort(HostAddress(), 0); + + if(CFDictionaryGetValueIfPresent(dict, reinterpret_cast<const void*> (enabledKey), reinterpret_cast<const void**> (&numberValue)) == true) { + const int i = 0; + CFNumberRef zero = CFNumberCreate(kCFAllocatorDefault, kCFNumberIntType, &i); + CFComparisonResult result = CFNumberCompare(numberValue, zero, NULL); + CFRelease(numberValue); + + if(result != kCFCompareEqualTo) { + int port = 0; + std::string host = ""; + + try { + CFNumberRef numberValue = reinterpret_cast<CFNumberRef> (CFDictionaryGetValue(dict, portKey)); + if(numberValue != NULL) { + CFNumberGetValue(numberValue, kCFNumberIntType, &port); + CFRelease(numberValue); + } + + CFStringRef stringValue = reinterpret_cast<CFStringRef> (CFDictionaryGetValue(dict, hostKey)); + if(stringValue != NULL) { + std::vector<char> buffer; + // length must be +1 for the ending zero; and the Docu of CFStringGetCString tells it like + // if the string is toby the length must be at least 5. + CFIndex length = CFStringGetLength(stringValue) + 1; + buffer.resize(length); + if(CFStringGetCString(stringValue, &buffer[0], length, kCFStringEncodingMacRoman)) { + for(std::vector<char>::iterator iter = buffer.begin(); iter != buffer.end(); iter++) { + host += *iter; + } + } + CFRelease(stringValue); + } + } + catch(...) { + std::cerr << "Exception caught ... " << std::endl; + } + + if(host != "" && port != 0) { + ret = HostAddressPort(HostAddress(host), port); + } + } + } + return ret; +} +#endif +namespace Swift { + +MacOSXProxyProvider::MacOSXProxyProvider() { +} + +HostAddressPort MacOSXProxyProvider::getHTTPConnectProxy() const { + HostAddressPort result; +#ifndef SWIFTEN_PLATFORM_IPHONE + CFDictionaryRef proxies = SCDynamicStoreCopyProxies(NULL); + if(proxies != NULL) { + result = getFromDictionary(proxies, kSCPropNetProxiesHTTPEnable, kSCPropNetProxiesHTTPProxy, kSCPropNetProxiesHTTPPort); + } +#endif + return result; +} + +HostAddressPort MacOSXProxyProvider::getSOCKS5Proxy() const { + HostAddressPort result; +#ifndef SWIFTEN_PLATFORM_IPHONE + CFDictionaryRef proxies = SCDynamicStoreCopyProxies(NULL); + if(proxies != NULL) { + result = getFromDictionary(proxies, kSCPropNetProxiesSOCKSEnable, kSCPropNetProxiesSOCKSProxy, kSCPropNetProxiesSOCKSPort); + } +#endif + return result; +} + +} diff --git a/Swiften/Network/MacOSXProxyProvider.h b/Swiften/Network/MacOSXProxyProvider.h new file mode 100644 index 0000000..6666d30 --- /dev/null +++ b/Swiften/Network/MacOSXProxyProvider.h @@ -0,0 +1,18 @@ +/* + * Copyright (c) 2010-2011 Thilo Cestonaro + * Licensed under the simplified BSD license. + * See Documentation/Licenses/BSD-simplified.txt for more information. + */ + +#pragma once +#include <Swiften/Network/ProxyProvider.h> +#include <CoreFoundation/CoreFoundation.h> + +namespace Swift { + class MacOSXProxyProvider : public ProxyProvider { + public: + MacOSXProxyProvider(); + virtual HostAddressPort getHTTPConnectProxy() const; + virtual HostAddressPort getSOCKS5Proxy() const; + }; +} diff --git a/Swiften/Network/NetworkFactories.cpp b/Swiften/Network/NetworkFactories.cpp index 361cb90..7046fd3 100644 --- a/Swiften/Network/NetworkFactories.cpp +++ b/Swiften/Network/NetworkFactories.cpp @@ -4,7 +4,7 @@ * See Documentation/Licenses/GPLv3.txt for more information. */ -#include "Swiften/Network/NetworkFactories.h" +#include <Swiften/Network/NetworkFactories.h> namespace Swift { diff --git a/Swiften/Network/NullProxyProvider.cpp b/Swiften/Network/NullProxyProvider.cpp new file mode 100644 index 0000000..3b9d94d --- /dev/null +++ b/Swiften/Network/NullProxyProvider.cpp @@ -0,0 +1,20 @@ +/* + * Copyright (c) 2011 Remko Tronçon + * Licensed under the simplified BSD license. + * See Documentation/Licenses/BSD-simplified.txt for more information. + */ + +#include <Swiften/Network/NullProxyProvider.h> + +using namespace Swift; + +NullProxyProvider::NullProxyProvider() { +} + +HostAddressPort NullProxyProvider::getHTTPConnectProxy() const { + return HostAddressPort(); +} + +HostAddressPort NullProxyProvider::getSOCKS5Proxy() const { + return HostAddressPort(); +} diff --git a/Swiften/Network/NullProxyProvider.h b/Swiften/Network/NullProxyProvider.h new file mode 100644 index 0000000..544bea2 --- /dev/null +++ b/Swiften/Network/NullProxyProvider.h @@ -0,0 +1,19 @@ +/* + * Copyright (c) 2011 Remko Tronçon + * Licensed under the simplified BSD license. + * See Documentation/Licenses/BSD-simplified.txt for more information. + */ + +#pragma once + +#include <Swiften/Network/ProxyProvider.h> + +namespace Swift { + class NullProxyProvider : public ProxyProvider { + public: + NullProxyProvider(); + + virtual HostAddressPort getHTTPConnectProxy() const; + virtual HostAddressPort getSOCKS5Proxy() const; + }; +} diff --git a/Swiften/Network/PlatformDomainNameAddressQuery.cpp b/Swiften/Network/PlatformDomainNameAddressQuery.cpp index 1832255..ec7e663 100644 --- a/Swiften/Network/PlatformDomainNameAddressQuery.cpp +++ b/Swiften/Network/PlatformDomainNameAddressQuery.cpp @@ -6,6 +6,8 @@ #include <Swiften/Network/PlatformDomainNameAddressQuery.h> +#include <boost/asio/ip/tcp.hpp> + #include <Swiften/Network/PlatformDomainNameResolver.h> #include <Swiften/EventLoop/EventLoop.h> diff --git a/Swiften/Network/PlatformDomainNameAddressQuery.h b/Swiften/Network/PlatformDomainNameAddressQuery.h index c2854ac..e1dc05f 100644 --- a/Swiften/Network/PlatformDomainNameAddressQuery.h +++ b/Swiften/Network/PlatformDomainNameAddressQuery.h @@ -6,7 +6,7 @@ #pragma once -#include <boost/asio.hpp> +#include <boost/asio/io_service.hpp> #include <boost/enable_shared_from_this.hpp> #include <Swiften/Network/DomainNameAddressQuery.h> diff --git a/Swiften/Network/PlatformDomainNameResolver.cpp b/Swiften/Network/PlatformDomainNameResolver.cpp index f2c1e36..63f7404 100644 --- a/Swiften/Network/PlatformDomainNameResolver.cpp +++ b/Swiften/Network/PlatformDomainNameResolver.cpp @@ -4,10 +4,10 @@ * See Documentation/Licenses/GPLv3.txt for more information. */ -#include "Swiften/Network/PlatformDomainNameResolver.h" +#include <Swiften/Network/PlatformDomainNameResolver.h> // Putting this early on, because some system types conflict with thread -#include "Swiften/Network/PlatformDomainNameServiceQuery.h" +#include <Swiften/Network/PlatformDomainNameServiceQuery.h> #include <string> #include <vector> @@ -16,11 +16,11 @@ #include <algorithm> #include <string> -#include "Swiften/IDN/IDNA.h" -#include "Swiften/Network/HostAddress.h" -#include "Swiften/EventLoop/EventLoop.h" -#include "Swiften/Network/HostAddressPort.h" -#include "Swiften/Network/DomainNameAddressQuery.h" +#include <Swiften/IDN/IDNA.h> +#include <Swiften/Network/HostAddress.h> +#include <Swiften/EventLoop/EventLoop.h> +#include <Swiften/Network/HostAddressPort.h> +#include <Swiften/Network/DomainNameAddressQuery.h> #include <Swiften/Network/PlatformDomainNameAddressQuery.h> using namespace Swift; diff --git a/Swiften/Network/PlatformDomainNameResolver.h b/Swiften/Network/PlatformDomainNameResolver.h index e681331..295ecc5 100644 --- a/Swiften/Network/PlatformDomainNameResolver.h +++ b/Swiften/Network/PlatformDomainNameResolver.h @@ -7,7 +7,7 @@ #pragma once #include <deque> -#include <boost/thread.hpp> +#include <boost/thread/thread.hpp> #include <boost/thread/mutex.hpp> #include <boost/thread/condition_variable.hpp> diff --git a/Swiften/Network/PlatformDomainNameServiceQuery.cpp b/Swiften/Network/PlatformDomainNameServiceQuery.cpp index 7d8074d..56c9748 100644 --- a/Swiften/Network/PlatformDomainNameServiceQuery.cpp +++ b/Swiften/Network/PlatformDomainNameServiceQuery.cpp @@ -6,11 +6,11 @@ #include <boost/asio.hpp> -#include "Swiften/Network/PlatformDomainNameServiceQuery.h" +#include <Swiften/Network/PlatformDomainNameServiceQuery.h> #pragma GCC diagnostic ignored "-Wold-style-cast" -#include "Swiften/Base/Platform.h" +#include <Swiften/Base/Platform.h> #include <stdlib.h> #ifdef SWIFTEN_PLATFORM_WINDOWS #undef UNICODE @@ -26,9 +26,9 @@ #endif #include <boost/bind.hpp> -#include "Swiften/Base/ByteArray.h" -#include "Swiften/EventLoop/EventLoop.h" -#include "Swiften/Base/foreach.h" +#include <Swiften/Base/ByteArray.h> +#include <Swiften/EventLoop/EventLoop.h> +#include <Swiften/Base/foreach.h> #include <Swiften/Base/Log.h> #include <Swiften/Network/PlatformDomainNameResolver.h> diff --git a/Swiften/Network/PlatformDomainNameServiceQuery.h b/Swiften/Network/PlatformDomainNameServiceQuery.h index 52f8bc1..3372517 100644 --- a/Swiften/Network/PlatformDomainNameServiceQuery.h +++ b/Swiften/Network/PlatformDomainNameServiceQuery.h @@ -8,8 +8,8 @@ #include <boost/enable_shared_from_this.hpp> -#include "Swiften/Network/DomainNameServiceQuery.h" -#include "Swiften/EventLoop/EventOwner.h" +#include <Swiften/Network/DomainNameServiceQuery.h> +#include <Swiften/EventLoop/EventOwner.h> #include <string> #include <Swiften/Network/PlatformDomainNameQuery.h> diff --git a/Swiften/Network/PlatformProxyProvider.h b/Swiften/Network/PlatformProxyProvider.h new file mode 100644 index 0000000..1a0a1c6 --- /dev/null +++ b/Swiften/Network/PlatformProxyProvider.h @@ -0,0 +1,26 @@ +/* + * Copyright (c) 2010-2011 Thilo Cestonaro + * Licensed under the simplified BSD license. + * See Documentation/Licenses/BSD-simplified.txt for more information. + */ + +#pragma once + +#include <Swiften/Base/Platform.h> + +#if defined(SWIFTEN_PLATFORM_MACOSX) +#include <Swiften/Network/MacOSXProxyProvider.h> +namespace Swift { + typedef MacOSXProxyProvider PlatformProxyProvider; +} +#elif defined(SWIFTEN_PLATFORM_WIN32) +#include <Swiften/Network/WindowsProxyProvider.h> +namespace Swift { + typedef WindowsProxyProvider PlatformProxyProvider; +} +#else +#include <Swiften/Network/UnixProxyProvider.h> +namespace Swift { + typedef UnixProxyProvider PlatformProxyProvider; +} +#endif diff --git a/Swiften/Network/ProxyProvider.cpp b/Swiften/Network/ProxyProvider.cpp new file mode 100644 index 0000000..fe235b1 --- /dev/null +++ b/Swiften/Network/ProxyProvider.cpp @@ -0,0 +1,19 @@ +/* + * Copyright (c) 2010-2011 Thilo Cestonaro + * Licensed under the simplified BSD license. + * See Documentation/Licenses/BSD-simplified.txt for more information. + */ + +#include "ProxyProvider.h" + +namespace Swift { + +ProxyProvider::ProxyProvider() +{ +} + +ProxyProvider::~ProxyProvider() +{ +} + +} diff --git a/Swiften/Network/ProxyProvider.h b/Swiften/Network/ProxyProvider.h new file mode 100644 index 0000000..0b63d51 --- /dev/null +++ b/Swiften/Network/ProxyProvider.h @@ -0,0 +1,23 @@ +/* + * Copyright (c) 2010-2011 Thilo Cestonaro + * Licensed under the simplified BSD license. + * See Documentation/Licenses/BSD-simplified.txt for more information. + */ + +#pragma once +#include <map> + +#include <Swiften/Base/Log.h> +#include <Swiften/Network/HostAddressPort.h> +#include <Swiften/Base/String.h> + +namespace Swift { + class ProxyProvider { + public: + ProxyProvider(); + virtual ~ProxyProvider(); + virtual HostAddressPort getHTTPConnectProxy() const = 0; + virtual HostAddressPort getSOCKS5Proxy() const = 0; + }; +} + diff --git a/Swiften/Network/SConscript b/Swiften/Network/SConscript index fa186fa..183d09c 100644 --- a/Swiften/Network/SConscript +++ b/Swiften/Network/SConscript @@ -6,13 +6,21 @@ if myenv.get("HAVE_CARES", False) : myenv.MergeFlags(myenv.get("CARES_FLAGS", {})) sourceList = [ + "HTTPConnectProxiedConnection.cpp", + "HTTPConnectProxiedConnectionFactory.cpp", + "SOCKS5ProxiedConnection.cpp", + "SOCKS5ProxiedConnectionFactory.cpp", "BoostConnection.cpp", "BoostConnectionFactory.cpp", "BoostConnectionServer.cpp", "BoostIOServiceThread.cpp", "ConnectionFactory.cpp", "ConnectionServer.cpp", + "DummyConnection.cpp", + "FakeConnection.cpp", + "ChainedConnector.cpp", "Connector.cpp", + "Connection.cpp", "TimerFactory.cpp", "DummyTimerFactory.cpp", "BoostTimerFactory.cpp", @@ -24,13 +32,30 @@ sourceList = [ "PlatformDomainNameAddressQuery.cpp", "StaticDomainNameResolver.cpp", "HostAddress.cpp", + "HostAddressPort.cpp", "NetworkFactories.cpp", "BoostNetworkFactories.cpp", "Timer.cpp", - "BoostTimer.cpp"] + "BoostTimer.cpp", + "ProxyProvider.cpp", + "NullProxyProvider.cpp" + ] + if myenv.get("HAVE_CARES", False) : sourceList.append("CAresDomainNameResolver.cpp") +if myenv["PLATFORM"] == "darwin" : + myenv.Append(FRAMEWORKS = ["CoreServices", "SystemConfiguration"]) + sourceList += [ "MacOSXProxyProvider.cpp" ] +elif myenv["PLATFORM"] == "win32" : + sourceList += [ "WindowsProxyProvider.cpp" ] +else : + sourceList += [ "UnixProxyProvider.cpp" ] + sourceList += [ "EnvironmentProxyProvider.cpp" ] + if myenv.get("HAVE_GCONF", 0) : + myenv.Append(CPPDEFINES = "HAVE_GCONF") + myenv.MergeFlags(myenv["GCONF_FLAGS"]) + sourceList += [ "GConfProxyProvider.cpp" ] objects = myenv.SwiftenObject(sourceList) swiften_env.Append(SWIFTEN_OBJECTS = [objects]) diff --git a/Swiften/Network/SOCKS5ProxiedConnection.cpp b/Swiften/Network/SOCKS5ProxiedConnection.cpp new file mode 100644 index 0000000..52e56a9 --- /dev/null +++ b/Swiften/Network/SOCKS5ProxiedConnection.cpp @@ -0,0 +1,174 @@ +/* + * Copyright (c) 2010-2011 Thilo Cestonaro + * Licensed under the simplified BSD license. + * See Documentation/Licenses/BSD-simplified.txt for more information. + */ + +#include <Swiften/Network/SOCKS5ProxiedConnection.h> + +#include <iostream> +#include <boost/bind.hpp> +#include <boost/thread.hpp> + +#include <Swiften/Network/ConnectionFactory.h> +#include <Swiften/Base/Log.h> +#include <Swiften/Base/String.h> +#include <Swiften/Base/ByteArray.h> +#include <Swiften/Network/HostAddressPort.h> + +using namespace Swift; + +SOCKS5ProxiedConnection::SOCKS5ProxiedConnection(ConnectionFactory* connectionFactory, const HostAddressPort& proxy) : connectionFactory_(connectionFactory), proxy_(proxy), server_(HostAddressPort(HostAddress("0.0.0.0"), 0)) { + connected_ = false; +} + +SOCKS5ProxiedConnection::~SOCKS5ProxiedConnection() { + if (connection_) { + connection_->onDataRead.disconnect(boost::bind(&SOCKS5ProxiedConnection::handleDataRead, shared_from_this(), _1)); + connection_->onDisconnected.disconnect(boost::bind(&SOCKS5ProxiedConnection::handleDisconnected, shared_from_this(), _1)); + } + + if (connected_) { + std::cerr << "Warning: Connection was still established." << std::endl; + } +} + +void SOCKS5ProxiedConnection::connect(const HostAddressPort& server) { + server_ = server; + connection_ = connectionFactory_->createConnection(); + connection_->onConnectFinished.connect(boost::bind(&SOCKS5ProxiedConnection::handleConnectionConnectFinished, shared_from_this(), _1)); + connection_->onDataRead.connect(boost::bind(&SOCKS5ProxiedConnection::handleDataRead, shared_from_this(), _1)); + connection_->onDisconnected.connect(boost::bind(&SOCKS5ProxiedConnection::handleDisconnected, shared_from_this(), _1)); + SWIFT_LOG(debug) << "Trying to connect via proxy " << proxy_.getAddress().toString() << ":" << proxy_.getPort() << std::endl; + SWIFT_LOG(debug) << "to server " << server.getAddress().toString() << ":" << server.getPort() << std::endl; + connection_->connect(proxy_); +} + +void SOCKS5ProxiedConnection::listen() { + assert(false); + connection_->listen(); +} + +void SOCKS5ProxiedConnection::disconnect() { + connected_ = false; + if (connection_) { + connection_->disconnect(); + } +} + +void SOCKS5ProxiedConnection::handleDisconnected(const boost::optional<Error>& error) { + onDisconnected(error); +} + +void SOCKS5ProxiedConnection::write(const ByteArray& data) { + if (connection_) { + connection_->write(data); + } +} + +void SOCKS5ProxiedConnection::handleConnectionConnectFinished(bool error) { + connection_->onConnectFinished.disconnect(boost::bind(&SOCKS5ProxiedConnection::handleConnectionConnectFinished, shared_from_this(), _1)); + if (!error) { + SWIFT_LOG(debug) << "Connection to proxy established, now connect to the server via it." << std::endl; + + proxyState_ = ProxyAuthenticating; + ByteArray socksConnect; + socksConnect += 0x05; // VER = SOCKS5 = 0x05 + socksConnect += 0x01; // Number of authentication methods after this byte. + socksConnect += 0x00; // 0x00 == no authentication + // buffer.push_back(0x01); // 0x01 == GSSAPI + // buffer.push_back(0x02); // 0x02 == Username/Password + // rest see RFC 1928 (http://tools.ietf.org/html/rfc1928) + connection_->write(socksConnect); + } + else { + onConnectFinished(true); + } +} + +void SOCKS5ProxiedConnection::handleDataRead(const ByteArray& data) { + ByteArray socksConnect; + boost::asio::ip::address rawAddress = server_.getAddress().getRawAddress(); + assert(rawAddress.is_v4() || rawAddress.is_v6()); + if (!connected_) { + if (proxyState_ == ProxyAuthenticating) { + SWIFT_LOG(debug) << "ProxyAuthenticating response received, reply with the connect BYTEs" << std::endl; + unsigned char choosenMethod = static_cast<unsigned char> (data[1]); + if (data[0] == 0x05 && choosenMethod != 0xFF) { + switch(choosenMethod) { // use the correct Method + case 0x00: + try { + proxyState_ = ProxyConnecting; + socksConnect += 0x05; // VER = SOCKS5 = 0x05 + socksConnect += 0x01; // Construct a TCP connection. (CMD) + socksConnect += 0x00; // reserved. + socksConnect += rawAddress.is_v4() ? 0x01 : 0x04; // IPv4 == 0x01, Hostname == 0x02, IPv6 == 0x04. (ATYP) + size_t size = rawAddress.is_v4() ? rawAddress.to_v4().to_bytes().size() : rawAddress.to_v6().to_bytes().size(); + for (size_t s = 0; s < size; s++) { + unsigned char uc; + if(rawAddress.is_v4()) { + uc = rawAddress.to_v4().to_bytes()[s]; // the address. + } + else { + uc = rawAddress.to_v6().to_bytes()[s]; // the address. + } + socksConnect += static_cast<char> (uc); + + } + socksConnect += static_cast<unsigned char> ((server_.getPort() >> 8) & 0xFF); // highbyte of the port. + socksConnect += static_cast<unsigned char> (server_.getPort() & 0xFF); // lowbyte of the port. + connection_->write(socksConnect); + return; + } + catch(...) { + std::cerr << "exception caught" << std::endl; + } + connection_->write(socksConnect); + break; + default: + onConnectFinished(true); + break; + } + return; + } + } + else if (proxyState_ == ProxyConnecting) { + SWIFT_LOG(debug) << "Connect response received, check if successfully." << std::endl; + SWIFT_LOG(debug) << "Errorbyte: 0x" << std::hex << static_cast<int> (data[1]) << std::dec << std::endl; + /* + + data.at(1) can be one of the following: + 0x00 succeeded + 0x01 general SOCKS server failure + 0x02 connection not allowed by ruleset + 0x03 Network unreachable + 0x04 Host unreachable + 0x05 Connection refused + 0x06 TTL expired + 0x07 Command not supported (CMD) + 0x08 Address type not supported (ATYP) + 0x09 bis 0xFF unassigned + */ + if (data[0] == 0x05 && data[1] == 0x0) { + SWIFT_LOG(debug) << "Successfully connected the server via the proxy." << std::endl; + connected_ = true; + onConnectFinished(false); + return; + } + else { + std::cerr << "SOCKS Proxy returned an error: " << std::hex << data[1] << std::endl; + } + return; + } + } + else { + onDataRead(data); + return; + } + disconnect(); + onConnectFinished(true); +} + +HostAddressPort SOCKS5ProxiedConnection::getLocalAddress() const { + return connection_->getLocalAddress(); +} diff --git a/Swiften/Network/SOCKS5ProxiedConnection.h b/Swiften/Network/SOCKS5ProxiedConnection.h new file mode 100644 index 0000000..e594e0f --- /dev/null +++ b/Swiften/Network/SOCKS5ProxiedConnection.h @@ -0,0 +1,59 @@ +/* + * Copyright (c) 2010-2011 Thilo Cestonaro + * Licensed under the simplified BSD license. + * See Documentation/Licenses/BSD-simplified.txt for more information. + */ + +#pragma once + +#include <boost/enable_shared_from_this.hpp> + +#include <Swiften/Network/Connection.h> +#include <Swiften/Network/HostAddressPort.h> + +namespace boost { + class thread; + namespace system { + class error_code; + } +} + +namespace Swift { + class ConnectionFactory; + + class SOCKS5ProxiedConnection : public Connection, public boost::enable_shared_from_this<SOCKS5ProxiedConnection> { + public: + typedef boost::shared_ptr<SOCKS5ProxiedConnection> ref; + + ~SOCKS5ProxiedConnection(); + + static ref create(ConnectionFactory* connectionFactory, const HostAddressPort& proxy) { + return ref(new SOCKS5ProxiedConnection(connectionFactory, proxy)); + } + + virtual void listen(); + virtual void connect(const HostAddressPort& address); + virtual void disconnect(); + virtual void write(const ByteArray& data); + + virtual HostAddressPort getLocalAddress() const; + + private: + SOCKS5ProxiedConnection(ConnectionFactory* connectionFactory, const HostAddressPort& proxy); + + void handleConnectionConnectFinished(bool error); + void handleDataRead(const ByteArray& data); + void handleDisconnected(const boost::optional<Error>& error); + + private: + enum { + ProxyAuthenticating = 0, + ProxyConnecting, + } proxyState_; + bool connected_; + ConnectionFactory* connectionFactory_; + HostAddressPort proxy_; + HostAddressPort server_; + boost::shared_ptr<Connection> connection_; + }; +} diff --git a/Swiften/Network/SOCKS5ProxiedConnectionFactory.cpp b/Swiften/Network/SOCKS5ProxiedConnectionFactory.cpp new file mode 100644 index 0000000..272ade9 --- /dev/null +++ b/Swiften/Network/SOCKS5ProxiedConnectionFactory.cpp @@ -0,0 +1,20 @@ +/* + * Copyright (c) 2010-2011 Thilo Cestonaro + * Licensed under the simplified BSD license. + * See Documentation/Licenses/BSD-simplified.txt for more information. + */ + +#include <Swiften/Network/SOCKS5ProxiedConnectionFactory.h> + +#include <Swiften/Network/SOCKS5ProxiedConnection.h> + +namespace Swift { + +SOCKS5ProxiedConnectionFactory::SOCKS5ProxiedConnectionFactory(ConnectionFactory* connectionFactory, const HostAddressPort& proxy) : connectionFactory_(connectionFactory), proxy_(proxy) { +} + +boost::shared_ptr<Connection> SOCKS5ProxiedConnectionFactory::createConnection() { + return SOCKS5ProxiedConnection::create(connectionFactory_, proxy_); +} + +} diff --git a/Swiften/Network/SOCKS5ProxiedConnectionFactory.h b/Swiften/Network/SOCKS5ProxiedConnectionFactory.h new file mode 100644 index 0000000..f36d42a --- /dev/null +++ b/Swiften/Network/SOCKS5ProxiedConnectionFactory.h @@ -0,0 +1,23 @@ +/* + * Copyright (c) 2010-2011 Thilo Cestonaro + * Licensed under the simplified BSD license. + * See Documentation/Licenses/BSD-simplified.txt for more information. + */ + +#pragma once + +#include <Swiften/Network/ConnectionFactory.h> +#include <Swiften/Network/HostAddressPort.h> + +namespace Swift { + class SOCKS5ProxiedConnectionFactory : public ConnectionFactory { + public: + SOCKS5ProxiedConnectionFactory(ConnectionFactory* connectionFactory, const HostAddressPort& proxy); + + virtual boost::shared_ptr<Connection> createConnection(); + + private: + ConnectionFactory* connectionFactory_; + HostAddressPort proxy_; + }; +} diff --git a/Swiften/Network/StaticDomainNameResolver.cpp b/Swiften/Network/StaticDomainNameResolver.cpp index a338272..76ab411 100644 --- a/Swiften/Network/StaticDomainNameResolver.cpp +++ b/Swiften/Network/StaticDomainNameResolver.cpp @@ -4,12 +4,12 @@ * See Documentation/Licenses/GPLv3.txt for more information. */ -#include "Swiften/Network/StaticDomainNameResolver.h" +#include <Swiften/Network/StaticDomainNameResolver.h> #include <boost/bind.hpp> #include <boost/lexical_cast.hpp> -#include "Swiften/Network/DomainNameResolveError.h" +#include <Swiften/Network/DomainNameResolveError.h> #include <string> using namespace Swift; diff --git a/Swiften/Network/StaticDomainNameResolver.h b/Swiften/Network/StaticDomainNameResolver.h index 2ef1295..a72db7c 100644 --- a/Swiften/Network/StaticDomainNameResolver.h +++ b/Swiften/Network/StaticDomainNameResolver.h @@ -9,12 +9,12 @@ #include <vector> #include <map> -#include "Swiften/Network/HostAddress.h" -#include "Swiften/Network/HostAddressPort.h" -#include "Swiften/Network/DomainNameResolver.h" -#include "Swiften/Network/DomainNameServiceQuery.h" -#include "Swiften/Network/DomainNameAddressQuery.h" -#include "Swiften/EventLoop/EventLoop.h" +#include <Swiften/Network/HostAddress.h> +#include <Swiften/Network/HostAddressPort.h> +#include <Swiften/Network/DomainNameResolver.h> +#include <Swiften/Network/DomainNameServiceQuery.h> +#include <Swiften/Network/DomainNameAddressQuery.h> +#include <Swiften/EventLoop/EventLoop.h> namespace Swift { diff --git a/Swiften/Network/Timer.cpp b/Swiften/Network/Timer.cpp index daa4490..3efbd3b 100644 --- a/Swiften/Network/Timer.cpp +++ b/Swiften/Network/Timer.cpp @@ -4,7 +4,7 @@ * See Documentation/Licenses/GPLv3.txt for more information. */ -#include "Swiften/Network/Timer.h" +#include <Swiften/Network/Timer.h> namespace Swift { diff --git a/Swiften/Network/Timer.h b/Swiften/Network/Timer.h index d44a00d..b7578f2 100644 --- a/Swiften/Network/Timer.h +++ b/Swiften/Network/Timer.h @@ -6,7 +6,7 @@ #pragma once -#include "Swiften/Base/boost_bsignals.h" +#include <Swiften/Base/boost_bsignals.h> namespace Swift { /** diff --git a/Swiften/Network/TimerFactory.cpp b/Swiften/Network/TimerFactory.cpp index 502f669..3fb807c 100644 --- a/Swiften/Network/TimerFactory.cpp +++ b/Swiften/Network/TimerFactory.cpp @@ -4,7 +4,7 @@ * See Documentation/Licenses/GPLv3.txt for more information. */ -#include "Swiften/Network/TimerFactory.h" +#include <Swiften/Network/TimerFactory.h> namespace Swift { diff --git a/Swiften/Network/TimerFactory.h b/Swiften/Network/TimerFactory.h index 44c87b6..99903c3 100644 --- a/Swiften/Network/TimerFactory.h +++ b/Swiften/Network/TimerFactory.h @@ -8,7 +8,7 @@ #include <boost/shared_ptr.hpp> -#include "Swiften/Network/Timer.h" +#include <Swiften/Network/Timer.h> namespace Swift { class TimerFactory { diff --git a/Swiften/Network/UnitTest/ChainedConnectorTest.cpp b/Swiften/Network/UnitTest/ChainedConnectorTest.cpp new file mode 100644 index 0000000..9c4c99d --- /dev/null +++ b/Swiften/Network/UnitTest/ChainedConnectorTest.cpp @@ -0,0 +1,161 @@ +/* + * Copyright (c) 2010 Remko Tronçon + * Licensed under the GNU General Public License v3. + * See Documentation/Licenses/GPLv3.txt for more information. + */ + +#include <cppunit/extensions/HelperMacros.h> +#include <cppunit/extensions/TestFactoryRegistry.h> + +#include <boost/bind.hpp> +#include <boost/smart_ptr/make_shared.hpp> + +#include <Swiften/Network/ChainedConnector.h> +#include <Swiften/Network/Connection.h> +#include <Swiften/Network/ConnectionFactory.h> +#include <Swiften/Network/HostAddressPort.h> +#include <Swiften/Network/StaticDomainNameResolver.h> +#include <Swiften/Network/DummyTimerFactory.h> +#include <Swiften/EventLoop/DummyEventLoop.h> + +using namespace Swift; + +class ChainedConnectorTest : public CppUnit::TestFixture { + CPPUNIT_TEST_SUITE(ChainedConnectorTest); + CPPUNIT_TEST(testConnect_FirstConnectorSucceeds); + CPPUNIT_TEST(testConnect_SecondConnectorSucceeds); + CPPUNIT_TEST(testConnect_NoConnectorSucceeds); + CPPUNIT_TEST(testStop); + CPPUNIT_TEST_SUITE_END(); + + public: + void setUp() { + host = HostAddressPort(HostAddress("1.1.1.1"), 1234); + eventLoop = new DummyEventLoop(); + resolver = new StaticDomainNameResolver(eventLoop); + resolver->addXMPPClientService("foo.com", host); + connectionFactory1 = new MockConnectionFactory(eventLoop, 1); + connectionFactory2 = new MockConnectionFactory(eventLoop, 2); + timerFactory = new DummyTimerFactory(); + } + + void tearDown() { + delete timerFactory; + delete connectionFactory2; + delete connectionFactory1; + delete resolver; + delete eventLoop; + } + + void testConnect_FirstConnectorSucceeds() { + boost::shared_ptr<ChainedConnector> testling(createConnector()); + connectionFactory1->connects = true; + connectionFactory2->connects = false; + + testling->start(); + eventLoop->processEvents(); + + CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(connections.size())); + CPPUNIT_ASSERT(connections[0]); + CPPUNIT_ASSERT_EQUAL(1, boost::dynamic_pointer_cast<MockConnection>(connections[0])->id); + } + + void testConnect_SecondConnectorSucceeds() { + boost::shared_ptr<ChainedConnector> testling(createConnector()); + connectionFactory1->connects = false; + connectionFactory2->connects = true; + + testling->start(); + eventLoop->processEvents(); + + CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(connections.size())); + CPPUNIT_ASSERT(connections[0]); + CPPUNIT_ASSERT_EQUAL(2, boost::dynamic_pointer_cast<MockConnection>(connections[0])->id); + } + + void testConnect_NoConnectorSucceeds() { + boost::shared_ptr<ChainedConnector> testling(createConnector()); + connectionFactory1->connects = false; + connectionFactory2->connects = false; + + testling->start(); + eventLoop->processEvents(); + + CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(connections.size())); + CPPUNIT_ASSERT(!connections[0]); + } + + void testStop() { + boost::shared_ptr<ChainedConnector> testling(createConnector()); + connectionFactory1->connects = true; + connectionFactory2->connects = false; + + testling->start(); + testling->stop(); + eventLoop->processEvents(); + + CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(connections.size())); + CPPUNIT_ASSERT(!connections[0]); + } + + private: + boost::shared_ptr<ChainedConnector> createConnector() { + std::vector<ConnectionFactory*> factories; + factories.push_back(connectionFactory1); + factories.push_back(connectionFactory2); + boost::shared_ptr<ChainedConnector> connector = boost::make_shared<ChainedConnector>("foo.com", resolver, factories, timerFactory); + connector->onConnectFinished.connect(boost::bind(&ChainedConnectorTest::handleConnectorFinished, this, _1)); + return connector; + } + + void handleConnectorFinished(boost::shared_ptr<Connection> connection) { + boost::shared_ptr<MockConnection> c(boost::dynamic_pointer_cast<MockConnection>(connection)); + if (connection) { + assert(c); + } + connections.push_back(c); + } + + struct MockConnection : public Connection { + public: + MockConnection(bool connects, int id, EventLoop* eventLoop) : connects(connects), id(id), eventLoop(eventLoop) { + } + + void listen() { assert(false); } + void connect(const HostAddressPort&) { + eventLoop->postEvent(boost::bind(boost::ref(onConnectFinished), !connects)); + } + + HostAddressPort getLocalAddress() const { return HostAddressPort(); } + void disconnect() { assert(false); } + void write(const ByteArray&) { assert(false); } + + bool connects; + int id; + EventLoop* eventLoop; + }; + + struct MockConnectionFactory : public ConnectionFactory { + MockConnectionFactory(EventLoop* eventLoop, int id) : eventLoop(eventLoop), connects(true), id(id) { + } + + boost::shared_ptr<Connection> createConnection() { + return boost::make_shared<MockConnection>(connects, id, eventLoop); + } + + EventLoop* eventLoop; + bool connects; + int id; + }; + + private: + HostAddressPort host; + DummyEventLoop* eventLoop; + StaticDomainNameResolver* resolver; + MockConnectionFactory* connectionFactory1; + MockConnectionFactory* connectionFactory2; + DummyTimerFactory* timerFactory; + std::vector< boost::shared_ptr<MockConnection> > connections; +}; + +CPPUNIT_TEST_SUITE_REGISTRATION(ChainedConnectorTest); diff --git a/Swiften/Network/UnitTest/ConnectorTest.cpp b/Swiften/Network/UnitTest/ConnectorTest.cpp index c8aa9a9..6151b5c 100644 --- a/Swiften/Network/UnitTest/ConnectorTest.cpp +++ b/Swiften/Network/UnitTest/ConnectorTest.cpp @@ -10,13 +10,13 @@ #include <boost/optional.hpp> #include <boost/bind.hpp> -#include "Swiften/Network/Connector.h" -#include "Swiften/Network/Connection.h" -#include "Swiften/Network/ConnectionFactory.h" -#include "Swiften/Network/HostAddressPort.h" -#include "Swiften/Network/StaticDomainNameResolver.h" -#include "Swiften/Network/DummyTimerFactory.h" -#include "Swiften/EventLoop/DummyEventLoop.h" +#include <Swiften/Network/Connector.h> +#include <Swiften/Network/Connection.h> +#include <Swiften/Network/ConnectionFactory.h> +#include <Swiften/Network/HostAddressPort.h> +#include <Swiften/Network/StaticDomainNameResolver.h> +#include <Swiften/Network/DummyTimerFactory.h> +#include <Swiften/EventLoop/DummyEventLoop.h> using namespace Swift; diff --git a/Swiften/Network/UnitTest/HTTPConnectProxiedConnectionTest.cpp b/Swiften/Network/UnitTest/HTTPConnectProxiedConnectionTest.cpp new file mode 100644 index 0000000..6c4c89c --- /dev/null +++ b/Swiften/Network/UnitTest/HTTPConnectProxiedConnectionTest.cpp @@ -0,0 +1,244 @@ +/* + * Copyright (c) 2010 Remko Tronçon + * Licensed under the GNU General Public License v3. + * See Documentation/Licenses/GPLv3.txt for more information. + */ + +#include <cppunit/extensions/HelperMacros.h> +#include <cppunit/extensions/TestFactoryRegistry.h> + +#include <boost/optional.hpp> +#include <boost/bind.hpp> +#include <boost/smart_ptr/make_shared.hpp> +#include <boost/shared_ptr.hpp> + +#include <Swiften/Network/Connection.h> +#include <Swiften/Network/ConnectionFactory.h> +#include <Swiften/Network/HTTPConnectProxiedConnection.h> +#include <Swiften/Network/HostAddressPort.h> +#include <Swiften/EventLoop/DummyEventLoop.h> + +using namespace Swift; + +class HTTPConnectProxiedConnectionTest : public CppUnit::TestFixture { + CPPUNIT_TEST_SUITE(HTTPConnectProxiedConnectionTest); + CPPUNIT_TEST(testConnect_CreatesConnectionToProxy); + CPPUNIT_TEST(testConnect_SendsConnectRequest); + CPPUNIT_TEST(testConnect_ReceiveConnectResponse); + CPPUNIT_TEST(testConnect_ReceiveMalformedConnectResponse); + CPPUNIT_TEST(testConnect_ReceiveErrorConnectResponse); + CPPUNIT_TEST(testConnect_ReceiveDataAfterConnect); + CPPUNIT_TEST(testWrite_AfterConnect); + CPPUNIT_TEST(testDisconnect_AfterConnectRequest); + CPPUNIT_TEST(testDisconnect_AfterConnect); + CPPUNIT_TEST_SUITE_END(); + + public: + void setUp() { + proxyHost = HostAddressPort(HostAddress("1.1.1.1"), 1234); + host = HostAddressPort(HostAddress("2.2.2.2"), 2345); + eventLoop = new DummyEventLoop(); + connectionFactory = new MockConnectionFactory(eventLoop); + connectFinished = false; + disconnected = false; + } + + void tearDown() { + delete connectionFactory; + delete eventLoop; + } + + void testConnect_CreatesConnectionToProxy() { + HTTPConnectProxiedConnection::ref testling(createTestling()); + + testling->connect(host); + eventLoop->processEvents(); + + CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(connectionFactory->connections.size())); + CPPUNIT_ASSERT(connectionFactory->connections[0]->hostAddressPort); + CPPUNIT_ASSERT(proxyHost == *connectionFactory->connections[0]->hostAddressPort); + CPPUNIT_ASSERT(!connectFinished); + } + + void testConnect_SendsConnectRequest() { + HTTPConnectProxiedConnection::ref testling(createTestling()); + + testling->connect(HostAddressPort(HostAddress("2.2.2.2"), 2345)); + eventLoop->processEvents(); + + CPPUNIT_ASSERT_EQUAL(ByteArray("CONNECT 2.2.2.2:2345 HTTP/1.1\r\n\r\n"), connectionFactory->connections[0]->dataWritten); + } + + void testConnect_ReceiveConnectResponse() { + HTTPConnectProxiedConnection::ref testling(createTestling()); + testling->connect(HostAddressPort(HostAddress("2.2.2.2"), 2345)); + eventLoop->processEvents(); + + connectionFactory->connections[0]->onDataRead(ByteArray("HTTP/1.0 200 Connection established\r\n\r\n")); + eventLoop->processEvents(); + + CPPUNIT_ASSERT(connectFinished); + CPPUNIT_ASSERT(!connectFinishedWithError); + CPPUNIT_ASSERT(dataRead.isEmpty()); + } + + void testConnect_ReceiveMalformedConnectResponse() { + HTTPConnectProxiedConnection::ref testling(createTestling()); + testling->connect(HostAddressPort(HostAddress("2.2.2.2"), 2345)); + eventLoop->processEvents(); + + connectionFactory->connections[0]->onDataRead(ByteArray("FLOOP")); + eventLoop->processEvents(); + + CPPUNIT_ASSERT(connectFinished); + CPPUNIT_ASSERT(connectFinishedWithError); + CPPUNIT_ASSERT(connectionFactory->connections[0]->disconnected); + } + + void testConnect_ReceiveErrorConnectResponse() { + HTTPConnectProxiedConnection::ref testling(createTestling()); + testling->connect(HostAddressPort(HostAddress("2.2.2.2"), 2345)); + eventLoop->processEvents(); + + connectionFactory->connections[0]->onDataRead(ByteArray("HTTP/1.0 401 Unauthorized\r\n\r\n")); + eventLoop->processEvents(); + + CPPUNIT_ASSERT(connectFinished); + CPPUNIT_ASSERT(connectFinishedWithError); + CPPUNIT_ASSERT(connectionFactory->connections[0]->disconnected); + } + + void testConnect_ReceiveDataAfterConnect() { + HTTPConnectProxiedConnection::ref testling(createTestling()); + testling->connect(HostAddressPort(HostAddress("2.2.2.2"), 2345)); + eventLoop->processEvents(); + connectionFactory->connections[0]->onDataRead(ByteArray("HTTP/1.0 200 Connection established\r\n\r\n")); + eventLoop->processEvents(); + + connectionFactory->connections[0]->onDataRead(ByteArray("abcdef")); + + CPPUNIT_ASSERT_EQUAL(ByteArray("abcdef"), dataRead); + } + + void testWrite_AfterConnect() { + HTTPConnectProxiedConnection::ref testling(createTestling()); + testling->connect(HostAddressPort(HostAddress("2.2.2.2"), 2345)); + eventLoop->processEvents(); + connectionFactory->connections[0]->onDataRead(ByteArray("HTTP/1.0 200 Connection established\r\n\r\n")); + eventLoop->processEvents(); + connectionFactory->connections[0]->dataWritten.clear(); + + testling->write(ByteArray("abcdef")); + + CPPUNIT_ASSERT_EQUAL(ByteArray("abcdef"), connectionFactory->connections[0]->dataWritten); + } + + void testDisconnect_AfterConnectRequest() { + HTTPConnectProxiedConnection::ref testling(createTestling()); + testling->connect(HostAddressPort(HostAddress("2.2.2.2"), 2345)); + eventLoop->processEvents(); + + testling->disconnect(); + + CPPUNIT_ASSERT(connectionFactory->connections[0]->disconnected); + CPPUNIT_ASSERT(disconnected); + CPPUNIT_ASSERT(!disconnectedError); + } + + void testDisconnect_AfterConnect() { + HTTPConnectProxiedConnection::ref testling(createTestling()); + testling->connect(HostAddressPort(HostAddress("2.2.2.2"), 2345)); + eventLoop->processEvents(); + connectionFactory->connections[0]->onDataRead(ByteArray("HTTP/1.0 200 Connection established\r\n\r\n")); + eventLoop->processEvents(); + + testling->disconnect(); + + CPPUNIT_ASSERT(connectionFactory->connections[0]->disconnected); + CPPUNIT_ASSERT(disconnected); + CPPUNIT_ASSERT(!disconnectedError); + } + + private: + HTTPConnectProxiedConnection::ref createTestling() { + boost::shared_ptr<HTTPConnectProxiedConnection> c = HTTPConnectProxiedConnection::create(connectionFactory, proxyHost); + c->onConnectFinished.connect(boost::bind(&HTTPConnectProxiedConnectionTest::handleConnectFinished, this, _1)); + c->onDisconnected.connect(boost::bind(&HTTPConnectProxiedConnectionTest::handleDisconnected, this, _1)); + c->onDataRead.connect(boost::bind(&HTTPConnectProxiedConnectionTest::handleDataRead, this, _1)); + return c; + } + + void handleConnectFinished(bool error) { + connectFinished = true; + connectFinishedWithError = error; + } + + void handleDisconnected(const boost::optional<Connection::Error>& e) { + disconnected = true; + disconnectedError = e; + } + + void handleDataRead(const ByteArray& d) { + dataRead += d; + } + + struct MockConnection : public Connection { + public: + MockConnection(const std::vector<HostAddressPort>& failingPorts, EventLoop* eventLoop) : eventLoop(eventLoop), failingPorts(failingPorts), disconnected(false) { + } + + void listen() { assert(false); } + + void connect(const HostAddressPort& address) { + hostAddressPort = address; + bool fail = std::find(failingPorts.begin(), failingPorts.end(), address) != failingPorts.end(); + eventLoop->postEvent(boost::bind(boost::ref(onConnectFinished), fail)); + } + + HostAddressPort getLocalAddress() const { return HostAddressPort(); } + + void disconnect() { + disconnected = true; + onDisconnected(boost::optional<Connection::Error>()); + } + + void write(const ByteArray& d) { + dataWritten += d; + } + + EventLoop* eventLoop; + boost::optional<HostAddressPort> hostAddressPort; + std::vector<HostAddressPort> failingPorts; + ByteArray dataWritten; + bool disconnected; + }; + + struct MockConnectionFactory : public ConnectionFactory { + MockConnectionFactory(EventLoop* eventLoop) : eventLoop(eventLoop) { + } + + boost::shared_ptr<Connection> createConnection() { + boost::shared_ptr<MockConnection> connection = boost::make_shared<MockConnection>(failingPorts, eventLoop); + connections.push_back(connection); + return connection; + } + + EventLoop* eventLoop; + std::vector< boost::shared_ptr<MockConnection> > connections; + std::vector<HostAddressPort> failingPorts; + }; + + private: + HostAddressPort proxyHost; + HostAddressPort host; + DummyEventLoop* eventLoop; + MockConnectionFactory* connectionFactory; + std::vector< boost::shared_ptr<MockConnection> > connections; + bool connectFinished; + bool connectFinishedWithError; + bool disconnected; + boost::optional<Connection::Error> disconnectedError; + ByteArray dataRead; +}; + +CPPUNIT_TEST_SUITE_REGISTRATION(HTTPConnectProxiedConnectionTest); diff --git a/Swiften/Network/UnitTest/HostAddressTest.cpp b/Swiften/Network/UnitTest/HostAddressTest.cpp index 7fb33ca..b2511a8 100644 --- a/Swiften/Network/UnitTest/HostAddressTest.cpp +++ b/Swiften/Network/UnitTest/HostAddressTest.cpp @@ -7,7 +7,7 @@ #include <cppunit/extensions/HelperMacros.h> #include <cppunit/extensions/TestFactoryRegistry.h> -#include "Swiften/Network/HostAddress.h" +#include <Swiften/Network/HostAddress.h> #include <string> using namespace Swift; diff --git a/Swiften/Network/UnixProxyProvider.cpp b/Swiften/Network/UnixProxyProvider.cpp new file mode 100644 index 0000000..04c95e4 --- /dev/null +++ b/Swiften/Network/UnixProxyProvider.cpp @@ -0,0 +1,55 @@ +/* + * Copyright (c) 2010-2011 Thilo Cestonaro + * Licensed under the simplified BSD license. + * See Documentation/Licenses/BSD-simplified.txt for more information. + */ + +#include <stdio.h> +#include <stdlib.h> +#include <iostream> + +#include <Swiften/Base/foreach.h> +#include <Swiften/Network/UnixProxyProvider.h> + +namespace Swift { + +UnixProxyProvider::UnixProxyProvider() : +#if defined(HAVE_GCONF) + gconfProxyProvider(), +#endif + environmentProxyProvider() +{ +} + +HostAddressPort UnixProxyProvider::getSOCKS5Proxy() const { + HostAddressPort proxy; +#if defined(HAVE_GCONF) + proxy = gconfProxyProvider.getSOCKS5Proxy(); + if(proxy.isValid()) { + return proxy; + } +#endif + proxy = environmentProxyProvider.getSOCKS5Proxy(); + if(proxy.isValid()) { + return proxy; + } + return HostAddressPort(HostAddress(), 0); +} + +HostAddressPort UnixProxyProvider::getHTTPConnectProxy() const { + HostAddressPort proxy; +#if defined(HAVE_GCONF) + proxy = gconfProxyProvider.getHTTPConnectProxy(); + if(proxy.isValid()) { + return proxy; + } +#endif + proxy = environmentProxyProvider.getHTTPConnectProxy(); + if(proxy.isValid()) { + return proxy; + } + return HostAddressPort(HostAddress(), 0); +} + + +} diff --git a/Swiften/Network/UnixProxyProvider.h b/Swiften/Network/UnixProxyProvider.h new file mode 100644 index 0000000..8657a95 --- /dev/null +++ b/Swiften/Network/UnixProxyProvider.h @@ -0,0 +1,25 @@ +/* + * Copyright (c) 2010-2011 Thilo Cestonaro + * Licensed under the simplified BSD license. + * See Documentation/Licenses/BSD-simplified.txt for more information. + */ + +#pragma once +#if defined(HAVE_GCONF) +# include "Swiften/Network/GConfProxyProvider.h" +#endif +#include <Swiften/Network/EnvironmentProxyProvider.h> + +namespace Swift { + class UnixProxyProvider : public ProxyProvider { + public: + UnixProxyProvider(); + virtual HostAddressPort getHTTPConnectProxy() const; + virtual HostAddressPort getSOCKS5Proxy() const; + private: +#if defined(HAVE_GCONF) + GConfProxyProvider gconfProxyProvider; +#endif + EnvironmentProxyProvider environmentProxyProvider; + }; +} diff --git a/Swiften/Network/WindowsProxyProvider.cpp b/Swiften/Network/WindowsProxyProvider.cpp new file mode 100644 index 0000000..5fb3c3a --- /dev/null +++ b/Swiften/Network/WindowsProxyProvider.cpp @@ -0,0 +1,113 @@ +/* + * Copyright (c) 2010-2011 Thilo Cestonaro + * Licensed under the simplified BSD license. + * See Documentation/Licenses/BSD-simplified.txt for more information. + */ + +#include <stdio.h> +#include <stdlib.h> +#include <math.h> +#include <iostream> +#include <boost/lexical_cast.hpp> + +#include <Swiften/Base/log.h> +#include <Swiften/Base/foreach.h> +#include <Swiften/Network/WindowsProxyProvider.h> +#include <Swiften/Base/ByteArray.h> + +#include <windows.h> + +namespace Swift { + +WindowsProxyProvider::WindowsProxyProvider() +: ProxyProvider() +{ + HKEY hKey = (HKEY)INVALID_HANDLE_VALUE; + long result; + + result = RegOpenKeyEx(HKEY_CURRENT_USER, "Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings", 0, KEY_READ, &hKey); + if (result == ERROR_SUCCESS && hKey != INVALID_HANDLE_VALUE && proxyEnabled(hKey)) { + DWORD dataType = REG_SZ; + DWORD dataSize = 0; + ByteArray dataBuffer; + + result = RegQueryValueEx(hKey, "ProxyServer", NULL, &dataType, NULL, &dataSize); + if(result != ERROR_SUCCESS) { + return; + } + dataBuffer.resize(dataSize); + result = RegQueryValueEx(hKey, "ProxyServer", NULL, &dataType, reinterpret_cast<BYTE*>(dataBuffer.getData()), &dataSize); + if(result == ERROR_SUCCESS) { + std::vector<std::string> proxies = String::split(dataBuffer.toString(), ';'); + std::pair<std::string, std::string> protocolAndProxy; + foreach(std::string proxy, proxies) { + if(proxy.find('=') != std::string::npos) { + protocolAndProxy = String::getSplittedAtFirst(proxy, '='); + SWIFT_LOG(debug) << "Found proxy: " << protocolAndProxy.first << " => " << protocolAndProxy.second << std::endl; + if(protocolAndProxy.first.compare("socks") == 0) { + socksProxy = getAsHostAddressPort(protocolAndProxy.second); + } + else if (protocolAndProxy.first.compare("http") == 0) { + httpProxy = getAsHostAddressPort(protocolAndProxy.second); + } + } + } + } + } +} + +HostAddressPort WindowsProxyProvider::getHTTPConnectProxy() const { + return httpProxy; +} + +HostAddressPort WindowsProxyProvider::getSOCKS5Proxy() const { + return socksProxy; +} + +HostAddressPort WindowsProxyProvider::getAsHostAddressPort(std::string proxy) { + HostAddressPort ret(HostAddress(), 0); + + try { + std::pair<std::string, std::string> tmp; + int port = 0; + tmp = String::getSplittedAtFirst(proxy, ':'); + // .c_str() is needed as tmp.second can include a \0 char which will end in an exception of the lexical cast. + // with .c_str() the \0 will not be part of the string which is to be casted + port = boost::lexical_cast<int> (tmp.second.c_str()); + ret = HostAddressPort(HostAddress(tmp.first), port); + } + catch(...) { + std::cerr << "Exception occured while parsing windows proxy \"getHostAddressPort\"." << std::endl; + } + + return ret; +} + + +bool WindowsProxyProvider::proxyEnabled(HKEY hKey) const { + bool ret = false; + long result; + DWORD dataType = REG_DWORD; + DWORD dataSize = 0; + DWORD data = 0; + ByteArray dataBuffer; + + if(hKey == INVALID_HANDLE_VALUE) + return ret; + + result = RegQueryValueEx(hKey, "ProxyEnable", NULL, &dataType, NULL, &dataSize); + if(result != ERROR_SUCCESS) + return ret; + + dataBuffer.resize(dataSize); + result = RegQueryValueEx(hKey, "ProxyEnable", NULL, &dataType, reinterpret_cast<BYTE*>(dataBuffer.getData()), &dataSize); + if(result != ERROR_SUCCESS) + return ret; + + for(size_t t = 0; t < dataBuffer.getSize(); t++) { + data += static_cast<int> (dataBuffer[t]) * pow(256, static_cast<double>(t)); + } + return (data == 1); +} + +} diff --git a/Swiften/Network/WindowsProxyProvider.h b/Swiften/Network/WindowsProxyProvider.h new file mode 100644 index 0000000..c2d1f51 --- /dev/null +++ b/Swiften/Network/WindowsProxyProvider.h @@ -0,0 +1,22 @@ +/* + * Copyright (c) 2010-2011 Thilo Cestonaro + * Licensed under the simplified BSD license. + * See Documentation/Licenses/BSD-simplified.txt for more information. + */ + +#pragma once +#include <Swiften/Network/ProxyProvider.h> + +namespace Swift { + class WindowsProxyProvider : public ProxyProvider { + public: + WindowsProxyProvider(); + virtual HostAddressPort getHTTPConnectProxy() const; + virtual HostAddressPort getSOCKS5Proxy() const; + private: + HostAddressPort getAsHostAddressPort(std::string proxy); + bool proxyEnabled(HKEY hKey) const; + HostAddressPort socksProxy; + HostAddressPort httpProxy; + }; +} diff --git a/Swiften/Parser/Attribute.h b/Swiften/Parser/Attribute.h new file mode 100644 index 0000000..f1f9a83 --- /dev/null +++ b/Swiften/Parser/Attribute.h @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2010 Remko Tronçon + * Licensed under the GNU General Public License v3. + * See Documentation/Licenses/GPLv3.txt for more information. + */ + +#pragma once + +#include <string> + +namespace Swift { + class Attribute { + public: + Attribute(const std::string& name, const std::string& ns) : name(name), ns(ns) { + } + + const std::string& getName() const { + return name; + } + + const std::string& getNamespace() const { + return ns; + } + + bool operator==(const Attribute& o) const { + return o.name == name && o.ns == ns; + } + + private: + std::string name; + std::string ns; + }; +} diff --git a/Swiften/Parser/AttributeMap.cpp b/Swiften/Parser/AttributeMap.cpp new file mode 100644 index 0000000..1aeaf99 --- /dev/null +++ b/Swiften/Parser/AttributeMap.cpp @@ -0,0 +1,62 @@ +/* + * Copyright (c) 2011 Remko Tronçon + * Licensed under the GNU General Public License v3. + * See Documentation/Licenses/GPLv3.txt for more information. + */ + +#include <Swiften/Parser/AttributeMap.h> + +#include <algorithm> +#include <boost/optional.hpp> + +using namespace Swift; + +namespace { + struct AttributeIs { + AttributeIs(const Attribute& attribute) : attribute(attribute) { + } + + bool operator()(const AttributeMap::Entry& o) const { + return o.getAttribute() == attribute; + } + + Attribute attribute; + }; +} + +AttributeMap::AttributeMap() { +} + +std::string AttributeMap::getAttribute(const std::string& attribute, const std::string& ns) const { + AttributeValueMap::const_iterator i = std::find_if(attributes.begin(), attributes.end(), AttributeIs(Attribute(attribute, ns))); + if (i == attributes.end()) { + return ""; + } + else { + return i->getValue(); + } +} + +bool AttributeMap::getBoolAttribute(const std::string& attribute, bool defaultValue) const { + AttributeValueMap::const_iterator i = std::find_if(attributes.begin(), attributes.end(), AttributeIs(Attribute(attribute, ""))); + if (i == attributes.end()) { + return defaultValue; + } + else { + return i->getValue() == "true" || i->getValue() == "1"; + } +} + +boost::optional<std::string> AttributeMap::getAttributeValue(const std::string& attribute) const { + AttributeValueMap::const_iterator i = std::find_if(attributes.begin(), attributes.end(), AttributeIs(Attribute(attribute, ""))); + if (i == attributes.end()) { + return boost::optional<std::string>(); + } + else { + return i->getValue(); + } +} + +void AttributeMap::addAttribute(const std::string& name, const std::string& ns, const std::string& value) { + attributes.push_back(Entry(Attribute(name, ns), value)); +} diff --git a/Swiften/Parser/AttributeMap.h b/Swiften/Parser/AttributeMap.h index c8b287b..31df606 100644 --- a/Swiften/Parser/AttributeMap.h +++ b/Swiften/Parser/AttributeMap.h @@ -4,38 +4,50 @@ * See Documentation/Licenses/GPLv3.txt for more information. */ -#ifndef ATTRIBUTEMAP_H -#define ATTRIBUTEMAP_H +#pragma once +#include <vector> +#include <string> #include <map> +#include <boost/optional/optional_fwd.hpp> -#include <string> +#include <Swiften/Parser/Attribute.h> namespace Swift { - class AttributeMap : public std::map<std::string,std::string> { + class AttributeMap { public: - AttributeMap() {} - - std::string getAttribute(const std::string& attribute) const { - AttributeMap::const_iterator i = find(attribute); - if (i == end()) { - return ""; - } - else { - return i->second; - } - } + class Entry { + public: + Entry(const Attribute& attribute, const std::string& value) : attribute(attribute), value(value) { + } + + const Attribute& getAttribute() const { + return attribute; + } + + const std::string& getValue() const { + return value; + } + + private: + Attribute attribute; + std::string value; + }; - bool getBoolAttribute(const std::string& attribute, bool defaultValue = false) const { - AttributeMap::const_iterator i = find(attribute); - if (i == end()) { - return defaultValue; - } - else { - return i->second == "true" || i->second == "1"; - } + AttributeMap(); + + std::string getAttribute(const std::string& attribute, const std::string& ns = "") const; + bool getBoolAttribute(const std::string& attribute, bool defaultValue = false) const; + boost::optional<std::string> getAttributeValue(const std::string&) const; + + void addAttribute(const std::string& name, const std::string& ns, const std::string& value); + + const std::vector<Entry>& getEntries() const { + return attributes; } + + private: + typedef std::vector<Entry> AttributeValueMap; + AttributeValueMap attributes; }; } - -#endif diff --git a/Swiften/Parser/AuthChallengeParser.cpp b/Swiften/Parser/AuthChallengeParser.cpp index 1e5e0c4..7cb665a 100644 --- a/Swiften/Parser/AuthChallengeParser.cpp +++ b/Swiften/Parser/AuthChallengeParser.cpp @@ -4,8 +4,8 @@ * See Documentation/Licenses/GPLv3.txt for more information. */ -#include "Swiften/Parser/AuthChallengeParser.h" -#include "Swiften/StringCodecs/Base64.h" +#include <Swiften/Parser/AuthChallengeParser.h> +#include <Swiften/StringCodecs/Base64.h> namespace Swift { diff --git a/Swiften/Parser/AuthChallengeParser.h b/Swiften/Parser/AuthChallengeParser.h index 39f7c57..31b6d89 100644 --- a/Swiften/Parser/AuthChallengeParser.h +++ b/Swiften/Parser/AuthChallengeParser.h @@ -6,8 +6,8 @@ #pragma once -#include "Swiften/Parser/GenericElementParser.h" -#include "Swiften/Elements/AuthChallenge.h" +#include <Swiften/Parser/GenericElementParser.h> +#include <Swiften/Elements/AuthChallenge.h> #include <string> namespace Swift { diff --git a/Swiften/Parser/AuthFailureParser.h b/Swiften/Parser/AuthFailureParser.h index af54794..6f611f1 100644 --- a/Swiften/Parser/AuthFailureParser.h +++ b/Swiften/Parser/AuthFailureParser.h @@ -7,8 +7,8 @@ #ifndef SWIFTEN_AuthFailureParser_H #define SWIFTEN_AuthFailureParser_H -#include "Swiften/Parser/GenericElementParser.h" -#include "Swiften/Elements/AuthFailure.h" +#include <Swiften/Parser/GenericElementParser.h> +#include <Swiften/Elements/AuthFailure.h> namespace Swift { class AuthFailureParser : public GenericElementParser<AuthFailure> { diff --git a/Swiften/Parser/AuthRequestParser.cpp b/Swiften/Parser/AuthRequestParser.cpp index 38af047..d5d977f 100644 --- a/Swiften/Parser/AuthRequestParser.cpp +++ b/Swiften/Parser/AuthRequestParser.cpp @@ -4,8 +4,8 @@ * See Documentation/Licenses/GPLv3.txt for more information. */ -#include "Swiften/Parser/AuthRequestParser.h" -#include "Swiften/StringCodecs/Base64.h" +#include <Swiften/Parser/AuthRequestParser.h> +#include <Swiften/StringCodecs/Base64.h> namespace Swift { diff --git a/Swiften/Parser/AuthRequestParser.h b/Swiften/Parser/AuthRequestParser.h index 5cc3694..7c7b423 100644 --- a/Swiften/Parser/AuthRequestParser.h +++ b/Swiften/Parser/AuthRequestParser.h @@ -7,8 +7,8 @@ #ifndef SWIFTEN_AuthRequestParser_H #define SWIFTEN_AuthRequestParser_H -#include "Swiften/Parser/GenericElementParser.h" -#include "Swiften/Elements/AuthRequest.h" +#include <Swiften/Parser/GenericElementParser.h> +#include <Swiften/Elements/AuthRequest.h> #include <string> namespace Swift { diff --git a/Swiften/Parser/AuthResponseParser.cpp b/Swiften/Parser/AuthResponseParser.cpp index 0db6a2a..32d66fe 100644 --- a/Swiften/Parser/AuthResponseParser.cpp +++ b/Swiften/Parser/AuthResponseParser.cpp @@ -4,8 +4,8 @@ * See Documentation/Licenses/GPLv3.txt for more information. */ -#include "Swiften/Parser/AuthResponseParser.h" -#include "Swiften/StringCodecs/Base64.h" +#include <Swiften/Parser/AuthResponseParser.h> +#include <Swiften/StringCodecs/Base64.h> namespace Swift { diff --git a/Swiften/Parser/AuthResponseParser.h b/Swiften/Parser/AuthResponseParser.h index aee2f9c..3dc2282 100644 --- a/Swiften/Parser/AuthResponseParser.h +++ b/Swiften/Parser/AuthResponseParser.h @@ -6,8 +6,8 @@ #pragma once -#include "Swiften/Parser/GenericElementParser.h" -#include "Swiften/Elements/AuthResponse.h" +#include <Swiften/Parser/GenericElementParser.h> +#include <Swiften/Elements/AuthResponse.h> #include <string> namespace Swift { diff --git a/Swiften/Parser/AuthSuccessParser.cpp b/Swiften/Parser/AuthSuccessParser.cpp index 0dee6ad..50246a4 100644 --- a/Swiften/Parser/AuthSuccessParser.cpp +++ b/Swiften/Parser/AuthSuccessParser.cpp @@ -4,8 +4,8 @@ * See Documentation/Licenses/GPLv3.txt for more information. */ -#include "Swiften/Parser/AuthSuccessParser.h" -#include "Swiften/StringCodecs/Base64.h" +#include <Swiften/Parser/AuthSuccessParser.h> +#include <Swiften/StringCodecs/Base64.h> namespace Swift { diff --git a/Swiften/Parser/AuthSuccessParser.h b/Swiften/Parser/AuthSuccessParser.h index 30c89d2..b726b95 100644 --- a/Swiften/Parser/AuthSuccessParser.h +++ b/Swiften/Parser/AuthSuccessParser.h @@ -6,8 +6,8 @@ #pragma once -#include "Swiften/Parser/GenericElementParser.h" -#include "Swiften/Elements/AuthSuccess.h" +#include <Swiften/Parser/GenericElementParser.h> +#include <Swiften/Elements/AuthSuccess.h> #include <string> namespace Swift { diff --git a/Swiften/Parser/ComponentHandshakeParser.cpp b/Swiften/Parser/ComponentHandshakeParser.cpp index 4117a56..c58caf0 100644 --- a/Swiften/Parser/ComponentHandshakeParser.cpp +++ b/Swiften/Parser/ComponentHandshakeParser.cpp @@ -4,8 +4,8 @@ * See Documentation/Licenses/GPLv3.txt for more information. */ -#include "Swiften/Parser/ComponentHandshakeParser.h" -#include "Swiften/StringCodecs/Base64.h" +#include <Swiften/Parser/ComponentHandshakeParser.h> +#include <Swiften/StringCodecs/Base64.h> namespace Swift { diff --git a/Swiften/Parser/ComponentHandshakeParser.h b/Swiften/Parser/ComponentHandshakeParser.h index 389bb6d..25cee6e 100644 --- a/Swiften/Parser/ComponentHandshakeParser.h +++ b/Swiften/Parser/ComponentHandshakeParser.h @@ -6,8 +6,8 @@ #pragma once -#include "Swiften/Parser/GenericElementParser.h" -#include "Swiften/Elements/ComponentHandshake.h" +#include <Swiften/Parser/GenericElementParser.h> +#include <Swiften/Elements/ComponentHandshake.h> #include <string> namespace Swift { diff --git a/Swiften/Parser/CompressFailureParser.h b/Swiften/Parser/CompressFailureParser.h index 7983a04..26077c8 100644 --- a/Swiften/Parser/CompressFailureParser.h +++ b/Swiften/Parser/CompressFailureParser.h @@ -7,8 +7,8 @@ #ifndef SWIFTEN_CompressFailureParser_H #define SWIFTEN_CompressFailureParser_H -#include "Swiften/Parser/GenericElementParser.h" -#include "Swiften/Elements/CompressFailure.h" +#include <Swiften/Parser/GenericElementParser.h> +#include <Swiften/Elements/CompressFailure.h> namespace Swift { class CompressFailureParser : public GenericElementParser<CompressFailure> { diff --git a/Swiften/Parser/CompressParser.cpp b/Swiften/Parser/CompressParser.cpp index 5ce5204..d8f773b 100644 --- a/Swiften/Parser/CompressParser.cpp +++ b/Swiften/Parser/CompressParser.cpp @@ -4,7 +4,7 @@ * See Documentation/Licenses/GPLv3.txt for more information. */ -#include "Swiften/Parser/CompressParser.h" +#include <Swiften/Parser/CompressParser.h> namespace Swift { diff --git a/Swiften/Parser/CompressParser.h b/Swiften/Parser/CompressParser.h index 54257b6..9982b31 100644 --- a/Swiften/Parser/CompressParser.h +++ b/Swiften/Parser/CompressParser.h @@ -8,8 +8,8 @@ #define SWIFTEN_CompressParser_H #include <string> -#include "Swiften/Parser/GenericElementParser.h" -#include "Swiften/Elements/CompressRequest.h" +#include <Swiften/Parser/GenericElementParser.h> +#include <Swiften/Elements/CompressRequest.h> namespace Swift { class CompressParser : public GenericElementParser<CompressRequest> { diff --git a/Swiften/Parser/CompressedParser.h b/Swiften/Parser/CompressedParser.h index af1f063..55f5bcd 100644 --- a/Swiften/Parser/CompressedParser.h +++ b/Swiften/Parser/CompressedParser.h @@ -7,8 +7,8 @@ #ifndef SWIFTEN_COMPRESSEDPARSER_H #define SWIFTEN_COMPRESSEDPARSER_H -#include "Swiften/Parser/GenericElementParser.h" -#include "Swiften/Elements/Compressed.h" +#include <Swiften/Parser/GenericElementParser.h> +#include <Swiften/Elements/Compressed.h> namespace Swift { class CompressedParser : public GenericElementParser<Compressed> { diff --git a/Swiften/Parser/ElementParser.cpp b/Swiften/Parser/ElementParser.cpp index f669a01..1064f2e 100644 --- a/Swiften/Parser/ElementParser.cpp +++ b/Swiften/Parser/ElementParser.cpp @@ -4,7 +4,7 @@ * See Documentation/Licenses/GPLv3.txt for more information. */ -#include "Swiften/Parser/ElementParser.h" +#include <Swiften/Parser/ElementParser.h> namespace Swift { diff --git a/Swiften/Parser/ElementParser.h b/Swiften/Parser/ElementParser.h index 60f2395..1765ea0 100644 --- a/Swiften/Parser/ElementParser.h +++ b/Swiften/Parser/ElementParser.h @@ -10,8 +10,8 @@ #include <boost/shared_ptr.hpp> #include <string> -#include "Swiften/Elements/Element.h" -#include "Swiften/Parser/AttributeMap.h" +#include <Swiften/Elements/Element.h> +#include <Swiften/Parser/AttributeMap.h> namespace Swift { class ElementParser { diff --git a/Swiften/Parser/EnableStreamManagementParser.h b/Swiften/Parser/EnableStreamManagementParser.h index bd86420..530efd9 100644 --- a/Swiften/Parser/EnableStreamManagementParser.h +++ b/Swiften/Parser/EnableStreamManagementParser.h @@ -6,8 +6,8 @@ #pragma once -#include "Swiften/Parser/GenericElementParser.h" -#include "Swiften/Elements/EnableStreamManagement.h" +#include <Swiften/Parser/GenericElementParser.h> +#include <Swiften/Elements/EnableStreamManagement.h> namespace Swift { class EnableStreamManagementParser : public GenericElementParser<EnableStreamManagement> { diff --git a/Swiften/Parser/ExpatParser.cpp b/Swiften/Parser/ExpatParser.cpp index 88be752..798e2e9 100644 --- a/Swiften/Parser/ExpatParser.cpp +++ b/Swiften/Parser/ExpatParser.cpp @@ -4,13 +4,13 @@ * See Documentation/Licenses/GPLv3.txt for more information. */ -#include "Swiften/Parser/ExpatParser.h" +#include <Swiften/Parser/ExpatParser.h> #include <iostream> #include <string> #include <Swiften/Base/String.h> -#include "Swiften/Parser/XMLParserClient.h" +#include <Swiften/Parser/XMLParserClient.h> namespace Swift { @@ -30,7 +30,7 @@ static void handleStartElement(void* client, const XML_Char* name, const XML_Cha nsAttributePair.second = nsAttributePair.first; nsAttributePair.first = ""; } - attributeValues[nsAttributePair.second] = std::string(*(currentAttribute+1)); + attributeValues.addAttribute(nsAttributePair.second, nsAttributePair.first, std::string(*(currentAttribute+1))); currentAttribute += 2; } diff --git a/Swiften/Parser/ExpatParser.h b/Swiften/Parser/ExpatParser.h index f6faf17..eb3e7ab 100644 --- a/Swiften/Parser/ExpatParser.h +++ b/Swiften/Parser/ExpatParser.h @@ -10,7 +10,7 @@ #include <expat.h> #include <boost/noncopyable.hpp> -#include "Swiften/Parser/XMLParser.h" +#include <Swiften/Parser/XMLParser.h> namespace Swift { class ExpatParser : public XMLParser, public boost::noncopyable { diff --git a/Swiften/Parser/GenericPayloadParserFactory.h b/Swiften/Parser/GenericPayloadParserFactory.h index 9b108a0..43042a1 100644 --- a/Swiften/Parser/GenericPayloadParserFactory.h +++ b/Swiften/Parser/GenericPayloadParserFactory.h @@ -6,7 +6,7 @@ #pragma once -#include "Swiften/Parser/PayloadParserFactory.h" +#include <Swiften/Parser/PayloadParserFactory.h> #include <string> namespace Swift { diff --git a/Swiften/Parser/IQParser.cpp b/Swiften/Parser/IQParser.cpp index e0883f2..62d775f 100644 --- a/Swiften/Parser/IQParser.cpp +++ b/Swiften/Parser/IQParser.cpp @@ -5,8 +5,9 @@ */ #include <iostream> +#include <boost/optional.hpp> -#include "Swiften/Parser/IQParser.h" +#include <Swiften/Parser/IQParser.h> namespace Swift { @@ -15,22 +16,22 @@ IQParser::IQParser(PayloadParserFactoryCollection* factories) : } void IQParser::handleStanzaAttributes(const AttributeMap& attributes) { - AttributeMap::const_iterator type = attributes.find("type"); - if (type != attributes.end()) { - if (type->second == "set") { + boost::optional<std::string> type = attributes.getAttributeValue("type"); + if (type) { + if (*type == "set") { getStanzaGeneric()->setType(IQ::Set); } - else if (type->second == "get") { + else if (*type == "get") { getStanzaGeneric()->setType(IQ::Get); } - else if (type->second == "result") { + else if (*type == "result") { getStanzaGeneric()->setType(IQ::Result); } - else if (type->second == "error") { + else if (*type == "error") { getStanzaGeneric()->setType(IQ::Error); } else { - std::cerr << "Unknown IQ type: " << type->second << std::endl; + std::cerr << "Unknown IQ type: " << *type << std::endl; getStanzaGeneric()->setType(IQ::Get); } } diff --git a/Swiften/Parser/IQParser.h b/Swiften/Parser/IQParser.h index e104dc4..a7aa967 100644 --- a/Swiften/Parser/IQParser.h +++ b/Swiften/Parser/IQParser.h @@ -4,11 +4,10 @@ * See Documentation/Licenses/GPLv3.txt for more information. */ -#ifndef SWIFTEN_IQParser_H -#define SWIFTEN_IQParser_H +#pragma once -#include "Swiften/Parser/GenericStanzaParser.h" -#include "Swiften/Elements/IQ.h" +#include <Swiften/Parser/GenericStanzaParser.h> +#include <Swiften/Elements/IQ.h> namespace Swift { class IQParser : public GenericStanzaParser<IQ> { @@ -19,5 +18,3 @@ namespace Swift { virtual void handleStanzaAttributes(const AttributeMap&); }; } - -#endif diff --git a/Swiften/Parser/LibXMLParser.cpp b/Swiften/Parser/LibXMLParser.cpp index 34db4ca..9a2260b 100644 --- a/Swiften/Parser/LibXMLParser.cpp +++ b/Swiften/Parser/LibXMLParser.cpp @@ -4,21 +4,29 @@ * See Documentation/Licenses/GPLv3.txt for more information. */ -#include "Swiften/Parser/LibXMLParser.h" +#include <Swiften/Parser/LibXMLParser.h> #include <iostream> #include <cassert> #include <cstring> #include <string> -#include "Swiften/Parser/XMLParserClient.h" +#include <Swiften/Parser/XMLParserClient.h> namespace Swift { -static void handleStartElement(void *client, const xmlChar* name, const xmlChar*, const xmlChar* xmlns, int, const xmlChar**, int nbAttributes, int, const xmlChar ** attributes) { +static void handleStartElement(void *client, const xmlChar* name, const xmlChar*, const xmlChar* xmlns, int, const xmlChar**, int nbAttributes, int nbDefaulted, const xmlChar ** attributes) { AttributeMap attributeValues; + if (nbDefaulted != 0) { + // Just because i don't understand what this means yet :-) + std::cerr << "Unexpected nbDefaulted on XML element" << std::endl; + } for (int i = 0; i < nbAttributes*5; i += 5) { - attributeValues[std::string(reinterpret_cast<const char*>(attributes[i]))] = std::string(reinterpret_cast<const char*>(attributes[i+3]), attributes[i+4]-attributes[i+3]); + std::string attributeNS = ""; + if (attributes[i+2]) { + attributeNS = std::string(reinterpret_cast<const char*>(attributes[i+2])); + } + attributeValues.addAttribute(std::string(reinterpret_cast<const char*>(attributes[i])), attributeNS, std::string(reinterpret_cast<const char*>(attributes[i+3]), attributes[i+4]-attributes[i+3])); } static_cast<XMLParserClient*>(client)->handleStartElement(reinterpret_cast<const char*>(name), (xmlns ? reinterpret_cast<const char*>(xmlns) : std::string()), attributeValues); } diff --git a/Swiften/Parser/LibXMLParser.h b/Swiften/Parser/LibXMLParser.h index d0dac8b..ba61ad9 100644 --- a/Swiften/Parser/LibXMLParser.h +++ b/Swiften/Parser/LibXMLParser.h @@ -9,7 +9,7 @@ #include <libxml/parser.h> #include <boost/noncopyable.hpp> -#include "Swiften/Parser/XMLParser.h" +#include <Swiften/Parser/XMLParser.h> namespace Swift { class LibXMLParser : public XMLParser, public boost::noncopyable { diff --git a/Swiften/Parser/MessageParser.cpp b/Swiften/Parser/MessageParser.cpp index 5f4d59c..7f5e6d4 100644 --- a/Swiften/Parser/MessageParser.cpp +++ b/Swiften/Parser/MessageParser.cpp @@ -4,9 +4,9 @@ * See Documentation/Licenses/GPLv3.txt for more information. */ -#include <iostream> +#include <boost/optional.hpp> -#include "Swiften/Parser/MessageParser.h" +#include <Swiften/Parser/MessageParser.h> namespace Swift { @@ -16,18 +16,18 @@ MessageParser::MessageParser(PayloadParserFactoryCollection* factories) : } void MessageParser::handleStanzaAttributes(const AttributeMap& attributes) { - AttributeMap::const_iterator type = attributes.find("type"); - if (type != attributes.end()) { - if (type->second == "chat") { + boost::optional<std::string> type = attributes.getAttributeValue("type"); + if (type) { + if (*type == "chat") { getStanzaGeneric()->setType(Message::Chat); } - else if (type->second == "error") { + else if (*type == "error") { getStanzaGeneric()->setType(Message::Error); } - else if (type->second == "groupchat") { + else if (*type == "groupchat") { getStanzaGeneric()->setType(Message::Groupchat); } - else if (type->second == "headline") { + else if (*type == "headline") { getStanzaGeneric()->setType(Message::Headline); } else { diff --git a/Swiften/Parser/MessageParser.h b/Swiften/Parser/MessageParser.h index 70def0a..795c0b3 100644 --- a/Swiften/Parser/MessageParser.h +++ b/Swiften/Parser/MessageParser.h @@ -7,8 +7,8 @@ #ifndef SWIFTEN_MESSAGEPARSER_H #define SWIFTEN_MESSAGEPARSER_H -#include "Swiften/Parser/GenericStanzaParser.h" -#include "Swiften/Elements/Message.h" +#include <Swiften/Parser/GenericStanzaParser.h> +#include <Swiften/Elements/Message.h> namespace Swift { class MessageParser : public GenericStanzaParser<Message> { diff --git a/Swiften/Parser/PayloadParser.cpp b/Swiften/Parser/PayloadParser.cpp index 42d36e0..3680d63 100644 --- a/Swiften/Parser/PayloadParser.cpp +++ b/Swiften/Parser/PayloadParser.cpp @@ -4,7 +4,7 @@ * See Documentation/Licenses/GPLv3.txt for more information. */ -#include "Swiften/Parser/PayloadParser.h" +#include <Swiften/Parser/PayloadParser.h> namespace Swift { diff --git a/Swiften/Parser/PayloadParser.h b/Swiften/Parser/PayloadParser.h index 423a2bb..8a9a290 100644 --- a/Swiften/Parser/PayloadParser.h +++ b/Swiften/Parser/PayloadParser.h @@ -7,9 +7,9 @@ #pragma once #include <boost/shared_ptr.hpp> -#include "Swiften/Parser/AttributeMap.h" +#include <Swiften/Parser/AttributeMap.h> -#include "Swiften/Elements/Payload.h" +#include <Swiften/Elements/Payload.h> namespace Swift { @@ -44,6 +44,6 @@ namespace Swift { /** * Retrieve a pointer to the payload. */ - virtual Payload::ref getPayload() const = 0; + virtual boost::shared_ptr<Payload> getPayload() const = 0; }; } diff --git a/Swiften/Parser/PayloadParserFactory.cpp b/Swiften/Parser/PayloadParserFactory.cpp index 29501d6..4dac217 100644 --- a/Swiften/Parser/PayloadParserFactory.cpp +++ b/Swiften/Parser/PayloadParserFactory.cpp @@ -4,7 +4,7 @@ * See Documentation/Licenses/GPLv3.txt for more information. */ -#include "Swiften/Parser/PayloadParserFactory.h" +#include <Swiften/Parser/PayloadParserFactory.h> namespace Swift { diff --git a/Swiften/Parser/PayloadParserFactory.h b/Swiften/Parser/PayloadParserFactory.h index 2baa2ad..5619d21 100644 --- a/Swiften/Parser/PayloadParserFactory.h +++ b/Swiften/Parser/PayloadParserFactory.h @@ -6,7 +6,7 @@ #pragma once -#include "Swiften/Parser/AttributeMap.h" +#include <Swiften/Parser/AttributeMap.h> namespace Swift { diff --git a/Swiften/Parser/PayloadParserFactoryCollection.cpp b/Swiften/Parser/PayloadParserFactoryCollection.cpp index 0080fbe..e3efc3d 100644 --- a/Swiften/Parser/PayloadParserFactoryCollection.cpp +++ b/Swiften/Parser/PayloadParserFactoryCollection.cpp @@ -7,8 +7,8 @@ #include <boost/bind.hpp> #include <algorithm> -#include "Swiften/Parser/PayloadParserFactoryCollection.h" -#include "Swiften/Parser/PayloadParserFactory.h" +#include <Swiften/Parser/PayloadParserFactoryCollection.h> +#include <Swiften/Parser/PayloadParserFactory.h> namespace Swift { diff --git a/Swiften/Parser/PayloadParserFactoryCollection.h b/Swiften/Parser/PayloadParserFactoryCollection.h index 9afb9b7..2c55d16 100644 --- a/Swiften/Parser/PayloadParserFactoryCollection.h +++ b/Swiften/Parser/PayloadParserFactoryCollection.h @@ -9,7 +9,7 @@ #include <vector> -#include "Swiften/Parser/AttributeMap.h" +#include <Swiften/Parser/AttributeMap.h> namespace Swift { class PayloadParserFactory; diff --git a/Swiften/Parser/PayloadParsers/BodyParser.cpp b/Swiften/Parser/PayloadParsers/BodyParser.cpp index d0f4e09..ac8bdd5 100644 --- a/Swiften/Parser/PayloadParsers/BodyParser.cpp +++ b/Swiften/Parser/PayloadParsers/BodyParser.cpp @@ -4,7 +4,7 @@ * See Documentation/Licenses/GPLv3.txt for more information. */ -#include "Swiften/Parser/PayloadParsers/BodyParser.h" +#include <Swiften/Parser/PayloadParsers/BodyParser.h> namespace Swift { diff --git a/Swiften/Parser/PayloadParsers/BodyParser.h b/Swiften/Parser/PayloadParsers/BodyParser.h index f9e17e0..09b935c 100644 --- a/Swiften/Parser/PayloadParsers/BodyParser.h +++ b/Swiften/Parser/PayloadParsers/BodyParser.h @@ -7,8 +7,8 @@ #ifndef SWIFTEN_BodyParser_H #define SWIFTEN_BodyParser_H -#include "Swiften/Elements/Body.h" -#include "Swiften/Parser/GenericPayloadParser.h" +#include <Swiften/Elements/Body.h> +#include <Swiften/Parser/GenericPayloadParser.h> namespace Swift { class BodyParser : public GenericPayloadParser<Body> { diff --git a/Swiften/Parser/PayloadParsers/BytestreamsParser.cpp b/Swiften/Parser/PayloadParsers/BytestreamsParser.cpp index 35db9ec..fddc1c7 100644 --- a/Swiften/Parser/PayloadParsers/BytestreamsParser.cpp +++ b/Swiften/Parser/PayloadParsers/BytestreamsParser.cpp @@ -4,11 +4,11 @@ * See Documentation/Licenses/GPLv3.txt for more information. */ -#include "Swiften/Parser/PayloadParsers/BytestreamsParser.h" +#include <Swiften/Parser/PayloadParsers/BytestreamsParser.h> #include <boost/lexical_cast.hpp> -#include "Swiften/Base/foreach.h" +#include <Swiften/Base/foreach.h> namespace Swift { @@ -27,7 +27,7 @@ void BytestreamsParser::handleStartElement(const std::string& element, const std try { getPayloadInternal()->addStreamHost(Bytestreams::StreamHost(attributes.getAttribute("host"), JID(attributes.getAttribute("jid")), boost::lexical_cast<int>(attributes.getAttribute("port")))); } - catch (boost::bad_lexical_cast& e) { + catch (boost::bad_lexical_cast&) { } } else if (element == "streamhost-used") { diff --git a/Swiften/Parser/PayloadParsers/BytestreamsParser.h b/Swiften/Parser/PayloadParsers/BytestreamsParser.h index 2d67785..4785913 100644 --- a/Swiften/Parser/PayloadParsers/BytestreamsParser.h +++ b/Swiften/Parser/PayloadParsers/BytestreamsParser.h @@ -8,8 +8,8 @@ #include <boost/optional.hpp> -#include "Swiften/Elements/Bytestreams.h" -#include "Swiften/Parser/GenericPayloadParser.h" +#include <Swiften/Elements/Bytestreams.h> +#include <Swiften/Parser/GenericPayloadParser.h> namespace Swift { class BytestreamsParser : public GenericPayloadParser<Bytestreams> { diff --git a/Swiften/Parser/PayloadParsers/BytestreamsParserFactory.h b/Swiften/Parser/PayloadParsers/BytestreamsParserFactory.h index 8defd45..06ebc4d 100644 --- a/Swiften/Parser/PayloadParsers/BytestreamsParserFactory.h +++ b/Swiften/Parser/PayloadParsers/BytestreamsParserFactory.h @@ -6,8 +6,8 @@ #pragma once -#include "Swiften/Parser/GenericPayloadParserFactory.h" -#include "Swiften/Parser/PayloadParsers/BytestreamsParser.h" +#include <Swiften/Parser/GenericPayloadParserFactory.h> +#include <Swiften/Parser/PayloadParsers/BytestreamsParser.h> namespace Swift { class BytestreamsParserFactory : public GenericPayloadParserFactory<BytestreamsParser> { diff --git a/Swiften/Parser/PayloadParsers/CapsInfoParser.cpp b/Swiften/Parser/PayloadParsers/CapsInfoParser.cpp index d7d9324..770d98b 100644 --- a/Swiften/Parser/PayloadParsers/CapsInfoParser.cpp +++ b/Swiften/Parser/PayloadParsers/CapsInfoParser.cpp @@ -4,7 +4,7 @@ * See Documentation/Licenses/GPLv3.txt for more information. */ -#include "Swiften/Parser/PayloadParsers/CapsInfoParser.h" +#include <Swiften/Parser/PayloadParsers/CapsInfoParser.h> #include <locale> diff --git a/Swiften/Parser/PayloadParsers/CapsInfoParser.h b/Swiften/Parser/PayloadParsers/CapsInfoParser.h index 590326d..96aa734 100644 --- a/Swiften/Parser/PayloadParsers/CapsInfoParser.h +++ b/Swiften/Parser/PayloadParsers/CapsInfoParser.h @@ -6,8 +6,8 @@ #pragma once -#include "Swiften/Elements/CapsInfo.h" -#include "Swiften/Parser/GenericPayloadParser.h" +#include <Swiften/Elements/CapsInfo.h> +#include <Swiften/Parser/GenericPayloadParser.h> namespace Swift { class CapsInfoParser : public GenericPayloadParser<CapsInfo> { diff --git a/Swiften/Parser/PayloadParsers/ChatStateParser.cpp b/Swiften/Parser/PayloadParsers/ChatStateParser.cpp index 3a5ba3b..a85dcf7 100644 --- a/Swiften/Parser/PayloadParsers/ChatStateParser.cpp +++ b/Swiften/Parser/PayloadParsers/ChatStateParser.cpp @@ -4,7 +4,7 @@ * See Documentation/Licenses/GPLv3.txt for more information. */ -#include "Swiften/Parser/PayloadParsers/ChatStateParser.h" +#include <Swiften/Parser/PayloadParsers/ChatStateParser.h> namespace Swift { diff --git a/Swiften/Parser/PayloadParsers/ChatStateParser.h b/Swiften/Parser/PayloadParsers/ChatStateParser.h index 8d0e7f5..4363d6b 100644 --- a/Swiften/Parser/PayloadParsers/ChatStateParser.h +++ b/Swiften/Parser/PayloadParsers/ChatStateParser.h @@ -6,8 +6,8 @@ #pragma once -#include "Swiften/Elements/ChatState.h" -#include "Swiften/Parser/GenericPayloadParser.h" +#include <Swiften/Elements/ChatState.h> +#include <Swiften/Parser/GenericPayloadParser.h> namespace Swift { class ChatStateParser : public GenericPayloadParser<ChatState> { diff --git a/Swiften/Parser/PayloadParsers/ChatStateParserFactory.h b/Swiften/Parser/PayloadParsers/ChatStateParserFactory.h index 3dadda7..80d76c4 100644 --- a/Swiften/Parser/PayloadParsers/ChatStateParserFactory.h +++ b/Swiften/Parser/PayloadParsers/ChatStateParserFactory.h @@ -6,8 +6,8 @@ #pragma once -#include "Swiften/Parser/PayloadParserFactory.h" -#include "Swiften/Parser/PayloadParsers/ChatStateParser.h" +#include <Swiften/Parser/PayloadParserFactory.h> +#include <Swiften/Parser/PayloadParsers/ChatStateParser.h> namespace Swift { class PayloadParserFactoryCollection; diff --git a/Swiften/Parser/PayloadParsers/CommandParser.cpp b/Swiften/Parser/PayloadParsers/CommandParser.cpp index 3ebab39..1af4074 100644 --- a/Swiften/Parser/PayloadParsers/CommandParser.cpp +++ b/Swiften/Parser/PayloadParsers/CommandParser.cpp @@ -4,12 +4,12 @@ * See Documentation/Licenses/GPLv3.txt for more information. */ -#include "Swiften/Parser/PayloadParsers/CommandParser.h" +#include <Swiften/Parser/PayloadParsers/CommandParser.h> #include <boost/cast.hpp> -#include "Swiften/Parser/PayloadParsers/FormParserFactory.h" -#include "Swiften/Parser/PayloadParsers/FormParser.h" +#include <Swiften/Parser/PayloadParsers/FormParserFactory.h> +#include <Swiften/Parser/PayloadParsers/FormParser.h> namespace Swift { diff --git a/Swiften/Parser/PayloadParsers/CommandParser.h b/Swiften/Parser/PayloadParsers/CommandParser.h index 0415ba6..80cffc4 100644 --- a/Swiften/Parser/PayloadParsers/CommandParser.h +++ b/Swiften/Parser/PayloadParsers/CommandParser.h @@ -8,8 +8,8 @@ #include <boost/optional.hpp> -#include "Swiften/Elements/Command.h" -#include "Swiften/Parser/GenericPayloadParser.h" +#include <Swiften/Elements/Command.h> +#include <Swiften/Parser/GenericPayloadParser.h> namespace Swift { class FormParserFactory; diff --git a/Swiften/Parser/PayloadParsers/CommandParserFactory.h b/Swiften/Parser/PayloadParsers/CommandParserFactory.h index 9eaaf62..47d3333 100644 --- a/Swiften/Parser/PayloadParsers/CommandParserFactory.h +++ b/Swiften/Parser/PayloadParsers/CommandParserFactory.h @@ -6,8 +6,8 @@ #pragma once -#include "Swiften/Parser/PayloadParserFactory.h" -#include "Swiften/Parser/PayloadParsers/CommandParser.h" +#include <Swiften/Parser/PayloadParserFactory.h> +#include <Swiften/Parser/PayloadParsers/CommandParser.h> namespace Swift { class PayloadParserFactoryCollection; diff --git a/Swiften/Parser/PayloadParsers/DelayParser.cpp b/Swiften/Parser/PayloadParsers/DelayParser.cpp index 3425b84..e2a6bad 100644 --- a/Swiften/Parser/PayloadParsers/DelayParser.cpp +++ b/Swiften/Parser/PayloadParsers/DelayParser.cpp @@ -4,11 +4,12 @@ * See Documentation/Licenses/GPLv3.txt for more information. */ -#include "Swiften/Parser/PayloadParsers/DelayParser.h" +#include <Swiften/Parser/PayloadParsers/DelayParser.h> #include <locale> #include <boost/date_time/time_facet.hpp> +#include <boost/date_time/posix_time/posix_time.hpp> namespace Swift { diff --git a/Swiften/Parser/PayloadParsers/DelayParser.h b/Swiften/Parser/PayloadParsers/DelayParser.h index c2e2bb6..02103d9 100644 --- a/Swiften/Parser/PayloadParsers/DelayParser.h +++ b/Swiften/Parser/PayloadParsers/DelayParser.h @@ -6,8 +6,8 @@ #pragma once -#include "Swiften/Elements/Delay.h" -#include "Swiften/Parser/GenericPayloadParser.h" +#include <Swiften/Elements/Delay.h> +#include <Swiften/Parser/GenericPayloadParser.h> namespace Swift { class DelayParser : public GenericPayloadParser<Delay> { diff --git a/Swiften/Parser/PayloadParsers/DelayParserFactory.cpp b/Swiften/Parser/PayloadParsers/DelayParserFactory.cpp index 19d0530..48841d2 100644 --- a/Swiften/Parser/PayloadParsers/DelayParserFactory.cpp +++ b/Swiften/Parser/PayloadParsers/DelayParserFactory.cpp @@ -6,6 +6,7 @@ #include <Swiften/Parser/PayloadParsers/DelayParserFactory.h> +#include <boost/date_time/posix_time/posix_time.hpp> #include <boost/date_time/time_facet.hpp> namespace Swift { diff --git a/Swiften/Parser/PayloadParsers/DelayParserFactory.h b/Swiften/Parser/PayloadParsers/DelayParserFactory.h index c150853..7dde35e 100644 --- a/Swiften/Parser/PayloadParsers/DelayParserFactory.h +++ b/Swiften/Parser/PayloadParsers/DelayParserFactory.h @@ -6,8 +6,8 @@ #pragma once -#include "Swiften/Parser/PayloadParserFactory.h" -#include "Swiften/Parser/PayloadParsers/DelayParser.h" +#include <Swiften/Parser/PayloadParserFactory.h> +#include <Swiften/Parser/PayloadParsers/DelayParser.h> namespace Swift { class PayloadParserFactoryCollection; diff --git a/Swiften/Parser/PayloadParsers/DiscoInfoParser.cpp b/Swiften/Parser/PayloadParsers/DiscoInfoParser.cpp index e1fcb20..14ff79d 100644 --- a/Swiften/Parser/PayloadParsers/DiscoInfoParser.cpp +++ b/Swiften/Parser/PayloadParsers/DiscoInfoParser.cpp @@ -4,8 +4,8 @@ * See Documentation/Licenses/GPLv3.txt for more information. */ -#include "Swiften/Parser/PayloadParsers/DiscoInfoParser.h" -#include "Swiften/Parser/PayloadParsers/FormParser.h" +#include <Swiften/Parser/PayloadParsers/DiscoInfoParser.h> +#include <Swiften/Parser/PayloadParsers/FormParser.h> namespace Swift { @@ -15,7 +15,7 @@ DiscoInfoParser::DiscoInfoParser() : level_(TopLevel), formParser_(NULL) { void DiscoInfoParser::handleStartElement(const std::string& element, const std::string& ns, const AttributeMap& attributes) { if (level_ == PayloadLevel) { if (element == "identity") { - getPayloadInternal()->addIdentity(DiscoInfo::Identity(attributes.getAttribute("name"), attributes.getAttribute("category"), attributes.getAttribute("type"), attributes.getAttribute("lang"))); + getPayloadInternal()->addIdentity(DiscoInfo::Identity(attributes.getAttribute("name"), attributes.getAttribute("category"), attributes.getAttribute("type"), attributes.getAttribute("lang", "http://www.w3.org/XML/1998/namespace"))); } else if (element == "feature") { getPayloadInternal()->addFeature(attributes.getAttribute("var")); diff --git a/Swiften/Parser/PayloadParsers/DiscoInfoParser.h b/Swiften/Parser/PayloadParsers/DiscoInfoParser.h index 24a1d6f..df1441c 100644 --- a/Swiften/Parser/PayloadParsers/DiscoInfoParser.h +++ b/Swiften/Parser/PayloadParsers/DiscoInfoParser.h @@ -6,8 +6,8 @@ #pragma once -#include "Swiften/Elements/DiscoInfo.h" -#include "Swiften/Parser/GenericPayloadParser.h" +#include <Swiften/Elements/DiscoInfo.h> +#include <Swiften/Parser/GenericPayloadParser.h> namespace Swift { class DiscoInfoParser : public GenericPayloadParser<DiscoInfo> { diff --git a/Swiften/Parser/PayloadParsers/DiscoItemsParser.cpp b/Swiften/Parser/PayloadParsers/DiscoItemsParser.cpp index 7ff375b..d6ac94d 100644 --- a/Swiften/Parser/PayloadParsers/DiscoItemsParser.cpp +++ b/Swiften/Parser/PayloadParsers/DiscoItemsParser.cpp @@ -4,7 +4,7 @@ * See Documentation/Licenses/GPLv3.txt for more information. */ -#include "Swiften/Parser/PayloadParsers/DiscoItemsParser.h" +#include <Swiften/Parser/PayloadParsers/DiscoItemsParser.h> namespace Swift { diff --git a/Swiften/Parser/PayloadParsers/DiscoItemsParser.h b/Swiften/Parser/PayloadParsers/DiscoItemsParser.h index 0700df6..ae799cb 100644 --- a/Swiften/Parser/PayloadParsers/DiscoItemsParser.h +++ b/Swiften/Parser/PayloadParsers/DiscoItemsParser.h @@ -6,8 +6,8 @@ #pragma once -#include "Swiften/Elements/DiscoItems.h" -#include "Swiften/Parser/GenericPayloadParser.h" +#include <Swiften/Elements/DiscoItems.h> +#include <Swiften/Parser/GenericPayloadParser.h> namespace Swift { class DiscoItemsParser : public GenericPayloadParser<DiscoItems> { diff --git a/Swiften/Parser/PayloadParsers/ErrorParser.cpp b/Swiften/Parser/PayloadParsers/ErrorParser.cpp index 4034cb5..74eb31d 100644 --- a/Swiften/Parser/PayloadParsers/ErrorParser.cpp +++ b/Swiften/Parser/PayloadParsers/ErrorParser.cpp @@ -4,7 +4,7 @@ * See Documentation/Licenses/GPLv3.txt for more information. */ -#include "Swiften/Parser/PayloadParsers/ErrorParser.h" +#include <Swiften/Parser/PayloadParsers/ErrorParser.h> namespace Swift { diff --git a/Swiften/Parser/PayloadParsers/ErrorParser.h b/Swiften/Parser/PayloadParsers/ErrorParser.h index 4318a8c..b80dd30 100644 --- a/Swiften/Parser/PayloadParsers/ErrorParser.h +++ b/Swiften/Parser/PayloadParsers/ErrorParser.h @@ -7,8 +7,8 @@ #ifndef SWIFTEN_ErrorParser_H #define SWIFTEN_ErrorParser_H -#include "Swiften/Elements/ErrorPayload.h" -#include "Swiften/Parser/GenericPayloadParser.h" +#include <Swiften/Elements/ErrorPayload.h> +#include <Swiften/Parser/GenericPayloadParser.h> namespace Swift { class ErrorParser : public GenericPayloadParser<ErrorPayload> { diff --git a/Swiften/Parser/PayloadParsers/FormParser.cpp b/Swiften/Parser/PayloadParsers/FormParser.cpp index f8e02a4..3905302 100644 --- a/Swiften/Parser/PayloadParsers/FormParser.cpp +++ b/Swiften/Parser/PayloadParsers/FormParser.cpp @@ -4,7 +4,7 @@ * See Documentation/Licenses/GPLv3.txt for more information. */ -#include "Swiften/Parser/PayloadParsers/FormParser.h" +#include <Swiften/Parser/PayloadParsers/FormParser.h> namespace Swift { @@ -63,12 +63,9 @@ void FormParser::handleStartElement(const std::string& element, const std::strin else if (type == "text-private") { currentFieldParseHelper_ = TextPrivateFormFieldParseHelper::create(); } - else if (type == "text-single") { + else /*if (type == "text-single") || undefined */ { currentFieldParseHelper_ = TextSingleFormFieldParseHelper::create(); } - else { - currentFieldParseHelper_ = UntypedFormFieldParseHelper::create(); - } if (currentFieldParseHelper_) { currentFieldParseHelper_->getField()->setName(attributes.getAttribute("var")); currentFieldParseHelper_->getField()->setLabel(attributes.getAttribute("label")); diff --git a/Swiften/Parser/PayloadParsers/FormParser.h b/Swiften/Parser/PayloadParsers/FormParser.h index 90a3550..eae40a1 100644 --- a/Swiften/Parser/PayloadParsers/FormParser.h +++ b/Swiften/Parser/PayloadParsers/FormParser.h @@ -6,8 +6,8 @@ #pragma once -#include "Swiften/Elements/Form.h" -#include "Swiften/Parser/GenericPayloadParser.h" +#include <Swiften/Elements/Form.h> +#include <Swiften/Parser/GenericPayloadParser.h> namespace Swift { class FormParser : public GenericPayloadParser<Form> { @@ -96,7 +96,6 @@ namespace Swift { SWIFTEN_DECLARE_FORM_FIELD_PARSE_HELPER(JIDSingle, JID); SWIFTEN_DECLARE_FORM_FIELD_PARSE_HELPER(JIDMulti, JIDList); SWIFTEN_DECLARE_FORM_FIELD_PARSE_HELPER(ListMulti, StringList); - SWIFTEN_DECLARE_FORM_FIELD_PARSE_HELPER(Untyped, StringList); enum Level { TopLevel = 0, diff --git a/Swiften/Parser/PayloadParsers/FormParserFactory.h b/Swiften/Parser/PayloadParsers/FormParserFactory.h index 7c095a7..9e1794a 100644 --- a/Swiften/Parser/PayloadParsers/FormParserFactory.h +++ b/Swiften/Parser/PayloadParsers/FormParserFactory.h @@ -6,8 +6,8 @@ #pragma once -#include "Swiften/Parser/PayloadParserFactory.h" -#include "Swiften/Parser/PayloadParsers/FormParser.h" +#include <Swiften/Parser/PayloadParserFactory.h> +#include <Swiften/Parser/PayloadParsers/FormParser.h> namespace Swift { class PayloadParserFactoryCollection; diff --git a/Swiften/Parser/PayloadParsers/FullPayloadParserFactoryCollection.cpp b/Swiften/Parser/PayloadParsers/FullPayloadParserFactoryCollection.cpp index e20c06d..db9c371 100644 --- a/Swiften/Parser/PayloadParsers/FullPayloadParserFactoryCollection.cpp +++ b/Swiften/Parser/PayloadParsers/FullPayloadParserFactoryCollection.cpp @@ -4,41 +4,43 @@ * See Documentation/Licenses/GPLv3.txt for more information. */ -#include "Swiften/Parser/PayloadParsers/FullPayloadParserFactoryCollection.h" -#include "Swiften/Base/foreach.h" -#include "Swiften/Parser/GenericPayloadParser.h" -#include "Swiften/Parser/PayloadParserFactory.h" -#include "Swiften/Parser/PayloadParsers/ErrorParser.h" -#include "Swiften/Parser/PayloadParsers/BodyParser.h" -#include "Swiften/Parser/PayloadParsers/SubjectParser.h" -#include "Swiften/Parser/PayloadParsers/ChatStateParserFactory.h" -#include "Swiften/Parser/PayloadParsers/PriorityParser.h" -#include "Swiften/Parser/PayloadParsers/ResourceBindParser.h" -#include "Swiften/Parser/PayloadParsers/StartSessionParser.h" -#include "Swiften/Parser/PayloadParsers/StatusParser.h" -#include "Swiften/Parser/PayloadParsers/StatusShowParser.h" -#include "Swiften/Parser/PayloadParsers/RosterParser.h" -#include "Swiften/Parser/PayloadParsers/SoftwareVersionParser.h" -#include "Swiften/Parser/PayloadParsers/StorageParser.h" -#include "Swiften/Parser/PayloadParsers/DiscoInfoParser.h" -#include "Swiften/Parser/PayloadParsers/DiscoItemsParser.h" -#include "Swiften/Parser/PayloadParsers/CapsInfoParser.h" -#include "Swiften/Parser/PayloadParsers/SecurityLabelParserFactory.h" -#include "Swiften/Parser/PayloadParsers/SecurityLabelsCatalogParserFactory.h" -#include "Swiften/Parser/PayloadParsers/FormParserFactory.h" -#include "Swiften/Parser/PayloadParsers/CommandParserFactory.h" -#include "Swiften/Parser/PayloadParsers/InBandRegistrationPayloadParserFactory.h" -#include "Swiften/Parser/PayloadParsers/SearchPayloadParserFactory.h" -#include "Swiften/Parser/PayloadParsers/StreamInitiationParserFactory.h" -#include "Swiften/Parser/PayloadParsers/BytestreamsParserFactory.h" -#include "Swiften/Parser/PayloadParsers/IBBParser.h" -#include "Swiften/Parser/PayloadParsers/VCardUpdateParserFactory.h" -#include "Swiften/Parser/PayloadParsers/VCardParserFactory.h" -#include "Swiften/Parser/PayloadParsers/RawXMLPayloadParserFactory.h" -#include "Swiften/Parser/PayloadParsers/PrivateStorageParserFactory.h" -#include "Swiften/Parser/PayloadParsers/DelayParserFactory.h" -#include "Swiften/Parser/PayloadParsers/MUCUserPayloadParserFactory.h" -#include "Swiften/Parser/PayloadParsers/NicknameParserFactory.h" +#include <Swiften/Parser/PayloadParsers/FullPayloadParserFactoryCollection.h> +#include <Swiften/Base/foreach.h> +#include <Swiften/Parser/GenericPayloadParser.h> +#include <Swiften/Parser/PayloadParserFactory.h> +#include <Swiften/Parser/PayloadParsers/ErrorParser.h> +#include <Swiften/Parser/PayloadParsers/BodyParser.h> +#include <Swiften/Parser/PayloadParsers/SubjectParser.h> +#include <Swiften/Parser/PayloadParsers/ChatStateParserFactory.h> +#include <Swiften/Parser/PayloadParsers/PriorityParser.h> +#include <Swiften/Parser/PayloadParsers/ResourceBindParser.h> +#include <Swiften/Parser/PayloadParsers/StartSessionParser.h> +#include <Swiften/Parser/PayloadParsers/StatusParser.h> +#include <Swiften/Parser/PayloadParsers/StatusShowParser.h> +#include <Swiften/Parser/PayloadParsers/RosterItemExchangeParser.h> +#include <Swiften/Parser/PayloadParsers/RosterParser.h> +#include <Swiften/Parser/PayloadParsers/SoftwareVersionParser.h> +#include <Swiften/Parser/PayloadParsers/StorageParser.h> +#include <Swiften/Parser/PayloadParsers/DiscoInfoParser.h> +#include <Swiften/Parser/PayloadParsers/DiscoItemsParser.h> +#include <Swiften/Parser/PayloadParsers/CapsInfoParser.h> +#include <Swiften/Parser/PayloadParsers/SecurityLabelParserFactory.h> +#include <Swiften/Parser/PayloadParsers/SecurityLabelsCatalogParserFactory.h> +#include <Swiften/Parser/PayloadParsers/FormParserFactory.h> +#include <Swiften/Parser/PayloadParsers/CommandParserFactory.h> +#include <Swiften/Parser/PayloadParsers/InBandRegistrationPayloadParserFactory.h> +#include <Swiften/Parser/PayloadParsers/SearchPayloadParserFactory.h> +#include <Swiften/Parser/PayloadParsers/StreamInitiationParserFactory.h> +#include <Swiften/Parser/PayloadParsers/BytestreamsParserFactory.h> +#include <Swiften/Parser/PayloadParsers/IBBParser.h> +#include <Swiften/Parser/PayloadParsers/VCardUpdateParserFactory.h> +#include <Swiften/Parser/PayloadParsers/VCardParserFactory.h> +#include <Swiften/Parser/PayloadParsers/RawXMLPayloadParserFactory.h> +#include <Swiften/Parser/PayloadParsers/PrivateStorageParserFactory.h> +#include <Swiften/Parser/PayloadParsers/DelayParserFactory.h> +#include <Swiften/Parser/PayloadParsers/MUCUserPayloadParserFactory.h> +#include <Swiften/Parser/PayloadParsers/NicknameParserFactory.h> +#include <Swiften/Parser/PayloadParsers/ReplaceParser.h> using namespace boost; @@ -48,12 +50,14 @@ FullPayloadParserFactoryCollection::FullPayloadParserFactoryCollection() { factories_.push_back(shared_ptr<PayloadParserFactory>(new GenericPayloadParserFactory<IBBParser>("", "http://jabber.org/protocol/ibb"))); factories_.push_back(shared_ptr<PayloadParserFactory>(new GenericPayloadParserFactory<StatusShowParser>("show"))); factories_.push_back(shared_ptr<PayloadParserFactory>(new GenericPayloadParserFactory<StatusParser>("status"))); + factories_.push_back(shared_ptr<PayloadParserFactory>(new GenericPayloadParserFactory<ReplaceParser>("replace", "http://swift.im/protocol/replace"))); factories_.push_back(shared_ptr<PayloadParserFactory>(new GenericPayloadParserFactory<BodyParser>("body"))); factories_.push_back(shared_ptr<PayloadParserFactory>(new GenericPayloadParserFactory<SubjectParser>("subject"))); factories_.push_back(shared_ptr<PayloadParserFactory>(new GenericPayloadParserFactory<PriorityParser>("priority"))); factories_.push_back(shared_ptr<PayloadParserFactory>(new GenericPayloadParserFactory<ErrorParser>("error"))); factories_.push_back(shared_ptr<PayloadParserFactory>(new GenericPayloadParserFactory<SoftwareVersionParser>("query", "jabber:iq:version"))); factories_.push_back(shared_ptr<PayloadParserFactory>(new GenericPayloadParserFactory<StorageParser>("storage", "storage:bookmarks"))); + factories_.push_back(shared_ptr<PayloadParserFactory>(new GenericPayloadParserFactory<RosterItemExchangeParser>("x", "http://jabber.org/protocol/rosterx"))); factories_.push_back(shared_ptr<PayloadParserFactory>(new GenericPayloadParserFactory<RosterParser>("query", "jabber:iq:roster"))); factories_.push_back(shared_ptr<PayloadParserFactory>(new GenericPayloadParserFactory<DiscoInfoParser>("query", "http://jabber.org/protocol/disco#info"))); factories_.push_back(shared_ptr<PayloadParserFactory>(new GenericPayloadParserFactory<DiscoItemsParser>("query", "http://jabber.org/protocol/disco#items"))); diff --git a/Swiften/Parser/PayloadParsers/FullPayloadParserFactoryCollection.h b/Swiften/Parser/PayloadParsers/FullPayloadParserFactoryCollection.h index f3883b0..46b692b 100644 --- a/Swiften/Parser/PayloadParsers/FullPayloadParserFactoryCollection.h +++ b/Swiften/Parser/PayloadParsers/FullPayloadParserFactoryCollection.h @@ -9,8 +9,8 @@ #include <boost/shared_ptr.hpp> #include <vector> -#include "Swiften/Parser/PayloadParserFactoryCollection.h" -#include "Swiften/Parser/PayloadParserFactory.h" +#include <Swiften/Parser/PayloadParserFactoryCollection.h> +#include <Swiften/Parser/PayloadParserFactory.h> namespace Swift { class FullPayloadParserFactoryCollection : public PayloadParserFactoryCollection { diff --git a/Swiften/Parser/PayloadParsers/IBBParser.cpp b/Swiften/Parser/PayloadParsers/IBBParser.cpp index f36dc43..2505f07 100644 --- a/Swiften/Parser/PayloadParsers/IBBParser.cpp +++ b/Swiften/Parser/PayloadParsers/IBBParser.cpp @@ -4,12 +4,12 @@ * See Documentation/Licenses/GPLv3.txt for more information. */ -#include "Swiften/Parser/PayloadParsers/IBBParser.h" +#include <Swiften/Parser/PayloadParsers/IBBParser.h> #include <boost/lexical_cast.hpp> -#include "Swiften/Base/foreach.h" -#include "Swiften/StringCodecs/Base64.h" +#include <Swiften/Base/foreach.h> +#include <Swiften/StringCodecs/Base64.h> namespace Swift { @@ -27,7 +27,7 @@ void IBBParser::handleStartElement(const std::string& element, const std::string try { getPayloadInternal()->setSequenceNumber(boost::lexical_cast<int>(attributes.getAttribute("seq"))); } - catch (boost::bad_lexical_cast& e) { + catch (boost::bad_lexical_cast&) { } } else if (element == "open") { @@ -42,7 +42,7 @@ void IBBParser::handleStartElement(const std::string& element, const std::string try { getPayloadInternal()->setBlockSize(boost::lexical_cast<int>(attributes.getAttribute("block-size"))); } - catch (boost::bad_lexical_cast& e) { + catch (boost::bad_lexical_cast&) { } } else if (element == "close") { @@ -64,7 +64,7 @@ void IBBParser::handleEndElement(const std::string& element, const std::string&) data.push_back(c); } } - getPayloadInternal()->setData(Base64::decode(std::string(&data[0], data.size()))); + getPayloadInternal()->setData(Base64::decode(std::string(&data[0], data.size())).getDataVector()); } } } diff --git a/Swiften/Parser/PayloadParsers/IBBParser.h b/Swiften/Parser/PayloadParsers/IBBParser.h index 132e79d..d899475 100644 --- a/Swiften/Parser/PayloadParsers/IBBParser.h +++ b/Swiften/Parser/PayloadParsers/IBBParser.h @@ -8,8 +8,8 @@ #include <boost/optional.hpp> -#include "Swiften/Elements/IBB.h" -#include "Swiften/Parser/GenericPayloadParser.h" +#include <Swiften/Elements/IBB.h> +#include <Swiften/Parser/GenericPayloadParser.h> namespace Swift { class IBBParser : public GenericPayloadParser<IBB> { diff --git a/Swiften/Parser/PayloadParsers/InBandRegistrationPayloadParser.cpp b/Swiften/Parser/PayloadParsers/InBandRegistrationPayloadParser.cpp index 56995d8..06759cb 100644 --- a/Swiften/Parser/PayloadParsers/InBandRegistrationPayloadParser.cpp +++ b/Swiften/Parser/PayloadParsers/InBandRegistrationPayloadParser.cpp @@ -4,12 +4,12 @@ * See Documentation/Licenses/GPLv3.txt for more information. */ -#include "Swiften/Parser/PayloadParsers/InBandRegistrationPayloadParser.h" +#include <Swiften/Parser/PayloadParsers/InBandRegistrationPayloadParser.h> #include <boost/cast.hpp> -#include "Swiften/Parser/PayloadParsers/FormParserFactory.h" -#include "Swiften/Parser/PayloadParsers/FormParser.h" +#include <Swiften/Parser/PayloadParsers/FormParserFactory.h> +#include <Swiften/Parser/PayloadParsers/FormParser.h> namespace Swift { diff --git a/Swiften/Parser/PayloadParsers/InBandRegistrationPayloadParser.h b/Swiften/Parser/PayloadParsers/InBandRegistrationPayloadParser.h index c0209c4..ae8d36c 100644 --- a/Swiften/Parser/PayloadParsers/InBandRegistrationPayloadParser.h +++ b/Swiften/Parser/PayloadParsers/InBandRegistrationPayloadParser.h @@ -8,8 +8,8 @@ #include <boost/optional.hpp> -#include "Swiften/Elements/InBandRegistrationPayload.h" -#include "Swiften/Parser/GenericPayloadParser.h" +#include <Swiften/Elements/InBandRegistrationPayload.h> +#include <Swiften/Parser/GenericPayloadParser.h> namespace Swift { class FormParserFactory; diff --git a/Swiften/Parser/PayloadParsers/InBandRegistrationPayloadParserFactory.h b/Swiften/Parser/PayloadParsers/InBandRegistrationPayloadParserFactory.h index 0417174..2dff18f 100644 --- a/Swiften/Parser/PayloadParsers/InBandRegistrationPayloadParserFactory.h +++ b/Swiften/Parser/PayloadParsers/InBandRegistrationPayloadParserFactory.h @@ -6,8 +6,8 @@ #pragma once -#include "Swiften/Parser/GenericPayloadParserFactory.h" -#include "Swiften/Parser/PayloadParsers/InBandRegistrationPayloadParser.h" +#include <Swiften/Parser/GenericPayloadParserFactory.h> +#include <Swiften/Parser/PayloadParsers/InBandRegistrationPayloadParser.h> namespace Swift { class InBandRegistrationPayloadParserFactory : public GenericPayloadParserFactory<InBandRegistrationPayloadParser> { diff --git a/Swiften/Parser/PayloadParsers/MUCUserPayloadParser.cpp b/Swiften/Parser/PayloadParsers/MUCUserPayloadParser.cpp index ec9e200..bd81b88 100644 --- a/Swiften/Parser/PayloadParsers/MUCUserPayloadParser.cpp +++ b/Swiften/Parser/PayloadParsers/MUCUserPayloadParser.cpp @@ -4,11 +4,11 @@ * See Documentation/Licenses/GPLv3.txt for more information. */ -#include "Swiften/Parser/PayloadParsers/MUCUserPayloadParser.h" +#include <Swiften/Parser/PayloadParsers/MUCUserPayloadParser.h> #include <boost/lexical_cast.hpp> -#include "Swiften/Elements/MUCOccupant.h" +#include <Swiften/Elements/MUCOccupant.h> #include <cassert> #include <iostream> diff --git a/Swiften/Parser/PayloadParsers/MUCUserPayloadParser.h b/Swiften/Parser/PayloadParsers/MUCUserPayloadParser.h index 384f0cd..b819905 100644 --- a/Swiften/Parser/PayloadParsers/MUCUserPayloadParser.h +++ b/Swiften/Parser/PayloadParsers/MUCUserPayloadParser.h @@ -8,8 +8,8 @@ #include <boost/optional.hpp> -#include "Swiften/Elements/MUCUserPayload.h" -#include "Swiften/Parser/GenericPayloadParser.h" +#include <Swiften/Elements/MUCUserPayload.h> +#include <Swiften/Parser/GenericPayloadParser.h> namespace Swift { class MUCUserPayloadParser : public GenericPayloadParser<MUCUserPayload> { diff --git a/Swiften/Parser/PayloadParsers/MUCUserPayloadParserFactory.h b/Swiften/Parser/PayloadParsers/MUCUserPayloadParserFactory.h index 3946ece..e6c8863 100644 --- a/Swiften/Parser/PayloadParsers/MUCUserPayloadParserFactory.h +++ b/Swiften/Parser/PayloadParsers/MUCUserPayloadParserFactory.h @@ -6,8 +6,8 @@ #pragma once -#include "Swiften/Parser/GenericPayloadParserFactory.h" -#include "Swiften/Parser/PayloadParsers/MUCUserPayloadParser.h" +#include <Swiften/Parser/GenericPayloadParserFactory.h> +#include <Swiften/Parser/PayloadParsers/MUCUserPayloadParser.h> namespace Swift { class MUCUserPayloadParserFactory : public GenericPayloadParserFactory<MUCUserPayloadParser> { diff --git a/Swiften/Parser/PayloadParsers/NicknameParser.cpp b/Swiften/Parser/PayloadParsers/NicknameParser.cpp index cd7ec27..b647b4d 100644 --- a/Swiften/Parser/PayloadParsers/NicknameParser.cpp +++ b/Swiften/Parser/PayloadParsers/NicknameParser.cpp @@ -4,7 +4,7 @@ * See Documentation/Licenses/GPLv3.txt for more information. */ -#include "Swiften/Parser/PayloadParsers/NicknameParser.h" +#include <Swiften/Parser/PayloadParsers/NicknameParser.h> namespace Swift { diff --git a/Swiften/Parser/PayloadParsers/NicknameParser.h b/Swiften/Parser/PayloadParsers/NicknameParser.h index 6e723c8..a89f835 100644 --- a/Swiften/Parser/PayloadParsers/NicknameParser.h +++ b/Swiften/Parser/PayloadParsers/NicknameParser.h @@ -6,8 +6,8 @@ #pragma once -#include "Swiften/Elements/Nickname.h" -#include "Swiften/Parser/GenericPayloadParser.h" +#include <Swiften/Elements/Nickname.h> +#include <Swiften/Parser/GenericPayloadParser.h> namespace Swift { class NicknameParser : public GenericPayloadParser<Nickname> { diff --git a/Swiften/Parser/PayloadParsers/NicknameParserFactory.h b/Swiften/Parser/PayloadParsers/NicknameParserFactory.h index ce2ebdd..b292513 100644 --- a/Swiften/Parser/PayloadParsers/NicknameParserFactory.h +++ b/Swiften/Parser/PayloadParsers/NicknameParserFactory.h @@ -6,8 +6,8 @@ #pragma once -#include "Swiften/Parser/GenericPayloadParserFactory.h" -#include "Swiften/Parser/PayloadParsers/NicknameParser.h" +#include <Swiften/Parser/GenericPayloadParserFactory.h> +#include <Swiften/Parser/PayloadParsers/NicknameParser.h> namespace Swift { class NicknameParserFactory : public GenericPayloadParserFactory<NicknameParser> { diff --git a/Swiften/Parser/PayloadParsers/PriorityParser.cpp b/Swiften/Parser/PayloadParsers/PriorityParser.cpp index bcbf67f..b440444 100644 --- a/Swiften/Parser/PayloadParsers/PriorityParser.cpp +++ b/Swiften/Parser/PayloadParsers/PriorityParser.cpp @@ -4,7 +4,7 @@ * See Documentation/Licenses/GPLv3.txt for more information. */ -#include "Swiften/Parser/PayloadParsers/PriorityParser.h" +#include <Swiften/Parser/PayloadParsers/PriorityParser.h> #include <boost/lexical_cast.hpp> @@ -24,7 +24,7 @@ void PriorityParser::handleEndElement(const std::string&, const std::string&) { try { priority = boost::lexical_cast<int>(text_); } - catch (boost::bad_lexical_cast& e) { + catch (boost::bad_lexical_cast&) { } getPayloadInternal()->setPriority(priority); } diff --git a/Swiften/Parser/PayloadParsers/PriorityParser.h b/Swiften/Parser/PayloadParsers/PriorityParser.h index 1b02255..dba4770 100644 --- a/Swiften/Parser/PayloadParsers/PriorityParser.h +++ b/Swiften/Parser/PayloadParsers/PriorityParser.h @@ -7,8 +7,8 @@ #ifndef SWIFTEN_PriorityParser_H #define SWIFTEN_PriorityParser_H -#include "Swiften/Elements/Priority.h" -#include "Swiften/Parser/GenericPayloadParser.h" +#include <Swiften/Elements/Priority.h> +#include <Swiften/Parser/GenericPayloadParser.h> namespace Swift { class PriorityParser : public GenericPayloadParser<Priority> { diff --git a/Swiften/Parser/PayloadParsers/PrivateStorageParser.cpp b/Swiften/Parser/PayloadParsers/PrivateStorageParser.cpp index 026da96..b7bcd5d 100644 --- a/Swiften/Parser/PayloadParsers/PrivateStorageParser.cpp +++ b/Swiften/Parser/PayloadParsers/PrivateStorageParser.cpp @@ -4,9 +4,9 @@ * See Documentation/Licenses/GPLv3.txt for more information. */ -#include "Swiften/Parser/PayloadParsers/PrivateStorageParser.h" -#include "Swiften/Parser/PayloadParserFactoryCollection.h" -#include "Swiften/Parser/PayloadParserFactory.h" +#include <Swiften/Parser/PayloadParsers/PrivateStorageParser.h> +#include <Swiften/Parser/PayloadParserFactoryCollection.h> +#include <Swiften/Parser/PayloadParserFactory.h> namespace Swift { diff --git a/Swiften/Parser/PayloadParsers/PrivateStorageParser.h b/Swiften/Parser/PayloadParsers/PrivateStorageParser.h index f5f569a..2f9e003 100644 --- a/Swiften/Parser/PayloadParsers/PrivateStorageParser.h +++ b/Swiften/Parser/PayloadParsers/PrivateStorageParser.h @@ -8,8 +8,8 @@ #include <boost/optional.hpp> -#include "Swiften/Elements/PrivateStorage.h" -#include "Swiften/Parser/GenericPayloadParser.h" +#include <Swiften/Elements/PrivateStorage.h> +#include <Swiften/Parser/GenericPayloadParser.h> namespace Swift { class PayloadParserFactoryCollection; diff --git a/Swiften/Parser/PayloadParsers/PrivateStorageParserFactory.h b/Swiften/Parser/PayloadParsers/PrivateStorageParserFactory.h index 9399ace..5b93aef 100644 --- a/Swiften/Parser/PayloadParsers/PrivateStorageParserFactory.h +++ b/Swiften/Parser/PayloadParsers/PrivateStorageParserFactory.h @@ -6,8 +6,8 @@ #pragma once -#include "Swiften/Parser/PayloadParserFactory.h" -#include "Swiften/Parser/PayloadParsers/PrivateStorageParser.h" +#include <Swiften/Parser/PayloadParserFactory.h> +#include <Swiften/Parser/PayloadParsers/PrivateStorageParser.h> namespace Swift { class PayloadParserFactoryCollection; diff --git a/Swiften/Parser/PayloadParsers/RawXMLPayloadParser.cpp b/Swiften/Parser/PayloadParsers/RawXMLPayloadParser.cpp index bc9b843..0837ae8 100644 --- a/Swiften/Parser/PayloadParsers/RawXMLPayloadParser.cpp +++ b/Swiften/Parser/PayloadParsers/RawXMLPayloadParser.cpp @@ -4,8 +4,8 @@ * See Documentation/Licenses/GPLv3.txt for more information. */ -#include "Swiften/Parser/PayloadParsers/RawXMLPayloadParser.h" -#include "Swiften/Parser/SerializingParser.h" +#include <Swiften/Parser/PayloadParsers/RawXMLPayloadParser.h> +#include <Swiften/Parser/SerializingParser.h> namespace Swift { diff --git a/Swiften/Parser/PayloadParsers/RawXMLPayloadParser.h b/Swiften/Parser/PayloadParsers/RawXMLPayloadParser.h index b5c887a..4a027a1 100644 --- a/Swiften/Parser/PayloadParsers/RawXMLPayloadParser.h +++ b/Swiften/Parser/PayloadParsers/RawXMLPayloadParser.h @@ -6,9 +6,9 @@ #pragma once -#include "Swiften/Elements/RawXMLPayload.h" -#include "Swiften/Parser/GenericPayloadParser.h" -#include "Swiften/Parser/SerializingParser.h" +#include <Swiften/Elements/RawXMLPayload.h> +#include <Swiften/Parser/GenericPayloadParser.h> +#include <Swiften/Parser/SerializingParser.h> namespace Swift { class SerializingParser; diff --git a/Swiften/Parser/PayloadParsers/RawXMLPayloadParserFactory.h b/Swiften/Parser/PayloadParsers/RawXMLPayloadParserFactory.h index b180e1e..d777caa 100644 --- a/Swiften/Parser/PayloadParsers/RawXMLPayloadParserFactory.h +++ b/Swiften/Parser/PayloadParsers/RawXMLPayloadParserFactory.h @@ -6,8 +6,8 @@ #pragma once -#include "Swiften/Parser/PayloadParserFactory.h" -#include "Swiften/Parser/PayloadParsers/RawXMLPayloadParser.h" +#include <Swiften/Parser/PayloadParserFactory.h> +#include <Swiften/Parser/PayloadParsers/RawXMLPayloadParser.h> #include <string> namespace Swift { diff --git a/Swiften/Parser/PayloadParsers/ReplaceParser.cpp b/Swiften/Parser/PayloadParsers/ReplaceParser.cpp new file mode 100644 index 0000000..fb85fbd --- /dev/null +++ b/Swiften/Parser/PayloadParsers/ReplaceParser.cpp @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2011 Vlad Voicu + * Licensed under the Simplified BSD license. + * See Documentation/Licenses/BSD-simplified.txt for more information. + */ + +#include <Swiften/Parser/PayloadParsers/ReplaceParser.h> + +namespace Swift { + + ReplaceParser::ReplaceParser() : level_(0) { + } + + void ReplaceParser::handleStartElement(const std::string&, const std::string&, const AttributeMap& attributes) { + if (level_ == 0) { + std::string id = attributes.getAttribute("id"); + getPayloadInternal()->setID(id); + } + level_++; + } + + void ReplaceParser::handleEndElement(const std::string&, const std::string&) { + --level_; + } + + void ReplaceParser::handleCharacterData(const std::string&) { + } + +} diff --git a/Swiften/Parser/PayloadParsers/ReplaceParser.h b/Swiften/Parser/PayloadParsers/ReplaceParser.h new file mode 100644 index 0000000..4d73459 --- /dev/null +++ b/Swiften/Parser/PayloadParsers/ReplaceParser.h @@ -0,0 +1,23 @@ +/* + * Copyright (c) 2011 Vlad Voicu + * Licensed under the Simplified BSD license. + * See Documentation/Licenses/BSD-simplified.txt for more information. + */ + +#pragma once + +#include <Swiften/Elements/Replace.h> +#include <Swiften/Parser/GenericPayloadParser.h> + +namespace Swift { + class ReplaceParser : public GenericPayloadParser<Replace> { + public: + ReplaceParser(); + virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes); + virtual void handleEndElement(const std::string& element, const std::string&); + virtual void handleCharacterData(const std::string& data); + + private: + int level_; + }; +} diff --git a/Swiften/Parser/PayloadParsers/ResourceBindParser.cpp b/Swiften/Parser/PayloadParsers/ResourceBindParser.cpp index 5c3affb..81378df 100644 --- a/Swiften/Parser/PayloadParsers/ResourceBindParser.cpp +++ b/Swiften/Parser/PayloadParsers/ResourceBindParser.cpp @@ -4,7 +4,7 @@ * See Documentation/Licenses/GPLv3.txt for more information. */ -#include "Swiften/Parser/PayloadParsers/ResourceBindParser.h" +#include <Swiften/Parser/PayloadParsers/ResourceBindParser.h> namespace Swift { diff --git a/Swiften/Parser/PayloadParsers/ResourceBindParser.h b/Swiften/Parser/PayloadParsers/ResourceBindParser.h index 875b5f4..0984867 100644 --- a/Swiften/Parser/PayloadParsers/ResourceBindParser.h +++ b/Swiften/Parser/PayloadParsers/ResourceBindParser.h @@ -7,8 +7,8 @@ #ifndef SWIFTEN_ResourceBindParser_H #define SWIFTEN_ResourceBindParser_H -#include "Swiften/Elements/ResourceBind.h" -#include "Swiften/Parser/GenericPayloadParser.h" +#include <Swiften/Elements/ResourceBind.h> +#include <Swiften/Parser/GenericPayloadParser.h> namespace Swift { class ResourceBindParser : public GenericPayloadParser<ResourceBind> { diff --git a/Swiften/Parser/PayloadParsers/RosterItemExchangeParser.cpp b/Swiften/Parser/PayloadParsers/RosterItemExchangeParser.cpp new file mode 100644 index 0000000..32be2c7 --- /dev/null +++ b/Swiften/Parser/PayloadParsers/RosterItemExchangeParser.cpp @@ -0,0 +1,68 @@ +/* + * Copyright (c) 2011 Jan Kaluza + * Licensed under the Simplified BSD license. + * See Documentation/Licenses/BSD-simplified.txt for more information. + */ + +#include <Swiften/Parser/PayloadParsers/RosterItemExchangeParser.h> +#include <Swiften/Parser/SerializingParser.h> + +namespace Swift { + +RosterItemExchangeParser::RosterItemExchangeParser() : level_(TopLevel), inItem_(false) { +} + +void RosterItemExchangeParser::handleStartElement(const std::string& element, const std::string& /*ns*/, const AttributeMap& attributes) { + if (level_ == PayloadLevel) { + if (element == "item") { + inItem_ = true; + + currentItem_ = RosterItemExchangePayload::Item(); + + currentItem_.setJID(JID(attributes.getAttribute("jid"))); + currentItem_.setName(attributes.getAttribute("name")); + + std::string action = attributes.getAttribute("action"); + if (action == "add") { + currentItem_.setAction(RosterItemExchangePayload::Item::Add); + } + else if (action == "modify") { + currentItem_.setAction(RosterItemExchangePayload::Item::Modify); + } + else if (action == "delete") { + currentItem_.setAction(RosterItemExchangePayload::Item::Delete); + } + else { + // Add is default action according to XEP + currentItem_.setAction(RosterItemExchangePayload::Item::Add); + } + } + } + else if (level_ == ItemLevel) { + if (element == "group") { + currentText_ = ""; + } + } + ++level_; +} + +void RosterItemExchangeParser::handleEndElement(const std::string& element, const std::string& /*ns*/) { + --level_; + if (level_ == PayloadLevel) { + if (inItem_) { + getPayloadInternal()->addItem(currentItem_); + inItem_ = false; + } + } + else if (level_ == ItemLevel) { + if (element == "group") { + currentItem_.addGroup(currentText_); + } + } +} + +void RosterItemExchangeParser::handleCharacterData(const std::string& data) { + currentText_ += data; +} + +} diff --git a/Swiften/Parser/PayloadParsers/RosterItemExchangeParser.h b/Swiften/Parser/PayloadParsers/RosterItemExchangeParser.h new file mode 100644 index 0000000..5652b94 --- /dev/null +++ b/Swiften/Parser/PayloadParsers/RosterItemExchangeParser.h @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2011 Jan Kaluza + * Licensed under the Simplified BSD license. + * See Documentation/Licenses/BSD-simplified.txt for more information. + */ + +#pragma once + +#include <Swiften/Elements/RosterItemExchangePayload.h> +#include <Swiften/Parser/GenericPayloadParser.h> + +namespace Swift { + class SerializingParser; + + class RosterItemExchangeParser : public GenericPayloadParser<RosterItemExchangePayload> { + public: + RosterItemExchangeParser(); + + virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes); + virtual void handleEndElement(const std::string& element, const std::string&); + virtual void handleCharacterData(const std::string& data); + + private: + enum Level { + TopLevel = 0, + PayloadLevel = 1, + ItemLevel = 2 + }; + int level_; + bool inItem_; + RosterItemExchangePayload::Item currentItem_; + std::string currentText_; + }; +} diff --git a/Swiften/Parser/PayloadParsers/RosterParser.cpp b/Swiften/Parser/PayloadParsers/RosterParser.cpp index ba19fbf..53c433a 100644 --- a/Swiften/Parser/PayloadParsers/RosterParser.cpp +++ b/Swiften/Parser/PayloadParsers/RosterParser.cpp @@ -4,8 +4,11 @@ * See Documentation/Licenses/GPLv3.txt for more information. */ -#include "Swiften/Parser/PayloadParsers/RosterParser.h" -#include "Swiften/Parser/SerializingParser.h" +#include <Swiften/Parser/PayloadParsers/RosterParser.h> + +#include <boost/optional.hpp> + +#include <Swiften/Parser/SerializingParser.h> namespace Swift { @@ -13,7 +16,13 @@ RosterParser::RosterParser() : level_(TopLevel), inItem_(false), unknownContentP } void RosterParser::handleStartElement(const std::string& element, const std::string& ns, const AttributeMap& attributes) { - if (level_ == PayloadLevel) { + if (level_ == TopLevel) { + boost::optional<std::string> ver = attributes.getAttributeValue("ver"); + if (ver) { + getPayloadInternal()->setVersion(*ver); + } + } + else if (level_ == PayloadLevel) { if (element == "item") { inItem_ = true; currentItem_ = RosterItemPayload(); diff --git a/Swiften/Parser/PayloadParsers/RosterParser.h b/Swiften/Parser/PayloadParsers/RosterParser.h index ac72696..6786a17 100644 --- a/Swiften/Parser/PayloadParsers/RosterParser.h +++ b/Swiften/Parser/PayloadParsers/RosterParser.h @@ -7,8 +7,8 @@ #ifndef SWIFTEN_RosterParser_H #define SWIFTEN_RosterParser_H -#include "Swiften/Elements/RosterPayload.h" -#include "Swiften/Parser/GenericPayloadParser.h" +#include <Swiften/Elements/RosterPayload.h> +#include <Swiften/Parser/GenericPayloadParser.h> namespace Swift { class SerializingParser; diff --git a/Swiften/Parser/PayloadParsers/SearchPayloadParser.cpp b/Swiften/Parser/PayloadParsers/SearchPayloadParser.cpp index 9daf842..f4de503 100644 --- a/Swiften/Parser/PayloadParsers/SearchPayloadParser.cpp +++ b/Swiften/Parser/PayloadParsers/SearchPayloadParser.cpp @@ -4,12 +4,12 @@ * See Documentation/Licenses/GPLv3.txt for more information. */ -#include "Swiften/Parser/PayloadParsers/SearchPayloadParser.h" +#include <Swiften/Parser/PayloadParsers/SearchPayloadParser.h> #include <boost/cast.hpp> -#include "Swiften/Parser/PayloadParsers/FormParserFactory.h" -#include "Swiften/Parser/PayloadParsers/FormParser.h" +#include <Swiften/Parser/PayloadParsers/FormParserFactory.h> +#include <Swiften/Parser/PayloadParsers/FormParser.h> namespace Swift { diff --git a/Swiften/Parser/PayloadParsers/SearchPayloadParser.h b/Swiften/Parser/PayloadParsers/SearchPayloadParser.h index 01441e8..006e0d9 100644 --- a/Swiften/Parser/PayloadParsers/SearchPayloadParser.h +++ b/Swiften/Parser/PayloadParsers/SearchPayloadParser.h @@ -8,8 +8,8 @@ #include <boost/optional.hpp> -#include "Swiften/Elements/SearchPayload.h" -#include "Swiften/Parser/GenericPayloadParser.h" +#include <Swiften/Elements/SearchPayload.h> +#include <Swiften/Parser/GenericPayloadParser.h> namespace Swift { class FormParserFactory; diff --git a/Swiften/Parser/PayloadParsers/SearchPayloadParserFactory.h b/Swiften/Parser/PayloadParsers/SearchPayloadParserFactory.h index 0f8a6c7..5130556 100644 --- a/Swiften/Parser/PayloadParsers/SearchPayloadParserFactory.h +++ b/Swiften/Parser/PayloadParsers/SearchPayloadParserFactory.h @@ -6,8 +6,8 @@ #pragma once -#include "Swiften/Parser/GenericPayloadParserFactory.h" -#include "Swiften/Parser/PayloadParsers/SearchPayloadParser.h" +#include <Swiften/Parser/GenericPayloadParserFactory.h> +#include <Swiften/Parser/PayloadParsers/SearchPayloadParser.h> namespace Swift { class SearchPayloadParserFactory : public GenericPayloadParserFactory<SearchPayloadParser> { diff --git a/Swiften/Parser/PayloadParsers/SecurityLabelParser.cpp b/Swiften/Parser/PayloadParsers/SecurityLabelParser.cpp index b769a47..0b0f104 100644 --- a/Swiften/Parser/PayloadParsers/SecurityLabelParser.cpp +++ b/Swiften/Parser/PayloadParsers/SecurityLabelParser.cpp @@ -4,8 +4,8 @@ * See Documentation/Licenses/GPLv3.txt for more information. */ -#include "Swiften/Parser/PayloadParsers/SecurityLabelParser.h" -#include "Swiften/Parser/SerializingParser.h" +#include <Swiften/Parser/PayloadParsers/SecurityLabelParser.h> +#include <Swiften/Parser/SerializingParser.h> namespace Swift { diff --git a/Swiften/Parser/PayloadParsers/SecurityLabelParser.h b/Swiften/Parser/PayloadParsers/SecurityLabelParser.h index b54c3be..070d185 100644 --- a/Swiften/Parser/PayloadParsers/SecurityLabelParser.h +++ b/Swiften/Parser/PayloadParsers/SecurityLabelParser.h @@ -7,8 +7,8 @@ #ifndef SWIFTEN_SecurityLabelParser_H #define SWIFTEN_SecurityLabelParser_H -#include "Swiften/Elements/SecurityLabel.h" -#include "Swiften/Parser/GenericPayloadParser.h" +#include <Swiften/Elements/SecurityLabel.h> +#include <Swiften/Parser/GenericPayloadParser.h> namespace Swift { class SerializingParser; diff --git a/Swiften/Parser/PayloadParsers/SecurityLabelParserFactory.h b/Swiften/Parser/PayloadParsers/SecurityLabelParserFactory.h index 538d4a1..9d5d86a 100644 --- a/Swiften/Parser/PayloadParsers/SecurityLabelParserFactory.h +++ b/Swiften/Parser/PayloadParsers/SecurityLabelParserFactory.h @@ -7,8 +7,8 @@ #ifndef SWIFTEN_SecurityLabelParserFactory_H #define SWIFTEN_SecurityLabelParserFactory_H -#include "Swiften/Parser/GenericPayloadParserFactory.h" -#include "Swiften/Parser/PayloadParsers/SecurityLabelParser.h" +#include <Swiften/Parser/GenericPayloadParserFactory.h> +#include <Swiften/Parser/PayloadParsers/SecurityLabelParser.h> namespace Swift { class SecurityLabelParserFactory : public GenericPayloadParserFactory<SecurityLabelParser> { diff --git a/Swiften/Parser/PayloadParsers/SecurityLabelsCatalogParser.cpp b/Swiften/Parser/PayloadParsers/SecurityLabelsCatalogParser.cpp index 6a366b3..e90573f 100644 --- a/Swiften/Parser/PayloadParsers/SecurityLabelsCatalogParser.cpp +++ b/Swiften/Parser/PayloadParsers/SecurityLabelsCatalogParser.cpp @@ -4,9 +4,9 @@ * See Documentation/Licenses/GPLv3.txt for more information. */ -#include "Swiften/Parser/PayloadParsers/SecurityLabelsCatalogParser.h" -#include "Swiften/Parser/PayloadParsers/SecurityLabelParserFactory.h" -#include "Swiften/Parser/PayloadParsers/SecurityLabelParser.h" +#include <Swiften/Parser/PayloadParsers/SecurityLabelsCatalogParser.h> +#include <Swiften/Parser/PayloadParsers/SecurityLabelParserFactory.h> +#include <Swiften/Parser/PayloadParsers/SecurityLabelParser.h> namespace Swift { diff --git a/Swiften/Parser/PayloadParsers/SecurityLabelsCatalogParser.h b/Swiften/Parser/PayloadParsers/SecurityLabelsCatalogParser.h index ca422d1..d7a43da 100644 --- a/Swiften/Parser/PayloadParsers/SecurityLabelsCatalogParser.h +++ b/Swiften/Parser/PayloadParsers/SecurityLabelsCatalogParser.h @@ -7,8 +7,8 @@ #ifndef SWIFTEN_SecurityLabelsCatalogParser_H #define SWIFTEN_SecurityLabelsCatalogParser_H -#include "Swiften/Elements/SecurityLabelsCatalog.h" -#include "Swiften/Parser/GenericPayloadParser.h" +#include <Swiften/Elements/SecurityLabelsCatalog.h> +#include <Swiften/Parser/GenericPayloadParser.h> namespace Swift { class SecurityLabelParserFactory; diff --git a/Swiften/Parser/PayloadParsers/SecurityLabelsCatalogParserFactory.h b/Swiften/Parser/PayloadParsers/SecurityLabelsCatalogParserFactory.h index a148d81..718b79c 100644 --- a/Swiften/Parser/PayloadParsers/SecurityLabelsCatalogParserFactory.h +++ b/Swiften/Parser/PayloadParsers/SecurityLabelsCatalogParserFactory.h @@ -7,8 +7,8 @@ #ifndef SWIFTEN_SecurityLabelsCatalogParserFactory_H #define SWIFTEN_SecurityLabelsCatalogParserFactory_H -#include "Swiften/Parser/GenericPayloadParserFactory.h" -#include "Swiften/Parser/PayloadParsers/SecurityLabelsCatalogParser.h" +#include <Swiften/Parser/GenericPayloadParserFactory.h> +#include <Swiften/Parser/PayloadParsers/SecurityLabelsCatalogParser.h> namespace Swift { class SecurityLabelsCatalogParserFactory : public GenericPayloadParserFactory<SecurityLabelsCatalogParser> { diff --git a/Swiften/Parser/PayloadParsers/SoftwareVersionParser.cpp b/Swiften/Parser/PayloadParsers/SoftwareVersionParser.cpp index f8e61c7..b1c3e18 100644 --- a/Swiften/Parser/PayloadParsers/SoftwareVersionParser.cpp +++ b/Swiften/Parser/PayloadParsers/SoftwareVersionParser.cpp @@ -4,7 +4,7 @@ * See Documentation/Licenses/GPLv3.txt for more information. */ -#include "Swiften/Parser/PayloadParsers/SoftwareVersionParser.h" +#include <Swiften/Parser/PayloadParsers/SoftwareVersionParser.h> namespace Swift { diff --git a/Swiften/Parser/PayloadParsers/SoftwareVersionParser.h b/Swiften/Parser/PayloadParsers/SoftwareVersionParser.h index 4272e5a..3e6db05 100644 --- a/Swiften/Parser/PayloadParsers/SoftwareVersionParser.h +++ b/Swiften/Parser/PayloadParsers/SoftwareVersionParser.h @@ -7,8 +7,8 @@ #ifndef SWIFTEN_SoftwareVersionParser_H #define SWIFTEN_SoftwareVersionParser_H -#include "Swiften/Elements/SoftwareVersion.h" -#include "Swiften/Parser/GenericPayloadParser.h" +#include <Swiften/Elements/SoftwareVersion.h> +#include <Swiften/Parser/GenericPayloadParser.h> namespace Swift { class SoftwareVersionParser : public GenericPayloadParser<SoftwareVersion> { diff --git a/Swiften/Parser/PayloadParsers/StartSessionParser.h b/Swiften/Parser/PayloadParsers/StartSessionParser.h index ba6e3c8..3b1a9b0 100644 --- a/Swiften/Parser/PayloadParsers/StartSessionParser.h +++ b/Swiften/Parser/PayloadParsers/StartSessionParser.h @@ -7,8 +7,8 @@ #ifndef SWIFTEN_StartSessionParser_H #define SWIFTEN_StartSessionParser_H -#include "Swiften/Elements/StartSession.h" -#include "Swiften/Parser/GenericPayloadParser.h" +#include <Swiften/Elements/StartSession.h> +#include <Swiften/Parser/GenericPayloadParser.h> namespace Swift { class StartSessionParser : public GenericPayloadParser<StartSession> { diff --git a/Swiften/Parser/PayloadParsers/StatusParser.cpp b/Swiften/Parser/PayloadParsers/StatusParser.cpp index a5d00de..1394d46 100644 --- a/Swiften/Parser/PayloadParsers/StatusParser.cpp +++ b/Swiften/Parser/PayloadParsers/StatusParser.cpp @@ -4,7 +4,7 @@ * See Documentation/Licenses/GPLv3.txt for more information. */ -#include "Swiften/Parser/PayloadParsers/StatusParser.h" +#include <Swiften/Parser/PayloadParsers/StatusParser.h> namespace Swift { diff --git a/Swiften/Parser/PayloadParsers/StatusParser.h b/Swiften/Parser/PayloadParsers/StatusParser.h index 4c6f4ac..c7c9a6d 100644 --- a/Swiften/Parser/PayloadParsers/StatusParser.h +++ b/Swiften/Parser/PayloadParsers/StatusParser.h @@ -7,8 +7,8 @@ #ifndef SWIFTEN_StatusParser_H #define SWIFTEN_StatusParser_H -#include "Swiften/Elements/Status.h" -#include "Swiften/Parser/GenericPayloadParser.h" +#include <Swiften/Elements/Status.h> +#include <Swiften/Parser/GenericPayloadParser.h> namespace Swift { class StatusParser : public GenericPayloadParser<Status> { diff --git a/Swiften/Parser/PayloadParsers/StatusShowParser.cpp b/Swiften/Parser/PayloadParsers/StatusShowParser.cpp index 774f27d..f5814ec 100644 --- a/Swiften/Parser/PayloadParsers/StatusShowParser.cpp +++ b/Swiften/Parser/PayloadParsers/StatusShowParser.cpp @@ -4,7 +4,7 @@ * See Documentation/Licenses/GPLv3.txt for more information. */ -#include "Swiften/Parser/PayloadParsers/StatusShowParser.h" +#include <Swiften/Parser/PayloadParsers/StatusShowParser.h> namespace Swift { diff --git a/Swiften/Parser/PayloadParsers/StatusShowParser.h b/Swiften/Parser/PayloadParsers/StatusShowParser.h index b4100a3..a01337f 100644 --- a/Swiften/Parser/PayloadParsers/StatusShowParser.h +++ b/Swiften/Parser/PayloadParsers/StatusShowParser.h @@ -7,8 +7,8 @@ #ifndef SWIFTEN_StatusShowParser_H #define SWIFTEN_StatusShowParser_H -#include "Swiften/Elements/StatusShow.h" -#include "Swiften/Parser/GenericPayloadParser.h" +#include <Swiften/Elements/StatusShow.h> +#include <Swiften/Parser/GenericPayloadParser.h> namespace Swift { class StatusShowParser : public GenericPayloadParser<StatusShow> { diff --git a/Swiften/Parser/PayloadParsers/StorageParser.cpp b/Swiften/Parser/PayloadParsers/StorageParser.cpp index 94cd0ce..05e24e7 100644 --- a/Swiften/Parser/PayloadParsers/StorageParser.cpp +++ b/Swiften/Parser/PayloadParsers/StorageParser.cpp @@ -4,7 +4,7 @@ * See Documentation/Licenses/GPLv3.txt for more information. */ -#include "Swiften/Parser/PayloadParsers/StorageParser.h" +#include <Swiften/Parser/PayloadParsers/StorageParser.h> #include <cassert> diff --git a/Swiften/Parser/PayloadParsers/StorageParser.h b/Swiften/Parser/PayloadParsers/StorageParser.h index 16fd869..76dce90 100644 --- a/Swiften/Parser/PayloadParsers/StorageParser.h +++ b/Swiften/Parser/PayloadParsers/StorageParser.h @@ -8,8 +8,8 @@ #include <boost/optional.hpp> -#include "Swiften/Elements/Storage.h" -#include "Swiften/Parser/GenericPayloadParser.h" +#include <Swiften/Elements/Storage.h> +#include <Swiften/Parser/GenericPayloadParser.h> namespace Swift { class StorageParser : public GenericPayloadParser<Storage> { diff --git a/Swiften/Parser/PayloadParsers/StreamInitiationParser.cpp b/Swiften/Parser/PayloadParsers/StreamInitiationParser.cpp index 1cf7fcf..9ea8089 100644 --- a/Swiften/Parser/PayloadParsers/StreamInitiationParser.cpp +++ b/Swiften/Parser/PayloadParsers/StreamInitiationParser.cpp @@ -4,14 +4,14 @@ * See Documentation/Licenses/GPLv3.txt for more information. */ -#include "Swiften/Parser/PayloadParsers/StreamInitiationParser.h" +#include <Swiften/Parser/PayloadParsers/StreamInitiationParser.h> #include <boost/lexical_cast.hpp> #include <boost/cast.hpp> -#include "Swiften/Parser/PayloadParsers/FormParserFactory.h" -#include "Swiften/Parser/PayloadParsers/FormParser.h" -#include "Swiften/Base/foreach.h" +#include <Swiften/Parser/PayloadParsers/FormParserFactory.h> +#include <Swiften/Parser/PayloadParsers/FormParser.h> +#include <Swiften/Base/foreach.h> #define FILE_TRANSFER_NS "http://jabber.org/protocol/si/profile/file-transfer" @@ -42,7 +42,7 @@ void StreamInitiationParser::handleStartElement(const std::string& element, cons try { currentFile.size = boost::lexical_cast<int>(attributes.getAttribute("size")); } - catch (boost::bad_lexical_cast& e) { + catch (boost::bad_lexical_cast&) { } } else if (element == "feature" && ns == FEATURE_NEG_NS) { diff --git a/Swiften/Parser/PayloadParsers/StreamInitiationParser.h b/Swiften/Parser/PayloadParsers/StreamInitiationParser.h index 46f5b2f..c2ffd07 100644 --- a/Swiften/Parser/PayloadParsers/StreamInitiationParser.h +++ b/Swiften/Parser/PayloadParsers/StreamInitiationParser.h @@ -8,8 +8,8 @@ #include <boost/optional.hpp> -#include "Swiften/Elements/StreamInitiation.h" -#include "Swiften/Parser/GenericPayloadParser.h" +#include <Swiften/Elements/StreamInitiation.h> +#include <Swiften/Parser/GenericPayloadParser.h> namespace Swift { class FormParserFactory; diff --git a/Swiften/Parser/PayloadParsers/StreamInitiationParserFactory.h b/Swiften/Parser/PayloadParsers/StreamInitiationParserFactory.h index ee5ed09..a75cf37 100644 --- a/Swiften/Parser/PayloadParsers/StreamInitiationParserFactory.h +++ b/Swiften/Parser/PayloadParsers/StreamInitiationParserFactory.h @@ -6,8 +6,8 @@ #pragma once -#include "Swiften/Parser/GenericPayloadParserFactory.h" -#include "Swiften/Parser/PayloadParsers/StreamInitiationParser.h" +#include <Swiften/Parser/GenericPayloadParserFactory.h> +#include <Swiften/Parser/PayloadParsers/StreamInitiationParser.h> namespace Swift { class StreamInitiationParserFactory : public GenericPayloadParserFactory<StreamInitiationParser> { diff --git a/Swiften/Parser/PayloadParsers/SubjectParser.cpp b/Swiften/Parser/PayloadParsers/SubjectParser.cpp index d7d9af8..276a05a 100644 --- a/Swiften/Parser/PayloadParsers/SubjectParser.cpp +++ b/Swiften/Parser/PayloadParsers/SubjectParser.cpp @@ -4,7 +4,7 @@ * See Documentation/Licenses/GPLv3.txt for more information. */ -#include "Swiften/Parser/PayloadParsers/SubjectParser.h" +#include <Swiften/Parser/PayloadParsers/SubjectParser.h> namespace Swift { diff --git a/Swiften/Parser/PayloadParsers/SubjectParser.h b/Swiften/Parser/PayloadParsers/SubjectParser.h index 78e5a9e..1d7d2ce 100644 --- a/Swiften/Parser/PayloadParsers/SubjectParser.h +++ b/Swiften/Parser/PayloadParsers/SubjectParser.h @@ -6,8 +6,8 @@ #pragma once -#include "Swiften/Elements/Subject.h" -#include "Swiften/Parser/GenericPayloadParser.h" +#include <Swiften/Elements/Subject.h> +#include <Swiften/Parser/GenericPayloadParser.h> namespace Swift { class SubjectParser : public GenericPayloadParser<Subject> { diff --git a/Swiften/Parser/PayloadParsers/UnitTest/BodyParserTest.cpp b/Swiften/Parser/PayloadParsers/UnitTest/BodyParserTest.cpp index bb53586..fe91088 100644 --- a/Swiften/Parser/PayloadParsers/UnitTest/BodyParserTest.cpp +++ b/Swiften/Parser/PayloadParsers/UnitTest/BodyParserTest.cpp @@ -7,8 +7,8 @@ #include <cppunit/extensions/HelperMacros.h> #include <cppunit/extensions/TestFactoryRegistry.h> -#include "Swiften/Parser/PayloadParsers/BodyParser.h" -#include "Swiften/Parser/PayloadParsers/UnitTest/PayloadsParserTester.h" +#include <Swiften/Parser/PayloadParsers/BodyParser.h> +#include <Swiften/Parser/PayloadParsers/UnitTest/PayloadsParserTester.h> using namespace Swift; diff --git a/Swiften/Parser/PayloadParsers/UnitTest/CommandParserTest.cpp b/Swiften/Parser/PayloadParsers/UnitTest/CommandParserTest.cpp index 7ebcbac..3e4971b 100644 --- a/Swiften/Parser/PayloadParsers/UnitTest/CommandParserTest.cpp +++ b/Swiften/Parser/PayloadParsers/UnitTest/CommandParserTest.cpp @@ -7,8 +7,8 @@ #include <cppunit/extensions/HelperMacros.h> #include <cppunit/extensions/TestFactoryRegistry.h> -#include "Swiften/Parser/PayloadParsers/UnitTest/PayloadsParserTester.h" -#include "Swiften/Elements/Command.h" +#include <Swiften/Parser/PayloadParsers/UnitTest/PayloadsParserTester.h> +#include <Swiften/Elements/Command.h> using namespace Swift; diff --git a/Swiften/Parser/PayloadParsers/UnitTest/DiscoInfoParserTest.cpp b/Swiften/Parser/PayloadParsers/UnitTest/DiscoInfoParserTest.cpp index 793e0c2..bfbc312 100644 --- a/Swiften/Parser/PayloadParsers/UnitTest/DiscoInfoParserTest.cpp +++ b/Swiften/Parser/PayloadParsers/UnitTest/DiscoInfoParserTest.cpp @@ -7,8 +7,8 @@ #include <cppunit/extensions/HelperMacros.h> #include <cppunit/extensions/TestFactoryRegistry.h> -#include "Swiften/Parser/PayloadParsers/DiscoInfoParser.h" -#include "Swiften/Parser/PayloadParsers/UnitTest/PayloadsParserTester.h" +#include <Swiften/Parser/PayloadParsers/DiscoInfoParser.h> +#include <Swiften/Parser/PayloadParsers/UnitTest/PayloadsParserTester.h> using namespace Swift; diff --git a/Swiften/Parser/PayloadParsers/UnitTest/ErrorParserTest.cpp b/Swiften/Parser/PayloadParsers/UnitTest/ErrorParserTest.cpp index 02c2f7d..dd3d167 100644 --- a/Swiften/Parser/PayloadParsers/UnitTest/ErrorParserTest.cpp +++ b/Swiften/Parser/PayloadParsers/UnitTest/ErrorParserTest.cpp @@ -7,8 +7,8 @@ #include <cppunit/extensions/HelperMacros.h> #include <cppunit/extensions/TestFactoryRegistry.h> -#include "Swiften/Parser/PayloadParsers/ErrorParser.h" -#include "Swiften/Parser/PayloadParsers/UnitTest/PayloadsParserTester.h" +#include <Swiften/Parser/PayloadParsers/ErrorParser.h> +#include <Swiften/Parser/PayloadParsers/UnitTest/PayloadsParserTester.h> using namespace Swift; diff --git a/Swiften/Parser/PayloadParsers/UnitTest/FormParserTest.cpp b/Swiften/Parser/PayloadParsers/UnitTest/FormParserTest.cpp index 6ec825b..86845be 100644 --- a/Swiften/Parser/PayloadParsers/UnitTest/FormParserTest.cpp +++ b/Swiften/Parser/PayloadParsers/UnitTest/FormParserTest.cpp @@ -7,8 +7,8 @@ #include <cppunit/extensions/HelperMacros.h> #include <cppunit/extensions/TestFactoryRegistry.h> -#include "Swiften/Parser/PayloadParsers/UnitTest/PayloadsParserTester.h" -#include "Swiften/Elements/Form.h" +#include <Swiften/Parser/PayloadParsers/UnitTest/PayloadsParserTester.h> +#include <Swiften/Elements/Form.h> using namespace Swift; @@ -77,7 +77,6 @@ class FormParserTest : public CppUnit::TestFixture { "</field>" "<field var=\"untyped\">" "<value>foo</value>" - "<value>baz</value>" "</field>" "</x>")); @@ -114,8 +113,7 @@ class FormParserTest : public CppUnit::TestFixture { CPPUNIT_ASSERT_EQUAL(JID("baz@fum.org"), boost::dynamic_pointer_cast<JIDMultiFormField>(payload->getFields()[8])->getValue()[1]); CPPUNIT_ASSERT_EQUAL(std::string("Tell all your friends about your new bot!"), payload->getFields()[8]->getDescription()); - CPPUNIT_ASSERT_EQUAL(std::string("foo"), boost::dynamic_pointer_cast<UntypedFormField>(payload->getFields()[9])->getValue()[0]); - CPPUNIT_ASSERT_EQUAL(std::string("baz"), boost::dynamic_pointer_cast<UntypedFormField>(payload->getFields()[9])->getValue()[1]); + CPPUNIT_ASSERT_EQUAL(std::string("foo"), boost::dynamic_pointer_cast<TextSingleFormField>(payload->getFields()[9])->getValue()); } }; diff --git a/Swiften/Parser/PayloadParsers/UnitTest/IBBParserTest.cpp b/Swiften/Parser/PayloadParsers/UnitTest/IBBParserTest.cpp index b4229f2..774ded3 100644 --- a/Swiften/Parser/PayloadParsers/UnitTest/IBBParserTest.cpp +++ b/Swiften/Parser/PayloadParsers/UnitTest/IBBParserTest.cpp @@ -4,13 +4,13 @@ * See Documentation/Licenses/GPLv3.txt for more information. */ -#include "Swiften/Base/ByteArray.h" +#include <Swiften/Base/ByteArray.h> #include <cppunit/extensions/HelperMacros.h> #include <cppunit/extensions/TestFactoryRegistry.h> -#include "Swiften/Parser/PayloadParsers/UnitTest/PayloadsParserTester.h" -#include "Swiften/Elements/IBB.h" +#include <Swiften/Parser/PayloadParsers/UnitTest/PayloadsParserTester.h> +#include <Swiften/Elements/IBB.h> using namespace Swift; @@ -32,7 +32,7 @@ class IBBParserTest : public CppUnit::TestFixture { IBB::ref ibb = parser.getPayload<IBB>(); CPPUNIT_ASSERT(ibb->getAction() == IBB::Data); - CPPUNIT_ASSERT_EQUAL(ByteArray("abcdefgihjklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890\x0a"), ibb->getData()); + CPPUNIT_ASSERT(ByteArray::create("abcdefgihjklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890\x0a") == ibb->getData()); CPPUNIT_ASSERT_EQUAL(4, ibb->getSequenceNumber()); } }; diff --git a/Swiften/Parser/PayloadParsers/UnitTest/PayloadParserTester.h b/Swiften/Parser/PayloadParsers/UnitTest/PayloadParserTester.h index 32fc56c..b0f68ab 100644 --- a/Swiften/Parser/PayloadParsers/UnitTest/PayloadParserTester.h +++ b/Swiften/Parser/PayloadParsers/UnitTest/PayloadParserTester.h @@ -6,8 +6,8 @@ #pragma once -#include "Swiften/Parser/UnitTest/ParserTester.h" -#include "Swiften/Parser/PayloadParser.h" +#include <Swiften/Parser/UnitTest/ParserTester.h> +#include <Swiften/Parser/PayloadParser.h> namespace Swift { typedef ParserTester<PayloadParser> PayloadParserTester; diff --git a/Swiften/Parser/PayloadParsers/UnitTest/PayloadsParserTester.h b/Swiften/Parser/PayloadParsers/UnitTest/PayloadsParserTester.h index 2c88955..2825857 100644 --- a/Swiften/Parser/PayloadParsers/UnitTest/PayloadsParserTester.h +++ b/Swiften/Parser/PayloadParsers/UnitTest/PayloadsParserTester.h @@ -8,12 +8,12 @@ #include <cppunit/extensions/HelperMacros.h> -#include "Swiften/Parser/PayloadParsers/FullPayloadParserFactoryCollection.h" -#include "Swiften/Parser/XMLParser.h" -#include "Swiften/Parser/XMLParserClient.h" -#include "Swiften/Parser/PlatformXMLParserFactory.h" -#include "Swiften/Elements/Payload.h" -#include "Swiften/Parser/PayloadParser.h" +#include <Swiften/Parser/PayloadParsers/FullPayloadParserFactoryCollection.h> +#include <Swiften/Parser/XMLParser.h> +#include <Swiften/Parser/XMLParserClient.h> +#include <Swiften/Parser/PlatformXMLParserFactory.h> +#include <Swiften/Elements/Payload.h> +#include <Swiften/Parser/PayloadParser.h> namespace Swift { class PayloadsParserTester : public XMLParserClient { diff --git a/Swiften/Parser/PayloadParsers/UnitTest/PriorityParserTest.cpp b/Swiften/Parser/PayloadParsers/UnitTest/PriorityParserTest.cpp index 68a2e4f..0974aec 100644 --- a/Swiften/Parser/PayloadParsers/UnitTest/PriorityParserTest.cpp +++ b/Swiften/Parser/PayloadParsers/UnitTest/PriorityParserTest.cpp @@ -7,8 +7,8 @@ #include <cppunit/extensions/HelperMacros.h> #include <cppunit/extensions/TestFactoryRegistry.h> -#include "Swiften/Parser/PayloadParsers/PriorityParser.h" -#include "Swiften/Parser/PayloadParsers/UnitTest/PayloadsParserTester.h" +#include <Swiften/Parser/PayloadParsers/PriorityParser.h> +#include <Swiften/Parser/PayloadParsers/UnitTest/PayloadsParserTester.h> using namespace Swift; @@ -24,7 +24,7 @@ class PriorityParserTest : public CppUnit::TestFixture { CPPUNIT_ASSERT(parser.parse("<priority>-120</priority>")); - Priority::ref payload = boost::dynamic_pointer_cast<Priority>(parser.getPayload()); + boost::shared_ptr<Priority> payload = boost::dynamic_pointer_cast<Priority>(parser.getPayload()); CPPUNIT_ASSERT_EQUAL(-120, payload->getPriority()); } @@ -33,7 +33,7 @@ class PriorityParserTest : public CppUnit::TestFixture { CPPUNIT_ASSERT(parser.parse("<priority>invalid</priority>")); - Priority::ref payload = boost::dynamic_pointer_cast<Priority>(parser.getPayload()); + boost::shared_ptr<Priority> payload = boost::dynamic_pointer_cast<Priority>(parser.getPayload()); CPPUNIT_ASSERT_EQUAL(0, payload->getPriority()); } }; diff --git a/Swiften/Parser/PayloadParsers/UnitTest/PrivateStorageParserTest.cpp b/Swiften/Parser/PayloadParsers/UnitTest/PrivateStorageParserTest.cpp index 867b25f..ef6ed9a 100644 --- a/Swiften/Parser/PayloadParsers/UnitTest/PrivateStorageParserTest.cpp +++ b/Swiften/Parser/PayloadParsers/UnitTest/PrivateStorageParserTest.cpp @@ -7,10 +7,10 @@ #include <cppunit/extensions/HelperMacros.h> #include <cppunit/extensions/TestFactoryRegistry.h> -#include "Swiften/Elements/Storage.h" -#include "Swiften/Parser/PayloadParsers/PrivateStorageParser.h" -#include "Swiften/Parser/PayloadParsers/UnitTest/PayloadsParserTester.h" -#include "Swiften/Parser/PayloadParsers/UnitTest/PayloadParserTester.h" +#include <Swiften/Elements/Storage.h> +#include <Swiften/Parser/PayloadParsers/PrivateStorageParser.h> +#include <Swiften/Parser/PayloadParsers/UnitTest/PayloadsParserTester.h> +#include <Swiften/Parser/PayloadParsers/UnitTest/PayloadParserTester.h> using namespace Swift; diff --git a/Swiften/Parser/PayloadParsers/UnitTest/RawXMLPayloadParserTest.cpp b/Swiften/Parser/PayloadParsers/UnitTest/RawXMLPayloadParserTest.cpp index 8885974..4862584 100644 --- a/Swiften/Parser/PayloadParsers/UnitTest/RawXMLPayloadParserTest.cpp +++ b/Swiften/Parser/PayloadParsers/UnitTest/RawXMLPayloadParserTest.cpp @@ -7,8 +7,8 @@ #include <cppunit/extensions/HelperMacros.h> #include <cppunit/extensions/TestFactoryRegistry.h> -#include "Swiften/Parser/PayloadParsers/RawXMLPayloadParser.h" -#include "Swiften/Parser/PayloadParsers/UnitTest/PayloadParserTester.h" +#include <Swiften/Parser/PayloadParsers/RawXMLPayloadParser.h> +#include <Swiften/Parser/PayloadParsers/UnitTest/PayloadParserTester.h> using namespace Swift; diff --git a/Swiften/Parser/PayloadParsers/UnitTest/ReplaceTest.cpp b/Swiften/Parser/PayloadParsers/UnitTest/ReplaceTest.cpp new file mode 100644 index 0000000..c3f410f --- /dev/null +++ b/Swiften/Parser/PayloadParsers/UnitTest/ReplaceTest.cpp @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2011 Vlad Voicu + * Licensed under the Simplified BSD license. + * See Documentation/Licenses/BSD-simplified.txt for more information. + */ + +#include <cppunit/extensions/HelperMacros.h> +#include <cppunit/extensions/TestFactoryRegistry.h> + +#include <Swiften/Parser/PayloadParsers/ReplaceParser.h> +#include <Swiften/Parser/PayloadParsers/UnitTest/PayloadsParserTester.h> + +using namespace Swift; + +class ReplaceParserTest : public CppUnit::TestFixture { + CPPUNIT_TEST_SUITE(ReplaceParserTest); + CPPUNIT_TEST(testParseTrivial); + CPPUNIT_TEST(testParseChild); + CPPUNIT_TEST_SUITE_END(); + + public: + void testParseTrivial() { + PayloadsParserTester parser; + CPPUNIT_ASSERT(parser.parse("<replace id='bad1' xmlns='http://swift.im/protocol/replace'/>")); + Replace::ref payload = boost::dynamic_pointer_cast <Replace>(parser.getPayload()); + CPPUNIT_ASSERT_EQUAL(std::string("bad1"), payload->getID()); + } + void testParseChild() { + PayloadsParserTester parser; + CPPUNIT_ASSERT(parser.parse("<replace id='bad1' xmlns='http://swift.im/protocol/replace' ><child xmlns='blah' id=\"hi\"/></replace>")); + Replace::ref payload = boost::dynamic_pointer_cast <Replace>(parser.getPayload()); + CPPUNIT_ASSERT_EQUAL(std::string("bad1"), payload->getID()); + } +}; + +CPPUNIT_TEST_SUITE_REGISTRATION(ReplaceParserTest); diff --git a/Swiften/Parser/PayloadParsers/UnitTest/ResourceBindParserTest.cpp b/Swiften/Parser/PayloadParsers/UnitTest/ResourceBindParserTest.cpp index 026ef2c..663a81c 100644 --- a/Swiften/Parser/PayloadParsers/UnitTest/ResourceBindParserTest.cpp +++ b/Swiften/Parser/PayloadParsers/UnitTest/ResourceBindParserTest.cpp @@ -7,8 +7,8 @@ #include <cppunit/extensions/HelperMacros.h> #include <cppunit/extensions/TestFactoryRegistry.h> -#include "Swiften/Parser/PayloadParsers/ResourceBindParser.h" -#include "Swiften/Parser/PayloadParsers/UnitTest/PayloadsParserTester.h" +#include <Swiften/Parser/PayloadParsers/ResourceBindParser.h> +#include <Swiften/Parser/PayloadParsers/UnitTest/PayloadsParserTester.h> using namespace Swift; diff --git a/Swiften/Parser/PayloadParsers/UnitTest/RosterItemExchangeParserTest.cpp b/Swiften/Parser/PayloadParsers/UnitTest/RosterItemExchangeParserTest.cpp new file mode 100644 index 0000000..1a18d6d --- /dev/null +++ b/Swiften/Parser/PayloadParsers/UnitTest/RosterItemExchangeParserTest.cpp @@ -0,0 +1,52 @@ +/* + * Copyright (c) 2011 Jan Kaluza + * Licensed under the Simplified BSD license. + * See Documentation/Licenses/BSD-simplified.txt for more information. + */ + +#include <cppunit/extensions/HelperMacros.h> +#include <cppunit/extensions/TestFactoryRegistry.h> + +#include <Swiften/Parser/PayloadParsers/RosterItemExchangeParser.h> +#include <Swiften/Parser/PayloadParsers/UnitTest/PayloadsParserTester.h> + +using namespace Swift; + +class RosterItemExchangeParserTest : public CppUnit::TestFixture +{ + CPPUNIT_TEST_SUITE(RosterItemExchangeParserTest); + CPPUNIT_TEST(testParse); + CPPUNIT_TEST_SUITE_END(); + + public: + void testParse() { + PayloadsParserTester parser; + CPPUNIT_ASSERT(parser.parse( + "<x xmlns=\"http://jabber.org/protocol/rosterx\">" + "<item action=\"add\" jid=\"foo@bar.com\" name=\"Foo @ Bar\">" + "<group>Group 1</group>" + "<group>Group 2</group>" + "</item>" + "<item action=\"modify\" jid=\"baz@blo.com\" name=\"Baz\"/>" + "</x>")); + + RosterItemExchangePayload* payload = dynamic_cast<RosterItemExchangePayload*>(parser.getPayload().get()); + const RosterItemExchangePayload::RosterItemExchangePayloadItems& items = payload->getItems(); + + CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(2), items.size()); + + CPPUNIT_ASSERT_EQUAL(JID("foo@bar.com"), items[0].getJID()); + CPPUNIT_ASSERT_EQUAL(std::string("Foo @ Bar"), items[0].getName()); + CPPUNIT_ASSERT_EQUAL(RosterItemExchangePayload::Item::Add, items[0].getAction()); + CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(2), items[0].getGroups().size()); + CPPUNIT_ASSERT_EQUAL(std::string("Group 1"), items[0].getGroups()[0]); + CPPUNIT_ASSERT_EQUAL(std::string("Group 2"), items[0].getGroups()[1]); + + CPPUNIT_ASSERT_EQUAL(JID("baz@blo.com"), items[1].getJID()); + CPPUNIT_ASSERT_EQUAL(std::string("Baz"), items[1].getName()); + CPPUNIT_ASSERT_EQUAL(RosterItemExchangePayload::Item::Modify, items[1].getAction()); + CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(0), items[1].getGroups().size()); + } +}; + +CPPUNIT_TEST_SUITE_REGISTRATION(RosterItemExchangeParserTest); diff --git a/Swiften/Parser/PayloadParsers/UnitTest/RosterParserTest.cpp b/Swiften/Parser/PayloadParsers/UnitTest/RosterParserTest.cpp index 1bcea0e..6cb5dbc 100644 --- a/Swiften/Parser/PayloadParsers/UnitTest/RosterParserTest.cpp +++ b/Swiften/Parser/PayloadParsers/UnitTest/RosterParserTest.cpp @@ -7,8 +7,8 @@ #include <cppunit/extensions/HelperMacros.h> #include <cppunit/extensions/TestFactoryRegistry.h> -#include "Swiften/Parser/PayloadParsers/RosterParser.h" -#include "Swiften/Parser/PayloadParsers/UnitTest/PayloadsParserTester.h" +#include <Swiften/Parser/PayloadParsers/RosterParser.h> +#include <Swiften/Parser/PayloadParsers/UnitTest/PayloadsParserTester.h> using namespace Swift; @@ -17,6 +17,8 @@ class RosterParserTest : public CppUnit::TestFixture CPPUNIT_TEST_SUITE(RosterParserTest); CPPUNIT_TEST(testParse); CPPUNIT_TEST(testParse_ItemWithUnknownContent); + CPPUNIT_TEST(testParse_WithVersion); + CPPUNIT_TEST(testParse_WithEmptyVersion); CPPUNIT_TEST_SUITE_END(); public: @@ -32,6 +34,8 @@ class RosterParserTest : public CppUnit::TestFixture "</query>")); RosterPayload* payload = dynamic_cast<RosterPayload*>(parser.getPayload().get()); + + CPPUNIT_ASSERT(!payload->getVersion()); const RosterPayload::RosterItemPayloads& items = payload->getItems(); CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(2), items.size()); @@ -74,6 +78,24 @@ class RosterParserTest : public CppUnit::TestFixture "<baz xmlns=\"jabber:iq:roster\"><fum xmlns=\"jabber:iq:roster\">foo</fum></baz>" ), items[0].getUnknownContent()); } + + void testParse_WithVersion() { + PayloadsParserTester parser; + CPPUNIT_ASSERT(parser.parse("<query xmlns='jabber:iq:roster' ver='ver10'/>")); + + RosterPayload* payload = dynamic_cast<RosterPayload*>(parser.getPayload().get()); + CPPUNIT_ASSERT(payload->getVersion()); + CPPUNIT_ASSERT_EQUAL(std::string("ver10"), *payload->getVersion()); + } + + void testParse_WithEmptyVersion() { + PayloadsParserTester parser; + CPPUNIT_ASSERT(parser.parse("<query xmlns='jabber:iq:roster' ver=''/>")); + + RosterPayload* payload = dynamic_cast<RosterPayload*>(parser.getPayload().get()); + CPPUNIT_ASSERT(payload->getVersion()); + CPPUNIT_ASSERT_EQUAL(std::string(""), *payload->getVersion()); + } }; CPPUNIT_TEST_SUITE_REGISTRATION(RosterParserTest); diff --git a/Swiften/Parser/PayloadParsers/UnitTest/SearchPayloadParserTest.cpp b/Swiften/Parser/PayloadParsers/UnitTest/SearchPayloadParserTest.cpp index 3d3bc7b..c07cd7f 100644 --- a/Swiften/Parser/PayloadParsers/UnitTest/SearchPayloadParserTest.cpp +++ b/Swiften/Parser/PayloadParsers/UnitTest/SearchPayloadParserTest.cpp @@ -7,8 +7,8 @@ #include <cppunit/extensions/HelperMacros.h> #include <cppunit/extensions/TestFactoryRegistry.h> -#include "Swiften/Parser/PayloadParsers/UnitTest/PayloadsParserTester.h" -#include "Swiften/Elements/SearchPayload.h" +#include <Swiften/Parser/PayloadParsers/UnitTest/PayloadsParserTester.h> +#include <Swiften/Elements/SearchPayload.h> using namespace Swift; diff --git a/Swiften/Parser/PayloadParsers/UnitTest/SecurityLabelParserTest.cpp b/Swiften/Parser/PayloadParsers/UnitTest/SecurityLabelParserTest.cpp index 0812c6b..5083a07 100644 --- a/Swiften/Parser/PayloadParsers/UnitTest/SecurityLabelParserTest.cpp +++ b/Swiften/Parser/PayloadParsers/UnitTest/SecurityLabelParserTest.cpp @@ -7,8 +7,8 @@ #include <cppunit/extensions/HelperMacros.h> #include <cppunit/extensions/TestFactoryRegistry.h> -#include "Swiften/Parser/PayloadParsers/SecurityLabelParser.h" -#include "Swiften/Parser/PayloadParsers/UnitTest/PayloadsParserTester.h" +#include <Swiften/Parser/PayloadParsers/SecurityLabelParser.h> +#include <Swiften/Parser/PayloadParsers/UnitTest/PayloadsParserTester.h> using namespace Swift; diff --git a/Swiften/Parser/PayloadParsers/UnitTest/SecurityLabelsCatalogParserTest.cpp b/Swiften/Parser/PayloadParsers/UnitTest/SecurityLabelsCatalogParserTest.cpp index e1e8594..395daf5 100644 --- a/Swiften/Parser/PayloadParsers/UnitTest/SecurityLabelsCatalogParserTest.cpp +++ b/Swiften/Parser/PayloadParsers/UnitTest/SecurityLabelsCatalogParserTest.cpp @@ -7,8 +7,8 @@ #include <cppunit/extensions/HelperMacros.h> #include <cppunit/extensions/TestFactoryRegistry.h> -#include "Swiften/Parser/PayloadParsers/SecurityLabelsCatalogParser.h" -#include "Swiften/Parser/PayloadParsers/UnitTest/PayloadsParserTester.h" +#include <Swiften/Parser/PayloadParsers/SecurityLabelsCatalogParser.h> +#include <Swiften/Parser/PayloadParsers/UnitTest/PayloadsParserTester.h> using namespace Swift; diff --git a/Swiften/Parser/PayloadParsers/UnitTest/SoftwareVersionParserTest.cpp b/Swiften/Parser/PayloadParsers/UnitTest/SoftwareVersionParserTest.cpp index 3689f10..d22d207 100644 --- a/Swiften/Parser/PayloadParsers/UnitTest/SoftwareVersionParserTest.cpp +++ b/Swiften/Parser/PayloadParsers/UnitTest/SoftwareVersionParserTest.cpp @@ -7,8 +7,8 @@ #include <cppunit/extensions/HelperMacros.h> #include <cppunit/extensions/TestFactoryRegistry.h> -#include "Swiften/Parser/PayloadParsers/SoftwareVersionParser.h" -#include "Swiften/Parser/PayloadParsers/UnitTest/PayloadsParserTester.h" +#include <Swiften/Parser/PayloadParsers/SoftwareVersionParser.h> +#include <Swiften/Parser/PayloadParsers/UnitTest/PayloadsParserTester.h> using namespace Swift; diff --git a/Swiften/Parser/PayloadParsers/UnitTest/StatusParserTest.cpp b/Swiften/Parser/PayloadParsers/UnitTest/StatusParserTest.cpp index 7791f5f..358ff88 100644 --- a/Swiften/Parser/PayloadParsers/UnitTest/StatusParserTest.cpp +++ b/Swiften/Parser/PayloadParsers/UnitTest/StatusParserTest.cpp @@ -7,8 +7,8 @@ #include <cppunit/extensions/HelperMacros.h> #include <cppunit/extensions/TestFactoryRegistry.h> -#include "Swiften/Parser/PayloadParsers/StatusParser.h" -#include "Swiften/Parser/PayloadParsers/UnitTest/PayloadsParserTester.h" +#include <Swiften/Parser/PayloadParsers/StatusParser.h> +#include <Swiften/Parser/PayloadParsers/UnitTest/PayloadsParserTester.h> using namespace Swift; diff --git a/Swiften/Parser/PayloadParsers/UnitTest/StatusShowParserTest.cpp b/Swiften/Parser/PayloadParsers/UnitTest/StatusShowParserTest.cpp index 17617b4..924a87f 100644 --- a/Swiften/Parser/PayloadParsers/UnitTest/StatusShowParserTest.cpp +++ b/Swiften/Parser/PayloadParsers/UnitTest/StatusShowParserTest.cpp @@ -7,8 +7,8 @@ #include <cppunit/extensions/HelperMacros.h> #include <cppunit/extensions/TestFactoryRegistry.h> -#include "Swiften/Parser/PayloadParsers/StatusShowParser.h" -#include "Swiften/Parser/PayloadParsers/UnitTest/PayloadsParserTester.h" +#include <Swiften/Parser/PayloadParsers/StatusShowParser.h> +#include <Swiften/Parser/PayloadParsers/UnitTest/PayloadsParserTester.h> using namespace Swift; diff --git a/Swiften/Parser/PayloadParsers/UnitTest/StorageParserTest.cpp b/Swiften/Parser/PayloadParsers/UnitTest/StorageParserTest.cpp index 88730b7..4fd8ae5 100644 --- a/Swiften/Parser/PayloadParsers/UnitTest/StorageParserTest.cpp +++ b/Swiften/Parser/PayloadParsers/UnitTest/StorageParserTest.cpp @@ -7,8 +7,8 @@ #include <cppunit/extensions/HelperMacros.h> #include <cppunit/extensions/TestFactoryRegistry.h> -#include "Swiften/Parser/PayloadParsers/StorageParser.h" -#include "Swiften/Parser/PayloadParsers/UnitTest/PayloadsParserTester.h" +#include <Swiften/Parser/PayloadParsers/StorageParser.h> +#include <Swiften/Parser/PayloadParsers/UnitTest/PayloadsParserTester.h> using namespace Swift; diff --git a/Swiften/Parser/PayloadParsers/UnitTest/StreamInitiationParserTest.cpp b/Swiften/Parser/PayloadParsers/UnitTest/StreamInitiationParserTest.cpp index 8001487..47b2816 100644 --- a/Swiften/Parser/PayloadParsers/UnitTest/StreamInitiationParserTest.cpp +++ b/Swiften/Parser/PayloadParsers/UnitTest/StreamInitiationParserTest.cpp @@ -7,8 +7,8 @@ #include <cppunit/extensions/HelperMacros.h> #include <cppunit/extensions/TestFactoryRegistry.h> -#include "Swiften/Parser/PayloadParsers/UnitTest/PayloadsParserTester.h" -#include "Swiften/Elements/StreamInitiation.h" +#include <Swiften/Parser/PayloadParsers/UnitTest/PayloadsParserTester.h> +#include <Swiften/Elements/StreamInitiation.h> using namespace Swift; diff --git a/Swiften/Parser/PayloadParsers/UnitTest/VCardParserTest.cpp b/Swiften/Parser/PayloadParsers/UnitTest/VCardParserTest.cpp index 909401d..f0fca3c 100644 --- a/Swiften/Parser/PayloadParsers/UnitTest/VCardParserTest.cpp +++ b/Swiften/Parser/PayloadParsers/UnitTest/VCardParserTest.cpp @@ -4,13 +4,13 @@ * See Documentation/Licenses/GPLv3.txt for more information. */ -#include "Swiften/Base/ByteArray.h" +#include <Swiften/Base/ByteArray.h> #include <cppunit/extensions/HelperMacros.h> #include <cppunit/extensions/TestFactoryRegistry.h> -#include "Swiften/Parser/PayloadParsers/VCardParser.h" -#include "Swiften/Parser/PayloadParsers/UnitTest/PayloadsParserTester.h" +#include <Swiften/Parser/PayloadParsers/VCardParser.h> +#include <Swiften/Parser/PayloadParsers/UnitTest/PayloadsParserTester.h> using namespace Swift; diff --git a/Swiften/Parser/PayloadParsers/UnitTest/VCardUpdateParserTest.cpp b/Swiften/Parser/PayloadParsers/UnitTest/VCardUpdateParserTest.cpp index b8ea4fb..fe69242 100644 --- a/Swiften/Parser/PayloadParsers/UnitTest/VCardUpdateParserTest.cpp +++ b/Swiften/Parser/PayloadParsers/UnitTest/VCardUpdateParserTest.cpp @@ -7,8 +7,8 @@ #include <cppunit/extensions/HelperMacros.h> #include <cppunit/extensions/TestFactoryRegistry.h> -#include "Swiften/Parser/PayloadParsers/VCardUpdateParser.h" -#include "Swiften/Parser/PayloadParsers/UnitTest/PayloadsParserTester.h" +#include <Swiften/Parser/PayloadParsers/VCardUpdateParser.h> +#include <Swiften/Parser/PayloadParsers/UnitTest/PayloadsParserTester.h> using namespace Swift; diff --git a/Swiften/Parser/PayloadParsers/VCardParser.cpp b/Swiften/Parser/PayloadParsers/VCardParser.cpp index 61af0ba..553d26a 100644 --- a/Swiften/Parser/PayloadParsers/VCardParser.cpp +++ b/Swiften/Parser/PayloadParsers/VCardParser.cpp @@ -4,10 +4,10 @@ * See Documentation/Licenses/GPLv3.txt for more information. */ -#include "Swiften/Parser/PayloadParsers/VCardParser.h" -#include "Swiften/Base/foreach.h" -#include "Swiften/StringCodecs/Base64.h" -#include "Swiften/Parser/SerializingParser.h" +#include <Swiften/Parser/PayloadParsers/VCardParser.h> +#include <Swiften/Base/foreach.h> +#include <Swiften/StringCodecs/Base64.h> +#include <Swiften/Parser/SerializingParser.h> namespace Swift { diff --git a/Swiften/Parser/PayloadParsers/VCardParser.h b/Swiften/Parser/PayloadParsers/VCardParser.h index c858e61..1475277 100644 --- a/Swiften/Parser/PayloadParsers/VCardParser.h +++ b/Swiften/Parser/PayloadParsers/VCardParser.h @@ -6,8 +6,8 @@ #pragma once -#include "Swiften/Elements/VCard.h" -#include "Swiften/Parser/GenericPayloadParser.h" +#include <Swiften/Elements/VCard.h> +#include <Swiften/Parser/GenericPayloadParser.h> namespace Swift { class SerializingParser; diff --git a/Swiften/Parser/PayloadParsers/VCardParserFactory.h b/Swiften/Parser/PayloadParsers/VCardParserFactory.h index 305d42e..8731c55 100644 --- a/Swiften/Parser/PayloadParsers/VCardParserFactory.h +++ b/Swiften/Parser/PayloadParsers/VCardParserFactory.h @@ -6,8 +6,8 @@ #pragma once -#include "Swiften/Parser/GenericPayloadParserFactory.h" -#include "Swiften/Parser/PayloadParsers/VCardParser.h" +#include <Swiften/Parser/GenericPayloadParserFactory.h> +#include <Swiften/Parser/PayloadParsers/VCardParser.h> namespace Swift { class VCardParserFactory : public GenericPayloadParserFactory<VCardParser> { diff --git a/Swiften/Parser/PayloadParsers/VCardUpdateParser.cpp b/Swiften/Parser/PayloadParsers/VCardUpdateParser.cpp index 2218d75..d4703da 100644 --- a/Swiften/Parser/PayloadParsers/VCardUpdateParser.cpp +++ b/Swiften/Parser/PayloadParsers/VCardUpdateParser.cpp @@ -4,7 +4,7 @@ * See Documentation/Licenses/GPLv3.txt for more information. */ -#include "Swiften/Parser/PayloadParsers/VCardUpdateParser.h" +#include <Swiften/Parser/PayloadParsers/VCardUpdateParser.h> namespace Swift { diff --git a/Swiften/Parser/PayloadParsers/VCardUpdateParser.h b/Swiften/Parser/PayloadParsers/VCardUpdateParser.h index b91c17b..4954f0a 100644 --- a/Swiften/Parser/PayloadParsers/VCardUpdateParser.h +++ b/Swiften/Parser/PayloadParsers/VCardUpdateParser.h @@ -6,8 +6,8 @@ #pragma once -#include "Swiften/Elements/VCardUpdate.h" -#include "Swiften/Parser/GenericPayloadParser.h" +#include <Swiften/Elements/VCardUpdate.h> +#include <Swiften/Parser/GenericPayloadParser.h> namespace Swift { class SerializingParser; diff --git a/Swiften/Parser/PayloadParsers/VCardUpdateParserFactory.h b/Swiften/Parser/PayloadParsers/VCardUpdateParserFactory.h index 562f253..8a449fb 100644 --- a/Swiften/Parser/PayloadParsers/VCardUpdateParserFactory.h +++ b/Swiften/Parser/PayloadParsers/VCardUpdateParserFactory.h @@ -6,8 +6,8 @@ #pragma once -#include "Swiften/Parser/GenericPayloadParserFactory.h" -#include "Swiften/Parser/PayloadParsers/VCardUpdateParser.h" +#include <Swiften/Parser/GenericPayloadParserFactory.h> +#include <Swiften/Parser/PayloadParsers/VCardUpdateParser.h> namespace Swift { class VCardUpdateParserFactory : public GenericPayloadParserFactory<VCardUpdateParser> { diff --git a/Swiften/Parser/PlatformXMLParserFactory.cpp b/Swiften/Parser/PlatformXMLParserFactory.cpp index 078e562..18acdc2 100644 --- a/Swiften/Parser/PlatformXMLParserFactory.cpp +++ b/Swiften/Parser/PlatformXMLParserFactory.cpp @@ -4,14 +4,14 @@ * See Documentation/Licenses/GPLv3.txt for more information. */ -#include "Swiften/Parser/PlatformXMLParserFactory.h" +#include <Swiften/Parser/PlatformXMLParserFactory.h> #include <cassert> #ifdef HAVE_LIBXML -#include "Swiften/Parser/LibXMLParser.h" +#include <Swiften/Parser/LibXMLParser.h> #else -#include "Swiften/Parser/ExpatParser.h" +#include <Swiften/Parser/ExpatParser.h> #endif diff --git a/Swiften/Parser/PlatformXMLParserFactory.h b/Swiften/Parser/PlatformXMLParserFactory.h index ea1bfd7..ffd2718 100644 --- a/Swiften/Parser/PlatformXMLParserFactory.h +++ b/Swiften/Parser/PlatformXMLParserFactory.h @@ -7,7 +7,7 @@ #ifndef SWIFTEN_PlatformXMLParserFactory_H #define SWIFTEN_PlatformXMLParserFactory_H -#include "Swiften/Parser/XMLParserFactory.h" +#include <Swiften/Parser/XMLParserFactory.h> namespace Swift { class PlatformXMLParserFactory : public XMLParserFactory { diff --git a/Swiften/Parser/PresenceParser.cpp b/Swiften/Parser/PresenceParser.cpp index 845ccf0..39305c0 100644 --- a/Swiften/Parser/PresenceParser.cpp +++ b/Swiften/Parser/PresenceParser.cpp @@ -5,8 +5,9 @@ */ #include <iostream> +#include <boost/optional.hpp> -#include "Swiften/Parser/PresenceParser.h" +#include <Swiften/Parser/PresenceParser.h> namespace Swift { @@ -15,31 +16,31 @@ PresenceParser::PresenceParser(PayloadParserFactoryCollection* factories) : } void PresenceParser::handleStanzaAttributes(const AttributeMap& attributes) { - AttributeMap::const_iterator type = attributes.find("type"); - if (type != attributes.end()) { - if (type->second == "unavailable") { + boost::optional<std::string> type = attributes.getAttributeValue("type"); + if (type) { + if (*type == "unavailable") { getStanzaGeneric()->setType(Presence::Unavailable); } - else if (type->second == "probe") { + else if (*type == "probe") { getStanzaGeneric()->setType(Presence::Probe); } - else if (type->second == "subscribe") { + else if (*type == "subscribe") { getStanzaGeneric()->setType(Presence::Subscribe); } - else if (type->second == "subscribed") { + else if (*type == "subscribed") { getStanzaGeneric()->setType(Presence::Subscribed); } - else if (type->second == "unsubscribe") { + else if (*type == "unsubscribe") { getStanzaGeneric()->setType(Presence::Unsubscribe); } - else if (type->second == "unsubscribed") { + else if (*type == "unsubscribed") { getStanzaGeneric()->setType(Presence::Unsubscribed); } - else if (type->second == "error") { + else if (*type == "error") { getStanzaGeneric()->setType(Presence::Error); } else { - std::cerr << "Unknown Presence type: " << type->second << std::endl; + std::cerr << "Unknown Presence type: " << *type << std::endl; getStanzaGeneric()->setType(Presence::Available); } } diff --git a/Swiften/Parser/PresenceParser.h b/Swiften/Parser/PresenceParser.h index cfecedf..49a9cbd 100644 --- a/Swiften/Parser/PresenceParser.h +++ b/Swiften/Parser/PresenceParser.h @@ -7,8 +7,8 @@ #ifndef SWIFTEN_PresenceParser_H #define SWIFTEN_PresenceParser_H -#include "Swiften/Parser/GenericStanzaParser.h" -#include "Swiften/Elements/Presence.h" +#include <Swiften/Parser/GenericStanzaParser.h> +#include <Swiften/Elements/Presence.h> namespace Swift { class PresenceParser : public GenericStanzaParser<Presence> { diff --git a/Swiften/Parser/SConscript b/Swiften/Parser/SConscript index cbb2190..d9915ed 100644 --- a/Swiften/Parser/SConscript +++ b/Swiften/Parser/SConscript @@ -6,6 +6,7 @@ myenv.MergeFlags(swiften_env.get("LIBXML_FLAGS", "")) myenv.MergeFlags(swiften_env.get("EXPAT_FLAGS", "")) sources = [ + "AttributeMap.cpp", "AuthRequestParser.cpp", "AuthChallengeParser.cpp", "AuthSuccessParser.cpp", @@ -37,6 +38,7 @@ sources = [ "PayloadParsers/PrivateStorageParser.cpp", "PayloadParsers/RawXMLPayloadParser.cpp", "PayloadParsers/ResourceBindParser.cpp", + "PayloadParsers/RosterItemExchangeParser.cpp", "PayloadParsers/RosterParser.cpp", "PayloadParsers/SecurityLabelParser.cpp", "PayloadParsers/SecurityLabelsCatalogParser.cpp", @@ -51,12 +53,15 @@ sources = [ "PayloadParsers/DelayParser.cpp", "PayloadParsers/MUCUserPayloadParser.cpp", "PayloadParsers/NicknameParser.cpp", + "PayloadParsers/ReplaceParser.cpp", "PlatformXMLParserFactory.cpp", "PresenceParser.cpp", "SerializingParser.cpp", "StanzaParser.cpp", "StreamErrorParser.cpp", "StreamFeaturesParser.cpp", + "StreamManagementEnabledParser.cpp", + "StreamResumeParser.cpp", "XMLParser.cpp", "XMLParserClient.cpp", "XMLParserFactory.cpp", diff --git a/Swiften/Parser/SerializingParser.cpp b/Swiften/Parser/SerializingParser.cpp index 43dfc51..096ffc1 100644 --- a/Swiften/Parser/SerializingParser.cpp +++ b/Swiften/Parser/SerializingParser.cpp @@ -4,10 +4,9 @@ * See Documentation/Licenses/GPLv3.txt for more information. */ -#include "Swiften/Parser/SerializingParser.h" -#include "Swiften/Serializer/XML/XMLTextNode.h" -#include "Swiften/Base/foreach.h" -#include <iostream> +#include <Swiften/Parser/SerializingParser.h> +#include <Swiften/Serializer/XML/XMLTextNode.h> +#include <Swiften/Base/foreach.h> namespace Swift { @@ -16,8 +15,9 @@ SerializingParser::SerializingParser() { void SerializingParser::handleStartElement(const std::string& tag, const std::string& ns, const AttributeMap& attributes) { boost::shared_ptr<XMLElement> element(new XMLElement(tag, ns)); - for (AttributeMap::const_iterator i = attributes.begin(); i != attributes.end(); ++i) { - element->setAttribute((*i).first, (*i).second); + // FIXME: Ignoring attribute namespace + foreach (const AttributeMap::Entry& e, attributes.getEntries()) { + element->setAttribute(e.getAttribute().getName(), e.getValue()); } if (elementStack_.empty()) { diff --git a/Swiften/Parser/SerializingParser.h b/Swiften/Parser/SerializingParser.h index 6276ea0..c4a8b94 100644 --- a/Swiften/Parser/SerializingParser.h +++ b/Swiften/Parser/SerializingParser.h @@ -8,8 +8,8 @@ #define SWIFTEN_SerializingParser_H #include <string> -#include "Swiften/Parser/AttributeMap.h" -#include "Swiften/Serializer/XML/XMLElement.h" +#include <Swiften/Parser/AttributeMap.h> +#include <Swiften/Serializer/XML/XMLElement.h> namespace Swift { class SerializingParser { diff --git a/Swiften/Parser/StanzaAckParser.cpp b/Swiften/Parser/StanzaAckParser.cpp index 9d029cc..1730493 100644 --- a/Swiften/Parser/StanzaAckParser.cpp +++ b/Swiften/Parser/StanzaAckParser.cpp @@ -4,7 +4,7 @@ * See Documentation/Licenses/GPLv3.txt for more information. */ -#include "Swiften/Parser/StanzaAckParser.h" +#include <Swiften/Parser/StanzaAckParser.h> #include <boost/lexical_cast.hpp> diff --git a/Swiften/Parser/StanzaAckParser.h b/Swiften/Parser/StanzaAckParser.h index 4078dc1..c188878 100644 --- a/Swiften/Parser/StanzaAckParser.h +++ b/Swiften/Parser/StanzaAckParser.h @@ -6,8 +6,8 @@ #pragma once -#include "Swiften/Parser/GenericElementParser.h" -#include "Swiften/Elements/StanzaAck.h" +#include <Swiften/Parser/GenericElementParser.h> +#include <Swiften/Elements/StanzaAck.h> namespace Swift { class StanzaAckParser : public GenericElementParser<StanzaAck> { diff --git a/Swiften/Parser/StanzaAckRequestParser.h b/Swiften/Parser/StanzaAckRequestParser.h index 82290c6..9a2ccd1 100644 --- a/Swiften/Parser/StanzaAckRequestParser.h +++ b/Swiften/Parser/StanzaAckRequestParser.h @@ -6,8 +6,8 @@ #pragma once -#include "Swiften/Parser/GenericElementParser.h" -#include "Swiften/Elements/StanzaAckRequest.h" +#include <Swiften/Parser/GenericElementParser.h> +#include <Swiften/Elements/StanzaAckRequest.h> namespace Swift { class StanzaAckRequestParser : public GenericElementParser<StanzaAckRequest> { diff --git a/Swiften/Parser/StanzaParser.cpp b/Swiften/Parser/StanzaParser.cpp index 64c4901..52f318d 100644 --- a/Swiften/Parser/StanzaParser.cpp +++ b/Swiften/Parser/StanzaParser.cpp @@ -4,15 +4,16 @@ * See Documentation/Licenses/GPLv3.txt for more information. */ -#include "Swiften/Parser/StanzaParser.h" +#include <Swiften/Parser/StanzaParser.h> #include <iostream> +#include <boost/optional.hpp> #include <cassert> -#include "Swiften/Parser/PayloadParser.h" -#include "Swiften/Parser/PayloadParserFactory.h" -#include "Swiften/Parser/PayloadParserFactoryCollection.h" -#include "Swiften/Parser/UnknownPayloadParser.h" +#include <Swiften/Parser/PayloadParser.h> +#include <Swiften/Parser/PayloadParserFactory.h> +#include <Swiften/Parser/PayloadParserFactoryCollection.h> +#include <Swiften/Parser/UnknownPayloadParser.h> namespace Swift { @@ -39,17 +40,17 @@ void StanzaParser::handleStartElement(const std::string& element, const std::str currentPayloadParser_->handleStartElement(element, ns, attributes); } else { - AttributeMap::const_iterator from = attributes.find("from"); - if (from != attributes.end()) { - getStanza()->setFrom(JID(from->second)); + boost::optional<std::string> from = attributes.getAttributeValue("from"); + if (from) { + getStanza()->setFrom(JID(*from)); } - AttributeMap::const_iterator to = attributes.find("to"); - if (to != attributes.end()) { - getStanza()->setTo(JID(to->second)); + boost::optional<std::string> to = attributes.getAttributeValue("to"); + if (to) { + getStanza()->setTo(JID(*to)); } - AttributeMap::const_iterator id = attributes.find("id"); - if (id != attributes.end()) { - getStanza()->setID(id->second); + boost::optional<std::string> id = attributes.getAttributeValue("id"); + if (id) { + getStanza()->setID(*id); } handleStanzaAttributes(attributes); } diff --git a/Swiften/Parser/StanzaParser.h b/Swiften/Parser/StanzaParser.h index df01943..a35215e 100644 --- a/Swiften/Parser/StanzaParser.h +++ b/Swiften/Parser/StanzaParser.h @@ -10,9 +10,9 @@ #include <boost/noncopyable.hpp> #include <string> -#include "Swiften/Elements/Stanza.h" -#include "Swiften/Parser/ElementParser.h" -#include "Swiften/Parser/AttributeMap.h" +#include <Swiften/Elements/Stanza.h> +#include <Swiften/Parser/ElementParser.h> +#include <Swiften/Parser/AttributeMap.h> namespace Swift { class PayloadParser; diff --git a/Swiften/Parser/StartTLSFailureParser.h b/Swiften/Parser/StartTLSFailureParser.h index 29b2d90..bc80f9e 100644 --- a/Swiften/Parser/StartTLSFailureParser.h +++ b/Swiften/Parser/StartTLSFailureParser.h @@ -7,8 +7,8 @@ #ifndef SWIFTEN_StartTLSFailureParser_H #define SWIFTEN_StartTLSFailureParser_H -#include "Swiften/Parser/GenericElementParser.h" -#include "Swiften/Elements/StartTLSFailure.h" +#include <Swiften/Parser/GenericElementParser.h> +#include <Swiften/Elements/StartTLSFailure.h> namespace Swift { class StartTLSFailureParser : public GenericElementParser<StartTLSFailure> { diff --git a/Swiften/Parser/StartTLSParser.h b/Swiften/Parser/StartTLSParser.h index 3822c3f..cc0640d 100644 --- a/Swiften/Parser/StartTLSParser.h +++ b/Swiften/Parser/StartTLSParser.h @@ -7,8 +7,8 @@ #ifndef SWIFTEN_StartTLSParser_H #define SWIFTEN_StartTLSParser_H -#include "Swiften/Parser/GenericElementParser.h" -#include "Swiften/Elements/StartTLSRequest.h" +#include <Swiften/Parser/GenericElementParser.h> +#include <Swiften/Elements/StartTLSRequest.h> namespace Swift { class StartTLSParser : public GenericElementParser<StartTLSRequest> { diff --git a/Swiften/Parser/StreamFeaturesParser.cpp b/Swiften/Parser/StreamFeaturesParser.cpp index 377f215..6a527ce 100644 --- a/Swiften/Parser/StreamFeaturesParser.cpp +++ b/Swiften/Parser/StreamFeaturesParser.cpp @@ -4,7 +4,7 @@ * See Documentation/Licenses/GPLv3.txt for more information. */ -#include "Swiften/Parser/StreamFeaturesParser.h" +#include <Swiften/Parser/StreamFeaturesParser.h> namespace Swift { @@ -31,6 +31,9 @@ void StreamFeaturesParser::handleStartElement(const std::string& element, const else if (element == "compression" && ns == "http://jabber.org/features/compress") { inCompression_ = true; } + else if (element == "ver" && ns == "urn:xmpp:features:rosterver") { + getElementGeneric()->setHasRosterVersioning(); + } } else if (currentDepth_ == 2) { if (inCompression_ && element == "method") { diff --git a/Swiften/Parser/StreamFeaturesParser.h b/Swiften/Parser/StreamFeaturesParser.h index ee65a2a..83a627d 100644 --- a/Swiften/Parser/StreamFeaturesParser.h +++ b/Swiften/Parser/StreamFeaturesParser.h @@ -8,8 +8,8 @@ #define SWIFTEN_STREAMFEATURESPARSER_H #include <string> -#include "Swiften/Parser/GenericElementParser.h" -#include "Swiften/Elements/StreamFeatures.h" +#include <Swiften/Parser/GenericElementParser.h> +#include <Swiften/Elements/StreamFeatures.h> namespace Swift { class StreamFeaturesParser : public GenericElementParser<StreamFeatures> { diff --git a/Swiften/Parser/StreamManagementEnabledParser.cpp b/Swiften/Parser/StreamManagementEnabledParser.cpp new file mode 100644 index 0000000..906e071 --- /dev/null +++ b/Swiften/Parser/StreamManagementEnabledParser.cpp @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2011 Remko Tronçon + * Licensed under the GNU General Public License v3. + * See Documentation/Licenses/GPLv3.txt for more information. + */ + +#include <Swiften/Parser/StreamManagementEnabledParser.h> + +using namespace Swift; + +StreamManagementEnabledParser::StreamManagementEnabledParser() : level(TopLevel) { +} + +StreamManagementEnabledParser::~StreamManagementEnabledParser() { +} + +void StreamManagementEnabledParser::handleStartElement(const std::string&, const std::string&, const AttributeMap& attributes) { + if (level == TopLevel) { + if (attributes.getBoolAttribute("resume", false)) { + getElementGeneric()->setResumeSupported(); + } + getElementGeneric()->setResumeID(attributes.getAttribute("id")); + } + ++level; +} + +void StreamManagementEnabledParser::handleEndElement(const std::string&, const std::string&) { + --level; +} diff --git a/Swiften/Parser/StreamManagementEnabledParser.h b/Swiften/Parser/StreamManagementEnabledParser.h index adc45ab..db616af 100644 --- a/Swiften/Parser/StreamManagementEnabledParser.h +++ b/Swiften/Parser/StreamManagementEnabledParser.h @@ -1,17 +1,27 @@ /* - * Copyright (c) 2010 Remko Tronçon + * Copyright (c) 2010-2011 Remko Tronçon * Licensed under the GNU General Public License v3. * See Documentation/Licenses/GPLv3.txt for more information. */ #pragma once -#include "Swiften/Parser/GenericElementParser.h" -#include "Swiften/Elements/StreamManagementEnabled.h" +#include <Swiften/Parser/GenericElementParser.h> +#include <Swiften/Elements/StreamManagementEnabled.h> namespace Swift { class StreamManagementEnabledParser : public GenericElementParser<StreamManagementEnabled> { public: - StreamManagementEnabledParser() : GenericElementParser<StreamManagementEnabled>() {} + StreamManagementEnabledParser(); + ~StreamManagementEnabledParser(); + + virtual void handleStartElement(const std::string&, const std::string&, const AttributeMap&); + virtual void handleEndElement(const std::string&, const std::string&); + + private: + enum Level { + TopLevel = 0 + }; + int level; }; } diff --git a/Swiften/Parser/StreamManagementFailedParser.h b/Swiften/Parser/StreamManagementFailedParser.h index 07f5935..6c111d0 100644 --- a/Swiften/Parser/StreamManagementFailedParser.h +++ b/Swiften/Parser/StreamManagementFailedParser.h @@ -6,8 +6,8 @@ #pragma once -#include "Swiften/Parser/GenericElementParser.h" -#include "Swiften/Elements/StreamManagementFailed.h" +#include <Swiften/Parser/GenericElementParser.h> +#include <Swiften/Elements/StreamManagementFailed.h> namespace Swift { class StreamManagementFailedParser : public GenericElementParser<StreamManagementFailed> { diff --git a/Swiften/Parser/StreamResumeParser.cpp b/Swiften/Parser/StreamResumeParser.cpp new file mode 100644 index 0000000..f54dcf0 --- /dev/null +++ b/Swiften/Parser/StreamResumeParser.cpp @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2011 Remko Tronçon + * Licensed under the GNU General Public License v3. + * See Documentation/Licenses/GPLv3.txt for more information. + */ + +#include <Swiften/Parser/StreamResumeParser.h> + +#include <boost/lexical_cast.hpp> + +using namespace Swift; + +StreamResumeParser::StreamResumeParser() : level(TopLevel) { +} + +StreamResumeParser::~StreamResumeParser() { +} + +void StreamResumeParser::handleStartElement(const std::string&, const std::string&, const AttributeMap& attributes) { + if (level == TopLevel) { + boost::optional<std::string> handledStanzasCount = attributes.getAttributeValue("h"); + if (handledStanzasCount) { + try { + getElementGeneric()->setHandledStanzasCount(boost::lexical_cast<int>(*handledStanzasCount)); + } + catch (const boost::bad_lexical_cast &) { + } + } + getElementGeneric()->setResumeID(attributes.getAttribute("previd")); + } + ++level; +} + +void StreamResumeParser::handleEndElement(const std::string&, const std::string&) { + --level; +} diff --git a/Swiften/Parser/StreamResumeParser.h b/Swiften/Parser/StreamResumeParser.h new file mode 100644 index 0000000..0ccd24c --- /dev/null +++ b/Swiften/Parser/StreamResumeParser.h @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2011 Remko Tronçon + * Licensed under the GNU General Public License v3. + * See Documentation/Licenses/GPLv3.txt for more information. + */ + +#pragma once + +#include <Swiften/Parser/GenericElementParser.h> +#include <Swiften/Elements/StreamResume.h> + +namespace Swift { + class StreamResumeParser : public GenericElementParser<StreamResume> { + public: + StreamResumeParser(); + ~StreamResumeParser(); + + virtual void handleStartElement(const std::string&, const std::string&, const AttributeMap&); + virtual void handleEndElement(const std::string&, const std::string&); + + private: + enum Level { + TopLevel = 0 + }; + int level; + }; +} diff --git a/Swiften/Parser/TLSProceedParser.h b/Swiften/Parser/TLSProceedParser.h index 20a44d7..83a2a8c 100644 --- a/Swiften/Parser/TLSProceedParser.h +++ b/Swiften/Parser/TLSProceedParser.h @@ -7,8 +7,8 @@ #ifndef SWIFTEN_TLSProceedParser_H #define SWIFTEN_TLSProceedParser_H -#include "Swiften/Parser/GenericElementParser.h" -#include "Swiften/Elements/TLSProceed.h" +#include <Swiften/Parser/GenericElementParser.h> +#include <Swiften/Elements/TLSProceed.h> namespace Swift { class TLSProceedParser : public GenericElementParser<TLSProceed> { diff --git a/Swiften/Parser/UnitTest/AttributeMapTest.cpp b/Swiften/Parser/UnitTest/AttributeMapTest.cpp index fb68f29..d6c3c01 100644 --- a/Swiften/Parser/UnitTest/AttributeMapTest.cpp +++ b/Swiften/Parser/UnitTest/AttributeMapTest.cpp @@ -7,13 +7,14 @@ #include <cppunit/extensions/HelperMacros.h> #include <cppunit/extensions/TestFactoryRegistry.h> -#include "Swiften/Parser/AttributeMap.h" +#include <Swiften/Parser/AttributeMap.h> using namespace Swift; class AttributeMapTest : public CppUnit::TestFixture { CPPUNIT_TEST_SUITE(AttributeMapTest); + CPPUNIT_TEST(testGetAttribute_Namespaced); CPPUNIT_TEST(testGetBoolAttribute_True); CPPUNIT_TEST(testGetBoolAttribute_1); CPPUNIT_TEST(testGetBoolAttribute_False); @@ -24,39 +25,46 @@ class AttributeMapTest : public CppUnit::TestFixture CPPUNIT_TEST_SUITE_END(); public: - AttributeMapTest() {} + void testGetAttribute_Namespaced() { + AttributeMap testling; + testling.addAttribute("lang", "", "nl"); + testling.addAttribute("lang", "http://www.w3.org/XML/1998/namespace", "en"); + testling.addAttribute("lang", "", "fr"); + + CPPUNIT_ASSERT_EQUAL(std::string("en"), testling.getAttribute("lang", "http://www.w3.org/XML/1998/namespace")); + } void testGetBoolAttribute_True() { AttributeMap testling; - testling["foo"] = "true"; + testling.addAttribute("foo", "", "true"); CPPUNIT_ASSERT(testling.getBoolAttribute("foo")); } void testGetBoolAttribute_1() { AttributeMap testling; - testling["foo"] = "1"; + testling.addAttribute("foo", "", "1"); CPPUNIT_ASSERT(testling.getBoolAttribute("foo")); } void testGetBoolAttribute_False() { AttributeMap testling; - testling["foo"] = "false"; + testling.addAttribute("foo", "", "false"); CPPUNIT_ASSERT(!testling.getBoolAttribute("foo", true)); } void testGetBoolAttribute_0() { AttributeMap testling; - testling["foo"] = "0"; + testling.addAttribute("foo", "", "0"); CPPUNIT_ASSERT(!testling.getBoolAttribute("foo", true)); } void testGetBoolAttribute_Invalid() { AttributeMap testling; - testling["foo"] = "bla"; + testling.addAttribute("foo", "", "bla"); CPPUNIT_ASSERT(!testling.getBoolAttribute("foo", true)); } diff --git a/Swiften/Parser/UnitTest/ElementParserTester.h b/Swiften/Parser/UnitTest/ElementParserTester.h index ba39eb7..6543e2b 100644 --- a/Swiften/Parser/UnitTest/ElementParserTester.h +++ b/Swiften/Parser/UnitTest/ElementParserTester.h @@ -7,7 +7,7 @@ #ifndef SWIFTEN_ElementParserTester_H #define SWIFTEN_ElementParserTester_H -#include "Swiften/Parser/UnitTest/ParserTester.h" +#include <Swiften/Parser/UnitTest/ParserTester.h> namespace Swift { typedef ParserTester<ElementParser> ElementParserTester; diff --git a/Swiften/Parser/UnitTest/IQParserTest.cpp b/Swiften/Parser/UnitTest/IQParserTest.cpp index 3cc7d45..3c86a5d 100644 --- a/Swiften/Parser/UnitTest/IQParserTest.cpp +++ b/Swiften/Parser/UnitTest/IQParserTest.cpp @@ -7,9 +7,9 @@ #include <cppunit/extensions/HelperMacros.h> #include <cppunit/extensions/TestFactoryRegistry.h> -#include "Swiften/Parser/IQParser.h" -#include "Swiften/Parser/PayloadParserFactoryCollection.h" -#include "Swiften/Parser/UnitTest/StanzaParserTester.h" +#include <Swiften/Parser/IQParser.h> +#include <Swiften/Parser/PayloadParserFactoryCollection.h> +#include <Swiften/Parser/UnitTest/StanzaParserTester.h> using namespace Swift; diff --git a/Swiften/Parser/UnitTest/MessageParserTest.cpp b/Swiften/Parser/UnitTest/MessageParserTest.cpp index 7615fa3..8ab59ed 100644 --- a/Swiften/Parser/UnitTest/MessageParserTest.cpp +++ b/Swiften/Parser/UnitTest/MessageParserTest.cpp @@ -7,9 +7,9 @@ #include <cppunit/extensions/HelperMacros.h> #include <cppunit/extensions/TestFactoryRegistry.h> -#include "Swiften/Parser/MessageParser.h" -#include "Swiften/Parser/PayloadParserFactoryCollection.h" -#include "Swiften/Parser/UnitTest/StanzaParserTester.h" +#include <Swiften/Parser/MessageParser.h> +#include <Swiften/Parser/PayloadParserFactoryCollection.h> +#include <Swiften/Parser/UnitTest/StanzaParserTester.h> using namespace Swift; diff --git a/Swiften/Parser/UnitTest/ParserTester.h b/Swiften/Parser/UnitTest/ParserTester.h index 970c1be..be22ed7 100644 --- a/Swiften/Parser/UnitTest/ParserTester.h +++ b/Swiften/Parser/UnitTest/ParserTester.h @@ -7,9 +7,9 @@ #ifndef SWIFTEN_ParserTester_H #define SWIFTEN_ParserTester_H -#include "Swiften/Parser/XMLParserClient.h" -#include "Swiften/Parser/PlatformXMLParserFactory.h" -#include "Swiften/Parser/XMLParser.h" +#include <Swiften/Parser/XMLParserClient.h> +#include <Swiften/Parser/PlatformXMLParserFactory.h> +#include <Swiften/Parser/XMLParser.h> namespace Swift { class XMLParser; diff --git a/Swiften/Parser/UnitTest/PayloadParserFactoryCollectionTest.cpp b/Swiften/Parser/UnitTest/PayloadParserFactoryCollectionTest.cpp index 8e49764..fea64e2 100644 --- a/Swiften/Parser/UnitTest/PayloadParserFactoryCollectionTest.cpp +++ b/Swiften/Parser/UnitTest/PayloadParserFactoryCollectionTest.cpp @@ -7,8 +7,8 @@ #include <cppunit/extensions/HelperMacros.h> #include <cppunit/extensions/TestFactoryRegistry.h> -#include "Swiften/Parser/PayloadParserFactoryCollection.h" -#include "Swiften/Parser/PayloadParserFactory.h" +#include <Swiften/Parser/PayloadParserFactoryCollection.h> +#include <Swiften/Parser/PayloadParserFactory.h> using namespace Swift; diff --git a/Swiften/Parser/UnitTest/PresenceParserTest.cpp b/Swiften/Parser/UnitTest/PresenceParserTest.cpp index f68db40..f9d6cf6 100644 --- a/Swiften/Parser/UnitTest/PresenceParserTest.cpp +++ b/Swiften/Parser/UnitTest/PresenceParserTest.cpp @@ -7,9 +7,9 @@ #include <cppunit/extensions/HelperMacros.h> #include <cppunit/extensions/TestFactoryRegistry.h> -#include "Swiften/Parser/PresenceParser.h" -#include "Swiften/Parser/PayloadParserFactoryCollection.h" -#include "Swiften/Parser/UnitTest/StanzaParserTester.h" +#include <Swiften/Parser/PresenceParser.h> +#include <Swiften/Parser/PayloadParserFactoryCollection.h> +#include <Swiften/Parser/UnitTest/StanzaParserTester.h> using namespace Swift; diff --git a/Swiften/Parser/UnitTest/SerializingParserTest.cpp b/Swiften/Parser/UnitTest/SerializingParserTest.cpp index c0af493..aef1dfb 100644 --- a/Swiften/Parser/UnitTest/SerializingParserTest.cpp +++ b/Swiften/Parser/UnitTest/SerializingParserTest.cpp @@ -7,8 +7,8 @@ #include <cppunit/extensions/HelperMacros.h> #include <cppunit/extensions/TestFactoryRegistry.h> -#include "Swiften/Parser/SerializingParser.h" -#include "Swiften/Parser/UnitTest/StanzaParserTester.h" +#include <Swiften/Parser/SerializingParser.h> +#include <Swiften/Parser/UnitTest/StanzaParserTester.h> using namespace Swift; diff --git a/Swiften/Parser/UnitTest/StanzaAckParserTest.cpp b/Swiften/Parser/UnitTest/StanzaAckParserTest.cpp index b90af6e..b68fb30 100644 --- a/Swiften/Parser/UnitTest/StanzaAckParserTest.cpp +++ b/Swiften/Parser/UnitTest/StanzaAckParserTest.cpp @@ -7,9 +7,9 @@ #include <cppunit/extensions/HelperMacros.h> #include <cppunit/extensions/TestFactoryRegistry.h> -#include "Swiften/Parser/StanzaAckParser.h" -#include "Swiften/Parser/PayloadParserFactoryCollection.h" -#include "Swiften/Parser/UnitTest/ElementParserTester.h" +#include <Swiften/Parser/StanzaAckParser.h> +#include <Swiften/Parser/PayloadParserFactoryCollection.h> +#include <Swiften/Parser/UnitTest/ElementParserTester.h> using namespace Swift; diff --git a/Swiften/Parser/UnitTest/StanzaParserTest.cpp b/Swiften/Parser/UnitTest/StanzaParserTest.cpp index d57f798..b2ddb39 100644 --- a/Swiften/Parser/UnitTest/StanzaParserTest.cpp +++ b/Swiften/Parser/UnitTest/StanzaParserTest.cpp @@ -7,12 +7,12 @@ #include <cppunit/extensions/HelperMacros.h> #include <cppunit/extensions/TestFactoryRegistry.h> -#include "Swiften/Parser/StanzaParser.h" -#include "Swiften/Parser/GenericPayloadParser.h" -#include "Swiften/Parser/PayloadParserFactory.h" -#include "Swiften/Parser/PayloadParserFactoryCollection.h" -#include "Swiften/Elements/Stanza.h" -#include "Swiften/Elements/Payload.h" +#include <Swiften/Parser/StanzaParser.h> +#include <Swiften/Parser/GenericPayloadParser.h> +#include <Swiften/Parser/PayloadParserFactory.h> +#include <Swiften/Parser/PayloadParserFactoryCollection.h> +#include <Swiften/Elements/Stanza.h> +#include <Swiften/Elements/Payload.h> using namespace Swift; @@ -40,8 +40,8 @@ class StanzaParserTest : public CppUnit::TestFixture { MyStanzaParser testling(factoryCollection_); AttributeMap attributes; - attributes["foo"] = "fum"; - attributes["bar"] = "baz"; + attributes.addAttribute("foo", "", "fum"); + attributes.addAttribute("bar", "", "baz"); testling.handleStartElement("mystanza", "", attributes); testling.handleStartElement("mypayload1", "", attributes); testling.handleStartElement("child", "", attributes); @@ -107,9 +107,9 @@ class StanzaParserTest : public CppUnit::TestFixture { MyStanzaParser testling(factoryCollection_); AttributeMap attributes; - attributes["to"] = "foo@example.com/blo"; - attributes["from"] = "bar@example.com/baz"; - attributes["id"] = "id-123"; + attributes.addAttribute("to", "", "foo@example.com/blo"); + attributes.addAttribute("from", "", "bar@example.com/baz"); + attributes.addAttribute("id", "", "id-123"); testling.handleStartElement("mystanza", "", attributes); testling.handleEndElement("mypayload1", ""); diff --git a/Swiften/Parser/UnitTest/StanzaParserTester.h b/Swiften/Parser/UnitTest/StanzaParserTester.h index eb3a18b..7e5039a 100644 --- a/Swiften/Parser/UnitTest/StanzaParserTester.h +++ b/Swiften/Parser/UnitTest/StanzaParserTester.h @@ -7,8 +7,8 @@ #ifndef SWIFTEN_StanzaParserTester_H #define SWIFTEN_StanzaParserTester_H -#include "Swiften/Parser/StanzaParser.h" -#include "Swiften/Parser/UnitTest/ParserTester.h" +#include <Swiften/Parser/StanzaParser.h> +#include <Swiften/Parser/UnitTest/ParserTester.h> namespace Swift { typedef ParserTester<StanzaParser> StanzaParserTester; diff --git a/Swiften/Parser/UnitTest/StreamFeaturesParserTest.cpp b/Swiften/Parser/UnitTest/StreamFeaturesParserTest.cpp index 1cdaf54..4bc971f 100644 --- a/Swiften/Parser/UnitTest/StreamFeaturesParserTest.cpp +++ b/Swiften/Parser/UnitTest/StreamFeaturesParserTest.cpp @@ -7,8 +7,8 @@ #include <cppunit/extensions/HelperMacros.h> #include <cppunit/extensions/TestFactoryRegistry.h> -#include "Swiften/Parser/StreamFeaturesParser.h" -#include "Swiften/Parser/UnitTest/ElementParserTester.h" +#include <Swiften/Parser/StreamFeaturesParser.h> +#include <Swiften/Parser/UnitTest/ElementParserTester.h> using namespace Swift; @@ -37,6 +37,7 @@ class StreamFeaturesParserTest : public CppUnit::TestFixture { "<bind xmlns=\"urn:ietf:params:xml:ns:xmpp-bind\"/>" "<sm xmlns='urn:xmpp:sm:2'/>" "<session xmlns=\"urn:ietf:params:xml:ns:xmpp-session\"/>" + "<ver xmlns=\"urn:xmpp:features:rosterver\"/>" "</stream:features>")); StreamFeatures::ref element = boost::dynamic_pointer_cast<StreamFeatures>(testling.getElement()); @@ -49,6 +50,7 @@ class StreamFeaturesParserTest : public CppUnit::TestFixture { CPPUNIT_ASSERT(element->hasAuthenticationMechanism("DIGEST-MD5")); CPPUNIT_ASSERT(element->hasAuthenticationMechanism("PLAIN")); CPPUNIT_ASSERT(element->hasStreamManagement()); + CPPUNIT_ASSERT(element->hasRosterVersioning()); } void testParse_Empty() { diff --git a/Swiften/Parser/UnitTest/StreamManagementEnabledParserTest.cpp b/Swiften/Parser/UnitTest/StreamManagementEnabledParserTest.cpp new file mode 100644 index 0000000..07b7b31 --- /dev/null +++ b/Swiften/Parser/UnitTest/StreamManagementEnabledParserTest.cpp @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2010 Remko Tronçon + * Licensed under the GNU General Public License v3. + * See Documentation/Licenses/GPLv3.txt for more information. + */ + +#include <cppunit/extensions/HelperMacros.h> +#include <cppunit/extensions/TestFactoryRegistry.h> + +#include <Swiften/Parser/StreamManagementEnabledParser.h> +#include <Swiften/Parser/UnitTest/ElementParserTester.h> + +using namespace Swift; + +class StreamManagementEnabledParserTest : public CppUnit::TestFixture { + CPPUNIT_TEST_SUITE(StreamManagementEnabledParserTest); + CPPUNIT_TEST(testParse); + CPPUNIT_TEST_SUITE_END(); + + public: + void testParse() { + StreamManagementEnabledParser testling; + ElementParserTester parser(&testling); + + CPPUNIT_ASSERT(parser.parse( + "<enabled xmlns=\"urn:xmpp:sm:3\" id=\"some-long-sm-id\" resume=\"true\"/>")); + + boost::shared_ptr<StreamManagementEnabled> element = boost::dynamic_pointer_cast<StreamManagementEnabled>(testling.getElement()); + CPPUNIT_ASSERT(element->getResumeSupported()); + CPPUNIT_ASSERT_EQUAL(std::string("some-long-sm-id"), element->getResumeID()); + } +}; + +CPPUNIT_TEST_SUITE_REGISTRATION(StreamManagementEnabledParserTest); diff --git a/Swiften/Parser/UnitTest/XMLParserTest.cpp b/Swiften/Parser/UnitTest/XMLParserTest.cpp index 426b7a0..9abc718 100644 --- a/Swiften/Parser/UnitTest/XMLParserTest.cpp +++ b/Swiften/Parser/UnitTest/XMLParserTest.cpp @@ -9,12 +9,12 @@ #include <vector> #include <string> -#include "Swiften/Parser/XMLParserClient.h" +#include <Swiften/Parser/XMLParserClient.h> #ifdef HAVE_EXPAT -#include "Swiften/Parser/ExpatParser.h" +#include <Swiften/Parser/ExpatParser.h> #endif #ifdef HAVE_LIBXML -#include "Swiften/Parser/LibXMLParser.h" +#include <Swiften/Parser/LibXMLParser.h> #endif using namespace Swift; @@ -31,6 +31,8 @@ class XMLParserTest : public CppUnit::TestFixture { CPPUNIT_TEST(testParse_InErrorState); CPPUNIT_TEST(testParse_Incremental); CPPUNIT_TEST(testParse_WhitespaceInAttribute); + CPPUNIT_TEST(testParse_AttributeWithoutNamespace); + CPPUNIT_TEST(testParse_AttributeWithNamespace); CPPUNIT_TEST_SUITE_END(); public: @@ -46,13 +48,13 @@ class XMLParserTest : public CppUnit::TestFixture { CPPUNIT_ASSERT_EQUAL(Client::StartElement, client_.events[0].type); CPPUNIT_ASSERT_EQUAL(std::string("iq"), client_.events[0].data); - CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(1), client_.events[0].attributes.size()); - CPPUNIT_ASSERT_EQUAL(std::string("get"), client_.events[0].attributes["type"]); + CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(1), client_.events[0].attributes.getEntries().size()); + CPPUNIT_ASSERT_EQUAL(std::string("get"), client_.events[0].attributes.getAttribute("type")); CPPUNIT_ASSERT_EQUAL(std::string(), client_.events[0].ns); CPPUNIT_ASSERT_EQUAL(Client::StartElement, client_.events[1].type); CPPUNIT_ASSERT_EQUAL(std::string("query"), client_.events[1].data); - CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(0), client_.events[1].attributes.size()); + CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(0), client_.events[1].attributes.getEntries().size()); CPPUNIT_ASSERT_EQUAL(std::string("jabber:iq:version"), client_.events[1].ns); CPPUNIT_ASSERT_EQUAL(Client::EndElement, client_.events[2].type); @@ -76,7 +78,7 @@ class XMLParserTest : public CppUnit::TestFixture { CPPUNIT_ASSERT_EQUAL(Client::StartElement, client_.events[0].type); CPPUNIT_ASSERT_EQUAL(std::string("query"), client_.events[0].data); - CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(0), client_.events[0].attributes.size()); + CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(0), client_.events[0].attributes.getEntries().size()); CPPUNIT_ASSERT_EQUAL(std::string("jabber:iq:version"), client_.events[0].ns); CPPUNIT_ASSERT_EQUAL(Client::StartElement, client_.events[1].type); @@ -205,6 +207,28 @@ class XMLParserTest : public CppUnit::TestFixture { CPPUNIT_ASSERT_EQUAL(Client::EndElement, client_.events[2].type); CPPUNIT_ASSERT_EQUAL(std::string("presence"), client_.events[2].data); } + + void testParse_AttributeWithoutNamespace() { + ParserType testling(&client_); + + CPPUNIT_ASSERT(testling.parse( + "<query xmlns='http://swift.im' attr='3'/>")); + + CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(1), client_.events[0].attributes.getEntries().size()); + CPPUNIT_ASSERT_EQUAL(std::string("attr"), client_.events[0].attributes.getEntries()[0].getAttribute().getName()); + CPPUNIT_ASSERT_EQUAL(std::string(""), client_.events[0].attributes.getEntries()[0].getAttribute().getNamespace()); + } + + void testParse_AttributeWithNamespace() { + ParserType testling(&client_); + + CPPUNIT_ASSERT(testling.parse( + "<query xmlns='http://swift.im' xmlns:f='http://swift.im/f' f:attr='3'/>")); + + CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(1), client_.events[0].attributes.getEntries().size()); + CPPUNIT_ASSERT_EQUAL(std::string("attr"), client_.events[0].attributes.getEntries()[0].getAttribute().getName()); + CPPUNIT_ASSERT_EQUAL(std::string("http://swift.im/f"), client_.events[0].attributes.getEntries()[0].getAttribute().getNamespace()); + } private: class Client : public XMLParserClient { diff --git a/Swiften/Parser/UnitTest/XMPPParserTest.cpp b/Swiften/Parser/UnitTest/XMPPParserTest.cpp index 8ce96d8..dbee18a 100644 --- a/Swiften/Parser/UnitTest/XMPPParserTest.cpp +++ b/Swiften/Parser/UnitTest/XMPPParserTest.cpp @@ -8,17 +8,17 @@ #include <cppunit/extensions/TestFactoryRegistry.h> #include <vector> -#include "Swiften/Elements/ProtocolHeader.h" +#include <Swiften/Elements/ProtocolHeader.h> #include <string> -#include "Swiften/Parser/XMPPParser.h" -#include "Swiften/Parser/ElementParser.h" -#include "Swiften/Parser/XMPPParserClient.h" -#include "Swiften/Parser/PayloadParserFactoryCollection.h" -#include "Swiften/Elements/Presence.h" -#include "Swiften/Elements/IQ.h" -#include "Swiften/Elements/Message.h" -#include "Swiften/Elements/StreamFeatures.h" -#include "Swiften/Elements/UnknownElement.h" +#include <Swiften/Parser/XMPPParser.h> +#include <Swiften/Parser/ElementParser.h> +#include <Swiften/Parser/XMPPParserClient.h> +#include <Swiften/Parser/PayloadParserFactoryCollection.h> +#include <Swiften/Elements/Presence.h> +#include <Swiften/Elements/IQ.h> +#include <Swiften/Elements/Message.h> +#include <Swiften/Elements/StreamFeatures.h> +#include <Swiften/Elements/UnknownElement.h> using namespace Swift; diff --git a/Swiften/Parser/UnknownElementParser.h b/Swiften/Parser/UnknownElementParser.h index 6ff885f..5df7ed3 100644 --- a/Swiften/Parser/UnknownElementParser.h +++ b/Swiften/Parser/UnknownElementParser.h @@ -7,8 +7,8 @@ #ifndef SWIFTEN_UnknownElementParser_H #define SWIFTEN_UnknownElementParser_H -#include "Swiften/Parser/GenericElementParser.h" -#include "Swiften/Elements/UnknownElement.h" +#include <Swiften/Parser/GenericElementParser.h> +#include <Swiften/Elements/UnknownElement.h> namespace Swift { class UnknownElementParser : public GenericElementParser<UnknownElement> { diff --git a/Swiften/Parser/UnknownPayloadParser.h b/Swiften/Parser/UnknownPayloadParser.h index 8750f22..40f29be 100644 --- a/Swiften/Parser/UnknownPayloadParser.h +++ b/Swiften/Parser/UnknownPayloadParser.h @@ -9,7 +9,7 @@ #include <boost/shared_ptr.hpp> -#include "Swiften/Parser/PayloadParser.h" +#include <Swiften/Parser/PayloadParser.h> namespace Swift { diff --git a/Swiften/Parser/XMLParser.cpp b/Swiften/Parser/XMLParser.cpp index a2e73fc..cd7baea 100644 --- a/Swiften/Parser/XMLParser.cpp +++ b/Swiften/Parser/XMLParser.cpp @@ -4,7 +4,7 @@ * See Documentation/Licenses/GPLv3.txt for more information. */ -#include "Swiften/Parser/XMLParser.h" +#include <Swiften/Parser/XMLParser.h> namespace Swift { diff --git a/Swiften/Parser/XMLParserClient.cpp b/Swiften/Parser/XMLParserClient.cpp index c0e7853..46d57b7 100644 --- a/Swiften/Parser/XMLParserClient.cpp +++ b/Swiften/Parser/XMLParserClient.cpp @@ -4,7 +4,7 @@ * See Documentation/Licenses/GPLv3.txt for more information. */ -#include "Swiften/Parser/XMLParserClient.h" +#include <Swiften/Parser/XMLParserClient.h> namespace Swift { diff --git a/Swiften/Parser/XMLParserClient.h b/Swiften/Parser/XMLParserClient.h index 089ef35..ff706a0 100644 --- a/Swiften/Parser/XMLParserClient.h +++ b/Swiften/Parser/XMLParserClient.h @@ -7,7 +7,7 @@ #ifndef XMLPARSERCLIENT_H #define XMLPARSERCLIENT_H -#include "Swiften/Parser/AttributeMap.h" +#include <Swiften/Parser/AttributeMap.h> namespace Swift { diff --git a/Swiften/Parser/XMLParserFactory.cpp b/Swiften/Parser/XMLParserFactory.cpp index 9da0747..af719bf 100644 --- a/Swiften/Parser/XMLParserFactory.cpp +++ b/Swiften/Parser/XMLParserFactory.cpp @@ -4,7 +4,7 @@ * See Documentation/Licenses/GPLv3.txt for more information. */ -#include "Swiften/Parser/XMLParserFactory.h" +#include <Swiften/Parser/XMLParserFactory.h> namespace Swift { diff --git a/Swiften/Parser/XMPPParser.cpp b/Swiften/Parser/XMPPParser.cpp index 1fb7682..62e1630 100644 --- a/Swiften/Parser/XMPPParser.cpp +++ b/Swiften/Parser/XMPPParser.cpp @@ -4,41 +4,42 @@ * See Documentation/Licenses/GPLv3.txt for more information. */ -#include "Swiften/Parser/XMPPParser.h" +#include <Swiften/Parser/XMPPParser.h> #include <iostream> #include <cassert> -#include "Swiften/Elements/ProtocolHeader.h" +#include <Swiften/Elements/ProtocolHeader.h> #include <string> -#include "Swiften/Parser/XMLParser.h" -#include "Swiften/Parser/PlatformXMLParserFactory.h" -#include "Swiften/Parser/XMPPParserClient.h" -#include "Swiften/Parser/XMPPParser.h" -#include "Swiften/Parser/ElementParser.h" -#include "Swiften/Parser/PresenceParser.h" -#include "Swiften/Parser/IQParser.h" -#include "Swiften/Parser/MessageParser.h" -#include "Swiften/Parser/StreamFeaturesParser.h" -#include "Swiften/Parser/StreamErrorParser.h" -#include "Swiften/Parser/AuthRequestParser.h" -#include "Swiften/Parser/AuthSuccessParser.h" -#include "Swiften/Parser/AuthFailureParser.h" -#include "Swiften/Parser/AuthChallengeParser.h" -#include "Swiften/Parser/AuthResponseParser.h" -#include "Swiften/Parser/EnableStreamManagementParser.h" -#include "Swiften/Parser/StreamManagementEnabledParser.h" -#include "Swiften/Parser/StreamManagementFailedParser.h" -#include "Swiften/Parser/StanzaAckParser.h" -#include "Swiften/Parser/StanzaAckRequestParser.h" -#include "Swiften/Parser/StartTLSParser.h" -#include "Swiften/Parser/StartTLSFailureParser.h" -#include "Swiften/Parser/CompressParser.h" -#include "Swiften/Parser/CompressFailureParser.h" -#include "Swiften/Parser/CompressedParser.h" -#include "Swiften/Parser/UnknownElementParser.h" -#include "Swiften/Parser/TLSProceedParser.h" -#include "Swiften/Parser/ComponentHandshakeParser.h" +#include <Swiften/Parser/XMLParser.h> +#include <Swiften/Parser/PlatformXMLParserFactory.h> +#include <Swiften/Parser/XMPPParserClient.h> +#include <Swiften/Parser/XMPPParser.h> +#include <Swiften/Parser/ElementParser.h> +#include <Swiften/Parser/PresenceParser.h> +#include <Swiften/Parser/IQParser.h> +#include <Swiften/Parser/MessageParser.h> +#include <Swiften/Parser/StreamFeaturesParser.h> +#include <Swiften/Parser/StreamErrorParser.h> +#include <Swiften/Parser/AuthRequestParser.h> +#include <Swiften/Parser/AuthSuccessParser.h> +#include <Swiften/Parser/AuthFailureParser.h> +#include <Swiften/Parser/AuthChallengeParser.h> +#include <Swiften/Parser/AuthResponseParser.h> +#include <Swiften/Parser/EnableStreamManagementParser.h> +#include <Swiften/Parser/StreamManagementEnabledParser.h> +#include <Swiften/Parser/StreamManagementFailedParser.h> +#include <Swiften/Parser/StreamResumeParser.h> +#include <Swiften/Parser/StanzaAckParser.h> +#include <Swiften/Parser/StanzaAckRequestParser.h> +#include <Swiften/Parser/StartTLSParser.h> +#include <Swiften/Parser/StartTLSFailureParser.h> +#include <Swiften/Parser/CompressParser.h> +#include <Swiften/Parser/CompressFailureParser.h> +#include <Swiften/Parser/CompressedParser.h> +#include <Swiften/Parser/UnknownElementParser.h> +#include <Swiften/Parser/TLSProceedParser.h> +#include <Swiften/Parser/ComponentHandshakeParser.h> // TODO: Whenever an error occurs in the handlers, stop the parser by returing // a bool value, and stopping the XML parser @@ -182,6 +183,12 @@ ElementParser* XMPPParser::createElementParser(const std::string& element, const else if (element == "failed" && ns == "urn:xmpp:sm:2") { return new StreamManagementFailedParser(); } + else if (element == "resume" && ns == "urn:xmpp:sm:2") { + return new StreamResumeParser(); + } + else if (element == "resumed" && ns == "urn:xmpp:sm:2") { + return new StreamResumeParser(); + } else if (element == "a" && ns == "urn:xmpp:sm:2") { return new StanzaAckParser(); } diff --git a/Swiften/Parser/XMPPParser.h b/Swiften/Parser/XMPPParser.h index 8a00995..eedbfc4 100644 --- a/Swiften/Parser/XMPPParser.h +++ b/Swiften/Parser/XMPPParser.h @@ -10,8 +10,8 @@ #include <boost/shared_ptr.hpp> #include <boost/noncopyable.hpp> -#include "Swiften/Parser/XMLParserClient.h" -#include "Swiften/Parser/AttributeMap.h" +#include <Swiften/Parser/XMLParserClient.h> +#include <Swiften/Parser/AttributeMap.h> namespace Swift { class XMLParser; diff --git a/Swiften/Parser/XMPPParserClient.cpp b/Swiften/Parser/XMPPParserClient.cpp index 3761e4f..4b7da04 100644 --- a/Swiften/Parser/XMPPParserClient.cpp +++ b/Swiften/Parser/XMPPParserClient.cpp @@ -4,7 +4,7 @@ * See Documentation/Licenses/GPLv3.txt for more information. */ -#include "Swiften/Parser/XMPPParserClient.h" +#include <Swiften/Parser/XMPPParserClient.h> namespace Swift { diff --git a/Swiften/Parser/XMPPParserClient.h b/Swiften/Parser/XMPPParserClient.h index 1ddb86d..e613f8e 100644 --- a/Swiften/Parser/XMPPParserClient.h +++ b/Swiften/Parser/XMPPParserClient.h @@ -8,7 +8,7 @@ #include <boost/shared_ptr.hpp> -#include "Swiften/Elements/Element.h" +#include <Swiften/Elements/Element.h> namespace Swift { diff --git a/Swiften/Presence/DirectedPresenceSender.cpp b/Swiften/Presence/DirectedPresenceSender.cpp index d824554..ec0bd3f 100644 --- a/Swiften/Presence/DirectedPresenceSender.cpp +++ b/Swiften/Presence/DirectedPresenceSender.cpp @@ -4,8 +4,8 @@ * See Documentation/Licenses/GPLv3.txt for more information. */ -#include "Swiften/Presence/DirectedPresenceSender.h" -#include "Swiften/Base/foreach.h" +#include <Swiften/Presence/DirectedPresenceSender.h> +#include <Swiften/Base/foreach.h> namespace Swift { diff --git a/Swiften/Presence/DirectedPresenceSender.h b/Swiften/Presence/DirectedPresenceSender.h index 207de3e..7dbdd37 100644 --- a/Swiften/Presence/DirectedPresenceSender.h +++ b/Swiften/Presence/DirectedPresenceSender.h @@ -8,8 +8,8 @@ #include <set> -#include "Swiften/Elements/Presence.h" -#include "Swiften/Presence/PresenceSender.h" +#include <Swiften/Elements/Presence.h> +#include <Swiften/Presence/PresenceSender.h> namespace Swift { class DirectedPresenceSender : public PresenceSender { diff --git a/Swiften/Presence/PayloadAddingPresenceSender.cpp b/Swiften/Presence/PayloadAddingPresenceSender.cpp index c3d1638..1ece32a 100644 --- a/Swiften/Presence/PayloadAddingPresenceSender.cpp +++ b/Swiften/Presence/PayloadAddingPresenceSender.cpp @@ -4,7 +4,7 @@ * See Documentation/Licenses/GPLv3.txt for more information. */ -#include "Swiften/Presence/PayloadAddingPresenceSender.h" +#include <Swiften/Presence/PayloadAddingPresenceSender.h> namespace Swift { @@ -34,7 +34,7 @@ bool PayloadAddingPresenceSender::isAvailable() const { return sender->isAvailable(); } -void PayloadAddingPresenceSender::setPayload(Payload::ref payload) { +void PayloadAddingPresenceSender::setPayload(boost::shared_ptr<Payload> payload) { this->payload = payload; if (lastSentPresence) { sendPresence(lastSentPresence); diff --git a/Swiften/Presence/PayloadAddingPresenceSender.h b/Swiften/Presence/PayloadAddingPresenceSender.h index ae82970..ddd460e 100644 --- a/Swiften/Presence/PayloadAddingPresenceSender.h +++ b/Swiften/Presence/PayloadAddingPresenceSender.h @@ -6,8 +6,8 @@ #pragma once -#include "Swiften/Presence/PresenceSender.h" -#include "Swiften/Elements/Payload.h" +#include <Swiften/Presence/PresenceSender.h> +#include <Swiften/Elements/Payload.h> namespace Swift { class StanzaChannel; @@ -21,7 +21,7 @@ namespace Swift { public: PayloadAddingPresenceSender(PresenceSender*); - void sendPresence(Presence::ref); + void sendPresence(boost::shared_ptr<Presence>); bool isAvailable() const; /** @@ -30,11 +30,11 @@ namespace Swift { * with an updated payload. Initial presence is reset when unavailable presence is * sent. */ - void setPayload(Payload::ref); + void setPayload(boost::shared_ptr<Payload>); private: - Presence::ref lastSentPresence; + boost::shared_ptr<Presence> lastSentPresence; PresenceSender* sender; - Payload::ref payload; + boost::shared_ptr<Payload> payload; }; } diff --git a/Swiften/Presence/PresenceOracle.cpp b/Swiften/Presence/PresenceOracle.cpp index 90e403c..1ad6fbf 100644 --- a/Swiften/Presence/PresenceOracle.cpp +++ b/Swiften/Presence/PresenceOracle.cpp @@ -8,7 +8,7 @@ #include <boost/bind.hpp> -#include "Swiften/Client/StanzaChannel.h" +#include <Swiften/Client/StanzaChannel.h> namespace Swift { diff --git a/Swiften/Presence/PresenceOracle.h b/Swiften/Presence/PresenceOracle.h index f98e1cd..09126ea 100644 --- a/Swiften/Presence/PresenceOracle.h +++ b/Swiften/Presence/PresenceOracle.h @@ -9,9 +9,9 @@ #include <map> #include <string> -#include "Swiften/Elements/Presence.h" +#include <Swiften/Elements/Presence.h> -#include "Swiften/Base/boost_bsignals.h" +#include <Swiften/Base/boost_bsignals.h> namespace Swift { class StanzaChannel; diff --git a/Swiften/Presence/PresenceSender.cpp b/Swiften/Presence/PresenceSender.cpp index 50d75eb..b75141d 100644 --- a/Swiften/Presence/PresenceSender.cpp +++ b/Swiften/Presence/PresenceSender.cpp @@ -4,7 +4,7 @@ * See Documentation/Licenses/GPLv3.txt for more information. */ -#include "Swiften/Presence/PresenceSender.h" +#include <Swiften/Presence/PresenceSender.h> namespace Swift { diff --git a/Swiften/Presence/PresenceSender.h b/Swiften/Presence/PresenceSender.h index 5abf2f3..c302074 100644 --- a/Swiften/Presence/PresenceSender.h +++ b/Swiften/Presence/PresenceSender.h @@ -6,7 +6,7 @@ #pragma once -#include "Swiften/Elements/Presence.h" +#include <Swiften/Elements/Presence.h> namespace Swift { class PresenceSender { diff --git a/Swiften/Presence/StanzaChannelPresenceSender.cpp b/Swiften/Presence/StanzaChannelPresenceSender.cpp index 654b7e7..5863a2d 100644 --- a/Swiften/Presence/StanzaChannelPresenceSender.cpp +++ b/Swiften/Presence/StanzaChannelPresenceSender.cpp @@ -4,8 +4,8 @@ * See Documentation/Licenses/GPLv3.txt for more information. */ -#include "Swiften/Presence/StanzaChannelPresenceSender.h" -#include "Swiften/Client/StanzaChannel.h" +#include <Swiften/Presence/StanzaChannelPresenceSender.h> +#include <Swiften/Client/StanzaChannel.h> namespace Swift { diff --git a/Swiften/Presence/StanzaChannelPresenceSender.h b/Swiften/Presence/StanzaChannelPresenceSender.h index 23230ab..d60d29d 100644 --- a/Swiften/Presence/StanzaChannelPresenceSender.h +++ b/Swiften/Presence/StanzaChannelPresenceSender.h @@ -6,7 +6,7 @@ #pragma once -#include "Swiften/Presence/PresenceSender.h" +#include <Swiften/Presence/PresenceSender.h> namespace Swift { class StanzaChannel; diff --git a/Swiften/Presence/SubscriptionManager.cpp b/Swiften/Presence/SubscriptionManager.cpp index 004309e..01525dd 100644 --- a/Swiften/Presence/SubscriptionManager.cpp +++ b/Swiften/Presence/SubscriptionManager.cpp @@ -4,12 +4,12 @@ * See Documentation/Licenses/GPLv3.txt for more information. */ -#include "Swiften/Presence/SubscriptionManager.h" +#include <Swiften/Presence/SubscriptionManager.h> #include <boost/bind.hpp> -#include "Swiften/Base/foreach.h" -#include "Swiften/Client/StanzaChannel.h" +#include <Swiften/Base/foreach.h> +#include <Swiften/Client/StanzaChannel.h> namespace Swift { diff --git a/Swiften/Presence/SubscriptionManager.h b/Swiften/Presence/SubscriptionManager.h index ad55f9d..efa3e1c 100644 --- a/Swiften/Presence/SubscriptionManager.h +++ b/Swiften/Presence/SubscriptionManager.h @@ -9,9 +9,9 @@ #include <map> #include <string> -#include "Swiften/JID/JID.h" -#include "Swiften/Base/boost_bsignals.h" -#include "Swiften/Elements/Presence.h" +#include <Swiften/JID/JID.h> +#include <Swiften/Base/boost_bsignals.h> +#include <Swiften/Elements/Presence.h> namespace Swift { class StanzaChannel; diff --git a/Swiften/Presence/UnitTest/DirectedPresenceSenderTest.cpp b/Swiften/Presence/UnitTest/DirectedPresenceSenderTest.cpp index 80f5ebd..a6910a1 100644 --- a/Swiften/Presence/UnitTest/DirectedPresenceSenderTest.cpp +++ b/Swiften/Presence/UnitTest/DirectedPresenceSenderTest.cpp @@ -7,9 +7,9 @@ #include <cppunit/extensions/HelperMacros.h> #include <cppunit/extensions/TestFactoryRegistry.h> -#include "Swiften/Client/DummyStanzaChannel.h" -#include "Swiften/Presence/DirectedPresenceSender.h" -#include "Swiften/Presence/StanzaChannelPresenceSender.h" +#include <Swiften/Client/DummyStanzaChannel.h> +#include <Swiften/Presence/DirectedPresenceSender.h> +#include <Swiften/Presence/StanzaChannelPresenceSender.h> using namespace Swift; diff --git a/Swiften/Presence/UnitTest/PayloadAddingPresenceSenderTest.cpp b/Swiften/Presence/UnitTest/PayloadAddingPresenceSenderTest.cpp index 132c865..bfdc8c4 100644 --- a/Swiften/Presence/UnitTest/PayloadAddingPresenceSenderTest.cpp +++ b/Swiften/Presence/UnitTest/PayloadAddingPresenceSenderTest.cpp @@ -9,10 +9,10 @@ #include <vector> #include <boost/bind.hpp> -#include "Swiften/Presence/PayloadAddingPresenceSender.h" -#include "Swiften/Presence/StanzaChannelPresenceSender.h" -#include "Swiften/Elements/Body.h" -#include "Swiften/Client/DummyStanzaChannel.h" +#include <Swiften/Presence/PayloadAddingPresenceSender.h> +#include <Swiften/Presence/StanzaChannelPresenceSender.h> +#include <Swiften/Elements/Body.h> +#include <Swiften/Client/DummyStanzaChannel.h> using namespace Swift; diff --git a/Swiften/Presence/UnitTest/PresenceOracleTest.cpp b/Swiften/Presence/UnitTest/PresenceOracleTest.cpp index 24cc62c..179538e 100644 --- a/Swiften/Presence/UnitTest/PresenceOracleTest.cpp +++ b/Swiften/Presence/UnitTest/PresenceOracleTest.cpp @@ -9,9 +9,9 @@ #include <boost/bind.hpp> #include <boost/shared_ptr.hpp> -#include "Swiften/Presence/PresenceOracle.h" -#include "Swiften/Client/DummyStanzaChannel.h" -#include "Swiften/Presence/SubscriptionManager.h" +#include <Swiften/Presence/PresenceOracle.h> +#include <Swiften/Client/DummyStanzaChannel.h> +#include <Swiften/Presence/SubscriptionManager.h> using namespace Swift; diff --git a/Swiften/QA/ClientTest/ClientTest.cpp b/Swiften/QA/ClientTest/ClientTest.cpp index 35bb096..584f644 100644 --- a/Swiften/QA/ClientTest/ClientTest.cpp +++ b/Swiften/QA/ClientTest/ClientTest.cpp @@ -6,14 +6,15 @@ #include <boost/bind.hpp> #include <boost/thread.hpp> +#include <iostream> -#include "Swiften/Client/Client.h" -#include "Swiften/Network/TimerFactory.h" -#include "Swiften/Network/BoostNetworkFactories.h" -#include "Swiften/EventLoop/EventLoop.h" -#include "Swiften/EventLoop/SimpleEventLoop.h" -#include "Swiften/Roster/GetRosterRequest.h" -#include "Swiften/Client/ClientXMLTracer.h" +#include <Swiften/Client/Client.h> +#include <Swiften/Network/TimerFactory.h> +#include <Swiften/Network/BoostNetworkFactories.h> +#include <Swiften/EventLoop/EventLoop.h> +#include <Swiften/EventLoop/SimpleEventLoop.h> +#include <Swiften/Roster/GetRosterRequest.h> +#include <Swiften/Client/ClientXMLTracer.h> using namespace Swift; diff --git a/Swiften/QA/DNSSDTest/DNSSDTest.cpp b/Swiften/QA/DNSSDTest/DNSSDTest.cpp index 1bf0965..65daa6e 100644 --- a/Swiften/QA/DNSSDTest/DNSSDTest.cpp +++ b/Swiften/QA/DNSSDTest/DNSSDTest.cpp @@ -11,16 +11,16 @@ #include <algorithm> -#include "Swiften/Base/sleep.h" -#include "Swiften/Base/ByteArray.h" -#include "Swiften/EventLoop/DummyEventLoop.h" -#include "Swiften/LinkLocal/LinkLocalServiceInfo.h" -#include "Swiften/LinkLocal/DNSSD/DNSSDQuerier.h" -#include "Swiften/LinkLocal/DNSSD/DNSSDBrowseQuery.h" -#include "Swiften/LinkLocal/DNSSD/DNSSDRegisterQuery.h" -#include "Swiften/LinkLocal/DNSSD/DNSSDResolveServiceQuery.h" +#include <Swiften/Base/sleep.h> +#include <Swiften/Base/ByteArray.h> +#include <Swiften/EventLoop/DummyEventLoop.h> +#include <Swiften/LinkLocal/LinkLocalServiceInfo.h> +#include <Swiften/LinkLocal/DNSSD/DNSSDQuerier.h> +#include <Swiften/LinkLocal/DNSSD/DNSSDBrowseQuery.h> +#include <Swiften/LinkLocal/DNSSD/DNSSDRegisterQuery.h> +#include <Swiften/LinkLocal/DNSSD/DNSSDResolveServiceQuery.h> #ifdef HAVE_AVAHI -#include "Swiften/LinkLocal/DNSSD/Avahi/AvahiQuerier.h" +#include <Swiften/LinkLocal/DNSSD/Avahi/AvahiQuerier.h> #endif #define SLEEP_INTERVALS 20 diff --git a/Swiften/QA/NetworkTest/BoostConnectionServerTest.cpp b/Swiften/QA/NetworkTest/BoostConnectionServerTest.cpp index 82a8be2..14da358 100644 --- a/Swiften/QA/NetworkTest/BoostConnectionServerTest.cpp +++ b/Swiften/QA/NetworkTest/BoostConnectionServerTest.cpp @@ -9,9 +9,9 @@ #include <boost/shared_ptr.hpp> #include <string> -#include "Swiften/Network/BoostConnectionServer.h" -#include "Swiften/Network/BoostIOServiceThread.h" -#include "Swiften/EventLoop/DummyEventLoop.h" +#include <Swiften/Network/BoostConnectionServer.h> +#include <Swiften/Network/BoostIOServiceThread.h> +#include <Swiften/EventLoop/DummyEventLoop.h> using namespace Swift; diff --git a/Swiften/QA/NetworkTest/BoostConnectionTest.cpp b/Swiften/QA/NetworkTest/BoostConnectionTest.cpp index 928e3db..0929974 100644 --- a/Swiften/QA/NetworkTest/BoostConnectionTest.cpp +++ b/Swiften/QA/NetworkTest/BoostConnectionTest.cpp @@ -10,12 +10,12 @@ #include <boost/smart_ptr/make_shared.hpp> #include <string> -#include "Swiften/Base/sleep.h" -#include "Swiften/Network/BoostConnection.h" -#include "Swiften/Network/HostAddress.h" -#include "Swiften/Network/HostAddressPort.h" -#include "Swiften/Network/BoostIOServiceThread.h" -#include "Swiften/EventLoop/DummyEventLoop.h" +#include <Swiften/Base/sleep.h> +#include <Swiften/Network/BoostConnection.h> +#include <Swiften/Network/HostAddress.h> +#include <Swiften/Network/HostAddressPort.h> +#include <Swiften/Network/BoostIOServiceThread.h> +#include <Swiften/EventLoop/DummyEventLoop.h> const unsigned char* address = reinterpret_cast<const unsigned char*>("\x41\x63\xde\x89"); diff --git a/Swiften/QA/NetworkTest/DomainNameResolverTest.cpp b/Swiften/QA/NetworkTest/DomainNameResolverTest.cpp index a0a7e7b..7cb9ed3 100644 --- a/Swiften/QA/NetworkTest/DomainNameResolverTest.cpp +++ b/Swiften/QA/NetworkTest/DomainNameResolverTest.cpp @@ -10,13 +10,13 @@ #include <algorithm> -#include "Swiften/Base/sleep.h" +#include <Swiften/Base/sleep.h> #include <string> -#include "Swiften/Base/ByteArray.h" -#include "Swiften/Network/PlatformDomainNameResolver.h" -#include "Swiften/Network/DomainNameAddressQuery.h" -#include "Swiften/Network/DomainNameServiceQuery.h" -#include "Swiften/EventLoop/DummyEventLoop.h" +#include <Swiften/Base/ByteArray.h> +#include <Swiften/Network/PlatformDomainNameResolver.h> +#include <Swiften/Network/DomainNameAddressQuery.h> +#include <Swiften/Network/DomainNameServiceQuery.h> +#include <Swiften/EventLoop/DummyEventLoop.h> using namespace Swift; diff --git a/Swiften/QA/ProxyProviderTest/.gitignore b/Swiften/QA/ProxyProviderTest/.gitignore new file mode 100644 index 0000000..9d4b9b8 --- /dev/null +++ b/Swiften/QA/ProxyProviderTest/.gitignore @@ -0,0 +1 @@ +ProxyProviderTest diff --git a/Swiften/QA/ProxyProviderTest/ProxyProviderTest.cpp b/Swiften/QA/ProxyProviderTest/ProxyProviderTest.cpp new file mode 100644 index 0000000..ddaee01 --- /dev/null +++ b/Swiften/QA/ProxyProviderTest/ProxyProviderTest.cpp @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2010 Thilo Cestonaro + * Licensed under the BSD License. + * See Documentation/Licenses/BSD.txt for more information. + */ + +#include <iostream> + +#include <Swiften/Network/PlatformProxyProvider.h> +#include <Swiften/Base/foreach.h> + +using namespace Swift; + +int main(void) +{ + int ret = 0; + HostAddressPort hap; + + std::cout << "constructing PlatfromProxyProvider instance ..." << std::endl; + PlatformProxyProvider ppp; + + hap = ppp.getSOCKS5Proxy(); + std::cout << "SOCKS5 Proxy configured: " << hap.isValid() << std::endl; + if(hap.isValid()) { + std::cout << "SOCKS5 Proxy: " << hap.getAddress().toString() << ":" << hap.getPort() << std::endl; + } + + hap = ppp.getHTTPConnectProxy(); + std::cout << "HTTPConnect Proxy configured: " << hap.isValid() << std::endl; + if(hap.isValid()) { + std::cout << "HTTPConnect Proxy: " << hap.getAddress().toString() << ":" << hap.getPort() << std::endl; + } + + return ret; +} diff --git a/Swiften/QA/ProxyProviderTest/SConscript b/Swiften/QA/ProxyProviderTest/SConscript new file mode 100644 index 0000000..2eb123d --- /dev/null +++ b/Swiften/QA/ProxyProviderTest/SConscript @@ -0,0 +1,11 @@ +import os + +Import("env") + +myenv = env.Clone() +myenv.MergeFlags(myenv["SWIFTEN_FLAGS"]) +myenv.MergeFlags(myenv["SWIFTEN_DEP_FLAGS"]) + +myenv.Program("ProxyProviderTest", [ + "ProxyProviderTest.cpp", + ]) diff --git a/Swiften/QA/ReconnectTest/ReconnectTest.cpp b/Swiften/QA/ReconnectTest/ReconnectTest.cpp index 117cfa3..933d5d2 100644 --- a/Swiften/QA/ReconnectTest/ReconnectTest.cpp +++ b/Swiften/QA/ReconnectTest/ReconnectTest.cpp @@ -7,14 +7,14 @@ #include <boost/bind.hpp> #include <boost/thread.hpp> -#include "Swiften/Client/Client.h" -#include "Swiften/Network/BoostTimer.h" -#include "Swiften/EventLoop/EventLoop.h" -#include "Swiften/EventLoop/SimpleEventLoop.h" -#include "Swiften/Roster/GetRosterRequest.h" -#include "Swiften/Client/ClientXMLTracer.h" -#include "Swiften/Network/BoostIOServiceThread.h" -#include "Swiften/Network/MainBoostIOServiceThread.h" +#include <Swiften/Client/Client.h> +#include <Swiften/Network/BoostTimer.h> +#include <Swiften/EventLoop/EventLoop.h> +#include <Swiften/EventLoop/SimpleEventLoop.h> +#include <Swiften/Roster/GetRosterRequest.h> +#include <Swiften/Client/ClientXMLTracer.h> +#include <Swiften/Network/BoostIOServiceThread.h> +#include <Swiften/Network/MainBoostIOServiceThread.h> using namespace Swift; diff --git a/Swiften/QA/SConscript b/Swiften/QA/SConscript index 25ba814..2f2be6e 100644 --- a/Swiften/QA/SConscript +++ b/Swiften/QA/SConscript @@ -5,7 +5,8 @@ SConscript(dirs = [ # "ReconnectTest", "ClientTest", # "DNSSDTest", - "StorageTest", +# "StorageTest", "TLSTest", "ScriptedTests", + "ProxyProviderTest", ]) diff --git a/Swiften/QA/StorageTest/FileReadBytestreamTest.cpp b/Swiften/QA/StorageTest/FileReadBytestreamTest.cpp index 925c775..10a8d0d 100644 --- a/Swiften/QA/StorageTest/FileReadBytestreamTest.cpp +++ b/Swiften/QA/StorageTest/FileReadBytestreamTest.cpp @@ -7,7 +7,8 @@ #include <cppunit/extensions/HelperMacros.h> #include <cppunit/extensions/TestFactoryRegistry.h> -#include "Swiften/FileTransfer/FileReadBytestream.h" +#include <Swiften/Base/ByteArray.h> +#include <Swiften/FileTransfer/FileReadBytestream.h> #include "SwifTools/Application/PlatformApplicationPathProvider.h" using namespace Swift; @@ -32,16 +33,16 @@ class FileReadBytestreamTest : public CppUnit::TestFixture { void testRead() { std::auto_ptr<FileReadBytestream> testling(createTestling()); - ByteArray result = testling->read(10); + std::vector<unsigned char> result = testling->read(10); - CPPUNIT_ASSERT_EQUAL(std::string("/*\n * Copy"), result.toString()); + CPPUNIT_ASSERT(ByteArray::create("/*\n * Copy") == result); } void testRead_Twice() { std::auto_ptr<FileReadBytestream> testling(createTestling()); testling->read(10); - ByteArray result = testling->read(10); + ByteArray result(testling->read(10)); CPPUNIT_ASSERT_EQUAL(std::string("right (c) "), result.toString()); } diff --git a/Swiften/QA/StorageTest/VCardFileStorageTest.cpp b/Swiften/QA/StorageTest/VCardFileStorageTest.cpp index 992ee50..0a3c6d2 100644 --- a/Swiften/QA/StorageTest/VCardFileStorageTest.cpp +++ b/Swiften/QA/StorageTest/VCardFileStorageTest.cpp @@ -8,10 +8,10 @@ #include <cppunit/extensions/TestFactoryRegistry.h> #include <boost/algorithm/string.hpp> -#include "Swiften/VCards/VCardFileStorage.h" -#include "Swiften/JID/JID.h" +#include <Swiften/VCards/VCardFileStorage.h> +#include <Swiften/JID/JID.h> #include "SwifTools/Application/PlatformApplicationPathProvider.h" -#include "Swiften/Elements/VCard.h" +#include <Swiften/Elements/VCard.h> using namespace Swift; diff --git a/Swiften/QA/TLSTest/CertificateTest.cpp b/Swiften/QA/TLSTest/CertificateTest.cpp index 0f37fde..dff065f 100644 --- a/Swiften/QA/TLSTest/CertificateTest.cpp +++ b/Swiften/QA/TLSTest/CertificateTest.cpp @@ -10,7 +10,7 @@ #include <cppunit/extensions/TestFactoryRegistry.h> #include <boost/bind.hpp> -#include "Swiften/TLS/CertificateFactory.h" +#include <Swiften/TLS/CertificateFactory.h> #include "SwifTools/Application/PlatformApplicationPathProvider.h" using namespace Swift; @@ -95,6 +95,6 @@ class CertificateTest : public CppUnit::TestFixture { }; #ifdef HAVE_OPENSSL -#include "Swiften/TLS/OpenSSL/OpenSSLCertificateFactory.h" +#include <Swiften/TLS/OpenSSL/OpenSSLCertificateFactory.h> CPPUNIT_TEST_SUITE_REGISTRATION(CertificateTest<OpenSSLCertificateFactory>); #endif diff --git a/Swiften/Queries/DummyIQChannel.h b/Swiften/Queries/DummyIQChannel.h index f740b5c..6adcdb1 100644 --- a/Swiften/Queries/DummyIQChannel.h +++ b/Swiften/Queries/DummyIQChannel.h @@ -8,7 +8,7 @@ #include <vector> -#include "Swiften/Queries/IQChannel.h" +#include <Swiften/Queries/IQChannel.h> namespace Swift { class DummyIQChannel : public IQChannel { diff --git a/Swiften/Queries/GenericRequest.h b/Swiften/Queries/GenericRequest.h index a8e3409..64c509c 100644 --- a/Swiften/Queries/GenericRequest.h +++ b/Swiften/Queries/GenericRequest.h @@ -6,9 +6,9 @@ #pragma once -#include "Swiften/Base/boost_bsignals.h" +#include <Swiften/Base/boost_bsignals.h> -#include "Swiften/Queries/Request.h" +#include <Swiften/Queries/Request.h> namespace Swift { template<typename PAYLOAD_TYPE> diff --git a/Swiften/Queries/GetResponder.h b/Swiften/Queries/GetResponder.h index ca3b677..bca507a 100644 --- a/Swiften/Queries/GetResponder.h +++ b/Swiften/Queries/GetResponder.h @@ -6,7 +6,7 @@ #pragma once -#include "Swiften/Queries/Responder.h" +#include <Swiften/Queries/Responder.h> namespace Swift { template<typename T> diff --git a/Swiften/Queries/IQChannel.cpp b/Swiften/Queries/IQChannel.cpp index 959d87d..815a617 100644 --- a/Swiften/Queries/IQChannel.cpp +++ b/Swiften/Queries/IQChannel.cpp @@ -4,7 +4,7 @@ * See Documentation/Licenses/GPLv3.txt for more information. */ -#include "Swiften/Queries/IQChannel.h" +#include <Swiften/Queries/IQChannel.h> namespace Swift { diff --git a/Swiften/Queries/IQChannel.h b/Swiften/Queries/IQChannel.h index 22b7572..afeb588 100644 --- a/Swiften/Queries/IQChannel.h +++ b/Swiften/Queries/IQChannel.h @@ -7,11 +7,11 @@ #ifndef SWIFTEN_IQChannel_H #define SWIFTEN_IQChannel_H -#include "Swiften/Base/boost_bsignals.h" +#include <Swiften/Base/boost_bsignals.h> #include <boost/shared_ptr.hpp> #include <string> -#include "Swiften/Elements/IQ.h" +#include <Swiften/Elements/IQ.h> namespace Swift { class IQChannel { diff --git a/Swiften/Queries/IQHandler.cpp b/Swiften/Queries/IQHandler.cpp index fe65c71..01e4387 100644 --- a/Swiften/Queries/IQHandler.cpp +++ b/Swiften/Queries/IQHandler.cpp @@ -4,8 +4,8 @@ * See Documentation/Licenses/GPLv3.txt for more information. */ -#include "Swiften/Queries/IQHandler.h" -#include "Swiften/Queries/IQRouter.h" +#include <Swiften/Queries/IQHandler.h> +#include <Swiften/Queries/IQRouter.h> namespace Swift { diff --git a/Swiften/Queries/IQHandler.h b/Swiften/Queries/IQHandler.h index 616f9fa..1d6c968 100644 --- a/Swiften/Queries/IQHandler.h +++ b/Swiften/Queries/IQHandler.h @@ -9,7 +9,7 @@ #include <boost/shared_ptr.hpp> -#include "Swiften/Elements/IQ.h" +#include <Swiften/Elements/IQ.h> namespace Swift { class IQRouter; diff --git a/Swiften/Queries/IQRouter.cpp b/Swiften/Queries/IQRouter.cpp index 1bfff70..4e23389 100644 --- a/Swiften/Queries/IQRouter.cpp +++ b/Swiften/Queries/IQRouter.cpp @@ -4,15 +4,15 @@ * See Documentation/Licenses/GPLv3.txt for more information. */ -#include "Swiften/Queries/IQRouter.h" +#include <Swiften/Queries/IQRouter.h> #include <algorithm> #include <boost/bind.hpp> -#include "Swiften/Base/foreach.h" -#include "Swiften/Queries/IQHandler.h" -#include "Swiften/Queries/IQChannel.h" -#include "Swiften/Elements/ErrorPayload.h" +#include <Swiften/Base/foreach.h> +#include <Swiften/Queries/IQHandler.h> +#include <Swiften/Queries/IQChannel.h> +#include <Swiften/Elements/ErrorPayload.h> namespace Swift { diff --git a/Swiften/Queries/IQRouter.h b/Swiften/Queries/IQRouter.h index 312dca8..80d623c 100644 --- a/Swiften/Queries/IQRouter.h +++ b/Swiften/Queries/IQRouter.h @@ -10,7 +10,7 @@ #include <vector> #include <string> -#include "Swiften/Elements/IQ.h" +#include <Swiften/Elements/IQ.h> namespace Swift { class IQChannel; diff --git a/Swiften/Queries/RawRequest.h b/Swiften/Queries/RawRequest.h index 477952f..e5b3a1d 100644 --- a/Swiften/Queries/RawRequest.h +++ b/Swiften/Queries/RawRequest.h @@ -31,7 +31,7 @@ namespace Swift { RawRequest(IQ::Type type, const JID& receiver, const std::string& data, IQRouter* router) : Request(type, receiver, boost::make_shared<RawXMLPayload>(data), router) { } - virtual void handleResponse(Payload::ref payload, ErrorPayload::ref error) { + virtual void handleResponse(boost::shared_ptr<Payload> payload, ErrorPayload::ref error) { if (error) { onResponse(ErrorSerializer().serializePayload(error)); } diff --git a/Swiften/Queries/Request.cpp b/Swiften/Queries/Request.cpp index 6c47725..7adf13c 100644 --- a/Swiften/Queries/Request.cpp +++ b/Swiften/Queries/Request.cpp @@ -4,8 +4,8 @@ * See Documentation/Licenses/GPLv3.txt for more information. */ -#include "Swiften/Queries/Request.h" -#include "Swiften/Queries/IQRouter.h" +#include <Swiften/Queries/Request.h> +#include <Swiften/Queries/IQRouter.h> #include <Swiften/Elements/RawXMLPayload.h> namespace Swift { diff --git a/Swiften/Queries/Request.h b/Swiften/Queries/Request.h index eee89e9..19687c1 100644 --- a/Swiften/Queries/Request.h +++ b/Swiften/Queries/Request.h @@ -4,19 +4,18 @@ * See Documentation/Licenses/GPLv3.txt for more information. */ -#ifndef SWIFTEN_Request_H -#define SWIFTEN_Request_H +#pragma once #include <boost/shared_ptr.hpp> #include <boost/optional.hpp> #include <boost/enable_shared_from_this.hpp> #include <string> -#include "Swiften/Queries/IQHandler.h" -#include "Swiften/Elements/IQ.h" -#include "Swiften/Elements/Payload.h" -#include "Swiften/Elements/ErrorPayload.h" -#include "Swiften/JID/JID.h" +#include <Swiften/Queries/IQHandler.h> +#include <Swiften/Elements/IQ.h> +#include <Swiften/Elements/Payload.h> +#include <Swiften/Elements/ErrorPayload.h> +#include <Swiften/JID/JID.h> namespace Swift { /** @@ -48,15 +47,15 @@ namespace Swift { const JID& receiver, IQRouter* router); - virtual void setPayload(Payload::ref payload) { + virtual void setPayload(boost::shared_ptr<Payload> payload) { payload_ = payload; } - Payload::ref getPayload() const { + boost::shared_ptr<Payload> getPayload() const { return payload_; } - virtual void handleResponse(Payload::ref, ErrorPayload::ref) = 0; + virtual void handleResponse(boost::shared_ptr<Payload>, boost::shared_ptr<ErrorPayload>) = 0; private: bool handleIQ(boost::shared_ptr<IQ>); @@ -70,5 +69,3 @@ namespace Swift { bool sent_; }; } - -#endif diff --git a/Swiften/Queries/Requests/GetInBandRegistrationFormRequest.cpp b/Swiften/Queries/Requests/GetInBandRegistrationFormRequest.cpp index 5f6be03..337375e 100644 --- a/Swiften/Queries/Requests/GetInBandRegistrationFormRequest.cpp +++ b/Swiften/Queries/Requests/GetInBandRegistrationFormRequest.cpp @@ -4,4 +4,4 @@ * See Documentation/Licenses/GPLv3.txt for more information. */ -#include "Swiften/Queries/Requests/GetInBandRegistrationFormRequest.h" +#include <Swiften/Queries/Requests/GetInBandRegistrationFormRequest.h> diff --git a/Swiften/Queries/Requests/GetInBandRegistrationFormRequest.h b/Swiften/Queries/Requests/GetInBandRegistrationFormRequest.h index aa0866a..c0488ad 100644 --- a/Swiften/Queries/Requests/GetInBandRegistrationFormRequest.h +++ b/Swiften/Queries/Requests/GetInBandRegistrationFormRequest.h @@ -6,8 +6,8 @@ #pragma once -#include "Swiften/Queries/GenericRequest.h" -#include "Swiften/Elements/InBandRegistrationPayload.h" +#include <Swiften/Queries/GenericRequest.h> +#include <Swiften/Elements/InBandRegistrationPayload.h> namespace Swift { diff --git a/Swiften/Queries/Requests/GetPrivateStorageRequest.h b/Swiften/Queries/Requests/GetPrivateStorageRequest.h index f0b95d8..b0eefb2 100644 --- a/Swiften/Queries/Requests/GetPrivateStorageRequest.h +++ b/Swiften/Queries/Requests/GetPrivateStorageRequest.h @@ -6,12 +6,12 @@ #pragma once -#include "Swiften/Base/boost_bsignals.h" +#include <Swiften/Base/boost_bsignals.h> #include <boost/shared_ptr.hpp> -#include "Swiften/Queries/Request.h" -#include "Swiften/Elements/PrivateStorage.h" -#include "Swiften/Elements/ErrorPayload.h" +#include <Swiften/Queries/Request.h> +#include <Swiften/Elements/PrivateStorage.h> +#include <Swiften/Elements/ErrorPayload.h> namespace Swift { template<typename PAYLOAD_TYPE> diff --git a/Swiften/Queries/Requests/GetSecurityLabelsCatalogRequest.h b/Swiften/Queries/Requests/GetSecurityLabelsCatalogRequest.h index 51794da..a6f782b 100644 --- a/Swiften/Queries/Requests/GetSecurityLabelsCatalogRequest.h +++ b/Swiften/Queries/Requests/GetSecurityLabelsCatalogRequest.h @@ -6,8 +6,8 @@ #pragma once -#include "Swiften/Queries/GenericRequest.h" -#include "Swiften/Elements/SecurityLabelsCatalog.h" +#include <Swiften/Queries/GenericRequest.h> +#include <Swiften/Elements/SecurityLabelsCatalog.h> namespace Swift { diff --git a/Swiften/Queries/Requests/GetSoftwareVersionRequest.h b/Swiften/Queries/Requests/GetSoftwareVersionRequest.h index 442ec88..18461bb 100644 --- a/Swiften/Queries/Requests/GetSoftwareVersionRequest.h +++ b/Swiften/Queries/Requests/GetSoftwareVersionRequest.h @@ -6,8 +6,8 @@ #pragma once -#include "Swiften/Queries/GenericRequest.h" -#include "Swiften/Elements/SoftwareVersion.h" +#include <Swiften/Queries/GenericRequest.h> +#include <Swiften/Elements/SoftwareVersion.h> #include <boost/smart_ptr/make_shared.hpp> diff --git a/Swiften/Queries/Requests/SetPrivateStorageRequest.h b/Swiften/Queries/Requests/SetPrivateStorageRequest.h index 69eb001..f795742 100644 --- a/Swiften/Queries/Requests/SetPrivateStorageRequest.h +++ b/Swiften/Queries/Requests/SetPrivateStorageRequest.h @@ -6,12 +6,12 @@ #pragma once -#include "Swiften/Base/boost_bsignals.h" +#include <Swiften/Base/boost_bsignals.h> #include <boost/shared_ptr.hpp> -#include "Swiften/Queries/Request.h" -#include "Swiften/Elements/PrivateStorage.h" -#include "Swiften/Elements/ErrorPayload.h" +#include <Swiften/Queries/Request.h> +#include <Swiften/Elements/PrivateStorage.h> +#include <Swiften/Elements/ErrorPayload.h> namespace Swift { template<typename PAYLOAD_TYPE> diff --git a/Swiften/Queries/Requests/SubmitInBandRegistrationFormRequest.cpp b/Swiften/Queries/Requests/SubmitInBandRegistrationFormRequest.cpp index f28c878..f010e96 100644 --- a/Swiften/Queries/Requests/SubmitInBandRegistrationFormRequest.cpp +++ b/Swiften/Queries/Requests/SubmitInBandRegistrationFormRequest.cpp @@ -4,4 +4,4 @@ * See Documentation/Licenses/GPLv3.txt for more information. */ -#include "Swiften/Queries/Requests/SubmitInBandRegistrationFormRequest.h" +#include <Swiften/Queries/Requests/SubmitInBandRegistrationFormRequest.h> diff --git a/Swiften/Queries/Requests/SubmitInBandRegistrationFormRequest.h b/Swiften/Queries/Requests/SubmitInBandRegistrationFormRequest.h index 0700c65..8e0862b 100644 --- a/Swiften/Queries/Requests/SubmitInBandRegistrationFormRequest.h +++ b/Swiften/Queries/Requests/SubmitInBandRegistrationFormRequest.h @@ -6,11 +6,11 @@ #pragma once -#include "Swiften/Base/boost_bsignals.h" +#include <Swiften/Base/boost_bsignals.h> #include <boost/shared_ptr.hpp> -#include "Swiften/Queries/Request.h" -#include "Swiften/Elements/InBandRegistrationPayload.h" +#include <Swiften/Queries/Request.h> +#include <Swiften/Elements/InBandRegistrationPayload.h> namespace Swift { @@ -26,11 +26,11 @@ namespace Swift { SetInBandRegistrationRequest(const JID& to, InBandRegistrationPayload::ref payload, IQRouter* router) : Request(IQ::Set, to, InBandRegistrationPayload::ref(payload), router) { } - virtual void handleResponse(Payload::ref payload, ErrorPayload::ref error) { + virtual void handleResponse(boost::shared_ptr<Payload> payload, ErrorPayload::ref error) { onResponse(payload, error); } public: - boost::signal<void (Payload::ref, ErrorPayload::ref)> onResponse; + boost::signal<void (boost::shared_ptr<Payload>, ErrorPayload::ref)> onResponse; }; } diff --git a/Swiften/Queries/Requests/UnitTest/GetPrivateStorageRequestTest.cpp b/Swiften/Queries/Requests/UnitTest/GetPrivateStorageRequestTest.cpp index b7c36cb..f3ecfb7 100644 --- a/Swiften/Queries/Requests/UnitTest/GetPrivateStorageRequestTest.cpp +++ b/Swiften/Queries/Requests/UnitTest/GetPrivateStorageRequestTest.cpp @@ -9,10 +9,10 @@ #include <boost/shared_ptr.hpp> #include <boost/bind.hpp> -#include "Swiften/Queries/Requests/GetPrivateStorageRequest.h" -#include "Swiften/Queries/IQRouter.h" -#include "Swiften/Queries/DummyIQChannel.h" -#include "Swiften/Elements/Payload.h" +#include <Swiften/Queries/Requests/GetPrivateStorageRequest.h> +#include <Swiften/Queries/IQRouter.h> +#include <Swiften/Queries/DummyIQChannel.h> +#include <Swiften/Elements/Payload.h> using namespace Swift; diff --git a/Swiften/Queries/Responder.h b/Swiften/Queries/Responder.h index 2ce8f10..a9aab17 100644 --- a/Swiften/Queries/Responder.h +++ b/Swiften/Queries/Responder.h @@ -6,9 +6,9 @@ #pragma once -#include "Swiften/Queries/IQHandler.h" -#include "Swiften/Queries/IQRouter.h" -#include "Swiften/Elements/ErrorPayload.h" +#include <Swiften/Queries/IQHandler.h> +#include <Swiften/Queries/IQRouter.h> +#include <Swiften/Elements/ErrorPayload.h> namespace Swift { /** diff --git a/Swiften/Queries/Responders/SoftwareVersionResponder.cpp b/Swiften/Queries/Responders/SoftwareVersionResponder.cpp index 445dcc7..3f9616a 100644 --- a/Swiften/Queries/Responders/SoftwareVersionResponder.cpp +++ b/Swiften/Queries/Responders/SoftwareVersionResponder.cpp @@ -4,8 +4,8 @@ * See Documentation/Licenses/GPLv3.txt for more information. */ -#include "Swiften/Queries/Responders/SoftwareVersionResponder.h" -#include "Swiften/Queries/IQRouter.h" +#include <Swiften/Queries/Responders/SoftwareVersionResponder.h> +#include <Swiften/Queries/IQRouter.h> namespace Swift { diff --git a/Swiften/Queries/Responders/SoftwareVersionResponder.h b/Swiften/Queries/Responders/SoftwareVersionResponder.h index cbda54c..a2929df 100644 --- a/Swiften/Queries/Responders/SoftwareVersionResponder.h +++ b/Swiften/Queries/Responders/SoftwareVersionResponder.h @@ -6,8 +6,8 @@ #pragma once -#include "Swiften/Queries/GetResponder.h" -#include "Swiften/Elements/SoftwareVersion.h" +#include <Swiften/Queries/GetResponder.h> +#include <Swiften/Elements/SoftwareVersion.h> namespace Swift { class IQRouter; diff --git a/Swiften/Queries/SetResponder.h b/Swiften/Queries/SetResponder.h index ec3460c..331aa46 100644 --- a/Swiften/Queries/SetResponder.h +++ b/Swiften/Queries/SetResponder.h @@ -6,7 +6,7 @@ #pragma once -#include "Swiften/Queries/Responder.h" +#include <Swiften/Queries/Responder.h> namespace Swift { template<typename T> diff --git a/Swiften/Queries/UnitTest/IQRouterTest.cpp b/Swiften/Queries/UnitTest/IQRouterTest.cpp index ef5da23..f06b967 100644 --- a/Swiften/Queries/UnitTest/IQRouterTest.cpp +++ b/Swiften/Queries/UnitTest/IQRouterTest.cpp @@ -9,9 +9,9 @@ #include <boost/shared_ptr.hpp> #include <boost/bind.hpp> -#include "Swiften/Queries/IQHandler.h" -#include "Swiften/Queries/IQRouter.h" -#include "Swiften/Queries/DummyIQChannel.h" +#include <Swiften/Queries/IQHandler.h> +#include <Swiften/Queries/IQRouter.h> +#include <Swiften/Queries/DummyIQChannel.h> using namespace Swift; diff --git a/Swiften/Queries/UnitTest/RequestTest.cpp b/Swiften/Queries/UnitTest/RequestTest.cpp index 34d07c9..c2e2390 100644 --- a/Swiften/Queries/UnitTest/RequestTest.cpp +++ b/Swiften/Queries/UnitTest/RequestTest.cpp @@ -10,10 +10,10 @@ #include <boost/bind.hpp> #include <boost/smart_ptr/make_shared.hpp> -#include "Swiften/Queries/GenericRequest.h" -#include "Swiften/Queries/IQRouter.h" -#include "Swiften/Queries/DummyIQChannel.h" -#include "Swiften/Elements/Payload.h" +#include <Swiften/Queries/GenericRequest.h> +#include <Swiften/Queries/IQRouter.h> +#include <Swiften/Queries/DummyIQChannel.h> +#include <Swiften/Elements/Payload.h> #include <Swiften/Elements/RawXMLPayload.h> using namespace Swift; diff --git a/Swiften/Queries/UnitTest/ResponderTest.cpp b/Swiften/Queries/UnitTest/ResponderTest.cpp index c087827..a256346 100644 --- a/Swiften/Queries/UnitTest/ResponderTest.cpp +++ b/Swiften/Queries/UnitTest/ResponderTest.cpp @@ -9,10 +9,10 @@ #include <boost/shared_ptr.hpp> #include <boost/bind.hpp> -#include "Swiften/Queries/Responder.h" -#include "Swiften/Queries/IQRouter.h" -#include "Swiften/Queries/DummyIQChannel.h" -#include "Swiften/Elements/SoftwareVersion.h" +#include <Swiften/Queries/Responder.h> +#include <Swiften/Queries/IQRouter.h> +#include <Swiften/Queries/DummyIQChannel.h> +#include <Swiften/Elements/SoftwareVersion.h> using namespace Swift; diff --git a/Swiften/Roster/GetRosterRequest.h b/Swiften/Roster/GetRosterRequest.h index 00cf77f..e7146d2 100644 --- a/Swiften/Roster/GetRosterRequest.h +++ b/Swiften/Roster/GetRosterRequest.h @@ -6,8 +6,8 @@ #pragma once -#include "Swiften/Queries/GenericRequest.h" -#include "Swiften/Elements/RosterPayload.h" +#include <Swiften/Queries/GenericRequest.h> +#include <Swiften/Elements/RosterPayload.h> namespace Swift { @@ -19,6 +19,12 @@ namespace Swift { return ref(new GetRosterRequest(router)); } + static ref create(IQRouter* router, const std::string& version) { + ref result(new GetRosterRequest(router)); + result->getPayloadGeneric()->setVersion(version); + return result; + } + private: GetRosterRequest(IQRouter* router) : GenericRequest<RosterPayload>(IQ::Get, JID(), boost::shared_ptr<Payload>(new RosterPayload()), router) { diff --git a/Swiften/Roster/RosterMemoryStorage.cpp b/Swiften/Roster/RosterMemoryStorage.cpp new file mode 100644 index 0000000..cbf4563 --- /dev/null +++ b/Swiften/Roster/RosterMemoryStorage.cpp @@ -0,0 +1,23 @@ +/* + * Copyright (c) 2011 Remko Tronçon + * Licensed under the GNU General Public License v3. + * See Documentation/Licenses/GPLv3.txt for more information. + */ + +#include <Swiften/Roster/RosterMemoryStorage.h> + +#include <boost/smart_ptr/make_shared.hpp> + +namespace Swift { + +RosterMemoryStorage::RosterMemoryStorage() { +} + +void RosterMemoryStorage::setRoster(boost::shared_ptr<RosterPayload> r) { + roster.reset(); + if (r) { + roster = boost::make_shared<RosterPayload>(*r); + } +} + +} diff --git a/Swiften/Roster/RosterMemoryStorage.h b/Swiften/Roster/RosterMemoryStorage.h new file mode 100644 index 0000000..b659d77 --- /dev/null +++ b/Swiften/Roster/RosterMemoryStorage.h @@ -0,0 +1,25 @@ +/* + * Copyright (c) 2011 Remko Tronçon + * Licensed under the GNU General Public License v3. + * See Documentation/Licenses/GPLv3.txt for more information. + */ + +#pragma once + +#include <Swiften/Roster/RosterStorage.h> + +namespace Swift { + class RosterMemoryStorage : public RosterStorage { + public: + RosterMemoryStorage(); + + virtual boost::shared_ptr<RosterPayload> getRoster() const { + return roster; + } + + virtual void setRoster(boost::shared_ptr<RosterPayload>); + + private: + boost::shared_ptr<RosterPayload> roster; + }; +} diff --git a/Swiften/Roster/RosterPushResponder.h b/Swiften/Roster/RosterPushResponder.h index b38914b..7200b2d 100644 --- a/Swiften/Roster/RosterPushResponder.h +++ b/Swiften/Roster/RosterPushResponder.h @@ -6,10 +6,10 @@ #pragma once -#include "Swiften/Base/boost_bsignals.h" +#include <Swiften/Base/boost_bsignals.h> -#include "Swiften/Queries/SetResponder.h" -#include "Swiften/Elements/RosterPayload.h" +#include <Swiften/Queries/SetResponder.h> +#include <Swiften/Elements/RosterPayload.h> namespace Swift { class RosterPushResponder : public SetResponder<RosterPayload> { diff --git a/Swiften/Roster/RosterStorage.cpp b/Swiften/Roster/RosterStorage.cpp new file mode 100644 index 0000000..6bf58de --- /dev/null +++ b/Swiften/Roster/RosterStorage.cpp @@ -0,0 +1,14 @@ +/* + * Copyright (c) 2011 Remko Tronçon + * Licensed under the GNU General Public License v3. + * See Documentation/Licenses/GPLv3.txt for more information. + */ + +#include <Swiften/Roster/RosterStorage.h> + +namespace Swift { + +RosterStorage::~RosterStorage() { +} + +} diff --git a/Swiften/Roster/RosterStorage.h b/Swiften/Roster/RosterStorage.h new file mode 100644 index 0000000..ba24cb3 --- /dev/null +++ b/Swiften/Roster/RosterStorage.h @@ -0,0 +1,21 @@ +/* + * Copyright (c) 2011 Remko Tronçon + * Licensed under the GNU General Public License v3. + * See Documentation/Licenses/GPLv3.txt for more information. + */ + +#pragma once + +#include <boost/shared_ptr.hpp> + +#include <Swiften/Elements/RosterPayload.h> + +namespace Swift { + class RosterStorage { + public: + virtual ~RosterStorage(); + + virtual boost::shared_ptr<RosterPayload> getRoster() const = 0; + virtual void setRoster(boost::shared_ptr<RosterPayload>) = 0; + }; +} diff --git a/Swiften/Roster/SetRosterRequest.h b/Swiften/Roster/SetRosterRequest.h index e5ae974..6f4d79d 100644 --- a/Swiften/Roster/SetRosterRequest.h +++ b/Swiften/Roster/SetRosterRequest.h @@ -6,11 +6,11 @@ #pragma once -#include "Swiften/Base/boost_bsignals.h" +#include <Swiften/Base/boost_bsignals.h> #include <boost/shared_ptr.hpp> -#include "Swiften/Queries/Request.h" -#include "Swiften/Elements/RosterPayload.h" +#include <Swiften/Queries/Request.h> +#include <Swiften/Elements/RosterPayload.h> namespace Swift { @@ -19,11 +19,15 @@ namespace Swift { typedef boost::shared_ptr<SetRosterRequest> ref; static ref create(RosterPayload::ref payload, IQRouter* router) { - return ref(new SetRosterRequest(payload, router)); + return ref(new SetRosterRequest(JID(), payload, router)); + } + + static ref create(RosterPayload::ref payload, const JID& to, IQRouter* router) { + return ref(new SetRosterRequest(to, payload, router)); } private: - SetRosterRequest(boost::shared_ptr<RosterPayload> payload, IQRouter* router) : Request(IQ::Set, JID(), boost::shared_ptr<RosterPayload>(payload), router) { + SetRosterRequest(const JID& to, boost::shared_ptr<RosterPayload> payload, IQRouter* router) : Request(IQ::Set, to, boost::shared_ptr<RosterPayload>(payload), router) { } virtual void handleResponse(boost::shared_ptr<Payload> /*payload*/, ErrorPayload::ref error) { diff --git a/Swiften/Roster/UnitTest/XMPPRosterControllerTest.cpp b/Swiften/Roster/UnitTest/XMPPRosterControllerTest.cpp index 4ef1cc1..e0f2859 100644 --- a/Swiften/Roster/UnitTest/XMPPRosterControllerTest.cpp +++ b/Swiften/Roster/UnitTest/XMPPRosterControllerTest.cpp @@ -8,23 +8,32 @@ #include <cppunit/extensions/TestFactoryRegistry.h> #include <boost/smart_ptr/make_shared.hpp> -#include "Swiften/Roster/UnitTest/XMPPRosterSignalHandler.h" -#include "Swiften/Roster/XMPPRosterController.h" -#include "Swiften/Elements/Payload.h" -#include "Swiften/Elements/RosterItemPayload.h" -#include "Swiften/Elements/RosterPayload.h" -#include "Swiften/Client/DummyStanzaChannel.h" -#include "Swiften/Queries/IQRouter.h" -#include "Swiften/Roster/XMPPRosterImpl.h" +#include <Swiften/Roster/UnitTest/XMPPRosterSignalHandler.h> +#include <Swiften/Roster/XMPPRosterController.h> +#include <Swiften/Elements/Payload.h> +#include <Swiften/Elements/RosterItemPayload.h> +#include <Swiften/Elements/RosterPayload.h> +#include <Swiften/Client/DummyStanzaChannel.h> +#include <Swiften/Queries/IQRouter.h> +#include <Swiften/Roster/XMPPRosterImpl.h> +#include <Swiften/Roster/RosterMemoryStorage.h> using namespace Swift; class XMPPRosterControllerTest : public CppUnit::TestFixture { CPPUNIT_TEST_SUITE(XMPPRosterControllerTest); + CPPUNIT_TEST(testGet_Response); CPPUNIT_TEST(testGet_EmptyResponse); + CPPUNIT_TEST(testGet_NoRosterInStorage); + CPPUNIT_TEST(testGet_NoVersionInStorage); + CPPUNIT_TEST(testGet_VersionInStorage); + CPPUNIT_TEST(testGet_ServerDoesNotSupportVersion); + CPPUNIT_TEST(testGet_ResponseWithoutNewVersion); + CPPUNIT_TEST(testGet_ResponseWithNewVersion); CPPUNIT_TEST(testAdd); CPPUNIT_TEST(testModify); CPPUNIT_TEST(testRemove); + CPPUNIT_TEST(testRemove_RosterStorageUpdated); CPPUNIT_TEST(testMany); CPPUNIT_TEST_SUITE_END(); @@ -34,20 +43,36 @@ class XMPPRosterControllerTest : public CppUnit::TestFixture { router_ = new IQRouter(channel_); xmppRoster_ = new XMPPRosterImpl(); handler_ = new XMPPRosterSignalHandler(xmppRoster_); + rosterStorage_ = new RosterMemoryStorage(); jid1_ = JID("foo@bar.com"); jid2_ = JID("alice@wonderland.lit"); jid3_ = JID("jane@austen.lit"); } void tearDown() { + delete rosterStorage_; delete handler_; delete xmppRoster_; delete router_; delete channel_; } + void testGet_Response() { + std::auto_ptr<XMPPRosterController> testling(createController()); + + testling->requestRoster(); + boost::shared_ptr<RosterPayload> payload = boost::make_shared<RosterPayload>(); + payload->addItem(RosterItemPayload(jid1_, "Bob", RosterItemPayload::Both)); + payload->addItem(RosterItemPayload(jid2_, "Alice", RosterItemPayload::Both)); + channel_->onIQReceived(IQ::createResult("foo@bar.com", channel_->sentStanzas[0]->getID(), payload)); + + CPPUNIT_ASSERT_EQUAL(2, handler_->getEventCount()); + CPPUNIT_ASSERT(xmppRoster_->getItem(jid1_)); + CPPUNIT_ASSERT(xmppRoster_->getItem(jid2_)); + } + void testGet_EmptyResponse() { - XMPPRosterController controller(router_, xmppRoster_); + XMPPRosterController controller(router_, xmppRoster_, rosterStorage_); controller.requestRoster(); @@ -55,7 +80,7 @@ class XMPPRosterControllerTest : public CppUnit::TestFixture { } void testAdd() { - XMPPRosterController controller(router_, xmppRoster_); + XMPPRosterController controller(router_, xmppRoster_, rosterStorage_); boost::shared_ptr<RosterPayload> payload(new RosterPayload()); payload->addItem(RosterItemPayload(jid1_, "Bob", RosterItemPayload::Both)); @@ -68,8 +93,115 @@ class XMPPRosterControllerTest : public CppUnit::TestFixture { CPPUNIT_ASSERT_EQUAL(std::string("Bob"), xmppRoster_->getNameForJID(jid1_)); } + void testGet_NoRosterInStorage() { + std::auto_ptr<XMPPRosterController> testling(createController()); + testling->setUseVersioning(true); + + testling->requestRoster(); + + boost::shared_ptr<RosterPayload> roster = channel_->sentStanzas[0]->getPayload<RosterPayload>(); + CPPUNIT_ASSERT(roster->getVersion()); + CPPUNIT_ASSERT_EQUAL(std::string(""), *roster->getVersion()); + } + + void testGet_NoVersionInStorage() { + std::auto_ptr<XMPPRosterController> testling(createController()); + testling->setUseVersioning(true); + rosterStorage_->setRoster(boost::make_shared<RosterPayload>()); + + testling->requestRoster(); + + boost::shared_ptr<RosterPayload> roster = channel_->sentStanzas[0]->getPayload<RosterPayload>(); + CPPUNIT_ASSERT(roster->getVersion()); + CPPUNIT_ASSERT_EQUAL(std::string(""), *roster->getVersion()); + } + + void testGet_VersionInStorage() { + std::auto_ptr<XMPPRosterController> testling(createController()); + testling->setUseVersioning(true); + boost::shared_ptr<RosterPayload> payload(new RosterPayload()); + payload->setVersion("foover"); + rosterStorage_->setRoster(payload); + + testling->requestRoster(); + + boost::shared_ptr<RosterPayload> roster = channel_->sentStanzas[0]->getPayload<RosterPayload>(); + CPPUNIT_ASSERT(roster->getVersion()); + CPPUNIT_ASSERT_EQUAL(std::string("foover"), *roster->getVersion()); + } + + void testGet_ServerDoesNotSupportVersion() { + std::auto_ptr<XMPPRosterController> testling(createController()); + boost::shared_ptr<RosterPayload> payload(new RosterPayload()); + payload->setVersion("foover"); + rosterStorage_->setRoster(payload); + + testling->requestRoster(); + + boost::shared_ptr<RosterPayload> roster = channel_->sentStanzas[0]->getPayload<RosterPayload>(); + CPPUNIT_ASSERT(!roster->getVersion()); + } + + void testGet_ResponseWithoutNewVersion() { + std::auto_ptr<XMPPRosterController> testling(createController()); + testling->setUseVersioning(true); + boost::shared_ptr<RosterPayload> storedRoster(new RosterPayload()); + storedRoster->setVersion("version10"); + storedRoster->addItem(RosterItemPayload(jid1_, "Bob", RosterItemPayload::Both)); + storedRoster->addItem(RosterItemPayload(jid2_, "Alice", RosterItemPayload::Both)); + rosterStorage_->setRoster(storedRoster); + testling->requestRoster(); + + channel_->onIQReceived(IQ::createResult("foo@bar.com", channel_->sentStanzas[0]->getID(), boost::shared_ptr<RosterPayload>())); + + CPPUNIT_ASSERT_EQUAL(2, handler_->getEventCount()); + CPPUNIT_ASSERT(xmppRoster_->getItem(jid1_)); + CPPUNIT_ASSERT(xmppRoster_->getItem(jid2_)); + CPPUNIT_ASSERT_EQUAL(Add, handler_->getLastEvent()); + CPPUNIT_ASSERT_EQUAL(jid2_, handler_->getLastJID()); + CPPUNIT_ASSERT(rosterStorage_->getRoster()); + CPPUNIT_ASSERT(rosterStorage_->getRoster()->getVersion()); + CPPUNIT_ASSERT_EQUAL(std::string("version10"), *rosterStorage_->getRoster()->getVersion()); + CPPUNIT_ASSERT(rosterStorage_->getRoster()->getItem(jid1_)); + CPPUNIT_ASSERT(rosterStorage_->getRoster()->getItem(jid2_)); + } + + void testGet_ResponseWithNewVersion() { + std::auto_ptr<XMPPRosterController> testling(createController()); + testling->setUseVersioning(true); + boost::shared_ptr<RosterPayload> storedRoster(new RosterPayload()); + storedRoster->setVersion("version10"); + storedRoster->addItem(RosterItemPayload(jid1_, "Bob", RosterItemPayload::Both)); + rosterStorage_->setRoster(storedRoster); + testling->requestRoster(); + + boost::shared_ptr<RosterPayload> serverRoster(new RosterPayload()); + serverRoster->setVersion("version12"); + serverRoster->addItem(RosterItemPayload(jid2_, "Alice", RosterItemPayload::Both)); + std::vector<std::string> groups; + groups.push_back("foo"); + groups.push_back("bar"); + serverRoster->addItem(RosterItemPayload(jid3_, "Rabbit", RosterItemPayload::Both, groups)); + channel_->onIQReceived(IQ::createResult("foo@bar.com", channel_->sentStanzas[0]->getID(), serverRoster)); + + + CPPUNIT_ASSERT_EQUAL(2, handler_->getEventCount()); + CPPUNIT_ASSERT(!xmppRoster_->getItem(jid1_)); + CPPUNIT_ASSERT(xmppRoster_->getItem(jid2_)); + CPPUNIT_ASSERT(xmppRoster_->getItem(jid3_)); + CPPUNIT_ASSERT_EQUAL(jid3_, handler_->getLastJID()); + CPPUNIT_ASSERT_EQUAL(Add, handler_->getLastEvent()); + CPPUNIT_ASSERT(rosterStorage_->getRoster()); + CPPUNIT_ASSERT(rosterStorage_->getRoster()->getVersion()); + CPPUNIT_ASSERT_EQUAL(std::string("version12"), *rosterStorage_->getRoster()->getVersion()); + CPPUNIT_ASSERT(!rosterStorage_->getRoster()->getItem(jid1_)); + CPPUNIT_ASSERT(rosterStorage_->getRoster()->getItem(jid2_)); + CPPUNIT_ASSERT(rosterStorage_->getRoster()->getItem(jid3_)); + CPPUNIT_ASSERT_EQUAL(2, static_cast<int>(rosterStorage_->getRoster()->getItem(jid3_)->getGroups().size())); + } + void testModify() { - XMPPRosterController controller(router_, xmppRoster_); + XMPPRosterController controller(router_, xmppRoster_, rosterStorage_); boost::shared_ptr<RosterPayload> payload1(new RosterPayload()); payload1->addItem(RosterItemPayload(jid1_, "Bob", RosterItemPayload::Both)); channel_->onIQReceived(IQ::createRequest(IQ::Set, JID(), "id1", payload1)); @@ -87,9 +219,9 @@ class XMPPRosterControllerTest : public CppUnit::TestFixture { CPPUNIT_ASSERT_EQUAL(std::string("Bob2"), xmppRoster_->getNameForJID(jid1_)); } - + void testRemove() { - XMPPRosterController controller(router_, xmppRoster_); + XMPPRosterController controller(router_, xmppRoster_, rosterStorage_); boost::shared_ptr<RosterPayload> payload1(new RosterPayload()); payload1->addItem(RosterItemPayload(jid1_, "Bob", RosterItemPayload::Both)); channel_->onIQReceived(IQ::createRequest(IQ::Set, JID(), "id1", payload1)); @@ -107,8 +239,31 @@ class XMPPRosterControllerTest : public CppUnit::TestFixture { } + void testRemove_RosterStorageUpdated() { + std::auto_ptr<XMPPRosterController> testling(createController()); + testling->setUseVersioning(true); + boost::shared_ptr<RosterPayload> storedRoster(new RosterPayload()); + storedRoster->setVersion("version10"); + storedRoster->addItem(RosterItemPayload(jid1_, "Bob", RosterItemPayload::Both)); + storedRoster->addItem(RosterItemPayload(jid2_, "Alice", RosterItemPayload::Both)); + rosterStorage_->setRoster(storedRoster); + testling->requestRoster(); + channel_->onIQReceived(IQ::createResult("foo@bar.com", channel_->sentStanzas[0]->getID(), boost::shared_ptr<RosterPayload>())); + + boost::shared_ptr<RosterPayload> payload2(new RosterPayload()); + payload2->setVersion("version15"); + payload2->addItem(RosterItemPayload(jid1_, "Bob", RosterItemPayload::Remove)); + channel_->onIQReceived(IQ::createRequest(IQ::Set, JID(), "id2", payload2)); + + CPPUNIT_ASSERT(rosterStorage_->getRoster()); + CPPUNIT_ASSERT(rosterStorage_->getRoster()->getVersion()); + CPPUNIT_ASSERT_EQUAL(std::string("version15"), *rosterStorage_->getRoster()->getVersion()); + CPPUNIT_ASSERT(!rosterStorage_->getRoster()->getItem(jid1_)); + CPPUNIT_ASSERT(rosterStorage_->getRoster()->getItem(jid2_)); + } + void testMany() { - XMPPRosterController controller(router_, xmppRoster_); + XMPPRosterController controller(router_, xmppRoster_, rosterStorage_); boost::shared_ptr<RosterPayload> payload1(new RosterPayload()); payload1->addItem(RosterItemPayload(jid1_, "Bob", RosterItemPayload::Both)); channel_->onIQReceived(IQ::createRequest(IQ::Set, JID(), "id1", payload1)); @@ -171,12 +326,18 @@ class XMPPRosterControllerTest : public CppUnit::TestFixture { handler_->reset(); } + + private: + XMPPRosterController* createController() { + return new XMPPRosterController(router_, xmppRoster_, rosterStorage_); + } private: DummyStanzaChannel* channel_; IQRouter* router_; XMPPRosterImpl* xmppRoster_; XMPPRosterSignalHandler* handler_; + RosterMemoryStorage* rosterStorage_; JID jid1_; JID jid2_; JID jid3_; diff --git a/Swiften/Roster/UnitTest/XMPPRosterImplTest.cpp b/Swiften/Roster/UnitTest/XMPPRosterImplTest.cpp index edb8271..692779f 100644 --- a/Swiften/Roster/UnitTest/XMPPRosterImplTest.cpp +++ b/Swiften/Roster/UnitTest/XMPPRosterImplTest.cpp @@ -9,8 +9,8 @@ #include <boost/shared_ptr.hpp> #include <boost/bind.hpp> -#include "Swiften/Roster/UnitTest/XMPPRosterSignalHandler.h" -#include "Swiften/Roster/XMPPRosterImpl.h" +#include <Swiften/Roster/UnitTest/XMPPRosterSignalHandler.h> +#include <Swiften/Roster/XMPPRosterImpl.h> using namespace Swift; diff --git a/Swiften/Roster/UnitTest/XMPPRosterSignalHandler.cpp b/Swiften/Roster/UnitTest/XMPPRosterSignalHandler.cpp new file mode 100644 index 0000000..d89644a --- /dev/null +++ b/Swiften/Roster/UnitTest/XMPPRosterSignalHandler.cpp @@ -0,0 +1,28 @@ +/* + * Copyright (c) 2010-2011 Remko Tronçon + * Licensed under the GNU General Public License v3. + * See Documentation/Licenses/GPLv3.txt for more information. + */ + +#include <Swiften/Roster/UnitTest/XMPPRosterSignalHandler.h> + +#include <boost/bind.hpp> +#include <cassert> + +using namespace Swift; + +XMPPRosterSignalHandler::XMPPRosterSignalHandler(Swift::XMPPRoster* roster) : eventCount(0) { + lastEvent_ = None; + roster->onJIDAdded.connect(boost::bind(&XMPPRosterSignalHandler::handleJIDAdded, this, _1)); + roster->onJIDRemoved.connect(boost::bind(&XMPPRosterSignalHandler::handleJIDRemoved, this, _1)); + roster->onJIDUpdated.connect(boost::bind(&XMPPRosterSignalHandler::handleJIDUpdated, this, _1, _2, _3)); +} + +void XMPPRosterSignalHandler::handleJIDUpdated(const Swift::JID& jid, const std::string& oldName, const std::vector<std::string>& oldGroups) { + assert(lastEvent_ == None); + lastJID_ = jid; + lastOldName_ = oldName; + lastOldGroups_ = oldGroups; + lastEvent_ = Update; + eventCount++; +} diff --git a/Swiften/Roster/UnitTest/XMPPRosterSignalHandler.h b/Swiften/Roster/UnitTest/XMPPRosterSignalHandler.h index 1bbd8e9..5c51ec3 100644 --- a/Swiften/Roster/UnitTest/XMPPRosterSignalHandler.h +++ b/Swiften/Roster/UnitTest/XMPPRosterSignalHandler.h @@ -3,34 +3,25 @@ * Licensed under the GNU General Public License v3. * See Documentation/Licenses/GPLv3.txt for more information. */ + #pragma once -#include <boost/shared_ptr.hpp> -#include <boost/bind.hpp> +#include <boost/shared_ptr.hpp> #include <vector> - -#include "Swiften/Roster/XMPPRosterImpl.h" - -using namespace Swift; - +#include <Swiften/Roster/XMPPRosterImpl.h> enum XMPPRosterEvents {None, Add, Remove, Update}; class XMPPRosterSignalHandler { public: - XMPPRosterSignalHandler(XMPPRoster* roster) { - lastEvent_ = None; - roster->onJIDAdded.connect(boost::bind(&XMPPRosterSignalHandler::handleJIDAdded, this, _1)); - roster->onJIDRemoved.connect(boost::bind(&XMPPRosterSignalHandler::handleJIDRemoved, this, _1)); - roster->onJIDUpdated.connect(boost::bind(&XMPPRosterSignalHandler::handleJIDUpdated, this, _1, _2, _3)); - } + XMPPRosterSignalHandler(Swift::XMPPRoster* roster); XMPPRosterEvents getLastEvent() { return lastEvent_; } - JID getLastJID() { + Swift::JID getLastJID() { return lastJID_; } @@ -46,28 +37,28 @@ public: lastEvent_ = None; } + int getEventCount() const { + return eventCount; + } + private: - void handleJIDAdded(const JID& jid) { + void handleJIDAdded(const Swift::JID& jid) { lastJID_ = jid; lastEvent_ = Add; + eventCount++; } - void handleJIDRemoved(const JID& jid) { + void handleJIDRemoved(const Swift::JID& jid) { lastJID_ = jid; lastEvent_ = Remove; + eventCount++; } - void handleJIDUpdated(const JID& jid, const std::string& oldName, const std::vector<std::string>& oldGroups) { - CPPUNIT_ASSERT_EQUAL(None, lastEvent_); - lastJID_ = jid; - lastOldName_ = oldName; - lastOldGroups_ = oldGroups; - lastEvent_ = Update; - } + void handleJIDUpdated(const Swift::JID& jid, const std::string& oldName, const std::vector<std::string>& oldGroups); XMPPRosterEvents lastEvent_; - JID lastJID_; + Swift::JID lastJID_; std::string lastOldName_; std::vector<std::string> lastOldGroups_; - + int eventCount; }; diff --git a/Swiften/Roster/XMPPRoster.cpp b/Swiften/Roster/XMPPRoster.cpp index 61630b4..730569d 100644 --- a/Swiften/Roster/XMPPRoster.cpp +++ b/Swiften/Roster/XMPPRoster.cpp @@ -4,7 +4,7 @@ * See Documentation/Licenses/GPLv3.txt for more information. */ -#include "Swiften/Roster/XMPPRoster.h" +#include <Swiften/Roster/XMPPRoster.h> namespace Swift { diff --git a/Swiften/Roster/XMPPRoster.h b/Swiften/Roster/XMPPRoster.h index be3494d..4b18940 100644 --- a/Swiften/Roster/XMPPRoster.h +++ b/Swiften/Roster/XMPPRoster.h @@ -9,11 +9,11 @@ #include <boost/optional.hpp> #include <vector> #include <set> -#include "Swiften/Base/boost_bsignals.h" +#include <Swiften/Base/boost_bsignals.h> #include <string> -#include "Swiften/JID/JID.h" -#include "Swiften/Elements/RosterItemPayload.h" +#include <Swiften/JID/JID.h> +#include <Swiften/Elements/RosterItemPayload.h> #include <Swiften/Roster/XMPPRosterItem.h> namespace Swift { diff --git a/Swiften/Roster/XMPPRosterController.cpp b/Swiften/Roster/XMPPRosterController.cpp index a294d35..c34c6ec 100644 --- a/Swiften/Roster/XMPPRosterController.cpp +++ b/Swiften/Roster/XMPPRosterController.cpp @@ -4,23 +4,25 @@ * See Documentation/Licenses/GPLv3.txt for more information. */ -#include "Swiften/Roster/XMPPRosterController.h" +#include <Swiften/Roster/XMPPRosterController.h> #include <boost/bind.hpp> +#include <iostream> -#include "Swiften/Base/foreach.h" -#include "Swiften/Elements/RosterItemPayload.h" -#include "Swiften/Queries/IQRouter.h" -#include "Swiften/Roster/GetRosterRequest.h" -#include "Swiften/Roster/XMPPRosterImpl.h" +#include <Swiften/Base/foreach.h> +#include <Swiften/Elements/RosterItemPayload.h> +#include <Swiften/Queries/IQRouter.h> +#include <Swiften/Roster/GetRosterRequest.h> +#include <Swiften/Roster/XMPPRosterImpl.h> +#include <Swiften/Roster/RosterStorage.h> namespace Swift { /** * The controller does not gain ownership of these parameters. */ -XMPPRosterController::XMPPRosterController(IQRouter* iqRouter, XMPPRosterImpl* xmppRoster) : iqRouter_(iqRouter), rosterPushResponder_(iqRouter), xmppRoster_(xmppRoster) { - rosterPushResponder_.onRosterReceived.connect(boost::bind(&XMPPRosterController::handleRosterReceived, this, _1, false)); +XMPPRosterController::XMPPRosterController(IQRouter* iqRouter, XMPPRosterImpl* xmppRoster, RosterStorage* rosterStorage) : iqRouter_(iqRouter), rosterPushResponder_(iqRouter), xmppRoster_(xmppRoster), rosterStorage_(rosterStorage), useVersioning(false) { + rosterPushResponder_.onRosterReceived.connect(boost::bind(&XMPPRosterController::handleRosterReceived, this, _1, false, boost::shared_ptr<RosterPayload>())); rosterPushResponder_.start(); } @@ -30,12 +32,24 @@ XMPPRosterController::~XMPPRosterController() { void XMPPRosterController::requestRoster() { xmppRoster_->clear(); - GetRosterRequest::ref rosterRequest = GetRosterRequest::create(iqRouter_); - rosterRequest->onResponse.connect(boost::bind(&XMPPRosterController::handleRosterReceived, this, _1, true)); + + boost::shared_ptr<RosterPayload> storedRoster = rosterStorage_->getRoster(); + GetRosterRequest::ref rosterRequest; + if (useVersioning) { + std::string version = ""; + if (storedRoster && storedRoster->getVersion()) { + version = *storedRoster->getVersion(); + } + rosterRequest = GetRosterRequest::create(iqRouter_, version); + } + else { + rosterRequest = GetRosterRequest::create(iqRouter_); + } + rosterRequest->onResponse.connect(boost::bind(&XMPPRosterController::handleRosterReceived, this, _1, true, storedRoster)); rosterRequest->send(); } -void XMPPRosterController::handleRosterReceived(boost::shared_ptr<RosterPayload> rosterPayload, bool initial) { +void XMPPRosterController::handleRosterReceived(boost::shared_ptr<RosterPayload> rosterPayload, bool initial, boost::shared_ptr<RosterPayload> previousRoster) { if (rosterPayload) { foreach(const RosterItemPayload& item, rosterPayload->getItems()) { //Don't worry about the updated case, the XMPPRoster sorts that out. @@ -46,9 +60,33 @@ void XMPPRosterController::handleRosterReceived(boost::shared_ptr<RosterPayload> } } } + else if (previousRoster) { + // The cached version hasn't changed; emit all items + foreach(const RosterItemPayload& item, previousRoster->getItems()) { + if (item.getSubscription() != RosterItemPayload::Remove) { + xmppRoster_->addContact(item.getJID(), item.getName(), item.getGroups(), item.getSubscription()); + } + else { + std::cerr << "ERROR: Stored invalid roster item" << std::endl; + } + } + } if (initial) { xmppRoster_->onInitialRosterPopulated(); } + if (rosterPayload && rosterPayload->getVersion() && useVersioning) { + saveRoster(*rosterPayload->getVersion()); + } +} + +void XMPPRosterController::saveRoster(const std::string& version) { + std::vector<XMPPRosterItem> items = xmppRoster_->getItems(); + boost::shared_ptr<RosterPayload> roster(new RosterPayload()); + roster->setVersion(version); + foreach(const XMPPRosterItem& item, items) { + roster->addItem(RosterItemPayload(item.getJID(), item.getName(), item.getSubscription(), item.getGroups())); + } + rosterStorage_->setRoster(roster); } } diff --git a/Swiften/Roster/XMPPRosterController.h b/Swiften/Roster/XMPPRosterController.h index eeb84f6..f105463 100644 --- a/Swiften/Roster/XMPPRosterController.h +++ b/Swiften/Roster/XMPPRosterController.h @@ -8,31 +8,39 @@ #include <boost/shared_ptr.hpp> -#include "Swiften/JID/JID.h" +#include <Swiften/JID/JID.h> #include <string> -#include "Swiften/Elements/IQ.h" -#include "Swiften/Elements/RosterPayload.h" -#include "Swiften/Roster/RosterPushResponder.h" -#include "Swiften/Base/boost_bsignals.h" +#include <Swiften/Elements/IQ.h> +#include <Swiften/Elements/RosterPayload.h> +#include <Swiften/Roster/RosterPushResponder.h> +#include <Swiften/Base/boost_bsignals.h> namespace Swift { class IQRouter; class XMPPRosterImpl; + class RosterStorage; class XMPPRosterController { public: - XMPPRosterController(IQRouter *iqRouter, XMPPRosterImpl* xmppRoster); + XMPPRosterController(IQRouter *iqRouter, XMPPRosterImpl* xmppRoster, RosterStorage* storage); ~XMPPRosterController(); void requestRoster(); + void setUseVersioning(bool b) { + useVersioning = b; + } + private: - void handleRosterReceived(boost::shared_ptr<RosterPayload> rosterPayload, bool initial); + void handleRosterReceived(boost::shared_ptr<RosterPayload> rosterPayload, bool initial, boost::shared_ptr<RosterPayload> previousRoster); + void saveRoster(const std::string& version); private: IQRouter* iqRouter_; RosterPushResponder rosterPushResponder_; XMPPRosterImpl* xmppRoster_; + RosterStorage* rosterStorage_; + bool useVersioning; }; } diff --git a/Swiften/Roster/XMPPRosterImpl.h b/Swiften/Roster/XMPPRosterImpl.h index a44a1ce..cbb3166 100644 --- a/Swiften/Roster/XMPPRosterImpl.h +++ b/Swiften/Roster/XMPPRosterImpl.h @@ -9,7 +9,7 @@ #include <map> #include <set> -#include "Swiften/Roster/XMPPRoster.h" +#include <Swiften/Roster/XMPPRoster.h> namespace Swift { class XMPPRosterImpl : public XMPPRoster { diff --git a/Swiften/SASL/ClientAuthenticator.cpp b/Swiften/SASL/ClientAuthenticator.cpp index 533f172..b882d04 100644 --- a/Swiften/SASL/ClientAuthenticator.cpp +++ b/Swiften/SASL/ClientAuthenticator.cpp @@ -4,7 +4,7 @@ * See Documentation/Licenses/GPLv3.txt for more information. */ -#include "Swiften/SASL/ClientAuthenticator.h" +#include <Swiften/SASL/ClientAuthenticator.h> namespace Swift { diff --git a/Swiften/SASL/ClientAuthenticator.h b/Swiften/SASL/ClientAuthenticator.h index 33db75f..b99d947 100644 --- a/Swiften/SASL/ClientAuthenticator.h +++ b/Swiften/SASL/ClientAuthenticator.h @@ -9,7 +9,7 @@ #include <boost/optional.hpp> #include <string> -#include "Swiften/Base/ByteArray.h" +#include <Swiften/Base/ByteArray.h> namespace Swift { class ClientAuthenticator { diff --git a/Swiften/SASL/DIGESTMD5ClientAuthenticator.cpp b/Swiften/SASL/DIGESTMD5ClientAuthenticator.cpp index 6892948..853609f 100644 --- a/Swiften/SASL/DIGESTMD5ClientAuthenticator.cpp +++ b/Swiften/SASL/DIGESTMD5ClientAuthenticator.cpp @@ -4,12 +4,12 @@ * See Documentation/Licenses/GPLv3.txt for more information. */ -#include "Swiften/SASL/DIGESTMD5ClientAuthenticator.h" +#include <Swiften/SASL/DIGESTMD5ClientAuthenticator.h> #include <cassert> -#include "Swiften/StringCodecs/MD5.h" -#include "Swiften/StringCodecs/Hexify.h" +#include <Swiften/StringCodecs/MD5.h> +#include <Swiften/StringCodecs/Hexify.h> namespace Swift { diff --git a/Swiften/SASL/DIGESTMD5ClientAuthenticator.h b/Swiften/SASL/DIGESTMD5ClientAuthenticator.h index 50dd9aa..f887b37 100644 --- a/Swiften/SASL/DIGESTMD5ClientAuthenticator.h +++ b/Swiften/SASL/DIGESTMD5ClientAuthenticator.h @@ -9,9 +9,9 @@ #include <map> #include <string> -#include "Swiften/Base/ByteArray.h" -#include "Swiften/SASL/ClientAuthenticator.h" -#include "Swiften/SASL/DIGESTMD5Properties.h" +#include <Swiften/Base/ByteArray.h> +#include <Swiften/SASL/ClientAuthenticator.h> +#include <Swiften/SASL/DIGESTMD5Properties.h> namespace Swift { class DIGESTMD5ClientAuthenticator : public ClientAuthenticator { diff --git a/Swiften/SASL/DIGESTMD5Properties.cpp b/Swiften/SASL/DIGESTMD5Properties.cpp index dfff9c8..c9d0882 100644 --- a/Swiften/SASL/DIGESTMD5Properties.cpp +++ b/Swiften/SASL/DIGESTMD5Properties.cpp @@ -4,7 +4,7 @@ * See Documentation/Licenses/GPLv3.txt for more information. */ -#include "Swiften/SASL/DIGESTMD5Properties.h" +#include <Swiften/SASL/DIGESTMD5Properties.h> namespace Swift { diff --git a/Swiften/SASL/DIGESTMD5Properties.h b/Swiften/SASL/DIGESTMD5Properties.h index 6e2e592..ef87574 100644 --- a/Swiften/SASL/DIGESTMD5Properties.h +++ b/Swiften/SASL/DIGESTMD5Properties.h @@ -10,7 +10,7 @@ #include <boost/optional.hpp> #include <string> -#include "Swiften/Base/ByteArray.h" +#include <Swiften/Base/ByteArray.h> namespace Swift { class DIGESTMD5Properties { diff --git a/Swiften/SASL/PLAINClientAuthenticator.cpp b/Swiften/SASL/PLAINClientAuthenticator.cpp index 2ea2425..1714182 100644 --- a/Swiften/SASL/PLAINClientAuthenticator.cpp +++ b/Swiften/SASL/PLAINClientAuthenticator.cpp @@ -4,7 +4,7 @@ * See Documentation/Licenses/GPLv3.txt for more information. */ -#include "Swiften/SASL/PLAINClientAuthenticator.h" +#include <Swiften/SASL/PLAINClientAuthenticator.h> namespace Swift { diff --git a/Swiften/SASL/PLAINClientAuthenticator.h b/Swiften/SASL/PLAINClientAuthenticator.h index 959244d..6a89df1 100644 --- a/Swiften/SASL/PLAINClientAuthenticator.h +++ b/Swiften/SASL/PLAINClientAuthenticator.h @@ -6,7 +6,7 @@ #pragma once -#include "Swiften/SASL/ClientAuthenticator.h" +#include <Swiften/SASL/ClientAuthenticator.h> namespace Swift { class PLAINClientAuthenticator : public ClientAuthenticator { diff --git a/Swiften/SASL/PLAINMessage.cpp b/Swiften/SASL/PLAINMessage.cpp index 3728b39..26261d0 100644 --- a/Swiften/SASL/PLAINMessage.cpp +++ b/Swiften/SASL/PLAINMessage.cpp @@ -4,7 +4,7 @@ * See Documentation/Licenses/GPLv3.txt for more information. */ -#include "Swiften/SASL/PLAINMessage.h" +#include <Swiften/SASL/PLAINMessage.h> namespace Swift { diff --git a/Swiften/SASL/PLAINMessage.h b/Swiften/SASL/PLAINMessage.h index d08d70d..916d267 100644 --- a/Swiften/SASL/PLAINMessage.h +++ b/Swiften/SASL/PLAINMessage.h @@ -9,7 +9,7 @@ #pragma once #include <string> -#include "Swiften/Base/ByteArray.h" +#include <Swiften/Base/ByteArray.h> namespace Swift { class PLAINMessage { diff --git a/Swiften/SASL/SCRAMSHA1ClientAuthenticator.cpp b/Swiften/SASL/SCRAMSHA1ClientAuthenticator.cpp index 2dd7bf4..7f36e48 100644 --- a/Swiften/SASL/SCRAMSHA1ClientAuthenticator.cpp +++ b/Swiften/SASL/SCRAMSHA1ClientAuthenticator.cpp @@ -4,17 +4,17 @@ * See Documentation/Licenses/GPLv3.txt for more information. */ -#include "Swiften/SASL/SCRAMSHA1ClientAuthenticator.h" +#include <Swiften/SASL/SCRAMSHA1ClientAuthenticator.h> #include <cassert> #include <map> #include <boost/lexical_cast.hpp> -#include "Swiften/StringCodecs/SHA1.h" -#include "Swiften/StringCodecs/Base64.h" -#include "Swiften/StringCodecs/HMACSHA1.h" -#include "Swiften/StringCodecs/PBKDF2.h" -#include "Swiften/IDN/StringPrep.h" +#include <Swiften/StringCodecs/SHA1.h> +#include <Swiften/StringCodecs/Base64.h> +#include <Swiften/StringCodecs/HMACSHA1.h> +#include <Swiften/StringCodecs/PBKDF2.h> +#include <Swiften/IDN/StringPrep.h> namespace Swift { diff --git a/Swiften/SASL/SCRAMSHA1ClientAuthenticator.h b/Swiften/SASL/SCRAMSHA1ClientAuthenticator.h index 602fc94..5780bc4 100644 --- a/Swiften/SASL/SCRAMSHA1ClientAuthenticator.h +++ b/Swiften/SASL/SCRAMSHA1ClientAuthenticator.h @@ -10,8 +10,8 @@ #include <boost/optional.hpp> #include <string> -#include "Swiften/Base/ByteArray.h" -#include "Swiften/SASL/ClientAuthenticator.h" +#include <Swiften/Base/ByteArray.h> +#include <Swiften/SASL/ClientAuthenticator.h> namespace Swift { class SCRAMSHA1ClientAuthenticator : public ClientAuthenticator { diff --git a/Swiften/SASL/SConscript b/Swiften/SASL/SConscript index 5a0cdef..085e49d 100644 --- a/Swiften/SASL/SConscript +++ b/Swiften/SASL/SConscript @@ -12,6 +12,7 @@ objects = myenv.SwiftenObject([ "DIGESTMD5ClientAuthenticator.cpp", ]) swiften_env.Append(SWIFTEN_OBJECTS = [objects]) + env.Append(UNITTEST_SOURCES = [ File("UnitTest/PLAINMessageTest.cpp"), File("UnitTest/PLAINClientAuthenticatorTest.cpp"), diff --git a/Swiften/SASL/UnitTest/DIGESTMD5ClientAuthenticatorTest.cpp b/Swiften/SASL/UnitTest/DIGESTMD5ClientAuthenticatorTest.cpp index 54f0571..84f4620 100644 --- a/Swiften/SASL/UnitTest/DIGESTMD5ClientAuthenticatorTest.cpp +++ b/Swiften/SASL/UnitTest/DIGESTMD5ClientAuthenticatorTest.cpp @@ -7,8 +7,8 @@ #include <cppunit/extensions/HelperMacros.h> #include <cppunit/extensions/TestFactoryRegistry.h> -#include "Swiften/SASL/DIGESTMD5ClientAuthenticator.h" -#include "Swiften/Base/ByteArray.h" +#include <Swiften/SASL/DIGESTMD5ClientAuthenticator.h> +#include <Swiften/Base/ByteArray.h> using namespace Swift; diff --git a/Swiften/SASL/UnitTest/DIGESTMD5PropertiesTest.cpp b/Swiften/SASL/UnitTest/DIGESTMD5PropertiesTest.cpp index 152a41e..ab04d9b 100644 --- a/Swiften/SASL/UnitTest/DIGESTMD5PropertiesTest.cpp +++ b/Swiften/SASL/UnitTest/DIGESTMD5PropertiesTest.cpp @@ -7,7 +7,7 @@ #include <cppunit/extensions/HelperMacros.h> #include <cppunit/extensions/TestFactoryRegistry.h> -#include "Swiften/SASL/DIGESTMD5Properties.h" +#include <Swiften/SASL/DIGESTMD5Properties.h> using namespace Swift; diff --git a/Swiften/SASL/UnitTest/PLAINClientAuthenticatorTest.cpp b/Swiften/SASL/UnitTest/PLAINClientAuthenticatorTest.cpp index 33914b2..f29d52b 100644 --- a/Swiften/SASL/UnitTest/PLAINClientAuthenticatorTest.cpp +++ b/Swiften/SASL/UnitTest/PLAINClientAuthenticatorTest.cpp @@ -4,7 +4,7 @@ * See Documentation/Licenses/GPLv3.txt for more information. */ -#include "Swiften/SASL/PLAINClientAuthenticator.h" +#include <Swiften/SASL/PLAINClientAuthenticator.h> #include <cppunit/extensions/HelperMacros.h> #include <cppunit/extensions/TestFactoryRegistry.h> diff --git a/Swiften/SASL/UnitTest/PLAINMessageTest.cpp b/Swiften/SASL/UnitTest/PLAINMessageTest.cpp index d517f0d..cebfbb2 100644 --- a/Swiften/SASL/UnitTest/PLAINMessageTest.cpp +++ b/Swiften/SASL/UnitTest/PLAINMessageTest.cpp @@ -4,12 +4,12 @@ * See Documentation/Licenses/GPLv3.txt for more information. */ -#include "Swiften/Base/ByteArray.h" +#include <Swiften/Base/ByteArray.h> #include <cppunit/extensions/HelperMacros.h> #include <cppunit/extensions/TestFactoryRegistry.h> -#include "Swiften/SASL/PLAINMessage.h" +#include <Swiften/SASL/PLAINMessage.h> using namespace Swift; diff --git a/Swiften/SASL/UnitTest/SCRAMSHA1ClientAuthenticatorTest.cpp b/Swiften/SASL/UnitTest/SCRAMSHA1ClientAuthenticatorTest.cpp index 5d0edbd..db0d1d3 100644 --- a/Swiften/SASL/UnitTest/SCRAMSHA1ClientAuthenticatorTest.cpp +++ b/Swiften/SASL/UnitTest/SCRAMSHA1ClientAuthenticatorTest.cpp @@ -7,8 +7,8 @@ #include <cppunit/extensions/HelperMacros.h> #include <cppunit/extensions/TestFactoryRegistry.h> -#include "Swiften/SASL/SCRAMSHA1ClientAuthenticator.h" -#include "Swiften/Base/ByteArray.h" +#include <Swiften/SASL/SCRAMSHA1ClientAuthenticator.h> +#include <Swiften/Base/ByteArray.h> using namespace Swift; diff --git a/Swiften/SConscript b/Swiften/SConscript index 110f202..244022c 100644 --- a/Swiften/SConscript +++ b/Swiften/SConscript @@ -1,4 +1,4 @@ -import os, re, Version +import os, re, Version, os.path Import("env") @@ -6,7 +6,7 @@ Import("env") # Flags ################################################################################ -swiften_dep_modules = ["BOOST", "LIBIDN", "ZLIB", "OPENSSL", "LIBXML", "EXPAT", "AVAHI"] +swiften_dep_modules = ["BOOST", "GCONF", "LIBIDN", "ZLIB", "OPENSSL", "LIBXML", "EXPAT", "AVAHI"] if env["SCONS_STAGE"] == "flags" : env["SWIFTEN_VERSION"] = Version.getBuildVersion(env.Dir("#").abspath, "swift") @@ -76,25 +76,34 @@ if env["SCONS_STAGE"] == "build" : "Client/ClientSessionStanzaChannel.cpp", "Client/CoreClient.cpp", "Client/Client.cpp", + "Client/ClientXMLTracer.cpp", "Client/ClientSession.cpp", "Client/MemoryStorages.cpp", - "Client/FileStorages.cpp", "Client/NickResolver.cpp", "Client/NickManager.cpp", "Client/NickManagerImpl.cpp", + "Client/Storages.cpp", "Compress/ZLibCodecompressor.cpp", "Compress/ZLibDecompressor.cpp", "Compress/ZLibCompressor.cpp", "Elements/DiscoInfo.cpp", + "Elements/Presence.cpp", "Elements/Form.cpp", + "Elements/StreamFeatures.cpp", "Elements/Element.cpp", "Elements/IQ.cpp", "Elements/Payload.cpp", + "Elements/RosterItemExchangePayload.cpp", "Elements/RosterPayload.cpp", "Elements/Stanza.cpp", + "Elements/StatusShow.cpp", + "Elements/StreamManagementEnabled.cpp", + "Elements/StreamResume.cpp", + "Elements/StreamResumed.cpp", "Elements/VCard.cpp", "Elements/MUCOccupant.cpp", "Entity/Entity.cpp", + "Entity/PayloadPersister.cpp", "MUC/MUC.cpp", "MUC/MUCManager.cpp", "MUC/MUCRegistry.cpp", @@ -106,6 +115,8 @@ if env["SCONS_STAGE"] == "build" : "Queries/Requests/GetInBandRegistrationFormRequest.cpp", "Queries/Requests/SubmitInBandRegistrationFormRequest.cpp", "Queries/Responders/SoftwareVersionResponder.cpp", + "Roster/RosterStorage.cpp", + "Roster/RosterMemoryStorage.cpp", "Roster/XMPPRoster.cpp", "Roster/XMPPRosterImpl.cpp", "Roster/XMPPRosterController.cpp", @@ -116,6 +127,9 @@ if env["SCONS_STAGE"] == "build" : "Serializer/CompressRequestSerializer.cpp", "Serializer/ElementSerializer.cpp", "Serializer/MessageSerializer.cpp", + "Serializer/StreamManagementEnabledSerializer.cpp", + "Serializer/StreamResumeSerializer.cpp", + "Serializer/StreamResumedSerializer.cpp", "Serializer/ComponentHandshakeSerializer.cpp", "Serializer/PayloadSerializer.cpp", "Serializer/PayloadSerializerCollection.cpp", @@ -130,6 +144,7 @@ if env["SCONS_STAGE"] == "build" : "Serializer/PayloadSerializers/MUCUserPayloadSerializer.cpp", "Serializer/PayloadSerializers/MUCOwnerPayloadSerializer.cpp", "Serializer/PayloadSerializers/ResourceBindSerializer.cpp", + "Serializer/PayloadSerializers/RosterItemExchangeSerializer.cpp", "Serializer/PayloadSerializers/RosterSerializer.cpp", "Serializer/PayloadSerializers/SecurityLabelSerializer.cpp", "Serializer/PayloadSerializers/SecurityLabelsCatalogSerializer.cpp", @@ -159,6 +174,7 @@ if env["SCONS_STAGE"] == "build" : "Server/SimpleUserRegistry.cpp", "Server/UserRegistry.cpp", "Session/Session.cpp", + "Session/SessionTracer.cpp", "Session/SessionStream.cpp", "Session/BasicSessionStream.cpp", "StringCodecs/Base64.cpp", @@ -190,6 +206,7 @@ if env["SCONS_STAGE"] == "build" : "StreamManagement", "Component", "Config", + "AdHoc" ]) SConscript(test_only = True, dirs = [ "QA", @@ -199,6 +216,8 @@ if env["SCONS_STAGE"] == "build" : ]) myenv = swiften_env.Clone() + if myenv["PLATFORM"] != "darwin" and myenv["PLATFORM"] != "win32" and myenv.get("HAVE_GCONF", 0) : + env.MergeFlags(env["GCONF_FLAGS"]) if ARGUMENTS.get("swiften_dll", False) : if myenv["PLATFORM"] == "posix" : myenv.Append(LINKFLAGS = ["-Wl,-soname,libSwiften.so.$SWIFTEN_VERSION_MAJOR"]) @@ -239,8 +258,6 @@ if env["SCONS_STAGE"] == "build" : File("Elements/UnitTest/FormTest.cpp"), File("EventLoop/UnitTest/EventLoopTest.cpp"), File("EventLoop/UnitTest/SimpleEventLoopTest.cpp"), - File("FileTransfer/UnitTest/SOCKS5BytestreamServerSessionTest.cpp"), - File("FileTransfer/UnitTest/IBBSendSessionTest.cpp"), # File("History/UnitTest/SQLiteHistoryManagerTest.cpp"), File("JID/UnitTest/JIDTest.cpp"), File("LinkLocal/UnitTest/LinkLocalConnectorTest.cpp"), @@ -250,6 +267,8 @@ if env["SCONS_STAGE"] == "build" : File("MUC/UnitTest/MUCTest.cpp"), File("Network/UnitTest/HostAddressTest.cpp"), File("Network/UnitTest/ConnectorTest.cpp"), + File("Network/UnitTest/ChainedConnectorTest.cpp"), + File("Network/UnitTest/HTTPConnectProxiedConnectionTest.cpp"), File("Parser/PayloadParsers/UnitTest/BodyParserTest.cpp"), File("Parser/PayloadParsers/UnitTest/DiscoInfoParserTest.cpp"), File("Parser/PayloadParsers/UnitTest/ErrorParserTest.cpp"), @@ -258,6 +277,7 @@ if env["SCONS_STAGE"] == "build" : File("Parser/PayloadParsers/UnitTest/PriorityParserTest.cpp"), File("Parser/PayloadParsers/UnitTest/RawXMLPayloadParserTest.cpp"), File("Parser/PayloadParsers/UnitTest/ResourceBindParserTest.cpp"), + File("Parser/PayloadParsers/UnitTest/RosterItemExchangeParserTest.cpp"), File("Parser/PayloadParsers/UnitTest/RosterParserTest.cpp"), File("Parser/PayloadParsers/UnitTest/IBBParserTest.cpp"), File("Parser/PayloadParsers/UnitTest/SearchPayloadParserTest.cpp"), @@ -271,6 +291,7 @@ if env["SCONS_STAGE"] == "build" : File("Parser/PayloadParsers/UnitTest/StorageParserTest.cpp"), File("Parser/PayloadParsers/UnitTest/PrivateStorageParserTest.cpp"), File("Parser/PayloadParsers/UnitTest/VCardUpdateParserTest.cpp"), + File("Parser/PayloadParsers/UnitTest/ReplaceTest.cpp"), File("Parser/UnitTest/AttributeMapTest.cpp"), File("Parser/UnitTest/IQParserTest.cpp"), File("Parser/UnitTest/MessageParserTest.cpp"), @@ -280,6 +301,7 @@ if env["SCONS_STAGE"] == "build" : File("Parser/UnitTest/SerializingParserTest.cpp"), File("Parser/UnitTest/StanzaParserTest.cpp"), File("Parser/UnitTest/StreamFeaturesParserTest.cpp"), + File("Parser/UnitTest/StreamManagementEnabledParserTest.cpp"), File("Parser/UnitTest/XMLParserTest.cpp"), File("Parser/UnitTest/XMPPParserTest.cpp"), File("Presence/UnitTest/PresenceOracleTest.cpp"), @@ -291,6 +313,7 @@ if env["SCONS_STAGE"] == "build" : File("Queries/UnitTest/ResponderTest.cpp"), File("Roster/UnitTest/XMPPRosterImplTest.cpp"), File("Roster/UnitTest/XMPPRosterControllerTest.cpp"), + File("Roster/UnitTest/XMPPRosterSignalHandler.cpp"), File("Serializer/PayloadSerializers/UnitTest/PayloadsSerializer.cpp"), File("Serializer/PayloadSerializers/UnitTest/CapsInfoSerializerTest.cpp"), File("Serializer/PayloadSerializers/UnitTest/FormSerializerTest.cpp"), @@ -298,6 +321,7 @@ if env["SCONS_STAGE"] == "build" : File("Serializer/PayloadSerializers/UnitTest/ErrorSerializerTest.cpp"), File("Serializer/PayloadSerializers/UnitTest/PrioritySerializerTest.cpp"), File("Serializer/PayloadSerializers/UnitTest/ResourceBindSerializerTest.cpp"), + File("Serializer/PayloadSerializers/UnitTest/RosterItemExchangeSerializerTest.cpp"), File("Serializer/PayloadSerializers/UnitTest/RosterSerializerTest.cpp"), File("Serializer/PayloadSerializers/UnitTest/SearchPayloadSerializerTest.cpp"), File("Serializer/PayloadSerializers/UnitTest/SecurityLabelSerializerTest.cpp"), @@ -311,6 +335,7 @@ if env["SCONS_STAGE"] == "build" : File("Serializer/PayloadSerializers/UnitTest/VCardSerializerTest.cpp"), File("Serializer/PayloadSerializers/UnitTest/StorageSerializerTest.cpp"), File("Serializer/PayloadSerializers/UnitTest/PrivateStorageSerializerTest.cpp"), + File("Serializer/PayloadSerializers/UnitTest/ReplaceSerializerTest.cpp"), File("Serializer/UnitTest/StreamFeaturesSerializerTest.cpp"), File("Serializer/UnitTest/AuthSuccessSerializerTest.cpp"), File("Serializer/UnitTest/AuthChallengeSerializerTest.cpp"), @@ -334,6 +359,9 @@ if env["SCONS_STAGE"] == "build" : ]) # Generate the Swiften header + def relpath(path, start) : + i = len(os.path.commonprefix([path, start])) + return path[i+1:] swiften_header = "#pragma once\n" swiften_includes = [] top_path = env.Dir("..").abspath @@ -343,7 +371,7 @@ if env["SCONS_STAGE"] == "build" : for file in files : if not file.endswith(".h") : continue - include = os.path.relpath(os.path.join(root, file), top_path) + include = relpath(os.path.join(root, file), top_path) swiften_includes.append(include) # Private modules if root.endswith("Config") or root.endswith("Compress") : @@ -354,7 +382,7 @@ if env["SCONS_STAGE"] == "build" : continue # Library-specific files - if file.startswith("CAres") or file.startswith("LibXML") or file.startswith("Expat") or file.startswith("SQLite") : + if file.startswith("CAres") or file.startswith("LibXML") or file.startswith("Expat") or file.startswith("GConf") or file.startswith("MacOSX") or file.startswith("Windows") or file.startswith("SQLite") : continue # Specific headers we don't want to globally include diff --git a/Swiften/Serializer/AuthChallengeSerializer.cpp b/Swiften/Serializer/AuthChallengeSerializer.cpp index dcded43..18d190d 100644 --- a/Swiften/Serializer/AuthChallengeSerializer.cpp +++ b/Swiften/Serializer/AuthChallengeSerializer.cpp @@ -4,10 +4,10 @@ * See Documentation/Licenses/GPLv3.txt for more information. */ -#include "Swiften/Serializer/AuthChallengeSerializer.h" +#include <Swiften/Serializer/AuthChallengeSerializer.h> -#include "Swiften/Elements/AuthChallenge.h" -#include "Swiften/StringCodecs/Base64.h" +#include <Swiften/Elements/AuthChallenge.h> +#include <Swiften/StringCodecs/Base64.h> namespace Swift { diff --git a/Swiften/Serializer/AuthChallengeSerializer.h b/Swiften/Serializer/AuthChallengeSerializer.h index a62efb3..5f04c4c 100644 --- a/Swiften/Serializer/AuthChallengeSerializer.h +++ b/Swiften/Serializer/AuthChallengeSerializer.h @@ -8,8 +8,8 @@ #include <boost/shared_ptr.hpp> -#include "Swiften/Elements/AuthChallenge.h" -#include "Swiften/Serializer/GenericElementSerializer.h" +#include <Swiften/Elements/AuthChallenge.h> +#include <Swiften/Serializer/GenericElementSerializer.h> namespace Swift { class AuthChallengeSerializer : public GenericElementSerializer<AuthChallenge> { diff --git a/Swiften/Serializer/AuthFailureSerializer.h b/Swiften/Serializer/AuthFailureSerializer.h index 477d98c..046a828 100644 --- a/Swiften/Serializer/AuthFailureSerializer.h +++ b/Swiften/Serializer/AuthFailureSerializer.h @@ -9,9 +9,9 @@ #include <boost/shared_ptr.hpp> -#include "Swiften/Elements/AuthFailure.h" -#include "Swiften/Serializer/GenericElementSerializer.h" -#include "Swiften/Serializer/XML/XMLElement.h" +#include <Swiften/Elements/AuthFailure.h> +#include <Swiften/Serializer/GenericElementSerializer.h> +#include <Swiften/Serializer/XML/XMLElement.h> namespace Swift { class AuthFailureSerializer : public GenericElementSerializer<AuthFailure> { diff --git a/Swiften/Serializer/AuthRequestSerializer.cpp b/Swiften/Serializer/AuthRequestSerializer.cpp index 0bee302..4ba3e47 100644 --- a/Swiften/Serializer/AuthRequestSerializer.cpp +++ b/Swiften/Serializer/AuthRequestSerializer.cpp @@ -4,10 +4,10 @@ * See Documentation/Licenses/GPLv3.txt for more information. */ -#include "Swiften/Serializer/AuthRequestSerializer.h" +#include <Swiften/Serializer/AuthRequestSerializer.h> -#include "Swiften/Elements/AuthRequest.h" -#include "Swiften/StringCodecs/Base64.h" +#include <Swiften/Elements/AuthRequest.h> +#include <Swiften/StringCodecs/Base64.h> namespace Swift { diff --git a/Swiften/Serializer/AuthRequestSerializer.h b/Swiften/Serializer/AuthRequestSerializer.h index 18ef5dd..9a1bb46 100644 --- a/Swiften/Serializer/AuthRequestSerializer.h +++ b/Swiften/Serializer/AuthRequestSerializer.h @@ -9,8 +9,8 @@ #include <boost/shared_ptr.hpp> -#include "Swiften/Elements/AuthRequest.h" -#include "Swiften/Serializer/GenericElementSerializer.h" +#include <Swiften/Elements/AuthRequest.h> +#include <Swiften/Serializer/GenericElementSerializer.h> namespace Swift { class AuthRequestSerializer : public GenericElementSerializer<AuthRequest> { diff --git a/Swiften/Serializer/AuthResponseSerializer.cpp b/Swiften/Serializer/AuthResponseSerializer.cpp index a93b4dd..9bd1cc1 100644 --- a/Swiften/Serializer/AuthResponseSerializer.cpp +++ b/Swiften/Serializer/AuthResponseSerializer.cpp @@ -4,10 +4,10 @@ * See Documentation/Licenses/GPLv3.txt for more information. */ -#include "Swiften/Serializer/AuthResponseSerializer.h" +#include <Swiften/Serializer/AuthResponseSerializer.h> -#include "Swiften/Elements/AuthResponse.h" -#include "Swiften/StringCodecs/Base64.h" +#include <Swiften/Elements/AuthResponse.h> +#include <Swiften/StringCodecs/Base64.h> namespace Swift { diff --git a/Swiften/Serializer/AuthResponseSerializer.h b/Swiften/Serializer/AuthResponseSerializer.h index cee8ff3..f3734c0 100644 --- a/Swiften/Serializer/AuthResponseSerializer.h +++ b/Swiften/Serializer/AuthResponseSerializer.h @@ -8,8 +8,8 @@ #include <boost/shared_ptr.hpp> -#include "Swiften/Elements/AuthResponse.h" -#include "Swiften/Serializer/GenericElementSerializer.h" +#include <Swiften/Elements/AuthResponse.h> +#include <Swiften/Serializer/GenericElementSerializer.h> namespace Swift { class AuthResponseSerializer : public GenericElementSerializer<AuthResponse> { diff --git a/Swiften/Serializer/AuthSuccessSerializer.cpp b/Swiften/Serializer/AuthSuccessSerializer.cpp index 443c740..518c970 100644 --- a/Swiften/Serializer/AuthSuccessSerializer.cpp +++ b/Swiften/Serializer/AuthSuccessSerializer.cpp @@ -4,10 +4,10 @@ * See Documentation/Licenses/GPLv3.txt for more information. */ -#include "Swiften/Serializer/AuthSuccessSerializer.h" +#include <Swiften/Serializer/AuthSuccessSerializer.h> -#include "Swiften/Elements/AuthSuccess.h" -#include "Swiften/StringCodecs/Base64.h" +#include <Swiften/Elements/AuthSuccess.h> +#include <Swiften/StringCodecs/Base64.h> namespace Swift { diff --git a/Swiften/Serializer/AuthSuccessSerializer.h b/Swiften/Serializer/AuthSuccessSerializer.h index eb3279c..d681f5a 100644 --- a/Swiften/Serializer/AuthSuccessSerializer.h +++ b/Swiften/Serializer/AuthSuccessSerializer.h @@ -8,8 +8,8 @@ #include <boost/shared_ptr.hpp> -#include "Swiften/Elements/AuthSuccess.h" -#include "Swiften/Serializer/GenericElementSerializer.h" +#include <Swiften/Elements/AuthSuccess.h> +#include <Swiften/Serializer/GenericElementSerializer.h> namespace Swift { class AuthSuccessSerializer : public GenericElementSerializer<AuthSuccess> { diff --git a/Swiften/Serializer/ComponentHandshakeSerializer.cpp b/Swiften/Serializer/ComponentHandshakeSerializer.cpp index cf44ea4..4eef395 100644 --- a/Swiften/Serializer/ComponentHandshakeSerializer.cpp +++ b/Swiften/Serializer/ComponentHandshakeSerializer.cpp @@ -4,9 +4,9 @@ * See Documentation/Licenses/GPLv3.txt for more information. */ -#include "Swiften/Serializer/ComponentHandshakeSerializer.h" +#include <Swiften/Serializer/ComponentHandshakeSerializer.h> -#include "Swiften/Elements/ComponentHandshake.h" +#include <Swiften/Elements/ComponentHandshake.h> namespace Swift { diff --git a/Swiften/Serializer/ComponentHandshakeSerializer.h b/Swiften/Serializer/ComponentHandshakeSerializer.h index 7681e56..fe79962 100644 --- a/Swiften/Serializer/ComponentHandshakeSerializer.h +++ b/Swiften/Serializer/ComponentHandshakeSerializer.h @@ -8,8 +8,8 @@ #include <boost/shared_ptr.hpp> -#include "Swiften/Elements/ComponentHandshake.h" -#include "Swiften/Serializer/GenericElementSerializer.h" +#include <Swiften/Elements/ComponentHandshake.h> +#include <Swiften/Serializer/GenericElementSerializer.h> namespace Swift { class ComponentHandshakeSerializer : public GenericElementSerializer<ComponentHandshake> { diff --git a/Swiften/Serializer/CompressFailureSerializer.h b/Swiften/Serializer/CompressFailureSerializer.h index 02a4b46..c6c23e6 100644 --- a/Swiften/Serializer/CompressFailureSerializer.h +++ b/Swiften/Serializer/CompressFailureSerializer.h @@ -9,9 +9,9 @@ #include <boost/shared_ptr.hpp> -#include "Swiften/Elements/CompressFailure.h" -#include "Swiften/Serializer/GenericElementSerializer.h" -#include "Swiften/Serializer/XML/XMLElement.h" +#include <Swiften/Elements/CompressFailure.h> +#include <Swiften/Serializer/GenericElementSerializer.h> +#include <Swiften/Serializer/XML/XMLElement.h> namespace Swift { class CompressFailureSerializer : public GenericElementSerializer<CompressFailure> { diff --git a/Swiften/Serializer/CompressRequestSerializer.cpp b/Swiften/Serializer/CompressRequestSerializer.cpp index 7733169..0c7a4ee 100644 --- a/Swiften/Serializer/CompressRequestSerializer.cpp +++ b/Swiften/Serializer/CompressRequestSerializer.cpp @@ -4,9 +4,9 @@ * See Documentation/Licenses/GPLv3.txt for more information. */ -#include "Swiften/Serializer/CompressRequestSerializer.h" +#include <Swiften/Serializer/CompressRequestSerializer.h> -#include "Swiften/Elements/CompressRequest.h" +#include <Swiften/Elements/CompressRequest.h> namespace Swift { diff --git a/Swiften/Serializer/CompressRequestSerializer.h b/Swiften/Serializer/CompressRequestSerializer.h index 0a14fb1..2cdb930 100644 --- a/Swiften/Serializer/CompressRequestSerializer.h +++ b/Swiften/Serializer/CompressRequestSerializer.h @@ -9,7 +9,7 @@ #include <boost/shared_ptr.hpp> -#include "Swiften/Serializer/ElementSerializer.h" +#include <Swiften/Serializer/ElementSerializer.h> namespace Swift { class CompressRequestSerializer : public ElementSerializer { diff --git a/Swiften/Serializer/ElementSerializer.cpp b/Swiften/Serializer/ElementSerializer.cpp index 6b9fdd5..8cfb294 100644 --- a/Swiften/Serializer/ElementSerializer.cpp +++ b/Swiften/Serializer/ElementSerializer.cpp @@ -4,7 +4,7 @@ * See Documentation/Licenses/GPLv3.txt for more information. */ -#include "Swiften/Serializer/ElementSerializer.h" +#include <Swiften/Serializer/ElementSerializer.h> namespace Swift { diff --git a/Swiften/Serializer/ElementSerializer.h b/Swiften/Serializer/ElementSerializer.h index 3abdf08..ebf0aa1 100644 --- a/Swiften/Serializer/ElementSerializer.h +++ b/Swiften/Serializer/ElementSerializer.h @@ -10,7 +10,7 @@ #include <boost/shared_ptr.hpp> #include <string> -#include "Swiften/Elements/Element.h" +#include <Swiften/Elements/Element.h> namespace Swift { class ElementSerializer { diff --git a/Swiften/Serializer/EnableStreamManagementSerializer.h b/Swiften/Serializer/EnableStreamManagementSerializer.h index e224a9c..dc9710e 100644 --- a/Swiften/Serializer/EnableStreamManagementSerializer.h +++ b/Swiften/Serializer/EnableStreamManagementSerializer.h @@ -8,9 +8,9 @@ #include <boost/shared_ptr.hpp> -#include "Swiften/Elements/EnableStreamManagement.h" -#include "Swiften/Serializer/GenericElementSerializer.h" -#include "Swiften/Serializer/XML/XMLElement.h" +#include <Swiften/Elements/EnableStreamManagement.h> +#include <Swiften/Serializer/GenericElementSerializer.h> +#include <Swiften/Serializer/XML/XMLElement.h> namespace Swift { class EnableStreamManagementSerializer : public GenericElementSerializer<EnableStreamManagement> { diff --git a/Swiften/Serializer/GenericStanzaSerializer.h b/Swiften/Serializer/GenericStanzaSerializer.h index 2f0fccf..89aa121 100644 --- a/Swiften/Serializer/GenericStanzaSerializer.h +++ b/Swiften/Serializer/GenericStanzaSerializer.h @@ -7,7 +7,7 @@ #ifndef SWIFTEN_GENERICSTANZASERIALIZER_H #define SWIFTEN_GENERICSTANZASERIALIZER_H -#include "Swiften/Serializer/StanzaSerializer.h" +#include <Swiften/Serializer/StanzaSerializer.h> namespace Swift { template<typename STANZA_TYPE> diff --git a/Swiften/Serializer/IQSerializer.h b/Swiften/Serializer/IQSerializer.h index 21ec300..3b3f471 100644 --- a/Swiften/Serializer/IQSerializer.h +++ b/Swiften/Serializer/IQSerializer.h @@ -7,11 +7,9 @@ #ifndef SWIFTEN_IQSerializer_H #define SWIFTEN_IQSerializer_H -#include <cassert> - -#include "Swiften/Serializer/GenericStanzaSerializer.h" -#include "Swiften/Elements/IQ.h" -#include "Swiften/Serializer/XML/XMLElement.h" +#include <Swiften/Serializer/GenericStanzaSerializer.h> +#include <Swiften/Elements/IQ.h> +#include <Swiften/Serializer/XML/XMLElement.h> namespace Swift { class IQSerializer : public GenericStanzaSerializer<IQ> { diff --git a/Swiften/Serializer/MessageSerializer.cpp b/Swiften/Serializer/MessageSerializer.cpp index cea9a1d..c221680 100644 --- a/Swiften/Serializer/MessageSerializer.cpp +++ b/Swiften/Serializer/MessageSerializer.cpp @@ -4,8 +4,8 @@ * See Documentation/Licenses/GPLv3.txt for more information. */ -#include "Swiften/Serializer/MessageSerializer.h" -#include "Swiften/Serializer/XML/XMLElement.h" +#include <Swiften/Serializer/MessageSerializer.h> +#include <Swiften/Serializer/XML/XMLElement.h> namespace Swift { diff --git a/Swiften/Serializer/MessageSerializer.h b/Swiften/Serializer/MessageSerializer.h index 873cc5a..b580a47 100644 --- a/Swiften/Serializer/MessageSerializer.h +++ b/Swiften/Serializer/MessageSerializer.h @@ -7,8 +7,8 @@ #ifndef SWIFTEN_MessageSerializer_H #define SWIFTEN_MessageSerializer_H -#include "Swiften/Serializer/GenericStanzaSerializer.h" -#include "Swiften/Elements/Message.h" +#include <Swiften/Serializer/GenericStanzaSerializer.h> +#include <Swiften/Elements/Message.h> namespace Swift { class XMLElement; diff --git a/Swiften/Serializer/PayloadSerializer.cpp b/Swiften/Serializer/PayloadSerializer.cpp index db13ade..be73676 100644 --- a/Swiften/Serializer/PayloadSerializer.cpp +++ b/Swiften/Serializer/PayloadSerializer.cpp @@ -4,7 +4,7 @@ * See Documentation/Licenses/GPLv3.txt for more information. */ -#include "Swiften/Serializer/PayloadSerializer.h" +#include <Swiften/Serializer/PayloadSerializer.h> namespace Swift { diff --git a/Swiften/Serializer/PayloadSerializer.h b/Swiften/Serializer/PayloadSerializer.h index 34e6679..c4ad23b 100644 --- a/Swiften/Serializer/PayloadSerializer.h +++ b/Swiften/Serializer/PayloadSerializer.h @@ -4,15 +4,14 @@ * See Documentation/Licenses/GPLv3.txt for more information. */ -#ifndef SWIFTEN_PAYLOADSERIALIZER_H -#define SWIFTEN_PAYLOADSERIALIZER_H - -#include <boost/shared_ptr.hpp> +#pragma once #include <string> -#include "Swiften/Elements/Payload.h" +#include <boost/shared_ptr.hpp> namespace Swift { + class Payload; + class PayloadSerializer { public: virtual ~PayloadSerializer(); @@ -21,5 +20,3 @@ namespace Swift { virtual std::string serialize(boost::shared_ptr<Payload>) const = 0; }; } - -#endif diff --git a/Swiften/Serializer/PayloadSerializerCollection.cpp b/Swiften/Serializer/PayloadSerializerCollection.cpp index 548dd32..ab2b4f4 100644 --- a/Swiften/Serializer/PayloadSerializerCollection.cpp +++ b/Swiften/Serializer/PayloadSerializerCollection.cpp @@ -7,8 +7,8 @@ #include <boost/bind.hpp> #include <algorithm> -#include "Swiften/Serializer/PayloadSerializerCollection.h" -#include "Swiften/Serializer/PayloadSerializer.h" +#include <Swiften/Serializer/PayloadSerializerCollection.h> +#include <Swiften/Serializer/PayloadSerializer.h> namespace Swift { diff --git a/Swiften/Serializer/PayloadSerializerCollection.h b/Swiften/Serializer/PayloadSerializerCollection.h index 1b3cbc5..f922a45 100644 --- a/Swiften/Serializer/PayloadSerializerCollection.h +++ b/Swiften/Serializer/PayloadSerializerCollection.h @@ -9,7 +9,7 @@ #include <vector> #include <boost/shared_ptr.hpp> -#include "Swiften/Elements/Payload.h" +#include <Swiften/Elements/Payload.h> namespace Swift { class PayloadSerializer; diff --git a/Swiften/Serializer/PayloadSerializers/BodySerializer.h b/Swiften/Serializer/PayloadSerializers/BodySerializer.h index 6fc6e6d..67213e2 100644 --- a/Swiften/Serializer/PayloadSerializers/BodySerializer.h +++ b/Swiften/Serializer/PayloadSerializers/BodySerializer.h @@ -7,9 +7,9 @@ #ifndef SWIFTEN_BodySerializer_H #define SWIFTEN_BodySerializer_H -#include "Swiften/Serializer/GenericPayloadSerializer.h" -#include "Swiften/Serializer/XML/XMLTextNode.h" -#include "Swiften/Elements/Body.h" +#include <Swiften/Serializer/GenericPayloadSerializer.h> +#include <Swiften/Serializer/XML/XMLTextNode.h> +#include <Swiften/Elements/Body.h> namespace Swift { class BodySerializer : public GenericPayloadSerializer<Body> { diff --git a/Swiften/Serializer/PayloadSerializers/BytestreamsSerializer.cpp b/Swiften/Serializer/PayloadSerializers/BytestreamsSerializer.cpp index f9b89f3..beb84dd 100644 --- a/Swiften/Serializer/PayloadSerializers/BytestreamsSerializer.cpp +++ b/Swiften/Serializer/PayloadSerializers/BytestreamsSerializer.cpp @@ -4,14 +4,14 @@ * See Documentation/Licenses/GPLv3.txt for more information. */ -#include "Swiften/Serializer/PayloadSerializers/BytestreamsSerializer.h" +#include <Swiften/Serializer/PayloadSerializers/BytestreamsSerializer.h> #include <boost/shared_ptr.hpp> #include <boost/lexical_cast.hpp> -#include "Swiften/Base/foreach.h" -#include "Swiften/Serializer/XML/XMLElement.h" -#include "Swiften/Serializer/PayloadSerializerCollection.h" +#include <Swiften/Base/foreach.h> +#include <Swiften/Serializer/XML/XMLElement.h> +#include <Swiften/Serializer/PayloadSerializerCollection.h> namespace Swift { diff --git a/Swiften/Serializer/PayloadSerializers/BytestreamsSerializer.h b/Swiften/Serializer/PayloadSerializers/BytestreamsSerializer.h index d9b14db..0e58eb0 100644 --- a/Swiften/Serializer/PayloadSerializers/BytestreamsSerializer.h +++ b/Swiften/Serializer/PayloadSerializers/BytestreamsSerializer.h @@ -6,8 +6,8 @@ #pragma once -#include "Swiften/Serializer/GenericPayloadSerializer.h" -#include "Swiften/Elements/Bytestreams.h" +#include <Swiften/Serializer/GenericPayloadSerializer.h> +#include <Swiften/Elements/Bytestreams.h> namespace Swift { class PayloadSerializerCollection; diff --git a/Swiften/Serializer/PayloadSerializers/CapsInfoSerializer.cpp b/Swiften/Serializer/PayloadSerializers/CapsInfoSerializer.cpp index ced0d62..2466958 100644 --- a/Swiften/Serializer/PayloadSerializers/CapsInfoSerializer.cpp +++ b/Swiften/Serializer/PayloadSerializers/CapsInfoSerializer.cpp @@ -4,11 +4,11 @@ * See Documentation/Licenses/GPLv3.txt for more information. */ -#include "Swiften/Serializer/PayloadSerializers/CapsInfoSerializer.h" +#include <Swiften/Serializer/PayloadSerializers/CapsInfoSerializer.h> #include <boost/shared_ptr.hpp> -#include "Swiften/Serializer/XML/XMLElement.h" +#include <Swiften/Serializer/XML/XMLElement.h> namespace Swift { diff --git a/Swiften/Serializer/PayloadSerializers/CapsInfoSerializer.h b/Swiften/Serializer/PayloadSerializers/CapsInfoSerializer.h index de0a871..af6e339 100644 --- a/Swiften/Serializer/PayloadSerializers/CapsInfoSerializer.h +++ b/Swiften/Serializer/PayloadSerializers/CapsInfoSerializer.h @@ -7,8 +7,8 @@ #ifndef SWIFTEN_CapsInfoSerializer_H #define SWIFTEN_CapsInfoSerializer_H -#include "Swiften/Serializer/GenericPayloadSerializer.h" -#include "Swiften/Elements/CapsInfo.h" +#include <Swiften/Serializer/GenericPayloadSerializer.h> +#include <Swiften/Elements/CapsInfo.h> namespace Swift { class CapsInfoSerializer : public GenericPayloadSerializer<CapsInfo> { diff --git a/Swiften/Serializer/PayloadSerializers/ChatStateSerializer.cpp b/Swiften/Serializer/PayloadSerializers/ChatStateSerializer.cpp index 3e877eb..ee468bb 100644 --- a/Swiften/Serializer/PayloadSerializers/ChatStateSerializer.cpp +++ b/Swiften/Serializer/PayloadSerializers/ChatStateSerializer.cpp @@ -4,7 +4,7 @@ * See Documentation/Licenses/GPLv3.txt for more information. */ -#include "Swiften/Serializer/PayloadSerializers/ChatStateSerializer.h" +#include <Swiften/Serializer/PayloadSerializers/ChatStateSerializer.h> namespace Swift { diff --git a/Swiften/Serializer/PayloadSerializers/ChatStateSerializer.h b/Swiften/Serializer/PayloadSerializers/ChatStateSerializer.h index a786901..d71873d 100644 --- a/Swiften/Serializer/PayloadSerializers/ChatStateSerializer.h +++ b/Swiften/Serializer/PayloadSerializers/ChatStateSerializer.h @@ -6,8 +6,8 @@ #pragma once -#include "Swiften/Serializer/GenericPayloadSerializer.h" -#include "Swiften/Elements/ChatState.h" +#include <Swiften/Serializer/GenericPayloadSerializer.h> +#include <Swiften/Elements/ChatState.h> namespace Swift { class ChatStateSerializer : public GenericPayloadSerializer<ChatState> { diff --git a/Swiften/Serializer/PayloadSerializers/CommandSerializer.cpp b/Swiften/Serializer/PayloadSerializers/CommandSerializer.cpp index 0fa45ce..534f4f6 100644 --- a/Swiften/Serializer/PayloadSerializers/CommandSerializer.cpp +++ b/Swiften/Serializer/PayloadSerializers/CommandSerializer.cpp @@ -4,16 +4,16 @@ * See Documentation/Licenses/GPLv3.txt for more information. */ -#include "Swiften/Serializer/PayloadSerializers/CommandSerializer.h" +#include <Swiften/Serializer/PayloadSerializers/CommandSerializer.h> #include <boost/shared_ptr.hpp> -#include "Swiften/Base/foreach.h" -#include "Swiften/Serializer/XML/XMLElement.h" -#include "Swiften/Serializer/XML/XMLTextNode.h" -#include "Swiften/Serializer/XML/XMLRawTextNode.h" -#include "Swiften/Serializer/PayloadSerializerCollection.h" -#include "Swiften/Serializer/PayloadSerializers/FormSerializer.h" +#include <Swiften/Base/foreach.h> +#include <Swiften/Serializer/XML/XMLElement.h> +#include <Swiften/Serializer/XML/XMLTextNode.h> +#include <Swiften/Serializer/XML/XMLRawTextNode.h> +#include <Swiften/Serializer/PayloadSerializerCollection.h> +#include <Swiften/Serializer/PayloadSerializers/FormSerializer.h> namespace Swift { @@ -21,7 +21,7 @@ CommandSerializer::CommandSerializer() { } std::string CommandSerializer::serializePayload(boost::shared_ptr<Command> command) const { - XMLElement commandElement("command", "http://jabber.org/protocol/comands"); + XMLElement commandElement("command", "http://jabber.org/protocol/commands"); commandElement.setAttribute("node", command->getNode()); if (!command->getSessionID().empty()) { diff --git a/Swiften/Serializer/PayloadSerializers/CommandSerializer.h b/Swiften/Serializer/PayloadSerializers/CommandSerializer.h index b1db825..0ac8451 100644 --- a/Swiften/Serializer/PayloadSerializers/CommandSerializer.h +++ b/Swiften/Serializer/PayloadSerializers/CommandSerializer.h @@ -6,8 +6,8 @@ #pragma once -#include "Swiften/Serializer/GenericPayloadSerializer.h" -#include "Swiften/Elements/Command.h" +#include <Swiften/Serializer/GenericPayloadSerializer.h> +#include <Swiften/Elements/Command.h> namespace Swift { class PayloadSerializerCollection; diff --git a/Swiften/Serializer/PayloadSerializers/DelaySerializer.cpp b/Swiften/Serializer/PayloadSerializers/DelaySerializer.cpp index 4922042..4f86faa 100644 --- a/Swiften/Serializer/PayloadSerializers/DelaySerializer.cpp +++ b/Swiften/Serializer/PayloadSerializers/DelaySerializer.cpp @@ -4,12 +4,13 @@ * See Documentation/Licenses/GPLv3.txt for more information. */ -#include "Swiften/Serializer/PayloadSerializers/DelaySerializer.h" +#include <Swiften/Serializer/PayloadSerializers/DelaySerializer.h> #include <boost/shared_ptr.hpp> +#include <boost/date_time/posix_time/posix_time.hpp> #include <Swiften/Base/String.h> -#include "Swiften/Serializer/XML/XMLElement.h" +#include <Swiften/Serializer/XML/XMLElement.h> namespace Swift { diff --git a/Swiften/Serializer/PayloadSerializers/DelaySerializer.h b/Swiften/Serializer/PayloadSerializers/DelaySerializer.h index c37dc02..4705e71 100644 --- a/Swiften/Serializer/PayloadSerializers/DelaySerializer.h +++ b/Swiften/Serializer/PayloadSerializers/DelaySerializer.h @@ -6,8 +6,8 @@ #pragma once -#include "Swiften/Serializer/GenericPayloadSerializer.h" -#include "Swiften/Elements/Delay.h" +#include <Swiften/Serializer/GenericPayloadSerializer.h> +#include <Swiften/Elements/Delay.h> namespace Swift { class DelaySerializer : public GenericPayloadSerializer<Delay> { diff --git a/Swiften/Serializer/PayloadSerializers/DiscoInfoSerializer.cpp b/Swiften/Serializer/PayloadSerializers/DiscoInfoSerializer.cpp index 65b0a38..e2c6f59 100644 --- a/Swiften/Serializer/PayloadSerializers/DiscoInfoSerializer.cpp +++ b/Swiften/Serializer/PayloadSerializers/DiscoInfoSerializer.cpp @@ -4,14 +4,14 @@ * See Documentation/Licenses/GPLv3.txt for more information. */ -#include "Swiften/Serializer/PayloadSerializers/DiscoInfoSerializer.h" +#include <Swiften/Serializer/PayloadSerializers/DiscoInfoSerializer.h> #include <boost/shared_ptr.hpp> -#include "Swiften/Base/foreach.h" -#include "Swiften/Serializer/XML/XMLElement.h" -#include "Swiften/Serializer/XML/XMLRawTextNode.h" -#include "Swiften/Serializer/PayloadSerializers/FormSerializer.h" +#include <Swiften/Base/foreach.h> +#include <Swiften/Serializer/XML/XMLElement.h> +#include <Swiften/Serializer/XML/XMLRawTextNode.h> +#include <Swiften/Serializer/PayloadSerializers/FormSerializer.h> namespace Swift { diff --git a/Swiften/Serializer/PayloadSerializers/DiscoInfoSerializer.h b/Swiften/Serializer/PayloadSerializers/DiscoInfoSerializer.h index 46e7ce2..e19ea4b 100644 --- a/Swiften/Serializer/PayloadSerializers/DiscoInfoSerializer.h +++ b/Swiften/Serializer/PayloadSerializers/DiscoInfoSerializer.h @@ -7,8 +7,8 @@ #ifndef SWIFTEN_DiscoInfoSerializer_H #define SWIFTEN_DiscoInfoSerializer_H -#include "Swiften/Serializer/GenericPayloadSerializer.h" -#include "Swiften/Elements/DiscoInfo.h" +#include <Swiften/Serializer/GenericPayloadSerializer.h> +#include <Swiften/Elements/DiscoInfo.h> namespace Swift { class DiscoInfoSerializer : public GenericPayloadSerializer<DiscoInfo> { diff --git a/Swiften/Serializer/PayloadSerializers/DiscoItemsSerializer.cpp b/Swiften/Serializer/PayloadSerializers/DiscoItemsSerializer.cpp index cb1b7c1..dd52b70 100644 --- a/Swiften/Serializer/PayloadSerializers/DiscoItemsSerializer.cpp +++ b/Swiften/Serializer/PayloadSerializers/DiscoItemsSerializer.cpp @@ -4,12 +4,12 @@ * See Documentation/Licenses/GPLv3.txt for more information. */ -#include "Swiften/Serializer/PayloadSerializers/DiscoItemsSerializer.h" +#include <Swiften/Serializer/PayloadSerializers/DiscoItemsSerializer.h> #include <boost/shared_ptr.hpp> -#include "Swiften/Base/foreach.h" -#include "Swiften/Serializer/XML/XMLElement.h" +#include <Swiften/Base/foreach.h> +#include <Swiften/Serializer/XML/XMLElement.h> namespace Swift { diff --git a/Swiften/Serializer/PayloadSerializers/DiscoItemsSerializer.h b/Swiften/Serializer/PayloadSerializers/DiscoItemsSerializer.h index 3b00a17..a8785c2 100644 --- a/Swiften/Serializer/PayloadSerializers/DiscoItemsSerializer.h +++ b/Swiften/Serializer/PayloadSerializers/DiscoItemsSerializer.h @@ -6,8 +6,8 @@ #pragma once -#include "Swiften/Serializer/GenericPayloadSerializer.h" -#include "Swiften/Elements/DiscoItems.h" +#include <Swiften/Serializer/GenericPayloadSerializer.h> +#include <Swiften/Elements/DiscoItems.h> namespace Swift { class DiscoItemsSerializer : public GenericPayloadSerializer<DiscoItems> { diff --git a/Swiften/Serializer/PayloadSerializers/ErrorSerializer.cpp b/Swiften/Serializer/PayloadSerializers/ErrorSerializer.cpp index 15d13d7..e3bfd54 100644 --- a/Swiften/Serializer/PayloadSerializers/ErrorSerializer.cpp +++ b/Swiften/Serializer/PayloadSerializers/ErrorSerializer.cpp @@ -4,8 +4,8 @@ * See Documentation/Licenses/GPLv3.txt for more information. */ -#include "Swiften/Serializer/PayloadSerializers/ErrorSerializer.h" -#include "Swiften/Serializer/XML/XMLTextNode.h" +#include <Swiften/Serializer/PayloadSerializers/ErrorSerializer.h> +#include <Swiften/Serializer/XML/XMLTextNode.h> namespace Swift { diff --git a/Swiften/Serializer/PayloadSerializers/ErrorSerializer.h b/Swiften/Serializer/PayloadSerializers/ErrorSerializer.h index 7fc4dad..1170320 100644 --- a/Swiften/Serializer/PayloadSerializers/ErrorSerializer.h +++ b/Swiften/Serializer/PayloadSerializers/ErrorSerializer.h @@ -7,8 +7,8 @@ #ifndef SWIFTEN_ErrorSerializer_H #define SWIFTEN_ErrorSerializer_H -#include "Swiften/Serializer/GenericPayloadSerializer.h" -#include "Swiften/Elements/ErrorPayload.h" +#include <Swiften/Serializer/GenericPayloadSerializer.h> +#include <Swiften/Elements/ErrorPayload.h> namespace Swift { class ErrorSerializer : public GenericPayloadSerializer<ErrorPayload> { diff --git a/Swiften/Serializer/PayloadSerializers/FormSerializer.cpp b/Swiften/Serializer/PayloadSerializers/FormSerializer.cpp index 53b4241..eae4c02 100644 --- a/Swiften/Serializer/PayloadSerializers/FormSerializer.cpp +++ b/Swiften/Serializer/PayloadSerializers/FormSerializer.cpp @@ -4,16 +4,16 @@ * See Documentation/Licenses/GPLv3.txt for more information. */ -#include "Swiften/Serializer/PayloadSerializers/FormSerializer.h" +#include <Swiften/Serializer/PayloadSerializers/FormSerializer.h> #include <boost/shared_ptr.hpp> #include <iostream> #include <string> -#include "Swiften/Base/String.h" -#include "Swiften/Base/foreach.h" -#include "Swiften/Serializer/XML/XMLTextNode.h" -#include "Swiften/Serializer/XML/XMLRawTextNode.h" +#include <Swiften/Base/String.h> +#include <Swiften/Base/foreach.h> +#include <Swiften/Serializer/XML/XMLTextNode.h> +#include <Swiften/Serializer/XML/XMLRawTextNode.h> using namespace Swift; @@ -129,14 +129,6 @@ boost::shared_ptr<XMLElement> FormSerializer::fieldToXML(boost::shared_ptr<FormF fieldType = "text-multi"; multiLineify(boost::dynamic_pointer_cast<TextMultiFormField>(field)->getValue(), "value", fieldElement); } - else if (boost::dynamic_pointer_cast<UntypedFormField>(field)) { - std::vector<std::string> lines = boost::dynamic_pointer_cast<UntypedFormField>(field)->getValue(); - foreach(const std::string& line, lines) { - boost::shared_ptr<XMLElement> valueElement(new XMLElement("value")); - valueElement->addNode(XMLTextNode::create(line)); - fieldElement->addNode(valueElement); - } - } else { assert(false); } diff --git a/Swiften/Serializer/PayloadSerializers/FormSerializer.h b/Swiften/Serializer/PayloadSerializers/FormSerializer.h index 86c8dee..43db9e8 100644 --- a/Swiften/Serializer/PayloadSerializers/FormSerializer.h +++ b/Swiften/Serializer/PayloadSerializers/FormSerializer.h @@ -6,10 +6,10 @@ #pragma once -#include "Swiften/Serializer/GenericPayloadSerializer.h" -#include "Swiften/Elements/Form.h" -#include "Swiften/Elements/FormField.h" -#include "Swiften/Serializer/XML/XMLElement.h" +#include <Swiften/Serializer/GenericPayloadSerializer.h> +#include <Swiften/Elements/Form.h> +#include <Swiften/Elements/FormField.h> +#include <Swiften/Serializer/XML/XMLElement.h> namespace Swift { class FormSerializer : public GenericPayloadSerializer<Form> { diff --git a/Swiften/Serializer/PayloadSerializers/FullPayloadSerializerCollection.cpp b/Swiften/Serializer/PayloadSerializers/FullPayloadSerializerCollection.cpp index 1bbcbf2..622fe1f 100644 --- a/Swiften/Serializer/PayloadSerializers/FullPayloadSerializerCollection.cpp +++ b/Swiften/Serializer/PayloadSerializers/FullPayloadSerializerCollection.cpp @@ -4,42 +4,44 @@ * See Documentation/Licenses/GPLv3.txt for more information. */ -#include "Swiften/Serializer/PayloadSerializers/FullPayloadSerializerCollection.h" -#include "Swiften/Base/foreach.h" -#include "Swiften/Serializer/PayloadSerializer.h" -#include "Swiften/Serializer/PayloadSerializers/IBBSerializer.h" -#include "Swiften/Serializer/PayloadSerializers/BodySerializer.h" -#include "Swiften/Serializer/PayloadSerializers/SubjectSerializer.h" -#include "Swiften/Serializer/PayloadSerializers/ChatStateSerializer.h" -#include "Swiften/Serializer/PayloadSerializers/PrioritySerializer.h" -#include "Swiften/Serializer/PayloadSerializers/ErrorSerializer.h" -#include "Swiften/Serializer/PayloadSerializers/RosterSerializer.h" -#include "Swiften/Serializer/PayloadSerializers/MUCPayloadSerializer.h" -#include "Swiften/Serializer/PayloadSerializers/MUCUserPayloadSerializer.h" -#include "Swiften/Serializer/PayloadSerializers/MUCOwnerPayloadSerializer.h" -#include "Swiften/Serializer/PayloadSerializers/SoftwareVersionSerializer.h" -#include "Swiften/Serializer/PayloadSerializers/StatusSerializer.h" -#include "Swiften/Serializer/PayloadSerializers/StatusShowSerializer.h" -#include "Swiften/Serializer/PayloadSerializers/DiscoInfoSerializer.h" -#include "Swiften/Serializer/PayloadSerializers/DiscoItemsSerializer.h" -#include "Swiften/Serializer/PayloadSerializers/CapsInfoSerializer.h" -#include "Swiften/Serializer/PayloadSerializers/ResourceBindSerializer.h" -#include "Swiften/Serializer/PayloadSerializers/StartSessionSerializer.h" -#include "Swiften/Serializer/PayloadSerializers/SecurityLabelSerializer.h" -#include "Swiften/Serializer/PayloadSerializers/SecurityLabelsCatalogSerializer.h" -#include "Swiften/Serializer/PayloadSerializers/StreamInitiationSerializer.h" -#include "Swiften/Serializer/PayloadSerializers/BytestreamsSerializer.h" -#include "Swiften/Serializer/PayloadSerializers/VCardSerializer.h" -#include "Swiften/Serializer/PayloadSerializers/VCardUpdateSerializer.h" -#include "Swiften/Serializer/PayloadSerializers/RawXMLPayloadSerializer.h" -#include "Swiften/Serializer/PayloadSerializers/StorageSerializer.h" -#include "Swiften/Serializer/PayloadSerializers/PrivateStorageSerializer.h" -#include "Swiften/Serializer/PayloadSerializers/DelaySerializer.h" -#include "Swiften/Serializer/PayloadSerializers/FormSerializer.h" -#include "Swiften/Serializer/PayloadSerializers/CommandSerializer.h" -#include "Swiften/Serializer/PayloadSerializers/InBandRegistrationPayloadSerializer.h" -#include "Swiften/Serializer/PayloadSerializers/NicknameSerializer.h" -#include "Swiften/Serializer/PayloadSerializers/SearchPayloadSerializer.h" +#include <Swiften/Serializer/PayloadSerializers/FullPayloadSerializerCollection.h> +#include <Swiften/Base/foreach.h> +#include <Swiften/Serializer/PayloadSerializer.h> +#include <Swiften/Serializer/PayloadSerializers/IBBSerializer.h> +#include <Swiften/Serializer/PayloadSerializers/BodySerializer.h> +#include <Swiften/Serializer/PayloadSerializers/SubjectSerializer.h> +#include <Swiften/Serializer/PayloadSerializers/ChatStateSerializer.h> +#include <Swiften/Serializer/PayloadSerializers/PrioritySerializer.h> +#include <Swiften/Serializer/PayloadSerializers/ErrorSerializer.h> +#include <Swiften/Serializer/PayloadSerializers/RosterSerializer.h> +#include <Swiften/Serializer/PayloadSerializers/RosterItemExchangeSerializer.h> +#include <Swiften/Serializer/PayloadSerializers/MUCPayloadSerializer.h> +#include <Swiften/Serializer/PayloadSerializers/MUCUserPayloadSerializer.h> +#include <Swiften/Serializer/PayloadSerializers/MUCOwnerPayloadSerializer.h> +#include <Swiften/Serializer/PayloadSerializers/SoftwareVersionSerializer.h> +#include <Swiften/Serializer/PayloadSerializers/StatusSerializer.h> +#include <Swiften/Serializer/PayloadSerializers/StatusShowSerializer.h> +#include <Swiften/Serializer/PayloadSerializers/DiscoInfoSerializer.h> +#include <Swiften/Serializer/PayloadSerializers/DiscoItemsSerializer.h> +#include <Swiften/Serializer/PayloadSerializers/CapsInfoSerializer.h> +#include <Swiften/Serializer/PayloadSerializers/ResourceBindSerializer.h> +#include <Swiften/Serializer/PayloadSerializers/StartSessionSerializer.h> +#include <Swiften/Serializer/PayloadSerializers/SecurityLabelSerializer.h> +#include <Swiften/Serializer/PayloadSerializers/SecurityLabelsCatalogSerializer.h> +#include <Swiften/Serializer/PayloadSerializers/StreamInitiationSerializer.h> +#include <Swiften/Serializer/PayloadSerializers/BytestreamsSerializer.h> +#include <Swiften/Serializer/PayloadSerializers/VCardSerializer.h> +#include <Swiften/Serializer/PayloadSerializers/VCardUpdateSerializer.h> +#include <Swiften/Serializer/PayloadSerializers/RawXMLPayloadSerializer.h> +#include <Swiften/Serializer/PayloadSerializers/StorageSerializer.h> +#include <Swiften/Serializer/PayloadSerializers/PrivateStorageSerializer.h> +#include <Swiften/Serializer/PayloadSerializers/DelaySerializer.h> +#include <Swiften/Serializer/PayloadSerializers/FormSerializer.h> +#include <Swiften/Serializer/PayloadSerializers/CommandSerializer.h> +#include <Swiften/Serializer/PayloadSerializers/InBandRegistrationPayloadSerializer.h> +#include <Swiften/Serializer/PayloadSerializers/NicknameSerializer.h> +#include <Swiften/Serializer/PayloadSerializers/SearchPayloadSerializer.h> +#include <Swiften/Serializer/PayloadSerializers/ReplaceSerializer.h> namespace Swift { @@ -51,6 +53,7 @@ FullPayloadSerializerCollection::FullPayloadSerializerCollection() { serializers_.push_back(new PrioritySerializer()); serializers_.push_back(new ErrorSerializer()); serializers_.push_back(new RosterSerializer()); + serializers_.push_back(new RosterItemExchangeSerializer()); serializers_.push_back(new MUCPayloadSerializer()); serializers_.push_back(new MUCUserPayloadSerializer()); serializers_.push_back(new MUCOwnerPayloadSerializer(this)); @@ -77,6 +80,7 @@ FullPayloadSerializerCollection::FullPayloadSerializerCollection() { serializers_.push_back(new InBandRegistrationPayloadSerializer()); serializers_.push_back(new NicknameSerializer()); serializers_.push_back(new SearchPayloadSerializer()); + serializers_.push_back(new ReplaceSerializer()); foreach(PayloadSerializer* serializer, serializers_) { addSerializer(serializer); } diff --git a/Swiften/Serializer/PayloadSerializers/FullPayloadSerializerCollection.h b/Swiften/Serializer/PayloadSerializers/FullPayloadSerializerCollection.h index bf86f27..ec08d66 100644 --- a/Swiften/Serializer/PayloadSerializers/FullPayloadSerializerCollection.h +++ b/Swiften/Serializer/PayloadSerializers/FullPayloadSerializerCollection.h @@ -9,7 +9,7 @@ #include <vector> -#include "Swiften/Serializer/PayloadSerializerCollection.h" +#include <Swiften/Serializer/PayloadSerializerCollection.h> namespace Swift { class FullPayloadSerializerCollection : public PayloadSerializerCollection { diff --git a/Swiften/Serializer/PayloadSerializers/IBBSerializer.cpp b/Swiften/Serializer/PayloadSerializers/IBBSerializer.cpp index 7ac4103..13370c5 100644 --- a/Swiften/Serializer/PayloadSerializers/IBBSerializer.cpp +++ b/Swiften/Serializer/PayloadSerializers/IBBSerializer.cpp @@ -4,16 +4,16 @@ * See Documentation/Licenses/GPLv3.txt for more information. */ -#include "Swiften/Serializer/PayloadSerializers/IBBSerializer.h" +#include <Swiften/Serializer/PayloadSerializers/IBBSerializer.h> #include <boost/shared_ptr.hpp> #include <boost/lexical_cast.hpp> -#include "Swiften/Base/foreach.h" -#include "Swiften/Serializer/XML/XMLElement.h" -#include "Swiften/Serializer/XML/XMLTextNode.h" -#include "Swiften/Serializer/PayloadSerializerCollection.h" -#include "Swiften/StringCodecs/Base64.h" +#include <Swiften/Base/foreach.h> +#include <Swiften/Serializer/XML/XMLElement.h> +#include <Swiften/Serializer/XML/XMLTextNode.h> +#include <Swiften/Serializer/PayloadSerializerCollection.h> +#include <Swiften/StringCodecs/Base64.h> namespace Swift { diff --git a/Swiften/Serializer/PayloadSerializers/IBBSerializer.h b/Swiften/Serializer/PayloadSerializers/IBBSerializer.h index d750f6f..8b026e1 100644 --- a/Swiften/Serializer/PayloadSerializers/IBBSerializer.h +++ b/Swiften/Serializer/PayloadSerializers/IBBSerializer.h @@ -6,8 +6,8 @@ #pragma once -#include "Swiften/Serializer/GenericPayloadSerializer.h" -#include "Swiften/Elements/IBB.h" +#include <Swiften/Serializer/GenericPayloadSerializer.h> +#include <Swiften/Elements/IBB.h> namespace Swift { class PayloadSerializerCollection; diff --git a/Swiften/Serializer/PayloadSerializers/InBandRegistrationPayloadSerializer.cpp b/Swiften/Serializer/PayloadSerializers/InBandRegistrationPayloadSerializer.cpp index e4ae11f..12b1bb5 100644 --- a/Swiften/Serializer/PayloadSerializers/InBandRegistrationPayloadSerializer.cpp +++ b/Swiften/Serializer/PayloadSerializers/InBandRegistrationPayloadSerializer.cpp @@ -4,14 +4,14 @@ * See Documentation/Licenses/GPLv3.txt for more information. */ -#include "Swiften/Serializer/PayloadSerializers/InBandRegistrationPayloadSerializer.h" +#include <Swiften/Serializer/PayloadSerializers/InBandRegistrationPayloadSerializer.h> #include <boost/shared_ptr.hpp> -#include "Swiften/Base/foreach.h" -#include "Swiften/Serializer/XML/XMLElement.h" -#include "Swiften/Serializer/XML/XMLRawTextNode.h" -#include "Swiften/Serializer/PayloadSerializers/FormSerializer.h" +#include <Swiften/Base/foreach.h> +#include <Swiften/Serializer/XML/XMLElement.h> +#include <Swiften/Serializer/XML/XMLRawTextNode.h> +#include <Swiften/Serializer/PayloadSerializers/FormSerializer.h> namespace Swift { diff --git a/Swiften/Serializer/PayloadSerializers/InBandRegistrationPayloadSerializer.h b/Swiften/Serializer/PayloadSerializers/InBandRegistrationPayloadSerializer.h index 45d49ea..008f374 100644 --- a/Swiften/Serializer/PayloadSerializers/InBandRegistrationPayloadSerializer.h +++ b/Swiften/Serializer/PayloadSerializers/InBandRegistrationPayloadSerializer.h @@ -7,8 +7,8 @@ #pragma once -#include "Swiften/Serializer/GenericPayloadSerializer.h" -#include "Swiften/Elements/InBandRegistrationPayload.h" +#include <Swiften/Serializer/GenericPayloadSerializer.h> +#include <Swiften/Elements/InBandRegistrationPayload.h> namespace Swift { class PayloadSerializerCollection; diff --git a/Swiften/Serializer/PayloadSerializers/MUCOwnerPayloadSerializer.cpp b/Swiften/Serializer/PayloadSerializers/MUCOwnerPayloadSerializer.cpp index db28514..f86b59e 100644 --- a/Swiften/Serializer/PayloadSerializers/MUCOwnerPayloadSerializer.cpp +++ b/Swiften/Serializer/PayloadSerializers/MUCOwnerPayloadSerializer.cpp @@ -4,11 +4,11 @@ * See Documentation/Licenses/GPLv3.txt for more information. */ -#include "Swiften/Serializer/PayloadSerializers/MUCOwnerPayloadSerializer.h" +#include <Swiften/Serializer/PayloadSerializers/MUCOwnerPayloadSerializer.h> -#include "Swiften/Serializer/PayloadSerializerCollection.h" -#include "Swiften/Serializer/XML/XMLElement.h" -#include "Swiften/Serializer/XML/XMLRawTextNode.h" +#include <Swiften/Serializer/PayloadSerializerCollection.h> +#include <Swiften/Serializer/XML/XMLElement.h> +#include <Swiften/Serializer/XML/XMLRawTextNode.h> namespace Swift { diff --git a/Swiften/Serializer/PayloadSerializers/MUCOwnerPayloadSerializer.h b/Swiften/Serializer/PayloadSerializers/MUCOwnerPayloadSerializer.h index 4808744..5e6913a 100644 --- a/Swiften/Serializer/PayloadSerializers/MUCOwnerPayloadSerializer.h +++ b/Swiften/Serializer/PayloadSerializers/MUCOwnerPayloadSerializer.h @@ -6,8 +6,8 @@ #pragma once -#include "Swiften/Serializer/GenericPayloadSerializer.h" -#include "Swiften/Elements/MUCOwnerPayload.h" +#include <Swiften/Serializer/GenericPayloadSerializer.h> +#include <Swiften/Elements/MUCOwnerPayload.h> namespace Swift { class PayloadSerializerCollection; diff --git a/Swiften/Serializer/PayloadSerializers/MUCPayloadSerializer.cpp b/Swiften/Serializer/PayloadSerializers/MUCPayloadSerializer.cpp index d7e1613..7080e14 100644 --- a/Swiften/Serializer/PayloadSerializers/MUCPayloadSerializer.cpp +++ b/Swiften/Serializer/PayloadSerializers/MUCPayloadSerializer.cpp @@ -4,9 +4,12 @@ * See Documentation/Licenses/GPLv3.txt for more information. */ -#include "Swiften/Serializer/PayloadSerializers/MUCPayloadSerializer.h" +#include <Swiften/Serializer/PayloadSerializers/MUCPayloadSerializer.h> -#include "Swiften/Serializer/XML/XMLElement.h" +#include <boost/lexical_cast.hpp> +#include <boost/date_time/posix_time/posix_time.hpp> + +#include <Swiften/Serializer/XML/XMLElement.h> #include <Swiften/Base/String.h> namespace Swift { diff --git a/Swiften/Serializer/PayloadSerializers/MUCPayloadSerializer.h b/Swiften/Serializer/PayloadSerializers/MUCPayloadSerializer.h index 7038e6e..4bf8d22 100644 --- a/Swiften/Serializer/PayloadSerializers/MUCPayloadSerializer.h +++ b/Swiften/Serializer/PayloadSerializers/MUCPayloadSerializer.h @@ -6,8 +6,8 @@ #pragma once -#include "Swiften/Serializer/GenericPayloadSerializer.h" -#include "Swiften/Elements/MUCPayload.h" +#include <Swiften/Serializer/GenericPayloadSerializer.h> +#include <Swiften/Elements/MUCPayload.h> namespace Swift { class MUCPayloadSerializer : public GenericPayloadSerializer<MUCPayload> { diff --git a/Swiften/Serializer/PayloadSerializers/MUCUserPayloadSerializer.cpp b/Swiften/Serializer/PayloadSerializers/MUCUserPayloadSerializer.cpp index 50746a9..7b76a50 100644 --- a/Swiften/Serializer/PayloadSerializers/MUCUserPayloadSerializer.cpp +++ b/Swiften/Serializer/PayloadSerializers/MUCUserPayloadSerializer.cpp @@ -4,15 +4,15 @@ * See Documentation/Licenses/GPLv3.txt for more information. */ -#include "Swiften/Serializer/PayloadSerializers/MUCUserPayloadSerializer.h" +#include <Swiften/Serializer/PayloadSerializers/MUCUserPayloadSerializer.h> #include <sstream> #include <boost/shared_ptr.hpp> -#include "Swiften/Base/foreach.h" -#include "Swiften/Serializer/XML/XMLElement.h" -#include "Swiften/Serializer/XML/XMLTextNode.h" +#include <Swiften/Base/foreach.h> +#include <Swiften/Serializer/XML/XMLElement.h> +#include <Swiften/Serializer/XML/XMLTextNode.h> namespace Swift { diff --git a/Swiften/Serializer/PayloadSerializers/MUCUserPayloadSerializer.h b/Swiften/Serializer/PayloadSerializers/MUCUserPayloadSerializer.h index 54e6aff..634ce22 100644 --- a/Swiften/Serializer/PayloadSerializers/MUCUserPayloadSerializer.h +++ b/Swiften/Serializer/PayloadSerializers/MUCUserPayloadSerializer.h @@ -6,8 +6,8 @@ #pragma once -#include "Swiften/Serializer/GenericPayloadSerializer.h" -#include "Swiften/Elements/MUCUserPayload.h" +#include <Swiften/Serializer/GenericPayloadSerializer.h> +#include <Swiften/Elements/MUCUserPayload.h> namespace Swift { class MUCUserPayloadSerializer : public GenericPayloadSerializer<MUCUserPayload> { diff --git a/Swiften/Serializer/PayloadSerializers/NicknameSerializer.cpp b/Swiften/Serializer/PayloadSerializers/NicknameSerializer.cpp index 23d2c25..38a5db5 100644 --- a/Swiften/Serializer/PayloadSerializers/NicknameSerializer.cpp +++ b/Swiften/Serializer/PayloadSerializers/NicknameSerializer.cpp @@ -4,12 +4,12 @@ * See Documentation/Licenses/GPLv3.txt for more information. */ -#include "Swiften/Serializer/PayloadSerializers/NicknameSerializer.h" +#include <Swiften/Serializer/PayloadSerializers/NicknameSerializer.h> #include <boost/shared_ptr.hpp> -#include "Swiften/Serializer/XML/XMLElement.h" -#include "Swiften/Serializer/XML/XMLTextNode.h" +#include <Swiften/Serializer/XML/XMLElement.h> +#include <Swiften/Serializer/XML/XMLTextNode.h> namespace Swift { diff --git a/Swiften/Serializer/PayloadSerializers/NicknameSerializer.h b/Swiften/Serializer/PayloadSerializers/NicknameSerializer.h index e07767b..382ec11 100644 --- a/Swiften/Serializer/PayloadSerializers/NicknameSerializer.h +++ b/Swiften/Serializer/PayloadSerializers/NicknameSerializer.h @@ -6,8 +6,8 @@ #pragma once -#include "Swiften/Serializer/GenericPayloadSerializer.h" -#include "Swiften/Elements/Nickname.h" +#include <Swiften/Serializer/GenericPayloadSerializer.h> +#include <Swiften/Elements/Nickname.h> namespace Swift { class NicknameSerializer : public GenericPayloadSerializer<Nickname> { diff --git a/Swiften/Serializer/PayloadSerializers/PrioritySerializer.h b/Swiften/Serializer/PayloadSerializers/PrioritySerializer.h index cc96ce7..f45d23f 100644 --- a/Swiften/Serializer/PayloadSerializers/PrioritySerializer.h +++ b/Swiften/Serializer/PayloadSerializers/PrioritySerializer.h @@ -9,8 +9,8 @@ #include <boost/lexical_cast.hpp> -#include "Swiften/Serializer/GenericPayloadSerializer.h" -#include "Swiften/Elements/Priority.h" +#include <Swiften/Serializer/GenericPayloadSerializer.h> +#include <Swiften/Elements/Priority.h> namespace Swift { class PrioritySerializer : public GenericPayloadSerializer<Priority> { diff --git a/Swiften/Serializer/PayloadSerializers/PrivateStorageSerializer.cpp b/Swiften/Serializer/PayloadSerializers/PrivateStorageSerializer.cpp index 6e1d74d..6cb226c 100644 --- a/Swiften/Serializer/PayloadSerializers/PrivateStorageSerializer.cpp +++ b/Swiften/Serializer/PayloadSerializers/PrivateStorageSerializer.cpp @@ -4,15 +4,15 @@ * See Documentation/Licenses/GPLv3.txt for more information. */ -#include "Swiften/Serializer/PayloadSerializers/PrivateStorageSerializer.h" +#include <Swiften/Serializer/PayloadSerializers/PrivateStorageSerializer.h> #include <boost/shared_ptr.hpp> -#include "Swiften/Base/foreach.h" -#include "Swiften/Serializer/XML/XMLElement.h" -#include "Swiften/Serializer/XML/XMLTextNode.h" -#include "Swiften/Serializer/XML/XMLRawTextNode.h" -#include "Swiften/Serializer/PayloadSerializerCollection.h" +#include <Swiften/Base/foreach.h> +#include <Swiften/Serializer/XML/XMLElement.h> +#include <Swiften/Serializer/XML/XMLTextNode.h> +#include <Swiften/Serializer/XML/XMLRawTextNode.h> +#include <Swiften/Serializer/PayloadSerializerCollection.h> namespace Swift { diff --git a/Swiften/Serializer/PayloadSerializers/PrivateStorageSerializer.h b/Swiften/Serializer/PayloadSerializers/PrivateStorageSerializer.h index 7b46136..3548cac 100644 --- a/Swiften/Serializer/PayloadSerializers/PrivateStorageSerializer.h +++ b/Swiften/Serializer/PayloadSerializers/PrivateStorageSerializer.h @@ -6,8 +6,8 @@ #pragma once -#include "Swiften/Serializer/GenericPayloadSerializer.h" -#include "Swiften/Elements/PrivateStorage.h" +#include <Swiften/Serializer/GenericPayloadSerializer.h> +#include <Swiften/Elements/PrivateStorage.h> namespace Swift { class PayloadSerializerCollection; diff --git a/Swiften/Serializer/PayloadSerializers/RawXMLPayloadSerializer.h b/Swiften/Serializer/PayloadSerializers/RawXMLPayloadSerializer.h index 6874569..02a5564 100644 --- a/Swiften/Serializer/PayloadSerializers/RawXMLPayloadSerializer.h +++ b/Swiften/Serializer/PayloadSerializers/RawXMLPayloadSerializer.h @@ -6,8 +6,8 @@ #pragma once -#include "Swiften/Serializer/GenericPayloadSerializer.h" -#include "Swiften/Elements/RawXMLPayload.h" +#include <Swiften/Serializer/GenericPayloadSerializer.h> +#include <Swiften/Elements/RawXMLPayload.h> namespace Swift { class RawXMLPayloadSerializer : public GenericPayloadSerializer<RawXMLPayload> { diff --git a/Swiften/Serializer/PayloadSerializers/ReplaceSerializer.h b/Swiften/Serializer/PayloadSerializers/ReplaceSerializer.h new file mode 100644 index 0000000..88ad2b3 --- /dev/null +++ b/Swiften/Serializer/PayloadSerializers/ReplaceSerializer.h @@ -0,0 +1,22 @@ +/* + * Copyright (c) 2011 Vlad Voicu + * Licensed under the Simplified BSD license. + * See Documentation/Licenses/BSD-simplified.txt for more information. + */ + +#pragma once + +#include <Swiften/Serializer/GenericPayloadSerializer.h> +#include <Swiften/Serializer/XML/XMLTextNode.h> +#include <Swiften/Elements/Replace.h> + +namespace Swift { + class ReplaceSerializer : public GenericPayloadSerializer<Replace> { + public: + ReplaceSerializer() : GenericPayloadSerializer<Replace>() {} + + virtual std::string serializePayload(boost::shared_ptr<Replace> replace) const { + return "<replace id = '" + replace->getID() + "' xmlns='http://swift.im/protocol/replace'/>"; + } + }; +} diff --git a/Swiften/Serializer/PayloadSerializers/ResourceBindSerializer.cpp b/Swiften/Serializer/PayloadSerializers/ResourceBindSerializer.cpp index cfb3a90..af0c609 100644 --- a/Swiften/Serializer/PayloadSerializers/ResourceBindSerializer.cpp +++ b/Swiften/Serializer/PayloadSerializers/ResourceBindSerializer.cpp @@ -4,12 +4,12 @@ * See Documentation/Licenses/GPLv3.txt for more information. */ -#include "Swiften/Serializer/PayloadSerializers/ResourceBindSerializer.h" +#include <Swiften/Serializer/PayloadSerializers/ResourceBindSerializer.h> #include <boost/shared_ptr.hpp> -#include "Swiften/Serializer/XML/XMLElement.h" -#include "Swiften/Serializer/XML/XMLTextNode.h" +#include <Swiften/Serializer/XML/XMLElement.h> +#include <Swiften/Serializer/XML/XMLTextNode.h> namespace Swift { diff --git a/Swiften/Serializer/PayloadSerializers/ResourceBindSerializer.h b/Swiften/Serializer/PayloadSerializers/ResourceBindSerializer.h index d259555..243a53d 100644 --- a/Swiften/Serializer/PayloadSerializers/ResourceBindSerializer.h +++ b/Swiften/Serializer/PayloadSerializers/ResourceBindSerializer.h @@ -7,8 +7,8 @@ #ifndef SWIFTEN_ResourceBindSerializer_H #define SWIFTEN_ResourceBindSerializer_H -#include "Swiften/Serializer/GenericPayloadSerializer.h" -#include "Swiften/Elements/ResourceBind.h" +#include <Swiften/Serializer/GenericPayloadSerializer.h> +#include <Swiften/Elements/ResourceBind.h> namespace Swift { class ResourceBindSerializer : public GenericPayloadSerializer<ResourceBind> { diff --git a/Swiften/Serializer/PayloadSerializers/RosterItemExchangeSerializer.cpp b/Swiften/Serializer/PayloadSerializers/RosterItemExchangeSerializer.cpp new file mode 100644 index 0000000..b60db12 --- /dev/null +++ b/Swiften/Serializer/PayloadSerializers/RosterItemExchangeSerializer.cpp @@ -0,0 +1,46 @@ +/* + * Copyright (c) 2011 Jan Kaluza + * Licensed under the Simplified BSD license. + * See Documentation/Licenses/BSD-simplified.txt for more information. + */ + +#include <Swiften/Serializer/PayloadSerializers/RosterItemExchangeSerializer.h> + +#include <boost/shared_ptr.hpp> + +#include <Swiften/Base/foreach.h> +#include <Swiften/Serializer/XML/XMLTextNode.h> +#include <Swiften/Serializer/XML/XMLRawTextNode.h> +#include <Swiften/Serializer/XML/XMLElement.h> + +namespace Swift { + +RosterItemExchangeSerializer::RosterItemExchangeSerializer() : GenericPayloadSerializer<RosterItemExchangePayload>() { +} + +std::string RosterItemExchangeSerializer::serializePayload(boost::shared_ptr<RosterItemExchangePayload> roster) const { + XMLElement queryElement("x", "http://jabber.org/protocol/rosterx"); + foreach(const RosterItemExchangePayload::Item& item, roster->getItems()) { + boost::shared_ptr<XMLElement> itemElement(new XMLElement("item")); + itemElement->setAttribute("jid", item.getJID()); + itemElement->setAttribute("name", item.getName()); + + switch (item.getAction()) { + case RosterItemExchangePayload::Item::Add: itemElement->setAttribute("action", "add"); break; + case RosterItemExchangePayload::Item::Modify: itemElement->setAttribute("action", "modify"); break; + case RosterItemExchangePayload::Item::Delete: itemElement->setAttribute("action", "delete"); break; + } + + foreach(const std::string& group, item.getGroups()) { + boost::shared_ptr<XMLElement> groupElement(new XMLElement("group")); + groupElement->addNode(boost::shared_ptr<XMLTextNode>(new XMLTextNode(group))); + itemElement->addNode(groupElement); + } + + queryElement.addNode(itemElement); + } + + return queryElement.serialize(); +} + +} diff --git a/Swiften/Serializer/PayloadSerializers/RosterItemExchangeSerializer.h b/Swiften/Serializer/PayloadSerializers/RosterItemExchangeSerializer.h new file mode 100644 index 0000000..f246f9e --- /dev/null +++ b/Swiften/Serializer/PayloadSerializers/RosterItemExchangeSerializer.h @@ -0,0 +1,19 @@ +/* + * Copyright (c) 2011 Jan Kaluza + * Licensed under the Simplified BSD license. + * See Documentation/Licenses/BSD-simplified.txt for more information. + */ + +#pragma once + +#include <Swiften/Serializer/GenericPayloadSerializer.h> +#include <Swiften/Elements/RosterItemExchangePayload.h> + +namespace Swift { + class RosterItemExchangeSerializer : public GenericPayloadSerializer<RosterItemExchangePayload> { + public: + RosterItemExchangeSerializer(); + + virtual std::string serializePayload(boost::shared_ptr<RosterItemExchangePayload>) const; + }; +} diff --git a/Swiften/Serializer/PayloadSerializers/RosterSerializer.cpp b/Swiften/Serializer/PayloadSerializers/RosterSerializer.cpp index 40faf73..84f36d2 100644 --- a/Swiften/Serializer/PayloadSerializers/RosterSerializer.cpp +++ b/Swiften/Serializer/PayloadSerializers/RosterSerializer.cpp @@ -4,14 +4,14 @@ * See Documentation/Licenses/GPLv3.txt for more information. */ -#include "Swiften/Serializer/PayloadSerializers/RosterSerializer.h" +#include <Swiften/Serializer/PayloadSerializers/RosterSerializer.h> #include <boost/shared_ptr.hpp> -#include "Swiften/Base/foreach.h" -#include "Swiften/Serializer/XML/XMLTextNode.h" -#include "Swiften/Serializer/XML/XMLRawTextNode.h" -#include "Swiften/Serializer/XML/XMLElement.h" +#include <Swiften/Base/foreach.h> +#include <Swiften/Serializer/XML/XMLTextNode.h> +#include <Swiften/Serializer/XML/XMLRawTextNode.h> +#include <Swiften/Serializer/XML/XMLElement.h> namespace Swift { @@ -20,6 +20,9 @@ RosterSerializer::RosterSerializer() : GenericPayloadSerializer<RosterPayload>() std::string RosterSerializer::serializePayload(boost::shared_ptr<RosterPayload> roster) const { XMLElement queryElement("query", "jabber:iq:roster"); + if (roster->getVersion()) { + queryElement.setAttribute("ver", *roster->getVersion()); + } foreach(const RosterItemPayload& item, roster->getItems()) { boost::shared_ptr<XMLElement> itemElement(new XMLElement("item")); itemElement->setAttribute("jid", item.getJID()); diff --git a/Swiften/Serializer/PayloadSerializers/RosterSerializer.h b/Swiften/Serializer/PayloadSerializers/RosterSerializer.h index 49e194b..674882f 100644 --- a/Swiften/Serializer/PayloadSerializers/RosterSerializer.h +++ b/Swiften/Serializer/PayloadSerializers/RosterSerializer.h @@ -7,8 +7,8 @@ #ifndef SWIFTEN_RosterSerializer_H #define SWIFTEN_RosterSerializer_H -#include "Swiften/Serializer/GenericPayloadSerializer.h" -#include "Swiften/Elements/RosterPayload.h" +#include <Swiften/Serializer/GenericPayloadSerializer.h> +#include <Swiften/Elements/RosterPayload.h> namespace Swift { class RosterSerializer : public GenericPayloadSerializer<RosterPayload> { diff --git a/Swiften/Serializer/PayloadSerializers/SearchPayloadSerializer.cpp b/Swiften/Serializer/PayloadSerializers/SearchPayloadSerializer.cpp index a7a9fda..a5cd634 100644 --- a/Swiften/Serializer/PayloadSerializers/SearchPayloadSerializer.cpp +++ b/Swiften/Serializer/PayloadSerializers/SearchPayloadSerializer.cpp @@ -4,14 +4,14 @@ * See Documentation/Licenses/GPLv3.txt for more information. */ -#include "Swiften/Serializer/PayloadSerializers/SearchPayloadSerializer.h" +#include <Swiften/Serializer/PayloadSerializers/SearchPayloadSerializer.h> #include <boost/shared_ptr.hpp> -#include "Swiften/Base/foreach.h" -#include "Swiften/Serializer/XML/XMLElement.h" -#include "Swiften/Serializer/XML/XMLRawTextNode.h" -#include "Swiften/Serializer/PayloadSerializers/FormSerializer.h" +#include <Swiften/Base/foreach.h> +#include <Swiften/Serializer/XML/XMLElement.h> +#include <Swiften/Serializer/XML/XMLRawTextNode.h> +#include <Swiften/Serializer/PayloadSerializers/FormSerializer.h> namespace Swift { diff --git a/Swiften/Serializer/PayloadSerializers/SearchPayloadSerializer.h b/Swiften/Serializer/PayloadSerializers/SearchPayloadSerializer.h index 2d8ec85..e4dbff8 100644 --- a/Swiften/Serializer/PayloadSerializers/SearchPayloadSerializer.h +++ b/Swiften/Serializer/PayloadSerializers/SearchPayloadSerializer.h @@ -7,8 +7,8 @@ #pragma once -#include "Swiften/Serializer/GenericPayloadSerializer.h" -#include "Swiften/Elements/SearchPayload.h" +#include <Swiften/Serializer/GenericPayloadSerializer.h> +#include <Swiften/Elements/SearchPayload.h> namespace Swift { class PayloadSerializerCollection; diff --git a/Swiften/Serializer/PayloadSerializers/SecurityLabelSerializer.cpp b/Swiften/Serializer/PayloadSerializers/SecurityLabelSerializer.cpp index b9ec55e..51079ee 100644 --- a/Swiften/Serializer/PayloadSerializers/SecurityLabelSerializer.cpp +++ b/Swiften/Serializer/PayloadSerializers/SecurityLabelSerializer.cpp @@ -4,11 +4,11 @@ * See Documentation/Licenses/GPLv3.txt for more information. */ -#include "Swiften/Serializer/PayloadSerializers/SecurityLabelSerializer.h" -#include "Swiften/Base/foreach.h" -#include "Swiften/Serializer/XML/XMLRawTextNode.h" -#include "Swiften/Serializer/XML/XMLTextNode.h" -#include "Swiften/Serializer/XML/XMLElement.h" +#include <Swiften/Serializer/PayloadSerializers/SecurityLabelSerializer.h> +#include <Swiften/Base/foreach.h> +#include <Swiften/Serializer/XML/XMLRawTextNode.h> +#include <Swiften/Serializer/XML/XMLTextNode.h> +#include <Swiften/Serializer/XML/XMLElement.h> namespace Swift { diff --git a/Swiften/Serializer/PayloadSerializers/SecurityLabelSerializer.h b/Swiften/Serializer/PayloadSerializers/SecurityLabelSerializer.h index a02aeb9..838f8d3 100644 --- a/Swiften/Serializer/PayloadSerializers/SecurityLabelSerializer.h +++ b/Swiften/Serializer/PayloadSerializers/SecurityLabelSerializer.h @@ -7,8 +7,8 @@ #ifndef SWIFTEN_SecurityLabelSerializer_H #define SWIFTEN_SecurityLabelSerializer_H -#include "Swiften/Serializer/GenericPayloadSerializer.h" -#include "Swiften/Elements/SecurityLabel.h" +#include <Swiften/Serializer/GenericPayloadSerializer.h> +#include <Swiften/Elements/SecurityLabel.h> namespace Swift { class SecurityLabelSerializer : public GenericPayloadSerializer<SecurityLabel> { diff --git a/Swiften/Serializer/PayloadSerializers/SecurityLabelsCatalogSerializer.cpp b/Swiften/Serializer/PayloadSerializers/SecurityLabelsCatalogSerializer.cpp index 7424c98..1078292 100644 --- a/Swiften/Serializer/PayloadSerializers/SecurityLabelsCatalogSerializer.cpp +++ b/Swiften/Serializer/PayloadSerializers/SecurityLabelsCatalogSerializer.cpp @@ -4,11 +4,11 @@ * See Documentation/Licenses/GPLv3.txt for more information. */ -#include "Swiften/Serializer/PayloadSerializers/SecurityLabelsCatalogSerializer.h" -#include "Swiften/Base/foreach.h" -#include "Swiften/Serializer/XML/XMLElement.h" -#include "Swiften/Serializer/XML/XMLRawTextNode.h" -#include "Swiften/Serializer/PayloadSerializers/SecurityLabelSerializer.h" +#include <Swiften/Serializer/PayloadSerializers/SecurityLabelsCatalogSerializer.h> +#include <Swiften/Base/foreach.h> +#include <Swiften/Serializer/XML/XMLElement.h> +#include <Swiften/Serializer/XML/XMLRawTextNode.h> +#include <Swiften/Serializer/PayloadSerializers/SecurityLabelSerializer.h> namespace Swift { diff --git a/Swiften/Serializer/PayloadSerializers/SecurityLabelsCatalogSerializer.h b/Swiften/Serializer/PayloadSerializers/SecurityLabelsCatalogSerializer.h index 88a1541..4d3d33a 100644 --- a/Swiften/Serializer/PayloadSerializers/SecurityLabelsCatalogSerializer.h +++ b/Swiften/Serializer/PayloadSerializers/SecurityLabelsCatalogSerializer.h @@ -7,8 +7,8 @@ #ifndef SWIFTEN_SecurityLabelsCatalogSerializer_H #define SWIFTEN_SecurityLabelsCatalogSerializer_H -#include "Swiften/Serializer/GenericPayloadSerializer.h" -#include "Swiften/Elements/SecurityLabelsCatalog.h" +#include <Swiften/Serializer/GenericPayloadSerializer.h> +#include <Swiften/Elements/SecurityLabelsCatalog.h> namespace Swift { class SecurityLabelsCatalogSerializer : public GenericPayloadSerializer<SecurityLabelsCatalog> { diff --git a/Swiften/Serializer/PayloadSerializers/SoftwareVersionSerializer.cpp b/Swiften/Serializer/PayloadSerializers/SoftwareVersionSerializer.cpp index b2eb1ed..e117167 100644 --- a/Swiften/Serializer/PayloadSerializers/SoftwareVersionSerializer.cpp +++ b/Swiften/Serializer/PayloadSerializers/SoftwareVersionSerializer.cpp @@ -4,7 +4,7 @@ * See Documentation/Licenses/GPLv3.txt for more information. */ -#include "Swiften/Serializer/PayloadSerializers/SoftwareVersionSerializer.h" +#include <Swiften/Serializer/PayloadSerializers/SoftwareVersionSerializer.h> namespace Swift { diff --git a/Swiften/Serializer/PayloadSerializers/SoftwareVersionSerializer.h b/Swiften/Serializer/PayloadSerializers/SoftwareVersionSerializer.h index 72f4afd..f4fbb0f 100644 --- a/Swiften/Serializer/PayloadSerializers/SoftwareVersionSerializer.h +++ b/Swiften/Serializer/PayloadSerializers/SoftwareVersionSerializer.h @@ -7,8 +7,8 @@ #ifndef SWIFTEN_SoftwareVersionSerializer_H #define SWIFTEN_SoftwareVersionSerializer_H -#include "Swiften/Serializer/GenericPayloadSerializer.h" -#include "Swiften/Elements/SoftwareVersion.h" +#include <Swiften/Serializer/GenericPayloadSerializer.h> +#include <Swiften/Elements/SoftwareVersion.h> namespace Swift { class SoftwareVersionSerializer : public GenericPayloadSerializer<SoftwareVersion> { diff --git a/Swiften/Serializer/PayloadSerializers/StartSessionSerializer.h b/Swiften/Serializer/PayloadSerializers/StartSessionSerializer.h index dd9ba97..497134e 100644 --- a/Swiften/Serializer/PayloadSerializers/StartSessionSerializer.h +++ b/Swiften/Serializer/PayloadSerializers/StartSessionSerializer.h @@ -9,8 +9,8 @@ #include <boost/lexical_cast.hpp> -#include "Swiften/Serializer/GenericPayloadSerializer.h" -#include "Swiften/Elements/StartSession.h" +#include <Swiften/Serializer/GenericPayloadSerializer.h> +#include <Swiften/Elements/StartSession.h> namespace Swift { class StartSessionSerializer : public GenericPayloadSerializer<StartSession> { diff --git a/Swiften/Serializer/PayloadSerializers/StatusSerializer.h b/Swiften/Serializer/PayloadSerializers/StatusSerializer.h index 565d554..68efbda 100644 --- a/Swiften/Serializer/PayloadSerializers/StatusSerializer.h +++ b/Swiften/Serializer/PayloadSerializers/StatusSerializer.h @@ -7,10 +7,10 @@ #ifndef SWIFTEN_StatusSerializer_H #define SWIFTEN_StatusSerializer_H -#include "Swiften/Serializer/GenericPayloadSerializer.h" -#include "Swiften/Serializer/XML/XMLElement.h" -#include "Swiften/Serializer/XML/XMLTextNode.h" -#include "Swiften/Elements/Status.h" +#include <Swiften/Serializer/GenericPayloadSerializer.h> +#include <Swiften/Serializer/XML/XMLElement.h> +#include <Swiften/Serializer/XML/XMLTextNode.h> +#include <Swiften/Elements/Status.h> namespace Swift { class StatusSerializer : public GenericPayloadSerializer<Status> { diff --git a/Swiften/Serializer/PayloadSerializers/StatusShowSerializer.h b/Swiften/Serializer/PayloadSerializers/StatusShowSerializer.h index e797e81..c4d4466 100644 --- a/Swiften/Serializer/PayloadSerializers/StatusShowSerializer.h +++ b/Swiften/Serializer/PayloadSerializers/StatusShowSerializer.h @@ -7,8 +7,8 @@ #ifndef SWIFTEN_StatusShowSerializer_H #define SWIFTEN_StatusShowSerializer_H -#include "Swiften/Serializer/GenericPayloadSerializer.h" -#include "Swiften/Elements/StatusShow.h" +#include <Swiften/Serializer/GenericPayloadSerializer.h> +#include <Swiften/Elements/StatusShow.h> namespace Swift { class StatusShowSerializer : public GenericPayloadSerializer<StatusShow> { diff --git a/Swiften/Serializer/PayloadSerializers/StorageSerializer.cpp b/Swiften/Serializer/PayloadSerializers/StorageSerializer.cpp index 049c797..30adf26 100644 --- a/Swiften/Serializer/PayloadSerializers/StorageSerializer.cpp +++ b/Swiften/Serializer/PayloadSerializers/StorageSerializer.cpp @@ -4,13 +4,13 @@ * See Documentation/Licenses/GPLv3.txt for more information. */ -#include "Swiften/Serializer/PayloadSerializers/StorageSerializer.h" +#include <Swiften/Serializer/PayloadSerializers/StorageSerializer.h> #include <boost/shared_ptr.hpp> -#include "Swiften/Base/foreach.h" -#include "Swiften/Serializer/XML/XMLElement.h" -#include "Swiften/Serializer/XML/XMLTextNode.h" +#include <Swiften/Base/foreach.h> +#include <Swiften/Serializer/XML/XMLElement.h> +#include <Swiften/Serializer/XML/XMLTextNode.h> namespace Swift { diff --git a/Swiften/Serializer/PayloadSerializers/StorageSerializer.h b/Swiften/Serializer/PayloadSerializers/StorageSerializer.h index bc682a6..6f4f03b 100644 --- a/Swiften/Serializer/PayloadSerializers/StorageSerializer.h +++ b/Swiften/Serializer/PayloadSerializers/StorageSerializer.h @@ -6,8 +6,8 @@ #pragma once -#include "Swiften/Serializer/GenericPayloadSerializer.h" -#include "Swiften/Elements/Storage.h" +#include <Swiften/Serializer/GenericPayloadSerializer.h> +#include <Swiften/Elements/Storage.h> namespace Swift { class StorageSerializer : public GenericPayloadSerializer<Storage> { diff --git a/Swiften/Serializer/PayloadSerializers/StreamInitiationSerializer.cpp b/Swiften/Serializer/PayloadSerializers/StreamInitiationSerializer.cpp index 70fb2ac..9a0f37c 100644 --- a/Swiften/Serializer/PayloadSerializers/StreamInitiationSerializer.cpp +++ b/Swiften/Serializer/PayloadSerializers/StreamInitiationSerializer.cpp @@ -4,17 +4,17 @@ * See Documentation/Licenses/GPLv3.txt for more information. */ -#include "Swiften/Serializer/PayloadSerializers/StreamInitiationSerializer.h" +#include <Swiften/Serializer/PayloadSerializers/StreamInitiationSerializer.h> #include <boost/shared_ptr.hpp> #include <boost/lexical_cast.hpp> -#include "Swiften/Base/foreach.h" -#include "Swiften/Serializer/XML/XMLElement.h" -#include "Swiften/Serializer/XML/XMLTextNode.h" -#include "Swiften/Serializer/XML/XMLRawTextNode.h" -#include "Swiften/Serializer/PayloadSerializerCollection.h" -#include "Swiften/Serializer/PayloadSerializers/FormSerializer.h" +#include <Swiften/Base/foreach.h> +#include <Swiften/Serializer/XML/XMLElement.h> +#include <Swiften/Serializer/XML/XMLTextNode.h> +#include <Swiften/Serializer/XML/XMLRawTextNode.h> +#include <Swiften/Serializer/PayloadSerializerCollection.h> +#include <Swiften/Serializer/PayloadSerializers/FormSerializer.h> #define FILE_TRANSFER_NS "http://jabber.org/protocol/si/profile/file-transfer" @@ -49,7 +49,7 @@ std::string StreamInitiationSerializer::serializePayload(boost::shared_ptr<Strea siElement.addNode(fileElement); } - boost::shared_ptr<XMLElement> featureElement(new XMLElement("feature", "http://jabber.org/protocol/feature-neg")); + boost::shared_ptr<XMLElement> featureElement(new XMLElement("feature", FEATURE_NEG_NS)); if (streamInitiation->getProvidedMethods().size() > 0) { Form::ref form(new Form(Form::FormType)); ListSingleFormField::ref field = ListSingleFormField::create(); diff --git a/Swiften/Serializer/PayloadSerializers/StreamInitiationSerializer.h b/Swiften/Serializer/PayloadSerializers/StreamInitiationSerializer.h index 0b51519..f28493b 100644 --- a/Swiften/Serializer/PayloadSerializers/StreamInitiationSerializer.h +++ b/Swiften/Serializer/PayloadSerializers/StreamInitiationSerializer.h @@ -6,8 +6,8 @@ #pragma once -#include "Swiften/Serializer/GenericPayloadSerializer.h" -#include "Swiften/Elements/StreamInitiation.h" +#include <Swiften/Serializer/GenericPayloadSerializer.h> +#include <Swiften/Elements/StreamInitiation.h> namespace Swift { class PayloadSerializerCollection; diff --git a/Swiften/Serializer/PayloadSerializers/SubjectSerializer.h b/Swiften/Serializer/PayloadSerializers/SubjectSerializer.h index cf78ddd..fe82499 100644 --- a/Swiften/Serializer/PayloadSerializers/SubjectSerializer.h +++ b/Swiften/Serializer/PayloadSerializers/SubjectSerializer.h @@ -6,9 +6,9 @@ #pragma once -#include "Swiften/Serializer/GenericPayloadSerializer.h" -#include "Swiften/Serializer/XML/XMLTextNode.h" -#include "Swiften/Elements/Subject.h" +#include <Swiften/Serializer/GenericPayloadSerializer.h> +#include <Swiften/Serializer/XML/XMLTextNode.h> +#include <Swiften/Elements/Subject.h> namespace Swift { class SubjectSerializer : public GenericPayloadSerializer<Subject> { diff --git a/Swiften/Serializer/PayloadSerializers/UnitTest/CapsInfoSerializerTest.cpp b/Swiften/Serializer/PayloadSerializers/UnitTest/CapsInfoSerializerTest.cpp index 2604331..270d165 100644 --- a/Swiften/Serializer/PayloadSerializers/UnitTest/CapsInfoSerializerTest.cpp +++ b/Swiften/Serializer/PayloadSerializers/UnitTest/CapsInfoSerializerTest.cpp @@ -7,7 +7,7 @@ #include <cppunit/extensions/HelperMacros.h> #include <cppunit/extensions/TestFactoryRegistry.h> -#include "Swiften/Serializer/PayloadSerializers/CapsInfoSerializer.h" +#include <Swiften/Serializer/PayloadSerializers/CapsInfoSerializer.h> using namespace Swift; diff --git a/Swiften/Serializer/PayloadSerializers/UnitTest/DiscoInfoSerializerTest.cpp b/Swiften/Serializer/PayloadSerializers/UnitTest/DiscoInfoSerializerTest.cpp index 3875efd..32f5f49 100644 --- a/Swiften/Serializer/PayloadSerializers/UnitTest/DiscoInfoSerializerTest.cpp +++ b/Swiften/Serializer/PayloadSerializers/UnitTest/DiscoInfoSerializerTest.cpp @@ -7,7 +7,7 @@ #include <cppunit/extensions/HelperMacros.h> #include <cppunit/extensions/TestFactoryRegistry.h> -#include "Swiften/Serializer/PayloadSerializers/DiscoInfoSerializer.h" +#include <Swiften/Serializer/PayloadSerializers/DiscoInfoSerializer.h> using namespace Swift; diff --git a/Swiften/Serializer/PayloadSerializers/UnitTest/ErrorSerializerTest.cpp b/Swiften/Serializer/PayloadSerializers/UnitTest/ErrorSerializerTest.cpp index dd06244..27d4ac5 100644 --- a/Swiften/Serializer/PayloadSerializers/UnitTest/ErrorSerializerTest.cpp +++ b/Swiften/Serializer/PayloadSerializers/UnitTest/ErrorSerializerTest.cpp @@ -7,7 +7,7 @@ #include <cppunit/extensions/HelperMacros.h> #include <cppunit/extensions/TestFactoryRegistry.h> -#include "Swiften/Serializer/PayloadSerializers/ErrorSerializer.h" +#include <Swiften/Serializer/PayloadSerializers/ErrorSerializer.h> using namespace Swift; diff --git a/Swiften/Serializer/PayloadSerializers/UnitTest/FormSerializerTest.cpp b/Swiften/Serializer/PayloadSerializers/UnitTest/FormSerializerTest.cpp index e4a6661..29e7e59 100644 --- a/Swiften/Serializer/PayloadSerializers/UnitTest/FormSerializerTest.cpp +++ b/Swiften/Serializer/PayloadSerializers/UnitTest/FormSerializerTest.cpp @@ -7,7 +7,7 @@ #include <cppunit/extensions/HelperMacros.h> #include <cppunit/extensions/TestFactoryRegistry.h> -#include "Swiften/Serializer/PayloadSerializers/FormSerializer.h" +#include <Swiften/Serializer/PayloadSerializers/FormSerializer.h> using namespace Swift; @@ -96,13 +96,6 @@ class FormSerializerTest : public CppUnit::TestFixture { field->setDescription("Tell all your friends about your new bot!"); form->addField(field); - std::vector<std::string> values2; - values2.push_back("foo"); - values2.push_back("bar"); - field = UntypedFormField::create(values2); - field->setName("fum"); - form->addField(field); - CPPUNIT_ASSERT_EQUAL(std::string( "<x type=\"form\" xmlns=\"jabber:x:data\">" "<field type=\"hidden\" var=\"FORM_TYPE\">" @@ -139,10 +132,6 @@ class FormSerializerTest : public CppUnit::TestFixture { "<value>foo@bar.com</value>" "<value>baz@fum.org</value>" "</field>" - "<field var=\"fum\">" - "<value>foo</value>" - "<value>bar</value>" - "</field>" "</x>"), testling.serialize(form)); } }; diff --git a/Swiften/Serializer/PayloadSerializers/UnitTest/InBandRegistrationPayloadSerializerTest.cpp b/Swiften/Serializer/PayloadSerializers/UnitTest/InBandRegistrationPayloadSerializerTest.cpp index 7020537..df43e69 100644 --- a/Swiften/Serializer/PayloadSerializers/UnitTest/InBandRegistrationPayloadSerializerTest.cpp +++ b/Swiften/Serializer/PayloadSerializers/UnitTest/InBandRegistrationPayloadSerializerTest.cpp @@ -7,7 +7,7 @@ #include <cppunit/extensions/HelperMacros.h> #include <cppunit/extensions/TestFactoryRegistry.h> -#include "Swiften/Serializer/PayloadSerializers/InBandRegistrationPayloadSerializer.h" +#include <Swiften/Serializer/PayloadSerializers/InBandRegistrationPayloadSerializer.h> using namespace Swift; diff --git a/Swiften/Serializer/PayloadSerializers/UnitTest/PayloadsSerializer.cpp b/Swiften/Serializer/PayloadSerializers/UnitTest/PayloadsSerializer.cpp index 481d9c2..9eed97e 100644 --- a/Swiften/Serializer/PayloadSerializers/UnitTest/PayloadsSerializer.cpp +++ b/Swiften/Serializer/PayloadSerializers/UnitTest/PayloadsSerializer.cpp @@ -4,11 +4,11 @@ * See Documentation/Licenses/GPLv3.txt for more information. */ -#include "Swiften/Serializer/PayloadSerializers/UnitTest/PayloadsSerializer.h" +#include <Swiften/Serializer/PayloadSerializers/UnitTest/PayloadsSerializer.h> #include <cppunit/extensions/HelperMacros.h> -#include "Swiften/Serializer/PayloadSerializer.h" +#include <Swiften/Serializer/PayloadSerializer.h> namespace Swift { diff --git a/Swiften/Serializer/PayloadSerializers/UnitTest/PayloadsSerializer.h b/Swiften/Serializer/PayloadSerializers/UnitTest/PayloadsSerializer.h index 038b616..01f07e4 100644 --- a/Swiften/Serializer/PayloadSerializers/UnitTest/PayloadsSerializer.h +++ b/Swiften/Serializer/PayloadSerializers/UnitTest/PayloadsSerializer.h @@ -8,9 +8,9 @@ #include <boost/shared_ptr.hpp> -#include "Swiften/Elements/Payload.h" +#include <Swiften/Elements/Payload.h> #include <string> -#include "Swiften/Serializer/PayloadSerializers/FullPayloadSerializerCollection.h" +#include <Swiften/Serializer/PayloadSerializers/FullPayloadSerializerCollection.h> namespace Swift { class PayloadsSerializer { diff --git a/Swiften/Serializer/PayloadSerializers/UnitTest/PrioritySerializerTest.cpp b/Swiften/Serializer/PayloadSerializers/UnitTest/PrioritySerializerTest.cpp index c976b12..f5b8bee 100644 --- a/Swiften/Serializer/PayloadSerializers/UnitTest/PrioritySerializerTest.cpp +++ b/Swiften/Serializer/PayloadSerializers/UnitTest/PrioritySerializerTest.cpp @@ -7,7 +7,7 @@ #include <cppunit/extensions/HelperMacros.h> #include <cppunit/extensions/TestFactoryRegistry.h> -#include "Swiften/Serializer/PayloadSerializers/PrioritySerializer.h" +#include <Swiften/Serializer/PayloadSerializers/PrioritySerializer.h> using namespace Swift; diff --git a/Swiften/Serializer/PayloadSerializers/UnitTest/PrivateStorageSerializerTest.cpp b/Swiften/Serializer/PayloadSerializers/UnitTest/PrivateStorageSerializerTest.cpp index b0f4084..23d71aa 100644 --- a/Swiften/Serializer/PayloadSerializers/UnitTest/PrivateStorageSerializerTest.cpp +++ b/Swiften/Serializer/PayloadSerializers/UnitTest/PrivateStorageSerializerTest.cpp @@ -7,9 +7,9 @@ #include <cppunit/extensions/HelperMacros.h> #include <cppunit/extensions/TestFactoryRegistry.h> -#include "Swiften/Serializer/PayloadSerializers/UnitTest/PayloadsSerializer.h" -#include "Swiften/Elements/PrivateStorage.h" -#include "Swiften/Elements/Storage.h" +#include <Swiften/Serializer/PayloadSerializers/UnitTest/PayloadsSerializer.h> +#include <Swiften/Elements/PrivateStorage.h> +#include <Swiften/Elements/Storage.h> using namespace Swift; diff --git a/Swiften/Serializer/PayloadSerializers/UnitTest/ReplaceSerializerTest.cpp b/Swiften/Serializer/PayloadSerializers/UnitTest/ReplaceSerializerTest.cpp new file mode 100644 index 0000000..3d054cc --- /dev/null +++ b/Swiften/Serializer/PayloadSerializers/UnitTest/ReplaceSerializerTest.cpp @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2011 Vlad Voicu + * Licensed under the Simplified BSD license. + * See Documentation/Licenses/BSD-simplified.txt for more information. + */ + +#include <cppunit/extensions/HelperMacros.h> +#include <cppunit/extensions/TestFactoryRegistry.h> + +#include <Swiften/Serializer/PayloadSerializers/ReplaceSerializer.h> + +using namespace Swift; + +class ReplaceSerializerTest: public CppUnit::TestFixture { + CPPUNIT_TEST_SUITE(ReplaceSerializerTest); + CPPUNIT_TEST(testSerialize); + CPPUNIT_TEST_SUITE_END(); + + public: + ReplaceSerializerTest() {} + + void testSerialize() { + ReplaceSerializer testling; + boost::shared_ptr<Replace> replace(new Replace()); + replace->setID("bad1"); + CPPUNIT_ASSERT_EQUAL(std::string("<replace id = 'bad1' xmlns='http://swift.im/protocol/replace'/>"), testling.serialize(replace)); + } +}; + +CPPUNIT_TEST_SUITE_REGISTRATION(ReplaceSerializerTest); diff --git a/Swiften/Serializer/PayloadSerializers/UnitTest/ResourceBindSerializerTest.cpp b/Swiften/Serializer/PayloadSerializers/UnitTest/ResourceBindSerializerTest.cpp index c7872fe..f8d3d30 100644 --- a/Swiften/Serializer/PayloadSerializers/UnitTest/ResourceBindSerializerTest.cpp +++ b/Swiften/Serializer/PayloadSerializers/UnitTest/ResourceBindSerializerTest.cpp @@ -7,7 +7,7 @@ #include <cppunit/extensions/HelperMacros.h> #include <cppunit/extensions/TestFactoryRegistry.h> -#include "Swiften/Serializer/PayloadSerializers/ResourceBindSerializer.h" +#include <Swiften/Serializer/PayloadSerializers/ResourceBindSerializer.h> using namespace Swift; diff --git a/Swiften/Serializer/PayloadSerializers/UnitTest/RosterItemExchangeSerializerTest.cpp b/Swiften/Serializer/PayloadSerializers/UnitTest/RosterItemExchangeSerializerTest.cpp new file mode 100644 index 0000000..b6a90d9 --- /dev/null +++ b/Swiften/Serializer/PayloadSerializers/UnitTest/RosterItemExchangeSerializerTest.cpp @@ -0,0 +1,54 @@ +/* + * Copyright (c) 2011 Jan Kaluza + * Licensed under the Simplified BSD license. + * See Documentation/Licenses/BSD-simplified.txt for more information. + */ + +#include <cppunit/extensions/HelperMacros.h> +#include <cppunit/extensions/TestFactoryRegistry.h> + +#include <Swiften/Serializer/PayloadSerializers/RosterItemExchangeSerializer.h> + +using namespace Swift; + +class RosterItemExchangeSerializerTest : public CppUnit::TestFixture +{ + CPPUNIT_TEST_SUITE(RosterItemExchangeSerializerTest); + CPPUNIT_TEST(testSerialize); + CPPUNIT_TEST_SUITE_END(); + + public: + RosterItemExchangeSerializerTest() {} + + void testSerialize() { + RosterItemExchangeSerializer testling; + boost::shared_ptr<RosterItemExchangePayload> roster(new RosterItemExchangePayload()); + + RosterItemExchangePayload::Item item1; + item1.setJID("foo@bar.com"); + item1.setName("Foo @ Bar"); + item1.setAction(RosterItemExchangePayload::Item::Add); + item1.addGroup("Group 1"); + item1.addGroup("Group 2"); + roster->addItem(item1); + + RosterItemExchangePayload::Item item2; + item2.setJID("baz@blo.com"); + item2.setName("Baz"); + item2.setAction(RosterItemExchangePayload::Item::Modify); + roster->addItem(item2); + + std::string expectedResult = + "<x xmlns=\"http://jabber.org/protocol/rosterx\">" + "<item action=\"add\" jid=\"foo@bar.com\" name=\"Foo @ Bar\">" + "<group>Group 1</group>" + "<group>Group 2</group>" + "</item>" + "<item action=\"modify\" jid=\"baz@blo.com\" name=\"Baz\"/>" + "</x>"; + + CPPUNIT_ASSERT_EQUAL(expectedResult, testling.serialize(roster)); + } +}; + +CPPUNIT_TEST_SUITE_REGISTRATION(RosterItemExchangeSerializerTest); diff --git a/Swiften/Serializer/PayloadSerializers/UnitTest/RosterSerializerTest.cpp b/Swiften/Serializer/PayloadSerializers/UnitTest/RosterSerializerTest.cpp index b8ceac3..9ecddc3 100644 --- a/Swiften/Serializer/PayloadSerializers/UnitTest/RosterSerializerTest.cpp +++ b/Swiften/Serializer/PayloadSerializers/UnitTest/RosterSerializerTest.cpp @@ -7,20 +7,19 @@ #include <cppunit/extensions/HelperMacros.h> #include <cppunit/extensions/TestFactoryRegistry.h> -#include "Swiften/Serializer/PayloadSerializers/RosterSerializer.h" +#include <Swiften/Serializer/PayloadSerializers/RosterSerializer.h> using namespace Swift; -class RosterSerializerTest : public CppUnit::TestFixture -{ +class RosterSerializerTest : public CppUnit::TestFixture { CPPUNIT_TEST_SUITE(RosterSerializerTest); CPPUNIT_TEST(testSerialize); CPPUNIT_TEST(testSerialize_ItemWithUnknownContent); + CPPUNIT_TEST(testSerialize_WithVersion); + CPPUNIT_TEST(testSerialize_WithEmptyVersion); CPPUNIT_TEST_SUITE_END(); public: - RosterSerializerTest() {} - void testSerialize() { RosterSerializer testling; boost::shared_ptr<RosterPayload> roster(new RosterPayload()); @@ -77,6 +76,26 @@ class RosterSerializerTest : public CppUnit::TestFixture CPPUNIT_ASSERT_EQUAL(expectedResult, testling.serialize(roster)); } + + void testSerialize_WithVersion() { + RosterSerializer testling; + boost::shared_ptr<RosterPayload> roster(new RosterPayload()); + roster->setVersion("ver20"); + + std::string expectedResult = "<query ver=\"ver20\" xmlns=\"jabber:iq:roster\"/>"; + + CPPUNIT_ASSERT_EQUAL(expectedResult, testling.serialize(roster)); + } + + void testSerialize_WithEmptyVersion() { + RosterSerializer testling; + boost::shared_ptr<RosterPayload> roster(new RosterPayload()); + roster->setVersion(""); + + std::string expectedResult = "<query ver=\"\" xmlns=\"jabber:iq:roster\"/>"; + + CPPUNIT_ASSERT_EQUAL(expectedResult, testling.serialize(roster)); + } }; CPPUNIT_TEST_SUITE_REGISTRATION(RosterSerializerTest); diff --git a/Swiften/Serializer/PayloadSerializers/UnitTest/SearchPayloadSerializerTest.cpp b/Swiften/Serializer/PayloadSerializers/UnitTest/SearchPayloadSerializerTest.cpp index e8328b8..d0dcbef 100644 --- a/Swiften/Serializer/PayloadSerializers/UnitTest/SearchPayloadSerializerTest.cpp +++ b/Swiften/Serializer/PayloadSerializers/UnitTest/SearchPayloadSerializerTest.cpp @@ -7,7 +7,7 @@ #include <cppunit/extensions/HelperMacros.h> #include <cppunit/extensions/TestFactoryRegistry.h> -#include "Swiften/Serializer/PayloadSerializers/SearchPayloadSerializer.h" +#include <Swiften/Serializer/PayloadSerializers/SearchPayloadSerializer.h> using namespace Swift; diff --git a/Swiften/Serializer/PayloadSerializers/UnitTest/SecurityLabelSerializerTest.cpp b/Swiften/Serializer/PayloadSerializers/UnitTest/SecurityLabelSerializerTest.cpp index 03bad89..0de509d 100644 --- a/Swiften/Serializer/PayloadSerializers/UnitTest/SecurityLabelSerializerTest.cpp +++ b/Swiften/Serializer/PayloadSerializers/UnitTest/SecurityLabelSerializerTest.cpp @@ -7,7 +7,7 @@ #include <cppunit/extensions/HelperMacros.h> #include <cppunit/extensions/TestFactoryRegistry.h> -#include "Swiften/Serializer/PayloadSerializers/SecurityLabelSerializer.h" +#include <Swiften/Serializer/PayloadSerializers/SecurityLabelSerializer.h> using namespace Swift; diff --git a/Swiften/Serializer/PayloadSerializers/UnitTest/SecurityLabelsCatalogSerializerTest.cpp b/Swiften/Serializer/PayloadSerializers/UnitTest/SecurityLabelsCatalogSerializerTest.cpp index a7bf1b9..c060e41 100644 --- a/Swiften/Serializer/PayloadSerializers/UnitTest/SecurityLabelsCatalogSerializerTest.cpp +++ b/Swiften/Serializer/PayloadSerializers/UnitTest/SecurityLabelsCatalogSerializerTest.cpp @@ -7,7 +7,7 @@ #include <cppunit/extensions/HelperMacros.h> #include <cppunit/extensions/TestFactoryRegistry.h> -#include "Swiften/Serializer/PayloadSerializers/SecurityLabelsCatalogSerializer.h" +#include <Swiften/Serializer/PayloadSerializers/SecurityLabelsCatalogSerializer.h> using namespace Swift; diff --git a/Swiften/Serializer/PayloadSerializers/UnitTest/SoftwareVersionSerializerTest.cpp b/Swiften/Serializer/PayloadSerializers/UnitTest/SoftwareVersionSerializerTest.cpp index 6fac094..ad1e9b4 100644 --- a/Swiften/Serializer/PayloadSerializers/UnitTest/SoftwareVersionSerializerTest.cpp +++ b/Swiften/Serializer/PayloadSerializers/UnitTest/SoftwareVersionSerializerTest.cpp @@ -7,7 +7,7 @@ #include <cppunit/extensions/HelperMacros.h> #include <cppunit/extensions/TestFactoryRegistry.h> -#include "Swiften/Serializer/PayloadSerializers/SoftwareVersionSerializer.h" +#include <Swiften/Serializer/PayloadSerializers/SoftwareVersionSerializer.h> using namespace Swift; diff --git a/Swiften/Serializer/PayloadSerializers/UnitTest/StatusSerializerTest.cpp b/Swiften/Serializer/PayloadSerializers/UnitTest/StatusSerializerTest.cpp index c0b1dc2..af90a0a 100644 --- a/Swiften/Serializer/PayloadSerializers/UnitTest/StatusSerializerTest.cpp +++ b/Swiften/Serializer/PayloadSerializers/UnitTest/StatusSerializerTest.cpp @@ -7,7 +7,7 @@ #include <cppunit/extensions/HelperMacros.h> #include <cppunit/extensions/TestFactoryRegistry.h> -#include "Swiften/Serializer/PayloadSerializers/StatusSerializer.h" +#include <Swiften/Serializer/PayloadSerializers/StatusSerializer.h> using namespace Swift; diff --git a/Swiften/Serializer/PayloadSerializers/UnitTest/StatusShowSerializerTest.cpp b/Swiften/Serializer/PayloadSerializers/UnitTest/StatusShowSerializerTest.cpp index 2fee152..898c835 100644 --- a/Swiften/Serializer/PayloadSerializers/UnitTest/StatusShowSerializerTest.cpp +++ b/Swiften/Serializer/PayloadSerializers/UnitTest/StatusShowSerializerTest.cpp @@ -7,7 +7,7 @@ #include <cppunit/extensions/HelperMacros.h> #include <cppunit/extensions/TestFactoryRegistry.h> -#include "Swiften/Serializer/PayloadSerializers/StatusShowSerializer.h" +#include <Swiften/Serializer/PayloadSerializers/StatusShowSerializer.h> using namespace Swift; diff --git a/Swiften/Serializer/PayloadSerializers/UnitTest/StorageSerializerTest.cpp b/Swiften/Serializer/PayloadSerializers/UnitTest/StorageSerializerTest.cpp index 01899a9..b963a9c 100644 --- a/Swiften/Serializer/PayloadSerializers/UnitTest/StorageSerializerTest.cpp +++ b/Swiften/Serializer/PayloadSerializers/UnitTest/StorageSerializerTest.cpp @@ -7,8 +7,8 @@ #include <cppunit/extensions/HelperMacros.h> #include <cppunit/extensions/TestFactoryRegistry.h> -#include "Swiften/Serializer/PayloadSerializers/UnitTest/PayloadsSerializer.h" -#include "Swiften/Elements/Storage.h" +#include <Swiften/Serializer/PayloadSerializers/UnitTest/PayloadsSerializer.h> +#include <Swiften/Elements/Storage.h> using namespace Swift; diff --git a/Swiften/Serializer/PayloadSerializers/UnitTest/StreamInitiationSerializerTest.cpp b/Swiften/Serializer/PayloadSerializers/UnitTest/StreamInitiationSerializerTest.cpp index d05fdba..7b96298 100644 --- a/Swiften/Serializer/PayloadSerializers/UnitTest/StreamInitiationSerializerTest.cpp +++ b/Swiften/Serializer/PayloadSerializers/UnitTest/StreamInitiationSerializerTest.cpp @@ -7,7 +7,7 @@ #include <cppunit/extensions/HelperMacros.h> #include <cppunit/extensions/TestFactoryRegistry.h> -#include "Swiften/Serializer/PayloadSerializers/StreamInitiationSerializer.h" +#include <Swiften/Serializer/PayloadSerializers/StreamInitiationSerializer.h> using namespace Swift; diff --git a/Swiften/Serializer/PayloadSerializers/UnitTest/VCardSerializerTest.cpp b/Swiften/Serializer/PayloadSerializers/UnitTest/VCardSerializerTest.cpp index 8a9a615..5122d22 100644 --- a/Swiften/Serializer/PayloadSerializers/UnitTest/VCardSerializerTest.cpp +++ b/Swiften/Serializer/PayloadSerializers/UnitTest/VCardSerializerTest.cpp @@ -7,7 +7,7 @@ #include <cppunit/extensions/HelperMacros.h> #include <cppunit/extensions/TestFactoryRegistry.h> -#include "Swiften/Serializer/PayloadSerializers/VCardSerializer.h" +#include <Swiften/Serializer/PayloadSerializers/VCardSerializer.h> using namespace Swift; diff --git a/Swiften/Serializer/PayloadSerializers/UnitTest/VCardUpdateSerializerTest.cpp b/Swiften/Serializer/PayloadSerializers/UnitTest/VCardUpdateSerializerTest.cpp index 6f37d61..613b465 100644 --- a/Swiften/Serializer/PayloadSerializers/UnitTest/VCardUpdateSerializerTest.cpp +++ b/Swiften/Serializer/PayloadSerializers/UnitTest/VCardUpdateSerializerTest.cpp @@ -7,7 +7,7 @@ #include <cppunit/extensions/HelperMacros.h> #include <cppunit/extensions/TestFactoryRegistry.h> -#include "Swiften/Serializer/PayloadSerializers/VCardUpdateSerializer.h" +#include <Swiften/Serializer/PayloadSerializers/VCardUpdateSerializer.h> using namespace Swift; diff --git a/Swiften/Serializer/PayloadSerializers/VCardSerializer.cpp b/Swiften/Serializer/PayloadSerializers/VCardSerializer.cpp index 79e543e..ab6aa1e 100644 --- a/Swiften/Serializer/PayloadSerializers/VCardSerializer.cpp +++ b/Swiften/Serializer/PayloadSerializers/VCardSerializer.cpp @@ -4,15 +4,15 @@ * See Documentation/Licenses/GPLv3.txt for more information. */ -#include "Swiften/Serializer/PayloadSerializers/VCardSerializer.h" +#include <Swiften/Serializer/PayloadSerializers/VCardSerializer.h> #include <boost/shared_ptr.hpp> -#include "Swiften/Serializer/XML/XMLElement.h" -#include "Swiften/Serializer/XML/XMLTextNode.h" -#include "Swiften/Serializer/XML/XMLRawTextNode.h" -#include "Swiften/StringCodecs/Base64.h" -#include "Swiften/Base/foreach.h" +#include <Swiften/Serializer/XML/XMLElement.h> +#include <Swiften/Serializer/XML/XMLTextNode.h> +#include <Swiften/Serializer/XML/XMLRawTextNode.h> +#include <Swiften/StringCodecs/Base64.h> +#include <Swiften/Base/foreach.h> namespace Swift { diff --git a/Swiften/Serializer/PayloadSerializers/VCardSerializer.h b/Swiften/Serializer/PayloadSerializers/VCardSerializer.h index 7b9a8a9..c73ff18 100644 --- a/Swiften/Serializer/PayloadSerializers/VCardSerializer.h +++ b/Swiften/Serializer/PayloadSerializers/VCardSerializer.h @@ -6,8 +6,8 @@ #pragma once -#include "Swiften/Serializer/GenericPayloadSerializer.h" -#include "Swiften/Elements/VCard.h" +#include <Swiften/Serializer/GenericPayloadSerializer.h> +#include <Swiften/Elements/VCard.h> namespace Swift { class VCardSerializer : public GenericPayloadSerializer<VCard> { diff --git a/Swiften/Serializer/PayloadSerializers/VCardUpdateSerializer.cpp b/Swiften/Serializer/PayloadSerializers/VCardUpdateSerializer.cpp index e315bc3..c06262f 100644 --- a/Swiften/Serializer/PayloadSerializers/VCardUpdateSerializer.cpp +++ b/Swiften/Serializer/PayloadSerializers/VCardUpdateSerializer.cpp @@ -4,12 +4,12 @@ * See Documentation/Licenses/GPLv3.txt for more information. */ -#include "Swiften/Serializer/PayloadSerializers/VCardUpdateSerializer.h" +#include <Swiften/Serializer/PayloadSerializers/VCardUpdateSerializer.h> #include <boost/shared_ptr.hpp> -#include "Swiften/Serializer/XML/XMLElement.h" -#include "Swiften/Serializer/XML/XMLTextNode.h" +#include <Swiften/Serializer/XML/XMLElement.h> +#include <Swiften/Serializer/XML/XMLTextNode.h> namespace Swift { diff --git a/Swiften/Serializer/PayloadSerializers/VCardUpdateSerializer.h b/Swiften/Serializer/PayloadSerializers/VCardUpdateSerializer.h index 46ca154..68084f0 100644 --- a/Swiften/Serializer/PayloadSerializers/VCardUpdateSerializer.h +++ b/Swiften/Serializer/PayloadSerializers/VCardUpdateSerializer.h @@ -6,8 +6,8 @@ #pragma once -#include "Swiften/Serializer/GenericPayloadSerializer.h" -#include "Swiften/Elements/VCardUpdate.h" +#include <Swiften/Serializer/GenericPayloadSerializer.h> +#include <Swiften/Elements/VCardUpdate.h> namespace Swift { class VCardUpdateSerializer : public GenericPayloadSerializer<VCardUpdate> { diff --git a/Swiften/Serializer/PresenceSerializer.cpp b/Swiften/Serializer/PresenceSerializer.cpp index 0de6493..ae1f88c 100644 --- a/Swiften/Serializer/PresenceSerializer.cpp +++ b/Swiften/Serializer/PresenceSerializer.cpp @@ -4,8 +4,8 @@ * See Documentation/Licenses/GPLv3.txt for more information. */ -#include "Swiften/Serializer/PresenceSerializer.h" -#include "Swiften/Serializer/XML/XMLElement.h" +#include <Swiften/Serializer/PresenceSerializer.h> +#include <Swiften/Serializer/XML/XMLElement.h> #include "boost/shared_ptr.hpp" diff --git a/Swiften/Serializer/PresenceSerializer.h b/Swiften/Serializer/PresenceSerializer.h index 3cb9aab..3c7ba70 100644 --- a/Swiften/Serializer/PresenceSerializer.h +++ b/Swiften/Serializer/PresenceSerializer.h @@ -7,10 +7,8 @@ #ifndef SWIFTEN_PresenceSerializer_H #define SWIFTEN_PresenceSerializer_H -#include <cassert> - -#include "Swiften/Serializer/GenericStanzaSerializer.h" -#include "Swiften/Elements/Presence.h" +#include <Swiften/Serializer/GenericStanzaSerializer.h> +#include <Swiften/Elements/Presence.h> namespace Swift { class PresenceSerializer : public GenericStanzaSerializer<Presence> { diff --git a/Swiften/Serializer/StanzaAckRequestSerializer.h b/Swiften/Serializer/StanzaAckRequestSerializer.h index b03a2c2..96598e9 100644 --- a/Swiften/Serializer/StanzaAckRequestSerializer.h +++ b/Swiften/Serializer/StanzaAckRequestSerializer.h @@ -8,9 +8,9 @@ #include <boost/shared_ptr.hpp> -#include "Swiften/Elements/StanzaAckRequest.h" -#include "Swiften/Serializer/GenericElementSerializer.h" -#include "Swiften/Serializer/XML/XMLElement.h" +#include <Swiften/Elements/StanzaAckRequest.h> +#include <Swiften/Serializer/GenericElementSerializer.h> +#include <Swiften/Serializer/XML/XMLElement.h> namespace Swift { class StanzaAckRequestSerializer : public GenericElementSerializer<StanzaAckRequest> { diff --git a/Swiften/Serializer/StanzaAckSerializer.h b/Swiften/Serializer/StanzaAckSerializer.h index 984509f..b417789 100644 --- a/Swiften/Serializer/StanzaAckSerializer.h +++ b/Swiften/Serializer/StanzaAckSerializer.h @@ -9,9 +9,9 @@ #include <boost/shared_ptr.hpp> #include <boost/lexical_cast.hpp> -#include "Swiften/Elements/StanzaAck.h" -#include "Swiften/Serializer/GenericElementSerializer.h" -#include "Swiften/Serializer/XML/XMLElement.h" +#include <Swiften/Elements/StanzaAck.h> +#include <Swiften/Serializer/GenericElementSerializer.h> +#include <Swiften/Serializer/XML/XMLElement.h> namespace Swift { class StanzaAckSerializer : public GenericElementSerializer<StanzaAck> { diff --git a/Swiften/Serializer/StanzaSerializer.cpp b/Swiften/Serializer/StanzaSerializer.cpp index cfc9a43..ab87416 100644 --- a/Swiften/Serializer/StanzaSerializer.cpp +++ b/Swiften/Serializer/StanzaSerializer.cpp @@ -4,17 +4,18 @@ * See Documentation/Licenses/GPLv3.txt for more information. */ -#include "Swiften/Serializer/StanzaSerializer.h" +#include <Swiften/Serializer/StanzaSerializer.h> #include <sstream> #include <typeinfo> #include <iostream> -#include "Swiften/Serializer/XML/XMLElement.h" -#include "Swiften/Serializer/XML/XMLRawTextNode.h" -#include "Swiften/Serializer/PayloadSerializer.h" -#include "Swiften/Serializer/PayloadSerializerCollection.h" -#include "Swiften/Elements/Stanza.h" +#include <Swiften/Base/foreach.h> +#include <Swiften/Serializer/XML/XMLElement.h> +#include <Swiften/Serializer/XML/XMLRawTextNode.h> +#include <Swiften/Serializer/PayloadSerializer.h> +#include <Swiften/Serializer/PayloadSerializerCollection.h> +#include <Swiften/Elements/Stanza.h> namespace Swift { diff --git a/Swiften/Serializer/StanzaSerializer.h b/Swiften/Serializer/StanzaSerializer.h index 505d320..3f57939 100644 --- a/Swiften/Serializer/StanzaSerializer.h +++ b/Swiften/Serializer/StanzaSerializer.h @@ -7,8 +7,8 @@ #ifndef SWIFTEN_STANZASERIALIZER_H #define SWIFTEN_STANZASERIALIZER_H -#include "Swiften/Elements/Stanza.h" -#include "Swiften/Serializer/ElementSerializer.h" +#include <Swiften/Elements/Stanza.h> +#include <Swiften/Serializer/ElementSerializer.h> #include <string> namespace Swift { diff --git a/Swiften/Serializer/StartTLSFailureSerializer.h b/Swiften/Serializer/StartTLSFailureSerializer.h index 548a24c..5d7870f 100644 --- a/Swiften/Serializer/StartTLSFailureSerializer.h +++ b/Swiften/Serializer/StartTLSFailureSerializer.h @@ -9,9 +9,9 @@ #include <boost/shared_ptr.hpp> -#include "Swiften/Elements/StartTLSFailure.h" -#include "Swiften/Serializer/GenericElementSerializer.h" -#include "Swiften/Serializer/XML/XMLElement.h" +#include <Swiften/Elements/StartTLSFailure.h> +#include <Swiften/Serializer/GenericElementSerializer.h> +#include <Swiften/Serializer/XML/XMLElement.h> namespace Swift { class StartTLSFailureSerializer : public GenericElementSerializer<StartTLSFailure> { diff --git a/Swiften/Serializer/StartTLSRequestSerializer.h b/Swiften/Serializer/StartTLSRequestSerializer.h index 2e9ecfa..972dff6 100644 --- a/Swiften/Serializer/StartTLSRequestSerializer.h +++ b/Swiften/Serializer/StartTLSRequestSerializer.h @@ -9,9 +9,9 @@ #include <boost/shared_ptr.hpp> -#include "Swiften/Elements/StartTLSRequest.h" -#include "Swiften/Serializer/GenericElementSerializer.h" -#include "Swiften/Serializer/XML/XMLElement.h" +#include <Swiften/Elements/StartTLSRequest.h> +#include <Swiften/Serializer/GenericElementSerializer.h> +#include <Swiften/Serializer/XML/XMLElement.h> namespace Swift { class StartTLSRequestSerializer : public GenericElementSerializer<StartTLSRequest> { diff --git a/Swiften/Serializer/StreamFeaturesSerializer.cpp b/Swiften/Serializer/StreamFeaturesSerializer.cpp index 915433c..c42d262 100644 --- a/Swiften/Serializer/StreamFeaturesSerializer.cpp +++ b/Swiften/Serializer/StreamFeaturesSerializer.cpp @@ -4,11 +4,13 @@ * See Documentation/Licenses/GPLv3.txt for more information. */ -#include "Swiften/Serializer/StreamFeaturesSerializer.h" +#include <Swiften/Serializer/StreamFeaturesSerializer.h> -#include "Swiften/Serializer/XML/XMLElement.h" -#include "Swiften/Serializer/XML/XMLTextNode.h" -#include "Swiften/Base/foreach.h" +#include <boost/smart_ptr/make_shared.hpp> + +#include <Swiften/Serializer/XML/XMLElement.h> +#include <Swiften/Serializer/XML/XMLTextNode.h> +#include <Swiften/Base/foreach.h> namespace Swift { @@ -49,6 +51,9 @@ std::string StreamFeaturesSerializer::serialize(boost::shared_ptr<Element> eleme if (streamFeatures->hasStreamManagement()) { streamFeaturesElement.addNode(boost::shared_ptr<XMLElement>(new XMLElement("sm", "urn:xmpp:sm:2"))); } + if (streamFeatures->hasRosterVersioning()) { + streamFeaturesElement.addNode(boost::make_shared<XMLElement>("ver", "urn:xmpp:features:rosterver")); + } return streamFeaturesElement.serialize(); } diff --git a/Swiften/Serializer/StreamFeaturesSerializer.h b/Swiften/Serializer/StreamFeaturesSerializer.h index 3b475e0..e2015d2 100644 --- a/Swiften/Serializer/StreamFeaturesSerializer.h +++ b/Swiften/Serializer/StreamFeaturesSerializer.h @@ -9,8 +9,8 @@ #include <boost/shared_ptr.hpp> -#include "Swiften/Elements/StreamFeatures.h" -#include "Swiften/Serializer/GenericElementSerializer.h" +#include <Swiften/Elements/StreamFeatures.h> +#include <Swiften/Serializer/GenericElementSerializer.h> namespace Swift { class StreamFeaturesSerializer : public GenericElementSerializer<StreamFeatures> { diff --git a/Swiften/Serializer/StreamManagementEnabledSerializer.cpp b/Swiften/Serializer/StreamManagementEnabledSerializer.cpp new file mode 100644 index 0000000..02cf948 --- /dev/null +++ b/Swiften/Serializer/StreamManagementEnabledSerializer.cpp @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2010 Remko Tronçon + * Licensed under the GNU General Public License v3. + * See Documentation/Licenses/GPLv3.txt for more information. + */ + +#include <Swiften/Serializer/StreamManagementEnabledSerializer.h> + +#include <boost/shared_ptr.hpp> + +#include <Swiften/Elements/StreamManagementEnabled.h> +#include <Swiften/Serializer/XML/XMLElement.h> + +using namespace Swift; + +StreamManagementEnabledSerializer::StreamManagementEnabledSerializer() : GenericElementSerializer<StreamManagementEnabled>() { +} + +std::string StreamManagementEnabledSerializer::serialize(boost::shared_ptr<Element> el) const { + boost::shared_ptr<StreamManagementEnabled> e(boost::dynamic_pointer_cast<StreamManagementEnabled>(el)); + XMLElement element("enabled", "urn:xmpp:sm:2"); + if (!e->getResumeID().empty()) { + element.setAttribute("id", e->getResumeID()); + } + if (e->getResumeSupported()) { + element.setAttribute("resume", "true"); + } + return element.serialize(); +} diff --git a/Swiften/Serializer/StreamManagementEnabledSerializer.h b/Swiften/Serializer/StreamManagementEnabledSerializer.h index fc7bd86..6a27457 100644 --- a/Swiften/Serializer/StreamManagementEnabledSerializer.h +++ b/Swiften/Serializer/StreamManagementEnabledSerializer.h @@ -8,18 +8,14 @@ #include <boost/shared_ptr.hpp> -#include "Swiften/Elements/StreamManagementEnabled.h" -#include "Swiften/Serializer/GenericElementSerializer.h" -#include "Swiften/Serializer/XML/XMLElement.h" +#include <Swiften/Elements/StreamManagementEnabled.h> +#include <Swiften/Serializer/GenericElementSerializer.h> namespace Swift { class StreamManagementEnabledSerializer : public GenericElementSerializer<StreamManagementEnabled> { public: - StreamManagementEnabledSerializer() : GenericElementSerializer<StreamManagementEnabled>() { - } + StreamManagementEnabledSerializer(); - virtual std::string serialize(boost::shared_ptr<Element>) const { - return XMLElement("enabled", "urn:xmpp:sm:2").serialize(); - } + virtual std::string serialize(boost::shared_ptr<Element>) const; }; } diff --git a/Swiften/Serializer/StreamManagementFailedSerializer.h b/Swiften/Serializer/StreamManagementFailedSerializer.h index b22ed0d..731cf4b 100644 --- a/Swiften/Serializer/StreamManagementFailedSerializer.h +++ b/Swiften/Serializer/StreamManagementFailedSerializer.h @@ -8,9 +8,9 @@ #include <boost/shared_ptr.hpp> -#include "Swiften/Elements/StreamManagementFailed.h" -#include "Swiften/Serializer/GenericElementSerializer.h" -#include "Swiften/Serializer/XML/XMLElement.h" +#include <Swiften/Elements/StreamManagementFailed.h> +#include <Swiften/Serializer/GenericElementSerializer.h> +#include <Swiften/Serializer/XML/XMLElement.h> namespace Swift { class StreamManagementFailedSerializer : public GenericElementSerializer<StreamManagementFailed> { diff --git a/Swiften/Serializer/StreamResumeSerializer.cpp b/Swiften/Serializer/StreamResumeSerializer.cpp new file mode 100644 index 0000000..a7a2e3b --- /dev/null +++ b/Swiften/Serializer/StreamResumeSerializer.cpp @@ -0,0 +1,28 @@ +/* + * Copyright (c) 2011 Remko Tronçon + * Licensed under the GNU General Public License v3. + * See Documentation/Licenses/GPLv3.txt for more information. + */ + +#include <Swiften/Serializer/StreamResumeSerializer.h> + +#include <boost/shared_ptr.hpp> +#include <boost/lexical_cast.hpp> + +#include <Swiften/Elements/StreamResume.h> +#include <Swiften/Serializer/XML/XMLElement.h> + +using namespace Swift; + +StreamResumeSerializer::StreamResumeSerializer() : GenericElementSerializer<StreamResume>() { +} + +std::string StreamResumeSerializer::serialize(boost::shared_ptr<Element> el) const { + boost::shared_ptr<StreamResume> e(boost::dynamic_pointer_cast<StreamResume>(el)); + XMLElement element("resume", "urn:xmpp:sm:2"); + element.setAttribute("previd", e->getResumeID()); + if (e->getHandledStanzasCount()) { + element.setAttribute("h", boost::lexical_cast<std::string>(e->getHandledStanzasCount())); + } + return element.serialize(); +} diff --git a/Swiften/Serializer/StreamResumeSerializer.h b/Swiften/Serializer/StreamResumeSerializer.h new file mode 100644 index 0000000..6ea7365 --- /dev/null +++ b/Swiften/Serializer/StreamResumeSerializer.h @@ -0,0 +1,21 @@ +/* + * Copyright (c) 2011 Remko Tronçon + * Licensed under the GNU General Public License v3. + * See Documentation/Licenses/GPLv3.txt for more information. + */ + +#pragma once + +#include <boost/shared_ptr.hpp> + +#include <Swiften/Elements/StreamResume.h> +#include <Swiften/Serializer/GenericElementSerializer.h> + +namespace Swift { + class StreamResumeSerializer : public GenericElementSerializer<StreamResume> { + public: + StreamResumeSerializer(); + + virtual std::string serialize(boost::shared_ptr<Element>) const; + }; +} diff --git a/Swiften/Serializer/StreamResumedSerializer.cpp b/Swiften/Serializer/StreamResumedSerializer.cpp new file mode 100644 index 0000000..d3beafb --- /dev/null +++ b/Swiften/Serializer/StreamResumedSerializer.cpp @@ -0,0 +1,28 @@ +/* + * Copyright (c) 2011 Remko Tronçon + * Licensed under the GNU General Public License v3. + * See Documentation/Licenses/GPLv3.txt for more information. + */ + +#include <Swiften/Serializer/StreamResumedSerializer.h> + +#include <boost/shared_ptr.hpp> +#include <boost/lexical_cast.hpp> + +#include <Swiften/Elements/StreamResumed.h> +#include <Swiften/Serializer/XML/XMLElement.h> + +using namespace Swift; + +StreamResumedSerializer::StreamResumedSerializer() : GenericElementSerializer<StreamResumed>() { +} + +std::string StreamResumedSerializer::serialize(boost::shared_ptr<Element> el) const { + boost::shared_ptr<StreamResumed> e(boost::dynamic_pointer_cast<StreamResumed>(el)); + XMLElement element("resumed", "urn:xmpp:sm:2"); + element.setAttribute("previd", e->getResumeID()); + if (e->getHandledStanzasCount()) { + element.setAttribute("h", boost::lexical_cast<std::string>(e->getHandledStanzasCount())); + } + return element.serialize(); +} diff --git a/Swiften/Serializer/StreamResumedSerializer.h b/Swiften/Serializer/StreamResumedSerializer.h new file mode 100644 index 0000000..38d846f --- /dev/null +++ b/Swiften/Serializer/StreamResumedSerializer.h @@ -0,0 +1,21 @@ +/* + * Copyright (c) 2011 Remko Tronçon + * Licensed under the GNU General Public License v3. + * See Documentation/Licenses/GPLv3.txt for more information. + */ + +#pragma once + +#include <boost/shared_ptr.hpp> + +#include <Swiften/Elements/StreamResumed.h> +#include <Swiften/Serializer/GenericElementSerializer.h> + +namespace Swift { + class StreamResumedSerializer : public GenericElementSerializer<StreamResumed> { + public: + StreamResumedSerializer(); + + virtual std::string serialize(boost::shared_ptr<Element>) const; + }; +} diff --git a/Swiften/Serializer/TLSProceedSerializer.h b/Swiften/Serializer/TLSProceedSerializer.h index 1b08c23..2fef058 100644 --- a/Swiften/Serializer/TLSProceedSerializer.h +++ b/Swiften/Serializer/TLSProceedSerializer.h @@ -9,9 +9,9 @@ #include <boost/shared_ptr.hpp> -#include "Swiften/Elements/TLSProceed.h" -#include "Swiften/Serializer/GenericElementSerializer.h" -#include "Swiften/Serializer/XML/XMLElement.h" +#include <Swiften/Elements/TLSProceed.h> +#include <Swiften/Serializer/GenericElementSerializer.h> +#include <Swiften/Serializer/XML/XMLElement.h> namespace Swift { class TLSProceedSerializer : public GenericElementSerializer<TLSProceed> { diff --git a/Swiften/Serializer/UnitTest/AuthChallengeSerializerTest.cpp b/Swiften/Serializer/UnitTest/AuthChallengeSerializerTest.cpp index af857ef..f044607 100644 --- a/Swiften/Serializer/UnitTest/AuthChallengeSerializerTest.cpp +++ b/Swiften/Serializer/UnitTest/AuthChallengeSerializerTest.cpp @@ -7,8 +7,8 @@ #include <cppunit/extensions/HelperMacros.h> #include <cppunit/extensions/TestFactoryRegistry.h> -#include "Swiften/Serializer/AuthChallengeSerializer.h" -#include "Swiften/Elements/AuthChallenge.h" +#include <Swiften/Serializer/AuthChallengeSerializer.h> +#include <Swiften/Elements/AuthChallenge.h> using namespace Swift; diff --git a/Swiften/Serializer/UnitTest/AuthRequestSerializerTest.cpp b/Swiften/Serializer/UnitTest/AuthRequestSerializerTest.cpp index 9f9f2fa..eff2c8e 100644 --- a/Swiften/Serializer/UnitTest/AuthRequestSerializerTest.cpp +++ b/Swiften/Serializer/UnitTest/AuthRequestSerializerTest.cpp @@ -7,8 +7,8 @@ #include <cppunit/extensions/HelperMacros.h> #include <cppunit/extensions/TestFactoryRegistry.h> -#include "Swiften/Serializer/AuthRequestSerializer.h" -#include "Swiften/Elements/AuthRequest.h" +#include <Swiften/Serializer/AuthRequestSerializer.h> +#include <Swiften/Elements/AuthRequest.h> using namespace Swift; diff --git a/Swiften/Serializer/UnitTest/AuthResponseSerializerTest.cpp b/Swiften/Serializer/UnitTest/AuthResponseSerializerTest.cpp index c93810c..f14d184 100644 --- a/Swiften/Serializer/UnitTest/AuthResponseSerializerTest.cpp +++ b/Swiften/Serializer/UnitTest/AuthResponseSerializerTest.cpp @@ -7,8 +7,8 @@ #include <cppunit/extensions/HelperMacros.h> #include <cppunit/extensions/TestFactoryRegistry.h> -#include "Swiften/Serializer/AuthResponseSerializer.h" -#include "Swiften/Elements/AuthResponse.h" +#include <Swiften/Serializer/AuthResponseSerializer.h> +#include <Swiften/Elements/AuthResponse.h> using namespace Swift; diff --git a/Swiften/Serializer/UnitTest/AuthSuccessSerializerTest.cpp b/Swiften/Serializer/UnitTest/AuthSuccessSerializerTest.cpp index 385c1e5..0f6987c 100644 --- a/Swiften/Serializer/UnitTest/AuthSuccessSerializerTest.cpp +++ b/Swiften/Serializer/UnitTest/AuthSuccessSerializerTest.cpp @@ -7,8 +7,8 @@ #include <cppunit/extensions/HelperMacros.h> #include <cppunit/extensions/TestFactoryRegistry.h> -#include "Swiften/Serializer/AuthSuccessSerializer.h" -#include "Swiften/Elements/AuthSuccess.h" +#include <Swiften/Serializer/AuthSuccessSerializer.h> +#include <Swiften/Elements/AuthSuccess.h> using namespace Swift; diff --git a/Swiften/Serializer/UnitTest/StreamFeaturesSerializerTest.cpp b/Swiften/Serializer/UnitTest/StreamFeaturesSerializerTest.cpp index 65caa81..5b9412b 100644 --- a/Swiften/Serializer/UnitTest/StreamFeaturesSerializerTest.cpp +++ b/Swiften/Serializer/UnitTest/StreamFeaturesSerializerTest.cpp @@ -7,8 +7,8 @@ #include <cppunit/extensions/HelperMacros.h> #include <cppunit/extensions/TestFactoryRegistry.h> -#include "Swiften/Serializer/StreamFeaturesSerializer.h" -#include "Swiften/Elements/StreamFeatures.h" +#include <Swiften/Serializer/StreamFeaturesSerializer.h> +#include <Swiften/Elements/StreamFeatures.h> using namespace Swift; @@ -32,6 +32,7 @@ class StreamFeaturesSerializerTest : public CppUnit::TestFixture streamFeatures->setHasResourceBind(); streamFeatures->setHasSession(); streamFeatures->setHasStreamManagement(); + streamFeatures->setHasRosterVersioning(); CPPUNIT_ASSERT_EQUAL(std::string( "<stream:features>" @@ -47,6 +48,7 @@ class StreamFeaturesSerializerTest : public CppUnit::TestFixture "<bind xmlns=\"urn:ietf:params:xml:ns:xmpp-bind\"/>" "<session xmlns=\"urn:ietf:params:xml:ns:xmpp-session\"/>" "<sm xmlns=\"urn:xmpp:sm:2\"/>" + "<ver xmlns=\"urn:xmpp:features:rosterver\"/>" "</stream:features>"), testling.serialize(streamFeatures)); } }; diff --git a/Swiften/Serializer/UnitTest/XMPPSerializerTest.cpp b/Swiften/Serializer/UnitTest/XMPPSerializerTest.cpp index 76c1b23..2956875 100644 --- a/Swiften/Serializer/UnitTest/XMPPSerializerTest.cpp +++ b/Swiften/Serializer/UnitTest/XMPPSerializerTest.cpp @@ -7,10 +7,10 @@ #include <cppunit/extensions/HelperMacros.h> #include <cppunit/extensions/TestFactoryRegistry.h> -#include "Swiften/Serializer/XMPPSerializer.h" -#include "Swiften/Elements/AuthChallenge.h" -#include "Swiften/Serializer/PayloadSerializerCollection.h" -#include "Swiften/Elements/ProtocolHeader.h" +#include <Swiften/Serializer/XMPPSerializer.h> +#include <Swiften/Elements/AuthChallenge.h> +#include <Swiften/Serializer/PayloadSerializerCollection.h> +#include <Swiften/Elements/ProtocolHeader.h> using namespace Swift; diff --git a/Swiften/Serializer/XML/UnitTest/XMLElementTest.cpp b/Swiften/Serializer/XML/UnitTest/XMLElementTest.cpp index 8c68f97..897a4f4 100644 --- a/Swiften/Serializer/XML/UnitTest/XMLElementTest.cpp +++ b/Swiften/Serializer/XML/UnitTest/XMLElementTest.cpp @@ -7,8 +7,8 @@ #include <cppunit/extensions/HelperMacros.h> #include <cppunit/extensions/TestFactoryRegistry.h> -#include "Swiften/Serializer/XML/XMLElement.h" -#include "Swiften/Serializer/XML/XMLTextNode.h" +#include <Swiften/Serializer/XML/XMLElement.h> +#include <Swiften/Serializer/XML/XMLTextNode.h> using namespace Swift; diff --git a/Swiften/Serializer/XML/XMLElement.cpp b/Swiften/Serializer/XML/XMLElement.cpp index 6c90e0d..be90406 100644 --- a/Swiften/Serializer/XML/XMLElement.cpp +++ b/Swiften/Serializer/XML/XMLElement.cpp @@ -4,10 +4,10 @@ * See Documentation/Licenses/GPLv3.txt for more information. */ -#include "Swiften/Serializer/XML/XMLElement.h" +#include <Swiften/Serializer/XML/XMLElement.h> -#include "Swiften/Base/foreach.h" -#include "Swiften/Serializer/XML/XMLTextNode.h" +#include <Swiften/Base/foreach.h> +#include <Swiften/Serializer/XML/XMLTextNode.h> namespace Swift { diff --git a/Swiften/Serializer/XML/XMLElement.h b/Swiften/Serializer/XML/XMLElement.h index 65af7ae..6eacb82 100644 --- a/Swiften/Serializer/XML/XMLElement.h +++ b/Swiften/Serializer/XML/XMLElement.h @@ -12,7 +12,7 @@ #include <string> -#include "Swiften/Serializer/XML/XMLNode.h" +#include <Swiften/Serializer/XML/XMLNode.h> namespace Swift { class XMLElement : public XMLNode { diff --git a/Swiften/Serializer/XML/XMLNode.cpp b/Swiften/Serializer/XML/XMLNode.cpp index cd604f5..7eedeff 100644 --- a/Swiften/Serializer/XML/XMLNode.cpp +++ b/Swiften/Serializer/XML/XMLNode.cpp @@ -4,7 +4,7 @@ * See Documentation/Licenses/GPLv3.txt for more information. */ -#include "Swiften/Serializer/XML/XMLNode.h" +#include <Swiften/Serializer/XML/XMLNode.h> namespace Swift { diff --git a/Swiften/Serializer/XML/XMLRawTextNode.h b/Swiften/Serializer/XML/XMLRawTextNode.h index 9fa8c40..d777cdb 100644 --- a/Swiften/Serializer/XML/XMLRawTextNode.h +++ b/Swiften/Serializer/XML/XMLRawTextNode.h @@ -7,7 +7,7 @@ #ifndef SWIFTEN_XMLRawTextNode_H #define SWIFTEN_XMLRawTextNode_H -#include "Swiften/Serializer/XML/XMLNode.h" +#include <Swiften/Serializer/XML/XMLNode.h> namespace Swift { class XMLRawTextNode : public XMLNode { diff --git a/Swiften/Serializer/XML/XMLTextNode.h b/Swiften/Serializer/XML/XMLTextNode.h index 4d55f76..648854f 100644 --- a/Swiften/Serializer/XML/XMLTextNode.h +++ b/Swiften/Serializer/XML/XMLTextNode.h @@ -6,7 +6,7 @@ #pragma once -#include "Swiften/Serializer/XML/XMLNode.h" +#include <Swiften/Serializer/XML/XMLNode.h> #include <Swiften/Base/String.h> namespace Swift { diff --git a/Swiften/Serializer/XMPPSerializer.cpp b/Swiften/Serializer/XMPPSerializer.cpp index 06f3558..19a30ce 100644 --- a/Swiften/Serializer/XMPPSerializer.cpp +++ b/Swiften/Serializer/XMPPSerializer.cpp @@ -4,36 +4,38 @@ * See Documentation/Licenses/GPLv3.txt for more information. */ -#include "Swiften/Serializer/XMPPSerializer.h" +#include <Swiften/Serializer/XMPPSerializer.h> #include <boost/bind.hpp> #include <boost/smart_ptr/make_shared.hpp> #include <iostream> #include <cassert> -#include "Swiften/Elements/ProtocolHeader.h" -#include "Swiften/Base/foreach.h" -#include "Swiften/Serializer/CompressRequestSerializer.h" -#include "Swiften/Serializer/CompressFailureSerializer.h" -#include "Swiften/Serializer/StreamErrorSerializer.h" -#include "Swiften/Serializer/StreamFeaturesSerializer.h" -#include "Swiften/Serializer/AuthRequestSerializer.h" -#include "Swiften/Serializer/AuthFailureSerializer.h" -#include "Swiften/Serializer/AuthSuccessSerializer.h" -#include "Swiften/Serializer/AuthChallengeSerializer.h" -#include "Swiften/Serializer/AuthResponseSerializer.h" -#include "Swiften/Serializer/EnableStreamManagementSerializer.h" -#include "Swiften/Serializer/StreamManagementEnabledSerializer.h" -#include "Swiften/Serializer/StreamManagementFailedSerializer.h" -#include "Swiften/Serializer/StanzaAckSerializer.h" -#include "Swiften/Serializer/StanzaAckRequestSerializer.h" -#include "Swiften/Serializer/StartTLSRequestSerializer.h" -#include "Swiften/Serializer/StartTLSFailureSerializer.h" -#include "Swiften/Serializer/TLSProceedSerializer.h" -#include "Swiften/Serializer/MessageSerializer.h" -#include "Swiften/Serializer/PresenceSerializer.h" -#include "Swiften/Serializer/IQSerializer.h" -#include "Swiften/Serializer/ComponentHandshakeSerializer.h" +#include <Swiften/Elements/ProtocolHeader.h> +#include <Swiften/Base/foreach.h> +#include <Swiften/Serializer/CompressRequestSerializer.h> +#include <Swiften/Serializer/CompressFailureSerializer.h> +#include <Swiften/Serializer/StreamErrorSerializer.h> +#include <Swiften/Serializer/StreamFeaturesSerializer.h> +#include <Swiften/Serializer/AuthRequestSerializer.h> +#include <Swiften/Serializer/AuthFailureSerializer.h> +#include <Swiften/Serializer/AuthSuccessSerializer.h> +#include <Swiften/Serializer/AuthChallengeSerializer.h> +#include <Swiften/Serializer/AuthResponseSerializer.h> +#include <Swiften/Serializer/EnableStreamManagementSerializer.h> +#include <Swiften/Serializer/StreamManagementEnabledSerializer.h> +#include <Swiften/Serializer/StreamResumeSerializer.h> +#include <Swiften/Serializer/StreamResumedSerializer.h> +#include <Swiften/Serializer/StreamManagementFailedSerializer.h> +#include <Swiften/Serializer/StanzaAckSerializer.h> +#include <Swiften/Serializer/StanzaAckRequestSerializer.h> +#include <Swiften/Serializer/StartTLSRequestSerializer.h> +#include <Swiften/Serializer/StartTLSFailureSerializer.h> +#include <Swiften/Serializer/TLSProceedSerializer.h> +#include <Swiften/Serializer/MessageSerializer.h> +#include <Swiften/Serializer/PresenceSerializer.h> +#include <Swiften/Serializer/IQSerializer.h> +#include <Swiften/Serializer/ComponentHandshakeSerializer.h> namespace Swift { @@ -56,6 +58,8 @@ XMPPSerializer::XMPPSerializer(PayloadSerializerCollection* payloadSerializers, serializers_.push_back(boost::make_shared<EnableStreamManagementSerializer>()); serializers_.push_back(boost::make_shared<StreamManagementEnabledSerializer>()); serializers_.push_back(boost::make_shared<StreamManagementFailedSerializer>()); + serializers_.push_back(boost::make_shared<StreamResumeSerializer>()); + serializers_.push_back(boost::make_shared<StreamResumedSerializer>()); serializers_.push_back(boost::make_shared<StanzaAckSerializer>()); serializers_.push_back(boost::make_shared<StanzaAckRequestSerializer>()); serializers_.push_back(boost::make_shared<ComponentHandshakeSerializer>()); diff --git a/Swiften/Serializer/XMPPSerializer.h b/Swiften/Serializer/XMPPSerializer.h index 4f83857..003d33b 100644 --- a/Swiften/Serializer/XMPPSerializer.h +++ b/Swiften/Serializer/XMPPSerializer.h @@ -9,10 +9,10 @@ #include <boost/shared_ptr.hpp> #include <vector> -#include "Swiften/Elements/Element.h" -#include "Swiften/Elements/StreamType.h" +#include <Swiften/Elements/Element.h> +#include <Swiften/Elements/StreamType.h> #include <string> -#include "Swiften/Serializer/ElementSerializer.h" +#include <Swiften/Serializer/ElementSerializer.h> namespace Swift { class PayloadSerializerCollection; diff --git a/Swiften/Server/ServerFromClientSession.cpp b/Swiften/Server/ServerFromClientSession.cpp index 18da7e8..3c9321b 100644 --- a/Swiften/Server/ServerFromClientSession.cpp +++ b/Swiften/Server/ServerFromClientSession.cpp @@ -4,22 +4,22 @@ * See Documentation/Licenses/GPLv3.txt for more information. */ -#include "Swiften/Server/ServerFromClientSession.h" +#include <Swiften/Server/ServerFromClientSession.h> #include <boost/bind.hpp> -#include "Swiften/Elements/ProtocolHeader.h" -#include "Swiften/Server/UserRegistry.h" -#include "Swiften/Network/Connection.h" -#include "Swiften/StreamStack/XMPPLayer.h" -#include "Swiften/Elements/StreamFeatures.h" -#include "Swiften/Elements/ResourceBind.h" -#include "Swiften/Elements/StartSession.h" -#include "Swiften/Elements/IQ.h" -#include "Swiften/Elements/AuthSuccess.h" -#include "Swiften/Elements/AuthFailure.h" -#include "Swiften/Elements/AuthRequest.h" -#include "Swiften/SASL/PLAINMessage.h" +#include <Swiften/Elements/ProtocolHeader.h> +#include <Swiften/Server/UserRegistry.h> +#include <Swiften/Network/Connection.h> +#include <Swiften/StreamStack/XMPPLayer.h> +#include <Swiften/Elements/StreamFeatures.h> +#include <Swiften/Elements/ResourceBind.h> +#include <Swiften/Elements/StartSession.h> +#include <Swiften/Elements/IQ.h> +#include <Swiften/Elements/AuthSuccess.h> +#include <Swiften/Elements/AuthFailure.h> +#include <Swiften/Elements/AuthRequest.h> +#include <Swiften/SASL/PLAINMessage.h> namespace Swift { diff --git a/Swiften/Server/ServerFromClientSession.h b/Swiften/Server/ServerFromClientSession.h index 80ef063..b35a3c2 100644 --- a/Swiften/Server/ServerFromClientSession.h +++ b/Swiften/Server/ServerFromClientSession.h @@ -7,13 +7,13 @@ #pragma once #include <boost/shared_ptr.hpp> -#include "Swiften/Base/boost_bsignals.h" +#include <Swiften/Base/boost_bsignals.h> #include <boost/enable_shared_from_this.hpp> #include <string> -#include "Swiften/Session/Session.h" -#include "Swiften/JID/JID.h" -#include "Swiften/Network/Connection.h" +#include <Swiften/Session/Session.h> +#include <Swiften/JID/JID.h> +#include <Swiften/Network/Connection.h> namespace Swift { class ProtocolHeader; diff --git a/Swiften/Server/ServerSession.cpp b/Swiften/Server/ServerSession.cpp index 10d642d..eb031f2 100644 --- a/Swiften/Server/ServerSession.cpp +++ b/Swiften/Server/ServerSession.cpp @@ -4,7 +4,7 @@ * See Documentation/Licenses/GPLv3.txt for more information. */ -#include "Swiften/Server/ServerSession.h" +#include <Swiften/Server/ServerSession.h> namespace Swift { diff --git a/Swiften/Server/ServerSession.h b/Swiften/Server/ServerSession.h index bd4ab6d..486ebaa 100644 --- a/Swiften/Server/ServerSession.h +++ b/Swiften/Server/ServerSession.h @@ -8,7 +8,7 @@ #include <boost/shared_ptr.hpp> -#include "Swiften/Elements/Stanza.h" +#include <Swiften/Elements/Stanza.h> namespace Swift { class ServerSession { diff --git a/Swiften/Server/ServerStanzaRouter.cpp b/Swiften/Server/ServerStanzaRouter.cpp index b4d230a..7cd8ed3 100644 --- a/Swiften/Server/ServerStanzaRouter.cpp +++ b/Swiften/Server/ServerStanzaRouter.cpp @@ -4,8 +4,8 @@ * See Documentation/Licenses/GPLv3.txt for more information. */ -#include "Swiften/Server/ServerStanzaRouter.h" -#include "Swiften/Server/ServerSession.h" +#include <Swiften/Server/ServerStanzaRouter.h> +#include <Swiften/Server/ServerSession.h> #include <cassert> #include <algorithm> diff --git a/Swiften/Server/ServerStanzaRouter.h b/Swiften/Server/ServerStanzaRouter.h index 2a1960c..4a9493b 100644 --- a/Swiften/Server/ServerStanzaRouter.h +++ b/Swiften/Server/ServerStanzaRouter.h @@ -9,8 +9,8 @@ #include <boost/shared_ptr.hpp> #include <map> -#include "Swiften/JID/JID.h" -#include "Swiften/Elements/Stanza.h" +#include <Swiften/JID/JID.h> +#include <Swiften/Elements/Stanza.h> namespace Swift { class ServerSession; diff --git a/Swiften/Server/SimpleUserRegistry.cpp b/Swiften/Server/SimpleUserRegistry.cpp index 2de28fe..9930a39 100644 --- a/Swiften/Server/SimpleUserRegistry.cpp +++ b/Swiften/Server/SimpleUserRegistry.cpp @@ -4,7 +4,7 @@ * See Documentation/Licenses/GPLv3.txt for more information. */ -#include "Swiften/Server/SimpleUserRegistry.h" +#include <Swiften/Server/SimpleUserRegistry.h> namespace Swift { diff --git a/Swiften/Server/SimpleUserRegistry.h b/Swiften/Server/SimpleUserRegistry.h index 5de9f64..ad1791b 100644 --- a/Swiften/Server/SimpleUserRegistry.h +++ b/Swiften/Server/SimpleUserRegistry.h @@ -8,9 +8,9 @@ #include <map> -#include "Swiften/JID/JID.h" +#include <Swiften/JID/JID.h> #include <string> -#include "Swiften/Server/UserRegistry.h" +#include <Swiften/Server/UserRegistry.h> namespace Swift { diff --git a/Swiften/Server/UnitTest/ServerStanzaRouterTest.cpp b/Swiften/Server/UnitTest/ServerStanzaRouterTest.cpp index 0a5c7c1..0941665 100644 --- a/Swiften/Server/UnitTest/ServerStanzaRouterTest.cpp +++ b/Swiften/Server/UnitTest/ServerStanzaRouterTest.cpp @@ -7,9 +7,9 @@ #include <cppunit/extensions/HelperMacros.h> #include <cppunit/extensions/TestFactoryRegistry.h> -#include "Swiften/Elements/Message.h" -#include "Swiften/Server/ServerStanzaRouter.h" -#include "Swiften/Server/ServerSession.h" +#include <Swiften/Elements/Message.h> +#include <Swiften/Server/ServerStanzaRouter.h> +#include <Swiften/Server/ServerSession.h> using namespace Swift; diff --git a/Swiften/Server/UserRegistry.cpp b/Swiften/Server/UserRegistry.cpp index 0795f16..60bbb33 100644 --- a/Swiften/Server/UserRegistry.cpp +++ b/Swiften/Server/UserRegistry.cpp @@ -4,7 +4,7 @@ * See Documentation/Licenses/GPLv3.txt for more information. */ -#include "Swiften/Server/UserRegistry.h" +#include <Swiften/Server/UserRegistry.h> namespace Swift { diff --git a/Swiften/Session/BasicSessionStream.cpp b/Swiften/Session/BasicSessionStream.cpp index c783e01..7e5f24b 100644 --- a/Swiften/Session/BasicSessionStream.cpp +++ b/Swiften/Session/BasicSessionStream.cpp @@ -4,18 +4,18 @@ * See Documentation/Licenses/GPLv3.txt for more information. */ -#include "Swiften/Session/BasicSessionStream.h" +#include <Swiften/Session/BasicSessionStream.h> #include <boost/bind.hpp> -#include "Swiften/StreamStack/XMPPLayer.h" -#include "Swiften/StreamStack/StreamStack.h" -#include "Swiften/StreamStack/ConnectionLayer.h" -#include "Swiften/StreamStack/WhitespacePingLayer.h" -#include "Swiften/StreamStack/CompressionLayer.h" -#include "Swiften/StreamStack/TLSLayer.h" -#include "Swiften/TLS/TLSContextFactory.h" -#include "Swiften/TLS/TLSContext.h" +#include <Swiften/StreamStack/XMPPLayer.h> +#include <Swiften/StreamStack/StreamStack.h> +#include <Swiften/StreamStack/ConnectionLayer.h> +#include <Swiften/StreamStack/WhitespacePingLayer.h> +#include <Swiften/StreamStack/CompressionLayer.h> +#include <Swiften/StreamStack/TLSLayer.h> +#include <Swiften/TLS/TLSContextFactory.h> +#include <Swiften/TLS/TLSContext.h> namespace Swift { diff --git a/Swiften/Session/BasicSessionStream.h b/Swiften/Session/BasicSessionStream.h index b3f7421..d2be2d3 100644 --- a/Swiften/Session/BasicSessionStream.h +++ b/Swiften/Session/BasicSessionStream.h @@ -8,9 +8,9 @@ #include <boost/shared_ptr.hpp> -#include "Swiften/Network/Connection.h" -#include "Swiften/Session/SessionStream.h" -#include "Swiften/Elements/StreamType.h" +#include <Swiften/Network/Connection.h> +#include <Swiften/Session/SessionStream.h> +#include <Swiften/Elements/StreamType.h> namespace Swift { class TLSContextFactory; diff --git a/Swiften/Session/Session.cpp b/Swiften/Session/Session.cpp index 39fab14..1d78640 100644 --- a/Swiften/Session/Session.cpp +++ b/Swiften/Session/Session.cpp @@ -4,12 +4,12 @@ * See Documentation/Licenses/GPLv3.txt for more information. */ -#include "Swiften/Session/Session.h" +#include <Swiften/Session/Session.h> #include <boost/bind.hpp> -#include "Swiften/StreamStack/XMPPLayer.h" -#include "Swiften/StreamStack/StreamStack.h" +#include <Swiften/StreamStack/XMPPLayer.h> +#include <Swiften/StreamStack/StreamStack.h> namespace Swift { diff --git a/Swiften/Session/Session.h b/Swiften/Session/Session.h index f8c8f0a..d399cd1 100644 --- a/Swiften/Session/Session.h +++ b/Swiften/Session/Session.h @@ -7,14 +7,14 @@ #pragma once #include <boost/shared_ptr.hpp> -#include "Swiften/Base/boost_bsignals.h" +#include <Swiften/Base/boost_bsignals.h> #include <boost/optional.hpp> #include <boost/enable_shared_from_this.hpp> -#include "Swiften/JID/JID.h" -#include "Swiften/Elements/Element.h" -#include "Swiften/Network/Connection.h" -#include "Swiften/StreamStack/ConnectionLayer.h" +#include <Swiften/JID/JID.h> +#include <Swiften/Elements/Element.h> +#include <Swiften/Network/Connection.h> +#include <Swiften/StreamStack/ConnectionLayer.h> namespace Swift { class ProtocolHeader; diff --git a/Swiften/Session/SessionStream.cpp b/Swiften/Session/SessionStream.cpp index 5bca0aa..0d73b63 100644 --- a/Swiften/Session/SessionStream.cpp +++ b/Swiften/Session/SessionStream.cpp @@ -4,7 +4,7 @@ * See Documentation/Licenses/GPLv3.txt for more information. */ -#include "Swiften/Session/SessionStream.h" +#include <Swiften/Session/SessionStream.h> namespace Swift { diff --git a/Swiften/Session/SessionStream.h b/Swiften/Session/SessionStream.h index 2753878..38f5d93 100644 --- a/Swiften/Session/SessionStream.h +++ b/Swiften/Session/SessionStream.h @@ -6,16 +6,16 @@ #pragma once -#include "Swiften/Base/boost_bsignals.h" +#include <Swiften/Base/boost_bsignals.h> #include <boost/shared_ptr.hpp> #include <boost/optional.hpp> -#include "Swiften/Elements/ProtocolHeader.h" -#include "Swiften/Elements/Element.h" -#include "Swiften/Base/Error.h" -#include "Swiften/TLS/PKCS12Certificate.h" -#include "Swiften/TLS/Certificate.h" -#include "Swiften/TLS/CertificateVerificationError.h" +#include <Swiften/Elements/ProtocolHeader.h> +#include <Swiften/Elements/Element.h> +#include <Swiften/Base/Error.h> +#include <Swiften/TLS/PKCS12Certificate.h> +#include <Swiften/TLS/Certificate.h> +#include <Swiften/TLS/CertificateVerificationError.h> namespace Swift { class SessionStream { diff --git a/Swiften/Session/SessionTracer.cpp b/Swiften/Session/SessionTracer.cpp new file mode 100644 index 0000000..6d41e40 --- /dev/null +++ b/Swiften/Session/SessionTracer.cpp @@ -0,0 +1,28 @@ +/* + * Copyright (c) 2010 Remko Tronçon + * Licensed under the GNU General Public License v3. + * See Documentation/Licenses/GPLv3.txt for more information. + */ + +#include <Swiften/Session/SessionTracer.h> + +#include <iostream> +#include <boost/bind.hpp> + +namespace Swift { + +SessionTracer::SessionTracer(boost::shared_ptr<Session> session) : session(session) { + session->onDataRead.connect(boost::bind(&SessionTracer::printData, this, '<', _1)); + session->onDataWritten.connect(boost::bind(&SessionTracer::printData, this, '>', _1)); +} + +void SessionTracer::printData(char direction, const ByteArray& data) { + std::cerr << direction << direction << " " << session->getLocalJID() << " "; + for (unsigned int i = 0; i < 72 - session->getLocalJID().toString().size() - session->getRemoteJID().toString().size(); ++i) { + std::cerr << direction; + } + std::cerr << " " << session->getRemoteJID()<< " " << direction << direction << std::endl; + std::cerr << data.toString() << std::endl; +} + +} diff --git a/Swiften/Session/SessionTracer.h b/Swiften/Session/SessionTracer.h index cce45eb..4e45957 100644 --- a/Swiften/Session/SessionTracer.h +++ b/Swiften/Session/SessionTracer.h @@ -6,29 +6,18 @@ #pragma once -#include <iostream> - -#include "Swiften/Session/Session.h" #include <string> -#include "Swiften/Base/ByteArray.h" + +#include <Swiften/Session/Session.h> +#include <Swiften/Base/ByteArray.h> namespace Swift { class SessionTracer { public: - SessionTracer(boost::shared_ptr<Session> session) : session(session) { - session->onDataRead.connect(boost::bind(&SessionTracer::printData, this, '<', _1)); - session->onDataWritten.connect(boost::bind(&SessionTracer::printData, this, '>', _1)); - } + SessionTracer(boost::shared_ptr<Session> session); private: - void printData(char direction, const ByteArray& data) { - std::cerr << direction << direction << " " << session->getLocalJID() << " "; - for (unsigned int i = 0; i < 72 - session->getLocalJID().toString().size() - session->getRemoteJID().toString().size(); ++i) { - std::cerr << direction; - } - std::cerr << " " << session->getRemoteJID()<< " " << direction << direction << std::endl; - std::cerr << data.toString() << std::endl; - } + void printData(char direction, const ByteArray& data); boost::shared_ptr<Session> session; }; diff --git a/Swiften/StreamManagement/StanzaAckRequester.cpp b/Swiften/StreamManagement/StanzaAckRequester.cpp index f7d603b..47f67a6 100644 --- a/Swiften/StreamManagement/StanzaAckRequester.cpp +++ b/Swiften/StreamManagement/StanzaAckRequester.cpp @@ -4,11 +4,12 @@ * See Documentation/Licenses/GPLv3.txt for more information. */ -#include "Swiften/StreamManagement/StanzaAckRequester.h" +#include <Swiften/StreamManagement/StanzaAckRequester.h> #include <boost/numeric/conversion/cast.hpp> +#include <iostream> -#include "Swiften/Elements/Message.h" +#include <Swiften/Elements/Message.h> namespace Swift { diff --git a/Swiften/StreamManagement/StanzaAckRequester.h b/Swiften/StreamManagement/StanzaAckRequester.h index 89f068e..e8e4997 100644 --- a/Swiften/StreamManagement/StanzaAckRequester.h +++ b/Swiften/StreamManagement/StanzaAckRequester.h @@ -9,8 +9,8 @@ #include <boost/shared_ptr.hpp> #include <deque> -#include "Swiften/Elements/Stanza.h" -#include "Swiften/Base/boost_bsignals.h" +#include <Swiften/Elements/Stanza.h> +#include <Swiften/Base/boost_bsignals.h> namespace Swift { class StanzaAckRequester { diff --git a/Swiften/StreamManagement/StanzaAckResponder.cpp b/Swiften/StreamManagement/StanzaAckResponder.cpp index 5b71f91..9295924 100644 --- a/Swiften/StreamManagement/StanzaAckResponder.cpp +++ b/Swiften/StreamManagement/StanzaAckResponder.cpp @@ -4,7 +4,7 @@ * See Documentation/Licenses/GPLv3.txt for more information. */ -#include "Swiften/StreamManagement/StanzaAckResponder.h" +#include <Swiften/StreamManagement/StanzaAckResponder.h> #include <boost/numeric/conversion/cast.hpp> diff --git a/Swiften/StreamManagement/StanzaAckResponder.h b/Swiften/StreamManagement/StanzaAckResponder.h index bc83aa1..b5888b7 100644 --- a/Swiften/StreamManagement/StanzaAckResponder.h +++ b/Swiften/StreamManagement/StanzaAckResponder.h @@ -8,8 +8,8 @@ #include <boost/shared_ptr.hpp> -#include "Swiften/Elements/Stanza.h" -#include "Swiften/Base/boost_bsignals.h" +#include <Swiften/Elements/Stanza.h> +#include <Swiften/Base/boost_bsignals.h> namespace Swift { class StanzaAckResponder { diff --git a/Swiften/StreamManagement/UnitTest/StanzaAckRequesterTest.cpp b/Swiften/StreamManagement/UnitTest/StanzaAckRequesterTest.cpp index 1028ae7..3f75017 100644 --- a/Swiften/StreamManagement/UnitTest/StanzaAckRequesterTest.cpp +++ b/Swiften/StreamManagement/UnitTest/StanzaAckRequesterTest.cpp @@ -9,10 +9,10 @@ #include <boost/bind.hpp> #include <boost/numeric/conversion/cast.hpp> -#include "Swiften/StreamManagement/StanzaAckRequester.h" -#include "Swiften/Elements/Message.h" -#include "Swiften/Elements/Presence.h" -#include "Swiften/Elements/IQ.h" +#include <Swiften/StreamManagement/StanzaAckRequester.h> +#include <Swiften/Elements/Message.h> +#include <Swiften/Elements/Presence.h> +#include <Swiften/Elements/IQ.h> using namespace Swift; diff --git a/Swiften/StreamManagement/UnitTest/StanzaAckResponderTest.cpp b/Swiften/StreamManagement/UnitTest/StanzaAckResponderTest.cpp index b24335f..37833bc 100644 --- a/Swiften/StreamManagement/UnitTest/StanzaAckResponderTest.cpp +++ b/Swiften/StreamManagement/UnitTest/StanzaAckResponderTest.cpp @@ -9,8 +9,8 @@ #include <boost/bind.hpp> #include <boost/numeric/conversion/cast.hpp> -#include "Swiften/StreamManagement/StanzaAckResponder.h" -#include "Swiften/Elements/Message.h" +#include <Swiften/StreamManagement/StanzaAckResponder.h> +#include <Swiften/Elements/Message.h> using namespace Swift; diff --git a/Swiften/StreamStack/CompressionLayer.h b/Swiften/StreamStack/CompressionLayer.h index b8293a8..b10ee52 100644 --- a/Swiften/StreamStack/CompressionLayer.h +++ b/Swiften/StreamStack/CompressionLayer.h @@ -7,13 +7,13 @@ #pragma once #include <boost/noncopyable.hpp> -#include "Swiften/Base/boost_bsignals.h" +#include <Swiften/Base/boost_bsignals.h> -#include "Swiften/Base/ByteArray.h" -#include "Swiften/StreamStack/StreamLayer.h" -#include "Swiften/Compress/ZLibException.h" -#include "Swiften/Compress/ZLibCompressor.h" -#include "Swiften/Compress/ZLibDecompressor.h" +#include <Swiften/Base/ByteArray.h> +#include <Swiften/StreamStack/StreamLayer.h> +#include <Swiften/Compress/ZLibException.h> +#include <Swiften/Compress/ZLibCompressor.h> +#include <Swiften/Compress/ZLibDecompressor.h> namespace Swift { class ZLibCompressor; @@ -27,7 +27,7 @@ namespace Swift { try { writeDataToChildLayer(compressor_.process(data)); } - catch (const ZLibException& e) { + catch (const ZLibException&) { onError(); } } @@ -36,7 +36,7 @@ namespace Swift { try { writeDataToParentLayer(decompressor_.process(data)); } - catch (const ZLibException& e) { + catch (const ZLibException&) { onError(); } } diff --git a/Swiften/StreamStack/ConnectionLayer.cpp b/Swiften/StreamStack/ConnectionLayer.cpp new file mode 100644 index 0000000..00b4289 --- /dev/null +++ b/Swiften/StreamStack/ConnectionLayer.cpp @@ -0,0 +1,21 @@ +/* + * Copyright (c) 2010 Remko Tronçon + * Licensed under the GNU General Public License v3. + * See Documentation/Licenses/GPLv3.txt for more information. + */ + +#include <Swiften/StreamStack/ConnectionLayer.h> +#include <boost/bind.hpp> + +namespace Swift { + +ConnectionLayer::ConnectionLayer(boost::shared_ptr<Connection> connection) : connection(connection) { + connection->onDataRead.connect(boost::bind(&ConnectionLayer::writeDataToParentLayer, this, _1)); +} + +ConnectionLayer::~ConnectionLayer() { + connection->onDataRead.disconnect(boost::bind(&ConnectionLayer::writeDataToParentLayer, this, _1)); +} + + +} diff --git a/Swiften/StreamStack/ConnectionLayer.h b/Swiften/StreamStack/ConnectionLayer.h index 0da0900..fc33e48 100644 --- a/Swiften/StreamStack/ConnectionLayer.h +++ b/Swiften/StreamStack/ConnectionLayer.h @@ -6,23 +6,16 @@ #pragma once -#include "Swiften/Base/boost_bsignals.h" #include <boost/shared_ptr.hpp> -#include <boost/bind.hpp> -#include "Swiften/StreamStack/LowLayer.h" -#include "Swiften/Network/Connection.h" +#include <Swiften/StreamStack/LowLayer.h> +#include <Swiften/Network/Connection.h> namespace Swift { class ConnectionLayer : public LowLayer { public: - ConnectionLayer(boost::shared_ptr<Connection> connection) : connection(connection) { - connection->onDataRead.connect(boost::bind(&ConnectionLayer::writeDataToParentLayer, this, _1)); - } - - ~ConnectionLayer() { - connection->onDataRead.disconnect(boost::bind(&ConnectionLayer::writeDataToParentLayer, this, _1)); - } + ConnectionLayer(boost::shared_ptr<Connection> connection); + ~ConnectionLayer(); void writeData(const ByteArray& data) { connection->write(data); diff --git a/Swiften/StreamStack/HighLayer.h b/Swiften/StreamStack/HighLayer.h index ca983f9..b96458f 100644 --- a/Swiften/StreamStack/HighLayer.h +++ b/Swiften/StreamStack/HighLayer.h @@ -6,7 +6,7 @@ #pragma once -#include "Swiften/Base/ByteArray.h" +#include <Swiften/Base/ByteArray.h> namespace Swift { class LowLayer; diff --git a/Swiften/StreamStack/LowLayer.h b/Swiften/StreamStack/LowLayer.h index 1f9645a..87eb3de 100644 --- a/Swiften/StreamStack/LowLayer.h +++ b/Swiften/StreamStack/LowLayer.h @@ -6,7 +6,7 @@ #pragma once -#include "Swiften/Base/ByteArray.h" +#include <Swiften/Base/ByteArray.h> namespace Swift { class HighLayer; diff --git a/Swiften/StreamStack/SConscript b/Swiften/StreamStack/SConscript index 022c695..06fcc03 100644 --- a/Swiften/StreamStack/SConscript +++ b/Swiften/StreamStack/SConscript @@ -6,6 +6,7 @@ sources = [ "HighLayer.cpp", "LowLayer.cpp", "StreamStack.cpp", + "ConnectionLayer.cpp", "TLSLayer.cpp", "WhitespacePingLayer.cpp", "XMPPLayer.cpp", diff --git a/Swiften/StreamStack/StreamLayer.h b/Swiften/StreamStack/StreamLayer.h index bcc5d79..09bb5b3 100644 --- a/Swiften/StreamStack/StreamLayer.h +++ b/Swiften/StreamStack/StreamLayer.h @@ -6,8 +6,8 @@ #pragma once -#include "Swiften/StreamStack/LowLayer.h" -#include "Swiften/StreamStack/HighLayer.h" +#include <Swiften/StreamStack/LowLayer.h> +#include <Swiften/StreamStack/HighLayer.h> namespace Swift { class StreamLayer : public LowLayer, public HighLayer { diff --git a/Swiften/StreamStack/StreamStack.cpp b/Swiften/StreamStack/StreamStack.cpp index 2a30768..78409f7 100644 --- a/Swiften/StreamStack/StreamStack.cpp +++ b/Swiften/StreamStack/StreamStack.cpp @@ -4,14 +4,14 @@ * See Documentation/Licenses/GPLv3.txt for more information. */ -#include "Swiften/StreamStack/StreamStack.h" +#include <Swiften/StreamStack/StreamStack.h> #include <boost/bind.hpp> -#include "Swiften/Base/foreach.h" -#include "Swiften/StreamStack/XMPPLayer.h" -#include "Swiften/StreamStack/LowLayer.h" -#include "Swiften/StreamStack/StreamLayer.h" +#include <Swiften/Base/foreach.h> +#include <Swiften/StreamStack/XMPPLayer.h> +#include <Swiften/StreamStack/LowLayer.h> +#include <Swiften/StreamStack/StreamLayer.h> namespace Swift { diff --git a/Swiften/StreamStack/StreamStack.h b/Swiften/StreamStack/StreamStack.h index 562245e..30e17ce 100644 --- a/Swiften/StreamStack/StreamStack.h +++ b/Swiften/StreamStack/StreamStack.h @@ -7,11 +7,10 @@ #pragma once #include <boost/shared_ptr.hpp> -#include "Swiften/Base/boost_bsignals.h" +#include <Swiften/Base/boost_bsignals.h> #include <vector> -#include "Swiften/Elements/Stanza.h" -#include "Swiften/Base/foreach.h" +#include <Swiften/Elements/Stanza.h> namespace Swift { class XMPPLayer; @@ -30,8 +29,8 @@ namespace Swift { } template<typename T> T* getLayer() { - foreach(StreamLayer* streamLayer, layers_) { - T* layer = dynamic_cast<T*>(streamLayer); + for (size_t i = 0; i < layers_.size(); ++i) { + T* layer = dynamic_cast<T*>(layers_[i]); if (layer) { return layer; } diff --git a/Swiften/StreamStack/TLSLayer.cpp b/Swiften/StreamStack/TLSLayer.cpp index 8a6c008..707b700 100644 --- a/Swiften/StreamStack/TLSLayer.cpp +++ b/Swiften/StreamStack/TLSLayer.cpp @@ -4,12 +4,12 @@ * See Documentation/Licenses/GPLv3.txt for more information. */ -#include "Swiften/StreamStack/TLSLayer.h" +#include <Swiften/StreamStack/TLSLayer.h> #include <boost/bind.hpp> -#include "Swiften/TLS/TLSContextFactory.h" -#include "Swiften/TLS/TLSContext.h" +#include <Swiften/TLS/TLSContextFactory.h> +#include <Swiften/TLS/TLSContext.h> namespace Swift { diff --git a/Swiften/StreamStack/TLSLayer.h b/Swiften/StreamStack/TLSLayer.h index 22e9aef..bec63ee 100644 --- a/Swiften/StreamStack/TLSLayer.h +++ b/Swiften/StreamStack/TLSLayer.h @@ -4,12 +4,12 @@ * See Documentation/Licenses/GPLv3.txt for more information. */ -#include "Swiften/Base/boost_bsignals.h" +#include <Swiften/Base/boost_bsignals.h> -#include "Swiften/Base/ByteArray.h" -#include "Swiften/StreamStack/StreamLayer.h" -#include "Swiften/TLS/Certificate.h" -#include "Swiften/TLS/CertificateVerificationError.h" +#include <Swiften/Base/ByteArray.h> +#include <Swiften/StreamStack/StreamLayer.h> +#include <Swiften/TLS/Certificate.h> +#include <Swiften/TLS/CertificateVerificationError.h> namespace Swift { class TLSContext; diff --git a/Swiften/StreamStack/UnitTest/StreamStackTest.cpp b/Swiften/StreamStack/UnitTest/StreamStackTest.cpp index be16baa..8b2e85c 100644 --- a/Swiften/StreamStack/UnitTest/StreamStackTest.cpp +++ b/Swiften/StreamStack/UnitTest/StreamStackTest.cpp @@ -4,7 +4,7 @@ * See Documentation/Licenses/GPLv3.txt for more information. */ -#include "Swiften/Base/ByteArray.h" +#include <Swiften/Base/ByteArray.h> #include <vector> #include <boost/bind.hpp> @@ -12,13 +12,13 @@ #include <cppunit/extensions/HelperMacros.h> #include <cppunit/extensions/TestFactoryRegistry.h> -#include "Swiften/Base/ByteArray.h" -#include "Swiften/StreamStack/StreamStack.h" -#include "Swiften/StreamStack/LowLayer.h" -#include "Swiften/StreamStack/XMPPLayer.h" -#include "Swiften/StreamStack/StreamLayer.h" -#include "Swiften/Parser/PayloadParsers/FullPayloadParserFactoryCollection.h" -#include "Swiften/Serializer/PayloadSerializers/FullPayloadSerializerCollection.h" +#include <Swiften/Base/ByteArray.h> +#include <Swiften/StreamStack/StreamStack.h> +#include <Swiften/StreamStack/LowLayer.h> +#include <Swiften/StreamStack/XMPPLayer.h> +#include <Swiften/StreamStack/StreamLayer.h> +#include <Swiften/Parser/PayloadParsers/FullPayloadParserFactoryCollection.h> +#include <Swiften/Serializer/PayloadSerializers/FullPayloadSerializerCollection.h> using namespace Swift; diff --git a/Swiften/StreamStack/UnitTest/XMPPLayerTest.cpp b/Swiften/StreamStack/UnitTest/XMPPLayerTest.cpp index 9d5e745..f6a75c1 100644 --- a/Swiften/StreamStack/UnitTest/XMPPLayerTest.cpp +++ b/Swiften/StreamStack/UnitTest/XMPPLayerTest.cpp @@ -9,13 +9,13 @@ #include <cppunit/extensions/HelperMacros.h> #include <cppunit/extensions/TestFactoryRegistry.h> -#include "Swiften/Elements/ProtocolHeader.h" -#include "Swiften/Elements/Presence.h" -#include "Swiften/Base/ByteArray.h" -#include "Swiften/StreamStack/XMPPLayer.h" -#include "Swiften/StreamStack/LowLayer.h" -#include "Swiften/Parser/PayloadParsers/FullPayloadParserFactoryCollection.h" -#include "Swiften/Serializer/PayloadSerializers/FullPayloadSerializerCollection.h" +#include <Swiften/Elements/ProtocolHeader.h> +#include <Swiften/Elements/Presence.h> +#include <Swiften/Base/ByteArray.h> +#include <Swiften/StreamStack/XMPPLayer.h> +#include <Swiften/StreamStack/LowLayer.h> +#include <Swiften/Parser/PayloadParsers/FullPayloadParserFactoryCollection.h> +#include <Swiften/Serializer/PayloadSerializers/FullPayloadSerializerCollection.h> using namespace Swift; diff --git a/Swiften/StreamStack/WhitespacePingLayer.cpp b/Swiften/StreamStack/WhitespacePingLayer.cpp index 35efc3c..9fb4b06 100644 --- a/Swiften/StreamStack/WhitespacePingLayer.cpp +++ b/Swiften/StreamStack/WhitespacePingLayer.cpp @@ -4,12 +4,12 @@ * See Documentation/Licenses/GPLv3.txt for more information. */ -#include "Swiften/StreamStack/WhitespacePingLayer.h" +#include <Swiften/StreamStack/WhitespacePingLayer.h> #include <boost/bind.hpp> -#include "Swiften/Network/TimerFactory.h" -#include "Swiften/Network/Timer.h" +#include <Swiften/Network/TimerFactory.h> +#include <Swiften/Network/Timer.h> namespace Swift { diff --git a/Swiften/StreamStack/WhitespacePingLayer.h b/Swiften/StreamStack/WhitespacePingLayer.h index 0532bbd..7c42c29 100644 --- a/Swiften/StreamStack/WhitespacePingLayer.h +++ b/Swiften/StreamStack/WhitespacePingLayer.h @@ -9,7 +9,7 @@ #include <boost/noncopyable.hpp> #include <boost/shared_ptr.hpp> -#include "Swiften/StreamStack/StreamLayer.h" +#include <Swiften/StreamStack/StreamLayer.h> namespace Swift { class Timer; diff --git a/Swiften/StreamStack/XMPPLayer.cpp b/Swiften/StreamStack/XMPPLayer.cpp index 684dfe6..3c7dcb4 100644 --- a/Swiften/StreamStack/XMPPLayer.cpp +++ b/Swiften/StreamStack/XMPPLayer.cpp @@ -4,10 +4,10 @@ * See Documentation/Licenses/GPLv3.txt for more information. */ -#include "Swiften/StreamStack/XMPPLayer.h" -#include "Swiften/Parser/XMPPParser.h" -#include "Swiften/Serializer/XMPPSerializer.h" -#include "Swiften/Elements/ProtocolHeader.h" +#include <Swiften/StreamStack/XMPPLayer.h> +#include <Swiften/Parser/XMPPParser.h> +#include <Swiften/Serializer/XMPPSerializer.h> +#include <Swiften/Elements/ProtocolHeader.h> namespace Swift { diff --git a/Swiften/StreamStack/XMPPLayer.h b/Swiften/StreamStack/XMPPLayer.h index 6669cda..72d0e7e 100644 --- a/Swiften/StreamStack/XMPPLayer.h +++ b/Swiften/StreamStack/XMPPLayer.h @@ -7,14 +7,14 @@ #pragma once #include <boost/shared_ptr.hpp> -#include "Swiften/Base/boost_bsignals.h" +#include <Swiften/Base/boost_bsignals.h> #include <boost/noncopyable.hpp> #include <Swiften/StreamStack/HighLayer.h> -#include "Swiften/Base/ByteArray.h" -#include "Swiften/Elements/Element.h" -#include "Swiften/Elements/StreamType.h" -#include "Swiften/Parser/XMPPParserClient.h" +#include <Swiften/Base/ByteArray.h> +#include <Swiften/Elements/Element.h> +#include <Swiften/Elements/StreamType.h> +#include <Swiften/Parser/XMPPParserClient.h> namespace Swift { class ProtocolHeader; diff --git a/Swiften/StringCodecs/Base64.cpp b/Swiften/StringCodecs/Base64.cpp index 795d982..214a425 100644 --- a/Swiften/StringCodecs/Base64.cpp +++ b/Swiften/StringCodecs/Base64.cpp @@ -7,7 +7,7 @@ #include <boost/numeric/conversion/cast.hpp> #include <algorithm> -#include "Swiften/StringCodecs/Base64.h" +#include <Swiften/StringCodecs/Base64.h> namespace Swift { diff --git a/Swiften/StringCodecs/Base64.h b/Swiften/StringCodecs/Base64.h index 4b19a9f..3b14595 100644 --- a/Swiften/StringCodecs/Base64.h +++ b/Swiften/StringCodecs/Base64.h @@ -9,7 +9,7 @@ #include <vector> #include <string> -#include "Swiften/Base/ByteArray.h" +#include <Swiften/Base/ByteArray.h> namespace Swift { class Base64 { diff --git a/Swiften/StringCodecs/HMACSHA1.cpp b/Swiften/StringCodecs/HMACSHA1.cpp index 6ae5513..6f88d68 100644 --- a/Swiften/StringCodecs/HMACSHA1.cpp +++ b/Swiften/StringCodecs/HMACSHA1.cpp @@ -4,12 +4,12 @@ * See Documentation/Licenses/GPLv3.txt for more information. */ -#include "Swiften/StringCodecs/HMACSHA1.h" +#include <Swiften/StringCodecs/HMACSHA1.h> #include <cassert> -#include "Swiften/StringCodecs/SHA1.h" -#include "Swiften/Base/ByteArray.h" +#include <Swiften/StringCodecs/SHA1.h> +#include <Swiften/Base/ByteArray.h> namespace Swift { diff --git a/Swiften/StringCodecs/Hexify.cpp b/Swiften/StringCodecs/Hexify.cpp index 61732b0..05b7d66 100644 --- a/Swiften/StringCodecs/Hexify.cpp +++ b/Swiften/StringCodecs/Hexify.cpp @@ -4,14 +4,14 @@ * See Documentation/Licenses/GPLv3.txt for more information. */ -#include "Swiften/StringCodecs/Hexify.h" +#include <Swiften/StringCodecs/Hexify.h> #include <sstream> #include <iomanip> #include <boost/numeric/conversion/cast.hpp> #include <string> -#include "Swiften/Base/ByteArray.h" +#include <Swiften/Base/ByteArray.h> namespace Swift { diff --git a/Swiften/StringCodecs/MD5.cpp b/Swiften/StringCodecs/MD5.cpp index 718f52e..07dcd8b 100644 --- a/Swiften/StringCodecs/MD5.cpp +++ b/Swiften/StringCodecs/MD5.cpp @@ -33,12 +33,12 @@ #pragma GCC diagnostic ignored "-Wold-style-cast" -#include "Swiften/StringCodecs/MD5.h" +#include <Swiften/StringCodecs/MD5.h> #include <cassert> -#include "Swiften/Base/ByteArray.h" -#include "Swiften/Base/Platform.h" +#include <Swiften/Base/ByteArray.h> +#include <Swiften/Base/Platform.h> namespace Swift { diff --git a/Swiften/StringCodecs/PBKDF2.cpp b/Swiften/StringCodecs/PBKDF2.cpp index a652242..f5b6126 100644 --- a/Swiften/StringCodecs/PBKDF2.cpp +++ b/Swiften/StringCodecs/PBKDF2.cpp @@ -4,8 +4,8 @@ * See Documentation/Licenses/GPLv3.txt for more information. */ -#include "Swiften/StringCodecs/PBKDF2.h" -#include "Swiften/StringCodecs/HMACSHA1.h" +#include <Swiften/StringCodecs/PBKDF2.h> +#include <Swiften/StringCodecs/HMACSHA1.h> namespace Swift { diff --git a/Swiften/StringCodecs/PBKDF2.h b/Swiften/StringCodecs/PBKDF2.h index 7f87af7..dd31921 100644 --- a/Swiften/StringCodecs/PBKDF2.h +++ b/Swiften/StringCodecs/PBKDF2.h @@ -6,7 +6,7 @@ #pragma once -#include "Swiften/Base/ByteArray.h" +#include <Swiften/Base/ByteArray.h> namespace Swift { class PBKDF2 { diff --git a/Swiften/StringCodecs/SHA1.cpp b/Swiften/StringCodecs/SHA1.cpp index 9882f70..eb667a8 100644 --- a/Swiften/StringCodecs/SHA1.cpp +++ b/Swiften/StringCodecs/SHA1.cpp @@ -4,10 +4,14 @@ * See Documentation/Licenses/GPLv3.txt for more information. */ -#include "Swiften/Base/Platform.h" +#include <Swiften/StringCodecs/SHA1.h> + +#include <Swiften/Base/Platform.h> #pragma GCC diagnostic ignored "-Wold-style-cast" +using namespace Swift; + /* SHA-1 in C By Steve Reid <steve@edmweb.com> @@ -25,21 +29,9 @@ A million repetitions of "a" /* #define LITTLE_ENDIAN * This should be #define'd if true. */ /* #define SHA1HANDSOFF * Copies data before messing with it. */ -#include <boost/cstdint.hpp> #include <stdio.h> #include <string.h> -typedef struct { - boost::uint32_t state[5]; - boost::uint32_t count[2]; - boost::uint8_t buffer[64]; -} SHA1_CTX; - -void SHA1Transform(boost::uint32_t state[5], boost::uint8_t buffer[64]); -void SHA1Init(SHA1_CTX* context); -void SHA1Update(SHA1_CTX* context, boost::uint8_t* data, unsigned int len); -void SHA1Final(boost::uint8_t digest[20], SHA1_CTX* context); - #define rol(value, bits) (((value) << (bits)) | ((value) >> (32 - (bits)))) /* blk0() and blk() perform the initial expand. */ @@ -63,7 +55,7 @@ void SHA1Final(boost::uint8_t digest[20], SHA1_CTX* context); /* Hash a single 512-bit block. This is the core of the algorithm. */ -void SHA1Transform(boost::uint32_t state[5], boost::uint8_t buffer[64]) +void SHA1::Transform(boost::uint32_t state[5], boost::uint8_t buffer[64]) { boost::uint32_t a, b, c, d, e; typedef union { @@ -118,7 +110,7 @@ static boost::uint8_t workspace[64]; /* SHA1Init - Initialize new context */ -void SHA1Init(SHA1_CTX* context) +void SHA1::Init(SHA1::CTX* context) { /* SHA1 initialization constants */ context->state[0] = 0x67452301; @@ -132,7 +124,7 @@ void SHA1Init(SHA1_CTX* context) /* Run your data through this. */ -void SHA1Update(SHA1_CTX* context, boost::uint8_t* data, unsigned int len) +void SHA1::Update(SHA1::CTX* context, boost::uint8_t* data, unsigned int len) { unsigned int i, j; @@ -141,9 +133,9 @@ unsigned int i, j; context->count[1] += (len >> 29); if ((j + len) > 63) { memcpy(&context->buffer[j], data, (i = 64-j)); - SHA1Transform(context->state, context->buffer); + Transform(context->state, context->buffer); for ( ; i + 63 < len; i += 64) { - SHA1Transform(context->state, &data[i]); + Transform(context->state, &data[i]); } j = 0; } @@ -154,7 +146,7 @@ unsigned int i, j; /* Add padding and return the message digest. */ -void SHA1Final(boost::uint8_t digest[20], SHA1_CTX* context) +void SHA1::Final(boost::uint8_t digest[20], SHA1::CTX* context) { boost::uint32_t i, j; boost::uint8_t finalcount[8]; @@ -163,11 +155,11 @@ boost::uint8_t finalcount[8]; finalcount[i] = (boost::uint8_t) ((context->count[(i >= 4 ? 0 : 1)] >> ((3-(i & 3)) * 8) ) & 255); /* Endian independent */ } - SHA1Update(context, (boost::uint8_t *)("\200"), 1); + Update(context, (boost::uint8_t *)("\200"), 1); while ((context->count[0] & 504) != 448) { - SHA1Update(context, (boost::uint8_t *)("\0"), 1); + Update(context, (boost::uint8_t *)("\0"), 1); } - SHA1Update(context, finalcount, 8); /* Should cause a SHA1Transform() */ + Update(context, finalcount, 8); /* Should cause a SHA1Transform() */ for (i = 0; i < 20; i++) { digest[i] = (boost::uint8_t) ((context->state[i>>2] >> ((3-(i & 3)) * 8) ) & 255); @@ -179,24 +171,43 @@ boost::uint8_t finalcount[8]; memset(context->count, 0, 8); memset(&finalcount, 0, 8); #ifdef SHA1HANDSOFF /* make SHA1Transform overwrite it's own static vars */ - SHA1Transform(context->state, context->buffer); + Transform(context->state, context->buffer); #endif } // ----------------------------------------------------------------------------- -#include "Swiften/StringCodecs/SHA1.h" - namespace Swift { +SHA1::SHA1() { + Init(&context); +} + +SHA1& SHA1::update(const std::vector<unsigned char>& input) { + std::vector<unsigned char> inputCopy(input); + Update(&context, (boost::uint8_t*) ByteArray::data(inputCopy), inputCopy.size()); + return *this; +} + +std::vector<unsigned char> SHA1::getHash() const { + std::vector<unsigned char> digest; + digest.resize(20); + CTX contextCopy(context); + Final((boost::uint8_t*) ByteArray::data(digest), &contextCopy); + return digest; +} + ByteArray SHA1::getHash(const ByteArray& input) { - ByteArray inputCopy(input); + CTX context; + Init(&context); + + std::vector<unsigned char> inputCopy(input.getVector()); + Update(&context, (boost::uint8_t*) ByteArray::data(inputCopy), inputCopy.size()); + ByteArray digest; digest.resize(20); - SHA1_CTX context; - SHA1Init(&context); - SHA1Update(&context, (boost::uint8_t*) inputCopy.getData(), inputCopy.getSize()); - SHA1Final((boost::uint8_t*) digest.getData(), &context); + Final((boost::uint8_t*) digest.getData(), &context); + return digest; } diff --git a/Swiften/StringCodecs/SHA1.h b/Swiften/StringCodecs/SHA1.h index fc5ba0e..671d890 100644 --- a/Swiften/StringCodecs/SHA1.h +++ b/Swiften/StringCodecs/SHA1.h @@ -6,11 +6,38 @@ #pragma once -#include "Swiften/Base/ByteArray.h" +#include <vector> +#include <boost/cstdint.hpp> + +#include <Swiften/Base/ByteArray.h> namespace Swift { class SHA1 { public: + SHA1(); + + SHA1& update(const std::vector<unsigned char>& data); + std::vector<unsigned char> getHash() const; + + /** + * Equivalent of: + * SHA1().update(data),getHash(), but slightly more efficient and + * convenient. + */ static ByteArray getHash(const ByteArray& data); + + private: + typedef struct { + boost::uint32_t state[5]; + boost::uint32_t count[2]; + boost::uint8_t buffer[64]; + } CTX; + static void Init(CTX* context); + static void Transform(boost::uint32_t state[5], boost::uint8_t buffer[64]); + static void Update(CTX* context, boost::uint8_t* data, unsigned int len); + static void Final(boost::uint8_t digest[20], CTX* context); + + private: + CTX context; }; } diff --git a/Swiften/StringCodecs/UnitTest/Base64Test.cpp b/Swiften/StringCodecs/UnitTest/Base64Test.cpp index b263050..211e684 100644 --- a/Swiften/StringCodecs/UnitTest/Base64Test.cpp +++ b/Swiften/StringCodecs/UnitTest/Base64Test.cpp @@ -4,12 +4,12 @@ * See Documentation/Licenses/GPLv3.txt for more information. */ -#include "Swiften/Base/ByteArray.h" +#include <Swiften/Base/ByteArray.h> #include <cppunit/extensions/HelperMacros.h> #include <cppunit/extensions/TestFactoryRegistry.h> -#include "Swiften/StringCodecs/Base64.h" +#include <Swiften/StringCodecs/Base64.h> using namespace Swift; diff --git a/Swiften/StringCodecs/UnitTest/HMACSHA1Test.cpp b/Swiften/StringCodecs/UnitTest/HMACSHA1Test.cpp index 44bd5b7..600765a 100644 --- a/Swiften/StringCodecs/UnitTest/HMACSHA1Test.cpp +++ b/Swiften/StringCodecs/UnitTest/HMACSHA1Test.cpp @@ -4,13 +4,13 @@ * See Documentation/Licenses/GPLv3.txt for more information. */ -#include "Swiften/Base/ByteArray.h" +#include <Swiften/Base/ByteArray.h> #include <cppunit/extensions/HelperMacros.h> #include <cppunit/extensions/TestFactoryRegistry.h> -#include "Swiften/Base/ByteArray.h" -#include "Swiften/StringCodecs/HMACSHA1.h" +#include <Swiften/Base/ByteArray.h> +#include <Swiften/StringCodecs/HMACSHA1.h> using namespace Swift; diff --git a/Swiften/StringCodecs/UnitTest/HexifyTest.cpp b/Swiften/StringCodecs/UnitTest/HexifyTest.cpp index 0f267bf..9643d00 100644 --- a/Swiften/StringCodecs/UnitTest/HexifyTest.cpp +++ b/Swiften/StringCodecs/UnitTest/HexifyTest.cpp @@ -7,9 +7,9 @@ #include <cppunit/extensions/HelperMacros.h> #include <cppunit/extensions/TestFactoryRegistry.h> -#include "Swiften/StringCodecs/Hexify.h" +#include <Swiften/StringCodecs/Hexify.h> #include <string> -#include "Swiften/Base/ByteArray.h" +#include <Swiften/Base/ByteArray.h> using namespace Swift; diff --git a/Swiften/StringCodecs/UnitTest/MD5Test.cpp b/Swiften/StringCodecs/UnitTest/MD5Test.cpp index b76af48..3f764d2 100644 --- a/Swiften/StringCodecs/UnitTest/MD5Test.cpp +++ b/Swiften/StringCodecs/UnitTest/MD5Test.cpp @@ -4,13 +4,13 @@ * See Documentation/Licenses/GPLv3.txt for more information. */ -#include "Swiften/Base/ByteArray.h" +#include <Swiften/Base/ByteArray.h> #include <cppunit/extensions/HelperMacros.h> #include <cppunit/extensions/TestFactoryRegistry.h> -#include "Swiften/StringCodecs/MD5.h" -#include "Swiften/Base/ByteArray.h" +#include <Swiften/StringCodecs/MD5.h> +#include <Swiften/Base/ByteArray.h> using namespace Swift; diff --git a/Swiften/StringCodecs/UnitTest/PBKDF2Test.cpp b/Swiften/StringCodecs/UnitTest/PBKDF2Test.cpp index 092fe31..7952471 100644 --- a/Swiften/StringCodecs/UnitTest/PBKDF2Test.cpp +++ b/Swiften/StringCodecs/UnitTest/PBKDF2Test.cpp @@ -4,13 +4,13 @@ * See Documentation/Licenses/GPLv3.txt for more information. */ -#include "Swiften/Base/ByteArray.h" +#include <Swiften/Base/ByteArray.h> #include <cppunit/extensions/HelperMacros.h> #include <cppunit/extensions/TestFactoryRegistry.h> -#include "Swiften/Base/ByteArray.h" -#include "Swiften/StringCodecs/PBKDF2.h" +#include <Swiften/Base/ByteArray.h> +#include <Swiften/StringCodecs/PBKDF2.h> using namespace Swift; diff --git a/Swiften/StringCodecs/UnitTest/SHA1Test.cpp b/Swiften/StringCodecs/UnitTest/SHA1Test.cpp index 9434235..76b71f9 100644 --- a/Swiften/StringCodecs/UnitTest/SHA1Test.cpp +++ b/Swiften/StringCodecs/UnitTest/SHA1Test.cpp @@ -4,30 +4,77 @@ * See Documentation/Licenses/GPLv3.txt for more information. */ -#include "Swiften/Base/ByteArray.h" +#include <Swiften/Base/ByteArray.h> #include <cppunit/extensions/HelperMacros.h> #include <cppunit/extensions/TestFactoryRegistry.h> -#include "Swiften/StringCodecs/SHA1.h" +#include <Swiften/StringCodecs/SHA1.h> using namespace Swift; class SHA1Test : public CppUnit::TestFixture { CPPUNIT_TEST_SUITE(SHA1Test); CPPUNIT_TEST(testGetHash); - CPPUNIT_TEST(testGetHash_Twice); + CPPUNIT_TEST(testGetHash_TwoUpdates); + CPPUNIT_TEST(testGetHash_TwoGetHash); CPPUNIT_TEST(testGetHash_NoData); + CPPUNIT_TEST(testGetHash_InterleavedUpdate); + CPPUNIT_TEST(testGetHashStatic); + CPPUNIT_TEST(testGetHashStatic_Twice); + CPPUNIT_TEST(testGetHashStatic_NoData); CPPUNIT_TEST_SUITE_END(); public: void testGetHash() { + SHA1 sha; + sha.update(ByteArray::create("client/pc//Exodus 0.9.1<http://jabber.org/protocol/caps<http://jabber.org/protocol/disco#info<http://jabber.org/protocol/disco#items<http://jabber.org/protocol/muc<")); + + CPPUNIT_ASSERT_EQUAL(ByteArray::create("\x42\x06\xb2\x3c\xa6\xb0\xa6\x43\xd2\x0d\x89\xb0\x4f\xf5\x8c\xf7\x8b\x80\x96\xed"), sha.getHash()); + } + + void testGetHash_TwoUpdates() { + SHA1 sha; + sha.update(ByteArray::create("client/pc//Exodus 0.9.1<http://jabber.org/protocol/caps<")); + sha.update(ByteArray::create("http://jabber.org/protocol/disco#info<http://jabber.org/protocol/disco#items<http://jabber.org/protocol/muc<")); + + CPPUNIT_ASSERT_EQUAL(ByteArray::create("\x42\x06\xb2\x3c\xa6\xb0\xa6\x43\xd2\x0d\x89\xb0\x4f\xf5\x8c\xf7\x8b\x80\x96\xed"), sha.getHash()); + } + + void testGetHash_TwoGetHash() { + SHA1 sha; + sha.update(ByteArray::create("client/pc//Exodus 0.9.1<http://jabber.org/protocol/caps<http://jabber.org/protocol/disco#info<http://jabber.org/protocol/disco#items<http://jabber.org/protocol/muc<")); + + sha.getHash(); + + CPPUNIT_ASSERT_EQUAL(ByteArray::create("\x42\x06\xb2\x3c\xa6\xb0\xa6\x43\xd2\x0d\x89\xb0\x4f\xf5\x8c\xf7\x8b\x80\x96\xed"), sha.getHash()); + } + + void testGetHash_InterleavedUpdate() { + SHA1 sha; + + sha.update(ByteArray::create("client/pc//Exodus 0.9.1<http://jabber.org/protocol/caps<")); + sha.getHash(); + sha.update(ByteArray::create("http://jabber.org/protocol/disco#info<http://jabber.org/protocol/disco#items<http://jabber.org/protocol/muc<")); + + CPPUNIT_ASSERT_EQUAL(ByteArray::create("\x42\x06\xb2\x3c\xa6\xb0\xa6\x43\xd2\x0d\x89\xb0\x4f\xf5\x8c\xf7\x8b\x80\x96\xed"), sha.getHash()); + } + + + void testGetHash_NoData() { + SHA1 sha; + sha.update(std::vector<unsigned char>()); + + CPPUNIT_ASSERT_EQUAL(ByteArray::create("\xda\x39\xa3\xee\x5e\x6b\x4b\x0d\x32\x55\xbf\xef\x95\x60\x18\x90\xaf\xd8\x07\x09"), sha.getHash()); + } + + void testGetHashStatic() { ByteArray result(SHA1::getHash("client/pc//Exodus 0.9.1<http://jabber.org/protocol/caps<http://jabber.org/protocol/disco#info<http://jabber.org/protocol/disco#items<http://jabber.org/protocol/muc<")); CPPUNIT_ASSERT_EQUAL(ByteArray("\x42\x06\xb2\x3c\xa6\xb0\xa6\x43\xd2\x0d\x89\xb0\x4f\xf5\x8c\xf7\x8b\x80\x96\xed"), result); } - void testGetHash_Twice() { + void testGetHashStatic_Twice() { ByteArray input("client/pc//Exodus 0.9.1<http://jabber.org/protocol/caps<http://jabber.org/protocol/disco#info<http://jabber.org/protocol/disco#items<http://jabber.org/protocol/muc<"); SHA1::getHash(input); ByteArray result(SHA1::getHash(input)); @@ -35,7 +82,7 @@ class SHA1Test : public CppUnit::TestFixture { CPPUNIT_ASSERT_EQUAL(ByteArray("\x42\x06\xb2\x3c\xa6\xb0\xa6\x43\xd2\x0d\x89\xb0\x4f\xf5\x8c\xf7\x8b\x80\x96\xed"), result); } - void testGetHash_NoData() { + void testGetHashStatic_NoData() { ByteArray result(SHA1::getHash(ByteArray())); CPPUNIT_ASSERT_EQUAL(ByteArray("\xda\x39\xa3\xee\x5e\x6b\x4b\x0d\x32\x55\xbf\xef\x95\x60\x18\x90\xaf\xd8\x07\x09"), result); diff --git a/Swiften/TLS/BlindCertificateTrustChecker.h b/Swiften/TLS/BlindCertificateTrustChecker.h index d9db14c..3177322 100644 --- a/Swiften/TLS/BlindCertificateTrustChecker.h +++ b/Swiften/TLS/BlindCertificateTrustChecker.h @@ -6,7 +6,7 @@ #pragma once -#include "Swiften/TLS/CertificateTrustChecker.h" +#include <Swiften/TLS/CertificateTrustChecker.h> namespace Swift { /** diff --git a/Swiften/TLS/Certificate.h b/Swiften/TLS/Certificate.h index dc93a2d..ec59a39 100644 --- a/Swiften/TLS/Certificate.h +++ b/Swiften/TLS/Certificate.h @@ -9,7 +9,7 @@ #include <boost/shared_ptr.hpp> #include <string> -#include "Swiften/Base/ByteArray.h" +#include <Swiften/Base/ByteArray.h> namespace Swift { class Certificate { diff --git a/Swiften/TLS/CertificateFactory.cpp b/Swiften/TLS/CertificateFactory.cpp index b2edaf4..df01090 100644 --- a/Swiften/TLS/CertificateFactory.cpp +++ b/Swiften/TLS/CertificateFactory.cpp @@ -4,7 +4,7 @@ * See Documentation/Licenses/GPLv3.txt for more information. */ -#include "Swiften/TLS/CertificateFactory.h" +#include <Swiften/TLS/CertificateFactory.h> namespace Swift { diff --git a/Swiften/TLS/CertificateFactory.h b/Swiften/TLS/CertificateFactory.h index 90eca58..3e94082 100644 --- a/Swiften/TLS/CertificateFactory.h +++ b/Swiften/TLS/CertificateFactory.h @@ -6,7 +6,7 @@ #pragma once -#include "Swiften/TLS/Certificate.h" +#include <Swiften/TLS/Certificate.h> namespace Swift { class CertificateFactory { diff --git a/Swiften/TLS/CertificateTrustChecker.cpp b/Swiften/TLS/CertificateTrustChecker.cpp index f4f921d..42e24a1 100644 --- a/Swiften/TLS/CertificateTrustChecker.cpp +++ b/Swiften/TLS/CertificateTrustChecker.cpp @@ -4,7 +4,7 @@ * See Documentation/Licenses/GPLv3.txt for more information. */ -#include "Swiften/TLS/CertificateTrustChecker.h" +#include <Swiften/TLS/CertificateTrustChecker.h> namespace Swift { diff --git a/Swiften/TLS/CertificateTrustChecker.h b/Swiften/TLS/CertificateTrustChecker.h index aec03e3..06c0c32 100644 --- a/Swiften/TLS/CertificateTrustChecker.h +++ b/Swiften/TLS/CertificateTrustChecker.h @@ -9,7 +9,7 @@ #include <boost/shared_ptr.hpp> #include <string> -#include "Swiften/TLS/Certificate.h" +#include <Swiften/TLS/Certificate.h> namespace Swift { /** diff --git a/Swiften/TLS/CertificateVerificationError.h b/Swiften/TLS/CertificateVerificationError.h index 554fd3b..2815fdb 100644 --- a/Swiften/TLS/CertificateVerificationError.h +++ b/Swiften/TLS/CertificateVerificationError.h @@ -6,7 +6,7 @@ #pragma once -#include "Swiften/Base/Error.h" +#include <Swiften/Base/Error.h> namespace Swift { class CertificateVerificationError : public Error { diff --git a/Swiften/TLS/OpenSSL/OpenSSLCertificate.h b/Swiften/TLS/OpenSSL/OpenSSLCertificate.h index b900170..897b432 100644 --- a/Swiften/TLS/OpenSSL/OpenSSLCertificate.h +++ b/Swiften/TLS/OpenSSL/OpenSSLCertificate.h @@ -10,7 +10,7 @@ #include <openssl/ssl.h> #include <string> -#include "Swiften/TLS/Certificate.h" +#include <Swiften/TLS/Certificate.h> namespace Swift { class OpenSSLCertificate : public Certificate { diff --git a/Swiften/TLS/OpenSSL/OpenSSLCertificateFactory.h b/Swiften/TLS/OpenSSL/OpenSSLCertificateFactory.h index cd4982e..52f134c 100644 --- a/Swiften/TLS/OpenSSL/OpenSSLCertificateFactory.h +++ b/Swiften/TLS/OpenSSL/OpenSSLCertificateFactory.h @@ -6,8 +6,8 @@ #pragma once -#include "Swiften/TLS/CertificateFactory.h" -#include "Swiften/TLS/OpenSSL/OpenSSLCertificate.h" +#include <Swiften/TLS/CertificateFactory.h> +#include <Swiften/TLS/OpenSSL/OpenSSLCertificate.h> namespace Swift { class OpenSSLCertificateFactory : public CertificateFactory { diff --git a/Swiften/TLS/OpenSSL/OpenSSLContext.cpp b/Swiften/TLS/OpenSSL/OpenSSLContext.cpp index 378b6aa..a2f97e6 100644 --- a/Swiften/TLS/OpenSSL/OpenSSLContext.cpp +++ b/Swiften/TLS/OpenSSL/OpenSSLContext.cpp @@ -3,7 +3,7 @@ * Licensed under the GNU General Public License v3. * See Documentation/Licenses/GPLv3.txt for more information. */ -#include "Swiften/Base/Platform.h" +#include <Swiften/Base/Platform.h> #ifdef SWIFTEN_PLATFORM_WINDOWS #include <windows.h> @@ -18,9 +18,9 @@ #include <Security/Security.h> #endif -#include "Swiften/TLS/OpenSSL/OpenSSLContext.h" -#include "Swiften/TLS/OpenSSL/OpenSSLCertificate.h" -#include "Swiften/TLS/PKCS12Certificate.h" +#include <Swiften/TLS/OpenSSL/OpenSSLContext.h> +#include <Swiften/TLS/OpenSSL/OpenSSLCertificate.h> +#include <Swiften/TLS/PKCS12Certificate.h> #pragma GCC diagnostic ignored "-Wold-style-cast" diff --git a/Swiften/TLS/OpenSSL/OpenSSLContext.h b/Swiften/TLS/OpenSSL/OpenSSLContext.h index 40e5483..30ac917 100644 --- a/Swiften/TLS/OpenSSL/OpenSSLContext.h +++ b/Swiften/TLS/OpenSSL/OpenSSLContext.h @@ -7,11 +7,11 @@ #pragma once #include <openssl/ssl.h> -#include "Swiften/Base/boost_bsignals.h" +#include <Swiften/Base/boost_bsignals.h> #include <boost/noncopyable.hpp> -#include "Swiften/TLS/TLSContext.h" -#include "Swiften/Base/ByteArray.h" +#include <Swiften/TLS/TLSContext.h> +#include <Swiften/Base/ByteArray.h> namespace Swift { class PKCS12Certificate; diff --git a/Swiften/TLS/OpenSSL/OpenSSLContextFactory.cpp b/Swiften/TLS/OpenSSL/OpenSSLContextFactory.cpp index f975df7..516482d 100644 --- a/Swiften/TLS/OpenSSL/OpenSSLContextFactory.cpp +++ b/Swiften/TLS/OpenSSL/OpenSSLContextFactory.cpp @@ -4,8 +4,8 @@ * See Documentation/Licenses/GPLv3.txt for more information. */ -#include "Swiften/TLS/OpenSSL/OpenSSLContextFactory.h" -#include "Swiften/TLS/OpenSSL/OpenSSLContext.h" +#include <Swiften/TLS/OpenSSL/OpenSSLContextFactory.h> +#include <Swiften/TLS/OpenSSL/OpenSSLContext.h> namespace Swift { diff --git a/Swiften/TLS/OpenSSL/OpenSSLContextFactory.h b/Swiften/TLS/OpenSSL/OpenSSLContextFactory.h index cf982c0..4e39cd6 100644 --- a/Swiften/TLS/OpenSSL/OpenSSLContextFactory.h +++ b/Swiften/TLS/OpenSSL/OpenSSLContextFactory.h @@ -6,7 +6,7 @@ #pragma once -#include "Swiften/TLS/TLSContextFactory.h" +#include <Swiften/TLS/TLSContextFactory.h> namespace Swift { class OpenSSLContextFactory : public TLSContextFactory { diff --git a/Swiften/TLS/PKCS12Certificate.h b/Swiften/TLS/PKCS12Certificate.h index 1c8c38f..75a60bc 100644 --- a/Swiften/TLS/PKCS12Certificate.h +++ b/Swiften/TLS/PKCS12Certificate.h @@ -7,7 +7,7 @@ #ifndef SWIFTEN_PKCS12Certificate_H #define SWIFTEN_PKCS12Certificate_H -#include "Swiften/Base/ByteArray.h" +#include <Swiften/Base/ByteArray.h> namespace Swift { class PKCS12Certificate { diff --git a/Swiften/TLS/PlatformTLSFactories.cpp b/Swiften/TLS/PlatformTLSFactories.cpp index e642758..dec8788 100644 --- a/Swiften/TLS/PlatformTLSFactories.cpp +++ b/Swiften/TLS/PlatformTLSFactories.cpp @@ -4,14 +4,14 @@ * See Documentation/Licenses/GPLv3.txt for more information. */ -#include "Swiften/TLS/PlatformTLSFactories.h" +#include <Swiften/TLS/PlatformTLSFactories.h> #include <cstring> #include <cassert> #ifdef HAVE_OPENSSL -#include "Swiften/TLS/OpenSSL/OpenSSLContextFactory.h" -#include "Swiften/TLS/OpenSSL/OpenSSLCertificateFactory.h" +#include <Swiften/TLS/OpenSSL/OpenSSLContextFactory.h> +#include <Swiften/TLS/OpenSSL/OpenSSLCertificateFactory.h> #endif namespace Swift { diff --git a/Swiften/TLS/ServerIdentityVerifier.cpp b/Swiften/TLS/ServerIdentityVerifier.cpp index d7b0580..7c68774 100644 --- a/Swiften/TLS/ServerIdentityVerifier.cpp +++ b/Swiften/TLS/ServerIdentityVerifier.cpp @@ -4,12 +4,12 @@ * See Documentation/Licenses/GPLv3.txt for more information. */ -#include "Swiften/TLS/ServerIdentityVerifier.h" +#include <Swiften/TLS/ServerIdentityVerifier.h> #include <boost/algorithm/string.hpp> -#include "Swiften/Base/foreach.h" -#include "Swiften/IDN/IDNA.h" +#include <Swiften/Base/foreach.h> +#include <Swiften/IDN/IDNA.h> namespace Swift { diff --git a/Swiften/TLS/ServerIdentityVerifier.h b/Swiften/TLS/ServerIdentityVerifier.h index 05bb5f0..c1abd5e 100644 --- a/Swiften/TLS/ServerIdentityVerifier.h +++ b/Swiften/TLS/ServerIdentityVerifier.h @@ -9,8 +9,8 @@ #include <boost/shared_ptr.hpp> #include <string> -#include "Swiften/JID/JID.h" -#include "Swiften/TLS/Certificate.h" +#include <Swiften/JID/JID.h> +#include <Swiften/TLS/Certificate.h> namespace Swift { class ServerIdentityVerifier { diff --git a/Swiften/TLS/SimpleCertificate.h b/Swiften/TLS/SimpleCertificate.h index a81a23e..4cf0cc2 100644 --- a/Swiften/TLS/SimpleCertificate.h +++ b/Swiften/TLS/SimpleCertificate.h @@ -7,7 +7,7 @@ #pragma once #include <string> -#include "Swiften/TLS/Certificate.h" +#include <Swiften/TLS/Certificate.h> namespace Swift { class SimpleCertificate : public Certificate { diff --git a/Swiften/TLS/TLSContext.cpp b/Swiften/TLS/TLSContext.cpp index 008bfc0..026ae70 100644 --- a/Swiften/TLS/TLSContext.cpp +++ b/Swiften/TLS/TLSContext.cpp @@ -4,7 +4,7 @@ * See Documentation/Licenses/GPLv3.txt for more information. */ -#include "Swiften/TLS/TLSContext.h" +#include <Swiften/TLS/TLSContext.h> namespace Swift { diff --git a/Swiften/TLS/TLSContext.h b/Swiften/TLS/TLSContext.h index 1279eeb..68926c2 100644 --- a/Swiften/TLS/TLSContext.h +++ b/Swiften/TLS/TLSContext.h @@ -6,12 +6,12 @@ #pragma once -#include "Swiften/Base/boost_bsignals.h" +#include <Swiften/Base/boost_bsignals.h> #include <boost/shared_ptr.hpp> -#include "Swiften/Base/ByteArray.h" -#include "Swiften/TLS/Certificate.h" -#include "Swiften/TLS/CertificateVerificationError.h" +#include <Swiften/Base/ByteArray.h> +#include <Swiften/TLS/Certificate.h> +#include <Swiften/TLS/CertificateVerificationError.h> namespace Swift { class PKCS12Certificate; diff --git a/Swiften/TLS/TLSContextFactory.cpp b/Swiften/TLS/TLSContextFactory.cpp index 47b529f..eb02f0c 100644 --- a/Swiften/TLS/TLSContextFactory.cpp +++ b/Swiften/TLS/TLSContextFactory.cpp @@ -4,7 +4,7 @@ * See Documentation/Licenses/GPLv3.txt for more information. */ -#include "Swiften/TLS/TLSContextFactory.h" +#include <Swiften/TLS/TLSContextFactory.h> namespace Swift { diff --git a/Swiften/TLS/UnitTest/ServerIdentityVerifierTest.cpp b/Swiften/TLS/UnitTest/ServerIdentityVerifierTest.cpp index 5234445..bd68c84 100644 --- a/Swiften/TLS/UnitTest/ServerIdentityVerifierTest.cpp +++ b/Swiften/TLS/UnitTest/ServerIdentityVerifierTest.cpp @@ -4,14 +4,14 @@ * See Documentation/Licenses/GPLv3.txt for more information. */ -#include "Swiften/Base/ByteArray.h" +#include <Swiften/Base/ByteArray.h> #include <cppunit/extensions/HelperMacros.h> #include <cppunit/extensions/TestFactoryRegistry.h> #include <vector> -#include "Swiften/TLS/ServerIdentityVerifier.h" -#include "Swiften/TLS/SimpleCertificate.h" +#include <Swiften/TLS/ServerIdentityVerifier.h> +#include <Swiften/TLS/SimpleCertificate.h> using namespace Swift; diff --git a/Swiften/VCards/GetVCardRequest.h b/Swiften/VCards/GetVCardRequest.h index 93e4871..dc65773 100644 --- a/Swiften/VCards/GetVCardRequest.h +++ b/Swiften/VCards/GetVCardRequest.h @@ -6,8 +6,8 @@ #pragma once -#include "Swiften/Queries/GenericRequest.h" -#include "Swiften/Elements/VCard.h" +#include <Swiften/Queries/GenericRequest.h> +#include <Swiften/Elements/VCard.h> namespace Swift { diff --git a/Swiften/VCards/SConscript b/Swiften/VCards/SConscript index e980ba3..c20c17d 100644 --- a/Swiften/VCards/SConscript +++ b/Swiften/VCards/SConscript @@ -3,6 +3,5 @@ Import("swiften_env") objects = swiften_env.SwiftenObject([ "VCardManager.cpp", "VCardStorage.cpp", - "VCardFileStorage.cpp", ]) swiften_env.Append(SWIFTEN_OBJECTS = [objects]) diff --git a/Swiften/VCards/UnitTest/VCardManagerTest.cpp b/Swiften/VCards/UnitTest/VCardManagerTest.cpp index 9274639..687442b 100644 --- a/Swiften/VCards/UnitTest/VCardManagerTest.cpp +++ b/Swiften/VCards/UnitTest/VCardManagerTest.cpp @@ -4,7 +4,7 @@ * See Documentation/Licenses/GPLv3.txt for more information. */ -#include "Swiften/Base/ByteArray.h" +#include <Swiften/Base/ByteArray.h> #include <cppunit/extensions/HelperMacros.h> #include <cppunit/extensions/TestFactoryRegistry.h> @@ -12,10 +12,10 @@ #include <boost/bind.hpp> #include <boost/smart_ptr/make_shared.hpp> -#include "Swiften/VCards/VCardManager.h" -#include "Swiften/VCards/VCardMemoryStorage.h" -#include "Swiften/Queries/IQRouter.h" -#include "Swiften/Client/DummyStanzaChannel.h" +#include <Swiften/VCards/VCardManager.h> +#include <Swiften/VCards/VCardMemoryStorage.h> +#include <Swiften/Queries/IQRouter.h> +#include <Swiften/Client/DummyStanzaChannel.h> using namespace Swift; diff --git a/Swiften/VCards/VCardManager.cpp b/Swiften/VCards/VCardManager.cpp index b9602ab..52447a1 100644 --- a/Swiften/VCards/VCardManager.cpp +++ b/Swiften/VCards/VCardManager.cpp @@ -4,13 +4,13 @@ * See Documentation/Licenses/GPLv3.txt for more information. */ -#include "Swiften/VCards/VCardManager.h" +#include <Swiften/VCards/VCardManager.h> #include <boost/bind.hpp> -#include "Swiften/JID/JID.h" -#include "Swiften/VCards/VCardStorage.h" -#include "Swiften/VCards/GetVCardRequest.h" +#include <Swiften/JID/JID.h> +#include <Swiften/VCards/VCardStorage.h> +#include <Swiften/VCards/GetVCardRequest.h> namespace Swift { diff --git a/Swiften/VCards/VCardManager.h b/Swiften/VCards/VCardManager.h index 1dd16ae..29fe32c 100644 --- a/Swiften/VCards/VCardManager.h +++ b/Swiften/VCards/VCardManager.h @@ -8,9 +8,9 @@ #include <set> -#include "Swiften/JID/JID.h" -#include "Swiften/Elements/VCard.h" -#include "Swiften/Elements/ErrorPayload.h" +#include <Swiften/JID/JID.h> +#include <Swiften/Elements/VCard.h> +#include <Swiften/Elements/ErrorPayload.h> #include <Swiften/VCards/SetVCardRequest.h> #include <Swiften/Base/boost_bsignals.h> diff --git a/Swiften/VCards/VCardMemoryStorage.h b/Swiften/VCards/VCardMemoryStorage.h index b2e99c6..ade9c89 100644 --- a/Swiften/VCards/VCardMemoryStorage.h +++ b/Swiften/VCards/VCardMemoryStorage.h @@ -9,8 +9,8 @@ #include <boost/shared_ptr.hpp> #include <map> -#include "Swiften/JID/JID.h" -#include "Swiften/VCards/VCardStorage.h" +#include <Swiften/JID/JID.h> +#include <Swiften/VCards/VCardStorage.h> namespace Swift { class VCardMemoryStorage : public VCardStorage { diff --git a/Swiften/VCards/VCardStorage.cpp b/Swiften/VCards/VCardStorage.cpp index b14ee60..6868813 100644 --- a/Swiften/VCards/VCardStorage.cpp +++ b/Swiften/VCards/VCardStorage.cpp @@ -4,7 +4,7 @@ * See Documentation/Licenses/GPLv3.txt for more information. */ -#include "Swiften/VCards/VCardStorage.h" +#include <Swiften/VCards/VCardStorage.h> #include <Swiften/StringCodecs/Hexify.h> #include <Swiften/StringCodecs/SHA1.h> diff --git a/Swiftob/Commands.cpp b/Swiftob/Commands.cpp index e39d23e..cf24196 100644 --- a/Swiftob/Commands.cpp +++ b/Swiftob/Commands.cpp @@ -4,8 +4,9 @@ * See Documentation/Licenses/GPLv3.txt for more information. */ -#include "Swiftob/Commands.h" +#include <Swiftob/Commands.h> +#include <Swiften/Base/foreach.h> #include <iostream> #include <boost/bind.hpp> diff --git a/Swiftob/Commands.h b/Swiftob/Commands.h index e11078d..8423252 100644 --- a/Swiftob/Commands.h +++ b/Swiftob/Commands.h @@ -12,8 +12,8 @@ #include <Swiften/Base/boost_bsignals.h> #include <Swiften/Elements/Message.h> -#include "Swiftob/Users.h" -#include "Swiftob/MUCs.h" +#include <Swiftob/Users.h> +#include <Swiftob/MUCs.h> namespace Swift { class Client; diff --git a/Swiftob/LuaCommands.cpp b/Swiftob/LuaCommands.cpp index 7be818e..9f99d82 100644 --- a/Swiftob/LuaCommands.cpp +++ b/Swiftob/LuaCommands.cpp @@ -4,16 +4,18 @@ * See Documentation/Licenses/GPLv3.txt for more information. */ -#include "Swiftob/LuaCommands.h" +#include <Swiftob/LuaCommands.h> #include <boost/bind.hpp> #include <vector> #include <algorithm> +#include <iostream> +#include <Swiften/Base/foreach.h> #include <Swiften/Client/Client.h> #include <Swiften/Network/TimerFactory.h> -#include "Swiftob/Commands.h" +#include <Swiftob/Commands.h> #define LUA_COMMANDS "__Lua_Commands" #define STORAGE "__Storage" diff --git a/Swiftob/LuaCommands.h b/Swiftob/LuaCommands.h index dc8e36e..fc743ca 100644 --- a/Swiftob/LuaCommands.h +++ b/Swiftob/LuaCommands.h @@ -9,21 +9,18 @@ #include <string> #include <vector> -extern "C" { #include <lua.h> #include <lauxlib.h> #include <lualib.h> -} - #include <boost/filesystem/fstream.hpp> #include <boost/noncopyable.hpp> -#include "Swiften/Network/NetworkFactories.h" +#include <Swiften/Network/NetworkFactories.h> #include <Swiften/Elements/SoftwareVersion.h> #include <Swiften/Queries/Requests/GetSoftwareVersionRequest.h> #include <Swiften/Network/Timer.h> -#include "Swiftob/Commands.h" -#include "Swiftob/Storage.h" +#include <Swiftob/Commands.h> +#include <Swiftob/Storage.h> using namespace Swift; /** diff --git a/Swiftob/MUCs.cpp b/Swiftob/MUCs.cpp index 55bf313..695cbd9 100644 --- a/Swiftob/MUCs.cpp +++ b/Swiftob/MUCs.cpp @@ -4,14 +4,18 @@ * See Documentation/Licenses/GPLv3.txt for more information. */ -#include "Swiftob/MUCs.h" +#include <Swiftob/MUCs.h> +#include <boost/bind.hpp> +#include <boost/date_time/posix_time/posix_time.hpp> + +#include <Swiften/Base/foreach.h> #include <Swiften/Client/Client.h> #include <Swiften/MUC/MUC.h> #include <Swiften/MUC/MUCManager.h> #include <Swiften/Base/String.h> -#include "Swiftob/Storage.h" +#include <Swiftob/Storage.h> #define MUC_LIST_SETTING "muc_list" diff --git a/Swiftob/SConscript b/Swiftob/SConscript index 3928ff0..e955a22 100644 --- a/Swiftob/SConscript +++ b/Swiftob/SConscript @@ -14,7 +14,7 @@ if env["SCONS_STAGE"] == "build": myenv.MergeFlags(myenv["PLATFORM_FLAGS"]) myenv.MergeFlags(myenv.get("LUA_FLAGS", {})) sources = [ - "linit.c", # This is horrible! + "linit.cpp", "Swiftob.cpp", "Users.cpp", "Commands.cpp", diff --git a/Swiftob/Storage.cpp b/Swiftob/Storage.cpp index 0cf16d7..aac720c 100644 --- a/Swiftob/Storage.cpp +++ b/Swiftob/Storage.cpp @@ -4,7 +4,7 @@ * See Documentation/Licenses/GPLv3.txt for more information. */ -#include "Swiftob/Storage.h" +#include <Swiftob/Storage.h> #include <Swiften/Base/String.h> #include <Swiften/Base/ByteArray.h> diff --git a/Swiftob/Swiftob.cpp b/Swiftob/Swiftob.cpp index 6c6dad0..10f7104 100644 --- a/Swiftob/Swiftob.cpp +++ b/Swiftob/Swiftob.cpp @@ -4,7 +4,7 @@ * See Documentation/Licenses/GPLv3.txt for more information. */ -#include "Swiftob/Swiftob.h" +#include <Swiftob/Swiftob.h> #include <string> #include <iostream> @@ -14,8 +14,8 @@ #include <Swiften/Base/String.h> #include <Swiften/Presence/PresenceSender.h> -#include "Swiftob/Users.h" -#include "Swiftob/Storage.h" +#include <Swiftob/Users.h> +#include <Swiftob/Storage.h> po::options_description Swiftob::getOptionsDescription() { diff --git a/Swiftob/Swiftob.h b/Swiftob/Swiftob.h index 45061d0..ad4e9b8 100644 --- a/Swiftob/Swiftob.h +++ b/Swiftob/Swiftob.h @@ -18,8 +18,8 @@ #include <Swiften/Client/Client.h> #include <Swiften/Network/BoostNetworkFactories.h> -#include "Swiftob/Commands.h" -#include "Swiftob/LuaCommands.h" +#include <Swiftob/Commands.h> +#include <Swiftob/LuaCommands.h> namespace po = boost::program_options; diff --git a/Swiftob/Users.cpp b/Swiftob/Users.cpp index 55ba4eb..09173cc 100644 --- a/Swiftob/Users.cpp +++ b/Swiftob/Users.cpp @@ -4,13 +4,14 @@ * See Documentation/Licenses/GPLv3.txt for more information. */ -#include "Swiftob/Users.h" +#include <Swiftob/Users.h> #include <iostream> +#include <Swiften/Base/foreach.h> #include <Swiften/Client/Client.h> -#include "Swiftob/MUCs.h" +#include <Swiftob/MUCs.h> Users::Users(Client* client, MUCs* mucs) { client_ = client; diff --git a/Swiftob/linit.c b/Swiftob/linit.cpp index 13c5b09..13c5b09 100644 --- a/Swiftob/linit.c +++ b/Swiftob/linit.cpp |