void rho_do_send_log(rho::apiGenerator::CMethodResult& oResult) { String strDevicePin, strClientID; net::IRhoSession* pSession = 0; if ( sync::RhoconnectClientManager::haveRhoconnectClientImpl() ) { strDevicePin = rho::sync::RhoconnectClientManager::clientRegisterGetDevicePin(); strClientID = rho::sync::RhoconnectClientManager::syncEnineReadClientID(); pSession = rho::sync::RhoconnectClientManager::getRhoSession(); } String strQuery; String strLogUrl = RHOCONF().getString("Log.destinationURI"); if ( strLogUrl.length() == 0 ) { strLogUrl = RHOCONF().getPath("logserver"); if ( strLogUrl.length() == 0 ) strLogUrl = RHOCONF().getPath("syncserver"); strQuery = strLogUrl + "client_log?" + "client_id=" + strClientID + "&device_pin=" + strDevicePin + "&log_name=" + RHOCONF().getString("logname"); }else { String strSign = "?"; if ( strrchr(strLogUrl.c_str(), '?') ) strSign = "&"; strQuery = strLogUrl + strSign + "client_id=" + strClientID + "&device_pin=" + strDevicePin; } net::CMultipartItem oItem; oItem.m_strFilePath = LOGCONF().getLogFilePath(); oItem.m_strContentType = "application/octet-stream"; boolean bOldSaveToFile = LOGCONF().isLogToFile(); LOGCONF().setLogToFile(false); NetRequest oNetRequest; oNetRequest.setSslVerifyPeer(false); NetResponse resp = getNetRequest(&oNetRequest).pushMultipartData( strQuery, oItem, pSession, null ); LOGCONF().setLogToFile(bOldSaveToFile); boolean isOK = true; if ( !resp.isOK() ) { LOG(ERROR) + "send_log failed : network error - " + resp.getRespCode() + "; Body - " + resp.getCharData(); isOK = false; } Hashtable<String, String> hashRes; hashRes["status"] = isOK ? "ok" : "error"; oResult.set(hashRes); RHODESAPPBASE().setSendingLog(false); }
int rho_unzip_file(const char* szZipPath) { #ifdef UNICODE rho::StringW strZipPathW; rho::common::convertToStringW(szZipPath, strZipPathW); HZIP hz = OpenZipFile(strZipPathW.c_str(), ""); if ( !hz ) return 0; // Set base for unziping SetUnzipBaseDir(hz, rho::common::convertToStringW(RHODESAPPBASE().getDBDirPath()).c_str() ); #else HZIP hz = OpenZipFile(szZipPath, ""); if ( !hz ) return 0; // Set base for unziping SetUnzipBaseDir(hz, RHODESAPPBASE().getDBDirPath().c_str() ); #endif ZIPENTRY ze; ZRESULT res = 0; // Get info about the zip // -1 gives overall information about the zipfile res = GetZipItem(hz,-1,&ze); int numitems = ze.index; // Iterate through items and unzip them for (int zi = 0; zi<numitems; zi++) { // fetch individual details, e.g. the item's name. res = GetZipItem(hz,zi,&ze); if ( res == ZR_OK ) res = UnzipItem(hz, zi, ze.name); } CloseZip(hz); return res == ZR_OK ? 1 : 0; }
void BundleUpdateThreadQueue::processCommand(IQueueCommand *pCmd) { BUCommand *cmd = (BUCommand*)pCmd; rho::String fileURL = cmd->bundle_url; rho::String fileZipLocalDir = rho::common::CFilePath::join(RHODESAPPBASE().getRhoUserPath(), "RhoBundle"); rho::String fileZipLocalPath = rho::common::CFilePath::join(fileZipLocalDir, "upgrade_bundle.zip"); const char* flz = fileZipLocalPath.c_str(); // 0 remove old files rho::common::CRhoFile::deleteFolder(fileZipLocalDir.c_str()); //rho_file_impl_delete_folder(fileZipLocalDir.c_str()); rho::common::CRhoFile::recursiveCreateDir(fileZipLocalDir.c_str(), RHODESAPPBASE().getRhoUserPath().c_str()); // 1 download zip rho::Hashtable<rho::String, rho::String> mapHeaders; mapHeaders["User-Agent"] = "Mozilla-5.0"; rho::apiGenerator::CMethodResult oResult; bool overwriteFile = true; bool createFolders = true; bool fileExists = false; NetRequest oNetRequest; NetResponse resp = getNetRequest(&oNetRequest).pullFile( fileURL, fileZipLocalPath, NULL, &mapHeaders,overwriteFile,createFolders,&fileExists); if (resp.isSuccess()) { int o; o = 9; } else { int r; r = 9; } // 2 unpack zip int zip_res = rho_sys_unzip_file(fileZipLocalPath.c_str(), ""); if (zip_res >= 0) { int o; o = 9; } else { int r; r = 9; // error // send request for full_update rho::String message = "ERROR when downloading and unpack Bundle ["; message = message + fileURL + "] ! Cancel update !"; alert_show_status("Development Extras", message.c_str(), "OK"); return; } // 3 call update bundle bool do_not_restart_app = true; bool not_thread_mode = true; bool check_filelist = true; rho::String cb_url = /*RHODESAPPBASE().getHomeUrl()*/ "http://127.0.0.1:";//37579/development/update_bundle_callback"; cb_url = cb_url + DevHTTPServer::getInstance()->getPort() + "/development/update_bundle_callback"; const char* hu = cb_url.c_str(); cmd->canContinue = false; rho_sys_replace_current_bundleEx( fileZipLocalDir.c_str(), cb_url.c_str(), do_not_restart_app, not_thread_mode, check_filelist, true ); // wait responce while (!cmd->canContinue) { sleep(30); } }
void callback_system_update_bundle_callback(void *arg, rho::String const &strQuery) { const char* s = strQuery.c_str(); // status ok,error,need_sync // message "bla bla bla" rho::String qStatus = ""; rho::String qMessage = ""; rho::common::CTokenizer oTokenizer(strQuery, "&"); while (oTokenizer.hasMoreTokens()) { rho::String tok = oTokenizer.nextToken(); if (tok.length() == 0) continue; if ( rho::String_startsWith(tok, "status=") ) { qStatus = tok.substr(7); }else if ( rho::String_startsWith( tok, "message=") ) { qMessage = tok.substr(8); } } rho::String query = ""; bool our_refresh_webview = false; rho::String our_responce_server_url = ""; BundleUpdateThreadQueue::BUCommand* cmd = getBundleUpdateThreadQueueSignletone()->getCurrentBUCommand(); if (cmd != NULL) { our_refresh_webview = cmd->refresh_webview; our_responce_server_url = cmd->responce_url; } rho::String message = "Unrecognizing Situation during update bundle! Restart application and reconnect device to server !"; if (qStatus.compare("ok") == 0) { message = "Update bundle was finished !"; query = "&status=ok"; if (our_refresh_webview) { rho_webview_refresh(-1); } } if (qStatus.compare("error") == 0) { message = "Error when update Bundle : " + qMessage + " !"; query = "&status=error&message="+message; } if (qStatus.compare("need_sync") == 0) { message = "Your application files too old. Request for full Bundle update was sended to server !"; query = "&status=need_full_update"; } alert_show_status("Development Extras", message.c_str(), "OK"); //alert_show_popup(&p); rho_http_sendresponse(arg, ""); // send responce to server char* norm_url = rho_http_normalizeurl(our_responce_server_url.c_str()); query = query + make_info_string(false); rho_net_request_with_data_in_separated_thread(norm_url, query.c_str()); rho_http_free(norm_url); // remove temporary files rho::String fileZipLocalDir = rho::common::CFilePath::join(RHODESAPPBASE().getRhoUserPath(), "RhoBundle"); //rho_file_impl_delete_folder(fileZipLocalDir.c_str()); rho::common::CRhoFile::deleteFolder(fileZipLocalDir.c_str()); if (cmd != NULL) { cmd->canContinue = true; } }
String CNetRequestWrapper::resolveUrl(const String& strUrl) { return RHODESAPPBASE().canonicalizeRhoUrl(strUrl); }
//{"source_name":"SampleAdapter","client_id":1,"create":{"1":{"brand":"Apple","name":"iPhone","price":"199.99"}}} //{"source_name":"SampleAdapter","client_id":1,"update":{"1":{"brand":"Apple","name":"iPhone","price":"199.99"}}} //{"source_name":"SampleAdapter","client_id":1,"delete":{"1":{"brand":"Apple","name":"iPhone","price":"199.99"}}} //{"source_name":"SampleAdapter","client_id":1,"delete":{"3":{"brand":"HTC","name":"Fuze","price":"299.99"}},"create":{"1":{"brand":"Apple","name":"iPhone","price":"199.99"}},"update":{"2":{"brand":"Android","name":"G2","price":"99.99"}}} void CSyncSource::makePushBody_Ver3(String& strBody, const String& strUpdateType, boolean isSync) { getDB().Lock(); DBResult( res , getDB().executeSQL("SELECT attrib, object, value, attrib_type " "FROM changed_values where source_id=? and update_type =? and sent<=1 ORDER BY object", getID(), strUpdateType.c_str() ) ); if ( res.isEnd() ) { getDB().Unlock(); return; } String strCurObject = ""; boolean bFirst = true; for( ; !res.isEnd(); res.next() ) { String strAttrib = res.getStringByIdx(0); String strObject = res.getStringByIdx(1); String value = res.getStringByIdx(2); String attribType = res.getStringByIdx(3); if ( attribType.compare("blob.file") == 0 ) { CMultipartItem* pItem = new CMultipartItem(); CMultipartItem& oItem = *pItem; oItem.m_strFilePath = RHODESAPPBASE().resolveDBFilesPath(value); oItem.m_strContentType = "application/octet-stream"; oItem.m_strName = strAttrib + "-" + strObject; m_arBlobAttrs.addElement(strAttrib); m_arMultipartItems.addElement(pItem); } if ( strBody.length() == 0 ) { if ( !isSync ) strBody += "{"; else strBody += "\"" + strUpdateType + "\":{"; } if ( strObject.compare(strCurObject) != 0 ) { if ( strCurObject.length() > 0 ) { if ( !bFirst ) strBody += "}"; strBody += ","; } bFirst = true; strBody += CJSONEntry::quoteValue(strObject); strCurObject = strObject; } if (!bFirst) strBody += ","; if ( strAttrib.length() > 0 ) { if ( bFirst ) strBody += ":{"; strBody += CJSONEntry::quoteValue(strAttrib) + ":" + CJSONEntry::quoteValue(value); bFirst = false; } } if ( strBody.length() > 0 ) { if ( !bFirst ) strBody += "}"; strBody += "}"; } if ( isSync ) getDB().executeSQL("UPDATE changed_values SET sent=1 WHERE source_id=? and update_type=? and sent=0", getID(), strUpdateType.c_str() ); getDB().Unlock(); }