rhodes 2.3.0 → 2.3.1.beta.1
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +6 -0
- data/Manifest.txt +5819 -0
- data/README.md +2 -2
- data/Rakefile +9 -5
- data/doc/build.txt +7 -13
- data/doc/configuration.txt +4 -0
- data/doc/connect-to-web-services.txt +0 -1
- data/doc/device-caps.txt +2 -2
- data/doc/extensions.txt +2 -0
- data/doc/linea.txt +699 -0
- data/doc/rhom.txt +2 -1
- data/doc/synchronization.txt +39 -2
- data/doc/ui.txt +1 -0
- data/installer/README.html +1 -1
- data/lib/build/jake.rb +3 -0
- data/lib/framework/res/esri.wm.png +0 -0
- data/lib/framework/rho/render.rb +2 -0
- data/lib/framework/rho/rho.rb +17 -10
- data/lib/framework/rho/rhoapplication.rb +13 -3
- data/lib/framework/rho/rhoevent_bb.rb +3 -1
- data/lib/framework/rho/rhoevent_c.rb +4 -1
- data/lib/framework/rhodes.rb +1 -1
- data/lib/framework/rhom/rhom.rb +10 -0
- data/lib/framework/rhom/rhom_object_factory.rb +45 -0
- data/lib/framework/rhom/rhom_source.rb +1 -1
- data/lib/framework/version.rb +1 -1
- data/lib/rhodes.rb +1 -1
- data/platform/android/Rhodes/AndroidManifest.xml +2 -2
- data/platform/android/Rhodes/jni/include/rhodes/RhoClassFactory.h +1 -1
- data/platform/android/Rhodes/jni/src/RhoClassFactory.cpp +1 -1
- data/platform/android/Rhodes/jni/src/callbacks.cpp +9 -11
- data/platform/android/Rhodes/jni/src/event.cpp +17 -9
- data/platform/android/Rhodes/jni/src/mapview.cpp +34 -4
- data/platform/android/Rhodes/jni/src/rhodes.cpp +1 -1
- data/platform/android/Rhodes/res/drawable/esri.png +0 -0
- data/platform/android/Rhodes/src/com/rhomobile/rhodes/AndroidR.java +1 -0
- data/platform/android/Rhodes/src/com/rhomobile/rhodes/BaseActivity.java +3 -0
- data/platform/android/Rhodes/src/com/rhomobile/rhodes/RhodesActivity.java +8 -5
- data/platform/android/Rhodes/src/com/rhomobile/rhodes/RhodesService.java +80 -9
- data/platform/android/Rhodes/src/com/rhomobile/rhodes/event/EventStore.java +29 -8
- data/platform/android/Rhodes/src/com/rhomobile/rhodes/mainview/SimpleMainView.java +4 -1
- data/platform/android/Rhodes/src/com/rhomobile/rhodes/mainview/TabbedMainView.java +50 -10
- data/platform/android/Rhodes/src/com/rhomobile/rhodes/mapview/MapView.java +3 -0
- data/platform/android/build/android.rake +45 -23
- data/platform/android/build/librhocommon_build.files +1 -0
- data/platform/bb/Hsqldb/src/com/rho/db/HsqlDBStorage.java +6 -1
- data/platform/bb/Hsqldb/src/org/hsqldb/CachedDataRow.java +1 -1
- data/platform/bb/Hsqldb/src/org/hsqldb/CachedRow.java +3 -2
- data/platform/bb/Hsqldb/src/org/hsqldb/Row.java +1 -1
- data/platform/bb/Hsqldb/src/org/hsqldb/persist/CachedObject.java +1 -1
- data/platform/bb/Hsqldb/src/org/hsqldb/persist/DataFileCache.java +66 -16
- data/platform/bb/Hsqldb/src/org/hsqldb/persist/HsqlDatabaseProperties.java +1 -1
- data/platform/bb/RubyVM/src/com/rho/RhoCrypto.java +116 -0
- data/platform/bb/RubyVM/src/com/rho/ThreadQueue.java +39 -2
- data/platform/bb/RubyVM/src/com/rho/Tokenizer.java +11 -6
- data/platform/bb/RubyVM/src/com/rho/db/DBAdapter.java +157 -150
- data/platform/bb/RubyVM/src/com/rho/db/IDBStorage.java +1 -1
- data/platform/bb/RubyVM/src/com/rho/file/RhoFile.java +15 -0
- data/platform/bb/RubyVM/src/com/rho/net/AsyncHttp.java +35 -23
- data/platform/bb/RubyVM/src/com/rho/net/NetRequest.java +6 -9
- data/platform/bb/RubyVM/src/com/rho/sync/SyncEngine.java +54 -16
- data/platform/bb/RubyVM/src/com/rho/sync/SyncNotify.java +18 -9
- data/platform/bb/RubyVM/src/com/rho/sync/SyncSource.java +37 -59
- data/platform/bb/RubyVM/src/com/rho/sync/SyncThread.java +3 -0
- data/platform/bb/build/RubyVM_build.files +1 -0
- data/platform/bb/build/bb.rake +4 -5
- data/platform/bb/rhodes/platform/5.0/com/rho/RhodesApplicationPlatform.java +4 -1
- data/platform/bb/rhodes/platform/5.0/com/rho/db/SqliteStorage.java +8 -3
- data/platform/bb/rhodes/resources/esri.png +0 -0
- data/platform/bb/rhodes/src/com/rho/RhodesApplicationPlatform.java +2 -0
- data/platform/bb/rhodes/src/com/rho/db/SqliteStorage.java +8 -3
- data/platform/bb/rhodes/src/com/rho/rubyext/RhoCalendar.java +4 -1
- data/platform/bb/rhodes/src/com/rho/rubyext/System.java +2 -0
- data/platform/bb/rhodes/src/rhomobile/mapview/ESRIMapField.java +9 -0
- data/platform/iphone/Classes/Event/Event.m +12 -2
- data/platform/iphone/Classes/NativeBar.h +12 -11
- data/platform/iphone/Classes/NativeBar.m +13 -3
- data/platform/iphone/Classes/Rhodes.m +48 -10
- data/platform/iphone/Classes/SimpleMainView.h +1 -0
- data/platform/iphone/Classes/SimpleMainView.m +7 -1
- data/platform/iphone/Classes/SplitView/LeftViewController.m +3 -0
- data/platform/iphone/Classes/SplitView/RightViewController.m +11 -6
- data/platform/iphone/Classes/SplitView/SplittedMainView.m +8 -0
- data/platform/iphone/Classes/TabbedMainView.m +39 -3
- data/platform/iphone/Info.plist +1 -1
- data/platform/iphone/RhoLib/RhoLib.xcodeproj/project.pbxproj +4 -0
- data/platform/iphone/rhorunner.xcodeproj/project.pbxproj +3 -3
- data/platform/shared/SyncClient/SyncClient.cpp +23 -23
- data/platform/shared/common/IRhoClassFactory.h +6 -4
- data/platform/shared/common/RhoAppAdapter.h +1 -1
- data/platform/shared/common/RhoFile.cpp +10 -0
- data/platform/shared/common/RhoFile.h +1 -0
- data/platform/shared/common/RhoMutexLock.h +1 -1
- data/platform/shared/common/RhoStd.h +5 -0
- data/platform/shared/common/RhoThread.cpp +2 -2
- data/platform/shared/common/RhoThread.h +1 -2
- data/platform/shared/common/RhodesApp.cpp +33 -55
- data/platform/shared/common/RhodesApp.h +0 -5
- data/platform/shared/common/RhodesAppBase.cpp +1 -1
- data/platform/shared/common/SplashScreen.cpp +1 -2
- data/platform/shared/common/ThreadQueue.cpp +31 -4
- data/platform/shared/common/ThreadQueue.h +10 -3
- data/platform/shared/common/Tokenizer.cpp +12 -8
- data/platform/shared/common/iphone/RhoClassFactory.cpp +5 -8
- data/platform/shared/common/iphone/RhoClassfactory.h +1 -1
- data/platform/shared/common/map/ESRIMapEngine.cpp +17 -7
- data/platform/shared/common/map/ESRIMapEngine.h +11 -1
- data/platform/shared/common/map/GoogleMapEngine.cpp +3 -3
- data/platform/shared/common/map/GoogleMapEngine.h +2 -2
- data/platform/shared/common/map/MapEngine.cpp +37 -0
- data/platform/shared/common/map/MapEngine.h +5 -0
- data/platform/shared/db/DBAdapter.cpp +113 -81
- data/platform/shared/db/DBAdapter.h +21 -5
- data/platform/shared/db/DBAttrManager.cpp +2 -2
- data/platform/shared/db/DBResult.h +28 -0
- data/platform/shared/net/AsyncHttp.cpp +48 -48
- data/platform/shared/net/AsyncHttp.h +15 -12
- data/platform/shared/net/CURLNetRequest.cpp +27 -105
- data/platform/shared/net/CURLNetRequest.h +8 -15
- data/platform/shared/net/INetRequest.cpp +122 -0
- data/platform/shared/net/INetRequest.h +96 -23
- data/platform/shared/net/ssl.cpp +1 -1
- data/platform/shared/ruby/ext/calendar/calendar.i +2 -2
- data/platform/shared/ruby/ext/calendar/calendar_wrap.c +30 -3
- data/platform/shared/rubyext/GeoLocation.cpp +4 -5
- data/platform/shared/rubyext/GeoLocation.h +4 -4
- data/platform/shared/rubyext/RhoAppAdapter.cpp +1 -1
- data/platform/shared/rubyext/System.cpp +3 -0
- data/platform/shared/sync/ClientRegister.cpp +6 -9
- data/platform/shared/sync/ClientRegister.h +8 -6
- data/platform/shared/sync/SyncEngine.cpp +54 -30
- data/platform/shared/sync/SyncEngine.h +9 -11
- data/platform/shared/sync/SyncNotify.cpp +19 -14
- data/platform/shared/sync/SyncNotify.h +5 -12
- data/platform/shared/sync/SyncSource.cpp +53 -76
- data/platform/shared/sync/SyncSource.h +5 -4
- data/platform/shared/sync/SyncThread.cpp +5 -7
- data/platform/shared/sync/SyncThread.h +2 -2
- data/platform/wm/RhoLib/RhoLib.vcproj +43 -39
- data/platform/wm/build/wm.rake +19 -17
- data/platform/wm/rhodes/AppManager.cpp +4 -4
- data/platform/wm/rhodes/MainWindow.cpp +0 -1
- data/platform/wm/rhodes/MapView/MapViewManager.cpp +4 -0
- data/platform/wm/rhodes/Vibrate.cpp +2 -2
- data/platform/wm/rhodes/Vibrate.h +1 -1
- data/platform/wm/rhodes/rho/common/RhoClassFactory.cpp +7 -5
- data/platform/wm/rhodes/rho/common/RhoClassFactory.h +3 -3
- data/platform/wm/rhodes/rho/net/NetRequestImpl.cpp +24 -10
- data/platform/wm/rhodes/rho/net/NetRequestImpl.h +49 -25
- data/platform/wm/rhodes/rho/rubyext/calendar.cpp +16 -2
- data/platform/wm/rhodes/rhodes.vcproj +77 -85
- data/platform/wm/tools/detool/detool.cpp +16 -6
- data/rakefile.rb +9 -5
- data/res/build-tools/detool.exe +0 -0
- data/rhodes.gemspec +2 -2
- data/spec/phone_spec/app/spec/blobsync_spec.rb +1 -0
- data/spec/phone_spec/app/spec/events_spec.rb +13 -2
- data/spec/phone_spec/app/spec/mapview_spec.rb +2 -2
- data/spec/phone_spec/app/spec/nativebar_spec.rb +3 -3
- data/spec/phone_spec/app/spec/navbar_spec.rb +3 -3
- data/spec/phone_spec/app/spec/rho_spec.rb +1 -1
- data/spec/phone_spec/app/spec/rhom_object_spec.rb +1 -1
- data/spec/phone_spec/app/spec/syncengine_spec.rb +219 -0
- data/spec/phone_spec/build.yml +1 -0
- metadata +15 -8
- data/platform/wm/rhodes/rho/net/NetRequest.cpp +0 -89
- data/platform/wm/rhodes/rho/net/NetRequest.h +0 -45
@@ -18,7 +18,7 @@ CAsyncHttp* CAsyncHttp::m_pInstance = 0;
|
|
18
18
|
if ( m_pInstance )
|
19
19
|
return m_pInstance;
|
20
20
|
|
21
|
-
m_pInstance = new CAsyncHttp(
|
21
|
+
m_pInstance = new CAsyncHttp( );
|
22
22
|
return m_pInstance;
|
23
23
|
}
|
24
24
|
|
@@ -30,33 +30,36 @@ CAsyncHttp* CAsyncHttp::m_pInstance = 0;
|
|
30
30
|
m_pInstance = 0;
|
31
31
|
}
|
32
32
|
|
33
|
-
CAsyncHttp::CAsyncHttp(
|
33
|
+
CAsyncHttp::CAsyncHttp() : CThreadQueue()
|
34
34
|
{
|
35
35
|
CThreadQueue::setLogCategory(getLogCategory());
|
36
36
|
|
37
37
|
setPollInterval(QUEUE_POLL_INTERVAL_INFINITE);
|
38
|
-
|
39
|
-
m_pCurCmd = null;
|
40
38
|
}
|
41
39
|
|
42
40
|
CAsyncHttp::~CAsyncHttp(void)
|
43
41
|
{
|
44
|
-
|
42
|
+
stop(-1);
|
45
43
|
LOG(INFO) + "Thread shutdown";
|
46
44
|
}
|
47
45
|
|
48
|
-
|
46
|
+
unsigned long CAsyncHttp::addHttpCommand(IQueueCommand* pCmd)
|
49
47
|
{
|
50
48
|
if ( ((CHttpCommand*)pCmd)->m_strCallback.length()==0)
|
51
|
-
processCommand(pCmd);
|
52
|
-
else
|
53
49
|
{
|
54
|
-
|
55
|
-
|
50
|
+
processCommandBase(pCmd);
|
51
|
+
unsigned long ret = ((CHttpCommand*)pCmd)->getRetValue();
|
52
|
+
delete pCmd;
|
53
|
+
return ret;
|
56
54
|
}
|
55
|
+
|
56
|
+
CThreadQueue::addQueueCommand(pCmd);
|
57
|
+
start(epLow);
|
58
|
+
|
59
|
+
return ((CHttpCommand*)pCmd)->getRetValue();
|
57
60
|
}
|
58
61
|
|
59
|
-
void CAsyncHttp::cancelRequest(const char* szCallback
|
62
|
+
void CAsyncHttp::cancelRequest(const char* szCallback)
|
60
63
|
{
|
61
64
|
if (!szCallback || !*szCallback )
|
62
65
|
{
|
@@ -64,20 +67,30 @@ void CAsyncHttp::cancelRequest(const char* szCallback, boolean bWait)
|
|
64
67
|
return;
|
65
68
|
}
|
66
69
|
|
67
|
-
|
68
|
-
|
70
|
+
synchronized(getCommandLock());
|
71
|
+
CHttpCommand* pCmd = (CHttpCommand*)getCurCommand();
|
72
|
+
|
73
|
+
if ( pCmd != null && ( *szCallback == '*' || pCmd->m_strCallback.compare(szCallback) == 0) )
|
74
|
+
pCmd->cancel();
|
75
|
+
|
76
|
+
if ( *szCallback == '*' )
|
77
|
+
getCommands().clear();
|
78
|
+
else
|
79
|
+
{
|
80
|
+
for (int i = getCommands().size()-1; i >= 0; i--)
|
81
|
+
{
|
82
|
+
CHttpCommand* pCmd1 = (CHttpCommand*)getCommands().get(i);
|
69
83
|
|
70
|
-
|
71
|
-
|
84
|
+
if ( pCmd1 != null && pCmd1->m_strCallback.compare(szCallback) == 0 )
|
85
|
+
getCommands().remove(i);
|
86
|
+
}
|
72
87
|
|
73
|
-
|
88
|
+
}
|
74
89
|
}
|
75
90
|
|
76
91
|
void CAsyncHttp::processCommand(IQueueCommand* pCmd)
|
77
92
|
{
|
78
|
-
|
79
|
-
m_pCurCmd->execute();
|
80
|
-
m_pCurCmd = null;
|
93
|
+
((CHttpCommand*)pCmd)->execute();
|
81
94
|
}
|
82
95
|
|
83
96
|
extern "C" void header_iter(const char* szName, const char* szValue, void* pHash)
|
@@ -93,33 +106,25 @@ CAsyncHttp::CHttpCommand::CHttpCommand(String strCmd, rho_param *p) : m_params(p
|
|
93
106
|
|
94
107
|
m_params.getHash("headers", m_mapHeaders);
|
95
108
|
|
96
|
-
|
97
|
-
m_pNetRequest->sslVerifyPeer(m_params.getBool("ssl_verify_peer"));
|
98
|
-
|
99
|
-
}
|
100
|
-
|
101
|
-
void CAsyncHttp::CHttpCommand::cancel()
|
102
|
-
{
|
103
|
-
if (m_pNetRequest!=null && !m_pNetRequest->isCancelled() )
|
104
|
-
m_pNetRequest->cancel();
|
109
|
+
m_NetRequest.setSslVerifyPeer(m_params.getBool("ssl_verify_peer"));
|
105
110
|
}
|
106
111
|
|
107
112
|
void CAsyncHttp::CHttpCommand::execute()
|
108
113
|
{
|
109
|
-
|
114
|
+
NetResponse resp;
|
110
115
|
switch( m_eCmd )
|
111
116
|
{
|
112
117
|
case hcGet:
|
113
|
-
resp =
|
118
|
+
resp = getNet().doRequest( m_params.getString("http_command", "GET").c_str(),
|
114
119
|
m_params.getString("url"), m_params.getString("body"), null, &m_mapHeaders);
|
115
120
|
break;
|
116
121
|
case hcPost:
|
117
|
-
resp =
|
122
|
+
resp = getNet().doRequest(m_params.getString("http_command", "POST").c_str(),
|
118
123
|
m_params.getString("url"), m_params.getString("body"), null, &m_mapHeaders);
|
119
124
|
break;
|
120
125
|
|
121
126
|
case hcDownload:
|
122
|
-
resp =
|
127
|
+
resp = getNet().pullFile(m_params.getString("url"), m_params.getString("filename"), null, &m_mapHeaders);
|
123
128
|
break;
|
124
129
|
|
125
130
|
case hcUpload:
|
@@ -169,12 +174,12 @@ void CAsyncHttp::CHttpCommand::execute()
|
|
169
174
|
}
|
170
175
|
}
|
171
176
|
|
172
|
-
resp =
|
177
|
+
resp = getNet().pushMultipartData( m_params.getString("url"), arMultipartItems, null, &m_mapHeaders );
|
173
178
|
break;
|
174
179
|
}
|
175
180
|
}
|
176
181
|
|
177
|
-
if ( !
|
182
|
+
if ( !m_NetRequest.isCancelled())
|
178
183
|
callNotify(resp,0);
|
179
184
|
|
180
185
|
m_params.free_params();
|
@@ -206,10 +211,8 @@ String CAsyncHttp::CHttpCommand::makeHeadersString()
|
|
206
211
|
return strRes;
|
207
212
|
}
|
208
213
|
|
209
|
-
void CAsyncHttp::CHttpCommand::callNotify(
|
214
|
+
void CAsyncHttp::CHttpCommand::callNotify(NetResponse& resp, int nError )
|
210
215
|
{
|
211
|
-
rho::net::INetResponse& resp = *pResp;
|
212
|
-
|
213
216
|
m_strResBody = "rho_callback=1";
|
214
217
|
m_strResBody += "&status=";
|
215
218
|
if ( nError > 0 )
|
@@ -236,7 +239,7 @@ void CAsyncHttp::CHttpCommand::callNotify(rho::net::INetResponse* pResp, int nEr
|
|
236
239
|
m_strResBody += "&" + strHeaders;
|
237
240
|
|
238
241
|
m_strResBody += "&" + RHODESAPP().addCallbackObject(
|
239
|
-
new CAsyncHttpResponse(
|
242
|
+
new CAsyncHttpResponse(resp, m_mapHeaders.get("content-type")), "body");
|
240
243
|
}
|
241
244
|
|
242
245
|
if ( m_strCallbackParams.length() > 0 )
|
@@ -244,8 +247,8 @@ void CAsyncHttp::CHttpCommand::callNotify(rho::net::INetResponse* pResp, int nEr
|
|
244
247
|
|
245
248
|
if ( m_strCallback.length() > 0 )
|
246
249
|
{
|
247
|
-
String strFullUrl =
|
248
|
-
|
250
|
+
String strFullUrl = m_NetRequest.resolveUrl(m_strCallback);
|
251
|
+
getNet().pushData( strFullUrl, m_strResBody, null );
|
249
252
|
}
|
250
253
|
}
|
251
254
|
|
@@ -254,13 +257,12 @@ CAsyncHttp::CAsyncHttpResponse::~CAsyncHttpResponse(){}
|
|
254
257
|
extern "C" VALUE rjson_tokener_parse(const char *str, char** pszError );
|
255
258
|
unsigned long CAsyncHttp::CAsyncHttpResponse::getObjectValue()
|
256
259
|
{
|
257
|
-
|
258
|
-
if (resp.isOK())
|
260
|
+
if (m_NetResponse.isOK())
|
259
261
|
{
|
260
262
|
if ( m_strContentType.find("application/json") != String::npos )
|
261
263
|
{
|
262
264
|
char* szError = 0;
|
263
|
-
unsigned long valBody = rjson_tokener_parse(
|
265
|
+
unsigned long valBody = rjson_tokener_parse(m_NetResponse.getCharData(), &szError);
|
264
266
|
if ( valBody != 0 )
|
265
267
|
return valBody;
|
266
268
|
|
@@ -270,7 +272,7 @@ unsigned long CAsyncHttp::CAsyncHttpResponse::getObjectValue()
|
|
270
272
|
}
|
271
273
|
}
|
272
274
|
|
273
|
-
return rho_ruby_create_string(
|
275
|
+
return rho_ruby_create_string(m_NetResponse.getCharData());
|
274
276
|
}
|
275
277
|
|
276
278
|
} // namespace net
|
@@ -283,16 +285,14 @@ using namespace rho::net;
|
|
283
285
|
void rho_asynchttp_cancel(const char* cancel_callback)
|
284
286
|
{
|
285
287
|
if ( CAsyncHttp::getInstance() != null )
|
286
|
-
CAsyncHttp::getInstance()->cancelRequest(cancel_callback
|
288
|
+
CAsyncHttp::getInstance()->cancelRequest(cancel_callback);
|
287
289
|
}
|
288
290
|
|
289
291
|
unsigned long rho_asynchttp_request(const char* command, rho_param *p)
|
290
292
|
{
|
291
293
|
CAsyncHttp::Create();
|
292
294
|
|
293
|
-
CAsyncHttp::
|
294
|
-
CAsyncHttp::getInstance()->addQueueCommand(pHttp);
|
295
|
-
return pHttp->getRetValue();
|
295
|
+
return CAsyncHttp::getInstance()->addHttpCommand(new CAsyncHttp::CHttpCommand( command, p ));
|
296
296
|
}
|
297
297
|
|
298
298
|
}
|
@@ -18,12 +18,12 @@ class CAsyncHttp : public common::CThreadQueue
|
|
18
18
|
|
19
19
|
class CAsyncHttpResponse : public rho::ICallbackObject
|
20
20
|
{
|
21
|
-
|
21
|
+
NetResponse m_NetResponse;
|
22
22
|
String m_strContentType;
|
23
23
|
public:
|
24
|
-
CAsyncHttpResponse(
|
24
|
+
CAsyncHttpResponse(NetResponse& resp, const String& strContentType)
|
25
25
|
{
|
26
|
-
|
26
|
+
m_NetResponse = resp;
|
27
27
|
m_strContentType = strContentType;
|
28
28
|
}
|
29
29
|
~CAsyncHttpResponse();
|
@@ -42,7 +42,7 @@ public:
|
|
42
42
|
String m_strCallback, m_strCallbackParams;
|
43
43
|
Hashtable<String,String> m_mapHeaders;
|
44
44
|
|
45
|
-
|
45
|
+
NetRequest m_NetRequest;
|
46
46
|
String m_strResBody;
|
47
47
|
|
48
48
|
CRhoParams m_params;
|
@@ -64,9 +64,8 @@ public:
|
|
64
64
|
}
|
65
65
|
|
66
66
|
void execute();
|
67
|
-
void cancel();
|
68
67
|
|
69
|
-
void callNotify(
|
68
|
+
void callNotify(NetResponse& resp, int nError );
|
70
69
|
unsigned long getRetValue();
|
71
70
|
|
72
71
|
boolean equals(const IQueueCommand& cmd){ return false; }
|
@@ -87,28 +86,32 @@ public:
|
|
87
86
|
return "Unknown";
|
88
87
|
}
|
89
88
|
|
89
|
+
virtual void cancel()
|
90
|
+
{
|
91
|
+
m_NetRequest.cancel();
|
92
|
+
}
|
93
|
+
|
90
94
|
private:
|
91
95
|
String makeHeadersString();
|
92
|
-
|
96
|
+
net::CNetRequestWrapper getNet(){ return getNetRequest(&m_NetRequest); }
|
97
|
+
|
93
98
|
};
|
94
99
|
|
95
100
|
private:
|
96
101
|
static CAsyncHttp* m_pInstance;
|
97
102
|
|
98
|
-
CHttpCommand* m_pCurCmd;
|
99
|
-
|
100
103
|
public:
|
101
104
|
|
102
105
|
static CAsyncHttp* Create();
|
103
106
|
static void Destroy();
|
104
107
|
static CAsyncHttp* getInstance(){ return m_pInstance; }
|
105
108
|
|
106
|
-
void cancelRequest(const char* szCallback
|
109
|
+
void cancelRequest(const char* szCallback);
|
107
110
|
|
108
|
-
|
111
|
+
unsigned long addHttpCommand(IQueueCommand* pCmd);
|
109
112
|
|
110
113
|
private:
|
111
|
-
CAsyncHttp(
|
114
|
+
CAsyncHttp();
|
112
115
|
~CAsyncHttp();
|
113
116
|
|
114
117
|
virtual void processCommand(IQueueCommand* pCmd);
|
@@ -46,32 +46,42 @@ public:
|
|
46
46
|
return m_data.size();
|
47
47
|
}
|
48
48
|
|
49
|
-
|
49
|
+
virtual int getRespCode()
|
50
50
|
{
|
51
|
-
m_nRespCode
|
51
|
+
return m_nRespCode;
|
52
52
|
}
|
53
53
|
|
54
|
-
virtual
|
54
|
+
virtual String getCookies()
|
55
55
|
{
|
56
|
-
return
|
56
|
+
return m_cookies;
|
57
57
|
}
|
58
58
|
|
59
|
-
virtual
|
59
|
+
virtual void setCharData(const char* szData)
|
60
|
+
{
|
61
|
+
m_data = szData;
|
62
|
+
}
|
63
|
+
|
64
|
+
void setRespCode(int nRespCode)
|
65
|
+
{
|
66
|
+
m_nRespCode = nRespCode;
|
67
|
+
}
|
68
|
+
|
69
|
+
boolean isOK()
|
60
70
|
{
|
61
71
|
return m_nRespCode == 200 || m_nRespCode == 206;
|
62
72
|
}
|
63
73
|
|
64
|
-
|
74
|
+
boolean isUnathorized()
|
65
75
|
{
|
66
76
|
return m_nRespCode == 401;
|
67
77
|
}
|
68
78
|
|
69
|
-
|
79
|
+
boolean isSuccess()
|
70
80
|
{
|
71
81
|
return m_nRespCode > 0 && m_nRespCode < 400;
|
72
82
|
}
|
73
83
|
|
74
|
-
|
84
|
+
boolean isResponseRecieved(){ return m_nRespCode!=-1;}
|
75
85
|
|
76
86
|
void setCharData(const String &data)
|
77
87
|
{
|
@@ -82,11 +92,7 @@ public:
|
|
82
92
|
{
|
83
93
|
m_cookies = s;
|
84
94
|
}
|
85
|
-
|
86
|
-
String getCookies()
|
87
|
-
{
|
88
|
-
return m_cookies;
|
89
|
-
}
|
95
|
+
|
90
96
|
};
|
91
97
|
|
92
98
|
INetResponse *CURLNetRequest::makeResponse(String const &body, int nErrorCode)
|
@@ -159,27 +165,6 @@ static size_t curlBodyBinaryCallback(void *ptr, size_t size, size_t nmemb, void
|
|
159
165
|
}
|
160
166
|
|
161
167
|
extern "C" int rho_net_ping_network(const char* szHost);
|
162
|
-
INetResponse* CURLNetRequest::pullData(const String& strUrl, IRhoSession* oSession )
|
163
|
-
{
|
164
|
-
RAWLOG_INFO1("GET url: %s", strUrl.c_str());
|
165
|
-
return doRequest("GET", strUrl, String(), oSession, null );
|
166
|
-
}
|
167
|
-
|
168
|
-
INetResponse* CURLNetRequest::pushData(const String& strUrl, const String& strBody, IRhoSession* oSession)
|
169
|
-
{
|
170
|
-
RAWLOG_INFO1("POST url: %s", strUrl.c_str());
|
171
|
-
return doRequest("POST", strUrl, strBody, oSession, null );
|
172
|
-
}
|
173
|
-
|
174
|
-
INetResponse* CURLNetRequest::pullCookies(const String& strUrl, const String& strBody, IRhoSession* oSession)
|
175
|
-
{
|
176
|
-
RAWLOG_INFO1("POST url: %s (requesting cookies)", strUrl.c_str());
|
177
|
-
INetResponse* pResp = doRequest("POST", strUrl, strBody, oSession, null );
|
178
|
-
if ( pResp->isOK() )
|
179
|
-
((CURLNetResponseImpl*)pResp)->setCharData(pResp->getCookies());
|
180
|
-
|
181
|
-
return pResp;
|
182
|
-
}
|
183
168
|
|
184
169
|
INetResponse* CURLNetRequest::doRequest(const char *method, const String& strUrl,
|
185
170
|
const String& strBody, IRhoSession *oSession,
|
@@ -196,10 +181,10 @@ CURLcode CURLNetRequest::doCURLPerform(const String& strUrl)
|
|
196
181
|
{
|
197
182
|
long statusCode = 0;
|
198
183
|
curl_easy_getinfo(m_curl.curl(), CURLINFO_RESPONSE_CODE, &statusCode);
|
199
|
-
if ( statusCode == 0 && rho_net_ping_network(strUrl.c_str()) )
|
184
|
+
if ( statusCode == 0 && rho_net_ping_network(strUrl.substr(0, strUrl.find("?")).c_str()) )
|
200
185
|
err = m_curl.perform();
|
201
186
|
}
|
202
|
-
|
187
|
+
|
203
188
|
return err;
|
204
189
|
}
|
205
190
|
|
@@ -277,19 +262,13 @@ INetResponse* CURLNetRequest::doPull(const char* method, const String& strUrl,
|
|
277
262
|
return makeResponse(respBody, nRespCode);
|
278
263
|
}
|
279
264
|
|
280
|
-
INetResponse* CURLNetRequest::
|
265
|
+
INetResponse* CURLNetRequest::createEmptyNetResponse()
|
266
|
+
{
|
267
|
+
return new CURLNetResponseImpl("", 0, -1);
|
268
|
+
}
|
269
|
+
|
270
|
+
INetResponse* CURLNetRequest::pullFile(const String& strUrl, common::CRhoFile& oFile, IRhoSession* oSession, Hashtable<String,String>* pHeaders)
|
281
271
|
{
|
282
|
-
int nRespCode = -1;
|
283
|
-
|
284
|
-
RAWLOG_INFO2("Pull file. Url: %s; File: %s", strUrl.c_str(), strFilePath.c_str());
|
285
|
-
|
286
|
-
common::CRhoFile oFile;
|
287
|
-
if ( !oFile.open(strFilePath.c_str(),common::CRhoFile::OpenForAppend) )
|
288
|
-
{
|
289
|
-
RAWLOG_ERROR1("pullFile: cannot create file: %s", strFilePath.c_str());
|
290
|
-
return new CURLNetResponseImpl("", 0, nRespCode);
|
291
|
-
}
|
292
|
-
|
293
272
|
return doPull("GET", strUrl, String(), &oFile, oSession, pHeaders);
|
294
273
|
}
|
295
274
|
|
@@ -364,58 +343,6 @@ INetResponse* CURLNetRequest::pushMultipartData(const String& strUrl, VectorPtr<
|
|
364
343
|
return makeResponse(strRespBody, nRespCode);
|
365
344
|
}
|
366
345
|
|
367
|
-
INetResponse* CURLNetRequest::pushMultipartData(const String& strUrl, CMultipartItem& oItem, IRhoSession* oSession, Hashtable<String,String>* pHeaders)
|
368
|
-
{
|
369
|
-
VectorPtr<CMultipartItem*> arItems;
|
370
|
-
arItems.addElement(&oItem);
|
371
|
-
|
372
|
-
INetResponse* pResp = pushMultipartData(strUrl, arItems, oSession, pHeaders);
|
373
|
-
|
374
|
-
arItems[0] = 0; //do not delete item
|
375
|
-
return pResp;
|
376
|
-
}
|
377
|
-
|
378
|
-
INetResponse* CURLNetRequest::pushFile(const String& strUrl, const String& strFilePath, IRhoSession* oSession, Hashtable<String,String>* pHeaders)
|
379
|
-
{
|
380
|
-
int nRespCode = -1;
|
381
|
-
String strRespBody;
|
382
|
-
|
383
|
-
RAWLOG_INFO2("Push file. Url: %s; File: %s", strUrl.c_str(), strFilePath.c_str());
|
384
|
-
|
385
|
-
common::CRhoFile oFile;
|
386
|
-
if ( !oFile.open(strFilePath.c_str(),common::CRhoFile::OpenReadOnly) )
|
387
|
-
{
|
388
|
-
LOG(ERROR) + "pushFile: cannot find file :" + strFilePath;
|
389
|
-
return new CURLNetResponseImpl(strRespBody.c_str(), strRespBody.size(), nRespCode);
|
390
|
-
}
|
391
|
-
|
392
|
-
rho_net_impl_network_indicator(1);
|
393
|
-
|
394
|
-
curl_slist *hdrs = m_curl.set_options("POST", strUrl, String(), oSession, pHeaders);
|
395
|
-
CURL *curl = m_curl.curl();
|
396
|
-
curl_easy_setopt(curl, CURLOPT_WRITEDATA, &strRespBody);
|
397
|
-
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, &curlBodyStringCallback);
|
398
|
-
|
399
|
-
curl_httppost *post = NULL, *last = NULL;
|
400
|
-
curl_easy_setopt(curl, CURLOPT_POSTFIELDS, NULL);
|
401
|
-
curl_formadd(&post, &last,
|
402
|
-
CURLFORM_COPYNAME, "blob",
|
403
|
-
CURLFORM_FILE, strFilePath.c_str(),
|
404
|
-
CURLFORM_CONTENTTYPE, "application/octet-stream",
|
405
|
-
CURLFORM_END);
|
406
|
-
curl_easy_setopt(curl, CURLOPT_HTTPPOST, post);
|
407
|
-
|
408
|
-
CURLcode err = doCURLPerform(strUrl);
|
409
|
-
|
410
|
-
curl_slist_free_all(hdrs);
|
411
|
-
curl_formfree(post);
|
412
|
-
|
413
|
-
rho_net_impl_network_indicator(0);
|
414
|
-
|
415
|
-
nRespCode = getResponseCode(err, strRespBody, oSession);
|
416
|
-
return makeResponse(strRespBody, nRespCode);
|
417
|
-
}
|
418
|
-
|
419
346
|
int CURLNetRequest::getResponseCode(CURLcode err, String const &body, IRhoSession* oSession)
|
420
347
|
{
|
421
348
|
return getResponseCode(err, body.c_str(), body.size(), oSession);
|
@@ -461,11 +388,6 @@ int CURLNetRequest::getResponseCode(CURLcode err, char const *body, size_t bodys
|
|
461
388
|
return (int)statusCode;
|
462
389
|
}
|
463
390
|
|
464
|
-
String CURLNetRequest::resolveUrl(const String& strUrl)
|
465
|
-
{
|
466
|
-
return RHODESAPP().canonicalizeRhoUrl(strUrl);
|
467
|
-
}
|
468
|
-
|
469
391
|
void CURLNetRequest::cancel()
|
470
392
|
{
|
471
393
|
m_curl.cancel();
|
@@ -12,7 +12,7 @@ namespace rho
|
|
12
12
|
namespace net
|
13
13
|
{
|
14
14
|
|
15
|
-
class CURLNetRequest : public
|
15
|
+
class CURLNetRequest : public INetRequestImpl
|
16
16
|
{
|
17
17
|
DEFINE_LOGCLASS;
|
18
18
|
|
@@ -50,23 +50,16 @@ class CURLNetRequest : public INetRequest
|
|
50
50
|
};
|
51
51
|
|
52
52
|
public:
|
53
|
-
INetResponse
|
54
|
-
INetResponse
|
55
|
-
INetResponse
|
56
|
-
INetResponse* pushMultipartData(const String& strUrl, VectorPtr<CMultipartItem*>& arItems, IRhoSession* oSession, Hashtable<String,String>* pHeaders);
|
57
|
-
INetResponse* pushMultipartData(const String& strUrl, CMultipartItem& oItem, IRhoSession* oSession, Hashtable<String,String>* pHeaders);
|
58
|
-
INetResponse *pullFile(const String& strUrl, const String& strFilePath, IRhoSession *oSession, Hashtable<String,String>* pHeaders);
|
59
|
-
INetResponse *pullCookies(const String& strUrl, const String& strBody, IRhoSession *oSession);
|
60
|
-
INetResponse* doRequest( const char* method, const String& strUrl, const String& strBody, IRhoSession* oSession, Hashtable<String,String>* pHeaders );
|
53
|
+
virtual INetResponse* doRequest( const char* method, const String& strUrl, const String& strBody, IRhoSession* oSession, Hashtable<String,String>* pHeaders );
|
54
|
+
virtual INetResponse* pullFile(const String& strUrl, common::CRhoFile& oFile, IRhoSession* oSession, Hashtable<String,String>* pHeaders);
|
55
|
+
virtual INetResponse* pushMultipartData(const String& strUrl, VectorPtr<CMultipartItem*>& arItems, IRhoSession* oSession, Hashtable<String,String>* pHeaders);
|
61
56
|
|
62
|
-
|
63
|
-
void sslVerifyPeer(boolean mode) {m_curl.sslVerifyPeer(mode);}
|
64
|
-
|
65
|
-
String resolveUrl(const String& strUrl);
|
57
|
+
virtual void cancel();
|
66
58
|
|
67
|
-
|
68
|
-
virtual boolean
|
59
|
+
virtual boolean getSslVerifyPeer() {return m_curl.sslVerifyPeer();}
|
60
|
+
virtual void setSslVerifyPeer(boolean mode){m_curl.sslVerifyPeer(mode);}
|
69
61
|
|
62
|
+
virtual INetResponse* createEmptyNetResponse();
|
70
63
|
private:
|
71
64
|
INetResponse* doPull(const char *method, const String &strUrl, const String &strBody, common::CRhoFile *oFile, IRhoSession *oSession, Hashtable<String,String>* pHeaders);
|
72
65
|
int getResponseCode(CURLcode err, String const &body, IRhoSession* oSession);
|
@@ -0,0 +1,122 @@
|
|
1
|
+
#include "INetRequest.h"
|
2
|
+
|
3
|
+
#include "common/RhoFile.h"
|
4
|
+
#include "common/RhodesAppBase.h"
|
5
|
+
|
6
|
+
namespace rho {
|
7
|
+
namespace net {
|
8
|
+
|
9
|
+
void CNetRequestHolder::setRequest(INetRequestImpl* pReq)
|
10
|
+
{
|
11
|
+
synchronized(m_mxReq)
|
12
|
+
{
|
13
|
+
m_pReq = pReq;
|
14
|
+
|
15
|
+
if ( pReq )
|
16
|
+
{
|
17
|
+
m_bCancel = false;
|
18
|
+
m_pReq->setSslVerifyPeer(m_sslVerifyPeer);
|
19
|
+
}
|
20
|
+
}
|
21
|
+
}
|
22
|
+
|
23
|
+
void CNetRequestHolder::cancel()
|
24
|
+
{
|
25
|
+
synchronized(m_mxReq)
|
26
|
+
{
|
27
|
+
m_bCancel = true;
|
28
|
+
if ( m_pReq != 0 )
|
29
|
+
m_pReq->cancel();
|
30
|
+
|
31
|
+
m_pReq = 0;
|
32
|
+
}
|
33
|
+
}
|
34
|
+
|
35
|
+
boolean CNetRequestHolder::isCancelled()
|
36
|
+
{
|
37
|
+
synchronized(m_mxReq)
|
38
|
+
{
|
39
|
+
return m_bCancel;
|
40
|
+
}
|
41
|
+
}
|
42
|
+
|
43
|
+
/*static*/ String CNetRequestHolder::resolveUrl(const String& strUrl)
|
44
|
+
{
|
45
|
+
return RHODESAPPBASE().canonicalizeRhoUrl(strUrl);
|
46
|
+
}
|
47
|
+
|
48
|
+
CNetRequestWrapper::CNetRequestWrapper(INetRequestImpl* pImpl, CNetRequestHolder* pHolder) : m_pReqImpl(pImpl), m_pHolder(pHolder)
|
49
|
+
{
|
50
|
+
if ( m_pHolder )
|
51
|
+
m_pHolder->setRequest(pImpl);
|
52
|
+
}
|
53
|
+
|
54
|
+
CNetRequestWrapper::~CNetRequestWrapper()
|
55
|
+
{
|
56
|
+
if ( m_pHolder )
|
57
|
+
m_pHolder->setRequest(0);
|
58
|
+
}
|
59
|
+
|
60
|
+
INetResponse* CNetRequestWrapper::pullData(const String& strUrl, IRhoSession* oSession )
|
61
|
+
{
|
62
|
+
return doRequest("GET",strUrl,String(),oSession,null);
|
63
|
+
}
|
64
|
+
|
65
|
+
INetResponse* CNetRequestWrapper::pushData(const String& strUrl, const String& strBody, IRhoSession* oSession)
|
66
|
+
{
|
67
|
+
return doRequest("POST",strUrl,strBody,oSession,null);
|
68
|
+
}
|
69
|
+
|
70
|
+
INetResponse* CNetRequestWrapper::pullCookies(const String& strUrl, const String& strBody, IRhoSession* oSession)
|
71
|
+
{
|
72
|
+
INetResponse* pResp = doRequest("POST", strUrl, strBody, oSession, null );
|
73
|
+
if ( pResp->getRespCode() == 200 )
|
74
|
+
pResp->setCharData(pResp->getCookies().c_str());
|
75
|
+
|
76
|
+
return pResp;
|
77
|
+
}
|
78
|
+
|
79
|
+
INetResponse* CNetRequestWrapper::doRequest( const char* method, const String& strUrl, const String& strBody, IRhoSession* oSession, Hashtable<String,String>* pHeaders )
|
80
|
+
{
|
81
|
+
return m_pReqImpl->doRequest(method, strUrl, strBody, oSession, pHeaders );
|
82
|
+
}
|
83
|
+
|
84
|
+
INetResponse* CNetRequestWrapper::pushMultipartData(const String& strUrl, VectorPtr<CMultipartItem*>& arItems, IRhoSession* oSession, Hashtable<String,String>* pHeaders)
|
85
|
+
{
|
86
|
+
return m_pReqImpl->pushMultipartData(strUrl, arItems, oSession, pHeaders);
|
87
|
+
}
|
88
|
+
|
89
|
+
INetResponse* CNetRequestWrapper::pushMultipartData(const String& strUrl, CMultipartItem& oItem, IRhoSession* oSession, Hashtable<String,String>* pHeaders)
|
90
|
+
{
|
91
|
+
VectorPtr<CMultipartItem*> arItems;
|
92
|
+
arItems.addElement(&oItem);
|
93
|
+
|
94
|
+
INetResponse* pResp = pushMultipartData(strUrl, arItems, oSession, pHeaders);
|
95
|
+
|
96
|
+
arItems[0] = 0; //do not delete item
|
97
|
+
return pResp;
|
98
|
+
}
|
99
|
+
|
100
|
+
INetResponse* CNetRequestWrapper::pullFile(const String& strUrl, const String& strFilePath, IRhoSession* oSession, Hashtable<String,String>* pHeaders)
|
101
|
+
{
|
102
|
+
common::CRhoFile oFile;
|
103
|
+
if ( !oFile.open(strFilePath.c_str(),common::CRhoFile::OpenForAppend) )
|
104
|
+
{
|
105
|
+
LOGC(ERROR, "Net") + "pullFile: cannot create file :" + strFilePath;
|
106
|
+
return m_pReqImpl->createEmptyNetResponse();
|
107
|
+
}
|
108
|
+
|
109
|
+
return m_pReqImpl->pullFile( strUrl, oFile, oSession, pHeaders );
|
110
|
+
}
|
111
|
+
|
112
|
+
String CNetRequestWrapper::resolveUrl(const String& strUrl)
|
113
|
+
{
|
114
|
+
return RHODESAPPBASE().canonicalizeRhoUrl(strUrl);
|
115
|
+
}
|
116
|
+
}
|
117
|
+
}
|
118
|
+
|
119
|
+
rho::net::CNetRequestWrapper getNetRequest(rho::net::CNetRequestHolder* pHolder/* = 0*/)
|
120
|
+
{
|
121
|
+
return rho::net::CNetRequestWrapper( rho_get_RhoClassFactory()->createNetRequestImpl(), pHolder );
|
122
|
+
}
|