#include #include #include #include String YProxyServer::smHostName="localhost"; bool YProxyServer::start(const String &remoteHost,const String &user,const String &password) { HostEnt hostEntry; ServEnt serverEntry; String stringData; message(String("[YProxyServer::start]Trying host'")+smHostName+String("'...")); if(!mWSASystem.isInitialized()){message("[YProxySever::start]WINSOCK initialization failure.");return FALSE;} InternetAddress internetAddress(smHostName); if(!internetAddress.isZero()){if(!hostEntry.hostByAddress(internetAddress)){message(String("[YProxyServer::start]no DNS entry for ")+smHostName);return FALSE;}} else if(!hostEntry.hostByName(smHostName)){message(String("[YProxyServer::start]no DNS entry for ")+smHostName);return FALSE;} message(String("[YProxyServer::start]connect...")+String("'")+hostEntry.hostName()+String("' (")+(String)(hostEntry.addresses())[0]+String(")")); if(!serverEntry.serviceByName("nntp","tcp")){message("[YProxyServer::start]cannot determine port number for nntp session");return false;} mINETSocketAddress.internetAddress((hostEntry.addresses())[0]); mINETSocketAddress.family(PF_INET); mINETSocketAddress.port(serverEntry.port()); while(TRUE) { INETSocketAddress internetSocketAddress; message(String("[YProxyServer::start] host='")+(hostEntry.addresses())[0]+String("' port=")+String().fromInt(serverEntry.port())); if(!mSocketControl.create()){message("[YProxyServer::start] socket initialization failure.");return FALSE;} mSocketControl.reuseAddress(); if(!mSocketControl.bind(mINETSocketAddress)){message("[YProxyServer::start] bind failed");return FALSE;} String strLocalHost((String)mINETSocketAddress.internetAddress()); message(String("[YProxyServer::start] waiting for connection on ")+strLocalHost+String(":")+String().fromInt(serverEntry.port())); if(!mSocketControl.listen()){message("[YProxyServer::start] listen failed");return FALSE;} mProxyThreads.insert(&SmartPointer()); PYProxyThread &yProxyThread=mProxyThreads[mProxyThreads.size()-1]; yProxyThread=::new YProxyThread(); yProxyThread.disposition(PointerDisposition::Delete); yProxyThread->accept(mSocketControl,remoteHost,user,password); } message("[YProxyServer::start]terminating connection"); return TRUE; } // virtuals void YProxyServer::acceptHandler(void) { } void YProxyServer::stringHandler(const String &string) { message(String("[YProxyServer::stringHandler]Received:")+string); } void YProxyServer::message(const String &message) { ::printf("%s\n",message.str()); }