Ejemplo n.º 1
0
void CAppManager::ReloadRhoBundle(HWND hwnd, const char* szUrl, const char* szZipPassword)
{	
	const char  *tmp_dir_name = "_tmp_";
	const char	*loadData = NULL;
	unsigned int loadSize = 0;
	String		 root_dir = rho_native_rhopath();
	String		 tmp_unzip_dir;
	int          errCode = RRB_UNKNOWN_ERR;

	root_dir.at(root_dir.length()-1) = '\\';
	tmp_unzip_dir = root_dir + tmp_dir_name;

	if (szUrl == NULL) {
		LOG(ERROR) + "null url passed to ReloadRhoBundle";
		return;
	}

	//trying to load file
	//NB: for mobile devices should use filesystem instead of RAM
	NetResponse resp = getNetRequest().pullData(szUrl, null);
	if (resp.getDataSize() > 0 && resp.getCharData()) 
    {
		loadData = resp.getCharData();
		loadSize = resp.getDataSize();
		errCode = RRB_NONE_ERR;
	} else {
		errCode = RRB_LOADING_ERR;
	}

	//trying to unzip loaded file
	if (errCode == RRB_NONE_ERR)
		errCode = unzipRhoBundle(loadData, loadSize, szZipPassword, tmp_unzip_dir);
	
	RHODESAPP().stopApp();

	//trying to delete old rhobundle
	if (errCode == RRB_NONE_ERR)
		errCode = removeOldRhoBundle();

	//move new rhobundle from temporary dir
	if (errCode == RRB_NONE_ERR) {
		errCode = updateRhoBundle (root_dir, tmp_unzip_dir);
	}

	showMessage(hwnd, errCode);
}
Ejemplo n.º 2
0
bool GoogleGeoCoding::fetchData(String const &url, void **data, size_t *datasize)
{
    RHO_MAP_TRACE1("GoogleGeoCoding: fetchData: url=%s", url.c_str());
    NetResponse resp = getNet().doRequest("GET", url, "", 0, 0);
    if (!resp.isOK())
        return false;
    *datasize = resp.getDataSize();
    *data = malloc(*datasize);
    if (!*data)
        return false;
    memcpy(*data, resp.getCharData(), *datasize);
    return true;
}
Ejemplo n.º 3
0
void CRhodesApp::callAppActiveCallback(boolean bActive)
{
    LOG(INFO) + "callAppActiveCallback";
    if (bActive)
    {
        // Restart server each time when we go to foreground
/*        if (m_activateCounter++ > 0)
        {
#if !defined( OS_WINCE ) && !defined (OS_WINDOWS)
            m_httpServer->stop();
#endif
            this->stopWait();

        } */

        m_appCallbacksQueue->addQueueCommand(new CAppCallbacksQueue::Command(CAppCallbacksQueue::app_activated));
    }
    else
    {
        // Deactivation callback must be called in place (not in separate thread!)
        // This is because system can kill application at any time after this callback finished
        // So to guarantee user code is executed on deactivation, we must not exit from this function
        // until application finish executing of user-defined deactivation callback.
        // However, blocking UI thread can cause problem with API refering to UI (such as WebView.navigate etc)
        // To fix this problem, new mode 'deactivation' introduced. When this mode active, no UI operations allowed.
        // All such operation will throw exception in ruby code when calling in 'deactivate' mode.
        m_bDeactivationMode = true;
        m_appCallbacksQueue->addQueueCommand(new CAppCallbacksQueue::Command(CAppCallbacksQueue::app_deactivated));

        String strUrl = m_strHomeUrl + "/system/deactivateapp";
        NetResponse resp = getNetRequest().pullData( strUrl, null );
        if ( !resp.isOK() )
        {
            LOG(ERROR) + "deactivate app failed. Code: " + resp.getRespCode() + "; Error body: " + resp.getCharData();
        }else
        {
            const char* szData = resp.getCharData();
            boolean bStop = szData && strcmp(szData,"stop_local_server") == 0;

            if (bStop)
            {
#if !defined( OS_WINCE ) && !defined (OS_WINDOWS)
                LOG(INFO) + "Stopping local server.";
                m_httpServer->stop();
#endif
            }
        }

        m_bDeactivationMode = false;
    }
}
Ejemplo n.º 4
0
const String& CRhodesApp::getRhoMessage(int nError, const char* szName)
{
    String strUrl = m_strHomeUrl + "/system/getrhomessage?";
    if ( nError )
        strUrl += "error=" + convertToStringA(nError);
    else if ( szName && *szName )
    {
        strUrl += "msgid=";
        strUrl += szName;
    }

    NetResponse resp = getNetRequest().pullData( strUrl, null );
    if ( !resp.isOK() )
    {
        LOG(ERROR) + "getRhoMessage failed. Code: " + resp.getRespCode() + "; Error body: " + resp.getCharData();
        m_strRhoMessage = "";
    }
    else
        m_strRhoMessage = resp.getCharData();

    return m_strRhoMessage;
}
Ejemplo n.º 5
0
bool GoogleGeoCoding::fetchData(String const &url, void **data, size_t *datasize)
{
    RHO_MAP_TRACE1("GoogleGeoCoding: fetchData: url=%s", url.c_str());
#ifdef ENABLE_ANDROID_NET_REQUEST
    mNetRequestID = mapengine_request_make();
    int s = 0;
    int res = 0;
    res = mapengine_request_data(mNetRequestID, url.c_str(), data, &s);
    *datasize = s;
    return res > 0;
#else
 NetResponse resp = getNet().doRequest("GET", url, "", 0, 0);
    if (!resp.isOK())
        return false;
    *datasize = resp.getDataSize();
    *data = malloc(*datasize);
    if (!*data)
        return false;
    memcpy(*data, resp.getCharData(), *datasize);
    return true;
#endif
 }
Ejemplo n.º 6
0
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);
}
Ejemplo n.º 7
0
void CRhodesApp::callUiDestroyedCallback()
{
    String strUrl = m_strHomeUrl + "/system/uidestroyed";
    NetResponse resp = getNetRequest().pullData( strUrl, null );
    if ( !resp.isOK() )
    {
        LOG(ERROR) + "UI destroy callback failed. Code: " + resp.getRespCode() + "; Error body: " + resp.getCharData();
    }
}
Ejemplo n.º 8
0
    void run(common::CRhoThread &)
    {
        String strDevicePin = rho::sync::CClientRegister::getInstance() ? rho::sync::CClientRegister::getInstance()->getDevicePin() : "";
	    String strClientID = rho::sync::CSyncThread::getSyncEngine().readClientID();
        
        String strLogUrl = RHOCONF().getPath("logserver");
        if ( strLogUrl.length() == 0 )
            strLogUrl = RHOCONF().getPath("syncserver");
        
	    String strQuery = strLogUrl + "client_log?" +
            "client_id=" + strClientID + "&device_pin=" + strDevicePin + "&log_name=" + RHOCONF().getString("logname");
        
        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, &(rho::sync::CSyncThread::getSyncEngine()), null );
        LOGCONF().setLogToFile(bOldSaveToFile);
        
        boolean isOK = true;
        
        if ( !resp.isOK() )
        {
            LOG(ERROR) + "send_log failed : network error - " + resp.getRespCode() + "; Body - " + resp.getCharData();
            isOK = false;
        }

        if (m_strCallback.length() > 0) 
        {
            const char* body = isOK ? "rho_callback=1&status=ok" : "rho_callback=1&status=error";

            rho_net_request_with_data(RHODESAPP().canonicalizeRhoUrl(m_strCallback).c_str(), body);
        }

        RHODESAPP().setSendingLog(false);
    }
Ejemplo n.º 9
0
boolean CRhodesApp::sendLog() 
{
    String strDevicePin = rho::sync::CClientRegister::getInstance() ? rho::sync::CClientRegister::getInstance()->getDevicePin() : "";
	String strClientID = rho::sync::CSyncThread::getSyncEngine().readClientID();

    String strLogUrl = RHOCONF().getPath("logserver");
    if ( strLogUrl.length() == 0 )
        strLogUrl = RHOCONF().getPath("syncserver");

	String strQuery = strLogUrl + "client_log?" +
	    "client_id=" + strClientID + "&device_pin=" + strDevicePin + "&log_name=" + RHOCONF().getString("logname");

    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, &(rho::sync::CSyncThread::getSyncEngine()), null );
    LOGCONF().setLogToFile(bOldSaveToFile);

    if ( !resp.isOK() )
    {
        LOG(ERROR) + "send_log failed : network error - " + resp.getRespCode() + "; Body - " + resp.getCharData();
        return false;
    }

    return true;
}