boolean CClientRegister::doUnregister(CSyncEngine& oSync) { String session = m_unregisterSession; if ( session.length() == 0 ) { m_unregisterSession = ""; m_unregisterClientID = ""; LOG(INFO)+"Session is empty, don't need to unregister"; return true; } m_nPollInterval = POLL_INTERVAL_SECONDS; String client_id = m_unregisterClientID; if ( client_id.length() == 0 ) { m_unregisterSession = ""; m_unregisterClientID = ""; LOG(WARNING)+"Sync client_id is empty, don't need to unregister"; return true; } String strBody = getUnregisterBody(client_id); LOG(INFO)+"Unregistered client with body = " + strBody; class UnregisterSession : public net::IRhoSession { String m_session; String m_contentType; public: UnregisterSession(const String& session, const String& contentType) : m_session(session), m_contentType(contentType) {} virtual void logout() {} virtual const String& getSession() { return m_session; } virtual const String& getContentType() { return m_contentType; } }; UnregisterSession unregSession(session, oSync.getProtocol().getContentType() ); NetResponse resp = getNet().pushData( oSync.getProtocol().getClientRegisterUrl(client_id), strBody, &unregSession ); if( resp.isOK() ) { m_unregisterSession = ""; m_unregisterClientID = ""; CDBAdapter::getUserDB().executeSQL("UPDATE client_info SET token_sent=?", 0 ); LOG(INFO)+"Unregistered 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; 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; }