--- innwebd/base_passive.cpp 2004/07/03 13:56:04 1.3 +++ innwebd/base_passive.cpp 2008/04/11 17:14:49 1.10 @@ -1,14 +1,10 @@ /*******************************************************/ /* */ -/* LeafOK Innd */ -/* Copyright (C) LeafOK.com, 2003-2004 */ +/* LeafOK Innbbsd */ /* */ -/* Programmed by Leaf */ -/* E-mail:leaf@leafok.com QQ:6049044 */ +/* Copyright (C) LeafOK.com, 2003-2008 */ /* */ -/* http://bbs.leafok.com */ -/* http://bbs.leafok.net */ -/* http://bbs.fenglin.info */ +/* http://www.leafok.com */ /* */ /*******************************************************/ @@ -102,14 +98,12 @@ int base_passive::work() if (this->load_priv() != 0) return -1; - this->p_ThreadPool = new thread_pool(MAX_CLIENT); + this->SetThreadPool(new thread_pool(MAX_CLIENT)); if (this->p_ThreadPool->GetLastError() != 0) { return -1; } - hThreadCurrent = GetCurrentThread(); - if (this->s_connect(this->w_address,this->w_port) == 0) { this->Startup(); @@ -129,7 +123,7 @@ int base_passive::work() this->running = true; - this->GetThreadPool()->SetThreadStatus(hThreadCurrent,thread_pool::S_WAITING); + this->GetParentThread()->GetThreadPool()->SetThreadStatus(GetCurrentThreadId(),thread_pool::S_WAITING); namelen = sizeof(sin); if ((p->s = accept(this->s,(LPSOCKADDR)&sin,&namelen)) == INVALID_SOCKET) @@ -141,20 +135,19 @@ int base_passive::work() return -2; } - this->GetThreadPool()->SetThreadStatus(hThreadCurrent,thread_pool::S_WORKING); - if (this->IsShutdown()) { break; } + this->GetParentThread()->GetThreadPool()->SetThreadStatus(GetCurrentThreadId(),thread_pool::S_WORKING); strcpy(p->hostaddr,inet_ntoa(sin.sin_addr)); p->port = sin.sin_port; p->isConnected = true; // strcpy(p->w_conn_str,this->w_conn_str); - if (this->>get_priv(p)!=0) + if (this->get_priv(p)!=0) { p->s_send("502 Load access file failed.\r\n"); @@ -162,7 +155,7 @@ int base_passive::work() continue; } - if (!p->access.get) + if (!p->check_priv()) { p->s_send("502 You are not in my access file.\r\n"); delete(p); @@ -173,7 +166,7 @@ int base_passive::work() if (this->GetThreadPool()->GetThreadCount() < MAX_CLIENT) { if (hThreadCurrent = CreateThread(NULL,0,(LPTHREAD_START_ROUTINE)base_passive::AcceptThread,(LPVOID)p,0,&ulThreadId)) -// base_passive::uThreadCount++; + { CloseHandle(hThreadCurrent); syslog << logfile::log_head << "Create accept thread ... OK" << endl; } @@ -193,8 +186,6 @@ int base_passive::work() Sleep(1000*5); // Wait several seconds for all threads to exit } this->s_close(); - delete(this->p_ThreadPool); - this->unload_priv(); @@ -204,19 +195,22 @@ int base_passive::work() } DWORD base_passive::AcceptThread(LPVOID pParam) - HANDLE hThreadCurrent; { base_passive* p; try { - hThreadCurrent = GetCurrentThread(); p = (base_passive*)pParam; - if (p->GetParentThread()->GetThreadPool()->AddThread(hThreadCurrent, CLOCKS_PER_SEC * 30) != 0) + + p->ulMainThreadId = GetCurrentThreadId(); + + syslog << logfile::log_head << "Accept connection from " << p->hostaddr + << ":" << p->port << endl; + if (p->GetParentThread()->GetThreadPool()->AddThread(GetCurrentThreadId(), CLOCKS_PER_SEC * 30) != 0) { syslog << logfile::log_head << "Register thread ... Failed" << endl; - p->GetParentThread()->GetThreadPool()->SetThreadStatus(hThreadCurrent,thread_pool::S_WORKING); + } p->GetParentThread()->GetThreadPool()->SetThreadStatus(GetCurrentThreadId(),thread_pool::S_WORKING); if (p->db_env_init() == 0) @@ -227,7 +221,7 @@ DWORD base_passive::AcceptThread(LPVOID { syslog << logfile::log_head << "DB_ENV_INIT failed" << endl; } - if (p->GetParentThread()->GetThreadPool()->RemoveThread(hThreadCurrent) != 0) + if (p->GetParentThread()->GetThreadPool()->RemoveThread(GetCurrentThreadId()) != 0) { syslog << logfile::log_head << "Unregister thread ... Failed" << endl; @@ -239,7 +233,9 @@ DWORD base_passive::AcceptThread(LPVOID } catch(CException* e) { - syslog << logfile::log_head << "Error in AcceptThread()" << endl; + char strErrMsg[1024]; + e->GetErrorMessage(strErrMsg,1024); + syslog << logfile::log_head << "Error in AcceptThread() [" << strErrMsg << "]" << endl; e->Delete(); return -1; } @@ -254,7 +250,7 @@ int base_passive::get_priv(base_passive* //Default value strcpy(p->access.ip,p->hostaddr); p->access.control = false; - p->access.get = true; + p->access.get = false; p->access.post = false; p->access.ihave = false; @@ -270,7 +266,9 @@ int base_passive::get_priv(base_passive* } catch(CException* e) { - syslog << logfile::log_head << "Error in get_priv()" << endl; + char strErrMsg[1024]; + e->GetErrorMessage(strErrMsg,1024); + syslog << logfile::log_head << "Error in get_priv() [" << strErrMsg << "]" << endl; e->Delete(); return -1; } @@ -322,7 +320,9 @@ int base_passive::load_priv(void) } catch(CException* e) { - syslog << logfile::log_head << "Error in load_priv()" << endl; + char strErrMsg[1024]; + e->GetErrorMessage(strErrMsg,1024); + syslog << logfile::log_head << "Error in load_priv() [" << strErrMsg << "]" << endl; e->Delete(); return -1; } @@ -345,7 +345,9 @@ int base_passive::unload_priv(void) } catch(CException* e) { - syslog << logfile::log_head << "Error in unload_priv()" << endl; + char strErrMsg[1024]; + e->GetErrorMessage(strErrMsg,1024); + syslog << logfile::log_head << "Error in unload_priv() [" << strErrMsg << "]" << endl; e->Delete(); return -1; } @@ -358,3 +360,8 @@ int base_passive::w_call(void) this->work(); return 0; } + +bool base_passive::check_priv(void) +{ + return this->access.get; +}