void Config_Handler1(uint8_t *buf) { uint8_t command=buf[0]; switch(command) { case 0x01: Config_Handler(buf); break; case 0x02: Send_Config(); break; case 0x03: Send_Data(); break; default: break; } Print_Config(); }
int Ctcs::CheckMessage() { ssize_t r; size_t q; r = in_buffer.FeedIn(m_sock); // This differs from tracker.cpp since we maintain a persistent connection. if( r == 0 ) return 0; // no data (should return an error) q = in_buffer.Count(); if( !q ){ int error = 0; socklen_t n = sizeof(error); if( getsockopt(m_sock, SOL_SOCKET, SO_ERROR, &error, &n) < 0 ) error = errno; if( error != 0 ) CONSOLE.Warning(2, "warn, received nothing from CTCS: %s", strerror(error)); Reset(5); return -1; } const char *s, *p, *msgbuf; while( in_buffer.Count() ){ msgbuf = in_buffer.BasePointer(); p = (const char *)memchr(msgbuf, '\r', in_buffer.Count()); s = (const char *)memchr(msgbuf, '\n', in_buffer.Count()); if( p && s > p ) s = p; if( !s ) break; if( *cfg_verbose && s != msgbuf ) CONSOLE.Debug("CTCS: %.*s", (int)(s - msgbuf), msgbuf); if( !strncmp("SETDLIMIT", msgbuf, 9) ){ dt_rate_t arg = (dt_rate_t)strtod(msgbuf+10, NULL); if( !BTCONTENT.IsFull() || arg < *cfg_max_bandwidth_down ){ cfg_max_bandwidth_down = arg; } }else if( !strncmp("SETULIMIT", msgbuf, 9) ){ cfg_max_bandwidth_up = (dt_rate_t)strtod(msgbuf+10, NULL); }else if( !strncmp("SENDPEERS", msgbuf, 9) ){ Send_Peers(); }else if( !strncmp("SENDSTATUS", msgbuf, 10) ){ Send_Status(); }else if( !strncmp("SENDCONF", msgbuf, 8) ){ Send_Config(); }else if( !strncmp("CTCONFIG", msgbuf, 8) ){ Set_Config(msgbuf); }else if( !strncmp("SENDDETAIL", msgbuf, 10) ){ Send_Detail(); }else if( !strncmp("CTQUIT", msgbuf, 6) ){ CONSOLE.Print("CTCS sent Quit command"); TRACKER.Stop(); }else if( !strncmp("CTRESTART", msgbuf, 9) ){ TRACKER.RestartTracker(); }else if( !strncmp("CTUPDATE", msgbuf, 8) ){ TRACKER.Update(); }else if( !strncmp("PROTOCOL", msgbuf, 8) ){ int proto = atoi(msgbuf+9); if( proto <= CTCS_PROTOCOL ) m_protocol = proto; else m_protocol = CTCS_PROTOCOL; }else if( s != msgbuf ){ if(*cfg_verbose) CONSOLE.Debug("unknown CTCS message: %.*s", (int)(s - msgbuf), msgbuf); } in_buffer.PickUp(s - msgbuf + 1); } m_last_timestamp = now; return 0; }