diff options
Diffstat (limited to 'HttpServer')
62 files changed, 2362 insertions, 0 deletions
diff --git a/HttpServer/.gitignore b/HttpServer/.gitignore new file mode 100644 index 00000000..39fb081a --- /dev/null +++ b/HttpServer/.gitignore @@ -0,0 +1,9 @@ +*.iml +.gradle +/local.properties +/.idea/workspace.xml +/.idea/libraries +.DS_Store +/build +/captures +.externalNativeBuild diff --git a/HttpServer/app/.gitignore b/HttpServer/app/.gitignore new file mode 100644 index 00000000..796b96d1 --- /dev/null +++ b/HttpServer/app/.gitignore @@ -0,0 +1 @@ +/build diff --git a/HttpServer/app/CMakeLists.txt b/HttpServer/app/CMakeLists.txt new file mode 100644 index 00000000..e58fedb6 --- /dev/null +++ b/HttpServer/app/CMakeLists.txt @@ -0,0 +1,85 @@ +# For more information about using CMake with Android Studio, read the +# documentation: https://d.android.com/studio/projects/add-native-code.html + +# Sets the minimum version of CMake required to build the native library. + +cmake_minimum_required(VERSION 3.4.1) + +# Creates and names a library, sets it as either STATIC +# or SHARED, and provides the relative paths to its source code. +# You can define multiple libraries, and CMake builds them for you. +# Gradle automatically packages shared libraries with your APK. +set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake/Modules/") +set_property(GLOBAL PROPERTY USE_FOLDERS ON) +set(CMAKE_FIND_ROOT_PATH "$ENV{DISTILLERY_ROOT_DIR}/usr_${CMAKE_SYSTEM_PROCESSOR};${CMAKE_FIND_ROOT_PATH}") + +find_package(Boost 1.53.0 COMPONENTS regex system filesystem REQUIRED) +include_directories(SYSTEM ${Boost_INCLUDE_DIR}) + +find_package ( OpenSSL REQUIRED ) + +find_package( LibEvent REQUIRED ) +include_directories(${LIBEVENT_INCLUDE_DIRS}) + +find_package( LongBow REQUIRED ) +include_directories(${LONGBOW_INCLUDE_DIRS}) + +find_package( Libparc REQUIRED ) +include_directories(${LIBPARC_INCLUDE_DIRS}) + +find_package( CCNX_Common REQUIRED ) +include_directories(${CCNX_COMMON_INCLUDE_DIRS}) + +find_package( CCNX_Transport_Rta REQUIRED ) +include_directories(${CCNX_TRANSPORT_RTA_INCLUDE_DIRS}) + +find_package( CCNX_Portal REQUIRED ) +include_directories(${CCNX_PORTAL_INCLUDE_DIRS}) + +find_package ( Threads REQUIRED ) + +find_package ( OpenSSL REQUIRED ) +find_package( Doxygen ) + +find_package(Jsoncpp REQUIRED) +include_directories(${JSONCPP_INCLUDE_DIRS}) + + +find_package(Libicnet REQUIRED) +include_directories(${LIBICNET_INCLUDE_DIRS}) + +find_package(CURL REQUIRED) + +find_package( HttpServer REQUIRED) +include_directories(${LIB_HTTP_SERVER_INCLUDE_DIRS}) + +add_library( # Sets the name of the library. + httpServerWrap + + # Sets the library as a shared library. + SHARED + + # Provides a relative path to your source file(s). + src/main/cpp/httpServerWrap.cpp ) + +# Searches for a specified prebuilt library and stores the path as a +# variable. Because CMake includes system libraries in the search path by +# default, you only need to specify the name of the public NDK library +# you want to add. CMake verifies that the library exists before +# completing its build. +find_library( # Sets the name of the path variable. + log-lib + + # Specifies the name of the NDK library that + # you want CMake to locate. + log ) +# Specifies libraries CMake should link to your target library. You +# can link multiple libraries, such as libraries you define in this +# build script, prebuilt third-party libraries, or system libraries. + +target_link_libraries( # Specifies the target library. + httpServerWrap + + # Links the target library to the log library + # included in the NDK. + ${log-lib} ${LIB_HTTP_SERVER_LIBRARIES} ${CURL_LIBRARIES} ${ANDROID_LIBRARIES} ${LIBICNET_LIBRARIES} ${LIBZF_LOG_LIBRARIES} ${Boost_LIBRARIES} ${JSONCPP_LIBRARIES} ${CCNX_PORTAL_LIBRARIES} ${CCNX_TRANSPORT_RTA_LIBRARIES} ${CCNX_COMMON_LIBRARIES} ${LIBPARC_LIBRARIES} ${LONGBOW_LIBRARIES} ${LIBEVENT_LIBRARIES} ${OPENSSL_LIBRARIES})
\ No newline at end of file diff --git a/HttpServer/app/build.gradle b/HttpServer/app/build.gradle new file mode 100644 index 00000000..4b30fccc --- /dev/null +++ b/HttpServer/app/build.gradle @@ -0,0 +1,79 @@ +apply plugin: 'com.android.application' + +android { + compileSdkVersion 26 + defaultConfig { + applicationId "icn.httpserver.com.httpserver" + minSdkVersion 24 + targetSdkVersion 26 + versionCode 2 + versionName "1.0" + testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" + externalNativeBuild { + cmake { + cppFlags "-std=c++11 -frtti -fexceptions -lz" + } + } + ndk { + // Specifies the ABI configurations of your native + // libraries Gradle should build and package with your APK. + abiFilters 'armeabi-v7a', 'x86' + } + } + + signingConfigs { + release { + storeFile file("httpserver.keystore") + storePassword "httpserver" + keyAlias "httpserver" + keyPassword "httpserver" + } + } + + buildTypes { + release { + minifyEnabled false + proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' + signingConfig signingConfigs.release + } + } + + android.applicationVariants.all { variant -> + variant.outputs.all { output -> + def outputFile = output.outputFile + outputFile + if (outputFile != null && outputFile.name.endsWith('.apk')) { + project.ext { + appName = 'httpserver'} + def fileName = outputFile.name.replace("app", + "$project.ext.appName") + outputFileName = fileName + + } + + } + } + + externalNativeBuild { + cmake { + path "CMakeLists.txt" + } + } + buildToolsVersion '26.0.2' + dexOptions { + incremental true + } + compileOptions { + sourceCompatibility JavaVersion.VERSION_1_8 + targetCompatibility JavaVersion.VERSION_1_8 + } +} + +dependencies { + implementation fileTree(include: ['*.jar'], dir: 'libs') + implementation 'com.android.support:appcompat-v7:26.1.0' + implementation 'com.android.support.constraint:constraint-layout:1.0.2' + testImplementation 'junit:junit:4.12' + androidTestImplementation 'com.android.support.test:runner:1.0.1' + androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1' +} diff --git a/HttpServer/app/cmake/Modules/FindCCNX_Common.cmake b/HttpServer/app/cmake/Modules/FindCCNX_Common.cmake new file mode 100644 index 00000000..da5a4119 --- /dev/null +++ b/HttpServer/app/cmake/Modules/FindCCNX_Common.cmake @@ -0,0 +1,52 @@ +# Copyright (c) 2017 Cisco and/or its affiliates. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at: +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +######################################## +# +# Find the Libparc libraries and includes +# This module sets: +# CCNX_COMMON_FOUND: True if Libparc was found +# CCNX_COMMON_LIBRARY: The Libparc library +# CCNX_COMMON_LIBRARIES: The Libparc library and dependencies +# CCNX_COMMON_INCLUDE_DIR: The Libparc include dir +# + +set(CCNX_COMMON_SEARCH_PATH_LIST + ${CCNX_COMMON_HOME} + $ENV{CCNX_COMMON_HOME} + $ENV{CCNX_HOME} + $ENV{PARC_HOME} + $ENV{FOUNDATION_HOME} + /usr/local/parc + /usr/local/ccnx + /usr/local/ccn + /usr/local + /opt + /usr + ) + +find_path(CCNX_COMMON_INCLUDE_DIR ccnx/common/libccnxCommon_About.h + HINTS ${CCNX_COMMON_SEARCH_PATH_LIST} + PATH_SUFFIXES include + DOC "Find the Libccnx-common includes") + +find_library(CCNX_COMMON_LIBRARY NAMES ccnx_common + HINTS ${CCNX_COMMON_SEARCH_PATH_LIST} + PATH_SUFFIXES lib + DOC "Find the Libccnx-common libraries") + +set(CCNX_COMMON_LIBRARIES ${CCNX_COMMON_LIBRARY}) +set(CCNX_COMMON_INCLUDE_DIRS ${CCNX_COMMON_INCLUDE_DIR}) + +include(FindPackageHandleStandardArgs) +find_package_handle_standard_args(CCNX_Common DEFAULT_MSG CCNX_COMMON_LIBRARY CCNX_COMMON_INCLUDE_DIR) diff --git a/HttpServer/app/cmake/Modules/FindCCNX_Portal.cmake b/HttpServer/app/cmake/Modules/FindCCNX_Portal.cmake new file mode 100644 index 00000000..d7aa9066 --- /dev/null +++ b/HttpServer/app/cmake/Modules/FindCCNX_Portal.cmake @@ -0,0 +1,53 @@ +# Copyright (c) 2017 Cisco and/or its affiliates. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at: +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +######################################## +# +# Find the Libccnx-transport libraries and includes +# This module sets: +# CCNX_PORTAL_FOUND: True if Libparc was found +# CCNX_PORTAL_LIBRARY: The Libparc library +# CCNX_PORTAL_LIBRARIES: The Libparc library and dependencies +# CCNX_PORTAL_INCLUDE_DIR: The Libparc include dir +# + +set(CCNX_PORTAL_SEARCH_PATH_LIST + ${CCNX_PORTAL_HOME} + $ENV{CCNX_PORTAL_HOME} + $ENV{CCNX_HOME} + $ENV{PARC_HOME} + $ENV{FOUNDATION_HOME} + /usr/local/parc + /usr/local/ccnx + /usr/local/ccn + /usr/local + /opt + /usr + ) + +find_path(CCNX_PORTAL_INCLUDE_DIR ccnx/api/ccnx_Portal/ccnxPortal_About.h + HINTS ${CCNX_PORTAL_SEARCH_PATH_LIST} + PATH_SUFFIXES include + DOC "Find the Libccnx-portal includes") + +find_library(CCNX_PORTAL_LIBRARY NAMES ccnx_api_portal + HINTS ${CCNX_PORTAL_SEARCH_PATH_LIST} + PATH_SUFFIXES lib + DOC "Find the Libccnx-portal libraries") + +set(CCNX_PORTAL_LIBRARIES ${CCNX_PORTAL_LIBRARY}) + +set(CCNX_PORTAL_INCLUDE_DIRS ${CCNX_PORTAL_INCLUDE_DIR}) + +include(FindPackageHandleStandardArgs) +find_package_handle_standard_args(CCNX_Portal DEFAULT_MSG CCNX_PORTAL_LIBRARY CCNX_PORTAL_INCLUDE_DIR) diff --git a/HttpServer/app/cmake/Modules/FindCCNX_Transport_Rta.cmake b/HttpServer/app/cmake/Modules/FindCCNX_Transport_Rta.cmake new file mode 100644 index 00000000..bc0b0428 --- /dev/null +++ b/HttpServer/app/cmake/Modules/FindCCNX_Transport_Rta.cmake @@ -0,0 +1,63 @@ +# Copyright (c) 2017 Cisco and/or its affiliates. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at: +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +######################################## +# +# Find the Libccnx-transport libraries and includes +# This module sets: +# CCNX_TRANSPORT_RTA_FOUND: True if Libparc was found +# CCNX_TRANSPORT_RTA_LIBRARY: The Libparc library +# CCNX_TRANSPORT_RTA_LIBRARIES: The Libparc library and dependencies +# CCNX_TRANSPORT_RTA_INCLUDE_DIR: The Libparc include dir +# + +set(CCNX_TRANSPORT_RTA_SEARCH_PATH_LIST + ${CCNX_TRANSPORT_RTA_HOME} + $ENV{CCNX_TRANSPORT_RTA_HOME} + $ENV{CCNX_HOME} + $ENV{PARC_HOME} + $ENV{FOUNDATION_HOME} + /usr/local/parc + /usr/local/ccnx + /usr/local/ccn + /usr/local + /opt + /usr + ) + +find_path(CCNX_TRANSPORT_RTA_INCLUDE_DIR ccnx/transport/librta_About.h + HINTS ${CCNX_TRANSPORT_RTA_SEARCH_PATH_LIST} + PATH_SUFFIXES include + DOC "Find the Libccnx-transport-rta includes") + +find_library(CCNX_TRANSPORT_RTA_LIBRARY NAMES ccnx_transport_rta + HINTS ${CCNX_TRANSPORT_RTA_SEARCH_PATH_LIST} + PATH_SUFFIXES lib + DOC "Find the Libccnx-transport-rta libraries") + +find_library(CCNX_API_NOTIFY_LIBRARY NAMES ccnx_api_notify + HINTS ${CCNX_TRANSPORT_RTA_SEARCH_PATH_LIST} + PATH_SUFFIXES lib + DOC "Find the Libccnx-transport-rta libraries") + +find_library(CCNX_API_CONTROL_LIBRARY NAMES ccnx_api_control + HINTS ${CCNX_TRANSPORT_RTA_SEARCH_PATH_LIST} + PATH_SUFFIXES lib + DOC "Find the Libccnx-transport-rta libraries") + +set(CCNX_TRANSPORT_RTA_LIBRARIES ${CCNX_TRANSPORT_RTA_LIBRARY} ${CCNX_API_CONTROL_LIBRARY} ${CCNX_API_NOTIFY_LIBRARY}) + +set(CCNX_TRANSPORT_RTA_INCLUDE_DIRS ${CCNX_TRANSPORT_RTA_INCLUDE_DIR}) + +include(FindPackageHandleStandardArgs) +find_package_handle_standard_args(CCNX_Transport_Api DEFAULT_MSG CCNX_TRANSPORT_RTA_LIBRARY CCNX_TRANSPORT_RTA_INCLUDE_DIR) diff --git a/HttpServer/app/cmake/Modules/FindCURL.cmake b/HttpServer/app/cmake/Modules/FindCURL.cmake new file mode 100644 index 00000000..239b0e50 --- /dev/null +++ b/HttpServer/app/cmake/Modules/FindCURL.cmake @@ -0,0 +1,69 @@ +#.rst: +# FindCURL +# -------- +# +# Find curl +# +# Find the native CURL headers and libraries. +# +# :: +# +# CURL_INCLUDE_DIRS - where to find curl_/curl_.h, etc. +# CURL_LIBRARIES - List of libraries when using curl. +# CURL_FOUND - True if curl found. +# CURL_VERSION_STRING - the version of curl found (since CMake 2.8.8) + +#============================================================================= +# Copyright 2006-2009 Kitware, Inc. +# Copyright 2012 Rolf Eike Beer <eike@sf-mail.de> +# +# Distributed under the OSI-approved BSD License (the "License"); +# see accompanying file Copyright.txt for details. +# +# This software is distributed WITHOUT ANY WARRANTY; without even the +# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +# See the License for more information. +#============================================================================= +# (To distribute this file outside of CMake, substitute the full +# License text for the above reference.) + +# Look for the header file. +find_path(CURL_INCLUDE_DIR NAMES curl/curl.h) +mark_as_advanced(CURL_INCLUDE_DIR) + +# Look for the library (sorted from most current/relevant entry to least). +find_library(CURL_LIBRARY NAMES + curl + # Windows MSVC prebuilts: + curllib + libcurl_imp + curllib_static + # Windows older "Win32 - MSVC" prebuilts (libcurl.lib, e.g. libcurl-7.15.5-win32-msvc.zip): + libcurl + ) +mark_as_advanced(CURL_LIBRARY) + +if(CURL_INCLUDE_DIR) + foreach(_curl_version_header curlver.h curl.h) + if(EXISTS "${CURL_INCLUDE_DIR}/curl/${_curl_version_header}") + file(STRINGS "${CURL_INCLUDE_DIR}/curl/${_curl_version_header}" curl_version_str REGEX "^#define[\t ]+LIBCURL_VERSION[\t ]+\".*\"") + + string(REGEX REPLACE "^#define[\t ]+LIBCURL_VERSION[\t ]+\"([^\"]*)\".*" "\\1" CURL_VERSION_STRING "${curl_version_str}") + unset(curl_version_str) + break() + endif() + endforeach() +endif() + +# handle the QUIETLY and REQUIRED arguments and set CURL_FOUND to TRUE if +# all listed variables are TRUE +include(FindPackageHandleStandardArgs) + +FIND_PACKAGE_HANDLE_STANDARD_ARGS(CURL + REQUIRED_VARS CURL_LIBRARY CURL_INCLUDE_DIR + VERSION_VAR CURL_VERSION_STRING) + +if(CURL_FOUND) + set(CURL_LIBRARIES ${CURL_LIBRARY}) + set(CURL_INCLUDE_DIRS ${CURL_INCLUDE_DIR}) +endif() diff --git a/HttpServer/app/cmake/Modules/FindHttpServer.cmake b/HttpServer/app/cmake/Modules/FindHttpServer.cmake new file mode 100644 index 00000000..263353fa --- /dev/null +++ b/HttpServer/app/cmake/Modules/FindHttpServer.cmake @@ -0,0 +1,39 @@ +######################################## +# +# Find the HttpServer libraries and includes +# This module sets: +# LIB_HTTP_SERVER_FOUND: True if lib_http_server was found +# LIB_HTTP_SERVER_LIBRARY: The lib_http_server library +# LIB_HTTP_SERVER_LIBRARIES: The lib_http_server library and dependencies +# LIB_HTTP_SERVER_INCLUDE_DIR: The lib_http_server include dir +# + +set(LIBICN_HTTP_SERVER_SEARCH_PATH_LIST + ${HTTP_SERVER_HOME} + $ENV{HTTP_SERVER_HOME} + $ENV{CCNX_HOME} + $ENV{PARC_HOME} + $ENV{FOUNDATION_HOME} + /usr/local/http-server + /usr/local/ccnx + /usr/local/ccn + /usr/local + /opt + /usr + ) + +find_path(LIB_HTTP_SERVER_INCLUDE_DIR http-server/http_server.h + HINTS ${LIBICN_HTTP_SERVER_SEARCH_PATH_LIST} + PATH_SUFFIXES include + DOC "Find the http-server includes") + +find_library(LIB_HTTP_SERVER_LIBRARY NAMES httpserver + HINTS ${LIB_HTTP_SERVER_SEARCH_PATH_LIST} + PATH_SUFFIXES lib + DOC "Find the http-server libraries") + +set(LIB_HTTP_SERVER_LIBRARIES ${LIB_HTTP_SERVER_LIBRARY}) +set(LIB_HTTP_SERVER_INCLUDE_DIRS ${LIB_HTTP_SERVER_INCLUDE_DIR}) + +include(FindPackageHandleStandardArgs) +find_package_handle_standard_args(lib_http_server DEFAULT_MSG LIB_HTTP_SERVER_LIBRARY LIB_HTTP_SERVER_INCLUDE_DIR) diff --git a/HttpServer/app/cmake/Modules/FindJsoncpp.cmake b/HttpServer/app/cmake/Modules/FindJsoncpp.cmake new file mode 100644 index 00000000..acde7b95 --- /dev/null +++ b/HttpServer/app/cmake/Modules/FindJsoncpp.cmake @@ -0,0 +1,47 @@ +# Find jsoncpp +# +# Find the jsoncpp includes and library +# +# if you nee to add a custom library search path, do it via via CMAKE_PREFIX_PATH +# +# This module defines +# JSONCPP_INCLUDE_DIRS, where to find header, etc. +# JSONCPP_LIBRARIES, the libraries needed to use jsoncpp. +# JSONCPP_FOUND, If false, do not try to use jsoncpp. +# JSONCPP_INCLUDE_PREFIX, include prefix for jsoncpp + +# only look in default directories +find_path( + JSONCPP_INCLUDE_DIR + NAMES jsoncpp/json/json.h json/json.h + DOC "jsoncpp include dir" +) + +find_library( + JSONCPP_LIBRARY + NAMES jsoncpp + DOC "jsoncpp library" +) + +set(JSONCPP_INCLUDE_DIRS ${JSONCPP_INCLUDE_DIR}) +set(JSONCPP_LIBRARIES ${JSONCPP_LIBRARY}) + +# find JSONCPP_INCLUDE_PREFIX +find_path( + JSONCPP_INCLUDE_PREFIX + NAMES json.h + PATH_SUFFIXES jsoncpp/json json +) + +if (${JSONCPP_INCLUDE_PREFIX} MATCHES "jsoncpp") + set(JSONCPP_INCLUDE_PREFIX "jsoncpp/json") +else() + set(JSONCPP_INCLUDE_PREFIX "json") +endif() + +# handle the QUIETLY and REQUIRED arguments and set JSONCPP_FOUND to TRUE +# if all listed variables are TRUE, hide their existence from configuration view +include(FindPackageHandleStandardArgs) +find_package_handle_standard_args(jsoncpp DEFAULT_MSG + JSONCPP_INCLUDE_DIR JSONCPP_LIBRARY) +mark_as_advanced (JSONCPP_INCLUDE_DIR JSONCPP_LIBRARY)
\ No newline at end of file diff --git a/HttpServer/app/cmake/Modules/FindLibEvent.cmake b/HttpServer/app/cmake/Modules/FindLibEvent.cmake new file mode 100644 index 00000000..2d1ca4fe --- /dev/null +++ b/HttpServer/app/cmake/Modules/FindLibEvent.cmake @@ -0,0 +1,47 @@ +######################################## +# +# Find the LibEvent libraries and includes +# This module sets: +# LIBEVENT_FOUND: True if LibEvent was found +# LIBEVENT_LIBRARY: The LibEvent library +# LIBEVENT_LIBRARIES: The LibEvent library and dependencies +# LIBEVENT_INCLUDE_DIR: The LibEvent include dir +# +# This module will look for the libraries in various locations +# See the LIBEVENT_SEARCH_PATH_LIST for a full list. +# +# The caller can hint at locations using the following variables: +# +# LIBEVENT_HOME (passed as -D to cmake) +# CCNX_DEPENDENCIES (in environment) +# LIBEVENT_HOME (in environment) +# CCNX_HOME (in environment) +# + +set(LIBEVENT_SEARCH_PATH_LIST + ${LIBEVENT_HOME} + $ENV{CCNX_DEPENDENCIES} + $ENV{LIBEVENT_HOME} + $ENV{CCNX_HOME} + /usr/local/ccnx + /usr/local/ccn + /usr/local + /opt + /usr + ) + +find_path(LIBEVENT_INCLUDE_DIR event2/event.h + HINTS ${LIBEVENT_SEARCH_PATH_LIST} + PATH_SUFFIXES include + DOC "Find the LibEvent includes" ) + +find_library(LIBEVENT_LIBRARY NAMES event + HINTS ${LIBEVENT_SEARCH_PATH_LIST} + PATH_SUFFIXES lib + DOC "Find the LibEvent libraries" ) + +set(LIBEVENT_LIBRARIES ${LIBEVENT_LIBRARY}) +set(LIBEVENT_INCLUDE_DIRS ${LIBEVENT_INCLUDE_DIR}) + +include(FindPackageHandleStandardArgs) +find_package_handle_standard_args(LibEvent DEFAULT_MSG LIBEVENT_LIBRARY LIBEVENT_INCLUDE_DIR) diff --git a/HttpServer/app/cmake/Modules/FindLibicnet.cmake b/HttpServer/app/cmake/Modules/FindLibicnet.cmake new file mode 100644 index 00000000..bfb81ef7 --- /dev/null +++ b/HttpServer/app/cmake/Modules/FindLibicnet.cmake @@ -0,0 +1,39 @@ +######################################## +# +# Find the Libparc libraries and includes +# This module sets: +# LIBICNET_FOUND: True if Libconsumer-producer was found +# LIBICNETR_LIBRARY: The Libconsumer-producer library +# LIBICNET_LIBRARIES: The Libconsumer-producer library and dependencies +# LIBICNET_INCLUDE_DIR: The Libconsumer-producer include dir +# + +set(LIBICNET_SEARCH_PATH_LIST + ${LIBICNET_HOME} + $ENV{LIBICNETHOME} + $ENV{CCNX_HOME} + $ENV{PARC_HOME} + $ENV{FOUNDATION_HOME} + /usr/local/parc + /usr/local/ccnx + /usr/local/ccn + /usr/local + /opt + /usr + ) + +find_path(LIBICNET_INCLUDE_DIR icnet/icnet_ccnx_common.h + HINTS ${LIBICNET_SEARCH_PATH_LIST} + PATH_SUFFIXES include + DOC "Find the libicnet includes") + +find_library(LIBICNET_LIBRARY NAMES icnet + HINTS ${LIBICNET_SEARCH_PATH_LIST} + PATH_SUFFIXES lib + DOC "Find the libicnet libraries") + +set(LIBICNET_LIBRARIES ${LIBICNET_LIBRARY}) +set(LIBICNET_INCLUDE_DIRS ${LIBICNET_INCLUDE_DIR}) + +include(FindPackageHandleStandardArgs) +find_package_handle_standard_args(Libicnet DEFAULT_MSG LIBICNET_LIBRARY LIBICNET_INCLUDE_DIR) diff --git a/HttpServer/app/cmake/Modules/FindLibparc.cmake b/HttpServer/app/cmake/Modules/FindLibparc.cmake new file mode 100644 index 00000000..da8b3af7 --- /dev/null +++ b/HttpServer/app/cmake/Modules/FindLibparc.cmake @@ -0,0 +1,52 @@ +# Copyright (c) 2017 Cisco and/or its affiliates. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at: +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +######################################## +# +# Find the Libparc libraries and includes +# This module sets: +# LIBPARC_FOUND: True if Libparc was found +# LIBPARC_LIBRARY: The Libparc library +# LIBPARC_LIBRARIES: The Libparc library and dependencies +# LIBPARC_INCLUDE_DIR: The Libparc include dir +# + +set(LIBPARC_SEARCH_PATH_LIST + ${LIBPARC_HOME} + $ENV{LIBPARC_HOME} + $ENV{CCNX_HOME} + $ENV{PARC_HOME} + $ENV{FOUNDATION_HOME} + /usr/local/parc + /usr/local/ccnx + /usr/local/ccn + /usr/local + /opt + /usr + ) + +find_path(LIBPARC_INCLUDE_DIR parc/libparc_About.h + HINTS ${LIBPARC_SEARCH_PATH_LIST} + PATH_SUFFIXES include + DOC "Find the Libparc includes") + +find_library(LIBPARC_LIBRARY NAMES parc + HINTS ${LIBPARC_SEARCH_PATH_LIST} + PATH_SUFFIXES lib + DOC "Find the Libparc libraries") + +set(LIBPARC_LIBRARIES ${LIBPARC_LIBRARY}) +set(LIBPARC_INCLUDE_DIRS ${LIBPARC_INCLUDE_DIR}) + +include(FindPackageHandleStandardArgs) +find_package_handle_standard_args(Libparc DEFAULT_MSG LIBPARC_LIBRARY LIBPARC_INCLUDE_DIR) diff --git a/HttpServer/app/cmake/Modules/FindLongBow.cmake b/HttpServer/app/cmake/Modules/FindLongBow.cmake new file mode 100644 index 00000000..28d0b3b1 --- /dev/null +++ b/HttpServer/app/cmake/Modules/FindLongBow.cmake @@ -0,0 +1,58 @@ +# Copyright (c) 2017 Cisco and/or its affiliates. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at: +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + + +######################################## +# +# Find the LongBow libraries and includes +# This module sets: +# LONGBOW_FOUND: True if LongBow was found +# LONGBOW_LIBRARY: The LongBow library +# LONGBOW_LIBRARIES: The LongBow library and dependencies +# LONGBOW_INCLUDE_DIR: The LongBow include dir +# + +set(LONGBOW_SEARCH_PATH_LIST + ${LONGBOW_HOME} + $ENV{LONGBOW_HOME} + $ENV{CCNX_HOME} + $ENV{PARC_HOME} + $ENV{FOUNDATION_HOME} + /usr/local/parc + /usr/local/ccnx + /usr/local/ccn + /usr/local + /opt + /usr + ) + +find_path(LONGBOW_INCLUDE_DIR LongBow/longBow_About.h + HINTS ${LONGBOW_SEARCH_PATH_LIST} + PATH_SUFFIXES include + DOC "Find the LongBow includes") + +find_library(LONGBOW_LIBRARY NAMES longbow + HINTS ${LONGBOW_SEARCH_PATH_LIST} + PATH_SUFFIXES lib + DOC "Find the LongBow libraries") + +find_library(LONGBOW_REPORT_LIBRARY NAMES longbow-textplain longbow-ansiterm + HINTS ${LONGBOW_SEARCH_PATH_LIST} + PATH_SUFFIXES lib + DOC "Find the LongBow report libraries") + +set(LONGBOW_LIBRARIES ${LONGBOW_LIBRARY} ${LONGBOW_REPORT_LIBRARY}) +set(LONGBOW_INCLUDE_DIRS ${LONGBOW_INCLUDE_DIR}) + +include(FindPackageHandleStandardArgs) +find_package_handle_standard_args(LongBow DEFAULT_MSG LONGBOW_LIBRARY LONGBOW_INCLUDE_DIR) diff --git a/HttpServer/app/cmake/Modules/FindUncrustify.cmake b/HttpServer/app/cmake/Modules/FindUncrustify.cmake new file mode 100644 index 00000000..e53f65fe --- /dev/null +++ b/HttpServer/app/cmake/Modules/FindUncrustify.cmake @@ -0,0 +1,8 @@ +# Find uncrustify program +# +find_program( UNCRUSTIFY_BIN uncrustify + PATHS + $ENV{UNCRUSTIFY_HOME} + ) + +message( "-- UNCRUSTIFY found in ${UNCRUSTIFY_BIN}" ) diff --git a/HttpServer/app/cmake/Modules/detectCacheSize.cmake b/HttpServer/app/cmake/Modules/detectCacheSize.cmake new file mode 100644 index 00000000..469d2627 --- /dev/null +++ b/HttpServer/app/cmake/Modules/detectCacheSize.cmake @@ -0,0 +1,21 @@ +# Detect the cache size +# +# XXX: TODO: This is a bug when cross compiling. We are detecting the local +# Cache Line size and not the target cache line size. We should provide some +# way to define this + +set(LEVEL1_DCACHE_LINESIZE 32) + +if( APPLE ) + execute_process(COMMAND sysctl -n hw.cachelinesize + OUTPUT_VARIABLE LEVEL1_DCACHE_LINESIZE + OUTPUT_STRIP_TRAILING_WHITESPACE) +endif( APPLE ) + +if( ${CMAKE_SYSTEM_NAME} STREQUAL "Linux" ) + execute_process(COMMAND getconf LEVEL1_DCACHE_LINESIZE + OUTPUT_VARIABLE LEVEL1_DCACHE_LINESIZE + OUTPUT_STRIP_TRAILING_WHITESPACE) +endif() + +message("-- Cache line size: ${LEVEL1_DCACHE_LINESIZE}") diff --git a/HttpServer/app/cmake/Modules/version.cmake b/HttpServer/app/cmake/Modules/version.cmake new file mode 100644 index 00000000..74831674 --- /dev/null +++ b/HttpServer/app/cmake/Modules/version.cmake @@ -0,0 +1,15 @@ +# +# Get a version to pass on the command line +# +execute_process(COMMAND ${PROJECT_SOURCE_DIR}/cmake/get_version.sh ${PROJECT_SOURCE_DIR} + OUTPUT_VARIABLE RELEASE_VERSION + OUTPUT_STRIP_TRAILING_WHITESPACE) + +execute_process(COMMAND date -u +%Y-%m-%dT%H:%M:%SZ + OUTPUT_VARIABLE ISO_DATE + OUTPUT_STRIP_TRAILING_WHITESPACE) + +MESSAGE( STATUS "Configuring version ${RELEASE_VERSION}" ) + +add_definitions("-DRELEASE_VERSION=\"${RELEASE_VERSION}\"") + diff --git a/HttpServer/app/cmake/get_version.sh b/HttpServer/app/cmake/get_version.sh new file mode 100755 index 00000000..34c6ddb2 --- /dev/null +++ b/HttpServer/app/cmake/get_version.sh @@ -0,0 +1,20 @@ +#!/bin/sh + +DATE_VERSION=`date "+%Y%m%d"` + +if [ ! -d $1 ]; then + echo 0.$DATE_VERSION + exit +fi + +if [ -f $1/BASE_VERSION ]; then + BASE_VERSION=`cat $1/BASE_VERSION`. +fi + +GIT=`which git` + +if test -x $GIT -a -f $1/.git/config; then + GIT_VERSION=.`git -C $1 rev-parse HEAD | cut -c 1-8` +fi + +echo $BASE_VERSION$DATE_VERSION$GIT_VERSION diff --git a/HttpServer/app/httpserver.keystore b/HttpServer/app/httpserver.keystore Binary files differnew file mode 100644 index 00000000..d277cc53 --- /dev/null +++ b/HttpServer/app/httpserver.keystore diff --git a/HttpServer/app/proguard-rules.pro b/HttpServer/app/proguard-rules.pro new file mode 100644 index 00000000..f1b42451 --- /dev/null +++ b/HttpServer/app/proguard-rules.pro @@ -0,0 +1,21 @@ +# Add project specific ProGuard rules here. +# You can control the set of applied configuration files using the +# proguardFiles setting in build.gradle. +# +# For more details, see +# http://developer.android.com/guide/developing/tools/proguard.html + +# If your project uses WebView with JS, uncomment the following +# and specify the fully qualified class name to the JavaScript interface +# class: +#-keepclassmembers class fqcn.of.javascript.interface.for.webview { +# public *; +#} + +# Uncomment this to preserve the line number information for +# debugging stack traces. +#-keepattributes SourceFile,LineNumberTable + +# If you keep the line number information, uncomment this to +# hide the original source file name. +#-renamesourcefileattribute SourceFile diff --git a/HttpServer/app/src/androidTest/java/icn/httpserver/com/hicnhttpserver/ExampleInstrumentedTest.java b/HttpServer/app/src/androidTest/java/icn/httpserver/com/hicnhttpserver/ExampleInstrumentedTest.java new file mode 100644 index 00000000..91fb35e9 --- /dev/null +++ b/HttpServer/app/src/androidTest/java/icn/httpserver/com/hicnhttpserver/ExampleInstrumentedTest.java @@ -0,0 +1,41 @@ +/* + * Copyright (c) 2018 Cisco and/or its affiliates. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at: + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package icn.httpserver.com.hicnhttpserver; + +import android.content.Context; +import android.support.test.InstrumentationRegistry; +import android.support.test.runner.AndroidJUnit4; + +import org.junit.Test; +import org.junit.runner.RunWith; + +import static org.junit.Assert.*; + +/** + * Instrumented test, which will execute on an Android device. + * + * @see <a href="http://d.android.com/tools/testing">Testing documentation</a> + */ +@RunWith(AndroidJUnit4.class) +public class ExampleInstrumentedTest { + @Test + public void useAppContext() throws Exception { + // Context of the app under test. + Context appContext = InstrumentationRegistry.getTargetContext(); + + assertEquals("hicn.cisco.com.hicnhttpserver", appContext.getPackageName()); + } +} diff --git a/HttpServer/app/src/main/AndroidManifest.xml b/HttpServer/app/src/main/AndroidManifest.xml new file mode 100644 index 00000000..1831bbc3 --- /dev/null +++ b/HttpServer/app/src/main/AndroidManifest.xml @@ -0,0 +1,33 @@ +<?xml version="1.0" encoding="utf-8"?> +<manifest xmlns:android="http://schemas.android.com/apk/res/android" + package="icn.httpserver.com.httpserver"> + + <application + android:allowBackup="true" + android:configChanges="orientation|screenSize|keyboard" + android:icon="@mipmap/ic_launcher" + android:label="@string/app_name" + android:roundIcon="@mipmap/ic_launcher_round" + android:supportsRtl="true" + android:theme="@style/AppTheme"> + <activity + android:name=".HttpServerActivity" + android:screenOrientation="portrait"> + <intent-filter> + <action android:name="android.intent.action.MAIN" /> + + <category android:name="android.intent.category.LAUNCHER" /> + </intent-filter> + </activity> + <service + android:name="icn.httpserver.com.service.HttpServerService"> + </service> + </application> + + <uses-permission android:name="android.permission.INTERNET" /> + <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> + <uses-permission + android:name="android.permission.READ_EXTERNAL_STORAGE" + android:maxSdkVersion="21" /> + +</manifest>
\ No newline at end of file diff --git a/HttpServer/app/src/main/cpp/httpServerWrap.cpp b/HttpServer/app/src/main/cpp/httpServerWrap.cpp new file mode 100644 index 00000000..d554fe58 --- /dev/null +++ b/HttpServer/app/src/main/cpp/httpServerWrap.cpp @@ -0,0 +1,236 @@ +/* + * Copyright (c) 2018 Cisco and/or its affiliates. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at: + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#include <jni.h> +#include <string> +#include <stdlib.h> +#include <http-server/http_server.h> +#include <http-client/http_client_icn.h> +#include <http-client/http_client_tcp.h> +#include <boost/filesystem.hpp> +#include <fstream> +#include <iostream> +#include <android/log.h> + + +static bool _isRunning = false; +icn_httpserver::HttpServer *server; + +void default_resource_send(const icn_httpserver::HttpServer &server, + std::shared_ptr<icn_httpserver::Response> response, + std::shared_ptr<std::ifstream> ifs, + std::shared_ptr<std::vector<char>> buffer, + std::size_t bytes_to_read) { + std::streamsize read_length; + + if ((read_length = ifs->read(&(*buffer)[0], buffer->size()).gcount()) > 0) { + response->write(&(*buffer)[0], read_length); + + if (bytes_to_read <= static_cast<std::streamsize>(buffer->size())) { + return; + } + + std::size_t to_read = bytes_to_read - read_length; + server.send(response, + [&server, response, ifs, buffer, to_read](const boost::system::error_code &ec) { + if (!ec) { + default_resource_send(server, response, ifs, buffer, to_read); + } else { + __android_log_print(ANDROID_LOG_ERROR, "HttpServer", + "Connection interrupted"); + } + }); + } +} + +extern "C" +JNIEXPORT void JNICALL +Java_icn_httpserver_com_supportlibrary_HttpServer_start(JNIEnv *env, jobject instance, + jstring rootFolderString, + jstring tcpListenPortString, + jstring webServerPrefixString, + jstring proxyAddressString, + jstring iCNproxyAddressString) { + std::string root_folder = ""; + int port = 8080; + std::string webserver_prefix = ""; + std::string proxy_address = ""; + std::string icn_proxy_address = ""; + if (rootFolderString) { + const char *rootFolderChar = env->GetStringUTFChars(rootFolderString, JNI_FALSE); + root_folder.append(rootFolderChar); + env->ReleaseStringUTFChars(rootFolderString, rootFolderChar); + } + + if (tcpListenPortString) { + const char *tcpListenPortChar = env->GetStringUTFChars(tcpListenPortString, JNI_FALSE); + port = atoi(tcpListenPortChar); + env->ReleaseStringUTFChars(tcpListenPortString, tcpListenPortChar); + } + if (webServerPrefixString) { + const char *webServerPrefixChar = env->GetStringUTFChars(webServerPrefixString, JNI_FALSE); + webserver_prefix.append(webServerPrefixChar); + env->ReleaseStringUTFChars(webServerPrefixString, webServerPrefixChar); + } + if (proxyAddressString) { + const char *proxyAddressChar = env->GetStringUTFChars(proxyAddressString, JNI_FALSE); + proxy_address.append(proxyAddressChar); + env->ReleaseStringUTFChars(proxyAddressString, proxyAddressChar); + } + + if (iCNproxyAddressString) { + const char *iCNproxyAddressChar = env->GetStringUTFChars(iCNproxyAddressString, JNI_FALSE); + icn_proxy_address.append(iCNproxyAddressChar); + env->ReleaseStringUTFChars(iCNproxyAddressString, iCNproxyAddressChar); + } + boost::asio::io_service io_service; + server = new icn_httpserver::HttpServer(port, webserver_prefix, 50, 50, 300, + io_service); + _isRunning = true; + server->resource["^/info$"]["GET"] = [](std::shared_ptr<icn_httpserver::Response> response, + std::shared_ptr<icn_httpserver::Request> request) { + std::stringstream content_stream; + content_stream << "<h1>This webserver is able to reply to HTTP over TCP/ICN</h1>"; + content_stream << request->getMethod() << " " << request->getPath() << " HTTP/" + << request->getHttp_version() << "<br>"; + for (auto &header: request->getHeader()) { + content_stream << header.first << ": " << header.second << "<br>"; + } + + content_stream.seekp(0, std::ios::end); + + *response << "HTTP/1.1 200 OK\r\nContent-Length: " << content_stream.tellp() << "\r\n\r\n" + << content_stream.rdbuf(); + }; + + + server->default_resource["GET"] = [&root_folder, &proxy_address, &icn_proxy_address]( + std::shared_ptr<icn_httpserver::Response> response, + std::shared_ptr<icn_httpserver::Request> + request) { + const auto web_root_path = boost::filesystem::canonical(root_folder); + + boost::filesystem::path path = web_root_path; + path /= request->getPath(); + + if (path.extension().string() == ".mpd") { + response->setResponseLifetime(std::chrono::milliseconds(3000)); + } + + icn_httpserver::SocketRequest *socket_request = dynamic_cast<icn_httpserver::SocketRequest *>(request.get()); + + if (boost::filesystem::exists(path)) { + path = boost::filesystem::canonical(path); + + if (std::distance(web_root_path.begin(), web_root_path.end()) <= + std::distance(path.begin(), path.end()) && + std::equal(web_root_path.begin(), web_root_path.end(), path.begin())) { + if (boost::filesystem::is_directory(path)) { + path /= "index.html"; + } // default path + + if (boost::filesystem::exists(path) && boost::filesystem::is_regular_file(path)) { + auto ifs = std::make_shared<std::ifstream>(); + ifs->open(path.string(), std::ifstream::in | std::ios::binary); + if (*ifs) { + std::streamsize buffer_size = 15 * 1024 * 1024; + auto buffer = std::make_shared<std::vector<char> >(buffer_size); + + ifs->seekg(0, std::ios::end); + auto length = ifs->tellg(); + ifs->seekg(0, std::ios::beg); + + response->setResponseLength(length); + *response << "HTTP/1.0 200 OK\r\nContent-Length: " << length << "\r\n\r\n"; + + if (path.extension().string() == ".mpd") { + response->setResponseLifetime(std::chrono::milliseconds(1000)); + } + default_resource_send(*server, response, ifs, buffer, length); + + return; + + } + } + } + } + + std::string proxy = ""; + HTTPClient *client = nullptr; + + if (proxy_address.empty() && !icn_proxy_address.empty()) { + proxy = icn_proxy_address; + client = new HTTPClientIcn(20); + } else if (!proxy_address.empty() && icn_proxy_address.empty()) { + proxy = proxy_address; + client = new HTTPClientTcp; + } else if (!proxy_address.empty() && !icn_proxy_address.empty()) { + if (socket_request) { + proxy = icn_proxy_address; + client = new HTTPClientIcn(20); + } else { + proxy = proxy_address; + client = new HTTPClientTcp; + } + } + + if (!proxy.empty()) { + std::stringstream ss; + if (strncmp("http://", proxy.c_str(), 7) != 0) { + if (strncmp("https://", proxy.c_str(), 8) != 0) { + ss << "https://"; + } else { + ss << "http://"; + } + } + ss << proxy; + ss << request->getPath(); + std::cout << ss.str() << std::endl; + client->download(ss.str(), *response); + + delete client; + if (response->size() == 0) { + *response << "HTTP/1.1 504 Gateway Timeout\r\n\r\n"; + } + + return; + } + + std::string content = "Could not open path " + request->getPath(); + + *response << "HTTP/1.1 404 Not found\r\nContent-Length: " << content.length() << "\r\n\r\n" + << content; + }; + + __android_log_print(ANDROID_LOG_INFO, "HttpServer", "HttpServer Starting"); + server->start(); + +} + +extern "C" +JNIEXPORT void JNICALL +Java_icn_httpserver_com_supportlibrary_HttpServer_stop(JNIEnv *env, jobject instance) { + server->stop(); + _isRunning = false; + __android_log_print(ANDROID_LOG_INFO, "HttpServer", "HttpServer Stopped"); + +} + +extern "C" +JNIEXPORT jboolean JNICALL +Java_icn_httpserver_com_supportlibrary_HttpServer_isRunning(JNIEnv *env, jobject instance) { + __android_log_print(ANDROID_LOG_INFO, "HttpServer", "Is Running? %s", _isRunning ? "true" : "false"); + return _isRunning; + +}
\ No newline at end of file diff --git a/HttpServer/app/src/main/ic_launcher-web.png b/HttpServer/app/src/main/ic_launcher-web.png Binary files differnew file mode 100644 index 00000000..1206ee9c --- /dev/null +++ b/HttpServer/app/src/main/ic_launcher-web.png diff --git a/HttpServer/app/src/main/java/icn/httpserver/com/httpserver/HttpServerActivity.java b/HttpServer/app/src/main/java/icn/httpserver/com/httpserver/HttpServerActivity.java new file mode 100644 index 00000000..78ef8ff2 --- /dev/null +++ b/HttpServer/app/src/main/java/icn/httpserver/com/httpserver/HttpServerActivity.java @@ -0,0 +1,187 @@ +/* + * Copyright (c) 2018 Cisco and/or its affiliates. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at: + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package icn.httpserver.com.httpserver; + +import android.Manifest; +import android.app.Dialog; +import android.content.Intent; +import android.content.SharedPreferences; +import android.content.pm.PackageManager; +import android.content.res.Configuration; +import android.net.Uri; +import android.support.v4.app.ActivityCompat; +import android.support.v4.content.ContextCompat; +import android.support.v7.app.AppCompatActivity; +import android.os.Bundle; +import android.util.Log; +import android.view.View; +import android.widget.Button; +import android.widget.CompoundButton; +import android.widget.EditText; +import android.widget.Switch; + +import icn.httpserver.com.service.HttpServerService; +import icn.httpserver.com.supportlibrary.HttpServer; +import icn.httpserver.com.utility.Constants; +import icn.httpserver.com.utility.ResourcesEnumerator; + +public class HttpServerActivity extends AppCompatActivity { + private EditText rootFolderEditText; + private EditText tcpListenPortEditText; + private EditText webServerPrefixEditText; + private EditText proxyAddressEditText; + private EditText iCNproxyAddressEditText; + private Switch httpServerSwitch; + private Button yesButtonDialog; + private Button noButtonDialog; + + + private SharedPreferences sharedPreferences; + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_http_server); + checkEnabledPermission(Manifest.permission.WRITE_EXTERNAL_STORAGE); + checkEnabledPermission(Manifest.permission.READ_EXTERNAL_STORAGE); + if (!checkMetis(Constants.METIS_ID)) { + final Dialog dialog = new Dialog(this); + dialog.setContentView(R.layout.popup_message); + yesButtonDialog = (Button) dialog.findViewById(R.id.yesButtonDialog); + noButtonDialog = (Button) dialog.findViewById(R.id.noButtonDialog); + yesButtonDialog.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + try { + startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=" + Constants.METIS_ID))); + } catch (android.content.ActivityNotFoundException anfe) { + startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("https://play.google.com/store/apps/details?id=" + Constants.METIS_ID))); + } + dialog.hide(); + } + }); + noButtonDialog.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + dialog.hide(); + } + }); + dialog.show(); + + } + init(); + } + + + private void checkEnabledPermission(String permission) { + if (ContextCompat.checkSelfPermission(this, + permission) + != PackageManager.PERMISSION_GRANTED) { + if (ActivityCompat.shouldShowRequestPermissionRationale(this, + permission)) { + } else { + ActivityCompat.requestPermissions(this, + new String[]{permission}, + 1); + } + } + } + + private boolean checkMetis(String uri) { + PackageManager pm = getPackageManager(); + try { + pm.getPackageInfo(uri, PackageManager.GET_ACTIVITIES); + return true; + } catch (PackageManager.NameNotFoundException e) { + return false; + } + } + + private void init() { + sharedPreferences = getSharedPreferences(Constants.HTTP_SERVER_PREFERENCES, MODE_PRIVATE); + rootFolderEditText = (EditText) findViewById(R.id.rootFolderEditText); + rootFolderEditText.setText(sharedPreferences.getString(ResourcesEnumerator.ROOT_FOLDER.key(), Constants.DEFAULT_ROOT_FOLDER)); + tcpListenPortEditText = (EditText) findViewById(R.id.tcpListenPortEditText); + tcpListenPortEditText.setText(sharedPreferences.getString(ResourcesEnumerator.TCP_LISTEN_PORT.key(), Constants.DEFAULT_TCP_LISTEN_PORT)); + webServerPrefixEditText = (EditText) findViewById(R.id.webServerPrefixEditText); + webServerPrefixEditText.setText(sharedPreferences.getString(ResourcesEnumerator.WEBSERVER_PREFIX.key(), Constants.DEFAULT_WEBSERVER_PREFIX)); + proxyAddressEditText = (EditText) findViewById(R.id.proxyAddressEditText); + proxyAddressEditText.setText(sharedPreferences.getString(ResourcesEnumerator.PROXY_ADDRESS.key(), Constants.DEFAULT_PROXY_ADDRESS)); + iCNproxyAddressEditText = (EditText) findViewById(R.id.iCNproxyAddressEditText); + iCNproxyAddressEditText.setText(sharedPreferences.getString(ResourcesEnumerator.ICN_PROXY_ADDRESS.key(), Constants.DEFAULT_ICN_PROXY_ADDRESS)); + httpServerSwitch = (Switch) findViewById(R.id.httpServerSwitch); + if (HttpServer.getInstance().isRunning()) { + httpServerSwitch.setChecked(true); + rootFolderEditText.setEnabled(false); + tcpListenPortEditText.setEnabled(false); + webServerPrefixEditText.setEnabled(false); + proxyAddressEditText.setEnabled(false); + iCNproxyAddressEditText.setEnabled(false); + } + + httpServerSwitch.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { + + @Override + public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { + Log.v("Switch State=", "" + isChecked); + if (isChecked) { + httpServerSwitch.setText(Constants.ENABLED); + SharedPreferences.Editor sharedPreferencesEditor = getSharedPreferences(Constants.HTTP_SERVER_PREFERENCES, MODE_PRIVATE).edit(); + sharedPreferencesEditor.putString(ResourcesEnumerator.ROOT_FOLDER.key(), rootFolderEditText.getText().toString()); + sharedPreferencesEditor.putString(ResourcesEnumerator.TCP_LISTEN_PORT.key(), tcpListenPortEditText.getText().toString()); + sharedPreferencesEditor.putString(ResourcesEnumerator.WEBSERVER_PREFIX.key(), webServerPrefixEditText.getText().toString()); + sharedPreferencesEditor.putString(ResourcesEnumerator.PROXY_ADDRESS.key(), proxyAddressEditText.getText().toString()); + sharedPreferencesEditor.putString(ResourcesEnumerator.ICN_PROXY_ADDRESS.key(), iCNproxyAddressEditText.getText().toString()); + sharedPreferencesEditor.commit(); + rootFolderEditText.setEnabled(false); + tcpListenPortEditText.setEnabled(false); + webServerPrefixEditText.setEnabled(false); + proxyAddressEditText.setEnabled(false); + iCNproxyAddressEditText.setEnabled(false); + startHttpServer(); + + } else { + httpServerSwitch.setText(Constants.DISABLED); + rootFolderEditText.setEnabled(true); + tcpListenPortEditText.setEnabled(true); + webServerPrefixEditText.setEnabled(true); + proxyAddressEditText.setEnabled(true); + iCNproxyAddressEditText.setEnabled(true); + stopHttpServer(); + } + } + + }); + + + } + + private void startHttpServer() { + Intent intent = new Intent(this, HttpServerService.class); + startService(intent); + } + + private void stopHttpServer() { + Intent intent = new Intent(this, HttpServerService.class); + stopService(intent); + } + + @Override + public void onConfigurationChanged(Configuration newConfig) { + super.onConfigurationChanged(newConfig); + } + +} diff --git a/HttpServer/app/src/main/java/icn/httpserver/com/service/HttpServerService.java b/HttpServer/app/src/main/java/icn/httpserver/com/service/HttpServerService.java new file mode 100644 index 00000000..977993ee --- /dev/null +++ b/HttpServer/app/src/main/java/icn/httpserver/com/service/HttpServerService.java @@ -0,0 +1,156 @@ +/* + * Copyright (c) 2018 Cisco and/or its affiliates. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at: + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package icn.httpserver.com.service; + +import android.app.Notification; +import android.app.NotificationChannel; +import android.app.NotificationManager; +import android.app.PendingIntent; +import android.app.Service; +import android.content.Context; +import android.content.Intent; +import android.content.SharedPreferences; +import android.os.Build; +import android.os.IBinder; +import android.util.Log; + +import java.io.File; + +import icn.httpserver.com.httpserver.HttpServerActivity; +import icn.httpserver.com.supportlibrary.HttpServer; +import icn.httpserver.com.utility.Constants; +import icn.httpserver.com.utility.ResourcesEnumerator; + +/** + * Created by angelomantellini on 12/11/17. + */ + + +public class HttpServerService extends Service { + private final static String TAG = "HttpServerService"; + + private static Thread sHttpServerThread = null; + + public HttpServerService() { + } + + private String rootFolderString; + private String tcpListenPortString; + private String webServerPrefixString; + private String proxyAddressString; + private String iCNproxyAddressString; + + @Override + public IBinder onBind(Intent intent) { + return null; + } + + + @Override + public int onStartCommand(Intent intent, int flags, int startId) { + + HttpServer httpServer = HttpServer.getInstance(); + if (!httpServer.isRunning()) { + Log.d(TAG, "Starting Http Server"); + SharedPreferences sharedPreferences = getSharedPreferences(Constants.HTTP_SERVER_PREFERENCES, MODE_PRIVATE); + String rootFolderString = sharedPreferences.getString(ResourcesEnumerator.ROOT_FOLDER.key(), + null); + String tcpListenPortString = sharedPreferences.getString(ResourcesEnumerator.TCP_LISTEN_PORT.key(), null); + String webServerPrefixString = sharedPreferences.getString(ResourcesEnumerator.WEBSERVER_PREFIX.key(), null); + String proxyAddressString = sharedPreferences.getString(ResourcesEnumerator.PROXY_ADDRESS.key(), null); + String iCNproxyAddressString = sharedPreferences.getString(ResourcesEnumerator.ICN_PROXY_ADDRESS.key(), null); + File folder = new File(rootFolderString); + if (!folder.exists()) { + folder.mkdirs(); + } + + + startHttpServer(intent, rootFolderString, tcpListenPortString, webServerPrefixString, proxyAddressString, iCNproxyAddressString); + + + } else { + Log.d(TAG, "Http Server is already running."); + } + return Service.START_STICKY; + } + + + @Override + public void onDestroy() { + HttpServer httpServer = HttpServer.getInstance(); + Log.d(TAG, "Destroying HttpServer"); + if (httpServer.isRunning()) { + httpServer.stop(); + stopForeground(true); + } + super.onDestroy(); + } + + protected Runnable mHttpServerRunner = new Runnable() { + + //private String path; + @Override + public void run() { + HttpServer httpServer = HttpServer.getInstance(); + httpServer.start(rootFolderString, tcpListenPortString, webServerPrefixString, proxyAddressString, iCNproxyAddressString); + } + + + }; + + private void startHttpServer(Intent intent, String rootFolderString, String tcpListenPortString, String webServerPrefixString, String proxyAddressString, String iCNproxyAddressString) { + String NOTIFICATION_CHANNEL_ID = "12345"; + Notification.Builder notificationBuilder = null; + if (Build.VERSION.SDK_INT >= 26) { + notificationBuilder = new Notification.Builder(this, NOTIFICATION_CHANNEL_ID); + } else { + notificationBuilder = new Notification.Builder(this); + } + Intent notificationIntent = new Intent(this, HttpServerActivity.class); + PendingIntent activity = PendingIntent.getActivity(this, 0, notificationIntent, PendingIntent.FLAG_UPDATE_CURRENT); + + notificationBuilder.setContentTitle("HttpServer").setContentText("HttpServer").setOngoing(true).setContentIntent(activity); + Notification notification = notificationBuilder.build(); + + if (Build.VERSION.SDK_INT >= 26) { + NotificationChannel channel = new NotificationChannel(NOTIFICATION_CHANNEL_ID, "HttpServer", NotificationManager.IMPORTANCE_DEFAULT); + channel.setDescription("HttpServer"); + NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); + notificationManager.createNotificationChannel(channel); + + } + + startForeground(Constants.FOREGROUND_SERVICE, notification); + + + HttpServer httpServer = HttpServer.getInstance(); + if (!httpServer.isRunning()) { + this.rootFolderString = rootFolderString; + this.tcpListenPortString = tcpListenPortString; + this.webServerPrefixString = webServerPrefixString; + this.proxyAddressString = proxyAddressString; + this.iCNproxyAddressString = iCNproxyAddressString; + sHttpServerThread = new Thread(mHttpServerRunner, "HttpServerRunner"); + sHttpServerThread.start(); + } + + + Log.e(TAG, "HttpServer Started"); + + } + + +} diff --git a/HttpServer/app/src/main/java/icn/httpserver/com/supportlibrary/HttpServer.java b/HttpServer/app/src/main/java/icn/httpserver/com/supportlibrary/HttpServer.java new file mode 100644 index 00000000..5b5356db --- /dev/null +++ b/HttpServer/app/src/main/java/icn/httpserver/com/supportlibrary/HttpServer.java @@ -0,0 +1,46 @@ +/* + * Copyright (c) 2018 Cisco and/or its affiliates. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at: + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package icn.httpserver.com.supportlibrary; + +public class HttpServer { + + private static HttpServer sInstance = null; + + static { + System.loadLibrary("httpServerWrap"); + + } + + public static HttpServer getInstance() { + if (sInstance == null) { + sInstance = new HttpServer(); + } + return sInstance; + } + + private HttpServer() { + + } + + + public native boolean isRunning(); + + public native void start(String rootFolderString, + String tcpListenPortString, + String webServerPrefixString, + String proxyAddressString, + String iCNproxyAddressString); + public native void stop(); +} diff --git a/HttpServer/app/src/main/java/icn/httpserver/com/utility/Constants.java b/HttpServer/app/src/main/java/icn/httpserver/com/utility/Constants.java new file mode 100644 index 00000000..d44bcbfd --- /dev/null +++ b/HttpServer/app/src/main/java/icn/httpserver/com/utility/Constants.java @@ -0,0 +1,28 @@ +/* + * Copyright (c) 2018 Cisco and/or its affiliates. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at: + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package icn.httpserver.com.utility; + +public class Constants { + public static final String DEFAULT_ROOT_FOLDER = "/sdcard/HttpServer"; + public static final String DEFAULT_TCP_LISTEN_PORT = "8080"; + public static final String DEFAULT_WEBSERVER_PREFIX = "http://android-webserver"; + public static final String DEFAULT_PROXY_ADDRESS = "http://localhost/proxy"; + public static final String DEFAULT_ICN_PROXY_ADDRESS = "http://systemx-cicn.enst.fr"; + public static final String METIS_ID = "icn.forwarder.com.icnforwarderandroid"; + public static final String ENABLED = "Enabled"; + public static final String DISABLED = "Disabled"; + public static final String HTTP_SERVER_PREFERENCES = "httpServerPreferences"; + public static final int FOREGROUND_SERVICE = 101; +} diff --git a/HttpServer/app/src/main/java/icn/httpserver/com/utility/ResourcesEnumerator.java b/HttpServer/app/src/main/java/icn/httpserver/com/utility/ResourcesEnumerator.java new file mode 100644 index 00000000..8efb10d3 --- /dev/null +++ b/HttpServer/app/src/main/java/icn/httpserver/com/utility/ResourcesEnumerator.java @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2018 Cisco and/or its affiliates. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at: + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package icn.httpserver.com.utility; + +public enum ResourcesEnumerator { + ROOT_FOLDER("rootFolder"), + TCP_LISTEN_PORT("tcpListenPort"), + WEBSERVER_PREFIX("webServerPRefix"), + PROXY_ADDRESS("proxyAddress"), + ICN_PROXY_ADDRESS("iCNproxyAddress"); + + private String key; + + ResourcesEnumerator(String key) { + this.key = key; + } + + public String key() { + return key; + } +} diff --git a/HttpServer/app/src/main/res/drawable-v24/ic_launcher_foreground.xml b/HttpServer/app/src/main/res/drawable-v24/ic_launcher_foreground.xml new file mode 100644 index 00000000..c7bd21db --- /dev/null +++ b/HttpServer/app/src/main/res/drawable-v24/ic_launcher_foreground.xml @@ -0,0 +1,34 @@ +<vector xmlns:android="http://schemas.android.com/apk/res/android" + xmlns:aapt="http://schemas.android.com/aapt" + android:width="108dp" + android:height="108dp" + android:viewportHeight="108" + android:viewportWidth="108"> + <path + android:fillType="evenOdd" + android:pathData="M32,64C32,64 38.39,52.99 44.13,50.95C51.37,48.37 70.14,49.57 70.14,49.57L108.26,87.69L108,109.01L75.97,107.97L32,64Z" + android:strokeColor="#00000000" + android:strokeWidth="1"> + <aapt:attr name="android:fillColor"> + <gradient + android:endX="78.5885" + android:endY="90.9159" + android:startX="48.7653" + android:startY="61.0927" + android:type="linear"> + <item + android:color="#44000000" + android:offset="0.0" /> + <item + android:color="#00000000" + android:offset="1.0" /> + </gradient> + </aapt:attr> + </path> + <path + android:fillColor="#FFFFFF" + android:fillType="nonZero" + android:pathData="M66.94,46.02L66.94,46.02C72.44,50.07 76,56.61 76,64L32,64C32,56.61 35.56,50.11 40.98,46.06L36.18,41.19C35.45,40.45 35.45,39.3 36.18,38.56C36.91,37.81 38.05,37.81 38.78,38.56L44.25,44.05C47.18,42.57 50.48,41.71 54,41.71C57.48,41.71 60.78,42.57 63.68,44.05L69.11,38.56C69.84,37.81 70.98,37.81 71.71,38.56C72.44,39.3 72.44,40.45 71.71,41.19L66.94,46.02ZM62.94,56.92C64.08,56.92 65,56.01 65,54.88C65,53.76 64.08,52.85 62.94,52.85C61.8,52.85 60.88,53.76 60.88,54.88C60.88,56.01 61.8,56.92 62.94,56.92ZM45.06,56.92C46.2,56.92 47.13,56.01 47.13,54.88C47.13,53.76 46.2,52.85 45.06,52.85C43.92,52.85 43,53.76 43,54.88C43,56.01 43.92,56.92 45.06,56.92Z" + android:strokeColor="#00000000" + android:strokeWidth="1" /> +</vector> diff --git a/HttpServer/app/src/main/res/drawable/ic_launcher_background.xml b/HttpServer/app/src/main/res/drawable/ic_launcher_background.xml new file mode 100644 index 00000000..d5fccc53 --- /dev/null +++ b/HttpServer/app/src/main/res/drawable/ic_launcher_background.xml @@ -0,0 +1,170 @@ +<?xml version="1.0" encoding="utf-8"?> +<vector xmlns:android="http://schemas.android.com/apk/res/android" + android:width="108dp" + android:height="108dp" + android:viewportHeight="108" + android:viewportWidth="108"> + <path + android:fillColor="#26A69A" + android:pathData="M0,0h108v108h-108z" /> + <path + android:fillColor="#00000000" + android:pathData="M9,0L9,108" + android:strokeColor="#33FFFFFF" + android:strokeWidth="0.8" /> + <path + android:fillColor="#00000000" + android:pathData="M19,0L19,108" + android:strokeColor="#33FFFFFF" + android:strokeWidth="0.8" /> + <path + android:fillColor="#00000000" + android:pathData="M29,0L29,108" + android:strokeColor="#33FFFFFF" + android:strokeWidth="0.8" /> + <path + android:fillColor="#00000000" + android:pathData="M39,0L39,108" + android:strokeColor="#33FFFFFF" + android:strokeWidth="0.8" /> + <path + android:fillColor="#00000000" + android:pathData="M49,0L49,108" + android:strokeColor="#33FFFFFF" + android:strokeWidth="0.8" /> + <path + android:fillColor="#00000000" + android:pathData="M59,0L59,108" + android:strokeColor="#33FFFFFF" + android:strokeWidth="0.8" /> + <path + android:fillColor="#00000000" + android:pathData="M69,0L69,108" + android:strokeColor="#33FFFFFF" + android:strokeWidth="0.8" /> + <path + android:fillColor="#00000000" + android:pathData="M79,0L79,108" + android:strokeColor="#33FFFFFF" + android:strokeWidth="0.8" /> + <path + android:fillColor="#00000000" + android:pathData="M89,0L89,108" + android:strokeColor="#33FFFFFF" + android:strokeWidth="0.8" /> + <path + android:fillColor="#00000000" + android:pathData="M99,0L99,108" + android:strokeColor="#33FFFFFF" + android:strokeWidth="0.8" /> + <path + android:fillColor="#00000000" + android:pathData="M0,9L108,9" + android:strokeColor="#33FFFFFF" + android:strokeWidth="0.8" /> + <path + android:fillColor="#00000000" + android:pathData="M0,19L108,19" + android:strokeColor="#33FFFFFF" + android:strokeWidth="0.8" /> + <path + android:fillColor="#00000000" + android:pathData="M0,29L108,29" + android:strokeColor="#33FFFFFF" + android:strokeWidth="0.8" /> + <path + android:fillColor="#00000000" + android:pathData="M0,39L108,39" + android:strokeColor="#33FFFFFF" + android:strokeWidth="0.8" /> + <path + android:fillColor="#00000000" + android:pathData="M0,49L108,49" + android:strokeColor="#33FFFFFF" + android:strokeWidth="0.8" /> + <path + android:fillColor="#00000000" + android:pathData="M0,59L108,59" + android:strokeColor="#33FFFFFF" + android:strokeWidth="0.8" /> + <path + android:fillColor="#00000000" + android:pathData="M0,69L108,69" + android:strokeColor="#33FFFFFF" + android:strokeWidth="0.8" /> + <path + android:fillColor="#00000000" + android:pathData="M0,79L108,79" + android:strokeColor="#33FFFFFF" + android:strokeWidth="0.8" /> + <path + android:fillColor="#00000000" + android:pathData="M0,89L108,89" + android:strokeColor="#33FFFFFF" + android:strokeWidth="0.8" /> + <path + android:fillColor="#00000000" + android:pathData="M0,99L108,99" + android:strokeColor="#33FFFFFF" + android:strokeWidth="0.8" /> + <path + android:fillColor="#00000000" + android:pathData="M19,29L89,29" + android:strokeColor="#33FFFFFF" + android:strokeWidth="0.8" /> + <path + android:fillColor="#00000000" + android:pathData="M19,39L89,39" + android:strokeColor="#33FFFFFF" + android:strokeWidth="0.8" /> + <path + android:fillColor="#00000000" + android:pathData="M19,49L89,49" + android:strokeColor="#33FFFFFF" + android:strokeWidth="0.8" /> + <path + android:fillColor="#00000000" + android:pathData="M19,59L89,59" + android:strokeColor="#33FFFFFF" + android:strokeWidth="0.8" /> + <path + android:fillColor="#00000000" + android:pathData="M19,69L89,69" + android:strokeColor="#33FFFFFF" + android:strokeWidth="0.8" /> + <path + android:fillColor="#00000000" + android:pathData="M19,79L89,79" + android:strokeColor="#33FFFFFF" + android:strokeWidth="0.8" /> + <path + android:fillColor="#00000000" + android:pathData="M29,19L29,89" + android:strokeColor="#33FFFFFF" + android:strokeWidth="0.8" /> + <path + android:fillColor="#00000000" + android:pathData="M39,19L39,89" + android:strokeColor="#33FFFFFF" + android:strokeWidth="0.8" /> + <path + android:fillColor="#00000000" + android:pathData="M49,19L49,89" + android:strokeColor="#33FFFFFF" + android:strokeWidth="0.8" /> + <path + android:fillColor="#00000000" + android:pathData="M59,19L59,89" + android:strokeColor="#33FFFFFF" + android:strokeWidth="0.8" /> + <path + android:fillColor="#00000000" + android:pathData="M69,19L69,89" + android:strokeColor="#33FFFFFF" + android:strokeWidth="0.8" /> + <path + android:fillColor="#00000000" + android:pathData="M79,19L79,89" + android:strokeColor="#33FFFFFF" + android:strokeWidth="0.8" /> +</vector> diff --git a/HttpServer/app/src/main/res/layout/activity_http_server.xml b/HttpServer/app/src/main/res/layout/activity_http_server.xml new file mode 100644 index 00000000..e4a7614a --- /dev/null +++ b/HttpServer/app/src/main/res/layout/activity_http_server.xml @@ -0,0 +1,207 @@ +<?xml version="1.0" encoding="utf-8"?> +<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" + xmlns:app="http://schemas.android.com/apk/res-auto" + xmlns:tools="http://schemas.android.com/tools" + android:layout_width="match_parent" + android:layout_height="match_parent" + tools:context="icn.httpserver.com.httpserver.HttpServerActivity"> + + <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" + android:layout_width="0dp" + android:layout_height="wrap_content" + android:orientation="vertical" + app:layout_constraintBottom_toBottomOf="parent" + app:layout_constraintHorizontal_bias="0.099" + app:layout_constraintLeft_toLeftOf="parent" + app:layout_constraintRight_toRightOf="parent" + app:layout_constraintTop_toTopOf="parent" + app:layout_constraintVertical_bias="0.029999971"> + + <LinearLayout + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:orientation="vertical"> + + <TextView + android:id="@+id/rootFolderTextView" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:text="Root Folder" + android:textSize="30sp" + android:textStyle="bold" /> + + <LinearLayout + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:layout_weight="0.25" + android:orientation="horizontal" + android:paddingLeft="30dp"> + + <EditText + android:id="@+id/rootFolderEditText" + android:layout_width="500dp" + android:layout_height="wrap_content" + android:ems="10" + android:inputType="textUri" + android:text="8888:8888:8888:8888:8888:8888:8888:8888" + android:textSize="24sp" /> + + </LinearLayout> + </LinearLayout> + + <LinearLayout + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:orientation="vertical"> + + <TextView + android:id="@+id/tcpListenPortTextView" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:text="TCP Listen Port" + android:textSize="30sp" + android:textStyle="bold" /> + + + <LinearLayout + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:layout_weight="0.25" + android:orientation="horizontal" + android:paddingLeft="30dp"> + + + <EditText + android:id="@+id/tcpListenPortEditText" + android:layout_width="80dp" + android:layout_height="wrap_content" + android:ems="10" + android:inputType="number" + android:text="88888" + android:textSize="24sp" /> + + + </LinearLayout> + + </LinearLayout> + + + <LinearLayout + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:orientation="vertical"> + + <TextView + android:id="@+id/webServerPrefixTextView" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:text="Web Server Prefix" + android:textSize="30sp" + android:textStyle="bold" /> + + + <LinearLayout + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:layout_weight="0.25" + android:orientation="horizontal" + android:paddingLeft="30dp"> + + + <EditText + android:id="@+id/webServerPrefixEditText" + android:layout_width="500dp" + android:layout_height="wrap_content" + android:ems="10" + android:inputType="textUri" + android:text="8888:8888:8888:8888:8888:8888:8888:8888" + android:textSize="24sp" /> + + + </LinearLayout> + + </LinearLayout> + + <LinearLayout + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:orientation="vertical"> + + <TextView + android:id="@+id/proxyAddressTextView" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:text="Proxy Address" + android:textSize="30sp" + android:textStyle="bold" /> + + + <LinearLayout + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:layout_weight="0.25" + android:orientation="horizontal" + android:paddingLeft="30dp"> + + + <EditText + android:id="@+id/proxyAddressEditText" + android:layout_width="500dp" + android:layout_height="wrap_content" + android:ems="10" + android:inputType="textUri" + android:text="8888:8888:8888:8888:8888:8888:8888:8888" + android:textSize="24sp" /> + + + </LinearLayout> + + </LinearLayout> + + <LinearLayout + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:orientation="vertical"> + + <TextView + android:id="@+id/iCNproxyAddressTextView" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:text="ICN Proxy Address" + android:textSize="30sp" + android:textStyle="bold" /> + + + <LinearLayout + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:layout_weight="0.25" + android:orientation="horizontal" + android:paddingLeft="30dp"> + + <EditText + android:id="@+id/iCNproxyAddressEditText" + android:layout_width="500dp" + android:layout_height="wrap_content" + android:ems="10" + android:inputType="textUri" + android:text="8888:8888:8888:8888:8888:8888:8888:8888" + android:textSize="24sp" /> + + + </LinearLayout> + + </LinearLayout> + + + <Switch + android:id="@+id/httpServerSwitch" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:layout_gravity="center" + android:text="Disabled" + android:textSize="30sp" /> + </LinearLayout> + + +</android.support.constraint.ConstraintLayout> diff --git a/HttpServer/app/src/main/res/layout/popup_message.xml b/HttpServer/app/src/main/res/layout/popup_message.xml new file mode 100644 index 00000000..a2631820 --- /dev/null +++ b/HttpServer/app/src/main/res/layout/popup_message.xml @@ -0,0 +1,44 @@ +<?xml version="1.0" encoding="utf-8"?> +<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" + android:layout_width="fill_parent" + android:layout_height="wrap_content" + android:background="#FFFFFF" + android:orientation="vertical"> + + <TextView + android:id="@+id/txt_dia" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:layout_gravity="center" + android:layout_margin="10dp" + android:text="Metis is not installed.\nDo you want to install it?" + android:textColor="#1B90CD" + android:textSize="15dp" + android:textStyle="bold" /> + + + <LinearLayout + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:layout_gravity="center" + android:orientation="horizontal"> + + <Button + android:id="@+id/yesButtonDialog" + android:layout_width="100dp" + android:layout_height="wrap_content" + android:clickable="true" + android:text="Yes" + android:textStyle="bold" /> + + <Button + android:id="@+id/noButtonDialog" + android:layout_width="100dp" + android:layout_height="wrap_content" + android:layout_marginLeft="5dp" + android:clickable="true" + android:text="No" + android:textStyle="bold" /> + </LinearLayout> + +</LinearLayout>
\ No newline at end of file diff --git a/HttpServer/app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml b/HttpServer/app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml new file mode 100644 index 00000000..036d09bc --- /dev/null +++ b/HttpServer/app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml @@ -0,0 +1,5 @@ +<?xml version="1.0" encoding="utf-8"?> +<adaptive-icon xmlns:android="http://schemas.android.com/apk/res/android"> + <background android:drawable="@color/ic_launcher_background"/> + <foreground android:drawable="@mipmap/ic_launcher_foreground"/> +</adaptive-icon>
\ No newline at end of file diff --git a/HttpServer/app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml b/HttpServer/app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml new file mode 100644 index 00000000..036d09bc --- /dev/null +++ b/HttpServer/app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml @@ -0,0 +1,5 @@ +<?xml version="1.0" encoding="utf-8"?> +<adaptive-icon xmlns:android="http://schemas.android.com/apk/res/android"> + <background android:drawable="@color/ic_launcher_background"/> + <foreground android:drawable="@mipmap/ic_launcher_foreground"/> +</adaptive-icon>
\ No newline at end of file diff --git a/HttpServer/app/src/main/res/mipmap-hdpi/ic_launcher.png b/HttpServer/app/src/main/res/mipmap-hdpi/ic_launcher.png Binary files differnew file mode 100644 index 00000000..1dbe3aa2 --- /dev/null +++ b/HttpServer/app/src/main/res/mipmap-hdpi/ic_launcher.png diff --git a/HttpServer/app/src/main/res/mipmap-hdpi/ic_launcher_foreground.png b/HttpServer/app/src/main/res/mipmap-hdpi/ic_launcher_foreground.png Binary files differnew file mode 100644 index 00000000..edefad42 --- /dev/null +++ b/HttpServer/app/src/main/res/mipmap-hdpi/ic_launcher_foreground.png diff --git a/HttpServer/app/src/main/res/mipmap-hdpi/ic_launcher_round.png b/HttpServer/app/src/main/res/mipmap-hdpi/ic_launcher_round.png Binary files differnew file mode 100644 index 00000000..111c8539 --- /dev/null +++ b/HttpServer/app/src/main/res/mipmap-hdpi/ic_launcher_round.png diff --git a/HttpServer/app/src/main/res/mipmap-mdpi/ic_launcher.png b/HttpServer/app/src/main/res/mipmap-mdpi/ic_launcher.png Binary files differnew file mode 100644 index 00000000..c48f24f5 --- /dev/null +++ b/HttpServer/app/src/main/res/mipmap-mdpi/ic_launcher.png diff --git a/HttpServer/app/src/main/res/mipmap-mdpi/ic_launcher_foreground.png b/HttpServer/app/src/main/res/mipmap-mdpi/ic_launcher_foreground.png Binary files differnew file mode 100644 index 00000000..d6759fbd --- /dev/null +++ b/HttpServer/app/src/main/res/mipmap-mdpi/ic_launcher_foreground.png diff --git a/HttpServer/app/src/main/res/mipmap-mdpi/ic_launcher_round.png b/HttpServer/app/src/main/res/mipmap-mdpi/ic_launcher_round.png Binary files differnew file mode 100644 index 00000000..de197c96 --- /dev/null +++ b/HttpServer/app/src/main/res/mipmap-mdpi/ic_launcher_round.png diff --git a/HttpServer/app/src/main/res/mipmap-xhdpi/ic_launcher.png b/HttpServer/app/src/main/res/mipmap-xhdpi/ic_launcher.png Binary files differnew file mode 100644 index 00000000..8dbd4a40 --- /dev/null +++ b/HttpServer/app/src/main/res/mipmap-xhdpi/ic_launcher.png diff --git a/HttpServer/app/src/main/res/mipmap-xhdpi/ic_launcher_foreground.png b/HttpServer/app/src/main/res/mipmap-xhdpi/ic_launcher_foreground.png Binary files differnew file mode 100644 index 00000000..e2e76cdb --- /dev/null +++ b/HttpServer/app/src/main/res/mipmap-xhdpi/ic_launcher_foreground.png diff --git a/HttpServer/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png b/HttpServer/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png Binary files differnew file mode 100644 index 00000000..d0b0550a --- /dev/null +++ b/HttpServer/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png diff --git a/HttpServer/app/src/main/res/mipmap-xxhdpi/ic_launcher.png b/HttpServer/app/src/main/res/mipmap-xxhdpi/ic_launcher.png Binary files differnew file mode 100644 index 00000000..6af4627e --- /dev/null +++ b/HttpServer/app/src/main/res/mipmap-xxhdpi/ic_launcher.png diff --git a/HttpServer/app/src/main/res/mipmap-xxhdpi/ic_launcher_foreground.png b/HttpServer/app/src/main/res/mipmap-xxhdpi/ic_launcher_foreground.png Binary files differnew file mode 100644 index 00000000..8f7a4216 --- /dev/null +++ b/HttpServer/app/src/main/res/mipmap-xxhdpi/ic_launcher_foreground.png diff --git a/HttpServer/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png b/HttpServer/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png Binary files differnew file mode 100644 index 00000000..037af884 --- /dev/null +++ b/HttpServer/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png diff --git a/HttpServer/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png b/HttpServer/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png Binary files differnew file mode 100644 index 00000000..7997db04 --- /dev/null +++ b/HttpServer/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png diff --git a/HttpServer/app/src/main/res/mipmap-xxxhdpi/ic_launcher_foreground.png b/HttpServer/app/src/main/res/mipmap-xxxhdpi/ic_launcher_foreground.png Binary files differnew file mode 100644 index 00000000..1d886ce9 --- /dev/null +++ b/HttpServer/app/src/main/res/mipmap-xxxhdpi/ic_launcher_foreground.png diff --git a/HttpServer/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png b/HttpServer/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png Binary files differnew file mode 100644 index 00000000..87477445 --- /dev/null +++ b/HttpServer/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png diff --git a/HttpServer/app/src/main/res/values/colors.xml b/HttpServer/app/src/main/res/values/colors.xml new file mode 100644 index 00000000..3ab3e9cb --- /dev/null +++ b/HttpServer/app/src/main/res/values/colors.xml @@ -0,0 +1,6 @@ +<?xml version="1.0" encoding="utf-8"?> +<resources> + <color name="colorPrimary">#3F51B5</color> + <color name="colorPrimaryDark">#303F9F</color> + <color name="colorAccent">#FF4081</color> +</resources> diff --git a/HttpServer/app/src/main/res/values/ic_launcher_background.xml b/HttpServer/app/src/main/res/values/ic_launcher_background.xml new file mode 100644 index 00000000..fb66f3a0 --- /dev/null +++ b/HttpServer/app/src/main/res/values/ic_launcher_background.xml @@ -0,0 +1,4 @@ +<?xml version="1.0" encoding="utf-8"?> +<resources> + <color name="ic_launcher_background">#FEFEFE</color> +</resources>
\ No newline at end of file diff --git a/HttpServer/app/src/main/res/values/strings.xml b/HttpServer/app/src/main/res/values/strings.xml new file mode 100644 index 00000000..cdb15faa --- /dev/null +++ b/HttpServer/app/src/main/res/values/strings.xml @@ -0,0 +1,3 @@ +<resources> + <string name="app_name">HttpServer</string> +</resources> diff --git a/HttpServer/app/src/main/res/values/styles.xml b/HttpServer/app/src/main/res/values/styles.xml new file mode 100644 index 00000000..5885930d --- /dev/null +++ b/HttpServer/app/src/main/res/values/styles.xml @@ -0,0 +1,11 @@ +<resources> + + <!-- Base application theme. --> + <style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar"> + <!-- Customize your theme here. --> + <item name="colorPrimary">@color/colorPrimary</item> + <item name="colorPrimaryDark">@color/colorPrimaryDark</item> + <item name="colorAccent">@color/colorAccent</item> + </style> + +</resources> diff --git a/HttpServer/app/src/test/java/icn/httpserver/com/hicnhttpserver/ExampleUnitTest.java b/HttpServer/app/src/test/java/icn/httpserver/com/hicnhttpserver/ExampleUnitTest.java new file mode 100644 index 00000000..e70b06db --- /dev/null +++ b/HttpServer/app/src/test/java/icn/httpserver/com/hicnhttpserver/ExampleUnitTest.java @@ -0,0 +1,32 @@ +/* + * Copyright (c) 2018 Cisco and/or its affiliates. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at: + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package icn.httpserver.com.hicnhttpserver; + +import org.junit.Test; + +import static org.junit.Assert.*; + +/** + * Example local unit test, which will execute on the development machine (host). + * + * @see <a href="http://d.android.com/tools/testing">Testing documentation</a> + */ +public class ExampleUnitTest { + @Test + public void addition_isCorrect() throws Exception { + assertEquals(4, 2 + 2); + } +} diff --git a/HttpServer/build.gradle b/HttpServer/build.gradle new file mode 100644 index 00000000..43cfc775 --- /dev/null +++ b/HttpServer/build.gradle @@ -0,0 +1,28 @@ +// Top-level build file where you can add configuration options common to all sub-projects/modules. + +buildscript { + + repositories { + google() + jcenter() + } + dependencies { + classpath 'com.android.tools.build:gradle:3.0.1' + + + // NOTE: Do not place your application dependencies here; they belong + // in the individual module build.gradle files + } + +} + +allprojects { + repositories { + google() + jcenter() + } +} + +task clean(type: Delete) { + delete rootProject.buildDir +} diff --git a/HttpServer/gradle.properties b/HttpServer/gradle.properties new file mode 100644 index 00000000..aac7c9b4 --- /dev/null +++ b/HttpServer/gradle.properties @@ -0,0 +1,17 @@ +# Project-wide Gradle settings. + +# IDE (e.g. Android Studio) users: +# Gradle settings configured through the IDE *will override* +# any settings specified in this file. + +# For more details on how to configure your build environment visit +# http://www.gradle.org/docs/current/userguide/build_environment.html + +# Specifies the JVM arguments used for the daemon process. +# The setting is particularly useful for tweaking memory settings. +org.gradle.jvmargs=-Xmx1536m + +# When configured, Gradle will run in incubating parallel mode. +# This option should only be used with decoupled projects. More details, visit +# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects +# org.gradle.parallel=true diff --git a/HttpServer/gradle/wrapper/gradle-wrapper.jar b/HttpServer/gradle/wrapper/gradle-wrapper.jar Binary files differnew file mode 100644 index 00000000..13372aef --- /dev/null +++ b/HttpServer/gradle/wrapper/gradle-wrapper.jar diff --git a/HttpServer/gradle/wrapper/gradle-wrapper.properties b/HttpServer/gradle/wrapper/gradle-wrapper.properties new file mode 100644 index 00000000..7ff9d56c --- /dev/null +++ b/HttpServer/gradle/wrapper/gradle-wrapper.properties @@ -0,0 +1,6 @@ +#Mon Dec 11 13:54:53 CET 2017 +distributionBase=GRADLE_USER_HOME +distributionPath=wrapper/dists +zipStoreBase=GRADLE_USER_HOME +zipStorePath=wrapper/dists +distributionUrl=https\://services.gradle.org/distributions/gradle-4.1-all.zip diff --git a/HttpServer/gradlew b/HttpServer/gradlew new file mode 100755 index 00000000..9d82f789 --- /dev/null +++ b/HttpServer/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/HttpServer/gradlew.bat b/HttpServer/gradlew.bat new file mode 100644 index 00000000..aec99730 --- /dev/null +++ b/HttpServer/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/HttpServer/settings.gradle b/HttpServer/settings.gradle new file mode 100644 index 00000000..e7b4def4 --- /dev/null +++ b/HttpServer/settings.gradle @@ -0,0 +1 @@ +include ':app' |