From a4897522174fb48864a4ef7d6276167f9da61f3b Mon Sep 17 00:00:00 2001
From: Vitaly Takmazov
Date: Sat, 31 Oct 2015 01:36:15 +0300
Subject: moved to Gradle
---
.gitignore | 9 +-
.gitmodules | 12 +
build.gradle | 67 ++
build.xml | 71 --
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/xpp3_min-1.1.4.jar | Bin 24955 -> 0 bytes
nbproject/ant-deploy.xml | 37 -
nbproject/build-impl.xml | 1112 -----------------------------
nbproject/genfiles.properties | 8 -
nbproject/project.properties | 95 ---
nbproject/project.xml | 77 --
settings.gradle | 1 +
src/conf/MANIFEST.MF | 2 -
src/java/com/juick/api/Main.java | 231 ------
src/java/com/juick/api/Messages.java | 89 ---
src/java/com/juick/api/Others.java | 45 --
src/java/com/juick/api/PM.java | 101 ---
src/java/com/juick/api/Users.java | 120 ----
src/java/com/juick/api/Utils.java | 149 ----
src/main/java/com/juick/api/Main.java | 231 ++++++
src/main/java/com/juick/api/Messages.java | 89 +++
src/main/java/com/juick/api/Others.java | 45 ++
src/main/java/com/juick/api/PM.java | 101 +++
src/main/java/com/juick/api/Users.java | 120 ++++
src/main/java/com/juick/api/Utils.java | 149 ++++
src/main/webapp/WEB-INF/web.xml | 16 +
web/META-INF/context.xml | 2 -
web/WEB-INF/web.xml | 16 -
35 files changed, 1097 insertions(+), 2158 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/xpp3_min-1.1.4.jar
delete mode 100644 nbproject/ant-deploy.xml
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/conf/MANIFEST.MF
delete mode 100644 src/java/com/juick/api/Main.java
delete mode 100644 src/java/com/juick/api/Messages.java
delete mode 100644 src/java/com/juick/api/Others.java
delete mode 100644 src/java/com/juick/api/PM.java
delete mode 100644 src/java/com/juick/api/Users.java
delete mode 100644 src/java/com/juick/api/Utils.java
create mode 100644 src/main/java/com/juick/api/Main.java
create mode 100644 src/main/java/com/juick/api/Messages.java
create mode 100644 src/main/java/com/juick/api/Others.java
create mode 100644 src/main/java/com/juick/api/PM.java
create mode 100644 src/main/java/com/juick/api/Users.java
create mode 100644 src/main/java/com/juick/api/Utils.java
create mode 100644 src/main/webapp/WEB-INF/web.xml
delete mode 100644 web/META-INF/context.xml
delete mode 100644 web/WEB-INF/web.xml
diff --git a/.gitignore b/.gitignore
index d3bae3d4..ec7d29ba 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,3 +1,6 @@
-/build/
-/dist/
-/nbproject/private/
\ No newline at end of file
+build/*
+.gradle/*
+deps/*
+.idea/*
+*.iml
+**/juick.conf
diff --git a/.gitmodules b/.gitmodules
new file mode 100644
index 00000000..35d5ef99
--- /dev/null
+++ b/.gitmodules
@@ -0,0 +1,12 @@
+[submodule "deps/com.juick"]
+ path = deps/com.juick
+ url = ssh://den.jabber.ru:2205/var/lib/git/com.juick.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.server"]
+ path = deps/com.juick.server
+ url = ssh://den.jabber.ru:2205/var/lib/git/com.juick.server.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..ab3d39b2
--- /dev/null
+++ b/build.gradle
@@ -0,0 +1,67 @@
+subprojects {
+ apply plugin: 'java'
+ repositories {
+ mavenCentral()
+ }
+}
+
+buildscript {
+ repositories {
+ mavenCentral()
+ jcenter()
+ }
+ dependencies {
+ classpath 'com.bmuschko:gradle-tomcat-plugin:2.2.+'
+ }
+}
+
+apply plugin: 'java'
+apply plugin: 'war'
+apply plugin: 'com.bmuschko.tomcat'
+
+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 'org.json:json:20140107'
+ compile core
+ compile server
+ compile xmpp
+ compile json
+ 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}"
+}
+
+compileJava.options.encoding = 'UTF-8'
+
+tomcat {
+ httpPort = 8080
+ contextPath = '/'
+}
diff --git a/build.xml b/build.xml
deleted file mode 100644
index b1509601..00000000
--- a/build.xml
+++ /dev/null
@@ -1,71 +0,0 @@
-
-
-
-
-
-
-
-
-
-
- Builds, tests, and runs the project com.juick.api.
-
-
-
diff --git a/deps/com.juick b/deps/com.juick
new file mode 160000
index 00000000..a5766d12
--- /dev/null
+++ b/deps/com.juick
@@ -0,0 +1 @@
+Subproject commit a5766d12d6dbd80a44d6d1deee4d454016b37079
diff --git a/deps/com.juick.json b/deps/com.juick.json
new file mode 160000
index 00000000..5f4602b3
--- /dev/null
+++ b/deps/com.juick.json
@@ -0,0 +1 @@
+Subproject commit 5f4602b34ccc3f899edd45e5e541cbb7307c9585
diff --git a/deps/com.juick.server b/deps/com.juick.server
new file mode 160000
index 00000000..5f981ff9
--- /dev/null
+++ b/deps/com.juick.server
@@ -0,0 +1 @@
+Subproject commit 5f981ff945d7bad508d0fb56d037bfe3dccd0cf3
diff --git a/deps/com.juick.xmpp b/deps/com.juick.xmpp
new file mode 160000
index 00000000..87ca4b93
--- /dev/null
+++ b/deps/com.juick.xmpp
@@ -0,0 +1 @@
+Subproject commit 87ca4b93d426c19b6fdaeec038202485515606d5
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/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/nbproject/ant-deploy.xml b/nbproject/ant-deploy.xml
deleted file mode 100644
index cbfe67c3..00000000
--- a/nbproject/ant-deploy.xml
+++ /dev/null
@@ -1,37 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/nbproject/build-impl.xml b/nbproject/build-impl.xml
deleted file mode 100644
index 7fcc9e67..00000000
--- a/nbproject/build-impl.xml
+++ /dev/null
@@ -1,1112 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- Must set src.dir
- Must set test.src.dir
- Must set build.dir
- Must set build.web.dir
- Must set build.generated.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.war
-
-
-
-
-
-
-
-
-
-The Java EE server classpath is not correctly set up - server home directory is missing.
-Either open the project in the IDE and assign the server or setup the server classpath manually.
-For example like this:
- ant -Dj2ee.server.home=<app_server_installation_directory>
-
-
-The Java EE server classpath is not correctly set up. Your active server type is ${j2ee.server.type}.
-Either open the project in the IDE and assign the server or setup the server classpath manually.
-For example like this:
- ant -Duser.properties.file=<path_to_property_file> (where you put the property "j2ee.platform.classpath" in a .properties file)
-or ant -Dj2ee.platform.classpath=<server_classpath> (where no properties file is used)
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- Must set javac.includes
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-The libs.CopyLibs.classpath property is not set up.
-This property must point to
-org-netbeans-modules-java-j2seproject-copylibstask.jar file which is part
-of NetBeans IDE installation and is usually located at
-<netbeans_installation>/java<version>/ant/extra folder.
-Either open the project in the IDE and make sure CopyLibs library
-exists or setup the property manually. For example like this:
- ant -Dlibs.CopyLibs.classpath=a/path/to/org-netbeans-modules-java-j2seproject-copylibstask.jar
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- 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
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- Must select some files in the IDE or set javac.jsp.includes
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- Must select a file in the IDE or set jsp.includes
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- Browser not found, cannot launch the deployed application. Try to set the BROWSER environment variable.
-
-
- Launching ${browse.url}
-
-
-
-
-
- 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 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
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/nbproject/genfiles.properties b/nbproject/genfiles.properties
deleted file mode 100644
index 9fa27ff1..00000000
--- a/nbproject/genfiles.properties
+++ /dev/null
@@ -1,8 +0,0 @@
-build.xml.data.CRC32=0e286cb1
-build.xml.script.CRC32=2226508e
-build.xml.stylesheet.CRC32=651128d4@1.33.1.1
-# 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=0e286cb1
-nbproject/build-impl.xml.script.CRC32=4228b93d
-nbproject/build-impl.xml.stylesheet.CRC32=0cbf5bb7@1.33.1.1
diff --git a/nbproject/project.properties b/nbproject/project.properties
deleted file mode 100644
index b3480c49..00000000
--- a/nbproject/project.properties
+++ /dev/null
@@ -1,95 +0,0 @@
-annotation.processing.enabled=true
-annotation.processing.enabled.in.editor=true
-annotation.processing.processors.list=
-annotation.processing.run.all.processors=true
-annotation.processing.source.output=${build.generated.sources.dir}/ap-source-output
-build.classes.dir=${build.web.dir}/WEB-INF/classes
-build.classes.excludes=**/*.java,**/*.form
-build.dir=build
-build.generated.dir=${build.dir}/generated
-build.generated.sources.dir=${build.dir}/generated-sources
-build.test.classes.dir=${build.dir}/test/classes
-build.test.results.dir=${build.dir}/test/results
-build.web.dir=${build.dir}/web
-build.web.excludes=${build.classes.excludes}
-client.urlPart=
-compile.jsps=false
-conf.dir=${source.root}/conf
-debug.classpath=${build.classes.dir}:${javac.classpath}
-debug.test.classpath=\
- ${run.test.classpath}
-display.browser=true
-dist.dir=dist
-dist.ear.war=${dist.dir}/${war.ear.name}
-dist.javadoc.dir=${dist.dir}/javadoc
-dist.war=${dist.dir}/${war.name}
-endorsed.classpath=\
- ${libs.javaee-endorsed-api-6.0.classpath}
-excludes=
-file.reference.xpp3_min-1.1.4.jar=lib/xpp3_min-1.1.4.jar
-includes=**
-j2ee.compile.on.save=true
-j2ee.deploy.on.save=true
-j2ee.platform=1.6-web
-j2ee.platform.classpath=${j2ee.server.home}/lib/catalina-ant.jar:${j2ee.server.home}/lib/tomcat-jdbc.jar:${j2ee.server.home}/lib/jasper-el.jar:${j2ee.server.home}/lib/tomcat-i18n-fr.jar:${j2ee.server.home}/lib/tomcat7-websocket.jar:${j2ee.server.home}/lib/jsp-api.jar:${j2ee.server.home}/lib/catalina.jar:${j2ee.server.home}/lib/ecj-4.2.2.jar:${j2ee.server.home}/lib/tomcat-i18n-ja.jar:${j2ee.server.home}/lib/websocket-api.jar:${j2ee.server.home}/lib/el-api.jar:${j2ee.server.home}/lib/catalina-tribes.jar:${j2ee.server.home}/lib/tomcat-coyote.jar:${j2ee.server.home}/lib/jasper.jar:${j2ee.server.home}/lib/tomcat-util.jar:${j2ee.server.home}/lib/tomcat-api.jar:${j2ee.server.home}/lib/tomcat-dbcp.jar:${j2ee.server.home}/lib/servlet-api.jar:${j2ee.server.home}/lib/tomcat-i18n-es.jar:${j2ee.server.home}/lib/catalina-ha.jar:${j2ee.server.home}/lib/annotations-api.jar
-j2ee.server.type=Tomcat
-jar.compress=false
-javac.classpath=\
- ${reference.com_juick.jar}:\
- ${reference.com_juick_server.jar}:\
- ${reference.com_juick_json.jar}:\
- ${reference.com_juick_xmpp.jar}:\
- ${libs.JSON.classpath}:\
- ${file.reference.xpp3_min-1.1.4.jar}
-# Space-separated list of extra javac options
-javac.compilerargs=
-javac.debug=true
-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.preview=true
-javadoc.private=false
-javadoc.splitindex=true
-javadoc.use=true
-javadoc.version=false
-javadoc.windowtitle=
-lib.dir=${web.docbase.dir}/WEB-INF/lib
-persistence.xml.dir=${conf.dir}
-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
-resource.dir=setup
-run.test.classpath=\
- ${javac.test.classpath}:\
- ${build.test.classes.dir}
-# Space-separated list of JVM arguments used when running a class with a main method or a unit test
-# (you may also define separate properties like run-sys-prop.name=value instead of -Dname=value):
-runmain.jvmargs=
-source.encoding=UTF-8
-source.root=src
-src.dir=${source.root}/java
-test.src.dir=test
-war.content.additional=
-war.ear.name=com.juick.api.war
-war.name=com.juick.api.war
-web.docbase.dir=web
-webinf.dir=web/WEB-INF
diff --git a/nbproject/project.xml b/nbproject/project.xml
deleted file mode 100644
index 01e2f8c9..00000000
--- a/nbproject/project.xml
+++ /dev/null
@@ -1,77 +0,0 @@
-
-
- org.netbeans.modules.web.project
-
-
- com.juick.api
- 1.6.5
-
-
- ${reference.com_juick.jar}
- WEB-INF/lib
-
-
- ${reference.com_juick_server.jar}
- WEB-INF/lib
-
-
- ${reference.com_juick_json.jar}
- WEB-INF/lib
-
-
- ${reference.com_juick_xmpp.jar}
- WEB-INF/lib
-
-
- ${libs.JSON.classpath}
- WEB-INF/lib
-
-
- ${file.reference.xpp3_min-1.1.4.jar}
- WEB-INF/lib
-
-
-
-
-
-
-
-
-
-
-
-
- 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..d775a49a
--- /dev/null
+++ b/settings.gradle
@@ -0,0 +1 @@
+include ':deps:com.juick', ':deps:com.juick.server', ':deps:com.juick.xmpp', ':deps:com.juick.json'
diff --git a/src/conf/MANIFEST.MF b/src/conf/MANIFEST.MF
deleted file mode 100644
index 59499bce..00000000
--- a/src/conf/MANIFEST.MF
+++ /dev/null
@@ -1,2 +0,0 @@
-Manifest-Version: 1.0
-
diff --git a/src/java/com/juick/api/Main.java b/src/java/com/juick/api/Main.java
deleted file mode 100644
index 5ee4027b..00000000
--- a/src/java/com/juick/api/Main.java
+++ /dev/null
@@ -1,231 +0,0 @@
-/*
- * Juick
- * Copyright (C) 2008-2013, 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.api;
-
-import com.juick.xmpp.JID;
-import com.juick.xmpp.Stream;
-import com.juick.xmpp.StreamComponent;
-import java.io.FileInputStream;
-import java.io.IOException;
-import java.io.PrintWriter;
-import java.net.Socket;
-import java.sql.Connection;
-import java.sql.DriverManager;
-import java.sql.SQLException;
-import java.util.Properties;
-import javax.servlet.ServletException;
-import javax.servlet.annotation.MultipartConfig;
-import javax.servlet.annotation.WebServlet;
-import javax.servlet.http.HttpServlet;
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
-
-/**
- *
- * @author Ugnich Anton
- */
-@WebServlet(name = "Main", urlPatterns = {"/"})
-@MultipartConfig
-public class Main extends HttpServlet implements Stream.StreamListener {
-
- Connection sql;
- Connection sqlSearch;
- Stream xmpp;
- Messages messages;
- Users users;
- PM pm;
- Others others;
-
- @Override
- public void init() throws ServletException {
- super.init();
- try {
- Properties conf = new Properties();
- conf.load(new FileInputStream("/etc/juick/api.conf"));
-
- Class.forName("com.mysql.jdbc.Driver");
- sql = DriverManager.getConnection("jdbc:mysql://localhost/juick?autoReconnect=true&user=" + conf.getProperty("mysql_username", "") + "&password=" + conf.getProperty("mysql_password", ""));
- sqlSearch = DriverManager.getConnection("jdbc:mysql://127.0.0.1:9306/juick?autoReconnect=true&characterEncoding=utf8&maxAllowedPacket=512000&relaxAutoCommit=true&user=root&password=");
-
- messages = new Messages(sql);
- users = new Users(sql);
- pm = new PM(sql);
- others = new Others(sql);
-
- setupXmppComponent(conf.getProperty("xmpp_password"));
-
- } catch (Exception e) {
- log(null, e);
- }
- }
-
- public void setupXmppComponent(final String password) {
- Thread thr = new Thread(new Runnable() {
-
- @Override
- public void run() {
- try {
- Socket socket = new Socket("localhost", 5347);
- xmpp = new StreamComponent(new JID("", "api.juick.com", ""), socket.getInputStream(), socket.getOutputStream(), password);
- xmpp.addListener(Main.this);
- xmpp.startParsing();
- } catch (IOException e) {
- System.err.println(e);
- }
- }
- });
- thr.start();
- }
-
- @Override
- public void onStreamFail(String msg) {
- System.err.println("XMPP STREAM FAIL: " + msg);
- }
-
- @Override
- public void onStreamReady() {
- System.err.println("XMPP STREAM READY");
- }
-
- @Override
- public void destroy() {
- super.destroy();
- if (sql != null) {
- try {
- sql.close();
- sql = null;
- } catch (SQLException e) {
- log(null, e);
- }
- }
- if (sqlSearch != null) {
- try {
- sqlSearch.close();
- sqlSearch = null;
- } catch (SQLException e) {
- log(null, e);
- }
- }
- }
-
- /**
- * Handles the HTTP GET
method.
- * @param request servlet request
- * @param response servlet response
- * @throws ServletException if a servlet-specific error occurs
- * @throws IOException if an I/O error occurs
- */
- @Override
- protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
- if (request.getCharacterEncoding() == null) {
- request.setCharacterEncoding("UTF-8");
- }
-
- int vuid = Utils.getHttpAuthUID(sql, request);
- if (vuid == 0) {
- vuid = Utils.getVisitorQueryStringUID(sql, request);
- }
-
- String uri = request.getRequestURI();
- if (uri.equals("/home")) {
- if (vuid > 0) {
- messages.doGetHome(request, response, vuid);
- } else {
- response.sendError(401);
- }
- } else if (uri.equals("/users")) {
- users.doGetUsers(request, response, vuid);
- } else if (uri.equals("/users/read")) {
- users.doGetUserRead(request, response, vuid);
- } else if (uri.equals("/users/readers")) {
- users.doGetUserReaders(request, response, vuid);
- } else if (uri.equals("/pm")) {
- if (vuid > 0) {
- pm.doGetPM(request, response, vuid);
- } else {
- response.sendError(401);
- }
- } else if (uri.equals("/groups_pms")) {
- if (vuid > 0) {
- others.doGetGroupsPMs(request, response, vuid);
- } else {
- response.sendError(401);
- }
- } else if (uri.equals("/messages/set_popular") && vuid == 1) {
- messages.doSetPopular(request, response, xmpp);
- } else if (uri.equals("/messages/set_privacy") && vuid > 0) {
- messages.doSetPrivacy(request, response, xmpp, vuid);
- } else {
- response.sendError(404);
- }
- }
-
- /**
- * Handles the HTTP POST
method.
- * @param request servlet request
- * @param response servlet response
- * @throws ServletException if a servlet-specific error occurs
- * @throws IOException if an I/O error occurs
- */
- @Override
- protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
- if (request.getCharacterEncoding() == null) {
- request.setCharacterEncoding("UTF-8");
- }
-
- int vuid = Utils.getHttpAuthUID(sql, request);
- if (vuid == 0) {
- vuid = Utils.getVisitorQueryStringUID(sql, request);
- }
- if (vuid == 0) {
- response.sendError(401);
- return;
- }
-
- String uri = request.getRequestURI();
- if (uri.equals("/post")) {
- } else if (uri.equals("/pm")) {
- pm.doPostPM(request, response, xmpp, vuid);
- } else {
- response.sendError(405);
- }
- }
-
- public static void replyJSON(HttpServletRequest request, HttpServletResponse response, String json) throws IOException {
- response.setContentType("application/json; charset=UTF-8");
- response.setHeader("Access-Control-Allow-Origin", "*");
-
- String callback = request.getParameter("callback");
- if (callback != null && (callback.length() > 64 || !callback.matches("[a-zA-Z0-9\\-\\_]+"))) {
- callback = null;
- }
-
- PrintWriter out = response.getWriter();
- try {
- if (callback != null) {
- out.print(callback + "(");
- out.print(json);
- out.print(")");
- } else {
- out.print(json);
- }
- } finally {
- out.close();
- }
- }
-}
diff --git a/src/java/com/juick/api/Messages.java b/src/java/com/juick/api/Messages.java
deleted file mode 100644
index b5462258..00000000
--- a/src/java/com/juick/api/Messages.java
+++ /dev/null
@@ -1,89 +0,0 @@
-package com.juick.api;
-
-import com.juick.server.MessagesQueries;
-import com.juick.xmpp.JID;
-import com.juick.xmpp.Message;
-import com.juick.xmpp.Stream;
-import com.juick.xmpp.extensions.JuickMessage;
-import java.io.IOException;
-import java.sql.Connection;
-import java.util.ArrayList;
-import javax.servlet.ServletException;
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
-
-/**
- *
- * @author ugnich
- */
-public class Messages {
-
- Connection sql;
-
- public Messages(Connection sql) {
- this.sql = sql;
- }
-
- public void doGetHome(HttpServletRequest request, HttpServletResponse response, int vuid) throws ServletException, IOException {
- int before_mid = Utils.parseInt(request.getParameter("before_mid"), 0);
-
- ArrayList mids = MessagesQueries.getMyFeed(sql, vuid, before_mid);
- if (mids != null && !mids.isEmpty()) {
- ArrayList msgs = MessagesQueries.getMessages(sql, mids);
- if (msgs != null && !msgs.isEmpty()) {
- String json = com.juick.json.Messages.arrayToString(msgs);
- Main.replyJSON(request, response, json);
- } else {
- response.sendError(404);
- }
- } else {
- response.sendError(404);
- }
- }
-
- public void doSetPrivacy(HttpServletRequest request, HttpServletResponse response, Stream xmpp, int vuid) throws ServletException, IOException {
- int mid = Utils.parseInt(request.getParameter("mid"), 0);
- com.juick.User user = MessagesQueries.getMessageAuthor(sql, mid);
- if (user != null && user.UID == vuid && MessagesQueries.setMessagePrivacy(sql, mid)) {
- Main.replyJSON(request, response, "{\"status\":\"ok\"}");
- } else {
- response.sendError(400);
- }
- }
-
- public void doSetPopular(HttpServletRequest request, HttpServletResponse response, Stream xmpp) throws ServletException, IOException {
- int mid = Utils.parseInt(request.getParameter("mid"), 0);
- int popular = Utils.parseInt(request.getParameter("popular"), 0);
-
- if (mid > 0) {
- boolean ret = MessagesQueries.setMessagePopular(sql, mid, popular);
-
- if (ret && popular == 2) {
- try {
- com.juick.Message m = MessagesQueries.getMessage(sql, mid);
- if (m != null) {
- Message msg = new Message();
- msg.from = new JID("juick", "juick.com", null);
- msg.to = new JID(null, "crosspost.juick.com", null);
- JuickMessage jmsg = new JuickMessage(m);
- jmsg.User.UID = 11574;
- msg.childs.add(jmsg);
-
- msg.to.Username = "twitter";
- xmpp.send(msg);
- msg.to.Username = "fb";
- xmpp.send(msg);
- msg.to.Username = "vk";
- xmpp.send(msg);
- } else {
- throw new Exception("Message not found");
- }
- } catch (Exception e) {
- System.err.println("SETPOPULAR ERROR: " + e.toString());
- }
- }
-
- Main.replyJSON(request, response, "{\"status\":\"ok\"}");
- }
- }
-}
diff --git a/src/java/com/juick/api/Others.java b/src/java/com/juick/api/Others.java
deleted file mode 100644
index 25df5bf4..00000000
--- a/src/java/com/juick/api/Others.java
+++ /dev/null
@@ -1,45 +0,0 @@
-package com.juick.api;
-
-import com.juick.server.PMQueries;
-import java.io.IOException;
-import java.sql.Connection;
-import java.util.ArrayList;
-import javax.servlet.ServletException;
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
-
-/**
- *
- * @author ugnich
- */
-public class Others {
-
- Connection sql;
-
- public Others(Connection sql) {
- this.sql = sql;
- }
-
- public void doGetGroupsPMs(HttpServletRequest request, HttpServletResponse response, int vuid) throws ServletException, IOException {
- int cnt = 5;
- try {
- String cntStr = request.getParameter("cnt");
- cnt = Integer.parseInt(cntStr);
- if (cnt < 3) {
- cnt = 3;
- }
- if (cnt > 10) {
- cnt = 10;
- }
- } catch (Exception e) {
- }
-
- ArrayList lastconv = PMQueries.getPMLastConversationsUsers(sql, vuid, cnt);
- if (lastconv != null && !lastconv.isEmpty()) {
- String json = "{\"pms\":" + com.juick.json.Users.arrayToString(lastconv) + "}";
- Main.replyJSON(request, response, json);
- } else {
- response.sendError(404);
- }
- }
-}
diff --git a/src/java/com/juick/api/PM.java b/src/java/com/juick/api/PM.java
deleted file mode 100644
index 2722526d..00000000
--- a/src/java/com/juick/api/PM.java
+++ /dev/null
@@ -1,101 +0,0 @@
-package com.juick.api;
-
-import com.juick.server.PMQueries;
-import com.juick.server.UserQueries;
-import com.juick.xmpp.JID;
-import com.juick.xmpp.Message;
-import com.juick.xmpp.Stream;
-import com.juick.xmpp.extensions.JuickMessage;
-import java.io.IOException;
-import java.sql.Connection;
-import java.util.ArrayList;
-import javax.servlet.ServletException;
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
-
-/**
- *
- * @author ugnich
- */
-public class PM {
-
- Connection sql;
-
- public PM(Connection sql) {
- this.sql = sql;
- }
-
- public void doGetPM(HttpServletRequest request, HttpServletResponse response, int vuid) throws ServletException, IOException {
- String uname = request.getParameter("uname");
- int uid = 0;
- if (uname != null && uname.matches("^[a-zA-Z0-9\\-]{2,16}$")) {
- uid = UserQueries.getUIDbyName(sql, uname);
- }
-
- if (uid == 0) {
- response.sendError(400);
- return;
- }
-
- ArrayList msgs = PMQueries.getPMMessages(sql, vuid, uid);
- if (msgs != null && !msgs.isEmpty()) {
- String json = com.juick.json.Messages.arrayToString(msgs);
- Main.replyJSON(request, response, json);
- } else {
- response.sendError(404);
- }
- }
-
- public void doPostPM(HttpServletRequest request, HttpServletResponse response, Stream xmpp, int vuid) throws ServletException, IOException {
- String uname = request.getParameter("uname");
- int uid = 0;
- if (UserQueries.checkUserNameValid(uname)) {
- uid = UserQueries.getUIDbyName(sql, uname);
- }
-
- String body = request.getParameter("body");
- if (uid == 0 || body == null || body.length() < 1 || body.length() > 10240) {
- response.sendError(400);
- return;
- }
-
- if (UserQueries.isInBLAny(sql, uid, vuid)) {
- response.sendError(403);
- return;
- }
-
- if (PMQueries.createPM(sql, vuid, uid, body)) {
- Message msg = new Message();
- msg.from = new JID("juick", "juick.com", null);
- msg.to = new JID(Integer.toString(uid), "push.juick.com", null);
- JuickMessage jmsg = new JuickMessage();
- jmsg.User = UserQueries.getUserByUID(sql, vuid);
- jmsg.Text = body;
- msg.childs.add(jmsg);
- xmpp.send(msg);
-
- msg.to.Host = "ws.juick.com";
- xmpp.send(msg);
-
- Main.replyJSON(request, response, com.juick.json.Message.toJSON(jmsg).toString());
-
- String jid = UserQueries.getJIDbyUID(sql, uid);
- if (jid != null) {
- Message mm = new Message();
- mm.to = new JID(jid);
- mm.type = Message.Type.chat;
- if (PMQueries.havePMinRoster(sql, vuid, jid)) {
- mm.from = new JID(jmsg.User.UName, "juick.com", "Juick");
- mm.body = body;
- } else {
- mm.from = new JID("juick", "juick.com", "Juick");
- mm.body = "Private message from @" + jmsg.User.UName + ":\n" + body;
- }
- xmpp.send(mm);
- }
-
- } else {
- response.sendError(500);
- }
- }
-}
diff --git a/src/java/com/juick/api/Users.java b/src/java/com/juick/api/Users.java
deleted file mode 100644
index cdd48fd6..00000000
--- a/src/java/com/juick/api/Users.java
+++ /dev/null
@@ -1,120 +0,0 @@
-package com.juick.api;
-
-import com.juick.User;
-import com.juick.server.UserQueries;
-import java.io.IOException;
-import java.sql.Connection;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Iterator;
-import javax.servlet.ServletException;
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
-
-/**
- *
- * @author ugnich
- */
-public class Users {
-
- Connection sql;
-
- public Users(Connection sql) {
- this.sql = sql;
- }
-
- public void doGetUsers(HttpServletRequest request, HttpServletResponse response, int vuid) throws ServletException, IOException {
- ArrayList users = new ArrayList();
-
- String punames[] = request.getParameterValues("uname");
- if (punames != null) {
- ArrayList unames = new ArrayList(Arrays.asList(punames));
- Iterator i = unames.iterator();
- while (i.hasNext()) {
- if (!i.next().matches("^[a-zA-Z0-9\\-]{2,16}$")) {
- i.remove();
- }
- }
- if (!unames.isEmpty() && unames.size() < 20) {
- users.addAll(UserQueries.getUsersByName(sql, unames));
- }
- }
-
- String pjids[] = request.getParameterValues("jid");
- if (pjids != null) {
- ArrayList jids = new ArrayList(Arrays.asList(pjids));
- Iterator ii = jids.iterator();
- while (ii.hasNext()) {
- if (!ii.next().matches("^[a-zA-Z0-9\\-\\_\\@\\.]{6,64}$")) {
- ii.remove();
- }
- }
- if (!jids.isEmpty() && jids.size() < 20) {
- users.addAll(UserQueries.getUsersByJID(sql, jids));
- }
- }
-
- if (!users.isEmpty()) {
- String json = com.juick.json.Users.arrayToString(users);
- Main.replyJSON(request, response, json);
- } else {
- response.sendError(404);
- }
- }
-
- public void doGetUserRead(HttpServletRequest request, HttpServletResponse response, int vuid) throws ServletException, IOException {
- int uid = 0;
- String uname = request.getParameter("uname");
- if (uname == null) {
- uid = vuid;
- } else {
- if (UserQueries.checkUserNameValid(uname)) {
- com.juick.User u = UserQueries.getUserByName(sql, uname);
- if (u != null && u.UID > 0) {
- uid = u.UID;
- }
- }
- }
-
- if (uid > 0) {
- ArrayList uids = UserQueries.getUserRead(sql, uid);
- if (uids.size() > 0) {
- ArrayList users = UserQueries.getUsersByID(sql, uids);
- if (users.size() > 0) {
- String json = com.juick.json.Users.arrayToString(users);
- Main.replyJSON(request, response, json);
- return;
- }
- }
- }
- response.sendError(404);
- }
-
- public void doGetUserReaders(HttpServletRequest request, HttpServletResponse response, int vuid) throws ServletException, IOException {
- int uid = 0;
- String uname = request.getParameter("uname");
- if (uname == null) {
- uid = vuid;
- } else {
- if (UserQueries.checkUserNameValid(uname)) {
- com.juick.User u = UserQueries.getUserByName(sql, uname);
- if (u != null && u.UID > 0) {
- uid = u.UID;
- }
- }
- }
-
- if (uid > 0) {
- ArrayList uids = UserQueries.getUserReaders(sql, uid);
- if (uids.size() > 0) {
- ArrayList users = UserQueries.getUsersByID(sql, uids);
- if (users.size() > 0) {
- String json = com.juick.json.Users.arrayToString(users);
- Main.replyJSON(request, response, json);
- return;
- }
- }
- }
- response.sendError(404);
- }
-}
diff --git a/src/java/com/juick/api/Utils.java b/src/java/com/juick/api/Utils.java
deleted file mode 100644
index 10e0cccb..00000000
--- a/src/java/com/juick/api/Utils.java
+++ /dev/null
@@ -1,149 +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.api;
-
-import com.juick.server.UserQueries;
-import java.io.IOException;
-import java.sql.Connection;
-import java.sql.ResultSet;
-import java.sql.SQLException;
-import java.sql.Statement;
-import java.util.ArrayList;
-import javax.servlet.http.Cookie;
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
-import sun.misc.BASE64Decoder;
-
-/**
- *
- * @author Ugnich Anton
- */
-public class Utils {
-
- public static String getCookie(HttpServletRequest request, String name) {
- Cookie cookies[] = request.getCookies();
- if (cookies != null) {
- for (int i = 0; i < cookies.length; i++) {
- if (cookies[i].getName().equals(name)) {
- return cookies[i].getValue();
- }
- }
- }
- return null;
- }
-
- public static com.juick.User getVisitorUser(Connection sql, HttpServletRequest request) {
- String hash = getCookie(request, "hash");
- if (hash != null) {
- return com.juick.server.UserQueries.getUserByHash(sql, hash);
- } else {
- return null;
- }
- }
-
- public static int getVisitorUID(Connection sql, HttpServletRequest request) {
- Cookie cookies[] = request.getCookies();
- if (cookies != null) {
- for (int i = 0; i < cookies.length; i++) {
- if (cookies[i].getName().equals("hash")) {
- String hash = cookies[i].getValue();
- return com.juick.server.UserQueries.getUIDbyHash(sql, hash);
- }
- }
- }
- return 0;
- }
-
- public static int getHttpAuthUID(Connection sql, HttpServletRequest request) {
- String auth = request.getHeader("Authorization");
- if (auth != null && auth.length() > 8 && auth.startsWith("Basic ")) {
- try {
- BASE64Decoder dec = new BASE64Decoder();
- String loginpassw[] = new String(dec.decodeBuffer(auth.substring(6))).split(":", 2);
- if (loginpassw.length == 2 && loginpassw[0].length() > 1 && loginpassw[0].length() < 16 && loginpassw[0].matches("[a-zA-Z0-9\\-]+") && !loginpassw[1].isEmpty()) {
- return UserQueries.checkPassword(sql, loginpassw[0], loginpassw[1]);
- }
- } catch (IOException e) {
- }
- }
- return 0;
- }
-
- public static int getVisitorQueryStringUID(Connection sql, HttpServletRequest request) {
- String hash = request.getParameter("hash");
- if (hash != null && hash.length() == 16) {
- return com.juick.server.UserQueries.getUIDbyHash(sql, hash);
- }
- return 0;
- }
-
- public static void sendPermanentRedirect(HttpServletResponse response, String location) {
- response.setStatus(HttpServletResponse.SC_MOVED_PERMANENTLY);
- response.setHeader("Location", location);
- }
-
- public static void finishSQL(ResultSet rs, Statement stmt) {
- if (rs != null) {
- try {
- rs.close();
- } catch (SQLException e) {
- }
- }
- if (stmt != null) {
- try {
- stmt.close();
- } catch (SQLException e) {
- }
- }
- }
-
- public static String convertArray2String(ArrayList mids) {
- String q = "";
- for (int i = 0; i < mids.size(); i++) {
- if (i > 0) {
- q += ",";
- }
- q += mids.get(i);
- }
- return q;
- }
-
- public static String encodeHTML(String str) {
- String ret = str;
- ret = ret.replaceAll("<", "<");
- ret = ret.replaceAll(">", ">");
- return str;
- }
-
- public static String encodeSphinx(String str) {
- String ret = str;
- ret = ret.replaceAll("@", "\\\\@");
- return ret;
- }
-
- public static int parseInt(String str, int def) {
- int ret = def;
- if (str != null) {
- try {
- ret = Integer.parseInt(str);
- } catch (Exception e) {
- }
- }
- return ret;
- }
-}
diff --git a/src/main/java/com/juick/api/Main.java b/src/main/java/com/juick/api/Main.java
new file mode 100644
index 00000000..5ee4027b
--- /dev/null
+++ b/src/main/java/com/juick/api/Main.java
@@ -0,0 +1,231 @@
+/*
+ * Juick
+ * Copyright (C) 2008-2013, 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.api;
+
+import com.juick.xmpp.JID;
+import com.juick.xmpp.Stream;
+import com.juick.xmpp.StreamComponent;
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.io.PrintWriter;
+import java.net.Socket;
+import java.sql.Connection;
+import java.sql.DriverManager;
+import java.sql.SQLException;
+import java.util.Properties;
+import javax.servlet.ServletException;
+import javax.servlet.annotation.MultipartConfig;
+import javax.servlet.annotation.WebServlet;
+import javax.servlet.http.HttpServlet;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+/**
+ *
+ * @author Ugnich Anton
+ */
+@WebServlet(name = "Main", urlPatterns = {"/"})
+@MultipartConfig
+public class Main extends HttpServlet implements Stream.StreamListener {
+
+ Connection sql;
+ Connection sqlSearch;
+ Stream xmpp;
+ Messages messages;
+ Users users;
+ PM pm;
+ Others others;
+
+ @Override
+ public void init() throws ServletException {
+ super.init();
+ try {
+ Properties conf = new Properties();
+ conf.load(new FileInputStream("/etc/juick/api.conf"));
+
+ Class.forName("com.mysql.jdbc.Driver");
+ sql = DriverManager.getConnection("jdbc:mysql://localhost/juick?autoReconnect=true&user=" + conf.getProperty("mysql_username", "") + "&password=" + conf.getProperty("mysql_password", ""));
+ sqlSearch = DriverManager.getConnection("jdbc:mysql://127.0.0.1:9306/juick?autoReconnect=true&characterEncoding=utf8&maxAllowedPacket=512000&relaxAutoCommit=true&user=root&password=");
+
+ messages = new Messages(sql);
+ users = new Users(sql);
+ pm = new PM(sql);
+ others = new Others(sql);
+
+ setupXmppComponent(conf.getProperty("xmpp_password"));
+
+ } catch (Exception e) {
+ log(null, e);
+ }
+ }
+
+ public void setupXmppComponent(final String password) {
+ Thread thr = new Thread(new Runnable() {
+
+ @Override
+ public void run() {
+ try {
+ Socket socket = new Socket("localhost", 5347);
+ xmpp = new StreamComponent(new JID("", "api.juick.com", ""), socket.getInputStream(), socket.getOutputStream(), password);
+ xmpp.addListener(Main.this);
+ xmpp.startParsing();
+ } catch (IOException e) {
+ System.err.println(e);
+ }
+ }
+ });
+ thr.start();
+ }
+
+ @Override
+ public void onStreamFail(String msg) {
+ System.err.println("XMPP STREAM FAIL: " + msg);
+ }
+
+ @Override
+ public void onStreamReady() {
+ System.err.println("XMPP STREAM READY");
+ }
+
+ @Override
+ public void destroy() {
+ super.destroy();
+ if (sql != null) {
+ try {
+ sql.close();
+ sql = null;
+ } catch (SQLException e) {
+ log(null, e);
+ }
+ }
+ if (sqlSearch != null) {
+ try {
+ sqlSearch.close();
+ sqlSearch = null;
+ } catch (SQLException e) {
+ log(null, e);
+ }
+ }
+ }
+
+ /**
+ * Handles the HTTP GET
method.
+ * @param request servlet request
+ * @param response servlet response
+ * @throws ServletException if a servlet-specific error occurs
+ * @throws IOException if an I/O error occurs
+ */
+ @Override
+ protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
+ if (request.getCharacterEncoding() == null) {
+ request.setCharacterEncoding("UTF-8");
+ }
+
+ int vuid = Utils.getHttpAuthUID(sql, request);
+ if (vuid == 0) {
+ vuid = Utils.getVisitorQueryStringUID(sql, request);
+ }
+
+ String uri = request.getRequestURI();
+ if (uri.equals("/home")) {
+ if (vuid > 0) {
+ messages.doGetHome(request, response, vuid);
+ } else {
+ response.sendError(401);
+ }
+ } else if (uri.equals("/users")) {
+ users.doGetUsers(request, response, vuid);
+ } else if (uri.equals("/users/read")) {
+ users.doGetUserRead(request, response, vuid);
+ } else if (uri.equals("/users/readers")) {
+ users.doGetUserReaders(request, response, vuid);
+ } else if (uri.equals("/pm")) {
+ if (vuid > 0) {
+ pm.doGetPM(request, response, vuid);
+ } else {
+ response.sendError(401);
+ }
+ } else if (uri.equals("/groups_pms")) {
+ if (vuid > 0) {
+ others.doGetGroupsPMs(request, response, vuid);
+ } else {
+ response.sendError(401);
+ }
+ } else if (uri.equals("/messages/set_popular") && vuid == 1) {
+ messages.doSetPopular(request, response, xmpp);
+ } else if (uri.equals("/messages/set_privacy") && vuid > 0) {
+ messages.doSetPrivacy(request, response, xmpp, vuid);
+ } else {
+ response.sendError(404);
+ }
+ }
+
+ /**
+ * Handles the HTTP POST
method.
+ * @param request servlet request
+ * @param response servlet response
+ * @throws ServletException if a servlet-specific error occurs
+ * @throws IOException if an I/O error occurs
+ */
+ @Override
+ protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
+ if (request.getCharacterEncoding() == null) {
+ request.setCharacterEncoding("UTF-8");
+ }
+
+ int vuid = Utils.getHttpAuthUID(sql, request);
+ if (vuid == 0) {
+ vuid = Utils.getVisitorQueryStringUID(sql, request);
+ }
+ if (vuid == 0) {
+ response.sendError(401);
+ return;
+ }
+
+ String uri = request.getRequestURI();
+ if (uri.equals("/post")) {
+ } else if (uri.equals("/pm")) {
+ pm.doPostPM(request, response, xmpp, vuid);
+ } else {
+ response.sendError(405);
+ }
+ }
+
+ public static void replyJSON(HttpServletRequest request, HttpServletResponse response, String json) throws IOException {
+ response.setContentType("application/json; charset=UTF-8");
+ response.setHeader("Access-Control-Allow-Origin", "*");
+
+ String callback = request.getParameter("callback");
+ if (callback != null && (callback.length() > 64 || !callback.matches("[a-zA-Z0-9\\-\\_]+"))) {
+ callback = null;
+ }
+
+ PrintWriter out = response.getWriter();
+ try {
+ if (callback != null) {
+ out.print(callback + "(");
+ out.print(json);
+ out.print(")");
+ } else {
+ out.print(json);
+ }
+ } finally {
+ out.close();
+ }
+ }
+}
diff --git a/src/main/java/com/juick/api/Messages.java b/src/main/java/com/juick/api/Messages.java
new file mode 100644
index 00000000..b5462258
--- /dev/null
+++ b/src/main/java/com/juick/api/Messages.java
@@ -0,0 +1,89 @@
+package com.juick.api;
+
+import com.juick.server.MessagesQueries;
+import com.juick.xmpp.JID;
+import com.juick.xmpp.Message;
+import com.juick.xmpp.Stream;
+import com.juick.xmpp.extensions.JuickMessage;
+import java.io.IOException;
+import java.sql.Connection;
+import java.util.ArrayList;
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+/**
+ *
+ * @author ugnich
+ */
+public class Messages {
+
+ Connection sql;
+
+ public Messages(Connection sql) {
+ this.sql = sql;
+ }
+
+ public void doGetHome(HttpServletRequest request, HttpServletResponse response, int vuid) throws ServletException, IOException {
+ int before_mid = Utils.parseInt(request.getParameter("before_mid"), 0);
+
+ ArrayList mids = MessagesQueries.getMyFeed(sql, vuid, before_mid);
+ if (mids != null && !mids.isEmpty()) {
+ ArrayList msgs = MessagesQueries.getMessages(sql, mids);
+ if (msgs != null && !msgs.isEmpty()) {
+ String json = com.juick.json.Messages.arrayToString(msgs);
+ Main.replyJSON(request, response, json);
+ } else {
+ response.sendError(404);
+ }
+ } else {
+ response.sendError(404);
+ }
+ }
+
+ public void doSetPrivacy(HttpServletRequest request, HttpServletResponse response, Stream xmpp, int vuid) throws ServletException, IOException {
+ int mid = Utils.parseInt(request.getParameter("mid"), 0);
+ com.juick.User user = MessagesQueries.getMessageAuthor(sql, mid);
+ if (user != null && user.UID == vuid && MessagesQueries.setMessagePrivacy(sql, mid)) {
+ Main.replyJSON(request, response, "{\"status\":\"ok\"}");
+ } else {
+ response.sendError(400);
+ }
+ }
+
+ public void doSetPopular(HttpServletRequest request, HttpServletResponse response, Stream xmpp) throws ServletException, IOException {
+ int mid = Utils.parseInt(request.getParameter("mid"), 0);
+ int popular = Utils.parseInt(request.getParameter("popular"), 0);
+
+ if (mid > 0) {
+ boolean ret = MessagesQueries.setMessagePopular(sql, mid, popular);
+
+ if (ret && popular == 2) {
+ try {
+ com.juick.Message m = MessagesQueries.getMessage(sql, mid);
+ if (m != null) {
+ Message msg = new Message();
+ msg.from = new JID("juick", "juick.com", null);
+ msg.to = new JID(null, "crosspost.juick.com", null);
+ JuickMessage jmsg = new JuickMessage(m);
+ jmsg.User.UID = 11574;
+ msg.childs.add(jmsg);
+
+ msg.to.Username = "twitter";
+ xmpp.send(msg);
+ msg.to.Username = "fb";
+ xmpp.send(msg);
+ msg.to.Username = "vk";
+ xmpp.send(msg);
+ } else {
+ throw new Exception("Message not found");
+ }
+ } catch (Exception e) {
+ System.err.println("SETPOPULAR ERROR: " + e.toString());
+ }
+ }
+
+ Main.replyJSON(request, response, "{\"status\":\"ok\"}");
+ }
+ }
+}
diff --git a/src/main/java/com/juick/api/Others.java b/src/main/java/com/juick/api/Others.java
new file mode 100644
index 00000000..25df5bf4
--- /dev/null
+++ b/src/main/java/com/juick/api/Others.java
@@ -0,0 +1,45 @@
+package com.juick.api;
+
+import com.juick.server.PMQueries;
+import java.io.IOException;
+import java.sql.Connection;
+import java.util.ArrayList;
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+/**
+ *
+ * @author ugnich
+ */
+public class Others {
+
+ Connection sql;
+
+ public Others(Connection sql) {
+ this.sql = sql;
+ }
+
+ public void doGetGroupsPMs(HttpServletRequest request, HttpServletResponse response, int vuid) throws ServletException, IOException {
+ int cnt = 5;
+ try {
+ String cntStr = request.getParameter("cnt");
+ cnt = Integer.parseInt(cntStr);
+ if (cnt < 3) {
+ cnt = 3;
+ }
+ if (cnt > 10) {
+ cnt = 10;
+ }
+ } catch (Exception e) {
+ }
+
+ ArrayList lastconv = PMQueries.getPMLastConversationsUsers(sql, vuid, cnt);
+ if (lastconv != null && !lastconv.isEmpty()) {
+ String json = "{\"pms\":" + com.juick.json.Users.arrayToString(lastconv) + "}";
+ Main.replyJSON(request, response, json);
+ } else {
+ response.sendError(404);
+ }
+ }
+}
diff --git a/src/main/java/com/juick/api/PM.java b/src/main/java/com/juick/api/PM.java
new file mode 100644
index 00000000..2722526d
--- /dev/null
+++ b/src/main/java/com/juick/api/PM.java
@@ -0,0 +1,101 @@
+package com.juick.api;
+
+import com.juick.server.PMQueries;
+import com.juick.server.UserQueries;
+import com.juick.xmpp.JID;
+import com.juick.xmpp.Message;
+import com.juick.xmpp.Stream;
+import com.juick.xmpp.extensions.JuickMessage;
+import java.io.IOException;
+import java.sql.Connection;
+import java.util.ArrayList;
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+/**
+ *
+ * @author ugnich
+ */
+public class PM {
+
+ Connection sql;
+
+ public PM(Connection sql) {
+ this.sql = sql;
+ }
+
+ public void doGetPM(HttpServletRequest request, HttpServletResponse response, int vuid) throws ServletException, IOException {
+ String uname = request.getParameter("uname");
+ int uid = 0;
+ if (uname != null && uname.matches("^[a-zA-Z0-9\\-]{2,16}$")) {
+ uid = UserQueries.getUIDbyName(sql, uname);
+ }
+
+ if (uid == 0) {
+ response.sendError(400);
+ return;
+ }
+
+ ArrayList msgs = PMQueries.getPMMessages(sql, vuid, uid);
+ if (msgs != null && !msgs.isEmpty()) {
+ String json = com.juick.json.Messages.arrayToString(msgs);
+ Main.replyJSON(request, response, json);
+ } else {
+ response.sendError(404);
+ }
+ }
+
+ public void doPostPM(HttpServletRequest request, HttpServletResponse response, Stream xmpp, int vuid) throws ServletException, IOException {
+ String uname = request.getParameter("uname");
+ int uid = 0;
+ if (UserQueries.checkUserNameValid(uname)) {
+ uid = UserQueries.getUIDbyName(sql, uname);
+ }
+
+ String body = request.getParameter("body");
+ if (uid == 0 || body == null || body.length() < 1 || body.length() > 10240) {
+ response.sendError(400);
+ return;
+ }
+
+ if (UserQueries.isInBLAny(sql, uid, vuid)) {
+ response.sendError(403);
+ return;
+ }
+
+ if (PMQueries.createPM(sql, vuid, uid, body)) {
+ Message msg = new Message();
+ msg.from = new JID("juick", "juick.com", null);
+ msg.to = new JID(Integer.toString(uid), "push.juick.com", null);
+ JuickMessage jmsg = new JuickMessage();
+ jmsg.User = UserQueries.getUserByUID(sql, vuid);
+ jmsg.Text = body;
+ msg.childs.add(jmsg);
+ xmpp.send(msg);
+
+ msg.to.Host = "ws.juick.com";
+ xmpp.send(msg);
+
+ Main.replyJSON(request, response, com.juick.json.Message.toJSON(jmsg).toString());
+
+ String jid = UserQueries.getJIDbyUID(sql, uid);
+ if (jid != null) {
+ Message mm = new Message();
+ mm.to = new JID(jid);
+ mm.type = Message.Type.chat;
+ if (PMQueries.havePMinRoster(sql, vuid, jid)) {
+ mm.from = new JID(jmsg.User.UName, "juick.com", "Juick");
+ mm.body = body;
+ } else {
+ mm.from = new JID("juick", "juick.com", "Juick");
+ mm.body = "Private message from @" + jmsg.User.UName + ":\n" + body;
+ }
+ xmpp.send(mm);
+ }
+
+ } else {
+ response.sendError(500);
+ }
+ }
+}
diff --git a/src/main/java/com/juick/api/Users.java b/src/main/java/com/juick/api/Users.java
new file mode 100644
index 00000000..cdd48fd6
--- /dev/null
+++ b/src/main/java/com/juick/api/Users.java
@@ -0,0 +1,120 @@
+package com.juick.api;
+
+import com.juick.User;
+import com.juick.server.UserQueries;
+import java.io.IOException;
+import java.sql.Connection;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Iterator;
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+/**
+ *
+ * @author ugnich
+ */
+public class Users {
+
+ Connection sql;
+
+ public Users(Connection sql) {
+ this.sql = sql;
+ }
+
+ public void doGetUsers(HttpServletRequest request, HttpServletResponse response, int vuid) throws ServletException, IOException {
+ ArrayList users = new ArrayList();
+
+ String punames[] = request.getParameterValues("uname");
+ if (punames != null) {
+ ArrayList unames = new ArrayList(Arrays.asList(punames));
+ Iterator i = unames.iterator();
+ while (i.hasNext()) {
+ if (!i.next().matches("^[a-zA-Z0-9\\-]{2,16}$")) {
+ i.remove();
+ }
+ }
+ if (!unames.isEmpty() && unames.size() < 20) {
+ users.addAll(UserQueries.getUsersByName(sql, unames));
+ }
+ }
+
+ String pjids[] = request.getParameterValues("jid");
+ if (pjids != null) {
+ ArrayList jids = new ArrayList(Arrays.asList(pjids));
+ Iterator ii = jids.iterator();
+ while (ii.hasNext()) {
+ if (!ii.next().matches("^[a-zA-Z0-9\\-\\_\\@\\.]{6,64}$")) {
+ ii.remove();
+ }
+ }
+ if (!jids.isEmpty() && jids.size() < 20) {
+ users.addAll(UserQueries.getUsersByJID(sql, jids));
+ }
+ }
+
+ if (!users.isEmpty()) {
+ String json = com.juick.json.Users.arrayToString(users);
+ Main.replyJSON(request, response, json);
+ } else {
+ response.sendError(404);
+ }
+ }
+
+ public void doGetUserRead(HttpServletRequest request, HttpServletResponse response, int vuid) throws ServletException, IOException {
+ int uid = 0;
+ String uname = request.getParameter("uname");
+ if (uname == null) {
+ uid = vuid;
+ } else {
+ if (UserQueries.checkUserNameValid(uname)) {
+ com.juick.User u = UserQueries.getUserByName(sql, uname);
+ if (u != null && u.UID > 0) {
+ uid = u.UID;
+ }
+ }
+ }
+
+ if (uid > 0) {
+ ArrayList uids = UserQueries.getUserRead(sql, uid);
+ if (uids.size() > 0) {
+ ArrayList users = UserQueries.getUsersByID(sql, uids);
+ if (users.size() > 0) {
+ String json = com.juick.json.Users.arrayToString(users);
+ Main.replyJSON(request, response, json);
+ return;
+ }
+ }
+ }
+ response.sendError(404);
+ }
+
+ public void doGetUserReaders(HttpServletRequest request, HttpServletResponse response, int vuid) throws ServletException, IOException {
+ int uid = 0;
+ String uname = request.getParameter("uname");
+ if (uname == null) {
+ uid = vuid;
+ } else {
+ if (UserQueries.checkUserNameValid(uname)) {
+ com.juick.User u = UserQueries.getUserByName(sql, uname);
+ if (u != null && u.UID > 0) {
+ uid = u.UID;
+ }
+ }
+ }
+
+ if (uid > 0) {
+ ArrayList uids = UserQueries.getUserReaders(sql, uid);
+ if (uids.size() > 0) {
+ ArrayList users = UserQueries.getUsersByID(sql, uids);
+ if (users.size() > 0) {
+ String json = com.juick.json.Users.arrayToString(users);
+ Main.replyJSON(request, response, json);
+ return;
+ }
+ }
+ }
+ response.sendError(404);
+ }
+}
diff --git a/src/main/java/com/juick/api/Utils.java b/src/main/java/com/juick/api/Utils.java
new file mode 100644
index 00000000..10e0cccb
--- /dev/null
+++ b/src/main/java/com/juick/api/Utils.java
@@ -0,0 +1,149 @@
+/*
+ * 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.api;
+
+import com.juick.server.UserQueries;
+import java.io.IOException;
+import java.sql.Connection;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.sql.Statement;
+import java.util.ArrayList;
+import javax.servlet.http.Cookie;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import sun.misc.BASE64Decoder;
+
+/**
+ *
+ * @author Ugnich Anton
+ */
+public class Utils {
+
+ public static String getCookie(HttpServletRequest request, String name) {
+ Cookie cookies[] = request.getCookies();
+ if (cookies != null) {
+ for (int i = 0; i < cookies.length; i++) {
+ if (cookies[i].getName().equals(name)) {
+ return cookies[i].getValue();
+ }
+ }
+ }
+ return null;
+ }
+
+ public static com.juick.User getVisitorUser(Connection sql, HttpServletRequest request) {
+ String hash = getCookie(request, "hash");
+ if (hash != null) {
+ return com.juick.server.UserQueries.getUserByHash(sql, hash);
+ } else {
+ return null;
+ }
+ }
+
+ public static int getVisitorUID(Connection sql, HttpServletRequest request) {
+ Cookie cookies[] = request.getCookies();
+ if (cookies != null) {
+ for (int i = 0; i < cookies.length; i++) {
+ if (cookies[i].getName().equals("hash")) {
+ String hash = cookies[i].getValue();
+ return com.juick.server.UserQueries.getUIDbyHash(sql, hash);
+ }
+ }
+ }
+ return 0;
+ }
+
+ public static int getHttpAuthUID(Connection sql, HttpServletRequest request) {
+ String auth = request.getHeader("Authorization");
+ if (auth != null && auth.length() > 8 && auth.startsWith("Basic ")) {
+ try {
+ BASE64Decoder dec = new BASE64Decoder();
+ String loginpassw[] = new String(dec.decodeBuffer(auth.substring(6))).split(":", 2);
+ if (loginpassw.length == 2 && loginpassw[0].length() > 1 && loginpassw[0].length() < 16 && loginpassw[0].matches("[a-zA-Z0-9\\-]+") && !loginpassw[1].isEmpty()) {
+ return UserQueries.checkPassword(sql, loginpassw[0], loginpassw[1]);
+ }
+ } catch (IOException e) {
+ }
+ }
+ return 0;
+ }
+
+ public static int getVisitorQueryStringUID(Connection sql, HttpServletRequest request) {
+ String hash = request.getParameter("hash");
+ if (hash != null && hash.length() == 16) {
+ return com.juick.server.UserQueries.getUIDbyHash(sql, hash);
+ }
+ return 0;
+ }
+
+ public static void sendPermanentRedirect(HttpServletResponse response, String location) {
+ response.setStatus(HttpServletResponse.SC_MOVED_PERMANENTLY);
+ response.setHeader("Location", location);
+ }
+
+ public static void finishSQL(ResultSet rs, Statement stmt) {
+ if (rs != null) {
+ try {
+ rs.close();
+ } catch (SQLException e) {
+ }
+ }
+ if (stmt != null) {
+ try {
+ stmt.close();
+ } catch (SQLException e) {
+ }
+ }
+ }
+
+ public static String convertArray2String(ArrayList mids) {
+ String q = "";
+ for (int i = 0; i < mids.size(); i++) {
+ if (i > 0) {
+ q += ",";
+ }
+ q += mids.get(i);
+ }
+ return q;
+ }
+
+ public static String encodeHTML(String str) {
+ String ret = str;
+ ret = ret.replaceAll("<", "<");
+ ret = ret.replaceAll(">", ">");
+ return str;
+ }
+
+ public static String encodeSphinx(String str) {
+ String ret = str;
+ ret = ret.replaceAll("@", "\\\\@");
+ return ret;
+ }
+
+ public static int parseInt(String str, int def) {
+ int ret = def;
+ if (str != null) {
+ try {
+ ret = Integer.parseInt(str);
+ } catch (Exception e) {
+ }
+ }
+ return ret;
+ }
+}
diff --git a/src/main/webapp/WEB-INF/web.xml b/src/main/webapp/WEB-INF/web.xml
new file mode 100644
index 00000000..533a6882
--- /dev/null
+++ b/src/main/webapp/WEB-INF/web.xml
@@ -0,0 +1,16 @@
+
+
+
+ Main
+ com.juick.api.Main
+
+
+ Main
+ /
+
+
+
+ 30
+
+
+
diff --git a/web/META-INF/context.xml b/web/META-INF/context.xml
deleted file mode 100644
index 5bee3dc3..00000000
--- a/web/META-INF/context.xml
+++ /dev/null
@@ -1,2 +0,0 @@
-
-
diff --git a/web/WEB-INF/web.xml b/web/WEB-INF/web.xml
deleted file mode 100644
index 533a6882..00000000
--- a/web/WEB-INF/web.xml
+++ /dev/null
@@ -1,16 +0,0 @@
-
-
-
- Main
- com.juick.api.Main
-
-
- Main
- /
-
-
-
- 30
-
-
-
--
cgit v1.2.3