Exemple #1
0
void CAsyncHttp::CHttpCommand::callNotify(NetResponse& resp, int nError )
{
    m_strResBody = "rho_callback=1";
    m_strResBody += "&status=";
    if ( nError > 0 )
    {
    	m_strResBody += "error&error_code=" + nError;
    }else
    {
        if ( resp.isSuccess() )
        {
    	    m_strResBody += "ok";
            if ( resp.isResponseRecieved())
	            m_strResBody += "&http_error=" + convertToStringA(resp.getRespCode());
        }
        else
        {
    	    m_strResBody += "error&error_code=";
            m_strResBody += convertToStringA(RhoAppAdapter.getErrorFromResponse(resp));
            if ( resp.isResponseRecieved())
	            m_strResBody += "&http_error=" + convertToStringA(resp.getRespCode());
        }

        String cookies = resp.getCookies();
        if (cookies.length()>0)
            m_strResBody += "&cookies=" + URI::urlEncode(cookies);

        String strHeaders = makeHeadersString();
        if (strHeaders.length() > 0 )
            m_strResBody += "&" + strHeaders;

        m_strResBody += "&" + RHODESAPP().addCallbackObject(
            new CAsyncHttpResponse(resp, m_mapHeaders.get("content-type")), "body");
    }

    if ( m_strCallbackParams.length() > 0 )
        m_strResBody += "&" + m_strCallbackParams;

    if ( m_strCallback.length() > 0 )
    {
        String strFullUrl = m_NetRequest.resolveUrl(m_strCallback);
        getNet().pushData( strFullUrl, m_strResBody, null );
    }
}
Exemple #2
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);
    }
}