boolean CClientRegister::doRegister(CSyncEngine& oSync) { String session = oSync.loadSession(); if ( session.length() == 0 ) { m_nPollInterval = POLL_INTERVAL_INFINITE; LOG(INFO)+"Session is empty, do register later"; return false; } if ( m_strDevicePin.length() == 0 ) { notifyLoggedIn("","",session); m_nPollInterval = POLL_INTERVAL_INFINITE; LOG(INFO)+"Device PUSH pin is empty, do register later"; return false; } m_nPollInterval = POLL_INTERVAL_SECONDS; String client_id = oSync.loadClientID(); if ( client_id.length() == 0 ) { LOG(WARNING)+"Sync client_id is empty, do register later"; return false; } IDBResult res = CDBAdapter::getUserDB().executeSQL("SELECT token,token_sent from client_info"); if ( !res.isEnd() ) { String token = res.getStringByIdx(0); int token_sent = res.getIntByIdx(1) && !RHOCONF().getBool("register_push_at_startup"); if ( m_strDevicePin.compare(token) == 0 && token_sent > 0 ) { //token in db same as new one and it was already send to the server //so we do nothing return true; } } String strBody = getRegisterBody(client_id); NetResponse resp = getNet().pushData( oSync.getProtocol().getClientRegisterUrl(client_id), strBody, &oSync ); if( resp.isOK() ) { CDBAdapter::getUserDB().executeSQL("UPDATE client_info SET token_sent=?, token=?", 1, m_strDevicePin ); LOG(INFO)+"Registered client sucessfully..."; return true; } LOG(WARNING)+"Network error: "+ resp.getRespCode(); return false; }
boolean CClientRegister::doRegister(CSyncEngine& oSync) { String session = oSync.loadSession(); if ( session.length() == 0 ) { m_nPollInterval = POLL_INTERVAL_INFINITE; return false; } m_nPollInterval = POLL_INTERVAL_SECONDS; String client_id = oSync.loadClientID(); if ( client_id.length() == 0 ) return false; IDBResult res = CDBAdapter::getUserDB().executeSQL("SELECT token,token_sent from client_info"); if ( !res.isEnd() ) { String token = res.getStringByIdx(0); int token_sent = res.getIntByIdx(1); if ( m_strDevicePin.compare(token) == 0 && token_sent > 0 ) { //token in db same as new one and it was already send to the server //so we do nothing return true; } } String strBody = getRegisterBody(client_id); NetResponse(resp, getNet().pushData( oSync.getProtocol().getClientRegisterUrl(), strBody, &oSync )); if( resp.isOK() ) { // try { CDBAdapter::getUserDB().executeSQL("UPDATE client_info SET token_sent=?, token=?", 1, m_strDevicePin ); // } catch(Exception ex) { // LOG.ERROR("Error saving token_sent to the DB..."); // } LOG(INFO)+"Registered client sucessfully..."; return true; } else { LOG(INFO)+"Network error POST-ing device pin to the server..."; } return false; }