rhodes 1.5.5 → 2.0.0.beta1
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +5 -0
- data/Manifest.txt +214 -32
- data/Rakefile +33 -10
- data/bin/upgrade-rhodes-app +0 -1
- data/lib/build/compileERB/bb.rb +2 -2
- data/lib/build/compileERB/default.rb +7 -5
- data/lib/build/jake.rb +1 -1
- data/lib/extensions/digest-md5/ext.yml +1 -1
- data/lib/extensions/digest-md5/ext/Rakefile +35 -36
- data/lib/extensions/digest-md5/ext/build.bat +1 -0
- data/lib/extensions/digest-md5/ext/digest-md5.vcproj +203 -0
- data/lib/extensions/digest-sha1/ext.yml +1 -1
- data/lib/extensions/digest/ext.yml +1 -1
- data/lib/extensions/digest/ext/Rakefile +35 -39
- data/lib/extensions/digest/ext/build.bat +1 -2
- data/lib/extensions/digest/ext/digest.vcproj +203 -0
- data/lib/framework/rho/render.rb +79 -22
- data/lib/framework/rho/rho.rb +294 -56
- data/lib/framework/rho/rhoapplication.rb +10 -0
- data/lib/framework/rho/rhofsconnector.rb +2 -6
- data/lib/framework/rho/rhoutils.rb +56 -14
- data/lib/framework/rho/rhoviewhelpers.rb +2 -0
- data/lib/framework/rhodes.rb +2 -2
- data/lib/framework/rhom/rhom.rb +42 -15
- data/lib/framework/rhom/rhom_db_adapter.rb +165 -159
- data/lib/framework/rhom/rhom_object.rb +0 -1
- data/lib/framework/rhom/rhom_object_factory.rb +343 -166
- data/lib/framework/rhom/rhom_source.rb +28 -15
- data/lib/framework/version.rb +2 -2
- data/lib/rhodes.rb +2 -2
- data/platform/android/Rhodes/AndroidManifest.xml +2 -2
- data/platform/android/Rhodes/gen/com/rhomobile/rhodes/R.java +39 -44
- data/platform/android/Rhodes/jni/include/JNIRhodes.h +1 -1
- data/platform/android/Rhodes/jni/include/details/rhojava.inc +23 -20
- data/platform/android/Rhodes/jni/include/jni/com_rhomobile_rhodes_RhoMenu.h +61 -0
- data/platform/android/Rhodes/jni/include/jni/com_rhomobile_rhodes_Rhodes.h +16 -0
- data/platform/android/Rhodes/jni/include/jni/com_rhomobile_rhodes_alert_Alert.h +21 -0
- data/platform/android/Rhodes/jni/include/sslimpl.h +1 -1
- data/platform/android/Rhodes/jni/src/alert.cpp +32 -5
- data/platform/android/Rhodes/jni/src/callbacks.cpp +51 -21
- data/platform/android/Rhodes/jni/src/mapview.cpp +3 -8
- data/platform/android/Rhodes/jni/src/menu.cpp +70 -0
- data/platform/android/Rhodes/jni/src/navbar.cpp +16 -0
- data/platform/android/Rhodes/jni/src/rhodes.cpp +37 -0
- data/platform/android/Rhodes/jni/src/sslimpl.cpp +3 -3
- data/platform/android/Rhodes/jni/src/webview.cpp +21 -7
- data/platform/android/Rhodes/res/drawable/alert_alert.png +0 -0
- data/platform/android/Rhodes/res/drawable/alert_info.png +0 -0
- data/platform/android/Rhodes/res/drawable/alert_question.png +0 -0
- data/platform/android/Rhodes/res/drawable/camera.png +0 -0
- data/platform/android/Rhodes/res/layout/camera.xml +18 -3
- data/platform/android/Rhodes/res/menu/options.xml +0 -10
- data/platform/android/Rhodes/src/com/rhomobile/rhodes/AndroidR.java +5 -10
- data/platform/android/Rhodes/src/com/rhomobile/rhodes/Capabilities.java +12 -0
- data/platform/android/Rhodes/src/com/rhomobile/rhodes/RhoMenu.java +105 -0
- data/platform/android/Rhodes/src/com/rhomobile/rhodes/Rhodes.java +157 -122
- data/platform/android/Rhodes/src/com/rhomobile/rhodes/SplashScreen.java +7 -58
- data/platform/android/Rhodes/src/com/rhomobile/rhodes/WebView.java +16 -0
- data/platform/android/Rhodes/src/com/rhomobile/rhodes/alert/Alert.java +220 -17
- data/platform/android/Rhodes/src/com/rhomobile/rhodes/camera/Camera.java +22 -4
- data/platform/android/Rhodes/src/com/rhomobile/rhodes/camera/ImageCapture.java +44 -25
- data/platform/android/Rhodes/src/com/rhomobile/rhodes/geolocation/GeoLocation.java +10 -0
- data/platform/android/Rhodes/src/com/rhomobile/rhodes/mainview/MainView.java +3 -0
- data/platform/android/Rhodes/src/com/rhomobile/rhodes/mainview/SimpleMainView.java +10 -21
- data/platform/android/Rhodes/src/com/rhomobile/rhodes/mainview/TabbedMainView.java +15 -12
- data/platform/android/Rhodes/src/com/rhomobile/rhodes/phonebook/Phonebook.java +44 -0
- data/platform/android/Rhodes/src/com/rhomobile/rhodes/socket/SSLImpl.java +47 -3
- data/platform/android/Rhodes/src/com/rhomobile/rhodes/uri/MailUriHandler.java +13 -6
- data/platform/android/Rhodes/src/com/rhomobile/rhodes/uri/TelUriHandler.java +11 -5
- data/platform/android/Rhodes/src/com/rhomobile/rhodes/uri/UriHandler.java +1 -4
- data/platform/android/Rhodes/src/com/rhomobile/rhodes/uri/VideoUriHandler.java +61 -0
- data/platform/android/build/RhodesSRC_build.files +3 -0
- data/platform/android/build/android.rake +173 -60
- data/platform/android/build/androidcommon.rb +1 -2
- data/platform/android/build/librhocommon_build.files +5 -0
- data/platform/android/build/librhodes_build.files +2 -0
- data/platform/android/build/libruby_build.files +2 -1
- data/platform/bb/Hsqldb/Hsqldb.jdp +0 -3
- data/platform/bb/Hsqldb/src/com/rho/db/FileUtilBB.java +1 -1
- data/platform/bb/Hsqldb/src/com/rho/db/HsqlDBResult.java +16 -1
- data/platform/bb/Hsqldb/src/com/rho/db/HsqlDBRowResult.java +5 -0
- data/platform/bb/Hsqldb/src/com/rho/db/HsqlDBStorage.java +25 -4
- data/platform/bb/Hsqldb/src/com/rho/db/Journal.java +1 -1
- data/platform/bb/Hsqldb/src/com/rho/file/FileAccessBB.java +0 -1
- data/platform/bb/Hsqldb/src/j2me/math/Number.java +6 -3
- data/platform/bb/Hsqldb/src/org/hsqldb/CompiledStatementExecutor.java +2 -1
- data/platform/bb/Hsqldb/src/org/hsqldb/Expression.java +1 -0
- data/platform/bb/Hsqldb/src/org/hsqldb/Parser.java +1 -0
- data/platform/bb/Hsqldb/src/org/hsqldb/Result.java +2 -0
- data/platform/bb/Hsqldb/src/org/hsqldb/Select.java +12 -6
- data/platform/bb/Hsqldb/src/org/hsqldb/Session.java +19 -12
- data/platform/bb/Hsqldb/src/org/hsqldb/Table.java +10 -4
- data/platform/bb/Hsqldb/src/org/hsqldb/Token.java +10 -2
- data/platform/bb/Hsqldb/src/org/hsqldb/Tokenizer.java +3 -3
- data/platform/bb/Hsqldb/src/org/hsqldb/lib/java/JavaSystem.java +1 -1
- data/platform/bb/Hsqldb/src/org/hsqldb/persist/HsqlProperties.java +2 -1
- data/platform/bb/Hsqldb/src/org/hsqldb/persist/ScaledRAFile.java +1 -1
- data/platform/bb/Hsqldb/src/org/hsqldb/scriptio/ScriptReaderText.java +1 -1
- data/platform/bb/Hsqldb/src/org/hsqldb/scriptio/ScriptWriterBase.java +1 -1
- data/platform/bb/RubyVM/RubyVM.jdp +9 -10
- data/platform/bb/build/RubyVM_build.files +9 -7
- data/platform/bb/build/bb.rake +13 -3
- data/platform/bb/build/hsqldb_build.files +0 -2
- data/platform/bb/build/rhodes_build.files +5 -2
- data/platform/bb/rhodes/platform/4.7/com/rho/RhoMainScreen.java +8 -0
- data/platform/bb/rhodes/platform/5.0/com/rho/BrowserAdapter5.java +154 -0
- data/platform/bb/rhodes/platform/5.0/com/rho/RhoMainScreen.java +8 -0
- data/platform/bb/rhodes/platform/common/com/rho/BrowserAdapter5.java +28 -0
- data/platform/bb/rhodes/rhodes.jdp +12 -7
- data/platform/bb/rhodes/src/com/rho/BrowserAdapter.java +331 -0
- data/platform/bb/rhodes/src/com/rho/BrowserAdapter5.java +28 -0
- data/platform/bb/rhodes/src/com/rho/IBrowserAdapter.java +10 -0
- data/platform/bb/rhodes/src/com/rho/RhoMainScreen.java +4 -0
- data/platform/bb/rhodes/src/com/rho/RhoRubyHelper.java +2 -4
- data/platform/bb/rhodes/src/com/rho/{Jsr75File.java → file/Jsr75File.java} +83 -36
- data/platform/bb/{Hsqldb → rhodes}/src/com/rho/file/Jsr75RAFileImpl.java +0 -1
- data/platform/bb/{Hsqldb → rhodes}/src/com/rho/file/PersistRAFileImpl.java +0 -2
- data/platform/bb/rhodes/src/com/rho/net/NetworkAccess.java +8 -10
- data/platform/bb/rhodes/src/com/rho/rubyext/Alert.java +1 -1
- data/platform/bb/rhodes/src/com/rho/rubyext/GeoLocation.java +39 -0
- data/platform/bb/rhodes/src/com/rho/rubyext/System.java +63 -2
- data/platform/bb/rhodes/src/com/rho/rubyext/WebView.java +100 -0
- data/platform/bb/rhodes/src/rhomobile/LogScreen.java +1 -1
- data/platform/bb/rhodes/src/rhomobile/PushListeningThread.java +13 -1
- data/platform/bb/rhodes/src/rhomobile/RhodesApplication.java +138 -492
- data/platform/bb/rhodes/src/rhomobile/SecondaryResourceFetchThread.java +11 -2
- data/platform/bb/rhodes/src/rhomobile/Utilities.java +14 -10
- data/platform/bb/rhodes/src/rhomobile/camera/CameraScreen.java +5 -14
- data/platform/bb/rhodes/src/rhomobile/camera/ImageBrowserScreen.java +1 -1
- data/platform/bb/rhodes/src/rhomobile/mapview/GoogleMapField.java +2 -2
- data/platform/iphone/Classes/AppManager/AppManager.m +37 -14
- data/platform/iphone/Classes/Camera/PickImageDelegate.h +15 -4
- data/platform/iphone/Classes/Camera/PickImageDelegate.m +53 -50
- data/platform/iphone/Classes/DateTimePicker.h +17 -0
- data/platform/iphone/Classes/DateTimePicker.m +35 -0
- data/platform/iphone/Classes/GeoLocation/LocationController.m +2 -3
- data/platform/iphone/Classes/LogOptionsController.m +3 -2
- data/platform/iphone/Classes/LogViewController.m +4 -2
- data/platform/iphone/Classes/MapView/GoogleGeocoder.m +12 -20
- data/platform/iphone/Classes/MapView/MapAnnotation.h +9 -13
- data/platform/iphone/Classes/MapView/MapAnnotation.m +17 -65
- data/platform/iphone/Classes/MapView/MapViewController.h +1 -7
- data/platform/iphone/Classes/MapView/MapViewController.m +51 -25
- data/platform/iphone/Classes/NativeBar.h +0 -12
- data/platform/iphone/Classes/NativeBar.m +121 -2
- data/platform/iphone/Classes/NavBar.h +16 -0
- data/platform/iphone/Classes/NavBar.m +115 -0
- data/platform/iphone/Classes/RhoAlert.h +19 -0
- data/platform/iphone/Classes/RhoAlert.m +258 -0
- data/platform/iphone/Classes/RhoDelegate.m +1 -0
- data/platform/iphone/Classes/RhoMainView.h +33 -0
- data/platform/iphone/Classes/Rhodes.h +56 -0
- data/platform/iphone/Classes/Rhodes.m +533 -0
- data/platform/iphone/Classes/RingtoneManager.h +17 -0
- data/platform/iphone/Classes/RingtoneManager.m +73 -0
- data/platform/iphone/Classes/SimpleMainView.h +30 -0
- data/platform/iphone/Classes/SimpleMainView.m +380 -0
- data/platform/iphone/Classes/TabbedMainView.h +24 -0
- data/platform/iphone/Classes/TabbedMainView.m +202 -0
- data/platform/iphone/Classes/WebView.m +123 -0
- data/platform/iphone/Classes/rho/net/NetRequestImpl.m +2 -2
- data/platform/iphone/Classes/rho/net/sslimpl.cpp +13 -1
- data/platform/iphone/Classes/rho/net/sslimpl.h +1 -1
- data/platform/iphone/Info.plist +1 -1
- data/platform/iphone/RhoLib/RhoLib.xcodeproj/project.pbxproj +44 -0
- data/platform/iphone/main.m +1 -2
- data/platform/iphone/rbuild/iphone.rake +8 -16
- data/platform/iphone/rhoextlib/dosyscall.c +1 -1
- data/platform/iphone/rhoextlib/rhoextlib.xcodeproj/project.pbxproj +6 -4
- data/platform/iphone/rhorubylib/rhorubylib.xcodeproj/project.pbxproj +12 -0
- data/platform/iphone/rhorunner.xcodeproj/project.pbxproj +97 -62
- data/platform/iphone/rhosynclib/rhosynclib.xcodeproj/project.pbxproj +12 -0
- data/platform/osx/Rhodes Launcher/launch.rb +14 -21
- data/platform/shared/common/AppMenu.cpp +122 -0
- data/platform/shared/common/AppMenu.h +46 -0
- data/platform/shared/common/PosixThreadImpl.cpp +1 -1
- data/platform/shared/common/RhoConf.cpp +27 -2
- data/platform/shared/common/RhoConf.h +5 -0
- data/platform/shared/common/RhoFilePath.h +21 -0
- data/platform/shared/common/RhoStd.h +44 -5
- data/platform/shared/common/RhoTime.h +20 -7
- data/platform/shared/common/RhodesApp.cpp +236 -177
- data/platform/shared/common/RhodesApp.h +36 -13
- data/platform/shared/common/SplashScreen.cpp +2 -2
- data/platform/shared/common/StringConverter.h +10 -11
- data/platform/shared/common/rhoparams.c +0 -6
- data/platform/shared/curl/lib/rhossl.c +3 -2
- data/platform/shared/curl/lib/url.c +0 -5
- data/platform/shared/db/DBAdapter.cpp +304 -81
- data/platform/shared/db/DBAdapter.h +24 -7
- data/platform/shared/db/DBAttrManager.cpp +83 -30
- data/platform/shared/db/DBAttrManager.h +6 -0
- data/platform/shared/db/DBResult.h +15 -4
- data/platform/shared/json/JSONIterator.cpp +100 -3
- data/platform/shared/json/JSONIterator.h +28 -3
- data/platform/shared/net/AsyncHttp.cpp +25 -22
- data/platform/shared/net/AsyncHttp.h +10 -6
- data/platform/shared/net/CURLNetRequest.cpp +115 -36
- data/platform/shared/net/CURLNetRequest.h +6 -0
- data/platform/shared/net/HttpServer.cpp +6 -4
- data/platform/shared/net/HttpServer.h +0 -1
- data/platform/shared/net/INetRequest.h +19 -3
- data/platform/shared/net/URI.cpp +2 -2
- data/platform/shared/net/ssl.cpp +2 -2
- data/platform/shared/net/ssl.h +2 -2
- data/platform/shared/ruby/ext/alert/alert.i +14 -2
- data/platform/shared/ruby/ext/alert/alert_wrap.c +40 -20
- data/platform/shared/ruby/ext/asynchttp/asynchttp.i +8 -8
- data/platform/shared/ruby/ext/asynchttp/asynchttp_wrap.c +112 -16
- data/platform/shared/ruby/ext/geolocation/geolocation.i +16 -12
- data/platform/shared/ruby/ext/geolocation/geolocation_wrap.c +481 -125
- data/platform/shared/ruby/ext/navbar/navbar.i +20 -0
- data/platform/shared/ruby/ext/navbar/navbar_wrap.c +1859 -0
- data/platform/shared/ruby/ext/rho/extensions.c +1 -1
- data/platform/shared/ruby/ext/rho/rhoruby.c +32 -2
- data/platform/shared/ruby/ext/rho/rhoruby.h +7 -2
- data/platform/shared/ruby/ext/rhoconf/rhoconf.i +4 -0
- data/platform/shared/ruby/ext/rhoconf/rhoconf_wrap.c +31 -0
- data/platform/shared/ruby/ext/sqlite3_api/sqlite3_api_wrap.c +188 -3226
- data/platform/shared/ruby/ext/syncengine/syncengine.i +14 -25
- data/platform/shared/ruby/ext/syncengine/syncengine_wrap.c +96 -104
- data/platform/shared/ruby/ext/system/system.i +12 -0
- data/platform/shared/ruby/ext/system/system_wrap.c +101 -7
- data/platform/shared/ruby/ext/webview/webview.i +20 -15
- data/platform/shared/ruby/ext/webview/webview_wrap.c +42 -16
- data/platform/shared/ruby/thread_pthread.c +4 -4
- data/platform/shared/ruby/thread_win32.c +4 -4
- data/platform/shared/ruby/wince/io_wce.c +0 -1
- data/platform/shared/rubyJVM/src/com/rho/FilePath.java +18 -2
- data/platform/shared/rubyJVM/src/com/rho/IRhoRubyHelper.java +1 -0
- data/platform/shared/rubyJVM/src/com/rho/Properties.java +9 -0
- data/platform/shared/rubyJVM/src/com/rho/RhoClassFactory.java +2 -3
- data/platform/shared/rubyJVM/src/com/rho/RhoConf.java +47 -8
- data/platform/shared/rubyJVM/src/com/rho/RhoLogConf.java +1 -0
- data/platform/shared/rubyJVM/src/com/rho/RhoLogFileSink.java +1 -0
- data/platform/shared/rubyJVM/src/com/rho/RhoRuby.java +43 -5
- data/platform/shared/rubyJVM/src/com/rho/RhodesApp.java +98 -3
- data/platform/shared/rubyJVM/src/com/rho/db/DBAdapter.java +460 -175
- data/platform/shared/rubyJVM/src/com/rho/db/DBAttrManager.java +81 -33
- data/platform/shared/rubyJVM/src/com/rho/db/IDBCallback.java +3 -5
- data/platform/shared/rubyJVM/src/com/rho/db/IDBResult.java +2 -0
- data/platform/shared/rubyJVM/src/com/rho/db/IDBStorage.java +2 -0
- data/platform/shared/rubyJVM/src/com/rho/{IFile.java → file/IFile.java} +1 -1
- data/platform/shared/rubyJVM/src/com/rho/{IFileAccess.java → file/IFileAccess.java} +1 -1
- data/platform/shared/rubyJVM/src/com/rho/{IRAFile.java → file/IRAFile.java} +1 -1
- data/platform/{bb/Hsqldb/src/com/rho/db → shared/rubyJVM/src/com/rho/file}/RandomAccessFile.java +1 -2
- data/platform/shared/rubyJVM/src/com/rho/{SimpleFile.java → file/SimpleFile.java} +5 -1
- data/platform/shared/rubyJVM/src/com/rho/net/AsyncHttp.java +23 -18
- data/platform/shared/rubyJVM/src/com/rho/net/NetRequest.java +167 -250
- data/platform/shared/rubyJVM/src/com/rho/net/RhoConnection.java +100 -30
- data/platform/shared/rubyJVM/src/com/rho/net/URI.java +0 -1
- data/platform/shared/rubyJVM/src/com/rho/sync/ClientRegister.java +30 -33
- data/platform/shared/rubyJVM/src/com/rho/sync/ISyncProtocol.java +20 -0
- data/platform/shared/rubyJVM/src/com/rho/sync/JSONEntry.java +5 -0
- data/platform/shared/rubyJVM/src/com/rho/sync/JSONStructIterator.java +74 -0
- data/platform/shared/rubyJVM/src/com/rho/sync/SyncEngine.java +486 -257
- data/platform/shared/rubyJVM/src/com/rho/sync/SyncNotify.java +89 -58
- data/platform/shared/rubyJVM/src/com/rho/sync/SyncProtocol_3.java +79 -0
- data/platform/shared/rubyJVM/src/com/rho/sync/SyncSource.java +634 -495
- data/platform/shared/rubyJVM/src/com/rho/sync/SyncThread.java +74 -90
- data/platform/shared/rubyJVM/src/com/xruby/GeneratedMethods/RubySymbol_Methods.java +1 -0
- data/platform/shared/rubyJVM/src/com/xruby/runtime/builtin/RubyThread.java +6 -0
- data/platform/shared/rubyJVM/src/com/xruby/runtime/lang/RubyRuntime.java +6 -2
- data/platform/shared/rubyJVM/src/com/xruby/runtime/lang/RubySymbol.java +17 -1
- data/platform/shared/rubyJVM/src/com/xruby/runtime/lang/RubyValue.java +1 -0
- data/platform/shared/rubyJVM/src/org/json/me/JSONObject.java +3 -0
- data/platform/shared/rubyext/GeoLocation.cpp +23 -0
- data/platform/shared/rubyext/GeoLocation.h +2 -0
- data/platform/shared/rubyext/RhoRuby.cpp +31 -0
- data/platform/shared/rubyext/RhoRuby.h +32 -0
- data/platform/shared/rubyext/System.cpp +14 -3
- data/platform/shared/rubyext/WebView.h +21 -0
- data/platform/shared/sync/ClientRegister.cpp +23 -28
- data/platform/shared/sync/ClientRegister.h +6 -2
- data/platform/shared/sync/ISyncProtocol.h +29 -0
- data/platform/shared/sync/SyncEngine.cpp +450 -190
- data/platform/shared/sync/SyncEngine.h +28 -38
- data/platform/shared/sync/SyncNotify.cpp +43 -41
- data/platform/shared/sync/SyncNotify.h +7 -7
- data/platform/shared/sync/SyncProtocol_3.h +86 -0
- data/platform/shared/sync/SyncSource.cpp +535 -371
- data/platform/shared/sync/SyncSource.h +48 -55
- data/platform/shared/sync/SyncThread.cpp +59 -103
- data/platform/shared/sync/SyncThread.h +10 -23
- data/platform/shared/unzip/unzip.cpp +3 -2
- data/platform/shared/unzip/unzip.h +5 -1
- data/platform/shared/wtl80/include/atlapp.h +10 -10
- data/platform/wm/RhoLib/RhoLib.vcproj +32 -0
- data/platform/wm/build/build_inf.js +40 -3
- data/platform/wm/build/wm.rake +95 -9
- data/platform/wm/rhodes/Alert.cpp +4 -0
- data/platform/wm/rhodes/DateTimePicker.cpp +183 -0
- data/platform/wm/rhodes/DateTimePicker.h +100 -0
- data/platform/wm/rhodes/MainWindow.cpp +222 -209
- data/platform/wm/rhodes/MainWindow.h +28 -35
- data/platform/wm/rhodes/Rhodes.cpp +20 -60
- data/platform/wm/rhodes/Rhodes.rc +41 -7
- data/platform/wm/rhodes/Utils.cpp +65 -0
- data/platform/wm/rhodes/Utils.h +9 -0
- data/platform/wm/rhodes/camera/Camera.cpp +2 -2
- data/platform/wm/rhodes/menubar.cpp +2 -33
- data/platform/wm/rhodes/menubar.h +0 -14
- data/platform/wm/rhodes/resource.h +13 -11
- data/platform/wm/rhodes/rho/net/NetRequest.cpp +16 -35
- data/platform/wm/rhodes/rho/net/NetRequest.h +8 -2
- data/platform/wm/rhodes/rho/net/NetRequestImpl.cpp +264 -46
- data/platform/wm/rhodes/rho/net/NetRequestImpl.h +14 -4
- data/platform/wm/rhodes/rho/rubyext/GeoLocationImpl.cpp +1 -1
- data/platform/wm/rhodes/rho/rubyext/GeoLocationImpl.h +1 -1
- data/platform/wm/rhodes/rho/rubyext/SystemImpl.cpp +77 -4
- data/platform/wm/rhodes/rho/rubyext/WebView.cpp +63 -0
- data/platform/wm/rhodes/rhodes.vcproj +20 -66
- data/platform/wm/rhodes/stdafx.h +22 -0
- data/platform/wm/rubylib/rubylib.vcproj +4 -0
- data/platform/wm/syncengine/syncengine.vcproj +8 -0
- data/platform/wm/tools/detool.sln +66 -0
- data/platform/wm/tools/detool/DEMComInterface.tlb +0 -0
- data/platform/wm/tools/detool/ReadMe.txt +33 -0
- data/platform/wm/tools/detool/detool.cpp +559 -0
- data/platform/wm/tools/detool/detool.h +5 -0
- data/platform/wm/tools/detool/detool.vcproj +233 -0
- data/platform/wm/tools/detool/stdafx.cpp +8 -0
- data/platform/wm/tools/detool/stdafx.h +15 -0
- data/platform/wm/tools/detool/targetver.h +24 -0
- data/platform/wm/tools/rhosetup/ReadMe.txt +41 -0
- data/platform/wm/tools/rhosetup/rhosetup.cpp +52 -0
- data/platform/wm/tools/rhosetup/rhosetup.vcproj +641 -0
- data/platform/wm/tools/rhosetup/stdafx.cpp +8 -0
- data/platform/wm/tools/rhosetup/stdafx.h +59 -0
- data/rakefile.rb +33 -10
- data/res/build-tools/db/syncdb.schema +25 -23
- data/res/build-tools/db/syncdb.triggers +1 -1
- data/res/build-tools/detool.exe +0 -0
- data/res/build-tools/rhosetup.dll +0 -0
- data/res/generators/rhogen.rb +27 -22
- data/res/generators/templates/application/app/Settings/controller.rb +3 -1
- data/res/generators/templates/application/app/Settings/home.bb.erb +17 -0
- data/res/generators/templates/application/app/Settings/home.erb +21 -12
- data/res/generators/templates/application/app/Settings/index.bb.erb +32 -0
- data/res/generators/templates/application/app/Settings/index.erb +44 -15
- data/res/generators/templates/application/app/Settings/login.bb.erb +35 -0
- data/res/generators/templates/application/app/Settings/login.erb +29 -30
- data/res/generators/templates/application/app/Settings/reset.bb.erb +15 -0
- data/res/generators/templates/application/app/Settings/reset.erb +16 -13
- data/res/generators/templates/application/app/Settings/wait.bb.erb +3 -0
- data/res/generators/templates/application/app/Settings/wait.erb +4 -4
- data/res/generators/templates/application/app/application.rb +8 -0
- data/res/generators/templates/application/app/helpers/browser_helper.rb +13 -0
- data/res/generators/templates/application/app/index.bb.erb +26 -0
- data/res/generators/templates/application/app/index.erb +21 -12
- data/res/generators/templates/application/app/layout.erb +9 -11
- data/res/generators/templates/application/public/css/android.css +285 -0
- data/res/generators/templates/application/public/css/blackberry.css +85 -78
- data/res/generators/templates/application/public/css/iphone.css +286 -296
- data/res/generators/templates/application/public/css/webkit.css +34 -0
- data/res/generators/templates/application/public/css/windows_mobile.css +208 -0
- data/res/generators/templates/application/public/icons/Read me first - license.txt +14 -0
- data/res/generators/templates/application/public/icons/about.png +0 -0
- data/res/generators/templates/application/public/icons/airplane.png +0 -0
- data/res/generators/templates/application/public/icons/baby.png +0 -0
- data/res/generators/templates/application/public/icons/badge.png +0 -0
- data/res/generators/templates/application/public/icons/bandaid.png +0 -0
- data/res/generators/templates/application/public/icons/bar-chart.png +0 -0
- data/res/generators/templates/application/public/icons/battery.png +0 -0
- data/res/generators/templates/application/public/icons/beaker.png +0 -0
- data/res/generators/templates/application/public/icons/beaker2.png +0 -0
- data/res/generators/templates/application/public/icons/beermug.png +0 -0
- data/res/generators/templates/application/public/icons/bird.png +0 -0
- data/res/generators/templates/application/public/icons/book.png +0 -0
- data/res/generators/templates/application/public/icons/bookmark.png +0 -0
- data/res/generators/templates/application/public/icons/brightness.png +0 -0
- data/res/generators/templates/application/public/icons/bug.png +0 -0
- data/res/generators/templates/application/public/icons/cabinet.png +0 -0
- data/res/generators/templates/application/public/icons/calendar.png +0 -0
- data/res/generators/templates/application/public/icons/camera.png +0 -0
- data/res/generators/templates/application/public/icons/changeName.rb +22 -0
- data/res/generators/templates/application/public/icons/chat2.png +0 -0
- data/res/generators/templates/application/public/icons/chicken.png +0 -0
- data/res/generators/templates/application/public/icons/clock.png +0 -0
- data/res/generators/templates/application/public/icons/cloud.png +0 -0
- data/res/generators/templates/application/public/icons/coffee.png +0 -0
- data/res/generators/templates/application/public/icons/compass.png +0 -0
- data/res/generators/templates/application/public/icons/contrast.png +0 -0
- data/res/generators/templates/application/public/icons/dashboard.png +0 -0
- data/res/generators/templates/application/public/icons/display.png +0 -0
- data/res/generators/templates/application/public/icons/dogpaw.png +0 -0
- data/res/generators/templates/application/public/icons/download.png +0 -0
- data/res/generators/templates/application/public/icons/dumbbell.png +0 -0
- data/res/generators/templates/application/public/icons/ekg.png +0 -0
- data/res/generators/templates/application/public/icons/envelope.png +0 -0
- data/res/generators/templates/application/public/icons/equalizer.png +0 -0
- data/res/generators/templates/application/public/icons/eye.png +0 -0
- data/res/generators/templates/application/public/icons/film-roll.png +0 -0
- data/res/generators/templates/application/public/icons/flag.png +0 -0
- data/res/generators/templates/application/public/icons/fork-and-knife.png +0 -0
- data/res/generators/templates/application/public/icons/fuel.png +0 -0
- data/res/generators/templates/application/public/icons/gameplan.png +0 -0
- data/res/generators/templates/application/public/icons/gear.png +0 -0
- data/res/generators/templates/application/public/icons/gear2.png +0 -0
- data/res/generators/templates/application/public/icons/gift.png +0 -0
- data/res/generators/templates/application/public/icons/heart.png +0 -0
- data/res/generators/templates/application/public/icons/house.png +0 -0
- data/res/generators/templates/application/public/icons/inbox.png +0 -0
- data/res/generators/templates/application/public/icons/index-cards.png +0 -0
- data/res/generators/templates/application/public/icons/iphone.png +0 -0
- data/res/generators/templates/application/public/icons/ipod.png +0 -0
- data/res/generators/templates/application/public/icons/key.png +0 -0
- data/res/generators/templates/application/public/icons/lifebuoy.png +0 -0
- data/res/generators/templates/application/public/icons/lightbulb.png +0 -0
- data/res/generators/templates/application/public/icons/line-chart.png +0 -0
- data/res/generators/templates/application/public/icons/location.png +0 -0
- data/res/generators/templates/application/public/icons/lock.png +0 -0
- data/res/generators/templates/application/public/icons/loopback.png +0 -0
- data/res/generators/templates/application/public/icons/magnifying-glass.png +0 -0
- data/res/generators/templates/application/public/icons/map-marker.png +0 -0
- data/res/generators/templates/application/public/icons/map.png +0 -0
- data/res/generators/templates/application/public/icons/medical-bag.png +0 -0
- data/res/generators/templates/application/public/icons/medical.png +0 -0
- data/res/generators/templates/application/public/icons/microphone.png +0 -0
- data/res/generators/templates/application/public/icons/movie1.png +0 -0
- data/res/generators/templates/application/public/icons/movie2.png +0 -0
- data/res/generators/templates/application/public/icons/network.png +0 -0
- data/res/generators/templates/application/public/icons/note.png +0 -0
- data/res/generators/templates/application/public/icons/outlet.png +0 -0
- data/res/generators/templates/application/public/icons/palette.png +0 -0
- data/res/generators/templates/application/public/icons/paperclip.png +0 -0
- data/res/generators/templates/application/public/icons/phone.png +0 -0
- data/res/generators/templates/application/public/icons/photos.png +0 -0
- data/res/generators/templates/application/public/icons/piano.png +0 -0
- data/res/generators/templates/application/public/icons/picture-frame.png +0 -0
- data/res/generators/templates/application/public/icons/pill.png +0 -0
- data/res/generators/templates/application/public/icons/pin.png +0 -0
- data/res/generators/templates/application/public/icons/pinetree.png +0 -0
- data/res/generators/templates/application/public/icons/planet.png +0 -0
- data/res/generators/templates/application/public/icons/puzzle.png +0 -0
- data/res/generators/templates/application/public/icons/radar.png +0 -0
- data/res/generators/templates/application/public/icons/redo.png +0 -0
- data/res/generators/templates/application/public/icons/refresh.png +0 -0
- data/res/generators/templates/application/public/icons/runner.png +0 -0
- data/res/generators/templates/application/public/icons/shoebox.png +0 -0
- data/res/generators/templates/application/public/icons/shopping-bag.png +0 -0
- data/res/generators/templates/application/public/icons/shopping-cart.png +0 -0
- data/res/generators/templates/application/public/icons/shuffle.png +0 -0
- data/res/generators/templates/application/public/icons/signpost.png +0 -0
- data/res/generators/templates/application/public/icons/skull-n-crossbones.png +0 -0
- data/res/generators/templates/application/public/icons/skull.png +0 -0
- data/res/generators/templates/application/public/icons/sliders.png +0 -0
- data/res/generators/templates/application/public/icons/spraycan.png +0 -0
- data/res/generators/templates/application/public/icons/squiggle.png +0 -0
- data/res/generators/templates/application/public/icons/star.png +0 -0
- data/res/generators/templates/application/public/icons/stopwatch.png +0 -0
- data/res/generators/templates/application/public/icons/suitcase.png +0 -0
- data/res/generators/templates/application/public/icons/tag.png +0 -0
- data/res/generators/templates/application/public/icons/tags.png +0 -0
- data/res/generators/templates/application/public/icons/target.png +0 -0
- data/res/generators/templates/application/public/icons/testtube.png +0 -0
- data/res/generators/templates/application/public/icons/thermometer.png +0 -0
- data/res/generators/templates/application/public/icons/toolbox.png +0 -0
- data/res/generators/templates/application/public/icons/trophy.png +0 -0
- data/res/generators/templates/application/public/icons/tshirt.png +0 -0
- data/res/generators/templates/application/public/icons/tv.png +0 -0
- data/res/generators/templates/application/public/icons/umbrella.png +0 -0
- data/res/generators/templates/application/public/icons/walk.png +0 -0
- data/res/generators/templates/application/public/icons/weather.png +0 -0
- data/res/generators/templates/application/public/icons/widescreen.png +0 -0
- data/res/generators/templates/application/public/icons/wineglass.png +0 -0
- data/res/generators/templates/application/public/icons/zap.png +0 -0
- data/res/generators/templates/application/public/images/android/btn_check_off.png +0 -0
- data/res/generators/templates/application/public/images/android/btn_check_on.png +0 -0
- data/res/generators/templates/application/public/images/android/btn_radio_off.png +0 -0
- data/res/generators/templates/application/public/images/android/btn_radio_on.png +0 -0
- data/res/generators/templates/application/public/images/android/ic_menu_more.png +0 -0
- data/res/generators/templates/application/public/images/iphone/disclosure.png +0 -0
- data/res/generators/templates/application/public/images/iphone/disclosure_detail.png +0 -0
- data/res/generators/templates/application/public/images/iphone/radiobutton.png +0 -0
- data/res/generators/templates/application/public/images/iphone/select.png +0 -0
- data/res/generators/templates/application/public/images/iphone/switch.png +0 -0
- data/res/generators/templates/application/public/images/listArrow.png +0 -0
- data/res/generators/templates/application/public/images/listArrowDown.png +0 -0
- data/res/generators/templates/model/controller.rb +2 -0
- data/res/generators/templates/model/edit.bb.erb +24 -0
- data/res/generators/templates/model/edit.erb +21 -25
- data/res/generators/templates/model/index.bb.erb +21 -0
- data/res/generators/templates/model/index.erb +28 -14
- data/res/generators/templates/model/new.bb.erb +24 -0
- data/res/generators/templates/model/new.erb +20 -20
- data/res/generators/templates/model/show.bb.erb +21 -0
- data/res/generators/templates/model/show.erb +15 -15
- data/rhobuild.yml +37 -0
- data/rhodes.gemspec +1 -1
- data/spec/framework_spec/app/Account/config.rb +57 -1
- data/spec/framework_spec/app/Case/config.rb +1 -1
- data/spec/framework_spec/app/Customer/config.rb +1 -1
- data/spec/framework_spec/app/Product/config.rb +15 -1
- data/spec/framework_spec/app/spec/fixtures/object_values.txt +90 -90
- data/spec/framework_spec/app/spec/pagination/fixtures/object_values.txt +91 -91
- data/spec/framework_spec/app/spec/rho_spec.rb +1 -1
- data/spec/framework_spec/app/spec/rhom_object_spec.rb +47 -28
- data/spec/framework_spec/app/spec/rhom_spec.rb +8 -8
- data/spec/framework_spec/app/spec/spec_helper.rb +13 -5
- data/spec/framework_spec/app/spec_runner.rb +5 -4
- data/spec/framework_spec/public/css/base.css +0 -1
- data/spec/framework_spec/public/css/iphone.css +0 -1
- data/spec/framework_spec/rhoconfig.txt +3 -1
- metadata +220 -37
- data/platform/bb/rhodes/src/rhomobile/WebView.java +0 -90
- data/platform/iphone/Classes/BarItem.h +0 -27
- data/platform/iphone/Classes/BarItem.m +0 -32
- data/platform/iphone/Classes/JSString.h +0 -12
- data/platform/iphone/Classes/JSString.m +0 -7
- data/platform/iphone/Classes/RhoRunnerAppDelegate.h +0 -48
- data/platform/iphone/Classes/RhoRunnerAppDelegate.m +0 -617
- data/platform/iphone/Classes/Server/ServerHost.h +0 -81
- data/platform/iphone/Classes/Server/ServerHost.m +0 -597
- data/platform/iphone/Classes/Server/WebViewUrl.h +0 -13
- data/platform/iphone/Classes/Server/WebViewUrl.m +0 -8
- data/platform/iphone/Classes/TabBarDelegate.h +0 -39
- data/platform/iphone/Classes/TabBarDelegate.m +0 -151
- data/platform/iphone/Classes/Utils/unzip.cpp +0 -4328
- data/platform/iphone/Classes/Utils/unzip.h +0 -234
- data/platform/iphone/Classes/WebViewController.h +0 -59
- data/platform/iphone/Classes/WebViewController.m +0 -472
- data/platform/wm/rhodes/GetURLDialog.cpp +0 -64
- data/platform/wm/rhodes/GetURLDialog.h +0 -39
- data/res/generators/templates/application/public/css/base.css +0 -39
- data/res/generators/templates/application/public/css/rho.css +0 -3
- data/res/generators/templates/application/public/css/xhtml.css +0 -114
- data/spec/framework_spec/app/Question/config.rb +0 -3
- data/spec/generator_spec/source_generator_spec.rb +0 -27
@@ -18,6 +18,7 @@ import com.xruby.runtime.lang.RhoSupport;
|
|
18
18
|
import com.rho.net.URI;
|
19
19
|
import com.rho.sync.SyncThread;
|
20
20
|
import com.rho.*;
|
21
|
+
import com.rho.file.SimpleFile;
|
21
22
|
|
22
23
|
public class RhoConnection implements IHttpConnection {
|
23
24
|
|
@@ -26,7 +27,7 @@ public class RhoConnection implements IHttpConnection {
|
|
26
27
|
|
27
28
|
/** Request URI **/
|
28
29
|
URI uri;
|
29
|
-
|
30
|
+
String url_external;
|
30
31
|
|
31
32
|
/** Method - GET, POST, HEAD **/
|
32
33
|
String method;
|
@@ -49,9 +50,10 @@ public class RhoConnection implements IHttpConnection {
|
|
49
50
|
|
50
51
|
/** Construct connection using URI **/
|
51
52
|
|
52
|
-
public RhoConnection(URI _uri)
|
53
|
-
|
54
|
-
|
53
|
+
public RhoConnection(URI _uri)
|
54
|
+
{
|
55
|
+
url_external = _uri.toString();
|
56
|
+
uri = new URI(url_external);
|
55
57
|
|
56
58
|
if ( !uri.getPath().startsWith("/apps") )
|
57
59
|
uri.setPath("/apps" + uri.getPath());
|
@@ -59,6 +61,52 @@ public class RhoConnection implements IHttpConnection {
|
|
59
61
|
uri.setPath(uri.getPath());
|
60
62
|
}
|
61
63
|
|
64
|
+
public void resetUrl(String url)
|
65
|
+
{
|
66
|
+
url_external = url;
|
67
|
+
uri = new URI(url_external);
|
68
|
+
|
69
|
+
if ( !uri.getPath().startsWith("/apps") )
|
70
|
+
uri.setPath("/apps" + uri.getPath());
|
71
|
+
else
|
72
|
+
uri.setPath(uri.getPath());
|
73
|
+
|
74
|
+
method = "";
|
75
|
+
responseCode = 200;
|
76
|
+
responseMsg = "OK";
|
77
|
+
contentLength = -1;
|
78
|
+
reqHeaders.clear();
|
79
|
+
resHeaders.clear();
|
80
|
+
requestProcessed = false;
|
81
|
+
|
82
|
+
try{
|
83
|
+
clean();
|
84
|
+
}catch(IOException exc)
|
85
|
+
{
|
86
|
+
LOG.ERROR("clean failed.", exc);
|
87
|
+
}
|
88
|
+
}
|
89
|
+
|
90
|
+
private void clean() throws IOException
|
91
|
+
{
|
92
|
+
if ( m_file != null ){
|
93
|
+
m_file.close();
|
94
|
+
m_file = null;
|
95
|
+
}else if (responseData != null)
|
96
|
+
responseData.close();
|
97
|
+
|
98
|
+
responseData = null;
|
99
|
+
|
100
|
+
if ( postData != null )
|
101
|
+
postData.close();
|
102
|
+
}
|
103
|
+
|
104
|
+
public void close() throws IOException
|
105
|
+
{
|
106
|
+
clean();
|
107
|
+
LOG.TRACE("Close browser connection.");
|
108
|
+
}
|
109
|
+
|
62
110
|
public Object getNativeConnection() {
|
63
111
|
throw new RuntimeException("getNativeConnection - Not implemented");
|
64
112
|
}
|
@@ -193,8 +241,8 @@ public class RhoConnection implements IHttpConnection {
|
|
193
241
|
}
|
194
242
|
|
195
243
|
public String getURL() {
|
196
|
-
LOG.TRACE("getURL: " +
|
197
|
-
return
|
244
|
+
LOG.TRACE("getURL: " + url_external);
|
245
|
+
return url_external;
|
198
246
|
}
|
199
247
|
|
200
248
|
public void setRequestMethod(String method) throws IOException {
|
@@ -319,16 +367,6 @@ public class RhoConnection implements IHttpConnection {
|
|
319
367
|
return responseData;
|
320
368
|
}
|
321
369
|
|
322
|
-
public void close() throws IOException {
|
323
|
-
if ( m_file != null ){
|
324
|
-
m_file.close();
|
325
|
-
m_file = null;
|
326
|
-
}else if (responseData != null)
|
327
|
-
responseData.close();
|
328
|
-
|
329
|
-
responseData = null;
|
330
|
-
}
|
331
|
-
|
332
370
|
public DataOutputStream openDataOutputStream() throws IOException {
|
333
371
|
return new DataOutputStream(postData);
|
334
372
|
}
|
@@ -498,23 +536,38 @@ public class RhoConnection implements IHttpConnection {
|
|
498
536
|
return strTime;
|
499
537
|
}
|
500
538
|
|
501
|
-
protected boolean
|
502
|
-
|
539
|
+
protected boolean isDbFilesPath(String strPath)
|
540
|
+
{
|
541
|
+
return strPath.startsWith("/apps/app/db/db-files") || strPath.startsWith("/apps/db/db-files");
|
542
|
+
}
|
543
|
+
|
544
|
+
protected boolean httpServeFile(String strContType)throws IOException
|
545
|
+
{
|
503
546
|
String strPath = uri.getPath();
|
504
547
|
//if ( !strPath.startsWith("/apps") )
|
505
548
|
// strPath = "/apps" + strPath;
|
506
549
|
|
507
|
-
LOG.
|
508
|
-
|
509
|
-
|
510
|
-
|
511
|
-
|
512
|
-
responseData =
|
550
|
+
LOG.TRACE("httpServeFile: " + strPath);
|
551
|
+
|
552
|
+
if ( !isDbFilesPath(strPath) )
|
553
|
+
{
|
554
|
+
if ( strContType.equals("application/javascript")){
|
555
|
+
responseData = RhoRuby.loadFile(strPath);
|
556
|
+
if ( responseData == null ){
|
557
|
+
String str = "";
|
558
|
+
responseData = new ByteArrayInputStream(str.getBytes());
|
559
|
+
}
|
513
560
|
}
|
561
|
+
else
|
562
|
+
responseData = RhoRuby.loadFile(strPath);
|
563
|
+
}else
|
564
|
+
{
|
565
|
+
if ( strPath.startsWith("/apps/app/db/db-files") )
|
566
|
+
strPath = strPath.substring(9);// remove /apps/app
|
567
|
+
else
|
568
|
+
strPath = strPath.substring(5);// remove /apps
|
514
569
|
}
|
515
|
-
|
516
|
-
responseData = RhoRuby.loadFile(strPath);
|
517
|
-
|
570
|
+
|
518
571
|
if (responseData == null){
|
519
572
|
|
520
573
|
SimpleFile file = null;
|
@@ -555,9 +608,22 @@ public class RhoConnection implements IHttpConnection {
|
|
555
608
|
return true;
|
556
609
|
}
|
557
610
|
|
558
|
-
|
611
|
+
private boolean isKnownExtension(String strPath)
|
612
|
+
{
|
613
|
+
int nDot = strPath.lastIndexOf('.');
|
614
|
+
if ( nDot >= 0 )
|
615
|
+
{
|
616
|
+
String strExt = strPath.substring(nDot+1);
|
617
|
+
return strExt.equalsIgnoreCase("png") || strExt.equalsIgnoreCase("jpg") ||
|
618
|
+
strExt.equalsIgnoreCase("css") || strExt.equalsIgnoreCase("js");
|
619
|
+
}
|
559
620
|
|
560
|
-
|
621
|
+
return false;
|
622
|
+
}
|
623
|
+
|
624
|
+
protected boolean httpGetFile(String strContType)throws IOException
|
625
|
+
{
|
626
|
+
if ( !isDbFilesPath(uri.getPath()) && !isKnownExtension(uri.getPath()) && strContType.length() == 0 )
|
561
627
|
{
|
562
628
|
String strTemp = FilePath.join(uri.getPath(), "/");
|
563
629
|
|
@@ -588,7 +654,11 @@ public class RhoConnection implements IHttpConnection {
|
|
588
654
|
if ( model.equalsIgnoreCase("geolocation") ){
|
589
655
|
showGeoLocation();
|
590
656
|
return true;
|
657
|
+
}else if ( model.equalsIgnoreCase("loadserversources") ){
|
658
|
+
RhoRuby.loadserversources(postData.toString());
|
659
|
+
return true;
|
591
660
|
}
|
661
|
+
|
592
662
|
}else if ( application.equalsIgnoreCase("shared") )
|
593
663
|
return false;
|
594
664
|
|
@@ -700,7 +770,7 @@ public class RhoConnection implements IHttpConnection {
|
|
700
770
|
if (!requestProcessed) {
|
701
771
|
String strErr = "";
|
702
772
|
|
703
|
-
LOG.
|
773
|
+
LOG.TRACE("processRequest: " + getURL() );
|
704
774
|
|
705
775
|
String strContType = getContentType();
|
706
776
|
if ( this.method.equals("POST") || strContType.length() == 0 )
|
@@ -9,6 +9,7 @@ import com.rho.RhoThread;
|
|
9
9
|
import com.rho.db.IDBResult;
|
10
10
|
import com.rho.net.NetRequest;
|
11
11
|
import com.rho.net.NetResponse;
|
12
|
+
import com.rho.db.DBAdapter;
|
12
13
|
|
13
14
|
public class ClientRegister extends RhoThread
|
14
15
|
{
|
@@ -16,13 +17,15 @@ public class ClientRegister extends RhoThread
|
|
16
17
|
new RhoLogger("ClientRegister");
|
17
18
|
|
18
19
|
private static final int WAIT_BEFOREKILL_SECONDS = 3;
|
19
|
-
private static final int POLL_INTERVAL_SECONDS =
|
20
|
+
private static final int POLL_INTERVAL_SECONDS = 60;
|
21
|
+
private static final int POLL_INTERVAL_INFINITE = Integer.MAX_VALUE/1000;
|
20
22
|
public static final int DEFAULT_PUSH_PORT = 100;
|
21
23
|
|
22
24
|
static ClientRegister m_pInstance;
|
23
25
|
IRhoRubyHelper m_sysInfo;
|
24
26
|
NetRequest m_NetRequest;
|
25
27
|
String m_strDevicePin;
|
28
|
+
int m_nPollInterval;
|
26
29
|
|
27
30
|
private NetRequest getNet() { return m_NetRequest;}
|
28
31
|
|
@@ -50,9 +53,10 @@ public class ClientRegister extends RhoThread
|
|
50
53
|
m_sysInfo = RhoClassFactory.createRhoRubyHelper();
|
51
54
|
m_strDevicePin = m_sysInfo.getDeviceId();
|
52
55
|
m_NetRequest = RhoClassFactory.createNetRequest();
|
56
|
+
m_nPollInterval = POLL_INTERVAL_SECONDS;
|
53
57
|
|
54
|
-
|
55
|
-
|
58
|
+
if ( RhoConf.getInstance().getString("syncserver").length() > 0 )
|
59
|
+
start(epLow);
|
56
60
|
}
|
57
61
|
|
58
62
|
public static ClientRegister getInstance(){ return m_pInstance; }
|
@@ -75,35 +79,36 @@ public class ClientRegister extends RhoThread
|
|
75
79
|
LOG.ERROR("doRegister failed", exc);
|
76
80
|
}
|
77
81
|
|
78
|
-
LOG.INFO("Waiting for "+
|
79
|
-
wait(
|
82
|
+
LOG.INFO("Waiting for "+ m_nPollInterval+ " sec to try again to register client");
|
83
|
+
wait(m_nPollInterval);
|
80
84
|
}
|
81
85
|
LOG.INFO( "ClientRegister thread shutdown" );
|
82
86
|
|
83
87
|
}
|
84
88
|
|
85
|
-
public String getRegisterBody()throws Exception
|
89
|
+
public String getRegisterBody(String strClientID)throws Exception
|
86
90
|
{
|
87
91
|
int port = RhoConf.getInstance().getInt("push_port");
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
"&device_type=" + m_sysInfo.getPlatform();
|
92
|
-
|
93
|
-
return strBody;
|
92
|
+
|
93
|
+
return SyncThread.getSyncEngine().getProtocol().getClientRegisterBody( strClientID, m_strDevicePin,
|
94
|
+
port > 0 ? port : DEFAULT_PUSH_PORT, m_sysInfo.getPlatform());
|
94
95
|
}
|
95
96
|
|
96
97
|
private boolean doRegister( SyncEngine oSync )throws Exception
|
97
98
|
{
|
98
99
|
String session = oSync.loadSession();
|
99
100
|
if ( session == null || session.length() == 0 )
|
101
|
+
{
|
102
|
+
m_nPollInterval = POLL_INTERVAL_INFINITE;
|
100
103
|
return false;
|
104
|
+
}
|
105
|
+
m_nPollInterval = POLL_INTERVAL_SECONDS;
|
101
106
|
|
102
107
|
String client_id = oSync.loadClientID();
|
103
108
|
if ( client_id == null || client_id.length() == 0 )
|
104
109
|
return false;
|
105
110
|
|
106
|
-
IDBResult res =
|
111
|
+
IDBResult res = DBAdapter.getUserDB().executeSQL("SELECT token,token_sent from client_info");
|
107
112
|
if ( !res.isEnd() ) {
|
108
113
|
String token = res.getStringByIdx(0);
|
109
114
|
int token_sent = res.getIntByIdx(1);
|
@@ -114,28 +119,20 @@ public class ClientRegister extends RhoThread
|
|
114
119
|
return true;
|
115
120
|
}
|
116
121
|
}
|
117
|
-
|
118
|
-
|
119
|
-
|
122
|
+
|
123
|
+
String strBody = getRegisterBody(client_id);
|
124
|
+
NetResponse resp = getNet().pushData( oSync.getProtocol().getClientRegisterUrl(), strBody, oSync );
|
125
|
+
if( resp.isOK() )
|
120
126
|
{
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
oSync.getDB().executeSQL("UPDATE client_info SET token_sent=?, token=?", new Integer(1), m_strDevicePin );
|
129
|
-
} catch(Exception ex) {
|
130
|
-
LOG.ERROR("Error saving token_sent to the DB...");
|
131
|
-
}
|
132
|
-
LOG.INFO("Registered client sucessfully...");
|
133
|
-
return true;
|
134
|
-
} else {
|
135
|
-
LOG.INFO("Network error POST-ing device pin to the server...");
|
136
|
-
}
|
127
|
+
try {
|
128
|
+
DBAdapter.getUserDB().executeSQL("UPDATE client_info SET token_sent=?, token=?", new Integer(1), m_strDevicePin );
|
129
|
+
} catch(Exception ex) {
|
130
|
+
LOG.ERROR("Error saving token_sent to the DB...");
|
131
|
+
}
|
132
|
+
LOG.INFO("Registered client sucessfully...");
|
133
|
+
return true;
|
137
134
|
} else {
|
138
|
-
LOG.INFO("
|
135
|
+
LOG.INFO("Network error POST-ing device pin to the server...");
|
139
136
|
}
|
140
137
|
|
141
138
|
return false;
|
@@ -0,0 +1,20 @@
|
|
1
|
+
package com.rho.sync;
|
2
|
+
public interface ISyncProtocol
|
3
|
+
{
|
4
|
+
public abstract String getContentType();
|
5
|
+
public abstract int getVersion();
|
6
|
+
|
7
|
+
public abstract String getLoginUrl();
|
8
|
+
public abstract String getLoginBody( String name, String password);
|
9
|
+
public abstract String getClientCreateUrl();
|
10
|
+
|
11
|
+
public abstract String getClientRegisterUrl();
|
12
|
+
public abstract String getClientRegisterBody( String strClientID, String strPin, int nPort, String strType );
|
13
|
+
|
14
|
+
public abstract String getClientResetUrl(String strClientID);
|
15
|
+
public abstract String getClientChangesUrl();
|
16
|
+
|
17
|
+
public abstract String getServerQueryUrl(String strAction);
|
18
|
+
public abstract String getServerQueryBody(String strSrcName, String strClientID, int nPageSize );
|
19
|
+
|
20
|
+
}
|
@@ -0,0 +1,74 @@
|
|
1
|
+
package com.rho.sync;
|
2
|
+
|
3
|
+
import org.json.me.JSONException;
|
4
|
+
import org.json.me.JSONObject;
|
5
|
+
import java.util.Enumeration;
|
6
|
+
class JSONStructIterator
|
7
|
+
{
|
8
|
+
JSONObject m_object;
|
9
|
+
Enumeration m_enumKeys;
|
10
|
+
String m_strCurKey;
|
11
|
+
|
12
|
+
JSONStructIterator(String szData)throws JSONException
|
13
|
+
{
|
14
|
+
m_object = new JSONObject(szData);
|
15
|
+
m_enumKeys = m_object.keys();
|
16
|
+
if ( m_enumKeys != null && m_enumKeys.hasMoreElements() )
|
17
|
+
m_strCurKey = (String)m_enumKeys.nextElement();
|
18
|
+
}
|
19
|
+
|
20
|
+
JSONStructIterator(JSONEntry oEntry, String strName)throws JSONException
|
21
|
+
{
|
22
|
+
m_object = (JSONObject)oEntry.m_object.get(strName);
|
23
|
+
m_enumKeys = m_object.keys();
|
24
|
+
if ( m_enumKeys != null && m_enumKeys.hasMoreElements() )
|
25
|
+
m_strCurKey = (String)m_enumKeys.nextElement();
|
26
|
+
}
|
27
|
+
|
28
|
+
JSONStructIterator(JSONEntry oEntry)
|
29
|
+
{
|
30
|
+
m_object = oEntry.m_object;
|
31
|
+
m_enumKeys = m_object.keys();
|
32
|
+
if ( m_enumKeys != null && m_enumKeys.hasMoreElements() )
|
33
|
+
m_strCurKey = (String)m_enumKeys.nextElement();
|
34
|
+
}
|
35
|
+
|
36
|
+
boolean isEnd()
|
37
|
+
{
|
38
|
+
return m_strCurKey == null;
|
39
|
+
}
|
40
|
+
|
41
|
+
void next()
|
42
|
+
{
|
43
|
+
if ( m_enumKeys != null && m_enumKeys.hasMoreElements() )
|
44
|
+
m_strCurKey = (String)m_enumKeys.nextElement();
|
45
|
+
else
|
46
|
+
m_strCurKey = null;
|
47
|
+
}
|
48
|
+
|
49
|
+
void reset()
|
50
|
+
{
|
51
|
+
m_enumKeys = m_object.keys();
|
52
|
+
if ( !isEnd() )
|
53
|
+
m_strCurKey = (String)m_enumKeys.nextElement();
|
54
|
+
}
|
55
|
+
|
56
|
+
String getCurKey()
|
57
|
+
{
|
58
|
+
return isEnd() ? new String() : m_strCurKey;
|
59
|
+
}
|
60
|
+
|
61
|
+
String getCurString()throws JSONException
|
62
|
+
{
|
63
|
+
return m_object.getString(m_strCurKey);
|
64
|
+
}
|
65
|
+
|
66
|
+
JSONEntry getCurValue()throws JSONException
|
67
|
+
{
|
68
|
+
if ( isEnd() )
|
69
|
+
return new JSONEntry( (JSONObject)null );
|
70
|
+
|
71
|
+
return new JSONEntry( (JSONObject)m_object.getJSONObject(m_strCurKey) );
|
72
|
+
}
|
73
|
+
|
74
|
+
}
|
@@ -39,24 +39,20 @@ public class SyncEngine implements NetRequest.IRhoSession
|
|
39
39
|
private static final RhoProfiler PROF = RhoProfiler.RHO_STRIP_PROFILER ? new RhoEmptyProfiler() :
|
40
40
|
new RhoProfiler();
|
41
41
|
|
42
|
-
public static final int esNone = 0, esSyncAllSources = 1, esSyncSource = 2, esStop =
|
42
|
+
public static final int esNone = 0, esSyncAllSources = 1, esSyncSource = 2, esSearch=3, esStop = 4, esExit = 5;
|
43
43
|
|
44
|
-
static String SYNC_SOURCE_FORMAT() { return "?format=json"; }
|
45
|
-
int SYNC_VERSION() { return 2; }
|
46
|
-
static String SYNC_ASK_ACTION() { return "/ask"; }
|
47
|
-
|
48
44
|
static class SourceID
|
49
45
|
{
|
50
46
|
String m_strName = "";
|
51
|
-
String m_strUrl = "";
|
52
47
|
int m_nID;
|
53
48
|
|
49
|
+
SourceID(int id, String strName ){ m_nID = id; m_strName = strName; }
|
50
|
+
SourceID(String strName ){ m_strName = strName; }
|
51
|
+
|
54
52
|
public String toString()
|
55
53
|
{
|
56
54
|
if ( m_strName.length() > 0 )
|
57
55
|
return "name : " + m_strName;
|
58
|
-
else if ( m_strUrl.length() > 0 )
|
59
|
-
return "url : " + m_strUrl;
|
60
56
|
|
61
57
|
return "# : " + m_nID;
|
62
58
|
}
|
@@ -64,22 +60,15 @@ public class SyncEngine implements NetRequest.IRhoSession
|
|
64
60
|
{
|
65
61
|
if ( m_strName.length() > 0 )
|
66
62
|
return src.getName().equals(m_strName);
|
67
|
-
|
68
|
-
{
|
69
|
-
URI uri1 = new URI(m_strUrl);
|
70
|
-
URI uri2 = new URI(src.getUrl());
|
71
|
-
|
72
|
-
return uri1.getPath().compareTo(uri2.getPath()) == 0;
|
73
|
-
//return src.getUrl().equals(m_strUrl);
|
74
|
-
}
|
75
|
-
|
63
|
+
|
76
64
|
return m_nID == src.getID().intValue();
|
77
65
|
}
|
78
66
|
};
|
79
67
|
|
80
68
|
Vector/*<SyncSource*>*/ m_sources = new Vector();
|
81
|
-
|
69
|
+
Vector/*<String>*/ m_arPartitions = new Vector();
|
82
70
|
NetRequest m_NetRequest;
|
71
|
+
ISyncProtocol m_SyncProtocol;
|
83
72
|
int m_syncState;
|
84
73
|
String m_clientID = "";
|
85
74
|
Mutex m_mxLoadClientID = new Mutex();
|
@@ -87,6 +76,8 @@ public class SyncEngine implements NetRequest.IRhoSession
|
|
87
76
|
SyncNotify m_oSyncNotify = new SyncNotify(this);
|
88
77
|
boolean m_bStopByUser = false;
|
89
78
|
int m_nSyncPageSize = 2000;
|
79
|
+
boolean m_bNoThreaded = false;
|
80
|
+
int m_nErrCode = RhoRuby.ERR_NONE;
|
90
81
|
|
91
82
|
void setState(int eState){ m_syncState = eState; }
|
92
83
|
int getState(){ return m_syncState; }
|
@@ -99,20 +90,31 @@ public class SyncEngine implements NetRequest.IRhoSession
|
|
99
90
|
|
100
91
|
String getClientID(){ return m_clientID; }
|
101
92
|
void setSession(String strSession){m_strSession=strSession;}
|
102
|
-
public String getSession(){ return m_strSession; }
|
103
93
|
boolean isSessionExist(){ return m_strSession != null && m_strSession.length() > 0; }
|
104
|
-
|
94
|
+
|
95
|
+
DBAdapter getUserDB(){ return DBAdapter.getUserDB(); }
|
96
|
+
DBAdapter getDB(String strPartition){ return DBAdapter.getDB(strPartition); }
|
97
|
+
|
98
|
+
//IRhoSession
|
99
|
+
public String getSession(){ return m_strSession; }
|
100
|
+
public String getContentType(){ return getProtocol().getContentType();}
|
101
|
+
|
105
102
|
SyncNotify getNotify(){ return m_oSyncNotify; }
|
106
103
|
NetRequest getNet() { return m_NetRequest;}
|
104
|
+
ISyncProtocol getProtocol(){ return m_SyncProtocol; }
|
107
105
|
|
108
|
-
SyncEngine(
|
109
|
-
m_dbAdapter = db;
|
110
|
-
|
106
|
+
SyncEngine(){
|
111
107
|
m_NetRequest = null;
|
112
|
-
m_syncState = esNone;
|
108
|
+
m_syncState = esNone;
|
109
|
+
|
110
|
+
initProtocol();
|
113
111
|
}
|
114
112
|
|
115
|
-
|
113
|
+
void initProtocol()
|
114
|
+
{
|
115
|
+
m_SyncProtocol = new SyncProtocol_3();
|
116
|
+
}
|
117
|
+
|
116
118
|
int getSyncPageSize() { return m_nSyncPageSize; }
|
117
119
|
void setSyncPageSize(int nPageSize){ m_nSyncPageSize = nPageSize; }
|
118
120
|
|
@@ -120,21 +122,48 @@ public class SyncEngine implements NetRequest.IRhoSession
|
|
120
122
|
m_NetRequest = RhoClassFactory.createNetRequest();
|
121
123
|
}
|
122
124
|
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
125
|
+
void prepareSync(int eState)throws Exception
|
126
|
+
{
|
127
|
+
setState(eState);
|
128
|
+
m_bStopByUser = false;
|
129
|
+
m_nErrCode = RhoRuby.ERR_NONE;
|
130
|
+
|
131
|
+
loadAllSources();
|
132
|
+
|
133
|
+
m_strSession = loadSession();
|
134
|
+
if ( isSessionExist() )
|
135
|
+
{
|
136
|
+
m_clientID = loadClientID();
|
137
|
+
if ( m_nErrCode == RhoRuby.ERR_NONE )
|
138
|
+
{
|
139
|
+
getNotify().cleanLastSyncObjectCount();
|
140
|
+
doBulkSync();
|
141
|
+
|
142
|
+
return;
|
143
|
+
}
|
144
|
+
}else
|
145
|
+
m_nErrCode = RhoRuby.ERR_CLIENTISNOTLOGGEDIN;
|
146
|
+
|
147
|
+
if ( m_sources.size() > 0 )
|
148
|
+
{
|
149
|
+
SyncSource src = (SyncSource)m_sources.elementAt(getStartSource());
|
150
|
+
src.m_nErrCode = m_nErrCode;
|
151
|
+
|
152
|
+
getNotify().fireSyncNotification(src, true, src.m_nErrCode, "");
|
153
|
+
}else
|
154
|
+
getNotify().fireSyncNotification(null, true, m_nErrCode, "");
|
155
|
+
|
156
|
+
stopSync();
|
157
|
+
}
|
158
|
+
|
159
|
+
void doSyncAllSources()
|
160
|
+
{
|
129
161
|
try
|
130
162
|
{
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
m_clientID = loadClientID();
|
136
|
-
getNotify().cleanLastSyncObjectCount();
|
137
|
-
|
163
|
+
prepareSync(esSyncAllSources);
|
164
|
+
|
165
|
+
if ( isContinueSync() )
|
166
|
+
{
|
138
167
|
PROF.CREATE_COUNTER("Net");
|
139
168
|
PROF.CREATE_COUNTER("Parse");
|
140
169
|
PROF.CREATE_COUNTER("DB");
|
@@ -142,9 +171,9 @@ public class SyncEngine implements NetRequest.IRhoSession
|
|
142
171
|
PROF.CREATE_COUNTER("Data1");
|
143
172
|
PROF.CREATE_COUNTER("Pull");
|
144
173
|
PROF.START("Sync");
|
145
|
-
|
146
|
-
|
147
|
-
|
174
|
+
|
175
|
+
syncAllSources();
|
176
|
+
|
148
177
|
PROF.DESTROY_COUNTER("Net");
|
149
178
|
PROF.DESTROY_COUNTER("Parse");
|
150
179
|
PROF.DESTROY_COUNTER("DB");
|
@@ -152,99 +181,189 @@ public class SyncEngine implements NetRequest.IRhoSession
|
|
152
181
|
PROF.DESTROY_COUNTER("Data1");
|
153
182
|
PROF.DESTROY_COUNTER("Pull");
|
154
183
|
PROF.STOP("Sync");
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
SyncSource src = (SyncSource)m_sources.elementAt(getStartSource());
|
159
|
-
//src.m_strError = "Client is not logged in. No sync will be performed.";
|
160
|
-
src.m_nErrCode = RhoRuby.ERR_CLIENTISNOTLOGGEDIN;
|
161
|
-
|
162
|
-
getNotify().fireSyncNotification(src, true, src.m_nErrCode, "");
|
163
|
-
}else
|
164
|
-
getNotify().fireSyncNotification(null, true, RhoRuby.ERR_CLIENTISNOTLOGGEDIN, "");
|
165
|
-
}
|
166
|
-
|
184
|
+
}
|
185
|
+
|
186
|
+
getNotify().cleanCreateObjectErrors();
|
167
187
|
}catch(Exception exc)
|
168
188
|
{
|
169
189
|
LOG.ERROR("Sync failed.", exc);
|
170
190
|
}
|
171
|
-
|
172
|
-
if ( getState() != esExit )
|
173
|
-
setState(esNone);
|
174
|
-
}
|
175
191
|
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
192
|
+
if ( getState() != esExit )
|
193
|
+
setState(esNone);
|
194
|
+
}
|
195
|
+
|
196
|
+
void doSearch(Vector/*<rho::String>*/ arSources, String strParams, String strAction, boolean bSearchSyncChanges, int nProgressStep)
|
197
|
+
{
|
198
|
+
/* prepareSync(esSearch);
|
199
|
+
if ( !isContinueSync() )
|
200
|
+
{
|
201
|
+
if ( getState() != esExit )
|
202
|
+
setState(esNone);
|
203
|
+
|
204
|
+
return;
|
205
|
+
}
|
206
|
+
|
207
|
+
CTimeInterval startTime = CTimeInterval::getCurrentTime();
|
208
|
+
|
209
|
+
if ( bSearchSyncChanges )
|
210
|
+
{
|
211
|
+
for ( int i = 0; i < (int)arSources.size(); i++ )
|
212
|
+
{
|
213
|
+
CSyncSource* pSrc = findSourceByName(arSources.elementAt(i));
|
214
|
+
if ( pSrc != null )
|
215
|
+
pSrc->syncClientChanges();
|
216
|
+
}
|
217
|
+
}
|
218
|
+
|
219
|
+
int nErrCode = 0;
|
220
|
+
while( isContinueSync() )
|
221
|
+
{
|
222
|
+
int nSearchCount = 0;
|
223
|
+
String strUrl = getProtocol().getServerQueryUrl(strAction);
|
224
|
+
String strQuery = getProtocol().getServerQueryBody("", getClientID(), getSyncPageSize());
|
225
|
+
|
226
|
+
if ( strParams.length() > 0 )
|
227
|
+
strQuery += strParams;
|
228
|
+
|
229
|
+
for ( int i = 0; i < (int)arSources.size(); i++ )
|
230
|
+
{
|
231
|
+
CSyncSource* pSrc = findSourceByName(arSources.elementAt(i));
|
232
|
+
if ( pSrc != null )
|
233
|
+
{
|
234
|
+
strQuery += "&sources[][name]=" + pSrc->getName();
|
235
|
+
|
236
|
+
if ( !pSrc->isTokenFromDB() && pSrc->getToken() > 1 )
|
237
|
+
strQuery += "&sources[][token]=" + convertToStringA(pSrc->getToken());
|
238
|
+
}
|
239
|
+
}
|
240
|
+
|
241
|
+
LOG(INFO) + "Call search on server. Url: " + (strUrl+strQuery);
|
242
|
+
NetResponse(resp,getNet().pullData(strUrl+strQuery, this));
|
243
|
+
|
244
|
+
if ( !resp.isOK() )
|
245
|
+
{
|
246
|
+
stopSync();
|
247
|
+
nErrCode = RhoRuby.getErrorFromResponse(resp);
|
248
|
+
continue;
|
249
|
+
}
|
250
|
+
|
251
|
+
const char* szData = resp.getCharData();
|
252
|
+
|
253
|
+
CJSONArrayIterator oJsonArr(szData);
|
254
|
+
|
255
|
+
for( ; !oJsonArr.isEnd() && isContinueSync(); oJsonArr.next() )
|
256
|
+
{
|
257
|
+
CJSONArrayIterator oSrcArr(oJsonArr.getCurItem());
|
258
|
+
|
259
|
+
int nVersion = 0;
|
260
|
+
if ( !oSrcArr.isEnd() && oSrcArr.getCurItem().hasName("version") )
|
261
|
+
{
|
262
|
+
nVersion = oSrcArr.getCurItem().getInt("version");
|
263
|
+
oJsonArr.next();
|
264
|
+
}
|
265
|
+
|
266
|
+
if ( nVersion != getProtocol().getVersion() )
|
267
|
+
{
|
268
|
+
LOG(ERROR) + "Sync server send search data with incompatible version. Client version: " + convertToStringA(getProtocol().getVersion()) +
|
269
|
+
"; Server response version: " + convertToStringA(nVersion);
|
270
|
+
stopSync();
|
271
|
+
nErrCode = RhoRuby.ERR_UNEXPECTEDSERVERRESPONSE;
|
272
|
+
continue;
|
273
|
+
}
|
274
|
+
|
275
|
+
if ( !oSrcArr.getCurItem().hasName("source") )
|
276
|
+
{
|
277
|
+
LOG(ERROR) + "Sync server send search data without source name.";
|
278
|
+
stopSync();
|
279
|
+
nErrCode = RhoRuby.ERR_UNEXPECTEDSERVERRESPONSE;
|
280
|
+
continue;
|
281
|
+
}
|
282
|
+
|
283
|
+
String strSrcName = oSrcArr.getCurItem().getString("source");
|
284
|
+
CSyncSource* pSrc = findSourceByName(strSrcName);
|
285
|
+
if ( pSrc == null )
|
286
|
+
{
|
287
|
+
LOG(ERROR) + "Sync server send search data for unknown source name:" + strSrcName;
|
288
|
+
stopSync();
|
289
|
+
nErrCode = RhoRuby.ERR_UNEXPECTEDSERVERRESPONSE;
|
290
|
+
continue;
|
291
|
+
}
|
292
|
+
|
293
|
+
oSrcArr.reset(0);
|
294
|
+
pSrc->m_bIsSearch = true;
|
295
|
+
pSrc->setProgressStep(nProgressStep);
|
296
|
+
pSrc->processServerResponse_ver3(oSrcArr);
|
297
|
+
|
298
|
+
nSearchCount += pSrc->getCurPageCount();
|
299
|
+
}
|
300
|
+
|
301
|
+
if ( nSearchCount == 0 )
|
302
|
+
break;
|
303
|
+
}
|
304
|
+
|
305
|
+
if ( isContinueSync() )
|
306
|
+
getNotify().fireSyncNotification(null, true, RhoRuby.ERR_NONE, RhoRuby.getMessageText("sync_completed"));
|
307
|
+
else if ( nErrCode != 0 )
|
308
|
+
{
|
309
|
+
CSyncSource& src = *m_sources.elementAt(getStartSource());
|
310
|
+
src.m_nErrCode = nErrCode;
|
311
|
+
src.m_bIsSearch = true;
|
312
|
+
getNotify().fireSyncNotification(&src, true, src.m_nErrCode, "");
|
313
|
+
}
|
314
|
+
|
315
|
+
//update db info
|
316
|
+
CTimeInterval endTime = CTimeInterval::getCurrentTime();
|
317
|
+
unsigned long timeUpdated = CLocalTime().toULong();
|
318
|
+
for ( int i = 0; i < (int)arSources.size(); i++ )
|
319
|
+
{
|
320
|
+
CSyncSource* pSrc = findSourceByName(arSources.elementAt(i));
|
321
|
+
if ( pSrc == null )
|
322
|
+
continue;
|
323
|
+
CSyncSource& oSrc = *pSrc;
|
324
|
+
oSrc.getDB().executeSQL("UPDATE sources set last_updated=?,last_inserted_size=?,last_deleted_size=?, \
|
325
|
+
last_sync_duration=?,last_sync_success=?, backend_refresh_time=? WHERE source_id=?",
|
326
|
+
timeUpdated, oSrc.getInsertedCount(), oSrc.getDeletedCount(),
|
327
|
+
(endTime-startTime).toULong(), oSrc.getGetAtLeastOnePage(), oSrc.getRefreshTime(),
|
328
|
+
oSrc.getID() );
|
329
|
+
}
|
330
|
+
//
|
331
|
+
|
332
|
+
getNotify().cleanCreateObjectErrors();
|
333
|
+
if ( getState() != esExit )
|
334
|
+
setState(esNone);*/
|
335
|
+
}
|
336
|
+
|
337
|
+
void doSyncSource(SourceID oSrcID)
|
338
|
+
{
|
181
339
|
SyncSource src = null;
|
182
340
|
|
183
341
|
try
|
184
342
|
{
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
if ( src != null )
|
343
|
+
prepareSync(esSyncSource);
|
344
|
+
|
345
|
+
if ( isContinueSync() )
|
189
346
|
{
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
}
|
209
|
-
|
210
|
-
m_strSession = loadSession();
|
211
|
-
if ( isSessionExist() ) {
|
212
|
-
m_clientID = loadClientID();
|
213
|
-
if ( getState() != esStop )
|
214
|
-
{
|
215
|
-
getNotify().cleanLastSyncObjectCount();
|
216
|
-
|
217
|
-
PROF.CREATE_COUNTER("Net");
|
218
|
-
PROF.CREATE_COUNTER("Parse");
|
219
|
-
PROF.CREATE_COUNTER("DB");
|
220
|
-
PROF.CREATE_COUNTER("Data");
|
221
|
-
PROF.CREATE_COUNTER("Data1");
|
222
|
-
PROF.CREATE_COUNTER("Pull");
|
223
|
-
PROF.START("Sync");
|
224
|
-
|
225
|
-
src.sync();
|
226
|
-
|
227
|
-
PROF.DESTROY_COUNTER("Net");
|
228
|
-
PROF.DESTROY_COUNTER("Parse");
|
229
|
-
PROF.DESTROY_COUNTER("DB");
|
230
|
-
PROF.DESTROY_COUNTER("Data");
|
231
|
-
PROF.DESTROY_COUNTER("Data1");
|
232
|
-
PROF.DESTROY_COUNTER("Pull");
|
233
|
-
PROF.STOP("Sync");
|
234
|
-
}
|
235
|
-
} else {
|
236
|
-
//src.m_strError = "Client is not logged in. No sync will be performed.";
|
237
|
-
src.m_nErrCode = RhoRuby.ERR_CLIENTISNOTLOGGEDIN;
|
238
|
-
}
|
239
|
-
|
240
|
-
getNotify().fireSyncNotification(src, true, src.m_nErrCode, src.m_nErrCode == RhoRuby.ERR_NONE ? RhoRuby.getMessageText("sync_completed") : "");
|
241
|
-
} else {
|
242
|
-
src = new SyncSource(this);
|
243
|
-
//src.m_strError = "Unknown sync source.";
|
244
|
-
src.m_nErrCode = RhoRuby.ERR_RUNTIME;
|
245
|
-
|
246
|
-
throw new RuntimeException("Sync one source : Unknown Source " + oSrcID.toString() );
|
347
|
+
src = findSource(oSrcID);
|
348
|
+
if ( src != null )
|
349
|
+
{
|
350
|
+
LOG.INFO("Started synchronization of the data source: " + src.getName() );
|
351
|
+
|
352
|
+
src.sync();
|
353
|
+
|
354
|
+
getNotify().fireSyncNotification(src, true, src.m_nErrCode, src.m_nErrCode == RhoRuby.ERR_NONE ? RhoRuby.getMessageText("sync_completed") : "");
|
355
|
+
}else
|
356
|
+
{
|
357
|
+
// LOG.ERROR( "Sync one source : Unknown Source " + oSrcID.toString() );
|
358
|
+
|
359
|
+
src = new SyncSource(this, getUserDB());
|
360
|
+
//src.m_strError = "Unknown sync source.";
|
361
|
+
src.m_nErrCode = RhoRuby.ERR_RUNTIME;
|
362
|
+
|
363
|
+
throw new RuntimeException("Sync one source : Unknown Source " + oSrcID.toString() );
|
364
|
+
}
|
247
365
|
}
|
366
|
+
|
248
367
|
} catch(Exception exc) {
|
249
368
|
LOG.ERROR("Sync source " + oSrcID.toString() + " failed.", exc);
|
250
369
|
|
@@ -253,11 +372,11 @@ public class SyncEngine implements NetRequest.IRhoSession
|
|
253
372
|
|
254
373
|
getNotify().fireSyncNotification(src, true, src.m_nErrCode, "" );
|
255
374
|
}
|
256
|
-
|
257
|
-
|
258
|
-
|
259
|
-
|
260
|
-
|
375
|
+
|
376
|
+
getNotify().cleanCreateObjectErrors();
|
377
|
+
if ( getState() != esExit )
|
378
|
+
setState(esNone);
|
379
|
+
}
|
261
380
|
|
262
381
|
SyncSource findSource(SourceID oSrcID)
|
263
382
|
{
|
@@ -273,29 +392,27 @@ public class SyncEngine implements NetRequest.IRhoSession
|
|
273
392
|
|
274
393
|
SyncSource findSourceByName(String strSrcName)
|
275
394
|
{
|
276
|
-
|
277
|
-
oSrcID.m_strName = strSrcName;
|
278
|
-
return findSource(oSrcID);
|
395
|
+
return findSource(new SourceID(strSrcName));
|
279
396
|
}
|
280
397
|
|
281
398
|
void loadAllSources()throws DBException
|
282
399
|
{
|
283
400
|
m_sources.removeAllElements();
|
284
|
-
|
285
|
-
|
401
|
+
|
402
|
+
IDBResult res = getUserDB().executeSQL("SELECT source_id,sync_type,name, partition from sources ORDER BY priority");
|
286
403
|
for ( ; !res.isEnd(); res.next() )
|
287
404
|
{
|
288
|
-
String
|
289
|
-
if (
|
290
|
-
|
405
|
+
String strShouldSync = res.getStringByIdx(1);
|
406
|
+
if ( strShouldSync.compareTo("none") == 0)
|
407
|
+
continue;
|
408
|
+
|
409
|
+
String strName = res.getStringByIdx(2);
|
410
|
+
String strPartition = res.getStringByIdx(3);
|
291
411
|
|
292
|
-
|
293
|
-
|
294
|
-
strUrl = strUrl.substring(0, strUrl.length()-1);
|
412
|
+
if ( m_arPartitions.indexOf(strPartition) < 0 )
|
413
|
+
m_arPartitions.addElement(strPartition);
|
295
414
|
|
296
|
-
|
297
|
-
if ( strUrl.length() > 0 )
|
298
|
-
m_sources.addElement( new SyncSource( res.getIntByIdx(0), strUrl, name, res.getLongByIdx(2), this) );
|
415
|
+
m_sources.addElement( new SyncSource( res.getIntByIdx(0), strName, strShouldSync, getDB(strPartition), this) );
|
299
416
|
}
|
300
417
|
}
|
301
418
|
|
@@ -306,76 +423,236 @@ public class SyncEngine implements NetRequest.IRhoSession
|
|
306
423
|
synchronized( m_mxLoadClientID )
|
307
424
|
{
|
308
425
|
boolean bResetClient = false;
|
309
|
-
|
310
|
-
|
311
|
-
|
312
|
-
|
313
|
-
|
314
|
-
|
426
|
+
{
|
427
|
+
IDBResult res = getUserDB().executeSQL("SELECT client_id,reset from client_info");
|
428
|
+
if ( !res.isEnd() )
|
429
|
+
{
|
430
|
+
clientID = res.getStringByIdx(0);
|
431
|
+
bResetClient = res.getIntByIdx(1) > 0;
|
432
|
+
}
|
433
|
+
}
|
315
434
|
|
316
435
|
if ( clientID.length() == 0 )
|
317
436
|
{
|
318
437
|
clientID = requestClientIDByNet();
|
319
438
|
|
320
|
-
|
321
|
-
|
439
|
+
IDBResult res = getUserDB().executeSQL("SELECT * FROM client_info");
|
440
|
+
if ( !res.isEnd() )
|
441
|
+
getUserDB().executeSQL("UPDATE client_info SET client_id=?", clientID);
|
442
|
+
else
|
443
|
+
getUserDB().executeSQL("INSERT INTO client_info (client_id) values (?)", clientID);
|
322
444
|
}else if ( bResetClient )
|
323
445
|
{
|
324
446
|
if ( !resetClientIDByNet(clientID) )
|
325
|
-
{
|
326
|
-
if ( m_sources.size() > 0 )
|
327
|
-
{
|
328
|
-
SyncSource src = (SyncSource)m_sources.elementAt(getStartSource());
|
329
|
-
src.m_nErrCode = RhoRuby.ERR_REMOTESERVER;
|
330
|
-
|
331
|
-
getNotify().fireSyncNotification(src, true, src.m_nErrCode, "");
|
332
|
-
}else
|
333
|
-
getNotify().fireSyncNotification(null, true, RhoRuby.ERR_REMOTESERVER, "");
|
334
|
-
|
335
447
|
stopSync();
|
336
|
-
}
|
337
448
|
else
|
338
|
-
|
449
|
+
getUserDB().executeSQL("UPDATE client_info SET reset=? where client_id=?", new Integer(0), clientID );
|
339
450
|
}
|
340
|
-
|
341
451
|
}
|
342
452
|
|
343
453
|
return clientID;
|
344
454
|
}
|
345
455
|
|
456
|
+
void processServerSources(String strSources)throws Exception
|
457
|
+
{
|
458
|
+
if ( strSources.length() > 0 )
|
459
|
+
{
|
460
|
+
NetResponse resp = getNet().pushData( getNet().resolveUrl("/system/loadserversources"), strSources, null);
|
461
|
+
loadAllSources();
|
462
|
+
|
463
|
+
DBAdapter.initAttrManager();
|
464
|
+
}
|
465
|
+
}
|
466
|
+
|
346
467
|
boolean resetClientIDByNet(String strClientID)throws Exception
|
347
468
|
{
|
348
|
-
|
349
|
-
|
350
|
-
|
351
|
-
|
469
|
+
String strBody = "";
|
470
|
+
//TODO: send client register info in client reset
|
471
|
+
// if ( ClientRegister.getInstance() != null )
|
472
|
+
// strBody += ClientRegister.getInstance().getRegisterBody();
|
473
|
+
|
474
|
+
NetResponse resp = getNet().pullData(getProtocol().getClientResetUrl(strClientID), this);
|
475
|
+
/*
|
476
|
+
processServerSources("{\"server_sources\":[{\"name\":\"Product\",\"partition\":\"application\",\"source_id\":\"2\",\"priority\":\"0\","+
|
477
|
+
"\"schema_version\":\"7.0\",\"schema\":{"+
|
478
|
+
"\"columns\":[\'brand\',\'created_at\',\'name\',\'price\',\'quantity\',\'sku\',\'updated_at\']"+
|
479
|
+
"}}]}");
|
480
|
+
*/
|
481
|
+
|
482
|
+
if ( !resp.isOK() )
|
483
|
+
m_nErrCode = RhoRuby.getErrorFromResponse(resp);
|
484
|
+
else
|
485
|
+
{
|
486
|
+
processServerSources(resp.getCharData());
|
487
|
+
}
|
352
488
|
|
353
|
-
NetResponse resp = getNet().pullData(strUrl+strQuery, this);
|
354
489
|
return resp.isOK();
|
355
490
|
}
|
356
|
-
|
491
|
+
|
357
492
|
String requestClientIDByNet()throws Exception
|
358
493
|
{
|
359
|
-
|
360
|
-
|
361
|
-
|
362
|
-
|
363
|
-
|
364
|
-
|
365
|
-
|
366
|
-
NetResponse resp = getNet().pullData(strUrl+strQuery, this);
|
494
|
+
String strBody = "";
|
495
|
+
//TODO: send client register info in client create
|
496
|
+
// if ( ClientRegister.getInstance() != null )
|
497
|
+
// strBody += ClientRegister.getInstance().getRegisterBody();
|
498
|
+
|
499
|
+
NetResponse resp = getNet().pullData(getProtocol().getClientCreateUrl(), this);
|
367
500
|
if ( resp.isOK() && resp.getCharData() != null )
|
368
501
|
{
|
369
502
|
String szData = resp.getCharData();
|
503
|
+
|
370
504
|
JSONEntry oJsonEntry = new JSONEntry(szData);
|
371
505
|
|
506
|
+
if (oJsonEntry.hasName("server_sources") )
|
507
|
+
processServerSources(szData);
|
508
|
+
|
372
509
|
JSONEntry oJsonObject = oJsonEntry.getEntry("client");
|
373
510
|
if ( !oJsonObject.isEmpty() )
|
374
511
|
return oJsonObject.getString("client_id");
|
512
|
+
}else
|
513
|
+
{
|
514
|
+
m_nErrCode = RhoRuby.getErrorFromResponse(resp);
|
515
|
+
if ( m_nErrCode == RhoRuby.ERR_NONE )
|
516
|
+
m_nErrCode = RhoRuby.ERR_UNEXPECTEDSERVERRESPONSE;
|
375
517
|
}
|
376
518
|
|
377
519
|
return "";
|
378
520
|
}
|
521
|
+
|
522
|
+
void doBulkSync()throws Exception
|
523
|
+
{
|
524
|
+
if ( !RhoConf.getInstance().isExist("bulksync_state") )
|
525
|
+
return;
|
526
|
+
|
527
|
+
int nBulkSyncState = RhoConf.getInstance().getInt("bulksync_state");;
|
528
|
+
if ( nBulkSyncState >= 1 || !isContinueSync() )
|
529
|
+
return;
|
530
|
+
|
531
|
+
LOG.INFO("Bulk sync: start");
|
532
|
+
getNotify().fireBulkSyncNotification(false, "start", "", RhoRuby.ERR_NONE);
|
533
|
+
|
534
|
+
for (int i = 0; i < (int)m_arPartitions.size() && isContinueSync(); i++)
|
535
|
+
loadBulkPartition( (String)m_arPartitions.elementAt(i));
|
536
|
+
|
537
|
+
if (isContinueSync())
|
538
|
+
{
|
539
|
+
RhoConf.getInstance().setInt("bulksync_state", 1, true);
|
540
|
+
getNotify().fireBulkSyncNotification(true, "", "", RhoRuby.ERR_NONE);
|
541
|
+
}
|
542
|
+
}
|
543
|
+
|
544
|
+
void loadBulkPartition(String strPartition )throws Exception
|
545
|
+
{
|
546
|
+
DBAdapter dbPartition = getDB(strPartition);
|
547
|
+
String serverUrl = RhoConf.getInstance().getPath("syncserver");
|
548
|
+
String strUrl = serverUrl + "bulk_data";
|
549
|
+
String strQuery = "?client_id=" + m_clientID + "&partition=" + strPartition;
|
550
|
+
String strDataUrl = "", strCmd = "";
|
551
|
+
|
552
|
+
getNotify().fireBulkSyncNotification(false, "start", strPartition, RhoRuby.ERR_NONE);
|
553
|
+
|
554
|
+
while(strCmd.length() == 0&&isContinueSync())
|
555
|
+
{
|
556
|
+
NetResponse resp = getNet().pullData(strUrl+strQuery, this);
|
557
|
+
if ( !resp.isOK() || resp.getCharData() == null )
|
558
|
+
{
|
559
|
+
LOG.ERROR( "Bulk sync failed: server return an error." );
|
560
|
+
stopSync();
|
561
|
+
getNotify().fireBulkSyncNotification(true, "", strPartition, RhoRuby.ERR_REMOTESERVER);
|
562
|
+
return;
|
563
|
+
}
|
564
|
+
|
565
|
+
LOG.INFO("Bulk sync: got response from server: " + resp.getCharData() );
|
566
|
+
|
567
|
+
String szData = resp.getCharData();
|
568
|
+
JSONEntry oJsonEntry = new JSONEntry(szData);
|
569
|
+
strCmd = oJsonEntry.getString("result");
|
570
|
+
if ( oJsonEntry.hasName("url") )
|
571
|
+
strDataUrl = oJsonEntry.getString("url");
|
572
|
+
|
573
|
+
if ( strCmd.compareTo("wait") == 0)
|
574
|
+
{
|
575
|
+
int nTimeout = RhoConf.getInstance().getInt("bulksync_timeout_sec");
|
576
|
+
if ( nTimeout == 0 )
|
577
|
+
nTimeout = 5;
|
578
|
+
|
579
|
+
SyncThread.getInstance().wait(nTimeout);
|
580
|
+
strCmd = "";
|
581
|
+
}
|
582
|
+
}
|
583
|
+
|
584
|
+
if ( strCmd.compareTo("nop") == 0)
|
585
|
+
{
|
586
|
+
LOG.INFO("Bulk sync return no data.");
|
587
|
+
getNotify().fireBulkSyncNotification(true, "", strPartition, RhoRuby.ERR_NONE);
|
588
|
+
return;
|
589
|
+
}
|
590
|
+
|
591
|
+
if ( !isContinueSync() )
|
592
|
+
return;
|
593
|
+
|
594
|
+
getNotify().fireBulkSyncNotification(false, "download", strPartition, RhoRuby.ERR_NONE);
|
595
|
+
|
596
|
+
String fDataName = makeBulkDataFileName(strDataUrl, dbPartition.getDBPath(), "_bulk.data");
|
597
|
+
String strHsqlDataUrl = getHostFromUrl(serverUrl) + strDataUrl + ".hsqldb.data";
|
598
|
+
LOG.INFO("Bulk sync: download data from server: " + strHsqlDataUrl);
|
599
|
+
{
|
600
|
+
NetResponse resp1 = getNet().pullFile(strHsqlDataUrl, fDataName, this, null);
|
601
|
+
if ( !resp1.isOK() )
|
602
|
+
{
|
603
|
+
LOG.ERROR("Bulk sync failed: cannot download database file: " + resp1.getRespCode() );
|
604
|
+
stopSync();
|
605
|
+
getNotify().fireBulkSyncNotification(true, "", strPartition, RhoRuby.ERR_REMOTESERVER);
|
606
|
+
return;
|
607
|
+
}
|
608
|
+
}
|
609
|
+
|
610
|
+
if ( !isContinueSync() )
|
611
|
+
return;
|
612
|
+
|
613
|
+
String fScriptName = makeBulkDataFileName(strDataUrl, dbPartition.getDBPath(), "_bulk.script" );
|
614
|
+
String strHsqlScriptUrl = getHostFromUrl(serverUrl) + strDataUrl + ".hsqldb.script";
|
615
|
+
LOG.INFO("Bulk sync: download script from server: " + strHsqlScriptUrl);
|
616
|
+
{
|
617
|
+
NetResponse resp1 = getNet().pullFile(strHsqlScriptUrl, fScriptName, this, null);
|
618
|
+
if ( !resp1.isOK() )
|
619
|
+
{
|
620
|
+
LOG.ERROR("Bulk sync failed: cannot download database file.");
|
621
|
+
stopSync();
|
622
|
+
getNotify().fireBulkSyncNotification(true, "", strPartition, RhoRuby.ERR_REMOTESERVER);
|
623
|
+
return;
|
624
|
+
}
|
625
|
+
}
|
626
|
+
|
627
|
+
LOG.INFO("Bulk sync: start change db");
|
628
|
+
getNotify().fireBulkSyncNotification(false, "change_db", strPartition, RhoRuby.ERR_NONE);
|
629
|
+
|
630
|
+
dbPartition.setBulkSyncDB(fDataName, fScriptName);
|
631
|
+
|
632
|
+
LOG.INFO("Bulk sync: end change db");
|
633
|
+
getNotify().fireBulkSyncNotification(false, "", strPartition, RhoRuby.ERR_NONE);
|
634
|
+
}
|
635
|
+
|
636
|
+
String makeBulkDataFileName(String strDataUrl, String strDbPath, String strExt)throws Exception
|
637
|
+
{
|
638
|
+
FilePath oUrlPath = new FilePath(strDataUrl);
|
639
|
+
String strNewName = oUrlPath.getBaseName();
|
640
|
+
String strOldName = RhoConf.getInstance().getString("bulksync_filename");
|
641
|
+
if ( strOldName.length() > 0 && strNewName.compareTo(strOldName) != 0 )
|
642
|
+
{
|
643
|
+
FilePath oFilePath = new FilePath(strDbPath);
|
644
|
+
String strFToDelete = oFilePath.changeBaseName(strOldName+strExt);
|
645
|
+
LOG.INFO( "Bulk sync: remove old bulk file '" + strFToDelete + "'" );
|
646
|
+
|
647
|
+
//RhoFile.deleteFile( strFToDelete.c_str() );
|
648
|
+
RhoClassFactory.createFile().delete(strFToDelete);
|
649
|
+
}
|
650
|
+
|
651
|
+
RhoConf.getInstance().setString("bulksync_filename", strNewName, true);
|
652
|
+
|
653
|
+
FilePath oFilePath = new FilePath(strDbPath);
|
654
|
+
return oFilePath.changeBaseName(strNewName+strExt);
|
655
|
+
}
|
379
656
|
|
380
657
|
int getStartSource()
|
381
658
|
{
|
@@ -391,12 +668,17 @@ public class SyncEngine implements NetRequest.IRhoSession
|
|
391
668
|
|
392
669
|
void syncAllSources()throws Exception
|
393
670
|
{
|
671
|
+
//TODO: do not stop on error source
|
394
672
|
boolean bError = false;
|
395
673
|
for( int i = getStartSource(); i < m_sources.size() && isContinueSync(); i++ )
|
396
674
|
{
|
397
675
|
SyncSource src = null;
|
398
676
|
try{
|
399
677
|
src = (SyncSource)m_sources.elementAt(i);
|
678
|
+
|
679
|
+
if ( src.getSyncType().compareTo("bulk_sync_only")==0 )
|
680
|
+
continue;
|
681
|
+
|
400
682
|
if ( isSessionExist() && getState() != esStop )
|
401
683
|
src.sync();
|
402
684
|
|
@@ -417,80 +699,24 @@ public class SyncEngine implements NetRequest.IRhoSession
|
|
417
699
|
getNotify().fireSyncNotification(null, true, RhoRuby.ERR_NONE, RhoRuby.getMessageText("sync_completed"));
|
418
700
|
}
|
419
701
|
|
420
|
-
void callLoginCallback(String callback, int nErrCode, String strMessage)
|
421
|
-
{
|
422
|
-
try{
|
423
|
-
String strBody = "error_code=" + nErrCode;
|
424
|
-
strBody += "&error_message=" + URI.urlEncode(strMessage != null? strMessage : "");
|
425
|
-
strBody += "&rho_callback=1";
|
426
|
-
|
427
|
-
String strUrl = getNet().resolveUrl(callback);
|
428
|
-
|
429
|
-
LOG.INFO( "Login callback: " + callback + ". Body: "+ strBody );
|
430
|
-
|
431
|
-
NetResponse resp = getNet().pushData( strUrl, strBody, this );
|
432
|
-
if ( !resp.isOK() )
|
433
|
-
LOG.ERROR( "Call Login callback failed. Code: " + resp.getRespCode() + "; Error body: " + resp.getCharData() );
|
434
|
-
}catch(Exception exc)
|
435
|
-
{
|
436
|
-
LOG.ERROR("Call Login callback failed.", exc);
|
437
|
-
}
|
438
|
-
}
|
439
|
-
|
440
|
-
boolean checkAllSourcesFromOneDomain()throws Exception
|
441
|
-
{
|
442
|
-
loadAllSources();
|
443
|
-
|
444
|
-
if ( m_sources.size() == 0 )
|
445
|
-
return true;
|
446
|
-
|
447
|
-
//All sources should be from one domain
|
448
|
-
SyncSource src0 = (SyncSource)m_sources.elementAt(0);
|
449
|
-
String srv0 = getServerFromUrl(src0.getUrl());
|
450
|
-
for( int i = 1; i < m_sources.size(); i++ )
|
451
|
-
{
|
452
|
-
SyncSource src = (SyncSource)m_sources.elementAt(i);
|
453
|
-
String srv = getServerFromUrl(src.getUrl());
|
454
|
-
if ( srv.equals( srv0 ) != true )
|
455
|
-
return false;
|
456
|
-
}
|
457
|
-
|
458
|
-
return true;
|
459
|
-
}
|
460
|
-
|
461
702
|
void login(String name, String password, String callback)
|
462
703
|
{
|
463
704
|
try {
|
464
|
-
if ( !checkAllSourcesFromOneDomain() )
|
465
|
-
{
|
466
|
-
callLoginCallback(callback, RhoRuby.ERR_DIFFDOMAINSINSYNCSRC, "");
|
467
|
-
return;
|
468
|
-
}
|
469
|
-
|
470
705
|
NetResponse resp = null;
|
471
|
-
|
706
|
+
|
472
707
|
try{
|
473
708
|
|
474
|
-
|
475
|
-
|
476
|
-
|
477
|
-
resp = getNet().pullCookies( serverUrl+"client_login", strBody, this);
|
478
|
-
|
479
|
-
if ( resp.isUnathorized() )
|
709
|
+
resp = getNet().pullCookies( getProtocol().getLoginUrl(), getProtocol().getLoginBody(name, password), this );
|
710
|
+
int nErrCode = RhoRuby.getErrorFromResponse(resp);
|
711
|
+
if ( nErrCode != RhoRuby.ERR_NONE )
|
480
712
|
{
|
481
|
-
callLoginCallback(callback,
|
482
|
-
|
483
|
-
}
|
484
|
-
|
485
|
-
if ( !resp.isOK() )
|
486
|
-
{
|
487
|
-
callLoginCallback(callback, RhoRuby.ERR_REMOTESERVER, resp.getCharData());
|
488
|
-
return;
|
713
|
+
getNotify().callLoginCallback(callback, nErrCode, resp.getCharData());
|
714
|
+
return;
|
489
715
|
}
|
490
716
|
}catch(IOException exc)
|
491
717
|
{
|
492
718
|
LOG.ERROR("Login failed.", exc);
|
493
|
-
callLoginCallback(callback, RhoRuby.getNetErrorCode(exc), "" );
|
719
|
+
getNotify().callLoginCallback(callback, RhoRuby.getNetErrorCode(exc), "" );
|
494
720
|
return;
|
495
721
|
}
|
496
722
|
|
@@ -498,40 +724,43 @@ public class SyncEngine implements NetRequest.IRhoSession
|
|
498
724
|
if ( strSession == null || strSession.length() == 0 )
|
499
725
|
{
|
500
726
|
LOG.ERROR("Return empty session.");
|
501
|
-
callLoginCallback(callback, RhoRuby.ERR_UNEXPECTEDSERVERRESPONSE, "" );
|
727
|
+
getNotify().callLoginCallback(callback, RhoRuby.ERR_UNEXPECTEDSERVERRESPONSE, "" );
|
502
728
|
return;
|
503
729
|
}
|
504
730
|
|
505
|
-
|
506
|
-
|
731
|
+
IDBResult res = getUserDB().executeSQL("SELECT * FROM client_info");
|
732
|
+
if ( !res.isEnd() )
|
733
|
+
getUserDB().executeSQL( "UPDATE client_info SET session=?", strSession );
|
734
|
+
else
|
735
|
+
getUserDB().executeSQL("INSERT INTO client_info (session) values (?)", strSession);
|
507
736
|
|
508
|
-
|
509
|
-
|
737
|
+
if ( ClientRegister.getInstance() != null )
|
738
|
+
ClientRegister.getInstance().stopWait();
|
510
739
|
|
511
|
-
callLoginCallback(callback, RhoRuby.ERR_NONE, "" );
|
740
|
+
getNotify().callLoginCallback(callback, RhoRuby.ERR_NONE, "" );
|
512
741
|
|
513
742
|
}catch(Exception exc)
|
514
743
|
{
|
515
744
|
LOG.ERROR("Login failed.", exc);
|
516
|
-
callLoginCallback(callback, RhoRuby.ERR_RUNTIME, "" );
|
745
|
+
getNotify().callLoginCallback(callback, RhoRuby.ERR_RUNTIME, "" );
|
517
746
|
}
|
518
747
|
}
|
519
748
|
|
520
749
|
boolean isLoggedIn()throws DBException
|
521
750
|
{
|
522
|
-
|
523
|
-
IDBResult res =
|
751
|
+
String strRes = "";
|
752
|
+
IDBResult res = getUserDB().executeSQL("SELECT session FROM client_info");
|
524
753
|
|
525
754
|
if ( !res.isEnd() )
|
526
|
-
|
755
|
+
strRes = res.getStringByIdx(0);
|
527
756
|
|
528
|
-
return
|
757
|
+
return strRes.length() > 0;
|
529
758
|
}
|
530
759
|
|
531
760
|
String loadSession()throws DBException
|
532
761
|
{
|
533
|
-
|
534
|
-
IDBResult res =
|
762
|
+
m_strSession = "";
|
763
|
+
IDBResult res = getUserDB().executeSQL("SELECT session FROM client_info");
|
535
764
|
|
536
765
|
if ( !res.isEnd() )
|
537
766
|
m_strSession = res.getStringByIdx(0);
|
@@ -541,7 +770,7 @@ public class SyncEngine implements NetRequest.IRhoSession
|
|
541
770
|
|
542
771
|
public void logout()throws Exception
|
543
772
|
{
|
544
|
-
|
773
|
+
getUserDB().executeSQL( "UPDATE client_info SET session = NULL");
|
545
774
|
m_strSession = "";
|
546
775
|
|
547
776
|
loadAllSources();
|
@@ -553,15 +782,15 @@ public class SyncEngine implements NetRequest.IRhoSession
|
|
553
782
|
RhoConf.getInstance().saveToFile();
|
554
783
|
RhoConf.getInstance().loadConf();
|
555
784
|
|
556
|
-
|
785
|
+
getUserDB().executeSQL("DELETE FROM client_info");
|
557
786
|
|
558
787
|
logout();
|
559
788
|
}
|
560
789
|
|
561
|
-
static String
|
790
|
+
static String getHostFromUrl( String strUrl )
|
562
791
|
{
|
563
792
|
URI uri = new URI(strUrl);
|
564
|
-
return uri.
|
793
|
+
return uri.getPathSpecificPart() + "/";
|
565
794
|
}
|
566
795
|
|
567
796
|
}
|