Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions lib/commonAPI/coreapi/ext/Network.xml
Original file line number Diff line number Diff line change
Expand Up @@ -89,12 +89,18 @@ Be sure to review the [Ruby API Usage](/guide/api_ruby) guide for important info
<PARAM name="createFolders" type="BOOLEAN" default="false">
<DESC>CreateFolders can automatically create the directory path.</DESC>
</PARAM>
<PARAM name="wantReceiveProgressCallbacks" type="BOOLEAN" default="false">
<DESC>Set to true to receive progress callbacks with status 'progress_headers' and 'progress_data'.</DESC>
</PARAM>
</PARAMS>
</PARAM>
</PARAMS>

<RETURN type="HASH">
<PARAMS>
<PARAM name="status" type="STRING">
<DESC>Status of the callback can be 'ok', 'error', 'progress_headers' and 'progress_data'.</DESC>
</PARAM>
<PARAM name="body" type="STRING">
<DESC>The body of the HTTP response.</DESC>
</PARAM>
Expand All @@ -110,6 +116,9 @@ Be sure to review the [Ruby API Usage](/guide/api_ruby) guide for important info
<PARAM name="fileExists" type="BOOLEAN">
<DESC>When overwriteFile is false and file exists, when error return and this flag set to true.</DESC>
</PARAM>
<PARAM name="length" type="BOOLEAN">
<DESC>Length of received content for 'progress_data' callback.</DESC>
</PARAM>
</PARAMS>
</RETURN>
</METHOD>
Expand Down
46 changes: 45 additions & 1 deletion lib/commonAPI/coreapi/ext/shared/NetworkImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,51 @@ void CNetworkImpl::downloadFile( const rho::Hashtable<rho::String, rho::String>&

bool overwriteFile = propertyMap.containsKey("overwriteFile") && (propertyMap.get("overwriteFile")=="true");
bool createFolders = propertyMap.containsKey("createFolders") && (propertyMap.get("createFolders")=="true");
bool fileExists = false;
bool wantMoreCallbacks = propertyMap.containsKey( "wantReceiveProgressCallbacks" ) && (propertyMap.get( "wantReceiveProgressCallbacks" )=="true");
bool fileExists = false;

//inplace callback for download progress notifications
struct NetCallback : public net::INetRequestCallback
{
rho::apiGenerator::CMethodResult& m_result;

NetCallback();
NetCallback( rho::apiGenerator::CMethodResult& r ) : m_result(r) {}

virtual void didReceiveResponse(NetResponse& resp, const Hashtable<String,String>* headers)
{
Hashtable<String,String>& mapRes = m_result.getStringHash();
mapRes["status"] = "progress_headers";
mapRes["http_error"] = convertToStringA(resp.getRespCode());
if ( headers != 0 ) {
m_result.getStringHashL2()["headers"] = *headers;
}

m_result.set(mapRes);
}

virtual void didReceiveData(const char* data, int len)
{
(m_result.getStringHashL2()["headers"]).clear();

Hashtable<String,String>& mapRes = m_result.getStringHash();
mapRes["status"] = "progress_data";
mapRes["length"] = convertToStringA( len );
//mapRes["data"] = String( data, len );

m_result.set(mapRes);
}

virtual void didFinishLoading() {}
virtual void didFail(NetResponse&) {}
};

NetCallback cb(oResult);

if ( wantMoreCallbacks )
{
reqWrapper.setCallback( &cb );
}

NetResponse resp = reqWrapper.pullFile( propertyMap.get("url"), propertyMap.get("filename"), NULL, &mapHeaders,overwriteFile,createFolders,&fileExists);

Expand Down