From e746ca6970bea80ec9b5ae79dda8f6332254e301 Mon Sep 17 00:00:00 2001 From: Vitaly Takmazov Date: Sat, 16 Jan 2016 16:43:43 +0300 Subject: moved to Gradle --- .gitignore | 2 +- .gitmodules | 12 + build.gradle | 70 ++ build.xml | 74 -- deps/com.juick | 1 + deps/com.juick.json | 1 + deps/com.juick.server | 1 + deps/com.juick.xmpp | 1 + gradle/wrapper/gradle-wrapper.jar | Bin 0 -> 53637 bytes gradle/wrapper/gradle-wrapper.properties | 6 + gradlew | 160 +++ gradlew.bat | 90 ++ lib/org.json.jar | Bin 80177 -> 0 bytes lib/xpp3_min-1.1.4.jar | Bin 24955 -> 0 bytes manifest.mf | 3 - nbproject/build-impl.xml | 1089 -------------------- nbproject/genfiles.properties | 8 - nbproject/project.properties | 88 -- nbproject/project.xml | 50 - settings.gradle | 1 + src/com/juick/jabber/ws/Main.java | 68 -- src/com/juick/jabber/ws/SocketSubscribed.java | 51 - src/com/juick/jabber/ws/WSConnections.java | 44 - src/com/juick/jabber/ws/WSData.java | 276 ----- src/com/juick/jabber/ws/WSKeepAlive.java | 102 -- src/com/juick/jabber/ws/XMPPConnection.java | 166 --- src/main/java/com/juick/jabber/ws/Main.java | 68 ++ .../java/com/juick/jabber/ws/SocketSubscribed.java | 51 + .../java/com/juick/jabber/ws/WSConnections.java | 44 + src/main/java/com/juick/jabber/ws/WSData.java | 276 +++++ src/main/java/com/juick/jabber/ws/WSKeepAlive.java | 102 ++ .../java/com/juick/jabber/ws/XMPPConnection.java | 166 +++ 32 files changed, 1051 insertions(+), 2020 deletions(-) create mode 100644 .gitmodules create mode 100644 build.gradle delete mode 100644 build.xml create mode 160000 deps/com.juick create mode 160000 deps/com.juick.json create mode 160000 deps/com.juick.server create mode 160000 deps/com.juick.xmpp create mode 100644 gradle/wrapper/gradle-wrapper.jar create mode 100644 gradle/wrapper/gradle-wrapper.properties create mode 100755 gradlew create mode 100644 gradlew.bat delete mode 100644 lib/org.json.jar delete mode 100644 lib/xpp3_min-1.1.4.jar delete mode 100644 manifest.mf delete mode 100644 nbproject/build-impl.xml delete mode 100644 nbproject/genfiles.properties delete mode 100644 nbproject/project.properties delete mode 100644 nbproject/project.xml create mode 100644 settings.gradle delete mode 100644 src/com/juick/jabber/ws/Main.java delete mode 100644 src/com/juick/jabber/ws/SocketSubscribed.java delete mode 100644 src/com/juick/jabber/ws/WSConnections.java delete mode 100644 src/com/juick/jabber/ws/WSData.java delete mode 100644 src/com/juick/jabber/ws/WSKeepAlive.java delete mode 100644 src/com/juick/jabber/ws/XMPPConnection.java create mode 100644 src/main/java/com/juick/jabber/ws/Main.java create mode 100644 src/main/java/com/juick/jabber/ws/SocketSubscribed.java create mode 100644 src/main/java/com/juick/jabber/ws/WSConnections.java create mode 100644 src/main/java/com/juick/jabber/ws/WSData.java create mode 100644 src/main/java/com/juick/jabber/ws/WSKeepAlive.java create mode 100644 src/main/java/com/juick/jabber/ws/XMPPConnection.java diff --git a/.gitignore b/.gitignore index 315ea15c..e3baf212 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,3 @@ /dist/ /build/ -/nbproject/private/ \ No newline at end of file +.gradle/* diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 00000000..e94e84e4 --- /dev/null +++ b/.gitmodules @@ -0,0 +1,12 @@ +[submodule "deps/com.juick.server"] + path = deps/com.juick.server + url = ssh://den.jabber.ru:2205/var/lib/git/com.juick.server.git +[submodule "deps/com.juick.xmpp"] + path = deps/com.juick.xmpp + url = ssh://den.jabber.ru:2205/var/lib/git/com.juick.xmpp.git +[submodule "deps/com.juick"] + path = deps/com.juick + url = ssh://den.jabber.ru:2205/var/lib/git/com.juick.git +[submodule "deps/com.juick.json"] + path = deps/com.juick.json + url = ssh://den.jabber.ru:2205/var/lib/git/com.juick.json.git diff --git a/build.gradle b/build.gradle new file mode 100644 index 00000000..0091459a --- /dev/null +++ b/build.gradle @@ -0,0 +1,70 @@ +subprojects { + apply plugin: 'java' + repositories { + mavenCentral() + } +} + +buildscript { + repositories { + mavenCentral() + jcenter() + } + dependencies { + classpath 'com.bmuschko:gradle-tomcat-plugin:2.2.+' + classpath 'com.tkruse.gradle:gradle-groovysh-plugin:1.0.7' + } +} + +apply plugin: 'java' +apply plugin: 'war' +apply plugin: 'com.bmuschko.tomcat' +apply plugin: 'com.github.tkruse.groovysh' + +repositories { + mavenCentral() +} + +def core = project(':deps:com.juick') +def server = project(':deps:com.juick.server') +def xmpp = project(':deps:com.juick.xmpp') +def json = project(':deps:com.juick.json') +project(':deps:com.juick.server') { + dependencies { + compile core + } +} + +project(':deps:com.juick.xmpp') { + dependencies { + compile core + } +} + +project(':deps:com.juick.json') { + dependencies { + compile core + } +} + +dependencies { + compile core + compile server + compile xmpp + compile json + compile "org.springframework:spring-jdbc:4.2.4.RELEASE" + providedCompile 'javax.servlet:javax.servlet-api:3.1.0' + def tomcatVersion = '7.0.+' + tomcat "org.apache.tomcat.embed:tomcat-embed-core:${tomcatVersion}", + "org.apache.tomcat.embed:tomcat-embed-logging-juli:${tomcatVersion}", + "org.apache.tomcat.embed:tomcat-embed-jasper:${tomcatVersion}" + testCompile 'junit:junit:4.12' + runtime 'mysql:mysql-connector-java:5.1.37' +} + +compileJava.options.encoding = 'UTF-8' + +tomcat { + httpPort = 8080 + contextPath = '/' +} diff --git a/build.xml b/build.xml deleted file mode 100644 index c7a42b44..00000000 --- a/build.xml +++ /dev/null @@ -1,74 +0,0 @@ - - - - - - - - - - - Builds, tests, and runs the project com.juick.jabber.ws. - - - diff --git a/deps/com.juick b/deps/com.juick new file mode 160000 index 00000000..1df19b47 --- /dev/null +++ b/deps/com.juick @@ -0,0 +1 @@ +Subproject commit 1df19b47f7f463e6cafa7dcf877cb42967fff166 diff --git a/deps/com.juick.json b/deps/com.juick.json new file mode 160000 index 00000000..ee0e13e7 --- /dev/null +++ b/deps/com.juick.json @@ -0,0 +1 @@ +Subproject commit ee0e13e7243abecf242236c224551774195524a3 diff --git a/deps/com.juick.server b/deps/com.juick.server new file mode 160000 index 00000000..96188f8d --- /dev/null +++ b/deps/com.juick.server @@ -0,0 +1 @@ +Subproject commit 96188f8d8a31df2474bf0eaf7a91773280ddccb6 diff --git a/deps/com.juick.xmpp b/deps/com.juick.xmpp new file mode 160000 index 00000000..1f08c012 --- /dev/null +++ b/deps/com.juick.xmpp @@ -0,0 +1 @@ +Subproject commit 1f08c01254fcbca79d1571ebb1ed2d68f86b8503 diff --git a/gradle/wrapper/gradle-wrapper.jar b/gradle/wrapper/gradle-wrapper.jar new file mode 100644 index 00000000..05ef575b Binary files /dev/null and b/gradle/wrapper/gradle-wrapper.jar differ diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties new file mode 100644 index 00000000..65a9525c --- /dev/null +++ b/gradle/wrapper/gradle-wrapper.properties @@ -0,0 +1,6 @@ +#Thu Oct 29 12:36:21 MSK 2015 +distributionBase=GRADLE_USER_HOME +distributionPath=wrapper/dists +zipStoreBase=GRADLE_USER_HOME +zipStorePath=wrapper/dists +distributionUrl=https\://services.gradle.org/distributions/gradle-2.8-all.zip diff --git a/gradlew b/gradlew new file mode 100755 index 00000000..9d82f789 --- /dev/null +++ b/gradlew @@ -0,0 +1,160 @@ +#!/usr/bin/env bash + +############################################################################## +## +## Gradle start up script for UN*X +## +############################################################################## + +# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +DEFAULT_JVM_OPTS="" + +APP_NAME="Gradle" +APP_BASE_NAME=`basename "$0"` + +# Use the maximum available, or set MAX_FD != -1 to use that value. +MAX_FD="maximum" + +warn ( ) { + echo "$*" +} + +die ( ) { + echo + echo "$*" + echo + exit 1 +} + +# OS specific support (must be 'true' or 'false'). +cygwin=false +msys=false +darwin=false +case "`uname`" in + CYGWIN* ) + cygwin=true + ;; + Darwin* ) + darwin=true + ;; + MINGW* ) + msys=true + ;; +esac + +# Attempt to set APP_HOME +# Resolve links: $0 may be a link +PRG="$0" +# Need this for relative symlinks. +while [ -h "$PRG" ] ; do + ls=`ls -ld "$PRG"` + link=`expr "$ls" : '.*-> \(.*\)$'` + if expr "$link" : '/.*' > /dev/null; then + PRG="$link" + else + PRG=`dirname "$PRG"`"/$link" + fi +done +SAVED="`pwd`" +cd "`dirname \"$PRG\"`/" >/dev/null +APP_HOME="`pwd -P`" +cd "$SAVED" >/dev/null + +CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar + +# Determine the Java command to use to start the JVM. +if [ -n "$JAVA_HOME" ] ; then + if [ -x "$JAVA_HOME/jre/sh/java" ] ; then + # IBM's JDK on AIX uses strange locations for the executables + JAVACMD="$JAVA_HOME/jre/sh/java" + else + JAVACMD="$JAVA_HOME/bin/java" + fi + if [ ! -x "$JAVACMD" ] ; then + die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." + fi +else + JAVACMD="java" + which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." +fi + +# Increase the maximum file descriptors if we can. +if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then + MAX_FD_LIMIT=`ulimit -H -n` + if [ $? -eq 0 ] ; then + if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then + MAX_FD="$MAX_FD_LIMIT" + fi + ulimit -n $MAX_FD + if [ $? -ne 0 ] ; then + warn "Could not set maximum file descriptor limit: $MAX_FD" + fi + else + warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" + fi +fi + +# For Darwin, add options to specify how the application appears in the dock +if $darwin; then + GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" +fi + +# For Cygwin, switch paths to Windows format before running java +if $cygwin ; then + APP_HOME=`cygpath --path --mixed "$APP_HOME"` + CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` + JAVACMD=`cygpath --unix "$JAVACMD"` + + # We build the pattern for arguments to be converted via cygpath + ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` + SEP="" + for dir in $ROOTDIRSRAW ; do + ROOTDIRS="$ROOTDIRS$SEP$dir" + SEP="|" + done + OURCYGPATTERN="(^($ROOTDIRS))" + # Add a user-defined pattern to the cygpath arguments + if [ "$GRADLE_CYGPATTERN" != "" ] ; then + OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" + fi + # Now convert the arguments - kludge to limit ourselves to /bin/sh + i=0 + for arg in "$@" ; do + CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` + CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option + + if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition + eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` + else + eval `echo args$i`="\"$arg\"" + fi + i=$((i+1)) + done + case $i in + (0) set -- ;; + (1) set -- "$args0" ;; + (2) set -- "$args0" "$args1" ;; + (3) set -- "$args0" "$args1" "$args2" ;; + (4) set -- "$args0" "$args1" "$args2" "$args3" ;; + (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; + (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; + (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; + (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; + (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; + esac +fi + +# Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules +function splitJvmOpts() { + JVM_OPTS=("$@") +} +eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS +JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME" + +exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@" diff --git a/gradlew.bat b/gradlew.bat new file mode 100644 index 00000000..aec99730 --- /dev/null +++ b/gradlew.bat @@ -0,0 +1,90 @@ +@if "%DEBUG%" == "" @echo off +@rem ########################################################################## +@rem +@rem Gradle startup script for Windows +@rem +@rem ########################################################################## + +@rem Set local scope for the variables with windows NT shell +if "%OS%"=="Windows_NT" setlocal + +@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +set DEFAULT_JVM_OPTS= + +set DIRNAME=%~dp0 +if "%DIRNAME%" == "" set DIRNAME=. +set APP_BASE_NAME=%~n0 +set APP_HOME=%DIRNAME% + +@rem Find java.exe +if defined JAVA_HOME goto findJavaFromJavaHome + +set JAVA_EXE=java.exe +%JAVA_EXE% -version >NUL 2>&1 +if "%ERRORLEVEL%" == "0" goto init + +echo. +echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:findJavaFromJavaHome +set JAVA_HOME=%JAVA_HOME:"=% +set JAVA_EXE=%JAVA_HOME%/bin/java.exe + +if exist "%JAVA_EXE%" goto init + +echo. +echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:init +@rem Get command-line arguments, handling Windowz variants + +if not "%OS%" == "Windows_NT" goto win9xME_args +if "%@eval[2+2]" == "4" goto 4NT_args + +:win9xME_args +@rem Slurp the command line arguments. +set CMD_LINE_ARGS= +set _SKIP=2 + +:win9xME_args_slurp +if "x%~1" == "x" goto execute + +set CMD_LINE_ARGS=%* +goto execute + +:4NT_args +@rem Get arguments from the 4NT Shell from JP Software +set CMD_LINE_ARGS=%$ + +:execute +@rem Setup the command line + +set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar + +@rem Execute Gradle +"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% + +:end +@rem End local scope for the variables with windows NT shell +if "%ERRORLEVEL%"=="0" goto mainEnd + +:fail +rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of +rem the _cmd.exe /c_ return code! +if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 +exit /b 1 + +:mainEnd +if "%OS%"=="Windows_NT" endlocal + +:omega diff --git a/lib/org.json.jar b/lib/org.json.jar deleted file mode 100644 index 911ca8f1..00000000 Binary files a/lib/org.json.jar and /dev/null differ diff --git a/lib/xpp3_min-1.1.4.jar b/lib/xpp3_min-1.1.4.jar deleted file mode 100644 index e02ea412..00000000 Binary files a/lib/xpp3_min-1.1.4.jar and /dev/null differ diff --git a/manifest.mf b/manifest.mf deleted file mode 100644 index 328e8e5b..00000000 --- a/manifest.mf +++ /dev/null @@ -1,3 +0,0 @@ -Manifest-Version: 1.0 -X-COMMENT: Main-Class will be added automatically by build - diff --git a/nbproject/build-impl.xml b/nbproject/build-impl.xml deleted file mode 100644 index 06162daf..00000000 --- a/nbproject/build-impl.xml +++ /dev/null @@ -1,1089 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Must set src.dir - Must set build.dir - Must set dist.dir - Must set build.classes.dir - Must set dist.javadoc.dir - Must set build.test.classes.dir - Must set build.test.results.dir - Must set build.classes.excludes - Must set dist.jar - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Must set javac.includes - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Must set JVM to use for profiling in profiler.info.jvm - Must set profiler agent JVM arguments in profiler.info.jvmargs.agent - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Must select some files in the IDE or set javac.includes - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - To run this application from the command line without Ant, try: - - - - - - - java -cp "${run.classpath.with.dist.jar}" ${main.class} - - - - - - - - - - - - - - - - - - - - - - - - - To run this application from the command line without Ant, try: - - java -jar "${dist.jar.resolved}" - - - - - - - - - - - - - - - - - - - - - - - - - Must select one file in the IDE or set run.class - - - - Must select one file in the IDE or set run.class - - - - - - - - - - - - - - - - - - - - - - - Must select one file in the IDE or set debug.class - - - - - Must select one file in the IDE or set debug.class - - - - - Must set fix.includes - - - - - - - - - - - - - - - - - Must select one file in the IDE or set profile.class - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Must select some files in the IDE or set javac.includes - - - - - - - - - - - - - - - - - - Some tests failed; see details above. - - - - - - - - - Must select some files in the IDE or set test.includes - - - - Some tests failed; see details above. - - - - - Must select one file in the IDE or set test.class - - - - - - - - - - - - - - - - - - - - - - - - - - - Must select one file in the IDE or set applet.url - - - - - - - - - Must select one file in the IDE or set applet.url - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/nbproject/genfiles.properties b/nbproject/genfiles.properties deleted file mode 100644 index 8b83736c..00000000 --- a/nbproject/genfiles.properties +++ /dev/null @@ -1,8 +0,0 @@ -build.xml.data.CRC32=68cbdaea -build.xml.script.CRC32=2ec0c6a9 -build.xml.stylesheet.CRC32=28e38971@1.44.1.45 -# This file is used by a NetBeans-based IDE to track changes in generated files such as build-impl.xml. -# Do not edit this file. You may delete it but then the IDE will never regenerate such files for you. -nbproject/build-impl.xml.data.CRC32=68cbdaea -nbproject/build-impl.xml.script.CRC32=e6ac4bc8 -nbproject/build-impl.xml.stylesheet.CRC32=0ae3a408@1.44.1.45 diff --git a/nbproject/project.properties b/nbproject/project.properties deleted file mode 100644 index e6b5db4c..00000000 --- a/nbproject/project.properties +++ /dev/null @@ -1,88 +0,0 @@ -annotation.processing.enabled=true -annotation.processing.enabled.in.editor=false -annotation.processing.run.all.processors=true -annotation.processing.source.output=${build.generated.sources.dir}/ap-source-output -application.title=com.juick.jabber.ws -application.vendor=ugnich -build.classes.dir=${build.dir}/classes -build.classes.excludes=**/*.java,**/*.form -# This directory is removed when the project is cleaned: -build.dir=build -build.generated.dir=${build.dir}/generated -build.generated.sources.dir=${build.dir}/generated-sources -# Only compile against the classpath explicitly listed here: -build.sysclasspath=ignore -build.test.classes.dir=${build.dir}/test/classes -build.test.results.dir=${build.dir}/test/results -# Uncomment to specify the preferred debugger connection transport: -#debug.transport=dt_socket -debug.classpath=\ - ${run.classpath} -debug.test.classpath=\ - ${run.test.classpath} -# This directory is removed when the project is cleaned: -dist.dir=dist -dist.jar=${dist.dir}/com.juick.jabber.ws.jar -dist.javadoc.dir=${dist.dir}/javadoc -endorsed.classpath= -excludes= -file.reference.org.json.jar=lib/org.json.jar -file.reference.xpp3_min-1.1.4.jar=lib/xpp3_min-1.1.4.jar -includes=** -jar.compress=false -javac.classpath=\ - ${reference.com_juick_xmpp.jar}:\ - ${reference.com_juick_server.jar}:\ - ${reference.com_juick_json.jar}:\ - ${reference.com_juick.jar}:\ - ${libs.MySQLDriver.classpath}:\ - ${file.reference.org.json.jar}:\ - ${file.reference.xpp3_min-1.1.4.jar} -# Space-separated list of extra javac options -javac.compilerargs= -javac.deprecation=false -javac.processorpath=\ - ${javac.classpath} -javac.source=1.6 -javac.target=1.6 -javac.test.classpath=\ - ${javac.classpath}:\ - ${build.classes.dir} -javac.test.processorpath=\ - ${javac.test.classpath} -javadoc.additionalparam= -javadoc.author=false -javadoc.encoding=${source.encoding} -javadoc.noindex=false -javadoc.nonavbar=false -javadoc.notree=false -javadoc.private=false -javadoc.splitindex=true -javadoc.use=true -javadoc.version=false -javadoc.windowtitle= -main.class=com.juick.jabber.ws.Main -manifest.file=manifest.mf -meta.inf.dir=${src.dir}/META-INF -mkdist.disabled=false -platform.active=default_platform -project.com_juick=../com.juick -project.com_juick_json=../com.juick.json -project.com_juick_server=../com.juick.server -project.com_juick_xmpp=../com.juick.xmpp -reference.com_juick.jar=${project.com_juick}/dist/com.juick.jar -reference.com_juick_json.jar=${project.com_juick_json}/dist/com.juick.json.jar -reference.com_juick_server.jar=${project.com_juick_server}/dist/com.juick.server.jar -reference.com_juick_xmpp.jar=${project.com_juick_xmpp}/dist/com.juick.xmpp.jar -run.classpath=\ - ${javac.classpath}:\ - ${build.classes.dir} -# Space-separated list of JVM arguments used when running the project -# (you may also define separate properties like run-sys-prop.name=value instead of -Dname=value -# or test-sys-prop.name=value to set system properties for unit tests): -run.jvmargs= -run.test.classpath=\ - ${javac.test.classpath}:\ - ${build.test.classes.dir} -source.encoding=UTF-8 -src.dir=src diff --git a/nbproject/project.xml b/nbproject/project.xml deleted file mode 100644 index 48bac001..00000000 --- a/nbproject/project.xml +++ /dev/null @@ -1,50 +0,0 @@ - - - org.netbeans.modules.java.j2seproject - - - com.juick.jabber.ws - - - - - - - - com_juick - jar - - jar - clean - jar - - - com_juick_json - jar - - jar - clean - jar - - - com_juick_server - jar - - jar - clean - jar - - - com_juick_xmpp - jar - - jar - clean - jar - - - - - - - diff --git a/settings.gradle b/settings.gradle new file mode 100644 index 00000000..56142dd6 --- /dev/null +++ b/settings.gradle @@ -0,0 +1 @@ +include ':deps:com.juick', ':deps:com.juick.json', ':deps:com.juick.server', ':deps:com.juick.xmpp' diff --git a/src/com/juick/jabber/ws/Main.java b/src/com/juick/jabber/ws/Main.java deleted file mode 100644 index a7aea543..00000000 --- a/src/com/juick/jabber/ws/Main.java +++ /dev/null @@ -1,68 +0,0 @@ -/* - * Juick - * Copyright (C) 2008-2011, Ugnich Anton - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ -package com.juick.jabber.ws; - -import java.io.FileInputStream; -import java.sql.Connection; -import java.sql.DriverManager; -import java.sql.SQLException; -import java.util.ArrayList; -import java.util.Properties; - -/** - * - * @author Ugnich Anton - */ -public class Main { - - Connection sql; - XMPPConnection xmpp; - public static String STATSFILE = null; - public final static ArrayList clients = new ArrayList(); - - public static void main(String[] args) { - new Main().start(); - } - - public void start() { - try { - Properties conf = new Properties(); - conf.load(new FileInputStream("/etc/juick/ws.conf")); - - STATSFILE = conf.getProperty("statsfile"); - - setupSql(conf.getProperty("mysql_username", ""), conf.getProperty("mysql_password", "")); - xmpp = new XMPPConnection(sql, conf.getProperty("xmpp_password", "")); - new Thread(xmpp).start(); - - //new Thread(new WSConnections()).start(); - new Thread(new WSData(sql)).start(); - new Thread(new WSKeepAlive(sql)).start(); - } catch (Exception e) { - System.err.println(e); - } - } - - public void setupSql(String username, String password) { - try { - sql = DriverManager.getConnection("jdbc:mysql://localhost/juick?autoReconnect=true&user=" + username + "&password=" + password); - } catch (SQLException e) { - System.err.println(e); - } - } -} \ No newline at end of file diff --git a/src/com/juick/jabber/ws/SocketSubscribed.java b/src/com/juick/jabber/ws/SocketSubscribed.java deleted file mode 100644 index 6144380c..00000000 --- a/src/com/juick/jabber/ws/SocketSubscribed.java +++ /dev/null @@ -1,51 +0,0 @@ -package com.juick.jabber.ws; - -import java.nio.ByteBuffer; -import java.nio.channels.SocketChannel; - -/** - * - * @author ugnich - */ -public class SocketSubscribed { - - public SocketChannel sock = null; - public String clientName = null; - public int VUID = 0; - public int UID = 0; - public int MID = 0; - public boolean allMessages = false; - public boolean allReplies = false; - public long tsConnected; - public long tsLastData; - - public SocketSubscribed(SocketChannel sock, String clientName, int VUID) { - this.sock = sock; - this.clientName = clientName; - this.VUID = VUID; - tsConnected = tsLastData = System.currentTimeMillis(); - } - - public boolean sendByteBuffer(ByteBuffer bb) { - boolean ret = false; - bb.rewind(); - try { - sock.write(bb); - ret = true; - } catch (Exception e) { - close(); - } - return ret; - } - - public void close() { - try { - sock.socket().close(); - } catch (Exception e) { - } - try { - sock.close(); - } catch (Exception e) { - } - } -} diff --git a/src/com/juick/jabber/ws/WSConnections.java b/src/com/juick/jabber/ws/WSConnections.java deleted file mode 100644 index 15fbe4e8..00000000 --- a/src/com/juick/jabber/ws/WSConnections.java +++ /dev/null @@ -1,44 +0,0 @@ -package com.juick.jabber.ws; - -import java.net.InetSocketAddress; -import java.nio.channels.SelectionKey; -import java.nio.channels.Selector; -import java.nio.channels.ServerSocketChannel; -import java.nio.channels.SocketChannel; -import java.util.Iterator; - -/** - * - * @author ugnich - */ -public class WSConnections implements Runnable { - - Selector sel; - - @Override - public void run() { - try { - sel = Selector.open(); - ServerSocketChannel listensock = ServerSocketChannel.open(); - listensock.configureBlocking(false); - listensock.socket().bind(new InetSocketAddress(8081)); - listensock.register(sel, SelectionKey.OP_ACCEPT); - - while (true) { - sel.select(); - Iterator it = sel.selectedKeys().iterator(); - while (it.hasNext()) { - SelectionKey selKey = it.next(); - it.remove(); - ServerSocketChannel ssChannel = (ServerSocketChannel) selKey.channel(); - SocketChannel sChannel = ssChannel.accept(); - sChannel.configureBlocking(false); - sChannel.register(sel, SelectionKey.OP_READ); - System.out.println(sChannel.socket().getRemoteSocketAddress().toString() + " ACCEPTED"); - } - } - } catch (Exception e) { - System.err.println("WSConnections: " + e); - } - } -} diff --git a/src/com/juick/jabber/ws/WSData.java b/src/com/juick/jabber/ws/WSData.java deleted file mode 100644 index d77257e6..00000000 --- a/src/com/juick/jabber/ws/WSData.java +++ /dev/null @@ -1,276 +0,0 @@ -package com.juick.jabber.ws; - -import com.juick.server.MessagesQueries; -import com.juick.server.UserQueries; -import com.juick.xmpp.utils.Base64; -import java.io.IOException; -import java.net.InetSocketAddress; -import java.nio.ByteBuffer; -import java.nio.CharBuffer; -import java.nio.channels.SelectionKey; -import java.nio.channels.Selector; -import java.nio.channels.ServerSocketChannel; -import java.nio.channels.SocketChannel; -import java.nio.charset.Charset; -import java.security.MessageDigest; -import java.security.NoSuchAlgorithmException; -import java.sql.Connection; -import java.util.Iterator; - -/** - * - * @author ugnich - */ -public class WSData implements Runnable { - - static final String WEBSOCKET_GUID = "258EAFA5-E914-47DA-95CA-C5AB0DC85B11"; - Connection sql; - public Selector sel; - - public WSData(Connection sql) { - this.sql = sql; - } - - @Override - public void run() { - try { - sel = Selector.open(); - ServerSocketChannel listensock = ServerSocketChannel.open(); - listensock.configureBlocking(false); - listensock.socket().bind(new InetSocketAddress(8081)); - listensock.register(sel, SelectionKey.OP_ACCEPT); - - while (true) { - sel.select(); - Iterator it = sel.selectedKeys().iterator(); - while (it.hasNext()) { - SelectionKey selKey = it.next(); - it.remove(); - - if (selKey.isAcceptable()) { - ServerSocketChannel ssChannel = (ServerSocketChannel) selKey.channel(); - SocketChannel sChannel = ssChannel.accept(); - sChannel.configureBlocking(false); - sChannel.register(sel, SelectionKey.OP_READ); - System.out.println(sChannel.socket().getRemoteSocketAddress().toString() + " ACCEPTED"); - } else if (selKey.isReadable()) { - SocketChannel sChannel = (SocketChannel) selKey.channel(); - ByteBuffer buf = ByteBuffer.allocate(10240); - try { - int readbytes = sChannel.read(buf); - if (readbytes > 0) { - buf.flip(); - - CharBuffer charbuf = Charset.forName("ISO-8859-1").decode(buf); - System.out.println("DATA: " + charbuf.toString()); - buf.rewind(); - - switch (buf.get(0)) { - case (byte) 0x89: // PING - updateSocketTS(sChannel); - wsPing(sChannel); - break; - case (byte) 0x8A: // PONG - updateSocketTS(sChannel); - break; - case (byte) 0x81: // TEXT FRAME - updateSocketTS(sChannel); - wsTextFrame(sChannel, buf); - break; - case (byte) 'G': // HTTP - updateSocketTS(sChannel); - wsHandshake(sChannel, buf); - break; - case (byte) 0x88: // CONNECTION CLOSE - throw new IOException(sChannel.socket().getRemoteSocketAddress().toString() + " CONNECTION CLOSE"); - } - } else if (readbytes < 0) { - throw new IOException(sChannel.socket().getRemoteSocketAddress().toString() + " END OF STREAM"); - } - } catch (IOException e) { - System.err.println("WSData: " + e); - sChannel.socket().close(); - sChannel.close(); - selKey.cancel(); - } - } - } - } - } catch (Exception e) { - System.err.println("WSData: " + e); - } - } - - public void wsHandshake(SocketChannel sock, ByteBuffer buf) throws Exception { - String hOrigin = null; - String hHost = null; - String hLocation = null; - String hSecWebSocketKey = null; - String hSecWebSocketVersion = null; - String hXRealIP = null; - - buf.rewind(); - CharBuffer charbuf = Charset.forName("ISO-8859-1").decode(buf); - String headers[] = charbuf.toString().split("\r\n"); - for (int i = 0; i < headers.length; i++) { - String h[] = headers[i].split(" ", 2); - if (h.length == 2) { - if (h[0].equals("GET")) { - hLocation = headers[i].split(" ", 3)[1]; - } else if (h[0].equals("Origin:")) { - hOrigin = h[1]; - } else if (h[0].equals("Host:")) { - hHost = h[1]; - } else if (h[0].equals("Sec-WebSocket-Key:")) { - hSecWebSocketKey = h[1]; - } else if (h[0].equals("Sec-WebSocket-Version:")) { - hSecWebSocketVersion = h[1]; - } else if (h[0].equals("X-Real-IP:")) { - hXRealIP = h[1]; - } - } - } - - if (hOrigin == null || hHost == null || hLocation == null || hSecWebSocketKey == null || hSecWebSocketVersion == null || !hSecWebSocketVersion.equals("13")) { - throw new IOException(sock.socket().getRemoteSocketAddress().toString() + " Invalid headers"); - } - - // Auth - int VUID = 0; - int hashloc = hLocation.indexOf("hash="); - if (hashloc > 0) { - String hash = hLocation.substring(hashloc + 5); - if (hash.indexOf('&') > 0) { - hash = hash.substring(0, hash.indexOf('&')); - } - if (hash.length() == 16) { - VUID = com.juick.server.UserQueries.getUIDbyHash(sql, hash); - } - } - - // URL - int hLocationQM = hLocation.indexOf('?'); - if (hLocationQM > 0) { - hLocation = hLocation.substring(0, hLocationQM); - } - - int MID = 0; - int responseCode = 404; - SocketSubscribed sockSubscr = null; - if (hLocation.equals("/") && VUID > 0) { - sockSubscr = new SocketSubscribed(sock, hXRealIP, VUID); - responseCode = 101; - } else if (hLocation.equals("/_all")) { - sockSubscr = new SocketSubscribed(sock, hXRealIP, VUID); - sockSubscr.allMessages = true; - responseCode = 101; - } else if (hLocation.equals("/_replies")) { - sockSubscr = new SocketSubscribed(sock, hXRealIP, VUID); - sockSubscr.allReplies = true; - responseCode = 101; - } else if (hLocation.matches("^/\\d+$")) { - try { - MID = Integer.parseInt(hLocation.substring(1)); - } catch (Exception e) { - } - if (MID > 0) { - if (MessagesQueries.canViewThread(sql, MID, VUID)) { - sockSubscr = new SocketSubscribed(sock, hXRealIP, VUID); - sockSubscr.MID = MID; - responseCode = 101; - } else { - responseCode = 403; - } - } - } else if (hLocation.matches("^/[a-zA-Z0-9\\-]{2,16}/?$")) { - String uname; - if (hLocation.endsWith("/")) { - uname = hLocation.substring(1, hLocation.length() - 2); - } else { - uname = hLocation.substring(1); - } - - int UID = UserQueries.getUIDbyName(sql, uname); - if (UID > 0) { - // check access - sockSubscr = new SocketSubscribed(sock, hXRealIP, VUID); - sockSubscr.UID = UID; - responseCode = 101; - } - } - if (sockSubscr != null) { - synchronized (Main.clients) { - Main.clients.add(sockSubscr); - } - } - - // Response - String outstr; - if (responseCode == 101) { - outstr = "HTTP/1.1 101 Switching Protocols\r\n" - + "Upgrade: websocket\r\n" - + "Connection: Upgrade\r\n" - + "Sec-WebSocket-Accept: " + calcHeaderAccept(hSecWebSocketKey) + "\r\n" - + "\r\n"; - } else if (responseCode == 403) { - outstr = "HTTP/1.1 403 Forbidden\r\n\r\n"; - } else { - outstr = "HTTP/1.1 404 Not Found\r\n\r\n"; - } - ByteBuffer out = ByteBuffer.allocate(1024); - out.put(Charset.forName("ISO-8859-1").encode(outstr)); - out.flip(); - sock.write(out); - - if (responseCode == 101) { - System.out.println(sock.socket().getRemoteSocketAddress().toString() + " HANDSHAKE (VUID = " + VUID + "; MID = " + MID + ")"); - } else { - throw new IOException(sock.socket().getRemoteSocketAddress().toString() + " " + responseCode); - } - } - - private String calcHeaderAccept(String key) { - String base = key + WEBSOCKET_GUID; - try { - MessageDigest md = MessageDigest.getInstance("SHA-1"); - return Base64.encode(md.digest(base.getBytes())); - } catch (NoSuchAlgorithmException e) { - System.err.println("calcHeaderAccept: " + e); - } - return ""; - } - - public void wsPing(SocketChannel sock) throws Exception { - ByteBuffer out = ByteBuffer.allocate(2); - out.put((byte) 0x8A); // PONG FRAME - out.put((byte) 0x00); // 1 byte long - out.flip(); - out.rewind(); - sock.write(out); - } - - public void wsTextFrame(SocketChannel sock, ByteBuffer buf) throws Exception { - /* - ByteBuffer out = ByteBuffer.allocate(3); - out.put((byte) 0x81); // TEXT FRAME - out.put((byte) 0x01); // 1 byte long - out.put((byte) 0x20); // ' ' - out.flip(); - out.rewind(); - sock.write(out); - */ - } - - public void updateSocketTS(SocketChannel sock) { - synchronized (Main.clients) { - Iterator i = Main.clients.iterator(); - while (i.hasNext()) { - SocketSubscribed s = i.next(); - if (s.sock == sock) { - s.tsLastData = System.currentTimeMillis(); - break; - } - } - } - } -} diff --git a/src/com/juick/jabber/ws/WSKeepAlive.java b/src/com/juick/jabber/ws/WSKeepAlive.java deleted file mode 100644 index 2deef594..00000000 --- a/src/com/juick/jabber/ws/WSKeepAlive.java +++ /dev/null @@ -1,102 +0,0 @@ -package com.juick.jabber.ws; - -import java.io.PrintWriter; -import java.nio.ByteBuffer; -import java.sql.Connection; -import java.util.Iterator; - -/** - * - * @author ugnich - */ -public class WSKeepAlive implements Runnable { - - Connection sql; - ByteBuffer pingBytes; - ByteBuffer closeBytes; - - public WSKeepAlive(Connection sql) { - this.sql = sql; - - //pingBytes = ByteBuffer.allocate(2); - //pingBytes.put((byte) 0x8A); // PONG FRAME - //pingBytes.put((byte) 0x00); // 0 byte long - pingBytes = ByteBuffer.allocate(3); - pingBytes.put((byte) 0x81); // TEXT FRAME - pingBytes.put((byte) 0x01); // 1 byte long - pingBytes.put((byte) 0x20); // ' ' - pingBytes.flip(); - - closeBytes = ByteBuffer.allocate(2); - closeBytes.put((byte) 0x88); // CLOSE FRAME - closeBytes.put((byte) 0x00); // 0 byte long - closeBytes.flip(); - } - - @Override - public void run() { - while (true) { - PrintWriter statsFile = null; - - if (Main.STATSFILE != null) { - try { - statsFile = new PrintWriter(Main.STATSFILE, "UTF-8"); - } catch (Exception e) { - statsFile = null; - System.err.println("WSKeepAlive statsFile: " + e); - } - } - - long now = System.currentTimeMillis(); - - synchronized (Main.clients) { - if (statsFile != null) { - statsFile.write("

Connections (" + Main.clients.size() + ")

"); - } - - for (Iterator i = Main.clients.iterator(); i.hasNext();) { - SocketSubscribed s = i.next(); - int inactive = (int) ((double) (now - s.tsLastData) / 1000.0); - - if (statsFile != null) { - try { - statsFile.print(""); - statsFile.print(""); - statsFile.print(""); - statsFile.print(""); - statsFile.print(""); - statsFile.print(""); - statsFile.print(""); - } catch (Exception e) { - System.err.println("WSKeepAlive statsFile print: " + e); - } - } - - if (inactive > 180) { - s.sendByteBuffer(closeBytes); - s.close(); - i.remove(); - } else if (inactive > 60) { - if (!s.sendByteBuffer(pingBytes)) { - i.remove(); - } - } - } - } - - if (Main.STATSFILE != null) { - try { - statsFile.write("
IPinactiveVUIDUIDMIDallMallR
" + (s.clientName != null ? s.clientName : "?") + "" + inactive + "" + (s.VUID > 0 ? s.VUID : "") + "" + (s.UID > 0 ? s.UID : "") + "" + (s.MID > 0 ? s.MID : "") + "" + (s.allMessages ? "+" : "") + "" + (s.allReplies ? "+" : "") + "
"); - statsFile.close(); - } catch (Exception e) { - System.err.println("WSKeepAlive statsFile close: " + e); - } - } - - try { - Thread.sleep(10000); - } catch (InterruptedException e) { - } - } - } -} diff --git a/src/com/juick/jabber/ws/XMPPConnection.java b/src/com/juick/jabber/ws/XMPPConnection.java deleted file mode 100644 index 39815da5..00000000 --- a/src/com/juick/jabber/ws/XMPPConnection.java +++ /dev/null @@ -1,166 +0,0 @@ -package com.juick.jabber.ws; - -import com.juick.server.MessagesQueries; -import com.juick.server.Utils; -import com.juick.xmpp.JID; -import com.juick.xmpp.Message; -import com.juick.xmpp.Stream; -import com.juick.xmpp.StreamComponent; -import com.juick.xmpp.extensions.JuickMessage; -import java.io.IOException; -import java.net.Socket; -import java.nio.ByteBuffer; -import java.nio.charset.Charset; -import java.sql.Connection; -import java.sql.ResultSet; -import java.sql.SQLException; -import java.sql.Statement; -import java.util.ArrayList; -import java.util.Iterator; - -/** - * - * @author ugnich - */ -public class XMPPConnection implements Runnable, Stream.StreamListener, Message.MessageListener { - - Connection sql; - Stream xmpp; - String xmppPassword; - - public XMPPConnection(Connection sql, String password) { - this.sql = sql; - xmppPassword = password; - } - - @Override - public void run() { - try { - Socket socket = new Socket("localhost", 5347); - xmpp = new StreamComponent(new JID("", "ws.juick.com", ""), socket.getInputStream(), socket.getOutputStream(), xmppPassword); - xmpp.addChildParser(new JuickMessage()); - xmpp.addListener((Stream.StreamListener) this); - xmpp.addListener((Message.MessageListener) this); - xmpp.startParsing(); - } catch (IOException e) { - System.err.println("XMPPConnection: " + e); - } - } - - @Override - public void onStreamReady() { - System.err.println("Stream ready"); - } - - @Override - public void onStreamFail(String msg) { - System.err.println("Stream failed: " + msg); - } - - @Override - public void onMessage(com.juick.xmpp.Message msg) { - JuickMessage jmsg = (JuickMessage) msg.getChild(JuickMessage.XMLNS); - if (jmsg != null) { - System.err.println("MID=" + jmsg.MID + "; RID=" + jmsg.RID); - if (jmsg.MID == 0) { - int uid_to = 0; - try { - uid_to = Integer.parseInt(msg.to.Username); - } catch (Exception e) { - } - if (uid_to > 0) { - onJuickPM(uid_to, jmsg); - } - } else if (jmsg.RID == 0) { - onJuickMessagePost(jmsg); - } else { - onJuickMessageReply(jmsg); - } - } - } - - private void onJuickPM(int uid_to, com.juick.Message jmsg) { - String json = com.juick.json.Message.toJSON(jmsg).toString(); - ByteBuffer bbMsg = buildTextFrame(json); - - synchronized (Main.clients) { - for (Iterator i = Main.clients.iterator(); i.hasNext();) { - SocketSubscribed s = i.next(); - if (s.VUID == uid_to && s.MID == 0 && s.allMessages == false && s.allReplies == false) { - if (!s.sendByteBuffer(bbMsg)) { - i.remove(); - } - } - } - } - } - - private void onJuickMessagePost(com.juick.Message jmsg) { - String json = com.juick.json.Message.toJSON(jmsg).toString(); - ByteBuffer bbMsg = buildTextFrame(json); - - ArrayList uids = new ArrayList(); - String query = "SELECT suser_id FROM subscr_users WHERE user_id=" + jmsg.User.UID + " AND suser_id NOT IN (SELECT user_id FROM bl_tags INNER JOIN messages_tags USING(tag_id) WHERE message_id=" + jmsg.MID + ")"; - if (jmsg.Privacy < 0) { - query += " AND suser_id IN (SELECT wl_user_id FROM wl_users WHERE user_id=" + jmsg.User.UID + ")"; - } - Statement stmt = null; - ResultSet rs = null; - try { - stmt = sql.createStatement(); - rs = stmt.executeQuery(query); - rs.beforeFirst(); - while (rs.next()) { - uids.add(rs.getInt(1)); - } - } catch (SQLException e) { - System.err.println("onJuickMessagePost: " + e); - } finally { - Utils.finishSQL(rs, stmt); - } - - synchronized (Main.clients) { - for (Iterator i = Main.clients.iterator(); i.hasNext();) { - SocketSubscribed s = i.next(); - if (s.MID == 0 && s.allReplies == false && ((jmsg.Privacy >= 0 && (s.allMessages || s.UID == jmsg.User.UID)) || uids.contains(s.VUID))) { - if (!s.sendByteBuffer(bbMsg)) { - i.remove(); - } - } - } - } - } - - private void onJuickMessageReply(com.juick.Message jmsg) { - String json = com.juick.json.Message.toJSON(jmsg).toString(); - ByteBuffer bbMsg = buildTextFrame(json); - - int privacy = MessagesQueries.getMessagePrivacy(sql, jmsg.MID); - - synchronized (Main.clients) { - for (Iterator i = Main.clients.iterator(); i.hasNext();) { - SocketSubscribed s = i.next(); - if ((privacy >= 0 && s.allReplies) || s.MID == jmsg.MID) { - if (!s.sendByteBuffer(bbMsg)) { - i.remove(); - } - } - } - } - } - - private ByteBuffer buildTextFrame(String json) { - ByteBuffer jsonbytes = Charset.forName("UTF-8").encode(json); - ByteBuffer bbMsg = ByteBuffer.allocate(jsonbytes.limit() + 8); - bbMsg.put((byte) 0x81); - if (jsonbytes.limit() <= 125) { - bbMsg.put((byte) jsonbytes.limit()); - } else { - bbMsg.put((byte) 126); - bbMsg.putShort((short) jsonbytes.limit()); - } - bbMsg.put(jsonbytes); - bbMsg.flip(); - return bbMsg; - } -} diff --git a/src/main/java/com/juick/jabber/ws/Main.java b/src/main/java/com/juick/jabber/ws/Main.java new file mode 100644 index 00000000..a7aea543 --- /dev/null +++ b/src/main/java/com/juick/jabber/ws/Main.java @@ -0,0 +1,68 @@ +/* + * Juick + * Copyright (C) 2008-2011, Ugnich Anton + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ +package com.juick.jabber.ws; + +import java.io.FileInputStream; +import java.sql.Connection; +import java.sql.DriverManager; +import java.sql.SQLException; +import java.util.ArrayList; +import java.util.Properties; + +/** + * + * @author Ugnich Anton + */ +public class Main { + + Connection sql; + XMPPConnection xmpp; + public static String STATSFILE = null; + public final static ArrayList clients = new ArrayList(); + + public static void main(String[] args) { + new Main().start(); + } + + public void start() { + try { + Properties conf = new Properties(); + conf.load(new FileInputStream("/etc/juick/ws.conf")); + + STATSFILE = conf.getProperty("statsfile"); + + setupSql(conf.getProperty("mysql_username", ""), conf.getProperty("mysql_password", "")); + xmpp = new XMPPConnection(sql, conf.getProperty("xmpp_password", "")); + new Thread(xmpp).start(); + + //new Thread(new WSConnections()).start(); + new Thread(new WSData(sql)).start(); + new Thread(new WSKeepAlive(sql)).start(); + } catch (Exception e) { + System.err.println(e); + } + } + + public void setupSql(String username, String password) { + try { + sql = DriverManager.getConnection("jdbc:mysql://localhost/juick?autoReconnect=true&user=" + username + "&password=" + password); + } catch (SQLException e) { + System.err.println(e); + } + } +} \ No newline at end of file diff --git a/src/main/java/com/juick/jabber/ws/SocketSubscribed.java b/src/main/java/com/juick/jabber/ws/SocketSubscribed.java new file mode 100644 index 00000000..6144380c --- /dev/null +++ b/src/main/java/com/juick/jabber/ws/SocketSubscribed.java @@ -0,0 +1,51 @@ +package com.juick.jabber.ws; + +import java.nio.ByteBuffer; +import java.nio.channels.SocketChannel; + +/** + * + * @author ugnich + */ +public class SocketSubscribed { + + public SocketChannel sock = null; + public String clientName = null; + public int VUID = 0; + public int UID = 0; + public int MID = 0; + public boolean allMessages = false; + public boolean allReplies = false; + public long tsConnected; + public long tsLastData; + + public SocketSubscribed(SocketChannel sock, String clientName, int VUID) { + this.sock = sock; + this.clientName = clientName; + this.VUID = VUID; + tsConnected = tsLastData = System.currentTimeMillis(); + } + + public boolean sendByteBuffer(ByteBuffer bb) { + boolean ret = false; + bb.rewind(); + try { + sock.write(bb); + ret = true; + } catch (Exception e) { + close(); + } + return ret; + } + + public void close() { + try { + sock.socket().close(); + } catch (Exception e) { + } + try { + sock.close(); + } catch (Exception e) { + } + } +} diff --git a/src/main/java/com/juick/jabber/ws/WSConnections.java b/src/main/java/com/juick/jabber/ws/WSConnections.java new file mode 100644 index 00000000..15fbe4e8 --- /dev/null +++ b/src/main/java/com/juick/jabber/ws/WSConnections.java @@ -0,0 +1,44 @@ +package com.juick.jabber.ws; + +import java.net.InetSocketAddress; +import java.nio.channels.SelectionKey; +import java.nio.channels.Selector; +import java.nio.channels.ServerSocketChannel; +import java.nio.channels.SocketChannel; +import java.util.Iterator; + +/** + * + * @author ugnich + */ +public class WSConnections implements Runnable { + + Selector sel; + + @Override + public void run() { + try { + sel = Selector.open(); + ServerSocketChannel listensock = ServerSocketChannel.open(); + listensock.configureBlocking(false); + listensock.socket().bind(new InetSocketAddress(8081)); + listensock.register(sel, SelectionKey.OP_ACCEPT); + + while (true) { + sel.select(); + Iterator it = sel.selectedKeys().iterator(); + while (it.hasNext()) { + SelectionKey selKey = it.next(); + it.remove(); + ServerSocketChannel ssChannel = (ServerSocketChannel) selKey.channel(); + SocketChannel sChannel = ssChannel.accept(); + sChannel.configureBlocking(false); + sChannel.register(sel, SelectionKey.OP_READ); + System.out.println(sChannel.socket().getRemoteSocketAddress().toString() + " ACCEPTED"); + } + } + } catch (Exception e) { + System.err.println("WSConnections: " + e); + } + } +} diff --git a/src/main/java/com/juick/jabber/ws/WSData.java b/src/main/java/com/juick/jabber/ws/WSData.java new file mode 100644 index 00000000..d77257e6 --- /dev/null +++ b/src/main/java/com/juick/jabber/ws/WSData.java @@ -0,0 +1,276 @@ +package com.juick.jabber.ws; + +import com.juick.server.MessagesQueries; +import com.juick.server.UserQueries; +import com.juick.xmpp.utils.Base64; +import java.io.IOException; +import java.net.InetSocketAddress; +import java.nio.ByteBuffer; +import java.nio.CharBuffer; +import java.nio.channels.SelectionKey; +import java.nio.channels.Selector; +import java.nio.channels.ServerSocketChannel; +import java.nio.channels.SocketChannel; +import java.nio.charset.Charset; +import java.security.MessageDigest; +import java.security.NoSuchAlgorithmException; +import java.sql.Connection; +import java.util.Iterator; + +/** + * + * @author ugnich + */ +public class WSData implements Runnable { + + static final String WEBSOCKET_GUID = "258EAFA5-E914-47DA-95CA-C5AB0DC85B11"; + Connection sql; + public Selector sel; + + public WSData(Connection sql) { + this.sql = sql; + } + + @Override + public void run() { + try { + sel = Selector.open(); + ServerSocketChannel listensock = ServerSocketChannel.open(); + listensock.configureBlocking(false); + listensock.socket().bind(new InetSocketAddress(8081)); + listensock.register(sel, SelectionKey.OP_ACCEPT); + + while (true) { + sel.select(); + Iterator it = sel.selectedKeys().iterator(); + while (it.hasNext()) { + SelectionKey selKey = it.next(); + it.remove(); + + if (selKey.isAcceptable()) { + ServerSocketChannel ssChannel = (ServerSocketChannel) selKey.channel(); + SocketChannel sChannel = ssChannel.accept(); + sChannel.configureBlocking(false); + sChannel.register(sel, SelectionKey.OP_READ); + System.out.println(sChannel.socket().getRemoteSocketAddress().toString() + " ACCEPTED"); + } else if (selKey.isReadable()) { + SocketChannel sChannel = (SocketChannel) selKey.channel(); + ByteBuffer buf = ByteBuffer.allocate(10240); + try { + int readbytes = sChannel.read(buf); + if (readbytes > 0) { + buf.flip(); + + CharBuffer charbuf = Charset.forName("ISO-8859-1").decode(buf); + System.out.println("DATA: " + charbuf.toString()); + buf.rewind(); + + switch (buf.get(0)) { + case (byte) 0x89: // PING + updateSocketTS(sChannel); + wsPing(sChannel); + break; + case (byte) 0x8A: // PONG + updateSocketTS(sChannel); + break; + case (byte) 0x81: // TEXT FRAME + updateSocketTS(sChannel); + wsTextFrame(sChannel, buf); + break; + case (byte) 'G': // HTTP + updateSocketTS(sChannel); + wsHandshake(sChannel, buf); + break; + case (byte) 0x88: // CONNECTION CLOSE + throw new IOException(sChannel.socket().getRemoteSocketAddress().toString() + " CONNECTION CLOSE"); + } + } else if (readbytes < 0) { + throw new IOException(sChannel.socket().getRemoteSocketAddress().toString() + " END OF STREAM"); + } + } catch (IOException e) { + System.err.println("WSData: " + e); + sChannel.socket().close(); + sChannel.close(); + selKey.cancel(); + } + } + } + } + } catch (Exception e) { + System.err.println("WSData: " + e); + } + } + + public void wsHandshake(SocketChannel sock, ByteBuffer buf) throws Exception { + String hOrigin = null; + String hHost = null; + String hLocation = null; + String hSecWebSocketKey = null; + String hSecWebSocketVersion = null; + String hXRealIP = null; + + buf.rewind(); + CharBuffer charbuf = Charset.forName("ISO-8859-1").decode(buf); + String headers[] = charbuf.toString().split("\r\n"); + for (int i = 0; i < headers.length; i++) { + String h[] = headers[i].split(" ", 2); + if (h.length == 2) { + if (h[0].equals("GET")) { + hLocation = headers[i].split(" ", 3)[1]; + } else if (h[0].equals("Origin:")) { + hOrigin = h[1]; + } else if (h[0].equals("Host:")) { + hHost = h[1]; + } else if (h[0].equals("Sec-WebSocket-Key:")) { + hSecWebSocketKey = h[1]; + } else if (h[0].equals("Sec-WebSocket-Version:")) { + hSecWebSocketVersion = h[1]; + } else if (h[0].equals("X-Real-IP:")) { + hXRealIP = h[1]; + } + } + } + + if (hOrigin == null || hHost == null || hLocation == null || hSecWebSocketKey == null || hSecWebSocketVersion == null || !hSecWebSocketVersion.equals("13")) { + throw new IOException(sock.socket().getRemoteSocketAddress().toString() + " Invalid headers"); + } + + // Auth + int VUID = 0; + int hashloc = hLocation.indexOf("hash="); + if (hashloc > 0) { + String hash = hLocation.substring(hashloc + 5); + if (hash.indexOf('&') > 0) { + hash = hash.substring(0, hash.indexOf('&')); + } + if (hash.length() == 16) { + VUID = com.juick.server.UserQueries.getUIDbyHash(sql, hash); + } + } + + // URL + int hLocationQM = hLocation.indexOf('?'); + if (hLocationQM > 0) { + hLocation = hLocation.substring(0, hLocationQM); + } + + int MID = 0; + int responseCode = 404; + SocketSubscribed sockSubscr = null; + if (hLocation.equals("/") && VUID > 0) { + sockSubscr = new SocketSubscribed(sock, hXRealIP, VUID); + responseCode = 101; + } else if (hLocation.equals("/_all")) { + sockSubscr = new SocketSubscribed(sock, hXRealIP, VUID); + sockSubscr.allMessages = true; + responseCode = 101; + } else if (hLocation.equals("/_replies")) { + sockSubscr = new SocketSubscribed(sock, hXRealIP, VUID); + sockSubscr.allReplies = true; + responseCode = 101; + } else if (hLocation.matches("^/\\d+$")) { + try { + MID = Integer.parseInt(hLocation.substring(1)); + } catch (Exception e) { + } + if (MID > 0) { + if (MessagesQueries.canViewThread(sql, MID, VUID)) { + sockSubscr = new SocketSubscribed(sock, hXRealIP, VUID); + sockSubscr.MID = MID; + responseCode = 101; + } else { + responseCode = 403; + } + } + } else if (hLocation.matches("^/[a-zA-Z0-9\\-]{2,16}/?$")) { + String uname; + if (hLocation.endsWith("/")) { + uname = hLocation.substring(1, hLocation.length() - 2); + } else { + uname = hLocation.substring(1); + } + + int UID = UserQueries.getUIDbyName(sql, uname); + if (UID > 0) { + // check access + sockSubscr = new SocketSubscribed(sock, hXRealIP, VUID); + sockSubscr.UID = UID; + responseCode = 101; + } + } + if (sockSubscr != null) { + synchronized (Main.clients) { + Main.clients.add(sockSubscr); + } + } + + // Response + String outstr; + if (responseCode == 101) { + outstr = "HTTP/1.1 101 Switching Protocols\r\n" + + "Upgrade: websocket\r\n" + + "Connection: Upgrade\r\n" + + "Sec-WebSocket-Accept: " + calcHeaderAccept(hSecWebSocketKey) + "\r\n" + + "\r\n"; + } else if (responseCode == 403) { + outstr = "HTTP/1.1 403 Forbidden\r\n\r\n"; + } else { + outstr = "HTTP/1.1 404 Not Found\r\n\r\n"; + } + ByteBuffer out = ByteBuffer.allocate(1024); + out.put(Charset.forName("ISO-8859-1").encode(outstr)); + out.flip(); + sock.write(out); + + if (responseCode == 101) { + System.out.println(sock.socket().getRemoteSocketAddress().toString() + " HANDSHAKE (VUID = " + VUID + "; MID = " + MID + ")"); + } else { + throw new IOException(sock.socket().getRemoteSocketAddress().toString() + " " + responseCode); + } + } + + private String calcHeaderAccept(String key) { + String base = key + WEBSOCKET_GUID; + try { + MessageDigest md = MessageDigest.getInstance("SHA-1"); + return Base64.encode(md.digest(base.getBytes())); + } catch (NoSuchAlgorithmException e) { + System.err.println("calcHeaderAccept: " + e); + } + return ""; + } + + public void wsPing(SocketChannel sock) throws Exception { + ByteBuffer out = ByteBuffer.allocate(2); + out.put((byte) 0x8A); // PONG FRAME + out.put((byte) 0x00); // 1 byte long + out.flip(); + out.rewind(); + sock.write(out); + } + + public void wsTextFrame(SocketChannel sock, ByteBuffer buf) throws Exception { + /* + ByteBuffer out = ByteBuffer.allocate(3); + out.put((byte) 0x81); // TEXT FRAME + out.put((byte) 0x01); // 1 byte long + out.put((byte) 0x20); // ' ' + out.flip(); + out.rewind(); + sock.write(out); + */ + } + + public void updateSocketTS(SocketChannel sock) { + synchronized (Main.clients) { + Iterator i = Main.clients.iterator(); + while (i.hasNext()) { + SocketSubscribed s = i.next(); + if (s.sock == sock) { + s.tsLastData = System.currentTimeMillis(); + break; + } + } + } + } +} diff --git a/src/main/java/com/juick/jabber/ws/WSKeepAlive.java b/src/main/java/com/juick/jabber/ws/WSKeepAlive.java new file mode 100644 index 00000000..2deef594 --- /dev/null +++ b/src/main/java/com/juick/jabber/ws/WSKeepAlive.java @@ -0,0 +1,102 @@ +package com.juick.jabber.ws; + +import java.io.PrintWriter; +import java.nio.ByteBuffer; +import java.sql.Connection; +import java.util.Iterator; + +/** + * + * @author ugnich + */ +public class WSKeepAlive implements Runnable { + + Connection sql; + ByteBuffer pingBytes; + ByteBuffer closeBytes; + + public WSKeepAlive(Connection sql) { + this.sql = sql; + + //pingBytes = ByteBuffer.allocate(2); + //pingBytes.put((byte) 0x8A); // PONG FRAME + //pingBytes.put((byte) 0x00); // 0 byte long + pingBytes = ByteBuffer.allocate(3); + pingBytes.put((byte) 0x81); // TEXT FRAME + pingBytes.put((byte) 0x01); // 1 byte long + pingBytes.put((byte) 0x20); // ' ' + pingBytes.flip(); + + closeBytes = ByteBuffer.allocate(2); + closeBytes.put((byte) 0x88); // CLOSE FRAME + closeBytes.put((byte) 0x00); // 0 byte long + closeBytes.flip(); + } + + @Override + public void run() { + while (true) { + PrintWriter statsFile = null; + + if (Main.STATSFILE != null) { + try { + statsFile = new PrintWriter(Main.STATSFILE, "UTF-8"); + } catch (Exception e) { + statsFile = null; + System.err.println("WSKeepAlive statsFile: " + e); + } + } + + long now = System.currentTimeMillis(); + + synchronized (Main.clients) { + if (statsFile != null) { + statsFile.write("

Connections (" + Main.clients.size() + ")

"); + } + + for (Iterator i = Main.clients.iterator(); i.hasNext();) { + SocketSubscribed s = i.next(); + int inactive = (int) ((double) (now - s.tsLastData) / 1000.0); + + if (statsFile != null) { + try { + statsFile.print(""); + statsFile.print(""); + statsFile.print(""); + statsFile.print(""); + statsFile.print(""); + statsFile.print(""); + statsFile.print(""); + } catch (Exception e) { + System.err.println("WSKeepAlive statsFile print: " + e); + } + } + + if (inactive > 180) { + s.sendByteBuffer(closeBytes); + s.close(); + i.remove(); + } else if (inactive > 60) { + if (!s.sendByteBuffer(pingBytes)) { + i.remove(); + } + } + } + } + + if (Main.STATSFILE != null) { + try { + statsFile.write("
IPinactiveVUIDUIDMIDallMallR
" + (s.clientName != null ? s.clientName : "?") + "" + inactive + "" + (s.VUID > 0 ? s.VUID : "") + "" + (s.UID > 0 ? s.UID : "") + "" + (s.MID > 0 ? s.MID : "") + "" + (s.allMessages ? "+" : "") + "" + (s.allReplies ? "+" : "") + "
"); + statsFile.close(); + } catch (Exception e) { + System.err.println("WSKeepAlive statsFile close: " + e); + } + } + + try { + Thread.sleep(10000); + } catch (InterruptedException e) { + } + } + } +} diff --git a/src/main/java/com/juick/jabber/ws/XMPPConnection.java b/src/main/java/com/juick/jabber/ws/XMPPConnection.java new file mode 100644 index 00000000..39815da5 --- /dev/null +++ b/src/main/java/com/juick/jabber/ws/XMPPConnection.java @@ -0,0 +1,166 @@ +package com.juick.jabber.ws; + +import com.juick.server.MessagesQueries; +import com.juick.server.Utils; +import com.juick.xmpp.JID; +import com.juick.xmpp.Message; +import com.juick.xmpp.Stream; +import com.juick.xmpp.StreamComponent; +import com.juick.xmpp.extensions.JuickMessage; +import java.io.IOException; +import java.net.Socket; +import java.nio.ByteBuffer; +import java.nio.charset.Charset; +import java.sql.Connection; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.sql.Statement; +import java.util.ArrayList; +import java.util.Iterator; + +/** + * + * @author ugnich + */ +public class XMPPConnection implements Runnable, Stream.StreamListener, Message.MessageListener { + + Connection sql; + Stream xmpp; + String xmppPassword; + + public XMPPConnection(Connection sql, String password) { + this.sql = sql; + xmppPassword = password; + } + + @Override + public void run() { + try { + Socket socket = new Socket("localhost", 5347); + xmpp = new StreamComponent(new JID("", "ws.juick.com", ""), socket.getInputStream(), socket.getOutputStream(), xmppPassword); + xmpp.addChildParser(new JuickMessage()); + xmpp.addListener((Stream.StreamListener) this); + xmpp.addListener((Message.MessageListener) this); + xmpp.startParsing(); + } catch (IOException e) { + System.err.println("XMPPConnection: " + e); + } + } + + @Override + public void onStreamReady() { + System.err.println("Stream ready"); + } + + @Override + public void onStreamFail(String msg) { + System.err.println("Stream failed: " + msg); + } + + @Override + public void onMessage(com.juick.xmpp.Message msg) { + JuickMessage jmsg = (JuickMessage) msg.getChild(JuickMessage.XMLNS); + if (jmsg != null) { + System.err.println("MID=" + jmsg.MID + "; RID=" + jmsg.RID); + if (jmsg.MID == 0) { + int uid_to = 0; + try { + uid_to = Integer.parseInt(msg.to.Username); + } catch (Exception e) { + } + if (uid_to > 0) { + onJuickPM(uid_to, jmsg); + } + } else if (jmsg.RID == 0) { + onJuickMessagePost(jmsg); + } else { + onJuickMessageReply(jmsg); + } + } + } + + private void onJuickPM(int uid_to, com.juick.Message jmsg) { + String json = com.juick.json.Message.toJSON(jmsg).toString(); + ByteBuffer bbMsg = buildTextFrame(json); + + synchronized (Main.clients) { + for (Iterator i = Main.clients.iterator(); i.hasNext();) { + SocketSubscribed s = i.next(); + if (s.VUID == uid_to && s.MID == 0 && s.allMessages == false && s.allReplies == false) { + if (!s.sendByteBuffer(bbMsg)) { + i.remove(); + } + } + } + } + } + + private void onJuickMessagePost(com.juick.Message jmsg) { + String json = com.juick.json.Message.toJSON(jmsg).toString(); + ByteBuffer bbMsg = buildTextFrame(json); + + ArrayList uids = new ArrayList(); + String query = "SELECT suser_id FROM subscr_users WHERE user_id=" + jmsg.User.UID + " AND suser_id NOT IN (SELECT user_id FROM bl_tags INNER JOIN messages_tags USING(tag_id) WHERE message_id=" + jmsg.MID + ")"; + if (jmsg.Privacy < 0) { + query += " AND suser_id IN (SELECT wl_user_id FROM wl_users WHERE user_id=" + jmsg.User.UID + ")"; + } + Statement stmt = null; + ResultSet rs = null; + try { + stmt = sql.createStatement(); + rs = stmt.executeQuery(query); + rs.beforeFirst(); + while (rs.next()) { + uids.add(rs.getInt(1)); + } + } catch (SQLException e) { + System.err.println("onJuickMessagePost: " + e); + } finally { + Utils.finishSQL(rs, stmt); + } + + synchronized (Main.clients) { + for (Iterator i = Main.clients.iterator(); i.hasNext();) { + SocketSubscribed s = i.next(); + if (s.MID == 0 && s.allReplies == false && ((jmsg.Privacy >= 0 && (s.allMessages || s.UID == jmsg.User.UID)) || uids.contains(s.VUID))) { + if (!s.sendByteBuffer(bbMsg)) { + i.remove(); + } + } + } + } + } + + private void onJuickMessageReply(com.juick.Message jmsg) { + String json = com.juick.json.Message.toJSON(jmsg).toString(); + ByteBuffer bbMsg = buildTextFrame(json); + + int privacy = MessagesQueries.getMessagePrivacy(sql, jmsg.MID); + + synchronized (Main.clients) { + for (Iterator i = Main.clients.iterator(); i.hasNext();) { + SocketSubscribed s = i.next(); + if ((privacy >= 0 && s.allReplies) || s.MID == jmsg.MID) { + if (!s.sendByteBuffer(bbMsg)) { + i.remove(); + } + } + } + } + } + + private ByteBuffer buildTextFrame(String json) { + ByteBuffer jsonbytes = Charset.forName("UTF-8").encode(json); + ByteBuffer bbMsg = ByteBuffer.allocate(jsonbytes.limit() + 8); + bbMsg.put((byte) 0x81); + if (jsonbytes.limit() <= 125) { + bbMsg.put((byte) jsonbytes.limit()); + } else { + bbMsg.put((byte) 126); + bbMsg.putShort((short) jsonbytes.limit()); + } + bbMsg.put(jsonbytes); + bbMsg.flip(); + return bbMsg; + } +} -- cgit v1.2.3