diff --git a/MacOS_X_InstallGuide.md b/MacOS_X_InstallGuide.md new file mode 100644 index 000000000..ab20893e3 --- /dev/null +++ b/MacOS_X_InstallGuide.md @@ -0,0 +1,71 @@ +##Compilation on MacOS + +### Qt Installation + +Install Qt via: [Qt Download](http://www.qt.io/download/) + +Use default options. +Add to the PATH environment variable with this temporary solution. + + export PATH=/users/$USER/Qt/5.5/clang_64/bin:$PATH + +Depends on wich version of Qt you use. + +###MacPort Installation + +Install MacPort and XCode following this guide: [MacPort and XCode](http://guide.macports.org/#installing.xcode) + +Start XCode to get it updated and to able C compiler to create executables. + +###Install libraries + + $sudo port -v selfupdate + $sudo port install openssl + $sudo port install miniupnpc + +For VOIP Plugin: + + $sudo port install speex-devel + $sudo port install opencv + +Get Your OSX SDK if missing: [MacOSX-SDKs](https://github.com/phracker/MacOSX-SDKs) + +###Last Settings + +In QtCreator Option Git add its path: + + C:\Program Files\Git\bin + +and select "Pull" with "Rebase" + +###Compil missing libraries +####SQLCipher + + cd + git clone https://github.com/sqlcipher/sqlcipher.git + cd sqlcipher + ./configure --enable-tempstore=yes CFLAGS="-DSQLITE_HAS_CODEC" LDFLAGS="-lcrypto" + make + sudo make install + +NOTE, might be necessary to *chmod 000 /usr/local/ssl* temporarily during *./configure* if +homebrew uses newer, non-stock ssl dependencies found there. configure might get confused. + +####libMicroHTTPD +The one with port don't have good support. + + cd + wget http://ftpmirror.gnu.org/libmicrohttpd/libmicrohttpd-0.9.46.tar.gz + tar zxvf libmicrohttpd-0.9.46.tar.gz + cd libmicrohttpd-0.9.46 + bash ./configure + sudo make install + +You can now compile RS into Qt Creator or with terminal + + cd + git clone https://github.com/RetroShare/RetroShare.git retroshare + cd retroshare + qmake; make + +You can find compiled application on *./retroshare/retroshare-gui/src/RetroShare06.app* diff --git a/MacOS_X_InstallGuide.txt b/MacOS_X_InstallGuide.txt deleted file mode 100644 index d56963611..000000000 --- a/MacOS_X_InstallGuide.txt +++ /dev/null @@ -1,66 +0,0 @@ -############################# -###--- QT INSTALLATION ---### -############################# - -###Install Qt via: -http://www.qt.io/download/ - -###Use default options. -###Add to the PATH environment variable with this temporary solution. -export PATH=/users/$USER/Qt/5.5/clang_64/bin:$PATH -###Depends on wich version of Qt you use. - -################################## -###--- MACPORT INSTALLATION ---### -################################## - -###Install MacPort and XCode following this guide: -http://guide.macports.org/#installing.xcode - -###Start XCode to get it updated and to able C compiler to create executables. - -###Install libraries -$sudo port -v selfupdate -$sudo port install openssl -$sudo port install miniupnpc -###For VOIP Plugin: -$sudo port install speex-devel -$sudo port install opencv - -###Get Your OSX SDK if missing: -https://github.com/phracker/MacOSX-SDKs - -########################### -###--- LAST SETTINGS ---### -########################### - -###In QtCreator Option Git add its path: -C:\Program Files\Git\bin -### and select "Pull" with "Rebase" - -###Compil missing libraries -###SQLCipher -cd -git clone https://github.com/sqlcipher/sqlcipher.git -cd sqlcipher -./configure --enable-tempstore=yes CFLAGS="-DSQLITE_HAS_CODEC" LDFLAGS="-lcrypto" -make -sudo make install -#NOTE, might be necessary to chmod 000 /usr/local/ssl temporarily during ./configure if -#homebrew uses newer, non-stock ssl dependencies found there. configure might get confused. - -### libMicroHTTPD: The one with port don't have good support. -cd -wget http://ftpmirror.gnu.org/libmicrohttpd/libmicrohttpd-0.9.46.tar.gz -tar zxvf libmicrohttpd-0.9.46.tar.gz -cd libmicrohttpd-0.9.46 -bash ./configure -sudo make install - -###You can now compile RS into Qt Creator or with terminal -cd -git clone https://github.com/RetroShare/RetroShare.git retroshare -cd retroshare -qmake;make - -###You can find compiled application on ./retroshare/retroshare-gui/src/RetroShare06.app diff --git a/README.md b/README.md index 4394180f0..dea1e4b8b 100644 --- a/README.md +++ b/README.md @@ -12,11 +12,11 @@ Build Status Compilation on Windows ---------------------------- -Follow this file : [WindowsMSys2_InstallGuide.txt](https://github.com/RetroShare/RetroShare/blob/master/WindowsMSys2_InstallGuide.txt) +Follow this file : [WindowsMSys2_InstallGuide.md](https://github.com/RetroShare/RetroShare/blob/master/WindowsMSys2_InstallGuide.md) Compilation on MacOSX ---------------------------- -Follow this file : [MacOS_X_InstallGuide.txt](https://github.com/RetroShare/RetroShare/blob/master/MacOS_X_InstallGuide.txt) +Follow this file : [MacOS_X_InstallGuide](https://github.com/RetroShare/RetroShare/blob/master/MacOS_X_InstallGuide.md) Compilation on Linux ---------------------------- @@ -67,6 +67,11 @@ Compilation on Linux /usr/bin/RetroShare06 /usr/bin/RetroShare06-nogui +5. Uninstall: + ```bash + sudo make uninstall + ``` + Compile only retroshare-nogui ----------------------------- If you want to run RetroShare on a server and don’t need the gui and plugins, diff --git a/WindowsMSys2_InstallGuide.md b/WindowsMSys2_InstallGuide.md new file mode 100644 index 000000000..c6782744d --- /dev/null +++ b/WindowsMSys2_InstallGuide.md @@ -0,0 +1,87 @@ +##Compilation on Windows + +###Qt Installation + +Install Qt via: [Qt Download](http://www.qt.io/download/) + +Use default options. +Add to the PATH environment variable + + ;C:\Qt\5.5\mingw492_32\bin;C:\Qt\Tools\mingw492_32\bin;C:\Qt\Tools\mingw492_32\opt\bin + +Depends on wich version of Qt you use. +Change build-all-mingw32make.bat with these values too if you don't use MSys2. + +###MSYS2 INSTALLATION + +Choose your MSYS2 installer here: [MSYS2](http://msys2.github.io/) + +Follow install procedure. +Don't forget to sync & Update pacman. + + pacman --needed -Sy bash pacman pacman-mirrors msys2-runtime + +Restart console + + pacman -Su + +Install all default programms + + pacman -S base-devel git mercurial cvs wget p7zip gcc perl ruby python2 + +Choose only w64-i686 if you want only compilation in 32b architecture. + + pacman -S mingw-w64-i686-toolchain mingw-w64-x86_64-toolchain + +###Install other binutils: + pacman -S mingw-w64-i686-miniupnpc mingw-w64-x86_64-miniupnpc + pacman -S mingw-w64-i686-sqlite3 mingw-w64-x86_64-sqlite3 + pacman -S mingw-w64-i686-speex mingw-w64-x86_64-speex + pacman -S mingw-w64-i686-opencv mingw-w64-x86_64-opencv + pacman -S mingw-w64-i686-ffmpeg mingw-w64-x86_64-ffmpeg + pacman -S mingw-w64-i686-libmicrohttpd mingw-w64-x86_64-libmicrohttpd + pacman -S mingw-w64-i686-libxslt mingw-w64-x86_64-libxslt + +Add MSYS2 to PATH environment variable depends your windows + + ;C:\msys64\mingw32\bin + ;C:\msys32\mingw32\bin + + +###Git Installation + +Install Git Gui or other client: [Git Scm](https://git-scm.com/download/win) + +Create a new directory named: + + C:\Development\GIT + +Right-click on it and choose: *Git Bash Here* + +Paste this text on git console: +git clone https://github.com/RetroShare/RetroShare.git + + +###Last Settings + + +In QtCreator Option Git add its path: *C:\Program Files\Git\bin* +and select "Pull" with "Rebase" + + +Open an MSys2 32|64 shell +Move to build_scripts: + + cd /c/Development/GIT/RetroShare/msys2_build_libs/ + +###Compile missing library + make + +You can now compile RS into Qt Creator + +For using, and debugging Plugins, you can use [Symlinker](http://amd989.github.io/Symlinker/) to link +the files in + + \build-RetroShare-Desktop_Qt_X_Y_Z_MinGW_32bit-Debug\plugins\PluginName\debug\*.dll +to +*%appdata%\RetroShare\extensions6* diff --git a/WindowsMSys2_InstallGuide.txt b/WindowsMSys2_InstallGuide.txt deleted file mode 100644 index ded6a1420..000000000 --- a/WindowsMSys2_InstallGuide.txt +++ /dev/null @@ -1,89 +0,0 @@ -############################# -###--- QT INSTALLATION ---### -############################# - -###Install Qt via: -http://www.qt.io/download/ - -###Use default options. -###Add to the PATH environment variable. -;C:\Qt\5.5\mingw492_32\bin;C:\Qt\Tools\mingw492_32\bin;C:\Qt\Tools\mingw492_32\opt\bin - -###Depends on wich version of Qt you use. - -###Change build-all-mingw32make.bat with these values too if you don't use MSys2. - - -############################### -###---MSYS2 INSTALLATION ---### -############################### - -###Choose your MSYS2 installer here: -http://msys2.github.io/ - -###Follow install procedure. -###Don't forget to sync & Update pacman. -pacman --needed -Sy bash pacman pacman-mirrors msys2-runtime - -###Restart console -pacman -Su - -###Install all default programms -pacman -S base-devel git mercurial cvs wget p7zip gcc perl ruby python2 - -###Choose only w64-i686 if you want only compilation in 32b architecture. -pacman -S mingw-w64-i686-toolchain mingw-w64-x86_64-toolchain - -###Install other binutils: -pacman -S mingw-w64-i686-miniupnpc mingw-w64-x86_64-miniupnpc -pacman -S mingw-w64-i686-sqlite3 mingw-w64-x86_64-sqlite3 -pacman -S mingw-w64-i686-speex mingw-w64-x86_64-speex -pacman -S mingw-w64-i686-opencv mingw-w64-x86_64-opencv -pacman -S mingw-w64-i686-ffmpeg mingw-w64-x86_64-ffmpeg -pacman -S mingw-w64-i686-libmicrohttpd mingw-w64-x86_64-libmicrohttpd -pacman -S mingw-w64-i686-libxslt mingw-w64-x86_64-libxslt - -### Add MSYS2 to PATH environment variable depends your windows -;C:\msys64\mingw32\bin -;C:\msys32\mingw32\bin - - -############################## -###--- GIT INSTALLATION ---### -############################## - -###Install Git Gui or other client: -https://git-scm.com/download/win - -###Create a new directory named: -C:\Development\GIT - -###Right-click on it and choose: -Git Bash Here - -###Paste this text on git console: -git clone https://github.com/RetroShare/RetroShare.git - - -########################### -###--- LAST SETTINGS ---### -########################### - -###In QtCreator Option Git add its path: -C:\Program Files\Git\bin -### and select "Pull" with "Rebase" - - -###Open an MSys2 32|64 shell -###Move to build_scripts: -cd /c/Development/GIT/RetroShare/msys2_build_libs/ - -###Compil missing library -make - -###You can now compile RS into Qt Creator - -###For using, and debugging Plugins, you can use SymLinker (http://amd989.github.io/Symlinker/) to link -### the files in \build-RetroShare-Desktop_Qt_X_Y_Z_MinGW_32bit-Debug\plugins\PluginName\debug\*.dll -### to %appdata%\RetroShare\extensions6 - diff --git a/build_scripts/Debian+Ubuntu/changelog b/build_scripts/Debian+Ubuntu/changelog index fa6a37703..666e580fb 100644 --- a/build_scripts/Debian+Ubuntu/changelog +++ b/build_scripts/Debian+Ubuntu/changelog @@ -1,5 +1,43 @@ retroshare06 (0.6.1-1.XXXXXX~YYYYYY) YYYYYY; urgency=low + 9a3eb1c csoler Sat, 8 Oct 2016 14:30:58 +0200 Merge pull request #528 from sehraf/pr-drop-ssh-protobuf + c55fb0d csoler Sat, 8 Oct 2016 14:11:43 +0200 Merge pull request #524 from cavebeat/compile + 97f2589 csoler Sat, 8 Oct 2016 14:09:34 +0200 Merge pull request #513 from grennvyper/patch-1 + aa200bf csoler Sat, 8 Oct 2016 14:06:54 +0200 Merge pull request #526 from marcobarbosa16/master + 2591818 csoler Sat, 8 Oct 2016 14:04:31 +0200 Merge pull request #515 from PhenomRetroShare/Add_ContextMenuToShowImageInLobby + 9ed759d csoler Sat, 8 Oct 2016 13:38:18 +0200 Merge pull request #527 from PhenomRetroShare/Fix_DesktopFileName + ada1cee sehraf Sat, 8 Oct 2016 12:59:27 +0200 remove deprecated ssh/protobuf code + 4b0f82a Phenom Sat, 8 Oct 2016 12:12:26 +0200 Fix Desktop Filename for option page message. + 69ecca4 MarcoBarbosa Fri, 7 Oct 2016 23:12:40 -0300 add uninstall section in README.md + 7cd31aa csoler Wed, 5 Oct 2016 14:15:12 +0200 fixed bug preventign update of subdirs after last commit + fdfd2e9 Phenom Sat, 24 Sep 2016 16:12:44 +0200 Add context menu to show hidden image on lobby. + 854eebb csoler Wed, 5 Oct 2016 10:59:51 +0200 only update subfiles and subdirs list during dir watching sweep when the TS of the dir has changed. Greatly improve cost of regular directory watching process + d020d8d thunder2 Wed, 5 Oct 2016 06:40:02 +0200 Windows build environment: - Added automatic mode for creating git-log - Fixed filename of installer + 891e61e cave beat Tue, 4 Oct 2016 23:27:40 +0200 MacOS to .md, + README update + 9177c82 cave beat Tue, 4 Oct 2016 23:14:50 +0200 updated MSys2 Install Guide to .md + d367491 thunder2 Tue, 4 Oct 2016 21:45:59 +0200 Fixed env.bat for Windows build + 20cd123 csoler Tue, 4 Oct 2016 21:41:38 +0200 removed annoying ERROR output that is more a debug info than a real error, in p3filelists + e42dae8 csoler Tue, 4 Oct 2016 21:34:23 +0200 continue sending packet slicing probes in case the peer has restarted + b08a62a csoler Tue, 4 Oct 2016 21:25:48 +0200 restored delay between location cleaning to 5 mins + 133676f csoler Tue, 4 Oct 2016 21:24:53 +0200 simplified the code to remove old locations and fixed bug that in some situation would let a PGP key with no locations + a35985e thunder2 Tue, 6 Sep 2016 21:31:41 +0200 Windows build environment: - Added build script - Added build-installer script - Added pack script - Added gitlog script - Use shadow build + ebfc82c csoler Mon, 3 Oct 2016 21:44:34 +0200 save/restore selection in shared dir list tree view + ed8d786 csoler Mon, 3 Oct 2016 20:49:49 +0200 added missing mChanged=false that caused remote directories to save far too often + c968490 csoler Sat, 1 Oct 2016 22:14:50 +0200 switched to floating point time for bandwidth estimation in pqistreamer. Helps a lot RTTs since rounding to int prveviously caused packets to be delayed up to 1 sec (improvement by Jollavilette) + 20397c3 csoler Sat, 1 Oct 2016 18:09:39 +0200 Merge pull request #523 from bryongloden/patch-1 + 9ae0511 Bryon Gloden Sat, 1 Oct 2016 12:01:09 -0400 uninitialized variable: size + a751155 csoler Sat, 1 Oct 2016 15:46:32 +0200 do not send un-hashed files to friends, and allow to re-send the directory content when all files are hashed + 84341f2 csoler Thu, 29 Sep 2016 22:30:26 +0200 changed _outgoing_file_hashes into a new map that connects services to tunnel ID instead of file hash, hence avoiding to remove a hash on server side when a tunnel is closed (bug found by Jolavillette) + b62b66a csoler Thu, 29 Sep 2016 20:55:16 +0200 replace std::vector for std::set to represent _hashes_to_remove, so as to avoid duplicates (suggested by Jo) + 1fd624c csoler Thu, 29 Sep 2016 12:47:14 +0200 Merge pull request #519 from PhenomRetroShare/Fix_WinCompil + 0ea909d Phenom Thu, 29 Sep 2016 12:45:01 +0200 Fix Windows Compilation after 6e4ba76b + e185bcd csoler Wed, 28 Sep 2016 23:02:24 +0200 fixed removal of directory when removing a friend + c276165 csoler Wed, 28 Sep 2016 22:28:43 +0200 updated clean.sh script to 0.6.1 + + -- Cyril Soler Sat, 8 Oct 2016 15:00:00 +0100 + +retroshare06 (0.6.1-1.20160928.e185bcda~trusty) trusty; urgency=low + Warning: new file list sharing system. * Old list of shares is not preserved and should be re-defined. * The hash cache however is imported from the old format, meaning that Retroshare should not re-hash new files that were already shared before. diff --git a/build_scripts/Windows/.gitignore b/build_scripts/Windows/.gitignore new file mode 100644 index 000000000..a7b500b79 --- /dev/null +++ b/build_scripts/Windows/.gitignore @@ -0,0 +1 @@ +/build/env-mod.bat \ No newline at end of file diff --git a/build_scripts/Windows/build/build-installer.bat b/build_scripts/Windows/build/build-installer.bat new file mode 100644 index 000000000..9d3aa837e --- /dev/null +++ b/build_scripts/Windows/build/build-installer.bat @@ -0,0 +1,56 @@ +@echo off + +setlocal + +:: Initialize environment +call "%~dp0..\env.bat" +if errorlevel 1 goto error_env +call "%EnvPath%\env.bat" +if errorlevel 1 goto error_env + +:: Get gcc versions +call "%ToolsPath%\get-gcc-version.bat" GCCVersion +if "%GCCVersion%"=="" echo Cannot get gcc version.& exit /B 1 + +:: Check external libraries +if not exist "%RootPath%\libs" echo Please build external libraries first.& exit /B 1 + +:: Check gcc version of external libraries +if not exist "%RootPath%\libs\gcc-version" echo Cannot get gcc version of external libraries.& exit /B 1 +set /P LibsGCCVersion=<"%RootPath%\libs\gcc-version" +if "%LibsGCCVersion%" NEQ "%GCCVersion%" echo Please use correct version of external libraries. (gcc %GCCVersion% ^<^> libs %LibsGCCVersion%).& exit /B 1 + +:: Initialize environment +call "%~dp0env.bat" +if errorlevel 1 goto error_env + +:: Build defines for script +set NSIS_PARAM= + +set NSIS_PARAM=%NSIS_PARAM% /DRELEASEDIR="%RsBuildPath%" +set NSIS_PARAM=%NSIS_PARAM% /DQTDIR="%QtPath%\.." +set NSIS_PARAM=%NSIS_PARAM% /DMINGWDIR="%MinGWPath%\.." +set NSIS_PARAM=%NSIS_PARAM% /DOUTDIR="%RsPackPath%" +set NSIS_PARAM=%NSIS_PARAM% /DINSTALLERADD="%RsArchiveAdd%" + +:: Scan version from source +set RsRevision= +set RsBuildAdd= +call "%ToolsPath%\get-rs-version.bat" RS_REVISION_STRING RsRevision +if "%RsRevision%"=="" echo Revision not found.& exit /B 1 +call "%ToolsPath%\get-rs-version.bat" RS_BUILD_NUMBER_ADD RsBuildAdd +if errorlevel 1 exit /B 1 + +set NSIS_PARAM=%NSIS_PARAM% /DREVISION=%RsRevision% /DBUILDADD=%RsBuildAdd% + +set QtMainVersion=%QtVersion:~0,1% + +:: Create installer +"%EnvMakeNSISExe%" %NSIS_PARAM% "%SourcePath%\build_scripts\Windows\installer\retroshare-Qt%QtMainVersion%.nsi" + +exit /B %ERRORLEVEL% + +:error_env +echo Failed to initialize environment. +endlocal +exit /B 1 diff --git a/build_scripts/Windows/build/build.bat b/build_scripts/Windows/build/build.bat new file mode 100644 index 000000000..4893a51d7 --- /dev/null +++ b/build_scripts/Windows/build/build.bat @@ -0,0 +1,81 @@ +@echo off + +setlocal + +:: Initialize environment +call "%~dp0..\env.bat" +if errorlevel 1 goto error_env +call "%EnvPath%\env.bat" +if errorlevel 1 goto error_env + +:: Get gcc versions +call "%ToolsPath%\get-gcc-version.bat" GCCVersion +if "%GCCVersion%"=="" echo Cannot get gcc version.& exit /B 1 + +:: Check external libraries +if not exist "%RootPath%\libs" echo Please build external libraries first.& exit /B 1 + +:: Check gcc version of external libraries +if not exist "%RootPath%\libs\gcc-version" echo Cannot get gcc version of external libraries.& exit /B 1 +set /P LibsGCCVersion=<"%RootPath%\libs\gcc-version" +if "%LibsGCCVersion%" NEQ "%GCCVersion%" echo Please use correct version of external libraries. (gcc %GCCVersion% ^<^> libs %LibsGCCVersion%).& exit /B 1 + +:: Initialize environment +call "%~dp0env.bat" +if errorlevel 1 goto error_env + +:: Check git executable +set GitPath= +call "%ToolsPath%\find-in-path.bat" GitPath git.exe +if "%GitPath%" NEQ "" goto found_git +choice /M "Git not found in PATH. Version information cannot be calculated. Do you want to proceed?" +if %errorlevel%==2 exit /B 1 +:found_git + +echo. +echo === Version +echo. + +title Build - %SourceName%-%RsBuildConfig% [Version] + +pushd "%SourcePath%\retroshare-gui\src\gui\images" +:: Touch resource file +copy /b retroshare_win.rc +,, +popd + +if not exist "%RsBuildPath%" mkdir "%RsBuildPath%" +pushd "%RsBuildPath%" + +echo. +echo === qmake +echo. + +title Build - %SourceName%-%RsBuildConfig% [qmake] + +qmake "%SourcePath%\RetroShare.pro" -r "CONFIG+=%RsBuildConfig% version_detail_bash_script" +if errorlevel 1 goto error + +echo. +echo === make +echo. + +title Build - %SourceName%-%RsBuildConfig% [make] + +if exist "%EnvJomExe%" ( + "%EnvJomExe%" +) else ( + mingw32-make +) + +:error +popd + +title %COMSPEC% + +if errorlevel 1 echo.& echo Build failed& echo. +exit /B %ERRORLEVEL% + +:error_env +echo Failed to initialize environment. +endlocal +exit /B 1 diff --git a/build_scripts/Windows/build/clean.bat b/build_scripts/Windows/build/clean.bat new file mode 100644 index 000000000..0797e7681 --- /dev/null +++ b/build_scripts/Windows/build/clean.bat @@ -0,0 +1,21 @@ +@echo off + +setlocal + +:: Initialize environment +call "%~dp0..\env.bat" +if errorlevel 1 goto error_env +call "%EnvPath%\env.bat" +if errorlevel 1 goto error_env +call "%~dp0env.bat" +if errorlevel 1 goto error_env + +if not exist "%RsBuildPath%" exit /B 0 +call "%ToolsPath%\remove-dir.bat" "%RsBuildPath%" + +exit /B %ERRORLEVEL% + +:error_env +echo Failed to initialize environment. +endlocal +exit /B 1 diff --git a/build_scripts/Windows/build/env.bat b/build_scripts/Windows/build/env.bat new file mode 100644 index 000000000..c4758f0d4 --- /dev/null +++ b/build_scripts/Windows/build/env.bat @@ -0,0 +1,33 @@ +set CurPath=%~dp0 +set BuildPath=%EnvRootPath%\builds +set DeployPath=%EnvRootPath%\deploy + +if not exist "%BuildPath%" mkdir "%BuildPath%" +if not exist "%DeployPath%" mkdir "%DeployPath%" + +:: Check Qt environment +set QtPath= +call "%ToolsPath%\find-in-path.bat" QtPath qmake.exe +if "%QtPath%"=="" echo Please run command in the Qt Command Prompt.& exit /B 1 + +:: Check MinGW environment +set MinGWPath= +call "%ToolsPath%\find-in-path.bat" MinGWPath gcc.exe +if "%MinGWPath%"=="" echo Please run command in the Qt Command Prompt.& exit /B 1 + +:: Get Qt version +call "%ToolsPath%\get-qt-version.bat" QtVersion +if "%QtVersion%"=="" echo Cannot get Qt version.& exit /B 1 + +set RsBuildConfig=release +set RsBuildPath=%BuildPath%\Qt-%QtVersion%-%RsBuildConfig% +set RsDeployPath=%DeployPath%\Qt-%QtVersion%-%RsBuildConfig% +set RsPackPath=%DeployPath% +set RsArchiveAdd= + +if not exist "%~dp0env-mod.bat" goto no_mod +call "%~dp0env-mod.bat" +if errorlevel 1 exit /B %ERRORLEVEL% +:no_mod + +exit /B 0 \ No newline at end of file diff --git a/build_scripts/Windows/build/git-log.bat b/build_scripts/Windows/build/git-log.bat new file mode 100644 index 000000000..8a36c7537 --- /dev/null +++ b/build_scripts/Windows/build/git-log.bat @@ -0,0 +1,117 @@ +:: Usage: +:: call git-log.bat [no-ask] + +@echo off + +setlocal + +set NoAsk= +if "%~1"=="no-ask" set NoAsk=1 + +:: Initialize environment +call "%~dp0..\env.bat" +if errorlevel 1 goto error_env +call "%EnvPath%\env.bat" +if errorlevel 1 goto error_env +call "%~dp0env.bat" +if errorlevel 1 goto error_env + +:: Check git executable +set GitPath= +call "%ToolsPath%\find-in-path.bat" GitPath git.exe +if "%GitPath%"=="" echo Git executable not found in PATH.& exit /B 1 + +:: Get compiled revision +set GetRsVersion=%SourcePath%\build_scripts\Windows\tools\get-rs-version.bat +if not exist "%GetRsVersion%" ( + echo File not found + echo %GetRsVersion% + exit /B 1 +) + +call "%GetRsVersion%" RS_REVISION_STRING RsRevision +if "%RsRevision%"=="" echo Revision not found.& exit /B 1 + +:: Get compiled version +call "%GetRsVersion%" RS_REVISION_STRING RsRevision +if "%RsRevision%"=="" echo Revision not found.& exit /B 1 + +call "%GetRsVersion%" RS_MAJOR_VERSION RsMajorVersion +if "%RsMajorVersion%"=="" echo Major version not found.& exit /B 1 + +call "%GetRsVersion%" RS_MINOR_VERSION RsMinorVersion +if "%RsMinorVersion%"=="" echo Minor version not found.& exit /B 1 + +call "%GetRsVersion%" RS_BUILD_NUMBER RsBuildNumber +if "%RsBuildNumber%"=="" echo Build number not found.& exit /B 1 + +call "%GetRsVersion%" RS_BUILD_NUMBER_ADD RsBuildNumberAdd + +set RsVersion=%RsMajorVersion%.%RsMinorVersion%.%RsBuildNumber%%RsBuildNumberAdd% + +:: Check WMIC is available +wmic.exe alias /? >nul 2>&1 || echo WMIC is not available.&& exit /B 1 + +:: Use WMIC to retrieve date in format YYYYMMDD +set RsDate= +for /f "tokens=2 delims==" %%I in ('wmic os get localdatetime /format:list') do set RsDate=%%I +set RsDate=%RsDate:~0,4%%RsDate:~4,2%%RsDate:~6,2% + +:: Get last revision +set RsLastRefFile=%BuildPath%\Qt-%QtVersion%-%RsBuildConfig%-LastRef.txt +set RsLastRef= +if exist "%RsLastRefFile%" set /P RsLastRef=<"%RsLastRefFile%" + +if "%NoAsk%"=="1" goto no_ask_for_last_revision +if not "%RsLastRef%"=="" echo Last Revision was %RsLastRef% +set /P RsLastRefInput=Last Revision: +if "%RsLastRefInput%" NEQ "" set RsLastRef=%RsLastRefInput% +:no_ask_for_last_revision + +:: Get current revision +pushd "%SourcePath%" +call "%ToolsPath%\get-git-ref.bat" RsRef +popd + +if errorlevel 1 exit /B 1 +if "%RsRef%"=="" echo Cannot get git revision.& exit /B 1 + +echo. +echo Creating log from %RsLastRef% +echo to %RsRef% + +if "%NoAsk%"=="1" goto no_confirm +choice /M "Do you want to proceed?" +if %errorlevel%==2 exit /B 1 +:no_confirm + +if "%RsBuildConfig%" NEQ "release" ( + set RsGitLog=%DeployPath%\RetroShare-%RsVersion%-Windows-Portable-%RsDate%-%RsRevision%-Qt-%QtVersion%%RsArchiveAdd%-%RsBuildConfig%.txt +) else ( + set RsGitLog=%DeployPath%\RetroShare-%RsVersion%-Windows-Portable-%RsDate%-%RsRevision%-Qt-%QtVersion%%RsArchiveAdd%.txt +) + +title %SourceName%-%RsBuildConfig% [git log] + +pushd "%SourcePath%" +if "%RsLastRef%"=="" ( + git log %RsRef% >"%RsGitLog%" +) else ( + if "%RsLastRef%"=="%RsRef%" ( + git log %RsRef% --max-count=1 >"%RsGitLog%" + ) else ( + git log %RsLastRef%..%RsRef% >"%RsGitLog%" + ) +) +popd + +title %COMSPEC% + +echo %RsRef%>"%RsLastRefFile%" + +exit /B %ERRORLEVEL% + +:error_env +echo Failed to initialize environment. +endlocal +exit /B 1 diff --git a/build_scripts/Windows/build/pack.bat b/build_scripts/Windows/build/pack.bat new file mode 100644 index 000000000..a8e7fdaff --- /dev/null +++ b/build_scripts/Windows/build/pack.bat @@ -0,0 +1,210 @@ +@echo off + +setlocal + +set Quite=^>nul + +:: Initialize environment +call "%~dp0..\env.bat" +if errorlevel 1 goto error_env +call "%EnvPath%\env.bat" +if errorlevel 1 goto error_env + +:: Get gcc versions +call "%ToolsPath%\get-gcc-version.bat" GCCVersion +if "%GCCVersion%"=="" echo Cannot get gcc version.& exit /B 1 + +:: Check external libraries +if not exist "%RootPath%\libs" echo Please build external libraries first.& exit /B 1 + +:: Check gcc version of external libraries +if not exist "%RootPath%\libs\gcc-version" echo Cannot get gcc version of external libraries.& exit /B 1 +set /P LibsGCCVersion=<"%RootPath%\libs\gcc-version" +if "%LibsGCCVersion%" NEQ "%GCCVersion%" echo Please use correct version of external libraries. (gcc %GCCVersion% ^<^> libs %LibsGCCVersion%).& exit /B 1 + +:: Initialize environment +call "%~dp0env.bat" +if errorlevel 1 goto error_env + +:: Remove deploy path +if exist "%RsDeployPath%" rmdir /S /Q "%RsDeployPath%" + +:: Check compilation +if not exist "%RsBuildPath%\Makefile" echo Project is not compiled.& goto error + +:: Get compiled revision +set GetRsVersion=%SourcePath%\build_scripts\Windows\tools\get-rs-version.bat +if not exist "%GetRsVersion%" ( + echo File not found + echo %GetRsVersion% + goto error +) + +call "%GetRsVersion%" RS_REVISION_STRING RsRevision +if "%RsRevision%"=="" echo Revision not found.& goto error + +:: Get compiled version +call "%GetRsVersion%" RS_MAJOR_VERSION RsMajorVersion +if "%RsMajorVersion%"=="" echo Major version not found.& goto error + +call "%GetRsVersion%" RS_MINOR_VERSION RsMinorVersion +if "%RsMinorVersion%"=="" echo Minor version not found.& goto error + +call "%GetRsVersion%" RS_BUILD_NUMBER RsBuildNumber +if "%RsBuildNumber%"=="" echo Build number not found.& goto error + +call "%GetRsVersion%" RS_BUILD_NUMBER_ADD RsBuildNumberAdd + +set RsVersion=%RsMajorVersion%.%RsMinorVersion%.%RsBuildNumber%%RsBuildNumberAdd% + +:: Check WMIC is available +wmic.exe alias /? >nul 2>&1 || echo WMIC is not available.&& goto error + +:: Use WMIC to retrieve date in format YYYYMMDD +set RsDate= +for /f "tokens=2 delims==" %%I in ('wmic os get localdatetime /format:list') do set RsDate=%%I +set RsDate=%RsDate:~0,4%%RsDate:~4,2%%RsDate:~6,2% + +set QtMainVersion=%QtVersion:~0,1% + +rem Qt 4 = QtSvg4.dll +rem Qt 5 = Qt5Svg.dll +set QtMainVersion1= +set QtMainVersion2= +if "%QtMainVersion%"=="4" set QtMainVersion2=4 +if "%QtMainVersion%"=="5" set QtMainVersion1=5 + +if "%RsBuildConfig%" NEQ "release" ( + set Archive=%RsPackPath%\RetroShare-%RsVersion%-Windows-Portable-%RsDate%-%RsRevision%-Qt-%QtVersion%%RsArchiveAdd%-%RsBuildConfig%.7z +) else ( + set Archive=%RsPackPath%\RetroShare-%RsVersion%-Windows-Portable-%RsDate%-%RsRevision%-Qt-%QtVersion%%RsArchiveAdd%.7z +) + +if exist "%Archive%" del /Q "%Archive%" + +:: Create deploy path +mkdir "%RsDeployPath%" + +title Pack - %SourceName%-%RsBuildConfig% [copy files] + +set ExtensionsFile=%SourcePath%\libretroshare\src\rsserver\rsinit.cc +set Extensions= +for /f %%e in ('type "%ExtensionsFile%" ^| "%EnvSedExe%" -n "s/^.*\/\(extensions[^/]*\)\/.*$/\1/p" ^| "%EnvSedExe%" -n "1,1p"') do set Extensions=%%e +if "%Extensions%"=="" echo Folder for extensions not found in %ExtensionsFile%& goto error + +:: Copy files +mkdir "%RsDeployPath%\Data\%Extensions%" +mkdir "%RsDeployPath%\imageformats" +mkdir "%RsDeployPath%\qss" +mkdir "%RsDeployPath%\stylesheets" +mkdir "%RsDeployPath%\sounds" +mkdir "%RsDeployPath%\translations" + +copy nul "%RsDeployPath%\portable" %Quite% + +echo copy binaries +copy "%RsBuildPath%\retroshare-gui\src\%RsBuildConfig%\RetroShare*.exe" "%RsDeployPath%" %Quite% +copy "%RsBuildPath%\retroshare-nogui\src\%RsBuildConfig%\retroshare*-nogui.exe" "%RsDeployPath%" %Quite% + +echo copy extensions +for /D %%D in ("%RsBuildPath%\plugins\*") do ( + call :copy_extension "%%D" "%RsDeployPath%\Data\%Extensions%" + call :copy_dependencies "%RsDeployPath%\Data\%Extensions%\%%~nxD.dll" "%RsDeployPath%" +) + +echo copy external binaries +copy "%RootPath%\libs\bin\*.dll" "%RsDeployPath%" %Quite% + +echo copy dependencies +call :copy_dependencies "%RsDeployPath%\RetroShare06.exe" "%RsDeployPath%" + +echo copy Qt DLL's +copy "%QtPath%\Qt%QtMainVersion1%Svg%QtMainVersion2%.dll" "%RsDeployPath%" %Quite% + +if "%QtMainVersion%"=="5" ( + mkdir "%RsDeployPath%\platforms" + copy "%QtPath%\..\plugins\platforms\qwindows.dll" "%RsDeployPath%\platforms" %Quite% + mkdir "%RsDeployPath%\audio" + copy "%QtPath%\..\plugins\audio\qtaudio_windows.dll" "%RsDeployPath%\audio" %Quite% +) + +copy "%QtPath%\..\plugins\imageformats\*.dll" "%RsDeployPath%\imageformats" %Quite% +del /Q "%RsDeployPath%\imageformats\*d?.dll" %Quite% + +echo copy qss +xcopy /S "%SourcePath%\retroshare-gui\src\qss" "%RsDeployPath%\qss" %Quite% + +echo copy stylesheets +xcopy /S "%SourcePath%\retroshare-gui\src\gui\qss\chat" "%RsDeployPath%\stylesheets" %Quite% +rmdir /S /Q "%RsDeployPath%\stylesheets\compact" %Quite% +rmdir /S /Q "%RsDeployPath%\stylesheets\standard" %Quite% +rmdir /S /Q "%RsDeployPath%\stylesheets\__MACOSX__Bubble" %Quite% + +echo copy sounds +xcopy /S "%SourcePath%\retroshare-gui\src\sounds" "%RsDeployPath%\sounds" %Quite% + +echo copy translation +copy "%SourcePath%\retroshare-gui\src\translations\qt_tr.qm" "%RsDeployPath%\translations" %Quite% +copy "%QtPath%\..\translations\qt_*.qm" "%RsDeployPath%\translations" %Quite% +if "%QtMainVersion%"=="5" ( + copy "%QtPath%\..\translations\qtbase_*.qm" "%RsDeployPath%\translations" %Quite% + copy "%QtPath%\..\translations\qtscript_*.qm" "%RsDeployPath%\translations" %Quite% + copy "%QtPath%\..\translations\qtquick1_*.qm" "%RsDeployPath%\translations" %Quite% + copy "%QtPath%\..\translations\qtmultimedia_*.qm" "%RsDeployPath%\translations" %Quite% + copy "%QtPath%\..\translations\qtxmlpatterns_*.qm" "%RsDeployPath%\translations" %Quite% +) + +echo copy bdboot.txt +copy "%SourcePath%\libbitdht\src\bitdht\bdboot.txt" "%RsDeployPath%" %Quite% + +echo copy changelog.txt +copy "%SourcePath%\retroshare-gui\src\changelog.txt" "%RsDeployPath%" %Quite% + +if exist "%SourcePath%\libresapi\src\webui" ( + echo copy webui + mkdir "%RsDeployPath%\webui" + xcopy /S "%SourcePath%\libresapi\src\webui" "%RsDeployPath%\webui" %Quite% +) + +rem pack files +title Pack - %SourceName%-%RsBuildConfig% [pack files] + +"%SevenZipExe%" a -mx=9 -t7z "%Archive%" "%RsDeployPath%\*" + +title %COMSPEC% + +call :cleanup + +endlocal +exit /B 0 + +:error +call :Cleanup +endlocal +exit /B 1 + +:cleanup +goto :EOF + +:error_env +echo Failed to initialize environment. +endlocal +exit /B 1 + +:copy_extension +if exist "%~1\%RsBuildConfig%\%~n1.dll" ( + copy "%~1\%RsBuildConfig%\%~n1.dll" %2 %Quite% +) +goto :EOF + +:copy_dependencies +for /F "usebackq" %%A in (`%ToolsPath%\depends.bat list %1`) do ( + if exist "%QtPath%\%%A" ( + copy "%QtPath%\%%A" %2 %Quite% + ) else ( + if exist "%MinGWPath%\%%A" ( + copy "%MinGWPath%\%%A" %2 %Quite% + ) + ) +) +goto :EOF diff --git a/build_scripts/Windows/build_libs/.gitignore b/build_scripts/Windows/build_libs/.gitignore deleted file mode 100644 index 9f502e129..000000000 --- a/build_scripts/Windows/build_libs/.gitignore +++ /dev/null @@ -1,6 +0,0 @@ -/download -/msys -/libs -/tools/7z.dll -/tools/7z.exe -/tools/curl.exe \ No newline at end of file diff --git a/build_scripts/Windows/build_libs/1-prepare.bat b/build_scripts/Windows/build_libs/1-prepare.bat deleted file mode 100644 index 4c93d54ef..000000000 --- a/build_scripts/Windows/build_libs/1-prepare.bat +++ /dev/null @@ -1,43 +0,0 @@ -@setlocal - -@echo off - -:: Initialize environment -call "%~dp0_env.bat" - -set SevenZipUrl=http://7-zip.org/a/7z1602.msi -set SevenZipInstall=7z1602.msi -set CurlUrl=https://bintray.com/artifact/download/vszakats/generic/curl-7.50.1-win32-mingw.7z -set CurlInstall=curl-7.50.1-win32-mingw.7z - -if not exist "%DownloadPath%" mkdir "%DownloadPath%" - -call :remove_dir "%TempPath%" - -echo Download installation files -if not exist "%DownloadPath%\%SevenZipInstall%" call "%ToolsPath%\winhttpjs.bat" %SevenZipUrl% -saveTo "%DownloadPath%\%SevenZipInstall%" -if not exist "%DownloadPath%\%SevenZipInstall%" echo Cannot download 7z& goto :exit - -if not exist "%DownloadPath%\%CurlInstall%" call "%ToolsPath%\winhttpjs.bat" %CurlUrl% -saveTo "%DownloadPath%\%CurlInstall%" -if not exist "%DownloadPath%\%CurlInstall%" echo Cannot download Curl& goto :exit - -echo Unpack 7z -msiexec /a "%DownloadPath%\%SevenZipInstall%" /qb TARGETDIR="%TempPath%" -copy "%TempPath%\Files\7-Zip\7z.dll" "%ToolsPath%" -copy "%TempPath%\Files\7-Zip\7z.exe" "%ToolsPath%" -call :remove_dir "%TempPath%" - -echo Unpack Curl -"%SevenZipExe%" x -o"%TempPath%" "%DownloadPath%\%CurlInstall%" -copy "%TempPath%\curl-7.50.1-win32-mingw\bin\curl.exe" "%ToolsPath%" -call :remove_dir "%TempPath%" - -:exit -endlocal -exit /B 0 - -:remove_dir -if not exist %1 goto :EOF -del /s /f /q %1 >nul -rmdir /s /q %1 -goto :EOF diff --git a/build_scripts/Windows/build_libs/2-install-msys.bat b/build_scripts/Windows/build_libs/2-install-msys.bat deleted file mode 100644 index 7e17a2dc0..000000000 --- a/build_scripts/Windows/build_libs/2-install-msys.bat +++ /dev/null @@ -1,70 +0,0 @@ -@setlocal - -@echo off - -:: Initialize environment -call "%~dp0_env.bat" - -set MSYSInstall=mingw-get-0.6.2-mingw32-beta-20131004-1-bin.zip -set CMakeInstall=cmake-3.1.0-win32-x86.zip -set CMakeUnpackPath=%MSYSPath%\msys\1.0 - -if not exist "%DownloadPath%" mkdir "%DownloadPath%" - -echo Check existing installation -if not exist "%MSYSPath%\bin\mingw-get.exe" goto proceed -choice /M "Found existing MSYS version. Do you want to proceed?" -if %ERRORLEVEL%==2 goto exit - -:proceed -echo Remove previous MSYS version -call :remove_dir "%MSYSPath%" - -echo Download installation files -if not exist "%DownloadPath%\%MSYSInstall%" "%CurlExe%" -L -k http://sourceforge.net/projects/mingw/files/Installer/mingw-get/mingw-get-0.6.2-beta-20131004-1/%MSYSInstall%/download -o "%DownloadPath%\%MSYSInstall%" -if not exist "%DownloadPath%%\MSYSInstall%" echo Cannot download MSYS& goto :exit - -if not exist "%DownloadPath%\%CMakeInstall%" "%CurlExe%" -L -k http://www.cmake.org/files/v3.1/cmake-3.1.0-win32-x86.zip -o "%DownloadPath%\%CMakeInstall%" -if not exist "%DownloadPath%\%CMakeInstall%" echo Cannot download CMake& goto :exit - -echo Unpack MSYS -"%SevenZipExe%" x -o"%MSYSPath%" "%DownloadPath%\%MSYSInstall%" - -echo Install MSYS -if not exist "%MSYSPath%\var\lib\mingw-get\data\profile.xml" copy "%MSYSPath%\var\lib\mingw-get\data\defaults.xml" "%MSYSPath%\var\lib\mingw-get\data\profile.xml" -pushd "%MSYSPath%\bin" -mingw-get.exe install mingw32-mingw-get -mingw-get.exe install msys-coreutils -mingw-get.exe install msys-base -mingw-get.exe install msys-autoconf -mingw-get.exe install msys-automake -mingw-get.exe install msys-autogen -mingw-get.exe install msys-mktemp -mingw-get.exe install msys-wget -popd - -echo Unpack CMake -"%SevenZipExe%" x -o"%CMakeUnpackPath%" "%DownloadPath%\%CMakeInstall%" - -echo Install CMake -set CMakeVersion= -for /D %%F in (%CMakeUnpackPath%\cmake*) do set CMakeVersion=%%~nxF -if "%CMakeVersion%"=="" echo CMake version not found.& goto :exit -echo Found CMake version %CMakeVersion% - -set FoundProfile= -for /f "tokens=3" %%F in ('find /c /i "%CMakeVersion%" "%MSYSPath%\msys\1.0\etc\profile"') do set FoundProfile=%%F - -if "%FoundProfile%"=="0" ( - echo export PATH="${PATH}:/%CMakeVersion%/bin">>"%MSYSPath%\msys\1.0\etc\profile" -) - -:exit -endlocal -exit /B 0 - -:remove_dir -if not exist %1 goto :EOF -del /s /f /q %1 >nul -rmdir /s /q %1 -goto :EOF diff --git a/build_scripts/Windows/build_libs/3-build-libs.bat b/build_scripts/Windows/build_libs/3-build-libs.bat deleted file mode 100644 index 3b7a3c92c..000000000 --- a/build_scripts/Windows/build_libs/3-build-libs.bat +++ /dev/null @@ -1,29 +0,0 @@ -@setlocal - -@echo off - -:: Initialize environment -call "%~dp0_env.bat" - -set MSYSSH=%MSYSPath%\msys\1.0\bin\sh.exe -set MSYSCurPath=/%CurPath:~0,1%/%CurPath:~3% -set MSYSCurPath=%MSYSCurPath:\=/% - -if not exist "%MSYSSH%" echo Please install MSYS first.&& exit /B 1 - -set GCCPath= -call :FIND_IN_PATH g++.exe GCCPath -if "%GCCPath%"=="" echo Please run %~nx0 in the Qt Command Prompt or add the path to MinGW bin folder to PATH variable.&& exit /B 1 - -"%MSYSSH%" --login -i -c "cd "%MSYSCurPath%" && make -f makefile %*" - -exit /B %ERRORLEVEL% - -:FIND_IN_PATH -SET PathTemp="%Path:;=";"%" -FOR %%P IN (%PathTemp%) DO ( - IF EXIST "%%~P.\%~1" ( - set %2=%%~P - goto :EOF - ) -) diff --git a/build_scripts/Windows/build_libs/Makefile b/build_scripts/Windows/build_libs/Makefile index c53ada54f..5f0a2351f 100755 --- a/build_scripts/Windows/build_libs/Makefile +++ b/build_scripts/Windows/build_libs/Makefile @@ -13,214 +13,331 @@ SQLCIPHER_VERSION=2.2.1 LIBMICROHTTPD_VERSION=0.9.46 FFMPEG_VERSION=3.1.2 +MAKEFILE_PATH=$(dir $(MAKEFILE_LIST)) +LIBS_PATH?=$(MAKEFILE_PATH)../../../../libs + +DOWNLOAD_PATH?=download +COPY_ANSWER?= + all: dirs zlib bzip2 miniupnpc openssl speex speexdsp opencv libxml2 libxslt curl sqlcipher libmicrohttpd ffmpeg copylibs download: \ - download/zlib-$(ZLIB_VERSION).tar.gz \ - download/bzip2-$(BZIP2_VERSION).tar.gz \ - download/miniupnpc-$(MINIUPNPC_VERSION).tar.gz \ - download/openssl-$(OPENSSL_VERSION).tar.gz \ - download/speex-$(SPEEX_VERSION).tar.gz \ - download/speexdsp-$(SPEEXDSP_VERSION).tar.gz \ - download/opencv-$(OPENCV_VERSION).tar.gz \ - download/libxml2-$(LIBXML2_VERSION).tar.gz \ - download/libxslt-$(LIBXSLT_VERSION).tar.gz \ - download/curl-$(CURL_VERSION).tar.gz \ - download/tcl$(TCL_VERSION)-src.tar.gz \ - download/sqlcipher-$(SQLCIPHER_VERSION).tar.gz \ - download/libmicrohttpd-$(LIBMICROHTTPD_VERSION).tar.gz \ - download/ffmpeg-$(FFMPEG_VERSION).tar.gz + $(DOWNLOAD_PATH)/zlib-$(ZLIB_VERSION).tar.gz \ + $(DOWNLOAD_PATH)/bzip2-$(BZIP2_VERSION).tar.gz \ + $(DOWNLOAD_PATH)/miniupnpc-$(MINIUPNPC_VERSION).tar.gz \ + $(DOWNLOAD_PATH)/openssl-$(OPENSSL_VERSION).tar.gz \ + $(DOWNLOAD_PATH)/speex-$(SPEEX_VERSION).tar.gz \ + $(DOWNLOAD_PATH)/speexdsp-$(SPEEXDSP_VERSION).tar.gz \ + $(DOWNLOAD_PATH)/opencv-$(OPENCV_VERSION).tar.gz \ + $(DOWNLOAD_PATH)/libxml2-$(LIBXML2_VERSION).tar.gz \ + $(DOWNLOAD_PATH)/libxslt-$(LIBXSLT_VERSION).tar.gz \ + $(DOWNLOAD_PATH)/curl-$(CURL_VERSION).tar.gz \ + $(DOWNLOAD_PATH)/tcl$(TCL_VERSION)-src.tar.gz \ + $(DOWNLOAD_PATH)/sqlcipher-$(SQLCIPHER_VERSION).tar.gz \ + $(DOWNLOAD_PATH)/libmicrohttpd-$(LIBMICROHTTPD_VERSION).tar.gz \ + $(DOWNLOAD_PATH)/ffmpeg-$(FFMPEG_VERSION).tar.gz + +clean: + rm -r -f libs dirs: - mkdir -p download - mkdir -p libs/include - mkdir -p libs/lib - mkdir -p libs/bin + mkdir -p $(DOWNLOAD_PATH) + mkdir -p libs + gcc --version | head --lines 1 | tr ' ' '\n' | tail -1 >libs/gcc-version -download/zlib-$(ZLIB_VERSION).tar.gz: - wget --no-check-certificate http://sourceforge.net/projects/libpng/files/zlib/$(ZLIB_VERSION)/zlib-$(ZLIB_VERSION).tar.gz/download -O download/zlib-$(ZLIB_VERSION).tar.gz +$(DOWNLOAD_PATH)/zlib-$(ZLIB_VERSION).tar.gz: + wget --no-check-certificate http://sourceforge.net/projects/libpng/files/zlib/$(ZLIB_VERSION)/zlib-$(ZLIB_VERSION).tar.gz/download -O $(DOWNLOAD_PATH)/zlib-$(ZLIB_VERSION).tar.gz -zlib: download/zlib-$(ZLIB_VERSION).tar.gz - tar xvf download/zlib-$(ZLIB_VERSION).tar.gz +zlib: libs/zlib-$(ZLIB_VERSION) + +libs/zlib-$(ZLIB_VERSION): $(DOWNLOAD_PATH)/zlib-$(ZLIB_VERSION).tar.gz + # prepare + rm -r -f libs/zlib-* + tar xvf $(DOWNLOAD_PATH)/zlib-$(ZLIB_VERSION).tar.gz + # build cd zlib-$(ZLIB_VERSION) && ./configure #cd zlib-$(ZLIB_VERSION) && make install prefix="`pwd`/../libs" cd zlib-$(ZLIB_VERSION) && make - cp zlib-$(ZLIB_VERSION)/zlib.h libs/include/ - cp zlib-$(ZLIB_VERSION)/zconf.h libs/include/ - cp zlib-$(ZLIB_VERSION)/libz.a libs/lib/ + # copy files + mkdir -p libs/zlib-$(ZLIB_VERSION).tmp/include + cp zlib-$(ZLIB_VERSION)/zlib.h libs/zlib-$(ZLIB_VERSION).tmp/include/ + cp zlib-$(ZLIB_VERSION)/zconf.h libs/zlib-$(ZLIB_VERSION).tmp/include/ + mkdir -p libs/zlib-$(ZLIB_VERSION).tmp/lib + cp zlib-$(ZLIB_VERSION)/libz.a libs/zlib-$(ZLIB_VERSION).tmp/lib/ rm -r -f zlib-$(ZLIB_VERSION) - touch zlib + mv libs/zlib-$(ZLIB_VERSION).tmp libs/zlib-$(ZLIB_VERSION) -download/bzip2-$(BZIP2_VERSION).tar.gz: - wget http://bzip.org/$(BZIP2_VERSION)/bzip2-$(BZIP2_VERSION).tar.gz -O download/bzip2-$(BZIP2_VERSION).tar.gz +bzip2: libs/bzip2-$(BZIP2_VERSION) -bzip2: download/bzip2-$(BZIP2_VERSION).tar.gz - tar xvf download/bzip2-$(BZIP2_VERSION).tar.gz +$(DOWNLOAD_PATH)/bzip2-$(BZIP2_VERSION).tar.gz: + wget http://bzip.org/$(BZIP2_VERSION)/bzip2-$(BZIP2_VERSION).tar.gz -O $(DOWNLOAD_PATH)/bzip2-$(BZIP2_VERSION).tar.gz + +libs/bzip2-$(BZIP2_VERSION): $(DOWNLOAD_PATH)/bzip2-$(BZIP2_VERSION).tar.gz + # prepare + rm -r -f libs/bzip2-* + tar xvf $(DOWNLOAD_PATH)/bzip2-$(BZIP2_VERSION).tar.gz + # build #cd bzip2-$(BZIP2_VERSION) && make install PREFIX="`pwd`/../libs" cd bzip2-$(BZIP2_VERSION) && make - cp bzip2-$(BZIP2_VERSION)/bzlib.h libs/include/ - cp bzip2-$(BZIP2_VERSION)/libbz2.a libs/lib/ + # copy files + mkdir -p libs/bzip2-$(BZIP2_VERSION).tmp/include + cp bzip2-$(BZIP2_VERSION)/bzlib.h libs/bzip2-$(BZIP2_VERSION).tmp/include/ + mkdir -p libs/bzip2-$(BZIP2_VERSION).tmp/lib + cp bzip2-$(BZIP2_VERSION)/libbz2.a libs/bzip2-$(BZIP2_VERSION).tmp/lib/ rm -r -f bzip2-$(BZIP2_VERSION) - touch bzip2 + mv libs/bzip2-$(BZIP2_VERSION).tmp libs/bzip2-$(BZIP2_VERSION) -download/miniupnpc-$(MINIUPNPC_VERSION).tar.gz: - wget http://miniupnp.free.fr/files/download.php?file=miniupnpc-$(MINIUPNPC_VERSION).tar.gz -O download/miniupnpc-$(MINIUPNPC_VERSION).tar.gz +miniupnpc: libs/miniupnpc-$(MINIUPNPC_VERSION) -miniupnpc: download/miniupnpc-$(MINIUPNPC_VERSION).tar.gz - tar xvf download/miniupnpc-$(MINIUPNPC_VERSION).tar.gz +$(DOWNLOAD_PATH)/miniupnpc-$(MINIUPNPC_VERSION).tar.gz: + wget http://miniupnp.free.fr/files/download.php?file=miniupnpc-$(MINIUPNPC_VERSION).tar.gz -O $(DOWNLOAD_PATH)/miniupnpc-$(MINIUPNPC_VERSION).tar.gz + +libs/miniupnpc-$(MINIUPNPC_VERSION): $(DOWNLOAD_PATH)/miniupnpc-$(MINIUPNPC_VERSION).tar.gz + # prepare + rm -r -f libs/miniupnpc-* + tar xvf $(DOWNLOAD_PATH)/miniupnpc-$(MINIUPNPC_VERSION).tar.gz + # build cd miniupnpc-$(MINIUPNPC_VERSION) && CC=gcc && export CC && make -f Makefile.mingw init libminiupnpc.a miniupnpc.dll - mkdir -p libs/include/miniupnpc && cp miniupnpc-$(MINIUPNPC_VERSION)/*.h libs/include/miniupnpc/ - cp miniupnpc-$(MINIUPNPC_VERSION)/miniupnpc.lib libs/lib/ - cp miniupnpc-$(MINIUPNPC_VERSION)/miniupnpc.dll libs/bin/ + # copy files + mkdir -p libs/miniupnpc-$(MINIUPNPC_VERSION).tmp/include/miniupnpc + cp miniupnpc-$(MINIUPNPC_VERSION)/*.h libs/miniupnpc-$(MINIUPNPC_VERSION).tmp/include/miniupnpc/ + mkdir -p libs/miniupnpc-$(MINIUPNPC_VERSION).tmp/lib + cp miniupnpc-$(MINIUPNPC_VERSION)/miniupnpc.lib libs/miniupnpc-$(MINIUPNPC_VERSION).tmp/lib/ + mkdir -p libs/miniupnpc-$(MINIUPNPC_VERSION).tmp/bin + cp miniupnpc-$(MINIUPNPC_VERSION)/miniupnpc.dll libs/miniupnpc-$(MINIUPNPC_VERSION).tmp/bin/ rm -r -f miniupnpc-$(MINIUPNPC_VERSION) - touch miniupnpc + mv libs/miniupnpc-$(MINIUPNPC_VERSION).tmp libs/miniupnpc-$(MINIUPNPC_VERSION) -download/openssl-$(OPENSSL_VERSION).tar.gz: - wget --no-check-certificate https://www.openssl.org/source/openssl-$(OPENSSL_VERSION).tar.gz -O download/openssl-$(OPENSSL_VERSION).tar.gz +openssl: libs/openssl-$(OPENSSL_VERSION) -openssl: download/openssl-$(OPENSSL_VERSION).tar.gz - tar xvf download/openssl-$(OPENSSL_VERSION).tar.gz +$(DOWNLOAD_PATH)/openssl-$(OPENSSL_VERSION).tar.gz: + wget --no-check-certificate https://www.openssl.org/source/openssl-$(OPENSSL_VERSION).tar.gz -O $(DOWNLOAD_PATH)/openssl-$(OPENSSL_VERSION).tar.gz + +libs/openssl-$(OPENSSL_VERSION): $(DOWNLOAD_PATH)/openssl-$(OPENSSL_VERSION).tar.gz + # prepare + rm -r -f libs/openssl-* + tar xvf $(DOWNLOAD_PATH)/openssl-$(OPENSSL_VERSION).tar.gz + # build #cd openssl-$(OPENSSL_VERSION) && ./config --prefix="`pwd`/../libs" #cd openssl-$(OPENSSL_VERSION) && make install cd openssl-$(OPENSSL_VERSION) && ./config shared cd openssl-$(OPENSSL_VERSION) && make - mkdir -p libs/include/openssl && cp openssl-$(OPENSSL_VERSION)/include/openssl/*.h libs/include/openssl/ - cp openssl-$(OPENSSL_VERSION)/libeay32.dll libs/bin/ - cp openssl-$(OPENSSL_VERSION)/ssleay32.dll libs/bin/ - cp openssl-$(OPENSSL_VERSION)/libcrypto.dll.a libs/lib/ - cp openssl-$(OPENSSL_VERSION)/libssl.dll.a libs/lib/ + # copy files + mkdir -p libs/openssl-$(OPENSSL_VERSION).tmp/include/openssl + cp openssl-$(OPENSSL_VERSION)/include/openssl/*.h libs/openssl-$(OPENSSL_VERSION).tmp/include/openssl/ + mkdir -p libs/openssl-$(OPENSSL_VERSION).tmp/bin + cp openssl-$(OPENSSL_VERSION)/libeay32.dll libs/openssl-$(OPENSSL_VERSION).tmp/bin/ + cp openssl-$(OPENSSL_VERSION)/ssleay32.dll libs/openssl-$(OPENSSL_VERSION).tmp/bin/ + mkdir -p libs/openssl-$(OPENSSL_VERSION).tmp/lib + cp openssl-$(OPENSSL_VERSION)/libcrypto.dll.a libs/openssl-$(OPENSSL_VERSION).tmp/lib/ + cp openssl-$(OPENSSL_VERSION)/libssl.dll.a libs/openssl-$(OPENSSL_VERSION).tmp/lib/ rm -r -f openssl-$(OPENSSL_VERSION) - touch openssl + mv libs/openssl-$(OPENSSL_VERSION).tmp libs/openssl-$(OPENSSL_VERSION) -download/speex-$(SPEEX_VERSION).tar.gz: - wget http://downloads.xiph.org/releases/speex/speex-$(SPEEX_VERSION).tar.gz -O download/speex-$(SPEEX_VERSION).tar.gz +speex: libs/speex-$(SPEEX_VERSION) -speex: download/speex-$(SPEEX_VERSION).tar.gz - tar xvf download/speex-$(SPEEX_VERSION).tar.gz +$(DOWNLOAD_PATH)/speex-$(SPEEX_VERSION).tar.gz: + wget http://downloads.xiph.org/releases/speex/speex-$(SPEEX_VERSION).tar.gz -O $(DOWNLOAD_PATH)/speex-$(SPEEX_VERSION).tar.gz + +libs/speex-$(SPEEX_VERSION): $(DOWNLOAD_PATH)/speex-$(SPEEX_VERSION).tar.gz + # prepare + rm -r -f libs/speex-* + tar xvf $(DOWNLOAD_PATH)/speex-$(SPEEX_VERSION).tar.gz + # build cd speex-$(SPEEX_VERSION) && ./configure #cd speex-$(SPEEX_VERSION) && make install exec_prefix="`pwd`/../libs" cd speex-$(SPEEX_VERSION) && make - mkdir -p libs/include/speex && cp speex-$(SPEEX_VERSION)/include/speex/*.h libs/include/speex/ - cp speex-$(SPEEX_VERSION)/libspeex/.libs/libspeex.a libs/lib + # copy files + mkdir -p libs/speex-$(SPEEX_VERSION).tmp/include/speex + cp speex-$(SPEEX_VERSION)/include/speex/*.h libs/speex-$(SPEEX_VERSION).tmp/include/speex/ + mkdir -p libs/speex-$(SPEEX_VERSION).tmp/lib + cp speex-$(SPEEX_VERSION)/libspeex/.libs/libspeex.a libs/speex-$(SPEEX_VERSION).tmp/lib rm -r -f speex-$(SPEEX_VERSION) - touch speex + mv libs/speex-$(SPEEX_VERSION).tmp libs/speex-$(SPEEX_VERSION) -download/speexdsp-$(SPEEXDSP_VERSION).tar.gz: - wget http://downloads.xiph.org/releases/speex/speexdsp-$(SPEEXDSP_VERSION).tar.gz -O download/speexdsp-$(SPEEXDSP_VERSION).tar.gz +speexdsp: libs/speexdsp-$(SPEEXDSP_VERSION) -speexdsp: download/speexdsp-$(SPEEXDSP_VERSION).tar.gz - tar xvf download/speexdsp-$(SPEEXDSP_VERSION).tar.gz +$(DOWNLOAD_PATH)/speexdsp-$(SPEEXDSP_VERSION).tar.gz: + wget http://downloads.xiph.org/releases/speex/speexdsp-$(SPEEXDSP_VERSION).tar.gz -O $(DOWNLOAD_PATH)/speexdsp-$(SPEEXDSP_VERSION).tar.gz + +libs/speexdsp-$(SPEEXDSP_VERSION): $(DOWNLOAD_PATH)/speexdsp-$(SPEEXDSP_VERSION).tar.gz + # prepare + rm -r -f libs/speexdsp-* + tar xvf $(DOWNLOAD_PATH)/speexdsp-$(SPEEXDSP_VERSION).tar.gz + # build cd speexdsp-$(SPEEXDSP_VERSION) && ./configure cd speexdsp-$(SPEEXDSP_VERSION) && make - mkdir -p libs/include/speex && cp speexdsp-$(SPEEXDSP_VERSION)/include/speex/*.h libs/include/speex/ - cp speexdsp-$(SPEEXDSP_VERSION)/libspeexdsp/.libs/libspeexdsp.a libs/lib + # copy files + mkdir -p libs/speexdsp-$(SPEEXDSP_VERSION).tmp/include/speex + cp speexdsp-$(SPEEXDSP_VERSION)/include/speex/*.h libs/speexdsp-$(SPEEXDSP_VERSION).tmp/include/speex/ + mkdir -p libs/speexdsp-$(SPEEXDSP_VERSION).tmp/lib + cp speexdsp-$(SPEEXDSP_VERSION)/libspeexdsp/.libs/libspeexdsp.a libs/speexdsp-$(SPEEXDSP_VERSION).tmp/lib rm -r -f speexdsp-$(SPEEXDSP_VERSION) - touch speexdsp + mv libs/speexdsp-$(SPEEXDSP_VERSION).tmp libs/speexdsp-$(SPEEXDSP_VERSION) -download/opencv-$(OPENCV_VERSION).tar.gz: - wget --no-check-certificate https://github.com/Itseez/opencv/archive/$(OPENCV_VERSION).tar.gz -O download/opencv-$(OPENCV_VERSION).tar.gz +opencv: libs/opencv-$(OPENCV_VERSION) -opencv: download/opencv-$(OPENCV_VERSION).tar.gz - tar xvf download/opencv-$(OPENCV_VERSION).tar.gz +$(DOWNLOAD_PATH)/opencv-$(OPENCV_VERSION).tar.gz: + wget --no-check-certificate https://github.com/Itseez/opencv/archive/$(OPENCV_VERSION).tar.gz -O $(DOWNLOAD_PATH)/opencv-$(OPENCV_VERSION).tar.gz + +libs/opencv-$(OPENCV_VERSION): $(DOWNLOAD_PATH)/opencv-$(OPENCV_VERSION).tar.gz + # prepare + rm -r -f libs/opencv-* + tar xvf $(DOWNLOAD_PATH)/opencv-$(OPENCV_VERSION).tar.gz + # build mkdir -p opencv-$(OPENCV_VERSION)/build #cd opencv-$(OPENCV_VERSION)/build && cmake .. -G"MSYS Makefiles" -DCMAKE_BUILD_TYPE=Release -DBUILD_PERF_TESTS=OFF -DBUILD_TESTS=OFF -DBUILD_SHARED_LIBS=OFF -DCMAKE_INSTALL_PREFIX="`pwd`/../../libs" cd opencv-$(OPENCV_VERSION)/build && cmake .. -G"MSYS Makefiles" -DCMAKE_BUILD_TYPE=Release -DBUILD_PERF_TESTS=OFF -DBUILD_TESTS=OFF -DBUILD_SHARED_LIBS=OFF -DCMAKE_INSTALL_PREFIX="`pwd`/install" cd opencv-$(OPENCV_VERSION)/build && make install - cp -r opencv-$(OPENCV_VERSION)/build/install/include/* libs/include/ - mkdir -p libs/lib/opencv && cp -r opencv-$(OPENCV_VERSION)/build/install/x86/mingw/staticlib/* libs/lib/opencv/ + # copy files + mkdir -p libs/opencv-$(OPENCV_VERSION).tmp/include + cp -r opencv-$(OPENCV_VERSION)/build/install/include/* libs/opencv-$(OPENCV_VERSION).tmp/include/ + mkdir -p libs/opencv-$(OPENCV_VERSION).tmp/lib/opencv + cp -r opencv-$(OPENCV_VERSION)/build/install/x86/mingw/staticlib/* libs/opencv-$(OPENCV_VERSION).tmp/lib/opencv/ rm -r -f opencv-$(OPENCV_VERSION) - touch opencv + mv libs/opencv-$(OPENCV_VERSION).tmp libs/opencv-$(OPENCV_VERSION) -download/libxml2-$(LIBXML2_VERSION).tar.gz: - wget ftp://xmlsoft.org/libxml2/libxml2-$(LIBXML2_VERSION).tar.gz -O download/libxml2-$(LIBXML2_VERSION).tar.gz +libxml2: libs/libxml2-$(LIBXML2_VERSION) -libxml2: download/libxml2-$(LIBXML2_VERSION).tar.gz - tar xvf download/libxml2-$(LIBXML2_VERSION).tar.gz +$(DOWNLOAD_PATH)/libxml2-$(LIBXML2_VERSION).tar.gz: + wget ftp://xmlsoft.org/libxml2/libxml2-$(LIBXML2_VERSION).tar.gz -O $(DOWNLOAD_PATH)/libxml2-$(LIBXML2_VERSION).tar.gz + +libs/libxml2-$(LIBXML2_VERSION): $(DOWNLOAD_PATH)/libxml2-$(LIBXML2_VERSION).tar.gz + # prepare + rm -r -f libs/libxml2-* + tar xvf $(DOWNLOAD_PATH)/libxml2-$(LIBXML2_VERSION).tar.gz + # build cd libxml2-$(LIBXML2_VERSION) && ./configure --without-iconv -enable-shared=no #cd libxml2-$(LIBXML2_VERSION) && make install exec_prefix="`pwd`/../libs" cd libxml2-$(LIBXML2_VERSION) && make - mkdir -p libs/include/libxml && cp libxml2-$(LIBXML2_VERSION)/include/libxml/*.h libs/include/libxml/ - cp libxml2-$(LIBXML2_VERSION)/.libs/libxml2.a libs/lib/ - touch libxml2 + # copy files + mkdir -p libs/libxml2-$(LIBXML2_VERSION).tmp/include/libxml + cp libxml2-$(LIBXML2_VERSION)/include/libxml/*.h libs/libxml2-$(LIBXML2_VERSION).tmp/include/libxml/ + mkdir -p libs/libxml2-$(LIBXML2_VERSION).tmp/lib + cp libxml2-$(LIBXML2_VERSION)/.libs/libxml2.a libs/libxml2-$(LIBXML2_VERSION).tmp/lib/ + #rm -r -f libxml2-$(LIBXML2_VERSION) # see libxslt + mv libs/libxml2-$(LIBXML2_VERSION).tmp libs/libxml2-$(LIBXML2_VERSION) -download/libxslt-$(LIBXSLT_VERSION).tar.gz: - wget ftp://xmlsoft.org/libxml2/libxslt-$(LIBXSLT_VERSION).tar.gz -O download/libxslt-$(LIBXSLT_VERSION).tar.gz +libxslt: libs/libxslt-$(LIBXSLT_VERSION) -libxslt: download/libxml2-$(LIBXML2_VERSION).tar.gz download/libxslt-$(LIBXSLT_VERSION).tar.gz - tar xvf download/libxml2-$(LIBXML2_VERSION).tar.gz - tar xvf download/libxslt-$(LIBXSLT_VERSION).tar.gz - tar xvf libxslt-$(LIBXSLT_VERSION)-fix.tar.gz +$(DOWNLOAD_PATH)/libxslt-$(LIBXSLT_VERSION).tar.gz: + wget ftp://xmlsoft.org/libxml2/libxslt-$(LIBXSLT_VERSION).tar.gz -O $(DOWNLOAD_PATH)/libxslt-$(LIBXSLT_VERSION).tar.gz + +libs/libxslt-$(LIBXSLT_VERSION): $(DOWNLOAD_PATH)/libxml2-$(LIBXML2_VERSION).tar.gz $(DOWNLOAD_PATH)/libxslt-$(LIBXSLT_VERSION).tar.gz + # prepare + rm -r -f libs/libxslt-* + tar xvf $(DOWNLOAD_PATH)/libxml2-$(LIBXML2_VERSION).tar.gz + tar xvf $(DOWNLOAD_PATH)/libxslt-$(LIBXSLT_VERSION).tar.gz + tar xvf $(MAKEFILE_PATH)libxslt-$(LIBXSLT_VERSION)-fix.tar.gz + # build cd libxslt-$(LIBXSLT_VERSION) && ./configure --with-libxml-src=../libxml2-$(LIBXML2_VERSION) -enable-shared=no CFLAGS=-DLIBXML_STATIC cd libxslt-$(LIBXSLT_VERSION) && make - mkdir -p libs/include/libxslt && cp libxslt-$(LIBXSLT_VERSION)/libxslt/*.h libs/include/libxslt/ - cp libxslt-$(LIBXSLT_VERSION)/libxslt/.libs/libxslt.a libs/lib/ - cp libxslt-$(LIBXSLT_VERSION)/libexslt/.libs/libexslt.a libs/lib/ + # copy files + mkdir -p libs/libxslt-$(LIBXSLT_VERSION).tmp/include/libxslt + cp libxslt-$(LIBXSLT_VERSION)/libxslt/*.h libs/libxslt-$(LIBXSLT_VERSION).tmp/include/libxslt/ + mkdir -p libs/libxslt-$(LIBXSLT_VERSION).tmp/lib + cp libxslt-$(LIBXSLT_VERSION)/libxslt/.libs/libxslt.a libs/libxslt-$(LIBXSLT_VERSION).tmp/lib/ + cp libxslt-$(LIBXSLT_VERSION)/libexslt/.libs/libexslt.a libs/libxslt-$(LIBXSLT_VERSION).tmp/lib/ rm -r -f libxml2-$(LIBXML2_VERSION) rm -r -f libxslt-$(LIBXSLT_VERSION) - touch libxslt + mv libs/libxslt-$(LIBXSLT_VERSION).tmp libs/libxslt-$(LIBXSLT_VERSION) -download/curl-$(CURL_VERSION).tar.gz: - wget --no-check-certificate http://curl.haxx.se/download/curl-$(CURL_VERSION).tar.gz -O download/curl-$(CURL_VERSION).tar.gz +curl: libs/curl-$(CURL_VERSION) -curl: download/curl-$(CURL_VERSION).tar.gz - tar xvf download/curl-$(CURL_VERSION).tar.gz - cd curl-$(CURL_VERSION) && ./configure --disable-shared --with-ssl="`pwd`/../libs" +$(DOWNLOAD_PATH)/curl-$(CURL_VERSION).tar.gz: + wget --no-check-certificate http://curl.haxx.se/$(DOWNLOAD_PATH)/curl-$(CURL_VERSION).tar.gz -O $(DOWNLOAD_PATH)/curl-$(CURL_VERSION).tar.gz + +libs/curl-$(CURL_VERSION): $(DOWNLOAD_PATH)/curl-$(CURL_VERSION).tar.gz + # prepare + rm -r -f libs/curl-* + tar xvf $(DOWNLOAD_PATH)/curl-$(CURL_VERSION).tar.gz + # build + cd curl-$(CURL_VERSION) && ./configure --disable-shared --with-ssl="`pwd`/../libs/openssl-$(OPENSSL_VERSION)" #cd curl-$(CURL_VERSION) && make install exec_prefix="`pwd`/../libs" cd curl-$(CURL_VERSION) && make - mkdir -p libs/include/curl && cp curl-$(CURL_VERSION)/include/curl/*.h libs/include/curl/ - cp curl-$(CURL_VERSION)/lib/.libs/libcurl.a libs/lib/ + # copy files + mkdir -p libs/curl-$(CURL_VERSION).tmp/include/curl + cp curl-$(CURL_VERSION)/include/curl/*.h libs/curl-$(CURL_VERSION).tmp/include/curl/ + mkdir -p libs/curl-$(CURL_VERSION).tmp/lib + cp curl-$(CURL_VERSION)/lib/.libs/libcurl.a libs/curl-$(CURL_VERSION).tmp/lib/ rm -r -f curl-$(CURL_VERSION) - touch curl + mv libs/curl-$(CURL_VERSION).tmp libs/curl-$(CURL_VERSION) -download/tcl$(TCL_VERSION)-src.tar.gz: - wget http://prdownloads.sourceforge.net/tcl/tcl$(TCL_VERSION)-src.tar.gz -O download/tcl$(TCL_VERSION)-src.tar.gz +sqlcipher: libs/sqlcipher-$(SQLCIPHER_VERSION) -download/sqlcipher-$(SQLCIPHER_VERSION).tar.gz: - wget --no-check-certificate https://github.com/sqlcipher/sqlcipher/archive/v$(SQLCIPHER_VERSION).tar.gz -O download/sqlcipher-$(SQLCIPHER_VERSION).tar.gz +$(DOWNLOAD_PATH)/tcl$(TCL_VERSION)-src.tar.gz: + wget http://prdownloads.sourceforge.net/tcl/tcl$(TCL_VERSION)-src.tar.gz -O $(DOWNLOAD_PATH)/tcl$(TCL_VERSION)-src.tar.gz -sqlcipher: download/tcl$(TCL_VERSION)-src.tar.gz download/sqlcipher-$(SQLCIPHER_VERSION).tar.gz +$(DOWNLOAD_PATH)/sqlcipher-$(SQLCIPHER_VERSION).tar.gz: + wget --no-check-certificate https://github.com/sqlcipher/sqlcipher/archive/v$(SQLCIPHER_VERSION).tar.gz -O $(DOWNLOAD_PATH)/sqlcipher-$(SQLCIPHER_VERSION).tar.gz + +libs/sqlcipher-$(SQLCIPHER_VERSION): $(DOWNLOAD_PATH)/tcl$(TCL_VERSION)-src.tar.gz $(DOWNLOAD_PATH)/sqlcipher-$(SQLCIPHER_VERSION).tar.gz + # prepare + rm -r -f libs/sqlcipher-* # tcl - tar xvf download/tcl$(TCL_VERSION)-src.tar.gz + tar xvf $(DOWNLOAD_PATH)/tcl$(TCL_VERSION)-src.tar.gz mkdir -p tcl$(TCL_VERSION)/build cd tcl$(TCL_VERSION)/build && ../win/configure cd tcl$(TCL_VERSION)/build && make #sqlcipher - tar xvf download/sqlcipher-$(SQLCIPHER_VERSION).tar.gz + tar xvf $(DOWNLOAD_PATH)/sqlcipher-$(SQLCIPHER_VERSION).tar.gz cd sqlcipher-$(SQLCIPHER_VERSION) && ln -s ../tcl$(TCL_VERSION)/build/tclsh86.exe tclsh mkdir -p tcl$(TCL_VERSION)/lib ln -s `pwd`/tcl$(TCL_VERSION)/library `pwd`/tcl$(TCL_VERSION)/lib/tcl8.6 - cd sqlcipher-$(SQLCIPHER_VERSION) && PATH=.:$$PATH:`pwd`/../tcl$(TCL_VERSION)/build && LIBS="-L`pwd`/../libs/lib -lgdi32 $$LIBS" && export LIBS && ./configure --disable-shared --enable-static --enable-tempstore=yes CFLAGS="-DSQLITE_HAS_CODEC -I`pwd`/../libs/include -I`pwd`/../tcl$(TCL_VERSION)/generic" LDFLAGS="-L`pwd`/../libs/lib -lcrypto -lgdi32" --with-tcl="`pwd`/../tcl$(TCL_VERSION)/build" && make install prefix="`pwd`/install" - cp -r sqlcipher-$(SQLCIPHER_VERSION)/install/include/* libs/include/ - cp sqlcipher-$(SQLCIPHER_VERSION)/install/lib/libsqlcipher.a libs/lib/ - cp sqlcipher-$(SQLCIPHER_VERSION)/install/bin/sqlcipher.exe libs/bin/ + # build + cd sqlcipher-$(SQLCIPHER_VERSION) && PATH=.:$$PATH:`pwd`/../tcl$(TCL_VERSION)/build && LIBS="-L`pwd`/../libs/openssl-$(OPENSSL_VERSION)/lib -lgdi32 $$LIBS" && export LIBS && ./configure --disable-shared --enable-static --enable-tempstore=yes CFLAGS="-DSQLITE_HAS_CODEC -I`pwd`/../libs/openssl-$(OPENSSL_VERSION)/include -I`pwd`/../tcl$(TCL_VERSION)/generic" LDFLAGS="-L`pwd`/../libs/openssl-$(OPENSSL_VERSION)/lib -lcrypto -lgdi32" --with-tcl="`pwd`/../tcl$(TCL_VERSION)/build" && make install prefix="`pwd`/install" + # copy files + mkdir -p libs/sqlcipher-$(SQLCIPHER_VERSION).tmp/include + cp -r sqlcipher-$(SQLCIPHER_VERSION)/install/include/* libs/sqlcipher-$(SQLCIPHER_VERSION).tmp/include/ + mkdir -p libs/sqlcipher-$(SQLCIPHER_VERSION).tmp/lib + cp sqlcipher-$(SQLCIPHER_VERSION)/install/lib/libsqlcipher.a libs/sqlcipher-$(SQLCIPHER_VERSION).tmp/lib/ + mkdir -p libs/sqlcipher-$(SQLCIPHER_VERSION).tmp/bin + cp sqlcipher-$(SQLCIPHER_VERSION)/install/bin/sqlcipher.exe libs/sqlcipher-$(SQLCIPHER_VERSION).tmp/bin/ rm -r -f sqlcipher-$(SQLCIPHER_VERSION) rm -r -f tcl$(TCL_VERSION) - touch sqlcipher + mv libs/sqlcipher-$(SQLCIPHER_VERSION).tmp libs/sqlcipher-$(SQLCIPHER_VERSION) -download/libmicrohttpd-$(LIBMICROHTTPD_VERSION).tar.gz: - wget --no-check-certificate http://ftp.gnu.org/gnu/libmicrohttpd/libmicrohttpd-$(LIBMICROHTTPD_VERSION).tar.gz -O download/libmicrohttpd-$(LIBMICROHTTPD_VERSION).tar.gz +libmicrohttpd: libs/libmicrohttpd-$(LIBMICROHTTPD_VERSION) -libmicrohttpd: download/libmicrohttpd-$(LIBMICROHTTPD_VERSION).tar.gz - tar xvf download/libmicrohttpd-$(LIBMICROHTTPD_VERSION).tar.gz - cd libmicrohttpd-$(LIBMICROHTTPD_VERSION) && ./configure --disable-shared --enable-static --prefix="`pwd`/../libs" +$(DOWNLOAD_PATH)/libmicrohttpd-$(LIBMICROHTTPD_VERSION).tar.gz: + wget --no-check-certificate http://ftp.gnu.org/gnu/libmicrohttpd/libmicrohttpd-$(LIBMICROHTTPD_VERSION).tar.gz -O $(DOWNLOAD_PATH)/libmicrohttpd-$(LIBMICROHTTPD_VERSION).tar.gz + +libs/libmicrohttpd-$(LIBMICROHTTPD_VERSION): $(DOWNLOAD_PATH)/libmicrohttpd-$(LIBMICROHTTPD_VERSION).tar.gz + # prepare + rm -r -f libs/libmicrohttpd-* + tar xvf $(DOWNLOAD_PATH)/libmicrohttpd-$(LIBMICROHTTPD_VERSION).tar.gz + # build + cd libmicrohttpd-$(LIBMICROHTTPD_VERSION) && ./configure --disable-shared --enable-static --prefix="`pwd`/../libs/libmicrohttpd-$(LIBMICROHTTPD_VERSION).tmp" cd libmicrohttpd-$(LIBMICROHTTPD_VERSION) && make install + # copy files rm -r -f libmicrohttpd-$(LIBMICROHTTPD_VERSION) - touch libmicrohttpd + mv libs/libmicrohttpd-$(LIBMICROHTTPD_VERSION).tmp libs/libmicrohttpd-$(LIBMICROHTTPD_VERSION) -download/ffmpeg-$(FFMPEG_VERSION).tar.gz: - wget --no-check-certificate https://ffmpeg.org/releases/ffmpeg-$(FFMPEG_VERSION).tar.gz -O download/ffmpeg-$(FFMPEG_VERSION).tar.gz +ffmpeg: libs/ffmpeg-$(FFMPEG_VERSION) -ffmpeg: download/ffmpeg-$(FFMPEG_VERSION).tar.gz - tar xvf download/ffmpeg-$(FFMPEG_VERSION).tar.gz - cd ffmpeg-$(FFMPEG_VERSION) && ./configure --disable-shared --enable-static --disable-programs --disable-ffmpeg --disable-ffplay --disable-ffprobe --disable-ffserver --disable-doc --disable-htmlpages --disable-manpages --disable-podpages --disable-txtpages --disable-yasm --disable-everything --enable-encoder=mpeg4 --enable-decoder=mpeg4 --prefix="`pwd`/../libs" +$(DOWNLOAD_PATH)/ffmpeg-$(FFMPEG_VERSION).tar.gz: + wget --no-check-certificate https://ffmpeg.org/releases/ffmpeg-$(FFMPEG_VERSION).tar.gz -O $(DOWNLOAD_PATH)/ffmpeg-$(FFMPEG_VERSION).tar.gz + +libs/ffmpeg-$(FFMPEG_VERSION): $(DOWNLOAD_PATH)/ffmpeg-$(FFMPEG_VERSION).tar.gz + # prepare + rm -r -f libs/ffmpeg-* + tar xvf $(DOWNLOAD_PATH)/ffmpeg-$(FFMPEG_VERSION).tar.gz + # build + cd ffmpeg-$(FFMPEG_VERSION) && ./configure --disable-shared --enable-static --disable-programs --disable-ffmpeg --disable-ffplay --disable-ffprobe --disable-ffserver --disable-doc --disable-htmlpages --disable-manpages --disable-podpages --disable-txtpages --disable-yasm --disable-everything --enable-encoder=mpeg4 --enable-decoder=mpeg4 --prefix="`pwd`/../libs/ffmpeg-$(FFMPEG_VERSION).tmp" cd ffmpeg-$(FFMPEG_VERSION) && make install + # copy files rm -r -f ffmpeg-$(FFMPEG_VERSION) - touch ffmpeg + mv libs/ffmpeg-$(FFMPEG_VERSION).tmp libs/ffmpeg-$(FFMPEG_VERSION) - -copylibs: - read -p "Do you want to copy libs to retroshare? (yes|no)" answer; \ - if [ "$$answer" = "yes" ] ; then \ - cp -r libs ../../../../ ; \ +copylibs: + if [ "$(COPY_ANSWER)" = "" ] ; then \ + read -p "Do you want to copy libs to retroshare? (y|n)" answer; \ + else \ + answer=$(COPY_ANSWER) ; \ + fi ; \ + if [ "$$answer" = "y" ] ; then \ + rm -r -f $(LIBS_PATH) ; \ + mkdir -p $(LIBS_PATH) ; \ + cp ./libs/gcc-version $(LIBS_PATH) ; \ + find ./libs -mindepth 1 -maxdepth 1 -type d -not -name "*.tmp" -print -exec cp -r {}/. $(LIBS_PATH) \; ; \ fi - diff --git a/build_scripts/Windows/build_libs/_env.bat b/build_scripts/Windows/build_libs/_env.bat deleted file mode 100644 index 8ca4f15ec..000000000 --- a/build_scripts/Windows/build_libs/_env.bat +++ /dev/null @@ -1,9 +0,0 @@ -set CurPath=%~dp0 -set DownloadPath=%CurPath%download -set ToolsPath=%CurPath%tools -set TempPath=%CurPath%tmp -set MSYSPath=%CurPath%msys -set LibsPath=%CurPath%libs - -set CurlExe=%ToolsPath%\curl.exe -set SevenZipExe=%ToolsPath%\7z.exe diff --git a/build_scripts/Windows/build_libs/build-libs.bat b/build_scripts/Windows/build_libs/build-libs.bat new file mode 100644 index 000000000..197f0f97f --- /dev/null +++ b/build_scripts/Windows/build_libs/build-libs.bat @@ -0,0 +1,46 @@ +:: Usage: +:: call build-libs.bat [auto-copy] [make tasks] + +@echo off + +setlocal + +:: Parameter +set MakeParam="DOWNLOAD_PATH=../download" +if "%~1"=="auto-copy" set MakeParam=%MakeParam% "COPY_ANSWER=y"& shift /1 + +set MakeTask= +:param_loop +if "%~1" NEQ "" ( + set MakeTask=%MakeTask% %1 + shift /1 + goto param_loop +) + +:: Initialize environment +call "%~dp0..\env.bat" +if errorlevel 1 goto error_env +call "%EnvPath%\env-msys.bat" +if errorlevel 1 goto error_env + +:: Check MSYS environment +set MSYSSH=%EnvMSYSPath%\msys\1.0\bin\sh.exe +if not exist "%MSYSSH%" echo Please install MSYS first.& exit /B 1 + +:: Initialize environment +call "%~dp0env.bat" +if errorlevel 1 goto error_env + +call "%ToolsPath%\msys-path.bat" "%CurPath%" MSYSCurPath +call "%ToolsPath%\msys-path.bat" "%BuildLibsPath%" MSYSBuildLibsPath + +if not exist "%BuildLibsPath%" mkdir "%BuildLibsPath%" + +"%MSYSSH%" --login -i -c "cd "%MSYSBuildLibsPath%" && make -f %MSYSCurPath%/makefile %MakeParam% %MakeTask%" + +exit /B %ERRORLEVEL% + +:error_env +echo Failed to initialize environment. +endlocal +exit /B 1 diff --git a/build_scripts/Windows/build_libs/clean-all.bat b/build_scripts/Windows/build_libs/clean-all.bat deleted file mode 100644 index 740bf9d3e..000000000 --- a/build_scripts/Windows/build_libs/clean-all.bat +++ /dev/null @@ -1,30 +0,0 @@ -@setlocal - -@echo off - -:: Initialize environment -call "%~dp0_env.bat" - -::call :remove_dir "%DownloadPath%" -call :remove_dir "%MSYSPath%" -call :remove_dir "%TempPath%" - -call :remove_file "%ToolsPath%\7z.exe" -call :remove_file "%ToolsPath%\7z.dll" -call :remove_file "%ToolsPath%\curl.exe" - -call "%~dp0clean.bat" - -endlocal -exit /B 0 - -:remove_dir -if not exist %1 goto :EOF -del /s /f /q %1 >nul -rmdir /s /q %1 -goto :EOF - -:remove_file -if not exist %1 goto :EOF -del /q %1 >nul -goto :EOF diff --git a/build_scripts/Windows/build_libs/clean.bat b/build_scripts/Windows/build_libs/clean.bat index 171130fc2..a8c35a512 100644 --- a/build_scripts/Windows/build_libs/clean.bat +++ b/build_scripts/Windows/build_libs/clean.bat @@ -1,36 +1,3 @@ -@setlocal - @echo off -:: Initialize environment -call "%~dp0_env.bat" - -call :remove_dir "%LibsPath%" - -call :remove_file "%CurPath%bzip2" -call :remove_file "%CurPath%curl" -call :remove_file "%CurPath%ffmpeg" -call :remove_file "%CurPath%libmicrohttpd" -call :remove_file "%CurPath%libxml2" -call :remove_file "%CurPath%libxslt" -call :remove_file "%CurPath%miniupnpc" -call :remove_file "%CurPath%opencv" -call :remove_file "%CurPath%openssl" -call :remove_file "%CurPath%speex" -call :remove_file "%CurPath%speexdsp" -call :remove_file "%CurPath%sqlcipher" -call :remove_file "%CurPath%zlib" - -endlocal -exit /B 0 - -:remove_dir -if not exist %1 goto :EOF -del /s /f /q %1 >nul -rmdir /s /q %1 -goto :EOF - -:remove_file -if not exist %1 goto :EOF -del /q %1 >nul -goto :EOF +call "%~dp0build-libs.bat" clean diff --git a/build_scripts/Windows/build_libs/env.bat b/build_scripts/Windows/build_libs/env.bat new file mode 100644 index 000000000..affde05f9 --- /dev/null +++ b/build_scripts/Windows/build_libs/env.bat @@ -0,0 +1,14 @@ +set CurPath=%~dp0 + +:: Check MinGW environment +set MinGWPath= +call "%ToolsPath%\find-in-path.bat" MinGWPath gcc.exe +if "%MinGWPath%"=="" echo Please run command in the Qt Command Prompt or add the path to MinGW bin folder to PATH variable.& exit /B 1 + +:: Get gcc versions +call "%ToolsPath%\get-gcc-version.bat" GCCVersion +if "%GCCVersion%"=="" echo Cannot get gcc version.& exit /B 1 + +set BuildLibsPath=%EnvRootPath%\build-libs\gcc-%GCCVersion% + +exit /B 0 diff --git a/build_scripts/Windows/build_libs/update-msys.bat b/build_scripts/Windows/build_libs/update-msys.bat deleted file mode 100644 index 6ecc30eff..000000000 --- a/build_scripts/Windows/build_libs/update-msys.bat +++ /dev/null @@ -1,16 +0,0 @@ -@setlocal - -@echo off - -:: Initialize environment -call "%~dp0_env.bat" - -if not exist "%MSYSPath%\bin\mingw-get.exe" exit /B 0 - -echo Update MSYS -pushd "%MSYSPath%\bin" -mingw-get.exe update -mingw-get.exe upgrade -popd - -exit /B %ERRORLEVEL% diff --git a/build_scripts/Windows/env.bat b/build_scripts/Windows/env.bat new file mode 100644 index 000000000..863369162 --- /dev/null +++ b/build_scripts/Windows/env.bat @@ -0,0 +1,19 @@ +call :make_path SourcePath "%~dp0..\.." +call :make_path RootPath "%SourcePath%\.." +call :source_name SourceName "%SourcePath%" +set ToolsPath=%~dp0tools +set EnvPath=%~dp0env + +exit /B 0 + +:make_path +setlocal +set Var=%~1 +pushd %2 +set CD=%cd% +popd +endlocal & set %Var%=%CD% +goto :EOF + +:source_name +set %~1=%~nx2 diff --git a/build_scripts/Windows/env/env-msys.bat b/build_scripts/Windows/env/env-msys.bat new file mode 100644 index 000000000..9b1d98620 --- /dev/null +++ b/build_scripts/Windows/env/env-msys.bat @@ -0,0 +1,16 @@ +:: Usage: +:: call find-in-path.bat [reinstall|clean] + +:: Initialize environment +call "%~dp0env.bat" +if errorlevel 1 goto error_env + +set EnvMSYSPath=%EnvRootPath%\msys + +call "%~dp0tools\prepare-msys.bat" %1 +exit /B %ERRORLEVEL% + +:error_env +echo Failed to initialize environment. +endlocal +exit /B 1 diff --git a/build_scripts/Windows/env/env.bat b/build_scripts/Windows/env/env.bat new file mode 100644 index 000000000..d9052b5f3 --- /dev/null +++ b/build_scripts/Windows/env/env.bat @@ -0,0 +1,29 @@ +:: Initialize environment +call "%~dp0..\env.bat" +if errorlevel 1 goto error_env + +set EnvRootPath=%RootPath%\%SourceName%-env +set EnvToolsPath=%EnvRootPath%\tools +set EnvTempPath=%EnvRootPath%\tmp +set EnvDownloadPath=%EnvRootPath%\download + +set EnvCurlExe=%EnvToolsPath%\curl.exe +set EnvSevenZipExe=%EnvToolsPath%\7z.exe +set EnvJomExe=%EnvToolsPath%\jom.exe +set EnvSedExe=%EnvToolsPath%\sed.exe +set EnvCutExe=%EnvToolsPath%\cut.exe +set EnvDependsExe=%EnvToolsPath%\depends.exe +set EnvMakeNSISExe=%EnvToolsPath%\NSIS\makensis.exe + +:: Create folders +if not exist "%EnvRootPath%" mkdir "%EnvRootPath%" +if not exist "%EnvToolsPath%" mkdir "%EnvToolsPath%" +if not exist "%EnvDownloadPath%" mkdir "%EnvDownloadPath%" + +call "%~dp0tools\prepare-tools.bat" +exit /B %ERRORLEVEL% + +:error_env +echo Failed to initialize environment. +endlocal +exit /B 1 diff --git a/build_scripts/Windows/env/tools/prepare-msys.bat b/build_scripts/Windows/env/tools/prepare-msys.bat new file mode 100644 index 000000000..4799715ca --- /dev/null +++ b/build_scripts/Windows/env/tools/prepare-msys.bat @@ -0,0 +1,83 @@ +:: Usage: +:: call prepare-msys.bat [reinstall|clean] + +setlocal enabledelayedexpansion + +if "%EnvMSYSPath%"=="" exit /B 1 +if not exist "%EnvRootPath%"=="" exit /B 1 + +copy "%~dp0root\update-msys.bat" "%EnvRootPath%" >nul + +if "%~1"=="clean" ( + echo Clean MSYS + call "%ToolsPath%\remove-dir.bat" "%EnvMSYSPath%" + goto exit +) + +if exist "%EnvMSYSPath%\bin\mingw-get.exe" ( + if "%~1"=="reinstall" ( + choice /M "Found existing MSYS version. Do you want to proceed?" + if !ERRORLEVEL!==2 goto exit + ) else ( + goto exit + ) +) + +set MSYSInstall=mingw-get-0.6.2-mingw32-beta-20131004-1-bin.zip +set CMakeInstall=cmake-3.1.0-win32-x86.zip +set CMakeUnpackPath=%EnvMSYSPath%\msys\1.0 + +echo Remove previous MSYS version +call "%ToolsPath%\remove-dir.bat" "%EnvMSYSPath%" + +echo Download installation files +if not exist "%EnvDownloadPath%\%MSYSInstall%" "%EnvCurlExe%" -L -k http://sourceforge.net/projects/mingw/files/Installer/mingw-get/mingw-get-0.6.2-beta-20131004-1/%MSYSInstall%/download -o "%EnvDownloadPath%\%MSYSInstall%" +if not exist "%EnvDownloadPath%%\MSYSInstall%" echo Cannot download MSYS& goto error + +if not exist "%EnvDownloadPath%\%CMakeInstall%" "%EnvCurlExe%" -L -k http://www.cmake.org/files/v3.1/cmake-3.1.0-win32-x86.zip -o "%EnvDownloadPath%\%CMakeInstall%" +if not exist "%EnvDownloadPath%\%CMakeInstall%" echo Cannot download CMake& goto error + +echo Unpack MSYS +"%EnvSevenZipExe%" x -o"%EnvMSYSPath%" "%EnvDownloadPath%\%MSYSInstall%" + +echo Install MSYS +if not exist "%EnvMSYSPath%\var\lib\mingw-get\data\profile.xml" copy "%EnvMSYSPath%\var\lib\mingw-get\data\defaults.xml" "%EnvMSYSPath%\var\lib\mingw-get\data\profile.xml" +pushd "%EnvMSYSPath%\bin" +mingw-get.exe install mingw32-mingw-get +mingw-get.exe install msys-coreutils +mingw-get.exe install msys-base +mingw-get.exe install msys-autoconf +mingw-get.exe install msys-automake +mingw-get.exe install msys-autogen +mingw-get.exe install msys-mktemp +mingw-get.exe install msys-wget +popd + +echo Unpack CMake +"%EnvSevenZipExe%" x -o"%CMakeUnpackPath%" "%EnvDownloadPath%\%CMakeInstall%" + +echo Install CMake +set CMakeVersion= +for /D %%F in (%CMakeUnpackPath%\cmake*) do set CMakeVersion=%%~nxF +if "%CMakeVersion%"=="" echo CMake version not found.& goto :exit +echo Found CMake version %CMakeVersion% + +set FoundProfile= +for /f "tokens=3" %%F in ('find /c /i "%CMakeVersion%" "%EnvMSYSPath%\msys\1.0\etc\profile"') do set FoundProfile=%%F + +if "%FoundProfile%"=="0" ( + echo export PATH="${PATH}:/%CMakeVersion%/bin">>"%EnvMSYSPath%\msys\1.0\etc\profile" +) + +:exit +endlocal +exit /B 0 + +:error +endlocal +exit /B 1 + +:error_vars +echo Failed to initialize variables. +endlocal +exit /B 1 diff --git a/build_scripts/Windows/env/tools/prepare-tools.bat b/build_scripts/Windows/env/tools/prepare-tools.bat new file mode 100644 index 000000000..f453f35da --- /dev/null +++ b/build_scripts/Windows/env/tools/prepare-tools.bat @@ -0,0 +1,139 @@ +setlocal + +if "%EnvRootPath%"=="" exit /B 1 + +set SevenZipUrl=http://7-zip.org/a/7z1602.msi +set SevenZipInstall=7z1602.msi +set CurlUrl=https://bintray.com/artifact/download/vszakats/generic/curl-7.50.1-win32-mingw.7z +set CurlInstall=curl-7.50.1-win32-mingw.7z +set JomUrl=http://download.qt.io/official_releases/jom/jom.zip +set JomInstall=jom.zip +set DependsUrl=http://www.dependencywalker.com/depends22_x86.zip +set DependsInstall=depends22_x86.zip +set UnixToolsUrl=http://unxutils.sourceforge.net/UnxUpdates.zip +set UnixToolsInstall=UnxUpdates.zip +set NSISUrl=http://prdownloads.sourceforge.net/nsis/nsis-3.0-setup.exe?download +set NSISInstall=nsis-3.0-setup.exe +set NSISInstallPath=%EnvToolsPath%\NSIS + +if not exist "%EnvToolsPath%\7z.exe" ( + call "%ToolsPath%\remove-dir.bat" "%EnvTempPath%" + mkdir "%EnvTempPath%" + + echo Download 7z installation + + if not exist "%EnvDownloadPath%\%SevenZipInstall%" call "%ToolsPath%\winhttpjs.bat" %SevenZipUrl% -saveTo "%EnvDownloadPath%\%SevenZipInstall%" + if not exist "%EnvDownloadPath%\%SevenZipInstall%" echo Cannot download 7z installation& goto error + + echo Unpack 7z + msiexec /a "%EnvDownloadPath%\%SevenZipInstall%" /qb TARGETDIR="%EnvTempPath%" + copy "%EnvTempPath%\Files\7-Zip\7z.dll" "%EnvToolsPath%" + copy "%EnvTempPath%\Files\7-Zip\7z.exe" "%EnvToolsPath%" + + call "%ToolsPath%\remove-dir.bat" "%EnvTempPath%" +) + +if not exist "%EnvToolsPath%\curl.exe" ( + call "%ToolsPath%\remove-dir.bat" "%EnvTempPath%" + mkdir "%EnvTempPath%" + + echo Download Curl installation + + if not exist "%EnvDownloadPath%\%CurlInstall%" call "%ToolsPath%\winhttpjs.bat" %CurlUrl% -saveTo "%EnvDownloadPath%\%CurlInstall%" + if not exist "%EnvDownloadPath%\%CurlInstall%" echo Cannot download Curl installation& goto error + + echo Unpack Curl + "%EnvSevenZipExe%" x -o"%EnvTempPath%" "%EnvDownloadPath%\%CurlInstall%" + copy "%EnvTempPath%\curl-7.50.1-win32-mingw\bin\curl.exe" "%EnvToolsPath%" + + call "%ToolsPath%\remove-dir.bat" "%EnvTempPath%" +) + +if not exist "%EnvToolsPath%\jom.exe" ( + call "%ToolsPath%\remove-dir.bat" "%EnvTempPath%" + mkdir "%EnvTempPath%" + + echo Download jom installation + + if not exist "%EnvDownloadPath%\%JomInstall%" call "%ToolsPath%\winhttpjs.bat" %JomUrl% -saveTo "%EnvDownloadPath%\%JomInstall%" + if not exist "%EnvDownloadPath%\%JomInstall%" echo Cannot download jom installation& goto error + + echo Unpack jom + "%EnvSevenZipExe%" x -o"%EnvTempPath%" "%EnvDownloadPath%\%JomInstall%" + copy "%EnvTempPath%\jom.exe" "%EnvToolsPath%" + + call "%ToolsPath%\remove-dir.bat" "%EnvTempPath%" +) + +if not exist "%EnvToolsPath%\depends.exe" ( + call "%ToolsPath%\remove-dir.bat" "%EnvTempPath%" + mkdir "%EnvTempPath%" + + echo Download Dependency Walker installation + + if not exist "%EnvDownloadPath%\%DependsInstall%" call "%ToolsPath%\winhttpjs.bat" %DependsUrl% -saveTo "%EnvDownloadPath%\%DependsInstall%" + if not exist "%EnvDownloadPath%\%DependsInstall%" echo Cannot download Dependendy Walker installation& goto error + + echo Unpack Dependency Walker + "%EnvSevenZipExe%" x -o"%EnvTempPath%" "%EnvDownloadPath%\%DependsInstall%" + copy "%EnvTempPath%\*" "%EnvToolsPath%" + + call "%ToolsPath%\remove-dir.bat" "%EnvTempPath%" +) + +if not exist "%EnvToolsPath%\cut.exe" ( + call "%ToolsPath%\remove-dir.bat" "%EnvTempPath%" + mkdir "%EnvTempPath%" + + echo Download Unix Tools installation + + if not exist "%EnvDownloadPath%\%UnixToolsInstall%" call "%ToolsPath%\winhttpjs.bat" %UnixToolsUrl% -saveTo "%EnvDownloadPath%\%UnixToolsInstall%" + if not exist "%EnvDownloadPath%\%UnixToolsInstall%" echo Cannot download unix Tools installation& goto error + + echo Unpack Unix Tools + "%EnvSevenZipExe%" x -o"%EnvTempPath%" "%EnvDownloadPath%\%UnixToolsInstall%" + copy "%EnvTempPath%\cut.exe" "%EnvToolsPath%" + + call "%ToolsPath%\remove-dir.bat" "%EnvTempPath%" +) + +if not exist "%EnvToolsPath%\sed.exe" ( + call "%ToolsPath%\remove-dir.bat" "%EnvTempPath%" + mkdir "%EnvTempPath%" + + echo Download Unix Tools installation + + if not exist "%EnvDownloadPath%\%UnixToolsInstall%" call "%ToolsPath%\winhttpjs.bat" %UnixToolsUrl% -saveTo "%EnvDownloadPath%\%UnixToolsInstall%" + if not exist "%EnvDownloadPath%\%UnixToolsInstall%" echo Cannot download Unix Tools installation& goto error + + echo Unpack Unix Tools + "%EnvSevenZipExe%" x -o"%EnvTempPath%" "%EnvDownloadPath%\%UnixToolsInstall%" + copy "%EnvTempPath%\sed.exe" "%EnvToolsPath%" + + call "%ToolsPath%\remove-dir.bat" "%EnvTempPath%" +) + +if not exist "%EnvToolsPath%\NSIS\nsis.exe" ( + call "%ToolsPath%\remove-dir.bat" "%EnvTempPath%" + mkdir "%EnvTempPath%" + + echo Download NSIS installation + + if not exist "%EnvDownloadPath%\%NSISInstall%" "%EnvCurlExe%" -L -k %NSISUrl% -o "%EnvDownloadPath%\%NSISInstall%" + if not exist "%EnvDownloadPath%\%NSISInstall%" echo Cannot download NSIS installation& goto error + + echo Unpack NSIS + "%EnvSevenZipExe%" x -o"%EnvTempPath%" "%EnvDownloadPath%\%NSISInstall%" + if not exist "%NSISInstallPath%" mkdir "%NSISInstallPath%" + xcopy /s "%EnvTempPath%" "%NSISInstallPath%" + + call "%ToolsPath%\remove-dir.bat" "%EnvTempPath%" +) + +:exit +endlocal +exit /B 0 + +:error +endlocal +exit /B 1 diff --git a/build_scripts/Windows/env/tools/root/update-msys.bat b/build_scripts/Windows/env/tools/root/update-msys.bat new file mode 100644 index 000000000..b0a109d01 --- /dev/null +++ b/build_scripts/Windows/env/tools/root/update-msys.bat @@ -0,0 +1,15 @@ +@echo off + +setlocal + +set MSYSPath=%~dp0msys + +if not exist "%MSYSPath%\bin\mingw-get.exe" echo MSYS is not installed& exit /B 0 + +echo Update MSYS +pushd "%MSYSPath%\bin" +mingw-get.exe update +mingw-get.exe upgrade +popd + +exit /B %ERRORLEVEL% diff --git a/build_scripts/Windows/HeaderImage.bmp b/build_scripts/Windows/installer/HeaderImage.bmp similarity index 100% rename from build_scripts/Windows/HeaderImage.bmp rename to build_scripts/Windows/installer/HeaderImage.bmp diff --git a/build_scripts/Windows/HeaderImageEmpty.bmp b/build_scripts/Windows/installer/HeaderImageEmpty.bmp similarity index 100% rename from build_scripts/Windows/HeaderImageEmpty.bmp rename to build_scripts/Windows/installer/HeaderImageEmpty.bmp diff --git a/build_scripts/Windows/lang/ca_ES.nsh b/build_scripts/Windows/installer/lang/ca_ES.nsh similarity index 100% rename from build_scripts/Windows/lang/ca_ES.nsh rename to build_scripts/Windows/installer/lang/ca_ES.nsh diff --git a/build_scripts/Windows/lang/de.nsh b/build_scripts/Windows/installer/lang/de.nsh similarity index 100% rename from build_scripts/Windows/lang/de.nsh rename to build_scripts/Windows/installer/lang/de.nsh diff --git a/build_scripts/Windows/lang/en.nsh b/build_scripts/Windows/installer/lang/en.nsh similarity index 100% rename from build_scripts/Windows/lang/en.nsh rename to build_scripts/Windows/installer/lang/en.nsh diff --git a/build_scripts/Windows/lang/es.nsh b/build_scripts/Windows/installer/lang/es.nsh similarity index 100% rename from build_scripts/Windows/lang/es.nsh rename to build_scripts/Windows/installer/lang/es.nsh diff --git a/build_scripts/Windows/lang/fr.nsh b/build_scripts/Windows/installer/lang/fr.nsh similarity index 100% rename from build_scripts/Windows/lang/fr.nsh rename to build_scripts/Windows/installer/lang/fr.nsh diff --git a/build_scripts/Windows/lang/pl.nsh b/build_scripts/Windows/installer/lang/pl.nsh similarity index 100% rename from build_scripts/Windows/lang/pl.nsh rename to build_scripts/Windows/installer/lang/pl.nsh diff --git a/build_scripts/Windows/lang/ru.nsh b/build_scripts/Windows/installer/lang/ru.nsh similarity index 100% rename from build_scripts/Windows/lang/ru.nsh rename to build_scripts/Windows/installer/lang/ru.nsh diff --git a/build_scripts/Windows/lang/tr.nsh b/build_scripts/Windows/installer/lang/tr.nsh similarity index 100% rename from build_scripts/Windows/lang/tr.nsh rename to build_scripts/Windows/installer/lang/tr.nsh diff --git a/build_scripts/Windows/lang/ts/ca_ES.ts b/build_scripts/Windows/installer/lang/ts/ca_ES.ts similarity index 100% rename from build_scripts/Windows/lang/ts/ca_ES.ts rename to build_scripts/Windows/installer/lang/ts/ca_ES.ts diff --git a/build_scripts/Windows/lang/ts/convert_from_ts.bat b/build_scripts/Windows/installer/lang/ts/convert_from_ts.bat similarity index 100% rename from build_scripts/Windows/lang/ts/convert_from_ts.bat rename to build_scripts/Windows/installer/lang/ts/convert_from_ts.bat diff --git a/build_scripts/Windows/lang/ts/convert_from_ts.xsl b/build_scripts/Windows/installer/lang/ts/convert_from_ts.xsl similarity index 100% rename from build_scripts/Windows/lang/ts/convert_from_ts.xsl rename to build_scripts/Windows/installer/lang/ts/convert_from_ts.xsl diff --git a/build_scripts/Windows/lang/ts/convert_to_ts.bat b/build_scripts/Windows/installer/lang/ts/convert_to_ts.bat similarity index 100% rename from build_scripts/Windows/lang/ts/convert_to_ts.bat rename to build_scripts/Windows/installer/lang/ts/convert_to_ts.bat diff --git a/build_scripts/Windows/lang/ts/de.ts b/build_scripts/Windows/installer/lang/ts/de.ts similarity index 100% rename from build_scripts/Windows/lang/ts/de.ts rename to build_scripts/Windows/installer/lang/ts/de.ts diff --git a/build_scripts/Windows/lang/ts/en.ts b/build_scripts/Windows/installer/lang/ts/en.ts similarity index 100% rename from build_scripts/Windows/lang/ts/en.ts rename to build_scripts/Windows/installer/lang/ts/en.ts diff --git a/build_scripts/Windows/lang/ts/es.ts b/build_scripts/Windows/installer/lang/ts/es.ts similarity index 100% rename from build_scripts/Windows/lang/ts/es.ts rename to build_scripts/Windows/installer/lang/ts/es.ts diff --git a/build_scripts/Windows/lang/ts/fr.ts b/build_scripts/Windows/installer/lang/ts/fr.ts similarity index 100% rename from build_scripts/Windows/lang/ts/fr.ts rename to build_scripts/Windows/installer/lang/ts/fr.ts diff --git a/build_scripts/Windows/lang/ts/pl.ts b/build_scripts/Windows/installer/lang/ts/pl.ts similarity index 100% rename from build_scripts/Windows/lang/ts/pl.ts rename to build_scripts/Windows/installer/lang/ts/pl.ts diff --git a/build_scripts/Windows/lang/ts/ru.ts b/build_scripts/Windows/installer/lang/ts/ru.ts similarity index 100% rename from build_scripts/Windows/lang/ts/ru.ts rename to build_scripts/Windows/installer/lang/ts/ru.ts diff --git a/build_scripts/Windows/lang/ts/tr.ts b/build_scripts/Windows/installer/lang/ts/tr.ts similarity index 100% rename from build_scripts/Windows/lang/ts/tr.ts rename to build_scripts/Windows/installer/lang/ts/tr.ts diff --git a/build_scripts/Windows/lang/ts/xsltproc.exe b/build_scripts/Windows/installer/lang/ts/xsltproc.exe similarity index 100% rename from build_scripts/Windows/lang/ts/xsltproc.exe rename to build_scripts/Windows/installer/lang/ts/xsltproc.exe diff --git a/build_scripts/Windows/lang/ts/zh_CN.ts b/build_scripts/Windows/installer/lang/ts/zh_CN.ts similarity index 100% rename from build_scripts/Windows/lang/ts/zh_CN.ts rename to build_scripts/Windows/installer/lang/ts/zh_CN.ts diff --git a/build_scripts/Windows/lang/zh_CN.nsh b/build_scripts/Windows/installer/lang/zh_CN.nsh similarity index 100% rename from build_scripts/Windows/lang/zh_CN.nsh rename to build_scripts/Windows/installer/lang/zh_CN.nsh diff --git a/build_scripts/Windows/retroshare-Qt4.nsi b/build_scripts/Windows/installer/retroshare-Qt4.nsi similarity index 94% rename from build_scripts/Windows/retroshare-Qt4.nsi rename to build_scripts/Windows/installer/retroshare-Qt4.nsi index 139113a02..4efaa22de 100644 --- a/build_scripts/Windows/retroshare-Qt4.nsi +++ b/build_scripts/Windows/installer/retroshare-Qt4.nsi @@ -3,7 +3,6 @@ # Needed defines ;!define BUILDADD "" -;!define SOURCEDIR "" ;!define RELEASEDIR "" ;!define QTDIR "" ;!define MINGWDIR "" @@ -16,10 +15,6 @@ !error "BUILDADD is not defined" !endif -!ifndef SOURCEDIR -!error "SOURCEDIR is not defined" -!endif - !ifndef RELEASEDIR !error "RELEASEDIR is not defined" !endif @@ -38,12 +33,22 @@ !define OUTDIR_ "" !endif +!ifndef INSTALLERADD +!define INSTALLERADD "" +!endif + +# Source directory +!define SOURCEDIR "..\..\.." + # Get version from executable !GetDllVersion "${RELEASEDIR}\retroshare-gui\src\release\RetroShare06.exe" VERSION_ - !define VERSION ${VERSION_1}.${VERSION_2}.${VERSION_3}${BUILDADD} ;!define REVISION ${VERSION_4} +# Get version of Qt +!GetDllVersion "${QTDIR}\bin\QtCore4.dll" QTVERSION_ +!define QTVERSION ${QTVERSION_1}.${QTVERSION_2}.${QTVERSION_3} + # Check version !ifndef REVISION !error "REVISION is not defined" @@ -71,7 +76,7 @@ # Main Install settings Name "${APPNAMEANDVERSION}" InstallDirRegKey HKLM "Software\${APPNAME}" "" -OutFile "${OUTDIR_}RetroShare-${VERSION}-${Date}-${REVISION}-setup.exe" +OutFile "${OUTDIR_}RetroShare-${VERSION}-${Date}-${REVISION}-Qt-${QTVERSION}${INSTALLERADD}-setup.exe" BrandingText "${APPNAMEANDVERSION}" RequestExecutionlevel highest # Use compression @@ -92,7 +97,7 @@ Var StyleSheetDir # Interface Settings !define MUI_ABORTWARNING !define MUI_HEADERIMAGE -!define MUI_HEADERIMAGE_BITMAP "${SOURCEDIR}\build_scripts\Windows\HeaderImage.bmp" +!define MUI_HEADERIMAGE_BITMAP "${SOURCEDIR}\build_scripts\Windows\installer\HeaderImage.bmp" ;!define MUI_WELCOMEFINISHPAGE_BITMAP "...bmp" # MUI defines diff --git a/build_scripts/Windows/retroshare-Qt5.nsi b/build_scripts/Windows/installer/retroshare-Qt5.nsi similarity index 95% rename from build_scripts/Windows/retroshare-Qt5.nsi rename to build_scripts/Windows/installer/retroshare-Qt5.nsi index 918ce53b1..cda4aff3a 100644 --- a/build_scripts/Windows/retroshare-Qt5.nsi +++ b/build_scripts/Windows/installer/retroshare-Qt5.nsi @@ -3,7 +3,6 @@ # Needed defines ;!define BUILDADD "" -;!define SOURCEDIR "" ;!define RELEASEDIR "" ;!define QTDIR "" ;!define MINGWDIR "" @@ -16,10 +15,6 @@ !error "BUILDADD is not defined" !endif -!ifndef SOURCEDIR -!error "SOURCEDIR is not defined" -!endif - !ifndef RELEASEDIR !error "RELEASEDIR is not defined" !endif @@ -38,12 +33,22 @@ !define OUTDIR_ "" !endif +!ifndef INSTALLERADD +!define INSTALLERADD "" +!endif + +# Source directory +!define SOURCEDIR "..\..\.." + # Get version from executable !GetDllVersion "${RELEASEDIR}\retroshare-gui\src\release\RetroShare06.exe" VERSION_ - !define VERSION ${VERSION_1}.${VERSION_2}.${VERSION_3}${BUILDADD} ;!define REVISION ${VERSION_4} +# Get version of Qt +!GetDllVersion "${QTDIR}\bin\Qt5Core.dll" QTVERSION_ +!define QTVERSION ${QTVERSION_1}.${QTVERSION_2}.${QTVERSION_3} + # Check version !ifndef REVISION !error "REVISION is not defined" @@ -71,7 +76,7 @@ # Main Install settings Name "${APPNAMEANDVERSION}" InstallDirRegKey HKLM "Software\${APPNAME}" "" -OutFile "${OUTDIR_}RetroShare-${VERSION}-${Date}-${REVISION}-setup.exe" +OutFile "${OUTDIR_}RetroShare-${VERSION}-${Date}-${REVISION}-Qt-${QTVERSION}${INSTALLERADD}-setup.exe" BrandingText "${APPNAMEANDVERSION}" RequestExecutionlevel highest # Use compression @@ -92,7 +97,7 @@ Var StyleSheetDir # Interface Settings !define MUI_ABORTWARNING !define MUI_HEADERIMAGE -!define MUI_HEADERIMAGE_BITMAP "${SOURCEDIR}\build_scripts\Windows\HeaderImage.bmp" +!define MUI_HEADERIMAGE_BITMAP "${SOURCEDIR}\build_scripts\Windows\installer\HeaderImage.bmp" ;!define MUI_WELCOMEFINISHPAGE_BITMAP "...bmp" # MUI defines @@ -216,9 +221,7 @@ Section $(Section_Main) Section_Main File /r "${QTDIR}\plugins\imageformats\qgif.dll" File /r "${QTDIR}\plugins\imageformats\qicns.dll" File /r "${QTDIR}\plugins\imageformats\qico.dll" - File /r "${QTDIR}\plugins\imageformats\qjp2.dll" File /r "${QTDIR}\plugins\imageformats\qjpeg.dll" - File /r "${QTDIR}\plugins\imageformats\qmng.dll" File /r "${QTDIR}\plugins\imageformats\qsvg.dll" File /r "${QTDIR}\plugins\imageformats\qtga.dll" File /r "${QTDIR}\plugins\imageformats\qtiff.dll" diff --git a/build_scripts/Windows/make_installer.bat b/build_scripts/Windows/make_installer.bat deleted file mode 100644 index 556680da8..000000000 --- a/build_scripts/Windows/make_installer.bat +++ /dev/null @@ -1,46 +0,0 @@ -@echo off - -setlocal - -:: Modify variable when makensis.exe doesn't exist in PATH -set NSIS_EXE=makensis.exe - -:: Needed environment variables -set SourceDir=%~dp0..\.. -::set ReleaseDir= -::set QtDir= -::set MinGWDir= - -:: Optional environment variables -::set OutDir= - -:: Build defines for script -set NSIS_PARAM= - -if "%SourceDir%" NEQ "" set NSIS_PARAM=%NSIS_PARAM% /DSOURCEDIR="%SourceDir%" -if "%ReleaseDir%" NEQ "" set NSIS_PARAM=%NSIS_PARAM% /DRELEASEDIR="%ReleaseDir%" -if "%QtDir%" NEQ "" set NSIS_PARAM=%NSIS_PARAM% /DQTDIR="%QtDir%" -if "%MinGWDir%" NEQ "" set NSIS_PARAM=%NSIS_PARAM% /DMINGWDIR="%MinGWDir%" -if "%OutDir%" NEQ "" set NSIS_PARAM=%NSIS_PARAM% /DOUTDIR="%OutDir%" - -:: Scan version from source -set Revision= -set BuildAdd= -call "%~dp0GetRsVersion.bat" RS_REVISION_STRING Revision -if errorlevel 1 goto exit -call "%~dp0GetRsVersion.bat" RS_BUILD_NUMBER_ADD BuildAdd -if errorlevel 1 goto exit - -if "%Revision%"=="" ( - echo. - echo Version not found - goto exit -) - -set NSIS_PARAM=%NSIS_PARAM% /DREVISION=%Revision% /DBUILDADD=%BuildAdd% - -:: Create installer -"%NSIS_EXE%" %NSIS_PARAM% "%~dp0retroshare.nsi" - -:exit -endlocal diff --git a/build_scripts/Windows/tools/depends.bat b/build_scripts/Windows/tools/depends.bat new file mode 100644 index 000000000..3f1bb3d08 --- /dev/null +++ b/build_scripts/Windows/tools/depends.bat @@ -0,0 +1,37 @@ +:: Usage: +:: call depends.bat [list^|missing] file + +setlocal + +if "%2"=="" ( + echo Usage: %~nx0 [list^|missing] File + goto :exit +) + +if not exist "%EnvDependsExe%" echo depends.exe not found in %EnvToolsPath%.& goto exit +if not exist "%EnvCutExe%" echo cut.exe not found in %EnvToolsPath%.& goto exit + +start /wait "" "%EnvDependsExe%" /c /oc:"%~dp0depends.tmp" %2 +if "%1"=="missing" ( + "%EnvCutExe%" --delimiter=, --fields=1,2 "%~dp0depends.tmp" >"%~dp0depends1.tmp" + for /F "tokens=1,2 delims=," %%A in (%~sdp0depends1.tmp) do ( + if "%%A"=="?" ( + echo %%~B + ) + ) +) + +if "%1"=="list" ( + "%EnvCutExe%" --delimiter=, --fields=2 "%~dp0depends.tmp" >"%~dp0depends1.tmp" + for /F "tokens=1 delims=," %%A in (%~sdp0depends1.tmp) do ( + if "%%A" NEQ "Module" ( + echo %%~A + ) + ) +) + +if exist "%~dp0depends.tmp" del /Q "%~dp0depends.tmp" +if exist "%~dp0depends1.tmp" del /Q "%~dp0depends1.tmp" + +:exit +endlocal diff --git a/build_scripts/Windows/tools/find-in-path.bat b/build_scripts/Windows/tools/find-in-path.bat new file mode 100644 index 000000000..0ee7407bf --- /dev/null +++ b/build_scripts/Windows/tools/find-in-path.bat @@ -0,0 +1,26 @@ +:: Usage: +:: call find-in-path.bat variable file + +setlocal + +set Var=%~1 +set File=%~2 + +if "%File%"=="" ( + echo. + echo Parameter error. + exit /B 1 +) + +set FoundPath= + +SET PathTemp="%Path:;=";"%" +FOR %%P IN (%PathTemp%) DO ( + IF EXIST "%%~P.\%File%" ( + set FoundPath=%%~P + goto :found + ) +) + +:found +endlocal & set %Var%=%FoundPath% diff --git a/build_scripts/Windows/tools/get-gcc-version.bat b/build_scripts/Windows/tools/get-gcc-version.bat new file mode 100644 index 000000000..c9998376b --- /dev/null +++ b/build_scripts/Windows/tools/get-gcc-version.bat @@ -0,0 +1,42 @@ +:: Usage: +:: call get-gcc-version.bat variable + +setlocal + +set Var=%~1 +if "%Var%"=="" ( + echo. + echo Parameter error. + exit /B 1 +) + +set GCCVersion= + +call "%~dp0find-in-path.bat" GCCPath gcc.exe +if "%GCCPath%"=="" ( + echo. + echo Cannot find gcc.exe in PATH. + goto exit +) + +gcc --version >"%~dp0gccversion.tmp" +for /F "tokens=1*" %%A in (%~sdp0gccversion.tmp) do ( + if "%%A"=="gcc" ( + call :find_version %%B + goto exit + ) +) + +:exit +if exist "%~dp0gccversion.tmp" del /Q "%~dp0gccversion.tmp" + +endlocal & set %Var%=%GCCVersion% +goto :EOF + +:find_version +:loop +if "%2" NEQ "" ( + shift + goto loop +) +set GCCVersion=%1 diff --git a/build_scripts/Windows/tools/get-git-ref.bat b/build_scripts/Windows/tools/get-git-ref.bat new file mode 100644 index 000000000..f8f6efdeb --- /dev/null +++ b/build_scripts/Windows/tools/get-git-ref.bat @@ -0,0 +1,39 @@ +REM Usage: +REM call get-git-ref.bat Variable [Branch] + +setlocal + +set Variable=%~1 +if "%Variable%"=="" ( + echo. + echo Parameter error + exit /B 1 +) + +set Ref= + +:: Check git executable +set GitPath= +call "%~dp0find-in-path.bat" GitPath git.exe +if "%GitPath%"=="" ( + echo. + echo Git executable not found in PATH. + goto exit +) + +set GitParameter= +set Branch=%~2 +if "%Branch%"=="" ( + set Branch=HEAD + set GitParameter=--head +) + +for /F "tokens=1*" %%A in ('git show-ref %GitParameter% %Branch%') do ( + if "%%B"=="%Branch%" ( + set Ref=%%A + ) +) + +:exit +endlocal & set %Variable%=%Ref% +exit /B 0 diff --git a/build_scripts/Windows/tools/get-qt-version.bat b/build_scripts/Windows/tools/get-qt-version.bat new file mode 100644 index 000000000..c49939970 --- /dev/null +++ b/build_scripts/Windows/tools/get-qt-version.bat @@ -0,0 +1,34 @@ +:: Usage: +:: call get-qt-version.bat variable + +setlocal + +set Var=%~1 +if "%Var%"=="" ( + echo. + echo Parameter error. + exit /B 1 +) + +set QtVersion= + +call "%~dp0find-in-path.bat" QMakePath qmake.exe +if "%QMakePath%"=="" ( + echo. + echo Cannot find qmake.exe in PATH. + goto exit +) + +qmake.exe -version >"%~dp0qtversion.tmp" +for /F "tokens=1,2,3,4" %%A in (%~sdp0qtversion.tmp) do ( + if "%%A"=="Using" ( + set QtVersion=%%D + goto exit + ) +) + +:exit +if exist "%~dp0qtversion.tmp" del /Q "%~dp0qtversion.tmp" + +endlocal & set %Var%=%QtVersion% +exit /B 0 \ No newline at end of file diff --git a/build_scripts/Windows/GetRsVersion.bat b/build_scripts/Windows/tools/get-rs-version.bat similarity index 54% rename from build_scripts/Windows/GetRsVersion.bat rename to build_scripts/Windows/tools/get-rs-version.bat index 153b5969d..c99ded405 100644 --- a/build_scripts/Windows/GetRsVersion.bat +++ b/build_scripts/Windows/tools/get-rs-version.bat @@ -1,33 +1,23 @@ -@:: Usage: -@:: call GetRsVersion.bat Define Variable +:: Usage: +:: call get-rs-version.bat Define Variable -@setlocal -@echo off +setlocal set Define=%~1 -if "%Define%"=="" ( - echo. - echo Parameter error - endlocal - exit /B1 -) - set Variable=%~2 if "%Variable%"=="" ( echo. - echo Parameter error - endlocal - exit /B1 + echo Parameter error. + exit /B 1 ) set Result= -set VersionFile="%~dp0..\..\libretroshare\src\retroshare\rsversion.h" +set VersionFile="%~dp0..\..\..\libretroshare\src\retroshare\rsversion.h" if not exist "%VersionFile%" ( echo. echo Version file doesn't exist. echo %VersionFile% - endlocal exit /B1 ) diff --git a/build_scripts/Windows/tools/msys-path.bat b/build_scripts/Windows/tools/msys-path.bat new file mode 100644 index 000000000..3b0c5fd69 --- /dev/null +++ b/build_scripts/Windows/tools/msys-path.bat @@ -0,0 +1,20 @@ +:: Usage: +:: call msys-path.bat path variable + +setlocal + +set WinPath=%~1 +set MSYSVar=%~2 + +if "%MSYSVar%"=="" ( + echo. + echo Parameter error. + exit /B 1 +) + +set MSYSPath=/%WinPath:~0,1%/%WinPath:~3% +set MSYSPath=%MSYSPath:\=/% + +endlocal & set %MSYSVar%=%MSYSPath% + +exit /B 0 diff --git a/build_scripts/Windows/tools/remove-dir.bat b/build_scripts/Windows/tools/remove-dir.bat new file mode 100644 index 000000000..2bcb14c51 --- /dev/null +++ b/build_scripts/Windows/tools/remove-dir.bat @@ -0,0 +1,15 @@ +:: Usage: +:: call remove-dir.bat path + +if "%~1"=="" ( + echo. + echo Parameter error. + exit /B 1 +) + +if exist %1 ( + del /s /f /q %1 >nul + rmdir /s /q %1 +) + +exit /B 0 diff --git a/build_scripts/Windows/build_libs/Tools/winhttpjs.bat b/build_scripts/Windows/tools/winhttpjs.bat similarity index 100% rename from build_scripts/Windows/build_libs/Tools/winhttpjs.bat rename to build_scripts/Windows/tools/winhttpjs.bat diff --git a/libresapi/src/api/IdentityHandler.cpp b/libresapi/src/api/IdentityHandler.cpp index 6d017fad8..f707e3596 100644 --- a/libresapi/src/api/IdentityHandler.cpp +++ b/libresapi/src/api/IdentityHandler.cpp @@ -29,7 +29,7 @@ private: std::vector mIds; StateToken mStateToken; protected: - virtual void gxsDoWork(Request &req, Response &resp) + virtual void gxsDoWork(Request& /*req*/, Response &resp) { resp.mDataStream.getStreamToMember(); for(std::vector::iterator vit = mIds.begin(); vit != mIds.end(); ++vit) diff --git a/libresapi/src/api/json.cpp b/libresapi/src/api/json.cpp index d921e6b80..2bcec7e81 100644 --- a/libresapi/src/api/json.cpp +++ b/libresapi/src/api/json.cpp @@ -824,7 +824,6 @@ static Value DeserializeValue(std::string& str, bool* had_error, std::stack& subdirs) +bool InternalFileHierarchyStorage::updateSubDirectoryList(const DirectoryStorage::EntryIndex& indx,const std::map& subdirs,const RsFileHash& random_hash_seed) { if(!checkIndex(indx,FileStorageNode::TYPE_DIR)) return false; @@ -188,9 +188,9 @@ bool InternalFileHierarchyStorage::updateSubDirectoryList(const DirectoryStorage de->row = mNodes.size(); de->parent_index = indx; - de->dir_modtime = it->second; - de->dir_parent_path = d.dir_parent_path + "/" + d.dir_name ; - de->dir_hash = createDirHash(de->dir_name,de->dir_parent_path) ; + de->dir_modtime = 0;// forces parsing.it->second; + de->dir_parent_path = RsDirUtil::makePath(d.dir_parent_path, d.dir_name) ; + de->dir_hash = createDirHash(de->dir_name,d.dir_hash,random_hash_seed) ; mDirHashes[de->dir_hash] = mNodes.size() ; @@ -201,7 +201,7 @@ bool InternalFileHierarchyStorage::updateSubDirectoryList(const DirectoryStorage return true; } -RsFileHash InternalFileHierarchyStorage::createDirHash(const std::string &/*dir_name*/, const std::string &/*dir_parent_path*/) +RsFileHash InternalFileHierarchyStorage::createDirHash(const std::string& dir_name, const RsFileHash& dir_parent_hash, const RsFileHash& random_hash_salt) { // What we need here: a unique identifier // - that cannot be bruteforced to find the real directory name and path @@ -215,7 +215,19 @@ RsFileHash InternalFileHierarchyStorage::createDirHash(const std::string &/*dir_ // Option 3: just compute something random, but then we need to store it so as to not // confuse friends when restarting. - return RsFileHash::random(); + RsTemporaryMemory mem(dir_name.size() + 2*RsFileHash::SIZE_IN_BYTES) ; + + memcpy( mem, random_hash_salt.toByteArray(),RsFileHash::SIZE_IN_BYTES) ; + memcpy(&mem[ RsFileHash::SIZE_IN_BYTES], dir_parent_hash.toByteArray(),RsFileHash::SIZE_IN_BYTES) ; + memcpy(&mem[2*RsFileHash::SIZE_IN_BYTES],dir_name.c_str(), dir_name.size()) ; + + RsFileHash res = RsDirUtil::sha1sum( mem,mem.size() ) ; + +#ifdef DEBUG_DIRECTORY_STORAGE + std::cerr << "Creating new dir hash for dir " << dir_name << ", parent dir hash=" << dir_parent_hash << " seed=[hidden]" << " result is " << res << std::endl; +#endif + + return res ; } bool InternalFileHierarchyStorage::removeDirectory(DirectoryStorage::EntryIndex indx) // no reference here! Very important. Otherwise, the messign we do inside can change the value of indx!! @@ -434,7 +446,7 @@ bool InternalFileHierarchyStorage::updateDirEntry(const DirectoryStorage::EntryI mNodes[dir_index] = de ; - de->dir_parent_path = d.dir_parent_path + "/" + dir_name ; + de->dir_parent_path = RsDirUtil::makePath(d.dir_parent_path, dir_name) ; de->dir_hash = subdirs_hash[i]; mDirHashes[subdirs_hash[i]] = dir_index ; @@ -675,7 +687,7 @@ public: inline virtual uint64_t file_size() const { return mFe.file_size ; } inline virtual const RsFileHash& file_hash() const { return mFe.file_hash ; } inline virtual time_t file_modtime() const { return mFe.file_modtime ; } - inline virtual std::string file_parent_path()const { return mDe.dir_parent_path + "/" + mDe.dir_name ; } + inline virtual std::string file_parent_path()const { return RsDirUtil::makePath(mDe.dir_parent_path, mDe.dir_name) ; } inline virtual uint32_t file_popularity() const { NOT_IMPLEMENTED() ; return 0; } private: @@ -1123,7 +1135,9 @@ bool InternalFileHierarchyStorage::load(const std::string& fname) } catch(read_error& e) { +#ifdef DEBUG_DIRECTORY_STORAGE std::cerr << "Error while reading: " << e.what() << std::endl; +#endif if(buffer != NULL) free(buffer) ; diff --git a/libretroshare/src/file_sharing/dir_hierarchy.h b/libretroshare/src/file_sharing/dir_hierarchy.h index dd1454b91..c6e59b9f8 100644 --- a/libretroshare/src/file_sharing/dir_hierarchy.h +++ b/libretroshare/src/file_sharing/dir_hierarchy.h @@ -95,7 +95,7 @@ public: int parentRow(DirectoryStorage::EntryIndex e); bool isIndexValid(DirectoryStorage::EntryIndex e) const; bool getChildIndex(DirectoryStorage::EntryIndex e,int row,DirectoryStorage::EntryIndex& c) const; - bool updateSubDirectoryList(const DirectoryStorage::EntryIndex& indx,const std::map& subdirs); + bool updateSubDirectoryList(const DirectoryStorage::EntryIndex& indx, const std::map& subdirs, const RsFileHash &random_hash_seed); bool removeDirectory(DirectoryStorage::EntryIndex indx) ; bool checkIndex(DirectoryStorage::EntryIndex indx,uint8_t type) const; bool updateSubFilesList(const DirectoryStorage::EntryIndex& indx,const std::map& subfiles,std::map& new_files); @@ -153,7 +153,7 @@ public: private: void recursPrint(int depth,DirectoryStorage::EntryIndex node) const; static bool nodeAccessError(const std::string& s); - static RsFileHash createDirHash(const std::string& dir_name,const std::string& dir_parent_path) ; + static RsFileHash createDirHash(const std::string& dir_name, const RsFileHash &dir_parent_hash, const RsFileHash &random_hash_salt) ; // Allocates a new entry in mNodes, possible re-using an empty slot and returns its index. diff --git a/libretroshare/src/file_sharing/directory_storage.cc b/libretroshare/src/file_sharing/directory_storage.cc index e4633ff72..950e37e30 100644 --- a/libretroshare/src/file_sharing/directory_storage.cc +++ b/libretroshare/src/file_sharing/directory_storage.cc @@ -127,10 +127,10 @@ bool DirectoryStorage::setDirectoryUpdateTime (EntryIndex index,time_t update bool DirectoryStorage::setDirectoryRecursModTime(EntryIndex index,time_t rec_md_TS) { RS_STACK_MUTEX(mDirStorageMtx) ; return mFileHierarchy->setTS(index,rec_md_TS,&InternalFileHierarchyStorage::DirEntry::dir_most_recent_time); } bool DirectoryStorage::setDirectoryLocalModTime (EntryIndex index,time_t loc_md_TS) { RS_STACK_MUTEX(mDirStorageMtx) ; return mFileHierarchy->setTS(index,loc_md_TS,&InternalFileHierarchyStorage::DirEntry::dir_modtime ); } -bool DirectoryStorage::updateSubDirectoryList(const EntryIndex& indx,const std::map& subdirs) +bool DirectoryStorage::updateSubDirectoryList(const EntryIndex& indx,const std::map& subdirs,const RsFileHash& hash_salt) { RS_STACK_MUTEX(mDirStorageMtx) ; - bool res = mFileHierarchy->updateSubDirectoryList(indx,subdirs) ; + bool res = mFileHierarchy->updateSubDirectoryList(indx,subdirs,hash_salt) ; locked_check() ; return res ; } @@ -168,10 +168,10 @@ bool DirectoryStorage::updateHash(const EntryIndex& index,const RsFileHash& hash return mFileHierarchy->updateHash(index,hash); } -void DirectoryStorage::load(const std::string& local_file_name) +bool DirectoryStorage::load(const std::string& local_file_name) { RS_STACK_MUTEX(mDirStorageMtx) ; - mFileHierarchy->load(local_file_name); + return mFileHierarchy->load(local_file_name); } void DirectoryStorage::save(const std::string& local_file_name) { @@ -238,7 +238,7 @@ bool DirectoryStorage::extractData(const EntryIndex& indx,DirDetails& d) d.min_age = now - dir_entry->dir_most_recent_time ; d.age = now - dir_entry->dir_modtime ; d.name = dir_entry->dir_name; - d.path = dir_entry->dir_parent_path + "/" + dir_entry->dir_name ; + d.path = RsDirUtil::makePath(dir_entry->dir_parent_path, dir_entry->dir_name) ; d.parent = (void*)(intptr_t)dir_entry->parent_index ; if(indx == 0) @@ -262,7 +262,7 @@ bool DirectoryStorage::extractData(const EntryIndex& indx,DirDetails& d) const InternalFileHierarchyStorage::DirEntry *parent_dir_entry = mFileHierarchy->getDirEntry(file_entry->parent_index); if(parent_dir_entry != NULL) - d.path = parent_dir_entry->dir_parent_path + "/" + parent_dir_entry->dir_name + "/" ; + d.path = RsDirUtil::makePath(parent_dir_entry->dir_parent_path, parent_dir_entry->dir_name) ; else d.path = "" ; } @@ -770,6 +770,7 @@ void RemoteDirectoryStorage::checkSave() { save(mFileName); mLastSavedTime = now ; + mChanged = false ; } } diff --git a/libretroshare/src/file_sharing/directory_storage.h b/libretroshare/src/file_sharing/directory_storage.h index 09a46c2d7..4d4e5df97 100644 --- a/libretroshare/src/file_sharing/directory_storage.h +++ b/libretroshare/src/file_sharing/directory_storage.h @@ -132,7 +132,7 @@ class DirectoryStorage // Sets the subdirectory/subfiles list of entry indx the supplied one, possible adding and removing directories (resp.files). New directories are set empty with // just a name and need to be updated later on. New files are returned in a list so that they can be sent to hash cache. // - bool updateSubDirectoryList(const EntryIndex& indx, const std::map &subdirs) ; + bool updateSubDirectoryList(const EntryIndex& indx, const std::map &subdirs, const RsFileHash &random_hash_salt) ; bool updateSubFilesList(const EntryIndex& indx, const std::map &subfiles, std::map &new_files) ; bool removeDirectory(const EntryIndex& indx) ; @@ -153,7 +153,7 @@ class DirectoryStorage void cleanup(); protected: - void load(const std::string& local_file_name) ; + bool load(const std::string& local_file_name) ; void save(const std::string& local_file_name) ; private: diff --git a/libretroshare/src/file_sharing/directory_updater.cc b/libretroshare/src/file_sharing/directory_updater.cc index 0a656417a..de92c6ee1 100644 --- a/libretroshare/src/file_sharing/directory_updater.cc +++ b/libretroshare/src/file_sharing/directory_updater.cc @@ -55,7 +55,7 @@ void LocalDirectoryUpdater::setEnabled(bool b) return ; if(b) - start("fs dir updater") ; + start("fs dir updater") ; else shutdown(); @@ -88,17 +88,23 @@ void LocalDirectoryUpdater::forceUpdate() void LocalDirectoryUpdater::sweepSharedDirectories() { + if(mHashSalt.isNull()) + { + std::cerr << "(EE) no salt value in LocalDirectoryUpdater. Is that a bug?" << std::endl; + return ; + } + RsServer::notify()->notifyListPreChange(NOTIFY_LIST_DIRLIST_LOCAL, 0); #ifdef DEBUG_LOCAL_DIR_UPDATER std::cerr << "[directory storage] LocalDirectoryUpdater::sweep()" << std::endl; #endif - // recursive update algorithm works that way: - // - the external loop starts on the shared directory list and goes through sub-directories + // recursive update algorithm works that way: + // - the external loop starts on the shared directory list and goes through sub-directories // - at the same time, it updates the local list of shared directories. A single sweep is performed over the whole directory structure. - // - the information that is costly to compute (the hash) is store externally into a separate structure. - // - doing so, changing directory names or moving files between directories does not cause a re-hash of the content. - // + // - the information that is costly to compute (the hash) is store externally into a separate structure. + // - doing so, changing directory names or moving files between directories does not cause a re-hash of the content. + // std::list shared_directory_list ; mSharedDirectories->getSharedDirectoryList(shared_directory_list); @@ -109,7 +115,7 @@ void LocalDirectoryUpdater::sweepSharedDirectories() // make sure that entries in stored_dir_it are the same than paths in real_dir_it, and in the same order. - mSharedDirectories->updateSubDirectoryList(mSharedDirectories->root(),sub_dir_list) ; + mSharedDirectories->updateSubDirectoryList(mSharedDirectories->root(),sub_dir_list,mHashSalt) ; // now for each of them, go recursively and match both files and dirs @@ -137,59 +143,71 @@ void LocalDirectoryUpdater::recursUpdateSharedDir(const std::string& cumulated_p librs::util::FolderIterator dirIt(cumulated_path); - // collect subdirs and subfiles - - std::map subfiles ; - std::map subdirs ; - - for(;dirIt.isValid();dirIt.next()) + time_t dir_local_mod_time ; + if(!mSharedDirectories->getDirectoryLocalModTime(indx,dir_local_mod_time)) { - switch(dirIt.file_type()) - { - case librs::util::FolderIterator::TYPE_FILE: subfiles[dirIt.file_name()].modtime = dirIt.file_modtime() ; - subfiles[dirIt.file_name()].size = dirIt.file_size(); -#ifdef DEBUG_LOCAL_DIR_UPDATER - std::cerr << " adding sub-file \"" << dirIt.file_name() << "\"" << std::endl; -#endif - break; - - case librs::util::FolderIterator::TYPE_DIR: subdirs[dirIt.file_name()] = dirIt.file_modtime(); -#ifdef DEBUG_LOCAL_DIR_UPDATER - std::cerr << " adding sub-dir \"" << dirIt.file_name() << "\"" << std::endl; -#endif - break; - default: - std::cerr << "(EE) Dir entry of unknown type with path \"" << cumulated_path << "/" << dirIt.file_name() << "\"" << std::endl; - } + std::cerr << "(EE) Cannot get local mod time for dir index " << indx << std::endl; + return; } - // update folder modificatoin time, which is the only way to detect e.g. removed or renamed files. - mSharedDirectories->setDirectoryLocalModTime(indx,dirIt.dir_modtime()) ; - - // update file and dir lists for current directory. - - mSharedDirectories->updateSubDirectoryList(indx,subdirs) ; - - std::map new_files ; - mSharedDirectories->updateSubFilesList(indx,subfiles,new_files) ; - - // now go through list of subfiles and request the hash to hashcache - - for(DirectoryStorage::FileIterator dit(mSharedDirectories,indx);dit;++dit) + if(dirIt.dir_modtime() != dir_local_mod_time) { - // ask about the hash. If not present, ask HashCache. If not present, or different, the callback will update it. + // collect subdirs and subfiles - RsFileHash hash ; + std::map subfiles ; + std::map subdirs ; - if(mHashCache->requestHash(cumulated_path + "/" + dit.name(),dit.size(),dit.modtime(),hash,this,*dit) && dit.hash() != hash) - mSharedDirectories->updateHash(*dit,hash); + for(;dirIt.isValid();dirIt.next()) + { + switch(dirIt.file_type()) + { + case librs::util::FolderIterator::TYPE_FILE: subfiles[dirIt.file_name()].modtime = dirIt.file_modtime() ; + subfiles[dirIt.file_name()].size = dirIt.file_size(); +#ifdef DEBUG_LOCAL_DIR_UPDATER + std::cerr << " adding sub-file \"" << dirIt.file_name() << "\"" << std::endl; +#endif + break; + + case librs::util::FolderIterator::TYPE_DIR: subdirs[dirIt.file_name()] = dirIt.file_modtime(); +#ifdef DEBUG_LOCAL_DIR_UPDATER + std::cerr << " adding sub-dir \"" << dirIt.file_name() << "\"" << std::endl; +#endif + break; + default: + std::cerr << "(EE) Dir entry of unknown type with path \"" << cumulated_path << "/" << dirIt.file_name() << "\"" << std::endl; + } + } + // update folder modificatoin time, which is the only way to detect e.g. removed or renamed files. + + mSharedDirectories->setDirectoryLocalModTime(indx,dirIt.dir_modtime()) ; + + // update file and dir lists for current directory. + + mSharedDirectories->updateSubDirectoryList(indx,subdirs,mHashSalt) ; + + std::map new_files ; + mSharedDirectories->updateSubFilesList(indx,subfiles,new_files) ; + + // now go through list of subfiles and request the hash to hashcache + + for(DirectoryStorage::FileIterator dit(mSharedDirectories,indx);dit;++dit) + { + // ask about the hash. If not present, ask HashCache. If not present, or different, the callback will update it. + + RsFileHash hash ; + + if(mHashCache->requestHash(cumulated_path + "/" + dit.name(),dit.size(),dit.modtime(),hash,this,*dit) && dit.hash() != hash) + mSharedDirectories->updateHash(*dit,hash); + } } +#ifdef DEBUG_LOCAL_DIR_UPDATER + else + std::cerr << " directory is unchanged. Keeping existing files and subdirs list." << std::endl; +#endif // go through the list of sub-dirs and recursively update - DirectoryStorage::DirIterator stored_dir_it(mSharedDirectories,indx) ; - - for(std::map::const_iterator real_dir_it(subdirs.begin());real_dir_it!=subdirs.end();++real_dir_it, ++stored_dir_it) + for(DirectoryStorage::DirIterator stored_dir_it(mSharedDirectories,indx) ; stored_dir_it; ++stored_dir_it) { #ifdef DEBUG_LOCAL_DIR_UPDATER std::cerr << " recursing into " << stored_dir_it.name() << std::endl; diff --git a/libretroshare/src/file_sharing/directory_updater.h b/libretroshare/src/file_sharing/directory_updater.h index d0f920cb0..85df00d6c 100644 --- a/libretroshare/src/file_sharing/directory_updater.h +++ b/libretroshare/src/file_sharing/directory_updater.h @@ -41,6 +41,9 @@ public: void forceUpdate(); bool inDirectoryCheck() const ; + void setHashSalt(const RsFileHash& hash) { mHashSalt = hash; } + const RsFileHash& hashSalt() const { return mHashSalt; } + void setFileWatchPeriod(int seconds) ; uint32_t fileWatchPeriod() const ; @@ -60,6 +63,8 @@ private: HashStorage *mHashCache ; LocalDirectoryStorage *mSharedDirectories ; + RsFileHash mHashSalt ; + time_t mLastSweepTime; time_t mLastTSUpdateTime; diff --git a/libretroshare/src/file_sharing/file_sharing_defaults.h b/libretroshare/src/file_sharing/file_sharing_defaults.h index 94e2981f7..520fc61ea 100644 --- a/libretroshare/src/file_sharing/file_sharing_defaults.h +++ b/libretroshare/src/file_sharing/file_sharing_defaults.h @@ -33,6 +33,7 @@ static const uint32_t DELAY_BETWEEN_LOCAL_DIRECTORIES_TS_UPDATE = 20 ; // 20 se static const std::string HASH_CACHE_DURATION_SS = "HASH_CACHE_DURATION" ; // key string to store hash remembering time static const std::string WATCH_FILE_DURATION_SS = "WATCH_FILES_DELAY" ; // key to store delay before re-checking for new files static const std::string WATCH_FILE_ENABLED_SS = "WATCH_FILES_ENABLED"; // key to store ON/OFF flags for file whatch +static const std::string WATCH_HASH_SALT_SS = "WATCH_HASH_SALT"; // Salt that is used to hash directory names static const std::string FILE_SHARING_DIR_NAME = "file_sharing" ; // hard-coded directory name to store friend file lists, hash cache, etc. static const std::string HASH_CACHE_FILE_NAME = "hash_cache.bin" ; // hard-coded directory name to store encrypted hash cache. diff --git a/libretroshare/src/file_sharing/filelist_io.cc b/libretroshare/src/file_sharing/filelist_io.cc index 8a1693c46..7be770c82 100644 --- a/libretroshare/src/file_sharing/filelist_io.cc +++ b/libretroshare/src/file_sharing/filelist_io.cc @@ -190,7 +190,9 @@ bool FileListIO::loadEncryptedDataFromFile(const std::string& fname,unsigned cha if(!RsDirUtil::checkFile( fname,file_size,false ) ) { +#ifdef FIM_DEBUG std::cerr << "Encrypted file " << fname << " not available." << std::endl; +#endif return false; } diff --git a/libretroshare/src/file_sharing/hash_cache.cc b/libretroshare/src/file_sharing/hash_cache.cc index abca37add..200a0de4d 100644 --- a/libretroshare/src/file_sharing/hash_cache.cc +++ b/libretroshare/src/file_sharing/hash_cache.cc @@ -76,7 +76,7 @@ void HashStorage::data_tick() { FileHashJob job; RsFileHash hash; - uint64_t size ; + uint64_t size = 0; { bool empty ; @@ -270,7 +270,7 @@ void HashStorage::clean() #endif for(std::map::iterator it(mFiles.begin());it!=mFiles.end();) - if(it->second.time_stamp + duration < (uint64_t)now) + if((uint64_t)(it->second.time_stamp + duration) < (uint64_t)now) { #ifdef HASHSTORAGE_DEBUG std::cerr << " Entry too old: " << it->first << ", ts=" << it->second.time_stamp << std::endl ; diff --git a/libretroshare/src/file_sharing/p3filelists.cc b/libretroshare/src/file_sharing/p3filelists.cc index 7aa9c5316..c14c6df35 100644 --- a/libretroshare/src/file_sharing/p3filelists.cc +++ b/libretroshare/src/file_sharing/p3filelists.cc @@ -224,7 +224,7 @@ int p3FileDatabase::tick() mLastRemoteDirSweepTS = now; - // This is a hash to make loaded directories show up in the GUI, because the GUI generally isn't ready at the time they are actually loaded up, + // This is a hack to make loaded directories show up in the GUI, because the GUI generally isn't ready at the time they are actually loaded up, // so the first notify is ignored, and no other notify will happen next. RsServer::notify()->notifyListChange(NOTIFY_LIST_DIRLIST_FRIENDS, 0); @@ -326,7 +326,14 @@ cleanup = true; rskv->tlvkvs.pairs.push_back(kv); } + { + RsTlvKeyValue kv; + kv.key = WATCH_HASH_SALT_SS; + kv.value = mLocalDirWatcher->hashSalt().toStdString(); + + rskv->tlvkvs.pairs.push_back(kv); + } /* Add KeyValue to saveList */ sList.push_back(rskv); @@ -373,6 +380,11 @@ bool p3FileDatabase::loadList(std::list& load) { setWatchEnabled(kit->value == "YES") ; } + else if(kit->key == WATCH_HASH_SALT_SS) + { + std::cerr << "Initing directory watcher with saved secret salt..." << std::endl; + mLocalDirWatcher->setHashSalt(RsFileHash(kit->value)) ; + } delete *it ; continue ; } @@ -397,6 +409,14 @@ bool p3FileDatabase::loadList(std::list& load) delete *it ; } + if(mLocalDirWatcher->hashSalt().isNull()) + { + std::cerr << "(WW) Initialising directory watcher salt to some random value " << std::endl; + mLocalDirWatcher->setHashSalt(RsFileHash::random()) ; + + IndicateConfigChanged(); + } + /* set directories */ mLocalSharedDirs->setSharedDirectoryList(dirList); @@ -620,12 +640,9 @@ void p3FileDatabase::requestDirUpdate(void *ref) } } -bool p3FileDatabase::findChildPointer(void *ref, int row, void *& result, FileSearchFlags flags) const +bool p3FileDatabase::findChildPointer( void *ref, int row, void *& result, + FileSearchFlags flags ) const { - RS_STACK_MUTEX(mFLSMtx) ; - - result = NULL ; - if (ref == NULL) { if(flags & RS_FILE_HINTS_LOCAL) @@ -668,8 +685,8 @@ bool p3FileDatabase::findChildPointer(void *ref, int row, void *& result, FileSe return res; } -// This function converts a pointer into directory details, to be used by the AbstractItemModel for browsing the files. +// This function converts a pointer into directory details, to be used by the AbstractItemModel for browsing the files. int p3FileDatabase::RequestDirDetails(void *ref, DirDetails& d, FileSearchFlags flags) const { RS_STACK_MUTEX(mFLSMtx) ; @@ -1130,7 +1147,9 @@ void p3FileDatabase::handleDirSyncRequest(RsFileListsSyncRequestItem *item) if(!mLocalSharedDirs->getIndexFromDirHash(item->entry_hash,entry_index)) { - P3FILELISTS_ERROR() << " (EE) Cannot find entry index for hash " << item->entry_hash << ": cannot respond to sync request." << std::endl; +#ifdef DEBUG_P3FILELISTS + P3FILELISTS_DEBUG() << " (EE) Cannot find entry index for hash " << item->entry_hash << ": cannot respond to sync request." << std::endl; +#endif return; } diff --git a/libretroshare/src/ft/ftcontroller.cc b/libretroshare/src/ft/ftcontroller.cc index 94d252ddf..4270da3d2 100644 --- a/libretroshare/src/ft/ftcontroller.cc +++ b/libretroshare/src/ft/ftcontroller.cc @@ -728,14 +728,13 @@ bool ftController::completeFile(const RsFileHash& hash) std::string path; std::string name; uint64_t size = 0; - uint32_t state = 0; uint32_t period = 0; TransferRequestFlags flags ; TransferRequestFlags extraflags ; uint32_t completeCount = 0; { - RsStackMutex stack(ctrlMutex); /******* LOCKED ********/ + RS_STACK_MUTEX(ctrlMutex); #ifdef CONTROL_DEBUG std::cerr << "ftController:completeFile(" << hash << ")"; @@ -817,7 +816,6 @@ bool ftController::completeFile(const RsFileHash& hash) name = fc->mName; //hash = fc->mHash; size = fc->mSize; - state = fc->mState; period = 30 * 24 * 3600; /* 30 days */ extraflags.clear() ; @@ -838,7 +836,7 @@ bool ftController::completeFile(const RsFileHash& hash) if(flags & RS_FILE_REQ_ANONYMOUS_ROUTING) mFtServer->activateTunnels(hash_to_suppress,flags,false); - } /******* UNLOCKED ********/ + } // UNLOCK: RS_STACK_MUTEX(ctrlMutex); /******************** NO Mutex from Now ******************** diff --git a/libretroshare/src/gxs/rsgenexchange.cc b/libretroshare/src/gxs/rsgenexchange.cc index d2ebedd85..3ff86cdf6 100644 --- a/libretroshare/src/gxs/rsgenexchange.cc +++ b/libretroshare/src/gxs/rsgenexchange.cc @@ -1691,7 +1691,7 @@ void RsGenExchange::processMsgMetaChanges() { MsgLocMetaData& m = mit->second; - int32_t value, mask; + int32_t value, mask; bool ok = true; bool changed = false; @@ -1717,7 +1717,7 @@ void RsGenExchange::processMsgMetaChanges() { RsGxsMsgMetaData* meta = *(msgMetaV.begin()); value = (meta->mMsgStatus & ~mask) | (mask & value); - changed = (meta->mMsgStatus != value); + changed = (static_cast(meta->mMsgStatus) != value); m.val.put(RsGeneralDataService::MSG_META_STATUS, value); delete meta; ok = true; @@ -2822,10 +2822,8 @@ void RsGenExchange::processRecvdMessages() mNetService->rejectMessage(*it) ; } -bool RsGenExchange::acceptNewGroup(const RsGxsGrpMetaData *grpMeta) -{ - return true; -} +bool RsGenExchange::acceptNewGroup(const RsGxsGrpMetaData* /*grpMeta*/ ) +{ return true; } void RsGenExchange::processRecvdGroups() { diff --git a/libretroshare/src/plugins/pluginmanager.cc b/libretroshare/src/plugins/pluginmanager.cc index 98335ea5a..19980c812 100644 --- a/libretroshare/src/plugins/pluginmanager.cc +++ b/libretroshare/src/plugins/pluginmanager.cc @@ -147,8 +147,7 @@ void RsPluginManager::loadPlugins(const std::vector& plugin_directo for(;dirIt.isValid();dirIt.next()) { - std::string fname; - dirIt.d_name(fname); + std::string fname = dirIt.file_name(); char lc = plugin_directories[i][plugin_directories[i].length()-1] ; // length cannot be 0 here. diff --git a/libretroshare/src/pqi/p3peermgr.cc b/libretroshare/src/pqi/p3peermgr.cc index f37f80b55..f85edb511 100644 --- a/libretroshare/src/pqi/p3peermgr.cc +++ b/libretroshare/src/pqi/p3peermgr.cc @@ -2841,121 +2841,48 @@ bool p3PeerMgrIMPL::removeBannedIps() bool p3PeerMgrIMPL::removeUnusedLocations() { std::list toRemove; - - std::map hasRecentLocation; std::map mostRecentTime; - std::map mostRecentLocation; - - // init maps - { - std::list pgpList; - - if(!rsPeers->getGPGAcceptedList(pgpList)) - return false; - - std::list::iterator it; - for(it = pgpList.begin(); it != pgpList.end(); ++it) - { - hasRecentLocation[*it] = false; - mostRecentTime[*it] = (time_t)0; - } - } const time_t now = time(NULL); - RsPgpId pgpID; - + + std::list pgpList; + + if(!rsPeers->getGPGAcceptedList(pgpList)) + return false; { RsStackMutex stack(mPeerMtx); /****** STACK LOCK MUTEX *******/ + // First put a sensible number in all PGP ids + + for(std::list::const_iterator it = pgpList.begin(); it != pgpList.end(); ++it) + mostRecentTime[*it] = (time_t)0; + #ifdef PEER_DEBUG std::cerr << "p3PeerMgr::removeUnusedLocations()" << std::endl; #endif + // Then compute the most recently used location for all PGP ids - std::map::iterator it; - for(it = mFriendList.begin(); it != mFriendList.end(); ++it) - { - pgpID = it->second.gpg_id; + for( std::map::iterator it = mFriendList.begin(); it != mFriendList.end(); ++it) + { + time_t& bst(mostRecentTime[it->second.gpg_id]) ; + bst = std::max(bst,it->second.lastcontact) ; + } - // store some references to speed up accessing - RsPeerId &idRef = mostRecentLocation[pgpID]; - bool &recentRef = hasRecentLocation[pgpID]; + // And remove all locations that are too old and also older than the most recent location. Doing this we're sure to always keep at least one location per PGP id. - if (now > it->second.lastcontact + RS_PEER_OFFLINE_DELETE) - { - // location is too old - if(recentRef) - { - // there is already one location that won't get removed - // -> we can safely remove this one - toRemove.push_back(it->first); + for( std::map::iterator it = mFriendList.begin(); it != mFriendList.end(); ++it) + { + if (now > it->second.lastcontact + RS_PEER_OFFLINE_DELETE && it->second.lastcontact < mostRecentTime[it->second.gpg_id]) + toRemove.push_back(it->first); #ifdef PEER_DEBUG - std::cerr << "p3PeerMgr::removeUnusedLocations() removing Old SSL Id: " << it->first << std::endl; + std::cerr << "Location " << it->first << " PGP id " << it->second.gpg_id << " last contact " << it->second.lastcontact << " remove: " << (now > it->second.lastcontact + RS_PEER_OFFLINE_DELETE) << " most recent: " << mostRecentTime[it->second.gpg_id] + << ". Final result remove: " << (it->second.lastcontact < mostRecentTime[it->second.gpg_id] && now > it->second.lastcontact + RS_PEER_OFFLINE_DELETE )<< std::endl; #endif - } - else - { - // we need to take care that the most recent location it not removed - time_t &timeRef = mostRecentTime[pgpID]; - - if(timeRef > it->second.lastcontact) - { - // this (it) location is longer offline compared to mostRecentLocation - // -> we can remove this one - toRemove.push_back(it->first); -#ifdef PEER_DEBUG - std::cerr << "p3PeerMgr::removeUnusedLocations() removing Old SSL Id: " << it->first << std::endl; -#endif - } - else - { - // this (it) location is more recent compared to mostRecentLocation - // -> we can remove mostRecentLocation - if(!idRef.isNull()) - { - toRemove.push_back(idRef); -#ifdef PEER_DEBUG - std::cerr << "p3PeerMgr::removeUnusedLocations() removing Old SSL Id: " << it->first << std::endl; -#endif - } - // update maps - idRef = it->first; - timeRef = it->second.lastcontact; - } - } - } - else - { - // found a location that won't get removed - recentRef = true; - - // we can remove mostRecentLocation if it is set - if(!idRef.isNull()) - { - toRemove.push_back(idRef); -#ifdef PEER_DEBUG - std::cerr << "p3PeerMgr::removeUnusedLocations() removing Old SSL Id: " << it->first << std::endl; -#endif - } - } - -// if (isDummyFriend(it->first)) -// { -// toRemove.push_back(it->first); -// -//#ifdef PEER_DEBUG -// std::cerr << "p3PeerMgr::removeUnusedLocations() removing Dummy Id: " << it->first << std::endl; -//#endif -// -// } - - } + } } - std::list::iterator it; - for(it = toRemove.begin(); it != toRemove.end(); ++it) - { - removeFriend(*it, false); - } + for( std::list::iterator it = toRemove.begin(); it != toRemove.end(); ++it) + removeFriend(*it, false); return true; } diff --git a/libretroshare/src/pqi/pqistreamer.cc b/libretroshare/src/pqi/pqistreamer.cc index 9d68a50b2..a96c93148 100644 --- a/libretroshare/src/pqi/pqistreamer.cc +++ b/libretroshare/src/pqi/pqistreamer.cc @@ -76,6 +76,19 @@ static uint8_t PACKET_SLICING_PROBE_BYTES[8] = { 0x02, 0xaa, 0xbb, 0xcc, 0x00, #include "util/rsprint.h" #endif +static double getCurrentTS() +{ +#ifndef WINDOWS_SYS + struct timeval cts_tmp; + gettimeofday(&cts_tmp, NULL); + double cts = (cts_tmp.tv_sec) + ((double) cts_tmp.tv_usec) / 1000000.0; +#else + struct _timeb timebuf; + _ftime( &timebuf); + double cts = (timebuf.time) + ((double) timebuf.millitm) / 1000.0; +#endif + return cts; +} pqistreamer::pqistreamer(RsSerialiser *rss, const RsPeerId& id, BinInterface *bio_in, int bio_flags_in) :PQInterface(id), mStreamerMtx("pqistreamer"), @@ -97,7 +110,9 @@ pqistreamer::pqistreamer(RsSerialiser *rss, const RsPeerId& id, BinInterface *bi mAcceptsPacketSlicing = false ; // by default. Will be turned into true when everyone's ready. mLastSentPacketSlicingProbe = 0 ; - mAvgLastUpdate = mCurrReadTS = mCurrSentTS = time(NULL); + mAvgLastUpdate = time(NULL); + mCurrSentTS = mCurrReadTS = getCurrentTS(); + mIncomingSize = 0 ; mStatisticsTimeStamp = 0 ; @@ -540,7 +555,7 @@ int pqistreamer::handleoutgoing_locked() // if so, we enable it for the session. This should be removed (because it's unnecessary) when all users have switched to the new version. time_t now = time(NULL) ; - if((!mAcceptsPacketSlicing) && now > mLastSentPacketSlicingProbe + PQISTREAM_PACKET_SLICING_PROBE_DELAY) + if(now > mLastSentPacketSlicingProbe + PQISTREAM_PACKET_SLICING_PROBE_DELAY) { #ifdef DEBUG_PACKET_SLICING std::cerr << "(II) Inserting packet slicing probe in traffic" << std::endl; @@ -1099,7 +1114,7 @@ float pqistreamer::outTimeSlice_locked() // very simple..... int pqistreamer::outAllowedBytes_locked() { - int t = time(NULL); // get current timestep. + double t = getCurrentTS() ; // Grabs today's time in sec, with ms accuracy. Allows a much more accurate allocation of bw /* allow a lot if not bandwidthLimited */ if (!mBio->bandwidthLimited()) @@ -1109,17 +1124,18 @@ int pqistreamer::outAllowedBytes_locked() return PQISTREAM_ABS_MAX; } - int dt = t - mCurrSentTS; - // limiter -> for when currSentTs -> 0. - if (dt > 5) - dt = 5; + double dt = t - mCurrSentTS; + + // limiter -> for when currSentTs -> 0. + if (dt > 5) + dt = 5; + + double maxout = getMaxRate(false) * 1024.0; + + mCurrSent -= int(dt * maxout); - int maxout = (int) (getMaxRate(false) * 1000.0); - mCurrSent -= dt * maxout; if (mCurrSent < 0) - { mCurrSent = 0; - } mCurrSentTS = t; @@ -1137,7 +1153,7 @@ int pqistreamer::outAllowedBytes_locked() int pqistreamer::inAllowedBytes_locked() { - int t = time(NULL); // get current timestep. + double t = getCurrentTS(); // in secs, with a ms accuracy /* allow a lot if not bandwidthLimited */ if (!mBio->bandwidthLimited()) @@ -1147,17 +1163,18 @@ int pqistreamer::inAllowedBytes_locked() return PQISTREAM_ABS_MAX; } - int dt = t - mCurrReadTS; + double dt = t - mCurrReadTS; + // limiter -> for when currReadTs -> 0. if (dt > 5) dt = 5; - int maxin = (int) (getMaxRate(true) * 1000.0); - mCurrRead -= dt * maxin; + double maxin = getMaxRate(true) * 1024.0; + + mCurrRead -= int(dt * maxin); + if (mCurrRead < 0) - { mCurrRead = 0; - } mCurrReadTS = t; diff --git a/libretroshare/src/pqi/pqistreamer.h b/libretroshare/src/pqi/pqistreamer.h index 5cdbab9d7..b4351670c 100644 --- a/libretroshare/src/pqi/pqistreamer.h +++ b/libretroshare/src/pqi/pqistreamer.h @@ -159,8 +159,8 @@ class pqistreamer: public PQInterface int mCurrRead; int mCurrSent; - time_t mCurrReadTS; // TS from which these are measured. - time_t mCurrSentTS; + double mCurrReadTS; // TS from which these are measured. + double mCurrSentTS; time_t mAvgLastUpdate; // TS from which these are measured. uint32_t mAvgReadCount; diff --git a/libretroshare/src/rsserver/rsaccounts.cc b/libretroshare/src/rsserver/rsaccounts.cc index 9bb8b49ed..09c3e7d63 100644 --- a/libretroshare/src/rsserver/rsaccounts.cc +++ b/libretroshare/src/rsserver/rsaccounts.cc @@ -536,8 +536,7 @@ bool RsAccountsDetail::getAvailableAccounts(std::map & for(;dirIt.isValid();dirIt.next()) { /* check entry type */ - std::string fname; - dirIt.d_name(fname); + std::string fname = dirIt.file_name(); std::string fullname = mBaseDirectory + "/" + fname; #ifdef FIM_DEBUG std::cerr << "calling stats on " << fullname <::iterator it(mBanRanges.begin());it!=mBanRanges.end();) + for(std::map::iterator it(mBanRanges.begin()); + it!=mBanRanges.end(); ) + { if(it->second.reason == RSBANLIST_REASON_AUTO_RANGE) { std::map::iterator it2=it ; ++it2 ; mBanRanges.erase(it) ; it=it2 ; - - changed = true ; } - else - ++it; + else ++it; + } IndicateConfigChanged(); - if(!mAutoRangeIps) - return ; + if(!mAutoRangeIps) return; + #ifdef DEBUG_BANLIST std::cerr << "Automatically figuring out IP ranges from banned IPs." << std::endl; #endif diff --git a/libretroshare/src/util/folderiterator.cc b/libretroshare/src/util/folderiterator.cc index b50ef99aa..03edf3b13 100644 --- a/libretroshare/src/util/folderiterator.cc +++ b/libretroshare/src/util/folderiterator.cc @@ -63,7 +63,11 @@ void FolderIterator::next() { while(readdir()) { - d_name(mFileName); +#ifdef WINDOWS_SYS + ConvertUtf16ToUtf8(fileInfo.cFileName, mFileName) ; +#else + mFileName = ent->d_name ; +#endif if(mFileName == "." || mFileName == "..") continue ; @@ -145,25 +149,6 @@ bool FolderIterator::readdir() #endif } -bool FolderIterator::d_name(std::string& dest) -{ - if(!validity) - return false; - -#ifdef WINDOWS_SYS - if(! ConvertUtf16ToUtf8(fileInfo.cFileName, dest)) { - validity = false; - return false; - } -#else - if(ent == 0) - return false; - dest = ent->d_name; -#endif - - return true; -} - time_t FolderIterator::dir_modtime() const { return mFolderModTime ; } const std::string& FolderIterator::file_fullpath() { return mFullPath ; } diff --git a/libretroshare/src/util/folderiterator.h b/libretroshare/src/util/folderiterator.h index 21ebacd06..f31e555f8 100644 --- a/libretroshare/src/util/folderiterator.h +++ b/libretroshare/src/util/folderiterator.h @@ -39,8 +39,6 @@ public: bool readdir(); void next(); -#warning this one should go, as it reports the same information than file_name() - bool d_name(std::string& dest); bool closedir(); const std::string& file_name() ; diff --git a/libretroshare/src/util/rsdir.cc b/libretroshare/src/util/rsdir.cc index dbf3c5bd6..c2ae4c916 100644 --- a/libretroshare/src/util/rsdir.cc +++ b/libretroshare/src/util/rsdir.cc @@ -34,6 +34,7 @@ #include "util/rsstring.h" #include "util/rsrandom.h" #include "util/rsmemory.h" +#include "util/folderiterator.h" #include "retroshare/rstypes.h" #include "rsthreads.h" #include @@ -437,200 +438,13 @@ bool RsDirUtil::checkCreateDirectory(const std::string& dir) bool RsDirUtil::cleanupDirectory(const std::string& cleandir, const std::set &keepFiles) { + for(librs::util::FolderIterator it(cleandir);it.isValid();it.next()) + if(it.file_type() == librs::util::FolderIterator::TYPE_FILE && (keepFiles.end() == std::find(keepFiles.begin(), keepFiles.end(), it.file_name()))) + remove( (cleandir + "/" + it.file_name()).c_str() ) ; - /* check for the dir existance */ -#ifdef WINDOWS_SYS - std::wstring wcleandir; - librs::util::ConvertUtf8ToUtf16(cleandir, wcleandir); - _WDIR *dir = _wopendir(wcleandir.c_str()); -#else - DIR *dir = opendir(cleandir.c_str()); -#endif - - - if (!dir) - { - return false; - } - -#ifdef WINDOWS_SYS - struct _wdirent *dent; - struct _stat buf; - - while(NULL != (dent = _wreaddir(dir))) -#else - struct dirent *dent; - struct stat buf; - - while(NULL != (dent = readdir(dir))) -#endif - { - /* check entry type */ -#ifdef WINDOWS_SYS - const std::wstring &wfname = dent -> d_name; - std::wstring wfullname = wcleandir + L"/" + wfname; -#else - const std::string &fname = dent -> d_name; - std::string fullname = cleandir + "/" + fname; -#endif - -#ifdef WINDOWS_SYS - if (-1 != _wstat(wfullname.c_str(), &buf)) -#else - if (-1 != stat(fullname.c_str(), &buf)) -#endif - { - /* only worry about files */ - if (S_ISREG(buf.st_mode)) - { -#ifdef WINDOWS_SYS - std::string fname; - librs::util::ConvertUtf16ToUtf8(wfname, fname); -#endif - /* check if we should keep it */ - if (keepFiles.end() == std::find(keepFiles.begin(), keepFiles.end(), fname)) - { - /* can remove */ -#ifdef WINDOWS_SYS - _wremove(wfullname.c_str()); -#else - remove(fullname.c_str()); -#endif - } - } - } - } - - /* close directory */ -#ifdef WINDOWS_SYS - _wclosedir(dir); -#else - closedir(dir); -#endif - - return true; + return true; } - - -/* faster cleanup - first construct two sets - then iterate over together */ -bool RsDirUtil::cleanupDirectoryFaster(const std::string& cleandir, const std::set &keepFiles) -{ - - /* check for the dir existance */ -#ifdef WINDOWS_SYS - std::map fileMap; - std::map::const_iterator fit; - - std::wstring wcleandir; - librs::util::ConvertUtf8ToUtf16(cleandir, wcleandir); - _WDIR *dir = _wopendir(wcleandir.c_str()); -#else - std::map fileMap; - std::map::const_iterator fit; - - DIR *dir = opendir(cleandir.c_str()); -#endif - - if (!dir) - { - return false; - } - -#ifdef WINDOWS_SYS - struct _wdirent *dent; - struct _stat buf; - - while(NULL != (dent = _wreaddir(dir))) - { - const std::wstring &wfname = dent -> d_name; - std::wstring wfullname = wcleandir + L"/" + wfname; - - if (-1 != _wstat(wfullname.c_str(), &buf)) - { - /* only worry about files */ - if (S_ISREG(buf.st_mode)) - { - std::string fname; - librs::util::ConvertUtf16ToUtf8(wfname, fname); - fileMap[fname] = wfullname; - } - } - } -#else - struct dirent *dent; - struct stat buf; - - while(NULL != (dent = readdir(dir))) - { - const std::string &fname = dent -> d_name; - std::string fullname = cleandir + "/" + fname; - - if (-1 != stat(fullname.c_str(), &buf)) - { - /* only worry about files */ - if (S_ISREG(buf.st_mode)) - { - fileMap[fname] = fullname; - } - } - } -#endif - - - - std::set::const_iterator kit; - - fit = fileMap.begin(); - kit = keepFiles.begin(); - - while(fit != fileMap.end() && kit != keepFiles.end()) - { - if (fit->first < *kit) // fit is not in keep list; - { -#ifdef WINDOWS_SYS - _wremove(fit->second.c_str()); -#else - remove(fit->second.c_str()); -#endif - ++fit; - } - else if (*kit < fit->first) // keepitem doesn't exist. - { - ++kit; - } - else // in keep list. - { - ++fit; - ++kit; - } - } - - // cleanup extra that aren't in keep list. - while(fit != fileMap.end()) - { -#ifdef WINDOWS_SYS - _wremove(fit->second.c_str()); -#else - remove(fit->second.c_str()); -#endif - ++fit; - } - - /* close directory */ -#ifdef WINDOWS_SYS - _wclosedir(dir); -#else - closedir(dir); -#endif - - return true; -} - - - - - /* slightly nicer helper function */ bool RsDirUtil::hashFile(const std::string& filepath, std::string &name, RsFileHash &hash, uint64_t &size) diff --git a/retroshare-gui/src/gui/Circles/CreateCircleDialog.cpp b/retroshare-gui/src/gui/Circles/CreateCircleDialog.cpp index 79e85d1cc..8ed0bfc47 100644 --- a/retroshare-gui/src/gui/Circles/CreateCircleDialog.cpp +++ b/retroshare-gui/src/gui/Circles/CreateCircleDialog.cpp @@ -25,16 +25,16 @@ #include #include -#include "gui/Circles/CreateCircleDialog.h" -#include "gui/gxs/GxsIdDetails.h" #include #include + +#include "gui/common/AvatarDefs.h" +#include "gui/Circles/CreateCircleDialog.h" +#include "gui/gxs/GxsIdDetails.h" #include "gui/Identity/IdDialog.h" #include "gui/Identity/IdEditDialog.h" -#include - //#define DEBUG_CREATE_CIRCLE_DIALOG 1 #define CREATECIRCLEDIALOG_CIRCLEINFO 2 @@ -258,8 +258,9 @@ void CreateCircleDialog::addMember() QString keyId = item->text(RSCIRCLEID_COL_KEYID); QString idtype = item->text(RSCIRCLEID_COL_IDTYPE); QString nickname = item->text(RSCIRCLEID_COL_NICKNAME); + QIcon icon = item->icon(RSCIRCLEID_COL_NICKNAME); - addMember(keyId, idtype, nickname); + addMember(keyId, idtype, nickname, icon); } void CreateCircleDialog::addMember(const RsGxsIdGroup &idGroup) @@ -267,15 +268,27 @@ void CreateCircleDialog::addMember(const RsGxsIdGroup &idGroup) QString keyId = QString::fromStdString(idGroup.mMeta.mGroupId.toStdString()); QString nickname = QString::fromUtf8(idGroup.mMeta.mGroupName.c_str()); QString idtype = tr("Anon Id"); + + QPixmap pixmap ; + + if(idGroup.mImage.mSize == 0 || !pixmap.loadFromData(idGroup.mImage.mData, idGroup.mImage.mSize, "PNG")) + pixmap = QPixmap::fromImage(GxsIdDetails::makeDefaultIcon(RsGxsId(idGroup.mMeta.mGroupId))); + if (idGroup.mPgpKnown){ RsPeerDetails details; rsPeers->getGPGDetails(idGroup.mPgpId, details); idtype = QString::fromUtf8(details.name.c_str()); }//if (idGroup.mPgpKnown) - addMember(keyId, idtype, nickname); + addMember(keyId, idtype, nickname, QIcon(pixmap)); } void CreateCircleDialog::addMember(const QString& keyId, const QString& idtype, const QString& nickname ) +{ + QIcon icon; + addMember(keyId, idtype, nickname, icon); +} + +void CreateCircleDialog::addMember(const QString& keyId, const QString& idtype, const QString& nickname, const QIcon& icon) { QTreeWidget *tree = ui.treeWidget_membership; @@ -293,9 +306,9 @@ void CreateCircleDialog::addMember(const QString& keyId, const QString& idtype, QTreeWidgetItem *member = new QTreeWidgetItem(); member->setText(RSCIRCLEID_COL_NICKNAME, nickname); + member->setIcon(RSCIRCLEID_COL_NICKNAME, icon); member->setText(RSCIRCLEID_COL_KEYID, keyId); member->setText(RSCIRCLEID_COL_IDTYPE, idtype); - //member->setIcon(RSCIRCLEID_COL_NICKNAME, pixmap); tree->addTopLevelItem(member); @@ -317,14 +330,19 @@ void CreateCircleDialog::addCircle(const RsGxsCircleDetails &cirDetails) QString nickname = QString::fromUtf8(gxs_details.mNickname.c_str()); QString idtype = tr("Anon Id"); - addMember(keyId, idtype, nickname); + QPixmap pixmap ; + + if(gxs_details.mAvatar.mSize == 0 || !pixmap.loadFromData(gxs_details.mAvatar.mData, gxs_details.mAvatar.mSize, "PNG")) + pixmap = QPixmap::fromImage(GxsIdDetails::makeDefaultIcon(gxs_details.mId)); + + addMember(keyId, idtype, nickname, QIcon(pixmap)); }//if(!gxs_id.isNull() && rsIdentity->getIdDetails(gxs_id,gxs_details)) }//for (itUnknownPeers it = cirDetails.mUnknownPeers.begin() typedef std::set::const_iterator itAllowedPeers; for (itAllowedPeers it = cirDetails.mAllowedNodes.begin() ; it != cirDetails.mAllowedNodes.end() ; ++it ) - { + { RsPgpId gpg_id = *it; RsPeerDetails details ; if(!gpg_id.isNull() && rsPeers->getGPGDetails(gpg_id,details)) { @@ -333,7 +351,10 @@ void CreateCircleDialog::addCircle(const RsGxsCircleDetails &cirDetails) QString nickname = QString::fromUtf8(details.name.c_str()); QString idtype = tr("PGP Identity"); - addMember(keyId, idtype, nickname); + QPixmap avatar; + AvatarDefs::getAvatarFromGpgId(gpg_id, avatar); + + addMember(keyId, idtype, nickname, QIcon(avatar)); }//if(!gpg_id.isNull() && rsPeers->getGPGDetails(gpg_id,details)) }//for (itAllowedPeers it = cirDetails.mAllowedPeers.begin() @@ -756,7 +777,7 @@ void CreateCircleDialog::loadIdentities(uint32_t token) bool acceptAllPGP = ui.radioButton_ListAllPGP->isChecked(); //bool acceptKnownPGP = ui.radioButton_ListKnownPGP->isChecked(); - RsGxsIdGroup data; + RsGxsIdGroup idGroup; std::vector datavector; std::vector::iterator vit; if (!rsIdentity->getGroupData(token, datavector)) { @@ -765,67 +786,68 @@ void CreateCircleDialog::loadIdentities(uint32_t token) return; } - for(vit = datavector.begin(); vit != datavector.end(); ++vit) - { - data = (*vit); + for(vit = datavector.begin(); vit != datavector.end(); ++vit) + { + idGroup = (*vit); - /* do filtering */ - bool ok = false; - if (acceptAnonymous) - ok = true; - else if (acceptAllPGP) - ok = data.mMeta.mGroupFlags & RSGXSID_GROUPFLAG_REALID ; - else if (data.mPgpKnown) - ok = data.mMeta.mGroupFlags & RSGXSID_GROUPFLAG_REALID ; + /* do filtering */ + bool ok = false; + if (acceptAnonymous) + ok = true; + else if (acceptAllPGP) + ok = idGroup.mMeta.mGroupFlags & RSGXSID_GROUPFLAG_REALID ; + else if (idGroup.mPgpKnown) + ok = idGroup.mMeta.mGroupFlags & RSGXSID_GROUPFLAG_REALID ; - if (!ok) { + if (!ok) { #ifdef DEBUG_CREATE_CIRCLE_DIALOG - std::cerr << "CreateCircleDialog::insertIdentities() Skipping ID: " << data.mMeta.mGroupId; - std::cerr << std::endl; + std::cerr << "CreateCircleDialog::insertIdentities() Skipping ID: " << data.mMeta.mGroupId; + std::cerr << std::endl; #endif - continue; - } + continue; + } - QString keyId = QString::fromStdString(data.mMeta.mGroupId.toStdString()); - QString nickname = QString::fromUtf8(data.mMeta.mGroupName.c_str()); - QString idtype = tr("Anon Id"); - - QPixmap pixmap ; + QString keyId = QString::fromStdString(idGroup.mMeta.mGroupId.toStdString()); + QString nickname = QString::fromUtf8(idGroup.mMeta.mGroupName.c_str()); + QString idtype = tr("Anon Id"); - if(data.mImage.mSize == 0 || !pixmap.loadFromData(data.mImage.mData, data.mImage.mSize, "PNG")) - pixmap = QPixmap::fromImage(GxsIdDetails::makeDefaultIcon(RsGxsId(data.mMeta.mGroupId))) ; + QPixmap pixmap ; - if (data.mMeta.mGroupFlags & RSGXSID_GROUPFLAG_REALID) - { - if (data.mPgpKnown) { - RsPeerDetails details; - rsPeers->getGPGDetails(data.mPgpId, details); - idtype = QString::fromUtf8(details.name.c_str()); - } - else - idtype = tr("PGP Linked Id"); - - } + if(idGroup.mImage.mSize == 0 || !pixmap.loadFromData(idGroup.mImage.mData, idGroup.mImage.mSize, "PNG")) + pixmap = QPixmap::fromImage(GxsIdDetails::makeDefaultIcon(RsGxsId(idGroup.mMeta.mGroupId))) ; - QTreeWidgetItem *item = new QTreeWidgetItem(); - item->setText(RSCIRCLEID_COL_NICKNAME, nickname); - item->setIcon(RSCIRCLEID_COL_NICKNAME, QIcon(pixmap)); - item->setText(RSCIRCLEID_COL_KEYID, keyId); - item->setText(RSCIRCLEID_COL_IDTYPE, idtype); - tree->addTopLevelItem(item); + if (idGroup.mMeta.mGroupFlags & RSGXSID_GROUPFLAG_REALID) + { + if (idGroup.mPgpKnown) { + RsPeerDetails details; + rsPeers->getGPGDetails(idGroup.mPgpId, details); + idtype = QString::fromUtf8(details.name.c_str()); + } + else + idtype = tr("PGP Linked Id"); - // External Circle. - if (mIsExistingCircle) - { - // check if its in the circle. + } - // We use an explicit cast - // + QTreeWidgetItem *item = new QTreeWidgetItem(); + item->setText(RSCIRCLEID_COL_NICKNAME, nickname); + item->setIcon(RSCIRCLEID_COL_NICKNAME, QIcon(pixmap)); + item->setText(RSCIRCLEID_COL_KEYID, keyId); + item->setText(RSCIRCLEID_COL_IDTYPE, idtype); + tree->addTopLevelItem(item); - if ( mCircleGroup.mInvitedMembers.find(RsGxsId(data.mMeta.mGroupId)) != mCircleGroup.mInvitedMembers.end()) /* found it */ - addMember(keyId, idtype, nickname); - } - } + // External Circle. + if (mIsExistingCircle) + { + // check if its in the circle. + + // We use an explicit cast + // + + if ( mCircleGroup.mInvitedMembers.find(RsGxsId(idGroup.mMeta.mGroupId)) != mCircleGroup.mInvitedMembers.end()) /* found it */ + addMember(keyId, idtype, nickname, QIcon(pixmap)); + + } + } } void CreateCircleDialog::loadRequest(const TokenQueue *queue, const TokenRequest &req) diff --git a/retroshare-gui/src/gui/Circles/CreateCircleDialog.h b/retroshare-gui/src/gui/Circles/CreateCircleDialog.h index 2cb050c04..2a6ce94de 100644 --- a/retroshare-gui/src/gui/Circles/CreateCircleDialog.h +++ b/retroshare-gui/src/gui/Circles/CreateCircleDialog.h @@ -41,6 +41,7 @@ public: void editNewId(bool isExternal); void editExistingId(const RsGxsGroupId &circleId, const bool &clearList = true, bool readonly=true); + void addMember(const QString &keyId, const QString &idtype, const QString &nickname, const QIcon &icon); void addMember(const QString &keyId, const QString &idtype, const QString &nickname); void addMember(const RsGxsIdGroup &idGroup); void addCircle(const RsGxsCircleDetails &cirDetails); diff --git a/retroshare-gui/src/gui/FriendsDialog.cpp b/retroshare-gui/src/gui/FriendsDialog.cpp index 4590ccdc5..52d25d5e3 100644 --- a/retroshare-gui/src/gui/FriendsDialog.cpp +++ b/retroshare-gui/src/gui/FriendsDialog.cpp @@ -54,7 +54,7 @@ #define IMAGE_NETWORK2 ":/icons/png/netgraph.png" #define IMAGE_PEERS ":/icons/png/keyring.png" #define IMAGE_IDENTITY ":/images/identity/identities_32.png" -#define IMAGE_CIRCLES ":/icons/png/circles.png" +//#define IMAGE_CIRCLES ":/icons/png/circles.png" /****** * #define FRIENDS_DEBUG 1 diff --git a/retroshare-gui/src/gui/People/IdentityWidget.h b/retroshare-gui/src/gui/People/IdentityWidget.h index 8daebc6c1..c9ade98e3 100644 --- a/retroshare-gui/src/gui/People/IdentityWidget.h +++ b/retroshare-gui/src/gui/People/IdentityWidget.h @@ -42,6 +42,7 @@ public: const QString idtype() const { return _idtype; } const QString nickname() const { return _nickname; } const QString gxsId() const { return _gxsId; } + const QImage avatar() const { return _avatar; } signals: void addButtonClicked(); diff --git a/retroshare-gui/src/gui/People/PeopleDialog.cpp b/retroshare-gui/src/gui/People/PeopleDialog.cpp index 842627338..5098da953 100644 --- a/retroshare-gui/src/gui/People/PeopleDialog.cpp +++ b/retroshare-gui/src/gui/People/PeopleDialog.cpp @@ -557,7 +557,7 @@ void PeopleDialog::addToCircleInt() std::map::iterator itIdFound; if((itIdFound=_pgp_identity_widgets.find(pgp_id)) != _pgp_identity_widgets.end()) { IdentityWidget *idWidget = itIdFound->second; - dlg.addMember(idWidget->keyId(), idWidget->idtype(), idWidget->nickname()); + dlg.addMember(idWidget->keyId(), idWidget->idtype(), idWidget->nickname(), QIcon(QPixmap::fromImage(idWidget->avatar())) ); }//if((itFound=_pgp_identity_widgets.find(pgp_id)) != _pgp_identity_widgets.end()) dlg.editExistingId(circle->groupInfo().mGroupId, false,false); @@ -769,7 +769,7 @@ void PeopleDialog::fl_flowLayoutItemDroppedInt(QListflListItem IdentityWidget* idDest = qobject_cast(dest); if (idDest) { if (idDest->havePGPDetail()){ - dlg.addMember(idDest->keyId(), idDest->idtype(), idDest->nickname()); + dlg.addMember(idDest->keyId(), idDest->idtype(), idDest->nickname(), QIcon(QPixmap::fromImage(idDest->avatar())) ); }//if (idDest->havePGPDetail()) }//if (idDest) @@ -790,7 +790,7 @@ void PeopleDialog::fl_flowLayoutItemDroppedInt(QListflListItem } else {//if (cirDropped) IdentityWidget* idDropped = qobject_cast(flCurs); if (idDropped){ - dlg.addMember(idDropped->keyId(), idDropped->idtype(), idDropped->nickname()); + dlg.addMember(idDropped->keyId(), idDropped->idtype(), idDropped->nickname(), QIcon(QPixmap::fromImage(idDropped->avatar())) ); }//if (idDropped) }//else (cirDropped) @@ -980,7 +980,7 @@ void PeopleDialog::pf_dropEventOccursInt(QDropEvent *event) IdentityWidget* idDropped = qobject_cast(flCurs); if (idDropped){ if (idDropped->havePGPDetail()){ - dlg.addMember(idDropped->keyId(), idDropped->idtype(), idDropped->nickname()); + dlg.addMember(idDropped->keyId(), idDropped->idtype(), idDropped->nickname(), QIcon(QPixmap::fromImage(idDropped->avatar())) ); atLeastOne = true; }//if (idDropped->havePGPDetail()) }//if (idDropped) @@ -1015,7 +1015,7 @@ void PeopleDialog::pf_dropEventOccursInt(QDropEvent *event) IdentityWidget* idDropped = qobject_cast(flCurs); if (idDropped){ if (idDropped->havePGPDetail()){ - dlg.addMember(idDropped->keyId(), idDropped->idtype(), idDropped->nickname()); + dlg.addMember(idDropped->keyId(), idDropped->idtype(), idDropped->nickname(), QIcon(QPixmap::fromImage(idDropped->avatar())) ); atLeastOne = true; }//if (idDropped->havePGPDetail()) diff --git a/retroshare-gui/src/gui/Posted/PostedCreatePostDialog.ui b/retroshare-gui/src/gui/Posted/PostedCreatePostDialog.ui index aca174f1c..d8128b199 100644 --- a/retroshare-gui/src/gui/Posted/PostedCreatePostDialog.ui +++ b/retroshare-gui/src/gui/Posted/PostedCreatePostDialog.ui @@ -13,8 +13,17 @@ Submit Post - - + + + 0 + + + 0 + + + 0 + + 0 @@ -31,14 +40,14 @@ - + QFrame::StyledPanel QFrame::Raised - + @@ -120,7 +129,7 @@ - + @@ -144,9 +153,9 @@ - + - + Qt::Horizontal @@ -162,7 +171,7 @@ - + Signed by: @@ -183,12 +192,12 @@ - + - + Qt::Horizontal @@ -235,6 +244,11 @@
gui/common/HeaderFrame.h
1 + + MimeTextEdit + QTextEdit +
gui/common/MimeTextEdit.h
+
GxsIdChooser QComboBox @@ -246,9 +260,7 @@
gui/common/StyledLabel.h
- - - + buttonBox diff --git a/retroshare-gui/src/gui/RemoteDirModel.cpp b/retroshare-gui/src/gui/RemoteDirModel.cpp index 5aa09c62c..5da0c1335 100644 --- a/retroshare-gui/src/gui/RemoteDirModel.cpp +++ b/retroshare-gui/src/gui/RemoteDirModel.cpp @@ -543,7 +543,7 @@ QVariant TreeStyle_RDM::sortRole(const QModelIndex& /*index*/,const DirDetails& } return QVariant(); } -QVariant FlatStyle_RDM::sortRole(const QModelIndex& index,const DirDetails& details,int coln) const +QVariant FlatStyle_RDM::sortRole(const QModelIndex& /*index*/,const DirDetails& details,int coln) const { /* * Person: name, id, 0, 0; diff --git a/retroshare-gui/src/gui/RetroShareLink.cpp b/retroshare-gui/src/gui/RetroShareLink.cpp index 0923c7864..5aa195373 100644 --- a/retroshare-gui/src/gui/RetroShareLink.cpp +++ b/retroshare-gui/src/gui/RetroShareLink.cpp @@ -790,9 +790,10 @@ QString RetroShareLink::toString() const #if QT_VERSION >= QT_VERSION_CHECK(5,0,0) url.setQuery(urlQuery); + return url.toString(QUrl::EncodeSpaces | QUrl::EncodeUnicode); +#else + return url.toString().replace(" ","%20");//Seems to be already done with Qt4 but to be sure. #endif - - return url.toString(); } QString RetroShareLink::niceName() const diff --git a/retroshare-gui/src/gui/SharedFilesDialog.cpp b/retroshare-gui/src/gui/SharedFilesDialog.cpp index ad22fb6f5..e0b37e3d2 100644 --- a/retroshare-gui/src/gui/SharedFilesDialog.cpp +++ b/retroshare-gui/src/gui/SharedFilesDialog.cpp @@ -290,13 +290,14 @@ void SharedFilesDialog::showEvent(QShowEvent *) { if(model!=NULL) { - std::set expanded_indexes ; - saveExpandedPaths(expanded_indexes); + std::set expanded_indexes,selected_indexes ; + + saveExpandedPathsAndSelection(expanded_indexes,selected_indexes); model->setVisible(true) ; model->update() ; - restoreExpandedPaths(expanded_indexes); + restoreExpandedPathsAndSelection(expanded_indexes,selected_indexes); } } RemoteSharedFilesDialog::~RemoteSharedFilesDialog() @@ -393,8 +394,9 @@ void SharedFilesDialog::changeCurrentViewModel(int viewTypeIndex) showProperColumns() ; - std::set expanded_indexes ; - saveExpandedPaths(expanded_indexes); + std::set expanded_indexes,selected_indexes ; + + saveExpandedPathsAndSelection(expanded_indexes,selected_indexes); if(isVisible()) { @@ -408,7 +410,7 @@ void SharedFilesDialog::changeCurrentViewModel(int viewTypeIndex) ui.dirTreeView->setModel(proxyModel); ui.dirTreeView->update(); - restoreExpandedPaths(expanded_indexes); + restoreExpandedPathsAndSelection(expanded_indexes,selected_indexes); QHeaderView * header = ui.dirTreeView->header () ; QHeaderView_setSectionResizeModeColumn(header, COLUMN_NAME, QHeaderView::Interactive); @@ -885,7 +887,7 @@ void SharedFilesDialog::preModDirectories(bool local) flat_model->preMods(); } -void SharedFilesDialog::saveExpandedPaths(std::set& expanded_indexes) +void SharedFilesDialog::saveExpandedPathsAndSelection(std::set& expanded_indexes, std::set& selected_indexes) { if(ui.dirTreeView->model() == NULL) return ; @@ -896,11 +898,12 @@ void SharedFilesDialog::saveExpandedPaths(std::set& expanded_indexe for(int row = 0; row < ui.dirTreeView->model()->rowCount(); ++row) { std::string path = ui.dirTreeView->model()->index(row,0).data(Qt::DisplayRole).toString().toStdString(); - recursSaveExpandedItems(ui.dirTreeView->model()->index(row,0),path,expanded_indexes); + + recursSaveExpandedItems(ui.dirTreeView->model()->index(row,0),path,expanded_indexes,selected_indexes); } } -void SharedFilesDialog::restoreExpandedPaths(const std::set& expanded_indexes) +void SharedFilesDialog::restoreExpandedPathsAndSelection(const std::set& expanded_indexes, const std::set& selected_indexes) { if(ui.dirTreeView->model() == NULL) return ; @@ -915,18 +918,23 @@ void SharedFilesDialog::restoreExpandedPaths(const std::set& expand for(int row = 0; row < ui.dirTreeView->model()->rowCount(); ++row) { std::string path = ui.dirTreeView->model()->index(row,0).data(Qt::DisplayRole).toString().toStdString(); - recursRestoreExpandedItems(ui.dirTreeView->model()->index(row,0),path,expanded_indexes); + recursRestoreExpandedItems(ui.dirTreeView->model()->index(row,0),path,expanded_indexes,selected_indexes); } + QItemSelection selection ; + ui.dirTreeView->blockSignals(false) ; } -void SharedFilesDialog::recursSaveExpandedItems(const QModelIndex& index,const std::string& path,std::set& exp) +void SharedFilesDialog::recursSaveExpandedItems(const QModelIndex& index,const std::string& path,std::set& exp,std::set& sel) { std::string local_path = path+"/"+index.data(Qt::DisplayRole).toString().toStdString(); #ifdef DEBUG_SHARED_FILES_DIALOG std::cerr << "at index " << index.row() << ". data[1]=" << local_path << std::endl; #endif + if(ui.dirTreeView->selectionModel()->selection().contains(index)) + sel.insert(local_path) ; + if(ui.dirTreeView->isExpanded(index)) { #ifdef DEBUG_SHARED_FILES_DIALOG @@ -936,7 +944,7 @@ void SharedFilesDialog::recursSaveExpandedItems(const QModelIndex& index,const s exp.insert(local_path) ; for(int row=0;rowmodel()->rowCount(index);++row) - recursSaveExpandedItems(index.child(row,0),local_path,exp) ; + recursSaveExpandedItems(index.child(row,0),local_path,exp,sel) ; } #ifdef DEBUG_SHARED_FILES_DIALOG else @@ -944,12 +952,14 @@ void SharedFilesDialog::recursSaveExpandedItems(const QModelIndex& index,const s #endif } -void SharedFilesDialog::recursRestoreExpandedItems(const QModelIndex& index, const std::string &path, const std::set& exp) +void SharedFilesDialog::recursRestoreExpandedItems(const QModelIndex& index, const std::string &path, const std::set& exp, const std::set &sel) { std::string local_path = path+"/"+index.data(Qt::DisplayRole).toString().toStdString(); #ifdef DEBUG_SHARED_FILES_DIALOG std::cerr << "at index " << index.row() << ". data[1]=" << local_path << std::endl; #endif + if(sel.find(local_path) != sel.end()) + ui.dirTreeView->selectionModel()->select(index, QItemSelectionModel::Select | QItemSelectionModel::Rows); if(exp.find(local_path) != exp.end()) { @@ -959,7 +969,7 @@ void SharedFilesDialog::recursRestoreExpandedItems(const QModelIndex& index, con ui.dirTreeView->setExpanded(index,true) ; for(int row=0;rowmodel()->rowCount(index);++row) - recursRestoreExpandedItems(index.child(row,0),local_path,exp) ; + recursRestoreExpandedItems(index.child(row,0),local_path,exp,sel) ; } } @@ -969,8 +979,9 @@ void SharedFilesDialog::postModDirectories(bool local) if (isRemote() == local) { return; } - std::set expanded_indexes; - saveExpandedPaths(expanded_indexes) ; + std::set expanded_indexes,selected_indexes; + + saveExpandedPathsAndSelection(expanded_indexes,selected_indexes) ; #ifdef DEBUG_SHARED_FILES_DIALOG std::cerr << "Saving expanded items. " << expanded_indexes.size() << " items found" << std::endl; #endif @@ -980,7 +991,7 @@ void SharedFilesDialog::postModDirectories(bool local) flat_model->postMods(); ui.dirTreeView->update() ; - restoreExpandedPaths(expanded_indexes) ; + restoreExpandedPathsAndSelection(expanded_indexes,selected_indexes) ; if (ui.filterPatternLineEdit->text().isEmpty() == false) FilterItems(); diff --git a/retroshare-gui/src/gui/SharedFilesDialog.h b/retroshare-gui/src/gui/SharedFilesDialog.h index 594df6fab..3d199fe98 100644 --- a/retroshare-gui/src/gui/SharedFilesDialog.h +++ b/retroshare-gui/src/gui/SharedFilesDialog.h @@ -94,10 +94,10 @@ protected: Ui::SharedFilesDialog ui; virtual void processSettings(bool bLoad) = 0; - void recursRestoreExpandedItems(const QModelIndex& index,const std::string& path,const std::set& exp); - void recursSaveExpandedItems(const QModelIndex& index, const std::string &path, std::set &exp); - void saveExpandedPaths(std::set& paths) ; - void restoreExpandedPaths(const std::set& paths) ; + void recursRestoreExpandedItems(const QModelIndex& index,const std::string& path,const std::set& exp,const std::set& sel); + void recursSaveExpandedItems(const QModelIndex& index, const std::string &path, std::set &exp, std::set& sel); + void saveExpandedPathsAndSelection(std::set& paths, std::set& selected_indexes) ; + void restoreExpandedPathsAndSelection(const std::set& paths, const std::set& selected_indexes) ; protected: //now context menu are created again every time theu are called ( in some diff --git a/retroshare-gui/src/gui/chat/ChatWidget.cpp b/retroshare-gui/src/gui/chat/ChatWidget.cpp index 725fcb11b..65b27d6e0 100644 --- a/retroshare-gui/src/gui/chat/ChatWidget.cpp +++ b/retroshare-gui/src/gui/chat/ChatWidget.cpp @@ -21,18 +21,19 @@ ****************************************************************/ #include -#include -#include -#include +#include #include #include +#include +#include #include -#include -#include -#include -#include -#include +#include #include +#include +#include +#include +#include +#include #include "ChatWidget.h" #include "ui_ChatWidget.h" @@ -157,6 +158,8 @@ ChatWidget::ChatWidget(QWidget *parent) : connect(ui->actionQuote, SIGNAL(triggered()), this, SLOT(quote())); connect(ui->actionDropPlacemark, SIGNAL(triggered()), this, SLOT(dropPlacemark())); connect(ui->actionSave_image, SIGNAL(triggered()), this, SLOT(saveImage())); + connect(ui->actionShow_Hidden_Images, SIGNAL(triggered()), ui->textBrowser, SLOT(showImages())); + ui->actionShow_Hidden_Images->setIcon(ui->textBrowser->getBlockedImage()); connect(ui->hashBox, SIGNAL(fileHashingFinished(QList)), this, SLOT(fileHashingFinished(QList))); @@ -196,9 +199,7 @@ ChatWidget::ChatWidget(QWidget *parent) : ui->actionSendAsPlainText->setChecked(Settings->getChatSendAsPlainTextByDef()); - ui->textBrowser->setImageBlockWidget(ui->imageBlockWidget); - ui->textBrowser->resetImagesStatus(Settings->getChatLoadEmbeddedImages());//Need to be called after setImageBlockWidget - ui->imageBlockWidget->setAutoHide(true); + ui->textBrowser->resetImagesStatus(Settings->getChatLoadEmbeddedImages()); ui->textBrowser->installEventFilter(this); ui->textBrowser->viewport()->installEventFilter(this); ui->chatTextEdit->installEventFilter(this); @@ -581,6 +582,12 @@ bool ChatWidget::eventFilter(QObject *obj, QEvent *event) if (!anchors.isEmpty()){ toolTipText = anchors.at(0); } + if (toolTipText.isEmpty() && !ui->textBrowser->getShowImages()){ + QString imageStr; + if (ui->textBrowser->checkImage(helpEvent->pos(), imageStr)) { + toolTipText = imageStr; + } + } } if (!toolTipText.isEmpty()){ QToolTip::showText(helpEvent->globalPos(), toolTipText); @@ -1016,9 +1023,11 @@ void ChatWidget::contextMenuTextBrowser(QPoint point) contextMnu->addAction(ui->actionQuote); contextMnu->addAction(ui->actionDropPlacemark); - QTextCursor cursor = ui->textBrowser->cursorForPosition(point); - if(ImageUtil::checkImage(cursor)) + if(ui->textBrowser->checkImage(point)) { + if (! ui->textBrowser->getShowImages()) + contextMnu->addAction(ui->actionShow_Hidden_Images); + ui->actionSave_image->setData(point); contextMnu->addAction(ui->actionSave_image); } diff --git a/retroshare-gui/src/gui/chat/ChatWidget.ui b/retroshare-gui/src/gui/chat/ChatWidget.ui index 1b9f57b71..fed47f6ce 100644 --- a/retroshare-gui/src/gui/chat/ChatWidget.ui +++ b/retroshare-gui/src/gui/chat/ChatWidget.ui @@ -7,7 +7,7 @@ 0 0 667 - 323 + 334
@@ -206,16 +206,6 @@ border-image: url(:/images/closepressed.png) - - - - - 0 - 0 - - - - @@ -989,6 +979,11 @@ border-image: url(:/images/closepressed.png) Don't replace tag with Emote Icon. + + + Show Hidden Images + + @@ -1017,17 +1012,10 @@ border-image: url(:/images/closepressed.png) QTextEdit
gui/common/MimeTextEdit.h
- - RSImageBlockWidget - QWidget -
gui/common/RSImageBlockWidget.h
- 1 -
- - + diff --git a/retroshare-gui/src/gui/chat/PopupDistantChatDialog.cpp b/retroshare-gui/src/gui/chat/PopupDistantChatDialog.cpp index 12911efc9..bfc961dad 100644 --- a/retroshare-gui/src/gui/chat/PopupDistantChatDialog.cpp +++ b/retroshare-gui/src/gui/chat/PopupDistantChatDialog.cpp @@ -167,7 +167,7 @@ void PopupDistantChatDialog::closeEvent(QCloseEvent *e) PopupChatDialog::closeEvent(e) ; } -QString PopupDistantChatDialog::getPeerName(const ChatId &id) const +QString PopupDistantChatDialog::getPeerName(const ChatId &/*id*/) const { DistantChatPeerInfo tinfo; diff --git a/retroshare-gui/src/gui/common/ElidedLabel.cpp b/retroshare-gui/src/gui/common/ElidedLabel.cpp index 934756dc4..0dd4f69b6 100644 --- a/retroshare-gui/src/gui/common/ElidedLabel.cpp +++ b/retroshare-gui/src/gui/common/ElidedLabel.cpp @@ -52,7 +52,9 @@ ElidedLabel::ElidedLabel(const QString &text, QWidget *parent) , mElided(false) , mOnlyPlainText(false) , mContent(text) + , mTextColor(QColor()) { + setStyleSheet("background-color: rgba(0,0,0,0%)"); mRectElision = QRect(); setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred); } @@ -62,7 +64,9 @@ ElidedLabel::ElidedLabel(QWidget *parent) , mElided(false) , mOnlyPlainText(false) , mContent("") + , mTextColor(QColor()) { + setStyleSheet("background-color: rgba(0,0,0,0%)"); mRectElision = QRect(); setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred); } @@ -94,7 +98,7 @@ void ElidedLabel::paintEvent(QPaintEvent *event) QFontMetrics fontMetrics = painter.fontMetrics(); QRect cr = contentsRect(); cr.adjust(margin(), margin(), -margin(), -margin()); - + bool didElide = false; QChar ellipsisChar(0x2026);//= "…" int lineSpacing = fontMetrics.lineSpacing(); @@ -225,3 +229,11 @@ void ElidedLabel::mousePressEvent(QMouseEvent *ev) } QLabel::mousePressEvent(ev); } + +void ElidedLabel::setTextColor(const QColor &color) +{ + QPalette tmpPalette = palette(); + tmpPalette.setColor(foregroundRole(), color); + setPalette(tmpPalette); + mTextColor = color; +} diff --git a/retroshare-gui/src/gui/common/ElidedLabel.h b/retroshare-gui/src/gui/common/ElidedLabel.h index db51aef79..a8110a857 100644 --- a/retroshare-gui/src/gui/common/ElidedLabel.h +++ b/retroshare-gui/src/gui/common/ElidedLabel.h @@ -53,6 +53,7 @@ class ElidedLabel : public QLabel Q_PROPERTY(QString text READ text WRITE setText) Q_PROPERTY(bool isElided READ isElided) Q_PROPERTY(bool isOnlyPlainText READ isOnlyPlainText WRITE setOnlyPlainText) + Q_PROPERTY(QColor textColor READ textColor WRITE setTextColor) public: ElidedLabel(const QString &text, QWidget *parent = 0); @@ -62,6 +63,9 @@ public: bool isElided() const { return mElided; } bool isOnlyPlainText() const { return mOnlyPlainText; } + QColor textColor() const { return mTextColor; } + void setTextColor(const QColor &color); + public slots: void setText(const QString &text); void setOnlyPlainText(const bool &value); @@ -79,6 +83,7 @@ private: bool mOnlyPlainText; QString mContent; QRect mRectElision; + QColor mTextColor; }; #endif // ELIDEDLABEL_H diff --git a/retroshare-gui/src/gui/common/Emoticons.cpp b/retroshare-gui/src/gui/common/Emoticons.cpp index d905c5559..3894c9deb 100644 --- a/retroshare-gui/src/gui/common/Emoticons.cpp +++ b/retroshare-gui/src/gui/common/Emoticons.cpp @@ -34,6 +34,7 @@ #include "util/HandleRichText.h" static QHash Smileys; +static QVector order; void Emoticons::load() { @@ -115,6 +116,7 @@ void Emoticons::load() } else { Smileys.insert(smcode, smfile); } + order.append(smcode); } } @@ -174,15 +176,15 @@ void Emoticons::showSmileyWidget(QWidget *parent, QWidget *button, const char *s x = 0; y = 0; - QHashIterator i(Smileys); + QVectorIterator i(order); while(i.hasNext()) { - i.next(); + QString key = i.next(); QPushButton *smButton = new QPushButton("", smWidget); smButton->setGeometry(x*buttonWidth, y*buttonHeight, buttonWidth, buttonHeight); smButton->setIconSize(QSize(buttonWidth, buttonHeight)); - smButton->setIcon(QPixmap(i.value())); - smButton->setToolTip(i.key()); + smButton->setIcon(QPixmap(Smileys.value(key))); + smButton->setToolTip(key); smButton->setStyleSheet("QPushButton:hover {border: 3px solid white; border-radius: 2px;}"); smButton->setFlat(true); ++x; diff --git a/retroshare-gui/src/gui/common/FriendList.cpp b/retroshare-gui/src/gui/common/FriendList.cpp index e61e8a568..643e9d482 100644 --- a/retroshare-gui/src/gui/common/FriendList.cpp +++ b/retroshare-gui/src/gui/common/FriendList.cpp @@ -510,6 +510,7 @@ static void getNameWidget(QTreeWidget *treeWidget, QTreeWidgetItem *item, Elided if (!widget) { widget = new QWidget; + widget->setAttribute(Qt::WA_TranslucentBackground); nameLabel = new ElidedLabel(widget); textLabel = new ElidedLabel(widget); diff --git a/retroshare-gui/src/gui/common/GroupTreeWidget.cpp b/retroshare-gui/src/gui/common/GroupTreeWidget.cpp index b396083b5..12408b92a 100644 --- a/retroshare-gui/src/gui/common/GroupTreeWidget.cpp +++ b/retroshare-gui/src/gui/common/GroupTreeWidget.cpp @@ -18,20 +18,22 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. ****************************************************************/ - -#include -#include -#include -#include - -#include "retroshare/rsgxsflags.h" #include "GroupTreeWidget.h" #include "ui_GroupTreeWidget.h" -#include "RSItemDelegate.h" +#include +#include +#include +#include +#include + +#include "retroshare/rsgxsflags.h" + #include "PopularityDefs.h" -#include "gui/settings/rsharesettings.h" +#include "RSItemDelegate.h" #include "RSTreeWidgetItem.h" +#include "gui/common/ElidedLabel.h" +#include "gui/settings/rsharesettings.h" #include "util/QtVersion.h" #include @@ -55,6 +57,9 @@ #define FILTER_NAME_INDEX 0 #define FILTER_DESC_INDEX 1 +Q_DECLARE_METATYPE(ElidedLabel*) +Q_DECLARE_METATYPE(QLabel*) + GroupTreeWidget::GroupTreeWidget(QWidget *parent) : QWidget(parent), ui(new Ui::GroupTreeWidget) { @@ -116,6 +121,38 @@ GroupTreeWidget::~GroupTreeWidget() delete ui; } +static void getNameWidget(QTreeWidget *treeWidget, QTreeWidgetItem *item, ElidedLabel *&nameLabel, QLabel *&waitLabel) +{ + QWidget *widget = treeWidget->itemWidget(item, COLUMN_NAME); + + if (!widget) { + widget = new QWidget; + widget->setAttribute(Qt::WA_TranslucentBackground); + nameLabel = new ElidedLabel(widget); + waitLabel = new QLabel(widget); + QMovie *movie = new QMovie(":/images/loader/circleball-16.gif"); + waitLabel->setMovie(movie); + waitLabel->setHidden(true); + + widget->setProperty("nameLabel", qVariantFromValue(nameLabel)); + widget->setProperty("waitLabel", qVariantFromValue(waitLabel)); + + QHBoxLayout *layout = new QHBoxLayout; + layout->setSpacing(0); + layout->setContentsMargins(0, 0, 0, 0); + + layout->addWidget(nameLabel); + layout->addWidget(waitLabel); + + widget->setLayout(layout); + + treeWidget->setItemWidget(item, COLUMN_NAME, widget); + } else { + nameLabel = widget->property("nameLabel").value(); + waitLabel = widget->property("waitLabel").value(); + } +} + void GroupTreeWidget::changeEvent(QEvent *e) { QWidget::changeEvent(e); @@ -229,7 +266,7 @@ void GroupTreeWidget::initDisplayMenu(QToolButton *toolButton) actionSortByLastPost = displayMenu->addAction(QIcon(), tr("Sort by Last Post"), this, SLOT(sort())); actionSortByLastPost->setCheckable(true); actionSortByLastPost->setActionGroup(actionGroup); - + actionSortByPosts = displayMenu->addAction(QIcon(), tr("Sort by Posts"), this, SLOT(sort())); actionSortByPosts->setCheckable(true); actionSortByPosts->setActionGroup(actionGroup); @@ -255,6 +292,11 @@ void GroupTreeWidget::updateColors() } item->setForeground(COLUMN_NAME, brush); + + ElidedLabel *nameLabel = NULL; + QLabel *waitLabel = NULL; + getNameWidget(ui->treeWidget, item, nameLabel, waitLabel); + nameLabel->setTextColor(brush.color()); } } @@ -293,21 +335,27 @@ QTreeWidgetItem *GroupTreeWidget::addCategoryItem(const QString &name, const QIc { QFont font; QTreeWidgetItem *item = new QTreeWidgetItem(); + ui->treeWidget->addTopLevelItem(item); + + ElidedLabel *nameLabel = NULL; + QLabel *waitLabel = NULL; + getNameWidget(ui->treeWidget, item, nameLabel, waitLabel); + + nameLabel->setText(name); + item->setData(COLUMN_DATA, ROLE_NAME, name); font = item->font(COLUMN_NAME); font.setBold(true); - item->setText(COLUMN_NAME, name); - item->setData(COLUMN_DATA, ROLE_NAME, name); item->setFont(COLUMN_NAME, font); + nameLabel->setFont(font); item->setIcon(COLUMN_NAME, icon); - int S = QFontMetricsF(font).height(); + int S = QFontMetricsF(font).height(); - item->setSizeHint(COLUMN_NAME, QSize(S*1.1, S*1.1)); + item->setSizeHint(COLUMN_NAME, QSize(S*1.1, S*1.1)); item->setForeground(COLUMN_NAME, QBrush(textColorCategory())); + nameLabel->setTextColor(textColorCategory()); item->setData(COLUMN_DATA, ROLE_COLOR, GROUPTREEWIDGET_COLOR_CATEGORY); - ui->treeWidget->addTopLevelItem(item); - item->setExpanded(expand); return item; @@ -334,114 +382,119 @@ QString GroupTreeWidget::itemIdAt(QPoint &point) void GroupTreeWidget::fillGroupItems(QTreeWidgetItem *categoryItem, const QList &itemList) { - if (categoryItem == NULL) { - return; - } + if (categoryItem == NULL) { + return; + } - QString filterText = ui->filterLineEdit->text(); + QString filterText = ui->filterLineEdit->text(); - /* Iterate all items */ - QList::const_iterator it; - for (it = itemList.begin(); it != itemList.end(); ++it) { - const GroupItemInfo &itemInfo = *it; + /* Iterate all items */ + QList::const_iterator it; + for (it = itemList.begin(); it != itemList.end(); ++it) { + const GroupItemInfo &itemInfo = *it; - QTreeWidgetItem *item = NULL; + QTreeWidgetItem *item = NULL; - /* Search exisiting item */ - int childCount = categoryItem->childCount(); - for (int child = 0; child < childCount; ++child) { - QTreeWidgetItem *childItem = categoryItem->child(child); - if (childItem->data(COLUMN_DATA, ROLE_ID).toString() == itemInfo.id) { - /* Found child */ - item = childItem; - break; - } - } + /* Search exisiting item */ + int childCount = categoryItem->childCount(); + for (int child = 0; child < childCount; ++child) { + QTreeWidgetItem *childItem = categoryItem->child(child); + if (childItem->data(COLUMN_DATA, ROLE_ID).toString() == itemInfo.id) { + /* Found child */ + item = childItem; + break; + } + } - if (item == NULL) { - item = new RSTreeWidgetItem(compareRole); - item->setData(COLUMN_DATA, ROLE_ID, itemInfo.id); - categoryItem->addChild(item); - } + if (item == NULL) { + item = new RSTreeWidgetItem(compareRole); + item->setData(COLUMN_DATA, ROLE_ID, itemInfo.id); + categoryItem->addChild(item); + } - item->setText(COLUMN_NAME, itemInfo.name); - item->setData(COLUMN_DATA, ROLE_NAME, itemInfo.name); - item->setData(COLUMN_DATA, ROLE_DESCRIPTION, itemInfo.description); + ElidedLabel *nameLabel = NULL; + QLabel *waitLabel = NULL; + getNameWidget(ui->treeWidget, item, nameLabel, waitLabel); - /* Set last post */ - qlonglong lastPost = itemInfo.lastpost.toTime_t(); - item->setData(COLUMN_DATA, ROLE_LASTPOST, -lastPost); // negative for correct sorting + nameLabel->setText(itemInfo.name); + item->setData(COLUMN_DATA, ROLE_NAME, itemInfo.name); + item->setData(COLUMN_DATA, ROLE_DESCRIPTION, itemInfo.description); - /* Set visible posts */ - item->setData(COLUMN_DATA, ROLE_POSTS, -itemInfo.max_visible_posts);// negative for correct sorting + /* Set last post */ + qlonglong lastPost = itemInfo.lastpost.toTime_t(); + item->setData(COLUMN_DATA, ROLE_LASTPOST, -lastPost); // negative for correct sorting - /* Set icon */ - if (ui->treeWidget->itemWidget(item, COLUMN_NAME)) { - /* Item is waiting, save icon in role */ - item->setData(COLUMN_DATA, ROLE_SAVED_ICON, itemInfo.icon); - } else { - item->setIcon(COLUMN_NAME, itemInfo.icon); - } + /* Set visible posts */ + item->setData(COLUMN_DATA, ROLE_POSTS, -itemInfo.max_visible_posts);// negative for correct sorting - /* Set popularity */ - QString tooltip = PopularityDefs::tooltip(itemInfo.popularity); + /* Set icon */ + if (waitLabel->isVisible()) { + /* Item is waiting, save icon in role */ + item->setData(COLUMN_DATA, ROLE_SAVED_ICON, itemInfo.icon); + } else { + item->setIcon(COLUMN_NAME, itemInfo.icon); + } - item->setIcon(COLUMN_POPULARITY, PopularityDefs::icon(itemInfo.popularity)); - item->setData(COLUMN_DATA, ROLE_POPULARITY, -itemInfo.popularity); // negative for correct sorting + /* Set popularity */ + QString tooltip = PopularityDefs::tooltip(itemInfo.popularity); - /* Set tooltip */ - if (itemInfo.adminKey) - tooltip += "\n" + tr("You are admin (modify names and description using Edit menu)"); - else if (itemInfo.publishKey) - tooltip += "\n" + tr("You have been granted as publisher (you can post here!)"); + item->setIcon(COLUMN_POPULARITY, PopularityDefs::icon(itemInfo.popularity)); + item->setData(COLUMN_DATA, ROLE_POPULARITY, -itemInfo.popularity); // negative for correct sorting - if(!IS_GROUP_SUBSCRIBED(itemInfo.subscribeFlags)) - { - tooltip += "\n" + QString::number(itemInfo.max_visible_posts) + " messages available" ; - tooltip += "\n" + tr("Subscribe to download and read messages") ; - } + /* Set tooltip */ + if (itemInfo.adminKey) + tooltip += "\n" + tr("You are admin (modify names and description using Edit menu)"); + else if (itemInfo.publishKey) + tooltip += "\n" + tr("You have been granted as publisher (you can post here!)"); - item->setToolTip(COLUMN_NAME, tooltip); - item->setToolTip(COLUMN_POPULARITY, tooltip); + if(!IS_GROUP_SUBSCRIBED(itemInfo.subscribeFlags)) + { + tooltip += "\n" + QString::number(itemInfo.max_visible_posts) + " messages available" ; + tooltip += "\n" + tr("Subscribe to download and read messages") ; + } - item->setData(COLUMN_DATA, ROLE_SUBSCRIBE_FLAGS, itemInfo.subscribeFlags); + item->setToolTip(COLUMN_NAME, tooltip); + item->setToolTip(COLUMN_POPULARITY, tooltip); - /* Set color */ - QBrush brush; - if (itemInfo.publishKey) { - brush = QBrush(textColorPrivateKey()); - item->setData(COLUMN_DATA, ROLE_COLOR, GROUPTREEWIDGET_COLOR_PRIVATEKEY); - } else { - brush = ui->treeWidget->palette().color(QPalette::Text); - item->setData(COLUMN_DATA, ROLE_COLOR, GROUPTREEWIDGET_COLOR_STANDARD); - } - item->setForeground(COLUMN_NAME, brush); + item->setData(COLUMN_DATA, ROLE_SUBSCRIBE_FLAGS, itemInfo.subscribeFlags); - /* Calculate score */ - calculateScore(item, filterText); - } + /* Set color */ + QBrush brush; + if (itemInfo.publishKey) { + brush = QBrush(textColorPrivateKey()); + item->setData(COLUMN_DATA, ROLE_COLOR, GROUPTREEWIDGET_COLOR_PRIVATEKEY); + } else { + brush = ui->treeWidget->palette().color(QPalette::Text); + item->setData(COLUMN_DATA, ROLE_COLOR, GROUPTREEWIDGET_COLOR_STANDARD); + } + item->setForeground(COLUMN_NAME, brush); + nameLabel->setTextColor(brush.color()); - /* Remove all items not in list */ - int child = 0; - int childCount = categoryItem->childCount(); - while (child < childCount) { - QString id = categoryItem->child(child)->data(COLUMN_DATA, ROLE_ID).toString(); + /* Calculate score */ + calculateScore(item, filterText); + } - for (it = itemList.begin(); it != itemList.end(); ++it) { - if (it->id == id) { - break; - } - } + /* Remove all items not in list */ + int child = 0; + int childCount = categoryItem->childCount(); + while (child < childCount) { + QString id = categoryItem->child(child)->data(COLUMN_DATA, ROLE_ID).toString(); - if (it == itemList.end()) { - delete(categoryItem->takeChild(child)); - childCount = categoryItem->childCount(); - } else { - ++child; - } - } + for (it = itemList.begin(); it != itemList.end(); ++it) { + if (it->id == id) { + break; + } + } - resort(categoryItem); + if (it == itemList.end()) { + delete(categoryItem->takeChild(child)); + childCount = categoryItem->childCount(); + } else { + ++child; + } + } + + resort(categoryItem); } void GroupTreeWidget::setUnreadCount(QTreeWidgetItem *item, int unreadCount) @@ -449,19 +502,22 @@ void GroupTreeWidget::setUnreadCount(QTreeWidgetItem *item, int unreadCount) if (item == NULL) { return; } + ElidedLabel *nameLabel = NULL; + QLabel *waitLabel = NULL; + getNameWidget(ui->treeWidget, item, nameLabel, waitLabel); QString name = item->data(COLUMN_DATA, ROLE_NAME).toString(); - QFont font = item->font(COLUMN_NAME); + QFont font = nameLabel->font(); if (unreadCount) { - name += QString(" (%1)").arg(unreadCount); + name = QString("(%1) ").arg(unreadCount) + name; font.setBold(true); } else { font.setBold(false); } - item->setText(COLUMN_NAME, name); - item->setFont(COLUMN_NAME, font); + nameLabel->setText(name); + nameLabel->setFont(font); } QTreeWidgetItem *GroupTreeWidget::getItemFromId(const QString &id) @@ -507,9 +563,11 @@ bool GroupTreeWidget::setWaiting(const QString &id, bool wait) return false; } - QWidget *w = ui->treeWidget->itemWidget(item, COLUMN_NAME); + ElidedLabel *nameLabel = NULL; + QLabel *waitLabel = NULL; + getNameWidget(ui->treeWidget, item, nameLabel, waitLabel); if (wait) { - if (w) { + if (waitLabel->isVisible()) { /* Allready waiting */ } else { /* Save icon in role */ @@ -519,21 +577,19 @@ bool GroupTreeWidget::setWaiting(const QString &id, bool wait) /* Create empty icon of the same size */ QPixmap pixmap(ui->treeWidget->iconSize()); pixmap.fill(Qt::transparent); - item->setIcon(COLUMN_NAME, QIcon(pixmap)); - QLabel *label = new QLabel(this); - QMovie *movie = new QMovie(":/images/loader/circleball-16.gif"); - label->setMovie(movie); - - ui->treeWidget->setItemWidget(item, COLUMN_NAME, label); - - movie->start(); + /* Show waitLabel and hide nameLabel */ + nameLabel->setHidden(true); + waitLabel->setVisible(true); + waitLabel->movie()->start(); } } else { - if (w) { - ui->treeWidget->setItemWidget(item, COLUMN_NAME, NULL); - delete(w); + if (waitLabel->isVisible()) { + /* Show nameLabel and hide waitLabel */ + waitLabel->movie()->stop(); + waitLabel->setHidden(true); + nameLabel->setVisible(true); /* Set icon saved in role */ item->setIcon(COLUMN_NAME, item->data(COLUMN_DATA, ROLE_SAVED_ICON).value()); diff --git a/retroshare-gui/src/gui/common/RSGraphWidget.cpp b/retroshare-gui/src/gui/common/RSGraphWidget.cpp index fa7d00bdc..2d586ae38 100644 --- a/retroshare-gui/src/gui/common/RSGraphWidget.cpp +++ b/retroshare-gui/src/gui/common/RSGraphWidget.cpp @@ -393,10 +393,12 @@ void RSGraphWidget::paintData() paintLine(points, getColor(i)); } if(_maxValue > 0.0f) + { if(_flags & RSGRAPH_FLAGS_LOG_SCALE_Y) _y_scale = _rec.height()*0.8 / log(_maxValue) ; else _y_scale = _rec.height()*0.8/_maxValue ; + } } /** Returns a list of points on the bandwidth graph based on the supplied set diff --git a/retroshare-gui/src/gui/common/RSTextBrowser.cpp b/retroshare-gui/src/gui/common/RSTextBrowser.cpp index cb0634ee6..f57e650a9 100644 --- a/retroshare-gui/src/gui/common/RSTextBrowser.cpp +++ b/retroshare-gui/src/gui/common/RSTextBrowser.cpp @@ -1,8 +1,9 @@ #include -#include #include +#include #include +#include #include "RSTextBrowser.h" #include "RSImageBlockWidget.h" @@ -19,7 +20,7 @@ RSTextBrowser::RSTextBrowser(QWidget *parent) : mImageBlockWidget = NULL; mLinkClickActive = true; - highliter = new RsSyntaxHighlighter(this); + highlighter = new RsSyntaxHighlighter(this); connect(this, SIGNAL(anchorClicked(QUrl)), this, SLOT(linkClicked(QUrl))); } @@ -73,6 +74,23 @@ void RSTextBrowser::paintEvent(QPaintEvent *event) painter.drawText(QRect(QPoint(), vieportWidget->size()), Qt::AlignHCenter | Qt::AlignVCenter | Qt::TextWordWrap, mPlaceholderText); } +#ifdef RSTEXTBROWSER_CHECKIMAGE_DEBUG + QPainter painter(viewport()); + QPen pen = painter.pen(); + pen.setWidth(2); + pen.setColor(QColor(qRgba(255,0,0,128))); + painter.setPen(pen); + painter.drawRect(mCursorRectStart); + pen.setColor(QColor(qRgba(0,255,0,128))); + painter.setPen(pen); + painter.drawRect(mCursorRectLeft); + pen.setColor(QColor(qRgba(0,0,255,128))); + painter.setPen(pen); + painter.drawRect(mCursorRectRight); + pen.setColor(QColor(qRgba(0,0,0,128))); + painter.setPen(pen); + painter.drawRect(mCursorRectEnd); +#endif } QVariant RSTextBrowser::loadResource(int type, const QUrl &name) @@ -103,6 +121,11 @@ QVariant RSTextBrowser::loadResource(int type, const QUrl &name) if (mImageBlockWidget) mImageBlockWidget->show(); + return getBlockedImage(); +} + +QPixmap RSTextBrowser::getBlockedImage() +{ return QPixmap(":/images/imageblocked_24.png"); } @@ -159,3 +182,61 @@ void RSTextBrowser::activateLinkClick(bool active) { mLinkClickActive = active; } + +/** + * @brief RSTextBrowser::checkImage + * @param pos where to check if image is shown in viewport coordinate + * @param imageStr return html source of cursor + * @return True if an image is under cursor + */ +bool RSTextBrowser::checkImage(QPoint pos, QString &imageStr) +{ + //Get text cursor under pos. But if pos is under text browser end line this return last cursor. + QTextCursor cursor = cursorForPosition(pos); + //First get rect of cursor (could be at left or right of image) + QRect cursorRectStart = cursorRect(cursor); + //Second get text + cursor.movePosition(QTextCursor::Left, QTextCursor::MoveAnchor, 1);//To get character just before + QRect cursorRectLeft = cursorRect(cursor); + cursor.movePosition(QTextCursor::Right, QTextCursor::KeepAnchor, 2); + QRect cursorRectRight = cursorRect(cursor); + imageStr = cursor.selection().toHtml(); +#ifdef RSTEXTBROWSER_CHECKIMAGE_DEBUG + mCursorRectStart = cursorRectStart; + mCursorRectLeft = cursorRectLeft; + mCursorRectRight = cursorRectRight; + + std::cerr << "cursorRect LTRB :" << cursorRectStart.left() << ";" << cursorRectStart.top() << ";" << cursorRectStart.right() << ";" << cursorRectStart.bottom() << std::endl; + std::cerr << "cursorRectLeft :" << cursorRectLeft.left() << ";" << cursorRectLeft.top() << ";" << cursorRectLeft.right() << ";" << cursorRectLeft.bottom() << std::endl; + std::cerr << "cursorRectRight :" << cursorRectRight.left() << ";" << cursorRectRight.top() << ";" << cursorRectRight.right() << ";" << cursorRectRight.bottom() << std::endl; + std::cerr << "pos XY :" << pos.x() << ";" << pos.y() << std::endl; +#endif + QRect cursorRectEnd = cursorRectStart; + //Finally set left with right of precedent character. + if (cursorRectEnd.top() < cursorRectLeft.bottom()) + { + cursorRectEnd.setLeft(cursorRectLeft.right()); + } else { + //Image on new line + cursorRectEnd.setLeft(0); + } + //And set Right with left of next character. + if (cursorRectEnd.bottom() > cursorRectRight.top()) + { + cursorRectEnd.setRight(cursorRectRight.left()); + } else { + //New line after Image. + } +#ifdef RSTEXTBROWSER_CHECKIMAGE_DEBUG + mCursorRectEnd = cursorRectEnd; + + std::cerr << "final cursorRect:" << cursorRectEnd.left() << ";" << cursorRectEnd.top() << ";" << cursorRectEnd.right() << ";" << cursorRectEnd.bottom() << std::endl; + viewport()->update(); +#endif + //If pos is on text rect + if (cursorRectEnd.contains(pos)) + { + return imageStr.indexOf("base64,") != -1; + } + return false; +} diff --git a/retroshare-gui/src/gui/common/RSTextBrowser.h b/retroshare-gui/src/gui/common/RSTextBrowser.h index f9e218b77..13e520d00 100644 --- a/retroshare-gui/src/gui/common/RSTextBrowser.h +++ b/retroshare-gui/src/gui/common/RSTextBrowser.h @@ -4,6 +4,8 @@ #include #include "util/RsSyntaxHighlighter.h" +//#define RSTEXTBROWSER_CHECKIMAGE_DEBUG 1 + class RSImageBlockWidget; class RSTextBrowser : public QTextBrowser @@ -18,16 +20,20 @@ public: void setPlaceholderText(const QString &text); void setImageBlockWidget(RSImageBlockWidget *widget); void resetImagesStatus(bool load); + QPixmap getBlockedImage(); + bool checkImage(QPoint pos, QString &imageStr); + bool checkImage(QPoint pos) {QString imageStr; return checkImage(pos, imageStr); } void activateLinkClick(bool active); virtual QVariant loadResource(int type, const QUrl &name); - QColor textColorQuote() const { return highliter->textColorQuote();} + QColor textColorQuote() const { return highlighter->textColorQuote();} + bool getShowImages() const { return mShowImages; } public slots: void showImages(); - void setTextColorQuote(QColor textColorQuote) { highliter->setTextColorQuote(textColorQuote);} + void setTextColorQuote(QColor textColorQuote) { highlighter->setTextColorQuote(textColorQuote);} private slots: void linkClicked(const QUrl &url); @@ -41,7 +47,13 @@ private: bool mShowImages; RSImageBlockWidget *mImageBlockWidget; bool mLinkClickActive; - RsSyntaxHighlighter *highliter; + RsSyntaxHighlighter *highlighter; +#ifdef RSTEXTBROWSER_CHECKIMAGE_DEBUG + QRect mCursorRectStart; + QRect mCursorRectLeft; + QRect mCursorRectRight; + QRect mCursorRectEnd; +#endif }; #endif // RSTEXTBROWSER_H diff --git a/retroshare-gui/src/gui/common/StyledElidedLabel.cpp b/retroshare-gui/src/gui/common/StyledElidedLabel.cpp index 68c84d0be..3a196dc24 100644 --- a/retroshare-gui/src/gui/common/StyledElidedLabel.cpp +++ b/retroshare-gui/src/gui/common/StyledElidedLabel.cpp @@ -25,19 +25,24 @@ /** Constructor */ StyledElidedLabel::StyledElidedLabel(QWidget *parent) - : ElidedLabel(parent) + : ElidedLabel(parent), _lastFactor(-1) { } StyledElidedLabel::StyledElidedLabel(const QString &text, QWidget *parent) - : ElidedLabel(text, parent) + : ElidedLabel(text, parent), _lastFactor(-1) { } void StyledElidedLabel::setFontSizeFactor(int factor) { - QFont f = font(); - qreal fontSize = factor * f.pointSizeF() / 100; - f.setPointSizeF(fontSize); - setFont(f); + int newFactor = factor; + if (factor > 0) { + if (_lastFactor > 0) newFactor = 100 + factor - _lastFactor; + _lastFactor = factor; + QFont f = font(); + qreal fontSize = newFactor * f.pointSizeF() / 100; + f.setPointSizeF(fontSize); + setFont(f); + } } diff --git a/retroshare-gui/src/gui/common/StyledElidedLabel.h b/retroshare-gui/src/gui/common/StyledElidedLabel.h index c871cb9c8..dea9ccd51 100644 --- a/retroshare-gui/src/gui/common/StyledElidedLabel.h +++ b/retroshare-gui/src/gui/common/StyledElidedLabel.h @@ -34,6 +34,9 @@ public: StyledElidedLabel(const QString &text, QWidget *parent = NULL); void setFontSizeFactor(int factor); + +private: + int _lastFactor; }; #endif diff --git a/retroshare-gui/src/gui/gxs/GxsCommentTreeWidget.cpp b/retroshare-gui/src/gui/gxs/GxsCommentTreeWidget.cpp index 3e7ec7b8f..7631ad23f 100644 --- a/retroshare-gui/src/gui/gxs/GxsCommentTreeWidget.cpp +++ b/retroshare-gui/src/gui/gxs/GxsCommentTreeWidget.cpp @@ -418,19 +418,21 @@ void GxsCommentTreeWidget::service_loadThread(const uint32_t &token) std::cerr << "GxsCommentTreeWidget::service_loadThread() Got Comment: " << comment.mMeta.mMsgId; std::cerr << std::endl; - GxsIdRSTreeWidgetItem *item = new GxsIdRSTreeWidgetItem(NULL); + GxsIdRSTreeWidgetItem *item = new GxsIdRSTreeWidgetItem(NULL) ; QString text; { - QDateTime qtime; - qtime.setTime_t(comment.mMeta.mPublishTs); + QDateTime qtime ; + qtime.setTime_t(comment.mMeta.mPublishTs) ; - text = qtime.toString("yyyy-MM-dd hh:mm:ss"); - item->setText(PCITEM_COLUMN_DATE, text); + text = qtime.toString("yyyy-MM-dd hh:mm:ss") ; + item->setText(PCITEM_COLUMN_DATE, text) ; + item->setToolTip(PCITEM_COLUMN_DATE, text) ; } text = QString::fromUtf8(comment.mComment.c_str()); item->setText(PCITEM_COLUMN_COMMENT, text); + item->setToolTip(PCITEM_COLUMN_COMMENT, text); RsGxsId authorId = comment.mMeta.mAuthorId; item->setId(authorId, PCITEM_COLUMN_AUTHOR, false); diff --git a/retroshare-gui/src/gui/gxs/GxsCreateCommentDialog.ui b/retroshare-gui/src/gui/gxs/GxsCreateCommentDialog.ui index 374949716..f989ccb6e 100644 --- a/retroshare-gui/src/gui/gxs/GxsCreateCommentDialog.ui +++ b/retroshare-gui/src/gui/gxs/GxsCreateCommentDialog.ui @@ -13,9 +13,9 @@ Make Comment - + - + <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN" "http://www.w3.org/TR/REC-html40/strict.dtd"> <html><head><meta name="qrichtext" content="1" /><style type="text/css"> @@ -26,11 +26,11 @@ p, li { white-space: pre-wrap; } - + - + - + Qt::Horizontal @@ -43,7 +43,7 @@ p, li { white-space: pre-wrap; } - + Signed by @@ -55,7 +55,7 @@ p, li { white-space: pre-wrap; } - + @@ -72,6 +72,11 @@ p, li { white-space: pre-wrap; } + + MimeTextEdit + QTextEdit +
gui/common/MimeTextEdit.h
+
GxsIdChooser QComboBox diff --git a/retroshare-gui/src/gui/gxs/GxsIdChooser.cpp b/retroshare-gui/src/gui/gxs/GxsIdChooser.cpp index 9ce07b77b..48ec40074 100644 --- a/retroshare-gui/src/gui/gxs/GxsIdChooser.cpp +++ b/retroshare-gui/src/gui/gxs/GxsIdChooser.cpp @@ -195,7 +195,7 @@ bool GxsIdChooser::isInConstraintSet(const RsGxsId& id) const return mConstraintIdsSet.find(id) != mConstraintIdsSet.end() ; } -void GxsIdChooser::setEntryEnabled(int indx,bool enabled) +void GxsIdChooser::setEntryEnabled(int indx,bool /*enabled*/) { removeItem(indx) ; diff --git a/retroshare-gui/src/gui/gxs/GxsMessageFramePostWidget.cpp b/retroshare-gui/src/gui/gxs/GxsMessageFramePostWidget.cpp index f9808a4d9..df5442bcd 100644 --- a/retroshare-gui/src/gui/gxs/GxsMessageFramePostWidget.cpp +++ b/retroshare-gui/src/gui/gxs/GxsMessageFramePostWidget.cpp @@ -59,7 +59,7 @@ void GxsMessageFramePostWidget::groupIdChanged() fillComplete(); } -QString GxsMessageFramePostWidget::groupName(bool withUnreadCount) +QString GxsMessageFramePostWidget::groupName(bool /*withUnreadCount*/) { QString name = groupId().isNull () ? tr("No name") : mGroupName; diff --git a/retroshare-gui/src/gui/gxschannels/CreateGxsChannelMsg.ui b/retroshare-gui/src/gui/gxschannels/CreateGxsChannelMsg.ui index 5c603cb93..c9e4c3346 100644 --- a/retroshare-gui/src/gui/gxschannels/CreateGxsChannelMsg.ui +++ b/retroshare-gui/src/gui/gxschannels/CreateGxsChannelMsg.ui @@ -20,8 +20,17 @@ :/images/logo/logo_16.png:/images/logo/logo_16.png
- - + + + 0 + + + 0 + + + 0 + + 0 @@ -31,14 +40,14 @@ - + QFrame::StyledPanel QFrame::Raised - + @@ -53,15 +62,15 @@ 0 - + Channel Post - + - + - + 75 @@ -86,9 +95,9 @@ - + - + <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN" "http://www.w3.org/TR/REC-html40/strict.dtd"> <html><head><meta name="qrichtext" content="1" /><style type="text/css"> @@ -157,15 +166,15 @@ p, li { white-space: pre-wrap; } - + Message - + - + - + 75 @@ -183,14 +192,14 @@ p, li { white-space: pre-wrap; } - + - + :/images/attachment.png:/images/attachment.png @@ -198,9 +207,9 @@ p, li { white-space: pre-wrap; } Attachments - + - + @@ -210,7 +219,7 @@ p, li { white-space: pre-wrap; } - + 16777215 @@ -229,7 +238,7 @@ p, li { white-space: pre-wrap; } - + Qt::Horizontal @@ -281,7 +290,7 @@ p, li { white-space: pre-wrap; } - + Qt::ScrollBarAlwaysOn @@ -293,7 +302,7 @@ p, li { white-space: pre-wrap; } 0 0 - 98 + 523 24 @@ -303,11 +312,20 @@ p, li { white-space: pre-wrap; } 0 - + 3 - + + 3 + + + 3 + + + 3 + + 3 @@ -324,7 +342,7 @@ p, li { white-space: pre-wrap; } Drag and Drop Files from Search Results - + @@ -336,7 +354,7 @@ p, li { white-space: pre-wrap; } - + @@ -378,10 +396,14 @@ p, li { white-space: pre-wrap; }
gui/common/HeaderFrame.h
1 + + MimeTextEdit + QTextEdit +
gui/common/MimeTextEdit.h
+
- diff --git a/retroshare-gui/src/gui/gxsforums/GxsForumThreadWidget.cpp b/retroshare-gui/src/gui/gxsforums/GxsForumThreadWidget.cpp index 29033ae09..24c4729cd 100644 --- a/retroshare-gui/src/gui/gxsforums/GxsForumThreadWidget.cpp +++ b/retroshare-gui/src/gui/gxsforums/GxsForumThreadWidget.cpp @@ -517,8 +517,7 @@ void GxsForumThreadWidget::contextMenuTextBrowser(QPoint point) contextMnu->addSeparator(); - QTextCursor cursor = ui->postText->cursorForPosition(point); - if(ImageUtil::checkImage(cursor)) + if(ui->postText->checkImage(point)) { ui->actionSave_image->setData(point); contextMnu->addAction(ui->actionSave_image); diff --git a/retroshare-gui/src/gui/settings/ServerPage.cpp b/retroshare-gui/src/gui/settings/ServerPage.cpp index 581a23183..9773570bb 100755 --- a/retroshare-gui/src/gui/settings/ServerPage.cpp +++ b/retroshare-gui/src/gui/settings/ServerPage.cpp @@ -486,7 +486,7 @@ void ServerPage::addPeerToIPTable(QTableWidget *table,int row,const BanListPeer& void ServerPage::toggleGroupIps(bool b) { rsBanList->enableAutoRange(b) ; } void ServerPage::setGroupIpLimit(int n) { rsBanList->setAutoRangeLimit(n) ; } -void ServerPage::ipFilterContextMenu(const QPoint& point) +void ServerPage::ipFilterContextMenu(const QPoint& /*point*/) { QMenu contextMenu(this) ; int row = ui.filteredIpsTable->currentRow(); @@ -604,7 +604,7 @@ void ServerPage::ipWhiteListContextMenu(const QPoint& /* point */) if(item == NULL) return ; - bool status = item->data(Qt::UserRole).toBool(); + //bool status = item->data(Qt::UserRole).toBool(); contextMenu.addAction(tr("Remove"),this,SLOT(removeWhiteListedIp())); diff --git a/retroshare-gui/src/gui/settings/rsharesettings.cpp b/retroshare-gui/src/gui/settings/rsharesettings.cpp index 530ffd766..1d0507337 100644 --- a/retroshare-gui/src/gui/settings/rsharesettings.cpp +++ b/retroshare-gui/src/gui/settings/rsharesettings.cpp @@ -789,7 +789,10 @@ bool RshareSettings::getRetroShareProtocol() } } #elif defined(Q_OS_LINUX) - QFile desktop("/usr/share/applications/RetroShare06.desktop"); + QFile desktop("/usr/share/applications/retroshare06.desktop"); + if (!desktop.exists()) { + desktop.setFileName("/usr/share/applications/RetroShare06.desktop"); + } if (desktop.exists()) { desktop.open(QIODevice::ReadOnly | QIODevice::Text); QTextStream in(&desktop); @@ -799,7 +802,7 @@ bool RshareSettings::getRetroShareProtocol() } desktop.close(); if (lines.contains("Exec=" + getAppPathForProtocol())) - if (lines.contains("MimeType=x-scheme-handler/retroshare")) + if (lines.contains("MimeType=x-scheme-handler/retroshare;")) return true; } #else diff --git a/retroshare-gui/src/lang/retroshare_de.ts b/retroshare-gui/src/lang/retroshare_de.ts index 4470cd4dd..0fd9b3ae3 100644 --- a/retroshare-gui/src/lang/retroshare_de.ts +++ b/retroshare-gui/src/lang/retroshare_de.ts @@ -402,7 +402,7 @@ p, li { white-space: pre-wrap; } Description: - Beschreibung + Beschreibung: @@ -514,7 +514,7 @@ p, li { white-space: pre-wrap; } Choose the language used in RetroShare - Wähle die Sprache, die RetroShare verwendet + Wähle die Sprache, die RetroShare verwenden soll @@ -771,7 +771,7 @@ Aber denke daran, dass alle Daten hier VERLOREN gehen werden, wenn wir die Proto Click to change your avatar - Klick zum Ändern deines Avatars + Klicke zum Ändern deines Avatars @@ -1417,7 +1417,7 @@ Aber denke daran, dass alle Daten hier VERLOREN gehen werden, wenn wir die Proto Select lobbies at left to show details. Double click lobbies to enter and chat. Keine Lobby ausgewählt. -Wähle links eine Lobby aus, um Details anzuzeigen. +Wähle links eine Lobby aus, um die Details anzusehen. Doppelklicke auf Lobbys um sie zu betreten und zu chatten. @@ -1630,7 +1630,7 @@ Doppelklicke auf Lobbys um sie zu betreten und zu chatten. Send as plain text by default - + Sende einen standart Klartext diff --git a/retroshare-gui/src/lang/retroshare_ru.qm b/retroshare-gui/src/lang/retroshare_ru.qm index cba101be1..9d00e79d8 100644 Binary files a/retroshare-gui/src/lang/retroshare_ru.qm and b/retroshare-gui/src/lang/retroshare_ru.qm differ diff --git a/retroshare-gui/src/lang/retroshare_ru.ts b/retroshare-gui/src/lang/retroshare_ru.ts index 1506404c3..fdc6378c1 100644 --- a/retroshare-gui/src/lang/retroshare_ru.ts +++ b/retroshare-gui/src/lang/retroshare_ru.ts @@ -1,6 +1,6 @@ - + AWidget @@ -560,7 +560,7 @@ p, li { white-space: pre-wrap; } On List Ite&m - + Отдельным списком @@ -660,7 +660,7 @@ p, li { white-space: pre-wrap; } Disable SysTray ToolTip - + Трэй без подсказки @@ -1058,7 +1058,7 @@ p, li { white-space: pre-wrap; } Ban this person (Sets negative opinion) - + Забанить этого пользователя (устанавливает негативную репутацию) @@ -1068,12 +1068,12 @@ p, li { white-space: pre-wrap; } Sort by Name - Сортировать по имени + Сортировать по имени Sort by Activity - + Сортировать по последней активности @@ -1310,7 +1310,7 @@ p, li { white-space: pre-wrap; } Anonymous IDs accepted - + Анонимные ID разрешены @@ -1556,27 +1556,27 @@ Double click lobbies to enter and chat. Distant Chat - + Удаленный чат Everyone - + Кого угодно Contacts - Контакты + Контакты Nobody - + Никого Accept encrypted distant chat from - + Разрешить шифрованный удаленный чат от @@ -1631,7 +1631,7 @@ Double click lobbies to enter and chat. Send as plain text by default - + Посылать как простой текст @@ -1775,7 +1775,7 @@ Double click lobbies to enter and chat. UserName - + Имя пользователя @@ -2028,17 +2028,17 @@ Double click lobbies to enter and chat. Quote - Цитата + Цитата Quotes the selected text - + Цитировать выбранный текст Drop Placemark - + Поставить метку @@ -2048,23 +2048,23 @@ Double click lobbies to enter and chat. Save image - + Сохранить изображение Send as PlainText - + Послать как простой текст Send as plain text without font. - + Послать как простой текст без шрифта Don't replace tag with Emote Icon. - + Не заметь текст смайлами @@ -2075,13 +2075,15 @@ Double click lobbies to enter and chat. It remains %1 characters after HTML conversion. - + %1 символов +после конвертирования в HTML. Warning: This message is too big of %1 characters after HTML conversion. - + Внимание: Это сообщение слишком большое, %1 символов +после конвертирования в HTML. @@ -2441,7 +2443,7 @@ after HTML conversion. Use this certificate to make friends: - + Используемый сертификат: @@ -2659,7 +2661,7 @@ after HTML conversion. Please, paste your friend's Retroshare certificate into the box below - + Пожалуйста введите сертификат вашего друга в поле внизу @@ -2784,7 +2786,7 @@ after HTML conversion. Email - Email + Email @@ -3211,7 +3213,7 @@ resources. The text below is your Retroshare certificate. You have to provide it to your friend - + Последущий текст это ваш сертификат RetroShare. Вы должны передать его вашему другу @@ -3881,7 +3883,7 @@ p, li { white-space: pre-wrap; } Invited Members - + Приглашенные Пользователи @@ -3891,7 +3893,7 @@ p, li { white-space: pre-wrap; } Known People - + Известные Пользователи @@ -3906,7 +3908,7 @@ p, li { white-space: pre-wrap; } Name: - Имя: + Имя: @@ -3916,7 +3918,7 @@ p, li { white-space: pre-wrap; } Contact author: - + Идентификатор Автора @@ -3926,12 +3928,12 @@ p, li { white-space: pre-wrap; } [Circle Admin] - + [Администратор Круга] Distribution: - + Достпно: @@ -3946,7 +3948,7 @@ p, li { white-space: pre-wrap; } Private - Частный + Частный @@ -3956,7 +3958,7 @@ p, li { white-space: pre-wrap; } Only visible to members of: - + Доступно только кругу: @@ -4051,28 +4053,28 @@ p, li { white-space: pre-wrap; } Circle name - + Имя Круга Update - + Обновить Close - Закрыть + Закрыть Create New Circle - + Создать Новый Круг Create - Создать + Создать @@ -4082,12 +4084,12 @@ p, li { white-space: pre-wrap; } Add Member - + Добавить члена Remove Member - + Удалить члена @@ -4101,12 +4103,12 @@ p, li { white-space: pre-wrap; } Group Name: - Имя группы: + Имя группы: Group ID: - + ID Группы Group Name @@ -4120,7 +4122,7 @@ p, li { white-space: pre-wrap; } To be defined - + Должно быть задано @@ -4367,12 +4369,12 @@ p, li { white-space: pre-wrap; } No compatible ID for this forum - + Нет совместимого ID для этого форума None of your identities is allowed to post in this forum. This could be due to the forum being limited to a circle that contains none of your identities, or forum flags requiring a PGP-signed identity. - + Ни один из ваших идентификаторов не имеет прав для отправки сообщений в этот форум. Возможно доступ к форуму ограничен кругом в котором вы не состоите, или форум требует наличие подписанного ID. @@ -4679,7 +4681,7 @@ Do you want to reject this message? No peer found in DHT - + Не найдено пиров в DHT @@ -4934,7 +4936,7 @@ Do you want to reject this message? Copy %1 to clipboard - + Копировать %1 в буфер обмена @@ -5190,7 +5192,7 @@ Do you want to reject this message? Relays - + Реле @@ -5981,7 +5983,7 @@ at least one peer was not added to a group Select file for importing your friendlist from - + Выберите файл из которого импортировать список друзей Select file for importing yoour friendlist from @@ -6714,7 +6716,7 @@ Fill in your PGP password when asked, to sign your new key. Register retroshare:// as URL protocol - + Заргеистрировать retroshare:// как URI протокол Register retroshare:// as URL protocol (Restart required) @@ -6743,7 +6745,7 @@ Fill in your PGP password when asked, to sign your new key. !!!The RetroShare's desktop file is missing or wrong!!! - + !!!Ярлык RetroShare отсутствует или поврежден!!! @@ -6768,12 +6770,12 @@ Fill in your PGP password when asked, to sign your new key. You have enough right. - + У вас достаточно прав. You don't have enough right. Run RetroShare as Admin to change this setting. - + У вас недостаточно прав. Запустите RetroShare от имени администратора для изменения этих настроек. @@ -7037,7 +7039,7 @@ p, li { white-space: pre-wrap; } Identity Name - + Имя идентификатора @@ -7057,17 +7059,17 @@ p, li { white-space: pre-wrap; } Stored data size - + Размер сохраненных данных Receive time (secs ago) - + Время получения (просшло секунд) Sending time (secs ago) - + Время отправки (прошло секунд) Data size @@ -7094,7 +7096,7 @@ p, li { white-space: pre-wrap; } Details - Подробности + Подробности @@ -7127,7 +7129,7 @@ p, li { white-space: pre-wrap; } [Unknown identity] - + [Неизвестный идентификатор] @@ -7148,7 +7150,7 @@ p, li { white-space: pre-wrap; } [Unknown] - [Неизвестный] + [Неизвестный] @@ -7286,12 +7288,12 @@ p, li { white-space: pre-wrap; } Share channel publish permissions - + Дать разрешение публиковать в канал You can allow your friends to publish in your channel, or send the publish permissions to another Retroshare instance of yours. Select the friends which you want to be allowed to publish in this channel. Note: it is currently not possible to revoke channel publish permissions. - + Вы можете разрешить вашим друзьям писать в канал или разрешать другим пользователям писать в канал. Выберите друзей которым вы хотите разрешить писать в канал. Имейте ввиду: на данный момент невозможно отменить разрешения записи в канал. @@ -7367,17 +7369,17 @@ p, li { white-space: pre-wrap; } Sort by Posts - + Сортировать по сообщениям You are admin (modify names and description using Edit menu) - + Вы администратор (изменяйте название и описание используя меню Редактировать) You have been granted as publisher (you can post here!) - + Вам разрешено публиковать @@ -7735,12 +7737,12 @@ p, li { white-space: pre-wrap; } New Comment: - + Новый Коментарий Comment Value - + Значение Коментария @@ -7911,27 +7913,27 @@ p, li { white-space: pre-wrap; } Public - Публичный + Публичный Restricted to members of circle " - + Только для членов круга " Restricted to members of circle - + Только для членов круга Your eyes only - + Только для вас You and your friend nodes - + Для вас и ваших друзей @@ -7956,18 +7958,18 @@ p, li { white-space: pre-wrap; } Administrator: - + Администратор: unknown - Неизвестно + Неизвестно Distribution: - + Распространение: @@ -8321,7 +8323,7 @@ before you can comment Save image - + Сохранить изображение @@ -8450,7 +8452,7 @@ before you can comment This message was obtained from %1 - + Это сообщение получено от %1 @@ -8460,58 +8462,58 @@ before you can comment Anonymous/unknown node IDs reputation threshold set to 0.4 - + Порог для агонимных/неизвестных id установлен в 0.4 Anonymous IDs reputation threshold set to 0.4 - + Порог для анонимных ID установлен в 0.4 Message routing info kept for 10 days - + Маршрут сообщения хранится 10 дней [unknown] - + [неизвестно] Public - Публичный + Публичный Restricted to members of circle " - + ограничено для членов круга " Restricted to members of circle - + Ограничено для членов круга Only friends nodes in group - + Только ноды друзей в группе Your eyes only - + Только для вас Distribution - Распределение + Распределение Anti-spam - + Анти-спам @@ -8841,29 +8843,29 @@ before you can comment Spam-protection - + Защита от спама Comments: - Комментарии: + Комментарии: TextLabel - Текстовая метка + Текстовая метка Distribution: - + Распространение: Anti Spam: - + Анти-Спам: @@ -8879,23 +8881,23 @@ before you can comment Restricted to circle: - + Ограничено кругом: Limited to your friends - + Только для ваших другей Allowed - + Разрешено Disallowed - + Запрещено @@ -8907,12 +8909,12 @@ before you can comment PGP signature required - + Необзодима PGP подпись Only friends nodes in group - + Только ноды друзей в группе @@ -8922,7 +8924,7 @@ before you can comment PGP signature from known ID required - + Необходима PGP подпись от известного ID @@ -8986,7 +8988,7 @@ before you can comment Restricted to Circle - + Ограничено кругом @@ -8996,7 +8998,7 @@ before you can comment Posts permissions: - + Разрешения: @@ -9006,17 +9008,17 @@ before you can comment All allowed - + Все Defavor unsigned IDs - + Запретить неподписанные ID Defavor unsigned IDs and IDs from unknown nodes - + Запретить неподписанные и неизвестные ID @@ -9098,7 +9100,7 @@ before you can comment Share publish permissions - + Поделиться правами на запись @@ -9217,42 +9219,42 @@ before you can comment Authenticated tunnels: - + Авторизованные туннели: Tunnel ID: %1 - + ID туннеля: %1 from: %1 - + от: %1 to: %1 - + к: %1 status: %1 - + статус: %1 total sent: %1 bytes - + всего отправленно: %1 байт total recv: %1 bytes - + всего получено: %1 байт Unknown Peer - Неизвестный пир + Неизвестный пир @@ -9605,7 +9607,7 @@ p, li { white-space: pre-wrap; } Owner node ID : - ID владельца узла + ID владельца узла: @@ -9615,17 +9617,17 @@ p, li { white-space: pre-wrap; } Owner node name : - Имя владельца узла + Имя владельца узла: Identity name : - Псевдоним + Псевдоним: Identity ID : - ID личности + ID личности: @@ -9726,7 +9728,7 @@ p, li { white-space: pre-wrap; } Overall: - Общая + Общая: @@ -9836,17 +9838,17 @@ p, li { white-space: pre-wrap; } Create new circle - + Создать новы круг Persons - + Участники Person - + Участник @@ -9865,27 +9867,27 @@ p, li { white-space: pre-wrap; } Circles - Круги + Круги Circle name - + Имя круга Membership - Членство + Членство Public Circles - Публичные Круги + Публичные Круги Personal Circles - Личные Круги + Личные Круги @@ -9911,12 +9913,12 @@ p, li { white-space: pre-wrap; } Owner node ID : - ID владельца узла + ID владельца узла : Identity name : - Псевдоним + Псевдоним : @@ -9941,12 +9943,12 @@ p, li { white-space: pre-wrap; } Identity ID : - ID личности + ID личности : Owner node name : - Имя владельца узла + Имя владельца узла : @@ -9956,7 +9958,7 @@ p, li { white-space: pre-wrap; } Send Invite - + Пригласить @@ -9996,7 +9998,7 @@ p, li { white-space: pre-wrap; } Overall: - Общая + Общая: Owned by you @@ -10010,12 +10012,12 @@ p, li { white-space: pre-wrap; } ID - + ID Search ID - + Искомый ID @@ -10033,22 +10035,22 @@ p, li { white-space: pre-wrap; } My own identities - + Мои идентификаторы My contacts - + Мои контакты Owned by myself - + Мои Linked to my node - + Связанные с моей нодой @@ -10058,162 +10060,162 @@ p, li { white-space: pre-wrap; } Other circles - + Другие круги Circles I belong to - + Круги со мной Circle ID: - + ID круга: Visibility: - + Видимость: Private (only visible to invited members) - + Частный (видим только членам) Only visible to full members of circle - + Видим только полноценным членам круга Public - Публичный + Публичный Your role: - + Ваша роль: Administrator (Can edit invite list, and request membership). - + Администратор (Может редактировать лист приглашений и запросов членства). User (Can only request membership). - + Пользователь (Может запросить членство). Distribution: - + Распространение: subscribed (Receive/forward membership requests from others and invite list). - + подписан (получает/передает запросы членства от других). unsubscribed (Only receive invite list). - + неподписанный (получает только праглашения). Your status: - + Ваш статус: Full member (you have access to data limited to this circle) - + Полноценный член (вы имеете доступ к данным достпным этому кругу) Not a member (do not have access to data limited to this circle) - + Не член (нет доступа к данным доступным кругу) Unknown ID : - + Незивестный ID : Identity ID: - + ID идентификатора: Status: - Статус: + Статус: Full member - + Полноценный член Invited by admin - + Пригглашен администратором Subscription request pending - + Запрошена подписка unknown - Неизвестно + Неизвестно Invited - + Приглашен Subscription pending - + Ожидание подписки Member - + Член Edit Circle - + Редактировать Круг See details - + Смотреть детали Request subscription - + Запросить подписку Accept circle invitation - + ПРинять приглашение в круг Quit this circle - + Покинуть круг Cancel subscribe request - + Отменить запрос подписки @@ -10221,17 +10223,17 @@ p, li { white-space: pre-wrap; } for identity - + для идентификатора Revoke this member - + Выгнать члена Grant membership - + Разрешить членство @@ -10245,24 +10247,24 @@ These identities will soon be not supported anymore. [Unknown node] - + [Неизвестная нода] Unverified signature from node - + Неподтвержденная подпись от ноды Unchecked signature - + Нероверенная подпись [unverified] - + [неподтверждено] @@ -10292,27 +10294,27 @@ These identities will soon be not supported anymore. Add to Contacts - + Добавить в контакты Remove from Contacts - + Удалить из контактов Set positive opinion - + Позитивное мнение Set neutral opinion - + Нейтральное мнение Set negative opinion - + Негативное мнение @@ -10327,22 +10329,22 @@ These identities will soon be not supported anymore. Hi,<br>I want to be friends with you on RetroShare.<br> - + Привет,<br>Я хочу дружить с тобой в RetroShare.<br> You have a friend invite - + Вы получили предложение дружбы Respond now: - + Ответить сейчас: Thanks, <br> - Спасибо, <br> + Спасибо, <br> @@ -10404,7 +10406,7 @@ These identities will soon be not supported anymore. Distant chat refused with this person. - В удалённом чате с этим человеком отказано + В удалённом чате с этим человеком отказано. @@ -10694,17 +10696,17 @@ These identities will soon be not supported anymore. Save image - + Сохранить изображение Cannot save the image, invalid filename - + Невозможно сохранить изображение, не верное имя файла Not an image - + Не является изображением @@ -11120,12 +11122,12 @@ RetroShare безопасно приостановит доступ диска Address list: - + Список адресов Recommend this friend - + Рекомендовать этого друга @@ -11235,17 +11237,17 @@ RetroShare безопасно приостановит доступ диска All addresses (mixed) - + Все адреса (смешано) All people - + Все люди My contacts - + Мои контакты @@ -11631,22 +11633,22 @@ Do you want to save message ? Everyone - + Все Contacts - Контакты + Контакты Nobody - + Никто Accept encrypted distant messages from - + Принимать зашифрованное сообщение от @@ -12382,7 +12384,7 @@ Do you want to save message ? This message goes to a distant person. - + Это сообщение будет отправлено удаленному участнику. @@ -12448,12 +12450,12 @@ Do you want to save message ? Spoiler - + Спойлер Select text to hide, then push this button - + Выберите текст который нужно скрыть, затем нажмите эту кнопку @@ -13466,7 +13468,7 @@ p, li { white-space: pre-wrap; } Below is the node's PGP key. It identifies the node and all its locations. A "Retroshare certificate" that you can exchange in order to make friends, is in the the "details" of each separate location. - + Ниже указан PGP ключ ноды, он определяет ноду и все её местоположения, "Сертификат RetroShare" который может быть использован для создания дружбы находится на вкладки "детали" в каждой отдельной локации @@ -13481,12 +13483,12 @@ p, li { white-space: pre-wrap; } Options - Параметры + Параметры These options apply to all locations of the same node: - + Эти опции применяются для всех локаций этой ноды @@ -13496,7 +13498,7 @@ p, li { white-space: pre-wrap; } Use as direct source, when available - + Использовать как прямой источник, если возможно @@ -13506,7 +13508,7 @@ p, li { white-space: pre-wrap; } Auto-download recommended files from this node - Авто-загрузка рекомендованных файлов с этого узла + Авто-загрузка рекомендованных файлов с этого узла @@ -13516,23 +13518,23 @@ p, li { white-space: pre-wrap; } Require white list clearance - Требуется разрешение белого списка + Требуется разрешение белого списка Max upload speed (0=unlimited) - + Максимальная скорость отдачи (0 - неограничено) Max download speed (0=unlimited) - + Максимальная скорость скачивания (0 - неограничено) kB/s - + kB/s @@ -13802,37 +13804,37 @@ p, li { white-space: pre-wrap; } Chat with this person - Начать чат + Начать чат Chat with this person as... - Инициировать чат с этим человеком от имени... + Инициировать чат с этим человеком от имени... Send message to this person - + Послать сообщение Person details - + Детали Distant chat cannot work - Удалённый чат не может работать + Удалённый чат не может работать Distant chat refused with this person. - В удалённом чате с этим человеком отказано + В удалённом чате с этим человеком отказано. Error code - Код ошибки + Код ошибки @@ -13840,22 +13842,22 @@ p, li { white-space: pre-wrap; } Identities handling - + Обработка идентификаторов ban all identities of a node when more than - + Банить все идентификаторы ноды если более чем 1 of them have a negative opinion - + из них имеет негативную репутацию People - Участники + Участники @@ -14402,7 +14404,7 @@ malicious behavior of crafted plugins. Chat remotely closed. Please close this window. - + Чат закрыт другой стороной. Пожалуйста закройте это окно. @@ -14659,12 +14661,12 @@ malicious behavior of crafted plugins. New Comment: - + Новый коментарий: Comment Value - + Значение Комантария @@ -15196,12 +15198,12 @@ and open the Make Friend Wizard. Warning: Retroshare is about to ask your system to open this file. - + Внимание: RetroShare собирается запросить открытие этого файла системой. Before you do so, please make sure that this file does not contain malicious executable code. - + Перед тем как это делать убедитесь в том что файл не содержит вредоносного кода. @@ -15316,17 +15318,17 @@ and open the Make Friend Wizard. Posted not found - + Не найдено Posted message not found - + Сообщение не найдено Posted messages not found - + Сообщения не найдены @@ -15645,7 +15647,8 @@ Reported error is: Security: no anonymous IDs - + +Безопасность: Анонимные ID запрещены @@ -16349,7 +16352,7 @@ Characters <b>",|,/,\,&lt;,&gt;,*,?</b> will be replace File Path - + Путь к файлу @@ -16621,7 +16624,7 @@ Reducing image to %1x%2 pixels? Registry Access Error. Maybe you need Administrator right. - + Ошибка доуступа к реестру, возможно необходимы права администратора. @@ -18120,7 +18123,7 @@ Select the Friends with which you want to Share your Channel. Lobby - + Лоби @@ -19704,12 +19707,12 @@ Try to be patient! Anonymous tunnels - + Анонимный туннели Authenticated tunnels - + Авторизованные туннели diff --git a/retroshare-gui/src/util/HandleRichText.cpp b/retroshare-gui/src/util/HandleRichText.cpp index 5f494224c..d5088d2df 100644 --- a/retroshare-gui/src/util/HandleRichText.cpp +++ b/retroshare-gui/src/util/HandleRichText.cpp @@ -71,39 +71,73 @@ class EmbedInHtmlAhref : public EmbedInHtml public: EmbedInHtmlAhref() : EmbedInHtml(Ahref) { - // myRE.setPattern("(\\bretroshare://[^\\s]*)|(\\bhttps?://[^\\s]*)|(\\bfile://[^\\s]*)|(\\bwww\\.[^\\s]*)"); + // The following regular expressions for finding URLs in + // plain text are borrowed from https://regex101.com/r/eR9yG2/4 + //Modified to: (Adding \s to stop when query have space char else don't stop at end.) + // ((?<=\s)(([a-z0-9.+-]+):)((\/\/)(\/|(((([^\/:@?&#\s]+)(:([^\/@?&#\s]+))?)@)?([^:\/?&#\s]+)(:([1-9][0-9]*))?)(?=[\/#$?]))))(([^#?\s]+)?(\?([^#\s]+))?(#([^\s]+))?([\s])?) + // regAddress .|| .| || | .| | . . .| .| ..| .../regPath .| | . .| .| ./ + // regBef/reChar .|| .| || | .| | . . .| .| ..| ... regPathnam/| | . .regHash /regEnd/har + // regScheme /regGrp5| || | .| | . . .| .| ..| ../ regSearch . / + // |regS/ash || | .| | . . .| .| ..| .. regQuery/ + // regFileAuthHost .| | . . .| .| ..| ./ + // regAuthHost .| | . . .| .| ./regPosLk / + // regUserPass .| | . . /regHost /regPort / + // regUser /| | . . + // regGrp12 . / + // regPassCharse/ + // + // to get all group captured. + // Test patern: " https://user:password@example.com:8080/./api/api/../users/./get/22iohoife.extension?return=name&return=email&a[]=3&a[]=3&a[]=3&a[]=3&a[]=3&a[]=3&a[]=3&a[]=3&a[]=3&a[]=3#test " - // The following regular expressions for finding URLs in - // plain text are borrowed from *gnome-terminal*: + QString regBeforeChar = ""; //"(?<=\\s)";//WARNING, Look Behind not supported by Qt + QStringList regSchemes; + // regSchemes.append("news:"); + // regSchemes.append("telnet:"); + // regSchemes.append("nntp:"); + // regSchemes.append("file:/"); + regSchemes.append("https?:"); + // regSchemes.append("ftps?:"); + // regSchemes.append("sftp:"); + // regSchemes.append("webcal:"); + regSchemes.append("retroshare:"); - QString regPassCharset = "[-\\w,?;\\.:/!%$^*&~\\\"#']"; - QString regHost = "[-\\w]+(\\.[-\\w]+)*"; - QString regPort = "(?:\\:\\d{1,5})?"; - QString regPathCharset = "[-\\w_$\\.+!*,;@&=?/~#%]"; - QString regPathTermSet = "[^\\]'.}<>) \\t\\r\\n,\\\"]"; - QStringList regSchemes; -// regSchemes.append("news:"); -// regSchemes.append("telnet:"); -// regSchemes.append("nntp:"); -// regSchemes.append("file:/"); - regSchemes.append("https?:"); -// regSchemes.append("ftps?:"); -// regSchemes.append("sftp:"); -// regSchemes.append("webcal:"); - regSchemes.append("retroshare:"); - QString regScheme = "((?:" + regSchemes.join(")|(?:") + "))"; - QString regUserPass = "[-\\w]+(?:%s+)?" % regPassCharset; - QString regUrlPath = "(?:(/" + regPathCharset + "+(?:[(]" + regPathCharset +"*[)])*" + regPathCharset + "*)*" + regPathTermSet + ")?"; - QStringList regHotLinkFinders; - regHotLinkFinders.append(regScheme + "//(?:" + regUserPass + "@)?"+ regHost + regPort + regUrlPath); -// regHotLinkFinders.append("(?:(?:www)|(?:ftp))[-\\w]*\\." + regHost + regPort + regUrlPath); -// regHotLinkFinders.append("(?:(?:callto:)|(?:h323:)|(?:sip:))[-\\w][-\\w\\.]*(?:" + regPort + "/[a-z0-9]+)?@" + regHost); -// regHotLinkFinders.append("(?:mailto:)?[-\\w][-\\w\\.]*@[-\\w]+\\." + regHost); -// regHotLinkFinders.append("news:[\\w^_{|}~!\\\"#$%&'()*+,\\./;:=?`]+"); - while (!regHotLinkFinders.isEmpty()) { - myREs.append(QRegExp(regHotLinkFinders.takeFirst(), Qt::CaseInsensitive)); - }; - } + QString regScheme = "(?:" + regSchemes.join(")|(?:") + ")";//2nd Group: "https:" //3rd group inside + + QString regSlash = "(\\/\\/)";//5th Group: "//" + + QString regUser = "([^\\/:@?&#\\s]+)";//10th Group: "user" + QString regPassCharset = "([^\\/@?&#\\s]+)";//12th Group "password" + QString regGrp12 = "(:" + regPassCharset + ")?"; // 11th Group: ":password" + QString regUserPass = "((" + regUser + regGrp12 + ")@)?"; //8th Group: "user:password@" with 9th inside + + QString regHost = "([^:\\/?&#\\s]+)"; //13th Group: "example.com" + QString regPort = "(:([1-9][0-9]*))?"; //14th Group: ":8080" with 15th inside + + QString regAuthHost = regUserPass + regHost + regPort; //7th Group: "user:password@example.com:8080" + QString regPosLk = ""; //Positive Lookahead + + QString regFileAuthHost = "(\\/|" + regAuthHost + regPosLk + ")"; //6th Group: "user:password@example.com:8080" Could be "/" with "file:///" + QString regGrp5 = "(" + regSlash + regFileAuthHost + ")"; //4th Group: "//user:password@example.com:8080" + QString regAddress = "(" + regBeforeChar + regScheme + regGrp5 + ")"; //1rst Group: "https://user:password@example.com:8080" + + QString regPathName = "([^#?\\s]+)?"; //17th Group: "/./api/api/../users/./get/22iohoife.extension" + + QString regQuery = "([^#\\s]+)"; //19th Group: "return=name&return=email&a[]=3&a[]=3&a[]=3&a[]=3&a[]=3&a[]=3&a[]=3&a[]=3&a[]=3&a[]=3" + QString regSearch = "(\\?" + regQuery + ")?"; //18th Group: "?return=name&return=email&a[]=3&a[]=3&a[]=3&a[]=3&a[]=3&a[]=3&a[]=3&a[]=3&a[]=3&a[]=3" + + QString regHash = "(#([^\\s]+))?"; //20th Group: "#test" 21th inside + QString regEndChar = "";//"([\\s])?"; //22th Group: " " + QString regPath = "(" + regPathName + regSearch + regHash + regEndChar +")"; //16th Group: "/./api/api/../users/./get/22iohoife.extension?return=name&return=email&a[]=3&a[]=3&a[]=3&a[]=3&a[]=3&a[]=3&a[]=3&a[]=3&a[]=3&a[]=3#test" + + QString regUrlPath = regAddress + regPath; + + QStringList regHotLinkFinders; + regHotLinkFinders.append(regUrlPath); + + while (!regHotLinkFinders.isEmpty()) { + myREs.append(QRegExp(regHotLinkFinders.takeFirst(), Qt::CaseInsensitive)); + }; + } }; diff --git a/retroshare-gui/src/util/imageutil.cpp b/retroshare-gui/src/util/imageutil.cpp index 01f8c4bcb..1a08ffb07 100644 --- a/retroshare-gui/src/util/imageutil.cpp +++ b/retroshare-gui/src/util/imageutil.cpp @@ -1,13 +1,13 @@ #include "imageutil.h" #include "util/misc.h" -#include -#include -#include -#include -#include -#include #include +#include +#include +#include +#include +#include +#include ImageUtil::ImageUtil() {} @@ -42,10 +42,3 @@ void ImageUtil::extractImage(QWidget *window, QTextCursor cursor) } } -bool ImageUtil::checkImage(QTextCursor cursor) -{ - cursor.movePosition(QTextCursor::Left, QTextCursor::MoveAnchor, 1); - cursor.movePosition(QTextCursor::Right, QTextCursor::KeepAnchor, 2); - QString imagestr = cursor.selection().toHtml(); - return imagestr.indexOf("base64,") != -1; -} diff --git a/retroshare-gui/src/util/imageutil.h b/retroshare-gui/src/util/imageutil.h index f8ac9016a..30e6ecb67 100644 --- a/retroshare-gui/src/util/imageutil.h +++ b/retroshare-gui/src/util/imageutil.h @@ -4,14 +4,12 @@ #include #include - class ImageUtil { public: ImageUtil(); static void extractImage(QWidget *window, QTextCursor cursor); - static bool checkImage(QTextCursor cursor); }; #endif // IMAGEUTIL_H diff --git a/retroshare-nogui/src/TerminalApiClient.cpp b/retroshare-nogui/src/TerminalApiClient.cpp index 6822004b4..6a08218c1 100644 --- a/retroshare-nogui/src/TerminalApiClient.cpp +++ b/retroshare-nogui/src/TerminalApiClient.cpp @@ -246,7 +246,7 @@ void TerminalApiClient::data_tick() if(!ask_for_password && runstate == "waiting_account_select" && last_char >= '0' && last_char <= '9' - && (last_char-'0') < accounts.size()) + && static_cast(last_char-'0') < accounts.size()) { std::string acc = accounts[last_char-'0']; JsonStream reqs; diff --git a/retroshare-nogui/src/introserver.cc b/retroshare-nogui/src/introserver.cc index 3734154b2..bc373c2da 100644 --- a/retroshare-nogui/src/introserver.cc +++ b/retroshare-nogui/src/introserver.cc @@ -293,8 +293,7 @@ int RsIntroServer::checkForNewCerts() for(;dirIt.isValid();dirIt.next()) { /* check entry type */ - std::string fname; - dirIt.d_name(fname); + std::string fname = dirIt.file_name(); std::string fullname = mCertLoadPath + "/" + fname; #ifdef RSIS_DEBUG std::cerr << "calling stats on " << fullname < -#include -#include - -#include -#include - -#include "util/rsstring.h" - -#define MENU_DEBUG 1 - -/********************************************************** - * Menu Base Interface. - */ - - // RsTermServer Interface. -void MenuInterface::reset(uint32_t /* chan_id */) -{ - mBase->reset(); - mCurrentMenu = mBase; - mInputRequired = false; - mUpdateTime = 0; -} - - - -int MenuInterface::tick() -{ -#ifdef MENU_DEBUG - std::cerr << "MenuInterface::tick()"; - std::cerr << std::endl; -#endif // MENU_DEBUG - - /* try to read a char */ - bool haveInput = false; - uint8_t keypress; - std::string output; - - uint32_t chan_id = 1; // dummy - for menu system. - - int read = mComms->recv(chan_id, &keypress, 1); -#ifdef MENU_DEBUG - std::cerr << "MenuInterface::tick() read " << read << " bytes"; - std::cerr << std::endl; -#endif // MENU_DEBUG - - if (read == 0) - { - haveInput = false; - /* make a harmless key */ - keypress = ' '; - } - else if (read == 1) - { - haveInput = true; - } - else - { - /* error, NON BLOCKING is handled by recv returning 0 */ - mComms->error(chan_id, "Bad Input"); - return -1; - } - - - /**** Main logic bit ****/ - /**** slow down the updates / refresh ****/ - - time_t now = time(NULL); -#define UPDATE_TIME 5 - if (!haveInput) - { - // If Input is Required, - if (mInputRequired) - { - std::cerr << "MenuInterface::tick() No Input & Required-No Output"; - std::cerr << std::endl; - return 0; - } - - // Output will just almost the same, so occasionally. - if (now < mUpdateTime + UPDATE_TIME) - { - std::cerr << "MenuInterface::tick() No Input-Slow Update"; - std::cerr << std::endl; - return 0; - } - - std::cerr << "MenuInterface::tick() No Input - but doing update."; - std::cerr << std::endl; - } - - uint32_t rt = process(keypress, mDrawFlags, output); - mInputRequired = (rt == MENU_PROCESS_NEEDDATA); - mUpdateTime = now; - - if (rt == MENU_PROCESS_QUIT) - { - return -1; - } - - if (output.size() > 0) - { - mComms->send(chan_id, output); - } - - return (haveInput); -} - - -int tailrec_printparents(Menu *m, std::string &buffer) -{ - Menu *p = m->parent(); - if (p) - { - tailrec_printparents(p, buffer); - } - buffer += m->ShortFnDesc(); - buffer += " => "; - return 1; -} - - - -uint32_t MenuInterface::process(char key, uint32_t drawFlags, std::string &buffer) -{ - -#ifdef MENU_DEBUG - std::cout << "MenuInterface::process(" << key << ")"; - std::cout << std::endl; -#endif // MENU_DEBUG - - /* call process on current menu */ - uint32_t rt = mCurrentMenu->process(key); - bool doRedraw = true; - bool showError = false; - bool showHelp = false; - -#ifdef MENU_DEBUG - std::cout << "MenuInterface::process() currentMenu says: " << rt; - std::cout << std::endl; -#endif // MENU_DEBUG - - - uint32_t base_rt = (rt & MENU_PROCESS_MASK); - bool needData = (rt & MENU_PROCESS_NEEDDATA); - switch(base_rt) - { - case MENU_PROCESS_NONE: - if (needData) - { - /* no redraw, this could be called many times */ - doRedraw = false; - } - break; - - case MENU_PROCESS_DONE: - /* no changes - operation performed, or noop */ - break; - - case MENU_PROCESS_ERROR: - /* Show Error at top of Page */ - showError = true; - break; - - case MENU_PROCESS_HELP: - /* Show Help at top of Page */ - showHelp = true; - break; - - case MENU_PROCESS_MENU: - /* new menu to switch to */ - if (mCurrentMenu->selectedMenu()) - { - std::cout << "MenuInterface::process() Switching Menus"; - std::cout << std::endl; - mCurrentMenu = mCurrentMenu->selectedMenu(); - } - else - { - std::cout << "MenuInterface::process() ERROR"; - std::cout << " SelectedMenu == NULL"; - std::cout << std::endl; - } - break; - - case MENU_PROCESS_TOP: - /* switch to Base Menu */ - mCurrentMenu = mBase; - break; - - case MENU_PROCESS_QUIT: - return MENU_PROCESS_QUIT; - break; - } - - if (drawFlags & MENU_DRAW_FLAGS_ECHO) - { - buffer += key; - } - - /* now we redraw, and wait for next data */ - if (!doRedraw) - { - return MENU_PROCESS_NEEDDATA; - } - - /* HEADER */ - for(int i = 0; i < 20; i++) - { - buffer += "\r\n"; - } - - /* ERROR */ - if (showError) - { - mCurrentMenu->showError(); - } - /* HELP */ - else if (showHelp) - { - mCurrentMenu->showHelp(); - } - - /* MENU PAGE */ - drawHeader(drawFlags, buffer); - mCurrentMenu->drawPage(drawFlags, buffer); - - if (needData) - return MENU_PROCESS_NEEDDATA; - - return MENU_PROCESS_NONE; -} - - - - -uint32_t MenuInterface::drawHeader(uint32_t drawFlags, std::string &buffer) -{ - buffer += "=======================================================\r\n"; - buffer += "Retroshare Terminal Menu V2.xxxx ======================\r\n"; - - unsigned int nTotal = 0; - unsigned int nConnected = 0; - rsPeers->getPeerCount(&nTotal, &nConnected, false); - - uint32_t netState = rsConfig->getNetState(); - std::string natState("Unknown"); - switch(netState) - { - default: - case RSNET_NETSTATE_BAD_UNKNOWN: - natState = "YELLOW:Unknown"; - break; - - case RSNET_NETSTATE_BAD_OFFLINE: - natState = "GRAY:Offline"; - break; - - case RSNET_NETSTATE_BAD_NATSYM: - natState = "RED:Nasty Firewall"; - break; - - case RSNET_NETSTATE_BAD_NODHT_NAT: - natState = "RED:NoDht & Firewalled"; - break; - - case RSNET_NETSTATE_WARNING_RESTART: - natState = "YELLOW:Restarting"; - break; - - case RSNET_NETSTATE_WARNING_NATTED: - natState = "YELLOW:Firewalled"; - break; - - case RSNET_NETSTATE_WARNING_NODHT: - natState = "YELLOW:DHT Disabled"; - break; - - case RSNET_NETSTATE_GOOD: - natState = "GREEN:Good!"; - break; - - case RSNET_NETSTATE_ADV_FORWARD: - natState = "GREEN:Forwarded Port"; - break; - } - - float downKb = 0; - float upKb = 0; - rsConfig->GetCurrentDataRates(downKb, upKb); - - rs_sprintf_append(buffer, "Friends %d / %d Network: %s\r\n", - nConnected, nTotal, natState.c_str()); - - rs_sprintf_append(buffer, "Down: %2.2f Up %2.2f\r\n", downKb, upKb); - - std::string menuState; - tailrec_printparents(mCurrentMenu, menuState); - - buffer += "Menu State: "; - buffer += menuState; - buffer += "\r\n"; - - buffer += "=======================================================\r\n"; - - return 1; -} - -/********************************************************** - * Menu (Base) - */ - -Menu::~Menu() -{ - /* cleanup children */ - mParent = NULL; - mSelectedMenu = NULL; - std::map::iterator it; - - for(it = mChildren.begin(); it != mChildren.end(); it++) - { - delete (it->second); - } - - mChildren.clear(); -} - -int Menu::addMenuItem(char key, Menu *child) -{ - std::map::iterator it; - it = mChildren.find(key); - if (it != mChildren.end()) - { - std::cout << "Menu::addMenuItem() ERROR DUPLICATE MENU ITEM"; - std::cout << std::endl; - return 0; - } - mChildren[key] = child; - child->setParent(this); - - return 1; -} - -void Menu::reset() -{ - mSelectedMenu = NULL; - std::map::iterator it; - for(it = mChildren.begin(); it != mChildren.end(); it++) - { - it->second->reset(); - } -} - - -uint32_t Menu::process(char key) -{ - /* try standard list ones */ - uint32_t rt = std_process(key); - if (rt) - { - return rt; - } - - /* now try children */ - rt = process_children(key); - if (rt) - { - return rt; - } - - return MENU_PROCESS_NONE; -} - -uint32_t Menu::std_process(char key) -{ - switch(key) - { - case MENU_KEY_QUIT: - return MENU_PROCESS_QUIT; - break; - case MENU_KEY_HELP: - return MENU_PROCESS_HELP; - break; - case MENU_KEY_TOP: - return MENU_PROCESS_TOP; - break; - case MENU_KEY_UP: - setSelectedMenu(parent()); - return MENU_PROCESS_MENU; - break; - } - - return MENU_PROCESS_NONE; -} - - -uint32_t Menu::process_children(char key) -{ - std::map::iterator it; - it = mChildren.find(key); - - if (it == mChildren.end()) - { - return MENU_PROCESS_NONE; - } - - /* have a child */ - - /* now return, depending on type */ - switch(it->second->op()) - { - case MENU_OP_NEEDDATA: - setSelectedMenu(it->second); - return MENU_PROCESS_MENU | MENU_PROCESS_NEEDDATA; - break; - - case MENU_OP_SUBMENU: - setSelectedMenu(it->second); - return MENU_PROCESS_MENU; - break; - - default: - case MENU_OP_INSTANT: - /* done already! */ - setSelectedMenu(NULL); - return MENU_PROCESS_DONE; - break; - - case MENU_OP_ERROR: - /* done already! */ - setSelectedMenu(NULL); - return MENU_PROCESS_ERROR; - break; - } -} - - -uint32_t Menu::drawPage(uint32_t drawFlags, std::string &buffer) -{ - buffer += "Universal Commands ( "; - if (!(drawFlags & MENU_DRAW_FLAGS_NOQUIT)) - { - buffer += (char) MENU_KEY_QUIT; - buffer += ":Quit "; - } - buffer += (char) MENU_KEY_HELP; - buffer += ":Help "; - buffer += (char) MENU_KEY_TOP; - buffer += ":Top "; - buffer += (char) MENU_KEY_UP; - buffer += ":Up "; - buffer += ")"; - buffer += "\r\n"; - - buffer += "Specific Commands ( "; - std::map::iterator it; - for(it = mChildren.begin(); it != mChildren.end(); it++) - { - buffer += (char) it->first; - buffer += ":"; - buffer += it->second->ShortFnDesc(); - buffer += " "; - } - buffer += ")"; - buffer += "\r\n"; - - return 1; -} - - -uint32_t Menu::drawHelpPage(uint32_t drawFlags, std::string &buffer) -{ - std::cout << "Menu Help: Universal Commands are:"; - std::cout << std::endl; - std::cout << "\tKey: " << (char) MENU_KEY_QUIT << " => Quit"; - std::cout << std::endl; - std::cout << "\tKey: " << (char) MENU_KEY_HELP << " => Help"; - std::cout << std::endl; - std::cout << "\tKey: " << (char) MENU_KEY_TOP << " => Top Menu"; - std::cout << std::endl; - std::cout << "\tKey: " << (char) MENU_KEY_UP << " => Up a Menu"; - std::cout << std::endl; - - std::cout << "Specific Commands are:"; - std::cout << std::endl; - std::map::iterator it; - for(it = mChildren.begin(); it != mChildren.end(); it++) - { - std::cout << "\tKey: " << (char) it->first << " => "; - std::cout << it->second->ShortFnDesc(); - std::cout << std::endl; - } - - return 1; -} - - -/********************************************************** - * Menu List (Base) - */ - - -uint32_t MenuList::drawPage(uint32_t drawFlags, std::string &buffer) -{ - Menu::drawPage(drawFlags, buffer); - - buffer += "Navigation Commands ("; - buffer += (char) MENULIST_KEY_NEXT; - buffer += ":Next "; - buffer += (char) MENULIST_KEY_PREV; - buffer += ":Prev "; - buffer += ")"; - buffer += "\r\n"; - - rs_sprintf_append(buffer, "MenuList::Internals ListSize: %d, SelectIdx: %d Cursor: %d\r\n", - getListCount(), mSelectIdx, mCursor); - - int i = 0; - - int listCount = getListCount(); - int startCount = mCursor + 1; - int endCount = mCursor + 10; - if (endCount > listCount) - { - endCount = listCount; - } - - if (mSelectIdx >= 0) - { - - rs_sprintf_append(buffer, "Current Selection Idx: %d : ", mSelectIdx); - std::string desc; - if (getEntryDesc(mSelectIdx, desc) & (desc != "")) - { - buffer += desc; - } - else - { - buffer += "Missing Description"; - } - buffer += "\r\n"; - } - else - { - buffer += "No Current Selection: Use 0 - 9 to choose an Entry"; - buffer += "\r\n"; - } - - - rs_sprintf_append(buffer, "Showing %d to %d of %d Entries\r\n", - startCount, endCount, listCount); - - std::list::iterator it; - for (it = mList.begin(); it != mList.end(); it++, i++) - { - int curIdx = i - mCursor; - if ((curIdx >= 0) && (curIdx < 10)) - { - if (i == mSelectIdx) - { - rs_sprintf_append(buffer, "SELECTED (%d) ", curIdx); - } - else - { - rs_sprintf_append(buffer, "\t(%d) ", curIdx); - } - std::string desc; - if (getEntryDesc(i, desc) & (desc != "")) - { - buffer += desc; - } - else - { - buffer += *it; - buffer += " => "; - buffer += "Missing Description"; - } - buffer += "\r\n"; - } - } - buffer += "\r\n"; - buffer += "Make Your Choice > "; - - return 1; -} - -uint32_t MenuList::drawHelpPage(uint32_t drawFlags, std::string &buffer) -{ - Menu::drawHelpPage(drawFlags, buffer); - - std::cout << "MenuList Help: Navigation Commands are:"; - std::cout << std::endl; - //std::cout << "\tKey: " << (char) MENULIST_KEY_LIST << " => List"; - //std::cout << std::endl; - std::cout << "\tKey: " << (char) MENULIST_KEY_NEXT << " => Next Page"; - std::cout << std::endl; - std::cout << "\tKey: " << (char) MENULIST_KEY_PREV << " => Prev Page"; - std::cout << std::endl; - - std::cout << "MenuList::drawPage() Internal Details"; - std::cout << std::endl; - std::cout << "List Size: " << getListCount(); - std::cout << std::endl; - std::cout << "SelectIdx: " << mSelectIdx; - std::cout << std::endl; - std::cout << "Cursor: " << mCursor; - std::cout << std::endl; - return 1; -} - - -void MenuList::reset() -{ - Menu::reset(); // clears children too. - - mList.clear(); - mSelectIdx = -1; - mCursor = 0; -} - -uint32_t MenuList::op() -{ - mList.clear(); - mSelectIdx = -1; - mCursor = 0; - - return MENU_OP_ERROR; // SUBMENU -> only for inherited classes; -} - -uint32_t MenuList::getListCount() -{ - return mList.size(); -} - -int MenuList::getCurrentKey(std::string &key) -{ - return getListEntry(mSelectIdx, key); -} - -int MenuList::getCurrentIdx(int &idx) -{ - idx = mSelectIdx; - return 1; -} - -int MenuList::getListEntry(int idx, std::string &key) -{ - if (idx < 0) - { - return MENU_ENTRY_NONE; - } - - std::list::iterator it; - int i = 0; - for (it = mList.begin(); (i < idx) && (it != mList.end()); it++, i++) ; - - if (it != mList.end()) - { - key = *it; - return MENU_ENTRY_OKAY; - } - return MENU_ENTRY_NONE; -} - -int MenuList::getEntryDesc(int idx, std::string &desc) -{ - desc = "Entry Description"; - return MENU_ENTRY_OKAY; -} - -uint32_t MenuList::process(char key) -{ - /* try standard list ones */ - uint32_t rt = Menu::process(key); - if (rt) - { - return rt; - } - - rt = list_process(key); - return rt; -} - -uint32_t MenuList::list_process(char key) -{ - if (((key >= '0') && (key <= '9')) || - ((key >= 'a') && (key <= 'f'))) - { - int idx = 0; - /* select index */ - if ((key >= '0') && (key <= '9')) - { - idx = key - '0'; - } - else - { - idx = key - 'a' + 9; - } - - /* now change selection, dependent on pagination */ - if (mCursor + idx < getListCount()) - { - mSelectIdx = mCursor + idx; - std::cout << "MenuList::list_process() Selected Idx: " << mSelectIdx; - std::cout << std::endl; - } - else - { - std::cout << "MenuList::list_process() Idx Out of Range"; - std::cout << std::endl; - } - - return MENU_PROCESS_DONE; /* ready for next key stroke */ - } - - - switch(key) - { - case MENULIST_KEY_LIST: - /* send a list to output */ - - return MENU_PROCESS_DONE; /* ready for next key stroke */ - break; - case MENULIST_KEY_NEXT: - /* shift to next page */ - if (mCursor + 10 < getListCount()) - { - mCursor += 10; - } - - return MENU_PROCESS_DONE; - break; - case MENULIST_KEY_PREV: - /* shift to prev page */ - if (((int) mCursor) - 10 >= 0) - { - mCursor -= 10; - } - - return MENU_PROCESS_DONE; - break; - } - - return MENU_PROCESS_NONE; -} - - -uint32_t MenuOpBasicKey::op_basic(std::string key) -{ - parent()->setErrorMessage("MenuOpBasicKey Not Overloaded Correctly"); - return MENU_OP_ERROR; -} - - -uint32_t MenuOpBasicKey::op() -{ - std::string key; - Menu *Parent=parent(); - MenuList *p = dynamic_cast(Parent); - - if (!p) - { - if (Parent) - { - Parent->setErrorMessage("Invalid (Basic) Menu Structure"); - } - return MENU_OP_ERROR; - } - - if (p->getCurrentKey(key)) - { - return op_basic(key); - } - - if (Parent) - { - Parent->setErrorMessage("Invalid Current Keys"); - } - return MENU_OP_ERROR; -} - - - -uint32_t MenuOpTwoKeys::op_twokeys(std::string parentkey, std::string key) -{ - parent()->setErrorMessage("MenuOpTwoKeys Not Overloaded Correctly"); - return MENU_OP_ERROR; -} - - -uint32_t MenuOpTwoKeys::op() -{ - std::string parentkey; - std::string key; - Menu *Parent=parent(); - MenuList *p = dynamic_cast(Parent); - - Menu *grandParent=parent()->parent(); - MenuList *gp = dynamic_cast(grandParent); - - if ((!gp) || (!p)) - { - if (Parent) - { - Parent->setErrorMessage("Invalid (TwoKeys) Menu Structure"); - } - return MENU_OP_ERROR; - } - - if ((gp->getCurrentKey(parentkey)) && (p->getCurrentKey(key))) - { - return op_twokeys(parentkey, key); - } - - if (Parent) - { - Parent->setErrorMessage("Invalid Current Keys"); - } - return MENU_OP_ERROR; -} - - - -/********************************************************** - * Menu Op Line Input (Base) - */ - - -uint32_t MenuOpLineInput::op() -{ - return MENU_OP_NEEDDATA; -} - - -uint32_t MenuOpLineInput::process_lines(std::string input) -{ - std::cout << "MenuOpLineInput::process_lines() => SHOULD BE OVERLOADED"; - std::cout << "Input Was: "; - std::cout << std::endl; - std::cout << "=================================================="; - std::cout << std::endl; - std::cout << input; - std::cout << "=================================================="; - std::cout << std::endl; - - return MENU_PROCESS_ERROR; -} - - -uint32_t MenuOpLineInput::process(char key) -{ - /* read data in and add to buffer */ - mInput += key; - if ((key != '\n') && (key != '\r')) - { - return MENU_PROCESS_NEEDDATA; - } - - uint32_t rt = process_lines(mInput); - - switch(rt) - { - case MENU_PROCESS_NEEDDATA: - break; - case MENU_PROCESS_ERROR: - std::cout << "MenuOpLineInput::process() => ERROR"; - std::cout << std::endl; - case MENU_PROCESS_DONE: - /* cleanup for next command */ - std::cout << "MenuOpLineInput::process() Clearing Buffer"; - std::cout << std::endl; - mInput.clear(); - - /* go back to parent menu */ - rt = MENU_PROCESS_MENU; - setSelectedMenu(parent()); - break; - } - - return rt; -} - - diff --git a/retroshare-nogui/src/menu/menu.h b/retroshare-nogui/src/menu/menu.h deleted file mode 100644 index c667e64dd..000000000 --- a/retroshare-nogui/src/menu/menu.h +++ /dev/null @@ -1,249 +0,0 @@ -/* - * RetroShare External Interface. - * - * Copyright 2012-2012 by Robert Fernie. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public - * License Version 2.1 as published by the Free Software Foundation. - * - * This library 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 - * Library General Public License for more details. - * - * You should have received a copy of the GNU Library General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 - * USA. - * - * Please report all bugs and problems to "retroshare@lunamutt.com". - * - */ - - - -#ifndef RSNOGUI_MENU_H -#define RSNOGUI_MENU_H - -#include - -#include -#include -#include - -#include "rpcsystem.h" // generic processing command. - -#define MENU_PROCESS_MASK 0x0fff - -#define MENU_PROCESS_NONE 0x0000 -#define MENU_PROCESS_TOP 0x0001 -#define MENU_PROCESS_MENU 0x0002 -#define MENU_PROCESS_DONE 0x0004 -#define MENU_PROCESS_QUIT 0x0008 -#define MENU_PROCESS_SHUTDOWN 0x0010 -#define MENU_PROCESS_HELP 0x0020 -#define MENU_PROCESS_ERROR 0x0040 - -#define MENU_PROCESS_NEEDDATA 0x1000 // Able to be OR'd with ANOTHER CASE. - -#define MENU_KEY_QUIT 'Q' -#define MENU_KEY_HELP 'h' -#define MENU_KEY_TOP 't' -#define MENU_KEY_REPEAT 'r' -#define MENU_KEY_UP 'u' - -#define MENULIST_KEY_LIST 'l' // Don't need this. -#define MENULIST_KEY_NEXT 'n' -#define MENULIST_KEY_PREV 'p' - -#define MENU_OP_ERROR 0 -#define MENU_OP_INSTANT 1 -#define MENU_OP_SUBMENU 2 -#define MENU_OP_NEEDDATA 3 - -#define MENU_ENTRY_NONE 0 -#define MENU_ENTRY_OKAY 1 - -#define MENU_DRAW_FLAGS_STD 0 -#define MENU_DRAW_FLAGS_HTML 1 -#define MENU_DRAW_FLAGS_ECHO 2 -#define MENU_DRAW_FLAGS_NOQUIT 4 - -class Menu; -class Screen; - -class Menu -{ -public: - Menu(std::string shortDesc): mParent(NULL), mShortDesc(shortDesc) { return; } -virtual ~Menu(); - - void setParent(Menu *p) { mParent = p; } - Menu *parent() { return mParent; } - Menu *selectedMenu() { return mSelectedMenu; } - int addMenuItem(char key, Menu *child); - -virtual void reset(); -virtual uint32_t op() { return MENU_OP_SUBMENU; } /* what type is it? returns SUBMENU, INSTANT, NEEDINPUT */ -virtual uint32_t process(char key); - - // THE BIT STILL TO BE DEFINED! - -std::string ShortFnDesc() { return mShortDesc; }// Menu Text (for Help). -virtual uint32_t drawPage(uint32_t drawFlags, std::string &buffer); -virtual uint32_t drawHelpPage(uint32_t drawFlags, std::string &buffer); - -//virtual std::string menuText() = 0; -//virtual std::string menuHelp() = 0; -virtual void setOpMessage(std::string msg) { return; } -virtual void setErrorMessage(std::string msg) { return; } -virtual uint32_t showError() { return 1; } //= 0; -virtual uint32_t showHelp() { return 1; } //= 0; - -protected: -virtual uint32_t std_process(char key); /* for H/T/R/Q */ -virtual uint32_t process_children(char key); /* check for children ops */ - - void setSelectedMenu(Menu *m) { mSelectedMenu = m; } - -private: - Menu *mParent; - Menu *mSelectedMenu; - std::string mShortDesc; - std::map mChildren; -}; - - -/********************************************************** - * Generic MenuList... provides a list of KEYS, which - * can be iterated through. - * - * Maintains: List + Current + Next / Previous. - * Single Child, which is called for all. - */ - -class MenuList: public Menu -{ -public: - MenuList(std::string shortDesc): Menu(shortDesc) { return; } - -virtual void reset(); -virtual uint32_t op(); -virtual uint32_t process(char key); - - // List Info. - uint32_t getListCount(); - int getCurrentIdx(int &idx); - int getCurrentKey(std::string &key); - int getListEntry(int idx, std::string &key); -virtual int getEntryDesc(int idx, std::string &desc); - - // Output. -virtual uint32_t drawPage(uint32_t drawFlags, std::string &buffer); -virtual uint32_t drawHelpPage(uint32_t drawFlags, std::string &buffer); - -protected: - virtual uint32_t list_process(char key); - - int32_t mSelectIdx; /* -1 => none */ - uint32_t mCursor; /* offset for list display */ - std::list mList; - -private: -}; - - - -class MenuOpBasicKey: public Menu -{ -public: - MenuOpBasicKey(std::string shortDesc): Menu(shortDesc) { return; } - virtual uint32_t op(); - -protected: - virtual uint32_t op_basic(std::string key); -}; - - - -class MenuOpTwoKeys: public Menu -{ - -public: - MenuOpTwoKeys(std::string shortDesc): Menu(shortDesc) { return; } - virtual uint32_t op(); - -protected: - virtual uint32_t op_twokeys(std::string parentkey, std::string key); - -}; - -/* Read input, line by line... - */ - -class MenuOpLineInput: public Menu -{ - -public: - MenuOpLineInput(std::string shortDesc): Menu(shortDesc) { return; } - virtual uint32_t op(); - virtual uint32_t process(char key); - -protected: - virtual uint32_t process_lines(std::string input); - - std::string mInput; -}; - - -#if 0 -class MenuInterface: public RsTermServer -{ -public: - - MenuInterface(Menu *b, uint32_t drawFlags) :mCurrentMenu(b), mBase(b), mDrawFlags(drawFlags), mInputRequired(false) { return; } - uint32_t process(char key, uint32_t drawFlags, std::string &buffer); - uint32_t drawHeader(uint32_t drawFlags, std::string &buffer); - - // RsTermServer Interface. - virtual void reset(); - virtual int tick(bool haveInput, char keypress, std::string &output); - - -private: - Menu *mCurrentMenu; - Menu *mBase; - uint32_t mDrawFlags; - bool mInputRequired; -}; - -#endif - - -class MenuInterface: public RpcSystem -{ -public: - - MenuInterface(RpcComms *c, Menu *b, uint32_t drawFlags) - :mComms(c), mCurrentMenu(b), mBase(b), mDrawFlags(drawFlags), mInputRequired(false) { return; } - - uint32_t process(char key, uint32_t drawFlags, std::string &buffer); - uint32_t drawHeader(uint32_t drawFlags, std::string &buffer); - - // RsSystem Interface. - virtual void reset(uint32_t chan_id); - virtual int tick(); - - -private: - RpcComms *mComms; - Menu *mCurrentMenu; - Menu *mBase; - uint32_t mDrawFlags; - bool mInputRequired; - time_t mUpdateTime; -}; - - -#endif diff --git a/retroshare-nogui/src/menu/menus.cc b/retroshare-nogui/src/menu/menus.cc deleted file mode 100644 index 3eeab4bae..000000000 --- a/retroshare-nogui/src/menu/menus.cc +++ /dev/null @@ -1,833 +0,0 @@ -/* - * RetroShare External Interface. - * - * Copyright 2012-2012 by Robert Fernie. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public - * License Version 2.1 as published by the Free Software Foundation. - * - * This library 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 - * Library General Public License for more details. - * - * You should have received a copy of the GNU Library General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 - * USA. - * - * Please report all bugs and problems to "retroshare@lunamutt.com". - * - */ - -#include -#include -#include -#include "util/rsstring.h" -#include "util/rsdir.h" - -#include "menu/menus.h" - -// Can't use: Q, H, T, U (universal) -// or L, N, P (list ops). -// or 0-9,a-f (list selection). - -#define MENU_FRIENDS_KEY_ADD 'a' -#define MENU_FRIENDS_KEY_VIEW 'v' -#define MENU_FRIENDS_KEY_REMOVE 'd' -#define MENU_FRIENDS_KEY_CHAT 'c' - -#define MENU_TRANSFER_KEY_STOP 's' -#define MENU_TRANSFER_KEY_CANCEL 'c' - -#define MENU_SEARCH_KEY_ADD 'a' -#define MENU_SEARCH_KEY_REMOVE 'd' -#define MENU_SEARCH_KEY_VIEW 'v' -#define MENU_SEARCH_KEY_DOWNLOAD 'g' - -#define MENU_FORUMS_KEY_ADD 'a' -#define MENU_FORUMS_KEY_VIEW 'v' -#define MENU_FORUMS_KEY_REMOVE 'd' -#define MENU_FORUMS_KEY_CHAT 'c' - -#define MENU_SHARED_KEY_EXPAND 'e' -#define MENU_SHARED_KEY_UNSHARE 's' -#define MENU_SHARED_KEY_ADD 'a' -#define MENU_SHARED_KEY_PUBLIC 'c' -#define MENU_SHARED_KEY_BROWSABLE 'b' - -#define MENU_TOPLEVEL_KEY_FRIENDS 'f' -#define MENU_TOPLEVEL_KEY_NETWORK 'w' -#define MENU_TOPLEVEL_KEY_TRANSFER 'd' -#define MENU_TOPLEVEL_KEY_SEARCH 's' -#define MENU_TOPLEVEL_KEY_FORUMS 'o' -#define MENU_TOPLEVEL_KEY_SHARED 'k' //If you know of a key which fits better, just change it ;-) -#define MENU_TOPLEVEL_KEY_UPLOADS 'e' - - -Menu *CreateMenuStructure(NotifyTxt *notify) -{ - /* construct Friends Menu */ - MenuList *friends = new MenuListFriends(); - // No Friends Operations Completed Yet! - //friends->addMenuItem(MENU_FRIENDS_KEY_ADD, new MenuOpFriendsAdd()); - //friends->addMenuItem(MENU_FRIENDS_KEY_VIEW, new MenuOpFriendsViewDetail()); - //friends->addMenuItem(MENU_FRIENDS_KEY_REMOVE, new MenuOpFriendsRemove()); - //friends->addMenuItem(MENU_FRIENDS_KEY_CHAT, new MenuOpFriendsChat()); - - MenuList *network = new MenuListNetwork(); - - MenuList *transfers = new MenuListTransfer(); - //transfers->addMenuItem(MENU_TRANSFER_KEY_STOP, new MenuOpTransferStop()); - transfers->addMenuItem(MENU_TRANSFER_KEY_CANCEL, new MenuOpTransferCancel()); - - MenuList *search = new MenuListSearch(notify); - MenuList *searchlist = new MenuListSearchList(notify); - search->addMenuItem(MENU_SEARCH_KEY_ADD, new MenuOpSearchNew(notify)); - //search->addMenuItem(MENU_SEARCH_KEY_REMOVE, new MenuOpSearchDelete()); - search->addMenuItem(MENU_SEARCH_KEY_VIEW, searchlist); - searchlist->addMenuItem(MENU_SEARCH_KEY_DOWNLOAD, new MenuOpSearchListDownload()); - - // Forums - TODO. - //MenuList *forums = new MenuListForums(); - //forums->addMenuItem(MENU_FRIENDS_KEY_ADD, new MenuOpFriendsAdd()); - //forums->addMenuItem(MENU_FRIENDS_KEY_VIEW, new MenuOpFriendsViewDetail()); - //forums->addMenuItem(MENU_FRIENDS_KEY_REMOVE, new MenuOpFriendsRemove()); - //forums->addMenuItem(MENU_FRIENDS_KEY_CHAT, new MenuOpFriendsChat()); - - // Shared folders Menu - MenuList *shared = new MenuListShared(); - shared->addMenuItem(MENU_SHARED_KEY_ADD , new MenuListSharedAddShare()); - shared->addMenuItem(MENU_SHARED_KEY_UNSHARE , new MenuListSharedUnshare()); - shared->addMenuItem(MENU_SHARED_KEY_PUBLIC , new MenuListSharedTogglePublic()); - shared->addMenuItem(MENU_SHARED_KEY_BROWSABLE , new MenuListSharedToggleBrowsable()); - - /* Top Level Menu */ - Menu *tlm = new Menu("Top Level Menu"); - - tlm->addMenuItem(MENU_TOPLEVEL_KEY_FRIENDS, friends); - tlm->addMenuItem(MENU_TOPLEVEL_KEY_NETWORK, network); - tlm->addMenuItem(MENU_TOPLEVEL_KEY_TRANSFER, transfers); - tlm->addMenuItem(MENU_TOPLEVEL_KEY_SEARCH, search); - //tlm->addMenuItem(MENU_TOPLEVEL_KEY_FORUMS, forums); - tlm->addMenuItem(MENU_TOPLEVEL_KEY_SHARED, shared); - - return tlm; -} - - -/************ - * Friends Menu - */ - - -uint32_t MenuListFriends::op() -{ - MenuList::op(); - - rsPeers->getGPGAcceptedList(mList); - //rsPeers->getGPGValidList(mList); - - return MENU_OP_SUBMENU; -} - -int MenuListFriends::getEntryDesc(int idx, std::string &desc) -{ - std::string gpgId; - - if (!getListEntry(idx, gpgId)) - { - /* error */ - return 0; - } - - RsPeerDetails details; - if (rsPeers->getPeerDetails(gpgId, details)) - { - if (details.accept_connection) - { - desc = "Friend: "; - } - else - { - desc = "Neighbour: "; - } - - desc += "<" + gpgId + "> "; - desc += details.name; - } - return 1; -} - - -uint32_t MenuListNetwork::op() -{ - MenuList::op(); - - rsPeers->getGPGValidList(mList); - //rsPeers->getGPGAcceptedList(mList); - - return MENU_OP_SUBMENU; -} - - -uint32_t MenuOpFriendsAdd::op_basic(std::string key) -{ - - - return MENU_OP_INSTANT; -} - -uint32_t MenuOpFriendsViewDetail::op_basic(std::string key) -{ - - - return MENU_OP_INSTANT; -} - - -uint32_t MenuOpFriendsRemove::op_basic(std::string key) -{ - - - return MENU_OP_INSTANT; -} - - -uint32_t MenuOpFriendsChat::op_basic(std::string key) -{ - - - return MENU_OP_INSTANT; -} - - -/************ - * Transfer Menu - */ - - -uint32_t MenuListTransfer::op() -{ - MenuList::op(); - - /* load friend list*/ - rsFiles->FileDownloads(mList); - - return MENU_OP_SUBMENU; -} - -int MenuListTransfer::getEntryDesc(int idx, std::string &desc) -{ - std::string hash; - if (!getListEntry(idx, hash)) - { - std::cout << "MenuListTransfer::getEntryDesc() No ListEntry"; - std::cout << std::endl; - return 0; - } - - FileInfo info; - if (!rsFiles->FileDetails(hash, RS_FILE_HINTS_DOWNLOAD, info)) - { - std::cout << "MenuListTransfer::getEntryDesc() No FileDetails"; - std::cout << std::endl; - return 0; - } - - float frac = 100.0 * (float) info.transfered / info.size; - - if (frac != 1.0) - { - if (info.tfRate > 0) - { - rs_sprintf(desc, "<%s> Downloading %3.2f%% from %d Peers @%3.1fKB/s. Name: %s", - info.hash.c_str(), frac, info.peers.size(), info.tfRate, info.fname.c_str()); - } - else - { - rs_sprintf(desc, "<%s> Stalled %3.2f%% Name: %s", - info.hash.c_str(), frac, info.fname.c_str()); - } - } - else - { - rs_sprintf(desc, "<%s> Done! Name: %s", info.hash.c_str(), info.fname.c_str()); - } - return MENU_OP_INSTANT; -} - -uint32_t MenuOpTransferStop::op_basic(std::string key) -{ - rsFiles->FileCancel(key); - parent()->setOpMessage("Stopped Transfer"); - return MENU_OP_INSTANT; -} - -uint32_t MenuOpTransferCancel::op_basic(std::string key) -{ - rsFiles->FileCancel(key); - parent()->setOpMessage("Stopped Transfer"); - return MENU_OP_INSTANT; -} - - -/************ - * Search Menu - */ - - - -uint32_t MenuListSearch::op() -{ - mSelectIdx = -1; - mCursor = 0; - - /* Don't reset List -> done dynamically */ - - return MENU_OP_SUBMENU; -} - -int MenuListSearch::getEntryDesc(int idx, std::string &desc) -{ - std::string strSearchId; - - if (!getListEntry(idx, strSearchId)) - { - /* error */ - return 0; - } - - std::map::iterator it; - std::map::iterator sit; - it = mSearchTerms.find(strSearchId); - sit = mSearchIds.find(strSearchId); - if ((it == mSearchTerms.end()) || (sit == mSearchIds.end())) - { - /* error */ - return 0; - } - - rs_sprintf(desc, "Search(\"%s\") Found %d matches so far", - it->second.c_str(), mNotify->getSearchResultCount(sit->second)); - return 1; -} - - -int MenuListSearch::getCurrentSearchId(uint32_t &id) -{ - std::string strSearchId; - - if (!getListEntry(mSelectIdx, strSearchId)) - { - /* error */ - return 0; - } - - std::map::iterator sit; - sit = mSearchIds.find(strSearchId); - if (sit == mSearchIds.end()) - { - /* error */ - return 0; - } - - id = sit->second; - return 1; -} - -int MenuListSearch::storeSearch(uint32_t searchId, std::string match_string) -{ - std::cout << "MenuListSearch::storeSearch(" << searchId << " => "; - std::cout << match_string; - std::cout << std::endl; - - std::string strSearchId; - rs_sprintf(strSearchId, "%lu", searchId); - mList.push_back(strSearchId); - - mSearchTerms[strSearchId] = match_string; - mSearchIds[strSearchId] = searchId; - - return 1; -} - -int MenuListSearch::removeSearch(std::string strSearchId) -{ - std::cout << "MenuListSearch::removeSearch(" << strSearchId << ")"; - std::cout << std::endl; - - std::map::iterator it; - it = mSearchIds.find(strSearchId); - if (it != mSearchIds.end()) - { - - /* cancel search */ - // CAN'T DO!!! - - /* clear results from Notify Collector */ - mNotify->clearSearchId(it->second); - - /* cleanup local maps */ - mSearchIds.erase(it); - - /* cleanup terms maps (TODO) */ - } - - return 1; -} - -uint32_t MenuOpSearchNew::drawPage(uint32_t drawFlags, std::string &buffer) -{ - buffer += "Enter New Search Term > "; - return 1; -} - - - -uint32_t MenuOpSearchNew::process_lines(std::string input) -{ - /* launch search */ - if (input.size() < 4) - { - std::cout << "MenuOpSearchNew::process_lines() ERROR Input too small"; - std::cout << std::endl; - return MENU_PROCESS_ERROR; - } - - std::string search = input.substr(0, input.size() - 1); // remove \n. - uint32_t searchId = (uint32_t) rsTurtle->turtleSearch(search); - mNotify->collectSearchResults(searchId); - - /* store request in parent */ - MenuListSearch *ms = dynamic_cast(parent()); - if (ms) - { - ms->storeSearch(searchId, search); - } - - return MENU_PROCESS_DONE; -} - -uint32_t MenuOpSearchDelete::op_basic(std::string key) -{ - - return MENU_OP_INSTANT; -} - - -uint32_t MenuListSearchList::op() -{ - MenuList::op(); - return refresh(); -} - -uint32_t MenuListSearchList::refresh() -{ - Menu* p = parent(); - MenuListSearch *mls = dynamic_cast(p); - if (!mls) - { - std::cout << "MenuListSearchList::refresh() mls not there"; - std::cout << std::endl; - return MENU_OP_ERROR; - } - - /* load friend list*/ - mList.clear(); - - uint32_t searchId; - if (!mls->getCurrentSearchId(searchId)) - { - std::cout << "MenuListSearchList::refresh() currentIdx invalid"; - std::cout << std::endl; - return MENU_OP_ERROR; - } - - std::cout << "MenuListSearchList::refresh() searchId: " << searchId; - std::cout << std::endl; - - std::list::iterator it; - mNotify->getSearchResults(searchId, mSearchResults); - - /* convert into useful list */ - for(it = mSearchResults.begin(); it != mSearchResults.end(); it++) - { - mList.push_back(it->hash); - } - - mSelectIdx = -1; - mCursor = 0; - return MENU_OP_SUBMENU; -} - -int MenuListSearchList::getEntryDesc(int idx, std::string &desc) -{ - std::list::iterator it; - int i = 0; - for (it = mSearchResults.begin(); - (i < idx) && (it != mSearchResults.end()); it++, i++) ; - - if (it != mSearchResults.end()) - { - rs_sprintf(desc, "<%s> Size: %llu Name:%s", - it->hash.c_str(), it->size, it->name.c_str()); - return MENU_ENTRY_OKAY; - } - return MENU_ENTRY_NONE; -} - - -int MenuListSearchList::downloadSelected() -{ - if (mSelectIdx < 0) - { - std::cout << "MenuListSearchList::downloadSelected() Invalid Selection"; - std::cout << std::endl; - return MENU_ENTRY_NONE; - } - - std::list::iterator it; - int i = 0; - for (it = mSearchResults.begin(); - (i < mSelectIdx) && (it != mSearchResults.end()); it++, i++) ; - - if (it != mSearchResults.end()) - { - std::list srcIds; - if (rsFiles -> FileRequest(it->name, it->hash, it->size, - "", RS_FILE_REQ_ANONYMOUS_ROUTING, srcIds)) - { - std::cout << "MenuListSearchList::downloadSelected() Download Started"; - std::cout << std::endl; - } - else - { - std::cout << "MenuListSearchList::downloadSelected() Error Starting Download"; - std::cout << std::endl; - } - return MENU_ENTRY_OKAY; - } - return MENU_ENTRY_NONE; -} - - - -uint32_t MenuOpSearchListDownload::op_basic(std::string key) -{ - Menu* p = parent(); - MenuListSearchList *mlsl = dynamic_cast(p); - if (!mlsl) - { - std::cout << "MenuOpSearchListDownload::op_basic() ERROR"; - std::cout << std::endl; - return MENU_OP_ERROR; - } - - mlsl->downloadSelected(); - - return MENU_OP_INSTANT; -} - -/************ - * Forums Menu - */ - - - -uint32_t MenuListForums::op() -{ - /* load friend list*/ - mList.clear(); - rsPeers->getGPGAcceptedList(mList); - mSelectIdx = 0; - - return MENU_OP_SUBMENU; -} - - -int MenuListForums::getEntryDesc(int idx, std::string &desc) -{ - - - return MENU_OP_INSTANT; -} - -uint32_t MenuOpForumDetails::op_basic(std::string key) -{ - - - return MENU_OP_INSTANT; -} - - -uint32_t MenuOpForumSubscribe::op_basic(std::string key) -{ - - - return MENU_OP_INSTANT; -} - - -uint32_t MenuOpForumUnsubscribe::op_basic(std::string key) -{ - - - return MENU_OP_INSTANT; -} - - -uint32_t MenuOpForumCreate::op_basic(std::string key) -{ - - - return MENU_OP_INSTANT; -} - - -uint32_t MenuListForumMsgs::op() -{ - /* load friend list*/ - mList.clear(); - rsPeers->getGPGAcceptedList(mList); - mSelectIdx = 0; - - return MENU_OP_SUBMENU; -} - -int MenuListForumMsgs::getEntryDesc(int idx, std::string &desc) -{ - - - return MENU_OP_INSTANT; -} - -uint32_t MenuOpForumMsgView::op_twokeys(std::string parentkey, std::string key) -{ - - - return MENU_OP_INSTANT; -} - -uint32_t MenuOpForumMsgReply::op_twokeys(std::string parentkey, std::string key) -{ - - - return MENU_OP_INSTANT; -} - - -uint32_t MenuOpForumMsgWrite::op_twokeys(std::string parentkey, std::string key) -{ - - - return MENU_OP_INSTANT; -} - -/************ - * Shared folders Menu - */ - - -uint32_t MenuListShared::op() -{ - MenuList::op(); - - mList.clear(); - std::list dirs; - rsFiles->getSharedDirectories(dirs); - std::list::iterator it; - for(it = dirs.begin(); it != dirs.end(); it++) - { - mList.push_back ((*it).virtualname) ; - } - - return MENU_OP_SUBMENU; -} - -int MenuListShared::getEntryDesc(int idx, std::string &desc) -{ - std::list dirs; - rsFiles->getSharedDirectories(dirs); - std::list::iterator it; - std::string shareflag; - int i=0; - for (it = dirs.begin(); (i < idx) && (it != dirs.end()); it++, i++); - if (it != dirs.end()) - { - bool networkwide = (it->shareflags & DIR_FLAGS_ANONYMOUS_DOWNLOAD); - bool browsable = (it->shareflags & DIR_FLAGS_BROWSABLE_OTHERS); - if (networkwide && browsable) - { - shareflag = "networkwide - browsable"; - } - else if (browsable) - { - shareflag = "private - browsable"; - } - else if (networkwide) - { - shareflag = "networkwide - anonymous"; - } - else - { - shareflag = "not shared"; - } - - rs_sprintf(desc, "Path: %s Share Type:%s", it->filename.c_str(), shareflag.c_str()); - return MENU_ENTRY_OKAY; - } - return MENU_ENTRY_NONE; -} - -int MenuListShared::unshareSelected() -{ - if (mSelectIdx < 0) - { - std::cout << "MenuListSearchList::unshareSelected() Invalid Selection"; - std::cout << std::endl; - return MENU_ENTRY_NONE; - } - std::list dirs; - rsFiles->getSharedDirectories(dirs); - std::list::iterator it; - int i=0; - for (it = dirs.begin(); (i < mSelectIdx) && (it != dirs.end()); it++, i++); - if (it != dirs.end()) - { - rsFiles->removeSharedDirectory(it->filename); - return MENU_ENTRY_OKAY; - } - return MENU_ENTRY_NONE; -} - -int MenuListShared::toggleFlagSelected(FileStorageFlags shareflags) -{ - if (mSelectIdx < 0) - { - std::cout << "MenuListSearchList::unshareSelected() Invalid Selection"; - std::cout << std::endl; - return MENU_ENTRY_NONE; - } - std::list dirs; - rsFiles->getSharedDirectories(dirs); - std::list::iterator it; - int i=0; - for (it = dirs.begin(); (i < mSelectIdx) && (it != dirs.end()); it++, i++); - if (it != dirs.end()) - { - if(FileStorageFlags(it->shareflags & shareflags) == shareflags) - { - it->shareflags = FileStorageFlags(it->shareflags & ~shareflags); //disable shareflags - rsFiles->updateShareFlags(*it); - } - else - { - it->shareflags = FileStorageFlags(it->shareflags | shareflags); //anable shareflags - rsFiles->updateShareFlags(*it); - } - return MENU_ENTRY_OKAY; - } - return MENU_ENTRY_NONE; -} - -uint32_t MenuListSharedUnshare::op_basic(std::string key) -{ - Menu* p = parent(); - MenuListShared *mls = dynamic_cast(p); - if (!mls) - { - std::cout << "MenuListShared::op_basic() ERROR"; - std::cout << std::endl; - return MENU_OP_ERROR; - } - - mls->unshareSelected(); - - return MENU_OP_INSTANT; -} - -uint32_t MenuListSharedTogglePublic::op_basic(std::string key) -{ - Menu* p = parent(); - MenuListShared *mls = dynamic_cast(p); - if (!mls) - { - std::cout << "MenuListShared::op_basic() ERROR"; - std::cout << std::endl; - return MENU_OP_ERROR; - } - - mls->toggleFlagSelected(DIR_FLAGS_ANONYMOUS_DOWNLOAD); - - return MENU_OP_INSTANT; -} - -uint32_t MenuListSharedToggleBrowsable::op_basic(std::string key) -{ - Menu* p = parent(); - MenuListShared *mls = dynamic_cast(p); - if (!mls) - { - std::cout << "MenuListShared::op_basic() ERROR"; - std::cout << std::endl; - return MENU_OP_ERROR; - } - - mls->toggleFlagSelected(DIR_FLAGS_BROWSABLE_OTHERS); - - return MENU_OP_INSTANT; -} - -uint32_t MenuListSharedAddShare::drawPage(uint32_t drawFlags, std::string &buffer) -{ - buffer += "Enter New path 'path' 'virtualfolder' > "; - return 1; -} - - - -uint32_t MenuListSharedAddShare::process_lines(std::string input) -{ - /* launch search */ - if (input.size() < 4) - { - std::cout << "MenuOpSearchNew::process_lines() ERROR Input too small"; - std::cout << std::endl; - return MENU_PROCESS_ERROR; - } - - std::string dir = input.substr(0, input.size() - 1); // remove \n. - - // check that the directory exists! - if (!RsDirUtil::checkDirectory(dir)) - { - std::cout << "MenuOpSearchNew::process_lines() ERROR Directory doesn't exist"; - std::cout << std::endl; - return MENU_PROCESS_ERROR; - } - - // extract top level as the virtual name. - std::string topdir = RsDirUtil::getTopDir(input); - if (topdir.size() < 1) - { - std::cout << "MenuOpSearchNew::process_lines() ERROR TopDir is invalid"; - std::cout << std::endl; - return MENU_PROCESS_ERROR; - } - - SharedDirInfo shareddir; - shareddir.filename = dir; - shareddir.virtualname = topdir; - shareddir.shareflags = FileStorageFlags(0x0); - - if (!rsFiles->addSharedDirectory(shareddir)) - { - std::cout << "MenuOpSearchNew::process_lines() ERROR Adding SharedDir"; - std::cout << std::endl; - return MENU_PROCESS_ERROR; - } - - return MENU_PROCESS_DONE; -} diff --git a/retroshare-nogui/src/menu/menus.h b/retroshare-nogui/src/menu/menus.h deleted file mode 100644 index d4c2486c1..000000000 --- a/retroshare-nogui/src/menu/menus.h +++ /dev/null @@ -1,346 +0,0 @@ -/* - * RetroShare External Interface. - * - * Copyright 2012-2012 by Robert Fernie. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public - * License Version 2.1 as published by the Free Software Foundation. - * - * This library 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 - * Library General Public License for more details. - * - * You should have received a copy of the GNU Library General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 - * USA. - * - * Please report all bugs and problems to "retroshare@lunamutt.com". - * - */ - -#include "menu/menu.h" -#include -#include "notifytxt.h" /* needed to access search results */ -#include - -Menu *CreateMenuStructure(NotifyTxt *notify); - -/************ - * Friends Menu - */ - -class MenuListFriends: public MenuList -{ - -public: - MenuListFriends() :MenuList("Friends") { return; } - - virtual uint32_t op(); - int getEntryDesc(int idx, std::string &desc); - -protected: - MenuListFriends(std::string name) :MenuList(name) { return; } // For Network. -}; - - -class MenuListNetwork: public MenuListFriends -{ - -public: - MenuListNetwork() :MenuListFriends("Network") { return; } - - virtual uint32_t op(); -}; - - -class MenuOpFriendsAdd: public MenuOpBasicKey -{ - public: - - MenuOpFriendsAdd() :MenuOpBasicKey("Add") { return; } - virtual uint32_t op_basic(std::string hash); -}; - - -class MenuOpFriendsViewDetail: public MenuOpBasicKey -{ - public: - - MenuOpFriendsViewDetail() :MenuOpBasicKey("View") { return; } - virtual uint32_t op_basic(std::string hash); -}; - - -class MenuOpFriendsRemove: public MenuOpBasicKey -{ - public: - - MenuOpFriendsRemove() :MenuOpBasicKey("Remove") { return; } - virtual uint32_t op_basic(std::string hash); -}; - - -class MenuOpFriendsChat: public MenuOpBasicKey -{ - public: - - MenuOpFriendsChat() :MenuOpBasicKey("Chat") { return; } - virtual uint32_t op_basic(std::string hash); -}; - - - -/************ - * Transfer Menu - */ - - -class MenuListTransfer: public MenuList -{ - public: - - MenuListTransfer() :MenuList("Downloads") { return; } - virtual uint32_t op(); - int getEntryDesc(int idx, std::string &desc); -}; - - -class MenuOpTransferStop: public MenuOpBasicKey -{ - public: - - MenuOpTransferStop() :MenuOpBasicKey("Stop") { return; } - virtual uint32_t op_basic(std::string hash); -}; - - - -class MenuOpTransferCancel: public MenuOpBasicKey -{ - public: - - MenuOpTransferCancel() :MenuOpBasicKey("Cancel") { return; } - virtual uint32_t op_basic(std::string hash); -}; - - - -/************ - * Search Menu - */ - - -class MenuListSearch: public MenuList -{ - public: - - MenuListSearch(NotifyTxt *notify) - :MenuList("Search"), mNotify(notify) { return; } - - virtual uint32_t op(); - int getEntryDesc(int idx, std::string &desc); - - /* specific Search Functions */ - int getCurrentSearchId(uint32_t &id); - int storeSearch(uint32_t searchId, std::string match_string); - int removeSearch(std::string strSearchId); - -private: - std::map mSearchIds; - std::map mSearchTerms; - NotifyTxt *mNotify; -}; - - -class MenuOpSearchNew: public MenuOpLineInput -{ - public: - - MenuOpSearchNew(NotifyTxt *notify) - :MenuOpLineInput("New"), mNotify(notify) { return; } - virtual uint32_t process_lines(std::string input); - virtual uint32_t drawPage(uint32_t drawFlags, std::string &buffer); - -private: - NotifyTxt *mNotify; -}; - - -class MenuOpSearchDelete: public MenuOpBasicKey -{ - public: - - MenuOpSearchDelete() :MenuOpBasicKey("Delete") { return; } - virtual uint32_t op_basic(std::string hash); -}; - - -class MenuListSearchList: public MenuList -{ - public: - - MenuListSearchList(NotifyTxt *notify) - :MenuList("Results"), mNotify(notify) { return; } - virtual uint32_t op(); - uint32_t refresh(); - int getEntryDesc(int idx, std::string &desc); - int downloadSelected(); - - private: - NotifyTxt *mNotify; - std::list mSearchResults; // local cache for consistency. -}; - - -class MenuOpSearchListDownload: public MenuOpBasicKey -{ - public: - - MenuOpSearchListDownload() :MenuOpBasicKey("Download") { return; } - virtual uint32_t op_basic(std::string hash); -}; - - - -/************ - * Forums Menu - */ - - - -class MenuListForums: public MenuList -{ - public: - - MenuListForums() :MenuList("Forums SubMenu") { return; } - virtual uint32_t op(); - int getEntryDesc(int idx, std::string &desc); -}; - - -class MenuOpForumDetails: public MenuOpBasicKey -{ - public: - - MenuOpForumDetails() :MenuOpBasicKey("Show Forum Details") { return; } - virtual uint32_t op_basic(std::string hash); -}; - - -class MenuOpForumSubscribe: public MenuOpBasicKey -{ - public: - - MenuOpForumSubscribe() :MenuOpBasicKey("Subscribe To Forum") { return; } - virtual uint32_t op_basic(std::string hash); -}; - - -class MenuOpForumUnsubscribe: public MenuOpBasicKey -{ - public: - - MenuOpForumUnsubscribe() :MenuOpBasicKey("Unsubscribe To Forum") { return; } - virtual uint32_t op_basic(std::string hash); -}; - - -class MenuOpForumCreate: public MenuOpBasicKey -{ - public: - - MenuOpForumCreate() :MenuOpBasicKey("Create Forum") { return; } - virtual uint32_t op_basic(std::string hash); -}; - - - -class MenuListForumMsgs: public MenuList -{ - public: - - MenuListForumMsgs() :MenuList("List Forum Msgs") { return; } - virtual uint32_t op(); - int getEntryDesc(int idx, std::string &desc); -}; - -class MenuOpForumMsgView: public MenuOpTwoKeys -{ - public: - - MenuOpForumMsgView() :MenuOpTwoKeys("View Message") { return; } - virtual uint32_t op_twokeys(std::string parentkey, std::string key); -}; - - -class MenuOpForumMsgReply: public MenuOpTwoKeys -{ - public: - - MenuOpForumMsgReply() :MenuOpTwoKeys("Reply to Message") { return; } - virtual uint32_t op_twokeys(std::string parentkey, std::string key); -}; - - -class MenuOpForumMsgWrite: public MenuOpTwoKeys -{ - public: - - MenuOpForumMsgWrite() :MenuOpTwoKeys("Write Message") { return; } - virtual uint32_t op_twokeys(std::string parentkey, std::string key); -}; - -/************ - * Shared folders Menu - */ - - -class MenuListShared: public MenuList -{ - public: - - MenuListShared() :MenuList("My Shared Directories") { return; } - virtual uint32_t op(); - int getEntryDesc(int idx, std::string &desc); - int unshareSelected(); - int toggleFlagSelected(FileStorageFlags shareflags); -}; - - - -class MenuListSharedUnshare: public MenuOpBasicKey -{ - public: - - MenuListSharedUnshare() :MenuOpBasicKey("Stop Sharing Selected") { return; } - virtual uint32_t op_basic(std::string key); -}; - -class MenuListSharedTogglePublic: public MenuOpBasicKey -{ - public: - - MenuListSharedTogglePublic() :MenuOpBasicKey("Enable/Disable Networkwide Sharing") { return; } - virtual uint32_t op_basic(std::string key); -}; - -class MenuListSharedToggleBrowsable: public MenuOpBasicKey -{ - public: - - MenuListSharedToggleBrowsable() :MenuOpBasicKey("Enable/Disable Browsing Of Selected") { return; } - virtual uint32_t op_basic(std::string key); -}; - -class MenuListSharedAddShare: public MenuOpLineInput -{ - public: - - MenuListSharedAddShare() :MenuOpLineInput("Add new Share") { return; } - virtual uint32_t process_lines(std::string input); - virtual uint32_t drawPage(uint32_t drawFlags, std::string &buffer); -}; - diff --git a/retroshare-nogui/src/menu/menutest.h b/retroshare-nogui/src/menu/menutest.h deleted file mode 100644 index 94c58d4ee..000000000 --- a/retroshare-nogui/src/menu/menutest.h +++ /dev/null @@ -1,94 +0,0 @@ - -#include -#include "menu/menu.h" - -class MenuTest -{ -public: - MenuTest(MenuInterface *i, std::istream &in, std::ostream &out) - :mMenus(i), mIn(in), mOut(out) - { - return; - } - -int tick() - { - int c = mIn.get(); - uint8_t key = (uint8_t) c; - uint32_t drawFlags = 0; - std::string buffer; - mMenus->process(key, drawFlags, buffer); - - return 1; - } - -private: - - - MenuInterface *mMenus; - std::istream &mIn; - std::ostream &mOut; -}; - -#include -#include - -#include "rstermserver.h" - -class RsConsole -{ - public: - - RsConsole(RsTermServer *s, int infd, int outfd) - :mServer(s), mIn(infd), mOut(outfd) - { - const int fcflags = fcntl(mIn,F_GETFL); - if (fcflags < 0) - { - std::cerr << "RsConsole() ERROR getting fcntl FLAGS"; - std::cerr << std::endl; - exit(1); - } - if (fcntl(mIn,F_SETFL,fcflags | O_NONBLOCK) <0) - { - std::cerr << "RsConsole() ERROR setting fcntl FLAGS"; - std::cerr << std::endl; - exit(1); - } - } - - int tick() - { - char buf; - std::string output; - int size = read(mIn, &buf, 1); - - bool haveInput = (size > 0); - - int rt = mServer->tick(haveInput, buf, output); - - if (output.size() > 0) - { - write(mOut, output.c_str(), output.size()); - } - - if (rt < 0) - { - std::cerr << "Exit Request"; - exit(1); - } - - if (!haveInput) - { - return 0; - } - - return 1; - } - -private: - - RsTermServer *mServer; - int mIn, mOut; -}; - diff --git a/retroshare-nogui/src/menu/stdiocomms.cc b/retroshare-nogui/src/menu/stdiocomms.cc deleted file mode 100644 index 132b8e89d..000000000 --- a/retroshare-nogui/src/menu/stdiocomms.cc +++ /dev/null @@ -1,183 +0,0 @@ -/* - * RetroShare External Interface. - * - * Copyright 2012-2012 by Robert Fernie. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public - * License Version 2.1 as published by the Free Software Foundation. - * - * This library 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 - * Library General Public License for more details. - * - * You should have received a copy of the GNU Library General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 - * USA. - * - * Please report all bugs and problems to "retroshare@lunamutt.com". - * - */ - -#include "menu/stdiocomms.h" - -#include -#include -#include -#include -#include - - -StdioComms::StdioComms(int infd, int outfd) - :mIn(infd), mOut(outfd) -{ -// fcntl not available on Windows, search alternative when needed -#ifndef WINDOWS_SYS -#if 1 -// THIS Code is strange... -// It seems to mess up stderr. -// But if you redirect it -> is comes out fine. Very Weird. -// HELP!!! - - std::cerr << "StdioComms() STDERR msg 0"; - std::cerr << std::endl; - const int fcflags = fcntl(mIn,F_GETFL); - if (fcflags < 0) - { - std::cerr << "StdioComms() ERROR getting fcntl FLAGS"; - std::cerr << std::endl; - exit(1); - } - if (fcntl(mIn,F_SETFL,fcflags | O_NONBLOCK) <0) - { - std::cerr << "StdioComms() ERROR setting fcntl FLAGS"; - std::cerr << std::endl; - exit(1); - } - std::cerr << "StdioComms() STDERR msg 1"; - std::cerr << std::endl; -#endif -#endif // WINDOWS_SYS -} - - -int StdioComms::isOkay() -{ - return 1; -} - - -int StdioComms::active_channels(std::list &chan_ids) -{ - if (isOkay()) - { - chan_ids.push_back(1); // only one possible here (stdin/stdout) - } - return 1; -} - -int StdioComms::error(uint32_t chan_id, std::string msg) -{ - std::cerr << "StdioComms::error(" << msg << ")"; - std::cerr << std::endl; - return 1; -} - - - -int StdioComms::recv_ready(uint32_t chan_id) -{ - /* should be proper poll / select! - but we don't use this at the moment */ - return 1; -} - - -int StdioComms::recv(uint32_t chan_id, uint8_t *buffer, int bytes) -{ - int size = read(mIn, buffer, bytes); - std::cerr << "StdioComms::recv() returned: " << size; - std::cerr << std::endl; - - if (size == -1) - { - std::cerr << "StdioComms::recv() ERROR: " << errno; - std::cerr << std::endl; - if (errno == EAGAIN) - { - return 0; // OKAY; - } - } - - return size; -} - - -int StdioComms::recv(uint32_t chan_id, std::string &buffer, int bytes) -{ - uint8_t tmpbuffer[bytes]; - int size = read(mIn, tmpbuffer, bytes); - for(int i = 0; i < size; i++) - { - buffer += tmpbuffer[i]; - } - return size; -} - - // these make it easier... -int StdioComms::recv_blocking(uint32_t chan_id, uint8_t *buffer, int bytes) -{ - int totalread = 0; - while(totalread < bytes) - { - int size = read(mIn, &(buffer[totalread]), bytes - totalread); - if (size < 0) - { - if (totalread) - break; // partial read. - else - return size; // error. - } - totalread += size; - usleep(1000); // minisleep - so we don't 100% CPU. - std::cerr << "StdioComms::recv_blocking() read so far: " << size; - std::cerr << " / " << totalread; - std::cerr << std::endl; - } - return totalread; -} - - -int StdioComms::recv_blocking(uint32_t chan_id, std::string &buffer, int bytes) -{ - uint8_t tmpbuffer[bytes]; - int size = recv_blocking(chan_id, tmpbuffer, bytes); - - if (size < 0) - return size; // error. - - for(int i = 0; i < size; i++) - buffer += tmpbuffer[i]; - - return size; -} - - -int StdioComms::send(uint32_t chan_id, uint8_t *buffer, int bytes) -{ - write(mOut, buffer, bytes); - return bytes; -} - - -int StdioComms::send(uint32_t chan_id, const std::string &output) -{ - if (output.size() > 0) - { - write(mOut, output.c_str(), output.size()); - } - return output.size(); -} - - diff --git a/retroshare-nogui/src/menu/stdiocomms.h b/retroshare-nogui/src/menu/stdiocomms.h deleted file mode 100644 index bc559af4c..000000000 --- a/retroshare-nogui/src/menu/stdiocomms.h +++ /dev/null @@ -1,59 +0,0 @@ -/* - * RetroShare External Interface. - * - * Copyright 2012-2012 by Robert Fernie. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public - * License Version 2.1 as published by the Free Software Foundation. - * - * This library 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 - * Library General Public License for more details. - * - * You should have received a copy of the GNU Library General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 - * USA. - * - * Please report all bugs and problems to "retroshare@lunamutt.com". - * - */ - - - -#ifndef RS_STDIO_COMMS_H -#define RS_STDIO_COMMS_H - -#include "rpcsystem.h" - - - -class StdioComms: public RpcComms -{ -public: - StdioComms(int infd, int outfd); - - virtual int isOkay(); - virtual int error(uint32_t chan_id, std::string msg); - - virtual int active_channels(std::list &chan_ids); - - virtual int recv_ready(uint32_t chan_id); - virtual int recv(uint32_t chan_id, uint8_t *buffer, int bytes); - virtual int recv(uint32_t chan_id, std::string &buffer, int bytes); - - // these make it easier... - virtual int recv_blocking(uint32_t chan_id, uint8_t *buffer, int bytes); - virtual int recv_blocking(uint32_t chan_id, std::string &buffer, int bytes); - - virtual int send(uint32_t chan_id, uint8_t *buffer, int bytes); - virtual int send(uint32_t chan_id, const std::string &buffer); - -private: - int mIn, mOut; -}; - -#endif - diff --git a/retroshare-nogui/src/retroshare-nogui.pro b/retroshare-nogui/src/retroshare-nogui.pro index c66ae37cd..358cb65f4 100644 --- a/retroshare-nogui/src/retroshare-nogui.pro +++ b/retroshare-nogui/src/retroshare-nogui.pro @@ -4,7 +4,6 @@ TEMPLATE = app TARGET = RetroShare06-nogui CONFIG += bitdht #CONFIG += introserver -#CONFIG += sshserver CONFIG -= qt xml gui CONFIG += link_prl @@ -84,8 +83,6 @@ win32 { LIBS += -luuid -lole32 -liphlpapi -lcrypt32 LIBS += -lole32 -lwinmm - PROTOCPATH=$$BIN_DIR - RC_FILE = resources/retroshare_win.rc DEFINES *= WINDOWS_SYS _USE_32BIT_TIME_T @@ -97,11 +94,11 @@ win32 { ##################################### MacOS ###################################### macx { - # ENABLE THIS OPTION FOR Univeral Binary BUILD. - # CONFIG += ppc x86 + # ENABLE THIS OPTION FOR Univeral Binary BUILD. + # CONFIG += ppc x86 LIBS += -Wl,-search_paths_first - LIBS += -lssl -lcrypto -lz + LIBS += -lssl -lcrypto -lz for(lib, LIB_DIR):exists($$lib/libminiupnpc.a){ LIBS += $$lib/libminiupnpc.a} LIBS += -framework CoreFoundation LIBS += -framework Security @@ -111,13 +108,7 @@ macx { DEPENDPATH += . $$INC_DIR INCLUDEPATH += . $$INC_DIR - sshserver { - LIBS += -L../../../lib - #LIBS += -L../../../lib/libssh-0.6.0 - } - - QMAKE_CXXFLAGS *= -Dfseeko64=fseeko -Dftello64=ftello -Dstat64=stat -Dstatvfs64=statvfs -Dfopen64=fopen - + QMAKE_CXXFLAGS *= -Dfseeko64=fseeko -Dftello64=ftello -Dstat64=stat -Dstatvfs64=statvfs -Dfopen64=fopen } ##################################### FreeBSD ###################################### @@ -193,173 +184,3 @@ libresapihttpserver { SOURCES += \ TerminalApiClient.cpp } - -sshserver { - - # This Requires libssh-0.5.* to compile. - # Please use this path below. - # (You can modify it locally if required - but dont commit it!) - - #LIBSSH_DIR = $PWD/../../../lib/libssh-0.5.2 - LIBSSH_DIR = $PWD/../../../libssh-0.6.0rc1 - - # - # Use the following commend to generate a Server RSA Key. - # Key should be in current directory - when run/ - # ssh-keygen -t rsa -f rs_ssh_host_rsa_key - # - # You can connect from a standard ssh, eg: ssh -p 7022 127.0.0.1 - # - # The Menu system is available from the command-line (-T) and SSH (-S) - # if it get covered by debug gunk, just press to refresh. - # - # ./retroshare-nogui -h provides some more instructions. - # - - win32 { - DEFINES *= LIBSSH_STATIC - } - - DEPENDPATH += $$LIBSSH_DIR/include/ - INCLUDEPATH += $$LIBSSH_DIR/include/ - - win32 { - LIBS += -lssh - LIBS += -lssh_threads - } else { - SSH_OK = $$system(pkg-config --atleast-version 0.5.4 libssh && echo yes) - isEmpty(SSH_OK) { - exists($$LIBSSH_DIR/build/src/libssh.a):exists($$LIBSSH_DIR/build/src/threads/libssh_threads.a) { - LIBS += $$LIBSSH_DIR/build/src/libssh.a - LIBS += $$LIBSSH_DIR/build/src/threads/libssh_threads.a - } - else { - ! exists($$LIBSSH_DIR/build/src/libssh.a):message($$LIBSSH_DIR/build/src/libssh.a does not exist) - ! exists($$LIBSSH_DIR/build/src/threads/libssh_threads.a):message($$LIBSSH_DIR/build/src/threads/libssh_threads.a does not exist) - message(You need to download and compile libssh) - message(See http://sourceforge.net/p/retroshare/code/6163/tree/trunk/) - } - } else { - LIBS += -lssh - LIBS += -lssh_threads - } - } - - HEADERS += ssh/rssshd.h - SOURCES += ssh/rssshd.cc - - # For the Menu System - HEADERS += menu/menu.h \ - menu/menus.h \ - menu/stdiocomms.h \ - - SOURCES += menu/menu.cc \ - menu/menus.cc \ - menu/stdiocomms.cc \ - - # For the RPC System - HEADERS += rpc/rpc.h \ - rpc/rpcserver.h \ - rpc/rpcsetup.h \ - rpc/rpcecho.h \ - rpcsystem.h \ - - SOURCES += rpc/rpc.cc \ - rpc/rpcserver.cc \ - rpc/rpcsetup.cc \ - rpc/rpcecho.cc \ - - # Actual protocol files to go here... - #HEADERS += rpc/proto/rpcecho.h \ - - #SOURCES += rpc/proto/rpcecho.cc \ - - DEFINES *= RS_SSH_SERVER - - # Include Protobuf classes. - CONFIG += protorpc -} - -protorpc { - # Proto Services - PROTOS = core.proto peers.proto system.proto chat.proto search.proto files.proto stream.proto - DESTPATH = $$PWD/rpc/proto/gencc - PROTOPATH = $$PWD/../../rsctrl/src/definition - CMD = echo Building protobuf files - for(pf, PROTOS):CMD += && $${PROTOCPATH}protoc --cpp_out=$${DESTPATH} --proto_path=$${PROTOPATH} $${PROTOPATH}/$${pf} - protobuf_gen.commands = $${CMD} - QMAKE_EXTRA_TARGETS += protobuf_gen - PRE_TARGETDEPS += protobuf_gen - - HEADERS += rpc/proto/rpcprotopeers.h \ - rpc/proto/rpcprotosystem.h \ - rpc/proto/rpcprotochat.h \ - rpc/proto/rpcprotosearch.h \ - rpc/proto/rpcprotofiles.h \ - rpc/proto/rpcprotostream.h \ - rpc/proto/rpcprotoutils.h \ - - SOURCES += rpc/proto/rpcprotopeers.cc \ - rpc/proto/rpcprotosystem.cc \ - rpc/proto/rpcprotochat.cc \ - rpc/proto/rpcprotosearch.cc \ - rpc/proto/rpcprotofiles.cc \ - rpc/proto/rpcprotostream.cc \ - rpc/proto/rpcprotoutils.cc \ - - # Offical Generated Code (protobuf 2.4.1) - HEADERS += rpc/proto/gencc/core.pb.h \ - rpc/proto/gencc/peers.pb.h \ - rpc/proto/gencc/system.pb.h \ - rpc/proto/gencc/chat.pb.h \ - rpc/proto/gencc/search.pb.h \ - rpc/proto/gencc/files.pb.h \ - rpc/proto/gencc/stream.pb.h \ - - SOURCES += rpc/proto/gencc/core.pb.cc \ - rpc/proto/gencc/peers.pb.cc \ - rpc/proto/gencc/system.pb.cc \ - rpc/proto/gencc/chat.pb.cc \ - rpc/proto/gencc/search.pb.cc \ - rpc/proto/gencc/files.pb.cc \ - rpc/proto/gencc/stream.pb.cc \ - - # Generated ProtoBuf Code the RPC System - # If you are developing, or have a different version of protobuf - # you can use these ones (run make inside rsctrl/src/ to generate) - #HEADERS += ../../rsctrl/src/gencc/core.pb.h \ - # ../../rsctrl/src/gencc/peers.pb.h \ - # ../../rsctrl/src/gencc/system.pb.h \ - # ../../rsctrl/src/gencc/chat.pb.h \ - # ../../rsctrl/src/gencc/search.pb.h \ - # ../../rsctrl/src/gencc/files.pb.h \ - # ../../rsctrl/src/gencc/stream.pb.h \ - - #SOURCES += ../../rsctrl/src/gencc/core.pb.cc \ - # ../../rsctrl/src/gencc/peers.pb.cc \ - # ../../rsctrl/src/gencc/system.pb.cc \ - # ../../rsctrl/src/gencc/chat.pb.cc \ - # ../../rsctrl/src/gencc/search.pb.cc \ - # ../../rsctrl/src/gencc/files.pb.cc \ - # ../../rsctrl/src/gencc/stream.pb.cc \ - - DEPENDPATH *= rpc/proto/gencc - INCLUDEPATH *= rpc/proto/gencc - - !win32 { - # unrecognized option - QMAKE_CFLAGS += -pthread - QMAKE_CXXFLAGS += -pthread - } - LIBS += -lprotobuf -lpthread - - win32 { - DEPENDPATH += $$LIBS_DIR/include/protobuf - INCLUDEPATH += $$LIBS_DIR/include/protobuf - } - - macx { - PROTOPATH = ../../../protobuf-2.4.1 - INCLUDEPATH += $${PROTOPATH}/src - } -} diff --git a/retroshare-nogui/src/retroshare.cc b/retroshare-nogui/src/retroshare.cc index 75b9e17d8..011e03873 100644 --- a/retroshare-nogui/src/retroshare.cc +++ b/retroshare-nogui/src/retroshare.cc @@ -40,20 +40,6 @@ #include "introserver.h" #endif -#ifdef RS_SSH_SERVER -#include "ssh/rssshd.h" - -#include "menu/menus.h" -#include "menu/stdiocomms.h" - -#include "rpc/rpcsetup.h" - -// NASTY GLOBAL VARIABLE HACK - NEED TO THINK OF A BETTER SYSTEM. -#include "rpc/proto/rpcprotosystem.h" - -void generatePasswordHash() ; -#endif - #ifdef ENABLE_WEBUI #include #include "api/ApiServerMHD.h" @@ -151,123 +137,6 @@ int main(int argc, char **argv) **/ bool strictCheck = true; - -#ifdef RS_SSH_SERVER - /* parse commandline for additional nogui options */ - - int c; - // libretroshare's getopt str - so don't use any of these: "hesamui:p:c:w:l:d:U:r:R:" - // need options for - // enable SSH. (-S) - // set user/password for SSH. -L "user:pwdhash" - // accept RSA Key Auth. -K "RsaPubKeyFile" - // Terminal mode. -T - bool enableRpc = false; - bool enableSsh = false; - bool enableSshHtml = false; - bool enableTerminal = false; - bool enableSshRsa = false; - bool genPwdHash = false; - std::string sshUser = "user"; - std::string sshPwdHash = ""; - std::string sshRsaFile = ""; - - uint16_t extPort = 0; - uint16_t sshPort = 7022; - bool extPortSet = false; - bool displayRPCInfo = false ; - - argstream as(argc,argv) ; - - as >> option('X',"enable-ssh" ,enableSsh ,"Enable SSH" ) - >> option('T',"enable-terminal",enableTerminal ,"Enable terminal interface." ) - >> option('C',"enable-rpc" ,enableRpc ,"Enable RPC protocol. To be used with e.g. -X (SSH).") - >> option('G',"gen-password" ,genPwdHash ,"Generate password hash (to supply to option -P)") -#if 0 - >> option('H',"enable-ssh-html",enableSshHtml ,"Enable SSH html." ) -#endif - >> parameter('S',"ssh-port" ,sshPort ,"port" ,"SSH port to contact the interface.",false) - >> parameter('E',"ext-port" ,extPort ,"port" ,"Specify Alternative External Port (provided to Clients)",false) - >> parameter('L',"ssh-user" ,sshUser ,"name" ,"Ssh login user",false) - >> parameter('P',"ssh-p-hash" ,sshPwdHash ,"hash" ,"Ssh login password hash (Generated by retroshare-nogui -G)",false) - >> parameter('K',"ssh-key-file" ,sshRsaFile ,"RSA key file", "RSA key file for SSH login (not yet implemented).",false )// NOT FINISHED YET. - -#ifdef __APPLE__ - >> help('h',"help","Display this Help"); -#else - >> help() ; -#endif - // Normally argstream would handle this by itself, if we called - // as.defaultErrorHandling() ; - // - // but we have other parameter handling functions after, so we don't want to quit if help is requested. - // - if (as.helpRequested()) - { - std::cerr << "\nSpecific Help Options:" << std::endl; - std::cerr << as.usage() << std::endl; - std::cerr << "\t To setup rs-nogui as a SSH Server is a three step process: " << std::endl; - std::cerr << "\t 1) Generate a RSA keypair in the current directory: \"ssh-keygen -t rsa -f rs_ssh_host_rsa_key\" " << std::endl; - std::cerr << "\t 2) Generate a password hash for the RPC login: \"./retroshare-nogui -G\" " << std::endl; - std::cerr << "\t 3) Launch the RS with remote control enabled: \"./retroshare-nogui -X/-T [-C] -S [port] -L -P \" " << std::endl; - - std::cerr << "\nAdditional options: \n" << std::endl; - } - if (!as.isOk()) - { - std::cerr << as.errorLog(); - return 1; - } - - if (genPwdHash) - { - generatePasswordHash() ; - return 0 ; - } - - /* enforce conditions */ - if ((!sshRsaFile.empty() || !sshPwdHash.empty()) && (!enableSsh)) - { - std::cerr << "ERROR: SSH Server (-X) must be enabled to specify SSH Pwd (-P) or SSH RSA (-K)"; - std::cerr << std::endl; - return 1 ; - } - - if (enableSsh && (!enableSshRsa) && sshPwdHash.empty()) - { - std::cerr << "ERROR: One of (or both) SSH Pwd (-P) and SSH RSA (-K) must be specified with SSH Server (-X)"; - std::cerr << std::endl; - return 1 ; - } - - if (enableRpc && (!enableSsh)) - { - std::cerr << "ERROR: RPC Mode (-C) requires SSH Server (-X) enabled"; - std::cerr << std::endl; - return 1 ; - } - - - /* parse -S, -L & -K parameters */ - if (enableSshRsa) - { - /* check the file exists */ - /* TODO */ - - } - - if (enableSsh) - { - /* try parse it */ - /* TODO */ - - } - -#else - std::cerr << "\nRetroshare command line interface." << std::endl; -#endif - - RsInit::InitRsConfig(); int initResult = RsInit::InitRetroShare(argc, argv, strictCheck); @@ -318,38 +187,6 @@ int main(int argc, char **argv) return 1; } -#ifdef RS_SSH_SERVER - // Says it must be called before all the threads are launched! */ - // NB: this port number is not currently used. - RsSshd *ssh = NULL; - - if (enableSsh) - { - std::ostringstream os ; - os << sshPort ; - ssh = RsSshd::InitRsSshd(os.str(), "rs_ssh_host_rsa_key"); - - // TODO Parse Option - if (enableSshRsa) - { - //ssh->adduser("anrsuser", "test"); - } - - if (!sshPwdHash.empty()) - { - ssh->adduserpwdhash(sshUser, sshPwdHash); - } - - if (!extPortSet) - { - extPort = sshPort; - } - - // NASTY GLOBAL VARIABLE HACK - NEED TO THINK OF A BETTER SYSTEM. - RpcProtoSystem::mExtPort = extPort; - } -#endif - /* Start-up libretroshare server threads */ RsControl::instance() -> StartupRetroShare(); @@ -357,47 +194,6 @@ int main(int argc, char **argv) RsIntroServer rsIS; #endif -#ifdef RS_SSH_SERVER - uint32_t baseDrawFlags = 0; - if (enableSshHtml) - { - baseDrawFlags = MENU_DRAW_FLAGS_HTML; - } - - if (enableSsh) - { - if (enableRpc) - { - /* Build RPC Server */ - RpcMediator *med = CreateRpcSystem(ssh, notify); - ssh->setRpcSystem(med); - ssh->setSleepPeriods(0.01, 0.1); - } - else - { - /* create menu system for SSH */ - Menu *baseMenu = CreateMenuStructure(notify); - MenuInterface *menuInterface = new MenuInterface(ssh, baseMenu, baseDrawFlags | MENU_DRAW_FLAGS_ECHO); - ssh->setRpcSystem(menuInterface); - ssh->setSleepPeriods(0.05, 0.5); - } - - ssh->start(); - } - - MenuInterface *terminalMenu = NULL; - if (enableTerminal) - { - /* Terminal Version */ - RpcComms *stdioComms = new StdioComms(fileno(stdin), fileno(stdout)); - Menu *baseMenu = CreateMenuStructure(notify); - terminalMenu = new MenuInterface(stdioComms, baseMenu, baseDrawFlags | MENU_DRAW_FLAGS_NOQUIT); - //menuTerminal = new RsConsole(menuInterface, fileno(stdin), fileno(stdout)); - } - - -#endif - /* pass control to the GUI */ while(1) { @@ -408,13 +204,6 @@ int main(int argc, char **argv) #endif int rt = 0; -#ifdef RS_SSH_SERVER - if (terminalMenu) - { - rt = terminalMenu->tick(); - } -#endif - // If we have a MenuTerminal ... // only want to sleep if there is no input. (rt == 0). if (rt == 0) @@ -430,73 +219,4 @@ int main(int argc, char **argv) } return 1; -} - -#ifdef RS_SSH_SERVER -void generatePasswordHash() -{ - std::string saltBin; - std::string pwdHashRadix64; - std::string sshPwdForHash = ""; - - std::string passwd1,passwd2 ; - bool cancel ; - - if(!NotifyTxt().askForPassword("","Type your password (at least 8 chars) : ",false,passwd1,cancel)) exit(1) ; - - if(passwd1.length() < 8) - { - std::cerr << "Password must be at least 8 characters long." << std::endl; - exit(1); - } - - if(!NotifyTxt().askForPassword("","Type your password (checking) : ",false,passwd2,cancel)) exit(1) ; - - if(passwd1 != passwd2) - { - std::cerr << "Passwords differ. Please retry." << std::endl; - exit(1); - } - - sshPwdForHash = passwd1 ; - - //std::cerr << "Chosen Password : " << sshPwdForHash; - std::cerr << std::endl; - - GenerateSalt(saltBin); - if (!GeneratePasswordHash(saltBin, sshPwdForHash, pwdHashRadix64)) - { - std::cerr << "Error Generating Password Hash, password probably too short"; - std::cerr << pwdHashRadix64; - std::cerr << std::endl; - exit(1); - } - - std::cout << "Generated Password Hash for rs-nogui: "; - std::cout << pwdHashRadix64; - std::cout << std::endl; - std::cout << std::endl; - - /* checking match */ - if (CheckPasswordHash(pwdHashRadix64, sshPwdForHash)) - { - std::cerr << "Passed Check Okay!"; - std::cerr << std::endl; - } - else - { - std::cerr << "ERROR: Failed CheckPassword!"; - std::cerr << std::endl; - exit(1); - } - - - std::cerr << "Usage:"; - std::cerr << std::endl; - std::cerr << " - for SSH access: ./retroshare-nogui -X -S [port] -L -P " << pwdHashRadix64; - std::cerr << std::endl; - std::cerr << " - for RPC access: ./retroshare-nogui -C -X -S [port] -L -P " << pwdHashRadix64; - std::cerr << std::endl; -} -#endif - +} diff --git a/retroshare-nogui/src/rpc/proto/rpcprotochat.cc b/retroshare-nogui/src/rpc/proto/rpcprotochat.cc deleted file mode 100644 index 388685c5d..000000000 --- a/retroshare-nogui/src/rpc/proto/rpcprotochat.cc +++ /dev/null @@ -1,1477 +0,0 @@ -/* - * RetroShare External Interface. - * - * Copyright 2012-2012 by Robert Fernie. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public - * License Version 2.1 as published by the Free Software Foundation. - * - * This library 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 - * Library General Public License for more details. - * - * You should have received a copy of the GNU Library General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 - * USA. - * - * Please report all bugs and problems to "retroshare@lunamutt.com". - * - */ - -#include "rpc/proto/rpcprotochat.h" -#include "rpc/proto/gencc/chat.pb.h" - -#include -#include -#include - -#include "util/rsstring.h" - -#include - -#include -#include - -#include - - -// Helper Functions -> maybe move to libretroshare/utils ?? -bool convertUTF8toWString(const std::string &msg_utf8, std::wstring &msg_wstr); -bool convertWStringToUTF8(const std::wstring &msg_wstr, std::string &msg_utf8); - -bool convertStringToLobbyId(const std::string &chat_id, ChatLobbyId &lobby_id); -bool convertLobbyIdToString(const ChatLobbyId &lobby_id, std::string &chat_id); - -bool fillLobbyInfoFromChatLobbyInfo(const ChatLobbyInfo &cfi, rsctrl::chat::ChatLobbyInfo *lobby); -bool fillLobbyInfoFromVisibleChatLobbyRecord(const VisibleChatLobbyRecord &pclr, rsctrl::chat::ChatLobbyInfo *lobby); -bool fillLobbyInfoFromChatLobbyInvite(const ChatLobbyInvite &cli, rsctrl::chat::ChatLobbyInfo *lobby); - -bool fillChatMessageFromHistoryMsg(const HistoryMsg &histmsg, rsctrl::chat::ChatMessage *rpcmsg); - -bool createQueuedEventSendMsg(const ChatInfo &chatinfo, rsctrl::chat::ChatType ctype, - std::string chat_id, const RpcEventRegister &ereg, RpcQueuedMsg &qmsg); - - -RpcProtoChat::RpcProtoChat(uint32_t serviceId) - :RpcQueueService(serviceId) -{ - return; -} - -//RpcProtoChat::msgsAccepted(std::list &msgIds); /* not used at the moment */ - -int RpcProtoChat::processMsg(uint32_t chan_id, uint32_t msg_id, uint32_t req_id, const std::string &msg) -{ - /* check the msgId */ - uint8_t topbyte = getRpcMsgIdExtension(msg_id); - uint16_t service = getRpcMsgIdService(msg_id); - uint8_t submsg = getRpcMsgIdSubMsg(msg_id); - bool isResponse = isRpcMsgIdResponse(msg_id); - - - std::cerr << "RpcProtoChat::processMsg() topbyte: " << (int32_t) topbyte; - std::cerr << " service: " << (int32_t) service << " submsg: " << (int32_t) submsg; - std::cerr << std::endl; - - if (isResponse) - { - std::cerr << "RpcProtoChat::processMsg() isResponse() - not processing"; - std::cerr << std::endl; - return 0; - } - - if (topbyte != (uint8_t) rsctrl::core::CORE) - { - std::cerr << "RpcProtoChat::processMsg() Extension Mismatch - not processing"; - std::cerr << std::endl; - return 0; - } - - if (service != (uint16_t) rsctrl::core::CHAT) - { - std::cerr << "RpcProtoChat::processMsg() Service Mismatch - not processing"; - std::cerr << std::endl; - return 0; - } - - if (!rsctrl::chat::RequestMsgIds_IsValid(submsg)) - { - std::cerr << "RpcProtoChat::processMsg() SubMsg Mismatch - not processing"; - std::cerr << std::endl; - return 0; - } - - switch(submsg) - { - case rsctrl::chat::MsgId_RequestChatLobbies: - processReqChatLobbies(chan_id, msg_id, req_id, msg); - break; - - case rsctrl::chat::MsgId_RequestCreateLobby: - processReqCreateLobby(chan_id, msg_id, req_id, msg); - break; - - case rsctrl::chat::MsgId_RequestJoinOrLeaveLobby: - processReqJoinOrLeaveLobby(chan_id, msg_id, req_id, msg); - break; - - case rsctrl::chat::MsgId_RequestSetLobbyNickname: - processReqSetLobbyNickname(chan_id, msg_id, req_id, msg); - break; - - case rsctrl::chat::MsgId_RequestRegisterEvents: - processReqRegisterEvents(chan_id, msg_id, req_id, msg); - break; - - case rsctrl::chat::MsgId_RequestSendMessage: - processReqSendMessage(chan_id, msg_id, req_id, msg); - break; - - case rsctrl::chat::MsgId_RequestChatHistory: - processReqChatHistory(chan_id, msg_id, req_id, msg); - break; - - - default: - std::cerr << "RpcProtoChat::processMsg() ERROR should never get here"; - std::cerr << std::endl; - return 0; - } - - /* must have matched id to get here */ - return 1; -} - - -// Registrations. -//#define REGISTRATION_EVENT_CHAT 1 - -int RpcProtoChat::processReqChatLobbies(uint32_t chan_id, uint32_t /*msg_id*/, uint32_t req_id, const std::string &msg) -{ - std::cerr << "RpcProtoChat::processReqChatLobbies()"; - std::cerr << std::endl; - - // parse msg. - rsctrl::chat::RequestChatLobbies req; - if (!req.ParseFromString(msg)) - { - std::cerr << "RpcProtoChat::processReqChatLobbies() ERROR ParseFromString()"; - std::cerr << std::endl; - return 0; - } - - // response. - rsctrl::chat::ResponseChatLobbies resp; - bool success = true; - std::string errorMsg; - - // set these flags from request. - bool fetch_chatlobbylist = true; - bool fetch_invites = true; - bool fetch_visiblelobbies = true; - - switch(req.lobby_set()) - { - case rsctrl::chat::RequestChatLobbies::LOBBYSET_ALL: - std::cerr << "RpcProtoChat::processReqChatLobbies() LOBBYSET_ALL"; - std::cerr << std::endl; - fetch_chatlobbylist = true; - fetch_invites = true; - fetch_visiblelobbies = true; - break; - case rsctrl::chat::RequestChatLobbies::LOBBYSET_JOINED: - std::cerr << "RpcProtoChat::processReqChatLobbies() LOBBYSET_JOINED"; - std::cerr << std::endl; - fetch_chatlobbylist = true; - fetch_invites = false; - fetch_visiblelobbies = false; - break; - case rsctrl::chat::RequestChatLobbies::LOBBYSET_INVITED: - std::cerr << "RpcProtoChat::processReqChatLobbies() LOBBYSET_INVITED"; - std::cerr << std::endl; - fetch_chatlobbylist = false; - fetch_invites = true; - fetch_visiblelobbies = false; - break; - case rsctrl::chat::RequestChatLobbies::LOBBYSET_VISIBLE: - std::cerr << "RpcProtoChat::processReqChatLobbies() LOBBYSET_VISIBLE"; - std::cerr << std::endl; - fetch_chatlobbylist = false; - fetch_invites = false; - fetch_visiblelobbies = true; - break; - default: - std::cerr << "RpcProtoChat::processReqChatLobbies() LOBBYSET ERROR"; - std::cerr << std::endl; - success = false; - errorMsg = "Invalid Lobby Set"; - } - - - std::set done_lobbies; // list of ones we've added already (to avoid duplicates). - - if (fetch_chatlobbylist) - { - std::cerr << "RpcProtoChat::processReqChatLobbies() Fetching chatlobbylist"; - std::cerr << std::endl; - - std::list cl_info; - std::list::iterator it; - - rsMsgs->getChatLobbyList(cl_info); - - for(it = cl_info.begin(); it != cl_info.end(); it++) - { - rsctrl::chat::ChatLobbyInfo *lobby = resp.add_lobbies(); - fillLobbyInfoFromChatLobbyInfo(*it, lobby); - - done_lobbies.insert(it->lobby_id); - - std::cerr << "\t Added Lobby: " << it->lobby_id; - std::cerr << std::endl; - } - } - - /* This is before Public Lobbies - as knowing you have been invited is - * more important, than the full info that might be gleaned from lobby. - * In the future, we might try to merge the info. - */ - if (fetch_invites) - { - std::cerr << "RpcProtoChat::processReqChatLobbies() Fetching invites"; - std::cerr << std::endl; - - std::list invites; - std::list::iterator it; - rsMsgs->getPendingChatLobbyInvites(invites); - - for(it = invites.begin(); it != invites.end(); it++) - { - if (done_lobbies.find(it->lobby_id) == done_lobbies.end()) - { - rsctrl::chat::ChatLobbyInfo *lobby = resp.add_lobbies(); - fillLobbyInfoFromChatLobbyInvite(*it, lobby); - - done_lobbies.insert(it->lobby_id); - - std::cerr << "\t Added Lobby: " << it->lobby_id; - std::cerr << std::endl; - } - else - { - std::cerr << "\t Skipping Already Added Lobby: " << it->lobby_id; - std::cerr << std::endl; - } - } - } - - if (fetch_visiblelobbies) - { - std::cerr << "RpcProtoChat::processReqChatLobbies() Fetching public lobbies"; - std::cerr << std::endl; - - std::vector public_lobbies; - std::vector::iterator it; - - rsMsgs->getListOfNearbyChatLobbies(public_lobbies); - - for(it = public_lobbies.begin(); it != public_lobbies.end(); it++) - { - if (done_lobbies.find(it->lobby_id) == done_lobbies.end()) - { - rsctrl::chat::ChatLobbyInfo *lobby = resp.add_lobbies(); - fillLobbyInfoFromVisibleChatLobbyRecord(*it, lobby); - - done_lobbies.insert(it->lobby_id); - - std::cerr << "\t Added Lobby: " << it->lobby_id; - std::cerr << std::endl; - } - else - { - std::cerr << "\t Skipping Already Added Lobby: " << it->lobby_id; - std::cerr << std::endl; - } - } - } - - - /* DONE - Generate Reply */ - if (success) - { - rsctrl::core::Status *status = resp.mutable_status(); - status->set_code(rsctrl::core::Status::SUCCESS); - } - else - { - rsctrl::core::Status *status = resp.mutable_status(); - status->set_code(rsctrl::core::Status::FAILED); - status->set_msg(errorMsg); - } - - std::string outmsg; - if (!resp.SerializeToString(&outmsg)) - { - std::cerr << "RpcProtoChat::processReqChatLobbies() ERROR SerialiseToString()"; - std::cerr << std::endl; - return 0; - } - - // Correctly Name Message. - uint32_t out_msg_id = constructMsgId(rsctrl::core::CORE, rsctrl::core::CHAT, - rsctrl::chat::MsgId_ResponseChatLobbies, true); - - // queue it. - queueResponse(chan_id, out_msg_id, req_id, outmsg); - - return 1; -} - - - -int RpcProtoChat::processReqCreateLobby(uint32_t chan_id, uint32_t /*msg_id*/, uint32_t req_id, const std::string &msg) -{ - std::cerr << "RpcProtoChat::processReqCreateLobby()"; - std::cerr << std::endl; - - // parse msg. - rsctrl::chat::RequestCreateLobby req; - if (!req.ParseFromString(msg)) - { - std::cerr << "RpcProtoChat::processReqCreateLobby() ERROR ParseFromString()"; - std::cerr << std::endl; - return 0; - } - - // response. - rsctrl::chat::ResponseChatLobbies resp; - bool success = true; - std::string errorMsg; - - /* convert msg parameters into local ones */ - - std::string lobby_name = req.lobby_name(); - std::string lobby_topic = req.lobby_topic(); - std::list invited_friends; - uint32_t lobby_privacy_type = 0; - - switch(req.privacy_level()) - { - case rsctrl::chat::PRIVACY_PRIVATE: - std::cerr << "\tCreating Private Lobby"; - std::cerr << std::endl; - lobby_privacy_type = RS_CHAT_LOBBY_PRIVACY_LEVEL_PRIVATE; - break; - case rsctrl::chat::PRIVACY_PUBLIC: - std::cerr << "\tCreating Public Lobby"; - std::cerr << std::endl; - lobby_privacy_type = RS_CHAT_LOBBY_PRIVACY_LEVEL_PUBLIC; - break; - default: - std::cerr << "ERROR invalid Privacy Level"; - std::cerr << std::endl; - - success = false; - errorMsg = "Invalid Privacy Level"; - } - - int no_invites = req.invited_friends_size(); - for(int i = 0; i < no_invites; i++) - { - std::string peer = req.invited_friends(i); - /* check that they are a valid friend */ - if (!rsPeers->isFriend(peer)) // checks SSL ID. - { - std::cerr << "ERROR invalid SSL Friend ID: " << peer; - std::cerr << std::endl; - - success = false; - errorMsg = "Invalid SSL Friend ID"; - break; - } - - std::cerr << "Adding Valid Friend to Invites: " << peer; - std::cerr << std::endl; - - invited_friends.push_back(peer); - } - - ChatLobbyId created_lobby_id = 0; - if (success) - { - created_lobby_id = rsMsgs->createChatLobby(lobby_name,lobby_topic, - invited_friends,lobby_privacy_type); - - std::cerr << "Created Lobby Id: " << created_lobby_id; - std::cerr << std::endl; - - std::list cl_info; - std::list::iterator it; - - rsMsgs->getChatLobbyList(cl_info); - - bool found_entry = false; - for(it = cl_info.begin(); it != cl_info.end(); it++) - { - if (it->lobby_id == created_lobby_id) - { - std::cerr << "Found Created Lobby Id: " << created_lobby_id; - std::cerr << std::endl; - - rsctrl::chat::ChatLobbyInfo *lobby = resp.add_lobbies(); - fillLobbyInfoFromChatLobbyInfo(*it, lobby); - found_entry = true; - break; - } - } - - if (!found_entry) - { - std::cerr << "FAILED TO FIND Created Lobby Id: " << created_lobby_id; - std::cerr << std::endl; - - success = false; - errorMsg = "Chat Lobby Creation appears to have failed"; - } - } - - /* DONE - Generate Reply */ - if (success) - { - rsctrl::core::Status *status = resp.mutable_status(); - status->set_code(rsctrl::core::Status::SUCCESS); - } - else - { - rsctrl::core::Status *status = resp.mutable_status(); - status->set_code(rsctrl::core::Status::FAILED); - status->set_msg(errorMsg); - } - - std::string outmsg; - if (!resp.SerializeToString(&outmsg)) - { - std::cerr << "RpcProtoChat::processReqCreateLobbies() ERROR SerialiseToString()"; - std::cerr << std::endl; - return 0; - } - - // Correctly Name Message. - uint32_t out_msg_id = constructMsgId(rsctrl::core::CORE, rsctrl::core::CHAT, - rsctrl::chat::MsgId_ResponseChatLobbies, true); - - // queue it. - queueResponse(chan_id, out_msg_id, req_id, outmsg); - - return 1; -} - - - -int RpcProtoChat::processReqJoinOrLeaveLobby(uint32_t chan_id, uint32_t /*msg_id*/, uint32_t req_id, const std::string &msg) -{ - std::cerr << "RpcProtoChat::processReqJoinOrLeaveLobby()"; - std::cerr << std::endl; - - // parse msg. - rsctrl::chat::RequestJoinOrLeaveLobby req; - if (!req.ParseFromString(msg)) - { - std::cerr << "RpcProtoChat::processReqJoinOrLeaveLobby() ERROR ParseFromString()"; - std::cerr << std::endl; - return 0; - } - - // response. - rsctrl::chat::ResponseChatLobbies resp; - bool success = false; - std::string errorMsg; - - /* convert msg parameters into local ones */ - ChatLobbyId lobby_id = 0; - convertStringToLobbyId(req.lobby_id(), lobby_id); - - std::cerr << "Requested Lobby is: " << lobby_id; - std::cerr << std::endl; - - /* now must work out if its an invite or an existing lobby */ - /* look for a pending invitation */ - bool isPendingInvite = false; - { - std::list invites; - std::list::iterator it; - rsMsgs->getPendingChatLobbyInvites(invites); - - for(it = invites.begin(); it != invites.end(); it++) - { - if (it->lobby_id == lobby_id) - { - std::cerr << "It is a Pending Invite" << lobby_id; - std::cerr << std::endl; - - isPendingInvite = true; - break; - } - } - } - - switch(req.action()) - { - case rsctrl::chat::RequestJoinOrLeaveLobby::JOIN_OR_ACCEPT: - { - std::cerr << "Request to JOIN_OR_ACCEPT"; - std::cerr << std::endl; - - if (isPendingInvite) - { - if (!rsMsgs->acceptLobbyInvite(lobby_id)) - { - std::cerr << "ERROR acceptLobbyInvite FAILED"; - std::cerr << std::endl; - - success = false; - errorMsg = "AcceptLobbyInvite returned False"; - } - } - else - { - if (!rsMsgs->joinVisibleChatLobby(lobby_id)) - { - std::cerr << "ERROR joinPublicChatLobby FAILED"; - std::cerr << std::endl; - - success = false; - errorMsg = "joinPublicChatLobby returned False"; - } - } - - break; - } - case rsctrl::chat::RequestJoinOrLeaveLobby::LEAVE_OR_DENY: - { - std::cerr << "Request to LEAVE_OR_DENY (No fail codes!)"; - std::cerr << std::endl; - - if (isPendingInvite) - { - // return void - so can't check. - rsMsgs->denyLobbyInvite(lobby_id); - } - else - { - // return void - so can't check. - rsMsgs->unsubscribeChatLobby(lobby_id); - } - - break; - } - default: - success = false; - errorMsg = "Unknown Action"; - } - - - if (success && (req.action() == rsctrl::chat::RequestJoinOrLeaveLobby::JOIN_OR_ACCEPT)) - { - std::list cl_info; - std::list::iterator it; - - rsMsgs->getChatLobbyList(cl_info); - - bool found_entry = false; - for(it = cl_info.begin(); it != cl_info.end(); it++) - { - if (it->lobby_id == lobby_id) - { - rsctrl::chat::ChatLobbyInfo *lobby = resp.add_lobbies(); - fillLobbyInfoFromChatLobbyInfo(*it, lobby); - found_entry = true; - break; - } - } - - if (!found_entry) - { - success = false; - errorMsg = "Chat Lobby JOIN/ACCEPT appears to have failed"; - } - } - - /* DONE - Generate Reply */ - if (success) - { - rsctrl::core::Status *status = resp.mutable_status(); - status->set_code(rsctrl::core::Status::SUCCESS); - } - else - { - rsctrl::core::Status *status = resp.mutable_status(); - status->set_code(rsctrl::core::Status::FAILED); - status->set_msg(errorMsg); - } - - std::string outmsg; - if (!resp.SerializeToString(&outmsg)) - { - std::cerr << "RpcProtoChat::processReqCreateLobbies() ERROR SerialiseToString()"; - std::cerr << std::endl; - return 0; - } - - // Correctly Name Message. - uint32_t out_msg_id = constructMsgId(rsctrl::core::CORE, rsctrl::core::CHAT, - rsctrl::chat::MsgId_ResponseChatLobbies, true); - - // queue it. - queueResponse(chan_id, out_msg_id, req_id, outmsg); - - return 1; -} - - - -int RpcProtoChat::processReqSetLobbyNickname(uint32_t chan_id, uint32_t /*msg_id*/, uint32_t req_id, const std::string &msg) -{ - std::cerr << "RpcProtoChat::processReqSetLobbyNickname()"; - std::cerr << std::endl; - - // parse msg. - rsctrl::chat::RequestSetLobbyNickname req; - if (!req.ParseFromString(msg)) - { - std::cerr << "RpcProtoChat::processReqSetLobbyNickname() ERROR ParseFromString()"; - std::cerr << std::endl; - return 0; - } - - // response. - rsctrl::chat::ResponseSetLobbyNickname resp; - bool success = true; - std::string errorMsg; - - /* convert msg parameters into local ones */ - std::string nickname = req.nickname(); - - std::cerr << "choosen nickname is: " << nickname; - std::cerr << std::endl; - - int no_lobbyids = req.lobby_ids_size(); - for(int i = 0; i < no_lobbyids; i++) - { - std::string idstr = req.lobby_ids(i); - ChatLobbyId id = 0; - convertStringToLobbyId(idstr, id); - - std::cerr << "setting nickname for lobby: " << id; - std::cerr << std::endl; - - if (!rsMsgs->setNickNameForChatLobby(id, nickname)) - { - std::cerr << "ERROR setting nickname for lobby: " << id; - std::cerr << std::endl; - - success = false; - errorMsg = "Failed to Set one of the nicknames"; - break; - } - - } - - if (no_lobbyids == 0) - { - std::cerr << "setting default nickname"; - std::cerr << std::endl; - - /* just do default instead */ - rsMsgs->setDefaultNickNameForChatLobby(nickname); - } - - /* DONE - Generate Reply */ - if (success) - { - rsctrl::core::Status *status = resp.mutable_status(); - status->set_code(rsctrl::core::Status::SUCCESS); - } - else - { - rsctrl::core::Status *status = resp.mutable_status(); - status->set_code(rsctrl::core::Status::FAILED); - status->set_msg(errorMsg); - } - - std::string outmsg; - if (!resp.SerializeToString(&outmsg)) - { - std::cerr << "RpcProtoChat::processReqCreateLobbies() ERROR SerialiseToString()"; - std::cerr << std::endl; - return 0; - } - - // Correctly Name Message. - uint32_t out_msg_id = constructMsgId(rsctrl::core::CORE, rsctrl::core::CHAT, - rsctrl::chat::MsgId_ResponseSetLobbyNickname, true); - - // queue it. - queueResponse(chan_id, out_msg_id, req_id, outmsg); - - return 1; - -} - - - -int RpcProtoChat::processReqRegisterEvents(uint32_t chan_id, uint32_t /*msg_id*/, uint32_t req_id, const std::string &msg) -{ - std::cerr << "RpcProtoChat::processReqRegisterEvents()"; - std::cerr << std::endl; - - // parse msg. - rsctrl::chat::RequestRegisterEvents req; - if (!req.ParseFromString(msg)) - { - std::cerr << "RpcProtoChat::processReqRegisterEvents() ERROR ParseFromString()"; - std::cerr << std::endl; - return 0; - } - - // response. - rsctrl::chat::ResponseRegisterEvents resp; - bool success = true; - bool doregister = false; - std::string errorMsg; - - switch(req.action()) - { - case rsctrl::chat::RequestRegisterEvents::REGISTER: - doregister = true; - break; - case rsctrl::chat::RequestRegisterEvents::DEREGISTER: - doregister = false; - break; - default: - std::cerr << "ERROR action is invalid"; - std::cerr << std::endl; - - success = false; - errorMsg = "RegisterEvent.Action is invalid"; - break; - } - - if (success) - { - if (doregister) - { - std::cerr << "Registering for Chat Events"; - std::cerr << std::endl; - - registerForEvents(chan_id, req_id, REGISTRATION_EVENT_CHAT); - } - else - { - std::cerr << "Deregistering for Chat Events"; - std::cerr << std::endl; - - deregisterForEvents(chan_id, req_id, REGISTRATION_EVENT_CHAT); - } - printEventRegister(std::cerr); - } - - - /* DONE - Generate Reply */ - if (success) - { - rsctrl::core::Status *status = resp.mutable_status(); - status->set_code(rsctrl::core::Status::SUCCESS); - } - else - { - rsctrl::core::Status *status = resp.mutable_status(); - status->set_code(rsctrl::core::Status::FAILED); - status->set_msg(errorMsg); - } - - std::string outmsg; - if (!resp.SerializeToString(&outmsg)) - { - std::cerr << "RpcProtoChat::processReqCreateLobbies() ERROR SerialiseToString()"; - std::cerr << std::endl; - return 0; - } - - // Correctly Name Message. - uint32_t out_msg_id = constructMsgId(rsctrl::core::CORE, rsctrl::core::CHAT, - rsctrl::chat::MsgId_ResponseRegisterEvents, true); - - // queue it. - queueResponse(chan_id, out_msg_id, req_id, outmsg); - - return 1; -} - - - - -int RpcProtoChat::processReqChatHistory(uint32_t chan_id, uint32_t /*msg_id*/, uint32_t req_id, const std::string &msg) -{ - std::cerr << "RpcProtoChat::processReqChatHistory()"; - std::cerr << std::endl; - - // parse msg. - rsctrl::chat::RequestChatHistory req; - if (!req.ParseFromString(msg)) - { - std::cerr << "RpcProtoChat::processReqChatHistory() ERROR ParseFromString()"; - std::cerr << std::endl; - return 0; - } - - // response. - rsctrl::chat::ResponseChatHistory resp; - bool success = true; - std::string errorMsg; - - // Get the Chat History for specified IDs.... - - /* switch depending on type */ - bool private_chat = false; - bool lobby_chat = false; - std::string chat_id; - - // copy the ID over. - rsctrl::chat::ChatId *id = resp.mutable_id(); - *id = req.id(); - - switch(req.id().chat_type()) - { - case rsctrl::chat::TYPE_PRIVATE: - { - // easy one. - chat_id = req.id().chat_id(); - private_chat = true; - - std::cerr << "RpcProtoChat::processReqChatHistory() Getting Private Chat History for: "; - std::cerr << chat_id; - std::cerr << std::endl; - - break; - } - case rsctrl::chat::TYPE_LOBBY: - { - std::cerr << "RpcProtoChat::processReqChatHistory() Lobby Chat History NOT IMPLEMENTED YET"; - std::cerr << std::endl; - success = false; - lobby_chat = true; - errorMsg = "Lobby Chat History Not Implemented"; - -#if 0 - /* convert string->ChatLobbyId */ - ChatLobbyId lobby_id; - if (!convertStringToLobbyId(req.msg().id().chat_id(), lobby_id)) - { - std::cerr << "ERROR Failed conversion of Lobby Id"; - std::cerr << std::endl; - - success = false; - errorMsg = "Failed Conversion of Lobby Id"; - } - /* convert lobby id to virtual peer id */ - else if (!rsMsgs->getVirtualPeerId(lobby_id, chat_id)) - { - std::cerr << "ERROR Invalid Lobby Id"; - std::cerr << std::endl; - - success = false; - errorMsg = "Invalid Lobby Id"; - } - lobby_chat = true; - std::cerr << "RpcProtoChat::processReqChatHistory() Getting Lobby Chat History for: "; - std::cerr << chat_id; - std::cerr << std::endl; -#endif - - break; - } - case rsctrl::chat::TYPE_GROUP: - - std::cerr << "RpcProtoChat::processReqChatHistory() Group Chat History NOT IMPLEMENTED YET"; - std::cerr << std::endl; - success = false; - errorMsg = "Group Chat History Not Implemented"; - - break; - default: - - std::cerr << "ERROR Chat Type invalid"; - std::cerr << std::endl; - - success = false; - errorMsg = "Invalid Chat Type"; - break; - } - - // Should be able to reply using the existing message types. - if (success) - { - if (private_chat) - { - /* extract the history */ - std::list msgs; - std::list::iterator it; - rsHistory->getMessages(chat_id, msgs, 0); - - //rsctrl::chat::ChatId *id = resp.mutable_id(); - //id->set_chat_type(rsctrl::chat::TYPE_PRIVATE); - //id->set_chat_id(chat_id); - - for(it = msgs.begin(); it != msgs.end(); it++) - { - rsctrl::chat::ChatMessage *msg = resp.add_msgs(); - fillChatMessageFromHistoryMsg(*it, msg); - - std::cerr << "\t Message: " << it->message; - std::cerr << std::endl; - } - } -#if 0 - else if (lobby_chat) - { - - - } -#endif - } - - - /* DONE - Generate Reply */ - if (success) - { - rsctrl::core::Status *status = resp.mutable_status(); - status->set_code(rsctrl::core::Status::SUCCESS); - } - else - { - rsctrl::core::Status *status = resp.mutable_status(); - status->set_code(rsctrl::core::Status::FAILED); - status->set_msg(errorMsg); - } - - std::string outmsg; - if (!resp.SerializeToString(&outmsg)) - { - std::cerr << "RpcProtoChat::processReqChatHistory() ERROR SerialiseToString()"; - std::cerr << std::endl; - return 0; - } - - // Correctly Name Message. - uint32_t out_msg_id = constructMsgId(rsctrl::core::CORE, rsctrl::core::CHAT, - rsctrl::chat::MsgId_ResponseChatHistory, true); - - // queue it. - queueResponse(chan_id, out_msg_id, req_id, outmsg); - - return 1; -} - - - - -int RpcProtoChat::processReqSendMessage(uint32_t chan_id, uint32_t /*msg_id*/, uint32_t req_id, const std::string &msg) -{ - std::cerr << "RpcProtoChat::processReqSendMessage()"; - std::cerr << std::endl; - - // parse msg. - rsctrl::chat::RequestSendMessage req; - if (!req.ParseFromString(msg)) - { - std::cerr << "RpcProtoChat::processReqSendMessage() ERROR ParseFromString()"; - std::cerr << std::endl; - return 0; - } - - // response. - rsctrl::chat::ResponseSendMessage resp; - bool success = true; - std::string errorMsg; - - // Send the message. - bool priv_or_lobby = true; - std::string chat_id; - std::string chat_msg = req.msg().msg() ; - - std::cerr << "Chat Message is: " << req.msg().msg(); - std::cerr << std::endl; - - /* switch depending on type */ - switch(req.msg().id().chat_type()) - { - case rsctrl::chat::TYPE_PRIVATE: - // easy one. - chat_id = req.msg().id().chat_id(); - priv_or_lobby = true; - - std::cerr << "Sending Private Chat"; - std::cerr << std::endl; - - - break; - case rsctrl::chat::TYPE_LOBBY: - { - std::cerr << "Sending Lobby Chat"; - std::cerr << std::endl; - - /* convert string->ChatLobbyId */ - ChatLobbyId lobby_id; - if (!convertStringToLobbyId(req.msg().id().chat_id(), lobby_id)) - { - std::cerr << "ERROR Failed conversion of Lobby Id"; - std::cerr << std::endl; - - success = false; - errorMsg = "Failed Conversion of Lobby Id"; - } - /* convert lobby id to virtual peer id */ - else if (!rsMsgs->getVirtualPeerId(lobby_id, chat_id)) - { - std::cerr << "ERROR Invalid Lobby Id"; - std::cerr << std::endl; - - success = false; - errorMsg = "Invalid Lobby Id"; - } - priv_or_lobby = true; - break; - } - case rsctrl::chat::TYPE_GROUP: - - std::cerr << "Sending Group Chat"; - std::cerr << std::endl; - - priv_or_lobby = false; - break; - default: - - std::cerr << "ERROR Chat Type invalid"; - std::cerr << std::endl; - - success = false; - errorMsg = "Invalid Chat Type"; - break; - } - - if (success) - { - if (priv_or_lobby) - { - rsMsgs->sendPrivateChat(chat_id, chat_msg); - } - else - { - rsMsgs->sendPublicChat(chat_msg); - } - } - - /* DONE - Generate Reply */ - - if (success) - { - rsctrl::core::Status *status = resp.mutable_status(); - status->set_code(rsctrl::core::Status::SUCCESS); - } - else - { - rsctrl::core::Status *status = resp.mutable_status(); - status->set_code(rsctrl::core::Status::FAILED); - status->set_msg(errorMsg); - } - - std::string outmsg; - if (!resp.SerializeToString(&outmsg)) - { - std::cerr << "RpcProtoChat::processReqSendMessage() ERROR SerialiseToString()"; - std::cerr << std::endl; - return 0; - } - - // Correctly Name Message. - uint32_t out_msg_id = constructMsgId(rsctrl::core::CORE, rsctrl::core::CHAT, - rsctrl::chat::MsgId_ResponseSendMessage, true); - - // queue it. - queueResponse(chan_id, out_msg_id, req_id, outmsg); - - return 1; -} - - // EVENTS. -int RpcProtoChat::locked_checkForEvents(uint32_t event, const std::list ®istered, std::list &events) -{ - /* Wow - here already! */ - //std::cerr << "locked_checkForEvents()"; - //std::cerr << std::endl; - - /* only one event type for now */ - if (event != REGISTRATION_EVENT_CHAT) - { - std::cerr << "ERROR Invalid Chat Event Type"; - std::cerr << std::endl; - - /* error */ - return 0; - } - - /* possible events */ - /* TODO lobby invites. how do we make sure these are only sent once? */ - - // Likewise with Chat Queues -> We'll have to track which items have been sent - // to which Chan Ids.... a bit painful. - - /* public chat queues */ - if (rsMsgs->getPublicChatQueueCount() > 0) - { - std::cerr << "Fetching Public Chat Queue"; - std::cerr << std::endl; - - std::list chats; - rsMsgs->getPublicChatQueue(chats); - std::list::iterator it; - for(it = chats.begin(); it != chats.end(); it++) - { - std::cerr << "Public Chat from : " << it->rsid; - std::cerr << " name: " << it->peer_nickname; - std::cerr << std::endl; - { - std::cerr << " Msg: " << it->msg ; - std::cerr << std::endl; - } - - /* must send to all registered clients */ - std::list::const_iterator rit; - for(rit = registered.begin(); rit != registered.end(); rit++) - { - RpcQueuedMsg qmsg; - rsctrl::chat::ChatType ctype = rsctrl::chat::TYPE_GROUP; - std::string chat_id = ""; // No ID for group. - - if (createQueuedEventSendMsg(*it, ctype, chat_id, *rit, qmsg)) - { - std::cerr << "Created MsgEvent"; - std::cerr << std::endl; - - events.push_back(qmsg); - } - else - { - std::cerr << "ERROR Creating MsgEvent"; - std::cerr << std::endl; - } - } - } - } - - - /* private chat queues */ - bool incoming = true; // ignore outgoing for now. (client can request that some other way) - if (rsMsgs->getPrivateChatQueueCount(incoming) > 0) - { - std::cerr << "Fetching Private Chat Queues"; - std::cerr << std::endl; - - std::list priv_chat_ids; - std::list::iterator cit; - rsMsgs->getPrivateChatQueueIds(incoming, priv_chat_ids); - for(cit = priv_chat_ids.begin(); cit != priv_chat_ids.end(); cit++) - { - std::list chats; - rsMsgs->getPrivateChatQueue(incoming, *cit, chats); - rsMsgs->clearPrivateChatQueue(incoming, *cit); - - // Default to Private. - rsctrl::chat::ChatType ctype = rsctrl::chat::TYPE_PRIVATE; - std::string chat_id = *cit; - - - // Check if its actually a LobbyId. - ChatLobbyId lobby_id; - if (rsMsgs->isLobbyId(*cit, lobby_id)) - { - ctype = rsctrl::chat::TYPE_LOBBY; - chat_id.clear(); - convertLobbyIdToString(lobby_id, chat_id); - - std::cerr << "Lobby Chat Queue: " << chat_id; - std::cerr << std::endl; - } - else - { - std::cerr << "Private Chat Queue: " << *cit; - std::cerr << std::endl; - } - - std::list::iterator it; - for(it = chats.begin(); it != chats.end(); it++) - { - std::cerr << "Private Chat from : " << it->rsid; - std::cerr << " name: " << it->peer_nickname; - std::cerr << std::endl; - { - std::cerr << " Msg: " << it->msg; - std::cerr << std::endl; - } - /* must send to all registered clients */ - std::list::const_iterator rit; - for(rit = registered.begin(); rit != registered.end(); rit++) - { - RpcQueuedMsg qmsg; - if (createQueuedEventSendMsg(*it, ctype, chat_id, *rit, qmsg)) - { - std::cerr << "Created MsgEvent"; - std::cerr << std::endl; - - events.push_back(qmsg); - } - else - { - std::cerr << "ERROR Creating MsgEvent"; - std::cerr << std::endl; - } - } - } - } - } - - return 1; -} - - -/***** HELPER FUNCTIONS *****/ - - - -bool fillLobbyInfoFromChatLobbyInfo(const ChatLobbyInfo &cli, rsctrl::chat::ChatLobbyInfo *lobby) -{ - /* convert info into response */ - std::string chat_id; - convertLobbyIdToString(cli.lobby_id, chat_id); - lobby->set_lobby_id(chat_id); - lobby->set_lobby_name(cli.lobby_name); - lobby->set_lobby_topic(cli.lobby_topic); - - /* see if there's a specific nickname for here */ - std::string nick; - if (!rsMsgs->getNickNameForChatLobby(cli.lobby_id,nick)) - { - rsMsgs->getDefaultNickNameForChatLobby(nick); - } - - lobby->set_lobby_nickname(nick); - - // Could be Private or Public. - if (cli.lobby_privacy_level & RS_CHAT_LOBBY_PRIVACY_LEVEL_PRIVATE) - { - lobby->set_privacy_level(rsctrl::chat::PRIVACY_PRIVATE); - } - else - { - lobby->set_privacy_level(rsctrl::chat::PRIVACY_PUBLIC); - } - lobby->set_lobby_state(rsctrl::chat::ChatLobbyInfo::LOBBYSTATE_JOINED); - - lobby->set_no_peers(cli.nick_names.size()); - - lobby->set_last_report_time(0); - lobby->set_last_activity(cli.last_activity); - - std::set::const_iterator pit; - for(pit = cli.participating_friends.begin(); pit != cli.participating_friends.end(); pit++) - { - lobby->add_participating_friends(*pit); - } - - std::map::const_iterator mit; - for(mit = cli.nick_names.begin(); mit != cli.nick_names.end(); mit++) - { - lobby->add_nicknames(mit->first); - } - return true; -} - - -bool fillLobbyInfoFromVisibleChatLobbyRecord(const VisibleChatLobbyRecord &pclr, rsctrl::chat::ChatLobbyInfo *lobby) -{ - /* convert info into response */ - std::string chat_id; - convertLobbyIdToString(pclr.lobby_id, chat_id); - lobby->set_lobby_id(chat_id); - lobby->set_lobby_name(pclr.lobby_name); - lobby->set_lobby_topic(pclr.lobby_topic); - - /* see if there's a specific nickname for here */ - std::string nick; - if (!rsMsgs->getNickNameForChatLobby(pclr.lobby_id,nick)) - { - rsMsgs->getDefaultNickNameForChatLobby(nick); - } - - lobby->set_lobby_nickname(nick); - - // Could be Private or Public. - if (pclr.lobby_privacy_level & RS_CHAT_LOBBY_PRIVACY_LEVEL_PRIVATE) - { - lobby->set_privacy_level(rsctrl::chat::PRIVACY_PRIVATE); - } - else - { - lobby->set_privacy_level(rsctrl::chat::PRIVACY_PUBLIC); - } - // TODO. - lobby->set_lobby_state(rsctrl::chat::ChatLobbyInfo::LOBBYSTATE_VISIBLE); - - lobby->set_no_peers(pclr.total_number_of_peers); - - lobby->set_last_report_time(pclr.last_report_time); - lobby->set_last_activity(0); // Unknown. - - std::set::const_iterator it; - for(it = pclr.participating_friends.begin(); it != pclr.participating_friends.begin(); it++) - { - lobby->add_participating_friends(*it); - } - - //lobby->add_nicknames(); // Unknown. - return true; -} - - -bool fillLobbyInfoFromChatLobbyInvite(const ChatLobbyInvite &cli, rsctrl::chat::ChatLobbyInfo *lobby) -{ - /* convert info into response */ - std::string chat_id; - convertLobbyIdToString(cli.lobby_id, chat_id); - lobby->set_lobby_id(chat_id); - lobby->set_lobby_name(cli.lobby_name); - lobby->set_lobby_topic(cli.lobby_topic); - - /* see if there's a specific nickname for here */ - std::string nick; - if (!rsMsgs->getNickNameForChatLobby(cli.lobby_id,nick)) - { - rsMsgs->getDefaultNickNameForChatLobby(nick); - } - - lobby->set_lobby_nickname(nick); - - // Can be invited to both Public and Private. - if (cli.lobby_privacy_level & RS_CHAT_LOBBY_PRIVACY_LEVEL_PRIVATE) - { - lobby->set_privacy_level(rsctrl::chat::PRIVACY_PRIVATE); - } - else - { - lobby->set_privacy_level(rsctrl::chat::PRIVACY_PUBLIC); - } - lobby->set_lobby_state(rsctrl::chat::ChatLobbyInfo::LOBBYSTATE_INVITED); - - lobby->set_no_peers(0); // Unknown. - - lobby->set_last_report_time(0); // Unknown - lobby->set_last_activity(0); // Unknown - - // Unknown, but we can fill in the inviting party here (the only one we know). - lobby->add_participating_friends(cli.peer_id); - //lobby->add_nicknames(); // Unknown. - return true; -} - - -bool fillChatMessageFromHistoryMsg(const HistoryMsg &histmsg, rsctrl::chat::ChatMessage *rpcmsg) -{ - rsctrl::chat::ChatId *id = rpcmsg->mutable_id(); - - id->set_chat_type(rsctrl::chat::TYPE_PRIVATE); - id->set_chat_id(histmsg.chatPeerId); - - rpcmsg->set_msg(histmsg.message); - - rpcmsg->set_peer_nickname(histmsg.peerName); - rpcmsg->set_chat_flags(0); - - rpcmsg->set_send_time(histmsg.sendTime); - rpcmsg->set_recv_time(histmsg.recvTime); - - return true; -} - - -bool createQueuedEventSendMsg(const ChatInfo &chatinfo, rsctrl::chat::ChatType ctype, - std::string chat_id, const RpcEventRegister &ereg, RpcQueuedMsg &qmsg) -{ - - rsctrl::chat::EventChatMessage event; - rsctrl::chat::ChatMessage *msg = event.mutable_msg(); - rsctrl::chat::ChatId *id = msg->mutable_id(); - - id->set_chat_type(ctype); - id->set_chat_id(chat_id); - - msg->set_peer_nickname(chatinfo.peer_nickname); - msg->set_chat_flags(chatinfo.chatflags); - msg->set_send_time(chatinfo.sendTime); - msg->set_recv_time(chatinfo.recvTime); - msg->set_msg(chatinfo.msg); - - /* DONE - Generate Reply */ - std::string outmsg; - if (!event.SerializeToString(&outmsg)) - { - std::cerr << "RpcProtoChat::createQueuedEventSendMsg() ERROR SerialiseToString()"; - std::cerr << std::endl; - return false; - } - - // Correctly Name Message. - qmsg.mMsgId = constructMsgId(rsctrl::core::CORE, rsctrl::core::CHAT, - rsctrl::chat::MsgId_EventChatMessage, true); - - qmsg.mChanId = ereg.mChanId; - qmsg.mReqId = ereg.mReqId; - qmsg.mMsg = outmsg; - - return true; -} - - - - -bool convertUTF8toWString(const std::string &msg_utf8, std::wstring &msg_wstr) -{ - return librs::util::ConvertUtf8ToUtf16(msg_utf8, msg_wstr); -} - -bool convertWStringToUTF8(const std::wstring &msg_wstr, std::string &msg_utf8) -{ - return librs::util::ConvertUtf16ToUtf8(msg_wstr, msg_utf8); -} - - -/* dependent on ChatLobbyId definition as uint64_t */ -bool convertStringToLobbyId(const std::string &chat_id, ChatLobbyId &lobby_id) -{ - if (1 != sscanf(chat_id.c_str(), UINT64FMT, &lobby_id)) - { - return false; - } - return true; -} - -bool convertLobbyIdToString(const ChatLobbyId &lobby_id, std::string &chat_id) -{ - rs_sprintf(chat_id, UINT64FMT, lobby_id); - return true; -} - - diff --git a/retroshare-nogui/src/rpc/proto/rpcprotochat.h b/retroshare-nogui/src/rpc/proto/rpcprotochat.h deleted file mode 100644 index 08595bf3e..000000000 --- a/retroshare-nogui/src/rpc/proto/rpcprotochat.h +++ /dev/null @@ -1,56 +0,0 @@ -/* - * RetroShare External Interface. - * - * Copyright 2012-2012 by Robert Fernie. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public - * License Version 2.1 as published by the Free Software Foundation. - * - * This library 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 - * Library General Public License for more details. - * - * You should have received a copy of the GNU Library General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 - * USA. - * - * Please report all bugs and problems to "retroshare@lunamutt.com". - * - */ - - -#ifndef RS_RPC_PROTO_CHAT_H -#define RS_RPC_PROTO_CHAT_H - -#include "rpc/rpcserver.h" - -// Registrations. -#define REGISTRATION_EVENT_CHAT 1 - -class RpcProtoChat: public RpcQueueService -{ -public: - RpcProtoChat(uint32_t serviceId); - virtual int processMsg(uint32_t chan_id, uint32_t msgId, uint32_t req_id, const std::string &msg); - -protected: - - int processReqChatLobbies(uint32_t chan_id, uint32_t msg_id, uint32_t req_id, const std::string &msg); - int processReqCreateLobby(uint32_t chan_id, uint32_t msg_id, uint32_t req_id, const std::string &msg); - int processReqJoinOrLeaveLobby(uint32_t chan_id, uint32_t msg_id, uint32_t req_id, const std::string &msg); - int processReqSetLobbyNickname(uint32_t chan_id, uint32_t msg_id, uint32_t req_id, const std::string &msg); - int processReqRegisterEvents(uint32_t chan_id, uint32_t msg_id, uint32_t req_id, const std::string &msg); - int processReqSendMessage(uint32_t chan_id, uint32_t msg_id, uint32_t req_id, const std::string &msg); - - int processReqChatHistory(uint32_t chan_id, uint32_t msg_id, uint32_t req_id, const std::string &msg); - - - // EVENTS. - virtual int locked_checkForEvents(uint32_t event, const std::list ®istered, std::list &events); -}; - - -#endif /* RS_PROTO_CHAT_H */ diff --git a/retroshare-nogui/src/rpc/proto/rpcprotofiles.cc b/retroshare-nogui/src/rpc/proto/rpcprotofiles.cc deleted file mode 100644 index c5838ec50..000000000 --- a/retroshare-nogui/src/rpc/proto/rpcprotofiles.cc +++ /dev/null @@ -1,630 +0,0 @@ -/* - * RetroShare External Interface. - * - * Copyright 2012-2012 by Robert Fernie. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public - * License Version 2.1 as published by the Free Software Foundation. - * - * This library 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 - * Library General Public License for more details. - * - * You should have received a copy of the GNU Library General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 - * USA. - * - * Please report all bugs and problems to "retroshare@lunamutt.com". - * - */ - -#include "rpc/proto/rpcprotofiles.h" -#include "rpc/proto/gencc/files.pb.h" - -#include -#include - -#include "util/rsstring.h" -#include "util/rsdir.h" - -#include - -#include -#include - -#include - - -bool fill_file_from_details(rsctrl::core::File *file, DirDetails &details); -bool fill_file_as_dir(rsctrl::core::File *file, const std::string &dir_name); - -RpcProtoFiles::RpcProtoFiles(uint32_t serviceId) - :RpcQueueService(serviceId) -{ - return; -} - -int RpcProtoFiles::processMsg(uint32_t chan_id, uint32_t msg_id, uint32_t req_id, const std::string &msg) -{ - /* check the msgId */ - uint8_t topbyte = getRpcMsgIdExtension(msg_id); - uint16_t service = getRpcMsgIdService(msg_id); - uint8_t submsg = getRpcMsgIdSubMsg(msg_id); - bool isResponse = isRpcMsgIdResponse(msg_id); - - - std::cerr << "RpcProtoFiles::processMsg() topbyte: " << (int32_t) topbyte; - std::cerr << " service: " << (int32_t) service << " submsg: " << (int32_t) submsg; - std::cerr << std::endl; - - if (isResponse) - { - std::cerr << "RpcProtoFiles::processMsg() isResponse() - not processing"; - std::cerr << std::endl; - return 0; - } - - if (topbyte != (uint8_t) rsctrl::core::CORE) - { - std::cerr << "RpcProtoFiles::processMsg() Extension Mismatch - not processing"; - std::cerr << std::endl; - return 0; - } - - if (service != (uint16_t) rsctrl::core::FILES) - { - std::cerr << "RpcProtoFiles::processMsg() Service Mismatch - not processing"; - std::cerr << std::endl; - return 0; - } - - if (!rsctrl::files::RequestMsgIds_IsValid(submsg)) - { - std::cerr << "RpcProtoFiles::processMsg() SubMsg Mismatch - not processing"; - std::cerr << std::endl; - return 0; - } - - switch(submsg) - { - case rsctrl::files::MsgId_RequestTransferList: - processReqTransferList(chan_id, msg_id, req_id, msg); - break; - - case rsctrl::files::MsgId_RequestControlDownload: - processReqControlDownload(chan_id, msg_id, req_id, msg); - break; - - case rsctrl::files::MsgId_RequestShareDirList: - processReqShareDirList(chan_id, msg_id, req_id, msg); - break; - - default: - std::cerr << "RpcProtoFiles::processMsg() ERROR should never get here"; - std::cerr << std::endl; - return 0; - } - - /* must have matched id to get here */ - return 1; -} - - - -int RpcProtoFiles::processReqTransferList(uint32_t chan_id, uint32_t /* msg_id */, uint32_t req_id, const std::string &msg) -{ - std::cerr << "RpcProtoFiles::processReqTransferList()"; - std::cerr << std::endl; - - // parse msg. - rsctrl::files::RequestTransferList req; - if (!req.ParseFromString(msg)) - { - std::cerr << "RpcProtoFiles::processReqTransferList() ERROR ParseFromString()"; - std::cerr << std::endl; - return 0; - } - - // response. - rsctrl::files::ResponseTransferList resp; - bool success = true; - std::string errorMsg; - - std::list file_list; - FileSearchFlags hints(0); - - /* convert msg parameters into local ones */ - switch(req.direction()) - { - case rsctrl::files::DIRECTION_UPLOAD: - { - rsFiles->FileUploads(file_list); - hints = RS_FILE_HINTS_UPLOAD; - break; - } - case rsctrl::files::DIRECTION_DOWNLOAD: - { - rsFiles->FileDownloads(file_list); - hints = RS_FILE_HINTS_DOWNLOAD; - break; - } - default: - std::cerr << "RpcProtoFiles::processReqTransferList() ERROR Unknown Dir"; - std::cerr << std::endl; - success = false; - errorMsg = "Unknown Direction"; - break; - } - - std::list::iterator lit; - for(lit = file_list.begin(); lit != file_list.end(); lit++) - { - rsctrl::files::FileTransfer *transfer = resp.add_transfers(); - transfer->set_direction(req.direction()); - - FileInfo info; - if (!rsFiles->FileDetails(*lit, hints, info)) - { - /* error */ - continue; - } - - /* copy file details */ - rsctrl::core::File *filedetails = transfer->mutable_file(); - filedetails->set_hash(info.hash); - filedetails->set_size(info.size); - filedetails->set_name(info.fname); - - transfer->set_fraction( (float) info.transfered / info.size ); - transfer->set_rate_kbs( info.tfRate ); - - switch(info.downloadStatus) - { - case FT_STATE_FAILED: - transfer->set_state(rsctrl::files::TRANSFER_FAILED); - break; - default: - case FT_STATE_OKAY: - transfer->set_state(rsctrl::files::TRANSFER_OKAY); - break; - case FT_STATE_PAUSED: - transfer->set_state(rsctrl::files::TRANSFER_PAUSED); - break; - case FT_STATE_QUEUED: - transfer->set_state(rsctrl::files::TRANSFER_QUEUED); - break; - case FT_STATE_WAITING: - transfer->set_state(rsctrl::files::TRANSFER_WAITING); - break; - case FT_STATE_DOWNLOADING: - transfer->set_state(rsctrl::files::TRANSFER_DOWNLOADING); - break; - case FT_STATE_CHECKING_HASH: - transfer->set_state(rsctrl::files::TRANSFER_CHECKING_HASH); - break; - case FT_STATE_COMPLETE: - transfer->set_state(rsctrl::files::TRANSFER_COMPLETE); - break; - } - } - - /* DONE - Generate Reply */ - if (success) - { - rsctrl::core::Status *status = resp.mutable_status(); - status->set_code(rsctrl::core::Status::SUCCESS); - } - else - { - rsctrl::core::Status *status = resp.mutable_status(); - status->set_code(rsctrl::core::Status::FAILED); - status->set_msg(errorMsg); - } - - std::string outmsg; - if (!resp.SerializeToString(&outmsg)) - { - std::cerr << "RpcProtoFiles::processReqTransferList() ERROR SerialiseToString()"; - std::cerr << std::endl; - return 0; - } - - // Correctly Name Message. - uint32_t out_msg_id = constructMsgId(rsctrl::core::CORE, rsctrl::core::FILES, - rsctrl::files::MsgId_ResponseTransferList, true); - - // queue it. - queueResponse(chan_id, out_msg_id, req_id, outmsg); - - return 1; -} - -int RpcProtoFiles::processReqControlDownload(uint32_t chan_id, uint32_t /* msg_id */, uint32_t req_id, const std::string &msg) -{ - std::cerr << "RpcProtoFiles::processReqControlDownload()"; - std::cerr << std::endl; - - // parse msg. - rsctrl::files::RequestControlDownload req; - if (!req.ParseFromString(msg)) - { - std::cerr << "RpcProtoFiles::processReqControlDownload() ERROR ParseFromString()"; - std::cerr << std::endl; - return 0; - } - - // response. - rsctrl::files::ResponseControlDownload resp; - bool success = true; - std::string errorMsg; - - std::string filehash = req.file().hash(); - switch(req.action()) - { - case rsctrl::files::RequestControlDownload::ACTION_START: - { - std::list srcIds; - - std::string filename = req.file().name(); - uint64_t filesize = req.file().size(); - - // We Set NETWORK_WIDE flag here -> as files will be found via search. - // If this changes, we might be adjust flag (or pass it in!) - if (!rsFiles -> FileRequest(filename, filehash, filesize, - "", RS_FILE_REQ_ANONYMOUS_ROUTING, srcIds)) - { - success = false; - errorMsg = "FileRequest ERROR"; - } - break; - } - case rsctrl::files::RequestControlDownload::ACTION_CONTINUE: - { - if (!rsFiles->changeQueuePosition(filehash,QUEUE_TOP)) - { - success = false; - errorMsg = "File QueuePosition(Top) ERROR"; - } - break; - } - case rsctrl::files::RequestControlDownload::ACTION_WAIT: - { - if (!rsFiles->changeQueuePosition(filehash,QUEUE_BOTTOM)) - { - success = false; - errorMsg = "File QueuePosition(Bottom) ERROR"; - - } - break; - } - case rsctrl::files::RequestControlDownload::ACTION_PAUSE: - { - if (!rsFiles->FileControl(filehash,RS_FILE_CTRL_PAUSE)) - { - success = false; - errorMsg = "FileControl(Pause) ERROR"; - - } - break; - } - case rsctrl::files::RequestControlDownload::ACTION_RESTART: - { - if (!rsFiles->FileControl(filehash,RS_FILE_CTRL_START)) - { - success = false; - errorMsg = "FileControl(Start) ERROR"; - - } - break; - } - case rsctrl::files::RequestControlDownload::ACTION_CHECK: - { - if (!rsFiles->FileControl(filehash,RS_FILE_CTRL_FORCE_CHECK)) - { - success = false; - errorMsg = "FileControl(Check) ERROR"; - - } - break; - } - case rsctrl::files::RequestControlDownload::ACTION_CANCEL: - { - if (!rsFiles->FileCancel(filehash)) - { - success = false; - errorMsg = "FileCancel ERROR"; - } - break; - } - default: - success = false; - errorMsg = "Invalid Action"; - break; - } - - - /* DONE - Generate Reply */ - if (success) - { - rsctrl::core::Status *status = resp.mutable_status(); - status->set_code(rsctrl::core::Status::SUCCESS); - } - else - { - rsctrl::core::Status *status = resp.mutable_status(); - status->set_code(rsctrl::core::Status::FAILED); - status->set_msg(errorMsg); - } - - std::string outmsg; - if (!resp.SerializeToString(&outmsg)) - { - std::cerr << "RpcProtoFiles::processReqControlDownload() ERROR SerialiseToString()"; - std::cerr << std::endl; - return 0; - } - - // Correctly Name Message. - uint32_t out_msg_id = constructMsgId(rsctrl::core::CORE, rsctrl::core::FILES, - rsctrl::files::MsgId_ResponseControlDownload, true); - - // queue it. - queueResponse(chan_id, out_msg_id, req_id, outmsg); - - return 1; -} - - -int RpcProtoFiles::processReqShareDirList(uint32_t chan_id, uint32_t /* msg_id */, uint32_t req_id, const std::string &msg) -{ - std::cerr << "RpcProtoFiles::processReqShareDirList()"; - std::cerr << std::endl; - - // parse msg. - rsctrl::files::RequestShareDirList req; - if (!req.ParseFromString(msg)) - { - std::cerr << "RpcProtoFiles::processReqShareDirList() ERROR ParseFromString()"; - std::cerr << std::endl; - return 0; - } - - // response. - rsctrl::files::ResponseShareDirList resp; - bool success = true; - std::string errorMsg; - - - std::string uid = req.ssl_id(); - std::string path = req.path(); - DirDetails details; - - if (uid.empty()) - { - uid = rsPeers->getOwnId(); - } - - std::cerr << "RpcProtoFiles::processReqShareDirList() For uid: " << uid << " & path: " << path; - std::cerr << std::endl; - - if (path.empty()) - { - /* we have to do a nasty hack to get anything useful. - * we do a ref=NULL to get the pointers to People, - * then use the correct one to get root directories - */ - std::cerr << "RpcProtoFiles::processReqShareDirList() Hack to get root Dirs!"; - std::cerr << std::endl; - - FileSearchFlags flags; - if (uid == rsPeers->getOwnId()) - { - flags |= RS_FILE_HINTS_LOCAL; - } - - DirDetails root_details; - if (!rsFiles->RequestDirDetails(NULL, root_details, flags)) - { - std::cerr << "RpcProtoFiles::processReqShareDirList() ref=NULL Hack failed"; - std::cerr << std::endl; - success = false; - errorMsg = "Root Directory Request Failed."; - } - else - { - void *person_ref = NULL; - std::list::iterator sit; - for(sit = root_details.children.begin(); sit != root_details.children.end(); sit++) - { - //std::cerr << "RpcProtoFiles::processReqShareDirList() Root.child->name : " << sit->name; - if (sit->name == uid) - { - person_ref = sit->ref; - break; - } - } - - if (!person_ref) - { - std::cerr << "RpcProtoFiles::processReqShareDirList() Person match failed"; - std::cerr << std::endl; - success = false; - errorMsg = "Missing Person Root Directory."; - } - else - { - // Doing the REAL request! - if (!rsFiles->RequestDirDetails(person_ref, details, flags)) - { - std::cerr << "RpcProtoFiles::processReqShareDirList() Personal Shared Dir Hack failed"; - std::cerr << std::endl; - success = false; - errorMsg = "Missing Person Shared Directories"; - } - } - } - - } - else - { - // Path must begin with / for proper matching. - if (path[0] != '/') - { - path = '/' + path; - } - - if (!rsFiles->RequestDirDetails(uid, path, details)) - { - std::cerr << "RpcProtoFiles::processReqShareDirList() ERROR Unknown Dir"; - std::cerr << std::endl; - success = false; - errorMsg = "Directory Request Failed."; - } - } - - - - - - if (success) - { - // setup basics of response. - resp.set_ssl_id(uid); - resp.set_path(path); - - switch(details.type) - { - case DIR_TYPE_ROOT: - { - std::cerr << "RpcProtoFiles::processReqShareDirList() Details.type == ROOT ??"; - std::cerr << std::endl; - resp.set_list_type(rsctrl::files::ResponseShareDirList::DIRQUERY_ROOT); - rsctrl::core::File *file = resp.add_files(); - fill_file_as_dir(file, details.name); - - } - break; - - case DIR_TYPE_FILE: - { - std::cerr << "RpcProtoFiles::processReqShareDirList() Details.type == FILE"; - std::cerr << std::endl; - resp.set_list_type(rsctrl::files::ResponseShareDirList::DIRQUERY_FILE); - rsctrl::core::File *file = resp.add_files(); - fill_file_from_details(file, details); - } - break; - - default: - std::cerr << "RpcProtoFiles::processReqShareDirList() Details.type == UNKNOWN => default to DIR"; - std::cerr << std::endl; - - case DIR_TYPE_PERSON: - case DIR_TYPE_DIR: - { - std::cerr << "RpcProtoFiles::processReqShareDirList() Details.type == DIR or PERSON"; - std::cerr << std::endl; - - resp.set_list_type(rsctrl::files::ResponseShareDirList::DIRQUERY_DIR); - - //std::string dir_path = RsDirUtil::makePath(details.path, details.name); - std::string dir_path = details.path; - - std::cerr << "RpcProtoFiles::processReqShareDirList() details.path: " << details.path; - std::cerr << " details.name: " << details.name; - std::cerr << std::endl; - - std::list::iterator sit; - for(sit = details.children.begin(); sit != details.children.end(); sit++) - { - std::cerr << "RpcProtoFiles::processReqShareDirList() checking child: " << sit->name; - std::cerr << std::endl; - if (sit->type == DIR_TYPE_FILE) - { - std::cerr << "RpcProtoFiles::processReqShareDirList() is FILE, fetching details."; - std::cerr << std::endl; - - DirDetails child_details; - std::string child_path = RsDirUtil::makePath(dir_path, sit->name); - if (rsFiles->RequestDirDetails(uid, child_path, child_details)) - { - rsctrl::core::File *file = resp.add_files(); - fill_file_from_details(file, child_details); - } - else - { - std::cerr << "RpcProtoFiles::processReqShareDirList() RequestDirDetails(" << child_path << ") Failed!!!"; - std::cerr << std::endl; - } - } - else - { - std::cerr << "RpcProtoFiles::processReqShareDirList() is DIR"; - std::cerr << std::endl; - - rsctrl::core::File *file = resp.add_files(); - fill_file_as_dir(file, sit->name); - } - } - } - break; - } - } - - /* DONE - Generate Reply */ - if (success) - { - rsctrl::core::Status *status = resp.mutable_status(); - status->set_code(rsctrl::core::Status::SUCCESS); - } - else - { - rsctrl::core::Status *status = resp.mutable_status(); - status->set_code(rsctrl::core::Status::FAILED); - status->set_msg(errorMsg); - } - - std::string outmsg; - if (!resp.SerializeToString(&outmsg)) - { - std::cerr << "RpcProtoFiles::processReqTransferList() ERROR SerialiseToString()"; - std::cerr << std::endl; - return 0; - } - - // Correctly Name Message. - uint32_t out_msg_id = constructMsgId(rsctrl::core::CORE, rsctrl::core::FILES, - rsctrl::files::MsgId_ResponseShareDirList, true); - - // queue it. - queueResponse(chan_id, out_msg_id, req_id, outmsg); - - return 1; -} - - -/***** HELPER FUNCTIONS *****/ - - -bool fill_file_from_details(rsctrl::core::File *file, DirDetails &details) -{ - file->set_hash(details.hash); - file->set_name(details.name); - file->set_size(details.count); - - return true; -} - - -bool fill_file_as_dir(rsctrl::core::File *file, const std::string &dir_name) -{ - file->set_hash(""); - file->set_name(dir_name); - file->set_size(0); - - return true; -} - diff --git a/retroshare-nogui/src/rpc/proto/rpcprotofiles.h b/retroshare-nogui/src/rpc/proto/rpcprotofiles.h deleted file mode 100644 index 7f0af0c9e..000000000 --- a/retroshare-nogui/src/rpc/proto/rpcprotofiles.h +++ /dev/null @@ -1,45 +0,0 @@ -/* - * RetroShare External Interface. - * - * Copyright 2012-2012 by Robert Fernie. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public - * License Version 2.1 as published by the Free Software Foundation. - * - * This library 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 - * Library General Public License for more details. - * - * You should have received a copy of the GNU Library General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 - * USA. - * - * Please report all bugs and problems to "retroshare@lunamutt.com". - * - */ - - -#ifndef RS_RPC_PROTO_FILES_H -#define RS_RPC_PROTO_FILES_H - -#include "rpc/rpcserver.h" - -class RpcProtoFiles: public RpcQueueService -{ -public: - RpcProtoFiles(uint32_t serviceId); - - virtual int processMsg(uint32_t chan_id, uint32_t msgId, uint32_t req_id, const std::string &msg); - -protected: - - int processReqTransferList(uint32_t chan_id, uint32_t msg_id, uint32_t req_id, const std::string &msg); - int processReqControlDownload(uint32_t chan_id, uint32_t msg_id, uint32_t req_id, const std::string &msg); - int processReqShareDirList(uint32_t chan_id, uint32_t /* msg_id */, uint32_t req_id, const std::string &msg); - -}; - -#endif /* RS_PROTO_FILES_H */ diff --git a/retroshare-nogui/src/rpc/proto/rpcprotopeers.cc b/retroshare-nogui/src/rpc/proto/rpcprotopeers.cc deleted file mode 100644 index cfe9c9076..000000000 --- a/retroshare-nogui/src/rpc/proto/rpcprotopeers.cc +++ /dev/null @@ -1,610 +0,0 @@ -/* - * RetroShare External Interface. - * - * Copyright 2012-2012 by Robert Fernie. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public - * License Version 2.1 as published by the Free Software Foundation. - * - * This library 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 - * Library General Public License for more details. - * - * You should have received a copy of the GNU Library General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 - * USA. - * - * Please report all bugs and problems to "retroshare@lunamutt.com". - * - */ - -#include "rpc/proto/rpcprotopeers.h" -#include "rpc/proto/gencc/peers.pb.h" - -#include -#include - -#include -#include - -bool load_person_details(std::string pgp_id, rsctrl::core::Person *person, - bool getLocations, bool onlyConnected); - -RpcProtoPeers::RpcProtoPeers(uint32_t serviceId) - :RpcQueueService(serviceId) -{ - return; -} - -//RpcProtoPeers::msgsAccepted(std::list &msgIds); /* not used at the moment */ - -int RpcProtoPeers::processMsg(uint32_t chan_id, uint32_t msg_id, uint32_t req_id, const std::string &msg) -{ - /* check the msgId */ - uint8_t topbyte = getRpcMsgIdExtension(msg_id); - uint16_t service = getRpcMsgIdService(msg_id); - uint8_t submsg = getRpcMsgIdSubMsg(msg_id); - bool isResponse = isRpcMsgIdResponse(msg_id); - - - std::cerr << "RpcProtoPeers::processMsg() topbyte: " << (int32_t) topbyte; - std::cerr << " service: " << (int32_t) service << " submsg: " << (int32_t) submsg; - std::cerr << std::endl; - - if (isResponse) - { - std::cerr << "RpcProtoPeers::processMsg() isResponse() - not processing"; - std::cerr << std::endl; - return 0; - } - - - if (topbyte != (uint8_t) rsctrl::core::CORE) - { - std::cerr << "RpcProtoPeers::processMsg() Extension Mismatch - not processing"; - std::cerr << std::endl; - return 0; - } - - if (service != (uint16_t) rsctrl::core::PEERS) - { - std::cerr << "RpcProtoPeers::processMsg() Service Mismatch - not processing"; - std::cerr << std::endl; - return 0; - } - - if (!rsctrl::peers::RequestMsgIds_IsValid(submsg)) - { - std::cerr << "RpcProtoPeers::processMsg() SubMsg Mismatch - not processing"; - std::cerr << std::endl; - return 0; - } - - switch(submsg) - { - case rsctrl::peers::MsgId_RequestPeers: - processRequestPeers(chan_id, msg_id, req_id, msg); - break; - case rsctrl::peers::MsgId_RequestAddPeer: - processAddPeer(chan_id, msg_id, req_id, msg); - break; - case rsctrl::peers::MsgId_RequestExaminePeer: - processExaminePeer(chan_id, msg_id, req_id, msg); - break; - //case rsctrl::peers::MsgId_RequestModifyPeer: - // processModifyPeer(chan_id, msg_id, req_id, msg); - // break; - default: - std::cerr << "RpcProtoPeers::processMsg() ERROR should never get here"; - std::cerr << std::endl; - return 0; - } - - /* must have matched id to get here */ - return 1; -} - - -int RpcProtoPeers::processAddPeer(uint32_t chan_id, uint32_t /* msg_id */, uint32_t req_id, const std::string &msg) -{ - std::cerr << "RpcProtoPeers::processAddPeer()"; - std::cerr << std::endl; - - - // parse msg. - rsctrl::peers::RequestAddPeer req; - if (!req.ParseFromString(msg)) - { - std::cerr << "RpcProtoPeers::processAddPeer() ERROR ParseFromString()"; - std::cerr << std::endl; - return 0; - } - - // response. - rsctrl::peers::ResponsePeerList resp; - bool success = true; - std::string errorMsg; - - /* check if the gpg_id is valid */ - std::string pgp_id = req.pgp_id(); - std::string ssl_id; - if (req.has_ssl_id()) - { - ssl_id = req.ssl_id(); - } - - RsPeerDetails details; - if (!rsPeers->getGPGDetails(pgp_id, details)) - { - success = false; - errorMsg = "Invalid PGP ID"; - } - else - { - switch(req.cmd()) - { - default: - success = false; - errorMsg = "Invalid AddCmd"; - break; - case rsctrl::peers::RequestAddPeer::ADD: - - // TODO. NEED TO HANDLE SERVICE PERMISSION FLAGS. - success = rsPeers->addFriend(ssl_id,pgp_id, RS_NODE_PERM_DEFAULT); - - break; - case rsctrl::peers::RequestAddPeer::REMOVE: - - success = rsPeers->removeFriend(pgp_id); - break; - } - - if (success) - { - rsctrl::core::Person *person = resp.add_peers(); - load_person_details(pgp_id, person, true, false); - } - } - - if (success) - { - rsctrl::core::Status *status = resp.mutable_status(); - status->set_code(rsctrl::core::Status::SUCCESS); - } - else - { - rsctrl::core::Status *status = resp.mutable_status(); - status->set_code(rsctrl::core::Status::NO_IMPL_YET); - } - - - std::string outmsg; - if (!resp.SerializeToString(&outmsg)) - { - std::cerr << "RpcProtoPeers::processAddPeer() ERROR SerialiseToString()"; - std::cerr << std::endl; - return 0; - } - - // Correctly Name Message. - uint32_t out_msg_id = constructMsgId(rsctrl::core::CORE, rsctrl::core::PEERS, - rsctrl::peers::MsgId_ResponsePeerList, true); - - // queue it. - queueResponse(chan_id, out_msg_id, req_id, outmsg); - - return 1; -} - - -int RpcProtoPeers::processExaminePeer(uint32_t chan_id, uint32_t /* msg_id */, uint32_t req_id, const std::string &msg) -{ - std::cerr << "RpcProtoPeers::processExaminePeer() NOT FINISHED"; - std::cerr << std::endl; - - - // parse msg. - rsctrl::peers::RequestExaminePeer req; - if (!req.ParseFromString(msg)) - { - std::cerr << "RpcProtoPeers::processExaminePeer() ERROR ParseFromString()"; - std::cerr << std::endl; - return 0; - } - - // response. - rsctrl::peers::ResponsePeerList resp; - bool success = false; - - if (success) - { - switch(req.cmd()) - { - default: - success = false; - break; - case rsctrl::peers::RequestExaminePeer::IMPORT: - break; - case rsctrl::peers::RequestExaminePeer::EXAMINE: - - // Gets the GPG details, but does not add the key to the keyring. - //virtual bool loadDetailsFromStringCert(const std::string& certGPG, RsPeerDetails &pd,uint32_t& error_code) = 0; - - break; - } - } - - if (success) - { - rsctrl::core::Status *status = resp.mutable_status(); - status->set_code(rsctrl::core::Status::SUCCESS); - } - else - { - rsctrl::core::Status *status = resp.mutable_status(); - status->set_code(rsctrl::core::Status::NO_IMPL_YET); - } - - - std::string outmsg; - if (!resp.SerializeToString(&outmsg)) - { - std::cerr << "RpcProtoPeers::processAddPeer() ERROR SerialiseToString()"; - std::cerr << std::endl; - return 0; - } - - // Correctly Name Message. - uint32_t out_msg_id = constructMsgId(rsctrl::core::CORE, rsctrl::core::PEERS, - rsctrl::peers::MsgId_ResponsePeerList, true); - - // queue it. - queueResponse(chan_id, out_msg_id, req_id, outmsg); - - return 1; -} - - -int RpcProtoPeers::processModifyPeer(uint32_t chan_id, uint32_t /* msg_id */, uint32_t req_id, const std::string &msg) -{ - std::cerr << "RpcProtoPeers::processModifyPeer() NOT FINISHED"; - std::cerr << std::endl; - - - // parse msg. - rsctrl::peers::RequestModifyPeer req; - if (!req.ParseFromString(msg)) - { - std::cerr << "RpcProtoPeers::processModifyPeer() ERROR ParseFromString()"; - std::cerr << std::endl; - return 0; - } - - - // response. - rsctrl::peers::ResponsePeerList resp; - bool success = false; - - if (success) - { - rsctrl::core::Status *status = resp.mutable_status(); - status->set_code(rsctrl::core::Status::SUCCESS); - } - else - { - rsctrl::core::Status *status = resp.mutable_status(); - status->set_code(rsctrl::core::Status::NO_IMPL_YET); - } - - - std::string outmsg; - if (!resp.SerializeToString(&outmsg)) - { - std::cerr << "RpcProtoPeers::processModifyPeer() ERROR SerialiseToString()"; - std::cerr << std::endl; - return 0; - } - - // Correctly Name Message. - uint32_t out_msg_id = constructMsgId(rsctrl::core::CORE, rsctrl::core::PEERS, - rsctrl::peers::MsgId_ResponsePeerList, true); - - // queue it. - queueResponse(chan_id, out_msg_id, req_id, outmsg); - - return 1; -} - - - -int RpcProtoPeers::processRequestPeers(uint32_t chan_id, uint32_t /* msg_id */, uint32_t req_id, const std::string &msg) -{ - std::cerr << "RpcProtoPeers::processRequestPeers()"; - std::cerr << std::endl; - - // parse msg. - rsctrl::peers::RequestPeers reqp; - if (!reqp.ParseFromString(msg)) - { - std::cerr << "RpcProtoPeers::processRequestPeers() ERROR ParseFromString()"; - std::cerr << std::endl; - return 0; - } - - // response. - rsctrl::peers::ResponsePeerList respp; - bool success = true; - std::string errorMsg; - - // Get the list of gpg_id to generate data for. - std::list ids; - bool onlyConnected = false; - switch(reqp.set()) - { - case rsctrl::peers::RequestPeers::OWNID: - { - std::cerr << "RpcProtoPeers::processRequestPeers() OWNID"; - std::cerr << std::endl; - std::string own_id = rsPeers->getGPGOwnId(); - ids.push_back(own_id); - break; - } - case rsctrl::peers::RequestPeers::LISTED: - { - std::cerr << "RpcProtoPeers::processRequestPeers() LISTED"; - std::cerr << std::endl; - int no_pgp_ids = reqp.pgp_ids_size(); - for (int i = 0; i < no_pgp_ids; i++) - { - std::string listed_id = reqp.pgp_ids(i); - std::cerr << "RpcProtoPeers::processRequestPeers() Adding Id: " << listed_id; - std::cerr << std::endl; - ids.push_back(listed_id); - } - break; - - } - case rsctrl::peers::RequestPeers::ALL: - std::cerr << "RpcProtoPeers::processRequestPeers() ALL"; - std::cerr << std::endl; - rsPeers->getGPGAllList(ids); - break; - case rsctrl::peers::RequestPeers::CONNECTED: - { - std::cerr << "RpcProtoPeers::processRequestPeers() CONNECTED"; - std::cerr << std::endl; - /* this ones a bit hard too */ - onlyConnected = true; - std::list ssl_ids; - std::list::const_iterator sit; - rsPeers->getOnlineList(ssl_ids); - for(sit = ssl_ids.begin(); sit != ssl_ids.end(); sit++) - { - std::string gpg_id = rsPeers->getGPGId(*sit); - if (gpg_id.size() > 0) - { - if (std::find(ids.begin(), ids.end(),gpg_id) == ids.end()) - { - ids.push_back(gpg_id); - } - } - } - break; - } - case rsctrl::peers::RequestPeers::FRIENDS: - std::cerr << "RpcProtoPeers::processRequestPeers() FRIENDS"; - std::cerr << std::endl; - rsPeers->getGPGAcceptedList(ids); - break; - case rsctrl::peers::RequestPeers::SIGNED: - std::cerr << "RpcProtoPeers::processRequestPeers() SIGNED"; - std::cerr << std::endl; - rsPeers->getGPGSignedList(ids); - break; - case rsctrl::peers::RequestPeers::VALID: - std::cerr << "RpcProtoPeers::processRequestPeers() VALID"; - std::cerr << std::endl; - rsPeers->getGPGSignedList(ids); - break; - } - - - // work out what data we need to request. - bool getLocations = false; - switch(reqp.info()) - { - default: - case rsctrl::peers::RequestPeers::NAMEONLY: - case rsctrl::peers::RequestPeers::BASIC: - break; - case rsctrl::peers::RequestPeers::LOCATION: - case rsctrl::peers::RequestPeers::ALLINFO: - getLocations = true; - break; - } - - - /* now iterate through the peers and fill in the response. */ - std::list::const_iterator git; - for(git = ids.begin(); git != ids.end(); git++) - { - rsctrl::core::Person *person = respp.add_peers(); - if (!load_person_details(*git, person, getLocations, onlyConnected)) - { - std::cerr << "RpcProtoPeers::processRequestPeers() ERROR Finding GPGID: "; - std::cerr << *git; - std::cerr << std::endl; - - /* cleanup peers */ - success = false; - errorMsg = "Error Loading PeerID"; - } - } - - if (success) - { - rsctrl::core::Status *status = respp.mutable_status(); - status->set_code(rsctrl::core::Status::SUCCESS); - } - else - { - rsctrl::core::Status *status = respp.mutable_status(); - status->set_code(rsctrl::core::Status::FAILED); - status->set_msg(errorMsg); - } - - - std::string outmsg; - if (!respp.SerializeToString(&outmsg)) - { - std::cerr << "RpcProtoPeers::processRequestPeers() ERROR SerialiseToString()"; - std::cerr << std::endl; - return 0; - } - - // Correctly Name Message. - uint32_t out_msg_id = constructMsgId(rsctrl::core::CORE, rsctrl::core::PEERS, - rsctrl::peers::MsgId_ResponsePeerList, true); - - // queue it. - queueResponse(chan_id, out_msg_id, req_id, outmsg); - - return 1; -} - - - - - -bool load_person_details(std::string pgp_id, rsctrl::core::Person *person, - bool getLocations, bool onlyConnected) -{ - RsPeerDetails details; - if (!rsPeers->getGPGDetails(pgp_id, details)) - { - std::cerr << "RpcProtoPeers::processRequestPeers() ERROR Finding GPGID: "; - std::cerr << pgp_id; - std::cerr << std::endl; - return false; - } - - /* fill in key gpg details */ - person->set_gpg_id(pgp_id); - person->set_name(details.name); - - std::cerr << "RpcProtoPeers::processRequestPeers() Adding GPGID: "; - std::cerr << pgp_id << " name: " << details.name; - std::cerr << std::endl; - - //if (details.state & RS_PEER_STATE_FRIEND) - if (pgp_id == rsPeers->getGPGOwnId()) - { - std::cerr << "RpcProtoPeers::processRequestPeers() Relation YOURSELF"; - std::cerr << std::endl; - person->set_relation(rsctrl::core::Person::YOURSELF); - } - else if (rsPeers->isGPGAccepted(pgp_id)) - { - std::cerr << "RpcProtoPeers::processRequestPeers() Relation FRIEND"; - std::cerr << std::endl; - person->set_relation(rsctrl::core::Person::FRIEND); - } - else - { - std::list common_friends; - rsDisc->getDiscPgpFriends(pgp_id, common_friends); - int size = common_friends.size(); - if (size) - { - if (size > 2) - { - std::cerr << "RpcProtoPeers::processRequestPeers() Relation FRIEND_OF_MANY_FRIENDS"; - std::cerr << std::endl; - person->set_relation(rsctrl::core::Person::FRIEND_OF_MANY_FRIENDS); - } - else - { - std::cerr << "RpcProtoPeers::processRequestPeers() Relation FRIEND_OF_FRIENDS"; - std::cerr << std::endl; - person->set_relation(rsctrl::core::Person::FRIEND_OF_FRIENDS); - } - } - else - { - std::cerr << "RpcProtoPeers::processRequestPeers() Relation UNKNOWN"; - std::cerr << std::endl; - person->set_relation(rsctrl::core::Person::UNKNOWN); - } - } - - if (getLocations) - { - std::list ssl_ids; - std::list::const_iterator sit; - - if (!rsPeers->getAssociatedSSLIds(pgp_id, ssl_ids)) - { - std::cerr << "RpcProtoPeers::processRequestPeers() No Locations"; - std::cerr << std::endl; - return true; /* end of this peer */ - } - - for(sit = ssl_ids.begin(); sit != ssl_ids.end(); sit++) - { - RsPeerDetails ssldetails; - if (!rsPeers->getPeerDetails(*sit, ssldetails)) - { - continue; /* uhm.. */ - } - if ((onlyConnected) && - (!(ssldetails.state & RS_PEER_STATE_CONNECTED))) - { - continue; - } - - rsctrl::core::Location *loc = person->add_locations(); - - std::cerr << "RpcProtoPeers::processRequestPeers() \t Adding Location: "; - std::cerr << *sit << " loc: " << ssldetails.location; - std::cerr << std::endl; - - /* fill in ssl details */ - loc->set_ssl_id(*sit); - loc->set_location(ssldetails.location); - - /* set addresses */ - rsctrl::core::IpAddr *laddr = loc->mutable_localaddr(); - laddr->set_addr(ssldetails.localAddr); - laddr->set_port(ssldetails.localPort); - - rsctrl::core::IpAddr *eaddr = loc->mutable_extaddr(); - eaddr->set_addr(ssldetails.extAddr); - eaddr->set_port(ssldetails.extPort); - - /* translate status */ - uint32_t loc_state = 0; - //dont think this state should be here. - //if (ssldetails.state & RS_PEER_STATE_FRIEND) - if (ssldetails.state & RS_PEER_STATE_ONLINE) - { - loc_state |= (uint32_t) rsctrl::core::Location::ONLINE; - } - if (ssldetails.state & RS_PEER_STATE_CONNECTED) - { - loc_state |= (uint32_t) rsctrl::core::Location::CONNECTED; - } - if (ssldetails.state & RS_PEER_STATE_UNREACHABLE) - { - loc_state |= (uint32_t) rsctrl::core::Location::UNREACHABLE; - } - - loc->set_state(loc_state); - } - } - return true; /* end of this peer */ -} - - diff --git a/retroshare-nogui/src/rpc/proto/rpcprotopeers.h b/retroshare-nogui/src/rpc/proto/rpcprotopeers.h deleted file mode 100644 index 7e15e0b07..000000000 --- a/retroshare-nogui/src/rpc/proto/rpcprotopeers.h +++ /dev/null @@ -1,46 +0,0 @@ -/* - * RetroShare External Interface. - * - * Copyright 2012-2012 by Robert Fernie. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public - * License Version 2.1 as published by the Free Software Foundation. - * - * This library 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 - * Library General Public License for more details. - * - * You should have received a copy of the GNU Library General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 - * USA. - * - * Please report all bugs and problems to "retroshare@lunamutt.com". - * - */ - - -#ifndef RS_RPC_PROTO_PEERS_H -#define RS_RPC_PROTO_PEERS_H - -#include "rpc/rpcserver.h" - -class RpcProtoPeers: public RpcQueueService -{ -public: - RpcProtoPeers(uint32_t serviceId); -// virtual msgsAccepted(std::list &msgIds); /* not used at the moment */ - virtual int processMsg(uint32_t chan_id, uint32_t msg_id, uint32_t req_id, const std::string &msg); - - virtual int processRequestPeers(uint32_t chan_id, uint32_t msg_id, uint32_t req_id, const std::string &msg); - virtual int processAddPeer(uint32_t chan_id, uint32_t msg_id, uint32_t req_id, const std::string &msg); - - // these aren't implemented yet. - virtual int processExaminePeer(uint32_t chan_id, uint32_t msg_id, uint32_t req_id, const std::string &msg); - virtual int processModifyPeer(uint32_t chan_id, uint32_t msg_id, uint32_t req_id, const std::string &msg); -}; - - -#endif /* RS_PROTO_PEERS_H */ diff --git a/retroshare-nogui/src/rpc/proto/rpcprotosearch.cc b/retroshare-nogui/src/rpc/proto/rpcprotosearch.cc deleted file mode 100644 index 77276ae12..000000000 --- a/retroshare-nogui/src/rpc/proto/rpcprotosearch.cc +++ /dev/null @@ -1,678 +0,0 @@ -/* - * RetroShare External Interface. - * - * Copyright 2012-2012 by Robert Fernie. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public - * License Version 2.1 as published by the Free Software Foundation. - * - * This library 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 - * Library General Public License for more details. - * - * You should have received a copy of the GNU Library General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 - * USA. - * - * Please report all bugs and problems to "retroshare@lunamutt.com". - * - */ - -#include "rpc/proto/rpcprotosearch.h" -#include "rpc/proto/gencc/search.pb.h" - -#include "notifytxt.h" - -#include -#include - -#include "util/rsstring.h" - -#include - -#include -#include - -#include - -bool condenseSearchResults(const std::list &searchResults, uint32_t limit, - rsctrl::search::SearchSet *result_set); - - -RpcProtoSearch::RpcProtoSearch(uint32_t serviceId, NotifyTxt *notify) - :RpcQueueService(serviceId), mNotify(notify), searchMtx("RpcProtoSearch") -{ - return; -} - -void RpcProtoSearch::reset(uint32_t chan_id) -{ - RpcQueueService::reset(chan_id); - - /* must clear all searches */ - clear_searches(chan_id); -} - - -int RpcProtoSearch::processMsg(uint32_t chan_id, uint32_t msg_id, uint32_t req_id, const std::string &msg) -{ - /* check the msgId */ - uint8_t topbyte = getRpcMsgIdExtension(msg_id); - uint16_t service = getRpcMsgIdService(msg_id); - uint8_t submsg = getRpcMsgIdSubMsg(msg_id); - bool isResponse = isRpcMsgIdResponse(msg_id); - - - std::cerr << "RpcProtoSearch::processMsg() topbyte: " << (int32_t) topbyte; - std::cerr << " service: " << (int32_t) service << " submsg: " << (int32_t) submsg; - std::cerr << std::endl; - - if (isResponse) - { - std::cerr << "RpcProtoSearch::processMsg() isResponse() - not processing"; - std::cerr << std::endl; - return 0; - } - - if (topbyte != (uint8_t) rsctrl::core::CORE) - { - std::cerr << "RpcProtoSearch::processMsg() Extension Mismatch - not processing"; - std::cerr << std::endl; - return 0; - } - - if (service != (uint16_t) rsctrl::core::SEARCH) - { - std::cerr << "RpcProtoSearch::processMsg() Service Mismatch - not processing"; - std::cerr << std::endl; - return 0; - } - - if (!rsctrl::search::RequestMsgIds_IsValid(submsg)) - { - std::cerr << "RpcProtoSearch::processMsg() SubMsg Mismatch - not processing"; - std::cerr << std::endl; - return 0; - } - - switch(submsg) - { - case rsctrl::search::MsgId_RequestBasicSearch: - processReqBasicSearch(chan_id, msg_id, req_id, msg); - break; - - case rsctrl::search::MsgId_RequestCloseSearch: - processReqCloseSearch(chan_id, msg_id, req_id, msg); - break; - - case rsctrl::search::MsgId_RequestListSearches: - processReqListSearches(chan_id, msg_id, req_id, msg); - break; - - case rsctrl::search::MsgId_RequestSearchResults: - processReqSearchResults(chan_id, msg_id, req_id, msg); - break; - - default: - std::cerr << "RpcProtoSearch::processMsg() ERROR should never get here"; - std::cerr << std::endl; - return 0; - } - - /* must have matched id to get here */ - return 1; -} - - - -int RpcProtoSearch::processReqBasicSearch(uint32_t chan_id, uint32_t /* msg_id */, uint32_t req_id, const std::string &msg) -{ - std::cerr << "RpcProtoSearch::processReqBasicSearch()"; - std::cerr << std::endl; - - // parse msg. - rsctrl::search::RequestBasicSearch req; - if (!req.ParseFromString(msg)) - { - std::cerr << "RpcProtoSearch::processReqBasicSearch() ERROR ParseFromString()"; - std::cerr << std::endl; - return 0; - } - - // response. - rsctrl::search::ResponseSearchIds resp; - bool success = true; - std::string errorMsg; - - /* convert msg parameters into local ones */ - std::list terms; - - int no_terms = req.terms_size(); - for(int i = 0; i < no_terms; i++) - { - std::string term = req.terms(i); - /* check for valid term? */ - if (term.size() > 0) - { - terms.push_back(term); - } - } - - NameExpression nameexp(ContainsAllStrings, terms, true); - LinearizedExpression lexpr; - nameexp.linearize(lexpr); - - uint32_t searchId = (uint32_t) rsTurtle->turtleSearch(lexpr); - mNotify->collectSearchResults(searchId); - - /* add into search array */ - add_search(chan_id, searchId); - - /* add to answer */ - resp.add_search_id(searchId); - - /* DONE - Generate Reply */ - if (success) - { - rsctrl::core::Status *status = resp.mutable_status(); - status->set_code(rsctrl::core::Status::SUCCESS); - } - else - { - rsctrl::core::Status *status = resp.mutable_status(); - status->set_code(rsctrl::core::Status::FAILED); - status->set_msg(errorMsg); - } - - std::string outmsg; - if (!resp.SerializeToString(&outmsg)) - { - std::cerr << "RpcProtoSearch::processReqBasicSearch() ERROR SerialiseToString()"; - std::cerr << std::endl; - return 0; - } - - // Correctly Name Message. - uint32_t out_msg_id = constructMsgId(rsctrl::core::CORE, rsctrl::core::SEARCH, - rsctrl::search::MsgId_ResponseSearchIds, true); - - // queue it. - queueResponse(chan_id, out_msg_id, req_id, outmsg); - - return 1; -} - - -int RpcProtoSearch::processReqCloseSearch(uint32_t chan_id, uint32_t /* msg_id */, uint32_t req_id, const std::string &msg) -{ - std::cerr << "RpcProtoSearch::processReqCloseSearch()"; - std::cerr << std::endl; - - // parse msg. - rsctrl::search::RequestCloseSearch req; - if (!req.ParseFromString(msg)) - { - std::cerr << "RpcProtoSearch::processReqCloseSearch() ERROR ParseFromString()"; - std::cerr << std::endl; - return 0; - } - - // response. - rsctrl::search::ResponseSearchIds resp; - bool success = true; - std::string errorMsg; - - /* convert msg parameters into local ones */ - uint32_t searchId = req.search_id(); - - - /* remove into search array */ - if (!remove_search(chan_id, searchId)) - { - success = false; - errorMsg = "Unknown SearchId in List"; - } - - /* clear search results - * we cannot cancel a turtle search - * so we tell notify to ignore further results - */ - - if (success) - { - if (!mNotify->clearSearchId(searchId)) - { - success = false; - errorMsg = "Unknown SearchId in Notify"; - } - } - - /* add to answer */ - if (success) - { - resp.add_search_id(searchId); - } - - /* DONE - Generate Reply */ - if (success) - { - rsctrl::core::Status *status = resp.mutable_status(); - status->set_code(rsctrl::core::Status::SUCCESS); - } - else - { - rsctrl::core::Status *status = resp.mutable_status(); - status->set_code(rsctrl::core::Status::FAILED); - status->set_msg(errorMsg); - } - - std::string outmsg; - if (!resp.SerializeToString(&outmsg)) - { - std::cerr << "RpcProtoSearch::processReqCloseSearch() ERROR SerialiseToString()"; - std::cerr << std::endl; - return 0; - } - - // Correctly Name Message. - uint32_t out_msg_id = constructMsgId(rsctrl::core::CORE, rsctrl::core::SEARCH, - rsctrl::search::MsgId_ResponseSearchIds, true); - - // queue it. - queueResponse(chan_id, out_msg_id, req_id, outmsg); - - return 1; -} - - -int RpcProtoSearch::processReqListSearches(uint32_t chan_id, uint32_t /* msg_id */, uint32_t req_id, const std::string &msg) -{ - std::cerr << "RpcProtoSearch::processReqListSearches()"; - std::cerr << std::endl; - - // parse msg. - rsctrl::search::RequestListSearches req; - if (!req.ParseFromString(msg)) - { - std::cerr << "RpcProtoSearch::processReqListSearches() ERROR ParseFromString()"; - std::cerr << std::endl; - return 0; - } - - // response. - rsctrl::search::ResponseSearchIds resp; - bool success = true; - std::string errorMsg; - - /* convert msg parameters into local ones */ - // Nothing to do. - - std::list reg_search_ids; - std::list::iterator it; - if (!get_search_list(chan_id, reg_search_ids)) - { - /* warning */ - success = false; - errorMsg = "No Searches Active"; - } - - /* iterate through search array */ - for(it = reg_search_ids.begin(); it != reg_search_ids.end(); it++) - { - /* add to answer */ - resp.add_search_id(*it); - } - - /* DONE - Generate Reply */ - if (success) - { - rsctrl::core::Status *status = resp.mutable_status(); - status->set_code(rsctrl::core::Status::SUCCESS); - } - else - { - rsctrl::core::Status *status = resp.mutable_status(); - status->set_code(rsctrl::core::Status::FAILED); - status->set_msg(errorMsg); - } - - std::string outmsg; - if (!resp.SerializeToString(&outmsg)) - { - std::cerr << "RpcProtoSearch::processReqListSearches() ERROR SerialiseToString()"; - std::cerr << std::endl; - return 0; - } - - // Correctly Name Message. - uint32_t out_msg_id = constructMsgId(rsctrl::core::CORE, rsctrl::core::SEARCH, - rsctrl::search::MsgId_ResponseSearchIds, true); - - // queue it. - queueResponse(chan_id, out_msg_id, req_id, outmsg); - - return 1; -} - - -int RpcProtoSearch::processReqSearchResults(uint32_t chan_id, uint32_t /* msg_id */, uint32_t req_id, const std::string &msg) -{ - std::cerr << "RpcProtoSearch::processReqSearchResults()"; - std::cerr << std::endl; - - // parse msg. - rsctrl::search::RequestSearchResults req; - if (!req.ParseFromString(msg)) - { - std::cerr << "RpcProtoSearch::processReqSearchResults() ERROR ParseFromString()"; - std::cerr << std::endl; - return 0; - } - - // response. - rsctrl::search::ResponseSearchResults resp; - bool success = true; - std::string errorMsg; - - /* convert msg parameters into local ones */ - std::list reg_search_ids; - std::list requested_search_ids; - if (!get_search_list(chan_id, reg_search_ids)) - { - /* warning */ - } - - int no_searches = req.search_ids_size(); - if (no_searches) - { - /* painful check that they are our searches */ - for(int i = 0; i < no_searches; i++) - { - uint32_t search_id = req.search_ids(i); - - /* check that its in reg_search_ids */ - if (reg_search_ids.end() != std::find(reg_search_ids.begin(), reg_search_ids.end(), search_id)) - { - /* error */ - continue; - } - requested_search_ids.push_back(search_id); - } - } - else - { - /* all current searches */ - requested_search_ids = reg_search_ids; - } - - - std::list::iterator rit; - for(rit = requested_search_ids.begin(); - rit != requested_search_ids.end(); rit++) - { - rsctrl::search::SearchSet *set = resp.add_searches(); - /* add to answer */ - set->set_search_id(*rit); - /* no search details at the moment */ - - /* add into search array */ - std::list::iterator it; - std::list searchResults; - mNotify->getSearchResults(*rit, searchResults); - - condenseSearchResults(searchResults, req.result_limit(), set); - } - - /* DONE - Generate Reply */ - /* different to others - partial success possible */ - if (success) - { - rsctrl::core::Status *status = resp.mutable_status(); - status->set_code(rsctrl::core::Status::SUCCESS); - } - else - { - rsctrl::core::Status *status = resp.mutable_status(); - status->set_code(rsctrl::core::Status::FAILED); - status->set_msg(errorMsg); - } - - std::string outmsg; - if (!resp.SerializeToString(&outmsg)) - { - std::cerr << "RpcProtoSearch::processReqSearchResults() ERROR SerialiseToString()"; - std::cerr << std::endl; - return 0; - } - - // Correctly Name Message. - uint32_t out_msg_id = constructMsgId(rsctrl::core::CORE, rsctrl::core::SEARCH, - rsctrl::search::MsgId_ResponseSearchResults, true); - - // queue it. - queueResponse(chan_id, out_msg_id, req_id, outmsg); - - return 1; -} - - - -/***** HELPER FUNCTIONS *****/ - - // These private functions use Mutex below and manipulate mActiveSearches. -int RpcProtoSearch::get_search_list(uint32_t chan_id, std::list &search_ids) -{ - std::cerr << "RpcProtoSearch::get_search_list(" << chan_id << ")"; - std::cerr << std::endl; - - RsStackMutex stack(searchMtx); /******* LOCKED *********/ - - std::map >::iterator mit; - - mit = mActiveSearches.find(chan_id); - if (mit == mActiveSearches.end()) - { - return 0; - } - - search_ids = mit->second; - - return 1; -} - -int RpcProtoSearch::add_search(uint32_t chan_id, uint32_t search_id) -{ - std::cerr << "RpcProtoSearch::add_search(" << chan_id << ", " << search_id << ")"; - std::cerr << std::endl; - - RsStackMutex stack(searchMtx); /******* LOCKED *********/ - - std::map >::iterator mit; - - mit = mActiveSearches.find(chan_id); - if (mit == mActiveSearches.end()) - { - std::list emptyList; - mActiveSearches[chan_id] = emptyList; - - mit = mActiveSearches.find(chan_id); - } - - /* sanity check */ - if (mit->second.end() != std::find(mit->second.begin(), mit->second.end(), search_id)) - { - std::cerr << "RpcProtoSearch::add_search() ERROR search_id already exists"; - std::cerr << std::endl; - return 0; - } - - mit->second.push_back(search_id); - return 1; -} - -int RpcProtoSearch::remove_search(uint32_t chan_id, uint32_t search_id) -{ - std::cerr << "RpcProtoSearch::remove_search(" << chan_id << ", " << search_id << ")"; - std::cerr << std::endl; - - RsStackMutex stack(searchMtx); /******* LOCKED *********/ - - std::map >::iterator mit; - - mit = mActiveSearches.find(chan_id); - if (mit == mActiveSearches.end()) - { - std::cerr << "RpcProtoSearch::remove_search() ERROR search set doesn't exist"; - std::cerr << std::endl; - return 0; - } - - bool removed = false; - std::list::iterator lit; - for(lit = mit->second.begin(); lit != mit->second.end();) - { - if (*lit == search_id) - { - lit = mit->second.erase(lit); - if (removed) - { - std::cerr << "RpcProtoSearch::remove_search() ERROR removed multiple"; - std::cerr << std::endl; - } - removed = true; - } - else - { - lit++; - } - } - - if (removed) - return 1; - - std::cerr << "RpcProtoSearch::remove_search() ERROR search_id not found"; - std::cerr << std::endl; - - return 0; -} - -int RpcProtoSearch::clear_searches(uint32_t chan_id) -{ - std::cerr << "RpcProtoSearch::clear_searches(" << chan_id << ")"; - std::cerr << std::endl; - - RsStackMutex stack(searchMtx); /******* LOCKED *********/ - - std::map >::iterator mit; - - mit = mActiveSearches.find(chan_id); - if (mit == mActiveSearches.end()) - { - std::cerr << "RpcProtoSearch::clear_searches() WARNING search set not found"; - std::cerr << std::endl; - return 0; - } - - mActiveSearches.erase(mit); - return 1; -} - - - -class RpcSearchInfo -{ - public: - std::string hash; - std::string name; - uint64_t size; - std::map name_map; - uint32_t hits; -}; - - -bool condenseSearchResults(const std::list &searchResults, uint32_t limit, - rsctrl::search::SearchSet *result_set) -{ - std::map searchMap; - std::map::iterator mit; - - std::list::const_iterator it; - for(it = searchResults.begin(); it != searchResults.end(); it++) - { - mit = searchMap.find(it->hash); - if (mit != searchMap.end()) - { - mit->second.hits++; - - if (mit->second.name_map.find(it->name) == mit->second.name_map.end()) - { - mit->second.name_map[it->name] = 1; - } - else - { - mit->second.name_map[it->name]++; - } - - if (it->size != mit->second.size) - { - // ERROR. - } - } - else - { - RpcSearchInfo info; - info.hash = it->hash; - info.size = it->size; - info.name_map[it->name] = 1; - info.hits = 1; - - searchMap[it->hash] = info; - } - } - - unsigned int i = 0; - for(mit = searchMap.begin(); (mit != searchMap.end()) && (i < limit || limit == 0); mit++, i++) - { - std::map::reverse_iterator nit; - nit = mit->second.name_map.rbegin(); - - /* add to answer */ - rsctrl::search::SearchHit *hit = result_set->add_hits(); - rsctrl::core::File *file = hit->mutable_file(); - - file->set_hash(mit->second.hash); - file->set_name(nit->first); - file->set_size(mit->second.size); - - // Uhm not provided for now. default to NETWORK - hit->set_loc(rsctrl::search::SearchHit::NETWORK); - hit->set_no_hits(mit->second.hits); // No aggregation yet. - - // guarenteed to have one item here. - for(nit++; nit != mit->second.name_map.rend(); nit++) - { - hit->add_alt_names(nit->first); - } - } - - return true; -} - - - - - - - - - - - - - - - - diff --git a/retroshare-nogui/src/rpc/proto/rpcprotosearch.h b/retroshare-nogui/src/rpc/proto/rpcprotosearch.h deleted file mode 100644 index 3ad77ce75..000000000 --- a/retroshare-nogui/src/rpc/proto/rpcprotosearch.h +++ /dev/null @@ -1,64 +0,0 @@ -/* - * RetroShare External Interface. - * - * Copyright 2012-2012 by Robert Fernie. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public - * License Version 2.1 as published by the Free Software Foundation. - * - * This library 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 - * Library General Public License for more details. - * - * You should have received a copy of the GNU Library General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 - * USA. - * - * Please report all bugs and problems to "retroshare@lunamutt.com". - * - */ - - -#ifndef RS_RPC_PROTO_SEARCH_H -#define RS_RPC_PROTO_SEARCH_H - -#include "rpc/rpcserver.h" - -class NotifyTxt; - -class RpcProtoSearch: public RpcQueueService -{ -public: - RpcProtoSearch(uint32_t serviceId, NotifyTxt *notify); - virtual void reset(uint32_t chan_id); - - virtual int processMsg(uint32_t chan_id, uint32_t msgId, uint32_t req_id, const std::string &msg); - -protected: - - int processReqBasicSearch(uint32_t chan_id, uint32_t msg_id, uint32_t req_id, const std::string &msg); - int processReqCloseSearch(uint32_t chan_id, uint32_t msg_id, uint32_t req_id, const std::string &msg); - int processReqListSearches(uint32_t chan_id, uint32_t msg_id, uint32_t req_id, const std::string &msg); - int processReqSearchResults(uint32_t chan_id, uint32_t msg_id, uint32_t req_id, const std::string &msg); - - -private: - // These private functions use Mutex below and manipulate mActiveSearches. - int get_search_list(uint32_t chan_id, std::list &search_ids); - int add_search(uint32_t chan_id, uint32_t search_id); - int remove_search(uint32_t chan_id, uint32_t search_id); - int clear_searches(uint32_t chan_id); - - NotifyTxt *mNotify; - - RsMutex searchMtx; - - /* must store list of active searches per channel */ - std::map > mActiveSearches; - -}; - -#endif /* RS_PROTO_SEARCH_H */ diff --git a/retroshare-nogui/src/rpc/proto/rpcprotostream.cc b/retroshare-nogui/src/rpc/proto/rpcprotostream.cc deleted file mode 100644 index 37980ba2d..000000000 --- a/retroshare-nogui/src/rpc/proto/rpcprotostream.cc +++ /dev/null @@ -1,825 +0,0 @@ -/* - * RetroShare External Interface. - * - * Copyright 2012-2012 by Robert Fernie. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public - * License Version 2.1 as published by the Free Software Foundation. - * - * This library 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 - * Library General Public License for more details. - * - * You should have received a copy of the GNU Library General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 - * USA. - * - * Please report all bugs and problems to "retroshare@lunamutt.com". - * - */ - -#include "rpc/proto/rpcprotostream.h" -#include "rpc/proto/rpcprotoutils.h" - -#include "rpc/proto/gencc/stream.pb.h" -#include "rpc/proto/gencc/core.pb.h" - -#include -#include - -// from libretroshare -#include "util/rsdir.h" - -//#include -//#include -//#include - -#include "util/rsstring.h" - -#include - -#include -#include - -#include - -#define MAX_DESIRED_RATE 1000.0 // 1Mb/s - -#define MIN_STREAM_CHUNK_SIZE 10 -#define MAX_STREAM_CHUNK_SIZE 100000 - -#define STREAM_STANDARD_MIN_DT 0.1 -#define STREAM_BACKGROUND_MIN_DT 0.5 - - -bool fill_stream_details(rsctrl::stream::ResponseStreamDetail &resp, - const std::list &streams); -bool fill_stream_desc(rsctrl::stream::StreamDesc &desc, - const RpcStream &stream); - -bool fill_stream_data(rsctrl::stream::StreamData &data, const RpcStream &stream); - -bool createQueuedStreamMsg(const RpcStream &stream, rsctrl::stream::ResponseStreamData &resp, RpcQueuedMsg &qmsg); - - -RpcProtoStream::RpcProtoStream(uint32_t serviceId) - :RpcQueueService(serviceId) -{ - mNextStreamId = 1; - - return; -} - - -void RpcProtoStream::reset(uint32_t chan_id) -{ - // We should be using a mutex for all stream operations!!!! - // TODO - //RsStackMutex stack(mQueueMtx); /********** LOCKED MUTEX ***************/ - - std::list toRemove; - std::map::iterator it; - for(it = mStreams.begin(); it != mStreams.end(); it++) - { - if (it->second.chan_id == chan_id) - { - toRemove.push_back(it->first); - } - } - - std::list::iterator rit; - for(rit = toRemove.begin(); rit != toRemove.end(); rit++) - { - it = mStreams.find(*rit); - if (it != mStreams.end()) - { - mStreams.erase(it); - } - } - - // Call the rest of reset. - RpcQueueService::reset(chan_id); -} - - - - - -//RpcProtoStream::msgsAccepted(std::list &msgIds); /* not used at the moment */ - -int RpcProtoStream::processMsg(uint32_t chan_id, uint32_t msg_id, uint32_t req_id, const std::string &msg) -{ - /* check the msgId */ - uint8_t topbyte = getRpcMsgIdExtension(msg_id); - uint16_t service = getRpcMsgIdService(msg_id); - uint8_t submsg = getRpcMsgIdSubMsg(msg_id); - bool isResponse = isRpcMsgIdResponse(msg_id); - - - std::cerr << "RpcProtoStream::processMsg() topbyte: " << (int32_t) topbyte; - std::cerr << " service: " << (int32_t) service << " submsg: " << (int32_t) submsg; - std::cerr << std::endl; - - if (isResponse) - { - std::cerr << "RpcProtoStream::processMsg() isResponse() - not processing"; - std::cerr << std::endl; - return 0; - } - - if (topbyte != (uint8_t) rsctrl::core::CORE) - { - std::cerr << "RpcProtoStream::processMsg() Extension Mismatch - not processing"; - std::cerr << std::endl; - return 0; - } - - if (service != (uint16_t) rsctrl::core::STREAM) - { - std::cerr << "RpcProtoStream::processMsg() Service Mismatch - not processing"; - std::cerr << std::endl; - return 0; - } - - if (!rsctrl::stream::RequestMsgIds_IsValid(submsg)) - { - std::cerr << "RpcProtoStream::processMsg() SubMsg Mismatch - not processing"; - std::cerr << std::endl; - return 0; - } - - switch(submsg) - { - - case rsctrl::stream::MsgId_RequestStartFileStream: - processReqStartFileStream(chan_id, msg_id, req_id, msg); - break; - - case rsctrl::stream::MsgId_RequestControlStream: - processReqControlStream(chan_id, msg_id, req_id, msg); - break; - - case rsctrl::stream::MsgId_RequestListStreams: - processReqListStreams(chan_id, msg_id, req_id, msg); - break; - -// case rsctrl::stream::MsgId_RequestRegisterStreams: -// processReqRegisterStreams(chan_id, msg_id, req_id, msg); -// break; - - default: - std::cerr << "RpcProtoStream::processMsg() ERROR should never get here"; - std::cerr << std::endl; - return 0; - } - - /* must have matched id to get here */ - return 1; -} - - - -int RpcProtoStream::processReqStartFileStream(uint32_t chan_id, uint32_t /*msg_id*/, uint32_t req_id, const std::string &msg) -{ - std::cerr << "RpcProtoStream::processReqStartFileStream()"; - std::cerr << std::endl; - - // parse msg. - rsctrl::stream::RequestStartFileStream req; - if (!req.ParseFromString(msg)) - { - std::cerr << "RpcProtoStream::processReqStartFileStream() ERROR ParseFromString()"; - std::cerr << std::endl; - return 0; - } - - // response. - rsctrl::stream::ResponseStreamDetail resp; - bool success = true; - std::string errorMsg; - - - // SETUP STREAM. - - // FIND the FILE. - std::list hashes; - hashes.push_back(req.file().hash()); - - //HashExpression exp(StringOperator::EqualsString, hashes); - HashExpression exp(EqualsString, hashes); - std::list results; - - FileSearchFlags flags = RS_FILE_HINTS_LOCAL; - int ans = rsFiles->SearchBoolExp(&exp, results, flags); - - // CREATE A STREAM OBJECT. - if (results.size() < 1) - { - success = false; - errorMsg = "No Matching File"; - } - else - { - DirDetails &dirdetail = results.front(); - - RpcStream stream; - stream.chan_id = chan_id; - stream.req_id = req_id; - stream.stream_id = getNextStreamId(); - stream.state = RpcStream::RUNNING; - - // Convert to Full local path. - std::string virtual_path = RsDirUtil::makePath(dirdetail.path, dirdetail.name); - if (!rsFiles->ConvertSharedFilePath(virtual_path, stream.path)) - { - success = false; - errorMsg = "Cannot Match to Shared Directory"; - } - - stream.length = dirdetail.count; - stream.hash = dirdetail.hash; - stream.name = dirdetail.name; - - stream.offset = 0; - stream.start_byte = 0; - stream.end_byte = stream.length; - stream.desired_rate = req.rate_kbs(); - - if (stream.desired_rate > MAX_DESIRED_RATE) - { - stream.desired_rate = MAX_DESIRED_RATE; - } - - // make response - rsctrl::stream::StreamDesc *desc = resp.add_streams(); - if (!fill_stream_desc(*desc, stream)) - { - success = false; - errorMsg = "Failed to Invalid Action"; - } - else - { - // insert. - mStreams[stream.stream_id] = stream; - - // register the stream too. - std::cerr << "RpcProtoStream::processReqStartFileStream() Registering the stream event."; - std::cerr << std::endl; - registerForEvents(chan_id, req_id, REGISTRATION_STREAMS); - } - - std::cerr << "RpcProtoStream::processReqStartFileStream() List of Registered Streams:"; - std::cerr << std::endl; - printEventRegister(std::cerr); - } - - /* DONE - Generate Reply */ - if (success) - { - rsctrl::core::Status *status = resp.mutable_status(); - status->set_code(rsctrl::core::Status::SUCCESS); - } - else - { - rsctrl::core::Status *status = resp.mutable_status(); - status->set_code(rsctrl::core::Status::FAILED); - status->set_msg(errorMsg); - } - - std::string outmsg; - if (!resp.SerializeToString(&outmsg)) - { - std::cerr << "RpcProtoStream::processReqStartFileStream() ERROR SerialiseToString()"; - std::cerr << std::endl; - return 0; - } - - // Correctly Name Message. - uint32_t out_msg_id = constructMsgId(rsctrl::core::CORE, rsctrl::core::STREAM, - rsctrl::stream::MsgId_ResponseStreamDetail, true); - - // queue it. - queueResponse(chan_id, out_msg_id, req_id, outmsg); - return 1; -} - - - -int RpcProtoStream::processReqControlStream(uint32_t chan_id, uint32_t /*msg_id*/, uint32_t req_id, const std::string &msg) -{ - std::cerr << "RpcProtoStream::processReqControlStream()"; - std::cerr << std::endl; - - // parse msg. - rsctrl::stream::RequestControlStream req; - if (!req.ParseFromString(msg)) - { - std::cerr << "RpcProtoStream::processReqControlStream() ERROR ParseFromString()"; - std::cerr << std::endl; - return 0; - } - - // response. - rsctrl::stream::ResponseStreamDetail resp; - bool success = true; - std::string errorMsg; - - // FIND MATCHING STREAM. - std::map::iterator it; - it = mStreams.find(req.stream_id()); - if (it != mStreams.end()) - { - // TWEAK - - if (it->second.state == RpcStream::STREAMERR) - { - if (req.action() == rsctrl::stream::RequestControlStream::STREAM_STOP) - { - it->second.state = RpcStream::FINISHED; - } - else - { - success = false; - errorMsg = "Stream Error"; - } - } - else - { - switch(req.action()) - { - case rsctrl::stream::RequestControlStream::STREAM_START: - if (it->second.state == RpcStream::PAUSED) - { - it->second.state = RpcStream::RUNNING; - } - break; - - case rsctrl::stream::RequestControlStream::STREAM_STOP: - it->second.state = RpcStream::FINISHED; - break; - - case rsctrl::stream::RequestControlStream::STREAM_PAUSE: - if (it->second.state == RpcStream::RUNNING) - { - it->second.state = RpcStream::PAUSED; - it->second.transfer_time = 0; // reset timings. - } - break; - - case rsctrl::stream::RequestControlStream::STREAM_CHANGE_RATE: - it->second.desired_rate = req.rate_kbs(); - break; - - case rsctrl::stream::RequestControlStream::STREAM_SEEK: - if (req.seek_byte() < it->second.end_byte) - { - it->second.offset = req.seek_byte(); - } - break; - default: - success = false; - errorMsg = "Invalid Action"; - } - } - - // FILL IN REPLY. - if (success) - { - rsctrl::stream::StreamDesc *desc = resp.add_streams(); - if (!fill_stream_desc(*desc, it->second)) - { - success = false; - errorMsg = "Invalid Action"; - } - } - - // Cleanup - TODO, this is explicit at the moment. - should be automatic after finish. - if (it->second.state == RpcStream::FINISHED) - { - deregisterForEvents(it->second.chan_id, it->second.req_id, REGISTRATION_STREAMS); - mStreams.erase(it); - } - } - else - { - success = false; - errorMsg = "No Matching Stream"; - } - - /* DONE - Generate Reply */ - if (success) - { - rsctrl::core::Status *status = resp.mutable_status(); - status->set_code(rsctrl::core::Status::SUCCESS); - } - else - { - rsctrl::core::Status *status = resp.mutable_status(); - status->set_code(rsctrl::core::Status::FAILED); - status->set_msg(errorMsg); - } - - std::string outmsg; - if (!resp.SerializeToString(&outmsg)) - { - std::cerr << "RpcProtoStream::processReqControlStream() ERROR SerialiseToString()"; - std::cerr << std::endl; - return 0; - } - - // Correctly Name Message. - uint32_t out_msg_id = constructMsgId(rsctrl::core::CORE, rsctrl::core::STREAM, - rsctrl::stream::MsgId_ResponseStreamDetail, true); - - // queue it. - queueResponse(chan_id, out_msg_id, req_id, outmsg); - - return 1; -} - - - -int RpcProtoStream::processReqListStreams(uint32_t chan_id, uint32_t /*msg_id*/, uint32_t req_id, const std::string &msg) -{ - std::cerr << "RpcProtoStream::processReqListStreams()"; - std::cerr << std::endl; - - // parse msg. - rsctrl::stream::RequestListStreams req; - if (!req.ParseFromString(msg)) - { - std::cerr << "RpcProtoStream::processReqListStreams() ERROR ParseFromString()"; - std::cerr << std::endl; - return 0; - } - - // response. - rsctrl::stream::ResponseStreamDetail resp; - bool success = false; - std::string errorMsg; - - - - std::map::iterator it; - for(it = mStreams.begin(); it != mStreams.end(); it++) - { - bool match = true; - - // TODO fill in match! - /* check that it matches */ - if (! match) - { - continue; - } - - rsctrl::stream::StreamDesc *desc = resp.add_streams(); - if (!fill_stream_desc(*desc, it->second)) - { - success = false; - errorMsg = "Some Details Failed to Fill"; - } - } - - /* DONE - Generate Reply */ - if (success) - { - rsctrl::core::Status *status = resp.mutable_status(); - status->set_code(rsctrl::core::Status::SUCCESS); - } - else - { - rsctrl::core::Status *status = resp.mutable_status(); - status->set_code(rsctrl::core::Status::FAILED); - status->set_msg(errorMsg); - } - - std::string outmsg; - if (!resp.SerializeToString(&outmsg)) - { - std::cerr << "RpcProtoStream::processReqListStreams() ERROR SerialiseToString()"; - std::cerr << std::endl; - return 0; - } - - // Correctly Name Message. - uint32_t out_msg_id = constructMsgId(rsctrl::core::CORE, rsctrl::core::STREAM, - rsctrl::stream::MsgId_ResponseStreamDetail, true); - - // queue it. - queueResponse(chan_id, out_msg_id, req_id, outmsg); - return 1; -} - - - // EVENTS. (STREAMS) -int RpcProtoStream::locked_checkForEvents(uint32_t event, const std::list & /* registered */, std::list &stream_msgs) -{ - /* only one event type for now */ - if (event != REGISTRATION_STREAMS) - { - std::cerr << "ERROR Invalid Stream Event Type"; - std::cerr << std::endl; - - /* error */ - return 0; - } - - /* iterate through streams, and get next chunk of data. - * package up and send it. - * NOTE we'll have to something more complex for VoIP! - */ - - double ts = getTimeStamp(); - double dt = ts - mStreamRates.last_ts; - uint32_t data_sent = 0; - -#define FILTER_K (0.75) - - if (dt < 5.0) //mStreamRates.last_ts != 0) - { - mStreamRates.avg_dt = FILTER_K * mStreamRates.avg_dt - + (1.0 - FILTER_K) * dt; - } - else - { - std::cerr << "RpcProtoStream::locked_checkForEvents() Large dT - resetting avg"; - std::cerr << std::endl; - mStreamRates.avg_dt = 0.0; - } - - mStreamRates.last_ts = ts; - - - std::map::iterator it; - for(it = mStreams.begin(); it != mStreams.end(); it++) - { - RpcStream &stream = it->second; - - if (!(stream.state == RpcStream::RUNNING)) - { - continue; - } - - double stream_dt = ts - stream.transfer_time; - - switch(stream.transfer_type) - { - case RpcStream::REALTIME: - // let it go through always. - break; - - case RpcStream::STANDARD: - if (stream_dt < STREAM_STANDARD_MIN_DT) - { - continue; - } - break; - - - case RpcStream::BACKGROUND: - if (stream_dt < STREAM_BACKGROUND_MIN_DT) - { - continue; - } - break; - } - - if (!stream.transfer_time) - { - std::cerr << "RpcProtoStream::locked_checkForEvents() Null stream.transfer_time .. resetting"; - std::cerr << std::endl; - stream.transfer_avg_dt = STREAM_STANDARD_MIN_DT; - } - else - { - std::cerr << "RpcProtoStream::locked_checkForEvents() stream.transfer_avg_dt: " << stream.transfer_avg_dt; - std::cerr << " stream_dt: " << stream_dt; - std::cerr << std::endl; - stream.transfer_avg_dt = FILTER_K * stream.transfer_avg_dt - + (1.0 - FILTER_K) * stream_dt; - - std::cerr << "RpcProtoStream::locked_checkForEvents() ==> stream.transfer_avg_dt: " << stream.transfer_avg_dt; - std::cerr << std::endl; - } - - uint32_t size = stream.desired_rate * 1000.0 * stream.transfer_avg_dt; - stream.transfer_time = ts; - - - if (size < MIN_STREAM_CHUNK_SIZE) - { - size = MIN_STREAM_CHUNK_SIZE; - } - if (size > MAX_STREAM_CHUNK_SIZE) - { - size = MAX_STREAM_CHUNK_SIZE; - } - - - /* get data */ - uint64_t remaining = stream.end_byte - stream.offset; - if (remaining < size) - { - size = remaining; - stream.state = RpcStream::FINISHED; - std::cerr << "RpcProtoStream::locked_checkForEvents() Sending Remaining: " << size; - std::cerr << std::endl; - } - - std::cerr << "RpcProtoStream::locked_checkForEvents() Handling Stream: " << stream.stream_id << " state: " << stream.state; - std::cerr << std::endl; - std::cerr << "path: " << stream.path; - std::cerr << std::endl; - std::cerr << "offset: " << stream.offset; - std::cerr << " avg_dt: " << stream.transfer_avg_dt; - std::cerr << " x desired_rate: " << stream.desired_rate; - std::cerr << " => chunk_size: " << size; - std::cerr << std::endl; - - /* fill in the answer */ - - rsctrl::stream::ResponseStreamData resp; - rsctrl::core::Status *status = resp.mutable_status(); - status->set_code(rsctrl::core::Status::SUCCESS); - - rsctrl::stream::StreamData *data = resp.mutable_data(); - data->set_stream_id(stream.stream_id); - - // convert state. - switch(stream.state) - { - case RpcStream::RUNNING: - data->set_stream_state(rsctrl::stream::STREAM_STATE_RUN); - break; - // This case cannot happen. - case RpcStream::PAUSED: - data->set_stream_state(rsctrl::stream::STREAM_STATE_PAUSED); - break; - // This can only happen at last chunk. - default: - case RpcStream::FINISHED: - data->set_stream_state(rsctrl::stream::STREAM_STATE_FINISHED); - break; - } - - - rsctrl::core::Timestamp *ts = data->mutable_send_time(); - setTimeStamp(ts); - - data->set_offset(stream.offset); - data->set_size(size); - - if (fill_stream_data(*data, stream)) - { - - /* increment seek_location - for next request */ - stream.offset += size; - - RpcQueuedMsg qmsg; - if (createQueuedStreamMsg(stream, resp, qmsg)) - { - std::cerr << "Created Stream Msg."; - std::cerr << std::endl; - - stream_msgs.push_back(qmsg); - } - else - { - std::cerr << "ERROR Creating Stream Msg"; - std::cerr << std::endl; - } - } - else - { - stream.state = RpcStream::STREAMERR; - std::cerr << "ERROR Filling Stream Data"; - std::cerr << std::endl; - } - - } - return 1; -} - - - -// TODO -int RpcProtoStream::cleanup_checkForEvents(uint32_t /* event */, const std::list & /* registered */) -{ - std::list to_remove; - std::list::iterator rit; - for(rit = to_remove.begin(); rit != to_remove.end(); rit++) - { - /* kill the stream! */ - std::map::iterator it; - it = mStreams.find(*rit); - if (it != mStreams.end()) - { - mStreams.erase(it); - } - } - return 1; -} - - -/***** HELPER FUNCTIONS *****/ - -bool createQueuedStreamMsg(const RpcStream &stream, rsctrl::stream::ResponseStreamData &resp, RpcQueuedMsg &qmsg) -{ - std::string outmsg; - if (!resp.SerializeToString(&outmsg)) - { - std::cerr << "RpcProtoStream::createQueuedEventSendMsg() ERROR SerialiseToString()"; - std::cerr << std::endl; - return false; - } - - // Correctly Name Message. - qmsg.mMsgId = constructMsgId(rsctrl::core::CORE, rsctrl::core::STREAM, - rsctrl::stream::MsgId_ResponseStreamData, true); - - qmsg.mChanId = stream.chan_id; - qmsg.mReqId = stream.req_id; - qmsg.mMsg = outmsg; - - return true; -} - - - - -/****************** NEW HELPER FNS ******************/ - -bool fill_stream_details(rsctrl::stream::ResponseStreamDetail &resp, - const std::list &streams) -{ - std::cerr << "fill_stream_details()"; - std::cerr << std::endl; - - bool val = true; - std::list::const_iterator it; - for (it = streams.begin(); it != streams.end(); it++) - { - rsctrl::stream::StreamDesc *desc = resp.add_streams(); - val &= fill_stream_desc(*desc, *it); - } - - return val; -} - -bool fill_stream_desc(rsctrl::stream::StreamDesc &desc, const RpcStream &stream) -{ - std::cerr << "fill_stream_desc()"; - std::cerr << std::endl; - - return true; -} - -bool fill_stream_data(rsctrl::stream::StreamData &data, const RpcStream &stream) -{ - /* fill the StreamData from stream */ - - /* open file */ - FILE *fd = RsDirUtil::rs_fopen(stream.path.c_str(), "rb"); - if (!fd) - { - std::cerr << "fill_stream_data() Failed to open file: " << stream.path; - std::cerr << std::endl; - return false; - } - - uint32_t data_size = data.size(); - uint64_t base_loc = data.offset(); - void *buffer = malloc(data_size); - - /* seek to correct spot */ - fseeko64(fd, base_loc, SEEK_SET); - - /* copy data into bytes */ - if (1 != fread(buffer, data_size, 1, fd)) - { - std::cerr << "fill_stream_data() Failed to get data. data_size=" << data_size << ", base_loc=" << base_loc << " !"; - std::cerr << std::endl; - free(buffer); - return false; - } - - data.set_stream_data(buffer, data_size); - free(buffer); - - fclose(fd); - - return true; -} - - - - -uint32_t RpcProtoStream::getNextStreamId() -{ - return mNextStreamId++; -} - - diff --git a/retroshare-nogui/src/rpc/proto/rpcprotostream.h b/retroshare-nogui/src/rpc/proto/rpcprotostream.h deleted file mode 100644 index 698e9a52f..000000000 --- a/retroshare-nogui/src/rpc/proto/rpcprotostream.h +++ /dev/null @@ -1,124 +0,0 @@ -/* - * RetroShare External Interface. - * - * Copyright 2012-2012 by Robert Fernie. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public - * License Version 2.1 as published by the Free Software Foundation. - * - * This library 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 - * Library General Public License for more details. - * - * You should have received a copy of the GNU Library General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 - * USA. - * - * Please report all bugs and problems to "retroshare@lunamutt.com". - * - */ - - -#ifndef RS_RPC_PROTO_STREAM_H -#define RS_RPC_PROTO_STREAM_H - -#include "rpc/rpcserver.h" - -// Registrations. -#define REGISTRATION_STREAMS 1 - -class RpcStream -{ - public: - RpcStream(): chan_id(0), req_id(0), stream_id(0), state(0), - offset(0), length(0), start_byte(0), end_byte(0), desired_rate(0), - transfer_type(0), transfer_time(0), transfer_avg_dt(0) - { return; } - -static const uint32_t STREAMERR = 0x00000; -static const uint32_t RUNNING = 0x00001; -static const uint32_t PAUSED = 0x00002; -static const uint32_t FINISHED = 0x00003; - - uint32_t chan_id; - uint32_t req_id; - uint32_t stream_id; - uint32_t state; - - std::string name; - std::string hash; - std::string path; - - uint64_t offset; // where we currently are. - uint64_t length; // filesize. - - uint64_t start_byte; - uint64_t end_byte; - - float desired_rate; // Kb/s - - - // Transfer Type -static const uint32_t STANDARD = 0x00000; -static const uint32_t REALTIME = 0x00001; -static const uint32_t BACKGROUND = 0x00002; - - uint32_t transfer_type; - double transfer_time; - double transfer_avg_dt; - - -}; - - -class RpcStreamRates -{ - public: - RpcStreamRates(): avg_data_rate(0), avg_dt(1), last_data_rate(0), last_ts(0) { return; } - - double avg_data_rate; - double avg_dt; - - double last_data_rate; - double last_ts; -}; - - - - -class RpcProtoStream: public RpcQueueService -{ -public: - RpcProtoStream(uint32_t serviceId); - virtual int processMsg(uint32_t chan_id, uint32_t msgId, uint32_t req_id, const std::string &msg); - virtual void reset(uint32_t chan_id); - - uint32_t getNextStreamId(); - -protected: - - - int processReqStartFileStream(uint32_t chan_id, uint32_t msg_id, uint32_t req_id, const std::string &msg); - int processReqControlStream(uint32_t chan_id, uint32_t msg_id, uint32_t req_id, const std::string &msg); - int processReqListStreams(uint32_t chan_id, uint32_t msg_id, uint32_t req_id, const std::string &msg); - int processReqRegisterStreams(uint32_t chan_id, uint32_t msg_id, uint32_t req_id, const std::string &msg); - - - uint32_t mNextStreamId; - - RpcStreamRates mStreamRates; - std::map mStreams; - - // EVENTS. - virtual int locked_checkForEvents(uint32_t event, const std::list ®istered, std::list &events); - - // Not actually used yet. - int cleanup_checkForEvents(uint32_t event, const std::list ®istered); - -}; - - -#endif /* RS_PROTO_STREAM_H */ diff --git a/retroshare-nogui/src/rpc/proto/rpcprotosystem.cc b/retroshare-nogui/src/rpc/proto/rpcprotosystem.cc deleted file mode 100644 index 3bcf885af..000000000 --- a/retroshare-nogui/src/rpc/proto/rpcprotosystem.cc +++ /dev/null @@ -1,354 +0,0 @@ -/* - * RetroShare External Interface. - * - * Copyright 2012-2012 by Robert Fernie. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public - * License Version 2.1 as published by the Free Software Foundation. - * - * This library 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 - * Library General Public License for more details. - * - * You should have received a copy of the GNU Library General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 - * USA. - * - * Please report all bugs and problems to "retroshare@lunamutt.com". - * - */ - -#include "rpc/proto/rpcprotosystem.h" -#include "rpc/proto/gencc/system.pb.h" - -#include -#include -#include -#include - -#include -#include - -// NASTY GLOBAL VARIABLE HACK - NEED TO THINK OF A BETTER SYSTEM. -uint16_t RpcProtoSystem::mExtPort = 0; - -RpcProtoSystem::RpcProtoSystem(uint32_t serviceId) - :RpcQueueService(serviceId) -{ - return; -} - -//RpcProtoSystem::msgsAccepted(std::list &msgIds); /* not used at the moment */ - -int RpcProtoSystem::processMsg(uint32_t chan_id, uint32_t msg_id, uint32_t req_id, const std::string &msg) -{ - /* check the msgId */ - uint8_t topbyte = getRpcMsgIdExtension(msg_id); - uint16_t service = getRpcMsgIdService(msg_id); - uint8_t submsg = getRpcMsgIdSubMsg(msg_id); - bool isResponse = isRpcMsgIdResponse(msg_id); - - - std::cerr << "RpcProtoSystem::processMsg() topbyte: " << (int32_t) topbyte; - std::cerr << " service: " << (int32_t) service << " submsg: " << (int32_t) submsg; - std::cerr << std::endl; - - if (isResponse) - { - std::cerr << "RpcProtoSystem::processMsg() isResponse() - not processing"; - std::cerr << std::endl; - return 0; - } - - - if (topbyte != (uint8_t) rsctrl::core::CORE) - { - std::cerr << "RpcProtoSystem::processMsg() Extension Mismatch - not processing"; - std::cerr << std::endl; - return 0; - } - - if (service != (uint16_t) rsctrl::core::SYSTEM) - { - std::cerr << "RpcProtoSystem::processMsg() Service Mismatch - not processing"; - std::cerr << std::endl; - return 0; - } - - if (!rsctrl::system::RequestMsgIds_IsValid(submsg)) - { - std::cerr << "RpcProtoSystem::processMsg() SubMsg Mismatch - not processing"; - std::cerr << std::endl; - return 0; - } - - switch(submsg) - { - case rsctrl::system::MsgId_RequestSystemStatus: - processSystemStatus(chan_id, msg_id, req_id, msg); - break; -#if 0 - case rsctrl::system::MsgId_RequestSystemQuit: - processSystemQuit(chan_id, msg_id, req_id, msg); - break; -#endif - case rsctrl::system::MsgId_RequestSystemExternalAccess: - processSystemExternalAccess(chan_id, msg_id, req_id, msg); - break; - default: - std::cerr << "RpcProtoSystem::processMsg() ERROR should never get here"; - std::cerr << std::endl; - return 0; - } - - /* must have matched id to get here */ - return 1; -} - - -int RpcProtoSystem::processSystemStatus(uint32_t chan_id, uint32_t /* msg_id */, uint32_t req_id, const std::string &msg) -{ - std::cerr << "RpcProtoSystem::processSystemStatus()"; - std::cerr << std::endl; - - // parse msg. - rsctrl::system::RequestSystemStatus req; - if (!req.ParseFromString(msg)) - { - std::cerr << "RpcProtoSystem::processSystemStatus() ERROR ParseFromString()"; - std::cerr << std::endl; - return 0; - } - - // NO Options... so go straight to answer. - // response. - rsctrl::system::ResponseSystemStatus resp; - bool success = true; - - unsigned int nTotal = 0; - unsigned int nConnected = 0; - rsPeers->getPeerCount(&nTotal, &nConnected, false); - - float downKb = 0; - float upKb = 0; - rsConfig->GetCurrentDataRates(downKb, upKb); - - // set the data. - resp.set_no_peers(nTotal); - resp.set_no_connected(nConnected); - - rsctrl::core::Bandwidth *bw = resp.mutable_bw_total(); - bw->set_up(upKb); - bw->set_down(downKb); - bw->set_name("Total Connection Bandwidth"); - - uint32_t netState = rsConfig->getNetState(); - std::string natState("Unknown"); - rsctrl::system::ResponseSystemStatus_NetCode protoCode; - - switch(netState) - { - default: - case RSNET_NETSTATE_BAD_UNKNOWN: - protoCode = rsctrl::system::ResponseSystemStatus::BAD_UNKNOWN; - break; - - case RSNET_NETSTATE_BAD_OFFLINE: - protoCode = rsctrl::system::ResponseSystemStatus::BAD_OFFLINE; - break; - - case RSNET_NETSTATE_BAD_NATSYM: - protoCode = rsctrl::system::ResponseSystemStatus::BAD_NATSYM; - break; - - case RSNET_NETSTATE_BAD_NODHT_NAT: - protoCode = rsctrl::system::ResponseSystemStatus::BAD_NODHT_NAT; - break; - - case RSNET_NETSTATE_WARNING_RESTART: - protoCode = rsctrl::system::ResponseSystemStatus::WARNING_RESTART; - break; - - case RSNET_NETSTATE_WARNING_NATTED: - protoCode = rsctrl::system::ResponseSystemStatus::WARNING_NATTED; - break; - - case RSNET_NETSTATE_WARNING_NODHT: - protoCode = rsctrl::system::ResponseSystemStatus::WARNING_NODHT; - break; - - case RSNET_NETSTATE_GOOD: - protoCode = rsctrl::system::ResponseSystemStatus::GOOD; - break; - - case RSNET_NETSTATE_ADV_FORWARD: - protoCode = rsctrl::system::ResponseSystemStatus::ADV_FORWARD; - break; - } - - resp.set_net_status(protoCode); - - - if (success) - { - rsctrl::core::Status *status = resp.mutable_status(); - status->set_code(rsctrl::core::Status::SUCCESS); - } - else - { - rsctrl::core::Status *status = resp.mutable_status(); - status->set_code(rsctrl::core::Status::FAILED); - status->set_msg("Unknown ERROR"); - } - - std::string outmsg; - if (!resp.SerializeToString(&outmsg)) - { - std::cerr << "RpcProtoSystem::processSystemStatus() ERROR SerialiseToString()"; - std::cerr << std::endl; - return 0; - } - - // Correctly Name Message. - uint32_t out_msg_id = constructMsgId(rsctrl::core::CORE, rsctrl::core::SYSTEM, - rsctrl::system::MsgId_ResponseSystemStatus, true); - - // queue it. - queueResponse(chan_id, out_msg_id, req_id, outmsg); - - return 1; -} - - - -int RpcProtoSystem::processSystemQuit(uint32_t chan_id, uint32_t /* msg_id */, uint32_t req_id, const std::string &msg) -{ - std::cerr << "RpcProtoSystem::processSystemQuit()"; - std::cerr << std::endl; - - // parse msg. - rsctrl::system::RequestSystemQuit req; - if (!req.ParseFromString(msg)) - { - std::cerr << "RpcProtoSystem::processSystemQuit() ERROR ParseFromString()"; - std::cerr << std::endl; - return 0; - } - - // NO Options... so go straight to answer. - // response. - rsctrl::system::ResponseSystemQuit resp; - bool success = true; - - switch(req.quit_code()) - { - default: - case rsctrl::system::RequestSystemQuit::CLOSE_CHANNEL: - { - RpcServer *server = getRpcServer(); - server->error(chan_id, "CLOSE_CHANNEL"); - - break; - } - case rsctrl::system::RequestSystemQuit::SHUTDOWN_RS: - { - RsControl::instance()->rsGlobalShutDown(); - break; - } - } - - if (success) - { - rsctrl::core::Status *status = resp.mutable_status(); - status->set_code(rsctrl::core::Status::SUCCESS); - } - else - { - rsctrl::core::Status *status = resp.mutable_status(); - status->set_code(rsctrl::core::Status::FAILED); - status->set_msg("Unknown ERROR"); - } - - std::string outmsg; - if (!resp.SerializeToString(&outmsg)) - { - std::cerr << "RpcProtoSystem::processSystemQuit() ERROR SerialiseToString()"; - std::cerr << std::endl; - return 0; - } - - // Correctly Name Message. - uint32_t out_msg_id = constructMsgId(rsctrl::core::CORE, rsctrl::core::SYSTEM, - rsctrl::system::MsgId_ResponseSystemQuit, true); - - // queue it. - queueResponse(chan_id, out_msg_id, req_id, outmsg); - - return 1; -} - - -int RpcProtoSystem::processSystemExternalAccess(uint32_t chan_id, uint32_t /* msg_id */, uint32_t req_id, const std::string &msg) -{ - std::cerr << "RpcProtoSystem::processSystemExternalAccess()"; - std::cerr << std::endl; - - // parse msg. - rsctrl::system::RequestSystemExternalAccess req; - if (!req.ParseFromString(msg)) - { - std::cerr << "RpcProtoSystem::processSystemExternalAccess() ERROR ParseFromString()"; - std::cerr << std::endl; - return 0; - } - - // NO Options... so go straight to answer. - // response. - rsctrl::system::ResponseSystemExternalAccess resp; - bool success = true; - - - std::string dhtKey; - if (!rsDht->getOwnDhtId(dhtKey)) - { - success = false; - } - // have to set something anyway!. - resp.set_dht_key(dhtKey); - // NASTY GLOBAL VARIABLE HACK - NEED TO THINK OF A BETTER SYSTEM. - resp.set_ext_port(mExtPort); - - if (success) - { - rsctrl::core::Status *status = resp.mutable_status(); - status->set_code(rsctrl::core::Status::SUCCESS); - } - else - { - rsctrl::core::Status *status = resp.mutable_status(); - status->set_code(rsctrl::core::Status::FAILED); - status->set_msg("Unknown ERROR"); - } - - std::string outmsg; - if (!resp.SerializeToString(&outmsg)) - { - std::cerr << "RpcProtoSystem::processSystemExternalAccess() ERROR SerialiseToString()"; - std::cerr << std::endl; - return 0; - } - - // Correctly Name Message. - uint32_t out_msg_id = constructMsgId(rsctrl::core::CORE, rsctrl::core::SYSTEM, - rsctrl::system::MsgId_ResponseSystemExternalAccess, true); - - // queue it. - queueResponse(chan_id, out_msg_id, req_id, outmsg); - - return 1; -} - - diff --git a/retroshare-nogui/src/rpc/proto/rpcprotosystem.h b/retroshare-nogui/src/rpc/proto/rpcprotosystem.h deleted file mode 100644 index 1c2ff36be..000000000 --- a/retroshare-nogui/src/rpc/proto/rpcprotosystem.h +++ /dev/null @@ -1,47 +0,0 @@ -/* - * RetroShare External Interface. - * - * Copyright 2012-2012 by Robert Fernie. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public - * License Version 2.1 as published by the Free Software Foundation. - * - * This library 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 - * Library General Public License for more details. - * - * You should have received a copy of the GNU Library General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 - * USA. - * - * Please report all bugs and problems to "retroshare@lunamutt.com". - * - */ - - -#ifndef RS_RPC_PROTO_SYSTEM_H -#define RS_RPC_PROTO_SYSTEM_H - -#include "rpc/rpcserver.h" - -class RpcProtoSystem: public RpcQueueService -{ -public: - RpcProtoSystem(uint32_t serviceId); -// virtual msgsAccepted(std::list &msgIds); /* not used at the moment */ - virtual int processMsg(uint32_t chan_id, uint32_t msgId, uint32_t req_id, const std::string &msg); - - virtual int processSystemStatus(uint32_t chan_id, uint32_t msg_id, uint32_t req_id, const std::string &msg); - virtual int processSystemQuit(uint32_t chan_id, uint32_t msg_id, uint32_t req_id, const std::string &msg); - virtual int processSystemExternalAccess(uint32_t chan_id, uint32_t msg_id, uint32_t req_id, const std::string &msg); - -// NASTY GLOBAL VARIABLE HACK - NEED TO THINK OF A BETTER SYSTEM. -static uint16_t mExtPort; - -}; - - -#endif /* RS_PROTO_SYSTEM_H */ diff --git a/retroshare-nogui/src/rpc/proto/rpcprotoutils.cc b/retroshare-nogui/src/rpc/proto/rpcprotoutils.cc deleted file mode 100644 index 4568560dd..000000000 --- a/retroshare-nogui/src/rpc/proto/rpcprotoutils.cc +++ /dev/null @@ -1,59 +0,0 @@ -/* - * RetroShare External Interface. - * - * Copyright 2012-2012 by Robert Fernie. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public - * License Version 2.1 as published by the Free Software Foundation. - * - * This library 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 - * Library General Public License for more details. - * - * You should have received a copy of the GNU Library General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 - * USA. - * - * Please report all bugs and problems to "retroshare@lunamutt.com". - * - */ - -#include "rpc/proto/rpcprotoutils.h" -#include - - -double getTimeStamp() -{ - struct timeval tv; - double ts = 0; - if (0 == gettimeofday(&tv, NULL)) - { - ts = tv.tv_sec + (tv.tv_usec / 1000000.0); - } - return ts; -} - -bool setTimeStamp(rsctrl::core::Timestamp *ts) -{ - struct timeval tv; - if (0 != gettimeofday(&tv, NULL)) - { - ts->set_secs(tv.tv_sec); - ts->set_microsecs(tv.tv_usec); - return true; - } - else - { - ts->set_secs(0); - ts->set_microsecs(0); - return false; - } - return false; -} - - - - diff --git a/retroshare-nogui/src/rpc/proto/rpcprotoutils.h b/retroshare-nogui/src/rpc/proto/rpcprotoutils.h deleted file mode 100644 index 9c9ecf647..000000000 --- a/retroshare-nogui/src/rpc/proto/rpcprotoutils.h +++ /dev/null @@ -1,35 +0,0 @@ -/* - * RetroShare External Interface. - * - * Copyright 2012-2012 by Robert Fernie. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public - * License Version 2.1 as published by the Free Software Foundation. - * - * This library 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 - * Library General Public License for more details. - * - * You should have received a copy of the GNU Library General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 - * USA. - * - * Please report all bugs and problems to "retroshare@lunamutt.com". - * - */ - - -#ifndef RS_RPC_PROTO_UTILS_H -#define RS_RPC_PROTO_UTILS_H - - -#include "rpc/proto/gencc/core.pb.h" - -double getTimeStamp(); -bool setTimeStamp(rsctrl::core::Timestamp *ts); - - -#endif /* RS_RPC_PROTO_UTILS_H */ diff --git a/retroshare-nogui/src/rpc/rpc.cc b/retroshare-nogui/src/rpc/rpc.cc deleted file mode 100644 index a1aa1683b..000000000 --- a/retroshare-nogui/src/rpc/rpc.cc +++ /dev/null @@ -1,307 +0,0 @@ -/* - * RetroShare External Interface. - * - * Copyright 2012-2012 by Robert Fernie. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public - * License Version 2.1 as published by the Free Software Foundation. - * - * This library 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 - * Library General Public License for more details. - * - * You should have received a copy of the GNU Library General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 - * USA. - * - * Please report all bugs and problems to "retroshare@lunamutt.com". - * - */ - -#include "rpc/rpc.h" -#include "rpc/rpcserver.h" - -// This one is inside libretroshare (BAD)!!! -#include "serialiser/rsbaseserial.h" - -#include - -const uint32_t kMsgHeaderSize = 16; -const uint32_t kMsgMagicCode = 0x137f0001; // Arbitary + 0x0001 - -RpcMediator::RpcMediator(RpcComms *c) - :mComms(c), mServer(NULL) -{ - return; -} - -void RpcMediator::reset(uint32_t chan_id) -{ - mServer->reset(chan_id); -} - -int RpcMediator::error(uint32_t chan_id, std::string msg) -{ - return mComms->error(chan_id, msg); -} - - -int RpcMediator::tick() -{ - bool worked = false; - if (recv()) - { - worked = true; - } - - if (mServer->checkPending()) - { - worked = true; - } - - if (mServer->checkEvents()) - { - worked = true; - } - - if (worked) - return 1; - else - return 0; - return 0; -} - - -int RpcMediator::recv() -{ - int recvd = 0; - - std::list chan_ids; - std::list::iterator it; - mComms->active_channels(chan_ids); - for(it = chan_ids.begin(); it != chan_ids.end(); it++) - { - while(recv_msg(*it)) - { - recvd = 1; - } - } - return recvd; -} - - -int RpcMediator::recv_msg(uint32_t chan_id) -{ - /* nothing in here needs a Mutex... */ - - if (!mComms->recv_ready(chan_id)) - { - return 0; - } - - std::cerr << "RpcMediator::recv_msg() Data Ready"; - std::cerr << std::endl; - - /* read in data */ - uint8_t buffer[kMsgHeaderSize]; - uint32_t bufsize = kMsgHeaderSize; - uint32_t msg_id; - uint32_t req_id; - uint32_t msg_size; - std::string msg_body; - - std::cerr << "RpcMediator::recv_msg() get Header: " << bufsize; - std::cerr << " bytes" << std::endl; - - int read = mComms->recv_blocking(chan_id, buffer, bufsize); - if (read != bufsize) - { - /* error */ - std::cerr << "RpcMediator::recv_msg() Error Reading Header: " << bufsize; - std::cerr << " bytes" << std::endl; - - mComms->error(chan_id, "Failed to Recv Header"); - return 0; - } - - if (!MsgPacker::deserialiseHeader(msg_id, req_id, msg_size, buffer, bufsize)) - { - /* error */ - std::cerr << "RpcMediator::recv_msg() Error Deserialising Header"; - std::cerr << std::endl; - - mComms->error(chan_id, "Failed to Deserialise Header"); - return 0; - } - - std::cerr << "RpcMediator::recv_msg() ChanId: " << chan_id; - std::cerr << " MsgId: " << msg_id; - std::cerr << " ReqId: " << req_id; - std::cerr << std::endl; - - std::cerr << "RpcMediator::recv_msg() get Body: " << msg_size; - std::cerr << " bytes" << std::endl; - - /* grab real size */ - read = mComms->recv_blocking(chan_id, msg_body, msg_size); - if (read != msg_size) - { - /* error */ - std::cerr << "RpcMediator::recv_msg() Error Reading Body: " << bufsize; - std::cerr << " bytes" << std::endl; - - mComms->error(chan_id, "Failed to Recv MsgBody"); - return 0; - } - mServer->processMsg(chan_id, msg_id, req_id, msg_body); - - return 1; -} - - -int RpcMediator::send(uint32_t chan_id, uint32_t msg_id, uint32_t req_id, const std::string &msg) - -{ - std::cerr << "RpcMediator::send(" << msg_id << "," << req_id << ", len("; - std::cerr << msg.size() << ")) on chan_id: " << chan_id; - std::cerr << std::endl; - - uint8_t buffer[kMsgHeaderSize]; - uint32_t bufsize = kMsgHeaderSize; - uint32_t msg_size = msg.size(); - - bool okay = MsgPacker::serialiseHeader(msg_id, req_id, msg_size, buffer, bufsize); - if (!okay) - { - std::cerr << "RpcMediator::send() SerialiseHeader Failed"; - std::cerr << std::endl; - /* error */ - return 0; - } - - if (!mComms->send(chan_id, buffer, bufsize)) - { - std::cerr << "RpcMediator::send() Send Header Failed"; - std::cerr << std::endl; - /* error */ - mComms->error(chan_id, "Failed to Send Header"); - return 0; - } - - /* now send the body */ - if (!mComms->send(chan_id, msg)) - { - std::cerr << "RpcMediator::send() Send Body Failed"; - std::cerr << std::endl; - /* error */ - mComms->error(chan_id, "Failed to Send Msg"); - return 0; - } - return 1; -} - - - - -/* Msg Packing */ -int MsgPacker::headersize() -{ - return kMsgHeaderSize; -} - -#if 0 -int MsgPacker::msgsize(Message *msg) -{ - /* */ - return 0; -} - -int MsgPacker::pktsize(Message *msg) -{ - /* */ - return headersize() + msgsize(); -} -#endif - -bool MsgPacker::serialiseHeader(uint32_t msg_id, uint32_t req_id, uint32_t msg_size, uint8_t *buffer, uint32_t bufsize) -{ - /* check size */ - if (bufsize < kMsgHeaderSize) - { - return false; - } - - /* pack the data (using libretroshare serialiser for now */ - void *data = buffer; - uint32_t offset = 0; - uint32_t size = bufsize; - - bool ok = true; - - /* 4 x uint32_t for header */ - ok &= setRawUInt32(data, size, &offset, kMsgMagicCode); - ok &= setRawUInt32(data, size, &offset, msg_id); - ok &= setRawUInt32(data, size, &offset, req_id); - ok &= setRawUInt32(data, size, &offset, msg_size); - - return ok; -} - - -bool MsgPacker::deserialiseHeader(uint32_t &msg_id, uint32_t &req_id, uint32_t &msg_size, uint8_t *buffer, uint32_t bufsize) -{ - /* check size */ - if (bufsize < kMsgHeaderSize) - { - return false; - } - - /* pack the data (using libretroshare serialiser for now */ - void *data = buffer; - uint32_t offset = 0; - uint32_t size = bufsize; - uint32_t magic_code; - - bool ok = true; - - /* 4 x uint32_t for header */ - ok &= getRawUInt32(data, size, &offset, &magic_code); - if (!ok) - { - std::cerr << "Failed to deserialise uint32_t(0)"; - std::cerr << std::endl; - } - ok &= getRawUInt32(data, size, &offset, &msg_id); - if (!ok) - { - std::cerr << "Failed to deserialise uint32_t(1)"; - std::cerr << std::endl; - } - ok &= getRawUInt32(data, size, &offset, &req_id); - if (!ok) - { - std::cerr << "Failed to deserialise uint32_t(2)"; - std::cerr << std::endl; - } - ok &= getRawUInt32(data, size, &offset, &msg_size); - if (!ok) - { - std::cerr << "Failed to deserialise uint32_t(3)"; - std::cerr << std::endl; - } - - ok &= (magic_code == kMsgMagicCode); - if (!ok) - { - std::cerr << "Failed to Match MagicCode"; - std::cerr << std::endl; - } - - return ok; -} - - - diff --git a/retroshare-nogui/src/rpc/rpc.h b/retroshare-nogui/src/rpc/rpc.h deleted file mode 100644 index bdc2e8a18..000000000 --- a/retroshare-nogui/src/rpc/rpc.h +++ /dev/null @@ -1,72 +0,0 @@ -/* - * RetroShare External Interface. - * - * Copyright 2012-2012 by Robert Fernie. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public - * License Version 2.1 as published by the Free Software Foundation. - * - * This library 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 - * Library General Public License for more details. - * - * You should have received a copy of the GNU Library General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 - * USA. - * - * Please report all bugs and problems to "retroshare@lunamutt.com". - * - */ - -#ifndef RPC_MEDIATOR_H -#define RPC_MEDIATOR_H - -/* - * Interface between RpcServer and RpcComms. - */ - -#include -#include - -#include "rpcsystem.h" - -class RpcServer; - -class RpcMediator: public RpcSystem -{ -public: - - RpcMediator(RpcComms *c); - void setRpcServer(RpcServer *s) { mServer = s; } /* Must only be called during setup */ - - // Overloaded from RpcSystem. -virtual void reset(uint32_t chan_id); -virtual int tick(); - - int recv(); - int recv_msg(uint32_t chan_id); - int send(uint32_t chan_id, uint32_t msg_id, uint32_t req_id, const std::string &msg); - - int error(uint32_t chan_id, std::string msg); // pass an error up to comms level. -private: - RpcComms *mComms; - RpcServer *mServer; - -}; - - -/* Msg Packing */ -class MsgPacker -{ -public: - static int headersize(); - static bool serialiseHeader(uint32_t msg_id, uint32_t req_id, uint32_t msg_size, uint8_t *buffer, uint32_t bufsize); - static bool deserialiseHeader(uint32_t &msg_id, uint32_t &req_id, uint32_t &msg_size, uint8_t *buffer, uint32_t bufsize); -}; - - - -#endif /* RPC_MEDIATOR_H */ diff --git a/retroshare-nogui/src/rpc/rpcecho.cc b/retroshare-nogui/src/rpc/rpcecho.cc deleted file mode 100644 index b11220bb8..000000000 --- a/retroshare-nogui/src/rpc/rpcecho.cc +++ /dev/null @@ -1,40 +0,0 @@ -/* - * RetroShare External Interface. - * - * Copyright 2012-2012 by Robert Fernie. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public - * License Version 2.1 as published by the Free Software Foundation. - * - * This library 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 - * Library General Public License for more details. - * - * You should have received a copy of the GNU Library General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 - * USA. - * - * Please report all bugs and problems to "retroshare@lunamutt.com". - * - */ - -#include "rpc/rpcecho.h" - -RpcEcho::RpcEcho(uint32_t serviceId) -:RpcQueueService(serviceId) -{ - return; -} - -int RpcEcho::processMsg(uint32_t chan_id, uint32_t msg_id, uint32_t req_id, const std::string &msg) -{ - /* */ - queueResponse(chan_id, msg_id, req_id, msg); - return 1; -} - - - diff --git a/retroshare-nogui/src/rpc/rpcecho.h b/retroshare-nogui/src/rpc/rpcecho.h deleted file mode 100644 index b34446310..000000000 --- a/retroshare-nogui/src/rpc/rpcecho.h +++ /dev/null @@ -1,38 +0,0 @@ -/* - * RetroShare External Interface. - * - * Copyright 2012-2012 by Robert Fernie. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public - * License Version 2.1 as published by the Free Software Foundation. - * - * This library 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 - * Library General Public License for more details. - * - * You should have received a copy of the GNU Library General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 - * USA. - * - * Please report all bugs and problems to "retroshare@lunamutt.com". - * - */ - - -#ifndef RS_RPC_ECHO_H -#define RS_RPC_ECHO_H - -#include "rpc/rpcserver.h" - -class RpcEcho: public RpcQueueService -{ -public: - RpcEcho(uint32_t serviceId); - virtual int processMsg(uint32_t chan_id, uint32_t msg_id, uint32_t req_id, const std::string &msg); -}; - - -#endif /* RS_RPC_ECHO_H */ diff --git a/retroshare-nogui/src/rpc/rpcserver.cc b/retroshare-nogui/src/rpc/rpcserver.cc deleted file mode 100644 index a879e08df..000000000 --- a/retroshare-nogui/src/rpc/rpcserver.cc +++ /dev/null @@ -1,538 +0,0 @@ -/* - * RetroShare External Interface. - * - * Copyright 2012-2012 by Robert Fernie. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public - * License Version 2.1 as published by the Free Software Foundation. - * - * This library 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 - * Library General Public License for more details. - * - * You should have received a copy of the GNU Library General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 - * USA. - * - * Please report all bugs and problems to "retroshare@lunamutt.com". - * - */ - -#include "rpc/rpcserver.h" - -#include "rpc/rpc.h" - -#include - - - -bool operator<(const RpcUniqueId &a, const RpcUniqueId &b) -{ - if (a.mChanId == b.mChanId) - return (a.mReqId < b.mReqId); - return (a.mChanId < b.mChanId); -} - - -RpcServer::RpcServer(RpcMediator *med) - :mMediator(med), mRpcMtx("RpcMtx") -{ - -} - -void RpcServer::reset(uint32_t chan_id) -{ - std::cerr << "RpcServer::reset(" << chan_id << ")" << std::endl; - { - RsStackMutex stack(mRpcMtx); /********** LOCKED MUTEX ***************/ - - std::list::iterator it; - for(it = mAllServices.begin(); it != mAllServices.end(); it++) - { - /* in mutex, but should be okay */ - (*it)->reset(chan_id); - } - - // clear existing queue. - mRpcQueue.clear(); - } - - return; -} - -int RpcServer::error(uint32_t chan_id, std::string msg) -{ - return mMediator->error(chan_id, msg); -} - -int RpcServer::addService(RpcService *service) -{ - RsStackMutex stack(mRpcMtx); /********** LOCKED MUTEX ***************/ - - service->setRpcServer(this); - mAllServices.push_back(service); - - return 1; -} - - -int RpcServer::processMsg(uint32_t chan_id, uint32_t msg_id, uint32_t req_id, const std::string &msg) -{ - std::cerr << "RpcServer::processMsg(" << msg_id << "," << req_id; - std::cerr << ", len(" << msg.size() << ")) from channel: " << chan_id; - std::cerr << std::endl; - - { - RsStackMutex stack(mRpcMtx); /********** LOCKED MUTEX ***************/ - - std::list::iterator it; - for(it = mAllServices.begin(); it != mAllServices.end(); it++) - { - int rt = (*it)->processMsg(chan_id, msg_id, req_id, msg); - if (!rt) - continue; - - /* remember request */ - queueRequest_locked(chan_id, msg_id, req_id, (*it)); - return 1; - } - } - - std::cerr << "RpcServer::processMsg() No service to accepted it - discard"; - std::cerr << std::endl; - return 0; -} - -int RpcServer::queueRequest_locked(uint32_t chan_id, uint32_t /* msgId */, uint32_t req_id, RpcService *service) -{ - std::cerr << "RpcServer::queueRequest_locked() req_id: " << req_id; - std::cerr << std::endl; - - RpcQueuedObj obj; - obj.mChanId = chan_id; - obj.mReqId = req_id; - obj.mService = service; - - mRpcQueue.push_back(obj); - - return 1; -} - - -bool RpcServer::checkPending() -{ - std::list msgsToSend; - bool someRemaining = false; - bool someToSend = false; - - { - RsStackMutex stack(mRpcMtx); /********** LOCKED MUTEX ***************/ - - std::list::iterator it; - for(it = mRpcQueue.begin(); it != mRpcQueue.end();) - { - uint32_t out_chan_id = it->mChanId; - uint32_t out_msg_id = 0; - uint32_t out_req_id = it->mReqId; - std::string out_msg; - if (it->mService->getResponse(out_chan_id, out_msg_id, out_req_id, out_msg)) - { - std::cerr << "RpcServer::checkPending() Response: ("; - std::cerr << out_msg_id << "," << out_req_id; - std::cerr << ", len(" << out_msg.size() << "))"; - std::cerr << " for chan_id: " << out_chan_id; - std::cerr << std::endl; - - /* store and send after queue is processed */ - RpcQueuedMsg msg; - msg.mChanId = out_chan_id; - msg.mMsgId = out_msg_id; - msg.mReqId = out_req_id; - msg.mMsg = out_msg; - - msgsToSend.push_back(msg); - - it = mRpcQueue.erase(it); - someToSend = true; - } - else - { - it++; - someRemaining = true; - } - } - } - - if (someToSend) - { - sendQueuedMsgs(msgsToSend); - } - - return someRemaining; -} - - -bool RpcServer::checkEvents() -{ - std::list msgsToSend; - bool someToSend = false; - - { - RsStackMutex stack(mRpcMtx); /********** LOCKED MUTEX ***************/ - - std::list::iterator it; - for(it = mAllServices.begin(); it != mAllServices.end(); it++) - { - if ((*it)->getEvents(msgsToSend)) - someToSend = true; - } - } - - if (someToSend) - { - sendQueuedMsgs(msgsToSend); - } - return someToSend; -} - -bool RpcServer::sendQueuedMsgs(std::list &msgs) -{ - /* No need for lock, as mOut is the only accessed item - and that has own protection */ - - std::cerr << "RpcServer::sendQueuedMsg() " << msgs.size() << " to send"; - std::cerr << std::endl; - - std::list::iterator it; - for (it = msgs.begin(); it != msgs.end(); it++) - { - mMediator->send(it->mChanId, it->mMsgId, it->mReqId, it->mMsg); - } - return true; -} - - - - - - - -RpcQueueService::RpcQueueService(uint32_t serviceId) -:RpcService(serviceId), mQueueMtx("RpcQueueService") -{ - return; -} - - -void RpcQueueService::reset(uint32_t chan_id) -{ - clearEventsForChannel(chan_id); - - RsStackMutex stack(mQueueMtx); /********** LOCKED MUTEX ***************/ - - std::list toRemove; - - // iterate through and remove only chan_id items. - std::map::iterator mit; - for(mit = mResponses.begin(); mit != mResponses.end(); mit++) - { - if (mit->second.mChanId == chan_id) - toRemove.push_back(mit->first); - } - - /* remove items */ - std::list::iterator rit; - for(rit = toRemove.begin(); rit != toRemove.end(); rit++) - { - mit = mResponses.find(*rit); - mResponses.erase(mit); - } - - - return; -} - -int RpcQueueService::getResponse(uint32_t &chan_id, uint32_t &msg_id, uint32_t &req_id, std::string &msg) -{ - RsStackMutex stack(mQueueMtx); /********** LOCKED MUTEX ***************/ - - std::map::iterator it; - - RpcUniqueId uid(chan_id, req_id); - it = mResponses.find(uid); - if (it == mResponses.end()) - { - return 0; - } - - // chan_id & req_id are already set. - msg_id = it->second.mMsgId; - msg = it->second.mMsg; - - mResponses.erase(it); - - return 1; -} - -int RpcQueueService::queueResponse(uint32_t chan_id, uint32_t msg_id, uint32_t req_id, const std::string &msg) -{ - RsStackMutex stack(mQueueMtx); /********** LOCKED MUTEX ***************/ - - RpcQueuedMsg qmsg; - qmsg.mChanId = chan_id; - qmsg.mMsgId = msg_id; - qmsg.mReqId = req_id; - qmsg.mMsg = msg; - - RpcUniqueId uid(chan_id, req_id); - mResponses[uid] = qmsg; - - return 1; -} - - - - -/********* Events & Registration ******/ - - -int RpcQueueService::getEvents(std::list &events) -{ - RsStackMutex stack(mQueueMtx); /********** LOCKED MUTEX ***************/ - - std::map >::iterator it; - for(it = mEventRegister.begin(); it != mEventRegister.end(); it++) - { - locked_checkForEvents(it->first, it->second, events); - } - - if (events.empty()) - { - return 0; - } - return 1; -} - -int RpcQueueService::locked_checkForEvents(uint32_t event, const std::list ®istered, std::list & /* events */) -{ - std::cerr << "RpcQueueService::locked_checkForEvents() NOT IMPLEMENTED"; - std::cerr << std::endl; - std::cerr << "\tRegistered for Event Type: " << event; - std::cerr << std::endl; - - std::list::const_iterator it; - for(it = registered.begin(); it != registered.end(); it++) - { - std::cerr << "\t\t Channel ID: " << it->mChanId; - std::cerr << " Request ID: " << it->mReqId; - std::cerr << std::endl; - } - - return 1; -} - -int RpcQueueService::registerForEvents(uint32_t chan_id, uint32_t req_id, uint32_t event_id) -{ - std::cerr << "RpcQueueService::registerForEvents(ChanId: " << chan_id; - std::cerr << ", ReqId: " << req_id; - std::cerr << ", EventId: " << event_id; - std::cerr << ")"; - std::cerr << std::endl; - - RsStackMutex stack(mQueueMtx); /********** LOCKED MUTEX ***************/ - - std::map >::iterator mit; - mit = mEventRegister.find(event_id); - if (mit == mEventRegister.end()) - { - std::list emptyList; - mEventRegister[event_id] = emptyList; - - mit = mEventRegister.find(event_id); - } - - RpcEventRegister reg; - reg.mChanId = chan_id; - reg.mReqId = req_id; - reg.mEventId = event_id; - - mit->second.push_back(reg); - - return 1; -} - -int RpcQueueService::deregisterForEvents(uint32_t chan_id, uint32_t req_id, uint32_t event_id) -{ - std::cerr << "RpcQueueService::deregisterForEvents(ChanId: " << chan_id; - std::cerr << ", ReqId: " << req_id; - std::cerr << ", EventId: " << event_id; - std::cerr << ")"; - std::cerr << std::endl; - - RsStackMutex stack(mQueueMtx); /********** LOCKED MUTEX ***************/ - - std::map >::iterator mit; - mit = mEventRegister.find(event_id); - if (mit == mEventRegister.end()) - { - std::cerr << "RpcQueueService::deregisterForEvents() "; - std::cerr << "ERROR no EventId: " << event_id; - std::cerr << std::endl; - - return 0; - } - - bool removed = false; - std::list::iterator lit; - for(lit = mit->second.begin(); lit != mit->second.end();) - { - /* remove all matches */ - if ((lit->mReqId == req_id) && (lit->mChanId == chan_id)) - { - lit = mit->second.erase(lit); - if (removed == true) - { - std::cerr << "RpcQueueService::deregisterForEvents() "; - std::cerr << "WARNING REMOVING MULTIPLE MATCHES"; - std::cerr << std::endl; - } - removed = true; - } - else - { - lit++; - } - } - - if (mit->second.empty()) - { - std::cerr << "RpcQueueService::deregisterForEvents() "; - std::cerr << " Last Registrant for Event, removing List from Map"; - std::cerr << std::endl; - - mEventRegister.erase(mit); - } - - return 1; -} - - -int RpcQueueService::clearEventsForChannel(uint32_t chan_id) -{ - std::cerr << "RpcQueueService::clearEventsForChannel(" << chan_id; - std::cerr << ")"; - std::cerr << std::endl; - - RsStackMutex stack(mQueueMtx); /********** LOCKED MUTEX ***************/ - - std::list toMapRemove; - - std::map >::iterator mit; - for(mit = mEventRegister.begin(); mit != mEventRegister.end(); mit++) - { - std::list::iterator lit; - for(lit = mit->second.begin(); lit != mit->second.end();) - { - /* remove all matches */ - if (lit->mChanId == chan_id) - { - std::cerr << "RpcQueueService::clearEventsForChannel() "; - std::cerr << " Removing ReqId: " << lit->mReqId; - std::cerr << " for EventId: " << lit->mEventId; - std::cerr << std::endl; - - lit = mit->second.erase(lit); - } - else - { - lit++; - } - } - if (mit->second.empty()) - { - toMapRemove.push_back(mit->first); - } - } - - /* remove any empty lists now */ - std::list::iterator rit; - for(rit = toMapRemove.begin(); rit != toMapRemove.end(); rit++) - { - mit = mEventRegister.find(*rit); - mEventRegister.erase(mit); - } - - return 1; -} - - -int RpcQueueService::printEventRegister(std::ostream &out) -{ - out << "RpcQueueService::printEventRegister()"; - out << std::endl; - - RsStackMutex stack(mQueueMtx); /********** LOCKED MUTEX ***************/ - - std::list toMapRemove; - - std::map >::iterator mit; - for(mit = mEventRegister.begin(); mit != mEventRegister.end(); mit++) - { - out << "Event: " << mit->first; - out << std::endl; - - std::list::iterator lit; - for(lit = mit->second.begin(); lit != mit->second.end(); lit++) - { - out << "\tRegistrant: ReqId: " << lit->mReqId; - out << "\t ChanId: " << lit->mChanId; - out << std::endl; - } - } - return 1; -} - - - - -// Lower 8 bits. -uint8_t getRpcMsgIdSubMsg(uint32_t msg_id) -{ - return msg_id & 0xFF; -} - -// Middle 16 bits. -uint16_t getRpcMsgIdService(uint32_t msg_id) -{ - return (msg_id >> 8) & 0xFFFF; -} - -// Top 8 bits. -uint8_t getRpcMsgIdExtension(uint32_t msg_id) -{ - return (msg_id >> 24) & 0xFE; // Bottom Bit is for Request / Response -} - -bool isRpcMsgIdResponse(uint32_t msg_id) -{ - return (msg_id >> 24) & 0x01; -} - - -uint32_t constructMsgId(uint8_t ext, uint16_t service, uint8_t submsg, bool is_response) -{ - if (is_response) - ext |= 0x01; // Set Bottom Bit. - else - ext &= 0xFE; // Clear Bottom Bit. - - uint32_t msg_id = (ext << 24) + (service << 8) + (submsg); - return msg_id; -} - - - - - diff --git a/retroshare-nogui/src/rpc/rpcserver.h b/retroshare-nogui/src/rpc/rpcserver.h deleted file mode 100644 index 341086234..000000000 --- a/retroshare-nogui/src/rpc/rpcserver.h +++ /dev/null @@ -1,164 +0,0 @@ -/* - * RetroShare External Interface. - * - * Copyright 2012-2012 by Robert Fernie. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public - * License Version 2.1 as published by the Free Software Foundation. - * - * This library 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 - * Library General Public License for more details. - * - * You should have received a copy of the GNU Library General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 - * USA. - * - * Please report all bugs and problems to "retroshare@lunamutt.com". - * - */ - - -#ifndef RS_RPC_SERVER_H -#define RS_RPC_SERVER_H - -#include -#include -#include -#include - -#include "util/rsthreads.h" - -// Dividing up MsgIds into components: - -uint8_t getRpcMsgIdSubMsg(uint32_t msg_id); -uint16_t getRpcMsgIdService(uint32_t msg_id); // Middle 16 bits. -uint8_t getRpcMsgIdExtension(uint32_t msg_id); // Top 7 of 8 bits. Bottom Bit is for Request / Response -bool isRpcMsgIdResponse(uint32_t msg_id); - -uint32_t constructMsgId(uint8_t ext, uint16_t service, uint8_t submsg, bool is_response); - -/*** This can be overloaded for plugins - * Also allows a natural seperation of the full interface into sections. - */ - -// The Combination of ChanId & ReqId must be unique for each RPC call. -// This is used as an map index, so failure to make it unique, will lead to lost entries. -class RpcUniqueId -{ - public: - RpcUniqueId():mChanId(0), mReqId(0) {return;} - RpcUniqueId(uint32_t chan_id, uint32_t req_id):mChanId(chan_id), mReqId(req_id) {return;} - uint32_t mChanId; - uint32_t mReqId; -}; - -bool operator<(const RpcUniqueId &a, const RpcUniqueId &b); - -class RpcQueuedMsg -{ -public: - uint32_t mChanId; - uint32_t mMsgId; - uint32_t mReqId; - std::string mMsg; -}; - -class RpcServer; - -class RpcService -{ -public: - RpcService(uint32_t /* serviceId */ ):mRpcServer(NULL) { return; } - virtual void reset(uint32_t /* chan_id */) { return; } - virtual int msgsAccepted(std::list & /* msgIds */) { return 0; } /* not used at the moment */ - virtual int processMsg(uint32_t chan_id, uint32_t msg_id, uint32_t req_id, const std::string &msg) = 0; /* returns 0 - not handled, > 0, accepted */ - virtual int getResponse(uint32_t &chan_id, uint32_t &msgId, uint32_t &req_id, std::string &msg) = 0; /* 0 - not ready, > 0 heres the response */ - - virtual int getEvents(std::list & /* events */) { return 0; } /* 0 = none, optional feature */ - - void setRpcServer(RpcServer *server) {mRpcServer = server; } - RpcServer *getRpcServer() { return mRpcServer; } -private: - RpcServer *mRpcServer; -}; - - -class RpcEventRegister -{ - public: - uint32_t mChanId; - uint32_t mReqId; - uint32_t mEventId; // THIS IS A LOCAL PARAMETER, Service Specific -}; - -/* Implements a Queue for quick implementation of Instant Response Services */ -class RpcQueueService: public RpcService -{ -public: - RpcQueueService(uint32_t serviceId); -virtual void reset(uint32_t chan_id); -virtual int getResponse(uint32_t &chan_id, uint32_t &msg_id, uint32_t &req_id, std::string &msg); -virtual int getEvents(std::list &events); - -protected: - int queueResponse(uint32_t chan_id, uint32_t msgId, uint32_t req_id, const std::string &msg); - -virtual int locked_checkForEvents(uint32_t event, const std::list ®istered, std::list &events); // Overload for functionality. - - int registerForEvents(uint32_t chan_id, uint32_t req_id, uint32_t event_id); - int deregisterForEvents(uint32_t chan_id, uint32_t req_id, uint32_t event_id); - - int clearEventsForChannel(uint32_t chan_id); - int printEventRegister(std::ostream &out); - -private: - RsMutex mQueueMtx; - - std::map mResponses; - std::map > mEventRegister; -}; - - -/* For Tracking responses */ -class RpcQueuedObj -{ -public: - uint32_t mChanId; - uint32_t mReqId; - RpcService *mService; -}; - - -class RpcMediator; - -class RpcServer -{ - -public: - RpcServer(RpcMediator *med); - int addService(RpcService *service); - int processMsg(uint32_t chan_id, uint32_t msg_id, uint32_t req_id, const std::string &msg); - bool checkPending(); - bool checkEvents(); - - void reset(uint32_t chan_id); - int error(uint32_t chan_id, std::string msg); // pass an error to mediator. - -private: - bool sendQueuedMsgs(std::list &msgs); - int queueRequest_locked(uint32_t chan_id, uint32_t msg_id, uint32_t req_id, RpcService *service); - - RpcMediator *mMediator; - - RsMutex mRpcMtx; - - std::list mRpcQueue; - std::list mAllServices; -}; - - -#endif /* RS_RPC_SERVER_H */ diff --git a/retroshare-nogui/src/rpc/rpcsetup.cc b/retroshare-nogui/src/rpc/rpcsetup.cc deleted file mode 100644 index 0db9a786d..000000000 --- a/retroshare-nogui/src/rpc/rpcsetup.cc +++ /dev/null @@ -1,68 +0,0 @@ -/* - * RetroShare External Interface. - * - * Copyright 2012-2012 by Robert Fernie. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public - * License Version 2.1 as published by the Free Software Foundation. - * - * This library 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 - * Library General Public License for more details. - * - * You should have received a copy of the GNU Library General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 - * USA. - * - * Please report all bugs and problems to "retroshare@lunamutt.com". - * - */ - -#include "rpc/rpcsetup.h" -#include "rpc/rpcserver.h" - -#include "rpc/proto/rpcprotopeers.h" -#include "rpc/proto/rpcprotosystem.h" -#include "rpc/proto/rpcprotochat.h" -#include "rpc/proto/rpcprotosearch.h" -#include "rpc/proto/rpcprotofiles.h" -#include "rpc/proto/rpcprotostream.h" - -#include "rpc/rpcecho.h" - -RpcMediator *CreateRpcSystem(RpcComms *comms, NotifyTxt *notify) -{ - RpcMediator *med = new RpcMediator(comms); - RpcServer *server = new RpcServer(med); - - /* add services */ - RpcProtoPeers *peers = new RpcProtoPeers(1); - server->addService(peers); - - RpcProtoSystem *system = new RpcProtoSystem(1); - server->addService(system); - - RpcProtoChat *chat = new RpcProtoChat(1); - server->addService(chat); - - RpcProtoSearch *search = new RpcProtoSearch(1, notify); - server->addService(search); - - RpcProtoFiles *files = new RpcProtoFiles(1); - server->addService(files); - - RpcProtoStream *streamer = new RpcProtoStream(1); - server->addService(streamer); - - /* Finally an Echo Service - which will echo back any unprocesses commands. */ - RpcEcho *echo = new RpcEcho(1); - server->addService(echo); - - med->setRpcServer(server); - - return med; -} - diff --git a/retroshare-nogui/src/rpc/rpcsetup.h b/retroshare-nogui/src/rpc/rpcsetup.h deleted file mode 100644 index b95193f87..000000000 --- a/retroshare-nogui/src/rpc/rpcsetup.h +++ /dev/null @@ -1,36 +0,0 @@ -/* - * RetroShare External Interface. - * - * Copyright 2012-2012 by Robert Fernie. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public - * License Version 2.1 as published by the Free Software Foundation. - * - * This library 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 - * Library General Public License for more details. - * - * You should have received a copy of the GNU Library General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 - * USA. - * - * Please report all bugs and problems to "retroshare@lunamutt.com". - * - */ - - -#ifndef RPC_SETUP_H -#define RPC_SETUP_H - - -#include "rpc/rpc.h" - -class NotifyTxt; - -RpcMediator *CreateRpcSystem(RpcComms *comms, NotifyTxt *notify); - -#endif - diff --git a/retroshare-nogui/src/rpcsystem.h b/retroshare-nogui/src/rpcsystem.h deleted file mode 100644 index dd1ccfc43..000000000 --- a/retroshare-nogui/src/rpcsystem.h +++ /dev/null @@ -1,64 +0,0 @@ -/* - * RetroShare External Interface. - * - * Copyright 2012-2012 by Robert Fernie. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public - * License Version 2.1 as published by the Free Software Foundation. - * - * This library 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 - * Library General Public License for more details. - * - * You should have received a copy of the GNU Library General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 - * USA. - * - * Please report all bugs and problems to "retroshare@lunamutt.com". - * - */ - - -#ifndef RS_RPC_SYSTEM_H -#define RS_RPC_SYSTEM_H - -#include -#include -#include - -class RpcComms -{ -public: - virtual int isOkay() = 0; - virtual int error(uint32_t chan_id, std::string msg) = 0; - - virtual int active_channels(std::list &chan_ids) = 0; - - virtual int recv_ready(uint32_t chan_id) = 0; - virtual int recv(uint32_t chan_id, uint8_t *buffer, int bytes) = 0; - virtual int recv(uint32_t chan_id, std::string &buffer, int bytes) = 0; - - // these make it easier... - virtual int recv_blocking(uint32_t chan_id, uint8_t *buffer, int bytes) = 0; - virtual int recv_blocking(uint32_t chan_id, std::string &buffer, int bytes) = 0; - - virtual int send(uint32_t chan_id, uint8_t *buffer, int bytes) = 0; - virtual int send(uint32_t chan_id, const std::string &buffer) = 0; - - virtual int setSleepPeriods(float /* busy */, float /* idle */) { return 0; } -}; - - -class RpcSystem -{ -public: - /* this must be regularly ticked to update the display */ - virtual void reset(uint32_t chan_id) = 0; - virtual int tick() = 0; -}; - - -#endif // RS_RPC_SERVER_H diff --git a/retroshare-nogui/src/ssh/rssshd.cc b/retroshare-nogui/src/ssh/rssshd.cc deleted file mode 100644 index c4d8082aa..000000000 --- a/retroshare-nogui/src/ssh/rssshd.cc +++ /dev/null @@ -1,913 +0,0 @@ -/* This is a sample implementation of a libssh based SSH server */ -/* -Copyright 2003-2009 Aris Adamantiadis - -This file is part of the SSH Library - -You are free to copy this file, modify it in any way, consider it being public -domain. This does not apply to the rest of the library though, but it is -allowed to cut-and-paste working code from this file to any license of -program. -The goal is to show the API in action. It's not a reference on how terminal -clients must be made or how a client should react. -*/ - -/***** - * Heavily Modified by Robert Fernie 2012... for retroshare project! - * - */ - - -#include - -#include "ssh/rssshd.h" - -#include - -#define RSSSHD_STATE_NULL 0 -#define RSSSHD_STATE_INIT_OK 1 -#define RSSSHD_STATE_CONNECTED 2 -#define RSSSHD_STATE_ERROR 3 - -RsSshd *rsSshd = NULL; // External Reference Variable. - -// NB: This must be called EARLY before all the threads are launched. -RsSshd *RsSshd::InitRsSshd(const std::string &portStr, const std::string &rsakeyfile) -{ -#if LIBSSH_VERSION_INT >= SSH_VERSION_INT(0,5,0) - ssh_threads_set_callbacks(ssh_threads_get_pthread()); -#endif - ssh_init(); - - rsSshd = new RsSshd(portStr); - if (rsSshd->init(rsakeyfile)) - { - return rsSshd; - } - - rsSshd = NULL; - return rsSshd; -} - - -RsSshd::RsSshd(std::string portStr) -:mSshMtx("sshMtx"), mPortStr(portStr), mChannel(0) -{ - - mState = RSSSHD_STATE_NULL; - mBindState = 0; - mRpcSystem = NULL; - - mSession = NULL; - - setSleepPeriods(0.01, 0.1); - return; -} - - - -int RsSshd::init(const std::string &pathrsakey) -{ - - mBind=ssh_bind_new(); - - //ssh_bind_options_set(mBind, SSH_BIND_OPTIONS_DSAKEY, KEYS_FOLDER "ssh_host_dsa_key"); - //ssh_bind_options_set(mBind, SSH_BIND_OPTIONS_RSAKEY, KEYS_FOLDER "ssh_host_rsa_key"); - - //ssh_bind_options_set(mBind, SSH_BIND_OPTIONS_BINDPORT_STR, arg); - ssh_bind_options_set(mBind, SSH_BIND_OPTIONS_BINDPORT_STR, mPortStr.c_str()); - //ssh_bind_options_set(mBind, SSH_BIND_OPTIONS_DSAKEY, arg); - //ssh_bind_options_set(mBind, SSH_BIND_OPTIONS_HOSTKEY, arg); - ssh_bind_options_set(mBind, SSH_BIND_OPTIONS_RSAKEY, pathrsakey.c_str()); - //ssh_bind_options_set(mBind, SSH_BIND_OPTIONS_LOG_VERBOSITY_STR, "3"); - - mState = RSSSHD_STATE_INIT_OK; - mBindState = 0; - - return 1; -} - - -void RsSshd::run() -{ - /* main loop */ - - /* listen */ - bool sshOk = true; - while(sshOk) - { - std::cerr << "RsSshd::run() starting sshd cycle"; - std::cerr << std::endl; - - if (listenConnect()) - { - std::cerr << "RsSshd::run() success connect => setup mSession"; - std::cerr << std::endl; - - if (setupSession()) - { - std::cerr << "RsSshd::run() setup mSession => interactive"; - std::cerr << std::endl; - - mState = RSSSHD_STATE_CONNECTED; - interactive(); - } - else - { - std::cerr << "RsSshd::run() setup mSession failed"; - std::cerr << std::endl; - } - } - cleanupSession(); -#ifndef WINDOWS_SYS - sleep(5); // have a break; -#else - Sleep(5000); // have a break; -#endif - } -} - - -int RsSshd::listenConnect() -{ - std::cerr << "RsSshd::listenConnect()"; - std::cerr << std::endl; - - if (!mBindState) - { - if(ssh_bind_listen(mBind)<0) - { - printf("Error listening to socket: %s\n",ssh_get_error(mBind)); - return 0; - } - mBindState = 1; - } - else - { - std::cerr << "RsSshd::listenConnect() Already Bound..."; - std::cerr << std::endl; - } - - mSession=ssh_new(); - int r=ssh_bind_accept(mBind,mSession); - if(r==SSH_ERROR) - { - printf("error accepting a connection : %s\n",ssh_get_error(mBind)); - return 0; - } - -#if LIBSSH_VERSION_INT >= SSH_VERSION_INT(0,5,0) - if (ssh_handle_key_exchange(mSession)) -#else - if (ssh_accept(mSession)) -#endif - { - printf("ssh_handle_key_exchange: %s\n", ssh_get_error(mSession)); - return 0; - } - return 1; -} - - -int RsSshd::setupSession() -{ - std::cerr << "RsSshd::listenConnect()"; - std::cerr << std::endl; - - if (authUser()) - { - std::cerr << "RsSshd::listenConnect() authUser SUCCESS"; - std::cerr << std::endl; - - if (setupChannel()) - { - std::cerr << "RsSshd::listenConnect() setupChannel SUCCESS"; - std::cerr << std::endl; - - if (setupShell()) - { - std::cerr << "RsSshd::listenConnect() setupShell SUCCESS"; - std::cerr << std::endl; - - return 1; - } - } - } - std::cerr << "RsSshd::listenConnect() Failed"; - std::cerr << std::endl; - - return 0; -} - - -int RsSshd::interactive() -{ - std::cerr << "RsSshd::interactive()"; - std::cerr << std::endl; - - doRpcSystem(); - //doEcho(); - return 1; -} - - - -int RsSshd::authUser() -{ - std::cerr << "RsSshd::authUser()"; - std::cerr << std::endl; - - - ssh_message message; - int auth = 0; - - do { - message=ssh_message_get(mSession); - if(!message) - break; - switch(ssh_message_type(message)){ - case SSH_REQUEST_AUTH: - switch(ssh_message_subtype(message)){ - case SSH_AUTH_METHOD_PASSWORD: - printf("User %s wants to auth with pass %s\n", - ssh_message_auth_user(message), - ssh_message_auth_password(message)); - if(auth_password(ssh_message_auth_user(message), - ssh_message_auth_password(message))){ - auth=1; - ssh_message_auth_reply_success(message,0); - break; - } - // not authenticated, send default message - case SSH_AUTH_METHOD_NONE: - default: - ssh_message_auth_set_methods(message,SSH_AUTH_METHOD_PASSWORD); - ssh_message_reply_default(message); - break; - } - break; - default: - ssh_message_reply_default(message); - } - ssh_message_free(message); - } while (!auth); - - if(!auth){ - printf("auth error: %s\n",ssh_get_error(mSession)); - ssh_disconnect(mSession); - return 0; - } - - std::cerr << "RsSshd::authuser() Success"; - std::cerr << std::endl; - - return 1; -} - - -int RsSshd::setupChannel() -{ - std::cerr << "RsSshd::setupChannel()"; - std::cerr << std::endl; - - ssh_message message; - - - do { - message=ssh_message_get(mSession); - if(message){ - switch(ssh_message_type(message)){ - case SSH_REQUEST_CHANNEL_OPEN: - if(ssh_message_subtype(message)==SSH_CHANNEL_SESSION){ - mChannel=ssh_message_channel_request_open_reply_accept(message); - break; - } - default: - ssh_message_reply_default(message); - } - ssh_message_free(message); - } - } while(message && !mChannel); - if(!mChannel){ - printf("error : %s\n",ssh_get_error(mSession)); - ssh_finalize(); - return 0; - } - - return 1; -} - - -int RsSshd::setupShell() -{ - std::cerr << "RsSshd::setupShell()"; - std::cerr << std::endl; - - int shell = 0; - ssh_message message; - - do { - message=ssh_message_get(mSession); - if(message && ssh_message_type(message)==SSH_REQUEST_CHANNEL && - ssh_message_subtype(message)==SSH_CHANNEL_REQUEST_SHELL){ - shell = 1; - ssh_message_channel_request_reply_success(message); - break; - } - if(!shell){ - ssh_message_reply_default(message); - } - ssh_message_free(message); - } while (message && !shell); - - if(!shell){ - printf("error : %s\n",ssh_get_error(mSession)); - return 0; - } - - return 1; -} - -// CLEANUP -int RsSshd::cleanupSession() -{ - std::cerr << "RsSshd::cleanupSession()"; - std::cerr << std::endl; - - ssh_disconnect(mSession); - ssh_free(mSession); - return 1; -} - - -int RsSshd::cleanupAll() -{ - std::cerr << "RsSshd::cleanupAll()"; - std::cerr << std::endl; - - cleanupSession(); - if (mBindState) - { - ssh_bind_free(mBind); - mBindState = 0; - } - ssh_finalize(); - return 1; -} - - - -// Various Operating Modes. -int RsSshd::doEcho() -{ - std::cerr << "RsSshd::doEcho()"; - std::cerr << std::endl; - int i = 0; - char buf[2048]; - - do{ -#if LIBSSH_VERSION_INT >= SSH_VERSION_INT(0,5,0) - i=ssh_channel_read(mChannel,buf, 2048, 0); -#else - i=channel_read(mChannel,buf, 2048, 0); -#endif - if(i>0) { -#if LIBSSH_VERSION_INT >= SSH_VERSION_INT(0,5,0) - ssh_channel_write(mChannel, buf, i); - ssh_channel_write(mChannel, buf, i); -#else - channel_write(mChannel, buf, i); - channel_write(mChannel, buf, i); -#endif - if (write(1,buf,i) < 0) { - printf("error writing to buffer\n"); - return 0; - } - } - } while (i>0); - - std::cerr << "RsSshd::doEcho() Finished"; - std::cerr << std::endl; - - return 1; -} - - -int RsSshd::setRpcSystem(RpcSystem *s) -{ - mRpcSystem = s; - return 1; -} - - -#if 0 - -int RsSshd::doTermServer() -{ - std::cerr << "RsSshd::doTermServer()"; - std::cerr << std::endl; - - if (!mTermServer) - { - std::cerr << "RsSshd::doTermServer() ERROR Not Set"; - std::cerr << std::endl; - return 0; - } - - mTermServer->reset(); // clear everything for new user. - - bool okay = true; - while(okay) - { - char buf; -#if LIBSSH_VERSION_INT >= SSH_VERSION_INT(0,5,0) - int size = ssh_channel_read_nonblocking(mChannel, &buf, 1, 0); -#else - int size = channel_read_nonblocking(mChannel, &buf, 1, 0); -#endif - bool haveInput = (size > 0); - std::string output; - - int rt = mTermServer->tick(haveInput, buf, output); - - if (output.size() > 0) - { -#if LIBSSH_VERSION_INT >= SSH_VERSION_INT(0,5,0) - ssh_channel_write(mChannel, output.c_str(), output.size()); -#else - channel_write(mChannel, output.c_str(), output.size()); -#endif - } - - if (!haveInput) - { - /* have a little sleep */ - sleep(1); //0000000); // 1/10th sec. - //usleep(10000000); // 1/10th sec. - } - else - { - usleep(10000); // 1/100th sec. - } - - if (rt < 0) - { - okay = false; // exit. - } - } - - std::cerr << "RsSshd::doTermServer() Finished"; - std::cerr << std::endl; - - return 1; -} - -#endif - - -int RsSshd::doRpcSystem() -{ - std::cerr << "RsSshd::doRpcSystem()"; - std::cerr << std::endl; - - if (!mRpcSystem) - { - std::cerr << "RsSshd::doRpcSystem() ERROR Not Set"; - std::cerr << std::endl; - return 0; - } - - uint32_t dummy_chan_id = 1; - mRpcSystem->reset(dummy_chan_id); // clear everything for new user. - - bool okay = true; - while(okay) - { - int rt = mRpcSystem->tick(); - if (rt) - { - // Working - so small sleep, - usleep(mBusyUSleep); - } - else - { - // No work cycle, longer break. - usleep(mIdleUSleep); - } - - if (rt < 0) - { - okay = false; // exit. - } - - if (!isOkay()) - { - okay = false; - } - } - - mRpcSystem->reset(dummy_chan_id); // cleanup old channel items. - - std::cerr << "RsSshd::doRpcSystem() Finished"; - std::cerr << std::endl; - - return 1; -} - -// RpcComms Interface.... -int RsSshd::isOkay() -{ - return (mState == RSSSHD_STATE_CONNECTED); -} - - std::list::iterator it; -int RsSshd::active_channels(std::list &chan_ids) -{ - if (isOkay()) - { - chan_ids.push_back(1); // dummy for now. - } - - return 1; -} - -int RsSshd::error(uint32_t chan_id, std::string msg) -{ - std::cerr << "RsSshd::error(" << msg << ")"; - std::cerr << std::endl; - - mState = RSSSHD_STATE_ERROR; - return 1; -} - - -int RsSshd::recv_ready(uint32_t chan_id) -{ - int bytes = ssh_channel_poll(mChannel, 0); - return bytes; -} - - -int RsSshd::recv(uint32_t chan_id, uint8_t *buffer, int bytes) -{ -#if LIBSSH_VERSION_INT >= SSH_VERSION_INT(0,5,0) - int size = ssh_channel_read_nonblocking(mChannel, buffer, bytes, 0); -#else - int size = channel_read_nonblocking(mChannel, buffer, bytes, 0); -#endif - return size; -} - - -int RsSshd::recv(uint32_t chan_id, std::string &buffer, int bytes) -{ - char input[bytes]; -#if LIBSSH_VERSION_INT >= SSH_VERSION_INT(0,5,0) - int size = ssh_channel_read_nonblocking(mChannel, input, bytes, 0); -#else - int size = channel_read_nonblocking(mChannel, input, bytes, 0); -#endif - for(int i = 0; i < size; i++) - { - buffer += input[i]; - } - return size; -} - - -int RsSshd::recv_blocking(uint32_t chan_id, uint8_t *buffer, int bytes) -{ -#if LIBSSH_VERSION_INT >= SSH_VERSION_INT(0,5,0) - int size = ssh_channel_read(mChannel, buffer, bytes, 0); -#else - int size = channel_read(mChannel, buffer, bytes, 0); -#endif - return size; -} - - -int RsSshd::recv_blocking(uint32_t chan_id, std::string &buffer, int bytes) -{ - char input[bytes]; -#if LIBSSH_VERSION_INT >= SSH_VERSION_INT(0,5,0) - int size = ssh_channel_read(mChannel, input, bytes, 0); -#else - int size = channel_read(mChannel, input, bytes, 0); -#endif - for(int i = 0; i < size; i++) - { - buffer += input[i]; - } - return size; -} - -int RsSshd::send(uint32_t chan_id, uint8_t *buffer, int bytes) -{ -#if LIBSSH_VERSION_INT >= SSH_VERSION_INT(0,5,0) - ssh_channel_write(mChannel, buffer, bytes); -#else - channel_write(mChannel, buffer, bytes); -#endif - return 1; -} - -int RsSshd::send(uint32_t chan_id, const std::string &buffer) -{ -#if LIBSSH_VERSION_INT >= SSH_VERSION_INT(0,5,0) - ssh_channel_write(mChannel, buffer.c_str(), buffer.size()); -#else - channel_write(mChannel, buffer.c_str(), buffer.size()); -#endif - return 1; -} - -int RsSshd::setSleepPeriods(float busy, float idle) -{ - mBusyUSleep = busy * 1000000; - mIdleUSleep = idle * 1000000; - return 1; -} - - - -/***********************************************************************************/ - /* PASSWORDS */ -/***********************************************************************************/ - -int RsSshd::auth_password(const char *name, const char *pwd) -{ -#ifdef ALLOW_CLEARPWDS - if (auth_password_basic(name, pwd)) - return 1; -#endif // ALLOW_CLEARPWDS - - if (auth_password_hashed(name, pwd)) - return 1; - return 0; -} - -#define RSSSHD_MIN_PASSWORD 4 -#define RSSSHD_MIN_USERNAME 3 - -#ifdef ALLOW_CLEARPWDS -int RsSshd::adduser(std::string username, std::string password) -{ - if (password.length() < RSSSHD_MIN_PASSWORD) - { - std::cerr << "RsSshd::adduser() Password Too Short"; - return 0; - } - - if (username.length() < RSSSHD_MIN_USERNAME) - { - std::cerr << "RsSshd::adduser() Password Too Short"; - return 0; - } - - std::map::iterator it; - it = mPasswords.find(username); - if (it != mPasswords.end()) - { - std::cerr << "RsSshd::adduser() Warning username already exists"; - } - - mPasswords[username] = password; - - return 1; -} - - -int RsSshd::auth_password_basic(char *name, char *pwd) -{ - std::string username(name); - std::string password(pwd); - - std::map::iterator it; - it = mPasswords.find(username); - if (it == mPasswords.end()) - { - std::cerr << "RsSshd::auth_password() Unknown username"; - return 0; - } - - if (it->second == password) - { - std::cerr << "RsSshd::auth_password() logged in " << username; - return 1; - } - - std::cerr << "RsSshd::auth_password() Invalid pwd for " << username; - return 0; -} -#endif // ALLOW_CLEARPWDS - -//#define RSSSHD_HASH_PWD_LENGTH 40 - -int RsSshd::adduserpwdhash(std::string username, std::string hash) -{ -#if 0 - if (hash.length() != RSSSHD_HASH_PWD_LENGTH) - { - std::cerr << "RsSshd::adduserpwdhash() Hash Wrong Length"; - return 0; - } -#endif - - if (username.length() < RSSSHD_MIN_USERNAME) - { - std::cerr << "RsSshd::adduserpwdhash() Username Too Short"; - return 0; - } - - std::map::iterator it; - it = mPwdHashs.find(username); - if (it != mPwdHashs.end()) - { - std::cerr << "RsSshd::adduser() Warning username already exists"; - } - - mPwdHashs[username] = hash; - - return 1; -} - - -int RsSshd::auth_password_hashed(const char *name, const char *pwd) -{ - std::string username(name); - std::string password(pwd); - - std::map::iterator it; - it = mPwdHashs.find(username); - if (it == mPwdHashs.end()) - { - std::cerr << "RsSshd::auth_password_hashed() Unknown username"; - return 0; - } - - if (CheckPasswordHash(it->second, password)) - { - std::cerr << "RsSshd::auth_password_hashed() logged in " << username; - return 1; - } - - std::cerr << "RsSshd::auth_password_hashed() Invalid pwd for " << username; - return 0; -} - -#include "util/radix64.h" -#include "util/rsrandom.h" -#include - -#define RSSSHD_PWD_SALT_LEN 16 -#define RSSSHD_PWD_MIN_LEN 8 - - -#if 0 -int printHex(const char *data, int len) -{ - for(int i = 0; i < len; i++) - { - fprintf(stderr, "%02x", (uint8_t) data[i]); - } - return 1; -} -#endif - - - -int GenerateSalt(std::string &saltBin) -{ - /* get from random */ - for(int i = 0; i < RSSSHD_PWD_SALT_LEN / 4; i++) - { - uint32_t rnd = RSRandom::random_u32(); - saltBin += ((char *) &rnd)[0]; - saltBin += ((char *) &rnd)[1]; - saltBin += ((char *) &rnd)[2]; - saltBin += ((char *) &rnd)[3]; - } - -#if 0 - std::cerr << "HexSalt: "; - printHex(saltBin.c_str(), saltBin.size()); - std::cerr << std::endl; -#endif - - return 1; -} - -int GeneratePasswordHash(std::string saltBin, std::string password, std::string &pwdHashRadix64) -{ -#if 0 - std::cerr << "GeneratePasswordHash()"; - std::cerr << std::endl; - - std::cerr << "HexSalt: "; - printHex(saltBin.c_str(), saltBin.size()); - std::cerr << std::endl; -#endif - - if (saltBin.size() != RSSSHD_PWD_SALT_LEN) - { - return 0; - } - - if (password.size() < RSSSHD_PWD_MIN_LEN) - { - return 0; - } - - EVP_MD_CTX *ctx = EVP_MD_CTX_create(); - EVP_DigestInit(ctx, EVP_sha256()); - - EVP_DigestUpdate(ctx, saltBin.c_str(), saltBin.size()); - EVP_DigestUpdate(ctx, password.c_str(), password.size()); - - - unsigned char hash[1024]; - unsigned int s = 1024 - RSSSHD_PWD_SALT_LEN; - - for(int i = 0; i < RSSSHD_PWD_SALT_LEN; i++) - { - hash[i] = saltBin[i]; - } - - EVP_DigestFinal(ctx, &(hash[RSSSHD_PWD_SALT_LEN]), &s); - - Radix64::encode((char *)hash, s + RSSSHD_PWD_SALT_LEN, pwdHashRadix64); - -#if 0 - std::cerr << "Salt Length: " << RSSSHD_PWD_SALT_LEN; - std::cerr << std::endl; - std::cerr << "Hash Length: " << s; - std::cerr << std::endl; - std::cerr << "Total Length: " << s + RSSSHD_PWD_SALT_LEN; - std::cerr << std::endl; - - - std::cerr << "Encoded Length: " << pwdHashRadix64.size(); - std::cerr << std::endl; - - std::cerr << "GeneratePasswordHash() Output: " << pwdHashRadix64; - std::cerr << std::endl; -#endif - - return 1; -} - - -int CheckPasswordHash(std::string pwdHashRadix64, std::string password) -{ - char output[1024]; - std::vector buf = Radix64::decode(pwdHashRadix64); - size_t len = buf.size(); - for(unsigned int i = 0; (i < len) && (i < 1024); i++) - { - output[i] = buf[i]; - } - -#if 0 - std::cerr << "CheckPasswordHash() Input: " << pwdHashRadix64; - std::cerr << std::endl; - std::cerr << "Decode Length: " << len; - std::cerr << std::endl; - std::cerr << "HexDecoded: "; - printHex(output, len); - std::cerr << std::endl; -#endif - - /* first N bytes are SALT */ - EVP_MD_CTX *ctx = EVP_MD_CTX_create(); - EVP_DigestInit(ctx, EVP_sha256()); - - EVP_DigestUpdate(ctx, output, RSSSHD_PWD_SALT_LEN); - EVP_DigestUpdate(ctx, password.c_str(), password.size()); - -#if 0 - std::cerr << "HexSalt: "; - printHex(output, RSSSHD_PWD_SALT_LEN); - std::cerr << std::endl; -#endif - - unsigned char hash[128]; - unsigned int s = 128; - EVP_DigestFinal(ctx, hash, &s); - - /* Final Comparison */ - if (s != len - RSSSHD_PWD_SALT_LEN) - { - std::cerr << "Length Mismatch"; - return 0; - } - - if (0 == strncmp(&(output[RSSSHD_PWD_SALT_LEN]), (char *) hash, s)) - { - return 1; - } - - return 0; -} - - - diff --git a/retroshare-nogui/src/ssh/rssshd.h b/retroshare-nogui/src/ssh/rssshd.h deleted file mode 100644 index 0f28ddffd..000000000 --- a/retroshare-nogui/src/ssh/rssshd.h +++ /dev/null @@ -1,157 +0,0 @@ -/* This is a sample implementation of a libssh based SSH server */ -/* -Copyright 2003-2009 Aris Adamantiadis - -This file is part of the SSH Library - -You are free to copy this file, modify it in any way, consider it being public -domain. This does not apply to the rest of the library though, but it is -allowed to cut-and-paste working code from this file to any license of -program. -The goal is to show the API in action. It's not a reference on how terminal -clients must be made or how a client should react. -*/ - -/***** - * Heavily Modified by Robert Fernie 2012... for retroshare project! - * - */ - - -#ifndef RS_SSHD_INTERFACE_H -#define RS_SSHD_INTERFACE_H - -#include -#include - -#include -#include -#include - -// From inside libretroshare.a -#include "util/rsthreads.h" - -#include -#include - -#include "rpcsystem.h" - -#ifndef KEYS_FOLDER -#ifdef _WIN32 -#define KEYS_FOLDER -#else -#define KEYS_FOLDER "/etc/ssh/" -#endif -#endif - - - -/****** - * - * Minimal Options to start with - * - */ - - - -//#define ALLOW_CLEARPWDS 1 - -class RsSshd; -extern RsSshd *rsSshd; - - - // TODO: NB: THIS FN DOES NOT USE A "SLOW" HASH FUNCTION. - // THE FIRST HALF OF THE HASH STRING IS THE SALT -int CheckPasswordHash(std::string pwdHashRadix64, std::string password); -int GeneratePasswordHash(std::string saltBin, std::string password, std::string &pwdHashRadix64); -int GenerateSalt(std::string &saltBin); - -class RsSshd: public RsThread, public RpcComms -{ -public: - -// NB: This must be called EARLY before all the threads are launched. -static RsSshd *InitRsSshd(const std::string& portStr, const std::string &rsakeyfile); - - - // Interface. -int setRpcSystem(RpcSystem *s); -int adduserpwdhash(std::string username, std::string hash); - - // RsThreads Interface. - virtual void run(); /* called once the thread is started */ - - // RsComms Interface. - virtual int isOkay(); - virtual int error(uint32_t chan_id, std::string msg); - - virtual int active_channels(std::list &chan_ids); - virtual int recv_ready(uint32_t chan_id); - - virtual int recv(uint32_t chan_id, uint8_t *buffer, int bytes); - virtual int recv(uint32_t chan_id, std::string &buffer, int bytes); - virtual int recv_blocking(uint32_t chan_id, uint8_t *buffer, int bytes); - virtual int recv_blocking(uint32_t chan_id, std::string &buffer, int bytes); - - virtual int send(uint32_t chan_id, uint8_t *buffer, int bytes); - virtual int send(uint32_t chan_id, const std::string &buffer); - - virtual int setSleepPeriods(float busy, float idle); - -private: - RsSshd(std::string portStr); /* private constructor => so can only create with */ - -int init(const std::string &pathrsakey); - - // High level operations. -int listenConnect(); -int setupSession(); -int interactive(); - - // Lower Level Operations. -int authUser(); -int setupChannel(); -int setupShell(); -int doEcho(); - - // Terminal Handling! -//int doTermServer(); -int doRpcSystem(); - -int cleanupSession(); -int cleanupAll(); - - /* Password Checking */ -int auth_password(const char *name, const char *pwd); -int auth_password_hashed(const char *name, const char *pwd); -#ifdef ALLOW_CLEARPWDS -int auth_password_basic(char *name, char *pwd); -#endif // ALLOW_CLEARPWDS - - // DATA. - - RsMutex mSshMtx; - - uint32_t mBusyUSleep; - uint32_t mIdleUSleep; - - uint32_t mState; - uint32_t mBindState; - - std::string mPortStr; - ssh_session mSession; - ssh_bind mBind; - ssh_channel mChannel; - - RpcSystem *mRpcSystem; - -#ifdef ALLOW_CLEARPWDS - std::map mPasswords; -#endif // ALLOW_CLEARPWDS - std::map mPwdHashs; - -}; - - -#endif - diff --git a/rsctrl/src/NOTES.txt b/rsctrl/src/NOTES.txt deleted file mode 100644 index a06f35ce2..000000000 --- a/rsctrl/src/NOTES.txt +++ /dev/null @@ -1,60 +0,0 @@ - -This document proposes the finer details of how to communicate with RS, -using SSH and protobuf classes. -========================================================================== - -Message Format -==================== - -Protobuf serialisation does not identify Message Types or Message Size. -So we need to have an encapsulation header system - -These headers describe the actual message via a MsgId and MsgSize. -Care must be taken to ensure these IDS are correct, as this is NOT enforced -by protobuf, and will lead to incorrect deserialisation! - -In Each .proto there is a list of MsgIds as an ENUM. - -The protocol message format is as follows: - [HEADER: 16 bytes: 4 x Network Order uint32_t][ VARIABLE LENGTH BODY ] - - [ MAGIC_CODE ] [ MSG_ID ] [ REQ_ID ] [ BODY_SIZE ] [ ..... BODY ..... ] - MagicCode = 0x137f0001. will be incremented for new versions of the protocol. - MsgID = Corresponds to the format of the Body. - ReqID = Generated by Requester, Returned in Response, - make sure its unique. (undefined behaviour for duplicates) - BodySize = Byte Length of Body. - - The Body will consist of a protobuf encoded message. - - -Usage -================= - * Create SSH connection to retroshare-nogui. - * Create Request Message(s), and send over SSH channel - You can send as meny requests as you want. - * They will processed, and responses sent back (potentially in an arbitary order). - -MsgIDs -================= -In Each .proto there is a list of MsgIds as an ENUM. - -0x00 XX XX xx => Reserved for libretroshare Requests. (XX - area, xxxx specific msg) -0x01 XX XX xx => Reserved for libretroshare Responses - -eg. 0x00 (fa bc) [01] -> Request, 0x01 (fa bc) [01/02/03] -> responses - -0x10 YY YY yy => Extensions for project YY (16k), with sub commands yy (256) -0x11 YY YY yy - -... if we run out of YY's will use 0x20 etc. - - -Extensions -================= - -These are welcome and encouraged. -We just need to make sure that MsgIDs don't clash. - - - - diff --git a/rsctrl/src/definition/chat.proto b/rsctrl/src/definition/chat.proto deleted file mode 100644 index 0c0b8465b..000000000 --- a/rsctrl/src/definition/chat.proto +++ /dev/null @@ -1,246 +0,0 @@ -package rsctrl.chat; - -import "core.proto"; - -/////////////////////////////////////////////////////////////// -// Private, Group and Chat Lobby RPC. -// -// OTHER COMMANDS TO ADD? -// Status Strings. -// Invite Friends to Private Lobbies. -// Chat History. -// ??? -/////////////////////////////////////////////////////////////// - -enum RequestMsgIds { - MsgId_RequestChatLobbies = 1; - MsgId_RequestCreateLobby = 2; - MsgId_RequestJoinOrLeaveLobby = 3; - MsgId_RequestSetLobbyNickname = 4; - MsgId_RequestRegisterEvents = 5; - MsgId_RequestSendMessage = 6; - MsgId_RequestChatHistory = 7; -} - -enum ResponseMsgIds { - // STANDARD RESPONSES. - MsgId_ResponseChatLobbies = 1; - MsgId_ResponseSetLobbyNickname = 4; - MsgId_ResponseRegisterEvents = 5; - MsgId_ResponseSendMessage = 6; - MsgId_ResponseChatHistory = 7; - - // EVENTS - MsgId_EventLobbyInvite = 101; - MsgId_EventChatMessage = 102; -} - -/////////////////////////////////////////////////////////////// -// BUILDING BLOCKS. - -// This is a combination of ChatLobbyInfo & PublicChatLobbyRecord. -// Which seem very similar?? - -enum LobbyPrivacyLevel { - PRIVACY_PRIVATE = 1; - PRIVACY_PUBLIC = 2; -} - -enum ChatType { - TYPE_PRIVATE = 1; - TYPE_LOBBY = 2; - TYPE_GROUP = 3; -} - -message ChatLobbyInfo { - required string lobby_id = 1; - required string lobby_topic = 2; - required string lobby_name = 3; - - required string lobby_nickname = 4; // empty for none set. - - enum LobbyState { - LOBBYSTATE_JOINED = 1; - LOBBYSTATE_INVITED = 2; - LOBBYSTATE_VISIBLE = 3; - } - - required LobbyPrivacyLevel privacy_level = 5; - required LobbyState lobby_state = 6; - - required uint32 no_peers = 7; - required uint32 last_report_time = 8; - required uint32 last_activity = 9; - - repeated string participating_friends = 10; // SSL_IDS? - repeated string nicknames = 11; -} - - -message ChatId { - - required ChatType chat_type = 1; - required string chat_id = 2; - -} - -message ChatMessage { - - required ChatId id = 1; - required string msg = 2; - - optional string peer_nickname = 3; - optional uint32 chat_flags = 4; - - optional uint32 send_time = 5; - optional uint32 recv_time = 6; - -} - - -// RESPONSE: ResponseChatLobbies -// This is a generic Response - used often. -// lobbies, will contain a list of affected / requested Lobbies. -message ResponseChatLobbies { - - required rsctrl.core.Status status = 1; - repeated ChatLobbyInfo lobbies = 2; -} - - - -/////////////////////////////////////////////////////////////// - -// REQUEST: RequestChatLobbies -message RequestChatLobbies { - - enum LobbySet { - LOBBYSET_ALL = 1; - LOBBYSET_JOINED = 2; - LOBBYSET_INVITED = 3; - LOBBYSET_VISIBLE = 4; - } - - required LobbySet lobby_set = 1; - -} - -// RESPONSE: ResponseChatLobbies - -/////////////////////////////////////////////////////////////// - - -// REQUEST: RequestCreateLobby -message RequestCreateLobby { - - required string lobby_name = 1; - required string lobby_topic = 2; - - required LobbyPrivacyLevel privacy_level = 4; - - repeated string invited_friends = 3; // SSL_IDS -} - -// RESPONSE: ResponseChatLobbies - -/////////////////////////////////////////////////////////////// - -// Accept / Deny Invite, Join / Leave Lobby (these can be combined?) - -// REQUEST: RequestJoinOrLeaveLobby -message RequestJoinOrLeaveLobby { - - enum LobbyAction { - JOIN_OR_ACCEPT = 1; - LEAVE_OR_DENY = 2; - } - - required string lobby_id = 1; - required LobbyAction action = 2; -} - -// RESPONSE: ResponseChatLobbies - -/////////////////////////////////////////////////////////////// - -// Set Nickname. -// Get is done via requesting ChatLobby Info. -// Empty lobby_ids => default Nickname. - -// REQUEST: RequestSetLobbyNickname -message RequestSetLobbyNickname { - required string nickname = 1; - repeated string lobby_ids = 2; -} - -// RESPONSE: ResponseSetLobbyNickname -// Didnt think the whole Lobby status was necessary. -message ResponseSetLobbyNickname { - required rsctrl.core.Status status = 1; -} - - -/////////////////////////////////////////////////////////////// - -// Request Chat Events. -// This is done by registering for events. - -// REQUEST: RequestRegisterEvents -message RequestRegisterEvents { - - enum RegisterAction { - REGISTER = 1; - DEREGISTER = 2; - } - - required RegisterAction action = 1; -} - -// RESPONSE: ResponseRegisterEvents -message ResponseRegisterEvents { - required rsctrl.core.Status status = 1; -} - -// RESPONSE: EventLobbyInvite -message EventLobbyInvite { - required ChatLobbyInfo lobby = 1; -} - -// RESPONSE: EventChatMessage -message EventChatMessage { - required ChatMessage msg = 1; -} - -/////////////////////////////////////////////////////////////// -// Send Message. - -// REQUEST: RequestSendMessage -message RequestSendMessage { - required ChatMessage msg = 1; -} - -// RESPONSE: ResponseSendMessage -message ResponseSendMessage { - required rsctrl.core.Status status = 1; -} - -/////////////////////////////////////////////////////////////// -// Chat History. -// INITIALLY THIS WILL ONLY WORK WITH PRIVATE CHATS. -// NEED TO EXTEND INTERNALS TO HANDLE LOBBIES. - -// REQUEST: RequestChatHistory -message RequestChatHistory { - required ChatId id = 1; /* lobby or chat, group id */ -} - -// RESPONSE: ResponseChatHistory -message ResponseChatHistory { - required rsctrl.core.Status status = 1; - required ChatId id = 2; /* lobby or chat, group id */ - repeated ChatMessage msgs = 3; -} - -/////////////////////////////////////////////////////////////// -/////////////////////////////////////////////////////////////// - diff --git a/rsctrl/src/definition/core.proto b/rsctrl/src/definition/core.proto deleted file mode 100644 index ffa051124..000000000 --- a/rsctrl/src/definition/core.proto +++ /dev/null @@ -1,161 +0,0 @@ -package rsctrl.core; - -/////////////////////////////////////////////////////////////// -// These are basic Messages, which are used as building blocks -// throughout the rest of the interface. -// They should not be sent RAW, but should be wrapped in another msg. -/////////////////////////////////////////////////////////////// - -/////////////////////////////////////////////////////////////// -// Expected PackageIds. - -enum ExtensionId { CORE = 0; } - -enum PackageId { - PEERS = 1; - SYSTEM = 2; - CHAT = 3; - SEARCH = 4; - FILES = 5; - STREAM = 6; - - // BELOW HERE IS STILL BEING DESIGNED. - //MSGS = 7; - - // THEORETICAL ONES. - GXS = 1000; -} - - -/////////////////////////////////////////////////////////////// -// Basic Status Response, should be in all responses - -message Status { - enum StatusCode { - FAILED = 0; - NO_IMPL_YET = 1; - INVALID_QUERY = 2; - PARTIAL_SUCCESS = 3; - SUCCESS = 4; - READMSG = 5; - } - - required StatusCode code = 1; - optional string msg = 2; -} - -/////////////////////////////////////////////////////////////// - -message IpAddr { - required string addr = 1 [default = ""]; - required uint32 port = 2 [default = 0]; // must be 16 bit, 0 for unknown. -} - -/////////////////////////////////////////////////////////////// -/////////////////////////////////////////////////////////////// -// Peer structures, mainly rsctrl.peers related. - -message Location { - - enum StateFlags { // ORd together... - ONLINE = 1; - CONNECTED = 2; - UNREACHABLE = 4; - } - - required string ssl_id = 1; - required string location = 2; - - required IpAddr localaddr = 3; - required IpAddr extaddr = 4; - - required uint32 state = 5; // Not an ENUM as ORd together. -} - -message Person { - - enum Relationship { - YOURSELF = 1; - FRIEND = 2; - FRIEND_OF_MANY_FRIENDS = 3; // 3+ at the moment. - FRIEND_OF_FRIENDS = 4; // 1 or 2. - UNKNOWN = 5; - } - - required string gpg_id = 1; - required string name = 2; - required Relationship relation = 3; - - repeated Location locations = 4; -} - -/////////////////////////////////////////////////////////////// -// File structures, mainly rsctrl.files related. - -message File { - required string name = 1; - required string hash = 2; - required uint64 size = 3; - - // THINK WE DONT WANT THESE HERE... - // BETTER TO KEEP File simple. - //optional string path = 4; - //optional string avail = 5; -} - -message Dir { - required string name = 1; - required string path = 2; - - repeated Dir subdirs = 3; - repeated File files = 4; -} - - -/////////////////////////////////////////////////////////////// - -message Timestamp { - required uint64 secs = 1; - required uint32 microsecs = 2; -} - - -/////////////////////////////////////////////////////////////// -// System Status - -message SystemStatus { - enum NetCode { - BAD_UNKNOWN = 0; - BAD_OFFLINE = 1; - BAD_NATSYM = 2; - BAD_NODHT_NAT = 3; - WARNING_RESTART = 4; - WARNING_NATTED = 5; - WARNING_NODHT = 6; - GOOD = 7; - ADV_FORWARD = 8; - } - - required NetCode net_status = 1; - optional string msg = 2; -} - - -/////////////////////////////////////////////////////////////// -// Bandwidth Measurements. - -message Bandwidth { - required float up = 1; // kB/s - required float down = 2; // kB/s - optional string name = 3; // e.g. DHT, UDP, TCP, Stun, or Total. -} - -message BandwidthSet { - repeated Bandwidth bandwidths = 1; -} - - - -/////////////////////////////////////////////////////////////// - - diff --git a/rsctrl/src/definition/files.proto b/rsctrl/src/definition/files.proto deleted file mode 100644 index 4a12be782..000000000 --- a/rsctrl/src/definition/files.proto +++ /dev/null @@ -1,143 +0,0 @@ -package rsctrl.files; - -import "core.proto"; - -/////////////////////////////////////////////////////////////// -// List Transfers. -// Control Transfers. -// -// TODO: -// Share Directories. -/////////////////////////////////////////////////////////////// - -enum RequestMsgIds { - MsgId_RequestTransferList = 1; - MsgId_RequestControlDownload = 2; - MsgId_RequestShareDirList = 3; -} - -enum ResponseMsgIds { - MsgId_ResponseTransferList = 1; - MsgId_ResponseControlDownload = 2; - MsgId_ResponseShareDirList = 3; -} - -/////////////////////////////////////////////////////////////// -/////////////////////////////////////////////////////////////// - -// Building Blocks - -enum Direction { - DIRECTION_UPLOAD = 1; - DIRECTION_DOWNLOAD = 2; -} - - -enum TransferState { - TRANSFER_FAILED = 1; - TRANSFER_OKAY = 2; - TRANSFER_PAUSED = 3; - TRANSFER_QUEUED = 4; - TRANSFER_WAITING = 5; - TRANSFER_DOWNLOADING = 6; - TRANSFER_CHECKING_HASH = 7; - TRANSFER_COMPLETE = 8; -} - - -message FileTransfer { - - required rsctrl.core.File file = 1; - required Direction direction = 2; - required float fraction = 3; - required float rate_kBs = 4; - required TransferState state = 5; -} - -/////////////////////////////////////////////////////////////// -// Transfer List. - -// REQUEST: RequestTransferList -message RequestTransferList { - required Direction direction = 1; -} - -// RESPONSE: ResponseTransferList -message ResponseTransferList { - - required rsctrl.core.Status status = 1; - repeated FileTransfer transfers = 2; - -} - -/////////////////////////////////////////////////////////////// -// Download. - -// REQUEST: RequestControlDownload -// START requires name, hash & size. -// other actions only require file hash. -message RequestControlDownload { - - enum Action { - ACTION_START = 1; // start download. - ACTION_CONTINUE = 2; // move to top of queue. - ACTION_WAIT = 3; // send to bottom of queue. - ACTION_PAUSE = 4; // hold indefinitely. - ACTION_RESTART = 5; // end pause, restart download. - ACTION_CHECK = 6; // force check. - ACTION_CANCEL = 7; // remove permenantly. - } - - required rsctrl.core.File file = 1; - required Action action = 2; - -} - -// RESPONSE: ResponseControlDownload -message ResponseControlDownload { - required rsctrl.core.Status status = 1; -} - - -/////////////////////////////////////////////////////////////// -/////////////////////////////////////////////////////////////// -// SHARED FILES - -// REQUEST: RequestShareDirList -message RequestShareDirList { - required string ssl_id = 1; - required string path = 2; -} - - -// RESPONSE: ResponseShareDirList -message ResponseShareDirList { - required rsctrl.core.Status status = 1; - - enum ListType { - DIRQUERY_ROOT = 1; // the query refers to root. - DIRQUERY_PERSON = 2; // the query refers to person - DIRQUERY_FILE = 3; // the query refers to a file. - DIRQUERY_DIR = 4; // move to top of queue. - } - - required string ssl_id = 2; - required string path = 3; - required ListType list_type = 4; - repeated rsctrl.core.File files = 5; -} - - -//// REQUEST: RequestChangeShares -// -//// REQUEST: RequestLiCloseSearch -//// REQUEST: RequestCloseSearch -// - - - -/////////////////////////////////////////////////////////////// -/////////////////////////////////////////////////////////////// -/////////////////////////////////////////////////////////////// -/////////////////////////////////////////////////////////////// - diff --git a/rsctrl/src/definition/gxs.proto b/rsctrl/src/definition/gxs.proto deleted file mode 100644 index 57bcd5a0f..000000000 --- a/rsctrl/src/definition/gxs.proto +++ /dev/null @@ -1,287 +0,0 @@ -package rsctrl.gxs; - -import "core.proto"; - -/////////////////////////////////////////////////////////////// -// Base Messages for GXS Interface. -/////////////////////////////////////////////////////////////// - -enum RequestMsgIds { - MsgId_RequestPeers = 1; - MsgId_RequestAddPeer = 2; - MsgId_RequestModifyPeer = 3; -} - -enum ResponseMsgIds { - MsgId_ResponsePeerList = 1; - MsgId_ResponseAddPeer = 2; - MsgId_ResponseModifyPeer = 3; -} - -/////////////////////////////////////////////////////////////// -/////////////////////////////////////////////////////////////// - -// BASE DATA TYPES - -message Service { - // - required uint32 service_id = 1; - optional string service_name = 2; -} - -message GroupMeta { - - // FLAGS as ENUMs. - enum GroupFlags { - GF_FLAG1 = 1; - GF_FLAG2 = 2; - GF_FLAG3 = 4; - GF_FLAG4 = 8; - } - - enum SignFlags { - SF_FLAG1 = 1; - SF_FLAG2 = 2; - } - - enum SubscribeFlags { - SUBF_FLAG1 = 1; - SUBF_FLAG2 = 2; - } - - enum StatusFlags { - STATF_FLAG1 = 1; - STATF_FLAG2 = 2; - } - - // THIS IS FIXED: From NETWORK. - required string group_id = 1; - required string group_name = 2; - required uint32 group_flags = 3; - required uint32 sign_flags = 4; - - required uint32 publish_ts = 5; - optional string author_id = 6; - - // BELOW HERE IS LOCAL DATA, THAT IS NOT FROM MSG. - - required uint32 subscribe_flags = 7; - required uint32 group_status = 8; - - optional string service_string = 9; - - optional uint32 pop = 10; // USED? - optional uint32 msg_count = 11; // ??? - optional int32 last_post = 12; // ??? -} - - -message GroupGenericData { - required GroupMeta meta = 1; - required string encoded_data = 2; -} - - -message MsgMeta { - - // FLAGS as ENUMs. - enum GroupFlags { - GF_FLAG1 = 1; - GF_FLAG2 = 2; - GF_FLAG3 = 4; - GF_FLAG4 = 8; - } - - enum SignFlags { - SF_FLAG1 = 1; - SF_FLAG2 = 2; - } - - enum SubscribeFlags { - SUBF_FLAG1 = 1; - SUBF_FLAG2 = 2; - } - - enum StatusFlags { - STATF_FLAG1 = 1; - STATF_FLAG2 = 2; - } - - // THIS IS FIXED: From NETWORK. - required string group_id = 1; - required string msg_id = 2; - - required string thread_id = 3; - required uint32 parent_id = 4; - required uint32 origmsg_id = 5; - - optional string author_id = 6; - - required uint32 publish_ts = 7; - required uint32 msg_name = 8; - - required uint32 msg_flags = 9; - - // BELOW HERE IS LOCAL DATA, THAT IS NOT FROM MSG. - - required uint32 msg_status = 10; - required uint32 child_ts = 11; - optional string service_string = 12; -} - -message MsgGenericData { - required MsgMeta meta = 1; - required string encoded_data = 2; -} - - -/////////////////////////////////////////////////////////////// -/////////////////////////////////////////////////////////////// - -message Filter { - required uint32 options = 1; - - optional uint32 status_filter = 2; - optional uint32 status_mask = 3; - - optional uint32 req_type = 4; - - optional uint32 subscribe_filter = 5; - - optional int32 before = 6; - optional int32 after = 7; -} - -message MsgSet { - required string group_id = 1; - repeated string msg_id = 2; -} - -message GroupMsgSet { - repeated MsgSet groups = 1; -} - - -/////////////////////////////////////////////////////////////// -/////////////////////////////////////////////////////////////// - -// REQUEST: RequestGroupInfo -message RequestGroupInfo { - - required Service service = 1; - - required uint32 ans_type = 2; - required Filter options = 3; - repeated string group_ids = 4; -} - - -// RESPONSE: ResponseGroupList -message ResponseGroupList { - - required rsctrl.core.Status status = 1; - - required Service service = 2; - repeated string group_ids = 3; -} - - -// RESPONSE: ResponseGroupMeta -message ResponseGroupMeta { - - required rsctrl.core.Status status = 1; - - required Service service = 2; - repeated GroupMeta meta = 3; -} - - -// RESPONSE: ResponseGroupData -message ResponseGroupData { - - required rsctrl.core.Status status = 1; - - required Service service = 2; - repeated GroupGenericData data = 3; -} - - -/////////////////////////////////////////////////////////////// - -// REQUEST: RequestMsgInfo -message RequestMsgInfo { - - required Service service = 1; - - required uint32 ans_type = 2; - required Filter options = 3; - repeated GroupMsgSet msgs = 4; -} - -// REQUEST: RequestMsgRelatedInfo -message RequestMsgRelatedInfo { - - required Service service = 1; - - required uint32 ans_type = 2; - required Filter options = 3; - repeated GroupMsgSet msgs = 4; -} - -// RESPONSE: ResponseMsgList -message ResponseMsgList { - - required rsctrl.core.Status status = 1; - - required Service service = 2; - repeated GroupMsgSet msgs = 3; -} - -// RESPONSE: ResponseMsgMeta -message ResponseMsgMeta { - - required rsctrl.core.Status status = 1; - - required Service service = 2; - repeated MsgMeta meta = 3; -} - -// RESPONSE: ResponseMsgData -message ResponseMsgData { - - required rsctrl.core.Status status = 1; - - required Service service = 2; - repeated MsgGenericData data = 3; -} - - -/////////////////////////////////////////////////////////////// -/////////////////////////////////////////////////////////////// - - -// REQUEST: RequestCreateGroup -message RequestCreateGroup { - - required Service service = 1; - repeated GroupGenericData data = 2; -} - - -// RESPONSE: ResponseMsgMeta -// As defined above. - - -// REQUEST: RequestCreateMsg -message RequestCreateMsg { - - required Service service = 1; - repeated MsgGenericData data = 2; -} - -// RESPONSE: ResponseMsgMeta -// As defined above. - - - - diff --git a/rsctrl/src/definition/msgs.proto b/rsctrl/src/definition/msgs.proto deleted file mode 100644 index e011dfb33..000000000 --- a/rsctrl/src/definition/msgs.proto +++ /dev/null @@ -1,108 +0,0 @@ -package rsctrl.msgs; - -import "core.proto"; - -/////////////////////////////////////////////////////////////// -// Access, and Control your Friends / Peers and related Settings. -/////////////////////////////////////////////////////////////// - -enum RequestMsgIds { - MsgId_RequestPeers = 1; - MsgId_RequestAddPeer = 2; - MsgId_RequestModifyPeer = 3; -} - -enum ResponseMsgIds { - MsgId_ResponsePeerList = 1; - MsgId_ResponseAddPeer = 2; - MsgId_ResponseModifyPeer = 3; -} - -/////////////////////////////////////////////////////////////// - -// REQUEST: RequestPeers -message RequestPeers { - - // About Who? - enum SetOption { - OWNID = 1; - LISTED = 2; - ONLINE = 3; - FRIENDS = 4; - VALID = 5; - SIGNED = 6; - ALL = 7; - } - - // What do you want? - enum InfoOption { - NAMEONLY = 1; - BASIC = 2; - LOCATION = 3; - ALLINFO = 4; - } - - required SetOption set = 1; - required InfoOption info = 2; - repeated string gpg_ids = 3; -} - - -// RESPONSE: ResponsePeerList -message ResponsePeerList { - required rsctrl.core.Status status = 1; - repeated rsctrl.core.Person peers = 2; -} - -/////////////////////////////////////////////////////////////// - -// REQUEST: RequestAddPeer -message RequestAddPeer { - - enum AddCmd { - NOOP = 0; // No op. - ADD = 1; // Add existing from gpg_id. - REMOVE = 2; // Remove existing from gpg_id. - IMPORT = 3; // Import from cert, with gpg_id. - EXAMINE = 4; // Examine cert, but no action. - } - - required string gpg_id = 1; - required AddCmd cmd = 2; - optional string cert = 3; -} - -// RESPONSE: ResponseAddPeer -message ResponseAddPeer { - required rsctrl.core.Status status = 1; - repeated rsctrl.core.Person peers = 2; -} - -/////////////////////////////////////////////////////////////// - -// REQUEST: RequestModifyPeer -message RequestModifyPeer { - - enum ModCmd { - NOOP = 0; - ADDRESS = 1; - DYNDNS = 2; - //SOMETHING_ELSE = 0x0000010; - //SOMETHING_ELSE = 0x0000020; - //SOMETHING_ELSE = 0x0000040; - //SOMETHING_ELSE = 0x0000080; - } - - required ModCmd cmd = 1; - //required int64 cmd = 1; // Could we OR the Cmds together? - repeated rsctrl.core.Person peers = 2; -} - -// RESPONSE: ResponseModifyPeer -message ResponseModifyPeer { - required rsctrl.core.Status status = 1; - repeated rsctrl.core.Person peers = 2; -} - -/////////////////////////////////////////////////////////////// - diff --git a/rsctrl/src/definition/peers.proto b/rsctrl/src/definition/peers.proto deleted file mode 100644 index 5cc38be27..000000000 --- a/rsctrl/src/definition/peers.proto +++ /dev/null @@ -1,111 +0,0 @@ -package rsctrl.peers; - -import "core.proto"; - -/////////////////////////////////////////////////////////////// -// Access, and Control your Friends / Peers and related Settings. -/////////////////////////////////////////////////////////////// - -enum RequestMsgIds { - MsgId_RequestPeers = 1; - MsgId_RequestAddPeer = 2; - MsgId_RequestExaminePeer = 3; - MsgId_RequestModifyPeer = 4; -} - -enum ResponseMsgIds { - MsgId_ResponsePeerList = 1; -} - -/////////////////////////////////////////////////////////////// - -// REQUEST: RequestPeers -message RequestPeers { - - // About Who? - enum SetOption { - OWNID = 1; - LISTED = 2; - CONNECTED = 3; - FRIENDS = 4; - VALID = 5; - SIGNED = 6; - ALL = 7; - } - - // What do you want? - enum InfoOption { - NAMEONLY = 1; - BASIC = 2; - LOCATION = 3; - ALLINFO = 4; - } - - required SetOption set = 1; - required InfoOption info = 2; - repeated string pgp_ids = 3; -} - - -// RESPONSE: ResponsePeerList -message ResponsePeerList { - required rsctrl.core.Status status = 1; - repeated rsctrl.core.Person peers = 2; -} - -/////////////////////////////////////////////////////////////// - -// REQUEST: RequestAddPeer -message RequestAddPeer { - - enum AddCmd { - ADD = 1; // Add existing from gpg_id. - REMOVE = 2; // Remove existing from gpg_id. - } - - required AddCmd cmd = 1; - required string pgp_id = 2; - optional string ssl_id = 3; - -} - -/////////////////////////////////////////////////////////////// - -// REQUEST: RequestExaminePeer -message RequestExaminePeer { - - enum ExamineCmd { - IMPORT = 3; // Import from cert, with gpg_id. - EXAMINE = 4; // Examine cert, but no action. - } - - // Must have GPG ID to import. Proves you've looked at it. - required string pgp_id = 1; - required ExamineCmd cmd = 2; - required string cert = 3; - -} - -/////////////////////////////////////////////////////////////// - -// REQUEST: RequestModifyPeer -// THIS IS INCOMPLETE... DON'T USE. -message RequestModifyPeer { - - enum ModCmd { - NOOP = 0; - ADDRESS = 1; - DYNDNS = 2; - //SOMETHING_ELSE = 0x0000010; - //SOMETHING_ELSE = 0x0000020; - //SOMETHING_ELSE = 0x0000040; - //SOMETHING_ELSE = 0x0000080; - } - - required ModCmd cmd = 1; - //required int64 cmd = 1; // Could we OR the Cmds together? - repeated rsctrl.core.Person peers = 2; -} - -/////////////////////////////////////////////////////////////// - diff --git a/rsctrl/src/definition/search.proto b/rsctrl/src/definition/search.proto deleted file mode 100644 index d058a6195..000000000 --- a/rsctrl/src/definition/search.proto +++ /dev/null @@ -1,120 +0,0 @@ -package rsctrl.search; - -import "core.proto"; - -/////////////////////////////////////////////////////////////// -// Searches -/////////////////////////////////////////////////////////////// - -enum RequestMsgIds { - MsgId_RequestBasicSearch = 1; - //MsgId_RequestAdvSearch = 2; // NOT IMPLEMENTED YET. - MsgId_RequestCloseSearch = 3; - MsgId_RequestListSearches = 4; - MsgId_RequestSearchResults = 5; -} - -enum ResponseMsgIds { - MsgId_ResponseSearchIds = 1; - MsgId_ResponseSearchResults = 5; -} - -/////////////////////////////////////////////////////////////// -/////////////////////////////////////////////////////////////// -// Building Block -message SearchHit { - - enum LocFlag { - LOCAL = 1; // We Have it. - FRIEND = 2; // Browsable - NETWORK = 4; // Network. - } - - required rsctrl.core.File file = 1; - required uint32 loc = 2; // OR of LocFlag so uint field - required uint32 no_hits = 3; // NOT USED YET. - repeated string alt_names = 4; -} - -message SearchSet { - - required uint32 search_id = 1; - repeated SearchHit hits = 2; - -} - -/////////////////////////////////////////////////////////////// -/////////////////////////////////////////////////////////////// -// SEARCH (start). - -// REQUEST: RequestBasicSearch -message RequestBasicSearch { - - repeated string terms = 1; -} - -// REQUEST: RequestAdvSearch -message RequestAdvSearch { - - repeated string terms = 1; -} - - -// RESPONSE: ResponseSearchIds -message ResponseSearchIds { - - required rsctrl.core.Status status = 1; - repeated uint32 search_id = 2; -} - - -/////////////////////////////////////////////////////////////// -// SEARCH (cancel) - -// REQUEST: RequestCloseSearch -message RequestCloseSearch { - - required uint32 search_id = 1; -} - - -// RESPONSE: ResponseSearchIds -// As before. - -/////////////////////////////////////////////////////////////// -// SEARCH (list) - -// REQUEST: RequestListSearches -message RequestListSearches { - // Nothing here. -} - -// RESPONSE: ResponseSearchIds -// As before. - -/////////////////////////////////////////////////////////////// -// SEARCH (list) - - -// REQUEST: RequestSearchResults -// Empty search_ids => all results. -message RequestSearchResults { - - optional uint32 result_limit = 1; - repeated uint32 search_ids = 2; -} - -// RESPONSE: ResponseSearchResults -message ResponseSearchResults { - - required rsctrl.core.Status status = 1; - repeated SearchSet searches = 2; -} - - -/////////////////////////////////////////////////////////////// -/////////////////////////////////////////////////////////////// -/////////////////////////////////////////////////////////////// -/////////////////////////////////////////////////////////////// -/////////////////////////////////////////////////////////////// - diff --git a/rsctrl/src/definition/stream.proto b/rsctrl/src/definition/stream.proto deleted file mode 100644 index 9fcbf8636..000000000 --- a/rsctrl/src/definition/stream.proto +++ /dev/null @@ -1,152 +0,0 @@ -package rsctrl.stream; - -import "core.proto"; - -/////////////////////////////////////////////////////////////// -// This protocol defines how to stream data from retroshare. -// It can be used for VoIP or Files, or whatever. -// -// There are two parts. -// Control and actual streaming. -// -/////////////////////////////////////////////////////////////// - -enum RequestMsgIds { - MsgId_RequestStartFileStream = 1; - MsgId_RequestControlStream = 2; - MsgId_RequestListStreams = 3; -} - -enum ResponseMsgIds { - MsgId_ResponseStreamDetail = 1; // RESPONSE to List and Control. - MsgId_ResponseStreamData = 101; -} - -/////////////////////////////////////////////////////////////// -/////////////////////////////////////////////////////////////// - -// Building Blocks - -enum StreamType { - STREAM_TYPE_ALL = 1; // all streams - STREAM_TYPE_FILES = 2; // files stream - STREAM_TYPE_VOIP = 3; // VoIP stream - STREAM_TYPE_OTHER = 4; // Who knows what else. -} - -enum StreamState { - STREAM_STATE_ERROR = 0; - STREAM_STATE_RUN = 1; - STREAM_STATE_PAUSED = 2; - STREAM_STATE_FINISHED = 3; -} - -message StreamFileDetail { - - required rsctrl.core.File file = 1; - required uint64 offset = 5; - -} - - -message StreamVoipDetail { - - // THIS NEEDS MORE DEFINITION. - required string peer_id = 1; - required uint64 duration = 2; - required uint64 offset = 3; - -} - - -message StreamDesc { - - required uint32 stream_id = 1; - required StreamType stream_type = 2; - required StreamState stream_state = 3; - required float rate_kbs = 4; - optional StreamFileDetail file = 5; - optional StreamVoipDetail voip = 6; - -} - - -message StreamData { - - required uint32 stream_id = 1; - required StreamState stream_state = 2; - required rsctrl.core.Timestamp send_time = 3; - required uint64 offset = 4; - required uint32 size = 5; - required bytes stream_data = 6; - -} - -/////////////////////////////////////////////////////////////// -/////////////////////////////////////////////////////////////// - - -// REQUEST: RequestStartFileStream -message RequestStartFileStream { - - required rsctrl.core.File file = 1; - required float rate_kbs = 2; - - // byte range. allows to restart transfer! - optional uint64 start_byte = 3; - optional uint64 end_byte = 4; - -} - -// RESPONSE: ResponseStreamDetail -message ResponseStreamDetail { - - required rsctrl.core.Status status = 1; - repeated StreamDesc streams = 2; - -} - - -/////////////////////////////////////////////////////////////// -/////////////////////////////////////////////////////////////// - -// REQUEST: RequestControlStream -message RequestControlStream { - - enum StreamAction { - STREAM_START = 1; // start stream - STREAM_STOP = 2; // stop stream - STREAM_PAUSE = 3; // pause stream - STREAM_CHANGE_RATE = 4; // rate of the stream - STREAM_SEEK = 5; // move streaming position. - } - - required uint32 stream_id = 1; - required StreamAction action = 2; - optional float rate_kbs = 3; - optional uint64 seek_byte = 4; -} - -/////////////////////////////////////////////////////////////// -/////////////////////////////////////////////////////////////// - -// REQUEST: RequestListStreams -message RequestListStreams { - - required StreamType request_type = 1; - -} - -/////////////////////////////////////////////////////////////// -/////////////////////////////////////////////////////////////// - -// RESPONSE: ResponseStreamData -message ResponseStreamData { - required rsctrl.core.Status status = 1; - required StreamData data = 2; -} - - -/////////////////////////////////////////////////////////////// -/////////////////////////////////////////////////////////////// - diff --git a/rsctrl/src/definition/system.proto b/rsctrl/src/definition/system.proto deleted file mode 100644 index d979b2696..000000000 --- a/rsctrl/src/definition/system.proto +++ /dev/null @@ -1,121 +0,0 @@ -package rsctrl.system; - -import "core.proto"; - -/////////////////////////////////////////////////////////////// -// Configuration and Stats. -/////////////////////////////////////////////////////////////// - -enum RequestMsgIds { - MsgId_RequestSystemStatus = 1; - MsgId_RequestSystemQuit = 2; - MsgId_RequestSystemExternalAccess = 3; - MsgId_RequestSystemAccount = 4; -} - -enum ResponseMsgIds { - MsgId_ResponseSystemStatus = 1; - MsgId_ResponseSystemQuit = 2; - MsgId_ResponseSystemExternalAccess = 3; - MsgId_ResponseSystemAccount = 4; -} - -/////////////////////////////////////////////////////////////// - -// REQUEST: RequestSystemStatus -message RequestSystemStatus { - // Nothing here? -} - -// RESPONSE: ResponseSystemStatus -message ResponseSystemStatus { - - enum NetCode { - BAD_UNKNOWN = 0; - BAD_OFFLINE = 1; - BAD_NATSYM = 2; - BAD_NODHT_NAT = 3; - WARNING_RESTART = 4; - WARNING_NATTED = 5; - WARNING_NODHT = 6; - GOOD = 7; - ADV_FORWARD = 8; - } - - // Status of response. - required rsctrl.core.Status status = 1; - - // Peers. - required uint32 no_peers = 2; - required uint32 no_connected = 3; - - // Basic Network Information. - required NetCode net_status = 4; - - required rsctrl.core.Bandwidth bw_total = 5; -} - -/////////////////////////////////////////////////////////////// - -// REQUEST: RequestSystemQuit -message RequestSystemQuit { - - enum QuitCode { - CLOSE_CHANNEL = 1; - SHUTDOWN_RS = 2; // NOT RECOMMENDED (but some people might like it) - } - - required QuitCode quit_code = 1; -} - -// RESPONSE: ResponseSystemQuit -// Effect potentially immediate (with loss of connection) - only expect a response error. -// Shutdown takes longer - so you should get a response. -message ResponseSystemQuit { - - // Status of response. - required rsctrl.core.Status status = 1; -} - - -/////////////////////////////////////////////////////////////// - -// REQUEST: RequestSystemExternalAccess -message RequestSystemExternalAccess { - // Nothing here? -} - -// RESPONSE: ResponseSystemExternalAccess -message ResponseSystemExternalAccess { - - // Status of response. - required rsctrl.core.Status status = 1; - - required uint32 ext_port = 2; - required string dht_key = 3; -} - - -/////////////////////////////////////////////////////////////// - -// REQUEST: RequestSystemAccount -message RequestSystemAccount { - // Nothing here? -} - -// RESPONSE: ResponseSystemAccount -message ResponseSystemAccount { - - // Status of response. - required rsctrl.core.Status status = 1; - - required string pgp_name = 2; - required string location = 3; - required string pgp_id = 4; - required string ssl_id = 5; -} - -/////////////////////////////////////////////////////////////// -/////////////////////////////////////////////////////////////// -/////////////////////////////////////////////////////////////// -